@dsh-plus/web-search-services 0.1.2 → 0.1.3
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/lib/index.js +9 -2
- package/package.json +1 -1
- package/src/normalize.ts +11 -2
package/lib/index.js
CHANGED
|
@@ -118,6 +118,12 @@ function asNonEmptyString(value) {
|
|
|
118
118
|
function asArray(value) {
|
|
119
119
|
return Array.isArray(value) ? value : [];
|
|
120
120
|
}
|
|
121
|
+
/** snippet 截断上限:官方 deepseek provider 的摘录是短引文;Tavily content /
|
|
122
|
+
* Exa highlights 原始值可达整页文本,直接透传会撑爆工具结果上下文。 */
|
|
123
|
+
const SNIPPET_MAX_CHARS = 500;
|
|
124
|
+
function truncateSnippet(text) {
|
|
125
|
+
return text.length <= SNIPPET_MAX_CHARS ? text : `${text.slice(0, SNIPPET_MAX_CHARS)}…`;
|
|
126
|
+
}
|
|
121
127
|
function makeSource(url, title, snippet, publishedAt) {
|
|
122
128
|
return {
|
|
123
129
|
url,
|
|
@@ -157,8 +163,9 @@ function normalizeTavily(raw) {
|
|
|
157
163
|
const payload = payloadOf(raw);
|
|
158
164
|
const sources = sourcesFromResults(payload.results, (item) => {
|
|
159
165
|
const url = asNonEmptyString(item.url);
|
|
166
|
+
const content = asNonEmptyString(item.content);
|
|
160
167
|
if (url === void 0) return void 0;
|
|
161
|
-
return makeSource(url, asNonEmptyString(item.title),
|
|
168
|
+
return makeSource(url, asNonEmptyString(item.title), content !== void 0 ? truncateSnippet(content) : void 0, asNonEmptyString(item.published_date));
|
|
162
169
|
});
|
|
163
170
|
return finish(asNonEmptyString(payload.answer), sources);
|
|
164
171
|
}
|
|
@@ -167,7 +174,7 @@ function normalizeExa(raw) {
|
|
|
167
174
|
const url = asNonEmptyString(item.url) ?? asNonEmptyString(item.id);
|
|
168
175
|
if (url === void 0) return void 0;
|
|
169
176
|
const highlights = asArray(item.highlights).map((h) => asNonEmptyString(h)).filter((h) => h !== void 0);
|
|
170
|
-
return makeSource(url, asNonEmptyString(item.title), highlights.length > 0 ? highlights.join(" ") : void 0, asNonEmptyString(item.publishedDate));
|
|
177
|
+
return makeSource(url, asNonEmptyString(item.title), highlights.length > 0 ? truncateSnippet(highlights.join(" ")) : void 0, asNonEmptyString(item.publishedDate));
|
|
171
178
|
}));
|
|
172
179
|
}
|
|
173
180
|
const MARKDOWN_LINK = /\[([^\]]*)\]\((https?:\/\/[^)\s]+)\)/g;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dsh-plus/web-search-services",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "dsh-plus service plugin: web_search 免费后端聚合——经官方 ctx.web provider 扩展点桥接 search-services skill(Tavily/Exa/OpenAI Chat 免费额度,优先级+自动回退+key 配置),官方 web_search 工具与输出格式零修改",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
package/src/normalize.ts
CHANGED
|
@@ -25,6 +25,14 @@ function asArray(value: unknown): unknown[] {
|
|
|
25
25
|
return Array.isArray(value) ? value : []
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
/** snippet 截断上限:官方 deepseek provider 的摘录是短引文;Tavily content /
|
|
29
|
+
* Exa highlights 原始值可达整页文本,直接透传会撑爆工具结果上下文。 */
|
|
30
|
+
const SNIPPET_MAX_CHARS = 500
|
|
31
|
+
|
|
32
|
+
export function truncateSnippet(text: string): string {
|
|
33
|
+
return text.length <= SNIPPET_MAX_CHARS ? text : `${text.slice(0, SNIPPET_MAX_CHARS)}…`
|
|
34
|
+
}
|
|
35
|
+
|
|
28
36
|
function makeSource(
|
|
29
37
|
url: string,
|
|
30
38
|
title?: string,
|
|
@@ -76,11 +84,12 @@ function normalizeTavily(raw: JsonObject): WebSearchResult {
|
|
|
76
84
|
const payload = payloadOf(raw)
|
|
77
85
|
const sources = sourcesFromResults(payload.results, (item) => {
|
|
78
86
|
const url = asNonEmptyString(item.url)
|
|
87
|
+
const content = asNonEmptyString(item.content)
|
|
79
88
|
if (url === undefined) return undefined
|
|
80
89
|
return makeSource(
|
|
81
90
|
url,
|
|
82
91
|
asNonEmptyString(item.title),
|
|
83
|
-
|
|
92
|
+
content !== undefined ? truncateSnippet(content) : undefined,
|
|
84
93
|
asNonEmptyString(item.published_date),
|
|
85
94
|
)
|
|
86
95
|
})
|
|
@@ -98,7 +107,7 @@ function normalizeExa(raw: JsonObject): WebSearchResult {
|
|
|
98
107
|
return makeSource(
|
|
99
108
|
url,
|
|
100
109
|
asNonEmptyString(item.title),
|
|
101
|
-
highlights.length > 0 ? highlights.join(' ') : undefined,
|
|
110
|
+
highlights.length > 0 ? truncateSnippet(highlights.join(' ')) : undefined,
|
|
102
111
|
asNonEmptyString(item.publishedDate),
|
|
103
112
|
)
|
|
104
113
|
})
|