@camstack/addon-pipeline 1.2.273 → 1.2.274

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-DCFaNnYd.mjs → default-detection-model-BXwE-Dvo.mjs} +1 -1
  4. package/dist/{default-detection-model-9Solpn0K.js → default-detection-model-CAWhHQo2.js} +1 -1
  5. package/dist/detection-pipeline/index.js +4 -4
  6. package/dist/detection-pipeline/index.mjs +4 -4
  7. package/dist/{dist-BRT-qKlE.mjs → dist-g5MfpiBh.mjs} +194 -98
  8. package/dist/{dist-DRDzfOnl.js → dist-k6Vu-AhZ.js} +217 -97
  9. package/dist/motion-wasm/index.js +1 -1
  10. package/dist/motion-wasm/index.mjs +1 -1
  11. package/dist/{node-BmTPPuIg.js → node--u_jUObS.js} +1 -1
  12. package/dist/{node-Dwu66ZR4.mjs → node-BXsHQH5h.mjs} +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-BTwHfysZ.js → process-memory-DN7opum2.js} +1 -1
  16. package/dist/{process-memory-Cx4oDFz9.mjs → process-memory-Gl3EowL-.mjs} +1 -1
  17. package/dist/recorder/index.js +570 -2
  18. package/dist/recorder/index.mjs +570 -2
  19. package/dist/{segment-demux-js--ePyI476.js → segment-demux-js-DHX8o8pI.js} +1 -1
  20. package/dist/{segment-demux-js-BKvYCad_.mjs → segment-demux-js-sYP_jndp.mjs} +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-shbmpL8E.mjs → _virtual_mf-localSharedImportMap___mfe_internal__addon_stream_broker_widgets-CEy8IryH.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-BlXyfeXU.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-C8RTK6nJ.mjs → _virtual_mf___mfe_internal__addon_stream_broker_widgets__loadShare___mf_0_camstack_mf_1_ui_mf_2_library__loadShare__.js-MU3_q1MX.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-CtVYKCNe.mjs → hostInit-UKNN4qes.mjs} +2 -2
  28. package/dist/stream-broker/index.js +3 -3
  29. package/dist/stream-broker/index.mjs +3 -3
  30. package/dist/stream-broker/remoteEntry.js +1 -1
  31. package/package.json +5 -1
  32. package/dist/stream-broker/_virtual_mf___mfe_internal__addon_stream_broker_widgets__loadShare___mf_0_camstack_mf_1_types__loadShare__.js-C_SEu7AC.mjs +0 -26
