GeezerVison is showing github.com — feat: Allow provider timeout override (#1982) · meSingh/opencode@aaff1aa
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: packages/opencode/src/config/config.ts +15Lines changed: 15 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -392,6 +392,21 @@ export namespace Config { |
392 | 392 | .object({ |
393 | 393 | apiKey: z.string().optional(), |
394 | 394 | baseURL: z.string().optional(), |
| 395 | + timeout: z |
| 396 | + .union([ |
| 397 | + z |
| 398 | + .number() |
| 399 | + .int() |
| 400 | + .positive() |
| 401 | + .describe( |
| 402 | + "Timeout in milliseconds for requests to this provider. Default is 300000 (5 minutes). Set to false to disable timeout.", |
| 403 | + ), |
| 404 | + z.literal(false).describe("Disable timeout for this provider entirely."), |
| 405 | + ]) |
| 406 | + .optional() |
| 407 | + .describe( |
| 408 | + "Timeout in milliseconds for requests to this provider. Default is 300000 (5 minutes). Set to false to disable timeout.", |
| 409 | + ), |
395 | 410 | }) |
396 | 411 | .catchall(z.any()) |
397 | 412 | .optional(), |
|
Collapse file
Copy file name to clipboardExpand all lines: packages/opencode/src/provider/provider.ts +8-1Lines changed: 8 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -320,9 +320,16 @@ export namespace Provider { |
320 | 320 | const pkg = provider.npm ?? provider.id |
321 | 321 | const mod = await import(await BunProc.install(pkg, "latest")) |
322 | 322 | const fn = mod[Object.keys(mod).find((key) => key.startsWith("create"))!] |
| 323 | + let options = { ...s.providers[provider.id]?.options } |
| 324 | + if (options["timeout"] !== undefined) { |
| 325 | + // Only override fetch if user explicitly sets timeout |
| 326 | + options["fetch"] = async (input: any, init?: any) => { |
| 327 | + return await fetch(input, { ...init, timeout: options["timeout"] }) |
| 328 | + } |
| 329 | + } |
323 | 330 | const loaded = fn({ |
324 | 331 | name: provider.id, |
325 | | - ...s.providers[provider.id]?.options, |
| 332 | + ...options, |
326 | 333 | }) |
327 | 334 | s.sdk.set(provider.id, loaded) |
328 | 335 | return loaded as SDK |
|