diff --git a/src/lib/components/chat/MessageInput/Commands/Knowledge.svelte b/src/lib/components/chat/MessageInput/Commands/Knowledge.svelte index bc9d5dddb..fc4612042 100644 --- a/src/lib/components/chat/MessageInput/Commands/Knowledge.svelte +++ b/src/lib/components/chat/MessageInput/Commands/Knowledge.svelte @@ -14,6 +14,7 @@ const dispatch = createEventDispatcher(); let selectedIdx = 0; + let items = []; let fuse = null; let filteredItems = []; @@ -22,7 +23,7 @@ ? fuse.search(command).map((e) => { return e.item; }) - : $knowledge; + : items; } $: if (command) { @@ -71,7 +72,38 @@ }; onMount(() => { - fuse = new Fuse($knowledge, { + let legacy_documents = $knowledge.filter((item) => item?.meta?.document); + let legacy_collections = + legacy_documents.length > 0 + ? [ + { + name: 'All Documents', + legacy: true, + type: 'collection', + description: 'Deprecated (legacy collection), please use the new knowledge base.', + title: $i18n.t('All Documents'), + collection_names: legacy_documents.map((item) => item.id) + }, + + ...legacy_documents + .reduce((a, item) => { + return [...new Set([...a, ...(item?.meta?.tags ?? []).map((tag) => tag.name)])]; + }, []) + .map((tag) => ({ + name: tag, + legacy: true, + type: 'collection', + description: 'Deprecated (legacy collection), please use the new knowledge base.', + collection_names: legacy_documents + .filter((item) => (item?.meta?.tags ?? []).map((tag) => tag.name).includes(tag)) + .map((item) => item.id) + })) + ] + : []; + + items = [...$knowledge, ...legacy_collections]; + + fuse = new Fuse(items, { keys: ['name', 'description'] }); }); @@ -107,27 +139,33 @@ on:focus={() => {}} >
-
- {item.name} -
- - {#if item?.meta?.document} + {#if item.legacy}
+ Legacy +
+ {:else if item?.meta?.document} +
Document
{:else}
Collection
{/if} + +
+ {item.name} +
- {item.description} + {item?.description}
{/each} diff --git a/src/lib/components/workspace/Knowledge.svelte b/src/lib/components/workspace/Knowledge.svelte index 77d1124f8..2e5d389c4 100644 --- a/src/lib/components/workspace/Knowledge.svelte +++ b/src/lib/components/workspace/Knowledge.svelte @@ -119,7 +119,11 @@ class=" flex space-x-4 cursor-pointer text-left w-full px-4 py-3 border border-gray-50 dark:border-gray-850 hover:bg-gray-50 dark:hover:bg-gray-850 rounded-xl" on:click={() => { if (item?.meta?.document) { - toast.error($i18n.t('Only collections can be edited, create a new knowledge instead.')); + toast.error( + $i18n.t( + 'Only collections can be edited, create a new knowledge base to edit/add documents.' + ) + ); } else { goto(`/workspace/knowledge/${item.id}`); } diff --git a/src/lib/components/workspace/Models/Knowledge.svelte b/src/lib/components/workspace/Models/Knowledge.svelte index 1a945a276..3ea8215ea 100644 --- a/src/lib/components/workspace/Models/Knowledge.svelte +++ b/src/lib/components/workspace/Models/Knowledge.svelte @@ -1,9 +1,9 @@ @@ -13,91 +13,44 @@
- {$i18n.t('To add documents here, upload them to the "Documents" workspace first.')} + {$i18n.t('To attach knowledge base here, add them to the "Knowledge" workspace first.')}
- {#if knowledge.length > 0} + {#if knowledge?.length > 0}
{#each knowledge as file, fileIdx} -
-
-
- {#if (file?.type ?? 'doc') === 'doc'} - - - - - {:else if file.type === 'collection'} - - - - - {/if} -
- -
-
- {file?.title ?? `#${file.name}`} -
- -
{$i18n.t(file?.type ?? 'Document')}
-
-
- -
- -
-
+ { + knowledge = knowledge.filter((_, idx) => idx !== fileIdx); + }} + /> {/each}
{/if}
- + { + const item = e.detail; + + if (!knowledge.find((k) => k.name === item.name)) { + knowledge = [ + ...knowledge, + { + ...item, + type: item?.type ?? 'doc' + } + ]; + } + }} + > {$i18n.t('Select Knowledge')}
diff --git a/src/lib/components/workspace/Models/Knowledge/Selector.svelte b/src/lib/components/workspace/Models/Knowledge/Selector.svelte index 0f04723b8..c6b5ff810 100644 --- a/src/lib/components/workspace/Models/Knowledge/Selector.svelte +++ b/src/lib/components/workspace/Models/Knowledge/Selector.svelte @@ -1,35 +1,48 @@ @@ -44,7 +57,7 @@
{#if items.length === 0}
- {$i18n.t('No documents found')} + {$i18n.t('No knowledge found')}
{:else} {#each items as item} { - if (!_knowledge.find((k) => k.name === item.name)) { - _knowledge = [ - ..._knowledge, - { - ...item, - type: item?.type ?? 'doc' - } - ]; - } + dispatch('select', item); }} > -
- {#if (item?.type ?? 'doc') === 'doc'} - - - - - {:else if item.type === 'collection'} - - - - - {/if} -
-
-
- {item?.type ?? 'Document'} +
+ {#if item.legacy} +
+ Legacy +
+ {:else if item?.meta?.document} +
+ Document +
+ {:else} +
+ Collection +
+ {/if}