2026-05-13 14:43:08 +00:00
|
|
|
import { Effect } from "effect"
|
2026-06-21 12:05:49 +00:00
|
|
|
import { define } from "@opencode-ai/plugin/v2/effect"
|
2026-05-13 14:43:08 +00:00
|
|
|
import { ProviderV2 } from "../../provider"
|
|
|
|
|
|
2026-06-21 12:05:49 +00:00
|
|
|
export const OpencodePlugin = define({
|
|
|
|
|
id: "opencode",
|
|
|
|
|
effect: Effect.fn(function* (ctx) {
|
2026-05-13 14:43:08 +00:00
|
|
|
let hasKey = false
|
2026-06-21 12:05:49 +00:00
|
|
|
yield* ctx.catalog.transform(
|
|
|
|
|
Effect.fn(function* (evt) {
|
2026-05-30 04:06:08 +00:00
|
|
|
const item = evt.provider.get(ProviderV2.ID.opencode)
|
2026-05-21 00:53:27 +00:00
|
|
|
if (!item) return
|
2026-06-21 12:05:49 +00:00
|
|
|
const integration = yield* ctx.integration.get(item.provider.id)
|
2026-05-13 14:43:08 +00:00
|
|
|
hasKey = Boolean(
|
2026-06-14 12:46:12 +00:00
|
|
|
process.env.OPENCODE_API_KEY || integration?.connections.length || item.provider.request.body.apiKey,
|
2026-05-13 14:43:08 +00:00
|
|
|
)
|
2026-05-21 00:53:27 +00:00
|
|
|
evt.provider.update(item.provider.id, (provider) => {
|
2026-06-03 17:32:58 +00:00
|
|
|
if (!hasKey) provider.request.body.apiKey = "public"
|
2026-05-21 00:53:27 +00:00
|
|
|
})
|
2026-05-13 14:43:08 +00:00
|
|
|
if (hasKey) return
|
2026-05-21 00:53:27 +00:00
|
|
|
for (const model of item.models.values()) {
|
|
|
|
|
if (!model.cost.some((cost) => cost.input > 0)) continue
|
|
|
|
|
evt.model.update(item.provider.id, model.id, (draft) => {
|
|
|
|
|
draft.enabled = false
|
|
|
|
|
})
|
|
|
|
|
}
|
2026-05-13 14:43:08 +00:00
|
|
|
}),
|
2026-06-21 12:05:49 +00:00
|
|
|
)
|
2026-05-13 14:43:08 +00:00
|
|
|
}),
|
|
|
|
|
})
|