@virtuals-protocol/acp-node 0.3.0-beta.14 → 0.3.0-beta.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs 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.14",
11
+ version: "0.3.0-beta.16",
12
12
  main: "./dist/index.js",
13
13
  module: "./dist/index.mjs",
14
14
  types: "./dist/index.d.ts",
@@ -3927,6 +3927,7 @@ var AcpJobOffering = class {
3927
3927
  var acpJobOffering_default = AcpJobOffering;
3928
3928
 
3929
3929
  // src/acpJob.ts
3930
+ import * as util from "util";
3930
3931
  var AcpJob = class {
3931
3932
  constructor(acpClient, id, clientAddress, providerAddress, evaluatorAddress, price, priceTokenAddress, memos, phase, context, contractAddress, netPayableAmount) {
3932
3933
  this.acpClient = acpClient;
@@ -4301,10 +4302,28 @@ var AcpJob = class {
4301
4302
  waitMs = Math.min(waitMs * 2, maxWaitMs);
4302
4303
  }
4303
4304
  }
4305
+ [util.inspect.custom]() {
4306
+ return {
4307
+ id: this.id,
4308
+ clientAddress: this.clientAddress,
4309
+ providerAddress: this.providerAddress,
4310
+ name: this.name,
4311
+ requirement: this.requirement,
4312
+ priceType: this.priceType,
4313
+ priceValue: this.priceValue,
4314
+ priceTokenAddress: this.priceTokenAddress,
4315
+ memos: this.memos,
4316
+ phase: this.phase,
4317
+ context: this.context,
4318
+ contractAddress: this.contractAddress,
4319
+ netPayableAmount: this.netPayableAmount
4320
+ };
4321
+ }
4304
4322
  };
4305
4323
  var acpJob_default = AcpJob;
4306
4324
 
4307
4325
  // src/acpMemo.ts
4326
+ import util2 from "util";
4308
4327
  var AcpMemo = class {
4309
4328
  constructor(contractClient, id, type, content, nextPhase, status, senderAddress, signedReason, expiry, payableDetails, txHash, signedTxHash) {
4310
4329
  this.contractClient = contractClient;
@@ -4344,6 +4363,21 @@ var AcpMemo = class {
4344
4363
  const payload = this.contractClient.signMemo(this.id, approved, reason);
4345
4364
  return await this.contractClient.handleOperation([payload]);
4346
4365
  }
4366
+ [util2.inspect.custom]() {
4367
+ return {
4368
+ id: this.id,
4369
+ senderAddress: this.senderAddress,
4370
+ type: MemoType[this.type],
4371
+ status: this.status,
4372
+ content: this.content,
4373
+ signedReason: this.signedReason,
4374
+ txHash: this.txHash,
4375
+ signedTxHash: this.signedTxHash,
4376
+ nextPhase: AcpJobPhases[this.nextPhase],
4377
+ expiry: this.expiry,
4378
+ payableDetails: this.payableDetails
4379
+ };
4380
+ }
4347
4381
  };
4348
4382
  var acpMemo_default = AcpMemo;
4349
4383
 
@@ -4373,8 +4407,8 @@ var AcpClient = class {
4373
4407
  if (this.contractClients.length === 0) {
4374
4408
  throw new acpError_default("ACP contract client is required");
4375
4409
  }
4376
- this.contractClients.every((client) => {
4377
- if (client.contractAddress !== this.contractClients[0].contractAddress) {
4410
+ this.contractClients.forEach((client) => {
4411
+ if (client.walletAddress !== this.contractClients[0].walletAddress) {
4378
4412
  throw new acpError_default(
4379
4413
  "All contract clients must have the same agent wallet address"
4380
4414
  );
@@ -4382,7 +4416,7 @@ var AcpClient = class {
4382
4416
  });
4383
4417
  this.onNewTask = options.onNewTask;
4384
4418
  this.onEvaluate = options.onEvaluate || this.defaultOnEvaluate;
4385
- this.init();
4419
+ this.init(options.skipSocketConnection);
4386
4420
  }
4387
4421
  contractClientByAddress(address) {
4388
4422
  if (!address) {
@@ -4406,12 +4440,12 @@ var AcpClient = class {
4406
4440
  await job.evaluate(true, "Evaluated by default");
4407
4441
  }
4408
4442
  get walletAddress() {
4409
- if (Array.isArray(this.acpContractClient)) {
4410
- return this.acpContractClient[0].walletAddress;
4411
- }
4412
4443
  return this.acpContractClient.walletAddress;
4413
4444
  }
4414
- async init() {
4445
+ async init(skipSocketConnection = false) {
4446
+ if (skipSocketConnection) {
4447
+ return;
4448
+ }
4415
4449
  const socket = io(this.acpUrl, {
4416
4450
  auth: {
4417
4451
  walletAddress: this.walletAddress
@@ -4517,7 +4551,7 @@ var AcpClient = class {
4517
4551
  process.on("SIGTERM", cleanup);
4518
4552
  }
4519
4553
  async browseAgents(keyword, options) {
4520
- let { cluster, sort_by, top_k, graduationStatus, onlineStatus } = options;
4554
+ let { cluster, sort_by, top_k, graduationStatus, onlineStatus, showHiddenOfferings } = options;
4521
4555
  top_k = top_k ?? 5;
4522
4556
  let url = `${this.acpUrl}/api/agents/v4/search?search=${keyword}`;
4523
4557
  if (sort_by && sort_by.length > 0) {
@@ -4538,6 +4572,9 @@ var AcpClient = class {
4538
4572
  if (onlineStatus) {
4539
4573
  url += `&onlineStatus=${onlineStatus}`;
4540
4574
  }
4575
+ if (showHiddenOfferings) {
4576
+ url += `&showHiddenOfferings=${showHiddenOfferings}`;
4577
+ }
4541
4578
  const response = await fetch(url);
4542
4579
  const data = await response.json();
4543
4580
  const availableContractClientAddresses = this.contractClients.map(
@@ -4575,7 +4612,7 @@ var AcpClient = class {
4575
4612
  twitterHandle: agent.twitterHandle,
4576
4613
  walletAddress: agent.walletAddress,
4577
4614
  metrics: agent.metrics,
4578
- resource: agent.resources
4615
+ resources: agent.resources
4579
4616
  };
4580
4617
  });
4581
4618
  }
@@ -4646,209 +4683,142 @@ var AcpClient = class {
4646
4683
  return jobId;
4647
4684
  }
4648
4685
  async getActiveJobs(page = 1, pageSize = 10) {
4649
- let url = `${this.acpUrl}/api/jobs/active?pagination[page]=${page}&pagination[pageSize]=${pageSize}`;
4650
- try {
4651
- const response = await fetch(url, {
4652
- headers: {
4653
- "wallet-address": this.walletAddress
4654
- }
4655
- });
4656
- const data = await response.json();
4657
- if (data.error) {
4658
- throw new acpError_default(data.error.message);
4659
- }
4660
- return data.data.map((job) => {
4661
- return new acpJob_default(
4662
- this,
4663
- job.id,
4664
- job.clientAddress,
4665
- job.providerAddress,
4666
- job.evaluatorAddress,
4667
- job.price,
4668
- job.priceTokenAddress,
4669
- job.memos.map((memo) => {
4670
- return new acpMemo_default(
4671
- this.contractClientByAddress(job.contractAddress),
4672
- memo.id,
4673
- memo.memoType,
4674
- memo.content,
4675
- memo.nextPhase,
4676
- memo.status,
4677
- memo.senderAddress,
4678
- memo.signedReason,
4679
- memo.expiry ? new Date(parseInt(memo.expiry) * 1e3) : void 0,
4680
- memo.payableDetails,
4681
- memo.txHash,
4682
- memo.signedTxHash
4683
- );
4684
- }),
4685
- job.phase,
4686
- job.context,
4687
- job.contractAddress,
4688
- job.netPayableAmount
4689
- );
4690
- });
4691
- } catch (error) {
4692
- throw new acpError_default("Failed to get active jobs", error);
4693
- }
4686
+ const url = `${this.acpUrl}/api/jobs/active?pagination[page]=${page}&pagination[pageSize]=${pageSize}`;
4687
+ const rawJobs = await this._fetchJobList(url);
4688
+ return this._hydrateJobs(rawJobs, { logPrefix: "Active jobs" });
4694
4689
  }
4695
4690
  async getPendingMemoJobs(page = 1, pageSize = 10) {
4696
- let url = `${this.acpUrl}/api/jobs/pending-memos?pagination[page]=${page}&pagination[pageSize]=${pageSize}`;
4697
- try {
4698
- const response = await fetch(url, {
4699
- headers: {
4700
- "wallet-address": this.acpContractClient.walletAddress
4701
- }
4702
- });
4703
- const data = await response.json();
4704
- if (data.error) {
4705
- throw new acpError_default(data.error.message);
4706
- }
4707
- return data.data.map((job) => {
4708
- return new acpJob_default(
4709
- this,
4710
- job.id,
4711
- job.clientAddress,
4712
- job.providerAddress,
4713
- job.evaluatorAddress,
4714
- job.price,
4715
- job.priceTokenAddress,
4716
- job.memos.map((memo) => {
4717
- return new acpMemo_default(
4718
- this.contractClientByAddress(job.contractAddress),
4719
- memo.id,
4720
- memo.memoType,
4721
- memo.content,
4722
- memo.nextPhase,
4723
- memo.status,
4724
- memo.senderAddress,
4725
- memo.signedReason,
4726
- memo.expiry ? new Date(parseInt(memo.expiry) * 1e3) : void 0,
4727
- typeof memo.payableDetails === "string" ? tryParseJson(memo.payableDetails) || void 0 : memo.payableDetails,
4728
- memo.txHash,
4729
- memo.signedTxHash
4730
- );
4731
- }),
4732
- job.phase,
4733
- job.context,
4734
- job.contractAddress,
4735
- job.netPayableAmount
4736
- );
4737
- });
4738
- } catch (error) {
4739
- throw new acpError_default("Failed to get pending memo jobs", error);
4740
- }
4691
+ const url = `${this.acpUrl}/api/jobs/pending-memos?pagination[page]=${page}&pagination[pageSize]=${pageSize}`;
4692
+ const rawJobs = await this._fetchJobList(url);
4693
+ return this._hydrateJobs(rawJobs, { logPrefix: "Pending memo jobs" });
4741
4694
  }
4742
4695
  async getCompletedJobs(page = 1, pageSize = 10) {
4743
- let url = `${this.acpUrl}/api/jobs/completed?pagination[page]=${page}&pagination[pageSize]=${pageSize}`;
4744
- try {
4745
- const response = await fetch(url, {
4746
- headers: {
4747
- "wallet-address": this.acpContractClient.walletAddress
4748
- }
4749
- });
4750
- const data = await response.json();
4751
- if (data.error) {
4752
- throw new acpError_default(data.error.message);
4753
- }
4754
- return data.data.map((job) => {
4755
- return new acpJob_default(
4756
- this,
4757
- job.id,
4758
- job.clientAddress,
4759
- job.providerAddress,
4760
- job.evaluatorAddress,
4761
- job.price,
4762
- job.priceTokenAddress,
4763
- job.memos.map((memo) => {
4764
- return new acpMemo_default(
4765
- this.contractClientByAddress(job.contractAddress),
4766
- memo.id,
4767
- memo.memoType,
4768
- memo.content,
4769
- memo.nextPhase,
4770
- memo.status,
4771
- memo.senderAddress,
4772
- memo.signedReason,
4773
- memo.expiry ? new Date(parseInt(memo.expiry) * 1e3) : void 0,
4774
- memo.payableDetails,
4775
- memo.txHash,
4776
- memo.signedTxHash
4777
- );
4778
- }),
4779
- job.phase,
4780
- job.context,
4781
- job.contractAddress,
4782
- job.netPayableAmount
4783
- );
4784
- });
4785
- } catch (error) {
4786
- throw new acpError_default("Failed to get completed jobs", error);
4787
- }
4696
+ const url = `${this.acpUrl}/api/jobs/completed?pagination[page]=${page}&pagination[pageSize]=${pageSize}`;
4697
+ const rawJobs = await this._fetchJobList(url);
4698
+ return this._hydrateJobs(rawJobs, { logPrefix: "Completed jobs" });
4788
4699
  }
4789
4700
  async getCancelledJobs(page = 1, pageSize = 10) {
4790
- let url = `${this.acpUrl}/api/jobs/cancelled?pagination[page]=${page}&pagination[pageSize]=${pageSize}`;
4701
+ const url = `${this.acpUrl}/api/jobs/cancelled?pagination[page]=${page}&pagination[pageSize]=${pageSize}`;
4702
+ const rawJobs = await this._fetchJobList(url);
4703
+ return this._hydrateJobs(rawJobs, { logPrefix: "Cancelled jobs" });
4704
+ }
4705
+ async _fetchJobList(url) {
4706
+ let response;
4791
4707
  try {
4792
- const response = await fetch(url, {
4708
+ response = await fetch(url, {
4793
4709
  headers: {
4794
4710
  "wallet-address": this.walletAddress
4795
4711
  }
4796
4712
  });
4797
- const data = await response.json();
4798
- if (data.error) {
4799
- throw new acpError_default(data.error.message);
4800
- }
4801
- return data.data.map((job) => {
4802
- return new acpJob_default(
4803
- this,
4804
- job.id,
4805
- job.clientAddress,
4806
- job.providerAddress,
4807
- job.evaluatorAddress,
4808
- job.price,
4809
- job.priceTokenAddress,
4810
- job.memos.map((memo) => {
4811
- return new acpMemo_default(
4812
- this.contractClientByAddress(job.contractAddress),
4813
- memo.id,
4814
- memo.memoType,
4815
- memo.content,
4816
- memo.nextPhase,
4817
- memo.status,
4818
- memo.senderAddress,
4819
- memo.signedReason,
4820
- memo.expiry ? new Date(parseInt(memo.expiry) * 1e3) : void 0,
4821
- memo.payableDetails,
4822
- memo.txHash,
4823
- memo.signedTxHash
4824
- );
4825
- }),
4826
- job.phase,
4827
- job.context,
4828
- job.contractAddress,
4829
- job.netPayableAmount
4713
+ } catch (err) {
4714
+ throw new acpError_default("Failed to fetch ACP jobs (network error)", err);
4715
+ }
4716
+ let data;
4717
+ try {
4718
+ data = await response.json();
4719
+ } catch (err) {
4720
+ throw new acpError_default("Failed to parse ACP jobs response", err);
4721
+ }
4722
+ if (data.error) {
4723
+ throw new acpError_default(data.error.message);
4724
+ }
4725
+ return data.data;
4726
+ }
4727
+ _hydrateJobs(rawJobs, options) {
4728
+ const jobs = [];
4729
+ const errors = [];
4730
+ for (const job of rawJobs) {
4731
+ try {
4732
+ const memos = job.memos.map(
4733
+ (memo) => new acpMemo_default(
4734
+ this.contractClientByAddress(job.contractAddress),
4735
+ memo.id,
4736
+ memo.memoType,
4737
+ memo.content,
4738
+ memo.nextPhase,
4739
+ memo.status,
4740
+ memo.senderAddress,
4741
+ memo.signedReason,
4742
+ memo.expiry ? new Date(parseInt(memo.expiry) * 1e3) : void 0,
4743
+ memo.payableDetails,
4744
+ memo.txHash,
4745
+ memo.signedTxHash
4746
+ )
4830
4747
  );
4831
- });
4832
- } catch (error) {
4833
- throw new acpError_default("Failed to get cancelled jobs", error);
4748
+ jobs.push(
4749
+ new acpJob_default(
4750
+ this,
4751
+ job.id,
4752
+ job.clientAddress,
4753
+ job.providerAddress,
4754
+ job.evaluatorAddress,
4755
+ job.price,
4756
+ job.priceTokenAddress,
4757
+ memos,
4758
+ job.phase,
4759
+ job.context,
4760
+ job.contractAddress,
4761
+ job.netPayableAmount
4762
+ )
4763
+ );
4764
+ } catch (err) {
4765
+ errors.push({ jobId: job.id, error: err });
4766
+ }
4767
+ }
4768
+ if (errors.length > 0) {
4769
+ console.warn(
4770
+ `${options?.logPrefix ?? "Skipped"} ${errors.length} malformed job(s)
4771
+ ` + JSON.stringify(
4772
+ errors.map((e) => ({ jobId: e.jobId, message: e.error.message })),
4773
+ null,
4774
+ 2
4775
+ )
4776
+ );
4834
4777
  }
4778
+ return jobs;
4835
4779
  }
4836
4780
  async getJobById(jobId) {
4837
- let url = `${this.acpUrl}/api/jobs/${jobId}`;
4781
+ const url = `${this.acpUrl}/api/jobs/${jobId}`;
4782
+ let response;
4838
4783
  try {
4839
- const response = await fetch(url, {
4784
+ response = await fetch(url, {
4840
4785
  headers: {
4841
4786
  "wallet-address": this.acpContractClient.walletAddress
4842
4787
  }
4843
4788
  });
4844
- const data = await response.json();
4845
- if (data.error) {
4846
- throw new acpError_default(data.error.message);
4847
- }
4848
- const job = data.data;
4849
- if (!job) {
4850
- return;
4851
- }
4789
+ } catch (err) {
4790
+ throw new acpError_default("Failed to fetch job by id (network error)", err);
4791
+ }
4792
+ let data;
4793
+ try {
4794
+ data = await response.json();
4795
+ } catch (err) {
4796
+ throw new acpError_default("Failed to parse job by id response", err);
4797
+ }
4798
+ if (data.error) {
4799
+ throw new acpError_default(data.error.message);
4800
+ }
4801
+ const job = data.data;
4802
+ if (!job) {
4803
+ return void 0;
4804
+ }
4805
+ try {
4806
+ const memos = job.memos.map(
4807
+ (memo) => new acpMemo_default(
4808
+ this.contractClientByAddress(job.contractAddress),
4809
+ memo.id,
4810
+ memo.memoType,
4811
+ memo.content,
4812
+ memo.nextPhase,
4813
+ memo.status,
4814
+ memo.senderAddress,
4815
+ memo.signedReason,
4816
+ memo.expiry ? new Date(parseInt(memo.expiry) * 1e3) : void 0,
4817
+ memo.payableDetails,
4818
+ memo.txHash,
4819
+ memo.signedTxHash
4820
+ )
4821
+ );
4852
4822
  return new acpJob_default(
4853
4823
  this,
4854
4824
  job.id,
@@ -4857,47 +4827,42 @@ var AcpClient = class {
4857
4827
  job.evaluatorAddress,
4858
4828
  job.price,
4859
4829
  job.priceTokenAddress,
4860
- job.memos.map((memo) => {
4861
- return new acpMemo_default(
4862
- this.contractClientByAddress(job.contractAddress),
4863
- memo.id,
4864
- memo.memoType,
4865
- memo.content,
4866
- memo.nextPhase,
4867
- memo.status,
4868
- memo.senderAddress,
4869
- memo.signedReason,
4870
- memo.expiry ? new Date(parseInt(memo.expiry) * 1e3) : void 0,
4871
- memo.payableDetails,
4872
- memo.txHash,
4873
- memo.signedTxHash
4874
- );
4875
- }),
4830
+ memos,
4876
4831
  job.phase,
4877
4832
  job.context,
4878
4833
  job.contractAddress,
4879
4834
  job.netPayableAmount
4880
4835
  );
4881
- } catch (error) {
4882
- throw new acpError_default("Failed to get job by id", error);
4836
+ } catch (err) {
4837
+ throw new acpError_default(`Failed to hydrate job ${jobId}`, err);
4883
4838
  }
4884
4839
  }
4885
4840
  async getMemoById(jobId, memoId) {
4886
- let url = `${this.acpUrl}/api/jobs/${jobId}/memos/${memoId}`;
4841
+ const url = `${this.acpUrl}/api/jobs/${jobId}/memos/${memoId}`;
4842
+ let response;
4887
4843
  try {
4888
- const response = await fetch(url, {
4844
+ response = await fetch(url, {
4889
4845
  headers: {
4890
4846
  "wallet-address": this.walletAddress
4891
4847
  }
4892
4848
  });
4893
- const data = await response.json();
4894
- if (data.error) {
4895
- throw new acpError_default(data.error.message);
4896
- }
4897
- const memo = data.data;
4898
- if (!memo) {
4899
- return;
4900
- }
4849
+ } catch (err) {
4850
+ throw new acpError_default("Failed to fetch memo by id (network error)", err);
4851
+ }
4852
+ let data;
4853
+ try {
4854
+ data = await response.json();
4855
+ } catch (err) {
4856
+ throw new acpError_default("Failed to parse memo by id response", err);
4857
+ }
4858
+ if (data.error) {
4859
+ throw new acpError_default(data.error.message);
4860
+ }
4861
+ const memo = data.data;
4862
+ if (!memo) {
4863
+ return void 0;
4864
+ }
4865
+ try {
4901
4866
  return new acpMemo_default(
4902
4867
  this.contractClientByAddress(memo.contractAddress),
4903
4868
  memo.id,
@@ -4912,8 +4877,11 @@ var AcpClient = class {
4912
4877
  memo.txHash,
4913
4878
  memo.signedTxHash
4914
4879
  );
4915
- } catch (error) {
4916
- throw new acpError_default("Failed to get memo by id", error);
4880
+ } catch (err) {
4881
+ throw new acpError_default(
4882
+ `Failed to hydrate memo ${memoId} for job ${jobId}`,
4883
+ err
4884
+ );
4917
4885
  }
4918
4886
  }
4919
4887
  async getAgent(walletAddress) {
@@ -5157,7 +5125,7 @@ var AcpContractClient = class _AcpContractClient extends baseAcpContractClient_d
5157
5125
  );
5158
5126
  }
5159
5127
  await this.validateSessionKeyOnChain(sessionSignerAddress, sessionEntityKeyId);
5160
- console.log("Connected to ACP:", {
5128
+ console.log("Connected to ACP with v1 Contract Client (Legacy):", {
5161
5129
  agentWalletAddress: this.agentWalletAddress,
5162
5130
  whitelistedWalletAddress: sessionSignerAddress,
5163
5131
  entityId: sessionEntityKeyId
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@virtuals-protocol/acp-node",
3
- "version": "0.3.0-beta.14",
3
+ "version": "0.3.0-beta.16",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",