@camstack/addon-post-analysis 1.1.40 → 1.1.42
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-DUcGHr9E.js → dist-BveR79HO.js} +127 -32
- package/dist/{dist-CO07v2sR.mjs → dist-Cgv25jQz.mjs} +127 -32
- package/dist/embedding-encoder/index.js +1 -1
- package/dist/embedding-encoder/index.mjs +1 -1
- package/dist/{node-B7HfyyIy.js → node-C-QTkE6o.js} +1 -1
- package/dist/pipeline-analytics/_stub.js +1 -1
- package/dist/pipeline-analytics/{_virtual_mf-localSharedImportMap___mfe_internal__addon_pipeline_analytics_widgets-Nr0GGHJb.mjs → _virtual_mf-localSharedImportMap___mfe_internal__addon_pipeline_analytics_widgets-DgeV9o4P.mjs} +2 -2
- package/dist/pipeline-analytics/_virtual_mf___mfe_internal__addon_pipeline_analytics_widgets__loadShare___mf_0_camstack_mf_1_ui_mf_2_library__loadShare__.js-CUKChUeW.mjs +26 -0
- package/dist/pipeline-analytics/{hostInit-4J_PYcat.mjs → hostInit-CnO6PKAO.mjs} +2 -2
- package/dist/pipeline-analytics/index.js +452 -59
- package/dist/pipeline-analytics/index.mjs +451 -58
- package/dist/pipeline-analytics/remoteEntry.js +1 -1
- package/package.json +1 -1
- package/dist/pipeline-analytics/_virtual_mf___mfe_internal__addon_pipeline_analytics_widgets__loadShare___mf_0_camstack_mf_1_ui_mf_2_library__loadShare__.js-B4AjHkeF.mjs +0 -26
|
@@ -2,7 +2,7 @@ Object.defineProperties(exports, {
|
|
|
2
2
|
__esModule: { value: true },
|
|
3
3
|
[Symbol.toStringTag]: { value: "Module" }
|
|
4
4
|
});
|
|
5
|
-
const require_dist = require("../dist-
|
|
5
|
+
const require_dist = require("../dist-BveR79HO.js");
|
|
6
6
|
let node_crypto = require("node:crypto");
|
|
7
7
|
let sharp = require("sharp");
|
|
8
8
|
sharp = require_dist.__toESM(sharp);
|
|
@@ -8108,6 +8108,169 @@ function resolveTrackingSettings(raw) {
|
|
|
8108
8108
|
};
|
|
8109
8109
|
}
|
|
8110
8110
|
//#endregion
|
|
8111
|
+
//#region src/pipeline-analytics/confirmation-gate-settings.ts
|
|
8112
|
+
/**
|
|
8113
|
+
* Per-device DETECTION CONFIRMATION GATE tuning.
|
|
8114
|
+
*
|
|
8115
|
+
* Before a NEW track is born (its `start` lifecycle + firstFrame media emitted)
|
|
8116
|
+
* the gate optionally re-runs object detection on the HI-RES NATIVE CROP of the
|
|
8117
|
+
* detection box. If the crop does not confirm a compatible object above
|
|
8118
|
+
* `minConfidence`, the birth is SUPPRESSED — it was a false positive from the
|
|
8119
|
+
* low-res detection frame (a static "person" phantom, a parked-truck ghost, a
|
|
8120
|
+
* misclassified static object).
|
|
8121
|
+
*
|
|
8122
|
+
* Ships DORMANT: `enabled` defaults to `false`, so behaviour is byte-identical
|
|
8123
|
+
* to today until an operator opts in per camera. The gate is fail-OPEN — any
|
|
8124
|
+
* missing frame handle, unavailable inference cap, crop-fetch miss, re-detection
|
|
8125
|
+
* error, or timeout ALLOWS the birth (a real track is never suppressed because
|
|
8126
|
+
* confirmation was unavailable).
|
|
8127
|
+
*
|
|
8128
|
+
* Every field is independently overridable per camera; an unknown/invalid value
|
|
8129
|
+
* falls back to the field default (never throws on a bad blob) — mirrors
|
|
8130
|
+
* {@link resolveTrackingSettings}.
|
|
8131
|
+
*/
|
|
8132
|
+
/**
|
|
8133
|
+
* Per-device store keys the confirmation gate reads. FLAT (not nested under a
|
|
8134
|
+
* `confirmationGate` blob) so the fields flow through the same hydrate /
|
|
8135
|
+
* `applyDeviceSettingsPatch` path as every other per-device tunable
|
|
8136
|
+
* (trackTtlMs, minScorePerson, …) and surface directly in the operator's
|
|
8137
|
+
* Detection-pipeline → Settings form.
|
|
8138
|
+
*/
|
|
8139
|
+
var CONFIRMATION_GATE_KEYS = {
|
|
8140
|
+
enabled: "confirmationGateEnabled",
|
|
8141
|
+
minConfidence: "confirmationGateMinConfidence",
|
|
8142
|
+
minCropPx: "confirmationGateMinCropPx",
|
|
8143
|
+
timeoutMs: "confirmationGateTimeoutMs"
|
|
8144
|
+
};
|
|
8145
|
+
var ConfirmationGateSettingsSchema = require_dist.object({
|
|
8146
|
+
/** Master switch. DEFAULT ON (2026-07-20 rollout) — the gate is FAIL-OPEN (any
|
|
8147
|
+
* crop-fetch / re-detection error or timeout confirms the birth), so enabling
|
|
8148
|
+
* it can only SUPPRESS false-positive births, never drop a real track on
|
|
8149
|
+
* error. Per-device store `confirmationGateEnabled=false` opts a camera out. */
|
|
8150
|
+
enabled: require_dist.boolean().default(true),
|
|
8151
|
+
/**
|
|
8152
|
+
* Minimum re-detection score (0..1) required in the crop for a birth to be
|
|
8153
|
+
* confirmed. A detection must clear this AND be class-compatible with the
|
|
8154
|
+
* track's class.
|
|
8155
|
+
*/
|
|
8156
|
+
minConfidence: require_dist.number().min(0).max(1).default(.4),
|
|
8157
|
+
/**
|
|
8158
|
+
* Minimum crop size (px, longest side in detection-frame pixel space) worth
|
|
8159
|
+
* re-detecting. A subject box smaller than this is too tiny to confirm
|
|
8160
|
+
* reliably, so the gate SKIPS it and fails open (confirms the birth). 0 =
|
|
8161
|
+
* confirm every birth regardless of size.
|
|
8162
|
+
*/
|
|
8163
|
+
minCropPx: require_dist.number().int().min(0).default(48),
|
|
8164
|
+
/**
|
|
8165
|
+
* Per-birth confirmation budget (ms). If the crop fetch + re-detection does
|
|
8166
|
+
* not resolve within this window the gate fails open (confirms the birth) so
|
|
8167
|
+
* the synchronous frame path never stalls on inference.
|
|
8168
|
+
*/
|
|
8169
|
+
timeoutMs: require_dist.number().int().min(1).default(300)
|
|
8170
|
+
});
|
|
8171
|
+
var CONFIRMATION_GATE_DEFAULTS = ConfirmationGateSettingsSchema.parse({});
|
|
8172
|
+
/**
|
|
8173
|
+
* Resolve a per-device store blob into typed confirmation-gate settings. The
|
|
8174
|
+
* gate's fields live as FLAT keys ({@link CONFIRMATION_GATE_KEYS}) in the
|
|
8175
|
+
* per-device store — the same shape the Detection-pipeline → Settings form
|
|
8176
|
+
* writes. Each field is validated independently via `.catch(default)` so an
|
|
8177
|
+
* invalid/missing field falls back to its default and parse never throws.
|
|
8178
|
+
* (A legacy nested `confirmationGate` blob, if any, is simply ignored.)
|
|
8179
|
+
*/
|
|
8180
|
+
function resolveConfirmationGateSettings(raw) {
|
|
8181
|
+
const s = ConfirmationGateSettingsSchema.shape;
|
|
8182
|
+
return {
|
|
8183
|
+
enabled: s.enabled.catch(CONFIRMATION_GATE_DEFAULTS.enabled).parse(raw[CONFIRMATION_GATE_KEYS.enabled]),
|
|
8184
|
+
minConfidence: s.minConfidence.catch(CONFIRMATION_GATE_DEFAULTS.minConfidence).parse(raw[CONFIRMATION_GATE_KEYS.minConfidence]),
|
|
8185
|
+
minCropPx: s.minCropPx.catch(CONFIRMATION_GATE_DEFAULTS.minCropPx).parse(raw[CONFIRMATION_GATE_KEYS.minCropPx]),
|
|
8186
|
+
timeoutMs: s.timeoutMs.catch(CONFIRMATION_GATE_DEFAULTS.timeoutMs).parse(raw[CONFIRMATION_GATE_KEYS.timeoutMs])
|
|
8187
|
+
};
|
|
8188
|
+
}
|
|
8189
|
+
//#endregion
|
|
8190
|
+
//#region src/pipeline-analytics/confirmation-gate.ts
|
|
8191
|
+
/**
|
|
8192
|
+
* Map a fine/raw detector or classifier class name to its coarse group. The
|
|
8193
|
+
* runtime detector already emits coarse `macroClass` values (person/vehicle/
|
|
8194
|
+
* animal), but a track's `className` may carry a finer class from a downstream
|
|
8195
|
+
* classifier — this normalizes both sides to the same three groups. Anything
|
|
8196
|
+
* unrecognized maps to `other`, which the compatibility check treats as
|
|
8197
|
+
* fail-open (compatible with everything) rather than a hard mismatch.
|
|
8198
|
+
*/
|
|
8199
|
+
function coarseGroupForClass(className) {
|
|
8200
|
+
const c = className.trim().toLowerCase();
|
|
8201
|
+
if (c === "person" || c === "people" || c === "pedestrian" || c === "human") return "person";
|
|
8202
|
+
if (c === "vehicle" || c === "car" || c === "truck" || c === "bus" || c === "van" || c === "motorcycle" || c === "motorbike" || c === "bicycle" || c === "bike") return "vehicle";
|
|
8203
|
+
if (c === "animal" || c === "dog" || c === "cat" || c === "bird" || c === "horse" || c === "sheep" || c === "cow" || c === "bear" || c === "deer" || c === "fox") return "animal";
|
|
8204
|
+
return "other";
|
|
8205
|
+
}
|
|
8206
|
+
/**
|
|
8207
|
+
* A re-detection in the crop is COMPATIBLE with the track's class when both map
|
|
8208
|
+
* to the same coarse group. When either side is unknown (`other`) we fail open
|
|
8209
|
+
* — treat it as compatible — so an unusual class never wrongly suppresses a
|
|
8210
|
+
* real track.
|
|
8211
|
+
*/
|
|
8212
|
+
function isConfirmationCompatible(trackClassName, detectionMacroClass) {
|
|
8213
|
+
const track = coarseGroupForClass(trackClassName);
|
|
8214
|
+
const det = coarseGroupForClass(detectionMacroClass);
|
|
8215
|
+
if (track === "other" || det === "other") return true;
|
|
8216
|
+
return track === det;
|
|
8217
|
+
}
|
|
8218
|
+
var failOpen = (trackId, reason) => ({
|
|
8219
|
+
trackId,
|
|
8220
|
+
confirmed: true,
|
|
8221
|
+
reason
|
|
8222
|
+
});
|
|
8223
|
+
function withTimeout(promise, timeoutMs) {
|
|
8224
|
+
return new Promise((resolve, reject) => {
|
|
8225
|
+
const timer = setTimeout(() => reject(/* @__PURE__ */ new Error("confirmation-timeout")), timeoutMs);
|
|
8226
|
+
promise.then((value) => {
|
|
8227
|
+
clearTimeout(timer);
|
|
8228
|
+
resolve(value);
|
|
8229
|
+
}, (err) => {
|
|
8230
|
+
clearTimeout(timer);
|
|
8231
|
+
reject(err instanceof Error ? err : new Error(String(err)));
|
|
8232
|
+
});
|
|
8233
|
+
});
|
|
8234
|
+
}
|
|
8235
|
+
async function runConfirmation(candidate, config, deps) {
|
|
8236
|
+
const crop = await deps.fetchCrop(candidate);
|
|
8237
|
+
if (!crop) return failOpen(candidate.trackId, "no-crop");
|
|
8238
|
+
const detections = await deps.redetect(crop);
|
|
8239
|
+
if (detections === null) return failOpen(candidate.trackId, "redetect-error");
|
|
8240
|
+
const confirmed = detections.some((d) => d.score >= config.minConfidence && isConfirmationCompatible(candidate.className, d.macroClass));
|
|
8241
|
+
return {
|
|
8242
|
+
trackId: candidate.trackId,
|
|
8243
|
+
confirmed,
|
|
8244
|
+
reason: confirmed ? "confirmed" : "suppressed"
|
|
8245
|
+
};
|
|
8246
|
+
}
|
|
8247
|
+
async function confirmOne(candidate, config, deps) {
|
|
8248
|
+
const cropPx = Math.max(candidate.bbox.w, candidate.bbox.h);
|
|
8249
|
+
if (config.minCropPx > 0 && cropPx < config.minCropPx) return failOpen(candidate.trackId, "below-min-crop");
|
|
8250
|
+
try {
|
|
8251
|
+
return await withTimeout(runConfirmation(candidate, config, deps), config.timeoutMs);
|
|
8252
|
+
} catch {
|
|
8253
|
+
return failOpen(candidate.trackId, "timeout");
|
|
8254
|
+
}
|
|
8255
|
+
}
|
|
8256
|
+
/**
|
|
8257
|
+
* Confirm a batch of birth candidates CONCURRENTLY and return the set of
|
|
8258
|
+
* trackIds whose births may PROCEED. When the gate is disabled (or there are no
|
|
8259
|
+
* candidates) every candidate is confirmed — byte-identical to no gate. The
|
|
8260
|
+
* caller runs this once, then processes only the confirmed births, preserving
|
|
8261
|
+
* the original birth-loop ordering.
|
|
8262
|
+
*/
|
|
8263
|
+
async function confirmBirths(candidates, config, deps) {
|
|
8264
|
+
if (!config.enabled || candidates.length === 0) return new Set(candidates.map((c) => c.trackId));
|
|
8265
|
+
const decisions = await Promise.all(candidates.map((c) => confirmOne(c, config, deps)));
|
|
8266
|
+
const confirmed = /* @__PURE__ */ new Set();
|
|
8267
|
+
for (const decision of decisions) {
|
|
8268
|
+
deps.onDecision?.(decision);
|
|
8269
|
+
if (decision.confirmed) confirmed.add(decision.trackId);
|
|
8270
|
+
}
|
|
8271
|
+
return confirmed;
|
|
8272
|
+
}
|
|
8273
|
+
//#endregion
|
|
8111
8274
|
//#region src/pipeline-analytics/face-settings.ts
|
|
8112
8275
|
/**
|
|
8113
8276
|
* Per-device face-recognition settings. Cascade: a per-device override on top
|
|
@@ -11768,6 +11931,15 @@ var DETAIL_FALLBACK_CROP_PADDING = .15;
|
|
|
11768
11931
|
* before re-reading. */
|
|
11769
11932
|
var CLIP_MODEL_ID_CACHE_TTL_MS = 6e4;
|
|
11770
11933
|
var SETTINGS_CACHE_TTL_MS = 5e3;
|
|
11934
|
+
/** TTL for the per-node confirmation-gate detector-step cache (the node's
|
|
11935
|
+
* default object-detector step rarely changes). */
|
|
11936
|
+
var CONFIRMATION_DETECTOR_CACHE_TTL_MS = 6e4;
|
|
11937
|
+
/** Padding applied to a birth box before re-detecting it — a little context
|
|
11938
|
+
* around the subject improves the confirmation detector's recall. */
|
|
11939
|
+
var CONFIRMATION_CROP_PADDING = .15;
|
|
11940
|
+
/** Cap the confirmation crop width so a 4K native surface never floods the
|
|
11941
|
+
* transport just to confirm one small box. */
|
|
11942
|
+
var CONFIRMATION_CROP_MAX_WIDTH = 320;
|
|
11771
11943
|
/** Reconcile cadence for the per-device `zones` / `zoneRules` slice handles.
|
|
11772
11944
|
* The `device.state-changed` push doesn't reliably reach a forked child, so
|
|
11773
11945
|
* each cached proxy re-pulls both slices on this timer (see ensureProxy) —
|
|
@@ -11867,6 +12039,7 @@ function toAnalyticsDeviceSections(sections) {
|
|
|
11867
12039
|
* belong in the consolidated `Detection pipeline → Settings` sub-tab alongside
|
|
11868
12040
|
* Object Detection — NOT under the generic `Analytics` top-tab:
|
|
11869
12041
|
* - `detection-sensitivity` — minHits / cooldown / stationary threshold.
|
|
12042
|
+
* - `confirmation-gate` — hi-res native-crop re-detection before a birth.
|
|
11870
12043
|
* - `tracking` — the tracker-tuning form incl. the FP knobs (dedup, person↔
|
|
11871
12044
|
* animal dedup, class voting, confirm-bypass, per-class min score).
|
|
11872
12045
|
* - `stationary-objects` — stationary promotion + occupancy tuning.
|
|
@@ -11876,6 +12049,7 @@ function toAnalyticsDeviceSections(sections) {
|
|
|
11876
12049
|
*/
|
|
11877
12050
|
var DETECTION_PIPELINE_SECTION_IDS = new Set([
|
|
11878
12051
|
"detection-sensitivity",
|
|
12052
|
+
"confirmation-gate",
|
|
11879
12053
|
"tracking",
|
|
11880
12054
|
"stationary-objects"
|
|
11881
12055
|
]);
|
|
@@ -11999,6 +12173,12 @@ var PipelineAnalyticsAddon = class extends require_dist.BaseAddon {
|
|
|
11999
12173
|
settingsCacheByDevice = /* @__PURE__ */ new Map();
|
|
12000
12174
|
sensitivityCacheByDevice = /* @__PURE__ */ new Map();
|
|
12001
12175
|
trackingCacheByDevice = /* @__PURE__ */ new Map();
|
|
12176
|
+
/** Per-device confirmation-gate settings cache (default off), TTL-mirrored. */
|
|
12177
|
+
confirmationGateCacheByDevice = /* @__PURE__ */ new Map();
|
|
12178
|
+
/** Per-node detector-step cache for the confirmation gate's re-detection —
|
|
12179
|
+
* the node's default root object-detector reduced to a single childless
|
|
12180
|
+
* step, resolved lazily from `pipelineExecutor.getGlobalSteps` and reused. */
|
|
12181
|
+
confirmationDetectorStepByNode = /* @__PURE__ */ new Map();
|
|
12002
12182
|
faceCacheByDevice = /* @__PURE__ */ new Map();
|
|
12003
12183
|
/** GLOBAL face-recognition master switch (addon store), TTL-cached. */
|
|
12004
12184
|
faceGlobalEnabledCache = null;
|
|
@@ -12118,7 +12298,7 @@ var PipelineAnalyticsAddon = class extends require_dist.BaseAddon {
|
|
|
12118
12298
|
let storage = this.ctx.kernel.storage;
|
|
12119
12299
|
const mediaRoot = process.env.CAMSTACK_MEDIA_ROOT?.trim();
|
|
12120
12300
|
if (mediaRoot) {
|
|
12121
|
-
const { FilesystemStorageProvider } = await Promise.resolve().then(() => require("../node-
|
|
12301
|
+
const { FilesystemStorageProvider } = await Promise.resolve().then(() => require("../node-C-QTkE6o.js"));
|
|
12122
12302
|
storage = new FilesystemStorageProvider(mediaRoot);
|
|
12123
12303
|
logger.info("pipeline-analytics: event media rooted at CAMSTACK_MEDIA_ROOT", { meta: { mediaRoot } });
|
|
12124
12304
|
}
|
|
@@ -12530,6 +12710,7 @@ var PipelineAnalyticsAddon = class extends require_dist.BaseAddon {
|
|
|
12530
12710
|
this.settingsCacheByDevice.delete(data.deviceId);
|
|
12531
12711
|
this.sensitivityCacheByDevice.delete(data.deviceId);
|
|
12532
12712
|
this.trackingCacheByDevice.delete(data.deviceId);
|
|
12713
|
+
this.confirmationGateCacheByDevice.delete(data.deviceId);
|
|
12533
12714
|
this.faceCacheByDevice.delete(data.deviceId);
|
|
12534
12715
|
this.mediaCacheByDevice.delete(data.deviceId);
|
|
12535
12716
|
this.packageDropCacheByDevice.delete(data.deviceId);
|
|
@@ -12547,6 +12728,7 @@ var PipelineAnalyticsAddon = class extends require_dist.BaseAddon {
|
|
|
12547
12728
|
this.settingsCacheByDevice.delete(deviceId);
|
|
12548
12729
|
this.sensitivityCacheByDevice.delete(deviceId);
|
|
12549
12730
|
this.trackingCacheByDevice.delete(deviceId);
|
|
12731
|
+
this.confirmationGateCacheByDevice.delete(deviceId);
|
|
12550
12732
|
this.faceCacheByDevice.delete(deviceId);
|
|
12551
12733
|
this.mediaCacheByDevice.delete(deviceId);
|
|
12552
12734
|
this.packageDropCacheByDevice.delete(deviceId);
|
|
@@ -12898,6 +13080,8 @@ var PipelineAnalyticsAddon = class extends require_dist.BaseAddon {
|
|
|
12898
13080
|
this.settingsCacheByDevice.clear();
|
|
12899
13081
|
this.sensitivityCacheByDevice.clear();
|
|
12900
13082
|
this.trackingCacheByDevice.clear();
|
|
13083
|
+
this.confirmationGateCacheByDevice.clear();
|
|
13084
|
+
this.confirmationDetectorStepByNode.clear();
|
|
12901
13085
|
this.faceCacheByDevice.clear();
|
|
12902
13086
|
this.faceGlobalEnabledCache = null;
|
|
12903
13087
|
this.mediaCacheByDevice.clear();
|
|
@@ -13013,70 +13197,88 @@ var PipelineAnalyticsAddon = class extends require_dist.BaseAddon {
|
|
|
13013
13197
|
const prevIds = this.lastActiveTrackIds.get(key) ?? /* @__PURE__ */ new Set();
|
|
13014
13198
|
const firstFrameTargets = [];
|
|
13015
13199
|
let newTrackCount = 0;
|
|
13016
|
-
|
|
13200
|
+
const bornCandidates = [];
|
|
13201
|
+
for (const id of currentTrackIds) {
|
|
13202
|
+
if (prevIds.has(id)) continue;
|
|
13017
13203
|
const t = result.tracked.find((x) => x.trackId === id);
|
|
13018
|
-
if (t)
|
|
13019
|
-
|
|
13020
|
-
|
|
13021
|
-
|
|
13022
|
-
|
|
13023
|
-
|
|
13024
|
-
trackId: id,
|
|
13025
|
-
className: t.className,
|
|
13026
|
-
source,
|
|
13027
|
-
resurrected: true
|
|
13028
|
-
} });
|
|
13029
|
-
continue;
|
|
13030
|
-
}
|
|
13031
|
-
newTrackCount += 1;
|
|
13032
|
-
log.info("track started", { meta: {
|
|
13204
|
+
if (!t) continue;
|
|
13205
|
+
if (classifyTrackAppearance({
|
|
13206
|
+
inPrevActive: false,
|
|
13207
|
+
positionsCount: positionsCountById.get(id) ?? 1
|
|
13208
|
+
}) === "resurrection") {
|
|
13209
|
+
log.info("track resumed", { meta: {
|
|
13033
13210
|
trackId: id,
|
|
13034
13211
|
className: t.className,
|
|
13035
|
-
source
|
|
13212
|
+
source,
|
|
13213
|
+
resurrected: true
|
|
13036
13214
|
} });
|
|
13037
|
-
|
|
13038
|
-
|
|
13039
|
-
|
|
13040
|
-
|
|
13041
|
-
|
|
13042
|
-
|
|
13043
|
-
|
|
13044
|
-
|
|
13045
|
-
|
|
13046
|
-
|
|
13047
|
-
|
|
13048
|
-
|
|
13049
|
-
|
|
13050
|
-
|
|
13051
|
-
|
|
13052
|
-
|
|
13053
|
-
|
|
13054
|
-
|
|
13055
|
-
|
|
13056
|
-
|
|
13057
|
-
|
|
13058
|
-
|
|
13059
|
-
|
|
13060
|
-
|
|
13061
|
-
|
|
13062
|
-
|
|
13215
|
+
continue;
|
|
13216
|
+
}
|
|
13217
|
+
bornCandidates.push({
|
|
13218
|
+
id,
|
|
13219
|
+
t
|
|
13220
|
+
});
|
|
13221
|
+
}
|
|
13222
|
+
const confirmedBirths = await this.confirmTrackBirths(bornCandidates.map(({ id, t }) => ({
|
|
13223
|
+
trackId: id,
|
|
13224
|
+
className: t.className,
|
|
13225
|
+
bbox: t.bbox
|
|
13226
|
+
})), {
|
|
13227
|
+
deviceId,
|
|
13228
|
+
frameHandle,
|
|
13229
|
+
frameWidth: result.frameWidth,
|
|
13230
|
+
frameHeight: result.frameHeight
|
|
13231
|
+
});
|
|
13232
|
+
for (const { id, t } of bornCandidates) {
|
|
13233
|
+
if (!confirmedBirths.has(id)) continue;
|
|
13234
|
+
newTrackCount += 1;
|
|
13235
|
+
log.info("track started", { meta: {
|
|
13236
|
+
trackId: id,
|
|
13237
|
+
className: t.className,
|
|
13238
|
+
source
|
|
13239
|
+
} });
|
|
13240
|
+
if (this.eventMediaDispatcher && frameHandle) {
|
|
13241
|
+
firstFrameTargets.push({
|
|
13063
13242
|
trackId: id,
|
|
13064
|
-
|
|
13065
|
-
|
|
13066
|
-
|
|
13067
|
-
bestConfidence: t.confidence,
|
|
13068
|
-
firstSeen: result.timestamp,
|
|
13069
|
-
lastSeen: result.timestamp,
|
|
13070
|
-
...t.label !== void 0 ? { label: t.label } : {}
|
|
13071
|
-
});
|
|
13072
|
-
this.emitTrackLifecycle(startPayload, result.timestamp);
|
|
13073
|
-
this.trackLifecycleUpdateMem.set(id, {
|
|
13074
|
-
lastConfidence: t.confidence,
|
|
13075
|
-
lastEmitAt: result.timestamp,
|
|
13076
|
-
...t.label !== void 0 ? { lastLabel: t.label } : {},
|
|
13077
|
-
lastBboxArea: t.bbox.w * t.bbox.h
|
|
13243
|
+
timestamp: result.timestamp,
|
|
13244
|
+
bbox: { ...t.bbox },
|
|
13245
|
+
...t.label ? { label: t.label } : {}
|
|
13078
13246
|
});
|
|
13247
|
+
this.trackStore.seedSnapshotClock(id, result.timestamp, t.bbox);
|
|
13079
13248
|
}
|
|
13249
|
+
this.ctx.eventBus.emit({
|
|
13250
|
+
id: `pa-${(0, node_crypto.randomUUID)()}`,
|
|
13251
|
+
timestamp: new Date(result.timestamp),
|
|
13252
|
+
source: {
|
|
13253
|
+
type: "addon",
|
|
13254
|
+
id: "pipeline-analytics",
|
|
13255
|
+
addonId: "pipeline-analytics"
|
|
13256
|
+
},
|
|
13257
|
+
category: require_dist.EventCategory.PipelineAnalyticsTrackStarted,
|
|
13258
|
+
data: {
|
|
13259
|
+
deviceId,
|
|
13260
|
+
trackId: id,
|
|
13261
|
+
className: t.className
|
|
13262
|
+
}
|
|
13263
|
+
});
|
|
13264
|
+
const startPayload = buildTrackLifecyclePayload({
|
|
13265
|
+
deviceId,
|
|
13266
|
+
trackId: id,
|
|
13267
|
+
phase: "start",
|
|
13268
|
+
classes: [t.className],
|
|
13269
|
+
bestClassName: t.className,
|
|
13270
|
+
bestConfidence: t.confidence,
|
|
13271
|
+
firstSeen: result.timestamp,
|
|
13272
|
+
lastSeen: result.timestamp,
|
|
13273
|
+
...t.label !== void 0 ? { label: t.label } : {}
|
|
13274
|
+
});
|
|
13275
|
+
this.emitTrackLifecycle(startPayload, result.timestamp);
|
|
13276
|
+
this.trackLifecycleUpdateMem.set(id, {
|
|
13277
|
+
lastConfidence: t.confidence,
|
|
13278
|
+
lastEmitAt: result.timestamp,
|
|
13279
|
+
...t.label !== void 0 ? { lastLabel: t.label } : {},
|
|
13280
|
+
lastBboxArea: t.bbox.w * t.bbox.h
|
|
13281
|
+
});
|
|
13080
13282
|
}
|
|
13081
13283
|
let lostTrackCount = 0;
|
|
13082
13284
|
for (const id of prevIds) if (!currentTrackIds.has(id)) {
|
|
@@ -13357,6 +13559,146 @@ var PipelineAnalyticsAddon = class extends require_dist.BaseAddon {
|
|
|
13357
13559
|
});
|
|
13358
13560
|
return settings;
|
|
13359
13561
|
}
|
|
13562
|
+
/** Per-device confirmation-gate settings (default OFF), TTL-cached like the
|
|
13563
|
+
* other per-device tunables. */
|
|
13564
|
+
async resolveDeviceConfirmationGateSettings(deviceId) {
|
|
13565
|
+
const now = Date.now();
|
|
13566
|
+
const cached = this.confirmationGateCacheByDevice.get(deviceId);
|
|
13567
|
+
if (cached && now < cached.expiresAt) return cached.settings;
|
|
13568
|
+
const settings = resolveConfirmationGateSettings(await this.ctx?.settings?.readDeviceStore(deviceId) ?? {});
|
|
13569
|
+
this.confirmationGateCacheByDevice.set(deviceId, {
|
|
13570
|
+
settings,
|
|
13571
|
+
expiresAt: now + SETTINGS_CACHE_TTL_MS
|
|
13572
|
+
});
|
|
13573
|
+
return settings;
|
|
13574
|
+
}
|
|
13575
|
+
/**
|
|
13576
|
+
* Narrowed, version-skew-safe handle onto the `pipelineExecutor` cap — same
|
|
13577
|
+
* structural-cast pattern as the `pipelineRunner` handle above. A node whose
|
|
13578
|
+
* executor predates these methods simply yields `undefined`, and the
|
|
13579
|
+
* confirmation gate then fails open (allows the birth).
|
|
13580
|
+
*/
|
|
13581
|
+
pipelineExecutorApi() {
|
|
13582
|
+
const api = this.ctx?.api;
|
|
13583
|
+
if (!api) return void 0;
|
|
13584
|
+
return api.pipelineExecutor;
|
|
13585
|
+
}
|
|
13586
|
+
/**
|
|
13587
|
+
* Resolve (and cache) the confirmation gate's re-detection step for a node:
|
|
13588
|
+
* the node's DEFAULT root object-detector (from `getGlobalSteps`) reduced to a
|
|
13589
|
+
* single CHILDLESS step, so the confirmation run does detection ONLY — no
|
|
13590
|
+
* crop/classifier subtree. Cached per node (TTL) since the node default rarely
|
|
13591
|
+
* changes. `null` ⇒ no detector available ⇒ the gate fails open.
|
|
13592
|
+
*/
|
|
13593
|
+
async resolveConfirmationDetectorStep(nodeId) {
|
|
13594
|
+
const now = Date.now();
|
|
13595
|
+
const cached = this.confirmationDetectorStepByNode.get(nodeId);
|
|
13596
|
+
if (cached && now < cached.expiresAt) return cached.step;
|
|
13597
|
+
let step = null;
|
|
13598
|
+
const executor = this.pipelineExecutorApi();
|
|
13599
|
+
if (executor?.getGlobalSteps) try {
|
|
13600
|
+
const steps = await executor.getGlobalSteps.query(void 0, require_dist.nodePin(nodeId));
|
|
13601
|
+
const detector = steps?.find((s) => s.slot === "detector" && s.enabled) ?? steps?.find((s) => s.slot === "detector");
|
|
13602
|
+
if (detector) step = {
|
|
13603
|
+
addonId: detector.addonId,
|
|
13604
|
+
...detector.modelId ? { modelId: detector.modelId } : {},
|
|
13605
|
+
enabled: true
|
|
13606
|
+
};
|
|
13607
|
+
} catch (err) {
|
|
13608
|
+
this.ctx.logger.debug("confirmation gate: getGlobalSteps failed", { meta: {
|
|
13609
|
+
nodeId,
|
|
13610
|
+
error: require_dist.errMsg(err)
|
|
13611
|
+
} });
|
|
13612
|
+
}
|
|
13613
|
+
this.confirmationDetectorStepByNode.set(nodeId, {
|
|
13614
|
+
step,
|
|
13615
|
+
expiresAt: now + CONFIRMATION_DETECTOR_CACHE_TTL_MS
|
|
13616
|
+
});
|
|
13617
|
+
return step;
|
|
13618
|
+
}
|
|
13619
|
+
/**
|
|
13620
|
+
* Re-run object detection on a confirmation crop JPEG via the frame-owning
|
|
13621
|
+
* node's `pipelineExecutor` (pinned by `nodeId`, matching the native-crop
|
|
13622
|
+
* fetch). Returns the crop's detections, or `null` on any unavailability /
|
|
13623
|
+
* error so the gate fails open.
|
|
13624
|
+
*/
|
|
13625
|
+
async redetectCropForConfirmation(nodeId, deviceId, cropJpeg) {
|
|
13626
|
+
const step = await this.resolveConfirmationDetectorStep(nodeId);
|
|
13627
|
+
if (!step) return null;
|
|
13628
|
+
const executor = this.pipelineExecutorApi();
|
|
13629
|
+
if (!executor?.runPipeline) return null;
|
|
13630
|
+
try {
|
|
13631
|
+
const detections = (await executor.runPipeline.mutate({
|
|
13632
|
+
steps: [step],
|
|
13633
|
+
image: new Uint8Array(cropJpeg),
|
|
13634
|
+
deviceId,
|
|
13635
|
+
plane: "frame"
|
|
13636
|
+
}, require_dist.nodePin(nodeId)))?.detections;
|
|
13637
|
+
if (!detections) return null;
|
|
13638
|
+
return detections.map((d) => ({
|
|
13639
|
+
macroClass: d.macroClass,
|
|
13640
|
+
score: d.score
|
|
13641
|
+
}));
|
|
13642
|
+
} catch (err) {
|
|
13643
|
+
this.ctx.logger.debug("confirmation gate: re-detection failed — fail-open", {
|
|
13644
|
+
tags: { deviceId },
|
|
13645
|
+
meta: { error: require_dist.errMsg(err) }
|
|
13646
|
+
});
|
|
13647
|
+
return null;
|
|
13648
|
+
}
|
|
13649
|
+
}
|
|
13650
|
+
/**
|
|
13651
|
+
* Confirm a batch of track-birth candidates before they are created. Returns
|
|
13652
|
+
* the set of trackIds whose births may PROCEED. When the gate is disabled
|
|
13653
|
+
* (default) or no crop path is available, every candidate is confirmed —
|
|
13654
|
+
* byte-identical to no gate. Confirmations run CONCURRENTLY (one inference per
|
|
13655
|
+
* candidate) and each failure path fails OPEN, so the synchronous frame path
|
|
13656
|
+
* is never blocked or reordered by a slow/failed re-detection.
|
|
13657
|
+
*/
|
|
13658
|
+
async confirmTrackBirths(candidates, params) {
|
|
13659
|
+
const allConfirmed = () => new Set(candidates.map((c) => c.trackId));
|
|
13660
|
+
if (candidates.length === 0) return allConfirmed();
|
|
13661
|
+
const config = await this.resolveDeviceConfirmationGateSettings(params.deviceId);
|
|
13662
|
+
if (!config.enabled) return allConfirmed();
|
|
13663
|
+
const { frameHandle, frameWidth, frameHeight, deviceId } = params;
|
|
13664
|
+
const captureCrop = this.captureCrop;
|
|
13665
|
+
if (!frameHandle || !captureCrop || frameWidth <= 0 || frameHeight <= 0) {
|
|
13666
|
+
this.ctx.logger.debug("confirmation gate: no crop path — births allowed (fail-open)", {
|
|
13667
|
+
tags: { deviceId },
|
|
13668
|
+
meta: {
|
|
13669
|
+
candidates: candidates.length,
|
|
13670
|
+
hasHandle: Boolean(frameHandle)
|
|
13671
|
+
}
|
|
13672
|
+
});
|
|
13673
|
+
return allConfirmed();
|
|
13674
|
+
}
|
|
13675
|
+
const nodeId = frameHandle.nodeId;
|
|
13676
|
+
return confirmBirths(candidates, config, {
|
|
13677
|
+
fetchCrop: (candidate) => captureCrop(frameHandle, {
|
|
13678
|
+
x: candidate.bbox.x,
|
|
13679
|
+
y: candidate.bbox.y,
|
|
13680
|
+
w: candidate.bbox.w,
|
|
13681
|
+
h: candidate.bbox.h
|
|
13682
|
+
}, frameWidth, frameHeight, CONFIRMATION_CROP_PADDING, CONFIRMATION_CROP_MAX_WIDTH),
|
|
13683
|
+
redetect: (cropJpeg) => this.redetectCropForConfirmation(nodeId, deviceId, cropJpeg),
|
|
13684
|
+
onDecision: (decision) => {
|
|
13685
|
+
if (!decision.confirmed) this.ctx.logger.info("confirmation gate: birth suppressed (false positive)", {
|
|
13686
|
+
tags: { deviceId },
|
|
13687
|
+
meta: {
|
|
13688
|
+
trackId: decision.trackId,
|
|
13689
|
+
reason: decision.reason
|
|
13690
|
+
}
|
|
13691
|
+
});
|
|
13692
|
+
else if (decision.reason !== "confirmed") this.ctx.logger.debug("confirmation gate: birth allowed (fail-open)", {
|
|
13693
|
+
tags: { deviceId },
|
|
13694
|
+
meta: {
|
|
13695
|
+
trackId: decision.trackId,
|
|
13696
|
+
reason: decision.reason
|
|
13697
|
+
}
|
|
13698
|
+
});
|
|
13699
|
+
}
|
|
13700
|
+
});
|
|
13701
|
+
}
|
|
13360
13702
|
async resolveGlobalFaceEnabled() {
|
|
13361
13703
|
const now = Date.now();
|
|
13362
13704
|
if (this.faceGlobalEnabledCache && now < this.faceGlobalEnabledCache.expiresAt) return this.faceGlobalEnabledCache.value;
|
|
@@ -15630,6 +15972,56 @@ var PipelineAnalyticsAddon = class extends require_dist.BaseAddon {
|
|
|
15630
15972
|
}
|
|
15631
15973
|
]
|
|
15632
15974
|
},
|
|
15975
|
+
{
|
|
15976
|
+
id: "confirmation-gate",
|
|
15977
|
+
title: "Confirmation gate",
|
|
15978
|
+
description: "Before a NEW track is born, optionally re-run object detection on the hi-res native crop of the detection box. If the crop does not confirm a compatible object above the threshold, the birth is suppressed as a false positive. Fail-OPEN: any crop-fetch miss, unavailable inference, error, or timeout confirms the birth (a real track is never dropped because confirmation was unavailable).",
|
|
15979
|
+
columns: 2,
|
|
15980
|
+
fields: [
|
|
15981
|
+
{
|
|
15982
|
+
type: "boolean",
|
|
15983
|
+
key: CONFIRMATION_GATE_KEYS.enabled,
|
|
15984
|
+
label: "Confirm new tracks",
|
|
15985
|
+
description: "Re-detect the native crop before a birth. Off = every track is born from the low-res detection frame directly.",
|
|
15986
|
+
default: CONFIRMATION_GATE_DEFAULTS.enabled
|
|
15987
|
+
},
|
|
15988
|
+
{
|
|
15989
|
+
type: "slider",
|
|
15990
|
+
key: CONFIRMATION_GATE_KEYS.minConfidence,
|
|
15991
|
+
label: "Min confirmation score",
|
|
15992
|
+
description: "Minimum re-detection score (0..1) required in the crop, class-compatible with the track, for a birth to be confirmed.",
|
|
15993
|
+
min: 0,
|
|
15994
|
+
max: 1,
|
|
15995
|
+
step: .05,
|
|
15996
|
+
default: CONFIRMATION_GATE_DEFAULTS.minConfidence,
|
|
15997
|
+
showValue: true
|
|
15998
|
+
},
|
|
15999
|
+
{
|
|
16000
|
+
type: "slider",
|
|
16001
|
+
key: CONFIRMATION_GATE_KEYS.minCropPx,
|
|
16002
|
+
label: "Min crop size",
|
|
16003
|
+
description: "Subject boxes smaller than this (longest side, detection-frame px) are too tiny to confirm reliably — the gate skips them and confirms the birth. 0 = confirm every birth regardless of size.",
|
|
16004
|
+
min: 0,
|
|
16005
|
+
max: 256,
|
|
16006
|
+
step: 8,
|
|
16007
|
+
default: CONFIRMATION_GATE_DEFAULTS.minCropPx,
|
|
16008
|
+
showValue: true,
|
|
16009
|
+
unit: "px"
|
|
16010
|
+
},
|
|
16011
|
+
{
|
|
16012
|
+
type: "slider",
|
|
16013
|
+
key: CONFIRMATION_GATE_KEYS.timeoutMs,
|
|
16014
|
+
label: "Confirmation timeout",
|
|
16015
|
+
description: "Per-birth budget for crop fetch + re-detection. If it does not resolve in time the gate fails open (confirms the birth) so the frame path never stalls on inference.",
|
|
16016
|
+
min: 50,
|
|
16017
|
+
max: 2e3,
|
|
16018
|
+
step: 50,
|
|
16019
|
+
default: CONFIRMATION_GATE_DEFAULTS.timeoutMs,
|
|
16020
|
+
showValue: true,
|
|
16021
|
+
unit: "ms"
|
|
16022
|
+
}
|
|
16023
|
+
]
|
|
16024
|
+
},
|
|
15633
16025
|
{
|
|
15634
16026
|
id: "tracking",
|
|
15635
16027
|
title: "Tracking",
|
|
@@ -16069,6 +16461,7 @@ var PipelineAnalyticsAddon = class extends require_dist.BaseAddon {
|
|
|
16069
16461
|
this.settingsCacheByDevice.delete(input.deviceId);
|
|
16070
16462
|
this.sensitivityCacheByDevice.delete(input.deviceId);
|
|
16071
16463
|
this.trackingCacheByDevice.delete(input.deviceId);
|
|
16464
|
+
this.confirmationGateCacheByDevice.delete(input.deviceId);
|
|
16072
16465
|
this.forgetDeviceProcessors(input.deviceId);
|
|
16073
16466
|
return { success: true };
|
|
16074
16467
|
}
|