@assistant-ui/appos 0.0.0-stage → 0.0.2
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/LICENSE +21 -0
- package/dist/chunks/ai-call.js +71 -0
- package/dist/chunks/ai-sdk.js +66 -0
- package/dist/chunks/src.js +1468 -0
- package/dist/index.js +1662 -0
- package/dist/next-page.js +150 -0
- package/dist/next-runtime.js +102 -0
- package/dist/next-server.js +50 -0
- package/dist/next.js +215 -0
- package/dist/pack.js +112 -0
- package/dist/server.js +77 -0
- package/dist/types/packages/appos-client/src/ai-sdk.d.ts +7 -0
- package/dist/types/packages/appos-client/src/index.d.ts +661 -0
- package/dist/types/packages/appos-client/src/theme.d.ts +16 -0
- package/dist/types/packages/appos-client/src/update-text.d.ts +13 -0
- package/dist/types/packages/appos-host/src/AppOSApp.d.ts +20 -0
- package/dist/types/packages/appos-host/src/ai-call.d.ts +31 -0
- package/dist/types/packages/appos-host/src/ai.d.ts +61 -0
- package/dist/types/packages/appos-host/src/embed.d.ts +119 -0
- package/dist/types/packages/appos-host/src/index.d.ts +6 -0
- package/dist/types/packages/appos-host/src/next/adapter.d.ts +43 -0
- package/dist/types/packages/appos-host/src/next/page.d.ts +1 -0
- package/dist/types/packages/appos-host/src/next/routes.d.ts +2 -0
- package/dist/types/packages/appos-host/src/next/runtime.d.ts +11 -0
- package/dist/types/packages/appos-host/src/next/server.d.ts +22 -0
- package/dist/types/packages/appos-host/src/pack.d.ts +16 -0
- package/dist/types/packages/appos-host/src/server.d.ts +23 -0
- package/dist/types/src/lib/ai-spend.d.ts +51 -0
- package/dist/types/src/lib/bundle-meta.d.ts +13 -0
- package/dist/types/src/lib/color-scheme.d.ts +17 -0
- package/dist/types/src/lib/external-link.d.ts +5 -0
- package/dist/types/src/lib/frame-pinch.d.ts +6 -0
- package/dist/types/src/lib/pack.d.ts +17 -0
- package/dist/types/src/lib/swbn/cbor.d.ts +16 -0
- package/dist/types/src/lib/swbn/identity.d.ts +121 -0
- package/dist/types/src/lib/swbn/integrity.d.ts +51 -0
- package/dist/types/src/lib/swbn/keys.d.ts +25 -0
- package/dist/types/src/lib/swbn/manifest.d.ts +144 -0
- package/dist/types/src/lib/swbn/release.d.ts +39 -0
- package/package.json +43 -4
- package/README.md +0 -3
|
@@ -0,0 +1,661 @@
|
|
|
1
|
+
export { theme, type ColorScheme } from "./theme";
|
|
2
|
+
export declare class CloudError extends Error {
|
|
3
|
+
readonly code: string;
|
|
4
|
+
readonly status: number;
|
|
5
|
+
readonly details: Record<string, unknown>;
|
|
6
|
+
constructor(code: string, message: string, status?: number, details?: Record<string, unknown>);
|
|
7
|
+
}
|
|
8
|
+
/** What is selected in an app (appos.setSelection): the words, and where they are. */
|
|
9
|
+
export interface Selection {
|
|
10
|
+
/** Where the text is: the file's address, or the app's own link to the document in it. No spaces. */
|
|
11
|
+
address: string;
|
|
12
|
+
/** The first and last line of it there, counting from 1. */
|
|
13
|
+
lines?: [number, number];
|
|
14
|
+
text: string;
|
|
15
|
+
}
|
|
16
|
+
/** What is selected in the app that shows this page, with that app as the shell names it (appos.onSelection). */
|
|
17
|
+
export interface EmbeddedSelection extends Selection {
|
|
18
|
+
app: {
|
|
19
|
+
did: string;
|
|
20
|
+
name: string;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The file this frame runs: one instance of the app. Local live files of one
|
|
25
|
+
* app share its origin's storage, so keep each one's data under its id.
|
|
26
|
+
* The primary live file (the app's first) owns what the origin held before
|
|
27
|
+
* live files existed. A cloud live file is a LiveWorker someone shared: open it with
|
|
28
|
+
* appos.liveWorkers.open(liveFile.actor).
|
|
29
|
+
*/
|
|
30
|
+
/** One file in appos.files.all(): where it is and what it is, never its data. */
|
|
31
|
+
export interface IndexedFile {
|
|
32
|
+
key: string;
|
|
33
|
+
title: string;
|
|
34
|
+
/** `ext`: the app's appos.extension, shown after the name; never part of it. */
|
|
35
|
+
app: {
|
|
36
|
+
did: string;
|
|
37
|
+
name: string;
|
|
38
|
+
icon?: string;
|
|
39
|
+
ext?: string;
|
|
40
|
+
};
|
|
41
|
+
/** "device", "cloud" or a host's name. */
|
|
42
|
+
host: string;
|
|
43
|
+
hostLabel: string;
|
|
44
|
+
/** Where it is stored, in words. */
|
|
45
|
+
location: string;
|
|
46
|
+
size?: number;
|
|
47
|
+
/** When it was last opened on this device. */
|
|
48
|
+
at?: number;
|
|
49
|
+
shared?: true;
|
|
50
|
+
/** A workspace: how many files it names. */
|
|
51
|
+
workspace?: number;
|
|
52
|
+
/** Its app isn't on this device yet: opening the file gets it. */
|
|
53
|
+
install?: true;
|
|
54
|
+
/** Open to the web (appos.requestOpenWeb()); the Files app closes it with appos.files.closeOpenWeb(key). */
|
|
55
|
+
openWeb?: true;
|
|
56
|
+
/** The user's role in it, when its host says. The owner renames, moves, shares and deletes it. */
|
|
57
|
+
role?: "owner" | "editor" | "viewer";
|
|
58
|
+
/** The folder it is in on its host, by id; at the top when absent. */
|
|
59
|
+
folder?: string;
|
|
60
|
+
/** Its address, for whoever may open it: <host>/<owner's handle>/<folders>/<name>.<ext>. */
|
|
61
|
+
url?: string;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* One of this app's own files (appos.files.list(), appos.files.recent()): what it is and where, never its data. Open
|
|
65
|
+
* it with appos.files.open(file.address).
|
|
66
|
+
*/
|
|
67
|
+
export interface AppFile {
|
|
68
|
+
name: string;
|
|
69
|
+
/** Its folder's path on its host ("Work/Plans"); "" at the top, and for a file someone shared with the person. */
|
|
70
|
+
folder: string;
|
|
71
|
+
/** Where it is, as people read it: "appOS cloud", "This device" or a host's name. */
|
|
72
|
+
host: string;
|
|
73
|
+
/** When it last changed (ms), to the minute, when its host keeps that (the appOS cloud does). */
|
|
74
|
+
updatedAt?: number;
|
|
75
|
+
/** When the person last opened it on this device (ms). */
|
|
76
|
+
openedAt?: number;
|
|
77
|
+
/** Someone besides its owner is in it, it is someone else's, or it is shared by link. */
|
|
78
|
+
shared: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Its address (https://<host>/<owner's handle>/<folders>/<name>.<ext>), which changes when it is renamed or moved;
|
|
81
|
+
* or, for a file without one yet (on another host, or on this device), a stand-in only appos.files.open() takes.
|
|
82
|
+
*/
|
|
83
|
+
address: string;
|
|
84
|
+
}
|
|
85
|
+
/** A folder on a host (appos.files.all()). `parent` is "" at the top. */
|
|
86
|
+
export interface IndexedFolder {
|
|
87
|
+
id: string;
|
|
88
|
+
host: string;
|
|
89
|
+
name: string;
|
|
90
|
+
parent: string;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* appos.files.all(): every host (this device first), every file and the hosts' folders. A host with `folders`
|
|
94
|
+
* keeps folders and names; one with `trash` moves a deleted file to Trash.
|
|
95
|
+
*/
|
|
96
|
+
export interface FileIndex {
|
|
97
|
+
hosts: {
|
|
98
|
+
id: string;
|
|
99
|
+
label: string;
|
|
100
|
+
folders?: true;
|
|
101
|
+
trash?: true;
|
|
102
|
+
}[];
|
|
103
|
+
files: IndexedFile[];
|
|
104
|
+
folders: IndexedFolder[];
|
|
105
|
+
}
|
|
106
|
+
/** A file in Trash (appos.files.trash()): deleted for good at `purgeAt`. */
|
|
107
|
+
export interface TrashedFile {
|
|
108
|
+
key: string;
|
|
109
|
+
title: string;
|
|
110
|
+
app: {
|
|
111
|
+
did: string;
|
|
112
|
+
name: string;
|
|
113
|
+
icon?: string;
|
|
114
|
+
};
|
|
115
|
+
host: string;
|
|
116
|
+
deleted: number;
|
|
117
|
+
purgeAt: number;
|
|
118
|
+
}
|
|
119
|
+
export interface LiveFile {
|
|
120
|
+
id: string;
|
|
121
|
+
kind: "local" | "cloud";
|
|
122
|
+
primary: boolean;
|
|
123
|
+
/** A cloud live file: its LiveWorker's id (the wire name is still `actor`). */
|
|
124
|
+
actor?: string;
|
|
125
|
+
/** A workspace (appos.multiple): the LiveWorkers it names, on any hosts. Open each and merge them. */
|
|
126
|
+
actors?: string[];
|
|
127
|
+
title?: string;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* appos.files.open(): the shell's file picker. This app's files on every host the user is signed in to, and New (on
|
|
131
|
+
* the host the user picks). Resolves to what the user picked or made, or null when they cancelled. Apps with
|
|
132
|
+
* appos.multiple may ask for several; the shell saves them as a workspace. `kind`: one of the app's LiveWorker
|
|
133
|
+
* classes; the sheet lists and makes only files of it. Each file shows the name its LiveWorker's title() method
|
|
134
|
+
* gives, when it has one.
|
|
135
|
+
*
|
|
136
|
+
* appos.files.open(address): opens one of this app's own files (an `address` from appos.files.list() or recent())
|
|
137
|
+
* in its own tab, as Recent files does, once the shell finds it among this app's files the person can reach. Rejects
|
|
138
|
+
* with CloudError "no-file" for any other address: another app's file, one they can't reach, or nothing.
|
|
139
|
+
*/
|
|
140
|
+
declare function openFiles(address: string): Promise<void>;
|
|
141
|
+
declare function openFiles(options?: {
|
|
142
|
+
multiple?: boolean;
|
|
143
|
+
kind?: string;
|
|
144
|
+
}): Promise<{
|
|
145
|
+
ids: string[];
|
|
146
|
+
workspace?: string;
|
|
147
|
+
} | null>;
|
|
148
|
+
/**
|
|
149
|
+
* Shows the page at `path` of the app with DID `app` in `slot`, a box of this page's that is the page's place: as wide
|
|
150
|
+
* as the slot, and as tall as the page's content (the slot's height is set to it). The shell runs the page as a frame of
|
|
151
|
+
* its own app, laid over the slot, so it keeps its own storage, files and grants, and this page never reaches into it.
|
|
152
|
+
* The app has to list `path` in its manifest's appos.embeddable. `remove()` takes it away. Outside a shell, nothing.
|
|
153
|
+
*/
|
|
154
|
+
declare function embed(slot: HTMLElement, app: string, path: string): {
|
|
155
|
+
remove(): void;
|
|
156
|
+
};
|
|
157
|
+
/**
|
|
158
|
+
* Tells the pages this one shows (appos.embed) what is selected here, as it changes: the words, the address of what
|
|
159
|
+
* they are in, and their lines there. null: nothing is selected. Nothing comes back.
|
|
160
|
+
*/
|
|
161
|
+
declare function setSelection(selection: Selection | null): void;
|
|
162
|
+
/**
|
|
163
|
+
* For a page another app shows (appos.embed): `fn` hears what is selected in that app, now and each time it changes
|
|
164
|
+
* (null for nothing), with the app. Never called in a page no app shows. Returns the unsubscribe.
|
|
165
|
+
*/
|
|
166
|
+
declare function onSelection(fn: (selection: EmbeddedSelection | null) => void): () => void;
|
|
167
|
+
declare function ready(): Promise<{
|
|
168
|
+
version: string;
|
|
169
|
+
build?: number;
|
|
170
|
+
previousVersion?: string;
|
|
171
|
+
upgrade?: {
|
|
172
|
+
from: string;
|
|
173
|
+
to: string;
|
|
174
|
+
};
|
|
175
|
+
}>;
|
|
176
|
+
/** A small modal sheet inside the app's frame. */
|
|
177
|
+
export declare function showSheet(opts: {
|
|
178
|
+
title: string;
|
|
179
|
+
text: string;
|
|
180
|
+
actions?: {
|
|
181
|
+
label: string;
|
|
182
|
+
primary?: boolean;
|
|
183
|
+
run: () => void | Promise<void>;
|
|
184
|
+
}[];
|
|
185
|
+
dismissable?: boolean;
|
|
186
|
+
}): void;
|
|
187
|
+
/** Shows the built-in sheet for a cloud problem the user can act on (`liveWorkerPath`: the LiveWorker the call went to). */
|
|
188
|
+
export declare function explain(error: CloudError, liveWorkerPath?: string): void;
|
|
189
|
+
/**
|
|
190
|
+
* The app's backend. It has no URL: `fetch()` can't reach it, so a URL that
|
|
191
|
+
* came from anywhere (a link, a message, another site) never becomes a call
|
|
192
|
+
* to it. Paths name a LiveWorker and what to send it:
|
|
193
|
+
*
|
|
194
|
+
* /whoami
|
|
195
|
+
* /actors GET: the user's LiveWorkers; POST /actors/<Class>: a new one
|
|
196
|
+
* /actor/<id>/<path> one LiveWorker
|
|
197
|
+
*/
|
|
198
|
+
export declare const backend: {
|
|
199
|
+
/** Sends a request to the backend; resolves to its streamed response. */
|
|
200
|
+
fetch(input: string | Request, init?: RequestInit): Promise<Response>;
|
|
201
|
+
/** A WebSocket to the backend, relayed by the shell. */
|
|
202
|
+
connect(path: string, protocols?: string | string[]): Promise<BackendSocket>;
|
|
203
|
+
};
|
|
204
|
+
/** A WebSocket-like socket over the handle: send, close, open/message/close/error events. */
|
|
205
|
+
export declare class BackendSocket extends EventTarget {
|
|
206
|
+
#private;
|
|
207
|
+
private readonly port;
|
|
208
|
+
private readonly id;
|
|
209
|
+
static readonly CONNECTING = 0;
|
|
210
|
+
static readonly OPEN = 1;
|
|
211
|
+
static readonly CLOSING = 2;
|
|
212
|
+
static readonly CLOSED = 3;
|
|
213
|
+
readyState: number;
|
|
214
|
+
protocol: string;
|
|
215
|
+
binaryType: "arraybuffer";
|
|
216
|
+
onopen: ((e: Event) => void) | null;
|
|
217
|
+
onmessage: ((e: MessageEvent) => void) | null;
|
|
218
|
+
onclose: ((e: CloseEvent) => void) | null;
|
|
219
|
+
onerror: ((e: Event) => void) | null;
|
|
220
|
+
constructor(port: MessagePort, id: number);
|
|
221
|
+
send(data: string | ArrayBuffer | ArrayBufferView): void;
|
|
222
|
+
close(code?: number, reason?: string): void;
|
|
223
|
+
/** @internal */
|
|
224
|
+
_opened(protocol: string): void;
|
|
225
|
+
/** @internal */
|
|
226
|
+
_message(data: string | ArrayBuffer): void;
|
|
227
|
+
/** @internal */
|
|
228
|
+
_closed(code: number, reason: string, clean: boolean): void;
|
|
229
|
+
}
|
|
230
|
+
export type LiveWorkerRole = "owner" | "editor" | "viewer";
|
|
231
|
+
export interface LiveWorkerEntry {
|
|
232
|
+
id: string;
|
|
233
|
+
/** The LiveWorker's class, as appos.actors names it. */
|
|
234
|
+
name: string;
|
|
235
|
+
/** The signed-in user's role in it. */
|
|
236
|
+
role: LiveWorkerRole;
|
|
237
|
+
/** Opens the app on this LiveWorker, for people who hold a role in it. */
|
|
238
|
+
url?: string;
|
|
239
|
+
}
|
|
240
|
+
export interface LiveWorkerInfo {
|
|
241
|
+
id: string;
|
|
242
|
+
className: string;
|
|
243
|
+
owner: string;
|
|
244
|
+
isOwner: boolean;
|
|
245
|
+
/** The signed-in user's roles here. */
|
|
246
|
+
roles: LiveWorkerRole[];
|
|
247
|
+
/** The owner sees every grant: user → role. */
|
|
248
|
+
grants?: Record<string, "editor" | "viewer">;
|
|
249
|
+
running?: {
|
|
250
|
+
version: string;
|
|
251
|
+
build?: number;
|
|
252
|
+
hash: string;
|
|
253
|
+
};
|
|
254
|
+
/** A newer build a member asked for, waiting for the owner. */
|
|
255
|
+
pending?: {
|
|
256
|
+
version: string;
|
|
257
|
+
build?: number;
|
|
258
|
+
hash: string;
|
|
259
|
+
by: string;
|
|
260
|
+
denied: boolean;
|
|
261
|
+
};
|
|
262
|
+
/**
|
|
263
|
+
* Open to the web (appos.requestOpenWeb()): since when, and `url`, the file's address plus ".git", where git's smart
|
|
264
|
+
* HTTP reaches it from anywhere (no url while the file has no address yet); else null.
|
|
265
|
+
*/
|
|
266
|
+
openWeb?: {
|
|
267
|
+
url?: string;
|
|
268
|
+
since: number;
|
|
269
|
+
} | null;
|
|
270
|
+
}
|
|
271
|
+
/** A person in a LiveWorker, to show: never an email. */
|
|
272
|
+
export interface LiveWorkerProfile {
|
|
273
|
+
id: string;
|
|
274
|
+
role: LiveWorkerRole;
|
|
275
|
+
name?: string;
|
|
276
|
+
image?: string;
|
|
277
|
+
}
|
|
278
|
+
/** A connection to one LiveWorker: RPC, fetch and a live socket, each with the user's claims. */
|
|
279
|
+
export declare class LiveWorker {
|
|
280
|
+
readonly id: string;
|
|
281
|
+
readonly path: string;
|
|
282
|
+
/** The signed-in user's roles, as of open(). */
|
|
283
|
+
roles: LiveWorkerRole[];
|
|
284
|
+
constructor(id: string);
|
|
285
|
+
/** backend.fetch() to the LiveWorker's own fetch handler, at `sub` under it. Problems the user can act on get the SDK's sheets. */
|
|
286
|
+
fetch(sub?: string, init?: RequestInit): Promise<Response>;
|
|
287
|
+
/** Calls a method of the LiveWorker's class. Throws CloudError on failure. */
|
|
288
|
+
call<T = unknown>(method: string, ...args: unknown[]): Promise<T>;
|
|
289
|
+
/** A WebSocket to the LiveWorker's fetch handler. */
|
|
290
|
+
websocket(sub?: string, protocols?: string | string[]): Promise<BackendSocket>;
|
|
291
|
+
/**
|
|
292
|
+
* The owner and members to show: [{ id, role, name?, image? }]. `name` and
|
|
293
|
+
* `image` (an https avatar URL) come from each person's assistant-ui
|
|
294
|
+
* account; someone who never signed in to appOS has only id and role.
|
|
295
|
+
* The backend reads the same list with env.appos.profiles(). Cloud LiveWorkers only.
|
|
296
|
+
*/
|
|
297
|
+
profiles(): Promise<LiveWorkerProfile[]>;
|
|
298
|
+
/** Owner, roles, the build it runs. Shows the owner a newer build a member asked for (Approve / Deny). */
|
|
299
|
+
info(): Promise<LiveWorkerInfo>;
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* A link that opens this app on LiveWorker `id` and gives whoever opens it `role`
|
|
303
|
+
* (editor by default; viewers can share only as viewers). The app shows it
|
|
304
|
+
* in its own share sheet.
|
|
305
|
+
*/
|
|
306
|
+
declare function share(id: string, role?: "editor" | "viewer"): Promise<string>;
|
|
307
|
+
/**
|
|
308
|
+
* Opens appOS's Share sheet for LiveWorker `id`: the people on it with their role
|
|
309
|
+
* and the link each joined by, and, for its owner, the share links (new,
|
|
310
|
+
* copy, revoke). The same sheet for every app; resolves once it is shown.
|
|
311
|
+
*/
|
|
312
|
+
declare function openShare(id: string): Promise<void>;
|
|
313
|
+
/** What appOS tells the page when the person's role in a LiveWorker changed: role null once they lost access. */
|
|
314
|
+
export interface AccessChange {
|
|
315
|
+
actor: string;
|
|
316
|
+
role: LiveWorkerRole | null;
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Calls `fn` when appOS finds the signed-in person's access to a LiveWorker
|
|
320
|
+
* changed (revoked, or they left on another device). Returns an unsubscribe.
|
|
321
|
+
*/
|
|
322
|
+
declare function onAccess(fn: (change: AccessChange) => void): () => void;
|
|
323
|
+
export type LiveTextStatus = {
|
|
324
|
+
state: "connecting";
|
|
325
|
+
} | {
|
|
326
|
+
state: "live";
|
|
327
|
+
peers: number;
|
|
328
|
+
} | {
|
|
329
|
+
state: "offline";
|
|
330
|
+
message: string;
|
|
331
|
+
} | {
|
|
332
|
+
state: "error";
|
|
333
|
+
code: string;
|
|
334
|
+
message: string;
|
|
335
|
+
};
|
|
336
|
+
/** The text of the live file this frame runs, when it is shared by link (appos.liveText()). */
|
|
337
|
+
export declare class LiveText {
|
|
338
|
+
#private;
|
|
339
|
+
/** The link that opens this file, to copy and send. */
|
|
340
|
+
readonly url: string;
|
|
341
|
+
/** @internal */
|
|
342
|
+
constructor(port: MessagePort, url: string);
|
|
343
|
+
/** The file's text as this frame last saw it; undefined until loaded(). */
|
|
344
|
+
get data(): string | undefined;
|
|
345
|
+
get rev(): number;
|
|
346
|
+
get status(): LiveTextStatus;
|
|
347
|
+
/** Resolves with the file's text once the cloud has sent it. */
|
|
348
|
+
loaded(): Promise<string>;
|
|
349
|
+
/** Runs `fn` with the text whenever someone else changed the file. */
|
|
350
|
+
onChange(fn: (data: string) => void): () => void;
|
|
351
|
+
/** Runs `fn` when the connection changes (connecting, live with N people, offline). */
|
|
352
|
+
onStatus(fn: (s: LiveTextStatus) => void): () => void;
|
|
353
|
+
/** Replaces the file's text for everyone. Resent after a reconnect until the cloud confirms it. */
|
|
354
|
+
save(data: string): void;
|
|
355
|
+
/** True while a local write is not yet in the cloud. */
|
|
356
|
+
get saving(): boolean;
|
|
357
|
+
close(): void;
|
|
358
|
+
}
|
|
359
|
+
declare function liveText(): Promise<LiveText | undefined>;
|
|
360
|
+
/**
|
|
361
|
+
* Moves the file this frame runs to the appOS cloud as a live file holding
|
|
362
|
+
* `data` (text, at most 512 KB), and returns its link. Anyone with the link
|
|
363
|
+
* opens the file and edits it live; no sign-in. Already live: its link.
|
|
364
|
+
* Afterwards appos.liveText() connects to it.
|
|
365
|
+
*/
|
|
366
|
+
declare function shareFile(data: string): Promise<{
|
|
367
|
+
url: string;
|
|
368
|
+
created: boolean;
|
|
369
|
+
}>;
|
|
370
|
+
export type Capability = "ai" | "microphone";
|
|
371
|
+
export type PermissionState = "granted" | "denied" | "prompt";
|
|
372
|
+
export type StreamPart = {
|
|
373
|
+
type: string;
|
|
374
|
+
[k: string]: unknown;
|
|
375
|
+
};
|
|
376
|
+
/**
|
|
377
|
+
* One AI call to the shell (the "appos:ai" port): AI SDK LanguageModelV4
|
|
378
|
+
* call options in (prompt, tools, maxOutputTokens…; no headers or signal),
|
|
379
|
+
* its stream parts out. `model` is a hint: the provider the user set up
|
|
380
|
+
* decides. Errors with code "not-configured" mean no AI is set up; offer
|
|
381
|
+
* appos.openSettings(). The AI SDK model on top is appos-client/ai-sdk.
|
|
382
|
+
*/
|
|
383
|
+
export declare function aiCall(options: Record<string, unknown>, model?: string, signal?: AbortSignal): ReadableStream<StreamPart>;
|
|
384
|
+
/** Text deltas for one prompt: `for await (const t of appos.ai.stream({ prompt: "Hi" }))`. */
|
|
385
|
+
declare function aiStream(opts: {
|
|
386
|
+
prompt: string;
|
|
387
|
+
system?: string;
|
|
388
|
+
model?: string;
|
|
389
|
+
maxOutputTokens?: number;
|
|
390
|
+
}): AsyncGenerator<string>;
|
|
391
|
+
export type VoiceEvent = {
|
|
392
|
+
event: "listening";
|
|
393
|
+
provider: string;
|
|
394
|
+
onDevice: boolean;
|
|
395
|
+
downloading?: boolean;
|
|
396
|
+
} | {
|
|
397
|
+
event: "level";
|
|
398
|
+
level: number;
|
|
399
|
+
} | {
|
|
400
|
+
event: "partial";
|
|
401
|
+
text: string;
|
|
402
|
+
start: number;
|
|
403
|
+
} | {
|
|
404
|
+
event: "final";
|
|
405
|
+
text: string;
|
|
406
|
+
start: number;
|
|
407
|
+
end: number;
|
|
408
|
+
speaker?: number;
|
|
409
|
+
} | {
|
|
410
|
+
event: "error";
|
|
411
|
+
code: string;
|
|
412
|
+
message: string;
|
|
413
|
+
} | {
|
|
414
|
+
event: "end";
|
|
415
|
+
};
|
|
416
|
+
/**
|
|
417
|
+
* Live transcription. The shell holds the mic and the provider; the app gets
|
|
418
|
+
* text. Times are seconds since listening started. Ends with an "end" event
|
|
419
|
+
* (after an "error" one when it failed).
|
|
420
|
+
*/
|
|
421
|
+
declare function transcribe(options: {
|
|
422
|
+
language?: string;
|
|
423
|
+
keyterms?: string[];
|
|
424
|
+
}, onEvent: (e: VoiceEvent) => void): {
|
|
425
|
+
stop(): void;
|
|
426
|
+
ended: Promise<void>;
|
|
427
|
+
};
|
|
428
|
+
export declare const appos: {
|
|
429
|
+
/** The app's backend: backend.fetch(path), backend.connect(path). No URL reaches it. */
|
|
430
|
+
backend: {
|
|
431
|
+
/** Sends a request to the backend; resolves to its streamed response. */
|
|
432
|
+
fetch(input: string | Request, init?: RequestInit): Promise<Response>;
|
|
433
|
+
/** A WebSocket to the backend, relayed by the shell. */
|
|
434
|
+
connect(path: string, protocols?: string | string[]): Promise<BackendSocket>;
|
|
435
|
+
};
|
|
436
|
+
/** The app's LiveWorkers: create, open, list, grant, revoke, launched (appos.actors in the manifest). */
|
|
437
|
+
liveWorkers: {
|
|
438
|
+
/**
|
|
439
|
+
* A new LiveWorker of class `name`, owned by the user, on their default host.
|
|
440
|
+
* `host` says where it went: "cloud" or the host's name.
|
|
441
|
+
*/
|
|
442
|
+
create(name: string): Promise<LiveWorkerEntry & {
|
|
443
|
+
url: string;
|
|
444
|
+
host: string;
|
|
445
|
+
}>;
|
|
446
|
+
/** A connection to a LiveWorker the user holds a role in. Rejects with "not-member" otherwise. */
|
|
447
|
+
open(id: string): Promise<LiveWorker>;
|
|
448
|
+
/** The LiveWorkers the user owns or holds a role in, on every host. */
|
|
449
|
+
list(): Promise<LiveWorkerEntry[]>;
|
|
450
|
+
/** Owner only: gives `user` a role in LiveWorker `id`. */
|
|
451
|
+
/** Owner only: gives `user` (their appOS ID) a role in LiveWorker `id`. */
|
|
452
|
+
grant(id: string, user: string, role: "editor" | "viewer"): Promise<void>;
|
|
453
|
+
/** Owner only: takes `user`'s role in LiveWorker `id` away. */
|
|
454
|
+
revoke(id: string, user: string): Promise<void>;
|
|
455
|
+
/**
|
|
456
|
+
* The LiveWorker a share link opened this app on, joined with the link's key
|
|
457
|
+
* (once per launch). Undefined when the app was not opened from one.
|
|
458
|
+
*/
|
|
459
|
+
launched(): Promise<LiveWorker | undefined>;
|
|
460
|
+
};
|
|
461
|
+
/** A share link to a LiveWorker for a role: share(id, "viewer"). */
|
|
462
|
+
share: typeof share;
|
|
463
|
+
/** appOS's Share sheet for a LiveWorker: openShare(id). */
|
|
464
|
+
openShare: typeof openShare;
|
|
465
|
+
/** Hears when the person's access to a LiveWorker changed: onAccess(({ LiveWorker, role }) => …). */
|
|
466
|
+
onAccess: typeof onAccess;
|
|
467
|
+
/** { version, previousVersion }: previousVersion only on the first launch after an update. */
|
|
468
|
+
ready: typeof ready;
|
|
469
|
+
/** This build's manifest version (after ready()). */
|
|
470
|
+
readonly version: string | undefined;
|
|
471
|
+
/** This build's appos.build, if the app has builds (after ready()). */
|
|
472
|
+
readonly build: number | undefined;
|
|
473
|
+
/**
|
|
474
|
+
* Asks the shell for this app's newest build now (the app's server said it
|
|
475
|
+
* is too old, or the app came back into view): the shell checks the app's
|
|
476
|
+
* update feed and applies what it lists at once, relaunching this frame.
|
|
477
|
+
* Answers when there was nothing to apply ("none"), or the check failed.
|
|
478
|
+
*/
|
|
479
|
+
checkForUpdate(): Promise<{
|
|
480
|
+
status: string;
|
|
481
|
+
version?: string;
|
|
482
|
+
build?: number;
|
|
483
|
+
error?: string;
|
|
484
|
+
}>;
|
|
485
|
+
/**
|
|
486
|
+
* What this origin ran before, on the first launch after an update (after
|
|
487
|
+
* ready()): the version, or "0.0.1 (12)" for apps with builds.
|
|
488
|
+
*/
|
|
489
|
+
readonly previousVersion: string | undefined;
|
|
490
|
+
/** Runs once, on the first launch after an update: migrate local data here. */
|
|
491
|
+
onUpgrade(fn: (from: string, to: string) => void | Promise<void>): void;
|
|
492
|
+
/**
|
|
493
|
+
* The data a file link opened this app with (/a/<did>/<name>#d=<data>),
|
|
494
|
+
* the first time it is asked: base64url text in the app's own format. The
|
|
495
|
+
* file is local and the link reopens it, so fill the file only when it is
|
|
496
|
+
* new. It came from a link: treat it as untrusted input.
|
|
497
|
+
*/
|
|
498
|
+
launchData(): string | undefined;
|
|
499
|
+
/**
|
|
500
|
+
* The live file this frame runs, connected: load with loaded(), write with
|
|
501
|
+
* save(), hear others with onChange(). Undefined when the file is not live
|
|
502
|
+
* (see shareFile()).
|
|
503
|
+
*/
|
|
504
|
+
liveText: typeof liveText;
|
|
505
|
+
/** Moves this frame's file to the cloud as a live file; resolves to its link. */
|
|
506
|
+
shareFile: typeof shareFile;
|
|
507
|
+
/** The live file this frame runs; undefined in appOS from before live files. */
|
|
508
|
+
liveFile(): Promise<LiveFile | undefined>;
|
|
509
|
+
/** The person's files of this app: the shell's Open and New dialogs, and this app's own list of them. */
|
|
510
|
+
files: {
|
|
511
|
+
/** The shell's Open dialog, or with an address, one of this app's own files in its tab (see openFiles). */
|
|
512
|
+
open: typeof openFiles;
|
|
513
|
+
/**
|
|
514
|
+
* This app's files the person owns or that are shared with them, on every host the shell is signed in to and this
|
|
515
|
+
* device, by name: what each is and where, never its data. Only this app's own type: other apps' files come only
|
|
516
|
+
* through the shell's Open dialog. `folder`: only those in that folder ("" the top, "Work/Plans" deeper).
|
|
517
|
+
*/
|
|
518
|
+
list({ folder }?: {
|
|
519
|
+
folder?: string;
|
|
520
|
+
}): Promise<AppFile[]>;
|
|
521
|
+
/** This app's files the person opened on this device lately, newest first: `limit` of them (10; at most 50). */
|
|
522
|
+
recent({ limit }?: {
|
|
523
|
+
limit?: number;
|
|
524
|
+
}): Promise<AppFile[]>;
|
|
525
|
+
/**
|
|
526
|
+
* The shell's New dialog: the user picks a host, a folder and a name, and the shell makes a file of this app
|
|
527
|
+
* there (of `kind`, one of the app's LiveWorker classes, when given). Resolves to its LiveWorker id (open it with
|
|
528
|
+
* appos.liveWorkers.open(id)), or null when the user cancelled. The app never sees the user's other files.
|
|
529
|
+
*/
|
|
530
|
+
create({ kind }?: {
|
|
531
|
+
kind?: string;
|
|
532
|
+
}): Promise<{
|
|
533
|
+
id: string;
|
|
534
|
+
} | null>;
|
|
535
|
+
/**
|
|
536
|
+
* The Files app only (did:web:appos.assistant-ui.workers.dev:apps:files):
|
|
537
|
+
* every file of every app, on this device and every host, read-only:
|
|
538
|
+
* where each is, never its data. Other apps get CloudError "forbidden".
|
|
539
|
+
*/
|
|
540
|
+
all(): Promise<FileIndex>;
|
|
541
|
+
/** The Files app only: opens a file all() listed in its own app, in a tab. */
|
|
542
|
+
openInApp(key: string): Promise<void>;
|
|
543
|
+
/** The Files app only: closes a file all() listed as openWeb to the web. */
|
|
544
|
+
closeOpenWeb(key: string): Promise<void>;
|
|
545
|
+
/**
|
|
546
|
+
* The Files app only: renames a file. Names are unique in a folder by name alone; a taken one rejects with
|
|
547
|
+
* CloudError "name-taken". Resolves to the name it has now.
|
|
548
|
+
*/
|
|
549
|
+
rename(key: string, name: string): Promise<string>;
|
|
550
|
+
/** The Files app only: moves a file into a folder on its host ("" for the top). */
|
|
551
|
+
move(key: string, folder: string): Promise<void>;
|
|
552
|
+
/**
|
|
553
|
+
* The Files app only: deletes a file. Its owner's goes to Trash where its host has one ("trash") and for good
|
|
554
|
+
* elsewhere ("delete"); anyone else's leaves their view on this device ("remove") and stays for its owner.
|
|
555
|
+
*/
|
|
556
|
+
delete(key: string): Promise<"trash" | "delete" | "remove">;
|
|
557
|
+
/** The Files app only: opens the shell's Share sheet on a file (its people, roles and links). */
|
|
558
|
+
share(key: string): Promise<void>;
|
|
559
|
+
/** The Files app only: the files in Trash, newest first. */
|
|
560
|
+
trash(): Promise<TrashedFile[]>;
|
|
561
|
+
/** The Files app only: back from Trash, in its folder (or at the top), its name suffixed if it was taken. */
|
|
562
|
+
restore(key: string): Promise<void>;
|
|
563
|
+
/** The Files app only: deletes a file in Trash for good, for everyone. */
|
|
564
|
+
purge(key: string): Promise<void>;
|
|
565
|
+
/** The Files app only: the shell's New dialog at a host and folder; the user picks the app. The file opens in it. */
|
|
566
|
+
newFile(host: string, folder?: string): Promise<boolean>;
|
|
567
|
+
/** The Files app only: deletes every file in Trash for good. */
|
|
568
|
+
emptyTrash(): Promise<void>;
|
|
569
|
+
/** The Files app only: a host's folders. Folders only organize; sharing is per file. */
|
|
570
|
+
folders: {
|
|
571
|
+
create(host: string, name: string, parent?: string): Promise<IndexedFolder>;
|
|
572
|
+
rename(host: string, id: string, name: string): Promise<IndexedFolder>;
|
|
573
|
+
move(host: string, id: string, parent: string): Promise<IndexedFolder>;
|
|
574
|
+
/** An empty folder only (CloudError "not-empty" otherwise). */
|
|
575
|
+
delete(host: string, id: string): Promise<void>;
|
|
576
|
+
};
|
|
577
|
+
};
|
|
578
|
+
/**
|
|
579
|
+
* Makes a new file of this app and opens it in its own tab: through the shell's New dialog (host, folder, name)
|
|
580
|
+
* when the app has LiveWorkers, else on this device. Null when the user cancelled the dialog.
|
|
581
|
+
*/
|
|
582
|
+
newLiveFile(): Promise<{
|
|
583
|
+
id: string;
|
|
584
|
+
kind: "local" | "cloud";
|
|
585
|
+
} | null>;
|
|
586
|
+
/**
|
|
587
|
+
* Opens another of this app's files (its id from liveFile()) in its own tab, as App info does: an app that
|
|
588
|
+
* lists its own files opens one this way. Rejects with CloudError "no-file" for an id that isn't this app's.
|
|
589
|
+
*/
|
|
590
|
+
openLiveFile(id: string): Promise<void>;
|
|
591
|
+
/**
|
|
592
|
+
* Asks appOS to open the file this frame runs (a LiveWorker in the appOS cloud) to the open web, for an app whose
|
|
593
|
+
* manifest declares appos.openWeb. appOS shows its own prompt to the file's owner; the app never sets it. Answers
|
|
594
|
+
* { open: true, url } (already open: no prompt), or { open: false } when the owner said no. `url` is the file's
|
|
595
|
+
* address plus ".git" (none while the file has no address yet): git's smart HTTP there (`<url>/info/refs`,
|
|
596
|
+
* `/git-upload-pack`, `/git-receive-pack`) reaches the LiveWorker's fetch() at that route, with no user the platform
|
|
597
|
+
* vouches for (caller() is { roles: [], web: true }) and Authorization untouched: the app checks who they are. Every
|
|
598
|
+
* refusal there answers as an address that names nothing. The owner closes it in App info or the Files app.
|
|
599
|
+
*/
|
|
600
|
+
requestOpenWeb(): Promise<{
|
|
601
|
+
open: boolean;
|
|
602
|
+
url?: string;
|
|
603
|
+
}>;
|
|
604
|
+
/**
|
|
605
|
+
* Local live files the user deleted since the app last ran: delete their data
|
|
606
|
+
* (it shares this origin). Called once per launch with the ids.
|
|
607
|
+
*/
|
|
608
|
+
onLiveFileRemoved(fn: (ids: string[]) => void | Promise<void>): void;
|
|
609
|
+
/** Names the app in the SDK's sheets. */
|
|
610
|
+
setName(name: string): void;
|
|
611
|
+
/** Names the file this frame runs, as Home and the tab show it. */
|
|
612
|
+
setTitle(title: string): Promise<void>;
|
|
613
|
+
/**
|
|
614
|
+
* A count for the shell to show on this app's tile or tab (unread items, say); 0 clears it. A whole number,
|
|
615
|
+
* 0 or more. Nothing comes back, and a shell may show it or ignore it (appOS itself doesn't show it yet).
|
|
616
|
+
* Outside a shell it does nothing.
|
|
617
|
+
*/
|
|
618
|
+
setBadge(count: number): void;
|
|
619
|
+
/** Another app's page in this one: embed(slot, did, path); see appos.embeddable in that app's manifest. */
|
|
620
|
+
embed: typeof embed;
|
|
621
|
+
/** What is selected here, for the pages this one shows: setSelection({ address, lines?, text }) or null. */
|
|
622
|
+
setSelection: typeof setSelection;
|
|
623
|
+
/** In a page another app shows: what is selected in that app, now and as it changes. */
|
|
624
|
+
onSelection: typeof onSelection;
|
|
625
|
+
/**
|
|
626
|
+
* How many CSS px of the shell's own chrome (a host page's mark, say) cover the start of the app's header, from
|
|
627
|
+
* the shell's hello: pad the header's start by it. 0 when the shell says nothing (appOS itself) or outside a shell.
|
|
628
|
+
*/
|
|
629
|
+
markSpace(): Promise<number>;
|
|
630
|
+
/**
|
|
631
|
+
* Opens a web page (https) as a new top-level page with no opener: sign-in pages, docs, anything outside the
|
|
632
|
+
* app. Call it from the tap or click itself. A popup the app's sandboxed frame opens inherits the sandbox,
|
|
633
|
+
* and browsers won't show pages that send Cross-Origin-Opener-Policy there; the shell opens it instead.
|
|
634
|
+
* Outside appOS it opens the page itself.
|
|
635
|
+
*/
|
|
636
|
+
openExternal(url: string): Promise<void>;
|
|
637
|
+
/** Opens appOS Settings (AI & voice, permissions), e.g. after a "not-configured" error. */
|
|
638
|
+
openSettings(): Promise<void>;
|
|
639
|
+
permissions: {
|
|
640
|
+
/** The grant now: "prompt" until the user has answered. */
|
|
641
|
+
query(cap: Capability): Promise<PermissionState>;
|
|
642
|
+
/** Asks the user (the shell's prompt) if they never have; the answer is remembered per app. */
|
|
643
|
+
request(cap: Capability): Promise<PermissionState>;
|
|
644
|
+
};
|
|
645
|
+
/** Language models through the shell (the "ai" capability). */
|
|
646
|
+
/** Text deltas for one prompt. For the AI SDK, use apposModel() from appos-client/ai-sdk. */
|
|
647
|
+
ai: {
|
|
648
|
+
stream: typeof aiStream;
|
|
649
|
+
};
|
|
650
|
+
/** Live transcription through the shell (the "microphone" capability). */
|
|
651
|
+
voice: {
|
|
652
|
+
transcribe: typeof transcribe;
|
|
653
|
+
};
|
|
654
|
+
/** Light or dark, from the shell: get(), onChange(fn), autoApply(false). Applied to <html> by default. */
|
|
655
|
+
theme: {
|
|
656
|
+
get: () => import("./theme").ColorScheme;
|
|
657
|
+
onChange: (fn: (scheme: import("./theme").ColorScheme) => void) => () => void;
|
|
658
|
+
autoApply: (on: boolean) => void;
|
|
659
|
+
};
|
|
660
|
+
};
|
|
661
|
+
export default appos;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type ColorScheme = "light" | "dark";
|
|
2
|
+
declare function get(): ColorScheme;
|
|
3
|
+
/** Calls `fn` with the new scheme on every change. Returns an unsubscribe. */
|
|
4
|
+
declare function onChange(fn: (scheme: ColorScheme) => void): () => void;
|
|
5
|
+
/**
|
|
6
|
+
* Whether the SDK keeps <html>'s "dark" class and color-scheme in step
|
|
7
|
+
* (default true). false leaves them as they are: style from get() and
|
|
8
|
+
* onChange() yourself. Same as <html data-appos-theme="manual">.
|
|
9
|
+
*/
|
|
10
|
+
declare function autoApply(on: boolean): void;
|
|
11
|
+
export declare const theme: {
|
|
12
|
+
get: typeof get;
|
|
13
|
+
onChange: typeof onChange;
|
|
14
|
+
autoApply: typeof autoApply;
|
|
15
|
+
};
|
|
16
|
+
export {};
|