From 0b604c8d3527d493bf6fccbc82266885670fe3b5 Mon Sep 17 00:00:00 2001 From: ismeth Date: Thu, 19 Mar 2026 12:15:43 +0100 Subject: [PATCH] fix(switch-agent): use direct HTTP POST for TUI navigation instead of missing SDK method The v1 SDK Tui class has no selectSession method (only exists in v2). Commit 4150e26d regressed this by replacing the working _client.post() direct HTTP call with client.tui.selectSession() which silently failed. Reverts to bypassing the SDK and POSTing to /tui/select-session directly, which works regardless of SDK version. --- src/tools/switch-agent/tools.ts | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/src/tools/switch-agent/tools.ts b/src/tools/switch-agent/tools.ts index 6340d7980..58695db0f 100644 --- a/src/tools/switch-agent/tools.ts +++ b/src/tools/switch-agent/tools.ts @@ -12,8 +12,12 @@ const DESCRIPTION = const ALLOWED_AGENTS = new Set(SWITCHABLE_AGENT_NAMES) -type TuiService = { - selectSession: (input: { body: { sessionID: string } }) => Promise +type TuiHttpClient = { + post: (input: { + url: string + body: Record + headers?: Record + }) => Promise } type SessionClient = { @@ -48,21 +52,29 @@ function extractSessionId(response: unknown): string | undefined { return undefined } -function hasTuiService(client: SessionClient): client is SessionClient & { tui: TuiService } { - const maybeTui = Reflect.get(client as object, "tui") - if (typeof maybeTui !== "object" || maybeTui === null) { - return false +function getHttpClient(client: SessionClient): TuiHttpClient | null { + const maybeClient = Reflect.get(client as object, "_client") + if (typeof maybeClient !== "object" || maybeClient === null) { + return null } - return typeof Reflect.get(maybeTui, "selectSession") === "function" + if (typeof Reflect.get(maybeClient, "post") !== "function") { + return null + } + return maybeClient as TuiHttpClient } async function navigateTuiToSession(client: SessionClient, sessionID: string): Promise { - if (!hasTuiService(client)) { - log("[switch-agent] TUI service not available, cannot navigate to session:", sessionID) + const httpClient = getHttpClient(client) + if (!httpClient) { + log("[switch-agent] HTTP client not available, cannot navigate TUI to session:", sessionID) return false } try { - await client.tui.selectSession({ body: { sessionID } }) + await httpClient.post({ + url: "/tui/select-session", + body: { sessionID }, + headers: { "Content-Type": "application/json" }, + }) return true } catch (error) { log("[switch-agent] TUI navigation failed for session:", { sessionID, error })