This commit is contained in:
Timothy Jaeryang Baek
2026-11-08 01:28:41 +09:00
parent dc22fa8f86
commit 834c47ee02
14 changed files with 947 additions and 571 deletions
+1 -1
View File
@@ -1120,7 +1120,7 @@ async def chat_completion(
folder_defaults = await get_folder_terminal_defaults(user, form_data.get('folder_id'))
if 'terminal_id' not in form_data and folder_defaults.get('terminal_id'):
form_data['terminal_id'] = folder_defaults['terminal_id']
if not requested_directory and form_data.get('terminal_id') == folder_defaults.get('terminal_id'):
if requested_directory is None and form_data.get('terminal_id') == folder_defaults.get('terminal_id'):
requested_directory = folder_defaults.get('working_directory')
else:
requested_directory = None
+1
View File
@@ -81,6 +81,7 @@ class InterfaceSettings(BaseModel):
chatFadeStreamingText: bool | None = None
richTextInput: bool | None = None
showFormattingToolbar: bool | None = None
showInputSelections: bool | None = None
insertPromptAsRichText: bool | None = None
promptAutocomplete: bool | None = None
insertSuggestionPrompt: bool | None = None
+81
View File
@@ -0,0 +1,81 @@
import {
joinTerminalPath,
terminalRequest,
TerminalRequestError,
type TerminalConnection,
type TerminalFileList
} from './index';
import { computeFileHash } from '$lib/utils/hash';
const historyDirectory = (home: string, userId: string) => {
if (!home || !userId || userId === '.' || userId === '..')
throw new Error('Terminal home and a valid user are required');
return joinTerminalPath(home, `.open-webui/users/${encodeURIComponent(userId)}/folders`);
};
export async function loadRecentFolders(
connection: TerminalConnection,
chatId: string | null,
home: string,
userId: string
): Promise<string[]> {
const directory = historyDirectory(home, userId);
let listing: TerminalFileList;
try {
listing = await terminalRequest(
connection,
chatId,
`/files/list?directory=${encodeURIComponent(directory)}`
);
} catch (error) {
if (error instanceof TerminalRequestError && error.status === 404) return [];
throw error;
}
const entries = listing.entries
.filter((entry) => entry.type === 'file' && /^[a-f0-9]{64}\.json$/.test(entry.name))
.sort((a, b) => (b.modified ?? 0) - (a.modified ?? 0))
.slice(0, 8);
const paths = await Promise.all(
entries.map(async (entry) => {
try {
const result = await terminalRequest<{ content: string }>(
connection,
chatId,
`/files/read?path=${encodeURIComponent(joinTerminalPath(directory, entry.name))}`
);
const record = JSON.parse(result.content);
return typeof record?.path === 'string' && record.path ? record.path : null;
} catch (error) {
// A missing or partially written record must not hide the rest of the history.
if (
error instanceof SyntaxError ||
(error instanceof TerminalRequestError && error.status === 404)
)
return null;
throw error;
}
})
);
return [...new Set(paths.filter((path): path is string => path !== null))];
}
export async function rememberRecentFolder(
connection: TerminalConnection,
chatId: string | null,
home: string,
userId: string,
path: string
): Promise<void> {
if (!path) return;
const normalized = path.replace(/\/+$/, '') || '/';
const hash = await computeFileHash(new File([normalized], 'folder'));
// Separate records preserve simultaneous selections in different browsers.
await terminalRequest(connection, chatId, '/files/write', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
path: joinTerminalPath(historyDirectory(home, userId), `${hash}.json`),
content: JSON.stringify({ path: normalized })
})
});
}
+3 -3
View File
@@ -5584,7 +5584,7 @@
class=" pb-2 {dragged ? 'z-0' : 'z-10'}"
>
<MessageInput
{terminalContext}
bind:terminalContext
{typingUsers}
on:typing={(event) => emitTyping(event.detail)}
callActive={!!(bridge?.connected || bridge?.connecting)}
@@ -5685,7 +5685,7 @@
{/if}
<div id={embedded ? messageInputDropzoneId : undefined} class="pb-2 z-10">
<MessageInput
{terminalContext}
bind:terminalContext
{typingUsers}
on:typing={(event) => emitTyping(event.detail)}
callActive={!!(bridge?.connected || bridge?.connecting)}
@@ -5756,7 +5756,7 @@
<div class="flex items-center h-full">
<Placeholder
chatId={$chatId}
{terminalContext}
bind:terminalContext
callActive={!!(bridge?.connected || bridge?.connecting)}
callEnabled={!isShared}
bind:selectedModelIdx
+22 -5
View File
@@ -152,9 +152,11 @@
let tabs = emptyTabs();
const paneStyle = (rect: PanelRect, header = 0) =>
`position:absolute;left:${rect.left * 100}%;top:calc(100% * ${rect.top} + ${header}px * var(--app-text-scale, 1));width:${rect.width * 100}%;height:calc(100% * ${rect.height} - ${header}px * var(--app-text-scale, 1));`;
const focusGroup = (id: string) => {
const focusGroup = (id: string, event?: Event) => {
// Tab activation reads the composer's directory before changing the active context.
if (event?.target instanceof Element && event.target.closest('[data-panel-tab]')) return;
const group = tabs.groups.find((group) => group.id === id);
if (group?.activeId) tabs = activateTab(tabs, group.activeId);
if (group?.activeId && tabs.activeGroupId !== id) tabs = activateTab(tabs, group.activeId);
};
let terminalViews: Record<string, XTerminal> = {};
export const hasTerminals = () => tabs.tabs.some((tab) => tab.kind === 'terminal');
@@ -422,6 +424,11 @@
tabs = activateTab(tabs, mainChatTabId);
};
const selectTab = (id: string) => {
const tab = tabs.tabs.find((tab) => tab.id === id);
if (tab?.kind === 'files') {
openFiles(tab.terminalId ?? null);
return;
}
tabs = activateTab(tabs, id);
showTabs.set(true);
};
@@ -434,6 +441,10 @@
};
const openFiles = (selector = $selectedTerminalId, directory?: string) => {
if (selector ? !terminalAccessible(selector) : !showFilesTab) return;
directory ??=
terminalContext?.terminalId === selector
? terminalContext.currentDirectory || undefined
: undefined;
const id = selector ? `files:${selector}` : 'files';
openPanel({
id,
@@ -442,7 +453,13 @@
terminalId: selector ?? undefined,
path: directory
});
if (directory) void fileViews[id]?.browseDirectory?.(directory);
const view = fileViews[id];
if (
directory &&
view &&
view.captureView()?.directory?.replace(/\/+$/, '') !== directory.replace(/\/+$/, '')
)
void view.browseDirectory(directory);
};
const openFile = (path: string, selector: string, page?: number | null) => {
if (!terminalAccessible(selector)) return;
@@ -1476,8 +1493,8 @@
role="presentation"
class="absolute min-h-0 min-w-0 pointer-events-none flex flex-col overflow-hidden"
style={paneStyle(positions.groups[group.id])}
on:focusin={() => focusGroup(group.id)}
on:pointerdown={() => focusGroup(group.id)}
on:focusin={(event) => focusGroup(group.id, event)}
on:pointerdown={(event) => focusGroup(group.id, event)}
>
{@render tabBar(group)}
</div>
+55 -61
View File
@@ -116,7 +116,6 @@
import Terminal from '../icons/Terminal.svelte';
import IntegrationsMenu from './MessageInput/IntegrationsMenu.svelte';
import TerminalMenu from './MessageInput/TerminalMenu.svelte';
import Component from '../icons/Component.svelte';
import PlusAlt from '../icons/PlusAlt.svelte';
import Dropdown from '../common/Dropdown.svelte';
@@ -317,10 +316,12 @@
let copiedStatusChatId = false;
let selectedValvesType = 'tool'; // 'tool' or 'function'
let selectedValvesItemId = null;
let integrationsMenuCloseOnOutsideClick = true;
let showInputMenu = false;
let inputMenuTab = '';
let inputMenuCloseOnOutsideClick = true;
$: if (!showValvesModal) {
integrationsMenuCloseOnOutsideClick = true;
inputMenuCloseOnOutsideClick = true;
}
let chatInputDraft: any;
@@ -936,6 +937,8 @@
.map((id) => ($models.find((model) => model.id === id) || {})?.filters ?? [])
.reduce((acc, filters) => acc.filter((f1) => filters.some((f2) => f2.id === f1.id)));
$: showInputSelections = $settings?.showInputSelections ?? false;
let showToolsButton = false;
$: showToolsButton = ($tools ?? []).length > 0 || ($toolServers ?? []).length > 0;
@@ -1945,7 +1948,7 @@
await tick();
}}
on:close={() => {
integrationsMenuCloseOnOutsideClick = true;
inputMenuCloseOnOutsideClick = true;
}}
/>
@@ -2557,7 +2560,9 @@
<div class=" flex justify-between mt-0.5 mb-2 mx-0.5 max-w-full" dir="ltr">
<div class="ml-1 self-end flex items-center">
<InputMenu
onCompare={openComparison}
bind:show={showInputMenu}
bind:tab={inputMenuTab}
closeOnOutsideClick={inputMenuCloseOnOutsideClick}
bind:files
selectedModels={selectedModelIds}
fileUploadCapableModels={getFilesystemUploadTerminal(
@@ -2626,58 +2631,45 @@
>
<PlusAlt className="size-5" />
</button>
<svelte:fragment slot="integrations">
{#if showWebSearchButton || showImageGenerationButton || showCodeInterpreterButton || showToolsButton || showSkillsButton || (toggleFilters && toggleFilters.length > 0)}
<IntegrationsMenu
bind:show={showInputMenu}
bind:tab={inputMenuTab}
selectedModels={selectedModelIds}
{toggleFilters}
{showWebSearchButton}
{showImageGenerationButton}
{showCodeInterpreterButton}
bind:selectedToolIds
bind:selectedSkillIds
bind:selectedFilterIds
bind:webSearchEnabled
bind:imageGenerationEnabled
bind:codeInterpreterEnabled
oauthRedirectHandler={(tool: {
id: string;
serverId: string;
authType?: string | null;
}) => oauthRedirectHandler(tool, chatInputDraft)}
{onWebSearchToggle}
onShowValves={(e) => {
const { type, id } = e;
selectedValvesType = type;
selectedValvesItemId = id;
showValvesModal = true;
inputMenuCloseOnOutsideClick = false;
}}
/>
{/if}
</svelte:fragment>
</InputMenu>
{#if showWebSearchButton || showImageGenerationButton || showCodeInterpreterButton || showToolsButton || showSkillsButton || (toggleFilters && toggleFilters.length > 0)}
<div
class="flex self-center w-[0.0625rem] h-4 mx-1 bg-gray-200/50 dark:bg-gray-800/50 shrink-0"
/>
<IntegrationsMenu
selectedModels={selectedModelIds}
{toggleFilters}
{showWebSearchButton}
{showImageGenerationButton}
{showCodeInterpreterButton}
bind:selectedToolIds
bind:selectedSkillIds
bind:selectedFilterIds
bind:webSearchEnabled
bind:imageGenerationEnabled
bind:codeInterpreterEnabled
oauthRedirectHandler={(tool: {
id: string;
serverId: string;
authType?: string | null;
}) => oauthRedirectHandler(tool, chatInputDraft)}
{onWebSearchToggle}
closeOnOutsideClick={integrationsMenuCloseOnOutsideClick}
onShowValves={(e) => {
const { type, id } = e;
selectedValvesType = type;
selectedValvesItemId = id;
showValvesModal = true;
integrationsMenuCloseOnOutsideClick = false;
}}
onClose={async () => {
await tick();
if (!$mobile) {
const chatInput = document.getElementById(inputId);
chatInput?.focus();
}
}}
>
<button
type="button"
id="integration-menu-button"
class="bg-transparent hover:bg-gray-100/40 text-gray-700 dark:text-white dark:hover:bg-gray-800/40 rounded-full size-[1.875rem] flex justify-center items-center outline-hidden focus:outline-hidden shrink-0"
aria-label={$i18n.t('Integrations')}
>
<Component className="size-4.5" strokeWidth="1.5" />
</button>
</IntegrationsMenu>
{/if}
<div
aria-hidden="true"
class="flex self-center w-[0.0625rem] h-4 mx-1 bg-gray-200/50 dark:bg-gray-800/50 shrink-0"
></div>
{#if hasChatVariables}
<Tooltip content={$i18n.t('Chat Variables')} placement="top">
@@ -2721,7 +2713,7 @@
{/if}
<div class="ml-1 flex gap-1.5 shrink-0">
{#if (selectedToolIds ?? []).length > 0 && $visibleControls['chat.selected_tools']}
{#if showInputSelections && (selectedToolIds ?? []).length > 0 && $visibleControls['chat.selected_tools']}
<Tooltip
content={$i18n.t('{{COUNT}} Available Tools', {
COUNT: (selectedToolIds ?? []).length
@@ -2744,7 +2736,7 @@
</Tooltip>
{/if}
{#if (selectedSkillIds ?? []).length > 0 && $visibleControls['chat.selected_skills']}
{#if showInputSelections && (selectedSkillIds ?? []).length > 0 && $visibleControls['chat.selected_skills']}
<Tooltip
content={$i18n.t('{{COUNT}} Available Skills', {
COUNT: (selectedSkillIds ?? []).length
@@ -2769,7 +2761,7 @@
{#each selectedFilterIds as filterId (filterId)}
{@const filter = toggleFilters.find((f) => f.id === filterId)}
{#if filter && $visibleControls['chat.selected_filters']}
{#if showInputSelections && filter && $visibleControls['chat.selected_filters']}
<Tooltip
content={resolveLocalizedFunction(
filter,
@@ -2838,7 +2830,7 @@
{/if}
{/each}
{#if webSearchEnabled && showWebSearchButton && $visibleControls['chat.selected_web_search']}
{#if showInputSelections && webSearchEnabled && showWebSearchButton && $visibleControls['chat.selected_web_search']}
<Tooltip content={$i18n.t('Web Search')} placement="top">
<button
aria-label={$i18n.t('Web Search')}
@@ -2855,7 +2847,7 @@
</Tooltip>
{/if}
{#if imageGenerationEnabled && showImageGenerationButton && $visibleControls['chat.selected_image_generation']}
{#if showInputSelections && imageGenerationEnabled && showImageGenerationButton && $visibleControls['chat.selected_image_generation']}
<Tooltip content={$i18n.t('Image')} placement="top">
<button
aria-label={$i18n.t('Image')}
@@ -2872,7 +2864,7 @@
</Tooltip>
{/if}
{#if codeInterpreterEnabled && showCodeInterpreterButton && $visibleControls['chat.selected_code_interpreter']}
{#if showInputSelections && codeInterpreterEnabled && showCodeInterpreterButton && $visibleControls['chat.selected_code_interpreter']}
<Tooltip content={$i18n.t('Code Interpreter')} placement="top">
<button
aria-label={codeInterpreterEnabled
@@ -2898,6 +2890,8 @@
{#if showTerminalSelector}
<TerminalMenu
bind:show={showTerminalMenu}
chatId={isSavedChatId(chatId) ? chatId : null}
bind:terminalContext
disabled={generating ||
(!!history?.currentId &&
history.messages[history.currentId]?.done != true)}
@@ -1,5 +1,5 @@
<script lang="ts">
import { getContext, onMount, tick } from 'svelte';
import { getContext, onMount } from 'svelte';
import { fly } from 'svelte/transition';
import { config, user, tools as _tools, mobile, knowledge, visibleControls } from '$lib/stores';
@@ -11,6 +11,7 @@
import DropdownMenu from '$lib/components/common/DropdownMenu.svelte';
import Tooltip from '$lib/components/common/Tooltip.svelte';
import DocumentArrowUp from '$lib/components/icons/DocumentArrowUp.svelte';
import DocumentDuplicate from '$lib/components/icons/DocumentDuplicate.svelte';
import Camera from '$lib/components/icons/Camera.svelte';
import Note from '$lib/components/icons/Note.svelte';
import Clip from '$lib/components/icons/Clip.svelte';
@@ -45,12 +46,13 @@
export let onUpload: Function;
export let onClose: Function;
export let onCompare: () => void = () => {};
export let toolApprovalMode = 'full';
export let onToolApprovalModeChange: Function = () => {};
let show = false;
let tab = '';
export let show = false;
export let tab = '';
export let closeOnOutsideClick = true;
$: if (!show) tab = '';
let showAttachWebpageModal = false;
$: toolApprovalModes = [
@@ -136,9 +138,10 @@
<Dropdown
bind:show
{closeOnOutsideClick}
visualViewportAware
on:change={(e) => {
if (e.detail === false) {
onOpenChange={(state) => {
if (state === false) {
onClose();
}
}}
@@ -148,12 +151,11 @@
</Tooltip>
<div slot="content">
<DropdownMenu className="w-70 max-h-72 overflow-hidden transition">
<DropdownMenu
className="w-70 max-h-72 overflow-y-auto overflow-x-hidden scrollbar-thin transition"
>
{#if tab === ''}
<div
class="max-h-72 overflow-y-auto overflow-x-hidden scrollbar-thin"
in:fly={{ x: -20, duration: 150 }}
>
<div in:fly={{ x: -20, duration: 150 }}>
{#if toolPermissionsEnabled}
<button
role="menuitem"
@@ -259,33 +261,38 @@
</Tooltip>
{/if}
{#if $visibleControls['chat.compare']}
<button
role="menuitem"
type="button"
class="flex w-full gap-2 items-center h-[1.6875rem] px-2 text-[0.8125rem] font-normal cursor-pointer hover:bg-gray-50/40 dark:hover:bg-gray-800/40 rounded-xl text-left"
on:click={async () => {
show = false;
await tick();
onCompare();
}}
>
<svg
class="size-3.5 shrink-0"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.5"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<rect x="3" y="4" width="18" height="16" rx="2" />
<path d="M12 4v16M5.5 12h4M14.5 12h4M16.5 10v4" />
</svg>
<span>{$i18n.t('Compare text')}</span>
</button>
{/if}
<button
role="menuitem"
type="button"
class="flex w-full gap-2 items-center h-[1.6875rem] px-2 text-[0.8125rem] font-normal cursor-pointer hover:bg-gray-50/40 dark:hover:bg-gray-800/40 rounded-xl text-left"
on:click={() => {
tab = 'attachments';
}}
>
<DocumentDuplicate />
<div class="flex items-center w-full justify-between">
<div>{$i18n.t('Add Context')}</div>
<div class="text-gray-500"><ChevronRight /></div>
</div>
</button>
</div>
{:else if tab === 'attachments'}
<div
class="max-h-72 overflow-y-auto overflow-x-hidden scrollbar-thin"
in:fly={{ x: 20, duration: 150 }}
>
<button
role="menuitem"
type="button"
class="flex w-full gap-2 items-center h-[1.6875rem] px-2 text-[0.8125rem] font-normal cursor-pointer hover:bg-gray-50/40 dark:hover:bg-gray-800/40 rounded-xl text-left"
on:click={() => {
tab = '';
}}
>
<ChevronLeft />
<div>{$i18n.t('Add Context')}</div>
</button>
<div class="h-px mx-1 my-1 bg-gray-100 dark:bg-gray-800"></div>
{#if $visibleControls['chat.attach_webpage']}
<Tooltip
@@ -665,7 +672,7 @@
role="menuitem"
class="flex w-full shrink-0 justify-between gap-2 items-center h-[1.6875rem] px-2 text-[0.8125rem] font-normal select-none cursor-pointer rounded-xl hover:bg-gray-50/40 dark:hover:bg-gray-800/40"
on:click={() => {
tab = '';
tab = 'attachments';
}}
>
<ChevronLeft />
@@ -685,7 +692,7 @@
role="menuitem"
class="flex w-full shrink-0 justify-between gap-2 items-center h-[1.6875rem] px-2 text-[0.8125rem] font-normal select-none cursor-pointer rounded-xl hover:bg-gray-50/40 dark:hover:bg-gray-800/40"
on:click={() => {
tab = '';
tab = 'attachments';
}}
>
<ChevronLeft />
@@ -705,7 +712,7 @@
role="menuitem"
class="flex w-full shrink-0 justify-between gap-2 items-center h-[1.6875rem] px-2 text-[0.8125rem] font-normal select-none cursor-pointer rounded-xl hover:bg-gray-50/40 dark:hover:bg-gray-800/40"
on:click={() => {
tab = '';
tab = 'attachments';
}}
>
<ChevronLeft />
@@ -725,7 +732,7 @@
role="menuitem"
class="flex w-full shrink-0 justify-between gap-2 items-center h-[1.6875rem] px-2 text-[0.8125rem] font-normal select-none cursor-pointer rounded-xl hover:bg-gray-50/40 dark:hover:bg-gray-800/40"
on:click={() => {
tab = '';
tab = 'attachments';
}}
>
<ChevronLeft />
@@ -745,7 +752,7 @@
role="menuitem"
class="flex w-full justify-between gap-2 items-center h-[1.6875rem] px-2 text-[0.8125rem] font-normal select-none cursor-pointer rounded-xl hover:bg-gray-50/40 dark:hover:bg-gray-800/40"
on:click={() => {
tab = '';
tab = 'attachments';
}}
>
<ChevronLeft />
@@ -790,6 +797,7 @@
{/if}
</div>
{/if}
<slot name="integrations" />
</DropdownMenu>
</div>
</Dropdown>
@@ -1,7 +1,7 @@
<script lang="ts">
import { resolveLocalizedResource, resolveLocalizedFunction } from '$lib/utils/localizedContent';
import { functions as localizedFunctions } from '$lib/stores';
import { getContext, onDestroy, tick } from 'svelte';
import { getContext, onDestroy, onMount, tick } from 'svelte';
import { fly } from 'svelte/transition';
import {
@@ -29,8 +29,6 @@
import { toast } from 'svelte-sonner';
import Knobs from '$lib/components/icons/Knobs.svelte';
import Dropdown from '$lib/components/common/Dropdown.svelte';
import DropdownMenu from '$lib/components/common/DropdownMenu.svelte';
import Tooltip from '$lib/components/common/Tooltip.svelte';
import Switch from '$lib/components/common/Switch.svelte';
import Spinner from '$lib/components/common/Spinner.svelte';
@@ -82,12 +80,10 @@
export let codeInterpreterEnabled = false;
export let onShowValves: Function;
export let onClose: Function;
export let onWebSearchToggle: Function = () => {};
export let closeOnOutsideClick = true;
let show = false;
let tab = '';
export let show = false;
export let tab = '';
let tools: Record<string, IntegrationItem> | null = null;
let skills: Record<string, IntegrationItem> | null = null;
@@ -111,9 +107,10 @@
scheduleSkillSearch();
}
$: if (show) {
init();
}
// This content mounts already open; initialize after the derived lists have been set up.
onMount(() => {
void init();
});
let fileUploadEnabled = true;
$: fileUploadEnabled =
@@ -291,473 +288,438 @@
});
</script>
<Dropdown
bind:show
{closeOnOutsideClick}
onOpenChange={(state) => {
if (state === false) {
toolQuery = '';
skillQuery = '';
onClose();
}
}}
>
<Tooltip content={$i18n.t('Integrations')} placement="top">
<slot />
</Tooltip>
<div slot="content">
<DropdownMenu className="min-w-70 max-w-70 max-h-72 overflow-hidden">
{#if tab === ''}
<div
class="max-h-72 overflow-y-auto overflow-x-hidden scrollbar-thin"
in:fly={{ x: -20, duration: 150 }}
{#if tab === ''}
<div class="h-px mx-1 my-1 bg-gray-100 dark:bg-gray-800"></div>
<div in:fly={{ x: -20, duration: 150 }}>
{#if tools}
{#if Object.keys(tools).length > 0}
<button
role="menuitem"
class="flex w-full justify-between gap-2 items-center h-[1.6875rem] px-2 text-[0.8125rem] font-normal cursor-pointer rounded-xl hover:bg-gray-50/40 dark:hover:bg-gray-800/40"
on:click={() => {
tab = 'tools';
}}
>
{#if tools}
{#if Object.keys(tools).length > 0}
<button
role="menuitem"
class="flex w-full justify-between gap-2 items-center h-[1.6875rem] px-2 text-[0.8125rem] font-normal cursor-pointer rounded-xl hover:bg-gray-50/40 dark:hover:bg-gray-800/40"
on:click={() => {
tab = 'tools';
}}
>
<Wrench />
<Wrench />
<div class="flex items-center w-full justify-between">
<div class=" line-clamp-1">
{$i18n.t('Tools')}
<span class="ml-0.5 text-gray-500">{Object.keys(tools).length}</span>
</div>
<div class="text-gray-500">
<ChevronRight />
</div>
</div>
</button>
{/if}
{#if skills && Object.keys(skills).length > 0}
<button
role="menuitem"
class="flex w-full justify-between gap-2 items-center h-[1.6875rem] px-2 text-[0.8125rem] font-normal cursor-pointer rounded-xl hover:bg-gray-50/40 dark:hover:bg-gray-800/40"
on:click={() => {
tab = 'skills';
}}
>
<Cube className="size-3.5" strokeWidth="1.75" />
<div class="flex items-center w-full justify-between">
<div class=" line-clamp-1">
{$i18n.t('Skills')}
<span class="ml-0.5 text-gray-500">{Object.keys(skills).length}</span>
</div>
<div class="text-gray-500">
<ChevronRight />
</div>
</div>
</button>
{/if}
{:else}
<div class="py-4">
<Spinner />
<div class="flex items-center w-full justify-between">
<div class=" line-clamp-1">
{$i18n.t('Tools')}
<span class="ml-0.5 text-gray-500">{Object.keys(tools).length}</span>
</div>
{/if}
{#if toggleFilters && toggleFilters.length > 0}
{#each toggleFilters.sort( (a, b) => a.name.localeCompare( b.name, undefined, { sensitivity: 'base' } ) ) as filter, filterIdx (filter.id)}
<Tooltip
content={resolveLocalizedFunction(
filter,
$localizedFunctions,
$i18n.language,
'description'
)}
placement="top-start"
>
<div
class="flex w-full justify-between gap-2 items-center h-[1.6875rem] px-2 text-[0.8125rem] font-normal cursor-pointer rounded-xl hover:bg-gray-50/40 dark:hover:bg-gray-800/40 has-[[role^=menuitem]:focus-visible]:outline-2 has-[[role^=menuitem]:focus-visible]:-outline-offset-2 has-[[role^=menuitem]:focus-visible]:outline-blue-500"
role="presentation"
on:click={() => {
if (selectedFilterIds.includes(filter.id)) {
selectedFilterIds = selectedFilterIds.filter((id) => id !== filter.id);
} else {
selectedFilterIds = [...selectedFilterIds, filter.id];
}
}}
>
<button
type="button"
class="flex-1 truncate text-left cursor-pointer focus-visible:outline-none!"
role="menuitemcheckbox"
aria-checked={selectedFilterIds.includes(filter.id)}
>
<div class="flex flex-1 gap-2 items-center">
<div class="shrink-0">
{#if filter?.icon}
<div class="size-3.5 items-center flex justify-center">
<img
src={filter.icon}
class="size-3.5 {filter.icon.includes('data:image/svg')
? 'dark:invert-[80%]'
: ''}"
style="fill: currentColor;"
alt={resolveLocalizedFunction(
filter,
$localizedFunctions,
$i18n.language
)}
/>
</div>
{:else}
<Sparkles className="size-3.5" strokeWidth="1.75" />
{/if}
</div>
<div class="text-gray-500">
<ChevronRight />
</div>
</div>
</button>
{/if}
<div class=" truncate">
{resolveLocalizedFunction(filter, $localizedFunctions, $i18n.language)}
</div>
</div>
</button>
{#if skills && Object.keys(skills).length > 0}
<button
role="menuitem"
class="flex w-full justify-between gap-2 items-center h-[1.6875rem] px-2 text-[0.8125rem] font-normal cursor-pointer rounded-xl hover:bg-gray-50/40 dark:hover:bg-gray-800/40"
on:click={() => {
tab = 'skills';
}}
>
<Cube className="size-3.5" strokeWidth="1.75" />
{#if filter?.has_user_valves && ($user?.role === 'admin' || ($user?.permissions?.chat?.valves ?? true))}
<div class=" shrink-0">
<Tooltip content={$i18n.t('Valves')}>
<button
aria-label={$i18n.t('Valves')}
class="self-center w-fit text-sm text-gray-600 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-300 transition rounded-full"
type="button"
on:click={(e) => {
e.stopPropagation();
e.preventDefault();
onShowValves({
type: 'function',
id: filter.id
});
}}
>
<Knobs />
</button>
</Tooltip>
<div class="flex items-center w-full justify-between">
<div class=" line-clamp-1">
{$i18n.t('Skills')}
<span class="ml-0.5 text-gray-500">{Object.keys(skills).length}</span>
</div>
<div class="text-gray-500">
<ChevronRight />
</div>
</div>
</button>
{/if}
{:else}
<div class="py-4">
<Spinner />
</div>
{/if}
{#if toggleFilters && toggleFilters.length > 0}
{#each toggleFilters.sort( (a, b) => a.name.localeCompare( b.name, undefined, { sensitivity: 'base' } ) ) as filter, filterIdx (filter.id)}
<Tooltip
content={resolveLocalizedFunction(
filter,
$localizedFunctions,
$i18n.language,
'description'
)}
placement="top-start"
>
<div
class="flex w-full justify-between gap-2 items-center h-[1.6875rem] px-2 text-[0.8125rem] font-normal cursor-pointer rounded-xl hover:bg-gray-50/40 dark:hover:bg-gray-800/40 has-[[role^=menuitem]:focus-visible]:outline-2 has-[[role^=menuitem]:focus-visible]:-outline-offset-2 has-[[role^=menuitem]:focus-visible]:outline-blue-500"
role="presentation"
on:click={() => {
if (selectedFilterIds.includes(filter.id)) {
selectedFilterIds = selectedFilterIds.filter((id) => id !== filter.id);
} else {
selectedFilterIds = [...selectedFilterIds, filter.id];
}
}}
>
<button
type="button"
class="flex-1 truncate text-left cursor-pointer focus-visible:outline-none!"
role="menuitemcheckbox"
aria-checked={selectedFilterIds.includes(filter.id)}
>
<div class="flex flex-1 gap-2 items-center">
<div class="shrink-0">
{#if filter?.icon}
<div class="size-3.5 items-center flex justify-center">
<img
src={filter.icon}
class="size-3.5 {filter.icon.includes('data:image/svg')
? 'dark:invert-[80%]'
: ''}"
style="fill: currentColor;"
alt={resolveLocalizedFunction(filter, $localizedFunctions, $i18n.language)}
/>
</div>
{:else}
<Sparkles className="size-3.5" strokeWidth="1.75" />
{/if}
<div class=" shrink-0" inert>
<Switch state={selectedFilterIds.includes(filter.id)} />
</div>
</div>
</Tooltip>
{/each}
{/if}
{#if showWebSearchButton}
<Tooltip content={$i18n.t('Search the internet')} placement="top-start">
<button
class="flex w-full justify-between gap-2 items-center h-[1.6875rem] px-2 text-[0.8125rem] font-normal cursor-pointer rounded-xl hover:bg-gray-50/40 dark:hover:bg-gray-800/40"
role="menuitemcheckbox"
aria-checked={webSearchEnabled}
on:click={() => {
webSearchEnabled = !webSearchEnabled;
// Left open, this menu would swallow the first click on the confirmation dialog
if (webSearchEnabled && $config?.features?.enable_web_search_confirmation) {
show = false;
}
onWebSearchToggle(webSearchEnabled);
}}
>
<div class="flex-1 truncate">
<div class="flex flex-1 gap-2 items-center">
<div class="shrink-0">
<GlobeAlt />
</div>
<div class=" truncate">{$i18n.t('Web Search')}</div>
</div>
</div>
<div class=" shrink-0" inert>
<Switch state={webSearchEnabled} />
<div class=" truncate">
{resolveLocalizedFunction(filter, $localizedFunctions, $i18n.language)}
</div>
</button>
</Tooltip>
{/if}
{#if showImageGenerationButton}
<Tooltip content={$i18n.t('Generate an image')} placement="top-start">
<button
class="flex w-full justify-between gap-2 items-center h-[1.6875rem] px-2 text-[0.8125rem] font-normal cursor-pointer rounded-xl hover:bg-gray-50/40 dark:hover:bg-gray-800/40"
role="menuitemcheckbox"
aria-checked={imageGenerationEnabled}
on:click={() => {
imageGenerationEnabled = !imageGenerationEnabled;
}}
>
<div class="flex-1 truncate">
<div class="flex flex-1 gap-2 items-center">
<div class="shrink-0">
<Photo className="size-3.5" strokeWidth="1.5" />
</div>
<div class=" truncate">{$i18n.t('Image')}</div>
</div>
</div>
<div class=" shrink-0" inert>
<Switch state={imageGenerationEnabled} />
</div>
</button>
</Tooltip>
{/if}
{#if showCodeInterpreterButton}
<Tooltip content={$i18n.t('Execute code for analysis')} placement="top-start">
<button
class="flex w-full justify-between gap-2 items-center h-[1.6875rem] px-2 text-[0.8125rem] font-normal cursor-pointer rounded-xl hover:bg-gray-50/40 dark:hover:bg-gray-800/40"
role="menuitemcheckbox"
aria-checked={codeInterpreterEnabled}
on:click={() => {
codeInterpreterEnabled = !codeInterpreterEnabled;
}}
>
<div class="flex-1 truncate">
<div class="flex flex-1 gap-2 items-center">
<div class="shrink-0">
<Terminal className="size-3.5" strokeWidth="1.75" />
</div>
<div class=" truncate">{$i18n.t('Code Interpreter')}</div>
</div>
</div>
<div class=" shrink-0" inert>
<Switch state={codeInterpreterEnabled} />
</div>
</button>
</Tooltip>
{/if}
</div>
{:else if tab === 'tools' && tools}
<div class="flex max-h-72 min-h-0 flex-col gap-0.5" in:fly={{ x: 20, duration: 150 }}>
<button
role="menuitem"
class="flex w-full justify-between gap-2 items-center h-[1.6875rem] px-2 text-[0.8125rem] font-normal cursor-pointer rounded-xl hover:bg-gray-50/40 dark:hover:bg-gray-800/40"
on:click={() => {
toolQuery = '';
tab = '';
}}
>
<ChevronLeft />
<div class="flex items-center w-full justify-between">
<div>
{$i18n.t('Tools')}
<span class="ml-0.5 text-gray-500">{toolIds.length}</span>
</div>
</div>
</button>
</button>
<SearchInput bind:value={toolQuery} placeholder={$i18n.t('Search tools')} />
<div class="min-h-0 flex-1 overflow-y-auto overflow-x-hidden scrollbar-thin">
{#if toolIds.length === 0}
<div class="text-center text-xs text-gray-500 py-3">{$i18n.t('No tools found')}</div>
{:else}
<div class="flex flex-col gap-0.5">
{#each toolIds as toolId}
<div
class="relative flex w-full justify-between gap-2 items-center h-[1.6875rem] px-2 text-[0.8125rem] font-normal cursor-pointer rounded-xl hover:bg-gray-50/40 dark:hover:bg-gray-800/40 has-[[role^=menuitem]:focus-visible]:outline-2 has-[[role^=menuitem]:focus-visible]:-outline-offset-2 has-[[role^=menuitem]:focus-visible]:outline-blue-500"
role="presentation"
on:click={async (e) => {
await toggleTool(toolId, e);
}}
>
{#if !(tools?.[toolId]?.authenticated ?? true)}
<!-- make it slighly darker and not clickable -->
<div class="absolute inset-0 opacity-50 rounded-xl cursor-pointer z-10"></div>
{/if}
<button
type="button"
class="flex-1 truncate text-left cursor-pointer focus-visible:outline-none!"
role={(tools?.[toolId]?.authenticated ?? true)
? 'menuitemcheckbox'
: 'menuitem'}
aria-checked={(tools?.[toolId]?.authenticated ?? true)
? selectedToolIds.includes(toolId)
: undefined}
>
<div class="flex flex-1 gap-2 items-center">
<Tooltip
content={resolveLocalizedResource(
tools?.[toolId],
$i18n.language,
'name'
)}
placement="top"
>
<div class="shrink-0">
<Wrench />
</div>
</Tooltip>
<Tooltip
content={resolveLocalizedResource(
tools?.[toolId],
$i18n.language,
'description'
)}
placement="top-start"
>
<div class=" truncate">
{resolveLocalizedResource(tools?.[toolId], $i18n.language, 'name')}
</div>
</Tooltip>
</div>
</button>
{#if tools?.[toolId]?.authenticated === true && toolId.startsWith('server:mcp:')}
<div class="shrink-0">
<Tooltip content={$i18n.t('Disconnect OAuth')}>
<button
aria-label={$i18n.t('Disconnect OAuth')}
class="self-center w-fit text-sm text-gray-600 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-300 transition rounded-full"
type="button"
on:click={async (e) => {
e.stopPropagation();
e.preventDefault();
const parts = toolId.split(':');
const serverId = parts.at(-1) ?? toolId;
const provider = `mcp:${serverId}`;
try {
await deleteOAuthSession(localStorage.token, provider);
toast.success($i18n.t('OAuth session disconnected'));
// Refresh tools to update authenticated state
_tools.set(await getTools(localStorage.token));
selectedToolIds = selectedToolIds.filter((id) => id !== toolId);
await init();
} catch (err) {
toast.error(err ?? $i18n.t('Failed to disconnect'));
}
}}
>
<LinkSlash className="size-3.5" />
</button>
</Tooltip>
</div>
{/if}
{#if tools?.[toolId]?.has_user_valves && ($user?.role === 'admin' || ($user?.permissions?.chat?.valves ?? true))}
<div class=" shrink-0">
<Tooltip content={$i18n.t('Valves')}>
<button
aria-label={$i18n.t('Valves')}
class="self-center w-fit text-sm text-gray-600 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-300 transition rounded-full"
type="button"
on:click={(e) => {
e.stopPropagation();
e.preventDefault();
onShowValves({
type: 'tool',
id: toolId
});
}}
>
<Knobs />
</button>
</Tooltip>
</div>
{/if}
<div class=" shrink-0" inert>
<Switch state={selectedToolIds.includes(toolId)} />
</div>
</div>
{/each}
</div>
{/if}
</div>
</div>
{:else if tab === 'skills' && skills}
<div class="flex max-h-72 min-h-0 flex-col gap-0.5" in:fly={{ x: 20, duration: 150 }}>
<button
role="menuitem"
class="flex w-full justify-between gap-2 items-center h-[1.6875rem] px-2 text-[0.8125rem] font-normal cursor-pointer rounded-xl hover:bg-gray-50/40 dark:hover:bg-gray-800/40"
on:click={() => {
skillQuery = '';
tab = '';
}}
>
<ChevronLeft />
<div class="flex items-center w-full justify-between">
<div>
{$i18n.t('Skills')}
<span class="ml-0.5 text-gray-500">{skillIds.length}</span>
</div>
</div>
</button>
<SearchInput bind:value={skillQuery} placeholder={$i18n.t('Search skills')} />
<div class="min-h-0 flex-1 overflow-y-auto overflow-x-hidden scrollbar-thin">
{#if skillIds.length === 0}
<div class="text-center text-xs text-gray-500 py-3">{$i18n.t('No skills found')}</div>
{:else}
<div class="flex flex-col gap-0.5">
{#each skillIds as skillId}
{#if filter?.has_user_valves && ($user?.role === 'admin' || ($user?.permissions?.chat?.valves ?? true))}
<div class=" shrink-0">
<Tooltip content={$i18n.t('Valves')}>
<button
class="relative flex w-full justify-between gap-2 items-center h-[1.6875rem] px-2 text-[0.8125rem] font-normal cursor-pointer rounded-xl hover:bg-gray-50/40 dark:hover:bg-gray-800/40"
role="menuitemcheckbox"
aria-checked={selectedSkillIds.includes(skillId)}
on:click={async () => {
await toggleSkill(skillId);
aria-label={$i18n.t('Valves')}
class="self-center w-fit text-sm text-gray-600 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-300 transition rounded-full"
type="button"
on:click={(e) => {
e.stopPropagation();
e.preventDefault();
onShowValves({
type: 'function',
id: filter.id
});
}}
>
<div class="flex-1 truncate">
<div class="flex flex-1 gap-2 items-center">
<Tooltip
content={resolveLocalizedResource(
skills?.[skillId],
$i18n.language,
'name'
)}
placement="top"
>
<div class="shrink-0">
<Cube className="size-3.5" strokeWidth="1.75" />
</div>
</Tooltip>
<Tooltip
content={resolveLocalizedResource(
skills?.[skillId],
$i18n.language,
'description'
)}
placement="top-start"
>
<div class=" truncate">
{resolveLocalizedResource(skills?.[skillId], $i18n.language, 'name')}
</div>
</Tooltip>
{#if skillSourceLabel(skills?.[skillId])}
<div class="shrink-0 text-[0.6875rem] text-gray-500 dark:text-gray-400">
{skillSourceLabel(skills?.[skillId])}
</div>
{/if}
</div>
</div>
<div class=" shrink-0" inert>
<Switch state={selectedSkillIds.includes(skillId)} />
</div>
<Knobs />
</button>
{/each}
</Tooltip>
</div>
{/if}
<div class=" shrink-0" inert>
<Switch state={selectedFilterIds.includes(filter.id)} />
</div>
</div>
</Tooltip>
{/each}
{/if}
{#if showWebSearchButton}
<Tooltip content={$i18n.t('Search the internet')} placement="top-start">
<button
class="flex w-full justify-between gap-2 items-center h-[1.6875rem] px-2 text-[0.8125rem] font-normal cursor-pointer rounded-xl hover:bg-gray-50/40 dark:hover:bg-gray-800/40"
role="menuitemcheckbox"
aria-checked={webSearchEnabled}
on:click={() => {
webSearchEnabled = !webSearchEnabled;
// Left open, this menu would swallow the first click on the confirmation dialog
if (webSearchEnabled && $config?.features?.enable_web_search_confirmation) {
show = false;
}
onWebSearchToggle(webSearchEnabled);
}}
>
<div class="flex-1 truncate">
<div class="flex flex-1 gap-2 items-center">
<div class="shrink-0">
<GlobeAlt className="size-3.5" strokeWidth="1.5" />
</div>
<div class=" truncate">{$i18n.t('Web Search')}</div>
</div>
</div>
<div class=" shrink-0" inert>
<Switch state={webSearchEnabled} />
</div>
</button>
</Tooltip>
{/if}
{#if showImageGenerationButton}
<Tooltip content={$i18n.t('Generate an image')} placement="top-start">
<button
class="flex w-full justify-between gap-2 items-center h-[1.6875rem] px-2 text-[0.8125rem] font-normal cursor-pointer rounded-xl hover:bg-gray-50/40 dark:hover:bg-gray-800/40"
role="menuitemcheckbox"
aria-checked={imageGenerationEnabled}
on:click={() => {
imageGenerationEnabled = !imageGenerationEnabled;
}}
>
<div class="flex-1 truncate">
<div class="flex flex-1 gap-2 items-center">
<div class="shrink-0">
<Photo className="size-3.5" strokeWidth="1.5" />
</div>
<div class=" truncate">{$i18n.t('Image')}</div>
</div>
</div>
<div class=" shrink-0" inert>
<Switch state={imageGenerationEnabled} />
</div>
</button>
</Tooltip>
{/if}
{#if showCodeInterpreterButton}
<Tooltip content={$i18n.t('Execute code for analysis')} placement="top-start">
<button
class="flex w-full justify-between gap-2 items-center h-[1.6875rem] px-2 text-[0.8125rem] font-normal cursor-pointer rounded-xl hover:bg-gray-50/40 dark:hover:bg-gray-800/40"
role="menuitemcheckbox"
aria-checked={codeInterpreterEnabled}
on:click={() => {
codeInterpreterEnabled = !codeInterpreterEnabled;
}}
>
<div class="flex-1 truncate">
<div class="flex flex-1 gap-2 items-center">
<div class="shrink-0">
<Terminal className="size-3.5" strokeWidth="1.75" />
</div>
<div class=" truncate">{$i18n.t('Code Interpreter')}</div>
</div>
</div>
<div class=" shrink-0" inert>
<Switch state={codeInterpreterEnabled} />
</div>
</button>
</Tooltip>
{/if}
</div>
{:else if tab === 'tools' && tools}
<div class="flex max-h-72 min-h-0 flex-col gap-0.5" in:fly={{ x: 20, duration: 150 }}>
<button
role="menuitem"
class="flex w-full justify-between gap-2 items-center h-[1.6875rem] px-2 text-[0.8125rem] font-normal cursor-pointer rounded-xl hover:bg-gray-50/40 dark:hover:bg-gray-800/40"
on:click={() => {
toolQuery = '';
tab = '';
}}
>
<ChevronLeft />
<div class="flex items-center w-full justify-between">
<div>
{$i18n.t('Tools')}
<span class="ml-0.5 text-gray-500">{toolIds.length}</span>
</div>
</div>
</button>
<SearchInput bind:value={toolQuery} placeholder={$i18n.t('Search tools')} />
<div class="min-h-0 flex-1 overflow-y-auto overflow-x-hidden scrollbar-thin">
{#if toolIds.length === 0}
<div class="text-center text-xs text-gray-500 py-3">{$i18n.t('No tools found')}</div>
{:else}
<div class="flex flex-col gap-0.5">
{#each toolIds as toolId}
<div
class="relative flex w-full justify-between gap-2 items-center h-[1.6875rem] px-2 text-[0.8125rem] font-normal cursor-pointer rounded-xl hover:bg-gray-50/40 dark:hover:bg-gray-800/40 has-[[role^=menuitem]:focus-visible]:outline-2 has-[[role^=menuitem]:focus-visible]:-outline-offset-2 has-[[role^=menuitem]:focus-visible]:outline-blue-500"
role="presentation"
on:click={async (e) => {
await toggleTool(toolId, e);
}}
>
{#if !(tools?.[toolId]?.authenticated ?? true)}
<!-- make it slighly darker and not clickable -->
<div class="absolute inset-0 opacity-50 rounded-xl cursor-pointer z-10"></div>
{/if}
<button
type="button"
class="flex-1 truncate text-left cursor-pointer focus-visible:outline-none!"
role={(tools?.[toolId]?.authenticated ?? true) ? 'menuitemcheckbox' : 'menuitem'}
aria-checked={(tools?.[toolId]?.authenticated ?? true)
? selectedToolIds.includes(toolId)
: undefined}
>
<div class="flex flex-1 gap-2 items-center">
<Tooltip
content={resolveLocalizedResource(tools?.[toolId], $i18n.language, 'name')}
placement="top"
>
<div class="shrink-0">
<Wrench />
</div>
</Tooltip>
<Tooltip
content={resolveLocalizedResource(
tools?.[toolId],
$i18n.language,
'description'
)}
placement="top-start"
>
<div class=" truncate">
{resolveLocalizedResource(tools?.[toolId], $i18n.language, 'name')}
</div>
</Tooltip>
</div>
</button>
{#if tools?.[toolId]?.authenticated === true && toolId.startsWith('server:mcp:')}
<div class="shrink-0">
<Tooltip content={$i18n.t('Disconnect OAuth')}>
<button
aria-label={$i18n.t('Disconnect OAuth')}
class="self-center w-fit text-sm text-gray-600 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-300 transition rounded-full"
type="button"
on:click={async (e) => {
e.stopPropagation();
e.preventDefault();
const parts = toolId.split(':');
const serverId = parts.at(-1) ?? toolId;
const provider = `mcp:${serverId}`;
try {
await deleteOAuthSession(localStorage.token, provider);
toast.success($i18n.t('OAuth session disconnected'));
// Refresh tools to update authenticated state
_tools.set(await getTools(localStorage.token));
selectedToolIds = selectedToolIds.filter((id) => id !== toolId);
await init();
} catch (err) {
toast.error(err ?? $i18n.t('Failed to disconnect'));
}
}}
>
<LinkSlash className="size-3.5" />
</button>
</Tooltip>
</div>
{/if}
{#if tools?.[toolId]?.has_user_valves && ($user?.role === 'admin' || ($user?.permissions?.chat?.valves ?? true))}
<div class=" shrink-0">
<Tooltip content={$i18n.t('Valves')}>
<button
aria-label={$i18n.t('Valves')}
class="self-center w-fit text-sm text-gray-600 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-300 transition rounded-full"
type="button"
on:click={(e) => {
e.stopPropagation();
e.preventDefault();
onShowValves({
type: 'tool',
id: toolId
});
}}
>
<Knobs />
</button>
</Tooltip>
</div>
{/if}
<div class=" shrink-0" inert>
<Switch state={selectedToolIds.includes(toolId)} />
</div>
</div>
{/each}
</div>
{/if}
</DropdownMenu>
</div>
</div>
</Dropdown>
{:else if tab === 'skills' && skills}
<div class="flex max-h-72 min-h-0 flex-col gap-0.5" in:fly={{ x: 20, duration: 150 }}>
<button
role="menuitem"
class="flex w-full justify-between gap-2 items-center h-[1.6875rem] px-2 text-[0.8125rem] font-normal cursor-pointer rounded-xl hover:bg-gray-50/40 dark:hover:bg-gray-800/40"
on:click={() => {
skillQuery = '';
tab = '';
}}
>
<ChevronLeft />
<div class="flex items-center w-full justify-between">
<div>
{$i18n.t('Skills')}
<span class="ml-0.5 text-gray-500">{skillIds.length}</span>
</div>
</div>
</button>
<SearchInput bind:value={skillQuery} placeholder={$i18n.t('Search skills')} />
<div class="min-h-0 flex-1 overflow-y-auto overflow-x-hidden scrollbar-thin">
{#if skillIds.length === 0}
<div class="text-center text-xs text-gray-500 py-3">{$i18n.t('No skills found')}</div>
{:else}
<div class="flex flex-col gap-0.5">
{#each skillIds as skillId}
<button
class="relative flex w-full justify-between gap-2 items-center h-[1.6875rem] px-2 text-[0.8125rem] font-normal cursor-pointer rounded-xl hover:bg-gray-50/40 dark:hover:bg-gray-800/40"
role="menuitemcheckbox"
aria-checked={selectedSkillIds.includes(skillId)}
on:click={async () => {
await toggleSkill(skillId);
}}
>
<div class="flex-1 truncate">
<div class="flex flex-1 gap-2 items-center">
<Tooltip
content={resolveLocalizedResource(skills?.[skillId], $i18n.language, 'name')}
placement="top"
>
<div class="shrink-0">
<Cube className="size-3.5" strokeWidth="1.75" />
</div>
</Tooltip>
<Tooltip
content={resolveLocalizedResource(
skills?.[skillId],
$i18n.language,
'description'
)}
placement="top-start"
>
<div class=" truncate">
{resolveLocalizedResource(skills?.[skillId], $i18n.language, 'name')}
</div>
</Tooltip>
{#if skillSourceLabel(skills?.[skillId])}
<div class="shrink-0 text-[0.6875rem] text-gray-500 dark:text-gray-400">
{skillSourceLabel(skills?.[skillId])}
</div>
{/if}
</div>
</div>
<div class=" shrink-0" inert>
<Switch state={selectedSkillIds.includes(skillId)} />
</div>
</button>
{/each}
</div>
{/if}
</div>
</div>
{/if}
@@ -3,6 +3,8 @@
import { resolveTerminalConnection, type TerminalConnection } from '$lib/apis/terminal';
import TerminalSystemInfoModal from '../TerminalSystemInfoModal.svelte';
import Activity from '$lib/components/icons/Activity.svelte';
import WorkingDirectoryMenu from './WorkingDirectoryMenu.svelte';
import type { TerminalContext } from '$lib/types';
import {
chatId as activeChatId,
@@ -27,6 +29,8 @@
export let show = false;
export let disabled = false;
export let chatId: string | null = null;
export let terminalContext: TerminalContext | null = null;
const chatContext = (terminal: any) => terminal?.contexts?.chat ?? {};
@@ -124,6 +128,12 @@
$: selectedSystemTerminal = systemTerminals.find((t) => t.id === $selectedTerminalId);
$: selectedDirectTerminal = directTerminals.find((t) => t.url === $selectedTerminalId);
$: folderConnection = resolveTerminalConnection(
$selectedTerminalId,
systemTerminals,
directTerminals,
''
);
$: selectedDevice = !!selectedSystemTerminal && isDevice(selectedSystemTerminal);
$: selectedLabel =
@@ -428,3 +438,15 @@
/>
{/key}
{/if}
{#if folderConnection && (chatContext(selectedSystemTerminal)?.context_id !== 'chat_id' || isSavedChatId(chatId))}
{#key `${$user?.id}:${folderConnection.selector}:${chatId ?? ''}`}
<WorkingDirectoryMenu
connection={folderConnection}
{chatId}
userId={$user?.id ?? ''}
bind:terminalContext
{disabled}
/>
{/key}
{/if}
@@ -0,0 +1,258 @@
<script lang="ts">
import { getContext, onMount, onDestroy } from 'svelte';
import { toast } from 'svelte-sonner';
import { getCwd, setCwd, type TerminalConnection } from '$lib/apis/terminal';
import { loadRecentFolders, rememberRecentFolder } from '$lib/apis/terminal/recentFolders';
import type { TerminalContext } from '$lib/types';
import Dropdown from '$lib/components/common/Dropdown.svelte';
import DropdownMenu from '$lib/components/common/DropdownMenu.svelte';
import Modal from '$lib/components/common/Modal.svelte';
import Folder from '$lib/components/icons/Folder.svelte';
import FolderOpen from '$lib/components/icons/FolderOpen.svelte';
import Tooltip from '$lib/components/common/Tooltip.svelte';
import SearchInput from './InputMenu/SearchInput.svelte';
import Check from '$lib/components/icons/Check.svelte';
import XMark from '$lib/components/icons/XMark.svelte';
import FileNav from '../FileNav.svelte';
const i18n = getContext<any>('i18n');
export let connection: TerminalConnection;
export let chatId: string | null = null;
export let userId: string;
export let terminalContext: TerminalContext | null = null;
export let disabled = false;
let show = false;
let showPicker = false;
let search = '';
let cwd = '';
let recent: string[] = [];
let saving = false;
let disposed = false;
let home = '';
let historyError = '';
let historyVersion = 0;
let initialization: Promise<void>;
const folderName = (path: string) => path.replace(/\/+$/, '').split('/').pop() || '/';
const normalize = (path: string) => path.replace(/\/+$/, '') || '/';
$: directory =
terminalContext?.terminalId === connection.selector
? (terminalContext.currentDirectory ?? cwd)
: cwd;
$: options = [...new Set([directory, ...recent].filter(Boolean).map(normalize))].filter((path) =>
path.toLowerCase().includes(search.trim().toLowerCase())
);
$: if (disabled && show) show = false;
$: if (disabled && showPicker) showPicker = false;
async function refreshRecentFolders() {
const version = ++historyVersion;
try {
await initialization;
if (disposed) return;
if (!home) {
const result = await getCwd(connection.baseUrl, connection.key, chatId ?? undefined);
if (disposed) return;
home = result?.home ?? '';
}
if (!home) throw new Error('Terminal home is unavailable');
const paths = await loadRecentFolders(connection, chatId, home, userId);
if (disposed || version !== historyVersion) return;
recent = paths;
historyError = '';
} catch {
if (!disposed && version === historyVersion)
historyError = $i18n.t('Failed to load recent folders');
}
}
onMount(() => {
if (!chatId && terminalContext?.terminalId !== connection.selector) {
terminalContext = { terminalId: connection.selector, currentDirectory: '' };
}
initialization = getCwd(connection.baseUrl, connection.key, chatId ?? undefined).then(
(result) => {
if (disposed) return;
home = result?.home ?? '';
if (chatId) cwd = result?.cwd ?? '';
}
);
void refreshRecentFolders();
});
onDestroy(() => (disposed = true));
async function selectDirectory(path: string) {
if (disabled || saving) return;
saving = true;
const result = await setCwd(connection.baseUrl, connection.key, path, chatId ?? undefined);
if (disposed) return;
if (!result?.cwd) {
saving = false;
toast.error($i18n.t('Failed to load folder'));
return;
}
// An empty path resets the terminal to its default directory.
cwd = path ? result.cwd : '';
terminalContext = { terminalId: connection.selector, currentDirectory: cwd };
if (cwd) {
recent = [
normalize(cwd),
...recent.filter((entry) => normalize(entry) !== normalize(cwd))
].slice(0, 8);
}
// Ignore history reads started before this selection.
++historyVersion;
if (cwd) {
try {
await initialization;
if (disposed) return;
await rememberRecentFolder(connection, chatId, home, userId, cwd);
if (disposed) return;
historyError = '';
} catch {
if (disposed) return;
historyError = $i18n.t('Failed to save recent folders');
toast.error(historyError);
}
}
saving = false;
show = false;
showPicker = false;
}
</script>
<div class="flex items-center translate-x-0.5">
<Dropdown
bind:show
align="start"
onOpenChange={(open) => {
search = '';
if (open) void refreshRecentFolders();
}}
>
<Tooltip content={directory || $i18n.t('Working Directory')} placement="top">
<button
type="button"
disabled={disabled || saving}
aria-label={$i18n.t('Choose working directory')}
class="flex min-w-0 items-center gap-1.5 translate-y-[1px] rounded-lg p-1 text-[0.8125rem] transition {disabled ||
saving
? 'cursor-not-allowed opacity-40 text-gray-400 dark:text-gray-600'
: directory
? 'cursor-pointer text-gray-600 hover:text-gray-700 dark:text-gray-300 dark:hover:text-gray-200'
: 'cursor-pointer text-gray-400 hover:text-gray-600 dark:text-gray-500 dark:hover:text-gray-300'}"
>
<Folder className="size-3.5 shrink-0" strokeWidth="2" />
<span data-input-label class="max-w-[9.375rem] truncate"
>{directory ? folderName(directory) : $i18n.t('Choose...')}</span
>
</button>
</Tooltip>
<div slot="content">
<DropdownMenu className="w-56 max-w-[calc(100vw-2rem)]">
<SearchInput bind:value={search} placeholder={$i18n.t('Search folders')} />
<hr class="mx-1 my-0.5 border-gray-50/30 dark:border-gray-800/30" />
<button
type="button"
role="menuitemradio"
aria-checked={!directory}
disabled={saving || disabled}
class="flex h-[1.6875rem] w-full items-center gap-2 rounded-xl px-2 text-[0.8125rem] font-normal cursor-pointer disabled:cursor-not-allowed disabled:opacity-40 {!directory
? 'bg-gray-50/40 dark:bg-gray-800/40'
: 'hover:bg-gray-50/40 dark:hover:bg-gray-800/40'}"
on:click={() => selectDirectory('')}
>
<Folder className="size-3.5 shrink-0" strokeWidth="2" />
<span class="flex-1 text-start">{$i18n.t('No folder')}</span>
{#if !directory}
<Check
className="size-3.5 shrink-0 text-emerald-600 dark:text-emerald-400"
strokeWidth="2"
/>
{/if}
</button>
{#if options.length > 0}
<div
class="px-2 py-1 text-[0.625rem] font-normal text-gray-400 dark:text-gray-500 uppercase tracking-wider"
>
{$i18n.t('Recently Used')}
</div>
{#if historyError}
<div role="status" class="px-2 py-1 text-[0.6875rem] text-gray-500 dark:text-gray-400">
{historyError}
</div>
{/if}
<div class="max-h-60 overflow-y-auto overflow-x-hidden scrollbar-thin">
{#each options as path}
{@const selected = !!directory && normalize(directory) === path}
<button
type="button"
role="menuitemradio"
aria-checked={selected}
disabled={saving || disabled}
title={path}
class="flex h-[1.6875rem] w-full items-center justify-between gap-2 rounded-xl px-2 text-[0.8125rem] font-normal cursor-pointer disabled:cursor-not-allowed disabled:opacity-40 {selected
? 'bg-gray-50/40 dark:bg-gray-800/40'
: 'hover:bg-gray-50/40 dark:hover:bg-gray-800/40'}"
on:click={() => selectDirectory(path)}
>
<div class="flex min-w-0 flex-1 items-center gap-2">
<Folder className="size-3.5 shrink-0" strokeWidth="2" />
<span class="truncate">{folderName(path)}</span>
</div>
{#if selected}
<Check
className="size-3.5 shrink-0 text-emerald-600 dark:text-emerald-400"
strokeWidth="2"
/>
{/if}
</button>
{/each}
</div>
{/if}
<hr class="mx-1 my-0.5 border-gray-50/30 dark:border-gray-800/30" />
<button
type="button"
disabled={saving || disabled}
class="flex h-[1.6875rem] w-full items-center gap-2 rounded-xl px-2 text-start text-[0.8125rem] font-normal cursor-pointer hover:bg-gray-50/40 disabled:cursor-not-allowed disabled:opacity-40 dark:hover:bg-gray-800/40"
on:click={() => {
show = false;
showPicker = true;
}}
>
<FolderOpen className="size-3.5 shrink-0" strokeWidth="2" />
<span>{$i18n.t('Open Folder')}</span>
</button>
</DropdownMenu>
</div>
</Dropdown>
</div>
{#if showPicker}
<Modal bind:show={showPicker} ariaLabel={$i18n.t('Choose working directory')} size="md">
<div class="p-4">
<div class="mb-3 flex items-center justify-between text-sm">
<span>{$i18n.t('Choose working directory')}</span>
<button
type="button"
aria-label={$i18n.t('Close')}
class="text-gray-500 hover:text-gray-900 dark:hover:text-gray-100"
on:click={() => (showPicker = false)}
>
<XMark className="size-4" />
</button>
</div>
<div class="h-[60dvh] min-h-0" aria-busy={saving}>
<FileNav
terminalId={connection.selector}
{chatId}
initialDirectory={directory || null}
manageFileRequests={false}
showTerminalDock={false}
onSelectDirectory={selectDirectory}
/>
</div>
</div>
</Modal>
{/if}
+1 -1
View File
@@ -260,7 +260,7 @@
{#if !($selectedFolder && folderReadOnly)}
<MessageInput
{chatId}
{terminalContext}
bind:terminalContext
{callActive}
{callEnabled}
bind:this={messageInput}
@@ -69,6 +69,7 @@
let richTextInput = true;
let showFormattingToolbar = false;
let showInputSelections = false;
let insertPromptAsRichText = false;
let promptAutocomplete = false;
@@ -354,6 +355,7 @@
richTextInput = currentSettings?.richTextInput ?? true;
showFormattingToolbar = currentSettings?.showFormattingToolbar ?? false;
showInputSelections = currentSettings?.showInputSelections ?? false;
insertPromptAsRichText = currentSettings?.insertPromptAsRichText ?? false;
promptAutocomplete = currentSettings?.promptAutocomplete ?? false;
@@ -1707,6 +1709,33 @@
</p>
</div>
<div>
<div class={settingRowClass}>
<label
id="show-input-selections-label"
class={settingLabelClass}
for="show-input-selections-label-control"
>
{$i18n.t('settings.personal.interface.showInputSelections.label')}
</label>
<div class={settingControlClass}>
<Switch
ariaLabelledbyId="show-input-selections-label"
tooltip={true}
bind:state={showInputSelections}
inherited={isDefaultSetting('showInputSelections')}
on:change={() => {
saveSettings({ showInputSelections });
}}
/>
</div>
</div>
<p class={settingDescriptionClass}>
{$i18n.t('settings.personal.interface.showInputSelections.description')}
</p>
</div>
{#if $visibleControls['settings.rich_text_input']}
<div>
<div class={settingRowClass}>
@@ -129,6 +129,7 @@
"Active Users": "",
"Activity": "",
"Add": "",
"Add Context": "Add Context",
"Add a comment…": "",
"Add a model ID": "",
"Add a preference, fact, or instruction about you": "",
@@ -3800,6 +3801,8 @@
"settings.personal.interface.showFilesOnTerminalSelect.label": "Show Files on Terminal Select",
"settings.personal.interface.showFormattingToolbar.description": "Show formatting controls in the rich text composer.",
"settings.personal.interface.showFormattingToolbar.label": "Show Formatting Toolbar",
"settings.personal.interface.showInputSelections.description": "Show selected tools, skills, filters, and capabilities beside the + menu. Hiding them preserves your selections.",
"settings.personal.interface.showInputSelections.label": "Show Input Selections",
"settings.personal.interface.stylizedPdfExport.description": "Use styled formatting when exporting chats to PDF.",
"settings.personal.interface.stylizedPdfExport.label": "Stylized PDF Export",
"settings.personal.interface.temporaryChatByDefault.description": "Start new chats as temporary unless changed.",
+1
View File
@@ -296,6 +296,7 @@ type Settings = {
responseAutoCopy?: any;
richTextInput?: boolean;
showFormattingToolbar?: boolean;
showInputSelections?: boolean;
params?: any;
userLocation?: any;
webSearch?: any;