openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 2.87 kB
JavaScript
import{n as normalizeAgentId}from"./agent-id-cOfqmfln.mjs";import{i as normalizeMainKey,n as buildAgentMainSessionKey}from"./session-key-DYtwLLn1.mjs";import"./session-key-BPgKfU2m.mjs";import{i as listAgentIds}from"./agent-roster-4XrgUgPK.mjs";import{O as tryResolveAmbientOwnerAgentId,m as resolveAmbientOwnerAgentId,z as resolvePersistedSessionStoreOwnerForKey}from"./agent-scope-config-CG9CFpGX.mjs";import{n as resolveCanonicalMainSessionKey}from"./main-session-key-JltUEew8.mjs";
//!src/config/sessions/main-session.ts
const FALLBACK_DEFAULT_AGENT_ID=`main`;const SESSION_ROUTING_CHANGED_ERROR_REASON=`session-routing-changed`;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})}function resolveSystemMainSessionTarget(e){const t=resolveAmbientOwnerAgentId(e);return{agentId:t,sessionKey:resolveCanonicalMainSessionKey({agentId:t,mainKey:e.session?.mainKey,sessionScope:e.session?.scope})}}function resolveSystemMainSessionKey(e){return resolveSystemMainSessionTarget(e).sessionKey}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(`|`)}function resolveAgentMainSessionKey(e){return buildAgentMainSessionKey({agentId:e.agentId,mainKey:e.cfg?.session?.mainKey})}function resolveExplicitAgentSessionKey(e){const t=e.agentId?.trim();if(!t)return;return resolveAgentMainSessionKey({cfg:e.cfg,agentId:t})}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}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};