Skip to content

Commit 8a321c4

Browse files
authored
fix(native-llm): prefer console opencode token (#28237)
1 parent ef9e567 commit 8a321c4

2 files changed

Lines changed: 29 additions & 6 deletions

File tree

packages/opencode/src/session/llm/native-runtime.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,7 @@ export function status(input: Pick<StreamInput, "model" | "provider" | "auth">):
4242
if (input.model.api.npm !== "@ai-sdk/openai") return { type: "unsupported", reason: "provider package is not OpenAI" }
4343
if (input.auth?.type === "oauth") return { type: "unsupported", reason: "OAuth auth is not supported" }
4444

45-
const apiKey =
46-
input.auth?.type === "api"
47-
? input.auth.key
48-
: typeof input.provider.options.apiKey === "string"
49-
? input.provider.options.apiKey
50-
: undefined
45+
const apiKey = typeof input.provider.options.apiKey === "string" ? input.provider.options.apiKey : input.provider.key
5146
if (!apiKey) return { type: "unsupported", reason: "OpenAI API key is not configured" }
5247

5348
return {

packages/opencode/test/session/llm-native.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,34 @@ describe("session.llm-native.request", () => {
292292
).toEqual({ type: "unsupported", reason: "OpenAI API key is not configured" })
293293
})
294294

295+
test("prefers console provider api key over stored opencode auth", () => {
296+
expect(
297+
LLMNativeRuntime.status({
298+
model: { ...baseModel, providerID: ProviderID.make("opencode") },
299+
provider: {
300+
...providerInfo,
301+
id: ProviderID.make("opencode"),
302+
options: { apiKey: "console-token" },
303+
key: "zen-token",
304+
},
305+
auth: { type: "api", key: "zen-token" },
306+
}),
307+
).toMatchObject({
308+
type: "supported",
309+
apiKey: "console-token",
310+
})
311+
expect(
312+
LLMNativeRuntime.status({
313+
model: baseModel,
314+
provider: { ...providerInfo, options: {}, key: "provider-key" },
315+
auth: undefined,
316+
}),
317+
).toMatchObject({
318+
type: "supported",
319+
apiKey: "provider-key",
320+
})
321+
})
322+
295323
test("native tool wrapper converts thrown errors into typed ToolFailure", async () => {
296324
const wrapped = LLMNativeRuntime.nativeTools(
297325
{

0 commit comments

Comments
 (0)