@assistant-ui/appos 0.0.0-stage → 0.0.1

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.
Files changed (41) hide show
  1. package/LICENSE +21 -0
  2. package/dist/chunks/ai-call.js +71 -0
  3. package/dist/chunks/ai-sdk.js +66 -0
  4. package/dist/chunks/src.js +1174 -0
  5. package/dist/index.js +1618 -0
  6. package/dist/next-page.js +150 -0
  7. package/dist/next-runtime.js +102 -0
  8. package/dist/next-server.js +50 -0
  9. package/dist/next.js +215 -0
  10. package/dist/pack.js +107 -0
  11. package/dist/server.js +77 -0
  12. package/dist/types/packages/appos-client/src/ai-sdk.d.ts +7 -0
  13. package/dist/types/packages/appos-client/src/index.d.ts +467 -0
  14. package/dist/types/packages/appos-client/src/theme.d.ts +16 -0
  15. package/dist/types/packages/appos-client/src/update-text.d.ts +13 -0
  16. package/dist/types/packages/appos-host/src/AppOSApp.d.ts +20 -0
  17. package/dist/types/packages/appos-host/src/ai-call.d.ts +31 -0
  18. package/dist/types/packages/appos-host/src/ai.d.ts +61 -0
  19. package/dist/types/packages/appos-host/src/embed.d.ts +119 -0
  20. package/dist/types/packages/appos-host/src/index.d.ts +6 -0
  21. package/dist/types/packages/appos-host/src/next/adapter.d.ts +43 -0
  22. package/dist/types/packages/appos-host/src/next/page.d.ts +1 -0
  23. package/dist/types/packages/appos-host/src/next/routes.d.ts +2 -0
  24. package/dist/types/packages/appos-host/src/next/runtime.d.ts +11 -0
  25. package/dist/types/packages/appos-host/src/next/server.d.ts +22 -0
  26. package/dist/types/packages/appos-host/src/pack.d.ts +16 -0
  27. package/dist/types/packages/appos-host/src/server.d.ts +23 -0
  28. package/dist/types/src/lib/ai-spend.d.ts +51 -0
  29. package/dist/types/src/lib/bundle-meta.d.ts +13 -0
  30. package/dist/types/src/lib/color-scheme.d.ts +17 -0
  31. package/dist/types/src/lib/external-link.d.ts +5 -0
  32. package/dist/types/src/lib/frame-pinch.d.ts +6 -0
  33. package/dist/types/src/lib/pack.d.ts +17 -0
  34. package/dist/types/src/lib/swbn/cbor.d.ts +16 -0
  35. package/dist/types/src/lib/swbn/identity.d.ts +121 -0
  36. package/dist/types/src/lib/swbn/integrity.d.ts +51 -0
  37. package/dist/types/src/lib/swbn/keys.d.ts +25 -0
  38. package/dist/types/src/lib/swbn/manifest.d.ts +106 -0
  39. package/dist/types/src/lib/swbn/release.d.ts +39 -0
  40. package/package.json +43 -4
  41. package/README.md +0 -3
