@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.mjs CHANGED
@@ -7256,8 +7256,31 @@ var AdoptionJobSchema = object({
7256
7256
  error: string().nullable()
7257
7257
  });
7258
7258
  /**
7259
- * Per-camera FUNCTION SWITCHES — the one coherent on/off surface over the
7260
- * pipeline functions an operator thinks in terms of.
7259
+ * Per-camera FUNCTION SWITCHES.
7260
+ *
7261
+ * ## The aggregate group is being withdrawn — the BADGE is not (D113)
7262
+ *
7263
+ * This file shipped as "the one coherent on/off surface over the pipeline
7264
+ * functions an operator thinks in terms of". The operator's verdict on
7265
+ * 2026-08-12 was that the coherent surface bought complexity and no clarity:
7266
+ * every function already had a settings page of its own, and a second place to
7267
+ * turn it off is a second place to look. Each switch is going back to its own
7268
+ * component's original options — detection to the detection-pipeline wrapper
7269
+ * binding, audio analysis to its own, recording to `RecordingConfig.enabled`
7270
+ * (which was always first-class; the switch was a veneer over
7271
+ * `recording.setDeviceConfig`), notifications to a notification-center
7272
+ * per-device setting, the two camera planes to their own components.
7273
+ *
7274
+ * What survives is {@link composeSwitchedOff}: `CameraStatus.switchedOff`, the
7275
+ * thing that lets a status surface say DISABLED instead of BROKEN, recomposed
7276
+ * straight from the authorities with no group in the middle. That rule was
7277
+ * never about a control panel.
7278
+ *
7279
+ * Everything else here — {@link CAMERA_SWITCH_CATALOG}, {@link CameraSwitch},
7280
+ * {@link deriveCameraSwitches}, the `pipelineOrchestrator.getCameraSwitches` /
7281
+ * `setCameraSwitch` pair — is a COMPATIBILITY surface for as long as deployed
7282
+ * viewers (v1.0.305) and the admin UI still call it. It is deleted when they
7283
+ * stop; nothing new may be built on it.
7261
7284
  *
7262
7285
  * ## This file adds no state
7263
7286
  *
@@ -7608,7 +7631,15 @@ var RecordingConfigSchema = object({
7608
7631
  * Each completed/failed run also lands one durable ops-log row on its owning
7609
7632
  * addon surface.
7610
7633
  */
