UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

41 lines (40 loc) • 2.21 kB
import { n as readSqliteBusyTimeout } from "./sqlite-busy-timeout-D3v1uB5d.mjs"; import { c as withSqlitePostCommitPublications } from "./sqlite-post-commit-DENvzR6w.mjs"; import { i as runSqliteImmediateTransaction } from "./sqlite-transaction-DBRLvCDM.mjs"; import { r as cloneEnvWithPlatformSemantics } from "./config-env-vars-BzUE_dOh.mjs"; import { v as assertAgentDeletionDatabaseCleanupAccess, x as getAgentDeletionDatabaseCleanup } from "./agent-deletion-journal-DkfGlzu8.mjs"; import { i as getOpenClawAgentDatabaseIfOpen, o as openOpenClawAgentDatabase } from "./openclaw-agent-db-DWI9Bgur.mjs"; import { S as retainAgentDatabase, t as cache } from "./openclaw-agent-db-lifecycle-C9dal1XJ.mjs"; import { s as ensureOpenClawAgentDatabasePermissions } from "./openclaw-agent-db-schema-CppMSzFp.mjs"; //#region src/state/openclaw-agent-db-transaction.ts /** Yield only for BEGIN admission; admitted writes and publications are never replayed. */ async function runOpenClawAgentWriteWithYieldingAdmission(operation, options, transactionOptions = {}) { const captured = { ...options, env: cloneEnvWithPlatformSemantics(options.env ?? process.env) }; const database = openOpenClawAgentDatabase(captured); captured.path = database.path; const release = retainAgentDatabase(database.db); try { return await runSqliteImmediateTransaction(database.db, async () => () => { assertAgentDeletionDatabaseCleanupAccess(database, captured); const result = operation(database); if (!cache.incognito.has(database)) ensureOpenClawAgentDatabasePermissions(database.path, captured); return result; }, { ...transactionOptions, busyTimeoutMs: readSqliteBusyTimeout(database.db), databaseLabel: database.path, operationLabel: transactionOptions.operationLabel ?? "agent.write", withCommit: getAgentDeletionDatabaseCleanup(captured)?.withCommit }, (write) => { if (getOpenClawAgentDatabaseIfOpen(captured) !== database) throw new Error(`Agent database closed or replaced before write: ${database.path}`); return withSqlitePostCommitPublications(database.db, write); }); } finally { release(); } } //#endregion export { runOpenClawAgentWriteWithYieldingAdmission as t };