fix: timeout option (#3229)

This commit is contained in:
Aiden Cline
2025-10-16 17:47:41 -05:00
committed by GitHub
parent 729ad1cb75
commit b24f4e3d2c

View File

@@ -413,8 +413,21 @@ export namespace Provider {
const mod = await import(modPath)
if (options["timeout"] !== undefined) {
// Only override fetch if user explicitly sets timeout
options["fetch"] = async (input: any, init?: any) => {
return await fetch(input, { ...init, timeout: options["timeout"] })
options["fetch"] = async (input: any, init?: BunFetchRequestInit) => {
const { signal, ...rest } = init ?? {}
const signals: AbortSignal[] = []
if (signal) signals.push(signal)
signals.push(AbortSignal.timeout(options["timeout"]))
const combined = signals.length > 1 ? AbortSignal.any(signals) : signals[0]
return fetch(input, {
...rest,
signal: combined,
// @ts-ignore see here: https://github.com/oven-sh/bun/issues/16682
timeout: false,
})
}
}
const fn = mod[Object.keys(mod).find((key) => key.startsWith("create"))!]