@trillboards/edge-sdk 0.2.246 → 0.2.254

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (141) hide show
  1. package/deploy/detector/README.md +15 -0
  2. package/deploy/detector/pyproject.toml +1 -1
  3. package/deploy/detector/tests/test_actor_tracking.py +136 -0
  4. package/deploy/detector/tests/test_actor_tracking_wire.py +11 -0
  5. package/deploy/detector/tests/test_face_identity.py +448 -0
  6. package/deploy/detector/tests/test_loader.py +28 -1
  7. package/deploy/detector/tests/test_registry.py +53 -0
  8. package/deploy/detector/trillboards_detector/_version.py +2 -2
  9. package/deploy/detector/trillboards_detector/actor_tracking.py +95 -9
  10. package/deploy/detector/trillboards_detector/face_contract.py +166 -0
  11. package/deploy/detector/trillboards_detector/face_identity.py +467 -0
  12. package/deploy/detector/trillboards_detector/loader.py +40 -0
  13. package/deploy/detector/trillboards_detector/registry.py +72 -2
  14. package/deploy/detector/trillboards_detector/server.py +48 -6
  15. package/deploy/detector/trillboards_detector/tasks.py +12 -1
  16. package/deploy/windows/build-windows.ps1 +1 -0
  17. package/deploy/windows/ci/test-detector-looks-field.ps1 +15 -3
  18. package/deploy/windows/ci/test-detector-reinstall.ps1 +173 -2
  19. package/deploy/windows/ci/test-main-stream-gpu-decode.ps1 +119 -0
  20. package/deploy/windows/ci/test-rollout-proofs.ps1 +3 -2
  21. package/deploy/windows/ensure-detector.ps1 +255 -0
  22. package/deploy/windows/install-update.ps1 +4 -3
  23. package/deploy/windows/stop-existing.ps1 +1 -0
  24. package/deploy/windows/trillboards-edge.cmd +10 -22
  25. package/dist/CloudSensingManager.d.ts +14 -0
  26. package/dist/CloudSensingManager.d.ts.map +1 -1
  27. package/dist/CloudSensingManager.js +51 -5
  28. package/dist/CloudSensingManager.js.map +1 -1
  29. package/dist/ConnectorStatusClient.d.ts +26 -1
  30. package/dist/ConnectorStatusClient.d.ts.map +1 -1
  31. package/dist/ConnectorStatusClient.js +9 -0
  32. package/dist/ConnectorStatusClient.js.map +1 -1
  33. package/dist/DetectorFields.d.ts +77 -1
  34. package/dist/DetectorFields.d.ts.map +1 -1
  35. package/dist/DetectorFields.js +34 -4
  36. package/dist/DetectorFields.js.map +1 -1
  37. package/dist/EdgeAgent.js +1 -1
  38. package/dist/FaceIdentity.d.ts +122 -0
  39. package/dist/FaceIdentity.d.ts.map +1 -0
  40. package/dist/FaceIdentity.js +256 -0
  41. package/dist/FaceIdentity.js.map +1 -0
  42. package/dist/FaceSightingUploader.d.ts +95 -0
  43. package/dist/FaceSightingUploader.d.ts.map +1 -0
  44. package/dist/FaceSightingUploader.js +214 -0
  45. package/dist/FaceSightingUploader.js.map +1 -0
  46. package/dist/FaceWatchLane.d.ts +297 -0
  47. package/dist/FaceWatchLane.d.ts.map +1 -0
  48. package/dist/FaceWatchLane.js +660 -0
  49. package/dist/FaceWatchLane.js.map +1 -0
  50. package/dist/FaceWatchPolicy.d.ts +154 -0
  51. package/dist/FaceWatchPolicy.d.ts.map +1 -0
  52. package/dist/FaceWatchPolicy.js +101 -0
  53. package/dist/FaceWatchPolicy.js.map +1 -0
  54. package/dist/LocalDetectorClient.d.ts +30 -0
  55. package/dist/LocalDetectorClient.d.ts.map +1 -1
  56. package/dist/LocalDetectorClient.js +72 -4
  57. package/dist/LocalDetectorClient.js.map +1 -1
  58. package/dist/MainStreamRing.d.ts +63 -1
  59. package/dist/MainStreamRing.d.ts.map +1 -1
  60. package/dist/MainStreamRing.js +101 -7
  61. package/dist/MainStreamRing.js.map +1 -1
  62. package/dist/NativeReadiness.d.ts +21 -2
  63. package/dist/NativeReadiness.d.ts.map +1 -1
  64. package/dist/NativeReadiness.js +32 -9
  65. package/dist/NativeReadiness.js.map +1 -1
  66. package/dist/OrderedReviewClient.d.ts +3 -0
  67. package/dist/OrderedReviewClient.d.ts.map +1 -1
  68. package/dist/OrderedReviewClient.js +3 -0
  69. package/dist/OrderedReviewClient.js.map +1 -1
  70. package/dist/ReviewPriority.d.ts +9 -0
  71. package/dist/ReviewPriority.d.ts.map +1 -1
  72. package/dist/ReviewPriority.js +6 -1
  73. package/dist/ReviewPriority.js.map +1 -1
  74. package/dist/ScopedVlmReview.d.ts +11 -2
  75. package/dist/ScopedVlmReview.d.ts.map +1 -1
  76. package/dist/ScopedVlmReview.js +43 -16
  77. package/dist/ScopedVlmReview.js.map +1 -1
  78. package/dist/SensingProfileClient.d.ts +14 -0
  79. package/dist/SensingProfileClient.d.ts.map +1 -1
  80. package/dist/SensingProfileClient.js +9 -0
  81. package/dist/SensingProfileClient.js.map +1 -1
  82. package/dist/TemporalReviewClient.d.ts +3 -0
  83. package/dist/TemporalReviewClient.d.ts.map +1 -1
  84. package/dist/TemporalReviewClient.js +3 -0
  85. package/dist/TemporalReviewClient.js.map +1 -1
  86. package/dist/UniformSceneStore.d.ts +6 -0
  87. package/dist/UniformSceneStore.d.ts.map +1 -1
  88. package/dist/UniformSceneStore.js +22 -1
  89. package/dist/UniformSceneStore.js.map +1 -1
  90. package/dist/VideoSegmentUploader.d.ts +11 -0
  91. package/dist/VideoSegmentUploader.d.ts.map +1 -1
  92. package/dist/VideoSegmentUploader.js +28 -2
  93. package/dist/VideoSegmentUploader.js.map +1 -1
  94. package/dist/VlmCandidateBuffer.d.ts +2 -0
  95. package/dist/VlmCandidateBuffer.d.ts.map +1 -1
  96. package/dist/VlmCandidateBuffer.js.map +1 -1
  97. package/dist/WatchlistClient.d.ts +55 -0
  98. package/dist/WatchlistClient.d.ts.map +1 -0
  99. package/dist/WatchlistClient.js +161 -0
  100. package/dist/WatchlistClient.js.map +1 -0
  101. package/dist/autoSense.d.ts.map +1 -1
  102. package/dist/autoSense.js +6 -0
  103. package/dist/autoSense.js.map +1 -1
  104. package/dist/cli.d.ts.map +1 -1
  105. package/dist/cli.js +6 -0
  106. package/dist/cli.js.map +1 -1
  107. package/dist/connectorUpdate.d.ts +34 -9
  108. package/dist/connectorUpdate.d.ts.map +1 -1
  109. package/dist/connectorUpdate.js +96 -9
  110. package/dist/connectorUpdate.js.map +1 -1
  111. package/dist/connectorUpdateApply.d.ts +20 -1
  112. package/dist/connectorUpdateApply.d.ts.map +1 -1
  113. package/dist/connectorUpdateApply.js +55 -1
  114. package/dist/connectorUpdateApply.js.map +1 -1
  115. package/dist/connectorUpdateApplyMac.d.ts +3 -1
  116. package/dist/connectorUpdateApplyMac.d.ts.map +1 -1
  117. package/dist/connectorUpdateApplyMac.js +6 -0
  118. package/dist/connectorUpdateApplyMac.js.map +1 -1
  119. package/dist/detectorEndpointState.d.ts +30 -0
  120. package/dist/detectorEndpointState.d.ts.map +1 -0
  121. package/dist/detectorEndpointState.js +125 -0
  122. package/dist/detectorEndpointState.js.map +1 -0
  123. package/dist/detectorLauncher.d.ts +23 -0
  124. package/dist/detectorLauncher.d.ts.map +1 -0
  125. package/dist/detectorLauncher.js +94 -0
  126. package/dist/detectorLauncher.js.map +1 -0
  127. package/dist/diagnose.d.ts +1 -1
  128. package/dist/diagnose.js +1 -1
  129. package/dist/hostCpu.d.ts +56 -0
  130. package/dist/hostCpu.d.ts.map +1 -0
  131. package/dist/hostCpu.js +113 -0
  132. package/dist/hostCpu.js.map +1 -0
  133. package/dist/localSensing.d.ts +86 -0
  134. package/dist/localSensing.d.ts.map +1 -1
  135. package/dist/localSensing.js +263 -30
  136. package/dist/localSensing.js.map +1 -1
  137. package/package.json +2 -2
  138. package/retained/ProfileAuthorityClient.cjs +4 -0
  139. package/retained/RetainedCaptureClient.cjs +6 -0
  140. package/retained/WebsiteAdmissionCaptureClient.cjs +3 -1
  141. package/retained/__tests__/website-admission-realtime.test.cjs +27 -2
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.SCENE_MEMORY_DIRNAME = exports.VIDEO_SEGMENTS_DIRNAME = exports.LocalSensingClient = exports.EVIDENCE_IMAGE_REQUIRED = exports.EVIDENCE_SAMPLE_INTERVAL_MS = void 0;
36
+ exports.SCENE_MEMORY_DIRNAME = exports.VIDEO_SEGMENTS_DIRNAME = exports.FACE_WATCH_DIRNAME = exports.LocalSensingClient = exports.EVIDENCE_IMAGE_REQUIRED = exports.EVIDENCE_SAMPLE_INTERVAL_MS = void 0;
37
37
  exports.alertPositiveKeys = alertPositiveKeys;
