@dcrays/web-search 0.1.4-beta.8 → 0.2.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/package.json +1 -1
- package/plugin/index.js +14 -2
- package/src/tools.js +16 -2
package/package.json
CHANGED
package/plugin/index.js
CHANGED
|
@@ -257,10 +257,22 @@ ${nonce}`;
|
|
|
257
257
|
|
|
258
258
|
// dist/src/tools.js
|
|
259
259
|
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
260
|
+
function renderSearchResult(result) {
|
|
261
|
+
if (result.results.length === 0)
|
|
262
|
+
return "\u6CA1\u6709\u627E\u5230\u76F8\u5173\u7F51\u9875\u3002";
|
|
263
|
+
return result.results.map((item, index) => {
|
|
264
|
+
const title = item.title.replace(/([\\`*_[\]<>])/g, "\\$1");
|
|
265
|
+
const url = item.url.replace(/[()]/g, (character) => character === "(" ? "%28" : "%29");
|
|
266
|
+
const link = /^https?:\/\//i.test(url) ? `[${title}](${url})` : title;
|
|
267
|
+
const snippet = item.snippet.replace(/\s+/g, " ").trim();
|
|
268
|
+
const summary = snippet.length > 80 ? `${snippet.slice(0, 80)}\u2026` : snippet;
|
|
269
|
+
return `${index + 1}. ${link}${summary ? ` \u2014 ${summary}` : ""}`;
|
|
270
|
+
}).join("\n");
|
|
271
|
+
}
|
|
260
272
|
function createWebSearchTool(search) {
|
|
261
273
|
return defineTool({
|
|
262
274
|
name: "web_search",
|
|
263
|
-
description: "Search the public web with Mobook search services. Use Bocha first and fall back to Tavily when Bocha fails or returns no results. Use this for current information, source discovery, fact verification, news, weather, prices, schedules, or any question that requires internet access. In the final answer, summarize first, then present useful sources as a numbered list with Markdown links in the form [title
|
|
275
|
+
description: "Search the public web with Mobook search services. Use Bocha first and fall back to Tavily when Bocha fails or returns no results. Use this for current information, source discovery, fact verification, news, weather, prices, schedules, or any question that requires internet access. In the final answer, summarize first, then present useful sources as a numbered list with Markdown links in the form [title](url), followed by a concise snippet-based explanation. Never expose the raw JSON or internal provider fields.",
|
|
264
276
|
parameters: {
|
|
265
277
|
query: { type: "string", required: true, description: "A focused web search query." },
|
|
266
278
|
count: { type: "integer", description: "Number of results to return. Defaults to 5; maximum 20." },
|
|
@@ -279,7 +291,7 @@ function createWebSearchTool(search) {
|
|
|
279
291
|
},
|
|
280
292
|
output: {
|
|
281
293
|
schema: { type: "json" },
|
|
282
|
-
render: (_args, value) => [{ type: "text", text:
|
|
294
|
+
render: (_args, value) => [{ type: "text", text: renderSearchResult(value) }]
|
|
283
295
|
},
|
|
284
296
|
timeoutMs: 35e3,
|
|
285
297
|
async execute(args, exec) {
|
package/src/tools.js
CHANGED
|
@@ -1,8 +1,22 @@
|
|
|
1
1
|
import { defineTool } from '@deepseek-ai/dsh-tools';
|
|
2
|
+
function renderSearchResult(result) {
|
|
3
|
+
if (result.results.length === 0)
|
|
4
|
+
return '没有找到相关网页。';
|
|
5
|
+
return result.results
|
|
6
|
+
.map((item, index) => {
|
|
7
|
+
const title = item.title.replace(/([\\`*_[\]<>])/g, '\\$1');
|
|
8
|
+
const url = item.url.replace(/[()]/g, (character) => (character === '(' ? '%28' : '%29'));
|
|
9
|
+
const link = /^https?:\/\//i.test(url) ? `[${title}](${url})` : title;
|
|
10
|
+
const snippet = item.snippet.replace(/\s+/g, ' ').trim();
|
|
11
|
+
const summary = snippet.length > 80 ? `${snippet.slice(0, 80)}…` : snippet;
|
|
12
|
+
return `${index + 1}. ${link}${summary ? ` — ${summary}` : ''}`;
|
|
13
|
+
})
|
|
14
|
+
.join('\n');
|
|
15
|
+
}
|
|
2
16
|
export function createWebSearchTool(search) {
|
|
3
17
|
return defineTool({
|
|
4
18
|
name: 'web_search',
|
|
5
|
-
description: 'Search the public web with Mobook search services. Use Bocha first and fall back to Tavily when Bocha fails or returns no results. Use this for current information, source discovery, fact verification, news, weather, prices, schedules, or any question that requires internet access. In the final answer, summarize first, then present useful sources as a numbered list with Markdown links in the form [title
|
|
19
|
+
description: 'Search the public web with Mobook search services. Use Bocha first and fall back to Tavily when Bocha fails or returns no results. Use this for current information, source discovery, fact verification, news, weather, prices, schedules, or any question that requires internet access. In the final answer, summarize first, then present useful sources as a numbered list with Markdown links in the form [title](url), followed by a concise snippet-based explanation. Never expose the raw JSON or internal provider fields.',
|
|
6
20
|
parameters: {
|
|
7
21
|
query: { type: 'string', required: true, description: 'A focused web search query.' },
|
|
8
22
|
count: { type: 'integer', description: 'Number of results to return. Defaults to 5; maximum 20.' },
|
|
@@ -21,7 +35,7 @@ export function createWebSearchTool(search) {
|
|
|
21
35
|
},
|
|
22
36
|
output: {
|
|
23
37
|
schema: { type: 'json' },
|
|
24
|
-
render: (_args, value) => [{ type: 'text', text:
|
|
38
|
+
render: (_args, value) => [{ type: 'text', text: renderSearchResult(value) }]
|
|
25
39
|
},
|
|
26
40
|
timeoutMs: 35_000,
|
|
27
41
|
async execute(args, exec) {
|