@promte/app-library 0.1.6 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -60,6 +60,23 @@ await client.data().ref("sessions/session-1/events").push({
60
60
  });
61
61
  ```
62
62
 
63
+ ## Backend functions
64
+
65
+ Call an approved app function or a configured shared-function alias after the provider is ready:
66
+
67
+ ```ts
68
+ const { ready } = usePromte();
69
+ const client = usePromteClient();
70
+ if (ready) {
71
+ const output = await client.functions.invoke("hello", { name: "Ada" });
72
+ // output is the handler result, not the administration run envelope.
73
+ }
74
+ ```
75
+
76
+ The running app is bound to its authorized release. In coding preview, calls use the saved draft and the test environment, which can contact real test APIs. Personal sign-in, workspace access and current function governance are required. Credentials stay in administrator-managed connections and must never be placed in browser code.
77
+
78
+ See [App backend functions](../docs/app-functions.md) for manifests, handlers, controlled connections, data scopes, testing, releases, sharing and schedules.
79
+
63
80
  ## Models/capabilities
64
81
 
65
82
  You can fetch configured models/capabilities from backend:
package/dist/index.d.ts CHANGED
@@ -14,15 +14,49 @@ export declare type AppDataScope = "private" | "public";
14
14
 
15
15
  export declare type AppDataUpdateMap = Record<string, any>;
16
16
 
17
+ /** A stored file. Names may contain folders, e.g. "corpus/2024/report.pdf". */
18
+ export declare type AppFile = {
19
+ id: string;
20
+ name: string;
21
+ contentType: string;
22
+ size: number;
23
+ sha256: string;
24
+ createdAt: string;
25
+ updatedAt: string;
26
+ };
27
+
28
+ /**
29
+ * File storage for larger or binary content (documents, images, exports).
30
+ * "private" files belong to the signed-in user; "public" files are shared in the
31
+ * app workspace and only workspace administrators can change them.
32
+ * Uploading a file with an existing name replaces it.
33
+ */
34
+ export declare type AppFiles = {
35
+ upload(file: Blob, options?: {
36
+ name?: string;
37
+ contentType?: string;
38
+ signal?: AbortSignal;
39
+ }): Promise<AppFile>;
40
+ list(options?: {
41
+ prefix?: string;
42
+ }): Promise<AppFile[]>;
43
+ download(id: string, options?: {
44
+ signal?: AbortSignal;
45
+ }): Promise<Blob>;
46
+ remove(id: string): Promise<void>;
47
+ };
48
+
17
49
  export declare type AudioSttRequest = {
18
50
  file: File | Blob;
19
51
  language?: string;
20
52
  prompt?: string;
53
+ responseFormat?: "json" | "verbose_json";
21
54
  ext?: string;
22
55
  };
23
56
 
24
57
  export declare type AudioSttResponse = {
25
58
  text: string;
59
+ language?: string;
26
60
  raw: any;
27
61
  };
28
62
 
@@ -68,9 +102,20 @@ export declare type ChatCompletionsRequest = {
68
102
 
69
103
  export declare type ChatCompletionsResponse = any;
70
104
 
105
+ export declare type ChatContentPart = {
106
+ type: "text";
107
+ text: string;
108
+ } | {
109
+ type: "image_url";
110
+ image_url: {
111
+ url: string;
112
+ detail?: "auto" | "low" | "high" | "original";
113
+ };
114
+ };
115
+
71
116
  export declare type ChatMessage = {
72
117
  role: "system" | "user" | "assistant" | "tool";
73
- content: string;
118
+ content: string | ChatContentPart[];
74
119
  };
75
120
 
76
121
  export declare type EmbeddingItem = {
@@ -149,6 +194,9 @@ export declare type PromteAppProviderProps = {
149
194
 
150
195
  export declare type PromteClient = {
151
196
  isReady(): boolean;
197
+ functions: {
198
+ invoke<TInput = unknown, TResult = unknown>(name: string, input: TInput): Promise<TResult>;
199
+ };
152
200
  getBackendUrl(): string | null;
153
201
  models(req?: PromteModelsRequest): Promise<PromteModelInfo[]>;
154
202
  chatCompletions(req: ChatCompletionsRequest): Promise<ChatCompletionsResponse>;
@@ -157,6 +205,16 @@ export declare type PromteClient = {
157
205
  create(req: EmbeddingsRequest): Promise<EmbeddingsResponse>;
158
206
  };
159
207
  audio: {
208
+ speechToken(): Promise<{
209
+ token: string;
210
+ region: string;
211
+ }>;
212
+ voiceLiveSession(): Promise<{
213
+ sessionToken: string;
214
+ websocketUrl: string;
215
+ model: string;
216
+ transcriptionModel: string;
217
+ }>;
160
218
  tts(req: AudioTtsRequest): Promise<AudioTtsResponse>;
161
219
  stt(req: AudioSttRequest): Promise<AudioSttResponse>;
162
220
  voices(req?: AudioVoicesRequest): Promise<AudioVoiceInfo[]>;
@@ -167,7 +225,20 @@ export declare type PromteClient = {
167
225
  knowledge: {
168
226
  search(req: KnowledgeSearchRequest): Promise<KnowledgeSearchResponse>;
169
227
  };
228
+ translatorLiveShare: {
229
+ create(displayLanguage: string): Promise<{
230
+ shareId: string;
231
+ token: string;
232
+ expiresAt: string;
233
+ }>;
234
+ update(shareId: string, snapshot: TranslatorLiveShareSnapshot): Promise<void>;
235
+ revoke(shareId: string): Promise<void>;
236
+ };
237
+ guardrails: {
238
+ check(value: unknown): Promise<PromteGuardrailsResult>;
239
+ };
170
240
  data(scope?: AppDataScope): AppDataRef;
241
+ files(scope?: AppDataScope): AppFiles;
171
242
  };
172
243
 
173
244
  declare type PromteCtxValue = {
@@ -181,6 +252,19 @@ declare type PromteCtxValue = {
181
252
  client: PromteClient;
182
253
  };
183
254
 
255
+ export declare type PromteGuardrailsResult = {
256
+ enabled: boolean;
257
+ allowed: boolean;
258
+ outcome: "allow" | "warn" | "block";
259
+ checks: Array<{
260
+ id: string;
261
+ mode: "warn" | "block";
262
+ result: "violation" | "inconclusive";
263
+ matches?: number;
264
+ }>;
265
+ revision: string;
266
+ };
267
+
184
268
  export declare type PromteHandshakeState = "booting" | "waiting_for_settings" | "waiting_for_token" | "ready";
185
269
 
186
270
  export declare type PromteModelInfo = {
@@ -198,12 +282,28 @@ export declare type PromteModelsRequest = {
198
282
 
199
283
  export declare type PromteModelType = "llm" | "embedding" | "image" | "stt" | "tts";
200
284
 
285
+ /**
286
+ * Provides the same Promte runtime to first-party, in-process features without
287
+ * duplicating the app client or emulating the iframe postMessage handshake.
288
+ */
289
+ export declare function PromteNativeProvider({ children, settings, token, isDarkMode, user, }: PromteNativeProviderProps): JSX_2.Element;
290
+
291
+ export declare type PromteNativeProviderProps = {
292
+ children: default_2.ReactNode;
293
+ settings: PromteSettings;
294
+ token: string | null;
295
+ isDarkMode: boolean;
296
+ user: PromteUser | null;
297
+ };
298
+
201
299
  export declare type PromteSettings = {
202
300
  workspaceId: string;
203
301
  version: number;
204
302
  backendUrl: string;
205
303
  parentOrigin?: string;
206
304
  user?: PromteUser;
305
+ /** Set by Promte pages that can send backend requests for the app. */
306
+ fetchProxy?: boolean;
207
307
  };
208
308
 
209
309
  export declare type PromteUser = {
@@ -238,6 +338,23 @@ export declare type ScrapeUrlResponse = {
238
338
  };
239
339
  };
240
340
 
341
+ export declare type TranslatorLiveShareLine = {
342
+ id: string;
343
+ speaker: string;
344
+ language?: string;
345
+ text: string;
346
+ pending?: boolean;
347
+ edited?: boolean;
348
+ createdAt: string;
349
+ };
350
+
351
+ export declare type TranslatorLiveShareSnapshot = {
352
+ displayLanguage: string;
353
+ status: "active" | "ended";
354
+ lines: TranslatorLiveShareLine[];
355
+ revision: number;
356
+ };
357
+
241
358
  export declare function usePromte(): PromteCtxValue;
242
359
 
243
360
  export declare function usePromteClient(): PromteClient;
@@ -257,6 +374,10 @@ export declare type UsePromteModelsOptions = PromteModelsRequest & {
257
374
 
258
375
  export declare function usePromteSettings(): PromteSettings;
259
376
 
377
+ /**
378
+ * @deprecated Promte sends backend requests for the app and no longer gives
379
+ * the app a token, so this returns null inside current Promte versions.
380
+ */
260
381
  export declare function usePromteToken(): string;
261
382
 
262
383
  export declare function usePromteUser(): PromteUser;
package/dist/index.mjs CHANGED
@@ -1,373 +1,508 @@
1
- import { jsx as B } from "react/jsx-runtime";
2
- import { createContext as L, useState as k, useMemo as T, useCallback as M, useEffect as $, useContext as D } from "react";
3
- const O = L(null);
4
- function _({
5
- children: p,
6
- expectedParentOrigin: d,
7
- initTargetOrigin: v,
8
- retryInit: l = { enabled: !0, intervalMs: 500, maxAttempts: 20 }
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({
81
+ children: i,
82
+ expectedParentOrigin: p,
83
+ initTargetOrigin: w,
84
+ retryInit: h = { enabled: !0, intervalMs: 500, maxAttempts: 20 }
9
85
  }) {
10
- const [m, x] = k(null), [h, S] = k(null), [y, b] = k(null), [E, t] = k(null), [r, e] = k(null), n = T(() => r ? "booting" : m ? h ? "ready" : "waiting_for_token" : "waiting_for_settings", [m, h, r]), s = n === "ready", c = T(() => v || d || "*", [v, d]), a = M(() => {
11
- var o;
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;
12
88
  try {
13
- const w = { type: "init" };
14
- (o = window.parent) == null || o.postMessage(w, c);
15
- } catch (w) {
16
- e((w == null ? void 0 : w.message) || "Failed to post init");
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");
17
93
  }
18
- }, [c]);
19
- $(() => {
20
- a();
21
- }, [a]), $(() => {
22
- if (!(l != null && l.enabled) || m) return;
23
- const o = l.intervalMs ?? 500, w = l.maxAttempts ?? 20;
24
- let i = 0;
25
- const f = window.setInterval(() => {
26
- if (m) {
27
- window.clearInterval(f);
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);
28
104
  return;
29
105
  }
30
- if (i += 1, i > w) {
31
- window.clearInterval(f);
106
+ if (m += 1, m > s) {
107
+ window.clearInterval(E);
32
108
  return;
33
109
  }
34
- a();
35
- }, o);
36
- return () => window.clearInterval(f);
37
- }, [l, m, a]), $(() => {
38
- const o = (w) => {
39
- if (d && w.origin !== d) return;
40
- const i = w.data;
41
- if (!(!i || typeof i != "object")) {
42
- if (i.type === "set-settings") {
43
- const f = i.value;
44
- if (!(f != null && f.backendUrl) || f.parentOrigin && d && f.parentOrigin !== d)
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)
45
121
  return;
46
- x(f), f != null && f.user && t(f.user), e(null);
122
+ y(E), e(s.source === window.parent ? s.origin : null), E != null && E.user && k(E.user), n(null);
47
123
  return;
48
124
  }
49
- if (i.type === "set-token" && typeof i.value == "string") {
50
- S(i.value), e(null);
125
+ if (m.type === "set-token" && typeof m.value == "string") {
126
+ P(m.value), n(null);
51
127
  return;
52
128
  }
53
- if (i.type === "set-dark-mode" && typeof i.value == "boolean") {
54
- b(i.value);
129
+ if (m.type === "set-dark-mode" && typeof m.value == "boolean") {
130
+ v(m.value);
55
131
  return;
56
132
  }
57
- if (i.type === "set-user" && typeof i.value == "object") {
58
- t(i.value);
133
+ if (m.type === "set-user" && typeof m.value == "object") {
134
+ k(m.value);
59
135
  return;
60
136
  }
61
137
  }
62
138
  };
63
- return window.addEventListener("message", o), () => window.removeEventListener("message", o);
64
- }, [d]);
65
- const u = T(() => F(
66
- () => m,
67
- () => h
68
- ), [m, h]), g = T(
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(
69
146
  () => ({
70
- settings: m,
71
- token: h,
72
- isDarkMode: y,
73
- user: E,
74
- ready: s,
75
- state: n,
76
- error: r,
77
- client: u
147
+ settings: a,
148
+ token: l,
149
+ isDarkMode: g,
150
+ user: S,
151
+ ready: u,
152
+ state: o,
153
+ error: t,
154
+ client: f
78
155
  }),
79
- [m, h, y, E, s, n, r, u]
156
+ [a, l, g, S, u, o, t, f]
80
157
  );
81
- return /* @__PURE__ */ B(O.Provider, { value: g, children: p });
158
+ return /* @__PURE__ */ I(j.Provider, { value: b, children: i });
82
159
  }
83
- function j() {
84
- const p = D(O);
85
- if (!p)
86
- throw new Error("usePromte must be used inside <PromteAppProvider>");
87
- return p;
160
+ function et({
161
+ children: i,
162
+ settings: p,
163
+ token: w,
164
+ isDarkMode: h,
165
+ user: a
166
+ }) {
167
+ const y = x(
168
+ () => J(() => p, () => w),
169
+ [p, w]
170
+ ), l = !!w, P = x(
171
+ () => ({
172
+ settings: p,
173
+ token: w,
174
+ isDarkMode: h,
175
+ user: a,
176
+ ready: l,
177
+ state: l ? "ready" : "waiting_for_token",
178
+ error: null,
179
+ client: y
180
+ }),
181
+ [y, h, l, p, w, a]
182
+ );
183
+ return /* @__PURE__ */ I(j.Provider, { value: P, children: i });
88
184
  }
89
- function G() {
90
- return j().settings;
185
+ function C() {
186
+ const i = z(j);
187
+ if (!i)
188
+ throw new Error(
189
+ "usePromte must be used inside <PromteAppProvider> or <PromteNativeProvider>"
190
+ );
191
+ return i;
91
192
  }
92
- function z() {
93
- return j().token;
193
+ function rt() {
194
+ return C().settings;
94
195
  }
95
- function V() {
96
- return j().isDarkMode;
196
+ function nt() {
197
+ return C().token;
97
198
  }
98
- function Q() {
99
- return j().user;
199
+ function ot() {
200
+ return C().isDarkMode;
201
+ }
202
+ function st() {
203
+ return C().user;
100
204
  }
101
- function I() {
102
- return j().client;
205
+ function Y() {
206
+ return C().client;
103
207
  }
104
- function W(p = {}) {
105
- const { ready: d } = j(), v = I(), [l, m] = k([]), [x, h] = k(!1), [S, y] = k(null), b = T(() => (Array.isArray(p.type) ? p.type : p.type ? [p.type] : []).filter(Boolean).map((n) => String(n)).join(","), [p.type]), E = p.configuredOnly === !0, t = p.auto !== !1, r = M(async () => {
106
- if (!d) return [];
107
- h(!0), y(null);
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);
108
212
  try {
109
- const e = b ? b.split(",").filter(Boolean) : void 0, n = await v.models({ type: e, configuredOnly: E });
110
- return m(n), n;
111
- } catch (e) {
112
- const n = e instanceof Error ? e.message : String(e);
113
- throw y(n), e;
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;
114
218
  } finally {
115
- h(!1);
219
+ l(!1);
116
220
  }
117
- }, [v, E, d, b]);
118
- return $(() => {
119
- !t || !d || r().catch(() => {
221
+ }, [w, S, p, v]);
222
+ return R(() => {
223
+ !k || !p || t().catch(() => {
120
224
  });
121
- }, [t, d, r]), { models: l, loading: x, error: S, reload: r };
225
+ }, [k, p, t]), { models: h, loading: y, error: P, reload: t };
122
226
  }
123
- function F(p, d) {
124
- const v = (t) => typeof t == "string" && t.startsWith("gpt-5");
125
- async function l(t, r) {
126
- const e = p(), n = d();
127
- if (!e) throw new Error("Promte settings not received yet");
128
- if (!n) throw new Error("Promte token not received yet");
129
- const s = e.backendUrl.replace(/\/+$/, ""), c = String(t || "").replace(/^\/+/, ""), a = `${s}/${c}`;
130
- return await fetch(a, {
131
- ...r,
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,
132
236
  headers: {
133
- ...r.headers || {},
134
- Authorization: `Bearer ${n}`
237
+ ...n.headers || {},
238
+ Authorization: `Bearer ${e}`
135
239
  }
136
240
  });
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;
137
242
  }
138
- async function m(t, r) {
139
- const e = await l(`/app-api/data/${t}`, {
243
+ async function y(t, n) {
244
+ const r = await a(`/app-api/data/${t}`, {
140
245
  method: "POST",
141
246
  headers: { "Content-Type": "application/json" },
142
- body: JSON.stringify(r)
143
- }), n = await e.json().catch(() => ({}));
144
- if (!e.ok)
247
+ body: JSON.stringify(n)
248
+ }), e = await r.json().catch(() => ({}));
249
+ if (!r.ok)
145
250
  throw new Error(
146
- (n == null ? void 0 : n.error) || `Request failed (${e.status})`
251
+ (e == null ? void 0 : e.error) || `Request failed (${r.status})`
147
252
  );
148
- return n == null ? void 0 : n.value;
253
+ return e == null ? void 0 : e.value;
149
254
  }
150
- async function x(t) {
151
- const r = new URLSearchParams();
152
- t.scope && r.set("scope", t.scope), t.path && r.set("path", t.path);
153
- const e = await l(`/app-api/data?${r.toString()}`, {
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()}`, {
154
259
  method: "GET"
155
- }), n = await e.json().catch(() => ({}));
156
- if (!e.ok)
157
- throw new Error((n == null ? void 0 : n.error) || `Request failed (${e.status})`);
158
- return n == null ? void 0 : n.value;
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;
159
264
  }
