core: expose v2 model listing API (#25821)

This commit is contained in:
Dax 2026-05-13 10:43:08 -04:00 committed by GitHub
commit 8345152319
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
138 changed files with 8188 additions and 302 deletions

View file

@ -0,0 +1,27 @@
import { Effect } from "effect"
import { PluginV2 } from "../../plugin"
import { ProviderV2 } from "../../provider"
export const OpencodePlugin = PluginV2.define({
id: PluginV2.ID.make("opencode"),
effect: Effect.gen(function* () {
let hasKey = false
return {
"provider.update": Effect.fn(function* (evt) {
if (evt.provider.id !== ProviderV2.ID.opencode) return
hasKey = Boolean(
process.env.OPENCODE_API_KEY ||
evt.provider.env.some((item) => process.env[item]) ||
evt.provider.options.aisdk.provider.apiKey ||
(evt.provider.enabled && evt.provider.enabled.via === "auth"),
)
if (!hasKey) evt.provider.options.aisdk.provider.apiKey = "public"
}),
"model.update": Effect.fn(function* (evt) {
if (evt.model.providerID !== ProviderV2.ID.opencode) return
if (hasKey) return
if (evt.model.cost.some((item) => item.input > 0)) evt.cancel = true
}),
}
}),
})