@librechat/agents 2.4.37 → 2.4.40
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 +2 -1
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/types.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/utils/message_inputs.cjs +13 -3
- 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/google/index.cjs +73 -0
- package/dist/cjs/llm/google/index.cjs.map +1 -0
- package/dist/cjs/llm/openai/index.cjs +101 -2
- package/dist/cjs/llm/openai/index.cjs.map +1 -1
- package/dist/cjs/llm/providers.cjs +11 -11
- package/dist/cjs/llm/providers.cjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +2 -1
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/llm/anthropic/types.mjs.map +1 -1
- package/dist/esm/llm/anthropic/utils/message_inputs.mjs +13 -3
- 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/google/index.mjs +71 -0
- package/dist/esm/llm/google/index.mjs.map +1 -0
- package/dist/esm/llm/openai/index.mjs +100 -4
- package/dist/esm/llm/openai/index.mjs.map +1 -1
- package/dist/esm/llm/providers.mjs +2 -2
- package/dist/esm/llm/providers.mjs.map +1 -1
- package/dist/types/llm/anthropic/types.d.ts +7 -3
- package/dist/types/llm/anthropic/utils/message_inputs.d.ts +1 -1
- package/dist/types/llm/anthropic/utils/output_parsers.d.ts +2 -2
- package/dist/types/llm/google/index.d.ts +8 -0
- package/dist/types/llm/openai/index.d.ts +37 -3
- package/dist/types/types/llm.d.ts +6 -3
- package/package.json +14 -14
- package/src/graphs/Graph.ts +3 -4
- package/src/llm/anthropic/types.ts +23 -3
- package/src/llm/anthropic/utils/message_inputs.ts +21 -5
- package/src/llm/anthropic/utils/message_outputs.ts +21 -2
- package/src/llm/anthropic/utils/output_parsers.ts +23 -4
- package/src/llm/google/index.ts +97 -0
- package/src/llm/openai/index.ts +170 -14
- package/src/llm/providers.ts +2 -2
- package/src/scripts/simple.ts +1 -1
- package/src/types/llm.ts +6 -3
- package/src/utils/llmConfig.ts +2 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../../../src/llm/openai/index.ts"],"sourcesContent":["import { AzureOpenAI as AzureOpenAIClient } from 'openai';\nimport { ChatXAI as OriginalChatXAI } from '@langchain/xai';\nimport { ChatDeepSeek as OriginalChatDeepSeek } from '@langchain/deepseek';\nimport {\n getEndpoint,\n OpenAIClient,\n ChatOpenAI as OriginalChatOpenAI,\n AzureChatOpenAI as OriginalAzureChatOpenAI,\n} from '@langchain/openai';\nimport type { OpenAICoreRequestOptions } from 'node_modules/@langchain/deepseek/node_modules/@langchain/openai';\nimport type * as t from '@langchain/openai';\n\nfunction createAbortHandler(controller: AbortController): () => void {\n return function (): void {\n controller.abort();\n };\n}\n\nexport class CustomOpenAIClient extends OpenAIClient {\n abortHandler?: () => void;\n async fetchWithTimeout(\n url: RequestInfo,\n init: RequestInit | undefined,\n ms: number,\n controller: AbortController\n ): Promise<Response> {\n const { signal, ...options } = init || {};\n const handler = createAbortHandler(controller);\n this.abortHandler = handler;\n if (signal) signal.addEventListener('abort', handler, { once: true });\n\n const timeout = setTimeout(() => handler, ms);\n\n const fetchOptions = {\n signal: controller.signal as AbortSignal,\n ...options,\n };\n if (fetchOptions.method != null) {\n // Custom methods like 'patch' need to be uppercased\n // See https://github.com/nodejs/undici/issues/2294\n fetchOptions.method = fetchOptions.method.toUpperCase();\n }\n\n return (\n // use undefined this binding; fetch errors if bound to something else in browser/cloudflare\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n /** @ts-ignore */\n this.fetch.call(undefined, url, fetchOptions).finally(() => {\n clearTimeout(timeout);\n })\n );\n }\n}\nexport class CustomAzureOpenAIClient extends AzureOpenAIClient {\n abortHandler?: () => void;\n async fetchWithTimeout(\n url: RequestInfo,\n init: RequestInit | undefined,\n ms: number,\n controller: AbortController\n ): Promise<Response> {\n const { signal, ...options } = init || {};\n const handler = createAbortHandler(controller);\n this.abortHandler = handler;\n if (signal) signal.addEventListener('abort', handler, { once: true });\n\n const timeout = setTimeout(() => handler, ms);\n\n const fetchOptions = {\n signal: controller.signal as AbortSignal,\n ...options,\n };\n if (fetchOptions.method != null) {\n // Custom methods like 'patch' need to be uppercased\n // See https://github.com/nodejs/undici/issues/2294\n fetchOptions.method = fetchOptions.method.toUpperCase();\n }\n\n return (\n // use undefined this binding; fetch errors if bound to something else in browser/cloudflare\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n /** @ts-ignore */\n this.fetch.call(undefined, url, fetchOptions).finally(() => {\n clearTimeout(timeout);\n })\n );\n }\n}\n\nexport class ChatOpenAI extends OriginalChatOpenAI<t.ChatOpenAICallOptions> {\n public get exposedClient(): CustomOpenAIClient {\n return this.client;\n }\n protected _getClientOptions(\n options?: t.OpenAICoreRequestOptions\n ): t.OpenAICoreRequestOptions {\n if (!(this.client as OpenAIClient | undefined)) {\n const openAIEndpointConfig: t.OpenAIEndpointConfig = {\n baseURL: this.clientConfig.baseURL,\n };\n\n const endpoint = getEndpoint(openAIEndpointConfig);\n const params = {\n ...this.clientConfig,\n baseURL: endpoint,\n timeout: this.timeout,\n maxRetries: 0,\n };\n if (params.baseURL == null) {\n delete params.baseURL;\n }\n\n this.client = new CustomOpenAIClient(params);\n }\n const requestOptions = {\n ...this.clientConfig,\n ...options,\n } as t.OpenAICoreRequestOptions;\n return requestOptions;\n }\n}\n\nexport class AzureChatOpenAI extends OriginalAzureChatOpenAI {\n public get exposedClient(): CustomOpenAIClient {\n return this.client;\n }\n protected _getClientOptions(\n options: t.OpenAICoreRequestOptions | undefined\n ): t.OpenAICoreRequestOptions {\n if (!(this.client as AzureOpenAIClient | undefined)) {\n const openAIEndpointConfig: t.OpenAIEndpointConfig = {\n azureOpenAIApiDeploymentName: this.azureOpenAIApiDeploymentName,\n azureOpenAIApiInstanceName: this.azureOpenAIApiInstanceName,\n azureOpenAIApiKey: this.azureOpenAIApiKey,\n azureOpenAIBasePath: this.azureOpenAIBasePath,\n azureADTokenProvider: this.azureADTokenProvider,\n baseURL: this.clientConfig.baseURL,\n };\n\n const endpoint = getEndpoint(openAIEndpointConfig);\n\n const params = {\n ...this.clientConfig,\n baseURL: endpoint,\n timeout: this.timeout,\n maxRetries: 0,\n };\n\n if (!this.azureADTokenProvider) {\n params.apiKey = openAIEndpointConfig.azureOpenAIApiKey;\n }\n\n if (params.baseURL == null) {\n delete params.baseURL;\n }\n\n params.defaultHeaders = {\n ...params.defaultHeaders,\n 'User-Agent':\n params.defaultHeaders?.['User-Agent'] != null\n ? `${params.defaultHeaders['User-Agent']}: langchainjs-azure-openai-v2`\n : 'langchainjs-azure-openai-v2',\n };\n\n this.client = new CustomAzureOpenAIClient({\n apiVersion: this.azureOpenAIApiVersion,\n azureADTokenProvider: this.azureADTokenProvider,\n ...params,\n });\n }\n\n const requestOptions = {\n ...this.clientConfig,\n ...options,\n } as t.OpenAICoreRequestOptions;\n if (this.azureOpenAIApiKey != null) {\n requestOptions.headers = {\n 'api-key': this.azureOpenAIApiKey,\n ...requestOptions.headers,\n };\n requestOptions.query = {\n 'api-version': this.azureOpenAIApiVersion,\n ...requestOptions.query,\n };\n }\n return requestOptions;\n }\n}\n\nexport class ChatDeepSeek extends OriginalChatDeepSeek {\n public get exposedClient(): CustomOpenAIClient {\n return this.client;\n }\n protected _getClientOptions(\n options?: OpenAICoreRequestOptions\n ): OpenAICoreRequestOptions {\n if (!(this.client as OpenAIClient | undefined)) {\n const openAIEndpointConfig: t.OpenAIEndpointConfig = {\n baseURL: this.clientConfig.baseURL,\n };\n\n const endpoint = getEndpoint(openAIEndpointConfig);\n const params = {\n ...this.clientConfig,\n baseURL: endpoint,\n timeout: this.timeout,\n maxRetries: 0,\n };\n if (params.baseURL == null) {\n delete params.baseURL;\n }\n\n this.client = new CustomOpenAIClient(params);\n }\n const requestOptions = {\n ...this.clientConfig,\n ...options,\n } as OpenAICoreRequestOptions;\n return requestOptions;\n }\n}\n\nexport class ChatXAI extends OriginalChatXAI {\n public get exposedClient(): CustomOpenAIClient {\n return this.client;\n }\n protected _getClientOptions(\n options?: OpenAICoreRequestOptions\n ): OpenAICoreRequestOptions {\n if (!(this.client as OpenAIClient | undefined)) {\n const openAIEndpointConfig: t.OpenAIEndpointConfig = {\n baseURL: this.clientConfig.baseURL,\n };\n\n const endpoint = getEndpoint(openAIEndpointConfig);\n const params = {\n ...this.clientConfig,\n baseURL: endpoint,\n timeout: this.timeout,\n maxRetries: 0,\n };\n if (params.baseURL == null) {\n delete params.baseURL;\n }\n\n this.client = new CustomOpenAIClient(params);\n }\n const requestOptions = {\n ...this.clientConfig,\n ...options,\n } as OpenAICoreRequestOptions;\n return requestOptions;\n }\n}\n"],"names":["AzureOpenAIClient","OriginalChatOpenAI","OriginalAzureChatOpenAI","OriginalChatDeepSeek","OriginalChatXAI"],"mappings":";;;;;AAYA,SAAS,kBAAkB,CAAC,UAA2B,EAAA;IACrD,OAAO,YAAA;QACL,UAAU,CAAC,KAAK,EAAE;AACpB,KAAC;AACH;AAEM,MAAO,kBAAmB,SAAQ,YAAY,CAAA;AAClD,IAAA,YAAY;IACZ,MAAM,gBAAgB,CACpB,GAAgB,EAChB,IAA6B,EAC7B,EAAU,EACV,UAA2B,EAAA;QAE3B,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,EAAE,GAAG,IAAI,IAAI,EAAE;AACzC,QAAA,MAAM,OAAO,GAAG,kBAAkB,CAAC,UAAU,CAAC;AAC9C,QAAA,IAAI,CAAC,Y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AAI,CAAE,IAAI,CAAC,MAAmC,EAAE;AAC9C,YAAA,MAAM,oBAAoB,GAA2B;AACnD,gBAAA,OAAO,EAAE,IAAI,CAAC,YAAY,CAAC,OAAO;aACnC;AAED,YAAA,MAAM,QAAQ,GAAG,WAAW,CAAC,oBAAoB,CAAC;AAClD,YAAA,MAAM,MAAM,GAAG;gBACb,GAAG,IAAI,CAAC,YAAY;AACpB,gBAAA,OAAO,EAAE,QAAQ;gBACjB,OAAO,EAAE,IAAI,CAAC,OAAO;AACrB,gBAAA,UAAU,EAAE,CAAC;aACd;AACD,YAAA,IAAI,MAAM,CAAC,OAAO,IAAI,IAAI,EAAE;gBAC1B,OAAO,MAAM,CAAC,OAAO;;YAGvB,IAAI,CAAC,MAAM,GAAG,IAAI,kBAAkB,CAAC,MAAM,CAAC;;AAE9C,QAAA,MAAM,cAAc,GAAG;YACrB,GAAG,IAAI,CAAC,YAAY;AACpB,YAAA,GAAG,OAAO;SACiB;AAC7B,QAAA,OAAO,cAAc;;AAExB;;;;"}
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../../../src/llm/openai/index.ts"],"sourcesContent":["import { AzureOpenAI as AzureOpenAIClient } from 'openai';\nimport { ChatXAI as OriginalChatXAI } from '@langchain/xai';\nimport { ChatDeepSeek as OriginalChatDeepSeek } from '@langchain/deepseek';\nimport {\n getEndpoint,\n OpenAIClient,\n formatToOpenAITool,\n ChatOpenAI as OriginalChatOpenAI,\n AzureChatOpenAI as OriginalAzureChatOpenAI,\n} from '@langchain/openai';\nimport { isLangChainTool } from '@langchain/core/utils/function_calling';\nimport type { BindToolsInput } from '@langchain/core/language_models/chat_models';\nimport type { OpenAIEndpointConfig } from '@langchain/openai/dist/utils/azure';\nimport type { AIMessageChunk } from '@langchain/core/messages';\nimport type { Runnable } from '@langchain/core/runnables';\nimport type * as t from '@langchain/openai';\nimport {\n isOpenAITool,\n ToolDefinition,\n BaseLanguageModelInput,\n} from '@langchain/core/language_models/base';\n\ntype ResponsesCreateParams = Parameters<OpenAIClient.Responses['create']>[0];\ntype ResponsesTool = Exclude<ResponsesCreateParams['tools'], undefined>[number];\n\ntype ChatOpenAIToolType =\n | BindToolsInput\n | OpenAIClient.ChatCompletionTool\n | ResponsesTool;\n\ntype HeaderValue = string | undefined | null;\nexport type HeadersLike =\n | Headers\n | readonly HeaderValue[][]\n | Record<string, HeaderValue | readonly HeaderValue[]>\n | undefined\n | null\n // NullableHeaders\n | { values: Headers; [key: string]: unknown };\n\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\nconst iife = <T>(fn: () => T) => fn();\n\nexport function isHeaders(headers: unknown): headers is Headers {\n return (\n typeof Headers !== 'undefined' &&\n headers !== null &&\n typeof headers === 'object' &&\n Object.prototype.toString.call(headers) === '[object Headers]'\n );\n}\n\nexport function normalizeHeaders(\n headers: HeadersLike\n): Record<string, HeaderValue | readonly HeaderValue[]> {\n const output = iife(() => {\n // If headers is a Headers instance\n if (isHeaders(headers)) {\n return headers;\n }\n // If headers is an array of [key, value] pairs\n else if (Array.isArray(headers)) {\n return new Headers(headers);\n }\n // If headers is a NullableHeaders-like object (has 'values' property that is a Headers)\n else if (\n typeof headers === 'object' &&\n headers !== null &&\n 'values' in headers &&\n isHeaders(headers.values)\n ) {\n return headers.values;\n }\n // If headers is a plain object\n else if (typeof headers === 'object' && headers !== null) {\n const entries: [string, string][] = Object.entries(headers)\n .filter(([, v]) => typeof v === 'string')\n .map(([k, v]) => [k, v as string]);\n return new Headers(entries);\n }\n return new Headers();\n });\n\n return Object.fromEntries(output.entries());\n}\n\ntype OpenAICoreRequestOptions = OpenAIClient.RequestOptions;\n\nfunction createAbortHandler(controller: AbortController): () => void {\n return function (): void {\n controller.abort();\n };\n}\n/**\n * Formats a tool in either OpenAI format, or LangChain structured tool format\n * into an OpenAI tool format. If the tool is already in OpenAI format, return without\n * any changes. If it is in LangChain structured tool format, convert it to OpenAI tool format\n * using OpenAI's `zodFunction` util, falling back to `convertToOpenAIFunction` if the parameters\n * returned from the `zodFunction` util are not defined.\n *\n * @param {BindToolsInput} tool The tool to convert to an OpenAI tool.\n * @param {Object} [fields] Additional fields to add to the OpenAI tool.\n * @returns {ToolDefinition} The inputted tool in OpenAI tool format.\n */\nexport function _convertToOpenAITool(\n tool: BindToolsInput,\n fields?: {\n /**\n * If `true`, model output is guaranteed to exactly match the JSON Schema\n * provided in the function definition.\n */\n strict?: boolean;\n }\n): OpenAIClient.ChatCompletionTool {\n let toolDef: OpenAIClient.ChatCompletionTool | undefined;\n\n if (isLangChainTool(tool)) {\n toolDef = formatToOpenAITool(tool);\n } else {\n toolDef = tool as ToolDefinition;\n }\n\n if (fields?.strict !== undefined) {\n toolDef.function.strict = fields.strict;\n }\n\n return toolDef;\n}\n\nfunction _convertChatOpenAIToolTypeToOpenAITool(\n tool: ChatOpenAIToolType,\n fields?: {\n strict?: boolean;\n }\n): OpenAIClient.ChatCompletionTool {\n if (isOpenAITool(tool)) {\n if (fields?.strict !== undefined) {\n return {\n ...tool,\n function: {\n ...tool.function,\n strict: fields.strict,\n },\n };\n }\n\n return tool;\n }\n return _convertToOpenAITool(tool, fields);\n}\n\nexport class CustomOpenAIClient extends OpenAIClient {\n abortHandler?: () => void;\n async fetchWithTimeout(\n url: RequestInfo,\n init: RequestInit | undefined,\n ms: number,\n controller: AbortController\n ): Promise<Response> {\n const { signal, ...options } = init || {};\n const handler = createAbortHandler(controller);\n this.abortHandler = handler;\n if (signal) signal.addEventListener('abort', handler, { once: true });\n\n const timeout = setTimeout(() => handler, ms);\n\n const fetchOptions = {\n signal: controller.signal as AbortSignal,\n ...options,\n };\n if (fetchOptions.method != null) {\n // Custom methods like 'patch' need to be uppercased\n // See https://github.com/nodejs/undici/issues/2294\n fetchOptions.method = fetchOptions.method.toUpperCase();\n }\n\n return (\n // use undefined this binding; fetch errors if bound to something else in browser/cloudflare\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n /** @ts-ignore */\n this.fetch.call(undefined, url, fetchOptions).finally(() => {\n clearTimeout(timeout);\n })\n );\n }\n}\nexport class CustomAzureOpenAIClient extends AzureOpenAIClient {\n abortHandler?: () => void;\n async fetchWithTimeout(\n url: RequestInfo,\n init: RequestInit | undefined,\n ms: number,\n controller: AbortController\n ): Promise<Response> {\n const { signal, ...options } = init || {};\n const handler = createAbortHandler(controller);\n this.abortHandler = handler;\n if (signal) signal.addEventListener('abort', handler, { once: true });\n\n const timeout = setTimeout(() => handler, ms);\n\n const fetchOptions = {\n signal: controller.signal as AbortSignal,\n ...options,\n };\n if (fetchOptions.method != null) {\n // Custom methods like 'patch' need to be uppercased\n // See https://github.com/nodejs/undici/issues/2294\n fetchOptions.method = fetchOptions.method.toUpperCase();\n }\n\n return (\n // use undefined this binding; fetch errors if bound to something else in browser/cloudflare\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n /** @ts-ignore */\n this.fetch.call(undefined, url, fetchOptions).finally(() => {\n clearTimeout(timeout);\n })\n );\n }\n}\n\nfunction isBuiltInTool(tool: ChatOpenAIToolType): tool is ResponsesTool {\n return 'type' in tool && tool.type !== 'function';\n}\n\nexport class ChatOpenAI extends OriginalChatOpenAI<t.ChatOpenAICallOptions> {\n public get exposedClient(): CustomOpenAIClient {\n return this.client;\n }\n override bindTools(\n tools: ChatOpenAIToolType[],\n kwargs?: Partial<t.ChatOpenAICallOptions>\n ): Runnable<BaseLanguageModelInput, AIMessageChunk, t.ChatOpenAICallOptions> {\n let strict: boolean | undefined;\n if (kwargs?.strict !== undefined) {\n strict = kwargs.strict;\n } else if (this.supportsStrictToolCalling !== undefined) {\n strict = this.supportsStrictToolCalling;\n }\n return this.withConfig({\n tools: tools.map((tool) =>\n isBuiltInTool(tool)\n ? tool\n : _convertChatOpenAIToolTypeToOpenAITool(tool, { strict })\n ),\n ...kwargs,\n } as Partial<t.ChatOpenAICallOptions>);\n }\n protected _getClientOptions(\n options?: OpenAICoreRequestOptions\n ): OpenAICoreRequestOptions {\n if (!(this.client as OpenAIClient | undefined)) {\n const openAIEndpointConfig: t.OpenAIEndpointConfig = {\n baseURL: this.clientConfig.baseURL,\n };\n\n const endpoint = getEndpoint(openAIEndpointConfig);\n const params = {\n ...this.clientConfig,\n baseURL: endpoint,\n timeout: this.timeout,\n maxRetries: 0,\n };\n if (params.baseURL == null) {\n delete params.baseURL;\n }\n\n this.client = new CustomOpenAIClient(params);\n }\n const requestOptions = {\n ...this.clientConfig,\n ...options,\n } as OpenAICoreRequestOptions;\n return requestOptions;\n }\n}\n\nexport class AzureChatOpenAI extends OriginalAzureChatOpenAI {\n public get exposedClient(): CustomOpenAIClient {\n return this.client;\n }\n protected _getClientOptions(\n options: OpenAICoreRequestOptions | undefined\n ): OpenAICoreRequestOptions {\n if (!(this.client as unknown as AzureOpenAIClient | undefined)) {\n const openAIEndpointConfig: OpenAIEndpointConfig = {\n azureOpenAIApiDeploymentName: this.azureOpenAIApiDeploymentName,\n azureOpenAIApiInstanceName: this.azureOpenAIApiInstanceName,\n azureOpenAIApiKey: this.azureOpenAIApiKey,\n azureOpenAIBasePath: this.azureOpenAIBasePath,\n azureADTokenProvider: this.azureADTokenProvider,\n baseURL: this.clientConfig.baseURL,\n };\n\n const endpoint = getEndpoint(openAIEndpointConfig);\n\n const params = {\n ...this.clientConfig,\n baseURL: endpoint,\n timeout: this.timeout,\n maxRetries: 0,\n };\n\n if (!this.azureADTokenProvider) {\n params.apiKey = openAIEndpointConfig.azureOpenAIApiKey;\n }\n\n if (params.baseURL == null) {\n delete params.baseURL;\n }\n\n const defaultHeaders = normalizeHeaders(params.defaultHeaders);\n params.defaultHeaders = {\n ...params.defaultHeaders,\n 'User-Agent':\n defaultHeaders['User-Agent'] != null\n ? `${defaultHeaders['User-Agent']}: langchainjs-azure-openai-v2`\n : 'langchainjs-azure-openai-v2',\n };\n\n this.client = new CustomAzureOpenAIClient({\n apiVersion: this.azureOpenAIApiVersion,\n azureADTokenProvider: this.azureADTokenProvider,\n ...(params as t.AzureOpenAIInput),\n }) as unknown as CustomOpenAIClient;\n }\n\n const requestOptions = {\n ...this.clientConfig,\n ...options,\n } as OpenAICoreRequestOptions;\n if (this.azureOpenAIApiKey != null) {\n requestOptions.headers = {\n 'api-key': this.azureOpenAIApiKey,\n ...requestOptions.headers,\n };\n requestOptions.query = {\n 'api-version': this.azureOpenAIApiVersion,\n ...requestOptions.query,\n };\n }\n return requestOptions;\n }\n}\nexport class ChatDeepSeek extends OriginalChatDeepSeek {\n public get exposedClient(): CustomOpenAIClient {\n return this.client;\n }\n protected _getClientOptions(\n options?: OpenAICoreRequestOptions\n ): OpenAICoreRequestOptions {\n if (!(this.client as OpenAIClient | undefined)) {\n const openAIEndpointConfig: t.OpenAIEndpointConfig = {\n baseURL: this.clientConfig.baseURL,\n };\n\n const endpoint = getEndpoint(openAIEndpointConfig);\n const params = {\n ...this.clientConfig,\n baseURL: endpoint,\n timeout: this.timeout,\n maxRetries: 0,\n };\n if (params.baseURL == null) {\n delete params.baseURL;\n }\n\n this.client = new CustomOpenAIClient(params);\n }\n const requestOptions = {\n ...this.clientConfig,\n ...options,\n } as OpenAICoreRequestOptions;\n return requestOptions;\n }\n}\n\nexport class ChatXAI extends OriginalChatXAI {\n public get exposedClient(): CustomOpenAIClient {\n return this.client;\n }\n protected _getClientOptions(\n options?: OpenAICoreRequestOptions\n ): OpenAICoreRequestOptions {\n if (!(this.client as OpenAIClient | undefined)) {\n const openAIEndpointConfig: t.OpenAIEndpointConfig = {\n baseURL: this.clientConfig.baseURL,\n };\n\n const endpoint = getEndpoint(openAIEndpointConfig);\n const params = {\n ...this.clientConfig,\n baseURL: endpoint,\n timeout: this.timeout,\n maxRetries: 0,\n };\n if (params.baseURL == null) {\n delete params.baseURL;\n }\n\n this.client = new CustomOpenAIClient(params);\n }\n const requestOptions = {\n ...this.clientConfig,\n ...options,\n } as OpenAICoreRequestOptions;\n return requestOptions;\n }\n}\n"],"names":["AzureOpenAIClient","OriginalChatOpenAI","OriginalAzureChatOpenAI","OriginalChatDeepSeek","OriginalChatXAI"],"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AG,OAAO;SACiB;AAC7B,QAAA,OAAO,cAAc;;AAExB;;;;"}
|
|
@@ -2,8 +2,8 @@ import { ChatOllama } from '@langchain/ollama';
|
|
|
2
2
|
import { ChatMistralAI } from '@langchain/mistralai';
|
|
3
3
|
import { ChatBedrockConverse } from '@langchain/aws';
|
|
4
4
|
import { ChatVertexAI } from '@langchain/google-vertexai';
|
|
5
|
-
import { ChatGoogleGenerativeAI } from '@langchain/google-genai';
|
|
6
5
|
import { BedrockChat } from '@langchain/community/chat_models/bedrock/web';
|
|
6
|
+
import { CustomChatGoogleGenerativeAI } from './google/index.mjs';
|
|
7
7
|
import { CustomAnthropic } from './anthropic/index.mjs';
|
|
8
8
|
import { ChatOpenRouter } from './openrouter/index.mjs';
|
|
9
9
|
import { ChatDeepSeek, AzureChatOpenAI, ChatOpenAI, ChatXAI } from './openai/index.mjs';
|
|
@@ -24,7 +24,7 @@ const llmProviders = {
|
|
|
24
24
|
[Providers.BEDROCK_LEGACY]: BedrockChat,
|
|
25
25
|
[Providers.BEDROCK]: ChatBedrockConverse,
|
|
26
26
|
// [Providers.ANTHROPIC]: ChatAnthropic,
|
|
27
|
-
[Providers.GOOGLE]:
|
|
27
|
+
[Providers.GOOGLE]: CustomChatGoogleGenerativeAI,
|
|
28
28
|
};
|
|
29
29
|
const manualToolStreamProviders = new Set([
|
|
30
30
|
Providers.ANTHROPIC,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"providers.mjs","sources":["../../../src/llm/providers.ts"],"sourcesContent":["// src/llm/providers.ts\nimport { ChatOllama } from '@langchain/ollama';\nimport { ChatMistralAI } from '@langchain/mistralai';\nimport { ChatBedrockConverse } from '@langchain/aws';\n// import { ChatAnthropic } from '@langchain/anthropic';\nimport { ChatVertexAI } from '@langchain/google-vertexai';\nimport {
|
|
1
|
+
{"version":3,"file":"providers.mjs","sources":["../../../src/llm/providers.ts"],"sourcesContent":["// src/llm/providers.ts\nimport { ChatOllama } from '@langchain/ollama';\nimport { ChatMistralAI } from '@langchain/mistralai';\nimport { ChatBedrockConverse } from '@langchain/aws';\n// import { ChatAnthropic } from '@langchain/anthropic';\nimport { ChatVertexAI } from '@langchain/google-vertexai';\nimport { BedrockChat } from '@langchain/community/chat_models/bedrock/web';\nimport type {\n ChatModelConstructorMap,\n ProviderOptionsMap,\n ChatModelMap,\n} from '@/types';\nimport { CustomChatGoogleGenerativeAI } from '@/llm/google';\nimport { CustomAnthropic } from '@/llm/anthropic';\nimport { ChatOpenRouter } from '@/llm/openrouter';\nimport {\n ChatXAI,\n ChatOpenAI,\n ChatDeepSeek,\n AzureChatOpenAI,\n} from '@/llm/openai';\nimport { Providers } from '@/common';\n\nexport const llmProviders: Partial<ChatModelConstructorMap> = {\n [Providers.XAI]: ChatXAI,\n [Providers.OPENAI]: ChatOpenAI,\n [Providers.OLLAMA]: ChatOllama,\n [Providers.AZURE]: AzureChatOpenAI,\n [Providers.VERTEXAI]: ChatVertexAI,\n [Providers.DEEPSEEK]: ChatDeepSeek,\n [Providers.MISTRALAI]: ChatMistralAI,\n [Providers.MISTRAL]: ChatMistralAI,\n [Providers.ANTHROPIC]: CustomAnthropic,\n [Providers.OPENROUTER]: ChatOpenRouter,\n [Providers.BEDROCK_LEGACY]: BedrockChat,\n [Providers.BEDROCK]: ChatBedrockConverse,\n // [Providers.ANTHROPIC]: ChatAnthropic,\n [Providers.GOOGLE]: CustomChatGoogleGenerativeAI,\n};\n\nexport const manualToolStreamProviders = new Set<Providers | string>([\n Providers.ANTHROPIC,\n Providers.BEDROCK,\n Providers.OLLAMA,\n]);\n\nexport const getChatModelClass = <P extends Providers>(\n provider: P\n): new (config: ProviderOptionsMap[P]) => ChatModelMap[P] => {\n const ChatModelClass = llmProviders[provider];\n if (!ChatModelClass) {\n throw new Error(`Unsupported LLM provider: ${provider}`);\n }\n\n return ChatModelClass;\n};\n"],"names":[],"mappings":";;;;;;;;;;;AAAA;AAuBa,MAAA,YAAY,GAAqC;AAC5D,IAAA,CAAC,SAAS,CAAC,GAAG,GAAG,OAAO;AACxB,IAAA,CAAC,SAAS,CAAC,MAAM,GAAG,UAAU;AAC9B,IAAA,CAAC,SAAS,CAAC,MAAM,GAAG,UAAU;AAC9B,IAAA,CAAC,SAAS,CAAC,KAAK,GAAG,eAAe;AAClC,IAAA,CAAC,SAAS,CAAC,QAAQ,GAAG,YAAY;AAClC,IAAA,CAAC,SAAS,CAAC,QAAQ,GAAG,YAAY;AAClC,IAAA,CAAC,SAAS,CAAC,SAAS,GAAG,aAAa;AACpC,IAAA,CAAC,SAAS,CAAC,OAAO,GAAG,aAAa;AAClC,IAAA,CAAC,SAAS,CAAC,SAAS,GAAG,eAAe;AACtC,IAAA,CAAC,SAAS,CAAC,UAAU,GAAG,cAAc;AACtC,IAAA,CAAC,SAAS,CAAC,cAAc,GAAG,WAAW;AACvC,IAAA,CAAC,SAAS,CAAC,OAAO,GAAG,mBAAmB;;AAExC,IAAA,CAAC,SAAS,CAAC,MAAM,GAAG,4BAA4B;;AAGrC,MAAA,yBAAyB,GAAG,IAAI,GAAG,CAAqB;AACnE,IAAA,SAAS,CAAC,SAAS;AACnB,IAAA,SAAS,CAAC,OAAO;AACjB,IAAA,SAAS,CAAC,MAAM;AACjB,CAAA;AAEY,MAAA,iBAAiB,GAAG,CAC/B,QAAW,KAC+C;AAC1D,IAAA,MAAM,cAAc,GAAG,YAAY,CAAC,QAAQ,CAAC;IAC7C,IAAI,CAAC,cAAc,EAAE;AACnB,QAAA,MAAM,IAAI,KAAK,CAAC,6BAA6B,QAAQ,CAAA,CAAE,CAAC;;AAG1D,IAAA,OAAO,cAAc;AACvB;;;;"}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import Anthropic from '@anthropic-ai/sdk';
|
|
2
2
|
import { BindToolsInput } from '@langchain/core/language_models/chat_models';
|
|
3
|
+
export type AnthropicStreamUsage = Anthropic.Usage;
|
|
4
|
+
export type AnthropicMessageDeltaEvent = Anthropic.MessageDeltaEvent;
|
|
5
|
+
export type AnthropicMessageStartEvent = Anthropic.MessageStartEvent;
|
|
3
6
|
export type AnthropicToolResponse = {
|
|
4
7
|
type: 'tool_use';
|
|
5
8
|
id: string;
|
|
6
9
|
name: string;
|
|
7
10
|
input: Record<string, any>;
|
|
8
11
|
};
|
|
9
|
-
export type AnthropicStreamUsage = Anthropic.Usage;
|
|
10
12
|
export type AnthropicMessageParam = Anthropic.MessageParam;
|
|
11
|
-
export type AnthropicMessageDeltaEvent = Anthropic.MessageDeltaEvent;
|
|
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;
|
|
@@ -28,4 +28,8 @@ export type AnthropicToolResultBlockParam = Anthropic.Messages.ToolResultBlockPa
|
|
|
28
28
|
export type AnthropicDocumentBlockParam = Anthropic.Messages.DocumentBlockParam;
|
|
29
29
|
export type AnthropicThinkingBlockParam = Anthropic.Messages.ThinkingBlockParam;
|
|
30
30
|
export type AnthropicRedactedThinkingBlockParam = Anthropic.Messages.RedactedThinkingBlockParam;
|
|
31
|
+
export type AnthropicServerToolUseBlockParam = Anthropic.Messages.ServerToolUseBlockParam;
|
|
32
|
+
export type AnthropicWebSearchToolResultBlockParam = Anthropic.Messages.WebSearchToolResultBlockParam;
|
|
33
|
+
export type AnthropicWebSearchResultBlockParam = Anthropic.Messages.WebSearchResultBlockParam;
|
|
34
|
+
export type AnthropicContentBlock = AnthropicTextBlockParam | AnthropicImageBlockParam | AnthropicToolUseBlockParam | AnthropicToolResultBlockParam | AnthropicDocumentBlockParam | AnthropicThinkingBlockParam | AnthropicRedactedThinkingBlockParam | AnthropicServerToolUseBlockParam | AnthropicWebSearchToolResultBlockParam | AnthropicWebSearchResultBlockParam;
|
|
31
35
|
export declare function isAnthropicImageBlockParam(block: unknown): block is AnthropicImageBlockParam;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { type BaseMessage } from '@langchain/core/messages';
|
|
5
5
|
import { ToolCall } from '@langchain/core/messages/tool';
|
|
6
|
-
import
|
|
6
|
+
import { 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.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
1
|
import { BaseLLMOutputParser } from '@langchain/core/output_parsers';
|
|
3
2
|
import { JsonOutputKeyToolsParserParams } from '@langchain/core/output_parsers/openai_tools';
|
|
3
|
+
import { InteropZodType } from '@langchain/core/utils/types';
|
|
4
4
|
import { ChatGeneration } from '@langchain/core/outputs';
|
|
5
5
|
import { ToolCall } from '@langchain/core/messages/tool';
|
|
6
6
|
interface AnthropicToolsOutputParserParams<T extends Record<string, any>> extends JsonOutputKeyToolsParserParams<T> {
|
|
@@ -13,7 +13,7 @@ export declare class AnthropicToolsOutputParser<T extends Record<string, any> =
|
|
|
13
13
|
keyName: string;
|
|
14
14
|
/** Whether to return only the first tool call. */
|
|
15
15
|
returnSingle: boolean;
|
|
16
|
-
zodSchema?:
|
|
16
|
+
zodSchema?: InteropZodType<T>;
|
|
17
17
|
constructor(params: AnthropicToolsOutputParserParams<T>);
|
|
18
18
|
protected _validateResult(result: unknown): Promise<T>;
|
|
19
19
|
parseResult(generations: ChatGeneration[]): Promise<T>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ChatGoogleGenerativeAI } from '@langchain/google-genai';
|
|
2
|
+
import type { GoogleGenerativeAIChatInput } from '@langchain/google-genai';
|
|
3
|
+
import type { RequestOptions } from '@google/generative-ai';
|
|
4
|
+
export declare class CustomChatGoogleGenerativeAI extends ChatGoogleGenerativeAI {
|
|
5
|
+
constructor(fields: GoogleGenerativeAIChatInput & {
|
|
6
|
+
customHeaders?: RequestOptions['customHeaders'];
|
|
7
|
+
});
|
|
8
|
+
}
|
|
@@ -2,8 +2,40 @@ 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 {
|
|
5
|
+
import type { BindToolsInput } from '@langchain/core/language_models/chat_models';
|
|
6
|
+
import type { AIMessageChunk } from '@langchain/core/messages';
|
|
7
|
+
import type { Runnable } from '@langchain/core/runnables';
|
|
6
8
|
import type * as t from '@langchain/openai';
|
|
9
|
+
import { BaseLanguageModelInput } from '@langchain/core/language_models/base';
|
|
10
|
+
type ResponsesCreateParams = Parameters<OpenAIClient.Responses['create']>[0];
|
|
11
|
+
type ResponsesTool = Exclude<ResponsesCreateParams['tools'], undefined>[number];
|
|
12
|
+
type ChatOpenAIToolType = BindToolsInput | OpenAIClient.ChatCompletionTool | ResponsesTool;
|
|
13
|
+
type HeaderValue = string | undefined | null;
|
|
14
|
+
export type HeadersLike = Headers | readonly HeaderValue[][] | Record<string, HeaderValue | readonly HeaderValue[]> | undefined | null | {
|
|
15
|
+
values: Headers;
|
|
16
|
+
[key: string]: unknown;
|
|
17
|
+
};
|
|
18
|
+
export declare function isHeaders(headers: unknown): headers is Headers;
|
|
19
|
+
export declare function normalizeHeaders(headers: HeadersLike): Record<string, HeaderValue | readonly HeaderValue[]>;
|
|
20
|
+
type OpenAICoreRequestOptions = OpenAIClient.RequestOptions;
|
|
21
|
+
/**
|
|
22
|
+
* Formats a tool in either OpenAI format, or LangChain structured tool format
|
|
23
|
+
* into an OpenAI tool format. If the tool is already in OpenAI format, return without
|
|
24
|
+
* any changes. If it is in LangChain structured tool format, convert it to OpenAI tool format
|
|
25
|
+
* using OpenAI's `zodFunction` util, falling back to `convertToOpenAIFunction` if the parameters
|
|
26
|
+
* returned from the `zodFunction` util are not defined.
|
|
27
|
+
*
|
|
28
|
+
* @param {BindToolsInput} tool The tool to convert to an OpenAI tool.
|
|
29
|
+
* @param {Object} [fields] Additional fields to add to the OpenAI tool.
|
|
30
|
+
* @returns {ToolDefinition} The inputted tool in OpenAI tool format.
|
|
31
|
+
*/
|
|
32
|
+
export declare function _convertToOpenAITool(tool: BindToolsInput, fields?: {
|
|
33
|
+
/**
|
|
34
|
+
* If `true`, model output is guaranteed to exactly match the JSON Schema
|
|
35
|
+
* provided in the function definition.
|
|
36
|
+
*/
|
|
37
|
+
strict?: boolean;
|
|
38
|
+
}): OpenAIClient.ChatCompletionTool;
|
|
7
39
|
export declare class CustomOpenAIClient extends OpenAIClient {
|
|
8
40
|
abortHandler?: () => void;
|
|
9
41
|
fetchWithTimeout(url: RequestInfo, init: RequestInit | undefined, ms: number, controller: AbortController): Promise<Response>;
|
|
@@ -14,11 +46,12 @@ export declare class CustomAzureOpenAIClient extends AzureOpenAIClient {
|
|
|
14
46
|
}
|
|
15
47
|
export declare class ChatOpenAI extends OriginalChatOpenAI<t.ChatOpenAICallOptions> {
|
|
16
48
|
get exposedClient(): CustomOpenAIClient;
|
|
17
|
-
|
|
49
|
+
bindTools(tools: ChatOpenAIToolType[], kwargs?: Partial<t.ChatOpenAICallOptions>): Runnable<BaseLanguageModelInput, AIMessageChunk, t.ChatOpenAICallOptions>;
|
|
50
|
+
protected _getClientOptions(options?: OpenAICoreRequestOptions): OpenAICoreRequestOptions;
|
|
18
51
|
}
|
|
19
52
|
export declare class AzureChatOpenAI extends OriginalAzureChatOpenAI {
|
|
20
53
|
get exposedClient(): CustomOpenAIClient;
|
|
21
|
-
protected _getClientOptions(options:
|
|
54
|
+
protected _getClientOptions(options: OpenAICoreRequestOptions | undefined): OpenAICoreRequestOptions;
|
|
22
55
|
}
|
|
23
56
|
export declare class ChatDeepSeek extends OriginalChatDeepSeek {
|
|
24
57
|
get exposedClient(): CustomOpenAIClient;
|
|
@@ -28,3 +61,4 @@ export declare class ChatXAI extends OriginalChatXAI {
|
|
|
28
61
|
get exposedClient(): CustomOpenAIClient;
|
|
29
62
|
protected _getClientOptions(options?: OpenAICoreRequestOptions): OpenAICoreRequestOptions;
|
|
30
63
|
}
|
|
64
|
+
export {};
|
|
@@ -3,7 +3,6 @@ import { ChatAnthropic } from '@langchain/anthropic';
|
|
|
3
3
|
import { ChatMistralAI } from '@langchain/mistralai';
|
|
4
4
|
import { ChatBedrockConverse } from '@langchain/aws';
|
|
5
5
|
import { ChatVertexAI } from '@langchain/google-vertexai';
|
|
6
|
-
import { ChatGoogleGenerativeAI } from '@langchain/google-genai';
|
|
7
6
|
import { BedrockChat } from '@langchain/community/chat_models/bedrock/web';
|
|
8
7
|
import type { BindToolsInput, BaseChatModelParams } from '@langchain/core/language_models/chat_models';
|
|
9
8
|
import type { OpenAIChatInput, ChatOpenAIFields, AzureOpenAIInput, ClientOptions as OAIClientOptions } from '@langchain/openai';
|
|
@@ -14,6 +13,7 @@ import type { ChatDeepSeekCallOptions } from '@langchain/deepseek';
|
|
|
14
13
|
import type { ChatOpenRouterCallOptions } from '@/llm/openrouter';
|
|
15
14
|
import type { ChatBedrockConverseInput } from '@langchain/aws';
|
|
16
15
|
import type { ChatMistralAIInput } from '@langchain/mistralai';
|
|
16
|
+
import type { RequestOptions } from '@google/generative-ai';
|
|
17
17
|
import type { StructuredTool } from '@langchain/core/tools';
|
|
18
18
|
import type { AnthropicInput } from '@langchain/anthropic';
|
|
19
19
|
import type { Runnable } from '@langchain/core/runnables';
|
|
@@ -21,6 +21,7 @@ import type { ChatOllamaInput } from '@langchain/ollama';
|
|
|
21
21
|
import type { OpenAI as OpenAIClient } from 'openai';
|
|
22
22
|
import type { ChatXAIInput } from '@langchain/xai';
|
|
23
23
|
import { ChatXAI, ChatOpenAI, ChatDeepSeek, AzureChatOpenAI } from '@/llm/openai';
|
|
24
|
+
import { CustomChatGoogleGenerativeAI } from '@/llm/google';
|
|
24
25
|
import { ChatOpenRouter } from '@/llm/openrouter';
|
|
25
26
|
import { Providers } from '@/common';
|
|
26
27
|
export type AzureClientOptions = Partial<OpenAIChatInput> & Partial<AzureOpenAIInput> & {
|
|
@@ -48,7 +49,9 @@ export type BedrockAnthropicInput = ChatBedrockConverseInput & {
|
|
|
48
49
|
additionalModelRequestFields?: ChatBedrockConverseInput['additionalModelRequestFields'] & AnthropicReasoning;
|
|
49
50
|
};
|
|
50
51
|
export type BedrockConverseClientOptions = ChatBedrockConverseInput;
|
|
51
|
-
export type GoogleClientOptions = GoogleGenerativeAIChatInput
|
|
52
|
+
export type GoogleClientOptions = GoogleGenerativeAIChatInput & {
|
|
53
|
+
customHeaders?: RequestOptions['customHeaders'];
|
|
54
|
+
};
|
|
52
55
|
export type DeepSeekClientOptions = ChatDeepSeekCallOptions;
|
|
53
56
|
export type XAIClientOptions = ChatXAIInput;
|
|
54
57
|
export type ClientOptions = OpenAIClientOptions | AzureClientOptions | OllamaClientOptions | AnthropicClientOptions | MistralAIClientOptions | VertexAIClientOptions | BedrockClientOptions | BedrockConverseClientOptions | GoogleClientOptions | DeepSeekClientOptions | XAIClientOptions;
|
|
@@ -83,7 +86,7 @@ export type ChatModelMap = {
|
|
|
83
86
|
[Providers.OPENROUTER]: ChatOpenRouter;
|
|
84
87
|
[Providers.BEDROCK_LEGACY]: BedrockChat;
|
|
85
88
|
[Providers.BEDROCK]: ChatBedrockConverse;
|
|
86
|
-
[Providers.GOOGLE]:
|
|
89
|
+
[Providers.GOOGLE]: CustomChatGoogleGenerativeAI;
|
|
87
90
|
};
|
|
88
91
|
export type ChatModelConstructorMap = {
|
|
89
92
|
[P in Providers]: new (config: ProviderOptionsMap[P]) => ChatModelMap[P];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@librechat/agents",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.40",
|
|
4
4
|
"main": "./dist/cjs/main.cjs",
|
|
5
5
|
"module": "./dist/esm/main.mjs",
|
|
6
6
|
"types": "./dist/types/index.d.ts",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"image": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/image.ts --provider 'google' --name 'Jo' --location 'New York, NY'",
|
|
48
48
|
"code_exec_files": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/code_exec_files.ts --provider 'openAI' --name 'Jo' --location 'New York, NY'",
|
|
49
49
|
"code_exec_simple": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/code_exec_simple.ts --provider 'google' --name 'Jo' --location 'New York, NY'",
|
|
50
|
-
"simple": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/simple.ts --provider '
|
|
50
|
+
"simple": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/simple.ts --provider 'google' --name 'Jo' --location 'New York, NY'",
|
|
51
51
|
"caching": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/caching.ts --name 'Jo' --location 'New York, NY'",
|
|
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'",
|
|
@@ -72,18 +72,18 @@
|
|
|
72
72
|
"format": "prettier --write ."
|
|
73
73
|
},
|
|
74
74
|
"dependencies": {
|
|
75
|
-
"@langchain/anthropic": "^0.3.
|
|
76
|
-
"@langchain/aws": "^0.1.
|
|
77
|
-
"@langchain/community": "^0.3.
|
|
78
|
-
"@langchain/core": "^0.3.
|
|
79
|
-
"@langchain/deepseek": "^0.0.
|
|
80
|
-
"@langchain/google-genai": "^0.2.
|
|
81
|
-
"@langchain/google-vertexai": "^0.2.
|
|
82
|
-
"@langchain/langgraph": "^0.
|
|
83
|
-
"@langchain/mistralai": "^0.2.
|
|
84
|
-
"@langchain/ollama": "^0.2.
|
|
85
|
-
"@langchain/openai": "^0.5.
|
|
86
|
-
"@langchain/xai": "^0.0.
|
|
75
|
+
"@langchain/anthropic": "^0.3.23",
|
|
76
|
+
"@langchain/aws": "^0.1.11",
|
|
77
|
+
"@langchain/community": "^0.3.47",
|
|
78
|
+
"@langchain/core": "^0.3.60",
|
|
79
|
+
"@langchain/deepseek": "^0.0.2",
|
|
80
|
+
"@langchain/google-genai": "^0.2.13",
|
|
81
|
+
"@langchain/google-vertexai": "^0.2.13",
|
|
82
|
+
"@langchain/langgraph": "^0.3.4",
|
|
83
|
+
"@langchain/mistralai": "^0.2.1",
|
|
84
|
+
"@langchain/ollama": "^0.2.3",
|
|
85
|
+
"@langchain/openai": "^0.5.14",
|
|
86
|
+
"@langchain/xai": "^0.0.3",
|
|
87
87
|
"cheerio": "^1.0.0",
|
|
88
88
|
"dotenv": "^16.4.7",
|
|
89
89
|
"https-proxy-agent": "^7.0.6",
|
package/src/graphs/Graph.ts
CHANGED
|
@@ -184,10 +184,9 @@ export class StandardGraph extends Graph<t.BaseGraphState, GraphNode> {
|
|
|
184
184
|
finalInstructions &&
|
|
185
185
|
provider === Providers.ANTHROPIC &&
|
|
186
186
|
((
|
|
187
|
-
clientOptions as t.AnthropicClientOptions
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
) ??
|
|
187
|
+
(clientOptions as t.AnthropicClientOptions).clientOptions
|
|
188
|
+
?.defaultHeaders as Record<string, string> | undefined
|
|
189
|
+
)?.['anthropic-beta']?.includes('prompt-caching') ??
|
|
191
190
|
false)
|
|
192
191
|
) {
|
|
193
192
|
finalInstructions = {
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import Anthropic from '@anthropic-ai/sdk';
|
|
2
2
|
import { BindToolsInput } from '@langchain/core/language_models/chat_models';
|
|
3
3
|
|
|
4
|
+
export type AnthropicStreamUsage = Anthropic.Usage;
|
|
5
|
+
export type AnthropicMessageDeltaEvent = Anthropic.MessageDeltaEvent;
|
|
6
|
+
export type AnthropicMessageStartEvent = Anthropic.MessageStartEvent;
|
|
7
|
+
|
|
4
8
|
export type AnthropicToolResponse = {
|
|
5
9
|
type: 'tool_use';
|
|
6
10
|
id: string;
|
|
@@ -9,10 +13,7 @@ export type AnthropicToolResponse = {
|
|
|
9
13
|
input: Record<string, any>;
|
|
10
14
|
};
|
|
11
15
|
|
|
12
|
-
export type AnthropicStreamUsage = Anthropic.Usage;
|
|
13
16
|
export type AnthropicMessageParam = Anthropic.MessageParam;
|
|
14
|
-
export type AnthropicMessageDeltaEvent = Anthropic.MessageDeltaEvent;
|
|
15
|
-
export type AnthropicMessageStartEvent = Anthropic.MessageStartEvent;
|
|
16
17
|
export type AnthropicMessageResponse =
|
|
17
18
|
| Anthropic.ContentBlock
|
|
18
19
|
| AnthropicToolResponse;
|
|
@@ -42,6 +43,25 @@ export type AnthropicDocumentBlockParam = Anthropic.Messages.DocumentBlockParam;
|
|
|
42
43
|
export type AnthropicThinkingBlockParam = Anthropic.Messages.ThinkingBlockParam;
|
|
43
44
|
export type AnthropicRedactedThinkingBlockParam =
|
|
44
45
|
Anthropic.Messages.RedactedThinkingBlockParam;
|
|
46
|
+
export type AnthropicServerToolUseBlockParam =
|
|
47
|
+
Anthropic.Messages.ServerToolUseBlockParam;
|
|
48
|
+
export type AnthropicWebSearchToolResultBlockParam =
|
|
49
|
+
Anthropic.Messages.WebSearchToolResultBlockParam;
|
|
50
|
+
export type AnthropicWebSearchResultBlockParam =
|
|
51
|
+
Anthropic.Messages.WebSearchResultBlockParam;
|
|
52
|
+
|
|
53
|
+
// Union of all possible content block types including server tool use
|
|
54
|
+
export type AnthropicContentBlock =
|
|
55
|
+
| AnthropicTextBlockParam
|
|
56
|
+
| AnthropicImageBlockParam
|
|
57
|
+
| AnthropicToolUseBlockParam
|
|
58
|
+
| AnthropicToolResultBlockParam
|
|
59
|
+
| AnthropicDocumentBlockParam
|
|
60
|
+
| AnthropicThinkingBlockParam
|
|
61
|
+
| AnthropicRedactedThinkingBlockParam
|
|
62
|
+
| AnthropicServerToolUseBlockParam
|
|
63
|
+
| AnthropicWebSearchToolResultBlockParam
|
|
64
|
+
| AnthropicWebSearchResultBlockParam;
|
|
45
65
|
|
|
46
66
|
export function isAnthropicImageBlockParam(
|
|
47
67
|
block: unknown
|
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
parseBase64DataUrl,
|
|
22
22
|
} from '@langchain/core/messages';
|
|
23
23
|
import { ToolCall } from '@langchain/core/messages/tool';
|
|
24
|
-
import
|
|
24
|
+
import {
|
|
25
25
|
AnthropicImageBlockParam,
|
|
26
26
|
AnthropicMessageCreateParams,
|
|
27
27
|
AnthropicTextBlockParam,
|
|
@@ -31,8 +31,10 @@ import type {
|
|
|
31
31
|
AnthropicDocumentBlockParam,
|
|
32
32
|
AnthropicThinkingBlockParam,
|
|
33
33
|
AnthropicRedactedThinkingBlockParam,
|
|
34
|
+
AnthropicServerToolUseBlockParam,
|
|
35
|
+
AnthropicWebSearchToolResultBlockParam,
|
|
36
|
+
isAnthropicImageBlockParam,
|
|
34
37
|
} from '@/llm/anthropic/types';
|
|
35
|
-
import { isAnthropicImageBlockParam } from '@/llm/anthropic/types';
|
|
36
38
|
|
|
37
39
|
function _formatImage(imageUrl: string) {
|
|
38
40
|
const parsed = parseBase64DataUrl({ dataUrl: imageUrl });
|
|
@@ -119,7 +121,6 @@ function _ensureMessageContents(
|
|
|
119
121
|
{
|
|
120
122
|
type: 'tool_result',
|
|
121
123
|
// rare case: message.content could be undefined
|
|
122
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
123
124
|
...(message.content != null
|
|
124
125
|
? { content: _formatContent(message.content) }
|
|
125
126
|
: {}),
|
|
@@ -347,7 +348,14 @@ const standardContentBlockConverter: StandardContentBlockConverter<{
|
|
|
347
348
|
};
|
|
348
349
|
|
|
349
350
|
function _formatContent(content: MessageContent) {
|
|
350
|
-
const toolTypes = [
|
|
351
|
+
const toolTypes = [
|
|
352
|
+
'tool_use',
|
|
353
|
+
'tool_result',
|
|
354
|
+
'input_json_delta',
|
|
355
|
+
'server_tool_use',
|
|
356
|
+
'web_search_tool_result',
|
|
357
|
+
'web_search_result',
|
|
358
|
+
];
|
|
351
359
|
const textTypes = ['text', 'text_delta'];
|
|
352
360
|
|
|
353
361
|
if (typeof content === 'string') {
|
|
@@ -408,6 +416,9 @@ function _formatContent(content: MessageContent) {
|
|
|
408
416
|
type: 'text' as const, // Explicitly setting the type as "text"
|
|
409
417
|
text: contentPart.text,
|
|
410
418
|
...(cacheControl ? { cache_control: cacheControl } : {}),
|
|
419
|
+
...('citations' in contentPart && contentPart.citations
|
|
420
|
+
? { citations: contentPart.citations }
|
|
421
|
+
: {}),
|
|
411
422
|
};
|
|
412
423
|
} else if (toolTypes.find((t) => t === contentPart.type)) {
|
|
413
424
|
const contentPartCopy = { ...contentPart };
|
|
@@ -502,7 +513,8 @@ export function _convertMessagesToAnthropicPayload(
|
|
|
502
513
|
content.find(
|
|
503
514
|
(contentPart) =>
|
|
504
515
|
(contentPart.type === 'tool_use' ||
|
|
505
|
-
contentPart.type === 'input_json_delta'
|
|
516
|
+
contentPart.type === 'input_json_delta' ||
|
|
517
|
+
contentPart.type === 'server_tool_use') &&
|
|
506
518
|
contentPart.id === toolCall.id
|
|
507
519
|
)
|
|
508
520
|
);
|
|
@@ -548,6 +560,8 @@ function mergeMessages(messages: AnthropicMessageCreateParams['messages']) {
|
|
|
548
560
|
| AnthropicDocumentBlockParam
|
|
549
561
|
| AnthropicThinkingBlockParam
|
|
550
562
|
| AnthropicRedactedThinkingBlockParam
|
|
563
|
+
| AnthropicServerToolUseBlockParam
|
|
564
|
+
| AnthropicWebSearchToolResultBlockParam
|
|
551
565
|
>
|
|
552
566
|
): Array<
|
|
553
567
|
| AnthropicTextBlockParam
|
|
@@ -557,6 +571,8 @@ function mergeMessages(messages: AnthropicMessageCreateParams['messages']) {
|
|
|
557
571
|
| AnthropicDocumentBlockParam
|
|
558
572
|
| AnthropicThinkingBlockParam
|
|
559
573
|
| AnthropicRedactedThinkingBlockParam
|
|
574
|
+
| AnthropicServerToolUseBlockParam
|
|
575
|
+
| AnthropicWebSearchToolResultBlockParam
|
|
560
576
|
> => {
|
|
561
577
|
if (typeof content === 'string') {
|
|
562
578
|
return [
|
|
@@ -77,7 +77,12 @@ export function _makeMessageChunkFromAnthropicEvent(
|
|
|
77
77
|
};
|
|
78
78
|
} else if (
|
|
79
79
|
data.type === 'content_block_start' &&
|
|
80
|
-
[
|
|
80
|
+
[
|
|
81
|
+
'tool_use',
|
|
82
|
+
'document',
|
|
83
|
+
'server_tool_use',
|
|
84
|
+
'web_search_tool_result',
|
|
85
|
+
].includes(data.content_block.type)
|
|
81
86
|
) {
|
|
82
87
|
const contentBlock = data.content_block;
|
|
83
88
|
let toolCallChunks: ToolCallChunk[];
|
|
@@ -90,6 +95,16 @@ export function _makeMessageChunkFromAnthropicEvent(
|
|
|
90
95
|
args: '',
|
|
91
96
|
},
|
|
92
97
|
];
|
|
98
|
+
} else if (contentBlock.type === 'server_tool_use') {
|
|
99
|
+
// Handle anthropic built-in server tool use (like web search)
|
|
100
|
+
toolCallChunks = [
|
|
101
|
+
{
|
|
102
|
+
id: contentBlock.id,
|
|
103
|
+
index: data.index,
|
|
104
|
+
name: contentBlock.name,
|
|
105
|
+
args: '',
|
|
106
|
+
},
|
|
107
|
+
];
|
|
93
108
|
} else {
|
|
94
109
|
toolCallChunks = [];
|
|
95
110
|
}
|
|
@@ -101,7 +116,11 @@ export function _makeMessageChunkFromAnthropicEvent(
|
|
|
101
116
|
{
|
|
102
117
|
index: data.index,
|
|
103
118
|
...data.content_block,
|
|
104
|
-
input:
|
|
119
|
+
input:
|
|
120
|
+
contentBlock.type === 'server_tool_use' ||
|
|
121
|
+
contentBlock.type === 'tool_use'
|
|
122
|
+
? ''
|
|
123
|
+
: undefined,
|
|
105
124
|
},
|
|
106
125
|
],
|
|
107
126
|
additional_kwargs: {},
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-empty-object-type */
|
|
3
|
-
import { z } from 'zod';
|
|
4
3
|
import {
|
|
5
4
|
BaseLLMOutputParser,
|
|
6
5
|
OutputParserException,
|
|
7
6
|
} from '@langchain/core/output_parsers';
|
|
8
7
|
import { JsonOutputKeyToolsParserParams } from '@langchain/core/output_parsers/openai_tools';
|
|
8
|
+
import {
|
|
9
|
+
interopSafeParseAsync,
|
|
10
|
+
InteropZodType,
|
|
11
|
+
} from '@langchain/core/utils/types';
|
|
9
12
|
import { ChatGeneration } from '@langchain/core/outputs';
|
|
10
13
|
import { ToolCall } from '@langchain/core/messages/tool';
|
|
11
14
|
|
|
@@ -31,7 +34,7 @@ export class AnthropicToolsOutputParser<
|
|
|
31
34
|
/** Whether to return only the first tool call. */
|
|
32
35
|
returnSingle = false;
|
|
33
36
|
|
|
34
|
-
zodSchema?:
|
|
37
|
+
zodSchema?: InteropZodType<T>;
|
|
35
38
|
|
|
36
39
|
constructor(params: AnthropicToolsOutputParserParams<T>) {
|
|
37
40
|
super(params);
|
|
@@ -62,7 +65,10 @@ export class AnthropicToolsOutputParser<
|
|
|
62
65
|
if (this.zodSchema === undefined) {
|
|
63
66
|
return parsedResult as T;
|
|
64
67
|
}
|
|
65
|
-
const zodParsedResult = await
|
|
68
|
+
const zodParsedResult = await interopSafeParseAsync(
|
|
69
|
+
this.zodSchema,
|
|
70
|
+
parsedResult
|
|
71
|
+
);
|
|
66
72
|
if (zodParsedResult.success) {
|
|
67
73
|
return zodParsedResult.data;
|
|
68
74
|
} else {
|
|
@@ -71,7 +77,7 @@ export class AnthropicToolsOutputParser<
|
|
|
71
77
|
result,
|
|
72
78
|
null,
|
|
73
79
|
2
|
|
74
|
-
)}". Error: ${JSON.stringify(zodParsedResult.error.
|
|
80
|
+
)}". Error: ${JSON.stringify(zodParsedResult.error.issues)}`,
|
|
75
81
|
JSON.stringify(parsedResult, null, 2)
|
|
76
82
|
);
|
|
77
83
|
}
|
|
@@ -100,6 +106,7 @@ export class AnthropicToolsOutputParser<
|
|
|
100
106
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
101
107
|
export function extractToolCalls(content: Record<string, any>[]) {
|
|
102
108
|
const toolCalls: ToolCall[] = [];
|
|
109
|
+
|
|
103
110
|
for (const block of content) {
|
|
104
111
|
if (block.type === 'tool_use') {
|
|
105
112
|
toolCalls.push({
|
|
@@ -108,7 +115,19 @@ export function extractToolCalls(content: Record<string, any>[]) {
|
|
|
108
115
|
id: block.id,
|
|
109
116
|
type: 'tool_call',
|
|
110
117
|
});
|
|
118
|
+
} else if (
|
|
119
|
+
block.type === 'server_tool_use' &&
|
|
120
|
+
block.name === 'web_search'
|
|
121
|
+
) {
|
|
122
|
+
// Handle Anthropic built-in web search tool
|
|
123
|
+
toolCalls.push({
|
|
124
|
+
name: block.name,
|
|
125
|
+
args: block.input,
|
|
126
|
+
id: block.id,
|
|
127
|
+
type: 'tool_call',
|
|
128
|
+
});
|
|
111
129
|
}
|
|
112
130
|
}
|
|
131
|
+
|
|
113
132
|
return toolCalls;
|
|
114
133
|
}
|