160
- async function h(t) {
161
- const r = new URLSearchParams(), e = Array.isArray(t == null ? void 0 : t.type) ? t == null ? void 0 : t.type : t != null && t.type ? [t.type] : [];
162
- e.length > 0 && r.set("type", e.join(",")), t != null && t.configuredOnly && r.set("configuredOnly", "true");
163
- const n = await l(
164
- `/app-api/models${r.toString() ? `?${r.toString()}` : ""}`,
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()}` : ""}`,
165
270
  { method: "GET" }
166
- ), s = await n.json().catch(() => ({}));
167
- if (!n.ok)
168
- throw new Error((s == null ? void 0 : s.error) || `Request failed (${n.status})`);
169
- return (Array.isArray(s == null ? void 0 : s.models) ? s.models : []).map((a) => {
170
- if (!a || typeof a != "object") return null;
171
- const u = typeof a.id == "string" ? a.id.trim() : "", g = typeof a.label == "string" ? a.label.trim() : u, o = a.type, w = a.configured === !0, i = typeof a.source == "string" && a.source.trim() ? a.source.trim() : void 0;
172
- return !u || o !== "llm" && o !== "embedding" && o !== "image" && o !== "stt" && o !== "tts" ? null : {
173
- id: u,
174
- label: g || u,
175
- type: o,
176
- configured: w,
177
- source: i
271
+ ), u = await o.json().catch(() => ({}));
272
+ 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 : {
278
+ id: f,
279
+ label: b || f,
280
+ type: T,
281
+ configured: s,
282
+ source: m
178
283
  };
179
284
  }).filter(
180
- (a) => !!a
285
+ (c) => !!c
181
286
  );
