From e4b969f606288443b2eb4acee22beaa366e90070 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Fri, 13 Nov 2026 19:44:00 +0900 Subject: [PATCH] refac --- src/lib/components/chat/MessageInput.svelte | 23 +- .../chat/MessageInput/InputMenu.svelte | 17 +- .../chat/MessageInput/TerminalMenu.svelte | 325 ++++++++++-------- .../MessageInput/WorkingDirectoryMenu.svelte | 321 +++++++++-------- 4 files changed, 397 insertions(+), 289 deletions(-) diff --git a/src/lib/components/chat/MessageInput.svelte b/src/lib/components/chat/MessageInput.svelte index 69ff781b79..a657390f98 100644 --- a/src/lib/components/chat/MessageInput.svelte +++ b/src/lib/components/chat/MessageInput.svelte @@ -273,14 +273,16 @@ cancelAnimationFrame(frame); frame = requestAnimationFrame(() => { const labels = controls.querySelectorAll('[data-input-label]'); - const terminalControls = controls.querySelector('[data-terminal-controls]'); + const directoryControl = controls.querySelector( + '[data-working-directory-control]' + ); // Measure all labels together so separate controls cannot compete for the same space. for (const label of labels) label.style.display = ''; - if (terminalControls) terminalControls.style.display = ''; - terminalControlsInMenu = !!terminalControls && controls.scrollWidth > controls.clientWidth; - if (terminalControls && terminalControlsInMenu) terminalControls.style.display = 'none'; - if (controls.scrollWidth > controls.clientWidth) { + if (directoryControl) directoryControl.style.display = ''; + terminalControlsInMenu = controls.scrollWidth > controls.clientWidth; + if (terminalControlsInMenu) { for (const label of labels) label.style.display = 'none'; + if (directoryControl) directoryControl.style.display = 'none'; } }); }; @@ -2232,9 +2234,9 @@
-
+ {#if inputMenuTab === ''} +
+ {/if} {/if} diff --git a/src/lib/components/chat/MessageInput/InputMenu.svelte b/src/lib/components/chat/MessageInput/InputMenu.svelte index 7c18ea0148..d2983d9c58 100644 --- a/src/lib/components/chat/MessageInput/InputMenu.svelte +++ b/src/lib/components/chat/MessageInput/InputMenu.svelte @@ -54,7 +54,16 @@ export let tab = ''; export let closeOnOutsideClick = true; $: if (!show) tab = ''; - $: hasInternalList = ['tools', 'skills', 'files', 'notes', 'knowledge', 'chats'].includes(tab); + $: hasInternalList = [ + 'tools', + 'skills', + 'files', + 'notes', + 'knowledge', + 'chats', + 'terminal', + 'directory' + ].includes(tab); let showAttachWebpageModal = false; $: showAddContext = @@ -216,9 +225,13 @@
{/if} +
+ {/if} - + + {#if tab === ''} +
{ + show = false; + if (inMenu) tab = ''; + }; export let disabled = false; export let chatId: string | null = null; export let terminalContext: TerminalContext | null = null; // Connections the user may create terminals on; a terminal on one of them is theirs to manage. let writable: { id: string; name: string }[] = []; - $: if (show) + $: if (inMenu ? tab === 'terminal' : show) templatesApi('/connections') .then((rows) => (writable = rows)) .catch(() => (writable = [])); @@ -105,7 +112,7 @@ }; const confirmLifecycle = (id: string, name: string, action: 'restart' | 'stop') => { pending = { id, name, action }; - show = false; + closeMenu(); showConfirm = true; }; @@ -121,7 +128,7 @@ ].filter((section) => !section.devices || section.terminals.length > 0); const toggleTerminal = (id: string) => { - show = false; + closeMenu(); selectTerminal(selectedTerminalId, $selectedTerminalId === id ? null : id, chatId); }; @@ -138,13 +145,13 @@ selectedSystemTerminal?.name || selectedSystemTerminal?.id || ($selectedTerminalId ? $i18n.t('Unavailable terminal') : $i18n.t('Terminal')); - $: if (disabled && show) show = false; + $: if (disabled && (show || (inMenu && tab === 'terminal'))) closeMenu(); let showTerminals = false; let managedTerminalId: string | null = null; const openTerminalDialog = (id: string | null) => { managedTerminalId = id; - show = false; + closeMenu(); showTerminals = true; }; let info: { target: TerminalTarget; label: string } | null = null; @@ -155,7 +162,7 @@ modelId: modelId }); if (!target) return; - show = false; + closeMenu(); await tick(); files = { target, label }; }; @@ -170,7 +177,7 @@ modelId: modelId }); if (!target) return; - show = false; + closeMenu(); await tick(); info = { target, label }; }; @@ -183,159 +190,198 @@ ) info = null; - $: triggerClass = inMenu - ? `flex w-full min-w-0 items-center gap-2 h-[1.6875rem] px-2 text-[0.8125rem] rounded-xl text-left ${disabled ? 'cursor-not-allowed opacity-40' : 'cursor-pointer hover:bg-gray-50/40 dark:hover:bg-gray-800/40'}` - : `flex items-center gap-1.5 translate-y-[1px] text-[0.8125rem] transition rounded-lg ${ - disabled - ? 'p-1 cursor-not-allowed opacity-40 text-gray-400 dark:text-gray-600' - : `text-gray-600 hover:text-gray-700 dark:text-gray-300 dark:hover:text-gray-200 cursor-pointer ${ - $selectedTerminalId && selectedLabel ? ' p-1 ' : ' p-1 opacity-50' - }` - }`; + $: triggerClass = `flex items-center gap-1.5 translate-y-[1px] text-[0.8125rem] transition rounded-lg ${ + disabled + ? 'p-1 cursor-not-allowed opacity-40 text-gray-400 dark:text-gray-600' + : `text-gray-600 hover:text-gray-700 dark:text-gray-300 dark:hover:text-gray-200 cursor-pointer ${ + $selectedTerminalId && selectedLabel ? ' p-1 ' : ' p-1 opacity-50' + }` + }`; -
- {#if disabled} - +{#snippet menuItems()} + + {#each systemSections as section} +
+ + {section.devices ? $i18n.t('Your devices') : $i18n.t('Terminals')} + + {#if !section.devices} +
+ {#if writable.length} + + + + {/if} + {#if $user?.role === 'admin'} + + + + {/if} +
+ {/if} +
+ + {#each section.terminals as terminal} + {@const label = terminal.name || $i18n.t('Terminal')} + {@const owned = canManage(terminal, manageable)} + {@const reachable = terminal.scope !== 'chat' || isSavedChatId($activeChatId)} +
+ +
+ machineStatus(terminal.id) : null} + onRestart={() => confirmLifecycle(terminal.id, label, 'restart')} + onStop={() => confirmLifecycle(terminal.id, label, 'stop')} + onStart={() => runLifecycle(terminal.id, label, 'start')} + onInfo={reachable ? () => openInfo(terminal.id, label) : null} + onFiles={reachable ? () => openFiles(terminal.id, label) : null} + onSettings={owned ? () => openTerminalDialog(terminal.id) : null} + /> +
+
+ {/each} + {/each} +{/snippet} + +{#if inMenu} + {#if tab === ''} +
- - {:else} - +
+ {:else if tab === 'terminal'} +
+ +
+ {@render menuItems()} +
+
+ {/if} +{:else} +
+ {#if disabled} - + {:else} + + + - - {/if} - {#if $user?.role === 'admin'} - - - - {/if} -
- {/if} -
+ {/if} + +
- {#each section.terminals as terminal} - {@const label = terminal.name || $i18n.t('Terminal')} - {@const owned = canManage(terminal, manageable)} - {@const reachable = terminal.scope !== 'chat' || isSavedChatId($activeChatId)} -
- -
- machineStatus(terminal.id) : null} - onRestart={() => confirmLifecycle(terminal.id, label, 'restart')} - onStop={() => confirmLifecycle(terminal.id, label, 'stop')} - onStart={() => runLifecycle(terminal.id, label, 'start')} - onInfo={reachable ? () => openInfo(terminal.id, label) : null} - onFiles={reachable ? () => openFiles(terminal.id, label) : null} - onSettings={owned ? () => openTerminalDialog(terminal.id) : null} - /> -
-
- {/each} - {/each} - -
- - {/if} - +
+ + {@render menuItems()} + +
+ + {/if} + +{/if} {#if info} {#key info} @@ -351,6 +397,7 @@ {#key `${$user?.id}:${folderTarget.selector}:${chatId ?? ''}`} { + show = false; + if (inMenu) tab = ''; + }; export let onSelect: (path: string) => Promise = async () => {}; let show = false; @@ -40,13 +47,12 @@ const folderName = (path: string) => path.replace(/\/+$/, '').split('/').pop() || '/'; const normalize = (path: string) => path.replace(/\/+$/, '') || '/'; - $: if (terminalContext?.terminalId === target.selector) - cwd = terminalContext.currentDirectory; + $: if (terminalContext?.terminalId === target.selector) cwd = terminalContext.currentDirectory; $: directory = cwd; $: options = [...new Set([directory, ...recent].filter(Boolean).map(normalize))].filter((path) => path.toLowerCase().includes(search.trim().toLowerCase()) ); - $: if (disabled && show) show = false; + $: if (disabled && (show || (inMenu && tab === 'directory'))) closeMenu(); $: if (disabled && showPicker) showPicker = false; async function refreshRecentFolders() { @@ -83,14 +89,12 @@ const selectedContext = terminalContext?.terminalId === target.selector ? terminalContext : null; if (selectedContext) cwd = selectedContext.currentDirectory; - initialization = getCwd(target).then( - (result) => { - if (disposed) return; - home = result?.home ?? ''; - // A new chat ID remounts this menu before its session cwd may be ready. - if (chatId && !selectedContext) cwd = result?.cwd ?? ''; - } - ); + initialization = getCwd(target).then((result) => { + if (disposed) return; + home = result?.home ?? ''; + // A new chat ID remounts this menu before its session cwd may be ready. + if (chatId && !selectedContext) cwd = result?.cwd ?? ''; + }); void refreshRecentFolders(); }); onDestroy(() => (disposed = true)); @@ -99,9 +103,7 @@ if (disabled || saving) return; saving = true; // A draft has no terminal session yet; submission applies this choice after creating the chat. - const result = chatId - ? await setCwd(target, path) - : { cwd: path || home }; + const result = chatId ? await setCwd(target, path) : { cwd: path || home }; if (disposed) return; if (!result?.cwd) { saving = false; @@ -139,149 +141,190 @@ } } saving = false; - show = false; + closeMenu(); showPicker = false; } -
- { - search = ''; - if (open) void refreshRecentFolders(); +{#snippet menuItems()} + +
+ + {#if options.length > 0} +
+ {$i18n.t('Recently Used')} +
+ {#if historyError} +
+ {historyError} +
+ {/if} +
+ {#each options as path} + {@const selected = !!directory && normalize(directory) === path} +
+ +
+ + + +
+
+ {/each} +
+ {/if} +
+ +{/snippet} + +{#if inMenu} + {#if tab === ''} +
- -
- - -
+
+ {:else if tab === 'directory'} +
+ +
+ {@render menuItems()} +
+
+ {/if} +{:else} +
+ { + search = ''; + if (open) void refreshRecentFolders(); + }} + > + - {#if options.length > 0} -
- {$i18n.t('Recently Used')} -
- {#if historyError} -
- {historyError} -
- {/if} -
- {#each options as path} - {@const selected = !!directory && normalize(directory) === path} -
- -
- - - -
-
- {/each} -
- {/if} -
- - -
- -
+ +
+ + {@render menuItems()} + +
+
+
+{/if} {#if showPicker}