fix: custom web search — WEB_URL_TEMPLATE not recognized, timeout too short, silent native fallback (#537)
* fix: custom web search — WEB_URL_TEMPLATE not recognized, timeout too short, silent native fallback 1. custom.ts: Add WEB_URL_TEMPLATE to isConfigured() so the custom provider is recognized when configured via URL template alone. 2. custom.ts: Bump DEFAULT_TIMEOUT_SECONDS from 15s to 120s. Self-hosted search APIs (SearXNG, internal) commonly need 30-90s. 3. WebSearchTool.ts: When an explicit adapter is selected via WEB_SEARCH_PROVIDER=custom, do not silently fall through to the native Anthropic path on adapter errors or 0-hit results. - 0 hits: return directly (no fallback) - Error: throw the real error (no fallback) - Auto mode: existing fallback behavior preserved * fix: tighten auto-mode adapter fallback — only swallow transient errors Address review feedback: in auto mode, only fall through to native on transient errors (network failure, timeout, HTTP 5xx). Config and guardrail errors (SSRF, HTTPS, bad URL, header allowlist, etc.) now surface properly instead of being silently swallowed. --------- Co-authored-by: FluxLuFFy <fluxluffy@users.noreply.github.com>
This commit is contained in:
@@ -22,7 +22,7 @@
|
||||
* 3. Built-in allowlist of header names — arbitrary headers require
|
||||
* WEB_CUSTOM_ALLOW_ARBITRARY_HEADERS=true
|
||||
* 4. Max body size guard (300 KB for POST)
|
||||
* 5. Request timeout (default 15s, configurable via WEB_CUSTOM_TIMEOUT_SEC)
|
||||
* 5. Request timeout (default 120s, configurable via WEB_CUSTOM_TIMEOUT_SEC)
|
||||
* 6. Audit log on first custom search (one-time warning)
|
||||
*/
|
||||
|
||||
@@ -117,7 +117,7 @@ const BUILT_IN_PROVIDERS: Record<string, ProviderPreset> = {
|
||||
const DEFAULT_MAX_BODY_KB = 300
|
||||
|
||||
/** Default request timeout in seconds. */
|
||||
const DEFAULT_TIMEOUT_SECONDS = 15
|
||||
const DEFAULT_TIMEOUT_SECONDS = 120
|
||||
|
||||
/** Header names that are always allowed (case-insensitive). */
|
||||
const SAFE_HEADER_NAMES = new Set([
|
||||
@@ -455,7 +455,7 @@ export const customProvider: SearchProvider = {
|
||||
name: 'custom',
|
||||
|
||||
isConfigured() {
|
||||
return Boolean(process.env.WEB_SEARCH_API || process.env.WEB_PROVIDER)
|
||||
return Boolean(process.env.WEB_SEARCH_API || process.env.WEB_PROVIDER || process.env.WEB_URL_TEMPLATE)
|
||||
},
|
||||
|
||||
async search(input: SearchInput, signal?: AbortSignal): Promise<ProviderOutput> {
|
||||
|
||||
Reference in New Issue
Block a user