@camstack/server 1.2.891 → 1.2.893

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 (118) 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 +204 -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 +14 -15
  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 +174 -39
  36. package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +175 -40
  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/device-history/device-history.addon.js +2 -2
  41. package/system/dist/builtins/device-history/device-history.addon.mjs +2 -2
  42. package/system/dist/builtins/device-manager/device-identifiers-action.d.ts +9 -0
  43. package/system/dist/builtins/device-manager/device-identity-index.d.ts +73 -0
  44. package/system/dist/builtins/device-manager/device-manager.addon.js +401 -14
  45. package/system/dist/builtins/device-manager/device-manager.addon.mjs +401 -14
  46. package/system/dist/builtins/device-manager/device-meta-types.d.ts +5 -1
  47. package/system/dist/builtins/device-manager/device-row-store.d.ts +7 -3
  48. package/system/dist/builtins/device-manager/device-state-mirror.d.ts +7 -0
  49. package/system/dist/builtins/device-manager/workload-transition.d.ts +23 -0
  50. package/system/dist/builtins/hub-forwarder/index.js +1 -1
  51. package/system/dist/builtins/hub-forwarder/index.mjs +1 -1
  52. package/system/dist/builtins/keychain/index.js +4 -4
  53. package/system/dist/builtins/keychain/index.mjs +4 -4
  54. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.js +1 -1
  55. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +1 -1
  56. package/system/dist/builtins/local-auth/local-auth.addon.js +2 -2
  57. package/system/dist/builtins/local-auth/local-auth.addon.mjs +2 -2
  58. package/system/dist/builtins/local-network/local-network.addon.js +3 -3
  59. package/system/dist/builtins/local-network/local-network.addon.mjs +3 -3
  60. package/system/dist/builtins/loki-logging/index.js +1 -1
  61. package/system/dist/builtins/loki-logging/index.mjs +1 -1
  62. package/system/dist/builtins/native-metrics/native-metrics.addon.js +1 -1
  63. package/system/dist/builtins/native-metrics/native-metrics.addon.mjs +1 -1
  64. package/system/dist/builtins/platform-probe/index.js +1 -1
  65. package/system/dist/builtins/platform-probe/index.mjs +1 -1
  66. package/system/dist/builtins/record-entries/index.js +1 -1
  67. package/system/dist/builtins/record-entries/index.mjs +1 -1
  68. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +1 -1
  69. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
  70. package/system/dist/builtins/snapshot/index.js +1 -1
  71. package/system/dist/builtins/snapshot/index.mjs +1 -1
  72. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.js +1 -1
  73. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +1 -1
  74. package/system/dist/builtins/sqlite-storage/index.js +1 -1
  75. package/system/dist/builtins/sqlite-storage/index.mjs +1 -1
  76. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.js +3 -3
  77. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +3 -3
  78. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +1 -1
  79. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +1 -1
  80. package/system/dist/builtins/system-config/system-config.addon.js +3 -3
  81. package/system/dist/builtins/system-config/system-config.addon.mjs +3 -3
  82. package/system/dist/builtins/winston-logging/index.js +1 -1
  83. package/system/dist/builtins/winston-logging/index.mjs +1 -1
  84. package/system/dist/{capture-engine-nmelnj-Y.mjs → capture-engine-CIVKm_jN.mjs} +1 -1
  85. package/system/dist/{capture-engine-DXz37Mjg.js → capture-engine-mZ2J-GD6.js} +1 -1
  86. package/system/dist/{composition-sources-BLn3cU74.js → composition-sources-CGP5ZUYo.js} +1 -1
  87. package/system/dist/{composition-sources-uphZtYtN.mjs → composition-sources-bJP8_Z2o.mjs} +1 -1
  88. package/system/dist/{constants-BAaGwvKn.js → constants-BD8oSQro.js} +1 -1
  89. package/system/dist/{constants-DWU46D02.mjs → constants-w-6vvTPp.mjs} +1 -1
  90. package/system/dist/{device-ca-jbH_rqZh.js → device-ca-CXxnQaff.js} +1 -1
  91. package/system/dist/{device-ca-CK6mLB2w.mjs → device-ca-DE_oetBE.mjs} +1 -1
  92. package/system/dist/{dist-m5beNMze.js → dist-B2-Uflhy.js} +2573 -443
  93. package/system/dist/{dist-Dgq9nuvh.mjs → dist-Be8yFd71.mjs} +2460 -444
  94. package/system/dist/file-host-worker.js +1 -1
  95. package/system/dist/file-host-worker.mjs +1 -1
  96. package/system/dist/{hub-identity-CKCA89XP.js → hub-identity-BjYvJU_v.js} +1 -1
  97. package/system/dist/{hub-identity-DlBBoHJC.mjs → hub-identity-C3g7b58L.mjs} +1 -1
  98. package/system/dist/{hub-mdns-ciao-CqcCGPdi.js → hub-mdns-ciao-BRfv9GfW.js} +2 -2
  99. package/system/dist/{hub-mdns-ciao-B8uFW-RG.mjs → hub-mdns-ciao-v6X_SbWl.mjs} +2 -2
  100. package/system/dist/index.js +33 -19
  101. package/system/dist/index.mjs +33 -19
  102. package/system/dist/kernel/moleculer/child-cap-dispatch.d.ts +3 -6
  103. package/system/dist/kernel/moleculer/switch-toggle.d.ts +7 -2
  104. package/system/dist/{legacy-integration-rows-door-Co0gj1Lm.js → legacy-integration-rows-door-B0q34gh3.js} +1 -1
  105. package/system/dist/{legacy-integration-rows-door-HI4nmSe_.mjs → legacy-integration-rows-door-DG35DG06.mjs} +1 -1
  106. package/system/dist/{rename-composition-block-UeVUYCwx.js → rename-composition-block-DNte3Cs9.js} +1 -1
  107. package/system/dist/{rename-composition-block-BthBMrXA.mjs → rename-composition-block-LEbZ4oZE.mjs} +1 -1
  108. package/system/dist/{restore-archive-P-ICnU58.mjs → restore-archive--4ENkU5f.mjs} +1 -1
  109. package/system/dist/{restore-archive-CJLsfBwK.js → restore-archive-DpFPheMK.js} +1 -1
  110. package/system/dist/{wal-maintenance-CUtwx-2Z.js → wal-maintenance-BWUJktqT.js} +0 -0
  111. package/system/dist/{wal-maintenance-qWjb7_f2.mjs → wal-maintenance-DQVDhuVJ.mjs} +0 -0
  112. package/system/package.json +2 -5
  113. package/system/dist/builtins/camera-grid/grid-camera-declarations.d.ts +0 -59
  114. package/system/dist/builtins/camera-grid/grid-instances.d.ts +0 -40
  115. package/system/dist/builtins/camera-grid/grid-record-kinds.d.ts +0 -31
  116. package/system/dist/builtins/camera-grid/migrations/__fixtures__/seed.d.ts +0 -13
  117. package/system/dist/builtins/camera-grid/migrations/camera-grids-to-records.d.ts +0 -26
  118. package/system/dist/builtins/camera-grid/migrations/index.d.ts +0 -6
