UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 2.28 kB
import{M as e}from"./transcript-chat-message-content-Cx-VPFHv.mjs";import{d as t,r as n}from"./transcript-sqlite-worker-identity-C2ykgpDo.mjs";import{i as r,o as i,t as a}from"./transcript-openclaw-agent-db-identity-BwKDyjmN.mjs";import{a as o}from"./transcript-openclaw-agent-db-validation-cache-CPj39b9d.mjs";var s=/* @__PURE__ */ e({assertCapturedSessionEntryReadSource:()=>assertCapturedSessionEntryReadSource,captureSessionEntryReadSource:()=>captureSessionEntryReadSource,prepareSessionEntryReadSource:()=>prepareSessionEntryReadSource});async function prepareSessionEntryReadSource(e,n,r){let i=r.prepareSource||r.capturePhysicalSource,a=!r.inspection&&i?await o(e):void 0,validationIdentity=e=>({key:`file:${e.validation.identity}`,canonicalPath:e.canonicalPath,birthtime:e.validation.birthtime}),s=n.candidates.find(t=>t.identity&&t.physicalPath===e.path)?.identity??(a?validationIdentity(a):i?await t(e.path):void 0),c=s&&{path:e.path,physicalPath:e.path,identity:s},l=c?[n,{sourcePath:e.path,candidates:[c]}]:[n],u=!1;return{get identity(){return s},readCustody:l,assertCurrent:()=>a?.assertCurrent(),async prepareRead(n){if(n&&s?.key.startsWith(`file:`)&&(`file:${n.validation.identity}`!==s.key||n.validation.birthtime!==s.birthtime))throw Error(`Session entry read changed its captured physical owner`);a??=n,!u&&s&&(!r.inspection&&s.birthtime===void 0&&(s=a?validationIdentity(a):await t(e.path),c&&(c.identity=s)),r.prepareSource?.(e,s),u=!0)}}}function captureSessionEntryReadSource(e,t,n=`Session entry read requires its current durable owner`){t&&a(e,t);let o=i(e);if(typeof o.identity!=`string`||!r(e))throw Error(n);return{agentId:e.agentId,path:e.path,databaseIdentity:o.identity,databaseBirthtime:o.birthtime}}function assertCapturedSessionEntryReadSource(e,t){if(typeof e.databaseIdentity!=`string`||t&&t.path===e.path||n(e.path,`file:${e.databaseIdentity}`,e.databaseBirthtime),!t){if(typeof e.databaseIdentity==`symbol`)throw Error(`Captured session database is no longer open`);return}let a=i(t);if(t.agentId!==e.agentId||a.identity!==e.databaseIdentity||a.birthtime!==e.databaseBirthtime||!r(t))throw Error(`Captured session database changed before read`)}export{captureSessionEntryReadSource as n,s as r,assertCapturedSessionEntryReadSource as t};