@roomle/embedding-lib 9.0.0-alpha.1 → 9.0.0-alpha.11

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/THIRD-PARTY-NOTICES.txt +764 -0
  2. package/{browser-BxG7yIaK.mjs → browser-D6As4Zxr.mjs} +1 -0
  3. package/{browser-CW9o-dtT.mjs → browser-zrjtYpL8.mjs} +1 -0
  4. package/coerce-CqJod_GZ.mjs +8 -0
  5. package/coerce-CsI42_k0.mjs +6 -0
  6. package/{comlink-B5lV2OWp.mjs → comlink-Cmiqa2s0.mjs} +1 -0
  7. package/{comlink-B2Kj_5Ge.mjs → comlink-Dc3LZUoi.mjs} +1 -0
  8. package/configurator.d.ts +2 -0
  9. package/configurator.js +29 -0
  10. package/configurator.min.js +27 -0
  11. package/dist-5jYYtT4q.mjs +8216 -0
  12. package/dist-B9yy8ym8.mjs +5512 -0
  13. package/dist-BV-32IEX.mjs +8128 -0
  14. package/dist-Bb2L1Zel.mjs +6045 -0
  15. package/dist-Bo3WzRdf.mjs +6223 -0
  16. package/dist-Bt1FopV4.mjs +7594 -0
  17. package/dist-C5fKJXpB.mjs +5598 -0
  18. package/dist-COgAdYY1.mjs +7554 -0
  19. package/dist-CXemOs84.mjs +849 -0
  20. package/dist-CqP0aX0A.mjs +866 -0
  21. package/dist-CqpDM10w.mjs +1179 -0
  22. package/dist-D0kh4WfT.mjs +7721 -0
  23. package/dist-D5HdKuwj.mjs +1221 -0
  24. package/dist-DJtonrDM.mjs +16906 -0
  25. package/dist-GTk8ppiK.mjs +8380 -0
  26. package/dist-XEy6Tk_Y.mjs +17341 -0
  27. package/docs/md/web/embedding/CHANGELOG.md +284 -98
  28. package/{drag-ghost-BQ8r6NVo.mjs → drag-ghost-D7FnWbO4.mjs} +2 -1
  29. package/{drag-ghost-BOwjMbG3.mjs → drag-ghost-yXe7c8jA.mjs} +2 -1
  30. package/{drag-in-QhL3zGC0.mjs → drag-in-BiEe2Lgv.mjs} +15 -20
  31. package/{drag-in-BP_E53zb.mjs → drag-in-t7T6Pqwc.mjs} +10 -15
  32. package/embedding-plugins.js +2 -1
  33. package/embedding-plugins.min.js +2 -1
  34. package/experimental-evaluation-BgWFolud.mjs +1074 -0
  35. package/experimental-evaluation-D56MbtjO.mjs +970 -0
  36. package/{from-custom-view-D2Z1YmCx.mjs → from-custom-view-CTBapIc6.mjs} +31 -30
  37. package/{from-custom-view-BM_zRJCf.mjs → from-custom-view-xbjgsLll.mjs} +32 -31
  38. package/{from-website-CPVeVVMI.mjs → from-website-DUPMQPl6.mjs} +24 -23
  39. package/{from-website-DlklVbxU.mjs → from-website-JwG7Ic_U.mjs} +24 -23
  40. package/hi.js +250 -111
  41. package/hi.min.js +212 -95
  42. package/mcp-tools-CJ7j_FI2.mjs +151 -0
  43. package/mcp-tools-D__M74CZ.mjs +153 -0
  44. package/package.json +12 -1
  45. package/packages/embedding-lib/src/configurator-agent/configurator-mcp-tools.d.ts +4 -0
  46. package/packages/embedding-lib/src/configurator-agent/configurator-planning-assistant.d.ts +13 -0
  47. package/packages/embedding-lib/src/configurator.d.ts +3 -0
  48. package/packages/embedding-lib/src/hi.d.ts +1 -3
  49. package/packages/embedding-lib/src/homag-intelligence/hi-mcp-tools.d.ts +11 -11
  50. package/packages/embedding-lib/src/homag-intelligence/hi-planning-assistant.d.ts +11 -34
  51. package/packages/embedding-lib/src/homag-intelligence/hi-planning-usage.d.ts +54 -0
  52. package/packages/embedding-lib/src/planning-assistant/chat-model.d.ts +1 -0
  53. package/packages/embedding-lib/src/planning-assistant/mcp-tools.d.ts +2 -0
  54. package/packages/web-sdk/packages/assistant.d.ts +3 -0
  55. package/packages/web-sdk/packages/common-core/src/agent-tools/mcp-tool-types.d.ts +30 -0
  56. package/packages/web-sdk/packages/common-core/src/planning-assistant/chat-model.d.ts +8 -0
  57. package/packages/{embedding-lib/src/homag-intelligence/hi-mcp/mcp-tool-types.d.ts → web-sdk/packages/common-core/src/planning-assistant/mcp-tools.d.ts} +15 -20
  58. package/packages/web-sdk/packages/common-core/src/planning-assistant/types.d.ts +35 -0
  59. package/roomle-embedding-lib.js +67 -57
  60. package/roomle-embedding-lib.min.js +13 -3
  61. package/sbom.cdx.json +405 -0
  62. package/{utils-wJ80awOA.mjs → utils-CAAGdgk8.mjs} +1 -0
  63. package/{utils-DxJ3PcKe.mjs → utils-WeolMfC5.mjs} +1 -0
  64. package/hi-mcp-server-BiZlFkBm.mjs +0 -4866
  65. package/hi-mcp-server-DTQnrykg.mjs +0 -5278
  66. package/packages/embedding-lib/src/homag-intelligence/hi-mcp/agent-facing.d.ts +0 -35
  67. package/packages/embedding-lib/src/homag-intelligence/hi-mcp/hi-mcp-server.d.ts +0 -3
  68. package/packages/embedding-lib/src/homag-intelligence/hi-mcp/mcp-tool.d.ts +0 -13
  69. package/packages/embedding-lib/src/homag-intelligence/hi-mcp/plan-history.d.ts +0 -33
  70. package/packages/embedding-lib/src/homag-intelligence/hi-mcp/planner-api.d.ts +0 -32
  71. package/packages/embedding-lib/src/homag-intelligence/hi-mcp/skills.d.ts +0 -23
  72. package/packages/embedding-lib/src/homag-intelligence/hi-mcp/tool-executors.d.ts +0 -4
