Files
openclaw/extensions/xai/runtime-model-compat.ts
kiranmagic7 095f3e1a44 feat(xai): add Grok 4.6 catalog and preserve OAuth xhigh (#122762)
* feat(xai): add Grok 4.6 catalog and preserve OAuth xhigh

Add first-class Grok 4.6 discovery, pricing, and reasoning metadata while
keeping the existing Grok 4.3 API-key and server-tool defaults unchanged.
Preserve xhigh only for Grok 4.6 so OAuth auto no longer inherits the
Grok 4.5 high downgrade.

Closes nothing; tracks #122734.

* fix(xai): resolve the OAuth auto alias to its canonical model in the thinking policy

The OAuth catalog row keeps id "auto" and records the provider-selected
target in params.canonicalModelId; judging the raw alias collapsed the
default OAuth route to an off-only thinking picker for every model.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* test(xai): refresh catalog-order assertions and restore stream deadlines for Grok 4.6

Exact-order catalog and onboarding arrays now include the new row with its
metadata assertion; payload-capture timeouts return to their original
values, Grok 4.5 off-clamp and Grok 4.3 modern-model coverage are
restored, and the Grok 4.6 xhigh boundary test passes its id explicitly.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* feat(agents): add Grok 4.6 to the curated high-signal live matrix

xai is a curated-only high-signal provider, so the new flagship was
structurally excluded from default live sweeps; add it alongside
Grok 4.5 with its test and docs mirrors, matching the 4.5 precedent.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* fix(xai): align Grok frontier metadata

* fix(xai): align Grok 4.6 catalog contract

Remove the unsupported moving alias, centralize OAuth auto target resolution, correct cached pricing, and keep live coverage on the stable xhigh completion path.

Co-authored-by: Kiran Magic <262980978+kiranmagic7@users.noreply.github.com>

---------

Co-authored-by: Kiran Magic <262980978+kiranmagic7@users.noreply.github.com>
Co-authored-by: Kiran Magic <kiran@Alices-Laptop.local>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Co-authored-by: Kiran <kiranmagic7@users.noreply.github.com>
Co-authored-by: Peter Steinberger <steipete@gmail.com>
2026-08-12 21:29:51 -07:00

90 lines
3.1 KiB
TypeScript

// Xai plugin module implements runtime model compat behavior.
// Reasoning effort is configurable only for current flagship Grok models; encrypted reasoning
// include/replay is handled separately in stream.ts for every reasoning-capable xAI model.
import { applyXaiModelCompat } from "./model-compat.js";
import { isXaiFrontierModelId, isXaiGrok46ModelId } from "./model-id.js";
type XaiRuntimeModelCompat = {
compat?: unknown;
id?: unknown;
reasoning?: unknown;
thinkingLevelMap?: XaiThinkingLevelMap;
};
type XaiThinkingLevelMap = Partial<
Record<"off" | "minimal" | "low" | "medium" | "high" | "xhigh", string | null>
>;
const XAI_UNSUPPORTED_REASONING_EFFORTS = {
off: null,
minimal: null,
low: null,
medium: null,
high: null,
xhigh: null,
} satisfies NonNullable<XaiRuntimeModelCompat["thinkingLevelMap"]>;
const XAI_REASONING_EFFORTS = {
off: null,
minimal: "low",
low: "low",
medium: "medium",
high: "high",
xhigh: "high",
} satisfies NonNullable<XaiRuntimeModelCompat["thinkingLevelMap"]>;
const XAI_SUPPORTED_REASONING_EFFORTS = ["low", "medium", "high"] as const;
function isGrok43Model(id: string): boolean {
return id === "grok-latest" || id === "grok-4.3" || id.startsWith("grok-4.3-");
}
function normalizeXaiCompatModelId(id: unknown): string {
return typeof id === "string" ? id.trim().toLowerCase() : "";
}
function supportsConfigurableXaiReasoningEffort(model: XaiRuntimeModelCompat): boolean {
const id = normalizeXaiCompatModelId(model.id);
const isConfigurableModel = isGrok43Model(id) || isXaiFrontierModelId(id);
return model.reasoning === true && isConfigurableModel;
}
function resolveXaiReasoningEffortCompat(model: XaiRuntimeModelCompat): Record<string, unknown> {
if (supportsConfigurableXaiReasoningEffort(model)) {
const id = normalizeXaiCompatModelId(model.id);
return {
supportsReasoningEffort: true,
supportedReasoningEfforts: [
...(isGrok43Model(id) ? ["none"] : []),
...XAI_SUPPORTED_REASONING_EFFORTS,
...(isXaiGrok46ModelId(id) ? ["xhigh"] : []),
],
};
}
return { supportsReasoningEffort: false };
}
export function applyXaiRuntimeModelCompat<T extends XaiRuntimeModelCompat>(
model: T,
): T & { compat: Record<string, unknown>; thinkingLevelMap: XaiThinkingLevelMap } {
const withCompat = applyXaiModelCompat(model);
const supportsReasoningEffort = supportsConfigurableXaiReasoningEffort(withCompat);
const id = normalizeXaiCompatModelId(withCompat.id);
const existingCompat =
withCompat.compat && typeof withCompat.compat === "object"
? (withCompat.compat as Record<string, unknown>)
: {};
return {
...withCompat,
compat: {
...existingCompat,
...resolveXaiReasoningEffortCompat(withCompat),
},
thinkingLevelMap: {
...withCompat.thinkingLevelMap,
...(supportsReasoningEffort ? XAI_REASONING_EFFORTS : XAI_UNSUPPORTED_REASONING_EFFORTS),
...(supportsReasoningEffort && isGrok43Model(id) ? { off: "none" } : {}),
...(supportsReasoningEffort && isXaiGrok46ModelId(id) ? { xhigh: "xhigh" } : {}),
},
};
}