fix(native-llm): prefer console opencode token (#28237)
This commit is contained in:
@@ -42,12 +42,7 @@ export function status(input: Pick<StreamInput, "model" | "provider" | "auth">):
|
|||||||
if (input.model.api.npm !== "@ai-sdk/openai") return { type: "unsupported", reason: "provider package is not OpenAI" }
|
if (input.model.api.npm !== "@ai-sdk/openai") return { type: "unsupported", reason: "provider package is not OpenAI" }
|
||||||
if (input.auth?.type === "oauth") return { type: "unsupported", reason: "OAuth auth is not supported" }
|
if (input.auth?.type === "oauth") return { type: "unsupported", reason: "OAuth auth is not supported" }
|
||||||
|
|
||||||
const apiKey =
|
const apiKey = typeof input.provider.options.apiKey === "string" ? input.provider.options.apiKey : input.provider.key
|
||||||
input.auth?.type === "api"
|
|
||||||
? input.auth.key
|
|
||||||
: typeof input.provider.options.apiKey === "string"
|
|
||||||
? input.provider.options.apiKey
|
|
||||||
: undefined
|
|
||||||
if (!apiKey) return { type: "unsupported", reason: "OpenAI API key is not configured" }
|
if (!apiKey) return { type: "unsupported", reason: "OpenAI API key is not configured" }
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -292,6 +292,34 @@ describe("session.llm-native.request", () => {
|
|||||||
).toEqual({ type: "unsupported", reason: "OpenAI API key is not configured" })
|
).toEqual({ type: "unsupported", reason: "OpenAI API key is not configured" })
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test("prefers console provider api key over stored opencode auth", () => {
|
||||||
|
expect(
|
||||||
|
LLMNativeRuntime.status({
|
||||||
|
model: { ...baseModel, providerID: ProviderID.make("opencode") },
|
||||||
|
provider: {
|
||||||
|
...providerInfo,
|
||||||
|
id: ProviderID.make("opencode"),
|
||||||
|
options: { apiKey: "console-token" },
|
||||||
|
key: "zen-token",
|
||||||
|
},
|
||||||
|
auth: { type: "api", key: "zen-token" },
|
||||||
|
}),
|
||||||
|
).toMatchObject({
|
||||||
|
type: "supported",
|
||||||
|
apiKey: "console-token",
|
||||||
|
})
|
||||||
|
expect(
|
||||||
|
LLMNativeRuntime.status({
|
||||||
|
model: baseModel,
|
||||||
|
provider: { ...providerInfo, options: {}, key: "provider-key" },
|
||||||
|
auth: undefined,
|
||||||
|
}),
|
||||||
|
).toMatchObject({
|
||||||
|
type: "supported",
|
||||||
|
apiKey: "provider-key",
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
test("native tool wrapper converts thrown errors into typed ToolFailure", async () => {
|
test("native tool wrapper converts thrown errors into typed ToolFailure", async () => {
|
||||||
const wrapped = LLMNativeRuntime.nativeTools(
|
const wrapped = LLMNativeRuntime.nativeTools(
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user