diff --git a/lib/chat/__tests__/handleChatWorkflowStream.test.ts b/lib/chat/__tests__/handleChatWorkflowStream.test.ts index 1af062c8b..9e8b396c8 100644 --- a/lib/chat/__tests__/handleChatWorkflowStream.test.ts +++ b/lib/chat/__tests__/handleChatWorkflowStream.test.ts @@ -289,6 +289,30 @@ describe("handleChatWorkflowStream", () => { expect(startArgs.modelId).toBe("anthropic/claude-haiku-4.5"); }); + it("prefers validated.model over a persisted chat.model_id", async () => { + vi.mocked(validateChatWorkflow).mockResolvedValue({ + messages: [], + chatId: CHAT_ID, + sessionId: SESSION_ID, + accountId: ACCOUNT_ID, + orgId: null, + authToken: "test-key", + model: "openai/gpt-5.4-mini", + }); + vi.mocked(selectChats).mockResolvedValue([ + { + id: CHAT_ID, + session_id: SESSION_ID, + active_stream_id: null, + model_id: "anthropic/claude-opus-4.6", + } as never, + ]); + mockStartedRun(); + await handleChatWorkflowStream(makeRequest()); + const startArgs = vi.mocked(start).mock.calls[0]?.[1]?.[0] as { modelId: string }; + expect(startArgs.modelId).toBe("openai/gpt-5.4-mini"); + }); + // Bundle A.4 — forward the Privy JWT from the validated body into // AgentContext.recoupAccessToken so the sandbox env-builder can // surface it as `RECOUP_ACCESS_TOKEN`. diff --git a/lib/chat/__tests__/validateChatWorkflow.test.ts b/lib/chat/__tests__/validateChatWorkflow.test.ts index 25dd74d20..540e7cc83 100644 --- a/lib/chat/__tests__/validateChatWorkflow.test.ts +++ b/lib/chat/__tests__/validateChatWorkflow.test.ts @@ -78,6 +78,15 @@ describe("validateChatWorkflow", () => { if (result instanceof NextResponse) return; expect(result.recoupAccessToken).toBe("eyJ.test.jwt"); }); + + it("accepts and surfaces the gateway-format model selected in the UI", async () => { + const result = await validateChatWorkflow( + makeRequest({ ...validBody, model: "openai/gpt-5.4-mini" }), + ); + expect(result).not.toBeInstanceOf(NextResponse); + if (result instanceof NextResponse) return; + expect(result.model).toBe("openai/gpt-5.4-mini"); + }); }); describe("invalid body", () => { diff --git a/lib/chat/handleChatWorkflowStream.ts b/lib/chat/handleChatWorkflowStream.ts index 0e7af2f3e..377b29780 100644 --- a/lib/chat/handleChatWorkflowStream.ts +++ b/lib/chat/handleChatWorkflowStream.ts @@ -90,7 +90,8 @@ export async function handleChatWorkflowStream(request: NextRequest): Promise;