@promte/app-library 0.1.4 → 0.1.6

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
@@ -68,6 +68,10 @@ You can fetch configured models/capabilities from backend:
68
68
  const client = usePromteClient();
69
69
  const allModels = await client.models();
70
70
  const llmsOnly = await client.models({ type: "llm", configuredOnly: true });
71
+ const embeddingsOnly = await client.models({
72
+ type: "embedding",
73
+ configuredOnly: true,
74
+ });
71
75
  ```
72
76
 
73
77
  Or use the built-in hook:
@@ -81,6 +85,49 @@ const { models, loading, error, reload } = usePromteModels({
81
85
 
82
86
  Each model includes `id`, `label`, `type` (`llm` | `embedding` | `image` | `stt` | `tts`) and `configured`.
83
87
 
88
+ ## Embeddings
89
+
90
+ Embeddings use the same app token/auth flow as LLM requests. Fetch an available
91
+ embedding model, then create embeddings:
92
+
93
+ ```ts
94
+ const client = usePromteClient();
95
+ const [model] = await client.models({
96
+ type: "embedding",
97
+ configuredOnly: true,
98
+ });
99
+
100
+ const response = await client.embeddings.create({
101
+ model: model.id,
102
+ input: ["First text", "Second text"],
103
+ });
104
+
105
+ const vectors = response.data.map((item) => item.embedding);
106
+ ```
107
+
108
+ ## Knowledge search
109
+
110
+ Apps can search an assistant/workspace knowledge base directly:
111
+
112
+ ```ts
113
+ const client = usePromteClient();
114
+
115
+ const response = await client.knowledge.search({
116
+ workspaceId: "assistant-workspace-id",
117
+ query: "Hvad gælder for carporte i BR18?",
118
+ maxResults: 8,
119
+ generateSearchQuery: true,
120
+ });
121
+
122
+ for (const result of response.results) {
123
+ console.log(result.title, result.text, result.sourceUrl);
124
+ }
125
+ ```
126
+
127
+ If `workspaceId` is omitted, the search uses the current app workspace. Searching
128
+ another workspace requires that the current user has access to that workspace.
129
+ Public app tokens can only search their own workspace.
130
+
84
131
  ## Return behavior
85
132
 
86
133
  - `get()` returns the value at the current path, or `null` if missing.
package/dist/index.d.ts CHANGED
@@ -73,6 +73,67 @@ export declare type ChatMessage = {
73
73
  content: string;
74
74
  };
75
75
 
76
+ export declare type EmbeddingItem = {
77
+ object?: string;
78
+ embedding: number[] | string;
79
+ index: number;
80
+ };
81
+
82
+ export declare type EmbeddingsRequest = {
83
+ model: string;
84
+ input: string | string[];
85
+ encoding_format?: "float" | "base64";
86
+ dimensions?: number;
87
+ user?: string;
88
+ };
89
+
90
+ export declare type EmbeddingsResponse = {
91
+ object?: string;
92
+ data: EmbeddingItem[];
93
+ model?: string;
94
+ usage?: {
95
+ prompt_tokens?: number;
96
+ total_tokens?: number;
97
+ [key: string]: any;
98
+ };
99
+ [key: string]: any;
100
+ };
101
+
102
+ export declare type KnowledgeSearchRequest = {
103
+ workspaceId?: string;
104
+ query: string;
105
+ maxResults?: number;
106
+ generateSearchQuery?: boolean;
107
+ sourceId?: string;
108
+ includeSourceUrls?: boolean;
109
+ queries?: string[];
110
+ };
111
+
112
+ export declare type KnowledgeSearchResponse = {
113
+ workspaceId: string;
114
+ workspaceName?: string;
115
+ query: string;
116
+ searchQueries: string[];
117
+ maxResults: number;
118
+ results: KnowledgeSearchResult[];
119
+ sourceIds: string[];
120
+ chunkIds: string[];
121
+ };
122
+
123
+ export declare type KnowledgeSearchResult = {
124
+ index: number;
125
+ id: string;
126
+ chunkId: string;
127
+ sourceWorkspaceId: string;
128
+ sourceId: string;
129
+ sourceName?: string;
130
+ title: string;
131
+ text: string;
132
+ relevance?: number;
133
+ link?: string;
134
+ sourceUrl?: string;
135
+ };
136
+
76
137
  export declare function PromteAppProvider({ children, expectedParentOrigin, initTargetOrigin, retryInit, }: PromteAppProviderProps): JSX_2.Element;
77
138
 
78
139
  export declare type PromteAppProviderProps = {
@@ -92,6 +153,9 @@ export declare type PromteClient = {
92
153
  models(req?: PromteModelsRequest): Promise<PromteModelInfo[]>;
93
154
  chatCompletions(req: ChatCompletionsRequest): Promise<ChatCompletionsResponse>;
94
155
  chatText(req: ChatCompletionsRequest): Promise<string>;
156
+ embeddings: {
157
+ create(req: EmbeddingsRequest): Promise<EmbeddingsResponse>;
158
+ };
95
159
  audio: {
96
160
  tts(req: AudioTtsRequest): Promise<AudioTtsResponse>;
97
161
  stt(req: AudioSttRequest): Promise<AudioSttResponse>;
@@ -100,6 +164,9 @@ export declare type PromteClient = {
100
164
  web: {
101
165
  scrapeUrl(req: ScrapeUrlRequest): Promise<ScrapeUrlResponse>;
102
166
  };
167
+ knowledge: {
168
+ search(req: KnowledgeSearchRequest): Promise<KnowledgeSearchResponse>;
169
+ };
103
170
  data(scope?: AppDataScope): AppDataRef;
104
171
  };
105
172
 
package/dist/index.mjs CHANGED
@@ -1,24 +1,24 @@
1
- import { jsx as L } from "react/jsx-runtime";
2
- import { createContext as O, useState as k, useMemo as S, useCallback as U, useEffect as P, useContext as D } from "react";
3
- const B = O(null);
4
- function N({
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
5
  children: p,
6
6
  expectedParentOrigin: d,
7
7
  initTargetOrigin: v,
8
8
  retryInit: l = { enabled: !0, intervalMs: 500, maxAttempts: 20 }
9
9
  }) {
10
- const [m, $] = k(null), [y, x] = k(null), [h, E] = k(null), [b, t] = k(null), [r, n] = k(null), e = S(() => r ? "booting" : m ? y ? "ready" : "waiting_for_token" : "waiting_for_settings", [m, y, r]), s = e === "ready", c = S(() => v || d || "*", [v, d]), a = U(() => {
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
11
  var o;
12
12
  try {
13
13
  const w = { type: "init" };
14
14
  (o = window.parent) == null || o.postMessage(w, c);
15
15
  } catch (w) {
16
- n((w == null ? void 0 : w.message) || "Failed to post init");
16
+ e((w == null ? void 0 : w.message) || "Failed to post init");
17
17
  }
18
18
  }, [c]);
19
- P(() => {
19
+ $(() => {
20
20
  a();
21
- }, [a]), P(() => {
21
+ }, [a]), $(() => {
22
22
  if (!(l != null && l.enabled) || m) return;
23
23
  const o = l.intervalMs ?? 500, w = l.maxAttempts ?? 20;
24
24
  let i = 0;
@@ -34,7 +34,7 @@ function N({
34
34
  a();
35
35
  }, o);
36
36
  return () => window.clearInterval(f);
37
- }, [l, m, a]), P(() => {
37
+ }, [l, m, a]), $(() => {
38
38
  const o = (w) => {
39
39
  if (d && w.origin !== d) return;
40
40
  const i = w.data;
@@ -43,15 +43,15 @@ function N({
43
43
  const f = i.value;
44
44
  if (!(f != null && f.backendUrl) || f.parentOrigin && d && f.parentOrigin !== d)
45
45
  return;
46
- $(f), f != null && f.user && t(f.user), n(null);
46
+ x(f), f != null && f.user && t(f.user), e(null);
47
47
  return;
48
48
  }
49
49
  if (i.type === "set-token" && typeof i.value == "string") {
50
- x(i.value), n(null);
50
+ S(i.value), e(null);
51
51
  return;
52
52
  }
53
53
  if (i.type === "set-dark-mode" && typeof i.value == "boolean") {
54
- E(i.value);
54
+ b(i.value);
55
55
  return;
56
56
  }
57
57
  if (i.type === "set-user" && typeof i.value == "object") {
@@ -62,110 +62,110 @@ function N({
62
62
  };
63
63
  return window.addEventListener("message", o), () => window.removeEventListener("message", o);
64
64
  }, [d]);
65
- const u = S(() => _(
65
+ const u = T(() => F(
66
66
  () => m,
67
- () => y
68
- ), [m, y]), g = S(
67
+ () => h
68
+ ), [m, h]), g = T(
69
69
  () => ({
70
70
  settings: m,
71
- token: y,
72
- isDarkMode: h,
73
- user: b,
71
+ token: h,
72
+ isDarkMode: y,
73
+ user: E,
74
74
  ready: s,
75
- state: e,
75
+ state: n,
76
76
  error: r,
77
77
  client: u
78
78
  }),
79
- [m, y, h, b, s, e, r, u]
79
+ [m, h, y, E, s, n, r, u]
80
80
  );
81
- return /* @__PURE__ */ L(B.Provider, { value: g, children: p });
81
+ return /* @__PURE__ */ B(O.Provider, { value: g, children: p });
82
82
  }
83
83
  function j() {
84
- const p = D(B);
84
+ const p = D(O);
85
85
  if (!p)
86
86
  throw new Error("usePromte must be used inside <PromteAppProvider>");
87
87
  return p;
88
88
  }
89
- function z() {
89
+ function G() {
90
90
  return j().settings;
91
91
  }
92
- function V() {
92
+ function z() {
93
93
  return j().token;
94
94
  }
95
- function W() {
95
+ function V() {
96
96
  return j().isDarkMode;
97
97
  }
98
- function I() {
98
+ function Q() {
99
99
  return j().user;
100
100
  }
101
- function F() {
101
+ function I() {
102
102
  return j().client;
103
103
  }
104
- function K(p = {}) {
105
- const { ready: d } = j(), v = F(), [l, m] = k([]), [$, y] = k(!1), [x, h] = k(null), E = S(() => (Array.isArray(p.type) ? p.type : p.type ? [p.type] : []).filter(Boolean).map((e) => String(e)).join(","), [p.type]), b = p.configuredOnly === !0, t = p.auto !== !1, r = U(async () => {
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
106
  if (!d) return [];
107
- y(!0), h(null);
107
+ h(!0), y(null);
108
108
  try {
109
- const n = E ? E.split(",").filter(Boolean) : void 0, e = await v.models({ type: n, configuredOnly: b });
110
- return m(e), e;
111
- } catch (n) {
112
- const e = n instanceof Error ? n.message : String(n);
113
- throw h(e), n;
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;
114
114
  } finally {
115
- y(!1);
115
+ h(!1);
116
116
  }
117
- }, [v, b, d, E]);
118
- return P(() => {
117
+ }, [v, E, d, b]);
118
+ return $(() => {
119
119
  !t || !d || r().catch(() => {
120
120
  });
121
- }, [t, d, r]), { models: l, loading: $, error: x, reload: r };
121
+ }, [t, d, r]), { models: l, loading: x, error: S, reload: r };
122
122
  }
123
- function _(p, d) {
123
+ function F(p, d) {
124
124
  const v = (t) => typeof t == "string" && t.startsWith("gpt-5");
125
125
  async function l(t, r) {
126
- const n = p(), e = d();
127
- if (!n) throw new Error("Promte settings not received yet");
128
- if (!e) throw new Error("Promte token not received yet");
129
- const s = n.backendUrl.replace(/\/+$/, ""), c = String(t || "").replace(/^\/+/, ""), a = `${s}/${c}`;
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
130
  return await fetch(a, {
131
131
  ...r,
132
132
  headers: {
133
133
  ...r.headers || {},
134
- Authorization: `Bearer ${e}`
134
+ Authorization: `Bearer ${n}`
135
135
  }
136
136
  });
137
137
  }
138
138
  async function m(t, r) {
139
- const n = await l(`/app-api/data/${t}`, {
139
+ const e = await l(`/app-api/data/${t}`, {
140
140
  method: "POST",
141
141
  headers: { "Content-Type": "application/json" },
142
142
  body: JSON.stringify(r)
143
- }), e = await n.json().catch(() => ({}));
144
- if (!n.ok)
143
+ }), n = await e.json().catch(() => ({}));
144
+ if (!e.ok)
145
145
  throw new Error(
146
- (e == null ? void 0 : e.error) || `Request failed (${n.status})`
146
+ (n == null ? void 0 : n.error) || `Request failed (${e.status})`
147
147
  );
148
- return e == null ? void 0 : e.value;
148
+ return n == null ? void 0 : n.value;
149
149
  }
150
- async function $(t) {
150
+ async function x(t) {
151
151
  const r = new URLSearchParams();
152
152
  t.scope && r.set("scope", t.scope), t.path && r.set("path", t.path);
153
- const n = await l(`/app-api/data?${r.toString()}`, {
153
+ const e = await l(`/app-api/data?${r.toString()}`, {
154
154
  method: "GET"
155
- }), e = await n.json().catch(() => ({}));
156
- if (!n.ok)
157
- throw new Error((e == null ? void 0 : e.error) || `Request failed (${n.status})`);
158
- return e == null ? void 0 : e.value;
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;
159
159
  }
160
- async function y(t) {
161
- const r = new URLSearchParams(), n = Array.isArray(t == null ? void 0 : t.type) ? t == null ? void 0 : t.type : t != null && t.type ? [t.type] : [];
162
- n.length > 0 && r.set("type", n.join(",")), t != null && t.configuredOnly && r.set("configuredOnly", "true");
163
- const e = await l(
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
164
  `/app-api/models${r.toString() ? `?${r.toString()}` : ""}`,
165
165
  { method: "GET" }
166
- ), s = await e.json().catch(() => ({}));
167
- if (!e.ok)
168
- throw new Error((s == null ? void 0 : s.error) || `Request failed (${e.status})`);
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
169
  return (Array.isArray(s == null ? void 0 : s.models) ? s.models : []).map((a) => {
170
170
  if (!a || typeof a != "object") return null;
171
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;
@@ -180,57 +180,57 @@ function _(p, d) {
180
180
  (a) => !!a
181
181
  );
182
182
  }
183
- async function x(t, r) {
184
- const n = await l(t, r), s = (n.headers.get("content-type") || "").includes("application/json") ? await n.json().catch(() => ({})) : await n.text();
185
- if (!n.ok)
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)
186
186
  throw new Error(
187
- typeof s == "string" ? s || `Request failed (${n.status})` : (s == null ? void 0 : s.error) || (s == null ? void 0 : s.message) || `Request failed (${n.status})`
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})`
188
188
  );