@@ -0,0 +1,849 @@
1
+
2
+ import { $t as e, Bt as t, D as n, Dn as r, E as i, H as a, Ht as o, Jt as s, K as c, O as l, Rt as u, S as d, St as f, Tt as p, Vt as m, Wt as h, X as g, Yt as _, Zt as v, _ as y, _t as b, an as x, bn as S, bt as C, dn as w, dt as T, f as E, ft as ee, h as D, in as O, jn as k, jt as A, kn as j, ln as M, o as N, ot as P, q as F, qt as te, sn as ne, st as re, tn as I, w as ie, yt as ae, zt as L } from "./dist-Bt1FopV4.mjs";
3
+ var R = x({
4
+ messages: s(e()).nullish(),
5
+ cached_tokens: O().nullish(),
6
+ audio_tokens: O().nullish()
7
+ }).catchall(e()), z = x({ reasoning_tokens: O().nullish() }).catchall(e()), B = x({
8
+ prompt_tokens: O(),
9
+ completion_tokens: O(),
10
+ total_tokens: O(),
11
+ prompt_audio_seconds: O().nullish(),
12
+ request_count: O().nullish(),
13
+ service_tier: M().nullish(),
14
+ num_cached_tokens: O().nullish(),
15
+ prompt_tokens_details: R.nullish(),
16
+ prompt_token_details: R.nullish(),
17
+ completion_tokens_details: z.nullish()
18
+ }).catchall(e());
19
+ function V(e) {
20
+ if (e == null) return l();
21
+ let t = e.prompt_tokens, n = e.completion_tokens, r = e.num_cached_tokens ?? e.prompt_tokens_details?.cached_tokens ?? e.prompt_token_details?.cached_tokens ?? 0;
22
+ return {
23
+ inputTokens: {
24
+ total: t,
25
+ noCache: t - r,
26
+ cacheRead: r || void 0,
27
+ cacheWrite: void 0
28
+ },
29
+ outputTokens: {
30
+ total: n,
31
+ text: n,
32
+ reasoning: void 0
33
+ },
34
+ raw: e
35
+ };
36
+ }
37
+ function H({ part: e }) {
38
+ if (e.data.type === "url") return e.data.url.toString();
39
+ if (e.data.type === "data") return `data:${p({ part: e })};base64,${y(e.data.data)}`;
40
+ throw new k({ functionality: `file part data type ${e.data.type}` });
41
+ }
42
+ function U(e) {
43
+ let t = [];
44
+ for (let n = 0; n < e.length; n++) {
45
+ let { role: r, content: i } = e[n], a = n === e.length - 1;
46
+ switch (r) {
47
+ case "system":
48
+ t.push({
49
+ role: "system",
50
+ content: i
51
+ });
52
+ break;
53
+ case "user":
54
+ t.push({
55
+ role: "user",
56
+ content: i.map((e) => {
57
+ switch (e.type) {
58
+ case "text": return {
59
+ type: "text",
60
+ text: e.text
61
+ };
62
+ case "file": switch (e.data.type) {
63
+ case "reference": throw new k({ functionality: "file parts with provider references" });
64
+ case "text": throw new k({ functionality: "text file parts" });
65
+ case "url":
66
+ case "data":
67
+ if (c(e.mediaType) === "image") return {
68
+ type: "image_url",
69
+ image_url: H({ part: e })
70
+ };
71
+ if (e.data.type === "data") {
72
+ if (p({ part: e }) !== "application/pdf") throw new k({ functionality: "Only images and PDF file parts are supported" });
73
+ } else if (e.mediaType !== "application/pdf") throw new k({ functionality: "Only images and PDF file parts are supported" });
74
+ return {
75
+ type: "document_url",
76
+ document_url: H({ part: e })
77
+ };
78
+ }
79
+ }
80
+ })
81
+ });
82
+ break;
83
+ case "assistant": {
84
+ let e = "", n = !1, r = [], o = [];
85
+ for (let t of i) switch (t.type) {
86
+ case "text":
87
+ e += t.text, r.push({
88
+ type: "text",
89
+ text: t.text
90
+ });
91
+ break;
92
+ case "tool-call":
93
+ o.push({
94
+ id: t.toolCallId,
95
+ type: "function",
96
+ function: {
97
+ name: t.toolName,
98
+ arguments: JSON.stringify(t.input)
99
+ }
100
+ });
101
+ break;
102
+ case "reasoning":
103
+ n = !0, r.push({
104
+ type: "thinking",
105
+ thinking: [{
106
+ type: "text",
107
+ text: t.text
108
+ }],
109
+ closed: !0
110
+ });
111
+ break;
112
+ default: throw Error(`Unsupported content type in assistant message: ${t.type}`);
113
+ }
114
+ t.push({
115
+ role: "assistant",
116
+ content: n ? r : e,
117
+ prefix: !!a || void 0,
118
+ tool_calls: o.length > 0 ? o : void 0
119
+ });
120
+ break;
121
+ }
122
+ case "tool":
123
+ for (let e of i) {
124
+ if (e.type === "tool-approval-response") continue;
125
+ let n = e.output, r;
126
+ switch (n.type) {
127
+ case "text":
128
+ case "error-text":
129
+ r = n.value;
130
+ break;
131
+ case "execution-denied":
132
+ r = n.reason ?? "Tool call execution denied.";
133
+ break;
134
+ case "content":
135
+ case "json":
136
+ case "error-json": r = JSON.stringify(n.value);
137
+ }
138
+ t.push({
139
+ role: "tool",
140
+ name: e.toolName,
141
+ tool_call_id: e.toolCallId,
142
+ content: r
143
+ });
144
+ }
145
+ break;
146
+ default: throw Error(`Unsupported role: ${r}`);
147
+ }
148
+ }
149
+ return t;
150
+ }
151
+ function W(e) {
152
+ switch (e) {
153
+ case "stop": return "stop";
154
+ case "length":
155
+ case "model_length": return "length";
156
+ case "tool_calls": return "tool-calls";
157
+ default: return "other";
158
+ }
159
+ }
160
+ var G = x({
161
+ safePrompt: _().optional(),
162
+ documentImageLimit: O().optional(),
163
+ documentPageLimit: O().optional(),
164
+ structuredOutputs: _().optional(),
165
+ strictJsonSchema: _().optional(),
166
+ parallelToolCalls: _().optional(),
167
+ promptCacheKey: M().optional(),
168
+ reasoningEffort: h(["high", "none"]).optional()
169
+ }), K = ie({
170
+ errorSchema: x({
171
+ object: I("error"),
172
+ message: M(),
173
+ type: M(),
174
+ param: M().nullable(),
175
+ code: M().nullable()
176
+ }),
177
+ errorToMessage: (e) => e.message
178
+ }), q = new Set([
179
+ "glm-5-2",
180
+ "labs-leanstral-1-5",
181
+ "labs-leanstral-1-5-1",
182
+ "magistral-medium-latest",
183
+ "magistral-small-latest",
184
+ "mistral-medium",
185
+ "mistral-medium-2604",
186
+ "mistral-medium-3",
187
+ "mistral-medium-3-5",
188
+ "mistral-medium-3.5",
189
+ "mistral-medium-latest",
190
+ "mistral-small-2603",
191
+ "mistral-small-latest",
192
+ "mistral-vibe-cli-fast",
193
+ "mistral-vibe-cli-latest",
194
+ "mistral-vibe-cli-with-tools",
195
+ "zai-glm-5-2"
196
+ ]), oe = class e {
197
+ constructor(e, t) {
198
+ this.specificationVersion = "v4", this.supportedUrls = { "application/pdf": [/^https:\/\/.*$/] }, this.modelId = e, this.config = t, this.generateId = t.generateId ?? a;
199
+ }
200
+ static [o](e) {
201
+ return A({
202
+ modelId: e.modelId,
203
+ config: e.config
204
+ });
205
+ }
206
+ static [m](t) {
207
+ return new e(t.modelId, t.config);
208
+ }
209
+ get provider() {
210
+ return this.config.provider;
211
+ }
212
+ async getArgs({ prompt: e, maxOutputTokens: t, temperature: n, topP: r, topK: i, frequencyPenalty: a, presencePenalty: o, reasoning: s, stopSequences: c, responseFormat: l, seed: u, providerOptions: d, tools: f, toolChoice: p }) {
213
+ let m = [], h = await b({
214
+ provider: "mistral",
215
+ providerOptions: d,
216
+ schema: G
217
+ }) ?? {}, _;
218
+ i != null && m.push({
219
+ type: "unsupported",
220
+ feature: "topK"
221
+ }), q.has(this.modelId) ? _ = h.reasoningEffort ?? (g(s) ? s === "none" ? "none" : T({
222
+ reasoning: s,
223
+ effortMap: {
224
+ minimal: "high",
225
+ low: "high",
226
+ medium: "high",
227
+ high: "high",
228
+ xhigh: "high"
229
+ },
230
+ warnings: m
231
+ }) : void 0) : g(s) && m.push({
232
+ type: "unsupported",
233
+ feature: "reasoning",
234
+ details: "This model does not support reasoning configuration."
235
+ });
236
+ let v = h.structuredOutputs ?? !0, y = h.strictJsonSchema ?? !1;
237
+ l?.type !== "json" || l?.schema || (e = F({
238
+ messages: e,
239
+ schema: l.schema
240
+ }));
241
+ let x = {
242
+ model: this.modelId,
243
+ safe_prompt: h.safePrompt,
244
+ max_tokens: t,
245
+ temperature: n,
246
+ top_p: r,
247
+ ...a == null ? {} : { frequency_penalty: a },
248
+ ...o == null ? {} : { presence_penalty: o },
249
+ stop: c,
250
+ random_seed: u,
251
+ reasoning_effort: _,
252
+ response_format: l?.type === "json" ? v && l?.schema != null ? {
253
+ type: "json_schema",
254
+ json_schema: {
255
+ schema: l.schema,
256
+ strict: y,
257
+ name: l.name ?? "response",
258
+ description: l.description
259
+ }
260
+ } : { type: "json_object" } : void 0,
261
+ document_image_limit: h.documentImageLimit,
262
+ document_page_limit: h.documentPageLimit,
263
+ ...h.promptCacheKey === void 0 ? {} : { prompt_cache_key: h.promptCacheKey },
264
+ messages: U(e)
265
+ }, { tools: S, toolChoice: C, toolWarnings: w } = function({ tools: e, toolChoice: t }) {
266
+ let n = [];
267
+ if ((e = e?.length ? e : void 0) == null) return {
268
+ tools: void 0,
269
+ toolChoice: void 0,
270
+ toolWarnings: n
271
+ };
272
+ let r = [];
273
+ for (let t of e) t.type === "provider" ? n.push({
274
+ type: "unsupported",
275
+ feature: `provider-defined tool ${t.id}`
276
+ }) : r.push({
277
+ type: "function",
278
+ function: {
279
+ name: t.name,
280
+ description: t.description,
281
+ parameters: t.inputSchema,
282
+ ...t.strict == null ? {} : { strict: t.strict }
283
+ }
284
+ });
285
+ if (t == null) return {
286
+ tools: r,
287
+ toolChoice: void 0,
288
+ toolWarnings: n
289
+ };
290
+ let i = t.type;
291
+ switch (i) {
292
+ case "auto":
293
+ case "none": return {
294
+ tools: r,
295
+ toolChoice: i,
296
+ toolWarnings: n
297
+ };
298
+ case "required": return {
299
+ tools: r,
300
+ toolChoice: "any",
301
+ toolWarnings: n
302
+ };
303
+ case "tool": return {
304
+ tools: r.filter((e) => e.function.name === t.toolName),
305
+ toolChoice: "any",
306
+ toolWarnings: n
307
+ };
308
+ default: throw new k({ functionality: `tool choice type: ${i}` });
309
+ }
310
+ }({
311
+ tools: f,
312
+ toolChoice: p
313
+ });
314
+ return {
315
+ args: {
316
+ ...x,
317
+ tools: S,
318
+ tool_choice: C,
319
+ ...S != null && h.parallelToolCalls !== void 0 ? { parallel_tool_calls: h.parallelToolCalls } : {}
320
+ },
321
+ warnings: [...m, ...w]
322
+ };
323
+ }
324
+ async doGenerate(e) {
325
+ let { args: t, warnings: r } = await this.getArgs(e), { responseHeaders: a, value: o, rawValue: s } = await C({
326
+ url: `${this.config.baseURL}/chat/completions`,
327
+ headers: E(this.config.headers?.(), e.headers),
328
+ body: t,
329
+ failedResponseHandler: K,
330
+ successfulResponseHandler: i(se),
331
+ abortSignal: e.abortSignal,
332
+ fetch: this.config.fetch
333
+ }), c = o.choices[0], l = [];
334
+ if (c.message.content != null && Array.isArray(c.message.content)) for (let e of c.message.content) if (e.type === "thinking") {
335
+ let t = J(e.thinking);
336
+ t.length > 0 && l.push({
337
+ type: "reasoning",
338
+ text: t
339
+ });
340
+ } else e.type === "text" && e.text.length > 0 && l.push({
341
+ type: "text",
342
+ text: e.text
343
+ });
344
+ else {
345
+ let e = Y(c.message.content);
346
+ e != null && e.length > 0 && l.push({
347
+ type: "text",
348
+ text: e
349
+ });
350
+ }
351
+ if (c.message.tool_calls != null) for (let e of c.message.tool_calls) l.push({
352
+ type: "tool-call",
353
+ toolCallId: e.id,
354
+ toolName: e.function.name,
355
+ input: e.function.arguments
356
+ });
357
+ return {
358
+ content: l,
359
+ finishReason: {
360
+ unified: W(c.finish_reason),
361
+ raw: c.finish_reason ?? void 0
362
+ },
363
+ usage: V(o.usage),
364
+ request: { body: t },
365
+ response: {
366
+ ...n(o),
367
+ headers: a,
368
+ body: s
369
+ },
370
+ warnings: r
371
+ };
372
+ }
373
+ async doStream(e) {
374
+ let { args: t, warnings: r } = await this.getArgs(e), i = {
375
+ ...t,
376
+ stream: !0
377
+ }, { responseHeaders: a, value: o } = await C({
378
+ url: `${this.config.baseURL}/chat/completions`,
379
+ headers: E(this.config.headers?.(), e.headers),
380
+ body: i,
381
+ failedResponseHandler: K,
382
+ successfulResponseHandler: d(ce),
383
+ abortSignal: e.abortSignal,
384
+ fetch: this.config.fetch
385
+ }), s, c, l = {
386
+ unified: "other",
387
+ raw: void 0
388
+ }, u = !0, f = !1, p = null, m = this.generateId;
389
+ return {
390
+ stream: o.pipeThrough(new TransformStream({
391
+ start(e) {
392
+ c = new N(e, { generateId: m }), e.enqueue({
393
+ type: "stream-start",
394
+ warnings: r
395
+ });
396
+ },
397
+ transform(t, r) {
398
+ if (e.includeRawChunks && r.enqueue({
399
+ type: "raw",
400
+ rawValue: t.rawValue
401
+ }), !t.success) return void r.enqueue({
402
+ type: "error",
403
+ error: t.error
404
+ });
405
+ let i = t.value;
406
+ u && (u = !1, r.enqueue({
407
+ type: "response-metadata",
408
+ ...n(i)
409
+ })), i.usage != null && (s = i.usage);
410
+ let a = i.choices[0], o = a.delta, d = Y(o.content);
411
+ if (o.content != null && Array.isArray(o.content)) {
412
+ for (let e of o.content) if (e.type === "thinking") {
413
+ let t = J(e.thinking);
414
+ t.length > 0 && (p ?? (f &&= (r.enqueue({
415
+ type: "text-end",
416
+ id: "0"
417
+ }), !1), p = m(), r.enqueue({
418
+ type: "reasoning-start",
419
+ id: p
420
+ })), r.enqueue({
421
+ type: "reasoning-delta",
422
+ id: p,
423
+ delta: t
424
+ }));
425
+ }
426
+ }
427
+ if (d != null && d.length > 0 && (f ||= (p != null && (r.enqueue({
428
+ type: "reasoning-end",
429
+ id: p
430
+ }), p = null), r.enqueue({
431
+ type: "text-start",
432
+ id: "0"
433
+ }), !0), r.enqueue({
434
+ type: "text-delta",
435
+ id: "0",
436
+ delta: d
437
+ })), o?.tool_calls != null) for (let e of o.tool_calls) c.processDelta(e);
438
+ a.finish_reason != null && (l = {
439
+ unified: W(a.finish_reason),
440
+ raw: a.finish_reason
441
+ });
442
+ },
443
+ flush(e) {
444
+ p != null && e.enqueue({
445
+ type: "reasoning-end",
446
+ id: p
447
+ }), f && e.enqueue({
448
+ type: "text-end",
449
+ id: "0"
450
+ }), c.flush(), e.enqueue({
451
+ type: "finish",
452
+ finishReason: l,
453
+ usage: V(s)
454
+ });
455
+ }
456
+ })),
457
+ request: { body: i },
458
+ response: { headers: a }
459
+ };
460
+ }
461
+ };
462
+ function J(e) {
463
+ return e.filter((e) => e.type === "text").map((e) => e.text).join("");
464
+ }
465
+ function Y(e) {
466
+ if (typeof e == "string") return e;
467
+ if (e == null) return;
468
+ let t = [];
469
+ for (let n of e) {
470
+ let { type: e } = n;
471
+ switch (e) {
472
+ case "text":
473
+ t.push(n.text);
474
+ break;
475
+ case "thinking":
476
+ case "image_url":
477
+ case "reference": break;
478
+ default: throw Error(`Unsupported type: ${e}`);
479
+ }
480
+ }
481
+ return t.length ? t.join("") : void 0;
482
+ }
483
+ var X = w([M(), s(v("type", [
484
+ x({
485
+ type: I("text"),
486
+ text: M()
487
+ }),
488
+ x({
489
+ type: I("image_url"),
490
+ image_url: w([M(), x({
491
+ url: M(),
492
+ detail: M().nullable()
493
+ })])
494
+ }),
495
+ x({
496
+ type: I("reference"),
497
+ reference_ids: s(w([M(), O()]))
498
+ }),
499
+ x({
500
+ type: I("thinking"),
501
+ thinking: s(x({
502
+ type: I("text"),
503
+ text: M()
504
+ }))
505
+ })
506
+ ]))]).nullish(), se = x({
507
+ id: M().nullish(),
508
+ created: O().nullish(),
509
+ model: M().nullish(),
510
+ choices: s(x({
511
+ message: x({
512
+ role: I("assistant"),
513
+ content: X,
514
+ tool_calls: s(x({
515
+ id: M(),
516
+ function: x({
517
+ name: M(),
518
+ arguments: M()
519
+ })
520
+ })).nullish()
521
+ }),
522
+ index: O(),
523
+ finish_reason: M().nullish()
524
+ })),
525
+ object: I("chat.completion"),
526
+ usage: B
527
+ }), ce = x({
528
+ id: M().nullish(),
529
+ created: O().nullish(),
530
+ model: M().nullish(),
531
+ choices: s(x({
532
+ delta: x({
533
+ role: h(["assistant"]).optional(),
534
+ content: X,
535
+ tool_calls: s(x({
536
+ index: O().nullish(),
537
+ id: M().nullish(),
538
+ function: x({
539
+ name: M().nullish(),
540
+ arguments: M().nullish()
541
+ })
542
+ })).nullish()
543
+ }),
544
+ finish_reason: M().nullish(),
545
+ index: O()
546
+ })),
547
+ usage: B.nullish()
548
+ }), le = x({
549
+ metadata: ne(M(), te()).optional(),
550
+ outputDimension: O().int().positive().optional(),
551
+ outputDtype: h([
552
+ "float",
553
+ "int8",
554
+ "uint8",
555
+ "binary",
556
+ "ubinary"
557
+ ]).optional()
558
+ }), ue = class e {
559
+ constructor(e, t) {
560
+ this.specificationVersion = "v4", this.maxEmbeddingsPerCall = 32, this.supportsParallelCalls = !1, this.modelId = e, this.config = t;
561
+ }
562
+ get provider() {
563
+ return this.config.provider;
564
+ }
565
+ static [o](e) {
566
+ return A({
567
+ modelId: e.modelId,
568
+ config: e.config
569
+ });
570
+ }
571
+ static [m](t) {
572
+ return new e(t.modelId, t.config);
573
+ }
574
+ async doEmbed({ values: e, abortSignal: t, headers: n, providerOptions: r }) {
575
+ if (e.length > this.maxEmbeddingsPerCall) throw new j({
576
+ provider: this.provider,
577
+ modelId: this.modelId,
578
+ maxEmbeddingsPerCall: this.maxEmbeddingsPerCall,
579
+ values: e
580
+ });
581
+ let a = await b({
582
+ provider: "mistral",
583
+ providerOptions: r,
584
+ schema: le
585
+ }) ?? {}, { responseHeaders: o, value: s, rawValue: c } = await C({
586
+ url: `${this.config.baseURL}/embeddings`,
587
+ headers: E(this.config.headers?.(), n),
588
+ body: {
589
+ model: this.modelId,
590
+ input: e,
591
+ metadata: a.metadata,
592
+ output_dimension: a.outputDimension,
593
+ output_dtype: a.outputDtype,
594
+ encoding_format: "float"
595
+ },
596
+ failedResponseHandler: K,
597
+ successfulResponseHandler: i(de),
598
+ abortSignal: t,
599
+ fetch: this.config.fetch
600
+ });
601
+ return {
602
+ warnings: [],
603
+ embeddings: s.data.map((e) => e.embedding),
604
+ usage: s.usage ? { tokens: s.usage.prompt_tokens } : void 0,
605
+ response: {
606
+ headers: o,
607
+ body: c
608
+ }
609
+ };
610
+ }
611
+ }, de = x({
612
+ data: s(x({ embedding: s(O()) })),
613
+ usage: x({ prompt_tokens: O() }).nullish()
614
+ }), Z = x({ refAudio: M().min(1).optional() }), fe = class e {
615
+ constructor(e, t) {
616
+ this.modelId = e, this.config = t, this.specificationVersion = "v4";
617
+ }
618
+ static [o](e) {
619
+ return A({
620
+ modelId: e.modelId,
621
+ config: e.config
622
+ });
623
+ }
624
+ static [m](t) {
625
+ return new e(t.modelId, t.config);
626
+ }
627
+ get provider() {
628
+ return this.config.provider;
629
+ }
630
+ async getArgs({ text: e, voice: t, outputFormat: n = "mp3", instructions: r, speed: i, language: a, providerOptions: o }) {
631
+ let s = [], c = await b({
632
+ provider: "mistral",
633
+ providerOptions: o,
634
+ schema: Z
635
+ }), l = "mp3";
636
+ [
637
+ "pcm",
638
+ "wav",
639
+ "mp3",
640
+ "flac",
641
+ "opus"
642
+ ].includes(n) ? l = n : s.push({
643
+ type: "unsupported",
644
+ feature: "outputFormat",
645
+ details: `Unsupported output format: ${n}. Using mp3 instead.`
646
+ }), r != null && s.push({
647
+ type: "unsupported",
648
+ feature: "instructions",
649
+ details: "Mistral speech models do not support the `instructions` option. Use a reference audio clip to guide delivery."
650
+ }), i != null && s.push({
651
+ type: "unsupported",
652
+ feature: "speed",
653
+ details: "Mistral speech models do not support the `speed` option. It was ignored."
654
+ }), a != null && s.push({
655
+ type: "unsupported",
656
+ feature: "language",
657
+ details: "Mistral speech models do not support the `language` option. Language is inferred from the input text and voice."
658
+ });
659
+ let u = c?.refAudio, d = {
660
+ model: this.modelId,
661
+ input: e,
662
+ voice_id: u == null ? t : void 0,
663
+ ref_audio: u,
664
+ response_format: l,
665
+ stream: !1
666
+ };
667
+ return {
668
+ requestBody: d,
669
+ requestBodyValues: {
670
+ ...d,
671
+ ref_audio: u == null ? void 0 : "[redacted]"
672
+ },
673
+ warnings: s
674
+ };
675
+ }
676
+ async doGenerate(e) {
677
+ let t = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date(), { requestBody: n, requestBodyValues: r, warnings: a } = await this.getArgs(e), { value: o, responseHeaders: s, rawValue: c } = await f({
678
+ url: `${this.config.baseURL}/audio/speech`,
679
+ headers: E({ "Content-Type": "application/json" }, this.config.headers?.(), e.headers),
680
+ body: {
681
+ content: JSON.stringify(n),
682
+ values: r
683
+ },
684
+ failedResponseHandler: K,
685
+ successfulResponseHandler: i(pe),
686
+ abortSignal: e.abortSignal,
687
+ fetch: this.config.fetch
688
+ });
689
+ return {
690
+ audio: o.audio_data,
691
+ warnings: a,
692
+ request: { body: JSON.stringify(r) },
693
+ response: {
694
+ timestamp: t,
695
+ modelId: this.modelId,
696
+ headers: s,
697
+ body: c
698
+ }
699
+ };
700
+ }
701
+ }, pe = x({ audio_data: M() }), me = P(() => t(x({
702
+ language: M().min(1).optional(),
703
+ temperature: O().optional(),
704
+ timestampGranularities: s(h(["segment", "word"])).min(1).optional(),
705
+ diarize: _().optional(),
706
+ contextBias: s(M().min(1).regex(/^[^\s,]+$/, "Context bias items must not contain commas or whitespace.")).max(100).optional()
707
+ }))), he = class e {
708
+ constructor(e, t) {
709
+ this.modelId = e, this.config = t, this.specificationVersion = "v4";
710
+ }
711
+ static [o](e) {
712
+ return A({
713
+ modelId: e.modelId,
714
+ config: e.config
715
+ });
716
+ }
717
+ static [m](t) {
718
+ return new e(t.modelId, t.config);
719
+ }
720
+ get provider() {
721
+ return this.config.provider;
722
+ }
723
+ async getArgs({ audio: e, mediaType: t, providerOptions: n }) {
724
+ let r = await b({
725
+ provider: "mistral",
726
+ providerOptions: n,
727
+ schema: me
728
+ });
729
+ if (r?.language != null && r.timestampGranularities != null) throw new S({
730
+ argument: "providerOptions",
731
+ message: "providerOptions.mistral.language cannot be combined with providerOptions.mistral.timestampGranularities"
732
+ });
733
+ let i = new FormData(), a = e instanceof Uint8Array ? new Blob([e]) : new Blob([D(e)]);
734
+ return i.append("model", this.modelId), i.append("file", new File([a], "audio", { type: t }), `audio.${ee(t)}`), r != null && (Q(i, "language", r.language), Q(i, "temperature", r.temperature), Q(i, "timestamp_granularities", r.timestampGranularities), Q(i, "diarize", r.diarize), Q(i, "context_bias", r.contextBias)), {
735
+ formData: i,
736
+ warnings: []
737
+ };
738
+ }
739
+ async doGenerate(e) {
740
+ let t = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date(), { formData: n, warnings: r } = await this.getArgs(e), { value: a, responseHeaders: o, rawValue: s } = await ae({
741
+ url: `${this.config.baseURL}/audio/transcriptions`,
742
+ headers: E(this.config.headers?.(), e.headers),
743
+ formData: n,
744
+ failedResponseHandler: K,
745
+ successfulResponseHandler: i(ge),
746
+ abortSignal: e.abortSignal,
747
+ fetch: this.config.fetch
748
+ }), c = a.segments?.map((e) => ({
749
+ text: e.text,
750
+ startSecond: e.start,
751
+ endSecond: e.end
752
+ })) ?? [], l = {};
753
+ a.usage != null && (l.usage = {
754
+ ...a.usage.prompt_tokens != null && { promptTokens: a.usage.prompt_tokens },
755
+ ...a.usage.completion_tokens != null && { completionTokens: a.usage.completion_tokens },
756
+ ...a.usage.total_tokens != null && { totalTokens: a.usage.total_tokens },
757
+ ...a.usage.prompt_audio_seconds != null && { promptAudioSeconds: a.usage.prompt_audio_seconds },
758
+ ...a.usage.request_count != null && { requestCount: a.usage.request_count }
759
+ });
760
+ let u = a.segments?.filter((e) => e.type != null || e.score != null || e.speaker_id != null).map((e) => ({
761
+ text: e.text,
762
+ startSecond: e.start,
763
+ endSecond: e.end,
764
+ ...e.type != null && { type: e.type },
765
+ ...e.score != null && { score: e.score },
766
+ ...e.speaker_id != null && { speakerId: e.speaker_id }
767
+ }));
768
+ return u != null && u.length > 0 && (l.segments = u), {
769
+ text: a.text,
770
+ segments: c,
771
+ language: a.language ?? void 0,
772
+ durationInSeconds: a.usage?.prompt_audio_seconds ?? c.at(-1)?.endSecond ?? void 0,
773
+ warnings: r,
774
+ response: {
775
+ timestamp: t,
776
+ modelId: a.model,
777
+ headers: o,
778
+ body: s
779
+ },
780
+ ...Object.keys(l).length > 0 && { providerMetadata: { mistral: l } }
781
+ };
782
+ }
783
+ };
784
+ function Q(e, t, n) {
785
+ if (n != null) if (Array.isArray(n)) for (let r of n) e.append(t, r);
786
+ else e.append(t, String(n));
787
+ }
788
+ var ge = x({
789
+ model: M(),
790
+ text: M(),
791
+ language: M().nullish(),
792
+ segments: s(x({
793
+ type: I("transcription_segment").nullish(),
794
+ text: M(),
795
+ start: O(),
796
+ end: O(),
797
+ score: O().nullish(),
798
+ speaker_id: M().nullish()
799
+ })).nullish(),
800
+ usage: x({
801
+ prompt_tokens: O().nullish(),
802
+ completion_tokens: O().nullish(),
803
+ total_tokens: O().nullish(),
804
+ prompt_audio_seconds: O().nullish(),
805
+ request_count: O().nullish()
806
+ }).nullish()
807
+ });
808
+ function $(e = {}) {
809
+ let t = L(e.baseURL) ?? "https://api.mistral.ai/v1", n = () => u({
810
+ Authorization: `Bearer ${re({
811
+ apiKey: e.apiKey,
812
+ environmentVariableName: "MISTRAL_API_KEY",
813
+ description: "Mistral"
814
+ })}`,
815
+ ...e.headers
816
+ }, "ai-sdk-mistral/4.0.54"), i = (r) => new oe(r, {
817
+ provider: "mistral.chat",
818
+ baseURL: t,
819
+ headers: n,
820
+ fetch: e.fetch,
821
+ generateId: e.generateId
822
+ }), a = (r) => new ue(r, {
823
+ provider: "mistral.embedding",
824
+ baseURL: t,
825
+ headers: n,
826
+ fetch: e.fetch
827
+ }), o = (r) => new fe(r, {
828
+ provider: "mistral.speech",
829
+ baseURL: t,
830
+ headers: n,
831
+ fetch: e.fetch
832
+ }), s = (r) => new he(r, {
833
+ provider: "mistral.transcription",
834
+ baseURL: t,
835
+ headers: n,
836
+ fetch: e.fetch
837
+ }), c = function(e) {
838
+ if (new.target) throw Error("The Mistral model function cannot be called with the new keyword.");
839
+ return i(e);
840
+ };
841
+ return c.specificationVersion = "v4", c.languageModel = i, c.chat = i, c.embedding = a, c.embeddingModel = a, c.textEmbedding = a, c.textEmbeddingModel = a, c.speech = o, c.speechModel = o, c.transcription = s, c.transcriptionModel = s, c.imageModel = (e) => {
842
+ throw new r({
843
+ modelId: e,
844
+ modelType: "imageModel"
845
+ });
846
+ }, c;
847
+ }
848
+ $();
849
+ export { $ as createMistral };