UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

80 lines (79 loc) • 3.75 kB
import { c as resolveUserPath } from "./home-dir-EKmgmdPG.mjs"; import { n as normalizeAgentId } from "./agent-id-CQjtp2ft.mjs"; import { d as tryResolveLegacyDataOwner, f as tryResolveRawLegacyDefaultAgentId, n as listAgentEntries } from "./agent-roster-t1ooUdXp.mjs"; import { n as resolveStateDir, t as resolveDefaultAgentWorkspaceDir } from "./openclaw-runtime-paths-DuD50SoI.mjs"; import path from "node:path"; //#region packages/memory-host-sdk/src/host/config-utils.ts /** Trim and deduplicate configured extra-memory roots without losing pattern identity. */ function normalizeConfiguredMemoryExtraPaths(e) { const t = /* @__PURE__ */ new Map(); for (const n of e ?? []) { const e = (typeof n === "string" ? n : n.path).trim(); const r = typeof n === "string" ? "" : n.pattern?.trim() || ""; const i = typeof n === "string" ? false : n.evergreen === true; if (e) t.set(`${e}\0${r}`, r || i ? { path: e, ...r ? { pattern: r } : {}, ...i ? { evergreen: true } : {} } : e); } return Array.from(t.values()); } function resolveRememberAcrossConversations(e, t) { const n = e.memory?.search; const r = (resolveAgentConfig(e, t)?.memory?.search)?.rememberAcrossConversations ?? n?.rememberAcrossConversations; if (r !== void 0) return r; return (e.session?.dmScope === void 0 || e.session.dmScope === "main") && !e.bindings?.some((e) => { if (!e || typeof e !== "object") return false; const t = e.session; return Boolean(t) && typeof t === "object" && t.dmScope !== void 0; }); } const MEMORY_HOST_ROOT_FILENAME = "MEMORY.md"; const DEFAULT_AGENT_ID = "main"; /** Preserve raw default-marker, then first-agent, workspace inheritance. */ function resolveDefaultAgentId(e) { return normalizeAgentId(tryResolveRawLegacyDefaultAgentId(e) ?? listAgentEntries(e)[0]?.id ?? DEFAULT_AGENT_ID); } function resolveAgentConfig(e, t) { const n = normalizeAgentId(t); return listAgentEntries(e).find((e) => normalizeAgentId(e.id) === n); } /** Remove null bytes before paths are handed to filesystem APIs. */ function stripNullBytes(e) { return e.replaceAll("\0", ""); } function resolveMemoryHostAgentWorkspaceDir(e, t, n = process.env) { const r = normalizeAgentId(t); const i = resolveAgentConfig(e, r)?.workspace?.trim(); if (i) return stripNullBytes(resolveUserPath(i, n)); const a = e.agents?.defaults?.workspace?.trim(); if (r === (e.agents?.ownership === "explicit" ? tryResolveLegacyDataOwner(e) : resolveDefaultAgentId(e))) return stripNullBytes(a ? resolveUserPath(a, n) : resolveDefaultAgentWorkspaceDir(n)); if (a) return stripNullBytes(path.join(resolveUserPath(a, n), r)); return stripNullBytes(path.join(resolveStateDir(n), `workspace-${r}`)); } /** Resolve context limits for an agent with defaults fallback. */ function resolveMemoryHostAgentContextLimits(e, t) { const n = e?.agents?.defaults?.contextLimits; if (!e || !t) return n; const r = resolveAgentConfig(e, t)?.contextLimits; return r ? { ...n, ...r } : n; } /** Resolve enabled memory search config plus deduplicated extra paths for an agent. */ function resolveMemoryHostSearchPathConfig(e, t) { const n = e.memory?.search; const r = resolveAgentConfig(e, t)?.memory?.search; const i = r?.enabled ?? n?.enabled ?? true; if (!i) return null; const a = normalizeConfiguredMemoryExtraPaths([...n?.extraPaths ?? [], ...r?.extraPaths ?? []]); return { enabled: i, rememberAcrossConversations: resolveRememberAcrossConversations(e, t), extraPaths: a }; } //#endregion export { resolveMemoryHostSearchPathConfig as a, resolveMemoryHostAgentWorkspaceDir as i, normalizeConfiguredMemoryExtraPaths as n, resolveRememberAcrossConversations as o, resolveMemoryHostAgentContextLimits as r, MEMORY_HOST_ROOT_FILENAME as t };