@virtuals-protocol/acp-node 0.3.0-beta.6 → 0.3.0-beta.7
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 +27 -16
- package/dist/index.d.ts +27 -16
- package/dist/index.js +103 -93
- package/dist/index.mjs +103 -93
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -216,7 +216,8 @@ declare enum AcpJobPhases {
|
|
|
216
216
|
declare enum FeeType {
|
|
217
217
|
NO_FEE = 0,
|
|
218
218
|
IMMEDIATE_FEE = 1,
|
|
219
|
-
DEFERRED_FEE = 2
|
|
219
|
+
DEFERRED_FEE = 2,
|
|
220
|
+
PERCENTAGE_FEE = 3
|
|
220
221
|
}
|
|
221
222
|
interface OperationPayload {
|
|
222
223
|
data: `0x${string}`;
|
|
@@ -234,7 +235,7 @@ declare abstract class BaseAcpContractClient {
|
|
|
234
235
|
abstract handleOperation(operations: OperationPayload[]): Promise<Address>;
|
|
235
236
|
abstract getJobId(hash: Address, clientAddress: Address, providerAddress: Address): Promise<number>;
|
|
236
237
|
get walletAddress(): `0x${string}`;
|
|
237
|
-
createJobWithAccount(accountId: number,
|
|
238
|
+
createJobWithAccount(accountId: number, evaluatorAddress: Address, budgetBaseUnit: bigint, paymentTokenAddress: Address, expiredAt: Date): OperationPayload;
|
|
238
239
|
createJob(providerAddress: Address, evaluatorAddress: Address, expiredAt: Date, paymentTokenAddress: Address, budgetBaseUnit: bigint, metadata: string): OperationPayload;
|
|
239
240
|
approveAllowance(amountBaseUnit: bigint, paymentTokenAddress?: Address): OperationPayload;
|
|
240
241
|
createPayableMemo(jobId: number, content: string, amountBaseUnit: bigint, recipient: Address, feeAmountBaseUnit: bigint, feeType: FeeType, nextPhase: AcpJobPhases, type: MemoType.PAYABLE_REQUEST | MemoType.PAYABLE_TRANSFER_ESCROW | MemoType.PAYABLE_TRANSFER | MemoType.PAYABLE_NOTIFICATION, expiredAt: Date, token?: Address, secured?: boolean): OperationPayload;
|
|
@@ -274,6 +275,23 @@ declare class AcpMemo {
|
|
|
274
275
|
sign(approved: boolean, reason?: string): Promise<`0x${string}`>;
|
|
275
276
|
}
|
|
276
277
|
|
|
278
|
+
declare enum PriceType {
|
|
279
|
+
FIXED = "fixed",
|
|
280
|
+
PERCENTAGE = "percentage"
|
|
281
|
+
}
|
|
282
|
+
declare class AcpJobOffering {
|
|
283
|
+
private readonly acpClient;
|
|
284
|
+
private readonly acpContractClient;
|
|
285
|
+
providerAddress: Address;
|
|
286
|
+
name: string;
|
|
287
|
+
price: number;
|
|
288
|
+
priceType: PriceType;
|
|
289
|
+
requirement?: (Object | string) | undefined;
|
|
290
|
+
private ajv;
|
|
291
|
+
constructor(acpClient: AcpClient, acpContractClient: BaseAcpContractClient, providerAddress: Address, name: string, price: number, priceType?: PriceType, requirement?: (Object | string) | undefined);
|
|
292
|
+
initiateJob(serviceRequirement: Object | string, evaluatorAddress?: Address, expiredAt?: Date): Promise<number>;
|
|
293
|
+
}
|
|
294
|
+
|
|
277
295
|
type DeliverablePayload = string | Record<string, unknown>;
|
|
278
296
|
/** @deprecated Use DeliverablePayload instead */
|
|
279
297
|
type IDeliverable = DeliverablePayload;
|
|
@@ -325,7 +343,10 @@ type AcpAgent = {
|
|
|
325
343
|
twitterHandle: string;
|
|
326
344
|
jobs: {
|
|
327
345
|
name: string;
|
|
328
|
-
|
|
346
|
+
priceV2: {
|
|
347
|
+
type: PriceType;
|
|
348
|
+
value: number;
|
|
349
|
+
};
|
|
329
350
|
requirement?: Object | string;
|
|
330
351
|
deliverable?: Object | string;
|
|
331
352
|
}[];
|
|
@@ -418,6 +439,8 @@ declare class AcpJob {
|
|
|
418
439
|
contractAddress: Address;
|
|
419
440
|
name: string | undefined;
|
|
420
441
|
requirement: Record<string, any> | string | undefined;
|
|
442
|
+
priceType: PriceType;
|
|
443
|
+
priceValue: number;
|
|
421
444
|
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);
|
|
422
445
|
get acpContractClient(): BaseAcpContractClient;
|
|
423
446
|
get config(): AcpContractConfig;
|
|
@@ -443,18 +466,6 @@ declare class AcpJob {
|
|
|
443
466
|
createPayableNotification(content: string, amount: FareAmountBase, expiredAt?: Date): Promise<`0x${string}`>;
|
|
444
467
|
}
|
|
445
468
|
|
|
446
|
-
declare class AcpJobOffering {
|
|
447
|
-
private readonly acpClient;
|
|
448
|
-
private readonly acpContractClient;
|
|
449
|
-
providerAddress: Address;
|
|
450
|
-
name: string;
|
|
451
|
-
price: number;
|
|
452
|
-
requirement?: (Object | string) | undefined;
|
|
453
|
-
private ajv;
|
|
454
|
-
constructor(acpClient: AcpClient, acpContractClient: BaseAcpContractClient, providerAddress: Address, name: string, price: number, requirement?: (Object | string) | undefined);
|
|
455
|
-
initiateJob(serviceRequirement: Object | string, evaluatorAddress?: Address, expiredAt?: Date): Promise<number>;
|
|
456
|
-
}
|
|
457
|
-
|
|
458
469
|
interface IAcpBrowseAgentsOptions {
|
|
459
470
|
cluster?: string;
|
|
460
471
|
sort_by?: AcpAgentSort[];
|
|
@@ -8771,7 +8782,7 @@ declare class AcpContractClient extends BaseAcpContractClient {
|
|
|
8771
8782
|
createJob(providerAddress: Address$1, evaluatorAddress: Address$1, expireAt: Date, paymentTokenAddress: Address$1, budgetBaseUnit: bigint, metadata: string): OperationPayload;
|
|
8772
8783
|
setBudgetWithPaymentToken(jobId: number, budgetBaseUnit: bigint, paymentTokenAddress?: Address$1): OperationPayload;
|
|
8773
8784
|
createPayableMemo(jobId: number, content: string, amountBaseUnit: bigint, recipient: Address$1, feeAmountBaseUnit: bigint, feeType: FeeType, nextPhase: AcpJobPhases, type: MemoType.PAYABLE_REQUEST | MemoType.PAYABLE_TRANSFER_ESCROW, expiredAt: Date, token?: Address$1, secured?: boolean): OperationPayload;
|
|
8774
|
-
createJobWithAccount(accountId: number,
|
|
8785
|
+
createJobWithAccount(accountId: number, evaluatorAddress: Address$1, budgetBaseUnit: bigint, paymentTokenAddress: Address$1, expiredAt: Date): OperationPayload;
|
|
8775
8786
|
updateAccountMetadata(accountId: number, metadata: string): OperationPayload;
|
|
8776
8787
|
}
|
|
8777
8788
|
|
package/dist/index.d.ts
CHANGED
|
@@ -216,7 +216,8 @@ declare enum AcpJobPhases {
|
|
|
216
216
|
declare enum FeeType {
|
|
217
217
|
NO_FEE = 0,
|
|
218
218
|
IMMEDIATE_FEE = 1,
|
|
219
|
-
DEFERRED_FEE = 2
|
|
219
|
+
DEFERRED_FEE = 2,
|
|
220
|
+
PERCENTAGE_FEE = 3
|
|
220
221
|
}
|
|
221
222
|
interface OperationPayload {
|
|
222
223
|
data: `0x${string}`;
|
|
@@ -234,7 +235,7 @@ declare abstract class BaseAcpContractClient {
|
|
|
234
235
|
abstract handleOperation(operations: OperationPayload[]): Promise<Address>;
|
|
235
236
|
abstract getJobId(hash: Address, clientAddress: Address, providerAddress: Address): Promise<number>;
|
|
236
237
|
get walletAddress(): `0x${string}`;
|
|
237
|
-
createJobWithAccount(accountId: number,
|
|
238
|
+
createJobWithAccount(accountId: number, evaluatorAddress: Address, budgetBaseUnit: bigint, paymentTokenAddress: Address, expiredAt: Date): OperationPayload;
|
|
238
239
|
createJob(providerAddress: Address, evaluatorAddress: Address, expiredAt: Date, paymentTokenAddress: Address, budgetBaseUnit: bigint, metadata: string): OperationPayload;
|
|
239
240
|
approveAllowance(amountBaseUnit: bigint, paymentTokenAddress?: Address): OperationPayload;
|
|
240
241
|
createPayableMemo(jobId: number, content: string, amountBaseUnit: bigint, recipient: Address, feeAmountBaseUnit: bigint, feeType: FeeType, nextPhase: AcpJobPhases, type: MemoType.PAYABLE_REQUEST | MemoType.PAYABLE_TRANSFER_ESCROW | MemoType.PAYABLE_TRANSFER | MemoType.PAYABLE_NOTIFICATION, expiredAt: Date, token?: Address, secured?: boolean): OperationPayload;
|
|
@@ -274,6 +275,23 @@ declare class AcpMemo {
|
|
|
274
275
|
sign(approved: boolean, reason?: string): Promise<`0x${string}`>;
|
|
275
276
|
}
|
|
276
277
|
|
|
278
|
+
declare enum PriceType {
|
|
279
|
+
FIXED = "fixed",
|
|
280
|
+
PERCENTAGE = "percentage"
|
|
281
|
+
}
|
|
282
|
+
declare class AcpJobOffering {
|
|
283
|
+
private readonly acpClient;
|
|
284
|
+
private readonly acpContractClient;
|
|
285
|
+
providerAddress: Address;
|
|
286
|
+
name: string;
|
|
287
|
+
price: number;
|
|
288
|
+
priceType: PriceType;
|
|
289
|
+
requirement?: (Object | string) | undefined;
|
|
290
|
+
private ajv;
|
|
291
|
+
constructor(acpClient: AcpClient, acpContractClient: BaseAcpContractClient, providerAddress: Address, name: string, price: number, priceType?: PriceType, requirement?: (Object | string) | undefined);
|
|
292
|
+
initiateJob(serviceRequirement: Object | string, evaluatorAddress?: Address, expiredAt?: Date): Promise<number>;
|
|
293
|
+
}
|
|
294
|
+
|
|
277
295
|
type DeliverablePayload = string | Record<string, unknown>;
|
|
278
296
|
/** @deprecated Use DeliverablePayload instead */
|
|
279
297
|
type IDeliverable = DeliverablePayload;
|
|
@@ -325,7 +343,10 @@ type AcpAgent = {
|
|
|
325
343
|
twitterHandle: string;
|
|
326
344
|
jobs: {
|
|
327
345
|
name: string;
|
|
328
|
-
|
|
346
|
+
priceV2: {
|
|
347
|
+
type: PriceType;
|
|
348
|
+
value: number;
|
|
349
|
+
};
|
|
329
350
|
requirement?: Object | string;
|
|
330
351
|
deliverable?: Object | string;
|
|
331
352
|
}[];
|
|
@@ -418,6 +439,8 @@ declare class AcpJob {
|
|
|
418
439
|
contractAddress: Address;
|
|
419
440
|
name: string | undefined;
|
|
420
441
|
requirement: Record<string, any> | string | undefined;
|
|
442
|
+
priceType: PriceType;
|
|
443
|
+
priceValue: number;
|
|
421
444
|
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);
|
|
422
445
|
get acpContractClient(): BaseAcpContractClient;
|
|
423
446
|
get config(): AcpContractConfig;
|
|
@@ -443,18 +466,6 @@ declare class AcpJob {
|
|
|
443
466
|
createPayableNotification(content: string, amount: FareAmountBase, expiredAt?: Date): Promise<`0x${string}`>;
|
|
444
467
|
}
|
|
445
468
|
|
|
446
|
-
declare class AcpJobOffering {
|
|
447
|
-
private readonly acpClient;
|
|
448
|
-
private readonly acpContractClient;
|
|
449
|
-
providerAddress: Address;
|
|
450
|
-
name: string;
|
|
451
|
-
price: number;
|
|
452
|
-
requirement?: (Object | string) | undefined;
|
|
453
|
-
private ajv;
|
|
454
|
-
constructor(acpClient: AcpClient, acpContractClient: BaseAcpContractClient, providerAddress: Address, name: string, price: number, requirement?: (Object | string) | undefined);
|
|
455
|
-
initiateJob(serviceRequirement: Object | string, evaluatorAddress?: Address, expiredAt?: Date): Promise<number>;
|
|
456
|
-
}
|
|
457
|
-
|
|
458
469
|
interface IAcpBrowseAgentsOptions {
|
|
459
470
|
cluster?: string;
|
|
460
471
|
sort_by?: AcpAgentSort[];
|
|
@@ -8771,7 +8782,7 @@ declare class AcpContractClient extends BaseAcpContractClient {
|
|
|
8771
8782
|
createJob(providerAddress: Address$1, evaluatorAddress: Address$1, expireAt: Date, paymentTokenAddress: Address$1, budgetBaseUnit: bigint, metadata: string): OperationPayload;
|
|
8772
8783
|
setBudgetWithPaymentToken(jobId: number, budgetBaseUnit: bigint, paymentTokenAddress?: Address$1): OperationPayload;
|
|
8773
8784
|
createPayableMemo(jobId: number, content: string, amountBaseUnit: bigint, recipient: Address$1, feeAmountBaseUnit: bigint, feeType: FeeType, nextPhase: AcpJobPhases, type: MemoType.PAYABLE_REQUEST | MemoType.PAYABLE_TRANSFER_ESCROW, expiredAt: Date, token?: Address$1, secured?: boolean): OperationPayload;
|
|
8774
|
-
createJobWithAccount(accountId: number,
|
|
8785
|
+
createJobWithAccount(accountId: number, evaluatorAddress: Address$1, budgetBaseUnit: bigint, paymentTokenAddress: Address$1, expiredAt: Date): OperationPayload;
|
|
8775
8786
|
updateAccountMetadata(accountId: number, metadata: string): OperationPayload;
|
|
8776
8787
|
}
|
|
8777
8788
|
|
package/dist/index.js
CHANGED
|
@@ -55,7 +55,7 @@ var require_package = __commonJS({
|
|
|
55
55
|
"package.json"(exports2, module2) {
|
|
56
56
|
module2.exports = {
|
|
57
57
|
name: "@virtuals-protocol/acp-node",
|
|
58
|
-
version: "0.3.0-beta.
|
|
58
|
+
version: "0.3.0-beta.7",
|
|
59
59
|
main: "./dist/index.js",
|
|
60
60
|
module: "./dist/index.mjs",
|
|
61
61
|
types: "./dist/index.d.ts",
|
|
@@ -3062,7 +3062,7 @@ var BaseAcpContractClient = class {
|
|
|
3062
3062
|
get walletAddress() {
|
|
3063
3063
|
return this.agentWalletAddress;
|
|
3064
3064
|
}
|
|
3065
|
-
createJobWithAccount(accountId,
|
|
3065
|
+
createJobWithAccount(accountId, evaluatorAddress, budgetBaseUnit, paymentTokenAddress, expiredAt) {
|
|
3066
3066
|
try {
|
|
3067
3067
|
const data = (0, import_viem2.encodeFunctionData)({
|
|
3068
3068
|
abi: this.abi,
|
|
@@ -3277,6 +3277,94 @@ function preparePayload(payload) {
|
|
|
3277
3277
|
return typeof payload === "string" ? payload : JSON.stringify(payload);
|
|
3278
3278
|
}
|
|
3279
3279
|
|
|
3280
|
+
// src/acpJobOffering.ts
|
|
3281
|
+
var import_viem3 = require("viem");
|
|
3282
|
+
var import_ajv = __toESM(require("ajv"));
|
|
3283
|
+
var AcpJobOffering = class {
|
|
3284
|
+
constructor(acpClient, acpContractClient, providerAddress, name, price, priceType = "fixed" /* FIXED */, requirement) {
|
|
3285
|
+
this.acpClient = acpClient;
|
|
3286
|
+
this.acpContractClient = acpContractClient;
|
|
3287
|
+
this.providerAddress = providerAddress;
|
|
3288
|
+
this.name = name;
|
|
3289
|
+
this.price = price;
|
|
3290
|
+
this.priceType = priceType;
|
|
3291
|
+
this.requirement = requirement;
|
|
3292
|
+
this.ajv = new import_ajv.default({ allErrors: true });
|
|
3293
|
+
}
|
|
3294
|
+
initiateJob(_0, _1) {
|
|
3295
|
+
return __async(this, arguments, function* (serviceRequirement, evaluatorAddress, expiredAt = new Date(Date.now() + 1e3 * 60 * 60 * 24)) {
|
|
3296
|
+
if (this.requirement && typeof this.requirement === "object") {
|
|
3297
|
+
const validator = this.ajv.compile(this.requirement);
|
|
3298
|
+
const valid = validator(serviceRequirement);
|
|
3299
|
+
if (!valid) {
|
|
3300
|
+
throw new acpError_default(this.ajv.errorsText(validator.errors));
|
|
3301
|
+
}
|
|
3302
|
+
}
|
|
3303
|
+
const finalServiceRequirement = {
|
|
3304
|
+
name: this.name,
|
|
3305
|
+
requirement: serviceRequirement,
|
|
3306
|
+
priceValue: this.price,
|
|
3307
|
+
priceType: this.priceType
|
|
3308
|
+
};
|
|
3309
|
+
const fareAmount = new FareAmount(
|
|
3310
|
+
this.priceType === "fixed" /* FIXED */ ? this.price : 0,
|
|
3311
|
+
this.acpContractClient.config.baseFare
|
|
3312
|
+
);
|
|
3313
|
+
const account = yield this.acpClient.getByClientAndProvider(
|
|
3314
|
+
this.acpContractClient.walletAddress,
|
|
3315
|
+
this.providerAddress,
|
|
3316
|
+
this.acpContractClient
|
|
3317
|
+
);
|
|
3318
|
+
const createJobPayload = [
|
|
3319
|
+
baseSepoliaAcpConfig.contractAddress,
|
|
3320
|
+
baseAcpConfig.contractAddress
|
|
3321
|
+
].includes(this.acpContractClient.config.contractAddress) || !account ? yield this.acpContractClient.createJob(
|
|
3322
|
+
this.providerAddress,
|
|
3323
|
+
evaluatorAddress || this.acpContractClient.walletAddress,
|
|
3324
|
+
expiredAt,
|
|
3325
|
+
fareAmount.fare.contractAddress,
|
|
3326
|
+
fareAmount.amount,
|
|
3327
|
+
""
|
|
3328
|
+
) : yield this.acpContractClient.createJobWithAccount(
|
|
3329
|
+
account.id,
|
|
3330
|
+
evaluatorAddress || import_viem3.zeroAddress,
|
|
3331
|
+
fareAmount.amount,
|
|
3332
|
+
fareAmount.fare.contractAddress,
|
|
3333
|
+
expiredAt
|
|
3334
|
+
);
|
|
3335
|
+
const createJobTxnHash = yield this.acpContractClient.handleOperation([
|
|
3336
|
+
createJobPayload
|
|
3337
|
+
]);
|
|
3338
|
+
const jobId = yield this.acpContractClient.getJobId(
|
|
3339
|
+
createJobTxnHash,
|
|
3340
|
+
this.acpContractClient.walletAddress,
|
|
3341
|
+
this.providerAddress
|
|
3342
|
+
);
|
|
3343
|
+
const payloads = [];
|
|
3344
|
+
const setBudgetWithPaymentTokenPayload = this.acpContractClient.setBudgetWithPaymentToken(
|
|
3345
|
+
jobId,
|
|
3346
|
+
fareAmount.amount,
|
|
3347
|
+
fareAmount.fare.contractAddress
|
|
3348
|
+
);
|
|
3349
|
+
if (setBudgetWithPaymentTokenPayload) {
|
|
3350
|
+
payloads.push(setBudgetWithPaymentTokenPayload);
|
|
3351
|
+
}
|
|
3352
|
+
payloads.push(
|
|
3353
|
+
this.acpContractClient.createMemo(
|
|
3354
|
+
jobId,
|
|
3355
|
+
JSON.stringify(finalServiceRequirement),
|
|
3356
|
+
0 /* MESSAGE */,
|
|
3357
|
+
true,
|
|
3358
|
+
1 /* NEGOTIATION */
|
|
3359
|
+
)
|
|
3360
|
+
);
|
|
3361
|
+
yield this.acpContractClient.handleOperation(payloads);
|
|
3362
|
+
return jobId;
|
|
3363
|
+
});
|
|
3364
|
+
}
|
|
3365
|
+
};
|
|
3366
|
+
var acpJobOffering_default = AcpJobOffering;
|
|
3367
|
+
|
|
3280
3368
|
// src/acpJob.ts
|
|
3281
3369
|
var AcpJob = class {
|
|
3282
3370
|
constructor(acpClient, id, clientAddress, providerAddress, evaluatorAddress, price, priceTokenAddress, memos, phase, context, contractAddress) {
|
|
@@ -3291,6 +3379,8 @@ var AcpJob = class {
|
|
|
3291
3379
|
this.phase = phase;
|
|
3292
3380
|
this.context = context;
|
|
3293
3381
|
this.contractAddress = contractAddress;
|
|
3382
|
+
this.priceType = "fixed" /* FIXED */;
|
|
3383
|
+
this.priceValue = 0;
|
|
3294
3384
|
var _a;
|
|
3295
3385
|
const content = (_a = this.memos.find(
|
|
3296
3386
|
(m) => m.nextPhase === 1 /* NEGOTIATION */
|
|
@@ -3308,6 +3398,12 @@ var AcpJob = class {
|
|
|
3308
3398
|
if (contentObj.serviceName || contentObj.name) {
|
|
3309
3399
|
this.name = contentObj.name || contentObj.serviceName;
|
|
3310
3400
|
}
|
|
3401
|
+
if (contentObj.priceType) {
|
|
3402
|
+
this.priceType = contentObj.priceType || "fixed" /* FIXED */;
|
|
3403
|
+
}
|
|
3404
|
+
if (contentObj.priceValue) {
|
|
3405
|
+
this.priceValue = contentObj.priceValue || this.price;
|
|
3406
|
+
}
|
|
3311
3407
|
}
|
|
3312
3408
|
get acpContractClient() {
|
|
3313
3409
|
return this.acpClient.contractClientByAddress(this.contractAddress);
|
|
@@ -3380,8 +3476,8 @@ var AcpJob = class {
|
|
|
3380
3476
|
content,
|
|
3381
3477
|
amount.amount,
|
|
3382
3478
|
recipient,
|
|
3383
|
-
feeAmount.amount,
|
|
3384
|
-
0 /* NO_FEE */,
|
|
3479
|
+
this.priceType === "percentage" /* PERCENTAGE */ ? BigInt(this.priceValue * 1e4) : feeAmount.amount,
|
|
3480
|
+
this.priceType === "percentage" /* PERCENTAGE */ ? 3 /* PERCENTAGE_FEE */ : 0 /* NO_FEE */,
|
|
3385
3481
|
2 /* TRANSACTION */,
|
|
3386
3482
|
type,
|
|
3387
3483
|
expiredAt,
|
|
@@ -3656,92 +3752,6 @@ var AcpMemo = class {
|
|
|
3656
3752
|
};
|
|
3657
3753
|
var acpMemo_default = AcpMemo;
|
|
3658
3754
|
|
|
3659
|
-
// src/acpJobOffering.ts
|
|
3660
|
-
var import_viem3 = require("viem");
|
|
3661
|
-
var import_ajv = __toESM(require("ajv"));
|
|
3662
|
-
var AcpJobOffering = class {
|
|
3663
|
-
constructor(acpClient, acpContractClient, providerAddress, name, price, requirement) {
|
|
3664
|
-
this.acpClient = acpClient;
|
|
3665
|
-
this.acpContractClient = acpContractClient;
|
|
3666
|
-
this.providerAddress = providerAddress;
|
|
3667
|
-
this.name = name;
|
|
3668
|
-
this.price = price;
|
|
3669
|
-
this.requirement = requirement;
|
|
3670
|
-
this.ajv = new import_ajv.default({ allErrors: true });
|
|
3671
|
-
}
|
|
3672
|
-
initiateJob(_0, _1) {
|
|
3673
|
-
return __async(this, arguments, function* (serviceRequirement, evaluatorAddress, expiredAt = new Date(Date.now() + 1e3 * 60 * 60 * 24)) {
|
|
3674
|
-
if (this.requirement && typeof this.requirement === "object") {
|
|
3675
|
-
const validator = this.ajv.compile(this.requirement);
|
|
3676
|
-
const valid = validator(serviceRequirement);
|
|
3677
|
-
if (!valid) {
|
|
3678
|
-
throw new acpError_default(this.ajv.errorsText(validator.errors));
|
|
3679
|
-
}
|
|
3680
|
-
}
|
|
3681
|
-
const finalServiceRequirement = {
|
|
3682
|
-
name: this.name,
|
|
3683
|
-
requirement: serviceRequirement
|
|
3684
|
-
};
|
|
3685
|
-
const fareAmount = new FareAmount(
|
|
3686
|
-
this.price,
|
|
3687
|
-
this.acpContractClient.config.baseFare
|
|
3688
|
-
);
|
|
3689
|
-
const account = yield this.acpClient.getByClientAndProvider(
|
|
3690
|
-
this.acpContractClient.walletAddress,
|
|
3691
|
-
this.providerAddress,
|
|
3692
|
-
this.acpContractClient
|
|
3693
|
-
);
|
|
3694
|
-
const createJobPayload = [
|
|
3695
|
-
baseSepoliaAcpConfig.contractAddress,
|
|
3696
|
-
baseAcpConfig.contractAddress
|
|
3697
|
-
].includes(this.acpContractClient.config.contractAddress) || !account ? yield this.acpContractClient.createJob(
|
|
3698
|
-
this.providerAddress,
|
|
3699
|
-
evaluatorAddress || this.acpContractClient.walletAddress,
|
|
3700
|
-
expiredAt,
|
|
3701
|
-
fareAmount.fare.contractAddress,
|
|
3702
|
-
fareAmount.amount,
|
|
3703
|
-
""
|
|
3704
|
-
) : yield this.acpContractClient.createJobWithAccount(
|
|
3705
|
-
account.id,
|
|
3706
|
-
this.providerAddress,
|
|
3707
|
-
evaluatorAddress || import_viem3.zeroAddress,
|
|
3708
|
-
fareAmount.amount,
|
|
3709
|
-
fareAmount.fare.contractAddress,
|
|
3710
|
-
expiredAt
|
|
3711
|
-
);
|
|
3712
|
-
const createJobTxnHash = yield this.acpContractClient.handleOperation([
|
|
3713
|
-
createJobPayload
|
|
3714
|
-
]);
|
|
3715
|
-
const jobId = yield this.acpContractClient.getJobId(
|
|
3716
|
-
createJobTxnHash,
|
|
3717
|
-
this.acpContractClient.walletAddress,
|
|
3718
|
-
this.providerAddress
|
|
3719
|
-
);
|
|
3720
|
-
const payloads = [];
|
|
3721
|
-
const setBudgetWithPaymentTokenPayload = this.acpContractClient.setBudgetWithPaymentToken(
|
|
3722
|
-
jobId,
|
|
3723
|
-
fareAmount.amount,
|
|
3724
|
-
fareAmount.fare.contractAddress
|
|
3725
|
-
);
|
|
3726
|
-
if (setBudgetWithPaymentTokenPayload) {
|
|
3727
|
-
payloads.push(setBudgetWithPaymentTokenPayload);
|
|
3728
|
-
}
|
|
3729
|
-
payloads.push(
|
|
3730
|
-
this.acpContractClient.createMemo(
|
|
3731
|
-
jobId,
|
|
3732
|
-
JSON.stringify(finalServiceRequirement),
|
|
3733
|
-
0 /* MESSAGE */,
|
|
3734
|
-
true,
|
|
3735
|
-
1 /* NEGOTIATION */
|
|
3736
|
-
)
|
|
3737
|
-
);
|
|
3738
|
-
yield this.acpContractClient.handleOperation(payloads);
|
|
3739
|
-
return jobId;
|
|
3740
|
-
});
|
|
3741
|
-
}
|
|
3742
|
-
};
|
|
3743
|
-
var acpJobOffering_default = AcpJobOffering;
|
|
3744
|
-
|
|
3745
3755
|
// src/acpAccount.ts
|
|
3746
3756
|
var AcpAccount = class {
|
|
3747
3757
|
constructor(contractClient, id, clientAddress, providerAddress, metadata) {
|
|
@@ -3962,7 +3972,8 @@ var AcpClient = class {
|
|
|
3962
3972
|
acpContractClient,
|
|
3963
3973
|
agent.walletAddress,
|
|
3964
3974
|
jobs.name,
|
|
3965
|
-
jobs.
|
|
3975
|
+
jobs.priceV2.value,
|
|
3976
|
+
jobs.priceV2.type,
|
|
3966
3977
|
jobs.requirement
|
|
3967
3978
|
);
|
|
3968
3979
|
}),
|
|
@@ -4003,7 +4014,6 @@ var AcpClient = class {
|
|
|
4003
4014
|
""
|
|
4004
4015
|
) : yield this.acpContractClient.createJobWithAccount(
|
|
4005
4016
|
account.id,
|
|
4006
|
-
providerAddress,
|
|
4007
4017
|
evaluatorAddress || defaultEvaluatorAddress,
|
|
4008
4018
|
fareAmount.amount,
|
|
4009
4019
|
fareAmount.fare.contractAddress,
|
|
@@ -4547,7 +4557,7 @@ var AcpContractClient = class _AcpContractClient extends baseAcpContractClient_d
|
|
|
4547
4557
|
throw new acpError_default("Failed to create payable memo", error);
|
|
4548
4558
|
}
|
|
4549
4559
|
}
|
|
4550
|
-
createJobWithAccount(accountId,
|
|
4560
|
+
createJobWithAccount(accountId, evaluatorAddress, budgetBaseUnit, paymentTokenAddress, expiredAt) {
|
|
4551
4561
|
throw new acpError_default("Not Supported");
|
|
4552
4562
|
}
|
|
4553
4563
|
updateAccountMetadata(accountId, metadata) {
|
package/dist/index.mjs
CHANGED
|
@@ -28,7 +28,7 @@ var require_package = __commonJS({
|
|
|
28
28
|
"package.json"(exports, module) {
|
|
29
29
|
module.exports = {
|
|
30
30
|
name: "@virtuals-protocol/acp-node",
|
|
31
|
-
version: "0.3.0-beta.
|
|
31
|
+
version: "0.3.0-beta.7",
|
|
32
32
|
main: "./dist/index.js",
|
|
33
33
|
module: "./dist/index.mjs",
|
|
34
34
|
types: "./dist/index.d.ts",
|
|
@@ -3014,7 +3014,7 @@ var BaseAcpContractClient = class {
|
|
|
3014
3014
|
get walletAddress() {
|
|
3015
3015
|
return this.agentWalletAddress;
|
|
3016
3016
|
}
|
|
3017
|
-
createJobWithAccount(accountId,
|
|
3017
|
+
createJobWithAccount(accountId, evaluatorAddress, budgetBaseUnit, paymentTokenAddress, expiredAt) {
|
|
3018
3018
|
try {
|
|
3019
3019
|
const data = encodeFunctionData({
|
|
3020
3020
|
abi: this.abi,
|
|
@@ -3229,6 +3229,94 @@ function preparePayload(payload) {
|
|
|
3229
3229
|
return typeof payload === "string" ? payload : JSON.stringify(payload);
|
|
3230
3230
|
}
|
|
3231
3231
|
|
|
3232
|
+
// src/acpJobOffering.ts
|
|
3233
|
+
import { zeroAddress } from "viem";
|
|
3234
|
+
import Ajv from "ajv";
|
|
3235
|
+
var AcpJobOffering = class {
|
|
3236
|
+
constructor(acpClient, acpContractClient, providerAddress, name, price, priceType = "fixed" /* FIXED */, requirement) {
|
|
3237
|
+
this.acpClient = acpClient;
|
|
3238
|
+
this.acpContractClient = acpContractClient;
|
|
3239
|
+
this.providerAddress = providerAddress;
|
|
3240
|
+
this.name = name;
|
|
3241
|
+
this.price = price;
|
|
3242
|
+
this.priceType = priceType;
|
|
3243
|
+
this.requirement = requirement;
|
|
3244
|
+
this.ajv = new Ajv({ allErrors: true });
|
|
3245
|
+
}
|
|
3246
|
+
initiateJob(_0, _1) {
|
|
3247
|
+
return __async(this, arguments, function* (serviceRequirement, evaluatorAddress, expiredAt = new Date(Date.now() + 1e3 * 60 * 60 * 24)) {
|
|
3248
|
+
if (this.requirement && typeof this.requirement === "object") {
|
|
3249
|
+
const validator = this.ajv.compile(this.requirement);
|
|
3250
|
+
const valid = validator(serviceRequirement);
|
|
3251
|
+
if (!valid) {
|
|
3252
|
+
throw new acpError_default(this.ajv.errorsText(validator.errors));
|
|
3253
|
+
}
|
|
3254
|
+
}
|
|
3255
|
+
const finalServiceRequirement = {
|
|
3256
|
+
name: this.name,
|
|
3257
|
+
requirement: serviceRequirement,
|
|
3258
|
+
priceValue: this.price,
|
|
3259
|
+
priceType: this.priceType
|
|
3260
|
+
};
|
|
3261
|
+
const fareAmount = new FareAmount(
|
|
3262
|
+
this.priceType === "fixed" /* FIXED */ ? this.price : 0,
|
|
3263
|
+
this.acpContractClient.config.baseFare
|
|
3264
|
+
);
|
|
3265
|
+
const account = yield this.acpClient.getByClientAndProvider(
|
|
3266
|
+
this.acpContractClient.walletAddress,
|
|
3267
|
+
this.providerAddress,
|
|
3268
|
+
this.acpContractClient
|
|
3269
|
+
);
|
|
3270
|
+
const createJobPayload = [
|
|
3271
|
+
baseSepoliaAcpConfig.contractAddress,
|
|
3272
|
+
baseAcpConfig.contractAddress
|
|
3273
|
+
].includes(this.acpContractClient.config.contractAddress) || !account ? yield this.acpContractClient.createJob(
|
|
3274
|
+
this.providerAddress,
|
|
3275
|
+
evaluatorAddress || this.acpContractClient.walletAddress,
|
|
3276
|
+
expiredAt,
|
|
3277
|
+
fareAmount.fare.contractAddress,
|
|
3278
|
+
fareAmount.amount,
|
|
3279
|
+
""
|
|
3280
|
+
) : yield this.acpContractClient.createJobWithAccount(
|
|
3281
|
+
account.id,
|
|
3282
|
+
evaluatorAddress || zeroAddress,
|
|
3283
|
+
fareAmount.amount,
|
|
3284
|
+
fareAmount.fare.contractAddress,
|
|
3285
|
+
expiredAt
|
|
3286
|
+
);
|
|
3287
|
+
const createJobTxnHash = yield this.acpContractClient.handleOperation([
|
|
3288
|
+
createJobPayload
|
|
3289
|
+
]);
|
|
3290
|
+
const jobId = yield this.acpContractClient.getJobId(
|
|
3291
|
+
createJobTxnHash,
|
|
3292
|
+
this.acpContractClient.walletAddress,
|
|
3293
|
+
this.providerAddress
|
|
3294
|
+
);
|
|
3295
|
+
const payloads = [];
|
|
3296
|
+
const setBudgetWithPaymentTokenPayload = this.acpContractClient.setBudgetWithPaymentToken(
|
|
3297
|
+
jobId,
|
|
3298
|
+
fareAmount.amount,
|
|
3299
|
+
fareAmount.fare.contractAddress
|
|
3300
|
+
);
|
|
3301
|
+
if (setBudgetWithPaymentTokenPayload) {
|
|
3302
|
+
payloads.push(setBudgetWithPaymentTokenPayload);
|
|
3303
|
+
}
|
|
3304
|
+
payloads.push(
|
|
3305
|
+
this.acpContractClient.createMemo(
|
|
3306
|
+
jobId,
|
|
3307
|
+
JSON.stringify(finalServiceRequirement),
|
|
3308
|
+
0 /* MESSAGE */,
|
|
3309
|
+
true,
|
|
3310
|
+
1 /* NEGOTIATION */
|
|
3311
|
+
)
|
|
3312
|
+
);
|
|
3313
|
+
yield this.acpContractClient.handleOperation(payloads);
|
|
3314
|
+
return jobId;
|
|
3315
|
+
});
|
|
3316
|
+
}
|
|
3317
|
+
};
|
|
3318
|
+
var acpJobOffering_default = AcpJobOffering;
|
|
3319
|
+
|
|
3232
3320
|
// src/acpJob.ts
|
|
3233
3321
|
var AcpJob = class {
|
|
3234
3322
|
constructor(acpClient, id, clientAddress, providerAddress, evaluatorAddress, price, priceTokenAddress, memos, phase, context, contractAddress) {
|
|
@@ -3243,6 +3331,8 @@ var AcpJob = class {
|
|
|
3243
3331
|
this.phase = phase;
|
|
3244
3332
|
this.context = context;
|
|
3245
3333
|
this.contractAddress = contractAddress;
|
|
3334
|
+
this.priceType = "fixed" /* FIXED */;
|
|
3335
|
+
this.priceValue = 0;
|
|
3246
3336
|
var _a;
|
|
3247
3337
|
const content = (_a = this.memos.find(
|
|
3248
3338
|
(m) => m.nextPhase === 1 /* NEGOTIATION */
|
|
@@ -3260,6 +3350,12 @@ var AcpJob = class {
|
|
|
3260
3350
|
if (contentObj.serviceName || contentObj.name) {
|
|
3261
3351
|
this.name = contentObj.name || contentObj.serviceName;
|
|
3262
3352
|
}
|
|
3353
|
+
if (contentObj.priceType) {
|
|
3354
|
+
this.priceType = contentObj.priceType || "fixed" /* FIXED */;
|
|
3355
|
+
}
|
|
3356
|
+
if (contentObj.priceValue) {
|
|
3357
|
+
this.priceValue = contentObj.priceValue || this.price;
|
|
3358
|
+
}
|
|
3263
3359
|
}
|
|
3264
3360
|
get acpContractClient() {
|
|
3265
3361
|
return this.acpClient.contractClientByAddress(this.contractAddress);
|
|
@@ -3332,8 +3428,8 @@ var AcpJob = class {
|
|
|
3332
3428
|
content,
|
|
3333
3429
|
amount.amount,
|
|
3334
3430
|
recipient,
|
|
3335
|
-
feeAmount.amount,
|
|
3336
|
-
0 /* NO_FEE */,
|
|
3431
|
+
this.priceType === "percentage" /* PERCENTAGE */ ? BigInt(this.priceValue * 1e4) : feeAmount.amount,
|
|
3432
|
+
this.priceType === "percentage" /* PERCENTAGE */ ? 3 /* PERCENTAGE_FEE */ : 0 /* NO_FEE */,
|
|
3337
3433
|
2 /* TRANSACTION */,
|
|
3338
3434
|
type,
|
|
3339
3435
|
expiredAt,
|
|
@@ -3608,92 +3704,6 @@ var AcpMemo = class {
|
|
|
3608
3704
|
};
|
|
3609
3705
|
var acpMemo_default = AcpMemo;
|
|
3610
3706
|
|
|
3611
|
-
// src/acpJobOffering.ts
|
|
3612
|
-
import { zeroAddress } from "viem";
|
|
3613
|
-
import Ajv from "ajv";
|
|
3614
|
-
var AcpJobOffering = class {
|
|
3615
|
-
constructor(acpClient, acpContractClient, providerAddress, name, price, requirement) {
|
|
3616
|
-
this.acpClient = acpClient;
|
|
3617
|
-
this.acpContractClient = acpContractClient;
|
|
3618
|
-
this.providerAddress = providerAddress;
|
|
3619
|
-
this.name = name;
|
|
3620
|
-
this.price = price;
|
|
3621
|
-
this.requirement = requirement;
|
|
3622
|
-
this.ajv = new Ajv({ allErrors: true });
|
|
3623
|
-
}
|
|
3624
|
-
initiateJob(_0, _1) {
|
|
3625
|
-
return __async(this, arguments, function* (serviceRequirement, evaluatorAddress, expiredAt = new Date(Date.now() + 1e3 * 60 * 60 * 24)) {
|
|
3626
|
-
if (this.requirement && typeof this.requirement === "object") {
|
|
3627
|
-
const validator = this.ajv.compile(this.requirement);
|
|
3628
|
-
const valid = validator(serviceRequirement);
|
|
3629
|
-
if (!valid) {
|
|
3630
|
-
throw new acpError_default(this.ajv.errorsText(validator.errors));
|
|
3631
|
-
}
|
|
3632
|
-
}
|
|
3633
|
-
const finalServiceRequirement = {
|
|
3634
|
-
name: this.name,
|
|
3635
|
-
requirement: serviceRequirement
|
|
3636
|
-
};
|
|
3637
|
-
const fareAmount = new FareAmount(
|
|
3638
|
-
this.price,
|
|
3639
|
-
this.acpContractClient.config.baseFare
|
|
3640
|
-
);
|
|
3641
|
-
const account = yield this.acpClient.getByClientAndProvider(
|
|
3642
|
-
this.acpContractClient.walletAddress,
|
|
3643
|
-
this.providerAddress,
|
|
3644
|
-
this.acpContractClient
|
|
3645
|
-
);
|
|
3646
|
-
const createJobPayload = [
|
|
3647
|
-
baseSepoliaAcpConfig.contractAddress,
|
|
3648
|
-
baseAcpConfig.contractAddress
|
|
3649
|
-
].includes(this.acpContractClient.config.contractAddress) || !account ? yield this.acpContractClient.createJob(
|
|
3650
|
-
this.providerAddress,
|
|
3651
|
-
evaluatorAddress || this.acpContractClient.walletAddress,
|
|
3652
|
-
expiredAt,
|
|
3653
|
-
fareAmount.fare.contractAddress,
|
|
3654
|
-
fareAmount.amount,
|
|
3655
|
-
""
|
|
3656
|
-
) : yield this.acpContractClient.createJobWithAccount(
|
|
3657
|
-
account.id,
|
|
3658
|
-
this.providerAddress,
|
|
3659
|
-
evaluatorAddress || zeroAddress,
|
|
3660
|
-
fareAmount.amount,
|
|
3661
|
-
fareAmount.fare.contractAddress,
|
|
3662
|
-
expiredAt
|
|
3663
|
-
);
|
|
3664
|
-
const createJobTxnHash = yield this.acpContractClient.handleOperation([
|
|
3665
|
-
createJobPayload
|
|
3666
|
-
]);
|
|
3667
|
-
const jobId = yield this.acpContractClient.getJobId(
|
|
3668
|
-
createJobTxnHash,
|
|
3669
|
-
this.acpContractClient.walletAddress,
|
|
3670
|
-
this.providerAddress
|
|
3671
|
-
);
|
|
3672
|
-
const payloads = [];
|
|
3673
|
-
const setBudgetWithPaymentTokenPayload = this.acpContractClient.setBudgetWithPaymentToken(
|
|
3674
|
-
jobId,
|
|
3675
|
-
fareAmount.amount,
|
|
3676
|
-
fareAmount.fare.contractAddress
|
|
3677
|
-
);
|
|
3678
|
-
if (setBudgetWithPaymentTokenPayload) {
|
|
3679
|
-
payloads.push(setBudgetWithPaymentTokenPayload);
|
|
3680
|
-
}
|
|
3681
|
-
payloads.push(
|
|
3682
|
-
this.acpContractClient.createMemo(
|
|
3683
|
-
jobId,
|
|
3684
|
-
JSON.stringify(finalServiceRequirement),
|
|
3685
|
-
0 /* MESSAGE */,
|
|
3686
|
-
true,
|
|
3687
|
-
1 /* NEGOTIATION */
|
|
3688
|
-
)
|
|
3689
|
-
);
|
|
3690
|
-
yield this.acpContractClient.handleOperation(payloads);
|
|
3691
|
-
return jobId;
|
|
3692
|
-
});
|
|
3693
|
-
}
|
|
3694
|
-
};
|
|
3695
|
-
var acpJobOffering_default = AcpJobOffering;
|
|
3696
|
-
|
|
3697
3707
|
// src/acpAccount.ts
|
|
3698
3708
|
var AcpAccount = class {
|
|
3699
3709
|
constructor(contractClient, id, clientAddress, providerAddress, metadata) {
|
|
@@ -3914,7 +3924,8 @@ var AcpClient = class {
|
|
|
3914
3924
|
acpContractClient,
|
|
3915
3925
|
agent.walletAddress,
|
|
3916
3926
|
jobs.name,
|
|
3917
|
-
jobs.
|
|
3927
|
+
jobs.priceV2.value,
|
|
3928
|
+
jobs.priceV2.type,
|
|
3918
3929
|
jobs.requirement
|
|
3919
3930
|
);
|
|
3920
3931
|
}),
|
|
@@ -3955,7 +3966,6 @@ var AcpClient = class {
|
|
|
3955
3966
|
""
|
|
3956
3967
|
) : yield this.acpContractClient.createJobWithAccount(
|
|
3957
3968
|
account.id,
|
|
3958
|
-
providerAddress,
|
|
3959
3969
|
evaluatorAddress || defaultEvaluatorAddress,
|
|
3960
3970
|
fareAmount.amount,
|
|
3961
3971
|
fareAmount.fare.contractAddress,
|
|
@@ -4501,7 +4511,7 @@ var AcpContractClient = class _AcpContractClient extends baseAcpContractClient_d
|
|
|
4501
4511
|
throw new acpError_default("Failed to create payable memo", error);
|
|
4502
4512
|
}
|
|
4503
4513
|
}
|
|
4504
|
-
createJobWithAccount(accountId,
|
|
4514
|
+
createJobWithAccount(accountId, evaluatorAddress, budgetBaseUnit, paymentTokenAddress, expiredAt) {
|
|
4505
4515
|
throw new acpError_default("Not Supported");
|
|
4506
4516
|
}
|
|
4507
4517
|
updateAccountMetadata(accountId, metadata) {
|