@camstack/addon-pipeline 1.2.274 → 1.2.275

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.
Files changed (32) hide show
  1. package/dist/audio-analyzer/index.js +2 -2
  2. package/dist/audio-analyzer/index.mjs +2 -2
  3. package/dist/{default-detection-model-CAWhHQo2.js → default-detection-model-6lCvep7n.js} +1 -1
  4. package/dist/{default-detection-model-BXwE-Dvo.mjs → default-detection-model-dQSwHHfx.mjs} +1 -1
  5. package/dist/detection-pipeline/index.js +4 -4
  6. package/dist/detection-pipeline/index.mjs +4 -4
  7. package/dist/{dist-g5MfpiBh.mjs → dist-C1pCVJk7.mjs} +440 -32
  8. package/dist/{dist-k6Vu-AhZ.js → dist-NYjn7hkE.js} +469 -31
  9. package/dist/motion-wasm/index.js +1 -1
  10. package/dist/motion-wasm/index.mjs +1 -1
  11. package/dist/{node-BXsHQH5h.mjs → node--UY0iepi.mjs} +1 -1
  12. package/dist/{node--u_jUObS.js → node-CVYY8a4y.js} +1 -1
  13. package/dist/pipeline-runner/index.js +3 -3
  14. package/dist/pipeline-runner/index.mjs +3 -3
  15. package/dist/{process-memory-Gl3EowL-.mjs → process-memory-BQOfL3Ig.mjs} +1 -1
  16. package/dist/{process-memory-DN7opum2.js → process-memory-DDvuSEMJ.js} +1 -1
  17. package/dist/recorder/index.js +495 -35
  18. package/dist/recorder/index.mjs +495 -35
  19. package/dist/{segment-demux-js-sYP_jndp.mjs → segment-demux-js-B0_aAzN0.mjs} +1 -1
  20. package/dist/{segment-demux-js-DHX8o8pI.js → segment-demux-js-DVupBBc4.js} +1 -1
  21. package/dist/stream-broker/_stub.js +2 -2
  22. package/dist/stream-broker/{_virtual_mf-localSharedImportMap___mfe_internal__addon_stream_broker_widgets-CEy8IryH.mjs → _virtual_mf-localSharedImportMap___mfe_internal__addon_stream_broker_widgets-BrNGbvkl.mjs} +2 -2
  23. package/dist/stream-broker/_virtual_mf___mfe_internal__addon_stream_broker_widgets__loadShare___mf_0_camstack_mf_1_types__loadShare__.js-BV2tQ1w3.mjs +26 -0
  24. package/dist/stream-broker/{_virtual_mf___mfe_internal__addon_stream_broker_widgets__loadShare___mf_0_camstack_mf_1_ui_mf_2_library__loadShare__.js-MU3_q1MX.mjs → _virtual_mf___mfe_internal__addon_stream_broker_widgets__loadShare___mf_0_camstack_mf_1_ui_mf_2_library__loadShare__.js-BnLVuoDg.mjs} +1 -1
  25. package/dist/stream-broker/demux-worker-child.js +1 -1
  26. package/dist/stream-broker/demux-worker-child.mjs +1 -1
  27. package/dist/stream-broker/{hostInit-UKNN4qes.mjs → hostInit-CSJt3rp0.mjs} +2 -2
  28. package/dist/stream-broker/index.js +526 -69
  29. package/dist/stream-broker/index.mjs +526 -69
  30. package/dist/stream-broker/remoteEntry.js +1 -1
  31. package/package.json +1 -1
  32. package/dist/stream-broker/_virtual_mf___mfe_internal__addon_stream_broker_widgets__loadShare___mf_0_camstack_mf_1_types__loadShare__.js-BlXyfeXU.mjs +0 -26
