@camstack/addon-export-hap 1.2.90 → 1.2.92

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.
@@ -72,7 +72,7 @@ function carryForward(base, existing, keys) {
72
72
  return out;
73
73
  }
74
74
  //#endregion
75
- //#region ../types/dist/event-category-zAv7pMUz.mjs
75
+ //#region ../types/dist/event-category-CnLqLOKs.mjs
76
76
  var EventCategory = /* @__PURE__ */ function(EventCategory) {
77
77
  EventCategory["SystemBoot"] = "system.boot";
78
78
  EventCategory["SystemAddonsReady"] = "system.addons-ready";
@@ -267,6 +267,19 @@ var EventCategory = /* @__PURE__ */ function(EventCategory) {
267
267
  EventCategory["ProcessCrashed"] = "process.crashed";
268
268
  EventCategory["ProcessRestartScheduled"] = "process.restart_scheduled";
269
269
  EventCategory["ProcessRestarted"] = "process.restarted";
270
+ /**
271
+ * The SET of storage locations changed — one was created, edited, enabled,
272
+ * disabled or deleted through `storage.upsertLocation` / `deleteLocation`.
273
+ *
274
+ * Telemetry, not a transaction (D8/D11): every consumer that re-resolves on
275
+ * it must also converge on its own periodic path, because a dropped event
276
+ * must not leave a node writing to yesterday's disk set forever. It exists
277
+ * because there was NO signal at all — an operator who added a second
278
+ * recordings disk in the admin UI got nothing, and the recorder kept its
279
+ * resolved locations until something else happened to re-resolve them
280
+ * (D387). Payload `StorageLocationsChangedPayload`.
281
+ */
282
+ EventCategory["StorageLocationsChanged"] = "storage.locations-changed";
270
283
  EventCategory["RecordingStarted"] = "recording.started";
271
284
  EventCategory["RecordingStopped"] = "recording.stopped";
272
285
  EventCategory["RecordingError"] = "recording.error";
@@ -9190,6 +9203,21 @@ var StorageCleanupJobSchema = object({
9190
9203
  });
9191
9204
  var StorageCleanupStatusInputSchema = object({ jobId: string().optional() });
9192
9205
  /**
9206
+ * The one typed state of a storage location. Authoritative Zod schema — the TS
9207
+ * alias below is `z.infer<>` of it, never a second spelling.
9208
+ */
9209
+ var StorageLocationModeSchema = _enum([
9210
+ "active",
9211
+ "readonly",
9212
+ "drain",
9213
+ "disabled"
9214
+ ]);
9215
+ _enum([
9216
+ "normal",
9217
+ "never",
9218
+ "drain"
9219
+ ]);
9220
+ /**
9193
9221
  * `StorageLocationType` — an addon-declared id that identifies the *kind* of
9194
9222
  * storage a location serves. Defined here (not in `capabilities/storage.cap.ts`)
9195
9223
  * so the persisted record schema and the consumer-facing cap can both consume it
@@ -9255,6 +9283,21 @@ var StorageLocationSchema = object({
9255
9283
  * stops existing rather than being re-derived on every read.
9256
9284
  */
9257
9285
  enabled: boolean().optional(),
9286
+ /**
9287
+ * THE state of this location (D385), and the only authority on what may be
9288
+ * written, read or evicted here. Interpreted in exactly one place —
9289
+ * `storage-location-mode.ts` — which also folds the legacy
9290
+ * `enabled` / `config.readOnly` pair into a mode so an old row is never
9291
+ * ambiguous.
9292
+ *
9293
+ * OPTIONAL only for the wire and for rows written before D385: absence is
9294
+ * resolved by `resolveLocationMode`, and the orchestrator stamps every
9295
+ * unstamped row ONCE at hydrate so absence stops existing rather than being
9296
+ * re-derived on every read. `enabled` survives one release as a DERIVED
9297
+ * mirror (`mode === 'active'`); `withLocationMode` is the only writer of
9298
+ * either, so the two cannot disagree.
9299
+ */
9300
+ mode: StorageLocationModeSchema.optional(),
9258
9301
  /** COMPUTED at read time by the orchestrator (statfs of the backing volume
9259
9302
  * for node-local locations it can reach) — never persisted, absent when the
9260
9303
  * volume is remote/unreachable. The single capacity truth every UI reads. */
@@ -9262,11 +9305,46 @@ var StorageLocationSchema = object({
9262
9305
  totalBytes: number(),
9263
9306
  availableBytes: number()
9264
9307
  }).nullable().optional(),
9308
+ /**
9309
+ * How much of that volume CamStack ITSELF holds on this location (D388) —
9310
+ * COMPUTED at read time from the `storage-occupancy` providers' own figures,
9311
+ * never persisted, never a filesystem walk.
9312
+ *
9313
+ * **ABSENT MEANS UNKNOWN, never zero.** No provider has reported for this
9314
+ * location yet — nobody stores here, the owning addon is down, or the first
9315
+ * refresh has not completed. A UI must omit the segment rather than draw it
9316
+ * at zero, which would claim we occupy nothing (D315). It is an OBJECT and
9317
+ * not a bare number precisely so that a `?? 0` on the consuming side has to
9318
+ * be spelled out loud instead of appearing by accident.
9319
+ *
9320
+ * `measuredAtMs` is the OLDEST contributing measurement, so it is honest
9321
+ * about the whole figure rather than about its freshest part.
9322
+ */
9323
+ owned: object({
9324
+ bytes: number().int().nonnegative(),
9325
+ measuredAtMs: number().int().nonnegative()
9326
+ }).optional(),
9265
9327
  createdAt: number(),
9266
9328
  updatedAt: number()
9267
9329
  });
9268
9330
  object({ isDefault: boolean().optional() });
