@nocobase/plugin-ai 2.2.0-beta.7 → 2.2.0-beta.9
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/dist/ai/docs/nocobase/api/app/env.md +28 -1
- package/dist/ai/docs/nocobase/api/cli/config/delete.md +9 -6
- package/dist/ai/docs/nocobase/api/cli/config/get.md +8 -6
- package/dist/ai/docs/nocobase/api/cli/config/index.md +40 -26
- package/dist/ai/docs/nocobase/api/cli/config/set.md +15 -8
- package/dist/ai/docs/nocobase/api/cli/env/auth.md +53 -5
- package/dist/ai/docs/nocobase/api/cli/self/check.md +19 -2
- package/dist/ai/docs/nocobase/api/cli/self/index.md +1 -1
- package/dist/ai/docs/nocobase/api/cli/self/update.md +17 -3
- package/dist/ai/docs/nocobase/file-manager/field-attachment.md +6 -0
- package/dist/ai/docs/nocobase/file-manager/file-preview/index.md +3 -12
- package/dist/ai/docs/nocobase/file-manager/storage/aliyun-oss.md +9 -0
- package/dist/ai/docs/nocobase/file-manager/storage/amazon-s3.md +9 -0
- package/dist/ai/docs/nocobase/file-manager/storage/index.md +23 -0
- package/dist/ai/docs/nocobase/file-manager/storage/local.md +9 -0
- package/dist/ai/docs/nocobase/file-manager/storage/migrate-to-s3-pro.md +269 -0
- package/dist/ai/docs/nocobase/file-manager/storage/tencent-cos.md +9 -0
- package/dist/ai/docs/nocobase/get-started/installation/docker-caddy.mdx +175 -0
- package/dist/ai/docs/nocobase/get-started/installation/docker-nginx.mdx +176 -0
- package/dist/ai/docs/nocobase/get-started/installation/docker.mdx +94 -1
- package/dist/ai/docs/nocobase/get-started/installation/env.md +14 -4
- package/dist/ai/docs/nocobase/nocobase-cli/installation/cli.md +2 -0
- package/dist/ai/docs/nocobase/ops-management/version-control/index.md +1 -0
- package/dist/client/559.9f97ebcdb0bd6231.js +10 -0
- package/dist/client/{604.de96f3ec4d471afd.js → 604.89c674f35b52b4ef.js} +1 -1
- package/dist/client/index.js +3 -3
- package/dist/client/llm-providers/mistral/ModelSettings.d.ts +10 -0
- package/dist/client/llm-providers/mistral/index.d.ts +10 -0
- package/dist/client/llm-services/utils.d.ts +5 -0
- package/dist/externalVersion.js +16 -16
- package/dist/locale/en-US.json +1 -0
- package/dist/locale/zh-CN.json +1 -0
- package/dist/node_modules/@langchain/mistralai/LICENSE +21 -0
- package/dist/node_modules/@langchain/mistralai/dist/_virtual/rolldown_runtime.cjs +25 -0
- package/dist/node_modules/@langchain/mistralai/dist/chat_models.cjs +859 -0
- package/dist/node_modules/@langchain/mistralai/dist/chat_models.d.cts +541 -0
- package/dist/node_modules/@langchain/mistralai/dist/chat_models.d.ts +541 -0
- package/dist/node_modules/@langchain/mistralai/dist/chat_models.js +857 -0
- package/dist/node_modules/@langchain/mistralai/dist/embeddings.cjs +140 -0
- package/dist/node_modules/@langchain/mistralai/dist/embeddings.d.cts +116 -0
- package/dist/node_modules/@langchain/mistralai/dist/embeddings.d.ts +116 -0
- package/dist/node_modules/@langchain/mistralai/dist/embeddings.js +139 -0
- package/dist/node_modules/@langchain/mistralai/dist/index.cjs +21 -0
- package/dist/node_modules/@langchain/mistralai/dist/index.d.cts +4 -0
- package/dist/node_modules/@langchain/mistralai/dist/index.d.ts +4 -0
- package/dist/node_modules/@langchain/mistralai/dist/index.js +5 -0
- package/dist/node_modules/@langchain/mistralai/dist/llms.cjs +275 -0
- package/dist/node_modules/@langchain/mistralai/dist/llms.d.cts +147 -0
- package/dist/node_modules/@langchain/mistralai/dist/llms.d.ts +147 -0
- package/dist/node_modules/@langchain/mistralai/dist/llms.js +274 -0
- package/dist/node_modules/@langchain/mistralai/dist/utils.cjs +61 -0
- package/dist/node_modules/@langchain/mistralai/dist/utils.js +59 -0
- package/dist/node_modules/@langchain/mistralai/package.json +1 -0
- package/dist/node_modules/@langchain/xai/dist/index.cjs +2 -2
- package/dist/node_modules/@langchain/xai/package.json +1 -1
- package/dist/node_modules/fs-extra/package.json +1 -1
- package/dist/node_modules/jsonrepair/package.json +1 -1
- package/dist/node_modules/just-bash/package.json +1 -1
- package/dist/node_modules/nodejs-snowflake/package.json +1 -1
- package/dist/node_modules/openai/package.json +1 -1
- package/dist/node_modules/zod/package.json +1 -1
- package/dist/server/ai-employees/ai-employee.js +19 -6
- package/dist/server/ai-employees/checkpoints/cleaner.d.ts +2 -0
- package/dist/server/ai-employees/checkpoints/cleaner.js +11 -1
- package/dist/server/ai-employees/middleware/conversation.d.ts +2 -0
- package/dist/server/ai-employees/middleware/conversation.js +2 -1
- package/dist/server/ai-employees/middleware/index.d.ts +1 -0
- package/dist/server/ai-employees/middleware/index.js +2 -0
- package/dist/server/ai-employees/middleware/tool-call-sanitizer.d.ts +16 -0
- package/dist/server/ai-employees/middleware/tool-call-sanitizer.js +90 -0
- package/dist/server/ai-employees/tool-call-sanitizer.d.ts +26 -0
- package/dist/server/ai-employees/tool-call-sanitizer.js +84 -0
- package/dist/server/ai-employees/utils.d.ts +3 -1
- package/dist/server/ai-employees/utils.js +16 -2
- package/dist/server/llm-providers/mistral.d.ts +62 -0
- package/dist/server/llm-providers/mistral.js +265 -0
- package/dist/server/llm-providers/provider.d.ts +6 -2
- package/dist/server/llm-providers/provider.js +27 -14
- package/dist/server/plugin.js +2 -0
- package/dist/server/workflow/nodes/employee/index.js +92 -46
- package/dist/server/workflow/nodes/employee/tools.js +8 -1
- package/package.json +3 -2
- package/dist/client/559.a0f2f1cc2be3c039.js +0 -10
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import { HTTPClient } from "@mistralai/mistralai/lib/http.js";
|
|
2
|
+
import { GenerationChunk } from "@langchain/core/outputs";
|
|
3
|
+
import { AsyncCaller } from "@langchain/core/utils/async_caller";
|
|
4
|
+
import { getEnvironmentVariable } from "@langchain/core/utils/env";
|
|
5
|
+
import { chunkArray } from "@langchain/core/utils/chunk_array";
|
|
6
|
+
import { LLM } from "@langchain/core/language_models/llms";
|
|
7
|
+
|
|
8
|
+
//#region src/llms.ts
|
|
9
|
+
/**
|
|
10
|
+
* MistralAI completions LLM.
|
|
11
|
+
*/
|
|
12
|
+
var MistralAI = class extends LLM {
|
|
13
|
+
static lc_name() {
|
|
14
|
+
return "MistralAI";
|
|
15
|
+
}
|
|
16
|
+
lc_namespace = [
|
|
17
|
+
"langchain",
|
|
18
|
+
"llms",
|
|
19
|
+
"mistralai"
|
|
20
|
+
];
|
|
21
|
+
lc_serializable = true;
|
|
22
|
+
model = "codestral-latest";
|
|
23
|
+
temperature = 0;
|
|
24
|
+
topP;
|
|
25
|
+
maxTokens;
|
|
26
|
+
randomSeed;
|
|
27
|
+
streaming = false;
|
|
28
|
+
batchSize = 20;
|
|
29
|
+
apiKey;
|
|
30
|
+
/**
|
|
31
|
+
* @deprecated use serverURL instead
|
|
32
|
+
*/
|
|
33
|
+
endpoint;
|
|
34
|
+
serverURL;
|
|
35
|
+
maxRetries;
|
|
36
|
+
maxConcurrency;
|
|
37
|
+
beforeRequestHooks;
|
|
38
|
+
requestErrorHooks;
|
|
39
|
+
responseHooks;
|
|
40
|
+
httpClient;
|
|
41
|
+
constructor(fields) {
|
|
42
|
+
super(fields ?? {});
|
|
43
|
+
this.model = fields?.model ?? this.model;
|
|
44
|
+
this.temperature = fields?.temperature ?? this.temperature;
|
|
45
|
+
this.topP = fields?.topP ?? this.topP;
|
|
46
|
+
this.maxTokens = fields?.maxTokens ?? this.maxTokens;
|
|
47
|
+
this.randomSeed = fields?.randomSeed ?? this.randomSeed;
|
|
48
|
+
this.batchSize = fields?.batchSize ?? this.batchSize;
|
|
49
|
+
this.streaming = fields?.streaming ?? this.streaming;
|
|
50
|
+
this.serverURL = fields?.serverURL ?? this.serverURL;
|
|
51
|
+
this.maxRetries = fields?.maxRetries;
|
|
52
|
+
this.maxConcurrency = fields?.maxConcurrency;
|
|
53
|
+
this.beforeRequestHooks = fields?.beforeRequestHooks ?? this.beforeRequestHooks;
|
|
54
|
+
this.requestErrorHooks = fields?.requestErrorHooks ?? this.requestErrorHooks;
|
|
55
|
+
this.responseHooks = fields?.responseHooks ?? this.responseHooks;
|
|
56
|
+
this.httpClient = fields?.httpClient ?? this.httpClient;
|
|
57
|
+
const apiKey = fields?.apiKey ?? getEnvironmentVariable("MISTRAL_API_KEY");
|
|
58
|
+
if (!apiKey) throw new Error(`MistralAI requires an API key to be set.
|
|
59
|
+
Either provide one via the "apiKey" field in the constructor, or set the "MISTRAL_API_KEY" environment variable.`);
|
|
60
|
+
this.apiKey = apiKey;
|
|
61
|
+
this.addAllHooksToHttpClient();
|
|
62
|
+
}
|
|
63
|
+
get lc_secrets() {
|
|
64
|
+
return { apiKey: "MISTRAL_API_KEY" };
|
|
65
|
+
}
|
|
66
|
+
get lc_aliases() {
|
|
67
|
+
return { apiKey: "mistral_api_key" };
|
|
68
|
+
}
|
|
69
|
+
_llmType() {
|
|
70
|
+
return "mistralai";
|
|
71
|
+
}
|
|
72
|
+
invocationParams(options) {
|
|
73
|
+
return {
|
|
74
|
+
model: this.model,
|
|
75
|
+
suffix: options.suffix,
|
|
76
|
+
temperature: this.temperature,
|
|
77
|
+
maxTokens: this.maxTokens,
|
|
78
|
+
topP: this.topP,
|
|
79
|
+
randomSeed: this.randomSeed,
|
|
80
|
+
stop: options.stop
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* For some given input string and options, return a string output.
|
|
85
|
+
*
|
|
86
|
+
* Despite the fact that `invoke` is overridden below, we still need this
|
|
87
|
+
* in order to handle public APi calls to `generate()`.
|
|
88
|
+
*/
|
|
89
|
+
async _call(prompt, options) {
|
|
90
|
+
const params = {
|
|
91
|
+
...this.invocationParams(options),
|
|
92
|
+
prompt
|
|
93
|
+
};
|
|
94
|
+
const result = await this.completionWithRetry(params, options, false);
|
|
95
|
+
let content = result?.choices?.[0].message.content ?? "";
|
|
96
|
+
if (Array.isArray(content)) content = content[0].type === "text" ? content[0].text : "";
|
|
97
|
+
return content;
|
|
98
|
+
}
|
|
99
|
+
async _generate(prompts, options, runManager) {
|
|
100
|
+
const subPrompts = chunkArray(prompts, this.batchSize);
|
|
101
|
+
const choices = [];
|
|
102
|
+
const params = this.invocationParams(options);
|
|
103
|
+
for (let i = 0; i < subPrompts.length; i += 1) {
|
|
104
|
+
const data = await (async () => {
|
|
105
|
+
if (this.streaming) {
|
|
106
|
+
const responseData = [];
|
|
107
|
+
for (let x = 0; x < subPrompts[i].length; x += 1) {
|
|
108
|
+
const choices$1 = [];
|
|
109
|
+
let response;
|
|
110
|
+
const stream = await this.completionWithRetry({
|
|
111
|
+
...params,
|
|
112
|
+
prompt: subPrompts[i][x]
|
|
113
|
+
}, options, true);
|
|
114
|
+
for await (const { data: data$1 } of stream) {
|
|
115
|
+
if (!response) response = {
|
|
116
|
+
id: data$1.id,
|
|
117
|
+
object: "chat.completion",
|
|
118
|
+
created: data$1.created,
|
|
119
|
+
model: data$1.model
|
|
120
|
+
};
|
|
121
|
+
for (const part of data$1.choices) {
|
|
122
|
+
let content = part.delta.content ?? "";
|
|
123
|
+
if (Array.isArray(content)) {
|
|
124
|
+
let strContent = "";
|
|
125
|
+
for (const contentChunk of content) if (contentChunk.type === "text") strContent += contentChunk.text;
|
|
126
|
+
else if (contentChunk.type === "image_url") {
|
|
127
|
+
const imageURL = typeof contentChunk.imageUrl === "string" ? contentChunk.imageUrl : contentChunk.imageUrl.url;
|
|
128
|
+
strContent += imageURL;
|
|
129
|
+
}
|
|
130
|
+
content = strContent;
|
|
131
|
+
}
|
|
132
|
+
if (!choices$1[part.index]) choices$1[part.index] = {
|
|
133
|
+
index: part.index,
|
|
134
|
+
message: {
|
|
135
|
+
role: "assistant",
|
|
136
|
+
content,
|
|
137
|
+
toolCalls: null
|
|
138
|
+
},
|
|
139
|
+
finishReason: part.finishReason ?? "length"
|
|
140
|
+
};
|
|
141
|
+
else {
|
|
142
|
+
const choice = choices$1[part.index];
|
|
143
|
+
choice.message.content += content;
|
|
144
|
+
choice.finishReason = part.finishReason ?? "length";
|
|
145
|
+
}
|
|
146
|
+
runManager?.handleLLMNewToken(content, {
|
|
147
|
+
prompt: part.index,
|
|
148
|
+
completion: part.index
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if (options.signal?.aborted) throw new Error("AbortError");
|
|
153
|
+
responseData.push({
|
|
154
|
+
...response,
|
|
155
|
+
choices: choices$1
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
return responseData;
|
|
159
|
+
} else {
|
|
160
|
+
const responseData = [];
|
|
161
|
+
for (let x = 0; x < subPrompts[i].length; x += 1) {
|
|
162
|
+
const res = await this.completionWithRetry({
|
|
163
|
+
...params,
|
|
164
|
+
prompt: subPrompts[i][x]
|
|
165
|
+
}, options, false);
|
|
166
|
+
responseData.push(res);
|
|
167
|
+
}
|
|
168
|
+
return responseData;
|
|
169
|
+
}
|
|
170
|
+
})();
|
|
171
|
+
choices.push(...data.map((d) => d.choices ?? []));
|
|
172
|
+
}
|
|
173
|
+
const generations = choices.map((promptChoices) => promptChoices.map((choice) => {
|
|
174
|
+
let text = choice.message?.content ?? "";
|
|
175
|
+
if (Array.isArray(text)) text = text[0].type === "text" ? text[0].text : "";
|
|
176
|
+
return {
|
|
177
|
+
text,
|
|
178
|
+
generationInfo: { finishReason: choice.finishReason }
|
|
179
|
+
};
|
|
180
|
+
}));
|
|
181
|
+
return { generations };
|
|
182
|
+
}
|
|
183
|
+
async completionWithRetry(request, options, stream) {
|
|
184
|
+
const { Mistral } = await this.imports();
|
|
185
|
+
const caller = new AsyncCaller({
|
|
186
|
+
maxConcurrency: options.maxConcurrency || this.maxConcurrency,
|
|
187
|
+
maxRetries: this.maxRetries
|
|
188
|
+
});
|
|
189
|
+
const client = new Mistral({
|
|
190
|
+
apiKey: this.apiKey,
|
|
191
|
+
serverURL: this.serverURL,
|
|
192
|
+
timeoutMs: options.timeout,
|
|
193
|
+
...this.httpClient ? { httpClient: this.httpClient } : {}
|
|
194
|
+
});
|
|
195
|
+
return caller.callWithOptions({ signal: options.signal }, async () => {
|
|
196
|
+
try {
|
|
197
|
+
let res;
|
|
198
|
+
if (stream) res = await client.fim.stream(request);
|
|
199
|
+
else res = await client.fim.complete(request);
|
|
200
|
+
return res;
|
|
201
|
+
} catch (e) {
|
|
202
|
+
if (e.message?.includes("status: 400") || e.message?.toLowerCase().includes("status 400") || e.message?.includes("validation failed")) e.status = 400;
|
|
203
|
+
throw e;
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
async *_streamResponseChunks(prompt, options, runManager) {
|
|
208
|
+
const params = {
|
|
209
|
+
...this.invocationParams(options),
|
|
210
|
+
prompt
|
|
211
|
+
};
|
|
212
|
+
const stream = await this.completionWithRetry(params, options, true);
|
|
213
|
+
for await (const message of stream) {
|
|
214
|
+
const { data } = message;
|
|
215
|
+
const choice = data?.choices[0];
|
|
216
|
+
if (!choice) continue;
|
|
217
|
+
let text = choice.delta.content ?? "";
|
|
218
|
+
if (Array.isArray(text)) text = text[0].type === "text" ? text[0].text : "";
|
|
219
|
+
const chunk = new GenerationChunk({
|
|
220
|
+
text,
|
|
221
|
+
generationInfo: {
|
|
222
|
+
finishReason: choice.finishReason,
|
|
223
|
+
tokenUsage: data.usage
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
yield chunk;
|
|
227
|
+
runManager?.handleLLMNewToken(chunk.text ?? "");
|
|
228
|
+
}
|
|
229
|
+
if (options.signal?.aborted) throw new Error("AbortError");
|
|
230
|
+
}
|
|
231
|
+
addAllHooksToHttpClient() {
|
|
232
|
+
try {
|
|
233
|
+
this.removeAllHooksFromHttpClient();
|
|
234
|
+
const hasHooks = [
|
|
235
|
+
this.beforeRequestHooks,
|
|
236
|
+
this.requestErrorHooks,
|
|
237
|
+
this.responseHooks
|
|
238
|
+
].some((hook) => hook && hook.length > 0);
|
|
239
|
+
if (hasHooks && !this.httpClient) this.httpClient = new HTTPClient();
|
|
240
|
+
if (this.beforeRequestHooks) for (const hook of this.beforeRequestHooks) this.httpClient?.addHook("beforeRequest", hook);
|
|
241
|
+
if (this.requestErrorHooks) for (const hook of this.requestErrorHooks) this.httpClient?.addHook("requestError", hook);
|
|
242
|
+
if (this.responseHooks) for (const hook of this.responseHooks) this.httpClient?.addHook("response", hook);
|
|
243
|
+
} catch {
|
|
244
|
+
throw new Error("Error in adding all hooks");
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
removeAllHooksFromHttpClient() {
|
|
248
|
+
try {
|
|
249
|
+
if (this.beforeRequestHooks) for (const hook of this.beforeRequestHooks) this.httpClient?.removeHook("beforeRequest", hook);
|
|
250
|
+
if (this.requestErrorHooks) for (const hook of this.requestErrorHooks) this.httpClient?.removeHook("requestError", hook);
|
|
251
|
+
if (this.responseHooks) for (const hook of this.responseHooks) this.httpClient?.removeHook("response", hook);
|
|
252
|
+
} catch {
|
|
253
|
+
throw new Error("Error in removing hooks");
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
removeHookFromHttpClient(hook) {
|
|
257
|
+
try {
|
|
258
|
+
this.httpClient?.removeHook("beforeRequest", hook);
|
|
259
|
+
this.httpClient?.removeHook("requestError", hook);
|
|
260
|
+
this.httpClient?.removeHook("response", hook);
|
|
261
|
+
} catch {
|
|
262
|
+
throw new Error("Error in removing hook");
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
/** @ignore */
|
|
266
|
+
async imports() {
|
|
267
|
+
const { Mistral } = await import("@mistralai/mistralai");
|
|
268
|
+
return { Mistral };
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
//#endregion
|
|
273
|
+
export { MistralAI };
|
|
274
|
+
//# sourceMappingURL=llms.js.map
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/utils.ts
|
|
3
|
+
const TOOL_CALL_ID_PATTERN = /^[a-zA-Z0-9]{9}$/;
|
|
4
|
+
function _isValidMistralToolCallId(toolCallId) {
|
|
5
|
+
return TOOL_CALL_ID_PATTERN.test(toolCallId);
|
|
6
|
+
}
|
|
7
|
+
function _base62Encode(num) {
|
|
8
|
+
let numCopy = num;
|
|
9
|
+
const base62 = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
10
|
+
if (numCopy === 0) return base62[0];
|
|
11
|
+
const arr = [];
|
|
12
|
+
const base = 62;
|
|
13
|
+
while (numCopy) {
|
|
14
|
+
arr.push(base62[numCopy % base]);
|
|
15
|
+
numCopy = Math.floor(numCopy / base);
|
|
16
|
+
}
|
|
17
|
+
return arr.reverse().join("");
|
|
18
|
+
}
|
|
19
|
+
function _simpleHash(str) {
|
|
20
|
+
let hash = 0;
|
|
21
|
+
for (let i = 0; i < str.length; i += 1) {
|
|
22
|
+
const char = str.charCodeAt(i);
|
|
23
|
+
hash = (hash << 5) - hash + char;
|
|
24
|
+
hash &= hash;
|
|
25
|
+
}
|
|
26
|
+
return Math.abs(hash);
|
|
27
|
+
}
|
|
28
|
+
function _convertToolCallIdToMistralCompatible(toolCallId) {
|
|
29
|
+
if (_isValidMistralToolCallId(toolCallId)) return toolCallId;
|
|
30
|
+
else {
|
|
31
|
+
const hash = _simpleHash(toolCallId);
|
|
32
|
+
const base62Str = _base62Encode(hash);
|
|
33
|
+
if (base62Str.length >= 9) return base62Str.slice(0, 9);
|
|
34
|
+
else return base62Str.padStart(9, "0");
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function _mistralContentChunkToMessageContentComplex(content) {
|
|
38
|
+
if (!content) return "";
|
|
39
|
+
if (typeof content === "string") return content;
|
|
40
|
+
return content.map((contentChunk) => {
|
|
41
|
+
if (contentChunk.type === "image_url") {
|
|
42
|
+
if (typeof contentChunk.imageUrl !== "string" && contentChunk.imageUrl?.detail) {
|
|
43
|
+
const { detail } = contentChunk.imageUrl;
|
|
44
|
+
if (detail !== "high" && detail !== "auto" && detail !== "low") return {
|
|
45
|
+
type: contentChunk.type,
|
|
46
|
+
image_url: { url: contentChunk.imageUrl.url }
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
type: contentChunk.type,
|
|
51
|
+
image_url: contentChunk.imageUrl
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
return contentChunk;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
//#endregion
|
|
59
|
+
exports._convertToolCallIdToMistralCompatible = _convertToolCallIdToMistralCompatible;
|
|
60
|
+
exports._mistralContentChunkToMessageContentComplex = _mistralContentChunkToMessageContentComplex;
|
|
61
|
+
//# sourceMappingURL=utils.cjs.map
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
//#region src/utils.ts
|
|
2
|
+
const TOOL_CALL_ID_PATTERN = /^[a-zA-Z0-9]{9}$/;
|
|
3
|
+
function _isValidMistralToolCallId(toolCallId) {
|
|
4
|
+
return TOOL_CALL_ID_PATTERN.test(toolCallId);
|
|
5
|
+
}
|
|
6
|
+
function _base62Encode(num) {
|
|
7
|
+
let numCopy = num;
|
|
8
|
+
const base62 = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
9
|
+
if (numCopy === 0) return base62[0];
|
|
10
|
+
const arr = [];
|
|
11
|
+
const base = 62;
|
|
12
|
+
while (numCopy) {
|
|
13
|
+
arr.push(base62[numCopy % base]);
|
|
14
|
+
numCopy = Math.floor(numCopy / base);
|
|
15
|
+
}
|
|
16
|
+
return arr.reverse().join("");
|
|
17
|
+
}
|
|
18
|
+
function _simpleHash(str) {
|
|
19
|
+
let hash = 0;
|
|
20
|
+
for (let i = 0; i < str.length; i += 1) {
|
|
21
|
+
const char = str.charCodeAt(i);
|
|
22
|
+
hash = (hash << 5) - hash + char;
|
|
23
|
+
hash &= hash;
|
|
24
|
+
}
|
|
25
|
+
return Math.abs(hash);
|
|
26
|
+
}
|
|
27
|
+
function _convertToolCallIdToMistralCompatible(toolCallId) {
|
|
28
|
+
if (_isValidMistralToolCallId(toolCallId)) return toolCallId;
|
|
29
|
+
else {
|
|
30
|
+
const hash = _simpleHash(toolCallId);
|
|
31
|
+
const base62Str = _base62Encode(hash);
|
|
32
|
+
if (base62Str.length >= 9) return base62Str.slice(0, 9);
|
|
33
|
+
else return base62Str.padStart(9, "0");
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function _mistralContentChunkToMessageContentComplex(content) {
|
|
37
|
+
if (!content) return "";
|
|
38
|
+
if (typeof content === "string") return content;
|
|
39
|
+
return content.map((contentChunk) => {
|
|
40
|
+
if (contentChunk.type === "image_url") {
|
|
41
|
+
if (typeof contentChunk.imageUrl !== "string" && contentChunk.imageUrl?.detail) {
|
|
42
|
+
const { detail } = contentChunk.imageUrl;
|
|
43
|
+
if (detail !== "high" && detail !== "auto" && detail !== "low") return {
|
|
44
|
+
type: contentChunk.type,
|
|
45
|
+
image_url: { url: contentChunk.imageUrl.url }
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
type: contentChunk.type,
|
|
50
|
+
image_url: contentChunk.imageUrl
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
return contentChunk;
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
//#endregion
|
|
58
|
+
export { _convertToolCallIdToMistralCompatible, _mistralContentChunkToMessageContentComplex };
|
|
59
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"name":"@langchain/mistralai","version":"1.0.0","description":"MistralAI integration for LangChain.js","author":"LangChain","license":"MIT","type":"module","engines":{"node":">=20"},"repository":{"type":"git","url":"git@github.com:langchain-ai/langchainjs.git"},"homepage":"https://github.com/langchain-ai/langchainjs/tree/main/libs/langchain-mistralai/","dependencies":{"@mistralai/mistralai":"^1.3.1","uuid":"^10.0.0"},"peerDependencies":{"@langchain/core":"^1.0.0"},"devDependencies":{"@tsconfig/recommended":"^1.0.3","@vitest/coverage-v8":"^3.2.4","dotenv":"^16.3.1","dpdm":"^3.14.0","eslint":"^9.34.0","prettier":"^2.8.3","rollup":"^4.5.2","typescript":"~5.8.3","vitest":"^3.2.4","zod":"^3.25.76","@langchain/eslint":"0.1.0","@langchain/standard-tests":"0.0.0","@langchain/core":"1.0.1"},"publishConfig":{"access":"public"},"main":"dist/index.js","types":"dist/index.d.ts","exports":{".":{"input":"./src/index.ts","import":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"require":{"types":"./dist/index.d.cts","default":"./dist/index.cjs"}},"./package.json":"./package.json"},"files":["dist/","CHANGELOG.md","README.md","LICENSE"],"scripts":{"build":"pnpm --filter @langchain/build compile @langchain/mistralai","lint:eslint":"eslint --cache src/","lint:dpdm":"dpdm --skip-dynamic-imports circular --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts","lint":"pnpm lint:eslint && pnpm lint:dpdm","lint:fix":"pnpm lint:eslint --fix && pnpm lint:dpdm","clean":"rm -rf .turbo dist/","test":"vitest run","test:watch":"vitest","test:int":"vitest run --mode int","test:standard:unit":"vitest run --mode standard-unit","test:standard:int":"vitest run --mode standard-int","test:standard":"pnpm test:standard:unit && pnpm test:standard:int","format":"prettier --config .prettierrc --write \"src\"","format:check":"prettier --config .prettierrc --check \"src\""},"_lastModified":"2026-07-06T02:56:42.312Z"}
|