@virtuals-protocol/acp-node 0.1.0-beta-fund.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs ADDED
@@ -0,0 +1,2349 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropNames = Object.getOwnPropertyNames;
3
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
6
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
+ var __spreadValues = (a, b) => {
8
+ for (var prop in b || (b = {}))
9
+ if (__hasOwnProp.call(b, prop))
10
+ __defNormalProp(a, prop, b[prop]);
11
+ if (__getOwnPropSymbols)
12
+ for (var prop of __getOwnPropSymbols(b)) {
13
+ if (__propIsEnum.call(b, prop))
14
+ __defNormalProp(a, prop, b[prop]);
15
+ }
16
+ return a;
17
+ };
18
+ var __commonJS = (cb, mod) => function __require() {
19
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
20
+ };
21
+ var __async = (__this, __arguments, generator) => {
22
+ return new Promise((resolve, reject) => {
23
+ var fulfilled = (value) => {
24
+ try {
25
+ step(generator.next(value));
26
+ } catch (e) {
27
+ reject(e);
28
+ }
29
+ };
30
+ var rejected = (value) => {
31
+ try {
32
+ step(generator.throw(value));
33
+ } catch (e) {
34
+ reject(e);
35
+ }
36
+ };
37
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
38
+ step((generator = generator.apply(__this, __arguments)).next());
39
+ });
40
+ };
41
+
42
+ // package.json
43
+ var require_package = __commonJS({
44
+ "package.json"(exports, module) {
45
+ module.exports = {
46
+ name: "@virtuals-protocol/acp-node",
47
+ version: "0.1.0-beta-fund.1",
48
+ main: "./dist/index.js",
49
+ module: "./dist/index.mjs",
50
+ types: "./dist/index.d.ts",
51
+ scripts: {
52
+ test: 'echo "Error: no test specified" && exit 1',
53
+ tsup: "tsup src/index.ts --dts --format cjs,esm --out-dir dist"
54
+ },
55
+ author: "",
56
+ license: "ISC",
57
+ description: "",
58
+ devDependencies: {
59
+ typescript: "^5.8.3"
60
+ },
61
+ dependencies: {
62
+ "@aa-sdk/core": "^4.30.0",
63
+ "@account-kit/infra": "^4.30.0",
64
+ "@account-kit/smart-contracts": "^4.30.0",
65
+ ajv: "^8.17.1",
66
+ "socket.io-client": "^4.8.1",
67
+ tsup: "^8.5.0",
68
+ viem: "^2.28.2"
69
+ },
70
+ files: [
71
+ "dist"
72
+ ]
73
+ };
74
+ }
75
+ });
76
+
77
+ // src/acpAbi.ts
78
+ var ACP_ABI = [
79
+ { inputs: [], stateMutability: "nonpayable", type: "constructor" },
80
+ { inputs: [], name: "AccessControlBadConfirmation", type: "error" },
81
+ {
82
+ inputs: [
83
+ { internalType: "address", name: "account", type: "address" },
84
+ { internalType: "bytes32", name: "neededRole", type: "bytes32" }
85
+ ],
86
+ name: "AccessControlUnauthorizedAccount",
87
+ type: "error"
88
+ },
89
+ {
90
+ inputs: [{ internalType: "address", name: "target", type: "address" }],
91
+ name: "AddressEmptyCode",
92
+ type: "error"
93
+ },
94
+ {
95
+ inputs: [{ internalType: "address", name: "account", type: "address" }],
96
+ name: "AddressInsufficientBalance",
97
+ type: "error"
98
+ },
99
+ { inputs: [], name: "FailedInnerCall", type: "error" },
100
+ { inputs: [], name: "InvalidInitialization", type: "error" },
101
+ { inputs: [], name: "NotInitializing", type: "error" },
102
+ { inputs: [], name: "ReentrancyGuardReentrantCall", type: "error" },
103
+ {
104
+ inputs: [{ internalType: "address", name: "token", type: "address" }],
105
+ name: "SafeERC20FailedOperation",
106
+ type: "error"
107
+ },
108
+ {
109
+ anonymous: false,
110
+ inputs: [
111
+ {
112
+ indexed: true,
113
+ internalType: "uint256",
114
+ name: "jobId",
115
+ type: "uint256"
116
+ },
117
+ {
118
+ indexed: false,
119
+ internalType: "uint256",
120
+ name: "newBudget",
121
+ type: "uint256"
122
+ }
123
+ ],
124
+ name: "BudgetSet",
125
+ type: "event"
126
+ },
127
+ {
128
+ anonymous: false,
129
+ inputs: [
130
+ {
131
+ indexed: false,
132
+ internalType: "uint256",
133
+ name: "jobId",
134
+ type: "uint256"
135
+ },
136
+ {
137
+ indexed: true,
138
+ internalType: "address",
139
+ name: "evaluator",
140
+ type: "address"
141
+ },
142
+ {
143
+ indexed: false,
144
+ internalType: "uint256",
145
+ name: "evaluatorFee",
146
+ type: "uint256"
147
+ }
148
+ ],
149
+ name: "ClaimedEvaluatorFee",
150
+ type: "event"
151
+ },
152
+ {
153
+ anonymous: false,
154
+ inputs: [
155
+ {
156
+ indexed: false,
157
+ internalType: "uint256",
158
+ name: "jobId",
159
+ type: "uint256"
160
+ },
161
+ {
162
+ indexed: true,
163
+ internalType: "address",
164
+ name: "provider",
165
+ type: "address"
166
+ },
167
+ {
168
+ indexed: false,
169
+ internalType: "uint256",
170
+ name: "providerFee",
171
+ type: "uint256"
172
+ }
173
+ ],
174
+ name: "ClaimedProviderFee",
175
+ type: "event"
176
+ },
177
+ {
178
+ anonymous: false,
179
+ inputs: [
180
+ {
181
+ indexed: false,
182
+ internalType: "uint64",
183
+ name: "version",
184
+ type: "uint64"
185
+ }
186
+ ],
187
+ name: "Initialized",
188
+ type: "event"
189
+ },
190
+ {
191
+ anonymous: false,
192
+ inputs: [
193
+ {
194
+ indexed: false,
195
+ internalType: "uint256",
196
+ name: "jobId",
197
+ type: "uint256"
198
+ },
199
+ {
200
+ indexed: true,
201
+ internalType: "address",
202
+ name: "client",
203
+ type: "address"
204
+ },
205
+ {
206
+ indexed: true,
207
+ internalType: "address",
208
+ name: "provider",
209
+ type: "address"
210
+ },
211
+ {
212
+ indexed: true,
213
+ internalType: "address",
214
+ name: "evaluator",
215
+ type: "address"
216
+ }
217
+ ],
218
+ name: "JobCreated",
219
+ type: "event"
220
+ },
221
+ {
222
+ anonymous: false,
223
+ inputs: [
224
+ {
225
+ indexed: true,
226
+ internalType: "uint256",
227
+ name: "jobId",
228
+ type: "uint256"
229
+ },
230
+ {
231
+ indexed: false,
232
+ internalType: "uint8",
233
+ name: "oldPhase",
234
+ type: "uint8"
235
+ },
236
+ { indexed: false, internalType: "uint8", name: "phase", type: "uint8" }
237
+ ],
238
+ name: "JobPhaseUpdated",
239
+ type: "event"
240
+ },
241
+ {
242
+ anonymous: false,
243
+ inputs: [
244
+ {
245
+ indexed: false,
246
+ internalType: "uint256",
247
+ name: "memoId",
248
+ type: "uint256"
249
+ },
250
+ {
251
+ indexed: false,
252
+ internalType: "bool",
253
+ name: "isApproved",
254
+ type: "bool"
255
+ },
256
+ {
257
+ indexed: false,
258
+ internalType: "string",
259
+ name: "reason",
260
+ type: "string"
261
+ }
262
+ ],
263
+ name: "MemoSigned",
264
+ type: "event"
265
+ },
266
+ {
267
+ anonymous: false,
268
+ inputs: [
269
+ {
270
+ indexed: true,
271
+ internalType: "uint256",
272
+ name: "jobId",
273
+ type: "uint256"
274
+ },
275
+ {
276
+ indexed: true,
277
+ internalType: "address",
278
+ name: "sender",
279
+ type: "address"
280
+ },
281
+ {
282
+ indexed: false,
283
+ internalType: "uint256",
284
+ name: "memoId",
285
+ type: "uint256"
286
+ },
287
+ {
288
+ indexed: false,
289
+ internalType: "string",
290
+ name: "content",
291
+ type: "string"
292
+ }
293
+ ],
294
+ name: "NewMemo",
295
+ type: "event"
296
+ },
297
+ {
298
+ anonymous: false,
299
+ inputs: [
300
+ {
301
+ indexed: true,
302
+ internalType: "uint256",
303
+ name: "jobId",
304
+ type: "uint256"
305
+ },
306
+ {
307
+ indexed: true,
308
+ internalType: "uint256",
309
+ name: "memoId",
310
+ type: "uint256"
311
+ },
312
+ {
313
+ indexed: true,
314
+ internalType: "address",
315
+ name: "payer",
316
+ type: "address"
317
+ },
318
+ {
319
+ indexed: false,
320
+ internalType: "uint256",
321
+ name: "amount",
322
+ type: "uint256"
323
+ }
324
+ ],
325
+ name: "PayableFeeCollected",
326
+ type: "event"
327
+ },
328
+ {
329
+ anonymous: false,
330
+ inputs: [
331
+ {
332
+ indexed: true,
333
+ internalType: "uint256",
334
+ name: "jobId",
335
+ type: "uint256"
336
+ },
337
+ {
338
+ indexed: true,
339
+ internalType: "uint256",
340
+ name: "memoId",
341
+ type: "uint256"
342
+ },
343
+ {
344
+ indexed: true,
345
+ internalType: "address",
346
+ name: "payer",
347
+ type: "address"
348
+ },
349
+ {
350
+ indexed: false,
351
+ internalType: "address",
352
+ name: "recipient",
353
+ type: "address"
354
+ },
355
+ {
356
+ indexed: false,
357
+ internalType: "uint256",
358
+ name: "netAmount",
359
+ type: "uint256"
360
+ }
361
+ ],
362
+ name: "PayableFeeRequestExecuted",
363
+ type: "event"
364
+ },
365
+ {
366
+ anonymous: false,
367
+ inputs: [
368
+ {
369
+ indexed: true,
370
+ internalType: "uint256",
371
+ name: "jobId",
372
+ type: "uint256"
373
+ },
374
+ {
375
+ indexed: true,
376
+ internalType: "uint256",
377
+ name: "memoId",
378
+ type: "uint256"
379
+ },
380
+ { indexed: true, internalType: "address", name: "from", type: "address" },
381
+ { indexed: false, internalType: "address", name: "to", type: "address" },
382
+ {
383
+ indexed: false,
384
+ internalType: "address",
385
+ name: "token",
386
+ type: "address"
387
+ },
388
+ {
389
+ indexed: false,
390
+ internalType: "uint256",
391
+ name: "amount",
392
+ type: "uint256"
393
+ }
394
+ ],
395
+ name: "PayableRequestExecuted",
396
+ type: "event"
397
+ },
398
+ {
399
+ anonymous: false,
400
+ inputs: [
401
+ {
402
+ indexed: true,
403
+ internalType: "uint256",
404
+ name: "jobId",
405
+ type: "uint256"
406
+ },
407
+ {
408
+ indexed: true,
409
+ internalType: "uint256",
410
+ name: "memoId",
411
+ type: "uint256"
412
+ },
413
+ { indexed: true, internalType: "address", name: "from", type: "address" },
414
+ { indexed: false, internalType: "address", name: "to", type: "address" },
415
+ {
416
+ indexed: false,
417
+ internalType: "address",
418
+ name: "token",
419
+ type: "address"
420
+ },
421
+ {
422
+ indexed: false,
423
+ internalType: "uint256",
424
+ name: "amount",
425
+ type: "uint256"
426
+ }
427
+ ],
428
+ name: "PayableTransferExecuted",
429
+ type: "event"
430
+ },
431
+ {
432
+ anonymous: false,
433
+ inputs: [
434
+ {
435
+ indexed: true,
436
+ internalType: "uint256",
437
+ name: "jobId",
438
+ type: "uint256"
439
+ },
440
+ {
441
+ indexed: true,
442
+ internalType: "address",
443
+ name: "client",
444
+ type: "address"
445
+ },
446
+ {
447
+ indexed: false,
448
+ internalType: "uint256",
449
+ name: "amount",
450
+ type: "uint256"
451
+ }
452
+ ],
453
+ name: "RefundedAdditionalFees",
454
+ type: "event"
455
+ },
456
+ {
457
+ anonymous: false,
458
+ inputs: [
459
+ {
460
+ indexed: false,
461
+ internalType: "uint256",
462
+ name: "jobId",
463
+ type: "uint256"
464
+ },
465
+ {
466
+ indexed: true,
467
+ internalType: "address",
468
+ name: "client",
469
+ type: "address"
470
+ },
471
+ {
472
+ indexed: false,
473
+ internalType: "uint256",
474
+ name: "amount",
475
+ type: "uint256"
476
+ }
477
+ ],
478
+ name: "RefundedBudget",
479
+ type: "event"
480
+ },
481
+ {
482
+ anonymous: false,
483
+ inputs: [
484
+ { indexed: true, internalType: "bytes32", name: "role", type: "bytes32" },
485
+ {
486
+ indexed: true,
487
+ internalType: "bytes32",
488
+ name: "previousAdminRole",
489
+ type: "bytes32"
490
+ },
491
+ {
492
+ indexed: true,
493
+ internalType: "bytes32",
494
+ name: "newAdminRole",
495
+ type: "bytes32"
496
+ }
497
+ ],
498
+ name: "RoleAdminChanged",
499
+ type: "event"
500
+ },
501
+ {
502
+ anonymous: false,
503
+ inputs: [
504
+ { indexed: true, internalType: "bytes32", name: "role", type: "bytes32" },
505
+ {
506
+ indexed: true,
507
+ internalType: "address",
508
+ name: "account",
509
+ type: "address"
510
+ },
511
+ {
512
+ indexed: true,
513
+ internalType: "address",
514
+ name: "sender",
515
+ type: "address"
516
+ }
517
+ ],
518
+ name: "RoleGranted",
519
+ type: "event"
520
+ },
521
+ {
522
+ anonymous: false,
523
+ inputs: [
524
+ { indexed: true, internalType: "bytes32", name: "role", type: "bytes32" },
525
+ {
526
+ indexed: true,
527
+ internalType: "address",
528
+ name: "account",
529
+ type: "address"
530
+ },
531
+ {
532
+ indexed: true,
533
+ internalType: "address",
534
+ name: "sender",
535
+ type: "address"
536
+ }
537
+ ],
538
+ name: "RoleRevoked",
539
+ type: "event"
540
+ },
541
+ {
542
+ inputs: [],
543
+ name: "ADMIN_ROLE",
544
+ outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }],
545
+ stateMutability: "view",
546
+ type: "function"
547
+ },
548
+ {
549
+ inputs: [],
550
+ name: "DEFAULT_ADMIN_ROLE",
551
+ outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }],
552
+ stateMutability: "view",
553
+ type: "function"
554
+ },
555
+ {
556
+ inputs: [],
557
+ name: "PHASE_COMPLETED",
558
+ outputs: [{ internalType: "uint8", name: "", type: "uint8" }],
559
+ stateMutability: "view",
560
+ type: "function"
561
+ },
562
+ {
563
+ inputs: [],
564
+ name: "PHASE_EVALUATION",
565
+ outputs: [{ internalType: "uint8", name: "", type: "uint8" }],
566
+ stateMutability: "view",
567
+ type: "function"
568
+ },
569
+ {
570
+ inputs: [],
571
+ name: "PHASE_EXPIRED",
572
+ outputs: [{ internalType: "uint8", name: "", type: "uint8" }],
573
+ stateMutability: "view",
574
+ type: "function"
575
+ },
576
+ {
577
+ inputs: [],
578
+ name: "PHASE_NEGOTIATION",
579
+ outputs: [{ internalType: "uint8", name: "", type: "uint8" }],
580
+ stateMutability: "view",
581
+ type: "function"
582
+ },
583
+ {
584
+ inputs: [],
585
+ name: "PHASE_REJECTED",
586
+ outputs: [{ internalType: "uint8", name: "", type: "uint8" }],
587
+ stateMutability: "view",
588
+ type: "function"
589
+ },
590
+ {
591
+ inputs: [],
592
+ name: "PHASE_REQUEST",
593
+ outputs: [{ internalType: "uint8", name: "", type: "uint8" }],
594
+ stateMutability: "view",
595
+ type: "function"
596
+ },
597
+ {
598
+ inputs: [],
599
+ name: "PHASE_TRANSACTION",
600
+ outputs: [{ internalType: "uint8", name: "", type: "uint8" }],
601
+ stateMutability: "view",
602
+ type: "function"
603
+ },
604
+ {
605
+ inputs: [],
606
+ name: "TOTAL_PHASES",
607
+ outputs: [{ internalType: "uint8", name: "", type: "uint8" }],
608
+ stateMutability: "view",
609
+ type: "function"
610
+ },
611
+ {
612
+ inputs: [
613
+ { internalType: "address", name: "account", type: "address" },
614
+ {
615
+ components: [
616
+ { internalType: "uint256", name: "id", type: "uint256" },
617
+ { internalType: "address", name: "client", type: "address" },
618
+ { internalType: "address", name: "provider", type: "address" },
619
+ { internalType: "uint256", name: "budget", type: "uint256" },
620
+ { internalType: "uint256", name: "amountClaimed", type: "uint256" },
621
+ { internalType: "uint8", name: "phase", type: "uint8" },
622
+ { internalType: "uint256", name: "memoCount", type: "uint256" },
623
+ { internalType: "uint256", name: "expiredAt", type: "uint256" },
624
+ { internalType: "address", name: "evaluator", type: "address" }
625
+ ],
626
+ internalType: "struct ACPSimple.Job",
627
+ name: "job",
628
+ type: "tuple"
629
+ }
630
+ ],
631
+ name: "canSign",
632
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
633
+ stateMutability: "pure",
634
+ type: "function"
635
+ },
636
+ {
637
+ inputs: [{ internalType: "uint256", name: "id", type: "uint256" }],
638
+ name: "claimBudget",
639
+ outputs: [],
640
+ stateMutability: "nonpayable",
641
+ type: "function"
642
+ },
643
+ {
644
+ inputs: [
645
+ { internalType: "address", name: "provider", type: "address" },
646
+ { internalType: "address", name: "evaluator", type: "address" },
647
+ { internalType: "uint256", name: "expiredAt", type: "uint256" }
648
+ ],
649
+ name: "createJob",
650
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
651
+ stateMutability: "nonpayable",
652
+ type: "function"
653
+ },
654
+ {
655
+ inputs: [
656
+ { internalType: "uint256", name: "jobId", type: "uint256" },
657
+ { internalType: "string", name: "content", type: "string" },
658
+ {
659
+ internalType: "enum InteractionLedger.MemoType",
660
+ name: "memoType",
661
+ type: "uint8"
662
+ },
663
+ { internalType: "bool", name: "isSecured", type: "bool" },
664
+ { internalType: "uint8", name: "nextPhase", type: "uint8" }
665
+ ],
666
+ name: "createMemo",
667
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
668
+ stateMutability: "nonpayable",
669
+ type: "function"
670
+ },
671
+ {
672
+ inputs: [
673
+ { internalType: "uint256", name: "jobId", type: "uint256" },
674
+ { internalType: "string", name: "content", type: "string" },
675
+ { internalType: "address", name: "token", type: "address" },
676
+ { internalType: "uint256", name: "amount", type: "uint256" },
677
+ { internalType: "address", name: "recipient", type: "address" },
678
+ { internalType: "uint256", name: "feeAmount", type: "uint256" },
679
+ {
680
+ internalType: "enum ACPSimple.FeeType",
681
+ name: "feeType",
682
+ type: "uint8"
683
+ },
684
+ {
685
+ internalType: "enum InteractionLedger.MemoType",
686
+ name: "memoType",
687
+ type: "uint8"
688
+ },
689
+ { internalType: "uint8", name: "nextPhase", type: "uint8" },
690
+ { internalType: "uint256", name: "expiredAt", type: "uint256" }
691
+ ],
692
+ name: "createPayableMemo",
693
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
694
+ stateMutability: "nonpayable",
695
+ type: "function"
696
+ },
697
+ {
698
+ inputs: [],
699
+ name: "evaluatorFeeBP",
700
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
701
+ stateMutability: "view",
702
+ type: "function"
703
+ },
704
+ {
705
+ inputs: [
706
+ { internalType: "uint256", name: "jobId", type: "uint256" },
707
+ { internalType: "uint256", name: "offset", type: "uint256" },
708
+ { internalType: "uint256", name: "limit", type: "uint256" }
709
+ ],
710
+ name: "getAllMemos",
711
+ outputs: [
712
+ {
713
+ components: [
714
+ { internalType: "string", name: "content", type: "string" },
715
+ {
716
+ internalType: "enum InteractionLedger.MemoType",
717
+ name: "memoType",
718
+ type: "uint8"
719
+ },
720
+ { internalType: "bool", name: "isSecured", type: "bool" },
721
+ { internalType: "uint8", name: "nextPhase", type: "uint8" },
722
+ { internalType: "uint256", name: "jobId", type: "uint256" },
723
+ { internalType: "address", name: "sender", type: "address" }
724
+ ],
725
+ internalType: "struct InteractionLedger.Memo[]",
726
+ name: "",
727
+ type: "tuple[]"
728
+ },
729
+ { internalType: "uint256", name: "total", type: "uint256" }
730
+ ],
731
+ stateMutability: "view",
732
+ type: "function"
733
+ },
734
+ {
735
+ inputs: [
736
+ { internalType: "uint256", name: "jobId", type: "uint256" },
737
+ { internalType: "uint8", name: "phase", type: "uint8" }
738
+ ],
739
+ name: "getJobPhaseMemoIds",
740
+ outputs: [{ internalType: "uint256[]", name: "", type: "uint256[]" }],
741
+ stateMutability: "view",
742
+ type: "function"
743
+ },
744
+ {
745
+ inputs: [
746
+ { internalType: "uint256", name: "jobId", type: "uint256" },
747
+ { internalType: "uint8", name: "phase", type: "uint8" },
748
+ { internalType: "uint256", name: "offset", type: "uint256" },
749
+ { internalType: "uint256", name: "limit", type: "uint256" }
750
+ ],
751
+ name: "getMemosForPhase",
752
+ outputs: [
753
+ {
754
+ components: [
755
+ { internalType: "string", name: "content", type: "string" },
756
+ {
757
+ internalType: "enum InteractionLedger.MemoType",
758
+ name: "memoType",
759
+ type: "uint8"
760
+ },
761
+ { internalType: "bool", name: "isSecured", type: "bool" },
762
+ { internalType: "uint8", name: "nextPhase", type: "uint8" },
763
+ { internalType: "uint256", name: "jobId", type: "uint256" },
764
+ { internalType: "address", name: "sender", type: "address" }
765
+ ],
766
+ internalType: "struct InteractionLedger.Memo[]",
767
+ name: "",
768
+ type: "tuple[]"
769
+ },
770
+ { internalType: "uint256", name: "total", type: "uint256" }
771
+ ],
772
+ stateMutability: "view",
773
+ type: "function"
774
+ },
775
+ {
776
+ inputs: [],
777
+ name: "getPhases",
778
+ outputs: [{ internalType: "string[7]", name: "", type: "string[7]" }],
779
+ stateMutability: "pure",
780
+ type: "function"
781
+ },
782
+ {
783
+ inputs: [{ internalType: "bytes32", name: "role", type: "bytes32" }],
784
+ name: "getRoleAdmin",
785
+ outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }],
786
+ stateMutability: "view",
787
+ type: "function"
788
+ },
789
+ {
790
+ inputs: [
791
+ { internalType: "bytes32", name: "role", type: "bytes32" },
792
+ { internalType: "address", name: "account", type: "address" }
793
+ ],
794
+ name: "grantRole",
795
+ outputs: [],
796
+ stateMutability: "nonpayable",
797
+ type: "function"
798
+ },
799
+ {
800
+ inputs: [
801
+ { internalType: "bytes32", name: "role", type: "bytes32" },
802
+ { internalType: "address", name: "account", type: "address" }
803
+ ],
804
+ name: "hasRole",
805
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
806
+ stateMutability: "view",
807
+ type: "function"
808
+ },
809
+ {
810
+ inputs: [
811
+ { internalType: "address", name: "paymentTokenAddress", type: "address" },
812
+ { internalType: "uint256", name: "evaluatorFeeBP_", type: "uint256" },
813
+ { internalType: "uint256", name: "platformFeeBP_", type: "uint256" },
814
+ { internalType: "address", name: "platformTreasury_", type: "address" }
815
+ ],
816
+ name: "initialize",
817
+ outputs: [],
818
+ stateMutability: "nonpayable",
819
+ type: "function"
820
+ },
821
+ {
822
+ inputs: [
823
+ { internalType: "uint256", name: "jobId", type: "uint256" },
824
+ { internalType: "address", name: "account", type: "address" }
825
+ ],
826
+ name: "isJobEvaluator",
827
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
828
+ stateMutability: "view",
829
+ type: "function"
830
+ },
831
+ {
832
+ inputs: [{ internalType: "uint256", name: "memoId", type: "uint256" }],
833
+ name: "isPayableMemo",
834
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
835
+ stateMutability: "view",
836
+ type: "function"
837
+ },
838
+ {
839
+ inputs: [{ internalType: "uint256", name: "jobId", type: "uint256" }],
840
+ name: "jobAdditionalFees",
841
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
842
+ stateMutability: "view",
843
+ type: "function"
844
+ },
845
+ {
846
+ inputs: [],
847
+ name: "jobCounter",
848
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
849
+ stateMutability: "view",
850
+ type: "function"
851
+ },
852
+ {
853
+ inputs: [
854
+ { internalType: "uint256", name: "jobId", type: "uint256" },
855
+ { internalType: "uint8", name: "phase", type: "uint8" },
856
+ { internalType: "uint256", name: "", type: "uint256" }
857
+ ],
858
+ name: "jobMemoIds",
859
+ outputs: [{ internalType: "uint256", name: "memoIds", type: "uint256" }],
860
+ stateMutability: "view",
861
+ type: "function"
862
+ },
863
+ {
864
+ inputs: [{ internalType: "uint256", name: "", type: "uint256" }],
865
+ name: "jobs",
866
+ outputs: [
867
+ { internalType: "uint256", name: "id", type: "uint256" },
868
+ { internalType: "address", name: "client", type: "address" },
869
+ { internalType: "address", name: "provider", type: "address" },
870
+ { internalType: "uint256", name: "budget", type: "uint256" },
871
+ { internalType: "uint256", name: "amountClaimed", type: "uint256" },
872
+ { internalType: "uint8", name: "phase", type: "uint8" },
873
+ { internalType: "uint256", name: "memoCount", type: "uint256" },
874
+ { internalType: "uint256", name: "expiredAt", type: "uint256" },
875
+ { internalType: "address", name: "evaluator", type: "address" }
876
+ ],
877
+ stateMutability: "view",
878
+ type: "function"
879
+ },
880
+ {
881
+ inputs: [],
882
+ name: "memoCounter",
883
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
884
+ stateMutability: "view",
885
+ type: "function"
886
+ },
887
+ {
888
+ inputs: [{ internalType: "uint256", name: "memoId", type: "uint256" }],
889
+ name: "memoExpiredAt",
890
+ outputs: [{ internalType: "uint256", name: "expiredAt", type: "uint256" }],
891
+ stateMutability: "view",
892
+ type: "function"
893
+ },
894
+ {
895
+ inputs: [{ internalType: "uint256", name: "", type: "uint256" }],
896
+ name: "memos",
897
+ outputs: [
898
+ { internalType: "string", name: "content", type: "string" },
899
+ {
900
+ internalType: "enum InteractionLedger.MemoType",
901
+ name: "memoType",
902
+ type: "uint8"
903
+ },
904
+ { internalType: "bool", name: "isSecured", type: "bool" },
905
+ { internalType: "uint8", name: "nextPhase", type: "uint8" },
906
+ { internalType: "uint256", name: "jobId", type: "uint256" },
907
+ { internalType: "address", name: "sender", type: "address" }
908
+ ],
909
+ stateMutability: "view",
910
+ type: "function"
911
+ },
912
+ {
913
+ inputs: [],
914
+ name: "numEvaluatorsPerJob",
915
+ outputs: [{ internalType: "uint8", name: "", type: "uint8" }],
916
+ stateMutability: "view",
917
+ type: "function"
918
+ },
919
+ {
920
+ inputs: [{ internalType: "uint256", name: "memoId", type: "uint256" }],
921
+ name: "payableDetails",
922
+ outputs: [
923
+ { internalType: "address", name: "token", type: "address" },
924
+ { internalType: "uint256", name: "amount", type: "uint256" },
925
+ { internalType: "address", name: "recipient", type: "address" },
926
+ { internalType: "uint256", name: "feeAmount", type: "uint256" },
927
+ {
928
+ internalType: "enum ACPSimple.FeeType",
929
+ name: "feeType",
930
+ type: "uint8"
931
+ },
932
+ { internalType: "bool", name: "isExecuted", type: "bool" }
933
+ ],
934
+ stateMutability: "view",
935
+ type: "function"
936
+ },
937
+ {
938
+ inputs: [],
939
+ name: "paymentToken",
940
+ outputs: [{ internalType: "contract IERC20", name: "", type: "address" }],
941
+ stateMutability: "view",
942
+ type: "function"
943
+ },
944
+ {
945
+ inputs: [],
946
+ name: "platformFeeBP",
947
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
948
+ stateMutability: "view",
949
+ type: "function"
950
+ },
951
+ {
952
+ inputs: [],
953
+ name: "platformTreasury",
954
+ outputs: [{ internalType: "address", name: "", type: "address" }],
955
+ stateMutability: "view",
956
+ type: "function"
957
+ },
958
+ {
959
+ inputs: [
960
+ { internalType: "bytes32", name: "role", type: "bytes32" },
961
+ { internalType: "address", name: "callerConfirmation", type: "address" }
962
+ ],
963
+ name: "renounceRole",
964
+ outputs: [],
965
+ stateMutability: "nonpayable",
966
+ type: "function"
967
+ },
968
+ {
969
+ inputs: [
970
+ { internalType: "bytes32", name: "role", type: "bytes32" },
971
+ { internalType: "address", name: "account", type: "address" }
972
+ ],
973
+ name: "revokeRole",
974
+ outputs: [],
975
+ stateMutability: "nonpayable",
976
+ type: "function"
977
+ },
978
+ {
979
+ inputs: [
980
+ { internalType: "uint256", name: "jobId", type: "uint256" },
981
+ { internalType: "uint256", name: "amount", type: "uint256" }
982
+ ],
983
+ name: "setBudget",
984
+ outputs: [],
985
+ stateMutability: "nonpayable",
986
+ type: "function"
987
+ },
988
+ {
989
+ inputs: [
990
+ { internalType: "uint256", name: "memoId", type: "uint256" },
991
+ { internalType: "bool", name: "isApproved", type: "bool" },
992
+ { internalType: "string", name: "reason", type: "string" }
993
+ ],
994
+ name: "signMemo",
995
+ outputs: [],
996
+ stateMutability: "nonpayable",
997
+ type: "function"
998
+ },
999
+ {
1000
+ inputs: [
1001
+ { internalType: "uint256", name: "memoId", type: "uint256" },
1002
+ { internalType: "address", name: "signer", type: "address" }
1003
+ ],
1004
+ name: "signatories",
1005
+ outputs: [{ internalType: "uint8", name: "res", type: "uint8" }],
1006
+ stateMutability: "view",
1007
+ type: "function"
1008
+ },
1009
+ {
1010
+ inputs: [{ internalType: "bytes4", name: "interfaceId", type: "bytes4" }],
1011
+ name: "supportsInterface",
1012
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
1013
+ stateMutability: "view",
1014
+ type: "function"
1015
+ },
1016
+ {
1017
+ inputs: [
1018
+ { internalType: "uint256", name: "evaluatorFeeBP_", type: "uint256" }
1019
+ ],
1020
+ name: "updateEvaluatorFee",
1021
+ outputs: [],
1022
+ stateMutability: "nonpayable",
1023
+ type: "function"
1024
+ },
1025
+ {
1026
+ inputs: [
1027
+ { internalType: "uint256", name: "platformFeeBP_", type: "uint256" },
1028
+ { internalType: "address", name: "platformTreasury_", type: "address" }
1029
+ ],
1030
+ name: "updatePlatformFee",
1031
+ outputs: [],
1032
+ stateMutability: "nonpayable",
1033
+ type: "function"
1034
+ }
1035
+ ];
1036
+ var acpAbi_default = ACP_ABI;
1037
+
1038
+ // src/acpClient.ts
1039
+ import { parseEther } from "viem";
1040
+ import { io } from "socket.io-client";
1041
+
1042
+ // src/acpContractClient.ts
1043
+ import { LocalAccountSigner } from "@aa-sdk/core";
1044
+ import { alchemy } from "@account-kit/infra";
1045
+ import {
1046
+ createModularAccountV2Client
1047
+ } from "@account-kit/smart-contracts";
1048
+
1049
+ // src/configs.ts
1050
+ import { baseSepolia, base } from "@account-kit/infra";
1051
+ var baseSepoliaAcpConfig = {
1052
+ chain: baseSepolia,
1053
+ contractAddress: "0x8Db6B1c839Fc8f6bd35777E194677B67b4D51928",
1054
+ virtualsTokenAddress: "0xbfAB80ccc15DF6fb7185f9498d6039317331846a",
1055
+ alchemyRpcUrl: "https://alchemy-proxy.virtuals.io/api/proxy/rpc",
1056
+ acpUrl: "https://acpx.virtuals.gg",
1057
+ priorityFeeMultiplier: 2,
1058
+ maxFeePerGas: 2e7,
1059
+ maxPriorityFeePerGas: 21e6
1060
+ };
1061
+ var baseAcpConfig = {
1062
+ chain: base,
1063
+ contractAddress: "0x6a1FE26D54ab0d3E1e3168f2e0c0cDa5cC0A0A4A",
1064
+ virtualsTokenAddress: "0x0b3e328455c4059EEb9e3f84b5543F74E24e7E1b",
1065
+ alchemyRpcUrl: "https://alchemy-proxy-prod.virtuals.io/api/proxy/rpc",
1066
+ acpUrl: "https://acpx.virtuals.io",
1067
+ priorityFeeMultiplier: 2,
1068
+ maxFeePerGas: 2e7,
1069
+ maxPriorityFeePerGas: 21e6
1070
+ };
1071
+
1072
+ // src/acpContractClient.ts
1073
+ import {
1074
+ createPublicClient,
1075
+ encodeFunctionData,
1076
+ erc20Abi,
1077
+ fromHex,
1078
+ http,
1079
+ decodeEventLog
1080
+ } from "viem";
1081
+ import { publicActionsL2 } from "viem/op-stack";
1082
+ var MemoType = /* @__PURE__ */ ((MemoType2) => {
1083
+ MemoType2[MemoType2["MESSAGE"] = 0] = "MESSAGE";
1084
+ MemoType2[MemoType2["CONTEXT_URL"] = 1] = "CONTEXT_URL";
1085
+ MemoType2[MemoType2["IMAGE_URL"] = 2] = "IMAGE_URL";
1086
+ MemoType2[MemoType2["VOICE_URL"] = 3] = "VOICE_URL";
1087
+ MemoType2[MemoType2["OBJECT_URL"] = 4] = "OBJECT_URL";
1088
+ MemoType2[MemoType2["TXHASH"] = 5] = "TXHASH";
1089
+ MemoType2[MemoType2["PAYABLE_REQUEST"] = 6] = "PAYABLE_REQUEST";
1090
+ MemoType2[MemoType2["PAYABLE_TRANSFER"] = 7] = "PAYABLE_TRANSFER";
1091
+ MemoType2[MemoType2["PAYABLE_FEE"] = 8] = "PAYABLE_FEE";
1092
+ MemoType2[MemoType2["PAYABLE_FEE_REQUEST"] = 9] = "PAYABLE_FEE_REQUEST";
1093
+ return MemoType2;
1094
+ })(MemoType || {});
1095
+ var AcpJobPhases = /* @__PURE__ */ ((AcpJobPhases2) => {
1096
+ AcpJobPhases2[AcpJobPhases2["REQUEST"] = 0] = "REQUEST";
1097
+ AcpJobPhases2[AcpJobPhases2["NEGOTIATION"] = 1] = "NEGOTIATION";
1098
+ AcpJobPhases2[AcpJobPhases2["TRANSACTION"] = 2] = "TRANSACTION";
1099
+ AcpJobPhases2[AcpJobPhases2["EVALUATION"] = 3] = "EVALUATION";
1100
+ AcpJobPhases2[AcpJobPhases2["COMPLETED"] = 4] = "COMPLETED";
1101
+ AcpJobPhases2[AcpJobPhases2["REJECTED"] = 5] = "REJECTED";
1102
+ AcpJobPhases2[AcpJobPhases2["EXPIRED"] = 6] = "EXPIRED";
1103
+ return AcpJobPhases2;
1104
+ })(AcpJobPhases || {});
1105
+ var AcpContractClient = class _AcpContractClient {
1106
+ constructor(walletPrivateKey, sessionEntityKeyId, agentWalletAddress, config = baseAcpConfig, customRpcUrl) {
1107
+ this.walletPrivateKey = walletPrivateKey;
1108
+ this.sessionEntityKeyId = sessionEntityKeyId;
1109
+ this.agentWalletAddress = agentWalletAddress;
1110
+ this.config = config;
1111
+ this.customRpcUrl = customRpcUrl;
1112
+ this.MAX_RETRIES = 3;
1113
+ this.chain = config.chain;
1114
+ this.contractAddress = config.contractAddress;
1115
+ this.virtualsTokenAddress = config.virtualsTokenAddress;
1116
+ this.customRpcUrl = customRpcUrl;
1117
+ this.customRpcClient = createPublicClient({
1118
+ chain: this.chain,
1119
+ transport: this.customRpcUrl ? http(this.customRpcUrl) : http()
1120
+ }).extend(publicActionsL2());
1121
+ }
1122
+ static build(_0, _1, _2, _3) {
1123
+ return __async(this, arguments, function* (walletPrivateKey, sessionEntityKeyId, agentWalletAddress, customRpcUrl, config = baseAcpConfig) {
1124
+ const acpContractClient = new _AcpContractClient(
1125
+ walletPrivateKey,
1126
+ sessionEntityKeyId,
1127
+ agentWalletAddress,
1128
+ config,
1129
+ customRpcUrl
1130
+ );
1131
+ yield acpContractClient.init();
1132
+ return acpContractClient;
1133
+ });
1134
+ }
1135
+ init() {
1136
+ return __async(this, null, function* () {
1137
+ const sessionKeySigner = LocalAccountSigner.privateKeyToAccountSigner(this.walletPrivateKey);
1138
+ this._sessionKeyClient = yield createModularAccountV2Client({
1139
+ chain: this.chain,
1140
+ transport: alchemy({
1141
+ rpcUrl: this.config.alchemyRpcUrl
1142
+ }),
1143
+ signer: sessionKeySigner,
1144
+ policyId: "186aaa4a-5f57-4156-83fb-e456365a8820",
1145
+ accountAddress: this.agentWalletAddress,
1146
+ signerEntity: {
1147
+ entityId: this.sessionEntityKeyId,
1148
+ isGlobalValidation: true
1149
+ }
1150
+ });
1151
+ });
1152
+ }
1153
+ get sessionKeyClient() {
1154
+ if (!this._sessionKeyClient) {
1155
+ throw new Error("Session key client not initialized");
1156
+ }
1157
+ return this._sessionKeyClient;
1158
+ }
1159
+ get walletAddress() {
1160
+ return this.sessionKeyClient.account.address;
1161
+ }
1162
+ calculateGasFees() {
1163
+ return __async(this, null, function* () {
1164
+ const { maxFeePerGas, maxPriorityFeePerGas } = yield this.customRpcClient.estimateFeesPerGas();
1165
+ let finalMaxFeePerGas = maxFeePerGas;
1166
+ let priorityFeeMultiplier = Number(this.config.priorityFeeMultiplier) || 2;
1167
+ const overrideMaxFeePerGas = this.config.maxFeePerGas || maxFeePerGas;
1168
+ const overrideMaxPriorityFeePerGas = this.config.maxPriorityFeePerGas || maxPriorityFeePerGas;
1169
+ finalMaxFeePerGas = BigInt(overrideMaxFeePerGas) + BigInt(overrideMaxPriorityFeePerGas) * BigInt(Math.max(0, priorityFeeMultiplier - 1));
1170
+ return finalMaxFeePerGas;
1171
+ });
1172
+ }
1173
+ handleSendUserOperation(_0) {
1174
+ return __async(this, arguments, function* (data, contractAddress = this.contractAddress) {
1175
+ const payload = {
1176
+ uo: {
1177
+ target: contractAddress,
1178
+ data
1179
+ },
1180
+ overrides: {}
1181
+ };
1182
+ let retries = this.MAX_RETRIES;
1183
+ let finalError;
1184
+ while (retries > 0) {
1185
+ try {
1186
+ if (this.MAX_RETRIES > retries) {
1187
+ const gasFees = yield this.calculateGasFees();
1188
+ payload["overrides"] = {
1189
+ maxFeePerGas: `0x${gasFees.toString(16)}`
1190
+ };
1191
+ }
1192
+ const { hash } = yield this.sessionKeyClient.sendUserOperation(payload);
1193
+ yield this.sessionKeyClient.waitForUserOperationTransaction({
1194
+ hash
1195
+ });
1196
+ return hash;
1197
+ } catch (error) {
1198
+ console.debug("Failed to send user operation", error);
1199
+ retries -= 1;
1200
+ if (retries === 0) {
1201
+ finalError = error;
1202
+ break;
1203
+ }
1204
+ yield new Promise((resolve) => setTimeout(resolve, 2e3 * retries));
1205
+ }
1206
+ }
1207
+ throw new Error(`Failed to send user operation ${finalError}`);
1208
+ });
1209
+ }
1210
+ getJobId(hash) {
1211
+ return __async(this, null, function* () {
1212
+ const result = yield this.sessionKeyClient.getUserOperationReceipt(hash);
1213
+ if (!result) {
1214
+ throw new Error("Failed to get user operation receipt");
1215
+ }
1216
+ const contractLogs = result.logs.find(
1217
+ (log) => log.address.toLowerCase() === this.contractAddress.toLowerCase()
1218
+ );
1219
+ if (!contractLogs) {
1220
+ throw new Error("Failed to get contract logs");
1221
+ }
1222
+ return fromHex(contractLogs.data, "number");
1223
+ });
1224
+ }
1225
+ createJob(providerAddress, evaluatorAddress, expireAt) {
1226
+ return __async(this, null, function* () {
1227
+ try {
1228
+ const data = encodeFunctionData({
1229
+ abi: acpAbi_default,
1230
+ functionName: "createJob",
1231
+ args: [
1232
+ providerAddress,
1233
+ evaluatorAddress,
1234
+ Math.floor(expireAt.getTime() / 1e3)
1235
+ ]
1236
+ });
1237
+ const hash = yield this.handleSendUserOperation(data);
1238
+ const jobId = yield this.getJobId(hash);
1239
+ return { txHash: hash, jobId };
1240
+ } catch (error) {
1241
+ console.error(`Failed to create job ${error}`);
1242
+ throw new Error("Failed to create job");
1243
+ }
1244
+ });
1245
+ }
1246
+ approveAllowance(priceInWei) {
1247
+ return __async(this, null, function* () {
1248
+ try {
1249
+ const data = encodeFunctionData({
1250
+ abi: erc20Abi,
1251
+ functionName: "approve",
1252
+ args: [this.contractAddress, priceInWei]
1253
+ });
1254
+ return yield this.handleSendUserOperation(
1255
+ data,
1256
+ this.virtualsTokenAddress
1257
+ );
1258
+ } catch (error) {
1259
+ console.error(`Failed to approve allowance ${error}`);
1260
+ throw new Error("Failed to approve allowance");
1261
+ }
1262
+ });
1263
+ }
1264
+ createPayableFeeMemo(jobId, content, amount, memoType, nextPhase) {
1265
+ return __async(this, null, function* () {
1266
+ let retries = 3;
1267
+ while (retries > 0) {
1268
+ try {
1269
+ const data = encodeFunctionData({
1270
+ abi: acpAbi_default,
1271
+ functionName: "createPayableFeeMemo",
1272
+ args: [jobId, content, amount, memoType, nextPhase]
1273
+ });
1274
+ const { hash } = yield this.sessionKeyClient.sendUserOperation({
1275
+ uo: {
1276
+ target: this.contractAddress,
1277
+ data
1278
+ }
1279
+ });
1280
+ yield this.sessionKeyClient.waitForUserOperationTransaction({
1281
+ hash
1282
+ });
1283
+ return hash;
1284
+ } catch (error) {
1285
+ console.error(
1286
+ `failed to create payable fee memo ${jobId} ${content} ${error}`
1287
+ );
1288
+ retries -= 1;
1289
+ yield new Promise((resolve) => setTimeout(resolve, 2e3 * retries));
1290
+ }
1291
+ }
1292
+ throw new Error("Failed to create payable fee memo");
1293
+ });
1294
+ }
1295
+ createPayableMemo(_0, _1, _2, _3, _4, _5, _6, _7, _8) {
1296
+ return __async(this, arguments, function* (jobId, content, amount, recipient, feeAmount, feeType, nextPhase, type, expiredAt, token = this.config.virtualsTokenAddress) {
1297
+ let retries = 3;
1298
+ while (retries > 0) {
1299
+ try {
1300
+ const data = encodeFunctionData({
1301
+ abi: acpAbi_default,
1302
+ functionName: "createPayableMemo",
1303
+ args: [
1304
+ jobId,
1305
+ content,
1306
+ token,
1307
+ amount,
1308
+ recipient,
1309
+ feeAmount,
1310
+ feeType,
1311
+ type,
1312
+ nextPhase,
1313
+ expiredAt ? Math.floor(expiredAt.getTime() / 1e3) : 0
1314
+ ]
1315
+ });
1316
+ const { hash } = yield this.sessionKeyClient.sendUserOperation({
1317
+ uo: {
1318
+ target: this.contractAddress,
1319
+ data
1320
+ }
1321
+ });
1322
+ yield this.sessionKeyClient.waitForUserOperationTransaction({
1323
+ hash
1324
+ });
1325
+ return hash;
1326
+ } catch (error) {
1327
+ console.error(
1328
+ `failed to create payable memo ${jobId} ${content} ${error}`
1329
+ );
1330
+ retries -= 1;
1331
+ yield new Promise((resolve) => setTimeout(resolve, 2e3 * retries));
1332
+ }
1333
+ }
1334
+ throw new Error("Failed to create payable memo");
1335
+ });
1336
+ }
1337
+ createMemo(jobId, content, type, isSecured, nextPhase) {
1338
+ return __async(this, null, function* () {
1339
+ try {
1340
+ const data = encodeFunctionData({
1341
+ abi: acpAbi_default,
1342
+ functionName: "createMemo",
1343
+ args: [jobId, content, type, isSecured, nextPhase]
1344
+ });
1345
+ return yield this.handleSendUserOperation(data);
1346
+ } catch (error) {
1347
+ console.error(`Failed to create memo ${jobId} ${content} ${error}`);
1348
+ throw new Error("Failed to create memo");
1349
+ }
1350
+ });
1351
+ }
1352
+ getMemoId(hash) {
1353
+ return __async(this, null, function* () {
1354
+ const result = yield this.sessionKeyClient.getUserOperationReceipt(hash);
1355
+ if (!result) {
1356
+ throw new Error("Failed to get user operation receipt");
1357
+ }
1358
+ const contractLogs = result.logs.find(
1359
+ (log) => log.address.toLowerCase() === this.contractAddress.toLowerCase()
1360
+ );
1361
+ if (!contractLogs) {
1362
+ throw new Error("Failed to get contract logs");
1363
+ }
1364
+ const decoded = decodeEventLog({
1365
+ abi: acpAbi_default,
1366
+ data: contractLogs.data,
1367
+ topics: contractLogs.topics
1368
+ });
1369
+ if (!decoded.args) {
1370
+ throw new Error("Failed to decode event logs");
1371
+ }
1372
+ return parseInt(decoded.args.memoId);
1373
+ });
1374
+ }
1375
+ signMemo(memoId, isApproved, reason) {
1376
+ return __async(this, null, function* () {
1377
+ try {
1378
+ const data = encodeFunctionData({
1379
+ abi: acpAbi_default,
1380
+ functionName: "signMemo",
1381
+ args: [memoId, isApproved, reason]
1382
+ });
1383
+ return yield this.handleSendUserOperation(data);
1384
+ } catch (error) {
1385
+ console.error(`Failed to sign memo ${error}`);
1386
+ throw new Error("Failed to sign memo");
1387
+ }
1388
+ });
1389
+ }
1390
+ setBudget(jobId, budget) {
1391
+ return __async(this, null, function* () {
1392
+ try {
1393
+ const data = encodeFunctionData({
1394
+ abi: acpAbi_default,
1395
+ functionName: "setBudget",
1396
+ args: [jobId, budget]
1397
+ });
1398
+ return yield this.handleSendUserOperation(data);
1399
+ } catch (error) {
1400
+ console.error(`Failed to set budget ${error}`);
1401
+ throw new Error("Failed to set budget");
1402
+ }
1403
+ });
1404
+ }
1405
+ };
1406
+ var acpContractClient_default = AcpContractClient;
1407
+
1408
+ // src/interfaces.ts
1409
+ var AcpAgentSort = /* @__PURE__ */ ((AcpAgentSort2) => {
1410
+ AcpAgentSort2["SUCCESSFUL_JOB_COUNT"] = "successfulJobCount";
1411
+ AcpAgentSort2["SUCCESS_RATE"] = "successRate";
1412
+ AcpAgentSort2["UNIQUE_BUYER_COUNT"] = "uniqueBuyerCount";
1413
+ AcpAgentSort2["MINS_FROM_LAST_ONLINE"] = "minsFromLastOnlineTime";
1414
+ AcpAgentSort2["IS_ONLINE"] = "isOnline";
1415
+ return AcpAgentSort2;
1416
+ })(AcpAgentSort || {});
1417
+
1418
+ // src/utils.ts
1419
+ function tryParseJson(content) {
1420
+ try {
1421
+ return JSON.parse(content);
1422
+ } catch (error) {
1423
+ return null;
1424
+ }
1425
+ }
1426
+
1427
+ // src/acpJob.ts
1428
+ var AcpJob = class {
1429
+ constructor(acpClient, id, clientAddress, providerAddress, evaluatorAddress, price, memos, phase, context) {
1430
+ this.acpClient = acpClient;
1431
+ this.id = id;
1432
+ this.clientAddress = clientAddress;
1433
+ this.providerAddress = providerAddress;
1434
+ this.evaluatorAddress = evaluatorAddress;
1435
+ this.price = price;
1436
+ this.memos = memos;
1437
+ this.phase = phase;
1438
+ this.context = context;
1439
+ }
1440
+ get serviceRequirement() {
1441
+ var _a;
1442
+ return (_a = this.memos.find((m) => m.nextPhase === 1 /* NEGOTIATION */)) == null ? void 0 : _a.content;
1443
+ }
1444
+ get deliverable() {
1445
+ var _a;
1446
+ return (_a = this.memos.find((m) => m.nextPhase === 4 /* COMPLETED */)) == null ? void 0 : _a.content;
1447
+ }
1448
+ get providerAgent() {
1449
+ return this.acpClient.getAgent(this.providerAddress);
1450
+ }
1451
+ get clientAgent() {
1452
+ return this.acpClient.getAgent(this.clientAddress);
1453
+ }
1454
+ get evaluatorAgent() {
1455
+ return this.acpClient.getAgent(this.evaluatorAddress);
1456
+ }
1457
+ get latestMemo() {
1458
+ return this.memos[this.memos.length - 1];
1459
+ }
1460
+ pay(amount, reason) {
1461
+ return __async(this, null, function* () {
1462
+ const memo = this.memos.find(
1463
+ (m) => m.nextPhase === 2 /* TRANSACTION */
1464
+ );
1465
+ if (!memo) {
1466
+ throw new Error("No transaction memo found");
1467
+ }
1468
+ return yield this.acpClient.payJob(this.id, amount, memo.id, reason);
1469
+ });
1470
+ }
1471
+ respond(accept, payload, reason) {
1472
+ return __async(this, null, function* () {
1473
+ var _a;
1474
+ if (((_a = this.latestMemo) == null ? void 0 : _a.nextPhase) !== 1 /* NEGOTIATION */) {
1475
+ throw new Error("No negotiation memo found");
1476
+ }
1477
+ return yield this.acpClient.respondJob(
1478
+ this.id,
1479
+ this.latestMemo.id,
1480
+ accept,
1481
+ payload ? JSON.stringify(payload) : void 0,
1482
+ reason
1483
+ );
1484
+ });
1485
+ }
1486
+ deliver(deliverable) {
1487
+ return __async(this, null, function* () {
1488
+ var _a;
1489
+ if (((_a = this.latestMemo) == null ? void 0 : _a.nextPhase) !== 3 /* EVALUATION */) {
1490
+ throw new Error("No transaction memo found");
1491
+ }
1492
+ return yield this.acpClient.deliverJob(
1493
+ this.id,
1494
+ JSON.stringify(deliverable)
1495
+ );
1496
+ });
1497
+ }
1498
+ evaluate(accept, reason) {
1499
+ return __async(this, null, function* () {
1500
+ var _a;
1501
+ if (((_a = this.latestMemo) == null ? void 0 : _a.nextPhase) !== 4 /* COMPLETED */) {
1502
+ throw new Error("No evaluation memo found");
1503
+ }
1504
+ return yield this.acpClient.acpContractClient.signMemo(
1505
+ this.latestMemo.id,
1506
+ accept,
1507
+ reason
1508
+ );
1509
+ });
1510
+ }
1511
+ openPosition(payload, feeAmount, expiredAt, walletAddress) {
1512
+ return __async(this, null, function* () {
1513
+ if (payload.length === 0) {
1514
+ throw new Error("No positions to open");
1515
+ }
1516
+ return yield this.acpClient.transferFunds(
1517
+ this.id,
1518
+ payload.reduce((acc, curr) => acc + curr.amount, 0),
1519
+ walletAddress || this.providerAddress,
1520
+ feeAmount,
1521
+ 1 /* IMMEDIATE_FEE */,
1522
+ {
1523
+ type: "open_position" /* OPEN_POSITION */,
1524
+ data: payload
1525
+ },
1526
+ 2 /* TRANSACTION */,
1527
+ expiredAt
1528
+ );
1529
+ });
1530
+ }
1531
+ responseOpenPosition(memoId, accept, reason) {
1532
+ return __async(this, null, function* () {
1533
+ const memo = this.memos.find((m) => m.id === memoId);
1534
+ if ((memo == null ? void 0 : memo.nextPhase) !== 2 /* TRANSACTION */ || (memo == null ? void 0 : memo.type) !== 7 /* PAYABLE_TRANSFER */) {
1535
+ throw new Error("No open position memo found");
1536
+ }
1537
+ const payload = tryParseJson(
1538
+ memo.content
1539
+ );
1540
+ if ((payload == null ? void 0 : payload.type) !== "open_position" /* OPEN_POSITION */) {
1541
+ throw new Error("Invalid open position memo");
1542
+ }
1543
+ return yield this.acpClient.responseFundsTransfer(memo.id, accept, reason);
1544
+ });
1545
+ }
1546
+ closePartialPosition(payload) {
1547
+ return __async(this, null, function* () {
1548
+ return yield this.acpClient.requestFunds(
1549
+ this.id,
1550
+ payload.amount,
1551
+ this.clientAddress,
1552
+ 0,
1553
+ 0 /* NO_FEE */,
1554
+ {
1555
+ type: "close_partial_position" /* CLOSE_PARTIAL_POSITION */,
1556
+ data: payload
1557
+ },
1558
+ 2 /* TRANSACTION */
1559
+ );
1560
+ });
1561
+ }
1562
+ responseClosePartialPosition(memoId, accept, reason) {
1563
+ return __async(this, null, function* () {
1564
+ const memo = this.memos.find((m) => m.id === memoId);
1565
+ if ((memo == null ? void 0 : memo.nextPhase) !== 2 /* TRANSACTION */ || (memo == null ? void 0 : memo.type) !== 6 /* PAYABLE_REQUEST */) {
1566
+ throw new Error("No close position memo found");
1567
+ }
1568
+ const payload = tryParseJson(
1569
+ memo.content
1570
+ );
1571
+ if ((payload == null ? void 0 : payload.type) !== "close_partial_position" /* CLOSE_PARTIAL_POSITION */) {
1572
+ throw new Error("Invalid close position memo");
1573
+ }
1574
+ return yield this.acpClient.responseFundsRequest(
1575
+ memo.id,
1576
+ accept,
1577
+ payload.data.amount,
1578
+ reason
1579
+ );
1580
+ });
1581
+ }
1582
+ requestClosePosition(payload) {
1583
+ return __async(this, null, function* () {
1584
+ return yield this.acpClient.sendMessage(
1585
+ this.id,
1586
+ {
1587
+ type: "close_position" /* CLOSE_POSITION */,
1588
+ data: payload
1589
+ },
1590
+ 2 /* TRANSACTION */
1591
+ );
1592
+ });
1593
+ }
1594
+ responseRequestClosePosition(memoId, accept, payload, reason) {
1595
+ return __async(this, null, function* () {
1596
+ const memo = this.memos.find((m) => m.id === memoId);
1597
+ if ((memo == null ? void 0 : memo.nextPhase) !== 2 /* TRANSACTION */ || (memo == null ? void 0 : memo.type) !== 0 /* MESSAGE */) {
1598
+ throw new Error("No message memo found");
1599
+ }
1600
+ const messagePayload = tryParseJson(memo.content);
1601
+ if ((messagePayload == null ? void 0 : messagePayload.type) !== "close_position" /* CLOSE_POSITION */) {
1602
+ throw new Error("Invalid close position memo");
1603
+ }
1604
+ yield memo.sign(accept, reason);
1605
+ if (accept) {
1606
+ return yield this.acpClient.transferFunds(
1607
+ this.id,
1608
+ payload.amount,
1609
+ this.clientAddress,
1610
+ 0,
1611
+ 0 /* NO_FEE */,
1612
+ {
1613
+ type: "close_position" /* CLOSE_POSITION */,
1614
+ data: payload
1615
+ },
1616
+ 2 /* TRANSACTION */
1617
+ );
1618
+ }
1619
+ });
1620
+ }
1621
+ confirmClosePosition(memoId, accept, reason) {
1622
+ return __async(this, null, function* () {
1623
+ const memo = this.memos.find((m) => m.id === memoId);
1624
+ if ((memo == null ? void 0 : memo.nextPhase) !== 2 /* TRANSACTION */ || (memo == null ? void 0 : memo.type) !== 7 /* PAYABLE_TRANSFER */) {
1625
+ throw new Error("No payable transfer memo found");
1626
+ }
1627
+ const payload = tryParseJson(
1628
+ memo.content
1629
+ );
1630
+ if ((payload == null ? void 0 : payload.type) !== "close_position" /* CLOSE_POSITION */) {
1631
+ throw new Error("Invalid close position memo");
1632
+ }
1633
+ yield memo.sign(accept, reason);
1634
+ });
1635
+ }
1636
+ positionFulfilled(payload) {
1637
+ return __async(this, null, function* () {
1638
+ return yield this.acpClient.transferFunds(
1639
+ this.id,
1640
+ payload.amount,
1641
+ this.clientAddress,
1642
+ 0,
1643
+ 0 /* NO_FEE */,
1644
+ {
1645
+ type: "position_fulfilled" /* POSITION_FULFILLED */,
1646
+ data: payload
1647
+ },
1648
+ 2 /* TRANSACTION */
1649
+ );
1650
+ });
1651
+ }
1652
+ unfulfilledPosition(payload) {
1653
+ return __async(this, null, function* () {
1654
+ return yield this.acpClient.transferFunds(
1655
+ this.id,
1656
+ payload.amount,
1657
+ this.clientAddress,
1658
+ 0,
1659
+ 0 /* NO_FEE */,
1660
+ {
1661
+ type: "unfulfilled_position" /* UNFULFILLED_POSITION */,
1662
+ data: payload
1663
+ },
1664
+ 2 /* TRANSACTION */
1665
+ );
1666
+ });
1667
+ }
1668
+ responseUnfulfilledPosition(memoId, accept, reason) {
1669
+ return __async(this, null, function* () {
1670
+ const memo = this.memos.find((m) => m.id === memoId);
1671
+ if ((memo == null ? void 0 : memo.nextPhase) !== 2 /* TRANSACTION */ || (memo == null ? void 0 : memo.type) !== 7 /* PAYABLE_TRANSFER */) {
1672
+ throw new Error("No unfulfilled position memo found");
1673
+ }
1674
+ const payload = tryParseJson(
1675
+ memo.content
1676
+ );
1677
+ if ((payload == null ? void 0 : payload.type) !== "unfulfilled_position" /* UNFULFILLED_POSITION */) {
1678
+ throw new Error("Invalid unfulfilled position memo");
1679
+ }
1680
+ return yield this.acpClient.responseFundsTransfer(memo.id, accept, reason);
1681
+ });
1682
+ }
1683
+ responsePositionFulfilled(memoId, accept, reason) {
1684
+ return __async(this, null, function* () {
1685
+ const memo = this.memos.find((m) => m.id === memoId);
1686
+ if ((memo == null ? void 0 : memo.nextPhase) !== 2 /* TRANSACTION */ || (memo == null ? void 0 : memo.type) !== 7 /* PAYABLE_TRANSFER */) {
1687
+ throw new Error("No position fulfilled memo found");
1688
+ }
1689
+ const payload = tryParseJson(
1690
+ memo.content
1691
+ );
1692
+ if ((payload == null ? void 0 : payload.type) !== "position_fulfilled" /* POSITION_FULFILLED */) {
1693
+ throw new Error("Invalid position fulfilled memo");
1694
+ }
1695
+ return yield this.acpClient.responseFundsTransfer(memo.id, accept, reason);
1696
+ });
1697
+ }
1698
+ closeJob(message = "Close job and withdraw all") {
1699
+ return __async(this, null, function* () {
1700
+ return yield this.acpClient.sendMessage(
1701
+ this.id,
1702
+ {
1703
+ type: "close_job_and_withdraw" /* CLOSE_JOB_AND_WITHDRAW */,
1704
+ data: {
1705
+ message
1706
+ }
1707
+ },
1708
+ 2 /* TRANSACTION */
1709
+ );
1710
+ });
1711
+ }
1712
+ responseCloseJob(memoId, accept, fulfilledPositions, reason) {
1713
+ return __async(this, null, function* () {
1714
+ const memo = this.memos.find((m) => m.id === memoId);
1715
+ if ((memo == null ? void 0 : memo.nextPhase) !== 2 /* TRANSACTION */ || (memo == null ? void 0 : memo.type) !== 0 /* MESSAGE */) {
1716
+ throw new Error("No message memo found");
1717
+ }
1718
+ const payload = tryParseJson(
1719
+ memo.content
1720
+ );
1721
+ if ((payload == null ? void 0 : payload.type) !== "close_job_and_withdraw" /* CLOSE_JOB_AND_WITHDRAW */) {
1722
+ throw new Error("Invalid close job and withdraw memo");
1723
+ }
1724
+ yield memo.sign(accept, reason);
1725
+ if (!accept) {
1726
+ return;
1727
+ }
1728
+ const totalAmount = fulfilledPositions.reduce(
1729
+ (acc, curr) => acc + curr.amount,
1730
+ 0
1731
+ );
1732
+ if (totalAmount === 0) {
1733
+ return yield this.acpClient.sendMessage(
1734
+ this.id,
1735
+ {
1736
+ type: "close_job_and_withdraw" /* CLOSE_JOB_AND_WITHDRAW */,
1737
+ data: fulfilledPositions
1738
+ },
1739
+ 4 /* COMPLETED */
1740
+ );
1741
+ }
1742
+ return yield this.acpClient.transferFunds(
1743
+ this.id,
1744
+ fulfilledPositions.reduce((acc, curr) => acc + curr.amount, 0),
1745
+ this.clientAddress,
1746
+ 0,
1747
+ 0 /* NO_FEE */,
1748
+ {
1749
+ type: "close_job_and_withdraw" /* CLOSE_JOB_AND_WITHDRAW */,
1750
+ data: fulfilledPositions
1751
+ },
1752
+ 4 /* COMPLETED */
1753
+ );
1754
+ });
1755
+ }
1756
+ confirmJobClosure(memoId, accept, reason) {
1757
+ return __async(this, null, function* () {
1758
+ const memo = this.memos.find((m) => m.id === memoId);
1759
+ if (!memo) {
1760
+ throw new Error("Memo not found");
1761
+ }
1762
+ const payload = tryParseJson(
1763
+ memo.content
1764
+ );
1765
+ if ((payload == null ? void 0 : payload.type) !== "close_job_and_withdraw" /* CLOSE_JOB_AND_WITHDRAW */) {
1766
+ throw new Error("Invalid close job and withdraw memo");
1767
+ }
1768
+ yield memo.sign(accept, reason);
1769
+ });
1770
+ }
1771
+ };
1772
+ var acpJob_default = AcpJob;
1773
+
1774
+ // src/acpMemo.ts
1775
+ var AcpMemo = class {
1776
+ constructor(acpClient, id, type, content, nextPhase, expiry) {
1777
+ this.acpClient = acpClient;
1778
+ this.id = id;
1779
+ this.type = type;
1780
+ this.content = content;
1781
+ this.nextPhase = nextPhase;
1782
+ this.expiry = expiry;
1783
+ this.structuredContent = tryParseJson(this.content) || void 0;
1784
+ }
1785
+ get payloadType() {
1786
+ var _a;
1787
+ return (_a = this.structuredContent) == null ? void 0 : _a.type;
1788
+ }
1789
+ getStructuredContent() {
1790
+ return this.structuredContent;
1791
+ }
1792
+ create(jobId, isSecured = true) {
1793
+ return __async(this, null, function* () {
1794
+ return yield this.acpClient.acpContractClient.createMemo(
1795
+ jobId,
1796
+ this.content,
1797
+ this.type,
1798
+ isSecured,
1799
+ this.nextPhase
1800
+ );
1801
+ });
1802
+ }
1803
+ sign(approved, reason) {
1804
+ return __async(this, null, function* () {
1805
+ return yield this.acpClient.acpContractClient.signMemo(
1806
+ this.id,
1807
+ approved,
1808
+ reason
1809
+ );
1810
+ });
1811
+ }
1812
+ };
1813
+ var acpMemo_default = AcpMemo;
1814
+
1815
+ // src/acpJobOffering.ts
1816
+ import Ajv from "ajv";
1817
+ var AcpJobOffering = class {
1818
+ constructor(acpClient, providerAddress, type, price, requirementSchema) {
1819
+ this.acpClient = acpClient;
1820
+ this.providerAddress = providerAddress;
1821
+ this.type = type;
1822
+ this.price = price;
1823
+ this.requirementSchema = requirementSchema;
1824
+ this.ajv = new Ajv({ allErrors: true });
1825
+ }
1826
+ initiateJob(_0, _1) {
1827
+ return __async(this, arguments, function* (serviceRequirement, evaluatorAddress, expiredAt = new Date(Date.now() + 1e3 * 60 * 60 * 24)) {
1828
+ if (this.requirementSchema) {
1829
+ const validator = this.ajv.compile(this.requirementSchema);
1830
+ const valid = validator(serviceRequirement);
1831
+ if (!valid) {
1832
+ throw new Error(this.ajv.errorsText(validator.errors));
1833
+ }
1834
+ }
1835
+ return yield this.acpClient.initiateJob(
1836
+ this.providerAddress,
1837
+ serviceRequirement,
1838
+ this.price,
1839
+ evaluatorAddress,
1840
+ expiredAt
1841
+ );
1842
+ });
1843
+ }
1844
+ };
1845
+ var acpJobOffering_default = AcpJobOffering;
1846
+
1847
+ // src/acpClient.ts
1848
+ var { version } = require_package();
1849
+ var AcpClient = class {
1850
+ constructor(options) {
1851
+ this.acpContractClient = options.acpContractClient;
1852
+ this.onNewTask = options.onNewTask;
1853
+ this.onEvaluate = options.onEvaluate || this.defaultOnEvaluate;
1854
+ this.acpUrl = this.acpContractClient.config.acpUrl;
1855
+ this.init();
1856
+ }
1857
+ defaultOnEvaluate(job) {
1858
+ return __async(this, null, function* () {
1859
+ yield job.evaluate(true, "Evaluated by default");
1860
+ });
1861
+ }
1862
+ init() {
1863
+ return __async(this, null, function* () {
1864
+ const socket = io(this.acpUrl, {
1865
+ auth: __spreadValues({
1866
+ walletAddress: this.acpContractClient.walletAddress
1867
+ }, this.onEvaluate !== this.defaultOnEvaluate && {
1868
+ evaluatorAddress: this.acpContractClient.walletAddress
1869
+ }),
1870
+ extraHeaders: {
1871
+ "x-sdk-version": version,
1872
+ "x-sdk-language": "node"
1873
+ },
1874
+ transports: ["websocket"]
1875
+ });
1876
+ socket.on("roomJoined" /* ROOM_JOINED */, (_, callback) => {
1877
+ console.log("Joined ACP Room");
1878
+ callback(true);
1879
+ });
1880
+ socket.on(
1881
+ "onEvaluate" /* ON_EVALUATE */,
1882
+ (data, callback) => __async(this, null, function* () {
1883
+ callback(true);
1884
+ if (this.onEvaluate) {
1885
+ const job = new acpJob_default(
1886
+ this,
1887
+ data.id,
1888
+ data.clientAddress,
1889
+ data.providerAddress,
1890
+ data.evaluatorAddress,
1891
+ data.price,
1892
+ data.memos.map((memo) => {
1893
+ return new acpMemo_default(
1894
+ this,
1895
+ memo.id,
1896
+ memo.memoType,
1897
+ memo.content,
1898
+ memo.nextPhase,
1899
+ memo.expiry ? new Date(parseInt(memo.expiry)) : null
1900
+ );
1901
+ }),
1902
+ data.phase,
1903
+ data.context
1904
+ );
1905
+ this.onEvaluate(job);
1906
+ }
1907
+ })
1908
+ );
1909
+ socket.on(
1910
+ "onNewTask" /* ON_NEW_TASK */,
1911
+ (data, callback) => __async(this, null, function* () {
1912
+ callback(true);
1913
+ if (this.onNewTask) {
1914
+ const job = new acpJob_default(
1915
+ this,
1916
+ data.id,
1917
+ data.clientAddress,
1918
+ data.providerAddress,
1919
+ data.evaluatorAddress,
1920
+ data.price,
1921
+ data.memos.map((memo) => {
1922
+ return new acpMemo_default(
1923
+ this,
1924
+ memo.id,
1925
+ memo.memoType,
1926
+ memo.content,
1927
+ memo.nextPhase,
1928
+ memo.expiry ? new Date(parseInt(memo.expiry)) : null
1929
+ );
1930
+ }),
1931
+ data.phase,
1932
+ data.context
1933
+ );
1934
+ this.onNewTask(
1935
+ job,
1936
+ job.memos.find((m) => m.id == data.memoToSign)
1937
+ );
1938
+ }
1939
+ })
1940
+ );
1941
+ const cleanup = () => __async(this, null, function* () {
1942
+ if (socket) {
1943
+ socket.disconnect();
1944
+ }
1945
+ process.exit(0);
1946
+ });
1947
+ process.on("SIGINT", cleanup);
1948
+ process.on("SIGTERM", cleanup);
1949
+ });
1950
+ }
1951
+ browseAgents(keyword, options) {
1952
+ return __async(this, null, function* () {
1953
+ let { cluster, sort_by, rerank, top_k, graduated } = options;
1954
+ rerank = rerank != null ? rerank : true;
1955
+ top_k = top_k != null ? top_k : 5;
1956
+ graduated = graduated != null ? graduated : true;
1957
+ let url = `${this.acpUrl}/api/agents?search=${keyword}`;
1958
+ if (sort_by && sort_by.length > 0) {
1959
+ url += `&sort=${sort_by.map((s) => s).join(",")}`;
1960
+ }
1961
+ if (top_k) {
1962
+ url += `&top_k=${top_k}`;
1963
+ }
1964
+ if (rerank) {
1965
+ url += `&rerank=true`;
1966
+ }
1967
+ if (this.acpContractClient.walletAddress) {
1968
+ url += `&filters[walletAddress][$notIn]=${this.acpContractClient.walletAddress}`;
1969
+ }
1970
+ if (cluster) {
1971
+ url += `&filters[cluster]=${cluster}`;
1972
+ }
1973
+ if (!graduated) {
1974
+ url += `&filters[hasGraduated]=false`;
1975
+ }
1976
+ const response = yield fetch(url);
1977
+ const data = yield response.json();
1978
+ return data.data.map((agent) => {
1979
+ return {
1980
+ id: agent.id,
1981
+ name: agent.name,
1982
+ description: agent.description,
1983
+ offerings: agent.offerings.map((offering) => {
1984
+ return new acpJobOffering_default(
1985
+ this,
1986
+ agent.walletAddress,
1987
+ offering.name,
1988
+ offering.price,
1989
+ offering.requirementSchema
1990
+ );
1991
+ }),
1992
+ twitterHandle: agent.twitterHandle,
1993
+ walletAddress: agent.walletAddress,
1994
+ metrics: agent.metrics
1995
+ };
1996
+ });
1997
+ });
1998
+ }
1999
+ initiateJob(_0, _1, _2, _3) {
2000
+ return __async(this, arguments, function* (providerAddress, serviceRequirement, amount, evaluatorAddress, expiredAt = new Date(Date.now() + 1e3 * 60 * 60 * 24)) {
2001
+ const { jobId } = yield this.acpContractClient.createJob(
2002
+ providerAddress,
2003
+ evaluatorAddress || this.acpContractClient.walletAddress,
2004
+ expiredAt
2005
+ );
2006
+ if (amount > 0) {
2007
+ yield this.acpContractClient.setBudget(
2008
+ jobId,
2009
+ parseEther(amount.toString())
2010
+ );
2011
+ }
2012
+ yield this.acpContractClient.createMemo(
2013
+ jobId,
2014
+ typeof serviceRequirement === "string" ? serviceRequirement : JSON.stringify(serviceRequirement),
2015
+ 0 /* MESSAGE */,
2016
+ true,
2017
+ 1 /* NEGOTIATION */
2018
+ );
2019
+ return jobId;
2020
+ });
2021
+ }
2022
+ respondJob(jobId, memoId, accept, content, reason) {
2023
+ return __async(this, null, function* () {
2024
+ yield this.acpContractClient.signMemo(memoId, accept, reason);
2025
+ if (!accept) {
2026
+ return;
2027
+ }
2028
+ return yield this.acpContractClient.createMemo(
2029
+ jobId,
2030
+ content != null ? content : `Job ${jobId} accepted. ${reason != null ? reason : ""}`,
2031
+ 0 /* MESSAGE */,
2032
+ false,
2033
+ 2 /* TRANSACTION */
2034
+ );
2035
+ });
2036
+ }
2037
+ payJob(jobId, amount, memoId, reason) {
2038
+ return __async(this, null, function* () {
2039
+ if (amount > 0) {
2040
+ yield this.acpContractClient.approveAllowance(
2041
+ parseEther(amount.toString())
2042
+ );
2043
+ }
2044
+ yield this.acpContractClient.signMemo(memoId, true, reason);
2045
+ return yield this.acpContractClient.createMemo(
2046
+ jobId,
2047
+ `Payment of ${amount} made. ${reason != null ? reason : ""}`,
2048
+ 0 /* MESSAGE */,
2049
+ false,
2050
+ 3 /* EVALUATION */
2051
+ );
2052
+ });
2053
+ }
2054
+ requestFunds(jobId, amount, recipient, feeAmount, feeType, reason, nextPhase) {
2055
+ return __async(this, null, function* () {
2056
+ return yield this.acpContractClient.createPayableMemo(
2057
+ jobId,
2058
+ JSON.stringify(reason),
2059
+ parseEther(amount.toString()),
2060
+ recipient,
2061
+ parseEther(feeAmount.toString()),
2062
+ feeType,
2063
+ nextPhase,
2064
+ 6 /* PAYABLE_REQUEST */
2065
+ );
2066
+ });
2067
+ }
2068
+ responseFundsRequest(memoId, accept, amount, reason) {
2069
+ return __async(this, null, function* () {
2070
+ if (!accept) {
2071
+ return yield this.acpContractClient.signMemo(memoId, accept, reason);
2072
+ }
2073
+ if (amount > 0) {
2074
+ yield this.acpContractClient.approveAllowance(
2075
+ parseEther(amount.toString())
2076
+ );
2077
+ }
2078
+ return yield this.acpContractClient.signMemo(memoId, true, reason);
2079
+ });
2080
+ }
2081
+ transferFunds(jobId, amount, recipient, feeAmount, feeType, reason, nextPhase, expiredAt) {
2082
+ return __async(this, null, function* () {
2083
+ const totalAmount = amount + feeAmount;
2084
+ if (totalAmount > 0) {
2085
+ yield this.acpContractClient.approveAllowance(
2086
+ parseEther((amount + feeAmount).toString())
2087
+ );
2088
+ }
2089
+ return yield this.acpContractClient.createPayableMemo(
2090
+ jobId,
2091
+ JSON.stringify(reason),
2092
+ parseEther(amount.toString()),
2093
+ recipient,
2094
+ parseEther(feeAmount.toString()),
2095
+ feeType,
2096
+ nextPhase,
2097
+ 7 /* PAYABLE_TRANSFER */,
2098
+ expiredAt
2099
+ );
2100
+ });
2101
+ }
2102
+ sendMessage(jobId, message, nextPhase) {
2103
+ return __async(this, null, function* () {
2104
+ return yield this.acpContractClient.createMemo(
2105
+ jobId,
2106
+ JSON.stringify(message),
2107
+ 0 /* MESSAGE */,
2108
+ false,
2109
+ nextPhase
2110
+ );
2111
+ });
2112
+ }
2113
+ responseFundsTransfer(memoId, accept, reason) {
2114
+ return __async(this, null, function* () {
2115
+ return yield this.acpContractClient.signMemo(memoId, accept, reason);
2116
+ });
2117
+ }
2118
+ deliverJob(jobId, deliverable) {
2119
+ return __async(this, null, function* () {
2120
+ return yield this.acpContractClient.createMemo(
2121
+ jobId,
2122
+ deliverable,
2123
+ 4 /* OBJECT_URL */,
2124
+ true,
2125
+ 4 /* COMPLETED */
2126
+ );
2127
+ });
2128
+ }
2129
+ getActiveJobs(page = 1, pageSize = 10) {
2130
+ return __async(this, null, function* () {
2131
+ let url = `${this.acpUrl}/api/jobs/active?pagination[page]=${page}&pagination[pageSize]=${pageSize}`;
2132
+ try {
2133
+ const response = yield fetch(url, {
2134
+ headers: {
2135
+ "wallet-address": this.acpContractClient.walletAddress
2136
+ }
2137
+ });
2138
+ const data = yield response.json();
2139
+ if (data.error) {
2140
+ throw new Error(data.error.message);
2141
+ }
2142
+ return data.data.map((job) => {
2143
+ return new acpJob_default(
2144
+ this,
2145
+ job.id,
2146
+ job.clientAddress,
2147
+ job.providerAddress,
2148
+ job.evaluatorAddress,
2149
+ job.price,
2150
+ job.memos.map((memo) => {
2151
+ return new acpMemo_default(
2152
+ this,
2153
+ memo.id,
2154
+ memo.memoType,
2155
+ memo.content,
2156
+ memo.nextPhase,
2157
+ memo.expiry ? new Date(parseInt(memo.expiry)) : null
2158
+ );
2159
+ }),
2160
+ job.phase,
2161
+ job.context
2162
+ );
2163
+ });
2164
+ } catch (error) {
2165
+ throw error;
2166
+ }
2167
+ });
2168
+ }
2169
+ getCompletedJobs(page = 1, pageSize = 10) {
2170
+ return __async(this, null, function* () {
2171
+ let url = `${this.acpUrl}/api/jobs/completed?pagination[page]=${page}&pagination[pageSize]=${pageSize}`;
2172
+ try {
2173
+ const response = yield fetch(url, {
2174
+ headers: {
2175
+ "wallet-address": this.acpContractClient.walletAddress
2176
+ }
2177
+ });
2178
+ const data = yield response.json();
2179
+ if (data.error) {
2180
+ throw new Error(data.error.message);
2181
+ }
2182
+ return data.data.map((job) => {
2183
+ return new acpJob_default(
2184
+ this,
2185
+ job.id,
2186
+ job.clientAddress,
2187
+ job.providerAddress,
2188
+ job.evaluatorAddress,
2189
+ job.price,
2190
+ job.memos.map((memo) => {
2191
+ return new acpMemo_default(
2192
+ this,
2193
+ memo.id,
2194
+ memo.memoType,
2195
+ memo.content,
2196
+ memo.nextPhase,
2197
+ memo.expiry ? new Date(parseInt(memo.expiry)) : null
2198
+ );
2199
+ }),
2200
+ job.phase,
2201
+ job.context
2202
+ );
2203
+ });
2204
+ } catch (error) {
2205
+ throw error;
2206
+ }
2207
+ });
2208
+ }
2209
+ getCancelledJobs(page = 1, pageSize = 10) {
2210
+ return __async(this, null, function* () {
2211
+ let url = `${this.acpUrl}/api/jobs/cancelled?pagination[page]=${page}&pagination[pageSize]=${pageSize}`;
2212
+ try {
2213
+ const response = yield fetch(url, {
2214
+ headers: {
2215
+ "wallet-address": this.acpContractClient.walletAddress
2216
+ }
2217
+ });
2218
+ const data = yield response.json();
2219
+ if (data.error) {
2220
+ throw new Error(data.error.message);
2221
+ }
2222
+ return data.data.map((job) => {
2223
+ return new acpJob_default(
2224
+ this,
2225
+ job.id,
2226
+ job.clientAddress,
2227
+ job.providerAddress,
2228
+ job.evaluatorAddress,
2229
+ job.price,
2230
+ job.memos.map((memo) => {
2231
+ return new acpMemo_default(
2232
+ this,
2233
+ memo.id,
2234
+ memo.memoType,
2235
+ memo.content,
2236
+ memo.nextPhase,
2237
+ memo.expiry ? new Date(parseInt(memo.expiry)) : null
2238
+ );
2239
+ }),
2240
+ job.phase,
2241
+ job.context
2242
+ );
2243
+ });
2244
+ } catch (error) {
2245
+ throw error;
2246
+ }
2247
+ });
2248
+ }
2249
+ getJobById(jobId) {
2250
+ return __async(this, null, function* () {
2251
+ let url = `${this.acpUrl}/api/jobs/${jobId}`;
2252
+ try {
2253
+ const response = yield fetch(url, {
2254
+ headers: {
2255
+ "wallet-address": this.acpContractClient.walletAddress
2256
+ }
2257
+ });
2258
+ const data = yield response.json();
2259
+ if (data.error) {
2260
+ throw new Error(data.error.message);
2261
+ }
2262
+ const job = data.data;
2263
+ if (!job) {
2264
+ return;
2265
+ }
2266
+ return new acpJob_default(
2267
+ this,
2268
+ job.id,
2269
+ job.clientAddress,
2270
+ job.providerAddress,
2271
+ job.evaluatorAddress,
2272
+ job.price,
2273
+ job.memos.map((memo) => {
2274
+ return new acpMemo_default(
2275
+ this,
2276
+ memo.id,
2277
+ memo.memoType,
2278
+ memo.content,
2279
+ memo.nextPhase,
2280
+ memo.expiry ? new Date(parseInt(memo.expiry)) : null
2281
+ );
2282
+ }),
2283
+ job.phase,
2284
+ job.context
2285
+ );
2286
+ } catch (error) {
2287
+ throw error;
2288
+ }
2289
+ });
2290
+ }
2291
+ getMemoById(jobId, memoId) {
2292
+ return __async(this, null, function* () {
2293
+ let url = `${this.acpUrl}/api/jobs/${jobId}/memos/${memoId}`;
2294
+ try {
2295
+ const response = yield fetch(url, {
2296
+ headers: {
2297
+ "wallet-address": this.acpContractClient.walletAddress
2298
+ }
2299
+ });
2300
+ const data = yield response.json();
2301
+ if (data.error) {
2302
+ throw new Error(data.error.message);
2303
+ }
2304
+ const memo = data.data;
2305
+ if (!memo) {
2306
+ return;
2307
+ }
2308
+ return new acpMemo_default(
2309
+ this,
2310
+ memo.id,
2311
+ memo.memoType,
2312
+ memo.content,
2313
+ memo.nextPhase,
2314
+ memo.expiry ? new Date(parseInt(memo.expiry)) : null
2315
+ );
2316
+ } catch (error) {
2317
+ throw error;
2318
+ }
2319
+ });
2320
+ }
2321
+ getAgent(walletAddress) {
2322
+ return __async(this, null, function* () {
2323
+ const url = `${this.acpUrl}/api/agents?filters[walletAddress]=${walletAddress}`;
2324
+ const response = yield fetch(url);
2325
+ const data = yield response.json();
2326
+ const agents = data.data || [];
2327
+ if (agents.length === 0) {
2328
+ return;
2329
+ }
2330
+ return agents[0];
2331
+ });
2332
+ }
2333
+ };
2334
+ var acpClient_default = AcpClient;
2335
+
2336
+ // src/index.ts
2337
+ var index_default = acpClient_default;
2338
+ export {
2339
+ acpAbi_default as ACP_ABI,
2340
+ AcpAgentSort,
2341
+ acpContractClient_default as AcpContractClient,
2342
+ acpJob_default as AcpJob,
2343
+ AcpJobPhases,
2344
+ acpMemo_default as AcpMemo,
2345
+ MemoType,
2346
+ baseAcpConfig,
2347
+ baseSepoliaAcpConfig,
2348
+ index_default as default
2349
+ };