189
189
  return s;
190
190
  }
191
- const h = (t) => t ? t.split("/").map((r) => r.trim()).filter(Boolean).join("/") : "", E = (t, r) => {
192
- const n = h(t), e = h(r);
193
- return n ? e ? `${n}/${e}` : n : e;
194
- }, b = (t, r) => {
195
- const n = { scope: t };
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 };
196
196
  return {
197
197
  async get() {
198
- const e = h(r);
199
- return $({ ...n, path: e || void 0 });
198
+ const n = y(r);
199
+ return x({ ...e, path: n || void 0 });
200
200
  },
201
- async set(e) {
202
- const s = h(r);
201
+ async set(n) {
202
+ const s = y(r);
203
203
  return m("set", {
204
- ...n,
204
+ ...e,
205
205
  path: s || void 0,
206
- value: e
206
+ value: n
207
207
  });
208
208
  },
209
- async update(e) {
210
- if (!e || typeof e != "object")
209
+ async update(n) {
210
+ if (!n || typeof n != "object")
211
211
  throw new Error("update requires an object");
212
212
  const s = {};
213
- for (const [c, a] of Object.entries(e)) {
214
- const u = E(r, c);
213
+ for (const [c, a] of Object.entries(n)) {
214
+ const u = b(r, c);
215
215
  if (!u)
216
216
  throw new Error("update paths must be non-empty");
217
217
  s[u] = a;
218
218
  }
219
- return m("update", { ...n, updates: s });
219
+ return m("update", { ...e, updates: s });
220
220
  },
221
221
  async remove() {
222
- const e = h(r);
223
- return m("remove", { ...n, path: e || void 0 });
222
+ const n = y(r);
223
+ return m("remove", { ...e, path: n || void 0 });
224
224
  },
225
- async push(e) {
226
- const s = h(r);
225
+ async push(n) {
226
+ const s = y(r);
227
227
  if (!s) throw new Error("push requires a path");
228
- return m("array-push", { ...n, path: s, value: e });
228
+ return m("array-push", { ...e, path: s, value: n });
229
229
  },
230
- ref(e) {
231
- const s = E(r, e);
230
+ ref(n) {
231
+ const s = b(r, n);
232
232
  if (!s) throw new Error("ref requires a path");
233
- return b(t, s);
233
+ return E(t, s);
234
234
  }
235
235
  };
236
236
  };
@@ -243,16 +243,16 @@ function _(p, d) {
243
243
  return ((t = p()) == null ? void 0 : t.backendUrl) ?? null;
244
244
  },
245
245
  async models(t) {
246
- return y(t);
246
+ return h(t);
247
247
  },
248
248
  async chatCompletions(t) {
249
249
  var o;
250
250
  const {
251
251
  reasoningEffort: r,
252
- reasoning_effort: n,
253
- ...e
254
- } = t, s = r ?? n, c = {
255
- ...e,
252
+ reasoning_effort: e,
253
+ ...n
254
+ } = t, s = r ?? e, c = {
255
+ ...n,
256
256
  stream: !1
257
257
  };
258
258
  s && v(t.model) && (c.reasoning_effort = s);
@@ -268,16 +268,37 @@ function _(p, d) {
268
268
  return g;
269
269
  },
270
270
  async chatText(t) {
271
- var n, e, s;
271
+ var e, n, s;
272
272
  const r = await this.chatCompletions(t);
273
- return ((s = (e = (n = r == null ? void 0 : r.choices) == null ? void 0 : n[0]) == null ? void 0 : e.message) == null ? void 0 : s.content) ?? "";
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) ?? "";
274
+ },
275
+ embeddings: {
276
+ 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")))
282
+ throw new Error(
283
+ "embeddings.create requires input as a string or string[]"
284
+ );
285
+ return S("/openai/embeddings", {
286
+ method: "POST",
287
+ headers: { "Content-Type": "application/json" },
288
+ body: JSON.stringify({
289
+ ...t,
290
+ model: r,
291
+ input: e
292
+ })
293
+ });
294
+ }
274
295
  },
275
296
  audio: {
276
297
  async tts(t) {
277
298
  var s;
278
299
  const r = (s = t == null ? void 0 : t.text) == null ? void 0 : s.trim();
279
300
  if (!r) throw new Error("audio.tts requires non-empty text");
280
- const n = await l("/app-api/audio/tts", {
301
+ const e = await l("/app-api/audio/tts", {
281
302
  method: "POST",
282
303
  headers: { "Content-Type": "application/json" },
283
304
  body: JSON.stringify({
@@ -286,26 +307,26 @@ function _(p, d) {
286
307
  lang: t.lang
287
308
  })
288
309
  });
289
- if (!n.ok) {
290
- const c = await n.text();
291
- throw new Error(c || `Request failed (${n.status})`);
310
+ if (!e.ok) {
311
+ const c = await e.text();
312
+ throw new Error(c || `Request failed (${e.status})`);
292
313
  }
293
314
  return {
294
- audio: await n.arrayBuffer(),
295
- contentType: n.headers.get("content-type")
315
+ audio: await e.arrayBuffer(),
316
+ contentType: e.headers.get("content-type")
296
317
  };
297
318
  },
298
319
  async stt(t) {
299
- var i, f, T;
320
+ var i, f, P;
300
321
  if (!(t != null && t.file)) throw new Error("audio.stt requires a file");
301
322
  const r = (R) => {
302
323
  if (!R) return;
303
324
  const C = R.trim();
304
325
  if (!C) return;
305
- const A = C.toLowerCase(), M = A.split("-")[0];
306
- return M.length === 2 ? M : A;
307
- }, n = typeof File < "u" && t.file instanceof File, e = n && t.file.name.split(".").pop() || "webm", s = t.ext || e, c = new FormData();
308
- n ? c.set("file", t.file) : c.set("file", t.file, `audio.${s}`);
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}`);
309
330
  const a = r(t.language);
310
331
  a && c.set("language", a), t.prompt && c.set("prompt", t.prompt);
311
332
  const u = await l(
@@ -319,28 +340,28 @@ function _(p, d) {
319
340
  throw new Error(
320
341
  typeof o == "string" ? o : ((i = o == null ? void 0 : o.error) == null ? void 0 : i.message) || `Request failed (${u.status})`
321
342
  );
322
- return { text: typeof o == "string" ? o : (o == null ? void 0 : o.text) || (o == null ? void 0 : o.original) || ((T = (f = o == null ? void 0 : o.results) == null ? void 0 : f[0]) == null ? void 0 : T.text) || "", raw: o };
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 };
323
344
  },
324
345
  async voices(t) {
325
346
  const r = new URLSearchParams();
326
347
  t != null && t.locale && r.set("locale", t.locale);
327
- const n = await l(
348
+ const e = await l(
328
349
  `/app-api/audio/tts/voices${r.toString() ? `?${r}` : ""}`,
329
350
  { method: "GET" }
330
- ), e = await n.json().catch(() => []);
331
- if (!n.ok)
351
+ ), n = await e.json().catch(() => []);
352
+ if (!e.ok)
332
353
  throw new Error(
333
- (e == null ? void 0 : e.error) || `Request failed (${n.status})`
354
+ (n == null ? void 0 : n.error) || `Request failed (${e.status})`
334
355
  );
335
- return Array.isArray(e) ? e : (e == null ? void 0 : e.voices) || [];
356
+ return Array.isArray(n) ? n : (n == null ? void 0 : n.voices) || [];
336
357
  }
337
358
  },
338
359
  web: {
339
360
  async scrapeUrl(t) {
340
- var n;
341
- const r = (n = t == null ? void 0 : t.url) == null ? void 0 : n.trim();
361
+ var e;
362
+ const r = (e = t == null ? void 0 : t.url) == null ? void 0 : e.trim();
342
363
  if (!r) throw new Error("web.scrapeUrl requires a url");
343
- return x(
364
+ return S(
344
365
  "/app-api/web/scrape-url",
345
366
  {
346
367
  method: "POST",
@@ -353,18 +374,41 @@ function _(p, d) {
353
374
  );
354
375
  }
355
376
  },
377
+ knowledge: {
378
+ 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(
383
+ "/app-api/knowledge/search",
384
+ {
385
+ method: "POST",
386
+ headers: { "Content-Type": "application/json" },
387
+ body: JSON.stringify({
388
+ workspaceId: t.workspaceId,
389
+ query: r,
390
+ maxResults: t.maxResults,
391
+ generateSearchQuery: t.generateSearchQuery,
392
+ sourceId: t.sourceId,
393
+ includeSourceUrls: t.includeSourceUrls,
394
+ queries: t.queries
395
+ })
396
+ }
397
+ );
398
+ }
399
+ },
356
400
  data(t = "private") {
357
- return b(t, "");
401
+ return E(t, "");
358
402
  }
359
403
  };
360
404
  }
361
405
  export {
362
- N as PromteAppProvider,
406
+ _ as PromteAppProvider,
363
407
  j as usePromte,
364
- F as usePromteClient,
365
- W as usePromteDarkMode,
366
- K as usePromteModels,
367
- z as usePromteSettings,
368
- V as usePromteToken,
369
- I as usePromteUser
408
+ I as usePromteClient,
409
+ V as usePromteDarkMode,
410
+ W as usePromteModels,
411
+ G as usePromteSettings,
412
+ z as usePromteToken,
413
+ Q as usePromteUser
370
414
  };
@@ -1 +1 @@
1
- (function(y,j){typeof exports=="object"&&typeof module<"u"?j(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],j):(y=typeof globalThis<"u"?globalThis:y||self,j(y.PromteAppLibrary={},y.jsxRuntime,y.react))})(this,function(y,j,i){"use strict";const M=i.createContext(null);function O({children:d,expectedParentOrigin:m,initTargetOrigin:b,retryInit:l={enabled:!0,intervalMs:500,maxAttempts:20}}){const[w,T]=i.useState(null),[v,$]=i.useState(null),[g,k]=i.useState(null),[P,t]=i.useState(null),[s,n]=i.useState(null),e=i.useMemo(()=>s?"booting":w?v?"ready":"waiting_for_token":"waiting_for_settings",[w,v,s]),r=e==="ready",c=i.useMemo(()=>b||m||"*",[b,m]),a=i.useCallback(()=>{var o;try{const h={type:"init"};(o=window.parent)==null||o.postMessage(h,c)}catch(h){n((h==null?void 0:h.message)||"Failed to post init")}},[c]);i.useEffect(()=>{a()},[a]),i.useEffect(()=>{if(!(l!=null&&l.enabled)||w)return;const o=l.intervalMs??500,h=l.maxAttempts??20;let u=0;const p=window.setInterval(()=>{if(w){window.clearInterval(p);return}if(u+=1,u>h){window.clearInterval(p);return}a()},o);return()=>window.clearInterval(p)},[l,w,a]),i.useEffect(()=>{const o=h=>{if(m&&h.origin!==m)return;const u=h.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;T(p),p!=null&&p.user&&t(p.user),n(null);return}if(u.type==="set-token"&&typeof u.value=="string"){$(u.value),n(null);return}if(u.type==="set-dark-mode"&&typeof u.value=="boolean"){k(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 f=i.useMemo(()=>J(()=>w,()=>v),[w,v]),E=i.useMemo(()=>({settings:w,token:v,isDarkMode:g,user:P,ready:r,state:e,error:s,client:f}),[w,v,g,P,r,e,s,f]);return j.jsx(M.Provider,{value:E,children:d})}function S(){const d=i.useContext(M);if(!d)throw new Error("usePromte must be used inside <PromteAppProvider>");return d}function B(){return S().settings}function D(){return S().token}function F(){return S().isDarkMode}function _(){return S().user}function R(){return S().client}function G(d={}){const{ready:m}=S(),b=R(),[l,w]=i.useState([]),[T,v]=i.useState(!1),[$,g]=i.useState(null),k=i.useMemo(()=>(Array.isArray(d.type)?d.type:d.type?[d.type]:[]).filter(Boolean).map(e=>String(e)).join(","),[d.type]),P=d.configuredOnly===!0,t=d.auto!==!1,s=i.useCallback(async()=>{if(!m)return[];v(!0),g(null);try{const n=k?k.split(",").filter(Boolean):void 0,e=await b.models({type:n,configuredOnly:P});return w(e),e}catch(n){const e=n instanceof Error?n.message:String(n);throw g(e),n}finally{v(!1)}},[b,P,m,k]);return i.useEffect(()=>{!t||!m||s().catch(()=>{})},[t,m,s]),{models:l,loading:T,error:$,reload:s}}function J(d,m){const b=t=>typeof t=="string"&&t.startsWith("gpt-5");async function l(t,s){const n=d(),e=m();if(!n)throw new Error("Promte settings not received yet");if(!e)throw new Error("Promte token not received yet");const r=n.backendUrl.replace(/\/+$/,""),c=String(t||"").replace(/^\/+/,""),a=`${r}/${c}`;return await fetch(a,{...s,headers:{...s.headers||{},Authorization:`Bearer ${e}`}})}async function w(t,s){const n=await l(`/app-api/data/${t}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)}),e=await n.json().catch(()=>({}));if(!n.ok)throw new Error((e==null?void 0:e.error)||`Request failed (${n.status})`);return e==null?void 0:e.value}async function T(t){const s=new URLSearchParams;t.scope&&s.set("scope",t.scope),t.path&&s.set("path",t.path);const n=await l(`/app-api/data?${s.toString()}`,{method:"GET"}),e=await n.json().catch(()=>({}));if(!n.ok)throw new Error((e==null?void 0:e.error)||`Request failed (${n.status})`);return e==null?void 0:e.value}async function v(t){const s=new URLSearchParams,n=Array.isArray(t==null?void 0:t.type)?t==null?void 0:t.type:t!=null&&t.type?[t.type]:[];n.length>0&&s.set("type",n.join(",")),t!=null&&t.configuredOnly&&s.set("configuredOnly","true");const e=await l(`/app-api/models${s.toString()?`?${s.toString()}`:""}`,{method:"GET"}),r=await e.json().catch(()=>({}));if(!e.ok)throw new Error((r==null?void 0:r.error)||`Request failed (${e.status})`);return(Array.isArray(r==null?void 0:r.models)?r.models:[]).map(a=>{if(!a||typeof a!="object")return null;const f=typeof a.id=="string"?a.id.trim():"",E=typeof a.label=="string"?a.label.trim():f,o=a.type,h=a.configured===!0,u=typeof a.source=="string"&&a.source.trim()?a.source.trim():void 0;return!f||o!=="llm"&&o!=="embedding"&&o!=="image"&&o!=="stt"&&o!=="tts"?null:{id:f,label:E||f,type:o,configured:h,source:u}}).filter(a=>!!a)}async function $(t,s){const n=await l(t,s),r=(n.headers.get("content-type")||"").includes("application/json")?await n.json().catch(()=>({})):await n.text();if(!n.ok)throw new Error(typeof r=="string"?r||`Request failed (${n.status})`:(r==null?void 0:r.error)||(r==null?void 0:r.message)||`Request failed (${n.status})`);return r}const g=t=>t?t.split("/").map(s=>s.trim()).filter(Boolean).join("/"):"",k=(t,s)=>{const n=g(t),e=g(s);return n?e?`${n}/${e}`:n:e},P=(t,s)=>{const n={scope:t};return{async get(){const e=g(s);return T({...n,path:e||void 0})},async set(e){const r=g(s);return w("set",{...n,path:r||void 0,value:e})},async update(e){if(!e||typeof e!="object")throw new Error("update requires an object");const r={};for(const[c,a]of Object.entries(e)){const f=k(s,c);if(!f)throw new Error("update paths must be non-empty");r[f]=a}return w("update",{...n,updates:r})},async remove(){const e=g(s);return w("remove",{...n,path:e||void 0})},async push(e){const r=g(s);if(!r)throw new Error("push requires a path");return w("array-push",{...n,path:r,value:e})},ref(e){const r=k(s,e);if(!r)throw new Error("ref requires a path");return P(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:n,...e}=t,r=s??n,c={...e,stream:!1};r&&b(t.model)&&(c.reasoning_effort=r);const a=await l("/openai/chat/completions",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(c)}),E=(a.headers.get("content-type")||"").includes("application/json")?await a.json():await a.text();if(!a.ok)throw new Error(typeof E=="string"?E:((o=E==null?void 0:E.error)==null?void 0:o.message)||`Request failed (${a.status})`);return E},async chatText(t){var n,e,r;const s=await this.chatCompletions(t);return((r=(e=(n=s==null?void 0:s.choices)==null?void 0:n[0])==null?void 0:e.message)==null?void 0:r.content)??""},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 n=await l("/app-api/audio/tts",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:s,voice:t.voice,lang:t.lang})});if(!n.ok){const c=await n.text();throw new Error(c||`Request failed (${n.status})`)}return{audio:await n.arrayBuffer(),contentType:n.headers.get("content-type")}},async stt(t){var u,p,x;if(!(t!=null&&t.file))throw new Error("audio.stt requires a file");const s=C=>{if(!C)return;const A=C.trim();if(!A)return;const U=A.toLowerCase(),L=U.split("-")[0];return L.length===2?L:U},n=typeof File<"u"&&t.file instanceof File,e=n&&t.file.name.split(".").pop()||"webm",r=t.ext||e,c=new FormData;n?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 f=await l(`/app-api/audio/stt?ext=${encodeURIComponent(r)}`,{method:"POST",body:c}),o=(f.headers.get("content-type")||"").includes("application/json")?await f.json():await f.text();if(!f.ok)throw new Error(typeof o=="string"?o:((u=o==null?void 0:o.error)==null?void 0:u.message)||`Request failed (${f.status})`);return{text:typeof o=="string"?o:(o==null?void 0:o.text)||(o==null?void 0:o.original)||((x=(p=o==null?void 0:o.results)==null?void 0:p[0])==null?void 0:x.text)||"",raw:o}},async voices(t){const s=new URLSearchParams;t!=null&&t.locale&&s.set("locale",t.locale);const n=await l(`/app-api/audio/tts/voices${s.toString()?`?${s}`:""}`,{method:"GET"}),e=await n.json().catch(()=>[]);if(!n.ok)throw new Error((e==null?void 0:e.error)||`Request failed (${n.status})`);return Array.isArray(e)?e:(e==null?void 0:e.voices)||[]}},web:{async scrapeUrl(t){var n;const s=(n=t==null?void 0:t.url)==null?void 0:n.trim();if(!s)throw new Error("web.scrapeUrl requires a url");return $("/app-api/web/scrape-url",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:s,maxChars:t.maxChars})})}},data(t="private"){return P(t,"")}}}y.PromteAppProvider=O,y.usePromte=S,y.usePromteClient=R,y.usePromteDarkMode=F,y.usePromteModels=G,y.usePromteSettings=B,y.usePromteToken=D,y.usePromteUser=_,Object.defineProperty(y,Symbol.toStringTag,{value:"Module"})});
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"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promte/app-library",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "files": [