UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

94 lines (93 loc) • 3.79 kB
import { n as normalizeAgentId } from "./agent-id-CQjtp2ft.mjs"; import { i as normalizeMainKey, n as buildAgentMainSessionKey } from "./session-key-DW1jcHbM.mjs"; import "./session-key-CqAyZeVk.mjs"; import { i as listAgentIds } from "./agent-roster-t1ooUdXp.mjs"; import { O as tryResolveAmbientOwnerAgentId, m as resolveAmbientOwnerAgentId, z as resolvePersistedSessionStoreOwnerForKey } from "./agent-scope-config-DmXgFGKP.mjs"; import { n as resolveCanonicalMainSessionKey } from "./main-session-key-DT_l1IDv.mjs"; //#region src/config/sessions/main-session.ts const FALLBACK_DEFAULT_AGENT_ID = "main"; const SESSION_ROUTING_CHANGED_ERROR_REASON = "session-routing-changed"; /** Resolves the configured main session key, honoring global session scope. */ function resolveMainSessionKey(e) { return resolveCanonicalMainSessionKey({ agentId: resolveAmbientOwnerAgentId(e, void 0, { surface: "main-session routing", hint: "Pass an explicit agent/session key instead of the unscoped main alias." }), mainKey: e.session?.mainKey, sessionScope: e.session?.scope }); } /** Resolves the owner and canonical session target for ambient system work. */ function resolveSystemMainSessionTarget(e) { const t = resolveAmbientOwnerAgentId(e); return { agentId: t, sessionKey: resolveCanonicalMainSessionKey({ agentId: t, mainKey: e.session?.mainKey, sessionScope: e.session?.scope }) }; } /** Resolves the main session owned by configured ambient system work. */ function resolveSystemMainSessionKey(e) { return resolveSystemMainSessionTarget(e).sessionKey; } /** Stable fingerprint for the config values that canonicalize chat session keys. */ function resolveSessionRoutingContract(e) { const t = e?.session?.scope ?? "per-sender"; const n = t === "global" ? resolvePersistedSessionStoreOwnerForKey(e, "global") : { kind: "none" }; const r = n.kind === "configured" ? n.agentId : n.kind === "retired" ? `retired:${n.agentId}` : tryResolveAmbientOwnerAgentId(e) ?? (e.agents?.ownership === "explicit" ? "unowned" : listAgentIds(e)[0] ?? "main"); return [ t, normalizeMainKey(e?.session?.mainKey), r ].join("|"); } /** Resolves the main session key for one explicit agent. */ function resolveAgentMainSessionKey(e) { return buildAgentMainSessionKey({ agentId: e.agentId, mainKey: e.cfg?.session?.mainKey }); } /** Resolves an explicit agent id to its canonical main session key. */ function resolveExplicitAgentSessionKey(e) { const t = e.agentId?.trim(); if (!t) return; return resolveAgentMainSessionKey({ cfg: e.cfg, agentId: t }); } /** Canonicalizes main-session aliases to the current scoped session key. */ function canonicalizeMainSessionAlias(e) { const t = e.sessionKey.trim(); if (!t) return t; const n = normalizeMainKey(e.cfg?.session?.mainKey); if (t !== "main" && t !== n && !t.endsWith(":main") && !(t.endsWith(n) && t[t.length - n.length - 1] === ":")) return t; const r = normalizeAgentId(e.agentId); const i = buildAgentMainSessionKey({ agentId: r, mainKey: n }); const a = buildAgentMainSessionKey({ agentId: r, mainKey: "main" }); const o = buildAgentMainSessionKey({ agentId: FALLBACK_DEFAULT_AGENT_ID, mainKey: n }); const s = buildAgentMainSessionKey({ agentId: FALLBACK_DEFAULT_AGENT_ID, mainKey: "main" }); const c = t === "main" || t === n || t === i || t === a || t === o || t === s; if (e.cfg?.session?.scope === "global" && c) return "global"; if (c) return i; return t; } //#endregion export { resolveMainSessionKey as a, resolveSystemMainSessionTarget as c, resolveExplicitAgentSessionKey as i, canonicalizeMainSessionAlias as n, resolveSessionRoutingContract as o, resolveAgentMainSessionKey as r, resolveSystemMainSessionKey as s, SESSION_ROUTING_CHANGED_ERROR_REASON as t };