package/dist/server.js ADDED
@@ -0,0 +1,77 @@
1
+ import { i as sanitizeAiOptions, n as plainAiError, r as plainPart, t as AiError } from "./chunks/ai-call.js";
2
+ // packages/appos-host/src/server.ts
3
+ /** A failed call as the embed reads it: { error: { code, message } }. */
4
+ function aiErrorResponse(status, code, message, headers) {
5
+ const h = new Headers(headers);
6
+ h.set("content-type", "application/json");
7
+ h.set("cache-control", "no-store");
8
+ return new Response(JSON.stringify({ error: {
9
+ code,
10
+ message
11
+ } }), {
12
+ status,
13
+ headers: h
14
+ });
15
+ }
16
+ /**
17
+ * Runs one AI call and streams it: NDJSON lines { part } …, then { done }
18
+ * or { error }. A body that isn't a valid call answers 400 (or 413).
19
+ */
20
+ async function aiResponse(body, { model, signal, headers }) {
21
+ const b = body;
22
+ let options;
23
+ try {
24
+ options = sanitizeAiOptions(b?.options);
25
+ } catch (e) {
26
+ const err = plainAiError(e);
27
+ return aiErrorResponse(err.code === "too-large" ? 413 : 400, err.code, err.message);
28
+ }
29
+ const hint = typeof b?.model === "string" ? b.model : void 0;
30
+ const encoder = new TextEncoder();
31
+ const line = (m) => encoder.encode(`${JSON.stringify(m)}\n`);
32
+ const abort = new AbortController();
33
+ signal?.addEventListener("abort", () => abort.abort(), { once: true });
34
+ let reader;
35
+ const stream = new ReadableStream({
36
+ async pull(controller) {
37
+ try {
38
+ if (!reader) {
39
+ const { stream: parts } = await (await model(hint)).doStream({
40
+ ...options,
41
+ abortSignal: abort.signal
42
+ });
43
+ reader = parts.getReader();
44
+ }
45
+ for (;;) {
46
+ const { done, value } = await reader.read();
47
+ if (done) {
48
+ controller.enqueue(line({ done: true }));
49
+ controller.close();
50
+ return;
51
+ }
52
+ const p = plainPart(value);
53
+ if (p) {
54
+ controller.enqueue(line({ part: p }));
55
+ return;
56
+ }
57
+ }
58
+ } catch (e) {
59
+ controller.enqueue(line({ error: plainAiError(e) }));
60
+ controller.close();
61
+ }
62
+ },
63
+ cancel() {
64
+ abort.abort();
65
+ reader?.cancel().catch(() => {});
66
+ }
67
+ });
68
+ const h = new Headers(headers);
69
+ h.set("content-type", "application/x-ndjson; charset=utf-8");
70
+ h.set("cache-control", "no-store");
71
+ h.set("x-content-type-options", "nosniff");
72
+ return new Response(stream, {
73
+ status: 200,
74
+ headers: h
75
+ });
76
+ }
77
+ export { AiError, aiErrorResponse, aiResponse };
@@ -0,0 +1,7 @@
1
+ import type { LanguageModelV4 } from "@ai-sdk/provider";
2
+ /**
3
+ * A language model the shell serves. The id is a hint: the shell's provider
4
+ * decides. Errors carry a stable `code` ("not-configured", "denied",
5
+ * "rate-limited", "unavailable", …).
6
+ */
7
+ export declare function apposModel(modelId?: string): LanguageModelV4;
@@ -0,0 +1,467 @@
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
+ /**
9
+ * The file this frame runs: one instance of the app. Local grains of one
10
+ * app share its origin's storage, so keep each one's data under its id.
11
+ * The primary grain (the app's first) owns what the origin held before
12
+ * grains existed. A cloud grain is an actor someone shared: open it with
13
+ * appos.actors.open(grain.actor).
14
+ */
15
+ /** One file in appos.files.all(): where it is and what it is, never its data. */
16
+ export interface IndexedFile {
17
+ key: string;
18
+ title: string;
19
+ app: {
20
+ did: string;
21
+ name: string;
22
+ icon?: string;
23
+ };
24
+ /** "device", "cloud" or a host's name. */
25
+ host: string;
26
+ hostLabel: string;
27
+ /** Where it is stored, in words. */
28
+ location: string;
29
+ size?: number;
30
+ /** When it was last opened on this device. */
31
+ at?: number;
32
+ shared?: true;
33
+ /** A workspace: how many files it names. */
34
+ workspace?: number;
35
+ /** Its app isn't on this device yet: opening the file gets it. */
36
+ install?: true;
37
+ }
38
+ /** appos.files.all(): every host (this device first) and every file. */
39
+ export interface FileIndex {
40
+ hosts: {
41
+ id: string;
42
+ label: string;
43
+ }[];
44
+ files: IndexedFile[];
45
+ }
46
+ export interface Grain {
47
+ id: string;
48
+ kind: "local" | "cloud";
49
+ primary: boolean;
50
+ actor?: string;
51
+ /** A workspace (appos.multiple): the actors it names, on any hosts. Open each and merge them. */
52
+ actors?: string[];
53
+ title?: string;
54
+ }
55
+ declare function ready(): Promise<{
56
+ version: string;
57
+ build?: number;
58
+ previousVersion?: string;
59
+ upgrade?: {
60
+ from: string;
61
+ to: string;
62
+ };
63
+ }>;
64
+ /** A small modal sheet inside the app's frame. */
65
+ export declare function showSheet(opts: {
66
+ title: string;
67
+ text: string;
68
+ actions?: {
69
+ label: string;
70
+ primary?: boolean;
71
+ run: () => void | Promise<void>;
72
+ }[];
73
+ dismissable?: boolean;
74
+ }): void;
75
+ /** Shows the built-in sheet for a cloud problem the user can act on (`actorPath`: the actor the call went to). */
76
+ export declare function explain(error: CloudError, actorPath?: string): void;
77
+ /**
78
+ * The app's backend. It has no URL: `fetch()` can't reach it, so a URL that
79
+ * came from anywhere (a link, a message, another site) never becomes a call
80
+ * to it. Paths name an actor and what to send it:
81
+ *
82
+ * /whoami
83
+ * /actors GET: the user's actors; POST /actors/<Class>: a new one
84
+ * /actor/<id>/<path> one actor
85
+ */
86
+ export declare const backend: {
87
+ /** Sends a request to the backend; resolves to its streamed response. */
88
+ fetch(input: string | Request, init?: RequestInit): Promise<Response>;
89
+ /** A WebSocket to the backend, relayed by the shell. */
90
+ connect(path: string, protocols?: string | string[]): Promise<BackendSocket>;
91
+ };
92
+ /** A WebSocket-like socket over the handle: send, close, open/message/close/error events. */
93
+ export declare class BackendSocket extends EventTarget {
94
+ #private;
95
+ private readonly port;
96
+ private readonly id;
97
+ static readonly CONNECTING = 0;
98
+ static readonly OPEN = 1;
99
+ static readonly CLOSING = 2;
100
+ static readonly CLOSED = 3;
101
+ readyState: number;
102
+ protocol: string;
103
+ binaryType: "arraybuffer";
104
+ onopen: ((e: Event) => void) | null;
105
+ onmessage: ((e: MessageEvent) => void) | null;
106
+ onclose: ((e: CloseEvent) => void) | null;
107
+ onerror: ((e: Event) => void) | null;
108
+ constructor(port: MessagePort, id: number);
109
+ send(data: string | ArrayBuffer | ArrayBufferView): void;
110
+ close(code?: number, reason?: string): void;
111
+ /** @internal */
112
+ _opened(protocol: string): void;
113
+ /** @internal */
114
+ _message(data: string | ArrayBuffer): void;
115
+ /** @internal */
116
+ _closed(code: number, reason: string, clean: boolean): void;
117
+ }
118
+ export type ActorRole = "owner" | "editor" | "viewer";
119
+ export interface ActorEntry {
120
+ id: string;
121
+ /** The actor's class, as appos.actors names it. */
122
+ name: string;
123
+ /** The signed-in user's role in it. */
124
+ role: ActorRole;
125
+ /** Opens the app on this actor, for people who hold a role in it. */
126
+ url?: string;
127
+ }
128
+ export interface ActorInfo {
129
+ id: string;
130
+ className: string;
131
+ owner: string;
132
+ isOwner: boolean;
133
+ /** The signed-in user's roles here. */
134
+ roles: ActorRole[];
135
+ /** The owner sees every grant: user → role. */
136
+ grants?: Record<string, "editor" | "viewer">;
137
+ running?: {
138
+ version: string;
139
+ build?: number;
140
+ hash: string;
141
+ };
142
+ /** A newer build a member asked for, waiting for the owner. */
143
+ pending?: {
144
+ version: string;
145
+ build?: number;
146
+ hash: string;
147
+ by: string;
148
+ denied: boolean;
149
+ };
150
+ }
151
+ /** A person in an actor, to show: never an email. */
152
+ export interface ActorProfile {
153
+ id: string;
154
+ role: ActorRole;
155
+ name?: string;
156
+ image?: string;
157
+ }
158
+ /** A connection to one actor: RPC, fetch and a live socket, each with the user's claims. */
159
+ export declare class Actor {
160
+ readonly id: string;
161
+ readonly path: string;
162
+ /** The signed-in user's roles, as of open(). */
163
+ roles: ActorRole[];
164
+ constructor(id: string);
165
+ /** backend.fetch() to the actor's own fetch handler, at `sub` under it. Problems the user can act on get the SDK's sheets. */
166
+ fetch(sub?: string, init?: RequestInit): Promise<Response>;
167
+ /** Calls a method of the actor's class. Throws CloudError on failure. */
168
+ call<T = unknown>(method: string, ...args: unknown[]): Promise<T>;
169
+ /** A WebSocket to the actor's fetch handler. */
170
+ websocket(sub?: string, protocols?: string | string[]): Promise<BackendSocket>;
171
+ /**
172
+ * The owner and members to show: [{ id, role, name?, image? }]. `name` and
173
+ * `image` (an https avatar URL) come from each person's assistant-ui
174
+ * account; someone who never signed in to appOS has only id and role.
175
+ * The backend reads the same list with env.appos.profiles(). Cloud actors only.
176
+ */
177
+ profiles(): Promise<ActorProfile[]>;
178
+ /** Owner, roles, the build it runs. Shows the owner a newer build a member asked for (Approve / Deny). */
179
+ info(): Promise<ActorInfo>;
180
+ }
181
+ /**
182
+ * A link that opens this app on actor `id` and gives whoever opens it `role`
183
+ * (editor by default; viewers can share only as viewers). The app shows it
184
+ * in its own share sheet.
185
+ */
186
+ declare function share(id: string, role?: "editor" | "viewer"): Promise<string>;
187
+ /**
188
+ * Opens appOS's Share sheet for actor `id`: the people on it with their role
189
+ * and the link each joined by, and, for its owner, the share links (new,
190
+ * copy, revoke). The same sheet for every app; resolves once it is shown.
191
+ */
192
+ declare function openShare(id: string): Promise<void>;
193
+ /** What appOS tells the page when the person's role in an actor changed: role null once they lost access. */
194
+ export interface AccessChange {
195
+ actor: string;
196
+ role: ActorRole | null;
197
+ }
198
+ /**
199
+ * Calls `fn` when appOS finds the signed-in person's access to an actor
200
+ * changed (revoked, or they left on another device). Returns an unsubscribe.
201
+ */
202
+ declare function onAccess(fn: (change: AccessChange) => void): () => void;
203
+ export type LiveFileStatus = {
204
+ state: "connecting";
205
+ } | {
206
+ state: "live";
207
+ peers: number;
208
+ } | {
209
+ state: "offline";
210
+ message: string;
211
+ } | {
212
+ state: "error";
213
+ code: string;
214
+ message: string;
215
+ };
216
+ /** The live file this frame runs (appos.liveFile()). */
217
+ export declare class LiveFile {
218
+ #private;
219
+ /** The link that opens this file, to copy and send. */
220
+ readonly url: string;
221
+ /** @internal */
222
+ constructor(port: MessagePort, url: string);
223
+ /** The file's text as this frame last saw it; undefined until loaded(). */
224
+ get data(): string | undefined;
225
+ get rev(): number;
226
+ get status(): LiveFileStatus;
227
+ /** Resolves with the file's text once the cloud has sent it. */
228
+ loaded(): Promise<string>;
229
+ /** Runs `fn` with the text whenever someone else changed the file. */
230
+ onChange(fn: (data: string) => void): () => void;
231
+ /** Runs `fn` when the connection changes (connecting, live with N people, offline). */
232
+ onStatus(fn: (s: LiveFileStatus) => void): () => void;
233
+ /** Replaces the file's text for everyone. Resent after a reconnect until the cloud confirms it. */
234
+ save(data: string): void;
235
+ /** True while a local write is not yet in the cloud. */
236
+ get saving(): boolean;
237
+ close(): void;
238
+ }
239
+ declare function liveFile(): Promise<LiveFile | undefined>;
240
+ /**
241
+ * Moves the file this frame runs to the appOS cloud as a live file holding
242
+ * `data` (text, at most 512 KB), and returns its link. Anyone with the link
243
+ * opens the file and edits it live; no sign-in. Already live: its link.
244
+ * Afterwards appos.liveFile() connects to it.
245
+ */
246
+ declare function shareFile(data: string): Promise<{
247
+ url: string;
248
+ created: boolean;
249
+ }>;
250
+ export type Capability = "ai" | "microphone";
251
+ export type PermissionState = "granted" | "denied" | "prompt";
252
+ export type StreamPart = {
253
+ type: string;
254
+ [k: string]: unknown;
255
+ };
256
+ /**
257
+ * One AI call to the shell (the "appos:ai" port): AI SDK LanguageModelV4
258
+ * call options in (prompt, tools, maxOutputTokens…; no headers or signal),
259
+ * its stream parts out. `model` is a hint: the provider the user set up
260
+ * decides. Errors with code "not-configured" mean no AI is set up; offer
261
+ * appos.openSettings(). The AI SDK model on top is appos-client/ai-sdk.
262
+ */
263
+ export declare function aiCall(options: Record<string, unknown>, model?: string, signal?: AbortSignal): ReadableStream<StreamPart>;
264
+ /** Text deltas for one prompt: `for await (const t of appos.ai.stream({ prompt: "Hi" }))`. */
265
+ declare function aiStream(opts: {
266
+ prompt: string;
267
+ system?: string;
268
+ model?: string;
269
+ maxOutputTokens?: number;
270
+ }): AsyncGenerator<string>;
271
+ export type VoiceEvent = {
272
+ event: "listening";
273
+ provider: string;
274
+ onDevice: boolean;
275
+ downloading?: boolean;
276
+ } | {
277
+ event: "level";
278
+ level: number;
279
+ } | {
280
+ event: "partial";
281
+ text: string;
282
+ start: number;
283
+ } | {
284
+ event: "final";
285
+ text: string;
286
+ start: number;
287
+ end: number;
288
+ speaker?: number;
289
+ } | {
290
+ event: "error";
291
+ code: string;
292
+ message: string;
293
+ } | {
294
+ event: "end";
295
+ };
296
+ /**
297
+ * Live transcription. The shell holds the mic and the provider; the app gets
298
+ * text. Times are seconds since listening started. Ends with an "end" event
299
+ * (after an "error" one when it failed).
300
+ */
301
+ declare function transcribe(options: {
302
+ language?: string;
303
+ keyterms?: string[];
304
+ }, onEvent: (e: VoiceEvent) => void): {
305
+ stop(): void;
306
+ ended: Promise<void>;
307
+ };
308
+ export declare const appos: {
309
+ /** The app's backend: backend.fetch(path), backend.connect(path). No URL reaches it. */
310
+ backend: {
311
+ /** Sends a request to the backend; resolves to its streamed response. */
312
+ fetch(input: string | Request, init?: RequestInit): Promise<Response>;
313
+ /** A WebSocket to the backend, relayed by the shell. */
314
+ connect(path: string, protocols?: string | string[]): Promise<BackendSocket>;
315
+ };
316
+ /** The app's actors: create, open, list, grant, revoke, launched (appos.actors in the manifest). */
317
+ actors: {
318
+ /**
319
+ * A new actor of class `name`, owned by the user, on their default host.
320
+ * `host` says where it went: "cloud" or the host's name.
321
+ */
322
+ create(name: string): Promise<ActorEntry & {
323
+ url: string;
324
+ host: string;
325
+ }>;
326
+ /** A connection to an actor the user holds a role in. Rejects with "not-member" otherwise. */
327
+ open(id: string): Promise<Actor>;
328
+ /** The actors the user owns or holds a role in, on every host. */
329
+ list(): Promise<ActorEntry[]>;
330
+ /** Owner only: gives `user` a role in actor `id`. */
331
+ /** Owner only: gives `user` (their appOS ID) a role in actor `id`. */
332
+ grant(id: string, user: string, role: "editor" | "viewer"): Promise<void>;
333
+ /** Owner only: takes `user`'s role in actor `id` away. */
334
+ revoke(id: string, user: string): Promise<void>;
335
+ /**
336
+ * The actor a share link opened this app on, joined with the link's key
337
+ * (once per launch). Undefined when the app was not opened from one.
338
+ */
339
+ launched(): Promise<Actor | undefined>;
340
+ };
341
+ /** A share link to an actor for a role: share(id, "viewer"). */
342
+ share: typeof share;
343
+ /** appOS's Share sheet for an actor: openShare(id). */
344
+ openShare: typeof openShare;
345
+ /** Hears when the person's access to an actor changed: onAccess(({ actor, role }) => …). */
346
+ onAccess: typeof onAccess;
347
+ /** { version, previousVersion }: previousVersion only on the first launch after an update. */
348
+ ready: typeof ready;
349
+ /** This build's manifest version (after ready()). */
350
+ readonly version: string | undefined;
351
+ /** This build's appos.build, if the app has builds (after ready()). */
352
+ readonly build: number | undefined;
353
+ /**
354
+ * Asks the shell for this app's newest build now (the app's server said it
355
+ * is too old, or the app came back into view): the shell checks the app's
356
+ * update feed and applies what it lists at once, relaunching this frame.
357
+ * Answers when there was nothing to apply ("none"), or the check failed.
358
+ */
359
+ checkForUpdate(): Promise<{
360
+ status: string;
361
+ version?: string;
362
+ build?: number;
363
+ error?: string;
364
+ }>;
365
+ /**
366
+ * What this origin ran before, on the first launch after an update (after
367
+ * ready()): the version, or "0.0.1 (12)" for apps with builds.
368
+ */
369
+ readonly previousVersion: string | undefined;
370
+ /** Runs once, on the first launch after an update: migrate local data here. */
371
+ onUpgrade(fn: (from: string, to: string) => void | Promise<void>): void;
372
+ /**
373
+ * The data a file link opened this app with (/a/<did>/<name>#d=<data>),
374
+ * the first time it is asked: base64url text in the app's own format. The
375
+ * file is local and the link reopens it, so fill the file only when it is
376
+ * new. It came from a link: treat it as untrusted input.
377
+ */
378
+ launchData(): string | undefined;
379
+ /**
380
+ * The live file this frame runs, connected: load with loaded(), write with
381
+ * save(), hear others with onChange(). Undefined when the file is not live
382
+ * (see shareFile()).
383
+ */
384
+ liveFile: typeof liveFile;
385
+ /** Moves this frame's file to the cloud as a live file; resolves to its link. */
386
+ shareFile: typeof shareFile;
387
+ /** The file (grain) this frame runs; undefined in appOS from before grains. */
388
+ grain(): Promise<Grain | undefined>;
389
+ /**
390
+ * The shell's file picker: this app's files on every host the user is
391
+ * signed in to, and New (on the host the user picks). Resolves to what the
392
+ * user picked or made, or null when they cancelled. Apps with
393
+ * appos.multiple may ask for several; the shell saves them as a workspace.
394
+ */
395
+ files: {
396
+ open({ multiple }?: {
397
+ multiple?: boolean;
398
+ }): Promise<{
399
+ ids: string[];
400
+ workspace?: string;
401
+ } | null>;
402
+ /**
403
+ * The Files app only (did:web:appos.assistant-ui.workers.dev:apps:files):
404
+ * every file of every app, on this device and every host, read-only:
405
+ * where each is, never its data. Other apps get CloudError "forbidden".
406
+ */
407
+ all(): Promise<FileIndex>;
408
+ /** The Files app only: opens a file all() listed in its own app, in a tab. */
409
+ openInApp(key: string): Promise<void>;
410
+ };
411
+ /** Makes a new file of this app (an actor when it has them) and opens it in its own tab. */
412
+ newGrain(): Promise<{
413
+ id: string;
414
+ kind: "local" | "cloud";
415
+ }>;
416
+ /**
417
+ * Local grains the user deleted since the app last ran: delete their data
418
+ * (it shares this origin). Called once per launch with the ids.
419
+ */
420
+ onGrainRemoved(fn: (ids: string[]) => void | Promise<void>): void;
421
+ /** Names the app in the SDK's sheets. */
422
+ setName(name: string): void;
423
+ /** Names the file this frame runs, as Home and the tab show it. */
424
+ setTitle(title: string): Promise<void>;
425
+ /**
426
+ * A count for the shell to show on this app's tile or tab (unread items, say); 0 clears it. A whole number,
427
+ * 0 or more. Nothing comes back, and a shell may show it or ignore it (appOS itself doesn't show it yet).
428
+ * Outside a shell it does nothing.
429
+ */
430
+ setBadge(count: number): void;
431
+ /**
432
+ * 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
433
+ * the shell's hello: pad the header's start by it. 0 when the shell says nothing (appOS itself) or outside a shell.
434
+ */
435
+ markSpace(): Promise<number>;
436
+ /**
437
+ * Opens a web page (https) as a new top-level page with no opener: sign-in pages, docs, anything outside the
438
+ * app. Call it from the tap or click itself. A popup the app's sandboxed frame opens inherits the sandbox,
439
+ * and browsers won't show pages that send Cross-Origin-Opener-Policy there; the shell opens it instead.
440
+ * Outside appOS it opens the page itself.
441
+ */
442
+ openExternal(url: string): Promise<void>;
443
+ /** Opens appOS Settings (AI & voice, permissions), e.g. after a "not-configured" error. */
444
+ openSettings(): Promise<void>;
445
+ permissions: {
446
+ /** The grant now: "prompt" until the user has answered. */
447
+ query(cap: Capability): Promise<PermissionState>;
448
+ /** Asks the user (the shell's prompt) if they never have; the answer is remembered per app. */
449
+ request(cap: Capability): Promise<PermissionState>;
450
+ };
451
+ /** Language models through the shell (the "ai" capability). */
452
+ /** Text deltas for one prompt. For the AI SDK, use apposModel() from appos-client/ai-sdk. */
453
+ ai: {
454
+ stream: typeof aiStream;
455
+ };
456
+ /** Live transcription through the shell (the "microphone" capability). */
457
+ voice: {
458
+ transcribe: typeof transcribe;
459
+ };
460
+ /** Light or dark, from the shell: get(), onChange(fn), autoApply(false). Applied to <html> by default. */
461
+ theme: {
462
+ get: () => import("./theme").ColorScheme;
463
+ onChange: (fn: (scheme: import("./theme").ColorScheme) => void) => () => void;
464
+ autoApply: (on: boolean) => void;
465
+ };
466
+ };
467
+ 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 {};
@@ -0,0 +1,13 @@
1
+ /** "0.0.1 (3)", "build 3", "1.0.0", or undefined when nothing usable came. */
2
+ export declare function releaseText(details: Record<string, unknown>): string | undefined;
3
+ /** The sheet's text for update-required. Never prints a missing version. */
4
+ export declare function updateRequiredText(appName: string, details: Record<string, unknown>): string;
5
+ /**
6
+ * The sheet for upgrade-pending / upgrade-denied. The owner (`canApprove`) gets
7
+ * Approve (and Deny while it is pending); anyone else gets the server's words.
8
+ */
9
+ export declare function upgradeSheet(appName: string, code: "upgrade-pending" | "upgrade-denied", message: string, details: Record<string, unknown>): {
10
+ title: string;
11
+ text: string;
12
+ actions: ("approve" | "deny")[];
13
+ };
@@ -0,0 +1,20 @@
1
+ import { type CSSProperties } from "react";
2
+ import { type EmbedOptions } from "./embed";
3
+ export interface AppOSAppProps extends Omit<EmbedOptions, "src"> {
4
+ /** The bundle: a signed .swbn (URL or bytes) or an unsigned .wbn URL on this site. A new value reloads the app. */
5
+ src: EmbedOptions["src"];
6
+ className?: string;
7
+ style?: CSSProperties;
8
+ /** The frame's accessible name. Default: the app's name. */
9
+ title?: string;
10
+ }
11
+ /**
12
+ * An appOS app in a sandboxed frame, with this page as its shell. `services`
13
+ * answer its capability calls; `permissions` are the defaults ("prompt" when
14
+ * missing). Without onPermissionRequest, a "prompt" shows a small built-in
15
+ * question over the frame. `colorScheme` ("light", "dark", default
16
+ * "system") is the app's light or dark; pass the site's theme to have the
17
+ * app follow it. Changing services, permissions, colorScheme or callbacks
18
+ * doesn't reload the app; changing `src` or `sandbox` does.
19
+ */
20
+ export declare function AppOSApp({ src, sandbox, className, style, title, ...live }: AppOSAppProps): import("react").JSX.Element;
@@ -0,0 +1,31 @@
1
+ /** Call options an app may set. Headers and signals stay the shell's. */
2
+ export declare const AI_OPTION_KEYS: readonly ["prompt", "maxOutputTokens", "temperature", "stopSequences", "topP", "topK", "presencePenalty", "frequencyPenalty", "responseFormat", "seed", "tools", "toolChoice", "reasoning", "providerOptions"];
3
+ /** Bigger calls are refused. */
4
+ export declare const MAX_AI_REQUEST: number;
5
+ /** Stable codes an app sees on a failed AI call. */
6
+ export type AiErrorCode = "not-configured" | "denied" | "unavailable" | "bad-request" | "too-large" | "rate-limited" | "over-limit" | "provider";
7
+ /** An AI call error with a stable code, as plain data on the wire. */
8
+ export interface AiErrorData {
9
+ code: AiErrorCode | (string & {});
10
+ message: string;
11
+ }
12
+ export declare class AiError extends Error {
13
+ readonly code: AiErrorData["code"];
14
+ constructor(code: AiErrorData["code"], message: string);
15
+ }
16
+ /**
17
+ * The options a shell passes on to its model: only AI_OPTION_KEYS, and no
18
+ * Anthropic options that change where requests go or what they cost beyond
19
+ * the prompt (container, mcpServers). Throws AiError ("bad-request",
20
+ * "too-large").
21
+ */
22
+ export declare function sanitizeAiOptions(options: unknown): Record<string, unknown>;
23
+ /** Any error as { code, message }: its own string code (an AiError, or one off the wire), else "provider". */
24
+ export declare function plainAiError(e: unknown): AiErrorData;
25
+ /** An AI SDK LanguageModelV4 stream part, loosely typed (no AI SDK import). */
26
+ export type AiStreamPart = {
27
+ type: string;
28
+ [key: string]: unknown;
29
+ };
30
+ /** A part as plain data: no raw chunks, errors as { code, message }. */
31
+ export declare function plainPart(part: AiStreamPart): AiStreamPart | undefined;