Skip to content

Commit d889767

Browse files
committed
fix(claude): preserve hosted web search choices
1 parent 7779c05 commit d889767

8 files changed

Lines changed: 40 additions & 16 deletions

File tree

‎docs-site/src/content/docs/guides/claude-code.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ Claude Code's `/effort` setting is preserved across the adapter:
371371
| --- | --- |
372372
| `thinking.type: "adaptive"` + `output_config.effort` | Effort passed directly (`minimal`\|`low`\|`medium`\|`high`\|`xhigh`\|`max`\|`ultra`) |
373373
| `thinking.type: "enabled"` + `budget_tokens` | ≤4096→`low`, ≤16384→`medium`, above→`high` |
374-
| `thinking.type: "disabled"` | Reasoning parameters omitted entirely |
374+
| `thinking.type: "disabled"` | `reasoning: { effort: "none" }`; summary omitted |
375375

376376
The resolved value appears in the request log's **Reasoning effort** column.
377377

@@ -389,7 +389,7 @@ The proxy translates every Anthropic Messages API request into the Codex Respons
389389
| User `tool_result` | `function_call_output` (`is_error` → `[tool error]` prefix) |
390390
| `thinking` / `redacted_thinking` replay | Dropped |
391391
| Function tools | `{type: "function"}` (`web_search*` → `{type: "web_search"}`) |
392-
| `tool_choice` | `auto`→`auto`, `none`→`none`, `any`→`required`, named→`{type:"function",name}` |
392+
| `tool_choice` | `auto`→`auto`, `none`→`none`, `any`→`required`, named function→`{type:"function",name}`, hosted WebSearch/web_search→`{type:"web_search"}` |
393393
| `max_tokens` | `max_output_tokens` |
394394
| `stop_sequences` | `stop` |
395395

‎docs-site/src/content/docs/ja/guides/claude-code.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ Claude Code の `/effort` 設定はアダプターでも維持されます。
250250
--- | --- |
251251
| `thinking.type: "adaptive"` + `output_config.effort` | Effort をそのまま渡します(`minimal`\|`low`\|`medium`\|`high`\|`xhigh`\|`max`\|`ultra`) |
252252
| `thinking.type: "enabled"` + `budget_tokens` | ≤4096→`low`、≤16384→`medium`、それより大→`high` |
253-
| `thinking.type: "disabled"` | 推論パラメータをすべて省略します |
253+
| `thinking.type: "disabled"` | `reasoning: { effort: "none" }` を明示し、`summary` は省略します |
254254

255255
解釈された値はリクエストログの **Reasoning effort** 列に表示されます。
256256

@@ -268,7 +268,7 @@ Claude Code の `/effort` 設定はアダプターでも維持されます。
268268
| ユーザー `tool_result` | `function_call_output`(`is_error` → `[tool error]` 接頭辞) |
269269
| `thinking` / `redacted_thinking` 再生 | 破棄 |
270270
| Function ツール | `{type: "function"}`(`web_search*` → `{type: "web_search"}`) |
271-
| `tool_choice` | `auto`→`auto`、`none`→`none`、`any`→`required`、名前指定→`{type:"function",name}` |
271+
| `tool_choice` | `auto`→`auto`、`none`→`none`、`any`→`required`、名前指定関数→`{type:"function",name}`、ホスト型 WebSearch/web_search→`{type:"web_search"}` |
272272
| `max_tokens` | `max_output_tokens` |
273273
| `stop_sequences` | `stop` |
274274

‎docs-site/src/content/docs/ko/guides/claude-code.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ Claude Code의 `/effort` 설정은 어댑터에서도 유지돼요.
287287
| --- | --- |
288288
| `thinking.type: "adaptive"` + `output_config.effort` | Effort를 그대로 전달해요(`minimal`\|`low`\|`medium`\|`high`\|`xhigh`\|`max`\|`ultra`) |
289289
| `thinking.type: "enabled"` + `budget_tokens` | ≤4096→`low`, ≤16384→`medium`, 그보다 크면→`high` |
290-
| `thinking.type: "disabled"` | 추론 매개변수를 모두 생략해요 |
290+
| `thinking.type: "disabled"` | `reasoning: { effort: "none" }`을 명시하고 `summary`는 생략해요 |
291291

292292
해석된 값은 요청 로그의 **Reasoning effort** 열에 표시돼요.
293293