@@ -1,7 +1,7 @@
1
- import { $c as expandCapMethods$1, Ai as isKernelDerivedFeature, Bl as vocabActionIdFor, Br as deviceStatusCapability, Cc as SECRET_CLEAR, Do as siteZoneKey, Fl as sleep$2, Fr as deviceManagerCapability, Fs as implementedMethodsOf$1, Gl as DeviceRole, Hc as commandEffect, Ic as auditedFields, Ir as deviceOffersActions, J as DEVICE_TEMPLATE_FILTERS, Kl as DeviceType$1, Kn as buildStreamParamsConfigSchema, La as reconcileReportedFeatures, Ll as toSecretFieldView, Ml as secretTreeFromPaths, Nr as deviceExtensionCapability, Nt as MINUTES_PER_DAY, Or as defineExtensionSlotProvider, Q as DEVICE_TEMPLATE_VALUES_CAP, Qr as extractSourceInfoFromMetadata, Ri as legacyAutoLinkIds, Rl as transformSecretWrite, S as CAP_NAMES_WITH_STATUS, Ui as locationIconKey, Ur as enumerateItemArrayFields, Vc as collectZodSecretPaths$1, Wl as DeviceFeature, Wr as enumerateSchemaFields, X as DEVICE_TEMPLATE_MAX_OUTPUT, Xn as canonicalIconKey, Y as DEVICE_TEMPLATE_MAX_LENGTH, Yc as defineRecordKinds, Yl as EventCategory$1, Yr as expandContainer, _t as FieldClaimModeSchema, al as isCommand$1, an as STREAM_PROFILE_META, at as DiscoveryProposalBodySchema, b as CAMERA_SWITCH_ORDER, br as createDeviceExtensionProvider, bs as canonicalStoredDeviceType, ci as formatMinutes, da as normalizeUnit, di as generateDeviceAlias, er as checkDeviceAlias, fl as isSecretClear, fo as runtimeFieldUnit, hl as isSecretMarkerLike, it as DeviceTombstoneSchema, j as ConditionMirror, kc as WELL_KNOWN_TAB_MAP, kl as resolveSecretMarkers, lo as resolveTemplateRef, lt as ExportNameRefusedError, ml as isSecretMarker, po as runtimeStatePolicyFor, ql as errMsg$1, qs as BaseAddon, rt as DeviceStatusSchema, s as ALL_CAPABILITY_DEFINITIONS, sl as isDeviceConfigCap, ua as normalizeTags, ul as isKeychainStoredField, va as parseStreamParamsFormPatch, vo as searchRank, vt as FieldClaimSchema, xo as settleDeviceFeatures, xs as capAppliesToDeviceKind, z as DAY_NAMES, zl as userError, zr as deviceStateCapability } from "../../dist-Dgq9nuvh.mjs";
1
+ import { $ as DEVICE_TEMPLATE_VALUES_CAP, $s as implementedMethodsOf$1, Bi as isKernelDerivedFeature, Br as deviceExtensionCapability, Ca as normalizeTags, Dn as WORKLOAD_TRANSITION_CATEGORY, Do as sameIdentifiers, Dr as createDeviceExtensionProvider, El as isDeviceConfigCap, Eo as runtimeStatePolicyFor, Fr as defineExtensionSlotProvider, Gi as isWorkloadSettled, Hc as SECRET_CLEAR, Ho as siteZoneKey, Hr as deviceManagerCapability, Io as settleDeviceFeatures, It as MINUTES_PER_DAY, Jc as WELL_KNOWN_TAB_MAP, Jl as resolveSecretMarkers, Kr as deviceStateCapability, Mo as searchRank, Nl as isSecretMarker, On as WorkloadStateSchema, Pl as isSecretMarkerLike, Qn as buildStreamParamsConfigSchema, Ri as isEmptyIdentifiers, Rs as canonicalStoredDeviceType, S as CAP_NAMES_WITH_STATUS, So as resolveTemplateRef, To as runtimeFieldUnit, Ts as workloadTransition, Ur as deviceOffersActions, W as DEVICE_IDENTIFIER_KEYS, X as DEVICE_TEMPLATE_MAX_LENGTH, Xa as reconcileReportedFeatures, Xr as enumerateItemArrayFields, Y as DEVICE_TEMPLATE_FILTERS, Yi as legacyAutoLinkIds, Z as DEVICE_TEMPLATE_MAX_OUTPUT, Zl as secretTreeFromPaths, Zr as enumerateSchemaFields, ai as extractSourceInfoFromMetadata, at as DeviceStatusSchema, au as vocabActionIdFor, b as CAMERA_SWITCH_ORDER, bt as FieldClaimSchema, cn as STREAM_PROFILE_META, dt as ExportNameRefusedError, du as DeviceType$1, eu as sleep$2, fa as mergeIdentifiers, fc as BaseAddon, fu as errMsg$1, hi as formatMinutes, iu as userError, j as ConditionMirror, ja as parseStreamParamsFormPatch, jl as isSecretClear, kl as isKeychainStoredField, lu as DeviceFeature, ml as defineRecordKinds, mu as EventCategory$1, ni as expandContainer, nr as canonicalIconKey, nu as toSecretFieldView, ol as collectZodSecretPaths$1, or as checkDeviceAlias, ot as DeviceTombstoneSchema, qr as deviceStatusCapability, rt as DeviceIdentifiersSchema, ru as transformSecretWrite, s as ALL_CAPABILITY_DEFINITIONS, sl as commandEffect, st as DiscoveryProposalBodySchema, ta as locationIconKey, tl as auditedFields, uu as DeviceRole, vi as generateDeviceAlias, vl as expandCapMethods$1, wa as normalizeUnit, wi as identifierStrength, wl as isCommand$1, ws as workloadCapability, yt as FieldClaimModeSchema, z as DAY_NAMES, zs as capAppliesToDeviceKind } from "../../dist-Be8yFd71.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-BthBMrXA.mjs";
4
+ import { n as renameCompositionBlock, t as composedBlockIdOf } from "../../rename-composition-block-LEbZ4oZE.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
  }
