diff --git a/src/lib/components/chat/Controls/Valves.svelte b/src/lib/components/chat/Controls/Valves.svelte index 8cf7ac39b..ab2e0895c 100644 --- a/src/lib/components/chat/Controls/Valves.svelte +++ b/src/lib/components/chat/Controls/Valves.svelte @@ -7,12 +7,14 @@ import { getUserValvesSpecById as getToolUserValvesSpecById, getUserValvesById as getToolUserValvesById, - updateUserValvesById as updateToolUserValvesById + updateUserValvesById as updateToolUserValvesById, + getTools } from '$lib/apis/tools'; import { getUserValvesSpecById as getFunctionUserValvesSpecById, getUserValvesById as getFunctionUserValvesById, - updateUserValvesById as updateFunctionUserValvesById + updateUserValvesById as updateFunctionUserValvesById, + getFunctions } from '$lib/apis/functions'; import Tooltip from '$lib/components/common/Tooltip.svelte'; @@ -112,77 +114,94 @@ $: if (selectedId) { getUserValves(); } + + onMount(async () => { + loading = true; + + if ($functions.length === 0) { + functions.set(await getFunctions(localStorage.token)); + } + if ($tools.length === 0) { + tools.set(await getTools(localStorage.token)); + } + + loading = false; + }); -
{ - submitHandler(); - dispatch('save'); - }} -> -
-
-
-
- - -
- -
- +
- {#each $tools as tool, toolIdx} - - {/each} - {:else if tab === 'functions'} - +
+ + {#each $tools as tool, toolIdx} + + {/each} + {:else if tab === 'functions'} + + + {#each $functions as func, funcIdx} + + {/each} + {/if} + +
+ + {#if selectedId} +
+ +
+ {#if !loading} + { + debounceSubmitHandler(); + }} + /> + {:else} + + {/if} +
+ {/if}
- - {#if selectedId} -
- -
- {#if !loading} - { - debounceSubmitHandler(); - }} - /> - {:else} - - {/if} -
- {/if} - -
+ +{:else} + +{/if} diff --git a/src/lib/components/chat/MessageInput.svelte b/src/lib/components/chat/MessageInput.svelte index 4d8ea5d70..39cb88b9e 100644 --- a/src/lib/components/chat/MessageInput.svelte +++ b/src/lib/components/chat/MessageInput.svelte @@ -519,16 +519,7 @@ { - if (availableToolIds.includes(e.id) || ($_user?.role ?? 'user') === 'admin') { - a[e.id] = { - name: e.name, - description: e.meta.description, - enabled: false - }; - } - return a; - }, {})} + {availableToolIds} uploadFilesHandler={() => { filesInputElement.click(); }} diff --git a/src/lib/components/chat/MessageInput/Commands.svelte b/src/lib/components/chat/MessageInput/Commands.svelte index 09a2f819c..0124d37aa 100644 --- a/src/lib/components/chat/MessageInput/Commands.svelte +++ b/src/lib/components/chat/MessageInput/Commands.svelte @@ -1,19 +1,24 @@ -{#if ['/', '#', '@'].includes(command?.charAt(0)) || '\\#' === command.slice(0, 2)} - {#if command?.charAt(0) === '/'} - - {:else if (command?.charAt(0) === '#' && command.startsWith('#') && !command.includes('# ')) || ('\\#' === command.slice(0, 2) && command.startsWith('#') && !command.includes('# '))} - { - console.log(e); - dispatch('upload', { - type: 'youtube', - data: e.detail - }); - }} - on:url={(e) => { - console.log(e); - dispatch('upload', { - type: 'web', - data: e.detail - }); - }} - on:select={(e) => { - console.log(e); - files = [ - ...files, - { - ...e.detail, - status: 'processed' - } - ]; +{#if show} + {#if !loading} + {#if command?.charAt(0) === '/'} + + {:else if (command?.charAt(0) === '#' && command.startsWith('#') && !command.includes('# ')) || ('\\#' === command.slice(0, 2) && command.startsWith('#') && !command.includes('# '))} + { + console.log(e); + dispatch('upload', { + type: 'youtube', + data: e.detail + }); + }} + on:url={(e) => { + console.log(e); + dispatch('upload', { + type: 'web', + data: e.detail + }); + }} + on:select={(e) => { + console.log(e); + files = [ + ...files, + { + ...e.detail, + status: 'processed' + } + ]; - dispatch('select'); - }} - /> - {:else if command?.charAt(0) === '@'} - { - prompt = removeLastWordFromString(prompt, command); + dispatch('select'); + }} + /> + {:else if command?.charAt(0) === '@'} + { + prompt = removeLastWordFromString(prompt, command); - dispatch('select', { - type: 'model', - data: e.detail - }); - }} - /> + dispatch('select', { + type: 'model', + data: e.detail + }); + }} + /> + {/if} + {:else} +
+
+
+ +
+
+
{/if} {/if} diff --git a/src/lib/components/chat/MessageInput/InputMenu.svelte b/src/lib/components/chat/MessageInput/InputMenu.svelte index 6ae35a259..b1df43e25 100644 --- a/src/lib/components/chat/MessageInput/InputMenu.svelte +++ b/src/lib/components/chat/MessageInput/InputMenu.svelte @@ -1,37 +1,52 @@ + import { getAllTags } from '$lib/apis/chats'; import { tags } from '$lib/stores'; - import { stringify } from 'postcss'; import { getContext, createEventDispatcher, onMount, onDestroy, tick } from 'svelte'; import { fade } from 'svelte/transition'; @@ -15,13 +15,14 @@ let lastWord = ''; $: lastWord = value ? value.split(' ').at(-1) : value; - let focused = false; let options = [ { name: 'tag:', description: $i18n.t('search for tags') } ]; + let focused = false; + let loading = false; let filteredOptions = options; $: filteredOptions = options.filter((option) => { @@ -52,6 +53,12 @@ }) : []; + const initTags = async () => { + loading = true; + await tags.set(await getAllTags(localStorage.token)); + loading = false; + }; + const documentClickHandler = (e) => { const searchContainer = document.getElementById('search-container'); const chatSearch = document.getElementById('chat-search'); @@ -99,6 +106,7 @@ }} on:focus={() => { focused = true; + initTags(); }} on:keydown={(e) => { if (e.key === 'Enter') { diff --git a/src/lib/stores/index.ts b/src/lib/stores/index.ts index 501ac9b81..6e809a5d6 100644 --- a/src/lib/stores/index.ts +++ b/src/lib/stores/index.ts @@ -28,11 +28,13 @@ export const pinnedChats = writable([]); export const tags = writable([]); export const models: Writable = writable([]); -export const prompts: Writable = writable([]); -export const knowledge: Writable = writable([]); -export const tools = writable([]); -export const functions = writable([]); + +export const prompts: Writable = writable(null); +export const knowledge: Writable = writable(null); +export const tools = writable(null); +export const functions = writable(null); + export const banners: Writable = writable([]); diff --git a/src/routes/(app)/+layout.svelte b/src/routes/(app)/+layout.svelte index c66ebb588..7f1c5cf17 100644 --- a/src/routes/(app)/+layout.svelte +++ b/src/routes/(app)/+layout.svelte @@ -101,23 +101,8 @@ (async () => { models.set(await getModels()); })(), - (async () => { - prompts.set(await getPrompts(localStorage.token)); - })(), - (async () => { - knowledge.set(await getKnowledgeItems(localStorage.token)); - })(), - (async () => { - tools.set(await getTools(localStorage.token)); - })(), - (async () => { - functions.set(await getFunctions(localStorage.token)); - })(), (async () => { banners.set(await getBanners(localStorage.token)); - })(), - (async () => { - tags.set(await getAllTags(localStorage.token)); })() ]); diff --git a/src/routes/(app)/workspace/+layout.svelte b/src/routes/(app)/workspace/+layout.svelte index f770071c6..55efb7b5a 100644 --- a/src/routes/(app)/workspace/+layout.svelte +++ b/src/routes/(app)/workspace/+layout.svelte @@ -1,10 +1,25 @@