refac
This commit is contained in:
@@ -15,7 +15,8 @@
|
||||
showCallOverlay,
|
||||
showArtifacts,
|
||||
showEmbeds,
|
||||
settings
|
||||
settings,
|
||||
showFileNavPath
|
||||
} from '$lib/stores';
|
||||
|
||||
import { uploadFile } from '$lib/apis/files';
|
||||
@@ -61,6 +62,12 @@
|
||||
$: hasMessages = history?.messages && Object.keys(history.messages).length > 0;
|
||||
$: if (!hasMessages && activeTab === 'overview') activeTab = 'controls';
|
||||
|
||||
// Auto-switch to Files tab when display_file is triggered
|
||||
$: if ($showFileNavPath) {
|
||||
activeTab = 'files';
|
||||
showControls.set(true);
|
||||
}
|
||||
|
||||
// Attach a terminal file to the chat input
|
||||
const handleTerminalAttach = async (blob: Blob, name: string, contentType: string) => {
|
||||
const tempItemId = uuidv4();
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<script lang="ts">
|
||||
import { toast } from 'svelte-sonner';
|
||||
import { getContext, onMount, onDestroy, tick } from 'svelte';
|
||||
import { settings } from '$lib/stores';
|
||||
import { settings, showFileNavPath } from '$lib/stores';
|
||||
import {
|
||||
getCwd,
|
||||
listFiles,
|
||||
@@ -224,12 +224,42 @@
|
||||
|
||||
onMount(async () => {
|
||||
if (!configured) return;
|
||||
// On first ever open, resolve the server's CWD instead of defaulting to /
|
||||
if (savedPath === '/') {
|
||||
const cwd = await getCwd(terminalUrl, terminalKey);
|
||||
if (cwd) savedPath = cwd.endsWith('/') ? cwd : cwd + '/';
|
||||
|
||||
let handledDisplayFile = false;
|
||||
|
||||
// Subscribe to display_file requests
|
||||
const unsubFileNav = showFileNavPath.subscribe(async (filePath) => {
|
||||
if (!filePath || !configured) return;
|
||||
handledDisplayFile = true;
|
||||
// Clear the store so it can be re-triggered for the same path
|
||||
showFileNavPath.set(null);
|
||||
|
||||
// Navigate to the parent directory
|
||||
const lastSlash = filePath.lastIndexOf('/');
|
||||
const dir = lastSlash > 0 ? filePath.substring(0, lastSlash + 1) : '/';
|
||||
const fileName = filePath.substring(lastSlash + 1);
|
||||
|
||||
if (dir !== currentPath) {
|
||||
await loadDir(dir);
|
||||
}
|
||||
|
||||
// Open the file for preview
|
||||
await tick();
|
||||
const entry = entries.find((e) => e.name === fileName);
|
||||
if (entry) {
|
||||
await openEntry(entry);
|
||||
}
|
||||
});
|
||||
|
||||
// Only load the default directory if a display_file wasn't pending
|
||||
if (!handledDisplayFile) {
|
||||
// On first ever open, resolve the server's CWD instead of defaulting to /
|
||||
if (savedPath === '/') {
|
||||
const cwd = await getCwd(terminalUrl, terminalKey);
|
||||
if (cwd) savedPath = cwd.endsWith('/') ? cwd : cwd + '/';
|
||||
}
|
||||
loadDir(savedPath);
|
||||
}
|
||||
loadDir(savedPath);
|
||||
|
||||
const onKeyDown = (e: KeyboardEvent) => {
|
||||
if (e.key === 'Shift') shiftKey = true;
|
||||
|
||||
@@ -92,6 +92,7 @@ export const showOverview = writable(false);
|
||||
export const showArtifacts = writable(false);
|
||||
export const showCallOverlay = writable(false);
|
||||
export const showFileNav = writable(false);
|
||||
export const showFileNavPath: Writable<string | null> = writable(null);
|
||||
|
||||
export const artifactCode = writable(null);
|
||||
export const artifactContents = writable(null);
|
||||
|
||||
+31
-23
@@ -31,7 +31,9 @@
|
||||
playingNotificationSound,
|
||||
channels,
|
||||
channelId,
|
||||
terminalServers
|
||||
terminalServers,
|
||||
showControls,
|
||||
showFileNavPath
|
||||
} from '$lib/stores';
|
||||
import { goto } from '$app/navigation';
|
||||
import { page } from '$app/stores';
|
||||
@@ -283,14 +285,11 @@
|
||||
};
|
||||
};
|
||||
|
||||
const executeTool = async (data, cb) => {
|
||||
let toolServer = $settings?.toolServers?.find((server) => server.url === data.server?.url);
|
||||
let toolServerData = $toolServers?.find((server) => server.url === data.server?.url);
|
||||
|
||||
// Also check terminal servers if not found in regular tool servers
|
||||
const resolveToolServer = (serverUrl) => {
|
||||
let toolServer = $settings?.toolServers?.find((server) => server.url === serverUrl);
|
||||
if (!toolServer) {
|
||||
const terminalServer = ($settings?.terminalServers ?? []).find(
|
||||
(server) => server.url === data.server?.url
|
||||
(server) => server.url === serverUrl
|
||||
);
|
||||
if (terminalServer) {
|
||||
toolServer = {
|
||||
@@ -302,28 +301,28 @@
|
||||
}
|
||||
}
|
||||
|
||||
// Check terminal server data if not found in regular tool servers data
|
||||
if (!toolServerData) {
|
||||
toolServerData = $terminalServers?.find((server) => server.url === data.server?.url);
|
||||
let toolServerData =
|
||||
$toolServers?.find((server) => server.url === serverUrl) ??
|
||||
$terminalServers?.find((server) => server.url === serverUrl);
|
||||
|
||||
let token = null;
|
||||
if (toolServer) {
|
||||
const auth_type = toolServer?.auth_type ?? 'bearer';
|
||||
if (auth_type === 'bearer') token = toolServer?.key;
|
||||
else if (auth_type === 'session') token = localStorage.token;
|
||||
}
|
||||
|
||||
return { toolServer, toolServerData, token };
|
||||
};
|
||||
|
||||
const executeTool = async (data, cb) => {
|
||||
const { toolServer, toolServerData, token } = resolveToolServer(data.server?.url);
|
||||
|
||||
console.log('executeTool', data, toolServer);
|
||||
|
||||
if (toolServer) {
|
||||
console.log(toolServer);
|
||||
|
||||
let toolServerToken = null;
|
||||
const auth_type = toolServer?.auth_type ?? 'bearer';
|
||||
if (auth_type === 'bearer') {
|
||||
toolServerToken = toolServer?.key;
|
||||
} else if (auth_type === 'none') {
|
||||
// No authentication
|
||||
} else if (auth_type === 'session') {
|
||||
toolServerToken = localStorage.token;
|
||||
}
|
||||
|
||||
const res = await executeToolServer(
|
||||
toolServerToken,
|
||||
token,
|
||||
toolServer.url,
|
||||
data?.name,
|
||||
data?.params,
|
||||
@@ -331,6 +330,15 @@
|
||||
);
|
||||
|
||||
console.log('executeToolServer', res);
|
||||
|
||||
// Intercept display_file result to handle UI
|
||||
if (data?.name === 'display_file' && data?.params?.path) {
|
||||
if (res?.exists !== false) {
|
||||
showControls.set(true);
|
||||
showFileNavPath.set(data.params.path);
|
||||
}
|
||||
}
|
||||
|
||||
if (cb) {
|
||||
cb(JSON.parse(JSON.stringify(res)));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user