@@ -1,5 +1,5 @@
1
- import { A as RecordingConfigSchema, At as resolveLocationMode, Dt as recordingSignalCapability, Et as recordingExportCapability, Ft as storageOccupancyCapability, G as deriveBatteryPresence, Jt as BaseAddon, Lt as stripRetiredBandPreBufferSec, Mt as resolveRecordingProfiles, N as VISIT_MERGE_GAP_MS, Pt as storageEvictableCapability, Q as evaluateSensorEdge, Sn as string, T as OpsLogEntrySchema, Tt as recordingCapability, Vt as errMsg, Xt as DeviceFeature, Zt as DeviceType, bn as preprocess, d as DEFAULT_EVENTS_BAND_BUFFER_SEC, dn as sleep$1, dt as mayReadLocation, en as customAction, et as evictionPolicyForMode, fn as _enum, ft as mayWriteToLocation, g as EVENT_PAD_MS, h as EVENT_OWNER_TYPES, i as BatteryStatusSchema, j as RecordingSignalStatusSchema, k as RECORDING_EXPORT_MAX_READ_BYTES, mn as boolean, mt as modeMayWrite, ot as isFirstLevelMacroClass, pn as array, pt as migrateLegacyDeviceSignalConfig, q as deriveRecordingMode, rn as hydrateSchema, rt as gbToBytes, sn as nodePin, st as loadContributionCapability, tn as defineCustomActions, tt as evictionPolicyOfLocation, un as selectAssignedProfileSlots, v as ExportRecordSchema, vn as number, wn as EventCategory, xn as record, yn as object, z as batteryCapability, zt as videoclipsCapability } from "../dist-g5MfpiBh.mjs";
2
- import { a as physicalRootOf, i as NO_COST_CLAIM, t as ChildCostRegistry } from "../node-BXsHQH5h.mjs";
1
+ import { A as RecordingConfigSchema, At as recordingSignalCapability, Cn as number, Dn as string, En as record, Gt as errMsg, H as clipExportFailureOf, It as resolveRecordingProfiles, Mt as resolveCreateExportSubject, N as VISIT_MERGE_GAP_MS, Ot as recordingCapability, Pt as resolveLocationMode, Qt as BaseAddon, Rt as storageEvictableCapability, T as OpsLogEntrySchema, Tn as preprocess, Ut as videoclipsCapability, V as clipExportFailure, Vt as stripRetiredBandPreBufferSec, Y as deriveRecordingMode, _n as _enum, _t as modeMayWrite, an as customAction, cn as hydrateSchema, d as DEFAULT_EVENTS_BAND_BUFFER_SEC, et as evaluateSensorEdge, fn as nodePin, g as EVENT_PAD_MS, gn as sleep$1, gt as migrateLegacyDeviceSignalConfig, h as EVENT_OWNER_TYPES, hn as selectAssignedProfileSlots, ht as mayWriteToLocation, i as BatteryStatusSchema, it as exportSubjectOf, j as RecordingSignalStatusSchema, k as RECORDING_EXPORT_MAX_READ_BYTES, kn as EventCategory, kt as recordingExportCapability, lt as isFirstLevelMacroClass, mt as mayReadLocation, nn as DeviceType, nt as evictionPolicyForMode, on as defineCustomActions, ot as gbToBytes, q as deriveBatteryPresence, rt as evictionPolicyOfLocation, tn as DeviceFeature, ut as loadContributionCapability, v as ExportRecordSchema, vn as array, wn as object, yn as boolean, z as batteryCapability, zt as storageOccupancyCapability } from "../dist-C1pCVJk7.mjs";
2
+ import { a as physicalRootOf, i as NO_COST_CLAIM, t as ChildCostRegistry } from "../node--UY0iepi.mjs";
3
3
  import { t as resolveHubHostname } from "../hub-hostname-cCknRYKj.mjs";
4
4
  import { d as PREBUFFER_MAX_MS, l as withRecordingIntent, r as RECORDING_PRE_ROLL_REQUEST_MS } from "../restream-intent-DyGmLAU9.mjs";
5
5
  import { n as RowMapStore, t as retireRootKeys } from "../retire-root-keys-DZvlso2l.mjs";
@@ -6122,6 +6122,21 @@ function errnoCode(raw) {
6122
6122
  }
6123
6123
  //#endregion
6124
6124
  //#region src/recorder/addon/export-engine.ts