182
287
  }
183
- async function S(t, r) {
184
- const e = await l(t, r), s = (e.headers.get("content-type") || "").includes("application/json") ? await e.json().catch(() => ({})) : await e.text();
185
- if (!e.ok)
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)
186
291
  throw new Error(
187
- typeof s == "string" ? s || `Request failed (${e.status})` : (s == null ? void 0 : s.error) || (s == null ? void 0 : s.message) || `Request failed (${e.status})`
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})`
188
293
  );
189
- return s;
294
+ return o;
190
295
  }
191
- const y = (t) => t ? t.split("/").map((r) => r.trim()).filter(Boolean).join("/") : "", b = (t, r) => {
192
- const e = y(t), n = y(r);
193
- return e ? n ? `${e}/${n}` : e : n;
194
- }, E = (t, r) => {
195
- const e = { scope: t };
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 };
196
301
  return {
197
302
  async get() {
198
- const n = y(r);
199
- return x({ ...e, path: n || void 0 });
303
+ const e = v(n);
304
+ return l({ ...r, path: e || void 0 });
200
305
  },
201
- async set(n) {
202
- const s = y(r);
203
- return m("set", {
204
- ...e,
205
- path: s || void 0,
206
- value: n
306
+ async set(e) {
307
+ const o = v(n);
308
+ return y("set", {
309
+ ...r,
310
+ path: o || void 0,
311
+ value: e
207
312
  });
208
313
  },
209
- async update(n) {
210
- if (!n || typeof n != "object")
314
+ async update(e) {
315
+ if (!e || typeof e != "object")
211
316
  throw new Error("update requires an object");
212
- const s = {};
213
- for (const [c, a] of Object.entries(n)) {
214
- const u = b(r, c);
215
- if (!u)
317
+ const o = {};
318
+ for (const [u, d] of Object.entries(e)) {
319
+ const c = S(n, u);
320
+ if (!c)
216
321
  throw new Error("update paths must be non-empty");
217
- s[u] = a;
322
+ o[c] = d;
218
323
  }
219
- return m("update", { ...e, updates: s });
324
+ return y("update", { ...r, updates: o });
220
325
  },
221
326
  async remove() {
222
- const n = y(r);
223
- return m("remove", { ...e, path: n || void 0 });
327
+ const e = v(n);
328
+ return y("remove", { ...r, path: e || void 0 });
224
329
  },
225
- async push(n) {
226
- const s = y(r);
227
- if (!s) throw new Error("push requires a path");
228
- return m("array-push", { ...e, path: s, value: n });
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 });
229
334
  },
230
- ref(n) {
231
- const s = b(r, n);
232
- if (!s) throw new Error("ref requires a path");
233
- return E(t, s);
335
+ ref(e) {
336
+ const o = S(n, e);
337
+ if (!o) throw new Error("ref requires a path");
338
+ return k(t, o);
234
339
  }
235
340
  };
236
341
  };
237
342
  return {
343
+ 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", {
347
+ method: "POST",
348
+ 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;
353
+ }
354
+ },
238
355
  isReady() {
239
- return !!p() && !!d();
356
+ return !!i() && (!!p() || !!w());
240
357
  },
241
358
  getBackendUrl() {
242
359
  var t;
243
- return ((t = p()) == null ? void 0 : t.backendUrl) ?? null;
360
+ return ((t = i()) == null ? void 0 : t.backendUrl) ?? null;
244
361
  },
245
362
  async models(t) {
246
- return h(t);
363
+ return P(t);
247
364
  },
248
365
  async chatCompletions(t) {
249
- var o;
366
+ var b;
250
367
  const {
251
- reasoningEffort: r,
252
- reasoning_effort: e,
253
- ...n
254
- } = t, s = r ?? e, c = {
255
- ...n,
368
+ reasoningEffort: n,
369
+ reasoning_effort: r,
370
+ ...e
371
+ } = t, o = n ?? r, u = {
372
+ ...e,
256
373
  stream: !1
257
374
  };
258
- s && v(t.model) && (c.reasoning_effort = s);
259
- const a = await l("/openai/chat/completions", {
375
+ o && h(t.model) && (u.reasoning_effort = o);
376
+ const d = await a("/openai/chat/completions", {
260
377
  method: "POST",
261
378
  headers: { "Content-Type": "application/json" },
262
- body: JSON.stringify(c)
263
- }), g = (a.headers.get("content-type") || "").includes("application/json") ? await a.json() : await a.text();
264
- if (!a.ok)
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)
265
382
  throw new Error(
266
- typeof g == "string" ? g : ((o = g == null ? void 0 : g.error) == null ? void 0 : o.message) || `Request failed (${a.status})`
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})`
267
384
  );
