fix(issue-39839): handle kimi anthropic-messages tool-call extra params#39854
fix(issue-39839): handle kimi anthropic-messages tool-call extra params#39854steipete merged 1 commit intoopenclaw:mainfrom
Conversation
Greptile SummaryThis PR hardens
Confidence Score: 4/5
Last reviewed commit: 98ddae9 |
| 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"); | ||
| }); |
There was a problem hiding this comment.
Missing coverage for none and required normalizations
The new test only exercises the { type: "auto" } → "auto" path, but the PR also adds { type: "none" } → "none" and { type: "required" } → "required" branches in normalizeKimiCodingToolChoice. Neither of those new branches is covered by a test, which means a future regression could go undetected.
Consider extending this test (or adding a parameterized table) to cover all three new cases — "none" and "required" alongside "auto" — so the behaviour is pinned:
it.each([
["auto", "auto"],
["none", "none"],
["required", "required"],
])("normalizes tool_choice {type: %s} to string %s for kimi-coding", (inputType, expected) => {
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: inputType },
};
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">;
void agent.streamFn?.(model, { messages: [] } as Context, {});
expect(payloads[0]?.tool_choice).toBe(expected);
});Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/pi-embedded-runner-extraparams.test.ts
Line: 806-838
Comment:
**Missing coverage for `none` and `required` normalizations**
The new test only exercises the `{ type: "auto" }` → `"auto"` path, but the PR also adds `{ type: "none" }` → `"none"` and `{ type: "required" }` → `"required"` branches in `normalizeKimiCodingToolChoice`. Neither of those new branches is covered by a test, which means a future regression could go undetected.
Consider extending this test (or adding a parameterized table) to cover all three new cases — `"none"` and `"required"` alongside `"auto"` — so the behaviour is pinned:
```ts
it.each([
["auto", "auto"],
["none", "none"],
["required", "required"],
])("normalizes tool_choice {type: %s} to string %s for kimi-coding", (inputType, expected) => {
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: inputType },
};
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">;
void agent.streamFn?.(model, { messages: [] } as Context, {});
expect(payloads[0]?.tool_choice).toBe(expected);
});
```
How can I resolve this? If you propose a fix, please make it concise.|
收尾同步:该 PR 当前状态 clean,历史 CI 全绿,可直接 review/merge。若需要我补充任何回归用例我会立即跟进。 |
|
Landed via temp rebase onto main. Thanks @GeekCheyun! |
Summary
Validation
Closes #39839