@nocobase/plugin-ai 2.1.0-beta.25 → 2.1.0-beta.26

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 (72) hide show
  1. package/dist/client/{559.c119db3f985a695f.js → 559.39872901b9053629.js} +1 -1
  2. package/dist/client/index.js +3 -3
  3. package/dist/client/llm-providers/xai/ModelSettings.d.ts +10 -0
  4. package/dist/client/llm-providers/xai/index.d.ts +10 -0
  5. package/dist/externalVersion.js +15 -15
  6. package/dist/node_modules/@langchain/xai/LICENSE +21 -0
  7. package/dist/node_modules/@langchain/xai/dist/_virtual/rolldown_runtime.cjs +25 -0
  8. package/dist/node_modules/@langchain/xai/dist/chat_models/completions.cjs +568 -0
  9. package/dist/node_modules/@langchain/xai/dist/chat_models/completions.d.cts +619 -0
  10. package/dist/node_modules/@langchain/xai/dist/chat_models/completions.d.ts +619 -0
  11. package/dist/node_modules/@langchain/xai/dist/chat_models/completions.js +566 -0
  12. package/dist/node_modules/@langchain/xai/dist/chat_models/index.cjs +2 -0
  13. package/dist/node_modules/@langchain/xai/dist/chat_models/index.d.ts +3 -0
  14. package/dist/node_modules/@langchain/xai/dist/chat_models/index.js +2 -0
  15. package/dist/node_modules/@langchain/xai/dist/chat_models/responses-types.d.cts +1178 -0
  16. package/dist/node_modules/@langchain/xai/dist/chat_models/responses-types.d.ts +1178 -0
  17. package/dist/node_modules/@langchain/xai/dist/chat_models/responses.cjs +233 -0
  18. package/dist/node_modules/@langchain/xai/dist/chat_models/responses.d.cts +70 -0
  19. package/dist/node_modules/@langchain/xai/dist/chat_models/responses.d.ts +70 -0
  20. package/dist/node_modules/@langchain/xai/dist/chat_models/responses.js +232 -0
  21. package/dist/node_modules/@langchain/xai/dist/converters/responses.cjs +168 -0
  22. package/dist/node_modules/@langchain/xai/dist/converters/responses.js +164 -0
  23. package/dist/node_modules/@langchain/xai/dist/index.cjs +7 -0
  24. package/dist/node_modules/@langchain/xai/dist/index.d.cts +5 -0
  25. package/dist/node_modules/@langchain/xai/dist/index.d.ts +6 -0
  26. package/dist/node_modules/@langchain/xai/dist/index.js +6 -0
  27. package/dist/node_modules/@langchain/xai/dist/live_search.cjs +54 -0
  28. package/dist/node_modules/@langchain/xai/dist/live_search.d.cts +145 -0
  29. package/dist/node_modules/@langchain/xai/dist/live_search.d.ts +145 -0
  30. package/dist/node_modules/@langchain/xai/dist/live_search.js +51 -0
  31. package/dist/node_modules/@langchain/xai/dist/profiles.cjs +289 -0
  32. package/dist/node_modules/@langchain/xai/dist/profiles.js +288 -0
  33. package/dist/node_modules/@langchain/xai/dist/tools/code_execution.cjs +52 -0
  34. package/dist/node_modules/@langchain/xai/dist/tools/code_execution.d.cts +64 -0
  35. package/dist/node_modules/@langchain/xai/dist/tools/code_execution.d.ts +64 -0
  36. package/dist/node_modules/@langchain/xai/dist/tools/code_execution.js +50 -0
  37. package/dist/node_modules/@langchain/xai/dist/tools/collections_search.cjs +60 -0
  38. package/dist/node_modules/@langchain/xai/dist/tools/collections_search.d.cts +90 -0
  39. package/dist/node_modules/@langchain/xai/dist/tools/collections_search.d.ts +90 -0
  40. package/dist/node_modules/@langchain/xai/dist/tools/collections_search.js +58 -0
  41. package/dist/node_modules/@langchain/xai/dist/tools/index.cjs +18 -0
  42. package/dist/node_modules/@langchain/xai/dist/tools/index.d.cts +18 -0
  43. package/dist/node_modules/@langchain/xai/dist/tools/index.d.ts +18 -0
  44. package/dist/node_modules/@langchain/xai/dist/tools/index.js +18 -0
  45. package/dist/node_modules/@langchain/xai/dist/tools/live_search.cjs +94 -0
  46. package/dist/node_modules/@langchain/xai/dist/tools/live_search.d.cts +149 -0
  47. package/dist/node_modules/@langchain/xai/dist/tools/live_search.d.ts +149 -0
  48. package/dist/node_modules/@langchain/xai/dist/tools/live_search.js +91 -0
  49. package/dist/node_modules/@langchain/xai/dist/tools/web_search.cjs +57 -0
  50. package/dist/node_modules/@langchain/xai/dist/tools/web_search.d.cts +104 -0
  51. package/dist/node_modules/@langchain/xai/dist/tools/web_search.d.ts +104 -0
  52. package/dist/node_modules/@langchain/xai/dist/tools/web_search.js +55 -0
  53. package/dist/node_modules/@langchain/xai/dist/tools/x_search.cjs +63 -0
  54. package/dist/node_modules/@langchain/xai/dist/tools/x_search.d.cts +145 -0
  55. package/dist/node_modules/@langchain/xai/dist/tools/x_search.d.ts +145 -0
  56. package/dist/node_modules/@langchain/xai/dist/tools/x_search.js +61 -0
  57. package/dist/node_modules/@langchain/xai/package.json +1 -0
  58. package/dist/node_modules/fast-glob/package.json +1 -1
  59. package/dist/node_modules/flexsearch/package.json +1 -1
  60. package/dist/node_modules/fs-extra/package.json +1 -1
  61. package/dist/node_modules/jsonrepair/package.json +1 -1
  62. package/dist/node_modules/nodejs-snowflake/package.json +1 -1
  63. package/dist/node_modules/openai/package.json +1 -1
  64. package/dist/node_modules/zod/package.json +1 -1
  65. package/dist/server/ai-employees/ai-employee.js +11 -7
  66. package/dist/server/llm-providers/xai.d.ts +17 -0
  67. package/dist/server/llm-providers/xai.js +88 -0
  68. package/dist/server/plugin.js +3 -0
  69. package/dist/server/workflow/nodes/employee/files.js +7 -4
  70. package/dist/server/workflow/nodes/employee/index.js +4 -3
  71. package/dist/server/workflow/nodes/employee/types.d.ts +1 -1
  72. package/package.json +3 -2
