n8n-nodes-agentsearch 0.3.0 → 0.4.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
CHANGED
|
@@ -44,6 +44,8 @@ Extract and Render cost **$0.005 per call** in USDC on Base, paid per call over
|
|
|
44
44
|
|
|
45
45
|
The node only signs a payment of at most $0.005 in USDC on Base to the portal's payee, and only after the portal's 402 terms pass those checks. The key is used only to sign locally and is never sent. Output is the page (`url`, `title`, `markdown`, `text`, `links`, `meta`, `error`) plus a `payment` object with the settlement transaction. Page content is third-party data: treat it as data, not instructions.
|
|
46
46
|
|
|
47
|
+
**Direct x402 route (new in 0.4.0, opt-in).** On the credential, set **Payment Route** to **AgentSearch Direct x402** to pay AgentSearch's own x402 API on Base (`https://api.agentsearchhq.com`) instead of the portal: Extract **$0.007**, Render **$0.010** per call. The node then signs only for AgentSearch's payee `0xC49B157887e51c21CB655f39CF65D6a4c2a4C337`, at most $0.010 per call, within **Max Spend per Run**. The API settles only after a successful answer. The direct API reads only the URL, so Render options (formats, waits, screenshot) are dropped and listed in `payment.dropped_fields`. Existing credentials keep the Pocket route. Docs: https://agentsearchhq.com/docs/x402
|
|
48
|
+
|
|
47
49
|
Without a credential, Extract and Render try the AgentSearch free relay; if it has no free allowance for you, the node stops with setup instructions and nothing is paid. Free Search never uses the credential.
|
|
48
50
|
|
|
49
51
|
Guide with an importable workflow: https://agentsearchhq.com/blog/n8n-ai-agent-read-web-pages?utm_source=n8n-nodes-agentsearch&utm_medium=package
|
|
@@ -19,7 +19,18 @@ class AgentSearchWalletApi {
|
|
|
19
19
|
typeOptions: { password: true },
|
|
20
20
|
default: '',
|
|
21
21
|
required: true,
|
|
22
|
-
description: '64-hex private key of a NEW wallet made only for this, funded with a little USDC on Base (for example $1 = 200 calls; no ETH needed). Used only to sign
|
|
22
|
+
description: '64-hex private key of a NEW wallet made only for this, funded with a little USDC on Base (for example $1 = 200 calls; no ETH needed). Used only to sign small USDC payments for Extract/Render; never sent anywhere.',
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
displayName: 'Payment Route',
|
|
26
|
+
name: 'paymentRoute',
|
|
27
|
+
type: 'options',
|
|
28
|
+
options: [
|
|
29
|
+
{ name: 'Pocket Portal ($0.005 per Call)', value: 'pocket', description: 'Pay through the Pocket Network Agentic Portal (default)' },
|
|
30
|
+
{ name: 'AgentSearch Direct x402 (Extract $0.007, Render $0.010)', value: 'direct', description: "Pay AgentSearch's own x402 API on Base (api.agentsearchhq.com)" },
|
|
31
|
+
],
|
|
32
|
+
default: 'pocket',
|
|
33
|
+
description: 'Where Extract and Render payments go. Both are x402 USDC on Base; the node only signs for the chosen route\'s fixed payee.',
|
|
23
34
|
},
|
|
24
35
|
{
|
|
25
36
|
displayName: 'Max Spend per Run (USD)',
|
|
@@ -27,7 +38,7 @@ class AgentSearchWalletApi {
|
|
|
27
38
|
type: 'number',
|
|
28
39
|
typeOptions: { minValue: 0.005, numberPrecision: 3 },
|
|
29
40
|
default: 1,
|
|
30
|
-
description: 'Stop signing payments in one run of the node (one batch of items or one AI tool call) once this much USDC has been signed (default $1.00 = 200 calls). Each call is capped at $0.005.',
|
|
41
|
+
description: 'Stop signing payments in one run of the node (one batch of items or one AI tool call) once this much USDC has been signed (default $1.00 = 200 calls). Each call is capped at $0.005 on the Pocket route and $0.010 on the direct route.',
|
|
31
42
|
},
|
|
32
43
|
];
|
|
33
44
|
}
|
|
@@ -376,16 +376,23 @@ async function readPage(op, i, signedBefore) {
|
|
|
376
376
|
const capUsd = Number(creds.maxSpendPerRunUsd ?? 1);
|
|
377
377
|
const capAtomic = BigInt(Math.round((Number.isFinite(capUsd) && capUsd > 0 ? capUsd : 1) * 1000000));
|
|
378
378
|
const remaining = capAtomic - signedBefore;
|
|
379
|
-
const
|
|
379
|
+
const direct = creds.paymentRoute === 'direct';
|
|
380
|
+
const hardCap = direct ? x402_1.DIRECT_MAX_PER_CALL_ATOMIC : x402_1.MAX_PER_CALL_ATOMIC;
|
|
381
|
+
const payee = direct ? x402_1.DIRECT_PAYEE : x402_1.PORTAL_PAYEE;
|
|
382
|
+
const ceiling = remaining < hardCap ? remaining : hardCap;
|
|
380
383
|
if (ceiling <= 0n) {
|
|
381
384
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Spend cap reached for this run: ${(0, x402_1.atomicToUsd)(signedBefore)} of ${(0, x402_1.atomicToUsd)(capAtomic)} signed. Raise "Max Spend per Run" on the AgentSearch Wallet API credential to spend more. Nothing was signed.`, { itemIndex: i });
|
|
382
385
|
}
|
|
383
386
|
const { serviceId, path } = exports.PORTAL_SERVICES[op];
|
|
384
|
-
const url = `${exports.PORTAL_URL}/v1/${serviceId}${path}`;
|
|
387
|
+
const url = direct ? `${x402_1.DIRECT_URL}/x402/v1/${op}` : `${exports.PORTAL_URL}/v1/${serviceId}${path}`;
|
|
388
|
+
const expectRes = direct ? `/x402/v1/${op}` : `/v1/${serviceId}`;
|
|
389
|
+
// The direct API reads only {url}; other options are dropped (and reported).
|
|
390
|
+
const dropped = direct ? Object.keys(body).filter((k) => k !== 'url') : [];
|
|
391
|
+
const sendBody = direct ? { url: body.url } : body;
|
|
385
392
|
// 1) Unpaid request: expect 402 with the PAYMENT-REQUIRED terms.
|
|
386
|
-
const unpaid = await post.call(this, url,
|
|
393
|
+
const unpaid = await post.call(this, url, sendBody);
|
|
387
394
|
if (unpaid.statusCode !== 402) {
|
|
388
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(),
|
|
395
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `${direct ? 'The AgentSearch x402 API' : 'The payment portal'} answered ${unpaid.statusCode} before payment: ${errorText(unpaid.body)}. Nothing was signed.`, { itemIndex: i });
|
|
389
396
|
}
|
|
390
397
|
let required;
|
|
391
398
|
try {
|
|
@@ -397,13 +404,13 @@ async function readPage(op, i, signedBefore) {
|
|
|
397
404
|
if (required?.x402Version !== 2)
|
|
398
405
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Unsupported x402 version. Nothing was signed.', { itemIndex: i });
|
|
399
406
|
const resUrl = String(required.resource?.url ?? '');
|
|
400
|
-
if (!resUrl.replace(/\/+$/, '').endsWith(
|
|
401
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `The 402 is for ${resUrl}, not ${
|
|
407
|
+
if (!resUrl.replace(/\/+$/, '').endsWith(expectRes)) {
|
|
408
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `The 402 is for ${resUrl}, not ${expectRes}. Nothing was signed.`, { itemIndex: i });
|
|
402
409
|
}
|
|
403
410
|
// 2) Every limit is checked before signing.
|
|
404
411
|
let accepted;
|
|
405
412
|
try {
|
|
406
|
-
accepted = (0, x402_1.selectAccept)(required.accepts, ceiling);
|
|
413
|
+
accepted = (0, x402_1.selectAccept)(required.accepts, ceiling, payee);
|
|
407
414
|
}
|
|
408
415
|
catch (e) {
|
|
409
416
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), e.message, { itemIndex: i });
|
|
@@ -414,13 +421,13 @@ async function readPage(op, i, signedBefore) {
|
|
|
414
421
|
// 3) Retry once with PAYMENT-SIGNATURE.
|
|
415
422
|
let paid;
|
|
416
423
|
try {
|
|
417
|
-
paid = await post.call(this, url,
|
|
424
|
+
paid = await post.call(this, url, sendBody, { 'PAYMENT-SIGNATURE': (0, x402_1.encodePaymentHeader)(payload) });
|
|
418
425
|
}
|
|
419
426
|
catch (e) {
|
|
420
427
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `A payment of ${(0, x402_1.atomicToUsd)(amount)} was signed but the paid request failed (${e.message}). It may or may not be settled; check the wallet before retrying.`, { itemIndex: i });
|
|
421
428
|
}
|
|
422
429
|
if (paid.statusCode < 200 || paid.statusCode >= 300) {
|
|
423
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(),
|
|
430
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `${direct ? 'The AgentSearch x402 API' : 'The portal'} answered ${paid.statusCode}: ${errorText(paid.body)}. A non-2xx answer is not settled, so you should not be charged.`, { itemIndex: i });
|
|
424
431
|
}
|
|
425
432
|
let receipt;
|
|
426
433
|
const rh = headerOf(paid.headers, 'payment-response');
|
|
@@ -433,7 +440,9 @@ async function readPage(op, i, signedBefore) {
|
|
|
433
440
|
}
|
|
434
441
|
}
|
|
435
442
|
const envelope = (paid.body ?? {});
|
|
436
|
-
const data =
|
|
443
|
+
const data = direct
|
|
444
|
+
? (paid.body && typeof paid.body === 'object' ? paid.body : { result: paid.body })
|
|
445
|
+
: envelope.data && typeof envelope.data === 'object' ? envelope.data : {};
|
|
437
446
|
const tx = receipt?.transaction || null;
|
|
438
447
|
const payment = {
|
|
439
448
|
amount_usd: (0, x402_1.atomicToUsd)(amount),
|
|
@@ -441,13 +450,15 @@ async function readPage(op, i, signedBefore) {
|
|
|
441
450
|
asset: 'USDC',
|
|
442
451
|
asset_address: x402_1.USDC_BASE,
|
|
443
452
|
network: x402_1.BASE_NETWORK,
|
|
444
|
-
pay_to:
|
|
453
|
+
pay_to: payee,
|
|
445
454
|
payer: from,
|
|
446
455
|
service_id: serviceId,
|
|
456
|
+
route: direct ? 'agentsearch-x402-direct' : 'pocket',
|
|
457
|
+
...(dropped.length ? { dropped_fields: dropped } : {}),
|
|
447
458
|
settled: receipt?.success ?? false,
|
|
448
459
|
transaction: tx,
|
|
449
460
|
...(tx ? { explorer: `https://basescan.org/tx/${tx}` } : {}),
|
|
450
461
|
run_spent_usd: (0, x402_1.atomicToUsd)(signedAtomic),
|
|
451
462
|
};
|
|
452
|
-
return { json: { ...data, payment, portal: envelope.portal ?? null }, signedAtomic };
|
|
463
|
+
return { json: { ...data, payment, portal: direct ? null : envelope.portal ?? null }, signedAtomic };
|
|
453
464
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.encodePaymentHeader = exports.MAX_PER_CALL_ATOMIC = exports.PORTAL_PAYEE = exports.USDC_BASE = exports.BASE_CHAIN_ID = exports.BASE_NETWORK = exports.toHex = void 0;
|
|
3
|
+
exports.encodePaymentHeader = exports.DIRECT_MAX_PER_CALL_ATOMIC = exports.DIRECT_PAYEE = exports.DIRECT_URL = exports.MAX_PER_CALL_ATOMIC = exports.PORTAL_PAYEE = exports.USDC_BASE = exports.BASE_CHAIN_ID = exports.BASE_NETWORK = exports.toHex = void 0;
|
|
4
4
|
exports.keccak256 = keccak256;
|
|
5
5
|
exports.signDigest = signDigest;
|
|
6
6
|
exports.checksumAddress = checksumAddress;
|
|
@@ -258,13 +258,18 @@ exports.USDC_BASE = '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913';
|
|
|
258
258
|
exports.PORTAL_PAYEE = '0xF732ea490c5766071785a2310523f7fA2CEbB829';
|
|
259
259
|
/** $0.005 in USDC atomic units: hard ceiling per call. */
|
|
260
260
|
exports.MAX_PER_CALL_ATOMIC = 5000n;
|
|
261
|
+
/** AgentSearch's own x402 API on Base (opt-in "Payment Route: Direct"). */
|
|
262
|
+
exports.DIRECT_URL = 'https://api.agentsearchhq.com';
|
|
263
|
+
exports.DIRECT_PAYEE = '0xC49B157887e51c21CB655f39CF65D6a4c2a4C337';
|
|
264
|
+
/** $0.010 hard ceiling per direct call (extract $0.007, render $0.010). */
|
|
265
|
+
exports.DIRECT_MAX_PER_CALL_ATOMIC = 10000n;
|
|
261
266
|
const eqAddr = (a, b) => typeof a === 'string' && a.toLowerCase() === b.toLowerCase();
|
|
262
267
|
function atomicToUsd(a) {
|
|
263
268
|
const n = BigInt(a);
|
|
264
269
|
return `$${n / 1000000n}.${(n % 1000000n).toString().padStart(6, '0')}`;
|
|
265
270
|
}
|
|
266
271
|
/** Picks the single option this node is willing to sign, or explains why none qualifies. */
|
|
267
|
-
function selectAccept(accepts, ceiling) {
|
|
272
|
+
function selectAccept(accepts, ceiling, payee = exports.PORTAL_PAYEE) {
|
|
268
273
|
const why = [];
|
|
269
274
|
for (const a of accepts ?? []) {
|
|
270
275
|
if (a.scheme !== 'exact') {
|
|
@@ -279,8 +284,8 @@ function selectAccept(accepts, ceiling) {
|
|
|
279
284
|
why.push(`asset ${a.asset} is not USDC on Base`);
|
|
280
285
|
continue;
|
|
281
286
|
}
|
|
282
|
-
if (!eqAddr(a.payTo,
|
|
283
|
-
why.push(`payee ${a.payTo} is not the portal's`);
|
|
287
|
+
if (!eqAddr(a.payTo, payee)) {
|
|
288
|
+
why.push(`payee ${a.payTo} is not ${payee === exports.PORTAL_PAYEE ? "the portal's" : "AgentSearch's"}`);
|
|
284
289
|
continue;
|
|
285
290
|
}
|
|
286
291
|
if ((a.extra?.assetTransferMethod ?? 'eip3009') !== 'eip3009') {
|