UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 2.79 kB
import{D as e,w as t}from"./disk-budget.worker-paths-DAFiPrD7.mjs";import{l as n}from"./disk-budget.worker-openclaw-agent-db.paths-BlkaCq0b.mjs";import{c as r,d as i,l as a,u as o}from"./disk-budget.worker.js";import{_ as s,d as c,l,m as u,o as d}from"./disk-budget.worker-agent-database-admission-CBRZjurS.mjs";import"./disk-budget.worker-legacy.default-agent-owner-CNQ3_GGg.mjs";import"./disk-budget.worker-sqlite-snapshot-staging-owner-DnWRS3Bz.mjs";const f=`main`;function resolveAgentMainSessionKey(e){return a({agentId:e.agentId,mainKey:e.cfg?.session?.mainKey})}function canonicalizeMainSessionAlias(e){let t=e.sessionKey.trim();if(!t)return t;let r=o(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),s=a({agentId:i,mainKey:r}),c=a({agentId:i,mainKey:`main`}),l=a({agentId:f,mainKey:r}),u=a({agentId:f,mainKey:`main`}),d=t===`main`||t===r||t===s||t===c||t===l||t===u;return e.cfg?.session?.scope===`global`&&d?`global`:d?s:t}function tryResolveSessionCompatibilityOwnerAgentId(e,t){let n=c(e,t);return n.kind===`configured`?n.agentId:n.kind===`retired`?void 0:l(e)??s(e)}function canonicalizeSessionKeyForAgent(e,t){let i=r(t);return i===`global`||i===`unknown`||i.startsWith(`agent:`)?i:`agent:${n(e)}:${i}`}function resolveLogicalSessionStoreAgentId(e,t){let n=tryResolveSessionCompatibilityOwnerAgentId(e,t);if(n)return n;let r=c(e,t);throw new d(u(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,r,i,a){let s=n(i.agentId),c=t(i.rest);if(s!==`main`||c!==`main`&&c!==o(e.session?.mainKey)||u(e).includes(`main`))return{agentId:s,sessionKey:r};let l=a?n(a):resolveLogicalSessionStoreAgentId(e,`main`);return{agentId:l,sessionKey:`agent:${l}:${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(t){let a=e(t.sessionKey)??``,s=r(a),c=i(s);if(c)return canonicalizeParsedSessionStoreKey(t.cfg,s,c,t.storeAgentId);let l=a.toLowerCase();if(!a||l===`global`||l===`unknown`)return l;let u=o(t.cfg.session?.mainKey),d=t.storeAgentId?n(t.storeAgentId):void 0;return l===`main`||l===u?t.cfg.session?.scope===`global`?`global`:resolveAgentMainSessionKey({cfg:t.cfg,agentId:d??resolveLogicalSessionStoreAgentId(t.cfg,a)}):canonicalizeSessionKeyForAgent(d??resolveLogicalSessionStoreAgentId(t.cfg,a),a)}export{canonicalizeSessionKeyForAgent,resolveSessionStoreKey};