UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 2.24 kB
import{Cn as e}from"./openclaw-state-read-subsystem-Dwoo5bcz.mjs";import{Ht as t,Lt as n,Vt as r,s as i}from"./openclaw-state-read-sqlite-database-admission-CrkztOzk.mjs";import{d as a}from"./openclaw-state-read-sqlite-post-commit-CsXPYVOo.mjs";import{statSync as o}from"node:fs";import{randomUUID as s}from"node:crypto";const c=e(Symbol.for(`openclaw.agentDatabaseIdentities`),()=>/* @__PURE__ */ new WeakMap);function registerOpenClawAgentDatabaseIdentity(e,o){let l=a(e),u=n(l.location()??``),d=u?i(u):void 0,f=d?{...d,canonicalPath:t(u)}:u?r(u):void 0;if(!f||!f.key.startsWith(`file:`))throw Error(`OpenClaw agent database requires a physical file for identity registration`);let p=f.key.slice(5);c.set(l,{identity:p,birthtime:f.birthtime,incarnation:s(),filename:u,canonicalPath:f.canonicalPath,ownerDatabasePath:o?t(o):void 0})}function readOpenClawAgentDatabaseIdentity(e){let t=findOpenClawAgentDatabaseIdentity(e);if(t===void 0)throw Error(`OpenClaw agent database identity was not prepared at open`);return t}function findOpenClawAgentDatabaseIdentity(e){return c.get(a(e.db))}function isOpenClawAgentDatabasePathCurrent(e){let t=a(e.db);if(!e.db.isOpen||!t.isOpen)return!1;let{identity:r,filename:i}=readOpenClawAgentDatabaseIdentity(e);if(n(t.location()??``)!==i)return!1;let s=o(e.path,{bigint:!0,throwIfNoEntry:!1});return s!==void 0&&r===`${s.dev}:${s.ino}`}function assertOpenClawAgentDatabaseIdentity(e,t){let n=readOpenClawAgentDatabaseIdentity(e);if(`file:${n.identity}`!==t.key||t.birthtime!==void 0&&n.birthtime!==t.birthtime||!isOpenClawAgentDatabasePathCurrent(e))throw Error(`Agent database changed during repair admission`)}function createOpenClawAgentDatabaseClaim(e,t){let n=!1,isCurrent=()=>!n&&e.db.isOpen&&a(e.db).isOpen,{identity:r,incarnation:i}=readOpenClawAgentDatabaseIdentity(e);return{identity:r,incarnation:i,isCurrent,assertCurrent:()=>{if(!isCurrent())throw Error(`OpenClaw agent database claim is no longer current`)},release:()=>{n||(n=!0,t())}}}export{readOpenClawAgentDatabaseIdentity as a,isOpenClawAgentDatabasePathCurrent as i,createOpenClawAgentDatabaseClaim as n,registerOpenClawAgentDatabaseIdentity as o,findOpenClawAgentDatabaseIdentity as r,assertOpenClawAgentDatabaseIdentity as t};