@camstack/addon-export-hap 1.2.90 → 1.2.91

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