2025-03-29 03:40:56 +08:00
|
|
|
<script lang="ts">
|
|
|
|
|
import { getContext, onMount } from 'svelte';
|
2025-04-05 15:05:47 +08:00
|
|
|
import { models, config, toolServers, tools } from '$lib/stores';
|
2025-03-29 03:40:56 +08:00
|
|
|
|
|
|
|
|
import { toast } from 'svelte-sonner';
|
|
|
|
|
import { deleteSharedChatById, getChatById, shareChatById } from '$lib/apis/chats';
|
|
|
|
|
import { copyToClipboard } from '$lib/utils';
|
|
|
|
|
|
|
|
|
|
import Modal from '../common/Modal.svelte';
|
|
|
|
|
import Link from '../icons/Link.svelte';
|
|
|
|
|
import Collapsible from '../common/Collapsible.svelte';
|
2025-06-26 06:44:45 +08:00
|
|
|
import XMark from '$lib/components/icons/XMark.svelte';
|
2025-03-29 03:40:56 +08:00
|
|
|
|
|
|
|
|
export let show = false;
|
2025-04-05 15:05:47 +08:00
|
|
|
export let selectedToolIds = [];
|
|
|
|
|
|
|
|
|
|
let selectedTools = [];
|
|
|
|
|
|
2025-04-09 03:51:48 +08:00
|
|
|
$: selectedTools = ($tools ?? []).filter((tool) => selectedToolIds.includes(tool.id));
|
2025-03-29 03:40:56 +08:00
|
|
|
|
|
|
|
|
const i18n = getContext('i18n');
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<Modal bind:show size="md">
|
|
|
|
|
<div>
|
|
|
|
|
<div class=" flex justify-between dark:text-gray-300 px-5 pt-4 pb-0.5">
|
2025-04-05 15:05:47 +08:00
|
|
|
<div class=" text-lg font-medium self-center">{$i18n.t('Available Tools')}</div>
|
2025-03-29 03:40:56 +08:00
|
|
|
<button
|
|
|
|
|
class="self-center"
|
|
|
|
|
on:click={() => {
|
|
|
|
|
show = false;
|
|
|
|
|
}}
|
|
|
|
|
>
|
2025-06-27 19:44:26 +08:00
|
|
|
<XMark className={'size-5'} />
|
2025-03-29 03:40:56 +08:00
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
|
2025-04-05 15:05:47 +08:00
|
|
|
{#if selectedTools.length > 0}
|
|
|
|
|
{#if $toolServers.length > 0}
|
|
|
|
|
<div class=" flex justify-between dark:text-gray-300 px-5 pb-1">
|
|
|
|
|
<div class=" text-base font-medium self-center">{$i18n.t('Tools')}</div>
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
2025-03-29 03:40:56 +08:00
|
|
|
|
2025-04-05 15:05:47 +08:00
|
|
|
<div class="px-5 pb-3 w-full flex flex-col justify-center">
|
|
|
|
|
<div class=" text-sm dark:text-gray-300 mb-1">
|
|
|
|
|
{#each selectedTools as tool}
|
|
|
|
|
<Collapsible buttonClassName="w-full mb-0.5">
|
|
|
|
|
<div>
|
|
|
|
|
<div class="text-sm font-medium dark:text-gray-100 text-gray-800">
|
|
|
|
|
{tool?.name}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{#if tool?.meta?.description}
|
|
|
|
|
<div class="text-xs text-gray-500">
|
|
|
|
|
{tool?.meta?.description}
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
2025-03-29 03:40:56 +08:00
|
|
|
</div>
|
|
|
|
|
|
2025-04-05 15:05:47 +08:00
|
|
|
<!-- <div slot="content">
|
|
|
|
|
{JSON.stringify(tool, null, 2)}
|
|
|
|
|
</div> -->
|
|
|
|
|
</Collapsible>
|
|
|
|
|
{/each}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
|
|
|
|
|
|
|
|
|
{#if $toolServers.length > 0}
|
|
|
|
|
<div class=" flex justify-between dark:text-gray-300 px-5 pb-0.5">
|
|
|
|
|
<div class=" text-base font-medium self-center">{$i18n.t('Tool Servers')}</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="px-5 pb-5 w-full flex flex-col justify-center">
|
|
|
|
|
<div class=" text-xs text-gray-600 dark:text-gray-300 mb-2">
|
2025-04-07 06:37:27 +08:00
|
|
|
{$i18n.t('Open WebUI can use tools provided by any OpenAPI server.')} <br /><a
|
2025-04-05 15:05:47 +08:00
|
|
|
class="underline"
|
|
|
|
|
href="https://github.com/open-webui/openapi-servers"
|
2025-04-07 06:37:27 +08:00
|
|
|
target="_blank">{$i18n.t('Learn more about OpenAPI tool servers.')}</a
|
2025-04-05 15:05:47 +08:00
|
|
|
>
|
|
|
|
|
</div>
|
|
|
|
|
<div class=" text-sm dark:text-gray-300 mb-1">
|
|
|
|
|
{#each $toolServers as toolServer}
|
|
|
|
|
<Collapsible buttonClassName="w-full" chevron>
|
|
|
|
|
<div>
|
|
|
|
|
<div class="text-sm font-medium dark:text-gray-100 text-gray-800">
|
|
|
|
|
{toolServer?.openapi?.info?.title} - v{toolServer?.openapi?.info?.version}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="text-xs text-gray-500">
|
|
|
|
|
{toolServer?.openapi?.info?.description}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="text-xs text-gray-500">
|
|
|
|
|
{toolServer?.url}
|
|
|
|
|
</div>
|
2025-03-29 03:40:56 +08:00
|
|
|
</div>
|
|
|
|
|
|
2025-04-05 15:05:47 +08:00
|
|
|
<div slot="content">
|
|
|
|
|
{#each toolServer?.specs ?? [] as tool_spec}
|
|
|
|
|
<div class="my-1">
|
|
|
|
|
<div class="font-medium text-gray-800 dark:text-gray-100">
|
|
|
|
|
{tool_spec?.name}
|
|
|
|
|
</div>
|
2025-03-29 03:40:56 +08:00
|
|
|
|
2025-04-05 15:05:47 +08:00
|
|
|
<div>
|
|
|
|
|
{tool_spec?.description}
|
|
|
|
|
</div>
|
2025-03-29 03:40:56 +08:00
|
|
|
</div>
|
2025-04-05 15:05:47 +08:00
|
|
|
{/each}
|
|
|
|
|
</div>
|
|
|
|
|
</Collapsible>
|
|
|
|
|
{/each}
|
|
|
|
|
</div>
|
2025-03-29 03:40:56 +08:00
|
|
|
</div>
|
2025-04-05 15:05:47 +08:00
|
|
|
{/if}
|
2025-03-29 03:40:56 +08:00
|
|
|
</div>
|
|
|
|
|
</Modal>
|