Browse Source

tweak: default to disabling fetch timeout in provider options

Aiden Cline 3 months ago
parent
commit
51bba6e634
1 changed files with 15 additions and 12 deletions
  1. 15 12
      packages/opencode/src/provider/provider.ts

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

@@ -516,26 +516,29 @@ export namespace Provider {
       const modPath =
         provider.id === "google-vertex-anthropic" ? `${installedPath}/dist/anthropic/index.mjs` : installedPath
       const mod = await import(modPath)
-      if (options["timeout"] !== undefined && options["timeout"] !== null) {
+
+      const customFetch = options["fetch"]
+
+      options["fetch"] = async (input: any, init?: BunFetchRequestInit) => {
         // Preserve custom fetch if it exists, wrap it with timeout logic
-        const customFetch = options["fetch"]
-        options["fetch"] = async (input: any, init?: BunFetchRequestInit) => {
-          const { signal, ...rest } = init ?? {}
+        const fetchFn = customFetch ?? fetch
+        const opts = init ?? {}
 
+        if (options["timeout"] !== undefined && options["timeout"] !== null) {
           const signals: AbortSignal[] = []
-          if (signal) signals.push(signal)
+          if (opts.signal) signals.push(opts.signal)
           if (options["timeout"] !== false) signals.push(AbortSignal.timeout(options["timeout"]))
 
           const combined = signals.length > 1 ? AbortSignal.any(signals) : signals[0]
 
-          const fetchFn = customFetch ?? fetch
-          return fetchFn(input, {
-            ...rest,
-            signal: combined,
-            // @ts-ignore see here: https://github.com/oven-sh/bun/issues/16682
-            timeout: false,
-          })
+          opts.signal = combined
         }
+
+        return fetchFn(input, {
+          ...opts,
+          // @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 loaded = fn({