@librechat/agents 3.1.75 → 3.1.77-dev.1
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 +22 -3
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/hitl/askUserQuestion.cjs +67 -0
- package/dist/cjs/hitl/askUserQuestion.cjs.map +1 -0
- package/dist/cjs/hooks/HookRegistry.cjs +54 -0
- package/dist/cjs/hooks/HookRegistry.cjs.map +1 -1
- package/dist/cjs/hooks/createToolPolicyHook.cjs +115 -0
- package/dist/cjs/hooks/createToolPolicyHook.cjs.map +1 -0
- package/dist/cjs/hooks/executeHooks.cjs +40 -1
- package/dist/cjs/hooks/executeHooks.cjs.map +1 -1
- package/dist/cjs/hooks/types.cjs +1 -0
- package/dist/cjs/hooks/types.cjs.map +1 -1
- package/dist/cjs/langchain/google-common.cjs +3 -0
- package/dist/cjs/langchain/google-common.cjs.map +1 -0
- package/dist/cjs/langchain/index.cjs +86 -0
- package/dist/cjs/langchain/index.cjs.map +1 -0
- package/dist/cjs/langchain/language_models/chat_models.cjs +3 -0
- package/dist/cjs/langchain/language_models/chat_models.cjs.map +1 -0
- package/dist/cjs/langchain/messages/tool.cjs +3 -0
- package/dist/cjs/langchain/messages/tool.cjs.map +1 -0
- package/dist/cjs/langchain/messages.cjs +51 -0
- package/dist/cjs/langchain/messages.cjs.map +1 -0
- package/dist/cjs/langchain/openai.cjs +3 -0
- package/dist/cjs/langchain/openai.cjs.map +1 -0
- package/dist/cjs/langchain/prompts.cjs +11 -0
- package/dist/cjs/langchain/prompts.cjs.map +1 -0
- package/dist/cjs/langchain/runnables.cjs +19 -0
- package/dist/cjs/langchain/runnables.cjs.map +1 -0
- package/dist/cjs/langchain/tools.cjs +23 -0
- package/dist/cjs/langchain/tools.cjs.map +1 -0
- package/dist/cjs/langchain/utils/env.cjs +11 -0
- package/dist/cjs/langchain/utils/env.cjs.map +1 -0
- package/dist/cjs/llm/anthropic/index.cjs +145 -52
- package/dist/cjs/llm/anthropic/index.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/types.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/utils/message_inputs.cjs +21 -14
- package/dist/cjs/llm/anthropic/utils/message_inputs.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/utils/message_outputs.cjs +84 -70
- package/dist/cjs/llm/anthropic/utils/message_outputs.cjs.map +1 -1
- package/dist/cjs/llm/bedrock/index.cjs +1 -1
- package/dist/cjs/llm/bedrock/index.cjs.map +1 -1
- package/dist/cjs/llm/bedrock/utils/message_inputs.cjs +213 -3
- package/dist/cjs/llm/bedrock/utils/message_inputs.cjs.map +1 -1
- package/dist/cjs/llm/bedrock/utils/message_outputs.cjs +2 -1
- package/dist/cjs/llm/bedrock/utils/message_outputs.cjs.map +1 -1
- package/dist/cjs/llm/google/utils/common.cjs +5 -4
- package/dist/cjs/llm/google/utils/common.cjs.map +1 -1
- package/dist/cjs/llm/openai/index.cjs +519 -655
- package/dist/cjs/llm/openai/index.cjs.map +1 -1
- package/dist/cjs/llm/openai/utils/index.cjs +20 -458
- package/dist/cjs/llm/openai/utils/index.cjs.map +1 -1
- package/dist/cjs/llm/openrouter/index.cjs +57 -175
- package/dist/cjs/llm/openrouter/index.cjs.map +1 -1
- package/dist/cjs/llm/vertexai/index.cjs +5 -3
- package/dist/cjs/llm/vertexai/index.cjs.map +1 -1
- package/dist/cjs/main.cjs +112 -3
- package/dist/cjs/main.cjs.map +1 -1
- package/dist/cjs/messages/cache.cjs +2 -1
- package/dist/cjs/messages/cache.cjs.map +1 -1
- package/dist/cjs/messages/core.cjs +7 -6
- package/dist/cjs/messages/core.cjs.map +1 -1
- package/dist/cjs/messages/format.cjs +73 -15
- package/dist/cjs/messages/format.cjs.map +1 -1
- package/dist/cjs/messages/langchain.cjs +26 -0
- package/dist/cjs/messages/langchain.cjs.map +1 -0
- package/dist/cjs/messages/prune.cjs +7 -6
- package/dist/cjs/messages/prune.cjs.map +1 -1
- package/dist/cjs/run.cjs +400 -42
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/cjs/tools/ToolNode.cjs +556 -56
- package/dist/cjs/tools/ToolNode.cjs.map +1 -1
- package/dist/cjs/tools/search/search.cjs +55 -66
- package/dist/cjs/tools/search/search.cjs.map +1 -1
- package/dist/cjs/tools/search/tavily-scraper.cjs +189 -0
- package/dist/cjs/tools/search/tavily-scraper.cjs.map +1 -0
- package/dist/cjs/tools/search/tavily-search.cjs +372 -0
- package/dist/cjs/tools/search/tavily-search.cjs.map +1 -0
- package/dist/cjs/tools/search/tool.cjs +26 -4
- package/dist/cjs/tools/search/tool.cjs.map +1 -1
- package/dist/cjs/tools/search/utils.cjs +10 -3
- package/dist/cjs/tools/search/utils.cjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +22 -3
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/hitl/askUserQuestion.mjs +65 -0
- package/dist/esm/hitl/askUserQuestion.mjs.map +1 -0
- package/dist/esm/hooks/HookRegistry.mjs +54 -0
- package/dist/esm/hooks/HookRegistry.mjs.map +1 -1
- package/dist/esm/hooks/createToolPolicyHook.mjs +113 -0
- package/dist/esm/hooks/createToolPolicyHook.mjs.map +1 -0
- package/dist/esm/hooks/executeHooks.mjs +40 -1
- package/dist/esm/hooks/executeHooks.mjs.map +1 -1
- package/dist/esm/hooks/types.mjs +1 -0
- package/dist/esm/hooks/types.mjs.map +1 -1
- package/dist/esm/langchain/google-common.mjs +2 -0
- package/dist/esm/langchain/google-common.mjs.map +1 -0
- package/dist/esm/langchain/index.mjs +5 -0
- package/dist/esm/langchain/index.mjs.map +1 -0
- package/dist/esm/langchain/language_models/chat_models.mjs +2 -0
- package/dist/esm/langchain/language_models/chat_models.mjs.map +1 -0
- package/dist/esm/langchain/messages/tool.mjs +2 -0
- package/dist/esm/langchain/messages/tool.mjs.map +1 -0
- package/dist/esm/langchain/messages.mjs +2 -0
- package/dist/esm/langchain/messages.mjs.map +1 -0
- package/dist/esm/langchain/openai.mjs +2 -0
- package/dist/esm/langchain/openai.mjs.map +1 -0
- package/dist/esm/langchain/prompts.mjs +2 -0
- package/dist/esm/langchain/prompts.mjs.map +1 -0
- package/dist/esm/langchain/runnables.mjs +2 -0
- package/dist/esm/langchain/runnables.mjs.map +1 -0
- package/dist/esm/langchain/tools.mjs +2 -0
- package/dist/esm/langchain/tools.mjs.map +1 -0
- package/dist/esm/langchain/utils/env.mjs +2 -0
- package/dist/esm/langchain/utils/env.mjs.map +1 -0
- package/dist/esm/llm/anthropic/index.mjs +146 -54
- package/dist/esm/llm/anthropic/index.mjs.map +1 -1
- package/dist/esm/llm/anthropic/types.mjs.map +1 -1
- package/dist/esm/llm/anthropic/utils/message_inputs.mjs +21 -14
- package/dist/esm/llm/anthropic/utils/message_inputs.mjs.map +1 -1
- package/dist/esm/llm/anthropic/utils/message_outputs.mjs +84 -71
- package/dist/esm/llm/anthropic/utils/message_outputs.mjs.map +1 -1
- package/dist/esm/llm/bedrock/index.mjs +1 -1
- package/dist/esm/llm/bedrock/index.mjs.map +1 -1
- package/dist/esm/llm/bedrock/utils/message_inputs.mjs +214 -4
- package/dist/esm/llm/bedrock/utils/message_inputs.mjs.map +1 -1
- package/dist/esm/llm/bedrock/utils/message_outputs.mjs +2 -1
- package/dist/esm/llm/bedrock/utils/message_outputs.mjs.map +1 -1
- package/dist/esm/llm/google/utils/common.mjs +5 -4
- package/dist/esm/llm/google/utils/common.mjs.map +1 -1
- package/dist/esm/llm/openai/index.mjs +520 -656
- package/dist/esm/llm/openai/index.mjs.map +1 -1
- package/dist/esm/llm/openai/utils/index.mjs +23 -459
- package/dist/esm/llm/openai/utils/index.mjs.map +1 -1
- package/dist/esm/llm/openrouter/index.mjs +57 -175
- package/dist/esm/llm/openrouter/index.mjs.map +1 -1
- package/dist/esm/llm/vertexai/index.mjs +5 -3
- package/dist/esm/llm/vertexai/index.mjs.map +1 -1
- package/dist/esm/main.mjs +7 -0
- package/dist/esm/main.mjs.map +1 -1
- package/dist/esm/messages/cache.mjs +2 -1
- package/dist/esm/messages/cache.mjs.map +1 -1
- package/dist/esm/messages/core.mjs +7 -6
- package/dist/esm/messages/core.mjs.map +1 -1
- package/dist/esm/messages/format.mjs +73 -15
- package/dist/esm/messages/format.mjs.map +1 -1
- package/dist/esm/messages/langchain.mjs +23 -0
- package/dist/esm/messages/langchain.mjs.map +1 -0
- package/dist/esm/messages/prune.mjs +7 -6
- package/dist/esm/messages/prune.mjs.map +1 -1
- package/dist/esm/run.mjs +400 -42
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/tools/ToolNode.mjs +557 -57
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/esm/tools/search/search.mjs +55 -66
- package/dist/esm/tools/search/search.mjs.map +1 -1
- package/dist/esm/tools/search/tavily-scraper.mjs +186 -0
- package/dist/esm/tools/search/tavily-scraper.mjs.map +1 -0
- package/dist/esm/tools/search/tavily-search.mjs +370 -0
- package/dist/esm/tools/search/tavily-search.mjs.map +1 -0
- package/dist/esm/tools/search/tool.mjs +26 -4
- package/dist/esm/tools/search/tool.mjs.map +1 -1
- package/dist/esm/tools/search/utils.mjs +10 -3
- package/dist/esm/tools/search/utils.mjs.map +1 -1
- package/dist/types/graphs/Graph.d.ts +7 -0
- package/dist/types/hitl/askUserQuestion.d.ts +55 -0
- package/dist/types/hitl/index.d.ts +6 -0
- package/dist/types/hooks/HookRegistry.d.ts +58 -0
- package/dist/types/hooks/createToolPolicyHook.d.ts +87 -0
- package/dist/types/hooks/index.d.ts +4 -1
- package/dist/types/hooks/types.d.ts +109 -3
- package/dist/types/index.d.ts +10 -0
- package/dist/types/langchain/google-common.d.ts +1 -0
- package/dist/types/langchain/index.d.ts +8 -0
- package/dist/types/langchain/language_models/chat_models.d.ts +1 -0
- package/dist/types/langchain/messages/tool.d.ts +1 -0
- package/dist/types/langchain/messages.d.ts +2 -0
- package/dist/types/langchain/openai.d.ts +1 -0
- package/dist/types/langchain/prompts.d.ts +1 -0
- package/dist/types/langchain/runnables.d.ts +2 -0
- package/dist/types/langchain/tools.d.ts +2 -0
- package/dist/types/langchain/utils/env.d.ts +1 -0
- package/dist/types/llm/anthropic/index.d.ts +22 -9
- package/dist/types/llm/anthropic/types.d.ts +5 -1
- package/dist/types/llm/anthropic/utils/message_outputs.d.ts +13 -6
- package/dist/types/llm/anthropic/utils/output_parsers.d.ts +1 -1
- package/dist/types/llm/openai/index.d.ts +21 -24
- package/dist/types/llm/openrouter/index.d.ts +11 -9
- package/dist/types/llm/vertexai/index.d.ts +1 -0
- package/dist/types/messages/cache.d.ts +4 -1
- package/dist/types/messages/format.d.ts +4 -1
- package/dist/types/messages/langchain.d.ts +27 -0
- package/dist/types/run.d.ts +117 -1
- package/dist/types/tools/ToolNode.d.ts +26 -1
- package/dist/types/tools/search/tavily-scraper.d.ts +19 -0
- package/dist/types/tools/search/tavily-search.d.ts +4 -0
- package/dist/types/tools/search/types.d.ts +99 -5
- package/dist/types/tools/search/utils.d.ts +2 -2
- package/dist/types/types/graph.d.ts +23 -37
- package/dist/types/types/hitl.d.ts +272 -0
- package/dist/types/types/index.d.ts +1 -0
- package/dist/types/types/llm.d.ts +3 -3
- package/dist/types/types/run.d.ts +33 -0
- package/dist/types/types/stream.d.ts +1 -1
- package/dist/types/types/tools.d.ts +19 -0
- package/package.json +80 -17
- package/src/graphs/Graph.ts +33 -4
- package/src/graphs/__tests__/composition.smoke.test.ts +188 -0
- package/src/hitl/askUserQuestion.ts +72 -0
- package/src/hitl/index.ts +7 -0
- package/src/hooks/HookRegistry.ts +71 -0
- package/src/hooks/__tests__/createToolPolicyHook.test.ts +259 -0
- package/src/hooks/createToolPolicyHook.ts +184 -0
- package/src/hooks/executeHooks.ts +50 -1
- package/src/hooks/index.ts +6 -0
- package/src/hooks/types.ts +112 -0
- package/src/index.ts +22 -0
- package/src/langchain/google-common.ts +1 -0
- package/src/langchain/index.ts +8 -0
- package/src/langchain/language_models/chat_models.ts +1 -0
- package/src/langchain/messages/tool.ts +5 -0
- package/src/langchain/messages.ts +21 -0
- package/src/langchain/openai.ts +1 -0
- package/src/langchain/prompts.ts +1 -0
- package/src/langchain/runnables.ts +7 -0
- package/src/langchain/tools.ts +8 -0
- package/src/langchain/utils/env.ts +1 -0
- package/src/llm/anthropic/index.ts +252 -84
- package/src/llm/anthropic/llm.spec.ts +751 -102
- package/src/llm/anthropic/types.ts +9 -1
- package/src/llm/anthropic/utils/message_inputs.ts +37 -19
- package/src/llm/anthropic/utils/message_outputs.ts +119 -101
- package/src/llm/bedrock/index.ts +2 -2
- package/src/llm/bedrock/llm.spec.ts +341 -0
- package/src/llm/bedrock/utils/message_inputs.ts +303 -4
- package/src/llm/bedrock/utils/message_outputs.ts +2 -1
- package/src/llm/custom-chat-models.smoke.test.ts +836 -0
- package/src/llm/google/llm.spec.ts +339 -57
- package/src/llm/google/utils/common.ts +53 -48
- package/src/llm/openai/contentBlocks.test.ts +346 -0
- package/src/llm/openai/index.ts +856 -833
- package/src/llm/openai/utils/index.ts +107 -78
- package/src/llm/openai/utils/messages.test.ts +159 -0
- package/src/llm/openrouter/index.ts +124 -247
- package/src/llm/openrouter/reasoning.test.ts +8 -1
- package/src/llm/vertexai/index.ts +11 -5
- package/src/llm/vertexai/llm.spec.ts +28 -1
- package/src/messages/cache.test.ts +4 -3
- package/src/messages/cache.ts +3 -2
- package/src/messages/core.ts +16 -9
- package/src/messages/format.ts +96 -16
- package/src/messages/formatAgentMessages.test.ts +166 -1
- package/src/messages/langchain.ts +39 -0
- package/src/messages/prune.ts +12 -8
- package/src/run.ts +456 -47
- package/src/scripts/caching.ts +2 -3
- package/src/specs/summarization.test.ts +51 -58
- package/src/tools/ToolNode.ts +706 -63
- package/src/tools/__tests__/hitl.test.ts +3593 -0
- package/src/tools/search/search.ts +83 -73
- package/src/tools/search/tavily-scraper.ts +235 -0
- package/src/tools/search/tavily-search.ts +424 -0
- package/src/tools/search/tavily.test.ts +965 -0
- package/src/tools/search/tool.ts +36 -26
- package/src/tools/search/types.ts +133 -8
- package/src/tools/search/utils.ts +13 -5
- package/src/types/graph.ts +32 -87
- package/src/types/hitl.ts +303 -0
- package/src/types/index.ts +1 -0
- package/src/types/llm.ts +3 -3
- package/src/types/run.ts +33 -0
- package/src/types/stream.ts +1 -1
- package/src/types/tools.ts +19 -0
- package/src/utils/llmConfig.ts +1 -6
|
@@ -1,20 +1,26 @@
|
|
|
1
1
|
import { AzureOpenAI as AzureOpenAIClient } from 'openai';
|
|
2
2
|
import { ChatXAI as OriginalChatXAI } from '@langchain/xai';
|
|
3
3
|
import { ChatGenerationChunk } from '@langchain/core/outputs';
|
|
4
|
-
import { AIMessage } from '@langchain/core/messages';
|
|
5
4
|
import { ChatDeepSeek as OriginalChatDeepSeek } from '@langchain/deepseek';
|
|
6
5
|
import { CallbackManagerForLLMRun } from '@langchain/core/callbacks/manager';
|
|
7
6
|
import { OpenAIClient, ChatOpenAI as OriginalChatOpenAI, AzureChatOpenAI as OriginalAzureChatOpenAI } from '@langchain/openai';
|
|
8
7
|
import type { HeaderValue, HeadersLike } from './types';
|
|
9
|
-
import type { BindToolsInput } from '@langchain/core/language_models/chat_models';
|
|
10
8
|
import type { BaseMessage } from '@langchain/core/messages';
|
|
11
|
-
import type {
|
|
9
|
+
import type { BindToolsInput } from '@langchain/core/language_models/chat_models';
|
|
12
10
|
import type { ChatXAIInput } from '@langchain/xai';
|
|
13
11
|
import type * as t from '@langchain/openai';
|
|
14
12
|
export declare function isHeaders(headers: unknown): headers is Headers;
|
|
15
13
|
export declare function normalizeHeaders(headers: HeadersLike): Record<string, HeaderValue | readonly HeaderValue[]>;
|
|
16
|
-
type OpenAICompletionParam = OpenAIClient.Chat.Completions.ChatCompletionMessageParam;
|
|
17
14
|
type OpenAICoreRequestOptions = OpenAIClient.RequestOptions;
|
|
15
|
+
type LibreChatOpenAIFields = t.ChatOpenAIFields & {
|
|
16
|
+
_lc_stream_delay?: number;
|
|
17
|
+
includeReasoningContent?: boolean;
|
|
18
|
+
includeReasoningDetails?: boolean;
|
|
19
|
+
convertReasoningDetailsToContent?: boolean;
|
|
20
|
+
};
|
|
21
|
+
type LibreChatAzureOpenAIFields = t.AzureOpenAIInput & {
|
|
22
|
+
_lc_stream_delay?: number;
|
|
23
|
+
};
|
|
18
24
|
/**
|
|
19
25
|
* Formats a tool in either OpenAI format, or LangChain structured tool format
|
|
20
26
|
* into an OpenAI tool format. If the tool is already in OpenAI format, return without
|
|
@@ -41,15 +47,12 @@ export declare class CustomAzureOpenAIClient extends AzureOpenAIClient {
|
|
|
41
47
|
abortHandler?: () => void;
|
|
42
48
|
fetchWithTimeout(url: RequestInfo, init: RequestInit | undefined, ms: number, controller: AbortController): Promise<Response>;
|
|
43
49
|
}
|
|
44
|
-
/** @ts-expect-error We are intentionally overriding `getReasoningParams` */
|
|
45
50
|
export declare class ChatOpenAI extends OriginalChatOpenAI<t.ChatOpenAICallOptions> {
|
|
46
51
|
_lc_stream_delay?: number;
|
|
47
|
-
constructor(fields?:
|
|
48
|
-
_lc_stream_delay?: number;
|
|
49
|
-
} & t.OpenAIChatInput['modelKwargs']);
|
|
52
|
+
constructor(fields?: LibreChatOpenAIFields & t.OpenAIChatInput['modelKwargs']);
|
|
50
53
|
get exposedClient(): CustomOpenAIClient;
|
|
51
54
|
static lc_name(): string;
|
|
52
|
-
|
|
55
|
+
_getClientOptions(options?: OpenAICoreRequestOptions): OpenAICoreRequestOptions;
|
|
53
56
|
/**
|
|
54
57
|
* Returns backwards compatible reasoning parameters from constructor params and call options
|
|
55
58
|
* @internal
|
|
@@ -57,14 +60,10 @@ export declare class ChatOpenAI extends OriginalChatOpenAI<t.ChatOpenAICallOptio
|
|
|
57
60
|
getReasoningParams(options?: this['ParsedCallOptions']): OpenAIClient.Reasoning | undefined;
|
|
58
61
|
protected _getReasoningParams(options?: this['ParsedCallOptions']): OpenAIClient.Reasoning | undefined;
|
|
59
62
|
_streamResponseChunks(messages: BaseMessage[], options: this['ParsedCallOptions'], runManager?: CallbackManagerForLLMRun): AsyncGenerator<ChatGenerationChunk>;
|
|
60
|
-
_streamResponseChunks2(messages: BaseMessage[], options: this['ParsedCallOptions'], runManager?: CallbackManagerForLLMRun): AsyncGenerator<ChatGenerationChunk>;
|
|
61
63
|
}
|
|
62
|
-
/** @ts-expect-error We are intentionally overriding `getReasoningParams` */
|
|
63
64
|
export declare class AzureChatOpenAI extends OriginalAzureChatOpenAI {
|
|
64
65
|
_lc_stream_delay?: number;
|
|
65
|
-
constructor(fields?:
|
|
66
|
-
_lc_stream_delay?: number;
|
|
67
|
-
});
|
|
66
|
+
constructor(fields?: LibreChatAzureOpenAIFields);
|
|
68
67
|
get exposedClient(): CustomOpenAIClient;
|
|
69
68
|
static lc_name(): 'LibreChatAzureOpenAI';
|
|
70
69
|
/**
|
|
@@ -73,16 +72,17 @@ export declare class AzureChatOpenAI extends OriginalAzureChatOpenAI {
|
|
|
73
72
|
*/
|
|
74
73
|
getReasoningParams(options?: this['ParsedCallOptions']): OpenAIClient.Reasoning | undefined;
|
|
75
74
|
protected _getReasoningParams(options?: this['ParsedCallOptions']): OpenAIClient.Reasoning | undefined;
|
|
76
|
-
|
|
75
|
+
_getClientOptions(options: OpenAICoreRequestOptions | undefined): OpenAICoreRequestOptions;
|
|
77
76
|
_streamResponseChunks(messages: BaseMessage[], options: this['ParsedCallOptions'], runManager?: CallbackManagerForLLMRun): AsyncGenerator<ChatGenerationChunk>;
|
|
78
77
|
}
|
|
79
78
|
export declare class ChatDeepSeek extends OriginalChatDeepSeek {
|
|
79
|
+
_lc_stream_delay?: number;
|
|
80
|
+
constructor(fields?: ConstructorParameters<typeof OriginalChatDeepSeek>[0] & {
|
|
81
|
+
_lc_stream_delay?: number;
|
|
82
|
+
});
|
|
80
83
|
get exposedClient(): CustomOpenAIClient;
|
|
81
84
|
static lc_name(): 'LibreChatDeepSeek';
|
|
82
|
-
|
|
83
|
-
_generate(messages: BaseMessage[], options: this['ParsedCallOptions'] | undefined, runManager?: CallbackManagerForLLMRun): Promise<ChatResult>;
|
|
84
|
-
protected _convertResponseToMessage(choice: OpenAIClient.Chat.Completions.ChatCompletion.Choice, data: OpenAIClient.Chat.Completions.ChatCompletion): AIMessage;
|
|
85
|
-
protected _getClientOptions(options?: OpenAICoreRequestOptions): OpenAICoreRequestOptions;
|
|
85
|
+
_getClientOptions(options?: OpenAICoreRequestOptions): OpenAICoreRequestOptions;
|
|
86
86
|
_streamResponseChunks(messages: BaseMessage[], options: this['ParsedCallOptions'], runManager?: CallbackManagerForLLMRun): AsyncGenerator<ChatGenerationChunk>;
|
|
87
87
|
}
|
|
88
88
|
/** xAI-specific usage metadata type */
|
|
@@ -102,11 +102,8 @@ export interface XAIUsageMetadata extends OpenAIClient.Completions.CompletionUsa
|
|
|
102
102
|
num_sources_used?: number;
|
|
103
103
|
}
|
|
104
104
|
export declare class ChatMoonshot extends ChatOpenAI {
|
|
105
|
+
constructor(fields?: LibreChatOpenAIFields & t.OpenAIChatInput['modelKwargs']);
|
|
105
106
|
static lc_name(): 'LibreChatMoonshot';
|
|
106
|
-
protected _convertMessages(messages: BaseMessage[]): OpenAICompletionParam[];
|
|
107
|
-
_generate(messages: BaseMessage[], options: this['ParsedCallOptions'], runManager?: CallbackManagerForLLMRun): Promise<ChatResult>;
|
|
108
|
-
protected _convertResponseToMessage(choice: OpenAIClient.Chat.Completions.ChatCompletion.Choice, data: OpenAIClient.Chat.Completions.ChatCompletion): AIMessage;
|
|
109
|
-
_streamResponseChunks(messages: BaseMessage[], options: this['ParsedCallOptions'], runManager?: CallbackManagerForLLMRun): AsyncGenerator<ChatGenerationChunk>;
|
|
110
107
|
}
|
|
111
108
|
export declare class ChatXAI extends OriginalChatXAI {
|
|
112
109
|
_lc_stream_delay?: number;
|
|
@@ -121,7 +118,7 @@ export declare class ChatXAI extends OriginalChatXAI {
|
|
|
121
118
|
});
|
|
122
119
|
static lc_name(): 'LibreChatXAI';
|
|
123
120
|
get exposedClient(): CustomOpenAIClient;
|
|
124
|
-
|
|
121
|
+
_getClientOptions(options?: OpenAICoreRequestOptions): OpenAICoreRequestOptions;
|
|
125
122
|
_streamResponseChunks(messages: BaseMessage[], options: this['ParsedCallOptions'], runManager?: CallbackManagerForLLMRun): AsyncGenerator<ChatGenerationChunk>;
|
|
126
123
|
}
|
|
127
124
|
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ChatOpenAI } from '@/llm/openai';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import type {
|
|
2
|
+
import type { BaseMessage } from '@langchain/core/messages';
|
|
3
|
+
import type { ChatGenerationChunk } from '@langchain/core/outputs';
|
|
4
|
+
import type { CallbackManagerForLLMRun } from '@langchain/core/callbacks/manager';
|
|
5
5
|
import type { ChatOpenAICallOptions, OpenAIChatInput, OpenAIClient } from '@langchain/openai';
|
|
6
6
|
export type OpenRouterReasoningEffort = 'xhigh' | 'high' | 'medium' | 'low' | 'minimal' | 'none';
|
|
7
7
|
export interface OpenRouterReasoning {
|
|
@@ -16,20 +16,22 @@ export interface ChatOpenRouterCallOptions extends Omit<ChatOpenAICallOptions, '
|
|
|
16
16
|
reasoning?: OpenRouterReasoning;
|
|
17
17
|
modelKwargs?: OpenAIChatInput['modelKwargs'];
|
|
18
18
|
}
|
|
19
|
+
export type ChatOpenRouterInput = Partial<ChatOpenRouterCallOptions & OpenAIChatInput>;
|
|
19
20
|
/** invocationParams return type extended with OpenRouter reasoning */
|
|
20
21
|
export type OpenRouterInvocationParams = Omit<OpenAIClient.Chat.ChatCompletionCreateParams, 'messages'> & {
|
|
21
22
|
reasoning?: OpenRouterReasoning;
|
|
22
23
|
};
|
|
24
|
+
type InvocationParamsExtra = {
|
|
25
|
+
streaming?: boolean;
|
|
26
|
+
};
|
|
23
27
|
export declare class ChatOpenRouter extends ChatOpenAI {
|
|
24
28
|
private openRouterReasoning?;
|
|
25
29
|
/** @deprecated Use `reasoning` object instead */
|
|
26
30
|
private includeReasoning?;
|
|
27
|
-
constructor(_fields:
|
|
31
|
+
constructor(_fields: ChatOpenRouterInput);
|
|
28
32
|
static lc_name(): 'LibreChatOpenRouter';
|
|
29
|
-
invocationParams(options?: this['ParsedCallOptions'], extra?:
|
|
30
|
-
streaming?: boolean;
|
|
31
|
-
}): OpenRouterInvocationParams;
|
|
33
|
+
invocationParams(options?: this['ParsedCallOptions'], extra?: InvocationParamsExtra): OpenRouterInvocationParams;
|
|
32
34
|
private buildOpenRouterReasoning;
|
|
33
|
-
|
|
34
|
-
_streamResponseChunks2(messages: BaseMessage[], options: this['ParsedCallOptions'], runManager?: CallbackManagerForLLMRun): AsyncGenerator<ChatGenerationChunk>;
|
|
35
|
+
_streamResponseChunks(messages: BaseMessage[], options: this['ParsedCallOptions'], runManager?: CallbackManagerForLLMRun): AsyncGenerator<ChatGenerationChunk>;
|
|
35
36
|
}
|
|
37
|
+
export {};
|
|
@@ -288,6 +288,7 @@ export declare class ChatVertexAI extends ChatGoogle {
|
|
|
288
288
|
dynamicThinkingBudget: boolean;
|
|
289
289
|
thinkingConfig?: GoogleThinkingConfig;
|
|
290
290
|
static lc_name(): 'LibreChatVertexAI';
|
|
291
|
+
constructor(model: string, fields?: Omit<VertexAIClientOptions, 'model'>);
|
|
291
292
|
constructor(fields?: VertexAIClientOptions);
|
|
292
293
|
invocationParams(options?: this['ParsedCallOptions'] | undefined): GoogleAIModelRequestParams;
|
|
293
294
|
buildConnection(fields: VertexAIClientOptions | undefined, client: GoogleAbstractedClient): void;
|
|
@@ -36,5 +36,8 @@ export declare function stripBedrockCacheControl<T extends MessageWithContent>(m
|
|
|
36
36
|
* @param messages - The array of message objects.
|
|
37
37
|
* @returns - A new array of message objects with cache points added.
|
|
38
38
|
*/
|
|
39
|
-
export declare function addBedrockCacheControl<T extends
|
|
39
|
+
export declare function addBedrockCacheControl<T extends MessageWithContent & {
|
|
40
|
+
getType?: () => string;
|
|
41
|
+
role?: string;
|
|
42
|
+
}>(messages: T[]): T[];
|
|
40
43
|
export {};
|
|
@@ -84,6 +84,9 @@ interface LangChainMessage {
|
|
|
84
84
|
* @returns - The formatted LangChain message.
|
|
85
85
|
*/
|
|
86
86
|
export declare const formatFromLangChain: (message: LangChainMessage) => Record<string, any>;
|
|
87
|
+
interface FormatAgentMessagesOptions {
|
|
88
|
+
provider?: Providers;
|
|
89
|
+
}
|
|
87
90
|
/**
|
|
88
91
|
* Groups content parts by agent and formats them with agent labels
|
|
89
92
|
* This preprocesses multi-agent content to prevent identity confusion
|
|
@@ -107,7 +110,7 @@ export declare const labelContentByAgent: (contentParts: MessageContentComplex[]
|
|
|
107
110
|
* @param skills - Optional map of skill name to body for reconstructing skill HumanMessages.
|
|
108
111
|
* @returns - Object containing formatted messages and updated indexTokenCountMap if provided.
|
|
109
112
|
*/
|
|
110
|
-
export declare const formatAgentMessages: (payload: TPayload, indexTokenCountMap?: Record<number, number | undefined>, tools?: Set<string>, skills?: Map<string, string
|
|
113
|
+
export declare const formatAgentMessages: (payload: TPayload, indexTokenCountMap?: Record<number, number | undefined>, tools?: Set<string>, skills?: Map<string, string>, options?: FormatAgentMessagesOptions) => {
|
|
111
114
|
messages: Array<HumanMessage | AIMessage | SystemMessage | ToolMessage>;
|
|
112
115
|
indexTokenCountMap?: Record<number, number>;
|
|
113
116
|
/** Cross-run summary extracted from the payload. Should be forwarded to the
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { MessageContent } from '@langchain/core/messages';
|
|
2
|
+
import type * as t from '@/types';
|
|
3
|
+
type LibreChatMessageContent = MessageContent | string | t.MessageContentComplex[] | t.ExtendedMessageContent[];
|
|
4
|
+
type WithLangChainContent<T extends {
|
|
5
|
+
content: LibreChatMessageContent;
|
|
6
|
+
}> = Omit<T, 'content'> & {
|
|
7
|
+
content: MessageContent;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Bridges LibreChat's extended content blocks to LangChain 1.x MessageContent.
|
|
11
|
+
*
|
|
12
|
+
* LangChain 1.x narrowed message constructor types around ContentBlock, while
|
|
13
|
+
* LibreChat still carries provider-specific blocks through the same content
|
|
14
|
+
* field. This helper keeps the runtime shape unchanged during the dependency
|
|
15
|
+
* upgrade; tracking issue: https://github.com/danny-avila/agents/issues/130.
|
|
16
|
+
*/
|
|
17
|
+
export declare function toLangChainContent(content: LibreChatMessageContent): MessageContent;
|
|
18
|
+
/**
|
|
19
|
+
* Applies the same LangChain 1.x content bridge to message constructor fields.
|
|
20
|
+
*
|
|
21
|
+
* Keep this cast-only helper local to constructor boundaries so follow-up work
|
|
22
|
+
* can replace it with aligned content types or explicit conversion logic.
|
|
23
|
+
*/
|
|
24
|
+
export declare function toLangChainMessageFields<T extends {
|
|
25
|
+
content: LibreChatMessageContent;
|
|
26
|
+
}>(message: T): WithLangChainContent<T>;
|
|
27
|
+
export {};
|
package/dist/types/run.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import './instrumentation';
|
|
2
|
+
import { Command } from '@langchain/langgraph';
|
|
2
3
|
import type { MessageContentComplex, BaseMessage } from '@langchain/core/messages';
|
|
3
4
|
import type { RunnableConfig } from '@langchain/core/runnables';
|
|
4
5
|
import type * as t from '@/types';
|
|
@@ -10,6 +11,7 @@ export declare class Run<_T extends t.BaseGraphState> {
|
|
|
10
11
|
private tokenCounter?;
|
|
11
12
|
private handlerRegistry?;
|
|
12
13
|
private hookRegistry?;
|
|
14
|
+
private humanInTheLoop?;
|
|
13
15
|
private toolOutputReferences?;
|
|
14
16
|
private indexTokenCountMap?;
|
|
15
17
|
calibrationRatio: number;
|
|
@@ -18,9 +20,70 @@ export declare class Run<_T extends t.BaseGraphState> {
|
|
|
18
20
|
returnContent: boolean;
|
|
19
21
|
private skipCleanup;
|
|
20
22
|
private _streamResult;
|
|
23
|
+
/**
|
|
24
|
+
* Captured interrupt payload typed as `unknown` because the SDK
|
|
25
|
+
* does not validate the runtime shape — custom graph nodes can
|
|
26
|
+
* raise interrupts with arbitrary payloads (not just the SDK's
|
|
27
|
+
* `HumanInterruptPayload` union). The public `getInterrupt<T>()`
|
|
28
|
+
* lets callers assert the type they expect.
|
|
29
|
+
*/
|
|
30
|
+
private _interrupt;
|
|
31
|
+
private _haltedReason;
|
|
21
32
|
private constructor();
|
|
22
33
|
private createLegacyGraph;
|
|
23
34
|
private createMultiAgentGraph;
|
|
35
|
+
/**
|
|
36
|
+
* When the host opted into HITL via `humanInTheLoop: { enabled: true }`
|
|
37
|
+
* and did not supply a checkpointer, install an in-memory `MemorySaver`
|
|
38
|
+
* so `interrupt()` can persist checkpoints and `Command({ resume })`
|
|
39
|
+
* can rebuild state. The fallback is intentionally process-local:
|
|
40
|
+
* production hosts that need durable resumption across processes /
|
|
41
|
+
* restarts must provide their own checkpointer (Redis, Postgres, etc.)
|
|
42
|
+
* on `compileOptions.checkpointer`.
|
|
43
|
+
*
|
|
44
|
+
* No-op when HITL is off (the default — omitted, or
|
|
45
|
+
* `{ enabled: false }`) or the host already supplied a checkpointer
|
|
46
|
+
* of their own. See `HumanInTheLoopConfig` JSDoc for the rationale
|
|
47
|
+
* behind the default-off stance.
|
|
48
|
+
*/
|
|
49
|
+
private applyHITLCheckpointerFallback;
|
|
50
|
+
/**
|
|
51
|
+
* Run RunStart + UserPromptSubmit hooks before the graph stream
|
|
52
|
+
* begins, accumulate any `additionalContext` strings into the input
|
|
53
|
+
* messages, and short-circuit when a hook signals the run should not
|
|
54
|
+
* proceed (deny / ask decision on the prompt, or `preventContinuation`
|
|
55
|
+
* on either hook).
|
|
56
|
+
*
|
|
57
|
+
* Returns `true` when the caller should bail with `undefined` (run
|
|
58
|
+
* was halted before any model call); returns `false` to proceed
|
|
59
|
+
* into the stream loop.
|
|
60
|
+
*
|
|
61
|
+
* ## Side effects
|
|
62
|
+
*
|
|
63
|
+
* On the success path:
|
|
64
|
+
* - Mutates `stateInputs.messages` in place to append a
|
|
65
|
+
* consolidated `HumanMessage` carrying any hook
|
|
66
|
+
* `additionalContext` strings. Safe because the host owns the
|
|
67
|
+
* array and `processStream` is the only consumer until LangGraph
|
|
68
|
+
* reads it.
|
|
69
|
+
*
|
|
70
|
+
* On the halt path (returning `true`):
|
|
71
|
+
* - Sets `this._haltedReason` so callers (and the eventual host)
|
|
72
|
+
* can distinguish a hook-driven halt from a natural completion.
|
|
73
|
+
* - Calls `registry.clearSession(this.id)` and
|
|
74
|
+
* `registry.clearHaltSignal(this.id)` because no resume is
|
|
75
|
+
* expected from a pre-stream halt — the run never entered the
|
|
76
|
+
* graph, so the session/halt state for this run would otherwise
|
|
77
|
+
* leak to the next `processStream` invocation on the same
|
|
78
|
+
* registry. Other concurrent runs on the same registry are
|
|
79
|
+
* untouched (halt signals are scoped per session id).
|
|
80
|
+
* - Sets `config.callbacks = undefined` to drop the callback
|
|
81
|
+
* references the caller built (langfuse handler, custom event
|
|
82
|
+
* handler, etc.) since they won't be exercised. Mirrors the
|
|
83
|
+
* equivalent cleanup the `processStream` `finally` block does
|
|
84
|
+
* on the natural-completion path.
|
|
85
|
+
*/
|
|
86
|
+
private runPreStreamHooks;
|
|
24
87
|
static create<T extends t.BaseGraphState>(config: t.RunConfig): Promise<Run<T>>;
|
|
25
88
|
getRunMessages(): BaseMessage[] | undefined;
|
|
26
89
|
/**
|
|
@@ -37,7 +100,60 @@ export declare class Run<_T extends t.BaseGraphState> {
|
|
|
37
100
|
* and processes them through our handler registry instead of EventStreamCallbackHandler
|
|
38
101
|
*/
|
|
39
102
|
private createCustomEventCallback;
|
|
40
|
-
processStream(inputs: t.IState, callerConfig: Partial<RunnableConfig> & {
|
|
103
|
+
processStream(inputs: t.IState | Command, callerConfig: Partial<RunnableConfig> & {
|
|
104
|
+
version: 'v1' | 'v2';
|
|
105
|
+
run_id?: string;
|
|
106
|
+
}, streamOptions?: t.EventStreamOptions): Promise<MessageContentComplex[] | undefined>;
|
|
107
|
+
/**
|
|
108
|
+
* Returns the pending interrupt captured during the most recent
|
|
109
|
+
* `processStream` (or `resume`) invocation. `undefined` when the run
|
|
110
|
+
* either has not been streamed yet or completed without pausing.
|
|
111
|
+
*
|
|
112
|
+
* Hosts call this immediately after `processStream` returns to decide
|
|
113
|
+
* whether the run is awaiting human input. Persist the returned
|
|
114
|
+
* descriptor (alongside `thread_id` and the agent run config) so a
|
|
115
|
+
* later `resume(decisions)` can rebuild the run.
|
|
116
|
+
*
|
|
117
|
+
* The default `TPayload` is the SDK's `HumanInterruptPayload` union
|
|
118
|
+
* (`tool_approval` / `ask_user_question`), suitable for the common
|
|
119
|
+
* case where interrupts come from the built-in ToolNode or
|
|
120
|
+
* `askUserQuestion()` helper. Hosts that raise custom interrupts
|
|
121
|
+
* from custom graph nodes pass their own type — the SDK does not
|
|
122
|
+
* validate the runtime shape, it just transports whatever the
|
|
123
|
+
* `interrupt()` call carried. When in doubt, narrow with the
|
|
124
|
+
* `isToolApprovalInterrupt` / `isAskUserQuestionInterrupt` type
|
|
125
|
+
* guards (which accept `unknown`) before reading variant-specific
|
|
126
|
+
* fields.
|
|
127
|
+
*/
|
|
128
|
+
getInterrupt<TPayload = t.HumanInterruptPayload>(): t.RunInterruptResult<TPayload> | undefined;
|
|
129
|
+
/**
|
|
130
|
+
* Returns the reason a hook halted the run via
|
|
131
|
+
* `preventContinuation: true`, or `undefined` if no hook halted.
|
|
132
|
+
*
|
|
133
|
+
* Hosts inspect this after `processStream` returns to distinguish a
|
|
134
|
+
* natural completion (`undefined`) from a hook-driven halt (a
|
|
135
|
+
* truthy string). Independent from `getInterrupt()` — a halted run
|
|
136
|
+
* has no interrupt; an interrupted run has no halt reason.
|
|
137
|
+
*/
|
|
138
|
+
getHaltReason(): string | undefined;
|
|
139
|
+
/**
|
|
140
|
+
* Resume a paused HITL run with the value the user (or whatever
|
|
141
|
+
* decided the interrupt) supplied. The default `TResume` covers the
|
|
142
|
+
* `tool_approval` interrupt (the common case): an array of decisions
|
|
143
|
+
* in `action_requests` order, or a record keyed by `tool_call_id`.
|
|
144
|
+
*
|
|
145
|
+
* For other interrupt types (e.g., `ask_user_question` →
|
|
146
|
+
* `AskUserQuestionResolution`, or any custom interrupt a host raises
|
|
147
|
+
* from a custom node), pass the type parameter and the SDK forwards
|
|
148
|
+
* the value through unchanged. LangGraph delivers it as the return
|
|
149
|
+
* value of the original `interrupt()` call inside the paused node.
|
|
150
|
+
*
|
|
151
|
+
* The host MUST construct this Run with the same `thread_id` and the
|
|
152
|
+
* same checkpointer as the original paused run; LangGraph rebuilds
|
|
153
|
+
* graph state from the checkpoint and re-enters the interrupted node
|
|
154
|
+
* from the start.
|
|
155
|
+
*/
|
|
156
|
+
resume<TResume = t.ToolApprovalDecision[] | t.ToolApprovalDecisionMap>(resumeValue: TResume, callerConfig: Partial<RunnableConfig> & {
|
|
41
157
|
version: 'v1' | 'v2';
|
|
42
158
|
run_id?: string;
|
|
43
159
|
}, streamOptions?: t.EventStreamOptions): Promise<MessageContentComplex[] | undefined>;
|
|
@@ -47,6 +47,12 @@ export declare class ToolNode<T = any> extends RunnableCallable<T, T> {
|
|
|
47
47
|
private maxToolResultChars;
|
|
48
48
|
/** Hook registry for PreToolUse/PostToolUse lifecycle hooks */
|
|
49
49
|
private hookRegistry?;
|
|
50
|
+
/**
|
|
51
|
+
* Run-scoped HITL config. When `enabled`, `ask` decisions from
|
|
52
|
+
* PreToolUse hooks raise a LangGraph `interrupt()` instead of being
|
|
53
|
+
* treated as fail-closed denies.
|
|
54
|
+
*/
|
|
55
|
+
private humanInTheLoop?;
|
|
50
56
|
/**
|
|
51
57
|
* Registry of tool outputs keyed by `tool<idx>turn<turn>`.
|
|
52
58
|
*
|
|
@@ -67,7 +73,7 @@ export declare class ToolNode<T = any> extends RunnableCallable<T, T> {
|
|
|
67
73
|
* other's in-flight state.
|
|
68
74
|
*/
|
|
69
75
|
private anonBatchCounter;
|
|
70
|
-
constructor({ tools, toolMap, name, tags, errorHandler, toolCallStepIds, handleToolErrors, loadRuntimeTools, toolRegistry, sessions, eventDrivenMode, agentId, directToolNames, maxContextTokens, maxToolResultChars, hookRegistry, toolOutputReferences, toolOutputRegistry, }: t.ToolNodeConstructorParams);
|
|
76
|
+
constructor({ tools, toolMap, name, tags, errorHandler, toolCallStepIds, handleToolErrors, loadRuntimeTools, toolRegistry, sessions, eventDrivenMode, agentId, directToolNames, maxContextTokens, maxToolResultChars, hookRegistry, humanInTheLoop, toolOutputReferences, toolOutputRegistry, }: t.ToolNodeConstructorParams);
|
|
71
77
|
/**
|
|
72
78
|
* Returns the run-scoped tool output registry, or `undefined` when
|
|
73
79
|
* the feature is disabled.
|
|
@@ -155,6 +161,25 @@ export declare class ToolNode<T = any> extends RunnableCallable<T, T> {
|
|
|
155
161
|
* ToolMessages (appended AFTER to respect provider ordering).
|
|
156
162
|
*/
|
|
157
163
|
private dispatchToolEvents;
|
|
164
|
+
/**
|
|
165
|
+
* Fires the `PostToolBatch` hook (if registered) and appends the
|
|
166
|
+
* accumulated batch-level `additionalContext` strings to `injected`
|
|
167
|
+
* as a single `HumanMessage`. Entries are materialized in the
|
|
168
|
+
* original `toolCalls` order so hooks correlating outcomes by
|
|
169
|
+
* position (as the type docs promise) see exactly the sequence
|
|
170
|
+
* the model emitted, regardless of when each individual outcome
|
|
171
|
+
* was recorded into the map (deny synchronous, approved
|
|
172
|
+
* post-execution, respond on resume).
|
|
173
|
+
*
|
|
174
|
+
* The PostToolBatch hook's `additionalContexts` flow into the same
|
|
175
|
+
* batch accumulator per-tool hooks already use, so a single
|
|
176
|
+
* batch-level convention message can be injected through one path.
|
|
177
|
+
*
|
|
178
|
+
* Mutates `batchAdditionalContexts` (push from batch hook) and
|
|
179
|
+
* `injected` (push the consolidated HumanMessage). The caller owns
|
|
180
|
+
* those arrays and consumes them right after this returns.
|
|
181
|
+
*/
|
|
182
|
+
private dispatchPostToolBatchAndInjectContext;
|
|
158
183
|
private dispatchStepCompleted;
|
|
159
184
|
/**
|
|
160
185
|
* Converts InjectedMessage instances to LangChain HumanMessage objects.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type * as t from './types';
|
|
2
|
+
export declare class TavilyScraper implements t.BaseScraper {
|
|
3
|
+
private apiKey;
|
|
4
|
+
private apiUrl;
|
|
5
|
+
private timeout;
|
|
6
|
+
private payloadTimeout;
|
|
7
|
+
private logger;
|
|
8
|
+
private extractDepth;
|
|
9
|
+
private includeImages;
|
|
10
|
+
private includeFavicon;
|
|
11
|
+
private format;
|
|
12
|
+
constructor(config?: t.TavilyScraperConfig);
|
|
13
|
+
scrapeUrl(url: string, options?: t.TavilyScrapeOptions): Promise<[string, t.TavilyScrapeResponse]>;
|
|
14
|
+
scrapeUrls(urls: string[], options?: t.TavilyScrapeOptions): Promise<Array<[string, t.TavilyScrapeResponse]>>;
|
|
15
|
+
private extractBatch;
|
|
16
|
+
extractContent(response: t.TavilyScrapeResponse): [string, undefined | t.References];
|
|
17
|
+
extractMetadata(response: t.TavilyScrapeResponse): t.GenericScrapeMetadata;
|
|
18
|
+
}
|
|
19
|
+
export declare const createTavilyScraper: (config?: t.TavilyScraperConfig) => TavilyScraper;
|
|
@@ -2,8 +2,8 @@ import type { Logger as WinstonLogger } from 'winston';
|
|
|
2
2
|
import type { RunnableConfig } from '@langchain/core/runnables';
|
|
3
3
|
import type { BaseReranker } from './rerankers';
|
|
4
4
|
import { DATE_RANGE } from './schema';
|
|
5
|
-
export type SearchProvider = 'serper' | 'searxng';
|
|
6
|
-
export type ScraperProvider = 'firecrawl' | 'serper';
|
|
5
|
+
export type SearchProvider = 'serper' | 'searxng' | 'tavily';
|
|
6
|
+
export type ScraperProvider = 'firecrawl' | 'serper' | 'tavily';
|
|
7
7
|
export type RerankerType = 'infinity' | 'jina' | 'cohere' | 'none';
|
|
8
8
|
export interface Highlight {
|
|
9
9
|
score: number;
|
|
@@ -56,11 +56,50 @@ export interface Source {
|
|
|
56
56
|
snippet?: string;
|
|
57
57
|
date?: string;
|
|
58
58
|
}
|
|
59
|
+
export type TavilyTimeRange = 'day' | 'week' | 'month' | 'year';
|
|
60
|
+
export type TavilyTimeRangeInput = TavilyTimeRange | 'h' | 'd' | 'w' | 'm' | 'y';
|
|
61
|
+
export interface TavilySearchOptions {
|
|
62
|
+
searchDepth?: 'basic' | 'advanced' | 'fast' | 'ultra-fast';
|
|
63
|
+
maxResults?: number;
|
|
64
|
+
includeImages?: boolean;
|
|
65
|
+
includeAnswer?: boolean | 'basic' | 'advanced';
|
|
66
|
+
includeRawContent?: boolean | 'markdown' | 'text';
|
|
67
|
+
includeDomains?: string[];
|
|
68
|
+
excludeDomains?: string[];
|
|
69
|
+
topic?: 'general' | 'news' | 'finance';
|
|
70
|
+
timeRange?: TavilyTimeRangeInput;
|
|
71
|
+
includeImageDescriptions?: boolean;
|
|
72
|
+
includeFavicon?: boolean;
|
|
73
|
+
chunksPerSource?: number;
|
|
74
|
+
safeSearch?: boolean;
|
|
75
|
+
timeout?: number;
|
|
76
|
+
}
|
|
77
|
+
export interface TavilySearchPayload {
|
|
78
|
+
query: string;
|
|
79
|
+
search_depth: NonNullable<TavilySearchOptions['searchDepth']>;
|
|
80
|
+
topic: NonNullable<TavilySearchOptions['topic']>;
|
|
81
|
+
max_results: number;
|
|
82
|
+
safe_search?: boolean;
|
|
83
|
+
time_range?: TavilyTimeRange;
|
|
84
|
+
country?: string;
|
|
85
|
+
include_images?: boolean;
|
|
86
|
+
include_answer?: NonNullable<TavilySearchOptions['includeAnswer']>;
|
|
87
|
+
include_raw_content?: NonNullable<TavilySearchOptions['includeRawContent']>;
|
|
88
|
+
include_domains?: string[];
|
|
89
|
+
exclude_domains?: string[];
|
|
90
|
+
include_image_descriptions?: boolean;
|
|
91
|
+
include_favicon?: boolean;
|
|
92
|
+
chunks_per_source?: number;
|
|
93
|
+
}
|
|
59
94
|
export interface SearchConfig {
|
|
60
95
|
searchProvider?: SearchProvider;
|
|
61
96
|
serperApiKey?: string;
|
|
62
97
|
searxngInstanceUrl?: string;
|
|
63
98
|
searxngApiKey?: string;
|
|
99
|
+
tavilyApiKey?: string;
|
|
100
|
+
tavilySearchUrl?: string;
|
|
101
|
+
tavilyExtractUrl?: string;
|
|
102
|
+
tavilySearchOptions?: TavilySearchOptions;
|
|
64
103
|
}
|
|
65
104
|
export type References = {
|
|
66
105
|
links: MediaReference[];
|
|
@@ -95,6 +134,16 @@ export interface SerperScraperConfig {
|
|
|
95
134
|
logger?: Logger;
|
|
96
135
|
includeMarkdown?: boolean;
|
|
97
136
|
}
|
|
137
|
+
export interface TavilyScraperConfig {
|
|
138
|
+
apiKey?: string;
|
|
139
|
+
apiUrl?: string;
|
|
140
|
+
timeout?: number;
|
|
141
|
+
logger?: Logger;
|
|
142
|
+
extractDepth?: 'basic' | 'advanced';
|
|
143
|
+
includeImages?: boolean;
|
|
144
|
+
includeFavicon?: boolean;
|
|
145
|
+
format?: 'markdown' | 'text';
|
|
146
|
+
}
|
|
98
147
|
export interface ScraperContentResult {
|
|
99
148
|
content: string;
|
|
100
149
|
}
|
|
@@ -135,6 +184,7 @@ export interface CohereRerankerResponse {
|
|
|
135
184
|
export type SafeSearchLevel = 0 | 1 | 2;
|
|
136
185
|
export type Logger = WinstonLogger;
|
|
137
186
|
export interface SearchToolConfig extends SearchConfig, ProcessSourcesConfig, FirecrawlConfig {
|
|
187
|
+
tavilyScraperOptions?: TavilyScraperConfig;
|
|
138
188
|
logger?: Logger;
|
|
139
189
|
safeSearch?: SafeSearchLevel;
|
|
140
190
|
jinaApiKey?: string;
|
|
@@ -157,15 +207,27 @@ export type UsedReferences = {
|
|
|
157
207
|
originalIndex: number;
|
|
158
208
|
reference: MediaReference;
|
|
159
209
|
}[];
|
|
210
|
+
export type AnyScraperResponse = FirecrawlScrapeResponse | SerperScrapeResponse | TavilyScrapeResponse;
|
|
160
211
|
/** Base Scraper Interface */
|
|
161
212
|
export interface BaseScraper {
|
|
162
|
-
scrapeUrl(url: string, options?: unknown): Promise<[string,
|
|
163
|
-
|
|
164
|
-
|
|
213
|
+
scrapeUrl(url: string, options?: unknown): Promise<[string, AnyScraperResponse]>;
|
|
214
|
+
scrapeUrls?(urls: string[], options?: unknown): Promise<Array<[string, AnyScraperResponse]>>;
|
|
215
|
+
extractContent(response: AnyScraperResponse): [string, undefined | References];
|
|
216
|
+
extractMetadata(response: AnyScraperResponse): ScrapeMetadata | GenericScrapeMetadata;
|
|
165
217
|
}
|
|
166
218
|
/** Firecrawl */
|
|
167
219
|
export type FirecrawlScrapeOptions = Omit<FirecrawlScraperConfig, 'apiKey' | 'apiUrl' | 'version' | 'logger'>;
|
|
168
220
|
export type SerperScrapeOptions = Omit<SerperScraperConfig, 'apiKey' | 'apiUrl' | 'logger'>;
|
|
221
|
+
export type TavilyScrapeOptions = Omit<TavilyScraperConfig, 'apiKey' | 'apiUrl' | 'logger'>;
|
|
222
|
+
export interface TavilyExtractPayload {
|
|
223
|
+
urls: string[];
|
|
224
|
+
extract_depth: NonNullable<TavilyScraperConfig['extractDepth']>;
|
|
225
|
+
include_images: boolean;
|
|
226
|
+
include_favicon?: boolean;
|
|
227
|
+
format?: NonNullable<TavilyScraperConfig['format']>;
|
|
228
|
+
timeout?: number;
|
|
229
|
+
}
|
|
230
|
+
export type GenericScrapeMetadata = Record<string, string | number | boolean | null | undefined>;
|
|
169
231
|
export interface ScrapeMetadata {
|
|
170
232
|
sourceURL?: string;
|
|
171
233
|
url?: string;
|
|
@@ -241,6 +303,38 @@ export interface SerperScrapeResponse {
|
|
|
241
303
|
};
|
|
242
304
|
error?: string;
|
|
243
305
|
}
|
|
306
|
+
export interface TavilyScrapeResponse {
|
|
307
|
+
success: boolean;
|
|
308
|
+
data?: {
|
|
309
|
+
rawContent?: string;
|
|
310
|
+
images?: string[];
|
|
311
|
+
favicon?: string;
|
|
312
|
+
};
|
|
313
|
+
error?: string;
|
|
314
|
+
}
|
|
315
|
+
export interface TavilySearchResult {
|
|
316
|
+
title?: string;
|
|
317
|
+
url?: string;
|
|
318
|
+
content?: string;
|
|
319
|
+
score?: number;
|
|
320
|
+
published_date?: string;
|
|
321
|
+
}
|
|
322
|
+
export type TavilyImageResult = string | {
|
|
323
|
+
url?: string;
|
|
324
|
+
description?: string;
|
|
325
|
+
};
|
|
326
|
+
export interface TavilySearchResponse {
|
|
327
|
+
answer?: string;
|
|
328
|
+
images?: TavilyImageResult[];
|
|
329
|
+
results?: TavilySearchResult[];
|
|
330
|
+
}
|
|
331
|
+
export interface TavilyExtractResult {
|
|
332
|
+
url: string;
|
|
333
|
+
raw_content?: string;
|
|
334
|
+
images?: string[];
|
|
335
|
+
favicon?: string;
|
|
336
|
+
error?: string;
|
|
337
|
+
}
|
|
244
338
|
export interface FirecrawlScraperConfig {
|
|
245
339
|
apiKey?: string;
|
|
246
340
|
apiUrl?: string;
|
|
@@ -6,5 +6,5 @@ import type * as t from './types';
|
|
|
6
6
|
*/
|
|
7
7
|
export declare const createDefaultLogger: () => t.Logger;
|
|
8
8
|
export declare const fileExtRegex: RegExp;
|
|
9
|
-
export declare const getDomainName: (link: string, metadata?: t.ScrapeMetadata, logger?: t.Logger) => string | undefined;
|
|
10
|
-
export declare function getAttribution(link: string, metadata?: t.ScrapeMetadata, logger?: t.Logger): string | undefined;
|
|
9
|
+
export declare const getDomainName: (link: string, metadata?: t.ScrapeMetadata | t.GenericScrapeMetadata, logger?: t.Logger) => string | undefined;
|
|
10
|
+
export declare function getAttribution(link: string, metadata?: t.ScrapeMetadata | t.GenericScrapeMetadata, logger?: t.Logger): string | undefined;
|