@promte/app-library 0.1.7 → 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 +51 -0
- package/dist/index.d.ts +225 -2
- package/dist/index.mjs +637 -303
- package/dist/index.umd.cjs +1 -1
- package/package.json +3 -3
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:
|
|
@@ -128,6 +145,40 @@ If `workspaceId` is omitted, the search uses the current app workspace. Searchin
|
|
|
128
145
|
another workspace requires that the current user has access to that workspace.
|
|
129
146
|
Public app tokens can only search their own workspace.
|
|
130
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
|
+
|
|
131
182
|
## Return behavior
|
|
132
183
|
|
|
133
184
|
- `get()` returns the value at the current path, or `null` if missing.
|
package/dist/index.d.ts
CHANGED
|
@@ -8,12 +8,78 @@ 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
|
-
|
|
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
|
|
|
25
|
+
/** A stored file. Names may contain folders, e.g. "corpus/2024/report.pdf". */
|
|
26
|
+
export declare type AppFile = {
|
|
27
|
+
id: string;
|
|
28
|
+
name: string;
|
|
29
|
+
contentType: string;
|
|
30
|
+
size: number;
|
|
31
|
+
sha256: string;
|
|
32
|
+
createdAt: string;
|
|
33
|
+
updatedAt: string;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* File storage for larger or binary content (documents, images, exports).
|
|
38
|
+
* "private" files belong to the signed-in user; "public" files are shared in the
|
|
39
|
+
* app workspace and only workspace administrators can change them.
|
|
40
|
+
* Uploading a file with an existing name replaces it.
|
|
41
|
+
*/
|
|
42
|
+
export declare type AppFiles = {
|
|
43
|
+
upload(file: Blob, options?: {
|
|
44
|
+
name?: string;
|
|
45
|
+
contentType?: string;
|
|
46
|
+
signal?: AbortSignal;
|
|
47
|
+
}): Promise<AppFile>;
|
|
48
|
+
list(options?: {
|
|
49
|
+
prefix?: string;
|
|
50
|
+
}): Promise<AppFile[]>;
|
|
51
|
+
download(id: string, options?: {
|
|
52
|
+
signal?: AbortSignal;
|
|
53
|
+
}): Promise<Blob>;
|
|
54
|
+
remove(id: string): Promise<void>;
|
|
55
|
+
};
|
|
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
|
+
|
|
17
83
|
export declare type AudioSttRequest = {
|
|
18
84
|
file: File | Blob;
|
|
19
85
|
language?: string;
|
|
@@ -59,6 +125,13 @@ export declare type AudioVoicesRequest = {
|
|
|
59
125
|
locale?: string;
|
|
60
126
|
};
|
|
61
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
|
+
|
|
62
135
|
export declare type ChatCompletionsRequest = {
|
|
63
136
|
model: string;
|
|
64
137
|
messages: ChatMessage[];
|
|
@@ -160,8 +233,28 @@ export declare type PromteAppProviderProps = {
|
|
|
160
233
|
};
|
|
161
234
|
};
|
|
162
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
|
+
|
|
163
253
|
export declare type PromteClient = {
|
|
164
254
|
isReady(): boolean;
|
|
255
|
+
functions: {
|
|
256
|
+
invoke<TInput = unknown, TResult = unknown>(name: string, input: TInput): Promise<TResult>;
|
|
257
|
+
};
|
|
165
258
|
getBackendUrl(): string | null;
|
|
166
259
|
models(req?: PromteModelsRequest): Promise<PromteModelInfo[]>;
|
|
167
260
|
chatCompletions(req: ChatCompletionsRequest): Promise<ChatCompletionsResponse>;
|
|
@@ -190,6 +283,9 @@ export declare type PromteClient = {
|
|
|
190
283
|
knowledge: {
|
|
191
284
|
search(req: KnowledgeSearchRequest): Promise<KnowledgeSearchResponse>;
|
|
192
285
|
};
|
|
286
|
+
assistant: {
|
|
287
|
+
ask(req: AssistantAskRequest): Promise<AssistantAskResponse>;
|
|
288
|
+
};
|
|
193
289
|
translatorLiveShare: {
|
|
194
290
|
create(displayLanguage: string): Promise<{
|
|
195
291
|
shareId: string;
|
|
@@ -199,7 +295,21 @@ export declare type PromteClient = {
|
|
|
199
295
|
update(shareId: string, snapshot: TranslatorLiveShareSnapshot): Promise<void>;
|
|
200
296
|
revoke(shareId: string): Promise<void>;
|
|
201
297
|
};
|
|
202
|
-
|
|
298
|
+
guardrails: {
|
|
299
|
+
check(value: unknown): Promise<PromteGuardrailsResult>;
|
|
300
|
+
};
|
|
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;
|
|
203
313
|
};
|
|
204
314
|
|
|
205
315
|
declare type PromteCtxValue = {
|
|
@@ -211,6 +321,43 @@ declare type PromteCtxValue = {
|
|
|
211
321
|
state: PromteHandshakeState;
|
|
212
322
|
error: string | null;
|
|
213
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;
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
export declare type PromteGuardrailsResult = {
|
|
351
|
+
enabled: boolean;
|
|
352
|
+
allowed: boolean;
|
|
353
|
+
outcome: "allow" | "warn" | "block";
|
|
354
|
+
checks: Array<{
|
|
355
|
+
id: string;
|
|
356
|
+
mode: "warn" | "block";
|
|
357
|
+
result: "violation" | "inconclusive";
|
|
358
|
+
matches?: number;
|
|
359
|
+
}>;
|
|
360
|
+
revision: string;
|
|
214
361
|
};
|
|
215
362
|
|
|
216
363
|
export declare type PromteHandshakeState = "booting" | "waiting_for_settings" | "waiting_for_token" | "ready";
|
|
@@ -250,6 +397,10 @@ export declare type PromteSettings = {
|
|
|
250
397
|
backendUrl: string;
|
|
251
398
|
parentOrigin?: string;
|
|
252
399
|
user?: PromteUser;
|
|
400
|
+
/** Set by Promte pages that can send backend requests for the app. */
|
|
401
|
+
fetchProxy?: boolean;
|
|
402
|
+
/** False when governance turned file downloads from apps off. */
|
|
403
|
+
allowDownloads?: boolean;
|
|
253
404
|
};
|
|
254
405
|
|
|
255
406
|
export declare type PromteUser = {
|
|
@@ -257,6 +408,15 @@ export declare type PromteUser = {
|
|
|
257
408
|
isAdmin?: boolean;
|
|
258
409
|
role?: string;
|
|
259
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;
|
|
260
420
|
};
|
|
261
421
|
|
|
262
422
|
export declare type ReasoningEffort = "minimal" | "low" | "medium" | "high";
|
|
@@ -284,6 +444,31 @@ export declare type ScrapeUrlResponse = {
|
|
|
284
444
|
};
|
|
285
445
|
};
|
|
286
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
|
+
|
|
287
472
|
export declare type TranslatorLiveShareLine = {
|
|
288
473
|
id: string;
|
|
289
474
|
speaker: string;
|
|
@@ -303,6 +488,40 @@ export declare type TranslatorLiveShareSnapshot = {
|
|
|
303
488
|
|
|
304
489
|
export declare function usePromte(): PromteCtxValue;
|
|
305
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
|
+
|
|
306
525
|
export declare function usePromteClient(): PromteClient;
|
|
307
526
|
|
|
308
527
|
export declare function usePromteDarkMode(): boolean;
|
|
@@ -320,6 +539,10 @@ export declare type UsePromteModelsOptions = PromteModelsRequest & {
|
|
|
320
539
|
|
|
321
540
|
export declare function usePromteSettings(): PromteSettings;
|
|
322
541
|
|
|
542
|
+
/**
|
|
543
|
+
* @deprecated Promte sends backend requests for the app and no longer gives
|
|
544
|
+
* the app a token, so this returns null inside current Promte versions.
|
|
545
|
+
*/
|
|
323
546
|
export declare function usePromteToken(): string;
|
|
324
547
|
|
|
325
548
|
export declare function usePromteUser(): PromteUser;
|