UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 6.05 kB
import{i as e,o as t}from"./transcript-record-coerce-eN4p5mcq.mjs";import{i as n,r}from"./transcript-global-singleton-DIJgobpU.mjs";import"./transcript-sqlite-database-admission-Cro6ZHgY.mjs";import"./transcript-number-coercion-Dr06QpMa.mjs";import{r as i,s as a}from"./transcript-sqlite-post-commit-BDZjIt2B.mjs";import"./transcript-sqlite-schema-facts-C4Tsn8VX.mjs";import{n as o,t as s}from"./transcript-session-row-changes-DzgVgiDT.mjs";import{r as c}from"./transcript-openclaw-agent-db-identity-BwKDyjmN.mjs";import"./transcript-session-actor-transaction-D7al_TuX.mjs";import{n as l,t as u}from"./transcript-sqlite-commit-receipt-B-xcw-Ul.mjs";import{at as d}from"./transcript-chat-display-projection.sanitize-DhS2w3ZG.mjs";import{ft as f}from"./transcript-tool-call-xml-BErSpGGl.mjs";import"./transcript-session-display-projection-DeWx2EM5.mjs";import{t as p}from"./transcript-transcript-events-CeN2k8Gr.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(t){let n=e(t);return!(!n||typeof n.runId!=`string`||typeof n.modelProvider!=`string`||f(n.modelProvider)||typeof n.model!=`string`)}function isSessionRowAssistantMessage(e){return t(e)&&typeof e.text==`string`&&typeof e.timestamp==`number`&&Number.isFinite(e.timestamp)}function readStoredSessionRowTranscriptProjection(e){if(e.json&&e.updatedAt===e.transcriptUpdatedAt)try{let n=JSON.parse(e.json);return t(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===(e.indexedSeq??null)?{lastMessagePreview:n.lastMessagePreview,lastAssistantMessage:n.lastAssistantMessage===void 0||n.lastAssistantMessage===`unchanged`?`unknown`:n.lastAssistantMessage,terminalModel:n.terminalModel,indexedSeq:e.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(e){if(!t(e)||!t(e.source)||!(e.facts instanceof Map))return!1;let n=[...e.facts.keys()];if(!n.every(e=>typeof e==`string`)||typeof e.source.identity!=`string`||typeof e.source.incarnation!=`string`||!l(e,{source:{identity:e.source.identity,incarnation:e.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 e.facts){if(!t(r))return!1;if(r.kind!==`postimage`)continue;let e=r.value;if(!t(e)||e.sessionKey!==n||typeof e.sessionId!=`string`||e.generation!==null&&typeof e.generation!=`string`||e.leafEventId!==null&&typeof e.leafEventId!=`string`||![e.rawSeq,e.updatedAt,e.indexedSeq,e.activeMessageCount].every(nullableNumber)||e.needsRebuild!==null&&e.needsRebuild!==0&&e.needsRebuild!==1||e.projectionReady!==void 0&&e.projectionReady!==!0||e.lastMessagePreview!==void 0&&e.lastMessagePreview!==null&&typeof e.lastMessagePreview!=`string`||e.lastAssistantMessage!==void 0&&e.lastAssistantMessage!==null&&e.lastAssistantMessage!==`unknown`&&e.lastAssistantMessage!==`unchanged`&&!isSessionRowAssistantMessage(e.lastAssistantMessage)||e.terminalModel!==void 0&&e.terminalModel!==null&&!isSessionTranscriptTerminalModel(e.terminalModel))return!1}return!0}export{h as a,readStoredSessionRowTranscriptProjection as i,publishUnchangedSessionTranscriptReceipts as n,readFinalSessionTranscriptProjection as r,publishUnchangedSessionTranscriptAuthority as t};