n8n-nodes-agentsearch 0.5.0 → 0.6.1

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 are paid per call over [x402](https://x402.org) in USDC on Ba
44
44
 
45
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
+ **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
+
47
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.
@@ -8,7 +8,7 @@ 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.5.0';
11
+ exports.CLIENT_TAG = 'n8n-nodes-agentsearch/0.6.1';
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
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}`;
@@ -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 ($0.007) and JavaScript Render ($0.010) per call via x402',
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: [
@@ -85,6 +85,12 @@ class AgentSearch {
85
85
  action: 'Render a dynamic page',
86
86
  description: 'Load a JavaScript-heavy page in a headless browser and read it ($0.010 per call, wallet credential)',
87
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)',
93
+ },
88
94
  ],
89
95
  default: 'freeSearch',
90
96
  },
@@ -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',
@@ -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 });
@@ -463,3 +501,121 @@ async function readPage(op, i, signedBefore) {
463
501
  };
464
502
  return { json: { ...data, payment, portal: direct ? null : envelope.portal ?? null }, signedAtomic };
465
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.010 hard ceiling per direct call (extract $0.007, render $0.010). */
265
- exports.DIRECT_MAX_PER_CALL_ATOMIC = 10000n;
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,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-agentsearch",
3
- "version": "0.5.0",
3
+ "version": "0.6.1",
4
4
  "author": {
5
5
  "name": "AgentSearch",
6
6
  "email": "AgentSearchhq@gmail.com",