n8n-nodes-agentsearch 0.2.3 → 0.3.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
@@ -2,8 +2,11 @@
2
2
 
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
- - **Free Search** operation: up to 5 results per call, 25 searches per day per IP, **no credentials**.
6
- - `usableAsTool`: works as a tool for the n8n AI Agent node.
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.005 per call.
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.005 per call.
8
+ - `usableAsTool`: all three work as tools for the n8n AI Agent node (search, then read the best page).
9
+ - No runtime dependencies.
7
10
 
8
11
  ## Install
9
12
 
@@ -27,19 +30,37 @@ Output (default):
27
30
 
28
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.
29
32
 
33
+ **Hit the 429?** Extract (full page text) and Render (JS pages) are in this node at $0.005 per call: see below.
34
+
35
+ ## Extract and Render (read full pages)
36
+
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
+
39
+ Extract and Render cost **$0.005 per call** in USDC on Base, paid per call over [x402](https://x402.org) through the Pocket Network Agentic Portal. No account or API key:
40
+
41
+ 1. Make a **new wallet used only for this** and send it a little USDC on Base (for example $1 = 200 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.005.
43
+ 3. Pick the credential on the Extract or Render node. The credential test shows the wallet address.
44
+
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
+
47
+ 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
+
49
+ Guide with an importable workflow: https://agentsearchhq.com/blog/n8n-ai-agent-read-web-pages?utm_source=n8n-nodes-agentsearch&utm_medium=package
50
+
30
51
  ## Workflow template (no install needed)
31
52
 
32
53
  `templates/agentsearch-free-search.workflow.json` does the same with the built-in **HTTP Request** node. Import it via **Workflows → Import from File** (or paste the JSON onto the canvas).
33
54
 
34
- ## Paid API
55
+ ## Other clients
35
56
 
36
- Unlimited search plus page extract and JS render are $0.005 per call via the Pocket Agentic Portal (x402, USDC on Base). See https://agentsearchhq.com/agents.md?utm_source=n8n-nodes-agentsearch&utm_medium=package
57
+ The same services (paid search, extract, render) are available to any agent via the AgentSearch MCP server (`npx -y @agentsearchhq/agentsearch-mcp`) and the Pocket Agentic Portal. See https://agentsearchhq.com/agents.md?utm_source=n8n-nodes-agentsearch&utm_medium=package
37
58
 
38
59
  ## Development
39
60
 
40
61
  ```bash
41
- npm install && npm test # mocked tests
42
- AGENTSEARCH_LIVE=1 npm test # + one real free search
62
+ npm install && npm test # mocked tests (incl. x402 signing vectors from the reference client)
63
+ AGENTSEARCH_LIVE=1 npm test # + one real free search and one free-relay extract probe (never pays)
43
64
  ```
44
65
 
45
66
  MIT
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AgentSearchWalletApi = void 0;
4
+ /**
5
+ * Wallet used to pay per call for Extract and Render ($0.005 in USDC on Base,
6
+ * x402 through the Pocket Network Agentic Portal). Free Search never uses it.
7
+ */
8
+ class AgentSearchWalletApi {
9
+ constructor() {
10
+ this.name = 'agentSearchWalletApi';
11
+ this.displayName = 'AgentSearch Wallet API';
12
+ this.icon = { light: 'file:agentsearch.svg', dark: 'file:agentsearch.dark.svg' };
13
+ this.documentationUrl = 'https://agentsearchhq.com/blog/n8n-ai-agent-read-web-pages';
14
+ this.properties = [
15
+ {
16
+ displayName: 'Wallet Private Key',
17
+ name: 'privateKey',
18
+ type: 'string',
19
+ typeOptions: { password: true },
20
+ default: '',
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 $0.005 USDC payments; never sent anywhere.',
23
+ },
24
+ {
25
+ displayName: 'Max Spend per Run (USD)',
26
+ name: 'maxSpendPerRunUsd',
27
+ type: 'number',
28
+ typeOptions: { minValue: 0.005, numberPrecision: 3 },
29
+ 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.',
31
+ },
32
+ ];
33
+ }
34
+ }
35
+ exports.AgentSearchWalletApi = AgentSearchWalletApi;
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><rect width="64" height="64" rx="12" fill="#111827"/><circle cx="28" cy="28" r="14" fill="none" stroke="#38bdf8" stroke-width="6"/><path d="M38 38l14 14" stroke="#38bdf8" stroke-width="7" stroke-linecap="round"/></svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><rect width="64" height="64" rx="12" fill="#111827"/><circle cx="28" cy="28" r="14" fill="none" stroke="#38bdf8" stroke-width="6"/><path d="M38 38l14 14" stroke="#38bdf8" stroke-width="7" stroke-linecap="round"/></svg>
@@ -1,53 +1,264 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AgentSearch = exports.LIMIT_MESSAGE = exports.CLIENT_TAG = exports.FREE_RELAY_URL = void 0;
3
+ exports.AgentSearch = exports.WALLET_SETUP = exports.PORTAL_SERVICES = exports.LIMIT_MESSAGE = exports.CLIENT_TAG = exports.PORTAL_URL = exports.RELAY_BASE_URL = exports.FREE_RELAY_URL = void 0;
4
+ exports.paidOnlyMessage = paidOnlyMessage;
5
+ exports.trialLimitMessage = trialLimitMessage;
4
6
  const n8n_workflow_1 = require("n8n-workflow");
7
+ const x402_1 = require("./x402");
5
8
  exports.FREE_RELAY_URL = 'https://relay.agentsearchhq.com/v1/search';
6
- exports.CLIENT_TAG = 'n8n-nodes-agentsearch/0.2.3';
9
+ exports.RELAY_BASE_URL = 'https://relay.agentsearchhq.com';
10
+ exports.PORTAL_URL = 'https://agent.pocket.network';
11
+ exports.CLIENT_TAG = 'n8n-nodes-agentsearch/0.3.0';
7
12
  const DOCS = 'https://agentsearchhq.com/?utm_source=n8n-nodes-agentsearch&utm_medium=package';
13
+ const GUIDE = 'https://agentsearchhq.com/blog/n8n-ai-agent-read-web-pages?utm_source=n8n-nodes-agentsearch&utm_medium=package';
8
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.005 per call via the Pocket Agentic Portal, x402 USDC on Base). Docs: ${DOCS}`;
15
+ exports.PORTAL_SERVICES = {
16
+ extract: { serviceId: 'agentsearch-web-extract-v1', path: '/v1/extract' },
17
+ render: { serviceId: 'agentsearch-web-render-v1', path: '/v1/render' },
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 = 200 calls; no ETH needed). Each call costs $0.005, paid over x402 through the Pocket Network Agentic Portal. Free Search stays free and needs no credential. Guide: ' +
20
+ GUIDE;
21
+ function paidOnlyMessage(op) {
22
+ return `${op === 'extract' ? 'Extract' : 'Render'} is a paid operation ($0.005 per call in USDC on Base) and no wallet credential is set, so nothing was paid. ${exports.WALLET_SETUP}`;
23
+ }
24
+ function trialLimitMessage(op) {
25
+ return `Free ${op} allowance for today is used up. Continue at $0.005 per call: ${exports.WALLET_SETUP}`;
26
+ }
27
+ const headerOf = (headers, name) => {
28
+ const h = (headers ?? {});
29
+ const key = Object.keys(h).find((k) => k.toLowerCase() === name.toLowerCase());
30
+ const v = key ? h[key] : undefined;
31
+ return Array.isArray(v) ? String(v[0]) : v === undefined || v === null ? undefined : String(v);
32
+ };
33
+ function errorText(body) {
34
+ const e = body?.error;
35
+ if (e && typeof e === 'object')
36
+ return `${String(e.code ?? '')} ${String(e.message ?? '')}`.trim();
37
+ if (typeof body === 'string')
38
+ return body.slice(0, 300);
39
+ try {
40
+ return JSON.stringify(body).slice(0, 300);
41
+ }
42
+ catch {
43
+ return '';
44
+ }
45
+ }
9
46
  class AgentSearch {
10
47
  constructor() {
11
48
  this.description = {
12
49
  displayName: 'AgentSearch',
13
50
  name: 'agentSearch',
14
- icon: 'file:agentsearch.svg',
51
+ icon: { light: 'file:agentsearch.svg', dark: 'file:agentsearch.dark.svg' },
15
52
  group: ['transform'],
16
53
  version: 1,
17
54
  subtitle: '={{$parameter["operation"]}}',
18
- description: 'Free live web search for AI agents (no credentials, 25 searches/day)',
55
+ description: 'Free live web search for AI agents, plus page Extract and JavaScript Render ($0.005 per call)',
19
56
  defaults: { name: 'AgentSearch' },
20
- inputs: ['main'],
21
- outputs: ['main'],
57
+ inputs: [n8n_workflow_1.NodeConnectionTypes.Main],
58
+ outputs: [n8n_workflow_1.NodeConnectionTypes.Main],
22
59
  usableAsTool: true,
23
- credentials: [],
60
+ credentials: [
61
+ {
62
+ name: 'agentSearchWalletApi',
63
+ required: false,
64
+ testedBy: 'agentSearchWalletTest',
65
+ displayOptions: { show: { operation: ['extract', 'render'] } },
66
+ },
67
+ ],
24
68
  properties: [
25
69
  {
26
70
  displayName: 'Operation',
27
71
  name: 'operation',
28
72
  type: 'options',
29
73
  noDataExpression: true,
30
- options: [{ name: 'Free Search', value: 'freeSearch', action: 'Search the web for free', description: 'Up to 5 results, 25 searches per day, no key' }],
74
+ options: [
75
+ { name: 'Free Search', value: 'freeSearch', action: 'Search the web for free', description: 'Up to 5 results, 25 searches per day, no key' },
76
+ {
77
+ name: 'Extract Page',
78
+ value: 'extract',
79
+ action: 'Extract a page as markdown',
80
+ description: 'Read a page as clean markdown or text ($0.005 per call, wallet credential)',
81
+ },
82
+ {
83
+ name: 'Render Page',
84
+ value: 'render',
85
+ action: 'Render a dynamic page',
86
+ description: 'Load a JavaScript-heavy page in a headless browser and read it ($0.005 per call, wallet credential)',
87
+ },
88
+ ],
31
89
  default: 'freeSearch',
32
90
  },
33
- { displayName: 'Query', name: 'query', type: 'string', default: '', required: true, placeholder: 'latest n8n release' },
34
- { displayName: 'Max Results', name: 'maxResults', type: 'number', typeOptions: { minValue: 1, maxValue: 5 }, default: 5 },
91
+ {
92
+ displayName: 'Query',
93
+ name: 'query',
94
+ type: 'string',
95
+ default: '',
96
+ required: true,
97
+ placeholder: 'latest n8n release',
98
+ displayOptions: { show: { operation: ['freeSearch'] } },
99
+ },
100
+ {
101
+ displayName: 'Max Results',
102
+ name: 'maxResults',
103
+ type: 'number',
104
+ typeOptions: { minValue: 1, maxValue: 5 },
105
+ default: 5,
106
+ displayOptions: { show: { operation: ['freeSearch'] } },
107
+ },
35
108
  {
36
109
  displayName: 'Split Results Into Items',
37
110
  name: 'split',
38
111
  type: 'boolean',
39
112
  default: false,
40
113
  description: 'Whether to output one item per result instead of one item with a results array',
114
+ displayOptions: { show: { operation: ['freeSearch'] } },
115
+ },
116
+ {
117
+ displayName: 'URL',
118
+ name: 'url',
119
+ type: 'string',
120
+ default: '',
121
+ required: true,
122
+ placeholder: 'https://example.com/article',
123
+ description: 'Absolute public http(s) URL of the page to read',
124
+ displayOptions: { show: { operation: ['extract', 'render'] } },
125
+ },
126
+ {
127
+ displayName: 'Formats',
128
+ name: 'extractFormats',
129
+ type: 'multiOptions',
130
+ options: [
131
+ { name: 'Markdown', value: 'markdown' },
132
+ { name: 'Text', value: 'text' },
133
+ ],
134
+ default: ['markdown'],
135
+ description: 'Renderings to return',
136
+ displayOptions: { show: { operation: ['extract'] } },
137
+ },
138
+ {
139
+ displayName: 'Formats',
140
+ name: 'renderFormats',
141
+ type: 'multiOptions',
142
+ options: [
143
+ { name: 'HTML', value: 'html' },
144
+ { name: 'Links', value: 'links' },
145
+ { name: 'Markdown', value: 'markdown' },
146
+ { name: 'Text', value: 'text' },
147
+ ],
148
+ default: ['markdown'],
149
+ description: 'Renderings of the rendered page to return',
150
+ displayOptions: { show: { operation: ['render'] } },
151
+ },
152
+ {
153
+ displayName: 'Max Characters',
154
+ name: 'maxChars',
155
+ type: 'number',
156
+ typeOptions: { minValue: 1, maxValue: 100000 },
157
+ default: 20000,
158
+ description: 'Cap on returned characters per format',
159
+ displayOptions: { show: { operation: ['extract', 'render'] } },
160
+ },
161
+ {
162
+ displayName: 'Options',
163
+ name: 'renderOptions',
164
+ type: 'collection',
165
+ placeholder: 'Add Option',
166
+ default: {},
167
+ displayOptions: { show: { operation: ['render'] } },
168
+ options: [
169
+ {
170
+ displayName: 'Block Resources',
171
+ name: 'block',
172
+ type: 'multiOptions',
173
+ options: [
174
+ { name: 'Font', value: 'font' },
175
+ { name: 'Image', value: 'image' },
176
+ { name: 'Media', value: 'media' },
177
+ { name: 'Stylesheet', value: 'stylesheet' },
178
+ ],
179
+ default: ['media', 'font'],
180
+ description: 'Resource types to block while rendering',
181
+ },
182
+ {
183
+ displayName: 'Full Page Screenshot',
184
+ name: 'fullPage',
185
+ type: 'boolean',
186
+ default: false,
187
+ description: 'Whether to capture the full page height (clipped to 4000 px) when taking a screenshot',
188
+ },
189
+ {
190
+ displayName: 'Screenshot',
191
+ name: 'screenshot',
192
+ type: 'boolean',
193
+ default: false,
194
+ description: 'Whether to also capture a screenshot, returned as base64',
195
+ },
196
+ {
197
+ displayName: 'Wait For Selector',
198
+ name: 'waitForSelector',
199
+ type: 'string',
200
+ default: '',
201
+ description: 'CSS selector to wait for (at most 1.5 s) before reading the page',
202
+ },
203
+ {
204
+ displayName: 'Wait Milliseconds',
205
+ name: 'waitMs',
206
+ type: 'number',
207
+ typeOptions: { minValue: 0, maxValue: 1500 },
208
+ default: 0,
209
+ description: 'Extra fixed wait after load (0-1500 ms)',
210
+ },
211
+ {
212
+ displayName: 'Wait Until',
213
+ name: 'waitUntil',
214
+ type: 'options',
215
+ options: [
216
+ { name: 'DOM Content Loaded', value: 'domcontentloaded' },
217
+ { name: 'Load', value: 'load' },
218
+ { name: 'Network Idle', value: 'networkidle' },
219
+ ],
220
+ default: 'domcontentloaded',
221
+ description: 'Navigation event to wait for before reading the page',
222
+ },
223
+ ],
41
224
  },
42
225
  ],
43
226
  };
227
+ this.methods = {
228
+ credentialTest: {
229
+ async agentSearchWalletTest(credential) {
230
+ const data = (credential.data ?? {});
231
+ let address;
232
+ try {
233
+ address = (0, x402_1.addressOf)((0, x402_1.parsePrivateKey)(String(data.privateKey ?? '')));
234
+ }
235
+ catch (e) {
236
+ return { status: 'Error', message: e.message };
237
+ }
238
+ const cap = Number(data.maxSpendPerRunUsd ?? 1);
239
+ if (!Number.isFinite(cap) || cap <= 0)
240
+ return { status: 'Error', message: 'Max Spend per Run must be a positive number of USD.' };
241
+ return {
242
+ 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.`,
244
+ };
245
+ },
246
+ },
247
+ };
44
248
  }