@@ -305,7 +305,7 @@ Claude Code의 `/effort` 설정은 어댑터에서도 유지돼요.
305305
| 사용자 `tool_result` | `function_call_output`(`is_error` → `[tool error]` 접두사) |
306306
| `thinking` / `redacted_thinking` 재생 | 버려요 |
307307
| Function 도구 | `{type: "function"}`(`web_search*` → `{type: "web_search"}`) |
308-
| `tool_choice` | `auto`→`auto`, `none`→`none`, `any`→`required`, 이름 지정→`{type:"function",name}` |
308+
| `tool_choice` | `auto`→`auto`, `none`→`none`, `any`→`required`, 이름 지정 함수→`{type:"function",name}`, 호스팅 WebSearch/web_search→`{type:"web_search"}` |
309309
| `max_tokens` | `max_output_tokens` |
310310
| `stop_sequences` | `stop` |
311311

‎docs-site/src/content/docs/ru/guides/claude-code.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ Claude Code — это лишь учётные данные для доступ
266266
| --- | --- |
267267
| `thinking.type: "adaptive"` + `output_config.effort` | Уровень передаётся напрямую (`minimal`\|`low`\|`medium`\|`high`\|`xhigh`\|`max`\|`ultra`) |
268268
| `thinking.type: "enabled"` + `budget_tokens` | ≤4096→`low`, ≤16384→`medium`, выше→`high` |
269-
| `thinking.type: "disabled"` | Параметры рассуждений полностью опускаются |
269+
| `thinking.type: "disabled"` | Явно передаётся `reasoning: { effort: "none" }`, а `summary` опускается |
270270

271271
Итоговое значение отображается в столбце **Reasoning effort** журнала запросов.
272272

@@ -284,7 +284,7 @@ Claude Code — это лишь учётные данные для доступ
284284
| `tool_result` пользователя | `function_call_output` (`is_error` → префикс `[tool error]`) |
285285
| Повтор `thinking` / `redacted_thinking` | Отбрасывается |
286286
| Function-инструменты | `{type: "function"}` (`web_search*` → `{type: "web_search"}`) |
287-
| `tool_choice` | `auto`→`auto`, `none`→`none`, `any`→`required`, именованный→`{type:"function",name}` |
287+
| `tool_choice` | `auto`→`auto`, `none`→`none`, `any`→`required`, именованная функция→`{type:"function",name}`, размещённый WebSearch/web_search→`{type:"web_search"}` |
288288
| `max_tokens` | `max_output_tokens` |
289289
| `stop_sequences` | `stop` |
290290

‎docs-site/src/content/docs/zh-cn/guides/claude-code.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ Claude Code 的 `/effort` 设置会完整保留并传递给适配器:
245245
| --- | --- |
246246
| `thinking.type: "adaptive"` + `output_config.effort` | 直接传递强度(`minimal`\|`low`\|`medium`\|`high`\|`xhigh`\|`max`\|`ultra`) |
247247
| `thinking.type: "enabled"` + `budget_tokens` | ≤4096→`low`,≤16384→`medium`,更高→`high` |
248-
| `thinking.type: "disabled"` | 完全省略推理参数 |
248+
| `thinking.type: "disabled"` | 显式发送 `reasoning: { effort: "none" }`,并省略 `summary` |
249249

250250
解析后的值会显示在请求日志的 **Reasoning effort** 列中。
251251

@@ -263,7 +263,7 @@ Claude Code 的 `/effort` 设置会完整保留并传递给适配器:
263263
| 用户 `tool_result` | `function_call_output`(`is_error` → `[tool error]` 前缀) |
264264
| 重放 `thinking` / `redacted_thinking` | 丢弃 |
265265
| Function 工具 | `{type: "function"}`(`web_search*` → `{type: "web_search"}`) |
266-
| `tool_choice` | `auto`→`auto`,`none`→`none`,`any`→`required`,指定名称→`{type:"function",name}` |
266+
| `tool_choice` | `auto`→`auto`,`none`→`none`,`any`→`required`,指定函数→`{type:"function",name}`,托管 WebSearch/web_search→`{type:"web_search"}` |
267267
| `max_tokens` | `max_output_tokens` |
268268
| `stop_sequences` | `stop` |
269269

‎src/claude/inbound.ts‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import type { OcxClaudeCodeConfig } from "../types";
1313
import { resolveAlias } from "./alias";
1414
import { stripOneMillionMarker } from "./context-windows";
1515
import { resolveDesktop3pAlias } from "./desktop-3p";
16+
import { isClaudeWebSearchToolName } from "./outbound";
1617
import { createHash } from "node:crypto";
1718

