@dcrays/web-search 0.1.4-beta.10 → 0.1.4-beta.11
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 +11 -12
- package/src/tools.js +13 -12
package/package.json
CHANGED
package/plugin/index.js
CHANGED
|
@@ -258,22 +258,21 @@ ${nonce}`;
|
|
|
258
258
|
// dist/src/tools.js
|
|
259
259
|
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
260
260
|
function renderSearchResult(result) {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
}
|
|
271
|
-
return lines.join("\n");
|
|
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");
|
|
272
271
|
}
|
|
273
272
|
function createWebSearchTool(search) {
|
|
274
273
|
return defineTool({
|
|
275
274
|
name: "web_search",
|
|
276
|
-
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.",
|
|
277
276
|
parameters: {
|
|
278
277
|
query: { type: "string", required: true, description: "A focused web search query." },
|
|
279
278
|
count: { type: "integer", description: "Number of results to return. Defaults to 5; maximum 20." },
|
package/src/tools.js
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
import { defineTool } from '@deepseek-ai/dsh-tools';
|
|
2
2
|
function renderSearchResult(result) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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');
|
|
14
15
|
}
|
|
15
16
|
export function createWebSearchTool(search) {
|
|
16
17
|
return defineTool({
|
|
17
18
|
name: 'web_search',
|
|
18
|
-
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.',
|
|
19
20
|
parameters: {
|
|
20
21
|
query: { type: 'string', required: true, description: 'A focused web search query.' },
|
|
21
22
|
count: { type: 'integer', description: 'Number of results to return. Defaults to 5; maximum 20.' },
|