@blaxel/langgraph 0.2.50-dev.215 → 0.2.50-preview.115

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.
Files changed (35) hide show
  1. package/README.md +1 -1
  2. package/dist/cjs/.tsbuildinfo +1 -1
  3. package/dist/cjs/model/cohere.js +74 -0
  4. package/dist/cjs/model/google-genai.js +75 -12
  5. package/dist/cjs/model.js +1 -1
  6. package/dist/cjs/types/model/google-genai.d.ts +20 -3
  7. package/dist/esm/.tsbuildinfo +1 -1
  8. package/dist/esm/model/cohere.js +74 -0
  9. package/dist/esm/model/google-genai.js +74 -11
  10. package/dist/esm/model.js +1 -1
  11. package/package.json +3 -2
  12. package/dist/cjs/model/google-genai/chat_models.js +0 -766
  13. package/dist/cjs/model/google-genai/embeddings.js +0 -111
  14. package/dist/cjs/model/google-genai/index.js +0 -18
  15. package/dist/cjs/model/google-genai/output_parsers.js +0 -51
  16. package/dist/cjs/model/google-genai/types.js +0 -2
  17. package/dist/cjs/model/google-genai/utils/common.js +0 -390
  18. package/dist/cjs/model/google-genai/utils/tools.js +0 -110
  19. package/dist/cjs/model/google-genai/utils/zod_to_genai_parameters.js +0 -46
  20. package/dist/cjs/types/model/google-genai/chat_models.d.ts +0 -557
  21. package/dist/cjs/types/model/google-genai/embeddings.d.ts +0 -94
  22. package/dist/cjs/types/model/google-genai/index.d.ts +0 -2
  23. package/dist/cjs/types/model/google-genai/output_parsers.d.ts +0 -20
  24. package/dist/cjs/types/model/google-genai/types.d.ts +0 -3
  25. package/dist/cjs/types/model/google-genai/utils/common.d.ts +0 -22
  26. package/dist/cjs/types/model/google-genai/utils/tools.d.ts +0 -10
  27. package/dist/cjs/types/model/google-genai/utils/zod_to_genai_parameters.d.ts +0 -13
  28. package/dist/esm/model/google-genai/chat_models.js +0 -762
  29. package/dist/esm/model/google-genai/embeddings.js +0 -107
  30. package/dist/esm/model/google-genai/index.js +0 -2
  31. package/dist/esm/model/google-genai/output_parsers.js +0 -47
  32. package/dist/esm/model/google-genai/types.js +0 -1
  33. package/dist/esm/model/google-genai/utils/common.js +0 -381
  34. package/dist/esm/model/google-genai/utils/tools.js +0 -107
  35. package/dist/esm/model/google-genai/utils/zod_to_genai_parameters.js +0 -41
@@ -94,6 +94,43 @@ const createCohereFetcher = () => {
94
94
  if ('tool_results' in transformedObj) {
95
95
  delete transformedObj.tool_results;
96
96
  }
97
+ // Transform tools array to ensure each tool has a 'type' field (required by Cohere v2)
98
+ if ('tools' in transformedObj && Array.isArray(transformedObj.tools)) {
99
+ const tools = transformedObj.tools;
100
+ transformedObj.tools = tools.map((tool) => {
101
+ if (typeof tool === 'object' && tool !== null) {
102
+ const toolObj = tool;
103
+ // If tool already has 'type' field, keep it
104
+ if ('type' in toolObj) {
105
+ return toolObj;
106
+ }
107
+ // If tool has 'function' field (OpenAI format), wrap it with type
108
+ if ('function' in toolObj) {
109
+ return {
110
+ type: 'function',
111
+ function: toolObj.function,
112
+ };
113
+ }
114
+ // If tool has name/description/parameters (direct format), wrap it
115
+ if ('name' in toolObj && ('description' in toolObj || 'parameters' in toolObj)) {
116
+ return {
117
+ type: 'function',
118
+ function: {
119
+ name: toolObj.name,
120
+ description: toolObj.description || '',
121
+ parameters: toolObj.parameters || toolObj.inputSchema || {},
122
+ },
123
+ };
124
+ }
125
+ // Default: add type field
126
+ return {
127
+ type: 'function',
128
+ ...toolObj,
129
+ };
130
+ }
131
+ return tool;
132
+ });
133
+ }
97
134
  }
98
135
  requestBody = JSON.stringify(transformedBody);
99
136
  }
@@ -134,6 +171,43 @@ const createCohereFetcher = () => {
134
171
  }
135
172
  delete transformed.message;
136
173
  }