@@ -0,0 +1,10 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ import React from 'react';
10
+ export declare const ModelSettingsForm: React.FC;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ import { LLMProviderOptions } from '../../manager/ai-manager';
10
+ export declare const xaiProviderOptions: LLMProviderOptions;
@@ -8,26 +8,26 @@
8
8
  */
9
9
 
10
10
  module.exports = {
11
- "@nocobase/plugin-acl": "2.1.0-beta.25",
12
- "@nocobase/plugin-workflow": "2.1.0-beta.25",
13
- "@nocobase/client": "2.1.0-beta.25",
14
- "@nocobase/utils": "2.1.0-beta.25",
15
- "@nocobase/database": "2.1.0-beta.25",
16
- "@nocobase/server": "2.1.0-beta.25",
17
- "@nocobase/plugin-file-manager": "2.1.0-beta.25",
18
- "@nocobase/actions": "2.1.0-beta.25",
19
- "@nocobase/ai": "2.1.0-beta.25",
11
+ "@nocobase/plugin-acl": "2.1.0-beta.26",
12
+ "@nocobase/plugin-workflow": "2.1.0-beta.26",
13
+ "@nocobase/client": "2.1.0-beta.26",
14
+ "@nocobase/utils": "2.1.0-beta.26",
15
+ "@nocobase/database": "2.1.0-beta.26",
16
+ "@nocobase/server": "2.1.0-beta.26",
17
+ "@nocobase/plugin-file-manager": "2.1.0-beta.26",
18
+ "@nocobase/actions": "2.1.0-beta.26",
19
+ "@nocobase/ai": "2.1.0-beta.26",
20
20
  "langchain": "1.2.24",
21
21
  "react": "18.2.0",
22
22
  "antd": "5.24.2",
23
23
  "@formily/core": "2.3.7",
24
24
  "@formily/react": "2.3.7",
25
- "@nocobase/flow-engine": "2.1.0-beta.25",
25
+ "@nocobase/flow-engine": "2.1.0-beta.26",
26
26
  "@ant-design/icons": "5.6.1",
27
27
  "@formily/antd-v5": "1.2.3",
28
28
  "react-router-dom": "6.30.1",
29
29
  "@formily/shared": "2.3.7",
30
- "@nocobase/client-v2": "2.1.0-beta.25",
30
+ "@nocobase/client-v2": "2.1.0-beta.26",
31
31
  "@formily/reactive": "2.3.7",
32
32
  "lodash": "4.18.1",
33
33
  "@langchain/core": "1.1.24",
@@ -38,14 +38,14 @@ module.exports = {
38
38
  "@langchain/deepseek": "1.0.11",
39
39
  "@langchain/google-genai": "2.1.18",
40
40
  "@langchain/ollama": "1.2.2",
41
- "@nocobase/acl": "2.1.0-beta.25",
42
- "@nocobase/resourcer": "2.1.0-beta.25",
41
+ "@nocobase/acl": "2.1.0-beta.26",
42
+ "@nocobase/resourcer": "2.1.0-beta.26",
43
43
  "@emotion/css": "11.13.0",
44
44
  "dayjs": "1.11.13",
45
45
  "react-i18next": "11.18.6",
46
- "@nocobase/plugin-data-source-manager": "2.1.0-beta.25",
46
+ "@nocobase/plugin-data-source-manager": "2.1.0-beta.26",
47
47
  "ahooks": "3.7.8",
48
48
  "@langchain/langgraph-checkpoint": "1.0.0",
49
- "@nocobase/data-source-manager": "2.1.0-beta.25",
49
+ "@nocobase/data-source-manager": "2.1.0-beta.26",
50
50
  "react-dom": "18.2.0"
51
51
  };
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) LangChain, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,25 @@
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+
23
+ //#endregion
24
+
25
+ exports.__toESM = __toESM;
@@ -0,0 +1,568 @@
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
+ const require_live_search = require('../live_search.cjs');
3
+ const require_profiles = require('../profiles.cjs');
4
+ const require_live_search$1 = require('../tools/live_search.cjs');
5
+ const __langchain_core_utils_function_calling = require_rolldown_runtime.__toESM(require("@langchain/core/utils/function_calling"));
6
+ const __langchain_core_utils_env = require_rolldown_runtime.__toESM(require("@langchain/core/utils/env"));
7
+ const __langchain_openai = require_rolldown_runtime.__toESM(require("@langchain/openai"));
8
+
9
+ //#region src/chat_models/completions.ts
10
+ /**
11
+ * Set of all supported xAI built-in server-side tool types.
12
+ * This allows us to easily extend support for future built-in tools
13
+ * without changing the core detection logic.
14
+ */
15
+ const XAI_BUILT_IN_TOOL_TYPES = new Set([require_live_search$1.XAI_LIVE_SEARCH_TOOL_TYPE]);
16
+ /**
17
+ * Checks if a tool is an xAI built-in tool (like live_search).
18
+ * Built-in tools are executed server-side by the xAI API.
19
+ *
20
+ * @param tool - The tool to check
21
+ * @returns true if the tool is an xAI built-in tool
22
+ */
23
+ function isXAIBuiltInTool(tool) {
24
+ return typeof tool === "object" && tool !== null && "type" in tool && typeof tool.type === "string" && XAI_BUILT_IN_TOOL_TYPES.has(tool.type);
25
+ }
26
+ /**
27
+ * xAI chat model integration.
28
+ *
29
+ * The xAI API is compatible to the OpenAI API with some limitations.
30
+ *
31
+ * Setup:
32
+ * Install `@langchain/xai` and set an environment variable named `XAI_API_KEY`.
33
+ *
34
+ * ```bash
35
+ * npm install @langchain/xai
36
+ * export XAI_API_KEY="your-api-key"
37
+ * ```
38
+ *
39
+ * ## [Constructor args](https://api.js.langchain.com/classes/_langchain_xai.ChatXAI.html#constructor)
40
+ *
41
+ * ## [Runtime args](https://api.js.langchain.com/interfaces/_langchain_xai.ChatXAICallOptions.html)
42
+ *
43
+ * Runtime args can be passed as the second argument to any of the base runnable methods `.invoke`. `.stream`, `.batch`, etc.
44
+ * They can also be passed via `.withConfig`, or the second arg in `.bindTools`, like shown in the examples below:
45
+ *
46
+ * ```typescript
47
+ * // When calling `.withConfig`, call options should be passed via the first argument
48
+ * const llmWithArgsBound = llm.withConfig({
49
+ * stop: ["\n"],
50
+ * tools: [...],
51
+ * });
52
+ *
53
+ * // When calling `.bindTools`, call options should be passed via the second argument
54
+ * const llmWithTools = llm.bindTools(
55
+ * [...],
56
+ * {
57
+ * tool_choice: "auto",
58
+ * }
59
+ * );
60
+ * ```
61
+ *
62
+ * ## Examples
63
+ *
64
+ * <details open>
65
+ * <summary><strong>Instantiate</strong></summary>
66
+ *
67
+ * ```typescript
68
+ * import { ChatXAI } from '@langchain/xai';
69
+ *
70
+ * const llm = new ChatXAI({
71
+ * model: "grok-beta",
72
+ * temperature: 0,
73
+ * // other params...
74
+ * });
75
+ * ```
76
+ * </details>
77
+ *
78
+ * <br />
79
+ *
80
+ * <details>
81
+ * <summary><strong>Invoking</strong></summary>
82
+ *
83
+ * ```typescript
84
+ * const input = `Translate "I love programming" into French.`;
85
+ *
86
+ * // Models also accept a list of chat messages or a formatted prompt
87
+ * const result = await llm.invoke(input);
88
+ * console.log(result);
89
+ * ```
90
+ *
91
+ * ```txt
92
+ * AIMessage {
93
+ * "content": "The French translation of \"I love programming\" is \"J'aime programmer\". In this sentence, \"J'aime\" is the first person singular conjugation of the French verb \"aimer\" which means \"to love\", and \"programmer\" is the French infinitive for \"to program\". I hope this helps! Let me know if you have any other questions.",
94
+ * "additional_kwargs": {},
95
+ * "response_metadata": {
96
+ * "tokenUsage": {
97
+ * "completionTokens": 82,
98
+ * "promptTokens": 20,
99
+ * "totalTokens": 102
100
+ * },
101
+ * "finish_reason": "stop"
102
+ * },
103
+ * "tool_calls": [],
104
+ * "invalid_tool_calls": []
105
+ * }
106
+ * ```
107
+ * </details>
108
+ *
109
+ * <br />
110
+ *
111
+ * <details>
112
+ * <summary><strong>Streaming Chunks</strong></summary>
113
+ *
114
+ * ```typescript
115
+ * for await (const chunk of await llm.stream(input)) {
116
+ * console.log(chunk);
117
+ * }
118
+ * ```
119
+ *
120
+ * ```txt
121
+ * AIMessageChunk {
122
+ * "content": "",
123
+ * "additional_kwargs": {},
124
+ * "response_metadata": {
125
+ * "finishReason": null
126
+ * },
127
+ * "tool_calls": [],
128
+ * "tool_call_chunks": [],
129
+ * "invalid_tool_calls": []
130
+ * }
131
+ * AIMessageChunk {
132
+ * "content": "The",
133
+ * "additional_kwargs": {},
134
+ * "response_metadata": {
135
+ * "finishReason": null
136
+ * },
137
+ * "tool_calls": [],
138
+ * "tool_call_chunks": [],
139
+ * "invalid_tool_calls": []
140
+ * }
141
+ * AIMessageChunk {
142
+ * "content": " French",
143
+ * "additional_kwargs": {},
144
+ * "response_metadata": {
145
+ * "finishReason": null
146
+ * },
147
+ * "tool_calls": [],
148
+ * "tool_call_chunks": [],
149
+ * "invalid_tool_calls": []
150
+ * }
151
+ * AIMessageChunk {
152
+ * "content": " translation",
153
+ * "additional_kwargs": {},
154
+ * "response_metadata": {
155
+ * "finishReason": null
156
+ * },
157
+ * "tool_calls": [],
158
+ * "tool_call_chunks": [],
159
+ * "invalid_tool_calls": []
160
+ * }
161
+ * AIMessageChunk {
162
+ * "content": " of",
163
+ * "additional_kwargs": {},
164
+ * "response_metadata": {
165
+ * "finishReason": null
166
+ * },
167
+ * "tool_calls": [],
168
+ * "tool_call_chunks": [],
169
+ * "invalid_tool_calls": []
170
+ * }
171
+ * AIMessageChunk {
172
+ * "content": " \"",
173
+ * "additional_kwargs": {},
174
+ * "response_metadata": {
175
+ * "finishReason": null
176
+ * },
177
+ * "tool_calls": [],
178
+ * "tool_call_chunks": [],
179
+ * "invalid_tool_calls": []
180
+ * }
181
+ * AIMessageChunk {
182
+ * "content": "I",
183
+ * "additional_kwargs": {},
184
+ * "response_metadata": {
185
+ * "finishReason": null
186
+ * },
187
+ * "tool_calls": [],
188
+ * "tool_call_chunks": [],
189
+ * "invalid_tool_calls": []
190
+ * }
191
+ * AIMessageChunk {
192
+ * "content": " love",
193
+ * "additional_kwargs": {},
194
+ * "response_metadata": {
195
+ * "finishReason": null
196
+ * },
197
+ * "tool_calls": [],
198
+ * "tool_call_chunks": [],
199
+ * "invalid_tool_calls": []
200
+ * }
201
+ * ...
202
+ * AIMessageChunk {
203
+ * "content": ".",
204
+ * "additional_kwargs": {},
205
+ * "response_metadata": {
206
+ * "finishReason": null
207
+ * },
208
+ * "tool_calls": [],
209
+ * "tool_call_chunks": [],
210
+ * "invalid_tool_calls": []
211
+ * }
212
+ * AIMessageChunk {
213
+ * "content": "",
214
+ * "additional_kwargs": {},
215
+ * "response_metadata": {
216
+ * "finishReason": "stop"
217
+ * },
218
+ * "tool_calls": [],
219
+ * "tool_call_chunks": [],
220
+ * "invalid_tool_calls": []
221
+ * }
222
+ * ```
223
+ * </details>
224
+ *
225
+ * <br />
226
+ *
227
+ * <details>
228
+ * <summary><strong>Aggregate Streamed Chunks</strong></summary>
229
+ *
230
+ * ```typescript
231
+ * import { AIMessageChunk } from '@langchain/core/messages';
232
+ * import { concat } from '@langchain/core/utils/stream';
233
+ *
234
+ * const stream = await llm.stream(input);
235
+ * let full: AIMessageChunk | undefined;
236
+ * for await (const chunk of stream) {
237
+ * full = !full ? chunk : concat(full, chunk);
238
+ * }
239
+ * console.log(full);
240
+ * ```
241
+ *
242
+ * ```txt
243
+ * AIMessageChunk {
244
+ * "content": "The French translation of \"I love programming\" is \"J'aime programmer\". In this sentence, \"J'aime\" is the first person singular conjugation of the French verb \"aimer\" which means \"to love\", and \"programmer\" is the French infinitive for \"to program\". I hope this helps! Let me know if you have any other questions.",
245
+ * "additional_kwargs": {},
246
+ * "response_metadata": {
247
+ * "finishReason": "stop"
248
+ * },
249
+ * "tool_calls": [],
250
+ * "tool_call_chunks": [],
251
+ * "invalid_tool_calls": []
252
+ * }
253
+ * ```
254
+ * </details>
255
+ *
256
+ * <br />
257
+ *
258
+ * <details>
259
+ * <summary><strong>Bind tools</strong></summary>
260
+ *
261
+ * ```typescript
262
+ * import { z } from 'zod';
263
+ *
264
+ * const llmForToolCalling = new ChatXAI({
265
+ * model: "grok-beta",
266
+ * temperature: 0,
267
+ * // other params...
268
+ * });
269
+ *
270
+ * const GetWeather = {
271
+ * name: "GetWeather",
272
+ * description: "Get the current weather in a given location",
273
+ * schema: z.object({
274
+ * location: z.string().describe("The city and state, e.g. San Francisco, CA")
275
+ * }),
276
+ * }
277
+ *
278
+ * const GetPopulation = {
279
+ * name: "GetPopulation",
280
+ * description: "Get the current population in a given location",
281
+ * schema: z.object({
282
+ * location: z.string().describe("The city and state, e.g. San Francisco, CA")
283
+ * }),
284
+ * }
285
+ *
286
+ * const llmWithTools = llmForToolCalling.bindTools([GetWeather, GetPopulation]);
287
+ * const aiMsg = await llmWithTools.invoke(
288
+ * "Which city is hotter today and which is bigger: LA or NY?"
289
+ * );
290
+ * console.log(aiMsg.tool_calls);
291
+ * ```
292
+ *
293
+ * ```txt
294
+ * [
295
+ * {
296
+ * name: 'GetWeather',
297
+ * args: { location: 'Los Angeles, CA' },
298
+ * type: 'tool_call',
299
+ * id: 'call_cd34'
300
+ * },
301
+ * {
302
+ * name: 'GetWeather',
303
+ * args: { location: 'New York, NY' },
304
+ * type: 'tool_call',
305
+ * id: 'call_68rf'
306
+ * },
307
+ * {
308
+ * name: 'GetPopulation',
309
+ * args: { location: 'Los Angeles, CA' },
310
+ * type: 'tool_call',
311
+ * id: 'call_f81z'
312
+ * },
313
+ * {
314
+ * name: 'GetPopulation',
315
+ * args: { location: 'New York, NY' },
316
+ * type: 'tool_call',
317
+ * id: 'call_8byt'
318
+ * }
319
+ * ]
320
+ * ```
321
+ * </details>
322
+ *
323
+ * <br />
324
+ *
325
+ * <details>
326
+ * <summary><strong>Structured Output</strong></summary>
327
+ *
328
+ * ```typescript
329
+ * import { z } from 'zod';
330
+ *
331
+ * const Joke = z.object({
332
+ * setup: z.string().describe("The setup of the joke"),
333
+ * punchline: z.string().describe("The punchline to the joke"),
334
+ * rating: z.number().optional().describe("How funny the joke is, from 1 to 10")
335
+ * }).describe('Joke to tell user.');
336
+ *
337
+ * const structuredLlm = llmForToolCalling.withStructuredOutput(Joke, { name: "Joke" });
338
+ * const jokeResult = await structuredLlm.invoke("Tell me a joke about cats");
339
+ * console.log(jokeResult);
340
+ * ```
341
+ *
342
+ * ```txt
343
+ * {
344
+ * setup: "Why don't cats play poker in the wild?",
345
+ * punchline: 'Because there are too many cheetahs.'
346
+ * }
347
+ * ```
348
+ * </details>
349
+ *
350
+ * <br />
351
+ *
352
+ * <details>
353
+ * <summary><strong>Server Tool Calling (Live Search)</strong></summary>
354
+ *
355
+ * xAI supports server-side tools that are executed by the API rather than
356
+ * requiring client-side execution. The `live_search` tool enables the model
357
+ * to search the web for real-time information.
358
+ *
359
+ * ```typescript
360
+ * // Method 1: Using the built-in live_search tool
361
+ * const llm = new ChatXAI({
362
+ * model: "grok-beta",
363
+ * temperature: 0,
364
+ * });
365
+ *
366
+ * const llmWithSearch = llm.bindTools([{ type: "live_search" }]);
367
+ * const result = await llmWithSearch.invoke("What happened in tech news today?");
368
+ * console.log(result.content);
369
+ * // The model will search the web and include real-time information in its response
370
+ * ```
371
+ *
372
+ * ```typescript
373
+ * // Method 2: Using searchParameters for more control
374
+ * const llm = new ChatXAI({
375
+ * model: "grok-beta",
376
+ * searchParameters: {
377
+ * mode: "auto", // "auto" | "on" | "off"
378
+ * max_search_results: 5,
379
+ * from_date: "2024-01-01", // ISO date string
380
+ * return_citations: true,
381
+ * }
382
+ * });
383
+ *
384
+ * const result = await llm.invoke("What are the latest AI developments?");
385
+ * ```
386
+ *
387
+ * ```typescript
388
+ * // Method 3: Override search parameters per request
389
+ * const result = await llm.invoke("Find recent news about SpaceX", {
390
+ * searchParameters: {
391
+ * mode: "on",
392
+ * max_search_results: 10,
393
+ * sources: [
394
+ * { type: "web", allowed_websites: ["spacex.com", "nasa.gov"] },
395
+ * ],
396
+ * }
397
+ * });
398
+ * ```
399
+ * </details>
400
+ *
401
+ * <br />
402
+ */
403
+ var ChatXAI = class extends __langchain_openai.ChatOpenAICompletions {
404
+ static lc_name() {
405
+ return "ChatXAI";
406
+ }
407
+ _llmType() {
408
+ return "xai";
409
+ }
410
+ get lc_secrets() {
411
+ return { apiKey: "XAI_API_KEY" };
412
+ }
413
+ lc_serializable = true;
414
+ lc_namespace = [
415
+ "langchain",
416
+ "chat_models",
417
+ "xai"
418
+ ];
419
+ /**
420
+ * Default search parameters for the Live Search API.
421
+ */
422
+ searchParameters;
423
+ constructor(fields) {
424
+ const apiKey = fields?.apiKey || (0, __langchain_core_utils_env.getEnvironmentVariable)("XAI_API_KEY");
425
+ if (!apiKey) throw new Error(`xAI API key not found. Please set the XAI_API_KEY environment variable or provide the key into "apiKey" field.`);
426
+ super({
427
+ ...fields,
428
+ model: fields?.model || "grok-beta",
429
+ apiKey,
430
+ configuration: { baseURL: fields?.baseURL ?? "https://api.x.ai/v1" }
431
+ });
432
+ this.searchParameters = fields?.searchParameters;
433
+ }
434
+ toJSON() {
435
+ const result = super.toJSON();
436
+ if ("kwargs" in result && typeof result.kwargs === "object" && result.kwargs != null) {
437
+ delete result.kwargs.openai_api_key;
438
+ delete result.kwargs.configuration;
439
+ }
440
+ return result;
441
+ }
442
+ getLsParams(options) {
443
+ const params = super.getLsParams(options);
444
+ params.ls_provider = "xai";
445
+ return params;
446
+ }
447
+ /**
448
+ * Get the effective search parameters, merging defaults with call options.
449
+ * @param options Call options that may contain search parameters
450
+ * @returns Merged search parameters or undefined if none are configured
451
+ */
452
+ _getEffectiveSearchParameters(options) {
453
+ return require_live_search.mergeSearchParams(this.searchParameters, options?.searchParameters);
454
+ }
455
+ /**
456
+ * Check if any built-in tools (like live_search) are in the tools list.
457
+ * @param tools List of tools to check
458
+ * @returns true if any built-in tools are present
459
+ */
460
+ _hasBuiltInTools(tools) {
461
+ return tools?.some(isXAIBuiltInTool) ?? false;
462
+ }
463
+ /**
464
+ * Formats tools to xAI/OpenAI format, preserving provider-specific definitions.
465
+ *
466
+ * @param tools The tools to format
467
+ * @returns The formatted tools
468
+ */
469
+ formatStructuredToolToXAI(tools) {
470
+ if (!tools || !tools.length) return void 0;
471
+ return tools.map((tool) => {
472
+ if ((0, __langchain_core_utils_function_calling.isLangChainTool)(tool) && tool.extras?.providerToolDefinition) return tool.extras.providerToolDefinition;
473
+ if (isXAIBuiltInTool(tool)) return tool;
474
+ return (0, __langchain_core_utils_function_calling.convertToOpenAITool)(tool);
475
+ });
476
+ }
477
+ bindTools(tools, kwargs) {
478
+ return this.withConfig({
479
+ tools: this.formatStructuredToolToXAI(tools),
480
+ ...kwargs
481
+ });
482
+ }
483
+ /** @internal */
484
+ invocationParams(options, extra) {
485
+ const baseParams = super.invocationParams(options, extra);
486
+ const params = { ...baseParams };
487
+ const liveSearchTool = options?.tools?.find(isXAIBuiltInTool);
488
+ const mergedSearchParams = require_live_search.mergeSearchParams(this.searchParameters, options?.searchParameters, liveSearchTool);
489
+ if (mergedSearchParams) params.search_parameters = require_live_search.buildSearchParametersPayload(mergedSearchParams);
490
+ return params;
491
+ }
492
+ /**
493
+ * Calls the xAI API with retry logic in case of failures.
494
+ * @param request The request to send to the xAI API.
495
+ * @param options Optional configuration for the API call.
496
+ * @returns The response from the xAI API.
497
+ */
498
+ async completionWithRetry(request, options) {
499
+ delete request.frequency_penalty;
500
+ delete request.presence_penalty;
501
+ delete request.logit_bias;
502
+ delete request.functions;
503
+ const newRequestMessages = request.messages.map((msg) => {
504
+ if (!msg.content) return {
505
+ ...msg,
506
+ content: ""
507
+ };
508
+ return msg;
509
+ });
510
+ let filteredTools;
511
+ if (request.tools) filteredTools = require_live_search.filterXAIBuiltInTools({
512
+ tools: request.tools,
513
+ excludedTypes: [require_live_search$1.XAI_LIVE_SEARCH_TOOL_TYPE]
514
+ });
515
+ const newRequest = {
516
+ ...request,
517
+ messages: newRequestMessages,
518
+ tools: filteredTools
519
+ };
520
+ if (newRequest.stream === true) return super.completionWithRetry(newRequest, options);
521
+ return super.completionWithRetry(newRequest, options);
522
+ }
523
+ _convertCompletionsDeltaToBaseMessageChunk(delta, rawResponse, defaultRole) {
524
+ const messageChunk = super._convertCompletionsDeltaToBaseMessageChunk(delta, rawResponse, defaultRole);
525
+ const responseMetadata = messageChunk.response_metadata;
526
+ if (!rawResponse.choices[0]?.finish_reason) {
527
+ delete responseMetadata.usage;
528
+ delete messageChunk.usage_metadata;
529
+ } else messageChunk.usage_metadata = responseMetadata.usage;
530
+ return messageChunk;
531
+ }
532
+ _convertCompletionsMessageToBaseMessage(message, rawResponse) {
533
+ const langChainMessage = super._convertCompletionsMessageToBaseMessage(message, rawResponse);
534
+ const additionalKwargs = langChainMessage.additional_kwargs;
535
+ additionalKwargs.reasoning_content = message.reasoning_content;
536
+ return langChainMessage;
537
+ }
538
+ /**
539
+ * Return profiling information for the model.
540
+ *
541
+ * Provides information about the model's capabilities and constraints,
542
+ * including token limits, multimodal support, and advanced features like
543
+ * tool calling and structured output.
544
+ *
545
+ * @returns {ModelProfile} An object describing the model's capabilities and constraints
546
+ *
547
+ * @example
548
+ * ```typescript
549
+ * const model = new ChatXAI({ model: "grok-beta" });
550
+ * const profile = model.profile;
551
+ * console.log(profile.maxInputTokens); // 128000
552
+ * console.log(profile.imageInputs); // true
553
+ * ```
554
+ */
555
+ get profile() {
556
+ return require_profiles.default[this.model] ?? {};
557
+ }
558
+ withStructuredOutput(outputSchema, config) {
559
+ const ensuredConfig = { ...config };
560
+ if (ensuredConfig?.method === void 0) ensuredConfig.method = "functionCalling";
561
+ return super.withStructuredOutput(outputSchema, ensuredConfig);
562
+ }
563
+ };
564
+
565
+ //#endregion
566
+ exports.ChatXAI = ChatXAI;
567
+ exports.isXAIBuiltInTool = isXAIBuiltInTool;
568
+ //# sourceMappingURL=completions.cjs.map