openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
245 lines (244 loc) • 8.66 kB
JavaScript
import { l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs";
import { C as parseFiniteNumber } from "./number-coercion-D6u-4YD8.mjs";
import { n as parseBooleanValue } from "./boolean-2vRuVafy.mjs";
import { l as isRecord } from "./record-coerce-CVPuDqcc.mjs";
import { f as normalizeResolvedSecretInputString } from "./types.secrets-BmNLLnHp.mjs";
import "./string-coerce-runtime-BwAZZDf5.mjs";
import "./secret-input-CpgOwFAi.mjs";
import { o as XAI_IMAGE_MODELS, r as XAI_DEFAULT_IMAGE_MODEL } from "./model-definitions-C5KvjcKR.mjs";
import { _ as normalizeXaiRealtimeProviderConfig, i as XAI_REALTIME_DEFAULT_MODEL, m as XAI_REALTIME_VOICES } from "./realtime-voice-config-t6n6IiqY.mjs";
//#region extensions/xai/capability-provider-metadata-factory.ts
const XAI_IMAGE_DEFAULT_TIMEOUT_MS = 6e5;
const XAI_SUPPORTED_IMAGE_ASPECT_RATIOS = [
"1:1",
"16:9",
"9:16",
"4:3",
"3:4",
"3:2",
"2:3",
"2:1",
"1:2",
"19.5:9",
"9:19.5",
"20:9",
"9:20"
];
function createXaiImageGenerationProviderMetadata() {
return {
id: "xai",
label: "xAI",
defaultModel: XAI_DEFAULT_IMAGE_MODEL,
defaultTimeoutMs: XAI_IMAGE_DEFAULT_TIMEOUT_MS,
models: [...XAI_IMAGE_MODELS],
capabilities: {
generate: {
maxCount: 4,
supportsAspectRatio: true,
supportsResolution: true,
supportsSize: false
},
edit: {
enabled: true,
maxCount: 4,
maxInputImages: 3,
supportsAspectRatio: true,
supportsResolution: true,
supportsSize: false
},
geometry: {
aspectRatios: [...XAI_SUPPORTED_IMAGE_ASPECT_RATIOS],
resolutions: ["1K", "2K"]
}
}
};
}
function createXaiMediaUnderstandingProviderMetadata() {
return {
id: "xai",
capabilities: ["audio"],
autoPriority: { audio: 25 }
};
}
const DEFAULT_XAI_VIDEO_BASE_URL = "https://api.x.ai/v1";
const DEFAULT_XAI_VIDEO_MODEL = "grok-imagine-video";
const XAI_VIDEO_15_MODEL = "grok-imagine-video-1.5";
const XAI_VIDEO_DEFAULT_TIMEOUT_MS = 6e5;
const XAI_VIDEO_ASPECT_RATIOS = /* @__PURE__ */ new Set([
"1:1",
"16:9",
"9:16",
"4:3",
"3:4",
"3:2",
"2:3"
]);
function createXaiVideoGenerationMode(e) {
return {
maxDurationSeconds: 15,
aspectRatios: [...XAI_VIDEO_ASPECT_RATIOS],
resolutions: e,
supportsAspectRatio: true,
supportsResolution: true
};
}
const XAI_VIDEO_15_CAPABILITIES = {
imageToVideo: {
enabled: true,
maxVideos: 1,
maxInputImages: 1,
...createXaiVideoGenerationMode([
"480P",
"720P",
"1080P"
])
},
videoToVideo: { enabled: false }
};
const XAI_VIDEO_15_MODEL_IDS = /* @__PURE__ */ new Set([
XAI_VIDEO_15_MODEL,
"grok-imagine-video-1.5-preview",
"grok-imagine-video-1.5-2026-05-30"
]);
function isXaiVideo15Model(e) {
const t = normalizeOptionalString(e);
return t ? XAI_VIDEO_15_MODEL_IDS.has(t) : false;
}
function createXaiVideoGenerationProviderMetadata(e) {
return {
id: "xai",
label: "xAI",
defaultModel: DEFAULT_XAI_VIDEO_MODEL,
defaultTimeoutMs: XAI_VIDEO_DEFAULT_TIMEOUT_MS,
models: [DEFAULT_XAI_VIDEO_MODEL, XAI_VIDEO_15_MODEL],
catalogByModel: { [XAI_VIDEO_15_MODEL]: {
capabilities: XAI_VIDEO_15_CAPABILITIES,
modes: ["imageToVideo"]
} },
isConfiguredAsync: (t) => e.isProviderApiKeyConfiguredAsync({
provider: "xai",
...t
}),
capabilities: {
generate: {
maxVideos: 1,
...createXaiVideoGenerationMode(["480P", "720P"])
},
imageToVideo: {
enabled: true,
maxVideos: 1,
maxInputImages: 7,
...createXaiVideoGenerationMode(["480P", "720P"])
},
videoToVideo: {
enabled: true,
maxVideos: 1,
maxInputVideos: 1,
maxDurationSeconds: 10,
supportsAspectRatio: false,
supportsResolution: false
}
},
resolveModelCapabilities: ({ model: e }) => isXaiVideo15Model(e) ? XAI_VIDEO_15_CAPABILITIES : void 0
};
}
function normalizeRealtimeTranscriptionEncoding(e) {
const t = normalizeOptionalString(e)?.toLowerCase();
if (!t) return;
if (t === "ulaw" || t === "g711_ulaw" || t === "g711-mulaw") return "mulaw";
if (t === "g711_alaw" || t === "g711-alaw") return "alaw";
if (t === "pcm" || t === "mulaw" || t === "alaw") return t;
throw new Error(`Invalid xAI realtime transcription encoding: ${t}`);
}
function normalizeXaiRealtimeTranscriptionProviderConfig(e) {
const t = isRecord(e) ? e : void 0;
const n = (isRecord(t?.providers) ? t.providers : void 0)?.xai ?? t?.xai ?? t;
const r = isRecord(n) ? n : {};
return {
apiKey: normalizeResolvedSecretInputString({
value: r.apiKey,
path: "plugins.entries.voice-call.config.streaming.providers.xai.apiKey"
}),
baseUrl: normalizeOptionalString(r.baseUrl),
sampleRate: parseFiniteNumber(r.sampleRate ?? r.sample_rate),
encoding: normalizeRealtimeTranscriptionEncoding(r.encoding),
interimResults: parseBooleanValue(r.interimResults ?? r.interim_results),
endpointingMs: parseFiniteNumber(r.endpointingMs ?? r.endpointing ?? r.silenceDurationMs),
language: normalizeOptionalString(r.language)
};
}
function createXaiRealtimeTranscriptionProviderMetadata(e) {
return {
id: "xai",
label: "xAI Realtime Transcription",
aliases: ["xai-realtime", "grok-stt-streaming"],
autoSelectOrder: 25,
resolveConfig: ({ rawConfig: e }) => normalizeXaiRealtimeTranscriptionProviderConfig(e),
isConfigured: ({ providerConfig: t, cfg: n }) => Boolean(normalizeXaiRealtimeTranscriptionProviderConfig(t).apiKey ?? normalizeOptionalString(process.env.XAI_API_KEY)) || e.isProviderAuthProfileConfigured({
provider: "xai",
cfg: n
}),
isConfiguredAsync: async ({ providerConfig: t, cfg: n }) => Boolean(normalizeXaiRealtimeTranscriptionProviderConfig(t).apiKey ?? normalizeOptionalString(process.env.XAI_API_KEY)) || await e.isProviderAuthProfileConfiguredAsync({
provider: "xai",
cfg: n
})
};
}
const XAI_REALTIME_AUDIO_FORMAT_G711_ULAW_8KHZ = {
encoding: "g711_ulaw",
sampleRateHz: 8e3,
channels: 1
};
const XAI_REALTIME_AUDIO_FORMAT_PCM16_24KHZ = {
encoding: "pcm16",
sampleRateHz: 24e3,
channels: 1
};
function createXaiRealtimeVoiceProviderMetadata(e) {
return {
id: "xai",
label: "xAI Grok Voice",
aliases: ["xai-realtime-voice", "grok-voice"],
defaultModel: XAI_REALTIME_DEFAULT_MODEL,
voices: XAI_REALTIME_VOICES,
autoSelectOrder: 25,
capabilities: {
transports: ["gateway-relay"],
inputAudioFormats: [XAI_REALTIME_AUDIO_FORMAT_G711_ULAW_8KHZ, XAI_REALTIME_AUDIO_FORMAT_PCM16_24KHZ],
outputAudioFormats: [XAI_REALTIME_AUDIO_FORMAT_G711_ULAW_8KHZ, XAI_REALTIME_AUDIO_FORMAT_PCM16_24KHZ],
supportsBargeIn: true,
handlesInputAudioBargeIn: true,
supportsToolCalls: true,
supportsSessionResumption: true
},
resolveConfig: ({ rawConfig: e }) => normalizeXaiRealtimeProviderConfig(e),
isConfigured: ({ providerConfig: t, cfg: n, agentId: r }) => {
const i = normalizeXaiRealtimeProviderConfig(t).apiKey;
const { isProviderAuthProfileConfigured: a, resolveAgentDir: o } = e;
if (normalizeOptionalString(i) || normalizeOptionalString(process.env.XAI_API_KEY)) return true;
return a({
provider: "xai",
cfg: n,
...n && r ? { agentDir: o(n, r) } : {}
});
},
resolveConfigAsync: async ({ rawConfig: e }) => normalizeXaiRealtimeProviderConfig(e),
isConfiguredAsync: ({ providerConfig: t, cfg: n, agentId: r }) => {
const i = normalizeXaiRealtimeProviderConfig(t).apiKey;
const { isProviderAuthProfileConfiguredAsync: a, resolveAgentDir: o } = e;
if (normalizeOptionalString(i) || normalizeOptionalString(process.env.XAI_API_KEY)) return Promise.resolve(true);
return a({
provider: "xai",
cfg: n,
...n && r ? { agentDir: o(n, r) } : {}
});
}
};
}
function assertXaiRealtimeVoiceRequestSupported(e) {
const t = normalizeXaiRealtimeProviderConfig(e.providerConfig);
if (e.autoRespondToAudio === false) throw new Error("xAI realtime voice requires automatic server-VAD responses; use consultRouting: \"provider-direct\"");
if ((e.interruptResponseOnInputAudio ?? t.interruptResponseOnInputAudio) === false) throw new Error("xAI realtime voice requires automatic server-VAD interruption handling");
}
//#endregion
export { XAI_VIDEO_ASPECT_RATIOS as a, createXaiImageGenerationProviderMetadata as c, createXaiRealtimeVoiceProviderMetadata as d, createXaiVideoGenerationProviderMetadata as f, XAI_SUPPORTED_IMAGE_ASPECT_RATIOS as i, createXaiMediaUnderstandingProviderMetadata as l, normalizeXaiRealtimeTranscriptionProviderConfig as m, DEFAULT_XAI_VIDEO_MODEL as n, XAI_VIDEO_DEFAULT_TIMEOUT_MS as o, isXaiVideo15Model as p, XAI_IMAGE_DEFAULT_TIMEOUT_MS as r, assertXaiRealtimeVoiceRequestSupported as s, DEFAULT_XAI_VIDEO_BASE_URL as t, createXaiRealtimeTranscriptionProviderMetadata as u };