{#snippet sectionChecklist()} {$i18n.t('Sidebar')} {#each availableSections as section (section)} {@const shown = !hiddenSections.includes(section)} toggleSection(section)} > {sectionLabels[section]} {#if shown}{/if} {/each} {/snippet} {#snippet sectionVisibilityItems(id: string, close = () => {})} { close(); toggleSection(id); }} > {$i18n.t('Hide from sidebar')} {@render sectionChecklist()} {/snippet} {#snippet sectionMoreMenu(id: string)} {@render sectionVisibilityItems(id)} {/snippet} applySelectedChatAction('delete', deleteSelectedIds)} /> { let { type, name, is_private, access_grants, group_ids, user_ids } = payload ?? {}; name = name?.trim(); if (type === 'dm') { if (!user_ids || user_ids.length === 0) { toast.error($i18n.t('Please select at least one user for Direct Message channel.')); return; } } else { if (!name) { toast.error($i18n.t('Channel name cannot be empty.')); return; } } const res = await createNewChannel(localStorage.token, { type: type, name: name, is_private: is_private, access_grants: access_grants, group_ids: group_ids, user_ids: user_ids }).catch((error) => { toast.error(`${error}`); return null; }); if (res) { $socket.emit('join-channels', { auth: { token: $user?.token } }); await initChannels(); showCreateChannel = false; showChannels = true; if (!openSidebarPage(`/channels/${res.id}`, res.name)) goto(`/channels/${res.id}`); } }} /> { await initTeams(); showTeams = true; goto(`/teams/${team.id}`); }} /> {#if $config?.features?.enable_folders && ($user?.role === 'admin' || ($user?.permissions?.features?.folders ?? true))} {#if showOpenDirectory} {/if} {/if} { if (!isResizing) return; if (activePointerId !== null && e.pointerId !== activePointerId) return; resizeSidebarHandler(e.clientX); }} on:pointerup={resizeEndHandler} on:pointercancel={resizeEndHandler} /> {#if $config?.features?.enable_notifications} {#key $user?.id}{/key} {/if} showSidebar.set(open)} let:visible let:progress let:panelStyle let:backdropStyle > {#if visible} { showSidebar.set(false); }} > {/if} { if ($mobile) { showSidebar.set(false); } }} /> { newChatHandler(); }} /> {#if !$mobile && !$showSidebar} { showSidebar.set(!$showSidebar); await tick(); closeSidebarButton?.focus(); }} > { e.stopImmediatePropagation(); e.preventDefault(); newChatHandler(); }} aria-label={$i18n.t('New Chat')} > { e.stopImmediatePropagation(); e.preventDefault(); showSearch.set(true); }} draggable="false" aria-label={$i18n.t('Search')} > {#each pinnedItems as itemId (itemId)} {@const meta = getMenuItemMeta(itemId)} {#if meta && isMenuItemVisible(itemId)} { e.stopImmediatePropagation(); e.preventDefault(); goto(meta.href); itemClickHandler(); }} draggable="true" aria-label={$i18n.t(meta.label)} > {#if itemId === 'notes'} {:else if itemId === 'workspace'} {:else if itemId === 'automations'} {:else if itemId === 'calendar'} {:else if itemId === 'tasks'} {:else if itemId === 'playground'} {/if} {/if} {/each} {#if $user !== undefined && $user !== null} {@render sectionChecklist()} {#if $config?.features?.enable_user_status} {/if} {/if} {/if} {#if visible || !$mobile} {$WEBUI_NAME} {#if $config?.features?.enable_notifications} inboxHost.close()} />{/if} { showSidebar.set(!$showSidebar); await tick(); openSidebarButton?.focus(); }} aria-label={$showSidebar ? $i18n.t('Close Sidebar') : $i18n.t('Open Sidebar')} > {#if $config?.features?.enable_notifications} {#key $user?.id} void inboxHost.close()} onSelect={(item) => inboxHost.select(item)} /> {/key} {/if} { if (e.target.scrollTop === 0) { scrollTop = 0; } else { scrollTop = e.target.scrollTop; } }} > {$i18n.t('New Chat')} { showSearch.set(true); }} draggable="false" aria-label={$i18n.t('Search')} > {$i18n.t('Search')} {#each pinnedItems as itemId (itemId)} {@const meta = getMenuItemMeta(itemId)} {#if meta && isMenuItemVisible(itemId)} {#if itemId === 'notes'} {:else if itemId === 'workspace'} {:else if itemId === 'automations'} {:else if itemId === 'calendar'} {:else if itemId === 'tasks'} {:else if itemId === 'playground'} {/if} {$i18n.t(meta.label)} {/if} {/each} {#each visibleSections as sectionId (sectionId)} {#if sectionId === 'models'} {@render sectionMoreMenu('models')} {:else if sectionId === 'notes'} { const note = await createNoteHandler('New Note'); if (note) { if (!openSidebarPage(`/notes/${note.id}`, note.title)) goto(`/notes/${note.id}`); } }} onAddLabel={$i18n.t('New Note')} > {@render sectionMoreMenu('notes')} {:else if sectionId === 'channels'} { await tick(); setTimeout(() => { showCreateChannel = true; }, 0); } : null} onAddLabel={$i18n.t('Create Channel')} > {@render sectionMoreMenu('channels')} {#each channelGroups as group, groupIdx} {#if groupIdx > 0} {/if} {#each group as channel (channel.id)} { await initChannels(); }} /> {/each} {/each} {:else if sectionId === 'teams'} { // A sub-team dropped on the section heading moves to the top level. const { type, id } = e.detail; if (type === 'team' && $teams.find((team) => team.id === id)?.parent_id) { moveTeam(id, null); } }} > {@render sectionMoreMenu('teams')} {#if canCreateTeams || browsableTeams.length > 0} (showCreateTeam = true) : null} onOpen={(team) => goto(`/teams/${team.id}`)} onJoined={async () => { await initTeams(); showTeams = true; }} /> {/if} {#each activeTeams.filter((team) => !activeTeams.some((parent) => parent.id === team.parent_id)) as team (team.id)} {/each} {#if archivedTeams.length > 0} (showArchivedTeams = !showArchivedTeams)} > {$i18n.t('Archived')} {archivedTeams.length} {#if showArchivedTeams} {#each archivedTeams as team (team.id)} {/each} {/if} {/if} {:else if sectionId === 'folders'} { showCreateFolderModal = true; }} onAddLabel={$i18n.t('New Folder')} on:drop={async (e) => { const { type, id, item } = e.detail; if (type === 'folder') { // Dropped on the section itself: top level, outside any section of yours. // While grouped, sections are hidden and keep their folders. if ( ($settings?.folderGroup ?? 'none') === 'none' && folderSections.some((section) => section.folderIds.includes(id)) ) { saveFolderListSettings({ folderSections: placeInSection(folderSections, id) }); } if (folders[id].parent_id === null || folders[id].shared) { return; } const res = await updateFolderParentIdById( localStorage.token, id, null ).catch((error) => { toast.error(`${error}`); return null; }); if (res) { updateFolderDetails(id, res); await initFolders(); } } }} > {#each folderListMenus as menu (menu.key)} {@const current = menu.choices.find( (choice) => choice.value === ($settings as Record | undefined)?.[menu.key] ) ?? menu.choices[0]} {menu.label} {current.label} {#each menu.choices as choice (choice.value)} { showFoldersMenu = false; if (choice.value !== current.value) setFolderListView(menu.key, choice.value); }} > {choice.label} {#if choice.value === current.value}{/if} {/each} {/each} { showFoldersMenu = false; createFolderSection(); }} > {$i18n.t('New section')} {@render sectionVisibilityItems( 'folders', () => (showFoldersMenu = false) )} {#if directoryMachines.length} (showCreateFolderModal = true)}> {$i18n.t('New Folder')} (showOpenDirectory = true)}> {$i18n.t('Open directory')} {/if} { for (const childId of Object.keys(folders)) { let parentId = childId; while (parentId && parentId !== folderId) parentId = folders[parentId]?.parent_id; if (parentId) removeFolderState(childId); } let id = $selectedFolder?.id; while (id && id !== folderId) id = folders[id]?.parent_id; if (id) selectedFolder.set(null); initChatList(); }} on:update={() => { initChatList(); }} on:import={(e) => { const { folderId, items } = e.detail; importChatHandler(items, false, folderId); }} on:change={async () => { initChatList(); }} /> {:else} { selectedFolder.set(null); }} on:import={(e) => { importChatHandler(e.detail); }} on:drop={async (e) => { const { type, id, item } = e.detail; if (type === 'chat') { let chat = await getChatById(localStorage.token, id).catch((error) => { return null; }); if (!chat && item) { if (!canImportChats) { toast.error($i18n.t('Access prohibited')); return; } chat = await importChats(localStorage.token, [ { chat: item.chat, meta: item?.meta ?? {}, pinned: false, folder_id: null, created_at: item?.created_at ?? null, updated_at: item?.updated_at ?? null } ]); } if (chat) { console.log(chat); if (!chat.folder_id && !chat.pinned) { return; } if (chat.folder_id) { const res = await updateChatFolderIdById( localStorage.token, chat.id, null ).catch((error) => { toast.error(`${error}`); return null; }); folderRegistry[chat.folder_id]?.setFolderItems(); if (res) { updateFolderChatLists(res, null); chat = res; } } if (chat.pinned) { const res = await toggleChatPinnedStatusById( localStorage.token, chat.id ); } await initChatList(); void refreshFolderChatLists(); } } else if (type === 'folder') { if (folders[id].parent_id === null || folders[id].shared) { return; } const res = await updateFolderParentIdById( localStorage.token, id, null ).catch((error) => { toast.error(`${error}`); return null; }); if (res) { await initFolders(); } } }} > {#each chatListMenus as menu (menu.key)} {@const current = menu.choices.find( (choice) => choice.value === $chatListView[menu.key] )} {menu.label} {current?.label} {#each menu.choices as choice (choice.value)} { showChatsMenu = false; if (choice.value !== current?.value) { setChatListView(localStorage.token, { [menu.key]: choice.value }); } }} > {choice.label} {#if choice.value === current?.value}{/if} {/each} {/each} {$i18n.t('Mark all as read')} {@render sectionVisibilityItems('chats', () => (showChatsMenu = false))} {#if $pinnedChats.length > 0} { importChatHandler(e.detail, true); }} on:drop={async (e) => { const { type, id, item } = e.detail; if (type === 'chat') { let chat = await getChatById(localStorage.token, id).catch( (error) => { return null; } ); if (!chat && item) { if (!canImportChats) { toast.error($i18n.t('Access prohibited')); return; } chat = await importChats(localStorage.token, [ { chat: item.chat, meta: item?.meta ?? {}, pinned: false, folder_id: null, created_at: item?.created_at ?? null, updated_at: item?.updated_at ?? null } ]); } if (chat) { console.log(chat); if (chat.folder_id) { const res = await updateChatFolderIdById( localStorage.token, chat.id, null ).catch((error) => { toast.error(`${error}`); return null; }); if (res) { updateFolderChatLists(res, null); chat = res; } } if (!chat.pinned) { const res = await toggleChatPinnedStatusById( localStorage.token, chat.id ); } await initChatList(); void refreshFolderChatLists(); } } }} name={$i18n.t('Pinned')} > {#each $pinnedChats as chat, idx (`pinned-chat-${chat?.id ?? idx}`)} { selectedChatId = chat.id; }} on:unselect={() => { selectedChatId = null; }} on:change={async () => { initChatList(); }} onReadStateChange={applyChatReadState} on:tag={(e) => { const { type, name } = e.detail; tagEventHandler(type, name, chat.id); }} /> {/each} {/if} {#if $chats} {#each $chats as chat, idx (`chat-${chat?.id ?? idx}`)} {#if idx === 0 || (idx > 0 && chat.time_range !== $chats[idx - 1].time_range)} {$i18n.t(chat.time_range)} {/if} { selectedChatId = chat.id; }} on:unselect={() => { selectedChatId = null; }} on:change={async () => { initChatList(); }} onReadStateChange={applyChatReadState} on:tag={(e) => { const { type, name } = e.detail; tagEventHandler(type, name, chat.id); }} /> {/each} {#if chatListReady && !allChatsLoaded} { if (!chatListLoading) { loadMoreChats(); } }} > {$i18n.t('Loading...')} {/if} {:else} {$i18n.t('Loading...')} {/if} {/if} {/each} {#if !inboxOpened && $selectedChatIds.size > 0} {$i18n.t('{{count}} selected', { count: $selectedChatIds.size })} {#if $visibleControls['chat.archive']} applySelectedChatAction('archive', [...$selectedChatIds])} > {/if} {#if canDeleteChats} { deleteSelectedIds = [...$selectedChatIds]; showDeleteSelectedConfirm = true; }} > {/if} {/if} {#if $user !== undefined && $user !== null} {@render sectionChecklist()} {#if $config?.features?.enable_user_status} {/if} {$user?.name} {/if} {#if !$mobile && visible} {/if} {/if}