@camstack/server 1.2.890 → 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.
Files changed (119) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/api/trpc/generated-cap-mounts.js +2 -1
  3. package/dist/api/trpc/generated-cap-routers.js +212 -39
  4. package/dist/core/addon/addon-registry.service.js +47 -0
  5. package/dist/core/addon/retire-undeclared-fixed-integrations.js +57 -0
  6. package/package.json +31 -19
  7. package/system/dist/addon-runner.js +25 -9
  8. package/system/dist/addon-runner.mjs +25 -9
  9. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +1 -1
  10. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +1 -1
  11. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +1 -1
  12. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +1 -1
  13. package/system/dist/builtins/alerts/alerts.addon.js +1 -1
  14. package/system/dist/builtins/alerts/alerts.addon.mjs +1 -1
  15. package/system/dist/builtins/autotrack/index.js +1 -1
  16. package/system/dist/builtins/autotrack/index.mjs +1 -1
  17. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +2 -2
  18. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +2 -2
  19. package/system/dist/builtins/calendars/calendars.addon.js +1 -1
  20. package/system/dist/builtins/calendars/calendars.addon.mjs +1 -1
  21. package/system/dist/builtins/camera-grid/addon.d.ts +65 -41
  22. package/system/dist/builtins/camera-grid/grid-blocks.d.ts +51 -0
  23. package/system/dist/builtins/camera-grid/grid-camera-device.d.ts +4 -3
  24. package/system/dist/builtins/camera-grid/grid-layout-native-provider.d.ts +3 -1
  25. package/system/dist/builtins/camera-grid/grid-plan.d.ts +3 -3
  26. package/system/dist/builtins/camera-grid/index.d.ts +2 -6
  27. package/system/dist/builtins/camera-grid/index.js +431 -727
  28. package/system/dist/builtins/camera-grid/index.mjs +428 -719
  29. package/system/dist/builtins/composer/composed-device.d.ts +12 -2
  30. package/system/dist/builtins/composer/composer.addon.js +28 -10
  31. package/system/dist/builtins/composer/composer.addon.mjs +28 -10
  32. package/system/dist/builtins/composer/composition-declarations.d.ts +3 -1
  33. package/system/dist/builtins/console-logging/index.js +1 -1
  34. package/system/dist/builtins/console-logging/index.mjs +1 -1
  35. package/system/dist/builtins/core-blocks/core-blocks.addon.js +283 -51
  36. package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +284 -52
  37. package/system/dist/builtins/core-blocks/hero-layout-service.d.ts +19 -1
  38. package/system/dist/builtins/core-blocks/power-source-devices.d.ts +9 -0
  39. package/system/dist/builtins/core-blocks/power-source-service.d.ts +39 -2
  40. package/system/dist/builtins/core-blocks/tags-service.d.ts +20 -3
  41. package/system/dist/builtins/core-blocks/tags-wiring.d.ts +15 -2
  42. package/system/dist/builtins/device-history/device-history.addon.js +2 -2
  43. package/system/dist/builtins/device-history/device-history.addon.mjs +2 -2
  44. package/system/dist/builtins/device-manager/device-identifiers-action.d.ts +9 -0
  45. package/system/dist/builtins/device-manager/device-manager.addon.js +172 -5
  46. package/system/dist/builtins/device-manager/device-manager.addon.mjs +172 -5
  47. package/system/dist/builtins/device-manager/device-meta-types.d.ts +5 -1
  48. package/system/dist/builtins/device-manager/device-row-store.d.ts +3 -2
  49. package/system/dist/builtins/device-manager/device-state-mirror.d.ts +7 -0
  50. package/system/dist/builtins/device-manager/workload-transition.d.ts +23 -0
  51. package/system/dist/builtins/hub-forwarder/index.js +1 -1
  52. package/system/dist/builtins/hub-forwarder/index.mjs +1 -1
  53. package/system/dist/builtins/keychain/index.js +4 -4
  54. package/system/dist/builtins/keychain/index.mjs +4 -4
  55. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.js +1 -1
  56. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +1 -1
  57. package/system/dist/builtins/local-auth/local-auth.addon.js +2 -2
  58. package/system/dist/builtins/local-auth/local-auth.addon.mjs +2 -2
  59. package/system/dist/builtins/local-network/local-network.addon.js +3 -3
  60. package/system/dist/builtins/local-network/local-network.addon.mjs +3 -3
  61. package/system/dist/builtins/loki-logging/index.js +1 -1
  62. package/system/dist/builtins/loki-logging/index.mjs +1 -1
  63. package/system/dist/builtins/native-metrics/native-metrics.addon.js +1 -1
  64. package/system/dist/builtins/native-metrics/native-metrics.addon.mjs +1 -1
  65. package/system/dist/builtins/platform-probe/index.js +1 -1
  66. package/system/dist/builtins/platform-probe/index.mjs +1 -1
  67. package/system/dist/builtins/record-entries/index.js +1 -1
  68. package/system/dist/builtins/record-entries/index.mjs +1 -1
  69. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +1 -1
  70. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
  71. package/system/dist/builtins/snapshot/index.js +1 -1
  72. package/system/dist/builtins/snapshot/index.mjs +1 -1
  73. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.js +1 -1
  74. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +1 -1
  75. package/system/dist/builtins/sqlite-storage/index.js +1 -1
  76. package/system/dist/builtins/sqlite-storage/index.mjs +1 -1
  77. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.js +3 -3
  78. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +3 -3
  79. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +1 -1
  80. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +1 -1
  81. package/system/dist/builtins/system-config/system-config.addon.js +3 -3
  82. package/system/dist/builtins/system-config/system-config.addon.mjs +284 -284
  83. package/system/dist/builtins/winston-logging/index.js +1 -1
  84. package/system/dist/builtins/winston-logging/index.mjs +1 -1
  85. package/system/dist/{capture-engine-C1vdBL88.js → capture-engine-DHmlkW_d.js} +1 -1
  86. package/system/dist/{capture-engine-B1bMuzVX.mjs → capture-engine-sl6e9f9S.mjs} +1 -1
  87. package/system/dist/{composition-sources-Dj6qn5PP.mjs → composition-sources-CznD85Ri.mjs} +1 -1
  88. package/system/dist/{composition-sources-BfLlyKRe.js → composition-sources-PqcZfe3j.js} +1 -1
  89. package/system/dist/{constants-Ba51ywI4.mjs → constants-CHwj_mIM.mjs} +1 -1
  90. package/system/dist/{constants-DuB_xXYx.js → constants-_2SOk0By.js} +1 -1
  91. package/system/dist/{device-ca-CkXjf3ms.mjs → device-ca-D2H1EMUY.mjs} +1 -1
  92. package/system/dist/{device-ca-CVjaotgX.js → device-ca-WIEO5ZcE.js} +1 -1
  93. package/system/dist/{dist-BKojK6Wf.mjs → dist-DbAhCrHy.mjs} +2468 -454
  94. package/system/dist/{dist-BjhII4Uq.js → dist-yx2KHo3b.js} +2575 -453
  95. package/system/dist/file-host-worker.js +1 -1
  96. package/system/dist/file-host-worker.mjs +1 -1
  97. package/system/dist/{hub-identity-C0qf888i.mjs → hub-identity-BcvZqT0L.mjs} +1 -1
  98. package/system/dist/{hub-identity-C0ehkt78.js → hub-identity-Buegac-w.js} +1 -1
  99. package/system/dist/{hub-mdns-ciao-BYe34S2Q.mjs → hub-mdns-ciao-B6K_dO2s.mjs} +2 -2
  100. package/system/dist/{hub-mdns-ciao-DJHjyjvT.js → hub-mdns-ciao-DcNPj7WJ.js} +2 -2
  101. package/system/dist/index.js +33 -19
  102. package/system/dist/index.mjs +33 -19
  103. package/system/dist/kernel/moleculer/child-cap-dispatch.d.ts +3 -6
  104. package/system/dist/kernel/moleculer/switch-toggle.d.ts +7 -2
  105. package/system/dist/{legacy-integration-rows-door-G6EceE_J.js → legacy-integration-rows-door-BsZyVNiR.js} +1 -1
  106. package/system/dist/{legacy-integration-rows-door-BEYgXSXr.mjs → legacy-integration-rows-door-DHOJeDPG.mjs} +1 -1
  107. package/system/dist/{rename-composition-block-D1mO51F9.js → rename-composition-block-BXMor7MR.js} +1 -1
  108. package/system/dist/{rename-composition-block-D6bq3Twf.mjs → rename-composition-block-DcVS1LuC.mjs} +1 -1
  109. package/system/dist/{restore-archive-FXsCWq_f.mjs → restore-archive-BG8VJ8Ar.mjs} +82 -82
  110. package/system/dist/{restore-archive-CJvMq13C.js → restore-archive-BURufVQd.js} +1 -1
  111. package/system/dist/{wal-maintenance-Ci9Dl-lB.mjs → wal-maintenance-B4wGD6QR.mjs} +0 -0
  112. package/system/dist/{wal-maintenance-COJ_JxrD.js → wal-maintenance-CeaJyKNT.js} +0 -0
  113. package/system/package.json +2 -5
  114. package/system/dist/builtins/camera-grid/grid-camera-declarations.d.ts +0 -59
  115. package/system/dist/builtins/camera-grid/grid-instances.d.ts +0 -40
  116. package/system/dist/builtins/camera-grid/grid-record-kinds.d.ts +0 -31
  117. package/system/dist/builtins/camera-grid/migrations/__fixtures__/seed.d.ts +0 -13
  118. package/system/dist/builtins/camera-grid/migrations/camera-grids-to-records.d.ts +0 -26
  119. package/system/dist/builtins/camera-grid/migrations/index.d.ts +0 -6
