Files
openclaw/extensions/xai/model-compat.ts
2026-05-31 03:04:25 -04:00

35 lines
983 B
TypeScript

import {
applyModelCompatPatch,
type ModelCompatConfig,
} from "openclaw/plugin-sdk/provider-model-shared";
export { normalizeXaiModelId as normalizeNativeXaiModelId } from "./model-id.js";
export const XAI_TOOL_SCHEMA_PROFILE = "xai";
export const HTML_ENTITY_TOOL_CALL_ARGUMENTS_ENCODING = "html-entities";
const XAI_UNSUPPORTED_SCHEMA_KEYWORDS = new Set([
"minLength",
"maxLength",
"minItems",
"maxItems",
"minContains",
"maxContains",
]);
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;
}