Sfoglia il codice sorgente

fix: timeout option (#3229)

Aiden Cline 10 mesi fa
parent
commit
b24f4e3d2c
1 ha cambiato i file con 15 aggiunte e 2 eliminazioni
  1. 15 2
      packages/opencode/src/provider/provider.ts

+ 15 - 2
packages/opencode/src/provider/provider.ts

@@ -413,8 +413,21 @@ export namespace Provider {
       const mod = await import(modPath)
       const mod = await import(modPath)
       if (options["timeout"] !== undefined) {
       if (options["timeout"] !== undefined) {
         // Only override fetch if user explicitly sets timeout
         // 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"))!]
       const fn = mod[Object.keys(mod).find((key) => key.startsWith("create"))!]