@hintergrund/ui 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Builder-H8tY8V9I.js +14172 -0
- package/dist/admin.js +11084 -9645
- package/dist/{anthropic-CwpwmW2G.js → anthropic-messages-C3hIUlsA.js} +1134 -1055
- package/dist/azure-openai-responses-t7u41KMr.js +222 -0
- package/dist/builder.js +2 -2
- package/dist/client-Cd7yMX39.js +7860 -0
- package/dist/deferred-tools-BZWMWBYN.js +28 -0
- package/dist/error-body-BUPcH4GF.js +71 -0
- package/dist/github-copilot-headers-B1RBGoZi.js +21 -0
- package/dist/{global-DdaMTl90.js → global-Bk9T4Af5.js} +17850 -16460
- package/dist/google-generative-ai-6ZG79NDC.js +264 -0
- package/dist/{google-shared-zl4aoTwW.js → google-shared-C6y4fA42.js} +1135 -1104
- package/dist/google-vertex-f2myaAmm.js +305 -0
- package/dist/headers-D4iLzGaS.js +21 -0
- package/dist/json-parse-LZdWp-Nd.js +232 -0
- package/dist/login.js +48 -48
- package/dist/mistral-conversations-D16H8Mgq.js +513 -0
- package/dist/openai-codex-responses-DIHPbnIS.js +947 -0
- package/dist/openai-completions-vDHGFsWV.js +741 -0
- package/dist/{headers-u7rXGJ9f.js → openai-prompt-cache-BJwqbEDx.js} +7 -6
- package/dist/openai-responses-B0rjAJxx.js +184 -0
- package/dist/openai-responses-shared-DqdzMfa_.js +477 -0
- package/dist/pi-messages-DB2BtH-g.js +251 -0
- package/dist/pi-user-agent-CUqx-qiX.js +13 -0
- package/dist/provider-env-D2VjEV3S.js +26 -0
- package/dist/provider-retry-BsigVlMg.js +67 -0
- package/dist/setup.js +230 -228
- package/dist/transform-messages-CsKsy6b4.js +398 -0
- package/package.json +4 -5
- package/dist/Builder-BhGmzNTC.js +0 -163449
- package/dist/azure-openai-responses-yWEFYMG1.js +0 -203
- package/dist/client-Sh7wNjbG.js +0 -5277
- package/dist/github-copilot-headers-DWh_6bE3.js +0 -35
- package/dist/google-BgPPfrTM.js +0 -248
- package/dist/google-vertex-D7kAAkZn.js +0 -285
- package/dist/json-parse-Dk_xwHcS.js +0 -93
- package/dist/mistral-BJWDROjc.js +0 -22932
- package/dist/openai-codex-responses-rzy0Aqwg.js +0 -700
- package/dist/openai-completions-CUEO2YVR.js +0 -535
- package/dist/openai-responses-k6plMvd9.js +0 -142
- package/dist/openai-responses-shared-CCD7nRqy.js +0 -324
- package/dist/transform-messages-CkpQp6fJ.js +0 -132
package/dist/login.js
CHANGED
|
@@ -1,110 +1,110 @@
|
|
|
1
|
-
import {
|
|
2
|
-
typeof globalThis.process > "u" && (globalThis.process = { env: {}, platform: "browser", version: "", versions: {}, browser: !0, nextTick: function(
|
|
3
|
-
return Promise.resolve().then(
|
|
1
|
+
import { $ as W, a0 as X, a1 as Y, ap as ee, K as ae, S as s, a4 as i, a5 as l, aa as y, a6 as te, aA as re, a3 as se, a8 as u, N as t, ab as g, aB as oe, ac as z, ad as ie, U as c, ae as w, ar as le, ai as k, ag as n, a7 as A, aj as N, au as ne } from "./global-Bk9T4Af5.js";
|
|
2
|
+
typeof globalThis.process > "u" && (globalThis.process = { env: {}, platform: "browser", version: "", versions: {}, browser: !0, nextTick: function(x) {
|
|
3
|
+
return Promise.resolve().then(x);
|
|
4
4
|
} });
|
|
5
|
-
var de =
|
|
6
|
-
const
|
|
5
|
+
var de = w('<div class="flash flash-error"><svg class="octicon" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16"><path d="M2.343 13.657A8 8 0 1 1 13.658 2.343 8 8 0 0 1 2.343 13.657ZM6.03 4.97a.751.751 0 0 0-1.042.018.751.751 0 0 0-.018 1.042L6.94 8 4.97 9.97a.749.749 0 0 0 .326 1.275.749.749 0 0 0 .734-.215L8 9.06l1.97 1.97a.749.749 0 0 0 1.275-.326.749.749 0 0 0-.215-.734L9.06 8l1.97-1.97a.749.749 0 0 0-.326-1.275.749.749 0 0 0-.734.215L8 6.94Z"></path></svg> </div>'), ue = w('<div class="flash flash-success"><svg class="octicon" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16"><path d="M8 16A8 8 0 1 1 8 0a8 8 0 0 1 0 16Zm3.78-9.72a.751.751 0 0 0-.018-1.042.751.751 0 0 0-1.042-.018L6.75 9.19 5.28 7.72a.751.751 0 0 0-1.042.018.751.751 0 0 0-.018 1.042l2 2a.75.75 0 0 0 1.06 0Z"></path></svg> </div>'), ce = w('<div class="form-group"><label for="password">Password</label> <input type="password" id="password" name="password" class="form-control form-control-lg" required="" placeholder="••••••••"/></div>'), ve = w('<div class="form-group"><label for="otp">Email code</label> <input type="text" id="otp" name="otp" class="form-control form-control-lg" required="" inputmode="numeric" autocomplete="one-time-code" maxlength="6" placeholder="123456"/></div>'), fe = w('<main class="auth-wrapper svelte-uxwqu2"><div class="auth-container svelte-uxwqu2"><div class="auth-header svelte-uxwqu2"><svg class="auth-logo svelte-uxwqu2" viewBox="0 0 90 90" width="48" height="48" fill="currentColor"><rect x="12" y="12" width="66" height="66" fill="currentColor"></rect></svg> <h1 class="svelte-uxwqu2">Sign in to Hintergrund</h1></div> <!> <!> <div class="Box"><div class="Box-body"><form autocomplete="off"><div class="form-group"><label for="email">Email</label> <input type="email" id="email" name="email" class="form-control form-control-lg" required="" placeholder="you@example.com"/></div> <!> <!></form></div></div></div></main>');
|
|
6
|
+
const pe = {
|
|
7
7
|
hash: "svelte-uxwqu2",
|
|
8
8
|
code: ".auth-wrapper.svelte-uxwqu2 {min-height:100vh;display:flex;align-items:center;justify-content:center;background-color:var(--bgColor-muted);padding:var(--base-size-24);}.auth-container.svelte-uxwqu2 {width:100%;max-width:340px;}.auth-header.svelte-uxwqu2 {text-align:center;margin-bottom:var(--base-size-24);}.auth-logo.svelte-uxwqu2 {color:var(--fgColor-default);margin-bottom:var(--base-size-16);}.auth-header.svelte-uxwqu2 h1:where(.svelte-uxwqu2) {font-size:var(--text-title-size-medium);font-weight:var(--base-text-weight-light);color:var(--fgColor-default);margin:0;}"
|
|
9
9
|
};
|
|
10
|
-
function
|
|
11
|
-
X(
|
|
12
|
-
let
|
|
10
|
+
function me(x, T) {
|
|
11
|
+
X(T, !0), Y(x, pe);
|
|
12
|
+
let j = ee(T, "config", 7), m = c(!1), f = c(!1), q = c(""), P = c(""), _ = c(""), p = c(""), b = c(""), v = c(!1);
|
|
13
13
|
ae(() => {
|
|
14
14
|
const e = new URLSearchParams(window.location.search).get("error");
|
|
15
|
-
e && (s(
|
|
15
|
+
e && (s(p, e, !0), window.history.replaceState({}, "", window.location.pathname));
|
|
16
16
|
});
|
|
17
|
-
async function
|
|
18
|
-
a.preventDefault(), s(
|
|
17
|
+
async function O(a) {
|
|
18
|
+
a.preventDefault(), s(p, ""), s(b, ""), s(v, !0);
|
|
19
19
|
try {
|
|
20
20
|
const e = {};
|
|
21
|
-
t(_) && (e.email = t(_)), t(
|
|
21
|
+
t(_) && (e.email = t(_)), t(m) && (e.password = t(q)), t(f) && (e.otp = t(P));
|
|
22
22
|
const o = await (await fetch("/api/admin/login", {
|
|
23
23
|
method: "POST",
|
|
24
24
|
headers: { "Content-Type": "application/json" },
|
|
25
25
|
body: JSON.stringify(e)
|
|
26
26
|
})).json();
|
|
27
|
-
o.success ? o.requirePassword ? s(
|
|
27
|
+
o.success ? o.requirePassword ? s(m, !0) : o.otpRequired ? (s(f, !0), s(b, o.message || "Check your email for a six-digit sign-in code.", !0)) : window.location.href = "/admin" : (o.requirePassword && (s(m, !0), s(f, !1)), s(p, o.message ?? "An error occurred. Please try again.", !0));
|
|
28
28
|
} catch {
|
|
29
|
-
s(
|
|
29
|
+
s(p, "An error occurred. Please try again.");
|
|
30
30
|
} finally {
|
|
31
|
-
s(
|
|
31
|
+
s(v, !1);
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
var D = {
|
|
35
35
|
get config() {
|
|
36
|
-
return
|
|
36
|
+
return j();
|
|
37
37
|
},
|
|
38
38
|
set config(a) {
|
|
39
|
-
|
|
39
|
+
j(a), le();
|
|
40
40
|
}
|
|
41
|
-
}, C = fe(), E = l(C),
|
|
41
|
+
}, C = fe(), E = l(C), Z = i(l(E), 2);
|
|
42
42
|
{
|
|
43
43
|
var H = (a) => {
|
|
44
44
|
var e = de(), r = i(l(e));
|
|
45
|
-
n(e),
|
|
45
|
+
n(e), g(() => N(r, ` ${t(p) ?? ""}`)), u(a, e);
|
|
46
46
|
};
|
|
47
|
-
y(
|
|
48
|
-
t(
|
|
47
|
+
y(Z, (a) => {
|
|
48
|
+
t(p) && a(H);
|
|
49
49
|
});
|
|
50
50
|
}
|
|
51
|
-
var M = i(
|
|
51
|
+
var M = i(Z, 2);
|
|
52
52
|
{
|
|
53
53
|
var K = (a) => {
|
|
54
54
|
var e = ue(), r = i(l(e));
|
|
55
|
-
n(e),
|
|
55
|
+
n(e), g(() => N(r, ` ${t(b) ?? ""}`)), u(a, e);
|
|
56
56
|
};
|
|
57
57
|
y(M, (a) => {
|
|
58
58
|
t(b) && a(K);
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
|
-
var R = i(M, 2),
|
|
62
|
-
k(
|
|
63
|
-
var
|
|
61
|
+
var R = i(M, 2), U = l(R), S = l(U), B = l(S), L = i(l(B), 2);
|
|
62
|
+
k(L), n(B);
|
|
63
|
+
var J = i(B, 2);
|
|
64
64
|
{
|
|
65
|
-
var
|
|
66
|
-
var e = ve(), r = i(l(e), 2);
|
|
67
|
-
k(r), n(e), h(() => r.disabled = t(c)), B(r, () => t(q), (o) => s(q, o)), u(a, e);
|
|
68
|
-
}, Y = (a) => {
|
|
65
|
+
var $ = (a) => {
|
|
69
66
|
var e = ce(), r = i(l(e), 2);
|
|
70
|
-
k(r),
|
|
67
|
+
k(r), n(e), g(() => r.disabled = t(v)), z(r, () => t(q), (o) => s(q, o)), u(a, e);
|
|
68
|
+
}, F = (a) => {
|
|
69
|
+
var e = ve(), r = i(l(e), 2);
|
|
70
|
+
k(r), ne(r, "pattern", "[0-9]6"), n(e), g(() => r.disabled = t(v)), z(r, () => t(P), (o) => s(P, o)), u(a, e);
|
|
71
71
|
};
|
|
72
|
-
y(
|
|
73
|
-
t(
|
|
72
|
+
y(J, (a) => {
|
|
73
|
+
t(m) ? a($) : t(f) && a(F, 1);
|
|
74
74
|
});
|
|
75
75
|
}
|
|
76
|
-
var
|
|
77
|
-
return te(
|
|
76
|
+
var G = i(J, 2);
|
|
77
|
+
return te(G, {
|
|
78
78
|
type: "submit",
|
|
79
79
|
variant: "primary",
|
|
80
80
|
size: "large",
|
|
81
81
|
block: !0,
|
|
82
82
|
get disabled() {
|
|
83
|
-
return t(
|
|
83
|
+
return t(v);
|
|
84
84
|
},
|
|
85
85
|
children: (a, e) => {
|
|
86
86
|
var r = re(), o = se(r);
|
|
87
87
|
{
|
|
88
|
-
var
|
|
89
|
-
var
|
|
90
|
-
u(d,
|
|
91
|
-
},
|
|
92
|
-
var
|
|
93
|
-
u(d,
|
|
88
|
+
var I = (d) => {
|
|
89
|
+
var h = A("Please wait...");
|
|
90
|
+
u(d, h);
|
|
91
|
+
}, Q = (d) => {
|
|
92
|
+
var h = A("Sign in");
|
|
93
|
+
u(d, h);
|
|
94
94
|
}, V = (d) => {
|
|
95
|
-
var
|
|
96
|
-
u(d,
|
|
95
|
+
var h = A("Continue");
|
|
96
|
+
u(d, h);
|
|
97
97
|
};
|
|
98
98
|
y(o, (d) => {
|
|
99
|
-
t(
|
|
99
|
+
t(v) ? d(I) : t(f) ? d(Q, 1) : d(V, -1);
|
|
100
100
|
});
|
|
101
101
|
}
|
|
102
102
|
u(a, r);
|
|
103
103
|
},
|
|
104
104
|
$$slots: { default: !0 }
|
|
105
|
-
}), n(
|
|
105
|
+
}), n(S), n(U), n(R), n(E), n(C), g(() => L.disabled = t(v) || t(m) || t(f)), oe("submit", S, O), z(L, () => t(_), (a) => s(_, a)), u(x, C), ie(D);
|
|
106
106
|
}
|
|
107
|
-
customElements.define("hintergrund-login", W(
|
|
107
|
+
customElements.define("hintergrund-login", W(me, { config: {} }, [], []));
|
|
108
108
|
export {
|
|
109
|
-
|
|
109
|
+
me as default
|
|
110
110
|
};
|
|
@@ -0,0 +1,513 @@
|
|
|
1
|
+
import { d as L, e as j, f as N } from "./Builder-H8tY8V9I.js";
|
|
2
|
+
import { s as D } 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 J, s as g, d as H, 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 = Z(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 = J(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 D(o).replace(/[^a-zA-Z0-9]/g, "").slice(0, C);
|
|
86
|
+
}
|
|
87
|
+
function Z(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}): ${G(r, K)}` : n !== void 0 ? `Mistral API error (${n}): ${t.message}` : t.message;
|
|
91
|
+
}
|
|
92
|
+
return X(t);
|
|
93
|
+
}
|
|
94
|
+
function G(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, N(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 = H(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
|
+
};
|