@trillboards/edge-sdk 0.2.260 → 0.2.264

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 (65) hide show
  1. package/deploy/windows/ci/test-published-install.ps1 +10 -1
  2. package/dist/AlertClips.d.ts +23 -0
  3. package/dist/AlertClips.d.ts.map +1 -1
  4. package/dist/AlertClips.js +64 -3
  5. package/dist/AlertClips.js.map +1 -1
  6. package/dist/CloudSensingManager.d.ts +36 -0
  7. package/dist/CloudSensingManager.d.ts.map +1 -1
  8. package/dist/CloudSensingManager.js +147 -20
  9. package/dist/CloudSensingManager.js.map +1 -1
  10. package/dist/EdgeAgent.js +1 -1
  11. package/dist/VideoSegmentUploader.d.ts +12 -0
  12. package/dist/VideoSegmentUploader.d.ts.map +1 -1
  13. package/dist/VideoSegmentUploader.js +103 -6
  14. package/dist/VideoSegmentUploader.js.map +1 -1
  15. package/dist/autoSense.d.ts +5 -4
  16. package/dist/autoSense.d.ts.map +1 -1
  17. package/dist/autoSense.js +24 -9
  18. package/dist/autoSense.js.map +1 -1
  19. package/dist/config.d.ts +9 -0
  20. package/dist/config.d.ts.map +1 -1
  21. package/dist/config.js +15 -0
  22. package/dist/config.js.map +1 -1
  23. package/dist/diagnose.d.ts +1 -1
  24. package/dist/diagnose.js +1 -1
  25. package/dist/sensingRunMode.d.ts +8 -0
  26. package/dist/sensingRunMode.d.ts.map +1 -1
  27. package/dist/sensingRunMode.js +59 -11
  28. package/dist/sensingRunMode.js.map +1 -1
  29. package/package.json +6 -5
  30. package/retained/CapturedTheftProfile.cjs +83 -0
  31. package/retained/ExperimentalTheftConnector.cjs +392 -0
  32. package/retained/FrameTheftRuntime.cjs +111 -0
  33. package/retained/FrameTheftWorker.py +136 -0
  34. package/retained/InstalledTheftLifecycle.cjs +165 -0
  35. package/retained/InstalledTheftPackage.cjs +91 -0
  36. package/retained/LiveTheftBinding.cjs +55 -0
  37. package/retained/ObservedReviewCaseEvidence.py +188 -0
  38. package/retained/ObservedSameWristPolicy.py +205 -0
  39. package/retained/OrderedPerceptionDelivery.cjs +72 -0
  40. package/retained/PairedTheftRoute.cjs +402 -0
  41. package/retained/ReplayRpc.cjs +157 -0
  42. package/retained/RetainedCaptureClient.cjs +63 -16
  43. package/retained/SavedTheftSession.cjs +110 -0
  44. package/retained/TheftCaseContract.cjs +36 -0
  45. package/retained/TheftCaseDelivery.cjs +81 -0
  46. package/retained/TheftDeliveryPump.cjs +41 -0
  47. package/retained/TheftMovementOwner.py +234 -0
  48. package/retained/TheftReviewPolicy.cjs +8 -0
  49. package/retained/__tests__/paired-theft-manager.test.cjs +509 -0
  50. package/retained/__tests__/support/live-shelf-api.cjs +139 -0
  51. package/retained/__tests__/support/load-sdk-sources.cjs +41 -0
  52. package/retained/__tests__/support/loopback-proxy.cjs +33 -0
  53. package/retained/__tests__/support/pinned-api-loader.cjs +11 -0
  54. package/retained/__tests__/support/theft-builder.cjs +61 -0
  55. package/retained/__tests__/support/theft-packet-fixture.cjs +58 -0
  56. package/retained/__tests__/support/theft-readiness.cjs +51 -0
  57. package/retained/__tests__/test_live_theft_input.py +103 -0
  58. package/retained/__tests__/theft-case-api.test.cjs +135 -0
  59. package/retained/__tests__/theft-ci-regression.test.cjs +92 -0
  60. package/retained/__tests__/theft-config.test.cjs +84 -0
  61. package/retained/__tests__/theft-entry.test.cjs +76 -0
  62. package/retained/__tests__/theft-native-recovery.test.cjs +90 -0
  63. package/retained/__tests__/theft-readiness.test.cjs +164 -0
  64. package/retained/manager.cjs +61 -7
  65. package/retained/pilot-profile-client.cjs +4 -0