@@ -3,8 +3,8 @@ Object.defineProperties(exports, {
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
5
  const require_chunk = require("../chunk-emK7D4bc.js");
6
- const require_dist = require("../dist-DRDzfOnl.js");
7
- const require_node = require("../node-BmTPPuIg.js");
6
+ const require_dist = require("../dist-k6Vu-AhZ.js");
7
+ const require_node = require("../node--u_jUObS.js");
8
8
  const require_hub_hostname = require("../hub-hostname-DAJXlOgV.js");
9
9
  const require_restream_intent = require("../restream-intent-7uDNqMKs.js");
10
10
  const require_retire_root_keys = require("../retire-root-keys-Csb8z2f3.js");
@@ -13496,6 +13496,567 @@ var PlacementService = class {
13496
13496
  }
13497
13497
  };
13498
13498
  //#endregion
13499
+ //#region src/recorder/addon/videoclip-visits.ts
13500
+ /**
13501
+ * Videoclip visits — the grain a clip should have on an events-mode camera.
13502
+ *
13503
+ * Disk writes one fMP4 per ffmpeg roll (~8–12 s). The recorder calendar merges
13504
+ * only gaps ≤ 5 s, so a single pantry walk shows up as several availability
13505
+ * ranges with ~8 s GOP holes between them. Analytics then mints one 15 s clip
13506
+ * per motion heartbeat. A *visit* is the keep-window those fragments belong
13507
+ * to: cluster availability with {@link VISIT_MERGE_GAP_MS}, annotate with
13508
+ * overlapping events. No second copy of the media; the files stay the source
13509
+ * of truth.
13510
+ */
13511
+ /** Synthetic event-id slot in `analytics:<start>:<end>:<id>` for a visit clip. */
13512
+ var VISIT_EVENT_ID = "visit";
13513
+ function clusterFootageVisits(ranges, gapMs = require_dist.VISIT_MERGE_GAP_MS) {
13514
+ if (ranges.length === 0) return [];
13515
+ const sorted = [...ranges].toSorted((a, b) => a.startMs - b.startMs);
13516
+ const visits = [];
13517
+ let pieces = [sorted[0]];
13518
+ let endMs = sorted[0].endMs;
13519
+ for (let i = 1; i < sorted.length; i++) {
13520
+ const next = sorted[i];
13521
+ if (next.startMs <= endMs + gapMs) {
13522
+ pieces.push(next);
13523
+ endMs = Math.max(endMs, next.endMs);
13524
+ continue;
13525
+ }
13526
+ visits.push(finishVisit(pieces, endMs));
13527
+ pieces = [next];
13528
+ endMs = next.endMs;
13529
+ }
13530
+ visits.push(finishVisit(pieces, endMs));
13531
+ return visits;
13532
+ }
13533
+ function finishVisit(pieces, endMs) {
13534
+ const holes = [];
13535
+ for (let i = 1; i < pieces.length; i++) {
13536
+ const prevEnd = pieces[i - 1].endMs;
13537
+ const nextStart = pieces[i].startMs;
13538
+ if (nextStart > prevEnd) holes.push({
13539
+ startMs: prevEnd,
13540
+ endMs: nextStart
13541
+ });
13542
+ }
13543
+ return {
13544
+ startMs: pieces[0].startMs,
13545
+ endMs,
13546
+ ranges: pieces,
13547
+ holes
13548
+ };
13549
+ }
13550
+ var KIND_ORDER = [
13551
+ "object",
13552
+ "motion",
13553
+ "audio"
13554
+ ];
13555
+ function eventOverlapsVisit(event, visit, pad) {
13556
+ if (event.timestamp >= visit.startMs && event.timestamp <= visit.endMs) return true;
13557
+ const windowStart = event.timestamp - pad.preMs;
13558
+ const windowEnd = event.timestamp + pad.postMs;
13559
+ return windowStart < visit.endMs && windowEnd > visit.startMs;
13560
+ }
13561
+ function dominantKind(attached) {
13562
+ for (const kind of KIND_ORDER) if (attached.some((a) => a.kind === kind)) return kind;
13563
+ return "motion";
13564
+ }
13565
+ /**
13566
+ * The instant a recorded still can actually be decoded inside a visit: the
13567
+ * midpoint of its LONGEST contiguous range.
13568
+ *
13569
+ * NOT the midpoint of the visit. A visit spans its holes by construction (it is
13570
+ * ranges glued across gaps up to `VISIT_MERGE_GAP_MS`), so the naive midpoint
13571
+ * lands in dead air roughly as often as not and the recorder's still route
13572
+ * answers 204 for a visit with plenty of footage.
13573
+ */
13574
+ function stillInstantMs(ranges) {
13575
+ let best;
13576
+ for (const range of ranges) if (best === void 0 || range.endMs - range.startMs > best.endMs - best.startMs) best = range;
13577
+ if (best === void 0) return void 0;
13578
+ return Math.floor((best.startMs + best.endMs) / 2);
13579
+ }
13580
+ /**
13581
+ * The distinct object classes attached to a visit, most frequent first,
13582
+ * capped at {@link MAX_CLIP_LABELS}. Empty when nothing classified overlapped
13583
+ * — the caller then omits the field so a motion/audio-only visit keeps its
13584
+ * kind label instead of carrying an empty array every consumer length-checks.
13585
+ */
13586
+ function dominantLabels(attached) {
13587
+ const counts = /* @__PURE__ */ new Map();
13588
+ for (const a of attached) {
13589
+ if (a.kind !== "object") continue;
13590
+ const name = a.event.className;
13591
+ if (typeof name !== "string" || name.length === 0) continue;
13592
+ counts.set(name, (counts.get(name) ?? 0) + 1);
13593
+ }
13594
+ return [...counts.entries()].toSorted((x, y) => y[1] - x[1]).slice(0, 3).map(([name]) => name);
13595
+ }
13596
+ function visitsToClips(visits, events, pad, vouched) {
13597
+ const tagged = [
13598
+ ...events.object.map((event) => ({
13599
+ kind: "object",
13600
+ event
13601
+ })),
13602
+ ...events.motion.map((event) => ({
13603
+ kind: "motion",
13604
+ event
13605
+ })),
13606
+ ...events.audio.map((event) => ({
13607
+ kind: "audio",
13608
+ event
13609
+ }))
13610
+ ];
13611
+ return visits.map((visit) => {
13612
+ const attached = tagged.filter((t) => eventOverlapsVisit(t.event, visit, pad));
13613
+ const kind = dominantKind(attached);
13614
+ const withThumb = attached.find((a) => a.kind === kind && a.event.mediaUrl && vouched.has(a.event.id)) ?? attached.find((a) => a.event.mediaUrl && vouched.has(a.event.id));
13615
+ const stillAtMs = stillInstantMs(visit.ranges);
13616
+ const labels = dominantLabels(attached);
13617
+ return {
13618
+ id: `analytics:${visit.startMs}:${visit.endMs}:${VISIT_EVENT_ID}`,
13619
+ source: "analytics",
13620
+ kind,
13621
+ timeRange: {
13622
+ startMs: visit.startMs,
13623
+ endMs: visit.endMs
13624
+ },
13625
+ ...withThumb?.event.mediaUrl !== void 0 ? { thumbnail: withThumb.event.mediaUrl } : {},
13626
+ ...stillAtMs !== void 0 ? { stillAtMs } : {},
13627
+ eventIds: attached.slice(0, 24).map((a) => a.event.id),
13628
+ eventCount: attached.length,
13629
+ holes: [...visit.holes],
13630
+ ...labels.length > 0 ? { labels } : {}
13631
+ };
13632
+ }).toSorted((a, b) => b.timeRange.startMs - a.timeRange.startMs);
13633
+ }
13634
+ //#endregion
13635
+ //#region src/recorder/addon/videoclips-provider.ts
13636
+ /**
13637
+ * Default `videoclips` provider — composes recorded footage visits with the
13638
+ * analytics event log. A clip is a time-WINDOW over existing footage, never a
13639
+ * separate file: `getClipPlayback` resolves to
13640
+ * `recording.getPlaybackManifest(startMs, endMs)`.
13641
+ *
13642
+ * When availability is present the grain is a *visit* (events-mode keep-window
13643
+ * clustered at `VISIT_MERGE_GAP_MS`), not one clip per motion heartbeat. The
13644
+ * clip id still encodes the window (`analytics:<startMs>:<endMs>:visit`) so
13645
+ * playback is self-contained. Without availability (or when that read fails)
13646
+ * the provider falls back to per-event padded windows.
13647
+ *
13648
+ * Pure helpers (`eventsToClips` / `clusterFootageVisits` / `clipIdFor` /
13649
+ * `parseClipId`) are unit-tested in isolation; the provider factory wires
13650
+ * injected fetch/resolve deps so the compose logic is testable without I/O.
13651
+ */
13652
+ var SOURCE = "analytics";
13653
+ /** The addon that registers this provider — stamped on its source row. */
13654
+ var CLIP_SOURCE_ADDON_ID = "recorder";
13655
+ /**
13656
+ * Backstop on the ANNOTATION read — never on the clip list.
13657
+ *
13658
+ * A visit is annotated by every event inside it, so the clip `limit` must not
13659
+ * reach this fetch (one 615 visit legitimately spans 2 345 motion rows). This
13660
+ * bound exists only so a pathological camera-day cannot pull an unbounded page:
13661
+ * the store orders `timestamp DESC`, so a truncation drops the OLDEST rows and
13662
+ * the EARLIEST visits silently lose their annotations — which is why hitting it
13663
+ * is logged, per camera, rather than absorbed.
13664
+ */
13665
+ var VISIT_EVENT_FETCH_LIMIT = 5e3;
13666
+ function clipIdFor(eventId, startMs, endMs) {
13667
+ return `${SOURCE}:${startMs}:${endMs}:${eventId}`;
13668
+ }
13669
+ /** Parse a default-provider clip id back into its window + event id. Returns
13670
+ * `null` for any id this provider did not mint (e.g. a native clip id). */
13671
+ function parseClipId(clipId) {
13672
+ const parts = clipId.split(":");
13673
+ if (parts.length < 4 || parts[0] !== SOURCE) return null;
13674
+ const startMs = Number(parts[1]);
13675
+ const endMs = Number(parts[2]);
13676
+ if (!Number.isFinite(startMs) || !Number.isFinite(endMs)) return null;
13677
+ const eventId = parts.slice(3).join(":");
13678
+ if (!eventId) return null;
13679
+ return {
13680
+ eventId,
13681
+ startMs,
13682
+ endMs
13683
+ };
13684
+ }
13685
+ /** Map per-kind events into time-ranged clips, newest-first. Pure. */
13686
+ function eventsToClips(events, pad, vouched) {
13687
+ const make = (e, kind) => {
13688
+ const startMs = e.timestamp - pad.preMs;
13689
+ const endMs = e.timestamp + pad.postMs;
13690
+ return {
13691
+ id: clipIdFor(e.id, startMs, endMs),
13692
+ source: SOURCE,
13693
+ kind,
13694
+ timeRange: {
13695
+ startMs,
13696
+ endMs
13697
+ },
13698
+ ...e.mediaUrl !== void 0 && vouched.has(e.id) ? { thumbnail: e.mediaUrl } : {}
13699
+ };
13700
+ };
13701
+ return [
13702
+ ...events.motion.map((e) => make(e, "motion")),
13703
+ ...events.object.map((e) => make(e, "object")),
13704
+ ...events.audio.map((e) => make(e, "audio"))
13705
+ ].toSorted((a, b) => b.timeRange.startMs - a.timeRange.startMs);
13706
+ }
13707
+ /** Every id in the three buckets, in the order the composers tag them. */
13708
+ function allEventIds(events) {
13709
+ return [
13710
+ ...events.motion,
13711
+ ...events.object,
13712
+ ...events.audio
13713
+ ].map((e) => e.id);
13714
+ }
13715
+ /**
13716
+ * Resolve the event ids whose `mediaUrl` is backed by real bytes, mirroring
13717
+ * `resolveDefaultEventMedia`: the event's OWN media when it has any, else its
13718
+ * owning TRACK's. Up to four batched index reads — one PER EVENT KIND that has
13719
+ * any ids (D476: `motion` / `object` / `audio` are separate owner kinds now,
13720
+ * so a single combined read can no longer ask "does any of these ids own
13721
+ * media" — a motion id and an object id can be the same number post-D474 and
13722
+ * are answered by different rows) — plus the track fallback, only over the
13723
+ * object events the first pass did not already answer for (motion and audio
13724
+ * are trackless roots, so they never need it).
13725
+ *
13726
+ * THROWS on a failed read. The caller fails closed on the CLAIM and open on the
13727
+ * LIST; swallowing here would collapse those two opposite directions into one.
13728
+ */
13729
+ async function resolveVouchedEvents(deviceId, events, fetchMediaOwners) {
13730
+ const ownMedia = /* @__PURE__ */ new Set();
13731
+ for (const ownerType of require_dist.EVENT_OWNER_TYPES) {
13732
+ const ownerIds = events[ownerType].map((e) => e.id);
13733
+ if (ownerIds.length === 0) continue;
13734
+ const found = await fetchMediaOwners({
13735
+ deviceId,
13736
+ ownerKind: ownerType,
13737
+ ownerIds
13738
+ });
13739
+ for (const id of found) ownMedia.add(id);
13740
+ }
13741
+ const residualTracks = [];
13742
+ const seenTracks = /* @__PURE__ */ new Set();
13743
+ for (const event of events.object) {
13744
+ const trackId = event.trackId;
13745
+ if (trackId === void 0 || ownMedia.has(event.id) || seenTracks.has(trackId)) continue;
13746
+ seenTracks.add(trackId);
13747
+ residualTracks.push(trackId);
13748
+ }
13749
+ const trackMedia = residualTracks.length === 0 ? /* @__PURE__ */ new Set() : await fetchMediaOwners({
13750
+ deviceId,
13751
+ ownerKind: "track",
13752
+ ownerIds: residualTracks
13753
+ });
13754
+ const vouched = new Set(ownMedia);
13755
+ for (const event of events.object) {
13756
+ const trackId = event.trackId;
13757
+ if (trackId !== void 0 && trackMedia.has(trackId)) vouched.add(event.id);
13758
+ }
13759
+ return vouched;
13760
+ }
13761
+ /** Keep only clips that actually touch the caller's window. The reads are
13762
+ * widened by {@link leftOverhangMs}; the ANSWER is not. */
13763
+ function intersectsWindow(clip, since, until) {
13764
+ return clip.timeRange.startMs < until && clip.timeRange.endMs > since;
13765
+ }
13766
+ /**
13767
+ * How far BEFORE `since` the event + availability reads must reach.
13768
+ *
13769
+ * A visit straddling `since` keeps its heartbeat rows and loses the transition
13770
+ * row — the only one that ever carries a snapshot — so the same visit shows a
13771
+ * picture or doesn't depending on where the operator scrolled. One wider range
13772
+ * scan on an indexed column buys a list that stops changing under the cursor.
13773
+ */
13774
+ function leftOverhangMs(pad) {
13775
+ return require_dist.VISIT_MERGE_GAP_MS + pad.preMs;
13776
+ }
13777
+ /** No events at all — what the degraded branch annotates its visits with. */
13778
+ var NO_EVENTS = {
13779
+ motion: [],
13780
+ object: [],
13781
+ audio: []
13782
+ };
13783
+ function createVideoclipsProvider(deps) {
13784
+ /**
13785
+ * Cameras whose LAST `listClips` could not read the analytics event log, with
13786
+ * the refusal verbatim.
13787
+ *
13788
+ * Not a cache of anybody else's fact (D224): it is this provider reporting
13789
+ * what IT just did, refreshed on the same call that produces it and cleared
13790
+ * by the next read that succeeds. `listSources` has no window argument and
13791
+ * must not go and ask again — an extra events read on the listing path would
13792
+ * be a second, disagreeing answer to the question `listClips` already
13793
+ * answered.
13794
+ */
13795
+ const eventsUnreachable = /* @__PURE__ */ new Map();
13796
+ return {
13797
+ listClips: async ({ deviceId, since, until, limit }) => {
13798
+ const readSince = since - leftOverhangMs(deps.defaultPad);
13799
+ let events;
13800
+ try {
13801
+ events = await deps.fetchEvents({
13802
+ deviceId,
13803
+ since: readSince,
13804
+ until,
13805
+ limit: deps.fetchAvailability ? VISIT_EVENT_FETCH_LIMIT : limit
13806
+ });
13807
+ } catch (err) {
13808
+ return await listWithoutEvents(deps, eventsUnreachable, errMessage(err), {
13809
+ deviceId,
13810
+ since,
13811
+ until,
13812
+ readSince,
13813
+ limit
13814
+ });
13815
+ }
13816
+ eventsUnreachable.delete(deviceId);
13817
+ warnOnTruncatedFetch(deps, deviceId, events);
13818
+ let vouched = /* @__PURE__ */ new Set();
13819
+ try {
13820
+ vouched = await resolveVouchedEvents(deviceId, events, deps.fetchMediaOwners);
13821
+ } catch (err) {
13822
+ deps.logWarn?.("videoclips: media presence read failed — listing without thumbnails", {
13823
+ deviceId,
13824
+ events: allEventIds(events).length,
13825
+ error: err instanceof Error ? err.message : String(err)
13826
+ });
13827
+ }
13828
+ let clips = eventsToClips(events, deps.defaultPad, vouched);
13829
+ if (deps.fetchAvailability) try {
13830
+ clips = visitsToClips(clusterFootageVisits(await deps.fetchAvailability({
13831
+ deviceId,
13832
+ since: readSince,
13833
+ until
13834
+ }), require_dist.VISIT_MERGE_GAP_MS), events, deps.defaultPad, vouched);
13835
+ } catch (err) {
13836
+ deps.logWarn?.("videoclips: availability read failed — listing unfiltered", {
13837
+ deviceId,
13838
+ error: err instanceof Error ? err.message : String(err)
13839
+ });
13840
+ }
13841
+ const inWindow = clips.filter((c) => intersectsWindow(c, since, until));
13842
+ const answer = limit != null ? inWindow.slice(0, limit) : inWindow;
13843
+ reportUnvouchedClips(deps, deviceId, answer);
13844
+ return answer;
13845
+ },
13846
+ /**
13847
+ * The one source this provider serves, on every camera: the hub's own
13848
+ * analytics visits over recorded footage.
13849
+ *
13850
+ * Always `ok`, and that is not optimism — this source IS the process
13851
+ * answering the call, so there is no reachability question to report. A
13852
+ * read that fails INSIDE `listClips` degrades that list (and logs it); a
13853
+ * source that cannot be reached at all is reported by the collection
13854
+ * dispatcher, which is the only layer that can tell the difference.
13855
+ * `label` is what the picker draws.
13856
+ */
13857
+ listSources: async ({ deviceId }) => {
13858
+ const outage = eventsUnreachable.get(deviceId);
13859
+ return [{
13860
+ source: SOURCE,
13861
+ addonId: CLIP_SOURCE_ADDON_ID,
13862
+ label: "CamStack recordings",
13863
+ availability: outage === void 0 ? { state: "ok" } : {
13864
+ state: "ok",
13865
+ reason: `${EVENTS_UNREACHABLE_NOTICE} (${outage})`
13866
+ }
13867
+ }];
13868
+ },
13869
+ getClipPlayback: async ({ deviceId, clipId }) => {
13870
+ const parsed = parseClipId(clipId);
13871
+ if (!parsed) throw new Error(`videoclips: unrecognized clipId "${clipId}"`);
13872
+ return {
13873
+ ...await deps.resolvePlayback({
13874
+ deviceId,
13875
+ startMs: parsed.startMs,
13876
+ endMs: parsed.endMs
13877
+ }),
13878
+ format: "hls"
13879
+ };
13880
+ }
13881
+ };
13882
+ }
13883
+ /** What the source row says while the event log is down. */
13884
+ var EVENTS_UNREACHABLE_NOTICE = "The analytics event log could not be read on the last listing — these clips are recorded footage only, with no labels, stills or event counts";
13885
+ function errMessage(err) {
13886
+ return err instanceof Error ? err.message : String(err);
13887
+ }
13888
+ /**
13889
+ * Footage present, EVENTS unreachable — the mirror of the two degradations
13890
+ * this provider already had, and the one that could not happen while a single
13891
+ * addon held both halves (D560).
13892
+ *
13893
+ * A visit is a window over recorded footage; the events only ANNOTATE it. So
13894
+ * when availability answers, the visits are still real and still playable —
13895
+ * their ids encode the window — and the honest answer is that list without its
13896
+ * annotations. An availability that answered `[]` yields an empty list that is
13897
+ * TRUE about footage: with availability present a clip only ever comes from a
13898
+ * recorded range, so it is the same answer a successful events read would have
13899
+ * given.
13900
+ *
13901
+ * Without availability (absent, or its read failed too) the clips ARE the
13902
+ * events, so there is nothing left that is true to say. That is a REFUSAL
13903
+ * naming both reads — never an empty list, which reads as "this camera has no
13904
+ * recordings".
13905
+ */
13906
+ async function listWithoutEvents(deps, eventsUnreachable, reason, window) {
13907
+ const { deviceId, since, until, readSince, limit } = window;
13908
+ const fetchAvailability = deps.fetchAvailability;
13909
+ if (fetchAvailability === void 0) {
13910
+ eventsUnreachable.set(deviceId, reason);
13911
+ throw new Error(`videoclips: the analytics event log is unreachable for device ${deviceId} (${reason}) and this source lists no recorded footage — refusing rather than answering an empty list`);
13912
+ }
13913
+ let ranges;
13914
+ try {
13915
+ ranges = await fetchAvailability({
13916
+ deviceId,
13917
+ since: readSince,
13918
+ until
13919
+ });
13920
+ } catch (err) {
13921
+ eventsUnreachable.set(deviceId, reason);
13922
+ throw new Error(`videoclips: neither read answered for device ${deviceId} — events: ${reason}; footage: ${errMessage(err)}. Refusing rather than answering an empty list.`);
13923
+ }
13924
+ eventsUnreachable.set(deviceId, reason);
13925
+ deps.logWarn?.("videoclips: event log unreachable — listing the recorded footage visits without their events", {
13926
+ deviceId,
13927
+ error: reason,
13928
+ ranges: ranges.length
13929
+ });
13930
+ const clips = visitsToClips(clusterFootageVisits(ranges, require_dist.VISIT_MERGE_GAP_MS), NO_EVENTS, deps.defaultPad, /* @__PURE__ */ new Set()).filter((clip) => intersectsWindow(clip, since, until));
13931
+ return limit != null ? clips.slice(0, limit) : clips;
13932
+ }
13933
+ /** The annotation backstop biting is a SILENT loss of the earliest visits'
13934
+ * events — say so, per camera, instead of shipping a thinner list. */
13935
+ function warnOnTruncatedFetch(deps, deviceId, events) {
13936
+ if (!deps.fetchAvailability) return;
13937
+ const truncated = [
13938
+ "motion",
13939
+ "object",
13940
+ "audio"
13941
+ ].filter((kind) => events[kind].length >= VISIT_EVENT_FETCH_LIMIT);
13942
+ if (truncated.length === 0) return;
13943
+ deps.logWarn?.("videoclips: annotation fetch truncated — earliest visits lose their events", {
13944
+ deviceId,
13945
+ kinds: truncated,
13946
+ limit: VISIT_EVENT_FETCH_LIMIT
13947
+ });
13948
+ }
13949
+ /** The operator's acceptance criterion as a number: a rising count on one
13950
+ * camera is its motion-snapshot capturer failing, not a quiet day. */
13951
+ function reportUnvouchedClips(deps, deviceId, clips) {
13952
+ const clipsWithoutStill = clips.filter((c) => c.thumbnail === void 0).length;
13953
+ if (clipsWithoutStill === 0) return;
13954
+ deps.logInfo?.("videoclips: visit has no vouched still", {
13955
+ deviceId,
13956
+ clipsWithoutStill,
13957
+ clips: clips.length
13958
+ });
13959
+ }
13960
+ //#endregion
13961
+ //#region src/recorder/addon/videoclips-shared.ts
13962
+ /** Stringify the numeric event ids of one bucket. Lossless. */
13963
+ function toEventLike(events) {
13964
+ return events.map((e) => ({
13965
+ ...e,
13966
+ id: String(e.id)
13967
+ }));
13968
+ }
13969
+ //#endregion
13970
+ //#region src/recorder/addon/videoclips-wiring.ts
13971
+ /**
13972
+ * The `videoclips` source over THIS addon's archive — the deps half.
13973
+ *
13974
+ * The composer (`videoclips-provider.ts`, `videoclip-visits.ts`) is unchanged
13975
+ * and moved here verbatim from `addon-post-analysis`: a clip is still a time
13976
+ * WINDOW over recorded footage, visits are still clustered at
13977
+ * `VISIT_MERGE_GAP_MS`, and `getClipPlayback` still resolves through
13978
+ * `recording.getPlaybackManifest`. What moved is WHO registers it — the addon
13979
+ * that owns the footage, not one that borrowed it (D560).
13980
+ *
13981
+ * All four reads go over `ctx.api`, the recorder's own two included. That is
13982
+ * not laziness:
13983
+ *
13984
+ * - `recorder` is `placement: 'any-node'`, so several nodes register this
13985
+ * capability and the hub's collection dispatcher resolves the binding to
13986
+ * ONE of them (`addonIdentityOf` strips the `@<nodeId>`). That registration
13987
+ * is not necessarily the node holding this camera's segments.
13988
+ * - `ctx.api.recording.*` is device-scoped and routes to the node that IS
13989
+ * holding them. A short cut to the local `RecordingProvider` would answer a
13990
+ * camera recorded on little-unraid out of the hub's empty index — an empty
13991
+ * clip list on a camera with weeks of footage, which is the exact
13992
+ * misreading this whole line of work exists to end.
13993
+ *
13994
+ * The events arriving over a process boundary is the new failure mode, and the
13995
+ * provider answers it per branch — see `listWithoutEvents`.
13996
+ */
13997
+ /**
13998
+ * Every log line about a camera carries `tags: { deviceId }`, always the
13999
+ * numeric id. A miss rate or a media gap is always asked per camera, and a line
14000
+ * that omits the tag cannot answer it.
14001
+ */
14002
+ function stamp(logger, level) {
14003
+ return (message, meta) => {
14004
+ logger[level](message, {
14005
+ tags: { deviceId: Number(meta["deviceId"]) },
14006
+ meta
14007
+ });
14008
+ };
14009
+ }
14010
+ function createRecorderVideoclipsProvider(deps) {
14011
+ const api = deps.api;
14012
+ return createVideoclipsProvider({
14013
+ defaultPad: require_dist.EVENT_PAD_MS,
14014
+ fetchEvents: async ({ deviceId, since, until, limit }) => {
14015
+ const query = {
14016
+ deviceId,
14017
+ since,
14018
+ until,
14019
+ limit,
14020
+ projection: "slim"
14021
+ };
14022
+ const [motion, object, audio] = await Promise.all([
14023
+ api.pipelineAnalytics.getMotionEvents.query(query),
14024
+ api.pipelineAnalytics.getObjectEvents.query(query),
14025
+ api.pipelineAnalytics.getAudioEvents.query(query)
14026
+ ]);
14027
+ return {
14028
+ motion: toEventLike(motion),
14029
+ object: toEventLike(object),
14030
+ audio: toEventLike(audio)
14031
+ };
14032
+ },
14033
+ fetchMediaOwners: async ({ deviceId, ownerKind, ownerIds }) => new Set(await api.pipelineAnalytics.ownersWithMedia.query({
14034
+ deviceId,
14035
+ ownerKind,
14036
+ ownerIds
14037
+ })),
14038
+ fetchAvailability: async ({ deviceId, since, until }) => (await api.recording.getAvailability.query({
14039
+ deviceId,
14040
+ fromMs: since,
14041
+ toMs: until
14042
+ })).ranges,
14043
+ logWarn: stamp(deps.logger, "warn"),
14044
+ logInfo: stamp(deps.logger, "info"),
14045
+ resolvePlayback: async ({ deviceId, startMs, endMs }) => {
14046
+ const manifest = await api.recording.getPlaybackManifest.query({
14047
+ deviceId,
14048
+ fromMs: startMs,
14049
+ toMs: endMs
14050
+ });
14051
+ if (manifest.playbackUrl == null) throw new Error(`videoclips: no footage for clip window [${String(startMs)},${String(endMs)}] on device ${String(deviceId)}`);
14052
+ return {
14053
+ playbackUrl: manifest.playbackUrl,
14054
+ ...manifest.playbackEndpoints === void 0 ? {} : { playbackEndpoints: [...manifest.playbackEndpoints] }
14055
+ };
14056
+ }
14057
+ });
14058
+ }
14059
+ //#endregion
13499
14060
  //#region src/recorder/band-engine.ts
13500
14061
  function toMin(hhmm) {
13501
14062
  const [h, m] = hhmm.split(":");
@@ -18653,6 +19214,13 @@ var RecorderV2Addon = class extends require_dist.BaseAddon {
18653
19214
  capability: require_dist.recordingCapability,
18654
19215
  provider: recordingProvider
18655
19216
  },
19217
+ {
19218
+ capability: require_dist.videoclipsCapability,
19219
+ provider: createRecorderVideoclipsProvider({
19220
+ api: this.ctx.api,
19221
+ logger: this.ctx.logger
19222
+ })
19223
+ },
18656
19224
  {
18657
19225
  capability: require_dist.storageEvictableCapability,
18658
19226
  provider: evictableProvider