fix(core): map xAI native options (#39787)
This commit is contained in:
parent
98229d466d
commit
5b4ebf3e9d
2 changed files with 57 additions and 1 deletions
|
|
@ -32,7 +32,7 @@ export function map(packageName: string | undefined, settings: Readonly<Record<s
|
||||||
settings: {
|
settings: {
|
||||||
...baseSettings,
|
...baseSettings,
|
||||||
...mapAPIKey(settings),
|
...mapAPIKey(settings),
|
||||||
...mapProviderOptions("xai", settings),
|
...mapXAIOptions(settings),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -48,6 +48,16 @@ function mapAPIKey(settings: Readonly<Record<string, unknown>>) {
|
||||||
return typeof settings.apiKey === "string" ? { apiKey: settings.apiKey } : {}
|
return typeof settings.apiKey === "string" ? { apiKey: settings.apiKey } : {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function mapXAIOptions(settings: Readonly<Record<string, unknown>>) {
|
||||||
|
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<Record<string, unknown>>) {
|
function mapProviderOptions(namespace: string, settings: Readonly<Record<string, unknown>>) {
|
||||||
const values = Object.fromEntries(
|
const values = Object.fromEntries(
|
||||||
Object.entries(settings).filter(
|
Object.entries(settings).filter(
|
||||||
|
|
|
||||||
46
packages/core/test/aisdk-native.test.ts
Normal file
46
packages/core/test/aisdk-native.test.ts
Normal file
|
|
@ -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: {},
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
Loading…
Add table
Add a link
Reference in a new issue