openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
7 lines • 4.04 kB
JavaScript
import{a as normalizeOptionalString,n as normalizeLowercaseStringOrEmpty}from"./string-coerce-BBqv4GXj.mjs";import"./number-coercion-DIhBGkET.mjs";import"./state-dir-C22DK7p0.mjs";import{n as normalizeAgentId}from"./agent-id-0RKGHEYi.mjs";import{c as resolvePersistedSessionStoreOwnerForKey,h as listAgentIds,o as tryResolveLegacyCompatibilityAgentId,t as AgentSelectionRequiredError,v as tryResolveSoleAgentId}from"./agent-scope-config-CGe7-g8s.mjs";import{a as buildAgentMainSessionKey,c as parseAgentSessionKeyParts,i as normalizeSessionKeyPreservingOpaquePeerIds,s as normalizeMainKey,t as DEFAULT_AGENT_ID}from"./session-key-B7vzF6rJ.mjs";import"./legacy.default-agent-owner-DavesGxq.mjs";import"./openclaw-state-worker-error-DBsl8KO0.mjs";import"./agent-database-admission-DQGethEB.mjs";
//!src/config/sessions/main-session.ts
const FALLBACK_DEFAULT_AGENT_ID=`main`;function resolveAgentMainSessionKey(e){return buildAgentMainSessionKey({agentId:e.agentId,mainKey:e.cfg?.session?.mainKey})}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}
//!src/gateway/session-request-agent.ts
function tryResolveSessionCompatibilityOwnerAgentId(e,t){const n=resolvePersistedSessionStoreOwnerForKey(e,t);if(n.kind===`configured`)return n.agentId;return n.kind===`retired`?void 0:tryResolveLegacyCompatibilityAgentId(e)??tryResolveSoleAgentId(e)}
//!src/gateway/session-store-key.ts
function canonicalizeSessionKeyForAgent(e,t){const n=normalizeSessionKeyPreservingOpaquePeerIds(t);return n===`global`||n===`unknown`||n.startsWith(`agent:`)?n:`agent:${normalizeAgentId(e)}:${n}`}function resolveLogicalSessionStoreAgentId(e,t){const n=tryResolveSessionCompatibilityOwnerAgentId(e,t);if(n)return n;const r=resolvePersistedSessionStoreOwnerForKey(e,t);throw new AgentSelectionRequiredError(listAgentIds(e),{surface:`session key "${t}"`,hint:r.kind===`retired`?`Its recorded owner "${r.agentId}" is no longer configured. Select a configured agent explicitly.`:`Use an agent-prefixed session key or select an agent explicitly.`})}function resolveParsedSessionStoreKey(e,t,n,r){const i=normalizeAgentId(n.agentId);const a=normalizeLowercaseStringOrEmpty(n.rest);if(i!==`main`||a!==`main`&&a!==normalizeMainKey(e.session?.mainKey)||listAgentIds(e).includes(`main`))return{agentId:i,sessionKey:t};const o=r?normalizeAgentId(r):resolveLogicalSessionStoreAgentId(e,`main`);return{agentId:o,sessionKey:`agent:${o}:${a}`}}function canonicalizeParsedSessionStoreKey(e,t,n,r,i=false){const a=resolveParsedSessionStoreKey(e,t,n,r);if(i&&a.agentId===normalizeAgentId(n.agentId))return a.sessionKey;return canonicalizeMainSessionAlias({cfg:e,agentId:a.agentId,sessionKey:a.sessionKey})}function resolveSessionStoreKey(e){const t=normalizeOptionalString(e.sessionKey)??``;const n=normalizeSessionKeyPreservingOpaquePeerIds(t);const r=parseAgentSessionKeyParts(n);if(r)return canonicalizeParsedSessionStoreKey(e.cfg,n,r,e.storeAgentId);const i=t.toLowerCase();if(!t||i===`global`||i===`unknown`)return i;const a=normalizeMainKey(e.cfg.session?.mainKey);const o=e.storeAgentId?normalizeAgentId(e.storeAgentId):void 0;if(i===`main`||i===a){if(e.cfg.session?.scope===`global`)return`global`;return resolveAgentMainSessionKey({cfg:e.cfg,agentId:o??resolveLogicalSessionStoreAgentId(e.cfg,t)})}return canonicalizeSessionKeyForAgent(o??resolveLogicalSessionStoreAgentId(e.cfg,t),t)}export{canonicalizeSessionKeyForAgent,resolveSessionStoreKey};