@roomle/embedding-lib 9.0.0-alpha.10 → 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 (62) 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 -4
  28. package/{drag-ghost-CDFtC1pd.mjs → drag-ghost-D7FnWbO4.mjs} +2 -1
  29. package/{drag-ghost-BxqPJdhq.mjs → drag-ghost-yXe7c8jA.mjs} +2 -1
  30. package/{drag-in-ClPpCYyi.mjs → drag-in-BiEe2Lgv.mjs} +15 -20
  31. package/{drag-in-CV1E-DO6.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-Sx6P6iDI.mjs → from-custom-view-CTBapIc6.mjs} +31 -30
  37. package/{from-custom-view-Q9A-J7qV.mjs → from-custom-view-xbjgsLll.mjs} +32 -31
  38. package/{from-website-DZJy_l42.mjs → from-website-DUPMQPl6.mjs} +24 -23
  39. package/{from-website-BmCO2xli.mjs → from-website-JwG7Ic_U.mjs} +24 -23
  40. package/hi.js +249 -150
  41. package/hi.min.js +211 -134
  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/homag-intelligence/hi-mcp-tools.d.ts +4 -61
  49. package/packages/embedding-lib/src/homag-intelligence/hi-planning-assistant.d.ts +9 -32
  50. package/packages/embedding-lib/src/homag-intelligence/hi-planning-usage.d.ts +54 -0
  51. package/packages/embedding-lib/src/planning-assistant/chat-model.d.ts +1 -0
  52. package/packages/embedding-lib/src/planning-assistant/mcp-tools.d.ts +2 -0
  53. package/packages/web-sdk/packages/assistant.d.ts +3 -0
  54. package/packages/web-sdk/packages/common-core/src/agent-tools/mcp-tool-types.d.ts +30 -0
  55. package/packages/web-sdk/packages/common-core/src/planning-assistant/chat-model.d.ts +8 -0
  56. package/packages/web-sdk/packages/common-core/src/planning-assistant/mcp-tools.d.ts +52 -0
  57. package/packages/web-sdk/packages/common-core/src/planning-assistant/types.d.ts +35 -0
  58. package/roomle-embedding-lib.js +3 -2
  59. package/roomle-embedding-lib.min.js +3 -2
  60. package/sbom.cdx.json +405 -0
  61. package/{utils-wJ80awOA.mjs → utils-CAAGdgk8.mjs} +1 -0
  62. package/{utils-DxJ3PcKe.mjs → utils-WeolMfC5.mjs} +1 -0
