mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-30 14:14:20 +01:00
properly support model level npm definition
This commit is contained in:
@@ -161,7 +161,7 @@ export namespace Provider {
|
|||||||
string,
|
string,
|
||||||
{ providerID: string; modelID: string; info: ModelsDev.Model; language: LanguageModel }
|
{ providerID: string; modelID: string; info: ModelsDev.Model; language: LanguageModel }
|
||||||
>()
|
>()
|
||||||
const sdk = new Map<string, SDK>()
|
const sdk = new Map<number, SDK>()
|
||||||
|
|
||||||
log.info("init")
|
log.info("init")
|
||||||
|
|
||||||
@@ -326,23 +326,24 @@ export namespace Provider {
|
|||||||
providerID: provider.id,
|
providerID: provider.id,
|
||||||
})
|
})
|
||||||
const s = await state()
|
const s = await state()
|
||||||
const existing = s.sdk.get(provider.id)
|
|
||||||
if (existing) return existing
|
|
||||||
const pkg = model.provider?.npm ?? provider.npm ?? provider.id
|
const pkg = model.provider?.npm ?? provider.npm ?? provider.id
|
||||||
|
const options = { ...s.providers[provider.id]?.options }
|
||||||
|
const key = Bun.hash.xxHash32(JSON.stringify({ pkg, options }))
|
||||||
|
const existing = s.sdk.get(key)
|
||||||
|
if (existing) return existing
|
||||||
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"))!]
|
|
||||||
let options = { ...s.providers[provider.id]?.options }
|
|
||||||
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) => {
|
options["fetch"] = async (input: any, init?: any) => {
|
||||||
return await fetch(input, { ...init, timeout: options["timeout"] })
|
return await fetch(input, { ...init, timeout: options["timeout"] })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const fn = mod[Object.keys(mod).find((key) => key.startsWith("create"))!]
|
||||||
const loaded = fn({
|
const loaded = fn({
|
||||||
name: provider.id,
|
name: provider.id,
|
||||||
...options,
|
...options,
|
||||||
})
|
})
|
||||||
s.sdk.set(provider.id, loaded)
|
s.sdk.set(key, loaded)
|
||||||
return loaded as SDK
|
return loaded as SDK
|
||||||
})().catch((e) => {
|
})().catch((e) => {
|
||||||
throw new InitError({ providerID: provider.id }, { cause: e })
|
throw new InitError({ providerID: provider.id }, { cause: e })
|
||||||
|
|||||||
Reference in New Issue
Block a user