@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/dist/index.mjs CHANGED
@@ -1,481 +1,815 @@
1
- import { jsx as B } from "react/jsx-runtime";
2
- import { createContext as J, useState as T, useMemo as P, useCallback as _, useEffect as $, useContext as D } from "react";
3
- const x = J(null);
4
- function W({
5
- children: f,
6
- expectedParentOrigin: l,
7
- initTargetOrigin: g,
8
- retryInit: c = { enabled: !0, intervalMs: 500, maxAttempts: 20 }
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 [p, k] = T(null), [y, v] = T(null), [b, E] = T(null), [S, t] = T(null), [r, e] = T(null), n = P(() => r ? "booting" : p ? y ? "ready" : "waiting_for_token" : "waiting_for_settings", [p, y, r]), o = n === "ready", a = P(() => g || l || "*", [g, l]), u = _(() => {
11
- var d;
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 h = { type: "init" };
14
- (d = window.parent) == null || d.postMessage(h, a);
15
- } catch (h) {
16
- e((h == null ? void 0 : h.message) || "Failed to post init");
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
- }, [a]);
19
- $(() => {
20
- u();
21
- }, [u]), $(() => {
22
- if (!(c != null && c.enabled) || p) return;
23
- const d = c.intervalMs ?? 500, h = c.maxAttempts ?? 20;
24
- let s = 0;
25
- const m = window.setInterval(() => {
26
- if (p) {
27
- window.clearInterval(m);
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 (s += 1, s > h) {
31
- window.clearInterval(m);
39
+ if (l += 1, l > E) {
40
+ window.clearInterval(y);
32
41
  return;
33
42
  }
34
- u();
35
- }, d);
36
- return () => window.clearInterval(m);
37
- }, [c, p, u]), $(() => {
38
- const d = (h) => {
39
- if (l && h.origin !== l) return;
40
- const s = h.data;
41
- if (!(!s || typeof s != "object")) {
42
- if (s.type === "set-settings") {
43
- const m = s.value;
44
- if (!(m != null && m.backendUrl) || m.parentOrigin && l && m.parentOrigin !== l)
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(m), m != null && m.user && t(m.user), e(null);
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 (s.type === "set-token" && typeof s.value == "string") {
50
- v(s.value), e(null);
58
+ if (l.type === "set-token" && typeof l.value == "string") {
59
+ x(l.value), P(null);
51
60
  return;
52
61
  }
53
- if (s.type === "set-dark-mode" && typeof s.value == "boolean") {
54
- E(s.value);
62
+ if (l.type === "set-dark-mode" && typeof l.value == "boolean") {
63
+ C(l.value);
55
64
  return;
56
65
  }
57
- if (s.type === "set-user" && typeof s.value == "object") {
58
- t(s.value);
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
- return window.addEventListener("message", d), () => window.removeEventListener("message", d);
64
- }, [l]);
65
- const i = P(() => F(
66
- () => p,
67
- () => y
68
- ), [p, y]), w = P(
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: p,
71
- token: y,
72
- isDarkMode: b,
173
+ settings: s,
174
+ token: g,
175
+ isDarkMode: L,
73
176
  user: S,
74
- ready: o,
75
- state: n,
76
- error: r,
77
- client: i
177
+ ready: h,
178
+ state: a,
179
+ error: R,
180
+ client: b,
181
+ auth: n,
182
+ authRequest: w
78
183
  }),
79
- [p, y, b, S, o, n, r, i]
184
+ [s, g, L, S, h, a, R, b, n, w]
80
185
  );
81
- return /* @__PURE__ */ B(x.Provider, { value: w, children: f });
186
+ return /* @__PURE__ */ oe(Z.Provider, { value: z, children: i });
82
187
  }
83
- function K({
84
- children: f,
85
- settings: l,
86
- token: g,
87
- isDarkMode: c,
88
- user: p
188
+ function ke({
189
+ children: i,
190
+ settings: c,
191
+ token: u,
192
+ isDarkMode: v,
193
+ user: s
89
194
  }) {
90
- const k = P(
91
- () => F(() => l, () => g),
92
- [l, g]
93
- ), y = !!g, v = P(
195
+ const k = G(
196
+ () => se(() => c, () => u),
197
+ [c, u]
198
+ ), g = !!u, x = G(
94
199
  () => ({
95
- settings: l,
96
- token: g,
97
- isDarkMode: c,
98
- user: p,
99
- ready: y,
100
- state: y ? "ready" : "waiting_for_token",
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, c, y, l, g, p]
211
+ [k, v, g, c, u, s]
105
212
  );
106
- return /* @__PURE__ */ B(x.Provider, { value: v, children: f });
213
+ return /* @__PURE__ */ oe(Z.Provider, { value: x, children: i });
107
214
  }
108
- function j() {
109
- const f = D(x);
110
- if (!f)
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 f;
221
+ return i;
222
+ }
223
+ function Se() {
224
+ return J().settings;
115
225
  }
116
- function Q() {
117
- return j().settings;
226
+ function Pe() {
227
+ return J().token;
118
228
  }
119
- function H() {
120
- return j().token;
229
+ function $e() {
230
+ return J().isDarkMode;
121
231
  }
122
- function X() {
123
- return j().isDarkMode;
232
+ function Re() {
233
+ return J().user;
124
234
  }
125
- function Y() {
126
- return j().user;
235
+ function de() {
236
+ return J().client;
127
237
  }
128
- function G() {
129
- return j().client;
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 Z(f = {}) {
132
- const { ready: l } = j(), g = G(), [c, p] = T([]), [k, y] = T(!1), [v, b] = T(null), E = P(() => (Array.isArray(f.type) ? f.type : f.type ? [f.type] : []).filter(Boolean).map((n) => String(n)).join(","), [f.type]), S = f.configuredOnly === !0, t = f.auto !== !1, r = _(async () => {
133
- if (!l) return [];
134
- y(!0), b(null);
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 e = E ? E.split(",").filter(Boolean) : void 0, n = await g.models({ type: e, configuredOnly: S });
137
- return p(n), n;
138
- } catch (e) {
139
- const n = e instanceof Error ? e.message : String(e);
140
- throw b(n), e;
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
- y(!1);
266
+ g(!1);
143
267
  }
144
- }, [g, S, l, E]);
145
- return $(() => {
146
- !t || !l || r().catch(() => {
268
+ }, [u, S, c, C]);
269
+ return K(() => {
270
+ !$ || !c || R().catch(() => {
147
271
  });
148
- }, [t, l, r]), { models: c, loading: k, error: v, reload: r };
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 F(f, l) {
151
- const g = (t) => typeof t == "string" && (t.startsWith("gpt-5") || t.startsWith("gpt-6"));
152
- async function c(t, r) {
153
- const e = f(), n = l();
154
- if (!e) throw new Error("Promte settings not received yet");
155
- if (!n) throw new Error("Promte token not received yet");
156
- const o = e.backendUrl.replace(/\/+$/, ""), a = String(t || "").replace(/^\/+/, ""), u = `${o}/${a}`;
157
- return await fetch(u, {
158
- ...r,
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
- ...r.headers || {},
161
- Authorization: `Bearer ${n}`
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
- async function p(t, r) {
166
- const e = await c(`/app-api/data/${t}`, {
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(r)
170
- }), n = await e.json().catch(() => ({}));
171
- if (!e.ok)
400
+ body: JSON.stringify(t)
401
+ }), r = await n.json().catch(() => ({}));
402
+ if (!n.ok)
172
403
  throw new Error(
173
- (n == null ? void 0 : n.error) || `Request failed (${e.status})`
404
+ (r == null ? void 0 : r.error) || `Request failed (${n.status})`
174
405
  );
175
- return n == null ? void 0 : n.value;
406
+ return r == null ? void 0 : r.value;
176
407
  }
177
- async function k(t) {
178
- const r = new URLSearchParams();
179
- t.scope && r.set("scope", t.scope), t.path && r.set("path", t.path);
180
- const e = await c(`/app-api/data?${r.toString()}`, {
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
- }), n = await e.json().catch(() => ({}));
183
- if (!e.ok)
184
- throw new Error((n == null ? void 0 : n.error) || `Request failed (${e.status})`);
185
- return n == null ? void 0 : n.value;
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 y(t) {
188
- const r = new URLSearchParams(), e = t == null ? void 0 : t.type, n = Array.isArray(e) ? e : e ? [e] : [];
189
- n.length > 0 && r.set("type", n.join(",")), t != null && t.configuredOnly && r.set("configuredOnly", "true");
190
- const o = await c(
191
- `/app-api/models${r.toString() ? `?${r.toString()}` : ""}`,
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((i) => {
197
- if (!i || typeof i != "object") return null;
198
- const w = typeof i.id == "string" ? i.id.trim() : "", d = typeof i.label == "string" ? i.label.trim() : w, h = i.type, s = i.configured === !0, m = typeof i.source == "string" && i.source.trim() ? i.source.trim() : void 0;
199
- return !w || h !== "llm" && h !== "embedding" && h !== "image" && h !== "stt" && h !== "tts" ? null : {
200
- id: w,
201
- label: d || w,
202
- type: h,
203
- configured: s,
204
- source: m
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
- (i) => !!i
438
+ (m) => !!m
208
439
  );
209
440
  }
210
- async function v(t, r) {
211
- const e = await c(t, r), o = (e.headers.get("content-type") || "").includes("application/json") ? await e.json().catch(() => ({})) : await e.text();
212
- if (!e.ok)
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 (${e.status})` : (o == null ? void 0 : o.error) || (o == null ? void 0 : o.message) || `Request failed (${e.status})`
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 b = (t) => t ? t.split("/").map((r) => r.trim()).filter(Boolean).join("/") : "", E = (t, r) => {
219
- const e = b(t), n = b(r);
220
- return e ? n ? `${e}/${n}` : e : n;
221
- }, S = (t, r) => {
222
- const e = { scope: t };
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 n = b(r);
226
- return k({ ...e, path: n || void 0 });
462
+ const o = $(t);
463
+ return L({ ...r, path: o || void 0 });
227
464
  },
228
- async set(n) {
229
- const o = b(r);
230
- return p("set", {
231
- ...e,
232
- path: o || void 0,
233
- value: n
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(n) {
237
- if (!n || typeof n != "object")
473
+ async update(o) {
474
+ if (!o || typeof o != "object")
238
475
  throw new Error("update requires an object");
239
- const o = {};
240
- for (const [a, u] of Object.entries(n)) {
241
- const i = E(r, a);
242
- if (!i)
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
- o[i] = u;
481
+ a[f] = m;
245
482
  }
246
- return p("update", { ...e, updates: o });
483
+ return x("update", { ...r, updates: a });
247
484
  },
248
485
  async remove() {
249
- const n = b(r);
250
- return p("remove", { ...e, path: n || void 0 });
486
+ const o = $(t);
487
+ return x("remove", { ...r, path: o || void 0 });
251
488
  },
252
- async push(n) {
253
- const o = b(r);
254
- if (!o) throw new Error("push requires a path");
255
- return p("array-push", { ...e, path: o, value: n });
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(n) {
258
- const o = E(r, n);
259
- if (!o) throw new Error("ref requires a path");
260
- return S(t, o);
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 !!f() && !!l();
515
+ return !!i() && (!!c() || !!u());
267
516
  },
268
517
  getBackendUrl() {
269
- var t;
270
- return ((t = f()) == null ? void 0 : t.backendUrl) ?? null;
518
+ var e;
519
+ return ((e = i()) == null ? void 0 : e.backendUrl) ?? null;
271
520
  },
272
- async models(t) {
273
- return y(t);
521
+ async models(e) {
522
+ return C(e);
274
523
  },
275
- async chatCompletions(t) {
276
- var d;
524
+ async chatCompletions(e) {
525
+ var b;
277
526
  const {
278
- reasoningEffort: r,
279
- reasoning_effort: e,
280
- ...n
281
- } = t, o = r ?? e, a = {
282
- ...n,
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 && g(t.model) && (a.reasoning_effort = o);
286
- const u = await c("/openai/chat/completions", {
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
- }), w = (u.headers.get("content-type") || "").includes("application/json") ? await u.json() : await u.text();
291
- if (!u.ok)
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 w == "string" ? w : ((d = w == null ? void 0 : w.error) == null ? void 0 : d.message) || `Request failed (${u.status})`
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 w;
544
+ return f;
296
545
  },
297
- async chatText(t) {
298
- var e, n, o;
299
- const r = await this.chatCompletions(t);
300
- return ((o = (n = (e = r == null ? void 0 : r.choices) == null ? void 0 : e[0]) == null ? void 0 : n.message) == null ? void 0 : o.content) ?? "";
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(t) {
552
+ async create(e) {
304
553
  var o;
305
- const r = (o = t == null ? void 0 : t.model) == null ? void 0 : o.trim();
306
- if (!r) throw new Error("embeddings.create requires a model");
307
- const e = t == null ? void 0 : t.input;
308
- if (!(typeof e == "string" ? e.length > 0 : Array.isArray(e) && e.length > 0 && e.every((a) => typeof a == "string")))
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 v("/openai/embeddings", {
561
+ return S("/openai/embeddings", {
313
562
  method: "POST",
314
563
  headers: { "Content-Type": "application/json" },
315
564
  body: JSON.stringify({
316
- ...t,
317
- model: r,
318
- input: e
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 t = await c("/app-api/audio/speech-token", { method: "POST" });
326
- if (!t.ok) throw new Error("Live talegenkendelse er ikke tilgængelig. Kontakt administratoren.");
327
- return t.json();
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 t = await c("/app-api/audio/voice-live-session", {
579
+ const e = await s("/app-api/audio/voice-live-session", {
331
580
  method: "POST"
332
581
  });
333
- if (!t.ok) {
334
- const r = await t.text();
335
- throw new Error(r || "Voice Live er ikke tilgængelig.");
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 t.json();
586
+ return e.json();
338
587
  },
339
- async tts(t) {
588
+ async tts(e) {
340
589
  var o;
341
- const r = (o = t == null ? void 0 : t.text) == null ? void 0 : o.trim();
342
- if (!r) throw new Error("audio.tts requires non-empty text");
343
- const e = await c("/app-api/audio/tts", {
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: r,
348
- voice: t.voice,
349
- lang: t.lang
596
+ text: t,
597
+ voice: e.voice,
598
+ lang: e.lang
350
599
  })
351
600
  });
352
- if (!e.ok) {
353
- const a = await e.text();
354
- throw new Error(a || `Request failed (${e.status})`);
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 e.arrayBuffer(),
358
- contentType: e.headers.get("content-type")
606
+ audio: await n.arrayBuffer(),
607
+ contentType: n.headers.get("content-type")
359
608
  };
360
609
  },
361
- async stt(t) {
362
- var R, C, U, O;
363
- if (!(t != null && t.file)) throw new Error("audio.stt requires a file");
364
- const r = (R = t.language) == null ? void 0 : R.trim(), e = (A) => {
365
- if (!A) return;
366
- const L = A.trim();
367
- if (!L) return;
368
- const M = L.toLowerCase(), N = M.split("-")[0];
369
- return N.length === 2 ? N : M;
370
- }, n = typeof File < "u" && t.file instanceof File, o = n && t.file.name.split(".").pop() || "webm", a = t.ext || o, u = new FormData();
371
- n ? u.set("file", t.file) : u.set("file", t.file, `audio.${a}`);
372
- const i = e(r);
373
- i && u.set("language", i), t.prompt && u.set("prompt", t.prompt), t.responseFormat && u.set("response_format", t.responseFormat);
374
- const w = new URLSearchParams({ ext: a });
375
- r && w.set("locale", r);
376
- const d = await c(
377
- `/app-api/audio/stt?${w.toString()}`,
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: u
629
+ body: h
381
630
  }
382
- ), s = (d.headers.get("content-type") || "").includes("application/json") ? await d.json() : await d.text();
383
- if (!d.ok)
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 s == "string" ? s : ((C = s == null ? void 0 : s.error) == null ? void 0 : C.message) || `Request failed (${d.status})`
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 m = typeof s == "string" ? s : (s == null ? void 0 : s.text) || (s == null ? void 0 : s.original) || ((O = (U = s == null ? void 0 : s.results) == null ? void 0 : U[0]) == null ? void 0 : O.text) || "", I = typeof s == "object" && typeof (s == null ? void 0 : s.language) == "string" ? s.language : void 0;
388
- return { text: m, language: I, raw: s };
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(t) {
391
- const r = new URLSearchParams();
392
- t != null && t.locale && r.set("locale", t.locale);
393
- const e = await c(
394
- `/app-api/audio/tts/voices${r.toString() ? `?${r}` : ""}`,
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
- ), n = await e.json().catch(() => []);
397
- if (!e.ok)
645
+ ), r = await n.json().catch(() => []);
646
+ if (!n.ok)
398
647
  throw new Error(
399
- (n == null ? void 0 : n.error) || `Request failed (${e.status})`
648
+ (r == null ? void 0 : r.error) || `Request failed (${n.status})`
400
649
  );
401
- return Array.isArray(n) ? n : (n == null ? void 0 : n.voices) || [];
650
+ return Array.isArray(r) ? r : (r == null ? void 0 : r.voices) || [];
402
651
  }
403
652
  },
404
653
  web: {
405
- async scrapeUrl(t) {
406
- var e;
407
- const r = (e = t == null ? void 0 : t.url) == null ? void 0 : e.trim();
408
- if (!r) throw new Error("web.scrapeUrl requires a url");
409
- return v(
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: r,
416
- maxChars: t.maxChars
664
+ url: t,
665
+ maxChars: e.maxChars
417
666
  })
418
667
  }
419
668
  );
420
669
  }
421
670
  },
422
671
  knowledge: {
423
- async search(t) {
424
- var e;
425
- const r = (e = t == null ? void 0 : t.query) == null ? void 0 : e.trim();
426
- if (!r) throw new Error("knowledge.search requires a query");
427
- return v(
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: t.workspaceId,
434
- query: r,
435
- maxResults: t.maxResults,
436
- generateSearchQuery: t.generateSearchQuery,
437
- sourceId: t.sourceId,
438
- includeSourceUrls: t.includeSourceUrls,
439
- queries: t.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(t) {
447
- return v("/app-api/translator/live-share", {
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: t })
716
+ body: JSON.stringify({ displayLanguage: e })
451
717
  });
452
718
  },
453
- async update(t, r) {
454
- await v(`/app-api/translator/live-share/${encodeURIComponent(t)}`, {
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(r)
723
+ body: JSON.stringify(t)
458
724
  });
459
725
  },
460
- async revoke(t) {
461
- await v(`/app-api/translator/live-share/${encodeURIComponent(t)}`, {
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
- data(t = "private") {
467
- return S(t, "");
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
- W as PromteAppProvider,
473
- K as PromteNativeProvider,
474
- j as usePromte,
475
- G as usePromteClient,
476
- X as usePromteDarkMode,
477
- Z as usePromteModels,
478
- Q as usePromteSettings,
479
- H as usePromteToken,
480
- Y as usePromteUser
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
  };