174
+ // Transform tools array to ensure each tool has a 'type' field (required by Cohere v2)
175
+ if ('tools' in transformed && Array.isArray(transformed.tools)) {
176
+ const tools = transformed.tools;
177
+ transformed.tools = tools.map((tool) => {
178
+ if (typeof tool === 'object' && tool !== null) {
179
+ const toolObj = tool;
180
+ // If tool already has 'type' field, keep it
181
+ if ('type' in toolObj) {
182
+ return toolObj;
183
+ }
184
+ // If tool has 'function' field (OpenAI format), wrap it with type
185
+ if ('function' in toolObj) {
186
+ return {
187
+ type: 'function',
188
+ function: toolObj.function,
189
+ };
190
+ }
191
+ // If tool has name/description/parameters (direct format), wrap it
192
+ if ('name' in toolObj && ('description' in toolObj || 'parameters' in toolObj)) {
193
+ return {
194
+ type: 'function',
195
+ function: {
196
+ name: toolObj.name,
197
+ description: toolObj.description || '',
198
+ parameters: toolObj.parameters || toolObj.inputSchema || {},
199
+ },
200
+ };
201
+ }
202
+ // Default: add type field
203
+ return {
204
+ type: 'function',
205
+ ...toolObj,
206
+ };
207
+ }
208
+ return tool;
209
+ });
210
+ }
137
211
  requestBody = JSON.stringify(transformed);
138
212
  }
