openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
222 lines (221 loc) • 5.32 kB
JavaScript
import { c as normalizeOptionalLowercaseString } from "./string-coerce-CCIiB4H7.mjs";
import { a as asOptionalRecord } from "./record-coerce-CVPuDqcc.mjs";
import "./string-coerce-runtime-BwAZZDf5.mjs";
import { l as modelCatalog, n as isXaiFrontierModelId, o as normalizeXaiModelId } from "./model-id-Cs3j89NC.mjs";
//#region extensions/xai/model-definitions.ts
const XAI_BASE_URL = modelCatalog.providers.xai.baseUrl;
const XAI_DEFAULT_IMAGE_MODEL = "grok-imagine-image";
const XAI_IMAGE_MODELS = [
"grok-imagine-image",
"grok-imagine-image-2.0",
"grok-imagine-image-quality"
];
const XAI_DEFAULT_CONTEXT_WINDOW = 1e6;
const XAI_DEFAULT_MAX_TOKENS = 64e3;
const XAI_DEFAULT_MODEL_ID = "grok-4.7";
/** Models outside the manifest carry no price until the manifest lists them. */
const XAI_UNKNOWN_MODEL_COST = {
input: 0,
output: 0,
cacheRead: 0,
cacheWrite: 0
};
function isXaiModelInput(e) {
return e === "text" || e === "image" || e === "video" || e === "audio";
}
function toXaiModelDefinition(e) {
return {
...e,
input: e.input.filter(isXaiModelInput)
};
}
const XAI_MODEL_CATALOG = modelCatalog.providers.xai.models.map(toXaiModelDefinition);
/** Curated pricing and supported-family capabilities share one lookup owner. */
function resolveXaiCatalogEntry(e) {
const t = normalizeXaiCatalogModelId(e);
const n = XAI_MODEL_CATALOG.find((e) => e.id.toLowerCase() === t);
if (n) return n;
if (t.includes("multi-agent")) return;
const r = t.startsWith("grok-3");
const i = isXaiFrontierModelId(t);
const a = t === "grok-latest" || i || t.startsWith("grok-4.3") || t.startsWith("grok-4.20") || t.startsWith("grok-4-1") || t.startsWith("grok-4-fast");
if (!r && !a && !t.startsWith("grok-4")) return;
const o = normalizeXaiModelId(e.trim());
return {
id: o,
name: o,
reasoning: r ? t.includes("mini") : !t.includes("non-reasoning"),
input: a ? ["text", "image"] : ["text"],
cost: XAI_UNKNOWN_MODEL_COST,
contextWindow: i ? 5e5 : XAI_DEFAULT_CONTEXT_WINDOW,
maxTokens: t.startsWith("grok-4.20") ? 3e4 : XAI_DEFAULT_MAX_TOKENS
};
}
function resolveXaiForwardCompatDefinition(e) {
const t = resolveXaiCatalogEntry(e);
if (t) return t;
const n = e.trim();
const r = normalizeOptionalLowercaseString(n) ?? "";
if (!r.startsWith("grok-") || r.includes("multi-agent")) return;
return {
id: n,
name: n,
reasoning: !r.includes("non-reasoning"),
input: ["text", "image"],
cost: XAI_UNKNOWN_MODEL_COST,
contextWindow: XAI_DEFAULT_CONTEXT_WINDOW,
maxTokens: XAI_DEFAULT_MAX_TOKENS
};
}
function buildXaiModelDefinition() {
const e = resolveXaiCatalogEntry(XAI_DEFAULT_MODEL_ID);
if (!e) throw new Error(`xai manifest omits the default model ${XAI_DEFAULT_MODEL_ID}`);
return e;
}
function buildXaiCatalogModels() {
return XAI_MODEL_CATALOG;
}
const LEGACY_XAI_BUILTIN_SIGNATURES = {
"grok-3": [
"Grok 3",
false,
"text",
131072,
8192,
3,
15,
.75,
0
],
"grok-3-fast": [
"Grok 3 Fast",
false,
"text",
131072,
8192,
5,
25,
1.25,
0
],
"grok-3-mini": [
"Grok 3 Mini",
true,
"text",
131072,
8192,
.3,
.5,
.075,
0
],
"grok-3-mini-fast": [
"Grok 3 Mini Fast",
true,
"text",
131072,
8192,
.6,
4,
.15,
0
],
"grok-4": [
"Grok 4",
true,
"text",
256e3,
64e3,
3,
15,
.75,
0
],
"grok-4-0709": [
"Grok 4 0709",
false,
"text",
256e3,
64e3,
3,
15,
.75,
0
],
"grok-4-fast": [
"Grok 4 Fast",
true,
"text,image",
2e6,
3e4,
.2,
.5,
.05,
0
],
"grok-4-fast-non-reasoning": [
"Grok 4 Fast (Non-Reasoning)",
false,
"text,image",
2e6,
3e4,
.2,
.5,
.05,
0
],
"grok-4-1-fast": [
"Grok 4.1 Fast",
true,
"text,image",
2e6,
3e4,
.2,
.5,
.05,
0
],
"grok-4-1-fast-non-reasoning": [
"Grok 4.1 Fast (Non-Reasoning)",
false,
"text,image",
2e6,
3e4,
.2,
.5,
.05,
0
]
};
const LEGACY_MODEL_KEYS = /* @__PURE__ */ new Set([
"id",
"name",
"reasoning",
"input",
"cost",
"contextWindow",
"maxTokens"
]);
const LEGACY_COST_KEYS = /* @__PURE__ */ new Set([
"input",
"output",
"cacheRead",
"cacheWrite"
]);
function normalizeXaiCatalogModelId(e) {
const t = normalizeOptionalLowercaseString(e) ?? "";
const n = t.startsWith("xai/") ? t.slice(4) : t;
return normalizeXaiModelId(n);
}
function isLegacyXaiBuiltinModel(e) {
const t = asOptionalRecord(e);
const n = normalizeOptionalLowercaseString(t?.id);
const r = n ? LEGACY_XAI_BUILTIN_SIGNATURES[n] : void 0;
const i = asOptionalRecord(t?.cost);
if (!t || !r || !i) return false;
if (Object.keys(t).some((e) => !LEGACY_MODEL_KEYS.has(e)) || Object.keys(i).some((e) => !LEGACY_COST_KEYS.has(e))) return false;
const [a, o, s, c, l, u, d, f, p] = r;
return t.name === a && t.reasoning === o && Array.isArray(t.input) && t.input.join(",") === s && t.contextWindow === c && t.maxTokens === l && i.input === u && i.output === d && i.cacheRead === f && i.cacheWrite === p;
}
//#endregion
export { XAI_DEFAULT_MODEL_ID as a, buildXaiCatalogModels as c, resolveXaiCatalogEntry as d, resolveXaiForwardCompatDefinition as f, XAI_DEFAULT_MAX_TOKENS as i, buildXaiModelDefinition as l, XAI_DEFAULT_CONTEXT_WINDOW as n, XAI_IMAGE_MODELS as o, XAI_DEFAULT_IMAGE_MODEL as r, XAI_UNKNOWN_MODEL_COST as s, XAI_BASE_URL as t, isLegacyXaiBuiltinModel as u };