gateway: cover default message-channel fallback

This commit is contained in:
bmendonca3
2026-03-02 15:22:43 -07:00
committed by Peter Steinberger
parent 842a79cf99
commit 0d8f14fed3
2 changed files with 37 additions and 1 deletions

View File

@@ -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,
},
},
);
});
});

View File

@@ -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, {