mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-19 06:45:50 +00:00
feat: 修正 web search 工具
This commit is contained in:
41
src/tools/WebSearchTool/adapters/index.ts
Normal file
41
src/tools/WebSearchTool/adapters/index.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* Search adapter factory — selects the appropriate backend by checking
|
||||
* whether the API base URL points to Anthropic's official endpoint.
|
||||
*/
|
||||
|
||||
import { isFirstPartyAnthropicBaseUrl } from '../../../utils/model/providers.js'
|
||||
import { ApiSearchAdapter } from './apiAdapter.js'
|
||||
import { BingSearchAdapter } from './bingAdapter.js'
|
||||
import type { WebSearchAdapter } from './types.js'
|
||||
|
||||
export type { SearchResult, SearchOptions, SearchProgress, WebSearchAdapter } from './types.js'
|
||||
|
||||
let cachedAdapter: WebSearchAdapter | null = null
|
||||
|
||||
export function createAdapter(): WebSearchAdapter {
|
||||
// 直接用 bing 适配器,跳过 API 适配器的选择逻辑
|
||||
return new BingSearchAdapter()
|
||||
// // Adapter is stateless — safe to reuse across calls within a session
|
||||
// if (cachedAdapter) return cachedAdapter
|
||||
|
||||
// // Env override: WEB_SEARCH_ADAPTER=api|bing forces specific backend
|
||||
// const envAdapter = process.env.WEB_SEARCH_ADAPTER
|
||||
// if (envAdapter === 'api') {
|
||||
// cachedAdapter = new ApiSearchAdapter()
|
||||
// return cachedAdapter
|
||||
// }
|
||||
// if (envAdapter === 'bing') {
|
||||
// cachedAdapter = new BingSearchAdapter()
|
||||
// return cachedAdapter
|
||||
// }
|
||||
|
||||
// // Anthropic official URL → API server-side search
|
||||
// if (isFirstPartyAnthropicBaseUrl()) {
|
||||
// cachedAdapter = new ApiSearchAdapter()
|
||||
// return cachedAdapter
|
||||
// }
|
||||
|
||||
// // Third-party proxies / non-Anthropic endpoints → Bing fallback
|
||||
// cachedAdapter = new BingSearchAdapter()
|
||||
// return cachedAdapter
|
||||
}
|
||||
Reference in New Issue
Block a user