mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 13:54:30 +00:00
fix(issue-39839): address tool-call extra params parsing for kimi anthropic-messages
This commit is contained in:
committed by
Peter Steinberger
parent
6dadfaa18c
commit
76e4b8277f
@@ -803,6 +803,40 @@ describe("applyExtraParamsToAgent", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("normalizes anthropic tool_choice modes for kimi-coding endpoints", () => {
|
||||||
|
const payloads: Record<string, unknown>[] = [];
|
||||||
|
const baseStreamFn: StreamFn = (_model, _context, options) => {
|
||||||
|
const payload: Record<string, unknown> = {
|
||||||
|
tools: [
|
||||||
|
{
|
||||||
|
name: "read",
|
||||||
|
description: "Read file",
|
||||||
|
input_schema: { type: "object", properties: {} },
|
||||||
|
},
|
||||||
|
],
|
||||||
|
tool_choice: { type: "auto" },
|
||||||
|
};
|
||||||
|
options?.onPayload?.(payload);
|
||||||
|
payloads.push(payload);
|
||||||
|
return {} as ReturnType<StreamFn>;
|
||||||
|
};
|
||||||
|
const agent = { streamFn: baseStreamFn };
|
||||||
|
|
||||||
|
applyExtraParamsToAgent(agent, undefined, "kimi-coding", "k2p5", undefined, "low");
|
||||||
|
|
||||||
|
const model = {
|
||||||
|
api: "anthropic-messages",
|
||||||
|
provider: "kimi-coding",
|
||||||
|
id: "k2p5",
|
||||||
|
baseUrl: "https://api.kimi.com/coding/",
|
||||||
|
} as Model<"anthropic-messages">;
|
||||||
|
const context: Context = { messages: [] };
|
||||||
|
void agent.streamFn?.(model, context, {});
|
||||||
|
|
||||||
|
expect(payloads).toHaveLength(1);
|
||||||
|
expect(payloads[0]?.tool_choice).toBe("auto");
|
||||||
|
});
|
||||||
|
|
||||||
it("does not rewrite anthropic tool schema for non-kimi endpoints", () => {
|
it("does not rewrite anthropic tool schema for non-kimi endpoints", () => {
|
||||||
const payloads: Record<string, unknown>[] = [];
|
const payloads: Record<string, unknown>[] = [];
|
||||||
const baseStreamFn: StreamFn = (_model, _context, options) => {
|
const baseStreamFn: StreamFn = (_model, _context, options) => {
|
||||||
|
|||||||
@@ -858,6 +858,15 @@ function normalizeKimiCodingToolChoice(toolChoice: unknown): unknown {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const choice = toolChoice as Record<string, unknown>;
|
const choice = toolChoice as Record<string, unknown>;
|
||||||
|
if (choice.type === "auto") {
|
||||||
|
return "auto";
|
||||||
|
}
|
||||||
|
if (choice.type === "none") {
|
||||||
|
return "none";
|
||||||
|
}
|
||||||
|
if (choice.type === "required") {
|
||||||
|
return "required";
|
||||||
|
}
|
||||||
if (choice.type === "any") {
|
if (choice.type === "any") {
|
||||||
return "required";
|
return "required";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user