@camstack/server 1.2.897 → 1.2.898
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/package.json +17 -10
- package/system/dist/addon-runner.js +103 -12
- package/system/dist/addon-runner.mjs +103 -12
- package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +1 -1
- package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +1 -1
- package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +1 -1
- package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +1 -1
- package/system/dist/builtins/alerts/alerts.addon.js +1 -1
- package/system/dist/builtins/alerts/alerts.addon.mjs +1 -1
- package/system/dist/builtins/autotrack/index.js +1 -1
- package/system/dist/builtins/autotrack/index.mjs +1 -1
- package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +2 -2
- package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +2 -2
- package/system/dist/builtins/calendars/calendars.addon.js +1 -1
- package/system/dist/builtins/calendars/calendars.addon.mjs +1 -1
- package/system/dist/builtins/camera-grid/index.js +1 -1
- package/system/dist/builtins/camera-grid/index.mjs +1 -1
- package/system/dist/builtins/composer/composer.addon.js +14 -11
- package/system/dist/builtins/composer/composer.addon.mjs +11 -8
- package/system/dist/builtins/console-logging/index.js +1 -1
- package/system/dist/builtins/console-logging/index.mjs +1 -1
- package/system/dist/builtins/core-blocks/core-blocks.addon.js +170 -14
- package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +169 -13
- package/system/dist/builtins/core-blocks/migrations/automation-confirmed-view.d.ts +23 -0
- package/system/dist/builtins/core-blocks/migrations/index.d.ts +1 -0
- package/system/dist/builtins/core-blocks/migrations/pump-cycle-split.d.ts +1 -0
- package/system/dist/builtins/device-history/device-history.addon.js +10 -9
- package/system/dist/builtins/device-history/device-history.addon.mjs +10 -9
- package/system/dist/builtins/device-manager/command-holds-wiring.d.ts +22 -0
- package/system/dist/builtins/device-manager/command-holds.d.ts +75 -0
- package/system/dist/builtins/device-manager/device-manager.addon.d.ts +2 -0
- package/system/dist/builtins/device-manager/device-manager.addon.js +381 -26
- package/system/dist/builtins/device-manager/device-manager.addon.mjs +378 -27
- package/system/dist/builtins/device-manager/device-state-mirror.d.ts +35 -9
- package/system/dist/builtins/hub-forwarder/index.js +1 -1
- package/system/dist/builtins/hub-forwarder/index.mjs +1 -1
- package/system/dist/builtins/keychain/index.js +4 -4
- package/system/dist/builtins/keychain/index.mjs +4 -4
- package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.js +1 -1
- package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +1 -1
- package/system/dist/builtins/local-auth/local-auth.addon.js +2 -2
- package/system/dist/builtins/local-auth/local-auth.addon.mjs +2 -2
- package/system/dist/builtins/local-network/local-network.addon.js +3 -3
- package/system/dist/builtins/local-network/local-network.addon.mjs +3 -3
- package/system/dist/builtins/loki-logging/index.js +1 -1
- package/system/dist/builtins/loki-logging/index.mjs +1 -1
- package/system/dist/builtins/native-metrics/native-metrics.addon.js +1 -1
- package/system/dist/builtins/native-metrics/native-metrics.addon.mjs +1 -1
- package/system/dist/builtins/platform-probe/index.js +1 -1
- package/system/dist/builtins/platform-probe/index.mjs +1 -1
- package/system/dist/builtins/record-entries/index.js +1 -1
- package/system/dist/builtins/record-entries/index.mjs +1 -1
- package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +1 -1
- package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
- package/system/dist/builtins/shared/device-state-changed.d.ts +8 -0
- package/system/dist/builtins/snapshot/index.js +1 -1
- package/system/dist/builtins/snapshot/index.mjs +1 -1
- package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.js +1 -1
- package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +1 -1
- package/system/dist/builtins/sqlite-storage/index.js +1 -1
- package/system/dist/builtins/sqlite-storage/index.mjs +1 -1
- package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.js +3 -3
- package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +3 -3
- package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +1 -1
- package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +1 -1
- package/system/dist/builtins/system-config/system-config.addon.js +3 -3
- package/system/dist/builtins/system-config/system-config.addon.mjs +3 -3
- package/system/dist/builtins/winston-logging/index.js +1 -1
- package/system/dist/builtins/winston-logging/index.mjs +1 -1
- package/system/dist/{capture-engine-D1rjl2dW.js → capture-engine-BWS0KTbm.js} +48 -1
- package/system/dist/{capture-engine-Bjgs__i9.mjs → capture-engine-DBQDaDxJ.mjs} +37 -2
- package/system/dist/{composition-sources-CF2-u58e.js → composition-sources-CDOW1dnY.js} +1 -32
- package/system/dist/{composition-sources-B727nlA0.mjs → composition-sources-CGUWmf-T.mjs} +2 -21
- package/system/dist/{constants-BF309c_I.mjs → constants-BmrLkwZs.mjs} +1 -1
- package/system/dist/{constants-DaR1SUh7.js → constants-BwrRoq-j.js} +1 -1
- package/system/dist/{device-ca-DT1hYtdW.mjs → device-ca-BGgZXEto.mjs} +1 -1
- package/system/dist/{device-ca-BqcX5_f2.js → device-ca-DiuwWyZY.js} +1 -1
- package/system/dist/{dist-BoEy9sm9.js → dist-CCd8IeIU.js} +685 -53
- package/system/dist/{dist-DorY_sjS.mjs → dist-D7t8wLTF.mjs} +674 -54
- package/system/dist/file-host-worker.js +1 -1
- package/system/dist/file-host-worker.mjs +1 -1
- package/system/dist/{hub-identity-CZ0nE3GK.mjs → hub-identity-BohJeqdO.mjs} +1 -1
- package/system/dist/{hub-identity-DH1rxUMD.js → hub-identity-G_ZdyPpc.js} +1 -1
- package/system/dist/{hub-mdns-ciao-N0nL34fx.js → hub-mdns-ciao-CKD4EgkG.js} +2 -2
- package/system/dist/{hub-mdns-ciao-7HK57Vtx.mjs → hub-mdns-ciao-D5RxSMrH.mjs} +2 -2
- package/system/dist/index.js +45 -13
- package/system/dist/index.mjs +46 -14
- package/system/dist/kernel/command-hold-overrides.d.ts +42 -0
- package/system/dist/kernel/moleculer/child-cap-descriptors.d.ts +3 -0
- package/system/dist/kernel/moleculer/device-cap-proxy.d.ts +2 -1
- package/system/dist/kernel/transport/child-cap-protocol.d.ts +6 -1
- package/system/dist/{legacy-integration-rows-door-BTfeULYt.js → legacy-integration-rows-door-BgCl68ek.js} +1 -1
- package/system/dist/{legacy-integration-rows-door-CdAQlIvv.mjs → legacy-integration-rows-door-Rm9JmIsl.mjs} +1 -1
- package/system/dist/{rename-composition-block-B1x-yK5U.js → rename-composition-block-2Z2ED7Og.js} +1 -1
- package/system/dist/{rename-composition-block-CIQjxBUa.mjs → rename-composition-block-DNO3mNEO.mjs} +1 -1
- package/system/dist/{restore-archive-Bj_gYmE9.mjs → restore-archive-2L5TymvF.mjs} +1 -1
- package/system/dist/{restore-archive-B086o8pL.js → restore-archive-CZkQO8t3.js} +1 -1
- package/system/dist/{wal-maintenance-Dgfmi-Ao.mjs → wal-maintenance-BMYe_n18.mjs} +0 -0
- package/system/dist/{wal-maintenance-MVIyxmu7.js → wal-maintenance-YjDJ73Qd.js} +0 -0
- package/system/package.json +1 -1
|
@@ -3,10 +3,10 @@ Object.defineProperties(exports, {
|
|
|
3
3
|
[Symbol.toStringTag]: { value: "Module" }
|
|
4
4
|
});
|
|
5
5
|
const require_chunk = require("../../chunk-Cek0wNdY.js");
|
|
6
|
-
const require_dist = require("../../dist-
|
|
6
|
+
const require_dist = require("../../dist-CCd8IeIU.js");
|
|
7
7
|
const require_read_all_rows$1 = require("../../read-all-rows-CVoO1ONM.js");
|
|
8
8
|
const require_log_redactor = require("../../log-redactor-BhIEMaG9.js");
|
|
9
|
-
const require_rename_composition_block = require("../../rename-composition-block-
|
|
9
|
+
const require_rename_composition_block = require("../../rename-composition-block-2Z2ED7Og.js");
|
|
10
10
|
const require_prefix_range = require("../../prefix-range-D_KueXbQ.js");
|
|
11
11
|
const require_prefix_walk = require("../../prefix-walk-Dv6MLZlM.js");
|
|
12
12
|
const require_retired_settings_keys = require("../../retired-settings-keys-C8nOOr5H.js");
|
|
@@ -12097,6 +12097,201 @@ var MirrorRowWriter = class MirrorRowWriter {
|
|
|
12097
12097
|
}
|
|
12098
12098
|
};
|
|
12099
12099
|
//#endregion
|
|
12100
|
+
//#region src/builtins/device-manager/command-holds.ts
|
|
12101
|
+
function same(a, b) {
|
|
12102
|
+
return Object.is(a, b);
|
|
12103
|
+
}
|
|
12104
|
+
/** Does `reading` confirm `held`: equal, or a number within its tolerance? */
|
|
12105
|
+
function confirms(reading, held, tolerance) {
|
|
12106
|
+
if (same(reading, held)) return true;
|
|
12107
|
+
if (typeof reading !== "number" || typeof held !== "number" || tolerance <= 0) return false;
|
|
12108
|
+
return Math.abs(reading - held) <= tolerance + 1e-9;
|
|
12109
|
+
}
|
|
12110
|
+
function judge(reading, held) {
|
|
12111
|
+
if (confirms(reading, held.value, held.tolerance)) return "confirmed";
|
|
12112
|
+
if (held.stale.some((v) => same(v, reading))) return "stale";
|
|
12113
|
+
return "device-answered";
|
|
12114
|
+
}
|
|
12115
|
+
var CommandHolds = class {
|
|
12116
|
+
deps;
|
|
12117
|
+
/** device → cap → field → held value. */
|
|
12118
|
+
held = /* @__PURE__ */ new Map();
|
|
12119
|
+
armings = /* @__PURE__ */ new Map();
|
|
12120
|
+
seq = 0;
|
|
12121
|
+
constructor(deps) {
|
|
12122
|
+
this.deps = deps;
|
|
12123
|
+
}
|
|
12124
|
+
/**
|
|
12125
|
+
* Hold what a command leads to. A field the slice already holds is not held
|
|
12126
|
+
* (and a standing hold on it is dropped: the newer command wins). Returns the
|
|
12127
|
+
* token that `release` takes, or `null` when nothing is held.
|
|
12128
|
+
*/
|
|
12129
|
+
arm(request) {
|
|
12130
|
+
const base = this.deps.baseSlice(request.deviceId, request.capName);
|
|
12131
|
+
if (base === null) {
|
|
12132
|
+
this.deps.logger.debug("command hold: the cap has no slice yet — nothing held", {
|
|
12133
|
+
tags: { deviceId: request.deviceId },
|
|
12134
|
+
meta: {
|
|
12135
|
+
cap: request.capName,
|
|
12136
|
+
method: request.method
|
|
12137
|
+
}
|
|
12138
|
+
});
|
|
12139
|
+
return null;
|
|
12140
|
+
}
|
|
12141
|
+
this.seq += 1;
|
|
12142
|
+
const token = this.seq;
|
|
12143
|
+
const fields = this.fieldsOf(request.deviceId, request.capName);
|
|
12144
|
+
let changed = false;
|
|
12145
|
+
let holding = false;
|
|
12146
|
+
for (const effect of request.effects) {
|
|
12147
|
+
const standing = fields.get(effect.field);
|
|
12148
|
+
const tolerance = effect.tolerance ?? 0;
|
|
12149
|
+
const reported = Object.hasOwn(base, effect.field) ? base[effect.field] : void 0;
|
|
12150
|
+
if (Object.hasOwn(base, effect.field) && confirms(reported, effect.value, tolerance)) {
|
|
12151
|
+
if (standing !== void 0) {
|
|
12152
|
+
fields.delete(effect.field);
|
|
12153
|
+
changed = true;
|
|
12154
|
+
}
|
|
12155
|
+
continue;
|
|
12156
|
+
}
|
|
12157
|
+
if (standing === void 0 || !same(standing.value, effect.value)) changed = true;
|
|
12158
|
+
const stale = standing === void 0 ? [reported] : [...standing.stale, standing.value];
|
|
12159
|
+
fields.set(effect.field, {
|
|
12160
|
+
value: effect.value,
|
|
12161
|
+
tolerance,
|
|
12162
|
+
stale,
|
|
12163
|
+
token
|
|
12164
|
+
});
|
|
12165
|
+
holding = true;
|
|
12166
|
+
}
|
|
12167
|
+
this.dropEmpty(request.deviceId, request.capName);
|
|
12168
|
+
this.forgetStaleArmings();
|
|
12169
|
+
if (holding) {
|
|
12170
|
+
const timer = setTimeout(() => this.release(token, "unconfirmed"), request.holdMs);
|
|
12171
|
+
timer.unref?.();
|
|
12172
|
+
this.armings.set(token, {
|
|
12173
|
+
token,
|
|
12174
|
+
deviceId: request.deviceId,
|
|
12175
|
+
capName: request.capName,
|
|
12176
|
+
method: request.method,
|
|
12177
|
+
holdMs: request.holdMs,
|
|
12178
|
+
timer
|
|
12179
|
+
});
|
|
12180
|
+
}
|
|
12181
|
+
if (changed) this.deps.reemit(request.deviceId, request.capName);
|
|
12182
|
+
return holding ? token : null;
|
|
12183
|
+
}
|
|
12184
|
+
/** End what `token` still holds — refused at once, or unconfirmed at the limit. */
|
|
12185
|
+
release(token, reason) {
|
|
12186
|
+
const arming = this.armings.get(token);
|
|
12187
|
+
if (arming === void 0) return;
|
|
12188
|
+
this.armings.delete(token);
|
|
12189
|
+
clearTimeout(arming.timer);
|
|
12190
|
+
const fields = this.held.get(arming.deviceId)?.get(arming.capName);
|
|
12191
|
+
if (fields === void 0) return;
|
|
12192
|
+
const dropped = [];
|
|
12193
|
+
for (const [field, held] of fields) {
|
|
12194
|
+
if (held.token !== token) continue;
|
|
12195
|
+
fields.delete(field);
|
|
12196
|
+
dropped.push(field);
|
|
12197
|
+
}
|
|
12198
|
+
if (dropped.length === 0) return;
|
|
12199
|
+
this.dropEmpty(arming.deviceId, arming.capName);
|
|
12200
|
+
const tags = { deviceId: arming.deviceId };
|
|
12201
|
+
const meta = {
|
|
12202
|
+
cap: arming.capName,
|
|
12203
|
+
method: arming.method,
|
|
12204
|
+
fields: dropped
|
|
12205
|
+
};
|
|
12206
|
+
if (reason === "unconfirmed" && arming.holdMs <= 1e4) this.deps.logger.debug("one-shot command hold ended", {
|
|
12207
|
+
tags,
|
|
12208
|
+
meta
|
|
12209
|
+
});
|
|
12210
|
+
else if (reason === "unconfirmed") this.deps.logger.warn("command hold reverted: the device did not confirm in time", {
|
|
12211
|
+
tags,
|
|
12212
|
+
meta
|
|
12213
|
+
});
|
|
12214
|
+
else this.deps.logger.info("command hold rolled back: the command was refused", {
|
|
12215
|
+
tags,
|
|
12216
|
+
meta
|
|
12217
|
+
});
|
|
12218
|
+
this.deps.reemit(arming.deviceId, arming.capName);
|
|
12219
|
+
}
|
|
12220
|
+
/**
|
|
12221
|
+
* The slice under the hold moved: keep each held field it still reports
|
|
12222
|
+
* stale, drop the ones it confirms or answers otherwise.
|
|
12223
|
+
*/
|
|
12224
|
+
settle(deviceId, capName, base) {
|
|
12225
|
+
const fields = this.held.get(deviceId)?.get(capName);
|
|
12226
|
+
if (fields === void 0) return;
|
|
12227
|
+
for (const [field, held] of fields) {
|
|
12228
|
+
if (!Object.hasOwn(base, field)) continue;
|
|
12229
|
+
const reading = judge(base[field], held);
|
|
12230
|
+
if (reading === "stale") continue;
|
|
12231
|
+
fields.delete(field);
|
|
12232
|
+
if (reading === "device-answered") this.deps.logger.debug("command hold released: the device answered otherwise", {
|
|
12233
|
+
tags: { deviceId },
|
|
12234
|
+
meta: {
|
|
12235
|
+
cap: capName,
|
|
12236
|
+
field,
|
|
12237
|
+
reason: reading
|
|
12238
|
+
}
|
|
12239
|
+
});
|
|
12240
|
+
}
|
|
12241
|
+
this.dropEmpty(deviceId, capName);
|
|
12242
|
+
this.forgetStaleArmings();
|
|
12243
|
+
}
|
|
12244
|
+
/** `base` with the held values over it; `base` itself when nothing is held. */
|
|
12245
|
+
overlay(deviceId, capName, base) {
|
|
12246
|
+
const fields = this.held.get(deviceId)?.get(capName);
|
|
12247
|
+
if (fields === void 0 || fields.size === 0) return base;
|
|
12248
|
+
const out = { ...base };
|
|
12249
|
+
for (const [field, held] of fields) out[field] = held.value;
|
|
12250
|
+
return out;
|
|
12251
|
+
}
|
|
12252
|
+
/** Is any field of the cap held? */
|
|
12253
|
+
isHolding(deviceId, capName) {
|
|
12254
|
+
return (this.held.get(deviceId)?.get(capName)?.size ?? 0) > 0;
|
|
12255
|
+
}
|
|
12256
|
+
/** Forget a removed device's holds. */
|
|
12257
|
+
clearDevice(deviceId) {
|
|
12258
|
+
this.held.delete(deviceId);
|
|
12259
|
+
for (const [token, arming] of this.armings) {
|
|
12260
|
+
if (arming.deviceId !== deviceId) continue;
|
|
12261
|
+
clearTimeout(arming.timer);
|
|
12262
|
+
this.armings.delete(token);
|
|
12263
|
+
}
|
|
12264
|
+
}
|
|
12265
|
+
/** Stop every timer (shutdown). */
|
|
12266
|
+
dispose() {
|
|
12267
|
+
for (const arming of this.armings.values()) clearTimeout(arming.timer);
|
|
12268
|
+
this.armings.clear();
|
|
12269
|
+
this.held.clear();
|
|
12270
|
+
}
|
|
12271
|
+
fieldsOf(deviceId, capName) {
|
|
12272
|
+
const perCap = this.held.get(deviceId) ?? /* @__PURE__ */ new Map();
|
|
12273
|
+
this.held.set(deviceId, perCap);
|
|
12274
|
+
const fields = perCap.get(capName) ?? /* @__PURE__ */ new Map();
|
|
12275
|
+
perCap.set(capName, fields);
|
|
12276
|
+
return fields;
|
|
12277
|
+
}
|
|
12278
|
+
dropEmpty(deviceId, capName) {
|
|
12279
|
+
const perCap = this.held.get(deviceId);
|
|
12280
|
+
if (perCap === void 0) return;
|
|
12281
|
+
if ((perCap.get(capName)?.size ?? 0) === 0) perCap.delete(capName);
|
|
12282
|
+
if (perCap.size === 0) this.held.delete(deviceId);
|
|
12283
|
+
}
|
|
12284
|
+
/** An arming whose fields were all confirmed or replaced holds nothing: stop its timer. */
|
|
12285
|
+
forgetStaleArmings() {
|
|
12286
|
+
for (const [token, arming] of this.armings) {
|
|
12287
|
+
const fields = this.held.get(arming.deviceId)?.get(arming.capName);
|
|
12288
|
+
if (fields !== void 0 && [...fields.values()].some((f) => f.token === token)) continue;
|
|
12289
|
+
clearTimeout(arming.timer);
|
|
12290
|
+
this.armings.delete(token);
|
|
12291
|
+
}
|
|
12292
|
+
}
|
|
12293
|
+
};
|
|
12294
|
+
//#endregion
|
|
12100
12295
|
//#region src/builtins/device-manager/device-state-mirror.ts
|
|
12101
12296
|
/**
|
|
12102
12297
|
* Hub-side runtime-state mirror for the device-manager addon.
|
|
@@ -12145,6 +12340,8 @@ var DeviceStateMirror = class {
|
|
|
12145
12340
|
stateMirror = /* @__PURE__ */ new Map();
|
|
12146
12341
|
/** The claims and the merged view of every claimed cap (D663). */
|
|
12147
12342
|
claims;
|
|
12343
|
+
/** Commanded values shown before the device confirms them (D1061). Memory only. */
|
|
12344
|
+
holds;
|
|
12148
12345
|
/**
|
|
12149
12346
|
* Devices whose CLAIMS are known: the row was read, or a loaded claims index
|
|
12150
12347
|
* vouched that it names none (D447). This is a READ-path fact — what a
|
|
@@ -12175,6 +12372,14 @@ var DeviceStateMirror = class {
|
|
|
12175
12372
|
schemaFor,
|
|
12176
12373
|
emitSlice: (deviceId, capName, slice) => this.emitStateChanged(deviceId, capName, slice)
|
|
12177
12374
|
});
|
|
12375
|
+
this.holds = new CommandHolds({
|
|
12376
|
+
logger: ctx.logger,
|
|
12377
|
+
baseSlice: (deviceId, capName) => this.baseSlice(deviceId, capName),
|
|
12378
|
+
reemit: (deviceId, capName) => {
|
|
12379
|
+
const base = this.baseSlice(deviceId, capName);
|
|
12380
|
+
if (base !== null) this.emitStateChanged(deviceId, capName, { ...base });
|
|
12381
|
+
}
|
|
12382
|
+
});
|
|
12178
12383
|
this.writer = new MirrorRowWriter({
|
|
12179
12384
|
logger: ctx.logger,
|
|
12180
12385
|
policyFor,
|
|
@@ -12187,6 +12392,22 @@ var DeviceStateMirror = class {
|
|
|
12187
12392
|
setTransitionTap(tap) {
|
|
12188
12393
|
this.transitionTap = tap;
|
|
12189
12394
|
}
|
|
12395
|
+
/**
|
|
12396
|
+
* Hold what a command leads to: the effective slice shows it at once (and
|
|
12397
|
+
* `DeviceStateChanged` carries it), the stored, persisted and recorded slice
|
|
12398
|
+
* does not change. Returns the token {@link releaseCommand} takes, or `null`.
|
|
12399
|
+
*/
|
|
12400
|
+
holdCommand(request) {
|
|
12401
|
+
return this.holds.arm(request);
|
|
12402
|
+
}
|
|
12403
|
+
/** End a command's hold: refused (rolled back at once) or unconfirmed (at the limit). */
|
|
12404
|
+
releaseCommand(token, reason) {
|
|
12405
|
+
this.holds.release(token, reason);
|
|
12406
|
+
}
|
|
12407
|
+
/** Stop the hold timers (shutdown). */
|
|
12408
|
+
disposeHolds() {
|
|
12409
|
+
this.holds.dispose();
|
|
12410
|
+
}
|
|
12190
12411
|
/** The native slice the mirror holds for `capName`, as a read-only view. */
|
|
12191
12412
|
currentSlice(deviceId, capName) {
|
|
12192
12413
|
return this.stateMirror.get(deviceId)?.get(capName);
|
|
@@ -12399,6 +12620,7 @@ var DeviceStateMirror = class {
|
|
|
12399
12620
|
await this.seeding.get(deviceId)?.catch(() => void 0);
|
|
12400
12621
|
await this.writer.forget(deviceId);
|
|
12401
12622
|
this.stateMirror.delete(deviceId);
|
|
12623
|
+
this.holds.clearDevice(deviceId);
|
|
12402
12624
|
this.workloadTransitions.forget(deviceId);
|
|
12403
12625
|
this.claims.clearDevice(deviceId);
|
|
12404
12626
|
this.seeded.delete(deviceId);
|
|
@@ -12690,25 +12912,33 @@ var DeviceStateMirror = class {
|
|
|
12690
12912
|
if (!raw) return true;
|
|
12691
12913
|
return (typeof raw.lastProbedAt === "number" ? raw.lastProbedAt : 0) > 0;
|
|
12692
12914
|
}
|
|
12693
|
-
/** The
|
|
12694
|
-
*
|
|
12695
|
-
|
|
12915
|
+
/** The slices of a device: native for an unclaimed cap, the merge for a
|
|
12916
|
+
* claimed one (a held cap is not reported) — and, in the `effective` view,
|
|
12917
|
+
* a commanded value over either (D1061). */
|
|
12918
|
+
snapshotForDevice(deviceId, view = "effective") {
|
|
12696
12919
|
const out = {};
|
|
12697
12920
|
for (const [k, v] of this.stateMirror.get(deviceId) ?? []) {
|
|
12698
12921
|
if (this.claims.isClaimed(deviceId, k)) continue;
|
|
12699
|
-
out[k] =
|
|
12922
|
+
out[k] = this.viewOf(deviceId, k, v, view);
|
|
12700
12923
|
}
|
|
12701
|
-
for (const [k, v] of this.claims.visibleCaps(deviceId)) out[k] =
|
|
12924
|
+
for (const [k, v] of this.claims.visibleCaps(deviceId)) out[k] = this.viewOf(deviceId, k, v, view);
|
|
12702
12925
|
return out;
|
|
12703
12926
|
}
|
|
12704
|
-
/** One cap's
|
|
12927
|
+
/** One cap's slice in `view`, cloned. Null when the device has never written
|
|
12705
12928
|
* it — callers read that as "the cap has no state", never as an empty slice —
|
|
12706
12929
|
* and null while a claim holds it. */
|
|
12707
|
-
capSlice(deviceId, cap) {
|
|
12930
|
+
capSlice(deviceId, cap, view = "effective") {
|
|
12931
|
+
const base = this.baseSlice(deviceId, cap);
|
|
12932
|
+
return base === null ? null : this.viewOf(deviceId, cap, base, view);
|
|
12933
|
+
}
|
|
12934
|
+
/** What the device reported for the cap, or the claim's merge — never a hold. Not cloned. */
|
|
12935
|
+
baseSlice(deviceId, cap) {
|
|
12708
12936
|
const visible = this.claims.visible(deviceId, cap);
|
|
12709
|
-
if (visible !== void 0) return visible ?
|
|
12710
|
-
|
|
12711
|
-
|
|
12937
|
+
if (visible !== void 0) return visible ? visible : null;
|
|
12938
|
+
return this.stateMirror.get(deviceId)?.get(cap) ?? null;
|
|
12939
|
+
}
|
|
12940
|
+
viewOf(deviceId, cap, base, view) {
|
|
12941
|
+
return view === "confirmed" ? { ...base } : { ...this.holds.overlay(deviceId, cap, base) };
|
|
12712
12942
|
}
|
|
12713
12943
|
/** The device's NATIVE slices — what the row stores under the cap names. */
|
|
12714
12944
|
nativeSnapshotForDevice(deviceId) {
|
|
@@ -12720,10 +12950,10 @@ var DeviceStateMirror = class {
|
|
|
12720
12950
|
}
|
|
12721
12951
|
/** Whole-system mirror dump. Backs `deviceState.getAllSnapshots` — one
|
|
12722
12952
|
* round-trip for a warm boot instead of N per-device calls. */
|
|
12723
|
-
allSnapshots() {
|
|
12953
|
+
allSnapshots(view = "effective") {
|
|
12724
12954
|
const out = {};
|
|
12725
12955
|
const deviceIds = new Set([...this.stateMirror.keys(), ...this.claims.deviceIds()]);
|
|
12726
|
-
for (const deviceId of deviceIds) out[String(deviceId)] = this.snapshotForDevice(deviceId);
|
|
12956
|
+
for (const deviceId of deviceIds) out[String(deviceId)] = this.snapshotForDevice(deviceId, view);
|
|
12727
12957
|
return out;
|
|
12728
12958
|
}
|
|
12729
12959
|
/**
|
|
@@ -12752,17 +12982,21 @@ var DeviceStateMirror = class {
|
|
|
12752
12982
|
}
|
|
12753
12983
|
/** Remember a restored running bit so the first public merge does not emit a flip. */
|
|
12754
12984
|
seedRunningFlip(deviceId) {
|
|
12755
|
-
const slice = this.capSlice(deviceId, RUNNING_STATE_CAP);
|
|
12985
|
+
const slice = this.capSlice(deviceId, RUNNING_STATE_CAP, "confirmed");
|
|
12756
12986
|
if (slice === null) return;
|
|
12757
12987
|
const running = slice["running"];
|
|
12758
12988
|
this.runningFlip.seed(deviceId, running === true || running === false ? running : null);
|
|
12759
12989
|
}
|
|
12760
12990
|
/**
|
|
12761
|
-
* The PUBLIC event:
|
|
12762
|
-
*
|
|
12763
|
-
* `
|
|
12991
|
+
* The PUBLIC event: `{ deviceId, capName, slice }` for every device, claimed
|
|
12992
|
+
* or not; `slice` is the EFFECTIVE slice. While a command hold changes it
|
|
12993
|
+
* (D1061), `confirmed` carries the slice without the hold — what history,
|
|
12994
|
+
* automations and the edge detectors below read. The native shadow of a
|
|
12995
|
+
* claim never rides here (D224) — see `emitNativeShadow`.
|
|
12764
12996
|
*/
|
|
12765
12997
|
emitStateChanged(deviceId, capName, slice) {
|
|
12998
|
+
this.holds.settle(deviceId, capName, slice);
|
|
12999
|
+
const effective = this.holds.overlay(deviceId, capName, slice);
|
|
12766
13000
|
if (capName === RUNNING_STATE_CAP) {
|
|
12767
13001
|
const flip = this.runningFlip.note(deviceId, slice);
|
|
12768
13002
|
if (flip !== null) this.ctx.eventBus.emit({
|
|
@@ -12789,10 +13023,15 @@ var DeviceStateMirror = class {
|
|
|
12789
13023
|
id: deviceId
|
|
12790
13024
|
},
|
|
12791
13025
|
category: require_dist.EventCategory.DeviceStateChanged,
|
|
12792
|
-
data: {
|
|
13026
|
+
data: effective === slice ? {
|
|
12793
13027
|
deviceId,
|
|
12794
13028
|
capName,
|
|
12795
13029
|
slice
|
|
13030
|
+
} : {
|
|
13031
|
+
deviceId,
|
|
13032
|
+
capName,
|
|
13033
|
+
slice: { ...effective },
|
|
13034
|
+
confirmed: slice
|
|
12796
13035
|
}
|
|
12797
13036
|
});
|
|
12798
13037
|
}
|
|
@@ -12893,15 +13132,15 @@ var CommandObserverRegistry = class {
|
|
|
12893
13132
|
} catch {}
|
|
12894
13133
|
}
|
|
12895
13134
|
};
|
|
12896
|
-
var registry;
|
|
13135
|
+
var registry$1;
|
|
12897
13136
|
/** The process-wide registry. */
|
|
12898
13137
|
function getCommandObserverRegistry() {
|
|
12899
|
-
registry ??= new CommandObserverRegistry();
|
|
12900
|
-
return registry;
|
|
13138
|
+
registry$1 ??= new CommandObserverRegistry();
|
|
13139
|
+
return registry$1;
|
|
12901
13140
|
}
|
|
12902
13141
|
/** Test seam: forget every subscriber. */
|
|
12903
13142
|
function __resetCommandObserverRegistryForTests() {
|
|
12904
|
-
registry = void 0;
|
|
13143
|
+
registry$1 = void 0;
|
|
12905
13144
|
}
|
|
12906
13145
|
function isRecord(value) {
|
|
12907
13146
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
@@ -13081,6 +13320,110 @@ function runObservedCommand(sink, facts, call) {
|
|
|
13081
13320
|
throw err;
|
|
13082
13321
|
}
|
|
13083
13322
|
}
|
|
13323
|
+
//#endregion
|
|
13324
|
+
//#region src/kernel/command-hold-overrides.ts
|
|
13325
|
+
/** The source key of an in-process registration. */
|
|
13326
|
+
var IN_PROCESS_HOLD_SOURCE = "in-process";
|
|
13327
|
+
/** The source key of a forked child's registrations. */
|
|
13328
|
+
function childHoldSource(childId) {
|
|
13329
|
+
return `child:${childId}`;
|
|
13330
|
+
}
|
|
13331
|
+
/** The options a child's cap descriptors carry, one entry per device cap. */
|
|
13332
|
+
function childCommandHoldEntries(caps) {
|
|
13333
|
+
const out = [];
|
|
13334
|
+
for (const cap of caps) {
|
|
13335
|
+
if (cap.deviceId === void 0 || cap.commandHolds === void 0) continue;
|
|
13336
|
+
out.push({
|
|
13337
|
+
deviceId: cap.deviceId,
|
|
13338
|
+
capName: cap.capName,
|
|
13339
|
+
commands: cap.commandHolds
|
|
13340
|
+
});
|
|
13341
|
+
}
|
|
13342
|
+
return out;
|
|
13343
|
+
}
|
|
13344
|
+
function keyOf$1(deviceId, capName) {
|
|
13345
|
+
return `${deviceId}|${capName}`;
|
|
13346
|
+
}
|
|
13347
|
+
var CommandHoldOverrideRegistry = class {
|
|
13348
|
+
bySource = /* @__PURE__ */ new Map();
|
|
13349
|
+
/** Record (or replace) one device cap's options from `source`. */
|
|
13350
|
+
set(source, entry) {
|
|
13351
|
+
const perSource = this.bySource.get(source) ?? /* @__PURE__ */ new Map();
|
|
13352
|
+
perSource.set(keyOf$1(entry.deviceId, entry.capName), entry.commands);
|
|
13353
|
+
this.bySource.set(source, perSource);
|
|
13354
|
+
}
|
|
13355
|
+
/** Forget one device cap's options from `source`. */
|
|
13356
|
+
delete(source, deviceId, capName) {
|
|
13357
|
+
const perSource = this.bySource.get(source);
|
|
13358
|
+
if (perSource === void 0) return;
|
|
13359
|
+
perSource.delete(keyOf$1(deviceId, capName));
|
|
13360
|
+
if (perSource.size === 0) this.bySource.delete(source);
|
|
13361
|
+
}
|
|
13362
|
+
/** Replace everything `source` reported with `entries` (an empty list forgets the source). */
|
|
13363
|
+
replaceSource(source, entries) {
|
|
13364
|
+
if (entries.length === 0) {
|
|
13365
|
+
this.bySource.delete(source);
|
|
13366
|
+
return;
|
|
13367
|
+
}
|
|
13368
|
+
this.bySource.set(source, new Map(entries.map((e) => [keyOf$1(e.deviceId, e.capName), e.commands])));
|
|
13369
|
+
}
|
|
13370
|
+
/** The options for a device cap, from whichever source registered it; `undefined` = default. */
|
|
13371
|
+
get(deviceId, capName) {
|
|
13372
|
+
const key = keyOf$1(deviceId, capName);
|
|
13373
|
+
for (const perSource of this.bySource.values()) {
|
|
13374
|
+
const found = perSource.get(key);
|
|
13375
|
+
if (found !== void 0) return found;
|
|
13376
|
+
}
|
|
13377
|
+
}
|
|
13378
|
+
};
|
|
13379
|
+
var registry;
|
|
13380
|
+
/** The process-wide registry. */
|
|
13381
|
+
function getCommandHoldOverrideRegistry() {
|
|
13382
|
+
registry ??= new CommandHoldOverrideRegistry();
|
|
13383
|
+
return registry;
|
|
13384
|
+
}
|
|
13385
|
+
//#endregion
|
|
13386
|
+
//#region src/builtins/device-manager/command-holds-wiring.ts
|
|
13387
|
+
/**
|
|
13388
|
+
* Arms the command hold (D1061) from the D1022 command seams.
|
|
13389
|
+
*
|
|
13390
|
+
* Every device command the hub sees — its tRPC mount, the UDS parent for a
|
|
13391
|
+
* forked addon's `ctx.api`, an in-process addon's `ctx.api` — reaches the
|
|
13392
|
+
* process-wide observer registry BEFORE the call runs. Here each one resolves
|
|
13393
|
+
* what it leads to (the vocabulary's effects under the provider's option) on
|
|
13394
|
+
* the slice the device last reported, and the mirror holds it; a refused call
|
|
13395
|
+
* rolls the hold back at once.
|
|
13396
|
+
*
|
|
13397
|
+
* Telemetry in, never a gate (D8): a throw here costs the hold, never the call.
|
|
13398
|
+
*/
|
|
13399
|
+
/** Subscribe the hold to the command observations; returns the unsubscribe. */
|
|
13400
|
+
function startCommandHolds(deps) {
|
|
13401
|
+
const optionsFor = deps.optionsFor ?? ((deviceId, capName) => getCommandHoldOverrideRegistry().get(deviceId, capName));
|
|
13402
|
+
const unsubscribe = getCommandObserverRegistry().subscribe((obs) => {
|
|
13403
|
+
try {
|
|
13404
|
+
const current = deps.mirror.capSlice(obs.deviceId, obs.capName, "confirmed") ?? void 0;
|
|
13405
|
+
const shown = deps.mirror.capSlice(obs.deviceId, obs.capName) ?? void 0;
|
|
13406
|
+
const option = optionsFor(obs.deviceId, obs.capName)?.[obs.method];
|
|
13407
|
+
const hold = require_dist.resolveCommandHold(obs.capName, obs.method, obs.args, current, option, shown);
|
|
13408
|
+
if (hold === null) return;
|
|
13409
|
+
const token = deps.mirror.holdCommand({
|
|
13410
|
+
deviceId: obs.deviceId,
|
|
13411
|
+
capName: obs.capName,
|
|
13412
|
+
method: obs.method,
|
|
13413
|
+
effects: hold.effects,
|
|
13414
|
+
holdMs: hold.holdMs
|
|
13415
|
+
});
|
|
13416
|
+
if (token === null) return;
|
|
13417
|
+
obs.outcome?.catch(() => deps.mirror.releaseCommand(token, "refused"));
|
|
13418
|
+
} catch (err) {
|
|
13419
|
+
deps.logger.error(`command hold: arming ${obs.capName}.${obs.method} failed: ${err instanceof Error ? err.message : String(err)}`, { tags: { deviceId: obs.deviceId } });
|
|
13420
|
+
}
|
|
13421
|
+
});
|
|
13422
|
+
return () => {
|
|
13423
|
+
unsubscribe();
|
|
13424
|
+
deps.mirror.disposeHolds();
|
|
13425
|
+
};
|
|
13426
|
+
}
|
|
13084
13427
|
var REDACTED = "***";
|
|
13085
13428
|
var ROUTING_KEYS = new Set([
|
|
13086
13429
|
"deviceId",
|
|
@@ -13999,6 +14342,8 @@ var DeviceManagerAddon = class extends require_dist.BaseAddon {
|
|
|
13999
14342
|
stateMirrorImpl = null;
|
|
14000
14343
|
/** The transition audit (D1022): command + mirror correlation, shipped to device-history. */
|
|
14001
14344
|
transitions = null;
|
|
14345
|
+
/** Unsubscribes the command hold (D1061). */
|
|
14346
|
+
stopCommandHolds = null;
|
|
14002
14347
|
/**
|
|
14003
14348
|
* Removes the claimed-status overlay this addon installed on the capability
|
|
14004
14349
|
* registry (D663, S3): `getStatus` of a claimed cap answers the mirror for
|
|
@@ -14345,6 +14690,10 @@ var DeviceManagerAddon = class extends require_dist.BaseAddon {
|
|
|
14345
14690
|
const metaStore = new DeviceMetaStore(settings, registry, deviceRows, this.addonStoreWriteLock);
|
|
14346
14691
|
this.stateMirrorImpl = new DeviceStateMirror(this.ctx);
|
|
14347
14692
|
const stateMirror = this.stateMirrorImpl;
|
|
14693
|
+
this.stopCommandHolds = startCommandHolds({
|
|
14694
|
+
mirror: stateMirror,
|
|
14695
|
+
logger: this.ctx.logger.child("command-holds")
|
|
14696
|
+
});
|
|
14348
14697
|
this.transitions = startDeviceTransitions({
|
|
14349
14698
|
mirror: stateMirror,
|
|
14350
14699
|
logger: this.ctx.logger.child("transitions"),
|
|
@@ -14639,13 +14988,13 @@ var DeviceManagerAddon = class extends require_dist.BaseAddon {
|
|
|
14639
14988
|
return stateMirror.snapshotForDevice(input.deviceId);
|
|
14640
14989
|
},
|
|
14641
14990
|
getCapSlice: async (input) => {
|
|
14642
|
-
return stateMirror.capSlice(input.deviceId, input.capName);
|
|
14991
|
+
return stateMirror.capSlice(input.deviceId, input.capName, input.confirmed === true ? "confirmed" : "effective");
|
|
14643
14992
|
},
|
|
14644
14993
|
getNativeCapSlice: async (input) => {
|
|
14645
14994
|
return stateMirror.nativeSlice(input.deviceId, input.capName);
|
|
14646
14995
|
},
|
|
14647
|
-
getAllSnapshots: async () => {
|
|
14648
|
-
return stateMirror.allSnapshots();
|
|
14996
|
+
getAllSnapshots: async (input) => {
|
|
14997
|
+
return stateMirror.allSnapshots(input?.confirmed === true ? "confirmed" : "effective");
|
|
14649
14998
|
},
|
|
14650
14999
|
setCapSlice: async (input) => {
|
|
14651
15000
|
const { deviceId, capName, slice } = input;
|
|
@@ -14743,6 +15092,8 @@ var DeviceManagerAddon = class extends require_dist.BaseAddon {
|
|
|
14743
15092
|
this.templateActions = null;
|
|
14744
15093
|
await this.transitions?.stop();
|
|
14745
15094
|
this.transitions = null;
|
|
15095
|
+
this.stopCommandHolds?.();
|
|
15096
|
+
this.stopCommandHolds = null;
|
|
14746
15097
|
this.removalCleanupImpl?.dispose();
|
|
14747
15098
|
this.removalCleanupImpl = null;
|
|
14748
15099
|
this.removalHooksCleanupImpl?.dispose();
|
|
@@ -14760,11 +15111,15 @@ var DeviceManagerAddon = class extends require_dist.BaseAddon {
|
|
|
14760
15111
|
exports.CommandObserverRegistry = CommandObserverRegistry;
|
|
14761
15112
|
exports.DeviceManagerAddon = DeviceManagerAddon;
|
|
14762
15113
|
exports.default = DeviceManagerAddon;
|
|
15114
|
+
exports.IN_PROCESS_HOLD_SOURCE = IN_PROCESS_HOLD_SOURCE;
|
|
14763
15115
|
exports.__resetCommandObserverRegistryForTests = __resetCommandObserverRegistryForTests;
|
|
14764
15116
|
exports.addonCommandActor = addonCommandActor;
|
|
15117
|
+
exports.childCommandHoldEntries = childCommandHoldEntries;
|
|
15118
|
+
exports.childHoldSource = childHoldSource;
|
|
14765
15119
|
exports.commandActorFromContext = commandActorFromContext;
|
|
14766
15120
|
exports.commandObserverLink = commandObserverLink;
|
|
14767
15121
|
exports.createDeviceSettingsStore = createDeviceSettingsStore;
|
|
15122
|
+
exports.getCommandHoldOverrideRegistry = getCommandHoldOverrideRegistry;
|
|
14768
15123
|
exports.getCommandObserverRegistry = getCommandObserverRegistry;
|
|
14769
15124
|
exports.mergeAggregates = mergeAggregates;
|
|
14770
15125
|
exports.observable = observable;
|