@@ -10,23 +10,47 @@
10
10
  * The link and the off time are read from the STORED composition on each call
11
11
  * (D676), never cached as a second copy. A forced restart is switch off now,
12
12
  * switch on after `offSeconds`, through an injected scheduler so a spec drives
13
- * the clock; the pending switch-on is cancelled on `stop()`.
13
+ * the clock; the pending switch-on is cancelled on `stop()`. A switch that declares
14
+ * a native power cycle (a PoE port) is cycled in one call instead, and never
15
+ * switched off or on. A switch that ANSWERED it only reports (D1058) is never
16
+ * switched on or off: power on / off are refused as `not-settable`, and `getStatus`
17
+ * says so (`switchSettable`) for the surfaces that withdraw them.
14
18
  *
15
19
  * Every refusal is a typed result with its reason, logged with the device tag.
16
20
  */
17
- import { type CompositionSourceRef, type CoreBlock, type IPowerSourceProvider, type IScopedLogger, type PowerSourceActionResult, type PowerSourceInfo } from "@camstack/types";
21
+ import { type CompositionSourceRef, type CoreBlock, type IPowerSourceProvider, type IScopedLogger, type PowerSourceActionResult, type PowerSourceInfo, type SwitchOptions } from "@camstack/types";
18
22
  /** What the service needs to know about a device it names. */
