UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 2.83 kB
import{Bt as e,Ut as t}from"./sqlite-readonly-subsystem-Bfq7Sewc.mjs";import{j as n}from"./sqlite-readonly-sqlite-snapshot-staging-owner-Bx_sVS1z.mjs";import"./sqlite-readonly-agent-database-admission-BqYBJpcK.mjs";import{F as r,H as i,J as a,Z as o,it as s,nt as c,rt as l,tt as u,z as d}from"./sqlite-readonly-openclaw-state-db-readonly-CQZBUV1N.mjs";import"./sqlite-readonly-openclaw-state-worker-error-CRDBDn6B.mjs";import"./sqlite-readonly-agent-delete-session-store-safety.kernel-C8y95yj5.mjs";const f=`main`;function resolveAgentMainSessionKey(e){return c({agentId:e.agentId,mainKey:e.cfg?.session?.mainKey})}function canonicalizeMainSessionAlias(e){let t=e.sessionKey.trim();if(!t)return t;let r=l(e.cfg?.session?.mainKey);if(t!==`main`&&t!==r&&!t.endsWith(`:main`)&&!(t.endsWith(r)&&t[t.length-r.length-1]===`:`))return t;let i=n(e.agentId),a=c({agentId:i,mainKey:r}),o=c({agentId:i,mainKey:`main`}),s=c({agentId:f,mainKey:r}),u=c({agentId:f,mainKey:`main`}),d=t===`main`||t===r||t===a||t===o||t===s||t===u;return e.cfg?.session?.scope===`global`&&d?`global`:d?a:t}function tryResolveSessionCompatibilityOwnerAgentId(e,t){let n=i(e,t);return n.kind===`configured`?n.agentId:n.kind===`retired`?void 0:d(e)??o(e)}function canonicalizeSessionKeyForAgent(e,t){let r=u(t);return r===`global`||r===`unknown`||r.startsWith(`agent:`)?r:`agent:${n(e)}:${r}`}function resolveLogicalSessionStoreAgentId(e,t){let n=tryResolveSessionCompatibilityOwnerAgentId(e,t);if(n)return n;let o=i(e,t);throw new r(a(e),{surface:`session key "${t}"`,hint:o.kind===`retired`?`Its recorded owner "${o.agentId}" is no longer configured. Select a configured agent explicitly.`:`Use an agent-prefixed session key or select an agent explicitly.`})}function resolveParsedSessionStoreKey(t,r,i,o){let s=n(i.agentId),c=e(i.rest);if(s!==`main`||c!==`main`&&c!==l(t.session?.mainKey)||a(t).includes(`main`))return{agentId:s,sessionKey:r};let u=o?n(o):resolveLogicalSessionStoreAgentId(t,`main`);return{agentId:u,sessionKey:`agent:${u}:${c}`}}function canonicalizeParsedSessionStoreKey(e,t,r,i,a=!1){let o=resolveParsedSessionStoreKey(e,t,r,i);return a&&o.agentId===n(r.agentId)?o.sessionKey:canonicalizeMainSessionAlias({cfg:e,agentId:o.agentId,sessionKey:o.sessionKey})}function resolveSessionStoreKey(e){let r=t(e.sessionKey)??``,i=u(r),a=s(i);if(a)return canonicalizeParsedSessionStoreKey(e.cfg,i,a,e.storeAgentId);let o=r.toLowerCase();if(!r||o===`global`||o===`unknown`)return o;let c=l(e.cfg.session?.mainKey),d=e.storeAgentId?n(e.storeAgentId):void 0;return o===`main`||o===c?e.cfg.session?.scope===`global`?`global`:resolveAgentMainSessionKey({cfg:e.cfg,agentId:d??resolveLogicalSessionStoreAgentId(e.cfg,r)}):canonicalizeSessionKeyForAgent(d??resolveLogicalSessionStoreAgentId(e.cfg,r),r)}export{canonicalizeSessionKeyForAgent,resolveSessionStoreKey};