@camstack/addon-post-analysis 1.2.272 → 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.
- package/dist/{dist-BkBZcyAK.js → dist-B9V4PRZO.js} +3720 -624
- package/dist/{dist-4BOLDrB1.mjs → dist-DDko6srJ.mjs} +3715 -607
- package/dist/embedding-encoder/index.js +1 -1
- package/dist/embedding-encoder/index.mjs +1 -1
- package/dist/pipeline-analytics/_stub.js +2 -2
- package/dist/pipeline-analytics/{_virtual_mf-localSharedImportMap___mfe_internal__addon_pipeline_analytics_widgets-D2l0wRbH.mjs → _virtual_mf-localSharedImportMap___mfe_internal__addon_pipeline_analytics_widgets-CNrdmO1k.mjs} +2 -2
- package/dist/pipeline-analytics/_virtual_mf___mfe_internal__addon_pipeline_analytics_widgets__loadShare___mf_0_camstack_mf_1_types__loadShare__.js-kX2Fkx3d.mjs +26 -0
- package/dist/pipeline-analytics/_virtual_mf___mfe_internal__addon_pipeline_analytics_widgets__loadShare___mf_0_camstack_mf_1_ui_mf_2_library__loadShare__.js-D-4roee-.mjs +26 -0
- package/dist/pipeline-analytics/{hostInit-DW0buByp.mjs → hostInit-BDwkPDdw.mjs} +2 -2
- package/dist/pipeline-analytics/index.js +705 -1104
- package/dist/pipeline-analytics/index.mjs +703 -1102
- package/dist/pipeline-analytics/remoteEntry.js +1 -1
- package/package.json +1 -4
- package/dist/pipeline-analytics/_virtual_mf___mfe_internal__addon_pipeline_analytics_widgets__loadShare___mf_0_camstack_mf_1_types__loadShare__.js-BePOftX5.mjs +0 -26
- package/dist/pipeline-analytics/_virtual_mf___mfe_internal__addon_pipeline_analytics_widgets__loadShare___mf_0_camstack_mf_1_ui_mf_2_library__loadShare__.js-DJJiuYPX.mjs +0 -26
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as TimelapseRuleSchema, $t as
|
|
1
|
+
import { $ as TimelapseRuleSchema, $t as discriminatedUnion, A as NcRuleInputSchema, At as readTimelapseGeneratedAt, B as OpsLogEntrySchema, Bt as BaseAddon, C as MediaFileKindEnum, Ct as notificationRulesCapability, Dt as pipelineAnalyticsCapability, E as NC_DEFAULT_SNOOZE_MINUTES, Et as pickClusterStepModels, F as NcSnoozeInputSchema, Ft as subKindsOf, Gt as defineCustomActions, H as RECORDING_EXPORT_MAX_READ_BYTES, Ht as DeviceType, I as NcSnoozeSchema, It as systemEventFilterApplies, J as SCENE_DIVERGED, Jt as nodePin, K as SCENE_DEFAULT_ANCHOR_THRESHOLD, Kt as hydrateSchema, L as NcSnoozeSuppressedSchema, Lt as vectorDimFromBase64, M as NcRuleSchema, N as NcRuleTargetSchema, Nt as sceneMonitorCapability, O as NC_TAXONOMY, Ot as plateGalleryCapability, P as NcScheduleSchema, Pt as storageOccupancyCapability, Q as TimelapseRulePatchSchema, Qt as boolean, R as NcSystemEventKindSchema, Rt as zoneAnalyticsCapability, S as MOTION_CLOSE_AFTER_MS, St as mayWriteToLocation, T as NC_CONDITION_CATALOG, U as RECORDING_SOURCE_CAMSTACK_ADDON, Ut as createEvent, Vt as CamProfileSchema, W as RetrainStatusSchema, Wt as customAction, X as TIMELAPSE_DENSE_FLOOR_SEC, Xt as _enum, Y as SceneMonitorSchema, Yt as sleep$1, Z as TimelapseRuleInputSchema, Zt as array, _ as FailureCounters, _t as isEventOwnerType, a as CLUSTER_MODEL_SCOPED_STEPS, an as string, at as audioModeOf, b as MAX_BIRTH_DECISION_RECORDS, bt as isSourceCap, ct as deriveRecordingMode, dt as evaluateSensorEdge, en as literal, et as TrackSourceSchema, f as DeclaredDevices, ft as evictionPolicyOfLocation, g as FULL_IMAGE_BBOX, gt as isDetectionMacroClass, h as FIRST_LEVEL_MACRO_CLASSES, i as BirthDecisionRecordSchema, in as record, it as audioMetricsCapability, j as NcRulePatchSchema, jt as resolveLocationMode, k as NcConditionDescriptorSchema, kt as readDeviceStateFrom, m as EVENT_OWNER_TYPES, mt as failureContributionCapability, n as ArchivedDebugNoteSchema, nn as object, nt as alarmPanelCapability, o as COCO_TO_MACRO, on as unknown, ot as buildEventKindDescriptor, p as EVENT_KIND_BY_CAP, pt as faceGalleryCapability, q as SCENE_DEFAULT_UNCOVERED_POLICY, qt as isDeviceScopedCap, r as BaseDevice, rn as partialRecord, rt as assertTimelapseCadences, s as DEFAULT_EVENT_COLOR, sn as EventCategory, st as cosineSimilarity$1, t as AUDIO_MACRO_LABELS, tn as number, tt as addonWidgetsSourceCapability, u as DETECTION_MACRO_CLASSES, ut as encodeVectorBase64, v as LabelAttributionSchema, vt as isMediaOwnerType, w as NC_ALARM_SYSTEM_EVENT_KINDS, wt as occupancyScope, xt as kebabToCamel, y as MAX_ARCHIVED_DEBUG_NOTES, yt as isScheduleActive, z as NcTaxonomySchema, zt as errMsg$1 } from "../dist-DDko6srJ.mjs";
|
|
2
2
|
import { t as __exportAll } from "../embedding-encoder/index.mjs";
|
|
3
3
|
import * as fs from "node:fs";
|
|
4
4
|
import { promises } from "node:fs";
|
|
@@ -41691,6 +41691,160 @@ var TrackResidentState = class {
|
|
|
41691
41691
|
if (resident.rasterFallback === void 0) resident.rasterFallback = fallback;
|
|
41692
41692
|
}
|
|
41693
41693
|
};
|
|
41694
|
+
/**
|
|
41695
|
+
* The shipped limits.
|
|
41696
|
+
*
|
|
41697
|
+
* `minTracks` 12 / `minSamples` 200: the four live cameras sampled above
|
|
41698
|
+
* produced 697–8739 samples from 42–51 tracks in a single 60-track read, so a
|
|
41699
|
+
* camera that cannot clear these has genuinely not been watched enough.
|
|
41700
|
+
* `maxTracks` 200 bounds the read: the `positions` blob averages ~10 kB a row
|
|
41701
|
+
* (`track-store.ts`), so this pass is ~2 MB of JSON at its worst.
|
|
41702
|
+
*/
|
|
41703
|
+
var DEFAULT_STILLNESS_CALIBRATION_LIMITS = {
|
|
41704
|
+
minTracks: 12,
|
|
41705
|
+
minSamples: 200,
|
|
41706
|
+
maxTracks: 200,
|
|
41707
|
+
minIntervalSec: .02,
|
|
41708
|
+
maxIntervalSec: 3,
|
|
41709
|
+
quantile: .25,
|
|
41710
|
+
floorFactor: .02,
|
|
41711
|
+
ceilFactor: .25,
|
|
41712
|
+
minBar: .001,
|
|
41713
|
+
maxBar: 1
|
|
41714
|
+
};
|
|
41715
|
+
/** Linear-interpolated quantile. `NaN` for an empty list — never 0, which
|
|
41716
|
+
* would read as a measured zero (D393). */
|
|
41717
|
+
function quantileOf(values, p) {
|
|
41718
|
+
if (values.length === 0) return NaN;
|
|
41719
|
+
const sorted = [...values].sort((a, b) => a - b);
|
|
41720
|
+
const idx = (sorted.length - 1) * Math.min(Math.max(p, 0), 1);
|
|
41721
|
+
const lo = Math.floor(idx);
|
|
41722
|
+
const hi = Math.ceil(idx);
|
|
41723
|
+
const at = sorted[lo];
|
|
41724
|
+
const next = sorted[hi];
|
|
41725
|
+
if (at === void 0 || next === void 0) return NaN;
|
|
41726
|
+
return at + (next - at) * (idx - lo);
|
|
41727
|
+
}
|
|
41728
|
+
/**
|
|
41729
|
+
* Per-sample centroid speeds for a camera, in subject-box-diagonals per second.
|
|
41730
|
+
*
|
|
41731
|
+
* A pair of consecutive positions contributes a sample only when the interval
|
|
41732
|
+
* between them is inside `[minIntervalSec, maxIntervalSec]` and the later box
|
|
41733
|
+
* has a positive diagonal. A gap outside that band is a session boundary or a
|
|
41734
|
+
* duplicate read, not a measurement of how fast anything travelled; a box with
|
|
41735
|
+
* no size is unknown geometry, and unknown is never a sample.
|
|
41736
|
+
*/
|
|
41737
|
+
function collectStillnessSamples(tracks, limits) {
|
|
41738
|
+
const speeds = [];
|
|
41739
|
+
const intervals = [];
|
|
41740
|
+
const diagonals = [];
|
|
41741
|
+
let trackCount = 0;
|
|
41742
|
+
const read = tracks.slice(0, limits.maxTracks);
|
|
41743
|
+
for (const track of read) {
|
|
41744
|
+
const positions = [...track.positions].sort((a, b) => a.timestamp - b.timestamp);
|
|
41745
|
+
let contributed = false;
|
|
41746
|
+
for (let i = 1; i < positions.length; i++) {
|
|
41747
|
+
const prev = positions[i - 1];
|
|
41748
|
+
const cur = positions[i];
|
|
41749
|
+
if (prev === void 0 || cur === void 0) continue;
|
|
41750
|
+
const dtSec = (cur.timestamp - prev.timestamp) / 1e3;
|
|
41751
|
+
if (dtSec < limits.minIntervalSec || dtSec > limits.maxIntervalSec) continue;
|
|
41752
|
+
const diagonal = Math.hypot(cur.bbox.w, cur.bbox.h);
|
|
41753
|
+
if (!(diagonal > 0)) continue;
|
|
41754
|
+
const travelled = Math.hypot(cur.x - prev.x, cur.y - prev.y);
|
|
41755
|
+
speeds.push(travelled / diagonal / dtSec);
|
|
41756
|
+
intervals.push(dtSec);
|
|
41757
|
+
diagonals.push(diagonal);
|
|
41758
|
+
contributed = true;
|
|
41759
|
+
}
|
|
41760
|
+
if (contributed) trackCount++;
|
|
41761
|
+
}
|
|
41762
|
+
return {
|
|
41763
|
+
speeds,
|
|
41764
|
+
intervals,
|
|
41765
|
+
diagonals,
|
|
41766
|
+
trackCount,
|
|
41767
|
+
tracksRead: read.length
|
|
41768
|
+
};
|
|
41769
|
+
}
|
|
41770
|
+
function measure$1(samples) {
|
|
41771
|
+
return {
|
|
41772
|
+
trackCount: samples.trackCount,
|
|
41773
|
+
sampleCount: samples.speeds.length,
|
|
41774
|
+
p25: quantileOf(samples.speeds, .25),
|
|
41775
|
+
p50: quantileOf(samples.speeds, .5),
|
|
41776
|
+
p90: quantileOf(samples.speeds, .9),
|
|
41777
|
+
medianIntervalSec: quantileOf(samples.intervals, .5),
|
|
41778
|
+
medianSubjectDiagonalPx: quantileOf(samples.diagonals, .5)
|
|
41779
|
+
};
|
|
41780
|
+
}
|
|
41781
|
+
/**
|
|
41782
|
+
* Choose this camera's stillness speed bar, or refuse with a named reason.
|
|
41783
|
+
*
|
|
41784
|
+
* The order of the gates is the order of the questions: is there anything at
|
|
41785
|
+
* all, is it enough tracks, is it enough samples, and did anything on this
|
|
41786
|
+
* camera ever actually move. The last one is not pedantry — the whole method
|
|
41787
|
+
* scales the bar against the camera's own travel, so with no travel there is
|
|
41788
|
+
* nothing to scale against and the default is the honest answer.
|
|
41789
|
+
*/
|
|
41790
|
+
function calibrateStillnessSpeed(samples, limits) {
|
|
41791
|
+
const measurement = measure$1(samples);
|
|
41792
|
+
if (samples.tracksRead === 0) return {
|
|
41793
|
+
ok: false,
|
|
41794
|
+
reason: "no-tracks",
|
|
41795
|
+
measurement
|
|
41796
|
+
};
|
|
41797
|
+
if (samples.trackCount < limits.minTracks) return {
|
|
41798
|
+
ok: false,
|
|
41799
|
+
reason: "too-few-tracks",
|
|
41800
|
+
measurement
|
|
41801
|
+
};
|
|
41802
|
+
if (samples.speeds.length < limits.minSamples) return {
|
|
41803
|
+
ok: false,
|
|
41804
|
+
reason: "too-few-samples",
|
|
41805
|
+
measurement
|
|
41806
|
+
};
|
|
41807
|
+
if (!(measurement.p90 > 0)) return {
|
|
41808
|
+
ok: false,
|
|
41809
|
+
reason: "no-motion-evidence",
|
|
41810
|
+
measurement
|
|
41811
|
+
};
|
|
41812
|
+
const rawBar = quantileOf(samples.speeds, limits.quantile);
|
|
41813
|
+
const floor = measurement.p90 * limits.floorFactor;
|
|
41814
|
+
const ceiling = measurement.p90 * limits.ceilFactor;
|
|
41815
|
+
let bar = rawBar;
|
|
41816
|
+
let clampedBy = "none";
|
|
41817
|
+
if (bar < floor) {
|
|
41818
|
+
bar = floor;
|
|
41819
|
+
clampedBy = "floor";
|
|
41820
|
+
} else if (bar > ceiling) {
|
|
41821
|
+
bar = ceiling;
|
|
41822
|
+
clampedBy = "ceiling";
|
|
41823
|
+
}
|
|
41824
|
+
if (bar < limits.minBar) {
|
|
41825
|
+
bar = limits.minBar;
|
|
41826
|
+
clampedBy = "min";
|
|
41827
|
+
} else if (bar > limits.maxBar) {
|
|
41828
|
+
bar = limits.maxBar;
|
|
41829
|
+
clampedBy = "max";
|
|
41830
|
+
}
|
|
41831
|
+
return {
|
|
41832
|
+
ok: true,
|
|
41833
|
+
bar,
|
|
41834
|
+
rawBar,
|
|
41835
|
+
clampedBy,
|
|
41836
|
+
measurement
|
|
41837
|
+
};
|
|
41838
|
+
}
|
|
41839
|
+
/** One line an operator can read: what was measured, from how much, and what
|
|
41840
|
+
* rule produced the stored number. Kept short — it rides the settings blob. */
|
|
41841
|
+
function describeStillnessCalibration(outcome) {
|
|
41842
|
+
const m = outcome.measurement;
|
|
41843
|
+
const n = (v) => Number.isFinite(v) ? v.toFixed(4) : "unknown";
|
|
41844
|
+
const evidence = `${m.sampleCount} samples / ${m.trackCount} tracks, p25 ${n(m.p25)}, p50 ${n(m.p50)}, p90 ${n(m.p90)} subject-diagonals/s`;
|
|
41845
|
+
if (!outcome.ok) return `refused (${outcome.reason}) — ${evidence}`;
|
|
41846
|
+
return `bar ${n(outcome.bar)} (raw ${n(outcome.rawBar)}, clamp ${outcome.clampedBy}) — ${evidence}`;
|
|
41847
|
+
}
|
|
41694
41848
|
//#endregion
|
|
41695
41849
|
//#region src/pipeline-analytics/pipeline/plate-clustering.ts
|
|
41696
41850
|
/**
|
|
@@ -47641,389 +47795,180 @@ async function retentionScopeDeviceIds(deps, onError) {
|
|
|
47641
47795
|
return [...ids];
|
|
47642
47796
|
}
|
|
47643
47797
|
//#endregion
|
|
47644
|
-
//#region src/pipeline-analytics/
|
|
47645
|
-
/**
|
|
47646
|
-
* Videoclip visits — the grain a clip should have on an events-mode camera.
|
|
47647
|
-
*
|
|
47648
|
-
* Disk writes one fMP4 per ffmpeg roll (~8–12 s). The recorder calendar merges
|
|
47649
|
-
* only gaps ≤ 5 s, so a single pantry walk shows up as several availability
|
|
47650
|
-
* ranges with ~8 s GOP holes between them. Analytics then mints one 15 s clip
|
|
47651
|
-
* per motion heartbeat. A *visit* is the keep-window those fragments belong
|
|
47652
|
-
* to: cluster availability with {@link VISIT_MERGE_GAP_MS}, annotate with
|
|
47653
|
-
* overlapping events. No second copy of the media; the files stay the source
|
|
47654
|
-
* of truth.
|
|
47655
|
-
*/
|
|
47656
|
-
/** Synthetic event-id slot in `analytics:<start>:<end>:<id>` for a visit clip. */
|
|
47657
|
-
var VISIT_EVENT_ID = "visit";
|
|
47658
|
-
function clusterFootageVisits(ranges, gapMs = VISIT_MERGE_GAP_MS) {
|
|
47659
|
-
if (ranges.length === 0) return [];
|
|
47660
|
-
const sorted = [...ranges].toSorted((a, b) => a.startMs - b.startMs);
|
|
47661
|
-
const visits = [];
|
|
47662
|
-
let pieces = [sorted[0]];
|
|
47663
|
-
let endMs = sorted[0].endMs;
|
|
47664
|
-
for (let i = 1; i < sorted.length; i++) {
|
|
47665
|
-
const next = sorted[i];
|
|
47666
|
-
if (next.startMs <= endMs + gapMs) {
|
|
47667
|
-
pieces.push(next);
|
|
47668
|
-
endMs = Math.max(endMs, next.endMs);
|
|
47669
|
-
continue;
|
|
47670
|
-
}
|
|
47671
|
-
visits.push(finishVisit(pieces, endMs));
|
|
47672
|
-
pieces = [next];
|
|
47673
|
-
endMs = next.endMs;
|
|
47674
|
-
}
|
|
47675
|
-
visits.push(finishVisit(pieces, endMs));
|
|
47676
|
-
return visits;
|
|
47677
|
-
}
|
|
47678
|
-
function finishVisit(pieces, endMs) {
|
|
47679
|
-
const holes = [];
|
|
47680
|
-
for (let i = 1; i < pieces.length; i++) {
|
|
47681
|
-
const prevEnd = pieces[i - 1].endMs;
|
|
47682
|
-
const nextStart = pieces[i].startMs;
|
|
47683
|
-
if (nextStart > prevEnd) holes.push({
|
|
47684
|
-
startMs: prevEnd,
|
|
47685
|
-
endMs: nextStart
|
|
47686
|
-
});
|
|
47687
|
-
}
|
|
47688
|
-
return {
|
|
47689
|
-
startMs: pieces[0].startMs,
|
|
47690
|
-
endMs,
|
|
47691
|
-
ranges: pieces,
|
|
47692
|
-
holes
|
|
47693
|
-
};
|
|
47694
|
-
}
|
|
47695
|
-
var KIND_ORDER = [
|
|
47696
|
-
"object",
|
|
47697
|
-
"motion",
|
|
47698
|
-
"audio"
|
|
47699
|
-
];
|
|
47700
|
-
function eventOverlapsVisit(event, visit, pad) {
|
|
47701
|
-
if (event.timestamp >= visit.startMs && event.timestamp <= visit.endMs) return true;
|
|
47702
|
-
const windowStart = event.timestamp - pad.preMs;
|
|
47703
|
-
const windowEnd = event.timestamp + pad.postMs;
|
|
47704
|
-
return windowStart < visit.endMs && windowEnd > visit.startMs;
|
|
47705
|
-
}
|
|
47706
|
-
function dominantKind(attached) {
|
|
47707
|
-
for (const kind of KIND_ORDER) if (attached.some((a) => a.kind === kind)) return kind;
|
|
47708
|
-
return "motion";
|
|
47709
|
-
}
|
|
47798
|
+
//#region src/pipeline-analytics/stillness-calibration-actions.ts
|
|
47710
47799
|
/**
|
|
47711
|
-
*
|
|
47712
|
-
*
|
|
47800
|
+
* stillness-calibration-actions — "measure this camera's own stillness scale".
|
|
47801
|
+
*
|
|
47802
|
+
* ## Why an `addons.custom` action and not a cap method
|
|
47803
|
+
*
|
|
47804
|
+
* Same reason as `face.rescoreTrack` beside it: a cap method's wire schema
|
|
47805
|
+
* lives in `@camstack/types`, which travels inside the `@camstack/server`
|
|
47806
|
+
* closure, so a new one is not callable until a server train ships. Here the
|
|
47807
|
+
* schema lives in this addon's own dist and the hub forwards an opaque
|
|
47808
|
+
* envelope, so `camstack deploy` is the whole delivery.
|
|
47809
|
+
*
|
|
47810
|
+
* ## Why `apply` is explicit and not a fallback
|
|
47713
47811
|
*
|
|
47714
|
-
*
|
|
47715
|
-
*
|
|
47716
|
-
*
|
|
47717
|
-
*
|
|
47812
|
+
* A calibration run READS recorded tracks and does arithmetic. Applying it
|
|
47813
|
+
* WRITES the camera's settings and changes what the tracker calls settled from
|
|
47814
|
+
* the next frame on. Those are different enough in consequence that a button
|
|
47815
|
+
* labelled "calibrate" must not choose between them on the operator's behalf —
|
|
47816
|
+
* the run reports, the operator applies. A REFUSED run never writes the bar
|
|
47817
|
+
* whatever `apply` says; it writes only the note, so the refusal and its reason
|
|
47818
|
+
* are visible in the form instead of being a toast that scrolls away.
|
|
47718
47819
|
*/
|
|
47719
|
-
|
|
47720
|
-
|
|
47721
|
-
|
|
47722
|
-
|
|
47723
|
-
|
|
47724
|
-
|
|
47820
|
+
/** Mirrors `StillnessCalibrationRefusal` — kept literal so the wire schema is
|
|
47821
|
+
* self-describing and a new reason is a deliberate edit in both places. */
|
|
47822
|
+
var StillnessRefusalSchema = _enum([
|
|
47823
|
+
"no-tracks",
|
|
47824
|
+
"too-few-tracks",
|
|
47825
|
+
"too-few-samples",
|
|
47826
|
+
"no-motion-evidence"
|
|
47827
|
+
]);
|
|
47828
|
+
var StillnessMeasurementSchema = object({
|
|
47829
|
+
/** Tracks that contributed at least one speed sample. */
|
|
47830
|
+
trackCount: number().int(),
|
|
47831
|
+
/** Tracks the pass actually read, after the cost bound. */
|
|
47832
|
+
tracksRead: number().int(),
|
|
47833
|
+
sampleCount: number().int(),
|
|
47834
|
+
/** Speed quantiles, subject-box-diagonals per second. `null` when there was
|
|
47835
|
+
* nothing to measure — never 0, which would read as a measured stillness
|
|
47836
|
+
* (D393). */
|
|
47837
|
+
p25: number().nullable(),
|
|
47838
|
+
p50: number().nullable(),
|
|
47839
|
+
p90: number().nullable(),
|
|
47840
|
+
/** Median gap between stored positions (s) — the camera's real cadence. */
|
|
47841
|
+
medianIntervalSec: number().nullable(),
|
|
47842
|
+
/** Median subject box diagonal (px) the speeds were normalised by. */
|
|
47843
|
+
medianSubjectDiagonalPx: number().nullable()
|
|
47844
|
+
});
|
|
47845
|
+
var stillnessCalibrationActions = defineCustomActions({
|
|
47725
47846
|
/**
|
|
47726
|
-
*
|
|
47727
|
-
*
|
|
47728
|
-
*
|
|
47729
|
-
* kind label instead of carrying an empty array every consumer length-checks.
|
|
47847
|
+
* `admin` because it WRITES a per-camera detection threshold when `apply` is
|
|
47848
|
+
* set, and because the report describes how the camera's subjects move,
|
|
47849
|
+
* which is not a viewer-level fact.
|
|
47730
47850
|
*/
|
|
47731
|
-
|
|
47732
|
-
|
|
47733
|
-
|
|
47734
|
-
|
|
47735
|
-
|
|
47736
|
-
|
|
47737
|
-
|
|
47738
|
-
|
|
47739
|
-
|
|
47740
|
-
|
|
47741
|
-
|
|
47742
|
-
|
|
47743
|
-
|
|
47744
|
-
|
|
47745
|
-
|
|
47746
|
-
|
|
47747
|
-
|
|
47748
|
-
|
|
47749
|
-
|
|
47750
|
-
|
|
47751
|
-
|
|
47752
|
-
|
|
47753
|
-
|
|
47754
|
-
|
|
47755
|
-
|
|
47756
|
-
|
|
47757
|
-
|
|
47758
|
-
|
|
47759
|
-
|
|
47760
|
-
|
|
47761
|
-
|
|
47762
|
-
|
|
47763
|
-
|
|
47764
|
-
|
|
47765
|
-
|
|
47766
|
-
|
|
47767
|
-
|
|
47768
|
-
|
|
47769
|
-
|
|
47770
|
-
|
|
47771
|
-
|
|
47772
|
-
|
|
47773
|
-
|
|
47774
|
-
|
|
47775
|
-
...labels.length > 0 ? { labels } : {}
|
|
47776
|
-
};
|
|
47777
|
-
}).toSorted((a, b) => b.timeRange.startMs - a.timeRange.startMs);
|
|
47778
|
-
}
|
|
47851
|
+
"stillness.calibrate": customAction(object({
|
|
47852
|
+
deviceId: number().int(),
|
|
47853
|
+
/** How far back to read. Bounded: this pass parses ~10 kB of trajectory a
|
|
47854
|
+
* row, so the window is a suggestion and `maxTracks` is the real bound. */
|
|
47855
|
+
sinceHours: number().min(.25).max(720).default(72),
|
|
47856
|
+
/** Hard cost bound on tracks read, newest first. */
|
|
47857
|
+
maxTracks: number().int().min(1).max(1e3).default(200),
|
|
47858
|
+
/**
|
|
47859
|
+
* Write the chosen bar onto the camera. Never implicit, and never done at
|
|
47860
|
+
* all for a refused run.
|
|
47861
|
+
*/
|
|
47862
|
+
apply: boolean().default(false)
|
|
47863
|
+
}), object({
|
|
47864
|
+
deviceId: number().int(),
|
|
47865
|
+
/** The window actually read (epoch ms). */
|
|
47866
|
+
since: number().int(),
|
|
47867
|
+
until: number().int(),
|
|
47868
|
+
accepted: boolean(),
|
|
47869
|
+
/** Why it refused. Absent on an accepted run. */
|
|
47870
|
+
reason: StillnessRefusalSchema.optional(),
|
|
47871
|
+
/** The chosen bar, subject-box-diagonals per second. Absent on a refusal —
|
|
47872
|
+
* never 0, which the settings layer reads as "uncalibrated". */
|
|
47873
|
+
bar: number().optional(),
|
|
47874
|
+
/** The raw quantile before the rails, so the clamp is arguable. */
|
|
47875
|
+
rawBar: number().optional(),
|
|
47876
|
+
clampedBy: _enum([
|
|
47877
|
+
"none",
|
|
47878
|
+
"floor",
|
|
47879
|
+
"ceiling",
|
|
47880
|
+
"min",
|
|
47881
|
+
"max"
|
|
47882
|
+
]).optional(),
|
|
47883
|
+
measurement: StillnessMeasurementSchema,
|
|
47884
|
+
/** The bar this camera was on BEFORE the run — `null` = uncalibrated. Read
|
|
47885
|
+
* before any write, so the operator sees both numbers. */
|
|
47886
|
+
previousBar: number().nullable(),
|
|
47887
|
+
/** Whether the camera's settings were actually written. */
|
|
47888
|
+
applied: boolean(),
|
|
47889
|
+
/** The one-line note stored on the camera (accepted or refused). */
|
|
47890
|
+
note: string()
|
|
47891
|
+
}), {
|
|
47892
|
+
kind: "mutation",
|
|
47893
|
+
auth: "admin"
|
|
47894
|
+
}) });
|
|
47779
47895
|
//#endregion
|
|
47780
|
-
//#region src/pipeline-analytics/
|
|
47781
|
-
/**
|
|
47782
|
-
* Default `videoclips` provider — composes recorded footage visits with the
|
|
47783
|
-
* analytics event log. A clip is a time-WINDOW over existing footage, never a
|
|
47784
|
-
* separate file: `getClipPlayback` resolves to
|
|
47785
|
-
* `recording.getPlaybackManifest(startMs, endMs)`.
|
|
47786
|
-
*
|
|
47787
|
-
* When availability is present the grain is a *visit* (events-mode keep-window
|
|
47788
|
-
* clustered at `VISIT_MERGE_GAP_MS`), not one clip per motion heartbeat. The
|
|
47789
|
-
* clip id still encodes the window (`analytics:<startMs>:<endMs>:visit`) so
|
|
47790
|
-
* playback is self-contained. Without availability (or when that read fails)
|
|
47791
|
-
* the provider falls back to per-event padded windows.
|
|
47792
|
-
*
|
|
47793
|
-
* Pure helpers (`eventsToClips` / `clusterFootageVisits` / `clipIdFor` /
|
|
47794
|
-
* `parseClipId`) are unit-tested in isolation; the provider factory wires
|
|
47795
|
-
* injected fetch/resolve deps so the compose logic is testable without I/O.
|
|
47796
|
-
*/
|
|
47797
|
-
var SOURCE = "analytics";
|
|
47798
|
-
/** The addon that registers this provider — stamped on its source row. */
|
|
47799
|
-
var ANALYTICS_ADDON_ID = "pipeline-analytics";
|
|
47800
|
-
/**
|
|
47801
|
-
* Backstop on the ANNOTATION read — never on the clip list.
|
|
47802
|
-
*
|
|
47803
|
-
* A visit is annotated by every event inside it, so the clip `limit` must not
|
|
47804
|
-
* reach this fetch (one 615 visit legitimately spans 2 345 motion rows). This
|
|
47805
|
-
* bound exists only so a pathological camera-day cannot pull an unbounded page:
|
|
47806
|
-
* the store orders `timestamp DESC`, so a truncation drops the OLDEST rows and
|
|
47807
|
-
* the EARLIEST visits silently lose their annotations — which is why hitting it
|
|
47808
|
-
* is logged, per camera, rather than absorbed.
|
|
47809
|
-
*/
|
|
47810
|
-
var VISIT_EVENT_FETCH_LIMIT = 5e3;
|
|
47811
|
-
function clipIdFor(eventId, startMs, endMs) {
|
|
47812
|
-
return `${SOURCE}:${startMs}:${endMs}:${eventId}`;
|
|
47813
|
-
}
|
|
47814
|
-
/** Parse a default-provider clip id back into its window + event id. Returns
|
|
47815
|
-
* `null` for any id this provider did not mint (e.g. a native clip id). */
|
|
47816
|
-
function parseClipId(clipId) {
|
|
47817
|
-
const parts = clipId.split(":");
|
|
47818
|
-
if (parts.length < 4 || parts[0] !== SOURCE) return null;
|
|
47819
|
-
const startMs = Number(parts[1]);
|
|
47820
|
-
const endMs = Number(parts[2]);
|
|
47821
|
-
if (!Number.isFinite(startMs) || !Number.isFinite(endMs)) return null;
|
|
47822
|
-
const eventId = parts.slice(3).join(":");
|
|
47823
|
-
if (!eventId) return null;
|
|
47824
|
-
return {
|
|
47825
|
-
eventId,
|
|
47826
|
-
startMs,
|
|
47827
|
-
endMs
|
|
47828
|
-
};
|
|
47829
|
-
}
|
|
47830
|
-
/** Map per-kind events into time-ranged clips, newest-first. Pure. */
|
|
47831
|
-
function eventsToClips(events, pad, vouched) {
|
|
47832
|
-
const make = (e, kind) => {
|
|
47833
|
-
const startMs = e.timestamp - pad.preMs;
|
|
47834
|
-
const endMs = e.timestamp + pad.postMs;
|
|
47835
|
-
return {
|
|
47836
|
-
id: clipIdFor(e.id, startMs, endMs),
|
|
47837
|
-
source: SOURCE,
|
|
47838
|
-
kind,
|
|
47839
|
-
timeRange: {
|
|
47840
|
-
startMs,
|
|
47841
|
-
endMs
|
|
47842
|
-
},
|
|
47843
|
-
...e.mediaUrl !== void 0 && vouched.has(e.id) ? { thumbnail: e.mediaUrl } : {}
|
|
47844
|
-
};
|
|
47845
|
-
};
|
|
47846
|
-
return [
|
|
47847
|
-
...events.motion.map((e) => make(e, "motion")),
|
|
47848
|
-
...events.object.map((e) => make(e, "object")),
|
|
47849
|
-
...events.audio.map((e) => make(e, "audio"))
|
|
47850
|
-
].toSorted((a, b) => b.timeRange.startMs - a.timeRange.startMs);
|
|
47851
|
-
}
|
|
47852
|
-
/** Every id in the three buckets, in the order the composers tag them. */
|
|
47853
|
-
function allEventIds(events) {
|
|
47854
|
-
return [
|
|
47855
|
-
...events.motion,
|
|
47856
|
-
...events.object,
|
|
47857
|
-
...events.audio
|
|
47858
|
-
].map((e) => e.id);
|
|
47859
|
-
}
|
|
47860
|
-
/**
|
|
47861
|
-
* Resolve the event ids whose `mediaUrl` is backed by real bytes, mirroring
|
|
47862
|
-
* `resolveDefaultEventMedia`: the event's OWN media when it has any, else its
|
|
47863
|
-
* owning TRACK's. Up to four batched index reads — one PER EVENT KIND that has
|
|
47864
|
-
* any ids (D476: `motion` / `object` / `audio` are separate owner kinds now,
|
|
47865
|
-
* so a single combined read can no longer ask "does any of these ids own
|
|
47866
|
-
* media" — a motion id and an object id can be the same number post-D474 and
|
|
47867
|
-
* are answered by different rows) — plus the track fallback, only over the
|
|
47868
|
-
* object events the first pass did not already answer for (motion and audio
|
|
47869
|
-
* are trackless roots, so they never need it).
|
|
47870
|
-
*
|
|
47871
|
-
* THROWS on a failed read. The caller fails closed on the CLAIM and open on the
|
|
47872
|
-
* LIST; swallowing here would collapse those two opposite directions into one.
|
|
47873
|
-
*/
|
|
47874
|
-
async function resolveVouchedEvents(deviceId, events, fetchMediaOwners) {
|
|
47875
|
-
const ownMedia = /* @__PURE__ */ new Set();
|
|
47876
|
-
for (const ownerType of EVENT_OWNER_TYPES) {
|
|
47877
|
-
const ownerIds = events[ownerType].map((e) => e.id);
|
|
47878
|
-
if (ownerIds.length === 0) continue;
|
|
47879
|
-
const found = await fetchMediaOwners({
|
|
47880
|
-
deviceId,
|
|
47881
|
-
ownerKind: ownerType,
|
|
47882
|
-
ownerIds
|
|
47883
|
-
});
|
|
47884
|
-
for (const id of found) ownMedia.add(id);
|
|
47885
|
-
}
|
|
47886
|
-
const residualTracks = [];
|
|
47887
|
-
const seenTracks = /* @__PURE__ */ new Set();
|
|
47888
|
-
for (const event of events.object) {
|
|
47889
|
-
const trackId = event.trackId;
|
|
47890
|
-
if (trackId === void 0 || ownMedia.has(event.id) || seenTracks.has(trackId)) continue;
|
|
47891
|
-
seenTracks.add(trackId);
|
|
47892
|
-
residualTracks.push(trackId);
|
|
47893
|
-
}
|
|
47894
|
-
const trackMedia = residualTracks.length === 0 ? /* @__PURE__ */ new Set() : await fetchMediaOwners({
|
|
47895
|
-
deviceId,
|
|
47896
|
-
ownerKind: "track",
|
|
47897
|
-
ownerIds: residualTracks
|
|
47898
|
-
});
|
|
47899
|
-
const vouched = new Set(ownMedia);
|
|
47900
|
-
for (const event of events.object) {
|
|
47901
|
-
const trackId = event.trackId;
|
|
47902
|
-
if (trackId !== void 0 && trackMedia.has(trackId)) vouched.add(event.id);
|
|
47903
|
-
}
|
|
47904
|
-
return vouched;
|
|
47905
|
-
}
|
|
47906
|
-
/** Keep only clips that actually touch the caller's window. The reads are
|
|
47907
|
-
* widened by {@link leftOverhangMs}; the ANSWER is not. */
|
|
47908
|
-
function intersectsWindow(clip, since, until) {
|
|
47909
|
-
return clip.timeRange.startMs < until && clip.timeRange.endMs > since;
|
|
47910
|
-
}
|
|
47896
|
+
//#region src/pipeline-analytics/stillness-settings.ts
|
|
47911
47897
|
/**
|
|
47912
|
-
*
|
|
47898
|
+
* Per-device STILLNESS SCALE — the one number that says how fast a subject on
|
|
47899
|
+
* THIS camera has to move before it is travelling.
|
|
47913
47900
|
*
|
|
47914
|
-
* A
|
|
47915
|
-
*
|
|
47916
|
-
*
|
|
47917
|
-
*
|
|
47901
|
+
* A threshold belongs to whoever GENERATES the event, per device, never baked
|
|
47902
|
+
* into a classifier default. The judgement this feeds is
|
|
47903
|
+
* `StateAnalyzer.speedSaysSettled`; the measurement behind the number is
|
|
47904
|
+
* `pipeline/tracker/stillness-scale.ts`, which also carries the live
|
|
47905
|
+
* measurement showing why one number cannot serve a 30 m driveway and a 2 m
|
|
47906
|
+
* doorway.
|
|
47907
|
+
*
|
|
47908
|
+
* Cascade and shape mirror `stationary-settings` / `media-settings`: a
|
|
47909
|
+
* per-device override on top of the default, resolved per FIELD, and a parse
|
|
47910
|
+
* that never throws on a bad blob.
|
|
47911
|
+
*
|
|
47912
|
+
* **Absent behaves exactly as today.** The device store is a flat numeric blob
|
|
47913
|
+
* with no room for "unset", so the stored form of absent is `0` — and `0` is
|
|
47914
|
+
* not a bar anyone could want (it would mean nothing on this camera is ever
|
|
47915
|
+
* still) and not a value the calibration can produce (`minBar`). The decision
|
|
47916
|
+
* layer never sees it: {@link resolveStillSpeedFracPerSec} maps it to
|
|
47917
|
+
* `undefined`, and `undefined` is what leaves `StateAnalyzer` on its original
|
|
47918
|
+
* absolute `velocityThreshold` path.
|
|
47918
47919
|
*/
|
|
47919
|
-
|
|
47920
|
-
|
|
47921
|
-
|
|
47922
|
-
|
|
47920
|
+
var StillnessSettingsSchema = object({
|
|
47921
|
+
/**
|
|
47922
|
+
* The camera's "not travelling" bar: centroid speed as a fraction of the
|
|
47923
|
+
* SUBJECT's own box diagonal, per second. `0` = not calibrated (see above).
|
|
47924
|
+
*
|
|
47925
|
+
* Measured p50 on the live hub 2026-09-19, for scale: 0.0136 (device 592,
|
|
47926
|
+
* close view, mostly parked subjects) to 0.3081 (device 615, far view, only
|
|
47927
|
+
* transits).
|
|
47928
|
+
*/
|
|
47929
|
+
stillnessSpeedFracPerSec: number().min(0).max(1).default(0),
|
|
47930
|
+
/**
|
|
47931
|
+
* When the number above was last CHOSEN — by a calibration run or by the
|
|
47932
|
+
* operator. `0` = never. Purely a readout; nothing gates on it.
|
|
47933
|
+
*/
|
|
47934
|
+
stillnessCalibratedAt: number().int().min(0).default(0),
|
|
47935
|
+
/**
|
|
47936
|
+
* What the last calibration run measured and decided, in one line
|
|
47937
|
+
* (`describeStillnessCalibration`) — including a REFUSAL and its named
|
|
47938
|
+
* reason, because "why is this camera still on the default" has to be
|
|
47939
|
+
* answerable without re-running anything.
|
|
47940
|
+
*/
|
|
47941
|
+
stillnessCalibrationNote: string().max(400).default("")
|
|
47942
|
+
});
|
|
47943
|
+
var STILLNESS_DEFAULTS = StillnessSettingsSchema.parse({});
|
|
47944
|
+
/**
|
|
47945
|
+
* Resolve a per-device store blob into typed stillness settings. Unknown or
|
|
47946
|
+
* invalid fields fall back to the default for that field — including a bar
|
|
47947
|
+
* outside the calibration's own rails, which is refused rather than clamped:
|
|
47948
|
+
* a number the calibration could never have produced is not evidence about
|
|
47949
|
+
* this camera, and silently bending it into range would present it as if it
|
|
47950
|
+
* were.
|
|
47951
|
+
*/
|
|
47952
|
+
function resolveStillnessSettings(raw) {
|
|
47953
|
+
const pick = (key) => {
|
|
47954
|
+
const parsed = StillnessSettingsSchema.shape[key].safeParse(raw[key]);
|
|
47955
|
+
return parsed.success ? parsed.data : STILLNESS_DEFAULTS[key];
|
|
47956
|
+
};
|
|
47923
47957
|
return {
|
|
47924
|
-
|
|
47925
|
-
|
|
47926
|
-
|
|
47927
|
-
deviceId,
|
|
47928
|
-
since: readSince,
|
|
47929
|
-
until,
|
|
47930
|
-
limit: deps.fetchAvailability ? VISIT_EVENT_FETCH_LIMIT : limit
|
|
47931
|
-
});
|
|
47932
|
-
warnOnTruncatedFetch(deps, deviceId, events);
|
|
47933
|
-
let vouched = /* @__PURE__ */ new Set();
|
|
47934
|
-
try {
|
|
47935
|
-
vouched = await resolveVouchedEvents(deviceId, events, deps.fetchMediaOwners);
|
|
47936
|
-
} catch (err) {
|
|
47937
|
-
deps.logWarn?.("videoclips: media presence read failed — listing without thumbnails", {
|
|
47938
|
-
deviceId,
|
|
47939
|
-
events: allEventIds(events).length,
|
|
47940
|
-
error: err instanceof Error ? err.message : String(err)
|
|
47941
|
-
});
|
|
47942
|
-
}
|
|
47943
|
-
let clips = eventsToClips(events, deps.defaultPad, vouched);
|
|
47944
|
-
if (deps.fetchAvailability) try {
|
|
47945
|
-
clips = visitsToClips(clusterFootageVisits(await deps.fetchAvailability({
|
|
47946
|
-
deviceId,
|
|
47947
|
-
since: readSince,
|
|
47948
|
-
until
|
|
47949
|
-
}), VISIT_MERGE_GAP_MS), events, deps.defaultPad, vouched);
|
|
47950
|
-
} catch (err) {
|
|
47951
|
-
deps.logWarn?.("videoclips: availability read failed — listing unfiltered", {
|
|
47952
|
-
deviceId,
|
|
47953
|
-
error: err instanceof Error ? err.message : String(err)
|
|
47954
|
-
});
|
|
47955
|
-
}
|
|
47956
|
-
const inWindow = clips.filter((c) => intersectsWindow(c, since, until));
|
|
47957
|
-
const answer = limit != null ? inWindow.slice(0, limit) : inWindow;
|
|
47958
|
-
reportUnvouchedClips(deps, deviceId, answer);
|
|
47959
|
-
return answer;
|
|
47960
|
-
},
|
|
47961
|
-
/**
|
|
47962
|
-
* The one source this provider serves, on every camera: the hub's own
|
|
47963
|
-
* analytics visits over recorded footage.
|
|
47964
|
-
*
|
|
47965
|
-
* Always `ok`, and that is not optimism — this source IS the process
|
|
47966
|
-
* answering the call, so there is no reachability question to report. A
|
|
47967
|
-
* read that fails INSIDE `listClips` degrades that list (and logs it); a
|
|
47968
|
-
* source that cannot be reached at all is reported by the collection
|
|
47969
|
-
* dispatcher, which is the only layer that can tell the difference.
|
|
47970
|
-
* `label` is what the picker draws.
|
|
47971
|
-
*/
|
|
47972
|
-
listSources: async () => [{
|
|
47973
|
-
source: SOURCE,
|
|
47974
|
-
addonId: ANALYTICS_ADDON_ID,
|
|
47975
|
-
label: "CamStack recordings",
|
|
47976
|
-
availability: { state: "ok" }
|
|
47977
|
-
}],
|
|
47978
|
-
getClipPlayback: async ({ deviceId, clipId }) => {
|
|
47979
|
-
const parsed = parseClipId(clipId);
|
|
47980
|
-
if (!parsed) throw new Error(`videoclips: unrecognized clipId "${clipId}"`);
|
|
47981
|
-
return {
|
|
47982
|
-
...await deps.resolvePlayback({
|
|
47983
|
-
deviceId,
|
|
47984
|
-
startMs: parsed.startMs,
|
|
47985
|
-
endMs: parsed.endMs
|
|
47986
|
-
}),
|
|
47987
|
-
format: "hls"
|
|
47988
|
-
};
|
|
47989
|
-
}
|
|
47958
|
+
stillnessSpeedFracPerSec: pick("stillnessSpeedFracPerSec"),
|
|
47959
|
+
stillnessCalibratedAt: pick("stillnessCalibratedAt"),
|
|
47960
|
+
stillnessCalibrationNote: pick("stillnessCalibrationNote")
|
|
47990
47961
|
};
|
|
47991
47962
|
}
|
|
47992
|
-
/**
|
|
47993
|
-
*
|
|
47994
|
-
|
|
47995
|
-
|
|
47996
|
-
|
|
47997
|
-
|
|
47998
|
-
|
|
47999
|
-
|
|
48000
|
-
|
|
48001
|
-
if (truncated.length === 0) return;
|
|
48002
|
-
deps.logWarn?.("videoclips: annotation fetch truncated — earliest visits lose their events", {
|
|
48003
|
-
deviceId,
|
|
48004
|
-
kinds: truncated,
|
|
48005
|
-
limit: VISIT_EVENT_FETCH_LIMIT
|
|
48006
|
-
});
|
|
48007
|
-
}
|
|
48008
|
-
/** The operator's acceptance criterion as a number: a rising count on one
|
|
48009
|
-
* camera is its motion-snapshot capturer failing, not a quiet day. */
|
|
48010
|
-
function reportUnvouchedClips(deps, deviceId, clips) {
|
|
48011
|
-
const clipsWithoutStill = clips.filter((c) => c.thumbnail === void 0).length;
|
|
48012
|
-
if (clipsWithoutStill === 0) return;
|
|
48013
|
-
deps.logInfo?.("videoclips: visit has no vouched still", {
|
|
48014
|
-
deviceId,
|
|
48015
|
-
clipsWithoutStill,
|
|
48016
|
-
clips: clips.length
|
|
48017
|
-
});
|
|
48018
|
-
}
|
|
48019
|
-
//#endregion
|
|
48020
|
-
//#region src/pipeline-analytics/videoclips-shared.ts
|
|
48021
|
-
/** Stringify the numeric event ids of one bucket. Lossless. */
|
|
48022
|
-
function toEventLike(events) {
|
|
48023
|
-
return events.map((e) => ({
|
|
48024
|
-
...e,
|
|
48025
|
-
id: String(e.id)
|
|
48026
|
-
}));
|
|
47963
|
+
/**
|
|
47964
|
+
* The bar the decision layer gets: a positive, in-rails number, or
|
|
47965
|
+
* `undefined` for "this camera is not calibrated — judge it exactly as
|
|
47966
|
+
* before". The ONE place the stored-zero convention is interpreted.
|
|
47967
|
+
*/
|
|
47968
|
+
function resolveStillSpeedFracPerSec(settings) {
|
|
47969
|
+
const bar = settings.stillnessSpeedFracPerSec;
|
|
47970
|
+
if (!(bar >= .001) || bar > 1) return void 0;
|
|
47971
|
+
return bar;
|
|
48027
47972
|
}
|
|
48028
47973
|
//#endregion
|
|
48029
47974
|
//#region src/pipeline-analytics/viewer-settings-actions.ts
|
|
@@ -48245,336 +48190,6 @@ function makeViewerSettingsActionHandlers(store) {
|
|
|
48245
48190
|
};
|
|
48246
48191
|
}
|
|
48247
48192
|
//#endregion
|
|
48248
|
-
//#region src/pipeline-analytics/stillness-calibration-actions.ts
|
|
48249
|
-
/**
|
|
48250
|
-
* stillness-calibration-actions — "measure this camera's own stillness scale".
|
|
48251
|
-
*
|
|
48252
|
-
* ## Why an `addons.custom` action and not a cap method
|
|
48253
|
-
*
|
|
48254
|
-
* Same reason as `face.rescoreTrack` beside it: a cap method's wire schema
|
|
48255
|
-
* lives in `@camstack/types`, which travels inside the `@camstack/server`
|
|
48256
|
-
* closure, so a new one is not callable until a server train ships. Here the
|
|
48257
|
-
* schema lives in this addon's own dist and the hub forwards an opaque
|
|
48258
|
-
* envelope, so `camstack deploy` is the whole delivery.
|
|
48259
|
-
*
|
|
48260
|
-
* ## Why `apply` is explicit and not a fallback
|
|
48261
|
-
*
|
|
48262
|
-
* A calibration run READS recorded tracks and does arithmetic. Applying it
|
|
48263
|
-
* WRITES the camera's settings and changes what the tracker calls settled from
|
|
48264
|
-
* the next frame on. Those are different enough in consequence that a button
|
|
48265
|
-
* labelled "calibrate" must not choose between them on the operator's behalf —
|
|
48266
|
-
* the run reports, the operator applies. A REFUSED run never writes the bar
|
|
48267
|
-
* whatever `apply` says; it writes only the note, so the refusal and its reason
|
|
48268
|
-
* are visible in the form instead of being a toast that scrolls away.
|
|
48269
|
-
*/
|
|
48270
|
-
/** Mirrors `StillnessCalibrationRefusal` — kept literal so the wire schema is
|
|
48271
|
-
* self-describing and a new reason is a deliberate edit in both places. */
|
|
48272
|
-
var StillnessRefusalSchema = _enum([
|
|
48273
|
-
"no-tracks",
|
|
48274
|
-
"too-few-tracks",
|
|
48275
|
-
"too-few-samples",
|
|
48276
|
-
"no-motion-evidence"
|
|
48277
|
-
]);
|
|
48278
|
-
var StillnessMeasurementSchema = object({
|
|
48279
|
-
/** Tracks that contributed at least one speed sample. */
|
|
48280
|
-
trackCount: number().int(),
|
|
48281
|
-
/** Tracks the pass actually read, after the cost bound. */
|
|
48282
|
-
tracksRead: number().int(),
|
|
48283
|
-
sampleCount: number().int(),
|
|
48284
|
-
/** Speed quantiles, subject-box-diagonals per second. `null` when there was
|
|
48285
|
-
* nothing to measure — never 0, which would read as a measured stillness
|
|
48286
|
-
* (D393). */
|
|
48287
|
-
p25: number().nullable(),
|
|
48288
|
-
p50: number().nullable(),
|
|
48289
|
-
p90: number().nullable(),
|
|
48290
|
-
/** Median gap between stored positions (s) — the camera's real cadence. */
|
|
48291
|
-
medianIntervalSec: number().nullable(),
|
|
48292
|
-
/** Median subject box diagonal (px) the speeds were normalised by. */
|
|
48293
|
-
medianSubjectDiagonalPx: number().nullable()
|
|
48294
|
-
});
|
|
48295
|
-
var stillnessCalibrationActions = defineCustomActions({
|
|
48296
|
-
/**
|
|
48297
|
-
* `admin` because it WRITES a per-camera detection threshold when `apply` is
|
|
48298
|
-
* set, and because the report describes how the camera's subjects move,
|
|
48299
|
-
* which is not a viewer-level fact.
|
|
48300
|
-
*/
|
|
48301
|
-
"stillness.calibrate": customAction(object({
|
|
48302
|
-
deviceId: number().int(),
|
|
48303
|
-
/** How far back to read. Bounded: this pass parses ~10 kB of trajectory a
|
|
48304
|
-
* row, so the window is a suggestion and `maxTracks` is the real bound. */
|
|
48305
|
-
sinceHours: number().min(.25).max(720).default(72),
|
|
48306
|
-
/** Hard cost bound on tracks read, newest first. */
|
|
48307
|
-
maxTracks: number().int().min(1).max(1e3).default(200),
|
|
48308
|
-
/**
|
|
48309
|
-
* Write the chosen bar onto the camera. Never implicit, and never done at
|
|
48310
|
-
* all for a refused run.
|
|
48311
|
-
*/
|
|
48312
|
-
apply: boolean().default(false)
|
|
48313
|
-
}), object({
|
|
48314
|
-
deviceId: number().int(),
|
|
48315
|
-
/** The window actually read (epoch ms). */
|
|
48316
|
-
since: number().int(),
|
|
48317
|
-
until: number().int(),
|
|
48318
|
-
accepted: boolean(),
|
|
48319
|
-
/** Why it refused. Absent on an accepted run. */
|
|
48320
|
-
reason: StillnessRefusalSchema.optional(),
|
|
48321
|
-
/** The chosen bar, subject-box-diagonals per second. Absent on a refusal —
|
|
48322
|
-
* never 0, which the settings layer reads as "uncalibrated". */
|
|
48323
|
-
bar: number().optional(),
|
|
48324
|
-
/** The raw quantile before the rails, so the clamp is arguable. */
|
|
48325
|
-
rawBar: number().optional(),
|
|
48326
|
-
clampedBy: _enum([
|
|
48327
|
-
"none",
|
|
48328
|
-
"floor",
|
|
48329
|
-
"ceiling",
|
|
48330
|
-
"min",
|
|
48331
|
-
"max"
|
|
48332
|
-
]).optional(),
|
|
48333
|
-
measurement: StillnessMeasurementSchema,
|
|
48334
|
-
/** The bar this camera was on BEFORE the run — `null` = uncalibrated. Read
|
|
48335
|
-
* before any write, so the operator sees both numbers. */
|
|
48336
|
-
previousBar: number().nullable(),
|
|
48337
|
-
/** Whether the camera's settings were actually written. */
|
|
48338
|
-
applied: boolean(),
|
|
48339
|
-
/** The one-line note stored on the camera (accepted or refused). */
|
|
48340
|
-
note: string()
|
|
48341
|
-
}), {
|
|
48342
|
-
kind: "mutation",
|
|
48343
|
-
auth: "admin"
|
|
48344
|
-
}) });
|
|
48345
|
-
/**
|
|
48346
|
-
* The shipped limits.
|
|
48347
|
-
*
|
|
48348
|
-
* `minTracks` 12 / `minSamples` 200: the four live cameras sampled above
|
|
48349
|
-
* produced 697–8739 samples from 42–51 tracks in a single 60-track read, so a
|
|
48350
|
-
* camera that cannot clear these has genuinely not been watched enough.
|
|
48351
|
-
* `maxTracks` 200 bounds the read: the `positions` blob averages ~10 kB a row
|
|
48352
|
-
* (`track-store.ts`), so this pass is ~2 MB of JSON at its worst.
|
|
48353
|
-
*/
|
|
48354
|
-
var DEFAULT_STILLNESS_CALIBRATION_LIMITS = {
|
|
48355
|
-
minTracks: 12,
|
|
48356
|
-
minSamples: 200,
|
|
48357
|
-
maxTracks: 200,
|
|
48358
|
-
minIntervalSec: .02,
|
|
48359
|
-
maxIntervalSec: 3,
|
|
48360
|
-
quantile: .25,
|
|
48361
|
-
floorFactor: .02,
|
|
48362
|
-
ceilFactor: .25,
|
|
48363
|
-
minBar: .001,
|
|
48364
|
-
maxBar: 1
|
|
48365
|
-
};
|
|
48366
|
-
/** Linear-interpolated quantile. `NaN` for an empty list — never 0, which
|
|
48367
|
-
* would read as a measured zero (D393). */
|
|
48368
|
-
function quantileOf(values, p) {
|
|
48369
|
-
if (values.length === 0) return NaN;
|
|
48370
|
-
const sorted = [...values].sort((a, b) => a - b);
|
|
48371
|
-
const idx = (sorted.length - 1) * Math.min(Math.max(p, 0), 1);
|
|
48372
|
-
const lo = Math.floor(idx);
|
|
48373
|
-
const hi = Math.ceil(idx);
|
|
48374
|
-
const at = sorted[lo];
|
|
48375
|
-
const next = sorted[hi];
|
|
48376
|
-
if (at === void 0 || next === void 0) return NaN;
|
|
48377
|
-
return at + (next - at) * (idx - lo);
|
|
48378
|
-
}
|
|
48379
|
-
/**
|
|
48380
|
-
* Per-sample centroid speeds for a camera, in subject-box-diagonals per second.
|
|
48381
|
-
*
|
|
48382
|
-
* A pair of consecutive positions contributes a sample only when the interval
|
|
48383
|
-
* between them is inside `[minIntervalSec, maxIntervalSec]` and the later box
|
|
48384
|
-
* has a positive diagonal. A gap outside that band is a session boundary or a
|
|
48385
|
-
* duplicate read, not a measurement of how fast anything travelled; a box with
|
|
48386
|
-
* no size is unknown geometry, and unknown is never a sample.
|
|
48387
|
-
*/
|
|
48388
|
-
function collectStillnessSamples(tracks, limits) {
|
|
48389
|
-
const speeds = [];
|
|
48390
|
-
const intervals = [];
|
|
48391
|
-
const diagonals = [];
|
|
48392
|
-
let trackCount = 0;
|
|
48393
|
-
const read = tracks.slice(0, limits.maxTracks);
|
|
48394
|
-
for (const track of read) {
|
|
48395
|
-
const positions = [...track.positions].sort((a, b) => a.timestamp - b.timestamp);
|
|
48396
|
-
let contributed = false;
|
|
48397
|
-
for (let i = 1; i < positions.length; i++) {
|
|
48398
|
-
const prev = positions[i - 1];
|
|
48399
|
-
const cur = positions[i];
|
|
48400
|
-
if (prev === void 0 || cur === void 0) continue;
|
|
48401
|
-
const dtSec = (cur.timestamp - prev.timestamp) / 1e3;
|
|
48402
|
-
if (dtSec < limits.minIntervalSec || dtSec > limits.maxIntervalSec) continue;
|
|
48403
|
-
const diagonal = Math.hypot(cur.bbox.w, cur.bbox.h);
|
|
48404
|
-
if (!(diagonal > 0)) continue;
|
|
48405
|
-
const travelled = Math.hypot(cur.x - prev.x, cur.y - prev.y);
|
|
48406
|
-
speeds.push(travelled / diagonal / dtSec);
|
|
48407
|
-
intervals.push(dtSec);
|
|
48408
|
-
diagonals.push(diagonal);
|
|
48409
|
-
contributed = true;
|
|
48410
|
-
}
|
|
48411
|
-
if (contributed) trackCount++;
|
|
48412
|
-
}
|
|
48413
|
-
return {
|
|
48414
|
-
speeds,
|
|
48415
|
-
intervals,
|
|
48416
|
-
diagonals,
|
|
48417
|
-
trackCount,
|
|
48418
|
-
tracksRead: read.length
|
|
48419
|
-
};
|
|
48420
|
-
}
|
|
48421
|
-
function measure$1(samples) {
|
|
48422
|
-
return {
|
|
48423
|
-
trackCount: samples.trackCount,
|
|
48424
|
-
sampleCount: samples.speeds.length,
|
|
48425
|
-
p25: quantileOf(samples.speeds, .25),
|
|
48426
|
-
p50: quantileOf(samples.speeds, .5),
|
|
48427
|
-
p90: quantileOf(samples.speeds, .9),
|
|
48428
|
-
medianIntervalSec: quantileOf(samples.intervals, .5),
|
|
48429
|
-
medianSubjectDiagonalPx: quantileOf(samples.diagonals, .5)
|
|
48430
|
-
};
|
|
48431
|
-
}
|
|
48432
|
-
/**
|
|
48433
|
-
* Choose this camera's stillness speed bar, or refuse with a named reason.
|
|
48434
|
-
*
|
|
48435
|
-
* The order of the gates is the order of the questions: is there anything at
|
|
48436
|
-
* all, is it enough tracks, is it enough samples, and did anything on this
|
|
48437
|
-
* camera ever actually move. The last one is not pedantry — the whole method
|
|
48438
|
-
* scales the bar against the camera's own travel, so with no travel there is
|
|
48439
|
-
* nothing to scale against and the default is the honest answer.
|
|
48440
|
-
*/
|
|
48441
|
-
function calibrateStillnessSpeed(samples, limits) {
|
|
48442
|
-
const measurement = measure$1(samples);
|
|
48443
|
-
if (samples.tracksRead === 0) return {
|
|
48444
|
-
ok: false,
|
|
48445
|
-
reason: "no-tracks",
|
|
48446
|
-
measurement
|
|
48447
|
-
};
|
|
48448
|
-
if (samples.trackCount < limits.minTracks) return {
|
|
48449
|
-
ok: false,
|
|
48450
|
-
reason: "too-few-tracks",
|
|
48451
|
-
measurement
|
|
48452
|
-
};
|
|
48453
|
-
if (samples.speeds.length < limits.minSamples) return {
|
|
48454
|
-
ok: false,
|
|
48455
|
-
reason: "too-few-samples",
|
|
48456
|
-
measurement
|
|
48457
|
-
};
|
|
48458
|
-
if (!(measurement.p90 > 0)) return {
|
|
48459
|
-
ok: false,
|
|
48460
|
-
reason: "no-motion-evidence",
|
|
48461
|
-
measurement
|
|
48462
|
-
};
|
|
48463
|
-
const rawBar = quantileOf(samples.speeds, limits.quantile);
|
|
48464
|
-
const floor = measurement.p90 * limits.floorFactor;
|
|
48465
|
-
const ceiling = measurement.p90 * limits.ceilFactor;
|
|
48466
|
-
let bar = rawBar;
|
|
48467
|
-
let clampedBy = "none";
|
|
48468
|
-
if (bar < floor) {
|
|
48469
|
-
bar = floor;
|
|
48470
|
-
clampedBy = "floor";
|
|
48471
|
-
} else if (bar > ceiling) {
|
|
48472
|
-
bar = ceiling;
|
|
48473
|
-
clampedBy = "ceiling";
|
|
48474
|
-
}
|
|
48475
|
-
if (bar < limits.minBar) {
|
|
48476
|
-
bar = limits.minBar;
|
|
48477
|
-
clampedBy = "min";
|
|
48478
|
-
} else if (bar > limits.maxBar) {
|
|
48479
|
-
bar = limits.maxBar;
|
|
48480
|
-
clampedBy = "max";
|
|
48481
|
-
}
|
|
48482
|
-
return {
|
|
48483
|
-
ok: true,
|
|
48484
|
-
bar,
|
|
48485
|
-
rawBar,
|
|
48486
|
-
clampedBy,
|
|
48487
|
-
measurement
|
|
48488
|
-
};
|
|
48489
|
-
}
|
|
48490
|
-
/** One line an operator can read: what was measured, from how much, and what
|
|
48491
|
-
* rule produced the stored number. Kept short — it rides the settings blob. */
|
|
48492
|
-
function describeStillnessCalibration(outcome) {
|
|
48493
|
-
const m = outcome.measurement;
|
|
48494
|
-
const n = (v) => Number.isFinite(v) ? v.toFixed(4) : "unknown";
|
|
48495
|
-
const evidence = `${m.sampleCount} samples / ${m.trackCount} tracks, p25 ${n(m.p25)}, p50 ${n(m.p50)}, p90 ${n(m.p90)} subject-diagonals/s`;
|
|
48496
|
-
if (!outcome.ok) return `refused (${outcome.reason}) — ${evidence}`;
|
|
48497
|
-
return `bar ${n(outcome.bar)} (raw ${n(outcome.rawBar)}, clamp ${outcome.clampedBy}) — ${evidence}`;
|
|
48498
|
-
}
|
|
48499
|
-
//#endregion
|
|
48500
|
-
//#region src/pipeline-analytics/stillness-settings.ts
|
|
48501
|
-
/**
|
|
48502
|
-
* Per-device STILLNESS SCALE — the one number that says how fast a subject on
|
|
48503
|
-
* THIS camera has to move before it is travelling.
|
|
48504
|
-
*
|
|
48505
|
-
* A threshold belongs to whoever GENERATES the event, per device, never baked
|
|
48506
|
-
* into a classifier default. The judgement this feeds is
|
|
48507
|
-
* `StateAnalyzer.speedSaysSettled`; the measurement behind the number is
|
|
48508
|
-
* `pipeline/tracker/stillness-scale.ts`, which also carries the live
|
|
48509
|
-
* measurement showing why one number cannot serve a 30 m driveway and a 2 m
|
|
48510
|
-
* doorway.
|
|
48511
|
-
*
|
|
48512
|
-
* Cascade and shape mirror `stationary-settings` / `media-settings`: a
|
|
48513
|
-
* per-device override on top of the default, resolved per FIELD, and a parse
|
|
48514
|
-
* that never throws on a bad blob.
|
|
48515
|
-
*
|
|
48516
|
-
* **Absent behaves exactly as today.** The device store is a flat numeric blob
|
|
48517
|
-
* with no room for "unset", so the stored form of absent is `0` — and `0` is
|
|
48518
|
-
* not a bar anyone could want (it would mean nothing on this camera is ever
|
|
48519
|
-
* still) and not a value the calibration can produce (`minBar`). The decision
|
|
48520
|
-
* layer never sees it: {@link resolveStillSpeedFracPerSec} maps it to
|
|
48521
|
-
* `undefined`, and `undefined` is what leaves `StateAnalyzer` on its original
|
|
48522
|
-
* absolute `velocityThreshold` path.
|
|
48523
|
-
*/
|
|
48524
|
-
var StillnessSettingsSchema = object({
|
|
48525
|
-
/**
|
|
48526
|
-
* The camera's "not travelling" bar: centroid speed as a fraction of the
|
|
48527
|
-
* SUBJECT's own box diagonal, per second. `0` = not calibrated (see above).
|
|
48528
|
-
*
|
|
48529
|
-
* Measured p50 on the live hub 2026-09-19, for scale: 0.0136 (device 592,
|
|
48530
|
-
* close view, mostly parked subjects) to 0.3081 (device 615, far view, only
|
|
48531
|
-
* transits).
|
|
48532
|
-
*/
|
|
48533
|
-
stillnessSpeedFracPerSec: number().min(0).max(1).default(0),
|
|
48534
|
-
/**
|
|
48535
|
-
* When the number above was last CHOSEN — by a calibration run or by the
|
|
48536
|
-
* operator. `0` = never. Purely a readout; nothing gates on it.
|
|
48537
|
-
*/
|
|
48538
|
-
stillnessCalibratedAt: number().int().min(0).default(0),
|
|
48539
|
-
/**
|
|
48540
|
-
* What the last calibration run measured and decided, in one line
|
|
48541
|
-
* (`describeStillnessCalibration`) — including a REFUSAL and its named
|
|
48542
|
-
* reason, because "why is this camera still on the default" has to be
|
|
48543
|
-
* answerable without re-running anything.
|
|
48544
|
-
*/
|
|
48545
|
-
stillnessCalibrationNote: string().max(400).default("")
|
|
48546
|
-
});
|
|
48547
|
-
var STILLNESS_DEFAULTS = StillnessSettingsSchema.parse({});
|
|
48548
|
-
/**
|
|
48549
|
-
* Resolve a per-device store blob into typed stillness settings. Unknown or
|
|
48550
|
-
* invalid fields fall back to the default for that field — including a bar
|
|
48551
|
-
* outside the calibration's own rails, which is refused rather than clamped:
|
|
48552
|
-
* a number the calibration could never have produced is not evidence about
|
|
48553
|
-
* this camera, and silently bending it into range would present it as if it
|
|
48554
|
-
* were.
|
|
48555
|
-
*/
|
|
48556
|
-
function resolveStillnessSettings(raw) {
|
|
48557
|
-
const pick = (key) => {
|
|
48558
|
-
const parsed = StillnessSettingsSchema.shape[key].safeParse(raw[key]);
|
|
48559
|
-
return parsed.success ? parsed.data : STILLNESS_DEFAULTS[key];
|
|
48560
|
-
};
|
|
48561
|
-
return {
|
|
48562
|
-
stillnessSpeedFracPerSec: pick("stillnessSpeedFracPerSec"),
|
|
48563
|
-
stillnessCalibratedAt: pick("stillnessCalibratedAt"),
|
|
48564
|
-
stillnessCalibrationNote: pick("stillnessCalibrationNote")
|
|
48565
|
-
};
|
|
48566
|
-
}
|
|
48567
|
-
/**
|
|
48568
|
-
* The bar the decision layer gets: a positive, in-rails number, or
|
|
48569
|
-
* `undefined` for "this camera is not calibrated — judge it exactly as
|
|
48570
|
-
* before". The ONE place the stored-zero convention is interpreted.
|
|
48571
|
-
*/
|
|
48572
|
-
function resolveStillSpeedFracPerSec(settings) {
|
|
48573
|
-
const bar = settings.stillnessSpeedFracPerSec;
|
|
48574
|
-
if (!(bar >= .001) || bar > 1) return void 0;
|
|
48575
|
-
return bar;
|
|
48576
|
-
}
|
|
48577
|
-
//#endregion
|
|
48578
48193
|
//#region src/pipeline-analytics/viewer-settings-legacy-adoption.ts
|
|
48579
48194
|
/**
|
|
48580
48195
|
* @durable class=config owner=pipeline-analytics
|
|
@@ -48752,6 +48367,230 @@ async function adoptLegacyViewerSettingsSnapshots(deps) {
|
|
|
48752
48367
|
return retired;
|
|
48753
48368
|
}
|
|
48754
48369
|
/**
|
|
48370
|
+
* The VIDEO's playback rate — 4×, the same as {@link NC_GIF_SPEED}.
|
|
48371
|
+
*
|
|
48372
|
+
* This was 1, and the reasoning for 1 was sound as far as it went: `speed !== 1`
|
|
48373
|
+
* fails `clipCanCopy`, so a sped-up video cannot be the camera's own H.264
|
|
48374
|
+
* copied — it is a `libx264` burst. The OPERATOR priced that and took it. It is
|
|
48375
|
+
* one encode per event over a ~12 s window, not a permanent transcode child
|
|
48376
|
+
* ([D84](../../../../../../docs/decisions/adr-0084.md) is about the latter), and
|
|
48377
|
+
* it was measured on a real 615 720p cut before being chosen: **0.23 s of
|
|
48378
|
+
* encode, 254 KB out**, against the 922 KB the copy of the same window carried.
|
|
48379
|
+
* The re-encode is smaller than what it replaces.
|
|
48380
|
+
*
|
|
48381
|
+
* So both attachments now agree on the timeline as well as on the window: one
|
|
48382
|
+
* clip, one rate, two containers.
|
|
48383
|
+
*/
|
|
48384
|
+
var DEFAULT_SPEED = 4;
|
|
48385
|
+
/** The fallback mp4's requested width — the cap's own ceiling, so a rendition
|
|
48386
|
+
* at or below 1080p is an identity scale and the broker copies it. */
|
|
48387
|
+
var RING_MP4_MAX_WIDTH = 1920;
|
|
48388
|
+
/** MP4 keeps the source cadence; this only bounds the muxer. The cap caps at 15. */
|
|
48389
|
+
var RING_MP4_FPS = 15;
|
|
48390
|
+
var NO_MEDIA = {
|
|
48391
|
+
mp4: null,
|
|
48392
|
+
gif: null,
|
|
48393
|
+
source: "none",
|
|
48394
|
+
startOffsetMs: null,
|
|
48395
|
+
endOffsetMs: null,
|
|
48396
|
+
profile: null,
|
|
48397
|
+
video: null
|
|
48398
|
+
};
|
|
48399
|
+
var EventMediaService = class {
|
|
48400
|
+
deps;
|
|
48401
|
+
constructor(deps) {
|
|
48402
|
+
this.deps = deps;
|
|
48403
|
+
}
|
|
48404
|
+
/**
|
|
48405
|
+
* Cut this event. Never throws — a notification that lost its media is still
|
|
48406
|
+
* a notification, and every branch that drops it logs why.
|
|
48407
|
+
*/
|
|
48408
|
+
async cut(request) {
|
|
48409
|
+
if (!request.wantMp4 && !request.wantGif) return NO_MEDIA;
|
|
48410
|
+
const produced = await this.produce(request);
|
|
48411
|
+
if (produced !== null) return produced;
|
|
48412
|
+
return this.fallbackToRing(request);
|
|
48413
|
+
}
|
|
48414
|
+
async produce(request) {
|
|
48415
|
+
const deviceId = request.deviceId;
|
|
48416
|
+
const log = this.deps.logger;
|
|
48417
|
+
const kinds = [];
|
|
48418
|
+
if (request.wantMp4) kinds.push("mp4");
|
|
48419
|
+
if (request.wantGif) kinds.push("gif");
|
|
48420
|
+
let production;
|
|
48421
|
+
try {
|
|
48422
|
+
production = await this.deps.produce({
|
|
48423
|
+
deviceId,
|
|
48424
|
+
aroundMs: request.aroundMs,
|
|
48425
|
+
preSeconds: request.preRollSec,
|
|
48426
|
+
postSeconds: request.postRollSec,
|
|
48427
|
+
kinds,
|
|
48428
|
+
gifMaxWidth: 640,
|
|
48429
|
+
gifFps: 12,
|
|
48430
|
+
gifSpeed: 4,
|
|
48431
|
+
speed: request.speed ?? DEFAULT_SPEED,
|
|
48432
|
+
...request.profile !== void 0 ? { profile: request.profile } : {}
|
|
48433
|
+
});
|
|
48434
|
+
} catch (err) {
|
|
48435
|
+
log.warn("nc media: the broker could not produce this event — falling back to the clip ring", {
|
|
48436
|
+
tags: { deviceId },
|
|
48437
|
+
meta: { error: err instanceof Error ? err.message : String(err) }
|
|
48438
|
+
});
|
|
48439
|
+
return null;
|
|
48440
|
+
}
|
|
48441
|
+
const mp4 = await this.redeem(deviceId, production.media, "mp4");
|
|
48442
|
+
const gif = await this.redeem(deviceId, production.media, "gif");
|
|
48443
|
+
if (mp4 === null && gif === null) {
|
|
48444
|
+
log.warn("nc media: the production carried no artifact — falling back to the clip ring", {
|
|
48445
|
+
tags: { deviceId },
|
|
48446
|
+
meta: {
|
|
48447
|
+
kinds: kinds.join(","),
|
|
48448
|
+
profile: production.profile
|
|
48449
|
+
}
|
|
48450
|
+
});
|
|
48451
|
+
return null;
|
|
48452
|
+
}
|
|
48453
|
+
const startOffsetMs = production.coverage.fromTs - request.aroundMs;
|
|
48454
|
+
const endOffsetMs = production.coverage.toTs - request.aroundMs;
|
|
48455
|
+
log.info("nc media: one production, every attachment", {
|
|
48456
|
+
tags: { deviceId },
|
|
48457
|
+
meta: {
|
|
48458
|
+
profile: production.profile,
|
|
48459
|
+
video: production.video,
|
|
48460
|
+
mp4Bytes: mp4?.byteLength ?? null,
|
|
48461
|
+
gifBytes: gif?.byteLength ?? null,
|
|
48462
|
+
startOffsetMs,
|
|
48463
|
+
endOffsetMs,
|
|
48464
|
+
sharedWindow: true
|
|
48465
|
+
}
|
|
48466
|
+
});
|
|
48467
|
+
return {
|
|
48468
|
+
mp4,
|
|
48469
|
+
gif,
|
|
48470
|
+
source: "produced",
|
|
48471
|
+
startOffsetMs,
|
|
48472
|
+
endOffsetMs,
|
|
48473
|
+
profile: production.profile,
|
|
48474
|
+
video: production.video
|
|
48475
|
+
};
|
|
48476
|
+
}
|
|
48477
|
+
/**
|
|
48478
|
+
* Redeem one artifact handle at the node that produced it.
|
|
48479
|
+
*
|
|
48480
|
+
* `null` is not an error here — a production simply may not carry the kind
|
|
48481
|
+
* (a gif whose derive failed says so on the broker's own log line). A handle
|
|
48482
|
+
* that FAILS to redeem is different and is logged, because it means the bytes
|
|
48483
|
+
* existed and did not arrive.
|
|
48484
|
+
*/
|
|
48485
|
+
async redeem(deviceId, media, kind) {
|
|
48486
|
+
const artifact = media.find((m) => m.kind === kind);
|
|
48487
|
+
if (artifact === void 0) return null;
|
|
48488
|
+
try {
|
|
48489
|
+
const res = await this.deps.fetch(artifact.handle, artifact.nodeId);
|
|
48490
|
+
if (res === null) {
|
|
48491
|
+
this.deps.logger.warn("nc media: an artifact handle expired before it could be fetched", {
|
|
48492
|
+
tags: { deviceId },
|
|
48493
|
+
meta: {
|
|
48494
|
+
kind,
|
|
48495
|
+
handle: artifact.handle,
|
|
48496
|
+
nodeId: artifact.nodeId
|
|
48497
|
+
}
|
|
48498
|
+
});
|
|
48499
|
+
return null;
|
|
48500
|
+
}
|
|
48501
|
+
const buf = Buffer.from(res.base64, "base64");
|
|
48502
|
+
if (buf.byteLength === 0) return null;
|
|
48503
|
+
const bytes = new Uint8Array(buf.byteLength);
|
|
48504
|
+
bytes.set(buf);
|
|
48505
|
+
return bytes;
|
|
48506
|
+
} catch (err) {
|
|
48507
|
+
this.deps.logger.warn("nc media: fetching an artifact failed — that attachment is dropped", {
|
|
48508
|
+
tags: { deviceId },
|
|
48509
|
+
meta: {
|
|
48510
|
+
kind,
|
|
48511
|
+
handle: artifact.handle,
|
|
48512
|
+
nodeId: artifact.nodeId,
|
|
48513
|
+
error: err instanceof Error ? err.message : String(err)
|
|
48514
|
+
}
|
|
48515
|
+
});
|
|
48516
|
+
return null;
|
|
48517
|
+
}
|
|
48518
|
+
}
|
|
48519
|
+
/**
|
|
48520
|
+
* The pre-`produceEventMedia` path: `renderPreBufferClip`, once per container.
|
|
48521
|
+
*
|
|
48522
|
+
* Weaker than a production and deliberately so — the coherence here rests on
|
|
48523
|
+
* the two calls being given IDENTICAL parameters rather than on there being
|
|
48524
|
+
* one render. That is defensible because the ring only ever grows forward and
|
|
48525
|
+
* `windowAround` selects by wall clock around the same instant, so two calls
|
|
48526
|
+
* seconds apart choose the same packets; the one thing that could differ is
|
|
48527
|
+
* the rendition, so the profile is pinned to whatever the FIRST call actually
|
|
48528
|
+
* used and handed to the second.
|
|
48529
|
+
*
|
|
48530
|
+
* It exists for one reason: a hub whose `@camstack/server` predates the
|
|
48531
|
+
* production method must not stop attaching footage, and three of the four
|
|
48532
|
+
* live rules on this install ask for a gif and nothing else.
|
|
48533
|
+
*/
|
|
48534
|
+
async fallbackToRing(request) {
|
|
48535
|
+
const deviceId = request.deviceId;
|
|
48536
|
+
const speed = request.speed ?? DEFAULT_SPEED;
|
|
48537
|
+
const window = {
|
|
48538
|
+
deviceId,
|
|
48539
|
+
aroundMs: request.aroundMs,
|
|
48540
|
+
preRollSec: request.preRollSec,
|
|
48541
|
+
postRollSec: request.postRollSec,
|
|
48542
|
+
speed,
|
|
48543
|
+
...request.profile !== void 0 ? { profile: request.profile } : {}
|
|
48544
|
+
};
|
|
48545
|
+
try {
|
|
48546
|
+
const mp4 = request.wantMp4 ? await this.deps.renderRingClip({
|
|
48547
|
+
...window,
|
|
48548
|
+
format: "mp4",
|
|
48549
|
+
maxWidth: RING_MP4_MAX_WIDTH,
|
|
48550
|
+
fps: RING_MP4_FPS
|
|
48551
|
+
}) : null;
|
|
48552
|
+
const gif = request.wantGif ? await this.deps.renderRingClip({
|
|
48553
|
+
...window,
|
|
48554
|
+
format: "gif",
|
|
48555
|
+
maxWidth: 640,
|
|
48556
|
+
fps: 12 / 4,
|
|
48557
|
+
speed: 4
|
|
48558
|
+
}) : null;
|
|
48559
|
+
if ((mp4 === null || mp4.byteLength === 0) && (gif === null || gif.byteLength === 0)) {
|
|
48560
|
+
this.deps.logger.warn("nc media: the clip ring covered nothing — no footage attached", {
|
|
48561
|
+
tags: { deviceId },
|
|
48562
|
+
meta: { aroundMs: request.aroundMs }
|
|
48563
|
+
});
|
|
48564
|
+
return NO_MEDIA;
|
|
48565
|
+
}
|
|
48566
|
+
this.deps.logger.info("nc media: served by the clip-ring FALLBACK", {
|
|
48567
|
+
tags: { deviceId },
|
|
48568
|
+
meta: {
|
|
48569
|
+
mp4Bytes: mp4?.byteLength ?? null,
|
|
48570
|
+
gifBytes: gif?.byteLength ?? null,
|
|
48571
|
+
profile: request.profile ?? null,
|
|
48572
|
+
sharedWindow: "by-parameters"
|
|
48573
|
+
}
|
|
48574
|
+
});
|
|
48575
|
+
return {
|
|
48576
|
+
mp4: mp4 !== null && mp4.byteLength > 0 ? mp4 : null,
|
|
48577
|
+
gif: gif !== null && gif.byteLength > 0 ? gif : null,
|
|
48578
|
+
source: "ring-fallback",
|
|
48579
|
+
startOffsetMs: -Math.max(0, request.preRollSec) * 1e3,
|
|
48580
|
+
endOffsetMs: Math.max(0, request.postRollSec) * 1e3,
|
|
48581
|
+
profile: request.profile ?? null,
|
|
48582
|
+
video: null
|
|
48583
|
+
};
|
|
48584
|
+
} catch (err) {
|
|
48585
|
+
this.deps.logger.warn("nc media: the clip ring failed too — this event ships no footage", {
|
|
48586
|
+
tags: { deviceId },
|
|
48587
|
+
meta: { error: err instanceof Error ? err.message : String(err) }
|
|
48588
|
+
});
|
|
48589
|
+
return NO_MEDIA;
|
|
48590
|
+
}
|
|
48591
|
+
}
|
|
48592
|
+
};
|
|
48593
|
+
/**
|
|
48755
48594
|
* How long the recorder keeps the file we are about to read and delete.
|
|
48756
48595
|
*
|
|
48757
48596
|
* `maxLifeMs` is `z.number().int().positive()` on the capability, so "do not
|
|
@@ -49005,230 +48844,6 @@ function decodeBase64(base64) {
|
|
|
49005
48844
|
return null;
|
|
49006
48845
|
}
|
|
49007
48846
|
}
|
|
49008
|
-
/**
|
|
49009
|
-
* The VIDEO's playback rate — 4×, the same as {@link NC_GIF_SPEED}.
|
|
49010
|
-
*
|
|
49011
|
-
* This was 1, and the reasoning for 1 was sound as far as it went: `speed !== 1`
|
|
49012
|
-
* fails `clipCanCopy`, so a sped-up video cannot be the camera's own H.264
|
|
49013
|
-
* copied — it is a `libx264` burst. The OPERATOR priced that and took it. It is
|
|
49014
|
-
* one encode per event over a ~12 s window, not a permanent transcode child
|
|
49015
|
-
* ([D84](../../../../../../docs/decisions/adr-0084.md) is about the latter), and
|
|
49016
|
-
* it was measured on a real 615 720p cut before being chosen: **0.23 s of
|
|
49017
|
-
* encode, 254 KB out**, against the 922 KB the copy of the same window carried.
|
|
49018
|
-
* The re-encode is smaller than what it replaces.
|
|
49019
|
-
*
|
|
49020
|
-
* So both attachments now agree on the timeline as well as on the window: one
|
|
49021
|
-
* clip, one rate, two containers.
|
|
49022
|
-
*/
|
|
49023
|
-
var DEFAULT_SPEED = 4;
|
|
49024
|
-
/** The fallback mp4's requested width — the cap's own ceiling, so a rendition
|
|
49025
|
-
* at or below 1080p is an identity scale and the broker copies it. */
|
|
49026
|
-
var RING_MP4_MAX_WIDTH = 1920;
|
|
49027
|
-
/** MP4 keeps the source cadence; this only bounds the muxer. The cap caps at 15. */
|
|
49028
|
-
var RING_MP4_FPS = 15;
|
|
49029
|
-
var NO_MEDIA = {
|
|
49030
|
-
mp4: null,
|
|
49031
|
-
gif: null,
|
|
49032
|
-
source: "none",
|
|
49033
|
-
startOffsetMs: null,
|
|
49034
|
-
endOffsetMs: null,
|
|
49035
|
-
profile: null,
|
|
49036
|
-
video: null
|
|
49037
|
-
};
|
|
49038
|
-
var EventMediaService = class {
|
|
49039
|
-
deps;
|
|
49040
|
-
constructor(deps) {
|
|
49041
|
-
this.deps = deps;
|
|
49042
|
-
}
|
|
49043
|
-
/**
|
|
49044
|
-
* Cut this event. Never throws — a notification that lost its media is still
|
|
49045
|
-
* a notification, and every branch that drops it logs why.
|
|
49046
|
-
*/
|
|
49047
|
-
async cut(request) {
|
|
49048
|
-
if (!request.wantMp4 && !request.wantGif) return NO_MEDIA;
|
|
49049
|
-
const produced = await this.produce(request);
|
|
49050
|
-
if (produced !== null) return produced;
|
|
49051
|
-
return this.fallbackToRing(request);
|
|
49052
|
-
}
|
|
49053
|
-
async produce(request) {
|
|
49054
|
-
const deviceId = request.deviceId;
|
|
49055
|
-
const log = this.deps.logger;
|
|
49056
|
-
const kinds = [];
|
|
49057
|
-
if (request.wantMp4) kinds.push("mp4");
|
|
49058
|
-
if (request.wantGif) kinds.push("gif");
|
|
49059
|
-
let production;
|
|
49060
|
-
try {
|
|
49061
|
-
production = await this.deps.produce({
|
|
49062
|
-
deviceId,
|
|
49063
|
-
aroundMs: request.aroundMs,
|
|
49064
|
-
preSeconds: request.preRollSec,
|
|
49065
|
-
postSeconds: request.postRollSec,
|
|
49066
|
-
kinds,
|
|
49067
|
-
gifMaxWidth: 640,
|
|
49068
|
-
gifFps: 12,
|
|
49069
|
-
gifSpeed: 4,
|
|
49070
|
-
speed: request.speed ?? DEFAULT_SPEED,
|
|
49071
|
-
...request.profile !== void 0 ? { profile: request.profile } : {}
|
|
49072
|
-
});
|
|
49073
|
-
} catch (err) {
|
|
49074
|
-
log.warn("nc media: the broker could not produce this event — falling back to the clip ring", {
|
|
49075
|
-
tags: { deviceId },
|
|
49076
|
-
meta: { error: err instanceof Error ? err.message : String(err) }
|
|
49077
|
-
});
|
|
49078
|
-
return null;
|
|
49079
|
-
}
|
|
49080
|
-
const mp4 = await this.redeem(deviceId, production.media, "mp4");
|
|
49081
|
-
const gif = await this.redeem(deviceId, production.media, "gif");
|
|
49082
|
-
if (mp4 === null && gif === null) {
|
|
49083
|
-
log.warn("nc media: the production carried no artifact — falling back to the clip ring", {
|
|
49084
|
-
tags: { deviceId },
|
|
49085
|
-
meta: {
|
|
49086
|
-
kinds: kinds.join(","),
|
|
49087
|
-
profile: production.profile
|
|
49088
|
-
}
|
|
49089
|
-
});
|
|
49090
|
-
return null;
|
|
49091
|
-
}
|
|
49092
|
-
const startOffsetMs = production.coverage.fromTs - request.aroundMs;
|
|
49093
|
-
const endOffsetMs = production.coverage.toTs - request.aroundMs;
|
|
49094
|
-
log.info("nc media: one production, every attachment", {
|
|
49095
|
-
tags: { deviceId },
|
|
49096
|
-
meta: {
|
|
49097
|
-
profile: production.profile,
|
|
49098
|
-
video: production.video,
|
|
49099
|
-
mp4Bytes: mp4?.byteLength ?? null,
|
|
49100
|
-
gifBytes: gif?.byteLength ?? null,
|
|
49101
|
-
startOffsetMs,
|
|
49102
|
-
endOffsetMs,
|
|
49103
|
-
sharedWindow: true
|
|
49104
|
-
}
|
|
49105
|
-
});
|
|
49106
|
-
return {
|
|
49107
|
-
mp4,
|
|
49108
|
-
gif,
|
|
49109
|
-
source: "produced",
|
|
49110
|
-
startOffsetMs,
|
|
49111
|
-
endOffsetMs,
|
|
49112
|
-
profile: production.profile,
|
|
49113
|
-
video: production.video
|
|
49114
|
-
};
|
|
49115
|
-
}
|
|
49116
|
-
/**
|
|
49117
|
-
* Redeem one artifact handle at the node that produced it.
|
|
49118
|
-
*
|
|
49119
|
-
* `null` is not an error here — a production simply may not carry the kind
|
|
49120
|
-
* (a gif whose derive failed says so on the broker's own log line). A handle
|
|
49121
|
-
* that FAILS to redeem is different and is logged, because it means the bytes
|
|
49122
|
-
* existed and did not arrive.
|
|
49123
|
-
*/
|
|
49124
|
-
async redeem(deviceId, media, kind) {
|
|
49125
|
-
const artifact = media.find((m) => m.kind === kind);
|
|
49126
|
-
if (artifact === void 0) return null;
|
|
49127
|
-
try {
|
|
49128
|
-
const res = await this.deps.fetch(artifact.handle, artifact.nodeId);
|
|
49129
|
-
if (res === null) {
|
|
49130
|
-
this.deps.logger.warn("nc media: an artifact handle expired before it could be fetched", {
|
|
49131
|
-
tags: { deviceId },
|
|
49132
|
-
meta: {
|
|
49133
|
-
kind,
|
|
49134
|
-
handle: artifact.handle,
|
|
49135
|
-
nodeId: artifact.nodeId
|
|
49136
|
-
}
|
|
49137
|
-
});
|
|
49138
|
-
return null;
|
|
49139
|
-
}
|
|
49140
|
-
const buf = Buffer.from(res.base64, "base64");
|
|
49141
|
-
if (buf.byteLength === 0) return null;
|
|
49142
|
-
const bytes = new Uint8Array(buf.byteLength);
|
|
49143
|
-
bytes.set(buf);
|
|
49144
|
-
return bytes;
|
|
49145
|
-
} catch (err) {
|
|
49146
|
-
this.deps.logger.warn("nc media: fetching an artifact failed — that attachment is dropped", {
|
|
49147
|
-
tags: { deviceId },
|
|
49148
|
-
meta: {
|
|
49149
|
-
kind,
|
|
49150
|
-
handle: artifact.handle,
|
|
49151
|
-
nodeId: artifact.nodeId,
|
|
49152
|
-
error: err instanceof Error ? err.message : String(err)
|
|
49153
|
-
}
|
|
49154
|
-
});
|
|
49155
|
-
return null;
|
|
49156
|
-
}
|
|
49157
|
-
}
|
|
49158
|
-
/**
|
|
49159
|
-
* The pre-`produceEventMedia` path: `renderPreBufferClip`, once per container.
|
|
49160
|
-
*
|
|
49161
|
-
* Weaker than a production and deliberately so — the coherence here rests on
|
|
49162
|
-
* the two calls being given IDENTICAL parameters rather than on there being
|
|
49163
|
-
* one render. That is defensible because the ring only ever grows forward and
|
|
49164
|
-
* `windowAround` selects by wall clock around the same instant, so two calls
|
|
49165
|
-
* seconds apart choose the same packets; the one thing that could differ is
|
|
49166
|
-
* the rendition, so the profile is pinned to whatever the FIRST call actually
|
|
49167
|
-
* used and handed to the second.
|
|
49168
|
-
*
|
|
49169
|
-
* It exists for one reason: a hub whose `@camstack/server` predates the
|
|
49170
|
-
* production method must not stop attaching footage, and three of the four
|
|
49171
|
-
* live rules on this install ask for a gif and nothing else.
|
|
49172
|
-
*/
|
|
49173
|
-
async fallbackToRing(request) {
|
|
49174
|
-
const deviceId = request.deviceId;
|
|
49175
|
-
const speed = request.speed ?? DEFAULT_SPEED;
|
|
49176
|
-
const window = {
|
|
49177
|
-
deviceId,
|
|
49178
|
-
aroundMs: request.aroundMs,
|
|
49179
|
-
preRollSec: request.preRollSec,
|
|
49180
|
-
postRollSec: request.postRollSec,
|
|
49181
|
-
speed,
|
|
49182
|
-
...request.profile !== void 0 ? { profile: request.profile } : {}
|
|
49183
|
-
};
|
|
49184
|
-
try {
|
|
49185
|
-
const mp4 = request.wantMp4 ? await this.deps.renderRingClip({
|
|
49186
|
-
...window,
|
|
49187
|
-
format: "mp4",
|
|
49188
|
-
maxWidth: RING_MP4_MAX_WIDTH,
|
|
49189
|
-
fps: RING_MP4_FPS
|
|
49190
|
-
}) : null;
|
|
49191
|
-
const gif = request.wantGif ? await this.deps.renderRingClip({
|
|
49192
|
-
...window,
|
|
49193
|
-
format: "gif",
|
|
49194
|
-
maxWidth: 640,
|
|
49195
|
-
fps: 12 / 4,
|
|
49196
|
-
speed: 4
|
|
49197
|
-
}) : null;
|
|
49198
|
-
if ((mp4 === null || mp4.byteLength === 0) && (gif === null || gif.byteLength === 0)) {
|
|
49199
|
-
this.deps.logger.warn("nc media: the clip ring covered nothing — no footage attached", {
|
|
49200
|
-
tags: { deviceId },
|
|
49201
|
-
meta: { aroundMs: request.aroundMs }
|
|
49202
|
-
});
|
|
49203
|
-
return NO_MEDIA;
|
|
49204
|
-
}
|
|
49205
|
-
this.deps.logger.info("nc media: served by the clip-ring FALLBACK", {
|
|
49206
|
-
tags: { deviceId },
|
|
49207
|
-
meta: {
|
|
49208
|
-
mp4Bytes: mp4?.byteLength ?? null,
|
|
49209
|
-
gifBytes: gif?.byteLength ?? null,
|
|
49210
|
-
profile: request.profile ?? null,
|
|
49211
|
-
sharedWindow: "by-parameters"
|
|
49212
|
-
}
|
|
49213
|
-
});
|
|
49214
|
-
return {
|
|
49215
|
-
mp4: mp4 !== null && mp4.byteLength > 0 ? mp4 : null,
|
|
49216
|
-
gif: gif !== null && gif.byteLength > 0 ? gif : null,
|
|
49217
|
-
source: "ring-fallback",
|
|
49218
|
-
startOffsetMs: -Math.max(0, request.preRollSec) * 1e3,
|
|
49219
|
-
endOffsetMs: Math.max(0, request.postRollSec) * 1e3,
|
|
49220
|
-
profile: request.profile ?? null,
|
|
49221
|
-
video: null
|
|
49222
|
-
};
|
|
49223
|
-
} catch (err) {
|
|
49224
|
-
this.deps.logger.warn("nc media: the clip ring failed too — this event ships no footage", {
|
|
49225
|
-
tags: { deviceId },
|
|
49226
|
-
meta: { error: err instanceof Error ? err.message : String(err) }
|
|
49227
|
-
});
|
|
49228
|
-
return NO_MEDIA;
|
|
49229
|
-
}
|
|
49230
|
-
}
|
|
49231
|
-
};
|
|
49232
48847
|
//#endregion
|
|
49233
48848
|
//#region src/shared/frame/crop-extractor.ts
|
|
49234
48849
|
/**
|
|
@@ -57499,6 +57114,41 @@ function resolveMediaSettings(raw) {
|
|
|
57499
57114
|
snapshotMaxIdleMs: pick("snapshotMaxIdleMs")
|
|
57500
57115
|
};
|
|
57501
57116
|
}
|
|
57117
|
+
//#endregion
|
|
57118
|
+
//#region src/pipeline-analytics/our-recording-availability.ts
|
|
57119
|
+
/**
|
|
57120
|
+
* Coverage of OUR archive, asked of the `recording` collection by name.
|
|
57121
|
+
*
|
|
57122
|
+
* `recording` became a device collection on 2026-09-24 (D625): a camera may
|
|
57123
|
+
* have several sources of recorded coverage and every read names one. Every
|
|
57124
|
+
* read in this addon wants the same one — the footage OUR recorder wrote,
|
|
57125
|
+
* because everything downstream of it (a recorded clip cut, a timelapse, the
|
|
57126
|
+
* earliest-footage floor of a retention sweep) is about bytes we hold and can
|
|
57127
|
+
* export. A camera's own SD card is not an answer to any of those questions.
|
|
57128
|
+
*
|
|
57129
|
+
* It also owns the `read: 'unreadable'` rule, in one place: a read that FAILED
|
|
57130
|
+
* throws here rather than arriving downstream as an empty range list. Every
|
|
57131
|
+
* caller of this module treats "no ranges" as "recording is off for this
|
|
57132
|
+
* camera" and acts on it — dropping the attachment, skipping the render,
|
|
57133
|
+
* lowering the sweep floor — so folding a failed read into that shape would
|
|
57134
|
+
* make an unreachable recorder look exactly like a camera nobody records
|
|
57135
|
+
* (D393). The callers already handle a throw and log it as a read failure.
|
|
57136
|
+
*/
|
|
57137
|
+
/** Our coverage of `[fromMs, toMs)`, or a throw naming the failed read. */
|
|
57138
|
+
async function ourRecordingAvailability(api, input) {
|
|
57139
|
+
const answer = await api.recording.getAvailability.query({
|
|
57140
|
+
deviceId: input.deviceId,
|
|
57141
|
+
provider: RECORDING_SOURCE_CAMSTACK_ADDON,
|
|
57142
|
+
fromMs: input.fromMs,
|
|
57143
|
+
toMs: input.toMs,
|
|
57144
|
+
...input.profile !== void 0 ? { profile: input.profile } : {}
|
|
57145
|
+
});
|
|
57146
|
+
if (answer.read === "unreadable") throw new Error(`recording.getAvailability: the CamStack archive was unreadable for device ${String(input.deviceId)} — no claim is made about its footage`);
|
|
57147
|
+
return {
|
|
57148
|
+
ranges: answer.ranges,
|
|
57149
|
+
profilesWithFootage: answer.profilesWithFootage
|
|
57150
|
+
};
|
|
57151
|
+
}
|
|
57502
57152
|
function toDetectionBbox(bbox) {
|
|
57503
57153
|
return {
|
|
57504
57154
|
x: bbox.x,
|
|
@@ -58790,6 +58440,17 @@ function resolveSearchThumbnailUrl(input) {
|
|
|
58790
58440
|
return `${input.baseUrl}/${encodeURIComponent(id)}`;
|
|
58791
58441
|
}
|
|
58792
58442
|
//#endregion
|
|
58443
|
+
//#region src/pipeline-analytics/pipeline/onboard-birth-authority.ts
|
|
58444
|
+
/**
|
|
58445
|
+
* May a suppression verdict RETRACT this birth?
|
|
58446
|
+
*
|
|
58447
|
+
* `false` means hold: keep the track, log the held verdict, and let the
|
|
58448
|
+
* ordinary lifetime decide. It never means "confirmed".
|
|
58449
|
+
*/
|
|
58450
|
+
function suppressionMayRetract(source) {
|
|
58451
|
+
return source !== "onboard";
|
|
58452
|
+
}
|
|
58453
|
+
//#endregion
|
|
58793
58454
|
//#region src/pipeline-analytics/pipeline/package/package-area-gate.ts
|
|
58794
58455
|
/**
|
|
58795
58456
|
* Decide whether a package-class box is plausibly parcel-sized.
|
|
@@ -61483,65 +61144,6 @@ var StationaryEvidenceLedger = class {
|
|
|
61483
61144
|
for (const row of excess) this.forgetKey(row.key);
|
|
61484
61145
|
}
|
|
61485
61146
|
};
|
|
61486
|
-
//#endregion
|
|
61487
|
-
//#region src/pipeline-analytics/pipeline/stationary/stationary-track-disposal.ts
|
|
61488
|
-
function planStationaryTrackDisposal(input) {
|
|
61489
|
-
const trackIds = [input.liveTrackId];
|
|
61490
|
-
if (input.sourceTrackId !== void 0 && input.sourceTrackId !== input.liveTrackId) trackIds.push(input.sourceTrackId);
|
|
61491
|
-
const keepMediaIds = /* @__PURE__ */ new Set();
|
|
61492
|
-
if (input.entryKeyFrameMediaId !== void 0) keepMediaIds.add(input.entryKeyFrameMediaId);
|
|
61493
|
-
return {
|
|
61494
|
-
trackIds,
|
|
61495
|
-
keepMediaIds
|
|
61496
|
-
};
|
|
61497
|
-
}
|
|
61498
|
-
/**
|
|
61499
|
-
* Run the plan. The live track is dropped from RAM FIRST so it can never be
|
|
61500
|
-
* persisted by a sweep racing this call; the cascade then removes what every
|
|
61501
|
-
* track owned, sparing the entry's key frame, and deletes the row (a no-op for
|
|
61502
|
-
* the never-persisted live track).
|
|
61503
|
-
*
|
|
61504
|
-
* Never silent: the line names the entity, what went and what was kept — a
|
|
61505
|
-
* deleted track is dropped work, and the operator asked for it by name.
|
|
61506
|
-
*/
|
|
61507
|
-
async function disposeStationaryTracks(deps, plan) {
|
|
61508
|
-
const [liveTrackId] = plan.trackIds;
|
|
61509
|
-
if (liveTrackId !== void 0) deps.trackStore.dropActive(liveTrackId);
|
|
61510
|
-
const sparingMedia = { deleteByTracks: (trackIds) => deps.media.deleteByTracks(trackIds, { spare: plan.keepMediaIds }) };
|
|
61511
|
-
const result = await runTrackCascadeBatch({
|
|
61512
|
-
registry: [...deps.leaves, sparingMedia],
|
|
61513
|
-
trackStore: deps.trackStore,
|
|
61514
|
-
deviceId: deps.deviceId,
|
|
61515
|
-
onTrackCleanup: deps.onTrackCleanup,
|
|
61516
|
-
onFailure: (trackId, err) => {
|
|
61517
|
-
deps.logger.warn("stationary promotion: a source track could not be disposed of", {
|
|
61518
|
-
tags: { deviceId: deps.deviceId },
|
|
61519
|
-
meta: {
|
|
61520
|
-
deviceId: deps.deviceId,
|
|
61521
|
-
entryId: deps.entryId,
|
|
61522
|
-
trackId,
|
|
61523
|
-
error: String(err)
|
|
61524
|
-
}
|
|
61525
|
-
});
|
|
61526
|
-
}
|
|
61527
|
-
}, plan.trackIds);
|
|
61528
|
-
deps.logger.info("stationary promotion: source tracks discarded — the entity keeps its key frame", {
|
|
61529
|
-
tags: { deviceId: deps.deviceId },
|
|
61530
|
-
meta: {
|
|
61531
|
-
deviceId: deps.deviceId,
|
|
61532
|
-
entryId: deps.entryId,
|
|
61533
|
-
trackIds: plan.trackIds,
|
|
61534
|
-
keptMediaIds: [...plan.keepMediaIds],
|
|
61535
|
-
deleted: result.deleted,
|
|
61536
|
-
failed: result.failed,
|
|
61537
|
-
mediaRows: result.tally.media
|
|
61538
|
-
}
|
|
61539
|
-
});
|
|
61540
|
-
return {
|
|
61541
|
-
deleted: result.deleted,
|
|
61542
|
-
failed: result.failed
|
|
61543
|
-
};
|
|
61544
|
-
}
|
|
61545
61147
|
/**
|
|
61546
61148
|
* How long the same weak box must keep being seen before it may re-anchor.
|
|
61547
61149
|
*
|
|
@@ -62483,6 +62085,97 @@ function rowToEntry(id, data) {
|
|
|
62483
62085
|
};
|
|
62484
62086
|
}
|
|
62485
62087
|
//#endregion
|
|
62088
|
+
//#region src/pipeline-analytics/pipeline/stationary/stationary-track-disposal.ts
|
|
62089
|
+
function planStationaryTrackDisposal(input) {
|
|
62090
|
+
const trackIds = [input.liveTrackId];
|
|
62091
|
+
if (input.sourceTrackId !== void 0 && input.sourceTrackId !== input.liveTrackId) trackIds.push(input.sourceTrackId);
|
|
62092
|
+
const keepMediaIds = /* @__PURE__ */ new Set();
|
|
62093
|
+
if (input.entryKeyFrameMediaId !== void 0) keepMediaIds.add(input.entryKeyFrameMediaId);
|
|
62094
|
+
return {
|
|
62095
|
+
trackIds,
|
|
62096
|
+
keepMediaIds
|
|
62097
|
+
};
|
|
62098
|
+
}
|
|
62099
|
+
/**
|
|
62100
|
+
* Run the plan. The live track is dropped from RAM FIRST so it can never be
|
|
62101
|
+
* persisted by a sweep racing this call; the cascade then removes what every
|
|
62102
|
+
* track owned, sparing the entry's key frame, and deletes the row (a no-op for
|
|
62103
|
+
* the never-persisted live track).
|
|
62104
|
+
*
|
|
62105
|
+
* Never silent: the line names the entity, what went and what was kept — a
|
|
62106
|
+
* deleted track is dropped work, and the operator asked for it by name.
|
|
62107
|
+
*/
|
|
62108
|
+
async function disposeStationaryTracks(deps, plan) {
|
|
62109
|
+
const [liveTrackId] = plan.trackIds;
|
|
62110
|
+
if (liveTrackId !== void 0) deps.trackStore.dropActive(liveTrackId);
|
|
62111
|
+
const sparingMedia = { deleteByTracks: (trackIds) => deps.media.deleteByTracks(trackIds, { spare: plan.keepMediaIds }) };
|
|
62112
|
+
const result = await runTrackCascadeBatch({
|
|
62113
|
+
registry: [...deps.leaves, sparingMedia],
|
|
62114
|
+
trackStore: deps.trackStore,
|
|
62115
|
+
deviceId: deps.deviceId,
|
|
62116
|
+
onTrackCleanup: deps.onTrackCleanup,
|
|
62117
|
+
onFailure: (trackId, err) => {
|
|
62118
|
+
deps.logger.warn("stationary promotion: a source track could not be disposed of", {
|
|
62119
|
+
tags: { deviceId: deps.deviceId },
|
|
62120
|
+
meta: {
|
|
62121
|
+
deviceId: deps.deviceId,
|
|
62122
|
+
entryId: deps.entryId,
|
|
62123
|
+
trackId,
|
|
62124
|
+
error: String(err)
|
|
62125
|
+
}
|
|
62126
|
+
});
|
|
62127
|
+
}
|
|
62128
|
+
}, plan.trackIds);
|
|
62129
|
+
deps.logger.info("stationary promotion: source tracks discarded — the entity keeps its key frame", {
|
|
62130
|
+
tags: { deviceId: deps.deviceId },
|
|
62131
|
+
meta: {
|
|
62132
|
+
deviceId: deps.deviceId,
|
|
62133
|
+
entryId: deps.entryId,
|
|
62134
|
+
trackIds: plan.trackIds,
|
|
62135
|
+
keptMediaIds: [...plan.keepMediaIds],
|
|
62136
|
+
deleted: result.deleted,
|
|
62137
|
+
failed: result.failed,
|
|
62138
|
+
mediaRows: result.tally.media
|
|
62139
|
+
}
|
|
62140
|
+
});
|
|
62141
|
+
return {
|
|
62142
|
+
deleted: result.deleted,
|
|
62143
|
+
failed: result.failed
|
|
62144
|
+
};
|
|
62145
|
+
}
|
|
62146
|
+
//#endregion
|
|
62147
|
+
//#region src/pipeline-analytics/pipeline/stationary-planes.ts
|
|
62148
|
+
/**
|
|
62149
|
+
* WHICH detection planes carry the stationary machinery.
|
|
62150
|
+
*
|
|
62151
|
+
* A plane qualifies when it produces OBJECT BOXES on decoded frames — because
|
|
62152
|
+
* that is what the registry needs to decide an object is parked: a box, a
|
|
62153
|
+
* class, and an observed clock that only advances while frames flow.
|
|
62154
|
+
*
|
|
62155
|
+
* Both root detectors qualify. `pipeline` is the ML tree; `onboard` is the
|
|
62156
|
+
* camera's own firmware, and the boxes it produces are paired with a decoded
|
|
62157
|
+
* frame in that frame's pixel space — the same plane, entered by a different
|
|
62158
|
+
* door. `sensor` and `audio` do not: they carry no geometry to park.
|
|
62159
|
+
*
|
|
62160
|
+
* It used to be `source === 'pipeline'`, in five places, each explaining that
|
|
62161
|
+
* the gate "runs on that plane". The reason given was WHERE the flood it was
|
|
62162
|
+
* written for had been measured (617, the ML plane), never an argument that the
|
|
62163
|
+
* firmware's boxes were unfit. The cost of the accident, on device 640: a still
|
|
62164
|
+
* object is never promoted, so it holds `hasLiveTrack` true for as long as it
|
|
62165
|
+
* sits there, and every detection session runs to its 120 s cap instead of
|
|
62166
|
+
* closing on cooldown — `closed at the max-hold cap with a subject still
|
|
62167
|
+
* present`. The camera's lazy stream is then torn down and rebuilt on the next
|
|
62168
|
+
* detection, on a battery camera.
|
|
62169
|
+
*
|
|
62170
|
+
* One predicate and not five comparisons, because five copies of a rule drift:
|
|
62171
|
+
* this repo has already paid for that with two authorities on one function
|
|
62172
|
+
* (D62).
|
|
62173
|
+
*/
|
|
62174
|
+
/** Does this detection plane run the stationary registry, gate and promotion? */
|
|
62175
|
+
function planeRunsStationary(source) {
|
|
62176
|
+
return source === "pipeline" || source === "onboard";
|
|
62177
|
+
}
|
|
62178
|
+
//#endregion
|
|
62486
62179
|
//#region src/pipeline-analytics/pipeline/suppressed-births.ts
|
|
62487
62180
|
/**
|
|
62488
62181
|
* Memory of births the confirmation gate rejected, per device.
|
|
@@ -63398,49 +63091,6 @@ function hasKeyFrame(source) {
|
|
|
63398
63091
|
return source.keyFrame !== null && source.bbox !== null;
|
|
63399
63092
|
}
|
|
63400
63093
|
//#endregion
|
|
63401
|
-
//#region src/pipeline-analytics/pipeline/stationary-planes.ts
|
|
63402
|
-
/**
|
|
63403
|
-
* WHICH detection planes carry the stationary machinery.
|
|
63404
|
-
*
|
|
63405
|
-
* A plane qualifies when it produces OBJECT BOXES on decoded frames — because
|
|
63406
|
-
* that is what the registry needs to decide an object is parked: a box, a
|
|
63407
|
-
* class, and an observed clock that only advances while frames flow.
|
|
63408
|
-
*
|
|
63409
|
-
* Both root detectors qualify. `pipeline` is the ML tree; `onboard` is the
|
|
63410
|
-
* camera's own firmware, and the boxes it produces are paired with a decoded
|
|
63411
|
-
* frame in that frame's pixel space — the same plane, entered by a different
|
|
63412
|
-
* door. `sensor` and `audio` do not: they carry no geometry to park.
|
|
63413
|
-
*
|
|
63414
|
-
* It used to be `source === 'pipeline'`, in five places, each explaining that
|
|
63415
|
-
* the gate "runs on that plane". The reason given was WHERE the flood it was
|
|
63416
|
-
* written for had been measured (617, the ML plane), never an argument that the
|
|
63417
|
-
* firmware's boxes were unfit. The cost of the accident, on device 640: a still
|
|
63418
|
-
* object is never promoted, so it holds `hasLiveTrack` true for as long as it
|
|
63419
|
-
* sits there, and every detection session runs to its 120 s cap instead of
|
|
63420
|
-
* closing on cooldown — `closed at the max-hold cap with a subject still
|
|
63421
|
-
* present`. The camera's lazy stream is then torn down and rebuilt on the next
|
|
63422
|
-
* detection, on a battery camera.
|
|
63423
|
-
*
|
|
63424
|
-
* One predicate and not five comparisons, because five copies of a rule drift:
|
|
63425
|
-
* this repo has already paid for that with two authorities on one function
|
|
63426
|
-
* (D62).
|
|
63427
|
-
*/
|
|
63428
|
-
/** Does this detection plane run the stationary registry, gate and promotion? */
|
|
63429
|
-
function planeRunsStationary(source) {
|
|
63430
|
-
return source === "pipeline" || source === "onboard";
|
|
63431
|
-
}
|
|
63432
|
-
//#endregion
|
|
63433
|
-
//#region src/pipeline-analytics/pipeline/onboard-birth-authority.ts
|
|
63434
|
-
/**
|
|
63435
|
-
* May a suppression verdict RETRACT this birth?
|
|
63436
|
-
*
|
|
63437
|
-
* `false` means hold: keep the track, log the held verdict, and let the
|
|
63438
|
-
* ordinary lifetime decide. It never means "confirmed".
|
|
63439
|
-
*/
|
|
63440
|
-
function suppressionMayRetract(source) {
|
|
63441
|
-
return source !== "onboard";
|
|
63442
|
-
}
|
|
63443
|
-
//#endregion
|
|
63444
63094
|
//#region src/pipeline-analytics/rebuild-source-loader.ts
|
|
63445
63095
|
/**
|
|
63446
63096
|
* Assemble one track's rebuild inputs, reading at most ONE blob.
|
|
@@ -78572,7 +78222,7 @@ var PipelineAnalyticsAddon = class PipelineAnalyticsAddon extends BaseAddon {
|
|
|
78572
78222
|
await step("buildSceneMonitor", () => this.buildSceneMonitor(api, logger));
|
|
78573
78223
|
this.startSweepTimers();
|
|
78574
78224
|
this.ctx.logger.info("pipeline-analytics subscribers installed");
|
|
78575
|
-
const providers = await step("buildProviderRegistrations", () => this.buildProviderRegistrations(
|
|
78225
|
+
const providers = await step("buildProviderRegistrations", () => this.buildProviderRegistrations(stores, capProviders));
|
|
78576
78226
|
const isHub = ownNodeId === "hub";
|
|
78577
78227
|
const ncHandlers = isHub ? this.buildNcActionHandlers(api) : void 0;
|
|
78578
78228
|
this.discardJob = createDiscardJob({
|
|
@@ -78651,7 +78301,7 @@ var PipelineAnalyticsAddon = class PipelineAnalyticsAddon extends BaseAddon {
|
|
|
78651
78301
|
injectTestEvent: (input) => center.injectTestEvent(input, { getSnapshot: (deviceId) => api.snapshot.getSnapshot.query({ deviceId }) }),
|
|
78652
78302
|
timelapse: {
|
|
78653
78303
|
store: center.timelapseStore,
|
|
78654
|
-
getRecordingConfig: (deviceId) => api.
|
|
78304
|
+
getRecordingConfig: (deviceId) => api.recordingArchive.getDeviceConfig.query({ deviceId }).catch(() => null),
|
|
78655
78305
|
runNow: (input) => center.runTimelapseNow(input)
|
|
78656
78306
|
},
|
|
78657
78307
|
summary: {
|
|
@@ -79744,7 +79394,7 @@ var PipelineAnalyticsAddon = class PipelineAnalyticsAddon extends BaseAddon {
|
|
|
79744
79394
|
logger: logger.child("RecordedClip"),
|
|
79745
79395
|
now: () => Date.now(),
|
|
79746
79396
|
sleep: (ms) => new Promise((resolve) => setTimeout(resolve, ms)),
|
|
79747
|
-
getAvailability: (input) => api
|
|
79397
|
+
getAvailability: (input) => ourRecordingAvailability(api, input),
|
|
79748
79398
|
createExport: (input) => api.recordingExport.createExport.mutate({ ...input }),
|
|
79749
79399
|
getExport: (input) => api.recordingExport.getExport.query(input),
|
|
79750
79400
|
readExportBytes: (input) => api.recordingExport.readExportBytes.query(input),
|
|
@@ -79998,7 +79648,7 @@ var PipelineAnalyticsAddon = class PipelineAnalyticsAddon extends BaseAddon {
|
|
|
79998
79648
|
buildTimelapsePorts(api, stores) {
|
|
79999
79649
|
return {
|
|
80000
79650
|
getAvailability: async ({ deviceId, fromMs, toMs, profile }) => {
|
|
80001
|
-
const availability = await api
|
|
79651
|
+
const availability = await ourRecordingAvailability(api, {
|
|
80002
79652
|
deviceId,
|
|
80003
79653
|
fromMs,
|
|
80004
79654
|
toMs,
|
|
@@ -80976,71 +80626,8 @@ var PipelineAnalyticsAddon = class PipelineAnalyticsAddon extends BaseAddon {
|
|
|
80976
80626
|
});
|
|
80977
80627
|
}
|
|
80978
80628
|
}
|
|
80979
|
-
buildProviderRegistrations(
|
|
80629
|
+
buildProviderRegistrations(stores, providers) {
|
|
80980
80630
|
const widgetsProvider = createAnalyticsWidgetsProvider();
|
|
80981
|
-
const videoclipsProvider = createVideoclipsProvider({
|
|
80982
|
-
defaultPad: EVENT_PAD_MS,
|
|
80983
|
-
fetchEvents: async ({ deviceId, since, until, limit }) => {
|
|
80984
|
-
const [motion, object, audio] = await Promise.all([
|
|
80985
|
-
this.getMotionEvents({
|
|
80986
|
-
deviceId,
|
|
80987
|
-
since,
|
|
80988
|
-
until,
|
|
80989
|
-
limit,
|
|
80990
|
-
projection: "slim"
|
|
80991
|
-
}),
|
|
80992
|
-
this.getObjectEvents({
|
|
80993
|
-
deviceId,
|
|
80994
|
-
since,
|
|
80995
|
-
until,
|
|
80996
|
-
limit,
|
|
80997
|
-
projection: "slim"
|
|
80998
|
-
}),
|
|
80999
|
-
this.getAudioEvents({
|
|
81000
|
-
deviceId,
|
|
81001
|
-
since,
|
|
81002
|
-
until,
|
|
81003
|
-
limit,
|
|
81004
|
-
projection: "slim"
|
|
81005
|
-
})
|
|
81006
|
-
]);
|
|
81007
|
-
return {
|
|
81008
|
-
motion: toEventLike(motion),
|
|
81009
|
-
object: toEventLike(object),
|
|
81010
|
-
audio: toEventLike(audio)
|
|
81011
|
-
};
|
|
81012
|
-
},
|
|
81013
|
-
fetchMediaOwners: async ({ deviceId, ownerKind, ownerIds }) => {
|
|
81014
|
-
return stores.mediaStore.ownersWithMedia(ownerKind, ownerIds, deviceId);
|
|
81015
|
-
},
|
|
81016
|
-
fetchAvailability: async ({ deviceId, since, until }) => {
|
|
81017
|
-
return (await api.recording.getAvailability.query({
|
|
81018
|
-
deviceId,
|
|
81019
|
-
fromMs: since,
|
|
81020
|
-
toMs: until
|
|
81021
|
-
})).ranges;
|
|
81022
|
-
},
|
|
81023
|
-
logWarn: (message, meta) => this.ctx.logger.warn(message, {
|
|
81024
|
-
tags: { deviceId: Number(meta["deviceId"]) },
|
|
81025
|
-
meta
|
|
81026
|
-
}),
|
|
81027
|
-
logInfo: (message, meta) => this.ctx.logger.info(message, {
|
|
81028
|
-
tags: { deviceId: Number(meta["deviceId"]) },
|
|
81029
|
-
meta
|
|
81030
|
-
}),
|
|
81031
|
-
resolvePlayback: async ({ deviceId, startMs, endMs }) => {
|
|
81032
|
-
const manifest = await api.recording.getPlaybackManifest.query({
|
|
81033
|
-
deviceId,
|
|
81034
|
-
fromMs: startMs,
|
|
81035
|
-
toMs: endMs
|
|
81036
|
-
});
|
|
81037
|
-
if (manifest.playbackUrl == null) throw new Error(`videoclips: no footage for clip window [${startMs},${endMs}] on device ${deviceId}`);
|
|
81038
|
-
return {
|
|
81039
|
-
playbackUrl: manifest.playbackUrl,
|
|
81040
|
-
playbackEndpoints: manifest.playbackEndpoints
|
|
81041
|
-
};
|
|
81042
|
-
}
|
|
81043
|
-
});
|
|
81044
80631
|
const faceGallery = new FaceGalleryProvider({
|
|
81045
80632
|
identityStore: stores.identityStore,
|
|
81046
80633
|
faceStore: stores.faceStore,
|
|
@@ -81103,10 +80690,6 @@ var PipelineAnalyticsAddon = class PipelineAnalyticsAddon extends BaseAddon {
|
|
|
81103
80690
|
capability: addonWidgetsSourceCapability,
|
|
81104
80691
|
provider: widgetsProvider
|
|
81105
80692
|
},
|
|
81106
|
-
{
|
|
81107
|
-
capability: videoclipsCapability,
|
|
81108
|
-
provider: videoclipsProvider
|
|
81109
|
-
},
|
|
81110
80693
|
{
|
|
81111
80694
|
capability: faceGalleryCapability,
|
|
81112
80695
|
provider: faceGallery
|
|
@@ -84256,7 +83839,7 @@ var PipelineAnalyticsAddon = class PipelineAnalyticsAddon extends BaseAddon {
|
|
|
84256
83839
|
if (cached && Date.now() - cached.at < 10 * 6e4) return cached.value;
|
|
84257
83840
|
let value = null;
|
|
84258
83841
|
try {
|
|
84259
|
-
const res = await this.ctx.api
|
|
83842
|
+
const res = await ourRecordingAvailability(this.ctx.api, {
|
|
84260
83843
|
deviceId,
|
|
84261
83844
|
fromMs: 0,
|
|
84262
83845
|
toMs: Date.now()
|
|
@@ -85759,6 +85342,24 @@ var PipelineAnalyticsAddon = class PipelineAnalyticsAddon extends BaseAddon {
|
|
|
85759
85342
|
return this.queryFacade.listEventMedia(input);
|
|
85760
85343
|
}
|
|
85761
85344
|
/**
|
|
85345
|
+
* Which of `ownerIds` hold at least ONE media row — the media-PRESENCE probe,
|
|
85346
|
+
* on the wire because the `videoclips` source lives in the addon that owns
|
|
85347
|
+
* the FOOTAGE now (D560).
|
|
85348
|
+
*
|
|
85349
|
+
* A pass-through to {@link MediaStore.ownersWithMedia}, which batches by
|
|
85350
|
+
* `whereIn` and pages: the N+1 this exists to prevent is one query per owner,
|
|
85351
|
+
* and a process boundary in front of it would multiply that, not absorb it.
|
|
85352
|
+
*
|
|
85353
|
+
* It THROWS rather than answering partially, and the empty ask costs no read
|
|
85354
|
+
* at all — a caller with nothing to probe must not pay a round trip for it.
|
|
85355
|
+
*/
|
|
85356
|
+
async ownersWithMedia(input) {
|
|
85357
|
+
if (input.ownerIds.length === 0) return [];
|
|
85358
|
+
const store = this.mediaStore;
|
|
85359
|
+
if (store === null) throw new Error(`pipelineAnalytics.ownersWithMedia: the media index is not open on this node — refusing rather than answering "these owners have nothing" (device ${String(input.deviceId)})`);
|
|
85360
|
+
return [...await store.ownersWithMedia(input.ownerKind, input.ownerIds, input.deviceId)];
|
|
85361
|
+
}
|
|
85362
|
+
/**
|
|
85762
85363
|
* Search object events by text using CLIP cosine similarity.
|
|
85763
85364
|
*
|
|
85764
85365
|
* Flow:
|
|
@@ -86284,7 +85885,7 @@ var PipelineAnalyticsAddon = class PipelineAnalyticsAddon extends BaseAddon {
|
|
|
86284
85885
|
} });
|
|
86285
85886
|
const deviceIds = input.deviceId !== void 0 ? [input.deviceId] : await trackStore.listDeviceIds();
|
|
86286
85887
|
const recordedStills = new RecordedStillService(buildRecordedStillPorts({
|
|
86287
|
-
api: this.ctx.api.
|
|
85888
|
+
api: this.ctx.api.recordingArchive,
|
|
86288
85889
|
logger: this.ctx.logger
|
|
86289
85890
|
}));
|
|
86290
85891
|
const deps = {
|