@@ -4734,7 +4738,7 @@ function compareUnranked(a, b) {
4734
4738
  if (a[2] !== b[2]) return a[2] < b[2] ? -1 : 1;
4735
4739
  return a[3] - b[3];
4736
4740
  }
4737
- function compareKeys(a, b) {
4741
+ function compareKeys$1(a, b) {
4738
4742
  if (a.length === 5 && b.length === 5) {
4739
4743
  if (a[0] !== b[0]) return a[0] - b[0];
4740
4744
  return compareUnranked([
@@ -4909,14 +4913,14 @@ async function searchDevices(deps, input) {
4909
4913
  const keyed = listed.map((c) => ({
4910
4914
  c,
4911
4915
  key: sortKeyOf(c)
4912
- })).sort((a, b) => compareKeys(a.key, b.key));
4916
+ })).sort((a, b) => compareKeys$1(a.key, b.key));
4913
4917
  const limit = Math.min(input.limit ?? 50, 200);
4914
4918
  let start = 0;
4915
4919
  if (input.cursor !== void 0 && input.cursor !== null) {
4916
4920
  const after = decodeCursor(input.cursor);
4917
4921
  if (after === null) deps.logger.warn("deviceManager.search: undecodable cursor — restarting from the first page");
4918
4922
  else {
4919
- const next = keyed.findIndex((k) => compareKeys(k.key, after) > 0);
4923
+ const next = keyed.findIndex((k) => compareKeys$1(k.key, after) > 0);
4920
4924
  start = next === -1 ? keyed.length : next;
4921
4925
  }
4922
4926
  }
@@ -8795,6 +8799,307 @@ 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
8895
+ //#region src/builtins/device-manager/device-identity-index.ts
8896
+ /**
8897
+ * The identifier INDEX (planning#593): identifier key → devices, so the
8898
+ * device-manager can say which devices of DIFFERENT integrations share
8899
+ * provider-declared identifiers (D1059) without reading the fleet per question.
8900
+ *
8901
+ * It is a PROJECTION of the device rows, never an authority: it holds, per
8902
+ * device, only what the pair rule needs — owning addon, integration instance and
8903
+ * the declared identifiers — and it moves with the rows, as the
8904
+ * {@link DeviceRowObserver} of the one `DeviceRowStore`. Every write of a row
8905
+ * passes through that store (`upsert`, `upsertRegistration`, `patch`, `remove`;
8906
+ * `swapIds` is built of them), so a row that changes reaches the index on the
8907
+ * same statement. A deleted device leaves the index on its row's DELETE — the
8908
+ * statement `removeDevice` runs right before it records the tombstone (D865) —
8909
+ * not on an event or on absence from a listing.
8910
+ *
8911
+ * It loads once, from the fleet listing the device-manager already reads at
8912
+ * boot ({@link seed}). Until then it answers `unknown` (D315), never `[]`; a row
8913
+ * write that lands while the snapshot is in flight is buffered and replayed over
8914
+ * it, so the seed can never roll a newer write back.
8915
+ *
8916
+ * Read-only: it finds candidates, it links nothing (that is step 3).
8917
+ */
8918
+ /** The `kind=value` keys of one declaration. */
8919
+ function keysOf(identifiers) {
8920
+ if (identifiers === null) return [];
8921
+ const out = [];
8922
+ for (const kind of DEVICE_IDENTIFIER_KEYS) {
8923
+ const entry = identifiers[kind];
8924
+ if (entry === void 0) continue;
8925
+ for (const e of [entry].flat()) out.push(`${kind}=${e.value}`);
8926
+ }
8927
+ return out;
8928
+ }
8929
+ function isIdentifierKind(value) {
8930
+ return DEVICE_IDENTIFIER_KEYS.some((k) => k === value);
8931
+ }
8932
+ function parseKey(key) {
8933
+ const at = key.indexOf("=");
8934
+ const kind = key.slice(0, at);
8935
+ return isIdentifierKind(kind) ? {
8936
+ key: kind,
8937
+ value: key.slice(at + 1)
8938
+ } : null;
8939
+ }
8940
+ /**
8941
+ * Same integration? The same instance when both carry one; otherwise — one side
8942
+ * was never stamped — the same addon. In doubt, the same: no candidate.
8943
+ */
8944
+ function sameIntegration(a, b) {
8945
+ if (a.integrationId !== null && b.integrationId !== null) return a.integrationId === b.integrationId;
8946
+ return a.addonId === b.addonId;
8947
+ }
8948
+ function sideOf(d) {
8949
+ return {
8950
+ deviceId: d.deviceId,
8951
+ addonId: d.addonId,
8952
+ integrationId: d.integrationId
8953
+ };
8954
+ }
8955
+ function compareKeys(x, y) {
8956
+ if (x.key !== y.key) return x.key < y.key ? -1 : 1;
8957
+ return x.value < y.value ? -1 : x.value > y.value ? 1 : 0;
8958
+ }
8959
+ /**
8960
+ * Grade the keys two devices share. `null` when they are no candidate at all
8961
+ * (no strong key matched).
8962
+ *
8963
+ * | Matched keys | Confidence |
8964
+ * | ----------------------------------------- | ------------ |
8965
+ * | two strong KINDS (e.g. `mac` + `serial`) | `auto` |
8966
+ * | `mac` + `ip` | `auto` |
8967
+ * | exactly one strong kind | `proposal` |
8968
+ * | weak keys only (`hostname`, `ip`) | no candidate |
8969
+ *
8970
+ * Strength counts distinct KINDS, not values: two MACs of one device matching
8971
+ * the other's two MACs are one kind of evidence, so a proposal.
8972
+ */
8973
+ function classifyIdentityMatch(keys) {
8974
+ const kinds = new Set(keys.map((k) => k.key));
8975
+ const strongKinds = [...kinds].filter((kind) => identifierStrength(kind) === "strong");
8976
+ if (strongKinds.length === 0) return null;
8977
+ if (strongKinds.length >= 2) return "auto";
8978
+ if (kinds.has("mac") && kinds.has("ip")) return "auto";
8979
+ return "proposal";
8980
+ }
8981
+ var DeviceIdentityIndex = class {
8982
+ devices = /* @__PURE__ */ new Map();
8983
+ byKey = /* @__PURE__ */ new Map();
8984
+ /** `null` once seeded; until then, the writes to replay over the snapshot. */
8985
+ pending = [];
8986
+ /** Load from a fleet snapshot, then replay every write that landed meanwhile. */
8987
+ seed(rows) {
8988
+ const buffered = this.pending ?? [];
8989
+ this.pending = null;
8990
+ this.devices.clear();
8991
+ this.byKey.clear();
8992
+ for (const row of rows) this.rowWritten(row.meta);
8993
+ for (const write of buffered) write(this);
8994
+ }
8995
+ rowWritten(meta) {
8996
+ if (this.buffer((i) => i.rowWritten(meta))) return;
8997
+ this.put({
8998
+ deviceId: meta.id,
8999
+ addonId: meta.addonId,
9000
+ integrationId: meta.integrationId ?? null,
9001
+ identifiers: meta.identifiers ?? null
9002
+ });
9003
+ }
9004
+ registrationWritten(row) {
9005
+ if (this.buffer((i) => i.registrationWritten(row))) return;
9006
+ const existing = this.devices.get(row.deviceId);
9007
+ this.put({
9008
+ deviceId: row.deviceId,
9009
+ addonId: row.addonId,
9010
+ integrationId: existing?.integrationId ?? null,
9011
+ identifiers: existing?.identifiers ?? null
9012
+ });
9013
+ }
9014
+ rowPatched(deviceId, patch) {
9015
+ if (patch.identifiers === void 0 && patch.integrationId === void 0) return;
9016
+ if (this.buffer((i) => i.rowPatched(deviceId, patch))) return;
9017
+ const existing = this.devices.get(deviceId);
9018
+ if (existing === void 0) return;
9019
+ this.put({
9020
+ ...existing,
9021
+ ...patch.identifiers !== void 0 ? { identifiers: patch.identifiers } : {},
9022
+ ...patch.integrationId !== void 0 ? { integrationId: patch.integrationId } : {}
9023
+ });
9024
+ }
9025
+ rowRemoved(deviceId) {
9026
+ if (this.buffer((i) => i.rowRemoved(deviceId))) return;
9027
+ this.drop(deviceId);
9028
+ }
9029
+ /**
9030
+ * Every cross-integration candidate pair, graded by `classifyIdentityMatch`,
9031
+ * plus the devices whose identity is unknown (nothing declared).
9032
+ */
9033
+ candidates() {
9034
+ if (this.pending !== null) return {
9035
+ status: "unknown",
9036
+ reason: "the identifier index has not loaded yet"
9037
+ };
9038
+ const seen = /* @__PURE__ */ new Set();
9039
+ const pairs = [];
9040
+ for (const [key, members] of this.byKey) {
9041
+ const parsed = parseKey(key);
9042
+ if (parsed === null || identifierStrength(parsed.key) !== "strong") continue;
9043
+ if (members.size < 2) continue;
9044
+ const sorted = [...members].sort((x, y) => x - y);
9045
+ for (let i = 0; i < sorted.length; i++) for (let j = i + 1; j < sorted.length; j++) {
9046
+ const pair = this.pairOf(sorted[i], sorted[j], seen);
9047
+ if (pair !== null) pairs.push(pair);
9048
+ }
9049
+ }
9050
+ pairs.sort((x, y) => x.a.deviceId - y.a.deviceId || x.b.deviceId - y.b.deviceId);
9051
+ return {
9052
+ status: "answered",
9053
+ pairs,
9054
+ undeclaredDeviceIds: [...this.devices.values()].filter((d) => d.identifiers === null).map((d) => d.deviceId).sort((x, y) => x - y)
9055
+ };
9056
+ }
9057
+ pairOf(idA, idB, seen) {
9058
+ if (idA === void 0 || idB === void 0) return null;
9059
+ const tag = `${idA}/${idB}`;
9060
+ if (seen.has(tag)) return null;
9061
+ seen.add(tag);
9062
+ const a = this.devices.get(idA);
9063
+ const b = this.devices.get(idB);
9064
+ if (a === void 0 || b === void 0 || sameIntegration(a, b)) return null;
9065
+ const bKeys = new Set(keysOf(b.identifiers));
9066
+ const keys = keysOf(a.identifiers).filter((k) => bKeys.has(k)).map(parseKey).filter((k) => k !== null).sort(compareKeys);
9067
+ const confidence = classifyIdentityMatch(keys);
9068
+ return confidence === null ? null : {
9069
+ a: sideOf(a),
9070
+ b: sideOf(b),
9071
+ keys,
9072
+ confidence
9073
+ };
9074
+ }
9075
+ /** True when the write was buffered for replay over a seed still in flight. */
9076
+ buffer(write) {
9077
+ if (this.pending === null) return false;
9078
+ this.pending.push(write);
9079
+ return true;
9080
+ }
9081
+ put(device) {
9082
+ this.drop(device.deviceId);
9083
+ this.devices.set(device.deviceId, device);
9084
+ for (const key of keysOf(device.identifiers)) {
9085
+ const members = this.byKey.get(key) ?? /* @__PURE__ */ new Set();
9086
+ members.add(device.deviceId);
9087
+ this.byKey.set(key, members);
9088
+ }
9089
+ }
9090
+ drop(deviceId) {
9091
+ const existing = this.devices.get(deviceId);
9092
+ if (existing === void 0) return;
9093
+ this.devices.delete(deviceId);
9094
+ for (const key of keysOf(existing.identifiers)) {
9095
+ const members = this.byKey.get(key);
9096
+ if (members === void 0) continue;
9097
+ members.delete(deviceId);
9098
+ if (members.size === 0) this.byKey.delete(key);
9099
+ }
9100
+ }
9101
+ };
9102
+ //#endregion
8798
9103
  //#region src/builtins/device-manager/linked-devices-manual-backfill.ts
8799
9104
  var LINKED_MANUAL_BACKFILL_MARKER_KEY = "_linkedDevicesManualBackfillVersion";
8800
9105
  function planManualBackfill(params) {
@@ -10332,6 +10637,10 @@ var DEVICE_ROWS_COLUMNS = [
10332
10637
  {
10333
10638
  name: "metadata",
10334
10639
  type: "JSON"
10640
+ },
10641
+ {
10642
+ name: "identifiers",
10643
+ type: "JSON"
10335
10644
  }
10336
10645
  ];
10337
10646
  /**
@@ -10451,6 +10760,7 @@ function decodeDeviceRow(data) {
10451
10760
  const primaryChildPreference = readStringArray(data["primaryChildPreference"]);
10452
10761
  const rawDisplay = data["display"];
10453
10762
  const rawMetadata = data["metadata"];
10763
+ const identifiers = DeviceIdentifiersSchema.safeParse(data["identifiers"]);
10454
10764
  return {
10455
10765
  meta: {
10456
10766
  id: deviceId,
@@ -10472,7 +10782,8 @@ function decodeDeviceRow(data) {
10472
10782
  ...isChildLayout(rawChildLayout) ? { childLayout: rawChildLayout } : {},
10473
10783
  ...primaryChildPreference !== void 0 ? { primaryChildPreference } : {},
10474
10784
  ...role !== void 0 ? { role } : {},
10475
- ...isPlainObject$1(rawDisplay) ? { display: toDisplayOverride(rawDisplay) } : {}
10785
+ ...isPlainObject$1(rawDisplay) ? { display: toDisplayOverride(rawDisplay) } : {},
10786
+ ...identifiers.success ? { identifiers: identifiers.data } : {}
10476
10787
  },
10477
10788
  metadata: isPlainObject$1(rawMetadata) ? rawMetadata : null,
10478
10789
  registered: readBoolean(data["registered"]) ?? false
@@ -10518,7 +10829,8 @@ function encodeDeviceRow(meta, extra = {}) {
10518
10829
  childLayout: meta.childLayout ?? null,
10519
10830
  primaryChildPreference: meta.primaryChildPreference === void 0 ? null : [...meta.primaryChildPreference],
10520
10831
  role: meta.role ?? null,
10521
- display: meta.display ?? null
10832
+ display: meta.display ?? null,
10833
+ identifiers: meta.identifiers ?? null
10522
10834
  };
10523
10835
  if (extra.metadata !== void 0) row["metadata"] = extra.metadata;
10524
10836
  return row;
@@ -10541,6 +10853,7 @@ function encodeDeviceRowPatch(patch) {
10541
10853
  var DeviceRowStore = class {
10542
10854
  backend;
10543
10855
  logger;
10856
+ observer;
10544
10857
  declared = null;
10545
10858
  /** Call-site attribution for fleet reads. Armed only by
10546
10859
  * `CAMSTACK_FLEET_READ_CENSUS_MS`; see `fleet-read-census.ts`. */
@@ -10555,9 +10868,10 @@ var DeviceRowStore = class {
10555
10868
  get censusArmed() {
10556
10869
  return this.census.armed;
10557
10870
  }
10558
- constructor(backend, logger, census) {
10871
+ constructor(backend, logger, census, observer) {
10559
10872
  this.backend = backend;
10560
10873
  this.logger = logger;
10874
+ this.observer = observer;
10561
10875
  this.census = census ?? new FleetReadCensus(process.env["CAMSTACK_FLEET_READ_CENSUS_MS"], Date.now());
10562
10876
  if (this.census.armed) {
10563
10877
  const startedAt = Date.now();
@@ -10832,6 +11146,7 @@ var DeviceRowStore = class {
10832
11146
  key: String(meta.id),
10833
11147
  value: encodeDeviceRow(meta, extra)
10834
11148
  });
11149
+ this.observer?.rowWritten(meta);
10835
11150
  }
10836
11151
  /**
10837
11152
  * Write the named columns of an EXISTING row and nothing else.
@@ -10853,10 +11168,14 @@ var DeviceRowStore = class {
10853
11168
  filter: { where: { id: String(deviceId) } },
10854
11169
  data: columns
10855
11170
  });
10856
- if (updated === 0) this.logger.warn("device row patch matched no row — the device was removed under it", {
10857
- tags: { deviceId },
10858
- meta: { columns: Object.keys(columns) }
10859
- });
11171
+ if (updated === 0) {
11172
+ this.logger.warn("device row patch matched no row — the device was removed under it", {
11173
+ tags: { deviceId },
11174
+ meta: { columns: Object.keys(columns) }
11175
+ });
11176
+ return;
11177
+ }
11178
+ this.observer?.rowPatched(deviceId, patch);
10860
11179
  }
10861
11180
  /**
10862
11181
  * Insert-or-update the registration columns. See {@link DeviceRegistrationRow}
@@ -10882,6 +11201,7 @@ var DeviceRowStore = class {
10882
11201
  exportFingerprint: row.exportFingerprint
10883
11202
  }
10884
11203
  });
11204
+ this.observer?.registrationWritten(row);
10885
11205
  }
10886
11206
  /** Drop the device's row. Idempotent. */
10887
11207
  /**
@@ -10981,6 +11301,7 @@ var DeviceRowStore = class {
10981
11301
  collection: DEVICE_ROWS_COLLECTION,
10982
11302
  key: String(deviceId)
10983
11303
  });
11304
+ this.observer?.rowRemoved(deviceId);
10984
11305
  }
10985
11306
  /**
10986
11307
  * The retirement door for the three blobs this collection replaced.
@@ -11167,6 +11488,41 @@ var RunningFlipDetector = class {
11167
11488
  }
11168
11489
  };
11169
11490
  //#endregion
11491
+ //#region src/builtins/device-manager/workload-transition.ts
11492
+ function readState(slice) {
11493
+ const parsed = WorkloadStateSchema.safeParse(slice["state"]);
11494
+ return parsed.success ? parsed.data : null;
11495
+ }
11496
+ /**
11497
+ * Remembers each workload's last SETTLED state (running, paused, stopped,
11498
+ * crashed) and turns a move away from it into the cap's events. `starting` /
11499
+ * `stopping` and an unknown state are never remembered, so stopped → starting →
11500
+ * running is one `started`, and crashed → starting → running one `recovered`.
11501
+ *
11502
+ * The first state seen for a device is a seed: it raises nothing, so a hub
11503
+ * restart does not announce every running container as started.
11504
+ */
11505
+ var WorkloadTransitionDetector = class {
11506
+ #settled = /* @__PURE__ */ new Map();
11507
+ note(deviceId, slice) {
11508
+ const state = readState(slice);
11509
+ const previous = this.#settled.get(deviceId);
11510
+ const kind = workloadTransition(previous, state);
11511
+ if (state !== null && isWorkloadSettled(state)) this.#settled.set(deviceId, state);
11512
+ if (kind === null || state === null || previous === void 0) return null;
11513
+ return {
11514
+ kind,
11515
+ deviceId,
11516
+ state,
11517
+ previous,
11518
+ since: typeof slice["since"] === "number" && Number.isFinite(slice["since"]) ? slice["since"] : null
11519
+ };
11520
+ }
11521
+ forget(deviceId) {
11522
+ this.#settled.delete(deviceId);
11523
+ }
11524
+ };
11525
+ //#endregion
11170
11526
  //#region src/builtins/device-manager/last-active-mode.ts
11171
11527
  /**
11172
11528
  * The last mode a climate device actually RAN (D224): "turn on" needs a mode to
@@ -11758,6 +12114,7 @@ var DeviceStateMirror = class {
11758
12114
  writer;
11759
12115
  /** Edge detector for `running-state` flip events (D933). */
11760
12116
  runningFlip = new RunningFlipDetector();
12117
+ workloadTransitions = new WorkloadTransitionDetector();
11761
12118
  constructor(ctx, policyFor = runtimeStatePolicyFor, schemaFor = defaultSchemaFor) {
11762
12119
  this.ctx = ctx;
11763
12120
  this.policyFor = policyFor;
@@ -11990,6 +12347,7 @@ var DeviceStateMirror = class {
11990
12347
  await this.seeding.get(deviceId)?.catch(() => void 0);
11991
12348
  await this.writer.forget(deviceId);
11992
12349
  this.stateMirror.delete(deviceId);
12350
+ this.workloadTransitions.forget(deviceId);
11993
12351
  this.claims.clearDevice(deviceId);
11994
12352
  this.seeded.delete(deviceId);
11995
12353
  this.rowRead.delete(deviceId);
@@ -12290,6 +12648,30 @@ var DeviceStateMirror = class {
12290
12648
  for (const deviceId of deviceIds) out[String(deviceId)] = this.snapshotForDevice(deviceId);
12291
12649
  return out;
12292
12650
  }
12651
+ /**
12652
+ * The `workload` cap's events (#585): judged from the PUBLIC slice like the
12653
+ * running flip, so a provider only writes its state. The first state seen is
12654
+ * a seed and raises nothing.
12655
+ */
12656
+ emitWorkloadTransition(deviceId, slice) {
12657
+ const transition = this.workloadTransitions.note(deviceId, slice);
12658
+ if (transition === null) return;
12659
+ this.ctx.eventBus.emit({
12660
+ id: randomUUID(),
12661
+ timestamp: /* @__PURE__ */ new Date(),
12662
+ source: {
12663
+ type: "device",
12664
+ id: deviceId
12665
+ },
12666
+ category: WORKLOAD_TRANSITION_CATEGORY[transition.kind],
12667
+ data: {
12668
+ deviceId,
12669
+ state: transition.state,
12670
+ previous: transition.previous,
12671
+ since: transition.since
12672
+ }
12673
+ });
12674
+ }
12293
12675
  /** Remember a restored running bit so the first public merge does not emit a flip. */
12294
12676
  seedRunningFlip(deviceId) {
12295
12677
  const slice = this.capSlice(deviceId, RUNNING_STATE_CAP);
@@ -12320,6 +12702,7 @@ var DeviceStateMirror = class {
12320
12702
  }
12321
12703
  });
12322
12704
  }
12705
+ if (capName === workloadCapability.name) this.emitWorkloadTransition(deviceId, slice);
12323
12706
  this.ctx.eventBus.emit({
12324
12707
  id: randomUUID(),
12325
12708
  timestamp: /* @__PURE__ */ new Date(),
@@ -13855,7 +14238,8 @@ var DeviceManagerAddon = class extends BaseAddon {
13855
14238
  };
13856
14239
  const settingsStoreApi = this.ctx.api?.settingsStore;
13857
14240
  if (!settingsStoreApi) throw new Error("[device-manager] settings-store API not available — refusing to serve a fleet it cannot persist");
13858
- const deviceRows = new DeviceRowStore(deviceRowBackendOf(settingsStoreApi), this.ctx.logger.child("rows"));
14241
+ const identityIndex = new DeviceIdentityIndex();
14242
+ const deviceRows = new DeviceRowStore(deviceRowBackendOf(settingsStoreApi), this.ctx.logger.child("rows"), void 0, identityIndex);
13859
14243
  await deviceRows.declare();
13860
14244
  this.deviceRows = deviceRows;
13861
14245
  const records = this.ctx.records;
@@ -13918,6 +14302,7 @@ var DeviceManagerAddon = class extends BaseAddon {
13918
14302
  const idToAddonId = metaStore.idToAddonId;
13919
14303
  const bootRows = await deviceRows.listAll();
13920
14304
  for (const row of bootRows) idToAddonId.set(row.meta.id, row.meta.addonId);
14305
+ identityIndex.seed(bootRows);
13921
14306
  const stampIntegrationId$1 = (deviceId, integrationId) => stampIntegrationId(metaStore, this.ctx, deviceId, integrationId);
13922
14307
  const templates = this.makeTemplateActions();
13923
14308
  const pctx = {
@@ -14002,6 +14387,8 @@ var DeviceManagerAddon = class extends BaseAddon {
14002
14387
  setPrimaryChildPreference: (input) => setPrimaryChildPreference(pctx, input),
14003
14388
  setRole: (input) => setRole(pctx, input),
14004
14389
  setDisplay: (input) => setDisplay(pctx, input),
14390
+ setIdentifiers: (input) => setIdentifiers(pctx, input),
14391
+ listIdentityCandidates: async () => identityIndex.candidates(),
14005
14392
  getRoleDisplayDefaults: (input) => getRoleDisplayDefaults(pctx, input),
14006
14393
  setRoleDisplayDefaults: (input) => setRoleDisplayDefaults(pctx, input),
14007
14394
  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,6 +1,7 @@
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
+ import type { DeviceRowObserver } from "./device-identity-index.js";
4
5
  import { FleetReadCensus } from "./fleet-read-census.js";
5
6
  /**
6
7
  * @durable class=ledger owner=device-manager
@@ -150,6 +151,7 @@ export interface DeviceRowPatch {
150
151
  readonly primaryChildPreference?: readonly string[] | null;
151
152
  readonly role?: string | null;
152
153
  readonly display?: DeviceDisplayOverride | null;
154
+ readonly identifiers?: DeviceIdentifiers | null;
153
155
  readonly metadata?: Record<string, unknown> | null;
154
156
  }
155
157
  /**
@@ -163,7 +165,7 @@ export interface DeviceRowPatch {
163
165
  * required here, and the type is what keeps it that way.
164
166
  *
165
167
  * Columns NOT listed — `integrationId`, `linkDeviceId`, `primaryChildEntityId`,
166
- * `childLayout`, `primaryChildPreference`, `role`, `display`, `metadata` — are not in the statement at
168
+ * `childLayout`, `primaryChildPreference`, `role`, `display`, `identifiers`, `metadata` — are not in the statement at
167
169
  * all, so re-registering preserves them. The blob shape had to re-state each
168
170
  * one to avoid clobbering it, and every field added since has been one more
169
171
  * spread somebody had to remember.
@@ -216,6 +218,8 @@ export declare function encodeDeviceRowPatch(patch: DeviceRowPatch): Record<stri
216
218
  export declare class DeviceRowStore {
217
219
  private readonly backend;
218
220
  private readonly logger;
221
+ /** Told of every row write after it succeeded — the identifier index (planning#593). */
222
+ private readonly observer?;
219
223
  private declared;
220
224
  /** Call-site attribution for fleet reads. Armed only by
221
225
  * `CAMSTACK_FLEET_READ_CENSUS_MS`; see `fleet-read-census.ts`. */
@@ -228,7 +232,7 @@ export declare class DeviceRowStore {
228
232
  * zero cost while disarmed.
229
233
  */
230
234
  get censusArmed(): boolean;
231
- constructor(backend: DeviceRowBackend, logger: IScopedLogger, census?: FleetReadCensus);
235
+ constructor(backend: DeviceRowBackend, logger: IScopedLogger, census?: FleetReadCensus, observer?: DeviceRowObserver);
232
236
  /**
233
237
  * Lazy, idempotent `declareCollection`, memoised on the PROMISE so N
234
238
  * concurrent first-callers issue one declaration rather than N. A rejection