n8n-nodes-agentsearch 0.6.1 → 0.7.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
|
@@ -3,7 +3,7 @@
|
|
|
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.
|
|
6
|
+
- **Extract Page** (new in 0.3.0): read a page as clean markdown or text. $0.004 per call (x402, USDC on Base).
|
|
7
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.
|
|
@@ -30,21 +30,29 @@ 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.004 / $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 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.
|
|
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.004, 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 = about 100-
|
|
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-250 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 direct call is hard-capped at $0.020 (Pocket route $0.005).
|
|
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 in USDC on Base to AgentSearch's payee `0xC49B157887e51c21CB655f39CF65D6a4c2a4C337`, at most $0.
|
|
45
|
+
The node only signs a payment in USDC on Base to AgentSearch's payee `0xC49B157887e51c21CB655f39CF65D6a4c2a4C337`, at most $0.020 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.
|
|
47
|
+
**New in 0.7.0: News Search and Screenshot, plus search filters.**
|
|
48
|
+
|
|
49
|
+
- **News Search** ($0.008 per call, not charged when there are no results): recent news articles with headline, URL, snippet, source and publish date, 1-10 per call.
|
|
50
|
+
- **Screenshot** ($0.010 per call, failed captures not charged): capture a page in a real headless browser as PNG or JPEG. The image is written to a binary property (default `data`) so you can pass it to an AI vision node, Slack, email or storage; the JSON keeps the metadata (final URL, title, size) without the base64.
|
|
51
|
+
- **Filters** on News Search and Search and Read: Freshness (past day/week/month/year) or a Date From/To range, Country, Language, and Include/Exclude Domains (comma-separated, up to 5).
|
|
52
|
+
|
|
53
|
+
All three are direct x402 only (AgentSearch's own API on Base; not on Pocket, not on the free relay). Prices are unchanged elsewhere: Extract $0.004, Render $0.010, Search and Read $0.009.
|
|
54
|
+
|
|
55
|
+
**New in 0.6.0: Search and Read** — one paid operation that searches the live web and returns the top pages' text for **$0.009** (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.004 extracts ($0.020), 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
56
|
|
|
49
57
|
**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).
|
|
50
58
|
|
|
@@ -2,7 +2,7 @@
|
|
|
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 ($0.
|
|
5
|
+
* Wallet used to pay per call for Extract ($0.004) and Render ($0.010) in USDC on Base over x402,
|
|
6
6
|
* by default to AgentSearch's own x402 API (Pocket portal route optional). Free Search never uses it.
|
|
7
7
|
*/
|
|
8
8
|
class AgentSearchWalletApi {
|
|
@@ -19,14 +19,14 @@ 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 = about 100-
|
|
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-250 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: 'AgentSearch Direct x402 (Extract $0.
|
|
29
|
+
{ name: 'AgentSearch Direct x402 (Extract $0.004, Render $0.010)', value: 'direct', description: "Pay AgentSearch's own x402 API on Base (api.agentsearchhq.com) (default)" },
|
|
30
30
|
{ name: 'Pocket Portal ($0.005 per Call)', value: 'pocket', description: 'Pay through the Pocket Network Agentic Portal instead' },
|
|
31
31
|
],
|
|
32
32
|
default: 'direct',
|
|
@@ -1,28 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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;
|
|
3
|
+
exports.DIRECT_OPS = exports.AgentSearch = exports.WALLET_SETUP = exports.PORTAL_SERVICES = exports.QUERY_TOO_SHORT_MESSAGE = exports.MIN_QUERY_CHARS = exports.LIMIT_MESSAGE = exports.CLIENT_TAG = exports.PORTAL_URL = exports.RELAY_BASE_URL = exports.FREE_RELAY_URL = void 0;
|
|
4
4
|
exports.paidOnlyMessage = paidOnlyMessage;
|
|
5
5
|
exports.trialLimitMessage = trialLimitMessage;
|
|
6
|
+
exports.filtersBody = filtersBody;
|
|
6
7
|
const n8n_workflow_1 = require("n8n-workflow");
|
|
7
8
|
const x402_1 = require("./x402");
|
|
8
9
|
exports.FREE_RELAY_URL = 'https://relay.agentsearchhq.com/v1/search';
|
|
9
10
|
exports.RELAY_BASE_URL = 'https://relay.agentsearchhq.com';
|
|
10
11
|
exports.PORTAL_URL = 'https://agent.pocket.network';
|
|
11
|
-
exports.CLIENT_TAG = 'n8n-nodes-agentsearch/0.
|
|
12
|
+
exports.CLIENT_TAG = 'n8n-nodes-agentsearch/0.7.0';
|
|
12
13
|
const DOCS = 'https://agentsearchhq.com/?utm_source=n8n-nodes-agentsearch&utm_medium=package';
|
|
13
14
|
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 (AgentSearch's own x402 API on Base: Extract $0.
|
|
15
|
+
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.004, Render $0.010 per call in USDC; Pocket route $0.005 optional). Docs: ${DOCS}`;
|
|
16
|
+
exports.MIN_QUERY_CHARS = 2;
|
|
17
|
+
exports.QUERY_TOO_SHORT_MESSAGE = 'Query must be at least 2 characters. Nothing was sent or charged.';
|
|
15
18
|
exports.PORTAL_SERVICES = {
|
|
16
19
|
extract: { serviceId: 'agentsearch-web-extract-v1', path: '/v1/extract' },
|
|
17
20
|
render: { serviceId: 'agentsearch-web-render-v1', path: '/v1/render' },
|
|
18
21
|
};
|
|
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-
|
|
22
|
+
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-250 calls; no ETH needed). Each call is paid over x402 to AgentSearch\'s own API on Base (Extract $0.004, 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
23
|
GUIDE;
|
|
21
24
|
function paidOnlyMessage(op) {
|
|
22
|
-
return `${op === 'extract' ? 'Extract' : 'Render'} is a paid operation (${op === 'extract' ? '$0.
|
|
25
|
+
return `${op === 'extract' ? 'Extract' : 'Render'} is a paid operation (${op === 'extract' ? '$0.004' : '$0.010'} per call in USDC on Base via x402) and no wallet credential is set, so nothing was paid. ${exports.WALLET_SETUP}`;
|
|
23
26
|
}
|
|
24
27
|
function trialLimitMessage(op) {
|
|
25
|
-
return `Free ${op} allowance for today is used up. Continue at ${op === 'extract' ? '$0.
|
|
28
|
+
return `Free ${op} allowance for today is used up. Continue at ${op === 'extract' ? '$0.004' : '$0.010'} per call (x402, USDC on Base): ${exports.WALLET_SETUP}`;
|
|
26
29
|
}
|
|
27
30
|
const headerOf = (headers, name) => {
|
|
28
31
|
const h = (headers ?? {});
|
|
@@ -52,7 +55,7 @@ class AgentSearch {
|
|
|
52
55
|
group: ['transform'],
|
|
53
56
|
version: 1,
|
|
54
57
|
subtitle: '={{$parameter["operation"]}}',
|
|
55
|
-
description: 'Free live web search for AI agents, plus page Extract ($0.
|
|
58
|
+
description: 'Free live web search for AI agents, plus News Search ($0.008), page Extract ($0.004), JavaScript Render ($0.010), Screenshot ($0.010), and Search + Read ($0.009) per call via x402',
|
|
56
59
|
defaults: { name: 'AgentSearch' },
|
|
57
60
|
inputs: [n8n_workflow_1.NodeConnectionTypes.Main],
|
|
58
61
|
outputs: [n8n_workflow_1.NodeConnectionTypes.Main],
|
|
@@ -62,7 +65,7 @@ class AgentSearch {
|
|
|
62
65
|
name: 'agentSearchWalletApi',
|
|
63
66
|
required: false,
|
|
64
67
|
testedBy: 'agentSearchWalletTest',
|
|
65
|
-
displayOptions: { show: { operation: ['extract', 'render', 'searchAndRead'] } },
|
|
68
|
+
displayOptions: { show: { operation: ['extract', 'render', 'searchAndRead', 'news', 'screenshot'] } },
|
|
66
69
|
},
|
|
67
70
|
],
|
|
68
71
|
properties: [
|
|
@@ -77,7 +80,7 @@ class AgentSearch {
|
|
|
77
80
|
name: 'Extract Page',
|
|
78
81
|
value: 'extract',
|
|
79
82
|
action: 'Extract a page as markdown',
|
|
80
|
-
description: 'Read a page as clean markdown or text ($0.
|
|
83
|
+
description: 'Read a page as clean markdown or text ($0.004 per call, wallet credential)',
|
|
81
84
|
},
|
|
82
85
|
{
|
|
83
86
|
name: 'Render Page',
|
|
@@ -85,11 +88,23 @@ class AgentSearch {
|
|
|
85
88
|
action: 'Render a dynamic page',
|
|
86
89
|
description: 'Load a JavaScript-heavy page in a headless browser and read it ($0.010 per call, wallet credential)',
|
|
87
90
|
},
|
|
91
|
+
{
|
|
92
|
+
name: 'News Search',
|
|
93
|
+
value: 'news',
|
|
94
|
+
action: 'Search recent news',
|
|
95
|
+
description: 'Recent news articles with date, source and snippet ($0.008 per call, not charged when no results; wallet credential; direct x402 only)',
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
name: 'Screenshot',
|
|
99
|
+
value: 'screenshot',
|
|
100
|
+
action: 'Take a screenshot of a page',
|
|
101
|
+
description: 'Capture a page in a real headless browser as a PNG or JPEG binary ($0.010 per call, failed captures not charged; wallet credential; direct x402 only)',
|
|
102
|
+
},
|
|
88
103
|
{
|
|
89
104
|
name: 'Search and Read',
|
|
90
105
|
value: 'searchAndRead',
|
|
91
106
|
action: 'Search and read top pages',
|
|
92
|
-
description: 'Search the live web and return the top pages\' text in one paid call ($0.
|
|
107
|
+
description: 'Search the live web and return the top pages\' text in one paid call ($0.009, charged only when at least one page returns text; wallet credential; direct x402 only)',
|
|
93
108
|
},
|
|
94
109
|
],
|
|
95
110
|
default: 'freeSearch',
|
|
@@ -101,7 +116,7 @@ class AgentSearch {
|
|
|
101
116
|
default: '',
|
|
102
117
|
required: true,
|
|
103
118
|
placeholder: 'latest n8n release',
|
|
104
|
-
displayOptions: { show: { operation: ['freeSearch', 'searchAndRead'] } },
|
|
119
|
+
displayOptions: { show: { operation: ['freeSearch', 'searchAndRead', 'news'] } },
|
|
105
120
|
},
|
|
106
121
|
{
|
|
107
122
|
displayName: 'Max Results',
|
|
@@ -111,6 +126,15 @@ class AgentSearch {
|
|
|
111
126
|
default: 5,
|
|
112
127
|
displayOptions: { show: { operation: ['freeSearch'] } },
|
|
113
128
|
},
|
|
129
|
+
{
|
|
130
|
+
displayName: 'Max Results',
|
|
131
|
+
name: 'newsMaxResults',
|
|
132
|
+
type: 'number',
|
|
133
|
+
typeOptions: { minValue: 1, maxValue: 10 },
|
|
134
|
+
default: 5,
|
|
135
|
+
description: 'How many news articles to return (default 5, max 10)',
|
|
136
|
+
displayOptions: { show: { operation: ['news'] } },
|
|
137
|
+
},
|
|
114
138
|
{
|
|
115
139
|
displayName: 'Number of Results to Read',
|
|
116
140
|
name: 'numResults',
|
|
@@ -136,7 +160,7 @@ class AgentSearch {
|
|
|
136
160
|
required: true,
|
|
137
161
|
placeholder: 'https://example.com/article',
|
|
138
162
|
description: 'Absolute public http(s) URL of the page to read',
|
|
139
|
-
displayOptions: { show: { operation: ['extract', 'render'] } },
|
|
163
|
+
displayOptions: { show: { operation: ['extract', 'render', 'screenshot'] } },
|
|
140
164
|
},
|
|
141
165
|
{
|
|
142
166
|
displayName: 'Formats',
|
|
@@ -187,9 +211,64 @@ class AgentSearch {
|
|
|
187
211
|
name: 'renderFallback',
|
|
188
212
|
type: 'boolean',
|
|
189
213
|
default: false,
|
|
190
|
-
description: 'Whether to render at most one thin page in the same $0.
|
|
214
|
+
description: 'Whether to render at most one thin page in the same $0.009 call if extract returns little text',
|
|
191
215
|
displayOptions: { show: { operation: ['searchAndRead'] } },
|
|
192
216
|
},
|
|
217
|
+
{
|
|
218
|
+
displayName: 'Filters',
|
|
219
|
+
name: 'filters',
|
|
220
|
+
type: 'collection',
|
|
221
|
+
placeholder: 'Add Filter',
|
|
222
|
+
default: {},
|
|
223
|
+
description: 'Optional search filters (direct x402 API)',
|
|
224
|
+
displayOptions: { show: { operation: ['news', 'searchAndRead'] } },
|
|
225
|
+
options: [
|
|
226
|
+
{ displayName: 'Country', name: 'country', type: 'string', default: '', placeholder: 'us', description: '2-letter ISO 3166-1 country code, e.g. us, gb, de' },
|
|
227
|
+
{ displayName: 'Date From', name: 'date_from', type: 'string', default: '', placeholder: '2026-11-01', description: 'Only results on or after this date (YYYY-MM-DD). Do not combine with Freshness.' },
|
|
228
|
+
{ displayName: 'Date To', name: 'date_to', type: 'string', default: '', placeholder: '2026-11-12', description: 'Only results on or before this date (YYYY-MM-DD)' },
|
|
229
|
+
{ displayName: 'Exclude Domains', name: 'exclude_domains', type: 'string', default: '', placeholder: 'pinterest.com, quora.com', description: 'Comma-separated domains to never return (up to 5)' },
|
|
230
|
+
{
|
|
231
|
+
displayName: 'Freshness',
|
|
232
|
+
name: 'freshness',
|
|
233
|
+
type: 'options',
|
|
234
|
+
options: [
|
|
235
|
+
{ name: 'Past Day', value: 'day' },
|
|
236
|
+
{ name: 'Past Week', value: 'week' },
|
|
237
|
+
{ name: 'Past Month', value: 'month' },
|
|
238
|
+
{ name: 'Past Year', value: 'year' },
|
|
239
|
+
],
|
|
240
|
+
default: 'week',
|
|
241
|
+
description: 'Only results from this recent period',
|
|
242
|
+
},
|
|
243
|
+
{ displayName: 'Include Domains', name: 'include_domains', type: 'string', default: '', placeholder: 'reuters.com, apnews.com', description: 'Comma-separated domains to search only (up to 5, subdomains included)' },
|
|
244
|
+
{ displayName: 'Language', name: 'language', type: 'string', default: '', placeholder: 'en', description: 'ISO 639-1 language, e.g. en, es or pt-BR' },
|
|
245
|
+
],
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
displayName: 'Image Format',
|
|
249
|
+
name: 'screenshotFormat',
|
|
250
|
+
type: 'options',
|
|
251
|
+
options: [
|
|
252
|
+
{ name: 'PNG', value: 'png' },
|
|
253
|
+
{ name: 'JPEG', value: 'jpeg' },
|
|
254
|
+
],
|
|
255
|
+
default: 'png',
|
|
256
|
+
displayOptions: { show: { operation: ['screenshot'] } },
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
displayName: 'Options',
|
|
260
|
+
name: 'screenshotOptions',
|
|
261
|
+
type: 'collection',
|
|
262
|
+
placeholder: 'Add Option',
|
|
263
|
+
default: {},
|
|
264
|
+
displayOptions: { show: { operation: ['screenshot'] } },
|
|
265
|
+
options: [
|
|
266
|
+
{ displayName: 'Binary Property', name: 'binaryProperty', type: 'string', default: 'data', description: 'Name of the binary property to write the image to' },
|
|
267
|
+
{ displayName: 'Full Page', name: 'fullPage', type: 'boolean', default: false, description: 'Whether to capture the whole page (clipped at 4000 px tall) instead of the viewport' },
|
|
268
|
+
{ displayName: 'Viewport Height', name: 'height', type: 'number', typeOptions: { minValue: 240, maxValue: 1600 }, default: 800, description: 'Viewport height in CSS pixels (240-1600)' },
|
|
269
|
+
{ displayName: 'Viewport Width', name: 'width', type: 'number', typeOptions: { minValue: 320, maxValue: 1920 }, default: 1280, description: 'Viewport width in CSS pixels (320-1920; e.g. 390 for mobile)' },
|
|
270
|
+
],
|
|
271
|
+
},
|
|
193
272
|
{
|
|
194
273
|
displayName: 'Options',
|
|
195
274
|
name: 'renderOptions',
|
|
@@ -272,7 +351,7 @@ class AgentSearch {
|
|
|
272
351
|
return { status: 'Error', message: 'Max Spend per Run must be a positive number of USD.' };
|
|
273
352
|
return {
|
|
274
353
|
status: 'OK',
|
|
275
|
-
message: `Valid key for wallet ${address}. Fund it with USDC on Base (no ETH needed); each Extract ($0.
|
|
354
|
+
message: `Valid key for wallet ${address}. Fund it with USDC on Base (no ETH needed); each Extract ($0.004) or Render ($0.010) call pays AgentSearch's x402 API ($0.005 on the Pocket route).`,
|
|
276
355
|
};
|
|
277
356
|
},
|
|
278
357
|
},
|
|
@@ -291,15 +370,17 @@ class AgentSearch {
|
|
|
291
370
|
out.push({ json: r.json, pairedItem: { item: i } });
|
|
292
371
|
continue;
|
|
293
372
|
}
|
|
294
|
-
if (operation === 'searchAndRead') {
|
|
295
|
-
const r = await
|
|
373
|
+
if (operation === 'searchAndRead' || operation === 'news' || operation === 'screenshot') {
|
|
374
|
+
const r = await directPaid.call(this, operation, i, signedAtomic);
|
|
296
375
|
signedAtomic = r.signedAtomic;
|
|
297
|
-
out.push({ json: r.json, pairedItem: { item: i } });
|
|
376
|
+
out.push({ json: r.json, ...(r.binary ? { binary: r.binary } : {}), pairedItem: { item: i } });
|
|
298
377
|
continue;
|
|
299
378
|
}
|
|
300
379
|
const query = this.getNodeParameter('query', i).trim();
|
|
301
380
|
if (!query)
|
|
302
381
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Query is empty', { itemIndex: i });
|
|
382
|
+
if (query.length < exports.MIN_QUERY_CHARS)
|
|
383
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), exports.QUERY_TOO_SHORT_MESSAGE, { itemIndex: i });
|
|
303
384
|
const maxResults = this.getNodeParameter('maxResults', i, 5);
|
|
304
385
|
const split = this.getNodeParameter('split', i, false);
|
|
305
386
|
let res;
|
|
@@ -318,6 +399,10 @@ class AgentSearch {
|
|
|
318
399
|
const status = err?.httpCode ?? err?.response?.status ?? err?.statusCode;
|
|
319
400
|
if (String(status) === '429')
|
|
320
401
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), exports.LIMIT_MESSAGE, { itemIndex: i });
|
|
402
|
+
const code = Number(status);
|
|
403
|
+
if (code >= 400 && code < 500 && code !== 408) {
|
|
404
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `AgentSearch rejected the request (HTTP ${code}). Fix the input before retrying; retrying the same request will fail again.`, { itemIndex: i });
|
|
405
|
+
}
|
|
321
406
|
throw new n8n_workflow_1.NodeApiError(this.getNode(), e, { itemIndex: i });
|
|
322
407
|
}
|
|
323
408
|
if (res && typeof res === 'object')
|
|
@@ -501,20 +586,71 @@ async function readPage(op, i, signedBefore) {
|
|
|
501
586
|
};
|
|
502
587
|
return { json: { ...data, payment, portal: direct ? null : envelope.portal ?? null }, signedAtomic };
|
|
503
588
|
}
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
589
|
+
exports.DIRECT_OPS = {
|
|
590
|
+
searchAndRead: { path: 'search_and_read', label: 'Search and Read', price: '$0.009', when: 'charged only when at least one page returns text' },
|
|
591
|
+
news: { path: 'news', label: 'News Search', price: '$0.008', when: 'not charged when there are no results' },
|
|
592
|
+
screenshot: { path: 'screenshot', label: 'Screenshot', price: '$0.010', when: 'failed captures are not charged' },
|
|
593
|
+
};
|
|
594
|
+
const domainList = (v) => String(v ?? '')
|
|
595
|
+
.split(',')
|
|
596
|
+
.map((d) => d.trim())
|
|
597
|
+
.filter(Boolean)
|
|
598
|
+
.slice(0, 5);
|
|
599
|
+
function filtersBody(raw) {
|
|
600
|
+
const f = raw ?? {};
|
|
601
|
+
const out = {};
|
|
602
|
+
for (const k of ['freshness', 'date_from', 'date_to', 'country', 'language']) {
|
|
603
|
+
const v = String(f[k] ?? '').trim();
|
|
604
|
+
if (v)
|
|
605
|
+
out[k] = k === 'country' ? v.toLowerCase() : v;
|
|
606
|
+
}
|
|
607
|
+
for (const k of ['include_domains', 'exclude_domains']) {
|
|
608
|
+
const v = domainList(f[k]);
|
|
609
|
+
if (v.length)
|
|
610
|
+
out[k] = v;
|
|
611
|
+
}
|
|
612
|
+
return out;
|
|
613
|
+
}
|
|
614
|
+
async function directPaid(op, i, signedBefore) {
|
|
615
|
+
const meta = exports.DIRECT_OPS[op];
|
|
616
|
+
let body;
|
|
617
|
+
if (op === 'screenshot') {
|
|
618
|
+
const url = String(this.getNodeParameter('url', i) ?? '').trim();
|
|
619
|
+
if (!/^https?:\/\//i.test(url))
|
|
620
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'URL must be an absolute http(s) URL', { itemIndex: i });
|
|
621
|
+
const format = this.getNodeParameter('screenshotFormat', i, 'png');
|
|
622
|
+
const o = (this.getNodeParameter('screenshotOptions', i, {}) ?? {});
|
|
623
|
+
body = { url, format };
|
|
624
|
+
if (o.fullPage === true)
|
|
625
|
+
body.full_page = true;
|
|
626
|
+
if (o.width || o.height)
|
|
627
|
+
body.viewport = { ...(o.width ? { width: Number(o.width) } : {}), ...(o.height ? { height: Number(o.height) } : {}) };
|
|
628
|
+
}
|
|
629
|
+
else {
|
|
630
|
+
const query = String(this.getNodeParameter('query', i) ?? '').trim();
|
|
631
|
+
if (!query)
|
|
632
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Query is empty', { itemIndex: i });
|
|
633
|
+
if (query.length < exports.MIN_QUERY_CHARS)
|
|
634
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), exports.QUERY_TOO_SHORT_MESSAGE, { itemIndex: i });
|
|
635
|
+
body = { query };
|
|
636
|
+
if (op === 'news') {
|
|
637
|
+
const n = this.getNodeParameter('newsMaxResults', i, 5);
|
|
638
|
+
if (n)
|
|
639
|
+
body.max_results = n;
|
|
640
|
+
}
|
|
641
|
+
else {
|
|
642
|
+
const numResults = this.getNodeParameter('numResults', i, 3);
|
|
643
|
+
const maxChars = this.getNodeParameter('searchAndReadMaxChars', i, 8000);
|
|
644
|
+
const renderFallback = this.getNodeParameter('renderFallback', i, false);
|
|
645
|
+
if (numResults)
|
|
646
|
+
body.num_results = numResults;
|
|
647
|
+
if (maxChars)
|
|
648
|
+
body.max_chars = maxChars;
|
|
649
|
+
if (renderFallback)
|
|
650
|
+
body.render_fallback = true;
|
|
651
|
+
}
|
|
652
|
+
Object.assign(body, filtersBody(this.getNodeParameter('filters', i, {})));
|
|
653
|
+
}
|
|
518
654
|
let creds;
|
|
519
655
|
try {
|
|
520
656
|
creds = await this.getCredentials('agentSearchWalletApi', i);
|
|
@@ -523,10 +659,10 @@ async function searchAndRead(i, signedBefore) {
|
|
|
523
659
|
creds = undefined;
|
|
524
660
|
}
|
|
525
661
|
if (!creds?.privateKey) {
|
|
526
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(),
|
|
662
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `${meta.label} is a paid operation (${meta.price} per call in USDC on Base via x402, ${meta.when}) and no wallet credential is set, so nothing was paid. It is not on the free relay. ` + exports.WALLET_SETUP, { itemIndex: i });
|
|
527
663
|
}
|
|
528
664
|
if (creds.paymentRoute === 'pocket') {
|
|
529
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(),
|
|
665
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `${meta.label} is available only on AgentSearch's own x402 API (${meta.price} per call, ${meta.when}). 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
666
|
}
|
|
531
667
|
let key;
|
|
532
668
|
try {
|
|
@@ -544,8 +680,8 @@ async function searchAndRead(i, signedBefore) {
|
|
|
544
680
|
if (ceiling <= 0n) {
|
|
545
681
|
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
682
|
}
|
|
547
|
-
const url = `${x402_1.DIRECT_URL}/x402/v1
|
|
548
|
-
const expectRes =
|
|
683
|
+
const url = `${x402_1.DIRECT_URL}/x402/v1/${meta.path}`;
|
|
684
|
+
const expectRes = `/x402/v1/${meta.path}`;
|
|
549
685
|
const unpaid = await post.call(this, url, body);
|
|
550
686
|
if (unpaid.statusCode !== 402) {
|
|
551
687
|
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 });
|
|
@@ -573,7 +709,7 @@ async function searchAndRead(i, signedBefore) {
|
|
|
573
709
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), msg, { itemIndex: i });
|
|
574
710
|
}
|
|
575
711
|
if (ceiling < 15000n) {
|
|
576
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `${msg}
|
|
712
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `${msg} ${meta.label} costs ${meta.price}; raise "Max Spend per Run" or the per-call ceiling to at least 20000 atomic units ($0.020). Nothing was signed.`, { itemIndex: i });
|
|
577
713
|
}
|
|
578
714
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), msg, { itemIndex: i });
|
|
579
715
|
}
|
|
@@ -610,12 +746,33 @@ async function searchAndRead(i, signedBefore) {
|
|
|
610
746
|
network: x402_1.BASE_NETWORK,
|
|
611
747
|
pay_to: payee,
|
|
612
748
|
payer: from,
|
|
613
|
-
service_id:
|
|
749
|
+
service_id: meta.path,
|
|
614
750
|
route: 'agentsearch-x402-direct',
|
|
615
751
|
settled: receipt?.success ?? false,
|
|
616
752
|
transaction: tx,
|
|
617
753
|
...(tx ? { explorer: `https://basescan.org/tx/${tx}` } : {}),
|
|
618
754
|
run_spent_usd: (0, x402_1.atomicToUsd)(signedAtomic),
|
|
619
755
|
};
|
|
756
|
+
if (op === 'screenshot') {
|
|
757
|
+
const shot = (data.screenshot && typeof data.screenshot === 'object' ? data.screenshot : data);
|
|
758
|
+
const b64 = typeof shot.base64 === 'string' ? shot.base64 : '';
|
|
759
|
+
const { base64: _omit, ...shotMeta } = shot;
|
|
760
|
+
const json = { ...data, ...(data.screenshot ? { screenshot: shotMeta } : shotMeta), payment, portal: null };
|
|
761
|
+
if (!data.screenshot)
|
|
762
|
+
delete json.base64;
|
|
763
|
+
if (!b64)
|
|
764
|
+
return { json, signedAtomic };
|
|
765
|
+
const o = (this.getNodeParameter('screenshotOptions', i, {}) ?? {});
|
|
766
|
+
const prop = String(o.binaryProperty || 'data');
|
|
767
|
+
const rawFormat = String(shot.format || body.format || 'png').toLowerCase();
|
|
768
|
+
const format = rawFormat === 'jpg' || rawFormat === 'jpeg' ? 'jpeg' : 'png';
|
|
769
|
+
const mimeType = `image/${format}`;
|
|
770
|
+
const fileName = `screenshot.${format === 'jpeg' ? 'jpg' : format}`;
|
|
771
|
+
const buf = Buffer.from(b64, 'base64');
|
|
772
|
+
const bin = this.helpers.prepareBinaryData
|
|
773
|
+
? await this.helpers.prepareBinaryData(buf, fileName, mimeType)
|
|
774
|
+
: { data: b64, mimeType, fileName, fileExtension: format === 'jpeg' ? 'jpg' : format };
|
|
775
|
+
return { json, binary: { [prop]: bin }, signedAtomic };
|
|
776
|
+
}
|
|
620
777
|
return { json: { ...data, payment, portal: null }, signedAtomic };
|
|
621
778
|
}
|
|
@@ -261,7 +261,7 @@ 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.020 hard ceiling per direct call (extract $0.
|
|
264
|
+
/** $0.020 hard ceiling per direct call (extract $0.004, render $0.010, search_and_read $0.009). */
|
|
265
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) {
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "n8n-nodes-agentsearch",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
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 ($0.
|
|
9
|
+
"description": "n8n community node for AgentSearch: free live web search for AI agents (no credentials), plus News Search ($0.008), page Extract ($0.004), JavaScript Render ($0.010), Screenshot ($0.010) and Search and Read ($0.009) 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",
|
|
@@ -16,7 +16,11 @@
|
|
|
16
16
|
"ai-agent",
|
|
17
17
|
"extract",
|
|
18
18
|
"web-scraping",
|
|
19
|
-
"x402"
|
|
19
|
+
"x402",
|
|
20
|
+
"news",
|
|
21
|
+
"news-search",
|
|
22
|
+
"screenshot",
|
|
23
|
+
"search-filters"
|
|
20
24
|
],
|
|
21
25
|
"license": "MIT",
|
|
22
26
|
"homepage": "https://agentsearchhq.com/?utm_source=n8n-nodes-agentsearch&utm_medium=package",
|