@blaxel/langgraph 0.2.50-dev.215 → 0.2.50
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/README.md +1 -1
- package/dist/cjs/.tsbuildinfo +1 -1
- package/dist/cjs/model/cohere.js +74 -0
- package/dist/cjs/model/google-genai.js +75 -12
- package/dist/cjs/model.js +1 -1
- package/dist/cjs/types/model/google-genai.d.ts +20 -3
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/model/cohere.js +74 -0
- package/dist/esm/model/google-genai.js +74 -11
- package/dist/esm/model.js +1 -1
- package/package.json +3 -2
- package/dist/cjs/model/google-genai/chat_models.js +0 -766
- package/dist/cjs/model/google-genai/embeddings.js +0 -111
- package/dist/cjs/model/google-genai/index.js +0 -18
- package/dist/cjs/model/google-genai/output_parsers.js +0 -51
- package/dist/cjs/model/google-genai/types.js +0 -2
- package/dist/cjs/model/google-genai/utils/common.js +0 -390
- package/dist/cjs/model/google-genai/utils/tools.js +0 -110
- package/dist/cjs/model/google-genai/utils/zod_to_genai_parameters.js +0 -46
- package/dist/cjs/types/model/google-genai/chat_models.d.ts +0 -557
- package/dist/cjs/types/model/google-genai/embeddings.d.ts +0 -94
- package/dist/cjs/types/model/google-genai/index.d.ts +0 -2
- package/dist/cjs/types/model/google-genai/output_parsers.d.ts +0 -20
- package/dist/cjs/types/model/google-genai/types.d.ts +0 -3
- package/dist/cjs/types/model/google-genai/utils/common.d.ts +0 -22
- package/dist/cjs/types/model/google-genai/utils/tools.d.ts +0 -10
- package/dist/cjs/types/model/google-genai/utils/zod_to_genai_parameters.d.ts +0 -13
- package/dist/esm/model/google-genai/chat_models.js +0 -762
- package/dist/esm/model/google-genai/embeddings.js +0 -107
- package/dist/esm/model/google-genai/index.js +0 -2
- package/dist/esm/model/google-genai/output_parsers.js +0 -47
- package/dist/esm/model/google-genai/types.js +0 -1
- package/dist/esm/model/google-genai/utils/common.js +0 -381
- package/dist/esm/model/google-genai/utils/tools.js +0 -107
- package/dist/esm/model/google-genai/utils/zod_to_genai_parameters.js +0 -41
package/dist/esm/model/cohere.js
CHANGED
|
@@ -91,6 +91,43 @@ export const createCohereFetcher = () => {
|
|
|
91
91
|
if ('tool_results' in transformedObj) {
|
|
92
92
|
delete transformedObj.tool_results;
|
|
93
93
|
}
|
|
94
|
+
// Transform tools array to ensure each tool has a 'type' field (required by Cohere v2)
|
|
95
|
+
if ('tools' in transformedObj && Array.isArray(transformedObj.tools)) {
|
|
96
|
+
const tools = transformedObj.tools;
|
|
97
|
+
transformedObj.tools = tools.map((tool) => {
|
|
98
|
+
if (typeof tool === 'object' && tool !== null) {
|
|
99
|
+
const toolObj = tool;
|
|
100
|
+
// If tool already has 'type' field, keep it
|
|
101
|
+
if ('type' in toolObj) {
|
|
102
|
+
return toolObj;
|
|
103
|
+
}
|
|
104
|
+
// If tool has 'function' field (OpenAI format), wrap it with type
|
|
105
|
+
if ('function' in toolObj) {
|
|
106
|
+
return {
|
|
107
|
+
type: 'function',
|
|
108
|
+
function: toolObj.function,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
// If tool has name/description/parameters (direct format), wrap it
|
|
112
|
+
if ('name' in toolObj && ('description' in toolObj || 'parameters' in toolObj)) {
|
|
113
|
+
return {
|
|
114
|
+
type: 'function',
|
|
115
|
+
function: {
|
|
116
|
+
name: toolObj.name,
|
|
117
|
+
description: toolObj.description || '',
|
|
118
|
+
parameters: toolObj.parameters || toolObj.inputSchema || {},
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
// Default: add type field
|
|
123
|
+
return {
|
|
124
|
+
type: 'function',
|
|
125
|
+
...toolObj,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
return tool;
|
|
129
|
+
});
|
|
130
|
+
}
|
|
94
131
|
}
|
|
95
132
|
requestBody = JSON.stringify(transformedBody);
|
|
96
133
|
}
|
|
@@ -131,6 +168,43 @@ export const createCohereFetcher = () => {
|
|
|
131
168
|
}
|
|
132
169
|
delete transformed.message;
|
|
133
170
|
}
|
|
171
|
+
// Transform tools array to ensure each tool has a 'type' field (required by Cohere v2)
|
|
172
|
+
if ('tools' in transformed && Array.isArray(transformed.tools)) {
|
|
173
|
+
const tools = transformed.tools;
|
|
174
|
+
transformed.tools = tools.map((tool) => {
|
|
175
|
+
if (typeof tool === 'object' && tool !== null) {
|
|
176
|
+
const toolObj = tool;
|
|
177
|
+
// If tool already has 'type' field, keep it
|
|
178
|
+
if ('type' in toolObj) {
|
|
179
|
+
return toolObj;
|
|
180
|
+
}
|
|
181
|
+
// If tool has 'function' field (OpenAI format), wrap it with type
|
|
182
|
+
if ('function' in toolObj) {
|
|
183
|
+
return {
|
|
184
|
+
type: 'function',
|
|
185
|
+
function: toolObj.function,
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
// If tool has name/description/parameters (direct format), wrap it
|
|
189
|
+
if ('name' in toolObj && ('description' in toolObj || 'parameters' in toolObj)) {
|
|
190
|
+
return {
|
|
191
|
+
type: 'function',
|
|
192
|
+
function: {
|
|
193
|
+
name: toolObj.name,
|
|
194
|
+
description: toolObj.description || '',
|
|
195
|
+
parameters: toolObj.parameters || toolObj.inputSchema || {},
|
|
196
|
+
},
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
// Default: add type field
|
|
200
|
+
return {
|
|
201
|
+
type: 'function',
|
|
202
|
+
...toolObj,
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
return tool;
|
|
206
|
+
});
|
|
207
|
+
}
|
|
134
208
|
requestBody = JSON.stringify(transformed);
|
|
135
209
|
}
|
|
136
210
|
else {
|
|
@@ -1,26 +1,89 @@
|
|
|
1
1
|
import { authenticate, settings } from "@blaxel/core";
|
|
2
|
-
import { ChatGoogleGenerativeAI } from "
|
|
2
|
+
import { ChatGoogleGenerativeAI } from "@langchain/google-genai";
|
|
3
|
+
import { GoogleGenerativeAI as GenerativeAI } from "@google/generative-ai";
|
|
3
4
|
/**
|
|
4
5
|
* Custom ChatGoogleGenerativeAI that ensures authentication before each request
|
|
6
|
+
* and supports custom headers without modifying the library code
|
|
5
7
|
*/
|
|
6
8
|
export class AuthenticatedChatGoogleGenerativeAI extends ChatGoogleGenerativeAI {
|
|
9
|
+
customHeaders;
|
|
10
|
+
constructorParams;
|
|
11
|
+
constructor(fields) {
|
|
12
|
+
super(fields);
|
|
13
|
+
// Store constructor parameters for recreating the client
|
|
14
|
+
this.constructorParams = {
|
|
15
|
+
apiKey: fields.apiKey,
|
|
16
|
+
apiVersion: fields.apiVersion,
|
|
17
|
+
baseUrl: fields.baseUrl,
|
|
18
|
+
model: fields.model,
|
|
19
|
+
safetySettings: fields.safetySettings,
|
|
20
|
+
stopSequences: fields.stopSequences,
|
|
21
|
+
maxOutputTokens: fields.maxOutputTokens,
|
|
22
|
+
temperature: fields.temperature,
|
|
23
|
+
topP: fields.topP,
|
|
24
|
+
topK: fields.topK,
|
|
25
|
+
json: fields.json,
|
|
26
|
+
thinkingConfig: fields.thinkingConfig,
|
|
27
|
+
};
|
|
28
|
+
this.customHeaders = fields.customHeaders;
|
|
29
|
+
// Initialize client with custom headers if provided
|
|
30
|
+
if (this.customHeaders) {
|
|
31
|
+
this.recreateClient();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Recreates the client with updated custom headers
|
|
36
|
+
* Uses type assertion to access the private client property
|
|
37
|
+
*/
|
|
38
|
+
recreateClient() {
|
|
39
|
+
const apiKey = this.constructorParams.apiKey || this.apiKey;
|
|
40
|
+
if (!apiKey)
|
|
41
|
+
return;
|
|
42
|
+
// Get the processed model name from the base class (it removes "models/" prefix)
|
|
43
|
+
const model = this.model || this.constructorParams.model.replace(/^models\//, "");
|
|
44
|
+
const modelParams = {
|
|
45
|
+
model,
|
|
46
|
+
safetySettings: this.constructorParams.safetySettings,
|
|
47
|
+
generationConfig: {
|
|
48
|
+
candidateCount: 1,
|
|
49
|
+
stopSequences: this.constructorParams.stopSequences,
|
|
50
|
+
maxOutputTokens: this.constructorParams.maxOutputTokens,
|
|
51
|
+
temperature: this.constructorParams.temperature,
|
|
52
|
+
topP: this.constructorParams.topP,
|
|
53
|
+
topK: this.constructorParams.topK,
|
|
54
|
+
...(this.constructorParams.json ? { responseMimeType: "application/json" } : {}),
|
|
55
|
+
...(this.constructorParams.thinkingConfig
|
|
56
|
+
? { thinkingConfig: this.constructorParams.thinkingConfig }
|
|
57
|
+
: {}),
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
const requestOptions = {
|
|
61
|
+
apiVersion: this.constructorParams.apiVersion,
|
|
62
|
+
baseUrl: this.constructorParams.baseUrl,
|
|
63
|
+
customHeaders: this.customHeaders,
|
|
64
|
+
};
|
|
65
|
+
// Use type assertion to access private client property
|
|
66
|
+
this.client = new GenerativeAI(apiKey).getGenerativeModel(modelParams, requestOptions);
|
|
67
|
+
}
|
|
7
68
|
async _generate(messages, options, runManager) {
|
|
8
69
|
// Authenticate before making the request
|
|
9
70
|
await authenticate();
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
this.client = this.initClient();
|
|
71
|
+
// Update custom headers from settings
|
|
72
|
+
this.customHeaders = { ...settings.headers };
|
|
73
|
+
// Recreate client with updated headers
|
|
74
|
+
this.recreateClient();
|
|
15
75
|
return await super._generate(messages, options || {}, runManager);
|
|
16
76
|
}
|
|
17
77
|
async *_streamResponseChunks(messages, options, runManager) {
|
|
18
78
|
// Authenticate before making the request
|
|
19
79
|
await authenticate();
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
yield* super._streamResponseChunks(messages, options
|
|
80
|
+
// Update custom headers from settings
|
|
81
|
+
this.customHeaders = { ...settings.headers };
|
|
82
|
+
// Recreate client with updated headers
|
|
83
|
+
this.recreateClient();
|
|
84
|
+
yield* super._streamResponseChunks(messages, options, runManager);
|
|
85
|
+
}
|
|
86
|
+
bindTools(tools, kwargs) {
|
|
87
|
+
return super.bindTools(tools, kwargs);
|
|
25
88
|
}
|
|
26
89
|
}
|
package/dist/esm/model.js
CHANGED
|
@@ -3,9 +3,9 @@ import { ChatAnthropic } from "@langchain/anthropic";
|
|
|
3
3
|
import { ChatCohere } from "@langchain/cohere";
|
|
4
4
|
import { ChatDeepSeek } from "@langchain/deepseek";
|
|
5
5
|
import { ChatOpenAI } from "@langchain/openai";
|
|
6
|
+
import { AuthenticatedChatGoogleGenerativeAI } from "./model/google-genai.js";
|
|
6
7
|
import { CohereClient } from "cohere-ai";
|
|
7
8
|
import { createCohereFetcher } from "./model/cohere.js";
|
|
8
|
-
import { AuthenticatedChatGoogleGenerativeAI } from "./model/google-genai.js";
|
|
9
9
|
import { ChatXAI } from "./model/xai.js";
|
|
10
10
|
/**
|
|
11
11
|
* Creates a custom fetch function that adds dynamic headers to each request
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blaxel/langgraph",
|
|
3
|
-
"version": "0.2.50
|
|
3
|
+
"version": "0.2.50",
|
|
4
4
|
"description": "Blaxel SDK for TypeScript",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Blaxel, INC (https://blaxel.ai)",
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"@langchain/cohere": "^1.0.0",
|
|
46
46
|
"@langchain/core": "^1.0.6",
|
|
47
47
|
"@langchain/deepseek": "^1.0.1",
|
|
48
|
+
"@langchain/google-genai": "^1.0.3",
|
|
48
49
|
"@langchain/openai": "^1.1.2",
|
|
49
50
|
"@opentelemetry/instrumentation": "^0.200.0",
|
|
50
51
|
"@traceloop/instrumentation-langchain": "^0.20.0",
|
|
@@ -52,7 +53,7 @@
|
|
|
52
53
|
"langchain": "^1.0.6",
|
|
53
54
|
"zod": "^3.24.3",
|
|
54
55
|
"zod-to-json-schema": "^3.24.5",
|
|
55
|
-
"@blaxel/core": "0.2.50
|
|
56
|
+
"@blaxel/core": "0.2.50"
|
|
56
57
|
},
|
|
57
58
|
"devDependencies": {
|
|
58
59
|
"@eslint/js": "^9.26.0",
|