@librechat/agents 2.4.321 → 3.0.0-rc1
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/agents/AgentContext.cjs +218 -0
- package/dist/cjs/agents/AgentContext.cjs.map +1 -0
- package/dist/cjs/common/enum.cjs +14 -5
- package/dist/cjs/common/enum.cjs.map +1 -1
- package/dist/cjs/events.cjs +10 -6
- package/dist/cjs/events.cjs.map +1 -1
- package/dist/cjs/graphs/Graph.cjs +309 -212
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/graphs/MultiAgentGraph.cjs +322 -0
- package/dist/cjs/graphs/MultiAgentGraph.cjs.map +1 -0
- package/dist/cjs/llm/anthropic/index.cjs +54 -9
- 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 +52 -6
- package/dist/cjs/llm/anthropic/utils/message_inputs.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/utils/message_outputs.cjs +22 -2
- package/dist/cjs/llm/anthropic/utils/message_outputs.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/utils/tools.cjs +29 -0
- package/dist/cjs/llm/anthropic/utils/tools.cjs.map +1 -0
- package/dist/cjs/llm/google/index.cjs +144 -0
- package/dist/cjs/llm/google/index.cjs.map +1 -0
- package/dist/cjs/llm/google/utils/common.cjs +477 -0
- package/dist/cjs/llm/google/utils/common.cjs.map +1 -0
- package/dist/cjs/llm/ollama/index.cjs +67 -0
- package/dist/cjs/llm/ollama/index.cjs.map +1 -0
- package/dist/cjs/llm/ollama/utils.cjs +158 -0
- package/dist/cjs/llm/ollama/utils.cjs.map +1 -0
- package/dist/cjs/llm/openai/index.cjs +389 -3
- package/dist/cjs/llm/openai/index.cjs.map +1 -1
- package/dist/cjs/llm/openai/utils/index.cjs +672 -0
- package/dist/cjs/llm/openai/utils/index.cjs.map +1 -0
- package/dist/cjs/llm/providers.cjs +15 -15
- package/dist/cjs/llm/providers.cjs.map +1 -1
- package/dist/cjs/llm/text.cjs +14 -3
- package/dist/cjs/llm/text.cjs.map +1 -1
- package/dist/cjs/llm/vertexai/index.cjs +330 -0
- package/dist/cjs/llm/vertexai/index.cjs.map +1 -0
- package/dist/cjs/main.cjs +11 -0
- package/dist/cjs/main.cjs.map +1 -1
- package/dist/cjs/run.cjs +120 -81
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/cjs/stream.cjs +85 -51
- package/dist/cjs/stream.cjs.map +1 -1
- package/dist/cjs/tools/ToolNode.cjs +10 -4
- package/dist/cjs/tools/ToolNode.cjs.map +1 -1
- package/dist/cjs/tools/handlers.cjs +119 -13
- package/dist/cjs/tools/handlers.cjs.map +1 -1
- package/dist/cjs/tools/search/anthropic.cjs +40 -0
- package/dist/cjs/tools/search/anthropic.cjs.map +1 -0
- package/dist/cjs/tools/search/firecrawl.cjs +61 -13
- package/dist/cjs/tools/search/firecrawl.cjs.map +1 -1
- package/dist/cjs/tools/search/format.cjs +9 -3
- package/dist/cjs/tools/search/format.cjs.map +1 -1
- package/dist/cjs/tools/search/rerankers.cjs +35 -50
- package/dist/cjs/tools/search/rerankers.cjs.map +1 -1
- package/dist/cjs/tools/search/schema.cjs +70 -0
- package/dist/cjs/tools/search/schema.cjs.map +1 -0
- package/dist/cjs/tools/search/search.cjs +145 -38
- package/dist/cjs/tools/search/search.cjs.map +1 -1
- package/dist/cjs/tools/search/tool.cjs +165 -48
- package/dist/cjs/tools/search/tool.cjs.map +1 -1
- package/dist/cjs/tools/search/utils.cjs +34 -5
- package/dist/cjs/tools/search/utils.cjs.map +1 -1
- package/dist/cjs/utils/events.cjs +31 -0
- package/dist/cjs/utils/events.cjs.map +1 -0
- package/dist/cjs/utils/title.cjs +57 -21
- package/dist/cjs/utils/title.cjs.map +1 -1
- package/dist/cjs/utils/tokens.cjs +54 -7
- package/dist/cjs/utils/tokens.cjs.map +1 -1
- package/dist/esm/agents/AgentContext.mjs +216 -0
- package/dist/esm/agents/AgentContext.mjs.map +1 -0
- package/dist/esm/common/enum.mjs +15 -6
- package/dist/esm/common/enum.mjs.map +1 -1
- package/dist/esm/events.mjs +10 -6
- package/dist/esm/events.mjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +311 -214
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/graphs/MultiAgentGraph.mjs +320 -0
- package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -0
- package/dist/esm/llm/anthropic/index.mjs +54 -9
- 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 +52 -6
- package/dist/esm/llm/anthropic/utils/message_inputs.mjs.map +1 -1
- package/dist/esm/llm/anthropic/utils/message_outputs.mjs +22 -2
- package/dist/esm/llm/anthropic/utils/message_outputs.mjs.map +1 -1
- package/dist/esm/llm/anthropic/utils/tools.mjs +27 -0
- package/dist/esm/llm/anthropic/utils/tools.mjs.map +1 -0
- package/dist/esm/llm/google/index.mjs +142 -0
- package/dist/esm/llm/google/index.mjs.map +1 -0
- package/dist/esm/llm/google/utils/common.mjs +471 -0
- package/dist/esm/llm/google/utils/common.mjs.map +1 -0
- package/dist/esm/llm/ollama/index.mjs +65 -0
- package/dist/esm/llm/ollama/index.mjs.map +1 -0
- package/dist/esm/llm/ollama/utils.mjs +155 -0
- package/dist/esm/llm/ollama/utils.mjs.map +1 -0
- package/dist/esm/llm/openai/index.mjs +388 -4
- package/dist/esm/llm/openai/index.mjs.map +1 -1
- package/dist/esm/llm/openai/utils/index.mjs +666 -0
- package/dist/esm/llm/openai/utils/index.mjs.map +1 -0
- package/dist/esm/llm/providers.mjs +5 -5
- package/dist/esm/llm/providers.mjs.map +1 -1
- package/dist/esm/llm/text.mjs +14 -3
- package/dist/esm/llm/text.mjs.map +1 -1
- package/dist/esm/llm/vertexai/index.mjs +328 -0
- package/dist/esm/llm/vertexai/index.mjs.map +1 -0
- package/dist/esm/main.mjs +6 -5
- package/dist/esm/main.mjs.map +1 -1
- package/dist/esm/run.mjs +121 -83
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/stream.mjs +87 -54
- package/dist/esm/stream.mjs.map +1 -1
- package/dist/esm/tools/ToolNode.mjs +10 -4
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/esm/tools/handlers.mjs +119 -15
- package/dist/esm/tools/handlers.mjs.map +1 -1
- package/dist/esm/tools/search/anthropic.mjs +37 -0
- package/dist/esm/tools/search/anthropic.mjs.map +1 -0
- package/dist/esm/tools/search/firecrawl.mjs +61 -13
- package/dist/esm/tools/search/firecrawl.mjs.map +1 -1
- package/dist/esm/tools/search/format.mjs +10 -4
- package/dist/esm/tools/search/format.mjs.map +1 -1
- package/dist/esm/tools/search/rerankers.mjs +35 -50
- package/dist/esm/tools/search/rerankers.mjs.map +1 -1
- package/dist/esm/tools/search/schema.mjs +61 -0
- package/dist/esm/tools/search/schema.mjs.map +1 -0
- package/dist/esm/tools/search/search.mjs +146 -39
- package/dist/esm/tools/search/search.mjs.map +1 -1
- package/dist/esm/tools/search/tool.mjs +164 -47
- package/dist/esm/tools/search/tool.mjs.map +1 -1
- package/dist/esm/tools/search/utils.mjs +33 -6
- package/dist/esm/tools/search/utils.mjs.map +1 -1
- package/dist/esm/utils/events.mjs +29 -0
- package/dist/esm/utils/events.mjs.map +1 -0
- package/dist/esm/utils/title.mjs +57 -22
- package/dist/esm/utils/title.mjs.map +1 -1
- package/dist/esm/utils/tokens.mjs +54 -8
- package/dist/esm/utils/tokens.mjs.map +1 -1
- package/dist/types/agents/AgentContext.d.ts +91 -0
- package/dist/types/common/enum.d.ts +15 -6
- package/dist/types/events.d.ts +5 -4
- package/dist/types/graphs/Graph.d.ts +64 -67
- package/dist/types/graphs/MultiAgentGraph.d.ts +37 -0
- package/dist/types/graphs/index.d.ts +1 -0
- package/dist/types/llm/anthropic/index.d.ts +11 -0
- package/dist/types/llm/anthropic/types.d.ts +9 -3
- package/dist/types/llm/anthropic/utils/message_inputs.d.ts +1 -1
- package/dist/types/llm/anthropic/utils/output_parsers.d.ts +4 -4
- package/dist/types/llm/anthropic/utils/tools.d.ts +3 -0
- package/dist/types/llm/google/index.d.ts +13 -0
- package/dist/types/llm/google/types.d.ts +32 -0
- package/dist/types/llm/google/utils/common.d.ts +19 -0
- package/dist/types/llm/google/utils/tools.d.ts +10 -0
- package/dist/types/llm/google/utils/zod_to_genai_parameters.d.ts +14 -0
- package/dist/types/llm/ollama/index.d.ts +7 -0
- package/dist/types/llm/ollama/utils.d.ts +7 -0
- package/dist/types/llm/openai/index.d.ts +72 -3
- package/dist/types/llm/openai/types.d.ts +10 -0
- package/dist/types/llm/openai/utils/index.d.ts +20 -0
- package/dist/types/llm/text.d.ts +1 -1
- package/dist/types/llm/vertexai/index.d.ts +293 -0
- package/dist/types/messages/reducer.d.ts +9 -0
- package/dist/types/run.d.ts +19 -12
- package/dist/types/scripts/ant_web_search.d.ts +1 -0
- package/dist/types/scripts/args.d.ts +2 -1
- package/dist/types/scripts/handoff-test.d.ts +1 -0
- package/dist/types/scripts/multi-agent-conditional.d.ts +1 -0
- package/dist/types/scripts/multi-agent-parallel.d.ts +1 -0
- package/dist/types/scripts/multi-agent-sequence.d.ts +1 -0
- package/dist/types/scripts/multi-agent-test.d.ts +1 -0
- package/dist/types/stream.d.ts +10 -3
- package/dist/types/tools/CodeExecutor.d.ts +2 -2
- package/dist/types/tools/ToolNode.d.ts +1 -1
- package/dist/types/tools/handlers.d.ts +17 -4
- package/dist/types/tools/search/anthropic.d.ts +16 -0
- package/dist/types/tools/search/firecrawl.d.ts +16 -0
- package/dist/types/tools/search/rerankers.d.ts +8 -5
- package/dist/types/tools/search/schema.d.ts +16 -0
- package/dist/types/tools/search/tool.d.ts +13 -0
- package/dist/types/tools/search/types.d.ts +64 -9
- package/dist/types/tools/search/utils.d.ts +9 -2
- package/dist/types/types/graph.d.ts +95 -15
- package/dist/types/types/llm.d.ts +24 -10
- package/dist/types/types/run.d.ts +46 -8
- package/dist/types/types/stream.d.ts +16 -2
- package/dist/types/types/tools.d.ts +1 -1
- package/dist/types/utils/events.d.ts +6 -0
- package/dist/types/utils/title.d.ts +2 -1
- package/dist/types/utils/tokens.d.ts +24 -0
- package/package.json +35 -18
- package/src/agents/AgentContext.ts +315 -0
- package/src/common/enum.ts +14 -5
- package/src/events.ts +24 -13
- package/src/graphs/Graph.ts +495 -312
- package/src/graphs/MultiAgentGraph.ts +381 -0
- package/src/graphs/index.ts +2 -1
- package/src/llm/anthropic/Jacob_Lee_Resume_2023.pdf +0 -0
- package/src/llm/anthropic/index.ts +78 -13
- package/src/llm/anthropic/llm.spec.ts +491 -115
- package/src/llm/anthropic/types.ts +39 -3
- package/src/llm/anthropic/utils/message_inputs.ts +67 -11
- package/src/llm/anthropic/utils/message_outputs.ts +21 -2
- package/src/llm/anthropic/utils/output_parsers.ts +25 -6
- package/src/llm/anthropic/utils/tools.ts +29 -0
- package/src/llm/google/index.ts +218 -0
- package/src/llm/google/types.ts +43 -0
- package/src/llm/google/utils/common.ts +646 -0
- package/src/llm/google/utils/tools.ts +160 -0
- package/src/llm/google/utils/zod_to_genai_parameters.ts +86 -0
- package/src/llm/ollama/index.ts +89 -0
- package/src/llm/ollama/utils.ts +193 -0
- package/src/llm/openai/index.ts +600 -14
- package/src/llm/openai/types.ts +24 -0
- package/src/llm/openai/utils/index.ts +912 -0
- package/src/llm/openai/utils/isReasoningModel.test.ts +90 -0
- package/src/llm/providers.ts +10 -9
- package/src/llm/text.ts +26 -7
- package/src/llm/vertexai/index.ts +360 -0
- package/src/messages/reducer.ts +80 -0
- package/src/run.ts +181 -112
- package/src/scripts/ant_web_search.ts +158 -0
- package/src/scripts/args.ts +12 -8
- package/src/scripts/cli4.ts +29 -21
- package/src/scripts/cli5.ts +29 -21
- package/src/scripts/code_exec.ts +54 -23
- package/src/scripts/code_exec_files.ts +48 -17
- package/src/scripts/code_exec_simple.ts +46 -27
- package/src/scripts/handoff-test.ts +135 -0
- package/src/scripts/image.ts +52 -20
- package/src/scripts/multi-agent-conditional.ts +220 -0
- package/src/scripts/multi-agent-example-output.md +110 -0
- package/src/scripts/multi-agent-parallel.ts +337 -0
- package/src/scripts/multi-agent-sequence.ts +212 -0
- package/src/scripts/multi-agent-test.ts +186 -0
- package/src/scripts/search.ts +4 -12
- package/src/scripts/simple.ts +25 -10
- package/src/scripts/tools.ts +48 -18
- package/src/specs/anthropic.simple.test.ts +150 -34
- package/src/specs/azure.simple.test.ts +325 -0
- package/src/specs/openai.simple.test.ts +140 -33
- package/src/specs/openrouter.simple.test.ts +107 -0
- package/src/specs/prune.test.ts +4 -9
- package/src/specs/reasoning.test.ts +80 -44
- package/src/specs/token-memoization.test.ts +39 -0
- package/src/stream.test.ts +94 -0
- package/src/stream.ts +139 -60
- package/src/tools/ToolNode.ts +21 -7
- package/src/tools/handlers.ts +192 -18
- package/src/tools/search/anthropic.ts +51 -0
- package/src/tools/search/firecrawl.ts +78 -24
- package/src/tools/search/format.ts +10 -5
- package/src/tools/search/rerankers.ts +50 -62
- package/src/tools/search/schema.ts +63 -0
- package/src/tools/search/search.ts +167 -34
- package/src/tools/search/tool.ts +222 -46
- package/src/tools/search/types.ts +65 -10
- package/src/tools/search/utils.ts +37 -5
- package/src/types/graph.ts +272 -103
- package/src/types/llm.ts +25 -12
- package/src/types/run.ts +51 -13
- package/src/types/stream.ts +22 -1
- package/src/types/tools.ts +16 -10
- package/src/utils/events.ts +32 -0
- package/src/utils/llmConfig.ts +20 -8
- package/src/utils/title.ts +104 -30
- package/src/utils/tokens.ts +69 -10
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { AnthropicTextBlockParam, AnthropicWebSearchResultBlockParam } from '@/llm/anthropic/types';
|
|
2
|
+
import type { SearchResultData } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Coerces Anthropic web search results to the SearchResultData format
|
|
5
|
+
* @param results - Array of Anthropic web search results
|
|
6
|
+
* @param turn - The turn number to associate with these results
|
|
7
|
+
* @returns SearchResultData with minimal ProcessedOrganic items
|
|
8
|
+
*/
|
|
9
|
+
export declare function coerceAnthropicSearchResults({ results, turn, }: {
|
|
10
|
+
results: (AnthropicTextBlockParam | AnthropicWebSearchResultBlockParam)[];
|
|
11
|
+
turn?: number;
|
|
12
|
+
}): SearchResultData;
|
|
13
|
+
/**
|
|
14
|
+
* Helper function to check if an object is an Anthropic web search result
|
|
15
|
+
*/
|
|
16
|
+
export declare function isAnthropicWebSearchResult(obj: unknown): obj is AnthropicWebSearchResultBlockParam;
|
|
@@ -8,6 +8,22 @@ export declare class FirecrawlScraper {
|
|
|
8
8
|
private apiUrl;
|
|
9
9
|
private defaultFormats;
|
|
10
10
|
private timeout;
|
|
11
|
+
private logger;
|
|
12
|
+
private includeTags?;
|
|
13
|
+
private excludeTags?;
|
|
14
|
+
private waitFor?;
|
|
15
|
+
private maxAge?;
|
|
16
|
+
private mobile?;
|
|
17
|
+
private skipTlsVerification?;
|
|
18
|
+
private blockAds?;
|
|
19
|
+
private removeBase64Images?;
|
|
20
|
+
private parsePDF?;
|
|
21
|
+
private storeInCache?;
|
|
22
|
+
private zeroDataRetention?;
|
|
23
|
+
private headers?;
|
|
24
|
+
private location?;
|
|
25
|
+
private onlyMainContent?;
|
|
26
|
+
private changeTrackingOptions?;
|
|
11
27
|
constructor(config?: t.FirecrawlScraperConfig);
|
|
12
28
|
/**
|
|
13
29
|
* Scrape a single URL
|
|
@@ -1,25 +1,27 @@
|
|
|
1
1
|
import type * as t from './types';
|
|
2
2
|
export declare abstract class BaseReranker {
|
|
3
3
|
protected apiKey: string | undefined;
|
|
4
|
-
|
|
4
|
+
protected logger: t.Logger;
|
|
5
|
+
constructor(logger?: t.Logger);
|
|
5
6
|
abstract rerank(query: string, documents: string[], topK?: number): Promise<t.Highlight[]>;
|
|
6
7
|
protected getDefaultRanking(documents: string[], topK: number): t.Highlight[];
|
|
7
|
-
protected logDocumentSamples(documents: string[]): void;
|
|
8
8
|
}
|
|
9
9
|
export declare class JinaReranker extends BaseReranker {
|
|
10
|
-
constructor({ apiKey }: {
|
|
10
|
+
constructor({ apiKey, logger, }: {
|
|
11
11
|
apiKey?: string;
|
|
12
|
+
logger?: t.Logger;
|
|
12
13
|
});
|
|
13
14
|
rerank(query: string, documents: string[], topK?: number): Promise<t.Highlight[]>;
|
|
14
15
|
}
|
|
15
16
|
export declare class CohereReranker extends BaseReranker {
|
|
16
|
-
constructor({ apiKey }: {
|
|
17
|
+
constructor({ apiKey, logger, }: {
|
|
17
18
|
apiKey?: string;
|
|
19
|
+
logger?: t.Logger;
|
|
18
20
|
});
|
|
19
21
|
rerank(query: string, documents: string[], topK?: number): Promise<t.Highlight[]>;
|
|
20
22
|
}
|
|
21
23
|
export declare class InfinityReranker extends BaseReranker {
|
|
22
|
-
constructor();
|
|
24
|
+
constructor(logger?: t.Logger);
|
|
23
25
|
rerank(query: string, documents: string[], topK?: number): Promise<t.Highlight[]>;
|
|
24
26
|
}
|
|
25
27
|
/**
|
|
@@ -29,4 +31,5 @@ export declare const createReranker: (config: {
|
|
|
29
31
|
rerankerType: t.RerankerType;
|
|
30
32
|
jinaApiKey?: string;
|
|
31
33
|
cohereApiKey?: string;
|
|
34
|
+
logger?: t.Logger;
|
|
32
35
|
}) => BaseReranker | undefined;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare enum DATE_RANGE {
|
|
3
|
+
PAST_HOUR = "h",
|
|
4
|
+
PAST_24_HOURS = "d",
|
|
5
|
+
PAST_WEEK = "w",
|
|
6
|
+
PAST_MONTH = "m",
|
|
7
|
+
PAST_YEAR = "y"
|
|
8
|
+
}
|
|
9
|
+
export declare const DEFAULT_QUERY_DESCRIPTION: string;
|
|
10
|
+
export declare const DEFAULT_COUNTRY_DESCRIPTION: string;
|
|
11
|
+
export declare const querySchema: z.ZodString;
|
|
12
|
+
export declare const dateSchema: z.ZodOptional<z.ZodNativeEnum<typeof DATE_RANGE>>;
|
|
13
|
+
export declare const countrySchema: z.ZodOptional<z.ZodString>;
|
|
14
|
+
export declare const imagesSchema: z.ZodOptional<z.ZodBoolean>;
|
|
15
|
+
export declare const videosSchema: z.ZodOptional<z.ZodBoolean>;
|
|
16
|
+
export declare const newsSchema: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { DynamicStructuredTool } from '@langchain/core/tools';
|
|
3
3
|
import type * as t from './types';
|
|
4
|
+
import { DATE_RANGE } from './schema';
|
|
4
5
|
/**
|
|
5
6
|
* Creates a search tool with a schema that dynamically includes the country field
|
|
6
7
|
* only when the searchProvider is 'serper'.
|
|
@@ -10,11 +11,23 @@ import type * as t from './types';
|
|
|
10
11
|
*/
|
|
11
12
|
export declare const createSearchTool: (config?: t.SearchToolConfig) => DynamicStructuredTool<z.ZodObject<{
|
|
12
13
|
query: z.ZodString;
|
|
14
|
+
date: z.ZodOptional<z.ZodNativeEnum<typeof DATE_RANGE>>;
|
|
13
15
|
country?: z.ZodOptional<z.ZodString>;
|
|
16
|
+
images: z.ZodOptional<z.ZodBoolean>;
|
|
17
|
+
videos: z.ZodOptional<z.ZodBoolean>;
|
|
18
|
+
news: z.ZodOptional<z.ZodBoolean>;
|
|
14
19
|
}, "strip", z.ZodTypeAny, {
|
|
15
20
|
query: string;
|
|
21
|
+
date?: DATE_RANGE | undefined;
|
|
22
|
+
images?: boolean | undefined;
|
|
23
|
+
videos?: boolean | undefined;
|
|
24
|
+
news?: boolean | undefined;
|
|
16
25
|
country?: unknown;
|
|
17
26
|
}, {
|
|
18
27
|
query: string;
|
|
28
|
+
date?: DATE_RANGE | undefined;
|
|
29
|
+
images?: boolean | undefined;
|
|
30
|
+
videos?: boolean | undefined;
|
|
31
|
+
news?: boolean | undefined;
|
|
19
32
|
country?: unknown;
|
|
20
33
|
}>>;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
import type { Logger as WinstonLogger } from 'winston';
|
|
2
3
|
import type { RunnableConfig } from '@langchain/core/runnables';
|
|
3
4
|
import type { BaseReranker } from './rerankers';
|
|
5
|
+
import { DATE_RANGE } from './schema';
|
|
4
6
|
export type SearchProvider = 'serper' | 'searxng';
|
|
5
7
|
export type RerankerType = 'infinity' | 'jina' | 'cohere' | 'none';
|
|
6
8
|
export interface Highlight {
|
|
@@ -78,11 +80,12 @@ export interface ProcessSourcesConfig {
|
|
|
78
80
|
strategies?: string[];
|
|
79
81
|
filterContent?: boolean;
|
|
80
82
|
reranker?: BaseReranker;
|
|
83
|
+
logger?: Logger;
|
|
81
84
|
}
|
|
82
85
|
export interface FirecrawlConfig {
|
|
83
86
|
firecrawlApiKey?: string;
|
|
84
87
|
firecrawlApiUrl?: string;
|
|
85
|
-
|
|
88
|
+
firecrawlOptions?: FirecrawlScraperConfig;
|
|
86
89
|
}
|
|
87
90
|
export interface ScraperContentResult {
|
|
88
91
|
content: string;
|
|
@@ -121,10 +124,15 @@ export interface CohereRerankerResponse {
|
|
|
121
124
|
};
|
|
122
125
|
};
|
|
123
126
|
}
|
|
127
|
+
export type SafeSearchLevel = 0 | 1 | 2;
|
|
128
|
+
export type Logger = WinstonLogger;
|
|
124
129
|
export interface SearchToolConfig extends SearchConfig, ProcessSourcesConfig, FirecrawlConfig {
|
|
130
|
+
logger?: Logger;
|
|
131
|
+
safeSearch?: SafeSearchLevel;
|
|
125
132
|
jinaApiKey?: string;
|
|
126
133
|
cohereApiKey?: string;
|
|
127
134
|
rerankerType?: RerankerType;
|
|
135
|
+
scraperTimeout?: number;
|
|
128
136
|
onSearchResults?: (results: SearchResult, runnableConfig?: RunnableConfig) => void;
|
|
129
137
|
onGetHighlights?: (link: string) => void;
|
|
130
138
|
}
|
|
@@ -139,14 +147,7 @@ export type UsedReferences = {
|
|
|
139
147
|
reference: MediaReference;
|
|
140
148
|
}[];
|
|
141
149
|
/** Firecrawl */
|
|
142
|
-
export
|
|
143
|
-
formats?: string[];
|
|
144
|
-
includeTags?: string[];
|
|
145
|
-
excludeTags?: string[];
|
|
146
|
-
headers?: Record<string, string>;
|
|
147
|
-
waitFor?: number;
|
|
148
|
-
timeout?: number;
|
|
149
|
-
}
|
|
150
|
+
export type FirecrawlScrapeOptions = Omit<FirecrawlScraperConfig, 'apiKey' | 'apiUrl' | 'logger'>;
|
|
150
151
|
export interface ScrapeMetadata {
|
|
151
152
|
sourceURL?: string;
|
|
152
153
|
url?: string;
|
|
@@ -217,11 +218,36 @@ export interface FirecrawlScraperConfig {
|
|
|
217
218
|
apiUrl?: string;
|
|
218
219
|
formats?: string[];
|
|
219
220
|
timeout?: number;
|
|
221
|
+
logger?: Logger;
|
|
222
|
+
includeTags?: string[];
|
|
223
|
+
excludeTags?: string[];
|
|
224
|
+
waitFor?: number;
|
|
225
|
+
maxAge?: number;
|
|
226
|
+
mobile?: boolean;
|
|
227
|
+
skipTlsVerification?: boolean;
|
|
228
|
+
blockAds?: boolean;
|
|
229
|
+
removeBase64Images?: boolean;
|
|
230
|
+
parsePDF?: boolean;
|
|
231
|
+
storeInCache?: boolean;
|
|
232
|
+
zeroDataRetention?: boolean;
|
|
233
|
+
headers?: Record<string, string>;
|
|
234
|
+
location?: {
|
|
235
|
+
country?: string;
|
|
236
|
+
languages?: string[];
|
|
237
|
+
};
|
|
238
|
+
onlyMainContent?: boolean;
|
|
239
|
+
changeTrackingOptions?: object;
|
|
220
240
|
}
|
|
221
241
|
export type GetSourcesParams = {
|
|
222
242
|
query: string;
|
|
243
|
+
date?: DATE_RANGE;
|
|
223
244
|
country?: string;
|
|
224
245
|
numResults?: number;
|
|
246
|
+
safeSearch?: SearchToolConfig['safeSearch'];
|
|
247
|
+
images?: boolean;
|
|
248
|
+
videos?: boolean;
|
|
249
|
+
news?: boolean;
|
|
250
|
+
type?: 'search' | 'images' | 'videos' | 'news';
|
|
225
251
|
};
|
|
226
252
|
/** Serper API */
|
|
227
253
|
export interface VideoResult {
|
|
@@ -382,6 +408,13 @@ export interface SerperSearchInput {
|
|
|
382
408
|
*/
|
|
383
409
|
autocorrect?: boolean;
|
|
384
410
|
page?: number;
|
|
411
|
+
/**
|
|
412
|
+
* Date range for search results
|
|
413
|
+
* Options: "h" (past hour), "d" (past 24 hours), "w" (past week),
|
|
414
|
+
* "m" (past month), "y" (past year)
|
|
415
|
+
* `qdr:${DATE_RANGE}`
|
|
416
|
+
*/
|
|
417
|
+
tbs?: string;
|
|
385
418
|
}
|
|
386
419
|
export type SerperResultData = {
|
|
387
420
|
searchParameters: SerperSearchPayload;
|
|
@@ -486,21 +519,43 @@ export interface SearXNGResult {
|
|
|
486
519
|
content?: string;
|
|
487
520
|
publishedDate?: string;
|
|
488
521
|
img_src?: string;
|
|
522
|
+
score?: number;
|
|
523
|
+
engine?: string;
|
|
524
|
+
category?: string;
|
|
525
|
+
thumbnail?: string;
|
|
526
|
+
priority?: string;
|
|
527
|
+
engines?: string[];
|
|
528
|
+
positions?: number[];
|
|
529
|
+
template?: string;
|
|
530
|
+
parsed_url?: string[];
|
|
489
531
|
}
|
|
490
532
|
export type ProcessSourcesFields = {
|
|
491
533
|
result: SearchResult;
|
|
492
534
|
numElements: number;
|
|
493
535
|
query: string;
|
|
536
|
+
news: boolean;
|
|
494
537
|
proMode: boolean;
|
|
495
538
|
onGetHighlights: SearchToolConfig['onGetHighlights'];
|
|
496
539
|
};
|
|
497
540
|
export type SearchToolSchema = z.ZodObject<{
|
|
498
541
|
query: z.ZodString;
|
|
542
|
+
date: z.ZodOptional<z.ZodNativeEnum<typeof DATE_RANGE>>;
|
|
499
543
|
country?: z.ZodOptional<z.ZodString>;
|
|
544
|
+
images: z.ZodOptional<z.ZodBoolean>;
|
|
545
|
+
videos: z.ZodOptional<z.ZodBoolean>;
|
|
546
|
+
news: z.ZodOptional<z.ZodBoolean>;
|
|
500
547
|
}, 'strip', z.ZodTypeAny, {
|
|
501
548
|
query: string;
|
|
549
|
+
date?: DATE_RANGE;
|
|
502
550
|
country?: unknown;
|
|
551
|
+
images?: boolean;
|
|
552
|
+
videos?: boolean;
|
|
553
|
+
news?: boolean;
|
|
503
554
|
}, {
|
|
504
555
|
query: string;
|
|
556
|
+
date?: DATE_RANGE;
|
|
505
557
|
country?: unknown;
|
|
558
|
+
images?: boolean;
|
|
559
|
+
videos?: boolean;
|
|
560
|
+
news?: boolean;
|
|
506
561
|
}>;
|
|
@@ -1,3 +1,10 @@
|
|
|
1
1
|
import type * as t from './types';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Creates a default logger that maps to console methods
|
|
4
|
+
* Uses a singleton pattern to avoid creating multiple instances
|
|
5
|
+
* @returns A default logger that implements the Logger interface
|
|
6
|
+
*/
|
|
7
|
+
export declare const createDefaultLogger: () => t.Logger;
|
|
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;
|
|
@@ -1,25 +1,77 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { START, StateType, UpdateType, StateGraph, StateGraphArgs, StateDefinition, CompiledStateGraph, BinaryOperatorAggregate } from '@langchain/langgraph';
|
|
2
|
+
import type { BindToolsInput } from '@langchain/core/language_models/chat_models';
|
|
3
|
+
import type { BaseMessage, AIMessageChunk, SystemMessage } from '@langchain/core/messages';
|
|
4
|
+
import type { RunnableConfig, Runnable } from '@langchain/core/runnables';
|
|
3
5
|
import type { ChatGenerationChunk } from '@langchain/core/outputs';
|
|
4
|
-
import type {
|
|
5
|
-
import type { ToolMap, GenericTool } from '@/types/tools';
|
|
6
|
+
import type { GoogleAIToolType } from '@langchain/google-common';
|
|
7
|
+
import type { ToolMap, ToolEndEvent, GenericTool } from '@/types/tools';
|
|
8
|
+
import type { Providers, Callback, GraphNodeKeys } from '@/common';
|
|
9
|
+
import type { StandardGraph, MultiAgentGraph } from '@/graphs';
|
|
6
10
|
import type { ClientOptions } from '@/types/llm';
|
|
7
|
-
import type {
|
|
8
|
-
import type {
|
|
11
|
+
import type { RunStep, RunStepDeltaEvent, MessageDeltaEvent, ReasoningDeltaEvent } from '@/types/stream';
|
|
12
|
+
import type { TokenCounter } from '@/types/run';
|
|
13
|
+
/** Interface for bound model with stream and invoke methods */
|
|
14
|
+
export interface ChatModel {
|
|
15
|
+
stream?: (messages: BaseMessage[], config?: RunnableConfig) => Promise<AsyncIterable<AIMessageChunk>>;
|
|
16
|
+
invoke: (messages: BaseMessage[], config?: RunnableConfig) => Promise<AIMessageChunk>;
|
|
17
|
+
}
|
|
18
|
+
export type GraphNode = GraphNodeKeys | typeof START;
|
|
19
|
+
export type ClientCallback<T extends unknown[]> = (graph: StandardGraph, ...args: T) => void;
|
|
20
|
+
export type ClientCallbacks = {
|
|
21
|
+
[Callback.TOOL_ERROR]?: ClientCallback<[Error, string]>;
|
|
22
|
+
[Callback.TOOL_START]?: ClientCallback<unknown[]>;
|
|
23
|
+
[Callback.TOOL_END]?: ClientCallback<unknown[]>;
|
|
24
|
+
};
|
|
25
|
+
export type SystemCallbacks = {
|
|
26
|
+
[K in keyof ClientCallbacks]: ClientCallbacks[K] extends ClientCallback<infer Args> ? (...args: Args) => void : never;
|
|
27
|
+
};
|
|
9
28
|
export type BaseGraphState = {
|
|
10
29
|
messages: BaseMessage[];
|
|
11
30
|
};
|
|
12
31
|
export type IState = BaseGraphState;
|
|
13
32
|
export interface EventHandler {
|
|
14
|
-
handle(event: string, data: StreamEventData | ModelEndData
|
|
33
|
+
handle(event: string, data: StreamEventData | ModelEndData | RunStep | RunStepDeltaEvent | MessageDeltaEvent | ReasoningDeltaEvent | {
|
|
34
|
+
result: ToolEndEvent;
|
|
35
|
+
}, metadata?: Record<string, unknown>, graph?: StandardGraph | MultiAgentGraph): void | Promise<void>;
|
|
15
36
|
}
|
|
16
37
|
export type GraphStateChannels<T extends BaseGraphState> = StateGraphArgs<T>['channels'];
|
|
17
38
|
export type Workflow<T extends BaseGraphState = BaseGraphState, U extends Partial<T> = Partial<T>, N extends string = string> = StateGraph<T, U, N>;
|
|
18
39
|
export type CompiledWorkflow<T extends BaseGraphState = BaseGraphState, U extends Partial<T> = Partial<T>, N extends string = string> = CompiledStateGraph<T, U, N>;
|
|
40
|
+
export type CompiledStateWorkflow = CompiledStateGraph<StateType<{
|
|
41
|
+
messages: BinaryOperatorAggregate<BaseMessage[], BaseMessage[]>;
|
|
42
|
+
}>, UpdateType<{
|
|
43
|
+
messages: BinaryOperatorAggregate<BaseMessage[], BaseMessage[]>;
|
|
44
|
+
}>, string, {
|
|
45
|
+
messages: BinaryOperatorAggregate<BaseMessage[], BaseMessage[]>;
|
|
46
|
+
}, {
|
|
47
|
+
messages: BinaryOperatorAggregate<BaseMessage[], BaseMessage[]>;
|
|
48
|
+
}, StateDefinition>;
|
|
49
|
+
export type CompiledAgentWorfklow = CompiledStateGraph<{
|
|
50
|
+
messages: BaseMessage[];
|
|
51
|
+
}, {
|
|
52
|
+
messages?: BaseMessage[] | undefined;
|
|
53
|
+
}, '__start__' | `agent=${string}` | `tools=${string}`, {
|
|
54
|
+
messages: BinaryOperatorAggregate<BaseMessage[], BaseMessage[]>;
|
|
55
|
+
}, {
|
|
56
|
+
messages: BinaryOperatorAggregate<BaseMessage[], BaseMessage[]>;
|
|
57
|
+
}, StateDefinition, {
|
|
58
|
+
[x: `agent=${string}`]: Partial<BaseGraphState>;
|
|
59
|
+
[x: `tools=${string}`]: any;
|
|
60
|
+
}>;
|
|
61
|
+
export type SystemRunnable = Runnable<BaseMessage[], (BaseMessage | SystemMessage)[], RunnableConfig<Record<string, unknown>>> | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* Optional compile options passed to workflow.compile().
|
|
64
|
+
* These are intentionally untyped to avoid coupling to library internals.
|
|
65
|
+
*/
|
|
66
|
+
export type CompileOptions = {
|
|
67
|
+
checkpointer?: any;
|
|
68
|
+
interruptBefore?: string[];
|
|
69
|
+
interruptAfter?: string[];
|
|
70
|
+
};
|
|
19
71
|
export type EventStreamCallbackHandlerInput = Parameters<CompiledWorkflow['streamEvents']>[2] extends Omit<infer T, 'autoClose'> ? T : never;
|
|
20
|
-
export type StreamChunk = ChatGenerationChunk & {
|
|
72
|
+
export type StreamChunk = (ChatGenerationChunk & {
|
|
21
73
|
message: AIMessageChunk;
|
|
22
|
-
} | AIMessageChunk;
|
|
74
|
+
}) | AIMessageChunk;
|
|
23
75
|
/**
|
|
24
76
|
* Data associated with a StreamEvent.
|
|
25
77
|
*/
|
|
@@ -55,6 +107,10 @@ export type StreamEventData = {
|
|
|
55
107
|
* Custom result from the runnable that generated the event.
|
|
56
108
|
*/
|
|
57
109
|
result?: unknown;
|
|
110
|
+
/**
|
|
111
|
+
* Custom field to indicate the event was manually emitted, and may have been handled already
|
|
112
|
+
*/
|
|
113
|
+
emitted?: boolean;
|
|
58
114
|
};
|
|
59
115
|
/**
|
|
60
116
|
* A streaming event.
|
|
@@ -117,19 +173,43 @@ export type PartMetadata = {
|
|
|
117
173
|
action?: boolean;
|
|
118
174
|
output?: string;
|
|
119
175
|
};
|
|
120
|
-
export type ModelEndData = StreamEventData & {
|
|
176
|
+
export type ModelEndData = (StreamEventData & {
|
|
121
177
|
output: AIMessageChunk | undefined;
|
|
122
|
-
} | undefined;
|
|
178
|
+
}) | undefined;
|
|
179
|
+
export type GraphTools = GenericTool[] | BindToolsInput[] | GoogleAIToolType[];
|
|
123
180
|
export type StandardGraphInput = {
|
|
124
181
|
runId?: string;
|
|
182
|
+
signal?: AbortSignal;
|
|
183
|
+
agents: AgentInputs[];
|
|
184
|
+
tokenCounter?: TokenCounter;
|
|
185
|
+
indexTokenCountMap?: Record<string, number>;
|
|
186
|
+
};
|
|
187
|
+
export type GraphEdge = {
|
|
188
|
+
/** Use a list for multiple sources */
|
|
189
|
+
from: string | string[];
|
|
190
|
+
/** Use a list for multiple destinations */
|
|
191
|
+
to: string | string[];
|
|
192
|
+
description?: string;
|
|
193
|
+
/** Can return boolean or specific destination(s) */
|
|
194
|
+
condition?: (state: BaseGraphState) => boolean | string | string[];
|
|
195
|
+
/** 'handoff' creates tools for dynamic routing, 'direct' creates direct edges, which also allow parallel execution */
|
|
196
|
+
edgeType?: 'handoff' | 'direct';
|
|
197
|
+
/** Optional prompt to add when transitioning through this edge */
|
|
198
|
+
promptInstructions?: string | ((messages: BaseMessage[]) => string | undefined);
|
|
199
|
+
};
|
|
200
|
+
export type MultiAgentGraphInput = StandardGraphInput & {
|
|
201
|
+
edges: GraphEdge[];
|
|
202
|
+
};
|
|
203
|
+
export interface AgentInputs {
|
|
204
|
+
agentId: string;
|
|
125
205
|
toolEnd?: boolean;
|
|
126
206
|
toolMap?: ToolMap;
|
|
207
|
+
tools?: GraphTools;
|
|
127
208
|
provider: Providers;
|
|
128
|
-
signal?: AbortSignal;
|
|
129
209
|
instructions?: string;
|
|
130
210
|
streamBuffer?: number;
|
|
131
|
-
|
|
132
|
-
clientOptions
|
|
211
|
+
maxContextTokens?: number;
|
|
212
|
+
clientOptions?: ClientOptions;
|
|
133
213
|
additional_instructions?: string;
|
|
134
214
|
reasoningKey?: 'reasoning_content' | 'reasoning';
|
|
135
|
-
}
|
|
215
|
+
}
|
|
@@ -1,27 +1,29 @@
|
|
|
1
1
|
import { ChatOllama } from '@langchain/ollama';
|
|
2
|
-
import { ChatAnthropic } from '@langchain/anthropic';
|
|
3
2
|
import { ChatMistralAI } from '@langchain/mistralai';
|
|
4
3
|
import { ChatBedrockConverse } from '@langchain/aws';
|
|
5
|
-
import { ChatVertexAI } from '@langchain/google-vertexai';
|
|
6
|
-
import { ChatGoogleGenerativeAI } from '@langchain/google-genai';
|
|
7
4
|
import { BedrockChat } from '@langchain/community/chat_models/bedrock/web';
|
|
8
5
|
import type { BindToolsInput, BaseChatModelParams } from '@langchain/core/language_models/chat_models';
|
|
9
6
|
import type { OpenAIChatInput, ChatOpenAIFields, AzureOpenAIInput, ClientOptions as OAIClientOptions } from '@langchain/openai';
|
|
10
7
|
import type { BedrockChatFields } from '@langchain/community/chat_models/bedrock/web';
|
|
11
8
|
import type { GoogleGenerativeAIChatInput } from '@langchain/google-genai';
|
|
9
|
+
import type { GeminiGenerationConfig } from '@langchain/google-common';
|
|
12
10
|
import type { ChatVertexAIInput } from '@langchain/google-vertexai';
|
|
13
11
|
import type { ChatDeepSeekCallOptions } from '@langchain/deepseek';
|
|
14
12
|
import type { ChatOpenRouterCallOptions } from '@/llm/openrouter';
|
|
15
13
|
import type { ChatBedrockConverseInput } from '@langchain/aws';
|
|
16
14
|
import type { ChatMistralAIInput } from '@langchain/mistralai';
|
|
15
|
+
import type { RequestOptions } from '@google/generative-ai';
|
|
17
16
|
import type { StructuredTool } from '@langchain/core/tools';
|
|
18
17
|
import type { AnthropicInput } from '@langchain/anthropic';
|
|
19
18
|
import type { Runnable } from '@langchain/core/runnables';
|
|
20
19
|
import type { ChatOllamaInput } from '@langchain/ollama';
|
|
21
20
|
import type { OpenAI as OpenAIClient } from 'openai';
|
|
22
21
|
import type { ChatXAIInput } from '@langchain/xai';
|
|
23
|
-
import {
|
|
22
|
+
import { AzureChatOpenAI, ChatDeepSeek, ChatOpenAI, ChatXAI } from '@/llm/openai';
|
|
23
|
+
import { CustomChatGoogleGenerativeAI } from '@/llm/google';
|
|
24
|
+
import { CustomAnthropic } from '@/llm/anthropic';
|
|
24
25
|
import { ChatOpenRouter } from '@/llm/openrouter';
|
|
26
|
+
import { ChatVertexAI } from '@/llm/vertexai';
|
|
25
27
|
import { Providers } from '@/common';
|
|
26
28
|
export type AzureClientOptions = Partial<OpenAIChatInput> & Partial<AzureOpenAIInput> & {
|
|
27
29
|
openAIApiKey?: string;
|
|
@@ -42,19 +44,31 @@ export type OpenAIClientOptions = ChatOpenAIFields;
|
|
|
42
44
|
export type OllamaClientOptions = ChatOllamaInput;
|
|
43
45
|
export type AnthropicClientOptions = AnthropicInput;
|
|
44
46
|
export type MistralAIClientOptions = ChatMistralAIInput;
|
|
45
|
-
export type VertexAIClientOptions = ChatVertexAIInput
|
|
47
|
+
export type VertexAIClientOptions = ChatVertexAIInput & {
|
|
48
|
+
includeThoughts?: boolean;
|
|
49
|
+
};
|
|
46
50
|
export type BedrockClientOptions = BedrockChatFields;
|
|
47
51
|
export type BedrockAnthropicInput = ChatBedrockConverseInput & {
|
|
48
52
|
additionalModelRequestFields?: ChatBedrockConverseInput['additionalModelRequestFields'] & AnthropicReasoning;
|
|
49
53
|
};
|
|
50
54
|
export type BedrockConverseClientOptions = ChatBedrockConverseInput;
|
|
51
|
-
export type GoogleClientOptions = GoogleGenerativeAIChatInput
|
|
55
|
+
export type GoogleClientOptions = GoogleGenerativeAIChatInput & {
|
|
56
|
+
customHeaders?: RequestOptions['customHeaders'];
|
|
57
|
+
thinkingConfig?: GeminiGenerationConfig['thinkingConfig'];
|
|
58
|
+
};
|
|
52
59
|
export type DeepSeekClientOptions = ChatDeepSeekCallOptions;
|
|
53
60
|
export type XAIClientOptions = ChatXAIInput;
|
|
54
61
|
export type ClientOptions = OpenAIClientOptions | AzureClientOptions | OllamaClientOptions | AnthropicClientOptions | MistralAIClientOptions | VertexAIClientOptions | BedrockClientOptions | BedrockConverseClientOptions | GoogleClientOptions | DeepSeekClientOptions | XAIClientOptions;
|
|
55
|
-
export type
|
|
62
|
+
export type SharedLLMConfig = {
|
|
56
63
|
provider: Providers;
|
|
57
|
-
}
|
|
64
|
+
};
|
|
65
|
+
export type LLMConfig = SharedLLMConfig & ClientOptions & {
|
|
66
|
+
/** Optional provider fallbacks in order of attempt */
|
|
67
|
+
fallbacks?: Array<{
|
|
68
|
+
provider: Providers;
|
|
69
|
+
clientOptions?: ClientOptions;
|
|
70
|
+
}>;
|
|
71
|
+
};
|
|
58
72
|
export type ProviderOptionsMap = {
|
|
59
73
|
[Providers.AZURE]: AzureClientOptions;
|
|
60
74
|
[Providers.OPENAI]: OpenAIClientOptions;
|
|
@@ -77,13 +91,13 @@ export type ChatModelMap = {
|
|
|
77
91
|
[Providers.AZURE]: AzureChatOpenAI;
|
|
78
92
|
[Providers.DEEPSEEK]: ChatDeepSeek;
|
|
79
93
|
[Providers.VERTEXAI]: ChatVertexAI;
|
|
80
|
-
[Providers.ANTHROPIC]:
|
|
94
|
+
[Providers.ANTHROPIC]: CustomAnthropic;
|
|
81
95
|
[Providers.MISTRALAI]: ChatMistralAI;
|
|
82
96
|
[Providers.MISTRAL]: ChatMistralAI;
|
|
83
97
|
[Providers.OPENROUTER]: ChatOpenRouter;
|
|
84
98
|
[Providers.BEDROCK_LEGACY]: BedrockChat;
|
|
85
99
|
[Providers.BEDROCK]: ChatBedrockConverse;
|
|
86
|
-
[Providers.GOOGLE]:
|
|
100
|
+
[Providers.GOOGLE]: CustomChatGoogleGenerativeAI;
|
|
87
101
|
};
|
|
88
102
|
export type ChatModelConstructorMap = {
|
|
89
103
|
[P in Providers]: new (config: ProviderOptionsMap[P]) => ChatModelMap[P];
|
|
@@ -3,26 +3,59 @@ import type { BaseMessage } from '@langchain/core/messages';
|
|
|
3
3
|
import type { StructuredTool } from '@langchain/core/tools';
|
|
4
4
|
import type { RunnableConfig } from '@langchain/core/runnables';
|
|
5
5
|
import type { BaseCallbackHandler, CallbackHandlerMethods } from '@langchain/core/callbacks/base';
|
|
6
|
-
import type * as graph from '@/graphs/Graph';
|
|
7
6
|
import type * as s from '@/types/stream';
|
|
8
7
|
import type * as e from '@/common/enum';
|
|
9
8
|
import type * as g from '@/types/graph';
|
|
10
9
|
import type * as l from '@/types/llm';
|
|
11
10
|
export type ZodObjectAny = z.ZodObject<any, any, any, any>;
|
|
12
11
|
export type BaseGraphConfig = {
|
|
13
|
-
type?: 'standard';
|
|
14
12
|
llmConfig: l.LLMConfig;
|
|
15
13
|
provider?: e.Providers;
|
|
16
14
|
clientOptions?: l.ClientOptions;
|
|
15
|
+
/** Optional compile options for workflow.compile() */
|
|
16
|
+
compileOptions?: g.CompileOptions;
|
|
17
17
|
};
|
|
18
|
-
export type
|
|
18
|
+
export type LegacyGraphConfig = BaseGraphConfig & {
|
|
19
|
+
type?: 'standard';
|
|
20
|
+
} & Omit<g.StandardGraphInput, 'provider' | 'clientOptions' | 'agents'> & Omit<g.AgentInputs, 'provider' | 'clientOptions' | 'agentId'>;
|
|
21
|
+
export type SupervisedGraphConfig = BaseGraphConfig & {
|
|
22
|
+
type: 'supervised';
|
|
23
|
+
/** Enable supervised router; when false, fall back to standard loop */
|
|
24
|
+
routerEnabled?: boolean;
|
|
25
|
+
/** Table-driven routing policy per stage */
|
|
26
|
+
routingPolicies?: Array<{
|
|
27
|
+
stage: string;
|
|
28
|
+
agents?: string[];
|
|
29
|
+
model?: e.Providers;
|
|
30
|
+
parallel?: boolean;
|
|
31
|
+
/** Optional simple condition on content/tools */
|
|
32
|
+
when?: 'always' | 'has_tools' | 'no_tools' | {
|
|
33
|
+
includes?: string[];
|
|
34
|
+
excludes?: string[];
|
|
35
|
+
};
|
|
36
|
+
}>;
|
|
37
|
+
/** Opt-in feature flags */
|
|
38
|
+
featureFlags?: {
|
|
39
|
+
multi_model_routing?: boolean;
|
|
40
|
+
fan_out?: boolean;
|
|
41
|
+
fan_out_retries?: number;
|
|
42
|
+
fan_out_backoff_ms?: number;
|
|
43
|
+
fan_out_concurrency?: number;
|
|
44
|
+
};
|
|
45
|
+
/** Optional per-stage model configs */
|
|
46
|
+
models?: Record<string, l.LLMConfig>;
|
|
47
|
+
} & Omit<g.StandardGraphInput, 'provider' | 'clientOptions'>;
|
|
19
48
|
export type RunTitleOptions = {
|
|
20
49
|
inputText: string;
|
|
50
|
+
provider: e.Providers;
|
|
21
51
|
contentParts: (s.MessageContentComplex | undefined)[];
|
|
22
52
|
titlePrompt?: string;
|
|
23
53
|
skipLanguage?: boolean;
|
|
24
54
|
clientOptions?: l.ClientOptions;
|
|
25
55
|
chainOptions?: Partial<RunnableConfig> | undefined;
|
|
56
|
+
omitOptions?: Set<string>;
|
|
57
|
+
titleMethod?: e.TitleMethod;
|
|
58
|
+
titlePromptTemplate?: string;
|
|
26
59
|
};
|
|
27
60
|
export interface AgentStateChannels {
|
|
28
61
|
messages: BaseMessage[];
|
|
@@ -53,18 +86,23 @@ export type TaskManagerGraphConfig = {
|
|
|
53
86
|
llmConfig: l.LLMConfig;
|
|
54
87
|
};
|
|
55
88
|
};
|
|
89
|
+
export type MultiAgentGraphConfig = {
|
|
90
|
+
type: 'multi-agent';
|
|
91
|
+
compileOptions?: g.CompileOptions;
|
|
92
|
+
agents: g.AgentInputs[];
|
|
93
|
+
edges: g.GraphEdge[];
|
|
94
|
+
};
|
|
56
95
|
export type RunConfig = {
|
|
57
96
|
runId: string;
|
|
58
|
-
graphConfig:
|
|
97
|
+
graphConfig: LegacyGraphConfig | MultiAgentGraphConfig;
|
|
59
98
|
customHandlers?: Record<string, g.EventHandler>;
|
|
60
99
|
returnContent?: boolean;
|
|
100
|
+
tokenCounter?: TokenCounter;
|
|
101
|
+
indexTokenCountMap?: Record<string, number>;
|
|
61
102
|
};
|
|
62
103
|
export type ProvidedCallbacks = (BaseCallbackHandler | CallbackHandlerMethods)[] | undefined;
|
|
63
104
|
export type TokenCounter = (message: BaseMessage) => number;
|
|
64
105
|
export type EventStreamOptions = {
|
|
65
|
-
callbacks?:
|
|
106
|
+
callbacks?: g.ClientCallbacks;
|
|
66
107
|
keepContent?: boolean;
|
|
67
|
-
maxContextTokens?: number;
|
|
68
|
-
tokenCounter?: TokenCounter;
|
|
69
|
-
indexTokenCountMap?: Record<string, number>;
|
|
70
108
|
};
|
|
@@ -2,6 +2,8 @@ import type OpenAITypes from 'openai';
|
|
|
2
2
|
import type { MessageContentImageUrl, MessageContentText, ToolMessage, BaseMessage } from '@langchain/core/messages';
|
|
3
3
|
import type { ToolCall, ToolCallChunk } from '@langchain/core/messages/tool';
|
|
4
4
|
import type { LLMResult, Generation } from '@langchain/core/outputs';
|
|
5
|
+
import type { AnthropicContentBlock } from '@/llm/anthropic/types';
|
|
6
|
+
import type { Command } from '@langchain/langgraph';
|
|
5
7
|
import type { ToolEndEvent } from '@/types/tools';
|
|
6
8
|
import { StepTypes, ContentTypes, GraphEvents } from '@/common/enum';
|
|
7
9
|
export type HandleLLMEnd = (output: LLMResult, runId: string, parentRunId?: string, tags?: string[]) => void;
|
|
@@ -64,7 +66,7 @@ export type MessageCreationDetails = {
|
|
|
64
66
|
};
|
|
65
67
|
export type ToolEndData = {
|
|
66
68
|
input: string | Record<string, unknown>;
|
|
67
|
-
output?: ToolMessage;
|
|
69
|
+
output?: ToolMessage | Command;
|
|
68
70
|
};
|
|
69
71
|
export type ToolErrorData = {
|
|
70
72
|
id: string;
|
|
@@ -191,6 +193,11 @@ export type ReasoningContentText = {
|
|
|
191
193
|
type: ContentTypes.THINK;
|
|
192
194
|
think: string;
|
|
193
195
|
};
|
|
196
|
+
/** Vertex AI / Google Common - Reasoning Content Block Format */
|
|
197
|
+
export type GoogleReasoningContentText = {
|
|
198
|
+
type: ContentTypes.REASONING;
|
|
199
|
+
reasoning: string;
|
|
200
|
+
};
|
|
194
201
|
/** Anthropic's Reasoning Content Block Format */
|
|
195
202
|
export type ThinkingContentText = {
|
|
196
203
|
type: ContentTypes.THINKING;
|
|
@@ -230,7 +237,14 @@ export type ToolCallContent = {
|
|
|
230
237
|
type: ContentTypes.TOOL_CALL;
|
|
231
238
|
tool_call?: ToolCallPart;
|
|
232
239
|
};
|
|
233
|
-
export type
|
|
240
|
+
export type ToolResultContent = {
|
|
241
|
+
content: string | Record<string, unknown> | Array<string | Record<string, unknown>> | AnthropicContentBlock[];
|
|
242
|
+
type: 'tool_result' | 'web_search_result' | 'web_search_tool_result';
|
|
243
|
+
tool_use_id?: string;
|
|
244
|
+
input?: string | Record<string, unknown>;
|
|
245
|
+
index?: number;
|
|
246
|
+
};
|
|
247
|
+
export type MessageContentComplex = (ToolResultContent | ThinkingContentText | AgentUpdate | ToolCallContent | ReasoningContentText | MessageContentText | MessageContentImageUrl | (Record<string, any> & {
|
|
234
248
|
type?: 'text' | 'image_url' | 'think' | 'thinking' | string;
|
|
235
249
|
}) | (Record<string, any> & {
|
|
236
250
|
type?: never;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { RunnableToolLike } from '@langchain/core/runnables';
|
|
2
1
|
import type { StructuredToolInterface } from '@langchain/core/tools';
|
|
2
|
+
import type { RunnableToolLike } from '@langchain/core/runnables';
|
|
3
3
|
import type { ToolCall } from '@langchain/core/messages/tool';
|
|
4
4
|
import type { ToolErrorData } from './stream';
|
|
5
5
|
import { EnvVar } from '@/common';
|