268
- return g;
385
+ return f;
269
386
  },
270
387
  async chatText(t) {
271
- var e, n, s;
272
- const r = await this.chatCompletions(t);
273
- return ((s = (n = (e = r == null ? void 0 : r.choices) == null ? void 0 : e[0]) == null ? void 0 : n.message) == null ? void 0 : s.content) ?? "";
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) ?? "";
274
391
  },
275
392
  embeddings: {
276
393
  async create(t) {
277
- var s;
278
- const r = (s = t == null ? void 0 : t.model) == null ? void 0 : s.trim();
279
- if (!r) throw new Error("embeddings.create requires a model");
280
- const e = t == null ? void 0 : t.input;
281
- if (!(typeof e == "string" ? e.length > 0 : Array.isArray(e) && e.length > 0 && e.every((c) => typeof c == "string")))
394
+ 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")))
282
399
  throw new Error(
283
400
  "embeddings.create requires input as a string or string[]"
284
401
  );
285
- return S("/openai/embeddings", {
402
+ return g("/openai/embeddings", {
286
403
  method: "POST",
287
404
  headers: { "Content-Type": "application/json" },
288
405
  body: JSON.stringify({
289
406
  ...t,
290
- model: r,
291
- input: e
407
+ model: n,
408
+ input: r
292
409
  })
293
410
  });
294
411
  }
295
412
  },
296
413
  audio: {
414
+ 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();
418
+ },
419
+ async voiceLiveSession() {
420
+ const t = await a("/app-api/audio/voice-live-session", {
421
+ method: "POST"
422
+ });
423
+ if (!t.ok) {
424
+ const n = await t.text();
425
+ throw new Error(n || "Voice Live er ikke tilgængelig.");
426
+ }
427
+ return t.json();
428
+ },
297
429
  async tts(t) {
298
- var s;
299
- const r = (s = t == null ? void 0 : t.text) == null ? void 0 : s.trim();
300
- if (!r) throw new Error("audio.tts requires non-empty text");
301
- const e = await l("/app-api/audio/tts", {
430
+ 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", {
302
434
  method: "POST",
303
435
  headers: { "Content-Type": "application/json" },
304
436
  body: JSON.stringify({
305
- text: r,
437
+ text: n,
306
438
  voice: t.voice,
307
439
  lang: t.lang
308
440
  })
309
441
  });
310
- if (!e.ok) {
311
- const c = await e.text();
312
- throw new Error(c || `Request failed (${e.status})`);
442
+ if (!r.ok) {
443
+ const u = await r.text();
444
+ throw new Error(u || `Request failed (${r.status})`);
313
445
  }
314
446
  return {
315
- audio: await e.arrayBuffer(),
316
- contentType: e.headers.get("content-type")
447
+ audio: await r.arrayBuffer(),
448
+ contentType: r.headers.get("content-type")
317
449
  };
318
450
  },
319
451
  async stt(t) {
320
- var i, f, P;
452
+ var U, O, L, A;
321
453
  if (!(t != null && t.file)) throw new Error("audio.stt requires a file");
322
- const r = (R) => {
323
- if (!R) return;
324
- const C = R.trim();
325
- if (!C) return;
326
- const A = C.toLowerCase(), U = A.split("-")[0];
327
- return U.length === 2 ? U : A;
328
- }, e = typeof File < "u" && t.file instanceof File, n = e && t.file.name.split(".").pop() || "webm", s = t.ext || n, c = new FormData();
329
- e ? c.set("file", t.file) : c.set("file", t.file, `audio.${s}`);
330
- const a = r(t.language);
331
- a && c.set("language", a), t.prompt && c.set("prompt", t.prompt);
332
- const u = await l(
333
- `/app-api/audio/stt?ext=${encodeURIComponent(s)}`,
454
+ const n = (U = t.language) == null ? void 0 : U.trim(), r = (M) => {
455
+ 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(
467
+ `/app-api/audio/stt?${f.toString()}`,
334
468
  {
335
469
  method: "POST",
336
- body: c
470
+ body: d
337
471
  }
338
- ), o = (u.headers.get("content-type") || "").includes("application/json") ? await u.json() : await u.text();
339
- if (!u.ok)
472
+ ), s = (b.headers.get("content-type") || "").includes("application/json") ? await b.json() : await b.text();
473
+ if (!b.ok)
340
474
  throw new Error(
341
- typeof o == "string" ? o : ((i = o == null ? void 0 : o.error) == null ? void 0 : i.message) || `Request failed (${u.status})`
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})`
342
476
  );
343
- return { text: typeof o == "string" ? o : (o == null ? void 0 : o.text) || (o == null ? void 0 : o.original) || ((P = (f = o == null ? void 0 : o.results) == null ? void 0 : f[0]) == null ? void 0 : P.text) || "", raw: o };
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 };
344
479
  },
345
480
  async voices(t) {
346
- const r = new URLSearchParams();
347
- t != null && t.locale && r.set("locale", t.locale);
348
- const e = await l(
349
- `/app-api/audio/tts/voices${r.toString() ? `?${r}` : ""}`,
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}` : ""}`,
350
485
  { method: "GET" }
351
- ), n = await e.json().catch(() => []);
352
- if (!e.ok)
486
+ ), e = await r.json().catch(() => []);
487
+ if (!r.ok)
353
488
  throw new Error(
354
- (n == null ? void 0 : n.error) || `Request failed (${e.status})`
489
+ (e == null ? void 0 : e.error) || `Request failed (${r.status})`
355
490
  );
356
- return Array.isArray(n) ? n : (n == null ? void 0 : n.voices) || [];
491
+ return Array.isArray(e) ? e : (e == null ? void 0 : e.voices) || [];
357
492
  }
358
493
  },
359
494
  web: {
360
495
  async scrapeUrl(t) {
361
- var e;
362
- const r = (e = t == null ? void 0 : t.url) == null ? void 0 : e.trim();
363
- if (!r) throw new Error("web.scrapeUrl requires a url");
364
- return S(
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(
365
500
  "/app-api/web/scrape-url",
366
501
  {
367
502
  method: "POST",
368
503
  headers: { "Content-Type": "application/json" },
369
504
  body: JSON.stringify({
370
- url: r,
505
+ url: n,
371
506
  maxChars: t.maxChars
372
507
  })
373
508
  }
@@ -376,17 +511,17 @@ function F(p, d) {
376
511
  },
377
512
  knowledge: {
378
513
  async search(t) {
379
- var e;
380
- const r = (e = t == null ? void 0 : t.query) == null ? void 0 : e.trim();
381
- if (!r) throw new Error("knowledge.search requires a query");
382
- return S(
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(
383
518
  "/app-api/knowledge/search",
384
519
  {
385
520
  method: "POST",
386
521
  headers: { "Content-Type": "application/json" },
387
522
  body: JSON.stringify({
388
523
  workspaceId: t.workspaceId,
389
- query: r,
524
+ query: n,
390
525
  maxResults: t.maxResults,
391
526
  generateSearchQuery: t.generateSearchQuery,
392
527
  sourceId: t.sourceId,
@@ -397,18 +532,91 @@ function F(p, d) {
397
532
  );
398
533
  }
399
534
  },
535
+ translatorLiveShare: {
536
+ async create(t) {
537
+ return g("/app-api/translator/live-share", {
538
+ method: "POST",
539
+ headers: { "Content-Type": "application/json" },
540
+ body: JSON.stringify({ displayLanguage: t })
541
+ });
542
+ },
543
+ async update(t, n) {
544
+ await g(`/app-api/translator/live-share/${encodeURIComponent(t)}`, {
545
+ method: "PUT",
546
+ headers: { "Content-Type": "application/json" },
547
+ body: JSON.stringify(n)
548
+ });
549
+ },
550
+ async revoke(t) {
551
+ await g(`/app-api/translator/live-share/${encodeURIComponent(t)}`, {
552
+ method: "DELETE"
553
+ });
554
+ }
555
+ },
556
+ guardrails: {
557
+ async check(t) {
558
+ return g("/app-api/guardrails/check", {
559
+ method: "POST",
560
+ headers: { "Content-Type": "application/json" },
561
+ body: JSON.stringify({ value: t })
562
+ });
563
+ }
564
+ },
400
565
  data(t = "private") {
401
- return E(t, "");
566
+ return k(t, "");
567
+ },
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})`);
572
+ };
573
+ 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 })}`, {
578
+ method: "POST",
579
+ headers: { "Content-Type": "application/octet-stream" },
580
+ body: e,
581
+ signal: o.signal
582
+ });
583
+ if (!c.ok) throw await r(c);
584
+ return (await c.json()).file;
585
+ },
586
+ async list(e = {}) {
587
+ const o = await a(
588
+ `/app-api/files?${n(e.prefix ? { prefix: e.prefix } : {})}`,
589
+ { method: "GET" }
590
+ );
591
+ if (!o.ok) throw await r(o);
592
+ return (await o.json()).files;
593
+ },
594
+ async download(e, o = {}) {
595
+ const u = await a(`/app-api/files/${encodeURIComponent(e)}?${n()}`, {
596
+ method: "GET",
597
+ signal: o.signal
598
+ });
599
+ if (!u.ok) throw await r(u);
600
+ return u.blob();
601
+ },
602
+ async remove(e) {
603
+ const o = await a(`/app-api/files/${encodeURIComponent(e)}?${n()}`, {
604
+ method: "DELETE"
605
+ });
606
+ if (!o.ok) throw await r(o);
607
+ }
608
+ };
402
609
  }
403
610
  };
404
611
  }
405
612
  export {
406
- _ as PromteAppProvider,
407
- j as usePromte,
408
- I as usePromteClient,
409
- V as usePromteDarkMode,
410
- W as usePromteModels,
411
- G as usePromteSettings,
412
- z as usePromteToken,
413
- Q as usePromteUser
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
414
622
  };
@@ -1 +1 @@
1
- (function(h,T){typeof exports=="object"&&typeof module<"u"?T(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],T):(h=typeof globalThis<"u"?globalThis:h||self,T(h.PromteAppLibrary={},h.jsxRuntime,h.react))})(this,function(h,T,i){"use strict";const R=i.createContext(null);function L({children:d,expectedParentOrigin:m,initTargetOrigin:S,retryInit:f={enabled:!0,intervalMs:500,maxAttempts:20}}){const[y,$]=i.useState(null),[v,j]=i.useState(null),[g,E]=i.useState(null),[k,t]=i.useState(null),[s,e]=i.useState(null),n=i.useMemo(()=>s?"booting":y?v?"ready":"waiting_for_token":"waiting_for_settings",[y,v,s]),r=n==="ready",c=i.useMemo(()=>S||m||"*",[S,m]),a=i.useCallback(()=>{var o;try{const w={type:"init"};(o=window.parent)==null||o.postMessage(w,c)}catch(w){e((w==null?void 0:w.message)||"Failed to post init")}},[c]);i.useEffect(()=>{a()},[a]),i.useEffect(()=>{if(!(f!=null&&f.enabled)||y)return;const o=f.intervalMs??500,w=f.maxAttempts??20;let u=0;const p=window.setInterval(()=>{if(y){window.clearInterval(p);return}if(u+=1,u>w){window.clearInterval(p);return}a()},o);return()=>window.clearInterval(p)},[f,y,a]),i.useEffect(()=>{const o=w=>{if(m&&w.origin!==m)return;const u=w.data;if(!(!u||typeof u!="object")){if(u.type==="set-settings"){const p=u.value;if(!(p!=null&&p.backendUrl)||p.parentOrigin&&m&&p.parentOrigin!==m)return;$(p),p!=null&&p.user&&t(p.user),e(null);return}if(u.type==="set-token"&&typeof u.value=="string"){j(u.value),e(null);return}if(u.type==="set-dark-mode"&&typeof u.value=="boolean"){E(u.value);return}if(u.type==="set-user"&&typeof u.value=="object"){t(u.value);return}}};return window.addEventListener("message",o),()=>window.removeEventListener("message",o)},[m]);const l=i.useMemo(()=>N(()=>y,()=>v),[y,v]),b=i.useMemo(()=>({settings:y,token:v,isDarkMode:g,user:k,ready:r,state:n,error:s,client:l}),[y,v,g,k,r,n,s,l]);return T.jsx(R.Provider,{value:b,children:d})}function P(){const d=i.useContext(R);if(!d)throw new Error("usePromte must be used inside <PromteAppProvider>");return d}function B(){return P().settings}function D(){return P().token}function I(){return P().isDarkMode}function F(){return P().user}function x(){return P().client}function J(d={}){const{ready:m}=P(),S=x(),[f,y]=i.useState([]),[$,v]=i.useState(!1),[j,g]=i.useState(null),E=i.useMemo(()=>(Array.isArray(d.type)?d.type:d.type?[d.type]:[]).filter(Boolean).map(n=>String(n)).join(","),[d.type]),k=d.configuredOnly===!0,t=d.auto!==!1,s=i.useCallback(async()=>{if(!m)return[];v(!0),g(null);try{const e=E?E.split(",").filter(Boolean):void 0,n=await S.models({type:e,configuredOnly:k});return y(n),n}catch(e){const n=e instanceof Error?e.message:String(e);throw g(n),e}finally{v(!1)}},[S,k,m,E]);return i.useEffect(()=>{!t||!m||s().catch(()=>{})},[t,m,s]),{models:f,loading:$,error:j,reload:s}}function N(d,m){const S=t=>typeof t=="string"&&t.startsWith("gpt-5");async function f(t,s){const e=d(),n=m();if(!e)throw new Error("Promte settings not received yet");if(!n)throw new Error("Promte token not received yet");const r=e.backendUrl.replace(/\/+$/,""),c=String(t||"").replace(/^\/+/,""),a=`${r}/${c}`;return await fetch(a,{...s,headers:{...s.headers||{},Authorization:`Bearer ${n}`}})}async function y(t,s){const e=await f(`/app-api/data/${t}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)}),n=await e.json().catch(()=>({}));if(!e.ok)throw new Error((n==null?void 0:n.error)||`Request failed (${e.status})`);return n==null?void 0:n.value}async function $(t){const s=new URLSearchParams;t.scope&&s.set("scope",t.scope),t.path&&s.set("path",t.path);const e=await f(`/app-api/data?${s.toString()}`,{method:"GET"}),n=await e.json().catch(()=>({}));if(!e.ok)throw new Error((n==null?void 0:n.error)||`Request failed (${e.status})`);return n==null?void 0:n.value}async function v(t){const s=new URLSearchParams,e=Array.isArray(t==null?void 0:t.type)?t==null?void 0:t.type:t!=null&&t.type?[t.type]:[];e.length>0&&s.set("type",e.join(",")),t!=null&&t.configuredOnly&&s.set("configuredOnly","true");const n=await f(`/app-api/models${s.toString()?`?${s.toString()}`:""}`,{method:"GET"}),r=await n.json().catch(()=>({}));if(!n.ok)throw new Error((r==null?void 0:r.error)||`Request failed (${n.status})`);return(Array.isArray(r==null?void 0:r.models)?r.models:[]).map(a=>{if(!a||typeof a!="object")return null;const l=typeof a.id=="string"?a.id.trim():"",b=typeof a.label=="string"?a.label.trim():l,o=a.type,w=a.configured===!0,u=typeof a.source=="string"&&a.source.trim()?a.source.trim():void 0;return!l||o!=="llm"&&o!=="embedding"&&o!=="image"&&o!=="stt"&&o!=="tts"?null:{id:l,label:b||l,type:o,configured:w,source:u}}).filter(a=>!!a)}async function j(t,s){const e=await f(t,s),r=(e.headers.get("content-type")||"").includes("application/json")?await e.json().catch(()=>({})):await e.text();if(!e.ok)throw new Error(typeof r=="string"?r||`Request failed (${e.status})`:(r==null?void 0:r.error)||(r==null?void 0:r.message)||`Request failed (${e.status})`);return r}const g=t=>t?t.split("/").map(s=>s.trim()).filter(Boolean).join("/"):"",E=(t,s)=>{const e=g(t),n=g(s);return e?n?`${e}/${n}`:e:n},k=(t,s)=>{const e={scope:t};return{async get(){const n=g(s);return $({...e,path:n||void 0})},async set(n){const r=g(s);return y("set",{...e,path:r||void 0,value:n})},async update(n){if(!n||typeof n!="object")throw new Error("update requires an object");const r={};for(const[c,a]of Object.entries(n)){const l=E(s,c);if(!l)throw new Error("update paths must be non-empty");r[l]=a}return y("update",{...e,updates:r})},async remove(){const n=g(s);return y("remove",{...e,path:n||void 0})},async push(n){const r=g(s);if(!r)throw new Error("push requires a path");return y("array-push",{...e,path:r,value:n})},ref(n){const r=E(s,n);if(!r)throw new Error("ref requires a path");return k(t,r)}}};return{isReady(){return!!d()&&!!m()},getBackendUrl(){var t;return((t=d())==null?void 0:t.backendUrl)??null},async models(t){return v(t)},async chatCompletions(t){var o;const{reasoningEffort:s,reasoning_effort:e,...n}=t,r=s??e,c={...n,stream:!1};r&&S(t.model)&&(c.reasoning_effort=r);const a=await f("/openai/chat/completions",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(c)}),b=(a.headers.get("content-type")||"").includes("application/json")?await a.json():await a.text();if(!a.ok)throw new Error(typeof b=="string"?b:((o=b==null?void 0:b.error)==null?void 0:o.message)||`Request failed (${a.status})`);return b},async chatText(t){var e,n,r;const s=await this.chatCompletions(t);return((r=(n=(e=s==null?void 0:s.choices)==null?void 0:e[0])==null?void 0:n.message)==null?void 0:r.content)??""},embeddings:{async create(t){var r;const s=(r=t==null?void 0:t.model)==null?void 0:r.trim();if(!s)throw new Error("embeddings.create requires a model");const e=t==null?void 0:t.input;if(!(typeof e=="string"?e.length>0:Array.isArray(e)&&e.length>0&&e.every(c=>typeof c=="string")))throw new Error("embeddings.create requires input as a string or string[]");return j("/openai/embeddings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...t,model:s,input:e})})}},audio:{async tts(t){var r;const s=(r=t==null?void 0:t.text)==null?void 0:r.trim();if(!s)throw new Error("audio.tts requires non-empty text");const e=await f("/app-api/audio/tts",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:s,voice:t.voice,lang:t.lang})});if(!e.ok){const c=await e.text();throw new Error(c||`Request failed (${e.status})`)}return{audio:await e.arrayBuffer(),contentType:e.headers.get("content-type")}},async stt(t){var u,p,C;if(!(t!=null&&t.file))throw new Error("audio.stt requires a file");const s=M=>{if(!M)return;const A=M.trim();if(!A)return;const U=A.toLowerCase(),O=U.split("-")[0];return O.length===2?O:U},e=typeof File<"u"&&t.file instanceof File,n=e&&t.file.name.split(".").pop()||"webm",r=t.ext||n,c=new FormData;e?c.set("file",t.file):c.set("file",t.file,`audio.${r}`);const a=s(t.language);a&&c.set("language",a),t.prompt&&c.set("prompt",t.prompt);const l=await f(`/app-api/audio/stt?ext=${encodeURIComponent(r)}`,{method:"POST",body:c}),o=(l.headers.get("content-type")||"").includes("application/json")?await l.json():await l.text();if(!l.ok)throw new Error(typeof o=="string"?o:((u=o==null?void 0:o.error)==null?void 0:u.message)||`Request failed (${l.status})`);return{text:typeof o=="string"?o:(o==null?void 0:o.text)||(o==null?void 0:o.original)||((C=(p=o==null?void 0:o.results)==null?void 0:p[0])==null?void 0:C.text)||"",raw:o}},async voices(t){const s=new URLSearchParams;t!=null&&t.locale&&s.set("locale",t.locale);const e=await f(`/app-api/audio/tts/voices${s.toString()?`?${s}`:""}`,{method:"GET"}),n=await e.json().catch(()=>[]);if(!e.ok)throw new Error((n==null?void 0:n.error)||`Request failed (${e.status})`);return Array.isArray(n)?n:(n==null?void 0:n.voices)||[]}},web:{async scrapeUrl(t){var e;const s=(e=t==null?void 0:t.url)==null?void 0:e.trim();if(!s)throw new Error("web.scrapeUrl requires a url");return j("/app-api/web/scrape-url",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:s,maxChars:t.maxChars})})}},knowledge:{async search(t){var e;const s=(e=t==null?void 0:t.query)==null?void 0:e.trim();if(!s)throw new Error("knowledge.search requires a query");return j("/app-api/knowledge/search",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({workspaceId:t.workspaceId,query:s,maxResults:t.maxResults,generateSearchQuery:t.generateSearchQuery,sourceId:t.sourceId,includeSourceUrls:t.includeSourceUrls,queries:t.queries})})}},data(t="private"){return k(t,"")}}}h.PromteAppProvider=L,h.usePromte=P,h.usePromteClient=x,h.usePromteDarkMode=I,h.usePromteModels=J,h.usePromteSettings=B,h.usePromteToken=D,h.usePromteUser=F,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
1
+ (function(E,R){typeof exports=="object"&&typeof module<"u"?R(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],R):(E=typeof globalThis<"u"?globalThis:E||self,R(E.PromteAppLibrary={},E.jsxRuntime,E.react))})(this,function(E,R,l){"use strict";const J="promte-fetch-request",G="promte-fetch-response",z=new Set([101,103,204,205,304]);function V(){return typeof crypto<"u"&&"randomUUID"in crypto?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`}function x(i){return i.reason??new DOMException("The operation was aborted.","AbortError")}function W(i,f){if(i==null)return null;if(typeof i=="string"||i instanceof Blob||i instanceof ArrayBuffer||ArrayBuffer.isView(i))return i;if(i instanceof URLSearchParams)return f.has("content-type")||f.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"),i.toString();if(i instanceof FormData){const w=[];return i.forEach((m,a)=>w.push([a,m])),{form:w}}throw new TypeError("This request body cannot be sent through Promte.")}function H({target:i,origin:f},w,m){return new Promise((a,g)=>{const p=m.signal;if(p!=null&&p.aborted)return g(x(p));const $=V(),v=new Headers(m.headers);v.delete("authorization");let T;try{T=W(m.body,v)}catch(n){return g(n)}const b=()=>{window.removeEventListener("message",e),p==null||p.removeEventListener("abort",j)},j=()=>{b(),g(x(p))},e=n=>{if(n.source!==i||n.origin!==f)return;const t=n.data;if(!t||t.type!==G||t.id!==$)return;if(b(),typeof t.error=="string")return g(new TypeError(t.error));const o=Number(t.status);if(!Number.isInteger(o)||o<200||o>599)return g(new TypeError("Promte returned an invalid response."));try{a(new Response(z.has(o)?null:t.body??null,{status:o,statusText:typeof t.statusText=="string"?t.statusText:"",headers:Array.isArray(t.headers)?t.headers:[]}))}catch{g(new TypeError("Promte returned an invalid response."))}};window.addEventListener("message",e),p==null||p.addEventListener("abort",j,{once:!0});const r=[];v.forEach((n,t)=>r.push([t,n]));try{i.postMessage({type:J,id:$,path:w,method:(m.method||"GET").toUpperCase(),headers:r,body:T},f)}catch(n){b(),g(n)}})}const U=l.createContext(null);function Q({children:i,expectedParentOrigin:f,initTargetOrigin:w,retryInit:m={enabled:!0,intervalMs:500,maxAttempts:20}}){const[a,g]=l.useState(null),[p,$]=l.useState(null),[v,T]=l.useState(null),[b,j]=l.useState(null),[e,r]=l.useState(null),[n,t]=l.useState(null),o=l.useMemo(()=>e?"booting":a?!p&&!a.fetchProxy?"waiting_for_token":"ready":"waiting_for_settings",[a,p,e]),u=o==="ready",h=l.useMemo(()=>w||f||"*",[w,f]),c=l.useCallback(()=>{var P;try{const s={type:"init",fetchProxy:!0};(P=window.parent)==null||P.postMessage(s,h)}catch(s){r((s==null?void 0:s.message)||"Failed to post init")}},[h]);l.useEffect(()=>{c()},[c]),l.useEffect(()=>{if(!(m!=null&&m.enabled)||a)return;const P=m.intervalMs??500,s=m.maxAttempts??20;let y=0;const S=window.setInterval(()=>{if(a){window.clearInterval(S);return}if(y+=1,y>s){window.clearInterval(S);return}c()},P);return()=>window.clearInterval(S)},[m,a,c]),l.useEffect(()=>{const P=s=>{if(f&&s.origin!==f)return;const y=s.data;if(!(!y||typeof y!="object")){if(y.type==="set-settings"){const S=y.value;if(!(S!=null&&S.backendUrl)||S.parentOrigin&&f&&S.parentOrigin!==f)return;g(S),t(s.source===window.parent?s.origin:null),S!=null&&S.user&&j(S.user),r(null);return}if(y.type==="set-token"&&typeof y.value=="string"){$(y.value),r(null);return}if(y.type==="set-dark-mode"&&typeof y.value=="boolean"){T(y.value);return}if(y.type==="set-user"&&typeof y.value=="object"){j(y.value);return}}};return window.addEventListener("message",P),()=>window.removeEventListener("message",P)},[f]);const d=l.useMemo(()=>L(()=>a,()=>p,()=>a!=null&&a.fetchProxy&&n&&window.parent!==window?{target:window.parent,origin:n}:null),[a,p,n]),k=l.useMemo(()=>({settings:a,token:p,isDarkMode:v,user:b,ready:u,state:o,error:e,client:d}),[a,p,v,b,u,o,e,d]);return R.jsx(U.Provider,{value:k,children:i})}function K({children:i,settings:f,token:w,isDarkMode:m,user:a}){const g=l.useMemo(()=>L(()=>f,()=>w),[f,w]),p=!!w,$=l.useMemo(()=>({settings:f,token:w,isDarkMode:m,user:a,ready:p,state:p?"ready":"waiting_for_token",error:null,client:g}),[g,m,p,f,w,a]);return R.jsx(U.Provider,{value:$,children:i})}function C(){const i=l.useContext(U);if(!i)throw new Error("usePromte must be used inside <PromteAppProvider> or <PromteNativeProvider>");return i}function X(){return C().settings}function Y(){return C().token}function Z(){return C().isDarkMode}function q(){return C().user}function O(){return C().client}function ee(i={}){const{ready:f}=C(),w=O(),[m,a]=l.useState([]),[g,p]=l.useState(!1),[$,v]=l.useState(null),T=l.useMemo(()=>(Array.isArray(i.type)?i.type:i.type?[i.type]:[]).filter(Boolean).map(n=>String(n)).join(","),[i.type]),b=i.configuredOnly===!0,j=i.auto!==!1,e=l.useCallback(async()=>{if(!f)return[];p(!0),v(null);try{const r=T?T.split(",").filter(Boolean):void 0,n=await w.models({type:r,configuredOnly:b});return a(n),n}catch(r){const n=r instanceof Error?r.message:String(r);throw v(n),r}finally{p(!1)}},[w,b,f,T]);return l.useEffect(()=>{!j||!f||e().catch(()=>{})},[j,f,e]),{models:m,loading:g,error:$,reload:e}}function L(i,f,w=()=>null){const m=e=>typeof e=="string"&&(e.startsWith("gpt-5")||e.startsWith("gpt-6"));async function a(e,r){const n=i(),t=f();if(!n)throw new Error("Promte settings not received yet");const o=n.backendUrl.replace(/\/+$/,""),u=String(e||"").replace(/^\/+/,""),h=`${o}/${u}`,c=w();if(!c&&!t)throw new Error("Promte token not received yet");const d=c?await H(c,u,r):await fetch(h,{...r,headers:{...r.headers||{},Authorization:`Bearer ${t}`}});return d.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.")),d}async function g(e,r){const n=await a(`/app-api/data/${e}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)}),t=await n.json().catch(()=>({}));if(!n.ok)throw new Error((t==null?void 0:t.error)||`Request failed (${n.status})`);return t==null?void 0:t.value}async function p(e){const r=new URLSearchParams;e.scope&&r.set("scope",e.scope),e.path&&r.set("path",e.path);const n=await a(`/app-api/data?${r.toString()}`,{method:"GET"}),t=await n.json().catch(()=>({}));if(!n.ok)throw new Error((t==null?void 0:t.error)||`Request failed (${n.status})`);return t==null?void 0:t.value}async function $(e){const r=new URLSearchParams,n=e==null?void 0:e.type,t=Array.isArray(n)?n:n?[n]:[];t.length>0&&r.set("type",t.join(",")),e!=null&&e.configuredOnly&&r.set("configuredOnly","true");const o=await a(`/app-api/models${r.toString()?`?${r.toString()}`:""}`,{method:"GET"}),u=await o.json().catch(()=>({}));if(!o.ok)throw new Error((u==null?void 0:u.error)||`Request failed (${o.status})`);return(Array.isArray(u==null?void 0:u.models)?u.models:[]).map(c=>{if(!c||typeof c!="object")return null;const d=typeof c.id=="string"?c.id.trim():"",k=typeof c.label=="string"?c.label.trim():d,P=c.type,s=c.configured===!0,y=typeof c.source=="string"&&c.source.trim()?c.source.trim():void 0;return!d||P!=="llm"&&P!=="embedding"&&P!=="image"&&P!=="stt"&&P!=="tts"?null:{id:d,label:k||d,type:P,configured:s,source:y}}).filter(c=>!!c)}async function v(e,r){const n=await a(e,r),o=(n.headers.get("content-type")||"").includes("application/json")?await n.json().catch(()=>({})):await n.text();if(!n.ok)throw new Error(typeof o=="string"?o||`Request failed (${n.status})`:(o==null?void 0:o.error)||(o==null?void 0:o.message)||`Request failed (${n.status})`);return o}const T=e=>e?e.split("/").map(r=>r.trim()).filter(Boolean).join("/"):"",b=(e,r)=>{const n=T(e),t=T(r);return n?t?`${n}/${t}`:n:t},j=(e,r)=>{const n={scope:e};return{async get(){const t=T(r);return p({...n,path:t||void 0})},async set(t){const o=T(r);return g("set",{...n,path:o||void 0,value:t})},async update(t){if(!t||typeof t!="object")throw new Error("update requires an object");const o={};for(const[u,h]of Object.entries(t)){const c=b(r,u);if(!c)throw new Error("update paths must be non-empty");o[c]=h}return g("update",{...n,updates:o})},async remove(){const t=T(r);return g("remove",{...n,path:t||void 0})},async push(t){const o=T(r);if(!o)throw new Error("push requires a path");return g("array-push",{...n,path:o,value:t})},ref(t){const o=b(r,t);if(!o)throw new Error("ref requires a path");return j(e,o)}}};return{functions:{async invoke(e,r){if(!/^[a-z][a-z0-9-]{0,63}$/.test(e))throw new Error("Choose a valid function name or configured binding alias.");const n=await a("/app-api/functions/invoke",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:e,input:r})}),t=await n.json().catch(()=>({}));if(!n.ok)throw new Error((t==null?void 0:t.error)||`Function call failed (${n.status})`);return t.output}},isReady(){return!!i()&&(!!f()||!!w())},getBackendUrl(){var e;return((e=i())==null?void 0:e.backendUrl)??null},async models(e){return $(e)},async chatCompletions(e){var k;const{reasoningEffort:r,reasoning_effort:n,...t}=e,o=r??n,u={...t,stream:!1};o&&m(e.model)&&(u.reasoning_effort=o);const h=await a("/openai/chat/completions",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(u)}),d=(h.headers.get("content-type")||"").includes("application/json")?await h.json():await h.text();if(!h.ok)throw new Error(typeof d=="string"?d:(typeof(d==null?void 0:d.error)=="string"?d.error:(k=d==null?void 0:d.error)==null?void 0:k.message)||`Request failed (${h.status})`);return d},async chatText(e){var n,t,o;const r=await this.chatCompletions(e);return((o=(t=(n=r==null?void 0:r.choices)==null?void 0:n[0])==null?void 0:t.message)==null?void 0:o.content)??""},embeddings:{async create(e){var o;const r=(o=e==null?void 0:e.model)==null?void 0:o.trim();if(!r)throw new Error("embeddings.create requires a model");const n=e==null?void 0:e.input;if(!(typeof n=="string"?n.length>0:Array.isArray(n)&&n.length>0&&n.every(u=>typeof u=="string")))throw new Error("embeddings.create requires input as a string or string[]");return v("/openai/embeddings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...e,model:r,input:n})})}},audio:{async speechToken(){const e=await a("/app-api/audio/speech-token",{method:"POST"});if(!e.ok)throw new Error("Live talegenkendelse er ikke tilgængelig. Kontakt administratoren.");return e.json()},async voiceLiveSession(){const e=await a("/app-api/audio/voice-live-session",{method:"POST"});if(!e.ok){const r=await e.text();throw new Error(r||"Voice Live er ikke tilgængelig.")}return e.json()},async tts(e){var o;const r=(o=e==null?void 0:e.text)==null?void 0:o.trim();if(!r)throw new Error("audio.tts requires non-empty text");const n=await a("/app-api/audio/tts",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:r,voice:e.voice,lang:e.lang})});if(!n.ok){const u=await n.text();throw new Error(u||`Request failed (${n.status})`)}return{audio:await n.arrayBuffer(),contentType:n.headers.get("content-type")}},async stt(e){var A,M,N,D;if(!(e!=null&&e.file))throw new Error("audio.stt requires a file");const r=(A=e.language)==null?void 0:A.trim(),n=B=>{if(!B)return;const F=B.trim();if(!F)return;const I=F.toLowerCase(),_=I.split("-")[0];return _.length===2?_:I},t=typeof File<"u"&&e.file instanceof File,o=t&&e.file.name.split(".").pop()||"webm",u=e.ext||o,h=new FormData;t?h.set("file",e.file):h.set("file",e.file,`audio.${u}`);const c=n(r);c&&h.set("language",c),e.prompt&&h.set("prompt",e.prompt),e.responseFormat&&h.set("response_format",e.responseFormat);const d=new URLSearchParams({ext:u});r&&d.set("locale",r);const k=await a(`/app-api/audio/stt?${d.toString()}`,{method:"POST",body:h}),s=(k.headers.get("content-type")||"").includes("application/json")?await k.json():await k.text();if(!k.ok)throw new Error(typeof s=="string"?s:(typeof(s==null?void 0:s.error)=="string"?s.error:(M=s==null?void 0:s.error)==null?void 0:M.message)||`Request failed (${k.status})`);const y=typeof s=="string"?s:(s==null?void 0:s.text)||(s==null?void 0:s.original)||((D=(N=s==null?void 0:s.results)==null?void 0:N[0])==null?void 0:D.text)||"",S=typeof s=="object"&&typeof(s==null?void 0:s.language)=="string"?s.language:void 0;return{text:y,language:S,raw:s}},async voices(e){const r=new URLSearchParams;e!=null&&e.locale&&r.set("locale",e.locale);const n=await a(`/app-api/audio/tts/voices${r.toString()?`?${r}`:""}`,{method:"GET"}),t=await n.json().catch(()=>[]);if(!n.ok)throw new Error((t==null?void 0:t.error)||`Request failed (${n.status})`);return Array.isArray(t)?t:(t==null?void 0:t.voices)||[]}},web:{async scrapeUrl(e){var n;const r=(n=e==null?void 0:e.url)==null?void 0:n.trim();if(!r)throw new Error("web.scrapeUrl requires a url");return v("/app-api/web/scrape-url",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:r,maxChars:e.maxChars})})}},knowledge:{async search(e){var n;const r=(n=e==null?void 0:e.query)==null?void 0:n.trim();if(!r)throw new Error("knowledge.search requires a query");return v("/app-api/knowledge/search",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({workspaceId:e.workspaceId,query:r,maxResults:e.maxResults,generateSearchQuery:e.generateSearchQuery,sourceId:e.sourceId,includeSourceUrls:e.includeSourceUrls,queries:e.queries})})}},translatorLiveShare:{async create(e){return v("/app-api/translator/live-share",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({displayLanguage:e})})},async update(e,r){await v(`/app-api/translator/live-share/${encodeURIComponent(e)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)})},async revoke(e){await v(`/app-api/translator/live-share/${encodeURIComponent(e)}`,{method:"DELETE"})}},guardrails:{async check(e){return v("/app-api/guardrails/check",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({value:e})})}},data(e="private"){return j(e,"")},files(e="private"){const r=(t={})=>new URLSearchParams({scope:e,...t}).toString(),n=async t=>{const o=await t.json().catch(()=>({}));return new Error((o==null?void 0:o.error)||`Request failed (${t.status})`)};return{async upload(t,o={}){const u=o.name||t.name;if(!u)throw new Error("A file name is required.");const h=o.contentType||t.type||"application/octet-stream",c=await a(`/app-api/files?${r({name:u,contentType:h})}`,{method:"POST",headers:{"Content-Type":"application/octet-stream"},body:t,signal:o.signal});if(!c.ok)throw await n(c);return(await c.json()).file},async list(t={}){const o=await a(`/app-api/files?${r(t.prefix?{prefix:t.prefix}:{})}`,{method:"GET"});if(!o.ok)throw await n(o);return(await o.json()).files},async download(t,o={}){const u=await a(`/app-api/files/${encodeURIComponent(t)}?${r()}`,{method:"GET",signal:o.signal});if(!u.ok)throw await n(u);return u.blob()},async remove(t){const o=await a(`/app-api/files/${encodeURIComponent(t)}?${r()}`,{method:"DELETE"});if(!o.ok)throw await n(o)}}}}}E.PromteAppProvider=Q,E.PromteNativeProvider=K,E.usePromte=C,E.usePromteClient=O,E.usePromteDarkMode=Z,E.usePromteModels=ee,E.usePromteSettings=X,E.usePromteToken=Y,E.usePromteUser=q,Object.defineProperty(E,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promte/app-library",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "files": [