@blaxel/langgraph 0.2.36-dev.185 → 0.2.36-dev.190

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 (50) hide show
  1. package/dist/cjs/.tsbuildinfo +1 -0
  2. package/dist/{model → cjs/model}/google-genai/chat_models.js +13 -8
  3. package/dist/{model → cjs/model}/google-genai/output_parsers.js +1 -0
  4. package/dist/{model → cjs/model}/google-genai/utils/common.js +1 -0
  5. package/dist/cjs/telemetry.js +54 -0
  6. package/dist/{tools.js → cjs/tools.js} +3 -1
  7. package/dist/{model → cjs/types/model}/xai.d.ts +1 -1
  8. package/dist/{tools.d.ts → cjs/types/tools.d.ts} +3 -7
  9. package/dist/esm/.tsbuildinfo +1 -0
  10. package/dist/esm/index.js +3 -0
  11. package/dist/esm/model/cohere.js +168 -0
  12. package/dist/esm/model/google-genai/chat_models.js +756 -0
  13. package/dist/esm/model/google-genai/embeddings.js +107 -0
  14. package/dist/esm/model/google-genai/index.js +2 -0
  15. package/dist/esm/model/google-genai/output_parsers.js +47 -0
  16. package/dist/esm/model/google-genai/types.js +1 -0
  17. package/dist/esm/model/google-genai/utils/common.js +378 -0
  18. package/dist/esm/model/google-genai/utils/tools.js +107 -0
  19. package/dist/esm/model/google-genai/utils/zod_to_genai_parameters.js +41 -0
  20. package/dist/esm/model/google-genai.js +26 -0
  21. package/dist/esm/model/xai.js +78 -0
  22. package/dist/esm/model.js +137 -0
  23. package/dist/esm/package.json +1 -0
  24. package/dist/esm/telemetry.js +19 -0
  25. package/dist/esm/tools.js +22 -0
  26. package/package.json +16 -28
  27. package/dist/telemetry.js +0 -24
  28. /package/dist/{index.js → cjs/index.js} +0 -0
  29. /package/dist/{model → cjs/model}/cohere.js +0 -0
  30. /package/dist/{model → cjs/model}/google-genai/embeddings.js +0 -0
  31. /package/dist/{model → cjs/model}/google-genai/index.js +0 -0
  32. /package/dist/{model → cjs/model}/google-genai/types.js +0 -0
  33. /package/dist/{model → cjs/model}/google-genai/utils/tools.js +0 -0
  34. /package/dist/{model → cjs/model}/google-genai/utils/zod_to_genai_parameters.js +0 -0
  35. /package/dist/{model → cjs/model}/google-genai.js +0 -0
  36. /package/dist/{model → cjs/model}/xai.js +0 -0
  37. /package/dist/{model.js → cjs/model.js} +0 -0
  38. /package/dist/{index.d.ts → cjs/types/index.d.ts} +0 -0
  39. /package/dist/{model → cjs/types/model}/cohere.d.ts +0 -0
  40. /package/dist/{model → cjs/types/model}/google-genai/chat_models.d.ts +0 -0
  41. /package/dist/{model → cjs/types/model}/google-genai/embeddings.d.ts +0 -0
  42. /package/dist/{model → cjs/types/model}/google-genai/index.d.ts +0 -0
  43. /package/dist/{model → cjs/types/model}/google-genai/output_parsers.d.ts +0 -0
  44. /package/dist/{model → cjs/types/model}/google-genai/types.d.ts +0 -0
  45. /package/dist/{model → cjs/types/model}/google-genai/utils/common.d.ts +0 -0
  46. /package/dist/{model → cjs/types/model}/google-genai/utils/tools.d.ts +0 -0
  47. /package/dist/{model → cjs/types/model}/google-genai/utils/zod_to_genai_parameters.d.ts +0 -0
  48. /package/dist/{model → cjs/types/model}/google-genai.d.ts +0 -0
  49. /package/dist/{model.d.ts → cjs/types/model.d.ts} +0 -0
  50. /package/dist/{telemetry.d.ts → cjs/types/telemetry.d.ts} +0 -0
