@hintergrund/ui 0.3.4 → 0.3.7

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 (87) hide show
  1. package/dist/BuilderAgentPane-Vj3NCGvZ.js +25916 -0
  2. package/dist/IntegrationHealth-D1HcBrQn.js +218 -0
  3. package/dist/admin.js +22766 -28480
  4. package/dist/anthropic-messages-D8Vp-Ncs.js +3772 -0
  5. package/dist/azure-openai-responses-DnjyYuiz.js +168 -0
  6. package/dist/builder.js +27 -22
  7. package/dist/config.types-DZ5yfeqq.js +20 -0
  8. package/dist/deferred-tools-nxpq94I4.js +34 -0
  9. package/dist/diagnostics-x5QOwca_.js +91 -0
  10. package/dist/error-body-pXgvw5vV.js +68 -0
  11. package/dist/font-pool/LICENSES.txt +22 -0
  12. package/dist/font-pool/inter.ttf +0 -0
  13. package/dist/font-pool/inter.woff2 +0 -0
  14. package/dist/font-pool/jetbrains-mono.ttf +0 -0
  15. package/dist/font-pool/jetbrains-mono.woff2 +0 -0
  16. package/dist/font-pool/lora.ttf +0 -0
  17. package/dist/font-pool/lora.woff2 +0 -0
  18. package/dist/font-pool/merriweather.ttf +0 -0
  19. package/dist/font-pool/merriweather.woff2 +0 -0
  20. package/dist/font-pool/montserrat.ttf +0 -0
  21. package/dist/font-pool/montserrat.woff2 +0 -0
  22. package/dist/font-pool/playfair-display.ttf +0 -0
  23. package/dist/font-pool/playfair-display.woff2 +0 -0
  24. package/dist/font-pool/poppins.ttf +0 -0
  25. package/dist/font-pool/poppins.woff2 +0 -0
  26. package/dist/font-pool/roboto.ttf +0 -0
  27. package/dist/font-pool/roboto.woff2 +0 -0
  28. package/dist/font-pool/space-grotesk.ttf +0 -0
  29. package/dist/font-pool/space-grotesk.woff2 +0 -0
  30. package/dist/font-pool/work-sans.ttf +0 -0
  31. package/dist/font-pool/work-sans.woff2 +0 -0
  32. package/dist/github-copilot-headers-pRo3v4t7.js +27 -0
  33. package/dist/global-xsR9gLDa.js +30568 -0
  34. package/dist/google-generative-ai-BmzNjEvl.js +291 -0
  35. package/dist/google-shared-CG2Lbh1z.js +8746 -0
  36. package/dist/google-vertex-Dfla93V_.js +329 -0
  37. package/dist/hash-BixfZjoG.js +21 -0
  38. package/dist/headers-CnTiKpOL.js +24 -0
  39. package/dist/json-parse-CxjAnWaM.js +231 -0
  40. package/dist/legacy-Zmnk-v81.js +14 -0
  41. package/dist/login.js +131 -146
  42. package/dist/mail.js +694 -789
  43. package/dist/mistral-conversations-DeDb7Gbd.js +558 -0
  44. package/dist/openai-ClxLHXsh.js +5371 -0
  45. package/dist/openai-codex-responses-usgOtWUT.js +909 -0
  46. package/dist/openai-completions-D_nFQy7A.js +730 -0
  47. package/dist/openai-prompt-cache-Bm8Re6Vv.js +17 -0
  48. package/dist/openai-responses-BqL3PFsb.js +192 -0
  49. package/dist/openai-responses-shared-BhQj78KM.js +481 -0
  50. package/dist/pi-messages-CRx0yqMp.js +268 -0
  51. package/dist/pi-user-agent-CsXkkH60.js +20 -0
  52. package/dist/provider-env-Cj6X7Wly.js +35 -0
  53. package/dist/provider-retry-BGImU1PV.js +68 -0
  54. package/dist/rolldown-runtime-nTTD767F.js +37 -0
  55. package/dist/setup.js +391 -418
  56. package/dist/transform-messages-DvxSeyBQ.js +383 -0
  57. package/dist/ui.css +2 -1
  58. package/package.json +5 -5
  59. package/dist/BuilderAgentPane-CwG29LOX.js +0 -13938
  60. package/dist/IntegrationHealth-G_4vzV66.js +0 -209
  61. package/dist/anthropic-messages-BmLfYiwX.js +0 -5605
  62. package/dist/azure-openai-responses-yf2M6GVe.js +0 -222
  63. package/dist/client-Cd7yMX39.js +0 -7860
  64. package/dist/config.types-iZoywORE.js +0 -15
  65. package/dist/deferred-tools-BZWMWBYN.js +0 -28
  66. package/dist/error-body-BUPcH4GF.js +0 -71
  67. package/dist/github-copilot-headers-B1RBGoZi.js +0 -21
  68. package/dist/global-CTQcFve1.js +0 -36177
  69. package/dist/google-generative-ai-DkzwUYzL.js +0 -264
  70. package/dist/google-shared-DTgKMtfJ.js +0 -11710
  71. package/dist/google-vertex-D2IzqvQM.js +0 -305
  72. package/dist/hash-DFlR084x.js +0 -14
  73. package/dist/headers-D4iLzGaS.js +0 -21
  74. package/dist/json-parse-LZdWp-Nd.js +0 -232
  75. package/dist/legacy-CckexQcJ.js +0 -5
  76. package/dist/mistral-conversations-CNfKG0tU.js +0 -513
  77. package/dist/openai-codex-responses-BLNjExaC.js +0 -947
  78. package/dist/openai-completions-46IVoF2N.js +0 -741
  79. package/dist/openai-prompt-cache-BJwqbEDx.js +0 -13
  80. package/dist/openai-responses-BfHoZFHI.js +0 -184
  81. package/dist/openai-responses-shared-DOTQAbCj.js +0 -477
  82. package/dist/pi-messages-fnW87Z4Z.js +0 -251
  83. package/dist/pi-user-agent-CUqx-qiX.js +0 -13
  84. package/dist/provider-env-D2VjEV3S.js +0 -26
  85. package/dist/provider-retry-BsigVlMg.js +0 -67
  86. package/dist/select-Cke4DYH1.js +0 -78
  87. package/dist/transform-messages-CsKsy6b4.js +0 -398
