mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-24 07:01:49 +00:00
gateway: cover default message-channel fallback
This commit is contained in:
committed by
Peter Steinberger
parent
842a79cf99
commit
0d8f14fed3
@@ -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,
|
||||
},
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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, {
|
||||
|
||||
Reference in New Issue
Block a user