Skip to content

Commit b24f4e3

Browse files
authored
fix: timeout option (#3229)
1 parent 729ad1c commit b24f4e3

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

packages/opencode/src/provider/provider.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,21 @@ export namespace Provider {
413413
const mod = await import(modPath)
414414
if (options["timeout"] !== undefined) {
415415
// Only override fetch if user explicitly sets timeout
416-
options["fetch"] = async (input: any, init?: any) => {
417-
return await fetch(input, { ...init, timeout: options["timeout"] })
416+
options["fetch"] = async (input: any, init?: BunFetchRequestInit) => {
417+
const { signal, ...rest } = init ?? {}
418+
419+
const signals: AbortSignal[] = []
420+
if (signal) signals.push(signal)
421+
signals.push(AbortSignal.timeout(options["timeout"]))
422+
423+
const combined = signals.length > 1 ? AbortSignal.any(signals) : signals[0]
424+
425+
return fetch(input, {
426+
...rest,
427+
signal: combined,
428+
// @ts-ignore see here: https://github.com/oven-sh/bun/issues/16682
429+
timeout: false,
430+
})
418431
}
419432
}
420433
const fn = mod[Object.keys(mod).find((key) => key.startsWith("create"))!]

0 commit comments

Comments
 (0)