This commit is contained in:
Timothy Jaeryang Baek committed 2026-11-08 01:28:41 +09:00
1 parent dc22fa8f86
commit 834c47ee02
14 files changed
+948 -572

No files matched your search

@@ -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 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>
{#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>
{/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}