UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

101 lines (100 loc) • 4.35 kB
import { _ as resolvePrimaryStringValue, l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs"; import { d as asPositiveFiniteNumber } from "./number-coercion-D6u-4YD8.mjs"; import { l as isRecord } from "./record-coerce-CVPuDqcc.mjs"; import { i as parseModelCatalogRef } from "./model-catalog-refs-Bk2MNoCv.mjs"; import { i as normalizeTogetherModelId, n as normalizeGooglePreviewModelId } from "./provider-model-id-normalize-DpMwcMeB.mjs"; //#region src/config/model-input.ts /** Returns the primary model ref from either string or object-style agent model config. */ function resolveAgentModelPrimaryValue(e) { return resolvePrimaryStringValue(e); } /** Returns configured fallback model refs, preserving their configured order. */ function resolveAgentModelFallbackValues(e) { if (!e || typeof e !== "object") return []; return Array.isArray(e.fallbacks) ? e.fallbacks : []; } /** An explicit primary starts its own chain; an omitted primary inherits unless fallbacks are set. */ function resolveSelectedModelFallbacksOverride(e) { if (!e) return; if (typeof e === "string") return resolvePrimaryStringValue(e) ? [] : void 0; if (!Object.hasOwn(e, "fallbacks")) return Object.hasOwn(e, "primary") && resolvePrimaryStringValue(e) ? [] : void 0; return Array.isArray(e.fallbacks) ? e.fallbacks : void 0; } /** Returns a positive finite tool timeout rounded down to whole milliseconds. */ function resolveAgentModelTimeoutMsValue(e) { if (!e || typeof e !== "object") return; const t = asPositiveFiniteNumber(e.timeoutMs); return t === void 0 ? void 0 : Math.floor(t); } /** Converts legacy string model config into the object shape used by model patch helpers. */ function toAgentModelListLike(e) { if (typeof e === "string") { const t = normalizeOptionalString(e); return t ? { primary: t } : void 0; } if (!e || typeof e !== "object") return; return e; } const GOOGLE_PROVIDER_IDS = /* @__PURE__ */ new Set([ "google", "google-gemini-cli", "google-vertex" ]); /** Applies existing Google/Together model fixes while preserving literal catalog namespaces. */ function normalizeProviderCatalogModelIdForConfig(e, t) { if (GOOGLE_PROVIDER_IDS.has(e) || t.startsWith("google/")) return normalizeGooglePreviewModelId(t); return e === "together" ? normalizeTogetherModelId(t) : t; } /** Canonicalizes provider/model refs before they are persisted to config. */ function normalizeAgentModelRefForConfig(e) { const t = e.trim(); const n = parseModelCatalogRef(t); if (!n) return t; const { provider: r, modelId: i } = n; return `${r}/${normalizeProviderCatalogModelIdForConfig(r, i)}`; } /** Normalizes primary/fallback refs without replacing unchanged config values. */ function normalizeAgentModelSelectionForConfig(e) { if (typeof e === "string") return normalizeAgentModelRefForConfig(e); if (!isRecord(e)) return e; let t = e; const assign = (e, n) => { if (n !== t[e]) t = { ...t, [e]: n }; }; if (typeof e.primary === "string") assign("primary", normalizeAgentModelRefForConfig(e.primary)); if (Array.isArray(e.fallbacks)) { const t = e.fallbacks; const n = t.map((e) => typeof e === "string" ? normalizeAgentModelRefForConfig(e) : e); if (n.some((e, n) => e !== t[n])) assign("fallbacks", n); } return t; } function mergeAgentModelEntryForConfig(e, t) { if (!isRecord(e) || !isRecord(t)) return t; const n = isRecord(e.params) ? e.params : void 0; const r = isRecord(t.params) ? t.params : void 0; return { ...e, ...t, ...n || r ? { params: { ...n, ...r } } : void 0 }; } /** Normalizes model map keys and merges entries that collapse to the same canonical ref. */ function normalizeAgentModelMapForConfig(e) { let t = false; const n = {}; for (const [r, i] of Object.entries(e)) { const e = normalizeAgentModelRefForConfig(r); if (e !== r || Object.hasOwn(n, e)) t = true; n[e] = mergeAgentModelEntryForConfig(n[e], i); } return t ? n : e; } //#endregion export { normalizeProviderCatalogModelIdForConfig as a, resolveAgentModelTimeoutMsValue as c, normalizeAgentModelSelectionForConfig as i, resolveSelectedModelFallbacksOverride as l, normalizeAgentModelMapForConfig as n, resolveAgentModelFallbackValues as o, normalizeAgentModelRefForConfig as r, resolveAgentModelPrimaryValue as s, mergeAgentModelEntryForConfig as t, toAgentModelListLike as u };