UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 2.86 kB
import{h as SessionGoalOperationError}from"../../openclaw-state-worker-error-Ca5E4dEV.mjs";import{l as ensureSessionGoalOperationsSchema}from"../../openclaw-agent-db-schema-compatibility-CvbEWJYZ.mjs";import{f as readSessionEntryRow}from"../../session-accessor.sqlite-entry-read-DBsgM_K3.mjs";import{r as mergeSessionEntry}from"../../types-Di4kCK2F.mjs";import{r as applySessionGoalOperation}from"../../goals-operation-policy-Dqo_4G9A.mjs";import{s as writeSessionEntry}from"../../session-accessor.sqlite-entry-store-Cxqr6m6F.mjs";import{n as readSessionGoalOperationReceipt,r as writeSessionGoalOperationReceipt}from"../../goals-operation-receipts-Buv2GZqF.mjs";import{n as prepareSessionEntryReplacementPublication}from"../../session-accessor.sqlite-replacement-publication-DWaC81mD.mjs";import{n as readSessionSourceValidation}from"../../session-source-predicate.worker-BiGmAAW2.mjs";import{i as transferSessionEntryWorkerCandidate,t as bindSessionWorkerBackend}from"../../session-entry-patch.worker-1XVZD5Dz.mjs"; //!src/config/sessions/goals-operations.worker.ts function bindSqliteWorkerBackend(e,t){return bindSessionWorkerBackend(e,t,`Goal`,({admit:e,writeTransaction:t},n)=>{ensureSessionGoalOperationsSchema(n.db);return({input:n})=>{return t(`session.goal.mutate`,`Goal transaction`,t=>{const r=readSessionSourceValidation(t,n.sources);const{refusedSource:i}=r;if(i){transferSessionEntryWorkerCandidate(t,e,{kind:`session-goal-management`,refusedSource:i});throw new Error(`Goal source refusal was not rejected`)}if(r.conversationMatches.length)e(`transaction`,{kind:`session-entry-patch-validated`,sourceValidation:r});const{previous:a,...o}=mutateSessionGoalInDatabase(t,n);const s={kind:`session-goal-management`,result:o,publication:a&&o.sessionEntry?prepareSessionEntryReplacementPublication({previous:/* @__PURE__ */ new Map([[n.sessionKey,a]]),current:/* @__PURE__ */ new Map([[n.sessionKey,o.sessionEntry]]),pendingArchiveRecovery:false,membershipInvalidatedKeys:[],maintenancePlans:[]},t):void 0};return transferSessionEntryWorkerCandidate(t,e,s)})}},`Goal management`)}function mutateSessionGoalInDatabase(e,t){const n=readSessionEntryRow(e,t.sessionKey);const r=readSessionGoalOperationReceipt(e.db,t.sessionKey,t.expectedSessionId,t.operation);if(r&&n?.entry.sessionId===t.expectedSessionId)return{result:r,replayed:true};if(!n||n.entry.sessionId!==t.expectedSessionId)throw new SessionGoalOperationError(`session-rebound`,`Session changed; refresh before changing its Goal.`);const i=applySessionGoalOperation(n.entry,t.operation,Date.now());const a=writeSessionEntry(e,t.sessionKey,mergeSessionEntry(n.entry,{goal:i}),{canonicalPreviousEntry:n.entry});return{result:writeSessionGoalOperationReceipt(e.db,t.sessionKey,t.expectedSessionId,t.operation,i),replayed:false,sessionEntry:a,previous:n.entry}}export{bindSqliteWorkerBackend};