UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

235 lines (234 loc) • 9.44 kB
import { C as OPENAI_GPT_54_NANO_MODEL_ID, D as OPENAI_GPT_56_MODEL_ID, E as OPENAI_GPT_55_PRO_MODEL_ID, M as OPENAI_GPT_6_MODEL_IDS, R as resolveOpenAICodexReasoningEfforts, S as OPENAI_GPT_54_MODEL_ID, T as OPENAI_GPT_55_MODEL_ID, a as isOpenAIApiBaseUrl, g as OPENAI_DAYBREAK_MODEL_IDS, i as classifyOpenAIBaseUrl, j as OPENAI_GPT_6_ASTRA_MODEL_ID, t as modelCatalog, w as OPENAI_GPT_54_PRO_MODEL_ID, x as OPENAI_GPT_54_MINI_MODEL_ID, y as OPENAI_GPT_53_CODEX_SPARK_MODEL_ID } from "./openclaw.plugin-DQsQ0kf1.mjs"; import { normalizeModelCatalog, supportsOpenAIResponsesFastMode } from "openclaw/plugin-sdk/provider-model-metadata"; import { normalizeLowercaseStringOrEmpty, normalizeOptionalLowercaseString, normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime"; //#region extensions/openai/realtime-quicksilver.ts const OPENAI_GPT_LIVE_MODEL_PREFIX = "gpt-live"; const OPENAI_GPT_LIVE_MODELS = ["gpt-live-1", "gpt-live-1-codex"]; const OPENAI_GPT_LIVE_API_VOICES = [ "alloy", "ash", "ballad", "beacon", "bossa", "cedar", "cinder", "coral", "delta", "echo", "gleam", "marin", "meridian", "quartz", "ripple", "sage", "shimmer", "stone", "tempo", "verse", "vesper", "willow" ]; const OPENAI_GPT_LIVE_VOICES = [ "arbor", "breeze", "cove", "ember", "juniper", "maple", "sol", "spruce", "vale" ]; const OPENAI_GPT_LIVE_UNLISTED_VOICES = ["marin", "cedar"]; function isOpenAIGptLiveApiModel(e) { return e?.trim().toLowerCase() === "gpt-live-1"; } function isOpenAIGptLiveSubscriptionModel(e) { return e?.trim().toLowerCase() === "gpt-live-1-codex"; } function isSupportedOpenAIGptLiveModel(e) { return isOpenAIGptLiveApiModel(e) || isOpenAIGptLiveSubscriptionModel(e); } function resolveOpenAIQuicksilverVoice(e, t) { const n = resolveOpenAIQuicksilverVoices(e); const r = isOpenAIGptLiveSubscriptionModel(e) ? "cove" : "marin"; const i = normalizeOptionalLowercaseString(t); return n.find((e) => e === i) ?? r; } function resolveOpenAIQuicksilverVoices(e) { if (isOpenAIGptLiveApiModel(e)) return OPENAI_GPT_LIVE_API_VOICES; return isOpenAIGptLiveSubscriptionModel(e) ? OPENAI_GPT_LIVE_VOICES : OPENAI_GPT_LIVE_UNLISTED_VOICES; } function isOpenAIGptLiveModel(e) { if (!e) return false; const t = e.trim().toLowerCase(); return t === "gpt-live" || t.startsWith(`${"gpt-live"}-`); } const OPENAI_QUICKSILVER_CAPABILITIES = { transports: ["webrtc", "gateway-relay"], handlesAgentConsult: true, supportsBargeIn: false, handlesInputAudioBargeIn: true, supportsActivationNameGating: false, supportsToolCalls: false, supportsVideoFrames: false }; function resolveOpenAIQuicksilverVoiceCapabilities(e) { return { voices: resolveOpenAIQuicksilverVoices(e), voiceSelectionPolicy: "allowlist-default" }; } //#endregion //#region extensions/openai/service-tier-policy.ts /** Alias capabilities are independent of the snapshot behind each Daybreak name. */ function resolveOpenAIModelServiceTiers(e) { if (e.api !== "openai-responses" || classifyOpenAIBaseUrl(e.baseUrl) !== "platform") return; const [t, n] = OPENAI_DAYBREAK_MODEL_IDS; return e.modelId === t ? ["default", "priority"] : e.modelId === n ? ["default"] : void 0; } //#endregion //#region extensions/openai/thinking-policy.ts const OPENAI_THINKING_BASE_LEVELS = [ { id: "off" }, { id: "minimal" }, { id: "low" }, { id: "medium" }, { id: "high" } ]; const OPENAI_THINKING_LEVEL_ORDER = [ "off", "minimal", "low", "medium", "high", "xhigh", "max", "ultra" ]; const OPENAI_UNIFIED_XHIGH_MODEL_IDS = [ OPENAI_GPT_56_MODEL_ID, OPENAI_GPT_55_MODEL_ID, OPENAI_GPT_55_PRO_MODEL_ID, OPENAI_GPT_54_MODEL_ID, OPENAI_GPT_54_PRO_MODEL_ID, OPENAI_GPT_53_CODEX_SPARK_MODEL_ID, OPENAI_GPT_54_MINI_MODEL_ID, OPENAI_GPT_54_NANO_MODEL_ID ]; function normalizeCodexReasoningEffort(e) { const t = normalizeLowercaseStringOrEmpty(e); if (t === "none") return "off"; return OPENAI_THINKING_LEVEL_ORDER.find((e) => e === t); } function buildCodexLevels(e) { const t = /* @__PURE__ */ new Set(); for (const n of e) { const e = normalizeCodexReasoningEffort(n); if (e) t.add(e); } return OPENAI_THINKING_LEVEL_ORDER.filter((e) => t.has(e)).map((e) => ({ id: e })); } function resolveUnifiedOpenAIThinkingProfile(e, t, n, r, i) { const a = normalizeLowercaseStringOrEmpty(e); const o = normalizeLowercaseStringOrEmpty(t ?? ""); const s = n?.supportedReasoningEfforts?.map(normalizeLowercaseStringOrEmpty); if (n?.supportsReasoningEffort === false || s?.length === 0) return { levels: r === "openai-completions" && (!o || o === "auto" || o === "openclaw") && [ "qwen", "qwen-chat-template", "zai", "deepseek", "together" ].includes(n?.thinkingFormat ?? "") ? OPENAI_THINKING_BASE_LEVELS : [] }; const c = i?.max !== null; const l = resolveOpenAICodexReasoningEfforts(a, void 0); const u = modelCatalog.providers.openai.models.find((e) => e.id === a)?.compat?.supportedReasoningEfforts; if (OPENAI_GPT_6_MODEL_IDS.some((e) => e === a) || (o !== "codex" || l === void 0) && (s ?? u) !== void 0) { const e = s ?? (o === "codex" ? (u ?? []).filter((e) => e !== "none") : u ?? []); const t = [ "openclaw", "codex", "auto" ].includes(o) && e.includes("max") && (o === "codex" ? a === "gpt-6-astra" || e.includes("ultra") : c); const n = e.includes("medium") ? "medium" : e.includes("low") ? "low" : void 0; return { levels: buildCodexLevels(t ? [...e, "ultra"] : e), ...n ? { defaultLevel: n } : {} }; } const d = r === void 0 || r === "openai-chatgpt-responses" ? resolveOpenAICodexReasoningEfforts(a, s) : void 0; const f = l !== void 0; const p = (d ?? l)?.includes("max"); const m = a.startsWith("gpt-5.6") && (o !== "codex" || p); const h = (d ?? l)?.includes("ultra"); const g = OPENAI_UNIFIED_XHIGH_MODEL_IDS.some((e) => a.startsWith(e)); const _ = (a === "gpt-5.6" || f) && ((o === "openclaw" || o === "auto") && (c || s?.includes("ultra")) || o === "codex" && h); const v = o === "codex" && n?.supportedReasoningEfforts === void 0 && (r === void 0 || r === "openai-chatgpt-responses") && !g && !a.startsWith("gpt-5.6"); const y = f ? "medium" : void 0; const b = [ ...OPENAI_THINKING_BASE_LEVELS, ...g ? [{ id: "xhigh" }] : [], ...m ? [{ id: "max" }] : [], ..._ ? [{ id: "ultra" }] : [], ...v ? [{ id: "xhigh" }, { id: "max" }] : [] ]; const x = o === "codex" && d !== void 0 ? buildCodexLevels(d) : b; return { levels: x, ...y && x.some((e) => e.id === y) ? { defaultLevel: y } : {} }; } //#endregion //#region extensions/openai/native-web-search-policy.ts /** Shared by catalog selection and payload construction before any provider request. */ function resolveNativeWebSearch(e) { const t = e.config?.tools?.web?.search?.provider?.trim().toLowerCase(); return e.config?.tools?.web?.search?.enabled !== false && (!t || t === "auto" || t === "openai") && e.api === "openai-responses" && e.provider.trim().toLowerCase() === "openai" && (!e.baseUrl || isOpenAIApiBaseUrl(e.baseUrl)); } //#endregion //#region extensions/openai/provider-policy-api.ts function resolveServiceTiers(e) { return e.runtimeId === "openclaw" ? resolveOpenAIModelServiceTiers(e) : void 0; } function resolveFastModeSupport(e) { if (!e.api || !e.baseUrl || e.runtimeId !== "openclaw") return; return (resolveOpenAIModelServiceTiers(e)?.includes("priority") ?? true) && supportsOpenAIResponsesFastMode(e); } const OPENAI_PROVIDER_ID = "openai"; const OPENAI_MODEL_CATALOG = normalizeModelCatalog(modelCatalog, { ownedProviders: /* @__PURE__ */ new Set([OPENAI_PROVIDER_ID]) }); /** Resolves authored OpenAI provider config without activating the runtime plugin. */ function resolveAuthoredOpenAIProviderConfig(e) { if (e.provider.trim().toLowerCase() !== OPENAI_PROVIDER_ID) return; const t = Object.entries(e.config?.models?.providers ?? {}); const n = e.provider.trim(); const r = t.find(([e]) => e.trim() === n)?.[0].trim() ?? t.find(([e]) => e.trim().toLowerCase() === OPENAI_PROVIDER_ID)?.[0].trim(); let i; for (const [e, n] of t) { if (e.trim() !== r || !n) continue; i = i ? { ...i, ...n, models: n.models ?? i.models } : n; } return i; } function projectRealtimeVoicePublicProjection(e) { const t = normalizeOptionalString(e.config.model) ?? e.providerConfig.model; const n = typeof t === "string" ? t : void 0; if (!isOpenAIGptLiveModel(n)) return { config: e.config }; if (isSupportedOpenAIGptLiveModel(n)) return { config: e.config, clientHints: { gatewayRelaySupported: e.config.consultRouting !== "force-agent-consult" && !normalizeOptionalString(e.providerConfig.baseUrl) && !normalizeOptionalString(e.providerConfig.azureEndpoint) && !normalizeOptionalString(e.providerConfig.azureDeployment) } }; const { model: r, ...i } = e.config; return { config: i, clientHints: { modelSource: "gateway", gatewayRelaySupported: false } }; } //#endregion export { resolveNativeWebSearch as a, OPENAI_GPT_LIVE_MODELS as c, isOpenAIGptLiveApiModel as d, isOpenAIGptLiveModel as f, resolveOpenAIQuicksilverVoiceCapabilities as h, resolveServiceTiers as i, OPENAI_GPT_LIVE_MODEL_PREFIX as l, resolveOpenAIQuicksilverVoice as m, resolveAuthoredOpenAIProviderConfig as n, resolveUnifiedOpenAIThinkingProfile as o, isOpenAIGptLiveSubscriptionModel as p, resolveFastModeSupport as r, resolveOpenAIModelServiceTiers as s, projectRealtimeVoicePublicProjection as t, OPENAI_QUICKSILVER_CAPABILITIES as u };