@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 +17 -0
- package/dist/index.d.ts +122 -1
- package/dist/index.mjs +459 -251
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
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
|
|
2
|
-
import { createContext as
|
|
3
|
-
const
|
|
4
|
-
function
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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 [
|
|
11
|
-
var
|
|
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
|
|
14
|
-
(
|
|
15
|
-
} catch (
|
|
16
|
-
|
|
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
|
-
}, [
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}, [
|
|
22
|
-
if (!(
|
|
23
|
-
const
|
|
24
|
-
let
|
|
25
|
-
const
|
|
26
|
-
if (
|
|
27
|
-
window.clearInterval(
|
|
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 (
|
|
31
|
-
window.clearInterval(
|
|
106
|
+
if (m += 1, m > s) {
|
|
107
|
+
window.clearInterval(E);
|
|
32
108
|
return;
|
|
33
109
|
}
|
|
34
|
-
|
|
35
|
-
},
|
|
36
|
-
return () => window.clearInterval(
|
|
37
|
-
}, [
|
|
38
|
-
const
|
|
39
|
-
if (
|
|
40
|
-
const
|
|
41
|
-
if (!(!
|
|
42
|
-
if (
|
|
43
|
-
const
|
|
44
|
-
if (!(
|
|
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
|
-
|
|
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 (
|
|
50
|
-
|
|
125
|
+
if (m.type === "set-token" && typeof m.value == "string") {
|
|
126
|
+
P(m.value), n(null);
|
|
51
127
|
return;
|
|
52
128
|
}
|
|
53
|
-
if (
|
|
54
|
-
|
|
129
|
+
if (m.type === "set-dark-mode" && typeof m.value == "boolean") {
|
|
130
|
+
v(m.value);
|
|
55
131
|
return;
|
|
56
132
|
}
|
|
57
|
-
if (
|
|
58
|
-
|
|
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",
|
|
64
|
-
}, [
|
|
65
|
-
const
|
|
66
|
-
() =>
|
|
67
|
-
() =>
|
|
68
|
-
|
|
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:
|
|
71
|
-
token:
|
|
72
|
-
isDarkMode:
|
|
73
|
-
user:
|
|
74
|
-
ready:
|
|
75
|
-
state:
|
|
76
|
-
error:
|
|
77
|
-
client:
|
|
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
|
-
[
|
|
156
|
+
[a, l, g, S, u, o, t, f]
|
|
80
157
|
);
|
|
81
|
-
return /* @__PURE__ */
|
|
158
|
+
return /* @__PURE__ */ I(j.Provider, { value: b, children: i });
|
|
82
159
|
}
|
|
83
|
-
function
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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
|
|
90
|
-
|
|
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
|
|
93
|
-
return
|
|
193
|
+
function rt() {
|
|
194
|
+
return C().settings;
|
|
94
195
|
}
|
|
95
|
-
function
|
|
96
|
-
return
|
|
196
|
+
function nt() {
|
|
197
|
+
return C().token;
|
|
97
198
|
}
|
|
98
|
-
function
|
|
99
|
-
return
|
|
199
|
+
function ot() {
|
|
200
|
+
return C().isDarkMode;
|
|
201
|
+
}
|
|
202
|
+
function st() {
|
|
203
|
+
return C().user;
|
|
100
204
|
}
|
|
101
|
-
function
|
|
102
|
-
return
|
|
205
|
+
function Y() {
|
|
206
|
+
return C().client;
|
|
103
207
|
}
|
|
104
|
-
function
|
|
105
|
-
const { ready:
|
|
106
|
-
if (!
|
|
107
|
-
|
|
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
|
|
110
|
-
return
|
|
111
|
-
} catch (
|
|
112
|
-
const
|
|
113
|
-
throw
|
|
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
|
-
|
|
219
|
+
l(!1);
|
|
116
220
|
}
|
|
117
|
-
}, [
|
|
118
|
-
return
|
|
119
|
-
!
|
|
221
|
+
}, [w, S, p, v]);
|
|
222
|
+
return R(() => {
|
|
223
|
+
!k || !p || t().catch(() => {
|
|
120
224
|
});
|
|
121
|
-
}, [
|
|
225
|
+
}, [k, p, t]), { models: h, loading: y, error: P, reload: t };
|
|
122
226
|
}
|
|
123
|
-
function
|
|
124
|
-
const
|
|
125
|
-
async function
|
|
126
|
-
const
|
|
127
|
-
if (!
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
...
|
|
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
|
-
...
|
|
134
|
-
Authorization: `Bearer ${
|
|
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
|
|
139
|
-
const
|
|
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(
|
|
143
|
-
}),
|
|
144
|
-
if (!
|
|
247
|
+
body: JSON.stringify(n)
|
|
248
|
+
}), e = await r.json().catch(() => ({}));
|
|
249
|
+
if (!r.ok)
|
|
145
250
|
throw new Error(
|
|
146
|
-
(
|
|
251
|
+
(e == null ? void 0 : e.error) || `Request failed (${r.status})`
|
|
147
252
|
);
|
|
148
|
-
return
|
|
253
|
+
return e == null ? void 0 : e.value;
|
|
149
254
|
}
|
|
150
|
-
async function
|
|
151
|
-
const
|
|
152
|
-
t.scope &&
|
|
153
|
-
const
|
|
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
|
-
}),
|
|
156
|
-
if (!
|
|
157
|
-
throw new Error((
|
|
158
|
-
return
|
|
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
|
|
161
|
-
const
|
|
162
|
-
e.length > 0 &&
|
|
163
|
-
const
|
|
164
|
-
`/app-api/models${
|
|
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
|
-
),
|
|
167
|
-
if (!
|
|
168
|
-
throw new Error((
|
|
169
|
-
return (Array.isArray(
|
|
170
|
-
if (!
|
|
171
|
-
const
|
|
172
|
-
return !
|
|
173
|
-
id:
|
|
174
|
-
label:
|
|
175
|
-
type:
|
|
176
|
-
configured:
|
|
177
|
-
source:
|
|
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
|
-
(
|
|
285
|
+
(c) => !!c
|
|
181
286
|
);
|
|
182
287
|
}
|
|
183
|
-
async function
|
|
184
|
-
const
|
|
185
|
-
if (!
|
|
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
|
|
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
|
|
294
|
+
return o;
|
|
190
295
|
}
|
|
191
|
-
const
|
|
192
|
-
const
|
|
193
|
-
return
|
|
194
|
-
},
|
|
195
|
-
const
|
|
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
|
|
199
|
-
return
|
|
303
|
+
const e = v(n);
|
|
304
|
+
return l({ ...r, path: e || void 0 });
|
|
200
305
|
},
|
|
201
|
-
async set(
|
|
202
|
-
const
|
|
203
|
-
return
|
|
204
|
-
...
|
|
205
|
-
path:
|
|
206
|
-
value:
|
|
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(
|
|
210
|
-
if (!
|
|
314
|
+
async update(e) {
|
|
315
|
+
if (!e || typeof e != "object")
|
|
211
316
|
throw new Error("update requires an object");
|
|
212
|
-
const
|
|
213
|
-
for (const [
|
|
214
|
-
const
|
|
215
|
-
if (!
|
|
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
|
-
|
|
322
|
+
o[c] = d;
|
|
218
323
|
}
|
|
219
|
-
return
|
|
324
|
+
return y("update", { ...r, updates: o });
|
|
220
325
|
},
|
|
221
326
|
async remove() {
|
|
222
|
-
const
|
|
223
|
-
return
|
|
327
|
+
const e = v(n);
|
|
328
|
+
return y("remove", { ...r, path: e || void 0 });
|
|
224
329
|
},
|
|
225
|
-
async push(
|
|
226
|
-
const
|
|
227
|
-
if (!
|
|
228
|
-
return
|
|
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(
|
|
231
|
-
const
|
|
232
|
-
if (!
|
|
233
|
-
return
|
|
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 !!
|
|
356
|
+
return !!i() && (!!p() || !!w());
|
|
240
357
|
},
|
|
241
358
|
getBackendUrl() {
|
|
242
359
|
var t;
|
|
243
|
-
return ((t =
|
|
360
|
+
return ((t = i()) == null ? void 0 : t.backendUrl) ?? null;
|
|
244
361
|
},
|
|
245
362
|
async models(t) {
|
|
246
|
-
return
|
|
363
|
+
return P(t);
|
|
247
364
|
},
|
|
248
365
|
async chatCompletions(t) {
|
|
249
|
-
var
|
|
366
|
+
var b;
|
|
250
367
|
const {
|
|
251
|
-
reasoningEffort:
|
|
252
|
-
reasoning_effort:
|
|
253
|
-
...
|
|
254
|
-
} = t,
|
|
255
|
-
...
|
|
368
|
+
reasoningEffort: n,
|
|
369
|
+
reasoning_effort: r,
|
|
370
|
+
...e
|
|
371
|
+
} = t, o = n ?? r, u = {
|
|
372
|
+
...e,
|
|
256
373
|
stream: !1
|
|
257
374
|
};
|
|
258
|
-
|
|
259
|
-
const
|
|
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(
|
|
263
|
-
}),
|
|
264
|
-
if (!
|
|
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
|
|
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
|
|
385
|
+
return f;
|
|
269
386
|
},
|
|
270
387
|
async chatText(t) {
|
|
271
|
-
var
|
|
272
|
-
const
|
|
273
|
-
return ((
|
|
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
|
|
278
|
-
const
|
|
279
|
-
if (!
|
|
280
|
-
const
|
|
281
|
-
if (!(typeof
|
|
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
|
|
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:
|
|
291
|
-
input:
|
|
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
|
|
299
|
-
const
|
|
300
|
-
if (!
|
|
301
|
-
const
|
|
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:
|
|
437
|
+
text: n,
|
|
306
438
|
voice: t.voice,
|
|
307
439
|
lang: t.lang
|
|
308
440
|
})
|
|
309
441
|
});
|
|
310
|
-
if (!
|
|
311
|
-
const
|
|
312
|
-
throw new Error(
|
|
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
|
|
316
|
-
contentType:
|
|
447
|
+
audio: await r.arrayBuffer(),
|
|
448
|
+
contentType: r.headers.get("content-type")
|
|
317
449
|
};
|
|
318
450
|
},
|
|
319
451
|
async stt(t) {
|
|
320
|
-
var
|
|
452
|
+
var U, O, L, A;
|
|
321
453
|
if (!(t != null && t.file)) throw new Error("audio.stt requires a file");
|
|
322
|
-
const r = (
|
|
323
|
-
if (!
|
|
324
|
-
const
|
|
325
|
-
if (!
|
|
326
|
-
const
|
|
327
|
-
return
|
|
328
|
-
}, e = typeof File < "u" && t.file instanceof File,
|
|
329
|
-
e ?
|
|
330
|
-
const
|
|
331
|
-
|
|
332
|
-
const
|
|
333
|
-
|
|
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:
|
|
470
|
+
body: d
|
|
337
471
|
}
|
|
338
|
-
),
|
|
339
|
-
if (!
|
|
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
|
|
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
|
-
|
|
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
|
|
347
|
-
t != null && t.locale &&
|
|
348
|
-
const
|
|
349
|
-
`/app-api/audio/tts/voices${
|
|
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
|
-
),
|
|
352
|
-
if (!
|
|
486
|
+
), e = await r.json().catch(() => []);
|
|
487
|
+
if (!r.ok)
|
|
353
488
|
throw new Error(
|
|
354
|
-
(
|
|
489
|
+
(e == null ? void 0 : e.error) || `Request failed (${r.status})`
|
|
355
490
|
);
|
|
356
|
-
return Array.isArray(
|
|
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
|
|
362
|
-
const
|
|
363
|
-
if (!
|
|
364
|
-
return
|
|
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:
|
|
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
|
|
380
|
-
const
|
|
381
|
-
if (!
|
|
382
|
-
return
|
|
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:
|
|
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
|
|
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
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
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
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -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"})});
|