@camstack/addon-ai 0.4.102 → 0.4.103

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.
package/dist/addon.js CHANGED
@@ -7506,6 +7506,23 @@ method(object({ deviceId: number$1() }), array(StreamSourceEntrySchema)), method
7506
7506
  action: string().min(1),
7507
7507
  input: unknown()
7508
7508
  }), unknown(), { kind: "mutation" }), method(object({ deviceId: number$1() }), _void(), { kind: "mutation" }), method(object({ deviceId: number$1() }), unknown().nullable()), method(object({ deviceId: number$1() }), RawStateResultSchema.nullable(), { auth: "protected" });
7509
+ new Set([
7510
+ "track",
7511
+ "summary",
7512
+ "face",
7513
+ "identity",
7514
+ "plate",
7515
+ "vehicle",
7516
+ "scene",
7517
+ "motion",
7518
+ "object",
7519
+ "audio"
7520
+ ]);
7521
+ new Set([
7522
+ "motion",
7523
+ "object",
7524
+ "audio"
7525
+ ]);
7509
7526
  var EncodeProfileSchema = object({
7510
7527
  video: object({
7511
7528
  codec: _enum([
@@ -12604,8 +12621,17 @@ method(object({
12604
12621
  }), array(SettingsRecordSchema).readonly()), method(object({
12605
12622
  namespace: string().optional(),
12606
12623
  collection: string(),
12607
- record: SettingsRecordSchema
12608
- }), _void(), { kind: "mutation" }), method(object({
12624
+ record: object({
12625
+ id: string().optional(),
12626
+ data: record(string(), unknown())
12627
+ })
12628
+ }), object({
12629
+ /**
12630
+ * The id the row ACTUALLY got (D473): the one supplied, the UUID minted
12631
+ * for an absent one, or the ROWID SQLite assigned on an `INTEGER`
12632
+ * primary key — which is the only place an auto key is knowable.
12633
+ */
12634
+ id: union([string(), number$1()]) }), { kind: "mutation" }), method(object({
12609
12635
  namespace: string().optional(),
12610
12636
  collection: string(),
12611
12637
  records: array(BulkRecordSchema).readonly()
@@ -12714,8 +12740,17 @@ method(_void(), EngineInfoSchema, { auth: "admin" }), method(object({
12714
12740
  }), array(SettingsRecordSchema).readonly(), { auth: "admin" }), method(object({
12715
12741
  namespace: string().optional(),
12716
12742
  collection: string(),
12717
- record: SettingsRecordSchema
12718
- }), _void(), {
12743
+ record: object({
12744
+ id: string().optional(),
12745
+ data: record(string(), unknown())
12746
+ })
12747
+ }), object({
12748
+ /**
12749
+ * The id the row ACTUALLY got (D473): the one supplied, the UUID minted
12750
+ * for an absent one, or the ROWID SQLite assigned on an `INTEGER`
12751
+ * primary key — which is the only place an auto key is knowable.
12752
+ */
12753
+ id: union([string(), number$1()]) }), {
12719
12754
  kind: "mutation",
12720
12755
  auth: "admin"
12721
12756
  }), method(object({
@@ -19451,7 +19486,20 @@ var TrackSchema = object({
19451
19486
  ...TrackRetrainFields
19452
19487
  });
19453
19488
  var BaseEventFields = {
19454
- id: string(),
19489
+ /**
19490
+ * A SQLite ROWID, assigned by the database (D474).
19491
+ *
19492
+ * Was a 36-character UUID and cost 263 MB of a 1 117 MB database — paid
19493
+ * TWICE per row, in the row and in the primary-key index, across 2.1 million
19494
+ * motion, audio and object events. An `INTEGER PRIMARY KEY` in SQLite **is**
19495
+ * the rowid: the table itself is that B-tree, so the index stops existing
19496
+ * rather than getting smaller. No shorter string does that.
19497
+ *
19498
+ * Defined once here for all three event kinds, which is why they move
19499
+ * together: a per-table migration would have forked this and
19500
+ * `COMMON_BASE_COLUMNS` and reunited them two stages later.
19501
+ */
19502
+ id: number$1().int(),
19455
19503
  deviceId: number$1(),
19456
19504
  timestamp: number$1()
19457
19505
  };
@@ -19470,7 +19518,34 @@ var MotionEventSchema = object({
19470
19518
  /** Omitted in slim projection. */
19471
19519
  frameHeight: number$1().optional(),
19472
19520
  /** Populated by B5 (recording playback URL for this event). */
19473
- mediaUrl: string().optional()
19521
+ mediaUrl: string().optional(),
19522
+ /**
19523
+ * One row per motion EPISODE, not one per push (D475). `null` while the
19524
+ * episode is still open — a further rising edge extends it in place rather
19525
+ * than inserting a new row. Set once, at close, to `lastOnAt - startedAt`
19526
+ * (the span from the first rising edge to the LAST one, deliberately NOT
19527
+ * `closedAt - startedAt` — the close delay is a quiet CONFIRMATION, not
19528
+ * movement, and folding it in would report `MOTION_CLOSE_AFTER_MS` of
19529
+ * motion for an instantaneous trigger).
19530
+ *
19531
+ * **Absent** (not merely `null`) on a row written before D475 — that means
19532
+ * "closed the old way, before this column existed", never "still open".
19533
+ * Nothing in this codebase may read an absent `durationMs` as an open
19534
+ * episode; only `null` means open.
19535
+ */
19536
+ durationMs: number$1().nullable().optional(),
19537
+ /**
19538
+ * Ms offsets from `timestamp` (the episode's own first rising edge, so the
19539
+ * first entry is always `0`) of every genuine off→on transition the
19540
+ * episode saw — "ogni evento on si deve salvare" (D475). NOT one entry per
19541
+ * push: a firmware source that keepalives at ~1 Hz for the whole burst
19542
+ * (Reolink, Hikvision) produces exactly one edge; a source that reports an
19543
+ * explicit `false` mid-episode and then resumes before the quiet window
19544
+ * elapses produces another. Stored compactly — see `motion-edge-codec.ts`
19545
+ * — and decoded back to this shape on read. Absent/empty on a legacy row,
19546
+ * which must never be read as "no episode happened here".
19547
+ */
19548
+ edges: array(number$1()).readonly().optional()
19474
19549
  });
19475
19550
  /**
19476
19551
  * Which detection SOURCE produced an object event. `pipeline` = the ML
@@ -19525,6 +19600,23 @@ var ObjectEventSchema = object({
19525
19600
  * includes it (it is light). Absent on rows written before this field.
19526
19601
  */
19527
19602
  frameId: string().optional(),
19603
+ /**
19604
+ * A PRODUCER-chosen key that makes a synthetic event's emission idempotent
19605
+ * (D474).
19606
+ *
19607
+ * Only the package detector writes it, and it exists because the event id
19608
+ * stopped being choosable: the delivery and pick-up rows used to BE their
19609
+ * dedupe key (`pa-pkg-<entryId>-delivered`), which is how "never emit a
19610
+ * second delivery for this entry" survived a restart. An `INTEGER` rowid is
19611
+ * assigned by SQLite, so that key had to move off the primary key rather
19612
+ * than be dropped — a detector that cannot recognise its own row re-delivers
19613
+ * every parcel on every boot.
19614
+ *
19615
+ * Absent on every other object event, and on every row written before this
19616
+ * field. Never a substitute for `id`: it is unique per (producer, occasion),
19617
+ * not per row, and nothing addresses a row by it.
19618
+ */
19619
+ idempotencyKey: string().optional(),
19528
19620
  /** Omitted in slim projection. */
19529
19621
  trackId: string().optional(),
19530
19622
  className: string(),
@@ -26591,9 +26683,54 @@ object({
26591
26683
  /** Ms epoch of the last detected-true observation. Null if never detected. */
26592
26684
  lastDetectedAt: number$1().nullable(),
26593
26685
  /**
26594
- * Ms after which `detected` auto-reverts to false if no fresh push
26595
- * arrives. Null means the provider leaves detected state until a
26596
- * native "clear" event.
26686
+ * `MOTION_CLOSE_AFTER_MS` while `detected: true` on a `Camera` device,
26687
+ * `null` while false and on every `Sensor` device (D475) — see that
26688
+ * constant's doc for the one-authority rule.
26689
+ *
26690
+ * ## Reading this field still arms nothing
26691
+ *
26692
+ * It reads like an instruction to the consumer ("revert after N ms if
26693
+ * no fresh push arrives") and it is not one: nothing in this repo reads
26694
+ * the LIVE cap value to drive a timer. `pipeline-analytics`'s motion-episode
26695
+ * close DOES now use the same number — `MOTION_CLOSE_AFTER_MS` — but as an
26696
+ * imported constant, not as a read of `device.state.motion.value`, so this
26697
+ * field stays what it always was: DESCRIPTIVE output, mirroring an answer
26698
+ * computed elsewhere. Building a self-clear timer out of a READ of this
26699
+ * field would add a second falling-edge authority beside whichever one
26700
+ * already owns the device, and two that can disagree are worse than one.
26701
+ * Consumers that need a falling edge SHAPED differently — held open across
26702
+ * a flapping source — debounce on their own side and say so, as
26703
+ * `addon-export-alexa/src/motion-clear-hold.ts` and
26704
+ * `addon-export-hap`'s `RESET_DEBOUNCE_MS` both do.
26705
+ *
26706
+ * ## Who writes it
26707
+ *
26708
+ * - **Cameras** — the runner's phase machine, `active → watching` on
26709
+ * `cooldown_expired`, which then writes this slice with
26710
+ * `detected: false` (`handlePhaseChanged` in
26711
+ * `pipeline-runner/index.ts`). It produces the FALLING edge, which
26712
+ * matters most for the sources that only ever push a rising one:
26713
+ * Reolink emits `MotionOnMotionChanged { detected: true }` and never
26714
+ * a false.
26715
+ * - **Sensors** (Home Assistant binary sensors, Homematic) — the
26716
+ * provider pushes the false itself, from the upstream system's own
26717
+ * state change. No phase machine is involved.
26718
+ *
26719
+ * ### The phase machine is CANONICAL, not sole — and that is a defect
26720
+ *
26721
+ * An earlier revision of this docblock (mine, 2026-09-12) claimed the
26722
+ * phase machine is the sole writer for a camera. It is not.
26723
+ * `hikvision-camera.ts:3464` and `amcrest-camera.ts:445` both call
26724
+ * `setCapSlice(motionCapability, …)` on their own rising edge, and
26725
+ * Hikvision's comment says why: it read THIS docblock, agreed the
26726
+ * runner is canonical, and wrote anyway to avoid per-tick churn. So
26727
+ * two authorities can disagree about one slice, which this repo
26728
+ * forbids, and the doc said otherwise — which is worse than saying
26729
+ * nothing, because it reads as verification.
26730
+ *
26731
+ * This predates D475 and is not fixed there: the fix touches every
26732
+ * camera provider. Recorded in D475's Consequences. Do not restore the
26733
+ * "sole writer" wording without also removing the other writers.
26597
26734
  */
26598
26735
  autoClearAfterMs: number$1().nullable()
26599
26736
  });
package/dist/addon.mjs CHANGED
@@ -7533,6 +7533,23 @@ method(object({ deviceId: number$1() }), array(StreamSourceEntrySchema)), method
7533
7533
  action: string().min(1),
7534
7534
  input: unknown()
7535
7535
  }), unknown(), { kind: "mutation" }), method(object({ deviceId: number$1() }), _void(), { kind: "mutation" }), method(object({ deviceId: number$1() }), unknown().nullable()), method(object({ deviceId: number$1() }), RawStateResultSchema.nullable(), { auth: "protected" });
7536
+ new Set([
7537
+ "track",
7538
+ "summary",
7539
+ "face",
7540
+ "identity",
7541
+ "plate",
7542
+ "vehicle",
7543
+ "scene",
7544
+ "motion",
7545
+ "object",
7546
+ "audio"
7547
+ ]);
7548
+ new Set([
7549
+ "motion",
7550
+ "object",
7551
+ "audio"
7552
+ ]);
7536
7553
  var EncodeProfileSchema = object({
7537
7554
  video: object({
7538
7555
  codec: _enum([
@@ -12631,8 +12648,17 @@ method(object({
12631
12648
  }), array(SettingsRecordSchema).readonly()), method(object({
12632
12649
  namespace: string().optional(),
12633
12650
  collection: string(),
12634
- record: SettingsRecordSchema
12635
- }), _void(), { kind: "mutation" }), method(object({
12651
+ record: object({
12652
+ id: string().optional(),
12653
+ data: record(string(), unknown())
12654
+ })
12655
+ }), object({
12656
+ /**
12657
+ * The id the row ACTUALLY got (D473): the one supplied, the UUID minted
12658
+ * for an absent one, or the ROWID SQLite assigned on an `INTEGER`
12659
+ * primary key — which is the only place an auto key is knowable.
12660
+ */
12661
+ id: union([string(), number$1()]) }), { kind: "mutation" }), method(object({
12636
12662
  namespace: string().optional(),
12637
12663
  collection: string(),
12638
12664
  records: array(BulkRecordSchema).readonly()
@@ -12741,8 +12767,17 @@ method(_void(), EngineInfoSchema, { auth: "admin" }), method(object({
12741
12767
  }), array(SettingsRecordSchema).readonly(), { auth: "admin" }), method(object({
12742
12768
  namespace: string().optional(),
12743
12769
  collection: string(),
12744
- record: SettingsRecordSchema
12745
- }), _void(), {
12770
+ record: object({
12771
+ id: string().optional(),
12772
+ data: record(string(), unknown())
12773
+ })
12774
+ }), object({
12775
+ /**
12776
+ * The id the row ACTUALLY got (D473): the one supplied, the UUID minted
12777
+ * for an absent one, or the ROWID SQLite assigned on an `INTEGER`
12778
+ * primary key — which is the only place an auto key is knowable.
12779
+ */
12780
+ id: union([string(), number$1()]) }), {
12746
12781
  kind: "mutation",
12747
12782
  auth: "admin"
12748
12783
  }), method(object({
@@ -19478,7 +19513,20 @@ var TrackSchema = object({
19478
19513
  ...TrackRetrainFields
19479
19514
  });
19480
19515
  var BaseEventFields = {
19481
- id: string(),
19516
+ /**
19517
+ * A SQLite ROWID, assigned by the database (D474).
19518
+ *
19519
+ * Was a 36-character UUID and cost 263 MB of a 1 117 MB database — paid
19520
+ * TWICE per row, in the row and in the primary-key index, across 2.1 million
19521
+ * motion, audio and object events. An `INTEGER PRIMARY KEY` in SQLite **is**
19522
+ * the rowid: the table itself is that B-tree, so the index stops existing
19523
+ * rather than getting smaller. No shorter string does that.
19524
+ *
19525
+ * Defined once here for all three event kinds, which is why they move
19526
+ * together: a per-table migration would have forked this and
19527
+ * `COMMON_BASE_COLUMNS` and reunited them two stages later.
19528
+ */
19529
+ id: number$1().int(),
19482
19530
  deviceId: number$1(),
19483
19531
  timestamp: number$1()
19484
19532
  };
@@ -19497,7 +19545,34 @@ var MotionEventSchema = object({
19497
19545
  /** Omitted in slim projection. */
19498
19546
  frameHeight: number$1().optional(),
19499
19547
  /** Populated by B5 (recording playback URL for this event). */
19500
- mediaUrl: string().optional()
19548
+ mediaUrl: string().optional(),
19549
+ /**
19550
+ * One row per motion EPISODE, not one per push (D475). `null` while the
19551
+ * episode is still open — a further rising edge extends it in place rather
19552
+ * than inserting a new row. Set once, at close, to `lastOnAt - startedAt`
19553
+ * (the span from the first rising edge to the LAST one, deliberately NOT
19554
+ * `closedAt - startedAt` — the close delay is a quiet CONFIRMATION, not
19555
+ * movement, and folding it in would report `MOTION_CLOSE_AFTER_MS` of
19556
+ * motion for an instantaneous trigger).
19557
+ *
19558
+ * **Absent** (not merely `null`) on a row written before D475 — that means
19559
+ * "closed the old way, before this column existed", never "still open".
19560
+ * Nothing in this codebase may read an absent `durationMs` as an open
19561
+ * episode; only `null` means open.
19562
+ */
19563
+ durationMs: number$1().nullable().optional(),
19564
+ /**
19565
+ * Ms offsets from `timestamp` (the episode's own first rising edge, so the
19566
+ * first entry is always `0`) of every genuine off→on transition the
19567
+ * episode saw — "ogni evento on si deve salvare" (D475). NOT one entry per
19568
+ * push: a firmware source that keepalives at ~1 Hz for the whole burst
19569
+ * (Reolink, Hikvision) produces exactly one edge; a source that reports an
19570
+ * explicit `false` mid-episode and then resumes before the quiet window
19571
+ * elapses produces another. Stored compactly — see `motion-edge-codec.ts`
19572
+ * — and decoded back to this shape on read. Absent/empty on a legacy row,
19573
+ * which must never be read as "no episode happened here".
19574
+ */
19575
+ edges: array(number$1()).readonly().optional()
19501
19576
  });
19502
19577
  /**
19503
19578
  * Which detection SOURCE produced an object event. `pipeline` = the ML
@@ -19552,6 +19627,23 @@ var ObjectEventSchema = object({
19552
19627
  * includes it (it is light). Absent on rows written before this field.
19553
19628
  */
19554
19629
  frameId: string().optional(),
19630
+ /**
19631
+ * A PRODUCER-chosen key that makes a synthetic event's emission idempotent
19632
+ * (D474).
19633
+ *
19634
+ * Only the package detector writes it, and it exists because the event id
19635
+ * stopped being choosable: the delivery and pick-up rows used to BE their
19636
+ * dedupe key (`pa-pkg-<entryId>-delivered`), which is how "never emit a
19637
+ * second delivery for this entry" survived a restart. An `INTEGER` rowid is
19638
+ * assigned by SQLite, so that key had to move off the primary key rather
19639
+ * than be dropped — a detector that cannot recognise its own row re-delivers
19640
+ * every parcel on every boot.
19641
+ *
19642
+ * Absent on every other object event, and on every row written before this
19643
+ * field. Never a substitute for `id`: it is unique per (producer, occasion),
19644
+ * not per row, and nothing addresses a row by it.
19645
+ */
19646
+ idempotencyKey: string().optional(),
19555
19647
  /** Omitted in slim projection. */
19556
19648
  trackId: string().optional(),
19557
19649
  className: string(),
@@ -26618,9 +26710,54 @@ object({
26618
26710
  /** Ms epoch of the last detected-true observation. Null if never detected. */
26619
26711
  lastDetectedAt: number$1().nullable(),
26620
26712
  /**
26621
- * Ms after which `detected` auto-reverts to false if no fresh push
26622
- * arrives. Null means the provider leaves detected state until a
26623
- * native "clear" event.
26713
+ * `MOTION_CLOSE_AFTER_MS` while `detected: true` on a `Camera` device,
26714
+ * `null` while false and on every `Sensor` device (D475) — see that
26715
+ * constant's doc for the one-authority rule.
26716
+ *
26717
+ * ## Reading this field still arms nothing
26718
+ *
26719
+ * It reads like an instruction to the consumer ("revert after N ms if
26720
+ * no fresh push arrives") and it is not one: nothing in this repo reads
26721
+ * the LIVE cap value to drive a timer. `pipeline-analytics`'s motion-episode
26722
+ * close DOES now use the same number — `MOTION_CLOSE_AFTER_MS` — but as an
26723
+ * imported constant, not as a read of `device.state.motion.value`, so this
26724
+ * field stays what it always was: DESCRIPTIVE output, mirroring an answer
26725
+ * computed elsewhere. Building a self-clear timer out of a READ of this
26726
+ * field would add a second falling-edge authority beside whichever one
26727
+ * already owns the device, and two that can disagree are worse than one.
26728
+ * Consumers that need a falling edge SHAPED differently — held open across
26729
+ * a flapping source — debounce on their own side and say so, as
26730
+ * `addon-export-alexa/src/motion-clear-hold.ts` and
26731
+ * `addon-export-hap`'s `RESET_DEBOUNCE_MS` both do.
26732
+ *
26733
+ * ## Who writes it
26734
+ *
26735
+ * - **Cameras** — the runner's phase machine, `active → watching` on
26736
+ * `cooldown_expired`, which then writes this slice with
26737
+ * `detected: false` (`handlePhaseChanged` in
26738
+ * `pipeline-runner/index.ts`). It produces the FALLING edge, which
26739
+ * matters most for the sources that only ever push a rising one:
26740
+ * Reolink emits `MotionOnMotionChanged { detected: true }` and never
26741
+ * a false.
26742
+ * - **Sensors** (Home Assistant binary sensors, Homematic) — the
26743
+ * provider pushes the false itself, from the upstream system's own
26744
+ * state change. No phase machine is involved.
26745
+ *
26746
+ * ### The phase machine is CANONICAL, not sole — and that is a defect
26747
+ *
26748
+ * An earlier revision of this docblock (mine, 2026-09-12) claimed the
26749
+ * phase machine is the sole writer for a camera. It is not.
26750
+ * `hikvision-camera.ts:3464` and `amcrest-camera.ts:445` both call
26751
+ * `setCapSlice(motionCapability, …)` on their own rising edge, and
26752
+ * Hikvision's comment says why: it read THIS docblock, agreed the
26753
+ * runner is canonical, and wrote anyway to avoid per-tick churn. So
26754
+ * two authorities can disagree about one slice, which this repo
26755
+ * forbids, and the doc said otherwise — which is worse than saying
26756
+ * nothing, because it reads as verification.
26757
+ *
26758
+ * This predates D475 and is not fixed there: the fix touches every
26759
+ * camera provider. Recorded in D475's Consequences. Do not restore the
26760
+ * "sole writer" wording without also removing the other writers.
26624
26761
  */
26625
26762
  autoClearAfterMs: number$1().nullable()
26626
26763
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@camstack/addon-ai",
3
- "version": "0.4.102",
3
+ "version": "0.4.103",
4
4
  "description": "AI addon for CamStack — the `llm` collection provider (cloud, LAN, and camstack-managed local llama.cpp profiles) plus the per-node `llm-runtime` managed executor.",
5
5
  "keywords": [
6
6
  "camstack",