45
249
  async execute() {
46
- var _a, _b, _c, _d;
47
250
  const items = this.getInputData();
48
251
  const out = [];
252
+ let signedAtomic = 0n;
49
253
  for (let i = 0; i < items.length; i++) {
50
254
  try {
255
+ const operation = this.getNodeParameter('operation', i, 'freeSearch');
256
+ if (operation === 'extract' || operation === 'render') {
257
+ const r = await readPage.call(this, operation, i, signedAtomic);
258
+ signedAtomic = r.signedAtomic;
259
+ out.push({ json: r.json, pairedItem: { item: i } });
260
+ continue;
261
+ }
51
262
  const query = this.getNodeParameter('query', i).trim();
52
263
  if (!query)
53
264
  throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Query is empty', { itemIndex: i });
@@ -65,15 +276,16 @@ class AgentSearch {
65
276
  });
66
277
  }
67
278
  catch (e) {
68
- const status = (_c = (_a = e === null || e === void 0 ? void 0 : e.httpCode) !== null && _a !== void 0 ? _a : (_b = e === null || e === void 0 ? void 0 : e.response) === null || _b === void 0 ? void 0 : _b.status) !== null && _c !== void 0 ? _c : e === null || e === void 0 ? void 0 : e.statusCode;
279
+ const err = e;
280
+ const status = err?.httpCode ?? err?.response?.status ?? err?.statusCode;
69
281
  if (String(status) === '429')
70
282
  throw new n8n_workflow_1.NodeOperationError(this.getNode(), exports.LIMIT_MESSAGE, { itemIndex: i });
71
- throw e;
283
+ throw new n8n_workflow_1.NodeApiError(this.getNode(), e, { itemIndex: i });
72
284
  }
73
285
  if (res && typeof res === 'object')
74
286
  delete res.provider;
75
287
  if (split) {
76
- for (const r of (_d = res === null || res === void 0 ? void 0 : res.results) !== null && _d !== void 0 ? _d : [])
288
+ for (const r of res?.results ?? [])
77
289
  out.push({ json: { query, ...r }, pairedItem: { item: i } });
78
290
  }
79
291
  else {
@@ -85,10 +297,157 @@ class AgentSearch {
85
297
  out.push({ json: { error: e.message }, pairedItem: { item: i } });
86
298
  continue;
87
299
  }
88
- throw e;
300
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), e, { itemIndex: i });
89
301
  }
