Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/responses/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ function mapToolChoice(value: unknown): OcxRequestOptions["toolChoice"] {
if (t === "image_generation" || t === "image_gen") {
return { name: IMAGE_GEN_TOOL_NAME };
}
// Hosted web-search choices force the synthetic routed search tool. Treating this shape as
// `auto` would also advertise unrelated client tools when the sidecar injects web_search.
if (t === "web_search" || t === "web_search_preview") {
return { name: WEB_SEARCH_TOOL_NAME };
Comment on lines +117 to +118

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Activate the sidecar for forced web_search_preview choices

For a routed Responses request whose tool declaration and choice both use the supported web_search_preview type, this new branch sets toolChoice to { name: "web_search" }, but extractHostedWebSearch() recognizes only type === "web_search". Consequently _webSearch remains unset, planWebSearch() returns no plan, the synthetic tool is never injected, and adapter filtering removes every unrelated declared tool, so the model produces an ordinary answer without performing the forced search. Normalize or extract web_search_preview as a hosted search too, and add a routed-planning regression case for this branch.

AGENTS.md reference: src/AGENTS.md:L22-L25

Useful? React with 👍 / 👎.

}
if (t === "allowed_tools" && Array.isArray(value.tools)) {
const names = value.tools
.map(allowedToolName)
Expand Down
14 changes: 14 additions & 0 deletions tests/responses-parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,20 @@ describe("Responses parser", () => {
expect(parsed.options.toolChoice).toEqual({ allowedTools: ["web_search"], mode: "required" });
});

test("maps a forced hosted web_search choice to the synthetic routed tool", () => {
const parsed = parseRequest({
model: "umans/umans-kimi-k2.7",
input: "search",
tools: [
{ type: "web_search" },
{ type: "function", name: "run_shell", parameters: { type: "object" } },
],
tool_choice: { type: "web_search" },
});

expect(parsed.options.toolChoice).toEqual({ name: "web_search" });
});
Comment on lines +164 to +176

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Add coverage for web_search_preview.

The parser now handles both web_search and web_search_preview, but this test covers only web_search. Add a second case that expects { name: "web_search" } for tool_choice: { type: "web_search_preview" }.

As per path instructions, behavior changes in src/ should have focused regression coverage in tests/.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/responses-parser.test.ts` around lines 164 - 176, Add a focused test
alongside the existing forced hosted web_search test in the responses parser
suite, using tool_choice type "web_search_preview" and asserting
parsed.options.toolChoice equals { name: "web_search" }. Keep the same request
setup and preserve the existing web_search coverage.

Source: Path instructions


test("maps type-only hosted image_generation tool_choice to required image_gen", () => {
const parsed = parseRequest({
model: "claude-opus-4-6",
Expand Down
Loading