6125
+ /**
6126
+ * How long an operator's authorised wake stays spendable.
6127
+ *
6128
+ * One authorised yes is ONE wake (D558 § 5.2 rule 3), and the two ways a job
6129
+ * outlives its yes without anybody meaning it are both real here: it can sit
6130
+ * behind {@link EXPORT_MAX_CONCURRENT} long renders, and it can be re-queued
6131
+ * after a restart. Five minutes is generous against a job measured at 4–6 s
6132
+ * end to end and short enough that a camera is never woken for a tap the
6133
+ * operator has forgotten making.
6134
+ *
6135
+ * Past it the export FAILS with `wake-expired` — a named row the operator can
6136
+ * retry with one tap, which re-asks for the authorisation — rather than
6137
+ * silently waking the camera on a yes from an hour ago.
6138
+ */
6139
+ var CLIP_WAKE_TTL_MS = 5 * 6e4;
6125
6140
  /** Stderr lines retained for the failure LOG. ffmpeg prints one line per failed
6126
6141
  * segment before the decisive "Error opening input" summary, so a short tail can
6127
6142
  * push the actual cause out of the window (it very nearly did — the line that
@@ -6130,6 +6145,42 @@ function errnoCode(raw) {
6130
6145
  var STDERR_TAIL_LINES$1 = 40;
6131
6146
  var TIME_RE = /time=(\d+):(\d+):(\d+(?:\.\d+)?)/;
6132
6147
  /**
6148
+ * How far a delivered clip's duration may sit from its catalog span before it
6149
+ * is worth a line. A remux rounds, a GOP boundary moves a fraction of a
6150
+ * second; two seconds is past both and well under D568's own "materially
6151
+ * shorter" retry threshold, so this reports a disagreement the PRODUCER
6152
+ * already decided to serve rather than second-guessing its completion rule.
6153
+ */
6154
+ var CLIP_DURATION_TOLERANCE_MS = 2e3;
6155
+ /**
6156
+ * The source id of the recorder's OWN `videoclips` provider — a visit over
6157
+ * footage we wrote, not a file a camera holds (D560).
6158
+ *
6159
+ * Duplicating the literal rather than importing `videoclips-provider.ts`
6160
+ * keeps the engine free of the provider (and of the analytics event reads it
6161
+ * carries); the two are pinned together by
6162
+ * `export-engine-clip-fetch.spec.ts`.
6163
+ */
6164
+ var ANALYTICS_CLIP_SOURCE = "analytics";
6165
+ /**
6166
+ * Read a producer's refusal as one of the named clip-export failures.
6167
+ *
6168
+ * A producer that speaks the vocabulary is believed — `clipExportFailureOf`
6169
+ * recovers its token, so a `sleeping` stays `sleeping` all the way to the
6170
+ * modal. Anything else is `fetch-failed` **with the producer's words kept
6171
+ * verbatim**: inventing a more specific token from prose is how a surface's
6172
+ * table came to render every refusal on this fleet as `Refused: <prose>`
6173
+ * (ClipStillRefusalCode's own docblock). The one exception is the size bound,
6174
+ * which the producer states in numbers rather than in a token, and which the
6175
+ * operator must be able to tell from a network failure.
6176
+ */
6177
+ function classifyClipFetchFailure(detail) {
6178
+ const spoken = clipExportFailureOf(detail);
6179
+ if (spoken !== null) return spoken;
6180
+ if (/too large/i.test(detail)) return "too-large-to-transfer";
6181
+ return "fetch-failed";
6182
+ }
6183
+ /**
6133
6184
  * The floor under which an MP4 cannot hold a single decodable frame.
6134
6185
  *
6135
6186
  * **Exit 0 is not the same question as "the file holds a video".** A timelapse
@@ -6211,6 +6262,13 @@ var ExportEngine = class {
6211
6262
  }
6212
6263
  }
6213
6264
  async render(id) {
6265
+ const existing = await getExportRecord(this.deps.state, id);
6266
+ if (!existing) return;
6267
+ const subject = exportSubjectOf(existing);
6268
+ if (subject.kind === "clip" && subject.source !== ANALYTICS_CLIP_SOURCE) {
6269
+ await this.fetchClip(id, existing, subject);
6270
+ return;
6271
+ }
6214
6272
  const rec = await patchExport(this.deps.state, id, {
6215
6273
  state: "rendering",
6216
6274
  progressPct: 0
@@ -6239,6 +6297,187 @@ var ExportEngine = class {
6239
6297
  }
6240
6298
  }
6241
6299
  /**
6300
+ * The CLIP branch: one by-handle fetch, under a bound, written straight to
6301
+ * the export path. No playlist, no ffmpeg, no second completion rule.
6302
+ *
6303
+ * The recorder cannot produce these bytes itself — talking to the camera is
6304
+ * the owning addon's monopoly (one session per host, the sleep gate before
6305
+ * `getApi()`, a cmd-5 transfer whose completion is an idle window proved
6306
+ * against the catalog span, D549 17 / D568) — and there is no addon→addon
6307
+ * byte transport, so the producer's own cap read is the seam (D558 § 3).
6308
+ *
6309
+ * `progressPct` stays `null` for the whole fetch. The job is measured at
6310
+ * 4–6 s end to end and only two of its phases have a real denominator; a
6311
+ * ramp would be a number nothing measured (D558 § 5.1).
6312
+ *
6313
+ * Every exit is named. A branch that accepts work and produces nothing is
6314
+ * the branch this repo keeps losing work in (D391), and a clip export has
6315
+ * five such branches a footage render does not have.
6316
+ */
6317
+ async fetchClip(id, rec, subject) {
6318
+ const tags = { deviceId: rec.deviceId };
6319
+ const now = (this.deps.now ?? Date.now)();
6320
+ if (subject.wake !== void 0 && now - rec.createdAt > 3e5) {
6321
+ const waitedMs = now - rec.createdAt;
6322
+ this.deps.logger.warn("clip export refused: it outlived the wake it was granted", {
6323
+ tags,
6324
+ meta: {
6325
+ exportId: id,
6326
+ clipId: subject.clipId,
6327
+ waitedMs,
6328
+ ttlMs: CLIP_WAKE_TTL_MS
6329
+ }
6330
+ });
6331
+ await this.fail(id, clipExportFailure("wake-expired", `queued ${Math.round(waitedMs / 1e3)}s ago, past the ${Math.round(CLIP_WAKE_TTL_MS / 1e3)}s an authorised wake stays spendable — ask again to wake the camera`));
6332
+ return;
6333
+ }
6334
+ const fetchClipBytes = this.deps.fetchClipBytes;
6335
+ const writeExportFile = this.deps.writeExportFile;
6336
+ if (fetchClipBytes === void 0 || writeExportFile === void 0) {
6337
+ this.deps.logger.error("clip export refused: this recorder has no clip byte reader wired", {
6338
+ tags,
6339
+ meta: {
6340
+ exportId: id,
6341
+ clipId: subject.clipId
6342
+ }
6343
+ });
6344
+ await this.fail(id, clipExportFailure("fetch-failed", "this recorder has no clip byte reader wired"));
6345
+ return;
6346
+ }
6347
+ await patchExport(this.deps.state, id, {
6348
+ state: "rendering",
6349
+ progressPct: null
6350
+ });
6351
+ this.deps.logger.info("clip export fetch starting", {
6352
+ tags,
6353
+ meta: {
6354
+ exportId: id,
6355
+ clipId: subject.clipId,
6356
+ source: subject.source,
6357
+ provider: subject.provider,
6358
+ profile: subject.profile,
6359
+ wake: subject.wake ?? "none"
6360
+ }
6361
+ });
6362
+ let answer;
6363
+ try {
6364
+ answer = await fetchClipBytes({
6365
+ deviceId: subject.deviceId,
6366
+ clipId: subject.clipId,
6367
+ profile: subject.profile,
6368
+ maxBytes: RECORDING_EXPORT_MAX_READ_BYTES,
6369
+ ...subject.wake !== void 0 ? { wake: subject.wake } : {}
6370
+ });
6371
+ } catch (err) {
6372
+ const detail = err instanceof Error ? err.message : String(err);
6373
+ const code = classifyClipFetchFailure(detail);
6374
+ this.deps.logger.warn("clip export fetch failed", {
6375
+ tags,
6376
+ meta: {
6377
+ exportId: id,
6378
+ clipId: subject.clipId,
6379
+ reason: code,
6380
+ error: detail
6381
+ }
6382
+ });
6383
+ await this.fail(id, clipExportFailure(code, detail));
6384
+ return;
6385
+ }
6386
+ if (this.cancelled.has(id)) {
6387
+ this.cancelled.delete(id);
6388
+ await this.fail(id, "cancelled");
6389
+ return;
6390
+ }
6391
+ const bytes = Buffer.from(answer.base64, "base64");
6392
+ if (bytes.byteLength > 52428800) {
6393
+ this.deps.logger.warn("clip export refused: the answer exceeded the transfer bound", {
6394
+ tags,
6395
+ meta: {
6396
+ exportId: id,
6397
+ bytes: bytes.byteLength,
6398
+ maxBytes: RECORDING_EXPORT_MAX_READ_BYTES
6399
+ }
6400
+ });
6401
+ await this.fail(id, clipExportFailure("too-large-to-transfer", `${bytes.byteLength} > ${RECORDING_EXPORT_MAX_READ_BYTES} bytes`));
6402
+ return;
6403
+ }
6404
+ if (bytes.byteLength < 1024) {
6405
+ this.deps.logger.error("clip export produced no video", {
6406
+ tags,
6407
+ meta: {
6408
+ exportId: id,
6409
+ clipId: subject.clipId,
6410
+ bytes: bytes.byteLength,
6411
+ minBytes: EXPORT_MIN_PLAUSIBLE_BYTES
6412
+ }
6413
+ });
6414
+ await this.fail(id, clipExportFailure("fetch-failed", `the source answered ${bytes.byteLength} bytes, under the ${EXPORT_MIN_PLAUSIBLE_BYTES} a playable MP4 needs`));
6415
+ return;
6416
+ }
6417
+ const outPath = this.deps.outPath(rec);
6418
+ try {
6419
+ await writeExportFile(outPath, bytes);
6420
+ } catch (err) {
6421
+ const detail = err instanceof Error ? err.message : String(err);
6422
+ this.deps.logger.error("clip export could not be written", {
6423
+ tags,
6424
+ meta: {
6425
+ exportId: id,
6426
+ outPath,
6427
+ error: detail
6428
+ }
6429
+ });
6430
+ await this.deps.removeFile(outPath);
6431
+ await this.fail(id, clipExportFailure("fetch-failed", `could not write the export: ${detail}`));
6432
+ return;
6433
+ }
6434
+ const servedPatch = answer.served !== rec.profile ? { profile: answer.served } : {};
6435
+ if (answer.served !== rec.profile) this.deps.logger.warn("clip export served a different twin than the catalog projected", {
6436
+ tags,
6437
+ meta: {
6438
+ exportId: id,
6439
+ clipId: subject.clipId,
6440
+ asked: subject.profile,
6441
+ projected: rec.profile,
6442
+ served: answer.served
6443
+ }
6444
+ });
6445
+ const claimedMs = rec.toMs - rec.fromMs;
6446
+ if (answer.durationMs !== void 0 && Math.abs(answer.durationMs - claimedMs) > CLIP_DURATION_TOLERANCE_MS) this.deps.logger.warn("clip export duration disagrees with the catalog row", {
6447
+ tags,
6448
+ meta: {
6449
+ exportId: id,
6450
+ clipId: subject.clipId,
6451
+ catalogSpanMs: claimedMs,
6452
+ deliveredMs: answer.durationMs
6453
+ }
6454
+ });
6455
+ await patchExport(this.deps.state, id, {
6456
+ state: "ready",
6457
+ progressPct: 100,
6458
+ fileBytes: bytes.byteLength,
6459
+ error: null,
6460
+ ...servedPatch
6461
+ });
6462
+ this.deps.logger.info("clip export ready", {
6463
+ tags,
6464
+ meta: {
6465
+ exportId: id,
6466
+ clipId: subject.clipId,
6467
+ outPath,
6468
+ bytes: bytes.byteLength,
6469
+ served: answer.served
6470
+ }
6471
+ });
6472
+ this.deps.emit(EventCategory.RecordingExportCompleted, {
6473
+ exportId: id,
6474
+ fileBytes: bytes.byteLength,
6475
+ deviceId: rec.deviceId,
6476
+ ...rec.options.title !== void 0 ? { title: rec.options.title } : {},
6477
+ ...rec.options.notifyTargetIds !== void 0 && rec.options.notifyTargetIds.length > 0 ? { notifyTargetIds: rec.options.notifyTargetIds } : {}
6478
+ });
6479
+ }
6480
+ /**
6242
6481
  * The record's options with any dense overlay moved onto ffmpeg's clock.
6243
6482
  *
6244
6483
  * The translation is reported on EVERY render that carries an overlay, not
@@ -6674,6 +6913,22 @@ function isInterrupted(record) {
6674
6913
  return record.state === "queued" || record.state === "rendering";
6675
6914
  }
6676
6915
  /**
6916
+ * Did this row carry an operator's authorised WAKE?
6917
+ *
6918
+ * A re-queue is the third of the three ways D558 § 5.2 rule 3 names for
6919
+ * spending one yes twice, and it is the quietest: the row reaches the fetch
6920
+ * hours after the tap, wakes the camera, and nothing in the log says the
6921
+ * operator did not ask for it. So a clip export holding a wake is FAILED by
6922
+ * name instead — a row he can retry with one tap, which re-asks for the
6923
+ * authorisation. A clip export WITHOUT a wake is re-queued like any render:
6924
+ * there is nothing to spend, and a sleeping camera refuses at its own gate
6925
+ * exactly as it did the first time.
6926
+ */
6927
+ function carriesAnAuthorisedWake(record) {
6928
+ const subject = exportSubjectOf(record);
6929
+ return subject.kind === "clip" && subject.wake !== void 0;
6930
+ }
6931
+ /**
6677
6932
  * Hand every interrupted row back to the engine, once, at boot.
6678
6933
  *
6679
6934
  * A row past its `expiresAt` is FAILED rather than re-rendered: hours of
@@ -6701,6 +6956,19 @@ async function reconcileInterruptedExports(deps) {
6701
6956
  toMs: row.toMs,
6702
6957
  createdAt: row.createdAt
6703
6958
  };
6959
+ if (carriesAnAuthorisedWake(row)) {
6960
+ expired += 1;
6961
+ await patchExport(deps.state, row.id, {
6962
+ state: "failed",
6963
+ progressPct: null,
6964
+ error: clipExportFailure("wake-expired", "interrupted by a restart — one authorised wake is one wake, so ask again to wake the camera")
6965
+ });
6966
+ deps.logger.warn("clip export abandoned: it was interrupted while holding a wake", {
6967
+ tags,
6968
+ meta
6969
+ });
6970
+ continue;
6971
+ }
6704
6972
  if (row.expiresAt <= now) {
6705
6973
  expired += 1;
6706
6974
  await patchExport(deps.state, row.id, {
@@ -13870,6 +14138,20 @@ function createVideoclipsProvider(deps) {
13870
14138
  }),
13871
14139
  format: "hls"
13872
14140
  };
14141
+ },
14142
+ /**
14143
+ * This source has no bytes to hand over, and says so rather than
14144
+ * inventing a path to them.
14145
+ *
14146
+ * An `analytics` clip is a time WINDOW over footage the recorder already
14147
+ * owns — there is no file behind it, and a caller that wants it as one
14148
+ * asks for it as an EXPORT, where the source playlist and
14149
+ * `export-dense-map` handle the holes a visit spans by construction
14150
+ * (D558 § 5.4.3). Reading it here would be this addon fetching from
14151
+ * itself, over a cap channel, in base64.
14152
+ */
14153
+ readClipBytes: async ({ clipId }) => {
14154
+ throw new Error(`videoclips: "${clipId}" is an analytics visit — a window over recorded footage with no file behind it. Export it through recordingExport with the same clip subject; the recorder renders it from its own segments.`);
13873
14155
  }