@@ -0,0 +1,26 @@
1
+ import { authenticate, settings } from "@blaxel/core";
2
+ import { ChatGoogleGenerativeAI } from "./google-genai/index.js";
3
+ /**
4
+ * Custom ChatGoogleGenerativeAI that ensures authentication before each request
5
+ */
6
+ export class AuthenticatedChatGoogleGenerativeAI extends ChatGoogleGenerativeAI {
7
+ async _generate(messages, options, runManager) {
8
+ // Authenticate before making the request
9
+ await authenticate();
10
+ this.customHeaders = {};
11
+ for (const header in settings.headers) {
12
+ this.customHeaders[header] = settings.headers[header];
13
+ }
14
+ this.client = this.initClient();
15
+ return await super._generate(messages, options || {}, runManager);
16
+ }
17
+ async *_streamResponseChunks(messages, options, runManager) {
18
+ // Authenticate before making the request
19
+ await authenticate();
20
+ this.customHeaders = {};
21
+ for (const header in settings.headers) {
22
+ this.customHeaders[header] = settings.headers[header];
23
+ }
24
+ yield* super._streamResponseChunks(messages, options || {}, runManager);
25
+ }
26
+ }
@@ -0,0 +1,78 @@
1
+ import { getEnvironmentVariable } from "@langchain/core/utils/env";
2
+ import { ChatOpenAI } from "@langchain/openai";
3
+ /**
4
+ * Extends the ChatOpenAI class to create a ChatXAI agent with additional configurations.
5
+ */
6
+ export class ChatXAI extends ChatOpenAI {
7
+ /**
8
+ * Returns the name of the class for LangChain serialization.
9
+ * @returns The class name as a string.
10
+ */
11
+ static lc_name() {
12
+ return "ChatXAI";
13
+ }
14
+ /**
15
+ * Specifies the type of the language model.
16
+ * @returns The type of the LLM as a string.
17
+ */
18
+ _llmType() {
19
+ return "xAI";
20
+ }
21
+ /**
22
+ * Specifies the secrets required for serialization.
23
+ * @returns An object mapping secret names to their keys.
24
+ */
25
+ get lc_secrets() {
26
+ return {
27
+ apiKey: "XAI_API_KEY",
28
+ };
29
+ }
30
+ /**
31
+ * Constructs a new ChatXAI instance.
32
+ * @param fields - Configuration fields, including the API key.
33
+ * @throws If the API key is not provided.
34
+ */
35
+ constructor(fields) {
36
+ const apiKey = fields?.apiKey || getEnvironmentVariable("XAI_API_KEY");
37
+ if (!apiKey) {
38
+ throw new Error(`xAI API key not found. Please set the XAI_API_KEY environment variable or provide the key into "apiKey" field.`);
39
+ }
40
+ super(fields);
41
+ Object.defineProperty(this, "lc_serializable", {
42
+ enumerable: true,
43
+ configurable: true,
44
+ writable: true,
45
+ value: true,
46
+ });
47
+ Object.defineProperty(this, "lc_namespace", {
48
+ enumerable: true,
49
+ configurable: true,
50
+ writable: true,
51
+ value: ["langchain", "chat_models", "xai"],
52
+ });
53
+ }
54
+ /**
55
+ * Serializes the instance to JSON, removing sensitive information.
56
+ * @returns The serialized JSON object.
57
+ */
58
+ toJSON() {
59
+ const result = super.toJSON();
60
+ if ("kwargs" in result &&
61
+ typeof result.kwargs === "object" &&
62
+ result.kwargs != null) {
63
+ delete result.kwargs.openai_api_key;
64
+ delete result.kwargs.configuration;
65
+ }
66
+ return result;
67
+ }
68
+ /**
69
+ * Retrieves parameters for LangChain based on provided options.
70
+ * @param options - Additional options for parameter retrieval.
71
+ * @returns An object containing LangChain parameters.
72
+ */
73
+ getLsParams(options) {
74
+ const params = super.getLsParams(options);
75
+ params.ls_provider = "xai";
76
+ return params;
77
+ }
78
+ }
@@ -0,0 +1,137 @@
1
+ import { authenticate, getModelMetadata, handleDynamicImportError, settings } from "@blaxel/core";
2
+ import { ChatAnthropic } from "@langchain/anthropic";
3
+ import { ChatCohere } from "@langchain/cohere";
4
+ import { ChatDeepSeek } from "@langchain/deepseek";
5
+ import { ChatOpenAI } from "@langchain/openai";
6
+ import { CohereClient } from "cohere-ai";
7
+ import { createCohereFetcher } from "./model/cohere.js";
8
+ import { AuthenticatedChatGoogleGenerativeAI } from "./model/google-genai.js";
9
+ import { ChatXAI } from "./model/xai.js";
10
+ /**
11
+ * Creates a custom fetch function that adds dynamic headers to each request
12
+ * Returns a function compatible with OpenAI SDK's fetch option
13
+ */
14
+ const authenticatedFetch = () => {
15
+ const customFetch = async (input, init) => {
16
+ await authenticate();
17
+ const dynamicHeaders = settings.headers;
18
+ // Merge headers: init headers take precedence over dynamic headers
19
+ const headers = {
20
+ ...dynamicHeaders,
21
+ ...(init?.headers || {}),
22
+ };
23
+ // Make the request with merged headers
24
+ return await fetch(input, {
25
+ ...init,
26
+ headers,
27
+ });
28
+ };
29
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
30
+ return customFetch;
31
+ };
32
+ export const blModel = async (model, options) => {
33
+ const url = `${settings.runUrl}/${settings.workspace}/models/${model}`;
34
+ const modelData = await getModelMetadata(model);
35
+ if (!modelData) {
36
+ throw new Error(`Model ${model} not found`);
37
+ }
38
+ await authenticate();
39
+ const type = modelData?.spec?.runtime?.type || "openai";
40
+ try {
41
+ if (type === "gemini") {
42
+ return new AuthenticatedChatGoogleGenerativeAI({
43
+ apiKey: settings.token,
44
+ model: modelData?.spec?.runtime?.model,
45
+ baseUrl: url,
46
+ customHeaders: settings.headers,
47
+ ...options,
48
+ });
49
+ }
50
+ else if (type === "mistral") {
51
+ return new ChatOpenAI({
52
+ apiKey: "replaced",
53
+ model: modelData?.spec?.runtime?.model,
54
+ configuration: {
55
+ baseURL: `${url}/v1`,
56
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
57
+ fetch: authenticatedFetch(),
58
+ },
59
+ ...options,
60
+ });
61
+ }
62
+ else if (type === "cohere") {
63
+ return new ChatCohere({
64
+ apiKey: "replaced",
65
+ model: modelData?.spec?.runtime?.model,
66
+ client: new CohereClient({
67
+ token: "replaced",
68
+ environment: url,
69
+ fetcher: createCohereFetcher(),
70
+ }),
71
+ ...options,
72
+ });
73
+ }
74
+ else if (type === "deepseek") {
75
+ return new ChatDeepSeek({
76
+ apiKey: "replaced",
77
+ model: modelData?.spec?.runtime?.model,
78
+ configuration: {
79
+ baseURL: `${url}/v1`,
80
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
81
+ fetch: authenticatedFetch(),
82
+ },
83
+ ...options,
84
+ });
85
+ }
86
+ else if (type === "anthropic") {
87
+ return new ChatAnthropic({
88
+ anthropicApiUrl: url,
89
+ model: modelData?.spec?.runtime?.model,
90
+ clientOptions: {
91
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
92
+ fetch: authenticatedFetch(),
93
+ },
94
+ ...options,
95
+ });
96
+ }
97
+ else if (type === "xai") {
98
+ return new ChatXAI({
99
+ apiKey: "replaced",
100
+ configuration: {
101
+ baseURL: `${url}/v1`,
102
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
103
+ fetch: authenticatedFetch(),
104
+ },
105
+ model: modelData?.spec?.runtime?.model,
106
+ ...options,
107
+ });
108
+ }
109
+ else if (type === "cerebras") {
110
+ // We don't use ChatCerebras because there is a problem with apiKey headers
111
+ return new ChatOpenAI({
112
+ apiKey: "replaced",
113
+ model: modelData?.spec?.runtime?.model,
114
+ configuration: {
115
+ baseURL: `${url}/v1`,
116
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
117
+ fetch: authenticatedFetch(),
118
+ },
119
+ ...options,
120
+ });
121
+ }
122
+ return new ChatOpenAI({
123
+ apiKey: "replaced",
124
+ model: modelData?.spec?.runtime?.model,
125
+ configuration: {
126
+ baseURL: `${url}/v1`,
127
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
128
+ fetch: authenticatedFetch(),
129
+ },
130
+ ...options,
131
+ });
132
+ }
133
+ catch (err) {
134
+ handleDynamicImportError(err);
135
+ throw err;
136
+ }
137
+ };
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1,19 @@
1
+ import * as RunnableModule from "@langchain/core/runnables";
2
+ import * as ToolsModule from "@langchain/core/tools";
3
+ import * as VectorStoresModule from "@langchain/core/vectorstores";
4
+ import { registerInstrumentations } from "@opentelemetry/instrumentation";
5
+ import { LangChainInstrumentation } from "@traceloop/instrumentation-langchain";
6
+ import * as AgentsModule from "langchain/agents";
7
+ import * as ChainsModule from "langchain/chains";
8
+ const langchain = new LangChainInstrumentation();
9
+ langchain.manuallyInstrument({
10
+ runnablesModule: RunnableModule,
11
+ toolsModule: ToolsModule,
12
+ chainsModule: ChainsModule,
13
+ agentsModule: AgentsModule,
14
+ vectorStoreModule: VectorStoresModule,
15
+ });
16
+ langchain.enable();
17
+ registerInstrumentations({
18
+ instrumentations: [langchain],
19
+ });
@@ -0,0 +1,22 @@
1
+ import { getTool, handleDynamicImportError } from "@blaxel/core";
2
+ import { tool } from "@langchain/core/tools";
3
+ export async function blTool(name, options) {
4
+ try {
5
+ const blaxelTool = await getTool(name, options);
6
+ return blaxelTool.map((t) =>
7
+ // @ts-ignore - Type instantiation depth issue with tool schemas
8
+ tool(t.call.bind(t), {
9
+ name: t.name,
10
+ description: t.description,
11
+ schema: t.inputSchema,
12
+ }));
13
+ }
14
+ catch (err) {
15
+ handleDynamicImportError(err);
16
+ throw err;
17
+ }
18
+ }
19
+ export async function blTools(names, ms) {
20
+ const toolArrays = await Promise.all(names.map((n) => blTool(n, ms)));
21
+ return toolArrays.flat();
22
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blaxel/langgraph",
3
- "version": "0.2.36-dev.185",
3
+ "version": "0.2.36-dev.190",
4
4
  "description": "Blaxel SDK for TypeScript",
5
5
  "license": "MIT",
6
6
  "author": "Blaxel, INC (https://blaxel.ai)",
@@ -17,38 +17,22 @@
17
17
  "agent",
18
18
  "mcp"
19
19
  ],
