mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-22 10:14:22 +01:00
feat: Allow provider timeout override (#1982)
This commit is contained in:
@@ -392,6 +392,21 @@ export namespace Config {
|
|||||||
.object({
|
.object({
|
||||||
apiKey: z.string().optional(),
|
apiKey: z.string().optional(),
|
||||||
baseURL: z.string().optional(),
|
baseURL: z.string().optional(),
|
||||||
|
timeout: z
|
||||||
|
.union([
|
||||||
|
z
|
||||||
|
.number()
|
||||||
|
.int()
|
||||||
|
.positive()
|
||||||
|
.describe(
|
||||||
|
"Timeout in milliseconds for requests to this provider. Default is 300000 (5 minutes). Set to false to disable timeout.",
|
||||||
|
),
|
||||||
|
z.literal(false).describe("Disable timeout for this provider entirely."),
|
||||||
|
])
|
||||||
|
.optional()
|
||||||
|
.describe(
|
||||||
|
"Timeout in milliseconds for requests to this provider. Default is 300000 (5 minutes). Set to false to disable timeout.",
|
||||||
|
),
|
||||||
})
|
})
|
||||||
.catchall(z.any())
|
.catchall(z.any())
|
||||||
.optional(),
|
.optional(),
|
||||||
|
|||||||
@@ -320,9 +320,16 @@ export namespace Provider {
|
|||||||
const pkg = provider.npm ?? provider.id
|
const pkg = provider.npm ?? provider.id
|
||||||
const mod = await import(await BunProc.install(pkg, "latest"))
|
const mod = await import(await BunProc.install(pkg, "latest"))
|
||||||
const fn = mod[Object.keys(mod).find((key) => key.startsWith("create"))!]
|
const fn = mod[Object.keys(mod).find((key) => key.startsWith("create"))!]
|
||||||
|
let options = { ...s.providers[provider.id]?.options }
|
||||||
|
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"] })
|
||||||
|
}
|
||||||
|
}
|
||||||
const loaded = fn({
|
const loaded = fn({
|
||||||
name: provider.id,
|
name: provider.id,
|
||||||
...s.providers[provider.id]?.options,
|
...options,
|
||||||
})
|
})
|
||||||
s.sdk.set(provider.id, loaded)
|
s.sdk.set(provider.id, loaded)
|
||||||
return loaded as SDK
|
return loaded as SDK
|
||||||
|
|||||||
Reference in New Issue
Block a user