feat: whitelist/blacklist config options for provider (#3416)

Co-authored-by: Aiden Cline <aidenpcline@gmail.com>
This commit is contained in:
geril07 2025-11-21 10:01:30 +03:00 committed by GitHub
parent a67b616139
commit c0d9f21c0f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 1 deletions

View file

@ -511,6 +511,8 @@ export namespace Config {
z.string(),
ModelsDev.Provider.partial()
.extend({
whitelist: z.array(z.string()).optional(),
blacklist: z.array(z.string()).optional(),
models: z.record(z.string(), ModelsDev.Model.partial()).optional(),
options: z
.object({

View file

@ -365,6 +365,7 @@ export namespace Provider {
}
parsed.models[modelID] = parsedModel
}
database[providerID] = parsed
}
@ -446,6 +447,7 @@ export namespace Provider {
}
for (const [providerID, provider] of Object.entries(providers)) {
const configProvider = config.provider?.[providerID]
const filteredModels = Object.fromEntries(
Object.entries(provider.info.models)
// Filter out blacklisted models
@ -458,8 +460,18 @@ export namespace Provider {
([, model]) =>
((!model.experimental && model.status !== "alpha") || Flag.OPENCODE_ENABLE_EXPERIMENTAL_MODELS) &&
model.status !== "deprecated",
),
)
// Filter by provider's whitelist/blacklist from config
.filter(([modelID]) => {
if (!configProvider) return true
return (
(!configProvider.blacklist || !configProvider.blacklist.includes(modelID)) &&
(!configProvider.whitelist || configProvider.whitelist.includes(modelID))
)
}),
)
provider.info.models = filteredModels
if (Object.keys(provider.info.models).length === 0) {