38
38
  exports.isAlertOnset = isAlertOnset;
39
39
  exports.evidenceImageReason = evidenceImageReason;
@@ -51,6 +51,7 @@ const crypto_1 = require("crypto");
51
51
  const path = __importStar(require("path"));
52
52
  const dataDir_1 = require("./dataDir");
53
53
  const VideoSegmentUploader_1 = require("./VideoSegmentUploader");
54
+ const FaceWatchLane_1 = require("./FaceWatchLane");
54
55
  const AudienceAnalyzeClient_1 = require("./AudienceAnalyzeClient");
55
56
  const LiteRtVlmProvider_1 = require("./LiteRtVlmProvider");
56
57
  const analyzeCostObserver_1 = require("./analyzeCostObserver");
@@ -59,6 +60,7 @@ const ProfileReviewWork_1 = require("./ProfileReviewWork");
59
60
  const DetectorFieldProducer_1 = require("./DetectorFieldProducer");
60
61
  const SensingProfileClient_1 = require("./SensingProfileClient");
61
62
  const NativeReadiness_1 = require("./NativeReadiness");
63
+ const detectorEndpointState_1 = require("./detectorEndpointState");
62
64
  const detectorCountReview_1 = require("./detectorCountReview");
63
65
  const jpegFrameSize_1 = require("./jpegFrameSize");
