@virtuals-protocol/acp-node 0.3.0-beta.15 → 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.15",
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
 
@@ -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,221 +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
- if (error instanceof acpError_default) {
4693
- return error;
4694
- }
4695
- throw new acpError_default("Failed to get active jobs", error);
4696
- }
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" });
4697
4689
  }
4698
4690
  async getPendingMemoJobs(page = 1, pageSize = 10) {
4699
- let url = `${this.acpUrl}/api/jobs/pending-memos?pagination[page]=${page}&pagination[pageSize]=${pageSize}`;
4700
- try {
4701
- const response = await fetch(url, {
4702
- headers: {
4703
- "wallet-address": this.acpContractClient.walletAddress
4704
- }
4705
- });
4706
- const data = await response.json();
4707
- if (data.error) {
4708
- throw new acpError_default(data.error.message);
4709
- }
4710
- return data.data.map((job) => {
4711
- return new acpJob_default(
4712
- this,
4713
- job.id,
4714
- job.clientAddress,
4715
- job.providerAddress,
4716
- job.evaluatorAddress,
4717
- job.price,
4718
- job.priceTokenAddress,
4719
- job.memos.map((memo) => {
4720
- return new acpMemo_default(
4721
- this.contractClientByAddress(job.contractAddress),
4722
- memo.id,
4723
- memo.memoType,
4724
- memo.content,
4725
- memo.nextPhase,
4726
- memo.status,
4727
- memo.senderAddress,
4728
- memo.signedReason,
4729
- memo.expiry ? new Date(parseInt(memo.expiry) * 1e3) : void 0,
4730
- typeof memo.payableDetails === "string" ? tryParseJson(memo.payableDetails) || void 0 : memo.payableDetails,
4731
- memo.txHash,
4732
- memo.signedTxHash
4733
- );
4734
- }),
4735
- job.phase,
4736
- job.context,
4737
- job.contractAddress,
4738
- job.netPayableAmount
4739
- );
4740
- });
4741
- } catch (error) {
4742
- if (error instanceof acpError_default) {
4743
- return error;
4744
- }
4745
- throw new acpError_default("Failed to get pending memo jobs", error);
4746
- }
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" });
4747
4694
  }
4748
4695
  async getCompletedJobs(page = 1, pageSize = 10) {
4749
- let url = `${this.acpUrl}/api/jobs/completed?pagination[page]=${page}&pagination[pageSize]=${pageSize}`;
4750
- try {
4751
- const response = await fetch(url, {
4752
- headers: {
4753
- "wallet-address": this.acpContractClient.walletAddress
4754
- }
4755
- });
4756
- const data = await response.json();
4757
- if (data.error) {
4758
- throw new acpError_default(data.error.message);
4759
- }
4760
- return data.data.map((job) => {
4761
- return new acpJob_default(
4762
- this,
4763
- job.id,
4764
- job.clientAddress,
4765
- job.providerAddress,
4766
- job.evaluatorAddress,
4767
- job.price,
4768
- job.priceTokenAddress,
4769
- job.memos.map((memo) => {
4770
- return new acpMemo_default(
4771
- this.contractClientByAddress(job.contractAddress),
4772
- memo.id,
4773
- memo.memoType,
4774
- memo.content,
4775
- memo.nextPhase,
4776
- memo.status,
4777
- memo.senderAddress,
4778
- memo.signedReason,
4779
- memo.expiry ? new Date(parseInt(memo.expiry) * 1e3) : void 0,
4780
- memo.payableDetails,
4781
- memo.txHash,
4782
- memo.signedTxHash
4783
- );
4784
- }),
4785
- job.phase,
4786
- job.context,
4787
- job.contractAddress,
4788
- job.netPayableAmount
4789
- );
4790
- });
4791
- } catch (error) {
4792
- if (error instanceof acpError_default) {
4793
- return error;
4794
- }
4795
- throw new acpError_default("Failed to get completed jobs", error);
4796
- }
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" });
4797
4699
  }
