UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

4 lines • 2.6 kB
import{o as getAsyncWorkSignal}from"./async-work-scope-DBcxYU4O.mjs";import{n as runtimeProcessEntrypoints}from"./runtime-process-entrypoints-Dnd1WskT.mjs";import{a as resolveRuntimeWorkerUrl}from"./runtime-worker-url-Dqf-I1cs.mjs";import{n as captureRuntimeWorkerSource}from"./runtime-worker-generation-0fwjR0Cv.mjs";import{a as resolveSqliteInspectionSignal}from"./sqlite-readonly-worker-context-BjXXEC4m.mjs";import{t as WorkerTaskPool}from"./worker-task-pool-Bg54sSAN.mjs";import{n as getPostgresPool}from"./pool-D39jfLRL.mjs";import{t as captureSqliteWorkerStateContext}from"./sqlite-worker-state-context-DJ4guxKh.mjs";import{n as captureOpenClawStateReadWorkerContext}from"./openclaw-state-worker-context-Dx8YjqO2.mjs";import{a as resolveCommandProcessSignal}from"./exec-spawn-DNCbDcyJ.mjs";import{t as BLOAT_MIN_FILE_BYTES}from"./doctor-db-bloat.constants-O_-hwSpG.mjs";import{t as note}from"./note-e4DtVgg2.mjs";import{n as formatBytes}from"./doctor-disk-space-wOo27Exa.mjs"; //!src/commands/doctor-db-bloat.ts const BLOAT_MIN_FREE_BYTES=33554432;const BLOAT_FREE_RATIO=.25;const LARGE_DB_WARN_BYTES=1073741824;function describeBloat(e,t){const n=t.fileBytes>0?t.freeBytes/t.fileBytes:0;if(t.fileBytes>=134217728&&t.freeBytes>=BLOAT_MIN_FREE_BYTES&&n>=BLOAT_FREE_RATIO){const n=t.incrementalAutoVacuum?`incremental vacuum will release it gradually`:`use offline Doctor SQLite compaction to reclaim it and enable incremental vacuum (gateway stopped; see https://docs.openclaw.ai/cli/doctor/sqlite-maintenance)`;return`${e}: ${formatBytes(t.fileBytes)} on disk with ${formatBytes(t.freeBytes)} reclaimable free pages; ${n}.`}if(t.fileBytes>=LARGE_DB_WARN_BYTES)return`${e}: ${formatBytes(t.fileBytes)} on disk; review session/transcript retention settings if growth is unexpected.`;return null}async function noteSqliteDatabaseBloat(e){const t=captureOpenClawStateReadWorkerContext({env:e?.env});if(Object.values(t.databaseEngineSelection?.effectiveEngines??{}).includes(`postgres`))getPostgresPool();const n=new WorkerTaskPool({workerUrl:captureRuntimeWorkerSource(resolveRuntimeWorkerUrl(runtimeProcessEntrypoints.doctorDatabaseBloat)).moduleUrl,maxWorkers:1});let r;try{r=await n.run({path:t.admission.databasePath,context:captureSqliteWorkerStateContext(t)},{signal:resolveCommandProcessSignal(resolveSqliteInspectionSignal(getAsyncWorkSignal()))})}finally{await n.close()}t.admission.assertCurrent();const i=(r??[]).flatMap(({label:e,stats:t})=>{const n=describeBloat(e,t);return n?[n]:[]});if(i.length===0)return;note(i.join(` `),`SQLite database size`)}export{noteSqliteDatabaseBloat};