@camstack/server 1.2.891 → 1.2.892
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 +16 -0
- package/dist/api/trpc/generated-cap-mounts.js +2 -1
- package/dist/api/trpc/generated-cap-routers.js +194 -39
- package/dist/core/addon/addon-registry.service.js +47 -0
- package/dist/core/addon/retire-undeclared-fixed-integrations.js +57 -0
- package/package.json +31 -15
- package/system/dist/addon-runner.js +25 -9
- package/system/dist/addon-runner.mjs +25 -9
- 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/addon.d.ts +65 -41
- package/system/dist/builtins/camera-grid/grid-blocks.d.ts +51 -0
- package/system/dist/builtins/camera-grid/grid-camera-device.d.ts +4 -3
- package/system/dist/builtins/camera-grid/grid-layout-native-provider.d.ts +3 -1
- package/system/dist/builtins/camera-grid/grid-plan.d.ts +3 -3
- package/system/dist/builtins/camera-grid/index.d.ts +2 -6
- package/system/dist/builtins/camera-grid/index.js +431 -727
- package/system/dist/builtins/camera-grid/index.mjs +428 -719
- package/system/dist/builtins/composer/composed-device.d.ts +12 -2
- package/system/dist/builtins/composer/composer.addon.js +28 -10
- package/system/dist/builtins/composer/composer.addon.mjs +28 -10
- package/system/dist/builtins/composer/composition-declarations.d.ts +3 -1
- 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 +174 -39
- package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +175 -40
- package/system/dist/builtins/core-blocks/hero-layout-service.d.ts +19 -1
- package/system/dist/builtins/core-blocks/power-source-devices.d.ts +9 -0
- package/system/dist/builtins/core-blocks/power-source-service.d.ts +39 -2
- package/system/dist/builtins/device-history/device-history.addon.js +2 -2
- package/system/dist/builtins/device-history/device-history.addon.mjs +2 -2
- package/system/dist/builtins/device-manager/device-identifiers-action.d.ts +9 -0
- package/system/dist/builtins/device-manager/device-manager.addon.js +172 -5
- package/system/dist/builtins/device-manager/device-manager.addon.mjs +172 -5
- package/system/dist/builtins/device-manager/device-meta-types.d.ts +5 -1
- package/system/dist/builtins/device-manager/device-row-store.d.ts +3 -2
- package/system/dist/builtins/device-manager/device-state-mirror.d.ts +7 -0
- package/system/dist/builtins/device-manager/workload-transition.d.ts +23 -0
- 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/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 +284 -284
- 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-DXz37Mjg.js → capture-engine-DHmlkW_d.js} +1 -1
- package/system/dist/{capture-engine-nmelnj-Y.mjs → capture-engine-sl6e9f9S.mjs} +1 -1
- package/system/dist/{composition-sources-uphZtYtN.mjs → composition-sources-CznD85Ri.mjs} +1 -1
- package/system/dist/{composition-sources-BLn3cU74.js → composition-sources-PqcZfe3j.js} +1 -1
- package/system/dist/{constants-DWU46D02.mjs → constants-CHwj_mIM.mjs} +1 -1
- package/system/dist/{constants-BAaGwvKn.js → constants-_2SOk0By.js} +1 -1
- package/system/dist/{device-ca-CK6mLB2w.mjs → device-ca-D2H1EMUY.mjs} +1 -1
- package/system/dist/{device-ca-jbH_rqZh.js → device-ca-WIEO5ZcE.js} +1 -1
- package/system/dist/{dist-Dgq9nuvh.mjs → dist-DbAhCrHy.mjs} +2366 -444
- package/system/dist/{dist-m5beNMze.js → dist-yx2KHo3b.js} +2467 -443
- package/system/dist/file-host-worker.js +1 -1
- package/system/dist/file-host-worker.mjs +1 -1
- package/system/dist/{hub-identity-DlBBoHJC.mjs → hub-identity-BcvZqT0L.mjs} +1 -1
- package/system/dist/{hub-identity-CKCA89XP.js → hub-identity-Buegac-w.js} +1 -1
- package/system/dist/{hub-mdns-ciao-B8uFW-RG.mjs → hub-mdns-ciao-B6K_dO2s.mjs} +2 -2
- package/system/dist/{hub-mdns-ciao-CqcCGPdi.js → hub-mdns-ciao-DcNPj7WJ.js} +2 -2
- package/system/dist/index.js +33 -19
- package/system/dist/index.mjs +33 -19
- package/system/dist/kernel/moleculer/child-cap-dispatch.d.ts +3 -6
- package/system/dist/kernel/moleculer/switch-toggle.d.ts +7 -2
- package/system/dist/{legacy-integration-rows-door-Co0gj1Lm.js → legacy-integration-rows-door-BsZyVNiR.js} +1 -1
- package/system/dist/{legacy-integration-rows-door-HI4nmSe_.mjs → legacy-integration-rows-door-DHOJeDPG.mjs} +1 -1
- package/system/dist/{rename-composition-block-UeVUYCwx.js → rename-composition-block-BXMor7MR.js} +1 -1
- package/system/dist/{rename-composition-block-BthBMrXA.mjs → rename-composition-block-DcVS1LuC.mjs} +1 -1
- package/system/dist/{restore-archive-P-ICnU58.mjs → restore-archive-BG8VJ8Ar.mjs} +82 -82
- package/system/dist/{restore-archive-CJLsfBwK.js → restore-archive-BURufVQd.js} +1 -1
- package/system/dist/{wal-maintenance-qWjb7_f2.mjs → wal-maintenance-B4wGD6QR.mjs} +0 -0
- package/system/dist/{wal-maintenance-CUtwx-2Z.js → wal-maintenance-CeaJyKNT.js} +0 -0
- package/system/package.json +2 -5
- package/system/dist/builtins/camera-grid/grid-camera-declarations.d.ts +0 -59
- package/system/dist/builtins/camera-grid/grid-instances.d.ts +0 -40
- package/system/dist/builtins/camera-grid/grid-record-kinds.d.ts +0 -31
- package/system/dist/builtins/camera-grid/migrations/__fixtures__/seed.d.ts +0 -13
- package/system/dist/builtins/camera-grid/migrations/camera-grids-to-records.d.ts +0 -26
- package/system/dist/builtins/camera-grid/migrations/index.d.ts +0 -6
|
@@ -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-yx2KHo3b.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-BXMor7MR.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");
|
|
@@ -484,7 +484,8 @@ function toDeviceInfo(addonId, device, metadata = null, metaRow = null) {
|
|
|
484
484
|
...metaRow?.childLayout !== void 0 ? { childLayout: metaRow.childLayout } : {},
|
|
485
485
|
...metaRow?.primaryChildPreference !== void 0 ? { primaryChildPreference: metaRow.primaryChildPreference } : {},
|
|
486
486
|
...metaRow?.tags !== void 0 ? { tags: metaRow.tags } : {},
|
|
487
|
-
...metaRow?.display !== void 0 ? { display: metaRow.display } : {}
|
|
487
|
+
...metaRow?.display !== void 0 ? { display: metaRow.display } : {},
|
|
488
|
+
...metaRow?.identifiers !== void 0 ? { identifiers: metaRow.identifiers } : {}
|
|
488
489
|
};
|
|
489
490
|
}
|
|
490
491
|
function resolveDeviceById(registry, deviceId) {
|
|
@@ -3068,6 +3069,7 @@ async function listAll(pctx, input) {
|
|
|
3068
3069
|
...m.primaryChildPreference !== void 0 ? { primaryChildPreference: m.primaryChildPreference } : {},
|
|
3069
3070
|
...m.tags !== void 0 ? { tags: m.tags } : {},
|
|
3070
3071
|
...m.display !== void 0 ? { display: m.display } : {},
|
|
3072
|
+
...m.identifiers !== void 0 ? { identifiers: m.identifiers } : {},
|
|
3071
3073
|
...(() => {
|
|
3072
3074
|
if (slim) return {};
|
|
3073
3075
|
const si = projectSourceInfo(persistedConfig ?? {}, stableId, aid, metadata);
|
|
@@ -3121,6 +3123,7 @@ async function getDevice(pctx, input) {
|
|
|
3121
3123
|
...m.primaryChildPreference !== void 0 ? { primaryChildPreference: m.primaryChildPreference } : {},
|
|
3122
3124
|
...m.tags !== void 0 ? { tags: m.tags } : {},
|
|
3123
3125
|
...m.display !== void 0 ? { display: m.display } : {},
|
|
3126
|
+
...m.identifiers !== void 0 ? { identifiers: m.identifiers } : {},
|
|
3124
3127
|
...sourceInfoGetDevice !== void 0 ? { sourceInfo: sourceInfoGetDevice } : {}
|
|
3125
3128
|
};
|
|
3126
3129
|
}
|
|
@@ -3201,6 +3204,7 @@ function projectChildren(pctx, parentDeviceId, ownerAddonId, childRows, liveChil
|
|
|
3201
3204
|
...m.primaryChildPreference !== void 0 ? { primaryChildPreference: m.primaryChildPreference } : {},
|
|
3202
3205
|
...m.tags !== void 0 ? { tags: m.tags } : {},
|
|
3203
3206
|
...m.display !== void 0 ? { display: m.display } : {},
|
|
3207
|
+
...m.identifiers !== void 0 ? { identifiers: m.identifiers } : {},
|
|
3204
3208
|
...sourceInfoChild !== void 0 ? { sourceInfo: sourceInfoChild } : {}
|
|
3205
3209
|
});
|
|
3206
3210
|
}
|
|
@@ -8801,6 +8805,99 @@ async function removeLocation(pctx, input) {
|
|
|
8801
8805
|
});
|
|
8802
8806
|
}
|
|
8803
8807
|
//#endregion
|
|
8808
|
+
//#region src/builtins/device-manager/device-identifiers-action.ts
|
|
8809
|
+
/**
|
|
8810
|
+
* `device-manager.setIdentifiers` — the ONE writer of a device's provider-declared
|
|
8811
|
+
* identifiers (D1059).
|
|
8812
|
+
*
|
|
8813
|
+
* Who may write: the provider that OWNS the device, and nobody else. Ownership is
|
|
8814
|
+
* the caller stamp the transport sets (`callerAddonId`, never in an input schema,
|
|
8815
|
+
* so a session cannot supply it — `CALLER_STAMPED_CAPABILITIES` lists
|
|
8816
|
+
* `device-manager`) compared with the row's `addonId`. An operator session carries
|
|
8817
|
+
* no stamp and is refused; so is another addon. The operator reads identifiers, it
|
|
8818
|
+
* never edits them: the free-form, editable blob is `metadata`.
|
|
8819
|
+
*
|
|
8820
|
+
* The stored value is `mergeIdentifiers(stored, declared, unread)`: each kind the
|
|
8821
|
+
* declaration carries replaces the stored one, each kind it lacks is removed,
|
|
8822
|
+
* except the kinds in `unread` (the provider's read FAILED), which keep what was
|
|
8823
|
+
* stored — a failed read never erases a fact (D49). An entry whose value and
|
|
8824
|
+
* origin are unchanged keeps its stored `readAt` (when that value was first read),
|
|
8825
|
+
* so a provider re-declaring the same values on every boot writes nothing and
|
|
8826
|
+
* emits nothing. `null` clears every kind not in `unread`.
|
|
8827
|
+
*/
|
|
8828
|
+
var SetIdentifiersRefusedError = class extends Error {
|
|
8829
|
+
reason;
|
|
8830
|
+
constructor(reason, message) {
|
|
8831
|
+
super(message);
|
|
8832
|
+
this.reason = reason;
|
|
8833
|
+
this.name = "SetIdentifiersRefusedError";
|
|
8834
|
+
}
|
|
8835
|
+
};
|
|
8836
|
+
/** The caller the transport stamped; `null` when the call carries none. */
|
|
8837
|
+
function stampedCaller(input) {
|
|
8838
|
+
const raw = Reflect.get(Object(input), "callerAddonId");
|
|
8839
|
+
return typeof raw === "string" && raw.length > 0 ? raw : null;
|
|
8840
|
+
}
|
|
8841
|
+
async function setIdentifiers(pctx, input) {
|
|
8842
|
+
const { deviceId } = input;
|
|
8843
|
+
const logger = pctx.host.ctx.logger;
|
|
8844
|
+
const caller = stampedCaller(input);
|
|
8845
|
+
const parsed = require_dist.DeviceIdentifiersSchema.nullable().safeParse(input.identifiers);
|
|
8846
|
+
if (!parsed.success) {
|
|
8847
|
+
logger.warn("setIdentifiers refused — the declaration is not in its normalised form", {
|
|
8848
|
+
tags: { deviceId },
|
|
8849
|
+
meta: {
|
|
8850
|
+
caller,
|
|
8851
|
+
issues: parsed.error.issues.map((i) => i.path.join("."))
|
|
8852
|
+
}
|
|
8853
|
+
});
|
|
8854
|
+
throw new SetIdentifiersRefusedError("invalid", `[device-manager] setIdentifiers: device ${deviceId} — declaration not normalised (use normaliseIdentifiers)`);
|
|
8855
|
+
}
|
|
8856
|
+
const next = parsed.data === null || require_dist.isEmptyIdentifiers(parsed.data) ? null : parsed.data;
|
|
8857
|
+
const outcome = await pctx.metaStore.withMetaWriteLock(async () => {
|
|
8858
|
+
const persisted = await pctx.metaStore.resolvePersistedById(deviceId);
|
|
8859
|
+
if (!persisted) return { kind: "unknown-device" };
|
|
8860
|
+
if (caller === null || caller !== persisted.addonId) return {
|
|
8861
|
+
kind: "not-owner",
|
|
8862
|
+
owner: persisted.addonId
|
|
8863
|
+
};
|
|
8864
|
+
const stored = persisted.meta.identifiers ?? null;
|
|
8865
|
+
const merged = require_dist.mergeIdentifiers(stored, next, input.unread ?? []);
|
|
8866
|
+
if (require_dist.sameIdentifiers(stored, merged)) return { kind: "unchanged" };
|
|
8867
|
+
await pctx.metaStore.rows.patch(deviceId, { identifiers: merged });
|
|
8868
|
+
return {
|
|
8869
|
+
kind: "written",
|
|
8870
|
+
value: merged
|
|
8871
|
+
};
|
|
8872
|
+
});
|
|
8873
|
+
if (outcome.kind === "unknown-device") throw new SetIdentifiersRefusedError("unknown-device", `[device-manager] setIdentifiers: unknown device id=${deviceId}`);
|
|
8874
|
+
if (outcome.kind === "not-owner") {
|
|
8875
|
+
logger.warn("setIdentifiers refused — only the owning provider declares identifiers", {
|
|
8876
|
+
tags: { deviceId },
|
|
8877
|
+
meta: {
|
|
8878
|
+
caller,
|
|
8879
|
+
owner: outcome.owner
|
|
8880
|
+
}
|
|
8881
|
+
});
|
|
8882
|
+
throw new SetIdentifiersRefusedError("not-owner", `[device-manager] setIdentifiers: device ${deviceId} belongs to ${outcome.owner}; caller ${caller ?? "(unstamped)"} may not declare its identifiers`);
|
|
8883
|
+
}
|
|
8884
|
+
if (outcome.kind === "unchanged") return;
|
|
8885
|
+
pctx.host.ctx.eventBus.emit({
|
|
8886
|
+
id: (0, node_crypto.randomUUID)(),
|
|
8887
|
+
timestamp: /* @__PURE__ */ new Date(),
|
|
8888
|
+
source: {
|
|
8889
|
+
type: "device",
|
|
8890
|
+
id: deviceId
|
|
8891
|
+
},
|
|
8892
|
+
category: require_dist.EventCategory.DeviceMetaChanged,
|
|
8893
|
+
data: {
|
|
8894
|
+
deviceId,
|
|
8895
|
+
field: "identifiers",
|
|
8896
|
+
value: outcome.value
|
|
8897
|
+
}
|
|
8898
|
+
});
|
|
8899
|
+
}
|
|
8900
|
+
//#endregion
|
|
8804
8901
|
//#region src/builtins/device-manager/linked-devices-manual-backfill.ts
|
|
8805
8902
|
var LINKED_MANUAL_BACKFILL_MARKER_KEY = "_linkedDevicesManualBackfillVersion";
|
|
8806
8903
|
function planManualBackfill(params) {
|
|
@@ -10339,6 +10436,10 @@ var DEVICE_ROWS_COLUMNS = [
|
|
|
10339
10436
|
{
|
|
10340
10437
|
name: "metadata",
|
|
10341
10438
|
type: "JSON"
|
|
10439
|
+
},
|
|
10440
|
+
{
|
|
10441
|
+
name: "identifiers",
|
|
10442
|
+
type: "JSON"
|
|
10342
10443
|
}
|
|
10343
10444
|
];
|
|
10344
10445
|
/**
|
|
@@ -10458,6 +10559,7 @@ function decodeDeviceRow(data) {
|
|
|
10458
10559
|
const primaryChildPreference = readStringArray(data["primaryChildPreference"]);
|
|
10459
10560
|
const rawDisplay = data["display"];
|
|
10460
10561
|
const rawMetadata = data["metadata"];
|
|
10562
|
+
const identifiers = require_dist.DeviceIdentifiersSchema.safeParse(data["identifiers"]);
|
|
10461
10563
|
return {
|
|
10462
10564
|
meta: {
|
|
10463
10565
|
id: deviceId,
|
|
@@ -10479,7 +10581,8 @@ function decodeDeviceRow(data) {
|
|
|
10479
10581
|
...isChildLayout(rawChildLayout) ? { childLayout: rawChildLayout } : {},
|
|
10480
10582
|
...primaryChildPreference !== void 0 ? { primaryChildPreference } : {},
|
|
10481
10583
|
...role !== void 0 ? { role } : {},
|
|
10482
|
-
...isPlainObject$1(rawDisplay) ? { display: toDisplayOverride(rawDisplay) } : {}
|
|
10584
|
+
...isPlainObject$1(rawDisplay) ? { display: toDisplayOverride(rawDisplay) } : {},
|
|
10585
|
+
...identifiers.success ? { identifiers: identifiers.data } : {}
|
|
10483
10586
|
},
|
|
10484
10587
|
metadata: isPlainObject$1(rawMetadata) ? rawMetadata : null,
|
|
10485
10588
|
registered: readBoolean(data["registered"]) ?? false
|
|
@@ -10525,7 +10628,8 @@ function encodeDeviceRow(meta, extra = {}) {
|
|
|
10525
10628
|
childLayout: meta.childLayout ?? null,
|
|
10526
10629
|
primaryChildPreference: meta.primaryChildPreference === void 0 ? null : [...meta.primaryChildPreference],
|
|
10527
10630
|
role: meta.role ?? null,
|
|
10528
|
-
display: meta.display ?? null
|
|
10631
|
+
display: meta.display ?? null,
|
|
10632
|
+
identifiers: meta.identifiers ?? null
|
|
10529
10633
|
};
|
|
10530
10634
|
if (extra.metadata !== void 0) row["metadata"] = extra.metadata;
|
|
10531
10635
|
return row;
|
|
@@ -11174,6 +11278,41 @@ var RunningFlipDetector = class {
|
|
|
11174
11278
|
}
|
|
11175
11279
|
};
|
|
11176
11280
|
//#endregion
|
|
11281
|
+
//#region src/builtins/device-manager/workload-transition.ts
|
|
11282
|
+
function readState(slice) {
|
|
11283
|
+
const parsed = require_dist.WorkloadStateSchema.safeParse(slice["state"]);
|
|
11284
|
+
return parsed.success ? parsed.data : null;
|
|
11285
|
+
}
|
|
11286
|
+
/**
|
|
11287
|
+
* Remembers each workload's last SETTLED state (running, paused, stopped,
|
|
11288
|
+
* crashed) and turns a move away from it into the cap's events. `starting` /
|
|
11289
|
+
* `stopping` and an unknown state are never remembered, so stopped → starting →
|
|
11290
|
+
* running is one `started`, and crashed → starting → running one `recovered`.
|
|
11291
|
+
*
|
|
11292
|
+
* The first state seen for a device is a seed: it raises nothing, so a hub
|
|
11293
|
+
* restart does not announce every running container as started.
|
|
11294
|
+
*/
|
|
11295
|
+
var WorkloadTransitionDetector = class {
|
|
11296
|
+
#settled = /* @__PURE__ */ new Map();
|
|
11297
|
+
note(deviceId, slice) {
|
|
11298
|
+
const state = readState(slice);
|
|
11299
|
+
const previous = this.#settled.get(deviceId);
|
|
11300
|
+
const kind = require_dist.workloadTransition(previous, state);
|
|
11301
|
+
if (state !== null && require_dist.isWorkloadSettled(state)) this.#settled.set(deviceId, state);
|
|
11302
|
+
if (kind === null || state === null || previous === void 0) return null;
|
|
11303
|
+
return {
|
|
11304
|
+
kind,
|
|
11305
|
+
deviceId,
|
|
11306
|
+
state,
|
|
11307
|
+
previous,
|
|
11308
|
+
since: typeof slice["since"] === "number" && Number.isFinite(slice["since"]) ? slice["since"] : null
|
|
11309
|
+
};
|
|
11310
|
+
}
|
|
11311
|
+
forget(deviceId) {
|
|
11312
|
+
this.#settled.delete(deviceId);
|
|
11313
|
+
}
|
|
11314
|
+
};
|
|
11315
|
+
//#endregion
|
|
11177
11316
|
//#region src/builtins/device-manager/last-active-mode.ts
|
|
11178
11317
|
/**
|
|
11179
11318
|
* The last mode a climate device actually RAN (D224): "turn on" needs a mode to
|
|
@@ -11765,6 +11904,7 @@ var DeviceStateMirror = class {
|
|
|
11765
11904
|
writer;
|
|
11766
11905
|
/** Edge detector for `running-state` flip events (D933). */
|
|
11767
11906
|
runningFlip = new RunningFlipDetector();
|
|
11907
|
+
workloadTransitions = new WorkloadTransitionDetector();
|
|
11768
11908
|
constructor(ctx, policyFor = require_dist.runtimeStatePolicyFor, schemaFor = defaultSchemaFor) {
|
|
11769
11909
|
this.ctx = ctx;
|
|
11770
11910
|
this.policyFor = policyFor;
|
|
@@ -11997,6 +12137,7 @@ var DeviceStateMirror = class {
|
|
|
11997
12137
|
await this.seeding.get(deviceId)?.catch(() => void 0);
|
|
11998
12138
|
await this.writer.forget(deviceId);
|
|
11999
12139
|
this.stateMirror.delete(deviceId);
|
|
12140
|
+
this.workloadTransitions.forget(deviceId);
|
|
12000
12141
|
this.claims.clearDevice(deviceId);
|
|
12001
12142
|
this.seeded.delete(deviceId);
|
|
12002
12143
|
this.rowRead.delete(deviceId);
|
|
@@ -12297,6 +12438,30 @@ var DeviceStateMirror = class {
|
|
|
12297
12438
|
for (const deviceId of deviceIds) out[String(deviceId)] = this.snapshotForDevice(deviceId);
|
|
12298
12439
|
return out;
|
|
12299
12440
|
}
|
|
12441
|
+
/**
|
|
12442
|
+
* The `workload` cap's events (#585): judged from the PUBLIC slice like the
|
|
12443
|
+
* running flip, so a provider only writes its state. The first state seen is
|
|
12444
|
+
* a seed and raises nothing.
|
|
12445
|
+
*/
|
|
12446
|
+
emitWorkloadTransition(deviceId, slice) {
|
|
12447
|
+
const transition = this.workloadTransitions.note(deviceId, slice);
|
|
12448
|
+
if (transition === null) return;
|
|
12449
|
+
this.ctx.eventBus.emit({
|
|
12450
|
+
id: (0, node_crypto.randomUUID)(),
|
|
12451
|
+
timestamp: /* @__PURE__ */ new Date(),
|
|
12452
|
+
source: {
|
|
12453
|
+
type: "device",
|
|
12454
|
+
id: deviceId
|
|
12455
|
+
},
|
|
12456
|
+
category: require_dist.WORKLOAD_TRANSITION_CATEGORY[transition.kind],
|
|
12457
|
+
data: {
|
|
12458
|
+
deviceId,
|
|
12459
|
+
state: transition.state,
|
|
12460
|
+
previous: transition.previous,
|
|
12461
|
+
since: transition.since
|
|
12462
|
+
}
|
|
12463
|
+
});
|
|
12464
|
+
}
|
|
12300
12465
|
/** Remember a restored running bit so the first public merge does not emit a flip. */
|
|
12301
12466
|
seedRunningFlip(deviceId) {
|
|
12302
12467
|
const slice = this.capSlice(deviceId, RUNNING_STATE_CAP);
|
|
@@ -12327,6 +12492,7 @@ var DeviceStateMirror = class {
|
|
|
12327
12492
|
}
|
|
12328
12493
|
});
|
|
12329
12494
|
}
|
|
12495
|
+
if (capName === require_dist.workloadCapability.name) this.emitWorkloadTransition(deviceId, slice);
|
|
12330
12496
|
this.ctx.eventBus.emit({
|
|
12331
12497
|
id: (0, node_crypto.randomUUID)(),
|
|
12332
12498
|
timestamp: /* @__PURE__ */ new Date(),
|
|
@@ -14009,6 +14175,7 @@ var DeviceManagerAddon = class extends require_dist.BaseAddon {
|
|
|
14009
14175
|
setPrimaryChildPreference: (input) => setPrimaryChildPreference(pctx, input),
|
|
14010
14176
|
setRole: (input) => setRole(pctx, input),
|
|
14011
14177
|
setDisplay: (input) => setDisplay(pctx, input),
|
|
14178
|
+
setIdentifiers: (input) => setIdentifiers(pctx, input),
|
|
14012
14179
|
getRoleDisplayDefaults: (input) => getRoleDisplayDefaults(pctx, input),
|
|
14013
14180
|
setRoleDisplayDefaults: (input) => setRoleDisplayDefaults(pctx, input),
|
|
14014
14181
|
applyInitialMeta: (input) => applyInitialMeta(pctx, input),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { $c as
|
|
1
|
+
import { $c as auditedFields, $i as locationIconKey, Ao as searchRank, Bc as SECRET_CLEAR, Bo as siteZoneKey, Co as runtimeFieldUnit, Cs as workloadTransition, Dl as isKeychainStoredField, Dn as WorkloadStateSchema, En as WORKLOAD_TRANSITION_CATEGORY, Er as createDeviceExtensionProvider, Ft as MINUTES_PER_DAY, Gr as deviceStateCapability, Hr as deviceOffersActions, Ii as isEmptyIdentifiers, Is as canonicalStoredDeviceType, J as DEVICE_TEMPLATE_FILTERS, Ja as reconcileReportedFeatures, Kc as WELL_KNOWN_TAB_MAP, Kl as resolveSecretMarkers, Kr as deviceStatusCapability, Ls as capAppliesToDeviceKind, Ml as isSecretMarkerLike, Po as settleDeviceFeatures, Pr as defineExtensionSlotProvider, Q as DEVICE_TEMPLATE_VALUES_CAP, Ql as sleep$2, Ri as isKernelDerivedFeature, S as CAP_NAMES_WITH_STATUS, Sa as normalizeUnit, Sl as isCommand$1, Ss as workloadCapability, To as sameIdentifiers, Ui as isWorkloadSettled, Vr as deviceManagerCapability, X as DEVICE_TEMPLATE_MAX_OUTPUT, Xr as enumerateSchemaFields, Y as DEVICE_TEMPLATE_MAX_LENGTH, Yl as secretTreeFromPaths, Yr as enumerateItemArrayFields, Zn as buildStreamParamsConfigSchema, Zs as implementedMethodsOf$1, _i as generateDeviceAlias, al as commandEffect, ar as checkDeviceAlias, at as DeviceTombstoneSchema, b as CAMERA_SWITCH_ORDER, bo as resolveTemplateRef, cu as DeviceRole, eu as toSecretFieldView, fl as defineRecordKinds, fu as EventCategory$1, gl as expandCapMethods$1, ii as extractSourceInfoFromMetadata, il as collectZodSecretPaths$1, it as DeviceStatusSchema, j as ConditionMirror, jl as isSecretMarker, ka as parseStreamParamsFormPatch, kl as isSecretClear, lu as DeviceType$1, mi as formatMinutes, nt as DeviceIdentifiersSchema, nu as userError, ot as DiscoveryProposalBodySchema, qi as legacyAutoLinkIds, ru as vocabActionIdFor, s as ALL_CAPABILITY_DEFINITIONS, sn as STREAM_PROFILE_META, su as DeviceFeature, ti as expandContainer, tr as canonicalIconKey, tu as transformSecretWrite, ua as mergeIdentifiers, uc as BaseAddon, ut as ExportNameRefusedError, uu as errMsg$1, vt as FieldClaimModeSchema, wl as isDeviceConfigCap, wo as runtimeStatePolicyFor, xa as normalizeTags, yt as FieldClaimSchema, z as DAY_NAMES, zr as deviceExtensionCapability } from "../../dist-DbAhCrHy.mjs";
|
|
2
2
|
import { t as require_read_all_rows } from "../../read-all-rows-TaPqdWNF.mjs";
|
|
3
3
|
import { a as redactLogText, i as redactLogMeta, n as isSecretArgumentKey } from "../../log-redactor-XLDrPzOi.mjs";
|
|
4
|
-
import { n as renameCompositionBlock, t as composedBlockIdOf } from "../../rename-composition-block-
|
|
4
|
+
import { n as renameCompositionBlock, t as composedBlockIdOf } from "../../rename-composition-block-DcVS1LuC.mjs";
|
|
5
5
|
import { t as prefixRange } from "../../prefix-range-Dl0znowN.mjs";
|
|
6
6
|
import { t as loadPrefixed } from "../../prefix-walk-DAOBSyH1.mjs";
|
|
7
7
|
import { n as purgeRetiredSettingsRows } from "../../retired-settings-keys-u6xQA6r7.mjs";
|
|
@@ -478,7 +478,8 @@ function toDeviceInfo(addonId, device, metadata = null, metaRow = null) {
|
|
|
478
478
|
...metaRow?.childLayout !== void 0 ? { childLayout: metaRow.childLayout } : {},
|
|
479
479
|
...metaRow?.primaryChildPreference !== void 0 ? { primaryChildPreference: metaRow.primaryChildPreference } : {},
|
|
480
480
|
...metaRow?.tags !== void 0 ? { tags: metaRow.tags } : {},
|
|
481
|
-
...metaRow?.display !== void 0 ? { display: metaRow.display } : {}
|
|
481
|
+
...metaRow?.display !== void 0 ? { display: metaRow.display } : {},
|
|
482
|
+
...metaRow?.identifiers !== void 0 ? { identifiers: metaRow.identifiers } : {}
|
|
482
483
|
};
|
|
483
484
|
}
|
|
484
485
|
function resolveDeviceById(registry, deviceId) {
|
|
@@ -3062,6 +3063,7 @@ async function listAll(pctx, input) {
|
|
|
3062
3063
|
...m.primaryChildPreference !== void 0 ? { primaryChildPreference: m.primaryChildPreference } : {},
|
|
3063
3064
|
...m.tags !== void 0 ? { tags: m.tags } : {},
|
|
3064
3065
|
...m.display !== void 0 ? { display: m.display } : {},
|
|
3066
|
+
...m.identifiers !== void 0 ? { identifiers: m.identifiers } : {},
|
|
3065
3067
|
...(() => {
|
|
3066
3068
|
if (slim) return {};
|
|
3067
3069
|
const si = projectSourceInfo(persistedConfig ?? {}, stableId, aid, metadata);
|
|
@@ -3115,6 +3117,7 @@ async function getDevice(pctx, input) {
|
|
|
3115
3117
|
...m.primaryChildPreference !== void 0 ? { primaryChildPreference: m.primaryChildPreference } : {},
|
|
3116
3118
|
...m.tags !== void 0 ? { tags: m.tags } : {},
|
|
3117
3119
|
...m.display !== void 0 ? { display: m.display } : {},
|
|
3120
|
+
...m.identifiers !== void 0 ? { identifiers: m.identifiers } : {},
|
|
3118
3121
|
...sourceInfoGetDevice !== void 0 ? { sourceInfo: sourceInfoGetDevice } : {}
|
|
3119
3122
|
};
|
|
3120
3123
|
}
|
|
@@ -3195,6 +3198,7 @@ function projectChildren(pctx, parentDeviceId, ownerAddonId, childRows, liveChil
|
|
|
3195
3198
|
...m.primaryChildPreference !== void 0 ? { primaryChildPreference: m.primaryChildPreference } : {},
|
|
3196
3199
|
...m.tags !== void 0 ? { tags: m.tags } : {},
|
|
3197
3200
|
...m.display !== void 0 ? { display: m.display } : {},
|
|
3201
|
+
...m.identifiers !== void 0 ? { identifiers: m.identifiers } : {},
|
|
3198
3202
|
...sourceInfoChild !== void 0 ? { sourceInfo: sourceInfoChild } : {}
|
|
3199
3203
|
});
|
|
3200
3204
|
}
|
|
@@ -8795,6 +8799,99 @@ async function removeLocation(pctx, input) {
|
|
|
8795
8799
|
});
|
|
8796
8800
|
}
|
|
8797
8801
|
//#endregion
|
|
8802
|
+
//#region src/builtins/device-manager/device-identifiers-action.ts
|
|
8803
|
+
/**
|
|
8804
|
+
* `device-manager.setIdentifiers` — the ONE writer of a device's provider-declared
|
|
8805
|
+
* identifiers (D1059).
|
|
8806
|
+
*
|
|
8807
|
+
* Who may write: the provider that OWNS the device, and nobody else. Ownership is
|
|
8808
|
+
* the caller stamp the transport sets (`callerAddonId`, never in an input schema,
|
|
8809
|
+
* so a session cannot supply it — `CALLER_STAMPED_CAPABILITIES` lists
|
|
8810
|
+
* `device-manager`) compared with the row's `addonId`. An operator session carries
|
|
8811
|
+
* no stamp and is refused; so is another addon. The operator reads identifiers, it
|
|
8812
|
+
* never edits them: the free-form, editable blob is `metadata`.
|
|
8813
|
+
*
|
|
8814
|
+
* The stored value is `mergeIdentifiers(stored, declared, unread)`: each kind the
|
|
8815
|
+
* declaration carries replaces the stored one, each kind it lacks is removed,
|
|
8816
|
+
* except the kinds in `unread` (the provider's read FAILED), which keep what was
|
|
8817
|
+
* stored — a failed read never erases a fact (D49). An entry whose value and
|
|
8818
|
+
* origin are unchanged keeps its stored `readAt` (when that value was first read),
|
|
8819
|
+
* so a provider re-declaring the same values on every boot writes nothing and
|
|
8820
|
+
* emits nothing. `null` clears every kind not in `unread`.
|
|
8821
|
+
*/
|
|
8822
|
+
var SetIdentifiersRefusedError = class extends Error {
|
|
8823
|
+
reason;
|
|
8824
|
+
constructor(reason, message) {
|
|
8825
|
+
super(message);
|
|
8826
|
+
this.reason = reason;
|
|
8827
|
+
this.name = "SetIdentifiersRefusedError";
|
|
8828
|
+
}
|
|
8829
|
+
};
|
|
8830
|
+
/** The caller the transport stamped; `null` when the call carries none. */
|
|
8831
|
+
function stampedCaller(input) {
|
|
8832
|
+
const raw = Reflect.get(Object(input), "callerAddonId");
|
|
8833
|
+
return typeof raw === "string" && raw.length > 0 ? raw : null;
|
|
8834
|
+
}
|
|
8835
|
+
async function setIdentifiers(pctx, input) {
|
|
8836
|
+
const { deviceId } = input;
|
|
8837
|
+
const logger = pctx.host.ctx.logger;
|
|
8838
|
+
const caller = stampedCaller(input);
|
|
8839
|
+
const parsed = DeviceIdentifiersSchema.nullable().safeParse(input.identifiers);
|
|
8840
|
+
if (!parsed.success) {
|
|
8841
|
+
logger.warn("setIdentifiers refused — the declaration is not in its normalised form", {
|
|
8842
|
+
tags: { deviceId },
|
|
8843
|
+
meta: {
|
|
8844
|
+
caller,
|
|
8845
|
+
issues: parsed.error.issues.map((i) => i.path.join("."))
|
|
8846
|
+
}
|
|
8847
|
+
});
|
|
8848
|
+
throw new SetIdentifiersRefusedError("invalid", `[device-manager] setIdentifiers: device ${deviceId} — declaration not normalised (use normaliseIdentifiers)`);
|
|
8849
|
+
}
|
|
8850
|
+
const next = parsed.data === null || isEmptyIdentifiers(parsed.data) ? null : parsed.data;
|
|
8851
|
+
const outcome = await pctx.metaStore.withMetaWriteLock(async () => {
|
|
8852
|
+
const persisted = await pctx.metaStore.resolvePersistedById(deviceId);
|
|
8853
|
+
if (!persisted) return { kind: "unknown-device" };
|
|
8854
|
+
if (caller === null || caller !== persisted.addonId) return {
|
|
8855
|
+
kind: "not-owner",
|
|
8856
|
+
owner: persisted.addonId
|
|
8857
|
+
};
|
|
8858
|
+
const stored = persisted.meta.identifiers ?? null;
|
|
8859
|
+
const merged = mergeIdentifiers(stored, next, input.unread ?? []);
|
|
8860
|
+
if (sameIdentifiers(stored, merged)) return { kind: "unchanged" };
|
|
8861
|
+
await pctx.metaStore.rows.patch(deviceId, { identifiers: merged });
|
|
8862
|
+
return {
|
|
8863
|
+
kind: "written",
|
|
8864
|
+
value: merged
|
|
8865
|
+
};
|
|
8866
|
+
});
|
|
8867
|
+
if (outcome.kind === "unknown-device") throw new SetIdentifiersRefusedError("unknown-device", `[device-manager] setIdentifiers: unknown device id=${deviceId}`);
|
|
8868
|
+
if (outcome.kind === "not-owner") {
|
|
8869
|
+
logger.warn("setIdentifiers refused — only the owning provider declares identifiers", {
|
|
8870
|
+
tags: { deviceId },
|
|
8871
|
+
meta: {
|
|
8872
|
+
caller,
|
|
8873
|
+
owner: outcome.owner
|
|
8874
|
+
}
|
|
8875
|
+
});
|
|
8876
|
+
throw new SetIdentifiersRefusedError("not-owner", `[device-manager] setIdentifiers: device ${deviceId} belongs to ${outcome.owner}; caller ${caller ?? "(unstamped)"} may not declare its identifiers`);
|
|
8877
|
+
}
|
|
8878
|
+
if (outcome.kind === "unchanged") return;
|
|
8879
|
+
pctx.host.ctx.eventBus.emit({
|
|
8880
|
+
id: randomUUID(),
|
|
8881
|
+
timestamp: /* @__PURE__ */ new Date(),
|
|
8882
|
+
source: {
|
|
8883
|
+
type: "device",
|
|
8884
|
+
id: deviceId
|
|
8885
|
+
},
|
|
8886
|
+
category: EventCategory$1.DeviceMetaChanged,
|
|
8887
|
+
data: {
|
|
8888
|
+
deviceId,
|
|
8889
|
+
field: "identifiers",
|
|
8890
|
+
value: outcome.value
|
|
8891
|
+
}
|
|
8892
|
+
});
|
|
8893
|
+
}
|
|
8894
|
+
//#endregion
|
|
8798
8895
|
//#region src/builtins/device-manager/linked-devices-manual-backfill.ts
|
|
8799
8896
|
var LINKED_MANUAL_BACKFILL_MARKER_KEY = "_linkedDevicesManualBackfillVersion";
|
|
8800
8897
|
function planManualBackfill(params) {
|
|
@@ -10332,6 +10429,10 @@ var DEVICE_ROWS_COLUMNS = [
|
|
|
10332
10429
|
{
|
|
10333
10430
|
name: "metadata",
|
|
10334
10431
|
type: "JSON"
|
|
10432
|
+
},
|
|
10433
|
+
{
|
|
10434
|
+
name: "identifiers",
|
|
10435
|
+
type: "JSON"
|
|
10335
10436
|
}
|
|
10336
10437
|
];
|
|
10337
10438
|
/**
|
|
@@ -10451,6 +10552,7 @@ function decodeDeviceRow(data) {
|
|
|
10451
10552
|
const primaryChildPreference = readStringArray(data["primaryChildPreference"]);
|
|
10452
10553
|
const rawDisplay = data["display"];
|
|
10453
10554
|
const rawMetadata = data["metadata"];
|
|
10555
|
+
const identifiers = DeviceIdentifiersSchema.safeParse(data["identifiers"]);
|
|
10454
10556
|
return {
|
|
10455
10557
|
meta: {
|
|
10456
10558
|
id: deviceId,
|
|
@@ -10472,7 +10574,8 @@ function decodeDeviceRow(data) {
|
|
|
10472
10574
|
...isChildLayout(rawChildLayout) ? { childLayout: rawChildLayout } : {},
|
|
10473
10575
|
...primaryChildPreference !== void 0 ? { primaryChildPreference } : {},
|
|
10474
10576
|
...role !== void 0 ? { role } : {},
|
|
10475
|
-
...isPlainObject$1(rawDisplay) ? { display: toDisplayOverride(rawDisplay) } : {}
|
|
10577
|
+
...isPlainObject$1(rawDisplay) ? { display: toDisplayOverride(rawDisplay) } : {},
|
|
10578
|
+
...identifiers.success ? { identifiers: identifiers.data } : {}
|
|
10476
10579
|
},
|
|
10477
10580
|
metadata: isPlainObject$1(rawMetadata) ? rawMetadata : null,
|
|
10478
10581
|
registered: readBoolean(data["registered"]) ?? false
|
|
@@ -10518,7 +10621,8 @@ function encodeDeviceRow(meta, extra = {}) {
|
|
|
10518
10621
|
childLayout: meta.childLayout ?? null,
|
|
10519
10622
|
primaryChildPreference: meta.primaryChildPreference === void 0 ? null : [...meta.primaryChildPreference],
|
|
10520
10623
|
role: meta.role ?? null,
|
|
10521
|
-
display: meta.display ?? null
|
|
10624
|
+
display: meta.display ?? null,
|
|
10625
|
+
identifiers: meta.identifiers ?? null
|
|
10522
10626
|
};
|
|
10523
10627
|
if (extra.metadata !== void 0) row["metadata"] = extra.metadata;
|
|
10524
10628
|
return row;
|
|
@@ -11167,6 +11271,41 @@ var RunningFlipDetector = class {
|
|
|
11167
11271
|
}
|
|
11168
11272
|
};
|
|
11169
11273
|
//#endregion
|
|
11274
|
+
//#region src/builtins/device-manager/workload-transition.ts
|
|
11275
|
+
function readState(slice) {
|
|
11276
|
+
const parsed = WorkloadStateSchema.safeParse(slice["state"]);
|
|
11277
|
+
return parsed.success ? parsed.data : null;
|
|
11278
|
+
}
|
|
11279
|
+
/**
|
|
11280
|
+
* Remembers each workload's last SETTLED state (running, paused, stopped,
|
|
11281
|
+
* crashed) and turns a move away from it into the cap's events. `starting` /
|
|
11282
|
+
* `stopping` and an unknown state are never remembered, so stopped → starting →
|
|
11283
|
+
* running is one `started`, and crashed → starting → running one `recovered`.
|
|
11284
|
+
*
|
|
11285
|
+
* The first state seen for a device is a seed: it raises nothing, so a hub
|
|
11286
|
+
* restart does not announce every running container as started.
|
|
11287
|
+
*/
|
|
11288
|
+
var WorkloadTransitionDetector = class {
|
|
11289
|
+
#settled = /* @__PURE__ */ new Map();
|
|
11290
|
+
note(deviceId, slice) {
|
|
11291
|
+
const state = readState(slice);
|
|
11292
|
+
const previous = this.#settled.get(deviceId);
|
|
11293
|
+
const kind = workloadTransition(previous, state);
|
|
11294
|
+
if (state !== null && isWorkloadSettled(state)) this.#settled.set(deviceId, state);
|
|
11295
|
+
if (kind === null || state === null || previous === void 0) return null;
|
|
11296
|
+
return {
|
|
11297
|
+
kind,
|
|
11298
|
+
deviceId,
|
|
11299
|
+
state,
|
|
11300
|
+
previous,
|
|
11301
|
+
since: typeof slice["since"] === "number" && Number.isFinite(slice["since"]) ? slice["since"] : null
|
|
11302
|
+
};
|
|
11303
|
+
}
|
|
11304
|
+
forget(deviceId) {
|
|
11305
|
+
this.#settled.delete(deviceId);
|
|
11306
|
+
}
|
|
11307
|
+
};
|
|
11308
|
+
//#endregion
|
|
11170
11309
|
//#region src/builtins/device-manager/last-active-mode.ts
|
|
11171
11310
|
/**
|
|
11172
11311
|
* The last mode a climate device actually RAN (D224): "turn on" needs a mode to
|
|
@@ -11758,6 +11897,7 @@ var DeviceStateMirror = class {
|
|
|
11758
11897
|
writer;
|
|
11759
11898
|
/** Edge detector for `running-state` flip events (D933). */
|
|
11760
11899
|
runningFlip = new RunningFlipDetector();
|
|
11900
|
+
workloadTransitions = new WorkloadTransitionDetector();
|
|
11761
11901
|
constructor(ctx, policyFor = runtimeStatePolicyFor, schemaFor = defaultSchemaFor) {
|
|
11762
11902
|
this.ctx = ctx;
|
|
11763
11903
|
this.policyFor = policyFor;
|
|
@@ -11990,6 +12130,7 @@ var DeviceStateMirror = class {
|
|
|
11990
12130
|
await this.seeding.get(deviceId)?.catch(() => void 0);
|
|
11991
12131
|
await this.writer.forget(deviceId);
|
|
11992
12132
|
this.stateMirror.delete(deviceId);
|
|
12133
|
+
this.workloadTransitions.forget(deviceId);
|
|
11993
12134
|
this.claims.clearDevice(deviceId);
|
|
11994
12135
|
this.seeded.delete(deviceId);
|
|
11995
12136
|
this.rowRead.delete(deviceId);
|
|
@@ -12290,6 +12431,30 @@ var DeviceStateMirror = class {
|
|
|
12290
12431
|
for (const deviceId of deviceIds) out[String(deviceId)] = this.snapshotForDevice(deviceId);
|
|
12291
12432
|
return out;
|
|
12292
12433
|
}
|
|
12434
|
+
/**
|
|
12435
|
+
* The `workload` cap's events (#585): judged from the PUBLIC slice like the
|
|
12436
|
+
* running flip, so a provider only writes its state. The first state seen is
|
|
12437
|
+
* a seed and raises nothing.
|
|
12438
|
+
*/
|
|
12439
|
+
emitWorkloadTransition(deviceId, slice) {
|
|
12440
|
+
const transition = this.workloadTransitions.note(deviceId, slice);
|
|
12441
|
+
if (transition === null) return;
|
|
12442
|
+
this.ctx.eventBus.emit({
|
|
12443
|
+
id: randomUUID(),
|
|
12444
|
+
timestamp: /* @__PURE__ */ new Date(),
|
|
12445
|
+
source: {
|
|
12446
|
+
type: "device",
|
|
12447
|
+
id: deviceId
|
|
12448
|
+
},
|
|
12449
|
+
category: WORKLOAD_TRANSITION_CATEGORY[transition.kind],
|
|
12450
|
+
data: {
|
|
12451
|
+
deviceId,
|
|
12452
|
+
state: transition.state,
|
|
12453
|
+
previous: transition.previous,
|
|
12454
|
+
since: transition.since
|
|
12455
|
+
}
|
|
12456
|
+
});
|
|
12457
|
+
}
|
|
12293
12458
|
/** Remember a restored running bit so the first public merge does not emit a flip. */
|
|
12294
12459
|
seedRunningFlip(deviceId) {
|
|
12295
12460
|
const slice = this.capSlice(deviceId, RUNNING_STATE_CAP);
|
|
@@ -12320,6 +12485,7 @@ var DeviceStateMirror = class {
|
|
|
12320
12485
|
}
|
|
12321
12486
|
});
|
|
12322
12487
|
}
|
|
12488
|
+
if (capName === workloadCapability.name) this.emitWorkloadTransition(deviceId, slice);
|
|
12323
12489
|
this.ctx.eventBus.emit({
|
|
12324
12490
|
id: randomUUID(),
|
|
12325
12491
|
timestamp: /* @__PURE__ */ new Date(),
|
|
@@ -14002,6 +14168,7 @@ var DeviceManagerAddon = class extends BaseAddon {
|
|
|
14002
14168
|
setPrimaryChildPreference: (input) => setPrimaryChildPreference(pctx, input),
|
|
14003
14169
|
setRole: (input) => setRole(pctx, input),
|
|
14004
14170
|
setDisplay: (input) => setDisplay(pctx, input),
|
|
14171
|
+
setIdentifiers: (input) => setIdentifiers(pctx, input),
|
|
14005
14172
|
getRoleDisplayDefaults: (input) => getRoleDisplayDefaults(pctx, input),
|
|
14006
14173
|
setRoleDisplayDefaults: (input) => setRoleDisplayDefaults(pctx, input),
|
|
14007
14174
|
applyInitialMeta: (input) => applyInitialMeta(pctx, input),
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* the decoders that turn an untyped store read into one of them — nothing that
|
|
8
8
|
* touches a store, a device or an event.
|
|
9
9
|
*/
|
|
10
|
-
import type { ChildLayout, DeviceDisplayOverride, IconKey, RoleDisplayDefault } from "@camstack/types";
|
|
10
|
+
import type { ChildLayout, DeviceDisplayOverride, DeviceIdentifiers, IconKey, RoleDisplayDefault } from "@camstack/types";
|
|
11
11
|
/**
|
|
12
12
|
* Wire shape matching `z.infer<typeof SettingsSchemaWithValuesSchema>` —
|
|
13
13
|
* duplicated as a plain interface because importing the Zod schema across
|
|
@@ -176,6 +176,10 @@ export interface PersistedDeviceMeta {
|
|
|
176
176
|
* lifecycle as `childLayout`. Absent ⇒ no override. Applied at render time
|
|
177
177
|
* only — storage stays in source units. */
|
|
178
178
|
display?: DeviceDisplayOverride;
|
|
179
|
+
/** Provider-declared identifiers (D1059), set via `setIdentifiers` by the
|
|
180
|
+
* owning provider only. Absent ⇒ none declared. Rides the device row like
|
|
181
|
+
* `display`, so a re-registration never clobbers it. */
|
|
182
|
+
identifiers?: DeviceIdentifiers;
|
|
179
183
|
}
|
|
180
184
|
/**
|
|
181
185
|
* The device-manager's own `addon-settings` row set — everything that is NOT a
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ChildLayout, CollectionColumn, CollectionIndex, DeviceDisplayOverride, IScopedLogger, MutationFilter, QueryFilter, SettingsRecord, SettingsStoreClient } from "@camstack/types";
|
|
1
|
+
import type { ChildLayout, CollectionColumn, CollectionIndex, DeviceDisplayOverride, DeviceIdentifiers, IScopedLogger, MutationFilter, QueryFilter, SettingsRecord, SettingsStoreClient } from "@camstack/types";
|
|
2
2
|
import type { RetiredRowStore } from "../sqlite-storage/retired-settings-keys.js";
|
|
3
3
|
import type { PersistedDeviceMeta } from "./device-meta-types.js";
|
|
4
4
|
import { FleetReadCensus } from "./fleet-read-census.js";
|
|
@@ -150,6 +150,7 @@ export interface DeviceRowPatch {
|
|
|
150
150
|
readonly primaryChildPreference?: readonly string[] | null;
|
|
151
151
|
readonly role?: string | null;
|
|
152
152
|
readonly display?: DeviceDisplayOverride | null;
|
|
153
|
+
readonly identifiers?: DeviceIdentifiers | null;
|
|
153
154
|
readonly metadata?: Record<string, unknown> | null;
|
|
154
155
|
}
|
|
155
156
|
/**
|
|
@@ -163,7 +164,7 @@ export interface DeviceRowPatch {
|
|
|
163
164
|
* required here, and the type is what keeps it that way.
|
|
164
165
|
*
|
|
165
166
|
* Columns NOT listed — `integrationId`, `linkDeviceId`, `primaryChildEntityId`,
|
|
166
|
-
* `childLayout`, `primaryChildPreference`, `role`, `display`, `metadata` — are not in the statement at
|
|
167
|
+
* `childLayout`, `primaryChildPreference`, `role`, `display`, `identifiers`, `metadata` — are not in the statement at
|
|
167
168
|
* all, so re-registering preserves them. The blob shape had to re-state each
|
|
168
169
|
* one to avoid clobbering it, and every field added since has been one more
|
|
169
170
|
* spread somebody had to remember.
|
|
@@ -63,6 +63,7 @@ export declare class DeviceStateMirror {
|
|
|
63
63
|
private readonly writer;
|
|
64
64
|
/** Edge detector for `running-state` flip events (D933). */
|
|
65
65
|
private readonly runningFlip;
|
|
66
|
+
private readonly workloadTransitions;
|
|
66
67
|
constructor(ctx: AddonContext, policyFor?: RuntimeStatePolicyLookup, schemaFor?: RuntimeStateSchemaLookup);
|
|
67
68
|
/** Set once by the device-manager: told, after the mirror stored it, of every native slice that actually changed (D1022). */
|
|
68
69
|
setTransitionTap(tap: SliceChangeTap | null): void;
|
|
@@ -256,6 +257,12 @@ export declare class DeviceStateMirror {
|
|
|
256
257
|
/** Whole-system mirror dump. Backs `deviceState.getAllSnapshots` — one
|
|
257
258
|
* round-trip for a warm boot instead of N per-device calls. */
|
|
258
259
|
allSnapshots(): Record<string, Record<string, Record<string, unknown>>>;
|
|
260
|
+
/**
|
|
261
|
+
* The `workload` cap's events (#585): judged from the PUBLIC slice like the
|
|
262
|
+
* running flip, so a provider only writes its state. The first state seen is
|
|
263
|
+
* a seed and raises nothing.
|
|
264
|
+
*/
|
|
265
|
+
private emitWorkloadTransition;
|
|
259
266
|
/** Remember a restored running bit so the first public merge does not emit a flip. */
|
|
260
267
|
private seedRunningFlip;
|
|
261
268
|
/**
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type WorkloadSettledState, type WorkloadState, type WorkloadTransitionKind } from "@camstack/types";
|
|
2
|
+
/** One workload event the mirror emits (#585). */
|
|
3
|
+
export interface WorkloadTransitionEvent {
|
|
4
|
+
readonly kind: WorkloadTransitionKind;
|
|
5
|
+
readonly deviceId: number;
|
|
6
|
+
readonly state: WorkloadState;
|
|
7
|
+
readonly previous: WorkloadSettledState;
|
|
8
|
+
readonly since: number | null;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Remembers each workload's last SETTLED state (running, paused, stopped,
|
|
12
|
+
* crashed) and turns a move away from it into the cap's events. `starting` /
|
|
13
|
+
* `stopping` and an unknown state are never remembered, so stopped → starting →
|
|
14
|
+
* running is one `started`, and crashed → starting → running one `recovered`.
|
|
15
|
+
*
|
|
16
|
+
* The first state seen for a device is a seed: it raises nothing, so a hub
|
|
17
|
+
* restart does not announce every running container as started.
|
|
18
|
+
*/
|
|
19
|
+
export declare class WorkloadTransitionDetector {
|
|
20
|
+
#private;
|
|
21
|
+
note(deviceId: number, slice: Readonly<Record<string, unknown>>): WorkloadTransitionEvent | null;
|
|
22
|
+
forget(deviceId: number): void;
|
|
23
|
+
}
|