UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

81 lines (80 loc) • 3.97 kB
import { a as normalizeFastMode } from "./string-coerce-CCIiB4H7.mjs"; import { D as parseStrictPositiveInteger } from "./number-coercion-D6u-4YD8.mjs"; import { a as asOptionalRecord } from "./record-coerce-CVPuDqcc.mjs"; import { t as isBlockedObjectKey } from "./prototype-keys-CLGi5xDj.mjs"; import { o as resolveAgentEntry } from "./agent-scope-config-DmXgFGKP.mjs"; import { l as normalizeThinkLevel } from "./thinking.shared-jmDGV33r.mjs"; import { r as modelKey } from "./provider-registry-index-DhPtwFh_.mjs"; //#region src/agents/model-extra-params.ts const FAST_MODE_CUTOFF_MODEL_PARAM_KEYS = /* @__PURE__ */ new Set([ "fastAutoOnSeconds", "fastSeconds", "fast_auto_on_seconds", "fast_seconds" ]); function isAgentRuntimeModelParam(e, t) { if (e === "thinking") return t === false || t === "disabled" || t === "none" || typeof t === "string" && normalizeThinkLevel(t) !== void 0; if (e === "fastMode" || e === "fast_mode") return normalizeFastMode(t) !== void 0; return FAST_MODE_CUTOFF_MODEL_PARAM_KEYS.has(e) && typeof t === "number" && Number.isInteger(t) && t > 0; } function legacyModelKey(e, t) { const n = `${e.trim()}/${t.trim()}`; return n === modelKey(e, t) ? void 0 : n; } /** Resolves the config records merged into one model request. */ function resolveModelExtraParamSources(e) { const t = e.config?.agents?.defaults?.params; const n = e.config?.agents?.defaults?.models; const r = e.modelId ? modelKey(e.provider, e.modelId) : void 0; const i = e.modelId ? legacyModelKey(e.provider, e.modelId) : void 0; const paramsForModel = (e) => r ? e?.[r]?.params ?? (i ? e?.[i]?.params : void 0) : void 0; const a = paramsForModel(n); const o = e.agentId && e.config ? resolveAgentEntry(e.config, e.agentId) : void 0; return { defaultParams: t, modelParams: a, agentModelParams: paramsForModel(o?.models), agentParams: o?.params }; } /** Returns whether embedded OpenClaw would apply authored provider request parameters. */ function hasAuthoredProviderRequestParams(e, t) { const n = resolveModelExtraParamSources(e); const usesHostCompaction = (e, n) => t?.nativeContextManagement === true && (e === "responsesServerCompaction" && typeof n === "boolean" || e === "responsesCompactThreshold" && (typeof n === "number" && Number.isFinite(n) && n > 0 || typeof n === "string" && parseStrictPositiveInteger(n) !== void 0)); if ([n.defaultParams, n.agentParams].some((e) => Object.entries(e ?? {}).some(([e, t]) => !usesHostCompaction(e, t)))) return true; return [n.modelParams, n.agentModelParams].some((e) => Object.entries(e ?? {}).some(([e, t]) => !usesHostCompaction(e, t) && !isAgentRuntimeModelParam(e, t))); } function sanitizeExtraParamsRecord(e) { if (!e) return; return Object.fromEntries(Object.entries(e).filter(([e]) => !isBlockedObjectKey(e))); } /** Later sources win; each source's first own alias wins, including null and undefined. */ function resolveAliasedParamValue(e, t) { let n = void 0; for (const r of e) { if (!r) continue; for (const e of t) { if (!Object.hasOwn(r, e)) continue; n = r[e]; break; } } return n; } /** Explicit empty or invalid settings remain unset; only absent configuration uses the fallback. */ function resolveConfiguredCyberAccessProgram(e, t) { const { defaultParams: n, modelParams: r, agentModelParams: i, agentParams: a } = resolveModelExtraParamSources(e); const o = [ n, r, i, a ]; if (!o.some((e) => e && Object.hasOwn(e, "accessPrograms"))) return t; const s = asOptionalRecord(resolveAliasedParamValue(o, ["accessPrograms"])); if (!s || Object.keys(s).some((e) => e !== "cyber")) return; const c = s.cyber; return c === "standard" || c === "daybreak_blue" || c === "daybreak_red" ? c : void 0; } //#endregion export { resolveModelExtraParamSources as a, resolveConfiguredCyberAccessProgram as i, isAgentRuntimeModelParam as n, sanitizeExtraParamsRecord as o, resolveAliasedParamValue as r, hasAuthoredProviderRequestParams as t };