Co-Authored-By: Classic298 <27028174+Classic298@users.noreply.github.com>
This commit is contained in:
Timothy Jaeryang Baek 2026-10-10 22:19:50 +04:00
parent 5ec6cf3205
commit 88ff2c65cf
3 changed files with 17 additions and 6 deletions

View file

@ -110,6 +110,8 @@ PROXY_METHODS = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS']
@router.api_route('/{server_id}/{path:path}', methods=PROXY_METHODS)
# Register the chat route before the catch-all.
@router.api_route('/{server_id}/chats/{chat_id}/{path:path}', methods=PROXY_METHODS)
async def proxy_terminal(
server_id: str,
path: str,
@ -157,7 +159,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'):

View file

@ -358,6 +358,11 @@
let selectedTerminal: { url: string; key: string } | null = null;
let terminalChatContextPending = false;
let terminalChatContextHidden = false;
let isPerChatTerminal = false;
$: portPreviewBaseUrl =
selectedTerminal && isPerChatTerminal && chatId
? `${selectedTerminal.url}/chats/${encodeURIComponent(chatId)}`
: (selectedTerminal?.url ?? '');
const chatContext = (terminal: any) => terminal?.contexts?.chat ?? {};
@ -366,10 +371,12 @@
? (($terminalServers ?? []).find((t) => t.id === $selectedTerminalId) ?? null)
: ($terminalServers?.[0] ?? null);
const chatConfig = chatContext(systemTerminal);
const chatScoped = !!systemTerminal && chatConfig?.context_id === 'chat_id';
isPerChatTerminal = !!systemTerminal && chatConfig?.context_id === 'chat_id';
terminalChatContextHidden =
!!systemTerminal && (chatConfig === false || (chatScoped && isTemporaryChatId(chatId)));
terminalChatContextPending = chatScoped && !terminalChatContextHidden && !isSavedChatId(chatId);
!!systemTerminal &&
(chatConfig === false || (isPerChatTerminal && isTemporaryChatId(chatId)));
terminalChatContextPending =
isPerChatTerminal && !terminalChatContextHidden && !isSavedChatId(chatId);
if (terminalChatContextHidden || terminalChatContextPending) return null;
const settingsValue: any = $settings;
@ -1831,7 +1838,7 @@
/>
{:else if previewPort !== null}
<PortPreview
baseUrl={selectedTerminal?.url ?? ''}
baseUrl={portPreviewBaseUrl}
port={previewPort}
overlay={overlay || isDraggingHandle}
onClose={() => {
@ -2108,6 +2115,7 @@
{#key JSON.stringify([chatId, selectedTerminal.url])}
<PortList
baseUrl={selectedTerminal.url}
previewBaseUrl={portPreviewBaseUrl}
apiKey={selectedTerminal.key}
{chatId}
on:previewPort={(e) => {

View file

@ -9,6 +9,7 @@
const dispatch = createEventDispatcher<{ previewPort: number }>();
export let baseUrl: string;
export let previewBaseUrl: string | null = null;
export let apiKey: string;
export let chatId: string | null = null;
@ -41,7 +42,7 @@
};
const openPortExternal = (port: number) => {
const url = getPortProxyUrl(baseUrl, port);
const url = getPortProxyUrl(previewBaseUrl ?? baseUrl, port);
window.open(url, '_blank', 'noopener,noreferrer');
};