@camstack/addon-provider-amcrest 0.2.124 → 0.2.125

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/dist/addon.js +230 -223
  2. package/dist/addon.mjs +230 -223
  3. package/package.json +1 -1
package/dist/addon.js CHANGED
@@ -34,7 +34,7 @@ let node_stream = require("node:stream");
34
34
  let node_stream_promises = require("node:stream/promises");
35
35
  let node_child_process = require("node:child_process");
36
36
  let node_os = require("node:os");
37
- //#region ../types/dist/event-category-C5xZWqz6.mjs
37
+ //#region ../types/dist/event-category-BGmz_oxW.mjs
38
38
  var EventCategory = /* @__PURE__ */ function(EventCategory) {
39
39
  EventCategory["SystemBoot"] = "system.boot";
40
40
  EventCategory["SystemAddonsReady"] = "system.addons-ready";
@@ -567,6 +567,15 @@ var EventCategory = /* @__PURE__ */ function(EventCategory) {
567
567
  */
568
568
  EventCategory["PipelineAudioInferenceResult"] = "pipeline.audio-inference-result";
569
569
  EventCategory["DetectionPhaseTransition"] = "detection.phase-transition";
570
+ /**
571
+ * A camera provider's RAW onboard motion push (D673): the `MotionOnMotionChanged`
572
+ * data shape without `triggeredBy`, built by `providerMotionEvent`. Its one
573
+ * consumer is the orchestrator's camera-sensors bridge, which re-emits the
574
+ * camera's EFFECTIVE onboard motion as `MotionOnMotionChanged` (a pass-through
575
+ * for a camera with no attached sensor). Providers must not emit
576
+ * `MotionOnMotionChanged` themselves; `scripts/check-onboard-motion-emitters.ts`
577
+ * keeps it so (camera-grid is a named, deferred exception).
578
+ */
570
579
  EventCategory["ProviderMotion"] = "provider.motion";
571
580
  EventCategory["ProviderDetection"] = "provider.detection";
572
581
  EventCategory["EnrichmentEmbeddingStored"] = "enrichment.embedding.stored";
@@ -5405,7 +5414,7 @@ var ZodIssueCode = {
5405
5414
  var ZodFirstPartyTypeKind;
5406
5415
  ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
5407
5416
  //#endregion
5408
- //#region ../types/dist/sleep-gU6hqv4_.mjs
5417
+ //#region ../types/dist/sleep-CDCONfkt.mjs
5409
5418
  /**
5410
5419
  * The audio chunk plane's byte format, and the ONE expansion from a coded
5411
5420
  * window to float samples (D455).
@@ -7438,7 +7447,7 @@ var DeviceRole = /* @__PURE__ */ function(DeviceRole) {
7438
7447
  return DeviceRole;
7439
7448
  }({});
7440
7449
  //#endregion
7441
- //#region ../types/dist/composition-Dq42XWp0.mjs
7450
+ //#region ../types/dist/composition-43aqsZQj.mjs
7442
7451
  /**
7443
7452
  * The ffmpeg build every CamStack node downloads, per platform and arch.
7444
7453
  *
@@ -7495,13 +7504,12 @@ portable("linux64"), portable("linuxarm64"), portable("macarm64"), portable("mac
7495
7504
  * LA tabella "quale booleano di questo tipo di device conta come ALTO", e il
7496
7505
  * valutatore puro del suo FRONTE.
7497
7506
  *
7498
- * Viveva dentro il builtin virtual-doorbell
7499
- * (`@camstack/system` — `builtins/doorbell/trigger-engine.ts`) e i suoi
7500
- * predicati erano privati al modulo. Il recorder ne ha bisogno per il trigger
7501
- * `RecordingTriggers.sensorDeviceIds`: copiarla avrebbe creato la SECONDA
7502
- * tabella, che diverge alla prima cap aggiunta e il cui sintomo — "il sensore
7503
- * fa suonare il campanello ma non registra" — è esattamente D62. Quindi si
7504
- * SPOSTA qui e il doorbell la ri-esporta.
7507
+ * UNA tabella per tutti quelli che chiedono "questo device è ALTO?": il
7508
+ * trigger `RecordingTriggers.sensorDeviceIds` del recorder, i marker dei
7509
+ * sensori della post-analysis, il bridge camera-sensors dell'orchestratore e
7510
+ * le sorgenti di un campanello composto (`doorbellFeatureSources`, D671).
7511
+ * Una seconda copia divergerebbe alla prima cap aggiunta, e il sintomo — "il
7512
+ * sensore fa suonare il campanello ma non registra" — è esattamente D62.
7505
7513
  *
7506
7514
  * ⚠ NON è `DEVICE_STATE_READERS` (`catalogs/device-state-vocabulary.ts`), e le
7507
7515
  * due non vanno unificate: quella risponde a "qual è la PAROLA di stato per una
@@ -7527,8 +7535,6 @@ var SOURCE_CAP_ACTIVE_FIELD = {
7527
7535
  vibration: "detected",
7528
7536
  tamper: "tampered"
7529
7537
  };
7530
- /** Cap names whose presence in a device's bindings qualify it as a source. */
7531
- var SOURCE_CAPS = Object.keys(SOURCE_CAP_ACTIVE_FIELD);
7532
7538
  /**
7533
7539
  * Error types for the safe expression engine. Two distinct classes so callers
7534
7540
  * can tell a compile-time (grammar) failure from a runtime (evaluation)
@@ -9258,7 +9264,7 @@ var RecordingTriggersSchema = object({
9258
9264
  *
9259
9265
  * Cosa vuol dire "alto" dipende dal TIPO di device e non è deciso qui:
9260
9266
  * `SOURCE_CAP_ACTIVE_FIELD` (`catalogs/sensor-active-state.ts`) è LA tabella,
9261
- * la stessa che il virtual-doorbell usa dal 2026-08-05. Ed è il FRONTE, non
9267
+ * la stessa del campanello composto (D671). Ed è il FRONTE, non
9262
9268
  * il livello: un contatto trovato già aperto al riavvio del runner non fa
9263
9269
  * registrare.
9264
9270
  */
@@ -15747,109 +15753,10 @@ method(object({
15747
15753
  deviceIds: array(number()).readonly(),
15748
15754
  caps: array(string()).readonly().optional()
15749
15755
  }), record(string(), record(string(), unknown().nullable())));
15750
- /**
15751
- * Doorbell button cap. Two kinds of providers coexist behind this cap
15752
- * name (same pattern as `snapshot`):
15753
- *
15754
- * - **Native** providers: registered per-device by device-driver
15755
- * addons via `ctx.registerNativeCap` — either on a
15756
- * `DeviceType.Button` accessory with `role: DeviceRole.Doorbell`,
15757
- * or directly on the camera (Reolink registers at camera level).
15758
- * Emits an `onPressed` event every time the firmware pushes a
15759
- * ring; status tracks the last press and a pressCount since start
15760
- * (diagnostic).
15761
- *
15762
- * - **Wrapper** provider: the `virtual-doorbell` system builtin
15763
- * (`@camstack/system/builtins/doorbell`). Turns ANY binary-ish
15764
- * device (contact / switch / event-emitter …) into a doorbell for
15765
- * a camera. `defaultActive: false` — the operator explicitly binds
15766
- * it per camera in the device-bindings UI, then picks the source
15767
- * device + trigger in the per-device settings.
15768
- *
15769
- * The DeviceEventPropagator re-emits `onPressed` on the camera parent
15770
- * — subscribers listening at the camera level receive ring events
15771
- * with `via[]` populated. No code on the parent needed.
15772
- */
15773
- var DoorbellStatusSchema = object({
15774
- /** Ms epoch of the last press. null = never observed since this provider started. */
15775
- lastPressedAt: number().nullable(),
15776
- /** Counter since provider start. Resets on reboot. Useful for metrics/debug. */
15777
- pressCountSinceStart: number()
15778
- });
15779
- var DoorbellPressEventSchema = object({
15780
- deviceId: number(),
15781
- timestamp: number()
15782
- });
15783
- /**
15784
- * The `doorbell-source` extension slot's editable value (D648): the camera's
15785
- * virtual-doorbell trigger devices, exactly what the wrapper's
15786
- * `doorbellSources` persists (as `{ deviceId }` records).
15787
- */
15788
- var DoorbellSourceSlotValueSchema = object({ deviceIds: array(number().int().positive()) });
15789
- /**
15790
- * The `doorbell-source` slot — which devices ring this camera's VIRTUAL
15791
- * doorbell, owned by the `virtual-doorbell` wrapper over its
15792
- * `doorbellSources` store (D648). A source rings when one of its
15793
- * `SOURCE_CAPS` rises. Whether the wrapper is bound to the camera at all is a
15794
- * different authority (`deviceManager.setWrapperActive`, D62) — the slot
15795
- * reports it, it never writes it.
15796
- */
15797
- var DOORBELL_SOURCE_SLOT = {
15798
- id: "doorbell-source",
15799
- label: "Doorbell trigger devices",
15800
- description: "Any of these becoming active rings this camera's virtual doorbell: a binary sensor when it goes active, a switch when it turns on.",
15801
- shape: "association",
15802
- hostDeviceTypes: [DeviceType.Camera],
15803
- sourceCaps: SOURCE_CAPS,
15804
- cardinality: "many",
15805
- value: DoorbellSourceSlotValueSchema
15806
- };
15807
- var doorbellCapability = {
15808
- name: "doorbell",
15809
- scope: "device",
15810
- deviceNative: true,
15811
- mode: "singleton",
15812
- kind: "wrapper",
15813
- defaultActive: false,
15814
- deviceTypes: [DeviceType.Button, DeviceType.Camera],
15815
- extensionSlots: [DOORBELL_SOURCE_SLOT],
15816
- methods: {},
15817
- events: {
15818
- /**
15819
- * Fires once per physical press. Reolink delivers via Baichuan
15820
- * push (`ReolinkSimpleEvent.type === 'doorbell'`). There is no
15821
- * release/duration — it's a pulse.
15822
- */
15823
- onPressed: {
15824
- data: DoorbellPressEventSchema,
15825
- fromState: {
15826
- field: "lastPressedAt",
15827
- on: "advance"
15828
- }
15829
- } },
15830
- status: {
15831
- schema: DoorbellStatusSchema,
15832
- kind: "push"
15833
- },
15834
- /**
15835
- * Runtime-state slice — last press timestamp + lifetime press count.
15836
- * Mirrored by the kernel and readable via
15837
- * `device.state.doorbell.value`. UIs can show "last ring 5m ago"
15838
- * without subscribing.
15839
- */
15840
- runtimeState: DoorbellStatusSchema,
15841
- /**
15842
- * Runtime-state durability: **restored** — a monotonic accumulator: the slice IS the record. `lastPressedAt` is content here, not a clock, so it is deliberately NOT volatile.
15843
- *
15844
- * See `RuntimeStateDurability`. Enforced by
15845
- * `scripts/check-runtime-state-durability.ts`.
15846
- */
15847
- durability: "restored"
15848
- };
15849
- var ExtensionSlotIdSchema = _enum(["doorbell-source", "linked-devices"]);
15850
- DeviceType.Camera, DeviceType.Camera;
15756
+ var ExtensionSlotIdSchema = _enum(["linked-devices"]);
15757
+ DeviceType.Camera;
15851
15758
  /** A slot's editable value, discriminated on `slot`. */
15852
- var ExtensionSlotValueSchema = discriminatedUnion("slot", [DoorbellSourceSlotValueSchema.extend({ slot: literal("doorbell-source") }), LinkedDevicesSlotValueSchema.extend({ slot: literal("linked-devices") })]);
15759
+ var ExtensionSlotValueSchema = discriminatedUnion("slot", [LinkedDevicesSlotValueSchema.extend({ slot: literal("linked-devices") })]);
15853
15760
  DeviceType.Camera;
15854
15761
  var ExtensionSourceAvailabilitySchema = discriminatedUnion("state", [object({ state: literal("ok") }), object({
15855
15762
  state: literal("unreachable"),
@@ -15886,10 +15793,11 @@ var ExtensionSlotSourceSchema = object({
15886
15793
  });
15887
15794
  /**
15888
15795
  * A DIFFERENT authority that gates whether the slot's sources do anything —
15889
- * reported read-only, named, never written through this contract (D62). The
15890
- * virtual doorbell's sources ring only while the wrapper is bound to the
15891
- * camera, and that binding belongs to `deviceManager.setWrapperActive`.
15892
- * `unknown` means the gate could not be read; it is not "inactive" (D315).
15796
+ * reported read-only, named, never written through this contract (D62) — e.g.
15797
+ * a slot whose sources act only while a wrapper is bound to the host, a
15798
+ * binding that belongs to `deviceManager.setWrapperActive`. No slot reports
15799
+ * one today (`linked-devices` answers `null`). `unknown` means the gate could
15800
+ * not be read; it is not "inactive" (D315).
15893
15801
  */
15894
15802
  var ExtensionSlotActivationSchema = object({
15895
15803
  state: _enum([
@@ -15905,7 +15813,7 @@ var ExtensionSlotRowSchema = discriminatedUnion("state", [object({
15905
15813
  /** `<source>:<slotId>` — the routing key for `listCandidates` / `setSlot`. */
15906
15814
  slotRef: string(),
15907
15815
  slot: ExtensionSlotIdSchema,
15908
- /** Names the store written (D62), e.g. `virtual-doorbell:doorbellSources`. */
15816
+ /** Names the store written (D62), e.g. `device-manager:_linkedDeviceIds`. */
15909
15817
  authority: string(),
15910
15818
  activation: ExtensionSlotActivationSchema.nullable(),
15911
15819
  value: ExtensionSlotValueSchema,
@@ -21027,12 +20935,26 @@ var CameraSensorRefSchema = object({
21027
20935
  function cameraSensorRefKey(ref) {
21028
20936
  return `${ref.addonId}/${ref.stableId}`;
21029
20937
  }
21030
- /** CS-1 accepts exactly one mode; CS-2 (D673) widens it to confirm / replace. */
21031
- var CameraSensorsModeSchema = _enum(["in-addition"]);
21032
- var CameraSensorsConfigSchema = object({
21033
- mode: CameraSensorsModeSchema,
21034
- sensors: array(CameraSensorRefSchema).min(1).max(8)
21035
- }).superRefine((value, ctx) => {
20938
+ /**
20939
+ * A sensor's mode (D673). `in-addition`: its motion is the camera's motion too.
20940
+ * `replace`: its motion is the camera's, and while one is READY the camera's
20941
+ * own motion no longer counts on its own. `confirm`: while one is READY the
20942
+ * camera's own motion counts only while a confirm sensor is active — with or
20943
+ * without a replace sensor (spec C2, the controller's ruling on Q1).
20944
+ */
20945
+ var CameraSensorModeSchema = _enum([
20946
+ "in-addition",
20947
+ "confirm",
20948
+ "replace"
20949
+ ]);
20950
+ /** A stored sensor with no mode — every CS-1 row — is in addition. */
20951
+ var DEFAULT_CAMERA_SENSOR_MODE = "in-addition";
20952
+ /**
20953
+ * A camera's attached sensors. A CS-1 row carried an envelope
20954
+ * `mode: 'in-addition'`: `z.object` drops it on parse, and the PARSED value is
20955
+ * what the write stores (D672 rule 3), so it is never written again.
20956
+ */
20957
+ var CameraSensorsConfigSchema = object({ sensors: array(CameraSensorRefSchema.extend({ mode: CameraSensorModeSchema.default(DEFAULT_CAMERA_SENSOR_MODE) })).min(1).max(8) }).superRefine((value, ctx) => {
21036
20958
  const seen = /* @__PURE__ */ new Set();
21037
20959
  value.sensors.forEach((ref, index) => {
21038
20960
  const key = cameraSensorRefKey(ref);
@@ -21044,39 +20966,41 @@ var CameraSensorsConfigSchema = object({
21044
20966
  seen.add(key);
21045
20967
  });
21046
20968
  });
21047
- var RefFields = {
20969
+ /** Every attachment names its mode; an older orchestrator that does not is in addition. */
20970
+ var AttachmentFields = {
21048
20971
  addonId: string(),
21049
- stableId: string()
20972
+ stableId: string(),
20973
+ mode: CameraSensorModeSchema.default(DEFAULT_CAMERA_SENSOR_MODE)
21050
20974
  };
21051
20975
  var CameraSensorAttachmentSchema = discriminatedUnion("state", [
21052
20976
  object({
21053
- ...RefFields,
20977
+ ...AttachmentFields,
21054
20978
  state: literal("ready"),
21055
20979
  deviceId: number(),
21056
20980
  name: string(),
21057
20981
  caps: array(string()).readonly()
21058
20982
  }),
21059
20983
  object({
21060
- ...RefFields,
20984
+ ...AttachmentFields,
21061
20985
  state: literal("offline"),
21062
20986
  deviceId: number(),
21063
20987
  name: string(),
21064
20988
  reason: _enum(["offline", "disabled"])
21065
20989
  }),
21066
20990
  object({
21067
- ...RefFields,
20991
+ ...AttachmentFields,
21068
20992
  state: literal("missing"),
21069
20993
  reason: string()
21070
20994
  }),
21071
20995
  object({
21072
- ...RefFields,
20996
+ ...AttachmentFields,
21073
20997
  state: literal("unsupported"),
21074
20998
  deviceId: number(),
21075
20999
  name: string(),
21076
21000
  reason: string()
21077
21001
  }),
21078
21002
  object({
21079
- ...RefFields,
21003
+ ...AttachmentFields,
21080
21004
  state: literal("unreadable"),
21081
21005
  reason: string()
21082
21006
  })
@@ -21089,17 +21013,49 @@ var CameraSensorAttachmentSchema = discriminatedUnion("state", [
21089
21013
  * say.
21090
21014
  */
21091
21015
  var CameraSensorsNotForwardedSchema = _enum(["onboard-not-listed", "no-active-detection"]);
21016
+ /** Whether the camera's OWN motion counts on its own (D673 C2), from its READY sensors (C3). */
21017
+ var CameraOwnMotionSchema = _enum([
21018
+ "always",
21019
+ "when-confirmed",
21020
+ "never"
21021
+ ]);
21022
+ /** Confirm / Replace cannot suppress this camera's motion: its provider still emits it directly (D673 C13). */
21023
+ var CameraSensorsNotEnforcedSchema = _enum(["provider-not-split"]);
21024
+ /**
21025
+ * The camera's OWN onboard motion (D696): the raw input the bridge combines,
21026
+ * never the effective value. The camera's `motion` slice is the effective one,
21027
+ * so a view of the camera's own row reads this.
21028
+ * - `atMs`: when the bridge received the camera's last own edge.
21029
+ * - `detected`: evaluated WHEN THE STATUS IS ASKED — the last edge said `true`
21030
+ * AND it is younger than the window the bridge counts the camera's own motion
21031
+ * for (`motionCooldownMs`, floored at two sustain ticks). A camera that never
21032
+ * sends a clear (heartbeats only) therefore reads `false` once no push came
21033
+ * within the window; a status read is a snapshot, so a live view re-asks.
21034
+ * Absent = this orchestrator has not received the camera's own motion since it
21035
+ * started (unknown, never "quiet"), or an orchestrator older than D696.
21036
+ */
21037
+ var CameraRawLevelSchema = object({
21038
+ detected: boolean(),
21039
+ atMs: number()
21040
+ });
21092
21041
  var CameraSensorsStatusSchema = discriminatedUnion("state", [
21093
- object({ state: literal("not-configured") }),
21042
+ object({
21043
+ state: literal("not-configured"),
21044
+ cameraLevel: CameraRawLevelSchema.optional()
21045
+ }),
21094
21046
  object({
21095
21047
  state: literal("unreadable"),
21096
- reason: string()
21048
+ reason: string(),
21049
+ cameraLevel: CameraRawLevelSchema.optional()
21097
21050
  }),
21098
21051
  object({
21099
21052
  state: literal("configured"),
21100
- mode: CameraSensorsModeSchema,
21053
+ cameraLevel: CameraRawLevelSchema.optional(),
21101
21054
  sensors: array(CameraSensorAttachmentSchema).readonly(),
21102
- notForwarded: CameraSensorsNotForwardedSchema.optional()
21055
+ /** Absent = an orchestrator older than CS-2: it does not say (D315). */
21056
+ cameraMotion: CameraOwnMotionSchema.optional(),
21057
+ notForwarded: CameraSensorsNotForwardedSchema.optional(),
21058
+ notEnforced: CameraSensorsNotEnforcedSchema.optional()
21103
21059
  })
21104
21060
  ]);
21105
21061
  Object.freeze({
@@ -24330,8 +24286,10 @@ var RunnerCameraConfigSchema = object({
24330
24286
  * - `analyzer`: ML/frame-diff motion detection (motion-wasm or other
24331
24287
  * analyzer providers) running on decoded frames in this runner.
24332
24288
  * - `onboard`: camera-native motion pushes (Reolink Baichuan, ONVIF
24333
- * analytics). The provider emits ProviderMotion
24334
- * events; the orchestrator forwards to `reportMotion`.
24289
+ * analytics). The provider emits its raw push as `ProviderMotion`
24290
+ * (D673); the orchestrator's camera-sensors bridge re-emits the camera's
24291
+ * effective motion as `MotionOnMotionChanged`, which is what reaches
24292
+ * `reportMotion`.
24335
24293
  */
24336
24294
  motionSources: MotionSourcesSchema.default(["analyzer"]),
24337
24295
  /**
@@ -24508,7 +24466,15 @@ var RunnerLocalLoadSchema = object({
24508
24466
  hasGpu: boolean(),
24509
24467
  inferenceBackend: string().optional(),
24510
24468
  cpuCores: number().optional()
24511
- })
24469
+ }),
24470
+ /**
24471
+ * Who writes a camera's `motion` runtime slice (D696). `'orchestrator'`: this
24472
+ * runner never writes it. ABSENT = a runner older than D696, which still
24473
+ * writes the slice from its phase machine; the orchestrator does not write
24474
+ * while any runner node is absent-or-unanswered, so one slice never has two
24475
+ * writers.
24476
+ */
24477
+ motionSliceWriter: literal("orchestrator").optional()
24512
24478
  });
24513
24479
  /**
24514
24480
  * Aggregate runtime metrics for the runner's whole local pool. Mirrors the
@@ -30542,6 +30508,70 @@ onStatusChanged: { data: object({
30542
30508
  * whether persisting is worth a SQLite commit. */
30543
30509
  volatileStateFields: ["lastChangedAt"]
30544
30510
  };
30511
+ var DoorbellStatusSchema = object({
30512
+ /** Ms epoch of the last press. null = never observed since this provider started. */
30513
+ lastPressedAt: number().nullable(),
30514
+ /** Counter since provider start. Resets on reboot. Useful for metrics/debug. */
30515
+ pressCountSinceStart: number()
30516
+ });
30517
+ var DoorbellPressEventSchema = object({
30518
+ deviceId: number(),
30519
+ timestamp: number()
30520
+ });
30521
+ /**
30522
+ * Doorbell button cap. Two kinds of provider serve it, and to every consumer
30523
+ * they are the same cap:
30524
+ *
30525
+ * - **Native** providers, registered per device by a driver addon through
30526
+ * `ctx.registerNativeCap` — a `DeviceType.Button` accessory with
30527
+ * `role: DeviceRole.Doorbell`, or the camera itself (Reolink registers at
30528
+ * camera level). They emit `onPressed` on every firmware ring.
30529
+ * - **A composed doorbell** (D670, D671): a camera's customization gives it
30530
+ * the cap, its `lastPressedAt` rising from the sources the operator
30531
+ * assigned in Customize → Doorbell, and the composer emits `onPressed`
30532
+ * from that field's advance (`fromState`).
30533
+ *
30534
+ * The DeviceEventPropagator re-emits `onPressed` on the camera parent.
30535
+ */
30536
+ var doorbellCapability = {
30537
+ name: "doorbell",
30538
+ scope: "device",
30539
+ deviceNative: true,
30540
+ mode: "singleton",
30541
+ deviceTypes: [DeviceType.Button, DeviceType.Camera],
30542
+ methods: {},
30543
+ events: {
30544
+ /**
30545
+ * Fires once per physical press. Reolink delivers via Baichuan
30546
+ * push (`ReolinkSimpleEvent.type === 'doorbell'`). There is no
30547
+ * release/duration — it's a pulse.
30548
+ */
30549
+ onPressed: {
30550
+ data: DoorbellPressEventSchema,
30551
+ fromState: {
30552
+ field: "lastPressedAt",
30553
+ on: "advance"
30554
+ }
30555
+ } },
30556
+ status: {
30557
+ schema: DoorbellStatusSchema,
30558
+ kind: "push"
30559
+ },
30560
+ /**
30561
+ * Runtime-state slice — last press timestamp + lifetime press count.
30562
+ * Mirrored by the kernel and readable via
30563
+ * `device.state.doorbell.value`. UIs can show "last ring 5m ago"
30564
+ * without subscribing.
30565
+ */
30566
+ runtimeState: DoorbellStatusSchema,
30567
+ /**
30568
+ * Runtime-state durability: **restored** — a monotonic accumulator: the slice IS the record. `lastPressedAt` is content here, not a clock, so it is deliberately NOT volatile.
30569
+ *
30570
+ * See `RuntimeStateDurability`. Enforced by
30571
+ * `scripts/check-runtime-state-durability.ts`.
30572
+ */
30573
+ durability: "restored"
30574
+ };
30545
30575
  /**
30546
30576
  * Enum-state sensor — a string value picked from a finite option set.
30547
30577
  * Drives HA `sensor` entries with `state_class: enum` (HVAC action
@@ -32681,39 +32711,14 @@ authKey: string().optional() }), object({
32681
32711
  /** Human-readable error when `ok: false`. */
32682
32712
  error: string().optional()
32683
32713
  }), { kind: "mutation" });
32684
- /**
32685
- * Hardware / firmware motion sensor cap — binary detected state plus
32686
- * a timestamp of the last observation. Distinct from
32687
- * `motion-detection.cap.ts` which owns the LOCAL ML motion pipeline;
32688
- * `motion` is the lightweight readout from on-camera motion (Reolink
32689
- * `GetMdState`, Baichuan push `type: motion`, ONVIF analytics).
32690
- *
32691
- * Native-motion providers also fan out to `detection.camera-native`
32692
- * with `source: 'onboard'` so cross-cutting system services
32693
- * (alert-center, advanced-notifier) can subscribe once and receive
32694
- * motion from every camera.
32695
- */
32696
- /**
32697
- * How long after a camera's last rising edge `pipeline-analytics` closes the
32698
- * motion EPISODE row it kept open for it (D475) — "il delay della cap", in
32699
- * the operator's words. One authority for the whole system: every provider
32700
- * that seeds `autoClearAfterMs` on a `Camera` device writes this SAME
32701
- * constant while `detected: true` (never its own number — Hikvision used to
32702
- * seed its internal 3 s inactivity timer here, which is a different clock for
32703
- * a different purpose), and `MotionEpisodeTracker` imports it directly rather
32704
- * than reading the live cap value on the hot path. A `Sensor` device (HA
32705
- * binary sensor, Homematic) gets a genuine push both ways and has no episode
32706
- * to close on a timer, so it writes `null`, never this constant.
32707
- */
32708
- var MOTION_CLOSE_AFTER_MS = 15e3;
32709
32714
  var MotionStatusSchema = object({
32710
32715
  detected: boolean(),
32711
32716
  /** Ms epoch of the last detected-true observation. Null if never detected. */
32712
32717
  lastDetectedAt: number().nullable(),
32713
32718
  /**
32714
- * `MOTION_CLOSE_AFTER_MS` while `detected: true` on a `Camera` device,
32715
- * `null` while false and on every `Sensor` device (D475) — see that
32716
- * constant's doc for the one-authority rule.
32719
+ * `MOTION_CLOSE_AFTER_MS` while `detected: true` on a `Camera` device (the
32720
+ * orchestrator writes it, D696), `null` while false and on every `Sensor`
32721
+ * device (D475) — see that constant's doc for the one-authority rule.
32717
32722
  *
32718
32723
  * ## Reading this field still arms nothing
32719
32724
  *
@@ -32731,34 +32736,31 @@ var MotionStatusSchema = object({
32731
32736
  * `addon-export-alexa/src/motion-clear-hold.ts` and
32732
32737
  * `addon-export-hap`'s `RESET_DEBOUNCE_MS` both do.
32733
32738
  *
32734
- * ## Who writes it
32735
- *
32736
- * - **Cameras** — the runner's phase machine, `active → watching` on
32737
- * `cooldown_expired`, which then writes this slice with
32738
- * `detected: false` (`handlePhaseChanged` in
32739
- * `pipeline-runner/index.ts`). It produces the FALLING edge, which
32740
- * matters most for the sources that only ever push a rising one:
32741
- * Reolink emits `MotionOnMotionChanged { detected: true }` and never
32742
- * a false.
32743
- * - **Sensors** (Home Assistant binary sensors, Homematic) — the
32744
- * provider pushes the false itself, from the upstream system's own
32745
- * state change. No phase machine is involved.
32739
+ * ## Who writes it (D696)
32746
32740
  *
32747
- * ### The phase machine is CANONICAL, not sole — and that is a defect
32741
+ * - **Cameras** — the orchestrator, and nothing else. It writes the camera's
32742
+ * EFFECTIVE motion (`addon-pipeline-orchestrator`
32743
+ * `camera-sensors/motion-slice.ts`), alongside the effective
32744
+ * `MotionOnMotionChanged` it emits or receives: the camera-sensors bridge
32745
+ * for a split camera, an unsplit emitter's direct event, the analyzer and
32746
+ * device activity, as the camera's `motionSources` counts them. A source
32747
+ * that never sends a clear falls one window after its last `true`.
32748
+ * `lastDetectedAt` moves only on an effective rise. No camera provider
32749
+ * writes this slice (not even a boot seed), and neither does the runner's
32750
+ * phase machine: its phase is "a session is attached" for every on-motion
32751
+ * session, not motion, and it now has its own `DetectionPhaseTransition`.
32752
+ * A provider's `isDetected` answers from the hub's slice.
32753
+ * - **Sensors** (Home Assistant binary sensors, Homematic, Matter, Alexa
32754
+ * imports) — the provider pushes both edges itself, from the upstream
32755
+ * system's own state change. That is the sensor's own fact.
32748
32756
  *
32749
- * An earlier revision of this docblock (mine, 2026-09-12) claimed the
32750
- * phase machine is the sole writer for a camera. It is not.
32751
- * `hikvision-camera.ts:3464` and `amcrest-camera.ts:445` both call
32752
- * `setCapSlice(motionCapability, …)` on their own rising edge, and
32753
- * Hikvision's comment says why: it read THIS docblock, agreed the
32754
- * runner is canonical, and wrote anyway to avoid per-tick churn. So
32755
- * two authorities can disagree about one slice, which this repo
32756
- * forbids, and the doc said otherwise — which is worse than saying
32757
- * nothing, because it reads as verification.
32757
+ * `scripts/check-onboard-motion-emitters.ts` refuses any other writer of a
32758
+ * `motion` slice; each sensor writer is a named exemption.
32758
32759
  *
32759
- * This predates D475 and is not fixed there: the fix touches every
32760
- * camera provider. Recorded in D475's Consequences. Do not restore the
32761
- * "sole writer" wording without also removing the other writers.
32760
+ * This replaces the D475 §4 rule ("the phase machine is the sole writer").
32761
+ * That rule was never true: Hikvision and Amcrest wrote the slice raw beside
32762
+ * it, every provider seeded it at boot, and every session left it
32763
+ * `detected: true` after its detach.
32762
32764
  */
32763
32765
  autoClearAfterMs: number().nullable()
32764
32766
  });
@@ -32830,11 +32832,12 @@ onMotionChanged: { data: MotionOnMotionChangedDataSchema } },
32830
32832
  */
32831
32833
  runtimeState: MotionStatusSchema,
32832
32834
  /**
32833
- * Runtime-state durability: **session** — every writer of this slice
32835
+ * Runtime-state durability: **session** — the writer of this slice
32834
32836
  * writes only on an EDGE, so a restored `detected: true` would stay
32835
32837
  * frozen until the next one instead of being corrected. The next edge
32836
- * re-publishes the real state. (On who the writers are, and why there
32837
- * is more than one, see `autoClearAfterMs` above.)
32838
+ * re-publishes the real state, and the orchestrator re-publishes every
32839
+ * camera when it starts writing (D696; on who writes it, see
32840
+ * `autoClearAfterMs` above).
32838
32841
  *
32839
32842
  * See `RuntimeStateDurability`. Enforced by
32840
32843
  * `scripts/check-runtime-state-durability.ts`.
@@ -35375,8 +35378,7 @@ var ptzAutotrackCapability = {
35375
35378
  deviceNative: true,
35376
35379
  mode: "singleton",
35377
35380
  /**
35378
- * Two kinds of provider behind one name, the same shape `snapshot` and
35379
- * `doorbell` use:
35381
+ * Two kinds of provider behind one name, the same shape `snapshot` uses:
35380
35382
  *
35381
35383
  * - **Native**: the camera's own firmware autotrack, registered per device by
35382
35384
  * the driver when the probe says it exists (Reolink: yes; Hikvision:
@@ -35384,7 +35386,7 @@ var ptzAutotrackCapability = {
35384
35386
  * - **Wrapper**: the emulated implementation (`@camstack/system`'s `autotrack` builtin),
35385
35387
  * which follows a subject with `ptz.move` pulses driven by the detection
35386
35388
  * pipeline. `defaultActive: false` — the operator binds it per camera in
35387
- * the bindings UI, exactly as `virtual-doorbell` is bound.
35389
+ * the bindings UI.
35388
35390
  *
35389
35391
  * The binding chooses WHICH implementation answers; `setEnabled` stays the
35390
35392
  * one switch for the function either way. A camera never has both driving its
@@ -52852,6 +52854,25 @@ TimelapseRuleInputSchema.extend({
52852
52854
  createdAt: number(),
52853
52855
  updatedAt: number()
52854
52856
  });
52857
+ async function readHubMotionDetected(deviceState, deviceId) {
52858
+ let slice;
52859
+ try {
52860
+ slice = await deviceState.getCapSlice.query({
52861
+ deviceId,
52862
+ capName: "motion"
52863
+ });
52864
+ } catch (err) {
52865
+ const reason = err instanceof Error ? err.message : String(err);
52866
+ throw new Error(`motion state of device ${deviceId} is unreadable: ${reason}`, { cause: err });
52867
+ }
52868
+ const detected = slice?.["detected"];
52869
+ if (typeof detected !== "boolean") throw new Error(`motion state of device ${deviceId} is not published yet (unknown)`);
52870
+ return detected;
52871
+ }
52872
+ MotionOnMotionChangedDataSchema.omit({ triggeredBy: true });
52873
+ function providerMotionEvent(source, data) {
52874
+ return createEvent(EventCategory.ProviderMotion, source, data);
52875
+ }
52855
52876
  object({
52856
52877
  /**
52857
52878
  * Fraction of the box's own size added on EACH side before cutting.
@@ -55221,17 +55242,14 @@ var AmcrestCamera = class AmcrestCamera extends BaseDevice {
55221
55242
  }
55222
55243
  /** Register the native `motion` cap. Its mere presence (a `kind:'native'`
55223
55244
  * `motion` binding) is what the orchestrator reads to default a
55224
- * freshly-adopted camera to `motionSources:['onboard']`. */
55245
+ * freshly-adopted camera to `motionSources:['onboard']`. `isDetected`
55246
+ * answers from the HUB's slice; an unreadable hub, or a slice nobody has
55247
+ * published yet, fails the call — never `false` for unknown (D49, D393). */
55225
55248
  registerMotionCap() {
55226
55249
  this.ctx.registerNativeCap(motionCapability, { isDetected: async ({ deviceId }) => {
55227
55250
  if (deviceId !== this.id) throw new Error(`AmcrestCamera: motion deviceId mismatch, expected ${this.id}, got ${deviceId}`);
55228
- return this.getCapSlice(motionCapability)?.detected ?? false;
55251
+ return readHubMotionDetected(this.ctx.api.deviceState, this.id);
55229
55252
  } });
55230
- this.setCapSlice(motionCapability, {
55231
- detected: false,
55232
- lastDetectedAt: null,
55233
- autoClearAfterMs: null
55234
- });
55235
55253
  this.ctx.logger.info("amcrest: motion cap registered", { tags: { deviceId: this.id } });
55236
55254
  }
55237
55255
  /** Reusable event-source identity for every emit on this device. */
@@ -55243,10 +55261,12 @@ var AmcrestCamera = class AmcrestCamera extends BaseDevice {
55243
55261
  deviceId: this.id
55244
55262
  };
55245
55263
  }
55246
- /** Emit an onboard motion transition on the bus. The runner subscribes
55247
- * and drives its phase machine via `reportMotion`. */
55264
+ /** Emit the camera's RAW onboard motion transition (`ProviderMotion`,
55265
+ * D673). The orchestrator's camera-sensors bridge re-emits it as
55266
+ * `MotionOnMotionChanged`; the runner subscribes to that and drives its
55267
+ * phase machine via `reportMotion`. */
55248
55268
  emitMotion(detected, timestamp) {
55249
- this.ctx.eventBus.emit(createEvent(EventCategory.MotionOnMotionChanged, this.eventSource(), {
55269
+ this.ctx.eventBus.emit(providerMotionEvent(this.eventSource(), {
55250
55270
  deviceId: this.id,
55251
55271
  detected,
55252
55272
  timestamp,
@@ -55341,14 +55361,7 @@ var AmcrestCamera = class AmcrestCamera extends BaseDevice {
55341
55361
  const wasActive = this.motionActive;
55342
55362
  this.motionActive = true;
55343
55363
  this.emitMotion(true, now);
55344
- if (!wasActive) {
55345
- this.setCapSlice(motionCapability, {
55346
- detected: true,
55347
- lastDetectedAt: now,
55348
- autoClearAfterMs: MOTION_CLOSE_AFTER_MS
55349
- });
55350
- this.ctx.logger.info("amcrest: onboard motion started", { tags: { deviceId: this.id } });
55351
- }
55364
+ if (!wasActive) this.ctx.logger.info("amcrest: onboard motion started", { tags: { deviceId: this.id } });
55352
55365
  if (this.motionKeepaliveTimer === null) this.motionKeepaliveTimer = setInterval(() => {
55353
55366
  this.emitMotion(true, Date.now());
55354
55367
  }, AmcrestCamera.MOTION_KEEPALIVE_MS);
@@ -55358,12 +55371,6 @@ var AmcrestCamera = class AmcrestCamera extends BaseDevice {
55358
55371
  if (!this.motionActive) return;
55359
55372
  this.motionActive = false;
55360
55373
  this.emitMotion(false, now);
55361
- const lastDetectedAt = this.getCapSlice(motionCapability)?.lastDetectedAt ?? now;
55362
- this.setCapSlice(motionCapability, {
55363
- detected: false,
55364
- lastDetectedAt,
55365
- autoClearAfterMs: null
55366
- });
55367
55374
  this.ctx.logger.info("amcrest: onboard motion stopped", { tags: { deviceId: this.id } });
55368
55375
  }
55369
55376
  clearMotionKeepalive() {