|
| 1 | +import { parseFiniteNumber } from "openclaw/plugin-sdk/number-runtime"; |
1 | 2 | import { fetchWithSsrFGuard } from "openclaw/plugin-sdk/ssrf-runtime"; |
2 | 3 | import { normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime"; |
3 | 4 | import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/string-coerce-runtime"; |
@@ -162,6 +163,11 @@ function appendBrowserToolModelHint(message: string): string { |
162 | 163 |
|
163 | 164 | type BrowserFetchFailureKind = "timeout" | "aborted" | "persistent"; |
164 | 165 |
|
| 166 | +function resolveBrowserFetchTimeoutMs(timeoutMs: number | undefined): number { |
| 167 | + const parsed = parseFiniteNumber(timeoutMs); |
| 168 | + return Math.max(1, Math.floor(parsed ?? 5000)); |
| 169 | +} |
| 170 | + |
165 | 171 | function classifyBrowserFetchFailure(err: unknown): BrowserFetchFailureKind { |
166 | 172 | const msg = normalizeErrorMessage(err); |
167 | 173 | const msgLower = normalizeLowercaseStringOrEmpty(msg); |
@@ -228,7 +234,7 @@ async function fetchHttpJson<T>( |
228 | 234 | url: string, |
229 | 235 | init: RequestInit & { timeoutMs?: number }, |
230 | 236 | ): Promise<T> { |
231 | | - const timeoutMs = init.timeoutMs ?? 5000; |
| 237 | + const timeoutMs = resolveBrowserFetchTimeoutMs(init.timeoutMs); |
232 | 238 | const ctrl = new AbortController(); |
233 | 239 | const upstreamSignal = init.signal; |
234 | 240 | let upstreamAbortListener: (() => void) | undefined; |
@@ -278,7 +284,7 @@ export async function fetchBrowserJson<T>( |
278 | 284 | url: string, |
279 | 285 | init?: RequestInit & { timeoutMs?: number }, |
280 | 286 | ): Promise<T> { |
281 | | - const timeoutMs = init?.timeoutMs ?? 5000; |
| 287 | + const timeoutMs = resolveBrowserFetchTimeoutMs(init?.timeoutMs); |
282 | 288 | let isDispatcherPath = false; |
283 | 289 | try { |
284 | 290 | if (isAbsoluteHttp(url)) { |
|
0 commit comments