cowork-cli 2.2.1 → 2.2.2
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/package.json +1 -1
- package/src/engine/tools/webSearch.js +11 -12
package/package.json
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { parse } from 'node-html-parser';
|
|
2
|
+
|
|
1
3
|
const TIMEOUT_MS = 10000;
|
|
2
4
|
const MAX_RESULTS_HARD_LIMIT = 20;
|
|
3
5
|
|
|
@@ -38,23 +40,20 @@ export default async function webSearch({ query, limit = 5 }) {
|
|
|
38
40
|
const html = await response.text();
|
|
39
41
|
const results = [];
|
|
40
42
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const blocks = html.split('class="links_main links_deep result__body"').slice(1);
|
|
43
|
+
const root = parse(html);
|
|
44
|
+
const resultNodes = root.querySelectorAll('.result__body');
|
|
44
45
|
|
|
45
|
-
for (const
|
|
46
|
+
for (const node of resultNodes) {
|
|
46
47
|
if (results.length >= maxLimit) break;
|
|
47
48
|
|
|
48
|
-
const
|
|
49
|
-
const
|
|
49
|
+
const titleEl = node.querySelector('.result__title a');
|
|
50
|
+
const snippetEl = node.querySelector('.result__snippet');
|
|
50
51
|
|
|
51
|
-
if (
|
|
52
|
-
|
|
53
|
-
const
|
|
54
|
-
const snippet = snippetMatch[2].replace(/<[^>]+>/g, '').trim();
|
|
52
|
+
if (titleEl && snippetEl) {
|
|
53
|
+
const title = titleEl.textContent.replace(/\s+/g, ' ').trim();
|
|
54
|
+
const snippet = snippetEl.textContent.replace(/\s+/g, ' ').trim();
|
|
55
55
|
|
|
56
|
-
|
|
57
|
-
let url = snippetMatch[1];
|
|
56
|
+
let url = titleEl.getAttribute('href') || '';
|
|
58
57
|
if (url.startsWith('//duckduckgo.com/l/?uddg=')) {
|
|
59
58
|
url = decodeURIComponent(url.split('uddg=')[1].split('&')[0]);
|
|
60
59
|
}
|