refactor(core): move provider env key exceptions into plugins (#54005)

This commit is contained in:
Aiden Cline
2026-10-08 15:20:20 -05:00
committed by GitHub
Unverified
parent 8059cdcbdf
commit 2b9cd892ba
8 changed files with 51 additions and 33 deletions
+2 -13
View File
@@ -45,7 +45,8 @@ export const ModelsDevPlugin = define({
integrationID,
method: {
type: "env",
names: environmentNames(provider),
// Every listed variable is treated as a key; plugins override providers that also list setup values.
names: [...provider.environment],
},
})
}
@@ -74,18 +75,6 @@ export const ModelsDevPlugin = define({
}),
})
function environmentNames(provider: ModelsDev.Snapshot) {
if (provider.info.id === Provider.ID.azure)
return [...provider.environment.filter((name) => name.endsWith("_API_KEY")), "AZURE_COGNITIVE_SERVICES_API_KEY"]
// models.dev advertises project, location, and the ADC credentials file path for
// Vertex. Those configure Google auth rather than carrying a key, so only the
// Express Mode key may become a credential; GoogleVertexPlugin handles activation.
if (provider.info.id === Provider.ID.googleVertex) return ["GOOGLE_VERTEX_API_KEY"]
if (provider.info.id === "cloudflare-workers-ai")
return ["CLOUDFLARE_API_KEY", "CLOUDFLARE_WORKERS_AI_TOKEN", "CLOUDFLARE_API_TOKEN"]
return [...provider.environment]
}
const prepared = new WeakMap<readonly ModelsDev.Snapshot[], readonly ModelsDev.Snapshot[]>()
function snapshots(data: readonly ModelsDev.Snapshot[]) {
+4
View File
@@ -5,6 +5,7 @@ import { ChatGPTPlugin } from "./provider/chatgpt.js"
import { CloudflareAIGatewayPlugin } from "./provider/cloudflare-ai-gateway.js"
import { CloudflareWorkersAIPlugin } from "./provider/cloudflare-workers-ai.js"
import { CoherePlugin } from "./provider/cohere.js"
import { DatabricksPlugin } from "./provider/databricks.js"
import { DigitalOceanPlugin } from "./provider/digitalocean.js"
import { DynamicProviderPlugin } from "./provider/dynamic.js"
import { GithubCopilotPlugin } from "./provider/github-copilot.js"
@@ -14,6 +15,7 @@ import { KiloPlugin } from "./provider/kilo.js"
import { LLMGatewayPlugin } from "./provider/llmgateway.js"
import { LMStudioPlugin } from "./provider/lmstudio.js"
import { ModalPlugin } from "./provider/modal.js"
import { NeonPlugin } from "./provider/neon.js"
import { NvidiaPlugin } from "./provider/nvidia.js"
import { OllamaPlugin } from "./provider/ollama.js"
import { OpenAIPlugin } from "./provider/openai.js"
@@ -38,6 +40,7 @@ export const ProviderPlugins: PluginInternal.InternalPlugin[] = [
CloudflareAIGatewayPlugin,
CloudflareWorkersAIPlugin,
CoherePlugin,
DatabricksPlugin,
DigitalOceanPlugin,
GithubCopilotPlugin,
GitLabPlugin,
@@ -46,6 +49,7 @@ export const ProviderPlugins: PluginInternal.InternalPlugin[] = [
LLMGatewayPlugin,
LMStudioPlugin,
ModalPlugin,
NeonPlugin,
NvidiaPlugin,
OllamaPlugin,
OpencodePlugin,
@@ -137,6 +137,11 @@ export function make(
const listing: { resources?: readonly Form.Option[] } = {}
yield* ctx.integration.transform((editor) => {
// The retired azure-cognitive-services provider's env var still connects Azure.
editor.method.update({
integrationID: Provider.ID.azure,
method: { type: "env", names: ["AZURE_API_KEY", "AZURE_COGNITIVE_SERVICES_API_KEY"] },
})
editor.method.update({
integrationID: Provider.ID.azure,
method: {
@@ -24,6 +24,10 @@ export const CloudflareWorkersAIPlugin = define({
])
})
yield* ctx.integration.transform((editor) => {
editor.method.update({
integrationID: providerID,
method: { type: "env", names: ["CLOUDFLARE_API_KEY", "CLOUDFLARE_WORKERS_AI_TOKEN", "CLOUDFLARE_API_TOKEN"] },
})
editor.method.update({
integrationID: providerID,
method: {
@@ -0,0 +1,12 @@
import { Effect } from "effect"
import { define } from "@opencode/plugin/effect/plugin"
export const DatabricksPlugin = define({
id: "opencode.provider.databricks",
effect: Effect.fn(function* (ctx) {
yield* ctx.integration.transform((editor) => {
// models.dev also lists DATABRICKS_HOST, which only fills the base URL template.
editor.method.update({ integrationID: "databricks", method: { type: "env", names: ["DATABRICKS_TOKEN"] } })
})
}),
})
@@ -108,6 +108,12 @@ export const GoogleVertexPlugin = define({
})
yield* ctx.integration.transform((editor) => {
// models.dev lists project, location, and the ADC file path, which configure Google auth rather than
// carrying a key. The Express Mode key is the only env credential.
editor.method.update({
integrationID: Provider.ID.googleVertex,
method: { type: "env", names: ["GOOGLE_VERTEX_API_KEY"] },
})
editor.method.update({
integrationID: Provider.ID.googleVertex,
method: {
+12
View File
@@ -0,0 +1,12 @@
import { Effect } from "effect"
import { define } from "@opencode/plugin/effect/plugin"
export const NeonPlugin = define({
id: "opencode.provider.neon",
effect: Effect.fn(function* (ctx) {
yield* ctx.integration.transform((editor) => {
// models.dev also lists NEON_AI_GATEWAY_BASE_URL, which only fills the base URL template.
editor.method.update({ integrationID: "neon", method: { type: "env", names: ["NEON_AI_GATEWAY_TOKEN"] } })
})
}),
})
+6 -20
View File
@@ -903,7 +903,7 @@ describe("ModelsDevPlugin", () => {
expect(yield* providers.get(Provider.ID.make("google-vertex-anthropic"))).toBeUndefined()
expect(yield* integrations.get(Integration.ID.make("azure"))).toBeDefined()
expect(yield* integrations.get(Integration.ID.make("azure"))).toMatchObject({
methods: [{ type: "key" }, { type: "env", names: ["AZURE_API_KEY", "AZURE_COGNITIVE_SERVICES_API_KEY"] }],
methods: [{ type: "key" }, { type: "env", names: ["AZURE_RESOURCE_NAME", "AZURE_API_KEY"] }],
})
expect(yield* integrations.get(Integration.ID.make("google-vertex"))).toBeDefined()
expect(yield* integrations.get(Integration.ID.make("azure-cognitive-services"))).toBeUndefined()
@@ -913,7 +913,7 @@ describe("ModelsDevPlugin", () => {
}),
)
it.effect("advertises only credential-bearing environment variables", () =>
it.effect("registers every listed environment variable for provider plugins to narrow", () =>
Effect.gen(function* () {
const integrations = yield* Integration.Service
const providers = yield* Provider.Service
@@ -955,29 +955,15 @@ describe("ModelsDevPlugin", () => {
),
)
// Vertex authenticates through ADC; project, location, and the credentials
// file path are configuration, not API keys.
expect(yield* integrations.get(Integration.ID.make("google-vertex"))).toMatchObject({
methods: [{ type: "key" }, { type: "env", names: ["GOOGLE_VERTEX_API_KEY"] }],
})
expect(yield* integrations.get(Integration.ID.make("cloudflare-workers-ai"))).toMatchObject({
methods: [
{ type: "key" },
{
type: "env",
names: ["CLOUDFLARE_API_KEY", "CLOUDFLARE_WORKERS_AI_TOKEN", "CLOUDFLARE_API_TOKEN"],
},
{ type: "env", names: ["GOOGLE_VERTEX_PROJECT", "GOOGLE_VERTEX_LOCATION", "GOOGLE_APPLICATION_CREDENTIALS"] },
],
})
yield* withEnv({ CLOUDFLARE_ACCOUNT_ID: "account", CLOUDFLARE_API_KEY: "token" }, () =>
integrations.connection
.active(Integration.ID.make("cloudflare-workers-ai"))
.pipe(
Effect.tap((connection) =>
Effect.sync(() => expect(connection).toEqual({ type: "env", name: "CLOUDFLARE_API_KEY" })),
),
),
)
expect(yield* integrations.get(Integration.ID.make("cloudflare-workers-ai"))).toMatchObject({
methods: [{ type: "key" }, { type: "env", names: ["CLOUDFLARE_ACCOUNT_ID", "CLOUDFLARE_API_KEY"] }],
})
}),
)