mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-22 03:54:03 +00:00
55 lines
1.5 KiB
TypeScript
55 lines
1.5 KiB
TypeScript
import {
|
|
applyModelCompatPatch,
|
|
type ModelCompatConfig,
|
|
} from "openclaw/plugin-sdk/provider-model-shared";
|
|
|
|
export const XAI_TOOL_SCHEMA_PROFILE = "xai";
|
|
export const HTML_ENTITY_TOOL_CALL_ARGUMENTS_ENCODING = "html-entities";
|
|
|
|
export const XAI_UNSUPPORTED_SCHEMA_KEYWORDS = new Set([
|
|
"minLength",
|
|
"maxLength",
|
|
"minItems",
|
|
"maxItems",
|
|
"minContains",
|
|
"maxContains",
|
|
]);
|
|
|
|
export function resolveXaiModelCompatPatch(): ModelCompatConfig {
|
|
return {
|
|
toolSchemaProfile: XAI_TOOL_SCHEMA_PROFILE,
|
|
unsupportedToolSchemaKeywords: Array.from(XAI_UNSUPPORTED_SCHEMA_KEYWORDS),
|
|
nativeWebSearchTool: true,
|
|
toolCallArgumentsEncoding: HTML_ENTITY_TOOL_CALL_ARGUMENTS_ENCODING,
|
|
};
|
|
}
|
|
|
|
export function applyXaiModelCompat<T extends { compat?: unknown }>(model: T): T {
|
|
return applyModelCompatPatch(
|
|
model as T & { compat?: ModelCompatConfig },
|
|
resolveXaiModelCompatPatch(),
|
|
) as T;
|
|
}
|
|
|
|
export function normalizeNativeXaiModelId(id: string): string {
|
|
if (id === "grok-4-fast-reasoning") {
|
|
return "grok-4-fast";
|
|
}
|
|
if (id === "grok-4-1-fast-reasoning") {
|
|
return "grok-4-1-fast";
|
|
}
|
|
if (id === "grok-4.20-experimental-beta-0304-reasoning") {
|
|
return "grok-4.20-beta-latest-reasoning";
|
|
}
|
|
if (id === "grok-4.20-experimental-beta-0304-non-reasoning") {
|
|
return "grok-4.20-beta-latest-non-reasoning";
|
|
}
|
|
if (id === "grok-4.20-reasoning") {
|
|
return "grok-4.20-beta-latest-reasoning";
|
|
}
|
|
if (id === "grok-4.20-non-reasoning") {
|
|
return "grok-4.20-beta-latest-non-reasoning";
|
|
}
|
|
return id;
|
|
}
|