UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

64 lines (63 loc) • 2.17 kB
import { s as asFiniteNumber } from "./number-coercion-D6u-4YD8.mjs"; import { a as SqliteSnapshotCleanupError } from "./sqlite-lifecycle-errors-D8BU4VLa.mjs"; import { r as withArtifactPreservingStateReads } from "./artifact-preserving-state-reads-BfhmBr-V.mjs"; import { a as prepareSqliteReadOnlyLocationSync } from "./sqlite-snapshot-source-Q9S7_uQN.mjs"; import "./openclaw-state-db-readonly-B6YHb1oF.mjs"; import { r as openOpenClawStateReadConnection } from "./openclaw-state-db-read-connection-DoTwzEPO.mjs"; import { p as readRegisteredAgentDatabases } from "./openclaw-agent-db-registry-listing-CbXBL50a.mjs"; import { t as BLOAT_MIN_FILE_BYTES } from "./doctor-db-bloat.constants-Cx5qGUKb.mjs"; import fs from "node:fs"; //#region src/commands/doctor-db-bloat.read.ts function readSqliteBloatStats(e) { let t; try { t = fs.statSync(e, { throwIfNoEntry: false })?.size ?? 0; } catch { return null; } if (t < 134217728) return null; let n; try { n = openOpenClawStateReadConnection(e, prepareSqliteReadOnlyLocationSync(e)); const r = n.database.db; const i = readPragmaNumber(r, "page_size") ?? 4096; const a = readPragmaNumber(r, "freelist_count") ?? 0; const o = readPragmaNumber(r, "auto_vacuum") ?? 0; return { fileBytes: t, freeBytes: a * i, incrementalAutoVacuum: o === 2 }; } catch (e) { if (e instanceof SqliteSnapshotCleanupError) throw e; return null; } finally { n?.close(); } } function readPragmaNumber(e, t) { const n = e.prepare(`PRAGMA ${t}`).get(); return asFiniteNumber(n?.[t]) ?? null; } function readSqliteDatabaseBloat(e) { const t = []; const n = readSqliteBloatStats(e.path); if (n) t.push({ label: "state DB", stats: n }); const r = withArtifactPreservingStateReads(() => readRegisteredAgentDatabases(e, false)); for (const e of r) { const n = readSqliteBloatStats(e.path); if (n) t.push({ label: `agent DB (${e.agentId})`, stats: n }); } return t; } //#endregion //#region src/commands/doctor-state.worker.ts const doctorOperations = { "doctor.databaseBloat": (e, { stateOptions: t }) => readSqliteDatabaseBloat(t()) }; //#endregion export { doctorOperations };