mirror of
https://github.com/anomalyco/opencode.git
synced 2026-06-01 19:05:38 +00:00
35 lines
1.4 KiB
TypeScript
35 lines
1.4 KiB
TypeScript
import { Effect } from "effect"
|
|
import { ModelV2 } from "../../model"
|
|
import { PluginV2 } from "../../plugin"
|
|
|
|
export const OpenRouterPlugin = PluginV2.define({
|
|
id: PluginV2.ID.make("openrouter"),
|
|
effect: Effect.gen(function* () {
|
|
return {
|
|
"catalog.transform": Effect.fn(function* (evt) {
|
|
for (const item of evt.data) {
|
|
if (item.provider.endpoint.type !== "aisdk") continue
|
|
if (item.provider.endpoint.package !== "@openrouter/ai-sdk-provider") continue
|
|
evt.provider.update(item.provider.id, (provider) => {
|
|
provider.options.headers["HTTP-Referer"] = "https://opencode.ai/"
|
|
provider.options.headers["X-Title"] = "opencode"
|
|
})
|
|
for (const modelID of [ModelV2.ID.make("gpt-5-chat-latest"), ModelV2.ID.make("openai/gpt-5-chat")]) {
|
|
if (!item.models.has(modelID)) continue
|
|
evt.model.update(item.provider.id, modelID, (model) => {
|
|
// These are OpenRouter-specific OpenAI chat aliases that do not work
|
|
// on the generic path. Keep custom providers with matching IDs untouched.
|
|
model.enabled = false
|
|
})
|
|
}
|
|
}
|
|
}),
|
|
"aisdk.sdk": Effect.fn(function* (evt) {
|
|
if (evt.package !== "@openrouter/ai-sdk-provider") return
|
|
const mod = yield* Effect.promise(() => import("@openrouter/ai-sdk-provider"))
|
|
evt.sdk = mod.createOpenRouter(evt.options)
|
|
}),
|
|
}
|
|
}),
|
|
})
|