From a52ebbcd51eb6bde7de8ed4d6108c845edba750f Mon Sep 17 00:00:00 2001 From: "Michal J. Gajda" Date: Sat, 25 Jul 2026 21:54:28 +0200 Subject: [PATCH] fix(native-llm): replace hardcoded provider gate with shared support set MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #38893. The native LLM runtime's statusWithFetch() had a hardcoded allowlist of supported provider IDs and npm packages that excluded Google, Amazon Bedrock, Azure, and OpenRouter from the native path, even though native-request.ts had working adapters for them. Export SUPPORTED_NPM_PACKAGES from native-request.ts and use it in the gate so the two stay in sync by construction. Also fix API key propagation for providers with multiple env vars (GOOGLE_API_KEY, GOOGLE_GENERATIVE_AI_API_KEY, GEMINI_API_KEY) by removing the env.length === 1 guard — the found key is now always stored in provider.key. --- packages/opencode/src/provider/provider.ts | 2 +- packages/opencode/src/session/llm/native-request.ts | 10 ++++++++++ packages/opencode/src/session/llm/native-runtime.ts | 7 ++----- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/opencode/src/provider/provider.ts b/packages/opencode/src/provider/provider.ts index a0ab5eb3474d..34294c7bc343 100644 --- a/packages/opencode/src/provider/provider.ts +++ b/packages/opencode/src/provider/provider.ts @@ -1523,7 +1523,7 @@ const layer = Layer.effect( if (!apiKey) continue mergeProvider(providerID, { source: "env", - key: provider.env.length === 1 ? apiKey : undefined, + key: apiKey, }) } diff --git a/packages/opencode/src/session/llm/native-request.ts b/packages/opencode/src/session/llm/native-request.ts index b7f30e24c362..2dd383454d0d 100644 --- a/packages/opencode/src/session/llm/native-request.ts +++ b/packages/opencode/src/session/llm/native-request.ts @@ -13,6 +13,16 @@ import type { ModelMessage } from "ai" import type { Provider } from "@/provider/provider" import { isRecord } from "@/util/record" +export const SUPPORTED_NPM_PACKAGES = new Set([ + "@ai-sdk/openai", + "@ai-sdk/azure", + "@ai-sdk/anthropic", + "@ai-sdk/google", + "@ai-sdk/amazon-bedrock", + "@ai-sdk/openai-compatible", + "@openrouter/ai-sdk-provider", +]) + type ToolInput = { readonly description?: string readonly inputSchema?: unknown diff --git a/packages/opencode/src/session/llm/native-runtime.ts b/packages/opencode/src/session/llm/native-runtime.ts index bac385c59137..81d61906a6f8 100644 --- a/packages/opencode/src/session/llm/native-runtime.ts +++ b/packages/opencode/src/session/llm/native-runtime.ts @@ -51,12 +51,9 @@ function statusWithFetch( input: Pick, fetch: typeof globalThis.fetch | undefined, ): RuntimeStatus { - const providerID = input.model.providerID - if (providerID !== "openai" && providerID !== "anthropic" && !providerID.startsWith("opencode")) - return { type: "unsupported", reason: "provider is not openai, opencode, or anthropic" } const npm = input.model.api.npm - if (npm !== "@ai-sdk/openai" && npm !== "@ai-sdk/openai-compatible" && npm !== "@ai-sdk/anthropic") - return { type: "unsupported", reason: "provider package is not OpenAI, OpenAI-compatible, or Anthropic" } + if (!LLMNative.SUPPORTED_NPM_PACKAGES.has(npm)) + return { type: "unsupported", reason: `provider package ${npm} is not supported by native runtime` } if (input.auth?.type === "oauth" && !(input.provider.id === "openai" && fetch)) { return { type: "unsupported", reason: "OAuth auth requires a provider fetch override" } }