UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

34 lines (33 loc) • 2.59 kB
import { n as isPostgresSqlConnection } from "./sql-connection-Beiyg5Dt.mjs"; import { a as executeSqliteQueryTakeFirstSync, i as executeSqliteQuerySync, s as getNodeSqliteKysely } from "./kysely-sync-YJo2lmGV.mjs"; import { r as ensureStatePostgresFragment } from "./openclaw-state-db-engine-sM0tpxNy.mjs"; import { t as createSqliteSchemaEnsurer } from "./sqlite-schema-ensure-B6yDrFvM.mjs"; import { t as getOpenClawStateFeatureSchemaSql } from "./openclaw-state-feature-schema-CEI_WUTe.mjs"; //#region src/audit/execution-owner-lifecycle-binding-store.ts const EXECUTION_OWNER_LIFECYCLE_BINDING_TABLE = "execution_owner_lifecycle_bindings"; /** Only an enabled binding write allocates this existing optional table. */ const ensureNativeExecutionOwnerLifecycleBindingSchema = createSqliteSchemaEnsurer(() => getOpenClawStateFeatureSchemaSql(EXECUTION_OWNER_LIFECYCLE_BINDING_TABLE), { tables: [EXECUTION_OWNER_LIFECYCLE_BINDING_TABLE] }); function ensureExecutionOwnerLifecycleBindingSchema(e) { if (isPostgresSqlConnection(e)) ensureStatePostgresFragment(e, EXECUTION_OWNER_LIFECYCLE_BINDING_TABLE); else ensureNativeExecutionOwnerLifecycleBindingSchema(e); } /** The first admitted execution owns this diagnostic link for the receipt's lifetime. */ function bindExecutionOwnerLifecycleMetadata(e) { const t = getNodeSqliteKysely(e.db); const n = executeSqliteQuerySync(e.db, t.insertInto(EXECUTION_OWNER_LIFECYCLE_BINDING_TABLE).values({ owner_kind: e.ownerKind, owner_id: e.ownerId, context_id: e.binding.contextId, execution_id: e.binding.executionId }).onConflict((e) => e.columns(["owner_kind", "owner_id"]).doNothing())); if (Number(n.numAffectedRows ?? 0n) === 1) return "bound"; const r = executeSqliteQueryTakeFirstSync(e.db, t.selectFrom(EXECUTION_OWNER_LIFECYCLE_BINDING_TABLE).select(["context_id", "execution_id"]).where("owner_kind", "=", e.ownerKind).where("owner_id", "=", e.ownerId)); return r?.context_id === e.binding.contextId && r.execution_id === e.binding.executionId ? "already-bound" : "mismatch"; } /** Removes exact owner metadata without allocating the opt-in table. */ function deleteExecutionOwnerLifecycleMetadata(e) { if (e.ownerIds.length === 0 || !e.executionOwnerLifecycleBindings) return; executeSqliteQuerySync(e.db, getNodeSqliteKysely(e.db).deleteFrom(EXECUTION_OWNER_LIFECYCLE_BINDING_TABLE).where("owner_kind", "=", e.ownerKind).where("owner_id", "in", e.ownerIds)); } //#endregion export { deleteExecutionOwnerLifecycleMetadata as n, ensureExecutionOwnerLifecycleBindingSchema as r, bindExecutionOwnerLifecycleMetadata as t };