@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/dist/index.mjs CHANGED
@@ -1,622 +1,815 @@
1
- import { jsx as I } from "react/jsx-runtime";
2
- import { createContext as G, useState as $, useMemo as x, useCallback as _, useEffect as R, useContext as z } from "react";
3
- const V = "promte-fetch-request", W = "promte-fetch-response", H = /* @__PURE__ */ new Set([101, 103, 204, 205, 304]);
4
- function Q() {
5
- return typeof crypto < "u" && "randomUUID" in crypto ? crypto.randomUUID() : `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
6
- }
7
- function F(i) {
8
- return i.reason ?? new DOMException("The operation was aborted.", "AbortError");
9
- }
10
- function K(i, p) {
11
- if (i == null) return null;
12
- if (typeof i == "string" || i instanceof Blob || i instanceof ArrayBuffer || ArrayBuffer.isView(i))
13
- return i;
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: p,
83
- initTargetOrigin: w,
84
- retryInit: h = { enabled: !0, intervalMs: 500, maxAttempts: 20 }
15
+ expectedParentOrigin: c,
16
+ initTargetOrigin: u,
17
+ retryInit: v = { enabled: !0, intervalMs: 500, maxAttempts: 20 }
85
18
  }) {
86
- const [a, y] = $(null), [l, P] = $(null), [g, v] = $(null), [S, k] = $(null), [t, n] = $(null), [r, e] = $(null), o = x(() => t ? "booting" : a ? !l && !a.fetchProxy ? "waiting_for_token" : "ready" : "waiting_for_settings", [a, l, t]), u = o === "ready", d = x(() => w || p || "*", [w, p]), c = _(() => {
87
- var T;
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 s = { type: "init", fetchProxy: !0 };
90
- (T = window.parent) == null || T.postMessage(s, d);
91
- } catch (s) {
92
- n((s == null ? void 0 : s.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");
93
26
  }
94
- }, [d]);
95
- R(() => {
96
- c();
97
- }, [c]), R(() => {
98
- if (!(h != null && h.enabled) || a) return;
99
- const T = h.intervalMs ?? 500, s = h.maxAttempts ?? 20;
100
- let m = 0;
101
- const E = window.setInterval(() => {
102
- if (a) {
103
- window.clearInterval(E);
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 (m += 1, m > s) {
107
- window.clearInterval(E);
39
+ if (l += 1, l > E) {
40
+ window.clearInterval(y);
108
41
  return;
109
42
  }
110
- c();
111
- }, T);
112
- return () => window.clearInterval(E);
113
- }, [h, a, c]), R(() => {
114
- const T = (s) => {
115
- if (p && s.origin !== p) return;
116
- const m = s.data;
117
- if (!(!m || typeof m != "object")) {
118
- if (m.type === "set-settings") {
119
- const E = m.value;
120
- if (!(E != null && E.backendUrl) || E.parentOrigin && p && E.parentOrigin !== p)
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(E), e(s.source === window.parent ? s.origin : null), E != null && E.user && k(E.user), n(null);
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 (m.type === "set-token" && typeof m.value == "string") {
126
- P(m.value), n(null);
58
+ if (l.type === "set-token" && typeof l.value == "string") {
59
+ x(l.value), P(null);
127
60
  return;
128
61
  }
129
- if (m.type === "set-dark-mode" && typeof m.value == "boolean") {
130
- v(m.value);
62
+ if (l.type === "set-dark-mode" && typeof l.value == "boolean") {
63
+ C(l.value);
131
64
  return;
132
65
  }
133
- if (m.type === "set-user" && typeof m.value == "object") {
134
- k(m.value);
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
- return window.addEventListener("message", T), () => window.removeEventListener("message", T);
140
- }, [p]);
141
- const f = x(() => J(
142
- () => a,
143
- () => l,
144
- () => a != null && a.fetchProxy && r && window.parent !== window ? { target: window.parent, origin: r } : null
145
- ), [a, l, r]), b = x(
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: a,
148
- token: l,
149
- isDarkMode: g,
173
+ settings: s,
174
+ token: g,
175
+ isDarkMode: L,
150
176
  user: S,
151
- ready: u,
152
- state: o,
153
- error: t,
154
- client: f
177
+ ready: h,
178
+ state: a,
179
+ error: R,
180
+ client: b,
181
+ auth: n,
182
+ authRequest: w
155
183
  }),
156
- [a, l, g, S, u, o, t, f]
184
+ [s, g, L, S, h, a, R, b, n, w]
157
185
  );
158
- return /* @__PURE__ */ I(j.Provider, { value: b, children: i });
186
+ return /* @__PURE__ */ oe(Z.Provider, { value: z, children: i });
159
187
  }
160
- function et({
188
+ function ke({
161
189
  children: i,
162
- settings: p,
163
- token: w,
164
- isDarkMode: h,
165
- user: a
190
+ settings: c,
191
+ token: u,
192
+ isDarkMode: v,
193
+ user: s
166
194
  }) {
167
- const y = x(
168
- () => J(() => p, () => w),
169
- [p, w]
170
- ), l = !!w, P = x(
195
+ const k = G(
196
+ () => se(() => c, () => u),
197
+ [c, u]
198
+ ), g = !!u, x = G(
171
199
  () => ({
172
- settings: p,
173
- token: w,
174
- isDarkMode: h,
175
- user: a,
176
- ready: l,
177
- state: l ? "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",
178
206
  error: null,
179
- client: y
207
+ client: k,
208
+ auth: Y,
209
+ authRequest: () => Promise.reject(new Error("not_available"))
180
210
  }),
181
- [y, h, l, p, w, a]
211
+ [k, v, g, c, u, s]
182
212
  );
183
- return /* @__PURE__ */ I(j.Provider, { value: P, children: i });
213
+ return /* @__PURE__ */ oe(Z.Provider, { value: x, children: i });
184
214
  }
185
- function C() {
186
- const i = z(j);
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 rt() {
194
- return C().settings;
223
+ function Se() {
224
+ return J().settings;
195
225
  }
196
- function nt() {
197
- return C().token;
226
+ function Pe() {
227
+ return J().token;
198
228
  }
199
- function ot() {
200
- return C().isDarkMode;
229
+ function $e() {
230
+ return J().isDarkMode;
201
231
  }
202
- function st() {
203
- return C().user;
232
+ function Re() {
233
+ return J().user;
204
234
  }
205
- function Y() {
206
- return C().client;
235
+ function de() {
236
+ return J().client;
207
237
  }
208
- function at(i = {}) {
209
- const { ready: p } = C(), w = Y(), [h, a] = $([]), [y, l] = $(!1), [P, g] = $(null), v = x(() => (Array.isArray(i.type) ? i.type : i.type ? [i.type] : []).filter(Boolean).map((r) => String(r)).join(","), [i.type]), S = i.configuredOnly === !0, k = i.auto !== !1, t = _(async () => {
210
- if (!p) return [];
211
- l(!0), g(null);
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 n = v ? v.split(",").filter(Boolean) : void 0, r = await w.models({ type: n, configuredOnly: S });
214
- return a(r), r;
215
- } catch (n) {
216
- const r = n instanceof Error ? n.message : String(n);
217
- throw g(r), n;
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
- l(!1);
266
+ g(!1);
220
267
  }
221
- }, [w, S, p, v]);
222
- return R(() => {
223
- !k || !p || t().catch(() => {
268
+ }, [u, S, c, C]);
269
+ return K(() => {
270
+ !$ || !c || R().catch(() => {
224
271
  });
225
- }, [k, p, t]), { models: h, loading: y, error: P, reload: t };
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 J(i, p, w = () => null) {
228
- const h = (t) => typeof t == "string" && (t.startsWith("gpt-5") || t.startsWith("gpt-6"));
229
- async function a(t, n) {
230
- const r = i(), e = p();
231
- if (!r) throw new Error("Promte settings not received yet");
232
- const o = r.backendUrl.replace(/\/+$/, ""), u = String(t || "").replace(/^\/+/, ""), d = `${o}/${u}`, c = w();
233
- if (!c && !e) throw new Error("Promte token not received yet");
234
- const f = c ? await X(c, u, n) : await fetch(d, {
235
- ...n,
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
- ...n.headers || {},
238
- Authorization: `Bearer ${e}`
368
+ ...t.headers || {},
369
+ Authorization: `Bearer ${r}`
239
370
  }
240
371
  });
241
- return f.headers.get("X-Promte-Governance-Warning") && (typeof window < "u" && window.dispatchEvent(new CustomEvent("promte:governance-warning", { detail: { endpoint: t } })), console.warn("Promte governance: this request triggered a warning policy.")), 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
- async function y(t, n) {
244
- const r = await a(`/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}`, {
245
398
  method: "POST",
246
399
  headers: { "Content-Type": "application/json" },
247
- body: JSON.stringify(n)
248
- }), e = await r.json().catch(() => ({}));
249
- if (!r.ok)
400
+ body: JSON.stringify(t)
401
+ }), r = await n.json().catch(() => ({}));
402
+ if (!n.ok)
250
403
  throw new Error(
251
- (e == null ? void 0 : e.error) || `Request failed (${r.status})`
404
+ (r == null ? void 0 : r.error) || `Request failed (${n.status})`
252
405
  );
253
- return e == null ? void 0 : e.value;
406
+ return r == null ? void 0 : r.value;
254
407
  }
255
- async function l(t) {
256
- const n = new URLSearchParams();
257
- t.scope && n.set("scope", t.scope), t.path && n.set("path", t.path);
258
- const r = await a(`/app-api/data?${n.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()}`, {
259
412
  method: "GET"
260
- }), e = await r.json().catch(() => ({}));
261
- if (!r.ok)
262
- throw new Error((e == null ? void 0 : e.error) || `Request failed (${r.status})`);
263
- return e == null ? void 0 : e.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;
264
417
  }
265
- async function P(t) {
266
- const n = new URLSearchParams(), r = t == null ? void 0 : t.type, e = Array.isArray(r) ? r : r ? [r] : [];
267
- e.length > 0 && n.set("type", e.join(",")), t != null && t.configuredOnly && n.set("configuredOnly", "true");
268
- const o = await a(
269
- `/app-api/models${n.toString() ? `?${n.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()}` : ""}`,
270
423
  { method: "GET" }
271
- ), u = await o.json().catch(() => ({}));
424
+ ), a = await o.json().catch(() => ({}));
272
425
  if (!o.ok)
273
- throw new Error((u == null ? void 0 : u.error) || `Request failed (${o.status})`);
274
- return (Array.isArray(u == null ? void 0 : u.models) ? u.models : []).map((c) => {
275
- if (!c || typeof c != "object") return null;
276
- const f = typeof c.id == "string" ? c.id.trim() : "", b = typeof c.label == "string" ? c.label.trim() : f, T = c.type, s = c.configured === !0, m = typeof c.source == "string" && c.source.trim() ? c.source.trim() : void 0;
277
- return !f || T !== "llm" && T !== "embedding" && T !== "image" && T !== "stt" && T !== "tts" ? null : {
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: T,
281
- configured: s,
282
- source: m
433
+ type: A,
434
+ configured: w,
435
+ source: z
283
436
  };
284
437
  }).filter(
285
- (c) => !!c
438
+ (m) => !!m
286
439
  );
287
440
  }
288
- async function g(t, n) {
289
- const r = await a(t, n), o = (r.headers.get("content-type") || "").includes("application/json") ? await r.json().catch(() => ({})) : await r.text();
290
- if (!r.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)
291
444
  throw new Error(
292
- typeof o == "string" ? o || `Request failed (${r.status})` : (o == null ? void 0 : o.error) || (o == null ? void 0 : o.message) || `Request failed (${r.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})`
293
446
  );
294
447
  return o;
295
448
  }
296
- const v = (t) => t ? t.split("/").map((n) => n.trim()).filter(Boolean).join("/") : "", S = (t, n) => {
297
- const r = v(t), e = v(n);
298
- return r ? e ? `${r}/${e}` : r : e;
299
- }, k = (t, n) => {
300
- const r = { 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 } : {} };
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 e = v(n);
304
- return l({ ...r, path: e || void 0 });
462
+ const o = $(t);
463
+ return L({ ...r, path: o || void 0 });
305
464
  },
306
- async set(e) {
307
- const o = v(n);
308
- return y("set", {
465
+ async set(o) {
466
+ const a = $(t);
467
+ return x("set", {
309
468
  ...r,
310
- path: o || void 0,
311
- value: e
469
+ path: a || void 0,
470
+ value: o
312
471
  });
313
472
  },
314
- async update(e) {
315
- if (!e || typeof e != "object")
473
+ async update(o) {
474
+ if (!o || typeof o != "object")
316
475
  throw new Error("update requires an object");
317
- const o = {};
318
- for (const [u, d] of Object.entries(e)) {
319
- const c = S(n, u);
320
- if (!c)
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
- o[c] = d;
481
+ a[f] = m;
323
482
  }
324
- return y("update", { ...r, updates: o });
483
+ return x("update", { ...r, updates: a });
325
484
  },
326
485
  async remove() {
327
- const e = v(n);
328
- return y("remove", { ...r, path: e || void 0 });
486
+ const o = $(t);
487
+ return x("remove", { ...r, path: o || void 0 });
329
488
  },
330
- async push(e) {
331
- const o = v(n);
332
- if (!o) throw new Error("push requires a path");
333
- return y("array-push", { ...r, path: o, value: e });
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(e) {
336
- const o = S(n, e);
337
- if (!o) throw new Error("ref requires a path");
338
- return k(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);
339
498
  }
340
499
  };
341
500
  };
342
501
  return {
343
502
  functions: {
344
- async invoke(t, n) {
345
- if (!/^[a-z][a-z0-9-]{0,63}$/.test(t)) throw new Error("Choose a valid function name or configured binding alias.");
346
- const r = await a("/app-api/functions/invoke", {
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: t, input: n })
350
- }), e = await r.json().catch(() => ({}));
351
- if (!r.ok) throw new Error((e == null ? void 0 : e.error) || `Function call failed (${r.status})`);
352
- return e.output;
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() && (!!p() || !!w());
515
+ return !!i() && (!!c() || !!u());
357
516
  },
358
517
  getBackendUrl() {
359
- var t;
360
- return ((t = i()) == null ? void 0 : t.backendUrl) ?? null;
518
+ var e;
519
+ return ((e = i()) == null ? void 0 : e.backendUrl) ?? null;
361
520
  },
362
- async models(t) {
363
- return P(t);
521
+ async models(e) {
522
+ return C(e);
364
523
  },
365
- async chatCompletions(t) {
524
+ async chatCompletions(e) {
366
525
  var b;
367
526
  const {
368
- reasoningEffort: n,
369
- reasoning_effort: r,
370
- ...e
371
- } = t, o = n ?? r, u = {
372
- ...e,
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 && h(t.model) && (u.reasoning_effort = o);
376
- const d = await a("/openai/chat/completions", {
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(u)
380
- }), f = (d.headers.get("content-type") || "").includes("application/json") ? await d.json() : await d.text();
381
- if (!d.ok)
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 (${d.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})`
384
543
  );
