@spekra.in/agent-os 0.0.0-stage → 1.0.0

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 (114) hide show
  1. package/Booker/README.md +41 -0
  2. package/Booker/package.json +11 -0
  3. package/Booker/src/agent.js +15 -0
  4. package/Booker/src/calendar-adapter.js +75 -0
  5. package/Booker/src/index.js +4 -0
  6. package/Booker/src/intake-parser.js +96 -0
  7. package/Booker/src/validation.js +34 -0
  8. package/Booker/test/booker.test.js +35 -0
  9. package/CashHound/README.md +181 -0
  10. package/CashHound/package.json +21 -0
  11. package/CashHound/src/agent.js +621 -0
  12. package/CashHound/src/bank-reconciler.js +66 -0
  13. package/CashHound/src/dunning.js +380 -0
  14. package/CashHound/src/index.js +32 -0
  15. package/CashHound/src/invoice.js +371 -0
  16. package/CashHound/src/mobile.js +35 -0
  17. package/CashHound/src/npv-optimizer.js +259 -0
  18. package/CashHound/test/advanced.test.js +44 -0
  19. package/CashHound/test/cashhound.test.js +530 -0
  20. package/CashHound/test/mobile.test.js +25 -0
  21. package/CashHound/test/security.test.js +35 -0
  22. package/Clerk/README.md +30 -0
  23. package/Clerk/package.json +11 -0
  24. package/Clerk/src/agent.js +18 -0
  25. package/Clerk/src/index.js +2 -0
  26. package/Clerk/src/reconciliation.js +52 -0
  27. package/Clerk/test/clerk.test.js +39 -0
  28. package/LocalRoar/README.md +37 -0
  29. package/LocalRoar/package.json +13 -0
  30. package/LocalRoar/src/agent.js +70 -0
  31. package/LocalRoar/src/booking-router.js +74 -0
  32. package/LocalRoar/src/feedback-interceptor.js +47 -0
  33. package/LocalRoar/src/index.js +7 -0
  34. package/LocalRoar/src/lead-engine.js +52 -0
  35. package/LocalRoar/src/mobile.js +23 -0
  36. package/LocalRoar/src/review-booster.js +24 -0
  37. package/LocalRoar/src/route-density.js +46 -0
  38. package/LocalRoar/test/advanced.test.js +41 -0
  39. package/LocalRoar/test/localroar.test.js +59 -0
  40. package/LocalRoar/test/mobile.test.js +12 -0
  41. package/OmniLife/README.md +39 -0
  42. package/OmniLife/package.json +13 -0
  43. package/OmniLife/src/agent.js +47 -0
  44. package/OmniLife/src/bill-negotiator.js +43 -0
  45. package/OmniLife/src/browser-cancel.js +28 -0
  46. package/OmniLife/src/conflict-engine.js +49 -0
  47. package/OmniLife/src/index.js +6 -0
  48. package/OmniLife/src/mobile.js +18 -0
  49. package/OmniLife/src/subscription-manager.js +66 -0
  50. package/OmniLife/test/advanced.test.js +29 -0
  51. package/OmniLife/test/mobile.test.js +12 -0
  52. package/OmniLife/test/omnilife.test.js +71 -0
  53. package/PulseMD/README.md +42 -0
  54. package/PulseMD/package.json +13 -0
  55. package/PulseMD/src/agent.js +67 -0
  56. package/PulseMD/src/ambient-scribe.js +46 -0
  57. package/PulseMD/src/auth.js +63 -0
  58. package/PulseMD/src/charting.js +54 -0
  59. package/PulseMD/src/index.js +7 -0
  60. package/PulseMD/src/mobile.js +18 -0
  61. package/PulseMD/src/prior-auth.js +39 -0
  62. package/PulseMD/src/safety-guard.js +88 -0
  63. package/PulseMD/test/advanced.test.js +50 -0
  64. package/PulseMD/test/mobile.test.js +12 -0
  65. package/PulseMD/test/pulsemd.test.js +71 -0
  66. package/README.md +203 -2
  67. package/ResolveX/README.md +274 -0
  68. package/ResolveX/package.json +20 -0
  69. package/ResolveX/src/agent.js +679 -0
  70. package/ResolveX/src/carrier-listener.js +405 -0
  71. package/ResolveX/src/diagnosis.js +315 -0
  72. package/ResolveX/src/index.js +36 -0
  73. package/ResolveX/src/mobile.js +31 -0
  74. package/ResolveX/src/policy.js +325 -0
  75. package/ResolveX/src/vision.js +384 -0
  76. package/ResolveX/test/advanced.test.js +445 -0
  77. package/ResolveX/test/mobile.test.js +15 -0
  78. package/ResolveX/test/resolvex.test.js +428 -0
  79. package/SentinelMesh/README.md +51 -0
  80. package/SentinelMesh/package.json +13 -0
  81. package/SentinelMesh/src/governor.js +61 -0
  82. package/SentinelMesh/src/index.js +4 -0
  83. package/SentinelMesh/src/mobile.js +19 -0
  84. package/SentinelMesh/src/policy.js +63 -0
  85. package/SentinelMesh/src/sandbox.js +152 -0
  86. package/SentinelMesh/test/mobile.test.js +12 -0
  87. package/SentinelMesh/test/sentinel.test.js +135 -0
  88. package/Sidekick/README.md +43 -0
  89. package/Sidekick/package.json +11 -0
  90. package/Sidekick/src/agent.js +15 -0
  91. package/Sidekick/src/evidence.js +45 -0
  92. package/Sidekick/src/index.js +3 -0
  93. package/Sidekick/src/validation.js +15 -0
  94. package/Sidekick/test/sidekick.test.js +33 -0
  95. package/agent-os-mobile/README.md +26 -0
  96. package/agent-os-mobile/src/api.js +97 -0
  97. package/agent-os-mobile/src/biometric.js +41 -0
  98. package/agent-os-mobile/src/components/ApprovalStack.js +207 -0
  99. package/agent-os-mobile/src/components/OutcomeCard.js +98 -0
  100. package/agent-os-mobile/src/memory-graph.js +114 -0
  101. package/agent-os-mobile/src/screens/CashHoundMobileScreen.js +111 -0
  102. package/agent-os-mobile/src/screens/LocalRoarMobileScreen.js +183 -0
  103. package/agent-os-mobile/src/screens/OmniLifeMobileScreen.js +111 -0
  104. package/agent-os-mobile/src/screens/PulseMDMobileScreen.js +55 -0
  105. package/agent-os-mobile/src/screens/ResolveXMobileScreen.js +96 -0
  106. package/agent-os-mobile/src/screens/SentinelMeshMobileScreen.js +199 -0
  107. package/agent-os-mobile/src/self-healer.js +104 -0
  108. package/agent-os-mobile/src/speculative-verifier.js +69 -0
  109. package/agent-os-mobile/src/spekra-bridge.js +216 -0
  110. package/agent-os-mobile/src/swarm.js +72 -0
  111. package/agent-os-mobile/src/voice.js +51 -0
  112. package/bin/agentos.js +260 -0
  113. package/package.json +51 -4
  114. package/src/index.js +91 -0