4798
4700
  async getCancelledJobs(page = 1, pageSize = 10) {
4799
- 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;
4800
4707
  try {
4801
- const response = await fetch(url, {
4708
+ response = await fetch(url, {
4802
4709
  headers: {
4803
4710
  "wallet-address": this.walletAddress
4804
4711
  }
4805
4712
  });
4806
- const data = await response.json();
4807
- if (data.error) {
4808
- throw new acpError_default(data.error.message);
4809
- }
4810
- return data.data.map((job) => {
4811
- return new acpJob_default(
4812
- this,
4813
- job.id,
4814
- job.clientAddress,
4815
- job.providerAddress,
4816
- job.evaluatorAddress,
4817
- job.price,
4818
- job.priceTokenAddress,
4819
- job.memos.map((memo) => {
4820
- return new acpMemo_default(
4821
- this.contractClientByAddress(job.contractAddress),
4822
- memo.id,
4823
- memo.memoType,
4824
- memo.content,
4825
- memo.nextPhase,
4826
- memo.status,
4827
- memo.senderAddress,
4828
- memo.signedReason,
4829
- memo.expiry ? new Date(parseInt(memo.expiry) * 1e3) : void 0,
4830
- memo.payableDetails,
4831
- memo.txHash,
4832
- memo.signedTxHash
4833
- );
4834
- }),
4835
- job.phase,
4836
- job.context,
4837
- job.contractAddress,
4838
- 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
+ )
4839
4747
  );
4840
- });
4841
- } catch (error) {
4842
- if (error instanceof Error) {
4843
- return 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 });
4844
4766
  }
4845
- throw new acpError_default("Failed to get cancelled jobs", error);
4846
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
+ );
4777
+ }
4778
+ return jobs;
4847
4779
  }
4848
4780
  async getJobById(jobId) {
4849
- let url = `${this.acpUrl}/api/jobs/${jobId}`;
4781
+ const url = `${this.acpUrl}/api/jobs/${jobId}`;
4782
+ let response;
4850
4783
  try {
4851
- const response = await fetch(url, {
4784
+ response = await fetch(url, {
4852
4785
  headers: {
4853
4786
  "wallet-address": this.acpContractClient.walletAddress
4854
4787
  }
4855
4788
  });
4856
- const data = await response.json();
4857
- if (data.error) {
4858
- throw new acpError_default(data.error.message);
4859
- }
4860
- const job = data.data;
4861
- if (!job) {
4862
- return;
4863
- }
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
+ );
4864
4822
  return new acpJob_default(
4865
4823
  this,
4866
4824
  job.id,
@@ -4869,50 +4827,42 @@ var AcpClient = class {
4869
4827
  job.evaluatorAddress,
4870
4828
  job.price,
4871
4829
  job.priceTokenAddress,
4872
- job.memos.map((memo) => {
4873
- return new acpMemo_default(
4874
- this.contractClientByAddress(job.contractAddress),
4875
- memo.id,
4876
- memo.memoType,
4877
- memo.content,
4878
- memo.nextPhase,
4879
- memo.status,
4880
- memo.senderAddress,
4881
- memo.signedReason,
4882
- memo.expiry ? new Date(parseInt(memo.expiry) * 1e3) : void 0,
4883
- memo.payableDetails,
4884
- memo.txHash,
4885
- memo.signedTxHash
4886
- );
4887
- }),
4830
+ memos,
4888
4831
  job.phase,
4889
4832
  job.context,
4890
4833
  job.contractAddress,
4891
4834
  job.netPayableAmount
4892
4835
  );
4893
- } catch (error) {
4894
- if (error instanceof acpError_default) {
4895
- return error;
4896
- }
4897
- 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);
4898
4838
  }
4899
4839
  }
4900
4840
  async getMemoById(jobId, memoId) {
4901
- let url = `${this.acpUrl}/api/jobs/${jobId}/memos/${memoId}`;
4841
+ const url = `${this.acpUrl}/api/jobs/${jobId}/memos/${memoId}`;
4842
+ let response;
4902
4843
  try {
4903
- const response = await fetch(url, {
4844
+ response = await fetch(url, {
4904
4845
  headers: {
4905
4846
  "wallet-address": this.walletAddress
4906
4847
  }
4907
4848
  });
4908
- const data = await response.json();
4909
- if (data.error) {
4910
- throw new acpError_default(data.error.message);
4911
- }
4912
- const memo = data.data;
4913
- if (!memo) {
4914
- return;
4915
- }
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 {
4916
4866
  return new acpMemo_default(
4917
4867
  this.contractClientByAddress(memo.contractAddress),
4918
4868
  memo.id,
@@ -4927,11 +4877,11 @@ var AcpClient = class {
4927
4877
  memo.txHash,
4928
4878
  memo.signedTxHash
4929
4879
  );
4930
- } catch (error) {
4931
- if (error instanceof acpError_default) {
4932
- return error;
4933
- }
4934
- 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
+ );
4935
4885
  }
4936
4886
  }
4937
4887
  async getAgent(walletAddress) {
@@ -5175,7 +5125,7 @@ var AcpContractClient = class _AcpContractClient extends baseAcpContractClient_d
5175
5125
  );
5176
5126
  }
5177
5127
  await this.validateSessionKeyOnChain(sessionSignerAddress, sessionEntityKeyId);
5178
- console.log("Connected to ACP:", {
5128
+ console.log("Connected to ACP with v1 Contract Client (Legacy):", {
5179
5129
  agentWalletAddress: this.agentWalletAddress,
5180
5130
  whitelistedWalletAddress: sessionSignerAddress,
5181
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.15",
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",