19
23
  export interface PowerSourceDevice {
20
24
  readonly id: number;
21
25
  readonly name: string;
22
26
  readonly online: boolean;
23
27
  }
28
+ /** `switch.getOptions` FAILED (not absent): what the switch can do is unknown. */
29
+ export declare class SwitchOptionsUnreadableError extends Error {
30
+ readonly switchDeviceId: number;
31
+ constructor(switchDeviceId: number, cause: unknown);
32
+ }
24
33
  export interface PowerSourceDevices {
25
34
  /** The device for a source ref, or null when it cannot be found. */
26
35
  readonly find: (ref: CompositionSourceRef) => Promise<PowerSourceDevice | null>;
27
36
  /** The switch's on/off state, or null when it has none. Throws when it cannot be read. */
28
37
  readonly readOn: (switchDeviceId: number) => Promise<boolean | null>;
29
38
  readonly setOn: (switchDeviceId: number, on: boolean) => Promise<void>;
39
+ /**
40
+ * What the switch can do (`switch.getOptions`): the defaults when its provider has no such
41
+ * method, `SwitchOptionsUnreadableError` when the read FAILED.
42
+ * Absent = every switch here is a plain on/off switch.
43
+ */
44
+ readonly options?: (switchDeviceId: number) => Promise<SwitchOptions>;
45
+ /**
46
+ * Cut and restore the switch's output in ONE native call, when its provider declares it
47
+ * (`switch.getOptions().supportsPowerCycle`). Resolves true when it cycled, false when the
48
+ * switch has no native cycle (the restart is then off / wait / on). Throws
49
+ * `SwitchOptionsUnreadableError` when what the switch can do could not be read, and any other
50
+ * error when the cycle call fails.
51
+ * Absent = no switch here has one.
52
+ */
53
+ readonly cycle?: (switchDeviceId: number) => Promise<boolean>;
30
54
  }