64
66
  const ScopedVlmReview_1 = require("./ScopedVlmReview");
@@ -69,6 +71,7 @@ const PhonePersonViews_1 = require("./PhonePersonViews");
69
71
  const PhoneEmbeddingClassifier_1 = require("./PhoneEmbeddingClassifier");
70
72
  const PhoneHeldInHand_1 = require("./PhoneHeldInHand");
71
73
  const DetectorFields_1 = require("./DetectorFields");
74
+ const FaceWatchPolicy_1 = require("./FaceWatchPolicy");
72
75
  const UniformSceneStore_1 = require("./UniformSceneStore");
73
76
  const SceneMarks_1 = require("./SceneMarks");
74
77
  const CloudSensingManager_1 = require("./CloudSensingManager");
@@ -454,8 +457,19 @@ class LocalSensingClient {
454
457
  this.cachedDeclaredProfileReview = false;
455
458
  this.nativeReadyKey = '';
456
459
  this.nativeReadyUntil = 0;
460
+ /** When the current proof was actually proven: a refusal after it suspends it (plan v7 W8 item 2). */
461
+ this.nativeReadyProvenAt = 0;
457
462
  this.nativeRetryAt = 0;
458
463
  this.nativeRetryKey = '';
464
+ /**
465
+ * The key whose /ready is failing now, since when, and whether its last failure may pass on
466
+ * retry (nothing listening, reset, timeout, 503). Cleared by that key's next proof.
467
+ */
468
+ this.nativeFailKey = '';
469
+ this.nativeFailSince = 0;
470
+ this.nativeFailTransient = false;
471
+ /** A key whose bounded wait ended without a proof: its looks take the fallback at once until it is proven. */
472
+ this.nativeWaitSkipKey = '';
459
473
  this.cachedVlmFields = [];
460
474
  this.cachedCascadeArmed = false;
461
475
  /** This feed's parked-vehicle memory per gated field; losing it costs one question. */
@@ -616,6 +630,9 @@ class LocalSensingClient {
616
630
  throw Error('Declared profile review requires scoped review');
617
631
  }
618
632
  this.sceneMemory = new UniformSceneStore_1.UniformSceneStore(options.sceneMemoryFile);
633
+ this.faceWatch = options.faceWatch;
634
+ this.faceWatch?.useMemory({ get: () => this.sceneMemory.getWatchlist(),
635
+ set: memory => this.sceneMemory.setWatchlist(memory) });
619
636
  // The owner's person marks (SceneMarks.ts) ride every producer this camera builds: a detection they name
620
637
  // is not counted by person_count, person_present or any drawn area.
621
638
  this.producerOptions = { ...(options.detectorFieldProducerOptions ?? {}),
@@ -758,6 +775,8 @@ class LocalSensingClient {
758
775
  this.cachedPhonePersonViews = (0, PhonePersonViews_1.parsePhonePersonViews)(profile.phonePersonViews);
759
776
  this.cachedPhoneHeldInHand = (0, PhoneHeldInHand_1.parsePhoneHeldInHand)(profile.phoneHeldInHand);
760
777
  this.cachedDetectorFields = (0, DetectorFields_1.parseDetectorFields)(profile.detectorFields);
778
+ // The face lane matches only while this camera's profile carries its receipted face_watchlist_v1 entry.
779
+ this.faceWatch?.setMatchPolicy(this.cachedDetectorFields?.fields.find((field) => field.method === FaceWatchPolicy_1.WATCHLIST_METHOD) ?? null);
761
780
  this.cachedCascadeArmed = profile.detectorCascade?.armed === true;
762
781
  this.cachedAbsenceWatchedFields = new Set(profile.absenceWatchedFields || []);
763
782
  // Absent = unknown, and unknown keeps every photo (evidenceImageReason 'legacy').
@@ -899,11 +918,18 @@ class LocalSensingClient {
899
918
  return;
900
919
  }
901
920
  const key = JSON.stringify(request);
902
- if (this.nativeReadyKey === key && Date.now() < this.nativeReadyUntil) {
921
+ const now = Date.now();
922
+ if (this.nativeProofCurrent(key, now)) {
903
923
  this.nativeFailure = undefined;
904
924
  this.applyReviewProfile(profile);
905
925
  return;
906
926
  }
927
+ // Plan v7 W8 item 2: a detector seen working within the restart grace is restarting or
928
+ // preparing. Its failing key pauses and retries; it does not hand the box to Gemma.
929
+ if (this.nativeRestartPaused(key, now)) {
930
+ this.nativeFailure = new NativeReadiness_1.NativeReadinessError('Native readiness: the detector is restarting', 'unavailable');
931
+ return;
932
+ }
907
933
  if (profile.nativeFallback) {
908
934
  this.nativeFailure = undefined;
909
935
  this.applyReviewProfile(profile.nativeFallback);
@@ -911,6 +937,83 @@ class LocalSensingClient {
911
937
  else
912
938
  this.nativeFailure = new NativeReadiness_1.NativeReadinessError(undefined, 'unavailable');
913
939
  }
940
+ /**
941
+ * A proof from this feed's own /ready, inside its expiry, with no refused or reset connection to
942
+ * the detector since: a refusal means the process that loaded those models is gone.
943
+ */
944
+ nativeProofCurrent(key, now) {
945
+ if (this.nativeReadyKey !== key || now >= this.nativeReadyUntil)
946
+ return false;
947
+ const base = this.nativeReadinessProbe.endpointBase;
948
+ return !base || (0, detectorEndpointState_1.detectorEndpointState)(base).refusedAt <= this.nativeReadyProvenAt;
949
+ }
950
+ /**
951
+ * The restart grace (plan v7 W8 item 2): this key's /ready failed in a way that may pass on
952
+ * retry, the detector answered or proved something within NATIVE_RESTART_GRACE_MS (kept on disk
953
+ * across a connector restart), and this key has been failing for less than that. A definite
954
+ * refusal (409, 400, 500, an invalid proof) never pauses: that key takes its fallback as before.
955
+ */
956
+ nativeRestartPaused(key, now) {
957
+ const base = this.nativeReadinessProbe.endpointBase;
958
+ if (!base || this.nativeFailKey !== key || !this.nativeFailTransient)
959
+ return false;
960
+ const { goodAt } = (0, detectorEndpointState_1.detectorEndpointState)(base);
961
+ return goodAt > 0 && now - goodAt < NativeReadiness_1.NATIVE_RESTART_GRACE_MS && now - this.nativeFailSince < NativeReadiness_1.NATIVE_RESTART_GRACE_MS;
962
+ }
963
+ /** The current website profile's native key, or '' when it needs no proof (or cannot be built). */
964
+ currentNativeKey() {
965
+ if (this.invalidWebsiteProfileAuthority || this.nativeAuthorityError)
966
+ return '';
967
+ const profile = this.desiredReviewProfile;
968
+ if (!profile || !this.websiteManagedProfiles || profile.profileState === 'inactive'
969
+ || profile.nativeReadiness?.state === 'unavailable')
970
+ return '';
971
+ try {
972
+ const request = (0, NativeReadiness_1.nativeReadinessRequest)(profile);
973
+ return request ? JSON.stringify(request) : '';
974
+ }
975
+ catch {
976
+ return '';
977
+ }
978
+ }
979
+ startNativeProbe(key, request) {
980
+ if (this.nativePending?.key === key)
981
+ return this.nativePending.promise;
982
+ if (this.nativeRetryKey === key && Date.now() < this.nativeRetryAt)
983
+ return undefined;
984
+ const pending = { key, promise: Promise.resolve() };
985
+ pending.promise = this.nativeReadinessProbe(request).then(until => {
986
+ if (this.nativePending !== pending)
987
+ return;
988
+ const now = Date.now(), known = typeof until === 'number' && Number.isFinite(until);
989
+ this.nativeReadyKey = key;
990
+ this.nativeReadyUntil = known ? until : now + NativeReadiness_1.NATIVE_READINESS_TTL_MS;
991
+ // A coalesced proof was made when its expiry says, not when this feed heard of it.
992
+ this.nativeReadyProvenAt = known ? Math.min(now, until - NativeReadiness_1.NATIVE_READINESS_TTL_MS) : now;
993
+ if (this.nativeFailKey === key)
994
+ this.nativeFailKey = '';
995
+ if (this.nativeWaitSkipKey === key)
996
+ this.nativeWaitSkipKey = '';
997
+ }, error => {
998
+ if (this.nativePending !== pending)
999
+ return;
1000
+ const now = Date.now();
1001
+ this.nativeRetryKey = key;
1002
+ this.nativeRetryAt = now + 1000;
1003
+ if (this.nativeFailKey !== key) {
1004
+ this.nativeFailKey = key;
1005
+ this.nativeFailSince = now;
1006
+ }
1007
+ this.nativeFailTransient = error?.transient === true;
1008
+ }).finally(() => {
1009
+ if (this.nativePending === pending)
1010
+ this.nativePending = undefined;
1011
+ // A delayed proof may select only the CURRENT profile, never a preceding policy.
1012
+ this.selectCaptureProfile();
1013
+ });
1014
+ this.nativePending = pending;
1015
+ return pending.promise;
1016
+ }
914
1017
  async prepareNativeCapture() {
915
1018
  if (this.invalidWebsiteProfileAuthority || this.nativeAuthorityError)
916
1019
  return;
@@ -926,34 +1029,107 @@ class LocalSensingClient {
926
1029
  // A current proof is renewed in its last NATIVE_READINESS_RENEW_MS, in the background, by
927
1030
  // the next look: a lapse between two looks paused new evidence (and parked the feed on the
928
1031
  // health heartbeat) although the detector was ready throughout. A failed renewal proves
929
- // nothing new, so it revokes nothing: the current proof still lapses at its own expiry.
930
- const proven = this.nativeReadyKey === key && Date.now() < this.nativeReadyUntil;
931
- if (proven && Date.now() < this.nativeReadyUntil - NativeReadiness_1.NATIVE_READINESS_RENEW_MS)
1032
+ // nothing new, so it revokes nothing: the current proof still lapses at its own expiry
1033
+ // (or at a refused connection, which means the detector process went away).
1034
+ const now = Date.now();
1035
+ const proven = this.nativeProofCurrent(key, now);
1036
+ if (proven && now < this.nativeReadyUntil - NativeReadiness_1.NATIVE_READINESS_RENEW_MS)
932
1037
  return;
933
- if (!this.nativePending || this.nativePending.key !== key) {
934
- if (this.nativeRetryKey === key && Date.now() < this.nativeRetryAt)
935
- return;
936
- const pending = { key, promise: Promise.resolve() };
937
- pending.promise = this.nativeReadinessProbe(request).then(until => {
938
- if (this.nativePending === pending) {
939
- this.nativeReadyKey = key;
940
- this.nativeReadyUntil = typeof until === 'number' && Number.isFinite(until) ? until : Date.now() + NativeReadiness_1.NATIVE_READINESS_TTL_MS;
941
- }
942
- }, () => { if (this.nativePending === pending) {
943
- this.nativeRetryKey = key;
944
- this.nativeRetryAt = Date.now() + 1000;
945
- } }).finally(() => {
946
- if (this.nativePending === pending)
947
- this.nativePending = undefined;
948
- // A delayed proof may select only the CURRENT profile, never a preceding policy.
949
- this.selectCaptureProfile();
950
- });
951
- this.nativePending = pending;
1038
+ const pending = this.startNativeProbe(key, request);
1039
+ // A current proof never waits for its renewal. A valid authorized Gemma projection never
1040
+ // waits for a cold native session here; a look waits, bounded, in awaitNativeProof. A feed
1041
+ // paused for a detector restart waits, so its retry resolves on the proof.
1042
+ if (!proven && (!profile.nativeFallback || this.nativeRestartPaused(key, now)))
1043
+ await pending;
1044
+ }
1045
+ /**
1046
+ * Plan v7 W8 item 2, called by a look before it captures. A proof that is not current (or
1047
+ * lapses within 2 s) is re-proven by a real /ready, waiting at most NATIVE_PROOF_WAIT_MS:
1048
+ * a 16.5 s gap between looks, or the first look after start, no longer hands the look to
1049
+ * Gemma. Undefined when there is nothing to wait for (no microtask hop on the common path).
1050
+ * Never rejects. A wait that ends without a proof, on a key that is not paused for a
1051
+ * detector restart, lets later looks take the fallback at once until the key is proven.
1052
+ */
1053
+ awaitNativeProof() {
1054
+ const key = this.currentNativeKey();
1055
+ if (!key || this.nativeWaitSkipKey === key)
1056
+ return undefined;
1057
+ const now = Date.now();
1058
+ if (this.nativeProofCurrent(key, now) && now < this.nativeReadyUntil - 2000)
1059
+ return undefined;
1060
+ // A paused key belongs to the feed's own 2 s retry, not to a look.
1061
+ if (this.nativeRestartPaused(key, now))
1062
+ return undefined;
1063
+ let request;
1064
+ try {
1065
+ request = (0, NativeReadiness_1.nativeReadinessRequest)(this.desiredReviewProfile);
952
1066
  }
953
- // A current proof never waits for its renewal. A valid authorized Gemma
954
- // projection never waits for a cold native session.
955
- if (!proven && !profile.nativeFallback)
956
- await this.nativePending?.promise;
1067
+ catch {
1068
+ return undefined;
1069
+ }
1070
+ if (!request)
1071
+ return undefined;
1072
+ const pending = this.startNativeProbe(key, request);
1073
+ if (!pending)
1074
+ return undefined;
1075
+ return new Promise(resolve => {
1076
+ let done = false;
1077
+ const finish = () => {
1078
+ if (done)
1079
+ return;
1080
+ done = true;
1081
+ clearTimeout(timer);
1082
+ const at = Date.now();
1083
+ if (!this.nativeProofCurrent(key, at) && !this.nativeRestartPaused(key, at))
1084
+ this.nativeWaitSkipKey = key;
1085
+ resolve();
1086
+ };
1087
+ const timer = setTimeout(finish, NativeReadiness_1.NATIVE_PROOF_WAIT_MS);
1088
+ timer.unref?.();
1089
+ pending.then(finish, finish);
1090
+ });
1091
+ }
1092
+ /**
1093
+ * True while this feed waits out a detector restart (plan v7 W8 item 2): keep its camera
1094
+ * session live and retry every 2 s, so its first look follows the detector's first answer.
1095
+ */
1096
+ isNativePaused() {
1097
+ const key = this.currentNativeKey();
1098
+ const now = Date.now();
1099
+ return !!key && !this.nativeProofCurrent(key, now) && this.nativeRestartPaused(key, now);
1100
+ }
1101
+ /**
1102
+ * True while this feed's native key has no current proof because the detector is not answering
1103
+ * (refused, reset, timed out or 503: a failure that may pass on retry), inside the restart grace
1104
+ * or after it. The camera wants its looks and the local detector is not giving them, so its
1105
+ * health says `waiting_for_capacity`, not `idle`: the look-stall sweep then judges a detector
1106
+ * that hangs past the grace (a native-only alert camera has no Gemma fallback, so it simply stops
1107
+ * looking) as a camera trying to review, the case a box restart can help. A definite refusal
1108
+ * (409, 400, 500, an invalid proof) stays `idle`, as before.
1109
+ */
1110
+ isNativeDetectorDown() {
1111
+ const key = this.currentNativeKey();
1112
+ return !!key && this.nativeFailKey === key && this.nativeFailTransient && !this.nativeProofCurrent(key, Date.now());
1113
+ }
1114
+ /**
1115
+ * Plan v7 W8 (Windows field run 44153992974, 15 Gemma calls in a swap): a look checks its proof
1116
+ * (awaitNativeProof) before it captures, but the proof can lapse, or be revoked by a refused
1117
+ * connection another feed saw, while the frame is read. When the look then takes its contract,
1118
+ * selectCaptureProfile finds this feed's proven key without a current proof and without a failure
1119
+ * of its own, and hands the look the Gemma fallback. On a proven key the fallback is a look's only
1120
+ * when it was earned: this key failed and is not paused (a definite refusal, or failing past the
1121
+ * restart grace), or a look's bounded wait ended without a proof outside a restart pause.
1122
+ * Otherwise this one look is skipped, as a detector-only camera's is, and the next re-proves the
1123
+ * key before it captures. A key never proven keeps its authorized fallback while its first
1124
+ * preparation is pending, as before.
1125
+ */
1126
+ unearnedNativeFallback() {
1127
+ const key = this.currentNativeKey();
1128
+ if (!key || !this.desiredReviewProfile?.nativeFallback || this.nativeReadyKey !== key)
1129
+ return undefined;
1130
+ if (this.nativeFailKey === key || this.nativeWaitSkipKey === key || this.nativeProofCurrent(key, Date.now()))
1131
+ return undefined;
1132
+ return new NativeReadiness_1.NativeReadinessError('Native readiness: re-proving the detector before this look', 'unavailable');
957
1133
  }
958
1134
  /**
959
1135
  * What the on-device runtime resolved about this host's accelerator (which
@@ -1017,7 +1193,16 @@ class LocalSensingClient {
1017
1193
  /** Explicit inactivity or invalid current native authority pauses new model work. */
1018
1194
  isReviewActive() {
1019
1195
  this.selectCaptureProfile();
1020
- return !this.invalidWebsiteProfileAuthority && !this.nativeAuthorityError && !this.nativeFailure && this.reviewProfileState !== 'inactive';
1196
+ return !this.invalidWebsiteProfileAuthority && !this.nativeAuthorityError && (!this.nativeFailure || this.nativeReprovable()) && this.reviewProfileState !== 'inactive';
1197
+ }
1198
+ /**
1199
+ * A detector-only key whose proof lapsed without its /ready failing: still active, because the
1200
+ * next look re-proves it before capturing (awaitNativeProof). Parking it on a lapse cost a
1201
+ * camera-health heartbeat although the detector was ready throughout.
1202
+ */
1203
+ nativeReprovable() {
1204
+ const key = this.currentNativeKey();
1205
+ return !!key && this.nativeFailKey !== key && this.nativeFailure?.kind === 'unavailable';
1021
1206
  }
1022
1207
  usesWebsiteProfile() {
1023
1208
  return this.websiteManagedProfiles && this.reviewProfileState === 'active';
@@ -1037,6 +1222,10 @@ class LocalSensingClient {
1037
1222
  .filter(field => field.derivation?.relation_kind === 'zone_count').map(field => field.field));
1038
1223
  return [...this.cachedAlertFocusRegions.keys()].filter(field => !detectorOwned.has(field)).length;
1039
1224
  }
1225
+ /** The face lane holds an announcement no look has taken yet: this camera's next look jumps the round. */
1226
+ urgentLookDue(nowMs) {
1227
+ return this.faceWatch?.hasPendingAnnouncement(nowMs) ? 'watchlist_match' : null;
1228
+ }
1040
1229
  captureReviewContext() {
1041
1230
  void this.prepareReview().catch(() => { });
1042
1231
  if (this.invalidWebsiteProfileAuthority)
@@ -1046,6 +1235,9 @@ class LocalSensingClient {
1046
1235
  this.selectCaptureProfile();
1047
1236
  if (this.nativeFailure)
1048
1237
  throw this.nativeFailure;
1238
+ const unearned = this.unearnedNativeFallback();
1239
+ if (unearned)
1240
+ throw unearned;
1049
1241
  const selected = this.cachedModelSelection && !('invalid' in this.cachedModelSelection) ? this.cachedModelSelection : null;
1050
1242
  const actorTasks = (0, ActorActionProducer_1.hasSelectedActorActions)(selected);
1051
1243
  const actorOnly = actorTasks && !selected.models.some(model => model.format === 'litert-lm');
@@ -1419,6 +1611,7 @@ class LocalSensingClient {
1419
1611
  let unavailableFields;
1420
1612
  let detectorProduced = null;
1421
1613
  let nativeProduced;
1614
+ let watchlistMatch;
1422
1615
  const reviewVlm = async () => {
1423
1616
  if (scopedReview) {
1424
1617
  const scoped = await (0, ScopedVlmReview_1.reviewScopedVlm)({ jpeg: request.jpeg, schema, contract: scopedReview,
@@ -1435,6 +1628,7 @@ class LocalSensingClient {
1435
1628
  setVehicles: (field, memory) => this.sceneMemory.setVehicles(field, memory),
1436
1629
  marks: family => this.sceneMemory.marks(family) },
1437
1630
  ...(scopedReview.detectorFields ? { detectFields, capturedAtMs,
1631
+ takeWatchlistAnnouncement: (_field, method, at) => this.faceWatch?.take(method, at),
1438
1632
  gateMemory: { get: (field) => this.vehicleGateMemory.get(field),
1439
1633
  set: (field, memory) => { this.vehicleGateMemory.set(field, memory); } },
1440
1634
  orientVehicles: (jpeg, method, boxes) => this.vehicleOrienter(jpeg, {
@@ -1462,6 +1656,10 @@ class LocalSensingClient {
1462
1656
  scopeReviews = scoped.traces;
1463
1657
  if (Object.keys(scoped.unavailable).length)
1464
1658
  unavailableFields = scoped.unavailable;
1659
+ // One watchlist question per camera: its match (if the look took one) is the upload's watchlistMatch.
1660
+ const watched = scoped.watchlistMatches ? Object.values(scoped.watchlistMatches)[0] : undefined;
1661
+ if (watched)
1662
+ watchlistMatch = watched;
1465
1663
  // A question the box decided natively (detector fields, a held phone)
1466
1664
  // is the detector's answer: ingest stamps it local_detector with the model id.
1467
1665
  const producers = (0, ScopedVlmReview_1.nativeAnswerProducers)(scopedReview, scoped.traces);
@@ -1613,6 +1811,7 @@ class LocalSensingClient {
1613
1811
  saved = {
1614
1812
  version: 1, structured, detectorProduced, analyzeMs, promptText,
1615
1813
  ...(detectorCauses ? { detectorCauses } : {}),
1814
+ ...(watchlistMatch ? { watchlistMatch } : {}),
1616
1815
  ...(actorProduction ?? {}),
1617
1816
  reviewedAtMs: Date.now(), evidenceSha256,
1618
1817
  ...(selection ? { runtimeSelectionSha256: (0, ProfileReviewWork_1.reviewContextHash)(context) } : {}),
@@ -1733,6 +1932,9 @@ class LocalSensingClient {
1733
1932
  localInferenceTrace: { ...(0, LocalInferenceTrace_1.localInferenceTrace)(saved, context?.scopedVlmReview?.detectorFields),
1734
1933
  // Plan v7 W8: the capture, look-reuse, detector-engine and clock facts of this look.
1735
1934
  pipeline: (0, pipelineSwitches_1.pipelineTrace)(this.feedName, request.lookReuse) },
1935
+ // The watchlist match the look took (plan v7 T1): the person, the strength, today's face.
1936
+ ...(review && saved.watchlistMatch && saved.structured[FaceWatchPolicy_1.WATCHLIST_FIELD] === true
1937
+ ? { watchlistMatch: saved.watchlistMatch } : {}),
1736
1938
  // The boxes behind each box-decided yes, so the owner's mark on its alert can be learned (SceneMarks.ts).
1737
1939
  ...(review && (0, SceneMarks_1.readSceneCauses)(saved.detectorCauses) ? { detectorCauses: { version: 1,
1738
1940
  fields: (0, SceneMarks_1.readSceneCauses)(saved.detectorCauses) } } : {}),
@@ -1871,6 +2073,8 @@ function persistentStreamDemandBySource(feeds) {
1871
2073
  }
1872
2074
  return demand;
1873
2075
  }
2076
+ /** Under the connector's data root: one directory per camera with face capture (sightings, gallery cache). */
2077
+ exports.FACE_WATCH_DIRNAME = 'face-watch';
1874
2078
  /** Under the connector's data root: one directory per recording feed. */
1875
2079
  exports.VIDEO_SEGMENTS_DIRNAME = 'video-segments';
1876
2080
  /** Each feed's uniform_colour_absence_v2 scene memory, one file per feed (UniformSceneStore). */
@@ -2005,11 +2209,17 @@ function buildLocalSensingLoops(config, deps) {
2005
2209
  */
2006
2210
  // Plan v7 W8: start from the pipeline switches this box last saw, before any feed is built.
2007
2211
  (0, pipelineSwitches_1.restorePipelineSwitches)((0, dataDir_1.resolveDataDir)(config.dataDir));
2212
+ // Plan v7 W8 item 2: a connector restarted in the middle of a detector swap still knows the detector worked.
2213
+ (0, detectorEndpointState_1.restoreDetectorEndpointState)((0, dataDir_1.resolveDataDir)(config.dataDir));
2008
2214
  const videoRoot = path.join((0, dataDir_1.resolveDataDir)(config.dataDir), exports.VIDEO_SEGMENTS_DIRNAME);
2009
2215
  const recordingFeedByUrl = new Map();
2010
2216
  /** The recorder of each feed that records: an alert-supporting review hands it its receipt. */
2011
2217
  const recorderByFeed = new Map();
2012
2218
  const attachVideo = deps?.videoRecorderFactory === undefined ? VideoSegmentUploader_1.attachCctvVideoRecorder : deps.videoRecorderFactory;
2219
+ const attachFace = deps?.faceWatchFactory === undefined ? FaceWatchLane_1.attachFaceWatch : deps.faceWatchFactory;
2220
+ const faceRoot = path.join((0, dataDir_1.resolveDataDir)(config.dataDir), exports.FACE_WATCH_DIRNAME);
2221
+ /** Each crop-less camera feed's face lane: its look takes the lane's announcements. */
2222
+ const faceWatchByFeed = new Map();
2013
2223
  const reviewOptions = config.cloudSensing?.candidateBuffer?.continuousReview;
2014
2224
  const retainedApiBaseUrl = (0, continuousReview_1.retainedReviewApiBase)(reviewOptions, config.apiBaseUrl);
2015
2225
  const rtspFactory = deps?.rtspProviderFactory ??
@@ -2063,6 +2273,8 @@ function buildLocalSensingLoops(config, deps) {
2063
2273
  // and each of this feed's looks reports how its frame was made.
2064
2274
  (0, pipelineSwitches_1.bindCapturePipeline)(feed.name, provider);
2065
2275
  const urlKey = recordingUrlKey(feed.rtspUrl);
2276
+ // The camera's main-stream owner (its recorder's MainStreamRing): the one session the face lane rides.
2277
+ let mainStream = null;
2066
2278
  if (attachVideo && !feed.crop && urlKey !== null && !recordingFeedByUrl.has(urlKey)) {
2067
2279
  // Recording is an addition to a feed, never a condition of it: a
2068
2280
  // recorder that cannot be built leaves the feed sensing exactly as before.
@@ -2087,14 +2299,34 @@ function buildLocalSensingLoops(config, deps) {
2087
2299
  rtspUrl: feed.rtspUrl,
2088
2300
  ...(feed.transport ? { transport: feed.transport } : {}),
2089
2301
  });
2090
- if (recorder && typeof recorder === 'object')
2302
+ if (recorder && typeof recorder === 'object') {
2091
2303
  recorderByFeed.set(feed.name, recorder);
2304
+ const owner = recorder.mainStreamRing;
2305
+ mainStream = typeof owner === 'function' ? owner.call(recorder) ?? null : null;
2306
+ }
2092
2307
  recordingFeedByUrl.set(urlKey, feed.name);
2093
2308
  }
2094
2309
  catch (err) {
2095
2310
  console.warn(`[video] ${feed.name}: recording not attached: ${err instanceof Error ? err.message : String(err)}`);
2096
2311
  }
2097
2312
  }
2313
+ // The face lane is an addition to a camera feed, never a condition of it (plan v7 T1): when the camera's face
2314
+ // capture is on it adds a face-zone output to the camera's ONE main-stream session (its recorder's, shared with
2315
+ // the probe and any ring recording; never a pull of its own), and a lane that cannot be built leaves the feed
2316
+ // sensing exactly as before. A mosaic tile is a crop of a composite, not a camera with a face zone.
2317
+ if (attachFace && !feed.crop && feed.deviceToken) {
2318
+ try {
2319
+ const lane = attachFace({ feedName: feed.name, rtspUrl: feed.rtspUrl, mainStream, apiBaseUrl: config.apiBaseUrl,
2320
+ deviceToken: feed.deviceToken, dir: path.join(faceRoot, videoFeedKey(feed)), pollMs: DEFAULT_PROFILE_TTL_MS,
2321
+ ...(deps?.detectorFieldProducerOptions?.baseUrl ? { detectorBaseUrl: deps.detectorFieldProducerOptions.baseUrl } : {}),
2322
+ ...(deps?.httpPoster ? { httpPoster: deps.httpPoster } : {}) });
2323
+ if (lane)
2324
+ faceWatchByFeed.set(feed.name, lane);
2325
+ }
2326
+ catch (err) {
2327
+ console.warn(`[face] ${feed.name}: face lane not attached: ${err instanceof Error ? err.message : String(err)}`);
2328
+ }
2329
+ }
2098
2330
  return provider;
2099
2331
  });
2100
2332
  const localProviderFactory = deps?.localProviderFactory ??
@@ -2167,6 +2399,7 @@ function buildLocalSensingLoops(config, deps) {
2167
2399
  onAlertEvidenceAccepted: (evidenceId, opts) => recorderByFeed.get(feed.name)?.watchReceipt?.(evidenceId, opts),
2168
2400
  detectorFieldProducerOptions: deps?.detectorFieldProducerOptions,
2169
2401
  sceneMemoryFile: path.join((0, dataDir_1.resolveDataDir)(config.dataDir), exports.SCENE_MEMORY_DIRNAME, `${videoFeedKey(feed)}.json`),
2402
+ ...(faceWatchByFeed.has(feed.name) ? { faceWatch: faceWatchByFeed.get(feed.name) } : {}),
2170
2403
  detectorCounts: config.cloudSensing?.candidateBuffer?.continuousReview?.enabled === true
2171
2404
  && config.cloudSensing.candidateBuffer.continuousReview.detectorCounts === true,
2172
2405
  scopedVlmReview: config.cloudSensing?.candidateBuffer?.continuousReview?.enabled === true