13874
14156
  };
13875
14157
  }
@@ -17275,6 +17557,81 @@ function makeBrokerCall(handle) {
17275
17557
  return (fn) => handle.call(fn, BROKER_READY_TIMEOUT_MS);
17276
17558
  }
17277
17559
  //#endregion
17560
+ //#region src/recorder/addon/export-clip-catalog.ts
17561
+ /**
17562
+ * Catalog page size for the confirm.
17563
+ *
17564
+ * One local day is the window (`ExportClipSubject.catalogWindow`) and a busy
17565
+ * day on 592 measured 546 rows, so 1 000 holds a day with room and still
17566
+ * bounds a pathological camera. A truncated page would read as "this clip is
17567
+ * gone", which is the one answer this gate must never give wrongly.
17568
+ */
17569
+ var EXPORT_CLIP_CATALOG_LIMIT = 1e3;
17570
+ /**
17571
+ * Which twin this row can actually serve for the asked profile.
17572
+ *
17573
+ * The mapping is the one D549 15 already fixed — `low | mid` → the sub file,
17574
+ * `high` → the main twin — and both ids are resolved at LISTING time, so this
17575
+ * never re-searches the camera. A row that holds only one twin answers with
17576
+ * the one it has and the caller SAYS so: the ask stays on `subject.profile`
17577
+ * and this lands on the record's top-level `profile`, so a week later the row
17578
+ * still tells the operator he was handed the sub stream.
17579
+ *
17580
+ * A row with no `streams` block at all is not a fallback and not a guess: the
17581
+ * ask is carried through and the producer's own `served` is what corrects it.
17582
+ */
17583
+ function servedTwinFor(clip, asked) {
17584
+ const streams = clip.streams;
17585
+ if (streams === void 0) return asked;
17586
+ const hasMain = streams.main !== void 0;
17587
+ const hasSub = streams.sub !== void 0;
17588
+ if (asked === "high") return hasMain ? "high" : hasSub ? "low" : asked;
17589
+ return hasSub ? asked : hasMain ? "high" : asked;
17590
+ }
17591
+ /**
17592
+ * Judge one catalog answer for one clip subject. Pure — the I/O is the
17593
+ * caller's, so every refusal below is unit-testable without a camera.
17594
+ */
17595
+ function judgeClipRow(subject, rows) {
17596
+ const clip = rows.find((row) => row.id === subject.clipId);
17597
+ if (clip === void 0) return {
17598
+ ok: false,
17599
+ refusal: {
17600
+ code: "catalog-miss",
17601
+ detail: `"${subject.sourceLabel}" does not list ${subject.clipId} between ${subject.catalogWindow.sinceMs} and ${subject.catalogWindow.untilMs}`
17602
+ }
17603
+ };
17604
+ if (clip.playable === false) return {
17605
+ ok: false,
17606
+ refusal: {
17607
+ code: "no-file-for-window",
17608
+ detail: clip.unplayableReason ?? "no bytes"
17609
+ }
17610
+ };
17611
+ if (clip.inProgress === true) return {
17612
+ ok: false,
17613
+ refusal: {
17614
+ code: "clip-in-progress",
17615
+ detail: "the camera is still writing this recording, so it has no end to export yet"
17616
+ }
17617
+ };
17618
+ const { startMs, endMs } = clip.timeRange;
17619
+ if (!(startMs < endMs)) return {
17620
+ ok: false,
17621
+ refusal: {
17622
+ code: "catalog-miss",
17623
+ detail: `the row carries no usable span (${startMs}..${endMs})`
17624
+ }
17625
+ };
17626
+ return {
17627
+ ok: true,
17628
+ accepted: {
17629
+ clip,
17630
+ served: servedTwinFor(clip, subject.profile)
17631
+ }
17632
+ };
17633
+ }
17634
+ //#endregion
17278
17635
  //#region src/recorder/addon/recording-export-provider.ts
