@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.
- package/README.md +373 -234
- package/dist/action-providers/cdp/cdpApiActionProvider.d.ts +15 -15
- package/dist/action-providers/cdp/cdpApiActionProvider.js +110 -63
- package/dist/action-providers/cdp/cdpApiActionProvider.test.js +205 -124
- package/dist/action-providers/cdp/index.d.ts +0 -1
- package/dist/action-providers/cdp/index.js +0 -1
- package/dist/action-providers/cdp/schemas.d.ts +9 -70
- package/dist/action-providers/cdp/schemas.js +12 -61
- package/dist/action-providers/cdp-legacy/index.d.ts +3 -0
- package/dist/action-providers/{cdp-v2 → cdp-legacy}/index.js +2 -1
- package/dist/action-providers/cdp-legacy/legacyCdpApiActionProvider.d.ts +45 -0
- package/dist/action-providers/cdp-legacy/legacyCdpApiActionProvider.js +130 -0
- package/dist/action-providers/cdp-legacy/legacyCdpApiActionProvider.test.js +146 -0
- package/dist/action-providers/{cdp/cdpWalletActionProvider.d.ts → cdp-legacy/legacyCdpWalletActionProvider.d.ts} +8 -8
- package/dist/action-providers/{cdp/cdpWalletActionProvider.js → cdp-legacy/legacyCdpWalletActionProvider.js} +14 -14
- package/dist/action-providers/{cdp/cdpWalletActionProvider.test.js → cdp-legacy/legacyCdpWalletActionProvider.test.js} +3 -3
- package/dist/action-providers/cdp-legacy/schemas.d.ts +91 -0
- package/dist/action-providers/cdp-legacy/schemas.js +77 -0
- package/dist/action-providers/erc20/erc20ActionProvider.js +1 -1
- package/dist/action-providers/index.d.ts +1 -1
- package/dist/action-providers/index.js +1 -1
- package/dist/action-providers/jupiter/jupiterActionProvider.test.js +2 -4
- package/dist/action-providers/x402/schemas.d.ts +58 -11
- package/dist/action-providers/x402/schemas.js +60 -8
- package/dist/action-providers/x402/x402ActionProvider.d.ts +33 -16
- package/dist/action-providers/x402/x402ActionProvider.js +203 -153
- package/dist/action-providers/x402/x402ActionProvider.test.js +78 -225
- package/dist/agentkit.d.ts +1 -0
- package/dist/agentkit.js +3 -2
- package/dist/wallet-providers/{cdpV2EvmWalletProvider.d.ts → cdpEvmWalletProvider.d.ts} +16 -7
- package/dist/wallet-providers/{cdpV2EvmWalletProvider.js → cdpEvmWalletProvider.js} +50 -39
- package/dist/wallet-providers/{cdpV2EvmWalletProvider.test.js → cdpEvmWalletProvider.test.js} +7 -7
- package/dist/wallet-providers/{cdpV2Shared.d.ts → cdpShared.d.ts} +15 -4
- package/dist/wallet-providers/cdpSmartWalletProvider.d.ts +115 -0
- package/dist/wallet-providers/cdpSmartWalletProvider.js +263 -0
- package/dist/wallet-providers/cdpSmartWalletProvider.test.js +287 -0
- package/dist/wallet-providers/{cdpV2SolanaWalletProvider.d.ts → cdpSolanaWalletProvider.d.ts} +16 -7
- package/dist/wallet-providers/{cdpV2SolanaWalletProvider.js → cdpSolanaWalletProvider.js} +43 -32
- package/dist/wallet-providers/{cdpV2SolanaWalletProvider.test.js → cdpSolanaWalletProvider.test.js} +7 -7
- package/dist/wallet-providers/index.d.ts +6 -6
- package/dist/wallet-providers/index.js +6 -6
- package/dist/wallet-providers/{smartWalletProvider.d.ts → legacyCdpSmartWalletProvider.d.ts} +3 -3
- package/dist/wallet-providers/{smartWalletProvider.js → legacyCdpSmartWalletProvider.js} +21 -21
- package/dist/wallet-providers/legacyCdpSmartWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/{smartWalletProvider.test.js → legacyCdpSmartWalletProvider.test.js} +2 -2
- package/dist/wallet-providers/{cdpWalletProvider.d.ts → legacyCdpWalletProvider.d.ts} +15 -11
- package/dist/wallet-providers/{cdpWalletProvider.js → legacyCdpWalletProvider.js} +72 -70
- package/dist/wallet-providers/legacyCdpWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/{cdpWalletProvider.test.js → legacyCdpWalletProvider.test.js} +10 -10
- package/package.json +3 -2
- package/dist/action-providers/cdp-v2/cdpApiV2ActionProvider.d.ts +0 -34
- package/dist/action-providers/cdp-v2/cdpApiV2ActionProvider.js +0 -98
- package/dist/action-providers/cdp-v2/index.d.ts +0 -2
- package/dist/action-providers/cdp-v2/schemas.d.ts +0 -11
- package/dist/action-providers/cdp-v2/schemas.js +0 -13
- package/dist/wallet-providers/cdpV2WalletProvider.d.ts +0 -35
- package/dist/wallet-providers/cdpV2WalletProvider.js +0 -42
- /package/dist/action-providers/{cdp → cdp-legacy}/constants.d.ts +0 -0
- /package/dist/action-providers/{cdp → cdp-legacy}/constants.js +0 -0
- /package/dist/action-providers/{cdp/cdpWalletActionProvider.test.d.ts → cdp-legacy/legacyCdpApiActionProvider.test.d.ts} +0 -0
- /package/dist/{wallet-providers/cdpV2EvmWalletProvider.test.d.ts → action-providers/cdp-legacy/legacyCdpWalletActionProvider.test.d.ts} +0 -0
- /package/dist/wallet-providers/{cdpV2SolanaWalletProvider.test.d.ts → cdpEvmWalletProvider.test.d.ts} +0 -0
- /package/dist/wallet-providers/{cdpV2Shared.js → cdpShared.js} +0 -0
- /package/dist/wallet-providers/{cdpWalletProvider.test.d.ts → cdpSmartWalletProvider.test.d.ts} +0 -0
- /package/dist/wallet-providers/{smartWalletProvider.test.d.ts → cdpSolanaWalletProvider.test.d.ts} +0 -0
|
@@ -127,14 +127,6 @@ const MOCK_PAYMENT_RESPONSE = {
|
|
|
127
127
|
network: "base-sepolia",
|
|
128
128
|
payer: "0xa8c1a5D3C372C65c04f91f87a43F549619A9483f",
|
|
129
129
|
};
|
|
130
|
-
const MOCK_PAID_REQUEST_RESPONSE = {
|
|
131
|
-
success: true,
|
|
132
|
-
url: "https://www.x402.org/protected",
|
|
133
|
-
method: "GET",
|
|
134
|
-
status: 200,
|
|
135
|
-
data: "<!DOCTYPE html><html>...</html>",
|
|
136
|
-
paymentResponse: MOCK_PAYMENT_RESPONSE,
|
|
137
|
-
};
|
|
138
130
|
describe("X402ActionProvider", () => {
|
|
139
131
|
let provider;
|
|
140
132
|
beforeEach(() => {
|
|
@@ -171,299 +163,160 @@ describe("X402ActionProvider", () => {
|
|
|
171
163
|
expect(provider.supportsNetwork(network)).toBe(false);
|
|
172
164
|
});
|
|
173
165
|
});
|
|
174
|
-
describe("
|
|
175
|
-
it("should
|
|
176
|
-
mockRequest.mockResolvedValue({
|
|
177
|
-
status: 402,
|
|
178
|
-
statusText: "Payment Required",
|
|
179
|
-
data: MOCK_PAYMENT_INFO_RESPONSE.data,
|
|
180
|
-
headers: {},
|
|
181
|
-
config: {},
|
|
182
|
-
});
|
|
183
|
-
const result = await provider.fetchPaymentInfo(mockWalletProvider, {
|
|
184
|
-
url: "https://www.x402.org/protected",
|
|
185
|
-
method: "GET",
|
|
186
|
-
});
|
|
187
|
-
expect(mockRequest).toHaveBeenCalledWith({
|
|
188
|
-
url: "https://www.x402.org/protected",
|
|
189
|
-
method: "GET",
|
|
190
|
-
headers: undefined,
|
|
191
|
-
validateStatus: expect.any(Function),
|
|
192
|
-
});
|
|
193
|
-
const parsedResult = JSON.parse(result);
|
|
194
|
-
expect(parsedResult.paymentRequired).toBe(true);
|
|
195
|
-
expect(parsedResult.status).toBe(402);
|
|
196
|
-
expect(parsedResult.data).toEqual(MOCK_PAYMENT_INFO_RESPONSE.data);
|
|
197
|
-
});
|
|
198
|
-
it("should handle non-payment-protected endpoints", async () => {
|
|
166
|
+
describe("makeHttpRequest", () => {
|
|
167
|
+
it("should handle successful non-payment requests", async () => {
|
|
199
168
|
mockRequest.mockResolvedValue({
|
|
200
169
|
status: 200,
|
|
201
|
-
|
|
202
|
-
data: { message: "No payment required" },
|
|
170
|
+
data: { message: "Success" },
|
|
203
171
|
headers: {},
|
|
204
172
|
config: {},
|
|
205
173
|
});
|
|
206
|
-
const result = await provider.
|
|
174
|
+
const result = await provider.makeHttpRequest(mockWalletProvider, {
|
|
207
175
|
url: "https://api.example.com/free",
|
|
208
176
|
method: "GET",
|
|
209
177
|
});
|
|
210
178
|
const parsedResult = JSON.parse(result);
|
|
211
|
-
expect(parsedResult.
|
|
179
|
+
expect(parsedResult.success).toBe(true);
|
|
212
180
|
expect(parsedResult.status).toBe(200);
|
|
213
|
-
expect(parsedResult.data).toEqual({ message: "
|
|
181
|
+
expect(parsedResult.data).toEqual({ message: "Success" });
|
|
214
182
|
});
|
|
215
|
-
it("should handle 402
|
|
216
|
-
|
|
217
|
-
const error = new Error("Payment required");
|
|
218
|
-
error.isAxiosError = true;
|
|
219
|
-
error.response = {
|
|
183
|
+
it("should handle 402 responses with payment options", async () => {
|
|
184
|
+
mockRequest.mockResolvedValue({
|
|
220
185
|
status: 402,
|
|
221
|
-
statusText: "Payment Required",
|
|
222
|
-
headers: {
|
|
223
|
-
"x-payment-response": "encoded-payment-data",
|
|
224
|
-
},
|
|
225
186
|
data: MOCK_PAYMENT_INFO_RESPONSE.data,
|
|
187
|
+
headers: {},
|
|
226
188
|
config: {},
|
|
227
|
-
};
|
|
228
|
-
|
|
229
|
-
const result = await provider.fetchPaymentInfo(mockWalletProvider, {
|
|
189
|
+
});
|
|
190
|
+
const result = await provider.makeHttpRequest(mockWalletProvider, {
|
|
230
191
|
url: "https://www.x402.org/protected",
|
|
231
192
|
method: "GET",
|
|
232
193
|
});
|
|
233
|
-
expect(mockDecodeXPaymentResponse).toHaveBeenCalledWith("encoded-payment-data");
|
|
234
194
|
const parsedResult = JSON.parse(result);
|
|
235
|
-
expect(parsedResult.
|
|
236
|
-
expect(parsedResult.
|
|
237
|
-
expect(parsedResult.
|
|
195
|
+
expect(parsedResult.status).toBe("error_402_payment_required");
|
|
196
|
+
expect(parsedResult.acceptablePaymentOptions).toEqual(MOCK_PAYMENT_INFO_RESPONSE.data.accepts);
|
|
197
|
+
expect(parsedResult.nextSteps).toBeDefined();
|
|
238
198
|
});
|
|
239
|
-
it("should
|
|
240
|
-
const
|
|
241
|
-
mockDecodeXPaymentResponse.mockImplementation(() => {
|
|
242
|
-
throw new Error("Decode failed");
|
|
243
|
-
});
|
|
244
|
-
const error = new Error("Payment required");
|
|
199
|
+
it("should handle network errors", async () => {
|
|
200
|
+
const error = new Error("Network error");
|
|
245
201
|
error.isAxiosError = true;
|
|
246
|
-
error.
|
|
247
|
-
status: 402,
|
|
248
|
-
statusText: "Payment Required",
|
|
249
|
-
headers: {
|
|
250
|
-
"x-payment-response": paymentDetailsJson,
|
|
251
|
-
},
|
|
252
|
-
data: MOCK_PAYMENT_INFO_RESPONSE.data,
|
|
253
|
-
config: {},
|
|
254
|
-
};
|
|
202
|
+
error.request = {};
|
|
255
203
|
mockRequest.mockRejectedValue(error);
|
|
256
|
-
const result = await provider.
|
|
257
|
-
url: "https://
|
|
204
|
+
const result = await provider.makeHttpRequest(mockWalletProvider, {
|
|
205
|
+
url: "https://api.example.com/endpoint",
|
|
258
206
|
method: "GET",
|
|
259
207
|
});
|
|
260
208
|
const parsedResult = JSON.parse(result);
|
|
261
|
-
expect(parsedResult.
|
|
209
|
+
expect(parsedResult.error).toBe(true);
|
|
210
|
+
expect(parsedResult.message).toContain("Network error");
|
|
262
211
|
});
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
statusText: "Payment Required",
|
|
212
|
+
});
|
|
213
|
+
describe("retryHttpRequestWithX402", () => {
|
|
214
|
+
it("should successfully retry with payment", async () => {
|
|
215
|
+
mockDecodeXPaymentResponse.mockReturnValue(MOCK_PAYMENT_RESPONSE);
|
|
216
|
+
mockRequest.mockResolvedValue({
|
|
217
|
+
status: 200,
|
|
218
|
+
statusText: "OK",
|
|
219
|
+
data: { message: "Paid content" },
|
|
272
220
|
headers: {
|
|
273
|
-
"x-payment-response": "
|
|
221
|
+
"x-payment-response": "encoded-payment-data",
|
|
274
222
|
},
|
|
275
|
-
data: MOCK_PAYMENT_INFO_RESPONSE.data,
|
|
276
223
|
config: {},
|
|
277
|
-
};
|
|
278
|
-
|
|
279
|
-
const result = await provider.fetchPaymentInfo(mockWalletProvider, {
|
|
224
|
+
});
|
|
225
|
+
const result = await provider.retryWithX402(mockWalletProvider, {
|
|
280
226
|
url: "https://www.x402.org/protected",
|
|
281
227
|
method: "GET",
|
|
228
|
+
selectedPaymentOption: {
|
|
229
|
+
scheme: "exact",
|
|
230
|
+
network: "base-sepolia",
|
|
231
|
+
maxAmountRequired: "10000",
|
|
232
|
+
asset: "0x456",
|
|
233
|
+
},
|
|
282
234
|
});
|
|
235
|
+
// Update expectation to accept the payment selector function
|
|
236
|
+
expect(mockWithPaymentInterceptor).toHaveBeenCalledWith(mockAxiosInstance, "mock-signer", expect.any(Function));
|
|
283
237
|
const parsedResult = JSON.parse(result);
|
|
284
|
-
expect(parsedResult.
|
|
285
|
-
expect(parsedResult.
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
error.isAxiosError = true;
|
|
290
|
-
error.response = {
|
|
291
|
-
status: 500,
|
|
292
|
-
statusText: "Internal Server Error",
|
|
293
|
-
headers: {},
|
|
294
|
-
data: { error: "Internal server error" },
|
|
295
|
-
config: {},
|
|
296
|
-
};
|
|
297
|
-
mockRequest.mockRejectedValue(error);
|
|
298
|
-
const result = await provider.fetchPaymentInfo(mockWalletProvider, {
|
|
299
|
-
url: "https://api.example.com/endpoint",
|
|
300
|
-
method: "GET",
|
|
238
|
+
expect(parsedResult.status).toBe("success");
|
|
239
|
+
expect(parsedResult.details.paymentProof).toEqual({
|
|
240
|
+
transaction: MOCK_PAYMENT_RESPONSE.transaction,
|
|
241
|
+
network: MOCK_PAYMENT_RESPONSE.network,
|
|
242
|
+
payer: MOCK_PAYMENT_RESPONSE.payer,
|
|
301
243
|
});
|
|
302
|
-
expect(result).toContain("Error fetching payment info");
|
|
303
|
-
expect(result).toContain("HTTP 500");
|
|
304
|
-
expect(result).toContain("Internal server error");
|
|
305
244
|
});
|
|
306
|
-
it("should handle network errors", async () => {
|
|
245
|
+
it("should handle network errors during payment", async () => {
|
|
307
246
|
const error = new Error("Network error");
|
|
308
247
|
error.isAxiosError = true;
|
|
309
248
|
error.request = {};
|
|
310
249
|
mockRequest.mockRejectedValue(error);
|
|
311
|
-
const result = await provider.
|
|
312
|
-
url: "https://
|
|
250
|
+
const result = await provider.retryWithX402(mockWalletProvider, {
|
|
251
|
+
url: "https://www.x402.org/protected",
|
|
313
252
|
method: "GET",
|
|
253
|
+
selectedPaymentOption: {
|
|
254
|
+
scheme: "exact",
|
|
255
|
+
network: "base-sepolia",
|
|
256
|
+
maxAmountRequired: "10000",
|
|
257
|
+
asset: "0x456",
|
|
258
|
+
},
|
|
314
259
|
});
|
|
315
|
-
|
|
316
|
-
expect(
|
|
260
|
+
const parsedResult = JSON.parse(result);
|
|
261
|
+
expect(parsedResult.error).toBe(true);
|
|
262
|
+
expect(parsedResult.message).toContain("Network error");
|
|
317
263
|
});
|
|
318
264
|
});
|
|
319
|
-
describe("
|
|
320
|
-
it("should
|
|
265
|
+
describe("makeHttpRequestWithX402", () => {
|
|
266
|
+
it("should handle successful direct payment requests", async () => {
|
|
321
267
|
mockDecodeXPaymentResponse.mockReturnValue(MOCK_PAYMENT_RESPONSE);
|
|
322
268
|
mockRequest.mockResolvedValue({
|
|
323
269
|
status: 200,
|
|
324
270
|
statusText: "OK",
|
|
325
|
-
data:
|
|
271
|
+
data: { message: "Paid content" },
|
|
326
272
|
headers: {
|
|
327
|
-
"x-payment-response": "encoded-payment-
|
|
273
|
+
"x-payment-response": "encoded-payment-data",
|
|
328
274
|
},
|
|
329
275
|
config: {},
|
|
330
276
|
});
|
|
331
|
-
const result = await provider.
|
|
277
|
+
const result = await provider.makeHttpRequestWithX402(mockWalletProvider, {
|
|
332
278
|
url: "https://www.x402.org/protected",
|
|
333
279
|
method: "GET",
|
|
334
280
|
});
|
|
335
281
|
expect(mockWithPaymentInterceptor).toHaveBeenCalledWith(mockAxiosInstance, "mock-signer");
|
|
336
|
-
expect(mockRequest).toHaveBeenCalledWith({
|
|
337
|
-
url: "https://www.x402.org/protected",
|
|
338
|
-
method: "GET",
|
|
339
|
-
headers: undefined,
|
|
340
|
-
data: undefined,
|
|
341
|
-
});
|
|
342
282
|
const parsedResult = JSON.parse(result);
|
|
343
283
|
expect(parsedResult.success).toBe(true);
|
|
344
|
-
expect(parsedResult.
|
|
345
|
-
expect(parsedResult.
|
|
284
|
+
expect(parsedResult.data).toEqual({ message: "Paid content" });
|
|
285
|
+
expect(parsedResult.paymentProof).toEqual({
|
|
286
|
+
transaction: MOCK_PAYMENT_RESPONSE.transaction,
|
|
287
|
+
network: MOCK_PAYMENT_RESPONSE.network,
|
|
288
|
+
payer: MOCK_PAYMENT_RESPONSE.payer,
|
|
289
|
+
});
|
|
346
290
|
});
|
|
347
|
-
it("should handle successful
|
|
291
|
+
it("should handle successful non-payment requests", async () => {
|
|
348
292
|
mockRequest.mockResolvedValue({
|
|
349
293
|
status: 200,
|
|
350
294
|
statusText: "OK",
|
|
351
|
-
data: { message: "
|
|
295
|
+
data: { message: "Free content" },
|
|
352
296
|
headers: {},
|
|
353
297
|
config: {},
|
|
354
298
|
});
|
|
355
|
-
const result = await provider.
|
|
299
|
+
const result = await provider.makeHttpRequestWithX402(mockWalletProvider, {
|
|
356
300
|
url: "https://api.example.com/free",
|
|
357
301
|
method: "GET",
|
|
358
302
|
});
|
|
359
303
|
const parsedResult = JSON.parse(result);
|
|
360
304
|
expect(parsedResult.success).toBe(true);
|
|
361
|
-
expect(parsedResult.
|
|
362
|
-
expect(parsedResult.
|
|
363
|
-
});
|
|
364
|
-
it("should fallback to JSON.parse when decodeXPaymentResponse fails", async () => {
|
|
365
|
-
const paymentResponseJson = '{"transaction": "0x123"}';
|
|
366
|
-
mockDecodeXPaymentResponse.mockImplementation(() => {
|
|
367
|
-
throw new Error("Decode failed");
|
|
368
|
-
});
|
|
369
|
-
mockRequest.mockResolvedValue({
|
|
370
|
-
status: 200,
|
|
371
|
-
statusText: "OK",
|
|
372
|
-
data: "Success",
|
|
373
|
-
headers: {
|
|
374
|
-
"x-payment-response": paymentResponseJson,
|
|
375
|
-
},
|
|
376
|
-
config: {},
|
|
377
|
-
});
|
|
378
|
-
const result = await provider.paidRequest(mockWalletProvider, {
|
|
379
|
-
url: "https://www.x402.org/protected",
|
|
380
|
-
method: "GET",
|
|
381
|
-
});
|
|
382
|
-
const parsedResult = JSON.parse(result);
|
|
383
|
-
expect(parsedResult.paymentResponse).toEqual({ transaction: "0x123" });
|
|
384
|
-
});
|
|
385
|
-
it("should handle payment response parsing failures", async () => {
|
|
386
|
-
mockDecodeXPaymentResponse.mockImplementation(() => {
|
|
387
|
-
throw new Error("Decode failed");
|
|
388
|
-
});
|
|
389
|
-
mockRequest.mockResolvedValue({
|
|
390
|
-
status: 200,
|
|
391
|
-
statusText: "OK",
|
|
392
|
-
data: "Success",
|
|
393
|
-
headers: {
|
|
394
|
-
"x-payment-response": "invalid-json",
|
|
395
|
-
},
|
|
396
|
-
config: {},
|
|
397
|
-
});
|
|
398
|
-
const result = await provider.paidRequest(mockWalletProvider, {
|
|
399
|
-
url: "https://www.x402.org/protected",
|
|
400
|
-
method: "GET",
|
|
401
|
-
});
|
|
402
|
-
const parsedResult = JSON.parse(result);
|
|
403
|
-
expect(parsedResult.paymentResponse.error).toBe("Failed to decode payment response");
|
|
404
|
-
expect(parsedResult.paymentResponse.rawHeader).toBe("invalid-json");
|
|
405
|
-
});
|
|
406
|
-
it("should handle HTTP errors", async () => {
|
|
407
|
-
const error = new Error("Bad request");
|
|
408
|
-
error.isAxiosError = true;
|
|
409
|
-
error.response = {
|
|
410
|
-
status: 400,
|
|
411
|
-
statusText: "Bad Request",
|
|
412
|
-
headers: {},
|
|
413
|
-
data: { error: "Invalid parameters" },
|
|
414
|
-
config: {},
|
|
415
|
-
};
|
|
416
|
-
mockRequest.mockRejectedValue(error);
|
|
417
|
-
const result = await provider.paidRequest(mockWalletProvider, {
|
|
418
|
-
url: "https://api.example.com/endpoint",
|
|
419
|
-
method: "POST",
|
|
420
|
-
body: { test: "data" },
|
|
421
|
-
});
|
|
422
|
-
expect(result).toContain("Error making paid request");
|
|
423
|
-
expect(result).toContain("HTTP 400");
|
|
424
|
-
expect(result).toContain("Invalid parameters");
|
|
305
|
+
expect(parsedResult.data).toEqual({ message: "Free content" });
|
|
306
|
+
expect(parsedResult.paymentProof).toBeNull();
|
|
425
307
|
});
|
|
426
308
|
it("should handle network errors", async () => {
|
|
427
|
-
const error = new Error("
|
|
309
|
+
const error = new Error("Network error");
|
|
428
310
|
error.isAxiosError = true;
|
|
429
311
|
error.request = {};
|
|
430
312
|
mockRequest.mockRejectedValue(error);
|
|
431
|
-
const result = await provider.
|
|
313
|
+
const result = await provider.makeHttpRequestWithX402(mockWalletProvider, {
|
|
432
314
|
url: "https://api.example.com/endpoint",
|
|
433
315
|
method: "GET",
|
|
434
316
|
});
|
|
435
|
-
|
|
436
|
-
expect(
|
|
437
|
-
expect(
|
|
438
|
-
});
|
|
439
|
-
it("should handle generic errors", async () => {
|
|
440
|
-
const error = new Error("Something went wrong");
|
|
441
|
-
mockRequest.mockRejectedValue(error);
|
|
442
|
-
const result = await provider.paidRequest(mockWalletProvider, {
|
|
443
|
-
url: "https://api.example.com/endpoint",
|
|
444
|
-
method: "GET",
|
|
445
|
-
});
|
|
446
|
-
expect(result).toContain("Error making paid request");
|
|
447
|
-
expect(result).toContain("Something went wrong");
|
|
448
|
-
});
|
|
449
|
-
it("should pass through all request parameters", async () => {
|
|
450
|
-
mockRequest.mockResolvedValue({
|
|
451
|
-
status: 200,
|
|
452
|
-
data: "Success",
|
|
453
|
-
headers: {},
|
|
454
|
-
});
|
|
455
|
-
await provider.paidRequest(mockWalletProvider, {
|
|
456
|
-
url: "https://api.example.com/endpoint",
|
|
457
|
-
method: "POST",
|
|
458
|
-
headers: { "Content-Type": "application/json" },
|
|
459
|
-
body: { key: "value" },
|
|
460
|
-
});
|
|
461
|
-
expect(mockRequest).toHaveBeenCalledWith({
|
|
462
|
-
url: "https://api.example.com/endpoint",
|
|
463
|
-
method: "POST",
|
|
464
|
-
headers: { "Content-Type": "application/json" },
|
|
465
|
-
data: { key: "value" },
|
|
466
|
-
});
|
|
317
|
+
const parsedResult = JSON.parse(result);
|
|
318
|
+
expect(parsedResult.error).toBe(true);
|
|
319
|
+
expect(parsedResult.message).toContain("Network error");
|
|
467
320
|
});
|
|
468
321
|
});
|
|
469
322
|
});
|
package/dist/agentkit.d.ts
CHANGED
package/dist/agentkit.js
CHANGED
|
@@ -32,12 +32,13 @@ class AgentKit {
|
|
|
32
32
|
static async from(config = { actionProviders: [(0, action_providers_1.walletActionProvider)()] }) {
|
|
33
33
|
let walletProvider = config.walletProvider;
|
|
34
34
|
if (!config.walletProvider) {
|
|
35
|
-
if (!config.cdpApiKeyId || !config.cdpApiKeySecret) {
|
|
35
|
+
if (!config.cdpApiKeyId || !config.cdpApiKeySecret || !config.cdpWalletSecret) {
|
|
36
36
|
throw new Error("cdpApiKeyId and cdpApiKeySecret are required if not providing a walletProvider");
|
|
37
37
|
}
|
|
38
|
-
walletProvider = await wallet_providers_1.
|
|
38
|
+
walletProvider = await wallet_providers_1.CdpSmartWalletProvider.configureWithWallet({
|
|
39
39
|
apiKeyId: config.cdpApiKeyId,
|
|
40
40
|
apiKeySecret: config.cdpApiKeySecret,
|
|
41
|
+
walletSecret: config.cdpWalletSecret,
|
|
41
42
|
});
|
|
42
43
|
}
|
|
43
44
|
return new AgentKit({ ...config, walletProvider: walletProvider });
|
|
@@ -2,26 +2,35 @@ import { CdpClient } from "@coinbase/cdp-sdk";
|
|
|
2
2
|
import { Abi, Address, ContractFunctionArgs, ContractFunctionName, Hex, ReadContractParameters, ReadContractReturnType, TransactionRequest } from "viem";
|
|
3
3
|
import { Network } from "../network";
|
|
4
4
|
import { EvmWalletProvider } from "./evmWalletProvider";
|
|
5
|
-
import { WalletProviderWithClient,
|
|
5
|
+
import { WalletProviderWithClient, CdpWalletProviderConfig } from "./cdpShared";
|
|
6
6
|
/**
|
|
7
7
|
* A wallet provider that uses the Coinbase SDK.
|
|
8
8
|
*/
|
|
9
|
-
export declare class
|
|
9
|
+
export declare class CdpEvmWalletProvider extends EvmWalletProvider implements WalletProviderWithClient {
|
|
10
10
|
#private;
|
|
11
11
|
/**
|
|
12
|
-
* Constructs a new
|
|
12
|
+
* Constructs a new CdpEvmWalletProvider.
|
|
13
13
|
*
|
|
14
|
-
* @param config - The configuration options for the
|
|
14
|
+
* @param config - The configuration options for the CdpEvmWalletProvider.
|
|
15
15
|
*/
|
|
16
16
|
private constructor();
|
|
17
17
|
/**
|
|
18
|
-
* Configures a new
|
|
18
|
+
* Configures a new CdpEvmWalletProvider with a wallet.
|
|
19
19
|
*
|
|
20
20
|
* @param config - Optional configuration parameters
|
|
21
|
-
* @returns A Promise that resolves to a new
|
|
21
|
+
* @returns A Promise that resolves to a new CdpEvmWalletProvider instance
|
|
22
22
|
* @throws Error if required environment variables are missing or wallet initialization fails
|
|
23
23
|
*/
|
|
24
|
-
static configureWithWallet(config?:
|
|
24
|
+
static configureWithWallet(config?: CdpWalletProviderConfig): Promise<CdpEvmWalletProvider>;
|
|
25
|
+
/**
|
|
26
|
+
* Exports the wallet.
|
|
27
|
+
*
|
|
28
|
+
* @returns The wallet's data.
|
|
29
|
+
*/
|
|
30
|
+
exportWallet(): Promise<{
|
|
31
|
+
name: string | undefined;
|
|
32
|
+
address: `0x${string}`;
|
|
33
|
+
}>;
|
|
25
34
|
/**
|
|
26
35
|
* Signs a message.
|
|
27
36
|
*
|