refac
This commit is contained in:
1 parent
4df2d9a7aa
commit
46dce79eb0
2 files changed
+2
-53
No files matched your search
@@ -3,15 +3,10 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { SvelteFlowProvider } from '@xyflow/svelte';
|
|
||||||
import { slide } from 'svelte/transition';
|
|
||||||
import { v4 as uuidv4 } from 'uuid';
|
|
||||||
|
|
||||||
import { onMount, tick, getContext } from 'svelte';
|
import { onMount, tick, getContext } from 'svelte';
|
||||||
import {
|
import {
|
||||||
config,
|
config,
|
||||||
terminalServers,
|
terminalServers,
|
||||||
mobile,
|
|
||||||
showControls,
|
showControls,
|
||||||
showCallOverlay,
|
showCallOverlay,
|
||||||
showArtifacts,
|
showArtifacts,
|
||||||
@@ -22,9 +17,6 @@
|
|||||||
user
|
user
|
||||||
} from '$lib/stores';
|
} from '$lib/stores';
|
||||||
|
|
||||||
import { uploadFile } from '$lib/apis/files';
|
|
||||||
import { toast } from 'svelte-sonner';
|
|
||||||
|
|
||||||
import Controls from './Controls/Controls.svelte';
|
import Controls from './Controls/Controls.svelte';
|
||||||
import CallOverlay from './MessageInput/CallOverlay.svelte';
|
import CallOverlay from './MessageInput/CallOverlay.svelte';
|
||||||
import Drawer from '../common/Drawer.svelte';
|
import Drawer from '../common/Drawer.svelte';
|
||||||
@@ -133,48 +125,6 @@
|
|||||||
selectedTerminalId.set(null);
|
selectedTerminalId.set(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attach a terminal file to the chat input
|
|
||||||
const handleTerminalAttach = async (blob: Blob, name: string, contentType: string) => {
|
|
||||||
const tempItemId = uuidv4();
|
|
||||||
const fileItem = {
|
|
||||||
type: 'file',
|
|
||||||
file: '',
|
|
||||||
id: null,
|
|
||||||
url: '',
|
|
||||||
name,
|
|
||||||
collection_name: '',
|
|
||||||
status: 'uploading',
|
|
||||||
error: '',
|
|
||||||
itemId: tempItemId,
|
|
||||||
size: blob.size
|
|
||||||
};
|
|
||||||
|
|
||||||
files = [...files, fileItem];
|
|
||||||
|
|
||||||
try {
|
|
||||||
const file = new File([blob], name, { type: contentType || 'application/octet-stream' });
|
|
||||||
const uploaded = await uploadFile(localStorage.token, file);
|
|
||||||
if (!uploaded) throw new Error('Upload failed');
|
|
||||||
|
|
||||||
const idx = files.findIndex((f) => f.itemId === tempItemId);
|
|
||||||
if (idx !== -1) {
|
|
||||||
files[idx] = {
|
|
||||||
...fileItem,
|
|
||||||
status: 'uploaded',
|
|
||||||
file: uploaded,
|
|
||||||
id: uploaded.id,
|
|
||||||
url: `${uploaded.id}`,
|
|
||||||
collection_name: uploaded?.meta?.collection_name
|
|
||||||
};
|
|
||||||
files = files;
|
|
||||||
}
|
|
||||||
toast.success($i18n.t('File attached to chat'));
|
|
||||||
} catch (e) {
|
|
||||||
files = files.filter((f) => f.itemId !== tempItemId);
|
|
||||||
toast.error($i18n.t('Failed to attach file'));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleMediaQuery = async (e) => {
|
const handleMediaQuery = async (e) => {
|
||||||
if (e.matches) {
|
if (e.matches) {
|
||||||
largeScreen = true;
|
largeScreen = true;
|
||||||
@@ -349,7 +299,7 @@
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
{:else if activeTab === 'files' && terminalFilesAvailable && $selectedTerminalId}
|
{:else if activeTab === 'files' && terminalFilesAvailable && $selectedTerminalId}
|
||||||
<FileNav onAttach={handleTerminalAttach} {chatId} />
|
<FileNav {chatId} />
|
||||||
{:else if activeTab === 'files' && codeInterpreterEnabled}
|
{:else if activeTab === 'files' && codeInterpreterEnabled}
|
||||||
<PyodideFileNav />
|
<PyodideFileNav />
|
||||||
{:else}
|
{:else}
|
||||||
@@ -475,7 +425,7 @@
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
{:else if activeTab === 'files' && terminalFilesAvailable && $selectedTerminalId}
|
{:else if activeTab === 'files' && terminalFilesAvailable && $selectedTerminalId}
|
||||||
<FileNav onAttach={handleTerminalAttach} overlay={dragged} {chatId} />
|
<FileNav overlay={dragged} {chatId} />
|
||||||
{:else if activeTab === 'files' && codeInterpreterEnabled}
|
{:else if activeTab === 'files' && codeInterpreterEnabled}
|
||||||
<PyodideFileNav overlay={dragged} />
|
<PyodideFileNav overlay={dragged} />
|
||||||
{:else}
|
{:else}
|
||||||
|
|||||||
@@ -52,7 +52,6 @@
|
|||||||
|
|
||||||
const i18n: any = getContext('i18n');
|
const i18n: any = getContext('i18n');
|
||||||
|
|
||||||
export let onAttach: ((blob: Blob, name: string, contentType: string) => void) | null = null;
|
|
||||||
export let overlay = false;
|
export let overlay = false;
|
||||||
export let chatId: string | null = null;
|
export let chatId: string | null = null;
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user