@librechat/agents 2.4.22 → 2.4.31
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/common/enum.cjs +1 -0
- package/dist/cjs/common/enum.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/index.cjs +1 -1
- package/dist/cjs/llm/anthropic/index.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/types.cjs +50 -0
- package/dist/cjs/llm/anthropic/types.cjs.map +1 -0
- package/dist/cjs/llm/anthropic/utils/message_inputs.cjs +227 -21
- package/dist/cjs/llm/anthropic/utils/message_inputs.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/utils/message_outputs.cjs +1 -0
- package/dist/cjs/llm/anthropic/utils/message_outputs.cjs.map +1 -1
- package/dist/cjs/llm/openai/index.cjs.map +1 -1
- package/dist/cjs/main.cjs +2 -0
- package/dist/cjs/main.cjs.map +1 -1
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/cjs/tools/search/firecrawl.cjs +149 -0
- package/dist/cjs/tools/search/firecrawl.cjs.map +1 -0
- package/dist/cjs/tools/search/format.cjs +116 -0
- package/dist/cjs/tools/search/format.cjs.map +1 -0
- package/dist/cjs/tools/search/highlights.cjs +193 -0
- package/dist/cjs/tools/search/highlights.cjs.map +1 -0
- package/dist/cjs/tools/search/rerankers.cjs +187 -0
- package/dist/cjs/tools/search/rerankers.cjs.map +1 -0
- package/dist/cjs/tools/search/search.cjs +410 -0
- package/dist/cjs/tools/search/search.cjs.map +1 -0
- package/dist/cjs/tools/search/tool.cjs +103 -0
- package/dist/cjs/tools/search/tool.cjs.map +1 -0
- package/dist/esm/common/enum.mjs +1 -0
- package/dist/esm/common/enum.mjs.map +1 -1
- package/dist/esm/llm/anthropic/index.mjs +1 -1
- package/dist/esm/llm/anthropic/index.mjs.map +1 -1
- package/dist/esm/llm/anthropic/types.mjs +48 -0
- package/dist/esm/llm/anthropic/types.mjs.map +1 -0
- package/dist/esm/llm/anthropic/utils/message_inputs.mjs +228 -22
- package/dist/esm/llm/anthropic/utils/message_inputs.mjs.map +1 -1
- package/dist/esm/llm/anthropic/utils/message_outputs.mjs +1 -0
- package/dist/esm/llm/anthropic/utils/message_outputs.mjs.map +1 -1
- package/dist/esm/llm/openai/index.mjs.map +1 -1
- package/dist/esm/main.mjs +1 -0
- package/dist/esm/main.mjs.map +1 -1
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/tools/search/firecrawl.mjs +145 -0
- package/dist/esm/tools/search/firecrawl.mjs.map +1 -0
- package/dist/esm/tools/search/format.mjs +114 -0
- package/dist/esm/tools/search/format.mjs.map +1 -0
- package/dist/esm/tools/search/highlights.mjs +191 -0
- package/dist/esm/tools/search/highlights.mjs.map +1 -0
- package/dist/esm/tools/search/rerankers.mjs +181 -0
- package/dist/esm/tools/search/rerankers.mjs.map +1 -0
- package/dist/esm/tools/search/search.mjs +407 -0
- package/dist/esm/tools/search/search.mjs.map +1 -0
- package/dist/esm/tools/search/tool.mjs +101 -0
- package/dist/esm/tools/search/tool.mjs.map +1 -0
- package/dist/types/common/enum.d.ts +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/llm/anthropic/index.d.ts +3 -4
- package/dist/types/llm/anthropic/types.d.ts +4 -35
- package/dist/types/llm/anthropic/utils/message_inputs.d.ts +2 -2
- package/dist/types/llm/anthropic/utils/message_outputs.d.ts +1 -3
- package/dist/types/llm/anthropic/utils/output_parsers.d.ts +22 -0
- package/dist/types/llm/openai/index.d.ts +3 -2
- package/dist/types/scripts/search.d.ts +1 -0
- package/dist/types/tools/example.d.ts +21 -3
- package/dist/types/tools/search/firecrawl.d.ts +117 -0
- package/dist/types/tools/search/format.d.ts +2 -0
- package/dist/types/tools/search/highlights.d.ts +13 -0
- package/dist/types/tools/search/index.d.ts +2 -0
- package/dist/types/tools/search/rerankers.d.ts +32 -0
- package/dist/types/tools/search/search.d.ts +9 -0
- package/dist/types/tools/search/tool.d.ts +12 -0
- package/dist/types/tools/search/types.d.ts +150 -0
- package/package.json +10 -9
- package/src/common/enum.ts +1 -0
- package/src/index.ts +1 -0
- package/src/llm/anthropic/index.ts +6 -5
- package/src/llm/anthropic/llm.spec.ts +176 -179
- package/src/llm/anthropic/types.ts +64 -39
- package/src/llm/anthropic/utils/message_inputs.ts +275 -37
- package/src/llm/anthropic/utils/message_outputs.ts +4 -21
- package/src/llm/anthropic/utils/output_parsers.ts +114 -0
- package/src/llm/openai/index.ts +7 -6
- package/src/run.ts +1 -1
- package/src/scripts/search.ts +141 -0
- package/src/tools/search/firecrawl.ts +270 -0
- package/src/tools/search/format.ts +121 -0
- package/src/tools/search/highlights.ts +237 -0
- package/src/tools/search/index.ts +2 -0
- package/src/tools/search/rerankers.ts +248 -0
- package/src/tools/search/search.ts +567 -0
- package/src/tools/search/tool.ts +151 -0
- package/src/tools/search/types.ts +179 -0
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import Anthropic from '@anthropic-ai/sdk';
|
|
2
|
-
import type { Tool as AnthropicTool } from '@anthropic-ai/sdk/resources';
|
|
3
2
|
import { BindToolsInput } from '@langchain/core/language_models/chat_models';
|
|
4
3
|
export type AnthropicToolResponse = {
|
|
5
4
|
type: 'tool_use';
|
|
@@ -7,19 +6,21 @@ export type AnthropicToolResponse = {
|
|
|
7
6
|
name: string;
|
|
8
7
|
input: Record<string, any>;
|
|
9
8
|
};
|
|
9
|
+
export type AnthropicStreamUsage = Anthropic.Usage;
|
|
10
10
|
export type AnthropicMessageParam = Anthropic.MessageParam;
|
|
11
11
|
export type AnthropicMessageDeltaEvent = Anthropic.MessageDeltaEvent;
|
|
12
12
|
export type AnthropicMessageStartEvent = Anthropic.MessageStartEvent;
|
|
13
13
|
export type AnthropicMessageResponse = Anthropic.ContentBlock | AnthropicToolResponse;
|
|
14
14
|
export type AnthropicMessageCreateParams = Anthropic.MessageCreateParamsNonStreaming;
|
|
15
15
|
export type AnthropicStreamingMessageCreateParams = Anthropic.MessageCreateParamsStreaming;
|
|
16
|
+
export type AnthropicThinkingConfigParam = Anthropic.ThinkingConfigParam;
|
|
16
17
|
export type AnthropicMessageStreamEvent = Anthropic.MessageStreamEvent;
|
|
17
18
|
export type AnthropicRequestOptions = Anthropic.RequestOptions;
|
|
18
19
|
export type AnthropicToolChoice = {
|
|
19
20
|
type: 'tool';
|
|
20
21
|
name: string;
|
|
21
22
|
} | 'any' | 'auto' | 'none' | string;
|
|
22
|
-
export type ChatAnthropicToolType =
|
|
23
|
+
export type ChatAnthropicToolType = Anthropic.Messages.Tool | BindToolsInput;
|
|
23
24
|
export type AnthropicTextBlockParam = Anthropic.Messages.TextBlockParam;
|
|
24
25
|
export type AnthropicImageBlockParam = Anthropic.Messages.ImageBlockParam;
|
|
25
26
|
export type AnthropicToolUseBlockParam = Anthropic.Messages.ToolUseBlockParam;
|
|
@@ -27,36 +28,4 @@ export type AnthropicToolResultBlockParam = Anthropic.Messages.ToolResultBlockPa
|
|
|
27
28
|
export type AnthropicDocumentBlockParam = Anthropic.Messages.DocumentBlockParam;
|
|
28
29
|
export type AnthropicThinkingBlockParam = Anthropic.Messages.ThinkingBlockParam;
|
|
29
30
|
export type AnthropicRedactedThinkingBlockParam = Anthropic.Messages.RedactedThinkingBlockParam;
|
|
30
|
-
|
|
31
|
-
* Stream usage information for Anthropic API calls
|
|
32
|
-
* @see https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching#pricing
|
|
33
|
-
*/
|
|
34
|
-
export interface AnthropicStreamUsage {
|
|
35
|
-
/**
|
|
36
|
-
* The number of input tokens used in the request
|
|
37
|
-
*/
|
|
38
|
-
input_tokens: number;
|
|
39
|
-
/**
|
|
40
|
-
* The number of cache creation input tokens used (write operations)
|
|
41
|
-
*/
|
|
42
|
-
cache_creation_input_tokens?: number;
|
|
43
|
-
/**
|
|
44
|
-
* The number of cache input tokens used (read operations)
|
|
45
|
-
*/
|
|
46
|
-
cache_read_input_tokens?: number;
|
|
47
|
-
/**
|
|
48
|
-
* The number of output tokens generated in the response
|
|
49
|
-
*/
|
|
50
|
-
output_tokens: number;
|
|
51
|
-
/**
|
|
52
|
-
* The total number of tokens generated in the response
|
|
53
|
-
*/
|
|
54
|
-
total_tokens: number;
|
|
55
|
-
/**
|
|
56
|
-
* Details about input token usage
|
|
57
|
-
*/
|
|
58
|
-
input_token_details?: {
|
|
59
|
-
cache_creation: number;
|
|
60
|
-
cache_read: number;
|
|
61
|
-
};
|
|
62
|
-
}
|
|
31
|
+
export declare function isAnthropicImageBlockParam(block: unknown): block is AnthropicImageBlockParam;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* This util file contains functions for converting LangChain messages to Anthropic messages.
|
|
3
3
|
*/
|
|
4
|
-
import { BaseMessage } from '@langchain/core/messages';
|
|
4
|
+
import { type BaseMessage } from '@langchain/core/messages';
|
|
5
5
|
import { ToolCall } from '@langchain/core/messages/tool';
|
|
6
|
-
import type {
|
|
6
|
+
import type { AnthropicMessageCreateParams, AnthropicToolResponse } from '@/llm/anthropic/types';
|
|
7
7
|
export declare function _convertLangChainToolCallToAnthropic(toolCall: ToolCall): AnthropicToolResponse;
|
|
8
8
|
/**
|
|
9
9
|
* Formats messages as a prompt for the model.
|
|
@@ -3,10 +3,8 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import Anthropic from '@anthropic-ai/sdk';
|
|
5
5
|
import { AIMessageChunk } from '@langchain/core/messages';
|
|
6
|
-
import { ToolCall } from '@langchain/core/messages/tool';
|
|
7
6
|
import { ChatGeneration } from '@langchain/core/outputs';
|
|
8
|
-
import { AnthropicMessageResponse } from '../types
|
|
9
|
-
export declare function extractToolCalls(content: Record<string, any>[]): ToolCall[];
|
|
7
|
+
import { AnthropicMessageResponse } from '../types';
|
|
10
8
|
export declare function _makeMessageChunkFromAnthropicEvent(data: Anthropic.Messages.RawMessageStreamEvent, fields: {
|
|
11
9
|
streamUsage: boolean;
|
|
12
10
|
coerceContentToString: boolean;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { BaseLLMOutputParser } from '@langchain/core/output_parsers';
|
|
3
|
+
import { JsonOutputKeyToolsParserParams } from '@langchain/core/output_parsers/openai_tools';
|
|
4
|
+
import { ChatGeneration } from '@langchain/core/outputs';
|
|
5
|
+
import { ToolCall } from '@langchain/core/messages/tool';
|
|
6
|
+
interface AnthropicToolsOutputParserParams<T extends Record<string, any>> extends JsonOutputKeyToolsParserParams<T> {
|
|
7
|
+
}
|
|
8
|
+
export declare class AnthropicToolsOutputParser<T extends Record<string, any> = Record<string, any>> extends BaseLLMOutputParser<T> {
|
|
9
|
+
static lc_name(): string;
|
|
10
|
+
lc_namespace: string[];
|
|
11
|
+
returnId: boolean;
|
|
12
|
+
/** The type of tool calls to return. */
|
|
13
|
+
keyName: string;
|
|
14
|
+
/** Whether to return only the first tool call. */
|
|
15
|
+
returnSingle: boolean;
|
|
16
|
+
zodSchema?: z.ZodType<T>;
|
|
17
|
+
constructor(params: AnthropicToolsOutputParserParams<T>);
|
|
18
|
+
protected _validateResult(result: unknown): Promise<T>;
|
|
19
|
+
parseResult(generations: ChatGeneration[]): Promise<T>;
|
|
20
|
+
}
|
|
21
|
+
export declare function extractToolCalls(content: Record<string, any>[]): ToolCall[];
|
|
22
|
+
export {};
|
|
@@ -2,6 +2,7 @@ import { AzureOpenAI as AzureOpenAIClient } from 'openai';
|
|
|
2
2
|
import { ChatXAI as OriginalChatXAI } from '@langchain/xai';
|
|
3
3
|
import { ChatDeepSeek as OriginalChatDeepSeek } from '@langchain/deepseek';
|
|
4
4
|
import { OpenAIClient, ChatOpenAI as OriginalChatOpenAI, AzureChatOpenAI as OriginalAzureChatOpenAI } from '@langchain/openai';
|
|
5
|
+
import type { OpenAICoreRequestOptions } from 'node_modules/@langchain/deepseek/node_modules/@langchain/openai';
|
|
5
6
|
import type * as t from '@langchain/openai';
|
|
6
7
|
export declare class CustomOpenAIClient extends OpenAIClient {
|
|
7
8
|
abortHandler?: () => void;
|
|
@@ -21,9 +22,9 @@ export declare class AzureChatOpenAI extends OriginalAzureChatOpenAI {
|
|
|
21
22
|
}
|
|
22
23
|
export declare class ChatDeepSeek extends OriginalChatDeepSeek {
|
|
23
24
|
get exposedClient(): CustomOpenAIClient;
|
|
24
|
-
protected _getClientOptions(options?:
|
|
25
|
+
protected _getClientOptions(options?: OpenAICoreRequestOptions): OpenAICoreRequestOptions;
|
|
25
26
|
}
|
|
26
27
|
export declare class ChatXAI extends OriginalChatXAI {
|
|
27
28
|
get exposedClient(): CustomOpenAIClient;
|
|
28
|
-
protected _getClientOptions(options?:
|
|
29
|
+
protected _getClientOptions(options?: OpenAICoreRequestOptions): OpenAICoreRequestOptions;
|
|
29
30
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -7,14 +7,22 @@ export declare const fetchRandomImageTool: DynamicStructuredTool<z.ZodObject<{
|
|
|
7
7
|
input?: string | undefined;
|
|
8
8
|
}, {
|
|
9
9
|
input?: string | undefined;
|
|
10
|
-
}
|
|
10
|
+
}>, {
|
|
11
|
+
input?: string | undefined;
|
|
12
|
+
}, {
|
|
13
|
+
input?: string | undefined;
|
|
14
|
+
}>;
|
|
11
15
|
export declare const fetchRandomImageURL: DynamicStructuredTool<z.ZodObject<{
|
|
12
16
|
input: z.ZodOptional<z.ZodString>;
|
|
13
17
|
}, "strip", z.ZodTypeAny, {
|
|
14
18
|
input?: string | undefined;
|
|
15
19
|
}, {
|
|
16
20
|
input?: string | undefined;
|
|
17
|
-
}
|
|
21
|
+
}>, {
|
|
22
|
+
input?: string | undefined;
|
|
23
|
+
}, {
|
|
24
|
+
input?: string | undefined;
|
|
25
|
+
}>;
|
|
18
26
|
export declare const chartTool: DynamicStructuredTool<z.ZodObject<{
|
|
19
27
|
data: z.ZodArray<z.ZodObject<{
|
|
20
28
|
label: z.ZodString;
|
|
@@ -36,5 +44,15 @@ export declare const chartTool: DynamicStructuredTool<z.ZodObject<{
|
|
|
36
44
|
value: number;
|
|
37
45
|
label: string;
|
|
38
46
|
}[];
|
|
39
|
-
}
|
|
47
|
+
}>, {
|
|
48
|
+
data: {
|
|
49
|
+
value: number;
|
|
50
|
+
label: string;
|
|
51
|
+
}[];
|
|
52
|
+
}, {
|
|
53
|
+
data: {
|
|
54
|
+
value: number;
|
|
55
|
+
label: string;
|
|
56
|
+
}[];
|
|
57
|
+
}>;
|
|
40
58
|
export declare const tavilyTool: TavilySearchResults;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
export interface FirecrawlScrapeOptions {
|
|
2
|
+
formats?: string[];
|
|
3
|
+
includeTags?: string[];
|
|
4
|
+
excludeTags?: string[];
|
|
5
|
+
headers?: Record<string, string>;
|
|
6
|
+
waitFor?: number;
|
|
7
|
+
timeout?: number;
|
|
8
|
+
}
|
|
9
|
+
interface ScrapeMetadata {
|
|
10
|
+
sourceURL?: string;
|
|
11
|
+
url?: string;
|
|
12
|
+
scrapeId?: string;
|
|
13
|
+
statusCode?: number;
|
|
14
|
+
title?: string;
|
|
15
|
+
description?: string;
|
|
16
|
+
language?: string;
|
|
17
|
+
favicon?: string;
|
|
18
|
+
viewport?: string;
|
|
19
|
+
robots?: string;
|
|
20
|
+
'theme-color'?: string;
|
|
21
|
+
'og:url'?: string;
|
|
22
|
+
'og:title'?: string;
|
|
23
|
+
'og:description'?: string;
|
|
24
|
+
'og:type'?: string;
|
|
25
|
+
'og:image'?: string;
|
|
26
|
+
'og:image:width'?: string;
|
|
27
|
+
'og:image:height'?: string;
|
|
28
|
+
'og:site_name'?: string;
|
|
29
|
+
ogUrl?: string;
|
|
30
|
+
ogTitle?: string;
|
|
31
|
+
ogDescription?: string;
|
|
32
|
+
ogImage?: string;
|
|
33
|
+
ogSiteName?: string;
|
|
34
|
+
'article:author'?: string;
|
|
35
|
+
'article:published_time'?: string;
|
|
36
|
+
'article:modified_time'?: string;
|
|
37
|
+
'article:section'?: string;
|
|
38
|
+
'article:tag'?: string;
|
|
39
|
+
'article:publisher'?: string;
|
|
40
|
+
publishedTime?: string;
|
|
41
|
+
modifiedTime?: string;
|
|
42
|
+
'twitter:site'?: string;
|
|
43
|
+
'twitter:creator'?: string;
|
|
44
|
+
'twitter:card'?: string;
|
|
45
|
+
'twitter:image'?: string;
|
|
46
|
+
'twitter:dnt'?: string;
|
|
47
|
+
'twitter:app:name:iphone'?: string;
|
|
48
|
+
'twitter:app:id:iphone'?: string;
|
|
49
|
+
'twitter:app:url:iphone'?: string;
|
|
50
|
+
'twitter:app:name:ipad'?: string;
|
|
51
|
+
'twitter:app:id:ipad'?: string;
|
|
52
|
+
'twitter:app:url:ipad'?: string;
|
|
53
|
+
'twitter:app:name:googleplay'?: string;
|
|
54
|
+
'twitter:app:id:googleplay'?: string;
|
|
55
|
+
'twitter:app:url:googleplay'?: string;
|
|
56
|
+
'fb:app_id'?: string;
|
|
57
|
+
'al:ios:url'?: string;
|
|
58
|
+
'al:ios:app_name'?: string;
|
|
59
|
+
'al:ios:app_store_id'?: string;
|
|
60
|
+
[key: string]: string | number | boolean | null | undefined;
|
|
61
|
+
}
|
|
62
|
+
export interface FirecrawlScrapeResponse {
|
|
63
|
+
success: boolean;
|
|
64
|
+
data?: {
|
|
65
|
+
markdown?: string;
|
|
66
|
+
html?: string;
|
|
67
|
+
rawHtml?: string;
|
|
68
|
+
screenshot?: string;
|
|
69
|
+
links?: string[];
|
|
70
|
+
metadata?: ScrapeMetadata;
|
|
71
|
+
};
|
|
72
|
+
error?: string;
|
|
73
|
+
}
|
|
74
|
+
export interface FirecrawlScraperConfig {
|
|
75
|
+
apiKey?: string;
|
|
76
|
+
apiUrl?: string;
|
|
77
|
+
formats?: string[];
|
|
78
|
+
timeout?: number;
|
|
79
|
+
}
|
|
80
|
+
export declare function getAttribution(link: string, metadata?: ScrapeMetadata): string | undefined;
|
|
81
|
+
/**
|
|
82
|
+
* Firecrawl scraper implementation
|
|
83
|
+
* Uses the Firecrawl API to scrape web pages
|
|
84
|
+
*/
|
|
85
|
+
export declare class FirecrawlScraper {
|
|
86
|
+
private apiKey;
|
|
87
|
+
private apiUrl;
|
|
88
|
+
private defaultFormats;
|
|
89
|
+
private timeout;
|
|
90
|
+
constructor(config?: FirecrawlScraperConfig);
|
|
91
|
+
/**
|
|
92
|
+
* Scrape a single URL
|
|
93
|
+
* @param url URL to scrape
|
|
94
|
+
* @param options Scrape options
|
|
95
|
+
* @returns Scrape response
|
|
96
|
+
*/
|
|
97
|
+
scrapeUrl(url: string, options?: FirecrawlScrapeOptions): Promise<[string, FirecrawlScrapeResponse]>;
|
|
98
|
+
/**
|
|
99
|
+
* Extract content from scrape response
|
|
100
|
+
* @param response Scrape response
|
|
101
|
+
* @returns Extracted content or empty string if not available
|
|
102
|
+
*/
|
|
103
|
+
extractContent(response: FirecrawlScrapeResponse): string;
|
|
104
|
+
/**
|
|
105
|
+
* Extract metadata from scrape response
|
|
106
|
+
* @param response Scrape response
|
|
107
|
+
* @returns Metadata object
|
|
108
|
+
*/
|
|
109
|
+
extractMetadata(response: FirecrawlScrapeResponse): ScrapeMetadata;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Create a Firecrawl scraper instance
|
|
113
|
+
* @param config Scraper configuration
|
|
114
|
+
* @returns Firecrawl scraper instance
|
|
115
|
+
*/
|
|
116
|
+
export declare const createFirecrawlScraper: (config?: FirecrawlScraperConfig) => FirecrawlScraper;
|
|
117
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type * as t from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Expand highlights in search results using smart boundary detection.
|
|
4
|
+
*
|
|
5
|
+
* This implementation finds natural text boundaries like paragraphs, sentences,
|
|
6
|
+
* and phrases to provide context while maintaining readability.
|
|
7
|
+
*
|
|
8
|
+
* @param searchResults - Search results object
|
|
9
|
+
* @param mainExpandBy - Primary expansion size on each side (default: 300)
|
|
10
|
+
* @param separatorExpandBy - Additional range to look for separators (default: 150)
|
|
11
|
+
* @returns Copy of search results with expanded highlights
|
|
12
|
+
*/
|
|
13
|
+
export declare function expandHighlights(searchResults: t.SearchResultData, mainExpandBy?: number, separatorExpandBy?: number): t.SearchResultData;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type * as t from './types';
|
|
2
|
+
export declare abstract class BaseReranker {
|
|
3
|
+
protected apiKey: string | undefined;
|
|
4
|
+
constructor();
|
|
5
|
+
abstract rerank(query: string, documents: string[], topK?: number): Promise<t.Highlight[]>;
|
|
6
|
+
protected getDefaultRanking(documents: string[], topK: number): t.Highlight[];
|
|
7
|
+
protected logDocumentSamples(documents: string[]): void;
|
|
8
|
+
}
|
|
9
|
+
export declare class JinaReranker extends BaseReranker {
|
|
10
|
+
constructor({ apiKey }: {
|
|
11
|
+
apiKey?: string;
|
|
12
|
+
});
|
|
13
|
+
rerank(query: string, documents: string[], topK?: number): Promise<t.Highlight[]>;
|
|
14
|
+
}
|
|
15
|
+
export declare class CohereReranker extends BaseReranker {
|
|
16
|
+
constructor({ apiKey }: {
|
|
17
|
+
apiKey?: string;
|
|
18
|
+
});
|
|
19
|
+
rerank(query: string, documents: string[], topK?: number): Promise<t.Highlight[]>;
|
|
20
|
+
}
|
|
21
|
+
export declare class InfinityReranker extends BaseReranker {
|
|
22
|
+
constructor();
|
|
23
|
+
rerank(query: string, documents: string[], topK?: number): Promise<t.Highlight[]>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Creates the appropriate reranker based on type and configuration
|
|
27
|
+
*/
|
|
28
|
+
export declare const createReranker: (config: {
|
|
29
|
+
rerankerType: t.RerankerType;
|
|
30
|
+
jinaApiKey?: string;
|
|
31
|
+
cohereApiKey?: string;
|
|
32
|
+
}) => BaseReranker | undefined;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type * as t from './types';
|
|
2
|
+
import { FirecrawlScraper } from './firecrawl';
|
|
3
|
+
export declare const createSearchAPI: (config: t.SearchConfig) => {
|
|
4
|
+
getSources: (query: string, numResults?: number, storedLocation?: string) => Promise<t.SearchResult>;
|
|
5
|
+
};
|
|
6
|
+
export declare const createSourceProcessor: (config?: t.ProcessSourcesConfig, scraperInstance?: FirecrawlScraper) => {
|
|
7
|
+
processSources: (result: t.SearchResult, numElements: number, query: string, proMode?: boolean) => Promise<t.SearchResultData>;
|
|
8
|
+
topResults: number;
|
|
9
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { DynamicStructuredTool } from '@langchain/core/tools';
|
|
3
|
+
import type * as t from './types';
|
|
4
|
+
declare const SearchToolSchema: z.ZodObject<{
|
|
5
|
+
query: z.ZodString;
|
|
6
|
+
}, "strip", z.ZodTypeAny, {
|
|
7
|
+
query: string;
|
|
8
|
+
}, {
|
|
9
|
+
query: string;
|
|
10
|
+
}>;
|
|
11
|
+
export declare const createSearchTool: (config?: t.SearchToolConfig) => DynamicStructuredTool<typeof SearchToolSchema>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import type { RunnableConfig } from '@langchain/core/runnables';
|
|
2
|
+
import type { BaseReranker } from './rerankers';
|
|
3
|
+
export type SearchProvider = 'serper' | 'searxng';
|
|
4
|
+
export type RerankerType = 'infinity' | 'jina' | 'cohere' | 'none';
|
|
5
|
+
export interface OrganicResult {
|
|
6
|
+
position?: number;
|
|
7
|
+
title?: string;
|
|
8
|
+
link: string;
|
|
9
|
+
snippet?: string;
|
|
10
|
+
date?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface TopStoryResult {
|
|
13
|
+
title?: string;
|
|
14
|
+
link: string;
|
|
15
|
+
source?: string;
|
|
16
|
+
date?: string;
|
|
17
|
+
imageUrl?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface ImageResult {
|
|
20
|
+
title?: string;
|
|
21
|
+
imageUrl?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface KnowledgeGraphResult {
|
|
24
|
+
title?: string;
|
|
25
|
+
type?: string;
|
|
26
|
+
description?: string;
|
|
27
|
+
attributes?: Record<string, string>;
|
|
28
|
+
imageUrl?: string;
|
|
29
|
+
}
|
|
30
|
+
export interface AnswerBoxResult {
|
|
31
|
+
title?: string;
|
|
32
|
+
answer?: string;
|
|
33
|
+
snippet?: string;
|
|
34
|
+
date?: string;
|
|
35
|
+
}
|
|
36
|
+
export interface PeopleAlsoAskResult {
|
|
37
|
+
question?: string;
|
|
38
|
+
answer?: string;
|
|
39
|
+
}
|
|
40
|
+
export interface Highlight {
|
|
41
|
+
score: number;
|
|
42
|
+
text: string;
|
|
43
|
+
}
|
|
44
|
+
export interface ValidSource {
|
|
45
|
+
link: string;
|
|
46
|
+
position?: number;
|
|
47
|
+
title?: string;
|
|
48
|
+
snippet?: string;
|
|
49
|
+
date?: string;
|
|
50
|
+
content?: string;
|
|
51
|
+
attribution?: string;
|
|
52
|
+
highlights?: Highlight[];
|
|
53
|
+
}
|
|
54
|
+
export interface SearchResultData {
|
|
55
|
+
organic?: ValidSource[];
|
|
56
|
+
topStories?: ValidSource[];
|
|
57
|
+
images?: ImageResult[];
|
|
58
|
+
knowledgeGraph?: KnowledgeGraphResult;
|
|
59
|
+
answerBox?: AnswerBoxResult;
|
|
60
|
+
peopleAlsoAsk?: PeopleAlsoAskResult[];
|
|
61
|
+
relatedSearches?: string[];
|
|
62
|
+
suggestions?: string[];
|
|
63
|
+
error?: string;
|
|
64
|
+
}
|
|
65
|
+
export interface SearchResult {
|
|
66
|
+
data?: SearchResultData;
|
|
67
|
+
error?: string;
|
|
68
|
+
success: boolean;
|
|
69
|
+
}
|
|
70
|
+
export interface Source {
|
|
71
|
+
link: string;
|
|
72
|
+
html?: string;
|
|
73
|
+
title?: string;
|
|
74
|
+
snippet?: string;
|
|
75
|
+
date?: string;
|
|
76
|
+
}
|
|
77
|
+
export interface SearchConfig {
|
|
78
|
+
searchProvider?: SearchProvider;
|
|
79
|
+
serperApiKey?: string;
|
|
80
|
+
searxngInstanceUrl?: string;
|
|
81
|
+
searxngApiKey?: string;
|
|
82
|
+
}
|
|
83
|
+
export interface ScrapeResult {
|
|
84
|
+
url: string;
|
|
85
|
+
error?: boolean;
|
|
86
|
+
content: string;
|
|
87
|
+
attribution?: string;
|
|
88
|
+
highlights?: Highlight[];
|
|
89
|
+
}
|
|
90
|
+
export interface ProcessSourcesConfig {
|
|
91
|
+
topResults?: number;
|
|
92
|
+
strategies?: string[];
|
|
93
|
+
filterContent?: boolean;
|
|
94
|
+
reranker?: BaseReranker;
|
|
95
|
+
}
|
|
96
|
+
export interface FirecrawlConfig {
|
|
97
|
+
firecrawlApiKey?: string;
|
|
98
|
+
firecrawlApiUrl?: string;
|
|
99
|
+
firecrawlFormats?: string[];
|
|
100
|
+
}
|
|
101
|
+
export interface ScraperContentResult {
|
|
102
|
+
content: string;
|
|
103
|
+
}
|
|
104
|
+
export interface ScraperExtractionResult {
|
|
105
|
+
no_extraction: ScraperContentResult;
|
|
106
|
+
}
|
|
107
|
+
export interface SearXNGResult {
|
|
108
|
+
title?: string;
|
|
109
|
+
url?: string;
|
|
110
|
+
content?: string;
|
|
111
|
+
publishedDate?: string;
|
|
112
|
+
img_src?: string;
|
|
113
|
+
}
|
|
114
|
+
export interface JinaRerankerResult {
|
|
115
|
+
index: number;
|
|
116
|
+
relevance_score: number;
|
|
117
|
+
document?: string | {
|
|
118
|
+
text: string;
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
export interface JinaRerankerResponse {
|
|
122
|
+
model: string;
|
|
123
|
+
usage: {
|
|
124
|
+
total_tokens: number;
|
|
125
|
+
};
|
|
126
|
+
results: JinaRerankerResult[];
|
|
127
|
+
}
|
|
128
|
+
export interface CohereRerankerResult {
|
|
129
|
+
index: number;
|
|
130
|
+
relevance_score: number;
|
|
131
|
+
}
|
|
132
|
+
export interface CohereRerankerResponse {
|
|
133
|
+
results: CohereRerankerResult[];
|
|
134
|
+
id: string;
|
|
135
|
+
meta: {
|
|
136
|
+
api_version: {
|
|
137
|
+
version: string;
|
|
138
|
+
is_experimental: boolean;
|
|
139
|
+
};
|
|
140
|
+
billed_units: {
|
|
141
|
+
search_units: number;
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
export interface SearchToolConfig extends SearchConfig, ProcessSourcesConfig, FirecrawlConfig {
|
|
146
|
+
jinaApiKey?: string;
|
|
147
|
+
cohereApiKey?: string;
|
|
148
|
+
rerankerType?: RerankerType;
|
|
149
|
+
onSearchResults?: (results: SearchResult, runnableConfig?: RunnableConfig) => void;
|
|
150
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@librechat/agents",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.31",
|
|
4
4
|
"main": "./dist/cjs/main.cjs",
|
|
5
5
|
"module": "./dist/esm/main.mjs",
|
|
6
6
|
"types": "./dist/types/index.d.ts",
|
|
@@ -52,6 +52,7 @@
|
|
|
52
52
|
"thinking": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/thinking.ts --name 'Jo' --location 'New York, NY'",
|
|
53
53
|
"memory": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/memory.ts --provider 'openAI' --name 'Jo' --location 'New York, NY'",
|
|
54
54
|
"tool-test": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/tools.ts --provider 'alibaba' --name 'Jo' --location 'New York, NY'",
|
|
55
|
+
"search": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/search.ts --provider 'anthropic' --name 'Jo' --location 'New York, NY'",
|
|
55
56
|
"abort": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/abort.ts --provider 'openAI' --name 'Jo' --location 'New York, NY'",
|
|
56
57
|
"start:cli2": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/cli2.ts --provider 'anthropic' --name 'Jo' --location 'New York, NY'",
|
|
57
58
|
"script2": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/proto/example_test.ts",
|
|
@@ -71,17 +72,17 @@
|
|
|
71
72
|
"format": "prettier --write ."
|
|
72
73
|
},
|
|
73
74
|
"dependencies": {
|
|
74
|
-
"@langchain/anthropic": "^0.3.
|
|
75
|
-
"@langchain/aws": "^0.1.
|
|
76
|
-
"@langchain/community": "^0.3.
|
|
77
|
-
"@langchain/core": "^0.3.
|
|
75
|
+
"@langchain/anthropic": "^0.3.20",
|
|
76
|
+
"@langchain/aws": "^0.1.9",
|
|
77
|
+
"@langchain/community": "^0.3.42",
|
|
78
|
+
"@langchain/core": "^0.3.51",
|
|
78
79
|
"@langchain/deepseek": "^0.0.1",
|
|
79
|
-
"@langchain/google-genai": "^0.2.
|
|
80
|
-
"@langchain/google-vertexai": "^0.2.
|
|
81
|
-
"@langchain/langgraph": "^0.2.
|
|
80
|
+
"@langchain/google-genai": "^0.2.5",
|
|
81
|
+
"@langchain/google-vertexai": "^0.2.5",
|
|
82
|
+
"@langchain/langgraph": "^0.2.67",
|
|
82
83
|
"@langchain/mistralai": "^0.2.0",
|
|
83
84
|
"@langchain/ollama": "^0.2.0",
|
|
84
|
-
"@langchain/openai": "^0.5.
|
|
85
|
+
"@langchain/openai": "^0.5.10",
|
|
85
86
|
"@langchain/xai": "^0.0.2",
|
|
86
87
|
"dotenv": "^16.4.7",
|
|
87
88
|
"https-proxy-agent": "^7.0.6",
|
package/src/common/enum.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { ChatGenerationChunk } from '@langchain/core/outputs';
|
|
|
4
4
|
import type { BaseChatModelParams } from '@langchain/core/language_models/chat_models';
|
|
5
5
|
import type {
|
|
6
6
|
BaseMessage,
|
|
7
|
+
UsageMetadata,
|
|
7
8
|
MessageContentComplex,
|
|
8
9
|
} from '@langchain/core/messages';
|
|
9
10
|
import type { CallbackManagerForLLMRun } from '@langchain/core/callbacks/manager';
|
|
@@ -132,9 +133,9 @@ export class CustomAnthropic extends ChatAnthropicMessages {
|
|
|
132
133
|
|
|
133
134
|
/**
|
|
134
135
|
* Get stream usage as returned by this client's API response.
|
|
135
|
-
* @returns
|
|
136
|
+
* @returns The stream usage object.
|
|
136
137
|
*/
|
|
137
|
-
getStreamUsage():
|
|
138
|
+
getStreamUsage(): UsageMetadata | undefined {
|
|
138
139
|
if (this.emitted_usage === true) {
|
|
139
140
|
return;
|
|
140
141
|
}
|
|
@@ -147,7 +148,7 @@ export class CustomAnthropic extends ChatAnthropicMessages {
|
|
|
147
148
|
if (!outputUsage) {
|
|
148
149
|
return;
|
|
149
150
|
}
|
|
150
|
-
const totalUsage:
|
|
151
|
+
const totalUsage: UsageMetadata = {
|
|
151
152
|
input_tokens: inputUsage?.input_tokens ?? 0,
|
|
152
153
|
output_tokens: outputUsage.output_tokens ?? 0,
|
|
153
154
|
total_tokens:
|
|
@@ -184,7 +185,7 @@ export class CustomAnthropic extends ChatAnthropicMessages {
|
|
|
184
185
|
token?: string;
|
|
185
186
|
chunk: AIMessageChunk;
|
|
186
187
|
shouldStreamUsage: boolean;
|
|
187
|
-
usageMetadata?:
|
|
188
|
+
usageMetadata?: UsageMetadata;
|
|
188
189
|
}): ChatGenerationChunk {
|
|
189
190
|
const usage_metadata = shouldStreamUsage
|
|
190
191
|
? (usageMetadata ?? chunk.usage_metadata)
|
|
@@ -245,7 +246,7 @@ export class CustomAnthropic extends ChatAnthropicMessages {
|
|
|
245
246
|
this.message_delta = data as AnthropicMessageDeltaEvent;
|
|
246
247
|
}
|
|
247
248
|
|
|
248
|
-
let usageMetadata:
|
|
249
|
+
let usageMetadata: UsageMetadata | undefined;
|
|
249
250
|
if (this.tools_in_params !== true && this.emitted_usage !== true) {
|
|
250
251
|
usageMetadata = this.getStreamUsage();
|
|
251
252
|
}
|