1819
export class AnthropicRequestError extends Error {}
@@ -375,7 +376,12 @@ function toolChoiceToResponses(choice: unknown, body: Rec): void {
375376
if (typeof choice.name !== "string" || choice.name.length === 0) {
376377
throw new AnthropicRequestError("tool_choice.tool requires a name");
377378
}
378-
body.tool_choice = { type: "function", name: choice.name };
379+
// Anthropic represents hosted WebSearch as a named tool choice, while
380+
// Responses requires the choice type to match the hosted declaration.
381+
// Preserve forced-tool intent rather than weakening it to `auto`.
382+
body.tool_choice = isClaudeWebSearchToolName(choice.name)
383+
? { type: "web_search" }
384+
: { type: "function", name: choice.name };
379385
break;
380386
default: break;
381387
}
@@ -502,8 +508,9 @@ export function anthropicToResponsesTranslation(raw: unknown, cc?: OcxClaudeCode
502508
// An explicit "disabled" is an instruction, not an absence. Dropping it made this
503509
// indistinguishable from a request that never mentioned thinking — and for models that
504510
// think by default, omission means thinking is ON, sharing the caller's max_tokens (#545).
505-
// "none" is the parser's disable sentinel (parser.ts REASONING_EFFORTS).
506-
body.reasoning = { effort: "none", summary: "none" };
511+
// `none` is the effort disable sentinel. It is not a valid OpenAI summary
512+
// value, so do not attach the similarly named internal catalog sentinel.
513+
body.reasoning = { effort: "none" };
507514
} else if (isRec(thinking) || outputConfigEffort !== undefined) {
508515
const reasoning: Rec = { summary: "auto" };
509516
if (outputConfigEffort !== undefined) {

‎src/responses/schema.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export const toolSchema = z.object({
107107
const builtinToolSchema = z.object({ type: z.string() }).loose();
108108

109109
const hostedToolType = z.enum([
110-
"web_search_preview", "file_search", "computer_use_preview",
110+
"web_search", "web_search_preview", "file_search", "computer_use_preview",
111111
"code_interpreter", "image_generation", "mcp",
112112
]);
113113

‎tests/claude-inbound.test.ts‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ describe("claude inbound translation", () => {
9696
expect((anthropicToResponsesBody({ ...base, thinking: { type: "adaptive" } }) as any).reasoning).toEqual({ summary: "auto" });
9797
// "disabled" and omitted must NOT collapse to the same state: for a model that thinks by
9898
// default, omission means thinking is ON and shares the caller's max_tokens (#545).
99-
expect((anthropicToResponsesBody({ ...base, thinking: { type: "disabled" } }) as any).reasoning).toEqual({ effort: "none", summary: "none" }); // justified: sibling assertions in this test use the same cast
99+
expect((anthropicToResponsesBody({ ...base, thinking: { type: "disabled" } }) as any).reasoning).toEqual({ effort: "none" }); // justified: sibling assertions in this test use the same cast
100100
expect((anthropicToResponsesBody(base) as any).reasoning).toBeUndefined();
101101
expect(effortForThinkingBudget(1024)).toBe("low");
102102
expect(effortForThinkingBudget(8192)).toBe("medium");
@@ -134,7 +134,7 @@ describe("claude inbound translation", () => {
134134
// rather than left to think anyway (#545).
135135
expect(reasoningOf(anthropicToResponsesBody({
136136
...base, thinking: { type: "disabled" }, output_config: { effort: "high" },
137-
}))).toEqual({ effort: "none", summary: "none" });
137+
}))).toEqual({ effort: "none" });
138138
// unknown effort strings are dropped so downstream defaults win
139139
expect(reasoningOf(anthropicToResponsesBody({
140140
...base, thinking: { type: "adaptive" }, output_config: { effort: "turbo" },
@@ -149,6 +149,23 @@ describe("claude inbound translation", () => {
149149
.toEqual({ type: "function", name: "Read" });
150150
});
151151

152+
test("forced Claude WebSearch stays a hosted Responses tool choice", () => {
153+
const body = anthropicToResponsesBody({
154+
model: "gpt-5.6-luna",
155+
max_tokens: 10,
156+
messages: [{ role: "user", content: "search" }],
157+
tools: [{ type: "web_search_20250305", name: "web_search" }],
158+
tool_choice: { type: "tool", name: "web_search" },
159+
thinking: { type: "disabled" },
160+
}) as Record<string, unknown>;
161+
162+
expect(body.tools).toEqual([{ type: "web_search" }]);
163+
expect(body.tool_choice).toEqual({ type: "web_search" });
164+
expect(body.reasoning).toEqual({ effort: "none" });
165+
expect(() => responsesRequestSchema.parse(body)).not.toThrow();
166+
expect(() => parseRequest(body)).not.toThrow();
167+
});
168+
152169
test("system role messages fold into instructions (real Claude Code sends them; native backend rejects system items)", () => {
153170
const body = anthropicToResponsesBody({
154171
model: "m", max_tokens: 10,

0 commit comments

Comments
 (0)