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