2024-05-27 20:22:24 +00:00
|
|
|
<script lang="ts">
|
|
|
|
import { DropdownMenu } from 'bits-ui';
|
|
|
|
import { flyAndScale } from '$lib/utils/transitions';
|
|
|
|
import { getContext } from 'svelte';
|
|
|
|
|
|
|
|
import Dropdown from '$lib/components/common/Dropdown.svelte';
|
|
|
|
import Tooltip from '$lib/components/common/Tooltip.svelte';
|
|
|
|
import DocumentArrowUpSolid from '$lib/components/icons/DocumentArrowUpSolid.svelte';
|
|
|
|
import Switch from '$lib/components/common/Switch.svelte';
|
|
|
|
import GlobeAltSolid from '$lib/components/icons/GlobeAltSolid.svelte';
|
2024-05-27 21:25:36 +00:00
|
|
|
import { config } from '$lib/stores';
|
2024-06-11 05:29:24 +00:00
|
|
|
import WrenchSolid from '$lib/components/icons/WrenchSolid.svelte';
|
2024-05-27 20:22:24 +00:00
|
|
|
|
|
|
|
const i18n = getContext('i18n');
|
|
|
|
|
|
|
|
export let uploadFilesHandler: Function;
|
2024-06-11 07:18:45 +00:00
|
|
|
|
|
|
|
export let selectedToolIds: string[] = [];
|
2024-05-27 20:22:24 +00:00
|
|
|
export let webSearchEnabled: boolean;
|
|
|
|
|
2024-06-11 05:29:24 +00:00
|
|
|
export let tools = {};
|
2024-05-27 20:22:24 +00:00
|
|
|
export let onClose: Function;
|
|
|
|
|
2024-06-12 01:23:42 +00:00
|
|
|
$: tools = Object.fromEntries(
|
|
|
|
Object.keys(tools).map((toolId) => [
|
|
|
|
toolId,
|
|
|
|
{
|
|
|
|
...tools[toolId],
|
|
|
|
enabled: selectedToolIds.includes(toolId)
|
|
|
|
}
|
|
|
|
])
|
|
|
|
);
|
|
|
|
|
2024-05-27 20:22:24 +00:00
|
|
|
let show = false;
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<Dropdown
|
|
|
|
bind:show
|
|
|
|
on:change={(e) => {
|
|
|
|
if (e.detail === false) {
|
|
|
|
onClose();
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Tooltip content={$i18n.t('More')}>
|
|
|
|
<slot />
|
|
|
|
</Tooltip>
|
|
|
|
|
|
|
|
<div slot="content">
|
|
|
|
<DropdownMenu.Content
|
2024-06-12 00:09:10 +00:00
|
|
|
class="w-full max-w-[200px] rounded-xl px-1 py-1 border-gray-300/30 dark:border-gray-700/50 z-50 bg-white dark:bg-gray-850 dark:text-white shadow"
|
2024-05-27 20:22:24 +00:00
|
|
|
sideOffset={15}
|
|
|
|
alignOffset={-8}
|
|
|
|
side="top"
|
|
|
|
align="start"
|
|
|
|
transition={flyAndScale}
|
|
|
|
>
|
2024-06-11 05:29:24 +00:00
|
|
|
{#if Object.keys(tools).length > 0}
|
2024-06-11 19:16:11 +00:00
|
|
|
<div class=" max-h-28 overflow-y-auto scrollbar-hidden">
|
|
|
|
{#each Object.keys(tools) as toolId}
|
|
|
|
<div
|
|
|
|
class="flex gap-2 items-center px-3 py-2 text-sm font-medium cursor-pointer rounded-xl"
|
|
|
|
>
|
|
|
|
<div class="flex-1 flex items-center gap-2">
|
2024-06-11 23:15:54 +00:00
|
|
|
<WrenchSolid />
|
|
|
|
<Tooltip content={tools[toolId]?.description ?? ''} className="flex-1">
|
|
|
|
<div class=" line-clamp-1">{tools[toolId].name}</div>
|
2024-06-11 19:16:11 +00:00
|
|
|
</Tooltip>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<Switch
|
|
|
|
bind:state={tools[toolId].enabled}
|
|
|
|
on:change={(e) => {
|
|
|
|
selectedToolIds = e.detail
|
|
|
|
? [...selectedToolIds, toolId]
|
|
|
|
: selectedToolIds.filter((id) => id !== toolId);
|
|
|
|
}}
|
|
|
|
/>
|
2024-06-11 05:29:24 +00:00
|
|
|
</div>
|
2024-06-11 19:16:11 +00:00
|
|
|
{/each}
|
|
|
|
</div>
|
2024-06-11 05:29:24 +00:00
|
|
|
|
|
|
|
<hr class="border-gray-100 dark:border-gray-800 my-1" />
|
|
|
|
{/if}
|
|
|
|
|
2024-05-27 21:25:36 +00:00
|
|
|
{#if $config?.features?.enable_web_search}
|
|
|
|
<div
|
|
|
|
class="flex gap-2 items-center px-3 py-2 text-sm font-medium cursor-pointer rounded-xl"
|
|
|
|
>
|
|
|
|
<div class="flex-1 flex items-center gap-2">
|
|
|
|
<GlobeAltSolid />
|
2024-06-12 09:09:00 +00:00
|
|
|
<div class=" line-clamp-1">{$i18n.t('Web Search')}</div>
|
2024-05-27 21:25:36 +00:00
|
|
|
</div>
|
2024-05-27 20:22:24 +00:00
|
|
|
|
2024-05-27 21:25:36 +00:00
|
|
|
<Switch bind:state={webSearchEnabled} />
|
|
|
|
</div>
|
2024-05-27 20:22:24 +00:00
|
|
|
|
2024-05-27 21:25:36 +00:00
|
|
|
<hr class="border-gray-100 dark:border-gray-800 my-1" />
|
|
|
|
{/if}
|
2024-05-27 20:22:24 +00:00
|
|
|
|
|
|
|
<DropdownMenu.Item
|
|
|
|
class="flex gap-2 items-center px-3 py-2 text-sm font-medium cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800 rounded-xl"
|
|
|
|
on:click={() => {
|
|
|
|
uploadFilesHandler();
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<DocumentArrowUpSolid />
|
2024-06-12 09:09:00 +00:00
|
|
|
<div class=" line-clamp-1">{$i18n.t('Upload Files')}</div>
|
2024-05-27 20:22:24 +00:00
|
|
|
</DropdownMenu.Item>
|
|
|
|
</DropdownMenu.Content>
|
|
|
|
</div>
|
|
|
|
</Dropdown>
|