UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 2.07 kB
import{n as e}from"./transcript-agent-id-DmscQLD6.mjs";import"./transcript-session-key-MDDhuEG9.mjs";function projectSessionMetadata(e,t=[]){return{agentId:e.agentId,sessionId:e.sessionId,sessionKey:e.sessionKey,...e.provenanceKnown&&e.entry.pluginOwnerId?{pluginOwnerId:e.entry.pluginOwnerId}:{},resolution:`live`,...e.sourceMetadata,participants:t}}function unresolvedMemorySessionTarget(e,t){return{agentId:e,sessionId:t,resolution:`unresolved`,hookExternalContentSource:null,channel:null,accountId:null,chatType:null,participants:[]}}function resolveMemorySessionSince(e){let t=typeof e==`string`?Date.parse(e):e;if(t!==void 0&&!Number.isFinite(t))throw Error(`Invalid memory session date: ${e}`);return t}function selectMemorySessionTargets(t,n){let r=[...new Set(t.sessionIds??[])],i=[...new Set(t.hookSources??[])],a=[...new Set(t.participants??[])];if(r.length===0&&i.length===0&&a.length===0)return[];let o=resolveMemorySessionSince(t.since),s=/* @__PURE__ */ new Set,c=/* @__PURE__ */ new Map,l=n.instances.filter(n=>n.agentId===e(t.agentId)).toSorted((e,t)=>e.sourceMetadata.createdAt-t.sourceMetadata.createdAt||e.sessionId.localeCompare(t.sessionId));for(let e of l){let t=[...n.participants.get(e.sessionKey)??[]],l=e.sourceMetadata.hookExternalContentSource;(r.includes(e.sessionId)||r.includes(e.sessionKey)||l&&i.includes(l)||t.some(e=>a.includes(e.id)))&&(s.add(e.sessionId),s.add(e.sessionKey),(o===void 0||e.sourceMetadata.createdAt>=o)&&c.set(e.sessionId,projectSessionMetadata(e,t)))}for(let e of n.archives)s.add(e.sessionId),s.add(e.sessionKey),!(c.has(e.sessionId)||o!==void 0&&e.createdAt<o)&&c.set(e.sessionId,{agentId:t.agentId,sessionId:e.sessionId,sessionKey:e.sessionKey,resolution:`archived`,hookExternalContentSource:null,channel:null,accountId:null,chatType:null,createdAt:e.createdAt,participants:[]});for(let e of r)s.has(e)||c.set(e,unresolvedMemorySessionTarget(t.agentId,e));return[...c.values()]}export{unresolvedMemorySessionTarget as i,resolveMemorySessionSince as n,selectMemorySessionTargets as r,projectSessionMetadata as t};