diff --git a/packages/core/src/variant.ts b/packages/core/src/variant.ts index f5792727ae2..1f47d37bf41 100644 --- a/packages/core/src/variant.ts +++ b/packages/core/src/variant.ts @@ -88,6 +88,11 @@ const responsesEffort = (effort: string): Overlay => ({ settings: { reasoningEffort: effort, reasoningSummary: "auto", include: ENCRYPTED_REASONING }, }) +const xaiResponses: Protocol = (_, support) => { + if (support.type !== "effort") return [] + return efforts(support.values ?? EFFORTS, responsesEffort) +} + const cloudflareAIGateway: Protocol = (model, support) => { const id = modelID(model) if (id.startsWith("openai/")) return openaiResponses(model, support) @@ -557,7 +562,7 @@ const PROTOCOLS: Readonly> = { "@opencode/ai/providers/mistral": openaiChat, "@opencode/ai/providers/moonshot/chat": moonshotChat, "@opencode/ai/providers/togetherai": openaiChat, - "@opencode/ai/providers/xai": openaiChat, + "@opencode/ai/providers/xai": xaiResponses, "@opencode/ai/providers/zai/chat": zaiChat, "@opencode/ai/providers/zai-coding-plan/chat": zaiChat, diff --git a/packages/core/test/model-resolver.test.ts b/packages/core/test/model-resolver.test.ts index 29ddfe746e3..3fedbcff941 100644 --- a/packages/core/test/model-resolver.test.ts +++ b/packages/core/test/model-resolver.test.ts @@ -9,6 +9,7 @@ import { Credential } from "@opencode/core/credential" import { Integration } from "@opencode/core/integration" import { Compatibility, ID, Info, Model, VariantID } from "@opencode/core/model" import { Provider } from "@opencode/core/provider" +import { Variant } from "@opencode/core/variant" import { ModelResolver } from "@opencode/core/model-resolver" import { AISDK } from "@opencode/core/aisdk" import { Npm } from "@opencode/util/npm" @@ -580,6 +581,29 @@ describe("ModelResolver", () => { }), ) + it.effect("sends xAI Responses effort variants with reasoning summaries", () => + Effect.gen(function* () { + const base = model("@opencode/ai/providers/xai", { providerID: Provider.ID.make("xai"), modelID: "grok-4.6" }) + const catalog = Info.make({ + ...base, + variants: Variant.resolve(base, [{ type: "effort", values: ["low", "high"] }]), + }) + const resolved = yield* ModelResolver.resolveModel( + catalog, + VariantID.make("high"), + Credential.Key.make({ type: "key", key: "secret" }), + ) + const prepared = yield* compileRequest(LLM.request({ model: resolved, prompt: "Hello" })) + + expect(resolved.route.id).toBe("openai-responses") + expect(prepared.body).toMatchObject({ + reasoning: { effort: "high", summary: "auto" }, + include: ["reasoning.encrypted_content"], + }) + expect(prepared.body).not.toHaveProperty("reasoning_effort") + }), + ) + it.effect("overlays selected OpenAI-compatible variant bodies", () => Effect.gen(function* () { const catalog = model(Provider.aisdk("@ai-sdk/openai-compatible"), { diff --git a/packages/core/test/variant.test.ts b/packages/core/test/variant.test.ts index 1366db778d4..c763b9f17b9 100644 --- a/packages/core/test/variant.test.ts +++ b/packages/core/test/variant.test.ts @@ -126,6 +126,26 @@ test("spells Cloudflare AI Gateway variants for their upstream routes", () => { ]) }) +test("spells xAI Responses variants with catalog effort levels", () => { + const supports: Variant.Support[] = [{ type: "effort", values: ["low", "medium", "high", "xhigh"] }] + expect(resolve(model("@opencode/ai/providers/xai", "grok-4.6"), supports)).toEqual( + ["low", "medium", "high", "xhigh"].map((effort) => ({ + id: effort, + settings: { reasoningEffort: effort, reasoningSummary: "auto", include: ["reasoning.encrypted_content"] }, + })), + ) + expect(resolve(model("@opencode/ai/providers/xai", "grok-4.3"), [{ type: "effort", values: ["none", "low"] }])).toEqual([ + { + id: "none", + settings: { reasoningEffort: "none", reasoningSummary: "auto", include: ["reasoning.encrypted_content"] }, + }, + { id: "low", settings: { reasoningEffort: "low", reasoningSummary: "auto", include: ["reasoning.encrypted_content"] } }, + ]) + expect(resolve(model("@opencode/ai/providers/xai", "grok-4.6"), [{ type: "effort" }]).map((item) => item.id)).toEqual([ + "low", "medium", "high", + ]) +}) + test("spells Chat Completions variants for direct providers", () => { expect( resolve(model("@opencode/ai/providers/deepseek", "deepseek-v4-flash"), [