From 5b4ebf3e9d519159c5f41b5e9c9712e73aae80bc Mon Sep 17 00:00:00 2001 From: Aiden Cline <63023139+rekram1-node@users.noreply.github.com> Date: Thu, 30 Jul 2026 21:42:53 -0500 Subject: [PATCH] fix(core): map xAI native options (#39787) --- packages/core/src/aisdk-native.ts | 12 ++++++- packages/core/test/aisdk-native.test.ts | 46 +++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 packages/core/test/aisdk-native.test.ts diff --git a/packages/core/src/aisdk-native.ts b/packages/core/src/aisdk-native.ts index f2b2c595ef2..b748d617d4d 100644 --- a/packages/core/src/aisdk-native.ts +++ b/packages/core/src/aisdk-native.ts @@ -32,7 +32,7 @@ export function map(packageName: string | undefined, settings: Readonly>) { return typeof settings.apiKey === "string" ? { apiKey: settings.apiKey } : {} } +function mapXAIOptions(settings: Readonly>) { + const options = { + ...(typeof settings.reasoningEffort === "string" ? { reasoningEffort: settings.reasoningEffort } : {}), + ...(typeof settings.store === "boolean" ? { store: settings.store } : {}), + ...(typeof settings.promptCacheKey === "string" ? { promptCacheKey: settings.promptCacheKey } : {}), + } + if (Object.keys(options).length === 0) return {} + return { providerOptions: { xai: options } } +} + function mapProviderOptions(namespace: string, settings: Readonly>) { const values = Object.fromEntries( Object.entries(settings).filter( diff --git a/packages/core/test/aisdk-native.test.ts b/packages/core/test/aisdk-native.test.ts new file mode 100644 index 00000000000..13825d4f107 --- /dev/null +++ b/packages/core/test/aisdk-native.test.ts @@ -0,0 +1,46 @@ +import { describe, expect, test } from "bun:test" +import { AISDKNative } from "@opencode-ai/core/aisdk-native" + +describe("AISDKNative", () => { + test("maps supported xAI settings", () => { + expect( + AISDKNative.map("@ai-sdk/xai", { + apiKey: "secret", + baseURL: "https://xai.example/v1", + reasoningEffort: "custom", + store: true, + promptCacheKey: "cache-key", + }), + ).toEqual({ + package: "@opencode-ai/ai/providers/xai", + settings: { + apiKey: "secret", + baseURL: "https://xai.example/v1", + providerOptions: { + xai: { + reasoningEffort: "custom", + store: true, + promptCacheKey: "cache-key", + }, + }, + }, + }) + }) + + test("omits invalid and unsupported xAI settings", () => { + expect( + AISDKNative.map("@ai-sdk/xai", { + reasoningEffort: 10, + store: "yes", + include: ["unknown"], + logprobs: true, + topLogprobs: 8, + previousResponseId: "response-id", + searchParameters: { mode: "auto" }, + }), + ).toEqual({ + package: "@opencode-ai/ai/providers/xai", + settings: {}, + }) + }) +})