17279
17636
  /** Content type of every rendered export — the engine only ever writes MP4. */
17280
17637
  var EXPORT_CONTENT_TYPE = "video/mp4";
@@ -17302,12 +17659,6 @@ function exportFileName(rec) {
17302
17659
  async function hasFootage(index, deviceId, profile, fromMs, toMs) {
17303
17660
  return (await index.segmentsInWindow(deviceId, profile, fromMs, toMs)).some((s) => s.startMs < toMs && s.startMs + s.durMs > fromMs);
17304
17661
  }
17305
- /** Canonical `profiles[]`, falling back to the legacy singular `profile`. */
17306
- function resolveExportProfiles(input) {
17307
- if (input.profiles !== void 0 && input.profiles.length > 0) return [...input.profiles];
17308
- if (typeof input.profile === "string" && input.profile.length > 0) return [input.profile];
17309
- return [];
17310
- }
17311
17662
  /** Load a record or throw a clear NOT_FOUND-style error. */
17312
17663
  async function requireRecord(state, exportId) {
17313
17664
  const rec = await getExportRecord(state, exportId);
@@ -17316,37 +17667,133 @@ async function requireRecord(state, exportId) {
17316
17667
  }
17317
17668
  /** Build the `recordingExport` provider over the injected deps. */
17318
17669
  function buildRecordingExportProvider(deps) {
17670
+ /**
17671
+ * Persist one `queued` row and hand it to the engine. The ONE place a record
17672
+ * is born, for both kinds — so the fields nothing about the subject decides
17673
+ * (the lifetime, the audit stamp, the null progress) cannot drift apart.
17674
+ */
17675
+ const queueOne = async (fields, options, now) => {
17676
+ const saved = await upsertExport(deps.state, {
17677
+ ...fields,
17678
+ id: deps.newId(),
17679
+ options,
17680
+ state: "queued",
17681
+ progressPct: null,
17682
+ fileBytes: null,
17683
+ expiresAt: now + options.maxLifeMs,
17684
+ deleteAfterDownload: options.deleteAfterDownload,
17685
+ downloadedAt: null,
17686
+ createdAt: now,
17687
+ createdBy: deps.createdBy(),
17688
+ error: null
17689
+ });
17690
+ deps.engine.enqueue(saved.id);
17691
+ return saved;
17692
+ };
17693
+ /**
17694
+ * The clip branch's fail-fast gate — the catalog, never the recording index.
17695
+ *
17696
+ * Refuses BEFORE a row exists, so an operator gets the reason in the answer
17697
+ * to his own tap instead of discovering it on a `failed` row a minute later,
17698
+ * and so a refusal never spends a wake.
17699
+ */
17700
+ const createClipExport = async (subject, options) => {
17701
+ const tags = { deviceId: subject.deviceId };
17702
+ if (options.timelapse !== void 0 || options.speed !== void 0 && options.speed !== 1) {
17703
+ const detail = "a clip is remuxed, never re-timed — drop speed/timelapse";
17704
+ deps.logger.warn("clip export refused: a render option a remux cannot honour", {
17705
+ tags,
17706
+ meta: {
17707
+ clipId: subject.clipId,
17708
+ speed: options.speed,
17709
+ timelapse: options.timelapse
17710
+ }
17711
+ });
17712
+ throw new Error(clipExportFailure("unsupported-option", detail));
17713
+ }
17714
+ let rows;
17715
+ try {
17716
+ rows = await deps.clipCatalog.listClips({
17717
+ deviceId: subject.deviceId,
17718
+ since: subject.catalogWindow.sinceMs,
17719
+ until: subject.catalogWindow.untilMs,
17720
+ provider: subject.provider,
17721
+ limit: EXPORT_CLIP_CATALOG_LIMIT
17722
+ });
17723
+ } catch (err) {
17724
+ const detail = err instanceof Error ? err.message : String(err);
17725
+ deps.logger.warn("clip export refused: the clip catalog could not be read", {
17726
+ tags,
17727
+ meta: {
17728
+ clipId: subject.clipId,
17729
+ provider: subject.provider,
17730
+ error: detail
17731
+ }
17732
+ });
17733
+ throw new Error(clipExportFailure("catalog-unreachable", detail), { cause: err });
17734
+ }
17735
+ const outcome = judgeClipRow(subject, rows);
17736
+ if (!outcome.ok) {
17737
+ deps.logger.warn("clip export refused by the catalog gate", {
17738
+ tags,
17739
+ meta: {
17740
+ clipId: subject.clipId,
17741
+ provider: subject.provider,
17742
+ reason: outcome.refusal.code,
17743
+ detail: outcome.refusal.detail
17744
+ }
17745
+ });
17746
+ throw new Error(clipExportFailure(outcome.refusal.code, outcome.refusal.detail));
17747
+ }
17748
+ const { clip, served } = outcome.accepted;
17749
+ const record = await queueOne({
17750
+ deviceId: subject.deviceId,
17751
+ profile: served,
17752
+ fromMs: clip.timeRange.startMs,
17753
+ toMs: clip.timeRange.endMs,
17754
+ subject
17755
+ }, options, deps.now());
17756
+ deps.logger.info("clip export queued", {
17757
+ tags,
17758
+ meta: {
17759
+ exportId: record.id,
17760
+ clipId: subject.clipId,
17761
+ source: subject.source,
17762
+ provider: subject.provider,
17763
+ askedProfile: subject.profile,
17764
+ servedProfile: served,
17765
+ wake: subject.wake ?? "none",
17766
+ fromMs: record.fromMs,
17767
+ toMs: record.toMs
17768
+ }
17769
+ });
17770
+ return record;
17771
+ };
17319
17772
  return {
17320
17773
  createExport: async (input) => {
17321
- const { deviceId, fromMs, toMs, options } = input;
17322
- const profiles = resolveExportProfiles(input);
17323
- if (profiles.length < 1) throw new Error("recording-export: profiles must contain at least one profile");
17774
+ const subject = resolveCreateExportSubject(input);
17775
+ if (subject.kind === "clip") return await createClipExport(subject, input.options);
17776
+ const { deviceId, profiles, fromMs, toMs } = subject;
17777
+ const { options } = input;
17324
17778
  if (!(fromMs < toMs)) throw new Error(`recording-export: invalid range ${fromMs}..${toMs}`);
17325
17779
  for (const profile of profiles) if (!await hasFootage(deps.index, deviceId, profile, fromMs, toMs)) throw new Error(`recording-export: no footage for ${deviceId}/${profile} in ${fromMs}..${toMs}`);
17326
17780
  const now = deps.now();
17327
- let first = null;
17328
- for (const profile of profiles) {
17329
- const record = {
17330
- id: deps.newId(),
17331
- deviceId,
17332
- profile,
17333
- fromMs,
17334
- toMs,
17335
- options,
17336
- state: "queued",
17337
- progressPct: null,
17338
- fileBytes: null,
17339
- expiresAt: now + options.maxLifeMs,
17340
- deleteAfterDownload: options.deleteAfterDownload,
17341
- downloadedAt: null,
17342
- createdAt: now,
17343
- createdBy: deps.createdBy(),
17344
- error: null
17345
- };
17346
- const saved = await upsertExport(deps.state, record);
17347
- deps.engine.enqueue(saved.id);
17348
- first ??= saved;
17349
- }
17781
+ const [head, ...rest] = profiles;
17782
+ if (head === void 0) throw new Error("recording-export: profiles must contain at least one profile");
17783
+ const first = await queueOne({
17784
+ deviceId,
17785
+ profile: head,
17786
+ fromMs,
17787
+ toMs,
17788
+ subject
17789
+ }, options, now);
17790
+ for (const profile of rest) await queueOne({
17791
+ deviceId,
17792
+ profile,
17793
+ fromMs,
17794
+ toMs,
17795
+ subject
17796
+ }, options, now);
17350
17797
  return first;
17351
17798
  },
17352
17799
  listExports: ({ deviceId }) => listExportsFor(deps.state, deviceId),
@@ -19121,7 +19568,19 @@ var RecorderV2Addon = class extends BaseAddon {
19121
19568
  outPath: exportOutPath,
19122
19569
  statBytes: async (p) => (await promises.stat(p)).size,
19123
19570
  removeFile: removeExportFile,
19124
- emit: (category, data) => this.emitExportEvent(category, data)
19571
+ emit: (category, data) => this.emitExportEvent(category, data),
19572
+ now: () => Date.now(),
19573
+ fetchClipBytes: async (req) => await this.ctx.api.videoclips.readClipBytes.query({
19574
+ deviceId: req.deviceId,
19575
+ clipId: req.clipId,
19576
+ profile: req.profile,
19577
+ maxBytes: req.maxBytes,
19578
+ ...req.wake !== void 0 ? { wake: req.wake } : {}
19579
+ }),
19580
+ writeExportFile: async (p, bytes) => {
19581
+ await promises.mkdir(path.dirname(p), { recursive: true });
19582
+ await promises.writeFile(p, bytes);
19583
+ }
19125
19584
  });
19126
19585
  const exportProvider = buildRecordingExportProvider({
19127
19586
  state: exportsState,
@@ -19130,6 +19589,7 @@ var RecorderV2Addon = class extends BaseAddon {
19130
19589
  if (this.index.hydrationOf(deviceId, fromMs, toMs) !== "hydrated") await hydrateWindowFromStorage(this.index, deviceId, fromMs, toMs, this.resolvedLocations, this.ctx.logger, this.segmentHours ?? void 0);
19131
19590
  return this.index.segments(deviceId, profile);
19132
19591
  } },
19592
+ clipCatalog: { listClips: async (input) => await this.ctx.api.videoclips.listClips.query(input) },
19133
19593
  now: () => Date.now(),
19134
19594
  newId: () => randomUUID(),
19135
19595
  createdBy: () => "operator",
@@ -1,5 +1,5 @@
1
1
  import { r as __toESM, t as __commonJSMin } from "./chunk-DnnnRqeS.mjs";
2
- import { Vt as errMsg } from "./dist-g5MfpiBh.mjs";
2
+ import { Gt as errMsg } from "./dist-C1pCVJk7.mjs";
3
3
  import { spawn } from "node:child_process";
4
4
  //#region ../../node_modules/mp4box/dist/mp4box.all.js
5
5
  var require_mp4box_all = /* @__PURE__ */ __commonJSMin(((exports) => {
@@ -1,5 +1,5 @@
1
1
  const require_chunk = require("./chunk-emK7D4bc.js");
2
- const require_dist = require("./dist-k6Vu-AhZ.js");
2
+ const require_dist = require("./dist-NYjn7hkE.js");
3
3
  let node_child_process = require("node:child_process");
4
4
  //#region ../../node_modules/mp4box/dist/mp4box.all.js
5
5
  var require_mp4box_all = /* @__PURE__ */ require_chunk.__commonJSMin(((exports) => {
@@ -1,7 +1,7 @@
1
- import { a as e, c as t, d as n, f as r, i, l as a, n as o, o as s, p as c, r as l, s as u, t as d, u as f } from "./_virtual_mf___mfe_internal__addon_stream_broker_widgets__loadShare___mf_0_camstack_mf_1_ui_mf_2_library__loadShare__.js-MU3_q1MX.mjs";
1
+ import { a as e, c as t, d as n, f as r, i, l as a, n as o, o as s, p as c, r as l, s as u, t as d, u as f } from "./_virtual_mf___mfe_internal__addon_stream_broker_widgets__loadShare___mf_0_camstack_mf_1_ui_mf_2_library__loadShare__.js-BnLVuoDg.mjs";
2
2
  import { a as p, i as m, n as h, o as g, r as _, t as v } from "./_virtual_mf___mfe_internal__addon_stream_broker_widgets__loadShare__react__loadShare__.js-C9j-2lBe.mjs";
3
3
  import { n as y, r as b, t as x } from "./_virtual_mf___mfe_internal__addon_stream_broker_widgets__loadShare__react_mf_1_jsx_mf_2_runtime__loadShare__.js-XO0-Pyu6.mjs";
4
- import { t as S } from "./_virtual_mf___mfe_internal__addon_stream_broker_widgets__loadShare___mf_0_camstack_mf_1_types__loadShare__.js-BlXyfeXU.mjs";
4
+ import { t as S } from "./_virtual_mf___mfe_internal__addon_stream_broker_widgets__loadShare___mf_0_camstack_mf_1_types__loadShare__.js-BV2tQ1w3.mjs";
5
5
  import { n as C, t as w } from "./_virtual_mf___mfe_internal__addon_stream_broker_widgets__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-BO7TIbJV.mjs";
6
6
  //#region ../../node_modules/lucide-react/dist/esm/shared/src/utils/mergeClasses.js
7
7
  var T = (...e) => e.filter((e, t, n) => !!e && e.trim() !== "" && n.indexOf(e) === t).join(" ").trim(), E = (e) => e.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase(), D = (e) => e.replace(/^([A-Z])|[\s-_]+(\w)/g, (e, t, n) => n ? n.toUpperCase() : t.toLowerCase()), O = (e) => {
@@ -18,7 +18,7 @@ var e = {
18
18
  },
19
19
  "@camstack/types": {
20
20
  name: "@camstack/types",
21
- version: "1.2.236",
21
+ version: "1.2.238",
22
22
  scope: ["default"],
23
23
  loaded: !1,
24
24
  from: "addon_stream_broker_widgets",
@@ -33,7 +33,7 @@ var e = {
33
33
  },
34
34
  "@camstack/ui-library": {
35
35
  name: "@camstack/ui-library",
36
- version: "1.2.192",
36
+ version: "1.2.194",
37
37
  scope: ["default"],
38
38
  loaded: !1,
39
39
  from: "addon_stream_broker_widgets",