From 2b9cd892baa273166059544df1ba15746d961710 Mon Sep 17 00:00:00 2001 From: Aiden Cline <63023139+rekram1-node@users.noreply.github.com> Date: Thu, 8 Oct 2026 15:20:20 -0500 Subject: [PATCH] refactor(core): move provider env key exceptions into plugins (#54005) --- packages/core/src/plugin/models-dev.ts | 15 ++--------- packages/core/src/plugin/provider.ts | 4 +++ packages/core/src/plugin/provider/azure.ts | 5 ++++ .../plugin/provider/cloudflare-workers-ai.ts | 4 +++ .../core/src/plugin/provider/databricks.ts | 12 +++++++++ .../core/src/plugin/provider/google-vertex.ts | 6 +++++ packages/core/src/plugin/provider/neon.ts | 12 +++++++++ packages/core/test/plugin/models-dev.test.ts | 26 +++++-------------- 8 files changed, 51 insertions(+), 33 deletions(-) create mode 100644 packages/core/src/plugin/provider/databricks.ts create mode 100644 packages/core/src/plugin/provider/neon.ts diff --git a/packages/core/src/plugin/models-dev.ts b/packages/core/src/plugin/models-dev.ts index f2ed1817fb8..11a58150e05 100644 --- a/packages/core/src/plugin/models-dev.ts +++ b/packages/core/src/plugin/models-dev.ts @@ -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() function snapshots(data: readonly ModelsDev.Snapshot[]) { diff --git a/packages/core/src/plugin/provider.ts b/packages/core/src/plugin/provider.ts index 3f34c7bfcfb..d7b0654a6ce 100644 --- a/packages/core/src/plugin/provider.ts +++ b/packages/core/src/plugin/provider.ts @@ -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, diff --git a/packages/core/src/plugin/provider/azure.ts b/packages/core/src/plugin/provider/azure.ts index eb562af09c2..15f44888e1c 100644 --- a/packages/core/src/plugin/provider/azure.ts +++ b/packages/core/src/plugin/provider/azure.ts @@ -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: { diff --git a/packages/core/src/plugin/provider/cloudflare-workers-ai.ts b/packages/core/src/plugin/provider/cloudflare-workers-ai.ts index 0efa0935443..c66d0b9270b 100644 --- a/packages/core/src/plugin/provider/cloudflare-workers-ai.ts +++ b/packages/core/src/plugin/provider/cloudflare-workers-ai.ts @@ -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: { diff --git a/packages/core/src/plugin/provider/databricks.ts b/packages/core/src/plugin/provider/databricks.ts new file mode 100644 index 00000000000..36c6be717ad --- /dev/null +++ b/packages/core/src/plugin/provider/databricks.ts @@ -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"] } }) + }) + }), +}) diff --git a/packages/core/src/plugin/provider/google-vertex.ts b/packages/core/src/plugin/provider/google-vertex.ts index 1d6bfee69b5..12f56735c10 100644 --- a/packages/core/src/plugin/provider/google-vertex.ts +++ b/packages/core/src/plugin/provider/google-vertex.ts @@ -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: { diff --git a/packages/core/src/plugin/provider/neon.ts b/packages/core/src/plugin/provider/neon.ts new file mode 100644 index 00000000000..1b11e87a97a --- /dev/null +++ b/packages/core/src/plugin/provider/neon.ts @@ -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"] } }) + }) + }), +}) diff --git a/packages/core/test/plugin/models-dev.test.ts b/packages/core/test/plugin/models-dev.test.ts index 47056cf891d..58c1fe6f125 100644 --- a/packages/core/test/plugin/models-dev.test.ts +++ b/packages/core/test/plugin/models-dev.test.ts @@ -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"] }], + }) }), )