use-agently 0.16.0 → 0.18.0

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.
Files changed (2) hide show
  1. package/build/bin.js +76 -20
  2. package/package.json +2 -2
package/build/bin.js CHANGED
@@ -98456,10 +98456,16 @@ var CaseInsensitiveMap = class extends Map {
98456
98456
  return super.delete(this.normalizeKey(key));
98457
98457
  }
98458
98458
  };
98459
+
98460
+ // ../use-agently-sdk/utils/transaction.ts
98461
+ var DryRunTransaction = { mode: "dry-run" };
98462
+ function PayTransaction(wallet) {
98463
+ return { mode: "pay", wallet };
98464
+ }
98459
98465
  // ../use-agently-sdk/package.json
98460
98466
  var package_default = {
98461
98467
  name: "@use-agently/sdk",
98462
- version: "0.16.0",
98468
+ version: "0.18.0",
98463
98469
  description: "Core SDK for the Agently platform — wallet management, A2A, MCP, x402 payments",
98464
98470
  homepage: "https://github.com/AgentlyHQ/use-agently/tree/main/packages/use-agently-sdk",
98465
98471
  bugs: {
@@ -98574,6 +98580,11 @@ function createDryRunFetch(fetchImpl = clientFetch) {
98574
98580
  return response;
98575
98581
  };
98576
98582
  }
98583
+ function resolveFetchForTransaction(transaction = DryRunTransaction, fetchImpl) {
98584
+ if (transaction.mode === "dry-run")
98585
+ return createDryRunFetch(fetchImpl);
98586
+ return createPaymentFetch(transaction.wallet, fetchImpl);
98587
+ }
98577
98588
  function createPaymentFetch(wallet, fetchImpl = clientFetch) {
98578
98589
  return wrapFetchWithPaymentFromConfig(fetchImpl, {
98579
98590
  schemes: wallet.getX402Schemes()
@@ -98629,21 +98640,11 @@ async function resolveErc8004Agent(uri, fetchImpl = clientFetch) {
98629
98640
  }
98630
98641
  return agent;
98631
98642
  }
98632
- // ../use-agently-sdk/utils/transaction.ts
98633
- var DryRunTransaction = { mode: "dry-run" };
98634
- function PayTransaction(wallet) {
98635
- return { mode: "pay", wallet };
98636
- }
98637
98643
  // ../use-agently-sdk/a2a.ts
98638
98644
  import { randomUUID } from "node:crypto";
98639
98645
  function extractTextFromParts(parts) {
98640
98646
  return parts.filter((p) => p.kind === "text").map((p) => p.text).join("");
98641
98647
  }
98642
- function resolveFetchForTransaction(transaction = DryRunTransaction, fetchImpl) {
98643
- if (transaction.mode === "dry-run")
98644
- return createDryRunFetch(fetchImpl);
98645
- return createPaymentFetch(transaction.wallet, fetchImpl);
98646
- }
98647
98648
  function resolveAgentUrl(agentInput) {
98648
98649
  const isDirectUrl = agentInput.startsWith("http://") || agentInput.startsWith("https://");
98649
98650
  return isDirectUrl ? agentInput : `https://use-agently.com/${agentInput}/`;
@@ -100064,12 +100065,18 @@ function resolveMcpUrl(input) {
100064
100065
  async function createMcpClient(mcpUrl, options) {
100065
100066
  const client = new Client(options?.clientInfo ?? { name: "@use-agently/sdk", version: package_default.version });
100066
100067
  const transport = new StreamableHTTPClientTransport(new URL(mcpUrl), options?.fetchImpl ? { fetch: options.fetchImpl } : undefined);
100068
+ if (options?.wallet) {
100069
+ const x402Client2 = createMcpPaymentClient(client, options.wallet);
100070
+ await x402Client2.connect(transport);
100071
+ return x402Client2;
100072
+ }
100067
100073
  await client.connect(transport);
100068
100074
  return client;
100069
100075
  }
100070
100076
  async function listMcpTools(uri, options) {
100071
100077
  const mcpUrl = resolveMcpUrl(uri);
100072
- const client = await createMcpClient(mcpUrl, { clientInfo: options?.clientInfo, fetchImpl: options?.fetchImpl });
100078
+ const resolvedFetch = resolveFetchForTransaction(options?.transaction, options?.fetchImpl);
100079
+ const client = await createMcpClient(mcpUrl, { clientInfo: options?.clientInfo, fetchImpl: resolvedFetch });
100073
100080
  try {
100074
100081
  const { tools } = await client.listTools();
100075
100082
  return tools;
@@ -100080,16 +100087,20 @@ async function listMcpTools(uri, options) {
100080
100087
  async function callMcpTool(uri, tool, args, options) {
100081
100088
  const mcpUrl = resolveMcpUrl(uri);
100082
100089
  const transaction = options?.transaction ?? DryRunTransaction;
100090
+ const resolvedFetch = resolveFetchForTransaction(transaction, options?.fetchImpl);
100083
100091
  if (transaction.mode === "pay") {
100084
- const client2 = await createMcpClient(mcpUrl, { clientInfo: options?.clientInfo, fetchImpl: options?.fetchImpl });
100092
+ const x402Client2 = await createMcpClient(mcpUrl, {
100093
+ clientInfo: options?.clientInfo,
100094
+ fetchImpl: options?.fetchImpl ?? clientFetch,
100095
+ wallet: transaction.wallet
100096
+ });
100085
100097
  try {
100086
- const x402Client2 = createMcpPaymentClient(client2, transaction.wallet);
100087
100098
  return await x402Client2.callTool(tool, args ?? {});
100088
100099
  } finally {
100089
- await client2.close();
100100
+ await x402Client2.close();
100090
100101
  }
100091
100102
  }
100092
- const client = await createMcpClient(mcpUrl, { clientInfo: options?.clientInfo, fetchImpl: options?.fetchImpl });
100103
+ const client = await createMcpClient(mcpUrl, { clientInfo: options?.clientInfo, fetchImpl: resolvedFetch });
100093
100104
  try {
100094
100105
  const result = await client.callTool({ name: tool, arguments: args ?? {} });
100095
100106
  if (result.isError) {
@@ -100097,7 +100108,7 @@ async function callMcpTool(uri, tool, args, options) {
100097
100108
  if (content?.length > 0 && content[0].type === "text" && content[0].text) {
100098
100109
  try {
100099
100110
  const parsed = JSON.parse(content[0].text);
100100
- if (parsed?.accepts) {
100111
+ if (Array.isArray(parsed?.accepts) && parsed.accepts.length > 0) {
100101
100112
  throw new DryRunPaymentRequired(parsed.accepts);
100102
100113
  }
100103
100114
  } catch (e) {
@@ -101602,7 +101613,7 @@ function boxen(text, options) {
101602
101613
  // package.json
101603
101614
  var package_default2 = {
101604
101615
  name: "use-agently",
101605
- version: "0.16.0",
101616
+ version: "0.18.0",
101606
101617
  description: "Use Agently CLI",
101607
101618
  homepage: "https://use-agently.com",
101608
101619
  bugs: "https://github.com/AgentlyHQ/use-agently/issues",
@@ -101626,7 +101637,7 @@ var package_default2 = {
101626
101637
  test: "bun test"
101627
101638
  },
101628
101639
  dependencies: {
101629
- "@use-agently/sdk": "0.16.0",
101640
+ "@use-agently/sdk": "0.18.0",
101630
101641
  boxen: "^8.0.1",
101631
101642
  commander: "^14.0.3",
101632
101643
  viem: "^2.46.3",
@@ -101831,7 +101842,52 @@ Expected a JSON object, e.g. '{"message":"hello"}'`);
101831
101842
  clientInfo: { name: "use-agently", version: package_default2.version },
101832
101843
  fetchImpl: clientFetch2
101833
101844
  });
101834
- output(command, result);
101845
+ const content = result.content;
101846
+ if (result.isError) {
101847
+ const text = content?.find((c) => c.type === "text")?.text;
101848
+ if (text) {
101849
+ try {
101850
+ const parsed = JSON.parse(text);
101851
+ if (parsed?.error && Array.isArray(parsed?.accepts) && parsed.accepts.length > 0) {
101852
+ let message;
101853
+ if (parsed.error === "insufficient_funds") {
101854
+ const req = parsed.accepts[0];
101855
+ let amountStr = "unknown amount";
101856
+ try {
101857
+ const { usdcDecimals } = getChainConfigByNetwork(req.network);
101858
+ const raw = formatUnits(BigInt(req.amount), usdcDecimals);
101859
+ const formatted = raw.includes(".") ? raw.replace(/\.?0+$/, "") : raw;
101860
+ amountStr = `$${formatted} USDC on ${req.network}`;
101861
+ } catch {
101862
+ amountStr = `${req.amount} (raw units)`;
101863
+ }
101864
+ message = `Insufficient funds to pay for this tool.
101865
+ Required: ${amountStr}
101866
+ Ensure your wallet has sufficient USDC balance and try again.`;
101867
+ } else {
101868
+ message = `Payment error: ${parsed.error}`;
101869
+ }
101870
+ console.error(boxen(message, {
101871
+ title: parsed.error === "insufficient_funds" ? "Insufficient Funds" : "Payment Error",
101872
+ titleAlignment: "center",
101873
+ borderColor: "red",
101874
+ padding: 1
101875
+ }));
101876
+ process.exit(1);
101877
+ }
101878
+ } catch {}
101879
+ console.error(text);
101880
+ } else {
101881
+ console.error("Tool call returned an error with no text content.");
101882
+ }
101883
+ process.exit(1);
101884
+ }
101885
+ if (content?.every((c) => c.type === "text" && c.text)) {
101886
+ const texts = content.map((c) => c.text);
101887
+ output(command, texts.length === 1 ? texts[0] : texts);
101888
+ } else {
101889
+ output(command, result);
101890
+ }
101835
101891
  } catch (err) {
101836
101892
  if (err instanceof DryRunPaymentRequired)
101837
101893
  handleDryRunError(err);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "use-agently",
3
- "version": "0.16.0",
3
+ "version": "0.18.0",
4
4
  "description": "Use Agently CLI",
5
5
  "homepage": "https://use-agently.com",
6
6
  "bugs": "https://github.com/AgentlyHQ/use-agently/issues",
@@ -24,7 +24,7 @@
24
24
  "test": "bun test"
25
25
  },
26
26
  "dependencies": {
27
- "@use-agently/sdk": "0.16.0",
27
+ "@use-agently/sdk": "0.18.0",
28
28
  "boxen": "^8.0.1",
29
29
  "commander": "^14.0.3",
30
30
  "viem": "^2.46.3",