UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

113 lines (112 loc) • 4.69 kB
import { i as withEngineStoreAdmission } from "../admission-scope-DmxaPNhm.mjs"; import { w as readSqliteDatabaseIntegrityVerification } from "../sqlite-database-admission-DQIqro3d.mjs"; import { l as OPENCLAW_SQLITE_BUSY_TIMEOUT_MS } from "../openclaw-state-db-contract-DfPjvL0M.mjs"; import { a as setSqliteBusyTimeout } from "../sqlite-busy-timeout-BEDmnGR_.mjs"; import { r as readExistingAgentSchemaMeta } from "../openclaw-agent-db-metadata-C3YvwHLh.mjs"; import { t as withSqliteSourceReadDatabase } from "../sqlite-source-handle-DPuyLiZy.mjs"; import { a as withDatabaseEngineSelection } from "../context-DE59wyBs.mjs"; import { r as readSqliteIntegrityFileIdentity } from "../sqlite-file-generation-DHPWG9de.mjs"; import { r as cloneEnvWithPlatformSemantics } from "../config-env-vars-ByeGN-9N.mjs"; import { o as readAgentDatabaseSchemaVersion } from "../openclaw-agent-db-schema-read-U5-_81Kg.mjs"; import { a as withFreshOpenClawAgentDatabaseReadOnly } from "../openclaw-agent-db-readonly-open-BzFUagBt.mjs"; import { t as tryInspectSqliteReadOnlyInProcess } from "../sqlite-readonly-inspection-1c83pUn1.mjs"; import { n as serializeAgentSchemaInspectionError } from "../openclaw-agent-schema-inspection-response-Cd8G_meQ.mjs"; //#region 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-DKIj3f5z.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 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-DNmJyR2D.mjs"), import("../sqlite-maintenance-cache-BpqGi94d.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 })?.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); }); //#endregion export {};