diff --git a/backend/open_webui/routers/terminals.py b/backend/open_webui/routers/terminals.py index 6b5cd6e1d3..ef6cbd01e2 100644 --- a/backend/open_webui/routers/terminals.py +++ b/backend/open_webui/routers/terminals.py @@ -107,6 +107,8 @@ PROXY_METHODS = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'] @router.api_route('/{server_id}/{path:path}', methods=PROXY_METHODS) +# Must stay the lower decorator so it registers before the catch-all, which would swallow chat paths. +@router.api_route('/{server_id}/chats/{chat_id}/{path:path}', methods=PROXY_METHODS) async def proxy_terminal( server_id: str, path: str, @@ -151,7 +153,7 @@ async def proxy_terminal( headers = {'X-User-Id': user.id} # Forward per-session cwd tracking header - session_id = request.headers.get('x-session-id') + session_id = request.path_params.get('chat_id') or request.headers.get('x-session-id') if session_id: headers['X-Session-Id'] = session_id if not terminal_context_available(connection, 'chat'): diff --git a/src/lib/components/chat/FileNav.svelte b/src/lib/components/chat/FileNav.svelte index e2d9aed0af..08085adb7c 100644 --- a/src/lib/components/chat/FileNav.svelte +++ b/src/lib/components/chat/FileNav.svelte @@ -355,6 +355,11 @@ let selectedTerminal: { url: string; key: string } | null = null; let terminalChatContextPending = false; let terminalChatContextHidden = false; + let scopedChatId: string | null = null; + $: portBaseUrl = + selectedTerminal && scopedChatId + ? `${selectedTerminal.url}/chats/${encodeURIComponent(scopedChatId)}` + : (selectedTerminal?.url ?? ''); const chatContext = (terminal: any) => terminal?.contexts?.chat ?? {}; @@ -364,6 +369,7 @@ : ($terminalServers?.[0] ?? null); const chatConfig = chatContext(systemTerminal); const chatScoped = !!systemTerminal && chatConfig?.context_id === 'chat_id'; + scopedChatId = chatScoped ? chatId : null; terminalChatContextHidden = !!systemTerminal && (chatConfig === false || (chatScoped && isTemporaryChatId(chatId))); terminalChatContextPending = chatScoped && !terminalChatContextHidden && !isSavedChatId(chatId); @@ -1824,7 +1830,7 @@ /> {:else if previewPort !== null} { @@ -2099,7 +2105,7 @@ {#if selectedTerminal && !selectedFile && previewPort === null && !isSearching}
{ selectedFile = null;