Skip to content

Commit 0eabccc

Browse files
claude-code-bestdeepseek-v4-pro
andcommitted
fix: review — Brave API key + webFetchHttpTimeoutMs 联动 + Tavily URL 推导
- braveAdapter: 读取 settings.braveApiKey (优先于环境变量) - webFetch utils: getFetchTimeoutMs() 统一读取 settings.webFetchHttpTimeoutMs,HTTP/Tavily 两条路径均生效 - tavilyAdapter: 自定义端点自动追加 /search 路径(与 fetchContentWithTavily 一致) Co-Authored-By: deepseek-v4-pro <deepseek-ai@claude-code-best.win>
1 parent 9d845d7 commit 0eabccc

3 files changed

Lines changed: 27 additions & 5 deletions

File tree

packages/builtin-tools/src/tools/WebFetchTool/utils.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,19 @@ const MAX_HTTP_CONTENT_LENGTH = 10 * 1024 * 1024
117117

118118
// Timeout for the main HTTP fetch request (60 seconds).
119119
// Prevents hanging indefinitely on slow/unresponsive servers.
120-
const FETCH_TIMEOUT_MS = 60_000
120+
// Overridable via settings.webFetchHttpTimeoutMs (set in /web-tools panel).
121+
const DEFAULT_FETCH_TIMEOUT_MS = 60_000
122+
123+
function getFetchTimeoutMs(): number {
124+
const settings = getSettings_DEPRECATED() as Record<string, unknown> & {
125+
webFetchHttpTimeoutMs?: number
126+
}
127+
return settings.webFetchHttpTimeoutMs ?? DEFAULT_FETCH_TIMEOUT_MS
128+
}
121129

122130
// Cap same-host redirect hops. Without this a malicious server can return
123-
// a redirect loop (/a → /b → /a …) and the per-request FETCH_TIMEOUT_MS
131+
// a redirect loop (/a → /b → /a …) and the per-request timeout
132+
// (controlled by settings.webFetchHttpTimeoutMs)
124133
// resets on every hop, hanging the tool until user interrupt. 10 matches
125134
// common client defaults (axios=5, follow-redirects=21, Chrome=20).
126135
const MAX_REDIRECTS = 10
@@ -238,7 +247,7 @@ export async function getWithPermittedRedirects(
238247
try {
239248
return await axios.get(url, {
240249
signal,
241-
timeout: FETCH_TIMEOUT_MS,
250+
timeout: getFetchTimeoutMs(),
242251
maxRedirects: 0,
243252
responseType: 'arraybuffer',
244253
maxContentLength: MAX_HTTP_CONTENT_LENGTH,
@@ -488,7 +497,7 @@ export async function fetchContentWithTavily(
488497
},
489498
{
490499
signal: abortSignal,
491-
timeout: FETCH_TIMEOUT_MS,
500+
timeout: getFetchTimeoutMs(),
492501
headers: { 'Content-Type': 'application/json' },
493502
},
494503
)

packages/builtin-tools/src/tools/WebSearchTool/adapters/braveAdapter.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import axios from 'axios'
77
import { AbortError } from 'src/utils/errors.js'
8+
import { getSettings_DEPRECATED } from 'src/utils/settings/settings.js'
89
import type { SearchResult, SearchOptions, WebSearchAdapter } from './types.js'
910

1011
const FETCH_TIMEOUT_MS = 30_000
@@ -156,6 +157,14 @@ function normalizeSnippet(snippets: string[] | undefined): string | undefined {
156157
}
157158

158159
function getBraveApiKey(): string {
160+
// Priority: settings.braveApiKey (from /web-tools panel) > environment variable
161+
const settings = getSettings_DEPRECATED() as Record<string, unknown> & {
162+
braveApiKey?: string
163+
}
164+
if (settings.braveApiKey?.trim()) {
165+
return settings.braveApiKey.trim()
166+
}
167+
159168
for (const envVar of BRAVE_API_KEY_ENV_VARS) {
160169
const value = process.env[envVar]?.trim()
161170
if (value) {

packages/builtin-tools/src/tools/WebSearchTool/adapters/tavilyAdapter.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ export class TavilySearchAdapter implements WebSearchAdapter {
4343
const settings = getSettings_DEPRECATED() as Record<string, unknown> & {
4444
tavilyEndpointUrl?: string
4545
}
46-
const searchUrl = settings.tavilyEndpointUrl || DEFAULT_TAVILY_SEARCH_URL
46+
const baseUrl = settings.tavilyEndpointUrl || DEFAULT_TAVILY_SEARCH_URL
47+
// Ensure the URL ends with /search (same pattern as fetchContentWithTavily for /extract)
48+
const searchUrl = baseUrl.endsWith('/search')
49+
? baseUrl
50+
: `${baseUrl.replace(/\/$/, '')}/search`
4751

4852
try {
4953
const response = await axios.post<{

0 commit comments

Comments
 (0)