openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 3.97 kB
JavaScript
import{o as e}from"./transcript-agent-scope-config-l-KZcQvf.mjs";import{o as t}from"./transcript-artifacts-BcxHhf8q.mjs";import"./transcript-agent-scope-B3Lazcye.mjs";import{t as n}from"./transcript-main-session-kIGO4exC.mjs";import{t as r}from"./transcript-session-accessor.sqlite-entry-list.read-B1Mru2j9.mjs";import{t as i}from"./transcript-session-accessor.sqlite-transcript-stats-read-s1YUTbxe.mjs";import{n as a,t as o}from"./transcript-session-history-read-BjPq6Ot9.mjs";import{n as s,t as c}from"./transcript-session-transcript-corpus-policy-YTf-w7Rw.mjs";import l from"node:path";function sqliteContentRevision(e){try{let t=i([e])[0];return t?[`sqlite`,t.maxSeq,t.sizeBytes,t.eventCount,t.lastMutationAtMs??``,t.lastObservedMutationAtMs??``].join(`:`):void 0}catch{return}}function toArtifactCorpusEntry(e,t,n,r,i){return{agentId:e,artifactKind:`archive-artifact`,sessionFile:t,sessionId:n,...i?{contentRevision:i}:{},...r?.generatedByDreamingNarrative?{generatedByDreamingNarrative:!0}:{},...r?.generatedByCronRun?{generatedByCronRun:!0}:{},sessionKind:r?.sessionKind??`unknown`}}function projectSessionTranscriptCorpusEntries(r,i,u,d,f=r.storePath,p){let{cfg:m,env:h,normalizedAgentId:g,storePath:_,isSharedFixedStore:v}=r,y=i.includeContentRevision!==!1,b=/* @__PURE__ */ new Map,x=/* @__PURE__ */ new Map,S={agentId:g,env:h,hydrateSkillPromptRefs:!1,projection:`list`,readConsistency:`latest`,storePath:f},C=i.includeRetainedSqlite?a(S,{},p):[],w=new Set(C.map(e=>e.sessionId)),T=[...new Set(d.flatMap(({entry:e})=>{let t=e.sessionId?.trim();return t&&!w.has(t)?[t]:[]}))],E=[...C,...T.length>0?a(S,{includeAllWindows:!0,sessionIds:T},p):[]],D=/* @__PURE__ */ new Map;for(let e of E)e.provenanceKnown&&e.entry.pluginOwnerId&&D.set(e.sessionId,e.entry.pluginOwnerId);let O=new Map(o({agentId:g,env:h,archiveNames:u.map(e=>l.basename(e.path)),storePath:f}).map(e=>[e.archiveName,e])),k=s([...C.map(({entry:e,sessionKey:t})=>({entry:e,sessionKey:t})),...d]),toSqliteEntry=(e,t,n,r,i,a)=>{let o=c(n,r,k),s=i===`active-session`?n.trim():n,l=D.get(t),u=y?sqliteContentRevision({agentId:e,env:h,sessionId:t,...s?{sessionKey:s}:{},storePath:f}):void 0;return{agentId:e,artifactKind:i,sessionFile:s,sessionId:t,...u?{contentRevision:u}:{},transcriptSource:`sqlite`,storePath:_,...a===void 0?{}:{updatedAtMs:a},...s?{sessionKey:s}:{},...l?{pluginOwnerId:l}:{},...o.generatedByDreamingNarrative?{generatedByDreamingNarrative:!0}:{},...o.generatedByCronRun?{generatedByCronRun:!0}:{},sessionKind:o.sessionKind}},resolveSessionOwnership=t=>{let r=v?t:n({cfg:m,agentId:g,sessionKey:t});return{sessionKey:r,ownerAgentId:e({config:m,sessionKey:r,...v?{}:{fallbackAgentId:g}})}};for(let e of d){let{ownerAgentId:t}=resolveSessionOwnership(e.sessionKey),n=e.entry.sessionId?.trim();if(!n)continue;let r=toSqliteEntry(t,n,e.sessionKey,e.entry,`active-session`,Number.isFinite(e.entry.updatedAt)?e.entry.updatedAt:void 0);x.set(r.sessionId,t),t===g&&b.set(r.sessionId,r)}let A=!v,j=[...b.values()];if(i.includeRetainedSqlite)for(let e of C){if(b.has(e.sessionId))continue;let{sessionKey:t,ownerAgentId:n}=resolveSessionOwnership(e.sessionKey);n!==g||!e.provenanceKnown||e.acpOwned||e.entry.pluginOwnerId||e.entry.hookExternalContentSource||j.push(toSqliteEntry(n,e.sessionId,t,e.entry,`retained-session`,e.updatedAtMs))}for(let{path:e,contentRevision:n}of u){let r=l.basename(e),i=O.get(r),a=i?.sessionId??t(r);if(!a)continue;let o=b.get(a),s=x.get(a);s&&s!==g||(s||i||A)&&j.push({...toArtifactCorpusEntry(g,e,a,o,n),...i?.sessionKey?{sessionKey:i.sessionKey}:{},...i?{storePath:_}:{}})}return j}function readCorpusSessionEntries(e,t){let n={agentId:e.normalizedAgentId,env:e.env,hydrateSkillPromptRefs:!1,projection:`list`,storePath:e.storePath};return r(n,{continuation:t})}function readSessionTranscriptCorpusInventory(e,t,n,r,i){return projectSessionTranscriptCorpusEntries(e,t,n,readCorpusSessionEntries({...e,storePath:r},i),r,i)}export{readSessionTranscriptCorpusInventory};