n8n-nodes-agentsearch 0.4.0 → 0.6.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
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
n8n community node for [AgentSearch](https://agentsearchhq.com/?utm_source=n8n-nodes-agentsearch&utm_medium=package): live web search for workflows and AI agents.
|
|
4
4
|
|
|
5
5
|
- **Free Search**: up to 5 results per call, 25 searches per day per IP, **no credentials**.
|
|
6
|
-
- **Extract Page** (new in 0.3.0): read a page as clean markdown or text. $0.
|
|
7
|
-
- **Render Page** (new in 0.3.0): load a JavaScript-heavy page in a headless browser, then read it (markdown, text, HTML, links, optional screenshot). $0.
|
|
6
|
+
- **Extract Page** (new in 0.3.0): read a page as clean markdown or text. $0.007 per call (x402, USDC on Base).
|
|
7
|
+
- **Render Page** (new in 0.3.0): load a JavaScript-heavy page in a headless browser, then read it (markdown, text, HTML, links, optional screenshot). $0.010 per call.
|
|
8
8
|
- `usableAsTool`: all three work as tools for the n8n AI Agent node (search, then read the best page).
|
|
9
9
|
- No runtime dependencies.
|
|
10
10
|
|
|
@@ -30,21 +30,23 @@ Output (default):
|
|
|
30
30
|
|
|
31
31
|
If the daily free limit is reached (HTTP 429) the node fails with an explanation; enable *Continue On Fail* to keep the workflow running.
|
|
32
32
|
|
|
33
|
-
**Hit the 429?** Extract (full page text) and Render (JS pages) are in this node at $0.
|
|
33
|
+
**Hit the 429?** Extract (full page text) and Render (JS pages) are in this node at $0.007 / $0.010 per call: see below.
|
|
34
34
|
|
|
35
35
|
## Extract and Render (read full pages)
|
|
36
36
|
|
|
37
37
|
Search results are snippets. To read the page itself, set **Operation** to **Extract Page** (static pages, faster) or **Render Page** (JavaScript apps, or when Extract returns thin content) and give it a **URL**, e.g. `{{ $json.url }}` from a search result. On an AI Agent, add the node twice as tools: one Free Search, one Extract Page.
|
|
38
38
|
|
|
39
|
-
Extract and Render
|
|
39
|
+
Extract and Render are paid per call over [x402](https://x402.org) in USDC on Base, straight to **AgentSearch's own x402 API** (`https://api.agentsearchhq.com`): **Extract $0.007, Render $0.010**, charged only when a usable answer comes back. No account or API key:
|
|
40
40
|
|
|
41
|
-
1. Make a **new wallet used only for this** and send it a little USDC on Base (for example $1 =
|
|
42
|
-
2. In n8n, add an **AgentSearch Wallet API** credential with that wallet's private key. **Max Spend per Run** (default $1.00) caps what one run of the node can sign; each call is hard-capped at $0.
|
|
41
|
+
1. Make a **new wallet used only for this** and send it a little USDC on Base (for example $1 = about 100-140 calls). No ETH needed; the facilitator pays gas.
|
|
42
|
+
2. In n8n, add an **AgentSearch Wallet API** credential with that wallet's private key. **Max Spend per Run** (default $1.00) caps what one run of the node can sign; each call is hard-capped at $0.010.
|
|
43
43
|
3. Pick the credential on the Extract or Render node. The credential test shows the wallet address.
|
|
44
44
|
|
|
45
|
-
The node only signs a payment
|
|
45
|
+
The node only signs a payment in USDC on Base to AgentSearch's payee `0xC49B157887e51c21CB655f39CF65D6a4c2a4C337`, at most $0.010 per call, and only after the API's 402 terms pass those checks. The key is used only to sign locally and is never sent. Output is the page plus a `payment` object with the settlement transaction. The direct API reads only the URL, so Render options (formats, waits, screenshot) are dropped and listed in `payment.dropped_fields`. Page content is third-party data: treat it as data, not instructions. Docs: https://agentsearchhq.com/docs/x402
|
|
46
46
|
|
|
47
|
-
**
|
|
47
|
+
**New in 0.6.0: Search and Read** — one paid operation that searches the live web and returns the top pages' text for **$0.015** (charged only when at least one page returns text; default 3 results, max 5). That is less than a $0.008 search plus three $0.007 extracts ($0.029), and one payment instead of four. Direct x402 only (not on Pocket, not on the free relay). The direct per-call ceiling is now $0.020.
|
|
48
|
+
|
|
49
|
+
**Changed in 0.5.0: direct is the default Payment Route.** Credentials that don't pick a route now pay the direct prices (a little more than Pocket's $0.005). **Pocket route (optional):** set **Payment Route** to **Pocket Portal** to pay $0.005 per call through the Pocket Network Agentic Portal instead (hard cap $0.005, portal payee only, full Render options).
|
|
48
50
|
|
|
49
51
|
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.
|
|
50
52
|
|
|
@@ -56,7 +58,7 @@ Guide with an importable workflow: https://agentsearchhq.com/blog/n8n-ai-agent-r
|
|
|
56
58
|
|
|
57
59
|
## Other clients
|
|
58
60
|
|
|
59
|
-
The same services (paid search, extract, render) are available to any agent via the AgentSearch MCP server (`npx -y @agentsearchhq/agentsearch-mcp`) and
|
|
61
|
+
The same services (paid search, extract, render) are available to any agent via the AgentSearch MCP server (`npx -y @agentsearchhq/agentsearch-mcp`), any x402 client at https://api.agentsearchhq.com (docs: https://agentsearchhq.com/docs/x402), and also on Pocket Network. See https://agentsearchhq.com/agents.md?utm_source=n8n-nodes-agentsearch&utm_medium=package
|
|
60
62
|
|
|
61
63
|
## Development
|
|
62
64
|
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AgentSearchWalletApi = void 0;
|
|
4
4
|
/**
|
|
5
|
-
* Wallet used to pay per call for Extract and Render ($0.
|
|
6
|
-
* x402
|
|
5
|
+
* Wallet used to pay per call for Extract ($0.007) and Render ($0.010) in USDC on Base over x402,
|
|
6
|
+
* by default to AgentSearch's own x402 API (Pocket portal route optional). Free Search never uses it.
|
|
7
7
|
*/
|
|
8
8
|
class AgentSearchWalletApi {
|
|
9
9
|
constructor() {
|
|
@@ -19,17 +19,17 @@ 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 =
|
|
22
|
+
description: '64-hex private key of a NEW wallet made only for this, funded with a little USDC on Base (for example $1 = about 100-140 calls; no ETH needed). Used only to sign small USDC payments for Extract/Render; never sent anywhere.',
|
|
23
23
|
},
|
|
24
24
|
{
|
|
25
25
|
displayName: 'Payment Route',
|
|
26
26
|
name: 'paymentRoute',
|
|
27
27
|
type: 'options',
|
|
28
28
|
options: [
|
|
29
|
-
{ name: '
|
|
30
|
-
{ name: '
|
|
29
|
+
{ name: 'AgentSearch Direct x402 (Extract $0.007, Render $0.010)', value: 'direct', description: "Pay AgentSearch's own x402 API on Base (api.agentsearchhq.com) (default)" },
|
|
30
|
+
{ name: 'Pocket Portal ($0.005 per Call)', value: 'pocket', description: 'Pay through the Pocket Network Agentic Portal instead' },
|
|
31
31
|
],
|
|
32
|
-
default: '
|
|
32
|
+
default: 'direct',
|
|
33
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.',
|
|
34
34
|
},
|
|
35
35
|
{
|
|
@@ -38,7 +38,7 @@ class AgentSearchWalletApi {
|
|
|
38
38
|
type: 'number',
|
|
39
39
|
typeOptions: { minValue: 0.005, numberPrecision: 3 },
|
|
40
40
|
default: 1,
|
|
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
|
|
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). Each call is capped at $0.005 on the Pocket route and $0.010 on the direct route.',
|
|
42
42
|
},
|
|
43
43
|
];
|
|
44
44
|
}
|
|
@@ -8,21 +8,21 @@ const x402_1 = require("./x402");
|
|
|
8
8
|
exports.FREE_RELAY_URL = 'https://relay.agentsearchhq.com/v1/search';
|
|
9
9
|
exports.RELAY_BASE_URL = 'https://relay.agentsearchhq.com';
|
|
10
10
|
exports.PORTAL_URL = 'https://agent.pocket.network';
|
|
11
|
-
exports.CLIENT_TAG = 'n8n-nodes-agentsearch/0.
|
|
11
|
+
exports.CLIENT_TAG = 'n8n-nodes-agentsearch/0.6.0';
|
|
12
12
|
const DOCS = 'https://agentsearchhq.com/?utm_source=n8n-nodes-agentsearch&utm_medium=package';
|
|
13
13
|
const GUIDE = 'https://agentsearchhq.com/blog/n8n-ai-agent-read-web-pages?utm_source=n8n-nodes-agentsearch&utm_medium=package';
|
|
14
|
-
exports.LIMIT_MESSAGE = `Free AgentSearch limit reached (25 searches per day per IP; resets daily). For unlimited search plus extract (static pages) and render (JavaScript-heavy pages, or when extract returns thin content), use the paid API ($0.
|
|
14
|
+
exports.LIMIT_MESSAGE = `Free AgentSearch limit reached (25 searches per day per IP; resets daily). For unlimited search plus extract (static pages) and render (JavaScript-heavy pages, or when extract returns thin content), use the paid API (AgentSearch's own x402 API on Base: Extract $0.007, Render $0.010 per call in USDC; Pocket route $0.005 optional). Docs: ${DOCS}`;
|
|
15
15
|
exports.PORTAL_SERVICES = {
|
|
16
16
|
extract: { serviceId: 'agentsearch-web-extract-v1', path: '/v1/extract' },
|
|
17
17
|
render: { serviceId: 'agentsearch-web-render-v1', path: '/v1/render' },
|
|
18
18
|
};
|
|
19
|
-
exports.WALLET_SETUP = 'Add an "AgentSearch Wallet API" credential to this node: the private key of a NEW wallet made only for this, funded with a little USDC on Base (for example $1 =
|
|
19
|
+
exports.WALLET_SETUP = 'Add an "AgentSearch Wallet API" credential to this node: the private key of a NEW wallet made only for this, funded with a little USDC on Base (for example $1 = about 100-140 calls; no ETH needed). Each call is paid over x402 to AgentSearch\'s own API on Base (Extract $0.007, Render $0.010; failed calls are not charged), or $0.005 through the Pocket Network Agentic Portal if you pick that Payment Route. Free Search stays free and needs no credential. Guide: ' +
|
|
20
20
|
GUIDE;
|
|
21
21
|
function paidOnlyMessage(op) {
|
|
22
|
-
return `${op === 'extract' ? 'Extract' : 'Render'} is a paid operation ($0.
|
|
22
|
+
return `${op === 'extract' ? 'Extract' : 'Render'} is a paid operation (${op === 'extract' ? '$0.007' : '$0.010'} per call in USDC on Base via x402) and no wallet credential is set, so nothing was paid. ${exports.WALLET_SETUP}`;
|
|
23
23
|
}
|
|
24
24
|
function trialLimitMessage(op) {
|
|
25
|
-
return `Free ${op} allowance for today is used up. Continue at $0.
|
|
25
|
+
return `Free ${op} allowance for today is used up. Continue at ${op === 'extract' ? '$0.007' : '$0.010'} per call (x402, USDC on Base): ${exports.WALLET_SETUP}`;
|
|
26
26
|
}
|
|
27
27
|
const headerOf = (headers, name) => {
|
|
28
28
|
const h = (headers ?? {});
|
|
@@ -52,7 +52,7 @@ class AgentSearch {
|
|
|
52
52
|
group: ['transform'],
|
|
53
53
|
version: 1,
|
|
54
54
|
subtitle: '={{$parameter["operation"]}}',
|
|
55
|
-
description: 'Free live web search for AI agents, plus page Extract
|
|
55
|
+
description: 'Free live web search for AI agents, plus page Extract ($0.007), JavaScript Render ($0.010), and Search + Read ($0.015) per call via x402',
|
|
56
56
|
defaults: { name: 'AgentSearch' },
|
|
57
57
|
inputs: [n8n_workflow_1.NodeConnectionTypes.Main],
|
|
58
58
|
outputs: [n8n_workflow_1.NodeConnectionTypes.Main],
|
|
@@ -62,7 +62,7 @@ class AgentSearch {
|
|
|
62
62
|
name: 'agentSearchWalletApi',
|
|
63
63
|
required: false,
|
|
64
64
|
testedBy: 'agentSearchWalletTest',
|
|
65
|
-
displayOptions: { show: { operation: ['extract', 'render'] } },
|
|
65
|
+
displayOptions: { show: { operation: ['extract', 'render', 'searchAndRead'] } },
|
|
66
66
|
},
|
|
67
67
|
],
|
|
68
68
|
properties: [
|
|
@@ -77,13 +77,19 @@ class AgentSearch {
|
|
|
77
77
|
name: 'Extract Page',
|
|
78
78
|
value: 'extract',
|
|
79
79
|
action: 'Extract a page as markdown',
|
|
80
|
-
description: 'Read a page as clean markdown or text ($0.
|
|
80
|
+
description: 'Read a page as clean markdown or text ($0.007 per call, wallet credential)',
|
|
81
81
|
},
|
|
82
82
|
{
|
|
83
83
|
name: 'Render Page',
|
|
84
84
|
value: 'render',
|
|
85
85
|
action: 'Render a dynamic page',
|
|
86
|
-
description: 'Load a JavaScript-heavy page in a headless browser and read it ($0.
|
|
86
|
+
description: 'Load a JavaScript-heavy page in a headless browser and read it ($0.010 per call, wallet credential)',
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
name: 'Search and Read',
|
|
90
|
+
value: 'searchAndRead',
|
|
91
|
+
action: 'Search and read top pages',
|
|
92
|
+
description: 'Search the live web and return the top pages\' text in one paid call ($0.015, charged only when at least one page returns text; wallet credential; direct x402 only)',
|
|
87
93
|
},
|
|
88
94
|
],
|
|
89
95
|
default: 'freeSearch',
|
|
@@ -95,7 +101,7 @@ class AgentSearch {
|
|
|
95
101
|
default: '',
|
|
96
102
|
required: true,
|
|
97
103
|
placeholder: 'latest n8n release',
|
|
98
|
-
displayOptions: { show: { operation: ['freeSearch'] } },
|
|
104
|
+
displayOptions: { show: { operation: ['freeSearch', 'searchAndRead'] } },
|
|
99
105
|
},
|
|
100
106
|
{
|
|
101
107
|
displayName: 'Max Results',
|
|
@@ -105,6 +111,15 @@ class AgentSearch {
|
|
|
105
111
|
default: 5,
|
|
106
112
|
displayOptions: { show: { operation: ['freeSearch'] } },
|
|
107
113
|
},
|
|
114
|
+
{
|
|
115
|
+
displayName: 'Number of Results to Read',
|
|
116
|
+
name: 'numResults',
|
|
117
|
+
type: 'number',
|
|
118
|
+
typeOptions: { minValue: 1, maxValue: 5 },
|
|
119
|
+
default: 3,
|
|
120
|
+
description: 'How many top search results to read (default 3, max 5)',
|
|
121
|
+
displayOptions: { show: { operation: ['searchAndRead'] } },
|
|
122
|
+
},
|
|
108
123
|
{
|
|
109
124
|
displayName: 'Split Results Into Items',
|
|
110
125
|
name: 'split',
|
|
@@ -158,6 +173,23 @@ class AgentSearch {
|
|
|
158
173
|
description: 'Cap on returned characters per format',
|
|
159
174
|
displayOptions: { show: { operation: ['extract', 'render'] } },
|
|
160
175
|
},
|
|
176
|
+
{
|
|
177
|
+
displayName: 'Max Characters Per Page',
|
|
178
|
+
name: 'searchAndReadMaxChars',
|
|
179
|
+
type: 'number',
|
|
180
|
+
typeOptions: { minValue: 1, maxValue: 20000 },
|
|
181
|
+
default: 8000,
|
|
182
|
+
description: 'Cap on returned characters of page text per result (default 8000, max 20000)',
|
|
183
|
+
displayOptions: { show: { operation: ['searchAndRead'] } },
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
displayName: 'Render Fallback',
|
|
187
|
+
name: 'renderFallback',
|
|
188
|
+
type: 'boolean',
|
|
189
|
+
default: false,
|
|
190
|
+
description: 'Whether to render at most one thin page in the same $0.015 call if extract returns little text',
|
|
191
|
+
displayOptions: { show: { operation: ['searchAndRead'] } },
|
|
192
|
+
},
|
|
161
193
|
{
|
|
162
194
|
displayName: 'Options',
|
|
163
195
|
name: 'renderOptions',
|
|
@@ -240,7 +272,7 @@ class AgentSearch {
|
|
|
240
272
|
return { status: 'Error', message: 'Max Spend per Run must be a positive number of USD.' };
|
|
241
273
|
return {
|
|
242
274
|
status: 'OK',
|
|
243
|
-
message: `Valid key for wallet ${address}. Fund it with USDC on Base (no ETH needed); each Extract or Render call pays $0.005.`,
|
|
275
|
+
message: `Valid key for wallet ${address}. Fund it with USDC on Base (no ETH needed); each Extract ($0.007) or Render ($0.010) call pays AgentSearch's x402 API ($0.005 on the Pocket route).`,
|
|
244
276
|
};
|
|
245
277
|
},
|
|
246
278
|
},
|
|
@@ -259,6 +291,12 @@ class AgentSearch {
|
|
|
259
291
|
out.push({ json: r.json, pairedItem: { item: i } });
|
|
260
292
|
continue;
|
|
261
293
|
}
|
|
294
|
+
if (operation === 'searchAndRead') {
|
|
295
|
+
const r = await searchAndRead.call(this, i, signedAtomic);
|
|
296
|
+
signedAtomic = r.signedAtomic;
|
|
297
|
+
out.push({ json: r.json, pairedItem: { item: i } });
|
|
298
|
+
continue;
|
|
299
|
+
}
|
|
262
300
|
const query = this.getNodeParameter('query', i).trim();
|
|
263
301
|
if (!query)
|
|
264
302
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Query is empty', { itemIndex: i });
|
|
@@ -376,7 +414,8 @@ async function readPage(op, i, signedBefore) {
|
|
|
376
414
|
const capUsd = Number(creds.maxSpendPerRunUsd ?? 1);
|
|
377
415
|
const capAtomic = BigInt(Math.round((Number.isFinite(capUsd) && capUsd > 0 ? capUsd : 1) * 1000000));
|
|
378
416
|
const remaining = capAtomic - signedBefore;
|
|
379
|
-
|
|
417
|
+
// 0.5.0: direct is the default; only an explicit 'pocket' uses the Pocket portal.
|
|
418
|
+
const direct = creds.paymentRoute !== 'pocket';
|
|
380
419
|
const hardCap = direct ? x402_1.DIRECT_MAX_PER_CALL_ATOMIC : x402_1.MAX_PER_CALL_ATOMIC;
|
|
381
420
|
const payee = direct ? x402_1.DIRECT_PAYEE : x402_1.PORTAL_PAYEE;
|
|
382
421
|
const ceiling = remaining < hardCap ? remaining : hardCap;
|
|
@@ -462,3 +501,121 @@ async function readPage(op, i, signedBefore) {
|
|
|
462
501
|
};
|
|
463
502
|
return { json: { ...data, payment, portal: direct ? null : envelope.portal ?? null }, signedAtomic };
|
|
464
503
|
}
|
|
504
|
+
async function searchAndRead(i, signedBefore) {
|
|
505
|
+
const query = String(this.getNodeParameter('query', i) ?? '').trim();
|
|
506
|
+
if (!query)
|
|
507
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Query is empty', { itemIndex: i });
|
|
508
|
+
const numResults = this.getNodeParameter('numResults', i, 3);
|
|
509
|
+
const maxChars = this.getNodeParameter('searchAndReadMaxChars', i, 8000);
|
|
510
|
+
const renderFallback = this.getNodeParameter('renderFallback', i, false);
|
|
511
|
+
const body = { query };
|
|
512
|
+
if (numResults)
|
|
513
|
+
body.num_results = numResults;
|
|
514
|
+
if (maxChars)
|
|
515
|
+
body.max_chars = maxChars;
|
|
516
|
+
if (renderFallback)
|
|
517
|
+
body.render_fallback = true;
|
|
518
|
+
let creds;
|
|
519
|
+
try {
|
|
520
|
+
creds = await this.getCredentials('agentSearchWalletApi', i);
|
|
521
|
+
}
|
|
522
|
+
catch {
|
|
523
|
+
creds = undefined;
|
|
524
|
+
}
|
|
525
|
+
if (!creds?.privateKey) {
|
|
526
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Search and Read is a paid operation ($0.015 per call in USDC on Base via x402, charged only when at least one page returns text) and no wallet credential is set, so nothing was paid. It is not on the free relay. ' + exports.WALLET_SETUP, { itemIndex: i });
|
|
527
|
+
}
|
|
528
|
+
if (creds.paymentRoute === 'pocket') {
|
|
529
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Search and Read is available only on AgentSearch\'s own x402 API ($0.015 per call when at least one page returns text). Set Payment Route to Direct (the default) on the AgentSearch Wallet API credential. Pocket does not offer this operation. Nothing was signed.', { itemIndex: i });
|
|
530
|
+
}
|
|
531
|
+
let key;
|
|
532
|
+
try {
|
|
533
|
+
key = (0, x402_1.parsePrivateKey)(String(creds.privateKey));
|
|
534
|
+
}
|
|
535
|
+
catch (e) {
|
|
536
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), e.message, { itemIndex: i });
|
|
537
|
+
}
|
|
538
|
+
const capUsd = Number(creds.maxSpendPerRunUsd ?? 1);
|
|
539
|
+
const capAtomic = BigInt(Math.round((Number.isFinite(capUsd) && capUsd > 0 ? capUsd : 1) * 1000000));
|
|
540
|
+
const remaining = capAtomic - signedBefore;
|
|
541
|
+
const hardCap = x402_1.DIRECT_MAX_PER_CALL_ATOMIC;
|
|
542
|
+
const payee = x402_1.DIRECT_PAYEE;
|
|
543
|
+
const ceiling = remaining < hardCap ? remaining : hardCap;
|
|
544
|
+
if (ceiling <= 0n) {
|
|
545
|
+
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 });
|
|
546
|
+
}
|
|
547
|
+
const url = `${x402_1.DIRECT_URL}/x402/v1/search_and_read`;
|
|
548
|
+
const expectRes = '/x402/v1/search_and_read';
|
|
549
|
+
const unpaid = await post.call(this, url, body);
|
|
550
|
+
if (unpaid.statusCode !== 402) {
|
|
551
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `The AgentSearch x402 API answered ${unpaid.statusCode} before payment: ${errorText(unpaid.body)}. Nothing was signed.`, { itemIndex: i });
|
|
552
|
+
}
|
|
553
|
+
let required;
|
|
554
|
+
try {
|
|
555
|
+
required = (0, x402_1.decodeBase64Json)(headerOf(unpaid.headers, 'payment-required') ?? '');
|
|
556
|
+
}
|
|
557
|
+
catch {
|
|
558
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), "The portal's 402 is not valid x402 v2. Nothing was signed.", { itemIndex: i });
|
|
559
|
+
}
|
|
560
|
+
if (required?.x402Version !== 2)
|
|
561
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Unsupported x402 version. Nothing was signed.', { itemIndex: i });
|
|
562
|
+
const resUrl = String(required.resource?.url ?? '');
|
|
563
|
+
if (!resUrl.replace(/\/+$/, '').endsWith(expectRes)) {
|
|
564
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `The 402 is for ${resUrl}, not ${expectRes}. Nothing was signed.`, { itemIndex: i });
|
|
565
|
+
}
|
|
566
|
+
let accepted;
|
|
567
|
+
try {
|
|
568
|
+
accepted = (0, x402_1.selectAccept)(required.accepts, ceiling, payee);
|
|
569
|
+
}
|
|
570
|
+
catch (e) {
|
|
571
|
+
const msg = e.message;
|
|
572
|
+
if (ceiling < hardCap && ceiling === remaining) {
|
|
573
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), msg, { itemIndex: i });
|
|
574
|
+
}
|
|
575
|
+
if (ceiling < 15000n) {
|
|
576
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `${msg} Search and Read costs $0.015; raise "Max Spend per Run" or the per-call ceiling to at least 20000 atomic units ($0.020). Nothing was signed.`, { itemIndex: i });
|
|
577
|
+
}
|
|
578
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), msg, { itemIndex: i });
|
|
579
|
+
}
|
|
580
|
+
const amount = BigInt(accepted.amount);
|
|
581
|
+
const { payload, from } = (0, x402_1.createPaymentPayload)(required, accepted, key);
|
|
582
|
+
const signedAtomic = signedBefore + amount;
|
|
583
|
+
let paid;
|
|
584
|
+
try {
|
|
585
|
+
paid = await post.call(this, url, body, { 'PAYMENT-SIGNATURE': (0, x402_1.encodePaymentHeader)(payload) });
|
|
586
|
+
}
|
|
587
|
+
catch (e) {
|
|
588
|
+
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 });
|
|
589
|
+
}
|
|
590
|
+
if (paid.statusCode < 200 || paid.statusCode >= 300) {
|
|
591
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `The AgentSearch x402 API answered ${paid.statusCode}: ${errorText(paid.body)}. A non-2xx answer is not settled, so you should not be charged.`, { itemIndex: i });
|
|
592
|
+
}
|
|
593
|
+
let receipt;
|
|
594
|
+
const rh = headerOf(paid.headers, 'payment-response');
|
|
595
|
+
if (rh) {
|
|
596
|
+
try {
|
|
597
|
+
receipt = (0, x402_1.decodeBase64Json)(rh);
|
|
598
|
+
}
|
|
599
|
+
catch {
|
|
600
|
+
receipt = undefined;
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
const data = paid.body && typeof paid.body === 'object' ? paid.body : { result: paid.body };
|
|
604
|
+
const tx = receipt?.transaction || null;
|
|
605
|
+
const payment = {
|
|
606
|
+
amount_usd: (0, x402_1.atomicToUsd)(amount),
|
|
607
|
+
amount_atomic: amount.toString(),
|
|
608
|
+
asset: 'USDC',
|
|
609
|
+
asset_address: x402_1.USDC_BASE,
|
|
610
|
+
network: x402_1.BASE_NETWORK,
|
|
611
|
+
pay_to: payee,
|
|
612
|
+
payer: from,
|
|
613
|
+
service_id: 'search_and_read',
|
|
614
|
+
route: 'agentsearch-x402-direct',
|
|
615
|
+
settled: receipt?.success ?? false,
|
|
616
|
+
transaction: tx,
|
|
617
|
+
...(tx ? { explorer: `https://basescan.org/tx/${tx}` } : {}),
|
|
618
|
+
run_spent_usd: (0, x402_1.atomicToUsd)(signedAtomic),
|
|
619
|
+
};
|
|
620
|
+
return { json: { ...data, payment, portal: null }, signedAtomic };
|
|
621
|
+
}
|
|
@@ -261,8 +261,8 @@ exports.MAX_PER_CALL_ATOMIC = 5000n;
|
|
|
261
261
|
/** AgentSearch's own x402 API on Base (opt-in "Payment Route: Direct"). */
|
|
262
262
|
exports.DIRECT_URL = 'https://api.agentsearchhq.com';
|
|
263
263
|
exports.DIRECT_PAYEE = '0xC49B157887e51c21CB655f39CF65D6a4c2a4C337';
|
|
264
|
-
/** $0.
|
|
265
|
-
exports.DIRECT_MAX_PER_CALL_ATOMIC =
|
|
264
|
+
/** $0.020 hard ceiling per direct call (extract $0.007, render $0.010, search_and_read $0.015). */
|
|
265
|
+
exports.DIRECT_MAX_PER_CALL_ATOMIC = 20000n;
|
|
266
266
|
const eqAddr = (a, b) => typeof a === 'string' && a.toLowerCase() === b.toLowerCase();
|
|
267
267
|
function atomicToUsd(a) {
|
|
268
268
|
const n = BigInt(a);
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "n8n-nodes-agentsearch",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"author": {
|
|
5
5
|
"name": "AgentSearch",
|
|
6
6
|
"email": "AgentSearchhq@gmail.com",
|
|
7
7
|
"url": "https://agentsearchhq.com"
|
|
8
8
|
},
|
|
9
|
-
"description": "n8n community node for AgentSearch: free live web search for AI agents (no credentials), plus page Extract and JavaScript Render
|
|
9
|
+
"description": "n8n community node for AgentSearch: free live web search for AI agents (no credentials), plus page Extract ($0.007) and JavaScript Render ($0.010) per call, paid in USDC on Base via x402 to AgentSearch's own API",
|
|
10
10
|
"keywords": [
|
|
11
11
|
"n8n-community-node-package",
|
|
12
12
|
"n8n",
|