mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-21 15:55:50 +00:00
Add brave as alternative WebSearchTool
This commit is contained in:
@@ -6,36 +6,42 @@
|
||||
import { isFirstPartyAnthropicBaseUrl } from '../../../utils/model/providers.js'
|
||||
import { ApiSearchAdapter } from './apiAdapter.js'
|
||||
import { BingSearchAdapter } from './bingAdapter.js'
|
||||
import { BraveSearchAdapter } from './braveAdapter.js'
|
||||
import type { WebSearchAdapter } from './types.js'
|
||||
|
||||
export type { SearchResult, SearchOptions, SearchProgress, WebSearchAdapter } from './types.js'
|
||||
export type {
|
||||
SearchResult,
|
||||
SearchOptions,
|
||||
SearchProgress,
|
||||
WebSearchAdapter,
|
||||
} from './types.js'
|
||||
|
||||
let cachedAdapter: WebSearchAdapter | null = null
|
||||
let cachedAdapterKey: 'api' | 'bing' | 'brave' | 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
|
||||
const envAdapter = process.env.WEB_SEARCH_ADAPTER
|
||||
const adapterKey =
|
||||
envAdapter === 'api' || envAdapter === 'bing' || envAdapter === 'brave'
|
||||
? envAdapter
|
||||
: isFirstPartyAnthropicBaseUrl()
|
||||
? 'api'
|
||||
: 'bing'
|
||||
|
||||
// // 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
|
||||
// }
|
||||
if (cachedAdapter && cachedAdapterKey === adapterKey) return cachedAdapter
|
||||
|
||||
// // Anthropic official URL → API server-side search
|
||||
// if (isFirstPartyAnthropicBaseUrl()) {
|
||||
// cachedAdapter = new ApiSearchAdapter()
|
||||
// return cachedAdapter
|
||||
// }
|
||||
if (adapterKey === 'api') {
|
||||
cachedAdapter = new ApiSearchAdapter()
|
||||
cachedAdapterKey = 'api'
|
||||
return cachedAdapter
|
||||
}
|
||||
if (adapterKey === 'bing') {
|
||||
cachedAdapter = new BingSearchAdapter()
|
||||
cachedAdapterKey = 'bing'
|
||||
return cachedAdapter
|
||||
}
|
||||
|
||||
// // Third-party proxies / non-Anthropic endpoints → Bing fallback
|
||||
// cachedAdapter = new BingSearchAdapter()
|
||||
// return cachedAdapter
|
||||
cachedAdapter = new BraveSearchAdapter()
|
||||
cachedAdapterKey = 'brave'
|
||||
return cachedAdapter
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user