UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 6.05 kB
import{a as e,i as t}from"./transcript-record-coerce-CPLgmAk9.mjs";import{i as n,r}from"./transcript-global-singleton-DIJgobpU.mjs";import"./transcript-sqlite-database-admission-IPmtadyc.mjs";import"./transcript-number-coercion-D2B2TTt-.mjs";import{r as i,s as a}from"./transcript-sqlite-post-commit-B_pko32i.mjs";import"./transcript-sqlite-schema-facts-C1_zV4Yg.mjs";import{n as o,t as s}from"./transcript-session-row-changes-DGiwEF1b.mjs";import{r as c}from"./transcript-openclaw-agent-db-identity-BPgUuROx.mjs";import"./transcript-session-actor-transaction-LsCQWbNw.mjs";import{n as l,t as u}from"./transcript-sqlite-commit-receipt-CIlkMK9M.mjs";import{U as d}from"./transcript-chat-display-projection.canvas-BVwGQyPV.mjs";import{n as f}from"./transcript-transcript-model-BjZIAV3m.mjs";import{t as p}from"./transcript-transcript-events-BDUVmbAW.mjs";import"./transcript-session-display-projection-D53CYaHn.mjs";import"node:v8";import"node:path";import{AsyncLocalStorage as m}from"node:async_hooks";import"node:util";n(Symbol.for(`openclaw.preparedSessionSharingReads`),()=>/* @__PURE__ */ new Map),n(Symbol.for(`openclaw.pendingSessionEntryPublications`),()=>/* @__PURE__ */ new Map),r(Symbol.for(`openclaw.unknownSessionSharingAuthorities`),`close-and-restart`);const h=n(Symbol.for(`openclaw.preparedSessionSharingChanges`),()=>({changes:/* @__PURE__ */ new WeakMap,operations:/* @__PURE__ */ new WeakMap,current:new m}));n(Symbol.for(`openclaw.sessionEntryPublicationSources`),()=>/* @__PURE__ */ new WeakMap);function isSessionTranscriptTerminalModel(e){let n=t(e);return!(!n||typeof n.runId!=`string`||typeof n.modelProvider!=`string`||f(n.modelProvider)||typeof n.model!=`string`)}function isSessionRowAssistantMessage(t){return e(t)&&typeof t.text==`string`&&typeof t.timestamp==`number`&&Number.isFinite(t.timestamp)}function readStoredSessionRowTranscriptProjection(t){if(t.json&&t.updatedAt===t.transcriptUpdatedAt)try{let n=JSON.parse(t.json);return e(n)&&(n.lastMessagePreview===null||typeof n.lastMessagePreview==`string`)&&(n.lastAssistantMessage===void 0||n.lastAssistantMessage===`unknown`||n.lastAssistantMessage===`unchanged`||n.lastAssistantMessage===null||isSessionRowAssistantMessage(n.lastAssistantMessage)&&!d(n.lastAssistantMessage.text))&&(n.terminalModel===null||isSessionTranscriptTerminalModel(n.terminalModel))&&n.indexedSeq===(t.indexedSeq??null)?{lastMessagePreview:n.lastMessagePreview,lastAssistantMessage:n.lastAssistantMessage===void 0||n.lastAssistantMessage===`unchanged`?`unknown`:n.lastAssistantMessage,terminalModel:n.terminalModel,indexedSeq:t.indexedSeq??null}:void 0}catch{return}}const g=n(Symbol.for(`openclaw.transcriptAuthorityStaged`),()=>/* @__PURE__ */ new WeakMap),_=n(Symbol.for(`openclaw.transcriptAuthorityChanges`),()=>/* @__PURE__ */ new WeakMap);function readFinalSessionTranscriptProjection(e){let t=_.get(o(e));return!e.factsInvalidated&&t?.publication.final&&t.fact.kind===`postimage`&&t.fact.value.projectionReady?t.fact.value:void 0}function receiptChanges(e,t,n,r={final:!0}){return[...e.facts].map(([i,a])=>{let o=s.markFactsOnly({agentId:t,storePath:n,sessionKey:i,scope:`transcript`,facts:{kind:`unchanged`}},a.kind===`unchanged`?void 0:p);return _.set(o,{fact:a,publication:r}),h.changes.set(o,{kind:`source`,databaseIdentity:e.source.identity,canonicalPath:e.source.canonicalPath}),o})}function publishTranscriptFact(e,t,n){if(e.db.isTransaction&&!i(e.db))return;let r=c(e);if(!r)return;let o=u({source:r,domain:`session-transcript-context`,keys:[t],readFact:()=>n}),l=g.get(e.db)??/* @__PURE__ */ new Map,d=l.get(t);if(n.kind===`unchanged`&&d)return;let remove=()=>{l.get(t)===o&&l.delete(t),l.size===0&&g.delete(e.db)},f={final:!1};f.final=!a(e.db,{stage(){g.set(e.db,l),l.set(t,o)},commit(){f.final=l.get(t)===o,remove()},rollback(){d?l.set(t,d):remove()}}),s.emitBatch(receiptChanges(o,e.agentId,e.path,f),e.db)}function publishUnchangedSessionTranscriptAuthority(e,t){publishTranscriptFact(e,t,{kind:`unchanged`})}function parseSessionTranscriptAuthorityReceipts(e){return Array.isArray(e)&&e.every(isTranscriptReceipt)?e:void 0}function publishUnchangedSessionTranscriptReceipts(e){if(e){if(!parseSessionTranscriptAuthorityReceipts(e)||e.some(e=>[...e.facts.values()].some(e=>e.kind!==`unchanged`)))throw Error(`Transcript materialization changed its content authority receipt`);publishCommittedSessionTranscriptReceipts(e)}}function publishCommittedSessionTranscriptReceipts(e){s.emitBatch((e??[]).flatMap(e=>receiptChanges(e,void 0,e.source.canonicalPath??e.source.filename)))}function isTranscriptReceipt(t){if(!e(t)||!e(t.source)||!(t.facts instanceof Map))return!1;let n=[...t.facts.keys()];if(!n.every(e=>typeof e==`string`)||typeof t.source.identity!=`string`||typeof t.source.incarnation!=`string`||!l(t,{source:{identity:t.source.identity,incarnation:t.source.incarnation},domain:`session-transcript-context`,keys:n}))return!1;let nullableNumber=e=>e===null||typeof e==`number`&&Number.isSafeInteger(e);for(let[n,r]of t.facts){if(!e(r))return!1;if(r.kind!==`postimage`)continue;let t=r.value;if(!e(t)||t.sessionKey!==n||typeof t.sessionId!=`string`||t.generation!==null&&typeof t.generation!=`string`||t.leafEventId!==null&&typeof t.leafEventId!=`string`||![t.rawSeq,t.updatedAt,t.indexedSeq,t.activeMessageCount].every(nullableNumber)||t.needsRebuild!==null&&t.needsRebuild!==0&&t.needsRebuild!==1||t.projectionReady!==void 0&&t.projectionReady!==!0||t.lastMessagePreview!==void 0&&t.lastMessagePreview!==null&&typeof t.lastMessagePreview!=`string`||t.lastAssistantMessage!==void 0&&t.lastAssistantMessage!==null&&t.lastAssistantMessage!==`unknown`&&t.lastAssistantMessage!==`unchanged`&&!isSessionRowAssistantMessage(t.lastAssistantMessage)||t.terminalModel!==void 0&&t.terminalModel!==null&&!isSessionTranscriptTerminalModel(t.terminalModel))return!1}return!0}export{h as a,readStoredSessionRowTranscriptProjection as i,publishUnchangedSessionTranscriptReceipts as n,readFinalSessionTranscriptProjection as r,publishUnchangedSessionTranscriptAuthority as t};