@@ -0,0 +1,558 @@
1
+ globalThis.process === void 0 && (globalThis.process = {
2
+ env: {},
3
+ platform: "browser",
4
+ version: "",
5
+ versions: {},
6
+ browser: !0,
7
+ nextTick: function(e) {
8
+ return Promise.resolve().then(e);
9
+ }
10
+ });
11
+ import { g as e, h as t } from "./BuilderAgentPane-Vj3NCGvZ.js";
12
+ import { i as n } from "./diagnostics-x5QOwca_.js";
13
+ import { n as r } from "./json-parse-CxjAnWaM.js";
14
+ import { t as i } from "./headers-CnTiKpOL.js";
15
+ import { f as a, i as o, p as s, t as c, u as l } from "./transform-messages-DvxSeyBQ.js";
16
+ import { t as u } from "./hash-BixfZjoG.js";
17
+ //#region ../../../../node_modules/.pnpm/@earendil-works+pi-ai@0.84.2_supports-color@10.2.2_ws@8.21.3_zod@4.4.3/node_modules/@earendil-works/pi-ai/dist/api/mistral-conversations.js
18
+ var d = 9, f = 4e3, p = (e, t, r) => {
19
+ let i = new n();
20
+ return (async () => {
21
+ let n = h(e);
22
+ try {
23
+ let a = r?.apiKey;
24
+ if (!a) throw Error(`No API key for provider: ${e.provider}`);
25
+ let o = g(), s = F(e, t, c(t.messages, e, (e) => o(e)), r), l = await r?.onPayload?.(s, e);
26
+ l !== void 0 && (s = l);
27
+ let u = await x(e, s, a, r);
28
+ if (i.push({
29
+ type: "start",
30
+ partial: n
31
+ }), await R(e, n, i, u), r?.signal?.aborted) throw Error("Request was aborted");
32
+ if (n.stopReason === "pending") throw Error("Mistral stream ended without a finish reason");
33
+ if (n.stopReason === "aborted" || n.stopReason === "error") throw Error(n.errorMessage || "An unknown error occurred");
34
+ i.push({
35
+ type: "done",
36
+ reason: n.stopReason,
37
+ message: n
38
+ }), i.end();
39
+ } catch (e) {
40
+ for (let e of n.content) delete e.partialArgs;
41
+ n.stopReason = r?.signal?.aborted ? "aborted" : "error", n.errorMessage = v(e), i.push({
42
+ type: "error",
43
+ reason: n.stopReason,
44
+ error: n
45
+ }), i.end();
46
+ }
47
+ })(), i;
48
+ }, m = (t, n, r) => {
49
+ let i = r?.apiKey;
50
+ if (!i) throw Error(`No API key for provider: ${t.provider}`);
51
+ let a = o(t, n, r, i), s = r?.reasoning ? e(t, r.reasoning) : void 0, c = s === "off" ? void 0 : s, l = t.reasoning && c !== void 0;
52
+ return p(t, n, {
53
+ ...a,
54
+ promptMode: l && W(t) ? "reasoning" : void 0,
55
+ reasoningEffort: l && U(t) ? G(t, c) : void 0
56
+ });
57
+ };
58
+ function h(e) {
59
+ return {
60
+ role: "assistant",
61
+ content: [],
62
+ api: e.api,
63
+ provider: e.provider,
64
+ model: e.id,
65
+ usage: {
66
+ input: 0,
67
+ output: 0,
68
+ cacheRead: 0,
69
+ cacheWrite: 0,
70
+ totalTokens: 0,
71
+ cost: {
72
+ input: 0,
73
+ output: 0,
74
+ cacheRead: 0,
75
+ cacheWrite: 0,
76
+ total: 0
77
+ }
78
+ },
79
+ stopReason: "pending",
80
+ timestamp: Date.now()
81
+ };
82
+ }
83
+ function g() {
84
+ let e = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Map();
85
+ return (n) => {
86
+ let r = e.get(n);
87
+ if (r) return r;
88
+ let i = 0;
89
+ for (;;) {
90
+ let r = _(n, i), a = t.get(r);
91
+ if (!a || a === n) return e.set(n, r), t.set(r, n), r;
92
+ i++;
93
+ }
94
+ };
95
+ }
96
+ function _(e, t) {
97
+ let n = e.replace(/[^a-zA-Z0-9]/g, "");
98
+ if (t === 0 && n.length === d) return n;
99
+ let r = n || e, i = t === 0 ? r : `${r}:${t}`;
100
+ return u(i).replace(/[^a-zA-Z0-9]/g, "").slice(0, d);
101
+ }
102
+ function v(e) {
103
+ if (e instanceof Error) {
104
+ let t = e, n = typeof t.statusCode == "number" ? t.statusCode : void 0, r = typeof t.body == "string" ? t.body.trim() : void 0;
105
+ return n !== void 0 && r ? `Mistral API error (${n}): ${y(r, f)}` : n === void 0 ? e.message : `Mistral API error (${n}): ${e.message}`;
106
+ }
107
+ return b(e);
108
+ }
109
+ function y(e, t) {
110
+ return e.length <= t ? e : `${e.slice(0, t)}... [truncated ${e.length - t} chars]`;
111
+ }
112
+ function b(e) {
113
+ try {
114
+ let t = JSON.stringify(e);
115
+ return t === void 0 ? String(e) : t;
116
+ } catch {
117
+ return String(e);
118
+ }
119
+ }
120
+ async function x(e, t, n, r) {
121
+ let a = new URL(e.baseUrl);
122
+ a.pathname = `${a.pathname.replace(/\/+$/u, "")}/`;
123
+ let o = new URL("v1/chat/completions", a), s = C(e, n, r), c = AbortSignal.timeout(r?.timeoutMs ?? 6e4), l = r?.signal ? AbortSignal.any([r.signal, c]) : c, u = await (r?.fetch ?? globalThis.fetch)(o, {
124
+ method: "POST",
125
+ headers: s,
126
+ body: JSON.stringify(E(t)),
127
+ signal: l
128
+ });
129
+ if (await r?.onResponse?.({
130
+ status: u.status,
131
+ headers: i(u.headers)
132
+ }, e), !u.ok) {
133
+ let e = await u.text();
134
+ throw new S(u.status, e, u.statusText);
135
+ }
136
+ if (!u.body) throw Error("Mistral response has no body");
137
+ return M(u.body, l);
138
+ }
139
+ var S = class extends Error {
140
+ statusCode;
141
+ body;
142
+ constructor(e, t, n) {
143
+ super(n || `Request failed with status ${e}`), this.name = "MistralHttpError", this.statusCode = e, this.body = t;
144
+ }
145
+ };
146
+ function C(e, t, n) {
147
+ let r = new Headers({
148
+ accept: "text/event-stream",
149
+ authorization: `Bearer ${t}`,
150
+ "content-type": "application/json"
151
+ });
152
+ w(r, e.headers), w(r, n?.headers);
153
+ let i = T(e.headers, "x-affinity") || T(n?.headers, "x-affinity");
154
+ return I(n) && !i && r.set("x-affinity", n.sessionId), r;
155
+ }
156
+ function w(e, t) {
157
+ if (t) for (let [n, r] of Object.entries(t)) r === null ? e.delete(n) : e.set(n, r);
158
+ }
159
+ function T(e, t) {
160
+ return !!e && Object.keys(e).some((e) => e.toLowerCase() === t);
161
+ }
162
+ function E(e) {
163
+ let t = { ...e };
164
+ for (let [e, n] of [
165
+ ["topP", "top_p"],
166
+ ["maxTokens", "max_tokens"],
167
+ ["randomSeed", "random_seed"],
168
+ ["responseFormat", "response_format"],
169
+ ["toolChoice", "tool_choice"],
170
+ ["presencePenalty", "presence_penalty"],
171
+ ["frequencyPenalty", "frequency_penalty"],
172
+ ["parallelToolCalls", "parallel_tool_calls"],
173
+ ["reasoningEffort", "reasoning_effort"],
174
+ ["promptMode", "prompt_mode"],
175
+ ["promptCacheKey", "prompt_cache_key"],
176
+ ["safePrompt", "safe_prompt"]
177
+ ]) k(t, e, n);
178
+ t.messages = e.messages.map((e) => D(e));
179
+ let n = t.response_format;
180
+ if (A(n)) {
181
+ let e = { ...n };
182
+ k(e, "jsonSchema", "json_schema");
183
+ let r = e.json_schema;
184
+ if (A(r)) {
185
+ let t = { ...r };
186
+ k(t, "schemaDefinition", "schema"), e.json_schema = t;
187
+ }
188
+ t.response_format = e;
189
+ }
190
+ return t;
191
+ }
192
+ function D(e) {
193
+ let t = { ...e };
194
+ return k(t, "toolCalls", "tool_calls"), k(t, "toolCallId", "tool_call_id"), Array.isArray(e.content) && (t.content = e.content.map((e) => O(e))), t;
195
+ }
196
+ function O(e) {
197
+ let t = { ...e };
198
+ for (let [e, n] of [
199
+ ["imageUrl", "image_url"],
200
+ ["documentUrl", "document_url"],
201
+ ["documentName", "document_name"],
202
+ ["fileId", "file_id"],
203
+ ["referenceIds", "reference_ids"],
204
+ ["inputAudio", "input_audio"]
205
+ ]) k(t, e, n);
206
+ return t;
207
+ }
208
+ function k(e, t, n) {
209
+ t in e && (e[n] = e[t], delete e[t]);
210
+ }
211
+ function A(e) {
212
+ return typeof e == "object" && !!e && !Array.isArray(e);
213
+ }
214
+ var j = Symbol("mistral-stream-done");
215
+ async function* M(e, t) {
216
+ let n = e.getReader(), r = new TextDecoder(), i = "", a = () => {
217
+ n.cancel().catch(() => {});
218
+ };
219
+ t.addEventListener("abort", a, { once: !0 });
220
+ try {
221
+ for (;;) {
222
+ if (t.aborted) throw t.reason;
223
+ let { done: e, value: a } = await n.read();
224
+ if (t.aborted) throw t.reason;
225
+ i += e ? r.decode() : r.decode(a, { stream: !0 });
226
+ let o = N(i);
227
+ for (; o;) {
228
+ let e = P(i.slice(0, o.index));
229
+ if (i = i.slice(o.index + o.length), e === j) return;
230
+ e && (yield e), o = N(i);
231
+ }
232
+ if (e) break;
233
+ }
234
+ if (i.trim()) {
235
+ let e = P(i);
236
+ e !== j && e && (yield e);
237
+ }
238
+ } finally {
239
+ t.removeEventListener("abort", a);
240
+ try {
241
+ await n.cancel();
242
+ } catch {}
243
+ try {
244
+ n.releaseLock();
245
+ } catch {}
246
+ }
247
+ }
248
+ function N(e) {
249
+ let t = /\r\n\r\n|\r\n\r|\r\n\n|\r\r\n|\n\r\n|\r\r|\n\r|\n\n/u.exec(e);
250
+ return t?.index === void 0 ? void 0 : {
251
+ index: t.index,
252
+ length: t[0].length
253
+ };
254
+ }
255
+ function P(e) {
256
+ let t = e.split(/\r\n|\r|\n/u).filter((e) => e.startsWith("data:")).map((e) => e.slice(5).trimStart()).join("\n").trim();
257
+ if (!t) return;
258
+ if (t === "[DONE]") return j;
259
+ let n = JSON.parse(t);
260
+ if (!A(n) || !Array.isArray(n.choices)) throw Error("Invalid Mistral streaming event");
261
+ return { data: n };
262
+ }
263
+ function F(e, t, n, r) {
264
+ let i = {
265
+ model: e.id,
266
+ stream: !0,
267
+ messages: V(n, e.input.includes("image"))
268
+ };
269
+ return t.tools?.length && (i.tools = z(t.tools)), r?.temperature !== void 0 && (i.temperature = r.temperature), r?.maxTokens !== void 0 && (i.maxTokens = r.maxTokens), r?.toolChoice && (i.toolChoice = K(r.toolChoice)), r?.promptMode && (i.promptMode = r.promptMode), r?.reasoningEffort && (i.reasoningEffort = r.reasoningEffort), I(r) && (i.promptCacheKey = r.sessionId), t.systemPrompt && i.messages.unshift({
270
+ role: "system",
271
+ content: s(t.systemPrompt)
272
+ }), i;
273
+ }
274
+ function I(e) {
275
+ return e?.cacheRetention !== "none" && !!e?.sessionId;
276
+ }
277
+ function L(e, t) {
278
+ let n = e, r = n.promptTokensDetails?.cachedTokens ?? n.prompt_tokens_details?.cached_tokens ?? n.promptTokenDetails?.cachedTokens ?? n.prompt_token_details?.cached_tokens ?? n.numCachedTokens ?? n.num_cached_tokens ?? 0;
279
+ return Math.min(t, Math.max(0, typeof r == "number" && Number.isFinite(r) ? r : 0));
280
+ }
281
+ async function R(e, n, i, a) {
282
+ let o = null, c = n.content, l = () => c.length - 1, u = /* @__PURE__ */ new Map(), d = (e) => {
283
+ if (e) {
284
+ if (e.type === "text") {
285
+ i.push({
286
+ type: "text_end",
287
+ contentIndex: l(),
288
+ content: e.text,
289
+ partial: n
290
+ });
291
+ return;
292
+ }
293
+ e.type === "thinking" && i.push({
294
+ type: "thinking_end",
295
+ contentIndex: l(),
296
+ content: e.thinking,
297
+ partial: n
298
+ });
299
+ }
300
+ };
301
+ for await (let c of a) {
302
+ let a = c.data;
303
+ if (n.responseId ||= a.id, a.usage) {
304
+ let r = a.usage.prompt_tokens || 0, i = L(a.usage, r);
305
+ n.usage.input = Math.max(0, r - i), n.usage.output = a.usage.completion_tokens || 0, n.usage.cacheRead = i, n.usage.cacheWrite = 0, n.usage.totalTokens = a.usage.total_tokens || n.usage.input + n.usage.output + n.usage.cacheRead + n.usage.cacheWrite, t(e, n.usage);
306
+ }
307
+ let f = a.choices[0];
308
+ if (!f) continue;
309
+ if (f.finish_reason) {
310
+ n.rawStopReason = f.finish_reason;
311
+ let e = q(f.finish_reason);
312
+ n.stopReason = e.stopReason, e.errorMessage && (n.errorMessage = e.errorMessage);
313
+ }
314
+ let p = f.delta;
315
+ if (p.content !== null && p.content !== void 0) {
316
+ let e = typeof p.content == "string" ? [p.content] : p.content;
317
+ for (let t of e) {
318
+ if (typeof t == "string") {
319
+ let e = s(t);
320
+ (!o || o.type !== "text") && (d(o), o = {
321
+ type: "text",
322
+ text: ""
323
+ }, n.content.push(o), i.push({
324
+ type: "text_start",
325
+ contentIndex: l(),
326
+ partial: n
327
+ })), o.text += e, i.push({
328
+ type: "text_delta",
329
+ contentIndex: l(),
330
+ delta: e,
331
+ partial: n
332
+ });
333
+ continue;
334
+ }
335
+ if (t.type === "thinking") {
336
+ let e = (t.thinking ?? []).map((e) => e.text ?? "").filter((e) => e.length > 0).join(""), r = s(e);
337
+ if (!r) continue;
338
+ (!o || o.type !== "thinking") && (d(o), o = {
339
+ type: "thinking",
340
+ thinking: ""
341
+ }, n.content.push(o), i.push({
342
+ type: "thinking_start",
343
+ contentIndex: l(),
344
+ partial: n
345
+ })), o.thinking += r, i.push({
346
+ type: "thinking_delta",
347
+ contentIndex: l(),
348
+ delta: r,
349
+ partial: n
350
+ });
351
+ continue;
352
+ }
353
+ if (t.type === "text") {
354
+ let e = s(t.text ?? "");
355
+ (!o || o.type !== "text") && (d(o), o = {
356
+ type: "text",
357
+ text: ""
358
+ }, n.content.push(o), i.push({
359
+ type: "text_start",
360
+ contentIndex: l(),
361
+ partial: n
362
+ })), o.text += e, i.push({
363
+ type: "text_delta",
364
+ contentIndex: l(),
365
+ delta: e,
366
+ partial: n
367
+ });
368
+ }
369
+ }
370
+ }
371
+ let m = p.tool_calls || [];
372
+ for (let e of m) {
373
+ o &&= (d(o), null);
374
+ let t = e.id && e.id !== "null" ? e.id : _(`toolcall:${e.index ?? 0}`, 0), a = `${t}:${e.index || 0}`, s = u.get(a), c;
375
+ if (s !== void 0) {
376
+ let e = n.content[s];
377
+ e?.type === "toolCall" && (c = e);
378
+ }
379
+ c || (c = {
380
+ type: "toolCall",
381
+ id: t,
382
+ name: e.function.name,
383
+ arguments: {},
384
+ partialArgs: ""
385
+ }, n.content.push(c), u.set(a, n.content.length - 1), i.push({
386
+ type: "toolcall_start",
387
+ contentIndex: n.content.length - 1,
388
+ partial: n
389
+ }));
390
+ let l = typeof e.function.arguments == "string" ? e.function.arguments : JSON.stringify(e.function.arguments || {});
391
+ c.partialArgs = (c.partialArgs || "") + l, c.arguments = r(c.partialArgs), i.push({
392
+ type: "toolcall_delta",
393
+ contentIndex: u.get(a),
394
+ delta: l,
395
+ partial: n
396
+ });
397
+ }
398
+ }
399
+ d(o);
400
+ for (let e of u.values()) {
401
+ let t = n.content[e];
402
+ if (t.type !== "toolCall") continue;
403
+ let a = t;
404
+ a.arguments = r(a.partialArgs), delete a.partialArgs, i.push({
405
+ type: "toolcall_end",
406
+ contentIndex: e,
407
+ toolCall: a,
408
+ partial: n
409
+ });
410
+ }
411
+ }
412
+ function z(e) {
413
+ return e.map((e) => {
414
+ let t = a(e, !0);
415
+ return {
416
+ type: "function",
417
+ function: {
418
+ name: e.name,
419
+ description: e.description,
420
+ parameters: B(l(e, t)),
421
+ strict: t ?? !1
422
+ }
423
+ };
424
+ });
425
+ }
426
+ function B(e) {
427
+ if (Array.isArray(e)) return e.map((e) => B(e));
428
+ if (e && typeof e == "object") {
429
+ let t = {};
430
+ for (let [n, r] of Object.entries(e)) t[n] = B(r);
431
+ return t;
432
+ }
433
+ return e;
434
+ }
435
+ function V(e, t) {
436
+ let n = [];
437
+ for (let r of e) {
438
+ if (r.role === "user") {
439
+ if (typeof r.content == "string") {
440
+ n.push({
441
+ role: "user",
442
+ content: s(r.content)
443
+ });
444
+ continue;
445
+ }
446
+ let e = r.content.some((e) => e.type === "image"), i = r.content.filter((e) => e.type === "text" || t).map((e) => e.type === "text" ? {
447
+ type: "text",
448
+ text: s(e.text)
449
+ } : {
450
+ type: "image_url",
451
+ imageUrl: `data:${e.mimeType};base64,${e.data}`
452
+ });
453
+ if (i.length > 0) {
454
+ n.push({
455
+ role: "user",
456
+ content: i
457
+ });
458
+ continue;
459
+ }
460
+ e && !t && n.push({
461
+ role: "user",
462
+ content: "(image omitted: model does not support images)"
463
+ });
464
+ continue;
465
+ }
466
+ if (r.role === "assistant") {
467
+ let e = [], t = [];
468
+ for (let n of r.content) {
469
+ if (n.type === "text") {
470
+ n.text.trim().length > 0 && e.push({
471
+ type: "text",
472
+ text: s(n.text)
473
+ });
474
+ continue;
475
+ }
476
+ if (n.type === "thinking") {
477
+ n.thinking.trim().length > 0 && e.push({
478
+ type: "thinking",
479
+ thinking: [{
480
+ type: "text",
481
+ text: s(n.thinking)
482
+ }]
483
+ });
484
+ continue;
485
+ }
486
+ t.push({
487
+ id: n.id,
488
+ type: "function",
489
+ function: {
490
+ name: n.name,
491
+ arguments: JSON.stringify(n.arguments || {})
492
+ },
493
+ index: 0
494
+ });
495
+ }
496
+ let i = {
497
+ role: "assistant",
498
+ prefix: !1
499
+ };
500
+ e.length > 0 && (i.content = e), t.length > 0 && (i.toolCalls = t), (e.length > 0 || t.length > 0) && n.push(i);
501
+ continue;
502
+ }
503
+ let e = [], i = H(r.content.filter((e) => e.type === "text").map((e) => e.type === "text" ? s(e.text) : "").join("\n"), r.content.some((e) => e.type === "image"), t, r.isError);
504
+ e.push({
505
+ type: "text",
506
+ text: i
507
+ });
508
+ for (let n of r.content) t && n.type === "image" && e.push({
509
+ type: "image_url",
510
+ imageUrl: `data:${n.mimeType};base64,${n.data}`
511
+ });
512
+ n.push({
513
+ role: "tool",
514
+ toolCallId: r.toolCallId,
515
+ name: r.toolName,
516
+ content: e
517
+ });
518
+ }
519
+ return n;
520
+ }
521
+ function H(e, t, n, r) {
522
+ let i = e.trim(), a = r ? "[tool error] " : "";
523
+ return i.length > 0 ? `${a}${i}${t && !n ? "\n[tool image omitted: model does not support images]" : ""}` : t ? n ? r ? "[tool error] (see attached image)" : "(see attached image)" : r ? "[tool error] (image omitted: model does not support images)" : "(image omitted: model does not support images)" : r ? "[tool error] (no tool output)" : "(no tool output)";
524
+ }
525
+ function U(e) {
526
+ return e.id === "mistral-small-2603" || e.id === "mistral-small-latest" || e.id === "mistral-medium-3.5";
527
+ }
528
+ function W(e) {
529
+ return e.reasoning && !U(e);
530
+ }
531
+ function G(e, t) {
532
+ return e.thinkingLevelMap?.[t] ?? "high";
533
+ }
534
+ function K(e) {
535
+ if (e) return e === "auto" || e === "none" || e === "any" || e === "required" ? e : {
536
+ type: "function",
537
+ function: { name: e.function.name }
538
+ };
539
+ }
540
+ function q(e) {
541
+ if (e === null) return { stopReason: "stop" };
542
+ switch (e) {
543
+ case "stop": return { stopReason: "stop" };
544
+ case "length":
545
+ case "model_length": return { stopReason: "length" };
546
+ case "tool_calls": return { stopReason: "toolUse" };
547
+ case "error": return {
548
+ stopReason: "error",
549
+ errorMessage: "Provider stopped with: error"
550
+ };
551
+ default: return {
552
+ stopReason: "error",
553
+ errorMessage: `Provider stopped with: ${e}`
554
+ };
555
+ }
556
+ }
557
+ //#endregion
558
+ export { p as stream, m as streamSimple };