9269
9331
  /**
9332
+ * How far a `drain` has got (D386) — the read a UI renders, and nothing more.
9333
+ *
9334
+ * `estimatedEmptyAtMs` is derived from the growth the ratchet has actually
9335
+ * OBSERVED and is `null` when it has observed none. Never a fabricated date: a
9336
+ * drain with no observed growth has no honest ETA, and inventing one is how an
9337
+ * operator learns not to believe the screen.
9338
+ */
9339
+ var StorageDrainProgressSchema = object({
9340
+ locationId: string(),
9341
+ startedAtMs: number(),
9342
+ startBytes: number(),
9343
+ bytesRemaining: number(),
9344
+ drained: boolean(),
9345
+ estimatedEmptyAtMs: number().nullable()
9346
+ });
9347
+ /**
9270
9348
  * Reference accepted by consumer-facing `api.storage.*` calls.
9271
9349
  * Either:
9272
9350
  * - a `StorageLocationType` (e.g. `'backups'`) → the sole location of that type
@@ -20842,8 +20920,25 @@ var occupancyRecheckFramesField = {
20842
20920
  * (analyzer attaches detected `regions[]`; onboard does not — the
20843
20921
  * camera typically only reports a binary signal plus an optional
20844
20922
  * channel/AI class which lives in dedicated event channels).
20845
- */
20846
- var MotionSourceEnum = _enum(["onboard", "analyzer"]);
20923
+ *
20924
+ * - `onboard` — the camera's firmware said something moved.
20925
+ * - `analyzer` — this runner's frame-diff said so, and attaches `regions[]`.
20926
+ * - `device-activity` — the DEVICE said it is doing its job: the
20927
+ * `recording-signal` LEVEL the same device raises for the recorder
20928
+ * ([D380](../../../../docs/decisions/adr-0380-a-device-decided-recording-is-a-mode-with-no-schedule-seeded-once.md)),
20929
+ * republished as a motion source. It attaches **nothing** — no regions, no
20930
+ * class: the only fact it carries is that the device is active, and a robot
20931
+ * vacuum that is itself the moving object has no region worth sending. It is
20932
+ * a LEVEL, so unlike `onboard` it has a real falling edge, and unlike
20933
+ * `analyzer` it must not open the frame-diff side-channel — the runner's
20934
+ * `handleOnboardMotionAnalyzer` gate is `source === 'onboard'` and stays that
20935
+ * way ([D392](../../../../docs/decisions/adr-0392-a-device-that-says-it-is-working-is-a-motion-source-of-its-own.md)).
20936
+ */
20937
+ var MotionSourceEnum = _enum([
20938
+ "onboard",
20939
+ "analyzer",
20940
+ "device-activity"
20941
+ ]);
20847
20942
  /**
20848
20943
  * List of motion sources active on a camera. Empty array is valid:
20849
20944
  * "no source" — happens for battery cams without firmware motion when
@@ -22362,7 +22457,7 @@ method(object({
22362
22457
  }), _void(), {
22363
22458
  kind: "mutation",
22364
22459
  auth: "admin"
22365
- }), method(object({ id: string() }), object({
22460
+ }), method(_void(), array(StorageDrainProgressSchema).readonly()), method(object({ id: string() }), object({
22366
22461
  ok: boolean(),
22367
22462
  error: string().optional()
22368
22463
  }), { auth: "admin" }), method(_void(), array(ProviderListEntrySchema).readonly()), method(object({
@@ -22432,6 +22527,51 @@ method(StorageMigrationInputSchema, StorageMigrationPlanSchema, { auth: "admin"
22432
22527
  kind: "mutation",
22433
22528
  auth: "admin"
22434
22529
  }), method(object({}), array(StorageMigrationJobSchema).readonly(), { auth: "admin" });
22530
+ /**
22531
+ * `storage-occupancy` — how many bytes an addon actually HOLDS on a storage
22532
+ * location (D388).
22533
+ *
22534
+ * ## Why this is not `storage-evictable`
22535
+ *
22536
+ * `storage-evictable.getEvictableUsage` looks like the same question and is
22537
+ * not, in two ways that both matter and both bite hardest on the locations an
22538
+ * operator most wants a figure for:
22539
+ *
22540
+ * - it reports the whole eviction DOMAIN, not the location. `recordings:default`
22541
+ * and `recordingsLow:default` deliberately share one root and evict as one
22542
+ * oldest-first pool, so both answer with the SAME combined total. As an
22543
+ * occupancy figure that double-counts the disk.
22544
+ * - it reports ZERO for a location whose eviction policy is `never` (D385) —
22545
+ * a `readonly` or `disabled` disk. Those are exactly the disks an operator
22546
+ * is retiring and staring at.
22547
+ *
22548
+ * So this is its own contract with its own quantity, and the quantity is
22549
+ * OCCUPIED: every byte the addon holds on that location, whether or not it
22550
+ * would ever be willing to delete it. A provider that can only answer
22551
+ * "evictable" must not register here — a number that silently means different
22552
+ * things per class is worse than no number.
22553
+ *
22554
+ * ## Absence is an answer
22555
+ *
22556
+ * A location nobody reports for is UNKNOWN, never zero (D315). The orchestrator
22557
+ * stamps `StorageLocation.owned` only for locations it has a report for, and
22558
+ * the field is an OBJECT rather than a bare number so that a `?? 0` on the
22559
+ * consuming side has to be written out loud instead of appearing by accident.
22560
+ *
22561
+ * `internal: true` — consumed by the orchestrator's `listLocations` stamp, never
22562
+ * a public client surface. Clients read the stamped `StorageLocation.owned`.
22563
+ */
22564
+ /** One provider's occupancy answer for one location. */
22565
+ var StorageOccupancyReportSchema = object({
22566
+ locationId: string(),
22567
+ /** Bytes this provider holds on THAT location — not its eviction domain, and
22568
+ * not net of what it is willing to delete. */
22569
+ ownedBytes: number().int().nonnegative(),
22570
+ /** When the provider last actually measured this. The orchestrator carries it
22571
+ * through so a UI can say how old the figure is instead of implying "now". */
22572
+ measuredAtMs: number().int().nonnegative()
22573
+ });
22574
+ method(object({ locationIds: array(string()).readonly() }), array(StorageOccupancyReportSchema).readonly(), { auth: "admin" });
22435
22575
  var ProviderInfoSchema = discriminatedUnion("shouldSaveDiskSpace", [object({
22436
22576
  providerId: string().min(1),
22437
22577
  displayName: string().min(1),
@@ -24071,39 +24211,6 @@ DeviceType.Camera, DeviceType.Sensor, DeviceType.Button, DeviceType.Switch, meth
24071
24211
  deviceId: number(),
24072
24212
  status: BatteryStatusSchema
24073
24213
  });
24074
- /**
24075
- * Network-link snapshot. Same shape for every provider (a Reolink wifi
24076
- * camera, a Home Assistant device with a signal-strength sensor, a Tapo
24077
- * plug): one slice under `device.runtimeState['network-link']`, one badge,
24078
- * one Home Assistant projection.
24079
- */
24080
- var NetworkLinkStatusSchema = object({
24081
- /** The link the device is on. `'unknown'` = not read yet, not "no link". */
24082
- type: _enum([
24083
- "wifi",
24084
- "ethernet",
24085
- "cellular",
24086
- "unknown"
24087
- ]),
24088
- /**
24089
- * Link quality, 0..100 inclusive, normalised by the provider from whatever
24090
- * the firmware reports (bars, RSSI, a vendor scale). **`null` means NOT
24091
- * KNOWN or NOT APPLICABLE** — a wired link has no signal, and a wireless
24092
- * one whose reading has not landed must not be drawn at 0 %. Consumers
24093
- * SKIP a null rather than coerce it.
24094
- */
24095
- signalPercent: number().min(0).max(100).nullable(),
24096
- /** Raw received signal strength in dBm, when the firmware reports one. */
24097
- rssiDbm: number().optional(),
24098
- /** Network name of a wireless link, when the firmware reports it. */
24099
- ssid: string().optional(),
24100
- /** Ms epoch of the last observation. Lets consumers reason about freshness. */
24101
- lastUpdated: number()
24102
- });
24103
- DeviceType.Camera, DeviceType.Sensor, DeviceType.Button, DeviceType.Switch, DeviceType.Light, DeviceType.Lock, DeviceType.Siren, object({
24104
- deviceId: number(),
24105
- status: NetworkLinkStatusSchema
24106
- });
24107
24214
  object({
24108
24215
  on: boolean(),
24109
24216
  /** Ms epoch of the last transition. 0 if never observed. */
@@ -26501,6 +26608,236 @@ DeviceType.Camera, method(object({
26501
26608
  detection: NativeDetectionSchema
26502
26609
  });
26503
26610
  /**
26611
+ * `navigation` — a device-scoped capability that natively expresses the FULL
26612
+ * navigation / action surface of a robot that DRIVES ITSELF and carries an
26613
+ * on-board camera (the Dreame robot-vacuum camera is the first provider).
26614
+ *
26615
+ * Why a NEW cap rather than overloading `ptz`:
26616
+ * - `ptz` moves a *gimbal* on a fixed camera (pan/tilt/zoom of the lens). A
26617
+ * robot vacuum has no gimbal — the whole chassis drives, turns and spins.
26618
+ * The two are different physical models: PTZ is absolute-position + presets,
26619
+ * navigation is momentary drive nudges + discrete robot ACTIONS
26620
+ * (dock / spot-clean / follow-pet / go-to-point / …).
26621
+ * - This cap is the SOURCE OF TRUTH. Two consumers adapt from it rather than
26622
+ * the reverse:
26623
+ * 1. a native CamStack navigation panel (data-driven from `listActions`
26624
+ * / `getOptions`), and
26625
+ * 2. the PTZ surface — a thin adapter mimics `ptz` from `navigation` so a
26626
+ * robot camera shows up in the existing PTZ control path without every
26627
+ * PTZ provider learning about robots. The mapping lives in the adapter,
26628
+ * not here (see the addon design note):
26629
+ * ptz.continuousMove({pan,tilt}) → navigation.move({pan,tilt})
26630
+ * ptz.stop() → navigation.stop()
26631
+ * ptz.goHome() → navigation.runAction('goHome')
26632
+ * ptz.getPresets() → navigation.listActions() (id→preset)
26633
+ * ptz.goToPreset(id) → navigation.runAction(id)
26634
+ *
26635
+ * ## Continuous drive
26636
+ *
26637
+ * `move` is MOMENTARY. Fluid navigation comes from the UI (or the PTZ adapter)
26638
+ * sending `move({pan,tilt})` REPEATEDLY at ~1 Hz while a direction is held, and
26639
+ * one `stop()` on release — exactly like the robot app's remote-drive joystick.
26640
+ * The provider forwards EACH `move` to one drive write; it must NOT debounce or
26641
+ * coalesce them. The UI owns the cadence.
26642
+ *
26643
+ * ## The action dictionary
26644
+ *
26645
+ * The discrete controls (dock / locate / spot-clean / follow / flash / sounds)
26646
+ * are a DATA-DRIVEN dictionary the cap exposes via `listActions()`. Each entry
26647
+ * carries `{ id, kind, label, icon }` (plus `soundId` for sound entries) so the
26648
+ * native panel AND the PTZ mimic render buttons WITHOUT hardcoding a
26649
+ * vendor-specific list. `kind: 'action'` entries are triggered with
26650
+ * `runAction({ actionId })`; `kind: 'sound'` entries with `playSound({ soundId })`
26651
+ * (the entry carries the `soundId` to pass). The general primitives — `move`,
26652
+ * `stop`, `goToPoint` — stay as first-class methods, not dictionary entries.
26653
+ *
26654
+ * NOTE (provider wiring): the first provider (Dreame) drives this with the RAW
26655
+ * `callAction(siid,aiid,in)` / `setProperty({siid,piid,value})` MIoT primitives
26656
+ * that the currently-published `@apocaliss92/nodedreame` already exposes on
26657
+ * every device handle. A future nodedreame publish adds a typed
26658
+ * `DreameCameraController` (drive / playPetSound / spotClean / findPet / …); the
26659
+ * provider can then swap the raw calls for the typed methods with no change to
26660
+ * THIS contract.
26661
+ */
26662
+ /**
26663
+ * A momentary drive nudge. The robot MOVES (no gimbal) for as long as the caller
26664
+ * keeps sending nudges (~1 Hz); an explicit `stop` (or letting the nudges lapse)
26665
+ * halts it.
26666
+ *
26667
+ * - `pan` — turn: negative = left, positive = right, 0 = straight.
26668
+ * - `tilt` — throttle: positive = forward, negative = spin / turn-around.
26669
+ * - `speed` — optional intensity hint [0, 1]; the provider may scale the drive
26670
+ * vector by it (drivers without proportional drive ignore it).
26671
+ *
26672
+ * `pan` / `tilt` are normalized [-1, 1]. Both optional so a caller can nudge one
26673
+ * axis alone; an all-undefined nudge is a no-op.
26674
+ */
26675
+ var NavigationMoveCommandSchema = object({
26676
+ pan: number().min(-1).max(1).optional(),
26677
+ tilt: number().min(-1).max(1).optional(),
26678
+ speed: number().min(0).max(1).optional()
26679
+ });
26680
+ /**
26681
+ * The enumerated discrete actions a navigation-capable robot can perform via
26682
+ * `runAction`. This is the CLOSED vocabulary; a given device advertises the
26683
+ * subset it supports through `listActions`. Sounds are NOT here — they go through
26684
+ * `playSound` (see the `sound` dictionary entries).
26685
+ */
26686
+ var NavigationActionIdSchema = _enum([
26687
+ "goHome",
26688
+ "locate",
26689
+ "spotClean",
26690
+ "findPet",
26691
+ "personFollow",
26692
+ "stop",
26693
+ "startClean",
26694
+ "pauseClean",
26695
+ "dockWash",
26696
+ "autoEmpty",
26697
+ "flashOn",
26698
+ "flashOff"
26699
+ ]);
26700
+ /** Whether a dictionary entry is a `runAction` action or a `playSound` sound. */
26701
+ var NavigationEntryKindSchema = _enum(["action", "sound"]);
26702
+ /**
26703
+ * One entry in the navigation action dictionary — the DATA-DRIVEN unit both the
26704
+ * native panel and the PTZ mimic render as a button.
26705
+ *
26706
+ * - `id` — stable id. For `kind:'action'` it is a {@link NavigationActionId}
26707
+ * (pass to `runAction`); for `kind:'sound'` it is a namespaced id
26708
+ * (`sound:meow`) whose `soundId` is passed to `playSound`.
26709
+ * - `icon` — icon HINT (lucide-style name; the UI maps it to its own set).
26710
+ * - `label` — operator-facing English label.
26711
+ * - `soundId` — wire sound id, present only on `kind:'sound'` entries.
26712
+ * - `enabled` — per-device FEATURE FLAG. `listActions` reports it so the UI /
26713
+ * PTZ render ONLY enabled entries. Data-driven: the provider
26714
+ * flips it from config, never by editing code.
26715
+ */
26716
+ var NavigationActionEntrySchema = object({
26717
+ id: string(),
26718
+ kind: NavigationEntryKindSchema,
26719
+ label: string(),
26720
+ icon: string(),
26721
+ /** Present only on `kind:'sound'` entries — the id to pass to `playSound`. */
26722
+ soundId: number().int().optional(),
26723
+ /** Per-device feature flag — render this entry only when true. */
26724
+ enabled: boolean()
26725
+ });
26726
+ /** Coordinates for `goToPoint` — a point on the robot's live map. */
26727
+ var NavigationPointSchema = object({
26728
+ x: number(),
26729
+ y: number()
26730
+ });
26731
+ /**
26732
+ * Per-device FEATURE-FLAG report for the general (non-dictionary) primitives.
26733
+ * The cap reports which are enabled so the UI / PTZ render only the controls
26734
+ * that are turned on for THIS device. Data-driven: the provider derives these
26735
+ * from config + probe, never hardcoded in the UI. The per-DICTIONARY-entry flags
26736
+ * live on {@link NavigationActionEntrySchema.enabled}; these gate the primitives
26737
+ * that are not dictionary entries.
26738
+ *
26739
+ * - `move` / `stop` — the momentary drive joystick.
26740
+ * - `goToPoint` — send-to-map-coordinate. Ships OFF on Dreame until the
26741
+ * map-coordinate plumbing is wired.
26742
+ * - `runAction` — the discrete action buttons (dictionary `kind:'action'`).
26743
+ * - `playSound` — the sound buttons (dictionary `kind:'sound'`).
26744
+ * - `light` — the on/off fill-light toggle (works anytime).
26745
+ * - `lightMode` — the auto/manual selector + manual level slider (a
26746
+ * camera-service control; needs an active stream).
26747
+ */
26748
+ var NavigationFeaturesSchema = object({
26749
+ move: boolean(),
26750
+ stop: boolean(),
26751
+ goToPoint: boolean(),
26752
+ runAction: boolean(),
26753
+ playSound: boolean(),
26754
+ light: boolean(),
26755
+ lightMode: boolean()
26756
+ });
26757
+ /** Light mode: `auto` lets the camera choose brightness; `manual` uses `level`. */
26758
+ var NavigationLightModeSchema = _enum(["auto", "manual"]);
26759
+ /**
26760
+ * Live navigation state so the UI can reflect what the robot is doing:
26761
+ * - `mode` — coarse activity (idle / cleaning / following / …).
26762
+ * - `following` — person/pet follow is currently armed.
26763
+ * - `flash` — the on-camera fill light is on.
26764
+ * - `lightMode` — auto vs manual fill-light mode.
26765
+ * - `lightLevel` — manual fill-light level (40..100); meaningful when
26766
+ * `lightMode === 'manual'`.
26767
+ */
26768
+ var NavigationStatusSchema = object({
26769
+ mode: _enum([
26770
+ "idle",
26771
+ "cleaning",
26772
+ "spot",
26773
+ "following",
26774
+ "goto",
26775
+ "returning",
26776
+ "paused",
26777
+ "unknown"
26778
+ ]),
26779
+ following: boolean(),
26780
+ flash: boolean(),
26781
+ lightMode: NavigationLightModeSchema,
26782
+ lightLevel: number().min(40).max(100),
26783
+ /** Ms epoch when the slice was last updated. */
26784
+ lastChangedAt: number()
26785
+ });
26786
+ NavigationStatusSchema.extend({ lastFetchedAt: number() });
26787
+ DeviceType.Camera, method(NavigationMoveCommandSchema.extend({ deviceId: number() }), _void(), { kind: "mutation" }), method(object({ deviceId: number() }), _void(), { kind: "mutation" }), method(NavigationPointSchema.extend({ deviceId: number() }), _void(), { kind: "mutation" }), method(object({ deviceId: number() }), array(NavigationActionEntrySchema)), method(object({
26788
+ deviceId: number(),
26789
+ actionId: NavigationActionIdSchema
26790
+ }), _void(), { kind: "mutation" }), method(object({
26791
+ deviceId: number(),
26792
+ soundId: number().int()
26793
+ }), _void(), { kind: "mutation" }), method(object({
26794
+ deviceId: number(),
26795
+ on: boolean()
26796
+ }), _void(), { kind: "mutation" }), method(object({
26797
+ deviceId: number(),
26798
+ mode: NavigationLightModeSchema,
26799
+ level: number().min(40).max(100).optional()
26800
+ }), _void(), { kind: "mutation" }), method(object({
26801
+ deviceId: number(),
26802
+ level: number().min(40).max(100)
26803
+ }), _void(), { kind: "mutation" }), method(object({ deviceId: number() }), NavigationFeaturesSchema), object({
26804
+ deviceId: number(),
26805
+ status: NavigationStatusSchema
26806
+ });
26807
+ /**
26808
+ * Network-link snapshot. Same shape for every provider (a Reolink wifi
26809
+ * camera, a Home Assistant device with a signal-strength sensor, a Tapo
26810
+ * plug): one slice under `device.runtimeState['network-link']`, one badge,
26811
+ * one Home Assistant projection.
26812
+ */
26813
+ var NetworkLinkStatusSchema = object({
26814
+ /** The link the device is on. `'unknown'` = not read yet, not "no link". */
26815
+ type: _enum([
26816
+ "wifi",
26817
+ "ethernet",
26818
+ "cellular",
26819
+ "unknown"
26820
+ ]),
26821
+ /**
26822
+ * Link quality, 0..100 inclusive, normalised by the provider from whatever
26823
+ * the firmware reports (bars, RSSI, a vendor scale). **`null` means NOT
26824
+ * KNOWN or NOT APPLICABLE** — a wired link has no signal, and a wireless
26825
+ * one whose reading has not landed must not be drawn at 0 %. Consumers
26826
+ * SKIP a null rather than coerce it.
26827
+ */
26828
+ signalPercent: number().min(0).max(100).nullable(),
26829
+ /** Raw received signal strength in dBm, when the firmware reports one. */
26830
+ rssiDbm: number().optional(),
26831
+ /** Network name of a wireless link, when the firmware reports it. */
26832
+ ssid: string().optional(),
26833
+ /** Ms epoch of the last observation. Lets consumers reason about freshness. */
26834
+ lastUpdated: number()
26835
+ });
26836
+ DeviceType.Camera, DeviceType.Sensor, DeviceType.Button, DeviceType.Switch, DeviceType.Light, DeviceType.Lock, DeviceType.Siren, object({
26837
+ deviceId: number(),
26838
+ status: NetworkLinkStatusSchema
26839
+ });
26840
+ /**
26504
26841
  * network-quality — system-scoped singleton capability tracking RTT,
26505
26842
  * jitter, and observed/peak bandwidth per device + per client.
26506
26843
  *
@@ -27742,203 +28079,6 @@ DeviceType.Camera, method(object({ deviceId: number() }), PtzAutotrackStatusSche
27742
28079
  deviceId: number(),
27743
28080
  status: PtzAutotrackStatusSchema
27744
28081
  });
27745
- /**
27746
- * `navigation` — a device-scoped capability that natively expresses the FULL
27747
- * navigation / action surface of a robot that DRIVES ITSELF and carries an
27748
- * on-board camera (the Dreame robot-vacuum camera is the first provider).
27749
- *
27750
- * Why a NEW cap rather than overloading `ptz`:
27751
- * - `ptz` moves a *gimbal* on a fixed camera (pan/tilt/zoom of the lens). A
27752
- * robot vacuum has no gimbal — the whole chassis drives, turns and spins.
27753
- * The two are different physical models: PTZ is absolute-position + presets,
27754
- * navigation is momentary drive nudges + discrete robot ACTIONS
27755
- * (dock / spot-clean / follow-pet / go-to-point / …).
27756
- * - This cap is the SOURCE OF TRUTH. Two consumers adapt from it rather than
27757
- * the reverse:
27758
- * 1. a native CamStack navigation panel (data-driven from `listActions`
27759
- * / `getOptions`), and
27760
- * 2. the PTZ surface — a thin adapter mimics `ptz` from `navigation` so a
27761
- * robot camera shows up in the existing PTZ control path without every
27762
- * PTZ provider learning about robots. The mapping lives in the adapter,
27763
- * not here (see the addon design note):
27764
- * ptz.continuousMove({pan,tilt}) → navigation.move({pan,tilt})
27765
- * ptz.stop() → navigation.stop()
27766
- * ptz.goHome() → navigation.runAction('goHome')
27767
- * ptz.getPresets() → navigation.listActions() (id→preset)
27768
- * ptz.goToPreset(id) → navigation.runAction(id)
27769
- *
27770
- * ## Continuous drive
27771
- *
27772
- * `move` is MOMENTARY. Fluid navigation comes from the UI (or the PTZ adapter)
27773
- * sending `move({pan,tilt})` REPEATEDLY at ~1 Hz while a direction is held, and
27774
- * one `stop()` on release — exactly like the robot app's remote-drive joystick.
27775
- * The provider forwards EACH `move` to one drive write; it must NOT debounce or
27776
- * coalesce them. The UI owns the cadence.
27777
- *
27778
- * ## The action dictionary
27779
- *
27780
- * The discrete controls (dock / locate / spot-clean / follow / flash / sounds)
27781
- * are a DATA-DRIVEN dictionary the cap exposes via `listActions()`. Each entry
27782
- * carries `{ id, kind, label, icon }` (plus `soundId` for sound entries) so the
27783
- * native panel AND the PTZ mimic render buttons WITHOUT hardcoding a
27784
- * vendor-specific list. `kind: 'action'` entries are triggered with
27785
- * `runAction({ actionId })`; `kind: 'sound'` entries with `playSound({ soundId })`
27786
- * (the entry carries the `soundId` to pass). The general primitives — `move`,
27787
- * `stop`, `goToPoint` — stay as first-class methods, not dictionary entries.
27788
- *
27789
- * NOTE (provider wiring): the first provider (Dreame) drives this with the RAW
27790
- * `callAction(siid,aiid,in)` / `setProperty({siid,piid,value})` MIoT primitives
27791
- * that the currently-published `@apocaliss92/nodedreame` already exposes on
27792
- * every device handle. A future nodedreame publish adds a typed
27793
- * `DreameCameraController` (drive / playPetSound / spotClean / findPet / …); the
27794
- * provider can then swap the raw calls for the typed methods with no change to
27795
- * THIS contract.
27796
- */
27797
- /**
27798
- * A momentary drive nudge. The robot MOVES (no gimbal) for as long as the caller
27799
- * keeps sending nudges (~1 Hz); an explicit `stop` (or letting the nudges lapse)
27800
- * halts it.
27801
- *
27802
- * - `pan` — turn: negative = left, positive = right, 0 = straight.
27803
- * - `tilt` — throttle: positive = forward, negative = spin / turn-around.
27804
- * - `speed` — optional intensity hint [0, 1]; the provider may scale the drive
27805
- * vector by it (drivers without proportional drive ignore it).
27806
- *
27807
- * `pan` / `tilt` are normalized [-1, 1]. Both optional so a caller can nudge one
27808
- * axis alone; an all-undefined nudge is a no-op.
27809
- */
27810
- var NavigationMoveCommandSchema = object({
27811
- pan: number().min(-1).max(1).optional(),
27812
- tilt: number().min(-1).max(1).optional(),
27813
- speed: number().min(0).max(1).optional()
27814
- });
27815
- /**
27816
- * The enumerated discrete actions a navigation-capable robot can perform via
27817
- * `runAction`. This is the CLOSED vocabulary; a given device advertises the
27818
- * subset it supports through `listActions`. Sounds are NOT here — they go through
27819
- * `playSound` (see the `sound` dictionary entries).
27820
- */
27821
- var NavigationActionIdSchema = _enum([
27822
- "goHome",
27823
- "locate",
27824
- "spotClean",
27825
- "findPet",
27826
- "personFollow",
27827
- "stop",
27828
- "startClean",
27829
- "pauseClean",
27830
- "dockWash",
27831
- "autoEmpty",
27832
- "flashOn",
27833
- "flashOff"
27834
- ]);
27835
- /** Whether a dictionary entry is a `runAction` action or a `playSound` sound. */
27836
- var NavigationEntryKindSchema = _enum(["action", "sound"]);
27837
- /**
27838
- * One entry in the navigation action dictionary — the DATA-DRIVEN unit both the
27839
- * native panel and the PTZ mimic render as a button.
27840
- *
27841
- * - `id` — stable id. For `kind:'action'` it is a {@link NavigationActionId}
27842
- * (pass to `runAction`); for `kind:'sound'` it is a namespaced id
27843
- * (`sound:meow`) whose `soundId` is passed to `playSound`.
27844
- * - `icon` — icon HINT (lucide-style name; the UI maps it to its own set).
27845
- * - `label` — operator-facing English label.
27846
- * - `soundId` — wire sound id, present only on `kind:'sound'` entries.
27847
- * - `enabled` — per-device FEATURE FLAG. `listActions` reports it so the UI /
27848
- * PTZ render ONLY enabled entries. Data-driven: the provider
27849
- * flips it from config, never by editing code.
27850
- */
27851
- var NavigationActionEntrySchema = object({
27852
- id: string(),
27853
- kind: NavigationEntryKindSchema,
27854
- label: string(),
27855
- icon: string(),
27856
- /** Present only on `kind:'sound'` entries — the id to pass to `playSound`. */
27857
- soundId: number().int().optional(),
27858
- /** Per-device feature flag — render this entry only when true. */
27859
- enabled: boolean()
27860
- });
27861
- /** Coordinates for `goToPoint` — a point on the robot's live map. */
27862
- var NavigationPointSchema = object({
27863
- x: number(),
27864
- y: number()
27865
- });
27866
- /**
27867
- * Per-device FEATURE-FLAG report for the general (non-dictionary) primitives.
27868
- * The cap reports which are enabled so the UI / PTZ render only the controls
27869
- * that are turned on for THIS device. Data-driven: the provider derives these
27870
- * from config + probe, never hardcoded in the UI. The per-DICTIONARY-entry flags
27871
- * live on {@link NavigationActionEntrySchema.enabled}; these gate the primitives
27872
- * that are not dictionary entries.
27873
- *
27874
- * - `move` / `stop` — the momentary drive joystick.
27875
- * - `goToPoint` — send-to-map-coordinate. Ships OFF on Dreame until the
27876
- * map-coordinate plumbing is wired.
27877
- * - `runAction` — the discrete action buttons (dictionary `kind:'action'`).
27878
- * - `playSound` — the sound buttons (dictionary `kind:'sound'`).
27879
- * - `light` — the on/off fill-light toggle (works anytime).
27880
- * - `lightMode` — the auto/manual selector + manual level slider (a
27881
- * camera-service control; needs an active stream).
27882
- */
27883
- var NavigationFeaturesSchema = object({
27884
- move: boolean(),
27885
- stop: boolean(),
27886
- goToPoint: boolean(),
27887
- runAction: boolean(),
27888
- playSound: boolean(),
27889
- light: boolean(),
27890
- lightMode: boolean()
27891
- });
27892
- /** Light mode: `auto` lets the camera choose brightness; `manual` uses `level`. */
27893
- var NavigationLightModeSchema = _enum(["auto", "manual"]);
27894
- /**
27895
- * Live navigation state so the UI can reflect what the robot is doing:
27896
- * - `mode` — coarse activity (idle / cleaning / following / …).
27897
- * - `following` — person/pet follow is currently armed.
27898
- * - `flash` — the on-camera fill light is on.
27899
- * - `lightMode` — auto vs manual fill-light mode.
27900
- * - `lightLevel` — manual fill-light level (40..100); meaningful when
27901
- * `lightMode === 'manual'`.
27902
- */
27903
- var NavigationStatusSchema = object({
27904
- mode: _enum([
27905
- "idle",
27906
- "cleaning",
27907
- "spot",
27908
- "following",
27909
- "goto",
27910
- "returning",
27911
- "paused",
27912
- "unknown"
27913
- ]),
27914
- following: boolean(),
27915
- flash: boolean(),
27916
- lightMode: NavigationLightModeSchema,
27917
- lightLevel: number().min(40).max(100),
27918
- /** Ms epoch when the slice was last updated. */
27919
- lastChangedAt: number()
27920
- });
27921
- NavigationStatusSchema.extend({ lastFetchedAt: number() });
27922
- DeviceType.Camera, method(NavigationMoveCommandSchema.extend({ deviceId: number() }), _void(), { kind: "mutation" }), method(object({ deviceId: number() }), _void(), { kind: "mutation" }), method(NavigationPointSchema.extend({ deviceId: number() }), _void(), { kind: "mutation" }), method(object({ deviceId: number() }), array(NavigationActionEntrySchema)), method(object({
27923
- deviceId: number(),
27924
- actionId: NavigationActionIdSchema
27925
- }), _void(), { kind: "mutation" }), method(object({
27926
- deviceId: number(),
27927
- soundId: number().int()
27928
- }), _void(), { kind: "mutation" }), method(object({
27929
- deviceId: number(),
27930
- on: boolean()
27931
- }), _void(), { kind: "mutation" }), method(object({
27932
- deviceId: number(),
27933
- mode: NavigationLightModeSchema,
27934
- level: number().min(40).max(100).optional()
27935
- }), _void(), { kind: "mutation" }), method(object({
27936
- deviceId: number(),
27937
- level: number().min(40).max(100)
27938
- }), _void(), { kind: "mutation" }), method(object({ deviceId: number() }), NavigationFeaturesSchema), object({
27939
- deviceId: number(),
27940
- status: NavigationStatusSchema
27941
- });
27942
28082
  DeviceType.Camera, DeviceType.Sensor, DeviceType.Switch, method(object({ deviceId: number().int().nonnegative() }), object({ success: literal(true) }), {
27943
28083
  kind: "mutation",
27944
28084
  auth: "admin"
@@ -35278,6 +35418,12 @@ Object.freeze({
35278
35418
  addonId: null,
35279
35419
  access: "view"
35280
35420
  },
35421
+ "storage.listDrainProgress": {
35422
+ capName: "storage",
35423
+ capScope: "system",
35424
+ addonId: null,
35425
+ access: "view"
35426
+ },
35281
35427
  "storage.listLocationDeclarations": {
35282
35428
  capName: "storage",
35283
35429
  capScope: "system",
@@ -35422,6 +35568,12 @@ Object.freeze({
35422
35568
  addonId: null,
35423
35569
  access: "view"
35424
35570
  },
35571
+ "storageOccupancy.getOccupancy": {
35572
+ capName: "storage-occupancy",
35573
+ capScope: "system",
35574
+ addonId: null,
35575
+ access: "view"
35576
+ },
35425
35577
  "storageProvider.abortUpload": {
35426
35578
  capName: "storage-provider",
35427
35579
  capScope: "system",
@@ -38802,32 +38954,221 @@ DEFAULT_NATIVE_LEASE_SETTINGS.sceneBudgetMb;
38802
38954
  DEFAULT_NATIVE_LEASE_SETTINGS.admission;
38803
38955
  var MB = 1024 * 1024;
38804
38956
  1024 * MB, 3072 * MB;
38805
- /**
38806
- * Compute the stable 64-char lowercase-hex fingerprint of a device's
38807
- * export-relevant shape. Two structurally-equal shapes (any feature order,
38808
- * any duplicates, any deviceId) hash identically.
38809
- */
38810
- function canonicalDeviceFingerprint(shape) {
38811
- const features = [...new Set(shape.features)].toSorted();
38812
- return canonicalHash({
38813
- deviceType: shape.deviceType,
38814
- features
38815
- });
38816
- }
38817
- /**
38818
- * Resolve the fingerprint an exporter should feed into `diffExportTargets`
38819
- * for one device this cycle.
38820
- *
38821
- * When a device is NOT yet probe-ready, carry forward its last-advertised
38822
- * (persisted) fingerprint so it nets to NO CHANGE in `diffExportTargets`
38823
- * (neither update nor remove) — never advertise a partial mid-probe shape. A
38824
- * brand-new un-probed device with no persisted entry falls back to `fresh` so
38825
- * it can advertise once.
38826
- */
38827
- function resolveExportFingerprint(input) {
38828
- if (input.ready) return input.fresh;
38829
- return input.persisted ?? input.fresh;
38830
- }
38957
+ var DEFAULT_FIRST_UNIT_TIMEOUT_MS = 12e3;
38958
+ /** Heartbeat cadence — ~2 minutes of 4 s fragments. */
38959
+ var FRAGMENT_LOG_EVERY = 30;
38960
+ var Fmp4FragmentChild = class {
38961
+ deps;
38962
+ args;
38963
+ child = null;
38964
+ splitter = new Fmp4BoxSplitter();
38965
+ stopped = false;
38966
+ unitsOut = 0;
38967
+ activeHwAccel = null;
38968
+ constructor(deps, args) {
38969
+ this.deps = deps;
38970
+ this.args = args;
38971
+ }
38972
+ /** Spawn, and resolve once the INIT segment has been cut out of stdout. */
38973
+ async start() {
38974
+ const requested = this.args.invocation.decodeHwAccel;
38975
+ this.activeHwAccel = requested;
38976
+ try {
38977
+ await this.spawnAttempt(requested);
38978
+ return;
38979
+ } catch (err) {
38980
+ if (this.stopped) throw err;
38981
+ if (requested === null || isSoftwareDecode(requested)) throw err;
38982
+ this.deps.logger.warn("fmp4 fragment child: hardware decode produced NO fragment — retrying in SOFTWARE", {
38983
+ tags: { deviceId: this.args.deviceId },
38984
+ meta: {
38985
+ sourceId: this.args.sourceId,
38986
+ decodeHwAccel: requested,
38987
+ error: errMsg$15(err)
38988
+ }
38989
+ });
38990
+ this.killChild();
38991
+ this.splitter = new Fmp4BoxSplitter();
38992
+ this.activeHwAccel = null;
38993
+ await this.spawnAttempt(null);
38994
+ }
38995
+ }
38996
+ /** The backend the child ACTUALLY ran with — `null` for software. */
38997
+ activeDecodeHwAccel() {
38998
+ const value = this.activeHwAccel;
38999
+ return value === null || value === "none" || value === "copy" ? null : value;
39000
+ }
39001
+ /** Kill ffmpeg and end the plane. Idempotent. */
39002
+ async stop() {
39003
+ if (this.stopped) return;
39004
+ this.stopped = true;
39005
+ this.killChild();
39006
+ this.args.plane.end("the fragment child stopped");
39007
+ }
39008
+ spawnAttempt(decodeHwAccel) {
39009
+ const args = buildFfmpegArgs({
39010
+ ...this.args.invocation,
39011
+ decodeHwAccel,
39012
+ sink: {
39013
+ kind: "stdout",
39014
+ container: "mp4",
39015
+ fragmentMs: this.args.fragmentMs
39016
+ }
39017
+ });
39018
+ this.deps.logger.info("fmp4 fragment child: spawning ffmpeg", {
39019
+ tags: { deviceId: this.args.deviceId },
39020
+ meta: {
39021
+ sourceId: this.args.sourceId,
39022
+ fragmentMs: this.args.fragmentMs,
39023
+ decodeHwAccel: decodeHwAccel ?? "software",
39024
+ argv: args.join(" ")
39025
+ }
39026
+ });
39027
+ return new Promise((resolve, reject) => {
39028
+ const child = this.deps.spawnFn(this.deps.ffmpegBinaryPath, args, { stdio: [
39029
+ "ignore",
39030
+ "pipe",
39031
+ "pipe"
39032
+ ] });
39033
+ this.child = child;
39034
+ let settled = false;
39035
+ /**
39036
+ * This attempt FAILED. Set before the kill, because SIGTERM makes the
39037
+ * child exit and that exit must not be reported as a death: the retry —
39038
+ * or the caller's rejection — already owns what happens next. Without it
39039
+ * the timeout path ends the plane the software retry is about to fill,
39040
+ * and the consumer sees a stream that stopped for no reason. A "which
39041
+ * spawn is current" counter does NOT cover this: the retry has not been
39042
+ * spawned when the kill's exit arrives.
39043
+ */
39044
+ let failed = false;
39045
+ /**
39046
+ * This attempt is still the live producer: it has not failed (a failure
39047
+ * hands ownership to the retry, or to the caller's rejection) and nothing
39048
+ * has stopped the child. Those two cover every way an attempt stops being
39049
+ * current — `start` only respawns after a rejection.
39050
+ */
39051
+ const isCurrent = () => !this.stopped && !failed;
39052
+ const timeoutMs = this.deps.firstUnitTimeoutMs ?? DEFAULT_FIRST_UNIT_TIMEOUT_MS;
39053
+ const settle = (fail) => {
39054
+ if (settled) return;
39055
+ settled = true;
39056
+ clearTimeout(timer);
39057
+ if (fail) {
39058
+ failed = true;
39059
+ reject(fail);
39060
+ } else resolve();
39061
+ };
39062
+ const timer = setTimeout(() => {
39063
+ settle(/* @__PURE__ */ new Error(`fmp4 fragment child: no fragment within ${timeoutMs}ms`));
39064
+ this.killChild();
39065
+ }, timeoutMs);
39066
+ timer.unref?.();
39067
+ child.stdout?.on("data", (chunk) => {
39068
+ for (const unit of this.splitter.push(chunk)) {
39069
+ this.unitsOut += 1;
39070
+ this.args.plane.publish(unit);
39071
+ if (unit.kind === "init") {
39072
+ this.deps.logger.info("fmp4 fragment child: INIT segment cut", {
39073
+ tags: { deviceId: this.args.deviceId },
39074
+ meta: {
39075
+ sourceId: this.args.sourceId,
39076
+ bytes: unit.data.length
39077
+ }
39078
+ });
39079
+ settle();
39080
+ } else if (this.unitsOut % FRAGMENT_LOG_EVERY === 0) this.deps.logger.info("fmp4 fragment child: fragments still flowing", {
39081
+ tags: { deviceId: this.args.deviceId },
39082
+ meta: {
39083
+ sourceId: this.args.sourceId,
39084
+ unitsOut: this.unitsOut,
39085
+ bytes: unit.data.length,
39086
+ subscribers: this.args.plane.subscriberCount
39087
+ }
39088
+ });
39089
+ }
39090
+ const fault = this.splitter.fault;
39091
+ if (fault !== null) this.onFault(fault, settled, isCurrent(), settle);
39092
+ });
39093
+ child.stderr?.setEncoding("utf8");
39094
+ child.stderr?.on("data", (line) => {
39095
+ this.deps.logger.debug("fmp4 fragment child ffmpeg", {
39096
+ tags: { deviceId: this.args.deviceId },
39097
+ meta: {
39098
+ sourceId: this.args.sourceId,
39099
+ line: line.trim()
39100
+ }
39101
+ });
39102
+ });
39103
+ child.once("error", (err) => {
39104
+ if (!settled) {
39105
+ settle(err);
39106
+ return;
39107
+ }
39108
+ if (!isCurrent()) return;
39109
+ this.args.plane.end("the fragment child errored");
39110
+ this.deps.onChildExit?.(err);
39111
+ });
39112
+ child.once("exit", (code, signal) => {
39113
+ if (!settled) {
39114
+ settle(/* @__PURE__ */ new Error(`fmp4 fragment child: ffmpeg exited before any fragment (code=${code} signal=${signal})`));
39115
+ return;
39116
+ }
39117
+ if (!isCurrent()) return;
39118
+ const error = /* @__PURE__ */ new Error(`fmp4 fragment child: ffmpeg exited while live (code=${code} signal=${signal})`);
39119
+ this.deps.logger.warn("fmp4 fragment child: ffmpeg exited while live", {
39120
+ tags: { deviceId: this.args.deviceId },
39121
+ meta: {
39122
+ sourceId: this.args.sourceId,
39123
+ code,
39124
+ signal,
39125
+ unitsOut: this.unitsOut
39126
+ }
39127
+ });
39128
+ this.args.plane.end("the fragment child exited");
39129
+ this.deps.onChildExit?.(error);
39130
+ });
39131
+ });
39132
+ }
39133
+ /**
39134
+ * The byte stream stopped being splittable. Not recoverable — the splitter
39135
+ * cannot resynchronise mid-box — so the child is a corpse and every consumer
39136
+ * has to be told, loudly, with the reason.
39137
+ */
39138
+ onFault(reason, wasLive, current, settle) {
39139
+ const error = /* @__PURE__ */ new Error(`fmp4 fragment child: ${reason}`);
39140
+ this.deps.logger.error("fmp4 fragment child: the ffmpeg output stopped parsing as fMP4", {
39141
+ tags: { deviceId: this.args.deviceId },
39142
+ meta: {
39143
+ sourceId: this.args.sourceId,
39144
+ unitsOut: this.unitsOut,
39145
+ interstitial: this.splitter.discardedInterstitialTypes,
39146
+ reason
39147
+ }
39148
+ });
39149
+ this.killChild();
39150
+ settle(error);
39151
+ if (wasLive && current) {
39152
+ this.args.plane.end("the fragment child produced unsplittable output");
39153
+ this.deps.onChildExit?.(error);
39154
+ }
39155
+ }
39156
+ killChild() {
39157
+ const child = this.child;
39158
+ this.child = null;
39159
+ if (child && !child.killed) try {
39160
+ child.kill("SIGTERM");
39161
+ } catch (err) {
39162
+ this.deps.logger.warn("fmp4 fragment child: kill error", {
39163
+ tags: { deviceId: this.args.deviceId },
39164
+ meta: {
39165
+ sourceId: this.args.sourceId,
39166
+ error: errMsg$15(err)
39167
+ }
39168
+ });
39169
+ }
39170
+ }
39171
+ };
38831
39172
  /**
38832
39173
  * Fmp4FragmentPlane — a SUBSCRIBABLE fragmented-MP4 plane, fed by one
38833
39174
  * {@link import('./fmp4-box-splitter.js').Fmp4BoxSplitter}.
@@ -39113,221 +39454,32 @@ var Fmp4FragmentPlane = class {
39113
39454
  }
39114
39455
  }
39115
39456
  };
39116
- var DEFAULT_FIRST_UNIT_TIMEOUT_MS = 12e3;
39117
- /** Heartbeat cadence — ~2 minutes of 4 s fragments. */
39118
- var FRAGMENT_LOG_EVERY = 30;
39119
- var Fmp4FragmentChild = class {
39120
- deps;
39121
- args;
39122
- child = null;
39123
- splitter = new Fmp4BoxSplitter();
39124
- stopped = false;
39125
- unitsOut = 0;
39126
- activeHwAccel = null;
39127
- constructor(deps, args) {
39128
- this.deps = deps;
39129
- this.args = args;
39130
- }
39131
- /** Spawn, and resolve once the INIT segment has been cut out of stdout. */
39132
- async start() {
39133
- const requested = this.args.invocation.decodeHwAccel;
39134
- this.activeHwAccel = requested;
39135
- try {
39136
- await this.spawnAttempt(requested);
39137
- return;
39138
- } catch (err) {
39139
- if (this.stopped) throw err;
39140
- if (requested === null || isSoftwareDecode(requested)) throw err;
39141
- this.deps.logger.warn("fmp4 fragment child: hardware decode produced NO fragment — retrying in SOFTWARE", {
39142
- tags: { deviceId: this.args.deviceId },
39143
- meta: {
39144
- sourceId: this.args.sourceId,
39145
- decodeHwAccel: requested,
39146
- error: errMsg$15(err)
39147
- }
39148
- });
39149
- this.killChild();
39150
- this.splitter = new Fmp4BoxSplitter();
39151
- this.activeHwAccel = null;
39152
- await this.spawnAttempt(null);
39153
- }
39154
- }
39155
- /** The backend the child ACTUALLY ran with — `null` for software. */
39156
- activeDecodeHwAccel() {
39157
- const value = this.activeHwAccel;
39158
- return value === null || value === "none" || value === "copy" ? null : value;
39159
- }
39160
- /** Kill ffmpeg and end the plane. Idempotent. */
39161
- async stop() {
39162
- if (this.stopped) return;
39163
- this.stopped = true;
39164
- this.killChild();
39165
- this.args.plane.end("the fragment child stopped");
39166
- }
39167
- spawnAttempt(decodeHwAccel) {
39168
- const args = buildFfmpegArgs({
39169
- ...this.args.invocation,
39170
- decodeHwAccel,
39171
- sink: {
39172
- kind: "stdout",
39173
- container: "mp4",
39174
- fragmentMs: this.args.fragmentMs
39175
- }
39176
- });
39177
- this.deps.logger.info("fmp4 fragment child: spawning ffmpeg", {
39178
- tags: { deviceId: this.args.deviceId },
39179
- meta: {
39180
- sourceId: this.args.sourceId,
39181
- fragmentMs: this.args.fragmentMs,
39182
- decodeHwAccel: decodeHwAccel ?? "software",
39183
- argv: args.join(" ")
39184
- }
39185
- });
39186
- return new Promise((resolve, reject) => {
39187
- const child = this.deps.spawnFn(this.deps.ffmpegBinaryPath, args, { stdio: [
39188
- "ignore",
39189
- "pipe",
39190
- "pipe"
39191
- ] });
39192
- this.child = child;
39193
- let settled = false;
39194
- /**
39195
- * This attempt FAILED. Set before the kill, because SIGTERM makes the
39196
- * child exit and that exit must not be reported as a death: the retry —
39197
- * or the caller's rejection — already owns what happens next. Without it
39198
- * the timeout path ends the plane the software retry is about to fill,
39199
- * and the consumer sees a stream that stopped for no reason. A "which
39200
- * spawn is current" counter does NOT cover this: the retry has not been
39201
- * spawned when the kill's exit arrives.
39202
- */
39203
- let failed = false;
39204
- /**
39205
- * This attempt is still the live producer: it has not failed (a failure
39206
- * hands ownership to the retry, or to the caller's rejection) and nothing
39207
- * has stopped the child. Those two cover every way an attempt stops being
39208
- * current — `start` only respawns after a rejection.
39209
- */
39210
- const isCurrent = () => !this.stopped && !failed;
39211
- const timeoutMs = this.deps.firstUnitTimeoutMs ?? DEFAULT_FIRST_UNIT_TIMEOUT_MS;
39212
- const settle = (fail) => {
39213
- if (settled) return;
39214
- settled = true;
39215
- clearTimeout(timer);
39216
- if (fail) {
39217
- failed = true;
39218
- reject(fail);
39219
- } else resolve();
39220
- };
39221
- const timer = setTimeout(() => {
39222
- settle(/* @__PURE__ */ new Error(`fmp4 fragment child: no fragment within ${timeoutMs}ms`));
39223
- this.killChild();
39224
- }, timeoutMs);
39225
- timer.unref?.();
39226
- child.stdout?.on("data", (chunk) => {
39227
- for (const unit of this.splitter.push(chunk)) {
39228
- this.unitsOut += 1;
39229
- this.args.plane.publish(unit);
39230
- if (unit.kind === "init") {
39231
- this.deps.logger.info("fmp4 fragment child: INIT segment cut", {
39232
- tags: { deviceId: this.args.deviceId },
39233
- meta: {
39234
- sourceId: this.args.sourceId,
39235
- bytes: unit.data.length
39236
- }
39237
- });
39238
- settle();
39239
- } else if (this.unitsOut % FRAGMENT_LOG_EVERY === 0) this.deps.logger.info("fmp4 fragment child: fragments still flowing", {
39240
- tags: { deviceId: this.args.deviceId },
39241
- meta: {
39242
- sourceId: this.args.sourceId,
39243
- unitsOut: this.unitsOut,
39244
- bytes: unit.data.length,
39245
- subscribers: this.args.plane.subscriberCount
39246
- }
39247
- });
39248
- }
39249
- const fault = this.splitter.fault;
39250
- if (fault !== null) this.onFault(fault, settled, isCurrent(), settle);
39251
- });
39252
- child.stderr?.setEncoding("utf8");
39253
- child.stderr?.on("data", (line) => {
39254
- this.deps.logger.debug("fmp4 fragment child ffmpeg", {
39255
- tags: { deviceId: this.args.deviceId },
39256
- meta: {
39257
- sourceId: this.args.sourceId,
39258
- line: line.trim()
39259
- }
39260
- });
39261
- });
39262
- child.once("error", (err) => {
39263
- if (!settled) {
39264
- settle(err);
39265
- return;
39266
- }
39267
- if (!isCurrent()) return;
39268
- this.args.plane.end("the fragment child errored");
39269
- this.deps.onChildExit?.(err);
39270
- });
39271
- child.once("exit", (code, signal) => {
39272
- if (!settled) {
39273
- settle(/* @__PURE__ */ new Error(`fmp4 fragment child: ffmpeg exited before any fragment (code=${code} signal=${signal})`));
39274
- return;
39275
- }
39276
- if (!isCurrent()) return;
39277
- const error = /* @__PURE__ */ new Error(`fmp4 fragment child: ffmpeg exited while live (code=${code} signal=${signal})`);
39278
- this.deps.logger.warn("fmp4 fragment child: ffmpeg exited while live", {
39279
- tags: { deviceId: this.args.deviceId },
39280
- meta: {
39281
- sourceId: this.args.sourceId,
39282
- code,
39283
- signal,
39284
- unitsOut: this.unitsOut
39285
- }
39286
- });
39287
- this.args.plane.end("the fragment child exited");
39288
- this.deps.onChildExit?.(error);
39289
- });
39290
- });
39291
- }
39292
- /**
39293
- * The byte stream stopped being splittable. Not recoverable — the splitter
39294
- * cannot resynchronise mid-box — so the child is a corpse and every consumer
39295
- * has to be told, loudly, with the reason.
39296
- */
39297
- onFault(reason, wasLive, current, settle) {
39298
- const error = /* @__PURE__ */ new Error(`fmp4 fragment child: ${reason}`);
39299
- this.deps.logger.error("fmp4 fragment child: the ffmpeg output stopped parsing as fMP4", {
39300
- tags: { deviceId: this.args.deviceId },
39301
- meta: {
39302
- sourceId: this.args.sourceId,
39303
- unitsOut: this.unitsOut,
39304
- interstitial: this.splitter.discardedInterstitialTypes,
39305
- reason
39306
- }
39307
- });
39308
- this.killChild();
39309
- settle(error);
39310
- if (wasLive && current) {
39311
- this.args.plane.end("the fragment child produced unsplittable output");
39312
- this.deps.onChildExit?.(error);
39313
- }
39314
- }
39315
- killChild() {
39316
- const child = this.child;
39317
- this.child = null;
39318
- if (child && !child.killed) try {
39319
- child.kill("SIGTERM");
39320
- } catch (err) {
39321
- this.deps.logger.warn("fmp4 fragment child: kill error", {
39322
- tags: { deviceId: this.args.deviceId },
39323
- meta: {
39324
- sourceId: this.args.sourceId,
39325
- error: errMsg$15(err)
39326
- }
39327
- });
39328
- }
39329
- }
39330
- };
39457
+ /**
39458
+ * Compute the stable 64-char lowercase-hex fingerprint of a device's
39459
+ * export-relevant shape. Two structurally-equal shapes (any feature order,
39460
+ * any duplicates, any deviceId) hash identically.
39461
+ */
39462
+ function canonicalDeviceFingerprint(shape) {
39463
+ const features = [...new Set(shape.features)].toSorted();
39464
+ return canonicalHash({
39465
+ deviceType: shape.deviceType,
39466
+ features
39467
+ });
39468
+ }
39469
+ /**
39470
+ * Resolve the fingerprint an exporter should feed into `diffExportTargets`
39471
+ * for one device this cycle.
39472
+ *
39473
+ * When a device is NOT yet probe-ready, carry forward its last-advertised
39474
+ * (persisted) fingerprint so it nets to NO CHANGE in `diffExportTargets`
39475
+ * (neither update nor remove) — never advertise a partial mid-probe shape. A
39476
+ * brand-new un-probed device with no persisted entry falls back to `fresh` so
39477
+ * it can advertise once.
39478
+ */
39479
+ function resolveExportFingerprint(input) {
39480
+ if (input.ready) return input.fresh;
39481
+ return input.persisted ?? input.fresh;
39482
+ }
39331
39483
  //#endregion
39332
39484
  //#region ../../node_modules/tslib/tslib.es6.mjs
39333
39485
  var tslib_es6_exports = /* @__PURE__ */ __exportAll({