listpage-next-ai 0.0.276 → 0.0.277
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/dist/cjs/index.d.ts +71 -1
- package/dist/cjs/index.js +125 -1
- package/package.json +1 -1
package/dist/cjs/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { BaseMessage } from 'langchain';
|
|
|
3
3
|
import { BaseMessageChunk } from 'langchain';
|
|
4
4
|
import { ChatOpenAICallOptions } from '@langchain/openai';
|
|
5
5
|
import { ChatOpenAICompletions } from '@langchain/openai';
|
|
6
|
+
import { DynamicStructuredTool } from 'langchain';
|
|
6
7
|
import { IterableReadableStream } from '@langchain/core/utils/stream';
|
|
7
8
|
import { LanguageModelLike } from '@langchain/core/language_models/base';
|
|
8
9
|
import { MessageStructure } from '@langchain/core/messages';
|
|
@@ -26,7 +27,9 @@ export declare interface AgentOptions {
|
|
|
26
27
|
knowledgeOptions?: KnowledgeAgentOptions;
|
|
27
28
|
wordOptions?: WordToolOptions;
|
|
28
29
|
documentSearchOptions?: DocumentSearchToolOptions;
|
|
29
|
-
|
|
30
|
+
webSearchOptions?: {
|
|
31
|
+
apiKey: string;
|
|
32
|
+
};
|
|
30
33
|
model: LanguageModelLike;
|
|
31
34
|
system_prompt: string;
|
|
32
35
|
tools?: any[];
|
|
@@ -73,6 +76,30 @@ declare interface CompiledSubAgent {
|
|
|
73
76
|
|
|
74
77
|
export declare function createReactAgent(options: AgentOptions): ReactAgent<ResponseFormatUndefined, undefined, AnyAnnotationRoot, any[]>;
|
|
75
78
|
|
|
79
|
+
export declare function createWebSearchTools(options: WebSearchToolOptions): (DynamicStructuredTool< {
|
|
80
|
+
type: "object";
|
|
81
|
+
properties: {
|
|
82
|
+
q: {
|
|
83
|
+
type: "string";
|
|
84
|
+
description: string;
|
|
85
|
+
};
|
|
86
|
+
page: {
|
|
87
|
+
type: "number";
|
|
88
|
+
description: string;
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
required: string[];
|
|
92
|
+
}, unknown, unknown, string> | DynamicStructuredTool< {
|
|
93
|
+
type: "object";
|
|
94
|
+
properties: {
|
|
95
|
+
url: {
|
|
96
|
+
type: "string";
|
|
97
|
+
description: string;
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
required: string[];
|
|
101
|
+
}, unknown, unknown, string>)[];
|
|
102
|
+
|
|
76
103
|
declare interface DatabaseAgentOptions extends DatabaseToolOptions {
|
|
77
104
|
}
|
|
78
105
|
|
|
@@ -117,6 +144,44 @@ declare interface KnowledgeToolOptions {
|
|
|
117
144
|
onRetrieveFullDocs: (index: string, title: string) => Promise<string>;
|
|
118
145
|
}
|
|
119
146
|
|
|
147
|
+
export declare class MetaSo {
|
|
148
|
+
private apiKey;
|
|
149
|
+
private baseUrl;
|
|
150
|
+
constructor(apiKey: string);
|
|
151
|
+
search(options: MetaSoSearchOptions): Promise<MetaSoResponse>;
|
|
152
|
+
read(url: string): Promise<string>;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export declare interface MetaSoResponse {
|
|
156
|
+
credits: number;
|
|
157
|
+
searchParameters: MetaSoSearchOptions & {
|
|
158
|
+
searchFile?: boolean;
|
|
159
|
+
format?: string;
|
|
160
|
+
};
|
|
161
|
+
webpages: MetaSoWebpage[];
|
|
162
|
+
total: number;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export declare interface MetaSoSearchOptions {
|
|
166
|
+
q: string;
|
|
167
|
+
scope?: 'webpage' | 'document' | 'scholar' | 'image' | 'video' | 'podcast';
|
|
168
|
+
includeSummary?: boolean;
|
|
169
|
+
size?: number;
|
|
170
|
+
page?: number;
|
|
171
|
+
includeRawContent?: boolean;
|
|
172
|
+
conciseSnippet?: boolean;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export declare interface MetaSoWebpage {
|
|
176
|
+
title: string;
|
|
177
|
+
link: string;
|
|
178
|
+
score: string;
|
|
179
|
+
snippet?: string;
|
|
180
|
+
summary?: string;
|
|
181
|
+
position: number;
|
|
182
|
+
date: string;
|
|
183
|
+
}
|
|
184
|
+
|
|
120
185
|
export declare function simplifyStreamEvents(events: IterableReadableStream<StreamEvent>): Promise<AsyncGenerator<{
|
|
121
186
|
type: string;
|
|
122
187
|
data: any;
|
|
@@ -139,6 +204,11 @@ export declare function streamEvents2Subject<Event = any>(events: IterableReadab
|
|
|
139
204
|
data: any;
|
|
140
205
|
}>;
|
|
141
206
|
|
|
207
|
+
export declare interface WebSearchToolOptions {
|
|
208
|
+
apiKey: string;
|
|
209
|
+
pageSize?: number;
|
|
210
|
+
}
|
|
211
|
+
|
|
142
212
|
declare interface WordToolOptions {
|
|
143
213
|
glossry: {
|
|
144
214
|
name: string;
|
package/dist/cjs/index.js
CHANGED
|
@@ -24,8 +24,10 @@ var __webpack_require__ = {};
|
|
|
24
24
|
var __webpack_exports__ = {};
|
|
25
25
|
__webpack_require__.r(__webpack_exports__);
|
|
26
26
|
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
createWebSearchTools: ()=>createWebSearchTools,
|
|
27
28
|
createReactAgent: ()=>createReactAgent,
|
|
28
29
|
simplifyStreamEvents: ()=>simplifyStreamEvents,
|
|
30
|
+
MetaSo: ()=>MetaSo,
|
|
29
31
|
streamEvents2Subject: ()=>streamEvents2Subject,
|
|
30
32
|
ChatVolcengine: ()=>ChatVolcengine,
|
|
31
33
|
AgentOptions: ()=>types_namespaceObject.AgentOptions
|
|
@@ -903,13 +905,131 @@ function createDocumentSearchTools(options) {
|
|
|
903
905
|
})
|
|
904
906
|
];
|
|
905
907
|
}
|
|
908
|
+
class MetaSo {
|
|
909
|
+
constructor(apiKey){
|
|
910
|
+
this.baseUrl = 'https://metaso.cn/api/v1';
|
|
911
|
+
this.apiKey = apiKey;
|
|
912
|
+
}
|
|
913
|
+
async search(options) {
|
|
914
|
+
const { q, scope = 'webpage', includeSummary = true, size = 10, page = 1, includeRawContent = false, conciseSnippet = true } = options;
|
|
915
|
+
const response = await fetch(`${this.baseUrl}/search`, {
|
|
916
|
+
method: 'POST',
|
|
917
|
+
headers: {
|
|
918
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
919
|
+
Accept: 'application/json',
|
|
920
|
+
'Content-Type': 'application/json'
|
|
921
|
+
},
|
|
922
|
+
body: JSON.stringify({
|
|
923
|
+
q,
|
|
924
|
+
scope,
|
|
925
|
+
includeSummary,
|
|
926
|
+
size,
|
|
927
|
+
page,
|
|
928
|
+
includeRawContent,
|
|
929
|
+
conciseSnippet
|
|
930
|
+
})
|
|
931
|
+
});
|
|
932
|
+
if (!response.ok) {
|
|
933
|
+
const errorText = await response.text();
|
|
934
|
+
throw new Error(`秘塔搜索请求失败: ${response.status} ${response.statusText} - ${errorText}`);
|
|
935
|
+
}
|
|
936
|
+
return response.json();
|
|
937
|
+
}
|
|
938
|
+
async read(url) {
|
|
939
|
+
const response = await fetch(`${this.baseUrl}/reader`, {
|
|
940
|
+
method: 'POST',
|
|
941
|
+
headers: {
|
|
942
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
943
|
+
Accept: 'text/plain',
|
|
944
|
+
'Content-Type': 'application/json'
|
|
945
|
+
},
|
|
946
|
+
body: JSON.stringify({
|
|
947
|
+
url
|
|
948
|
+
})
|
|
949
|
+
});
|
|
950
|
+
if (!response.ok) {
|
|
951
|
+
const errorText = await response.text();
|
|
952
|
+
throw new Error(`秘塔阅读请求失败: ${response.status} ${response.statusText} - ${errorText}`);
|
|
953
|
+
}
|
|
954
|
+
return await response.text();
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
function createWebSearchTools(options) {
|
|
958
|
+
const { apiKey, pageSize = 10 } = options;
|
|
959
|
+
const client = new MetaSo(apiKey);
|
|
960
|
+
return [
|
|
961
|
+
(0, external_langchain_namespaceObject.tool)(async ({ q, page = 1 })=>{
|
|
962
|
+
try {
|
|
963
|
+
const result = await client.search({
|
|
964
|
+
q,
|
|
965
|
+
page,
|
|
966
|
+
scope: 'webpage',
|
|
967
|
+
includeSummary: true,
|
|
968
|
+
size: pageSize
|
|
969
|
+
});
|
|
970
|
+
if (!result.webpages || 0 === result.webpages.length) return '未找到相关结果。';
|
|
971
|
+
return result.webpages.map((page, index)=>{
|
|
972
|
+
const content = `摘要: ${page.summary || ''}\n内容: ${page.snippet}`;
|
|
973
|
+
return `[结果 ${index + 1}]\n标题: ${page.title}\n链接: ${page.link}\n${content}\n日期: ${page.date}\n`;
|
|
974
|
+
}).join('\n---\n');
|
|
975
|
+
} catch (error) {
|
|
976
|
+
console.error('Web search failed:', error);
|
|
977
|
+
return `搜索过程中发生错误: ${error instanceof Error ? error.message : String(error)}`;
|
|
978
|
+
}
|
|
979
|
+
}, {
|
|
980
|
+
name: 'web_search',
|
|
981
|
+
description: '当需要查询实时信息、新闻、百科知识或其他互联网内容时使用此工具。支持翻页和获取全文。',
|
|
982
|
+
schema: {
|
|
983
|
+
type: 'object',
|
|
984
|
+
properties: {
|
|
985
|
+
q: {
|
|
986
|
+
type: 'string',
|
|
987
|
+
description: '搜索关键词或问题'
|
|
988
|
+
},
|
|
989
|
+
page: {
|
|
990
|
+
type: 'number',
|
|
991
|
+
description: '页码,默认为 1。如果第一页结果不满足需求,可以尝试搜索下一页。'
|
|
992
|
+
}
|
|
993
|
+
},
|
|
994
|
+
required: [
|
|
995
|
+
'q'
|
|
996
|
+
]
|
|
997
|
+
}
|
|
998
|
+
}),
|
|
999
|
+
(0, external_langchain_namespaceObject.tool)(async ({ url })=>{
|
|
1000
|
+
try {
|
|
1001
|
+
const content = await client.read(url);
|
|
1002
|
+
return content || '未获取到内容。';
|
|
1003
|
+
} catch (error) {
|
|
1004
|
+
console.error('Web read failed:', error);
|
|
1005
|
+
return `获取网页内容失败: ${error instanceof Error ? error.message : String(error)}`;
|
|
1006
|
+
}
|
|
1007
|
+
}, {
|
|
1008
|
+
name: 'web_read',
|
|
1009
|
+
description: '用于获取指定 URL 的网页正文内容(Markdown 格式)。当 web_search 的结果摘要不足以回答问题,或者需要深入分析某个网页的具体内容时,请使用此工具。',
|
|
1010
|
+
schema: {
|
|
1011
|
+
type: 'object',
|
|
1012
|
+
properties: {
|
|
1013
|
+
url: {
|
|
1014
|
+
type: 'string',
|
|
1015
|
+
description: '需要阅读的网页 URL'
|
|
1016
|
+
}
|
|
1017
|
+
},
|
|
1018
|
+
required: [
|
|
1019
|
+
'url'
|
|
1020
|
+
]
|
|
1021
|
+
}
|
|
1022
|
+
})
|
|
1023
|
+
];
|
|
1024
|
+
}
|
|
906
1025
|
function createReactAgent(options) {
|
|
907
|
-
const { name, model, system_prompt, subagents = [], tools = [], middleware = [], features, databaseOptions, knowledgeOptions, wordOptions, documentSearchOptions, inject_current_time, max_iterations = 0, simple = false } = options;
|
|
1026
|
+
const { name, model, system_prompt, subagents = [], tools = [], middleware = [], features, databaseOptions, knowledgeOptions, wordOptions, webSearchOptions, documentSearchOptions, inject_current_time, max_iterations = 0, simple = false } = options;
|
|
908
1027
|
const defaultTools = [
|
|
909
1028
|
...features.database ? createDatabaseTools(databaseOptions) : [],
|
|
910
1029
|
...features.knowledge ? createKnowledgeTools(knowledgeOptions) : [],
|
|
911
1030
|
...features.word ? createWordTools(wordOptions) : [],
|
|
912
1031
|
...features.documentSearch ? createDocumentSearchTools(documentSearchOptions) : [],
|
|
1032
|
+
...features.websearch ? createWebSearchTools(webSearchOptions) : [],
|
|
913
1033
|
...tools
|
|
914
1034
|
].filter(Boolean);
|
|
915
1035
|
const agent = (0, external_langchain_namespaceObject.createAgent)({
|
|
@@ -1052,13 +1172,17 @@ function streamEvents2Subject(events, transform, callbacks) {
|
|
|
1052
1172
|
}
|
|
1053
1173
|
exports.AgentOptions = __webpack_exports__.AgentOptions;
|
|
1054
1174
|
exports.ChatVolcengine = __webpack_exports__.ChatVolcengine;
|
|
1175
|
+
exports.MetaSo = __webpack_exports__.MetaSo;
|
|
1055
1176
|
exports.createReactAgent = __webpack_exports__.createReactAgent;
|
|
1177
|
+
exports.createWebSearchTools = __webpack_exports__.createWebSearchTools;
|
|
1056
1178
|
exports.simplifyStreamEvents = __webpack_exports__.simplifyStreamEvents;
|
|
1057
1179
|
exports.streamEvents2Subject = __webpack_exports__.streamEvents2Subject;
|
|
1058
1180
|
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
1059
1181
|
"AgentOptions",
|
|
1060
1182
|
"ChatVolcengine",
|
|
1183
|
+
"MetaSo",
|
|
1061
1184
|
"createReactAgent",
|
|
1185
|
+
"createWebSearchTools",
|
|
1062
1186
|
"simplifyStreamEvents",
|
|
1063
1187
|
"streamEvents2Subject"
|
|
1064
1188
|
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|