@camstack/types 1.2.236 → 1.2.238

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/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_sleep = require("./sleep-Cqxm5OIN.js");
2
+ const require_sleep = require("./sleep-C0n7gucP.js");
3
3
  const require_event_category = require("./event-category-BVfsrBYA.js");
4
4
  const require_canonical_hash = require("./canonical-hash-CSE4ioRi.js");
5
5
  const require_enums = require("./enums.js");
@@ -27164,13 +27164,14 @@ var vectorStoreCapability = {
27164
27164
  *
27165
27165
  * A device-scoped wrapper COLLECTION (D549 decision 2, D554): every provider a
27166
27166
  * camera has is a SOURCE, and they are listed beside each other — never one
27167
- * substituted for another. The DEFAULT provider (`analytics`, registered by
27168
- * the RECORDER — the addon that owns the footage, D560 — `defaultActive: true`)
27169
- * composes the analytics event log (markers + thumbnails, read over `ctx.api`)
27170
- * with the recorder's own `getPlaybackManifest` — a clip is a time-WINDOW over
27171
- * existing footage, never a separate file. A camera that exposes NATIVE onboard
27172
- * clips (Reolink SD card, a hub's storage, HKSV) adds its own catalog
27173
- * ALONGSIDE that one.
27167
+ * substituted for another, and none of them privileged by name. One source,
27168
+ * `analytics`, is registered by the RECORDER — the addon that owns the
27169
+ * footage, D560 — and composes the analytics event log (markers + thumbnails,
27170
+ * read over `ctx.api`) with the recorder's own `getPlaybackManifest`: a clip
27171
+ * is a time-WINDOW over existing footage, never a separate file. A camera that
27172
+ * exposes NATIVE onboard clips (Reolink SD card, a hub's storage, HKSV) adds
27173
+ * its own catalog ALONGSIDE that one. (`defaultActive` above is the CAP's
27174
+ * auto-bind to cameras, not a ranking among these sources — there is none.)
27174
27175
  *
27175
27176
  * The mount stays per-device (`resolveCapMount` → `device-scoped`), and a
27176
27177
  * device's SOURCES are its BINDINGS: `deviceManager.getBindings(deviceId)` is
@@ -27180,10 +27181,17 @@ var vectorStoreCapability = {
27180
27181
  * native provider, as the hub-local registration and as an
27181
27182
  * `<addonId>@<nodeId>` one (D554 amended 2026-09-20).
27182
27183
  *
27183
- * `listClips` is asked of ONE provider at a time
27184
- * ({@link videoclipsCapability.methods.listClips} `provider`), defaulting to
27185
- * the bound one, which is CamStack on every camera today. It is NOT a union
27186
- * over everything a camera has: *"l'utilizzatore è uno solo"*.
27184
+ * `listClips` is asked of ONE provider at a time, and NAMING it is REQUIRED
27185
+ * ({@link videoclipsCapability.methods.listClips} `provider`, D554 amended). It is not
27186
+ * a union over everything a camera has: *"l'utilizzatore è uno solo"*. There
27187
+ * is no default, because a collection cap's binding set is DERIVED and PLURAL
27188
+ * (D554 amended, `getBindings` step 0) — "the bound one" does not exist to
27189
+ * resolve to, and the one thing that could take its place is a second
27190
+ * authority naming a provider per camera, which D554 decision 3 rejected.
27191
+ * The pick is a SURFACE's to make, from the {@link ClipSourceSchema} rows it
27192
+ * already holds, and it says which one it made (D569 § 1–3).
27193
+ * {@link videoclipsCapability.methods.listSources} is the method that fans out
27194
+ * — one row per source, by construction.
27187
27195
  * {@link videoclipsCapability.methods.getClipPlayback} dispatches by the
27188
27196
  * source namespace inside the clip id, which is why ids are self-contained.
27189
27197
  *
@@ -27454,6 +27462,77 @@ var ClipPlaybackSchema = zod.z.object({
27454
27462
  * which days it asked for and got nothing — "no clips" would be a lie about a
27455
27463
  * card that is full of them.
27456
27464
  */
27465
+ /**
27466
+ * The operator's authorisation to WAKE a sleeping camera for one clip read.
27467
+ *
27468
+ * ONE value, absent by default, and it is a `force`-shaped operator signal in
27469
+ * exactly the sense `snapshot-wake-gate.ts` uses the word: *"`snapshot.getSnapshot`'s
27470
+ * `force` flag, and nothing else… a background caller must never set it…
27471
+ * Stale but honest beats woken"*. A scheduler, a retry, a reconcile and a
27472
+ * prefetch never set it; a surface sets it only behind the same confirm the
27473
+ * "Wake and refresh" gesture uses, and it is refused below 15 % battery
27474
+ * exactly as that gesture is.
27475
+ *
27476
+ * The gate is decided BEFORE `getApi()`, because on UDP the login IS the wake
27477
+ * (D549) — a read that opened a session and then checked would have woken the
27478
+ * camera to find out it was not allowed to.
27479
+ *
27480
+ * **One authorised yes is one wake.** `next-natural` — take the clip the next
27481
+ * time the camera is awake for its own reasons — is deliberately not a member:
27482
+ * it was proposed, it is free on the battery, and the operator declined it on
27483
+ * 2026-09-20 (*"Quando un export viene richiesto si sveglia la camera."*,
27484
+ * D558 "Considered and not taken").
27485
+ */
27486
+ var ClipWakeSchema = zod.z.enum(["authorised"]);
27487
+ /**
27488
+ * Hard ceiling on ONE {@link videoclipsCapability.methods.readClipBytes} — the
27489
+ * same 50 MiB `RECORDING_EXPORT_MAX_READ_BYTES` uses, and for the same second
27490
+ * reason: the envelope is unary, so a base64 payload is held whole (~1.33× its
27491
+ * size) in the provider AND in the caller, on a hub this repo has already
27492
+ * OOM'd once (D9/D18).
27493
+ *
27494
+ * Measured clips sit far below it — 92 KB–2.29 MB for a sub twin, 455 KB for a
27495
+ * 16 s main clip — so the bound bites rarely. "Rarely" is not "never": a long
27496
+ * 4K main twin can exceed it, and above the bound the provider REFUSES with
27497
+ * the size in the message, never truncates. Half a video is worse than an
27498
+ * honest refusal.
27499
+ *
27500
+ * The clean follow-on is a CHUNKED read so a `high` twin of a long clip stops
27501
+ * being refusable at all. That is a later slice, named here so the bound is
27502
+ * not mistaken for a design ceiling.
27503
+ */
27504
+ var VIDEOCLIPS_MAX_READ_BYTES = 50 * 1024 * 1024;
27505
+ /**
27506
+ * A clip's finished bytes, inline — the twin of `recordingExport.readExportBytes`.
27507
+ *
27508
+ * `bytes` is the DECODED length, so nobody infers it from the base64 length,
27509
+ * and `served` says which twin the caller actually got.
27510
+ */
27511
+ var ClipBytesSchema = zod.z.object({
27512
+ base64: zod.z.string(),
27513
+ contentType: zod.z.string(),
27514
+ /** Suggested filename, extension included. */
27515
+ name: zod.z.string(),
27516
+ bytes: zod.z.number().int().nonnegative(),
27517
+ /**
27518
+ * Which twin was actually served — the same contract
27519
+ * {@link ClipPlaybackSchema.served} carries, and REQUIRED here because the
27520
+ * export record persists it: a row read a week later must say the same thing
27521
+ * the panel said at the moment of the tap. A missing main twin is never
27522
+ * served silently as if it were the asked-for quality (D549 15).
27523
+ */
27524
+ served: require_sleep.CamProfileSchema,
27525
+ /**
27526
+ * The DECODED duration of the delivered file, when the fetch measured one.
27527
+ *
27528
+ * A clip fetch verifies its own completion against the catalog row and
27529
+ * retries a materially short pass (D568); this is that measurement, carried
27530
+ * so a consumer can say the same thing rather than re-deriving it. Absent
27531
+ * when the producer did not measure — never zero, which would say the file
27532
+ * is empty.
27533
+ */
27534
+ durationMs: zod.z.number().positive().optional()
27535
+ });
27457
27536
  var ClipSourceAvailabilitySchema = zod.z.object({
27458
27537
  state: zod.z.enum([
27459
27538
  "ok",
@@ -27555,22 +27634,40 @@ var videoclipsCapability = {
27555
27634
  limit: zod.z.number().int().positive().optional(),
27556
27635
  /**
27557
27636
  * WHICH provider to ask — the `addonId` a {@link ClipSourceSchema} row
27558
- * carries, never a source id and never a list.
27637
+ * carries, never a source id and never a list. **Required** (D554 amended).
27559
27638
  *
27560
- * Absent means the device's BOUND provider, which is CamStack on every
27561
- * camera today because that is what `deviceManager.getBindings`
27562
- * answers with. A provider the device is not bound to is refused by
27563
- * name rather than answered by another one (D552's
27564
- * `rejectUnresolvedAddonPin` rule).
27639
+ * A provider the device is not bound to is refused by name rather than
27640
+ * answered by another one (D552's `rejectUnresolvedAddonPin` rule).
27641
+ *
27642
+ * It was optional, documented as "absent means the device's BOUND
27643
+ * provider, which is CamStack on every camera". No code implemented
27644
+ * that. Measured on the live hub 2026-09-20 — device 592, bound to
27645
+ * `recorder` AND `provider-reolink` — a bare call with `limit: 3`
27646
+ * answered SIX rows, three from each source, merged newest-first:
27647
+ * `device-collection-dispatch.ts` simply left the fan-out un-narrowed,
27648
+ * so absence bought the union this method exists not to be, and
27649
+ * `limit` meant `limit × sources`.
27650
+ *
27651
+ * There is nothing to restore the default to. `getBindings` answers a
27652
+ * collection cap with a DERIVED, PLURAL set (D554 amended, step 0);
27653
+ * `setWrapperActive` — the singleton authority that could name one —
27654
+ * throws for a collection cap by design. Naming CamStack here instead
27655
+ * would privilege one addon by id inside a surface whose premise is
27656
+ * that sources are peers, and would be wrong on the first camera with
27657
+ * no recorder binding. So absence is REFUSED, in the schema, where the
27658
+ * generated types make it unomittable rather than merely discouraged.
27659
+ *
27660
+ * The default belongs to the SURFACE, which has the `listSources` rows
27661
+ * and can say which one it picked (D569 § 1–3; the viewer already
27662
+ * always sends this).
27565
27663
  *
27566
27664
  * It replaced `sources?: string[]`, a VIEW filter over source ids that
27567
27665
  * assumed the answer was a fan-out over everything a camera has. The
27568
- * operator settled otherwise on 2026-09-20 — *"il get videoclips
27569
- * prendere un provider opzionale, di default va su camstack"*,
27570
- * *"l'utilizzatore è uno solo"* — so the list is asked of one provider
27571
- * at a time and there is nothing to filter out of it.
27666
+ * operator settled otherwise on 2026-09-20 — *"l'utilizzatore è uno
27667
+ * solo"* — so the list is asked of one provider at a time and there is
27668
+ * nothing to filter out of it.
27572
27669
  */
27573
- provider: zod.z.string().optional()
27670
+ provider: zod.z.string().min(1)
27574
27671
  }), zod.z.array(ClipSchema).readonly(), {
27575
27672
  kind: "query",
27576
27673
  auth: "protected"
@@ -27607,6 +27704,68 @@ var videoclipsCapability = {
27607
27704
  }), ClipPlaybackSchema, {
27608
27705
  kind: "query",
27609
27706
  auth: "protected"
27707
+ }),
27708
+ /**
27709
+ * This clip's BYTES, base64, bounded — the by-handle read a clip EXPORT
27710
+ * pulls once (D558).
27711
+ *
27712
+ * `getClipPlayback` is the right answer for a player: it hands back a URL
27713
+ * on a plane the hub serves `access:'authenticated'`, which a browser and a
27714
+ * viewer session satisfy. It is the wrong answer for another ADDON. There
27715
+ * is no addon→addon byte transport in this framework — `AddonDataPlane`
27716
+ * only lets an addon SERVE, on `127.0.0.1` behind a per-listener secret
27717
+ * only the hub may present — so a recorder that wants a camera's clip
27718
+ * cannot fetch that URL. This method is the one seam that exists for it,
27719
+ * and it is deliberately the same shape (and the same bound) as
27720
+ * `recordingExport.readExportBytes`, which exists for the mirror-image
27721
+ * reason.
27722
+ *
27723
+ * Routing needs no `provider` pin: the id is source-prefixed and
27724
+ * self-contained, so `device-collection-dispatch.ts` rule 3 hands the call
27725
+ * to the source that claims it — and an id nobody claims is REFUSED rather
27726
+ * than answered by another source.
27727
+ *
27728
+ * The producer reuses the fetch path it already has, completion rules
27729
+ * included: a clip is taken by cmd 5 and finished on a short idle window
27730
+ * whose result is PROVED against the catalog row's own span, retried once
27731
+ * when it comes up materially short, and served-and-named when it is still
27732
+ * short (D568). A second fetch with different completion rules is exactly
27733
+ * the second authority D558 refuses to create.
27734
+ *
27735
+ * Every refusal THROWS with its reason and none of them is silent — the
27736
+ * sleep gate (decided before `getApi()`, liftable only by
27737
+ * {@link ClipWakeSchema}), a catalog row nobody claims, a clip with no
27738
+ * bytes behind it, a mux that failed, and the size bound. The caller turns
27739
+ * that reason into an operator-facing one; a truncated file is never an
27740
+ * answer.
27741
+ */
27742
+ readClipBytes: require_sleep.optionalMethod(zod.z.object({
27743
+ deviceId: zod.z.number(),
27744
+ clipId: zod.z.string().min(1),
27745
+ /**
27746
+ * Which twin to fetch, on the mapping D549 15 already fixed:
27747
+ * `low | mid` → the sub file, `high` → the main twin. `auto` is not
27748
+ * accepted here for the same reason it is not accepted by
27749
+ * `getClipPlayback` — a stored file has no broker session, so the
27750
+ * adaptive tier cannot be resolved for it.
27751
+ */
27752
+ profile: require_sleep.CamProfileSchema.optional(),
27753
+ /**
27754
+ * The CALLER's byte bound, so an over-size clip is refused before it is
27755
+ * read and encoded rather than after. Capped by
27756
+ * {@link VIDEOCLIPS_MAX_READ_BYTES} whatever is passed; absent means
27757
+ * that ceiling.
27758
+ */
27759
+ maxBytes: zod.z.number().int().positive().optional(),
27760
+ /**
27761
+ * The operator's authorisation to wake a sleeping camera for this
27762
+ * read. Absent — the default — means a sleeping standalone battery
27763
+ * camera is REFUSED by name, before any session is opened.
27764
+ */
27765
+ wake: ClipWakeSchema.optional()
27766
+ }), ClipBytesSchema, {
27767
+ kind: "query",
27768
+ auth: "protected"
27610
27769
  })
27611
27770
  }
27612
27771
  };
@@ -37127,13 +37286,135 @@ var ExportStateSchema = zod.z.enum([
37127
37286
  "expired",
37128
37287
  "deleted"
37129
37288
  ]);
37130
- /** One export job / history row. */
37289
+ /**
37290
+ * A stretch of footage THIS system recorded — the only thing `createExport`
37291
+ * could export before D558, and still the shape every legacy caller sends.
37292
+ */
37293
+ var ExportFootageSubjectSchema = zod.z.object({
37294
+ kind: zod.z.literal("footage"),
37295
+ deviceId: zod.z.number(),
37296
+ profiles: zod.z.array(zod.z.string()).min(1),
37297
+ fromMs: zod.z.number(),
37298
+ toMs: zod.z.number()
37299
+ });
37300
+ /**
37301
+ * A CLIP — a finished file with boundaries the camera chose, listed by one of
37302
+ * the device's `videoclips` sources.
37303
+ *
37304
+ * There is deliberately **no `fromMs`/`toMs` here**. The camera chose them,
37305
+ * no surface on this path asks for them (there is no drag and no
37306
+ * `datetime-local` pair — D558 § 5.4.3), and they reach the record only as the
37307
+ * projection. A range in the subject would be a second place the boundaries
37308
+ * live and the one a caller could get wrong.
37309
+ *
37310
+ * `provider` is the **addonId** of the source's serving addon — the `provider`
37311
+ * pin `videoclips.listClips` REQUIRES since D554 was amended on 2026-09-20.
37312
+ * There was never a default: a bare call fanned out and returned the union of
37313
+ * every source with `limit` meaning `limit × sources`. The catalog check that
37314
+ * validates this subject names it, so it asks exactly the source the operator
37315
+ * picked.
37316
+ *
37317
+ * `source` is that source's id (the namespace `clipId` is prefixed with), and
37318
+ * `sourceLabel` is its operator-facing name FROZEN at creation — a history row
37319
+ * still reads "SD card" after the source is unbound.
37320
+ *
37321
+ * `profile` is exactly ONE, and it is what was ASKED. What was SERVED lands on
37322
+ * the record's top-level `profile`, so a clip with no main twin renders the
37323
+ * divergence instead of hiding it (D549 15; measured on 592, 17 of 546 clips
37324
+ * had no main twin, so a silent fallback would be right 96.9 % of the time).
37325
+ * `auto` is not a member: a stored file has no broker session, so the adaptive
37326
+ * tier cannot be resolved for it.
37327
+ */
37328
+ var ExportClipSubjectSchema = zod.z.object({
37329
+ kind: zod.z.literal("clip"),
37330
+ deviceId: zod.z.number(),
37331
+ provider: zod.z.string().min(1),
37332
+ source: zod.z.string().min(1),
37333
+ sourceLabel: zod.z.string().min(1),
37334
+ clipId: zod.z.string().min(1),
37335
+ /**
37336
+ * WHERE IN THE CATALOG to confirm this clip — the day window the surface was
37337
+ * already listing when the operator picked the segment.
37338
+ *
37339
+ * It is **not** a time range control and it never becomes one: the record's
37340
+ * `fromMs`/`toMs` come from the catalog ROW and from nothing a caller
37341
+ * supplied (D558 § 5.4.3), and a window that does not contain the clip is a
37342
+ * `catalog-miss`, not a silently wider search. It exists because
37343
+ * `videoclips.listClips` takes `since`/`until` and has no by-handle twin:
37344
+ * the catalog check D558 asks for is literally that call, and a call needs a
37345
+ * window. The surface has one — `ClipsBrowser`'s `dayWindow`, one local
37346
+ * wall-clock day, which is also the only width measured to be cheap (one
37347
+ * day on 592 lists 171 clips in 712 ms, a busy day 546 in 2.0 s; twenty days
37348
+ * of one child's events took 3.6–5.4 s).
37349
+ */
37350
+ catalogWindow: zod.z.object({
37351
+ sinceMs: zod.z.number(),
37352
+ untilMs: zod.z.number()
37353
+ }),
37354
+ profile: zod.z.enum([
37355
+ "high",
37356
+ "mid",
37357
+ "low"
37358
+ ]),
37359
+ /**
37360
+ * The operator's authorisation to wake a sleeping camera for this export.
37361
+ * ONE definition, in the cap that owns the clip read ({@link ClipWakeSchema}),
37362
+ * because the gate that honours it is the clip provider's sleep gate — a
37363
+ * second enum here would be a second contract. Absent by default; never
37364
+ * settable by a scheduler or a retry.
37365
+ *
37366
+ * **One authorised yes is ONE wake.** A failed clip export is retried only by
37367
+ * an operator act that asks again; a queued job that outlived its wake fails
37368
+ * with a reason rather than waking on its turn; and this subject carries
37369
+ * exactly one profile precisely so one tap is never two fetches (D558 § 5.2).
37370
+ */
37371
+ wake: ClipWakeSchema.optional()
37372
+ });
37373
+ /**
37374
+ * WHAT an export is — the authority, as opposed to the four top-level fields
37375
+ * the Library sorts and labels on (D558 § 2.2).
37376
+ *
37377
+ * Read it through {@link exportSubjectOf}, never off the record directly: the
37378
+ * field is optional for the history rows written before it existed, and that
37379
+ * absence has exactly one interpreter.
37380
+ */
37381
+ var ExportSubjectSchema = zod.z.discriminatedUnion("kind", [ExportFootageSubjectSchema, ExportClipSubjectSchema]);
37382
+ /**
37383
+ * One export job / history row.
37384
+ *
37385
+ * **`subject` is the AUTHORITY on what was exported. `deviceId`, `profile`,
37386
+ * `fromMs` and `toMs` are its PROJECTION** — kept top-level because the whole
37387
+ * Library sorts and labels on them (`library-items.ts` orders an export by
37388
+ * `fromMs`; `export-format.ts` draws `rangeLabel` from the pair), and a row
37389
+ * that did not fill them would sort under the epoch and render a blank range.
37390
+ * Write to the subject and read from the projection and the two will disagree;
37391
+ * the projection is derived at creation and never edited afterwards.
37392
+ *
37393
+ * And they mean DIFFERENT FACTS for the two kinds, which is the part a reader
37394
+ * who knows only the recording export will get wrong:
37395
+ *
37396
+ * | field | `kind:'footage'` | `kind:'clip'` |
37397
+ * | --- | --- | --- |
37398
+ * | `fromMs`/`toMs` | the stretch the operator ASKED for | the camera's own boundaries, always `clip.timeRange`, never anything a caller supplied |
37399
+ * | `profile` | the stream rendered | the twin actually SERVED (`subject.profile` is the one asked for) |
37400
+ *
37401
+ * Same type, different fact — the shape this repo keeps getting wrong (D385's
37402
+ * two authorities, D224's second copy).
37403
+ */
37131
37404
  var ExportRecordSchema = zod.z.object({
37132
37405
  id: zod.z.string(),
37133
37406
  deviceId: zod.z.number(),
37134
37407
  profile: zod.z.string(),
37135
37408
  fromMs: zod.z.number(),
37136
37409
  toMs: zod.z.number(),
37410
+ /**
37411
+ * What this export IS. Optional ONLY for the rows written before D558: the
37412
+ * store parses every row through this schema on every read, so a required
37413
+ * field would make the export AUDIT — which is the whole reason rows survive
37414
+ * file deletion — unreadable in one release. Absence means `footage`, and
37415
+ * {@link exportSubjectOf} is the one place that says so.
37416
+ */
37417
+ subject: ExportSubjectSchema.optional(),
37137
37418
  options: ExportOptionsSchema,
37138
37419
  state: ExportStateSchema,
37139
37420
  /** 0–100 while rendering; null otherwise. */
@@ -37150,6 +37431,49 @@ var ExportRecordSchema = zod.z.object({
37150
37431
  /** Failure reason when state is 'failed'; null otherwise. */
37151
37432
  error: zod.z.string().nullable()
37152
37433
  });
37434
+ /**
37435
+ * Every way a clip export can fail, as a TOKEN — never prose.
37436
+ *
37437
+ * A branch that accepts work and produces nothing is the branch this repo
37438
+ * keeps losing work in (D391), and a clip export has five places to lose it
37439
+ * that a recording export does not have. The token is what a surface may key
37440
+ * a table on; the PROSE — the camera's own words, the source's verbatim
37441
+ * refusal — travels with it, in the same `ExportRecord.error` string, after a
37442
+ * `: `. Two separate things in one field because the field is one field:
37443
+ * `ClipStillRefusalCodeSchema` split them across two HTTP headers for the same
37444
+ * reason, and the surface that keyed on the whole header rendered every
37445
+ * refusal on this fleet as `Refused: <prose>`.
37446
+ *
37447
+ * Compose with {@link clipExportFailure}, read back with
37448
+ * {@link clipExportFailureOf}. Never hand-spell the separator.
37449
+ */
37450
+ var ClipExportFailureSchema = zod.z.enum([
37451
+ "catalog-miss",
37452
+ "catalog-unreachable",
37453
+ "no-file-for-window",
37454
+ "clip-in-progress",
37455
+ "unsupported-option",
37456
+ "sleeping",
37457
+ "camera-refused",
37458
+ "fetch-failed",
37459
+ "too-large-to-transfer",
37460
+ "wake-expired"
37461
+ ]);
37462
+ /** `<token>: <prose>` — the ONE composition of a clip export's failure string. */
37463
+ function clipExportFailure(code, detail) {
37464
+ return detail.length > 0 ? `${code}: ${detail}` : code;
37465
+ }
37466
+ /**
37467
+ * The token out of an {@link ExportRecord.error}, or null when the string did
37468
+ * not come from {@link clipExportFailure} (every footage failure, and every
37469
+ * error thrown by something that never heard of this vocabulary).
37470
+ */
37471
+ function clipExportFailureOf(error) {
37472
+ if (error === null) return null;
37473
+ const head = error.split(":", 1)[0] ?? "";
37474
+ const parsed = ClipExportFailureSchema.safeParse(head.trim());
37475
+ return parsed.success ? parsed.data : null;
37476
+ }
37153
37477
  /** Candidate download URLs (LAN first, then operator extra hosts). */
37154
37478
  var ExportDownloadSchema = zod.z.object({
37155
37479
  url: zod.z.string(),
@@ -37187,35 +37511,149 @@ var ExportBytesSchema = zod.z.object({
37187
37511
  name: zod.z.string(),
37188
37512
  bytes: zod.z.number().int().nonnegative()
37189
37513
  });
37514
+ /** Canonical `profiles[]`, falling back to the legacy singular `profile`. */
37515
+ function resolveExportProfiles(input) {
37516
+ if (input.profiles !== void 0 && input.profiles.length > 0) return [...input.profiles];
37517
+ if (typeof input.profile === "string" && input.profile.length > 0) return [input.profile];
37518
+ return [];
37519
+ }
37190
37520
  /**
37191
- * `createExport` input. `profiles` is the canonical field (min 1). A legacy
37192
- * singular `profile` is still accepted so existing callers do not break.
37521
+ * `createExport` input — ONE object carrying an optional {@link ExportSubject},
37522
+ * never a union of two inputs.
37193
37523
  *
37194
- * Must remain a ZodObject (`.loose()` for out-of-band `nodeId`).
37524
+ * It has to be a ZodObject: generated routers call `.input.loose()` so the
37525
+ * out-of-band `nodeId` selector survives the wire parse, and `.loose()` is a
37526
+ * ZodObject method a `z.discriminatedUnion` does not have. That is why the
37527
+ * discriminant sits one level down, in `subject`, and why
37528
+ * {@link resolveCreateExportSubject} — not a `z.preprocess` wrapper, which
37529
+ * would have produced a schema with no `.loose()` — is the one reading of a
37530
+ * legacy flat input as a subject.
37531
+ *
37532
+ * **`deviceId` stays REQUIRED at the top level**, for both kinds, and a clip
37533
+ * subject naming a different one is REFUSED. Not symmetry: `METHOD_DEVICE_SELECTORS`
37534
+ * (generated) maps top-level fields and one-level object arrays, so per-device
37535
+ * scope enforcement in `scope-access.ts` reads THIS field and cannot see
37536
+ * `subject.deviceId`. A deviceId that lived only in the subject would let a
37537
+ * principal scoped to one camera create an export — and, on the clip path, a
37538
+ * WAKE — for another.
37539
+ *
37540
+ * **A clip carries no time range**, and one supplied alongside a clip subject
37541
+ * is refused rather than ignored: there is no drag on this path and nothing to
37542
+ * normalise (D558 § 5.4.3). The record's `fromMs`/`toMs` come from the clip's
37543
+ * own `timeRange` and from nowhere else.
37195
37544
  */
37196
37545
  var CreateExportInputSchema = zod.z.object({
37197
37546
  deviceId: zod.z.number(),
37198
37547
  /** @deprecated Prefer `profiles`. Kept so timelapse/notifiers keep working. */
37199
37548
  profile: zod.z.string().optional(),
37200
37549
  profiles: zod.z.array(zod.z.string()).min(1).optional(),
37201
- fromMs: zod.z.number(),
37202
- toMs: zod.z.number(),
37550
+ /** Footage only — a clip's boundaries are the camera's. */
37551
+ fromMs: zod.z.number().optional(),
37552
+ toMs: zod.z.number().optional(),
37553
+ /** What to export. Absent means the legacy flat footage request. */
37554
+ subject: ExportSubjectSchema.optional(),
37203
37555
  options: ExportOptionsSchema
37204
37556
  }).superRefine((v, ctx) => {
37205
- if ((v.profiles !== void 0 && v.profiles.length > 0 ? v.profiles : v.profile !== void 0 ? [v.profile] : []).length < 1) ctx.addIssue({
37557
+ if (v.subject?.kind === "clip") {
37558
+ if (v.subject.deviceId !== v.deviceId) ctx.addIssue({
37559
+ code: zod.z.ZodIssueCode.custom,
37560
+ message: `subject.deviceId (${v.subject.deviceId}) must equal deviceId (${v.deviceId}) — the top-level field is what per-device scope enforcement reads`,
37561
+ path: ["subject", "deviceId"]
37562
+ });
37563
+ if (v.fromMs !== void 0 || v.toMs !== void 0) ctx.addIssue({
37564
+ code: zod.z.ZodIssueCode.custom,
37565
+ message: "a clip export asks for no time range: the camera chose the boundaries and they are read from the catalog row",
37566
+ path: ["fromMs"]
37567
+ });
37568
+ return;
37569
+ }
37570
+ if (v.subject?.kind === "footage" && v.subject.deviceId !== v.deviceId) ctx.addIssue({
37571
+ code: zod.z.ZodIssueCode.custom,
37572
+ message: `subject.deviceId (${v.subject.deviceId}) must equal deviceId (${v.deviceId})`,
37573
+ path: ["subject", "deviceId"]
37574
+ });
37575
+ const fromMs = v.subject?.kind === "footage" ? v.subject.fromMs : v.fromMs;
37576
+ const toMs = v.subject?.kind === "footage" ? v.subject.toMs : v.toMs;
37577
+ if (typeof fromMs !== "number" || typeof toMs !== "number") ctx.addIssue({
37578
+ code: zod.z.ZodIssueCode.custom,
37579
+ message: "a footage export needs fromMs and toMs",
37580
+ path: ["fromMs"]
37581
+ });
37582
+ if ((v.subject?.kind === "footage" ? [...v.subject.profiles] : resolveExportProfiles(v)).length < 1) ctx.addIssue({
37206
37583
  code: zod.z.ZodIssueCode.custom,
37207
37584
  message: "pass profiles[] (min 1) or legacy profile",
37208
37585
  path: ["profiles"]
37209
37586
  });
37210
37587
  });
37588
+ /**
37589
+ * The ONE reading of a `createExport` input as a {@link ExportSubject}.
37590
+ *
37591
+ * Every consumer goes through this: a provider that branched on
37592
+ * `input.subject !== undefined` in one place and on `input.fromMs` in another
37593
+ * would be two authorities on what was asked for, which is how the flat fields
37594
+ * and the subject drift apart.
37595
+ *
37596
+ * Throws on a footage input with no range — an input that parsed cannot reach
37597
+ * that, and a caller that skipped the parse gets a named refusal rather than
37598
+ * `NaN` boundaries on a durable row.
37599
+ */
37600
+ function resolveCreateExportSubject(input) {
37601
+ if (input.subject !== void 0) return input.subject;
37602
+ const profiles = resolveExportProfiles(input);
37603
+ if (typeof input.fromMs !== "number" || typeof input.toMs !== "number") throw new Error("recording-export: a footage export needs fromMs and toMs");
37604
+ return {
37605
+ kind: "footage",
37606
+ deviceId: input.deviceId,
37607
+ profiles,
37608
+ fromMs: input.fromMs,
37609
+ toMs: input.toMs
37610
+ };
37611
+ }
37612
+ /**
37613
+ * The ONE interpreter of a stored row's subject.
37614
+ *
37615
+ * `ExportRecord.subject` is optional for exactly one reason — the history rows
37616
+ * written before D558 — and "absent means footage, built from the projection"
37617
+ * is a statement that must live in one place. Anything that reads
37618
+ * `rec.subject` directly and falls back inline is the second authority.
37619
+ */
37620
+ function exportSubjectOf(rec) {
37621
+ if (rec.subject !== void 0) return rec.subject;
37622
+ return {
37623
+ kind: "footage",
37624
+ deviceId: rec.deviceId,
37625
+ profiles: [rec.profile],
37626
+ fromMs: rec.fromMs,
37627
+ toMs: rec.toMs
37628
+ };
37629
+ }
37211
37630
  var recordingExportCapability = {
37212
37631
  name: "recording-export",
37213
37632
  scope: "system",
37214
37633
  mode: "singleton",
37215
37634
  methods: {
37216
- /** Queue a render of `[fromMs,toMs)` for `deviceId`/`profiles` (legacy
37217
- * singular `profile` still accepted). Fails fast when no footage covers
37218
- * the range. One job per profile; returns the first queued record. */
37635
+ /**
37636
+ * Queue an export of {@link ExportSubjectSchema}.
37637
+ *
37638
+ * `kind:'footage'` — a render of `[fromMs,toMs)` for `deviceId`/`profiles`
37639
+ * (legacy flat input, singular `profile` included, still accepted and
37640
+ * rewritten). Fails fast when no footage covers the range. One job per
37641
+ * profile; **returns the first queued record and the others are reachable
37642
+ * only through `listExports`** — a defect named in D558 § 6.3 and the
37643
+ * reason a clip subject carries exactly ONE profile.
37644
+ *
37645
+ * `kind:'clip'` — a finished file the camera holds, validated against the
37646
+ * device's clip CATALOG (`videoclips.listClips`, at the subject's
37647
+ * `provider`) instead of the recording index, and fetched once by handle
37648
+ * under a bound. Its `fromMs`/`toMs` come from the catalog row and from
37649
+ * nowhere else; a caller supplying a range is refused.
37650
+ *
37651
+ * A clip export reuses the six {@link ExportStateSchema} members and adds
37652
+ * none: the viewer maps an unknown state string to `failed`, so a seventh
37653
+ * member renders every live export — of both kinds — as FAILED on every
37654
+ * installed app (D558 § 6.1, pinned by `export-state-members.spec.ts`).
37655
+ * `subject.kind` is what tells a surface what `rendering` means.
37656
+ */
37219
37657
  createExport: require_sleep.method(CreateExportInputSchema, ExportRecordSchema, {
37220
37658
  kind: "mutation",
37221
37659
  auth: "protected"
@@ -51097,6 +51535,12 @@ var METHOD_ACCESS_MAP = Object.freeze({
51097
51535
  addonId: null,
51098
51536
  access: "view"
51099
51537
  },
51538
+ "videoclips.readClipBytes": {
51539
+ capName: "videoclips",
51540
+ capScope: "device",
51541
+ addonId: null,
51542
+ access: "view"
51543
+ },
51100
51544
  "viewerUi.getStaticDir": {
51101
51545
  capName: "viewer-ui",
51102
51546
  capScope: "system",
@@ -53388,6 +53832,11 @@ var METHOD_DEVICE_SELECTORS = Object.freeze({
53388
53832
  form: "single",
53389
53833
  optional: false
53390
53834
  }],
53835
+ "videoclips.readClipBytes": [{
53836
+ name: "deviceId",
53837
+ form: "single",
53838
+ optional: false
53839
+ }],
53391
53840
  "waterHeater.setAway": [{
53392
53841
  name: "deviceId",
53393
53842
  form: "single",
@@ -59052,12 +59501,15 @@ exports.CarbonMonoxideStatusSchema = CarbonMonoxideStatusSchema;
59052
59501
  exports.ChargingStatus = require_sleep.ChargingStatus;
59053
59502
  exports.ClientNetworkStatsSchema = ClientNetworkStatsSchema;
59054
59503
  exports.ClimateControlStatusSchema = ClimateControlStatusSchema;
59504
+ exports.ClipBytesSchema = ClipBytesSchema;
59505
+ exports.ClipExportFailureSchema = ClipExportFailureSchema;
59055
59506
  exports.ClipPlaybackSchema = ClipPlaybackSchema;
59056
59507
  exports.ClipSchema = ClipSchema;
59057
59508
  exports.ClipSourceAvailabilitySchema = ClipSourceAvailabilitySchema;
59058
59509
  exports.ClipSourceSchema = ClipSourceSchema;
59059
59510
  exports.ClipStillDispositionSchema = ClipStillDispositionSchema;
59060
59511
  exports.ClipStillRefusalCodeSchema = ClipStillRefusalCodeSchema;
59512
+ exports.ClipWakeSchema = ClipWakeSchema;
59061
59513
  exports.ClusterAddonNodeDeploymentSchema = ClusterAddonNodeDeploymentSchema;
59062
59514
  exports.ClusterAddonStatusEntrySchema = ClusterAddonStatusEntrySchema;
59063
59515
  exports.CollectionColumnSchema = CollectionColumnSchema;
@@ -59217,15 +59669,18 @@ exports.EventMediaProductionSchema = EventMediaProductionSchema;
59217
59669
  exports.EventOwnerTypeSchema = EventOwnerTypeSchema;
59218
59670
  exports.EventSourceType = require_enums.EventSourceType$1;
59219
59671
  exports.ExportBytesSchema = ExportBytesSchema;
59672
+ exports.ExportClipSubjectSchema = ExportClipSubjectSchema;
59220
59673
  exports.ExportDenseRangeSchema = ExportDenseRangeSchema;
59221
59674
  exports.ExportDenseSchema = ExportDenseSchema;
59222
59675
  exports.ExportDownloadSchema = ExportDownloadSchema;
59676
+ exports.ExportFootageSubjectSchema = ExportFootageSubjectSchema;
59223
59677
  exports.ExportOptionsSchema = ExportOptionsSchema;
59224
59678
  exports.ExportRecordSchema = ExportRecordSchema;
59225
59679
  exports.ExportSetupFieldSchema = ExportSetupFieldSchema;
59226
59680
  exports.ExportSetupSchema = ExportSetupSchema;
59227
59681
  exports.ExportSpeedSchema = ExportSpeedSchema;
59228
59682
  exports.ExportStateSchema = ExportStateSchema;
59683
+ exports.ExportSubjectSchema = ExportSubjectSchema;
59229
59684
  exports.ExportTimelapseSchema = ExportTimelapseSchema;
59230
59685
  exports.ExposedDeviceSchema = ExposedDeviceSchema;
59231
59686
  exports.ExposureModeSchema = ExposureModeSchema;
@@ -59952,6 +60407,7 @@ exports.UpdateStatusSchema = UpdateStatusSchema;
59952
60407
  exports.UpdateUserInputSchema = UpdateUserInputSchema;
59953
60408
  exports.UserRecordSchema = UserRecordSchema;
59954
60409
  exports.UserSummarySchema = UserSummarySchema;
60410
+ exports.VIDEOCLIPS_MAX_READ_BYTES = VIDEOCLIPS_MAX_READ_BYTES;
59955
60411
  exports.VISIT_MERGE_GAP_MS = VISIT_MERGE_GAP_MS;
59956
60412
  exports.VacuumControlStatusSchema = VacuumControlStatusSchema;
59957
60413
  exports.VacuumStateSchema = VacuumStateSchema;
@@ -60072,6 +60528,8 @@ exports.classifyBearerPrincipal = classifyBearerPrincipal;
60072
60528
  exports.classifyStream = classifyStream;
60073
60529
  exports.classifyStreams = classifyStreams;
60074
60530
  exports.climateControlCapability = climateControlCapability;
60531
+ exports.clipExportFailure = clipExportFailure;
60532
+ exports.clipExportFailureOf = clipExportFailureOf;
60075
60533
  exports.clusterModelSettingKey = clusterModelSettingKey;
60076
60534
  exports.clusterStepSettingFieldsFor = clusterStepSettingFieldsFor;
60077
60535
  exports.clusterStepSettingKey = clusterStepSettingKey;
@@ -60171,6 +60629,7 @@ exports.evictionPolicyForMode = evictionPolicyForMode;
60171
60629
  exports.evictionPolicyOfLocation = evictionPolicyOfLocation;
60172
60630
  exports.expandAudioChunkToF32le = require_sleep.expandAudioChunkToF32le;
60173
60631
  exports.expandCapMethods = require_sleep.expandCapMethods;
60632
+ exports.exportSubjectOf = exportSubjectOf;
60174
60633
  exports.extractNestedAddonId = extractNestedAddonId;
60175
60634
  exports.extractSourceInfoFromMetadata = extractSourceInfoFromMetadata;
60176
60635
  exports.faceGalleryCapability = faceGalleryCapability;
@@ -60305,6 +60764,7 @@ exports.oauthIntegrationCapability = oauthIntegrationCapability;
60305
60764
  exports.objectInputDeclaresAddonId = objectInputDeclaresAddonId;
60306
60765
  exports.objectInputDeclaresRequiredDeviceId = objectInputDeclaresRequiredDeviceId;
60307
60766
  exports.occupancyScope = occupancyScope;
60767
+ exports.optionalMethod = require_sleep.optionalMethod;
60308
60768
  exports.osdCapability = osdCapability;
60309
60769
  exports.osdManagerCapability = osdManagerCapability;
60310
60770
  exports.overlayClusterStepSettings = overlayClusterStepSettings;
@@ -60372,10 +60832,12 @@ exports.resolveBucketMs = resolveBucketMs;
60372
60832
  exports.resolveCapMount = require_sleep.resolveCapMount;
60373
60833
  exports.resolveClusterStepModelId = resolveClusterStepModelId;
60374
60834
  exports.resolveContainerPrimaryChild = resolveContainerPrimaryChild;
60835
+ exports.resolveCreateExportSubject = resolveCreateExportSubject;
60375
60836
  exports.resolveDetectionRuntime = resolveDetectionRuntime;
60376
60837
  exports.resolveDeviceControlKind = resolveDeviceControlKind;
60377
60838
  exports.resolveDeviceProfile = resolveDeviceProfile;
60378
60839
  exports.resolveEgressDecodeHwAccel = resolveEgressDecodeHwAccel;
60840
+ exports.resolveExportProfiles = resolveExportProfiles;
60379
60841
  exports.resolveFormat = resolveFormat;
60380
60842
  exports.resolveHydratedFieldValue = require_sleep.resolveHydratedFieldValue;
60381
60843
  exports.resolveLocationIcon = resolveLocationIcon;