fix: ensure user config takes precendence over plugin hooks for model resolution (#25167)
This commit is contained in:
@@ -1140,6 +1140,33 @@ const layer: Layer.Layer<
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const hook of plugins) {
|
||||||
|
const p = hook.provider
|
||||||
|
const models = p?.models
|
||||||
|
if (!p || !models) continue
|
||||||
|
|
||||||
|
const providerID = ProviderID.make(p.id)
|
||||||
|
if (disabled.has(providerID)) continue
|
||||||
|
|
||||||
|
const provider = database[providerID]
|
||||||
|
if (!provider) continue
|
||||||
|
const pluginAuth = yield* auth.get(providerID).pipe(Effect.orDie)
|
||||||
|
|
||||||
|
provider.models = yield* Effect.promise(async () => {
|
||||||
|
const next = await models(provider, { auth: pluginAuth })
|
||||||
|
return Object.fromEntries(
|
||||||
|
Object.entries(next).map(([id, model]) => [
|
||||||
|
id,
|
||||||
|
{
|
||||||
|
...model,
|
||||||
|
id: ModelID.make(id),
|
||||||
|
providerID,
|
||||||
|
},
|
||||||
|
]),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// extend database from config
|
// extend database from config
|
||||||
for (const [providerID, provider] of configProviders) {
|
for (const [providerID, provider] of configProviders) {
|
||||||
const existing = database[providerID]
|
const existing = database[providerID]
|
||||||
@@ -1326,33 +1353,6 @@ const layer: Layer.Layer<
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const hook of plugins) {
|
|
||||||
const p = hook.provider
|
|
||||||
const models = p?.models
|
|
||||||
if (!p || !models) continue
|
|
||||||
|
|
||||||
const providerID = ProviderID.make(p.id)
|
|
||||||
if (disabled.has(providerID)) continue
|
|
||||||
|
|
||||||
const provider = providers[providerID]
|
|
||||||
if (!provider) continue
|
|
||||||
const pluginAuth = yield* auth.get(providerID).pipe(Effect.orDie)
|
|
||||||
|
|
||||||
provider.models = yield* Effect.promise(async () => {
|
|
||||||
const next = await models(provider, { auth: pluginAuth })
|
|
||||||
return Object.fromEntries(
|
|
||||||
Object.entries(next).map(([id, model]) => [
|
|
||||||
id,
|
|
||||||
{
|
|
||||||
...model,
|
|
||||||
id: ModelID.make(id),
|
|
||||||
providerID,
|
|
||||||
},
|
|
||||||
]),
|
|
||||||
)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const [id, provider] of Object.entries(providers)) {
|
for (const [id, provider] of Object.entries(providers)) {
|
||||||
const providerID = ProviderID.make(id)
|
const providerID = ProviderID.make(id)
|
||||||
if (!isProviderAllowed(providerID)) {
|
if (!isProviderAllowed(providerID)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user