feat: Allow provider timeout override (#1982)

This commit is contained in:
Beshoy Girgis
2025-08-31 13:06:02 -05:00
committed by GitHub
parent 029612d8d5
commit e4cc05a975
2 changed files with 23 additions and 1 deletions

View File

@@ -392,6 +392,21 @@ export namespace Config {
.object({
apiKey: 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())
.optional(),

View File

@@ -320,9 +320,16 @@ export namespace Provider {
const pkg = provider.npm ?? provider.id
const mod = await import(await BunProc.install(pkg, "latest"))
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({
name: provider.id,
...s.providers[provider.id]?.options,
...options,
})
s.sdk.set(provider.id, loaded)
return loaded as SDK