90
302
  }
91
303
  return [out];
92
304
  }
93
305
  }
94
306
  exports.AgentSearch = AgentSearch;
307
+ function buildBody(op, i) {
308
+ const url = String(this.getNodeParameter('url', i) ?? '').trim();
309
+ if (!/^https?:\/\/\S+$/i.test(url))
310
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'URL must be an absolute http(s) URL', { itemIndex: i });
311
+ const maxChars = this.getNodeParameter('maxChars', i, 20000);
312
+ if (op === 'extract') {
313
+ const formats = this.getNodeParameter('extractFormats', i, ['markdown']);
314
+ return { url, formats: formats?.length ? formats : ['markdown'], max_chars: maxChars };
315
+ }
316
+ const formats = this.getNodeParameter('renderFormats', i, ['markdown']);
317
+ const o = this.getNodeParameter('renderOptions', i, {});
318
+ const body = { url, formats: formats?.length ? formats : ['markdown'], max_chars: maxChars };
319
+ if (o.waitUntil)
320
+ body.wait_until = o.waitUntil;
321
+ if (typeof o.waitForSelector === 'string' && o.waitForSelector.trim())
322
+ body.wait_for_selector = o.waitForSelector.trim();
323
+ if (typeof o.waitMs === 'number' && o.waitMs > 0)
324
+ body.wait_ms = o.waitMs;
325
+ if (Array.isArray(o.block))
326
+ body.block = o.block;
327
+ if (o.screenshot === true)
328
+ body.screenshot = true;
329
+ if (o.fullPage === true)
330
+ body.full_page = true;
331
+ return body;
332
+ }
333
+ async function post(url, body, headers = {}) {
334
+ const req = {
335
+ method: 'POST',
336
+ url,
337
+ body,
338
+ headers: { 'X-Agent-Client': exports.CLIENT_TAG, accept: 'application/json', ...headers },
339
+ json: true,
340
+ timeout: 60000,
341
+ returnFullResponse: true,
342
+ ignoreHttpStatusErrors: true,
343
+ };
344
+ return (await this.helpers.httpRequest(req));
345
+ }
346
+ async function readPage(op, i, signedBefore) {
347
+ const body = buildBody.call(this, op, i);
348
+ let creds;
349
+ try {
350
+ creds = await this.getCredentials('agentSearchWalletApi', i);
351
+ }
352
+ catch {
353
+ creds = undefined; // no wallet credential attached: use the free allowance if the relay offers one
354
+ }
355
+ if (!creds?.privateKey) {
356
+ const { path } = exports.PORTAL_SERVICES[op];
357
+ const res = await post.call(this, `${exports.RELAY_BASE_URL}${path}`, body);
358
+ if (res.statusCode >= 200 && res.statusCode < 300) {
359
+ const data = res.body && typeof res.body === 'object' ? res.body : { result: res.body };
360
+ delete data.provider;
361
+ return { json: { ...data, free_trial: true }, signedAtomic: signedBefore };
362
+ }
363
+ if (res.statusCode === 429)
364
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), trialLimitMessage(op), { itemIndex: i });
365
+ if ([401, 402, 403, 404, 405].includes(res.statusCode))
366
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), paidOnlyMessage(op), { itemIndex: i });
367
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `AgentSearch free ${op} failed (HTTP ${res.statusCode}): ${errorText(res.body)}`, { itemIndex: i });
368
+ }
369
+ let key;
370
+ try {
371
+ key = (0, x402_1.parsePrivateKey)(String(creds.privateKey));
372
+ }
373
+ catch (e) {
374
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), e.message, { itemIndex: i });
375
+ }
376
+ const capUsd = Number(creds.maxSpendPerRunUsd ?? 1);
377
+ const capAtomic = BigInt(Math.round((Number.isFinite(capUsd) && capUsd > 0 ? capUsd : 1) * 1000000));
378
+ const remaining = capAtomic - signedBefore;
379
+ const ceiling = remaining < x402_1.MAX_PER_CALL_ATOMIC ? remaining : x402_1.MAX_PER_CALL_ATOMIC;
380
+ if (ceiling <= 0n) {
381
+ 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
+ }
383
+ const { serviceId, path } = exports.PORTAL_SERVICES[op];
384
+ const url = `${exports.PORTAL_URL}/v1/${serviceId}${path}`;
385
+ // 1) Unpaid request: expect 402 with the PAYMENT-REQUIRED terms.
386
+ const unpaid = await post.call(this, url, body);
387
+ if (unpaid.statusCode !== 402) {
388
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `The payment portal answered ${unpaid.statusCode} before payment: ${errorText(unpaid.body)}. Nothing was signed.`, { itemIndex: i });
389
+ }
390
+ let required;
391
+ try {
392
+ required = (0, x402_1.decodeBase64Json)(headerOf(unpaid.headers, 'payment-required') ?? '');
393
+ }
394
+ catch {
395
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), "The portal's 402 is not valid x402 v2. Nothing was signed.", { itemIndex: i });
396
+ }
397
+ if (required?.x402Version !== 2)
398
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Unsupported x402 version. Nothing was signed.', { itemIndex: i });
399
+ const resUrl = String(required.resource?.url ?? '');
400
+ if (!resUrl.replace(/\/+$/, '').endsWith(`/v1/${serviceId}`)) {
401
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `The 402 is for ${resUrl}, not ${serviceId}. Nothing was signed.`, { itemIndex: i });
402
+ }
403
+ // 2) Every limit is checked before signing.
404
+ let accepted;
405
+ try {
406
+ accepted = (0, x402_1.selectAccept)(required.accepts, ceiling);
407
+ }
408
+ catch (e) {
409
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), e.message, { itemIndex: i });
410
+ }
411
+ const amount = BigInt(accepted.amount);
412
+ const { payload, from } = (0, x402_1.createPaymentPayload)(required, accepted, key);
413
+ const signedAtomic = signedBefore + amount; // counted at signing: a signed authorization may be settled
414
+ // 3) Retry once with PAYMENT-SIGNATURE.
415
+ let paid;
416
+ try {
417
+ paid = await post.call(this, url, body, { 'PAYMENT-SIGNATURE': (0, x402_1.encodePaymentHeader)(payload) });
418
+ }
419
+ catch (e) {
420
+ 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
+ }
422
+ if (paid.statusCode < 200 || paid.statusCode >= 300) {
423
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `The portal answered ${paid.statusCode}: ${errorText(paid.body)}. A non-2xx answer is not settled, so you should not be charged.`, { itemIndex: i });
424
+ }
425
+ let receipt;
426
+ const rh = headerOf(paid.headers, 'payment-response');
427
+ if (rh) {
428
+ try {
429
+ receipt = (0, x402_1.decodeBase64Json)(rh);
430
+ }
431
+ catch {
432
+ receipt = undefined;
433
+ }
434
+ }
435
+ const envelope = (paid.body ?? {});
436
+ const data = envelope.data && typeof envelope.data === 'object' ? envelope.data : {};
437
+ const tx = receipt?.transaction || null;
438
+ const payment = {
439
+ amount_usd: (0, x402_1.atomicToUsd)(amount),
440
+ amount_atomic: amount.toString(),
441
+ asset: 'USDC',
442
+ asset_address: x402_1.USDC_BASE,
443
+ network: x402_1.BASE_NETWORK,
444
+ pay_to: x402_1.PORTAL_PAYEE,
445
+ payer: from,
446
+ service_id: serviceId,
447
+ settled: receipt?.success ?? false,
448
+ transaction: tx,
449
+ ...(tx ? { explorer: `https://basescan.org/tx/${tx}` } : {}),
450
+ run_spent_usd: (0, x402_1.atomicToUsd)(signedAtomic),
451
+ };
452
+ return { json: { ...data, payment, portal: envelope.portal ?? null }, signedAtomic };
453
+ }
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><rect width="64" height="64" rx="12" fill="#111827"/><circle cx="28" cy="28" r="14" fill="none" stroke="#38bdf8" stroke-width="6"/><path d="M38 38l14 14" stroke="#38bdf8" stroke-width="7" stroke-linecap="round"/></svg>
@@ -0,0 +1,342 @@
1
+ "use strict";
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;
4
+ exports.keccak256 = keccak256;
5
+ exports.signDigest = signDigest;
6
+ exports.checksumAddress = checksumAddress;
7
+ exports.parsePrivateKey = parsePrivateKey;
8
+ exports.addressOf = addressOf;
9
+ exports.transferWithAuthorizationDigest = transferWithAuthorizationDigest;
10
+ exports.atomicToUsd = atomicToUsd;
11
+ exports.selectAccept = selectAccept;
12
+ exports.decodeBase64Json = decodeBase64Json;
13
+ exports.createPaymentPayload = createPaymentPayload;
14
+ /**
15
+ * Minimal, dependency-free x402 v2 "exact" payer for USDC on Base (EIP-3009
16
+ * TransferWithAuthorization signed as EIP-712 typed data).
17
+ *
18
+ * n8n verified community nodes may not ship runtime dependencies, so this file
19
+ * implements the three primitives the payment needs with only node:crypto:
20
+ * keccak-256, secp256k1 ECDSA (RFC 6979 deterministic nonces, low-s, recoverable
21
+ * v) and EIP-712 hashing. Its output is checked byte-for-byte against the
22
+ * reference @x402/evm + viem client in the test suite.
23
+ *
24
+ * The private key is only used to sign; it is never logged or returned.
25
+ */
26
+ const crypto_1 = require("crypto");
27
+ /* ----------------------------- keccak-256 ----------------------------- */
28
+ const MASK64 = (1n << 64n) - 1n;
29
+ const RC = [];
30
+ const ROT = [];
31
+ const PI = [];
32
+ (() => {
33
+ let r = 1;
34
+ for (let i = 0; i < 24; i++) {
35
+ let c = 0n;
36
+ for (let j = 0; j < 7; j++) {
37
+ r = ((r << 1) ^ ((r >> 7) * 0x71)) % 256;
38
+ if (r & 2)
39
+ c ^= 1n << ((1n << BigInt(j)) - 1n);
40
+ }
41
+ RC.push(c);
42
+ }
43
+ let x = 1;
44
+ let y = 0;
45
+ for (let t = 0; t < 24; t++) {
46
+ ROT[x + 5 * y] = (((t + 1) * (t + 2)) / 2) % 64;
47
+ [x, y] = [y, (2 * x + 3 * y) % 5];
48
+ }
49
+ ROT[0] = 0;
50
+ for (let i = 0; i < 25; i++) {
51
+ const xi = i % 5;
52
+ const yi = Math.floor(i / 5);
53
+ PI[i] = yi + 5 * ((2 * xi + 3 * yi) % 5);
54
+ }
55
+ })();
56
+ const rotl = (v, n) => (n === 0 ? v : ((v << BigInt(n)) | (v >> BigInt(64 - n))) & MASK64);
57
+ function keccakF(s) {
58
+ const c = new Array(5);
59
+ const b = new Array(25);
60
+ for (let round = 0; round < 24; round++) {
61
+ for (let x = 0; x < 5; x++)
62
+ c[x] = s[x] ^ s[x + 5] ^ s[x + 10] ^ s[x + 15] ^ s[x + 20];
63
+ for (let x = 0; x < 5; x++) {
64
+ const d = c[(x + 4) % 5] ^ rotl(c[(x + 1) % 5], 1);
65
+ for (let y = 0; y < 25; y += 5)
66
+ s[x + y] ^= d;
67
+ }
68
+ for (let i = 0; i < 25; i++)
69
+ b[PI[i]] = rotl(s[i], ROT[i]);
70
+ for (let y = 0; y < 25; y += 5) {
71
+ for (let x = 0; x < 5; x++)
72
+ s[x + y] = b[x + y] ^ (~b[((x + 1) % 5) + y] & MASK64 & b[((x + 2) % 5) + y]);
73
+ }
74
+ s[0] ^= RC[round];
75
+ }
76
+ }
77
+ function keccak256(data) {
78
+ const rate = 136;
79
+ const padLen = rate - (data.length % rate);
80
+ const msg = new Uint8Array(data.length + padLen);
81
+ msg.set(data);
82
+ msg[data.length] ^= 0x01;
83
+ msg[msg.length - 1] ^= 0x80;
84
+ const s = new Array(25).fill(0n);
85
+ for (let off = 0; off < msg.length; off += rate) {
86
+ for (let i = 0; i < rate / 8; i++) {
87
+ let lane = 0n;
88
+ for (let k = 7; k >= 0; k--)
89
+ lane = (lane << 8n) | BigInt(msg[off + i * 8 + k]);
90
+ s[i] ^= lane;
91
+ }
92
+ keccakF(s);
93
+ }
94
+ const out = new Uint8Array(32);
95
+ for (let i = 0; i < 4; i++) {
96
+ let lane = s[i];
97
+ for (let k = 0; k < 8; k++) {
98
+ out[i * 8 + k] = Number(lane & 0xffn);
99
+ lane >>= 8n;
100
+ }
101
+ }
102
+ return out;
103
+ }
104
+ /* ------------------------------ bytes utils ----------------------------- */
105
+ const toHex = (b) => '0x' + Buffer.from(b).toString('hex');
106
+ exports.toHex = toHex;
107
+ const fromHex = (h) => new Uint8Array(Buffer.from(h.replace(/^0x/i, ''), 'hex'));
108
+ const bigToBytes = (n, len = 32) => fromHex(n.toString(16).padStart(len * 2, '0'));
109
+ const bytesToBig = (b) => (b.length ? BigInt((0, exports.toHex)(b)) : 0n);
110
+ const concat = (...parts) => {
111
+ const out = new Uint8Array(parts.reduce((n, p) => n + p.length, 0));
112
+ let o = 0;
113
+ for (const p of parts) {
114
+ out.set(p, o);
115
+ o += p.length;
116
+ }
117
+ return out;
118
+ };
119
+ const utf8 = (s) => new Uint8Array(Buffer.from(s, 'utf8'));
120
+ /* ------------------------------- secp256k1 ------------------------------ */
121
+ const P = 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2fn;
122
+ const N = 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141n;
123
+ const G = {
124
+ x: 0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798n,
125
+ y: 0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8n,
126
+ };
127
+ const mod = (a, m) => {
128
+ const r = a % m;
129
+ return r >= 0n ? r : r + m;
130
+ };
131
+ function inv(a, m) {
132
+ let [lo, hi] = [mod(a, m), m];
133
+ let [x0, x1] = [1n, 0n];
134
+ while (lo > 1n) {
135
+ const q = hi / lo;
136
+ [lo, hi] = [hi - q * lo, lo];
137
+ [x0, x1] = [x1 - q * x0, x0];
138
+ }
139
+ return mod(x0, m);
140
+ }
141
+ function add(p, q) {
142
+ if (!p)
143
+ return q;
144
+ if (!q)
145
+ return p;
146
+ if (p.x === q.x) {
147
+ if (mod(p.y + q.y, P) === 0n)
148
+ return null;
149
+ const l = mod(3n * p.x * p.x * inv(2n * p.y, P), P);
150
+ const x = mod(l * l - 2n * p.x, P);
151
+ return { x, y: mod(l * (p.x - x) - p.y, P) };
152
+ }
153
+ const l = mod((q.y - p.y) * inv(q.x - p.x, P), P);
154
+ const x = mod(l * l - p.x - q.x, P);
155
+ return { x, y: mod(l * (p.x - x) - p.y, P) };
156
+ }
157
+ function mul(k, p) {
158
+ let r = null;
159
+ let a = p;
160
+ while (k > 0n) {
161
+ if (k & 1n)
162
+ r = add(r, a);
163
+ a = add(a, a);
164
+ k >>= 1n;
165
+ }
166
+ return r;
167
+ }
168
+ function hmac(key, ...data) {
169
+ const h = (0, crypto_1.createHmac)('sha256', key);
170
+ for (const d of data)
171
+ h.update(d);
172
+ return new Uint8Array(h.digest());
173
+ }
174
+ /** RFC 6979 deterministic k for secp256k1 / SHA-256 sized inputs. */
175
+ function rfc6979(d, h1) {
176
+ const x = bigToBytes(d);
177
+ const h = bigToBytes(mod(bytesToBig(h1), N));
178
+ let v = new Uint8Array(32).fill(1);
179
+ let k = new Uint8Array(32).fill(0);
180
+ k = hmac(k, v, Uint8Array.of(0), x, h);
181
+ v = hmac(k, v);
182
+ k = hmac(k, v, Uint8Array.of(1), x, h);
183
+ v = hmac(k, v);
184
+ for (;;) {
185
+ v = hmac(k, v);
186
+ const t = bytesToBig(v);
187
+ if (t >= 1n && t < N)
188
+ return t;
189
+ k = hmac(k, v, Uint8Array.of(0));
190
+ v = hmac(k, v);
191
+ }
192
+ }
193
+ /** Signs a 32-byte digest. Returns 65-byte r || s || v (v = 27 or 28), low-s. */
194
+ function signDigest(digest, privateKey) {
195
+ const z = mod(bytesToBig(digest), N);
196
+ let k = rfc6979(privateKey, digest);
197
+ for (;;) {
198
+ const R = mul(k, G);
199
+ if (R) {
200
+ const r = mod(R.x, N);
201
+ if (r !== 0n) {
202
+ let s = mod(inv(k, N) * (z + r * privateKey), N);
203
+ if (s !== 0n) {
204
+ let rec = (R.y & 1n ? 1 : 0) | (R.x >= N ? 2 : 0);
205
+ if (s > N / 2n) {
206
+ s = N - s;
207
+ rec ^= 1;
208
+ }
209
+ return (0, exports.toHex)(concat(bigToBytes(r), bigToBytes(s), Uint8Array.of(27 + (rec & 1))));
210
+ }
211
+ }
212
+ }
213
+ k = mod(k + 1n, N); // practically unreachable
214
+ }
215
+ }
216
+ /* ------------------------------- addresses ------------------------------ */
217
+ function checksumAddress(addr) {
218
+ const a = addr.toLowerCase().replace(/^0x/, '');
219
+ const h = Buffer.from(keccak256(utf8(a))).toString('hex');
220
+ let out = '0x';
221
+ for (let i = 0; i < 40; i++)
222
+ out += parseInt(h[i], 16) >= 8 ? a[i].toUpperCase() : a[i];
223
+ return out;
224
+ }
225
+ /** Parses a 64-hex private key (optional 0x). Throws without echoing the value. */
226
+ function parsePrivateKey(raw) {
227
+ const t = (raw ?? '').trim();
228
+ if (!/^(0x)?[0-9a-fA-F]{64}$/.test(t)) {
229
+ throw new Error('The wallet private key is not valid (expected 64 hex characters, optional 0x prefix). The value is not shown. Nothing was signed.');
230
+ }
231
+ const d = BigInt(t.startsWith('0x') || t.startsWith('0X') ? t : '0x' + t);
232
+ if (d <= 0n || d >= N)
233
+ throw new Error('The wallet private key is out of range. The value is not shown. Nothing was signed.');
234
+ return d;
235
+ }
236
+ function addressOf(privateKey) {
237
+ const Q = mul(privateKey, G);
238
+ if (!Q)
239
+ throw new Error('Invalid private key');
240
+ const pub = concat(bigToBytes(Q.x), bigToBytes(Q.y));
241
+ return checksumAddress((0, exports.toHex)(keccak256(pub).slice(12)));
242
+ }
243
+ /* -------------------------------- EIP-712 ------------------------------- */
244
+ const DOMAIN_TYPEHASH = keccak256(utf8('EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)'));
245
+ const TWA_TYPEHASH = keccak256(utf8('TransferWithAuthorization(address from,address to,uint256 value,uint256 validAfter,uint256 validBefore,bytes32 nonce)'));
246
+ const addr32 = (a) => bigToBytes(BigInt(a));
247
+ function transferWithAuthorizationDigest(domain, a) {
248
+ const ds = keccak256(concat(DOMAIN_TYPEHASH, keccak256(utf8(domain.name)), keccak256(utf8(domain.version)), bigToBytes(BigInt(domain.chainId)), addr32(domain.verifyingContract)));
249
+ const sh = keccak256(concat(TWA_TYPEHASH, addr32(a.from), addr32(a.to), bigToBytes(BigInt(a.value)), bigToBytes(BigInt(a.validAfter)), bigToBytes(BigInt(a.validBefore)), fromHex(a.nonce)));
250
+ return keccak256(concat(Uint8Array.of(0x19, 0x01), ds, sh));
251
+ }
252
+ /* ------------------------------ x402 payment ----------------------------- */
253
+ exports.BASE_NETWORK = 'eip155:8453';
254
+ exports.BASE_CHAIN_ID = 8453;
255
+ /** Native USDC on Base. */
256
+ exports.USDC_BASE = '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913';
257
+ /** The Pocket Agentic Portal payee for the AgentSearch services. */
258
+ exports.PORTAL_PAYEE = '0xF732ea490c5766071785a2310523f7fA2CEbB829';
259
+ /** $0.005 in USDC atomic units: hard ceiling per call. */
260
+ exports.MAX_PER_CALL_ATOMIC = 5000n;
261
+ const eqAddr = (a, b) => typeof a === 'string' && a.toLowerCase() === b.toLowerCase();
262
+ function atomicToUsd(a) {
263
+ const n = BigInt(a);
264
+ return `$${n / 1000000n}.${(n % 1000000n).toString().padStart(6, '0')}`;
265
+ }
266
+ /** Picks the single option this node is willing to sign, or explains why none qualifies. */
267
+ function selectAccept(accepts, ceiling) {
268
+ const why = [];
269
+ for (const a of accepts ?? []) {
270
+ if (a.scheme !== 'exact') {
271
+ why.push(`${a.scheme} scheme`);
272
+ continue;
273
+ }
274
+ if (a.network !== exports.BASE_NETWORK) {
275
+ why.push(`network ${a.network}`);
276
+ continue;
277
+ }
278
+ if (!eqAddr(a.asset, exports.USDC_BASE)) {
279
+ why.push(`asset ${a.asset} is not USDC on Base`);
280
+ continue;
281
+ }
282
+ if (!eqAddr(a.payTo, exports.PORTAL_PAYEE)) {
283
+ why.push(`payee ${a.payTo} is not the portal's`);
284
+ continue;
285
+ }
286
+ if ((a.extra?.assetTransferMethod ?? 'eip3009') !== 'eip3009') {
287
+ why.push('not an EIP-3009 transfer');
288
+ continue;
289
+ }
290
+ if (!a.extra?.name || !a.extra?.version) {
291
+ why.push('missing EIP-712 domain name/version');
292
+ continue;
293
+ }
294
+ if (!/^\d+$/.test(String(a.amount))) {
295
+ why.push(`amount ${a.amount} is not an integer`);
296
+ continue;
297
+ }
298
+ const amt = BigInt(a.amount);
299
+ if (amt <= 0n) {
300
+ why.push(`amount ${a.amount}`);
301
+ continue;
302
+ }
303
+ if (amt > ceiling) {
304
+ why.push(`amount ${atomicToUsd(amt)} is above the ${atomicToUsd(ceiling)} limit`);
305
+ continue;
306
+ }
307
+ return a;
308
+ }
309
+ throw new Error(`Refusing to pay: no acceptable payment option (${why.join('; ') || 'none offered'}). Nothing was signed.`);
310
+ }
311
+ function decodeBase64Json(header) {
312
+ return JSON.parse(Buffer.from(header, 'base64').toString('utf8'));
313
+ }
314
+ /**
315
+ * Builds the x402 v2 PaymentPayload for one accepted requirement (same shape as
316
+ * @x402/core x402Client.createPaymentPayload with the exact EVM scheme).
317
+ * `now` and `nonce` are injectable for tests only.
318
+ */
319
+ function createPaymentPayload(required, accepted, privateKey, opts = {}) {
320
+ const from = addressOf(privateKey);
321
+ const now = opts.now ?? Math.floor(Date.now() / 1000);
322
+ const authorization = {
323
+ from,
324
+ to: checksumAddress(accepted.payTo),
325
+ value: String(accepted.amount),
326
+ validAfter: '0',
327
+ validBefore: String(now + (accepted.maxTimeoutSeconds ?? 60)),
328
+ nonce: opts.nonce ?? (0, exports.toHex)(new Uint8Array((0, crypto_1.randomBytes)(32))),
329
+ };
330
+ const digest = transferWithAuthorizationDigest({ name: String(accepted.extra?.name), version: String(accepted.extra?.version), chainId: exports.BASE_CHAIN_ID, verifyingContract: checksumAddress(accepted.asset) }, authorization);
331
+ const signature = signDigest(digest, privateKey);
332
+ const payload = {
333
+ x402Version: 2,
334
+ payload: { authorization, signature },
335
+ extensions: required.extensions,
336
+ resource: required.resource,
337
+ accepted,
338
+ };
339
+ return { payload, from };
340
+ }
341
+ const encodePaymentHeader = (payload) => Buffer.from(JSON.stringify(payload), 'utf8').toString('base64');
342
+ exports.encodePaymentHeader = encodePaymentHeader;
package/package.json CHANGED
@@ -1,21 +1,28 @@
1
1
  {
2
2
  "name": "n8n-nodes-agentsearch",
3
- "version": "0.2.3",
4
- "author": { "name": "AgentSearch", "email": "AgentSearchhq@gmail.com", "url": "https://agentsearchhq.com" },
5
- "description": "n8n community node for AgentSearch: free live web search for AI agents and workflows (no credentials)",
3
+ "version": "0.3.0",
4
+ "author": {
5
+ "name": "AgentSearch",
6
+ "email": "AgentSearchhq@gmail.com",
7
+ "url": "https://agentsearchhq.com"
8
+ },
9
+ "description": "n8n community node for AgentSearch: free live web search for AI agents (no credentials), plus page Extract and JavaScript Render at $0.005 per call (USDC on Base via x402)",
6
10
  "keywords": [
7
11
  "n8n-community-node-package",
8
12
  "n8n",
9
13
  "agentsearch",
10
14
  "web-search",
11
15
  "search",
12
- "ai-agent"
16
+ "ai-agent",
17
+ "extract",
18
+ "web-scraping",
19
+ "x402"
13
20
  ],
14
21
  "license": "MIT",
15
22
  "homepage": "https://agentsearchhq.com/?utm_source=n8n-nodes-agentsearch&utm_medium=package",
16
23
  "main": "index.js",
17
24
  "scripts": {
18
- "build": "tsc && cp nodes/AgentSearch/*.svg dist/nodes/AgentSearch/",
25
+ "build": "tsc && cp nodes/AgentSearch/*.svg dist/nodes/AgentSearch/ && cp credentials/*.svg dist/credentials/",
19
26
  "prepublishOnly": "npm run build",
20
27
  "test": "npm run build && node --test test/*.test.mjs"
21
28
  },
@@ -27,7 +34,9 @@
27
34
  ],
