2024-08-23 12:31:39 +00:00
|
|
|
<script>
|
2024-11-12 23:31:11 +00:00
|
|
|
import { knowledge, prompts } from '$lib/stores';
|
|
|
|
|
|
|
|
|
|
import { removeLastWordFromString } from '$lib/utils';
|
|
|
|
|
import { getPrompts } from '$lib/apis/prompts';
|
2024-11-17 00:51:55 +00:00
|
|
|
import { getKnowledgeBases } from '$lib/apis/knowledge';
|
2024-11-12 23:31:11 +00:00
|
|
|
|
2024-08-23 12:31:39 +00:00
|
|
|
import Prompts from './Commands/Prompts.svelte';
|
2024-10-02 05:45:04 +00:00
|
|
|
import Knowledge from './Commands/Knowledge.svelte';
|
2024-08-23 12:31:39 +00:00
|
|
|
import Models from './Commands/Models.svelte';
|
2024-11-12 23:31:11 +00:00
|
|
|
import Spinner from '$lib/components/common/Spinner.svelte';
|
2024-08-23 12:31:39 +00:00
|
|
|
|
2025-07-04 16:26:01 +00:00
|
|
|
export let show = false;
|
|
|
|
|
|
2024-08-23 12:31:39 +00:00
|
|
|
export let files = [];
|
2025-07-04 16:26:01 +00:00
|
|
|
export let command = '';
|
|
|
|
|
|
|
|
|
|
export let onSelect = (e) => {};
|
|
|
|
|
export let onUpload = (e) => {};
|
|
|
|
|
|
|
|
|
|
export let insertTextHandler = (text) => {};
|
2024-08-23 12:31:39 +00:00
|
|
|
|
2024-11-12 23:31:11 +00:00
|
|
|
let loading = false;
|
2024-08-23 12:31:39 +00:00
|
|
|
let commandElement = null;
|
|
|
|
|
|
|
|
|
|
export const selectUp = () => {
|
|
|
|
|
commandElement?.selectUp();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const selectDown = () => {
|
|
|
|
|
commandElement?.selectDown();
|
|
|
|
|
};
|
|
|
|
|
|
2024-11-12 23:31:11 +00:00
|
|
|
$: if (show) {
|
|
|
|
|
init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const init = async () => {
|
|
|
|
|
loading = true;
|
|
|
|
|
await Promise.all([
|
|
|
|
|
(async () => {
|
|
|
|
|
prompts.set(await getPrompts(localStorage.token));
|
|
|
|
|
})(),
|
|
|
|
|
(async () => {
|
2024-11-17 00:51:55 +00:00
|
|
|
knowledge.set(await getKnowledgeBases(localStorage.token));
|
2024-11-12 23:31:11 +00:00
|
|
|
})()
|
|
|
|
|
]);
|
|
|
|
|
loading = false;
|
|
|
|
|
};
|
2024-08-23 12:31:39 +00:00
|
|
|
</script>
|
|
|
|
|
|
2024-11-12 23:31:11 +00:00
|
|
|
{#if show}
|
|
|
|
|
{#if !loading}
|
|
|
|
|
{#if command?.charAt(0) === '/'}
|
2025-07-04 16:26:01 +00:00
|
|
|
<Prompts
|
|
|
|
|
bind:this={commandElement}
|
|
|
|
|
{command}
|
|
|
|
|
onSelect={(e) => {
|
|
|
|
|
const { type, data } = e;
|
|
|
|
|
|
|
|
|
|
if (type === 'prompt') {
|
|
|
|
|
insertTextHandler(data.content);
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
/>
|
2024-11-12 23:31:11 +00:00
|
|
|
{:else if (command?.charAt(0) === '#' && command.startsWith('#') && !command.includes('# ')) || ('\\#' === command.slice(0, 2) && command.startsWith('#') && !command.includes('# '))}
|
|
|
|
|
<Knowledge
|
|
|
|
|
bind:this={commandElement}
|
|
|
|
|
command={command.includes('\\#') ? command.slice(2) : command}
|
2025-07-04 16:26:01 +00:00
|
|
|
onSelect={(e) => {
|
|
|
|
|
const { type, data } = e;
|
|
|
|
|
|
|
|
|
|
if (type === 'knowledge') {
|
|
|
|
|
insertTextHandler('');
|
|
|
|
|
|
|
|
|
|
onUpload({
|
|
|
|
|
type: 'file',
|
|
|
|
|
data: data
|
|
|
|
|
});
|
|
|
|
|
} else if (type === 'youtube') {
|
|
|
|
|
insertTextHandler('');
|
|
|
|
|
|
|
|
|
|
onUpload({
|
|
|
|
|
type: 'youtube',
|
|
|
|
|
data: data
|
|
|
|
|
});
|
|
|
|
|
} else if (type === 'web') {
|
|
|
|
|
insertTextHandler('');
|
|
|
|
|
|
|
|
|
|
onUpload({
|
|
|
|
|
type: 'web',
|
|
|
|
|
data: data
|
|
|
|
|
});
|
2025-01-22 19:28:54 +00:00
|
|
|
}
|
2024-11-12 23:31:11 +00:00
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
{:else if command?.charAt(0) === '@'}
|
|
|
|
|
<Models
|
|
|
|
|
bind:this={commandElement}
|
|
|
|
|
{command}
|
2025-07-04 16:26:01 +00:00
|
|
|
onSelect={(e) => {
|
|
|
|
|
const { type, data } = e;
|
2024-08-23 12:31:39 +00:00
|
|
|
|
2025-07-04 16:26:01 +00:00
|
|
|
if (type === 'model') {
|
|
|
|
|
insertTextHandler('');
|
|
|
|
|
|
|
|
|
|
onSelect({
|
|
|
|
|
type: 'model',
|
|
|
|
|
data: data
|
|
|
|
|
});
|
|
|
|
|
}
|
2024-11-12 23:31:11 +00:00
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
{/if}
|
|
|
|
|
{:else}
|
|
|
|
|
<div
|
|
|
|
|
id="commands-container"
|
2024-12-02 07:16:00 +00:00
|
|
|
class="px-2 mb-2 text-left w-full absolute bottom-0 left-0 right-0 z-10"
|
2024-11-12 23:31:11 +00:00
|
|
|
>
|
2025-02-16 03:50:40 +00:00
|
|
|
<div class="flex w-full rounded-xl border border-gray-100 dark:border-gray-850">
|
2024-11-12 23:31:11 +00:00
|
|
|
<div
|
|
|
|
|
class="max-h-60 flex flex-col w-full rounded-xl bg-white dark:bg-gray-900 dark:text-gray-100"
|
|
|
|
|
>
|
|
|
|
|
<Spinner />
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2024-08-23 12:31:39 +00:00
|
|
|
{/if}
|
|
|
|
|
{/if}
|