diff --git a/src/agents/tools/web-fetch.ts b/src/agents/tools/web-fetch.ts index 8588b661616..9206386a796 100644 --- a/src/agents/tools/web-fetch.ts +++ b/src/agents/tools/web-fetch.ts @@ -26,6 +26,7 @@ import { normalizeCacheKey, readCache, readResponseText, + resolveWebUrlAllowlist, resolveCacheTtlMs, resolveTimeoutSeconds, withTimeout, @@ -75,17 +76,7 @@ type WebFetchConfig = NonNullable["web"] extends infer type WebConfig = NonNullable["web"]; export function resolveFetchUrlAllowlist(web?: WebConfig): string[] | undefined { - if (!web || typeof web !== "object") { - return undefined; - } - if (!("urlAllowlist" in web)) { - return undefined; - } - const allowlist = web.urlAllowlist; - if (!Array.isArray(allowlist)) { - return undefined; - } - return allowlist.length > 0 ? allowlist : undefined; + return resolveWebUrlAllowlist(web); } export function isUrlAllowedByAllowlist(url: string, allowlist: string[]): boolean { diff --git a/src/agents/tools/web-search.ts b/src/agents/tools/web-search.ts index 63911f0d5e7..a47737594df 100644 --- a/src/agents/tools/web-search.ts +++ b/src/agents/tools/web-search.ts @@ -13,6 +13,7 @@ import { normalizeCacheKey, readCache, readResponseText, + resolveWebUrlAllowlist, resolveCacheTtlMs, resolveTimeoutSeconds, withTimeout, @@ -79,17 +80,7 @@ type WebSearchConfig = NonNullable["web"] extends infer type WebConfig = NonNullable["web"]; export function resolveUrlAllowlist(web?: WebConfig): string[] | undefined { - if (!web || typeof web !== "object") { - return undefined; - } - if (!("urlAllowlist" in web)) { - return undefined; - } - const allowlist = web.urlAllowlist; - if (!Array.isArray(allowlist)) { - return undefined; - } - return allowlist.length > 0 ? allowlist : undefined; + return resolveWebUrlAllowlist(web); } export function filterResultsByAllowlist( diff --git a/src/agents/tools/web-shared.ts b/src/agents/tools/web-shared.ts index da0fbb38beb..419d8a5cdb1 100644 --- a/src/agents/tools/web-shared.ts +++ b/src/agents/tools/web-shared.ts @@ -8,6 +8,20 @@ export const DEFAULT_TIMEOUT_SECONDS = 30; export const DEFAULT_CACHE_TTL_MINUTES = 15; const DEFAULT_CACHE_MAX_ENTRIES = 100; +export function resolveWebUrlAllowlist(web: unknown): string[] | undefined { + if (!web || typeof web !== "object") { + return undefined; + } + if (!("urlAllowlist" in web)) { + return undefined; + } + const allowlist = (web as { urlAllowlist?: unknown }).urlAllowlist; + if (!Array.isArray(allowlist)) { + return undefined; + } + return allowlist.length > 0 ? allowlist : undefined; +} + export function resolveTimeoutSeconds(value: unknown, fallback: number): number { const parsed = typeof value === "number" && Number.isFinite(value) ? value : fallback; return Math.max(1, Math.floor(parsed));