385
544
  return f;
386
545
  },
387
- async chatText(t) {
388
- var r, e, o;
389
- const n = await this.chatCompletions(t);
390
- return ((o = (e = (r = n == null ? void 0 : n.choices) == null ? void 0 : r[0]) == null ? void 0 : e.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) ?? "";
391
550
  },
392
551
  embeddings: {
393
- async create(t) {
552
+ async create(e) {
394
553
  var o;
395
- const n = (o = t == null ? void 0 : t.model) == null ? void 0 : o.trim();
396
- if (!n) throw new Error("embeddings.create requires a model");
397
- const r = t == null ? void 0 : t.input;
398
- if (!(typeof r == "string" ? r.length > 0 : Array.isArray(r) && r.length > 0 && r.every((u) => typeof u == "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")))
399
558
  throw new Error(
400
559
  "embeddings.create requires input as a string or string[]"
401
560
  );
402
- return g("/openai/embeddings", {
561
+ return S("/openai/embeddings", {
403
562
  method: "POST",
404
563
  headers: { "Content-Type": "application/json" },
405
564
  body: JSON.stringify({
406
- ...t,
407
- model: n,
408
- input: r
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 t = await a("/app-api/audio/speech-token", { method: "POST" });
416
- if (!t.ok) throw new Error("Live talegenkendelse er ikke tilgængelig. Kontakt administratoren.");
417
- 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();
418
577
  },
419
578
  async voiceLiveSession() {
420
- const t = await a("/app-api/audio/voice-live-session", {
579
+ const e = await s("/app-api/audio/voice-live-session", {
421
580
  method: "POST"
422
581
  });
423
- if (!t.ok) {
424
- const n = await t.text();
425
- throw new Error(n || "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.");
426
585
  }
427
- return t.json();
586
+ return e.json();
428
587
  },
429
- async tts(t) {
588
+ async tts(e) {
430
589
  var o;
431
- const n = (o = t == null ? void 0 : t.text) == null ? void 0 : o.trim();
432
- if (!n) throw new Error("audio.tts requires non-empty text");
433
- const r = await a("/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", {
434
593
  method: "POST",
435
594
  headers: { "Content-Type": "application/json" },
436
595
  body: JSON.stringify({
437
- text: n,
438
- voice: t.voice,
439
- lang: t.lang
596
+ text: t,
597
+ voice: e.voice,
598
+ lang: e.lang
440
599
  })
441
600
  });
442
- if (!r.ok) {
443
- const u = await r.text();
444
- throw new Error(u || `Request failed (${r.status})`);
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 r.arrayBuffer(),
448
- contentType: r.headers.get("content-type")
606
+ audio: await n.arrayBuffer(),
607
+ contentType: n.headers.get("content-type")
449
608
  };
450
609
  },
451
- async stt(t) {
452
- var U, O, L, A;
453
- if (!(t != null && t.file)) throw new Error("audio.stt requires a file");
454
- const n = (U = t.language) == null ? void 0 : U.trim(), r = (M) => {
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 N = M.trim();
457
- if (!N) return;
458
- const B = N.toLowerCase(), D = B.split("-")[0];
459
- return D.length === 2 ? D : B;
460
- }, e = typeof File < "u" && t.file instanceof File, o = e && t.file.name.split(".").pop() || "webm", u = t.ext || o, d = new FormData();
461
- e ? d.set("file", t.file) : d.set("file", t.file, `audio.${u}`);
462
- const c = r(n);
463
- c && d.set("language", c), t.prompt && d.set("prompt", t.prompt), t.responseFormat && d.set("response_format", t.responseFormat);
464
- const f = new URLSearchParams({ ext: u });
465
- n && f.set("locale", n);
466
- const b = await a(
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: d
629
+ body: h
471
630
  }
472
- ), s = (b.headers.get("content-type") || "").includes("application/json") ? await b.json() : await b.text();
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 s == "string" ? s : (typeof (s == null ? void 0 : s.error) == "string" ? s.error : (O = s == null ? void 0 : s.error) == null ? void 0 : O.message) || `Request failed (${b.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})`
476
635
  );
477
- const m = typeof s == "string" ? s : (s == null ? void 0 : s.text) || (s == null ? void 0 : s.original) || ((A = (L = s == null ? void 0 : s.results) == null ? void 0 : L[0]) == null ? void 0 : A.text) || "", E = typeof s == "object" && typeof (s == null ? void 0 : s.language) == "string" ? s.language : void 0;
478
- return { text: m, language: E, 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 };
479
638
  },
480
- async voices(t) {
481
- const n = new URLSearchParams();
482
- t != null && t.locale && n.set("locale", t.locale);
483
- const r = await a(
484
- `/app-api/audio/tts/voices${n.toString() ? `?${n}` : ""}`,
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
- ), e = await r.json().catch(() => []);
487
- if (!r.ok)
645
+ ), r = await n.json().catch(() => []);
646
+ if (!n.ok)
488
647
  throw new Error(
489
- (e == null ? void 0 : e.error) || `Request failed (${r.status})`
648
+ (r == null ? void 0 : r.error) || `Request failed (${n.status})`
490
649
  );
491
- return Array.isArray(e) ? e : (e == null ? void 0 : e.voices) || [];
650
+ return Array.isArray(r) ? r : (r == null ? void 0 : r.voices) || [];
492
651
  }
493
652
  },
494
653
  web: {
495
- async scrapeUrl(t) {
496
- var r;
497
- const n = (r = t == null ? void 0 : t.url) == null ? void 0 : r.trim();
498
- if (!n) throw new Error("web.scrapeUrl requires a url");
499
- return g(
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: n,
506
- maxChars: t.maxChars
664
+ url: t,
665
+ maxChars: e.maxChars
507
666
  })
508
667
  }
509
668
  );
510
669
  }
511
670
  },
512
671
  knowledge: {
513
- async search(t) {
514
- var r;
515
- const n = (r = t == null ? void 0 : t.query) == null ? void 0 : r.trim();
516
- if (!n) throw new Error("knowledge.search requires a query");
517
- return g(
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: t.workspaceId,
524
- query: n,
525
- maxResults: t.maxResults,
526
- generateSearchQuery: t.generateSearchQuery,
527
- sourceId: t.sourceId,
528
- includeSourceUrls: t.includeSourceUrls,
529
- 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
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(t) {
537
- return g("/app-api/translator/live-share", {
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: t })
716
+ body: JSON.stringify({ displayLanguage: e })
541
717
  });
542
718
  },
543
- async update(t, n) {
544
- await g(`/app-api/translator/live-share/${encodeURIComponent(t)}`, {
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(n)
723
+ body: JSON.stringify(t)
548
724
  });
549
725
  },
550
- async revoke(t) {
551
- await g(`/app-api/translator/live-share/${encodeURIComponent(t)}`, {
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(t) {
558
- return g("/app-api/guardrails/check", {
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: t })
737
+ body: JSON.stringify({ value: e })
562
738
  });
563
739
  }
564
740
  },
565
- data(t = "private") {
566
- return k(t, "");
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
- files(t = "private") {
569
- const n = (e = {}) => new URLSearchParams({ scope: t, ...e }).toString(), r = async (e) => {
570
- const o = await e.json().catch(() => ({}));
571
- return new Error((o == null ? void 0 : o.error) || `Request failed (${e.status})`);
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(e, o = {}) {
575
- const u = o.name || e.name;
576
- if (!u) throw new Error("A file name is required.");
577
- const d = o.contentType || e.type || "application/octet-stream", c = await a(`/app-api/files?${n({ name: u, contentType: d })}`, {
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: e,
771
+ body: r,
581
772
  signal: o.signal
582
773
  });
583
- if (!c.ok) throw await r(c);
584
- return (await c.json()).file;
774
+ if (!m.ok) throw await n(m);
775
+ return (await m.json()).file;
585
776
  },
586
- async list(e = {}) {
587
- const o = await a(
588
- `/app-api/files?${n(e.prefix ? { prefix: e.prefix } : {})}`,
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 r(o);
782
+ if (!o.ok) throw await n(o);
592
783
  return (await o.json()).files;
593
784
  },
594
- async download(e, o = {}) {
595
- const u = await a(`/app-api/files/${encodeURIComponent(e)}?${n()}`, {
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 (!u.ok) throw await r(u);
600
- return u.blob();
790
+ if (!a.ok) throw await n(a);
791
+ return a.blob();
601
792
  },
602
- async remove(e) {
603
- const o = await a(`/app-api/files/${encodeURIComponent(e)}?${n()}`, {
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 r(o);
797
+ if (!o.ok) throw await n(o);
607
798
  }
608
799
  };
609
800
  }
610
801
  };
611
802
  }
612
803
  export {
613
- tt as PromteAppProvider,
614
- et as PromteNativeProvider,
615
- C as usePromte,
616
- Y as usePromteClient,
617
- ot as usePromteDarkMode,
618
- at as usePromteModels,
619
- rt as usePromteSettings,
620
- nt as usePromteToken,
621
- st 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
622
815
  };