openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 3.58 kB
JavaScript
import{t as e}from"./transcript-session-transcript-read-fence-error-DfU0swK6.mjs";import{i as t,m as n,o as r}from"./transcript-kysely-sync-DQ_Yn8jW.mjs";import{i}from"./transcript-session-entry-codec-CvLNFJN0.mjs";import{u as a}from"./transcript-json-values-CmANsVU4.mjs";import{F as o}from"./transcript-tool-call-xml-BErSpGGl.mjs";import{o as s,s as c}from"./transcript-transcript-payload-C58U6XNI.mjs";import{n as l}from"./transcript-transcript-payload-read-BfcV5CyI.mjs";import{r as u}from"./transcript-session-transcript-read-bytes-C7AU5F9V.mjs";import{n as d}from"./transcript-session-transcript-read-fence-CgDWkLBX.mjs";import{t as f}from"./transcript-session-accessor.sqlite-projection-read-HIelFCp6.mjs";import{t as p}from"./transcript-session-accessor.sqlite-active-projection-DqkcLtDM.mjs";import{s as m}from"./transcript-session-UBvbxpSH.mjs";import"./transcript-src-B7mi3doP.mjs";import{n as h,t as g}from"./transcript-session-transcript-replay.types-Dio3u4I1.mjs";function readSessionTranscriptReplayGroupsCore(_,v,y={}){let b=h(v);return p(_,p=>{let{database:h,resolved:_}=p,y=f(h),x=d({database:h,..._});if(x&&p.generation!==x.admission.generation)throw new e(`Current-turn transcript admission generation changed`);let S=0,C=[],w=y.selectFrom(`session_transcript_active_events as active`).innerJoin(`transcript_events as event`,e=>e.onRef(`event.session_id`,`=`,`active.session_id`).onRef(`event.seq`,`=`,`active.event_seq`)).where(`active.session_id`,`=`,_.sessionId).where(`active.event_seq`,`<`,x?.beforeRawSeq??2**53-1),T=c(h.db,`event`),E=s(h.db,`event`),D,readOperatorBoundary=()=>{for(let e of r(h.db,w.select([`active.active_position`,E.as(`entry`)]).where(e=>e.or([e(a(h.db,T,n.lit(`$.type`)),`in`,[`reset`,`compaction`]),e.and([e(a(h.db,T,n.lit(`$.type`)),`=`,`custom`),e(a(h.db,T,n.lit(`$.customType`)),`=`,`openclaw.system-prompt`)])])).orderBy(`active.active_position`,`desc`)))if(o(JSON.parse(e.entry)))return e.active_position;return-1},O=w.select([`active.active_position`,`active.event_seq`,u(`event`).as(`bytes`),a(h.db,T,n.lit(`$.type`)).as(`type`),a(h.db,T,n.lit(`$.message.role`)).as(`role`),a(h.db,T,n.lit(`$.customType`)).as(`customType`),a(h.db,E,n.lit(`$.details.kind`)).as(`operatorKind`)]),hydrate=e=>{if(S+=e.bytes+1,S>b)throw RangeError(`Session transcript replay exceeds maxBytes (${b})`);let n=t(h.db,w.select([`event.event_json`,`event.event_zstd`,`event.event_utf8_bytes`]).where(`active.event_seq`,`=`,e.event_seq));if(!n)throw Error(`Selected replay entry disappeared inside its snapshot`);let r=JSON.parse(l(n));if(!i(r))throw Error(`Selected replay entry is not a readable session entry`);return m(r)};for(let e of new Set(v.entryIds)){let n=t(h.db,O.innerJoin(`transcript_event_identities as identity`,e=>e.onRef(`identity.session_id`,`=`,`active.session_id`).onRef(`identity.seq`,`=`,`active.event_seq`)).where(`identity.event_id`,`=`,e).where(`identity.session_id`,`=`,_.sessionId));if(!n||n.type!==`message`||n.role!==`user`)continue;let r=hydrate(n);if(!r)continue;let i={entryId:e,message:r,carriers:[]};for(let e=n.active_position+1;;e+=1){let n=t(h.db,O.where(`active.active_position`,`=`,e));if(n&&g(n.type,n.customType))continue;if(!n||n.type!==`custom_message`||n.customType!==`openclaw.runtime-context`&&n.customType!==`openclaw.system-update`)break;if(n.operatorKind===`prompt-update`&&n.customType===`openclaw.system-update`&&n.active_position<(D??=readOperatorBoundary()))continue;let r=hydrate(n);r&&i.carriers.push(r)}C.push(i)}return C},{...y,readOnly:!0})}export{readSessionTranscriptReplayGroupsCore};