openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
82 lines (81 loc) • 4.59 kB
JavaScript
import { a as getOrLoadSqliteDatabaseAdmissionForPath } from "./sqlite-database-admission-DQIqro3d.mjs";
import { f as withExistingOpenClawStateDatabaseArtifactPreservingReadOnlyAsync } from "./openclaw-state-db-readonly-B6YHb1oF.mjs";
import { _ as nextDeliveryQueueTombstoneExpiryAdmission, g as isDeliveryQueueTombstonePruneDue, h as failedDeliveryQueueHealthAdmission } from "./delivery-queue-sqlite.types-B7uW265Q.mjs";
import { i as runOpenClawStateWorkerOperation } from "./openclaw-state-worker-store-2LoAv_8B.mjs";
import { r as openOpenClawStateDatabase } from "./openclaw-state-db-ARhwdPJg.mjs";
import { d as loadDeliveryQueueEntriesInDatabase, f as prepareDeliveryQueueTerminalEntry, h as terminalizePendingDeliveryQueueEntryInDatabase, i as countPendingDeliveryQueueEntriesInDatabase } from "./delivery-queue-sqlite.kernel-Cv08QjUU.mjs";
import { n as resolveDeliveryQueueStateEnv, t as captureDeliveryQueueStateContext } from "./delivery-queue-state-context-Cxp-xMAQ.mjs";
//#region src/infra/delivery-queue-worker-store.ts
async function executeDeliveryQueueOperation(e, t, n, r) {
const i = e ?? captureDeliveryQueueStateContext(t);
return await runOpenClawStateWorkerOperation(i.workerContext, (e) => e.execute(n), r);
}
//#endregion
//#region src/infra/delivery-queue-sqlite.ts
function openStateDatabase(e, t) {
return openOpenClawStateDatabase({ env: resolveDeliveryQueueStateEnv(e, t) });
}
/** Select receipt and pending custody together, preserving bounded receipt expiry. */
async function inspectDeliveryQueueReceipt(e, t, n, r) {
const i = await executeDeliveryQueueOperation(r, void 0, {
type: "deliveryQueue.inspectReceipt",
input: {
queueName: e,
id: t,
includePending: n
}
});
r.workerContext.admission.assertCurrent();
return i;
}
/** Load all pending entries for a queue namespace in database order. */
function loadDeliveryQueueEntries(e, t) {
return loadDeliveryQueueEntriesInDatabase(openStateDatabase(t), e);
}
/** Count dead-lettered entries per queue namespace for coarse health reporting. */
async function countFailedDeliveryQueueEntries(e, t) {
const n = t ?? captureDeliveryQueueStateContext(e);
const r = getOrLoadSqliteDatabaseAdmissionForPath(n.workerContext.admission.databasePath, failedDeliveryQueueHealthAdmission, () => void 0);
if (r !== void 0) return r;
return executeDeliveryQueueOperation(n, void 0, {
type: "deliveryQueue.countFailed",
input: void 0
});
}
/** Count pending entries across an exact set of queue namespaces. */
async function countPendingDeliveryQueueEntries(e, t, n) {
if (e.length === 0) return 0;
const r = n ?? captureDeliveryQueueStateContext(t);
const i = await executeDeliveryQueueOperation(r, void 0, {
type: "deliveryQueue.countPending",
input: { queueNames: [...e] }
});
r.workerContext.admission.assertCurrent();
return i;
}
/** Doctor's offline migration retains its admitted native database owner. */
function countPendingDeliveryQueueEntriesForMaintenance(e, t, n) {
if (e.length === 0) return 0;
return countPendingDeliveryQueueEntriesInDatabase(openStateDatabase(t, n), e);
}
/** Inventory retired custody without opening a writer or creating state. */
async function countPendingDeliveryQueueEntriesReadOnly(e, t = process.env) {
return await withExistingOpenClawStateDatabaseArtifactPreservingReadOnlyAsync((t) => countPendingDeliveryQueueEntriesInDatabase(t, e), { env: t }) ?? 0;
}
/** Physically expire age-bounded delivery queue tombstones. */
async function pruneExpiredDeliveryQueueTombstones(e, t) {
const n = t ?? captureDeliveryQueueStateContext(e);
const r = getOrLoadSqliteDatabaseAdmissionForPath(n.workerContext.admission.databasePath, nextDeliveryQueueTombstoneExpiryAdmission, () => void 0);
if (!isDeliveryQueueTombstonePruneDue(r, Date.now())) return;
await executeDeliveryQueueOperation(n, void 0, {
type: "deliveryQueue.pruneTombstones",
input: void 0
});
}
/** Atomically delete or tombstone a pending row only while its value is unchanged. */
function terminalizePendingDeliveryQueueEntry(e, t) {
const n = prepareDeliveryQueueTerminalEntry(e);
return terminalizePendingDeliveryQueueEntryInDatabase(openStateDatabase(e.stateDir, t), n);
}
//#endregion
export { inspectDeliveryQueueReceipt as a, terminalizePendingDeliveryQueueEntry as c, countPendingDeliveryQueueEntriesReadOnly as i, executeDeliveryQueueOperation as l, countPendingDeliveryQueueEntries as n, loadDeliveryQueueEntries as o, countPendingDeliveryQueueEntriesForMaintenance as r, pruneExpiredDeliveryQueueTombstones as s, countFailedDeliveryQueueEntries as t };