openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 4.35 kB
JavaScript
import{i as withEngineStoreAdmission}from"../admission-scope-Xl89MEui.mjs";import{k as readSqliteDatabaseIntegrityVerification}from"../sqlite-database-admission-B3KDkUt-.mjs";import{l as OPENCLAW_SQLITE_BUSY_TIMEOUT_MS}from"../openclaw-state-db-contract-G6fQNIi2.mjs";import{a as setSqliteBusyTimeout}from"../sqlite-busy-timeout-CKFMTRX2.mjs";import{a as withDatabaseEngineSelection}from"../context-DZjni16e.mjs";import{r as readSqliteIntegrityFileIdentity}from"../sqlite-file-generation-CHAXRj0p.mjs";import{o as runSqliteReadSnapshotSync}from"../sqlite-transaction-CON-dGDv.mjs";import{r as cloneEnvWithPlatformSemantics}from"../config-env-vars-DCDGIBtT.mjs";import{t as withSqliteSourceReadDatabase}from"../sqlite-source-handle-Dbv4uBKs.mjs";import{r as readExistingAgentSchemaMeta}from"../openclaw-agent-db-metadata-BZHIuJv_.mjs";import{o as readAgentDatabaseSchemaVersion}from"../openclaw-agent-db-schema-read-CQmdNEsa.mjs";import{a as withFreshOpenClawAgentDatabaseReadOnly}from"../openclaw-agent-db-readonly-open-D1ygiMvy.mjs";import{t as tryInspectSqliteReadOnlyInProcess}from"../sqlite-readonly-inspection-C8BaM-cZ.mjs";import{n as serializeAgentSchemaInspectionError}from"../openclaw-agent-schema-inspection-response-DJ7lInLM.mjs";
//!src/state/openclaw-agent-schema-inspection.worker.ts
if(!process.send||!process.disconnect)throw new Error(`Agent schema inspection requires parent IPC.`);const send=e=>process.send?.(e);const disconnect=process.disconnect.bind(process);async function inspectRequest(e){const{requestId:t}=e;try{if(e.type===`inspect-state`){const{input:n,snapshot:r}=e;const{inspectStateDatabaseSchema:i}=await import(`../openclaw-state-schema-preflight-D-0j7p8r.mjs`);const inspect=e=>i(e,n);let a;if(r){readSqliteIntegrityFileIdentity(r.pathname,r.identity);a=withSqliteSourceReadDatabase(r.pathname,`snapshot`,e=>{readSqliteIntegrityFileIdentity(r.pathname,r.identity);return inspect(e)},{timeout:OPENCLAW_SQLITE_BUSY_TIMEOUT_MS});readSqliteIntegrityFileIdentity(r.pathname,r.identity)}else if(n.purpose===`runtime`)a=withSqliteSourceReadDatabase(n.pathname,`source`,e=>runSqliteReadSnapshotSync(e,()=>inspect(e)),{timeout:OPENCLAW_SQLITE_BUSY_TIMEOUT_MS,waitForAdmission:true});else a=tryInspectSqliteReadOnlyInProcess(n.pathname,inspect)?.value;send({requestId:t,ok:true,inspection:null,stateInspection:a?{...a,inspectionErrors:a.inspectionErrors.map(serializeAgentSchemaInspectionError)}:null});return}const{input:n,snapshot:r}=e;if(n.env)n.env=cloneEnvWithPlatformSemantics(n.env);if(e.databaseEngineSelection){const r=n.agentId;if(!r)throw new Error(`PostgreSQL schema inspection requires an established agent owner`);const i=withDatabaseEngineSelection(e.databaseEngineSelection,()=>withEngineStoreAdmission(()=>withFreshOpenClawAgentDatabaseReadOnly(({db:e})=>({version:readAgentDatabaseSchemaVersion(e),integrityGateOutcome:`healthy`,agentSchemaMeta:readExistingAgentSchemaMeta(e)}),{agentId:r,path:n.pathname,env:n.env})));send({requestId:t,ok:true,inspection:i.found?i.value:null});return}const[{inspectAgentDatabaseSchema:i},{configureSqliteMaintenanceCache:a}]=await Promise.all([import(`../openclaw-agent-schema-inspection-Ctn5_fYc.mjs`),import(`../sqlite-maintenance-cache-BUhOst-9.mjs`)]);const readVerification=()=>!r&&n.requireStartupMigrationReadiness?readSqliteDatabaseIntegrityVerification(n.pathname):void 0;const inspect=(e,t=readVerification())=>{setSqliteBusyTimeout(e,OPENCLAW_SQLITE_BUSY_TIMEOUT_MS);if(n.requireStartupMigrationReadiness)a(e);return i(e,{...n,startupIntegrityVerification:t})};let o;if(r){readSqliteIntegrityFileIdentity(r.pathname,r.identity);o=withSqliteSourceReadDatabase(r.pathname,`snapshot`,e=>{readSqliteIntegrityFileIdentity(r.pathname,r.identity);return inspect(e)});readSqliteIntegrityFileIdentity(r.pathname,r.identity)}else o=tryInspectSqliteReadOnlyInProcess(n.pathname,inspect,{allowClosedWal:n.allowClosedWal||readVerification()!==void 0,preserveSourceArtifacts:n.preserveSourceArtifacts,snapshotAfterClosedWalFailure:n.snapshotAfterClosedWalFailure})?.value;send({requestId:t,ok:true,inspection:o?{...o,failure:o.failure?serializeAgentSchemaInspectionError(o.failure):void 0}:null})}catch(e){send({requestId:t,ok:false,error:serializeAgentSchemaInspectionError(e)})}}process.on(`message`,e=>{if(e.type===`close`){disconnect();return}inspectRequest(e)});export{};