@camstack/types 1.2.171 → 1.2.173

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.
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Mint-on-empty, with the read-back that makes it safe.
3
+ *
4
+ * ## The shape, and why it is a trap
5
+ *
6
+ * ```ts
7
+ * let secret = await state.get()
8
+ * if (secret === '') {
9
+ * secret = randomUUID()
10
+ * await state.set(secret)
11
+ * }
12
+ * ```
13
+ *
14
+ * `state.get()` cannot distinguish "never minted" from "the store could not be
15
+ * read": `readAddonStoreWithRetry` gives up and answers `{}`, so a store that
16
+ * is merely unreachable reads as EMPTY and this mints a SECOND secret over a
17
+ * perfectly good first one. For a signing secret that invalidates every link
18
+ * already handed out. For the HomeKit bridge identity it is irreversible —
19
+ * every paired iPhone loses the bridge, and no later write of the store brings
20
+ * it back.
21
+ *
22
+ * The read-back is the only evidence available at this layer that the store is
23
+ * actually answering. `snapshot.addon.ts` (`ensureLinkSecret`) has done this
24
+ * since 2026-08-14 and was the only site that did.
25
+ *
26
+ * ## What it does NOT fix
27
+ *
28
+ * If the write genuinely lands, the read-back confirms it and the old value is
29
+ * already gone — a read-back cannot undo a write. It is a gate on USING the
30
+ * minted value, and it is load-bearing only because the settings view refuses
31
+ * to write at all when the last read of the addon store failed
32
+ * (`writeAddonStore`'s refusal). The two together are what close the window;
33
+ * the durable fix is a discriminated read result carried all the way up —
34
+ * `docs/design/plans/2026-08-27-lettura-fallita-non-diventa-un-default.md`.
35
+ */
36
+ /** Why a mint was refused. Both mean: the store is not answering. */
37
+ export type MintRefusalReason = 'read-back-empty' | 'read-back-mismatch';
38
+ export interface MintRefusalDetail {
39
+ readonly reason: MintRefusalReason;
40
+ /** True when the read-back answered the fallback — the usual store-down shape. */
41
+ readonly readBackEmpty: boolean;
42
+ }
43
+ export type MintOnceOutcome<TValue> = {
44
+ readonly kind: 'existing';
45
+ readonly value: TValue;
46
+ } | {
47
+ readonly kind: 'minted';
48
+ readonly value: TValue;
49
+ } | {
50
+ readonly kind: 'refused';
51
+ };
52
+ export interface MintOnceReadBackInput<TValue> {
53
+ /** Read the persisted value. MUST answer the fallback (not throw) when absent. */
54
+ readonly read: () => Promise<TValue>;
55
+ /** Is this the fallback — i.e. "nothing persisted, or nothing readable"? */
56
+ readonly isEmpty: (value: TValue) => boolean;
57
+ /** Produce a fresh value. Called at most once, and only when `isEmpty` holds. */
58
+ readonly mint: () => TValue;
59
+ /** Persist the freshly minted value. */
60
+ readonly write: (value: TValue) => Promise<void>;
61
+ /** Value equality for the read-back. Defaults to `Object.is`. */
62
+ readonly equals?: (a: TValue, b: TValue) => boolean;
63
+ /** Always log this: a refusal means a feature is deliberately not starting. */
64
+ readonly onRefused: (detail: MintRefusalDetail) => void;
65
+ }
66
+ /**
67
+ * Resolve a mint-once secret/identity: reuse what is stored, or mint, persist
68
+ * and READ BACK — refusing the minted value when the read-back disagrees.
69
+ *
70
+ * A `refused` outcome is never cached by this function; the caller may retry on
71
+ * the next tick, when the store may be answering again.
72
+ */
73
+ export declare function mintOnceWithReadBack<TValue>(input: MintOnceReadBackInput<TValue>): Promise<MintOnceOutcome<TValue>>;
package/dist/addon.js CHANGED
@@ -149,6 +149,8 @@ var CAP_INPUT_DEFAULTS = Object.freeze({
149
149
  "pipelineEnabled": true,
150
150
  "zones": [],
151
151
  "onboardMotionDrivesAnalyzer": true,
152
+ "preRollInferenceEnabled": true,
153
+ "preRollInferenceFrames": 12,
152
154
  "occupancyRecheckEnabled": true,
153
155
  "occupancyRecheckSec": 300,
154
156
  "occupancyRecheckFrames": 4,
package/dist/addon.mjs CHANGED
@@ -148,6 +148,8 @@ var CAP_INPUT_DEFAULTS = Object.freeze({
148
148
  "pipelineEnabled": true,
149
149
  "zones": [],
150
150
  "onboardMotionDrivesAnalyzer": true,
151
+ "preRollInferenceEnabled": true,
152
+ "preRollInferenceFrames": 12,
151
153
  "occupancyRecheckEnabled": true,
152
154
  "occupancyRecheckSec": 300,
153
155
  "occupancyRecheckFrames": 4,
@@ -256,6 +256,8 @@ declare const RunnerCameraConfigSchema: z.ZodObject<{
256
256
  color: z.ZodDefault<z.ZodString>;
257
257
  }, z.core.$strip>>>>;
258
258
  onboardMotionDrivesAnalyzer: z.ZodDefault<z.ZodBoolean>;
259
+ preRollInferenceEnabled: z.ZodDefault<z.ZodBoolean>;
260
+ preRollInferenceFrames: z.ZodDefault<z.ZodNumber>;
259
261
  occupancyRecheckEnabled: z.ZodDefault<z.ZodBoolean>;
260
262
  occupancyRecheckSec: z.ZodDefault<z.ZodNumber>;
261
263
  occupancyRecheckFrames: z.ZodDefault<z.ZodNumber>;
@@ -516,6 +518,8 @@ export declare const pipelineRunnerCapability: {
516
518
  color: z.ZodDefault<z.ZodString>;
517
519
  }, z.core.$strip>>>>;
518
520
  onboardMotionDrivesAnalyzer: z.ZodDefault<z.ZodBoolean>;
521
+ preRollInferenceEnabled: z.ZodDefault<z.ZodBoolean>;
522
+ preRollInferenceFrames: z.ZodDefault<z.ZodNumber>;
519
523
  occupancyRecheckEnabled: z.ZodDefault<z.ZodBoolean>;
520
524
  occupancyRecheckSec: z.ZodDefault<z.ZodNumber>;
521
525
  occupancyRecheckFrames: z.ZodDefault<z.ZodNumber>;
package/dist/index.js CHANGED
@@ -21324,6 +21324,22 @@ var occupancyRecheckFramesField = {
21324
21324
  step: 1
21325
21325
  };
21326
21326
  /**
21327
+ * Frames one PRE-ROLL catch-up burst may send to inference at session open.
21328
+ *
21329
+ * The default of 12 over a ~4 s retained window is one frame per ~333 ms of
21330
+ * footage, and costs ~480 ms of ONE inference permit at the 40 ms/frame this
21331
+ * fleet measures — one-shot, and only ever taken while a permit would still be
21332
+ * spare for live. `0` turns the burst off entirely (the history is still
21333
+ * decoded, because that is how the dial reaches a decodable GOP, and is then
21334
+ * discarded — the pre-D411 behaviour).
21335
+ */
21336
+ var preRollInferenceFramesField = {
21337
+ min: 0,
21338
+ max: 30,
21339
+ default: 12,
21340
+ step: 1
21341
+ };
21342
+ /**
21327
21343
  * Source enum for motion signals fed to the runner. Extensible — add
21328
21344
  * new variants here when new motion-trigger paths are wired in
21329
21345
  * (`wasm-cross-camera`, `event-bus-relay`, etc.). The runner uses
@@ -21564,6 +21580,31 @@ var RunnerCameraConfigSchema = zod.z.object({
21564
21580
  * to every occupancy rule until something moved in front of it. The churn is
21565
21581
  * now paid on the interval instead — see `occupancyRecheckSecField`.
21566
21582
  */
21583
+ /**
21584
+ * Infer the session's PRE-ROLL — the retained history the restreamer replays
21585
+ * at session open — instead of decoding it and throwing it away.
21586
+ *
21587
+ * DEFAULT `true`, and the default is the argument. This is not a new
21588
+ * capability being offered cautiously: the pre-roll is ALREADY requested,
21589
+ * already served, already decoded and already paid for on every on-motion
21590
+ * detection session that asks for history. What shipped was a last-moment
21591
+ * discard — `FrameSlot`'s throttle compares wall clocks, and ~4 s of media
21592
+ * arriving inside a few hundred ms of wall clock looks to it like one frame's
21593
+ * worth. Device 617, 2026-09-08: a re-run of the SAME model over the stored
21594
+ * recording scored the subject `vehicle 0.5669` — above the 0.50 floor —
21595
+ * 1.68 s BEFORE the live track was born, on a frame that was in the pre-roll,
21596
+ * was decoded, and was freed.
21597
+ *
21598
+ * Shipping that as opt-in would ship the bug: an operator cannot discover a
21599
+ * setting whose absence looks exactly like a camera that noticed the cyclist
21600
+ * late. What makes ON safe is not a switch but the BOUND —
21601
+ * `preRollInferenceFrames`, a wall-clock ceiling, and a lane that never takes
21602
+ * the last inference permit — so the switch exists for the camera where the
21603
+ * history is worthless (a doorbell whose subject is always already at the
21604
+ * door), not as a hedge against the feature.
21605
+ */
21606
+ preRollInferenceEnabled: zod.z.boolean().default(true),
21607
+ preRollInferenceFrames: zod.z.number().min(preRollInferenceFramesField.min).max(preRollInferenceFramesField.max).default(preRollInferenceFramesField.default),
21567
21608
  occupancyRecheckEnabled: zod.z.boolean().default(true),
21568
21609
  occupancyRecheckSec: zod.z.number().min(occupancyRecheckSecField.min).max(occupancyRecheckSecField.max).default(occupancyRecheckSecField.default),
21569
21610
  occupancyRecheckFrames: zod.z.number().min(occupancyRecheckFramesField.min).max(occupancyRecheckFramesField.max).default(occupancyRecheckFramesField.default),
@@ -21718,6 +21759,29 @@ var RunnerCameraDeviceUIFields = [
21718
21759
  includes: "onboard"
21719
21760
  }
21720
21761
  },
21762
+ {
21763
+ key: "preRollInferenceEnabled",
21764
+ type: "boolean",
21765
+ style: "checkbox",
21766
+ label: "Detect in the pre-roll",
21767
+ description: "Run detection over the few seconds of footage the camera had already buffered when motion fired, so a subject that was in view before the trigger is found at the moment it appeared rather than seconds later. The burst is bounded and never delays live detection.",
21768
+ default: true
21769
+ },
21770
+ {
21771
+ key: "preRollInferenceFrames",
21772
+ type: "slider",
21773
+ label: "Pre-roll frames",
21774
+ description: "How many frames of buffered history may be detected on, per session. Higher samples the history more densely; 0 disables the pass.",
21775
+ min: preRollInferenceFramesField.min,
21776
+ max: preRollInferenceFramesField.max,
21777
+ step: preRollInferenceFramesField.step,
21778
+ default: preRollInferenceFramesField.default,
21779
+ showValue: true,
21780
+ showWhen: {
21781
+ field: "preRollInferenceEnabled",
21782
+ equals: true
21783
+ }
21784
+ },
21721
21785
  {
21722
21786
  key: "occupancyRecheckEnabled",
21723
21787
  type: "boolean",
package/dist/index.mjs CHANGED
@@ -21323,6 +21323,22 @@ var occupancyRecheckFramesField = {
21323
21323
  step: 1
21324
21324
  };
21325
21325
  /**
21326
+ * Frames one PRE-ROLL catch-up burst may send to inference at session open.
21327
+ *
21328
+ * The default of 12 over a ~4 s retained window is one frame per ~333 ms of
21329
+ * footage, and costs ~480 ms of ONE inference permit at the 40 ms/frame this
21330
+ * fleet measures — one-shot, and only ever taken while a permit would still be
21331
+ * spare for live. `0` turns the burst off entirely (the history is still
21332
+ * decoded, because that is how the dial reaches a decodable GOP, and is then
21333
+ * discarded — the pre-D411 behaviour).
21334
+ */
21335
+ var preRollInferenceFramesField = {
21336
+ min: 0,
21337
+ max: 30,
21338
+ default: 12,
21339
+ step: 1
21340
+ };
21341
+ /**
21326
21342
  * Source enum for motion signals fed to the runner. Extensible — add
21327
21343
  * new variants here when new motion-trigger paths are wired in
21328
21344
  * (`wasm-cross-camera`, `event-bus-relay`, etc.). The runner uses
@@ -21563,6 +21579,31 @@ var RunnerCameraConfigSchema = z.object({
21563
21579
  * to every occupancy rule until something moved in front of it. The churn is
21564
21580
  * now paid on the interval instead — see `occupancyRecheckSecField`.
21565
21581
  */
21582
+ /**
21583
+ * Infer the session's PRE-ROLL — the retained history the restreamer replays
21584
+ * at session open — instead of decoding it and throwing it away.
21585
+ *
21586
+ * DEFAULT `true`, and the default is the argument. This is not a new
21587
+ * capability being offered cautiously: the pre-roll is ALREADY requested,
21588
+ * already served, already decoded and already paid for on every on-motion
21589
+ * detection session that asks for history. What shipped was a last-moment
21590
+ * discard — `FrameSlot`'s throttle compares wall clocks, and ~4 s of media
21591
+ * arriving inside a few hundred ms of wall clock looks to it like one frame's
21592
+ * worth. Device 617, 2026-09-08: a re-run of the SAME model over the stored
21593
+ * recording scored the subject `vehicle 0.5669` — above the 0.50 floor —
21594
+ * 1.68 s BEFORE the live track was born, on a frame that was in the pre-roll,
21595
+ * was decoded, and was freed.
21596
+ *
21597
+ * Shipping that as opt-in would ship the bug: an operator cannot discover a
21598
+ * setting whose absence looks exactly like a camera that noticed the cyclist
21599
+ * late. What makes ON safe is not a switch but the BOUND —
21600
+ * `preRollInferenceFrames`, a wall-clock ceiling, and a lane that never takes
21601
+ * the last inference permit — so the switch exists for the camera where the
21602
+ * history is worthless (a doorbell whose subject is always already at the
21603
+ * door), not as a hedge against the feature.
21604
+ */
21605
+ preRollInferenceEnabled: z.boolean().default(true),
21606
+ preRollInferenceFrames: z.number().min(preRollInferenceFramesField.min).max(preRollInferenceFramesField.max).default(preRollInferenceFramesField.default),
21566
21607
  occupancyRecheckEnabled: z.boolean().default(true),
21567
21608
  occupancyRecheckSec: z.number().min(occupancyRecheckSecField.min).max(occupancyRecheckSecField.max).default(occupancyRecheckSecField.default),
21568
21609
  occupancyRecheckFrames: z.number().min(occupancyRecheckFramesField.min).max(occupancyRecheckFramesField.max).default(occupancyRecheckFramesField.default),
@@ -21717,6 +21758,29 @@ var RunnerCameraDeviceUIFields = [
21717
21758
  includes: "onboard"
21718
21759
  }
21719
21760
  },
21761
+ {
21762
+ key: "preRollInferenceEnabled",
21763
+ type: "boolean",
21764
+ style: "checkbox",
21765
+ label: "Detect in the pre-roll",
21766
+ description: "Run detection over the few seconds of footage the camera had already buffered when motion fired, so a subject that was in view before the trigger is found at the moment it appeared rather than seconds later. The burst is bounded and never delays live detection.",
21767
+ default: true
21768
+ },
21769
+ {
21770
+ key: "preRollInferenceFrames",
21771
+ type: "slider",
21772
+ label: "Pre-roll frames",
21773
+ description: "How many frames of buffered history may be detected on, per session. Higher samples the history more densely; 0 disables the pass.",
21774
+ min: preRollInferenceFramesField.min,
21775
+ max: preRollInferenceFramesField.max,
21776
+ step: preRollInferenceFramesField.step,
21777
+ default: preRollInferenceFramesField.default,
21778
+ showValue: true,
21779
+ showWhen: {
21780
+ field: "preRollInferenceEnabled",
21781
+ equals: true
21782
+ }
21783
+ },
21720
21784
  {
21721
21785
  key: "occupancyRecheckEnabled",
21722
21786
  type: "boolean",
@@ -345,6 +345,21 @@ export interface PipelineInferenceResultPayload {
345
345
  * → delivery latency. Undefined when the frame carried no capture stamp.
346
346
  */
347
347
  readonly capturedAt?: number;
348
+ /**
349
+ * Wall-clock (ms) read on the RUNNER's node at the instant this payload was
350
+ * handed to the bus. A consumer's `now - emittedAt` is the delivery lag —
351
+ * the one number that tells a late DELIVERY apart from a slow CONSUMER when
352
+ * both produce the same signature (a silence, then a burst-drain). See
353
+ * `addon-post-analysis/src/pipeline-analytics/frame-lag-observer.ts` for how
354
+ * it is read and why the absolute value is not a latency.
355
+ *
356
+ * Optional, and undefined is UNKNOWN, never 0 (D8): the bus is telemetry,
357
+ * and during a rolling deploy a runner older than this field emits payloads
358
+ * without it as the normal case. A consumer that folds an absent stamp in as
359
+ * 0 reports "delivered instantly" and fabricates exactly the verdict the
360
+ * field exists to establish.
361
+ */
362
+ readonly emittedAt?: number;
348
363
  /** Child steps enabled for this camera + their scheduling policy (from the catalog). */
349
364
  readonly detailSteps?: readonly DetailStepAnnounce[];
350
365
  readonly [key: string]: unknown;
@@ -83,6 +83,15 @@ export interface RunnerCameraConfig {
83
83
  * to disable the dynamic analyzer for this camera.
84
84
  */
85
85
  readonly onboardMotionDrivesAnalyzer: boolean;
86
+ /**
87
+ * Infer the session's PRE-ROLL — the retained history the restreamer replays
88
+ * at session open — instead of decoding it and discarding it. Mirrors
89
+ * `RunnerCameraConfigSchema.preRollInferenceEnabled` (default true; see the
90
+ * schema for why the default is the argument).
91
+ */
92
+ readonly preRollInferenceEnabled: boolean;
93
+ /** Frames one pre-roll catch-up burst may send to inference. `0` disables it. */
94
+ readonly preRollInferenceFrames: number;
86
95
  /** Master toggle — when false the occupancy recheck never arms (default). */
87
96
  readonly occupancyRecheckEnabled: boolean;
88
97
  /** Seconds between occupancy re-check bursts in watching phase. */
@@ -149,6 +149,18 @@ export interface DecodedFrame {
149
149
  readonly capturedAt?: number;
150
150
  /** Process-local lazy source. Present with an empty `data` buffer on the co-located path. */
151
151
  readonly frameRef?: FrameRef;
152
+ /**
153
+ * True when this frame came out of a session's PRE-ROLL catch-up burst —
154
+ * retained history replayed at session open rather than live footage.
155
+ *
156
+ * It exists so a consumer can ROUTE the frame, not merely label it: history
157
+ * belongs in the runner's bounded pre-roll lane (FIFO, drained strictly
158
+ * behind live), never in the latest-only live detection queue, which would
159
+ * collapse a whole burst to its newest frame. A frame carrying this ALWAYS
160
+ * carries a `capturedAt` measured on the session media clock, not a fresh
161
+ * wall clock.
162
+ */
163
+ readonly preRoll?: boolean;
152
164
  }
153
165
  export interface DecodedAudioChunk {
154
166
  readonly data: Buffer;
@@ -446,4 +458,12 @@ export interface CameraDetectionConfig {
446
458
  readonly occupancyRecheckEnabled: boolean;
447
459
  readonly occupancyRecheckSec: number;
448
460
  readonly occupancyRecheckFrames: number;
461
+ /**
462
+ * Whether the session's already-decoded PRE-ROLL is inferred rather than
463
+ * dropped as stale, and how many of its frames the catch-up burst may spend
464
+ * (D411). Carried here because the orchestrator resolves it per camera and
465
+ * the runner is the one that spends it.
466
+ */
467
+ readonly preRollInferenceEnabled: boolean;
468
+ readonly preRollInferenceFrames: number;
449
469
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@camstack/types",
3
- "version": "1.2.171",
3
+ "version": "1.2.173",
4
4
  "description": "Shared types, interfaces, and model catalogs for the CamStack detection ecosystem",
5
5
  "keywords": [
6
6
  "camstack",