openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
71 lines (70 loc) • 2.46 kB
JavaScript
import { a as deferSqliteWorkerCommitReceipt } from "./sqlite-worker-operation-settlement-OZQM-wtd.mjs";
import "./sqlite-worker-operation-admission-9E_X-oRy.mjs";
import { a as getSqliteWorkerStateContext } from "./sqlite-worker-state-context-CR8h__Vh.mjs";
import { l as runOpenClawStateWriteTransaction } from "./openclaw-state-db-ARhwdPJg.mjs";
import { A as withDevicePairingStoreDatabase, I as withDevicePairingMutationAdmission, O as readPairedDevicePairingSnapshotFromDatabase, l as resolveNodePairingState } from "./device-pairing-identity-BqPJxbIo.mjs";
//#region src/infra/device-pairing-binding.ts
function prepareDevicePairingBinding(e, t) {
const n = resolveNodePairingState(t);
return {
deviceId: e,
device: t,
binding: n ? {
identity: n.identity.key,
...n.generation ? { generation: n.generation.key } : {}
} : null
};
}
//#endregion
//#region src/infra/device-pairing-dispatch.worker.ts
function devicePairingMutation(e, { publishPairing: t = true, pairedDeviceId: n } = {}) {
return (r, { open: i }) => {
const a = i();
return runOpenClawStateWriteTransaction(() => withDevicePairingMutationAdmission(() => {
const i = t ? readPairedDevicePairingSnapshotFromDatabase(a.db, n?.(r).trim()) : void 0;
const o = i?.pairedByDeviceId;
const s = o ? structuredClone(o) : void 0;
const c = { value: i?.revision ?? "0" };
return withDevicePairingStoreDatabase(a, () => {
let t;
let n;
let l;
let u;
const d = e(r, {
database: a,
recordTokenReplacement: (e) => {
t = e;
},
recordWorkerEnvironment: (e) => {
n = e;
},
recordRetiredNodeToken: (e) => {
u = e;
},
recordNodeApproval: (e) => {
l = e;
}
});
if (!o || !s) return d;
const f = [];
for (const e of /* @__PURE__ */ new Set([...Object.keys(o), ...Object.keys(s)])) if (JSON.stringify(o[e]) !== JSON.stringify(s[e])) f.push(prepareDevicePairingBinding(e, s[e] ?? null));
deferSqliteWorkerCommitReceipt(a.db, {
kind: "devicePairing",
beforeRevision: i.revision,
revision: c.value,
changed: f,
...t ? { tokensReplaced: t } : {},
...u ? { retiredNodeToken: u } : {},
...n ? { workerEnvironment: n } : {},
...l ? { nodeApproval: l } : {}
});
return d;
}, s, c);
}), {
database: a,
env: getSqliteWorkerStateContext().environment
});
};
}
//#endregion
export { devicePairingMutation as t };