listpage-next-ai 0.0.276 → 0.0.278

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.
@@ -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
- websearchOptions?: {};
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,135 @@ 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: String(size),
927
+ page: String(page),
928
+ includeRawContent,
929
+ conciseSnippet
930
+ })
931
+ });
932
+ if (!response.ok) {
933
+ const errorText = await response.text();
934
+ console.error(errorText);
935
+ throw new Error(`秘塔搜索请求失败: ${response.status} ${response.statusText} - ${errorText}`);
936
+ }
937
+ return await response.json();
938
+ }
939
+ async read(url) {
940
+ const response = await fetch(`${this.baseUrl}/reader`, {
941
+ method: 'POST',
942
+ headers: {
943
+ Authorization: `Bearer ${this.apiKey}`,
944
+ Accept: 'text/plain',
945
+ 'Content-Type': 'application/json'
946
+ },
947
+ body: JSON.stringify({
948
+ url
949
+ })
950
+ });
951
+ if (!response.ok) {
952
+ const errorText = await response.text();
953
+ throw new Error(`秘塔阅读请求失败: ${response.status} ${response.statusText} - ${errorText}`);
954
+ }
955
+ return await response.text();
956
+ }
957
+ }
958
+ function createWebSearchTools(options) {
959
+ const { apiKey, pageSize = 10 } = options;
960
+ const client = new MetaSo(apiKey);
961
+ return [
962
+ (0, external_langchain_namespaceObject.tool)(async ({ q, page = 1 })=>{
963
+ try {
964
+ const result = await client.search({
965
+ q,
966
+ page,
967
+ scope: 'webpage',
968
+ includeSummary: true,
969
+ size: pageSize
970
+ });
971
+ if (!result.webpages || 0 === result.webpages.length) {
972
+ console.log(result);
973
+ return '未找到相关结果。';
974
+ }
975
+ return result.webpages.map((page, index)=>{
976
+ const content = `摘要: ${page.summary || ''}\n内容: ${page.snippet}`;
977
+ return `[结果 ${index + 1}]\n标题: ${page.title}\n链接: ${page.link}\n${content}\n日期: ${page.date}\n`;
978
+ }).join('\n---\n');
979
+ } catch (error) {
980
+ console.error('Web search failed:', error);
981
+ return `搜索过程中发生错误: ${error instanceof Error ? error.message : String(error)}`;
982
+ }
983
+ }, {
984
+ name: 'web_search',
985
+ description: '当需要查询实时信息、新闻、百科知识或其他互联网内容时使用此工具。支持翻页和获取全文。',
986
+ schema: {
987
+ type: 'object',
988
+ properties: {
989
+ q: {
990
+ type: 'string',
991
+ description: '搜索关键词或问题'
992
+ },
993
+ page: {
994
+ type: 'number',
995
+ description: '页码,默认为 1。如果第一页结果不满足需求,可以尝试搜索下一页。'
996
+ }
997
+ },
998
+ required: [
999
+ 'q'
1000
+ ]
1001
+ }
1002
+ }),
1003
+ (0, external_langchain_namespaceObject.tool)(async ({ url })=>{
1004
+ try {
1005
+ const content = await client.read(url);
1006
+ return content || '未获取到内容。';
1007
+ } catch (error) {
1008
+ console.error('Web read failed:', error);
1009
+ return `获取网页内容失败: ${error instanceof Error ? error.message : String(error)}`;
1010
+ }
1011
+ }, {
1012
+ name: 'web_read',
1013
+ description: '用于获取指定 URL 的网页正文内容(Markdown 格式)。当 web_search 的结果摘要不足以回答问题,或者需要深入分析某个网页的具体内容时,请使用此工具。',
1014
+ schema: {
1015
+ type: 'object',
1016
+ properties: {
1017
+ url: {
1018
+ type: 'string',
1019
+ description: '需要阅读的网页 URL'
1020
+ }
1021
+ },
1022
+ required: [
1023
+ 'url'
1024
+ ]
1025
+ }
1026
+ })
1027
+ ];
1028
+ }
906
1029
  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;
1030
+ const { name, model, system_prompt, subagents = [], tools = [], middleware = [], features, databaseOptions, knowledgeOptions, wordOptions, webSearchOptions, documentSearchOptions, inject_current_time, max_iterations = 0, simple = false } = options;
908
1031
  const defaultTools = [
909
1032
  ...features.database ? createDatabaseTools(databaseOptions) : [],
910
1033
  ...features.knowledge ? createKnowledgeTools(knowledgeOptions) : [],
911
1034
  ...features.word ? createWordTools(wordOptions) : [],
912
1035
  ...features.documentSearch ? createDocumentSearchTools(documentSearchOptions) : [],
1036
+ ...features.websearch ? createWebSearchTools(webSearchOptions) : [],
913
1037
  ...tools
914
1038
  ].filter(Boolean);
915
1039
  const agent = (0, external_langchain_namespaceObject.createAgent)({
@@ -1052,13 +1176,17 @@ function streamEvents2Subject(events, transform, callbacks) {
1052
1176
  }
1053
1177
  exports.AgentOptions = __webpack_exports__.AgentOptions;
1054
1178
  exports.ChatVolcengine = __webpack_exports__.ChatVolcengine;
1179
+ exports.MetaSo = __webpack_exports__.MetaSo;
1055
1180
  exports.createReactAgent = __webpack_exports__.createReactAgent;
1181
+ exports.createWebSearchTools = __webpack_exports__.createWebSearchTools;
1056
1182
  exports.simplifyStreamEvents = __webpack_exports__.simplifyStreamEvents;
1057
1183
  exports.streamEvents2Subject = __webpack_exports__.streamEvents2Subject;
1058
1184
  for(var __webpack_i__ in __webpack_exports__)if (-1 === [
1059
1185
  "AgentOptions",
1060
1186
  "ChatVolcengine",
1187
+ "MetaSo",
1061
1188
  "createReactAgent",
1189
+ "createWebSearchTools",
1062
1190
  "simplifyStreamEvents",
1063
1191
  "streamEvents2Subject"
1064
1192
  ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "listpage-next-ai",
3
- "version": "0.0.276",
3
+ "version": "0.0.278",
4
4
  "description": "A React component library for creating filter forms with Ant Design",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",