28
35
  "n8n": {
29
36
  "n8nNodesApiVersion": 1,
30
- "credentials": [],
37
+ "credentials": [
38
+ "dist/credentials/AgentSearchWalletApi.credentials.js"
39
+ ],
31
40
  "nodes": [
32
41
  "dist/nodes/AgentSearch/AgentSearch.node.js"
33
42
  ]
@@ -1,16 +1,144 @@
1
1
  {
2
- "name": "AgentSearch free web search (HTTP Request)",
2
+ "name": "Give an AI agent free live web search with cited sources (no API key)",
3
3
  "nodes": [
4
- { "parameters": {}, "id": "a1b2c3d4-0000-4000-8000-000000000001", "name": "When clicking 'Test workflow'", "type": "n8n-nodes-base.manualTrigger", "typeVersion": 1, "position": [0, 0] },
5
- { "parameters": { "assignments": { "assignments": [ { "id": "q1", "name": "query", "value": "latest n8n release", "type": "string" } ] }, "options": {} }, "id": "a1b2c3d4-0000-4000-8000-000000000002", "name": "Set Query", "type": "n8n-nodes-base.set", "typeVersion": 3.4, "position": [220, 0] },
6
- { "parameters": { "method": "POST", "url": "https://relay.agentsearchhq.com/v1/search", "sendBody": true, "specifyBody": "json", "jsonBody": "={{ JSON.stringify({ query: $json.query, max_results: 5 }) }}", "options": {} }, "id": "a1b2c3d4-0000-4000-8000-000000000003", "name": "AgentSearch (free)", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [440, 0], "notes": "Free: 25 searches/day per user, up to 5 results, no key. HTTP 429 = daily limit reached. Docs: https://agentsearchhq.com/agents.md?utm_source=n8n-nodes-agentsearch&utm_medium=package" },
7
- { "parameters": { "fieldToSplitOut": "results", "options": {} }, "id": "a1b2c3d4-0000-4000-8000-000000000004", "name": "One Item per Result", "type": "n8n-nodes-base.splitOut", "typeVersion": 1, "position": [660, 0] }
4
+ {
5
+ "parameters": {},
6
+ "id": "a1b2c3d4-0000-4000-8000-000000000001",
7
+ "name": "When clicking 'Test workflow'",
8
+ "type": "n8n-nodes-base.manualTrigger",
9
+ "typeVersion": 1,
10
+ "position": [
11
+ 0,
12
+ 0
13
+ ]
14
+ },
15
+ {
16
+ "parameters": {
17
+ "assignments": {
18
+ "assignments": [
19
+ {
20
+ "id": "q1",
21
+ "name": "query",
22
+ "value": "latest n8n release",
23
+ "type": "string"
24
+ }
25
+ ]
26
+ },
27
+ "options": {}
28
+ },
29
+ "id": "a1b2c3d4-0000-4000-8000-000000000002",
30
+ "name": "Set Query",
31
+ "type": "n8n-nodes-base.set",
32
+ "typeVersion": 3.4,
33
+ "position": [
34
+ 220,
35
+ 0
36
+ ]
37
+ },
38
+ {
39
+ "parameters": {
40
+ "method": "POST",
41
+ "url": "https://relay.agentsearchhq.com/v1/search",
42
+ "sendBody": true,
43
+ "specifyBody": "json",
44
+ "jsonBody": "={{ JSON.stringify({ query: $json.query, max_results: 5 }) }}",
45
+ "options": {}
46
+ },
47
+ "id": "a1b2c3d4-0000-4000-8000-000000000003",
48
+ "name": "AgentSearch (free)",
49
+ "type": "n8n-nodes-base.httpRequest",
50
+ "typeVersion": 4.2,
51
+ "position": [
52
+ 440,
53
+ 0
54
+ ],
55
+ "notes": "Free: 25 searches/day per user, up to 5 results, no key. HTTP 429 = daily limit reached. Docs: https://agentsearchhq.com/agents.md?utm_source=n8n-nodes-agentsearch&utm_medium=package",
56
+ "onError": "continueRegularOutput"
57
+ },
58
+ {
59
+ "parameters": {
60
+ "fieldToSplitOut": "results",
61
+ "options": {}
62
+ },
63
+ "id": "a1b2c3d4-0000-4000-8000-000000000004",
64
+ "name": "One Item per Result",
65
+ "type": "n8n-nodes-base.splitOut",
66
+ "typeVersion": 1,
67
+ "position": [
68
+ 660,
69
+ 0
70
+ ]
71
+ },
72
+ {
73
+ "parameters": {
74
+ "content": "## Free web search (no API key)\nSearches the web with AgentSearch and returns up to 5 cited results (title, URL, snippet). 25 free searches/day per user.\n\n### How it works\n1. **Manual Trigger** starts the run (swap for Chat, Schedule or Webhook).\n2. **Set Query** holds the question.\n3. **AgentSearch (free)** calls the free search endpoint, no credentials.\n4. **One Item per Result** splits results into items.\n\n### Setup\nEdit the query in **Set Query**, then run.\n\n### Customize\nConnect results to an AI Agent or LLM node to answer with citations. Self-hosted: install the community node `n8n-nodes-agentsearch`.",
75
+ "height": 560,
76
+ "width": 380,
77
+ "color": 4
78
+ },
79
+ "id": "a1b2c3d4-0000-4000-8000-000000000010",
80
+ "name": "Sticky Note",
81
+ "type": "n8n-nodes-base.stickyNote",
82
+ "typeVersion": 1,
83
+ "position": [
84
+ -420,
85
+ -320
86
+ ]
87
+ },
88
+ {
89
+ "parameters": {
90
+ "content": "### Daily limit\nHit the free daily limit? This node returns **429**. *Continue On Fail* is enabled so the workflow keeps running; connect a fallback if needed.",
91
+ "height": 200,
92
+ "width": 260,
93
+ "color": 3
94
+ },
95
+ "id": "a1b2c3d4-0000-4000-8000-000000000011",
96
+ "name": "Sticky Note 1",
97
+ "type": "n8n-nodes-base.stickyNote",
98
+ "typeVersion": 1,
99
+ "position": [
100
+ 380,
101
+ -220
102
+ ]
103
+ }
8
104
  ],
9
105
  "connections": {
10
- "When clicking 'Test workflow'": { "main": [[{ "node": "Set Query", "type": "main", "index": 0 }]] },
11
- "Set Query": { "main": [[{ "node": "AgentSearch (free)", "type": "main", "index": 0 }]] },
12
- "AgentSearch (free)": { "main": [[{ "node": "One Item per Result", "type": "main", "index": 0 }]] }
106
+ "When clicking 'Test workflow'": {
107
+ "main": [
108
+ [
109
+ {
110
+ "node": "Set Query",
111
+ "type": "main",
112
+ "index": 0
113
+ }
114
+ ]
115
+ ]
116
+ },
117
+ "Set Query": {
118
+ "main": [
119
+ [
120
+ {
121
+ "node": "AgentSearch (free)",
122
+ "type": "main",
123
+ "index": 0
124
+ }
125
+ ]
126
+ ]
127
+ },
128
+ "AgentSearch (free)": {
129
+ "main": [
130
+ [
131
+ {
132
+ "node": "One Item per Result",
133
+ "type": "main",
134
+ "index": 0
135
+ }
136
+ ]
137
+ ]
138
+ }
139
+ },
140
+ "settings": {
141
+ "executionOrder": "v1"
13
142
  },
14
- "settings": { "executionOrder": "v1" },
15
143
  "pinData": {}
16
- }
144
+ }
@@ -1,8 +0,0 @@
1
- import type { IExecuteFunctions, INodeExecutionData, INodeType, INodeTypeDescription } from 'n8n-workflow';
2
- export declare const FREE_RELAY_URL = "https://relay.agentsearchhq.com/v1/search";
3
- export declare const CLIENT_TAG = "n8n-nodes-agentsearch/0.2.3";
4
- export declare const 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.005 per call via the Pocket Agentic Portal, x402 USDC on Base). Docs: https://agentsearchhq.com/?utm_source=n8n-nodes-agentsearch&utm_medium=package";
5
- export declare class AgentSearch implements INodeType {
6
- description: INodeTypeDescription;
7
- execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]>;
8
- }