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.
This commit is contained in:
ismeth
2026-03-19 12:15:43 +01:00
committed by YeonGyu-Kim
parent 597fdb7a51
commit 0b604c8d35
+22 -10
View File
@@ -12,8 +12,12 @@ const DESCRIPTION =
const ALLOWED_AGENTS = new Set<string>(SWITCHABLE_AGENT_NAMES) const ALLOWED_AGENTS = new Set<string>(SWITCHABLE_AGENT_NAMES)
type TuiService = { type TuiHttpClient = {
selectSession: (input: { body: { sessionID: string } }) => Promise<unknown> post: (input: {
url: string
body: Record<string, unknown>
headers?: Record<string, string>
}) => Promise<unknown>
} }
type SessionClient = { type SessionClient = {
@@ -48,21 +52,29 @@ function extractSessionId(response: unknown): string | undefined {
return undefined return undefined
} }
function hasTuiService(client: SessionClient): client is SessionClient & { tui: TuiService } { function getHttpClient(client: SessionClient): TuiHttpClient | null {
const maybeTui = Reflect.get(client as object, "tui") const maybeClient = Reflect.get(client as object, "_client")
if (typeof maybeTui !== "object" || maybeTui === null) { if (typeof maybeClient !== "object" || maybeClient === null) {
return false 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<boolean> { async function navigateTuiToSession(client: SessionClient, sessionID: string): Promise<boolean> {
if (!hasTuiService(client)) { const httpClient = getHttpClient(client)
log("[switch-agent] TUI service not available, cannot navigate to session:", sessionID) if (!httpClient) {
log("[switch-agent] HTTP client not available, cannot navigate TUI to session:", sessionID)
return false return false
} }
try { try {
await client.tui.selectSession({ body: { sessionID } }) await httpClient.post({
url: "/tui/select-session",
body: { sessionID },
headers: { "Content-Type": "application/json" },
})
return true return true
} catch (error) { } catch (error) {
log("[switch-agent] TUI navigation failed for session:", { sessionID, error }) log("[switch-agent] TUI navigation failed for session:", { sessionID, error })