@trillboards/edge-sdk 0.2.245 → 0.2.246
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/deploy/detector/bench/detect_frames.py +88 -0
- package/deploy/detector/bench/openvino_parity.py +152 -0
- package/deploy/detector/pyproject.toml +10 -1
- package/deploy/detector/tests/test_actor_tracking.py +32 -0
- package/deploy/detector/tests/test_actor_tracking_wire.py +11 -0
- package/deploy/detector/tests/test_openvino_engines.py +251 -0
- package/deploy/detector/tests/test_server.py +43 -0
- package/deploy/detector/tests/test_version_stamp.py +17 -4
- package/deploy/detector/trillboards_detector/_version.py +2 -2
- package/deploy/detector/trillboards_detector/actor_tracking.py +51 -0
- package/deploy/detector/trillboards_detector/cli.py +5 -0
- package/deploy/detector/trillboards_detector/detections.py +5 -0
- package/deploy/detector/trillboards_detector/execution.py +386 -0
- package/deploy/detector/trillboards_detector/loader.py +12 -1
- package/deploy/detector/trillboards_detector/registry.py +6 -0
- package/deploy/detector/trillboards_detector/server.py +41 -0
- package/deploy/detector/trillboards_detector/session.py +81 -3
- package/deploy/detector/trillboards_detector/track_records.py +113 -0
- package/deploy/windows/ci/test-detector-reinstall.ps1 +474 -0
- package/deploy/windows/setup-detector.ps1 +122 -29
- package/dist/ActorTracking.d.ts +38 -0
- package/dist/ActorTracking.d.ts.map +1 -1
- package/dist/ActorTracking.js +40 -0
- package/dist/ActorTracking.js.map +1 -1
- package/dist/AlertClips.d.ts +4 -2
- package/dist/AlertClips.d.ts.map +1 -1
- package/dist/AlertClips.js +24 -9
- package/dist/AlertClips.js.map +1 -1
- package/dist/CloudSensingManager.d.ts.map +1 -1
- package/dist/CloudSensingManager.js +6 -1
- package/dist/CloudSensingManager.js.map +1 -1
- package/dist/DurableVlmCandidateSpool.d.ts +11 -0
- package/dist/DurableVlmCandidateSpool.d.ts.map +1 -1
- package/dist/DurableVlmCandidateSpool.js +31 -2
- package/dist/DurableVlmCandidateSpool.js.map +1 -1
- package/dist/EdgeAgent.js +1 -1
- package/dist/FrameGroupingShadow.d.ts +57 -0
- package/dist/FrameGroupingShadow.d.ts.map +1 -1
- package/dist/FrameGroupingShadow.js +123 -5
- package/dist/FrameGroupingShadow.js.map +1 -1
- package/dist/LocalDetectorClient.d.ts +25 -1
- package/dist/LocalDetectorClient.d.ts.map +1 -1
- package/dist/LocalDetectorClient.js +60 -0
- package/dist/LocalDetectorClient.js.map +1 -1
- package/dist/LocalVideoBuffer.d.ts +14 -2
- package/dist/LocalVideoBuffer.d.ts.map +1 -1
- package/dist/LocalVideoBuffer.js +23 -3
- package/dist/LocalVideoBuffer.js.map +1 -1
- package/dist/SensingProfileClient.d.ts.map +1 -1
- package/dist/SensingProfileClient.js +3 -0
- package/dist/SensingProfileClient.js.map +1 -1
- package/dist/VideoSegmentUploader.d.ts +14 -7
- package/dist/VideoSegmentUploader.d.ts.map +1 -1
- package/dist/VideoSegmentUploader.js +34 -38
- package/dist/VideoSegmentUploader.js.map +1 -1
- package/dist/VlmCandidateBuffer.d.ts +13 -0
- package/dist/VlmCandidateBuffer.d.ts.map +1 -1
- package/dist/VlmCandidateBuffer.js.map +1 -1
- package/dist/autoSense.d.ts +4 -0
- package/dist/autoSense.d.ts.map +1 -1
- package/dist/autoSense.js +4 -0
- package/dist/autoSense.js.map +1 -1
- package/dist/continuousReview.d.ts +6 -2
- package/dist/continuousReview.d.ts.map +1 -1
- package/dist/continuousReview.js.map +1 -1
- package/dist/detectorBackendRelay.d.ts +24 -0
- package/dist/detectorBackendRelay.d.ts.map +1 -0
- package/dist/detectorBackendRelay.js +70 -0
- package/dist/detectorBackendRelay.js.map +1 -0
- package/dist/diagnose.d.ts +1 -1
- package/dist/diagnose.js +1 -1
- package/dist/localSensing.d.ts +3 -0
- package/dist/localSensing.d.ts.map +1 -1
- package/dist/localSensing.js +69 -3
- package/dist/localSensing.js.map +1 -1
- package/dist/pipelineSwitches.d.ts +59 -0
- package/dist/pipelineSwitches.d.ts.map +1 -0
- package/dist/pipelineSwitches.js +240 -0
- package/dist/pipelineSwitches.js.map +1 -0
- package/package.json +4 -4
- package/retained/RetainedCaptureClient.cjs +37 -2
- package/retained/WebsiteAdmissionCaptureClient.cjs +57 -2
- package/retained/__tests__/look-reuse.test.cjs +167 -0
- package/retained/manager.cjs +28 -2
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.DEFAULT_PIPELINE_SWITCHES = exports.DETECTOR_BACKENDS = exports.LOOK_REUSE_MODES = exports.CAPTURE_PIPELINES = void 0;
|
|
37
|
+
exports.parsePipelineSwitches = parsePipelineSwitches;
|
|
38
|
+
exports.restorePipelineSwitches = restorePipelineSwitches;
|
|
39
|
+
exports.notePipelineSwitches = notePipelineSwitches;
|
|
40
|
+
exports.currentPipelineSwitches = currentPipelineSwitches;
|
|
41
|
+
exports.onPipelineSwitches = onPipelineSwitches;
|
|
42
|
+
exports.bindCapturePipeline = bindCapturePipeline;
|
|
43
|
+
exports.noteDetectorBackend = noteDetectorBackend;
|
|
44
|
+
exports.noteServerClock = noteServerClock;
|
|
45
|
+
exports.pipelineTrace = pipelineTrace;
|
|
46
|
+
exports.__resetPipelineSwitchesForTests = __resetPipelineSwitchesForTests;
|
|
47
|
+
/**
|
|
48
|
+
* The store-PC pipeline switches (plan v7 W8), and the diagnostics each look
|
|
49
|
+
* carries about them.
|
|
50
|
+
*
|
|
51
|
+
* The server sends `pipeline: { version: 1, capture, lookReuse, detectorBackend }`
|
|
52
|
+
* on every sensing-profile response (runtime_config CCTV_CAPTURE_PIPELINE,
|
|
53
|
+
* CCTV_LOOK_REUSE, CCTV_DETECTOR_BACKEND; cameraPairingController.pipelineSwitches).
|
|
54
|
+
* `SensingProfileClient.fetchProfile` hands every parsed body to
|
|
55
|
+
* `notePipelineSwitches`, exactly as it hands `connectorRelease` to the update
|
|
56
|
+
* loop, so a switch reaches the box within one profile poll with no release.
|
|
57
|
+
*
|
|
58
|
+
* BOX-LEVEL, NEVER PART OF A REVIEW CONTEXT. The switches change how the box
|
|
59
|
+
* captures, schedules and detects, never which question a camera asks, so they
|
|
60
|
+
* stay out of every archived review context: flipping one cannot restart an
|
|
61
|
+
* alert's episode or wait clock.
|
|
62
|
+
*
|
|
63
|
+
* DEFAULTS ARE TODAY'S BEHAVIOUR: legacy capture, no look reuse, ONNX Runtime.
|
|
64
|
+
* A restart starts from the last switches this box saw (persisted beside the
|
|
65
|
+
* scene memory), so a box that was told `select_first` does not run one legacy
|
|
66
|
+
* session per camera before its first poll.
|
|
67
|
+
*/
|
|
68
|
+
const fs = __importStar(require("fs"));
|
|
69
|
+
const path = __importStar(require("path"));
|
|
70
|
+
exports.CAPTURE_PIPELINES = Object.freeze(['legacy', 'select_first', 'select_first_hw', 'keyframes', 'keyframes_hw']);
|
|
71
|
+
exports.LOOK_REUSE_MODES = Object.freeze(['off', 'shadow', 'live']);
|
|
72
|
+
exports.DETECTOR_BACKENDS = Object.freeze(['ort', 'openvino_probe', 'openvino', 'openvino_gpu']);
|
|
73
|
+
exports.DEFAULT_PIPELINE_SWITCHES = Object.freeze({
|
|
74
|
+
version: 1, capture: 'legacy', lookReuse: 'off', detectorBackend: 'ort',
|
|
75
|
+
});
|
|
76
|
+
/** Strictly read a `pipeline` body; null when any part is unusable (the box keeps what it has). */
|
|
77
|
+
function parsePipelineSwitches(raw) {
|
|
78
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw))
|
|
79
|
+
return null;
|
|
80
|
+
const o = raw;
|
|
81
|
+
if (o.version !== 1
|
|
82
|
+
|| !exports.CAPTURE_PIPELINES.includes(o.capture)
|
|
83
|
+
|| !exports.LOOK_REUSE_MODES.includes(o.lookReuse)
|
|
84
|
+
|| !exports.DETECTOR_BACKENDS.includes(o.detectorBackend))
|
|
85
|
+
return null;
|
|
86
|
+
return { version: 1, capture: o.capture, lookReuse: o.lookReuse,
|
|
87
|
+
detectorBackend: o.detectorBackend };
|
|
88
|
+
}
|
|
89
|
+
let current = { ...exports.DEFAULT_PIPELINE_SWITCHES };
|
|
90
|
+
/** Where the box last saw switches, so a restart starts from them; null = not persisted. */
|
|
91
|
+
let stateFile = null;
|
|
92
|
+
let fromServer = false;
|
|
93
|
+
const listeners = new Set();
|
|
94
|
+
function same(a, b) {
|
|
95
|
+
return a.capture === b.capture && a.lookReuse === b.lookReuse && a.detectorBackend === b.detectorBackend;
|
|
96
|
+
}
|
|
97
|
+
function announce() {
|
|
98
|
+
for (const listener of [...listeners]) {
|
|
99
|
+
try {
|
|
100
|
+
listener(current);
|
|
101
|
+
}
|
|
102
|
+
catch { /* a listener never breaks a profile poll */ }
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Persist the switches under `dataDir` and start from the last ones saved there.
|
|
107
|
+
* Called once by the run mode, before any feed is built. A missing, unreadable
|
|
108
|
+
* or malformed file is today's defaults, and never an error.
|
|
109
|
+
*/
|
|
110
|
+
function restorePipelineSwitches(dataDir) {
|
|
111
|
+
stateFile = path.join(dataDir, 'pipeline-switches.json');
|
|
112
|
+
try {
|
|
113
|
+
const saved = parsePipelineSwitches(JSON.parse(fs.readFileSync(stateFile, 'utf8')));
|
|
114
|
+
if (saved && !fromServer && !same(saved, current)) {
|
|
115
|
+
current = saved;
|
|
116
|
+
announce();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
catch { /* nothing saved yet */ }
|
|
120
|
+
return current;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Hand a sensing-profile response's `pipeline` to the box. Called by
|
|
124
|
+
* `SensingProfileClient.fetchProfile` on every parsed body. Never throws: a
|
|
125
|
+
* profile fetch must not be able to fail because of a switch.
|
|
126
|
+
*/
|
|
127
|
+
function notePipelineSwitches(raw) {
|
|
128
|
+
if (raw === undefined || raw === null)
|
|
129
|
+
return;
|
|
130
|
+
const next = parsePipelineSwitches(raw);
|
|
131
|
+
if (!next)
|
|
132
|
+
return;
|
|
133
|
+
fromServer = true;
|
|
134
|
+
if (same(next, current))
|
|
135
|
+
return;
|
|
136
|
+
current = next;
|
|
137
|
+
if (stateFile) {
|
|
138
|
+
try {
|
|
139
|
+
fs.mkdirSync(path.dirname(stateFile), { recursive: true });
|
|
140
|
+
const tmp = `${stateFile}.tmp`;
|
|
141
|
+
fs.writeFileSync(tmp, JSON.stringify(current));
|
|
142
|
+
fs.renameSync(tmp, stateFile);
|
|
143
|
+
}
|
|
144
|
+
catch { /* the switch still applies; only the restart starts from defaults */ }
|
|
145
|
+
}
|
|
146
|
+
announce();
|
|
147
|
+
}
|
|
148
|
+
function currentPipelineSwitches() {
|
|
149
|
+
return current;
|
|
150
|
+
}
|
|
151
|
+
/** Called now with the current switches, then on every change. Returns the unsubscribe. */
|
|
152
|
+
function onPipelineSwitches(listener) {
|
|
153
|
+
listeners.add(listener);
|
|
154
|
+
try {
|
|
155
|
+
listener(current);
|
|
156
|
+
}
|
|
157
|
+
catch { /* see announce */ }
|
|
158
|
+
return () => { listeners.delete(listener); };
|
|
159
|
+
}
|
|
160
|
+
const captureFeeds = new Map();
|
|
161
|
+
let captureListening = false;
|
|
162
|
+
function bindCapturePipeline(feedName, provider) {
|
|
163
|
+
if (!provider || typeof provider !== 'object')
|
|
164
|
+
return;
|
|
165
|
+
captureFeeds.set(feedName, provider);
|
|
166
|
+
if (!captureListening) {
|
|
167
|
+
captureListening = true;
|
|
168
|
+
onPipelineSwitches((switches) => {
|
|
169
|
+
for (const target of captureFeeds.values()) {
|
|
170
|
+
try {
|
|
171
|
+
target.setCapturePipeline?.(switches.capture);
|
|
172
|
+
}
|
|
173
|
+
catch { /* one feed never stops another */ }
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
try {
|
|
179
|
+
provider.setCapturePipeline?.(current.capture);
|
|
180
|
+
}
|
|
181
|
+
catch { /* see above */ }
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
let detectorSnapshot = null;
|
|
185
|
+
function noteDetectorBackend(snapshot) {
|
|
186
|
+
if (snapshot)
|
|
187
|
+
detectorSnapshot = snapshot;
|
|
188
|
+
}
|
|
189
|
+
const clockSamples = [];
|
|
190
|
+
function noteServerClock(sentAtMs, receivedAtMs, serverNowMs) {
|
|
191
|
+
if (typeof serverNowMs !== 'number' || !Number.isSafeInteger(serverNowMs) || serverNowMs <= 0)
|
|
192
|
+
return;
|
|
193
|
+
if (!Number.isFinite(sentAtMs) || !Number.isFinite(receivedAtMs) || receivedAtMs < sentAtMs)
|
|
194
|
+
return;
|
|
195
|
+
const rttMs = receivedAtMs - sentAtMs;
|
|
196
|
+
clockSamples.push({ offsetMs: Math.round(serverNowMs - (sentAtMs + rttMs / 2)), rttMs, atMs: receivedAtMs });
|
|
197
|
+
const cutoff = receivedAtMs - 600000;
|
|
198
|
+
while (clockSamples.length && (clockSamples[0].atMs < cutoff || clockSamples.length > 256))
|
|
199
|
+
clockSamples.shift();
|
|
200
|
+
}
|
|
201
|
+
function clockEstimate() {
|
|
202
|
+
if (!clockSamples.length)
|
|
203
|
+
return null;
|
|
204
|
+
const best = [...clockSamples].sort((a, b) => a.rttMs - b.rttMs).slice(0, 8);
|
|
205
|
+
const offsets = best.map((s) => s.offsetMs).sort((a, b) => a - b);
|
|
206
|
+
return { offsetMs: offsets[Math.floor(offsets.length / 2)], rttMs: best[0].rttMs, samples: clockSamples.length };
|
|
207
|
+
}
|
|
208
|
+
/** What a look reports about the pipeline that produced it. Bounded and diagnostic. */
|
|
209
|
+
function pipelineTrace(feedName, lookReuse) {
|
|
210
|
+
const camera = feedName ? captureFeeds.get(feedName) : undefined;
|
|
211
|
+
let capture = null;
|
|
212
|
+
try {
|
|
213
|
+
const stats = camera?.getStats?.() ?? null;
|
|
214
|
+
if (stats && stats.capture)
|
|
215
|
+
capture = { ...stats.capture, frameAgeMs: stats.frameAgeMs ?? null };
|
|
216
|
+
}
|
|
217
|
+
catch {
|
|
218
|
+
capture = null;
|
|
219
|
+
}
|
|
220
|
+
const clock = clockEstimate();
|
|
221
|
+
return {
|
|
222
|
+
version: 1,
|
|
223
|
+
switches: { capture: current.capture, lookReuse: current.lookReuse, detectorBackend: current.detectorBackend },
|
|
224
|
+
...(capture ? { capture } : {}),
|
|
225
|
+
...(detectorSnapshot ? { detector: detectorSnapshot } : {}),
|
|
226
|
+
...(clock ? { clock } : {}),
|
|
227
|
+
...(lookReuse && typeof lookReuse === 'object' ? { lookReuse } : {}),
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
function __resetPipelineSwitchesForTests() {
|
|
231
|
+
current = { ...exports.DEFAULT_PIPELINE_SWITCHES };
|
|
232
|
+
stateFile = null;
|
|
233
|
+
fromServer = false;
|
|
234
|
+
listeners.clear();
|
|
235
|
+
captureFeeds.clear();
|
|
236
|
+
captureListening = false;
|
|
237
|
+
detectorSnapshot = null;
|
|
238
|
+
clockSamples.length = 0;
|
|
239
|
+
}
|
|
240
|
+
//# sourceMappingURL=pipelineSwitches.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipelineSwitches.js","sourceRoot":"","sources":["../src/pipelineSwitches.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8CA,sDASC;AAyBD,0DAUC;AAOD,oDAgBC;AAED,0DAEC;AAGD,gDAIC;AAWD,kDAaC;AAgBD,kDAEC;AAWD,0CAOC;AAUD,sCAgBC;AAED,0EASC;AA7ND;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,uCAAyB;AACzB,2CAA6B;AAahB,QAAA,iBAAiB,GAC5B,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,cAAc,EAAE,iBAAiB,EAAE,WAAW,EAAE,cAAc,CAAC,CAAC,CAAC;AAC/E,QAAA,gBAAgB,GAA6B,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC;AACtF,QAAA,iBAAiB,GAC5B,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,cAAc,CAAC,CAAC,CAAC;AAE1D,QAAA,yBAAyB,GAA+B,MAAM,CAAC,MAAM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O;QACL,OAAO,EAAE,CAAC;QACV,QAAQ,EAAE,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,eAAe,EAAE,OAAO,CAAC,eAAe,EAAE;QAC9G,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/B,GAAG,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,gBAAgB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC3D,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC3B,GAAG,CAAC,SAAS,IAAI,OAAO,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACrE,CAAC;AACJ,CAAC;AAED,SAAgB,+BAA+B;IAC7C,OAAO,GAAG,EAAE,GAAG,iCAAyB,EAAE,CAAC;IAC3C,SAAS,GAAG,IAAI,CAAC;IACjB,UAAU,GAAG,KAAK,CAAC;IACnB,SAAS,CAAC,KAAK,EAAE,CAAC;IAClB,YAAY,CAAC,KAAK,EAAE,CAAC;IACrB,gBAAgB,GAAG,KAAK,CAAC;IACzB,gBAAgB,GAAG,IAAI,CAAC;IACxB,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC;AAC1B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trillboards/edge-sdk",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.246",
|
|
4
4
|
"description": "Composable cross-platform Edge AI SDK for audience sensing on DOOH/CTV devices",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
"scripts": {
|
|
12
12
|
"build": "tsc",
|
|
13
13
|
"postbuild": "chmod +x dist/cli.js dist/mcp-server.js",
|
|
14
|
-
"test": "jest --passWithNoTests --forceExit && node --test retained/__tests__/runtime.test.cjs retained/__tests__/archive-lifecycle.test.cjs retained/__tests__/actor-perception.test.cjs retained/__tests__/actor-window.test.cjs retained/__tests__/website-admission.test.cjs retained/__tests__/realtime-schedule.test.cjs retained/__tests__/upgrade-backlog.test.cjs retained/__tests__/website-admission-realtime.test.cjs retained/__tests__/evidence-uploads.test.cjs scripts/__tests__/local-sense-wiring-detector.test.cjs scripts/__tests__/alert-safe-point-verdict.test.mjs",
|
|
15
|
-
"test:retained": "node --test retained/__tests__/runtime.test.cjs retained/__tests__/archive-lifecycle.test.cjs retained/__tests__/actor-perception.test.cjs retained/__tests__/actor-window.test.cjs retained/__tests__/website-admission.test.cjs retained/__tests__/realtime-schedule.test.cjs retained/__tests__/upgrade-backlog.test.cjs retained/__tests__/website-admission-realtime.test.cjs retained/__tests__/evidence-uploads.test.cjs scripts/__tests__/local-sense-wiring-detector.test.cjs scripts/__tests__/alert-safe-point-verdict.test.mjs",
|
|
14
|
+
"test": "jest --passWithNoTests --forceExit && node --test retained/__tests__/runtime.test.cjs retained/__tests__/archive-lifecycle.test.cjs retained/__tests__/actor-perception.test.cjs retained/__tests__/actor-window.test.cjs retained/__tests__/website-admission.test.cjs retained/__tests__/realtime-schedule.test.cjs retained/__tests__/upgrade-backlog.test.cjs retained/__tests__/website-admission-realtime.test.cjs retained/__tests__/evidence-uploads.test.cjs retained/__tests__/look-reuse.test.cjs scripts/__tests__/local-sense-wiring-detector.test.cjs scripts/__tests__/alert-safe-point-verdict.test.mjs",
|
|
15
|
+
"test:retained": "node --test retained/__tests__/runtime.test.cjs retained/__tests__/archive-lifecycle.test.cjs retained/__tests__/actor-perception.test.cjs retained/__tests__/actor-window.test.cjs retained/__tests__/website-admission.test.cjs retained/__tests__/realtime-schedule.test.cjs retained/__tests__/upgrade-backlog.test.cjs retained/__tests__/website-admission-realtime.test.cjs retained/__tests__/evidence-uploads.test.cjs retained/__tests__/look-reuse.test.cjs scripts/__tests__/local-sense-wiring-detector.test.cjs scripts/__tests__/alert-safe-point-verdict.test.mjs",
|
|
16
16
|
"clean": "rm -rf dist",
|
|
17
17
|
"prepublishOnly": "npm run build"
|
|
18
18
|
},
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
},
|
|
30
30
|
"optionalDependencies": {
|
|
31
31
|
"@trillboards/edge-platform-linux": "^0.2.0",
|
|
32
|
-
"@trillboards/edge-platform-rtsp": "^0.2.
|
|
32
|
+
"@trillboards/edge-platform-rtsp": "^0.2.21",
|
|
33
33
|
"@trillboards/edge-platform-windows": "^0.2.0"
|
|
34
34
|
},
|
|
35
35
|
"files": [
|
|
@@ -39,7 +39,7 @@ function commit(file,value) {
|
|
|
39
39
|
* Every original is retained. Sampling is explicit; archived intermediate images are NOT called reviewed.
|
|
40
40
|
*/
|
|
41
41
|
class RetainedCaptureClient {
|
|
42
|
-
constructor(client,directory,{cameraId,intervalMs=500,maxCaptures=100000,maxBytes=32*1024**3,offerWindow=16,reviewStage=()=>'active',selectionMode='all',groupingPolicy=null,configuredApiBaseUrl,archiveRetentionMs,actorPerceiver,realtimeReview,onOfferStall}={}) {
|
|
42
|
+
constructor(client,directory,{cameraId,intervalMs=500,maxCaptures=100000,maxBytes=32*1024**3,offerWindow=16,reviewStage=()=>'active',selectionMode='all',groupingPolicy=null,configuredApiBaseUrl,archiveRetentionMs,actorPerceiver,realtimeReview,onOfferStall,onReviewed}={}) {
|
|
43
43
|
require('../dist/continuousReview').assertRetainedReviewReceiver(client.getEndpoint(),configuredApiBaseUrl);
|
|
44
44
|
assert(cameraId && Number.isSafeInteger(intervalMs)&&intervalMs>=500);
|
|
45
45
|
assert(['all','state-change-v1'].includes(selectionMode));
|
|
@@ -58,6 +58,9 @@ class RetainedCaptureClient {
|
|
|
58
58
|
// Offer-path watchdog state (see OFFER_STALL_MIN_MS): when this camera last captured, and when
|
|
59
59
|
// its archive last made progress (an offer, a review start, a receipt).
|
|
60
60
|
this.onOfferStall=typeof onOfferStall==='function'?onOfferStall:null;
|
|
61
|
+
// Plan v7 W8: told of every live frame a model answered directly, so the frame grouper can judge
|
|
62
|
+
// later captures against it for look reuse. Never told of a reused answer or a backlog frame.
|
|
63
|
+
this.onReviewed=typeof onReviewed==='function'?onReviewed:null;
|
|
61
64
|
this.captureAttemptAtMs=null;this.offerProgressAtMs=null;this.offerStalls=0;
|
|
62
65
|
this.groupReferences=new Map();this.previousCaptureRecord=null;this.previousSelectedRecord=null;
|
|
63
66
|
this.entries=new Map();this.queued=new Set();this.anchor=null;this.nextDue=null;this.lastAt=-1;this.bytes=0;
|
|
@@ -338,6 +341,11 @@ class RetainedCaptureClient {
|
|
|
338
341
|
}
|
|
339
342
|
offerFor(r,extra={}){
|
|
340
343
|
return {...r.candidate,jpeg:fs.readFileSync(this.image(r)),retainedId:r.id,...extra,
|
|
344
|
+
// Plan v7 W8: a live look the admission answered from the newest reviewed frame (unchanged_scene).
|
|
345
|
+
// The spool honours it only when that frame's direct answer is still its newest for this camera.
|
|
346
|
+
...(r.lookReuse?.mode==='live'&&r.lookReuse.eligible===true&&r.lookReuse.liveSafe===true&&!r.result?{lookReuse:{version:1,
|
|
347
|
+
method:'unchanged_scene',referenceEvidenceId:r.lookReuse.referenceId,referenceCapturedAtMs:r.lookReuse.referenceCapturedAtMs,
|
|
348
|
+
referenceSha256:r.lookReuse.referenceSha256}}:{}),
|
|
341
349
|
reviewContext:{...r.candidate.reviewContext,retainedCapture:{version:1,id:r.id,kind:'retained_single_capture'}}};
|
|
342
350
|
}
|
|
343
351
|
captureOrderCandidates(rows,available=this.offerWindow-this.queued.size){
|
|
@@ -554,7 +562,34 @@ class RetainedCaptureClient {
|
|
|
554
562
|
}
|
|
555
563
|
const req={...request,...(r.reviewSchedule?{reviewSchedule:r.reviewSchedule}:{}),...(r.actorPerception?{actorPerception:this.actorPerceiver.validate(r.actorPerception,this.perceptionInput(r),r.actorPerceptionPolicy)}:{}),reviewContext:r.candidate.reviewContext,resolveActorWindow:(actor,modelId)=>resolveActorWindow(this,r,actor,modelId),temporalContinuityBreak:r.temporalContinuityBroken===true,resolveTemporalCoverage:contract=>{const key=JSON.stringify(contract);if(!coverageCache.has(key))coverageCache.set(key,resolveTemporalCoverage(this,r,contract));return coverageCache.get(key);},cachedAnalysis:request.cachedAnalysis??r.result,
|
|
556
564
|
checkpointAnalysis:result=>{const first=!r.result;r.result=result;commit(this.file(r.id),r);if(first)this.counts.reviewed++;this.noteReviewed(r);this.leaveBacklog(r);request.checkpointAnalysis(result);}};
|
|
557
|
-
await reviewExecution.run({evidenceId:r.id,cameraId:r.cameraId},()=>this.client.reviewCandidate(req));assert(r.result,'No durable result');
|
|
565
|
+
await reviewExecution.run({evidenceId:r.id,cameraId:r.cameraId},()=>this.client.reviewCandidate(req));assert(r.result,'No durable result');
|
|
566
|
+
if(!historical&&r.result.reuseMethod===undefined&&r.result.reusedFromEvidenceId===undefined){try{this.onReviewed?.(r);}catch{/* reuse is an optimisation, never a review failure */}}
|
|
567
|
+
this.settleLookReuse(r);
|
|
568
|
+
return {...req,...(r.lookReuse?{lookReuse:r.lookReuse}:{}),cachedAnalysis:r.result};
|
|
569
|
+
}
|
|
570
|
+
/**
|
|
571
|
+
* Plan v7 W8: what look reuse did with this look, once its answer exists. A shadow look ran the model,
|
|
572
|
+
* so its answer is compared with the reviewed frame's (the answer reuse would have given): `agrees`, and
|
|
573
|
+
* the fields that differ. A live look records whether the reused answer was applied (the spool may have
|
|
574
|
+
* had a newer direct answer, and then the model ran). Saved once, so every upload retry reports the same.
|
|
575
|
+
*/
|
|
576
|
+
settleLookReuse(r){
|
|
577
|
+
const reuse=r.lookReuse;
|
|
578
|
+
if(!reuse||reuse.settled===true||!r.result)return;
|
|
579
|
+
const settled={...reuse,settled:true};
|
|
580
|
+
if(reuse.mode==='live')settled.applied=r.result.reuseMethod==='unchanged_scene';
|
|
581
|
+
if(reuse.eligible===true&&r.result.reuseMethod===undefined){
|
|
582
|
+
const ref=reuse.referenceId?this.records.get(reuse.referenceId):null;
|
|
583
|
+
const want=ref?.result?.structured,got=r.result.structured;
|
|
584
|
+
if(want&&got&&typeof want==='object'&&typeof got==='object'){
|
|
585
|
+
const fields=[...new Set([...Object.keys(want),...Object.keys(got)])].filter(f=>f!=='captured_at'&&f!=='source').sort();
|
|
586
|
+
const differing=fields.filter(f=>JSON.stringify(want[f])!==JSON.stringify(got[f]));
|
|
587
|
+
settled.agrees=differing.length===0;
|
|
588
|
+
if(differing.length)settled.differing=differing.slice(0,16);
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
r.lookReuse=settled;
|
|
592
|
+
try{commit(this.file(r.id),r);}catch{/* the verdict is diagnostic; the answer is already durable */}
|
|
558
593
|
}
|
|
559
594
|
async reviewCandidate(request){await this.prepare(request);}
|
|
560
595
|
async analyze(request){
|
|
@@ -71,6 +71,24 @@ function advanceAdmission(admission, row, previous) {
|
|
|
71
71
|
/** A live look the camera is owed: see liveLookDue. */
|
|
72
72
|
const LIVE_LOOK = Object.freeze({ selected: true, disposition: 'pending_review', selectionReason: 'live_look_interval' });
|
|
73
73
|
|
|
74
|
+
/** The box's look-reuse switch (plan v7 W8, CCTV_LOOK_REUSE): off | shadow | live. Unreadable is off. */
|
|
75
|
+
function lookReuseMode() {
|
|
76
|
+
try { return require('../dist/pipelineSwitches').currentPipelineSwitches().lookReuse; } catch { return 'off'; }
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* May a reused answer stand for this camera's look? Only a plain detector answer: a scoped
|
|
81
|
+
* (box-method) review carries per-look box memory (staff identity, vehicle announcements, gates)
|
|
82
|
+
* that a reused answer would leave unfed, and an actor, temporal or ordered review is bound to its
|
|
83
|
+
* own frame. Those cameras run reuse in shadow only, until their own replay passes.
|
|
84
|
+
*/
|
|
85
|
+
function liveSafeContext(context, reference, row) {
|
|
86
|
+
return !!context && !row.actorPerceptionPolicy && !context.scopedVlmReview && context.detectorCounts === undefined
|
|
87
|
+
&& context.mixedModelExecution === undefined && !context.temporalReviewContract && !context.orderedSequence
|
|
88
|
+
&& !context.orderedCaptureContract && reference.analysisMethod === undefined && reference.actorReview === undefined
|
|
89
|
+
&& reference.actorPerceptionSha256 === undefined;
|
|
90
|
+
}
|
|
91
|
+
|
|
74
92
|
/** The ordinary website still owns all conditions, timing and delivery.
|
|
75
93
|
* Originals are archived first; only redundant observations INSIDE every active
|
|
76
94
|
* wait window may be omitted from inference, and never the camera's live look
|
|
@@ -168,6 +186,43 @@ class WebsiteAdmissionCaptureClient extends RetainedCaptureClient {
|
|
|
168
186
|
this.liveLookStartedAtMs = schedule.startedAtMs;
|
|
169
187
|
}
|
|
170
188
|
}
|
|
189
|
+
/**
|
|
190
|
+
* Plan v7 W8: what look reuse makes of a live look on this capture, or null when the switch is off.
|
|
191
|
+
* `eligible`: the frame grouper found every question scope unchanged against the camera's newest
|
|
192
|
+
* model-reviewed frame inside its re-check bound, and this archive holds that frame with its direct
|
|
193
|
+
* model answer under the same context. `liveSafe`: that answer may stand for this look (liveSafeContext).
|
|
194
|
+
*/
|
|
195
|
+
lookReuseFor(row) {
|
|
196
|
+
const mode = lookReuseMode();
|
|
197
|
+
if (mode !== 'shadow' && mode !== 'live') return null;
|
|
198
|
+
const verdict = row.candidate.groupingShadow?.reuse;
|
|
199
|
+
const base = { version: 1, mode, eligible: false };
|
|
200
|
+
if (!verdict || verdict.version !== 1 || typeof verdict.eligible !== 'boolean') return { ...base, reason: 'no_verdict' };
|
|
201
|
+
const where = Number.isSafeInteger(verdict.referenceCapturedAtMs) && /^[a-f0-9]{64}$/.test(verdict.referenceSha256 ?? '')
|
|
202
|
+
? { referenceCapturedAtMs: verdict.referenceCapturedAtMs, referenceSha256: verdict.referenceSha256,
|
|
203
|
+
occupied: verdict.occupied === true, ageMs: verdict.ageMs } : {};
|
|
204
|
+
if (!verdict.eligible) return { ...base, reason: verdict.reason, ...where };
|
|
205
|
+
if (!where.referenceSha256 || where.referenceCapturedAtMs >= row.capturedAt) return { ...base, reason: 'invalid_verdict' };
|
|
206
|
+
const context = row.candidate.reviewContext;
|
|
207
|
+
const referenceId = crypto.createHash('sha256').update(JSON.stringify([row.candidate.name,
|
|
208
|
+
where.referenceCapturedAtMs, where.referenceSha256, context])).digest('hex').slice(0, 32);
|
|
209
|
+
const reference = this.records.get(referenceId);
|
|
210
|
+
const answer = reference?.result;
|
|
211
|
+
if (!answer || reference.imageSha256 !== where.referenceSha256 || answer.evidenceSha256 !== where.referenceSha256
|
|
212
|
+
|| answer.reuseMethod !== undefined || answer.reusedFromEvidenceId !== undefined) {
|
|
213
|
+
return { ...base, reason: 'reference_not_reviewed', ...where };
|
|
214
|
+
}
|
|
215
|
+
return { ...base, eligible: true, reason: 'unchanged', referenceId, ...where,
|
|
216
|
+
liveSafe: liveSafeContext(context, answer, row) };
|
|
217
|
+
}
|
|
218
|
+
/** A live look, answered from the reviewed frame when the switch is live and the reuse is safe. */
|
|
219
|
+
liveLookChoice(row) {
|
|
220
|
+
const reuse = this.lookReuseFor(row);
|
|
221
|
+
if (reuse?.mode === 'live' && reuse.eligible && reuse.liveSafe) {
|
|
222
|
+
return { selected: true, disposition: 'pending_review', selectionReason: 'unchanged_scene', lookReuse: reuse };
|
|
223
|
+
}
|
|
224
|
+
return reuse ? { ...LIVE_LOOK, lookReuse: reuse } : LIVE_LOOK;
|
|
225
|
+
}
|
|
171
226
|
admissionSelection(row, lastSelectedAt = this.previousSelectedRecord?.capturedAt ?? null) {
|
|
172
227
|
const admission = this.admission(row.candidate.reviewContext, row.capturedAt);
|
|
173
228
|
const remembered = this.states.get(admissionContextHash(row.candidate.reviewContext));
|
|
@@ -183,14 +238,14 @@ class WebsiteAdmissionCaptureClient extends RetainedCaptureClient {
|
|
|
183
238
|
// The server's wait/recheck clock ignores answers inside the window (routeReviewTiming:
|
|
184
239
|
// intermediate answers cannot cancel or clear an episode), so a live look there only keeps
|
|
185
240
|
// the camera watched; the deadline endpoint keeps its own reserved, urgent slot.
|
|
186
|
-
if (waiting) choice = lookDue ?
|
|
241
|
+
if (waiting) choice = lookDue ? this.liveLookChoice(row)
|
|
187
242
|
: { selected: false, disposition: 'archived_wait_window', selectionReason: 'before_all_website_wait_deadlines' };
|
|
188
243
|
else if (admission && (!state || expired || followUp)) choice = { selected: true, disposition: 'pending_review',
|
|
189
244
|
selectionReason: followUp ? 'website_wait_deadline_check' : 'website_initial_or_context_change' };
|
|
190
245
|
else {
|
|
191
246
|
choice = super.chooseReview(row.candidate, row.imageSha256,
|
|
192
247
|
this.nextDue === null || row.capturedAt >= this.nextDue, row.reviewStage);
|
|
193
|
-
if (lookDue && !choice.selected && choice.disposition === 'archived_grouped_unchanged') choice =
|
|
248
|
+
if (lookDue && !choice.selected && choice.disposition === 'archived_grouped_unchanged') choice = this.liveLookChoice(row);
|
|
194
249
|
}
|
|
195
250
|
return { choice, anchors, followUp };
|
|
196
251
|
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// Plan v7 W8, look reuse (CCTV_LOOK_REUSE) through the ACTUAL website admission client, the
|
|
3
|
+
// ACTUAL frame grouper (with its reuse verdict) and the ACTUAL durable spool. Only the model
|
|
4
|
+
// answer is controlled; a "model call" is a reviewCandidate without a saved answer.
|
|
5
|
+
const { test } = require('node:test');
|
|
6
|
+
const assert = require('node:assert/strict');
|
|
7
|
+
const fs = require('node:fs'), os = require('node:os'), path = require('node:path'), crypto = require('node:crypto');
|
|
8
|
+
const { WebsiteAdmissionCaptureClient } = require('../WebsiteAdmissionCaptureClient.cjs');
|
|
9
|
+
const { answerOccupied } = require('../manager.cjs');
|
|
10
|
+
const { DurableVlmCandidateSpool } = require('../../dist/DurableVlmCandidateSpool');
|
|
11
|
+
const { FrameGroupingShadow, groupingScopes, DEFAULT_LOOK_REUSE } = require('../../dist/FrameGroupingShadow');
|
|
12
|
+
const switches = require('../../dist/pipelineSwitches');
|
|
13
|
+
const sha = bytes => crypto.createHash('sha256').update(bytes).digest('hex');
|
|
14
|
+
const ENDPOINT = 'http://127.0.0.1:18791/v2/earner/audience-analyze';
|
|
15
|
+
const GROUPING = { mode: 'shadow', separateProfileWork: true, pixelDelta: 12, minChangedPixels: 12,
|
|
16
|
+
quietIntervalMs: 10000, followUpMs: 5000 };
|
|
17
|
+
const sourceJpeg = fs.readFileSync(path.join(__dirname, '../../src/__tests__/fixtures/cctv-cstore-empty.jpg'));
|
|
18
|
+
let tag = 0;
|
|
19
|
+
function original() {
|
|
20
|
+
const comment = Buffer.from('look-reuse-original-' + ++tag);
|
|
21
|
+
const header = Buffer.alloc(4); header.writeUInt16BE(0xfffe); header.writeUInt16BE(comment.length + 2, 2);
|
|
22
|
+
return Buffer.concat([sourceJpeg.subarray(0, 2), header, comment, sourceJpeg.subarray(2)]);
|
|
23
|
+
}
|
|
24
|
+
function context(extra = {}) {
|
|
25
|
+
return { version: 1, profileState: 'active', prompt: 'Controlled look-reuse fixture.',
|
|
26
|
+
schema: { type: 'object', properties: { person_present: { type: 'boolean' } }, required: ['person_present'] },
|
|
27
|
+
retainedFieldContract: { version: 1, required: [{ field: 'person_present', type: 'boolean' }] },
|
|
28
|
+
producerFields: [], regions: [], operatingPoints: [], absenceWatchedFields: [], ...extra };
|
|
29
|
+
}
|
|
30
|
+
function scene(at, moving) {
|
|
31
|
+
const data = new Uint8Array(32 * 24).fill(90);
|
|
32
|
+
if (moving) for (let i = 0; i < 40; i++) data[(i * 13 + Math.floor(at / 100)) % data.length] = 220;
|
|
33
|
+
return { width: 32, height: 24, data };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function rig(t, mode, { reviewContext = context() } = {}) {
|
|
37
|
+
switches.__resetPipelineSwitchesForTests();
|
|
38
|
+
switches.notePipelineSwitches({ version: 1, capture: 'legacy', lookReuse: mode, detectorBackend: 'ort' });
|
|
39
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'look-reuse-'));
|
|
40
|
+
t.after(() => { fs.rmSync(root, { recursive: true, force: true }); switches.__resetPipelineSwitchesForTests(); });
|
|
41
|
+
const state = { now: 1000, answer: { person_present: false } };
|
|
42
|
+
const calls = [], uploads = [];
|
|
43
|
+
const grouper = new FrameGroupingShadow({ ...GROUPING, reuse: DEFAULT_LOOK_REUSE });
|
|
44
|
+
const client = {
|
|
45
|
+
getEndpoint: () => ENDPOINT,
|
|
46
|
+
captureReviewContext: () => reviewContext,
|
|
47
|
+
async reviewCandidate(req) {
|
|
48
|
+
if (!req.cachedAnalysis) calls.push({ capturedAt: req.capturedAt, jpegSha256: sha(req.jpeg) });
|
|
49
|
+
req.checkpointAnalysis(req.cachedAnalysis ?? { version: 1, evidenceSha256: sha(req.jpeg),
|
|
50
|
+
reviewedAtMs: state.now, structured: { ...state.answer } });
|
|
51
|
+
},
|
|
52
|
+
async analyze(req) {
|
|
53
|
+
uploads.push({ capturedAt: req.capturedAt, saved: JSON.parse(JSON.stringify(req.cachedAnalysis)),
|
|
54
|
+
lookReuse: req.lookReuse ? JSON.parse(JSON.stringify(req.lookReuse)) : undefined });
|
|
55
|
+
return { ok: true, body: { accepted: true, evidenceId: req.evidenceId,
|
|
56
|
+
evidenceReview: { version: 1, capturedAtMs: req.capturedAt } } };
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
const spool = new DurableVlmCandidateSpool({ directory: path.join(root, 'spool'), now: () => state.now,
|
|
60
|
+
reviewWindowMs: 150000, retentionMs: 86400000, priorityScheduling: true, preserveArchivedPending: true,
|
|
61
|
+
maxFrames: 512, maxPerFeed: 128, maxBytes: 128 * 1024 ** 2, retryInitialMs: 500 });
|
|
62
|
+
spool.startRun();
|
|
63
|
+
const archive = new WebsiteAdmissionCaptureClient(client, path.join(root, 'archive'), {
|
|
64
|
+
cameraId: 'cam', pairedCameraId: 'paired-cam', intervalMs: 500, offerWindow: 16, maxCaptures: 1000,
|
|
65
|
+
maxBytes: 128 * 1024 ** 2, archiveRetentionMs: 600000, realtimeReview: { freshnessMs: 180000, now: () => state.now },
|
|
66
|
+
admissionNowMs: () => state.now, selectionMode: 'state-change-v1', groupingPolicy: GROUPING, liveLookIntervalMs: 2000,
|
|
67
|
+
onReviewed: row => grouper.noteReviewed(row.capturedAt, row.imageSha256, answerOccupied(row.result?.structured)),
|
|
68
|
+
});
|
|
69
|
+
archive.attachReviewQueue(spool);
|
|
70
|
+
function capture(at, moving = false) {
|
|
71
|
+
state.now = at;
|
|
72
|
+
const jpeg = original();
|
|
73
|
+
const groupingShadow = grouper.observe(scene(at, moving), groupingScopes(reviewContext), reviewContext, at, sha(jpeg));
|
|
74
|
+
archive.retainOrderedCapture({ name: 'cam', enqueuedAtMs: at, jpeg, captureMode: 'periodic', reason: 'motion',
|
|
75
|
+
signature: String(at), reviewKind: 'event', reviewContext, groupingShadow });
|
|
76
|
+
}
|
|
77
|
+
function request(item) {
|
|
78
|
+
return { evidenceId: item.spoolId, capturedAt: item.enqueuedAtMs, jpeg: item.jpeg, reviewContext: item.reviewContext,
|
|
79
|
+
cachedAnalysis: item.cachedAnalysis, checkpointAnalysis: saved => spool.checkpoint(item, saved) };
|
|
80
|
+
}
|
|
81
|
+
// One pump: offer, then serve whatever the spool holds (review lane, then delivery lane).
|
|
82
|
+
async function pump() {
|
|
83
|
+
for (const candidate of archive.pendingOrderedCandidates()) archive.offered(candidate, spool.offer(candidate, state.now));
|
|
84
|
+
for (let item; (item = spool.take(undefined, 'review'));) {
|
|
85
|
+
await archive.reviewCandidate(request(item)); spool.readyForDelivery(item);
|
|
86
|
+
}
|
|
87
|
+
for (let item; (item = spool.take(undefined, 'delivery'));) {
|
|
88
|
+
await archive.analyze(request(item)); spool.complete(item);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
// A still (or moving) camera captured every 500 ms for `ms`.
|
|
92
|
+
async function run(from, ms, moving = false) {
|
|
93
|
+
for (let at = from; at < from + ms; at += 500) { capture(at, moving); await pump(); }
|
|
94
|
+
}
|
|
95
|
+
return { state, calls, uploads, archive, run, capture, pump };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
test('off: every live look is a model look, exactly as before, with no reuse provenance', async t => {
|
|
99
|
+
const r = rig(t, 'off');
|
|
100
|
+
await r.run(1000, 20000);
|
|
101
|
+
assert(r.calls.length >= 9, `a still camera is looked at every ~2 s (${r.calls.length} looks)`);
|
|
102
|
+
assert(r.uploads.every(u => u.saved.reuseMethod === undefined && u.lookReuse === undefined));
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test('live: an unchanged camera is answered from its reviewed frame, re-checked by the model on the empty bound', async t => {
|
|
106
|
+
const r = rig(t, 'live');
|
|
107
|
+
await r.run(1000, 70000);
|
|
108
|
+
const reused = r.uploads.filter(u => u.saved.reuseMethod === 'unchanged_scene');
|
|
109
|
+
const modelLooks = r.calls.length;
|
|
110
|
+
assert(reused.length >= 25, `most live looks reused (${reused.length})`);
|
|
111
|
+
// The first look, the grouper's 10 s quiet checks and the 60 s bound still reach the model.
|
|
112
|
+
assert(modelLooks >= 2 && modelLooks <= 12, `model looks ${modelLooks}`);
|
|
113
|
+
for (const u of reused) {
|
|
114
|
+
assert.equal(u.saved.analyzeMs, 0);
|
|
115
|
+
assert.equal(u.saved.structured.person_present, false);
|
|
116
|
+
assert.notEqual(u.saved.evidenceSha256, u.saved.sourceEvidenceSha256, 'the answer is re-bound to its own image');
|
|
117
|
+
assert(u.saved.sourceCapturedAtMs < u.capturedAt);
|
|
118
|
+
assert(u.capturedAt - u.saved.sourceCapturedAtMs < DEFAULT_LOOK_REUSE.emptyRecheckMs);
|
|
119
|
+
assert.equal(u.lookReuse.applied, true);
|
|
120
|
+
assert.equal(u.saved.evidenceImage, undefined, 'the photo decision belongs to the client, not the reference');
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
test('live: an occupied scene is re-checked by the model within 12 s', async t => {
|
|
125
|
+
const r = rig(t, 'live');
|
|
126
|
+
r.state.answer = { person_present: true };
|
|
127
|
+
await r.run(1000, 40000);
|
|
128
|
+
const reused = r.uploads.filter(u => u.saved.reuseMethod === 'unchanged_scene');
|
|
129
|
+
assert(reused.length > 0);
|
|
130
|
+
for (const u of reused) assert(u.capturedAt - u.saved.sourceCapturedAtMs < DEFAULT_LOOK_REUSE.occupiedRecheckMs);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
test('live: a changing scene always goes to the model', async t => {
|
|
134
|
+
const r = rig(t, 'live');
|
|
135
|
+
await r.run(1000, 20000, true);
|
|
136
|
+
assert.equal(r.uploads.filter(u => u.saved.reuseMethod).length, 0);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
test('shadow: the model still looks, and each eligible look records whether reuse would have agreed', async t => {
|
|
140
|
+
const r = rig(t, 'shadow');
|
|
141
|
+
await r.run(1000, 30000);
|
|
142
|
+
assert(r.uploads.every(u => u.saved.reuseMethod === undefined), 'shadow never answers from the reviewed frame');
|
|
143
|
+
const eligible = r.uploads.filter(u => u.lookReuse?.eligible === true);
|
|
144
|
+
assert(eligible.length >= 5, `eligible shadow looks ${eligible.length}`);
|
|
145
|
+
assert(eligible.every(u => u.lookReuse.agrees === true && u.lookReuse.settled === true));
|
|
146
|
+
// A model answer that differs is counted, field by field.
|
|
147
|
+
r.state.answer = { person_present: true };
|
|
148
|
+
await r.run(31000, 6000);
|
|
149
|
+
const disagreed = r.uploads.filter(u => u.lookReuse?.agrees === false);
|
|
150
|
+
assert(disagreed.length >= 1 && disagreed.every(u => u.lookReuse.differing.includes('person_present')));
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
test('live never answers a box-method (scoped) camera: its box memory needs every look', async t => {
|
|
154
|
+
const r = rig(t, 'live', { reviewContext: context({ scopedVlmReview: { fields: [{ field: 'person_present', type: 'boolean' }] } }) });
|
|
155
|
+
await r.run(1000, 20000);
|
|
156
|
+
assert.equal(r.uploads.filter(u => u.saved.reuseMethod).length, 0);
|
|
157
|
+
assert(r.uploads.some(u => u.lookReuse?.eligible === true && u.lookReuse.liveSafe === false));
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
test('answerOccupied: anything not plainly empty counts as occupied', () => {
|
|
161
|
+
assert.equal(answerOccupied({ person_present: false, person_count: 0, source: 'detector_edge', captured_at: 'x' }), false);
|
|
162
|
+
assert.equal(answerOccupied({ person_count: 1 }), true);
|
|
163
|
+
assert.equal(answerOccupied({ detected_objects: [] , reverse_parked_vehicle_detected: false }), false);
|
|
164
|
+
assert.equal(answerOccupied({ detected_objects: ['car'] }), true);
|
|
165
|
+
assert.equal(answerOccupied({ phone_use: 'unclear' }), false);
|
|
166
|
+
assert.equal(answerOccupied(null), true);
|
|
167
|
+
});
|