@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
@@ -1,513 +0,0 @@
1
- import { D as L, G as j, H as D } from "./BuilderAgentPane-CwG29LOX.js";
2
- import { s as N } from "./hash-DFlR084x.js";
3
- import { h as U } from "./headers-D4iLzGaS.js";
4
- import { p as T } from "./json-parse-LZdWp-Nd.js";
5
- import { t as B, b as H, s as g, d as J, e as z } from "./transform-messages-CsKsy6b4.js";
6
- typeof globalThis.process > "u" && (globalThis.process = { env: {}, platform: "browser", version: "", versions: {}, browser: !0, nextTick: function(t) {
7
- return Promise.resolve().then(t);
8
- } });
9
- const C = 9, K = 4e3, W = (t, e, n) => {
10
- const r = new L();
11
- return (async () => {
12
- const o = q(t);
13
- try {
14
- const l = n?.apiKey;
15
- if (!l)
16
- throw new Error(`No API key for provider: ${t.provider}`);
17
- const i = F(), u = B(e.messages, t, (f) => i(f));
18
- let s = oe(t, e, u, n);
19
- const a = await n?.onPayload?.(s, t);
20
- a !== void 0 && (s = a);
21
- const c = await Y(t, s, l, n);
22
- if (r.push({ type: "start", partial: o }), await ae(t, o, r, c), n?.signal?.aborted)
23
- throw new Error("Request was aborted");
24
- if (o.stopReason === "pending")
25
- throw new Error("Mistral stream ended without a finish reason");
26
- if (o.stopReason === "aborted" || o.stopReason === "error")
27
- throw new Error(o.errorMessage || "An unknown error occurred");
28
- r.push({ type: "done", reason: o.stopReason, message: o }), r.end();
29
- } catch (l) {
30
- for (const i of o.content)
31
- delete i.partialArgs;
32
- o.stopReason = n?.signal?.aborted ? "aborted" : "error", o.errorMessage = G(l), r.push({ type: "error", reason: o.stopReason, error: o }), r.end();
33
- }
34
- })(), r;
35
- }, _e = (t, e, n) => {
36
- const r = n?.apiKey;
37
- if (!r)
38
- throw new Error(`No API key for provider: ${t.provider}`);
39
- const o = H(t, e, n, r), l = n?.reasoning ? j(t, n.reasoning) : void 0, i = l === "off" ? void 0 : l, u = t.reasoning && i !== void 0;
40
- return W(t, e, {
41
- ...o,
42
- promptMode: u && fe(t) ? "reasoning" : void 0,
43
- reasoningEffort: u && $(t) ? de(t, i) : void 0
44
- });
45
- };
46
- function q(t) {
47
- return {
48
- role: "assistant",
49
- content: [],
50
- api: t.api,
51
- provider: t.provider,
52
- model: t.id,
53
- usage: {
54
- input: 0,
55
- output: 0,
56
- cacheRead: 0,
57
- cacheWrite: 0,
58
- totalTokens: 0,
59
- cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 }
60
- },
61
- stopReason: "pending",
62
- timestamp: Date.now()
63
- };
64
- }
65
- function F() {
66
- const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map();
67
- return (n) => {
68
- const r = t.get(n);
69
- if (r)
70
- return r;
71
- let o = 0;
72
- for (; ; ) {
73
- const l = P(n, o), i = e.get(l);
74
- if (!i || i === n)
75
- return t.set(n, l), e.set(l, n), l;
76
- o++;
77
- }
78
- };
79
- }
80
- function P(t, e) {
81
- const n = t.replace(/[^a-zA-Z0-9]/g, "");
82
- if (e === 0 && n.length === C)
83
- return n;
84
- const r = n || t, o = e === 0 ? r : `${r}:${e}`;
85
- return N(o).replace(/[^a-zA-Z0-9]/g, "").slice(0, C);
86
- }
87
- function G(t) {
88
- if (t instanceof Error) {
89
- const e = t, n = typeof e.statusCode == "number" ? e.statusCode : void 0, r = typeof e.body == "string" ? e.body.trim() : void 0;
90
- return n !== void 0 && r ? `Mistral API error (${n}): ${Z(r, K)}` : n !== void 0 ? `Mistral API error (${n}): ${t.message}` : t.message;
91
- }
92
- return X(t);
93
- }
94
- function Z(t, e) {
95
- return t.length <= e ? t : `${t.slice(0, e)}... [truncated ${t.length - e} chars]`;
96
- }
97
- function X(t) {
98
- try {
99
- const e = JSON.stringify(t);
100
- return e === void 0 ? String(t) : e;
101
- } catch {
102
- return String(t);
103
- }
104
- }
105
- async function Y(t, e, n, r) {
106
- const o = new URL(t.baseUrl);
107
- o.pathname = `${o.pathname.replace(/\/+$/u, "")}/`;
108
- const l = new URL("v1/chat/completions", o), i = V(t, n, r), u = AbortSignal.timeout(r?.timeoutMs ?? 6e4), s = r?.signal ? AbortSignal.any([r.signal, u]) : u, a = await (r?.fetch ?? globalThis.fetch)(l, {
109
- method: "POST",
110
- headers: i,
111
- body: JSON.stringify(ee(e)),
112
- signal: s
113
- });
114
- if (await r?.onResponse?.({ status: a.status, headers: U(a.headers) }, t), !a.ok) {
115
- const c = await a.text();
116
- throw new Q(a.status, c, a.statusText);
117
- }
118
- if (!a.body)
119
- throw new Error("Mistral response has no body");
120
- return re(a.body, s);
121
- }
122
- class Q extends Error {
123
- statusCode;
124
- body;
125
- constructor(e, n, r) {
126
- super(r || `Request failed with status ${e}`), this.name = "MistralHttpError", this.statusCode = e, this.body = n;
127
- }
128
- }
129
- function V(t, e, n) {
130
- const r = new Headers({
131
- accept: "text/event-stream",
132
- authorization: `Bearer ${e}`,
133
- "content-type": "application/json"
134
- });
135
- S(r, t.headers), S(r, n?.headers);
136
- const o = A(t.headers, "x-affinity") || A(n?.headers, "x-affinity");
137
- return v(n) && !o && r.set("x-affinity", n.sessionId), r;
138
- }
139
- function S(t, e) {
140
- if (e)
141
- for (const [n, r] of Object.entries(e))
142
- r === null ? t.delete(n) : t.set(n, r);
143
- }
144
- function A(t, e) {
145
- return !!t && Object.keys(t).some((n) => n.toLowerCase() === e);
146
- }
147
- function ee(t) {
148
- const e = { ...t };
149
- for (const [r, o] of [
150
- ["topP", "top_p"],
151
- ["maxTokens", "max_tokens"],
152
- ["randomSeed", "random_seed"],
153
- ["responseFormat", "response_format"],
154
- ["toolChoice", "tool_choice"],
155
- ["presencePenalty", "presence_penalty"],
156
- ["frequencyPenalty", "frequency_penalty"],
157
- ["parallelToolCalls", "parallel_tool_calls"],
158
- ["reasoningEffort", "reasoning_effort"],
159
- ["promptMode", "prompt_mode"],
160
- ["promptCacheKey", "prompt_cache_key"],
161
- ["safePrompt", "safe_prompt"]
162
- ])
163
- _(e, r, o);
164
- e.messages = t.messages.map((r) => te(r));
165
- const n = e.response_format;
166
- if (k(n)) {
167
- const r = { ...n };
168
- _(r, "jsonSchema", "json_schema");
169
- const o = r.json_schema;
170
- if (k(o)) {
171
- const l = { ...o };
172
- _(l, "schemaDefinition", "schema"), r.json_schema = l;
173
- }
174
- e.response_format = r;
175
- }
176
- return e;
177
- }
178
- function te(t) {
179
- const e = { ...t };
180
- return _(e, "toolCalls", "tool_calls"), _(e, "toolCallId", "tool_call_id"), Array.isArray(t.content) && (e.content = t.content.map((n) => ne(n))), e;
181
- }
182
- function ne(t) {
183
- const e = { ...t };
184
- for (const [n, r] of [
185
- ["imageUrl", "image_url"],
186
- ["documentUrl", "document_url"],
187
- ["documentName", "document_name"],
188
- ["fileId", "file_id"],
189
- ["referenceIds", "reference_ids"],
190
- ["inputAudio", "input_audio"]
191
- ])
192
- _(e, n, r);
193
- return e;
194
- }
195
- function _(t, e, n) {
196
- e in t && (t[n] = t[e], delete t[e]);
197
- }
198
- function k(t) {
199
- return typeof t == "object" && t !== null && !Array.isArray(t);
200
- }
201
- const M = /* @__PURE__ */ Symbol("mistral-stream-done");
202
- async function* re(t, e) {
203
- const n = t.getReader(), r = new TextDecoder();
204
- let o = "";
205
- const l = () => {
206
- n.cancel().catch(() => {
207
- });
208
- };
209
- e.addEventListener("abort", l, { once: !0 });
210
- try {
211
- for (; ; ) {
212
- if (e.aborted)
213
- throw e.reason;
214
- const { done: i, value: u } = await n.read();
215
- if (e.aborted)
216
- throw e.reason;
217
- o += i ? r.decode() : r.decode(u, { stream: !0 });
218
- let s = I(o);
219
- for (; s; ) {
220
- const a = E(o.slice(0, s.index));
221
- if (o = o.slice(s.index + s.length), a === M)
222
- return;
223
- a && (yield a), s = I(o);
224
- }
225
- if (i)
226
- break;
227
- }
228
- if (o.trim()) {
229
- const i = E(o);
230
- i !== M && i && (yield i);
231
- }
232
- } finally {
233
- e.removeEventListener("abort", l);
234
- try {
235
- await n.cancel();
236
- } catch {
237
- }
238
- try {
239
- n.releaseLock();
240
- } catch {
241
- }
242
- }
243
- }
244
- function I(t) {
245
- const e = /\r\n\r\n|\r\n\r|\r\n\n|\r\r\n|\n\r\n|\r\r|\n\r|\n\n/u.exec(t);
246
- return e?.index === void 0 ? void 0 : { index: e.index, length: e[0].length };
247
- }
248
- function E(t) {
249
- const e = t.split(/\r\n|\r|\n/u).filter((r) => r.startsWith("data:")).map((r) => r.slice(5).trimStart()).join(`
250
- `).trim();
251
- if (!e)
252
- return;
253
- if (e === "[DONE]")
254
- return M;
255
- const n = JSON.parse(e);
256
- if (!k(n) || !Array.isArray(n.choices))
257
- throw new Error("Invalid Mistral streaming event");
258
- return { data: n };
259
- }
260
- function oe(t, e, n, r) {
261
- const o = {
262
- model: t.id,
263
- stream: !0,
264
- messages: ce(n, t.input.includes("image"))
265
- };
266
- return e.tools?.length && (o.tools = ie(e.tools)), r?.temperature !== void 0 && (o.temperature = r.temperature), r?.maxTokens !== void 0 && (o.maxTokens = r.maxTokens), r?.toolChoice && (o.toolChoice = ue(r.toolChoice)), r?.promptMode && (o.promptMode = r.promptMode), r?.reasoningEffort && (o.reasoningEffort = r.reasoningEffort), v(r) && (o.promptCacheKey = r.sessionId), e.systemPrompt && o.messages.unshift({
267
- role: "system",
268
- content: g(e.systemPrompt)
269
- }), o;
270
- }
271
- function v(t) {
272
- return t?.cacheRetention !== "none" && !!t?.sessionId;
273
- }
274
- function se(t, e) {
275
- const n = t, 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, o = typeof r == "number" && Number.isFinite(r) ? r : 0;
276
- return Math.min(e, Math.max(0, o));
277
- }
278
- async function ae(t, e, n, r) {
279
- let o = null;
280
- const l = e.content, i = () => l.length - 1, u = /* @__PURE__ */ new Map(), s = (a) => {
281
- if (a) {
282
- if (a.type === "text") {
283
- n.push({
284
- type: "text_end",
285
- contentIndex: i(),
286
- content: a.text,
287
- partial: e
288
- });
289
- return;
290
- }
291
- a.type === "thinking" && n.push({
292
- type: "thinking_end",
293
- contentIndex: i(),
294
- content: a.thinking,
295
- partial: e
296
- });
297
- }
298
- };
299
- for await (const a of r) {
300
- const c = a.data;
301
- if (e.responseId ||= c.id, c.usage) {
302
- const d = c.usage.prompt_tokens || 0, p = se(c.usage, d);
303
- e.usage.input = Math.max(0, d - p), e.usage.output = c.usage.completion_tokens || 0, e.usage.cacheRead = p, e.usage.cacheWrite = 0, e.usage.totalTokens = c.usage.total_tokens || e.usage.input + e.usage.output + e.usage.cacheRead + e.usage.cacheWrite, D(t, e.usage);
304
- }
305
- const f = c.choices[0];
306
- if (!f)
307
- continue;
308
- if (f.finish_reason) {
309
- e.rawStopReason = f.finish_reason;
310
- const d = pe(f.finish_reason);
311
- e.stopReason = d.stopReason, d.errorMessage && (e.errorMessage = d.errorMessage);
312
- }
313
- const y = f.delta;
314
- if (y.content !== null && y.content !== void 0) {
315
- const d = typeof y.content == "string" ? [y.content] : y.content;
316
- for (const p of d) {
317
- if (typeof p == "string") {
318
- const m = g(p);
319
- (!o || o.type !== "text") && (s(o), o = { type: "text", text: "" }, e.content.push(o), n.push({ type: "text_start", contentIndex: i(), partial: e })), o.text += m, n.push({
320
- type: "text_delta",
321
- contentIndex: i(),
322
- delta: m,
323
- partial: e
324
- });
325
- continue;
326
- }
327
- if (p.type === "thinking") {
328
- const m = (p.thinking ?? []).map((h) => h.text ?? "").filter((h) => h.length > 0).join(""), x = g(m);
329
- if (!x)
330
- continue;
331
- (!o || o.type !== "thinking") && (s(o), o = { type: "thinking", thinking: "" }, e.content.push(o), n.push({ type: "thinking_start", contentIndex: i(), partial: e })), o.thinking += x, n.push({
332
- type: "thinking_delta",
333
- contentIndex: i(),
334
- delta: x,
335
- partial: e
336
- });
337
- continue;
338
- }
339
- if (p.type === "text") {
340
- const m = g(p.text ?? "");
341
- (!o || o.type !== "text") && (s(o), o = { type: "text", text: "" }, e.content.push(o), n.push({ type: "text_start", contentIndex: i(), partial: e })), o.text += m, n.push({
342
- type: "text_delta",
343
- contentIndex: i(),
344
- delta: m,
345
- partial: e
346
- });
347
- }
348
- }
349
- }
350
- const O = y.tool_calls || [];
351
- for (const d of O) {
352
- o && (s(o), o = null);
353
- const p = d.id && d.id !== "null" ? d.id : P(`toolcall:${d.index ?? 0}`, 0), m = `${p}:${d.index || 0}`, x = u.get(m);
354
- let h;
355
- if (x !== void 0) {
356
- const R = e.content[x];
357
- R?.type === "toolCall" && (h = R);
358
- }
359
- h || (h = {
360
- type: "toolCall",
361
- id: p,
362
- name: d.function.name,
363
- arguments: {},
364
- partialArgs: ""
365
- }, e.content.push(h), u.set(m, e.content.length - 1), n.push({ type: "toolcall_start", contentIndex: e.content.length - 1, partial: e }));
366
- const b = typeof d.function.arguments == "string" ? d.function.arguments : JSON.stringify(d.function.arguments || {});
367
- h.partialArgs = (h.partialArgs || "") + b, h.arguments = T(h.partialArgs), n.push({
368
- type: "toolcall_delta",
369
- contentIndex: u.get(m),
370
- delta: b,
371
- partial: e
372
- });
373
- }
374
- }
375
- s(o);
376
- for (const a of u.values()) {
377
- const c = e.content[a];
378
- if (c.type !== "toolCall")
379
- continue;
380
- const f = c;
381
- f.arguments = T(f.partialArgs), delete f.partialArgs, n.push({
382
- type: "toolcall_end",
383
- contentIndex: a,
384
- toolCall: f,
385
- partial: e
386
- });
387
- }
388
- }
389
- function ie(t) {
390
- return t.map((e) => {
391
- const n = J(e, !0);
392
- return {
393
- type: "function",
394
- function: {
395
- name: e.name,
396
- description: e.description,
397
- parameters: w(z(e, n)),
398
- strict: n ?? !1
399
- }
400
- };
401
- });
402
- }
403
- function w(t) {
404
- if (Array.isArray(t))
405
- return t.map((e) => w(e));
406
- if (t && typeof t == "object") {
407
- const e = {};
408
- for (const [n, r] of Object.entries(t))
409
- e[n] = w(r);
410
- return e;
411
- }
412
- return t;
413
- }
414
- function ce(t, e) {
415
- const n = [];
416
- for (const r of t) {
417
- if (r.role === "user") {
418
- if (typeof r.content == "string") {
419
- n.push({ role: "user", content: g(r.content) });
420
- continue;
421
- }
422
- const s = r.content.some((c) => c.type === "image"), a = r.content.filter((c) => c.type === "text" || e).map((c) => c.type === "text" ? { type: "text", text: g(c.text) } : { type: "image_url", imageUrl: `data:${c.mimeType};base64,${c.data}` });
423
- if (a.length > 0) {
424
- n.push({ role: "user", content: a });
425
- continue;
426
- }
427
- s && !e && n.push({ role: "user", content: "(image omitted: model does not support images)" });
428
- continue;
429
- }
430
- if (r.role === "assistant") {
431
- const s = [], a = [];
432
- for (const f of r.content) {
433
- if (f.type === "text") {
434
- f.text.trim().length > 0 && s.push({ type: "text", text: g(f.text) });
435
- continue;
436
- }
437
- if (f.type === "thinking") {
438
- f.thinking.trim().length > 0 && s.push({
439
- type: "thinking",
440
- thinking: [{ type: "text", text: g(f.thinking) }]
441
- });
442
- continue;
443
- }
444
- a.push({
445
- id: f.id,
446
- type: "function",
447
- function: { name: f.name, arguments: JSON.stringify(f.arguments || {}) },
448
- index: 0
449
- });
450
- }
451
- const c = { role: "assistant", prefix: !1 };
452
- s.length > 0 && (c.content = s), a.length > 0 && (c.toolCalls = a), (s.length > 0 || a.length > 0) && n.push(c);
453
- continue;
454
- }
455
- const o = [], l = r.content.filter((s) => s.type === "text").map((s) => s.type === "text" ? g(s.text) : "").join(`
456
- `), i = r.content.some((s) => s.type === "image"), u = le(l, i, e, r.isError);
457
- o.push({ type: "text", text: u });
458
- for (const s of r.content)
459
- e && s.type === "image" && o.push({
460
- type: "image_url",
461
- imageUrl: `data:${s.mimeType};base64,${s.data}`
462
- });
463
- n.push({
464
- role: "tool",
465
- toolCallId: r.toolCallId,
466
- name: r.toolName,
467
- content: o
468
- });
469
- }
470
- return n;
471
- }
472
- function le(t, e, n, r) {
473
- const o = t.trim(), l = r ? "[tool error] " : "";
474
- return o.length > 0 ? `${l}${o}${e && !n ? `
475
- [tool image omitted: model does not support images]` : ""}` : e ? 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)";
476
- }
477
- function $(t) {
478
- return t.id === "mistral-small-2603" || t.id === "mistral-small-latest" || t.id === "mistral-medium-3.5";
479
- }
480
- function fe(t) {
481
- return t.reasoning && !$(t);
482
- }
483
- function de(t, e) {
484
- return t.thinkingLevelMap?.[e] ?? "high";
485
- }
486
- function ue(t) {
487
- if (t)
488
- return t === "auto" || t === "none" || t === "any" || t === "required" ? t : {
489
- type: "function",
490
- function: { name: t.function.name }
491
- };
492
- }
493
- function pe(t) {
494
- if (t === null)
495
- return { stopReason: "stop" };
496
- switch (t) {
497
- case "stop":
498
- return { stopReason: "stop" };
499
- case "length":
500
- case "model_length":
501
- return { stopReason: "length" };
502
- case "tool_calls":
503
- return { stopReason: "toolUse" };
504
- case "error":
505
- return { stopReason: "error", errorMessage: "Provider stopped with: error" };
506
- default:
507
- return { stopReason: "error", errorMessage: `Provider stopped with: ${t}` };
508
- }
509
- }
510
- export {
511
- W as stream,
512
- _e as streamSimple
513
- };