@promte/app-library 0.1.8 → 0.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -145,6 +145,40 @@ If `workspaceId` is omitted, the search uses the current app workspace. Searchin
145
145
  another workspace requires that the current user has access to that workspace.
146
146
  Public app tokens can only search their own workspace.
147
147
 
148
+ ## Ask an assistant
149
+
150
+ Apps can ask a Promte assistant. The assistant answers with its own prompt,
151
+ model, tools and knowledge base, and the conversation appears in the
152
+ assistant's logs and insights:
153
+
154
+ ```ts
155
+ const first = await client.assistant.ask({
156
+ assistantId: "assistant-workspace-id",
157
+ question: "Hvad kan vi låne til en 6. klasse i fysik?",
158
+ });
159
+ console.log(first.answer, first.sources);
160
+
161
+ // Follow-up in the same conversation
162
+ await client.assistant.ask({
163
+ assistantId: "assistant-workspace-id",
164
+ conversationId: first.conversationId,
165
+ question: "Har I noget til indskolingen?",
166
+ });
167
+ ```
168
+
169
+ Signed-in users can ask assistants they have access to. Public apps can only
170
+ ask assistants that are published publicly. The call waits for the full answer
171
+ (no streaming). For structured data, ask the assistant to answer in JSON in its
172
+ prompt or question and parse `answer`.
173
+
174
+ Each visitor without login may ask 30 questions per 10 minutes from one IP
175
+ address, and each app 2,000 questions per day. Above that the call fails with
176
+ status 429 and the message `rate_limited`; show a friendly "try again later".
177
+
178
+ `answer` is Markdown. Footnotes such as `^2^` or `^0,3^` point at
179
+ `sources[2]`, `sources[0]` and `sources[3]`; the same source can appear more
180
+ than once. `link` is empty for uploaded files, which have no public address.
181
+
148
182
  ## Return behavior
149
183
 
150
184
  - `get()` returns the value at the current path, or `null` if missing.
package/dist/index.d.ts CHANGED
@@ -8,9 +8,17 @@ export declare type AppDataRef = {
8
8
  remove(): Promise<any>;
9
9
  push(value: any): Promise<any>;
10
10
  ref(path: string): AppDataRef;
11
+ /** "shared" scope only: every user's value at this path. */
12
+ getAll<T = any>(): Promise<AppSharedItem<T>[]>;
11
13
  };
12
14
 
13
- export declare type AppDataScope = "private" | "public";
15
+ /**
16
+ * "private": only the signed-in user. "public": readable by everyone, only
17
+ * workspace administrators can change it. "shared": everyone reads all of it,
18
+ * each user writes only their own part (ref().getAll() returns every part),
19
+ * and workspace administrators can change anyone's part with { owner }.
20
+ */
21
+ export declare type AppDataScope = "private" | "public" | "shared";
14
22
 
15
23
  export declare type AppDataUpdateMap = Record<string, any>;
16
24
 
@@ -46,6 +54,32 @@ export declare type AppFiles = {
46
54
  remove(id: string): Promise<void>;
47
55
  };
48
56
 
