@librechat/agents 2.4.43 → 2.4.44

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.
@@ -3,12 +3,12 @@
3
3
  var ollama = require('@langchain/ollama');
4
4
  var mistralai = require('@langchain/mistralai');
5
5
  var aws = require('@langchain/aws');
6
- var googleVertexai = require('@langchain/google-vertexai');
7
6
  var web = require('@langchain/community/chat_models/bedrock/web');
7
+ var index$3 = require('./openai/index.cjs');
8
8
  var index = require('./google/index.cjs');
9
9
  var index$2 = require('./anthropic/index.cjs');
10
10
  var index$1 = require('./openrouter/index.cjs');
11
- var index$3 = require('./openai/index.cjs');
11
+ var index$4 = require('./vertexai/index.cjs');
12
12
  var _enum = require('../common/enum.cjs');
13
13
 
14
14
  // src/llm/providers.ts
@@ -17,7 +17,7 @@ const llmProviders = {
17
17
  [_enum.Providers.OPENAI]: index$3.ChatOpenAI,
18
18
  [_enum.Providers.OLLAMA]: ollama.ChatOllama,
19
19
  [_enum.Providers.AZURE]: index$3.AzureChatOpenAI,
20
- [_enum.Providers.VERTEXAI]: googleVertexai.ChatVertexAI,
20
+ [_enum.Providers.VERTEXAI]: index$4.ChatVertexAI,
21
21
  [_enum.Providers.DEEPSEEK]: index$3.ChatDeepSeek,
22
22
  [_enum.Providers.MISTRALAI]: mistralai.ChatMistralAI,
23
23
  [_enum.Providers.MISTRAL]: mistralai.ChatMistralAI,
@@ -1 +1 @@
1
- {"version":3,"file":"providers.cjs","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":["Providers","ChatXAI","ChatOpenAI","ChatOllama","AzureChatOpenAI","ChatVertexAI","ChatDeepSeek","ChatMistralAI","CustomAnthropic","ChatOpenRouter","BedrockChat","ChatBedrockConverse","CustomChatGoogleGenerativeAI"],"mappings":";;;;;;;;;;;;;AAAA;AAuBa,MAAA,YAAY,GAAqC;AAC5D,IAAA,CAACA,eAAS,CAAC,GAAG,GAAGC,eAAO;AACxB,IAAA,CAACD,eAAS,CAAC,MAAM,GAAGE,kBAAU;AAC9B,IAAA,CAACF,eAAS,CAAC,MAAM,GAAGG,iBAAU;AAC9B,IAAA,CAACH,eAAS,CAAC,KAAK,GAAGI,uBAAe;AAClC,IAAA,CAACJ,eAAS,CAAC,QAAQ,GAAGK,2BAAY;AAClC,IAAA,CAACL,eAAS,CAAC,QAAQ,GAAGM,oBAAY;AAClC,IAAA,CAACN,eAAS,CAAC,SAAS,GAAGO,uBAAa;AACpC,IAAA,CAACP,eAAS,CAAC,OAAO,GAAGO,uBAAa;AAClC,IAAA,CAACP,eAAS,CAAC,SAAS,GAAGQ,uBAAe;AACtC,IAAA,CAACR,eAAS,CAAC,UAAU,GAAGS,sBAAc;AACtC,IAAA,CAACT,eAAS,CAAC,cAAc,GAAGU,eAAW;AACvC,IAAA,CAACV,eAAS,CAAC,OAAO,GAAGW,uBAAmB;;AAExC,IAAA,CAACX,eAAS,CAAC,MAAM,GAAGY,kCAA4B;;AAGrC,MAAA,yBAAyB,GAAG,IAAI,GAAG,CAAqB;AACnE,IAAAZ,eAAS,CAAC,SAAS;AACnB,IAAAA,eAAS,CAAC,OAAO;AACjB,IAAAA,eAAS,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
+ {"version":3,"file":"providers.cjs","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';\n// import { 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 {\n AzureChatOpenAI,\n ChatDeepSeek,\n ChatOpenAI,\n ChatXAI,\n} from '@/llm/openai';\nimport { CustomChatGoogleGenerativeAI } from '@/llm/google';\nimport { CustomAnthropic } from '@/llm/anthropic';\nimport { ChatOpenRouter } from '@/llm/openrouter';\nimport { ChatVertexAI } from '@/llm/vertexai';\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":["Providers","ChatXAI","ChatOpenAI","ChatOllama","AzureChatOpenAI","ChatVertexAI","ChatDeepSeek","ChatMistralAI","CustomAnthropic","ChatOpenRouter","BedrockChat","ChatBedrockConverse","CustomChatGoogleGenerativeAI"],"mappings":";;;;;;;;;;;;;AAAA;AAwBa,MAAA,YAAY,GAAqC;AAC5D,IAAA,CAACA,eAAS,CAAC,GAAG,GAAGC,eAAO;AACxB,IAAA,CAACD,eAAS,CAAC,MAAM,GAAGE,kBAAU;AAC9B,IAAA,CAACF,eAAS,CAAC,MAAM,GAAGG,iBAAU;AAC9B,IAAA,CAACH,eAAS,CAAC,KAAK,GAAGI,uBAAe;AAClC,IAAA,CAACJ,eAAS,CAAC,QAAQ,GAAGK,oBAAY;AAClC,IAAA,CAACL,eAAS,CAAC,QAAQ,GAAGM,oBAAY;AAClC,IAAA,CAACN,eAAS,CAAC,SAAS,GAAGO,uBAAa;AACpC,IAAA,CAACP,eAAS,CAAC,OAAO,GAAGO,uBAAa;AAClC,IAAA,CAACP,eAAS,CAAC,SAAS,GAAGQ,uBAAe;AACtC,IAAA,CAACR,eAAS,CAAC,UAAU,GAAGS,sBAAc;AACtC,IAAA,CAACT,eAAS,CAAC,cAAc,GAAGU,eAAW;AACvC,IAAA,CAACV,eAAS,CAAC,OAAO,GAAGW,uBAAmB;;AAExC,IAAA,CAACX,eAAS,CAAC,MAAM,GAAGY,kCAA4B;;AAGrC,MAAA,yBAAyB,GAAG,IAAI,GAAG,CAAqB;AACnE,IAAAZ,eAAS,CAAC,SAAS;AACnB,IAAAA,eAAS,CAAC,OAAO;AACjB,IAAAA,eAAS,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;;;;;;"}
@@ -0,0 +1,330 @@
1
+ 'use strict';
2
+
3
+ var googleGauth = require('@langchain/google-gauth');
4
+ var googleCommon = require('@langchain/google-common');
5
+
6
+ class CustomChatConnection extends googleCommon.ChatConnection {
7
+ async formatData(input, parameters) {
8
+ const formattedData = (await super.formatData(input, parameters));
9
+ if (formattedData.generationConfig?.thinkingConfig?.thinkingBudget === -1 &&
10
+ formattedData.generationConfig.thinkingConfig.includeThoughts === false) {
11
+ formattedData.generationConfig.thinkingConfig.includeThoughts = true;
12
+ }
13
+ return formattedData;
14
+ }
15
+ }
16
+ /**
17
+ * Integration with Google Vertex AI chat models.
18
+ *
19
+ * Setup:
20
+ * Install `@langchain/google-vertexai` and set your stringified
21
+ * Vertex AI credentials as an environment variable named `GOOGLE_APPLICATION_CREDENTIALS`.
22
+ *
23
+ * ```bash
24
+ * npm install @langchain/google-vertexai
25
+ * export GOOGLE_APPLICATION_CREDENTIALS="path/to/credentials"
26
+ * ```
27
+ *
28
+ * ## [Constructor args](https://api.js.langchain.com/classes/_langchain_google_vertexai.index.ChatVertexAI.html#constructor.new_ChatVertexAI)
29
+ *
30
+ * ## [Runtime args](https://api.js.langchain.com/interfaces/langchain_google_common_types.GoogleAIBaseLanguageModelCallOptions.html)
31
+ *
32
+ * Runtime args can be passed as the second argument to any of the base runnable methods `.invoke`. `.stream`, `.batch`, etc.
33
+ * They can also be passed via `.withConfig`, or the second arg in `.bindTools`, like shown in the examples below:
34
+ *
35
+ * ```typescript
36
+ * // When calling `.withConfig`, call options should be passed via the first argument
37
+ * const llmWithArgsBound = llm.withConfig({
38
+ * stop: ["\n"],
39
+ * tools: [...],
40
+ * });
41
+ *
42
+ * // When calling `.bindTools`, call options should be passed via the second argument
43
+ * const llmWithTools = llm.bindTools(
44
+ * [...],
45
+ * {
46
+ * tool_choice: "auto",
47
+ * }
48
+ * );
49
+ * ```
50
+ *
51
+ * ## Examples
52
+ *
53
+ * <details open>
54
+ * <summary><strong>Instantiate</strong></summary>
55
+ *
56
+ * ```typescript
57
+ * import { ChatVertexAI } from '@langchain/google-vertexai';
58
+ *
59
+ * const llm = new ChatVertexAI({
60
+ * model: "gemini-1.5-pro",
61
+ * temperature: 0,
62
+ * // other params...
63
+ * });
64
+ * ```
65
+ * </details>
66
+ *
67
+ * <br />
68
+ *
69
+ * <details>
70
+ * <summary><strong>Invoking</strong></summary>
71
+ *
72
+ * ```typescript
73
+ * const input = `Translate "I love programming" into French.`;
74
+ *
75
+ * // Models also accept a list of chat messages or a formatted prompt
76
+ * const result = await llm.invoke(input);
77
+ * console.log(result);
78
+ * ```
79
+ *
80
+ * ```txt
81
+ * AIMessageChunk {
82
+ * "content": "\"J'adore programmer\" \n\nHere's why this is the best translation:\n\n* **J'adore** means \"I love\" and conveys a strong passion.\n* **Programmer** is the French verb for \"to program.\"\n\nThis translation is natural and idiomatic in French. \n",
83
+ * "additional_kwargs": {},
84
+ * "response_metadata": {},
85
+ * "tool_calls": [],
86
+ * "tool_call_chunks": [],
87
+ * "invalid_tool_calls": [],
88
+ * "usage_metadata": {
89
+ * "input_tokens": 9,
90
+ * "output_tokens": 63,
91
+ * "total_tokens": 72
92
+ * }
93
+ * }
94
+ * ```
95
+ * </details>
96
+ *
97
+ * <br />
98
+ *
99
+ * <details>
100
+ * <summary><strong>Streaming Chunks</strong></summary>
101
+ *
102
+ * ```typescript
103
+ * for await (const chunk of await llm.stream(input)) {
104
+ * console.log(chunk);
105
+ * }
106
+ * ```
107
+ *
108
+ * ```txt
109
+ * AIMessageChunk {
110
+ * "content": "\"",
111
+ * "additional_kwargs": {},
112
+ * "response_metadata": {},
113
+ * "tool_calls": [],
114
+ * "tool_call_chunks": [],
115
+ * "invalid_tool_calls": []
116
+ * }
117
+ * AIMessageChunk {
118
+ * "content": "J'adore programmer\" \n",
119
+ * "additional_kwargs": {},
120
+ * "response_metadata": {},
121
+ * "tool_calls": [],
122
+ * "tool_call_chunks": [],
123
+ * "invalid_tool_calls": []
124
+ * }
125
+ * AIMessageChunk {
126
+ * "content": "",
127
+ * "additional_kwargs": {},
128
+ * "response_metadata": {},
129
+ * "tool_calls": [],
130
+ * "tool_call_chunks": [],
131
+ * "invalid_tool_calls": []
132
+ * }
133
+ * AIMessageChunk {
134
+ * "content": "",
135
+ * "additional_kwargs": {},
136
+ * "response_metadata": {
137
+ * "finishReason": "stop"
138
+ * },
139
+ * "tool_calls": [],
140
+ * "tool_call_chunks": [],
141
+ * "invalid_tool_calls": [],
142
+ * "usage_metadata": {
143
+ * "input_tokens": 9,
144
+ * "output_tokens": 8,
145
+ * "total_tokens": 17
146
+ * }
147
+ * }
148
+ * ```
149
+ * </details>
150
+ *
151
+ * <br />
152
+ *
153
+ * <details>
154
+ * <summary><strong>Aggregate Streamed Chunks</strong></summary>
155
+ *
156
+ * ```typescript
157
+ * import { AIMessageChunk } from '@langchain/core/messages';
158
+ * import { concat } from '@langchain/core/utils/stream';
159
+ *
160
+ * const stream = await llm.stream(input);
161
+ * let full: AIMessageChunk | undefined;
162
+ * for await (const chunk of stream) {
163
+ * full = !full ? chunk : concat(full, chunk);
164
+ * }
165
+ * console.log(full);
166
+ * ```
167
+ *
168
+ * ```txt
169
+ * AIMessageChunk {
170
+ * "content": "\"J'adore programmer\" \n",
171
+ * "additional_kwargs": {},
172
+ * "response_metadata": {
173
+ * "finishReason": "stop"
174
+ * },
175
+ * "tool_calls": [],
176
+ * "tool_call_chunks": [],
177
+ * "invalid_tool_calls": [],
178
+ * "usage_metadata": {
179
+ * "input_tokens": 9,
180
+ * "output_tokens": 8,
181
+ * "total_tokens": 17
182
+ * }
183
+ * }
184
+ * ```
185
+ * </details>
186
+ *
187
+ * <br />
188
+ *
189
+ * <details>
190
+ * <summary><strong>Bind tools</strong></summary>
191
+ *
192
+ * ```typescript
193
+ * import { z } from 'zod';
194
+ *
195
+ * const GetWeather = {
196
+ * name: "GetWeather",
197
+ * description: "Get the current weather in a given location",
198
+ * schema: z.object({
199
+ * location: z.string().describe("The city and state, e.g. San Francisco, CA")
200
+ * }),
201
+ * }
202
+ *
203
+ * const GetPopulation = {
204
+ * name: "GetPopulation",
205
+ * description: "Get the current population in a given location",
206
+ * schema: z.object({
207
+ * location: z.string().describe("The city and state, e.g. San Francisco, CA")
208
+ * }),
209
+ * }
210
+ *
211
+ * const llmWithTools = llm.bindTools([GetWeather, GetPopulation]);
212
+ * const aiMsg = await llmWithTools.invoke(
213
+ * "Which city is hotter today and which is bigger: LA or NY?"
214
+ * );
215
+ * console.log(aiMsg.tool_calls);
216
+ * ```
217
+ *
218
+ * ```txt
219
+ * [
220
+ * {
221
+ * name: 'GetPopulation',
222
+ * args: { location: 'New York City, NY' },
223
+ * id: '33c1c1f47e2f492799c77d2800a43912',
224
+ * type: 'tool_call'
225
+ * }
226
+ * ]
227
+ * ```
228
+ * </details>
229
+ *
230
+ * <br />
231
+ *
232
+ * <details>
233
+ * <summary><strong>Structured Output</strong></summary>
234
+ *
235
+ * ```typescript
236
+ * import { z } from 'zod';
237
+ *
238
+ * const Joke = z.object({
239
+ * setup: z.string().describe("The setup of the joke"),
240
+ * punchline: z.string().describe("The punchline to the joke"),
241
+ * rating: z.number().optional().describe("How funny the joke is, from 1 to 10")
242
+ * }).describe('Joke to tell user.');
243
+ *
244
+ * const structuredLlm = llm.withStructuredOutput(Joke, { name: "Joke" });
245
+ * const jokeResult = await structuredLlm.invoke("Tell me a joke about cats");
246
+ * console.log(jokeResult);
247
+ * ```
248
+ *
249
+ * ```txt
250
+ * {
251
+ * setup: 'What do you call a cat that loves to bowl?',
252
+ * punchline: 'An alley cat!'
253
+ * }
254
+ * ```
255
+ * </details>
256
+ *
257
+ * <br />
258
+ *
259
+ * <details>
260
+ * <summary><strong>Usage Metadata</strong></summary>
261
+ *
262
+ * ```typescript
263
+ * const aiMsgForMetadata = await llm.invoke(input);
264
+ * console.log(aiMsgForMetadata.usage_metadata);
265
+ * ```
266
+ *
267
+ * ```txt
268
+ * { input_tokens: 9, output_tokens: 8, total_tokens: 17 }
269
+ * ```
270
+ * </details>
271
+ *
272
+ * <br />
273
+ *
274
+ * <details>
275
+ * <summary><strong>Stream Usage Metadata</strong></summary>
276
+ *
277
+ * ```typescript
278
+ * const streamForMetadata = await llm.stream(
279
+ * input,
280
+ * {
281
+ * streamUsage: true
282
+ * }
283
+ * );
284
+ * let fullForMetadata: AIMessageChunk | undefined;
285
+ * for await (const chunk of streamForMetadata) {
286
+ * fullForMetadata = !fullForMetadata ? chunk : concat(fullForMetadata, chunk);
287
+ * }
288
+ * console.log(fullForMetadata?.usage_metadata);
289
+ * ```
290
+ *
291
+ * ```txt
292
+ * { input_tokens: 9, output_tokens: 8, total_tokens: 17 }
293
+ * ```
294
+ * </details>
295
+ *
296
+ * <br />
297
+ */
298
+ class ChatVertexAI extends googleGauth.ChatGoogle {
299
+ lc_namespace = ['langchain', 'chat_models', 'vertexai'];
300
+ dynamicThinkingBudget = false;
301
+ static lc_name() {
302
+ return 'ChatVertexAI';
303
+ }
304
+ constructor(fields) {
305
+ let dynamicThinkingBudget = false;
306
+ if (fields?.thinkingBudget === -1) {
307
+ dynamicThinkingBudget = true;
308
+ fields.thinkingBudget = 1;
309
+ }
310
+ super({
311
+ ...fields,
312
+ platformType: 'gcp',
313
+ });
314
+ this.dynamicThinkingBudget = dynamicThinkingBudget;
315
+ }
316
+ invocationParams(options) {
317
+ const params = super.invocationParams(options);
318
+ if (this.dynamicThinkingBudget) {
319
+ params.maxReasoningTokens = -1;
320
+ }
321
+ return params;
322
+ }
323
+ buildConnection(fields, client) {
324
+ this.connection = new CustomChatConnection({ ...fields, ...this }, this.caller, client, false);
325
+ this.streamedConnection = new CustomChatConnection({ ...fields, ...this }, this.caller, client, true);
326
+ }
327
+ }
328
+
329
+ exports.ChatVertexAI = ChatVertexAI;
330
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":["../../../../src/llm/vertexai/index.ts"],"sourcesContent":["import { ChatGoogle } from '@langchain/google-gauth';\nimport { ChatConnection } from '@langchain/google-common';\nimport type {\n GeminiRequest,\n GoogleAIModelRequestParams,\n GoogleAbstractedClient,\n} from '@langchain/google-common';\nimport type { BaseMessage } from '@langchain/core/messages';\nimport type { VertexAIClientOptions } from '@/types';\n\nclass CustomChatConnection extends ChatConnection<VertexAIClientOptions> {\n async formatData(\n input: BaseMessage[],\n parameters: GoogleAIModelRequestParams\n ): Promise<unknown> {\n const formattedData = (await super.formatData(\n input,\n parameters\n )) as GeminiRequest;\n if (\n formattedData.generationConfig?.thinkingConfig?.thinkingBudget === -1 &&\n formattedData.generationConfig.thinkingConfig.includeThoughts === false\n ) {\n formattedData.generationConfig.thinkingConfig.includeThoughts = true;\n }\n return formattedData;\n }\n}\n\n/**\n * Integration with Google Vertex AI chat models.\n *\n * Setup:\n * Install `@langchain/google-vertexai` and set your stringified\n * Vertex AI credentials as an environment variable named `GOOGLE_APPLICATION_CREDENTIALS`.\n *\n * ```bash\n * npm install @langchain/google-vertexai\n * export GOOGLE_APPLICATION_CREDENTIALS=\"path/to/credentials\"\n * ```\n *\n * ## [Constructor args](https://api.js.langchain.com/classes/_langchain_google_vertexai.index.ChatVertexAI.html#constructor.new_ChatVertexAI)\n *\n * ## [Runtime args](https://api.js.langchain.com/interfaces/langchain_google_common_types.GoogleAIBaseLanguageModelCallOptions.html)\n *\n * Runtime args can be passed as the second argument to any of the base runnable methods `.invoke`. `.stream`, `.batch`, etc.\n * They can also be passed via `.withConfig`, or the second arg in `.bindTools`, like shown in the examples below:\n *\n * ```typescript\n * // When calling `.withConfig`, call options should be passed via the first argument\n * const llmWithArgsBound = llm.withConfig({\n * stop: [\"\\n\"],\n * tools: [...],\n * });\n *\n * // When calling `.bindTools`, call options should be passed via the second argument\n * const llmWithTools = llm.bindTools(\n * [...],\n * {\n * tool_choice: \"auto\",\n * }\n * );\n * ```\n *\n * ## Examples\n *\n * <details open>\n * <summary><strong>Instantiate</strong></summary>\n *\n * ```typescript\n * import { ChatVertexAI } from '@langchain/google-vertexai';\n *\n * const llm = new ChatVertexAI({\n * model: \"gemini-1.5-pro\",\n * temperature: 0,\n * // other params...\n * });\n * ```\n * </details>\n *\n * <br />\n *\n * <details>\n * <summary><strong>Invoking</strong></summary>\n *\n * ```typescript\n * const input = `Translate \"I love programming\" into French.`;\n *\n * // Models also accept a list of chat messages or a formatted prompt\n * const result = await llm.invoke(input);\n * console.log(result);\n * ```\n *\n * ```txt\n * AIMessageChunk {\n * \"content\": \"\\\"J'adore programmer\\\" \\n\\nHere's why this is the best translation:\\n\\n* **J'adore** means \\\"I love\\\" and conveys a strong passion.\\n* **Programmer** is the French verb for \\\"to program.\\\"\\n\\nThis translation is natural and idiomatic in French. \\n\",\n * \"additional_kwargs\": {},\n * \"response_metadata\": {},\n * \"tool_calls\": [],\n * \"tool_call_chunks\": [],\n * \"invalid_tool_calls\": [],\n * \"usage_metadata\": {\n * \"input_tokens\": 9,\n * \"output_tokens\": 63,\n * \"total_tokens\": 72\n * }\n * }\n * ```\n * </details>\n *\n * <br />\n *\n * <details>\n * <summary><strong>Streaming Chunks</strong></summary>\n *\n * ```typescript\n * for await (const chunk of await llm.stream(input)) {\n * console.log(chunk);\n * }\n * ```\n *\n * ```txt\n * AIMessageChunk {\n * \"content\": \"\\\"\",\n * \"additional_kwargs\": {},\n * \"response_metadata\": {},\n * \"tool_calls\": [],\n * \"tool_call_chunks\": [],\n * \"invalid_tool_calls\": []\n * }\n * AIMessageChunk {\n * \"content\": \"J'adore programmer\\\" \\n\",\n * \"additional_kwargs\": {},\n * \"response_metadata\": {},\n * \"tool_calls\": [],\n * \"tool_call_chunks\": [],\n * \"invalid_tool_calls\": []\n * }\n * AIMessageChunk {\n * \"content\": \"\",\n * \"additional_kwargs\": {},\n * \"response_metadata\": {},\n * \"tool_calls\": [],\n * \"tool_call_chunks\": [],\n * \"invalid_tool_calls\": []\n * }\n * AIMessageChunk {\n * \"content\": \"\",\n * \"additional_kwargs\": {},\n * \"response_metadata\": {\n * \"finishReason\": \"stop\"\n * },\n * \"tool_calls\": [],\n * \"tool_call_chunks\": [],\n * \"invalid_tool_calls\": [],\n * \"usage_metadata\": {\n * \"input_tokens\": 9,\n * \"output_tokens\": 8,\n * \"total_tokens\": 17\n * }\n * }\n * ```\n * </details>\n *\n * <br />\n *\n * <details>\n * <summary><strong>Aggregate Streamed Chunks</strong></summary>\n *\n * ```typescript\n * import { AIMessageChunk } from '@langchain/core/messages';\n * import { concat } from '@langchain/core/utils/stream';\n *\n * const stream = await llm.stream(input);\n * let full: AIMessageChunk | undefined;\n * for await (const chunk of stream) {\n * full = !full ? chunk : concat(full, chunk);\n * }\n * console.log(full);\n * ```\n *\n * ```txt\n * AIMessageChunk {\n * \"content\": \"\\\"J'adore programmer\\\" \\n\",\n * \"additional_kwargs\": {},\n * \"response_metadata\": {\n * \"finishReason\": \"stop\"\n * },\n * \"tool_calls\": [],\n * \"tool_call_chunks\": [],\n * \"invalid_tool_calls\": [],\n * \"usage_metadata\": {\n * \"input_tokens\": 9,\n * \"output_tokens\": 8,\n * \"total_tokens\": 17\n * }\n * }\n * ```\n * </details>\n *\n * <br />\n *\n * <details>\n * <summary><strong>Bind tools</strong></summary>\n *\n * ```typescript\n * import { z } from 'zod';\n *\n * const GetWeather = {\n * name: \"GetWeather\",\n * description: \"Get the current weather in a given location\",\n * schema: z.object({\n * location: z.string().describe(\"The city and state, e.g. San Francisco, CA\")\n * }),\n * }\n *\n * const GetPopulation = {\n * name: \"GetPopulation\",\n * description: \"Get the current population in a given location\",\n * schema: z.object({\n * location: z.string().describe(\"The city and state, e.g. San Francisco, CA\")\n * }),\n * }\n *\n * const llmWithTools = llm.bindTools([GetWeather, GetPopulation]);\n * const aiMsg = await llmWithTools.invoke(\n * \"Which city is hotter today and which is bigger: LA or NY?\"\n * );\n * console.log(aiMsg.tool_calls);\n * ```\n *\n * ```txt\n * [\n * {\n * name: 'GetPopulation',\n * args: { location: 'New York City, NY' },\n * id: '33c1c1f47e2f492799c77d2800a43912',\n * type: 'tool_call'\n * }\n * ]\n * ```\n * </details>\n *\n * <br />\n *\n * <details>\n * <summary><strong>Structured Output</strong></summary>\n *\n * ```typescript\n * import { z } from 'zod';\n *\n * const Joke = z.object({\n * setup: z.string().describe(\"The setup of the joke\"),\n * punchline: z.string().describe(\"The punchline to the joke\"),\n * rating: z.number().optional().describe(\"How funny the joke is, from 1 to 10\")\n * }).describe('Joke to tell user.');\n *\n * const structuredLlm = llm.withStructuredOutput(Joke, { name: \"Joke\" });\n * const jokeResult = await structuredLlm.invoke(\"Tell me a joke about cats\");\n * console.log(jokeResult);\n * ```\n *\n * ```txt\n * {\n * setup: 'What do you call a cat that loves to bowl?',\n * punchline: 'An alley cat!'\n * }\n * ```\n * </details>\n *\n * <br />\n *\n * <details>\n * <summary><strong>Usage Metadata</strong></summary>\n *\n * ```typescript\n * const aiMsgForMetadata = await llm.invoke(input);\n * console.log(aiMsgForMetadata.usage_metadata);\n * ```\n *\n * ```txt\n * { input_tokens: 9, output_tokens: 8, total_tokens: 17 }\n * ```\n * </details>\n *\n * <br />\n *\n * <details>\n * <summary><strong>Stream Usage Metadata</strong></summary>\n *\n * ```typescript\n * const streamForMetadata = await llm.stream(\n * input,\n * {\n * streamUsage: true\n * }\n * );\n * let fullForMetadata: AIMessageChunk | undefined;\n * for await (const chunk of streamForMetadata) {\n * fullForMetadata = !fullForMetadata ? chunk : concat(fullForMetadata, chunk);\n * }\n * console.log(fullForMetadata?.usage_metadata);\n * ```\n *\n * ```txt\n * { input_tokens: 9, output_tokens: 8, total_tokens: 17 }\n * ```\n * </details>\n *\n * <br />\n */\nexport class ChatVertexAI extends ChatGoogle {\n lc_namespace = ['langchain', 'chat_models', 'vertexai'];\n dynamicThinkingBudget = false;\n\n static lc_name(): 'ChatVertexAI' {\n return 'ChatVertexAI';\n }\n\n constructor(fields?: VertexAIClientOptions) {\n let dynamicThinkingBudget = false;\n if (fields?.thinkingBudget === -1) {\n dynamicThinkingBudget = true;\n fields.thinkingBudget = 1;\n }\n super({\n ...fields,\n platformType: 'gcp',\n });\n this.dynamicThinkingBudget = dynamicThinkingBudget;\n }\n invocationParams(\n options?: this['ParsedCallOptions'] | undefined\n ): GoogleAIModelRequestParams {\n const params = super.invocationParams(options);\n if (this.dynamicThinkingBudget) {\n params.maxReasoningTokens = -1;\n }\n return params;\n }\n\n buildConnection(\n fields: VertexAIClientOptions,\n client: GoogleAbstractedClient\n ): void {\n this.connection = new CustomChatConnection(\n { ...fields, ...this },\n this.caller,\n client,\n false\n );\n\n this.streamedConnection = new CustomChatConnection(\n { ...fields, ...this },\n this.caller,\n client,\n true\n );\n }\n}\n"],"names":["ChatConnection","ChatGoogle"],"mappings":";;;;;AAUA,MAAM,oBAAqB,SAAQA,2BAAqC,CAAA;AACtE,IAAA,MAAM,UAAU,CACd,KAAoB,EACpB,UAAsC,EAAA;AAEtC,QAAA,MAAM,aAAa,IAAI,MAAM,KAAK,CAAC,UAAU,CAC3C,KAAK,EACL,UAAU,CACX,CAAkB;QACnB,IACE,aAAa,CAAC,gBAAgB,EAAE,cAAc,EAAE,cAAc,KAAK,EAAE;YACrE,aAAa,CAAC,gBAAgB,CAAC,cAAc,CAAC,eAAe,KAAK,KAAK,EACvE;YACA,aAAa,CAAC,gBAAgB,CAAC,cAAc,CAAC,eAAe,GAAG,IAAI;;AAEtE,QAAA,OAAO,aAAa;;AAEvB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyRG;AACG,MAAO,YAAa,SAAQC,sBAAU,CAAA;IAC1C,YAAY,GAAG,CAAC,WAAW,EAAE,aAAa,EAAE,UAAU,CAAC;IACvD,qBAAqB,GAAG,KAAK;AAE7B,IAAA,OAAO,OAAO,GAAA;AACZ,QAAA,OAAO,cAAc;;AAGvB,IAAA,WAAA,CAAY,MAA8B,EAAA;QACxC,IAAI,qBAAqB,GAAG,KAAK;AACjC,QAAA,IAAI,MAAM,EAAE,cAAc,KAAK,EAAE,EAAE;YACjC,qBAAqB,GAAG,IAAI;AAC5B,YAAA,MAAM,CAAC,cAAc,GAAG,CAAC;;AAE3B,QAAA,KAAK,CAAC;AACJ,YAAA,GAAG,MAAM;AACT,YAAA,YAAY,EAAE,KAAK;AACpB,SAAA,CAAC;AACF,QAAA,IAAI,CAAC,qBAAqB,GAAG,qBAAqB;;AAEpD,IAAA,gBAAgB,CACd,OAA+C,EAAA;QAE/C,MAAM,MAAM,GAAG,KAAK,CAAC,gBAAgB,CAAC,OAAO,CAAC;AAC9C,QAAA,IAAI,IAAI,CAAC,qBAAqB,EAAE;AAC9B,YAAA,MAAM,CAAC,kBAAkB,GAAG,EAAE;;AAEhC,QAAA,OAAO,MAAM;;IAGf,eAAe,CACb,MAA6B,EAC7B,MAA8B,EAAA;QAE9B,IAAI,CAAC,UAAU,GAAG,IAAI,oBAAoB,CACxC,EAAE,GAAG,MAAM,EAAE,GAAG,IAAI,EAAE,EACtB,IAAI,CAAC,MAAM,EACX,MAAM,EACN,KAAK,CACN;QAED,IAAI,CAAC,kBAAkB,GAAG,IAAI,oBAAoB,CAChD,EAAE,GAAG,MAAM,EAAE,GAAG,IAAI,EAAE,EACtB,IAAI,CAAC,MAAM,EACX,MAAM,EACN,IAAI,CACL;;AAEJ;;;;"}
@@ -1,12 +1,12 @@
1
1
  import { ChatOllama } from '@langchain/ollama';
2
2
  import { ChatMistralAI } from '@langchain/mistralai';
3
3
  import { ChatBedrockConverse } from '@langchain/aws';
4
- import { ChatVertexAI } from '@langchain/google-vertexai';
5
4
  import { BedrockChat } from '@langchain/community/chat_models/bedrock/web';
5
+ import { ChatDeepSeek, AzureChatOpenAI, ChatOpenAI, ChatXAI } from './openai/index.mjs';
6
6
  import { CustomChatGoogleGenerativeAI } from './google/index.mjs';
7
7
  import { CustomAnthropic } from './anthropic/index.mjs';
8
8
  import { ChatOpenRouter } from './openrouter/index.mjs';
9
- import { ChatDeepSeek, AzureChatOpenAI, ChatOpenAI, ChatXAI } from './openai/index.mjs';
9
+ import { ChatVertexAI } from './vertexai/index.mjs';
10
10
  import { Providers } from '../common/enum.mjs';
11
11
 
12
12
  // src/llm/providers.ts
@@ -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 { 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
+ {"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';\n// import { 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 {\n AzureChatOpenAI,\n ChatDeepSeek,\n ChatOpenAI,\n ChatXAI,\n} from '@/llm/openai';\nimport { CustomChatGoogleGenerativeAI } from '@/llm/google';\nimport { CustomAnthropic } from '@/llm/anthropic';\nimport { ChatOpenRouter } from '@/llm/openrouter';\nimport { ChatVertexAI } from '@/llm/vertexai';\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;AAwBa,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;;;;"}