@coinbase/agentkit 0.8.2 → 0.9.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 (65) hide show
  1. package/README.md +373 -234
  2. package/dist/action-providers/cdp/cdpApiActionProvider.d.ts +15 -15
  3. package/dist/action-providers/cdp/cdpApiActionProvider.js +110 -63
  4. package/dist/action-providers/cdp/cdpApiActionProvider.test.js +205 -124
  5. package/dist/action-providers/cdp/index.d.ts +0 -1
  6. package/dist/action-providers/cdp/index.js +0 -1
  7. package/dist/action-providers/cdp/schemas.d.ts +9 -70
  8. package/dist/action-providers/cdp/schemas.js +12 -61
  9. package/dist/action-providers/cdp-legacy/index.d.ts +3 -0
  10. package/dist/action-providers/{cdp-v2 → cdp-legacy}/index.js +2 -1
  11. package/dist/action-providers/cdp-legacy/legacyCdpApiActionProvider.d.ts +45 -0
  12. package/dist/action-providers/cdp-legacy/legacyCdpApiActionProvider.js +130 -0
  13. package/dist/action-providers/cdp-legacy/legacyCdpApiActionProvider.test.js +146 -0
  14. package/dist/action-providers/{cdp/cdpWalletActionProvider.d.ts → cdp-legacy/legacyCdpWalletActionProvider.d.ts} +8 -8
  15. package/dist/action-providers/{cdp/cdpWalletActionProvider.js → cdp-legacy/legacyCdpWalletActionProvider.js} +14 -14
  16. package/dist/action-providers/{cdp/cdpWalletActionProvider.test.js → cdp-legacy/legacyCdpWalletActionProvider.test.js} +3 -3
  17. package/dist/action-providers/cdp-legacy/schemas.d.ts +91 -0
  18. package/dist/action-providers/cdp-legacy/schemas.js +77 -0
  19. package/dist/action-providers/erc20/erc20ActionProvider.js +1 -1
  20. package/dist/action-providers/index.d.ts +1 -1
  21. package/dist/action-providers/index.js +1 -1
  22. package/dist/action-providers/jupiter/jupiterActionProvider.test.js +2 -4
  23. package/dist/action-providers/x402/schemas.d.ts +58 -11
  24. package/dist/action-providers/x402/schemas.js +60 -8
  25. package/dist/action-providers/x402/x402ActionProvider.d.ts +33 -16
  26. package/dist/action-providers/x402/x402ActionProvider.js +203 -153
  27. package/dist/action-providers/x402/x402ActionProvider.test.js +78 -225
  28. package/dist/agentkit.d.ts +1 -0
  29. package/dist/agentkit.js +3 -2
  30. package/dist/wallet-providers/{cdpV2EvmWalletProvider.d.ts → cdpEvmWalletProvider.d.ts} +16 -7
  31. package/dist/wallet-providers/{cdpV2EvmWalletProvider.js → cdpEvmWalletProvider.js} +50 -39
  32. package/dist/wallet-providers/{cdpV2EvmWalletProvider.test.js → cdpEvmWalletProvider.test.js} +7 -7
  33. package/dist/wallet-providers/{cdpV2Shared.d.ts → cdpShared.d.ts} +15 -4
  34. package/dist/wallet-providers/cdpSmartWalletProvider.d.ts +115 -0
  35. package/dist/wallet-providers/cdpSmartWalletProvider.js +263 -0
  36. package/dist/wallet-providers/cdpSmartWalletProvider.test.js +287 -0
  37. package/dist/wallet-providers/{cdpV2SolanaWalletProvider.d.ts → cdpSolanaWalletProvider.d.ts} +16 -7
  38. package/dist/wallet-providers/{cdpV2SolanaWalletProvider.js → cdpSolanaWalletProvider.js} +43 -32
  39. package/dist/wallet-providers/{cdpV2SolanaWalletProvider.test.js → cdpSolanaWalletProvider.test.js} +7 -7
  40. package/dist/wallet-providers/index.d.ts +6 -6
  41. package/dist/wallet-providers/index.js +6 -6
  42. package/dist/wallet-providers/{smartWalletProvider.d.ts → legacyCdpSmartWalletProvider.d.ts} +3 -3
  43. package/dist/wallet-providers/{smartWalletProvider.js → legacyCdpSmartWalletProvider.js} +21 -21
  44. package/dist/wallet-providers/legacyCdpSmartWalletProvider.test.d.ts +1 -0
  45. package/dist/wallet-providers/{smartWalletProvider.test.js → legacyCdpSmartWalletProvider.test.js} +2 -2
  46. package/dist/wallet-providers/{cdpWalletProvider.d.ts → legacyCdpWalletProvider.d.ts} +15 -11
  47. package/dist/wallet-providers/{cdpWalletProvider.js → legacyCdpWalletProvider.js} +72 -70
  48. package/dist/wallet-providers/legacyCdpWalletProvider.test.d.ts +1 -0
  49. package/dist/wallet-providers/{cdpWalletProvider.test.js → legacyCdpWalletProvider.test.js} +10 -10
  50. package/package.json +3 -2
  51. package/dist/action-providers/cdp-v2/cdpApiV2ActionProvider.d.ts +0 -34
  52. package/dist/action-providers/cdp-v2/cdpApiV2ActionProvider.js +0 -98
  53. package/dist/action-providers/cdp-v2/index.d.ts +0 -2
  54. package/dist/action-providers/cdp-v2/schemas.d.ts +0 -11
  55. package/dist/action-providers/cdp-v2/schemas.js +0 -13
  56. package/dist/wallet-providers/cdpV2WalletProvider.d.ts +0 -35
  57. package/dist/wallet-providers/cdpV2WalletProvider.js +0 -42
  58. /package/dist/action-providers/{cdp → cdp-legacy}/constants.d.ts +0 -0
  59. /package/dist/action-providers/{cdp → cdp-legacy}/constants.js +0 -0
  60. /package/dist/action-providers/{cdp/cdpWalletActionProvider.test.d.ts → cdp-legacy/legacyCdpApiActionProvider.test.d.ts} +0 -0
  61. /package/dist/{wallet-providers/cdpV2EvmWalletProvider.test.d.ts → action-providers/cdp-legacy/legacyCdpWalletActionProvider.test.d.ts} +0 -0
  62. /package/dist/wallet-providers/{cdpV2SolanaWalletProvider.test.d.ts → cdpEvmWalletProvider.test.d.ts} +0 -0
  63. /package/dist/wallet-providers/{cdpV2Shared.js → cdpShared.js} +0 -0
  64. /package/dist/wallet-providers/{cdpWalletProvider.test.d.ts → cdpSmartWalletProvider.test.d.ts} +0 -0
  65. /package/dist/wallet-providers/{smartWalletProvider.test.d.ts → cdpSolanaWalletProvider.test.d.ts} +0 -0
