@promte/app-library 0.1.8 → 0.1.10
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/README.md +34 -0
- package/dist/index.d.ts +168 -3
- package/dist/index.mjs +597 -404
- package/dist/index.umd.cjs +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -1,622 +1,815 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (i instanceof URLSearchParams)
|
|
15
|
-
return p.has("content-type") || p.set("content-type", "application/x-www-form-urlencoded;charset=UTF-8"), i.toString();
|
|
16
|
-
if (i instanceof FormData) {
|
|
17
|
-
const w = [];
|
|
18
|
-
return i.forEach((h, a) => w.push([a, h])), { form: w };
|
|
19
|
-
}
|
|
20
|
-
throw new TypeError("This request body cannot be sent through Promte.");
|
|
21
|
-
}
|
|
22
|
-
function X({ target: i, origin: p }, w, h) {
|
|
23
|
-
return new Promise((a, y) => {
|
|
24
|
-
const l = h.signal;
|
|
25
|
-
if (l != null && l.aborted) return y(F(l));
|
|
26
|
-
const P = Q(), g = new Headers(h.headers);
|
|
27
|
-
g.delete("authorization");
|
|
28
|
-
let v;
|
|
29
|
-
try {
|
|
30
|
-
v = K(h.body, g);
|
|
31
|
-
} catch (r) {
|
|
32
|
-
return y(r);
|
|
33
|
-
}
|
|
34
|
-
const S = () => {
|
|
35
|
-
window.removeEventListener("message", t), l == null || l.removeEventListener("abort", k);
|
|
36
|
-
}, k = () => {
|
|
37
|
-
S(), y(F(l));
|
|
38
|
-
}, t = (r) => {
|
|
39
|
-
if (r.source !== i || r.origin !== p) return;
|
|
40
|
-
const e = r.data;
|
|
41
|
-
if (!e || e.type !== W || e.id !== P) return;
|
|
42
|
-
if (S(), typeof e.error == "string")
|
|
43
|
-
return y(new TypeError(e.error));
|
|
44
|
-
const o = Number(e.status);
|
|
45
|
-
if (!Number.isInteger(o) || o < 200 || o > 599)
|
|
46
|
-
return y(new TypeError("Promte returned an invalid response."));
|
|
47
|
-
try {
|
|
48
|
-
a(
|
|
49
|
-
new Response(H.has(o) ? null : e.body ?? null, {
|
|
50
|
-
status: o,
|
|
51
|
-
statusText: typeof e.statusText == "string" ? e.statusText : "",
|
|
52
|
-
headers: Array.isArray(e.headers) ? e.headers : []
|
|
53
|
-
})
|
|
54
|
-
);
|
|
55
|
-
} catch {
|
|
56
|
-
y(new TypeError("Promte returned an invalid response."));
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
window.addEventListener("message", t), l == null || l.addEventListener("abort", k, { once: !0 });
|
|
60
|
-
const n = [];
|
|
61
|
-
g.forEach((r, e) => n.push([e, r]));
|
|
62
|
-
try {
|
|
63
|
-
i.postMessage(
|
|
64
|
-
{
|
|
65
|
-
type: V,
|
|
66
|
-
id: P,
|
|
67
|
-
path: w,
|
|
68
|
-
method: (h.method || "GET").toUpperCase(),
|
|
69
|
-
headers: n,
|
|
70
|
-
body: v
|
|
71
|
-
},
|
|
72
|
-
p
|
|
73
|
-
);
|
|
74
|
-
} catch (r) {
|
|
75
|
-
S(), y(r);
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
const j = G(null);
|
|
80
|
-
function tt({
|
|
1
|
+
var ae = Object.defineProperty;
|
|
2
|
+
var ie = (i, c, u) => c in i ? ae(i, c, { enumerable: !0, configurable: !0, writable: !0, value: u }) : i[c] = u;
|
|
3
|
+
var Q = (i, c, u) => ie(i, typeof c != "symbol" ? c + "" : c, u);
|
|
4
|
+
import { jsx as oe } from "react/jsx-runtime";
|
|
5
|
+
import ce, { createContext as ue, useState as O, useMemo as G, useCallback as X, useEffect as K, useContext as le } from "react";
|
|
6
|
+
const Z = ue(null), Y = {
|
|
7
|
+
loginEnabled: !1,
|
|
8
|
+
methods: { password: !1, magicLink: !1, signup: !1 },
|
|
9
|
+
signedIn: !1,
|
|
10
|
+
pendingPasswordReset: !1,
|
|
11
|
+
expiredLink: !1
|
|
12
|
+
};
|
|
13
|
+
function Te({
|
|
81
14
|
children: i,
|
|
82
|
-
expectedParentOrigin:
|
|
83
|
-
initTargetOrigin:
|
|
84
|
-
retryInit:
|
|
15
|
+
expectedParentOrigin: c,
|
|
16
|
+
initTargetOrigin: u,
|
|
17
|
+
retryInit: v = { enabled: !0, intervalMs: 500, maxAttempts: 20 }
|
|
85
18
|
}) {
|
|
86
|
-
const [
|
|
87
|
-
var
|
|
19
|
+
const [s, k] = O(null), [g, x] = O(null), [L, C] = O(null), [S, $] = O(null), [R, P] = O(null), [e, t] = O(null), [n, r] = O(Y), o = ce.useRef(/* @__PURE__ */ new Map()), a = G(() => R ? "booting" : s ? !g && !s.fetchProxy ? "waiting_for_token" : "ready" : "waiting_for_settings", [s, g, R]), h = a === "ready", m = G(() => u || c || "*", [u, c]), f = X(() => {
|
|
20
|
+
var U;
|
|
88
21
|
try {
|
|
89
|
-
const
|
|
90
|
-
(
|
|
91
|
-
} catch (
|
|
92
|
-
|
|
22
|
+
const E = { type: "init", fetchProxy: !0 };
|
|
23
|
+
(U = window.parent) == null || U.postMessage(E, m);
|
|
24
|
+
} catch (E) {
|
|
25
|
+
P((E == null ? void 0 : E.message) || "Failed to post init");
|
|
93
26
|
}
|
|
94
|
-
}, [
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}, [
|
|
98
|
-
if (!(
|
|
99
|
-
const
|
|
100
|
-
let
|
|
101
|
-
const
|
|
102
|
-
if (
|
|
103
|
-
window.clearInterval(
|
|
27
|
+
}, [m]);
|
|
28
|
+
K(() => {
|
|
29
|
+
f();
|
|
30
|
+
}, [f]), K(() => {
|
|
31
|
+
if (!(v != null && v.enabled) || s) return;
|
|
32
|
+
const U = v.intervalMs ?? 500, E = v.maxAttempts ?? 20;
|
|
33
|
+
let l = 0;
|
|
34
|
+
const y = window.setInterval(() => {
|
|
35
|
+
if (s) {
|
|
36
|
+
window.clearInterval(y);
|
|
104
37
|
return;
|
|
105
38
|
}
|
|
106
|
-
if (
|
|
107
|
-
window.clearInterval(
|
|
39
|
+
if (l += 1, l > E) {
|
|
40
|
+
window.clearInterval(y);
|
|
108
41
|
return;
|
|
109
42
|
}
|
|
110
|
-
|
|
111
|
-
},
|
|
112
|
-
return () => window.clearInterval(
|
|
113
|
-
}, [
|
|
114
|
-
const
|
|
115
|
-
if (
|
|
116
|
-
const
|
|
117
|
-
if (!(!
|
|
118
|
-
if (
|
|
119
|
-
const
|
|
120
|
-
if (!(
|
|
43
|
+
f();
|
|
44
|
+
}, U);
|
|
45
|
+
return () => window.clearInterval(y);
|
|
46
|
+
}, [v, s, f]), K(() => {
|
|
47
|
+
const U = (E) => {
|
|
48
|
+
if (c && E.origin !== c) return;
|
|
49
|
+
const l = E.data;
|
|
50
|
+
if (!(!l || typeof l != "object")) {
|
|
51
|
+
if (l.type === "set-settings") {
|
|
52
|
+
const y = l.value;
|
|
53
|
+
if (!(y != null && y.backendUrl) || y.parentOrigin && c && y.parentOrigin !== c)
|
|
121
54
|
return;
|
|
122
|
-
y
|
|
55
|
+
k(y), t(E.source === window.parent ? E.origin : null), y != null && y.user && $(y.user), P(null);
|
|
123
56
|
return;
|
|
124
57
|
}
|
|
125
|
-
if (
|
|
126
|
-
|
|
58
|
+
if (l.type === "set-token" && typeof l.value == "string") {
|
|
59
|
+
x(l.value), P(null);
|
|
127
60
|
return;
|
|
128
61
|
}
|
|
129
|
-
if (
|
|
130
|
-
|
|
62
|
+
if (l.type === "set-dark-mode" && typeof l.value == "boolean") {
|
|
63
|
+
C(l.value);
|
|
131
64
|
return;
|
|
132
65
|
}
|
|
133
|
-
if (
|
|
134
|
-
|
|
66
|
+
if (l.type === "set-user" && typeof l.value == "object") {
|
|
67
|
+
$(l.value);
|
|
135
68
|
return;
|
|
136
69
|
}
|
|
70
|
+
if (E.source === window.parent) {
|
|
71
|
+
if (l.type === "set-auth" && l.value && typeof l.value == "object") {
|
|
72
|
+
r({ ...Y, ...l.value });
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (l.type === "promte-auth-result" && typeof l.requestId == "string") {
|
|
76
|
+
const y = o.current.get(l.requestId);
|
|
77
|
+
if (!y) return;
|
|
78
|
+
o.current.delete(l.requestId), l.ok ? y.resolve() : y.reject(new Error(typeof l.error == "string" ? l.error : "server_error"));
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
return window.addEventListener("message", U), () => window.removeEventListener("message", U);
|
|
85
|
+
}, [c]);
|
|
86
|
+
const b = G(() => se(
|
|
87
|
+
() => s,
|
|
88
|
+
() => g,
|
|
89
|
+
() => s != null && s.fetchProxy && e && window.parent !== window ? { target: window.parent, origin: e } : null
|
|
90
|
+
), [s, g, e]), A = (s == null ? void 0 : s.allowDownloads) !== !1;
|
|
91
|
+
K(() => {
|
|
92
|
+
var q, ee, te;
|
|
93
|
+
if (!e || window.parent === window) return;
|
|
94
|
+
const U = /* @__PURE__ */ new Set(), E = (p, d, j) => {
|
|
95
|
+
const _ = `${p}:${d}`;
|
|
96
|
+
if (!U.has(_)) {
|
|
97
|
+
U.add(_), console.error(`[Promte] ${j}`);
|
|
98
|
+
try {
|
|
99
|
+
window.parent.postMessage({ type: "promte-blocked", kind: p, detail: d }, e);
|
|
100
|
+
} catch {
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}, l = (p) => {
|
|
104
|
+
try {
|
|
105
|
+
const d = new URL(p, window.location.href);
|
|
106
|
+
return /^https?:$/.test(d.protocol) && d.origin !== window.location.origin ? d : null;
|
|
107
|
+
} catch {
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
}, y = window.open, I = (p) => {
|
|
111
|
+
var N, ne;
|
|
112
|
+
if (p.defaultPrevented || p.button !== 0 || p.metaKey || p.ctrlKey || p.shiftKey || p.altKey) return;
|
|
113
|
+
const d = (ne = (N = p.target) == null ? void 0 : N.closest) == null ? void 0 : ne.call(N, "a[href]");
|
|
114
|
+
if (!d) return;
|
|
115
|
+
if (d.hasAttribute("download") || /^(?:blob|data):/i.test(d.href)) {
|
|
116
|
+
A || E("download", d.getAttribute("download") || "", "The app tried to download a file, but file downloads from apps are turned off in governance.");
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
const j = l(d.href);
|
|
120
|
+
if (!j) return;
|
|
121
|
+
p.preventDefault();
|
|
122
|
+
const _ = y.call(window, j.href, "_blank");
|
|
123
|
+
if (_)
|
|
124
|
+
try {
|
|
125
|
+
_.opener = null;
|
|
126
|
+
} catch {
|
|
127
|
+
}
|
|
128
|
+
else E("link", j.href, `The link to ${j.href} could not open in a new tab. Governance may only allow approved web addresses for this app.`);
|
|
129
|
+
};
|
|
130
|
+
window.open = function(p, d, j) {
|
|
131
|
+
const _ = y.call(window, p, d, j), N = p === void 0 ? null : l(String(p));
|
|
132
|
+
return !_ && N && !/noopener|noreferrer/i.test(j || "") && E("link", N.href, `The link to ${N.href} could not open in a new tab. Governance may only allow approved web addresses for this app.`), _;
|
|
133
|
+
};
|
|
134
|
+
const M = (p) => {
|
|
135
|
+
const d = p.blockedURI;
|
|
136
|
+
if (!/^https?:/i.test(d)) return;
|
|
137
|
+
let j = d;
|
|
138
|
+
try {
|
|
139
|
+
j = new URL(d).origin;
|
|
140
|
+
} catch {
|
|
137
141
|
}
|
|
142
|
+
E("address", j, `A request to ${d} was blocked (${p.effectiveDirective}). Governance may only allow approved web addresses for this app.`);
|
|
143
|
+
}, B = (p) => {
|
|
144
|
+
const d = p.detail;
|
|
145
|
+
E("governance", String((d == null ? void 0 : d.message) || ""), `Governance blocked an action in the app${d != null && d.message ? `: ${d.message}` : "."}`);
|
|
146
|
+
}, T = navigator.mediaDevices, F = (q = T == null ? void 0 : T.getUserMedia) == null ? void 0 : q.bind(T), V = (ee = T == null ? void 0 : T.getDisplayMedia) == null ? void 0 : ee.bind(T), H = (p) => (d) => {
|
|
147
|
+
throw ((d == null ? void 0 : d.name) === "NotAllowedError" || (d == null ? void 0 : d.name) === "SecurityError") && E("device", p, `The app was not allowed to use the ${p} here.`), d;
|
|
148
|
+
};
|
|
149
|
+
T && F && (T.getUserMedia = (p) => F(p).catch(H(p != null && p.video ? "camera" : "microphone"))), T && V && (T.getDisplayMedia = (p) => V(p).catch(H("screen")));
|
|
150
|
+
const D = navigator.clipboard, W = (te = D == null ? void 0 : D.writeText) == null ? void 0 : te.bind(D);
|
|
151
|
+
return D && W && (D.writeText = (p) => W(p).catch(H("clipboard"))), document.addEventListener("click", I), document.addEventListener("securitypolicyviolation", M), window.addEventListener("promte:governance-blocked", B), () => {
|
|
152
|
+
document.removeEventListener("click", I), document.removeEventListener("securitypolicyviolation", M), window.removeEventListener("promte:governance-blocked", B), window.open = y, T && F && (T.getUserMedia = F), T && V && (T.getDisplayMedia = V), D && W && (D.writeText = W);
|
|
138
153
|
};
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
()
|
|
143
|
-
() =>
|
|
144
|
-
|
|
145
|
-
|
|
154
|
+
}, [e, A]);
|
|
155
|
+
const w = X((U, E = {}) => {
|
|
156
|
+
if (!e || window.parent === window) return Promise.reject(new Error("not_available"));
|
|
157
|
+
const l = `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
|
|
158
|
+
return new Promise((y, I) => {
|
|
159
|
+
const M = window.setTimeout(() => {
|
|
160
|
+
o.current.delete(l), I(new Error("timeout"));
|
|
161
|
+
}, 6e4);
|
|
162
|
+
o.current.set(l, {
|
|
163
|
+
resolve: () => {
|
|
164
|
+
window.clearTimeout(M), y();
|
|
165
|
+
},
|
|
166
|
+
reject: (B) => {
|
|
167
|
+
window.clearTimeout(M), I(B);
|
|
168
|
+
}
|
|
169
|
+
}), window.parent.postMessage({ type: "promte-auth", requestId: l, action: U, ...E }, e);
|
|
170
|
+
});
|
|
171
|
+
}, [e]), z = G(
|
|
146
172
|
() => ({
|
|
147
|
-
settings:
|
|
148
|
-
token:
|
|
149
|
-
isDarkMode:
|
|
173
|
+
settings: s,
|
|
174
|
+
token: g,
|
|
175
|
+
isDarkMode: L,
|
|
150
176
|
user: S,
|
|
151
|
-
ready:
|
|
152
|
-
state:
|
|
153
|
-
error:
|
|
154
|
-
client:
|
|
177
|
+
ready: h,
|
|
178
|
+
state: a,
|
|
179
|
+
error: R,
|
|
180
|
+
client: b,
|
|
181
|
+
auth: n,
|
|
182
|
+
authRequest: w
|
|
155
183
|
}),
|
|
156
|
-
[
|
|
184
|
+
[s, g, L, S, h, a, R, b, n, w]
|
|
157
185
|
);
|
|
158
|
-
return /* @__PURE__ */
|
|
186
|
+
return /* @__PURE__ */ oe(Z.Provider, { value: z, children: i });
|
|
159
187
|
}
|
|
160
|
-
function
|
|
188
|
+
function ke({
|
|
161
189
|
children: i,
|
|
162
|
-
settings:
|
|
163
|
-
token:
|
|
164
|
-
isDarkMode:
|
|
165
|
-
user:
|
|
190
|
+
settings: c,
|
|
191
|
+
token: u,
|
|
192
|
+
isDarkMode: v,
|
|
193
|
+
user: s
|
|
166
194
|
}) {
|
|
167
|
-
const
|
|
168
|
-
() =>
|
|
169
|
-
[
|
|
170
|
-
),
|
|
195
|
+
const k = G(
|
|
196
|
+
() => se(() => c, () => u),
|
|
197
|
+
[c, u]
|
|
198
|
+
), g = !!u, x = G(
|
|
171
199
|
() => ({
|
|
172
|
-
settings:
|
|
173
|
-
token:
|
|
174
|
-
isDarkMode:
|
|
175
|
-
user:
|
|
176
|
-
ready:
|
|
177
|
-
state:
|
|
200
|
+
settings: c,
|
|
201
|
+
token: u,
|
|
202
|
+
isDarkMode: v,
|
|
203
|
+
user: s,
|
|
204
|
+
ready: g,
|
|
205
|
+
state: g ? "ready" : "waiting_for_token",
|
|
178
206
|
error: null,
|
|
179
|
-
client:
|
|
207
|
+
client: k,
|
|
208
|
+
auth: Y,
|
|
209
|
+
authRequest: () => Promise.reject(new Error("not_available"))
|
|
180
210
|
}),
|
|
181
|
-
[
|
|
211
|
+
[k, v, g, c, u, s]
|
|
182
212
|
);
|
|
183
|
-
return /* @__PURE__ */
|
|
213
|
+
return /* @__PURE__ */ oe(Z.Provider, { value: x, children: i });
|
|
184
214
|
}
|
|
185
|
-
function
|
|
186
|
-
const i =
|
|
215
|
+
function J() {
|
|
216
|
+
const i = le(Z);
|
|
187
217
|
if (!i)
|
|
188
218
|
throw new Error(
|
|
189
219
|
"usePromte must be used inside <PromteAppProvider> or <PromteNativeProvider>"
|
|
190
220
|
);
|
|
191
221
|
return i;
|
|
192
222
|
}
|
|
193
|
-
function
|
|
194
|
-
return
|
|
223
|
+
function Se() {
|
|
224
|
+
return J().settings;
|
|
195
225
|
}
|
|
196
|
-
function
|
|
197
|
-
return
|
|
226
|
+
function Pe() {
|
|
227
|
+
return J().token;
|
|
198
228
|
}
|
|
199
|
-
function
|
|
200
|
-
return
|
|
229
|
+
function $e() {
|
|
230
|
+
return J().isDarkMode;
|
|
201
231
|
}
|
|
202
|
-
function
|
|
203
|
-
return
|
|
232
|
+
function Re() {
|
|
233
|
+
return J().user;
|
|
204
234
|
}
|
|
205
|
-
function
|
|
206
|
-
return
|
|
235
|
+
function de() {
|
|
236
|
+
return J().client;
|
|
207
237
|
}
|
|
208
|
-
function
|
|
209
|
-
const {
|
|
210
|
-
|
|
211
|
-
|
|
238
|
+
function Ue() {
|
|
239
|
+
const { auth: i, authRequest: c } = J();
|
|
240
|
+
return G(() => ({
|
|
241
|
+
...i,
|
|
242
|
+
/** Signs in with email and password. */
|
|
243
|
+
signIn: (u, v) => c("signIn", { email: u, password: v }),
|
|
244
|
+
/** Starts sign-up; the account is created when the visitor clicks the link in the email. */
|
|
245
|
+
signUp: (u, v) => c("signUp", { email: u, password: v }),
|
|
246
|
+
/** Emails a single-use login link. Resolves even if the email has no account. */
|
|
247
|
+
sendLoginLink: (u) => c("sendLoginLink", { email: u }),
|
|
248
|
+
/** Emails a link for choosing a new password. */
|
|
249
|
+
sendPasswordReset: (u) => c("sendPasswordReset", { email: u }),
|
|
250
|
+
/** Sets the new password after the visitor opened a reset link, and signs them in. */
|
|
251
|
+
completePasswordReset: (u) => c("completePasswordReset", { password: u }),
|
|
252
|
+
signOut: () => c("signOut")
|
|
253
|
+
}), [i, c]);
|
|
254
|
+
}
|
|
255
|
+
function xe(i = {}) {
|
|
256
|
+
const { ready: c } = J(), u = de(), [v, s] = O([]), [k, g] = O(!1), [x, L] = O(null), C = G(() => (Array.isArray(i.type) ? i.type : i.type ? [i.type] : []).filter(Boolean).map((e) => String(e)).join(","), [i.type]), S = i.configuredOnly === !0, $ = i.auto !== !1, R = X(async () => {
|
|
257
|
+
if (!c) return [];
|
|
258
|
+
g(!0), L(null);
|
|
212
259
|
try {
|
|
213
|
-
const
|
|
214
|
-
return
|
|
215
|
-
} catch (
|
|
216
|
-
const
|
|
217
|
-
throw
|
|
260
|
+
const P = C ? C.split(",").filter(Boolean) : void 0, e = await u.models({ type: P, configuredOnly: S });
|
|
261
|
+
return s(e), e;
|
|
262
|
+
} catch (P) {
|
|
263
|
+
const e = P instanceof Error ? P.message : String(P);
|
|
264
|
+
throw L(e), P;
|
|
218
265
|
} finally {
|
|
219
|
-
|
|
266
|
+
g(!1);
|
|
220
267
|
}
|
|
221
|
-
}, [
|
|
222
|
-
return
|
|
223
|
-
|
|
268
|
+
}, [u, S, c, C]);
|
|
269
|
+
return K(() => {
|
|
270
|
+
!$ || !c || R().catch(() => {
|
|
224
271
|
});
|
|
225
|
-
}, [
|
|
272
|
+
}, [$, c, R]), { models: v, loading: k, error: x, reload: R };
|
|
273
|
+
}
|
|
274
|
+
class pe extends Error {
|
|
275
|
+
constructor(u, v, s) {
|
|
276
|
+
super(s || u);
|
|
277
|
+
Q(this, "code");
|
|
278
|
+
Q(this, "status");
|
|
279
|
+
this.name = "PromteEmailError", this.code = u, this.status = v;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
const fe = "promte-fetch-request", we = "promte-fetch-response", he = /* @__PURE__ */ new Set([101, 103, 204, 205, 304]);
|
|
283
|
+
function me() {
|
|
284
|
+
return typeof crypto < "u" && "randomUUID" in crypto ? crypto.randomUUID() : `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
|
|
285
|
+
}
|
|
286
|
+
function re(i) {
|
|
287
|
+
return i.reason ?? new DOMException("The operation was aborted.", "AbortError");
|
|
288
|
+
}
|
|
289
|
+
function ge(i, c) {
|
|
290
|
+
if (i == null) return null;
|
|
291
|
+
if (typeof i == "string" || i instanceof Blob || i instanceof ArrayBuffer || ArrayBuffer.isView(i))
|
|
292
|
+
return i;
|
|
293
|
+
if (i instanceof URLSearchParams)
|
|
294
|
+
return c.has("content-type") || c.set("content-type", "application/x-www-form-urlencoded;charset=UTF-8"), i.toString();
|
|
295
|
+
if (i instanceof FormData) {
|
|
296
|
+
const u = [];
|
|
297
|
+
return i.forEach((v, s) => u.push([s, v])), { form: u };
|
|
298
|
+
}
|
|
299
|
+
throw new TypeError("This request body cannot be sent through Promte.");
|
|
300
|
+
}
|
|
301
|
+
function ye({ target: i, origin: c }, u, v) {
|
|
302
|
+
return new Promise((s, k) => {
|
|
303
|
+
const g = v.signal;
|
|
304
|
+
if (g != null && g.aborted) return k(re(g));
|
|
305
|
+
const x = me(), L = new Headers(v.headers);
|
|
306
|
+
L.delete("authorization");
|
|
307
|
+
let C;
|
|
308
|
+
try {
|
|
309
|
+
C = ge(v.body, L);
|
|
310
|
+
} catch (e) {
|
|
311
|
+
return k(e);
|
|
312
|
+
}
|
|
313
|
+
const S = () => {
|
|
314
|
+
window.removeEventListener("message", R), g == null || g.removeEventListener("abort", $);
|
|
315
|
+
}, $ = () => {
|
|
316
|
+
S(), k(re(g));
|
|
317
|
+
}, R = (e) => {
|
|
318
|
+
if (e.source !== i || e.origin !== c) return;
|
|
319
|
+
const t = e.data;
|
|
320
|
+
if (!t || t.type !== we || t.id !== x) return;
|
|
321
|
+
if (S(), typeof t.error == "string")
|
|
322
|
+
return k(new TypeError(t.error));
|
|
323
|
+
const n = Number(t.status);
|
|
324
|
+
if (!Number.isInteger(n) || n < 200 || n > 599)
|
|
325
|
+
return k(new TypeError("Promte returned an invalid response."));
|
|
326
|
+
try {
|
|
327
|
+
s(
|
|
328
|
+
new Response(he.has(n) ? null : t.body ?? null, {
|
|
329
|
+
status: n,
|
|
330
|
+
statusText: typeof t.statusText == "string" ? t.statusText : "",
|
|
331
|
+
headers: Array.isArray(t.headers) ? t.headers : []
|
|
332
|
+
})
|
|
333
|
+
);
|
|
334
|
+
} catch {
|
|
335
|
+
k(new TypeError("Promte returned an invalid response."));
|
|
336
|
+
}
|
|
337
|
+
};
|
|
338
|
+
window.addEventListener("message", R), g == null || g.addEventListener("abort", $, { once: !0 });
|
|
339
|
+
const P = [];
|
|
340
|
+
L.forEach((e, t) => P.push([t, e]));
|
|
341
|
+
try {
|
|
342
|
+
i.postMessage(
|
|
343
|
+
{
|
|
344
|
+
type: fe,
|
|
345
|
+
id: x,
|
|
346
|
+
path: u,
|
|
347
|
+
method: (v.method || "GET").toUpperCase(),
|
|
348
|
+
headers: P,
|
|
349
|
+
body: C
|
|
350
|
+
},
|
|
351
|
+
c
|
|
352
|
+
);
|
|
353
|
+
} catch (e) {
|
|
354
|
+
S(), k(e);
|
|
355
|
+
}
|
|
356
|
+
});
|
|
226
357
|
}
|
|
227
|
-
function
|
|
228
|
-
const
|
|
229
|
-
async function
|
|
230
|
-
const
|
|
231
|
-
if (!
|
|
232
|
-
const o =
|
|
233
|
-
if (!
|
|
234
|
-
const f =
|
|
235
|
-
...
|
|
358
|
+
function se(i, c, u = () => null) {
|
|
359
|
+
const v = (e) => typeof e == "string" && (e.startsWith("gpt-5") || e.startsWith("gpt-6"));
|
|
360
|
+
async function s(e, t) {
|
|
361
|
+
const n = i(), r = c();
|
|
362
|
+
if (!n) throw new Error("Promte settings not received yet");
|
|
363
|
+
const o = n.backendUrl.replace(/\/+$/, ""), a = String(e || "").replace(/^\/+/, ""), h = `${o}/${a}`, m = u();
|
|
364
|
+
if (!m && !r) throw new Error("Promte token not received yet");
|
|
365
|
+
const f = m ? await ye(m, a, t) : await fetch(h, {
|
|
366
|
+
...t,
|
|
236
367
|
headers: {
|
|
237
|
-
...
|
|
238
|
-
Authorization: `Bearer ${
|
|
368
|
+
...t.headers || {},
|
|
369
|
+
Authorization: `Bearer ${r}`
|
|
239
370
|
}
|
|
240
371
|
});
|
|
241
|
-
return f.
|
|
372
|
+
return f.status === 403 && typeof window < "u" && f.clone().json().then((b) => {
|
|
373
|
+
(b == null ? void 0 : b.code) === "app_policy_blocked" && window.dispatchEvent(new CustomEvent("promte:governance-blocked", { detail: { endpoint: e, message: typeof b.error == "string" ? b.error : "" } }));
|
|
374
|
+
}).catch(() => {
|
|
375
|
+
}), f.headers.get("X-Promte-Governance-Warning") && (typeof window < "u" && window.dispatchEvent(new CustomEvent("promte:governance-warning", { detail: { endpoint: e } })), console.warn("Promte governance: this request triggered a warning policy.")), f;
|
|
242
376
|
}
|
|
243
|
-
|
|
244
|
-
|
|
377
|
+
const k = /* @__PURE__ */ new Map(), g = {
|
|
378
|
+
async list() {
|
|
379
|
+
const e = await s("/app-api/shared-assets", { method: "GET" });
|
|
380
|
+
if (!e.ok) throw new Error(`Request failed (${e.status})`);
|
|
381
|
+
return (await e.json()).assets;
|
|
382
|
+
},
|
|
383
|
+
async get(e, t = {}) {
|
|
384
|
+
const n = await s(`/app-api/shared-assets/${encodeURIComponent(e)}`, { method: "GET", signal: t.signal });
|
|
385
|
+
if (!n.ok) throw new Error(n.status === 404 ? `The shared asset ${e} does not exist.` : `Request failed (${n.status})`);
|
|
386
|
+
return n.blob();
|
|
387
|
+
},
|
|
388
|
+
async text(e) {
|
|
389
|
+
return (await g.get(e)).text();
|
|
390
|
+
},
|
|
391
|
+
url(e) {
|
|
392
|
+
let t = k.get(e);
|
|
393
|
+
return t || (t = g.get(e).then((n) => URL.createObjectURL(n)), t.catch(() => k.delete(e)), k.set(e, t)), t;
|
|
394
|
+
}
|
|
395
|
+
};
|
|
396
|
+
async function x(e, t) {
|
|
397
|
+
const n = await s(`/app-api/data/${e}`, {
|
|
245
398
|
method: "POST",
|
|
246
399
|
headers: { "Content-Type": "application/json" },
|
|
247
|
-
body: JSON.stringify(
|
|
248
|
-
}),
|
|
249
|
-
if (!
|
|
400
|
+
body: JSON.stringify(t)
|
|
401
|
+
}), r = await n.json().catch(() => ({}));
|
|
402
|
+
if (!n.ok)
|
|
250
403
|
throw new Error(
|
|
251
|
-
(
|
|
404
|
+
(r == null ? void 0 : r.error) || `Request failed (${n.status})`
|
|
252
405
|
);
|
|
253
|
-
return
|
|
406
|
+
return r == null ? void 0 : r.value;
|
|
254
407
|
}
|
|
255
|
-
async function
|
|
256
|
-
const
|
|
257
|
-
|
|
258
|
-
const
|
|
408
|
+
async function L(e) {
|
|
409
|
+
const t = new URLSearchParams();
|
|
410
|
+
e.scope && t.set("scope", e.scope), e.path && t.set("path", e.path), e.owner && t.set("owner", e.owner);
|
|
411
|
+
const n = await s(`/app-api/data?${t.toString()}`, {
|
|
259
412
|
method: "GET"
|
|
260
|
-
}),
|
|
261
|
-
if (!
|
|
262
|
-
throw new Error((
|
|
263
|
-
return
|
|
413
|
+
}), r = await n.json().catch(() => ({}));
|
|
414
|
+
if (!n.ok)
|
|
415
|
+
throw new Error((r == null ? void 0 : r.error) || `Request failed (${n.status})`);
|
|
416
|
+
return r == null ? void 0 : r.value;
|
|
264
417
|
}
|
|
265
|
-
async function
|
|
266
|
-
const
|
|
267
|
-
|
|
268
|
-
const o = await
|
|
269
|
-
`/app-api/models${
|
|
418
|
+
async function C(e) {
|
|
419
|
+
const t = new URLSearchParams(), n = e == null ? void 0 : e.type, r = Array.isArray(n) ? n : n ? [n] : [];
|
|
420
|
+
r.length > 0 && t.set("type", r.join(",")), e != null && e.configuredOnly && t.set("configuredOnly", "true");
|
|
421
|
+
const o = await s(
|
|
422
|
+
`/app-api/models${t.toString() ? `?${t.toString()}` : ""}`,
|
|
270
423
|
{ method: "GET" }
|
|
271
|
-
),
|
|
424
|
+
), a = await o.json().catch(() => ({}));
|
|
272
425
|
if (!o.ok)
|
|
273
|
-
throw new Error((
|
|
274
|
-
return (Array.isArray(
|
|
275
|
-
if (!
|
|
276
|
-
const f = typeof
|
|
277
|
-
return !f ||
|
|
426
|
+
throw new Error((a == null ? void 0 : a.error) || `Request failed (${o.status})`);
|
|
427
|
+
return (Array.isArray(a == null ? void 0 : a.models) ? a.models : []).map((m) => {
|
|
428
|
+
if (!m || typeof m != "object") return null;
|
|
429
|
+
const f = typeof m.id == "string" ? m.id.trim() : "", b = typeof m.label == "string" ? m.label.trim() : f, A = m.type, w = m.configured === !0, z = typeof m.source == "string" && m.source.trim() ? m.source.trim() : void 0;
|
|
430
|
+
return !f || A !== "llm" && A !== "embedding" && A !== "image" && A !== "stt" && A !== "tts" ? null : {
|
|
278
431
|
id: f,
|
|
279
432
|
label: b || f,
|
|
280
|
-
type:
|
|
281
|
-
configured:
|
|
282
|
-
source:
|
|
433
|
+
type: A,
|
|
434
|
+
configured: w,
|
|
435
|
+
source: z
|
|
283
436
|
};
|
|
284
437
|
}).filter(
|
|
285
|
-
(
|
|
438
|
+
(m) => !!m
|
|
286
439
|
);
|
|
287
440
|
}
|
|
288
|
-
async function
|
|
289
|
-
const
|
|
290
|
-
if (!
|
|
441
|
+
async function S(e, t) {
|
|
442
|
+
const n = await s(e, t), o = (n.headers.get("content-type") || "").includes("application/json") ? await n.json().catch(() => ({})) : await n.text();
|
|
443
|
+
if (!n.ok)
|
|
291
444
|
throw new Error(
|
|
292
|
-
typeof o == "string" ? o || `Request failed (${
|
|
445
|
+
typeof o == "string" ? o || `Request failed (${n.status})` : (o == null ? void 0 : o.error) || (o == null ? void 0 : o.message) || `Request failed (${n.status})`
|
|
293
446
|
);
|
|
294
447
|
return o;
|
|
295
448
|
}
|
|
296
|
-
const
|
|
297
|
-
const
|
|
298
|
-
return
|
|
299
|
-
},
|
|
300
|
-
const r = { scope:
|
|
449
|
+
const $ = (e) => e ? e.split("/").map((t) => t.trim()).filter(Boolean).join("/") : "", R = (e, t) => {
|
|
450
|
+
const n = $(e), r = $(t);
|
|
451
|
+
return n ? r ? `${n}/${r}` : n : r;
|
|
452
|
+
}, P = (e, t, n) => {
|
|
453
|
+
const r = { scope: e, ...n ? { owner: n } : {} };
|
|
301
454
|
return {
|
|
455
|
+
async getAll() {
|
|
456
|
+
if (e !== "shared") throw new Error('getAll is only available for client.data("shared")');
|
|
457
|
+
const o = $(t), a = await s(`/app-api/data/shared${o ? `?path=${encodeURIComponent(o)}` : ""}`, { method: "GET" }), h = await a.json().catch(() => ({}));
|
|
458
|
+
if (!a.ok) throw new Error((h == null ? void 0 : h.error) || `Request failed (${a.status})`);
|
|
459
|
+
return Array.isArray(h == null ? void 0 : h.items) ? h.items : [];
|
|
460
|
+
},
|
|
302
461
|
async get() {
|
|
303
|
-
const
|
|
304
|
-
return
|
|
462
|
+
const o = $(t);
|
|
463
|
+
return L({ ...r, path: o || void 0 });
|
|
305
464
|
},
|
|
306
|
-
async set(
|
|
307
|
-
const
|
|
308
|
-
return
|
|
465
|
+
async set(o) {
|
|
466
|
+
const a = $(t);
|
|
467
|
+
return x("set", {
|
|
309
468
|
...r,
|
|
310
|
-
path:
|
|
311
|
-
value:
|
|
469
|
+
path: a || void 0,
|
|
470
|
+
value: o
|
|
312
471
|
});
|
|
313
472
|
},
|
|
314
|
-
async update(
|
|
315
|
-
if (!
|
|
473
|
+
async update(o) {
|
|
474
|
+
if (!o || typeof o != "object")
|
|
316
475
|
throw new Error("update requires an object");
|
|
317
|
-
const
|
|
318
|
-
for (const [
|
|
319
|
-
const
|
|
320
|
-
if (!
|
|
476
|
+
const a = {};
|
|
477
|
+
for (const [h, m] of Object.entries(o)) {
|
|
478
|
+
const f = R(t, h);
|
|
479
|
+
if (!f)
|
|
321
480
|
throw new Error("update paths must be non-empty");
|
|
322
|
-
|
|
481
|
+
a[f] = m;
|
|
323
482
|
}
|
|
324
|
-
return
|
|
483
|
+
return x("update", { ...r, updates: a });
|
|
325
484
|
},
|
|
326
485
|
async remove() {
|
|
327
|
-
const
|
|
328
|
-
return
|
|
486
|
+
const o = $(t);
|
|
487
|
+
return x("remove", { ...r, path: o || void 0 });
|
|
329
488
|
},
|
|
330
|
-
async push(
|
|
331
|
-
const
|
|
332
|
-
if (!
|
|
333
|
-
return
|
|
489
|
+
async push(o) {
|
|
490
|
+
const a = $(t);
|
|
491
|
+
if (!a) throw new Error("push requires a path");
|
|
492
|
+
return x("array-push", { ...r, path: a, value: o });
|
|
334
493
|
},
|
|
335
|
-
ref(
|
|
336
|
-
const
|
|
337
|
-
if (!
|
|
338
|
-
return
|
|
494
|
+
ref(o) {
|
|
495
|
+
const a = R(t, o);
|
|
496
|
+
if (!a) throw new Error("ref requires a path");
|
|
497
|
+
return P(e, a, n);
|
|
339
498
|
}
|
|
340
499
|
};
|
|
341
500
|
};
|
|
342
501
|
return {
|
|
343
502
|
functions: {
|
|
344
|
-
async invoke(
|
|
345
|
-
if (!/^[a-z][a-z0-9-]{0,63}$/.test(
|
|
346
|
-
const
|
|
503
|
+
async invoke(e, t) {
|
|
504
|
+
if (!/^[a-z][a-z0-9-]{0,63}$/.test(e)) throw new Error("Choose a valid function name or configured binding alias.");
|
|
505
|
+
const n = await s("/app-api/functions/invoke", {
|
|
347
506
|
method: "POST",
|
|
348
507
|
headers: { "Content-Type": "application/json" },
|
|
349
|
-
body: JSON.stringify({ name:
|
|
350
|
-
}),
|
|
351
|
-
if (!
|
|
352
|
-
return
|
|
508
|
+
body: JSON.stringify({ name: e, input: t })
|
|
509
|
+
}), r = await n.json().catch(() => ({}));
|
|
510
|
+
if (!n.ok) throw new Error((r == null ? void 0 : r.error) || `Function call failed (${n.status})`);
|
|
511
|
+
return r.output;
|
|
353
512
|
}
|
|
354
513
|
},
|
|
355
514
|
isReady() {
|
|
356
|
-
return !!i() && (!!
|
|
515
|
+
return !!i() && (!!c() || !!u());
|
|
357
516
|
},
|
|
358
517
|
getBackendUrl() {
|
|
359
|
-
var
|
|
360
|
-
return ((
|
|
518
|
+
var e;
|
|
519
|
+
return ((e = i()) == null ? void 0 : e.backendUrl) ?? null;
|
|
361
520
|
},
|
|
362
|
-
async models(
|
|
363
|
-
return
|
|
521
|
+
async models(e) {
|
|
522
|
+
return C(e);
|
|
364
523
|
},
|
|
365
|
-
async chatCompletions(
|
|
524
|
+
async chatCompletions(e) {
|
|
366
525
|
var b;
|
|
367
526
|
const {
|
|
368
|
-
reasoningEffort:
|
|
369
|
-
reasoning_effort:
|
|
370
|
-
...
|
|
371
|
-
} =
|
|
372
|
-
...
|
|
527
|
+
reasoningEffort: t,
|
|
528
|
+
reasoning_effort: n,
|
|
529
|
+
...r
|
|
530
|
+
} = e, o = t ?? n, a = {
|
|
531
|
+
...r,
|
|
373
532
|
stream: !1
|
|
374
533
|
};
|
|
375
|
-
o &&
|
|
376
|
-
const
|
|
534
|
+
o && v(e.model) && (a.reasoning_effort = o);
|
|
535
|
+
const h = await s("/openai/chat/completions", {
|
|
377
536
|
method: "POST",
|
|
378
537
|
headers: { "Content-Type": "application/json" },
|
|
379
|
-
body: JSON.stringify(
|
|
380
|
-
}), f = (
|
|
381
|
-
if (!
|
|
538
|
+
body: JSON.stringify(a)
|
|
539
|
+
}), f = (h.headers.get("content-type") || "").includes("application/json") ? await h.json() : await h.text();
|
|
540
|
+
if (!h.ok)
|
|
382
541
|
throw new Error(
|
|
383
|
-
typeof f == "string" ? f : (typeof (f == null ? void 0 : f.error) == "string" ? f.error : (b = f == null ? void 0 : f.error) == null ? void 0 : b.message) || `Request failed (${
|
|
542
|
+
typeof f == "string" ? f : (typeof (f == null ? void 0 : f.error) == "string" ? f.error : (b = f == null ? void 0 : f.error) == null ? void 0 : b.message) || `Request failed (${h.status})`
|
|
384
543
|
);
|
|
385
544
|
return f;
|
|
386
545
|
},
|
|
387
|
-
async chatText(
|
|
388
|
-
var
|
|
389
|
-
const
|
|
390
|
-
return ((o = (
|
|
546
|
+
async chatText(e) {
|
|
547
|
+
var n, r, o;
|
|
548
|
+
const t = await this.chatCompletions(e);
|
|
549
|
+
return ((o = (r = (n = t == null ? void 0 : t.choices) == null ? void 0 : n[0]) == null ? void 0 : r.message) == null ? void 0 : o.content) ?? "";
|
|
391
550
|
},
|
|
392
551
|
embeddings: {
|
|
393
|
-
async create(
|
|
552
|
+
async create(e) {
|
|
394
553
|
var o;
|
|
395
|
-
const
|
|
396
|
-
if (!
|
|
397
|
-
const
|
|
398
|
-
if (!(typeof
|
|
554
|
+
const t = (o = e == null ? void 0 : e.model) == null ? void 0 : o.trim();
|
|
555
|
+
if (!t) throw new Error("embeddings.create requires a model");
|
|
556
|
+
const n = e == null ? void 0 : e.input;
|
|
557
|
+
if (!(typeof n == "string" ? n.length > 0 : Array.isArray(n) && n.length > 0 && n.every((a) => typeof a == "string")))
|
|
399
558
|
throw new Error(
|
|
400
559
|
"embeddings.create requires input as a string or string[]"
|
|
401
560
|
);
|
|
402
|
-
return
|
|
561
|
+
return S("/openai/embeddings", {
|
|
403
562
|
method: "POST",
|
|
404
563
|
headers: { "Content-Type": "application/json" },
|
|
405
564
|
body: JSON.stringify({
|
|
406
|
-
...
|
|
407
|
-
model:
|
|
408
|
-
input:
|
|
565
|
+
...e,
|
|
566
|
+
model: t,
|
|
567
|
+
input: n
|
|
409
568
|
})
|
|
410
569
|
});
|
|
411
570
|
}
|
|
412
571
|
},
|
|
413
572
|
audio: {
|
|
414
573
|
async speechToken() {
|
|
415
|
-
const
|
|
416
|
-
if (!
|
|
417
|
-
return
|
|
574
|
+
const e = await s("/app-api/audio/speech-token", { method: "POST" });
|
|
575
|
+
if (!e.ok) throw new Error("Live talegenkendelse er ikke tilgængelig. Kontakt administratoren.");
|
|
576
|
+
return e.json();
|
|
418
577
|
},
|
|
419
578
|
async voiceLiveSession() {
|
|
420
|
-
const
|
|
579
|
+
const e = await s("/app-api/audio/voice-live-session", {
|
|
421
580
|
method: "POST"
|
|
422
581
|
});
|
|
423
|
-
if (!
|
|
424
|
-
const
|
|
425
|
-
throw new Error(
|
|
582
|
+
if (!e.ok) {
|
|
583
|
+
const t = await e.text();
|
|
584
|
+
throw new Error(t || "Voice Live er ikke tilgængelig.");
|
|
426
585
|
}
|
|
427
|
-
return
|
|
586
|
+
return e.json();
|
|
428
587
|
},
|
|
429
|
-
async tts(
|
|
588
|
+
async tts(e) {
|
|
430
589
|
var o;
|
|
431
|
-
const
|
|
432
|
-
if (!
|
|
433
|
-
const
|
|
590
|
+
const t = (o = e == null ? void 0 : e.text) == null ? void 0 : o.trim();
|
|
591
|
+
if (!t) throw new Error("audio.tts requires non-empty text");
|
|
592
|
+
const n = await s("/app-api/audio/tts", {
|
|
434
593
|
method: "POST",
|
|
435
594
|
headers: { "Content-Type": "application/json" },
|
|
436
595
|
body: JSON.stringify({
|
|
437
|
-
text:
|
|
438
|
-
voice:
|
|
439
|
-
lang:
|
|
596
|
+
text: t,
|
|
597
|
+
voice: e.voice,
|
|
598
|
+
lang: e.lang
|
|
440
599
|
})
|
|
441
600
|
});
|
|
442
|
-
if (!
|
|
443
|
-
const
|
|
444
|
-
throw new Error(
|
|
601
|
+
if (!n.ok) {
|
|
602
|
+
const a = await n.text();
|
|
603
|
+
throw new Error(a || `Request failed (${n.status})`);
|
|
445
604
|
}
|
|
446
605
|
return {
|
|
447
|
-
audio: await
|
|
448
|
-
contentType:
|
|
606
|
+
audio: await n.arrayBuffer(),
|
|
607
|
+
contentType: n.headers.get("content-type")
|
|
449
608
|
};
|
|
450
609
|
},
|
|
451
|
-
async stt(
|
|
452
|
-
var
|
|
453
|
-
if (!(
|
|
454
|
-
const
|
|
610
|
+
async stt(e) {
|
|
611
|
+
var E, l, y, I;
|
|
612
|
+
if (!(e != null && e.file)) throw new Error("audio.stt requires a file");
|
|
613
|
+
const t = (E = e.language) == null ? void 0 : E.trim(), n = (M) => {
|
|
455
614
|
if (!M) return;
|
|
456
|
-
const
|
|
457
|
-
if (!
|
|
458
|
-
const
|
|
459
|
-
return
|
|
460
|
-
},
|
|
461
|
-
|
|
462
|
-
const
|
|
463
|
-
|
|
464
|
-
const f = new URLSearchParams({ ext:
|
|
465
|
-
|
|
466
|
-
const b = await
|
|
615
|
+
const B = M.trim();
|
|
616
|
+
if (!B) return;
|
|
617
|
+
const T = B.toLowerCase(), F = T.split("-")[0];
|
|
618
|
+
return F.length === 2 ? F : T;
|
|
619
|
+
}, r = typeof File < "u" && e.file instanceof File, o = r && e.file.name.split(".").pop() || "webm", a = e.ext || o, h = new FormData();
|
|
620
|
+
r ? h.set("file", e.file) : h.set("file", e.file, `audio.${a}`);
|
|
621
|
+
const m = n(t);
|
|
622
|
+
m && h.set("language", m), e.prompt && h.set("prompt", e.prompt), e.responseFormat && h.set("response_format", e.responseFormat);
|
|
623
|
+
const f = new URLSearchParams({ ext: a });
|
|
624
|
+
t && f.set("locale", t);
|
|
625
|
+
const b = await s(
|
|
467
626
|
`/app-api/audio/stt?${f.toString()}`,
|
|
468
627
|
{
|
|
469
628
|
method: "POST",
|
|
470
|
-
body:
|
|
629
|
+
body: h
|
|
471
630
|
}
|
|
472
|
-
),
|
|
631
|
+
), w = (b.headers.get("content-type") || "").includes("application/json") ? await b.json() : await b.text();
|
|
473
632
|
if (!b.ok)
|
|
474
633
|
throw new Error(
|
|
475
|
-
typeof
|
|
634
|
+
typeof w == "string" ? w : (typeof (w == null ? void 0 : w.error) == "string" ? w.error : (l = w == null ? void 0 : w.error) == null ? void 0 : l.message) || `Request failed (${b.status})`
|
|
476
635
|
);
|
|
477
|
-
const
|
|
478
|
-
return { text:
|
|
636
|
+
const z = typeof w == "string" ? w : (w == null ? void 0 : w.text) || (w == null ? void 0 : w.original) || ((I = (y = w == null ? void 0 : w.results) == null ? void 0 : y[0]) == null ? void 0 : I.text) || "", U = typeof w == "object" && typeof (w == null ? void 0 : w.language) == "string" ? w.language : void 0;
|
|
637
|
+
return { text: z, language: U, raw: w };
|
|
479
638
|
},
|
|
480
|
-
async voices(
|
|
481
|
-
const
|
|
482
|
-
|
|
483
|
-
const
|
|
484
|
-
`/app-api/audio/tts/voices${
|
|
639
|
+
async voices(e) {
|
|
640
|
+
const t = new URLSearchParams();
|
|
641
|
+
e != null && e.locale && t.set("locale", e.locale);
|
|
642
|
+
const n = await s(
|
|
643
|
+
`/app-api/audio/tts/voices${t.toString() ? `?${t}` : ""}`,
|
|
485
644
|
{ method: "GET" }
|
|
486
|
-
),
|
|
487
|
-
if (!
|
|
645
|
+
), r = await n.json().catch(() => []);
|
|
646
|
+
if (!n.ok)
|
|
488
647
|
throw new Error(
|
|
489
|
-
(
|
|
648
|
+
(r == null ? void 0 : r.error) || `Request failed (${n.status})`
|
|
490
649
|
);
|
|
491
|
-
return Array.isArray(
|
|
650
|
+
return Array.isArray(r) ? r : (r == null ? void 0 : r.voices) || [];
|
|
492
651
|
}
|
|
493
652
|
},
|
|
494
653
|
web: {
|
|
495
|
-
async scrapeUrl(
|
|
496
|
-
var
|
|
497
|
-
const
|
|
498
|
-
if (!
|
|
499
|
-
return
|
|
654
|
+
async scrapeUrl(e) {
|
|
655
|
+
var n;
|
|
656
|
+
const t = (n = e == null ? void 0 : e.url) == null ? void 0 : n.trim();
|
|
657
|
+
if (!t) throw new Error("web.scrapeUrl requires a url");
|
|
658
|
+
return S(
|
|
500
659
|
"/app-api/web/scrape-url",
|
|
501
660
|
{
|
|
502
661
|
method: "POST",
|
|
503
662
|
headers: { "Content-Type": "application/json" },
|
|
504
663
|
body: JSON.stringify({
|
|
505
|
-
url:
|
|
506
|
-
maxChars:
|
|
664
|
+
url: t,
|
|
665
|
+
maxChars: e.maxChars
|
|
507
666
|
})
|
|
508
667
|
}
|
|
509
668
|
);
|
|
510
669
|
}
|
|
511
670
|
},
|
|
512
671
|
knowledge: {
|
|
513
|
-
async search(
|
|
514
|
-
var
|
|
515
|
-
const
|
|
516
|
-
if (!
|
|
517
|
-
return
|
|
672
|
+
async search(e) {
|
|
673
|
+
var n;
|
|
674
|
+
const t = (n = e == null ? void 0 : e.query) == null ? void 0 : n.trim();
|
|
675
|
+
if (!t) throw new Error("knowledge.search requires a query");
|
|
676
|
+
return S(
|
|
518
677
|
"/app-api/knowledge/search",
|
|
519
678
|
{
|
|
520
679
|
method: "POST",
|
|
521
680
|
headers: { "Content-Type": "application/json" },
|
|
522
681
|
body: JSON.stringify({
|
|
523
|
-
workspaceId:
|
|
524
|
-
query:
|
|
525
|
-
maxResults:
|
|
526
|
-
generateSearchQuery:
|
|
527
|
-
sourceId:
|
|
528
|
-
includeSourceUrls:
|
|
529
|
-
queries:
|
|
682
|
+
workspaceId: e.workspaceId,
|
|
683
|
+
query: t,
|
|
684
|
+
maxResults: e.maxResults,
|
|
685
|
+
generateSearchQuery: e.generateSearchQuery,
|
|
686
|
+
sourceId: e.sourceId,
|
|
687
|
+
includeSourceUrls: e.includeSourceUrls,
|
|
688
|
+
queries: e.queries
|
|
530
689
|
})
|
|
531
690
|
}
|
|
532
691
|
);
|
|
533
692
|
}
|
|
534
693
|
},
|
|
694
|
+
assistant: {
|
|
695
|
+
async ask(e) {
|
|
696
|
+
var n;
|
|
697
|
+
const t = (n = e == null ? void 0 : e.question) == null ? void 0 : n.trim();
|
|
698
|
+
if (!(e != null && e.assistantId)) throw new Error("assistant.ask requires an assistantId");
|
|
699
|
+
if (!t) throw new Error("assistant.ask requires a question");
|
|
700
|
+
return S("/app-api/assistant/ask", {
|
|
701
|
+
method: "POST",
|
|
702
|
+
headers: { "Content-Type": "application/json" },
|
|
703
|
+
body: JSON.stringify({
|
|
704
|
+
assistantId: e.assistantId,
|
|
705
|
+
question: t,
|
|
706
|
+
conversationId: e.conversationId
|
|
707
|
+
})
|
|
708
|
+
});
|
|
709
|
+
}
|
|
710
|
+
},
|
|
535
711
|
translatorLiveShare: {
|
|
536
|
-
async create(
|
|
537
|
-
return
|
|
712
|
+
async create(e) {
|
|
713
|
+
return S("/app-api/translator/live-share", {
|
|
538
714
|
method: "POST",
|
|
539
715
|
headers: { "Content-Type": "application/json" },
|
|
540
|
-
body: JSON.stringify({ displayLanguage:
|
|
716
|
+
body: JSON.stringify({ displayLanguage: e })
|
|
541
717
|
});
|
|
542
718
|
},
|
|
543
|
-
async update(
|
|
544
|
-
await
|
|
719
|
+
async update(e, t) {
|
|
720
|
+
await S(`/app-api/translator/live-share/${encodeURIComponent(e)}`, {
|
|
545
721
|
method: "PUT",
|
|
546
722
|
headers: { "Content-Type": "application/json" },
|
|
547
|
-
body: JSON.stringify(
|
|
723
|
+
body: JSON.stringify(t)
|
|
548
724
|
});
|
|
549
725
|
},
|
|
550
|
-
async revoke(
|
|
551
|
-
await
|
|
726
|
+
async revoke(e) {
|
|
727
|
+
await S(`/app-api/translator/live-share/${encodeURIComponent(e)}`, {
|
|
552
728
|
method: "DELETE"
|
|
553
729
|
});
|
|
554
730
|
}
|
|
555
731
|
},
|
|
556
732
|
guardrails: {
|
|
557
|
-
async check(
|
|
558
|
-
return
|
|
733
|
+
async check(e) {
|
|
734
|
+
return S("/app-api/guardrails/check", {
|
|
559
735
|
method: "POST",
|
|
560
736
|
headers: { "Content-Type": "application/json" },
|
|
561
|
-
body: JSON.stringify({ value:
|
|
737
|
+
body: JSON.stringify({ value: e })
|
|
562
738
|
});
|
|
563
739
|
}
|
|
564
740
|
},
|
|
565
|
-
|
|
566
|
-
|
|
741
|
+
email: {
|
|
742
|
+
async send(e) {
|
|
743
|
+
const t = await s("/app-api/email/send", {
|
|
744
|
+
method: "POST",
|
|
745
|
+
headers: { "Content-Type": "application/json" },
|
|
746
|
+
body: JSON.stringify(e)
|
|
747
|
+
}), n = await t.json().catch(() => ({}));
|
|
748
|
+
if (!t.ok) {
|
|
749
|
+
const r = (n == null ? void 0 : n.code) || (t.status === 401 ? "sign_in_required" : "server_error");
|
|
750
|
+
throw new pe(r, t.status, n != null && n.error && n.error !== r ? n.error : void 0);
|
|
751
|
+
}
|
|
752
|
+
return n;
|
|
753
|
+
}
|
|
754
|
+
},
|
|
755
|
+
data(e = "private", t) {
|
|
756
|
+
return P(e, "", t == null ? void 0 : t.owner);
|
|
567
757
|
},
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
758
|
+
assets: g,
|
|
759
|
+
files(e = "private") {
|
|
760
|
+
const t = (r = {}) => new URLSearchParams({ scope: e, ...r }).toString(), n = async (r) => {
|
|
761
|
+
const o = await r.json().catch(() => ({}));
|
|
762
|
+
return new Error((o == null ? void 0 : o.error) || `Request failed (${r.status})`);
|
|
572
763
|
};
|
|
573
764
|
return {
|
|
574
|
-
async upload(
|
|
575
|
-
const
|
|
576
|
-
if (!
|
|
577
|
-
const
|
|
765
|
+
async upload(r, o = {}) {
|
|
766
|
+
const a = o.name || r.name;
|
|
767
|
+
if (!a) throw new Error("A file name is required.");
|
|
768
|
+
const h = o.contentType || r.type || "application/octet-stream", m = await s(`/app-api/files?${t({ name: a, contentType: h })}`, {
|
|
578
769
|
method: "POST",
|
|
579
770
|
headers: { "Content-Type": "application/octet-stream" },
|
|
580
|
-
body:
|
|
771
|
+
body: r,
|
|
581
772
|
signal: o.signal
|
|
582
773
|
});
|
|
583
|
-
if (!
|
|
584
|
-
return (await
|
|
774
|
+
if (!m.ok) throw await n(m);
|
|
775
|
+
return (await m.json()).file;
|
|
585
776
|
},
|
|
586
|
-
async list(
|
|
587
|
-
const o = await
|
|
588
|
-
`/app-api/files?${
|
|
777
|
+
async list(r = {}) {
|
|
778
|
+
const o = await s(
|
|
779
|
+
`/app-api/files?${t(r.prefix ? { prefix: r.prefix } : {})}`,
|
|
589
780
|
{ method: "GET" }
|
|
590
781
|
);
|
|
591
|
-
if (!o.ok) throw await
|
|
782
|
+
if (!o.ok) throw await n(o);
|
|
592
783
|
return (await o.json()).files;
|
|
593
784
|
},
|
|
594
|
-
async download(
|
|
595
|
-
const
|
|
785
|
+
async download(r, o = {}) {
|
|
786
|
+
const a = await s(`/app-api/files/${encodeURIComponent(r)}?${t()}`, {
|
|
596
787
|
method: "GET",
|
|
597
788
|
signal: o.signal
|
|
598
789
|
});
|
|
599
|
-
if (!
|
|
600
|
-
return
|
|
790
|
+
if (!a.ok) throw await n(a);
|
|
791
|
+
return a.blob();
|
|
601
792
|
},
|
|
602
|
-
async remove(
|
|
603
|
-
const o = await
|
|
793
|
+
async remove(r) {
|
|
794
|
+
const o = await s(`/app-api/files/${encodeURIComponent(r)}?${t()}`, {
|
|
604
795
|
method: "DELETE"
|
|
605
796
|
});
|
|
606
|
-
if (!o.ok) throw await
|
|
797
|
+
if (!o.ok) throw await n(o);
|
|
607
798
|
}
|
|
608
799
|
};
|
|
609
800
|
}
|
|
610
801
|
};
|
|
611
802
|
}
|
|
612
803
|
export {
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
804
|
+
Te as PromteAppProvider,
|
|
805
|
+
pe as PromteEmailError,
|
|
806
|
+
ke as PromteNativeProvider,
|
|
807
|
+
J as usePromte,
|
|
808
|
+
Ue as usePromteAuth,
|
|
809
|
+
de as usePromteClient,
|
|
810
|
+
$e as usePromteDarkMode,
|
|
811
|
+
xe as usePromteModels,
|
|
812
|
+
Se as usePromteSettings,
|
|
813
|
+
Pe as usePromteToken,
|
|
814
|
+
Re as usePromteUser
|
|
622
815
|
};
|