139
213
  else {
@@ -2,29 +2,92 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AuthenticatedChatGoogleGenerativeAI = void 0;
4
4
  const core_1 = require("@blaxel/core");
5
- const index_js_1 = require("./google-genai/index.js");
5
+ const google_genai_1 = require("@langchain/google-genai");
6
+ const generative_ai_1 = require("@google/generative-ai");
6
7
  /**
7
8
  * Custom ChatGoogleGenerativeAI that ensures authentication before each request
9
+ * and supports custom headers without modifying the library code
8
10
  */
9
- class AuthenticatedChatGoogleGenerativeAI extends index_js_1.ChatGoogleGenerativeAI {
11
+ class AuthenticatedChatGoogleGenerativeAI extends google_genai_1.ChatGoogleGenerativeAI {
12
+ customHeaders;
13
+ constructorParams;
14
+ constructor(fields) {
15
+ super(fields);
16
+ // Store constructor parameters for recreating the client
17
+ this.constructorParams = {
18
+ apiKey: fields.apiKey,
19
+ apiVersion: fields.apiVersion,
20
+ baseUrl: fields.baseUrl,
21
+ model: fields.model,
22
+ safetySettings: fields.safetySettings,
23
+ stopSequences: fields.stopSequences,
24
+ maxOutputTokens: fields.maxOutputTokens,
25
+ temperature: fields.temperature,
26
+ topP: fields.topP,
27
+ topK: fields.topK,
28
+ json: fields.json,
29
+ thinkingConfig: fields.thinkingConfig,
30
+ };
31
+ this.customHeaders = fields.customHeaders;
32
+ // Initialize client with custom headers if provided
33
+ if (this.customHeaders) {
34
+ this.recreateClient();
35
+ }
36
+ }
37
+ /**
38
+ * Recreates the client with updated custom headers
39
+ * Uses type assertion to access the private client property
40
+ */
41
+ recreateClient() {
42
+ const apiKey = this.constructorParams.apiKey || this.apiKey;
43
+ if (!apiKey)
44
+ return;
45
+ // Get the processed model name from the base class (it removes "models/" prefix)
46
+ const model = this.model || this.constructorParams.model.replace(/^models\//, "");
47
+ const modelParams = {
48
+ model,
49
+ safetySettings: this.constructorParams.safetySettings,
50
+ generationConfig: {
51
+ candidateCount: 1,
52
+ stopSequences: this.constructorParams.stopSequences,
53
+ maxOutputTokens: this.constructorParams.maxOutputTokens,
54
+ temperature: this.constructorParams.temperature,
55
+ topP: this.constructorParams.topP,
56
+ topK: this.constructorParams.topK,
57
+ ...(this.constructorParams.json ? { responseMimeType: "application/json" } : {}),
58
+ ...(this.constructorParams.thinkingConfig
59
+ ? { thinkingConfig: this.constructorParams.thinkingConfig }
60
+ : {}),
61
+ },
62
+ };
63
+ const requestOptions = {
64
+ apiVersion: this.constructorParams.apiVersion,
65
+ baseUrl: this.constructorParams.baseUrl,
66
+ customHeaders: this.customHeaders,
67
+ };
68
+ // Use type assertion to access private client property
69
+ this.client = new generative_ai_1.GoogleGenerativeAI(apiKey).getGenerativeModel(modelParams, requestOptions);
70
+ }
10
71
  async _generate(messages, options, runManager) {
11
72
  // Authenticate before making the request
12
73
  await (0, core_1.authenticate)();
13
- this.customHeaders = {};
14
- for (const header in core_1.settings.headers) {
15
- this.customHeaders[header] = core_1.settings.headers[header];
16
- }
17
- this.client = this.initClient();
74
+ // Update custom headers from settings
75
+ this.customHeaders = { ...core_1.settings.headers };
76
+ // Recreate client with updated headers
77
+ this.recreateClient();
18
78
  return await super._generate(messages, options || {}, runManager);
19
79
  }
20
80
  async *_streamResponseChunks(messages, options, runManager) {
21
81
  // Authenticate before making the request
22
82
  await (0, core_1.authenticate)();
23
- this.customHeaders = {};
24
- for (const header in core_1.settings.headers) {
25
- this.customHeaders[header] = core_1.settings.headers[header];
26
- }
27
- yield* super._streamResponseChunks(messages, options || {}, runManager);
83
+ // Update custom headers from settings
84
+ this.customHeaders = { ...core_1.settings.headers };
85
+ // Recreate client with updated headers
86
+ this.recreateClient();
87
+ yield* super._streamResponseChunks(messages, options, runManager);
88
+ }
89
+ bindTools(tools, kwargs) {
90
+ return super.bindTools(tools, kwargs);
28
91
  }
29
92
  }
30
93
  exports.AuthenticatedChatGoogleGenerativeAI = AuthenticatedChatGoogleGenerativeAI;
package/dist/cjs/model.js CHANGED
@@ -6,9 +6,9 @@ const anthropic_1 = require("@langchain/anthropic");
6
6
  const cohere_1 = require("@langchain/cohere");
7
7
  const deepseek_1 = require("@langchain/deepseek");
8
8
  const openai_1 = require("@langchain/openai");
9
+ const google_genai_js_1 = require("./model/google-genai.js");
9
10
  const cohere_ai_1 = require("cohere-ai");
10
11
  const cohere_js_1 = require("./model/cohere.js");
11
- const google_genai_js_1 = require("./model/google-genai.js");
12
12
  const xai_js_1 = require("./model/xai.js");
13
13
  /**
14
14
  * Creates a custom fetch function that adds dynamic headers to each request
@@ -1,11 +1,28 @@
1
1
  import { CallbackManagerForLLMRun } from "@langchain/core/callbacks/manager";
2
+ import { BaseLanguageModelInput } from "@langchain/core/language_models/base";
2
3
  import { BaseMessage } from "@langchain/core/messages";
3
- import { ChatResult } from "@langchain/core/outputs";
4
- import { ChatGoogleGenerativeAI } from "./google-genai/index.js";
4
+ import { AIMessageChunk } from "@langchain/core/messages";
5
+ import { ChatResult, ChatGenerationChunk } from "@langchain/core/outputs";
6
+ import { Runnable } from "@langchain/core/runnables";
7
+ import { ChatGoogleGenerativeAI, GoogleGenerativeAIChatCallOptions, GoogleGenerativeAIChatInput } from "@langchain/google-genai";
8
+ type GoogleGenerativeAIToolType = NonNullable<GoogleGenerativeAIChatCallOptions["tools"]>[number];
5
9
  /**
6
10
  * Custom ChatGoogleGenerativeAI that ensures authentication before each request
11
+ * and supports custom headers without modifying the library code
7
12
  */
8
13
  export declare class AuthenticatedChatGoogleGenerativeAI extends ChatGoogleGenerativeAI {
14
+ private customHeaders?;
15
+ private constructorParams;
16
+ constructor(fields: GoogleGenerativeAIChatInput & {
17
+ customHeaders?: Record<string, string>;
18
+ });
19
+ /**
20
+ * Recreates the client with updated custom headers
21
+ * Uses type assertion to access the private client property
22
+ */
23
+ private recreateClient;
9
24
  _generate(messages: BaseMessage[], options?: this["ParsedCallOptions"], runManager?: CallbackManagerForLLMRun): Promise<ChatResult>;
10
- _streamResponseChunks(messages: BaseMessage[], options?: this["ParsedCallOptions"], runManager?: CallbackManagerForLLMRun): AsyncGenerator<any>;
25
+ _streamResponseChunks(messages: BaseMessage[], options: this["ParsedCallOptions"], runManager?: CallbackManagerForLLMRun): AsyncGenerator<ChatGenerationChunk>;
26
+ bindTools(tools: GoogleGenerativeAIToolType[], kwargs?: Partial<GoogleGenerativeAIChatCallOptions>): Runnable<BaseLanguageModelInput, AIMessageChunk, GoogleGenerativeAIChatCallOptions>;
11
27
  }
28
+ export {};