@@ -9,7 +9,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.cdpWalletActionProvider = exports.CdpWalletActionProvider = void 0;
12
+ exports.legacyCdpWalletActionProvider = exports.LegacyCdpWalletActionProvider = void 0;
13
13
  const coinbase_sdk_1 = require("@coinbase/coinbase-sdk");
14
14
  const zod_1 = require("zod");
15
15
  const package_json_1 = require("../../../package.json");
@@ -23,14 +23,14 @@ const schemas_1 = require("./schemas");
23
23
  *
24
24
  * This provider is used for any action that requires a CDP Wallet.
25
25
  */
26
- class CdpWalletActionProvider extends actionProvider_1.ActionProvider {
26
+ class LegacyCdpWalletActionProvider extends actionProvider_1.ActionProvider {
27
27
  /**
28
28
  * Constructor for the CdpWalletActionProvider class.
29
29
  *
30
30
  * @param config - The configuration options for the CdpWalletActionProvider.
31
31
  */
32
32
  constructor(config = {}) {
33
- super("cdp_wallet", []);
33
+ super("legacy_cdp_wallet", []);
34
34
  /**
35
35
  * Checks if the Cdp action provider supports the given network.
36
36
  *
@@ -154,7 +154,7 @@ class CdpWalletActionProvider extends actionProvider_1.ActionProvider {
154
154
  }
155
155
  }
156
156
  }
157
- exports.CdpWalletActionProvider = CdpWalletActionProvider;
157
+ exports.LegacyCdpWalletActionProvider = LegacyCdpWalletActionProvider;
158
158
  __decorate([
159
159
  (0, actionDecorator_1.CreateAction)({
160
160
  name: "deploy_contract",
@@ -176,9 +176,9 @@ map where the key is the arg name and the value is the arg value. Encode uint/in
176
176
  schema: schemas_1.DeployContractSchema,
177
177
  }),
178
178
  __metadata("design:type", Function),
179
- __metadata("design:paramtypes", [wallet_providers_1.CdpWalletProvider, void 0]),
179
+ __metadata("design:paramtypes", [wallet_providers_1.LegacyCdpWalletProvider, void 0]),
180
180
  __metadata("design:returntype", Promise)
181
- ], CdpWalletActionProvider.prototype, "deployContract", null);
181
+ ], LegacyCdpWalletActionProvider.prototype, "deployContract", null);
182
182
  __decorate([
183
183
  (0, actionDecorator_1.CreateAction)({
184
184
  name: "deploy_nft",
@@ -187,9 +187,9 @@ __decorate([
187
187
  schema: schemas_1.DeployNftSchema,
188
188
  }),
189
189
  __metadata("design:type", Function),
190
- __metadata("design:paramtypes", [wallet_providers_1.CdpWalletProvider, void 0]),
190
+ __metadata("design:paramtypes", [wallet_providers_1.LegacyCdpWalletProvider, void 0]),
191
191
  __metadata("design:returntype", Promise)
192
- ], CdpWalletActionProvider.prototype, "deployNFT", null);
192
+ ], LegacyCdpWalletActionProvider.prototype, "deployNFT", null);
193
193
  __decorate([
194
194
  (0, actionDecorator_1.CreateAction)({
195
195
  name: "deploy_token",
@@ -198,9 +198,9 @@ The token will be deployed using the wallet's default address as the owner and i
198
198
  schema: schemas_1.DeployTokenSchema,
199
199
  }),
200
200
  __metadata("design:type", Function),
201
- __metadata("design:paramtypes", [wallet_providers_1.CdpWalletProvider, void 0]),
201
+ __metadata("design:paramtypes", [wallet_providers_1.LegacyCdpWalletProvider, void 0]),
202
202
  __metadata("design:returntype", Promise)
203
- ], CdpWalletActionProvider.prototype, "deployToken", null);
203
+ ], LegacyCdpWalletActionProvider.prototype, "deployToken", null);
204
204
  __decorate([
205
205
  (0, actionDecorator_1.CreateAction)({
206
206
  name: "trade",
@@ -217,8 +217,8 @@ Important notes:
217
217
  schema: schemas_1.TradeSchema,
218
218
  }),
219
219
  __metadata("design:type", Function),
220
- __metadata("design:paramtypes", [wallet_providers_1.CdpWalletProvider, void 0]),
220
+ __metadata("design:paramtypes", [wallet_providers_1.LegacyCdpWalletProvider, void 0]),
221
221
  __metadata("design:returntype", Promise)
222
- ], CdpWalletActionProvider.prototype, "trade", null);
223
- const cdpWalletActionProvider = (config = {}) => new CdpWalletActionProvider(config);
224
- exports.cdpWalletActionProvider = cdpWalletActionProvider;
222
+ ], LegacyCdpWalletActionProvider.prototype, "trade", null);
223
+ const legacyCdpWalletActionProvider = (config = {}) => new LegacyCdpWalletActionProvider(config);
224
+ exports.legacyCdpWalletActionProvider = legacyCdpWalletActionProvider;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const cdpWalletActionProvider_1 = require("./cdpWalletActionProvider");
3
+ const legacyCdpWalletActionProvider_1 = require("./legacyCdpWalletActionProvider");
4
4
  const schemas_1 = require("./schemas");
5
5
  // Mock the entire module
6
6
  jest.mock("@coinbase/coinbase-sdk");
@@ -55,7 +55,7 @@ describe("CDP Wallet Action Provider Input Schemas", () => {
55
55
  });
56
56
  });
57
57
  });
58
- describe("CDP Wallet Action Provider", () => {
58
+ describe("Legacy CDP Wallet Action Provider", () => {
59
59
  let actionProvider;
60
60
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
61
61
  let mockExternalAddressInstance;
@@ -63,7 +63,7 @@ describe("CDP Wallet Action Provider", () => {
63
63
  beforeEach(() => {
64
64
  // Reset all mocks before each test
65
65
  jest.clearAllMocks();
66
- actionProvider = new cdpWalletActionProvider_1.CdpWalletActionProvider();
66
+ actionProvider = new legacyCdpWalletActionProvider_1.LegacyCdpWalletActionProvider();
67
67
  mockExternalAddressInstance = {
68
68
  reputation: jest.fn(),
69
69
  faucet: jest.fn(),
@@ -0,0 +1,91 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * Input schema for address reputation check.
4
+ */
5
+ export declare const AddressReputationSchema: z.ZodObject<{
6
+ address: z.ZodString;
7
+ network: z.ZodString;
8
+ }, "strip", z.ZodTypeAny, {
9
+ address: string;
10
+ network: string;
11
+ }, {
12
+ address: string;
13
+ network: string;
14
+ }>;
15
+ /**
16
+ * Input schema for deploy contract action.
17
+ */
18
+ export declare const DeployContractSchema: z.ZodObject<{
19
+ solidityVersion: z.ZodEnum<[string, ...string[]]>;
20
+ solidityInputJson: z.ZodString;
21
+ contractName: z.ZodString;
22
+ constructorArgs: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
23
+ }, "strip", z.ZodTypeAny, {
24
+ solidityVersion: string;
25
+ solidityInputJson: string;
26
+ contractName: string;
27
+ constructorArgs?: Record<string, any> | undefined;
28
+ }, {
29
+ solidityVersion: string;
30
+ solidityInputJson: string;
31
+ contractName: string;
32
+ constructorArgs?: Record<string, any> | undefined;
33
+ }>;
34
+ /**
35
+ * Input schema for deploy NFT action
36
+ */
37
+ export declare const DeployNftSchema: z.ZodObject<{
38
+ name: z.ZodString;
39
+ symbol: z.ZodString;
40
+ baseURI: z.ZodString;
41
+ }, "strip", z.ZodTypeAny, {
42
+ symbol: string;
43
+ name: string;
44
+ baseURI: string;
45
+ }, {
46
+ symbol: string;
47
+ name: string;
48
+ baseURI: string;
49
+ }>;
50
+ /**
51
+ * Input schema for deploy token action.
52
+ */
53
+ export declare const DeployTokenSchema: z.ZodObject<{
54
+ name: z.ZodString;
55
+ symbol: z.ZodString;
56
+ totalSupply: z.ZodType<bigint, z.ZodTypeDef, bigint>;
57
+ }, "strip", z.ZodTypeAny, {
58
+ symbol: string;
59
+ name: string;
60
+ totalSupply: bigint;
61
+ }, {
62
+ symbol: string;
63
+ name: string;
64
+ totalSupply: bigint;
65
+ }>;
66
+ /**
67
+ * Input schema for request faucet funds action.
68
+ */
69
+ export declare const RequestFaucetFundsSchema: z.ZodObject<{
70
+ assetId: z.ZodOptional<z.ZodString>;
71
+ }, "strip", z.ZodTypeAny, {
72
+ assetId?: string | undefined;
73
+ }, {
74
+ assetId?: string | undefined;
75
+ }>;
76
+ /**
77
+ * Input schema for trade action.
78
+ */
79
+ export declare const TradeSchema: z.ZodObject<{
80
+ amount: z.ZodType<bigint, z.ZodTypeDef, bigint>;
81
+ fromAssetId: z.ZodString;
82
+ toAssetId: z.ZodString;
83
+ }, "strip", z.ZodTypeAny, {
84
+ amount: bigint;
85
+ fromAssetId: string;
86
+ toAssetId: string;
87
+ }, {
88
+ amount: bigint;
89
+ fromAssetId: string;
90
+ toAssetId: string;
91
+ }>;
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TradeSchema = exports.RequestFaucetFundsSchema = exports.DeployTokenSchema = exports.DeployNftSchema = exports.DeployContractSchema = exports.AddressReputationSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ const constants_1 = require("./constants");
6
+ /**
7
+ * Input schema for address reputation check.
8
+ */
9
+ exports.AddressReputationSchema = zod_1.z
10
+ .object({
11
+ address: zod_1.z
12
+ .string()
13
+ .regex(/^0x[a-fA-F0-9]{40}$/, "Invalid Ethereum address format")
14
+ .describe("The Ethereum address to check"),
15
+ network: zod_1.z.string().describe("The network to check the address on"),
16
+ })
17
+ .strip()
18
+ .describe("Input schema for address reputation check");
19
+ /**
20
+ * Input schema for deploy contract action.
21
+ */
22
+ exports.DeployContractSchema = zod_1.z
23
+ .object({
24
+ solidityVersion: zod_1.z
25
+ .enum(Object.keys(constants_1.SolidityVersions))
26
+ .describe("The solidity compiler version"),
27
+ solidityInputJson: zod_1.z.string().describe("The input json for the solidity compiler"),
28
+ contractName: zod_1.z.string().describe("The name of the contract class to be deployed"),
29
+ constructorArgs: zod_1.z
30
+ .record(zod_1.z.string(), zod_1.z.any())
31
+ .describe("The constructor arguments for the contract")
32
+ .optional(),
33
+ })
34
+ .strip()
35
+ .describe("Instructions for deploying an arbitrary contract");
36
+ /**
37
+ * Input schema for deploy NFT action
38
+ */
39
+ exports.DeployNftSchema = zod_1.z
40
+ .object({
41
+ name: zod_1.z.string().describe("The name of the NFT collection"),
42
+ symbol: zod_1.z.string().describe("The symbol of the NFT collection"),
43
+ baseURI: zod_1.z.string().describe("The base URI for the token metadata"),
44
+ })
45
+ .strip()
46
+ .describe("Instructions for deploying an NFT collection");
47
+ /**
48
+ * Input schema for deploy token action.
49
+ */
50
+ exports.DeployTokenSchema = zod_1.z
51
+ .object({
52
+ name: zod_1.z.string().describe("The name of the token"),
53
+ symbol: zod_1.z.string().describe("The token symbol"),
54
+ totalSupply: zod_1.z.custom().describe("The total supply of tokens to mint"),
55
+ })
56
+ .strip()
57
+ .describe("Instructions for deploying a token");
58
+ /**
59
+ * Input schema for request faucet funds action.
60
+ */
61
+ exports.RequestFaucetFundsSchema = zod_1.z
62
+ .object({
63
+ assetId: zod_1.z.string().optional().describe("The optional asset ID to request from faucet"),
64
+ })
65
+ .strip()
66
+ .describe("Instructions for requesting faucet funds");
67
+ /**
68
+ * Input schema for trade action.
69
+ */
70
+ exports.TradeSchema = zod_1.z
71
+ .object({
72
+ amount: zod_1.z.custom().describe("The amount of the from asset to trade"),
73
+ fromAssetId: zod_1.z.string().describe("The from asset ID to trade"),
74
+ toAssetId: zod_1.z.string().describe("The to asset ID to receive from the trade"),
75
+ })
76
+ .strip()
77
+ .describe("Instructions for trading assets");
@@ -78,7 +78,7 @@ class ERC20ActionProvider extends actionProvider_1.ActionProvider {
78
78
  ((network.networkId === "base-mainnet" && constants_1.BaseTokenToAssetId.has(tokenAddress)) ||
79
79
  (network.networkId === "base-sepolia" && constants_1.BaseSepoliaTokenToAssetId.has(tokenAddress)));
80
80
  if (canDoGasless) {
81
- // Cast to CdpWalletProvider to access erc20Transfer
81
+ // Cast to LegacyCdpWalletProvider to access erc20Transfer
82
82
  const cdpWallet = walletProvider;
83
83
  const assetId = network.networkId === "base-mainnet"
84
84
  ? constants_1.BaseTokenToAssetId.get(tokenAddress)
@@ -4,8 +4,8 @@ export * from "./customActionProvider";
4
4
  export * from "./across";
5
5
  export * from "./alchemy";
6
6
  export * from "./basename";
7
+ export * from "./cdp-legacy";
7
8
  export * from "./cdp";
8
- export * from "./cdp-v2";
9
9
  export * from "./compound";
10
10
  export * from "./defillama";
11
11
  export * from "./erc20";
@@ -20,8 +20,8 @@ __exportStar(require("./customActionProvider"), exports);
20
20
  __exportStar(require("./across"), exports);
21
21
  __exportStar(require("./alchemy"), exports);
22
22
  __exportStar(require("./basename"), exports);
23
+ __exportStar(require("./cdp-legacy"), exports);
23
24
  __exportStar(require("./cdp"), exports);
24
- __exportStar(require("./cdp-v2"), exports);
25
25
  __exportStar(require("./compound"), exports);
26
26
  __exportStar(require("./defillama"), exports);
27
27
  __exportStar(require("./erc20"), exports);
@@ -3,8 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const web3_js_1 = require("@solana/web3.js");
4
4
  const jupiterActionProvider_1 = require("./jupiterActionProvider");
5
5
  const api_1 = require("@jup-ag/api");
6
- // Default SPL token decimals for tests
7
- const DECIMALS = 6;
8
6
  // Mock the @solana/web3.js module
9
7
  jest.mock("@solana/web3.js", () => ({
10
8
  // Preserve the actual implementation of @solana/web3.js while overriding specific methods
@@ -28,7 +26,7 @@ jest.mock("@solana/spl-token", () => ({
28
26
  // Preserve the actual implementation of @solana/spl-token while overriding specific methods
29
27
  ...jest.requireActual("@solana/spl-token"),
30
28
  // Mock getMint to always return a fixed decimal value for tokens
31
- getMint: jest.fn().mockReturnValue({ decimals: DECIMALS }),
29
+ getMint: jest.fn().mockReturnValue({ decimals: 6 }),
32
30
  }));
33
31
  // Mock the @jup-ag/api module
34
32
  jest.mock("@jup-ag/api", () => ({
@@ -107,7 +105,7 @@ describe("JupiterActionProvider", () => {
107
105
  expect(mockQuoteGet).toHaveBeenCalledWith({
108
106
  inputMint: INPUT_MINT,
109
107
  outputMint: OUTPUT_MINT,
110
- amount: swapArgs.amount * 10 ** DECIMALS, // Ensure correct decimal conversion
108
+ amount: swapArgs.amount * 10 ** 6, // Ensure correct decimal conversion
111
109
  slippageBps: swapArgs.slippageBps,
112
110
  });
113
111
  expect(mockSwapPost).toHaveBeenCalled();
@@ -1,30 +1,77 @@
1
1
  import { z } from "zod";
2
- export declare const PaidRequestSchema: z.ZodObject<{
2
+ export declare const HttpRequestSchema: z.ZodObject<{
3
3
  url: z.ZodString;
4
- method: z.ZodDefault<z.ZodEnum<["GET", "POST", "PUT", "DELETE", "PATCH"]>>;
4
+ method: z.ZodDefault<z.ZodNullable<z.ZodEnum<["GET", "POST", "PUT", "DELETE", "PATCH"]>>>;
5
+ headers: z.ZodNullable<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>>;
6
+ body: z.ZodNullable<z.ZodOptional<z.ZodAny>>;
7
+ }, "strip", z.ZodTypeAny, {
8
+ method: "POST" | "GET" | "PUT" | "DELETE" | "PATCH" | null;
9
+ url: string;
10
+ body?: any;
11
+ headers?: Record<string, string> | null | undefined;
12
+ }, {
13
+ url: string;
14
+ method?: "POST" | "GET" | "PUT" | "DELETE" | "PATCH" | null | undefined;
15
+ body?: any;
16
+ headers?: Record<string, string> | null | undefined;
17
+ }>;
18
+ export declare const RetryWithX402Schema: z.ZodObject<{
19
+ url: z.ZodString;
20
+ method: z.ZodDefault<z.ZodNullable<z.ZodEnum<["GET", "POST", "PUT", "DELETE", "PATCH"]>>>;
5
21
  headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
6
22
  body: z.ZodOptional<z.ZodAny>;
23
+ selectedPaymentOption: z.ZodObject<{
24
+ scheme: z.ZodString;
25
+ network: z.ZodString;
26
+ maxAmountRequired: z.ZodString;
27
+ asset: z.ZodString;
28
+ }, "strip", z.ZodTypeAny, {
29
+ scheme: string;
30
+ network: string;
31
+ asset: string;
32
+ maxAmountRequired: string;
33
+ }, {
34
+ scheme: string;
35
+ network: string;
36
+ asset: string;
37
+ maxAmountRequired: string;
38
+ }>;
7
39
  }, "strip", z.ZodTypeAny, {
8
- method: "POST" | "GET" | "PUT" | "DELETE" | "PATCH";
40
+ method: "POST" | "GET" | "PUT" | "DELETE" | "PATCH" | null;
9
41
  url: string;
42
+ selectedPaymentOption: {
43
+ scheme: string;
44
+ network: string;
45
+ asset: string;
46
+ maxAmountRequired: string;
47
+ };
10
48
  body?: any;
11
49
  headers?: Record<string, string> | undefined;
12
50
  }, {
13
51
  url: string;
14
- method?: "POST" | "GET" | "PUT" | "DELETE" | "PATCH" | undefined;
52
+ selectedPaymentOption: {
53
+ scheme: string;
54
+ network: string;
55
+ asset: string;
56
+ maxAmountRequired: string;
57
+ };
58
+ method?: "POST" | "GET" | "PUT" | "DELETE" | "PATCH" | null | undefined;
15
59
  body?: any;
16
60
  headers?: Record<string, string> | undefined;
17
61
  }>;
18
- export declare const FetchPaymentInfoSchema: z.ZodObject<{
62
+ export declare const DirectX402RequestSchema: z.ZodObject<{
19
63
  url: z.ZodString;
20
- method: z.ZodDefault<z.ZodEnum<["GET", "POST", "PUT", "DELETE", "PATCH"]>>;
21
- headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
64
+ method: z.ZodDefault<z.ZodNullable<z.ZodEnum<["GET", "POST", "PUT", "DELETE", "PATCH"]>>>;
65
+ headers: z.ZodNullable<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>>;
66
+ body: z.ZodNullable<z.ZodOptional<z.ZodAny>>;
22
67
  }, "strip", z.ZodTypeAny, {
23
- method: "POST" | "GET" | "PUT" | "DELETE" | "PATCH";
68
+ method: "POST" | "GET" | "PUT" | "DELETE" | "PATCH" | null;
24
69
  url: string;
25
- headers?: Record<string, string> | undefined;
70
+ body?: any;
71
+ headers?: Record<string, string> | null | undefined;
26
72
  }, {
27
73
  url: string;
28
- method?: "POST" | "GET" | "PUT" | "DELETE" | "PATCH" | undefined;
29
- headers?: Record<string, string> | undefined;
74
+ method?: "POST" | "GET" | "PUT" | "DELETE" | "PATCH" | null | undefined;
75
+ body?: any;
76
+ headers?: Record<string, string> | null | undefined;
30
77
  }>;
@@ -1,27 +1,79 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FetchPaymentInfoSchema = exports.PaidRequestSchema = void 0;
3
+ exports.DirectX402RequestSchema = exports.RetryWithX402Schema = exports.HttpRequestSchema = void 0;
4
4
  const zod_1 = require("zod");
5
- exports.PaidRequestSchema = zod_1.z
5
+ // Schema for initial HTTP request
6
+ exports.HttpRequestSchema = zod_1.z
6
7
  .object({
7
- url: zod_1.z.string().url().describe("The URL of the x402-protected API endpoint"),
8
+ url: zod_1.z
9
+ .string()
10
+ .url()
11
+ .describe("The URL of the API endpoint (can be localhost for development)"),
8
12
  method: zod_1.z
9
13
  .enum(["GET", "POST", "PUT", "DELETE", "PATCH"])
14
+ .nullable()
15
+ .default("GET")
16
+ .describe("The HTTP method to use for the request"),
17
+ headers: zod_1.z
18
+ .record(zod_1.z.string())
19
+ .optional()
20
+ .nullable()
21
+ .describe("Optional headers to include in the request"),
22
+ body: zod_1.z
23
+ .any()
24
+ .optional()
25
+ .nullable()
26
+ .describe("Optional request body for POST/PUT/PATCH requests"),
27
+ })
28
+ .strip()
29
+ .describe("Instructions for making a basic HTTP request");
30
+ // Schema for retrying a failed request with x402 payment
31
+ exports.RetryWithX402Schema = zod_1.z
32
+ .object({
33
+ url: zod_1.z
34
+ .string()
35
+ .url()
36
+ .describe("The URL of the API endpoint (can be localhost for development)"),
37
+ method: zod_1.z
38
+ .enum(["GET", "POST", "PUT", "DELETE", "PATCH"])
39
+ .nullable()
10
40
  .default("GET")
11
41
  .describe("The HTTP method to use for the request"),
12
42
  headers: zod_1.z.record(zod_1.z.string()).optional().describe("Optional headers to include in the request"),
13
43
  body: zod_1.z.any().optional().describe("Optional request body for POST/PUT/PATCH requests"),
44
+ selectedPaymentOption: zod_1.z
45
+ .object({
46
+ scheme: zod_1.z.string(),
47
+ network: zod_1.z.string(),
48
+ maxAmountRequired: zod_1.z.string(),
49
+ asset: zod_1.z.string(),
50
+ })
51
+ .describe("The payment option to use for this request"),
14
52
  })
15
53
  .strip()
16
- .describe("Instructions for making a paid request to an x402-protected API");
17
- exports.FetchPaymentInfoSchema = zod_1.z
54
+ .describe("Instructions for retrying a request with x402 payment after receiving a 402 response");
55
+ // Schema for direct x402 payment request (with warning)
56
+ exports.DirectX402RequestSchema = zod_1.z
18
57
  .object({
19
- url: zod_1.z.string().url().describe("The URL of the x402-protected API endpoint"),
58
+ url: zod_1.z
59
+ .string()
60
+ .url()
61
+ .describe("The URL of the API endpoint (can be localhost for development)"),
20
62
  method: zod_1.z
21
63
  .enum(["GET", "POST", "PUT", "DELETE", "PATCH"])
64
+ .nullable()
22
65
  .default("GET")
23
66
  .describe("The HTTP method to use for the request"),
24
- headers: zod_1.z.record(zod_1.z.string()).optional().describe("Optional headers to include in the request"),
67
+ headers: zod_1.z
68
+ .record(zod_1.z.string())
69
+ .optional()
70
+ .nullable()
71
+ .describe("Optional headers to include in the request"),
72
+ body: zod_1.z
73
+ .any()
74
+ .optional()
75
+ .nullable()
76
+ .describe("Optional request body for POST/PUT/PATCH requests"),
25
77
  })
26
78
  .strip()
27
- .describe("Instructions for fetching payment information from an x402-protected API endpoint");
79
+ .describe("Instructions for making an HTTP request with automatic x402 payment handling. WARNING: This bypasses user confirmation - only use when explicitly told to skip confirmation!");
@@ -1,38 +1,55 @@
1
1
  import { z } from "zod";
2
2
  import { ActionProvider } from "../actionProvider";
3
3
  import { Network } from "../../network";
4
- import { PaidRequestSchema, FetchPaymentInfoSchema } from "./schemas";
4
+ import { HttpRequestSchema, RetryWithX402Schema, DirectX402RequestSchema } from "./schemas";
5
5
  import { EvmWalletProvider } from "../../wallet-providers";
6
6
  /**
7
- * X402ActionProvider is an action provider for making paid requests to x402-protected APIs.
7
+ * X402ActionProvider provides actions for making HTTP requests, with optional x402 payment handling.
8
8
  */
9
9
  export declare class X402ActionProvider extends ActionProvider<EvmWalletProvider> {
10
10
  /**
11
- * Constructor for the X402ActionProvider.
11
+ * Creates a new instance of X402ActionProvider.
12
+ * Initializes the provider with x402 capabilities.
12
13
  */
13
14
  constructor();
14
15
  /**
15
- * Makes a paid request to an x402-protected API endpoint.
16
+ * Makes a basic HTTP request to an API endpoint.
16
17
  *
17
- * @param walletProvider - The wallet provider to use for payment signing.
18
- * @param args - The input arguments for the action.
19
- * @returns A message containing the API response data.
18
+ * @param walletProvider - The wallet provider to use for potential payments
19
+ * @param args - The request parameters including URL, method, headers, and body
20
+ * @returns A JSON string containing the response or error details
20
21
  */
21
- paidRequest(walletProvider: EvmWalletProvider, args: z.infer<typeof PaidRequestSchema>): Promise<string>;
22
+ makeHttpRequest(walletProvider: EvmWalletProvider, args: z.infer<typeof HttpRequestSchema>): Promise<string>;
22
23
  /**
23
- * Fetches payment information from an x402-protected API endpoint without making the payment.
24
+ * Retries a request with x402 payment after receiving a 402 response.
24
25
  *
25
- * @param walletProvider - The wallet provider (not used for this action but required by interface).
26
- * @param args - The input arguments for the action.
27
- * @returns A message containing the payment requirements and endpoint information.
26
+ * @param walletProvider - The wallet provider to use for making the payment
27
+ * @param args - The request parameters including URL, method, headers, body, and payment option
28
+ * @returns A JSON string containing the response with payment details or error information
28
29
  */
29
- fetchPaymentInfo(walletProvider: EvmWalletProvider, args: z.infer<typeof FetchPaymentInfoSchema>): Promise<string>;
30
+ retryWithX402(walletProvider: EvmWalletProvider, args: z.infer<typeof RetryWithX402Schema>): Promise<string>;
30
31
  /**
31
- * Checks if the X402 action provider supports the given network.
32
+ * Makes an HTTP request with automatic x402 payment handling.
32
33
  *
33
- * @param network - The network to check.
34
- * @returns True if the X402 action provider supports the network, false otherwise.
34
+ * @param walletProvider - The wallet provider to use for automatic payments
35
+ * @param args - The request parameters including URL, method, headers, and body
36
+ * @returns A JSON string containing the response with optional payment details or error information
37
+ */
38
+ makeHttpRequestWithX402(walletProvider: EvmWalletProvider, args: z.infer<typeof DirectX402RequestSchema>): Promise<string>;
39
+ /**
40
+ * Checks if the action provider supports the given network.
41
+ *
42
+ * @param network - The network to check support for
43
+ * @returns True if the network is supported, false otherwise
35
44
  */
36
45
  supportsNetwork: (network: Network) => boolean;
46
+ /**
47
+ * Helper method to handle HTTP errors consistently.
48
+ *
49
+ * @param error - The axios error to handle
50
+ * @param url - The URL that was being accessed when the error occurred
51
+ * @returns A JSON string containing formatted error details
52
+ */
53
+ private handleHttpError;
37
54
  }
38
55
  export declare const x402ActionProvider: () => X402ActionProvider;