20
- "main": "dist/index.js",
21
- "module": "dist/index.js",
22
- "types": "dist/index.d.ts",
20
+ "main": "./dist/cjs/index.js",
21
+ "module": "./dist/esm/index.js",
22
+ "types": "./dist/cjs/types/index.d.ts",
23
23
  "exports": {
24
24
  ".": {
25
- "import": {
26
- "types": "./dist/index.d.ts",
27
- "default": "./dist/index.js"
28
- },
29
- "require": {
30
- "types": "./dist/index.d.ts",
31
- "default": "./dist/index.js"
32
- }
25
+ "types": "./dist/cjs/types/index.d.ts",
26
+ "import": "./dist/esm/index.js",
27
+ "require": "./dist/cjs/index.js",
28
+ "default": "./dist/cjs/index.js"
33
29
  },
34
- "./*": {
35
- "import": {
36
- "types": "./dist/*.d.ts",
37
- "default": "./dist/*.js"
38
- },
39
- "require": {
40
- "types": "./dist/*.d.ts",
41
- "default": "./dist/*.js"
42
- }
43
- }
30
+ "./package.json": "./package.json"
44
31
  },
45
32
  "typesVersions": {
46
33
  "*": {
47
34
  ".": [
48
- "./dist/index.d.ts"
49
- ],
50
- "*": [
51
- "./dist/*"
35
+ "./dist/cjs/types/index.d.ts"
52
36
  ]
53
37
  }
54
38
  },
