()
| 268 | let loggedOptimistic = false |
| 269 | |
| 270 | export function isToolSearchEnabledOptimistic(): boolean { |
| 271 | const mode = getToolSearchMode() |
| 272 | if (mode === 'standard') { |
| 273 | if (!loggedOptimistic) { |
| 274 | loggedOptimistic = true |
| 275 | logForDebugging( |
| 276 | `[ToolSearch:optimistic] mode=${mode}, ENABLE_TOOL_SEARCH=${process.env.ENABLE_TOOL_SEARCH}, result=false`, |
| 277 | ) |
| 278 | } |
| 279 | return false |
| 280 | } |
| 281 | |
| 282 | // tool_reference is a beta content type that third-party API gateways |
| 283 | // (ANTHROPIC_BASE_URL proxies) typically don't support. When the provider |
| 284 | // is 'firstParty' but the base URL points elsewhere, the proxy will reject |
| 285 | // tool_reference blocks with a 400. Vertex/Bedrock/Foundry are unaffected — |
| 286 | // they have their own endpoints and beta headers. |
| 287 | // https://github.com/anthropics/claude-code/issues/30912 |
| 288 | // |
| 289 | // HOWEVER: some proxies DO support tool_reference (LiteLLM passthrough, |
| 290 | // Cloudflare AI Gateway, corp gateways that forward beta headers). The |
| 291 | // blanket disable breaks defer_loading for those users — all MCP tools |
| 292 | // loaded into main context instead of on-demand (gh-31936 / CC-457, |
| 293 | // likely the real cause of CC-330 "v2.1.70 defer_loading regression"). |
| 294 | // This gate only applies when ENABLE_TOOL_SEARCH is unset/empty (default |
| 295 | // behavior). Setting any non-empty value — 'true', 'auto', 'auto:N' — |
| 296 | // means the user is explicitly configuring tool search and asserts their |
| 297 | // setup supports it. The falsy check (rather than === undefined) aligns |
| 298 | // with getToolSearchMode(), which also treats "" as unset. |
| 299 | if ( |
| 300 | !process.env.ENABLE_TOOL_SEARCH && |
| 301 | getAPIProvider() === 'firstParty' && |
| 302 | !isFirstPartyAnthropicBaseUrl() |
| 303 | ) { |
| 304 | if (!loggedOptimistic) { |
| 305 | loggedOptimistic = true |
| 306 | logForDebugging( |
| 307 | `[ToolSearch:optimistic] disabled: ANTHROPIC_BASE_URL=${process.env.ANTHROPIC_BASE_URL} is not a first-party Anthropic host. Set ENABLE_TOOL_SEARCH=true (or auto / auto:N) if your proxy forwards tool_reference blocks.`, |
| 308 | ) |
| 309 | } |
| 310 | return false |
| 311 | } |
| 312 | |
| 313 | if (!loggedOptimistic) { |
| 314 | loggedOptimistic = true |
| 315 | logForDebugging( |
| 316 | `[ToolSearch:optimistic] mode=${mode}, ENABLE_TOOL_SEARCH=${process.env.ENABLE_TOOL_SEARCH}, result=true`, |
| 317 | ) |
| 318 | } |
| 319 | return true |
| 320 | } |
| 321 | |
| 322 | /** |
| 323 | * Check if ToolSearchTool is available in the provided tools list. |
no test coverage detected