diff --git a/package.json b/package.json index 424b6ac..485dfbe 100644 --- a/package.json +++ b/package.json @@ -68,6 +68,7 @@ "socket.io-client": "^4.8.3" }, "devDependencies": { + "esbuild": "^0.27.0", "@koa/bodyparser": "^5.0.0", "@koa/cors": "^5.0.0", "@koa/router": "^15.4.0", diff --git a/packages/client/src/api/hermes/chat.ts b/packages/client/src/api/hermes/chat.ts index 4cc654d..1ce6bd6 100644 --- a/packages/client/src/api/hermes/chat.ts +++ b/packages/client/src/api/hermes/chat.ts @@ -131,14 +131,26 @@ export function startRunViaSocket( socket.off('usage.updated', onUsageUpdated) } - // All event handlers share the same cleanup logic + // All event handlers share the same cleanup logic. + // IMPORTANT: The Socket.IO connection is shared across all in-flight runs + // (single namespace, single socket). When two sessions run concurrently, + // every `startRunViaSocket()` call registers its own `message.delta` / + // `tool.*` / `run.*` listeners on the SAME socket, so each event would + // fan out to every listener and corrupt the wrong session's transcript. + // The server tags every payload with `session_id`; we filter here so each + // run only sees its own events. We also accept untagged events (for + // backwards compatibility) when no session_id was provided in the request. + const expectedSid = body.session_id const handleEvent = (event: RunEvent) => { if (closed) return + // Filter events by session_id to prevent cross-session contamination + if (expectedSid && event.session_id && event.session_id !== expectedSid) { + return + } try { onEvent(event) } finally { if (event.event === 'run.completed' || event.event === 'run.failed') { - console.log('[startRunViaSocket] Run completed/failed, calling cleanup and onDone', event.event) cleanup() onDone() } diff --git a/packages/client/src/api/hermes/sessions.ts b/packages/client/src/api/hermes/sessions.ts index eeba736..d47bab2 100644 --- a/packages/client/src/api/hermes/sessions.ts +++ b/packages/client/src/api/hermes/sessions.ts @@ -20,6 +20,7 @@ export interface SessionSummary { estimated_cost_usd: number actual_cost_usd: number | null cost_status: string + workspace?: string | null } export interface SessionDetail extends SessionSummary { @@ -95,6 +96,18 @@ export async function renameSession(id: string, title: string): Promise } } +export async function setSessionWorkspace(id: string, workspace: string | null): Promise { + try { + await request(`/api/hermes/sessions/${id}/workspace`, { + method: 'POST', + body: JSON.stringify({ workspace: workspace || '' }), + }) + return true + } catch { + return false + } +} + export interface UsageStatsResponse { total_input_tokens: number total_output_tokens: number diff --git a/packages/client/src/components/hermes/chat/ChatPanel.vue b/packages/client/src/components/hermes/chat/ChatPanel.vue index de5c222..58301b7 100644 --- a/packages/client/src/components/hermes/chat/ChatPanel.vue +++ b/packages/client/src/components/hermes/chat/ChatPanel.vue @@ -1,5 +1,5 @@