fix(issue-39839): address tool-call extra params parsing for kimi anthropic-messages

This commit is contained in:
GeekCheyun
2026-03-08 21:10:59 +08:00
committed by Peter Steinberger
parent 6dadfaa18c
commit 76e4b8277f
2 changed files with 43 additions and 0 deletions

View File

@@ -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", () => {
const payloads: Record<string, unknown>[] = [];
const baseStreamFn: StreamFn = (_model, _context, options) => {

View File

@@ -858,6 +858,15 @@ function normalizeKimiCodingToolChoice(toolChoice: unknown): 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") {
return "required";
}