@@ -0,0 +1,445 @@
1
+ import { describe, it } from 'node:test';
2
+ import assert from 'node:assert';
3
+ import {
4
+ DamageVerifier,
5
+ DamageType,
6
+ DamageVerificationStatus,
7
+ CarrierWebhookListener,
8
+ CarrierExceptionType,
9
+ } from '../src/index.js';
10
+
11
+ describe('DamageVerifier - Computer Vision Damage Assessment', () => {
12
+ const verifier = new DamageVerifier();
13
+
14
+ it('authenticates valid cracked screen photo with genuine camera metadata', () => {
15
+ const photo = {
16
+ photoId: 'IMG-CRACK-01',
17
+ width: 1920,
18
+ height: 1080,
19
+ fileSizeBytes: 2450000,
20
+ clarityScore: 0.92,
21
+ detectedDamageTypes: [DamageType.CRACKED_SCREEN],
22
+ exif: {
23
+ deviceModel: 'iPhone 15 Pro',
24
+ timestamp: '2026-11-18T14:30:00Z',
25
+ gps: { latitude: 37.7749, longitude: -122.4194 },
26
+ software: 'iOS 18.2',
27
+ },
28
+ };
29
+
30
+ const evaluation = verifier.evaluatePhoto(photo);
31
+
32
+ assert.strictEqual(evaluation.valid, true);
33
+ assert.strictEqual(evaluation.status, DamageVerificationStatus.AUTHENTIC);
34
+ assert.ok(evaluation.confidenceScore >= 0.85, `Expected score >= 0.85, got ${evaluation.confidenceScore}`);
35
+ assert.deepStrictEqual(evaluation.detectedDamageTypes, [DamageType.CRACKED_SCREEN]);
36
+ assert.strictEqual(evaluation.details.clarityScore, 0.92);
37
+ });
38
+
39
+ it('evaluates all supported damage types: WATER_DAMAGE, SHATTERED_CASING, PHYSICAL_DEFORMATION', () => {
40
+ const damageTypes = [
41
+ DamageType.WATER_DAMAGE,
42
+ DamageType.SHATTERED_CASING,
43
+ DamageType.PHYSICAL_DEFORMATION,
44
+ ];
45
+
46
+ for (const dtype of damageTypes) {
47
+ const evaluation = verifier.evaluatePhoto({
48
+ photoId: `IMG-${dtype}`,
49
+ width: 1920,
50
+ height: 1080,
51
+ fileSizeBytes: 1800000,
52
+ clarityScore: 0.88,
53
+ detectedDamageTypes: [dtype],
54
+ exif: {
55
+ deviceModel: 'Google Pixel 9 Pro',
56
+ timestamp: '2026-11-18T10:15:00Z',
57
+ },
58
+ });
59
+
60
+ assert.strictEqual(evaluation.valid, true);
61
+ assert.strictEqual(evaluation.status, DamageVerificationStatus.AUTHENTIC);
62
+ assert.ok(evaluation.detectedDamageTypes.includes(dtype));
63
+ }
64
+ });
65
+
66
+ it('rejects unreadable photo with low clarity score (blur/out of focus)', () => {
67
+ const blurryPhoto = {
68
+ photoId: 'BLURRY-01',
69
+ width: 1920,
70
+ height: 1080,
71
+ clarityScore: 0.35, // Below 0.60 threshold
72
+ detectedDamageTypes: [DamageType.CRACKED_SCREEN],
73
+ };
74
+
75
+ const evaluation = verifier.evaluatePhoto(blurryPhoto);
76
+
77
+ assert.strictEqual(evaluation.valid, false);
78
+ assert.strictEqual(evaluation.status, DamageVerificationStatus.UNREADABLE);
79
+ assert.ok(evaluation.confidenceScore <= 0.40);
80
+ assert.ok(evaluation.reasons.some((r) => r.includes('clarity score')));
81
+ });
82
+
83
+ it('rejects low-resolution image below minimum dimension threshold', () => {
84
+ const lowResPhoto = {
85
+ photoId: 'TINY-01',
86
+ width: 320, // Below 640px threshold
87
+ height: 240,
88
+ clarityScore: 0.85,
89
+ detectedDamageTypes: [DamageType.CRACKED_SCREEN],
90
+ };
91
+
92
+ const evaluation = verifier.evaluatePhoto(lowResPhoto);
93
+
94
+ assert.strictEqual(evaluation.valid, false);
95
+ assert.strictEqual(evaluation.status, DamageVerificationStatus.UNREADABLE);
96
+ assert.ok(evaluation.reasons.some((r) => r.includes('width')));
97
+ });
98
+
99
+ it('rejects photo with no recognized physical damage types detected', () => {
100
+ const noDamagePhoto = {
101
+ photoId: 'CLEAN-01',
102
+ width: 1920,
103
+ height: 1080,
104
+ clarityScore: 0.95,
105
+ detectedDamageTypes: [],
106
+ exif: { deviceModel: 'iPhone 15' },
107
+ };
108
+
109
+ const evaluation = verifier.evaluatePhoto(noDamagePhoto);
110
+
111
+ assert.strictEqual(evaluation.valid, false);
112
+ assert.strictEqual(evaluation.status, DamageVerificationStatus.INSUFFICIENT_EVIDENCE);
113
+ assert.ok(evaluation.reasons.some((r) => r.includes('No recognized physical damage')));
114
+ });
115
+
116
+ it('detects fraudulent stock photo via URL domain, metadata flags, or watermarks', () => {
117
+ // 1. URL referencing stock agency
118
+ const stockUrlEval = verifier.evaluatePhoto({
119
+ photoId: 'STOCK-01',
120
+ width: 1920,
121
+ height: 1080,
122
+ clarityScore: 0.95,
123
+ url: 'https://images.shutterstock.com/image-photo/cracked-smart-phone-screen-600w.jpg',
124
+ detectedDamageTypes: [DamageType.CRACKED_SCREEN],
125
+ });
126
+ assert.strictEqual(stockUrlEval.valid, false);
127
+ assert.strictEqual(stockUrlEval.status, DamageVerificationStatus.FRAUDULENT);
128
+ assert.ok(stockUrlEval.confidenceScore <= 0.10);
129
+
130
+ // 2. Explicit stock photo / watermark flag
131
+ const watermarkEval = verifier.evaluatePhoto({
132
+ photoId: 'STOCK-02',
133
+ width: 1920,
134
+ height: 1080,
135
+ clarityScore: 0.90,
136
+ watermarkDetected: true,
137
+ detectedDamageTypes: [DamageType.SHATTERED_CASING],
138
+ });
139
+ assert.strictEqual(watermarkEval.valid, false);
140
+ assert.strictEqual(watermarkEval.status, DamageVerificationStatus.FRAUDULENT);
141
+
142
+ // 3. Known fraudulent hash
143
+ const fraudRepoVerifier = new DamageVerifier({
144
+ knownFraudulentHashes: ['HASH-KNOWN-FRAUD-999'],
145
+ });
146
+ const hashFraudEval = fraudRepoVerifier.evaluatePhoto({
147
+ photoId: 'FRAUD-HASH-01',
148
+ imageHash: 'HASH-KNOWN-FRAUD-999',
149
+ width: 1920,
150
+ height: 1080,
151
+ clarityScore: 0.95,
152
+ detectedDamageTypes: [DamageType.CRACKED_SCREEN],
153
+ });
154
+ assert.strictEqual(hashFraudEval.valid, false);
155
+ assert.strictEqual(hashFraudEval.status, DamageVerificationStatus.FRAUDULENT);
156
+
157
+ // 4. Manipulation software in EXIF (Photoshop / Deepfake)
158
+ const manipulatedEval = verifier.evaluatePhoto({
159
+ photoId: 'PHOTOSHOP-01',
160
+ width: 1920,
161
+ height: 1080,
162
+ clarityScore: 0.92,
163
+ detectedDamageTypes: [DamageType.CRACKED_SCREEN],
164
+ exif: {
165
+ software: 'Adobe Photoshop 2024 (Macintosh)',
166
+ },
167
+ });
168
+ assert.strictEqual(manipulatedEval.valid, false);
169
+ assert.strictEqual(manipulatedEval.status, DamageVerificationStatus.FRAUDULENT);
170
+ });
171
+
172
+ it('generates automated replacement authorization payload for genuine damage', () => {
173
+ const photo = {
174
+ photoId: 'GENUINE-REPL-01',
175
+ width: 2560,
176
+ height: 1440,
177
+ clarityScore: 0.94,
178
+ detectedDamageTypes: [DamageType.CRACKED_SCREEN],
179
+ exif: {
180
+ deviceModel: 'iPhone 15 Pro Max',
181
+ timestamp: '2026-11-18T12:00:00Z',
182
+ },
183
+ };
184
+
185
+ const evaluation = verifier.evaluatePhoto(photo);
186
+ const authorization = verifier.generateReplacementAuthorization({
187
+ evaluation,
188
+ claim: { id: 'CLM-7890' },
189
+ customer: { id: 'CUST-5541' },
190
+ item: { sku: 'PROD-SMARTPHONE-15', serialNumber: 'SN-99887766' },
191
+ });
192
+
193
+ assert.strictEqual(authorization.authorized, true);
194
+ assert.strictEqual(authorization.status, 'APPROVED');
195
+ assert.ok(authorization.authorizationCode.startsWith('AUTH-REPL-'));
196
+ assert.strictEqual(authorization.claimId, 'CLM-7890');
197
+ assert.strictEqual(authorization.customerId, 'CUST-5541');
198
+ assert.strictEqual(authorization.itemSku, 'PROD-SMARTPHONE-15');
199
+ assert.strictEqual(authorization.serialNumber, 'SN-99887766');
200
+ assert.strictEqual(authorization.replacementOrder.shippingSpeed, 'NEXT_DAY_PRIORITY');
201
+ assert.strictEqual(authorization.replacementOrder.action, 'EXPEDITED_REPLACEMENT');
202
+ assert.ok(authorization.replacementOrder.returnLabelCode.startsWith('RET-LBL-'));
203
+ });
204
+
205
+ it('refuses automated replacement authorization and flags human review for fraudulent claim', () => {
206
+ const photo = {
207
+ photoId: 'STOCK-SUSPECT',
208
+ width: 1920,
209
+ height: 1080,
210
+ clarityScore: 0.90,
211
+ isStockPhoto: true,
212
+ detectedDamageTypes: [DamageType.WATER_DAMAGE],
213
+ };
214
+
215
+ const evaluation = verifier.evaluatePhoto(photo);
216
+ const authorization = verifier.generateReplacementAuthorization({
217
+ evaluation,
218
+ claim: { id: 'CLM-FRAUD-01' },
219
+ customer: { id: 'CUST-FLAGGED' },
220
+ item: { sku: 'PROD-TABLET-01' },
221
+ });
222
+
223
+ assert.strictEqual(authorization.authorized, false);
224
+ assert.strictEqual(authorization.status, 'REJECTED_FRAUD_SUSPECTED');
225
+ assert.strictEqual(authorization.authorizationCode, null);
226
+ assert.strictEqual(authorization.replacementOrder, null);
227
+ assert.strictEqual(authorization.requiresHumanReview, true);
228
+ });
229
+
230
+ it('supports verifyDamageAndAuthorize composite pipeline', () => {
231
+ const result = verifier.verifyDamageAndAuthorize({
232
+ photo: {
233
+ width: 1920,
234
+ height: 1080,
235
+ clarityScore: 0.91,
236
+ detectedDamageTypes: [DamageType.PHYSICAL_DEFORMATION],
237
+ exif: { deviceModel: 'Pixel 8', timestamp: '2026-11-18T09:00:00Z' },
238
+ },
239
+ claim: { claimId: 'CLM-COMPOSITE-1' },
240
+ customer: { customerId: 'CUST-COMPOSITE-1' },
241
+ item: { itemSku: 'SKU-LAPTOP-X1' },
242
+ });
243
+
244
+ assert.strictEqual(result.evaluation.valid, true);
245
+ assert.strictEqual(result.authorization.authorized, true);
246
+ assert.strictEqual(result.authorization.claimId, 'CLM-COMPOSITE-1');
247
+ });
248
+ });
249
+
250
+ describe('CarrierWebhookListener - Proactive Transit Tracking & Resolution', () => {
251
+ it('detects WEATHER_EXCEPTION from FedEx and proactively dispatches trace & apology credit', () => {
252
+ const listener = new CarrierWebhookListener();
253
+
254
+ const fedexWebhook = {
255
+ carrier: 'FedEx',
256
+ trackingNumber: 'FX-9876543210',
257
+ customerId: 'CUST-1001',
258
+ orderId: 'ORD-501',
259
+ eventType: 'EXCEPTION',
260
+ exceptionCode: 'WEATHER_DELAY',
261
+ statusDescription: 'Severe blizzard in Memphis central hub causing ground shutdown',
262
+ };
263
+
264
+ const result = listener.ingestWebhook(fedexWebhook);
265
+
266
+ assert.strictEqual(result.status, 'PROACTIVE_RESOLUTION_DISPATCHED');
267
+ assert.strictEqual(result.proactiveActionTaken, true);
268
+ assert.strictEqual(result.exceptionType, CarrierExceptionType.WEATHER_EXCEPTION);
269
+ assert.strictEqual(result.carrier, 'FEDEX');
270
+ assert.strictEqual(result.trackingNumber, 'FX-9876543210');
271
+
272
+ // Verify dispatched actions
273
+ assert.strictEqual(result.dispatchedActions.length, 2);
274
+ const traceAction = result.dispatchedActions.find((a) => a.actionType === 'PRIORITY_CARRIER_TRACE');
275
+ const creditAction = result.dispatchedActions.find((a) => a.actionType === 'PROACTIVE_LOYALTY_CREDIT');
276
+
277
+ assert.ok(traceAction, 'Expected priority carrier trace action');
278
+ assert.strictEqual(traceAction.priority, 'EXPEDITED_CRITICAL');
279
+ assert.ok(traceAction.traceTicketId.startsWith('TRACE-FEDEX-'));
280
+
281
+ assert.ok(creditAction, 'Expected proactive loyalty credit action');
282
+ assert.strictEqual(creditAction.amount, 15.0); // Base weather credit
283
+ assert.strictEqual(creditAction.customerId, 'CUST-1001');
284
+
285
+ // Verify pre-emptive ticket created before customer ticket
286
+ assert.strictEqual(result.proactiveIncident.beforeCustomerTicketFiled, true);
287
+ assert.ok(result.proactiveIncident.customerNotification.message.includes('credited $15.00'));
288
+ });
289
+
290
+ it('detects TRANSIT_STALL_48H from UPS and proactively dispatches trace & loyalty credit', () => {
291
+ const listener = new CarrierWebhookListener();
292
+
293
+ const upsWebhook = {
294
+ carrier: 'UPS',
295
+ trackingNumber: '1Z9999999999999999',
296
+ customerId: 'CUST-1002',
297
+ eventType: 'STATUS_UPDATE',
298
+ eventCode: 'TRANSIT_STALL_48H',
299
+ stallHours: 54,
300
+ details: 'Package stationary at Hodgkins facility for 54 hours without departure scan',
301
+ };
302
+
303
+ const result = listener.ingestWebhook(upsWebhook);
304
+
305
+ assert.strictEqual(result.status, 'PROACTIVE_RESOLUTION_DISPATCHED');
306
+ assert.strictEqual(result.proactiveActionTaken, true);
307
+ assert.strictEqual(result.exceptionType, CarrierExceptionType.TRANSIT_STALL_48H);
308
+ assert.strictEqual(result.carrier, 'UPS');
309
+
310
+ const creditAction = result.dispatchedActions.find((a) => a.actionType === 'PROACTIVE_LOYALTY_CREDIT');
311
+ assert.strictEqual(creditAction.amount, 25.0); // Base stall credit
312
+ });
313
+
314
+ it('detects TRANSIT_STALL_48H from timestamp differences (> 48 hours)', () => {
315
+ const listener = new CarrierWebhookListener();
316
+
317
+ const webhook = {
318
+ carrier: 'FedEx',
319
+ trackingNumber: 'FX-STALL-TIMESTAMP',
320
+ customerId: 'CUST-1005',
321
+ lastScanTime: '2026-11-15T08:00:00Z',
322
+ currentScanTime: '2026-11-18T10:00:00Z', // 74 hours gap
323
+ statusDescription: 'In transit - awaiting sort',
324
+ };
325
+
326
+ const result = listener.ingestWebhook(webhook);
327
+
328
+ assert.strictEqual(result.proactiveActionTaken, true);
329
+ assert.strictEqual(result.exceptionType, CarrierExceptionType.TRANSIT_STALL_48H);
330
+ });
331
+
332
+ it('detects CUSTOMS_HOLD from DHL and proactively dispatches trace & loyalty credit', () => {
333
+ const listener = new CarrierWebhookListener();
334
+
335
+ const dhlWebhook = {
336
+ carrier: 'DHL',
337
+ shipmentTrackingNumber: 'DHL-1122334455',
338
+ customerId: 'CUST-1003',
339
+ eventCode: 'CUSTOMS_HOLD',
340
+ details: {
341
+ statusCode: 'CUSTOMS_CLEARANCE_DELAY',
342
+ remarks: 'Package held at port of entry for international customs inspection',
343
+ },
344
+ };
345
+
346
+ const result = listener.ingestWebhook(dhlWebhook);
347
+
348
+ assert.strictEqual(result.status, 'PROACTIVE_RESOLUTION_DISPATCHED');
349
+ assert.strictEqual(result.proactiveActionTaken, true);
350
+ assert.strictEqual(result.exceptionType, CarrierExceptionType.CUSTOMS_HOLD);
351
+ assert.strictEqual(result.carrier, 'DHL');
352
+ assert.strictEqual(result.trackingNumber, 'DHL-1122334455');
353
+
354
+ const creditAction = result.dispatchedActions.find((a) => a.actionType === 'PROACTIVE_LOYALTY_CREDIT');
355
+ assert.strictEqual(creditAction.amount, 30.0); // Base customs credit
356
+ });
357
+
358
+ it('applies customer tier multiplier to proactive loyalty credit', () => {
359
+ const listener = new CarrierWebhookListener();
360
+
361
+ const dhlPlatinumWebhook = {
362
+ carrier: 'DHL',
363
+ shipmentTrackingNumber: 'DHL-PLATINUM-01',
364
+ customerId: 'CUST-PLATINUM',
365
+ customerTier: 'PLATINUM', // 2.0x multiplier
366
+ eventCode: 'CUSTOMS_HOLD',
367
+ };
368
+
369
+ const result = listener.ingestWebhook(dhlPlatinumWebhook);
370
+ const creditAction = result.dispatchedActions.find((a) => a.actionType === 'PROACTIVE_LOYALTY_CREDIT');
371
+
372
+ // 30.0 * 2.0 = 60.0
373
+ assert.strictEqual(creditAction.amount, 60.0);
374
+ assert.strictEqual(creditAction.customerTier, 'PLATINUM');
375
+ assert.strictEqual(creditAction.breakdown.tierMultiplier, 2.0);
376
+ });
377
+
378
+ it('ignores standard in-transit webhooks with no exception', () => {
379
+ const listener = new CarrierWebhookListener();
380
+
381
+ const normalWebhook = {
382
+ carrier: 'FedEx',
383
+ trackingNumber: 'FX-NORMAL-001',
384
+ status: 'IN_TRANSIT',
385
+ statusDescription: 'Departed FedEx location Memphis, TN',
386
+ currentScanTime: '2026-11-18T12:00:00Z',
387
+ lastScanTime: '2026-11-18T08:00:00Z',
388
+ };
389
+
390
+ const result = listener.ingestWebhook(normalWebhook);
391
+
392
+ assert.strictEqual(result.status, 'IGNORED_NO_EXCEPTION');
393
+ assert.strictEqual(result.exceptionDetected, false);
394
+ assert.strictEqual(result.proactiveActionTaken, false);
395
+ assert.strictEqual(listener.dispatchedActions.length, 0);
396
+ });
397
+
398
+ it('enforces idempotency and suppresses duplicate proactive actions for replayed webhooks', () => {
399
+ const listener = new CarrierWebhookListener();
400
+
401
+ const webhook = {
402
+ carrier: 'UPS',
403
+ trackingNumber: '1Z-REPLAY-TEST',
404
+ customerId: 'CUST-DUP',
405
+ eventCode: 'WEATHER_EXCEPTION',
406
+ details: 'Snowstorm delay',
407
+ };
408
+
409
+ // First ingestion -> proactive resolution dispatched
410
+ const firstResult = listener.ingestWebhook(webhook);
411
+ assert.strictEqual(firstResult.status, 'PROACTIVE_RESOLUTION_DISPATCHED');
412
+ assert.strictEqual(firstResult.proactiveActionTaken, true);
413
+
414
+ // Second ingestion (replayed webhook) -> duplicate suppressed
415
+ const secondResult = listener.ingestWebhook(webhook);
416
+ assert.strictEqual(secondResult.status, 'DUPLICATE_SUPPRESSED');
417
+ assert.strictEqual(secondResult.proactiveActionTaken, false);
418
+
419
+ // Total dispatched actions must be exactly 2 (from first execution only)
420
+ assert.strictEqual(listener.dispatchedActions.length, 2);
421
+ });
422
+
423
+ it('triggers onProactiveDispatch callback when proactive action fires', () => {
424
+ let callbackFired = false;
425
+ let receivedIncident = null;
426
+
427
+ const listener = new CarrierWebhookListener({
428
+ onProactiveDispatch: (incident) => {
429
+ callbackFired = true;
430
+ receivedIncident = incident;
431
+ },
432
+ });
433
+
434
+ listener.ingestWebhook({
435
+ carrier: 'FedEx',
436
+ trackingNumber: 'FX-CALLBACK-01',
437
+ eventCode: 'WEATHER_EXCEPTION',
438
+ });
439
+
440
+ assert.strictEqual(callbackFired, true);
441
+ assert.ok(receivedIncident);
442
+ assert.strictEqual(receivedIncident.carrier, 'FEDEX');
443
+ assert.strictEqual(receivedIncident.exceptionType, CarrierExceptionType.WEATHER_EXCEPTION);
444
+ });
445
+ });
@@ -0,0 +1,15 @@
1
+ import test from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import { ResolveXAgent, ResolveXMobileAdapter } from '../src/index.js';
4
+
5
+ test('ResolveX Mobile Adapter: builds mobile outcome cards and tickets', async () => {
6
+ const agent = new ResolveXAgent();
7
+ const mobile = new ResolveXMobileAdapter(agent);
8
+
9
+ const card = mobile.getMobileOutcomeCard();
10
+ assert.equal(card.title, 'ResolveX Autonomous Care');
11
+ assert.equal(card.statusBadge, 'ONLINE_24_7');
12
+
13
+ const queue = mobile.getMobileTicketQueue();
14
+ assert.equal(Array.isArray(queue), true);
15
+ });