zan-browser 3.0.2 → 3.0.4
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web_search.d.ts","sourceRoot":"","sources":["../../../src/tools/network/web_search.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"web_search.d.ts","sourceRoot":"","sources":["../../../src/tools/network/web_search.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAgCzE,qBAAa,aAAc,YAAW,IAAI;IACxC,IAAI,SAAgB;IACpB,WAAW,SAAoJ;IAE/J,WAAW,EAAE,UAAU,CAMrB;IAEI,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC;CA2FtF"}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.WebSearchTool = void 0;
|
|
7
|
-
const
|
|
8
|
-
const
|
|
4
|
+
const FALLBACK_MODEL = "claude-sonnet-4-6";
|
|
5
|
+
const API_TIMEOUT_MS = 30_000;
|
|
6
|
+
// ─── Tool ────────────────────────────────────────────────────────────────────
|
|
9
7
|
class WebSearchTool {
|
|
10
8
|
name = "web_search";
|
|
11
9
|
description = "Search the web for information before navigating. Useful when the goal is vague or the target site/URL is unknown. Does NOT require a browser.";
|
|
@@ -19,38 +17,77 @@ class WebSearchTool {
|
|
|
19
17
|
async execute(params, ctx) {
|
|
20
18
|
const query = String(params.query);
|
|
21
19
|
try {
|
|
22
|
-
|
|
23
|
-
//
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
20
|
+
// Call the Anthropic API directly via fetch — the SDK 0.39.0 doesn't
|
|
21
|
+
// support the web_search server-side tool, so we bypass it entirely.
|
|
22
|
+
const response = await fetch("https://api.anthropic.com/v1/messages", {
|
|
23
|
+
method: "POST",
|
|
24
|
+
headers: {
|
|
25
|
+
"Content-Type": "application/json",
|
|
26
|
+
"x-api-key": ctx.anthropicApiKey,
|
|
27
|
+
"anthropic-version": "2023-06-01",
|
|
28
|
+
"anthropic-beta": "web-search-2025-03-05",
|
|
29
|
+
},
|
|
30
|
+
body: JSON.stringify({
|
|
31
|
+
model: ctx.aiModel ?? FALLBACK_MODEL,
|
|
32
|
+
max_tokens: 1024,
|
|
33
|
+
tools: [{ type: "web_search_20250305", name: "web_search" }],
|
|
34
|
+
messages: [{ role: "user", content: query }],
|
|
35
|
+
}),
|
|
36
|
+
signal: AbortSignal.timeout(API_TIMEOUT_MS),
|
|
32
37
|
});
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
38
|
+
if (!response.ok) {
|
|
39
|
+
const errorBody = await response.text();
|
|
40
|
+
return {
|
|
41
|
+
success: false,
|
|
42
|
+
summary: `web_search failed: HTTP ${response.status} — ${errorBody.slice(0, 300)}`,
|
|
43
|
+
error: `HTTP ${response.status}`,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
const data = (await response.json());
|
|
47
|
+
if (data.error) {
|
|
48
|
+
return {
|
|
49
|
+
success: false,
|
|
50
|
+
summary: `web_search failed: ${data.error.message}`,
|
|
51
|
+
error: data.error.message,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
// Extract search results and text blocks
|
|
55
|
+
const results = [];
|
|
56
|
+
const textParts = [];
|
|
57
|
+
for (const block of data.content) {
|
|
37
58
|
if (block.type === "text") {
|
|
38
|
-
|
|
59
|
+
textParts.push(block.text);
|
|
39
60
|
}
|
|
40
61
|
else if (block.type === "web_search_tool_result") {
|
|
41
|
-
|
|
62
|
+
const searchBlock = block;
|
|
63
|
+
for (const item of searchBlock.content ?? []) {
|
|
42
64
|
if (item.type === "web_search_result") {
|
|
43
|
-
|
|
44
|
-
|
|
65
|
+
results.push({
|
|
66
|
+
title: item.title,
|
|
67
|
+
url: item.url,
|
|
68
|
+
snippet: (item.page_content ?? item.encrypted_content ?? "").slice(0, 200),
|
|
69
|
+
});
|
|
45
70
|
}
|
|
46
71
|
}
|
|
47
72
|
}
|
|
48
73
|
}
|
|
49
|
-
|
|
74
|
+
// Format top 5 results
|
|
75
|
+
const top = results.slice(0, 5);
|
|
76
|
+
const resultLines = top.map((r, i) => `[${i + 1}] ${r.title} — ${r.url}\n${r.snippet}`);
|
|
77
|
+
// Combine: search results first, then any Claude commentary
|
|
78
|
+
const parts = [];
|
|
79
|
+
if (resultLines.length > 0) {
|
|
80
|
+
parts.push(resultLines.join("\n\n"));
|
|
81
|
+
}
|
|
82
|
+
if (textParts.length > 0) {
|
|
83
|
+
parts.push(textParts.join("\n"));
|
|
84
|
+
}
|
|
85
|
+
const summary = parts.join("\n\n---\n\n").slice(0, 4000);
|
|
86
|
+
const urls = results.map((r) => r.url);
|
|
50
87
|
return {
|
|
51
88
|
success: true,
|
|
52
|
-
summary:
|
|
53
|
-
data: { query, urls, resultCount:
|
|
89
|
+
summary: summary || "Web search returned no results.",
|
|
90
|
+
data: { query, urls, resultCount: results.length },
|
|
54
91
|
};
|
|
55
92
|
}
|
|
56
93
|
catch (err) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web_search.js","sourceRoot":"","sources":["../../../src/tools/network/web_search.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"web_search.js","sourceRoot":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