@0xkobold/pi-web 0.1.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 +101 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +223 -0
- package/dist/index.js.map +1 -0
- package/dist/search.d.ts +30 -0
- package/dist/search.js +322 -0
- package/dist/search.js.map +1 -0
- package/package.json +47 -0
- package/src/index.ts +270 -0
- package/src/search.ts +393 -0
package/README.md
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# pi-web
|
|
2
|
+
|
|
3
|
+
Web search and content extraction for [pi-coding-agent](https://github.com/badlobby/pi-mono) — cascade fetching, multi-engine search, deep research.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pi install npm:@0xkobold/pi-web
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Or as part of the meta-extension:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pi install npm:@0xkobold/pi-kobold
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Features
|
|
18
|
+
|
|
19
|
+
- **Cascade Fetching** — Fast HTML → Readability → Playwright for JS sites
|
|
20
|
+
- **Multi-Engine Search** — DuckDuckGo (default) + SearXNG (fallback)
|
|
21
|
+
- **Deep Research** — Search + fetch + synthesize from multiple sources
|
|
22
|
+
- **Playwright Pool** — Browser reuse with concurrency limits and retries
|
|
23
|
+
- **Optional Dependency** — Playwright is optional; fast fetch works without it
|
|
24
|
+
|
|
25
|
+
## Tools
|
|
26
|
+
|
|
27
|
+
| Tool | Description |
|
|
28
|
+
|------|-------------|
|
|
29
|
+
| `web_fetch` | Fetch and extract content from a URL |
|
|
30
|
+
| `web_search` | Search web, optionally fetch content from results |
|
|
31
|
+
| `web_research` | Deep research: search + fetch + multi-source synthesis |
|
|
32
|
+
|
|
33
|
+
## Commands
|
|
34
|
+
|
|
35
|
+
| Command | Description |
|
|
36
|
+
|---------|-------------|
|
|
37
|
+
| `/deep-fetch <url>` | Fetch JS-rendered content using Playwright |
|
|
38
|
+
| `/web-search-deep <query>` | Search + fetch from top results |
|
|
39
|
+
|
|
40
|
+
## Parameters
|
|
41
|
+
|
|
42
|
+
### web_fetch
|
|
43
|
+
|
|
44
|
+
| Parameter | Type | Default | Description |
|
|
45
|
+
|-----------|------|---------|-------------|
|
|
46
|
+
| `url` | string | required | Full URL to fetch |
|
|
47
|
+
| `max_length` | number | 5000 | Maximum characters to retrieve |
|
|
48
|
+
| `use_playwright` | boolean | false | Force Playwright for JS content |
|
|
49
|
+
| `timeout_ms` | number | 15000 | Timeout in ms (max: 60000) |
|
|
50
|
+
|
|
51
|
+
### web_search
|
|
52
|
+
|
|
53
|
+
| Parameter | Type | Default | Description |
|
|
54
|
+
|-----------|------|---------|-------------|
|
|
55
|
+
| `query` | string | required | Search query |
|
|
56
|
+
| `limit` | number | 5 | Number of results (1-10) |
|
|
57
|
+
| `fetch_content` | boolean | false | Fetch full content from top results |
|
|
58
|
+
| `fetch_sources` | number | 3 | How many sources to fetch |
|
|
59
|
+
|
|
60
|
+
### web_research
|
|
61
|
+
|
|
62
|
+
| Parameter | Type | Default | Description |
|
|
63
|
+
|-----------|------|---------|-------------|
|
|
64
|
+
| `question` | string | required | Research question |
|
|
65
|
+
| `sources` | number | 5 | Number of sources to analyze (1-10) |
|
|
66
|
+
|
|
67
|
+
## Architecture
|
|
68
|
+
|
|
69
|
+
```
|
|
70
|
+
┌────────────────────────────────────────┐
|
|
71
|
+
│ pi-web │
|
|
72
|
+
├─────────────┬──────────────────────────┤
|
|
73
|
+
│ Search │ Content Extraction │
|
|
74
|
+
│ ───────── │ ────────────────────── │
|
|
75
|
+
│ DuckDuckGo │ 1. Fast fetch (HTML) │
|
|
76
|
+
│ SearXNG │ 2. Readability (regex) │
|
|
77
|
+
│ │ 3. Playwright (JS) │
|
|
78
|
+
├─────────────┴──────────────────────────┤
|
|
79
|
+
│ Playwright Browser Pool │
|
|
80
|
+
│ (concurrency: 2, pool TTL: 2m) │
|
|
81
|
+
└────────────────────────────────────────┘
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Development
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
cd packages/pi-web
|
|
88
|
+
bun install
|
|
89
|
+
bun run build
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Optional: Playwright
|
|
93
|
+
|
|
94
|
+
For JavaScript-rendered content, install Playwright:
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
npm install playwright
|
|
98
|
+
npx playwright install chromium
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Without Playwright, `web_fetch` still works using fast HTML fetch and readability extraction.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* pi-web - Web Search and Content Extraction for Pi Agents
|
|
3
|
+
*
|
|
4
|
+
* Provides web search + advanced content extraction using:
|
|
5
|
+
* 1. Standard fetch() for simple sites
|
|
6
|
+
* 2. Readability-style extraction for articles
|
|
7
|
+
* 3. Playwright for JavaScript-rendered content
|
|
8
|
+
* 4. Cascade strategy: fast → detailed
|
|
9
|
+
*
|
|
10
|
+
* Search backends: DuckDuckGo (default), SearXNG (fallback)
|
|
11
|
+
*
|
|
12
|
+
* Tools:
|
|
13
|
+
* web_fetch - Fetch and extract content from a URL
|
|
14
|
+
* web_search - Search web, optionally fetch content from results
|
|
15
|
+
* web_research - Deep research: search + fetch + synthesize from multiple sources
|
|
16
|
+
*
|
|
17
|
+
* Commands:
|
|
18
|
+
* /deep-fetch <url> - Fetch JS-rendered content
|
|
19
|
+
* /web-search-deep <query> - Search + fetch from top results
|
|
20
|
+
*/
|
|
21
|
+
import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
|
|
22
|
+
export default function (pi: ExtensionAPI): Promise<void>;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* pi-web - Web Search and Content Extraction for Pi Agents
|
|
3
|
+
*
|
|
4
|
+
* Provides web search + advanced content extraction using:
|
|
5
|
+
* 1. Standard fetch() for simple sites
|
|
6
|
+
* 2. Readability-style extraction for articles
|
|
7
|
+
* 3. Playwright for JavaScript-rendered content
|
|
8
|
+
* 4. Cascade strategy: fast → detailed
|
|
9
|
+
*
|
|
10
|
+
* Search backends: DuckDuckGo (default), SearXNG (fallback)
|
|
11
|
+
*
|
|
12
|
+
* Tools:
|
|
13
|
+
* web_fetch - Fetch and extract content from a URL
|
|
14
|
+
* web_search - Search web, optionally fetch content from results
|
|
15
|
+
* web_research - Deep research: search + fetch + synthesize from multiple sources
|
|
16
|
+
*
|
|
17
|
+
* Commands:
|
|
18
|
+
* /deep-fetch <url> - Fetch JS-rendered content
|
|
19
|
+
* /web-search-deep <query> - Search + fetch from top results
|
|
20
|
+
*/
|
|
21
|
+
import { Type } from "@sinclair/typebox";
|
|
22
|
+
import { cascadeFetch, playwrightFetch, webSearch, } from "./search.js";
|
|
23
|
+
export default async function (pi) {
|
|
24
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
25
|
+
// Commands
|
|
26
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
27
|
+
pi.registerCommand("deep-fetch", {
|
|
28
|
+
description: "Fetch JavaScript-rendered content from a URL using Playwright",
|
|
29
|
+
handler: async (args, ctx) => {
|
|
30
|
+
const parts = args.split(/\s+/).filter(Boolean);
|
|
31
|
+
const url = parts[0];
|
|
32
|
+
const max = parseInt(parts[1]) || 8000;
|
|
33
|
+
if (!url?.startsWith("http")) {
|
|
34
|
+
ctx.ui?.notify?.("❌ URL must start with http:// or https://", "error");
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
ctx.ui?.notify?.(`🔍 Deep fetching: ${url}`, "info");
|
|
38
|
+
const result = await cascadeFetch(url, max, true);
|
|
39
|
+
if (!result) {
|
|
40
|
+
ctx.ui?.notify?.("❌ Failed to fetch content", "error");
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
ctx.ui?.notify?.(`📄 ${result.title}\nMethod: ${result.method} | Source: ${result.url}\n─────────────────────────────────────────\n\n${result.content.slice(0, max)}${result.content.length > max ? `\n... (${result.content.length - max} more chars)` : ""}`, "info");
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
pi.registerCommand("web-search-deep", {
|
|
47
|
+
description: "Search web + fetch content from top results",
|
|
48
|
+
handler: async (args, ctx) => {
|
|
49
|
+
const numResults = 3;
|
|
50
|
+
ctx.ui?.notify?.(`🔍 Searching + fetching: "${args}"`, "info");
|
|
51
|
+
const results = await webSearch(args, numResults * 2);
|
|
52
|
+
if (results.length === 0) {
|
|
53
|
+
ctx.ui?.notify?.("❌ No search results found", "error");
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const fetched = [];
|
|
57
|
+
for (let i = 0; i < Math.min(numResults, results.length); i++) {
|
|
58
|
+
const r = results[i];
|
|
59
|
+
ctx.ui?.notify?.(` Fetching ${i + 1}/${numResults}: ${r.title.slice(0, 50)}...`, "info");
|
|
60
|
+
const content = await cascadeFetch(r.url, 3000);
|
|
61
|
+
if (content)
|
|
62
|
+
fetched.push(content);
|
|
63
|
+
}
|
|
64
|
+
const lines = [
|
|
65
|
+
`🔍 Research Results: "${args}"`,
|
|
66
|
+
`Sources: ${fetched.length} / ${results.length} found`,
|
|
67
|
+
"═══════════════════════════════════════════",
|
|
68
|
+
"",
|
|
69
|
+
];
|
|
70
|
+
for (let i = 0; i < fetched.length; i++) {
|
|
71
|
+
const f = fetched[i];
|
|
72
|
+
lines.push(`## ${i + 1}. ${f.title}`);
|
|
73
|
+
lines.push(`Source: ${f.url} | Method: ${f.method}`);
|
|
74
|
+
lines.push("");
|
|
75
|
+
lines.push(f.content.slice(0, 2500));
|
|
76
|
+
lines.push("");
|
|
77
|
+
lines.push("─────────────────────────────────────────");
|
|
78
|
+
lines.push("");
|
|
79
|
+
}
|
|
80
|
+
ctx.ui?.notify?.(lines.join("\n"), "info");
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
84
|
+
// Tools
|
|
85
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
86
|
+
pi.registerTool({
|
|
87
|
+
name: "web_fetch",
|
|
88
|
+
label: "Web Fetch",
|
|
89
|
+
description: "Fetch and extract content from a web page. Uses cascade: fast HTML → readability → Playwright for JS sites.",
|
|
90
|
+
parameters: Type.Object({
|
|
91
|
+
url: Type.String({ description: "Full URL to fetch (must include http:// or https://)" }),
|
|
92
|
+
max_length: Type.Optional(Type.Number({ description: "Maximum characters to retrieve (default: 5000)", default: 5000 })),
|
|
93
|
+
use_playwright: Type.Optional(Type.Boolean({ description: "Force Playwright for JavaScript-rendered content (default: false)", default: false })),
|
|
94
|
+
timeout_ms: Type.Optional(Type.Number({ description: "Timeout in milliseconds (default: 15000, max: 60000)", default: 15000 })),
|
|
95
|
+
}),
|
|
96
|
+
async execute(_toolCallId, params, _signal, _onUpdate, _ctx) {
|
|
97
|
+
const { url, max_length = 5000, use_playwright = false, timeout_ms = 15000 } = params;
|
|
98
|
+
if (!url?.startsWith("http")) {
|
|
99
|
+
return {
|
|
100
|
+
content: [{ type: "text", text: "URL must start with http:// or https://" }],
|
|
101
|
+
details: { error: "fetch_failed" },
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
const cappedTimeout = Math.min(timeout_ms, 60000);
|
|
105
|
+
let result;
|
|
106
|
+
if (use_playwright) {
|
|
107
|
+
result = await playwrightFetch(url, max_length, cappedTimeout);
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
result = await cascadeFetch(url, max_length, use_playwright, cappedTimeout);
|
|
111
|
+
}
|
|
112
|
+
if (!result) {
|
|
113
|
+
return {
|
|
114
|
+
content: [{ type: "text", text: `Failed to fetch content from ${url}` }],
|
|
115
|
+
details: { error: "fetch_failed", url },
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
content: [{
|
|
120
|
+
type: "text",
|
|
121
|
+
text: `# ${result.title}\n\n${result.content}\n\n[Source: ${result.url} | Method: ${result.method}]`,
|
|
122
|
+
}],
|
|
123
|
+
details: { url, title: result.title, method: result.method, length: result.content.length },
|
|
124
|
+
};
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
pi.registerTool({
|
|
128
|
+
name: "web_search",
|
|
129
|
+
label: "Web Search",
|
|
130
|
+
description: "Search the web using DuckDuckGo and SearX. Optionally fetch content from top results.",
|
|
131
|
+
parameters: Type.Object({
|
|
132
|
+
query: Type.String({ description: "Search query — be specific" }),
|
|
133
|
+
limit: Type.Optional(Type.Number({ description: "Number of results (1-10, default: 5)", default: 5 })),
|
|
134
|
+
fetch_content: Type.Optional(Type.Boolean({ description: "Fetch full content from top results (default: false)", default: false })),
|
|
135
|
+
fetch_sources: Type.Optional(Type.Number({ description: "How many sources to fetch content from if fetch_content is true (default: 3)", default: 3 })),
|
|
136
|
+
}),
|
|
137
|
+
async execute(_toolCallId, params, _signal, _onUpdate, _ctx) {
|
|
138
|
+
const { query, limit = 5, fetch_content = false, fetch_sources = 3 } = params;
|
|
139
|
+
if (!query) {
|
|
140
|
+
return {
|
|
141
|
+
content: [{ type: "text", text: "Invalid search query" }],
|
|
142
|
+
details: { error: "fetch_failed" },
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
const results = await webSearch(query, Math.min(limit, 10));
|
|
146
|
+
if (results.length === 0) {
|
|
147
|
+
return {
|
|
148
|
+
content: [{ type: "text", text: "No search results found" }],
|
|
149
|
+
details: { query, error: "no_results" },
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
const basicFormatted = results
|
|
153
|
+
.map((r, i) => `${i + 1}. ${r.title}\n ${r.url}${r.snippet ? "\n " + r.snippet : ""}`)
|
|
154
|
+
.join("\n\n");
|
|
155
|
+
if (fetch_content) {
|
|
156
|
+
const fetchedContent = [];
|
|
157
|
+
for (let i = 0; i < Math.min(fetch_sources, results.length); i++) {
|
|
158
|
+
const result = await cascadeFetch(results[i].url, 3000);
|
|
159
|
+
if (result) {
|
|
160
|
+
fetchedContent.push(`## ${result.title}\n${result.content.slice(0, 2500)}...\n[Source: ${result.url}]`);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return {
|
|
164
|
+
content: [{
|
|
165
|
+
type: "text",
|
|
166
|
+
text: `Search results for "${query}":\n\n${basicFormatted}\n\nDetailed content from ${fetchedContent.length} sources:\n\n${fetchedContent.join("\n\n---\n\n")}`,
|
|
167
|
+
}],
|
|
168
|
+
details: { query, results: results.length, fetched: fetchedContent.length, urls: results.map(r => r.url) },
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
return {
|
|
172
|
+
content: [{ type: "text", text: `Search results for "${query}":\n\n${basicFormatted}` }],
|
|
173
|
+
details: { query, results: results.length, urls: results.map(r => r.url) },
|
|
174
|
+
};
|
|
175
|
+
},
|
|
176
|
+
});
|
|
177
|
+
pi.registerTool({
|
|
178
|
+
name: "web_research",
|
|
179
|
+
label: "Web Research",
|
|
180
|
+
description: "Deep research: search + fetch content from multiple sources with synthesis. Best for comprehensive answers.",
|
|
181
|
+
parameters: Type.Object({
|
|
182
|
+
question: Type.String({ description: "The research question" }),
|
|
183
|
+
sources: Type.Optional(Type.Number({ description: "Number of sources to analyze (1-10, default: 5)", default: 5 })),
|
|
184
|
+
}),
|
|
185
|
+
async execute(_toolCallId, params, _signal, _onUpdate, _ctx) {
|
|
186
|
+
const { question, sources = 5 } = params;
|
|
187
|
+
if (!question) {
|
|
188
|
+
return {
|
|
189
|
+
content: [{ type: "text", text: "Invalid question provided" }],
|
|
190
|
+
details: { error: "fetch_failed" },
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
const searchResults = await webSearch(question, Math.min(sources, 10) * 2);
|
|
194
|
+
if (searchResults.length === 0) {
|
|
195
|
+
return {
|
|
196
|
+
content: [{ type: "text", text: `Could not find information about: "${question}"` }],
|
|
197
|
+
details: { question, error: "no_results" },
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
const fetched = [];
|
|
201
|
+
for (let i = 0; i < Math.min(sources, searchResults.length); i++) {
|
|
202
|
+
const result = await cascadeFetch(searchResults[i].url, 3000);
|
|
203
|
+
if (result)
|
|
204
|
+
fetched.push(result);
|
|
205
|
+
}
|
|
206
|
+
const summary = fetched.length > 0
|
|
207
|
+
? `Research on: "${question}"\n\nFound ${fetched.length} relevant sources:\n\n` +
|
|
208
|
+
fetched.map((c, i) => `## ${i + 1}. ${c.title}\n${c.content.slice(0, 2000)}...\n(Source: ${c.url} | Method: ${c.method})`).join("\n\n---\n\n")
|
|
209
|
+
: `Found ${searchResults.length} search results but could not fetch detailed content:\n\n` +
|
|
210
|
+
searchResults.slice(0, sources).map(r => `- ${r.title}: ${r.url}`).join("\n");
|
|
211
|
+
return {
|
|
212
|
+
content: [{ type: "text", text: summary }],
|
|
213
|
+
details: {
|
|
214
|
+
question,
|
|
215
|
+
sources_found: searchResults.length,
|
|
216
|
+
sources_fetched: fetched.length,
|
|
217
|
+
},
|
|
218
|
+
};
|
|
219
|
+
},
|
|
220
|
+
});
|
|
221
|
+
console.log("[pi-web] Extension loaded — tools: web_fetch, web_search, web_research");
|
|
222
|
+
}
|
|
223
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEzC,OAAO,EACL,YAAY,EACZ,eAAe,EACf,SAAS,GAGV,MAAM,aAAa,CAAC;AAErB,MAAM,CAAC,OAAO,CAAC,KAAK,WAAW,EAAgB;IAE7C,8EAA8E;IAC9E,WAAW;IACX,8EAA8E;IAE9E,EAAE,CAAC,eAAe,CAAC,YAAY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AC,IAAI,CAAC,MAAM,CAAC,CAAC;YACnC,CAAC;YAED,MAAM,OAAO,GAAG,OAAO,CAAC,MAAM,GAAG,CAAC;gBAChC,CAAC,CAAC,iBAAiB,QAAQ,cAAc,OAAO,CAAC,MAAM,wBAAwB;oBAC7E,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC;gBAChJ,CAAC,CAAC,SAAS,aAAa,CAAC,MAAM,2DAA2D;oBACxF,aAAa,CAAC,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAElF,OAAO;gBACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;gBAC1C,OAAO,EAAE;oBACP,QAAQ;oBACR,aAAa,EAAE,aAAa,CAAC,MAAM;oBACnC,eAAe,EAAE,OAAO,CAAC,MAAM;iBAChC;aACF,CAAC;QACJ,CAAC;KACF,CAAC,CAAC;IAEH,OAAO,CAAC,GAAG,CAAC,wEAAwE,CAAC,CAAC;AACxF,CAAC"}
|
package/dist/search.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* pi-web - Search and Content Extraction
|
|
3
|
+
*
|
|
4
|
+
* Internal search and fetch utilities. No framework dependencies.
|
|
5
|
+
*/
|
|
6
|
+
export interface ScrapingResult {
|
|
7
|
+
content: string;
|
|
8
|
+
title: string;
|
|
9
|
+
method: string;
|
|
10
|
+
url: string;
|
|
11
|
+
}
|
|
12
|
+
export interface WebSearchResult {
|
|
13
|
+
title: string;
|
|
14
|
+
url: string;
|
|
15
|
+
snippet: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Playwright fetch with queue-based concurrency
|
|
19
|
+
*/
|
|
20
|
+
export declare function playwrightFetch(url: string, maxLength: number, timeoutMs?: number): Promise<ScrapingResult | null>;
|
|
21
|
+
/**
|
|
22
|
+
* CASCADE: Try all methods in order of speed → quality
|
|
23
|
+
*/
|
|
24
|
+
export declare function cascadeFetch(url: string, maxLength?: number, usePlaywright?: boolean, timeoutMs?: number): Promise<ScrapingResult | null>;
|
|
25
|
+
export declare function searchDuckDuckGo(query: string, limit: number): Promise<WebSearchResult[]>;
|
|
26
|
+
export declare function searchSearX(query: string, limit: number, instance?: string): Promise<WebSearchResult[]>;
|
|
27
|
+
/**
|
|
28
|
+
* Combined search across multiple engines
|
|
29
|
+
*/
|
|
30
|
+
export declare function webSearch(query: string, limit?: number): Promise<WebSearchResult[]>;
|