From 0d8f14fed3aa28a7f512684877b6953f7939322e Mon Sep 17 00:00:00 2001 From: bmendonca3 Date: Mon, 2 Mar 2026 15:22:43 -0700 Subject: [PATCH] gateway: cover default message-channel fallback --- .../openai-http.message-channel.test.ts | 36 +++++++++++++++++++ src/gateway/openai-http.ts | 2 +- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/gateway/openai-http.message-channel.test.ts b/src/gateway/openai-http.message-channel.test.ts index 92c2a2ca21a..153570bdf08 100644 --- a/src/gateway/openai-http.message-channel.test.ts +++ b/src/gateway/openai-http.message-channel.test.ts @@ -40,4 +40,40 @@ describe("OpenAI HTTP message channel", () => { }, ); }); + + it("defaults messageChannel to webchat when header is absent", async () => { + agentCommand.mockReset(); + agentCommand.mockResolvedValueOnce({ payloads: [{ text: "ok" }] } as never); + + await withGatewayServer( + async ({ port }) => { + const res = await fetch(`http://127.0.0.1:${port}/v1/chat/completions`, { + method: "POST", + headers: { + "content-type": "application/json", + authorization: "Bearer secret", + }, + body: JSON.stringify({ + model: "openclaw", + messages: [{ role: "user", content: "hi" }], + }), + }); + + expect(res.status).toBe(200); + const firstCall = (agentCommand.mock.calls[0] as unknown[] | undefined)?.[0] as + | { messageChannel?: string } + | undefined; + expect(firstCall?.messageChannel).toBe("webchat"); + await res.text(); + }, + { + serverOptions: { + host: "127.0.0.1", + auth: { mode: "token", token: "secret" }, + controlUiEnabled: false, + openAiChatCompletionsEnabled: true, + }, + }, + ); + }); }); diff --git a/src/gateway/openai-http.ts b/src/gateway/openai-http.ts index b7b6e3daec3..b78b9e0176f 100644 --- a/src/gateway/openai-http.ts +++ b/src/gateway/openai-http.ts @@ -229,7 +229,7 @@ export async function handleOpenAiHttpRequest( const agentId = resolveAgentIdForRequest({ req, model }); const sessionKey = resolveOpenAiSessionKey({ req, agentId, user }); const messageChannel = - normalizeMessageChannel(getHeader(req, "x-openclaw-message-channel") ?? "") ?? "webchat"; + normalizeMessageChannel(getHeader(req, "x-openclaw-message-channel")) ?? "webchat"; const prompt = buildAgentPrompt(payload.messages); if (!prompt.message) { sendJson(res, 400, {