mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-16 13:05:14 +03:00
fix(core): request xAI reasoning summaries on Responses variants (#51964)
This commit is contained in:
committed by
GitHub
Unverified
parent
49437a25b1
commit
3ab5c1433c
@@ -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<Record<string, Protocol>> = {
|
||||
"@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,
|
||||
|
||||
|
||||
@@ -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"), {
|
||||
|
||||
@@ -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"), [
|
||||
|
||||
Reference in New Issue
Block a user