UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

168 lines (167 loc) • 7.39 kB
import { l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs"; import { D as parseStrictPositiveInteger, P as resolveIntegerOption } from "./number-coercion-D6u-4YD8.mjs"; import { a as asOptionalRecord } from "./record-coerce-CVPuDqcc.mjs"; import { b as uniqueStrings, f as normalizeStringEntries, m as normalizeTrimmedStringList } from "./string-normalization-DLmfYZXI.mjs"; import { r as isPathInside } from "./path-guards-TIjxtj6H.mjs"; import "./file-access-runtime-BD2Fjfbw.mjs"; import "./string-coerce-runtime-BwAZZDf5.mjs"; import "./number-runtime-W4chuk8B.mjs"; import { C as DEFAULT_RECENT_ASSISTANT_CHARS, D as DEFAULT_SETUP_GRACE_TIMEOUT_MS, E as DEFAULT_RECENT_USER_TURNS, F as MAX_ACTIVE_MEMORY_TOOLS_ALLOW, L as MAX_SETUP_GRACE_TIMEOUT_MS, N as LANCEDB_ACTIVE_MEMORY_TOOLS_ALLOW, O as DEFAULT_TIMEOUT_MS, R as MAX_TIMEOUT_MS, S as DEFAULT_QUERY_MODE, T as DEFAULT_RECENT_USER_CHARS, _ as DEFAULT_CLI_RUNTIME_RECALL_TIMEOUT_MS, b as DEFAULT_MIN_TIMEOUT_MS, c as ACTIVE_MEMORY_RESERVED_TOOLS_ALLOW, d as DEFAULT_ACTIVE_MEMORY_MODE, f as DEFAULT_ACTIVE_MEMORY_TOOLS_ALLOW, g as DEFAULT_CIRCUIT_BREAKER_MAX_TIMEOUTS, h as DEFAULT_CIRCUIT_BREAKER_COOLDOWN_MS, k as DEFAULT_TRANSCRIPT_DIR, m as DEFAULT_CACHE_TTL_MS, w as DEFAULT_RECENT_ASSISTANT_TURNS, y as DEFAULT_MAX_SUMMARY_CHARS } from "./types-DgEaE0BK.mjs"; import path from "node:path"; //#region extensions/active-memory/config.ts function parseOptionalPositiveInt(e, t) { const n = typeof e === "number" ? e : typeof e === "string" ? parseStrictPositiveInteger(e) : NaN; return n !== void 0 && Number.isFinite(n) && n > 0 ? n : t; } function resolveChoice(e, t, n) { return t.find((t) => t === e) ?? n; } function normalizeTranscriptDir(e) { const t = normalizeOptionalString(e); if (!t) return DEFAULT_TRANSCRIPT_DIR; const n = t.replace(/\\/g, "/").split("/").map((e) => e.trim()).filter((e) => e.length > 0 && e !== "." && e !== ".."); return n.length > 0 ? path.join(...n) : DEFAULT_TRANSCRIPT_DIR; } function normalizeIdentifierList(e) { return uniqueStrings(normalizeTrimmedStringList(e).map((e) => e.toLowerCase())); } function normalizeConfiguredToolsAllow(e) { if (!Array.isArray(e)) return; const t = normalizeIdentifierList(e).filter((e) => !e.startsWith("group:") && !ACTIVE_MEMORY_RESERVED_TOOLS_ALLOW.has(e)).slice(0, 32); return t.length > 0 ? t : void 0; } function resolveDefaultToolsAllow(e, t) { const n = normalizeIdentifierList(t); if (n.length > 0) return n; return e?.plugins?.slots?.memory === "memory-lancedb" ? [...LANCEDB_ACTIVE_MEMORY_TOOLS_ALLOW] : [...DEFAULT_ACTIVE_MEMORY_TOOLS_ALLOW]; } function hasDeprecatedModelFallbackPolicy(e) { const t = asOptionalRecord(e); return t ? Object.hasOwn(t, "modelFallbackPolicy") : false; } function resolveSafeTranscriptDir(e, t) { const n = t.trim(); if (!n || n.includes(":") || path.isAbsolute(n)) return path.resolve(e, DEFAULT_TRANSCRIPT_DIR); const r = path.resolve(e); const i = path.resolve(r, n); if (!isPathInside(r, i)) return path.resolve(r, DEFAULT_TRANSCRIPT_DIR); return i; } function resolvePersistentTranscriptBaseDir(e, t) { return path.join(e.runtime.state.resolveStateDir(), "plugins", "active-memory", "transcripts", "agents", encodeURIComponent(t.trim()) || "unknown-agent"); } function isMissingRegisteredMemoryToolsError(e, t = DEFAULT_ACTIVE_MEMORY_TOOLS_ALLOW) { if (!(e instanceof Error)) return false; const n = e.message.trim(); if (!n.startsWith("No callable tools remain after resolving explicit tool allowlist (") || !n.endsWith("); no registered tools matched. Fix the allowlist or enable the plugin that registers the requested tool.")) return false; const r = n.slice(66, -105); return normalizeStringEntries(r.split(";")).includes(`runtime toolsAllow: ${t.join(", ")}`); } function normalizePluginConfig(e, t, n) { const r = e && typeof e === "object" ? e : {}; const i = Array.isArray(r.allowedChatTypes) ? r.allowedChatTypes.filter((e) => e === "direct" || e === "group" || e === "channel" || e === "explicit") : []; return { enabled: r.enabled !== false, mode: resolveChoice(r.mode, [ "always", "off", "escalate" ], DEFAULT_ACTIVE_MEMORY_MODE), agents: Array.isArray(r.agents) ? normalizeStringEntries(r.agents) : [], model: normalizeOptionalString(r.model), modelFallback: normalizeOptionalString(r.modelFallback), allowedChatTypes: i.length > 0 ? i : ["direct"], allowedChatIds: normalizeIdentifierList(r.allowedChatIds), deniedChatIds: normalizeIdentifierList(r.deniedChatIds), thinking: resolveChoice(r.thinking, [ "off", "minimal", "low", "medium", "high", "xhigh", "adaptive", "max" ], "off"), fastMode: normalizeActiveMemoryFastMode(r.fastMode), promptStyle: resolveChoice(r.promptStyle, [ "balanced", "strict", "contextual", "recall-heavy", "precision-heavy", "preference-only" ], r.queryMode === "message" ? "strict" : r.queryMode === "full" ? "contextual" : "balanced"), toolsAllow: normalizeConfiguredToolsAllow(r.toolsAllow) ?? resolveDefaultToolsAllow(t, n), promptOverride: normalizeOptionalString(r.promptOverride), promptAppend: normalizeOptionalString(r.promptAppend), timeoutMs: resolveIntegerOption(parseOptionalPositiveInt(r.timeoutMs, DEFAULT_TIMEOUT_MS), DEFAULT_TIMEOUT_MS, { min: 250, max: MAX_TIMEOUT_MS }), timeoutMsIsDefault: r.timeoutMs === void 0 || r.timeoutMs === null, setupGraceTimeoutMs: resolveIntegerOption(r.setupGraceTimeoutMs, 0, { min: 0, max: MAX_SETUP_GRACE_TIMEOUT_MS }), queryMode: resolveChoice(r.queryMode, [ "message", "recent", "full" ], DEFAULT_QUERY_MODE), maxSummaryChars: resolveIntegerOption(r.maxSummaryChars, 220, { min: 40, max: 1e3 }), recentUserTurns: resolveIntegerOption(r.recentUserTurns, 2, { min: 0, max: 4 }), recentAssistantTurns: resolveIntegerOption(r.recentAssistantTurns, 1, { min: 0, max: 3 }), recentUserChars: resolveIntegerOption(r.recentUserChars, 220, { min: 40, max: 1e3 }), recentAssistantChars: resolveIntegerOption(r.recentAssistantChars, 180, { min: 40, max: 1e3 }), logging: r.logging === true, cacheTtlMs: resolveIntegerOption(r.cacheTtlMs, DEFAULT_CACHE_TTL_MS, { min: 1e3, max: 12e4 }), circuitBreakerMaxTimeouts: resolveIntegerOption(r.circuitBreakerMaxTimeouts, 3, { min: 1, max: 20 }), circuitBreakerCooldownMs: resolveIntegerOption(r.circuitBreakerCooldownMs, DEFAULT_CIRCUIT_BREAKER_COOLDOWN_MS, { min: 5e3, max: 6e5 }), persistTranscripts: r.persistTranscripts === true, transcriptDir: normalizeTranscriptDir(r.transcriptDir) }; } function readActiveMemoryConfig(e) { try { return e.runtime.config.current(); } catch { return e.config; } } function normalizeActiveMemoryFastMode(e) { return e === true || e === false || e === "auto" ? e : void 0; } function applyCliRuntimeRecallTimeoutDefault(e, t) { if (!e.timeoutMsIsDefault || e.timeoutMs >= 45e3) return e; return t ? { ...e, timeoutMs: DEFAULT_CLI_RUNTIME_RECALL_TIMEOUT_MS } : e; } //#endregion export { normalizePluginConfig as a, resolveSafeTranscriptDir as c, normalizeActiveMemoryFastMode as i, hasDeprecatedModelFallbackPolicy as n, readActiveMemoryConfig as o, isMissingRegisteredMemoryToolsError as r, resolvePersistentTranscriptBaseDir as s, applyCliRuntimeRecallTimeoutDefault as t };