@@ -68,7 +52,7 @@
68
52
  "langchain": "^0.3.24",
69
53
  "zod": "^3.24.3",
70
54
  "zod-to-json-schema": "^3.24.5",
71
- "@blaxel/core": "0.2.36-dev.185"
55
+ "@blaxel/core": "0.2.36-dev.190"
72
56
  },
73
57
  "devDependencies": {
74
58
  "@eslint/js": "^9.26.0",
@@ -79,6 +63,10 @@
79
63
  "scripts": {
80
64
  "lint": "eslint src/",
81
65
  "dev": "tsc --watch",
82
- "build": "tsc"
66
+ "build": "npm run build:cjs && npm run build:esm && npm run build:fix-esm && npm run build:esm-package",
67
+ "build:cjs": "NODE_OPTIONS='--max-old-space-size=8192' tsc -p tsconfig.cjs.json",
68
+ "build:esm": "NODE_OPTIONS='--max-old-space-size=8192' tsc -p tsconfig.esm.json",
69
+ "build:fix-esm": "node fix-esm-imports.js",
70
+ "build:esm-package": "echo '{\"type\":\"module\"}' > dist/esm/package.json"
83
71
  }
84
72
  }
package/dist/telemetry.js DELETED
@@ -1,24 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const runnables_1 = __importDefault(require("@langchain/core/runnables"));
7
- const tools_1 = __importDefault(require("@langchain/core/tools"));
8
- const vectorstores_1 = __importDefault(require("@langchain/core/vectorstores"));
9
- const instrumentation_1 = require("@opentelemetry/instrumentation");
10
- const instrumentation_langchain_1 = require("@traceloop/instrumentation-langchain");
11
- const agents_1 = __importDefault(require("langchain/agents"));
12
- const chains_1 = __importDefault(require("langchain/chains"));
13
- const langchain = new instrumentation_langchain_1.LangChainInstrumentation();
14
- langchain.manuallyInstrument({
15
- runnablesModule: runnables_1.default,
16
- toolsModule: tools_1.default,
17
- chainsModule: chains_1.default,
18
- agentsModule: agents_1.default,
19
- vectorStoreModule: vectorstores_1.default,
20
- });
21
- langchain.enable();
22
- (0, instrumentation_1.registerInstrumentations)({
23
- instrumentations: [langchain],
24
- });
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes