@virtuals-protocol/acp-node 0.3.0-beta.30 → 0.3.0-beta.32
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.d.mts +10 -3
- package/dist/index.d.ts +10 -3
- package/dist/index.js +40 -8
- package/dist/index.mjs +40 -8
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -281,22 +281,23 @@ declare class AcpJob {
|
|
|
281
281
|
phase: AcpJobPhases;
|
|
282
282
|
context: Record<string, any>;
|
|
283
283
|
contractAddress: Address;
|
|
284
|
+
private _deliverable;
|
|
284
285
|
netPayableAmount?: number | undefined;
|
|
285
286
|
name: string | undefined;
|
|
286
287
|
requirement: Record<string, any> | string | undefined;
|
|
287
288
|
priceType: PriceType;
|
|
288
289
|
priceValue: number;
|
|
289
|
-
constructor(acpClient: AcpClient, id: number, clientAddress: Address, providerAddress: Address, evaluatorAddress: Address, price: number, priceTokenAddress: Address, memos: AcpMemo[], phase: AcpJobPhases, context: Record<string, any>, contractAddress: Address, netPayableAmount?: number | undefined);
|
|
290
|
+
constructor(acpClient: AcpClient, id: number, clientAddress: Address, providerAddress: Address, evaluatorAddress: Address, price: number, priceTokenAddress: Address, memos: AcpMemo[], phase: AcpJobPhases, context: Record<string, any>, contractAddress: Address, _deliverable: DeliverablePayload | null, netPayableAmount?: number | undefined);
|
|
290
291
|
get acpContractClient(): BaseAcpContractClient;
|
|
291
292
|
get config(): AcpContractConfig;
|
|
292
293
|
get baseFare(): Fare;
|
|
293
|
-
get deliverable(): string | undefined;
|
|
294
294
|
get rejectionReason(): string | undefined;
|
|
295
295
|
get providerAgent(): Promise<AcpAgent | null>;
|
|
296
296
|
get clientAgent(): Promise<AcpAgent | null>;
|
|
297
297
|
get evaluatorAgent(): Promise<AcpAgent | null>;
|
|
298
298
|
get account(): Promise<AcpAccount | null>;
|
|
299
299
|
get latestMemo(): AcpMemo | undefined;
|
|
300
|
+
getDeliverable(): Promise<DeliverablePayload | null>;
|
|
300
301
|
createRequirement(content: string): Promise<{
|
|
301
302
|
userOpHash: Address;
|
|
302
303
|
txnHash: Address;
|
|
@@ -488,6 +489,11 @@ type X402PaymentResponse = {
|
|
|
488
489
|
isPaymentRequired: boolean;
|
|
489
490
|
data: X402PayableRequirements;
|
|
490
491
|
};
|
|
492
|
+
type IAcpMemoContent = {
|
|
493
|
+
id: number;
|
|
494
|
+
content: string;
|
|
495
|
+
url: string;
|
|
496
|
+
};
|
|
491
497
|
|
|
492
498
|
type SupportedChain = typeof mainnet | typeof sepolia | typeof polygon | typeof polygonAmoy | typeof bsc | typeof bscTestnet | typeof arbitrum | typeof arbitrumSepolia;
|
|
493
499
|
declare class AcpContractConfig {
|
|
@@ -643,7 +649,8 @@ declare class AcpClient {
|
|
|
643
649
|
getAgent(walletAddress: Address, options?: IAcpGetAgentOptions): Promise<AcpAgent | null>;
|
|
644
650
|
getAccountByJobId(jobId: number, acpContractClient?: BaseAcpContractClient): Promise<AcpAccount | null>;
|
|
645
651
|
getByClientAndProvider(clientAddress: Address, providerAddress: Address, acpContractClient?: BaseAcpContractClient): Promise<AcpAccount | null>;
|
|
646
|
-
createMemoContent(jobId: number, content: string): Promise<
|
|
652
|
+
createMemoContent(jobId: number, content: string): Promise<IAcpMemoContent>;
|
|
653
|
+
getMemoContent(url: string): Promise<string>;
|
|
647
654
|
getTokenBalances(): Promise<{
|
|
648
655
|
tokens: Record<string, any>;
|
|
649
656
|
} | undefined>;
|
package/dist/index.d.ts
CHANGED
|
@@ -281,22 +281,23 @@ declare class AcpJob {
|
|
|
281
281
|
phase: AcpJobPhases;
|
|
282
282
|
context: Record<string, any>;
|
|
283
283
|
contractAddress: Address;
|
|
284
|
+
private _deliverable;
|
|
284
285
|
netPayableAmount?: number | undefined;
|
|
285
286
|
name: string | undefined;
|
|
286
287
|
requirement: Record<string, any> | string | undefined;
|
|
287
288
|
priceType: PriceType;
|
|
288
289
|
priceValue: number;
|
|
289
|
-
constructor(acpClient: AcpClient, id: number, clientAddress: Address, providerAddress: Address, evaluatorAddress: Address, price: number, priceTokenAddress: Address, memos: AcpMemo[], phase: AcpJobPhases, context: Record<string, any>, contractAddress: Address, netPayableAmount?: number | undefined);
|
|
290
|
+
constructor(acpClient: AcpClient, id: number, clientAddress: Address, providerAddress: Address, evaluatorAddress: Address, price: number, priceTokenAddress: Address, memos: AcpMemo[], phase: AcpJobPhases, context: Record<string, any>, contractAddress: Address, _deliverable: DeliverablePayload | null, netPayableAmount?: number | undefined);
|
|
290
291
|
get acpContractClient(): BaseAcpContractClient;
|
|
291
292
|
get config(): AcpContractConfig;
|
|
292
293
|
get baseFare(): Fare;
|
|
293
|
-
get deliverable(): string | undefined;
|
|
294
294
|
get rejectionReason(): string | undefined;
|
|
295
295
|
get providerAgent(): Promise<AcpAgent | null>;
|
|
296
296
|
get clientAgent(): Promise<AcpAgent | null>;
|
|
297
297
|
get evaluatorAgent(): Promise<AcpAgent | null>;
|
|
298
298
|
get account(): Promise<AcpAccount | null>;
|
|
299
299
|
get latestMemo(): AcpMemo | undefined;
|
|
300
|
+
getDeliverable(): Promise<DeliverablePayload | null>;
|
|
300
301
|
createRequirement(content: string): Promise<{
|
|
301
302
|
userOpHash: Address;
|
|
302
303
|
txnHash: Address;
|
|
@@ -488,6 +489,11 @@ type X402PaymentResponse = {
|
|
|
488
489
|
isPaymentRequired: boolean;
|
|
489
490
|
data: X402PayableRequirements;
|
|
490
491
|
};
|
|
492
|
+
type IAcpMemoContent = {
|
|
493
|
+
id: number;
|
|
494
|
+
content: string;
|
|
495
|
+
url: string;
|
|
496
|
+
};
|
|
491
497
|
|
|
492
498
|
type SupportedChain = typeof mainnet | typeof sepolia | typeof polygon | typeof polygonAmoy | typeof bsc | typeof bscTestnet | typeof arbitrum | typeof arbitrumSepolia;
|
|
493
499
|
declare class AcpContractConfig {
|
|
@@ -643,7 +649,8 @@ declare class AcpClient {
|
|
|
643
649
|
getAgent(walletAddress: Address, options?: IAcpGetAgentOptions): Promise<AcpAgent | null>;
|
|
644
650
|
getAccountByJobId(jobId: number, acpContractClient?: BaseAcpContractClient): Promise<AcpAccount | null>;
|
|
645
651
|
getByClientAndProvider(clientAddress: Address, providerAddress: Address, acpContractClient?: BaseAcpContractClient): Promise<AcpAccount | null>;
|
|
646
|
-
createMemoContent(jobId: number, content: string): Promise<
|
|
652
|
+
createMemoContent(jobId: number, content: string): Promise<IAcpMemoContent>;
|
|
653
|
+
getMemoContent(url: string): Promise<string>;
|
|
647
654
|
getTokenBalances(): Promise<{
|
|
648
655
|
tokens: Record<string, any>;
|
|
649
656
|
} | undefined>;
|
package/dist/index.js
CHANGED
|
@@ -35,7 +35,7 @@ var require_package = __commonJS({
|
|
|
35
35
|
"package.json"(exports2, module2) {
|
|
36
36
|
module2.exports = {
|
|
37
37
|
name: "@virtuals-protocol/acp-node",
|
|
38
|
-
version: "0.3.0-beta.
|
|
38
|
+
version: "0.3.0-beta.32",
|
|
39
39
|
main: "./dist/index.js",
|
|
40
40
|
module: "./dist/index.mjs",
|
|
41
41
|
types: "./dist/index.d.ts",
|
|
@@ -4225,7 +4225,7 @@ var acpJobOffering_default = AcpJobOffering;
|
|
|
4225
4225
|
// src/acpJob.ts
|
|
4226
4226
|
var util = __toESM(require("util"));
|
|
4227
4227
|
var AcpJob = class {
|
|
4228
|
-
constructor(acpClient, id, clientAddress, providerAddress, evaluatorAddress, price, priceTokenAddress, memos, phase, context, contractAddress, netPayableAmount) {
|
|
4228
|
+
constructor(acpClient, id, clientAddress, providerAddress, evaluatorAddress, price, priceTokenAddress, memos, phase, context, contractAddress, _deliverable, netPayableAmount) {
|
|
4229
4229
|
this.acpClient = acpClient;
|
|
4230
4230
|
this.id = id;
|
|
4231
4231
|
this.clientAddress = clientAddress;
|
|
@@ -4237,6 +4237,7 @@ var AcpJob = class {
|
|
|
4237
4237
|
this.phase = phase;
|
|
4238
4238
|
this.context = context;
|
|
4239
4239
|
this.contractAddress = contractAddress;
|
|
4240
|
+
this._deliverable = _deliverable;
|
|
4240
4241
|
this.netPayableAmount = netPayableAmount;
|
|
4241
4242
|
this.priceType = "fixed" /* FIXED */;
|
|
4242
4243
|
this.priceValue = 0;
|
|
@@ -4272,9 +4273,6 @@ var AcpJob = class {
|
|
|
4272
4273
|
get baseFare() {
|
|
4273
4274
|
return this.acpContractClient.config.baseFare;
|
|
4274
4275
|
}
|
|
4275
|
-
get deliverable() {
|
|
4276
|
-
return this.memos.find((m) => m.nextPhase === 4 /* COMPLETED */)?.content;
|
|
4277
|
-
}
|
|
4278
4276
|
get rejectionReason() {
|
|
4279
4277
|
const requestMemo = this.memos.find(
|
|
4280
4278
|
(m) => m.nextPhase === 1 /* NEGOTIATION */ && m.status === "REJECTED" /* REJECTED */
|
|
@@ -4299,6 +4297,21 @@ var AcpJob = class {
|
|
|
4299
4297
|
get latestMemo() {
|
|
4300
4298
|
return this.memos[this.memos.length - 1];
|
|
4301
4299
|
}
|
|
4300
|
+
async getDeliverable() {
|
|
4301
|
+
if (!this._deliverable) {
|
|
4302
|
+
return null;
|
|
4303
|
+
}
|
|
4304
|
+
if (typeof this._deliverable !== "string") {
|
|
4305
|
+
return this._deliverable;
|
|
4306
|
+
}
|
|
4307
|
+
const regex = /api\/memo-contents\/([0-9]+)$/;
|
|
4308
|
+
const result = this._deliverable?.match(regex);
|
|
4309
|
+
if (!result) {
|
|
4310
|
+
return this._deliverable;
|
|
4311
|
+
}
|
|
4312
|
+
const deliverable = await this.acpClient.getMemoContent(this._deliverable);
|
|
4313
|
+
return tryParseJson(deliverable);
|
|
4314
|
+
}
|
|
4302
4315
|
async createRequirement(content) {
|
|
4303
4316
|
const operations = [];
|
|
4304
4317
|
operations.push(
|
|
@@ -4519,12 +4532,19 @@ var AcpJob = class {
|
|
|
4519
4532
|
return await this.acpContractClient.handleOperation(operations);
|
|
4520
4533
|
}
|
|
4521
4534
|
async deliver(deliverable) {
|
|
4535
|
+
if (this.phase !== 2 /* TRANSACTION */) {
|
|
4536
|
+
throw new acpError_default("Job is not in transaction phase");
|
|
4537
|
+
}
|
|
4522
4538
|
const operations = [];
|
|
4539
|
+
const memoContent = await this.acpClient.createMemoContent(
|
|
4540
|
+
this.id,
|
|
4541
|
+
preparePayload(deliverable)
|
|
4542
|
+
);
|
|
4523
4543
|
operations.push(
|
|
4524
4544
|
this.acpContractClient.createMemo(
|
|
4525
4545
|
this.id,
|
|
4526
|
-
|
|
4527
|
-
|
|
4546
|
+
memoContent?.url,
|
|
4547
|
+
1 /* CONTEXT_URL */,
|
|
4528
4548
|
true,
|
|
4529
4549
|
4 /* COMPLETED */
|
|
4530
4550
|
)
|
|
@@ -4549,10 +4569,14 @@ var AcpJob = class {
|
|
|
4549
4569
|
);
|
|
4550
4570
|
const feeAmount = new FareAmount(0, this.acpContractClient.config.baseFare);
|
|
4551
4571
|
const isPercentagePricing = this.priceType === "percentage" /* PERCENTAGE */ && !skipFee;
|
|
4572
|
+
const memoContent = await this.acpClient.createMemoContent(
|
|
4573
|
+
this.id,
|
|
4574
|
+
preparePayload(deliverable)
|
|
4575
|
+
);
|
|
4552
4576
|
operations.push(
|
|
4553
4577
|
this.acpContractClient.createPayableMemo(
|
|
4554
4578
|
this.id,
|
|
4555
|
-
|
|
4579
|
+
memoContent.url,
|
|
4556
4580
|
amount.amount,
|
|
4557
4581
|
this.clientAddress,
|
|
4558
4582
|
isPercentagePricing ? BigInt(Math.round(this.priceValue * 1e4)) : feeAmount.amount,
|
|
@@ -5067,6 +5091,7 @@ var AcpClient = class {
|
|
|
5067
5091
|
job.phase,
|
|
5068
5092
|
job.context,
|
|
5069
5093
|
job.contractAddress,
|
|
5094
|
+
job.deliverable,
|
|
5070
5095
|
job.netPayableAmount
|
|
5071
5096
|
);
|
|
5072
5097
|
} catch (err) {
|
|
@@ -5357,6 +5382,13 @@ var AcpClient = class {
|
|
|
5357
5382
|
}
|
|
5358
5383
|
return response;
|
|
5359
5384
|
}
|
|
5385
|
+
async getMemoContent(url) {
|
|
5386
|
+
const response = await this._fetch(url);
|
|
5387
|
+
if (!response) {
|
|
5388
|
+
throw new acpError_default("Failed to get memo content");
|
|
5389
|
+
}
|
|
5390
|
+
return response.content;
|
|
5391
|
+
}
|
|
5360
5392
|
async getTokenBalances() {
|
|
5361
5393
|
const response = await this._fetch(
|
|
5362
5394
|
`/chains/token-balances`,
|
package/dist/index.mjs
CHANGED
|
@@ -8,7 +8,7 @@ var require_package = __commonJS({
|
|
|
8
8
|
"package.json"(exports, module) {
|
|
9
9
|
module.exports = {
|
|
10
10
|
name: "@virtuals-protocol/acp-node",
|
|
11
|
-
version: "0.3.0-beta.
|
|
11
|
+
version: "0.3.0-beta.32",
|
|
12
12
|
main: "./dist/index.js",
|
|
13
13
|
module: "./dist/index.mjs",
|
|
14
14
|
types: "./dist/index.d.ts",
|
|
@@ -4202,7 +4202,7 @@ var acpJobOffering_default = AcpJobOffering;
|
|
|
4202
4202
|
// src/acpJob.ts
|
|
4203
4203
|
import * as util from "util";
|
|
4204
4204
|
var AcpJob = class {
|
|
4205
|
-
constructor(acpClient, id, clientAddress, providerAddress, evaluatorAddress, price, priceTokenAddress, memos, phase, context, contractAddress, netPayableAmount) {
|
|
4205
|
+
constructor(acpClient, id, clientAddress, providerAddress, evaluatorAddress, price, priceTokenAddress, memos, phase, context, contractAddress, _deliverable, netPayableAmount) {
|
|
4206
4206
|
this.acpClient = acpClient;
|
|
4207
4207
|
this.id = id;
|
|
4208
4208
|
this.clientAddress = clientAddress;
|
|
@@ -4214,6 +4214,7 @@ var AcpJob = class {
|
|
|
4214
4214
|
this.phase = phase;
|
|
4215
4215
|
this.context = context;
|
|
4216
4216
|
this.contractAddress = contractAddress;
|
|
4217
|
+
this._deliverable = _deliverable;
|
|
4217
4218
|
this.netPayableAmount = netPayableAmount;
|
|
4218
4219
|
this.priceType = "fixed" /* FIXED */;
|
|
4219
4220
|
this.priceValue = 0;
|
|
@@ -4249,9 +4250,6 @@ var AcpJob = class {
|
|
|
4249
4250
|
get baseFare() {
|
|
4250
4251
|
return this.acpContractClient.config.baseFare;
|
|
4251
4252
|
}
|
|
4252
|
-
get deliverable() {
|
|
4253
|
-
return this.memos.find((m) => m.nextPhase === 4 /* COMPLETED */)?.content;
|
|
4254
|
-
}
|
|
4255
4253
|
get rejectionReason() {
|
|
4256
4254
|
const requestMemo = this.memos.find(
|
|
4257
4255
|
(m) => m.nextPhase === 1 /* NEGOTIATION */ && m.status === "REJECTED" /* REJECTED */
|
|
@@ -4276,6 +4274,21 @@ var AcpJob = class {
|
|
|
4276
4274
|
get latestMemo() {
|
|
4277
4275
|
return this.memos[this.memos.length - 1];
|
|
4278
4276
|
}
|
|
4277
|
+
async getDeliverable() {
|
|
4278
|
+
if (!this._deliverable) {
|
|
4279
|
+
return null;
|
|
4280
|
+
}
|
|
4281
|
+
if (typeof this._deliverable !== "string") {
|
|
4282
|
+
return this._deliverable;
|
|
4283
|
+
}
|
|
4284
|
+
const regex = /api\/memo-contents\/([0-9]+)$/;
|
|
4285
|
+
const result = this._deliverable?.match(regex);
|
|
4286
|
+
if (!result) {
|
|
4287
|
+
return this._deliverable;
|
|
4288
|
+
}
|
|
4289
|
+
const deliverable = await this.acpClient.getMemoContent(this._deliverable);
|
|
4290
|
+
return tryParseJson(deliverable);
|
|
4291
|
+
}
|
|
4279
4292
|
async createRequirement(content) {
|
|
4280
4293
|
const operations = [];
|
|
4281
4294
|
operations.push(
|
|
@@ -4496,12 +4509,19 @@ var AcpJob = class {
|
|
|
4496
4509
|
return await this.acpContractClient.handleOperation(operations);
|
|
4497
4510
|
}
|
|
4498
4511
|
async deliver(deliverable) {
|
|
4512
|
+
if (this.phase !== 2 /* TRANSACTION */) {
|
|
4513
|
+
throw new acpError_default("Job is not in transaction phase");
|
|
4514
|
+
}
|
|
4499
4515
|
const operations = [];
|
|
4516
|
+
const memoContent = await this.acpClient.createMemoContent(
|
|
4517
|
+
this.id,
|
|
4518
|
+
preparePayload(deliverable)
|
|
4519
|
+
);
|
|
4500
4520
|
operations.push(
|
|
4501
4521
|
this.acpContractClient.createMemo(
|
|
4502
4522
|
this.id,
|
|
4503
|
-
|
|
4504
|
-
|
|
4523
|
+
memoContent?.url,
|
|
4524
|
+
1 /* CONTEXT_URL */,
|
|
4505
4525
|
true,
|
|
4506
4526
|
4 /* COMPLETED */
|
|
4507
4527
|
)
|
|
@@ -4526,10 +4546,14 @@ var AcpJob = class {
|
|
|
4526
4546
|
);
|
|
4527
4547
|
const feeAmount = new FareAmount(0, this.acpContractClient.config.baseFare);
|
|
4528
4548
|
const isPercentagePricing = this.priceType === "percentage" /* PERCENTAGE */ && !skipFee;
|
|
4549
|
+
const memoContent = await this.acpClient.createMemoContent(
|
|
4550
|
+
this.id,
|
|
4551
|
+
preparePayload(deliverable)
|
|
4552
|
+
);
|
|
4529
4553
|
operations.push(
|
|
4530
4554
|
this.acpContractClient.createPayableMemo(
|
|
4531
4555
|
this.id,
|
|
4532
|
-
|
|
4556
|
+
memoContent.url,
|
|
4533
4557
|
amount.amount,
|
|
4534
4558
|
this.clientAddress,
|
|
4535
4559
|
isPercentagePricing ? BigInt(Math.round(this.priceValue * 1e4)) : feeAmount.amount,
|
|
@@ -5044,6 +5068,7 @@ var AcpClient = class {
|
|
|
5044
5068
|
job.phase,
|
|
5045
5069
|
job.context,
|
|
5046
5070
|
job.contractAddress,
|
|
5071
|
+
job.deliverable,
|
|
5047
5072
|
job.netPayableAmount
|
|
5048
5073
|
);
|
|
5049
5074
|
} catch (err) {
|
|
@@ -5334,6 +5359,13 @@ var AcpClient = class {
|
|
|
5334
5359
|
}
|
|
5335
5360
|
return response;
|
|
5336
5361
|
}
|
|
5362
|
+
async getMemoContent(url) {
|
|
5363
|
+
const response = await this._fetch(url);
|
|
5364
|
+
if (!response) {
|
|
5365
|
+
throw new acpError_default("Failed to get memo content");
|
|
5366
|
+
}
|
|
5367
|
+
return response.content;
|
|
5368
|
+
}
|
|
5337
5369
|
async getTokenBalances() {
|
|
5338
5370
|
const response = await this._fetch(
|
|
5339
5371
|
`/chains/token-balances`,
|