57
+ export declare type AppFileScope = "private" | "public";
58
+
59
+ /** One user's part of shared data. owner is a stable id, not an email. */
60
+ export declare type AppSharedItem<T = any> = {
61
+ owner: string;
62
+ mine: boolean;
63
+ value: T;
64
+ };
65
+
66
+ export declare type AssistantAskRequest = {
67
+ /** The assistant workspace that answers. Public apps can only ask public assistants. */
68
+ assistantId: string;
69
+ question: string;
70
+ /** Continue an earlier conversation from a previous answer. */
71
+ conversationId?: string;
72
+ };
73
+
74
+ export declare type AssistantAskResponse = {
75
+ conversationId: string;
76
+ answer: string;
77
+ sources: {
78
+ title: string;
79
+ link: string;
80
+ }[];
81
+ };
82
+
49
83
  export declare type AudioSttRequest = {
50
84
  file: File | Blob;
51
85
  language?: string;
@@ -91,6 +125,13 @@ export declare type AudioVoicesRequest = {
91
125
  locale?: string;
92
126
  };
93
127
 
128
+ declare type AuthAction = "signIn" | "signUp" | "sendLoginLink" | "sendPasswordReset" | "completePasswordReset" | "signOut";
129
+
130
+ declare type AuthRequest = (action: AuthAction, input?: {
131
+ email?: string;
132
+ password?: string;
133
+ }) => Promise<void>;
134
+
94
135
  export declare type ChatCompletionsRequest = {
95
136
  model: string;
96
137
  messages: ChatMessage[];
@@ -192,6 +233,23 @@ export declare type PromteAppProviderProps = {
192
233
  };
193
234
  };
194
235
 
236
+ /** Login for visitors of a public app, when the app's admins turned it on. */
237
+ export declare type PromteAuthState = {
238
+ /** The app's admins turned on visitor login for this public app. */
239
+ loginEnabled: boolean;
240
+ methods: {
241
+ password: boolean;
242
+ magicLink: boolean;
243
+ signup: boolean;
244
+ };
245
+ /** A visitor is signed in. People signed in to Promte are never visitors. */
246
+ signedIn: boolean;
247
+ /** The visitor opened a password-reset link; call completePasswordReset. */
248
+ pendingPasswordReset: boolean;
249
+ /** The visitor opened a login or reset link that had expired or was already used. */
250
+ expiredLink: boolean;
251
+ };
252
+
195
253
  export declare type PromteClient = {
196
254
  isReady(): boolean;
197
255
  functions: {
@@ -225,6 +283,9 @@ export declare type PromteClient = {
225
283
  knowledge: {
226
284
  search(req: KnowledgeSearchRequest): Promise<KnowledgeSearchResponse>;
227
285
  };
286
+ assistant: {
287
+ ask(req: AssistantAskRequest): Promise<AssistantAskResponse>;
288
+ };
228
289
  translatorLiveShare: {
229
290
  create(displayLanguage: string): Promise<{
230
291
  shareId: string;
@@ -237,8 +298,18 @@ export declare type PromteClient = {
237
298
  guardrails: {
238
299
  check(value: unknown): Promise<PromteGuardrailsResult>;
239
300
  };
240
- data(scope?: AppDataScope): AppDataRef;
241
- files(scope?: AppDataScope): AppFiles;
301
+ /** owner (from getAll) lets workspace administrators change another user's shared part. */
302
+ data(scope?: AppDataScope, options?: {
303
+ owner?: string;
304
+ }): AppDataRef;
305
+ files(scope?: AppFileScope): AppFiles;
306
+ email: {
307
+ /** Sends one email per recipient from "<app name> via Promte"; replies go to the signed-in user, or to replyTo for visitors without login. */
308
+ send(req: PromteEmailRequest): Promise<{
309
+ sent: number;
310
+ }>;
311
+ };
312
+ assets: SharedAssets;
242
313
  };
243
314
 
244
315
  declare type PromteCtxValue = {
@@ -250,6 +321,30 @@ declare type PromteCtxValue = {
250
321
  state: PromteHandshakeState;
251
322
  error: string | null;
252
323
  client: PromteClient;
324
+ auth: PromteAuthState;
325
+ authRequest: AuthRequest;
326
+ };
327
+
328
+ /** Thrown by client.email.send; code says why the email was not sent. */
329
+ export declare class PromteEmailError extends Error {
330
+ code: PromteEmailErrorCode;
331
+ status: number;
332
+ constructor(code: PromteEmailErrorCode, status: number, message?: string);
333
+ }
334
+
335
+ export declare type PromteEmailErrorCode = "sign_in_required" | "invalid_recipient" | "too_many_recipients" | "invalid_subject" | "invalid_body" | "body_too_large" | "invalid_reply_to" | "recipient_not_allowed" | "email_disabled" | "rate_limited" | "email_not_configured" | "send_failed" | "app_policy_blocked" | "server_error";
336
+
337
+ export declare type PromteEmailRequest = {
338
+ /** One address or up to 5. Only the signed-in user, members of the app, the app's visitor accounts and the app's fixed recipients. Visitors without login may only write to the fixed recipients. */
339
+ to: string | string[];
340
+ /** At most 200 characters. */
341
+ subject: string;
342
+ /** Plain text. Text and html together may be at most 50 KB. */
343
+ text: string;
344
+ /** Optional simple HTML: only p, br, strong, b, em, i, u, ul, ol, li, h1-h3, blockquote and <a href="https://...">; everything else is shown as text. */
345
+ html?: string;
346
+ /** Visitors without login only: the address replies should go to, for example one the visitor typed in. It is not verified and is marked as such in the mail. Signed-in users always get the replies themselves. */
347
+ replyTo?: string;
253
348
  };
254
349
 
255
350
  export declare type PromteGuardrailsResult = {
@@ -304,6 +399,8 @@ export declare type PromteSettings = {
304
399
  user?: PromteUser;
305
400
  /** Set by Promte pages that can send backend requests for the app. */
306
401
  fetchProxy?: boolean;
402
+ /** False when governance turned file downloads from apps off. */
403
+ allowDownloads?: boolean;
307
404
  };
308
405
 
309
406
  export declare type PromteUser = {
@@ -311,6 +408,15 @@ export declare type PromteUser = {
311
408
  isAdmin?: boolean;
312
409
  role?: string;
313
410
  workspaceId?: string;
411
+ /** Entra ID or FK Organisation groups, when the organisation and app share them. */
412
+ groups?: Array<{
413
+ id: string;
414
+ name?: string;
415
+ }>;
416
+ /** Roles from the organisation's login (for example Entra ID app roles). */
417
+ roles?: string[];
418
+ /** True for a visitor signed in to a public app with its own app login. */
419
+ visitor?: boolean;
314
420
  };
315
421
 
316
422
  export declare type ReasoningEffort = "minimal" | "low" | "medium" | "high";
@@ -338,6 +444,31 @@ export declare type ScrapeUrlResponse = {
338
444
  };
339
445
  };
340
446
 
447
+ /** An organisation-wide asset (logo, font, image or style file) shared by all apps. */
448
+ export declare type SharedAsset = {
449
+ name: string;
450
+ contentType: string;
451
+ size: number;
452
+ sha256: string;
453
+ description: string;
454
+ updatedAt: string;
455
+ };
456
+
457
+ /**
458
+ * Organisation assets uploaded by super administrators. Load them through
459
+ * these helpers: the app sandbox blocks direct remote image, font and style URLs.
460
+ */
461
+ export declare type SharedAssets = {
462
+ list(): Promise<SharedAsset[]>;
463
+ get(name: string, options?: {
464
+ signal?: AbortSignal;
465
+ }): Promise<Blob>;
466
+ /** The asset as text, for CSS, JSON and text files. */
467
+ text(name: string): Promise<string>;
468
+ /** A cached object URL for img src, CSS url(...) or FontFace. */
469
+ url(name: string): Promise<string>;
470
+ };
471
+
341
472
  export declare type TranslatorLiveShareLine = {
342
473
  id: string;
343
474
  speaker: string;
@@ -357,6 +488,40 @@ export declare type TranslatorLiveShareSnapshot = {
357
488
 
358
489
  export declare function usePromte(): PromteCtxValue;
359
490
 
491
+ /**
492
+ * Visitor login for public apps. Build your own login UI with these functions;
493
+ * Promte checks passwords, stores accounts, sends the emails and keeps the
494
+ * session. Errors reject with an Error whose message is a code such as
495
+ * "invalid_credentials", "weak_password", "too_many_attempts", "expired_link"
496
+ * or "login_disabled". After signIn, usePromteUser() returns the visitor.
497
+ */
498
+ export declare function usePromteAuth(): {
499
+ /** Signs in with email and password. */
500
+ signIn: (email: string, password: string) => Promise<void>;
501
+ /** Starts sign-up; the account is created when the visitor clicks the link in the email. */
502
+ signUp: (email: string, password: string) => Promise<void>;
503
+ /** Emails a single-use login link. Resolves even if the email has no account. */
504
+ sendLoginLink: (email: string) => Promise<void>;
505
+ /** Emails a link for choosing a new password. */
506
+ sendPasswordReset: (email: string) => Promise<void>;
507
+ /** Sets the new password after the visitor opened a reset link, and signs them in. */
508
+ completePasswordReset: (password: string) => Promise<void>;
509
+ signOut: () => Promise<void>;
510
+ /** The app's admins turned on visitor login for this public app. */
511
+ loginEnabled: boolean;
512
+ methods: {
513
+ password: boolean;
514
+ magicLink: boolean;
515
+ signup: boolean;
516
+ };
517
+ /** A visitor is signed in. People signed in to Promte are never visitors. */
518
+ signedIn: boolean;
519
+ /** The visitor opened a password-reset link; call completePasswordReset. */
520
+ pendingPasswordReset: boolean;
521
+ /** The visitor opened a login or reset link that had expired or was already used. */
522
+ expiredLink: boolean;
523
+ };
524
+
360
525
  export declare function usePromteClient(): PromteClient;
361
526
 
362
527
  export declare function usePromteDarkMode(): boolean;