@camstack/addon-ai 0.2.17 → 0.2.19

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
@@ -7294,8 +7294,31 @@ var AdoptionJobSchema = object({
7294
7294
  error: string().nullable()
7295
7295
  });
7296
7296
  /**
7297
- * Per-camera FUNCTION SWITCHES — the one coherent on/off surface over the
7298
- * pipeline functions an operator thinks in terms of.
7297
+ * Per-camera FUNCTION SWITCHES.
7298
+ *
7299
+ * ## The aggregate group is being withdrawn — the BADGE is not (D113)
7300
+ *
7301
+ * This file shipped as "the one coherent on/off surface over the pipeline
7302
+ * functions an operator thinks in terms of". The operator's verdict on
7303
+ * 2026-08-12 was that the coherent surface bought complexity and no clarity:
7304
+ * every function already had a settings page of its own, and a second place to
7305
+ * turn it off is a second place to look. Each switch is going back to its own
7306
+ * component's original options — detection to the detection-pipeline wrapper
7307
+ * binding, audio analysis to its own, recording to `RecordingConfig.enabled`
7308
+ * (which was always first-class; the switch was a veneer over
7309
+ * `recording.setDeviceConfig`), notifications to a notification-center
7310
+ * per-device setting, the two camera planes to their own components.
7311
+ *
7312
+ * What survives is {@link composeSwitchedOff}: `CameraStatus.switchedOff`, the
7313
+ * thing that lets a status surface say DISABLED instead of BROKEN, recomposed
7314
+ * straight from the authorities with no group in the middle. That rule was
7315
+ * never about a control panel.
7316
+ *
7317
+ * Everything else here — {@link CAMERA_SWITCH_CATALOG}, {@link CameraSwitch},
7318
+ * {@link deriveCameraSwitches}, the `pipelineOrchestrator.getCameraSwitches` /
7319
+ * `setCameraSwitch` pair — is a COMPATIBILITY surface for as long as deployed
7320
+ * viewers (v1.0.305) and the admin UI still call it. It is deleted when they
7321
+ * stop; nothing new may be built on it.
7299
7322
  *
7300
7323
  * ## This file adds no state
7301
7324
  *
@@ -7646,7 +7669,15 @@ var RecordingConfigSchema = object({
7646
7669
  * Each completed/failed run also lands one durable ops-log row on its owning
7647
7670
  * addon surface.
7648
7671
  */
