@blaxel/langgraph 0.2.49-dev.214 → 0.2.49-dev1

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 (34) hide show
  1. package/dist/cjs/.tsbuildinfo +1 -1
  2. package/dist/cjs/types/tools.d.ts +6 -2
  3. package/dist/esm/.tsbuildinfo +1 -1
  4. package/dist/index.d.ts +3 -0
  5. package/dist/index.js +19 -0
  6. package/dist/model/cohere.d.ts +6 -0
  7. package/dist/model/cohere.js +172 -0
  8. package/dist/model/google-genai/chat_models.d.ts +557 -0
  9. package/dist/model/google-genai/chat_models.js +755 -0
  10. package/dist/model/google-genai/embeddings.d.ts +94 -0
  11. package/dist/model/google-genai/embeddings.js +111 -0
  12. package/dist/model/google-genai/index.d.ts +2 -0
  13. package/dist/model/google-genai/index.js +18 -0
  14. package/dist/model/google-genai/output_parsers.d.ts +20 -0
  15. package/dist/model/google-genai/output_parsers.js +50 -0
  16. package/dist/model/google-genai/types.d.ts +3 -0
  17. package/dist/model/google-genai/types.js +2 -0
  18. package/dist/model/google-genai/utils/common.d.ts +22 -0
  19. package/dist/model/google-genai/utils/common.js +386 -0
  20. package/dist/model/google-genai/utils/tools.d.ts +10 -0
  21. package/dist/model/google-genai/utils/tools.js +110 -0
  22. package/dist/model/google-genai/utils/zod_to_genai_parameters.d.ts +13 -0
  23. package/dist/model/google-genai/utils/zod_to_genai_parameters.js +46 -0
  24. package/dist/model/google-genai.d.ts +11 -0
  25. package/dist/model/google-genai.js +30 -0
  26. package/dist/model/xai.d.ts +41 -0
  27. package/dist/model/xai.js +82 -0
  28. package/dist/model.d.ts +2 -0
  29. package/dist/model.js +141 -0
  30. package/dist/telemetry.d.ts +1 -0
  31. package/dist/telemetry.js +24 -0
  32. package/dist/tools.d.ts +15 -0
  33. package/dist/tools.js +24 -0
  34. package/package.json +2 -2
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ChatXAI = void 0;
4
+ const env_1 = require("@langchain/core/utils/env");
5
+ const openai_1 = require("@langchain/openai");
6
+ /**
7
+ * Extends the ChatOpenAI class to create a ChatXAI agent with additional configurations.
8
+ */
9
+ class ChatXAI extends openai_1.ChatOpenAI {
10
+ /**
11
+ * Returns the name of the class for LangChain serialization.
12
+ * @returns The class name as a string.
13
+ */
14
+ static lc_name() {
15
+ return "ChatXAI";
16
+ }
17
+ /**
18
+ * Specifies the type of the language model.
19
+ * @returns The type of the LLM as a string.
20
+ */
21
+ _llmType() {
22
+ return "xAI";
23
+ }
24
+ /**
25
+ * Specifies the secrets required for serialization.
26
+ * @returns An object mapping secret names to their keys.
27
+ */
28
+ get lc_secrets() {
29
+ return {
30
+ apiKey: "XAI_API_KEY",
31
+ };
32
+ }
33
+ /**
34
+ * Constructs a new ChatXAI instance.
35
+ * @param fields - Configuration fields, including the API key.
36
+ * @throws If the API key is not provided.
37
+ */
38
+ constructor(fields) {
39
+ const apiKey = fields?.apiKey || (0, env_1.getEnvironmentVariable)("XAI_API_KEY");
40
+ if (!apiKey) {
41
+ throw new Error(`xAI API key not found. Please set the XAI_API_KEY environment variable or provide the key into "apiKey" field.`);
42
+ }
43
+ super(fields);
44
+ Object.defineProperty(this, "lc_serializable", {
45
+ enumerable: true,
46
+ configurable: true,
47
+ writable: true,
48
+ value: true,
49
+ });
50
+ Object.defineProperty(this, "lc_namespace", {
51
+ enumerable: true,
52
+ configurable: true,
53
+ writable: true,
54
+ value: ["langchain", "chat_models", "xai"],
55
+ });
56
+ }
57
+ /**
58
+ * Serializes the instance to JSON, removing sensitive information.
59
+ * @returns The serialized JSON object.
60
+ */
61
+ toJSON() {
62
+ const result = super.toJSON();
63
+ if ("kwargs" in result &&
64
+ typeof result.kwargs === "object" &&
65
+ result.kwargs != null) {
66
+ delete result.kwargs.openai_api_key;
67
+ delete result.kwargs.configuration;
68
+ }
69
+ return result;
70
+ }
71
+ /**
72
+ * Retrieves parameters for LangChain based on provided options.
73
+ * @param options - Additional options for parameter retrieval.
74
+ * @returns An object containing LangChain parameters.
75
+ */
76
+ getLsParams(options) {
77
+ const params = super.getLsParams(options);
78
+ params.ls_provider = "xai";
79
+ return params;
80
+ }
81
+ }
82
+ exports.ChatXAI = ChatXAI;
@@ -0,0 +1,2 @@
1
+ import { LanguageModelLike } from "@langchain/core/language_models/base";
2
+ export declare const blModel: (model: string, options?: Record<string, unknown>) => Promise<LanguageModelLike>;
package/dist/model.js ADDED
@@ -0,0 +1,141 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.blModel = void 0;
4
+ const core_1 = require("@blaxel/core");
5
+ const anthropic_1 = require("@langchain/anthropic");
6
+ const cohere_1 = require("@langchain/cohere");
7
+ const deepseek_1 = require("@langchain/deepseek");
8
+ const openai_1 = require("@langchain/openai");
9
+ const cohere_ai_1 = require("cohere-ai");
10
+ const cohere_js_1 = require("./model/cohere.js");
11
+ const google_genai_js_1 = require("./model/google-genai.js");
12
+ const xai_js_1 = require("./model/xai.js");
13
+ /**
14
+ * Creates a custom fetch function that adds dynamic headers to each request
15
+ * Returns a function compatible with OpenAI SDK's fetch option
16
+ */
17
+ const authenticatedFetch = () => {
18
+ const customFetch = async (input, init) => {
19
+ await (0, core_1.authenticate)();
20
+ const dynamicHeaders = core_1.settings.headers;
21
+ // Merge headers: init headers take precedence over dynamic headers
22
+ const headers = {
23
+ ...dynamicHeaders,
24
+ ...(init?.headers || {}),
25
+ };
26
+ // Make the request with merged headers
27
+ return await fetch(input, {
28
+ ...init,
29
+ headers,
30
+ });
31
+ };
32
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
33
+ return customFetch;
34
+ };
35
+ const blModel = async (model, options) => {
36
+ const url = `${core_1.settings.runUrl}/${core_1.settings.workspace}/models/${model}`;
37
+ const modelData = await (0, core_1.getModelMetadata)(model);
38
+ if (!modelData) {
39
+ throw new Error(`Model ${model} not found`);
40
+ }
41
+ await (0, core_1.authenticate)();
42
+ const type = modelData?.spec?.runtime?.type || "openai";
43
+ try {
44
+ if (type === "gemini") {
45
+ return new google_genai_js_1.AuthenticatedChatGoogleGenerativeAI({
46
+ apiKey: core_1.settings.token,
47
+ model: modelData?.spec?.runtime?.model,
48
+ baseUrl: url,
49
+ customHeaders: core_1.settings.headers,
50
+ ...options,
51
+ });
52
+ }
53
+ else if (type === "mistral") {
54
+ return new openai_1.ChatOpenAI({
55
+ apiKey: "replaced",
56
+ model: modelData?.spec?.runtime?.model,
57
+ configuration: {
58
+ baseURL: `${url}/v1`,
59
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
60
+ fetch: authenticatedFetch(),
61
+ },
62
+ ...options,
63
+ });
64
+ }
65
+ else if (type === "cohere") {
66
+ return new cohere_1.ChatCohere({
67
+ apiKey: "replaced",
68
+ model: modelData?.spec?.runtime?.model,
69
+ client: new cohere_ai_1.CohereClient({
70
+ token: "replaced",
71
+ environment: url,
72
+ fetcher: (0, cohere_js_1.createCohereFetcher)(),
73
+ }),
74
+ ...options,
75
+ });
76
+ }
77
+ else if (type === "deepseek") {
78
+ return new deepseek_1.ChatDeepSeek({
79
+ apiKey: "replaced",
80
+ model: modelData?.spec?.runtime?.model,
81
+ configuration: {
82
+ baseURL: `${url}/v1`,
83
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
84
+ fetch: authenticatedFetch(),
85
+ },
86
+ ...options,
87
+ });
88
+ }
89
+ else if (type === "anthropic") {
90
+ return new anthropic_1.ChatAnthropic({
91
+ anthropicApiUrl: url,
92
+ model: modelData?.spec?.runtime?.model,
93
+ clientOptions: {
94
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
95
+ fetch: authenticatedFetch(),
96
+ },
97
+ ...options,
98
+ });
99
+ }
100
+ else if (type === "xai") {
101
+ return new xai_js_1.ChatXAI({
102
+ apiKey: "replaced",
103
+ configuration: {
104
+ baseURL: `${url}/v1`,
105
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
106
+ fetch: authenticatedFetch(),
107
+ },
108
+ model: modelData?.spec?.runtime?.model,
109
+ ...options,
110
+ });
111
+ }
112
+ else if (type === "cerebras") {
113
+ // We don't use ChatCerebras because there is a problem with apiKey headers
114
+ return new openai_1.ChatOpenAI({
115
+ apiKey: "replaced",
116
+ model: modelData?.spec?.runtime?.model,
117
+ configuration: {
118
+ baseURL: `${url}/v1`,
119
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
120
+ fetch: authenticatedFetch(),
121
+ },
122
+ ...options,
123
+ });
124
+ }
125
+ return new openai_1.ChatOpenAI({
126
+ apiKey: "replaced",
127
+ model: modelData?.spec?.runtime?.model,
128
+ configuration: {
129
+ baseURL: `${url}/v1`,
130
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
131
+ fetch: authenticatedFetch(),
132
+ },
133
+ ...options,
134
+ });
135
+ }
136
+ catch (err) {
137
+ (0, core_1.handleDynamicImportError)(err);
138
+ throw err;
139
+ }
140
+ };
141
+ exports.blModel = blModel;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,24 @@
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
+ });
@@ -0,0 +1,15 @@
1
+ import { ToolOptions } from "@blaxel/core/tools/mcpTool";
2
+ export declare function blTool(name: string, options?: ToolOptions | number): Promise<import("@langchain/core/tools").DynamicStructuredTool<import("zod").ZodObject<any, import("zod").UnknownKeysParam, import("zod").ZodTypeAny, {
3
+ [x: string]: any;
4
+ }, {
5
+ [x: string]: any;
6
+ }>, unknown, {
7
+ [x: string]: any;
8
+ }>[]>;
9
+ export declare function blTools(names: string[], ms?: number): Promise<import("@langchain/core/tools").DynamicStructuredTool<import("zod").ZodObject<any, import("zod").UnknownKeysParam, import("zod").ZodTypeAny, {
10
+ [x: string]: any;
11
+ }, {
12
+ [x: string]: any;
13
+ }>, unknown, {
14
+ [x: string]: any;
15
+ }>[]>;
package/dist/tools.js ADDED
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.blTool = blTool;
4
+ exports.blTools = blTools;
5
+ const core_1 = require("@blaxel/core");
6
+ const tools_1 = require("@langchain/core/tools");
7
+ async function blTool(name, options) {
8
+ try {
9
+ const blaxelTool = await (0, core_1.getTool)(name, options);
10
+ return blaxelTool.map((t) => (0, tools_1.tool)(t.call.bind(t), {
11
+ name: t.name,
12
+ description: t.description,
13
+ schema: t.inputSchema,
14
+ }));
15
+ }
16
+ catch (err) {
17
+ (0, core_1.handleDynamicImportError)(err);
18
+ throw err;
19
+ }
20
+ }
21
+ async function blTools(names, ms) {
22
+ const toolArrays = await Promise.all(names.map((n) => blTool(n, ms)));
23
+ return toolArrays.flat();
24
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blaxel/langgraph",
3
- "version": "0.2.49-dev.214",
3
+ "version": "0.2.49-dev1",
4
4
  "description": "Blaxel SDK for TypeScript",
5
5
  "license": "MIT",
6
6
  "author": "Blaxel, INC (https://blaxel.ai)",
@@ -52,7 +52,7 @@
52
52
  "langchain": "^0.3.24",
53
53
  "zod": "^3.24.3",
54
54
  "zod-to-json-schema": "^3.24.5",
55
- "@blaxel/core": "0.2.49-dev.214"
55
+ "@blaxel/core": "0.2.49-dev1"
56
56
  },
57
57
  "devDependencies": {
58
58
  "@eslint/js": "^9.26.0",