@@ -0,0 +1,1179 @@
1
+
2
+ import { D as e, E as t, H as n, Ht as r, Jt as i, K as a, L as o, O as s, Rt as c, S as l, Sn as u, Tt as d, Vt as f, Wt as p, X as m, Yt as h, _ as g, _t as _, an as v, bt as y, dn as b, f as x, h as S, in as C, jn as w, jt as T, kn as ee, ln as E, nn as D, o as te, qt as O, sn as k, tn as ne, v as A, w as j, xn as re, yt as ie, zt as ae } from "./dist-Bt1FopV4.mjs";
3
+ function M(e) {
4
+ return e.replace(/[_-]([a-z])/g, (e) => e[1].toUpperCase());
5
+ }
6
+ function N({ rawName: e, providerOptions: t, warnings: n }) {
7
+ let r = M(e);
8
+ r !== e && t?.[e] != null && n.push({
9
+ type: "deprecated",
10
+ setting: `providerOptions key '${e}'`,
11
+ message: `Use '${r}' instead.`
12
+ });
13
+ }
14
+ var P = {
15
+ errorSchema: v({ error: v({
16
+ message: E(),
17
+ type: E().nullish(),
18
+ param: O().nullish(),
19
+ code: b([E(), C()]).nullish()
20
+ }) }),
21
+ errorToMessage: (e) => e.error.message
22
+ };
23
+ function F(e) {
24
+ return e?.providerOptions?.openaiCompatible ?? {};
25
+ }
26
+ function oe(e) {
27
+ switch (e) {
28
+ case "audio/wav": return "wav";
29
+ case "audio/mp3":
30
+ case "audio/mpeg": return "mp3";
31
+ default: return null;
32
+ }
33
+ }
34
+ function se(e, { providerOptionsKey: t = "google" } = {}) {
35
+ let n = [];
36
+ for (let { role: r, content: i, ...o } of e) {
37
+ let e = F({ ...o });
38
+ switch (r) {
39
+ case "system":
40
+ n.push({
41
+ role: "system",
42
+ content: i,
43
+ ...e
44
+ });
45
+ break;
46
+ case "user":
47
+ if (i.length === 1 && i[0].type === "text") {
48
+ n.push({
49
+ role: "user",
50
+ content: i[0].text,
51
+ ...F(i[0])
52
+ });
53
+ break;
54
+ }
55
+ n.push({
56
+ role: "user",
57
+ content: i.map((e) => {
58
+ let t = F(e);
59
+ switch (e.type) {
60
+ case "text": return {
61
+ type: "text",
62
+ text: e.text,
63
+ ...t
64
+ };
65
+ case "file": switch (e.data.type) {
66
+ case "reference": throw new w({ functionality: "file parts with provider references" });
67
+ case "text": throw new w({ functionality: "text file parts" });
68
+ case "url":
69
+ case "data": {
70
+ let n = a(e.mediaType);
71
+ if (n === "image") return {
72
+ type: "image_url",
73
+ image_url: { url: e.data.type === "url" ? e.data.url.toString() : `data:${d({ part: e })};base64,${g(e.data.data)}` },
74
+ ...t
75
+ };
76
+ if (n === "video") return {
77
+ type: "video_url",
78
+ video_url: { url: e.data.type === "url" ? e.data.url.toString() : `data:${d({ part: e })};base64,${g(e.data.data)}` },
79
+ ...t
80
+ };
81
+ if (n === "audio") {
82
+ if (e.data.type === "url") throw new w({ functionality: "audio file parts with URLs" });
83
+ let n = d({ part: e }), r = oe(n);
84
+ if (r === null) throw new w({ functionality: `audio media type ${n}` });
85
+ return {
86
+ type: "input_audio",
87
+ input_audio: {
88
+ data: g(e.data.data),
89
+ format: r
90
+ },
91
+ ...t
92
+ };
93
+ }
94
+ if (n === "application") {
95
+ if (e.data.type === "url") throw new w({ functionality: "PDF file parts with URLs" });
96
+ let n = d({ part: e });
97
+ if (n !== "application/pdf") throw new w({ functionality: `file part media type ${n}` });
98
+ return {
99
+ type: "file",
100
+ file: {
101
+ filename: e.filename ?? "document.pdf",
102
+ file_data: `data:application/pdf;base64,${g(e.data.data)}`
103
+ },
104
+ ...t
105
+ };
106
+ }
107
+ if (n === "text") return {
108
+ type: "text",
109
+ text: e.data.type === "url" ? e.data.url.toString() : typeof e.data.data == "string" ? new TextDecoder().decode(S(e.data.data)) : new TextDecoder().decode(e.data.data),
110
+ ...t
111
+ };
112
+ throw new w({ functionality: `file part media type ${e.mediaType}` });
113
+ }
114
+ }
115
+ }
116
+ }),
117
+ ...e
118
+ });
119
+ break;
120
+ case "assistant": {
121
+ let r = "", a = "", o = [];
122
+ for (let e of i) {
123
+ let n = F(e);
124
+ switch (e.type) {
125
+ case "text":
126
+ r += e.text;
127
+ break;
128
+ case "reasoning":
129
+ a += e.text;
130
+ break;
131
+ case "tool-call": {
132
+ let r = e.providerOptions?.[t]?.thoughtSignature ?? e.providerOptions?.google?.thoughtSignature;
133
+ o.push({
134
+ id: e.toolCallId,
135
+ type: "function",
136
+ function: {
137
+ name: e.toolName,
138
+ arguments: JSON.stringify(e.input)
139
+ },
140
+ ...n,
141
+ ...r ? { extra_content: { google: { thought_signature: String(r) } } } : {}
142
+ });
143
+ break;
144
+ }
145
+ }
146
+ }
147
+ n.push({
148
+ role: "assistant",
149
+ content: o.length > 0 ? r || null : r,
150
+ ...a.length > 0 ? { reasoning_content: a } : {},
151
+ tool_calls: o.length > 0 ? o : void 0,
152
+ ...e
153
+ });
154
+ break;
155
+ }
156
+ case "tool":
157
+ for (let e of i) {
158
+ if (e.type === "tool-approval-response") continue;
159
+ let t = e.output, r;
160
+ switch (t.type) {
161
+ case "text":
162
+ case "error-text":
163
+ r = t.value;
164
+ break;
165
+ case "execution-denied":
166
+ r = t.reason ?? "Tool call execution denied.";
167
+ break;
168
+ case "content":
169
+ case "json":
170
+ case "error-json": r = JSON.stringify(t.value);
171
+ }
172
+ let i = F(e);
173
+ n.push({
174
+ role: "tool",
175
+ tool_call_id: e.toolCallId,
176
+ content: r,
177
+ ...i
178
+ });
179
+ }
180
+ break;
181
+ default: throw Error(`Unsupported role: ${r}`);
182
+ }
183
+ }
184
+ return n;
185
+ }
186
+ function I({ id: t, model: n, created: r }) {
187
+ return e({
188
+ id: t,
189
+ model: n,
190
+ created: r || void 0
191
+ });
192
+ }
193
+ function L(e) {
194
+ switch (e) {
195
+ case "stop": return "stop";
196
+ case "length": return "length";
197
+ case "content_filter": return "content-filter";
198
+ case "function_call":
199
+ case "tool_calls": return "tool-calls";
200
+ default: return "other";
201
+ }
202
+ }
203
+ var R = v({
204
+ user: E().optional(),
205
+ reasoningEffort: E().optional(),
206
+ textVerbosity: E().optional(),
207
+ strictJsonSchema: h().optional()
208
+ }), ce = class e {
209
+ constructor(e, t) {
210
+ this.specificationVersion = "v4", this.modelId = e, this.config = t;
211
+ let n = t.errorStructure ?? P;
212
+ this.chunkSchema = W(n.errorSchema), this.failedResponseHandler = j(n), this.supportsStructuredOutputs = t.supportsStructuredOutputs ?? !1;
213
+ }
214
+ static [r](e) {
215
+ return T({
216
+ modelId: e.modelId,
217
+ config: e.config
218
+ });
219
+ }
220
+ static [f](t) {
221
+ return new e(t.modelId, t.config);
222
+ }
223
+ get provider() {
224
+ return this.config.provider;
225
+ }
226
+ get providerOptionsName() {
227
+ return this.config.provider.split(".")[0].trim();
228
+ }
229
+ get supportedUrls() {
230
+ return this.config.supportedUrls?.() ?? {};
231
+ }
232
+ transformRequestBody(e) {
233
+ return this.config.transformRequestBody?.(e) ?? e;
234
+ }
235
+ convertUsage(e) {
236
+ return this.config.convertUsage?.(e) ?? function(e) {
237
+ if (e == null) return s();
238
+ let t = e.prompt_tokens ?? 0, n = e.completion_tokens ?? 0, r = e.prompt_tokens_details?.cached_tokens ?? 0, i = e.completion_tokens_details?.reasoning_tokens ?? 0;
239
+ return {
240
+ inputTokens: {
241
+ total: t,
242
+ noCache: t - r,
243
+ cacheRead: r,
244
+ cacheWrite: void 0
245
+ },
246
+ outputTokens: {
247
+ total: n,
248
+ text: Math.max(0, n - i),
249
+ reasoning: i
250
+ },
251
+ raw: e
252
+ };
253
+ }(e);
254
+ }
255
+ async getArgs({ prompt: e, maxOutputTokens: t, temperature: n, topP: r, topK: i, frequencyPenalty: a, presencePenalty: o, reasoning: s, providerOptions: c, stopSequences: l, responseFormat: u, seed: d, toolChoice: f, tools: p }) {
256
+ let h = [], g = await _({
257
+ provider: "openai-compatible",
258
+ providerOptions: c,
259
+ schema: R
260
+ });
261
+ g != null && h.push({
262
+ type: "deprecated",
263
+ setting: "providerOptions key 'openai-compatible'",
264
+ message: "Use 'openaiCompatible' instead."
265
+ }), N({
266
+ rawName: this.providerOptionsName,
267
+ providerOptions: c,
268
+ warnings: h
269
+ });
270
+ let v = Object.assign(g ?? {}, await _({
271
+ provider: "openaiCompatible",
272
+ providerOptions: c,
273
+ schema: R
274
+ }) ?? {}, await _({
275
+ provider: this.providerOptionsName,
276
+ providerOptions: c,
277
+ schema: R
278
+ }) ?? {}, await _({
279
+ provider: M(this.providerOptionsName),
280
+ providerOptions: c,
281
+ schema: R
282
+ }) ?? {}), y = v?.strictJsonSchema ?? !0;
283
+ i != null && h.push({
284
+ type: "unsupported",
285
+ feature: "topK"
286
+ }), u?.type !== "json" || u.schema == null || this.supportsStructuredOutputs || h.push({
287
+ type: "unsupported",
288
+ feature: "responseFormat",
289
+ details: "JSON response format schema is only supported with structuredOutputs"
290
+ });
291
+ let { tools: b, toolChoice: x, toolWarnings: S } = function({ tools: e, toolChoice: t }) {
292
+ let n = [];
293
+ if ((e = e?.length ? e : void 0) == null) return {
294
+ tools: void 0,
295
+ toolChoice: void 0,
296
+ toolWarnings: n
297
+ };
298
+ let r = [];
299
+ for (let t of e) t.type === "provider" ? n.push({
300
+ type: "unsupported",
301
+ feature: `provider-defined tool ${t.id}`
302
+ }) : r.push({
303
+ type: "function",
304
+ function: {
305
+ name: t.name,
306
+ description: t.description,
307
+ parameters: t.inputSchema,
308
+ ...t.strict == null ? {} : { strict: t.strict }
309
+ }
310
+ });
311
+ if (t == null) return {
312
+ tools: r,
313
+ toolChoice: void 0,
314
+ toolWarnings: n
315
+ };
316
+ let i = t.type;
317
+ switch (i) {
318
+ case "auto":
319
+ case "none":
320
+ case "required": return {
321
+ tools: r,
322
+ toolChoice: i,
323
+ toolWarnings: n
324
+ };
325
+ case "tool": return {
326
+ tools: r,
327
+ toolChoice: {
328
+ type: "function",
329
+ function: { name: t.toolName }
330
+ },
331
+ toolWarnings: n
332
+ };
333
+ default: throw new w({ functionality: `tool choice type: ${i}` });
334
+ }
335
+ }({
336
+ tools: p,
337
+ toolChoice: f
338
+ }), C = function(e, t) {
339
+ let n = M(e);
340
+ return n !== e && t?.[n] != null ? n : e;
341
+ }(this.providerOptionsName, c);
342
+ return {
343
+ metadataKey: C,
344
+ args: {
345
+ model: this.modelId,
346
+ user: v.user,
347
+ max_tokens: t,
348
+ temperature: n,
349
+ top_p: r,
350
+ frequency_penalty: a,
351
+ presence_penalty: o,
352
+ response_format: u?.type === "json" ? !0 === this.supportsStructuredOutputs && u.schema != null ? {
353
+ type: "json_schema",
354
+ json_schema: {
355
+ schema: u.schema,
356
+ strict: y,
357
+ name: u.name ?? "response",
358
+ description: u.description
359
+ }
360
+ } : { type: "json_object" } : void 0,
361
+ stop: l,
362
+ seed: d,
363
+ ...Object.fromEntries(Object.entries({
364
+ ...c?.[this.providerOptionsName],
365
+ ...c?.[M(this.providerOptionsName)]
366
+ }).filter(([e]) => !Object.keys(R.shape).includes(e))),
367
+ reasoning_effort: v.reasoningEffort ?? (m(s) ? s : void 0),
368
+ verbosity: v.textVerbosity,
369
+ messages: se(e, { providerOptionsKey: C }),
370
+ tools: b,
371
+ tool_choice: x
372
+ },
373
+ warnings: [...h, ...S]
374
+ };
375
+ }
376
+ async doGenerate(e) {
377
+ let { args: r, warnings: i, metadataKey: a } = await this.getArgs({ ...e }), o = this.transformRequestBody(r), s = JSON.stringify(o), { responseHeaders: c, value: l, rawValue: d } = await y({
378
+ url: this.config.url({
379
+ path: "/chat/completions",
380
+ modelId: this.modelId
381
+ }),
382
+ headers: x(this.config.headers?.(), e.headers),
383
+ body: o,
384
+ failedResponseHandler: this.failedResponseHandler,
385
+ successfulResponseHandler: t(H),
386
+ abortSignal: e.abortSignal,
387
+ fetch: this.config.fetch
388
+ }), f = l.choices[0];
389
+ if (f == null) throw new u({
390
+ data: d,
391
+ message: "Response did not contain any choices."
392
+ });
393
+ let p = [];
394
+ p.push(...V(f.message.content));
395
+ let m = f.message.reasoning_content ?? f.message.reasoning;
396
+ if (m != null && m.length > 0 && p.push({
397
+ type: "reasoning",
398
+ text: m
399
+ }), f.message.tool_calls != null) for (let e of f.message.tool_calls) {
400
+ let t = e.extra_content?.google?.thought_signature;
401
+ p.push({
402
+ type: "tool-call",
403
+ toolCallId: e.id || n(),
404
+ toolName: e.function.name,
405
+ input: e.function.arguments,
406
+ ...t ? { providerMetadata: { [a]: { thoughtSignature: t } } } : {}
407
+ });
408
+ }
409
+ let h = {
410
+ [a]: {},
411
+ ...await this.config.metadataExtractor?.extractMetadata?.({ parsedBody: d })
412
+ }, g = l.usage?.completion_tokens_details;
413
+ return g?.accepted_prediction_tokens != null && (h[a].acceptedPredictionTokens = g?.accepted_prediction_tokens), g?.rejected_prediction_tokens != null && (h[a].rejectedPredictionTokens = g?.rejected_prediction_tokens), {
414
+ content: p,
415
+ finishReason: {
416
+ unified: L(f.finish_reason),
417
+ raw: f.finish_reason ?? void 0
418
+ },
419
+ usage: this.convertUsage(l.usage),
420
+ providerMetadata: h,
421
+ request: { body: s },
422
+ response: {
423
+ ...I(l),
424
+ headers: c,
425
+ body: d
426
+ },
427
+ warnings: i
428
+ };
429
+ }
430
+ async doStream(e) {
431
+ let { args: t, warnings: r, metadataKey: i } = await this.getArgs({ ...e }), a = this.transformRequestBody({
432
+ ...t,
433
+ stream: !0,
434
+ stream_options: this.config.includeUsage ? { include_usage: !0 } : void 0
435
+ }), o = this.config.metadataExtractor?.createStreamExtractor(), { responseHeaders: s, value: c } = await y({
436
+ url: this.config.url({
437
+ path: "/chat/completions",
438
+ modelId: this.modelId
439
+ }),
440
+ headers: x(this.config.headers?.(), e.headers),
441
+ body: a,
442
+ failedResponseHandler: this.failedResponseHandler,
443
+ successfulResponseHandler: l(this.chunkSchema),
444
+ abortSignal: e.abortSignal,
445
+ fetch: this.config.fetch
446
+ }), d = i, f, p = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Set(), h = (e) => {
447
+ let t = e.index;
448
+ if (t == null || m.has(t)) return void f.processDelta(e);
449
+ let n = p.get(t);
450
+ n == null ? (n = {
451
+ id: e.id ?? null,
452
+ bufferedArguments: "",
453
+ extraContent: e.extra_content ?? null
454
+ }, p.set(t, n)) : (n.id == null && e.id != null && (n.id = e.id), n.extraContent == null && e.extra_content != null && (n.extraContent = e.extra_content));
455
+ let r = e.function?.arguments;
456
+ r != null && (n.bufferedArguments += r);
457
+ let i = e.function?.name;
458
+ if (i != null) {
459
+ let e = {
460
+ index: t,
461
+ id: n.id,
462
+ function: {
463
+ name: i,
464
+ arguments: n.bufferedArguments
465
+ },
466
+ extra_content: n.extraContent ?? void 0
467
+ };
468
+ f.processDelta(e), p.delete(t), m.add(t);
469
+ }
470
+ }, g, _, v = !1, b = !1, S = !1, C = (e) => this.convertUsage(e);
471
+ return {
472
+ stream: c.pipeThrough(new TransformStream({
473
+ start(e) {
474
+ f = new te(e, {
475
+ generateId: n,
476
+ extractMetadata: (e) => {
477
+ let t = e.extra_content?.google?.thought_signature;
478
+ return t ? { [d]: { thoughtSignature: t } } : void 0;
479
+ },
480
+ buildToolCallProviderMetadata: (e) => e
481
+ }), e.enqueue({
482
+ type: "stream-start",
483
+ warnings: r
484
+ });
485
+ },
486
+ transform(t, n) {
487
+ if (e.includeRawChunks && n.enqueue({
488
+ type: "raw",
489
+ rawValue: t.rawValue
490
+ }), !t.success) return g = {
491
+ unified: "error",
492
+ raw: void 0
493
+ }, void n.enqueue({
494
+ type: "error",
495
+ error: t.error
496
+ });
497
+ if (o?.processChunk(t.rawValue), "error" in t.value) return g = {
498
+ unified: "error",
499
+ raw: void 0
500
+ }, void n.enqueue({
501
+ type: "error",
502
+ error: t.value.error
503
+ });
504
+ let r = t.value;
505
+ if (!v) {
506
+ let e = I(r);
507
+ Object.values(e).some(Boolean) && (v = !0, n.enqueue({
508
+ type: "response-metadata",
509
+ ...e
510
+ }));
511
+ }
512
+ r.usage != null && (_ = r.usage);
513
+ let i = r.choices[0];
514
+ if (i?.finish_reason != null && (g = {
515
+ unified: L(i.finish_reason),
516
+ raw: i.finish_reason ?? void 0
517
+ }), i?.delta == null) return;
518
+ let a = i.delta, s = (e) => {
519
+ S &&= (n.enqueue({
520
+ type: "text-end",
521
+ id: "txt-0"
522
+ }), !1), b ||= (n.enqueue({
523
+ type: "reasoning-start",
524
+ id: "reasoning-0"
525
+ }), !0), n.enqueue({
526
+ type: "reasoning-delta",
527
+ id: "reasoning-0",
528
+ delta: e
529
+ });
530
+ }, c = (e) => {
531
+ b &&= (n.enqueue({
532
+ type: "reasoning-end",
533
+ id: "reasoning-0"
534
+ }), !1), S ||= (n.enqueue({
535
+ type: "text-start",
536
+ id: "txt-0"
537
+ }), !0), n.enqueue({
538
+ type: "text-delta",
539
+ id: "txt-0",
540
+ delta: e
541
+ });
542
+ }, l = a.reasoning_content ?? a.reasoning;
543
+ l && s(l);
544
+ for (let e of V(a.content)) e.type === "reasoning" ? s(e.text) : c(e.text);
545
+ if (a.tool_calls != null && a.tool_calls.length > 0) {
546
+ b &&= (n.enqueue({
547
+ type: "reasoning-end",
548
+ id: "reasoning-0"
549
+ }), !1);
550
+ for (let e of a.tool_calls) h(e);
551
+ }
552
+ },
553
+ flush(e) {
554
+ b && e.enqueue({
555
+ type: "reasoning-end",
556
+ id: "reasoning-0"
557
+ }), S && e.enqueue({
558
+ type: "text-end",
559
+ id: "txt-0"
560
+ });
561
+ for (let [e, t] of p) f.processDelta({
562
+ index: e,
563
+ id: t.id,
564
+ function: { arguments: t.bufferedArguments }
565
+ });
566
+ p.clear(), f.flush(), g ?? (g = {
567
+ unified: "error",
568
+ raw: void 0
569
+ }, e.enqueue({
570
+ type: "error",
571
+ error: new u({
572
+ data: void 0,
573
+ message: "Response stream ended without a finish reason."
574
+ })
575
+ }));
576
+ let t = {
577
+ [d]: {},
578
+ ...o?.buildMetadata()
579
+ };
580
+ _?.completion_tokens_details?.accepted_prediction_tokens != null && (t[d].acceptedPredictionTokens = _?.completion_tokens_details?.accepted_prediction_tokens), _?.completion_tokens_details?.rejected_prediction_tokens != null && (t[d].rejectedPredictionTokens = _?.completion_tokens_details?.rejected_prediction_tokens), e.enqueue({
581
+ type: "finish",
582
+ finishReason: g,
583
+ usage: C(_),
584
+ providerMetadata: t
585
+ });
586
+ }
587
+ })),
588
+ request: { body: a },
589
+ response: { headers: s }
590
+ };
591
+ }
592
+ }, z = D({
593
+ prompt_tokens: C().nullish(),
594
+ completion_tokens: C().nullish(),
595
+ total_tokens: C().nullish(),
596
+ prompt_tokens_details: D({ cached_tokens: C().nullish() }).nullish(),
597
+ completion_tokens_details: D({
598
+ reasoning_tokens: C().nullish(),
599
+ accepted_prediction_tokens: C().nullish(),
600
+ rejected_prediction_tokens: C().nullish()
601
+ }).nullish()
602
+ }).nullish(), B = b([E(), i(D({ type: E() }))]).nullish();
603
+ function V(e) {
604
+ if (e == null) return [];
605
+ if (typeof e == "string") return e.length > 0 ? [{
606
+ type: "text",
607
+ text: e
608
+ }] : [];
609
+ let t = [];
610
+ for (let n of e) if (n.type === "text" && typeof n.text == "string") n.text.length > 0 && t.push({
611
+ type: "text",
612
+ text: n.text
613
+ });
614
+ else if (n.type === "thinking" && Array.isArray(n.thinking)) {
615
+ let e = n.thinking.filter((e) => typeof e == "object" && !!e && "type" in e && e.type === "text" && "text" in e && typeof e.text == "string").map((e) => e.text).join("");
616
+ e.length > 0 && t.push({
617
+ type: "reasoning",
618
+ text: e
619
+ });
620
+ }
621
+ return t;
622
+ }
623
+ var H = D({
624
+ id: E().nullish(),
625
+ created: C().nullish(),
626
+ model: E().nullish(),
627
+ choices: i(v({
628
+ message: v({
629
+ role: ne("assistant").nullish(),
630
+ content: B,
631
+ reasoning_content: E().nullish(),
632
+ reasoning: E().nullish(),
633
+ tool_calls: i(v({
634
+ id: E().nullish(),
635
+ function: v({
636
+ name: E(),
637
+ arguments: E()
638
+ }),
639
+ extra_content: v({ google: v({ thought_signature: E().nullish() }).nullish() }).nullish()
640
+ })).nullish()
641
+ }),
642
+ finish_reason: E().nullish()
643
+ })),
644
+ usage: z
645
+ }), U = D({
646
+ id: E().nullish(),
647
+ created: C().nullish(),
648
+ model: E().nullish(),
649
+ choices: i(v({
650
+ delta: v({
651
+ role: p(["assistant", ""]).nullish(),
652
+ content: B,
653
+ reasoning_content: E().nullish(),
654
+ reasoning: E().nullish(),
655
+ tool_calls: i(v({
656
+ index: C().nullish(),
657
+ id: E().nullish(),
658
+ function: v({
659
+ name: E().nullish(),
660
+ arguments: E().nullish()
661
+ }),
662
+ extra_content: v({ google: v({ thought_signature: E().nullish() }).nullish() }).nullish()
663
+ })).nullish()
664
+ }).nullish(),
665
+ finish_reason: E().nullish()
666
+ })),
667
+ usage: z
668
+ }), W = (e) => b([U, e]);
669
+ function G(e) {
670
+ if (e == null) return s();
671
+ let t = e.prompt_tokens ?? 0, n = e.completion_tokens ?? 0;
672
+ return {
673
+ inputTokens: {
674
+ total: t,
675
+ noCache: t,
676
+ cacheRead: void 0,
677
+ cacheWrite: void 0
678
+ },
679
+ outputTokens: {
680
+ total: n,
681
+ text: n,
682
+ reasoning: void 0
683
+ },
684
+ raw: e
685
+ };
686
+ }
687
+ function K(e) {
688
+ switch (e) {
689
+ case "stop": return "stop";
690
+ case "length": return "length";
691
+ case "content_filter": return "content-filter";
692
+ case "function_call":
693
+ case "tool_calls": return "tool-calls";
694
+ default: return "other";
695
+ }
696
+ }
697
+ var q = v({
698
+ echo: h().optional(),
699
+ logitBias: k(E(), C()).optional(),
700
+ suffix: E().optional(),
701
+ user: E().optional()
702
+ }), le = class n {
703
+ constructor(e, t) {
704
+ this.specificationVersion = "v4", this.modelId = e, this.config = t;
705
+ let n = t.errorStructure ?? P;
706
+ this.chunkSchema = de(n.errorSchema), this.failedResponseHandler = j(n);
707
+ }
708
+ static [r](e) {
709
+ return T({
710
+ modelId: e.modelId,
711
+ config: e.config
712
+ });
713
+ }
714
+ static [f](e) {
715
+ return new n(e.modelId, e.config);
716
+ }
717
+ get provider() {
718
+ return this.config.provider;
719
+ }
720
+ get providerOptionsName() {
721
+ return this.config.provider.split(".")[0].trim();
722
+ }
723
+ get supportedUrls() {
724
+ return this.config.supportedUrls?.() ?? {};
725
+ }
726
+ async getArgs({ prompt: e, maxOutputTokens: t, temperature: n, topP: r, topK: i, frequencyPenalty: a, presencePenalty: o, stopSequences: s, responseFormat: c, seed: l, providerOptions: u, tools: d, toolChoice: f }) {
727
+ let p = [];
728
+ N({
729
+ rawName: this.providerOptionsName,
730
+ providerOptions: u,
731
+ warnings: p
732
+ });
733
+ let m = Object.assign(await _({
734
+ provider: this.providerOptionsName,
735
+ providerOptions: u,
736
+ schema: q
737
+ }) ?? {}, await _({
738
+ provider: M(this.providerOptionsName),
739
+ providerOptions: u,
740
+ schema: q
741
+ }) ?? {});
742
+ i != null && p.push({
743
+ type: "unsupported",
744
+ feature: "topK"
745
+ }), d?.length && p.push({
746
+ type: "unsupported",
747
+ feature: "tools"
748
+ }), f != null && p.push({
749
+ type: "unsupported",
750
+ feature: "toolChoice"
751
+ }), c != null && c.type !== "text" && p.push({
752
+ type: "unsupported",
753
+ feature: "responseFormat",
754
+ details: "JSON response format is not supported."
755
+ });
756
+ let { prompt: h, stopSequences: g } = function({ prompt: e, user: t = "user", assistant: n = "assistant" }) {
757
+ let r = "";
758
+ e[0].role === "system" && (r += `${e[0].content}\n\n`, e = e.slice(1));
759
+ for (let { role: i, content: a } of e) switch (i) {
760
+ case "system": throw new re({
761
+ message: "Unexpected system message in prompt: ${content}",
762
+ prompt: e
763
+ });
764
+ case "user":
765
+ r += `${t}:\n${a.map((e) => {
766
+ if (e.type === "text") return e.text;
767
+ }).filter(Boolean).join("")}\n\n`;
768
+ break;
769
+ case "assistant":
770
+ r += `${n}:\n${a.map((e) => {
771
+ switch (e.type) {
772
+ case "text": return e.text;
773
+ case "tool-call": throw new w({ functionality: "tool-call messages" });
774
+ }
775
+ }).join("")}\n\n`;
776
+ break;
777
+ case "tool": throw new w({ functionality: "tool messages" });
778
+ default: throw Error(`Unsupported role: ${i}`);
779
+ }
780
+ return r += `${n}:\n`, {
781
+ prompt: r,
782
+ stopSequences: [`\n${t}:`]
783
+ };
784
+ }({ prompt: e }), v = [...g ?? [], ...s ?? []];
785
+ return {
786
+ args: {
787
+ model: this.modelId,
788
+ echo: m.echo,
789
+ logit_bias: m.logitBias,
790
+ suffix: m.suffix,
791
+ user: m.user,
792
+ max_tokens: t,
793
+ temperature: n,
794
+ top_p: r,
795
+ frequency_penalty: a,
796
+ presence_penalty: o,
797
+ seed: l,
798
+ ...u?.[this.providerOptionsName],
799
+ ...u?.[M(this.providerOptionsName)],
800
+ prompt: h,
801
+ stop: v.length > 0 ? v : void 0
802
+ },
803
+ warnings: p
804
+ };
805
+ }
806
+ async doGenerate(n) {
807
+ let { args: r, warnings: i } = await this.getArgs(n), { responseHeaders: a, value: o, rawValue: s } = await y({
808
+ url: this.config.url({
809
+ path: "/completions",
810
+ modelId: this.modelId
811
+ }),
812
+ headers: x(this.config.headers?.(), n.headers),
813
+ body: r,
814
+ failedResponseHandler: this.failedResponseHandler,
815
+ successfulResponseHandler: t(ue),
816
+ abortSignal: n.abortSignal,
817
+ fetch: this.config.fetch
818
+ }), c = o.choices[0], l = [];
819
+ return c.text != null && c.text.length > 0 && l.push({
820
+ type: "text",
821
+ text: c.text
822
+ }), {
823
+ content: l,
824
+ usage: G(o.usage),
825
+ finishReason: {
826
+ unified: K(c.finish_reason),
827
+ raw: c.finish_reason
828
+ },
829
+ request: { body: r },
830
+ response: {
831
+ ...e(o),
832
+ headers: a,
833
+ body: s
834
+ },
835
+ warnings: i
836
+ };
837
+ }
838
+ async doStream(t) {
839
+ let { args: n, warnings: r } = await this.getArgs(t), i = {
840
+ ...n,
841
+ stream: !0,
842
+ stream_options: this.config.includeUsage ? { include_usage: !0 } : void 0
843
+ }, { responseHeaders: a, value: o } = await y({
844
+ url: this.config.url({
845
+ path: "/completions",
846
+ modelId: this.modelId
847
+ }),
848
+ headers: x(this.config.headers?.(), t.headers),
849
+ body: i,
850
+ failedResponseHandler: this.failedResponseHandler,
851
+ successfulResponseHandler: l(this.chunkSchema),
852
+ abortSignal: t.abortSignal,
853
+ fetch: this.config.fetch
854
+ }), s, c = {
855
+ unified: "other",
856
+ raw: void 0
857
+ }, u = !0;
858
+ return {
859
+ stream: o.pipeThrough(new TransformStream({
860
+ start(e) {
861
+ e.enqueue({
862
+ type: "stream-start",
863
+ warnings: r
864
+ });
865
+ },
866
+ transform(n, r) {
867
+ if (t.includeRawChunks && r.enqueue({
868
+ type: "raw",
869
+ rawValue: n.rawValue
870
+ }), !n.success) return c = {
871
+ unified: "error",
872
+ raw: void 0
873
+ }, void r.enqueue({
874
+ type: "error",
875
+ error: n.error
876
+ });
877
+ let i = n.value;
878
+ if ("error" in i) return c = {
879
+ unified: "error",
880
+ raw: void 0
881
+ }, void r.enqueue({
882
+ type: "error",
883
+ error: i.error
884
+ });
885
+ u && (u = !1, r.enqueue({
886
+ type: "response-metadata",
887
+ ...e(i)
888
+ }), r.enqueue({
889
+ type: "text-start",
890
+ id: "0"
891
+ })), i.usage != null && (s = i.usage);
892
+ let a = i.choices[0];
893
+ a?.finish_reason != null && (c = {
894
+ unified: K(a.finish_reason),
895
+ raw: a.finish_reason ?? void 0
896
+ }), a?.text != null && r.enqueue({
897
+ type: "text-delta",
898
+ id: "0",
899
+ delta: a.text
900
+ });
901
+ },
902
+ flush(e) {
903
+ u || e.enqueue({
904
+ type: "text-end",
905
+ id: "0"
906
+ }), e.enqueue({
907
+ type: "finish",
908
+ finishReason: c,
909
+ usage: G(s)
910
+ });
911
+ }
912
+ })),
913
+ request: { body: i },
914
+ response: { headers: a }
915
+ };
916
+ }
917
+ }, J = D({
918
+ prompt_tokens: C(),
919
+ completion_tokens: C(),
920
+ total_tokens: C()
921
+ }), ue = v({
922
+ id: E().nullish(),
923
+ created: C().nullish(),
924
+ model: E().nullish(),
925
+ choices: i(v({
926
+ text: E(),
927
+ finish_reason: E()
928
+ })),
929
+ usage: J.nullish()
930
+ }), de = (e) => b([v({
931
+ id: E().nullish(),
932
+ created: C().nullish(),
933
+ model: E().nullish(),
934
+ choices: i(v({
935
+ text: E(),
936
+ finish_reason: E().nullish(),
937
+ index: C()
938
+ })),
939
+ usage: J.nullish()
940
+ }), e]), Y = v({
941
+ dimensions: C().optional(),
942
+ user: E().optional()
943
+ }), fe = class e {
944
+ constructor(e, t) {
945
+ this.specificationVersion = "v4", this.modelId = e, this.config = t;
946
+ }
947
+ get provider() {
948
+ return this.config.provider;
949
+ }
950
+ get maxEmbeddingsPerCall() {
951
+ return this.config.maxEmbeddingsPerCall ?? 2048;
952
+ }
953
+ get supportsParallelCalls() {
954
+ return this.config.supportsParallelCalls ?? !0;
955
+ }
956
+ static [r](e) {
957
+ return T({
958
+ modelId: e.modelId,
959
+ config: e.config
960
+ });
961
+ }
962
+ static [f](t) {
963
+ return new e(t.modelId, t.config);
964
+ }
965
+ get providerOptionsName() {
966
+ return this.config.provider.split(".")[0].trim();
967
+ }
968
+ async doEmbed({ values: e, headers: n, abortSignal: r, providerOptions: i }) {
969
+ let a = [], o = await _({
970
+ provider: "openai-compatible",
971
+ providerOptions: i,
972
+ schema: Y
973
+ });
974
+ o != null && a.push({
975
+ type: "deprecated",
976
+ setting: "providerOptions key 'openai-compatible'",
977
+ message: "Use 'openaiCompatible' instead."
978
+ }), N({
979
+ rawName: this.providerOptionsName,
980
+ providerOptions: i,
981
+ warnings: a
982
+ });
983
+ let s = Object.assign(o ?? {}, await _({
984
+ provider: "openaiCompatible",
985
+ providerOptions: i,
986
+ schema: Y
987
+ }) ?? {}, await _({
988
+ provider: this.providerOptionsName,
989
+ providerOptions: i,
990
+ schema: Y
991
+ }) ?? {});
992
+ if (e.length > this.maxEmbeddingsPerCall) throw new ee({
993
+ provider: this.provider,
994
+ modelId: this.modelId,
995
+ maxEmbeddingsPerCall: this.maxEmbeddingsPerCall,
996
+ values: e
997
+ });
998
+ let { responseHeaders: c, value: l, rawValue: u } = await y({
999
+ url: this.config.url({
1000
+ path: "/embeddings",
1001
+ modelId: this.modelId
1002
+ }),
1003
+ headers: x(this.config.headers?.(), n),
1004
+ body: {
1005
+ model: this.modelId,
1006
+ input: e,
1007
+ encoding_format: "float",
1008
+ dimensions: s.dimensions,
1009
+ user: s.user
1010
+ },
1011
+ failedResponseHandler: j(this.config.errorStructure ?? P),
1012
+ successfulResponseHandler: t(X),
1013
+ abortSignal: r,
1014
+ fetch: this.config.fetch
1015
+ });
1016
+ return {
1017
+ warnings: a,
1018
+ embeddings: l.data.map((e) => e.embedding),
1019
+ usage: l.usage ? { tokens: l.usage.prompt_tokens } : void 0,
1020
+ providerMetadata: l.providerMetadata,
1021
+ response: {
1022
+ headers: c,
1023
+ body: u
1024
+ }
1025
+ };
1026
+ }
1027
+ }, X = v({
1028
+ data: i(v({ embedding: i(C()) })),
1029
+ usage: v({ prompt_tokens: C() }).nullish(),
1030
+ providerMetadata: k(E(), k(E(), O())).optional()
1031
+ }), pe = class e {
1032
+ constructor(e, t) {
1033
+ this.modelId = e, this.config = t, this.specificationVersion = "v4", this.maxImagesPerCall = 10, this.supportsFileInputs = void 0, this.supportsMaskInputs = void 0;
1034
+ }
1035
+ get provider() {
1036
+ return this.config.provider;
1037
+ }
1038
+ get providerOptionsKey() {
1039
+ return this.config.provider.split(".")[0].trim();
1040
+ }
1041
+ static [r](e) {
1042
+ return T({
1043
+ modelId: e.modelId,
1044
+ config: e.config
1045
+ });
1046
+ }
1047
+ static [f](t) {
1048
+ return new e(t.modelId, t.config);
1049
+ }
1050
+ getArgs(e, t) {
1051
+ return N({
1052
+ rawName: this.providerOptionsKey,
1053
+ providerOptions: e,
1054
+ warnings: t
1055
+ }), {
1056
+ ...e[this.providerOptionsKey],
1057
+ ...e[M(this.providerOptionsKey)]
1058
+ };
1059
+ }
1060
+ async doGenerate({ prompt: e, n, size: r, aspectRatio: i, seed: a, providerOptions: o, headers: s, abortSignal: c, files: l, mask: u }) {
1061
+ let d = [];
1062
+ i != null && d.push({
1063
+ type: "unsupported",
1064
+ feature: "aspectRatio",
1065
+ details: "This model does not support aspect ratio. Use `size` instead."
1066
+ }), a != null && d.push({
1067
+ type: "unsupported",
1068
+ feature: "seed"
1069
+ });
1070
+ let f = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date(), p = this.getArgs(o, d);
1071
+ if (l != null && l.length > 0) {
1072
+ let { value: i, responseHeaders: a } = await ie({
1073
+ url: this.config.url({
1074
+ path: "/images/edits",
1075
+ modelId: this.modelId
1076
+ }),
1077
+ headers: x(this.config.headers?.(), s),
1078
+ formData: A({
1079
+ model: this.modelId,
1080
+ prompt: e,
1081
+ image: await Promise.all(l.map((e) => $(e))),
1082
+ mask: u == null ? void 0 : await $(u),
1083
+ n,
1084
+ size: r,
1085
+ ...p
1086
+ }),
1087
+ failedResponseHandler: j(this.config.errorStructure ?? P),
1088
+ successfulResponseHandler: t(Q),
1089
+ abortSignal: c,
1090
+ fetch: this.config.fetch
1091
+ });
1092
+ return {
1093
+ images: i.data.map((e) => e.b64_json),
1094
+ warnings: d,
1095
+ usage: Z(i.usage),
1096
+ response: {
1097
+ timestamp: f,
1098
+ modelId: this.modelId,
1099
+ headers: a
1100
+ }
1101
+ };
1102
+ }
1103
+ let { value: m, responseHeaders: h } = await y({
1104
+ url: this.config.url({
1105
+ path: "/images/generations",
1106
+ modelId: this.modelId
1107
+ }),
1108
+ headers: x(this.config.headers?.(), s),
1109
+ body: {
1110
+ model: this.modelId,
1111
+ prompt: e,
1112
+ n,
1113
+ size: r,
1114
+ ...p
1115
+ },
1116
+ failedResponseHandler: j(this.config.errorStructure ?? P),
1117
+ successfulResponseHandler: t(Q),
1118
+ abortSignal: c,
1119
+ fetch: this.config.fetch
1120
+ });
1121
+ return {
1122
+ images: m.data.map((e) => e.b64_json),
1123
+ warnings: d,
1124
+ usage: Z(m.usage),
1125
+ response: {
1126
+ timestamp: f,
1127
+ modelId: this.modelId,
1128
+ headers: h
1129
+ }
1130
+ };
1131
+ }
1132
+ };
1133
+ function Z(e) {
1134
+ return e == null ? void 0 : {
1135
+ inputTokens: e.input_tokens ?? void 0,
1136
+ outputTokens: e.output_tokens ?? void 0,
1137
+ totalTokens: e.total_tokens ?? void 0
1138
+ };
1139
+ }
1140
+ var Q = v({
1141
+ data: i(v({ b64_json: E() })),
1142
+ usage: v({
1143
+ input_tokens: C().nullish(),
1144
+ output_tokens: C().nullish(),
1145
+ total_tokens: C().nullish()
1146
+ }).nullish()
1147
+ });
1148
+ async function $(e) {
1149
+ if (e.type === "url") return o(e.url);
1150
+ let t = e.data instanceof Uint8Array ? e.data : S(e.data);
1151
+ return new Blob([t], { type: e.mediaType });
1152
+ }
1153
+ function me(e) {
1154
+ let t = ae(e.baseURL), n = e.name, r = {
1155
+ ...e.apiKey && { Authorization: `Bearer ${e.apiKey}` },
1156
+ ...e.headers
1157
+ }, i = () => c(r, "ai-sdk-openai-compatible/3.0.59"), a = (r) => ({
1158
+ provider: `${n}.${r}`,
1159
+ url: ({ path: n }) => {
1160
+ let r = new URL(`${t}${n}`);
1161
+ return e.queryParams && (r.search = new URLSearchParams(e.queryParams).toString()), r.toString();
1162
+ },
1163
+ headers: i,
1164
+ fetch: e.fetch
1165
+ }), o = (e) => s(e), s = (t) => new ce(t, {
1166
+ ...a("chat"),
1167
+ includeUsage: e.includeUsage,
1168
+ supportsStructuredOutputs: e.supportsStructuredOutputs,
1169
+ supportedUrls: e.supportedUrls,
1170
+ transformRequestBody: e.transformRequestBody,
1171
+ metadataExtractor: e.metadataExtractor,
1172
+ convertUsage: e.convertUsage
1173
+ }), l = (e) => new fe(e, { ...a("embedding") }), u = (e) => o(e);
1174
+ return u.specificationVersion = "v4", u.languageModel = o, u.chatModel = s, u.completionModel = (t) => new le(t, {
1175
+ ...a("completion"),
1176
+ includeUsage: e.includeUsage
1177
+ }), u.embeddingModel = l, u.textEmbeddingModel = l, u.imageModel = (e) => new pe(e, a("image")), u;
1178
+ }
1179
+ export { me as createOpenAICompatible };