31
55
  export interface PowerSourceTimer {
32
56
  readonly cancel: () => void;
@@ -45,6 +69,12 @@ export declare class PowerSourceService implements IPowerSourceProvider {
45
69
  private readonly deps;
46
70
  /** Restarts whose switch-on has not run yet, by device id. */
47
71
  private readonly restarting;
72
+ /**
73
+ * Devices whose switch-options read is failing now: warned once per streak, cleared by a
74
+ * success or when the device is no longer linked. A removed device leaves at most one bare id
75
+ * behind (this service has no removal hook); the set dies with the process.
76
+ */
77
+ private readonly optionsReadFailing;
48
78
  constructor(deps: PowerSourceServiceDeps);
49
79
  getStatus: ({ deviceId }: {
50
80
  deviceId: number;
@@ -62,6 +92,13 @@ export declare class PowerSourceService implements IPowerSourceProvider {
62
92
  stop(): void;
63
93
  private finishRestart;
64
94
  private switchTo;
95
+ /**
96
+ * Whether the switch can be set: `true` for a plain switch (no options reader, or a provider
97
+ * without `getOptions`), `null` when the read FAILED — never `false` for unknown. Every hero
98
+ * build reads `getStatus`, so a failing read warns once per device per failure streak (tagged);
99
+ * a successful read ends the streak.
100
+ */
101
+ private settableOf;
65
102
  /** The link and the switch, or the reason there is nothing to act on. Reads the switch state: unknown is refused. */
66
103
  private lookup;
67
104
  /** The stored link of the device `deviceId`, read from the customizations now. */
@@ -1,13 +1,15 @@
1
1
  /**
2
2
  * The `tags` cap (D1054). A tag lives on the record it labels — a core block, a
3
- * scheduler, a template, an action, a device — and only its STYLE (colour token,
4
- * icon) is registered here. This service is the one place that knows every owner
3
+ * scheduler, a template, an action, a device, a notification rule — and only
4
+ * its STYLE (colour token, icon) is registered here. This service is the one place that knows every owner
5
5
  * kind, so `rename` and `remove` are ONE server operation that rewrites all of
6
6
  * them; the browser never drives that sequence (a closed tab would split the
7
7
  * fleet across two spellings).
8
8
  *
9
9
  * Owners are reached through {@link TagOwnerPort}s: the local stores directly,
10
- * the devices through the device manager over `ctx.api` — never a second copy.
10
+ * the devices and notification rules through their caps over `ctx.api` — never
11
+ * a second copy. An owner that cannot be read degrades `list` (its count is
12
+ * `null`) and refuses `rename` / `remove` before any write.
11
13
  * Tags compare trimmed and case-insensitively (`sameTag`).
12
14
  */
13
15
  import { type IScopedLogger, type ITagsProvider, type RecordKindHandle, type TagUsageCounts } from "@camstack/types";
@@ -24,6 +26,15 @@ export interface TagOwnerPort {
24
26
  }
25
27
  export type TagOwnerKind = keyof TagUsageCounts;
26
28
  export type TagOwnerPorts = Readonly<Record<TagOwnerKind, TagOwnerPort>>;
29
+ /**
30
+ * A rename or remove refused because one owner kind could not be read. Nothing
31
+ * was written; `owner` names which one, so the operator knows what to bring back.
32
+ */
33
+ export declare class TagOwnerUnreachableError extends Error {
34
+ readonly owner: TagOwnerKind;
35
+ override readonly name = "TagOwnerUnreachableError";
36
+ constructor(owner: TagOwnerKind, tag: string, cause: unknown);
37
+ }
27
38
  export interface TagsServiceDeps {
28
39
  readonly owners: TagOwnerPorts;
29
40
  /** Row id = `tagKey(name)`. */
@@ -45,6 +56,12 @@ export declare class TagsService implements ITagsProvider {
45
56
  * operator repeats the same call (every step is idempotent).
46
57
  */
47
58
  private rewrite;
59
+ /**
60
+ * An owner's records for a rewrite. One that cannot be read refuses the whole
61
+ * call BEFORE anything is written: a rename applied to only some owners would
62
+ * leave the fleet split across two spellings.
63
+ */
64
+ private readOwnerOrRefuse;
48
65
  /** The style follows the tag; a merge onto a styled target keeps the TARGET's style. */
49
66
  private moveStyle;
50
67
  }
@@ -1,8 +1,9 @@
1
1
  /**
2
2
  * Builds the `tags` cap provider (D1054) over the stores core-blocks owns and the
3
- * device manager (over `ctx.api`, never a copy of its data).
3
+ * device manager and the notification rules (over `ctx.api`, never a copy of
4
+ * their data).
4
5
  */
5
- import { type AddonApi, type IScopedLogger, type RecordsAccess } from "@camstack/types";
6
+ import { type AddonApi, type IScopedLogger, type NcTaggedRuleKind, type RecordsAccess } from "@camstack/types";
6
7
  import type { CoreBlockStore } from "./core-block-store.js";
7
8
  import { type TagOwnerPort, TagsService } from "./tags-service.js";
8
9
  export interface TagsRuntimeDeps {
@@ -12,5 +13,17 @@ export interface TagsRuntimeDeps {
12
13
  readonly logger: IScopedLogger;
13
14
  /** A spec swaps the device owner; production reads the device manager over `api`. */
14
15
  readonly devices?: TagOwnerPort;
16
+ /** A spec swaps the rule owner; production reads the notification rules over `api`. */
17
+ readonly notificationRules?: TagOwnerPort;
15
18
  }
19
+ /**
20
+ * A notification rule's owner-port id is `<kind>:<ruleId>`: event rules,
21
+ * summaries, timelapses and calendar-events rules live in separate stores, so
22
+ * the write must name which one.
23
+ */
24
+ export declare function ruleTagOwnerId(kind: NcTaggedRuleKind, ruleId: string): string;
25
+ export declare function parseRuleTagOwnerId(id: string): {
26
+ kind: NcTaggedRuleKind;
27
+ ruleId: string;
28
+ };
16
29
  export declare function buildTagsService(deps: TagsRuntimeDeps): TagsService;
@@ -3,8 +3,8 @@ Object.defineProperties(exports, {
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
5
  require("../../chunk-Cek0wNdY.js");
6
- const require_dist = require("../../dist-BjhII4Uq.js");
7
- const require_capture_engine = require("../../capture-engine-C1vdBL88.js");
6
+ const require_dist = require("../../dist-yx2KHo3b.js");
7
+ const require_capture_engine = require("../../capture-engine-DHmlkW_d.js");
8
8
  const require_retention = require("../../retention-BcOSL6b9.js");
9
9
  let node_crypto = require("node:crypto");
10
10
  //#region src/builtins/device-history/capture/point-writer.ts
@@ -1,5 +1,5 @@
1
- import { $s as DeviceTransitionSchema, Br as deviceTransitionsCapability, Gl as DeviceType, Gs as wattMillisecondsToKwh, Ir as deviceRemovalHookCapability, Jc as defineRecordKinds, Jl as EventCategory, Ks as BaseAddon, Lr as deviceRunsCapability, Nn as armRemovalReconcile, Nr as deviceHistoryCapability, U as DEVICE_HISTORY_ENERGY_KEY, Xc as emitReadiness, bt as HISTORY_CATALOG, nl as historyUnitFor, nt as DeviceRunSchema, rc as InvalidRecordError, ul as isReadingQuantity, xt as HISTORY_ITEM_CATALOG, yc as RecordTooLargeError } from "../../dist-BKojK6Wf.mjs";
2
- import { a as catalogMetrics, c as DeviceDirectory, d as identityOf, f as subjectIdOf, i as capSeriesKey, l as isRealDeviceType, n as CaptureEngine, o as readPath, r as capItemSeriesKey, s as readUnit, t as CAP_KEY_PREFIX, u as SeriesRegistry } from "../../capture-engine-B1bMuzVX.mjs";
1
+ import { Br as deviceHistoryCapability, Lc as RecordTooLargeError, Ol as isReadingQuantity, St as HISTORY_ITEM_CATALOG, U as DEVICE_HISTORY_ENERGY_KEY, Ur as deviceRemovalHookCapability, Wr as deviceRunsCapability, _c as DeviceTransitionSchema, bl as historyUnitFor, fl as defineRecordKinds, fu as EventCategory, lc as wattMillisecondsToKwh, lu as DeviceType, ml as emitReadiness, qr as deviceTransitionsCapability, rt as DeviceRunSchema, uc as BaseAddon, xc as InvalidRecordError, xt as HISTORY_CATALOG, zn as armRemovalReconcile } from "../../dist-DbAhCrHy.mjs";
2
+ import { a as catalogMetrics, c as DeviceDirectory, d as identityOf, f as subjectIdOf, i as capSeriesKey, l as isRealDeviceType, n as CaptureEngine, o as readPath, r as capItemSeriesKey, s as readUnit, t as CAP_KEY_PREFIX, u as SeriesRegistry } from "../../capture-engine-sl6e9f9S.mjs";
3
3
  import { a as FIVE_MINUTES_MS, c as bucketEndOf, i as DAY_MS, l as bucketStartOf, n as RetentionJob, o as HOUR_MS, r as DepartureTracker, s as ROLLUP_GRACE_MS, t as DEFAULT_RETENTION, u as floorTo } from "../../retention-CUOVI1p7.mjs";
4
4
  import { randomUUID } from "node:crypto";
5
5
  //#region src/builtins/device-history/capture/point-writer.ts
@@ -0,0 +1,9 @@
1
+ import { type IDeviceManagerProvider } from "@camstack/types";
2
+ import type { ProviderContext } from "./device-provider-context.js";
3
+ /** Why a `setIdentifiers` call was refused. */
4
+ export type SetIdentifiersRefusal = "unknown-device" | "not-owner" | "invalid";
5
+ export declare class SetIdentifiersRefusedError extends Error {
6
+ readonly reason: SetIdentifiersRefusal;
7
+ constructor(reason: SetIdentifiersRefusal, message: string);
8
+ }
9
+ export declare function setIdentifiers(pctx: ProviderContext, input: Parameters<IDeviceManagerProvider["setIdentifiers"]>[0]): ReturnType<IDeviceManagerProvider["setIdentifiers"]>;
@@ -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-BjhII4Uq.js");
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-D1mO51F9.js");
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),