7634
+ /**
7635
+ * `queued` exists because the recorder mover is SINGLE-FLIGHT and an operator
7636
+ * rebalance enqueues one job per (camera, profile). Refusing the second job —
7637
+ * what the engine did before — turned a fifteen-camera rebalance into fifteen
7638
+ * manual retries. Queued jobs run FIFO; a queued job that is cancelled never
7639
+ * runs at all.
7640
+ */
7611
7641
  var RelocateJobStateSchema = _enum([
7642
+ "queued",
7612
7643
  "running",
7613
7644
  "done",
7614
7645
  "failed",
@@ -7643,6 +7674,15 @@ var RelocateFootageInputSchema = object({
7643
7674
  /** Limits relocation to the logical profile class. Omit only for the
7644
7675
  * pre-orchestration compatibility path. */
7645
7676
  footageClass: RelocateFootageClassSchema.optional(),
7677
+ /** Scope the move to ONE camera. Absent = every camera on the source, which
7678
+ * is what a whole-disk drain means. The rebalance path always sets it: its
7679
+ * unit is a (camera, profile) pile, not a disk. */
7680
+ deviceId: number().int().optional(),
7681
+ /** Scope the move to specific segment profiles (`high` / `mid` / `low`).
7682
+ * Finer than `footageClass`, which cannot separate high from mid — and the
7683
+ * placement plan assigns those two independently, so a rebalance that could
7684
+ * only say "recordings" would move footage the plan never asked to move. */
7685
+ profiles: array(string()).optional(),
7646
7686
  /** Copy throttle in MB/s (default 40) — the drain is a background chore,
7647
7687
  * never allowed to starve live writers. */
7648
7688
  throttleMbps: number().min(1).max(1e3).optional()
@@ -7778,6 +7818,21 @@ var StorageLocationSchema = object({
7778
7818
  nodeId: string().optional(),
7779
7819
  isDefault: boolean().default(false),
7780
7820
  isSystem: boolean().default(false),
7821
+ /**
7822
+ * Operator opt-in: whether consumers that BALANCE across several locations
7823
+ * of a type may write here. Recordings reads it today; event media and
7824
+ * backups are the next consumers, which is why the flag lives on the
7825
+ * location rather than in any one addon's store — nothing has to be
7826
+ * extended to add the next consumer.
7827
+ *
7828
+ * OPTIONAL, and ABSENT MEANS ACTIVE. Every location persisted before the
7829
+ * flag existed reads back with no flag and keeps working exactly as before;
7830
+ * that is the whole compat story, and it is why no migration ships with it.
7831
+ * A newly CREATED sibling is stamped `false` by the orchestrator (creating a
7832
+ * disk must not silently start writing to it); the default of a type is
7833
+ * always stamped `true`.
7834
+ */
7835
+ enabled: boolean().optional(),
7781
7836
  /** COMPUTED at read time by the orchestrator (statfs of the backing volume
7782
7837
  * for node-local locations it can reach) — never persisted, absent when the
7783
7838
  * volume is remote/unreachable. The single capacity truth every UI reads. */
@@ -12080,7 +12135,8 @@ method(object({
12080
12135
  }), EmbeddingResultSchema), method(object({ text: string() }), EmbeddingResultSchema), method(_void(), EmbeddingInfoSchema);
12081
12136
  /**
12082
12137
  * filesystem-browse — per-node capability for browsing the node's local
12083
- * filesystem, sandboxed to operator-configured allowed roots. Used by the
12138
+ * filesystem. Reads are unconfined (whole filesystem, from `/` down); WRITES
12139
+ * are sandboxed to operator-configured allowed roots (D115). Used by the
12084
12140
  * admin "Add filesystem location" flow to pick a node + path. `mode:'per-node'`
12085
12141
  * (one provider per node); the hub calls it with `{nodeId}` so the codegen
12086
12142
  * routes to that exact node (default `nodeIdMode:'routing'`).
@@ -13938,6 +13994,13 @@ var MaskGridDimsSchema = object({
13938
13994
  * `package-event` are pure trigger kinds (no urgency dimension). Extending
13939
13995
  * this one field keeps the schema additive — a rule still declares exactly
13940
13996
  * one trigger.
13997
+ *
13998
+ * AUDIO rules add no member here, for the reason occupancy added none: the
13999
+ * enum is mirrored by hand in the viewer (`scripts/check-viewer-condition-
14000
+ * mirror.ts` fails the build on a member the app cannot render) and every
14001
+ * member costs a release train. A sustained-sound rule is therefore an
14002
+ * `immediate` rule carrying {@link NcConditions.audio} — the condition is the
14003
+ * trigger discriminator, exactly as `occupancy` is on `device-event`.
13941
14004
  */
13942
14005
  var NcDeliverySchema = _enum([
13943
14006
  "immediate",
@@ -13952,15 +14015,32 @@ var NcDeliverySchema = _enum([
13952
14015
  * depend on a provider's raw event name or payload shape.
13953
14016
  */
13954
14017
  var NcSystemEventKindSchema = _enum([
13955
- "camera-online",
13956
- "camera-offline",
14018
+ "device-online",
14019
+ "device-offline",
14020
+ "device-disabled",
14021
+ "device-enabled",
13957
14022
  "stream-online",
13958
14023
  "stream-offline",
13959
14024
  "node-online",
13960
14025
  "node-offline",
13961
14026
  "addon-update-available",
13962
- "server-update-available"
14027
+ "server-update-available",
14028
+ "alarm-triggered",
14029
+ "alarm-armed",
14030
+ "alarm-disarmed",
14031
+ "camera-online",
14032
+ "camera-offline",
14033
+ "camera-disabled",
14034
+ "camera-enabled"
14035
+ ]);
14036
+ /** The legacy tail of {@link NcSystemEventKindSchema} — see its docblock. */
14037
+ var NC_LEGACY_SYSTEM_EVENT_KINDS = new Set([
14038
+ "camera-online",
14039
+ "camera-offline",
14040
+ "camera-disabled",
14041
+ "camera-enabled"
13963
14042
  ]);
14043
+ NcSystemEventKindSchema.options.filter((kind) => !NC_LEGACY_SYSTEM_EVENT_KINDS.has(kind));
13964
14044
  /**
13965
14045
  * One coherent system-event condition. `kinds` is the required opt-in safety
13966
14046
  * gate; the remaining lists are optional narrowing filters relevant to the
@@ -13969,6 +14049,18 @@ var NcSystemEventKindSchema = _enum([
13969
14049
  var NcSystemEventConditionSchema = object({
13970
14050
  kinds: array(NcSystemEventKindSchema).min(1),
13971
14051
  deviceIds: array(number().int()).min(1).optional(),
14052
+ /**
14053
+ * Narrow a `device-*` kind to these device TYPES (`DeviceType` values —
14054
+ * `camera`, `switch`, `sensor`, `container`, …). Absent = every type, which
14055
+ * is what a liveness rule means when nobody said otherwise.
14056
+ *
14057
+ * This is where "only my cameras" is expressed, and it lives on the rule for
14058
+ * one reason: the intake cannot know which devices this household cares
14059
+ * about, and a producer-side filter is one no operator can change. Fails
14060
+ * CLOSED — a subject whose device type is unknown (an id the device mirror
14061
+ * does not carry) matches no `deviceTypes` list.
14062
+ */
14063
+ deviceTypes: array(string().min(1)).min(1).optional(),
13972
14064
  nodeIds: array(string().min(1)).min(1).optional(),
13973
14065
  packageNames: array(string().min(1)).min(1).optional()
13974
14066
  });
@@ -14019,6 +14111,47 @@ var NcOccupancyConditionSchema = object({
14019
14111
  sustainSeconds: number().int().min(0).max(3600).default(15)
14020
14112
  });
14021
14113
  /**
14114
+ * Audio condition (IMMEDIATE trigger) — a rule on SOUND, not on a picture.
14115
+ *
14116
+ * Operator-approved vocabulary (2026-08-12, option A — the same one the
14117
+ * reference notifier uses, so an operator moving between them re-uses what
14118
+ * they already know): a rule matches when, over a sampling window of
14119
+ * `samplingSeconds`, at least `hitPercent`% of the audio samples in that
14120
+ * window are HITS. A sample is a hit when it satisfies BOTH present filters:
14121
+ *
14122
+ * - `dbThreshold` — its level is at or above this many dBFS (see
14123
+ * {@link NC_AUDIO_DBFS_FLOOR}: negative-going, `0` = full scale);
14124
+ * - `labels` — the classifier put at least one of these labels on it.
14125
+ *
14126
+ * Both are OPTIONAL and independent, which is the point of the shape: a
14127
+ * loudness rule ("something loud at 3am") needs no model to be right, and a
14128
+ * label rule ("a dog barked") needs no threshold. **Fail-closed when NEITHER
14129
+ * is given** — a window in which every sample is trivially a hit would fire on
14130
+ * silence, so the engine refuses such a condition rather than notifying on
14131
+ * nothing (the schema cannot express "at least one of" without becoming a
14132
+ * ZodEffects the cap path would have to special-case).
14133
+ *
14134
+ * `hitPercent` is over the samples the window actually HOLDS, and the window
14135
+ * must be FULL before it can match — a window that has been open for two
14136
+ * seconds of its ten is 100% of nothing, and firing on it would make
14137
+ * `samplingSeconds` decorative.
14138
+ *
14139
+ * Labels are the audio macro classes (`AUDIO_MACRO_LABELS` / the NC taxonomy's
14140
+ * `audio-*` ids). Both spellings are accepted — the matcher normalizes the
14141
+ * `audio-` prefix away on both sides, so a picker that offers taxonomy ids and
14142
+ * an operator who typed `dog` mean the same thing.
14143
+ */
14144
+ var NcAudioConditionSchema = object({
14145
+ /** Audio macro labels; absent = any sound (level-only rule). */
14146
+ labels: array(string().min(1)).min(1).optional(),
14147
+ /** Level floor in dBFS (negative-going, `0` = full scale); absent = any level. */
14148
+ dbThreshold: number().min(-96).max(0).optional(),
14149
+ /** Percentage of the window's samples that must be hits (1–100). */
14150
+ hitPercent: number().int().min(1).max(100).default(60),
14151
+ /** Length of the sampling window in seconds. */
14152
+ samplingSeconds: number().int().min(1).max(300).default(10)
14153
+ });
14154
+ /**
14022
14155
  * Which zone-crossing DIRECTION a rule accepts (`ObjectEvent.zoneCrossing`).
14023
14156
  *
14024
14157
  * The values are not symmetric, and deliberately so — the absent value has to
@@ -14291,7 +14424,33 @@ var NcConditionsSchema = object({
14291
14424
  * threshold and holds for `sustainSeconds`. Fail-closed on missing
14292
14425
  * substrate (no snapshot / missing zone). See {@link NcOccupancyCondition}.
14293
14426
  */
14294
- occupancy: NcOccupancyConditionSchema.optional()
14427
+ occupancy: NcOccupancyConditionSchema.optional(),
14428
+ /**
14429
+ * IMMEDIATE only. Sustained-sound matcher — `hitPercent` of the samples in a
14430
+ * `samplingSeconds` window clear the optional `dbThreshold` and carry one of
14431
+ * the optional `labels`. Fail-closed on missing substrate (no audio samples,
14432
+ * a window that is not full yet, neither filter given). See
14433
+ * {@link NcAudioCondition}.
14434
+ *
14435
+ * Presence of this key is what makes a rule an AUDIO rule: the engine fires
14436
+ * it ONLY on a confirmed audio window, and a rule carrying it never fires on
14437
+ * a detection, a track or a device event (the same fail-closed pairing
14438
+ * `occupancy` has with the `device-event` trigger). That is how audio labels
14439
+ * leave `classes`: an audio rule names its sounds HERE, and the legacy path
14440
+ * (an `immediate` rule naming an `audio-*` class, one notification per
14441
+ * classified sample) stays exactly as it was for rules that already use it.
14442
+ *
14443
+ * NOT in {@link NC_CONDITION_CATALOG} yet, and that is the sequencing rule
14444
+ * rather than an oversight: the viewer mirrors the descriptor enums BY HAND
14445
+ * (`camstack/src/data/notification-center.ts`, guarded by
14446
+ * `scripts/check-viewer-condition-mirror.ts`) and its rule editor STRIPS the
14447
+ * condition fields it does not know when a rule is saved from the phone.
14448
+ * Publishing an editor for a condition the app cannot round-trip is how an
14449
+ * operator loses a rule's conditions by opening it — so the descriptor, the
14450
+ * admin widget and the viewer mirror land together (P2 + P3), and only then
14451
+ * does an audio rule become authorable.
14452
+ */
14453
+ audio: NcAudioConditionSchema.optional()
14295
14454
  });
14296
14455
  /** One delivery target: a `notification-output` Target ref + passthrough params. */
14297
14456
  var NcRuleTargetSchema = object({
@@ -14405,6 +14564,73 @@ var NcThrottleSchema = object({
14405
14564
  */
14406
14565
  granularity: NcThrottleGranularitySchema.optional()
14407
14566
  });
14567
+ /**
14568
+ * How long the confirm gate may hold ONE notification, and how big the picture
14569
+ * it judges may be.
14570
+ *
14571
+ * The clamp is the product decision, not a coincidence of the model: p50 was
14572
+ * 4.9 s warm and 15.3 s cold against qwen3-vl-8b, and a notification that
14573
+ * arrives after the visitor has gone is not a notification. 448 px was enough
14574
+ * to score 16/16 on the operator's parking scenario — bigger costs latency and
14575
+ * tokens for pixels the model pools away.
14576
+ */
14577
+ var NC_CONFIRM_MIN_TIMEOUT_MS = 1e3;
14578
+ var NC_CONFIRM_MAX_TIMEOUT_MS = 2e4;
14579
+ var NC_CONFIRM_DEFAULT_TIMEOUT_MS = 8e3;
14580
+ /** Comparison the model's COUNT must satisfy for the notification to fire. */
14581
+ var NcConfirmExpectSchema = object({
14582
+ op: _enum([
14583
+ ">=",
14584
+ ">",
14585
+ "<=",
14586
+ "<",
14587
+ "=="
14588
+ ]),
14589
+ count: number().int().min(0).max(1e3)
14590
+ });
14591
+ /**
14592
+ * AI CONFIRM — a vision model looks at the picture this notification is about
14593
+ * to ship and says whether it agrees with the rule.
14594
+ *
14595
+ * It runs AFTER the attachments resolve, deliberately: the crop JUDGED is the
14596
+ * crop SHIPPED (D52). A verdict about a different pixel rectangle than the one
14597
+ * on the operator's phone is not a verdict about this notification.
14598
+ *
14599
+ * FAIL-OPEN is the only safe default. A gate that cannot reach its model, or
14600
+ * whose model is cold, must not silence a camera — so `onTimeout: 'fire'` is
14601
+ * the default and every fail-open is COUNTED, because a gate that always fails
14602
+ * open looks in the log exactly like a gate that works.
14603
+ *
14604
+ * Every field is `.optional()` rather than relied on as a Zod default at the
14605
+ * runtime seam: a Zod default does NOT run on the addon→addon cap path (three
14606
+ * production failures in one day), so the gate reads absent as the constant
14607
+ * above rather than trusting a parse it may never have seen.
14608
+ */
14609
+ var NcConfirmSchema = object({
14610
+ /** Off unless asked for. An absent `confirm` and `enabled:false` are the
14611
+ * same thing, and both mean "deliver exactly as before". */
14612
+ enabled: boolean().default(false),
14613
+ /** Explicit vision profile; absent = the `purpose:'vision'` cluster default. */
14614
+ profileId: string().optional(),
14615
+ /**
14616
+ * The operator's question, in his own words. Absent = a question derived
14617
+ * from the rule (its class and its expectation).
14618
+ *
14619
+ * NEVER composed with text READ OUT OF THE FRAME. The model reads OSD
14620
+ * banners, signage and plates as instructions if you let them reach the
14621
+ * prompt — proven live — so the authoritative contract stays in the system
14622
+ * turn and only rule-authored words land here.
14623
+ */
14624
+ prompt: string().max(1e3).optional(),
14625
+ /** Fire only when the model's count satisfies this. Absent = the model's
14626
+ * own boolean verdict decides. */
14627
+ expect: NcConfirmExpectSchema.optional(),
14628
+ timeoutMs: number().int().min(NC_CONFIRM_MIN_TIMEOUT_MS).max(NC_CONFIRM_MAX_TIMEOUT_MS).default(NC_CONFIRM_DEFAULT_TIMEOUT_MS),
14629
+ /** What a timeout / unreachable model MEANS. `fire` (default) = fail-open. */
14630
+ onTimeout: _enum(["fire", "suppress"]).default("fire"),
14631
+ /** Longest edge the judged image is downscaled to before it is sent. */
14632
+ maxImagePx: number().int().min(64).max(2048).default(448)
14633
+ });
14408
14634
  /** Client-supplied rule fields (server stamps id/createdBy/createdAt/updatedAt). */
14409
14635
  var NcRuleInputSchema = object({
14410
14636
  name: string().min(1).max(200),
@@ -14465,7 +14691,13 @@ var NcRuleInputSchema = object({
14465
14691
  * `{ cap: 'alarm-panel', method: 'arm', args: { mode: 'away' } }`, the same
14466
14692
  * shape as every other actuation.
14467
14693
  */
14468
- actions: NcRuleActionsSchema.optional()
14694
+ actions: NcRuleActionsSchema.optional(),
14695
+ /**
14696
+ * AI CONFIRM — see {@link NcConfirmSchema}. `.optional()`, never defaulted:
14697
+ * a rule that predates the gate must keep delivering byte-for-byte as it
14698
+ * did, and absent is the only way to say that without a migration.
14699
+ */
14700
+ confirm: NcConfirmSchema.optional()
14469
14701
  });
14470
14702
  /**
14471
14703
  * Partial patch for `updateRule` — any subset of the input fields, plus the
@@ -14476,7 +14708,37 @@ var NcRuleInputSchema = object({
14476
14708
  * still flow through `nc.setRuleTargetEnabled` (owner-checked), never a raw
14477
14709
  * `updateRule` patch.
14478
14710
  */
14479
- var NcRulePatchSchema = NcRuleInputSchema.partial().extend({ disabledTargetIds: array(string()).optional() });
14711
+ var NcRulePatchSchema = NcRuleInputSchema.partial().extend({
14712
+ disabledTargetIds: array(string()).optional(),
14713
+ /**
14714
+ * `.partial()` DOES NOT REMOVE A FIELD'S `.default()`.
14715
+ *
14716
+ * It makes the key optional to SUPPLY; the parse still materialises the
14717
+ * default when the key is absent. And `NcRuleStore.update` merges with
14718
+ * `{ ...existing, ...patch }`, so a materialised key OVERWRITES the stored
14719
+ * one — which made every partial edit destructive:
14720
+ *
14721
+ * nc.updateRule({ throttle }) → conditions reset to `{}`
14722
+ * nc.setRuleTargetEnabled(...) → conditions reset to `{}`
14723
+ * setEnabled(ruleId, false) → conditions reset to `{}`
14724
+ *
14725
+ * A rule scoped to one camera and one zone silently became a rule that
14726
+ * matches EVERY event on EVERY camera, and lost its `media` policy
14727
+ * (zoneCrop / gif / clip / frame) and its `priority` at the same time. Seen
14728
+ * live on 2026-08-12: a rule scoped to device 617 fired on 590 and 615
14729
+ * within a minute of a two-field patch.
14730
+ *
14731
+ * So every defaulted field is re-declared here WITHOUT its default. The
14732
+ * inner defaults still apply when the caller DOES send the key — `{}` for
14733
+ * conditions remains a real instruction ("clear them") — and only the
14734
+ * absent key is now genuinely absent.
14735
+ */
14736
+ enabled: boolean().optional(),
14737
+ conditions: NcConditionsSchema.optional(),
14738
+ media: NcMediaPolicySchema.optional(),
14739
+ throttle: NcThrottleSchema.optional(),
14740
+ priority: number().int().min(1).max(5).optional()
14741
+ });
14480
14742
  /** A persisted rule. */
14481
14743
  var NcRuleSchema = NcRuleInputSchema.extend({
14482
14744
  id: string(),
@@ -14777,6 +15039,25 @@ var NcAlarmSettingsPatchSchema = NcAlarmSettingsSchema.partial();
14777
15039
  * Never authored, never stored — see `alarm-mode-coverage.ts` for why a stored
14778
15040
  * copy would lie the first time a rule is disabled.
14779
15041
  */
15042
+ /**
15043
+ * Why a device a mode NAMES is nonetheless not armed by it.
15044
+ *
15045
+ * Each value is an existing authority, never a new flag (D62): `muted` is the
15046
+ * per-camera notification switch the Notification Center already owns,
15047
+ * `detection-off` is the device's own detection binding being inactive, and
15048
+ * `offline` is the device manager's liveness. A fourth reason would mean a
15049
+ * fourth authority, and inventing one here is how a panel starts disagreeing
15050
+ * with the switches the operator actually used.
15051
+ */
15052
+ var NcAlarmSkipReasonSchema = _enum([
15053
+ "muted",
15054
+ "detection-off",
15055
+ "offline"
15056
+ ]);
15057
+ var NcAlarmSkippedDeviceSchema = object({
15058
+ deviceId: number().int(),
15059
+ reason: NcAlarmSkipReasonSchema
15060
+ });
14780
15061
  var NcAlarmModeCoverageSchema = object({
14781
15062
  mode: AlarmArmModeSchema,
14782
15063
  /** Enabled rules gated on `armed_<mode>`. Zero means the mode does nothing. */
@@ -14784,7 +15065,18 @@ var NcAlarmModeCoverageSchema = object({
14784
15065
  /** At least one covering rule has no device scope, so the mode covers all. */
14785
15066
  allDevices: boolean(),
14786
15067
  /** Ids named by the covering rules. A SUBSET when `allDevices` is true. */
14787
- deviceIds: array(number().int())
15068
+ deviceIds: array(number().int()),
15069
+ /**
15070
+ * Devices this mode NAMES but cannot actually arm, each with the switch that
15071
+ * excludes it.
15072
+ *
15073
+ * "Away armed — 12 cameras" is a promise, and a muted camera among those
15074
+ * twelve makes it false in exactly the way nobody notices until an incident.
15075
+ * Defaulted to `[]` so a coverage answer computed before this field existed
15076
+ * still parses as "nothing known to be skipped" rather than failing the whole
15077
+ * alarm tab.
15078
+ */
15079
+ skippedDevices: array(NcAlarmSkippedDeviceSchema).default([])
14788
15080
  });
14789
15081
  var NcAlarmConfigSchema = object({
14790
15082
  /**
@@ -17583,9 +17875,16 @@ var CameraStatusSchema = object({
17583
17875
  audio: CameraAudioStatusSchema.nullable(),
17584
17876
  recording: CameraRecordingStatusSchema.nullable(),
17585
17877
  /**
17586
- * Per-camera function switches an OPERATOR has turned off
17878
+ * Per-camera functions an OPERATOR has turned off
17587
17879
  * ([D61](../../../../docs/decisions/adr-0067.md)).
17588
17880
  *
17881
+ * Composed from the AUTHORITIES themselves — the wrapper bindings,
17882
+ * `RecordingConfig.enabled`, the notification mute, the broker's audio
17883
+ * policy, the camera's own microphone — via `composeSwitchedOff`, not from
17884
+ * the deprecated `getCameraSwitches` group ([D113](../../../../docs/decisions/adr-0113.md)).
17885
+ * The badge outlives the control panel: the panel was a convenience, this is
17886
+ * the difference between a camera being off and a camera being dead.
17887
+ *
17589
17888
  * This is the difference between DISABLED and BROKEN. A camera whose
17590
17889
  * `detection` block reports zero fps and whose `switchedOff` contains
17591
17890
  * `'object-detection'` was switched off by a person; the same camera with an
@@ -23094,7 +23393,19 @@ var RecordingManifestSchema = object({
23094
23393
  * profiles/subtrees/locations on this node). */
23095
23394
  var RecordingDeviceUsageSchema = object({
23096
23395
  deviceId: number(),
23097
- usedBytes: number()
23396
+ usedBytes: number(),
23397
+ /**
23398
+ * Start of this camera's OLDEST indexed segment, across every profile and
23399
+ * location — the "Oldest footage" column in Recordings → Storage, and the
23400
+ * only honest answer to "is retention actually holding?" per camera.
23401
+ *
23402
+ * `null` = the camera has no footage. OPTIONAL because a recorder that
23403
+ * predates this field omits it entirely, and a hub whose types carry the
23404
+ * field must keep validating that older provider's payload: the framework
23405
+ * (types) and the addon ship on different trains, and the addon is usually
23406
+ * the later of the two.
23407
+ */
23408
+ oldestMs: number().nullable().optional()
23098
23409
  });
23099
23410
  /** Recording storage usage + capacity for one storage location. */
23100
23411
  var RecordingLocationUsageSchema = object({
@@ -23122,6 +23433,57 @@ var RecordingStorageUsageSchema = object({
23122
23433
  locations: array(RecordingLocationUsageSchema)
23123
23434
  });
23124
23435
  /**
23436
+ * The OPERATOR-ARMED half of multi-location recordings (D116).
23437
+ *
23438
+ * The placement plan decides where NEW writes go and moves nothing. A rebalance
23439
+ * is the operator asking for the EXISTING archive to be brought into line with
23440
+ * that plan: one relocate job per (camera, profile) pile that sits on the wrong
23441
+ * location, run FIFO behind the single-flight mover.
23442
+ *
23443
+ * `plan…` and `start…` return the SAME shape deliberately — what the operator
23444
+ * confirms is exactly what gets enqueued, and `jobIds` is the only difference
23445
+ * (empty on the plan).
23446
+ */
23447
+ var RecordingRebalanceMoveSchema = object({
23448
+ deviceId: number(),
23449
+ profile: string(),
23450
+ fromLocationId: string(),
23451
+ toLocationId: string(),
23452
+ bytes: number(),
23453
+ files: number().int()
23454
+ });
23455
+ /** Why a pile that is out of place is staying there. Every refusal is
23456
+ * reported: a rebalance that silently drops a camera reads exactly like one
23457
+ * that had nothing to do. */
23458
+ var RecordingRebalanceSkipReasonSchema = _enum([
23459
+ "unassigned",
23460
+ "target-not-writable",
23461
+ "below-threshold",
23462
+ "no-headroom"
23463
+ ]);
23464
+ var RecordingRebalanceSkipSchema = object({
23465
+ deviceId: number(),
23466
+ profile: string(),
23467
+ fromLocationId: string(),
23468
+ /** The location the plan wants; null when the camera has no assignment. */
23469
+ toLocationId: string().nullable(),
23470
+ bytes: number(),
23471
+ reason: RecordingRebalanceSkipReasonSchema
23472
+ });
23473
+ var RecordingRebalancePlanSchema = object({
23474
+ moves: array(RecordingRebalanceMoveSchema),
23475
+ skipped: array(RecordingRebalanceSkipSchema),
23476
+ bytesToMove: number(),
23477
+ /** Relocate job ids enqueued. Always empty for the plan (dry-run) call. */
23478
+ jobIds: array(string())
23479
+ });
23480
+ var RecordingRebalanceInputSchema = object({
23481
+ /** Copy throttle in MB/s (default 40) — a rebalance is a background chore. */
23482
+ throttleMbps: number().min(1).max(1e3).optional(),
23483
+ /** Ignore piles smaller than this (default 1 GB). */
23484
+ minMoveGb: number().min(0).optional()
23485
+ });
23486
+ /**
23125
23487
  * Result of locating footage at a wall-clock instant for one device/profile.
23126
23488
  * `segment` carries the covering segment's window; `gap` reports the forward
23127
23489
  * nearest covered edge (`null` past the end of footage / when none exists)
@@ -23284,9 +23646,24 @@ method(object({
23284
23646
  }), method(object({ jobId: string() }), RelocateJobSchema.nullable(), { auth: "admin" }), method(object({ jobId: string() }), object({ cancelled: boolean() }), {
23285
23647
  kind: "mutation",
23286
23648
  auth: "admin"
23649
+ }), method(RelocateFootageInputSchema, object({ jobId: string() }), {
23650
+ kind: "mutation",
23651
+ auth: "admin"
23652
+ }), method(object({}), array(RelocateJobSchema).readonly(), {
23653
+ kind: "query",
23654
+ auth: "admin"
23655
+ }), method(object({ jobId: string() }), object({ cancelled: boolean() }), {
23656
+ kind: "mutation",
23657
+ auth: "admin"
23658
+ }), method(RecordingRebalanceInputSchema, RecordingRebalancePlanSchema, {
23659
+ kind: "query",
23660
+ auth: "admin"
23661
+ }), method(RecordingRebalanceInputSchema, RecordingRebalancePlanSchema, {
23662
+ kind: "mutation",
23663
+ auth: "admin"
23287
23664
  });
23288
23665
  /**
23289
- * `recordingExport` cap — render a footage time range into a single downloadable
23666
+ * `recording-export` cap — render a footage time range into a single downloadable
23290
23667
  * MP4 (regular / accelerated / decelerated / timelapse, ± audio), kept for a
23291
23668
  * bounded lifetime with a durable history, auto-expiry, and optional
23292
23669
  * delete-after-download.
@@ -23301,10 +23678,53 @@ method(object({
23301
23678
  */
23302
23679
  /** Playback-speed multiplier for the render (1 = realtime). */
23303
23680
  var ExportSpeedSchema = number().min(.25).max(32);
23681
+ /**
23682
+ * One dense interval, in WALL-CLOCK SECONDS FROM THE EXPORT'S OWN `fromMs`.
23683
+ *
23684
+ * **Wall clock, not ffmpeg's `t`** — and the recorder translates. A caller
23685
+ * derives these bounds from things that happened at a TIME (a track's
23686
+ * `firstSeen`), while `t` runs over the source playlist: the concatenation of
23687
+ * every segment present for the range, with each recording GAP removed. The
23688
+ * two agree only on a window that recorded without one interruption, and only
23689
+ * the render side knows the segments, so the translation lives there
23690
+ * (`export-dense-map.ts`, addon-pipeline).
23691
+ *
23692
+ * It was not always so. These seconds were fed to `between(t,…)` verbatim, and
23693
+ * on a 10 h window holding 29,393 s of footage every range landed late by the
23694
+ * gap accumulated before it — up to 6,607 s, well past EOF. Nothing matched,
23695
+ * the video was a uniform timelapse, and the log line reported the five ranges
23696
+ * that had been ASKED for (2026-08-13, export `57d14363`, camera 615).
23697
+ *
23698
+ * Relative and not absolute epoch, because an absolute epoch would make every
23699
+ * call site responsible for the same subtraction.
23700
+ */
23701
+ var ExportDenseRangeSchema = object({
23702
+ fromSec: number().nonnegative(),
23703
+ toSec: number().nonnegative()
23704
+ }).refine((r) => r.toSec > r.fromSec, { message: "dense range must have toSec > fromSec" });
23705
+ /**
23706
+ * Dense-interval overlay for a timelapse: sample at `dense.everyMs` INSIDE the
23707
+ * listed ranges and at the base `everyMs` everywhere else.
23708
+ *
23709
+ * `everyMs` must be strictly smaller than the base cadence — a dense rate that
23710
+ * is not denser renders a uniform timelapse the operator believes is two-rate.
23711
+ */
23712
+ var ExportDenseSchema = object({
23713
+ everyMs: number().int().positive(),
23714
+ ranges: array(ExportDenseRangeSchema).min(1).max(200)
23715
+ });
23304
23716
  /** Timelapse cadence — sample one source frame per `everyMs`, output at `outputFps`. */
23305
23717
  var ExportTimelapseSchema = object({
23306
23718
  everyMs: number().int().positive(),
23307
- outputFps: number().int().min(1).max(60).optional()
23719
+ outputFps: number().int().min(1).max(60).optional(),
23720
+ /** Optional second, FASTER rate over the intervals that matter. */
23721
+ dense: ExportDenseSchema.optional()
23722
+ }).superRefine((v, ctx) => {
23723
+ if (v.dense !== void 0 && v.dense.everyMs >= v.everyMs) ctx.addIssue({
23724
+ code: ZodIssueCode.custom,
23725
+ message: "dense.everyMs must be strictly smaller than the base everyMs",
23726
+ path: ["dense", "everyMs"]
23727
+ });
23308
23728
  });
23309
23729
  /**
23310
23730
  * Render options. `speed` and `timelapse` are mutually exclusive. `includeAudio`
@@ -23362,6 +23782,19 @@ var ExportDownloadSchema = object({
23362
23782
  url: string(),
23363
23783
  endpoints: array(string())
23364
23784
  });
23785
+ /**
23786
+ * A finished export's bytes, inline.
23787
+ *
23788
+ * `bytes` is the DECODED length — the number the caller bounds and logs
23789
+ * against, so nobody has to infer it from the base64 length.
23790
+ */
23791
+ var ExportBytesSchema = object({
23792
+ base64: string(),
23793
+ contentType: string(),
23794
+ /** Suggested filename, extension included. */
23795
+ name: string(),
23796
+ bytes: number().int().nonnegative()
23797
+ });
23365
23798
  method(object({
23366
23799
  deviceId: number(),
23367
23800
  profile: string(),
@@ -23386,6 +23819,9 @@ method(object({
23386
23819
  }), method(object({ exportId: string() }), ExportDownloadSchema, {
23387
23820
  kind: "query",
23388
23821
  auth: "protected"
23822
+ }), method(object({ exportId: string() }), ExportBytesSchema, {
23823
+ kind: "query",
23824
+ auth: "protected"
23389
23825
  });
23390
23826
  /**
23391
23827
  * scene-monitor — device-scoped reference-region state cap. An operator marks
@@ -28579,6 +29015,12 @@ Object.freeze({
28579
29015
  addonId: null,
28580
29016
  access: "create"
28581
29017
  },
29018
+ "recording.cancelRelocateJob": {
29019
+ capName: "recording",
29020
+ capScope: "system",
29021
+ addonId: null,
29022
+ access: "create"
29023
+ },
28582
29024
  "recording.cancelStorageMigrationMove": {
28583
29025
  capName: "recording",
28584
29026
  capScope: "system",
@@ -28633,6 +29075,12 @@ Object.freeze({
28633
29075
  addonId: null,
28634
29076
  access: "view"
28635
29077
  },
29078
+ "recording.listRelocateJobs": {
29079
+ capName: "recording",
29080
+ capScope: "system",
29081
+ addonId: null,
29082
+ access: "view"
29083
+ },
28636
29084
  "recording.locateSegment": {
28637
29085
  capName: "recording",
28638
29086
  capScope: "system",
@@ -28645,6 +29093,12 @@ Object.freeze({
28645
29093
  addonId: null,
28646
29094
  access: "create"
28647
29095
  },
29096
+ "recording.planStorageRebalance": {
29097
+ capName: "recording",
29098
+ capScope: "system",
29099
+ addonId: null,
29100
+ access: "view"
29101
+ },
28648
29102
  "recording.pruneFootage": {
28649
29103
  capName: "recording",
28650
29104
  capScope: "system",
@@ -28669,6 +29123,12 @@ Object.freeze({
28669
29123
  addonId: null,
28670
29124
  access: "create"
28671
29125
  },
29126
+ "recording.relocateFootage": {
29127
+ capName: "recording",
29128
+ capScope: "system",
29129
+ addonId: null,
29130
+ access: "create"
29131
+ },
28672
29132
  "recording.renderClip": {
28673
29133
  capName: "recording",
28674
29134
  capScope: "system",
@@ -28705,38 +29165,50 @@ Object.freeze({
28705
29165
  addonId: null,
28706
29166
  access: "create"
28707
29167
  },
29168
+ "recording.startStorageRebalance": {
29169
+ capName: "recording",
29170
+ capScope: "system",
29171
+ addonId: null,
29172
+ access: "create"
29173
+ },
28708
29174
  "recordingExport.cancelExport": {
28709
- capName: "recordingExport",
29175
+ capName: "recording-export",
28710
29176
  capScope: "system",
28711
29177
  addonId: null,
28712
29178
  access: "create"
28713
29179
  },
28714
29180
  "recordingExport.createExport": {
28715
- capName: "recordingExport",
29181
+ capName: "recording-export",
28716
29182
  capScope: "system",
28717
29183
  addonId: null,
28718
29184
  access: "create"
28719
29185
  },
28720
29186
  "recordingExport.deleteExport": {
28721
- capName: "recordingExport",
29187
+ capName: "recording-export",
28722
29188
  capScope: "system",
28723
29189
  addonId: null,
28724
29190
  access: "delete"
28725
29191
  },
28726
29192
  "recordingExport.getDownloadUrl": {
28727
- capName: "recordingExport",
29193
+ capName: "recording-export",
28728
29194
  capScope: "system",
28729
29195
  addonId: null,
28730
29196
  access: "view"
28731
29197
  },
28732
29198
  "recordingExport.getExport": {
28733
- capName: "recordingExport",
29199
+ capName: "recording-export",
28734
29200
  capScope: "system",
28735
29201
  addonId: null,
28736
29202
  access: "view"
28737
29203
  },
28738
29204
  "recordingExport.listExports": {
28739
- capName: "recordingExport",
29205
+ capName: "recording-export",
29206
+ capScope: "system",
29207
+ addonId: null,
29208
+ access: "view"
29209
+ },
29210
+ "recordingExport.readExportBytes": {
29211
+ capName: "recording-export",
28740
29212
  capScope: "system",
28741
29213
  addonId: null,
28742
29214
  access: "view"
@@ -30113,6 +30585,104 @@ var FramerateField = number().int().min(1).max(60);
30113
30585
  var TargetsField = array(NcRuleTargetSchema).min(1);
30114
30586
  var PriorityField = number().int().min(1).max(5);
30115
30587
  /**
30588
+ * Explicit override of the DENSE sampling cadence, seconds.
30589
+ *
30590
+ * Absent ⇒ derived as `max(1s, cadenceSec / 30)` — a 30 s base samples every
30591
+ * 1 s inside a detection range. (It was `base / 10` until 2026-08-12, which
30592
+ * made that same base 3 s and rendered a person pass as two frames.)
30593
+ *
30594
+ * THE ARITHMETIC. A detection range of `rangeSec` seconds sampled every
30595
+ * `denseCadenceSec` and played at `framerate` occupies
30596
+ *
30597
+ * outputSeconds = (rangeSec / denseCadenceSec) / framerate
30598
+ *
30599
+ * 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.
30600
+ * Halving this field doubles the frames INSIDE ranges only — the base cadence,
30601
+ * and therefore the length of a quiet night, does not move.
30602
+ *
30603
+ * Floored at {@link TIMELAPSE_DENSE_FLOOR_SEC}: asking for frames faster than
30604
+ * the recording has them returns the same frames, requested twice. Must be
30605
+ * STRICTLY smaller than `cadenceSec` — a dense rate that is not denser renders
30606
+ * a uniform video the operator believes is two-rate — and upsert refuses it
30607
+ * rather than letting the export cap reject the render hours after the window.
30608
+ */
30609
+ var DenseCadenceSecField = number().min(.1).max(3600);
30610
+ /**
30611
+ * Minimum seconds of OUTPUT video each detection range must occupy.
30612
+ *
30613
+ * The operator-facing form of the arithmetic above: instead of solving for a
30614
+ * cadence, state the dwell and let the renderer solve. `minDwellSec: 1` on a
30615
+ * 30 s base at 12 fps turns a 7 s pass into a full second of video by sampling
30616
+ * that range every ~583 ms.
30617
+ *
30618
+ * ONE CADENCE SERVES EVERY RANGE. `ExportDenseSchema.everyMs` is global — the
30619
+ * ranges are terms of a single ffmpeg `select` expression that cannot vary rate
30620
+ * per term — so the MOST DEMANDING (shortest) range sets the rate and longer
30621
+ * ranges are sampled denser than they need. Per-range cadences require a cap
30622
+ * schema change and are the tracked follow-up.
30623
+ *
30624
+ * A range too short to reach the dwell even at {@link TIMELAPSE_DENSE_FLOOR_SEC}
30625
+ * is rendered with every frame that EXISTS and no more: the guarantee is capped
30626
+ * by real footage, never met by duplicating frames into motion that never
30627
+ * happened.
30628
+ */
30629
+ var MinDwellSecField = number().min(0).max(60);
30630
+ /**
30631
+ * Caption burned into the notification's preview frame.
30632
+ *
30633
+ * Same `{{var}}` vocabulary as {@link TimelapseTemplateSchema} (`camera`,
30634
+ * `rule`, `from`, `to`) and rendered by the SAME renderer — a second
30635
+ * templating dialect for one field would be a second thing to explain.
30636
+ *
30637
+ * Absent ⇒ {@link DEFAULT_TIMELAPSE_PREVIEW_TEXT}. An EMPTY STRING is the
30638
+ * operator saying "the frame, no caption" — a distinct, reachable answer, and
30639
+ * the reason this is not `.min(1)`.
30640
+ */
30641
+ var PreviewTextField = string().max(200);
30642
+ /**
30643
+ * Whether the notification's preview is a STILL or a short animation.
30644
+ *
30645
+ * The operator's ask, verbatim: *"inviato come gif o video (come per le altre
30646
+ * rule)"* — his Scrypted advanced-notifier has a `gifRule`, and a ten-hour
30647
+ * night reads better as three seconds of motion than as one frame of it. Both
30648
+ * modes get the SAME treatment (blurred frame, large centred title); `'gif'`
30649
+ * simply applies it to a dozen frames sampled across the render and assembles
30650
+ * them.
30651
+ *
30652
+ * `'image'` is the default and stays the default: a GIF costs a dozen ffmpeg
30653
+ * seeks and a palette pass, and no rule that never asked for one should start
30654
+ * paying that on the deploy that shipped it.
30655
+ *
30656
+ * A GIF that cannot be assembled DEGRADES to the still — never to nothing.
30657
+ */
30658
+ var PreviewModeField = _enum(["image", "gif"]);
30659
+ /**
30660
+ * Which detection classes the notification reports counts for.
30661
+ *
30662
+ * The counts come from the tracks the render ALREADY fetched for its dense-range
30663
+ * plan — no second query — aggregated per class. Absent or empty means "every
30664
+ * class the window actually contained", which is what an operator who never
30665
+ * opened the field wants; a list narrows it (`['person']` on a driveway that
30666
+ * counts cars all night).
30667
+ *
30668
+ * Class names are the tracker's own (`person`, `vehicle`, `animal`, `package`,
30669
+ * …). An unknown name simply never matches and reports nothing — it is not an
30670
+ * error, because a rule may legitimately name a class this camera's model does
30671
+ * not emit.
30672
+ *
30673
+ * The counts are exposed to {@link TimelapseTemplateSchema} as:
30674
+ * - `{{detections}}` — total over the reported classes
30675
+ * - `{{detectionSummary}}` — `2 persone, 1 veicolo`
30676
+ * - `{{count_person}}` / `{{count_vehicle}}` / `{{count_animal}}` / … —
30677
+ * one per class, `count_` + the class name
30678
+ *
30679
+ * With NO custom body template the summary is appended to the derived body, and
30680
+ * only when the total is non-zero: a nightly `0 rilevamenti` is a line nobody
30681
+ * reads. With a custom template the operator owns every word — nothing is
30682
+ * appended, so `{{detectionSummary}}` is how he asks for it.
30683
+ */
30684
+ var ReportClassesField = array(string().min(1).max(40)).max(20);
30685
+ /**
30116
30686
  * Client-supplied timelapse-rule fields. The server stamps id / createdBy /
30117
30687
  * createdAt / updatedAt / ownerUserId / lastGeneratedAt — none of them appear
30118
30688
  * here (see the ownership note above).
@@ -30132,9 +30702,30 @@ var TimelapseRuleInputSchema = object({
30132
30702
  cadenceSec: CadenceSecField.default(15),
30133
30703
  /** Output frames per second of the assembled mp4 (predecessor parity). */
30134
30704
  framerate: FramerateField.default(10),
30705
+ /**
30706
+ * Explicit dense cadence — see {@link DenseCadenceSecField}. Absent ⇒ derived
30707
+ * as `max(1s, cadenceSec / 30)`, which is what every rule written before this
30708
+ * field gets.
30709
+ */
30710
+ denseCadenceSec: DenseCadenceSecField.optional(),
30711
+ /** Output-seconds guarantee per detection range — see {@link MinDwellSecField}. */
30712
+ minDwellSec: MinDwellSecField.optional(),
30135
30713
  /** `notification-output` targets the finished video/thumbnail is sent to. */
30136
30714
  targets: TargetsField,
30137
30715
  template: TimelapseTemplateSchema.optional(),
30716
+ /**
30717
+ * Caption on the notification's PREVIEW FRAME — see {@link PreviewTextField}
30718
+ * and {@link DEFAULT_TIMELAPSE_PREVIEW_TEXT}.
30719
+ *
30720
+ * Deliberately NOT part of {@link TimelapseTemplateSchema}: that object is
30721
+ * the notification's title/body, and clearing it (`template: null`) must not
30722
+ * silently clear the caption too.
30723
+ */
30724
+ previewText: PreviewTextField.optional(),
30725
+ /** Still or animation — see {@link PreviewModeField}. */
30726
+ previewMode: PreviewModeField.default("image"),
30727
+ /** Classes the notification counts — see {@link ReportClassesField}. */
30728
+ reportClasses: ReportClassesField.optional(),
30138
30729
  /** Canonical notification priority ordinal (1..5); per-target overridable. */
30139
30730
  priority: PriorityField.default(3)
30140
30731
  });
@@ -30145,8 +30736,13 @@ object({
30145
30736
  schedule: NcScheduleSchema.optional(),
30146
30737
  cadenceSec: CadenceSecField.optional(),
30147
30738
  framerate: FramerateField.optional(),
30739
+ denseCadenceSec: DenseCadenceSecField.optional(),
30740
+ minDwellSec: MinDwellSecField.optional(),
30148
30741
  targets: TargetsField.optional(),
30149
30742
  template: TimelapseTemplateSchema.nullable().optional(),
30743
+ previewText: PreviewTextField.optional(),
30744
+ previewMode: PreviewModeField.optional(),
30745
+ reportClasses: ReportClassesField.optional(),
30150
30746
  priority: PriorityField.optional()
30151
30747
  });
30152
30748
  TimelapseRuleInputSchema.extend({
@@ -30158,10 +30754,28 @@ TimelapseRuleInputSchema.extend({
30158
30754
  */
30159
30755
  ownerUserId: string().optional(),
30160
30756
  /**
30161
- * Epoch-ms of the last successful generation — the 1-hour re-generation
30162
- * guard's durable state (predecessor parity). Absent = never generated.
30757
+ * Epoch-ms of the NEWEST successful generation across every camera of this
30758
+ * rule. What a UI shows, and the compatibility floor for
30759
+ * {@link readTimelapseGeneratedAt}. Absent = never generated.
30163
30760
  */
30164
30761
  lastGeneratedAt: number().optional(),
30762
+ /**
30763
+ * PER-CAMERA generation state, keyed by `String(deviceId)` — the
30764
+ * re-generation guard's real durable state.
30765
+ *
30766
+ * One rule covers several cameras and each renders its own video, so a rule
30767
+ * -wide stamp is wrong in the direction that DESTROYS work: camera A
30768
+ * succeeding at 06:05 tells camera B, whose render failed, that it is
30769
+ * already done — and B's night is gone for good, because the window will not
30770
+ * come back.
30771
+ *
30772
+ * ADDITIVE, so the migration is free: a row written before this field simply
30773
+ * has no map, and {@link readTimelapseGeneratedAt} falls back to
30774
+ * {@link TimelapseRuleSchema.shape.lastGeneratedAt}. Reading an old row as
30775
+ * "never generated" would re-render and re-notify every camera of every rule
30776
+ * once, on the deploy that shipped the map.
30777
+ */
30778
+ generatedByDevice: record(string(), number()).optional(),
30165
30779
  /** userId of the caller who created the rule (server-stamped). */
30166
30780
  createdBy: string(),
30167
30781
  createdAt: number(),
@@ -30212,25 +30826,32 @@ object({
30212
30826
  var NativeLeaseAdmissionSchema = _enum(["all", "inferred"]);
30213
30827
  object({
30214
30828
  /**
30215
- * How long a retained native frame is served before it counts as a miss.
30829
+ * How many delivered frames the worker HOLDS at once, waiting for each one's
30830
+ * detection result.
30831
+ *
30832
+ * This replaced a TTL on 2026-08-13, and the replacement is the whole point:
30833
+ * a time window was never related to the event the pixels were waiting for.
30834
+ * A held frame now lives from delivery until the runner has its `FrameResult`
30835
+ * — at which moment the runner cuts the subject tiles it actually wanted and
30836
+ * releases the frame. The bound exists only so a runner that stops answering
30837
+ * cannot pin RAM: above it the OLDEST held frame is dropped and counted.
30216
30838
  *
30217
- * Must cover the FULL late-crop horizon: detection inference + the
30218
- * cross-process inference-result hop to hub post-analysis + tracking + the
30219
- * tRPC crop round-trip back. Below ~500 ms the busiest cameras' subject crops
30220
- * outrun it and fall back to the ≤640 detection frame; above ~3 s the resident
30221
- * RAM per busy camera grows linearly with no measured hit-rate gain.
30839
+ * Sizing: the steady state is `inferenceLatency × deliveredFps`, measured at
30840
+ * 40-160 ms × ≤25 fps = 1-4 frames. The default leaves headroom for a hiccup
30841
+ * without ever approaching the old resident set (43 frames × 24.9 MB at 4K).
30842
+ * Raising it does not buy hit rate — it buys tolerance for a slow runner, and
30843
+ * `holdOverflow` on the metrics line is what says you need it.
30222
30844
  */
30223
- ttlMs: number().int().min(250).max(1e4),
30845
+ holdFrames: number().int().min(1).max(64),
30224
30846
  /**
30225
30847
  * Hard per-decode-worker RAM ceiling for retained native frames, in MB.
30226
30848
  *
30227
- * Intended as a SAFETY ceiling with the TTL as the effective cap — but check
30228
- * which one is actually binding before reasoning from that. At the shipped
30229
- * 1024 MB and a 2 800 ms TTL, a 4K camera hits the CEILING first (~43 frames
30230
- * at ~24 MB each) and the TTL never gets to expire anything; `leaseMb` /
30231
- * `leaseFrames` on the metrics line say which. When the ceiling binds, a
30232
- * change that admits fewer frames buys retention WINDOW at constant RAM
30233
- * rather than giving RAM back — lower this knob if RAM is what you wanted.
30849
+ * Since 2026-08-13 this is a SAFETY ceiling and nothing else: `holdFrames`
30850
+ * is what decides how much is held, and the ceiling is the number above which
30851
+ * something is wrong. Before that it was the effective cap — at 1024 MB with
30852
+ * a 2 800 ms TTL a 4K camera sat pinned at `leaseMb:1020, leaseFrames:43`
30853
+ * with the TTL expiring nothing, which is exactly the confusion the hold
30854
+ * removes. `leaseMb` / `leaseFrames` still say what is resident.
30234
30855
  * `0` DISABLES the lease entirely and falls the worker back to the tiny
30235
30856
  * leak-prone GPU surface ring (~85% crop miss; that is what the lease exists
30236
30857
  * to replace).
@@ -30256,22 +30877,45 @@ object({
30256
30877
  * there is the signal that some caller names frames outside the inference set
30257
30878
  * and that this must go back to `all`.
30258
30879
  */
30259
- admission: NativeLeaseAdmissionSchema
30880
+ admission: NativeLeaseAdmissionSchema,
30881
+ /**
30882
+ * RAM ceiling per decode worker, in MB, for the SUBJECT TILES — the
30883
+ * compressed native crops the worker cuts at the moment a frame's detection
30884
+ * result arrives, and keeps long after the frame itself is freed.
30885
+ *
30886
+ * This is the knob that replaced the old retention window, and it buys about
30887
+ * three orders of magnitude more of it: a tile is one subject at native
30888
+ * resolution, JPEG-encoded (~60-120 KB on a 4K person), against ~24.9 MB for
30889
+ * the frame it was cut from. A frame on which nothing was detected costs
30890
+ * nothing at all, which is the real change — the old lease paid per FRAME and
30891
+ * was interrogated per SUBJECT.
30892
+ *
30893
+ * `0` DISABLES tiles, leaving only the hold window and the ≤640 RAM
30894
+ * fallback — i.e. the pre-2026-08-13 miss profile. Set it there only to
30895
+ * reproduce that.
30896
+ */
30897
+ tileBudgetMb: number().int().min(0).max(1024)
30260
30898
  });
30261
30899
  /**
30262
- * The values in force when the operator has set nothing — byte-for-byte the
30263
- * constants the decode worker shipped with as env-var defaults, so making these
30264
- * settings changed no behaviour on the day it landed.
30900
+ * The values in force when the operator has set nothing.
30901
+ *
30902
+ * `budgetMb` stays at 1024 on the day the hold landed, deliberately: it stopped
30903
+ * being the retention window and became the OOM ceiling, and lowering a ceiling
30904
+ * in the same change that redefines it would make a regression and a retune
30905
+ * indistinguishable. Cut it once `tileHits` / `holdOverflow` have been read on
30906
+ * live traffic.
30265
30907
  */
30266
30908
  var DEFAULT_NATIVE_LEASE_SETTINGS = {
30267
- ttlMs: 1200,
30909
+ holdFrames: 8,
30268
30910
  budgetMb: 1024,
30269
30911
  activityMs: 15e3,
30912
+ tileBudgetMb: 64,
30270
30913
  admission: "inferred"
30271
30914
  };
30272
- DEFAULT_NATIVE_LEASE_SETTINGS.ttlMs;
30915
+ DEFAULT_NATIVE_LEASE_SETTINGS.holdFrames;
30273
30916
  DEFAULT_NATIVE_LEASE_SETTINGS.budgetMb;
30274
30917
  DEFAULT_NATIVE_LEASE_SETTINGS.activityMs;
30918
+ DEFAULT_NATIVE_LEASE_SETTINGS.tileBudgetMb;
30275
30919
  DEFAULT_NATIVE_LEASE_SETTINGS.admission;
30276
30920
  //#endregion
30277
30921
  //#region src/adapters/adapter.ts
@@ -31935,10 +32579,10 @@ async function assembleAi(deps) {
31935
32579
  registrations,
31936
32580
  runtimeProvider
31937
32581
  };
31938
- const { UsageStore } = await import("./usage-store-BVa_imkv.mjs").then((n) => n.i);
32582
+ const { UsageStore } = await import("./usage-store-1FrTJdpU.mjs").then((n) => n.i);
31939
32583
  const store = new ProfileStore(deps.settingsPort);
31940
32584
  const defaults = new DefaultsStore(deps.settingsPort);
31941
- const usage = new UsageStore(deps.settingsPort);
32585
+ const usage = new UsageStore(deps.settingsPort, Date.now, deps.logger.child("llm-usage"));
31942
32586
  await store.init();
31943
32587
  await defaults.init();
31944
32588
  await usage.init();