@librechat/agents 3.3.11 → 3.3.12
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/graphs/Graph.cjs +246 -25
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/llm/bedrock/index.cjs +13 -2
- package/dist/cjs/llm/bedrock/index.cjs.map +1 -1
- package/dist/cjs/llm/invoke.cjs +146 -36
- package/dist/cjs/llm/invoke.cjs.map +1 -1
- package/dist/cjs/llm/openai/index.cjs +2 -2
- package/dist/cjs/llm/openai/index.cjs.map +1 -1
- package/dist/cjs/llm/streamLimits.cjs +723 -0
- package/dist/cjs/llm/streamLimits.cjs.map +1 -0
- package/dist/cjs/main.cjs +8 -0
- package/dist/cjs/run.cjs +6 -2
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/cjs/session/AgentSession.cjs +4 -1
- package/dist/cjs/session/AgentSession.cjs.map +1 -1
- package/dist/cjs/stream.cjs +103 -12
- package/dist/cjs/stream.cjs.map +1 -1
- package/dist/cjs/summarization/node.cjs +157 -37
- package/dist/cjs/summarization/node.cjs.map +1 -1
- package/dist/cjs/tools/BashExecutor.cjs +3 -2
- package/dist/cjs/tools/BashExecutor.cjs.map +1 -1
- package/dist/cjs/tools/CodeExecutor.cjs +4 -3
- package/dist/cjs/tools/CodeExecutor.cjs.map +1 -1
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs +5 -3
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs.map +1 -1
- package/dist/cjs/tools/ToolNode.cjs +76 -3
- package/dist/cjs/tools/ToolNode.cjs.map +1 -1
- package/dist/cjs/tools/ToolSearch.cjs +3 -2
- package/dist/cjs/tools/ToolSearch.cjs.map +1 -1
- package/dist/cjs/tools/search/crw-scraper.cjs +7 -1
- package/dist/cjs/tools/search/crw-scraper.cjs.map +1 -1
- package/dist/cjs/tools/search/crw-search.cjs +3 -1
- package/dist/cjs/tools/search/crw-search.cjs.map +1 -1
- package/dist/cjs/tools/search/firecrawl.cjs +7 -1
- package/dist/cjs/tools/search/firecrawl.cjs.map +1 -1
- package/dist/cjs/tools/search/keenable-scraper.cjs +7 -1
- package/dist/cjs/tools/search/keenable-scraper.cjs.map +1 -1
- package/dist/cjs/tools/search/keenable-search.cjs +3 -1
- package/dist/cjs/tools/search/keenable-search.cjs.map +1 -1
- package/dist/cjs/tools/search/rerankers.cjs +26 -8
- package/dist/cjs/tools/search/rerankers.cjs.map +1 -1
- package/dist/cjs/tools/search/search.cjs +30 -10
- package/dist/cjs/tools/search/search.cjs.map +1 -1
- package/dist/cjs/tools/search/serper-scraper.cjs +7 -1
- package/dist/cjs/tools/search/serper-scraper.cjs.map +1 -1
- package/dist/cjs/tools/search/tavily-scraper.cjs +7 -1
- package/dist/cjs/tools/search/tavily-scraper.cjs.map +1 -1
- package/dist/cjs/tools/search/tavily-search.cjs +3 -1
- package/dist/cjs/tools/search/tavily-search.cjs.map +1 -1
- package/dist/cjs/tools/search/tool.cjs +16 -2
- package/dist/cjs/tools/search/tool.cjs.map +1 -1
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs +54 -3
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs.map +1 -1
- package/dist/cjs/utils/index.cjs +1 -0
- package/dist/cjs/utils/misc.cjs +12 -0
- package/dist/cjs/utils/misc.cjs.map +1 -1
- package/dist/cjs/utils/proxy.cjs +63 -0
- package/dist/cjs/utils/proxy.cjs.map +1 -0
- package/dist/esm/graphs/Graph.mjs +245 -24
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/llm/bedrock/index.mjs +13 -2
- package/dist/esm/llm/bedrock/index.mjs.map +1 -1
- package/dist/esm/llm/invoke.mjs +146 -36
- package/dist/esm/llm/invoke.mjs.map +1 -1
- package/dist/esm/llm/openai/index.mjs +2 -2
- package/dist/esm/llm/openai/index.mjs.map +1 -1
- package/dist/esm/llm/streamLimits.mjs +704 -0
- package/dist/esm/llm/streamLimits.mjs.map +1 -0
- package/dist/esm/main.mjs +4 -2
- package/dist/esm/run.mjs +6 -2
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/session/AgentSession.mjs +4 -1
- package/dist/esm/session/AgentSession.mjs.map +1 -1
- package/dist/esm/stream.mjs +103 -12
- package/dist/esm/stream.mjs.map +1 -1
- package/dist/esm/summarization/node.mjs +157 -37
- package/dist/esm/summarization/node.mjs.map +1 -1
- package/dist/esm/tools/BashExecutor.mjs +3 -2
- package/dist/esm/tools/BashExecutor.mjs.map +1 -1
- package/dist/esm/tools/CodeExecutor.mjs +4 -3
- package/dist/esm/tools/CodeExecutor.mjs.map +1 -1
- package/dist/esm/tools/ProgrammaticToolCalling.mjs +5 -3
- package/dist/esm/tools/ProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/ToolNode.mjs +76 -3
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/esm/tools/ToolSearch.mjs +3 -2
- package/dist/esm/tools/ToolSearch.mjs.map +1 -1
- package/dist/esm/tools/search/crw-scraper.mjs +7 -1
- package/dist/esm/tools/search/crw-scraper.mjs.map +1 -1
- package/dist/esm/tools/search/crw-search.mjs +3 -1
- package/dist/esm/tools/search/crw-search.mjs.map +1 -1
- package/dist/esm/tools/search/firecrawl.mjs +7 -1
- package/dist/esm/tools/search/firecrawl.mjs.map +1 -1
- package/dist/esm/tools/search/keenable-scraper.mjs +7 -1
- package/dist/esm/tools/search/keenable-scraper.mjs.map +1 -1
- package/dist/esm/tools/search/keenable-search.mjs +3 -1
- package/dist/esm/tools/search/keenable-search.mjs.map +1 -1
- package/dist/esm/tools/search/rerankers.mjs +26 -8
- package/dist/esm/tools/search/rerankers.mjs.map +1 -1
- package/dist/esm/tools/search/search.mjs +30 -10
- package/dist/esm/tools/search/search.mjs.map +1 -1
- package/dist/esm/tools/search/serper-scraper.mjs +7 -1
- package/dist/esm/tools/search/serper-scraper.mjs.map +1 -1
- package/dist/esm/tools/search/tavily-scraper.mjs +7 -1
- package/dist/esm/tools/search/tavily-scraper.mjs.map +1 -1
- package/dist/esm/tools/search/tavily-search.mjs +3 -1
- package/dist/esm/tools/search/tavily-search.mjs.map +1 -1
- package/dist/esm/tools/search/tool.mjs +16 -2
- package/dist/esm/tools/search/tool.mjs.map +1 -1
- package/dist/esm/tools/subagent/SubagentExecutor.mjs +54 -3
- package/dist/esm/tools/subagent/SubagentExecutor.mjs.map +1 -1
- package/dist/esm/utils/index.mjs +1 -0
- package/dist/esm/utils/misc.mjs +12 -1
- package/dist/esm/utils/misc.mjs.map +1 -1
- package/dist/esm/utils/proxy.mjs +62 -0
- package/dist/esm/utils/proxy.mjs.map +1 -0
- package/dist/types/graphs/Graph.d.ts +53 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/llm/invoke.d.ts +25 -4
- package/dist/types/llm/openai/index.d.ts +3 -0
- package/dist/types/llm/streamLimits.d.ts +314 -0
- package/dist/types/run.d.ts +1 -0
- package/dist/types/summarization/node.d.ts +27 -2
- package/dist/types/tools/BashExecutor.d.ts +2 -2
- package/dist/types/tools/CodeExecutor.d.ts +3 -3
- package/dist/types/tools/ToolNode.d.ts +11 -1
- package/dist/types/tools/search/crw-scraper.d.ts +2 -0
- package/dist/types/tools/search/firecrawl.d.ts +2 -0
- package/dist/types/tools/search/keenable-scraper.d.ts +2 -0
- package/dist/types/tools/search/rerankers.d.ts +9 -5
- package/dist/types/tools/search/serper-scraper.d.ts +2 -0
- package/dist/types/tools/search/tavily-scraper.d.ts +2 -0
- package/dist/types/tools/search/types.d.ts +28 -33
- package/dist/types/tools/subagent/SubagentExecutor.d.ts +44 -0
- package/dist/types/types/graph.d.ts +7 -1
- package/dist/types/types/run.d.ts +46 -1
- package/dist/types/types/tools.d.ts +21 -0
- package/dist/types/utils/index.d.ts +1 -0
- package/dist/types/utils/misc.d.ts +7 -0
- package/dist/types/utils/proxy.d.ts +31 -0
- package/package.json +2 -1
- package/src/__tests__/stream.eagerArgsDivergence.test.ts +158 -0
- package/src/__tests__/stream.eagerEventExecution.test.ts +1 -0
- package/src/__tests__/stream.streamLimits.test.ts +1982 -0
- package/src/graphs/Graph.ts +302 -27
- package/src/graphs/__tests__/Graph.breakerLifecycle.test.ts +234 -0
- package/src/index.ts +11 -0
- package/src/llm/bedrock/index.ts +22 -2
- package/src/llm/invoke.streamLimits.test.ts +142 -0
- package/src/llm/invoke.test.ts +89 -1
- package/src/llm/invoke.ts +197 -20
- package/src/llm/openai/cacheWriteTokens.test.ts +112 -0
- package/src/llm/openai/index.ts +14 -6
- package/src/llm/streamLimits.test.ts +450 -0
- package/src/llm/streamLimits.ts +1158 -0
- package/src/run.ts +4 -0
- package/src/session/AgentSession.ts +5 -0
- package/src/stream.ts +141 -6
- package/src/summarization/__tests__/node.test.ts +269 -0
- package/src/summarization/chunkHandler.test.ts +196 -0
- package/src/summarization/node.ts +203 -6
- package/src/tools/BashExecutor.ts +4 -3
- package/src/tools/CodeExecutor.ts +5 -4
- package/src/tools/ProgrammaticToolCalling.ts +7 -5
- package/src/tools/ToolNode.ts +109 -6
- package/src/tools/ToolSearch.ts +4 -3
- package/src/tools/__tests__/BashExecutor.test.ts +2 -2
- package/src/tools/__tests__/ProgrammaticToolCalling.test.ts +2 -4
- package/src/tools/__tests__/SubagentExecutor.test.ts +126 -0
- package/src/tools/__tests__/ToolNode.breakerSignal.test.ts +389 -0
- package/src/tools/__tests__/ToolNode.streamLimits.test.ts +69 -0
- package/src/tools/search/crw-scraper.ts +6 -0
- package/src/tools/search/crw-search.ts +6 -1
- package/src/tools/search/firecrawl.ts +6 -0
- package/src/tools/search/http-agent.test.ts +133 -0
- package/src/tools/search/keenable-scraper.ts +6 -0
- package/src/tools/search/keenable-search.ts +6 -1
- package/src/tools/search/rerankers.ts +36 -10
- package/src/tools/search/search.ts +29 -11
- package/src/tools/search/serper-scraper.ts +6 -0
- package/src/tools/search/tavily-scraper.ts +6 -0
- package/src/tools/search/tavily-search.ts +2 -0
- package/src/tools/search/tool.ts +16 -0
- package/src/tools/search/types.ts +31 -33
- package/src/tools/subagent/SubagentExecutor.ts +96 -3
- package/src/types/graph.ts +7 -0
- package/src/types/run.ts +49 -1
- package/src/types/tools.ts +21 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/misc.ts +19 -0
- package/src/utils/proxy.test.ts +176 -0
- package/src/utils/proxy.ts +93 -0
|
@@ -42,22 +42,28 @@ export abstract class BaseReranker {
|
|
|
42
42
|
export class JinaReranker extends BaseReranker {
|
|
43
43
|
private apiUrl: string;
|
|
44
44
|
private timeout: number;
|
|
45
|
+
private httpAgent?: t.HttpAgent;
|
|
46
|
+
private httpsAgent?: t.HttpsAgent;
|
|
45
47
|
|
|
46
48
|
constructor({
|
|
47
49
|
apiKey = process.env.JINA_API_KEY,
|
|
48
50
|
apiUrl = getDefaultJinaApiUrl(),
|
|
49
51
|
timeout = DEFAULT_RERANKER_TIMEOUT,
|
|
50
52
|
logger,
|
|
53
|
+
httpAgent,
|
|
54
|
+
httpsAgent,
|
|
51
55
|
}: {
|
|
52
56
|
apiKey?: string;
|
|
53
57
|
apiUrl?: string;
|
|
54
58
|
timeout?: number;
|
|
55
59
|
logger?: t.Logger;
|
|
56
|
-
}) {
|
|
60
|
+
} & t.HttpAgentConfig) {
|
|
57
61
|
super(logger);
|
|
58
62
|
this.apiKey = apiKey;
|
|
59
63
|
this.apiUrl = apiUrl;
|
|
60
64
|
this.timeout = timeout;
|
|
65
|
+
this.httpAgent = httpAgent;
|
|
66
|
+
this.httpsAgent = httpsAgent;
|
|
61
67
|
}
|
|
62
68
|
|
|
63
69
|
async rerank(
|
|
@@ -92,6 +98,8 @@ export class JinaReranker extends BaseReranker {
|
|
|
92
98
|
Authorization: `Bearer ${this.apiKey}`,
|
|
93
99
|
},
|
|
94
100
|
timeout: this.timeout,
|
|
101
|
+
httpAgent: this.httpAgent,
|
|
102
|
+
httpsAgent: this.httpsAgent,
|
|
95
103
|
}
|
|
96
104
|
);
|
|
97
105
|
|
|
@@ -135,19 +143,25 @@ export class JinaReranker extends BaseReranker {
|
|
|
135
143
|
|
|
136
144
|
export class CohereReranker extends BaseReranker {
|
|
137
145
|
private timeout: number;
|
|
146
|
+
private httpAgent?: t.HttpAgent;
|
|
147
|
+
private httpsAgent?: t.HttpsAgent;
|
|
138
148
|
|
|
139
149
|
constructor({
|
|
140
150
|
apiKey = process.env.COHERE_API_KEY,
|
|
141
151
|
timeout = DEFAULT_RERANKER_TIMEOUT,
|
|
142
152
|
logger,
|
|
153
|
+
httpAgent,
|
|
154
|
+
httpsAgent,
|
|
143
155
|
}: {
|
|
144
156
|
apiKey?: string;
|
|
145
157
|
timeout?: number;
|
|
146
158
|
logger?: t.Logger;
|
|
147
|
-
}) {
|
|
159
|
+
} & t.HttpAgentConfig) {
|
|
148
160
|
super(logger);
|
|
149
161
|
this.apiKey = apiKey;
|
|
150
162
|
this.timeout = timeout;
|
|
163
|
+
this.httpAgent = httpAgent;
|
|
164
|
+
this.httpsAgent = httpsAgent;
|
|
151
165
|
}
|
|
152
166
|
|
|
153
167
|
async rerank(
|
|
@@ -179,6 +193,8 @@ export class CohereReranker extends BaseReranker {
|
|
|
179
193
|
Authorization: `Bearer ${this.apiKey}`,
|
|
180
194
|
},
|
|
181
195
|
timeout: this.timeout,
|
|
196
|
+
httpAgent: this.httpAgent,
|
|
197
|
+
httpsAgent: this.httpsAgent,
|
|
182
198
|
}
|
|
183
199
|
);
|
|
184
200
|
|
|
@@ -231,14 +247,16 @@ export class InfinityReranker extends BaseReranker {
|
|
|
231
247
|
/**
|
|
232
248
|
* Creates the appropriate reranker based on type and configuration
|
|
233
249
|
*/
|
|
234
|
-
export const createReranker = (
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
250
|
+
export const createReranker = (
|
|
251
|
+
config: {
|
|
252
|
+
rerankerType: t.RerankerType;
|
|
253
|
+
jinaApiKey?: string;
|
|
254
|
+
jinaApiUrl?: string;
|
|
255
|
+
cohereApiKey?: string;
|
|
256
|
+
rerankerTimeout?: number;
|
|
257
|
+
logger?: t.Logger;
|
|
258
|
+
} & t.HttpAgentConfig
|
|
259
|
+
): BaseReranker | undefined => {
|
|
242
260
|
const {
|
|
243
261
|
rerankerType,
|
|
244
262
|
jinaApiKey,
|
|
@@ -246,6 +264,8 @@ export const createReranker = (config: {
|
|
|
246
264
|
cohereApiKey,
|
|
247
265
|
rerankerTimeout,
|
|
248
266
|
logger,
|
|
267
|
+
httpAgent,
|
|
268
|
+
httpsAgent,
|
|
249
269
|
} = config;
|
|
250
270
|
|
|
251
271
|
// Create a default logger if none is provided
|
|
@@ -258,12 +278,16 @@ export const createReranker = (config: {
|
|
|
258
278
|
apiUrl: jinaApiUrl,
|
|
259
279
|
timeout: rerankerTimeout,
|
|
260
280
|
logger: defaultLogger,
|
|
281
|
+
httpAgent,
|
|
282
|
+
httpsAgent,
|
|
261
283
|
});
|
|
262
284
|
case 'cohere':
|
|
263
285
|
return new CohereReranker({
|
|
264
286
|
apiKey: cohereApiKey,
|
|
265
287
|
timeout: rerankerTimeout,
|
|
266
288
|
logger: defaultLogger,
|
|
289
|
+
httpAgent,
|
|
290
|
+
httpsAgent,
|
|
267
291
|
});
|
|
268
292
|
case 'infinity':
|
|
269
293
|
return new InfinityReranker(defaultLogger);
|
|
@@ -279,6 +303,8 @@ export const createReranker = (config: {
|
|
|
279
303
|
apiUrl: jinaApiUrl,
|
|
280
304
|
timeout: rerankerTimeout,
|
|
281
305
|
logger: defaultLogger,
|
|
306
|
+
httpAgent,
|
|
307
|
+
httpsAgent,
|
|
282
308
|
});
|
|
283
309
|
}
|
|
284
310
|
};
|
|
@@ -185,7 +185,8 @@ const getHighlights = async ({
|
|
|
185
185
|
};
|
|
186
186
|
|
|
187
187
|
const createSerperAPI = (
|
|
188
|
-
apiKey?: string
|
|
188
|
+
apiKey?: string,
|
|
189
|
+
agents?: t.HttpAgentConfig
|
|
189
190
|
): {
|
|
190
191
|
getSources: (params: t.GetSourcesParams) => Promise<t.SearchResult>;
|
|
191
192
|
} => {
|
|
@@ -251,6 +252,8 @@ const createSerperAPI = (
|
|
|
251
252
|
'Content-Type': 'application/json',
|
|
252
253
|
},
|
|
253
254
|
timeout: config.timeout,
|
|
255
|
+
httpAgent: agents?.httpAgent,
|
|
256
|
+
httpsAgent: agents?.httpsAgent,
|
|
254
257
|
}
|
|
255
258
|
);
|
|
256
259
|
|
|
@@ -280,7 +283,8 @@ const createSerperAPI = (
|
|
|
280
283
|
|
|
281
284
|
const createSearXNGAPI = (
|
|
282
285
|
instanceUrl?: string,
|
|
283
|
-
apiKey?: string
|
|
286
|
+
apiKey?: string,
|
|
287
|
+
agents?: t.HttpAgentConfig
|
|
284
288
|
): {
|
|
285
289
|
getSources: (params: t.GetSourcesParams) => Promise<t.SearchResult>;
|
|
286
290
|
} => {
|
|
@@ -349,6 +353,8 @@ const createSearXNGAPI = (
|
|
|
349
353
|
headers,
|
|
350
354
|
params,
|
|
351
355
|
timeout: config.timeout,
|
|
356
|
+
httpAgent: agents?.httpAgent,
|
|
357
|
+
httpsAgent: agents?.httpsAgent,
|
|
352
358
|
});
|
|
353
359
|
|
|
354
360
|
const data = response.data;
|
|
@@ -493,22 +499,34 @@ export const createSearchAPI = (
|
|
|
493
499
|
crwApiKey,
|
|
494
500
|
crwApiUrl,
|
|
495
501
|
crwSearchOptions,
|
|
502
|
+
httpAgent,
|
|
503
|
+
httpsAgent,
|
|
496
504
|
} = config;
|
|
497
505
|
|
|
506
|
+
const agents: t.HttpAgentConfig = { httpAgent, httpsAgent };
|
|
507
|
+
|
|
498
508
|
if (searchProvider.toLowerCase() === 'serper') {
|
|
499
|
-
return createSerperAPI(serperApiKey);
|
|
509
|
+
return createSerperAPI(serperApiKey, agents);
|
|
500
510
|
} else if (searchProvider.toLowerCase() === 'searxng') {
|
|
501
|
-
return createSearXNGAPI(searxngInstanceUrl, searxngApiKey);
|
|
511
|
+
return createSearXNGAPI(searxngInstanceUrl, searxngApiKey, agents);
|
|
502
512
|
} else if (searchProvider.toLowerCase() === 'tavily') {
|
|
503
|
-
return createTavilyAPI(tavilyApiKey, tavilySearchUrl,
|
|
513
|
+
return createTavilyAPI(tavilyApiKey, tavilySearchUrl, {
|
|
514
|
+
...tavilySearchOptions,
|
|
515
|
+
httpAgent: httpAgent ?? tavilySearchOptions?.httpAgent,
|
|
516
|
+
httpsAgent: httpsAgent ?? tavilySearchOptions?.httpsAgent,
|
|
517
|
+
});
|
|
504
518
|
} else if (searchProvider.toLowerCase() === 'keenable') {
|
|
505
|
-
return createKeenableAPI(
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
keenableSearchOptions
|
|
509
|
-
);
|
|
519
|
+
return createKeenableAPI(keenableApiKey, keenableApiUrl, {
|
|
520
|
+
...keenableSearchOptions,
|
|
521
|
+
httpAgent: httpAgent ?? keenableSearchOptions?.httpAgent,
|
|
522
|
+
httpsAgent: httpsAgent ?? keenableSearchOptions?.httpsAgent,
|
|
523
|
+
});
|
|
510
524
|
} else if (searchProvider.toLowerCase() === 'crw') {
|
|
511
|
-
return createCrwAPI(crwApiKey, crwApiUrl,
|
|
525
|
+
return createCrwAPI(crwApiKey, crwApiUrl, {
|
|
526
|
+
...crwSearchOptions,
|
|
527
|
+
httpAgent: httpAgent ?? crwSearchOptions?.httpAgent,
|
|
528
|
+
httpsAgent: httpsAgent ?? crwSearchOptions?.httpsAgent,
|
|
529
|
+
});
|
|
512
530
|
} else {
|
|
513
531
|
throw new Error(
|
|
514
532
|
`Invalid search provider: ${searchProvider}. Must be 'serper', 'searxng', 'tavily', 'keenable', or 'crw'`
|
|
@@ -33,6 +33,8 @@ export class SerperScraper implements t.BaseScraper {
|
|
|
33
33
|
private timeout: number;
|
|
34
34
|
private logger: t.Logger;
|
|
35
35
|
private includeMarkdown: boolean;
|
|
36
|
+
private httpAgent?: t.HttpAgent;
|
|
37
|
+
private httpsAgent?: t.HttpsAgent;
|
|
36
38
|
|
|
37
39
|
constructor(config: t.SerperScraperConfig = {}) {
|
|
38
40
|
this.apiKey = config.apiKey ?? process.env.SERPER_API_KEY ?? '';
|
|
@@ -44,6 +46,8 @@ export class SerperScraper implements t.BaseScraper {
|
|
|
44
46
|
|
|
45
47
|
this.timeout = config.timeout ?? 7500;
|
|
46
48
|
this.includeMarkdown = config.includeMarkdown ?? true;
|
|
49
|
+
this.httpAgent = config.httpAgent;
|
|
50
|
+
this.httpsAgent = config.httpsAgent;
|
|
47
51
|
|
|
48
52
|
this.logger = config.logger || createDefaultLogger();
|
|
49
53
|
|
|
@@ -88,6 +92,8 @@ export class SerperScraper implements t.BaseScraper {
|
|
|
88
92
|
'Content-Type': 'application/json',
|
|
89
93
|
},
|
|
90
94
|
timeout: options.timeout ?? this.timeout,
|
|
95
|
+
httpAgent: this.httpAgent,
|
|
96
|
+
httpsAgent: this.httpsAgent,
|
|
91
97
|
});
|
|
92
98
|
|
|
93
99
|
return [url, { success: true, data: response.data }];
|
|
@@ -45,6 +45,8 @@ export class TavilyScraper implements t.BaseScraper {
|
|
|
45
45
|
private includeImages: boolean;
|
|
46
46
|
private includeFavicon: boolean;
|
|
47
47
|
private format: 'markdown' | 'text' | undefined;
|
|
48
|
+
private httpAgent?: t.HttpAgent;
|
|
49
|
+
private httpsAgent?: t.HttpsAgent;
|
|
48
50
|
|
|
49
51
|
constructor(config: t.TavilyScraperConfig = {}) {
|
|
50
52
|
this.apiKey = config.apiKey ?? process.env.TAVILY_API_KEY ?? '';
|
|
@@ -58,6 +60,8 @@ export class TavilyScraper implements t.BaseScraper {
|
|
|
58
60
|
this.includeImages = config.includeImages ?? false;
|
|
59
61
|
this.includeFavicon = config.includeFavicon ?? false;
|
|
60
62
|
this.format = config.format;
|
|
63
|
+
this.httpAgent = config.httpAgent;
|
|
64
|
+
this.httpsAgent = config.httpsAgent;
|
|
61
65
|
this.logger = config.logger || createDefaultLogger();
|
|
62
66
|
|
|
63
67
|
if (!this.apiKey) {
|
|
@@ -140,6 +144,8 @@ export class TavilyScraper implements t.BaseScraper {
|
|
|
140
144
|
'Content-Type': 'application/json',
|
|
141
145
|
},
|
|
142
146
|
timeout: effectiveTimeout,
|
|
147
|
+
httpAgent: this.httpAgent,
|
|
148
|
+
httpsAgent: this.httpsAgent,
|
|
143
149
|
});
|
|
144
150
|
|
|
145
151
|
const data = response.data;
|
package/src/tools/search/tool.ts
CHANGED
|
@@ -452,6 +452,8 @@ export const createSearchTool = (
|
|
|
452
452
|
jinaApiKey,
|
|
453
453
|
jinaApiUrl,
|
|
454
454
|
cohereApiKey,
|
|
455
|
+
httpAgent,
|
|
456
|
+
httpsAgent,
|
|
455
457
|
onSearchResults: _onSearchResults,
|
|
456
458
|
onGetHighlights,
|
|
457
459
|
} = config;
|
|
@@ -498,6 +500,8 @@ export const createSearchTool = (
|
|
|
498
500
|
crwApiKey,
|
|
499
501
|
crwApiUrl,
|
|
500
502
|
crwSearchOptions,
|
|
503
|
+
httpAgent,
|
|
504
|
+
httpsAgent,
|
|
501
505
|
});
|
|
502
506
|
|
|
503
507
|
/** Create scraper based on scraperProvider */
|
|
@@ -508,6 +512,8 @@ export const createSearchTool = (
|
|
|
508
512
|
...serperScraperOptions,
|
|
509
513
|
apiKey: serperApiKey,
|
|
510
514
|
timeout: scraperTimeout ?? serperScraperOptions?.timeout,
|
|
515
|
+
httpAgent: httpAgent ?? serperScraperOptions?.httpAgent,
|
|
516
|
+
httpsAgent: httpsAgent ?? serperScraperOptions?.httpsAgent,
|
|
511
517
|
logger,
|
|
512
518
|
});
|
|
513
519
|
} else if (scraperProvider === 'tavily') {
|
|
@@ -519,6 +525,8 @@ export const createSearchTool = (
|
|
|
519
525
|
process.env.TAVILY_API_KEY,
|
|
520
526
|
apiUrl: tavilyScraperOptions?.apiUrl ?? tavilyExtractUrl,
|
|
521
527
|
timeout: scraperTimeout ?? tavilyScraperOptions?.timeout,
|
|
528
|
+
httpAgent: httpAgent ?? tavilyScraperOptions?.httpAgent,
|
|
529
|
+
httpsAgent: httpsAgent ?? tavilyScraperOptions?.httpsAgent,
|
|
522
530
|
logger,
|
|
523
531
|
});
|
|
524
532
|
} else if (scraperProvider === 'crw') {
|
|
@@ -528,6 +536,8 @@ export const createSearchTool = (
|
|
|
528
536
|
apiUrl: crwScraperOptions?.apiUrl ?? crwApiUrl,
|
|
529
537
|
timeout: scraperTimeout ?? crwScraperOptions?.timeout,
|
|
530
538
|
formats: crwScraperOptions?.formats ?? ['markdown', 'rawHtml'],
|
|
539
|
+
httpAgent: httpAgent ?? crwScraperOptions?.httpAgent,
|
|
540
|
+
httpsAgent: httpsAgent ?? crwScraperOptions?.httpsAgent,
|
|
531
541
|
logger,
|
|
532
542
|
});
|
|
533
543
|
} else if (scraperProvider === 'keenable') {
|
|
@@ -538,6 +548,8 @@ export const createSearchTool = (
|
|
|
538
548
|
attributionTitle:
|
|
539
549
|
keenableScraperOptions?.attributionTitle ??
|
|
540
550
|
keenableSearchOptions?.attributionTitle,
|
|
551
|
+
httpAgent: httpAgent ?? keenableScraperOptions?.httpAgent,
|
|
552
|
+
httpsAgent: httpsAgent ?? keenableScraperOptions?.httpsAgent,
|
|
541
553
|
logger,
|
|
542
554
|
});
|
|
543
555
|
} else {
|
|
@@ -548,6 +560,8 @@ export const createSearchTool = (
|
|
|
548
560
|
version: firecrawlVersion,
|
|
549
561
|
timeout: scraperTimeout ?? firecrawlOptions?.timeout,
|
|
550
562
|
formats: firecrawlOptions?.formats ?? ['markdown', 'rawHtml'],
|
|
563
|
+
httpAgent: httpAgent ?? firecrawlOptions?.httpAgent,
|
|
564
|
+
httpsAgent: httpsAgent ?? firecrawlOptions?.httpsAgent,
|
|
551
565
|
logger,
|
|
552
566
|
});
|
|
553
567
|
}
|
|
@@ -558,6 +572,8 @@ export const createSearchTool = (
|
|
|
558
572
|
jinaApiUrl,
|
|
559
573
|
cohereApiKey,
|
|
560
574
|
rerankerTimeout,
|
|
575
|
+
httpAgent,
|
|
576
|
+
httpsAgent,
|
|
561
577
|
logger,
|
|
562
578
|
});
|
|
563
579
|
|
|
@@ -1,8 +1,25 @@
|
|
|
1
1
|
import type { RunnableConfig } from '@langchain/core/runnables';
|
|
2
2
|
import type { Logger as WinstonLogger } from 'winston';
|
|
3
|
+
import type { Agent as HttpsAgent } from 'https';
|
|
4
|
+
import type { Agent as HttpAgent } from 'http';
|
|
3
5
|
import type { BaseReranker } from './rerankers';
|
|
4
6
|
import { DATE_RANGE } from './schema';
|
|
5
7
|
|
|
8
|
+
export type { HttpAgent, HttpsAgent };
|
|
9
|
+
|
|
10
|
+
export interface HttpAgentConfig {
|
|
11
|
+
httpAgent?: HttpAgent;
|
|
12
|
+
httpsAgent?: HttpsAgent;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Transport and credential fields shared by every provider scraper config. */
|
|
16
|
+
export interface BaseSearchProviderConfig extends HttpAgentConfig {
|
|
17
|
+
apiKey?: string;
|
|
18
|
+
apiUrl?: string;
|
|
19
|
+
timeout?: number;
|
|
20
|
+
logger?: Logger;
|
|
21
|
+
}
|
|
22
|
+
|
|
6
23
|
export type SearchProvider =
|
|
7
24
|
| 'serper'
|
|
8
25
|
| 'searxng'
|
|
@@ -81,7 +98,7 @@ export type TavilyTimeRangeInput =
|
|
|
81
98
|
| 'm'
|
|
82
99
|
| 'y';
|
|
83
100
|
|
|
84
|
-
export interface TavilySearchOptions {
|
|
101
|
+
export interface TavilySearchOptions extends HttpAgentConfig {
|
|
85
102
|
searchDepth?: 'basic' | 'advanced' | 'fast' | 'ultra-fast';
|
|
86
103
|
maxResults?: number;
|
|
87
104
|
includeImages?: boolean;
|
|
@@ -116,7 +133,7 @@ export interface TavilySearchPayload {
|
|
|
116
133
|
chunks_per_source?: number;
|
|
117
134
|
}
|
|
118
135
|
|
|
119
|
-
export interface CrwSearchOptions {
|
|
136
|
+
export interface CrwSearchOptions extends HttpAgentConfig {
|
|
120
137
|
/** Max results to request (maps to `limit`; clamped 1..20). */
|
|
121
138
|
maxResults?: number;
|
|
122
139
|
/** Add 'images' to the sources array. */
|
|
@@ -164,7 +181,7 @@ export interface CrwSearchResponse {
|
|
|
164
181
|
error_code?: string;
|
|
165
182
|
}
|
|
166
183
|
|
|
167
|
-
export interface SearchConfig {
|
|
184
|
+
export interface SearchConfig extends HttpAgentConfig {
|
|
168
185
|
searchProvider?: SearchProvider;
|
|
169
186
|
serperApiKey?: string;
|
|
170
187
|
searxngInstanceUrl?: string;
|
|
@@ -181,7 +198,7 @@ export interface SearchConfig {
|
|
|
181
198
|
crwSearchOptions?: CrwSearchOptions;
|
|
182
199
|
}
|
|
183
200
|
|
|
184
|
-
export interface KeenableSearchOptions {
|
|
201
|
+
export interface KeenableSearchOptions extends HttpAgentConfig {
|
|
185
202
|
maxResults?: number;
|
|
186
203
|
/** Restrict results to a single domain, e.g. "github.com". */
|
|
187
204
|
site?: string;
|
|
@@ -208,20 +225,17 @@ export interface KeenableSearchResponse {
|
|
|
208
225
|
results?: KeenableSearchResult[];
|
|
209
226
|
}
|
|
210
227
|
|
|
211
|
-
export interface KeenableScraperConfig {
|
|
212
|
-
apiKey?: string;
|
|
228
|
+
export interface KeenableScraperConfig extends BaseSearchProviderConfig {
|
|
213
229
|
/** Override the fetch endpoint base (default: public keyless, keyed when a
|
|
214
230
|
* key is set). Env fallback: KEENABLE_FETCH_URL. */
|
|
215
231
|
apiUrl?: string;
|
|
216
|
-
timeout?: number;
|
|
217
|
-
logger?: Logger;
|
|
218
232
|
/** Sent as the X-Keenable-Title attribution header. Defaults to "LibreChat". */
|
|
219
233
|
attributionTitle?: string;
|
|
220
234
|
}
|
|
221
235
|
|
|
222
236
|
export type KeenableScrapeOptions = Omit<
|
|
223
237
|
KeenableScraperConfig,
|
|
224
|
-
'apiKey' | 'apiUrl' | 'logger'
|
|
238
|
+
'apiKey' | 'apiUrl' | 'logger' | 'httpAgent' | 'httpsAgent'
|
|
225
239
|
>;
|
|
226
240
|
|
|
227
241
|
/** Raw JSON shape returned by GET /v1/fetch{,/public}?url=... */
|
|
@@ -287,19 +301,11 @@ export interface FirecrawlConfig {
|
|
|
287
301
|
firecrawlOptions?: FirecrawlScraperConfig;
|
|
288
302
|
}
|
|
289
303
|
|
|
290
|
-
export interface SerperScraperConfig {
|
|
291
|
-
apiKey?: string;
|
|
292
|
-
apiUrl?: string;
|
|
293
|
-
timeout?: number;
|
|
294
|
-
logger?: Logger;
|
|
304
|
+
export interface SerperScraperConfig extends BaseSearchProviderConfig {
|
|
295
305
|
includeMarkdown?: boolean;
|
|
296
306
|
}
|
|
297
307
|
|
|
298
|
-
export interface TavilyScraperConfig {
|
|
299
|
-
apiKey?: string;
|
|
300
|
-
apiUrl?: string;
|
|
301
|
-
timeout?: number;
|
|
302
|
-
logger?: Logger;
|
|
308
|
+
export interface TavilyScraperConfig extends BaseSearchProviderConfig {
|
|
303
309
|
extractDepth?: 'basic' | 'advanced';
|
|
304
310
|
includeImages?: boolean;
|
|
305
311
|
includeFavicon?: boolean;
|
|
@@ -421,15 +427,11 @@ export interface BaseScraper {
|
|
|
421
427
|
/** Firecrawl */
|
|
422
428
|
export type FirecrawlScrapeOptions = Omit<
|
|
423
429
|
FirecrawlScraperConfig,
|
|
424
|
-
'apiKey' | 'apiUrl' | 'version' | 'logger'
|
|
430
|
+
'apiKey' | 'apiUrl' | 'version' | 'logger' | 'httpAgent' | 'httpsAgent'
|
|
425
431
|
>;
|
|
426
432
|
|
|
427
|
-
export interface CrwScraperConfig {
|
|
428
|
-
apiKey?: string;
|
|
429
|
-
apiUrl?: string;
|
|
433
|
+
export interface CrwScraperConfig extends BaseSearchProviderConfig {
|
|
430
434
|
formats?: string[];
|
|
431
|
-
timeout?: number;
|
|
432
|
-
logger?: Logger;
|
|
433
435
|
onlyMainContent?: boolean;
|
|
434
436
|
includeTags?: string[];
|
|
435
437
|
excludeTags?: string[];
|
|
@@ -444,17 +446,17 @@ export interface CrwScraperConfig {
|
|
|
444
446
|
|
|
445
447
|
export type CrwScrapeOptions = Omit<
|
|
446
448
|
CrwScraperConfig,
|
|
447
|
-
'apiKey' | 'apiUrl' | 'logger'
|
|
449
|
+
'apiKey' | 'apiUrl' | 'logger' | 'httpAgent' | 'httpsAgent'
|
|
448
450
|
>;
|
|
449
451
|
|
|
450
452
|
export type SerperScrapeOptions = Omit<
|
|
451
453
|
SerperScraperConfig,
|
|
452
|
-
'apiKey' | 'apiUrl' | 'logger'
|
|
454
|
+
'apiKey' | 'apiUrl' | 'logger' | 'httpAgent' | 'httpsAgent'
|
|
453
455
|
>;
|
|
454
456
|
|
|
455
457
|
export type TavilyScrapeOptions = Omit<
|
|
456
458
|
TavilyScraperConfig,
|
|
457
|
-
'apiKey' | 'apiUrl' | 'logger'
|
|
459
|
+
'apiKey' | 'apiUrl' | 'logger' | 'httpAgent' | 'httpsAgent'
|
|
458
460
|
>;
|
|
459
461
|
|
|
460
462
|
export interface TavilyExtractPayload {
|
|
@@ -620,13 +622,9 @@ export interface TavilyExtractResult {
|
|
|
620
622
|
error?: string;
|
|
621
623
|
}
|
|
622
624
|
|
|
623
|
-
export interface FirecrawlScraperConfig {
|
|
624
|
-
apiKey?: string;
|
|
625
|
-
apiUrl?: string;
|
|
625
|
+
export interface FirecrawlScraperConfig extends BaseSearchProviderConfig {
|
|
626
626
|
version?: string;
|
|
627
627
|
formats?: string[];
|
|
628
|
-
timeout?: number;
|
|
629
|
-
logger?: Logger;
|
|
630
628
|
includeTags?: string[];
|
|
631
629
|
excludeTags?: string[];
|
|
632
630
|
waitFor?: number;
|