@@ -0,0 +1,205 @@
1
+ """Versioned actual-clock integration copy; original wrist geometry retained.
2
+ Frozen predecessor SHA256: 65f87e287a3766e65fccd828951cb977e46bdce3dd495457afc5f8a66a9a7dc9
3
+ """
4
+
5
+ import copy
6
+ import math
7
+
8
+ import cv2
9
+ import numpy as np
10
+ from review_case_evidence import COLLAR_ROUTE, SAME_WRIST_ROUTE, collar_approach, CAPTURE_TIMING_POLICY, observed_gap
11
+
12
+
13
+ ROUTE = SAME_WRIST_ROUTE
14
+ MAX_MS = 4000
15
+ CADENCE_MS = 500
16
+ SKELETON = {'left': (5, 7, 9, 11), 'right': (6, 8, 10, 12)}
17
+
18
+
19
+ def chest_position(points, side):
20
+ shoulder, _, wrist, hip = SKELETON[side]
21
+ top = np.asarray(points[shoulder][:2], dtype=float)
22
+ down = np.asarray(points[hip][:2], dtype=float) - top
23
+ length = float(np.linalg.norm(down))
24
+ if length < 1:
25
+ return None
26
+ axis = down / length
27
+ cross = np.asarray((-axis[1], axis[0]))
28
+ center = (np.asarray(points[5][:2]) + np.asarray(points[6][:2])) / 2
29
+ span = max(float(np.linalg.norm(np.asarray(points[5][:2]) - points[6][:2])), .30 * length)
30
+ hand = np.asarray(points[wrist][:2], dtype=float)
31
+ return [float(np.dot(hand - top, axis) / length),
32
+ float(np.dot(hand - center, cross) / span)]
33
+
34
+
35
+ def trail_decision(trail):
36
+ """Return a suffix beginning at the last observed stock departure."""
37
+ if not trail or trail[-1]['stock']:
38
+ return 'at_stock_or_no_visible_wrist', []
39
+ last = trail[-1]
40
+ if not last['chest']:
41
+ return 'wrist_outside_chest', []
42
+ origin = next((i for i in range(len(trail) - 2, -1, -1) if trail[i]['stock']), None)
43
+ if origin is None:
44
+ return 'no_continuous_same_wrist_stock_origin', []
45
+ segment = trail[origin:]
46
+ if (last['clock'] - segment[0]['clock'] > MAX_MS
47
+ or any(not observed_gap(a['clock'], b['clock']) for a, b in zip(segment, segment[1:]))):
48
+ return 'wrist_path_gap_or_expired', []
49
+ if last['clock'] - segment[0]['clock'] < CAPTURE_TIMING_POLICY['minimumSpanMs']:
50
+ return 'wrist_path_below_existing_minimum_span', []
51
+ if segment[0]['chest']:
52
+ return 'wrist_already_in_chest_at_stock_origin', []
53
+ # A direct jump between shelf and chest can come from overlapping zones or
54
+ # a pose change. Require an original showing the wrist clear of both zones.
55
+ if len(segment) < 3:
56
+ return 'wrist_departure_between_stock_and_chest_unobserved', []
57
+ if any(row['chest'] for row in segment[1:-1]):
58
+ return 'wrist_already_reached_chest', []
59
+ # Require approach relative to the torso, even when the entire person moves.
60
+ start_depth, start_lateral = segment[0]['torso']
61
+ end_depth, end_lateral = last['torso']
62
+ approach = math.hypot(start_depth - .30, start_lateral) - math.hypot(end_depth - .30, end_lateral)
63
+ if approach < .12:
64
+ return 'wrist_did_not_approach_torso', []
65
+ return ROUTE, segment
66
+
67
+
68
+ class SameWristLab:
69
+ capture_timing_policy = CAPTURE_TIMING_POLICY
70
+
71
+ def __init__(self, movement, policy, *, collar_enabled=False):
72
+ self.movement = movement
73
+ self.policy = policy
74
+ self.collar_enabled = collar_enabled
75
+ self.trails = {}
76
+ self.last_cue = {}
77
+ width, height = movement.environment['frameSize']
78
+ self.size = [width, height]
79
+ self.polygons = []
80
+ for region in movement.environment['regions']:
81
+ shape = region['region']
82
+ if 'points' in shape:
83
+ points = [(p['x'], p['y']) for p in shape['points']]
84
+ else:
85
+ x, y, w, h = (shape[k] for k in ('x', 'y', 'width', 'height'))
86
+ points = [(x, y), (x+w, y), (x+w, y+h), (x, y+h)]
87
+ self.polygons.append((region['id'], np.array([(x*width, y*height) for x, y in points], np.float32)))
88
+
89
+ def _stock(self, wrist, elbow, radius):
90
+ # The distal edge of the measured wrist region may reach the polygon
91
+ # while the joint centre remains a few pixels outside it.
92
+ axis = np.asarray(wrist) - elbow
93
+ norm = float(np.linalg.norm(axis))
94
+ distal = tuple(float(x) for x in (wrist + axis * (radius / norm))) if norm > 0 else tuple(wrist)
95
+ return [name for name, polygon in self.polygons
96
+ if any(cv2.pointPolygonTest(polygon, point, False) >= 0 for point in (tuple(wrist), distal))]
97
+
98
+ def _window(self, actor, side, trail, route):
99
+ original_rows = [entry['row'] for entry in trail]
100
+ proofs = []
101
+ for a, b in zip(original_rows, original_rows[1:]):
102
+ pair = self.policy.qualify_arm_window([a, b], actor, side, self.size)
103
+ if not pair['qualified']:
104
+ return None, pair['reason']
105
+ proofs.append(pair['proof'])
106
+ proof = copy.deepcopy(proofs[0])
107
+ originals = [self.policy._ref(row['frame']) for row in original_rows]
108
+ indices = [frame['sourceIndex'] for frame in originals]
109
+ proof.update(originals=originals, motionSourceIndices=indices, supportSourceIndices=indices,
110
+ frameQualifications=[proofs[0]['frameQualifications'][0]]
111
+ + [pair['frameQualifications'][1] for pair in proofs],
112
+ warpQualifications=[warp for pair in proofs for warp in pair['warpQualifications']])
113
+ path_keys = ('clock', 'wrist', 'torso', 'stock', 'chest')
114
+ if route == COLLAR_ROUTE:
115
+ path_keys += ('armApproachSupported',)
116
+ return {
117
+ 'actorHypothesis': actor, 'side': side, 'reason': self.policy.SUPPORTED,
118
+ 'fromClock': trail[0]['clock'], 'toClock': trail[-1]['clock'],
119
+ 'spanMs': trail[-1]['clock'] - trail[0]['clock'],
120
+ 'armAreaEligibility': {'qualified': True, 'reason': 'registered_adjacent_wrist_path'},
121
+ 'armAreaQualification': proof,
122
+ 'movementConfirmation': {
123
+ 'route': route,
124
+ 'stockOriginEvidence': {'route': route, 'stockRegionIds': trail[0]['stock']},
125
+ 'wristPath': [{k: entry[k] for k in path_keys}
126
+ for entry in trail],
127
+ 'supplementalOriginalFrameReferences': [],
128
+ 'allSupplementalWitnessPicturesRequiredForHumanReview': True,
129
+ },
130
+ }, route
131
+
132
+ def observe(self, record):
133
+ frame, camera, raw = (record[key] for key in ('frame', 'camera', 'row'))
134
+ clock = frame['capturedAtMs']
135
+ row = {'frame': frame, 'clock': clock, 'people': {p['track_id']: p for p in record['people']},
136
+ **{key: camera.get(key) for key in ('guard', 'trackerResetDiagnostic', 'resetMovementEvidence',
137
+ 'backgroundRegistration')}}
138
+ observed = {p['track_id']: p for p in record['actualObservedPeople']}
139
+ previous = self.trails
140
+ if row['guard'] != 'stable_hypothesis' or row['trackerResetDiagnostic'] is not False or row['resetMovementEvidence']:
141
+ previous = {}
142
+ self.last_cue.clear()
143
+ self.last_cue = {actor: at for actor, at in self.last_cue.items() if clock - at < 90_000}
144
+ self.trails = {}
145
+ baselines = {actor['actorHypothesis']: actor['allObservedArmWindows'] for actor in raw['actors']}
146
+ old_cues = [{'side': cue['side'], 'actor': cue['trackHypothesis'],
147
+ 'route': cue['support']['movementConfirmation']['stockOriginEvidence']['route'],
148
+ 'first': cue['support']['fromClock']}
149
+ for cue in raw['cues']]
150
+ actors, cues, decisions = [], [], []
151
+ for actor, person in observed.items():
152
+ passed = []
153
+ points = person['keypoints']
154
+ for side, (_, elbow, wrist, _) in SKELETON.items():
155
+ gate = self.policy.qualify_arm_frame(row, actor, side, self.size)
156
+ log = {'actor': actor, 'side': side, 'reason': gate['reason'],
157
+ 'baselineReasons': sorted({arm['reason'] for arm in baselines.get(actor, []) if arm['side'] == side})}
158
+ decisions.append(log)
159
+ if len(points) == 17:
160
+ log['wrist'] = points[wrist]
161
+ if not gate['qualified']:
162
+ continue
163
+ torso = chest_position(points, side)
164
+ if torso is None:
165
+ log['reason'] = 'torso_axis_unavailable'
166
+ continue
167
+ position = points[wrist][:2]
168
+ frame_proof, = gate['proof']['frameQualifications']
169
+ stock = self._stock(position, np.asarray(points[elbow][:2]), frame_proof['existingArmRadiusPixels'])
170
+ chest = -.12 <= torso[0] <= .65 and abs(torso[1]) <= .72
171
+ item = {'clock': clock, 'wrist': position, 'torso': torso, 'stock': stock, 'chest': chest, 'row': row}
172
+ if self.collar_enabled:
173
+ item['armApproachSupported'] = self.policy.SUPPORTED in log['baselineReasons']
174
+ history = previous.get((actor, side), [])
175
+ if history and (not observed_gap(history[-1]['clock'], clock)
176
+ or math.dist(torso, history[-1]['torso']) > 1.35):
177
+ history = []
178
+ log['continuityBreak'] = True
179
+ trail = [entry for entry in history if clock - entry['clock'] <= MAX_MS] + [item]
180
+ self.trails[(actor, side)] = trail
181
+ reason, segment = trail_decision(trail)
182
+ if self.collar_enabled and reason == 'wrist_outside_chest' and len(trail) >= 3:
183
+ origin = next((i for i in range(len(trail) - 3, -1, -1) if trail[i]['stock']), None)
184
+ if origin is not None and collar_approach(trail[origin:]):
185
+ reason, segment = COLLAR_ROUTE, trail[origin:]
186
+ log.update(reason=reason, torso=torso, stock=stock, chest=chest)
187
+ if segment:
188
+ window, reason = self._window(actor, side, segment, reason)
189
+ log.update(reason=reason, sourceIndices=[x['row']['frame']['sourceIndex'] for x in segment])
190
+ if window is not None:
191
+ passed.append(window)
192
+ actors.append({'actorHypothesis': actor, 'allObservedArmWindows': passed})
193
+ if passed and actor not in self.last_cue:
194
+ window = min(passed, key=lambda value: (
195
+ value['movementConfirmation']['route'] != ROUTE, value['spanMs'], value['side']))
196
+ cue = {'policyVersion': self.policy.POLICY, 'scope': self.movement.scope,
197
+ 'trackHypothesis': actor, 'side': window['side'], 'kind': 'neutral_observed_arm_motion_review',
198
+ 'message': 'Observed wrist movement from marked stock toward upper clothing. Please review.',
199
+ 'sourceFrameReferences': window['armAreaQualification']['originals'], 'support': window}
200
+ cue['id'] = self.policy.digest(cue)
201
+ cues.append(cue)
202
+ self.last_cue[actor] = clock
203
+ raw['actors'], raw['cues'] = actors, cues
204
+ return {'sourceIndex': frame['sourceIndex'], 'capturedAtMs': clock, 'cameraGuard': row['guard'],
205
+ 'wrists': decisions, 'originalRuleCues': old_cues}
@@ -0,0 +1,72 @@
1
+ 'use strict';
2
+ const assert=require('node:assert/strict');
3
+ const crypto=require('node:crypto');
4
+ const hash=value=>crypto.createHash('sha256').update(JSON.stringify(value)).digest('hex');
5
+ const id=value=>typeof value==='string'&&/^[a-zA-Z0-9][a-zA-Z0-9_.-]{0,127}$/.test(value);
6
+ const exact=(value,keys,message)=>assert(value&&typeof value==='object'&&!Array.isArray(value)
7
+ &&Object.keys(value).sort().join(',')===keys.split(',').sort().join(','),message);
8
+
9
+ function checkSink(sink){
10
+ if(sink===undefined)return;
11
+ assert(sink&&id(sink.id)&&['handlesContext','prepare','deliver'].every(k=>typeof sink[k]==='function'),
12
+ 'A complete original-perception delivery sink is required');
13
+ }
14
+ function intent(sink,context){
15
+ if(!sink)return;
16
+ const handles=sink.handlesContext(structuredClone(context));
17
+ assert(typeof handles==='boolean','Explicit captured-context delivery selection required');
18
+ return handles?{version:1,consumerId:sink.id,status:'awaiting_perception'}:undefined;
19
+ }
20
+ function pending(row){
21
+ return !!row.perceptionDelivery&&!['delivered','withheld'].includes(row.perceptionDelivery.status);
22
+ }
23
+ function withheld(row){return row.perceptionDelivery?.status==='withheld';}
24
+ function jsonPayload(value){
25
+ assert(value&&typeof value==='object'&&!Array.isArray(value),'Structured delivery payload required');
26
+ const text=JSON.stringify(value);
27
+ assert(Buffer.byteLength(text)<=8*1024*1024,'Original perception delivery payload exceeds bound; do not truncate');
28
+ const copy=JSON.parse(text);assert.deepEqual(copy,value,'Delivery payload must survive exact JSON storage');return copy;
29
+ }
30
+ function receipt(consumerId,frameId,payloadSha256){return {version:1,consumerId,frameId,payloadSha256,accepted:true};}
31
+ function checkReceipt(value,row){
32
+ const d=row.perceptionDelivery;
33
+ assert.deepEqual(value,receipt(d.consumerId,row.id,d.payloadSha256),'Exact original-frame delivery receipt required');
34
+ }
35
+ function validate(row,sink){
36
+ const d=row.perceptionDelivery;if(!d)return;
37
+ assert(d.version===1&&id(d.consumerId)&&['awaiting_perception','pending','delivered','withheld'].includes(d.status),'Invalid saved perception delivery');
38
+ if(pending(row))assert(sink&&sink.id===d.consumerId,'Pending original delivery requires the same registered consumer sink');
39
+ if(withheld(row)){
40
+ assert(row.candidate?.reviewContext?.privateTheftSession?.scope?.sourceKind==='live_shelf_review_v1'
41
+ &&d.reason==='live_shelf_profile_ended','Only ended live shelf evidence can be withheld');
42
+ exact(d,row.actorPerception?'version,consumerId,status,reason,payload,payloadSha256':'version,consumerId,status,reason',
43
+ 'Invalid withheld live evidence');
44
+ if(!row.actorPerception)return;
45
+ assert.equal(d.payloadSha256,hash(jsonPayload(d.payload)),'Withheld original handoff payload changed');
46
+ return;
47
+ }
48
+ if(d.status==='awaiting_perception'){
49
+ exact(d,'version,consumerId,status','Invalid saved delivery intent');assert(!row.actorPerception,'Delivery intent lost its original payload');return;
50
+ }
51
+ exact(d,d.status==='pending'?'version,consumerId,status,payload,payloadSha256':'version,consumerId,status,payload,payloadSha256,receipt',
52
+ 'Invalid saved perception delivery fields');
53
+ assert(row.actorPerception&&row.actorPerceptionPolicy,'Delivery has no original saved perception');
54
+ const payload=jsonPayload(d.payload);assert.equal(d.payloadSha256,hash(payload),'Saved delivery payload hash changed');
55
+ if(d.status==='delivered')checkReceipt(d.receipt,row);
56
+ }
57
+ function argumentsFor(row,input,perception){
58
+ return {record:structuredClone(row),input:{...input,jpeg:Buffer.from(input.jpeg)},perception:structuredClone(perception)};
59
+ }
60
+ function prepare(sink,row,input,perception){
61
+ validate(row,sink);assert.equal(row.perceptionDelivery.status,'awaiting_perception');
62
+ const payload=jsonPayload(sink.prepare(argumentsFor(row,input,perception)));
63
+ return {version:1,consumerId:row.perceptionDelivery.consumerId,status:'pending',payload,payloadSha256:hash(payload)};
64
+ }
65
+ async function deliver(sink,row,input,perception){
66
+ validate(row,sink);assert.equal(row.perceptionDelivery.status,'pending');
67
+ const d=row.perceptionDelivery;
68
+ const ack=await sink.deliver({...argumentsFor(row,input,perception),payload:structuredClone(d.payload),payloadSha256:d.payloadSha256});
69
+ checkReceipt(ack,row);return {...d,status:'delivered',receipt:structuredClone(ack)};
70
+ }
71
+ function errorRecord(error){return {name:error?.name??'Error',message:error?.message??String(error),code:error?.code??null,stack:error?.stack??null};}
72
+ module.exports={checkSink,intent,pending,withheld,validate,prepare,deliver,receipt,errorRecord};