7672
+ /**
7673
+ * `queued` exists because the recorder mover is SINGLE-FLIGHT and an operator
7674
+ * rebalance enqueues one job per (camera, profile). Refusing the second job —
7675
+ * what the engine did before — turned a fifteen-camera rebalance into fifteen
7676
+ * manual retries. Queued jobs run FIFO; a queued job that is cancelled never
7677
+ * runs at all.
7678
+ */
7649
7679
  var RelocateJobStateSchema = _enum([
7680
+ "queued",
7650
7681
  "running",
7651
7682
  "done",
7652
7683
  "failed",
@@ -7681,6 +7712,15 @@ var RelocateFootageInputSchema = object({
7681
7712
  /** Limits relocation to the logical profile class. Omit only for the
7682
7713
  * pre-orchestration compatibility path. */
7683
7714
  footageClass: RelocateFootageClassSchema.optional(),
7715
+ /** Scope the move to ONE camera. Absent = every camera on the source, which
7716
+ * is what a whole-disk drain means. The rebalance path always sets it: its
7717
+ * unit is a (camera, profile) pile, not a disk. */
7718
+ deviceId: number().int().optional(),
7719
+ /** Scope the move to specific segment profiles (`high` / `mid` / `low`).
7720
+ * Finer than `footageClass`, which cannot separate high from mid — and the
7721
+ * placement plan assigns those two independently, so a rebalance that could
7722
+ * only say "recordings" would move footage the plan never asked to move. */
7723
+ profiles: array(string()).optional(),
7684
7724
  /** Copy throttle in MB/s (default 40) — the drain is a background chore,
7685
7725
  * never allowed to starve live writers. */
7686
7726
  throttleMbps: number().min(1).max(1e3).optional()
@@ -7816,6 +7856,21 @@ var StorageLocationSchema = object({
7816
7856
  nodeId: string().optional(),
7817
7857
  isDefault: boolean().default(false),
7818
7858
  isSystem: boolean().default(false),
7859
+ /**
7860
+ * Operator opt-in: whether consumers that BALANCE across several locations
7861
+ * of a type may write here. Recordings reads it today; event media and
7862
+ * backups are the next consumers, which is why the flag lives on the
7863
+ * location rather than in any one addon's store — nothing has to be
7864
+ * extended to add the next consumer.
7865
+ *
7866
+ * OPTIONAL, and ABSENT MEANS ACTIVE. Every location persisted before the
7867
+ * flag existed reads back with no flag and keeps working exactly as before;
7868
+ * that is the whole compat story, and it is why no migration ships with it.
7869
+ * A newly CREATED sibling is stamped `false` by the orchestrator (creating a
7870
+ * disk must not silently start writing to it); the default of a type is
7871
+ * always stamped `true`.
7872
+ */
7873
+ enabled: boolean().optional(),
7819
7874
  /** COMPUTED at read time by the orchestrator (statfs of the backing volume
7820
7875
  * for node-local locations it can reach) — never persisted, absent when the
7821
7876
  * volume is remote/unreachable. The single capacity truth every UI reads. */
@@ -12118,7 +12173,8 @@ method(object({
12118
12173
  }), EmbeddingResultSchema), method(object({ text: string() }), EmbeddingResultSchema), method(_void(), EmbeddingInfoSchema);
12119
12174
  /**
12120
12175
  * filesystem-browse — per-node capability for browsing the node's local
12121
- * filesystem, sandboxed to operator-configured allowed roots. Used by the
12176
+ * filesystem. Reads are unconfined (whole filesystem, from `/` down); WRITES
12177
+ * are sandboxed to operator-configured allowed roots (D115). Used by the
12122
12178
  * admin "Add filesystem location" flow to pick a node + path. `mode:'per-node'`
12123
12179
  * (one provider per node); the hub calls it with `{nodeId}` so the codegen
12124
12180
  * routes to that exact node (default `nodeIdMode:'routing'`).
@@ -13976,6 +14032,13 @@ var MaskGridDimsSchema = object({
13976
14032
  * `package-event` are pure trigger kinds (no urgency dimension). Extending
13977
14033
  * this one field keeps the schema additive — a rule still declares exactly
13978
14034
  * one trigger.
14035
+ *
14036
+ * AUDIO rules add no member here, for the reason occupancy added none: the
14037
+ * enum is mirrored by hand in the viewer (`scripts/check-viewer-condition-
14038
+ * mirror.ts` fails the build on a member the app cannot render) and every
14039
+ * member costs a release train. A sustained-sound rule is therefore an
14040
+ * `immediate` rule carrying {@link NcConditions.audio} — the condition is the
14041
+ * trigger discriminator, exactly as `occupancy` is on `device-event`.
13979
14042
  */
13980
14043
  var NcDeliverySchema = _enum([
13981
14044
  "immediate",
@@ -13990,15 +14053,32 @@ var NcDeliverySchema = _enum([
13990
14053
  * depend on a provider's raw event name or payload shape.
13991
14054
  */
13992
14055
  var NcSystemEventKindSchema = _enum([
13993
- "camera-online",
13994
- "camera-offline",
14056
+ "device-online",
14057
+ "device-offline",
14058
+ "device-disabled",
14059
+ "device-enabled",
13995
14060
  "stream-online",
13996
14061
  "stream-offline",
13997
14062
  "node-online",
13998
14063
  "node-offline",
13999
14064
  "addon-update-available",
14000
- "server-update-available"
14065
+ "server-update-available",
14066
+ "alarm-triggered",
14067
+ "alarm-armed",
14068
+ "alarm-disarmed",
14069
+ "camera-online",
14070
+ "camera-offline",
14071
+ "camera-disabled",
14072
+ "camera-enabled"
14073
+ ]);
14074
+ /** The legacy tail of {@link NcSystemEventKindSchema} — see its docblock. */
14075
+ var NC_LEGACY_SYSTEM_EVENT_KINDS = new Set([
14076
+ "camera-online",
14077
+ "camera-offline",
14078
+ "camera-disabled",
14079
+ "camera-enabled"
14001
14080
  ]);
14081
+ NcSystemEventKindSchema.options.filter((kind) => !NC_LEGACY_SYSTEM_EVENT_KINDS.has(kind));
14002
14082
  /**
14003
14083
  * One coherent system-event condition. `kinds` is the required opt-in safety
14004
14084
  * gate; the remaining lists are optional narrowing filters relevant to the
@@ -14007,6 +14087,18 @@ var NcSystemEventKindSchema = _enum([
14007
14087
  var NcSystemEventConditionSchema = object({
14008
14088
  kinds: array(NcSystemEventKindSchema).min(1),
14009
14089
  deviceIds: array(number().int()).min(1).optional(),
14090
+ /**
14091
+ * Narrow a `device-*` kind to these device TYPES (`DeviceType` values —
14092
+ * `camera`, `switch`, `sensor`, `container`, …). Absent = every type, which
14093
+ * is what a liveness rule means when nobody said otherwise.
14094
+ *
14095
+ * This is where "only my cameras" is expressed, and it lives on the rule for
14096
+ * one reason: the intake cannot know which devices this household cares
14097
+ * about, and a producer-side filter is one no operator can change. Fails
14098
+ * CLOSED — a subject whose device type is unknown (an id the device mirror
14099
+ * does not carry) matches no `deviceTypes` list.
14100
+ */
14101
+ deviceTypes: array(string().min(1)).min(1).optional(),
14010
14102
  nodeIds: array(string().min(1)).min(1).optional(),
14011
14103
  packageNames: array(string().min(1)).min(1).optional()
14012
14104
  });
@@ -14057,6 +14149,47 @@ var NcOccupancyConditionSchema = object({
14057
14149
  sustainSeconds: number().int().min(0).max(3600).default(15)
14058
14150
  });
14059
14151
  /**
14152
+ * Audio condition (IMMEDIATE trigger) — a rule on SOUND, not on a picture.
14153
+ *
14154
+ * Operator-approved vocabulary (2026-08-12, option A — the same one the
14155
+ * reference notifier uses, so an operator moving between them re-uses what
14156
+ * they already know): a rule matches when, over a sampling window of
14157
+ * `samplingSeconds`, at least `hitPercent`% of the audio samples in that
14158
+ * window are HITS. A sample is a hit when it satisfies BOTH present filters:
14159
+ *
14160
+ * - `dbThreshold` — its level is at or above this many dBFS (see
14161
+ * {@link NC_AUDIO_DBFS_FLOOR}: negative-going, `0` = full scale);
14162
+ * - `labels` — the classifier put at least one of these labels on it.
14163
+ *
14164
+ * Both are OPTIONAL and independent, which is the point of the shape: a
14165
+ * loudness rule ("something loud at 3am") needs no model to be right, and a
14166
+ * label rule ("a dog barked") needs no threshold. **Fail-closed when NEITHER
14167
+ * is given** — a window in which every sample is trivially a hit would fire on
14168
+ * silence, so the engine refuses such a condition rather than notifying on
14169
+ * nothing (the schema cannot express "at least one of" without becoming a
14170
+ * ZodEffects the cap path would have to special-case).
14171
+ *
14172
+ * `hitPercent` is over the samples the window actually HOLDS, and the window
14173
+ * must be FULL before it can match — a window that has been open for two
14174
+ * seconds of its ten is 100% of nothing, and firing on it would make
14175
+ * `samplingSeconds` decorative.
14176
+ *
14177
+ * Labels are the audio macro classes (`AUDIO_MACRO_LABELS` / the NC taxonomy's
14178
+ * `audio-*` ids). Both spellings are accepted — the matcher normalizes the
14179
+ * `audio-` prefix away on both sides, so a picker that offers taxonomy ids and
14180
+ * an operator who typed `dog` mean the same thing.
14181
+ */
14182
+ var NcAudioConditionSchema = object({
14183
+ /** Audio macro labels; absent = any sound (level-only rule). */
14184
+ labels: array(string().min(1)).min(1).optional(),
14185
+ /** Level floor in dBFS (negative-going, `0` = full scale); absent = any level. */
14186
+ dbThreshold: number().min(-96).max(0).optional(),
14187
+ /** Percentage of the window's samples that must be hits (1–100). */
14188
+ hitPercent: number().int().min(1).max(100).default(60),
14189
+ /** Length of the sampling window in seconds. */
14190
+ samplingSeconds: number().int().min(1).max(300).default(10)
14191
+ });
14192
+ /**
14060
14193
  * Which zone-crossing DIRECTION a rule accepts (`ObjectEvent.zoneCrossing`).
14061
14194
  *
14062
14195
  * The values are not symmetric, and deliberately so — the absent value has to
@@ -14329,7 +14462,33 @@ var NcConditionsSchema = object({
14329
14462
  * threshold and holds for `sustainSeconds`. Fail-closed on missing
14330
14463
  * substrate (no snapshot / missing zone). See {@link NcOccupancyCondition}.
14331
14464
  */
14332
- occupancy: NcOccupancyConditionSchema.optional()
14465
+ occupancy: NcOccupancyConditionSchema.optional(),
14466
+ /**
14467
+ * IMMEDIATE only. Sustained-sound matcher — `hitPercent` of the samples in a
14468
+ * `samplingSeconds` window clear the optional `dbThreshold` and carry one of
14469
+ * the optional `labels`. Fail-closed on missing substrate (no audio samples,
14470
+ * a window that is not full yet, neither filter given). See
14471
+ * {@link NcAudioCondition}.
14472
+ *
14473
+ * Presence of this key is what makes a rule an AUDIO rule: the engine fires
14474
+ * it ONLY on a confirmed audio window, and a rule carrying it never fires on
14475
+ * a detection, a track or a device event (the same fail-closed pairing
14476
+ * `occupancy` has with the `device-event` trigger). That is how audio labels
14477
+ * leave `classes`: an audio rule names its sounds HERE, and the legacy path
14478
+ * (an `immediate` rule naming an `audio-*` class, one notification per
14479
+ * classified sample) stays exactly as it was for rules that already use it.
14480
+ *
14481
+ * NOT in {@link NC_CONDITION_CATALOG} yet, and that is the sequencing rule
14482
+ * rather than an oversight: the viewer mirrors the descriptor enums BY HAND
14483
+ * (`camstack/src/data/notification-center.ts`, guarded by
14484
+ * `scripts/check-viewer-condition-mirror.ts`) and its rule editor STRIPS the
14485
+ * condition fields it does not know when a rule is saved from the phone.
14486
+ * Publishing an editor for a condition the app cannot round-trip is how an
14487
+ * operator loses a rule's conditions by opening it — so the descriptor, the
14488
+ * admin widget and the viewer mirror land together (P2 + P3), and only then
14489
+ * does an audio rule become authorable.
14490
+ */
14491
+ audio: NcAudioConditionSchema.optional()
14333
14492
  });
14334
14493
  /** One delivery target: a `notification-output` Target ref + passthrough params. */
14335
14494
  var NcRuleTargetSchema = object({
@@ -14443,6 +14602,73 @@ var NcThrottleSchema = object({
14443
14602
  */
14444
14603
  granularity: NcThrottleGranularitySchema.optional()
14445
14604
  });
14605
+ /**
14606
+ * How long the confirm gate may hold ONE notification, and how big the picture
14607
+ * it judges may be.
14608
+ *
14609
+ * The clamp is the product decision, not a coincidence of the model: p50 was
14610
+ * 4.9 s warm and 15.3 s cold against qwen3-vl-8b, and a notification that
14611
+ * arrives after the visitor has gone is not a notification. 448 px was enough
14612
+ * to score 16/16 on the operator's parking scenario — bigger costs latency and
14613
+ * tokens for pixels the model pools away.
14614
+ */
14615
+ var NC_CONFIRM_MIN_TIMEOUT_MS = 1e3;
14616
+ var NC_CONFIRM_MAX_TIMEOUT_MS = 2e4;
14617
+ var NC_CONFIRM_DEFAULT_TIMEOUT_MS = 8e3;
14618
+ /** Comparison the model's COUNT must satisfy for the notification to fire. */
14619
+ var NcConfirmExpectSchema = object({
14620
+ op: _enum([
14621
+ ">=",
14622
+ ">",
14623
+ "<=",
14624
+ "<",
14625
+ "=="
14626
+ ]),
14627
+ count: number().int().min(0).max(1e3)
14628
+ });
14629
+ /**
14630
+ * AI CONFIRM — a vision model looks at the picture this notification is about
14631
+ * to ship and says whether it agrees with the rule.
14632
+ *
14633
+ * It runs AFTER the attachments resolve, deliberately: the crop JUDGED is the
14634
+ * crop SHIPPED (D52). A verdict about a different pixel rectangle than the one
14635
+ * on the operator's phone is not a verdict about this notification.
14636
+ *
14637
+ * FAIL-OPEN is the only safe default. A gate that cannot reach its model, or
14638
+ * whose model is cold, must not silence a camera — so `onTimeout: 'fire'` is
14639
+ * the default and every fail-open is COUNTED, because a gate that always fails
14640
+ * open looks in the log exactly like a gate that works.
14641
+ *
14642
+ * Every field is `.optional()` rather than relied on as a Zod default at the
14643
+ * runtime seam: a Zod default does NOT run on the addon→addon cap path (three
14644
+ * production failures in one day), so the gate reads absent as the constant
14645
+ * above rather than trusting a parse it may never have seen.
14646
+ */
14647
+ var NcConfirmSchema = object({
14648
+ /** Off unless asked for. An absent `confirm` and `enabled:false` are the
14649
+ * same thing, and both mean "deliver exactly as before". */
14650
+ enabled: boolean().default(false),
14651
+ /** Explicit vision profile; absent = the `purpose:'vision'` cluster default. */
14652
+ profileId: string().optional(),
14653
+ /**
14654
+ * The operator's question, in his own words. Absent = a question derived
14655
+ * from the rule (its class and its expectation).
14656
+ *
14657
+ * NEVER composed with text READ OUT OF THE FRAME. The model reads OSD
14658
+ * banners, signage and plates as instructions if you let them reach the
14659
+ * prompt — proven live — so the authoritative contract stays in the system
14660
+ * turn and only rule-authored words land here.
14661
+ */
14662
+ prompt: string().max(1e3).optional(),
14663
+ /** Fire only when the model's count satisfies this. Absent = the model's
14664
+ * own boolean verdict decides. */
14665
+ expect: NcConfirmExpectSchema.optional(),
14666
+ timeoutMs: number().int().min(NC_CONFIRM_MIN_TIMEOUT_MS).max(NC_CONFIRM_MAX_TIMEOUT_MS).default(NC_CONFIRM_DEFAULT_TIMEOUT_MS),
14667
+ /** What a timeout / unreachable model MEANS. `fire` (default) = fail-open. */
14668
+ onTimeout: _enum(["fire", "suppress"]).default("fire"),
14669
+ /** Longest edge the judged image is downscaled to before it is sent. */
14670
+ maxImagePx: number().int().min(64).max(2048).default(448)
14671
+ });
14446
14672
  /** Client-supplied rule fields (server stamps id/createdBy/createdAt/updatedAt). */
14447
14673
  var NcRuleInputSchema = object({
14448
14674
  name: string().min(1).max(200),
@@ -14503,7 +14729,13 @@ var NcRuleInputSchema = object({
14503
14729
  * `{ cap: 'alarm-panel', method: 'arm', args: { mode: 'away' } }`, the same
14504
14730
  * shape as every other actuation.
14505
14731
  */
14506
- actions: NcRuleActionsSchema.optional()
14732
+ actions: NcRuleActionsSchema.optional(),
14733
+ /**
14734
+ * AI CONFIRM — see {@link NcConfirmSchema}. `.optional()`, never defaulted:
14735
+ * a rule that predates the gate must keep delivering byte-for-byte as it
14736
+ * did, and absent is the only way to say that without a migration.
14737
+ */
14738
+ confirm: NcConfirmSchema.optional()
14507
14739
  });
14508
14740
  /**
14509
14741
  * Partial patch for `updateRule` — any subset of the input fields, plus the
@@ -14514,7 +14746,37 @@ var NcRuleInputSchema = object({
14514
14746
  * still flow through `nc.setRuleTargetEnabled` (owner-checked), never a raw
14515
14747
  * `updateRule` patch.
14516
14748
  */
14517
- var NcRulePatchSchema = NcRuleInputSchema.partial().extend({ disabledTargetIds: array(string()).optional() });
14749
+ var NcRulePatchSchema = NcRuleInputSchema.partial().extend({
14750
+ disabledTargetIds: array(string()).optional(),
14751
+ /**
14752
+ * `.partial()` DOES NOT REMOVE A FIELD'S `.default()`.
14753
+ *
14754
+ * It makes the key optional to SUPPLY; the parse still materialises the
14755
+ * default when the key is absent. And `NcRuleStore.update` merges with
14756
+ * `{ ...existing, ...patch }`, so a materialised key OVERWRITES the stored
14757
+ * one — which made every partial edit destructive:
14758
+ *
14759
+ * nc.updateRule({ throttle }) → conditions reset to `{}`
14760
+ * nc.setRuleTargetEnabled(...) → conditions reset to `{}`
14761
+ * setEnabled(ruleId, false) → conditions reset to `{}`
14762
+ *
14763
+ * A rule scoped to one camera and one zone silently became a rule that
14764
+ * matches EVERY event on EVERY camera, and lost its `media` policy
14765
+ * (zoneCrop / gif / clip / frame) and its `priority` at the same time. Seen
14766
+ * live on 2026-08-12: a rule scoped to device 617 fired on 590 and 615
14767
+ * within a minute of a two-field patch.
14768
+ *
14769
+ * So every defaulted field is re-declared here WITHOUT its default. The
14770
+ * inner defaults still apply when the caller DOES send the key — `{}` for
14771
+ * conditions remains a real instruction ("clear them") — and only the
14772
+ * absent key is now genuinely absent.
14773
+ */
14774
+ enabled: boolean().optional(),
14775
+ conditions: NcConditionsSchema.optional(),
14776
+ media: NcMediaPolicySchema.optional(),
14777
+ throttle: NcThrottleSchema.optional(),
14778
+ priority: number().int().min(1).max(5).optional()
14779
+ });
14518
14780
  /** A persisted rule. */
14519
14781
  var NcRuleSchema = NcRuleInputSchema.extend({
14520
14782
  id: string(),
@@ -14815,6 +15077,25 @@ var NcAlarmSettingsPatchSchema = NcAlarmSettingsSchema.partial();
14815
15077
  * Never authored, never stored — see `alarm-mode-coverage.ts` for why a stored
14816
15078
  * copy would lie the first time a rule is disabled.
14817
15079
  */
15080
+ /**
15081
+ * Why a device a mode NAMES is nonetheless not armed by it.
15082
+ *
15083
+ * Each value is an existing authority, never a new flag (D62): `muted` is the
15084
+ * per-camera notification switch the Notification Center already owns,
15085
+ * `detection-off` is the device's own detection binding being inactive, and
15086
+ * `offline` is the device manager's liveness. A fourth reason would mean a
15087
+ * fourth authority, and inventing one here is how a panel starts disagreeing
15088
+ * with the switches the operator actually used.
15089
+ */
15090
+ var NcAlarmSkipReasonSchema = _enum([
15091
+ "muted",
15092
+ "detection-off",
15093
+ "offline"
15094
+ ]);
15095
+ var NcAlarmSkippedDeviceSchema = object({
15096
+ deviceId: number().int(),
15097
+ reason: NcAlarmSkipReasonSchema
15098
+ });
14818
15099
  var NcAlarmModeCoverageSchema = object({
14819
15100
  mode: AlarmArmModeSchema,
14820
15101
  /** Enabled rules gated on `armed_<mode>`. Zero means the mode does nothing. */
@@ -14822,7 +15103,18 @@ var NcAlarmModeCoverageSchema = object({
14822
15103
  /** At least one covering rule has no device scope, so the mode covers all. */
14823
15104
  allDevices: boolean(),
14824
15105
  /** Ids named by the covering rules. A SUBSET when `allDevices` is true. */
14825
- deviceIds: array(number().int())
15106
+ deviceIds: array(number().int()),
15107
+ /**
15108
+ * Devices this mode NAMES but cannot actually arm, each with the switch that
15109
+ * excludes it.
15110
+ *
15111
+ * "Away armed — 12 cameras" is a promise, and a muted camera among those
15112
+ * twelve makes it false in exactly the way nobody notices until an incident.
15113
+ * Defaulted to `[]` so a coverage answer computed before this field existed
15114
+ * still parses as "nothing known to be skipped" rather than failing the whole
15115
+ * alarm tab.
15116
+ */
15117
+ skippedDevices: array(NcAlarmSkippedDeviceSchema).default([])
14826
15118
  });
14827
15119
  var NcAlarmConfigSchema = object({
14828
15120
  /**
@@ -17621,9 +17913,16 @@ var CameraStatusSchema = object({
17621
17913
  audio: CameraAudioStatusSchema.nullable(),
17622
17914
  recording: CameraRecordingStatusSchema.nullable(),
17623
17915
  /**
17624
- * Per-camera function switches an OPERATOR has turned off
17916
+ * Per-camera functions an OPERATOR has turned off
17625
17917
  * ([D61](../../../../docs/decisions/adr-0067.md)).
17626
17918
  *
17919
+ * Composed from the AUTHORITIES themselves — the wrapper bindings,
17920
+ * `RecordingConfig.enabled`, the notification mute, the broker's audio
17921
+ * policy, the camera's own microphone — via `composeSwitchedOff`, not from
17922
+ * the deprecated `getCameraSwitches` group ([D113](../../../../docs/decisions/adr-0113.md)).
17923
+ * The badge outlives the control panel: the panel was a convenience, this is
17924
+ * the difference between a camera being off and a camera being dead.
17925
+ *
17627
17926
  * This is the difference between DISABLED and BROKEN. A camera whose
17628
17927
  * `detection` block reports zero fps and whose `switchedOff` contains
17629
17928
  * `'object-detection'` was switched off by a person; the same camera with an
@@ -23132,7 +23431,19 @@ var RecordingManifestSchema = object({
23132
23431
  * profiles/subtrees/locations on this node). */
23133
23432
  var RecordingDeviceUsageSchema = object({
23134
23433
  deviceId: number(),
23135
- usedBytes: number()
23434
+ usedBytes: number(),
23435
+ /**
23436
+ * Start of this camera's OLDEST indexed segment, across every profile and
23437
+ * location — the "Oldest footage" column in Recordings → Storage, and the
23438
+ * only honest answer to "is retention actually holding?" per camera.
23439
+ *
23440
+ * `null` = the camera has no footage. OPTIONAL because a recorder that
23441
+ * predates this field omits it entirely, and a hub whose types carry the
23442
+ * field must keep validating that older provider's payload: the framework
23443
+ * (types) and the addon ship on different trains, and the addon is usually
23444
+ * the later of the two.
23445
+ */
23446
+ oldestMs: number().nullable().optional()
23136
23447
  });
23137
23448
  /** Recording storage usage + capacity for one storage location. */
23138
23449
  var RecordingLocationUsageSchema = object({
@@ -23160,6 +23471,57 @@ var RecordingStorageUsageSchema = object({
23160
23471
  locations: array(RecordingLocationUsageSchema)
23161
23472
  });
23162
23473
  /**
23474
+ * The OPERATOR-ARMED half of multi-location recordings (D116).
23475
+ *
23476
+ * The placement plan decides where NEW writes go and moves nothing. A rebalance
23477
+ * is the operator asking for the EXISTING archive to be brought into line with
23478
+ * that plan: one relocate job per (camera, profile) pile that sits on the wrong
23479
+ * location, run FIFO behind the single-flight mover.
23480
+ *
23481
+ * `plan…` and `start…` return the SAME shape deliberately — what the operator
23482
+ * confirms is exactly what gets enqueued, and `jobIds` is the only difference
23483
+ * (empty on the plan).
23484
+ */
23485
+ var RecordingRebalanceMoveSchema = object({
23486
+ deviceId: number(),
23487
+ profile: string(),
23488
+ fromLocationId: string(),
23489
+ toLocationId: string(),
23490
+ bytes: number(),
23491
+ files: number().int()
23492
+ });
23493
+ /** Why a pile that is out of place is staying there. Every refusal is
23494
+ * reported: a rebalance that silently drops a camera reads exactly like one
23495
+ * that had nothing to do. */
23496
+ var RecordingRebalanceSkipReasonSchema = _enum([
23497
+ "unassigned",
23498
+ "target-not-writable",
23499
+ "below-threshold",
23500
+ "no-headroom"
23501
+ ]);
23502
+ var RecordingRebalanceSkipSchema = object({
23503
+ deviceId: number(),
23504
+ profile: string(),
23505
+ fromLocationId: string(),
23506
+ /** The location the plan wants; null when the camera has no assignment. */
23507
+ toLocationId: string().nullable(),
23508
+ bytes: number(),
23509
+ reason: RecordingRebalanceSkipReasonSchema
23510
+ });
23511
+ var RecordingRebalancePlanSchema = object({
23512
+ moves: array(RecordingRebalanceMoveSchema),
23513
+ skipped: array(RecordingRebalanceSkipSchema),
23514
+ bytesToMove: number(),
23515
+ /** Relocate job ids enqueued. Always empty for the plan (dry-run) call. */
23516
+ jobIds: array(string())
23517
+ });
23518
+ var RecordingRebalanceInputSchema = object({
23519
+ /** Copy throttle in MB/s (default 40) — a rebalance is a background chore. */
23520
+ throttleMbps: number().min(1).max(1e3).optional(),
23521
+ /** Ignore piles smaller than this (default 1 GB). */
23522
+ minMoveGb: number().min(0).optional()
23523
+ });
23524
+ /**
23163
23525
  * Result of locating footage at a wall-clock instant for one device/profile.
23164
23526
  * `segment` carries the covering segment's window; `gap` reports the forward
23165
23527
  * nearest covered edge (`null` past the end of footage / when none exists)
@@ -23322,9 +23684,24 @@ method(object({
23322
23684
  }), method(object({ jobId: string() }), RelocateJobSchema.nullable(), { auth: "admin" }), method(object({ jobId: string() }), object({ cancelled: boolean() }), {
23323
23685
  kind: "mutation",
23324
23686
  auth: "admin"
23687
+ }), method(RelocateFootageInputSchema, object({ jobId: string() }), {
23688
+ kind: "mutation",
23689
+ auth: "admin"
23690
+ }), method(object({}), array(RelocateJobSchema).readonly(), {
23691
+ kind: "query",
23692
+ auth: "admin"
23693
+ }), method(object({ jobId: string() }), object({ cancelled: boolean() }), {
23694
+ kind: "mutation",
23695
+ auth: "admin"
23696
+ }), method(RecordingRebalanceInputSchema, RecordingRebalancePlanSchema, {
23697
+ kind: "query",
23698
+ auth: "admin"
23699
+ }), method(RecordingRebalanceInputSchema, RecordingRebalancePlanSchema, {
23700
+ kind: "mutation",
23701
+ auth: "admin"
23325
23702
  });
23326
23703
  /**
23327
- * `recordingExport` cap — render a footage time range into a single downloadable
23704
+ * `recording-export` cap — render a footage time range into a single downloadable
23328
23705
  * MP4 (regular / accelerated / decelerated / timelapse, ± audio), kept for a
23329
23706
  * bounded lifetime with a durable history, auto-expiry, and optional
23330
23707
  * delete-after-download.
@@ -23339,10 +23716,53 @@ method(object({
23339
23716
  */
23340
23717
  /** Playback-speed multiplier for the render (1 = realtime). */
23341
23718
  var ExportSpeedSchema = number().min(.25).max(32);
23719
+ /**
23720
+ * One dense interval, in WALL-CLOCK SECONDS FROM THE EXPORT'S OWN `fromMs`.
23721
+ *
23722
+ * **Wall clock, not ffmpeg's `t`** — and the recorder translates. A caller
23723
+ * derives these bounds from things that happened at a TIME (a track's
23724
+ * `firstSeen`), while `t` runs over the source playlist: the concatenation of
23725
+ * every segment present for the range, with each recording GAP removed. The
23726
+ * two agree only on a window that recorded without one interruption, and only
23727
+ * the render side knows the segments, so the translation lives there
23728
+ * (`export-dense-map.ts`, addon-pipeline).
23729
+ *
23730
+ * It was not always so. These seconds were fed to `between(t,…)` verbatim, and
23731
+ * on a 10 h window holding 29,393 s of footage every range landed late by the
23732
+ * gap accumulated before it — up to 6,607 s, well past EOF. Nothing matched,
23733
+ * the video was a uniform timelapse, and the log line reported the five ranges
23734
+ * that had been ASKED for (2026-08-13, export `57d14363`, camera 615).
23735
+ *
23736
+ * Relative and not absolute epoch, because an absolute epoch would make every
23737
+ * call site responsible for the same subtraction.
23738
+ */
23739
+ var ExportDenseRangeSchema = object({
23740
+ fromSec: number().nonnegative(),
23741
+ toSec: number().nonnegative()
23742
+ }).refine((r) => r.toSec > r.fromSec, { message: "dense range must have toSec > fromSec" });
23743
+ /**
23744
+ * Dense-interval overlay for a timelapse: sample at `dense.everyMs` INSIDE the
23745
+ * listed ranges and at the base `everyMs` everywhere else.
23746
+ *
23747
+ * `everyMs` must be strictly smaller than the base cadence — a dense rate that
23748
+ * is not denser renders a uniform timelapse the operator believes is two-rate.
23749
+ */
23750
+ var ExportDenseSchema = object({
23751
+ everyMs: number().int().positive(),
23752
+ ranges: array(ExportDenseRangeSchema).min(1).max(200)
23753
+ });
23342
23754
  /** Timelapse cadence — sample one source frame per `everyMs`, output at `outputFps`. */
23343
23755
  var ExportTimelapseSchema = object({
23344
23756
  everyMs: number().int().positive(),
23345
- outputFps: number().int().min(1).max(60).optional()
23757
+ outputFps: number().int().min(1).max(60).optional(),
23758
+ /** Optional second, FASTER rate over the intervals that matter. */
23759
+ dense: ExportDenseSchema.optional()
23760
+ }).superRefine((v, ctx) => {
23761
+ if (v.dense !== void 0 && v.dense.everyMs >= v.everyMs) ctx.addIssue({
23762
+ code: ZodIssueCode.custom,
23763
+ message: "dense.everyMs must be strictly smaller than the base everyMs",
23764
+ path: ["dense", "everyMs"]
23765
+ });
23346
23766
  });
23347
23767
  /**
23348
23768
  * Render options. `speed` and `timelapse` are mutually exclusive. `includeAudio`
@@ -23400,6 +23820,19 @@ var ExportDownloadSchema = object({
23400
23820
  url: string(),
23401
23821
  endpoints: array(string())
23402
23822
  });
23823
+ /**
23824
+ * A finished export's bytes, inline.
23825
+ *
23826
+ * `bytes` is the DECODED length — the number the caller bounds and logs
23827
+ * against, so nobody has to infer it from the base64 length.
23828
+ */
23829
+ var ExportBytesSchema = object({
23830
+ base64: string(),
23831
+ contentType: string(),
23832
+ /** Suggested filename, extension included. */
23833
+ name: string(),
23834
+ bytes: number().int().nonnegative()
23835
+ });
23403
23836
  method(object({
23404
23837
  deviceId: number(),
23405
23838
  profile: string(),
@@ -23424,6 +23857,9 @@ method(object({
23424
23857
  }), method(object({ exportId: string() }), ExportDownloadSchema, {
23425
23858
  kind: "query",
23426
23859
  auth: "protected"
23860
+ }), method(object({ exportId: string() }), ExportBytesSchema, {
23861
+ kind: "query",
23862
+ auth: "protected"
23427
23863
  });
23428
23864
  /**
23429
23865
  * scene-monitor — device-scoped reference-region state cap. An operator marks
@@ -28617,6 +29053,12 @@ Object.freeze({
28617
29053
  addonId: null,
28618
29054
  access: "create"
28619
29055
  },
29056
+ "recording.cancelRelocateJob": {
29057
+ capName: "recording",
29058
+ capScope: "system",
29059
+ addonId: null,
29060
+ access: "create"
29061
+ },
28620
29062
  "recording.cancelStorageMigrationMove": {
28621
29063
  capName: "recording",
28622
29064
  capScope: "system",
@@ -28671,6 +29113,12 @@ Object.freeze({
28671
29113
  addonId: null,
28672
29114
  access: "view"
28673
29115
  },
29116
+ "recording.listRelocateJobs": {
29117
+ capName: "recording",
29118
+ capScope: "system",
29119
+ addonId: null,
29120
+ access: "view"
29121
+ },
28674
29122
  "recording.locateSegment": {
28675
29123
  capName: "recording",
28676
29124
  capScope: "system",
@@ -28683,6 +29131,12 @@ Object.freeze({
28683
29131
  addonId: null,
28684
29132
  access: "create"
28685
29133
  },
29134
+ "recording.planStorageRebalance": {
29135
+ capName: "recording",
29136
+ capScope: "system",
29137
+ addonId: null,
29138
+ access: "view"
29139
+ },
28686
29140
  "recording.pruneFootage": {
28687
29141
  capName: "recording",
28688
29142
  capScope: "system",
@@ -28707,6 +29161,12 @@ Object.freeze({
28707
29161
  addonId: null,
28708
29162
  access: "create"
28709
29163
  },
29164
+ "recording.relocateFootage": {
29165
+ capName: "recording",
29166
+ capScope: "system",
29167
+ addonId: null,
29168
+ access: "create"
29169
+ },
28710
29170
  "recording.renderClip": {
28711
29171
  capName: "recording",
28712
29172
  capScope: "system",
@@ -28743,38 +29203,50 @@ Object.freeze({
28743
29203
  addonId: null,
28744
29204
  access: "create"
28745
29205
  },
29206
+ "recording.startStorageRebalance": {
29207
+ capName: "recording",
29208
+ capScope: "system",
29209
+ addonId: null,
29210
+ access: "create"
29211
+ },
28746
29212
  "recordingExport.cancelExport": {
28747
- capName: "recordingExport",
29213
+ capName: "recording-export",
28748
29214
  capScope: "system",
28749
29215
  addonId: null,
28750
29216
  access: "create"
28751
29217
  },
28752
29218
  "recordingExport.createExport": {
28753
- capName: "recordingExport",
29219
+ capName: "recording-export",
28754
29220
  capScope: "system",
28755
29221
  addonId: null,
28756
29222
  access: "create"
28757
29223
  },
28758
29224
  "recordingExport.deleteExport": {
28759
- capName: "recordingExport",
29225
+ capName: "recording-export",
28760
29226
  capScope: "system",
28761
29227
  addonId: null,
28762
29228
  access: "delete"
28763
29229
  },
28764
29230
  "recordingExport.getDownloadUrl": {
28765
- capName: "recordingExport",
29231
+ capName: "recording-export",
28766
29232
  capScope: "system",
28767
29233
  addonId: null,
28768
29234
  access: "view"
28769
29235
  },
28770
29236
  "recordingExport.getExport": {
28771
- capName: "recordingExport",
29237
+ capName: "recording-export",
28772
29238
  capScope: "system",
28773
29239
  addonId: null,
28774
29240
  access: "view"
28775
29241
  },
28776
29242
  "recordingExport.listExports": {
28777
- capName: "recordingExport",
29243
+ capName: "recording-export",
29244
+ capScope: "system",
29245
+ addonId: null,
29246
+ access: "view"
29247
+ },
29248
+ "recordingExport.readExportBytes": {
29249
+ capName: "recording-export",
28778
29250
  capScope: "system",
28779
29251
  addonId: null,
28780
29252
  access: "view"
@@ -30151,6 +30623,104 @@ var FramerateField = number().int().min(1).max(60);
30151
30623
  var TargetsField = array(NcRuleTargetSchema).min(1);
30152
30624
  var PriorityField = number().int().min(1).max(5);
30153
30625
  /**
30626
+ * Explicit override of the DENSE sampling cadence, seconds.
30627
+ *
30628
+ * Absent ⇒ derived as `max(1s, cadenceSec / 30)` — a 30 s base samples every
30629
+ * 1 s inside a detection range. (It was `base / 10` until 2026-08-12, which
30630
+ * made that same base 3 s and rendered a person pass as two frames.)
30631
+ *
30632
+ * THE ARITHMETIC. A detection range of `rangeSec` seconds sampled every
30633
+ * `denseCadenceSec` and played at `framerate` occupies
30634
+ *
30635
+ * outputSeconds = (rangeSec / denseCadenceSec) / framerate
30636
+ *
30637
+ * so a 7 s pass at 1 s / 12 fps is 0.58 s of video, and at 0.5 s it is 1.17 s.
30638
+ * Halving this field doubles the frames INSIDE ranges only — the base cadence,
30639
+ * and therefore the length of a quiet night, does not move.
30640
+ *
30641
+ * Floored at {@link TIMELAPSE_DENSE_FLOOR_SEC}: asking for frames faster than
30642
+ * the recording has them returns the same frames, requested twice. Must be
30643
+ * STRICTLY smaller than `cadenceSec` — a dense rate that is not denser renders
30644
+ * a uniform video the operator believes is two-rate — and upsert refuses it
30645
+ * rather than letting the export cap reject the render hours after the window.
30646
+ */
30647
+ var DenseCadenceSecField = number().min(.1).max(3600);
30648
+ /**
30649
+ * Minimum seconds of OUTPUT video each detection range must occupy.
30650
+ *
30651
+ * The operator-facing form of the arithmetic above: instead of solving for a
30652
+ * cadence, state the dwell and let the renderer solve. `minDwellSec: 1` on a
30653
+ * 30 s base at 12 fps turns a 7 s pass into a full second of video by sampling
30654
+ * that range every ~583 ms.
30655
+ *
30656
+ * ONE CADENCE SERVES EVERY RANGE. `ExportDenseSchema.everyMs` is global — the
30657
+ * ranges are terms of a single ffmpeg `select` expression that cannot vary rate
30658
+ * per term — so the MOST DEMANDING (shortest) range sets the rate and longer
30659
+ * ranges are sampled denser than they need. Per-range cadences require a cap
30660
+ * schema change and are the tracked follow-up.
30661
+ *
30662
+ * A range too short to reach the dwell even at {@link TIMELAPSE_DENSE_FLOOR_SEC}
30663
+ * is rendered with every frame that EXISTS and no more: the guarantee is capped
30664
+ * by real footage, never met by duplicating frames into motion that never
30665
+ * happened.
30666
+ */
30667
+ var MinDwellSecField = number().min(0).max(60);
30668
+ /**
30669
+ * Caption burned into the notification's preview frame.
30670
+ *
30671
+ * Same `{{var}}` vocabulary as {@link TimelapseTemplateSchema} (`camera`,
30672
+ * `rule`, `from`, `to`) and rendered by the SAME renderer — a second
30673
+ * templating dialect for one field would be a second thing to explain.
30674
+ *
30675
+ * Absent ⇒ {@link DEFAULT_TIMELAPSE_PREVIEW_TEXT}. An EMPTY STRING is the
30676
+ * operator saying "the frame, no caption" — a distinct, reachable answer, and
30677
+ * the reason this is not `.min(1)`.
30678
+ */
30679
+ var PreviewTextField = string().max(200);
30680
+ /**
30681
+ * Whether the notification's preview is a STILL or a short animation.
30682
+ *
30683
+ * The operator's ask, verbatim: *"inviato come gif o video (come per le altre
30684
+ * rule)"* — his Scrypted advanced-notifier has a `gifRule`, and a ten-hour
30685
+ * night reads better as three seconds of motion than as one frame of it. Both
30686
+ * modes get the SAME treatment (blurred frame, large centred title); `'gif'`
30687
+ * simply applies it to a dozen frames sampled across the render and assembles
30688
+ * them.
30689
+ *
30690
+ * `'image'` is the default and stays the default: a GIF costs a dozen ffmpeg
30691
+ * seeks and a palette pass, and no rule that never asked for one should start
30692
+ * paying that on the deploy that shipped it.
30693
+ *
30694
+ * A GIF that cannot be assembled DEGRADES to the still — never to nothing.
30695
+ */
30696
+ var PreviewModeField = _enum(["image", "gif"]);
30697
+ /**
30698
+ * Which detection classes the notification reports counts for.
30699
+ *
30700
+ * The counts come from the tracks the render ALREADY fetched for its dense-range
30701
+ * plan — no second query — aggregated per class. Absent or empty means "every
30702
+ * class the window actually contained", which is what an operator who never
30703
+ * opened the field wants; a list narrows it (`['person']` on a driveway that
30704
+ * counts cars all night).
30705
+ *
30706
+ * Class names are the tracker's own (`person`, `vehicle`, `animal`, `package`,
30707
+ * …). An unknown name simply never matches and reports nothing — it is not an
30708
+ * error, because a rule may legitimately name a class this camera's model does
30709
+ * not emit.
30710
+ *
30711
+ * The counts are exposed to {@link TimelapseTemplateSchema} as:
30712
+ * - `{{detections}}` — total over the reported classes
30713
+ * - `{{detectionSummary}}` — `2 persone, 1 veicolo`
30714
+ * - `{{count_person}}` / `{{count_vehicle}}` / `{{count_animal}}` / … —
30715
+ * one per class, `count_` + the class name
30716
+ *
30717
+ * With NO custom body template the summary is appended to the derived body, and
30718
+ * only when the total is non-zero: a nightly `0 rilevamenti` is a line nobody
30719
+ * reads. With a custom template the operator owns every word — nothing is
30720
+ * appended, so `{{detectionSummary}}` is how he asks for it.
30721
+ */
30722
+ var ReportClassesField = array(string().min(1).max(40)).max(20);
30723
+ /**
30154
30724
  * Client-supplied timelapse-rule fields. The server stamps id / createdBy /
30155
30725
  * createdAt / updatedAt / ownerUserId / lastGeneratedAt — none of them appear
30156
30726
  * here (see the ownership note above).
@@ -30170,9 +30740,30 @@ var TimelapseRuleInputSchema = object({
30170
30740
  cadenceSec: CadenceSecField.default(15),
30171
30741
  /** Output frames per second of the assembled mp4 (predecessor parity). */
30172
30742
  framerate: FramerateField.default(10),
30743
+ /**
30744
+ * Explicit dense cadence — see {@link DenseCadenceSecField}. Absent ⇒ derived
30745
+ * as `max(1s, cadenceSec / 30)`, which is what every rule written before this
30746
+ * field gets.
30747
+ */
30748
+ denseCadenceSec: DenseCadenceSecField.optional(),
30749
+ /** Output-seconds guarantee per detection range — see {@link MinDwellSecField}. */
30750
+ minDwellSec: MinDwellSecField.optional(),
30173
30751
  /** `notification-output` targets the finished video/thumbnail is sent to. */
30174
30752
  targets: TargetsField,
30175
30753
  template: TimelapseTemplateSchema.optional(),
30754
+ /**
30755
+ * Caption on the notification's PREVIEW FRAME — see {@link PreviewTextField}
30756
+ * and {@link DEFAULT_TIMELAPSE_PREVIEW_TEXT}.
30757
+ *
30758
+ * Deliberately NOT part of {@link TimelapseTemplateSchema}: that object is
30759
+ * the notification's title/body, and clearing it (`template: null`) must not
30760
+ * silently clear the caption too.
30761
+ */
30762
+ previewText: PreviewTextField.optional(),
30763
+ /** Still or animation — see {@link PreviewModeField}. */
30764
+ previewMode: PreviewModeField.default("image"),
30765
+ /** Classes the notification counts — see {@link ReportClassesField}. */
30766
+ reportClasses: ReportClassesField.optional(),
30176
30767
  /** Canonical notification priority ordinal (1..5); per-target overridable. */
30177
30768
  priority: PriorityField.default(3)
30178
30769
  });
@@ -30183,8 +30774,13 @@ object({
30183
30774
  schedule: NcScheduleSchema.optional(),
30184
30775
  cadenceSec: CadenceSecField.optional(),
30185
30776
  framerate: FramerateField.optional(),
30777
+ denseCadenceSec: DenseCadenceSecField.optional(),
30778
+ minDwellSec: MinDwellSecField.optional(),
30186
30779
  targets: TargetsField.optional(),
30187
30780
  template: TimelapseTemplateSchema.nullable().optional(),
30781
+ previewText: PreviewTextField.optional(),
30782
+ previewMode: PreviewModeField.optional(),
30783
+ reportClasses: ReportClassesField.optional(),
30188
30784
  priority: PriorityField.optional()
30189
30785
  });
30190
30786
  TimelapseRuleInputSchema.extend({
@@ -30196,10 +30792,28 @@ TimelapseRuleInputSchema.extend({
30196
30792
  */
30197
30793
  ownerUserId: string().optional(),
30198
30794
  /**
30199
- * Epoch-ms of the last successful generation — the 1-hour re-generation
30200
- * guard's durable state (predecessor parity). Absent = never generated.
30795
+ * Epoch-ms of the NEWEST successful generation across every camera of this
30796
+ * rule. What a UI shows, and the compatibility floor for
30797
+ * {@link readTimelapseGeneratedAt}. Absent = never generated.
30201
30798
  */
30202
30799
  lastGeneratedAt: number().optional(),
30800
+ /**
30801
+ * PER-CAMERA generation state, keyed by `String(deviceId)` — the
30802
+ * re-generation guard's real durable state.
30803
+ *
30804
+ * One rule covers several cameras and each renders its own video, so a rule
30805
+ * -wide stamp is wrong in the direction that DESTROYS work: camera A
30806
+ * succeeding at 06:05 tells camera B, whose render failed, that it is
30807
+ * already done — and B's night is gone for good, because the window will not
30808
+ * come back.
30809
+ *
30810
+ * ADDITIVE, so the migration is free: a row written before this field simply
30811
+ * has no map, and {@link readTimelapseGeneratedAt} falls back to
30812
+ * {@link TimelapseRuleSchema.shape.lastGeneratedAt}. Reading an old row as
30813
+ * "never generated" would re-render and re-notify every camera of every rule
30814
+ * once, on the deploy that shipped the map.
30815
+ */
30816
+ generatedByDevice: record(string(), number()).optional(),
30203
30817
  /** userId of the caller who created the rule (server-stamped). */
30204
30818
  createdBy: string(),
30205
30819
  createdAt: number(),
@@ -30250,25 +30864,32 @@ object({
30250
30864
  var NativeLeaseAdmissionSchema = _enum(["all", "inferred"]);
30251
30865
  object({
30252
30866
  /**
30253
- * How long a retained native frame is served before it counts as a miss.
30867
+ * How many delivered frames the worker HOLDS at once, waiting for each one's
30868
+ * detection result.
30869
+ *
30870
+ * This replaced a TTL on 2026-08-13, and the replacement is the whole point:
30871
+ * a time window was never related to the event the pixels were waiting for.
30872
+ * A held frame now lives from delivery until the runner has its `FrameResult`
30873
+ * — at which moment the runner cuts the subject tiles it actually wanted and
30874
+ * releases the frame. The bound exists only so a runner that stops answering
30875
+ * cannot pin RAM: above it the OLDEST held frame is dropped and counted.
30254
30876
  *
30255
- * Must cover the FULL late-crop horizon: detection inference + the
30256
- * cross-process inference-result hop to hub post-analysis + tracking + the
30257
- * tRPC crop round-trip back. Below ~500 ms the busiest cameras' subject crops
30258
- * outrun it and fall back to the ≤640 detection frame; above ~3 s the resident
30259
- * RAM per busy camera grows linearly with no measured hit-rate gain.
30877
+ * Sizing: the steady state is `inferenceLatency × deliveredFps`, measured at
30878
+ * 40-160 ms × ≤25 fps = 1-4 frames. The default leaves headroom for a hiccup
30879
+ * without ever approaching the old resident set (43 frames × 24.9 MB at 4K).
30880
+ * Raising it does not buy hit rate — it buys tolerance for a slow runner, and
30881
+ * `holdOverflow` on the metrics line is what says you need it.
30260
30882
  */
30261
- ttlMs: number().int().min(250).max(1e4),
30883
+ holdFrames: number().int().min(1).max(64),
30262
30884
  /**
30263
30885
  * Hard per-decode-worker RAM ceiling for retained native frames, in MB.
30264
30886
  *
30265
- * Intended as a SAFETY ceiling with the TTL as the effective cap — but check
30266
- * which one is actually binding before reasoning from that. At the shipped
30267
- * 1024 MB and a 2 800 ms TTL, a 4K camera hits the CEILING first (~43 frames
30268
- * at ~24 MB each) and the TTL never gets to expire anything; `leaseMb` /
30269
- * `leaseFrames` on the metrics line say which. When the ceiling binds, a
30270
- * change that admits fewer frames buys retention WINDOW at constant RAM
30271
- * rather than giving RAM back — lower this knob if RAM is what you wanted.
30887
+ * Since 2026-08-13 this is a SAFETY ceiling and nothing else: `holdFrames`
30888
+ * is what decides how much is held, and the ceiling is the number above which
30889
+ * something is wrong. Before that it was the effective cap — at 1024 MB with
30890
+ * a 2 800 ms TTL a 4K camera sat pinned at `leaseMb:1020, leaseFrames:43`
30891
+ * with the TTL expiring nothing, which is exactly the confusion the hold
30892
+ * removes. `leaseMb` / `leaseFrames` still say what is resident.
30272
30893
  * `0` DISABLES the lease entirely and falls the worker back to the tiny
30273
30894
  * leak-prone GPU surface ring (~85% crop miss; that is what the lease exists
30274
30895
  * to replace).
@@ -30294,22 +30915,45 @@ object({
30294
30915
  * there is the signal that some caller names frames outside the inference set
30295
30916
  * and that this must go back to `all`.
30296
30917
  */
30297
- admission: NativeLeaseAdmissionSchema
30918
+ admission: NativeLeaseAdmissionSchema,
30919
+ /**
30920
+ * RAM ceiling per decode worker, in MB, for the SUBJECT TILES — the
30921
+ * compressed native crops the worker cuts at the moment a frame's detection
30922
+ * result arrives, and keeps long after the frame itself is freed.
30923
+ *
30924
+ * This is the knob that replaced the old retention window, and it buys about
30925
+ * three orders of magnitude more of it: a tile is one subject at native
30926
+ * resolution, JPEG-encoded (~60-120 KB on a 4K person), against ~24.9 MB for
30927
+ * the frame it was cut from. A frame on which nothing was detected costs
30928
+ * nothing at all, which is the real change — the old lease paid per FRAME and
30929
+ * was interrogated per SUBJECT.
30930
+ *
30931
+ * `0` DISABLES tiles, leaving only the hold window and the ≤640 RAM
30932
+ * fallback — i.e. the pre-2026-08-13 miss profile. Set it there only to
30933
+ * reproduce that.
30934
+ */
30935
+ tileBudgetMb: number().int().min(0).max(1024)
30298
30936
  });
30299
30937
  /**
30300
- * The values in force when the operator has set nothing — byte-for-byte the
30301
- * constants the decode worker shipped with as env-var defaults, so making these
30302
- * settings changed no behaviour on the day it landed.
30938
+ * The values in force when the operator has set nothing.
30939
+ *
30940
+ * `budgetMb` stays at 1024 on the day the hold landed, deliberately: it stopped
30941
+ * being the retention window and became the OOM ceiling, and lowering a ceiling
30942
+ * in the same change that redefines it would make a regression and a retune
30943
+ * indistinguishable. Cut it once `tileHits` / `holdOverflow` have been read on
30944
+ * live traffic.
30303
30945
  */
30304
30946
  var DEFAULT_NATIVE_LEASE_SETTINGS = {
30305
- ttlMs: 1200,
30947
+ holdFrames: 8,
30306
30948
  budgetMb: 1024,
30307
30949
  activityMs: 15e3,
30950
+ tileBudgetMb: 64,
30308
30951
  admission: "inferred"
30309
30952
  };
30310
- DEFAULT_NATIVE_LEASE_SETTINGS.ttlMs;
30953
+ DEFAULT_NATIVE_LEASE_SETTINGS.holdFrames;
30311
30954
  DEFAULT_NATIVE_LEASE_SETTINGS.budgetMb;
30312
30955
  DEFAULT_NATIVE_LEASE_SETTINGS.activityMs;
30956
+ DEFAULT_NATIVE_LEASE_SETTINGS.tileBudgetMb;
30313
30957
  DEFAULT_NATIVE_LEASE_SETTINGS.admission;
30314
30958
  //#endregion
30315
30959
  //#region src/adapters/adapter.ts
@@ -31973,10 +32617,10 @@ async function assembleAi(deps) {
31973
32617
  registrations,
31974
32618
  runtimeProvider
31975
32619
  };
31976
- const { UsageStore } = await Promise.resolve().then(() => require("./usage-store-DK494_zK.js")).then((n) => n.usage_store_exports);
32620
+ const { UsageStore } = await Promise.resolve().then(() => require("./usage-store-8hfWI98H.js")).then((n) => n.usage_store_exports);
31977
32621
  const store = new ProfileStore(deps.settingsPort);
31978
32622
  const defaults = new DefaultsStore(deps.settingsPort);
31979
- const usage = new UsageStore(deps.settingsPort);
32623
+ const usage = new UsageStore(deps.settingsPort, Date.now, deps.logger.child("llm-usage"));
31980
32624
  await store.init();
31981
32625
  await defaults.init();
31982
32626
  await usage.init();