From 46ff3abbb85c5b84e7a8a98454a18b0814cc053c Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Sat, 9 May 2026 15:23:00 +0900 Subject: [PATCH] refac --- src/lib/components/chat/Chat.svelte | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/lib/components/chat/Chat.svelte b/src/lib/components/chat/Chat.svelte index f13404ea07..1853d11692 100644 --- a/src/lib/components/chat/Chat.svelte +++ b/src/lib/components/chat/Chat.svelte @@ -312,6 +312,14 @@ } }; + /** Check whether a terminal ID references an available system or direct terminal. */ + const isTerminalAvailable = (tid: string): boolean => { + return ( + ($terminalServers ?? []).some((t) => t.id && t.id === tid) || + ($settings?.terminalServers ?? []).some((s) => s.url === tid) + ); + }; + const setDefaults = async () => { if (!$tools) { tools.set(await getTools(localStorage.token)); @@ -390,9 +398,12 @@ } } - // Set Default Terminal + // Set Default Terminal — only if the referenced terminal actually exists if (model?.info?.meta?.terminalId) { - selectedTerminalId.set(model.info.meta.terminalId); + const tid = model.info.meta.terminalId; + if (isTerminalAvailable(tid)) { + selectedTerminalId.set(tid); + } } } }; @@ -730,6 +741,11 @@ }); } + // Clear stale selectedTerminalId if the referenced terminal no longer exists + if ($selectedTerminalId && !isTerminalAvailable($selectedTerminalId)) { + selectedTerminalId.set(null); + } + const pageSubscribe = page.subscribe(async (p) => { if (p.url.pathname === '/') { await tick();