@promte/app-library 0.1.7 → 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 +51 -0
- package/dist/index.d.ts +225 -2
- package/dist/index.mjs +637 -303
- package/dist/index.umd.cjs +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -1,481 +1,815 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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({
|
|
14
|
+
children: i,
|
|
15
|
+
expectedParentOrigin: c,
|
|
16
|
+
initTargetOrigin: u,
|
|
17
|
+
retryInit: v = { enabled: !0, intervalMs: 500, maxAttempts: 20 }
|
|
9
18
|
}) {
|
|
10
|
-
const [
|
|
11
|
-
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;
|
|
12
21
|
try {
|
|
13
|
-
const
|
|
14
|
-
(
|
|
15
|
-
} catch (
|
|
16
|
-
|
|
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");
|
|
17
26
|
}
|
|
18
|
-
}, [
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}, [
|
|
22
|
-
if (!(
|
|
23
|
-
const
|
|
24
|
-
let
|
|
25
|
-
const
|
|
26
|
-
if (
|
|
27
|
-
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);
|
|
28
37
|
return;
|
|
29
38
|
}
|
|
30
|
-
if (
|
|
31
|
-
window.clearInterval(
|
|
39
|
+
if (l += 1, l > E) {
|
|
40
|
+
window.clearInterval(y);
|
|
32
41
|
return;
|
|
33
42
|
}
|
|
34
|
-
|
|
35
|
-
},
|
|
36
|
-
return () => window.clearInterval(
|
|
37
|
-
}, [
|
|
38
|
-
const
|
|
39
|
-
if (
|
|
40
|
-
const
|
|
41
|
-
if (!(!
|
|
42
|
-
if (
|
|
43
|
-
const
|
|
44
|
-
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)
|
|
45
54
|
return;
|
|
46
|
-
k(
|
|
55
|
+
k(y), t(E.source === window.parent ? E.origin : null), y != null && y.user && $(y.user), P(null);
|
|
47
56
|
return;
|
|
48
57
|
}
|
|
49
|
-
if (
|
|
50
|
-
|
|
58
|
+
if (l.type === "set-token" && typeof l.value == "string") {
|
|
59
|
+
x(l.value), P(null);
|
|
51
60
|
return;
|
|
52
61
|
}
|
|
53
|
-
if (
|
|
54
|
-
|
|
62
|
+
if (l.type === "set-dark-mode" && typeof l.value == "boolean") {
|
|
63
|
+
C(l.value);
|
|
55
64
|
return;
|
|
56
65
|
}
|
|
57
|
-
if (
|
|
58
|
-
|
|
66
|
+
if (l.type === "set-user" && typeof l.value == "object") {
|
|
67
|
+
$(l.value);
|
|
59
68
|
return;
|
|
60
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 {
|
|
61
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);
|
|
62
153
|
};
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
()
|
|
67
|
-
() =>
|
|
68
|
-
|
|
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(
|
|
69
172
|
() => ({
|
|
70
|
-
settings:
|
|
71
|
-
token:
|
|
72
|
-
isDarkMode:
|
|
173
|
+
settings: s,
|
|
174
|
+
token: g,
|
|
175
|
+
isDarkMode: L,
|
|
73
176
|
user: S,
|
|
74
|
-
ready:
|
|
75
|
-
state:
|
|
76
|
-
error:
|
|
77
|
-
client:
|
|
177
|
+
ready: h,
|
|
178
|
+
state: a,
|
|
179
|
+
error: R,
|
|
180
|
+
client: b,
|
|
181
|
+
auth: n,
|
|
182
|
+
authRequest: w
|
|
78
183
|
}),
|
|
79
|
-
[
|
|
184
|
+
[s, g, L, S, h, a, R, b, n, w]
|
|
80
185
|
);
|
|
81
|
-
return /* @__PURE__ */
|
|
186
|
+
return /* @__PURE__ */ oe(Z.Provider, { value: z, children: i });
|
|
82
187
|
}
|
|
83
|
-
function
|
|
84
|
-
children:
|
|
85
|
-
settings:
|
|
86
|
-
token:
|
|
87
|
-
isDarkMode:
|
|
88
|
-
user:
|
|
188
|
+
function ke({
|
|
189
|
+
children: i,
|
|
190
|
+
settings: c,
|
|
191
|
+
token: u,
|
|
192
|
+
isDarkMode: v,
|
|
193
|
+
user: s
|
|
89
194
|
}) {
|
|
90
|
-
const k =
|
|
91
|
-
() =>
|
|
92
|
-
[
|
|
93
|
-
),
|
|
195
|
+
const k = G(
|
|
196
|
+
() => se(() => c, () => u),
|
|
197
|
+
[c, u]
|
|
198
|
+
), g = !!u, x = G(
|
|
94
199
|
() => ({
|
|
95
|
-
settings:
|
|
96
|
-
token:
|
|
97
|
-
isDarkMode:
|
|
98
|
-
user:
|
|
99
|
-
ready:
|
|
100
|
-
state:
|
|
200
|
+
settings: c,
|
|
201
|
+
token: u,
|
|
202
|
+
isDarkMode: v,
|
|
203
|
+
user: s,
|
|
204
|
+
ready: g,
|
|
205
|
+
state: g ? "ready" : "waiting_for_token",
|
|
101
206
|
error: null,
|
|
102
|
-
client: k
|
|
207
|
+
client: k,
|
|
208
|
+
auth: Y,
|
|
209
|
+
authRequest: () => Promise.reject(new Error("not_available"))
|
|
103
210
|
}),
|
|
104
|
-
[k,
|
|
211
|
+
[k, v, g, c, u, s]
|
|
105
212
|
);
|
|
106
|
-
return /* @__PURE__ */
|
|
213
|
+
return /* @__PURE__ */ oe(Z.Provider, { value: x, children: i });
|
|
107
214
|
}
|
|
108
|
-
function
|
|
109
|
-
const
|
|
110
|
-
if (!
|
|
215
|
+
function J() {
|
|
216
|
+
const i = le(Z);
|
|
217
|
+
if (!i)
|
|
111
218
|
throw new Error(
|
|
112
219
|
"usePromte must be used inside <PromteAppProvider> or <PromteNativeProvider>"
|
|
113
220
|
);
|
|
114
|
-
return
|
|
221
|
+
return i;
|
|
222
|
+
}
|
|
223
|
+
function Se() {
|
|
224
|
+
return J().settings;
|
|
115
225
|
}
|
|
116
|
-
function
|
|
117
|
-
return
|
|
226
|
+
function Pe() {
|
|
227
|
+
return J().token;
|
|
118
228
|
}
|
|
119
|
-
function
|
|
120
|
-
return
|
|
229
|
+
function $e() {
|
|
230
|
+
return J().isDarkMode;
|
|
121
231
|
}
|
|
122
|
-
function
|
|
123
|
-
return
|
|
232
|
+
function Re() {
|
|
233
|
+
return J().user;
|
|
124
234
|
}
|
|
125
|
-
function
|
|
126
|
-
return
|
|
235
|
+
function de() {
|
|
236
|
+
return J().client;
|
|
127
237
|
}
|
|
128
|
-
function
|
|
129
|
-
|
|
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]);
|
|
130
254
|
}
|
|
131
|
-
function
|
|
132
|
-
const { ready:
|
|
133
|
-
if (!
|
|
134
|
-
|
|
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);
|
|
135
259
|
try {
|
|
136
|
-
const
|
|
137
|
-
return
|
|
138
|
-
} catch (
|
|
139
|
-
const
|
|
140
|
-
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;
|
|
141
265
|
} finally {
|
|
142
|
-
|
|
266
|
+
g(!1);
|
|
143
267
|
}
|
|
144
|
-
}, [
|
|
145
|
-
return
|
|
146
|
-
|
|
268
|
+
}, [u, S, c, C]);
|
|
269
|
+
return K(() => {
|
|
270
|
+
!$ || !c || R().catch(() => {
|
|
147
271
|
});
|
|
148
|
-
}, [
|
|
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
|
+
});
|
|
149
357
|
}
|
|
150
|
-
function
|
|
151
|
-
const
|
|
152
|
-
async function
|
|
153
|
-
const
|
|
154
|
-
if (!
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
...
|
|
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,
|
|
159
367
|
headers: {
|
|
160
|
-
...
|
|
161
|
-
Authorization: `Bearer ${
|
|
368
|
+
...t.headers || {},
|
|
369
|
+
Authorization: `Bearer ${r}`
|
|
162
370
|
}
|
|
163
371
|
});
|
|
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;
|
|
164
376
|
}
|
|
165
|
-
|
|
166
|
-
|
|
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}`, {
|
|
167
398
|
method: "POST",
|
|
168
399
|
headers: { "Content-Type": "application/json" },
|
|
169
|
-
body: JSON.stringify(
|
|
170
|
-
}),
|
|
171
|
-
if (!
|
|
400
|
+
body: JSON.stringify(t)
|
|
401
|
+
}), r = await n.json().catch(() => ({}));
|
|
402
|
+
if (!n.ok)
|
|
172
403
|
throw new Error(
|
|
173
|
-
(
|
|
404
|
+
(r == null ? void 0 : r.error) || `Request failed (${n.status})`
|
|
174
405
|
);
|
|
175
|
-
return
|
|
406
|
+
return r == null ? void 0 : r.value;
|
|
176
407
|
}
|
|
177
|
-
async function
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
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()}`, {
|
|
181
412
|
method: "GET"
|
|
182
|
-
}),
|
|
183
|
-
if (!
|
|
184
|
-
throw new Error((
|
|
185
|
-
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;
|
|
186
417
|
}
|
|
187
|
-
async function
|
|
188
|
-
const
|
|
189
|
-
|
|
190
|
-
const o = await
|
|
191
|
-
`/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()}` : ""}`,
|
|
192
423
|
{ method: "GET" }
|
|
193
424
|
), a = await o.json().catch(() => ({}));
|
|
194
425
|
if (!o.ok)
|
|
195
426
|
throw new Error((a == null ? void 0 : a.error) || `Request failed (${o.status})`);
|
|
196
|
-
return (Array.isArray(a == null ? void 0 : a.models) ? a.models : []).map((
|
|
197
|
-
if (!
|
|
198
|
-
const
|
|
199
|
-
return !
|
|
200
|
-
id:
|
|
201
|
-
label:
|
|
202
|
-
type:
|
|
203
|
-
configured:
|
|
204
|
-
source:
|
|
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 : {
|
|
431
|
+
id: f,
|
|
432
|
+
label: b || f,
|
|
433
|
+
type: A,
|
|
434
|
+
configured: w,
|
|
435
|
+
source: z
|
|
205
436
|
};
|
|
206
437
|
}).filter(
|
|
207
|
-
(
|
|
438
|
+
(m) => !!m
|
|
208
439
|
);
|
|
209
440
|
}
|
|
210
|
-
async function
|
|
211
|
-
const
|
|
212
|
-
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)
|
|
213
444
|
throw new Error(
|
|
214
|
-
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})`
|
|
215
446
|
);
|
|
216
447
|
return o;
|
|
217
448
|
}
|
|
218
|
-
const
|
|
219
|
-
const
|
|
220
|
-
return
|
|
221
|
-
},
|
|
222
|
-
const
|
|
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 } : {} };
|
|
223
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
|
+
},
|
|
224
461
|
async get() {
|
|
225
|
-
const
|
|
226
|
-
return
|
|
462
|
+
const o = $(t);
|
|
463
|
+
return L({ ...r, path: o || void 0 });
|
|
227
464
|
},
|
|
228
|
-
async set(
|
|
229
|
-
const
|
|
230
|
-
return
|
|
231
|
-
...
|
|
232
|
-
path:
|
|
233
|
-
value:
|
|
465
|
+
async set(o) {
|
|
466
|
+
const a = $(t);
|
|
467
|
+
return x("set", {
|
|
468
|
+
...r,
|
|
469
|
+
path: a || void 0,
|
|
470
|
+
value: o
|
|
234
471
|
});
|
|
235
472
|
},
|
|
236
|
-
async update(
|
|
237
|
-
if (!
|
|
473
|
+
async update(o) {
|
|
474
|
+
if (!o || typeof o != "object")
|
|
238
475
|
throw new Error("update requires an object");
|
|
239
|
-
const
|
|
240
|
-
for (const [
|
|
241
|
-
const
|
|
242
|
-
if (!
|
|
476
|
+
const a = {};
|
|
477
|
+
for (const [h, m] of Object.entries(o)) {
|
|
478
|
+
const f = R(t, h);
|
|
479
|
+
if (!f)
|
|
243
480
|
throw new Error("update paths must be non-empty");
|
|
244
|
-
|
|
481
|
+
a[f] = m;
|
|
245
482
|
}
|
|
246
|
-
return
|
|
483
|
+
return x("update", { ...r, updates: a });
|
|
247
484
|
},
|
|
248
485
|
async remove() {
|
|
249
|
-
const
|
|
250
|
-
return
|
|
486
|
+
const o = $(t);
|
|
487
|
+
return x("remove", { ...r, path: o || void 0 });
|
|
251
488
|
},
|
|
252
|
-
async push(
|
|
253
|
-
const
|
|
254
|
-
if (!
|
|
255
|
-
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 });
|
|
256
493
|
},
|
|
257
|
-
ref(
|
|
258
|
-
const
|
|
259
|
-
if (!
|
|
260
|
-
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);
|
|
261
498
|
}
|
|
262
499
|
};
|
|
263
500
|
};
|
|
264
501
|
return {
|
|
502
|
+
functions: {
|
|
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", {
|
|
506
|
+
method: "POST",
|
|
507
|
+
headers: { "Content-Type": "application/json" },
|
|
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;
|
|
512
|
+
}
|
|
513
|
+
},
|
|
265
514
|
isReady() {
|
|
266
|
-
return !!
|
|
515
|
+
return !!i() && (!!c() || !!u());
|
|
267
516
|
},
|
|
268
517
|
getBackendUrl() {
|
|
269
|
-
var
|
|
270
|
-
return ((
|
|
518
|
+
var e;
|
|
519
|
+
return ((e = i()) == null ? void 0 : e.backendUrl) ?? null;
|
|
271
520
|
},
|
|
272
|
-
async models(
|
|
273
|
-
return
|
|
521
|
+
async models(e) {
|
|
522
|
+
return C(e);
|
|
274
523
|
},
|
|
275
|
-
async chatCompletions(
|
|
276
|
-
var
|
|
524
|
+
async chatCompletions(e) {
|
|
525
|
+
var b;
|
|
277
526
|
const {
|
|
278
|
-
reasoningEffort:
|
|
279
|
-
reasoning_effort:
|
|
280
|
-
...
|
|
281
|
-
} =
|
|
282
|
-
...
|
|
527
|
+
reasoningEffort: t,
|
|
528
|
+
reasoning_effort: n,
|
|
529
|
+
...r
|
|
530
|
+
} = e, o = t ?? n, a = {
|
|
531
|
+
...r,
|
|
283
532
|
stream: !1
|
|
284
533
|
};
|
|
285
|
-
o &&
|
|
286
|
-
const
|
|
534
|
+
o && v(e.model) && (a.reasoning_effort = o);
|
|
535
|
+
const h = await s("/openai/chat/completions", {
|
|
287
536
|
method: "POST",
|
|
288
537
|
headers: { "Content-Type": "application/json" },
|
|
289
538
|
body: JSON.stringify(a)
|
|
290
|
-
}),
|
|
291
|
-
if (!
|
|
539
|
+
}), f = (h.headers.get("content-type") || "").includes("application/json") ? await h.json() : await h.text();
|
|
540
|
+
if (!h.ok)
|
|
292
541
|
throw new Error(
|
|
293
|
-
typeof
|
|
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})`
|
|
294
543
|
);
|
|
295
|
-
return
|
|
544
|
+
return f;
|
|
296
545
|
},
|
|
297
|
-
async chatText(
|
|
298
|
-
var
|
|
299
|
-
const
|
|
300
|
-
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) ?? "";
|
|
301
550
|
},
|
|
302
551
|
embeddings: {
|
|
303
|
-
async create(
|
|
552
|
+
async create(e) {
|
|
304
553
|
var o;
|
|
305
|
-
const
|
|
306
|
-
if (!
|
|
307
|
-
const
|
|
308
|
-
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")))
|
|
309
558
|
throw new Error(
|
|
310
559
|
"embeddings.create requires input as a string or string[]"
|
|
311
560
|
);
|
|
312
|
-
return
|
|
561
|
+
return S("/openai/embeddings", {
|
|
313
562
|
method: "POST",
|
|
314
563
|
headers: { "Content-Type": "application/json" },
|
|
315
564
|
body: JSON.stringify({
|
|
316
|
-
...
|
|
317
|
-
model:
|
|
318
|
-
input:
|
|
565
|
+
...e,
|
|
566
|
+
model: t,
|
|
567
|
+
input: n
|
|
319
568
|
})
|
|
320
569
|
});
|
|
321
570
|
}
|
|
322
571
|
},
|
|
323
572
|
audio: {
|
|
324
573
|
async speechToken() {
|
|
325
|
-
const
|
|
326
|
-
if (!
|
|
327
|
-
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();
|
|
328
577
|
},
|
|
329
578
|
async voiceLiveSession() {
|
|
330
|
-
const
|
|
579
|
+
const e = await s("/app-api/audio/voice-live-session", {
|
|
331
580
|
method: "POST"
|
|
332
581
|
});
|
|
333
|
-
if (!
|
|
334
|
-
const
|
|
335
|
-
throw new Error(
|
|
582
|
+
if (!e.ok) {
|
|
583
|
+
const t = await e.text();
|
|
584
|
+
throw new Error(t || "Voice Live er ikke tilgængelig.");
|
|
336
585
|
}
|
|
337
|
-
return
|
|
586
|
+
return e.json();
|
|
338
587
|
},
|
|
339
|
-
async tts(
|
|
588
|
+
async tts(e) {
|
|
340
589
|
var o;
|
|
341
|
-
const
|
|
342
|
-
if (!
|
|
343
|
-
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", {
|
|
344
593
|
method: "POST",
|
|
345
594
|
headers: { "Content-Type": "application/json" },
|
|
346
595
|
body: JSON.stringify({
|
|
347
|
-
text:
|
|
348
|
-
voice:
|
|
349
|
-
lang:
|
|
596
|
+
text: t,
|
|
597
|
+
voice: e.voice,
|
|
598
|
+
lang: e.lang
|
|
350
599
|
})
|
|
351
600
|
});
|
|
352
|
-
if (!
|
|
353
|
-
const a = await
|
|
354
|
-
throw new Error(a || `Request failed (${
|
|
601
|
+
if (!n.ok) {
|
|
602
|
+
const a = await n.text();
|
|
603
|
+
throw new Error(a || `Request failed (${n.status})`);
|
|
355
604
|
}
|
|
356
605
|
return {
|
|
357
|
-
audio: await
|
|
358
|
-
contentType:
|
|
606
|
+
audio: await n.arrayBuffer(),
|
|
607
|
+
contentType: n.headers.get("content-type")
|
|
359
608
|
};
|
|
360
609
|
},
|
|
361
|
-
async stt(
|
|
362
|
-
var
|
|
363
|
-
if (!(
|
|
364
|
-
const
|
|
365
|
-
if (!
|
|
366
|
-
const
|
|
367
|
-
if (!
|
|
368
|
-
const
|
|
369
|
-
return
|
|
370
|
-
},
|
|
371
|
-
|
|
372
|
-
const
|
|
373
|
-
|
|
374
|
-
const
|
|
375
|
-
|
|
376
|
-
const
|
|
377
|
-
`/app-api/audio/stt?${
|
|
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) => {
|
|
614
|
+
if (!M) return;
|
|
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(
|
|
626
|
+
`/app-api/audio/stt?${f.toString()}`,
|
|
378
627
|
{
|
|
379
628
|
method: "POST",
|
|
380
|
-
body:
|
|
629
|
+
body: h
|
|
381
630
|
}
|
|
382
|
-
),
|
|
383
|
-
if (!
|
|
631
|
+
), w = (b.headers.get("content-type") || "").includes("application/json") ? await b.json() : await b.text();
|
|
632
|
+
if (!b.ok)
|
|
384
633
|
throw new Error(
|
|
385
|
-
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})`
|
|
386
635
|
);
|
|
387
|
-
const
|
|
388
|
-
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 };
|
|
389
638
|
},
|
|
390
|
-
async voices(
|
|
391
|
-
const
|
|
392
|
-
|
|
393
|
-
const
|
|
394
|
-
`/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}` : ""}`,
|
|
395
644
|
{ method: "GET" }
|
|
396
|
-
),
|
|
397
|
-
if (!
|
|
645
|
+
), r = await n.json().catch(() => []);
|
|
646
|
+
if (!n.ok)
|
|
398
647
|
throw new Error(
|
|
399
|
-
(
|
|
648
|
+
(r == null ? void 0 : r.error) || `Request failed (${n.status})`
|
|
400
649
|
);
|
|
401
|
-
return Array.isArray(
|
|
650
|
+
return Array.isArray(r) ? r : (r == null ? void 0 : r.voices) || [];
|
|
402
651
|
}
|
|
403
652
|
},
|
|
404
653
|
web: {
|
|
405
|
-
async scrapeUrl(
|
|
406
|
-
var
|
|
407
|
-
const
|
|
408
|
-
if (!
|
|
409
|
-
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(
|
|
410
659
|
"/app-api/web/scrape-url",
|
|
411
660
|
{
|
|
412
661
|
method: "POST",
|
|
413
662
|
headers: { "Content-Type": "application/json" },
|
|
414
663
|
body: JSON.stringify({
|
|
415
|
-
url:
|
|
416
|
-
maxChars:
|
|
664
|
+
url: t,
|
|
665
|
+
maxChars: e.maxChars
|
|
417
666
|
})
|
|
418
667
|
}
|
|
419
668
|
);
|
|
420
669
|
}
|
|
421
670
|
},
|
|
422
671
|
knowledge: {
|
|
423
|
-
async search(
|
|
424
|
-
var
|
|
425
|
-
const
|
|
426
|
-
if (!
|
|
427
|
-
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(
|
|
428
677
|
"/app-api/knowledge/search",
|
|
429
678
|
{
|
|
430
679
|
method: "POST",
|
|
431
680
|
headers: { "Content-Type": "application/json" },
|
|
432
681
|
body: JSON.stringify({
|
|
433
|
-
workspaceId:
|
|
434
|
-
query:
|
|
435
|
-
maxResults:
|
|
436
|
-
generateSearchQuery:
|
|
437
|
-
sourceId:
|
|
438
|
-
includeSourceUrls:
|
|
439
|
-
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
|
|
440
689
|
})
|
|
441
690
|
}
|
|
442
691
|
);
|
|
443
692
|
}
|
|
444
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
|
+
},
|
|
445
711
|
translatorLiveShare: {
|
|
446
|
-
async create(
|
|
447
|
-
return
|
|
712
|
+
async create(e) {
|
|
713
|
+
return S("/app-api/translator/live-share", {
|
|
448
714
|
method: "POST",
|
|
449
715
|
headers: { "Content-Type": "application/json" },
|
|
450
|
-
body: JSON.stringify({ displayLanguage:
|
|
716
|
+
body: JSON.stringify({ displayLanguage: e })
|
|
451
717
|
});
|
|
452
718
|
},
|
|
453
|
-
async update(
|
|
454
|
-
await
|
|
719
|
+
async update(e, t) {
|
|
720
|
+
await S(`/app-api/translator/live-share/${encodeURIComponent(e)}`, {
|
|
455
721
|
method: "PUT",
|
|
456
722
|
headers: { "Content-Type": "application/json" },
|
|
457
|
-
body: JSON.stringify(
|
|
723
|
+
body: JSON.stringify(t)
|
|
458
724
|
});
|
|
459
725
|
},
|
|
460
|
-
async revoke(
|
|
461
|
-
await
|
|
726
|
+
async revoke(e) {
|
|
727
|
+
await S(`/app-api/translator/live-share/${encodeURIComponent(e)}`, {
|
|
462
728
|
method: "DELETE"
|
|
463
729
|
});
|
|
464
730
|
}
|
|
465
731
|
},
|
|
466
|
-
|
|
467
|
-
|
|
732
|
+
guardrails: {
|
|
733
|
+
async check(e) {
|
|
734
|
+
return S("/app-api/guardrails/check", {
|
|
735
|
+
method: "POST",
|
|
736
|
+
headers: { "Content-Type": "application/json" },
|
|
737
|
+
body: JSON.stringify({ value: e })
|
|
738
|
+
});
|
|
739
|
+
}
|
|
740
|
+
},
|
|
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);
|
|
757
|
+
},
|
|
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})`);
|
|
763
|
+
};
|
|
764
|
+
return {
|
|
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 })}`, {
|
|
769
|
+
method: "POST",
|
|
770
|
+
headers: { "Content-Type": "application/octet-stream" },
|
|
771
|
+
body: r,
|
|
772
|
+
signal: o.signal
|
|
773
|
+
});
|
|
774
|
+
if (!m.ok) throw await n(m);
|
|
775
|
+
return (await m.json()).file;
|
|
776
|
+
},
|
|
777
|
+
async list(r = {}) {
|
|
778
|
+
const o = await s(
|
|
779
|
+
`/app-api/files?${t(r.prefix ? { prefix: r.prefix } : {})}`,
|
|
780
|
+
{ method: "GET" }
|
|
781
|
+
);
|
|
782
|
+
if (!o.ok) throw await n(o);
|
|
783
|
+
return (await o.json()).files;
|
|
784
|
+
},
|
|
785
|
+
async download(r, o = {}) {
|
|
786
|
+
const a = await s(`/app-api/files/${encodeURIComponent(r)}?${t()}`, {
|
|
787
|
+
method: "GET",
|
|
788
|
+
signal: o.signal
|
|
789
|
+
});
|
|
790
|
+
if (!a.ok) throw await n(a);
|
|
791
|
+
return a.blob();
|
|
792
|
+
},
|
|
793
|
+
async remove(r) {
|
|
794
|
+
const o = await s(`/app-api/files/${encodeURIComponent(r)}?${t()}`, {
|
|
795
|
+
method: "DELETE"
|
|
796
|
+
});
|
|
797
|
+
if (!o.ok) throw await n(o);
|
|
798
|
+
}
|
|
799
|
+
};
|
|
468
800
|
}
|
|
469
801
|
};
|
|
470
802
|
}
|
|
471
803
|
export {
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
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
|
|
481
815
|
};
|