openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 2.39 kB
JavaScript
import{i as e}from"./transcript-record-coerce-CPLgmAk9.mjs";import{i as t,o as n,t as r}from"./transcript-session-history-worker-errors-CaYY_L96.mjs";import{t as i}from"./transcript-chat-display-projection.core-B2Q8dHzN.mjs";import"./transcript-chat-display-projection.history-Dd7fL_uC.mjs";import{n as a}from"./transcript-session-transcript-entry-message-aTWZE4hU.mjs";function isAppendOnlySessionHistoryDelta(t){return t.kind===`page`&&!t.hasMore&&!t.events.some(({event:t})=>{let n=e(t)?.type;return n===`reset`||n===`compaction`||n===`leaf`})}function prepareSessionHistorySubagentFacts(e,n,r){let i=/* @__PURE__ */ new Map,a=[],readFact=(e,n)=>{try{return n()}catch(n){let o=t(n);if(!o||!r)throw n;return r({sessions:[...i],runMessages:a,failure:{lookup:e,error:o}},n)}};return n({assertCurrent:e.assertCurrent,isSubagentSession(t){let n=readFact({kind:`session`,sessionKey:t},()=>e.isSubagentSession(t));return i.set(t,n),n},isSubagentRunMessage(t,n){let r=readFact({kind:`run`,runId:t,messageSeq:n},()=>e.isSubagentRunMessage(t,n));return a.push([t,n,r]),r}}),{sessions:[...i],runMessages:a}}function prepareSessionHistoryDelta(e,t){return{delta:e,subagentCoordination:prepareSessionHistorySubagentFacts(t,t=>{if(isAppendOnlySessionHistoryDelta(e))for(let n of e.events){if(n.messageSeq===void 0)continue;let e=a(n.event,n.messageSeq,n.displayPosition);e&&i({subagentCoordination:t}).append([e])}},(t,n)=>{throw new r({delta:e,subagentCoordination:t},n)})}}function createPreparedSessionHistorySubagentProjection(e,t){let r=new Map(e.sessions),i=/* @__PURE__ */ new Map;for(let[t,n,r]of e.runMessages){let e=i.get(t);e||(e=/* @__PURE__ */ new Map,i.set(t,e)),e.set(n,r)}let requireFact=(r,i)=>{if(t(),r===void 0){let t=e.failure?.lookup;throw e.failure&&(i.kind===`session`&&t?.kind===`session`&&i.sessionKey===t.sessionKey||i.kind===`run`&&t?.kind===`run`&&i.runId===t.runId&&i.messageSeq===t.messageSeq)&&n({ok:!1,error:e.failure.error}),Error(`Session history visibility is unavailable; retry the request.`)}return r};return{assertCurrent:t,isSubagentSession:e=>requireFact(r.get(e),{kind:`session`,sessionKey:e}),isSubagentRunMessage:(e,t)=>requireFact(i.get(e)?.get(t),{kind:`run`,runId:e,messageSeq:t})}}export{prepareSessionHistorySubagentFacts as i,isAppendOnlySessionHistoryDelta as n,prepareSessionHistoryDelta as r,createPreparedSessionHistorySubagentProjection as t};