@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.
- 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 +1174 -0
- package/dist/index.js +1618 -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 +107 -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 +467 -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 +106 -0
- package/dist/types/src/lib/swbn/release.d.ts +39 -0
- package/package.json +43 -4
- package/README.md +0 -3
package/dist/index.js
ADDED
|
@@ -0,0 +1,1618 @@
|
|
|
1
|
+
import { i as sanitizeAiOptions, n as plainAiError, r as plainPart, t as AiError } from "./chunks/ai-call.js";
|
|
2
|
+
import { useEffect, useRef, useState } from "react";
|
|
3
|
+
import { Bundle } from "wbn";
|
|
4
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
// src/lib/swbn/keys.ts
|
|
6
|
+
var BASE32 = "abcdefghijklmnopqrstuvwxyz234567";
|
|
7
|
+
/** RFC 4648 base32, lowercase, no padding. */
|
|
8
|
+
function base32(bytes) {
|
|
9
|
+
let bits = 0;
|
|
10
|
+
let value = 0;
|
|
11
|
+
let out = "";
|
|
12
|
+
for (const b of bytes) {
|
|
13
|
+
value = (value << 8 | b) & 65535;
|
|
14
|
+
bits += 8;
|
|
15
|
+
while (bits >= 5) {
|
|
16
|
+
out += BASE32[value >>> bits - 5 & 31];
|
|
17
|
+
bits -= 5;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
if (bits > 0) out += BASE32[value << 5 - bits & 31];
|
|
21
|
+
return out;
|
|
22
|
+
}
|
|
23
|
+
function toBase64Url(bytes) {
|
|
24
|
+
let binary = "";
|
|
25
|
+
for (const b of bytes) binary += String.fromCharCode(b);
|
|
26
|
+
return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
27
|
+
}
|
|
28
|
+
function formatKey(key) {
|
|
29
|
+
return `${key.type}:${toBase64Url(key.raw)}`;
|
|
30
|
+
}
|
|
31
|
+
async function sha256(bytes) {
|
|
32
|
+
return new Uint8Array(await crypto.subtle.digest("SHA-256", bytes));
|
|
33
|
+
}
|
|
34
|
+
new Map([...BASE32].map((c, i) => [c, i]));
|
|
35
|
+
var B58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
36
|
+
var B58_INDEX = new Map([...B58].map((c, i) => [c, BigInt(i)]));
|
|
37
|
+
function base58btc(bytes) {
|
|
38
|
+
let n = bytes.reduce((acc, b) => acc << 8n | BigInt(b), 0n);
|
|
39
|
+
let out = "";
|
|
40
|
+
while (n > 0n) {
|
|
41
|
+
out = B58[Number(n % 58n)] + out;
|
|
42
|
+
n /= 58n;
|
|
43
|
+
}
|
|
44
|
+
for (const b of bytes) {
|
|
45
|
+
if (b !== 0) break;
|
|
46
|
+
out = "1" + out;
|
|
47
|
+
}
|
|
48
|
+
return out;
|
|
49
|
+
}
|
|
50
|
+
function fromBase58btc(text) {
|
|
51
|
+
if (text.length === 0 || text.length > 200) return void 0;
|
|
52
|
+
let n = 0n;
|
|
53
|
+
for (const c of text) {
|
|
54
|
+
const v = B58_INDEX.get(c);
|
|
55
|
+
if (v === void 0) return void 0;
|
|
56
|
+
n = n * 58n + v;
|
|
57
|
+
}
|
|
58
|
+
const out = [];
|
|
59
|
+
while (n > 0n) {
|
|
60
|
+
out.unshift(Number(n & 255n));
|
|
61
|
+
n >>= 8n;
|
|
62
|
+
}
|
|
63
|
+
for (const c of text) {
|
|
64
|
+
if (c !== "1") break;
|
|
65
|
+
out.unshift(0);
|
|
66
|
+
}
|
|
67
|
+
return Uint8Array.from(out);
|
|
68
|
+
}
|
|
69
|
+
/** Multicodec prefixes for public keys in Multikey / did:key form. */
|
|
70
|
+
var ED25519_PUB = [237, 1];
|
|
71
|
+
var P256_PUB = [128, 36];
|
|
72
|
+
/** "z6Mk…" (Ed25519) or "zDn…" (P-256, compressed) multibase to a key. */
|
|
73
|
+
function parseMultikey(text) {
|
|
74
|
+
if (typeof text !== "string" || !text.startsWith("z")) return void 0;
|
|
75
|
+
const bytes = fromBase58btc(text.slice(1));
|
|
76
|
+
if (!bytes) return void 0;
|
|
77
|
+
const has = (p) => p.every((x, i) => bytes[i] === x);
|
|
78
|
+
if (has(ED25519_PUB) && bytes.length === 34) return {
|
|
79
|
+
type: "ed25519",
|
|
80
|
+
raw: bytes.slice(2)
|
|
81
|
+
};
|
|
82
|
+
if (has(P256_PUB) && bytes.length === 35 && (bytes[2] === 2 || bytes[2] === 3)) return {
|
|
83
|
+
type: "ecdsa-p256",
|
|
84
|
+
raw: bytes.slice(2)
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function toMultikey(key) {
|
|
88
|
+
const prefix = key.type === "ed25519" ? ED25519_PUB : P256_PUB;
|
|
89
|
+
return `z${base58btc(Uint8Array.from([...prefix, ...key.raw]))}`;
|
|
90
|
+
}
|
|
91
|
+
// src/lib/swbn/identity.ts
|
|
92
|
+
var DNS_LABEL = /^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$/;
|
|
93
|
+
var PATH_SEGMENT = /^(?:[A-Za-z0-9._~-]|%[0-9A-F]{2})+$/;
|
|
94
|
+
/** Hosts that name private or special-use networks (RFC 6761 and friends). */
|
|
95
|
+
var SPECIAL_HOST = /(^|\.)(localhost|local|internal|intranet|lan|home|corp|home\.arpa|onion|invalid|test|alt)$/;
|
|
96
|
+
var PLC = /^did:plc:[a-z2-7]{24}$/;
|
|
97
|
+
/** True for a public hostname: 2+ lowercase DNS labels, not an IP. */
|
|
98
|
+
function isPublicHostname(host) {
|
|
99
|
+
if (host.length > 253) return false;
|
|
100
|
+
const labels = host.split(".");
|
|
101
|
+
return labels.length >= 2 && labels.every((l) => DNS_LABEL.test(l)) && !/^[0-9]+$/.test(labels[labels.length - 1]);
|
|
102
|
+
}
|
|
103
|
+
/** The did:key for an Ed25519 public key. */
|
|
104
|
+
function didKeyFor(raw) {
|
|
105
|
+
return `did:key:${toMultikey({
|
|
106
|
+
type: "ed25519",
|
|
107
|
+
raw
|
|
108
|
+
})}`;
|
|
109
|
+
}
|
|
110
|
+
function parseDidWeb(id) {
|
|
111
|
+
const parts = id.slice(8).split(":");
|
|
112
|
+
const host = parts[0];
|
|
113
|
+
if (!isPublicHostname(host) || SPECIAL_HOST.test(host)) return void 0;
|
|
114
|
+
const path = parts.slice(1);
|
|
115
|
+
if (path.some((s) => !PATH_SEGMENT.test(s) || s === "." || s === "..")) return void 0;
|
|
116
|
+
for (const m of path.join("").matchAll(/%([0-9A-F]{2})/g)) if (/[A-Za-z0-9._~-]/.test(String.fromCharCode(parseInt(m[1], 16)))) return void 0;
|
|
117
|
+
return {
|
|
118
|
+
method: "web",
|
|
119
|
+
id,
|
|
120
|
+
host,
|
|
121
|
+
path,
|
|
122
|
+
url: `https://${host}/${path.length ? `${path.join("/")}/did.json` : ".well-known/did.json"}`
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
/** Parses a DID this sandbox can run, or returns undefined. */
|
|
126
|
+
function parseDid(id) {
|
|
127
|
+
if (typeof id !== "string" || id.length > 2048) return void 0;
|
|
128
|
+
if (id.startsWith("did:key:")) {
|
|
129
|
+
const key = parseMultikey(id.slice(8));
|
|
130
|
+
if (key?.type !== "ed25519" || didKeyFor(key.raw) !== id) return void 0;
|
|
131
|
+
return {
|
|
132
|
+
method: "key",
|
|
133
|
+
id,
|
|
134
|
+
key
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
if (id.startsWith("did:web:")) return parseDidWeb(id);
|
|
138
|
+
if (PLC.test(id)) return {
|
|
139
|
+
method: "plc",
|
|
140
|
+
id,
|
|
141
|
+
url: `https://plc.directory/${id}`
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
new RegExp(`^[a-z2-7]{52}$`);
|
|
145
|
+
/** The origin label a DID runs on. */
|
|
146
|
+
async function labelForId(id) {
|
|
147
|
+
if (!parseDid(id)) throw new Error(`Not a supported DID: ${id}`);
|
|
148
|
+
return base32(await sha256(new TextEncoder().encode(id))).slice(0, 52);
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* The origin label of an app served from a URL (decision 17): the same
|
|
152
|
+
* hash as a DID's, of its normalized URL (src/lib/remote.ts). A URL starts
|
|
153
|
+
* with "https:" or "http:", a DID with "did:", so the two never collide.
|
|
154
|
+
*/
|
|
155
|
+
async function labelForUrl(base) {
|
|
156
|
+
if (!/^https?:\/\//.test(base)) throw new Error(`Not an app URL: ${base}`);
|
|
157
|
+
return base32(await sha256(new TextEncoder().encode(base))).slice(0, 52);
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* The identity of an unsigned .wbn served at `raw` (appos-host embeds): its
|
|
161
|
+
* URL without query or fragment. Only https, or http on localhost for dev;
|
|
162
|
+
* its origin label is labelForUrl of it. Undefined if not allowed.
|
|
163
|
+
*/
|
|
164
|
+
function bundleUrlId(raw) {
|
|
165
|
+
if (typeof raw !== "string" || raw.length > 2048) return void 0;
|
|
166
|
+
let u;
|
|
167
|
+
try {
|
|
168
|
+
u = new URL(raw);
|
|
169
|
+
} catch {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
const local = u.hostname === "localhost" || u.hostname === "127.0.0.1" || u.hostname === "[::1]";
|
|
173
|
+
if (u.protocol !== "https:" && !(u.protocol === "http:" && local)) return void 0;
|
|
174
|
+
if (u.username || u.password) return void 0;
|
|
175
|
+
return `${u.origin}${u.pathname}`;
|
|
176
|
+
}
|
|
177
|
+
// src/lib/swbn/cbor.ts
|
|
178
|
+
var MAX_DEPTH = 16;
|
|
179
|
+
var CborError = class extends Error {};
|
|
180
|
+
function head(bytes, at) {
|
|
181
|
+
if (at >= bytes.length) throw new CborError("CBOR: unexpected end of data");
|
|
182
|
+
const first = bytes[at];
|
|
183
|
+
const major = first >> 5;
|
|
184
|
+
const info = first & 31;
|
|
185
|
+
if (info < 24) return {
|
|
186
|
+
major,
|
|
187
|
+
arg: BigInt(info),
|
|
188
|
+
next: at + 1
|
|
189
|
+
};
|
|
190
|
+
const size = info === 24 ? 1 : info === 25 ? 2 : info === 26 ? 4 : info === 27 ? 8 : 0;
|
|
191
|
+
if (size === 0) throw new CborError(info === 31 ? "CBOR: indefinite lengths are not allowed" : "CBOR: reserved additional info");
|
|
192
|
+
if (at + 1 + size > bytes.length) throw new CborError("CBOR: unexpected end of data");
|
|
193
|
+
let arg = 0n;
|
|
194
|
+
for (let i = 0; i < size; i++) arg = arg << 8n | BigInt(bytes[at + 1 + i]);
|
|
195
|
+
const min = size === 1 ? 24n : 1n << BigInt(size / 2 * 8);
|
|
196
|
+
if (arg < min) throw new CborError("CBOR: non-minimal integer encoding");
|
|
197
|
+
return {
|
|
198
|
+
major,
|
|
199
|
+
arg,
|
|
200
|
+
next: at + 1 + size
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
function length(arg, bytes, at) {
|
|
204
|
+
if (arg > BigInt(bytes.length - at)) throw new CborError("CBOR: length runs past the end");
|
|
205
|
+
return Number(arg);
|
|
206
|
+
}
|
|
207
|
+
function keyId(v) {
|
|
208
|
+
if (typeof v === "string") return `s:${v}`;
|
|
209
|
+
if (typeof v === "number" || typeof v === "bigint") return `n:${v}`;
|
|
210
|
+
if (v instanceof Uint8Array) return `b:${[...v].join(",")}`;
|
|
211
|
+
return `o:${JSON.stringify(v)}`;
|
|
212
|
+
}
|
|
213
|
+
function readItem(bytes, at, depth) {
|
|
214
|
+
if (depth > MAX_DEPTH) throw new CborError("CBOR: nested too deeply");
|
|
215
|
+
const { major, arg, next } = head(bytes, at);
|
|
216
|
+
switch (major) {
|
|
217
|
+
case 0: return {
|
|
218
|
+
value: arg <= BigInt(Number.MAX_SAFE_INTEGER) ? Number(arg) : arg,
|
|
219
|
+
start: at,
|
|
220
|
+
end: next
|
|
221
|
+
};
|
|
222
|
+
case 1: {
|
|
223
|
+
const n = -1n - arg;
|
|
224
|
+
return {
|
|
225
|
+
value: n >= BigInt(Number.MIN_SAFE_INTEGER) ? Number(n) : n,
|
|
226
|
+
start: at,
|
|
227
|
+
end: next
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
case 2: {
|
|
231
|
+
const len = length(arg, bytes, next);
|
|
232
|
+
return {
|
|
233
|
+
value: bytes.slice(next, next + len),
|
|
234
|
+
start: at,
|
|
235
|
+
end: next + len
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
case 3: {
|
|
239
|
+
const len = length(arg, bytes, next);
|
|
240
|
+
let text;
|
|
241
|
+
try {
|
|
242
|
+
text = new TextDecoder("utf-8", { fatal: true }).decode(bytes.subarray(next, next + len));
|
|
243
|
+
} catch {
|
|
244
|
+
throw new CborError("CBOR: text is not valid UTF-8");
|
|
245
|
+
}
|
|
246
|
+
return {
|
|
247
|
+
value: text,
|
|
248
|
+
start: at,
|
|
249
|
+
end: next + len
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
case 4: {
|
|
253
|
+
const count = length(arg, bytes, next);
|
|
254
|
+
const items = [];
|
|
255
|
+
let pos = next;
|
|
256
|
+
for (let i = 0; i < count; i++) {
|
|
257
|
+
const item = readItem(bytes, pos, depth + 1);
|
|
258
|
+
items.push(item);
|
|
259
|
+
pos = item.end;
|
|
260
|
+
}
|
|
261
|
+
return {
|
|
262
|
+
value: items.map((i) => i.value),
|
|
263
|
+
start: at,
|
|
264
|
+
end: pos,
|
|
265
|
+
items
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
case 5: {
|
|
269
|
+
const count = length(arg, bytes, next);
|
|
270
|
+
const items = [];
|
|
271
|
+
const map = /* @__PURE__ */ new Map();
|
|
272
|
+
const seen = /* @__PURE__ */ new Set();
|
|
273
|
+
let pos = next;
|
|
274
|
+
for (let i = 0; i < count; i++) {
|
|
275
|
+
const k = readItem(bytes, pos, depth + 1);
|
|
276
|
+
const v = readItem(bytes, k.end, depth + 1);
|
|
277
|
+
const id = keyId(k.value);
|
|
278
|
+
if (seen.has(id)) throw new CborError("CBOR: duplicate map key");
|
|
279
|
+
seen.add(id);
|
|
280
|
+
map.set(k.value, v.value);
|
|
281
|
+
items.push(k, v);
|
|
282
|
+
pos = v.end;
|
|
283
|
+
}
|
|
284
|
+
return {
|
|
285
|
+
value: map,
|
|
286
|
+
start: at,
|
|
287
|
+
end: pos,
|
|
288
|
+
items
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
case 6: throw new CborError("CBOR: tags are not allowed");
|
|
292
|
+
default: {
|
|
293
|
+
const info = bytes[at] & 31;
|
|
294
|
+
if (info === 20) return {
|
|
295
|
+
value: false,
|
|
296
|
+
start: at,
|
|
297
|
+
end: at + 1
|
|
298
|
+
};
|
|
299
|
+
if (info === 21) return {
|
|
300
|
+
value: true,
|
|
301
|
+
start: at,
|
|
302
|
+
end: at + 1
|
|
303
|
+
};
|
|
304
|
+
if (info === 22) return {
|
|
305
|
+
value: null,
|
|
306
|
+
start: at,
|
|
307
|
+
end: at + 1
|
|
308
|
+
};
|
|
309
|
+
throw new CborError("CBOR: floats and other simple values are not allowed");
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
/** Reads one CBOR item at `offset`. Trailing bytes are left alone. */
|
|
314
|
+
function readCbor(bytes, offset = 0) {
|
|
315
|
+
return readItem(bytes, offset, 0);
|
|
316
|
+
}
|
|
317
|
+
// src/lib/swbn/integrity.ts
|
|
318
|
+
var MAGIC = Uint8Array.from([
|
|
319
|
+
240,
|
|
320
|
+
159,
|
|
321
|
+
150,
|
|
322
|
+
139,
|
|
323
|
+
240,
|
|
324
|
+
159,
|
|
325
|
+
147,
|
|
326
|
+
166
|
|
327
|
+
]);
|
|
328
|
+
/**
|
|
329
|
+
* "2b\0\0", what Chrome and wbn-sign 0.3.x write and read. (The explainer's
|
|
330
|
+
* text says "2\0\0\0"; implementations use 2b.) The only version accepted.
|
|
331
|
+
*/
|
|
332
|
+
var VERSION = Uint8Array.from([
|
|
333
|
+
50,
|
|
334
|
+
98,
|
|
335
|
+
0,
|
|
336
|
+
0
|
|
337
|
+
]);
|
|
338
|
+
var ATTRIBUTE_KEY = new Map(Object.entries({
|
|
339
|
+
ed25519: "ed25519PublicKey",
|
|
340
|
+
"ecdsa-p256": "ecdsaP256SHA256PublicKey"
|
|
341
|
+
}).map(([t, a]) => [a, t]));
|
|
342
|
+
var MAX_SIGNATURES = 8;
|
|
343
|
+
/** Web Bundle magic: CBOR array header then "🌐📦" as a byte string. */
|
|
344
|
+
var WBN_MAGIC = Uint8Array.from([
|
|
345
|
+
240,
|
|
346
|
+
159,
|
|
347
|
+
140,
|
|
348
|
+
144,
|
|
349
|
+
240,
|
|
350
|
+
159,
|
|
351
|
+
147,
|
|
352
|
+
166
|
|
353
|
+
]);
|
|
354
|
+
function equal(a, b) {
|
|
355
|
+
return a.length === b.length && a.every((x, i) => x === b[i]);
|
|
356
|
+
}
|
|
357
|
+
/** True if the bytes start with the integrity block magic. */
|
|
358
|
+
function isSigned(bytes) {
|
|
359
|
+
return bytes.length > 10 && bytes[0] === 132 && bytes[1] === 72 && equal(bytes.subarray(2, 10), MAGIC);
|
|
360
|
+
}
|
|
361
|
+
/** True if the bytes look like an unsigned Web Bundle. */
|
|
362
|
+
function isWebBundle(bytes) {
|
|
363
|
+
return bytes.length > 10 && bytes[1] === 72 && equal(bytes.subarray(2, 10), WBN_MAGIC);
|
|
364
|
+
}
|
|
365
|
+
var FormatError = class extends Error {
|
|
366
|
+
constructor(message) {
|
|
367
|
+
super(`Not a valid signed bundle: ${message}`);
|
|
368
|
+
}
|
|
369
|
+
};
|
|
370
|
+
/** Parses the integrity block. Does not check any signature. */
|
|
371
|
+
function parseSignedBundle(bytes) {
|
|
372
|
+
if (!isSigned(bytes)) throw new FormatError(isWebBundle(bytes) ? "it is an unsigned .wbn" : "no integrity block");
|
|
373
|
+
let block;
|
|
374
|
+
try {
|
|
375
|
+
block = readCbor(bytes);
|
|
376
|
+
} catch (e) {
|
|
377
|
+
throw new FormatError(e instanceof CborError ? e.message : String(e));
|
|
378
|
+
}
|
|
379
|
+
const [magic, version, attributes, signatures] = block.items ?? [];
|
|
380
|
+
if (!Array.isArray(block.value) || block.items.length !== 4) throw new FormatError("integrity block must have 4 parts");
|
|
381
|
+
if (!(magic.value instanceof Uint8Array) || !equal(magic.value, MAGIC)) throw new FormatError("bad magic");
|
|
382
|
+
if (!(version.value instanceof Uint8Array) || !equal(version.value, VERSION)) throw new FormatError("unsupported integrity block version");
|
|
383
|
+
if (!(attributes.value instanceof Map)) throw new FormatError("attributes must be a map");
|
|
384
|
+
const id = attributes.value.get("webBundleId");
|
|
385
|
+
if (typeof id !== "string" || id === "") throw new FormatError("webBundleId missing");
|
|
386
|
+
if (!Array.isArray(signatures.value)) throw new FormatError("signatures must be a list");
|
|
387
|
+
const list = signatures.items;
|
|
388
|
+
if (list.length === 0) throw new FormatError("no signatures");
|
|
389
|
+
if (list.length > MAX_SIGNATURES) throw new FormatError("too many signatures");
|
|
390
|
+
const out = list.map((sig) => {
|
|
391
|
+
const [attrs, value] = sig.items ?? [];
|
|
392
|
+
if (!Array.isArray(sig.value) || sig.items.length !== 2) throw new FormatError("signature must be [attributes, signature]");
|
|
393
|
+
if (!(attrs.value instanceof Map)) throw new FormatError("signature attributes must be a map");
|
|
394
|
+
if (!(value.value instanceof Uint8Array)) throw new FormatError("signature must be bytes");
|
|
395
|
+
const entries = [...attrs.value];
|
|
396
|
+
if (entries.length !== 1 || typeof entries[0][0] !== "string" || !ATTRIBUTE_KEY.has(entries[0][0])) throw new FormatError("each signature needs exactly one ed25519PublicKey or ecdsaP256SHA256PublicKey");
|
|
397
|
+
const [name, raw] = entries[0];
|
|
398
|
+
const type = ATTRIBUTE_KEY.get(name);
|
|
399
|
+
if (!(raw instanceof Uint8Array) || raw.length !== (type === "ed25519" ? 32 : 33)) throw new FormatError(`bad ${name}`);
|
|
400
|
+
return {
|
|
401
|
+
key: {
|
|
402
|
+
type,
|
|
403
|
+
raw
|
|
404
|
+
},
|
|
405
|
+
signature: value.value,
|
|
406
|
+
attributes: bytes.slice(attrs.start, attrs.end)
|
|
407
|
+
};
|
|
408
|
+
});
|
|
409
|
+
const stripped = new Uint8Array(signatures.start + 1);
|
|
410
|
+
stripped.set(bytes.subarray(0, signatures.start));
|
|
411
|
+
stripped[signatures.start] = 128;
|
|
412
|
+
return {
|
|
413
|
+
webBundleId: id,
|
|
414
|
+
signatures: out,
|
|
415
|
+
stripped,
|
|
416
|
+
bundle: bytes.subarray(block.end)
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
function u64(n) {
|
|
420
|
+
const out = /* @__PURE__ */ new Uint8Array(8);
|
|
421
|
+
new DataView(out.buffer).setBigUint64(0, BigInt(n));
|
|
422
|
+
return out;
|
|
423
|
+
}
|
|
424
|
+
/** The bytes a signature covers. */
|
|
425
|
+
function dataToBeSigned(bundleHash, stripped, attributes) {
|
|
426
|
+
const parts = [
|
|
427
|
+
bundleHash,
|
|
428
|
+
stripped,
|
|
429
|
+
attributes
|
|
430
|
+
];
|
|
431
|
+
const out = new Uint8Array(parts.reduce((n, p) => n + 8 + p.length, 0));
|
|
432
|
+
let at = 0;
|
|
433
|
+
for (const p of parts) {
|
|
434
|
+
out.set(u64(p.length), at);
|
|
435
|
+
out.set(p, at + 8);
|
|
436
|
+
at += 8 + p.length;
|
|
437
|
+
}
|
|
438
|
+
return out;
|
|
439
|
+
}
|
|
440
|
+
async function sha512(bytes) {
|
|
441
|
+
return new Uint8Array(await crypto.subtle.digest("SHA-512", bytes));
|
|
442
|
+
}
|
|
443
|
+
var P = 115792089210356248762697446949407573530086143415290314195533631308867097853951n;
|
|
444
|
+
var B = 41058363725152142129326129780047268409114441015993725554835256314039467401291n;
|
|
445
|
+
function modPow(base, exp, mod) {
|
|
446
|
+
let result = 1n;
|
|
447
|
+
base %= mod;
|
|
448
|
+
while (exp > 0n) {
|
|
449
|
+
if (exp & 1n) result = result * base % mod;
|
|
450
|
+
base = base * base % mod;
|
|
451
|
+
exp >>= 1n;
|
|
452
|
+
}
|
|
453
|
+
return result;
|
|
454
|
+
}
|
|
455
|
+
function bytesToBig(b) {
|
|
456
|
+
return b.reduce((n, x) => n << 8n | BigInt(x), 0n);
|
|
457
|
+
}
|
|
458
|
+
function bigToBytes(n, len) {
|
|
459
|
+
const out = new Uint8Array(len);
|
|
460
|
+
for (let i = len - 1; i >= 0; i--) {
|
|
461
|
+
out[i] = Number(n & 255n);
|
|
462
|
+
n >>= 8n;
|
|
463
|
+
}
|
|
464
|
+
return out;
|
|
465
|
+
}
|
|
466
|
+
/** Decompresses a 33-byte P-256 point to the 65-byte uncompressed form. */
|
|
467
|
+
function decompressP256(raw) {
|
|
468
|
+
const x = bytesToBig(raw.subarray(1));
|
|
469
|
+
if (x >= P) throw new Error("bad P-256 key");
|
|
470
|
+
const rhs = ((x * x * x - 3n * x + B) % P + P) % P;
|
|
471
|
+
let y = modPow(rhs, 115792089210356248762697446949407573530086143415290314195533631308867097853952n / 4n, P);
|
|
472
|
+
if (y * y % P !== rhs) throw new Error("bad P-256 key");
|
|
473
|
+
if (Number(y & 1n) !== (raw[0] & 1)) y = P - y;
|
|
474
|
+
const out = /* @__PURE__ */ new Uint8Array(65);
|
|
475
|
+
out[0] = 4;
|
|
476
|
+
out.set(bigToBytes(x, 32), 1);
|
|
477
|
+
out.set(bigToBytes(y, 32), 33);
|
|
478
|
+
return out;
|
|
479
|
+
}
|
|
480
|
+
/** DER ECDSA-Sig-Value to raw r||s (64 bytes). Raw input passes through. */
|
|
481
|
+
function derToRaw(sig) {
|
|
482
|
+
try {
|
|
483
|
+
return parseDer(sig);
|
|
484
|
+
} catch (e) {
|
|
485
|
+
if (sig.length === 64) return sig;
|
|
486
|
+
throw e;
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
function parseDer(sig) {
|
|
490
|
+
const fail = () => {
|
|
491
|
+
throw new Error("bad ECDSA signature");
|
|
492
|
+
};
|
|
493
|
+
if (sig[0] !== 48 || sig[1] !== sig.length - 2) fail();
|
|
494
|
+
let at = 2;
|
|
495
|
+
const ints = [];
|
|
496
|
+
for (let i = 0; i < 2; i++) {
|
|
497
|
+
if (sig[at] !== 2) fail();
|
|
498
|
+
const len = sig[at + 1];
|
|
499
|
+
let v = sig.subarray(at + 2, at + 2 + len);
|
|
500
|
+
if (v.length !== len || len === 0) fail();
|
|
501
|
+
while (v.length > 32 && v[0] === 0) v = v.subarray(1);
|
|
502
|
+
if (v.length > 32) fail();
|
|
503
|
+
const padded = /* @__PURE__ */ new Uint8Array(32);
|
|
504
|
+
padded.set(v, 32 - v.length);
|
|
505
|
+
ints.push(padded);
|
|
506
|
+
at += 2 + len;
|
|
507
|
+
}
|
|
508
|
+
if (at !== sig.length) fail();
|
|
509
|
+
const out = /* @__PURE__ */ new Uint8Array(64);
|
|
510
|
+
out.set(ints[0]);
|
|
511
|
+
out.set(ints[1], 32);
|
|
512
|
+
return out;
|
|
513
|
+
}
|
|
514
|
+
async function verifyOne(key, signature, data) {
|
|
515
|
+
try {
|
|
516
|
+
if (key.type === "ed25519") {
|
|
517
|
+
const k = await crypto.subtle.importKey("raw", key.raw, { name: "Ed25519" }, false, ["verify"]);
|
|
518
|
+
return await crypto.subtle.verify({ name: "Ed25519" }, k, signature, data);
|
|
519
|
+
}
|
|
520
|
+
const k = await crypto.subtle.importKey("raw", decompressP256(key.raw), {
|
|
521
|
+
name: "ECDSA",
|
|
522
|
+
namedCurve: "P-256"
|
|
523
|
+
}, false, ["verify"]);
|
|
524
|
+
return await crypto.subtle.verify({
|
|
525
|
+
name: "ECDSA",
|
|
526
|
+
hash: "SHA-256"
|
|
527
|
+
}, k, derToRaw(signature), data);
|
|
528
|
+
} catch {
|
|
529
|
+
return false;
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
/**
|
|
533
|
+
* Checks every signature against the bundle. Throws unless all of them are
|
|
534
|
+
* valid. Returns the signing keys as "ed25519:<base64url>" strings. Says
|
|
535
|
+
* nothing about whether the keys may sign for the bundle's id.
|
|
536
|
+
*/
|
|
537
|
+
async function verifySignatures(signed) {
|
|
538
|
+
const hash = await sha512(signed.bundle);
|
|
539
|
+
const keys = [];
|
|
540
|
+
for (const sig of signed.signatures) {
|
|
541
|
+
const data = dataToBeSigned(hash, signed.stripped, sig.attributes);
|
|
542
|
+
if (!await verifyOne(sig.key, sig.signature, data)) throw new Error("The bundle's signature does not match its contents. It may have been changed after signing.");
|
|
543
|
+
keys.push(formatKey(sig.key));
|
|
544
|
+
}
|
|
545
|
+
return keys;
|
|
546
|
+
}
|
|
547
|
+
// src/lib/bundle-meta.ts
|
|
548
|
+
/** Icons bigger than this are skipped; the grid falls back to a monogram. */
|
|
549
|
+
var MAX_ICON_BYTES = 262144;
|
|
550
|
+
var ICON_TYPES = {
|
|
551
|
+
svg: "image/svg+xml",
|
|
552
|
+
png: "image/png",
|
|
553
|
+
ico: "image/x-icon",
|
|
554
|
+
webp: "image/webp",
|
|
555
|
+
jpg: "image/jpeg",
|
|
556
|
+
jpeg: "image/jpeg",
|
|
557
|
+
gif: "image/gif"
|
|
558
|
+
};
|
|
559
|
+
function pathOf$1(url, base = "/") {
|
|
560
|
+
return new URL(url, new URL(base, "https://bundle.invalid/")).pathname;
|
|
561
|
+
}
|
|
562
|
+
/** Biggest declared size of an icon; `any` (SVG) wins. */
|
|
563
|
+
function iconSize(icon) {
|
|
564
|
+
if (!icon.sizes) return 0;
|
|
565
|
+
return Math.max(...icon.sizes.split(/\s+/).map((s) => s === "any" ? Infinity : Number(s.split("x")[0]) || 0));
|
|
566
|
+
}
|
|
567
|
+
/**
|
|
568
|
+
* Reads the app's name and icon from a Web Bundle. The icon comes from, in
|
|
569
|
+
* order: the web app manifest, `<link rel="apple-touch-icon">` or
|
|
570
|
+
* `<link rel="icon">` in the primary document, then `/favicon.*`.
|
|
571
|
+
* Throws if the bytes are not a Web Bundle.
|
|
572
|
+
*/
|
|
573
|
+
function readBundleMeta(bytes) {
|
|
574
|
+
const bundle = new Bundle(bytes);
|
|
575
|
+
const byPath = new Map(bundle.urls.map((u) => [pathOf$1(u), u]));
|
|
576
|
+
const get = (path) => {
|
|
577
|
+
const url = byPath.get(path);
|
|
578
|
+
if (!url) return void 0;
|
|
579
|
+
const res = bundle.getResponse(url);
|
|
580
|
+
return res.status === 200 ? res : void 0;
|
|
581
|
+
};
|
|
582
|
+
const text = (path) => {
|
|
583
|
+
const res = get(path);
|
|
584
|
+
return res ? new TextDecoder().decode(res.body) : void 0;
|
|
585
|
+
};
|
|
586
|
+
const primaryPath = pathOf$1(bundle.primaryURL ?? "/");
|
|
587
|
+
const html = text(primaryPath) ?? text("/index.html");
|
|
588
|
+
const doc = html ? new DOMParser().parseFromString(html, "text/html") : void 0;
|
|
589
|
+
const linkHref = (rel) => doc?.querySelector(`link[rel~="${rel}"][href]`)?.getAttribute("href") ?? void 0;
|
|
590
|
+
let manifest;
|
|
591
|
+
let manifestPath;
|
|
592
|
+
for (const candidate of [
|
|
593
|
+
linkHref("manifest") && pathOf$1(linkHref("manifest"), primaryPath),
|
|
594
|
+
"/manifest.webmanifest",
|
|
595
|
+
"/manifest.json"
|
|
596
|
+
]) {
|
|
597
|
+
if (!candidate) continue;
|
|
598
|
+
const json = text(candidate);
|
|
599
|
+
if (!json) continue;
|
|
600
|
+
try {
|
|
601
|
+
manifest = JSON.parse(json);
|
|
602
|
+
manifestPath = candidate;
|
|
603
|
+
break;
|
|
604
|
+
} catch {}
|
|
605
|
+
}
|
|
606
|
+
const iconPaths = [];
|
|
607
|
+
const manifestIcons = (manifest?.icons ?? []).filter((i) => i.src && (!i.purpose || i.purpose.split(/\s+/).includes("any"))).sort((a, b) => iconSize(b) - iconSize(a));
|
|
608
|
+
for (const icon of manifestIcons) iconPaths.push(pathOf$1(icon.src, manifestPath));
|
|
609
|
+
for (const rel of ["apple-touch-icon", "icon"]) {
|
|
610
|
+
const href = linkHref(rel);
|
|
611
|
+
if (href && !href.startsWith("data:")) iconPaths.push(pathOf$1(href, primaryPath));
|
|
612
|
+
}
|
|
613
|
+
iconPaths.push("/favicon.svg", "/favicon.png", "/favicon.ico");
|
|
614
|
+
let icon;
|
|
615
|
+
for (const path of iconPaths) {
|
|
616
|
+
const res = get(path);
|
|
617
|
+
if (!res || res.body.length === 0 || res.body.length > MAX_ICON_BYTES) continue;
|
|
618
|
+
const ext = path.split(".").pop()?.toLowerCase() ?? "";
|
|
619
|
+
const type = res.headers["content-type"]?.split(";")[0] || ICON_TYPES[ext];
|
|
620
|
+
if (!type?.startsWith("image/")) continue;
|
|
621
|
+
icon = `data:${type};base64,${toBase64(res.body)}`;
|
|
622
|
+
break;
|
|
623
|
+
}
|
|
624
|
+
return {
|
|
625
|
+
name: manifest?.short_name?.trim() || manifest?.name?.trim() || doc?.title.trim() || void 0,
|
|
626
|
+
icon
|
|
627
|
+
};
|
|
628
|
+
}
|
|
629
|
+
function toBase64(bytes) {
|
|
630
|
+
let binary = "";
|
|
631
|
+
for (let i = 0; i < bytes.length; i += 32768) binary += String.fromCharCode(...bytes.subarray(i, i + 32768));
|
|
632
|
+
return btoa(binary);
|
|
633
|
+
}
|
|
634
|
+
// src/lib/swbn/release.ts
|
|
635
|
+
/** Largest build number accepted (fits every store and header). */
|
|
636
|
+
var MAX_BUILD = 2 ** 31 - 1;
|
|
637
|
+
/** appos.build: a positive integer, or undefined. */
|
|
638
|
+
function parseBuild(v) {
|
|
639
|
+
return typeof v === "number" && Number.isInteger(v) && v >= 1 && v <= MAX_BUILD ? v : void 0;
|
|
640
|
+
}
|
|
641
|
+
// src/lib/swbn/manifest.ts
|
|
642
|
+
function pathOf(url, base = "/") {
|
|
643
|
+
return new URL(url, new URL(base, "https://bundle.invalid/")).pathname;
|
|
644
|
+
}
|
|
645
|
+
/** What appos.permissions may list, and the iframe allow feature each delegates. */
|
|
646
|
+
var FRAME_PERMISSIONS = { "local-network": "local-network-access" };
|
|
647
|
+
/** appos.permissions: the known names, once each; anything else is ignored (a newer appOS may know it). */
|
|
648
|
+
function parsePermissions(v) {
|
|
649
|
+
if (!Array.isArray(v)) return void 0;
|
|
650
|
+
const out = [...new Set(v.filter((p) => typeof p === "string" && Object.hasOwn(FRAME_PERMISSIONS, p)))];
|
|
651
|
+
return out.length ? out : void 0;
|
|
652
|
+
}
|
|
653
|
+
/**
|
|
654
|
+
* What every app's frame gets: copying (share links and the like) and keeping the screen on while it's in front (a
|
|
655
|
+
* dictation, a recipe). Without screen-wake-lock Chrome refuses navigator.wakeLock in the frame by permissions policy.
|
|
656
|
+
*/
|
|
657
|
+
var BASE_FRAME_ALLOW = ["clipboard-write", "screen-wake-lock"];
|
|
658
|
+
/** The allow features for an app's frame: what it declared (FRAME_PERMISSIONS). */
|
|
659
|
+
function frameAllow(permissions) {
|
|
660
|
+
return (permissions ?? []).map((p) => FRAME_PERMISSIONS[p]);
|
|
661
|
+
}
|
|
662
|
+
var MODULE_PATH = /^(?:[A-Za-z0-9_-][A-Za-z0-9._-]*\/)*[A-Za-z0-9_-][A-Za-z0-9._-]*\.m?js$/;
|
|
663
|
+
var CLASS_NAME = /^[A-Z][A-Za-z0-9_]{0,63}$/;
|
|
664
|
+
var HOST = /^(?=.{1,253}$)([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z][a-z0-9-]{0,61}[a-z0-9]$/;
|
|
665
|
+
var cleanMain = (m) => {
|
|
666
|
+
const main = typeof m === "string" ? m.replace(/^\/+/, "") : void 0;
|
|
667
|
+
return main && MODULE_PATH.test(main) && !main.split("/").includes("..") ? main : void 0;
|
|
668
|
+
};
|
|
669
|
+
/**
|
|
670
|
+
* appos.actors: { Name: { main } }. v1 runs one bundled module per app, so
|
|
671
|
+
* every actor names the same main. Returns the normalized actors or an error.
|
|
672
|
+
*/
|
|
673
|
+
function parseActors(v) {
|
|
674
|
+
if (!v || typeof v !== "object" || Array.isArray(v)) return { error: "appos.actors must be { \"Name\": { \"main\": \"actor.js\" } }." };
|
|
675
|
+
const entries = Object.entries(v);
|
|
676
|
+
if (entries.length === 0 || entries.length > 16) return { error: `appos.actors must list 1 to 16 actors.` };
|
|
677
|
+
const actors = {};
|
|
678
|
+
let main;
|
|
679
|
+
for (const [name, a] of entries) {
|
|
680
|
+
if (!CLASS_NAME.test(name)) return { error: `appos.actors: "${name}" is not a class name, like Board.` };
|
|
681
|
+
const m = cleanMain(a && typeof a === "object" ? a.main : void 0);
|
|
682
|
+
if (!m) return { error: `appos.actors.${name}.main must be a .js path inside the bundle, like actor.js.` };
|
|
683
|
+
if (main !== void 0 && m !== main) return { error: "appos.actors: every actor must name the same main module for now." };
|
|
684
|
+
main = m;
|
|
685
|
+
actors[name] = { main: m };
|
|
686
|
+
}
|
|
687
|
+
return {
|
|
688
|
+
actors,
|
|
689
|
+
main
|
|
690
|
+
};
|
|
691
|
+
}
|
|
692
|
+
var ROUTE = /^\/[A-Za-z0-9._~!$&'()*+,;=:@%\[\]\/-]{0,255}$/;
|
|
693
|
+
/** appos.server: { main, routes }. Returns it normalized, or an error. */
|
|
694
|
+
function parseServer(v) {
|
|
695
|
+
const s = v && typeof v === "object" && !Array.isArray(v) ? v : void 0;
|
|
696
|
+
const main = cleanMain(s?.main);
|
|
697
|
+
if (!main) return { error: "appos.server must be { \"main\": \"server.js\", \"routes\": [\"/api/chat\"] }." };
|
|
698
|
+
const routes = s.routes;
|
|
699
|
+
if (!Array.isArray(routes) || routes.length === 0 || routes.length > 256 || !routes.every((r) => typeof r === "string" && ROUTE.test(r) && !r.split("/").includes(".."))) return { error: `appos.server.routes must list 1 to 256 paths, like "/api/chat".` };
|
|
700
|
+
return {
|
|
701
|
+
main,
|
|
702
|
+
routes: [...new Set(routes)]
|
|
703
|
+
};
|
|
704
|
+
}
|
|
705
|
+
/** Validates appos.actors, appos.server and appos.network; never throws. */
|
|
706
|
+
function parseBackend(appos) {
|
|
707
|
+
const out = {};
|
|
708
|
+
const net = appos.network;
|
|
709
|
+
if (net === void 0 || net === "none") out.network = "none";
|
|
710
|
+
else if (Array.isArray(net) && net.length <= 32 && net.every((h) => typeof h === "string" && HOST.test(h))) out.network = [...new Set(net)];
|
|
711
|
+
else out.backendError = `appos.network must be "none" or a list of up to 32 lowercase host names.`;
|
|
712
|
+
if ("server" in appos) {
|
|
713
|
+
const server = parseServer(appos.server);
|
|
714
|
+
if ("error" in server) {
|
|
715
|
+
out.backendError = server.error;
|
|
716
|
+
return out;
|
|
717
|
+
}
|
|
718
|
+
if (!out.backendError) out.server = server;
|
|
719
|
+
}
|
|
720
|
+
if (!("actors" in appos)) return out;
|
|
721
|
+
const r = parseActors(appos.actors);
|
|
722
|
+
if ("error" in r) {
|
|
723
|
+
out.backendError = r.error;
|
|
724
|
+
return out;
|
|
725
|
+
}
|
|
726
|
+
if (!out.backendError) {
|
|
727
|
+
out.backend = {
|
|
728
|
+
main: r.main,
|
|
729
|
+
classes: Object.keys(r.actors)
|
|
730
|
+
};
|
|
731
|
+
out.actors = r.actors;
|
|
732
|
+
}
|
|
733
|
+
return out;
|
|
734
|
+
}
|
|
735
|
+
/** A channel name: lowercase, like "beta" or "dev". */
|
|
736
|
+
var CHANNEL_NAME = /^[a-z][a-z0-9-]{0,31}$/;
|
|
737
|
+
/**
|
|
738
|
+
* appos.channels: { name: feed URL }. Malformed entries, and "stable" (that
|
|
739
|
+
* is appos.update), are dropped; the URLs are checked when used.
|
|
740
|
+
*/
|
|
741
|
+
function parseChannels(v) {
|
|
742
|
+
if (!v || typeof v !== "object" || Array.isArray(v)) return void 0;
|
|
743
|
+
const out = {};
|
|
744
|
+
for (const [name, url] of Object.entries(v)) {
|
|
745
|
+
if (Object.keys(out).length >= 8) break;
|
|
746
|
+
if (name === "stable" || !CHANNEL_NAME.test(name)) continue;
|
|
747
|
+
if (typeof url !== "string" || url.length === 0 || url.length > 2048) continue;
|
|
748
|
+
out[name] = url;
|
|
749
|
+
}
|
|
750
|
+
return Object.keys(out).length ? out : void 0;
|
|
751
|
+
}
|
|
752
|
+
/** Reads the app's manifest from a .wbn: the <link rel=manifest>, else
|
|
753
|
+
* /manifest.webmanifest or /manifest.json. */
|
|
754
|
+
function readManifest(wbn) {
|
|
755
|
+
const bundle = new Bundle(wbn);
|
|
756
|
+
const byPath = new Map(bundle.urls.map((u) => [pathOf(u), u]));
|
|
757
|
+
const text = (path) => {
|
|
758
|
+
const url = byPath.get(path);
|
|
759
|
+
if (!url) return void 0;
|
|
760
|
+
const res = bundle.getResponse(url);
|
|
761
|
+
return res.status === 200 ? new TextDecoder().decode(res.body) : void 0;
|
|
762
|
+
};
|
|
763
|
+
const primary = pathOf(bundle.primaryURL ?? "/");
|
|
764
|
+
const html = text(primary) ?? text("/index.html") ?? "";
|
|
765
|
+
const candidates = [];
|
|
766
|
+
for (const tag of html.match(/<link\b[^>]*>/gi) ?? []) {
|
|
767
|
+
const rel = /\brel\s*=\s*["']?([^"'>]+)/i.exec(tag)?.[1] ?? "";
|
|
768
|
+
const href = /\bhref\s*=\s*["']?([^"'\s>]+)/i.exec(tag)?.[1];
|
|
769
|
+
if (href && rel.toLowerCase().split(/\s+/).includes("manifest")) candidates.push(pathOf(href, primary));
|
|
770
|
+
}
|
|
771
|
+
candidates.push("/manifest.webmanifest", "/manifest.json");
|
|
772
|
+
for (const path of candidates) {
|
|
773
|
+
const json = text(path);
|
|
774
|
+
if (json === void 0) continue;
|
|
775
|
+
let m;
|
|
776
|
+
try {
|
|
777
|
+
m = JSON.parse(json);
|
|
778
|
+
} catch {
|
|
779
|
+
continue;
|
|
780
|
+
}
|
|
781
|
+
if (!m || typeof m !== "object") continue;
|
|
782
|
+
const out = {};
|
|
783
|
+
if (m.appos && typeof m.appos === "object" && "did" in m.appos) out.did = typeof m.appos.did === "string" ? m.appos.did : JSON.stringify(m.appos.did);
|
|
784
|
+
if (m.appos && typeof m.appos === "object" && typeof m.appos.update === "string") out.update = m.appos.update;
|
|
785
|
+
if (m.appos && typeof m.appos === "object" && m.appos.home === true) out.home = true;
|
|
786
|
+
if (m.appos && typeof m.appos === "object" && m.appos.multiple === true) out.multiple = true;
|
|
787
|
+
if (m.appos && typeof m.appos === "object") {
|
|
788
|
+
const permissions = parsePermissions(m.appos.permissions);
|
|
789
|
+
if (permissions) out.permissions = permissions;
|
|
790
|
+
}
|
|
791
|
+
if (m.version !== void 0) out.version = typeof m.version === "string" ? m.version : JSON.stringify(m.version);
|
|
792
|
+
if (m.appos && typeof m.appos === "object" && "build" in m.appos) {
|
|
793
|
+
const build = parseBuild(m.appos.build);
|
|
794
|
+
if (build === void 0) out.buildError = "appos.build must be a whole number from 1 to 2147483647.";
|
|
795
|
+
else out.build = build;
|
|
796
|
+
}
|
|
797
|
+
if (m.appos && typeof m.appos === "object" && "channels" in m.appos) {
|
|
798
|
+
const channels = parseChannels(m.appos.channels);
|
|
799
|
+
if (channels) out.channels = channels;
|
|
800
|
+
}
|
|
801
|
+
if (m.appos && typeof m.appos === "object" && ("actors" in m.appos || "server" in m.appos || "network" in m.appos)) Object.assign(out, parseBackend(m.appos));
|
|
802
|
+
return out;
|
|
803
|
+
}
|
|
804
|
+
return {};
|
|
805
|
+
}
|
|
806
|
+
// src/lib/color-scheme.ts
|
|
807
|
+
var COLOR_SCHEME_MESSAGE = "appos:color-scheme";
|
|
808
|
+
function isColorScheme(value) {
|
|
809
|
+
return value === "light" || value === "dark";
|
|
810
|
+
}
|
|
811
|
+
function colorSchemeMessage(scheme) {
|
|
812
|
+
return {
|
|
813
|
+
type: COLOR_SCHEME_MESSAGE,
|
|
814
|
+
scheme
|
|
815
|
+
};
|
|
816
|
+
}
|
|
817
|
+
var DARK_QUERY = "(prefers-color-scheme: dark)";
|
|
818
|
+
/** "system" as this page sees it now: its own prefers-color-scheme. */
|
|
819
|
+
function resolveColorScheme(preference) {
|
|
820
|
+
if (isColorScheme(preference)) return preference;
|
|
821
|
+
return typeof matchMedia === "function" && matchMedia(DARK_QUERY).matches ? "dark" : "light";
|
|
822
|
+
}
|
|
823
|
+
/**
|
|
824
|
+
* Calls `onScheme` with the resolved scheme now and whenever it changes:
|
|
825
|
+
* for "system", when this page's prefers-color-scheme does. Returns a stop
|
|
826
|
+
* function.
|
|
827
|
+
*/
|
|
828
|
+
function watchColorScheme(preference, onScheme) {
|
|
829
|
+
onScheme(resolveColorScheme(preference));
|
|
830
|
+
if (isColorScheme(preference) || typeof matchMedia !== "function") return () => {};
|
|
831
|
+
const query = matchMedia(DARK_QUERY);
|
|
832
|
+
const onChange = () => onScheme(query.matches ? "dark" : "light");
|
|
833
|
+
query.addEventListener("change", onChange);
|
|
834
|
+
return () => query.removeEventListener("change", onChange);
|
|
835
|
+
}
|
|
836
|
+
// src/lib/frame-pinch.ts
|
|
837
|
+
/**
|
|
838
|
+
* Hands ctrl+wheel on `iframe` to the app at `origin`, at the same point in
|
|
839
|
+
* the frame's own pixels. `skip` leaves the pinch to the page (the canvas
|
|
840
|
+
* layout zooms the canvas). Returns the cleanup.
|
|
841
|
+
*/
|
|
842
|
+
function forwardFramePinch(iframe, origin, skip) {
|
|
843
|
+
const onWheel = (e) => {
|
|
844
|
+
if (!e.ctrlKey || skip?.()) return;
|
|
845
|
+
e.preventDefault();
|
|
846
|
+
const r = iframe.getBoundingClientRect();
|
|
847
|
+
const k = iframe.offsetWidth ? r.width / iframe.offsetWidth : 1;
|
|
848
|
+
iframe.contentWindow?.postMessage({
|
|
849
|
+
type: "appos:pinch-in",
|
|
850
|
+
x: (e.clientX - r.left) / k,
|
|
851
|
+
y: (e.clientY - r.top) / k,
|
|
852
|
+
deltaY: e.deltaY,
|
|
853
|
+
deltaMode: e.deltaMode
|
|
854
|
+
}, origin);
|
|
855
|
+
};
|
|
856
|
+
iframe.addEventListener("wheel", onWheel, { passive: false });
|
|
857
|
+
return () => iframe.removeEventListener("wheel", onWheel);
|
|
858
|
+
}
|
|
859
|
+
// src/lib/external-link.ts
|
|
860
|
+
/** The URL to open: https, or http on a loopback host. Anything else (javascript:, data:, blob:, file:) is refused. */
|
|
861
|
+
function externalUrl(value) {
|
|
862
|
+
if (typeof value !== "string" || value.length > 8192) return void 0;
|
|
863
|
+
let url;
|
|
864
|
+
try {
|
|
865
|
+
url = new URL(value);
|
|
866
|
+
} catch {
|
|
867
|
+
return;
|
|
868
|
+
}
|
|
869
|
+
if (url.protocol === "https:") return url.href;
|
|
870
|
+
if (url.protocol === "http:" && [
|
|
871
|
+
"localhost",
|
|
872
|
+
"127.0.0.1",
|
|
873
|
+
"[::1]"
|
|
874
|
+
].includes(url.hostname)) return url.href;
|
|
875
|
+
}
|
|
876
|
+
/** Opens `url` as a fresh top-level page: no opener, no referrer. Returns false when the URL was refused. */
|
|
877
|
+
function openExternal(value, open = window.open.bind(window)) {
|
|
878
|
+
const url = externalUrl(value);
|
|
879
|
+
if (!url) return false;
|
|
880
|
+
open(url, "_blank", "noopener,noreferrer");
|
|
881
|
+
return true;
|
|
882
|
+
}
|
|
883
|
+
// src/lib/ai-spend.ts
|
|
884
|
+
var price = (input, output) => ({
|
|
885
|
+
input,
|
|
886
|
+
output,
|
|
887
|
+
cacheRead: input / 10,
|
|
888
|
+
cacheWrite: input * 1.25
|
|
889
|
+
});
|
|
890
|
+
/**
|
|
891
|
+
* Anthropic's list prices (platform.claude.com pricing, November 2026). A
|
|
892
|
+
* model id matches the longest key it starts with, so dated or suffixed ids
|
|
893
|
+
* price as their family. Haiku 5.5 prompts over 100K tokens cost 5x; calls
|
|
894
|
+
* here are capped well below that in practice, so it is not modeled.
|
|
895
|
+
*/
|
|
896
|
+
var AI_PRICES = {
|
|
897
|
+
"claude-fable-5-2": price(8, 40),
|
|
898
|
+
"claude-fable-5-1": price(10, 50),
|
|
899
|
+
"claude-fable-5": price(10, 50),
|
|
900
|
+
"claude-mythos-5-2": price(8, 40),
|
|
901
|
+
"claude-mythos-5-1": price(10, 50),
|
|
902
|
+
"claude-opus-5-5": price(4, 20),
|
|
903
|
+
"claude-opus-5": price(5, 25),
|
|
904
|
+
"claude-opus-4": price(5, 25),
|
|
905
|
+
"claude-sonnet-5-5": price(2, 10),
|
|
906
|
+
"claude-sonnet-5": price(2, 10),
|
|
907
|
+
"claude-sonnet-4-6": price(3, 15),
|
|
908
|
+
"claude-sonnet-4": price(3, 15),
|
|
909
|
+
"claude-haiku-5-5": price(.1, .5),
|
|
910
|
+
"claude-haiku-4": price(1, 5)
|
|
911
|
+
};
|
|
912
|
+
/** A model the table doesn't know costs as much as the dearest one, so a limit never under-counts. */
|
|
913
|
+
var UNKNOWN_MODEL_PRICE = price(10, 50);
|
|
914
|
+
function priceOf(model) {
|
|
915
|
+
let best;
|
|
916
|
+
for (const k of Object.keys(AI_PRICES)) if (model.startsWith(k) && (!best || k.length > best.length)) best = k;
|
|
917
|
+
return best ? AI_PRICES[best] : UNKNOWN_MODEL_PRICE;
|
|
918
|
+
}
|
|
919
|
+
var n = (v) => typeof v === "number" && Number.isFinite(v) && v > 0 ? v : 0;
|
|
920
|
+
/** A call's cost in micro-dollars (millionths of a dollar), rounded up. */
|
|
921
|
+
function costMicros(model, usage) {
|
|
922
|
+
if (!usage) return 0;
|
|
923
|
+
const p = priceOf(model);
|
|
924
|
+
const input = usage.inputTokens;
|
|
925
|
+
const output = usage.outputTokens;
|
|
926
|
+
let fresh, read, write;
|
|
927
|
+
if (typeof input === "object" && input) {
|
|
928
|
+
read = n(input.cacheRead);
|
|
929
|
+
write = n(input.cacheWrite);
|
|
930
|
+
fresh = input.noCache !== void 0 ? n(input.noCache) : Math.max(0, n(input.total) - read - write);
|
|
931
|
+
} else {
|
|
932
|
+
fresh = n(input);
|
|
933
|
+
read = write = 0;
|
|
934
|
+
}
|
|
935
|
+
const out = typeof output === "object" && output ? n(output.total) : n(output);
|
|
936
|
+
return Math.ceil(fresh * p.input + read * p.cacheRead + write * p.cacheWrite + out * p.output);
|
|
937
|
+
}
|
|
938
|
+
/** A limit as sent or stored, or undefined if it isn't one. */
|
|
939
|
+
function parseLimit(v) {
|
|
940
|
+
if (v === null) return null;
|
|
941
|
+
if (typeof v !== "number" || !Number.isFinite(v)) return void 0;
|
|
942
|
+
const cents = Math.round(v * 100) / 100;
|
|
943
|
+
return cents > 0 && cents <= 1e4 ? cents : void 0;
|
|
944
|
+
}
|
|
945
|
+
var limitMicros = (limit) => limit === null ? Infinity : Math.round(limit * 1e6);
|
|
946
|
+
/** "$5", "$2.50", "$0.004". */
|
|
947
|
+
function formatUsd(dollars) {
|
|
948
|
+
if (dollars === 0) return "$0";
|
|
949
|
+
if (dollars < .01) return `$${dollars.toFixed(3)}`;
|
|
950
|
+
return Number.isInteger(dollars) ? `$${dollars}` : `$${dollars.toFixed(2)}`;
|
|
951
|
+
}
|
|
952
|
+
function formatLimit(limit) {
|
|
953
|
+
return limit === null ? "No limit" : `${formatUsd(limit)}/day`;
|
|
954
|
+
}
|
|
955
|
+
/** Limits are per UTC day, on every path. */
|
|
956
|
+
var utcDay = (now = Date.now()) => new Date(now).toISOString().slice(0, 10);
|
|
957
|
+
// packages/appos-host/src/ai.ts
|
|
958
|
+
/**
|
|
959
|
+
* An AiService that streams through the host's own backend: POST { model?,
|
|
960
|
+
* options } to `url`, read NDJSON lines ({ part } … then { done } or
|
|
961
|
+
* { error }) back. A non-2xx answer fails the call with its { error } body,
|
|
962
|
+
* so a 429 from the gateway reaches the app as code "rate-limited".
|
|
963
|
+
*/
|
|
964
|
+
function aiGateway({ url, headers, credentials = "same-origin" }) {
|
|
965
|
+
return async function* ({ options, model, signal }) {
|
|
966
|
+
const res = await fetch(url, {
|
|
967
|
+
method: "POST",
|
|
968
|
+
headers: {
|
|
969
|
+
"content-type": "application/json",
|
|
970
|
+
...headers
|
|
971
|
+
},
|
|
972
|
+
body: JSON.stringify({
|
|
973
|
+
model,
|
|
974
|
+
options
|
|
975
|
+
}),
|
|
976
|
+
credentials,
|
|
977
|
+
signal
|
|
978
|
+
});
|
|
979
|
+
if (!res.ok || !res.body) throw await httpError(res);
|
|
980
|
+
const reader = res.body.pipeThrough(new TextDecoderStream()).getReader();
|
|
981
|
+
let buffer = "";
|
|
982
|
+
for (;;) {
|
|
983
|
+
const { done, value } = await reader.read();
|
|
984
|
+
buffer += value ?? "";
|
|
985
|
+
const lines = buffer.split("\n");
|
|
986
|
+
buffer = done ? "" : lines.pop();
|
|
987
|
+
for (const line of lines) {
|
|
988
|
+
if (!line.trim()) continue;
|
|
989
|
+
const msg = JSON.parse(line);
|
|
990
|
+
if (msg.error) throw new AiError(msg.error.code, msg.error.message);
|
|
991
|
+
if (msg.done) return;
|
|
992
|
+
if (msg.part) yield revive(msg.part);
|
|
993
|
+
}
|
|
994
|
+
if (done) throw new AiError("provider", "The AI gateway closed the stream early.");
|
|
995
|
+
}
|
|
996
|
+
};
|
|
997
|
+
}
|
|
998
|
+
async function httpError(res) {
|
|
999
|
+
const body = await res.json().catch(() => void 0);
|
|
1000
|
+
const code = body?.error?.code ?? (res.status === 429 ? "rate-limited" : "provider");
|
|
1001
|
+
const message = body?.error?.message ?? `The AI gateway answered ${res.status}.`;
|
|
1002
|
+
return new AiError(code, message);
|
|
1003
|
+
}
|
|
1004
|
+
/** JSON turned the response timestamp into a string; the AI SDK wants a Date. */
|
|
1005
|
+
function revive(part) {
|
|
1006
|
+
if (part.type === "response-metadata" && typeof part.timestamp === "string") return {
|
|
1007
|
+
...part,
|
|
1008
|
+
timestamp: new Date(part.timestamp)
|
|
1009
|
+
};
|
|
1010
|
+
return part;
|
|
1011
|
+
}
|
|
1012
|
+
async function* parts(source) {
|
|
1013
|
+
if (Symbol.asyncIterator in source) {
|
|
1014
|
+
yield* source;
|
|
1015
|
+
return;
|
|
1016
|
+
}
|
|
1017
|
+
const reader = source.getReader();
|
|
1018
|
+
try {
|
|
1019
|
+
for (;;) {
|
|
1020
|
+
const { done, value } = await reader.read();
|
|
1021
|
+
if (done) return;
|
|
1022
|
+
yield value;
|
|
1023
|
+
}
|
|
1024
|
+
} finally {
|
|
1025
|
+
reader.releaseLock();
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
var SPEND_KEY = "appos-host:ai-spend";
|
|
1029
|
+
/** localStorage, or memory for this page load when the browser refuses it. */
|
|
1030
|
+
function browserSpendStore() {
|
|
1031
|
+
let memory = null;
|
|
1032
|
+
return {
|
|
1033
|
+
get() {
|
|
1034
|
+
try {
|
|
1035
|
+
return localStorage.getItem(SPEND_KEY);
|
|
1036
|
+
} catch {
|
|
1037
|
+
return memory;
|
|
1038
|
+
}
|
|
1039
|
+
},
|
|
1040
|
+
set(value) {
|
|
1041
|
+
memory = value;
|
|
1042
|
+
try {
|
|
1043
|
+
localStorage.setItem(SPEND_KEY, value);
|
|
1044
|
+
} catch {}
|
|
1045
|
+
}
|
|
1046
|
+
};
|
|
1047
|
+
}
|
|
1048
|
+
/** What an embedded app sees over its limit. */
|
|
1049
|
+
var embedOverLimitMessage = (limit) => `This app reached its AI spend limit for today on this site (${formatLimit(limit)}).`;
|
|
1050
|
+
function aiBudget(app, limit, store) {
|
|
1051
|
+
const read = () => {
|
|
1052
|
+
try {
|
|
1053
|
+
const s = JSON.parse(store.get() ?? "null");
|
|
1054
|
+
if (s && s.day === utcDay() && s.apps && typeof s.apps === "object") return s;
|
|
1055
|
+
} catch {}
|
|
1056
|
+
return {
|
|
1057
|
+
day: utcDay(),
|
|
1058
|
+
apps: {}
|
|
1059
|
+
};
|
|
1060
|
+
};
|
|
1061
|
+
return {
|
|
1062
|
+
check() {
|
|
1063
|
+
const l = limit();
|
|
1064
|
+
if ((read().apps[app] ?? 0) >= limitMicros(l)) throw new AiError("over-limit", embedOverLimitMessage(l));
|
|
1065
|
+
},
|
|
1066
|
+
meter(part, model) {
|
|
1067
|
+
if (part.type !== "finish") return;
|
|
1068
|
+
const micros = costMicros(model ?? "", part.usage);
|
|
1069
|
+
if (!(micros > 0)) return;
|
|
1070
|
+
const s = read();
|
|
1071
|
+
s.apps[app] = (s.apps[app] ?? 0) + micros;
|
|
1072
|
+
store.set(JSON.stringify(s));
|
|
1073
|
+
}
|
|
1074
|
+
};
|
|
1075
|
+
}
|
|
1076
|
+
/**
|
|
1077
|
+
* Serves one call on the app's port, as appOS's shell does
|
|
1078
|
+
* (src/lib/capabilities/ai.ts): { op: "stream", options, model? } in;
|
|
1079
|
+
* { part } messages, then { done } or { error }, out. { op: "abort" } stops
|
|
1080
|
+
* it. `allowed` runs the permission check (and prompt) first, then `budget`
|
|
1081
|
+
* the app's spend limit. Returns a cleanup that aborts the call.
|
|
1082
|
+
*/
|
|
1083
|
+
function serveAiPort(port, service, allowed, budget) {
|
|
1084
|
+
const abort = new AbortController();
|
|
1085
|
+
const send = (m) => {
|
|
1086
|
+
try {
|
|
1087
|
+
port.postMessage(m);
|
|
1088
|
+
} catch {
|
|
1089
|
+
port.postMessage(JSON.parse(JSON.stringify(m)));
|
|
1090
|
+
}
|
|
1091
|
+
};
|
|
1092
|
+
port.onmessage = async (e) => {
|
|
1093
|
+
const msg = e.data;
|
|
1094
|
+
if (msg?.op === "abort") return abort.abort();
|
|
1095
|
+
if (msg?.op !== "stream") return;
|
|
1096
|
+
try {
|
|
1097
|
+
if (!service) throw new AiError("unavailable", "This site doesn't offer AI to its apps.");
|
|
1098
|
+
if (!await allowed()) throw new AiError("denied", "AI is turned off for this app on this site.");
|
|
1099
|
+
budget?.check();
|
|
1100
|
+
const options = sanitizeAiOptions(msg.options);
|
|
1101
|
+
const model = typeof msg.model === "string" ? msg.model : void 0;
|
|
1102
|
+
let served = model;
|
|
1103
|
+
for await (const part of parts(service({
|
|
1104
|
+
options,
|
|
1105
|
+
model,
|
|
1106
|
+
signal: abort.signal
|
|
1107
|
+
}))) {
|
|
1108
|
+
if (part.type === "response-metadata" && typeof part.modelId === "string") served = part.modelId;
|
|
1109
|
+
budget?.meter(part, served);
|
|
1110
|
+
if (abort.signal.aborted) break;
|
|
1111
|
+
const p = plainPart(part);
|
|
1112
|
+
if (p) send({ part: p });
|
|
1113
|
+
}
|
|
1114
|
+
send({ done: true });
|
|
1115
|
+
} catch (err) {
|
|
1116
|
+
if (!abort.signal.aborted) send({ error: plainAiError(err) });
|
|
1117
|
+
} finally {
|
|
1118
|
+
port.close();
|
|
1119
|
+
}
|
|
1120
|
+
};
|
|
1121
|
+
port.start();
|
|
1122
|
+
return () => {
|
|
1123
|
+
abort.abort();
|
|
1124
|
+
port.close();
|
|
1125
|
+
};
|
|
1126
|
+
}
|
|
1127
|
+
// packages/appos-host/src/embed.ts
|
|
1128
|
+
/** The hosted sandbox: one origin per app identity. */
|
|
1129
|
+
var DEFAULT_SANDBOX = "https://{key}.apps.auiusercontent.com";
|
|
1130
|
+
var EmbedError = class extends Error {
|
|
1131
|
+
code;
|
|
1132
|
+
constructor(code, message) {
|
|
1133
|
+
super(message);
|
|
1134
|
+
this.name = "EmbedError";
|
|
1135
|
+
this.code = code;
|
|
1136
|
+
}
|
|
1137
|
+
};
|
|
1138
|
+
/** The iframe's sandbox flags: the same as appOS's app frames. */
|
|
1139
|
+
var SANDBOX_FLAGS = "allow-scripts allow-same-origin allow-forms allow-popups allow-downloads";
|
|
1140
|
+
/** The app's origin for a sandbox template. */
|
|
1141
|
+
function sandboxOrigin(template, key) {
|
|
1142
|
+
if (!template.includes("{key}")) throw new EmbedError("bad-sandbox", `The sandbox "${template}" has no {key}.`);
|
|
1143
|
+
return new URL(template.replace("{key}", key)).origin;
|
|
1144
|
+
}
|
|
1145
|
+
async function sha256Hex(bytes) {
|
|
1146
|
+
const digest = new Uint8Array(await crypto.subtle.digest("SHA-256", bytes));
|
|
1147
|
+
return Array.from(digest, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
1148
|
+
}
|
|
1149
|
+
/**
|
|
1150
|
+
* Fetches a bundle and checks it as far as the host can. Signed: a valid
|
|
1151
|
+
* integrity block, every signature valid, a DID the sandbox runs; the
|
|
1152
|
+
* sandbox checks it again, fully (keys for did:web/did:plc, the label,
|
|
1153
|
+
* downgrades), before it runs. Unsigned: a .wbn from this page's own
|
|
1154
|
+
* origin, whose URL becomes its identity; the sandbox checks that too.
|
|
1155
|
+
*/
|
|
1156
|
+
async function loadBundle(src, signal) {
|
|
1157
|
+
let bytes;
|
|
1158
|
+
let url;
|
|
1159
|
+
if (typeof src === "string" || src instanceof URL) {
|
|
1160
|
+
url = new URL(src, location.href).href;
|
|
1161
|
+
const res = await fetch(url, {
|
|
1162
|
+
signal,
|
|
1163
|
+
credentials: "omit"
|
|
1164
|
+
});
|
|
1165
|
+
if (!res.ok) throw new EmbedError("fetch-failed", `Could not load ${url}: ${res.status} ${res.statusText}`);
|
|
1166
|
+
bytes = await res.arrayBuffer();
|
|
1167
|
+
} else bytes = src instanceof Uint8Array ? new Uint8Array(src).buffer : src.slice(0);
|
|
1168
|
+
const view = new Uint8Array(bytes);
|
|
1169
|
+
const hash = await sha256Hex(bytes);
|
|
1170
|
+
if (!isSigned(view)) {
|
|
1171
|
+
if (!isWebBundle(view)) throw new EmbedError("not-a-bundle", "Not an app bundle (.wbn or .swbn).");
|
|
1172
|
+
const id = url ? bundleUrlId(url) : void 0;
|
|
1173
|
+
if (!url || !id) throw new EmbedError("unsigned", "An unsigned bundle (.wbn) needs an https URL (or http on localhost).");
|
|
1174
|
+
if (new URL(id).origin !== location.origin) throw new EmbedError("unsigned", `An unsigned bundle must come from this site (${location.origin}). Sign it (appos sign) to embed it from ${new URL(id).origin}.`);
|
|
1175
|
+
return {
|
|
1176
|
+
bytes,
|
|
1177
|
+
hash,
|
|
1178
|
+
id,
|
|
1179
|
+
signed: false,
|
|
1180
|
+
key: await labelForUrl(id),
|
|
1181
|
+
...nameOf(view)
|
|
1182
|
+
};
|
|
1183
|
+
}
|
|
1184
|
+
let signed;
|
|
1185
|
+
try {
|
|
1186
|
+
signed = parseSignedBundle(view);
|
|
1187
|
+
await verifySignatures(signed);
|
|
1188
|
+
} catch (e) {
|
|
1189
|
+
throw new EmbedError("bad-signature", `The bundle's signature does not check out: ${e.message}`);
|
|
1190
|
+
}
|
|
1191
|
+
if (!parseDid(signed.webBundleId)) throw new EmbedError("bad-identity", `"${signed.webBundleId}" is not a DID appOS runs (did:key, did:web, did:plc).`);
|
|
1192
|
+
return {
|
|
1193
|
+
bytes,
|
|
1194
|
+
hash,
|
|
1195
|
+
id: signed.webBundleId,
|
|
1196
|
+
signed: true,
|
|
1197
|
+
key: await labelForId(signed.webBundleId),
|
|
1198
|
+
...nameOf(signed.bundle)
|
|
1199
|
+
};
|
|
1200
|
+
}
|
|
1201
|
+
function nameOf(wbn) {
|
|
1202
|
+
try {
|
|
1203
|
+
const meta = readBundleMeta(wbn);
|
|
1204
|
+
return {
|
|
1205
|
+
name: meta.name ?? "This app",
|
|
1206
|
+
icon: meta.icon,
|
|
1207
|
+
permissions: readManifest(wbn).permissions
|
|
1208
|
+
};
|
|
1209
|
+
} catch {
|
|
1210
|
+
return { name: "This app" };
|
|
1211
|
+
}
|
|
1212
|
+
}
|
|
1213
|
+
/** How long the boot page has to say it is ready. */
|
|
1214
|
+
var READY_TIMEOUT_MS = 15e3;
|
|
1215
|
+
/** Requests from appos-client this host doesn't serve: answered so the app doesn't wait. */
|
|
1216
|
+
var UNSERVED_REQUESTS = /* @__PURE__ */ new Set([
|
|
1217
|
+
"appos:hello",
|
|
1218
|
+
"appos:new-grain",
|
|
1219
|
+
"appos:files-open",
|
|
1220
|
+
"appos:set-title",
|
|
1221
|
+
"appos:share-link",
|
|
1222
|
+
"appos:share-file",
|
|
1223
|
+
"appos:sign-in",
|
|
1224
|
+
"appos:update-from-cloud",
|
|
1225
|
+
"appos:check-update",
|
|
1226
|
+
"appos:backend",
|
|
1227
|
+
"appos:live-file"
|
|
1228
|
+
]);
|
|
1229
|
+
/**
|
|
1230
|
+
* Runs the app at `src` in `iframe`. Returns at once; progress and errors
|
|
1231
|
+
* come through the callbacks.
|
|
1232
|
+
*/
|
|
1233
|
+
function embedApp(iframe, options) {
|
|
1234
|
+
let live = options;
|
|
1235
|
+
const abort = new AbortController();
|
|
1236
|
+
const cleanups = [];
|
|
1237
|
+
/** Answers given to prompts in this embed; a reload asks again. */
|
|
1238
|
+
const answered = /* @__PURE__ */ new Map();
|
|
1239
|
+
const asking = /* @__PURE__ */ new Map();
|
|
1240
|
+
let destroyed = false;
|
|
1241
|
+
/** Posts to the frame once its origin is known. */
|
|
1242
|
+
let post;
|
|
1243
|
+
let scheme = "light";
|
|
1244
|
+
let preference = options.colorScheme ?? "system";
|
|
1245
|
+
const setScheme = (next) => {
|
|
1246
|
+
scheme = next;
|
|
1247
|
+
iframe.style.colorScheme = next;
|
|
1248
|
+
post?.(colorSchemeMessage(next));
|
|
1249
|
+
};
|
|
1250
|
+
let unwatch = watchColorScheme(preference, setScheme);
|
|
1251
|
+
const fail = (error) => {
|
|
1252
|
+
if (destroyed) return;
|
|
1253
|
+
const e = error instanceof EmbedError ? error : new EmbedError("error", error instanceof Error ? error.message : String(error));
|
|
1254
|
+
live.onError?.(e);
|
|
1255
|
+
};
|
|
1256
|
+
const state = (cap) => {
|
|
1257
|
+
const answer = answered.get(cap);
|
|
1258
|
+
if (answer !== void 0) return answer ? "granted" : "denied";
|
|
1259
|
+
return live.permissions?.[cap] ?? "prompt";
|
|
1260
|
+
};
|
|
1261
|
+
const allowed = (app, cap) => {
|
|
1262
|
+
const now = state(cap);
|
|
1263
|
+
if (now !== "prompt") return Promise.resolve(now === "granted");
|
|
1264
|
+
let p = asking.get(cap);
|
|
1265
|
+
if (!p) {
|
|
1266
|
+
const ask = live.onPermissionRequest;
|
|
1267
|
+
p = Promise.resolve(ask ? ask({
|
|
1268
|
+
capability: cap,
|
|
1269
|
+
app
|
|
1270
|
+
}) : false).then((yes) => {
|
|
1271
|
+
answered.set(cap, yes === true);
|
|
1272
|
+
return yes === true;
|
|
1273
|
+
}).finally(() => asking.delete(cap));
|
|
1274
|
+
asking.set(cap, p);
|
|
1275
|
+
}
|
|
1276
|
+
return p;
|
|
1277
|
+
};
|
|
1278
|
+
(async () => {
|
|
1279
|
+
const bundle = await loadBundle(options.src, abort.signal);
|
|
1280
|
+
if (destroyed) return;
|
|
1281
|
+
const origin = sandboxOrigin(options.sandbox ?? "https://{key}.apps.auiusercontent.com", bundle.key);
|
|
1282
|
+
const app = {
|
|
1283
|
+
id: bundle.id,
|
|
1284
|
+
signed: bundle.signed,
|
|
1285
|
+
name: bundle.name,
|
|
1286
|
+
icon: bundle.icon,
|
|
1287
|
+
origin
|
|
1288
|
+
};
|
|
1289
|
+
const limit = () => parseLimit(live.spendLimit) ?? 5;
|
|
1290
|
+
const budget = aiBudget(app.id, limit, options.spendStore ?? browserSpendStore());
|
|
1291
|
+
live.onVerified?.(app);
|
|
1292
|
+
let expectAppLoad = false;
|
|
1293
|
+
const silent = setTimeout(() => fail(new EmbedError("no-sandbox", `The sandbox at ${origin} did not answer. Check that it is reachable and lets ${location.origin} frame it.`)), READY_TIMEOUT_MS);
|
|
1294
|
+
const send = (msg, transfer = []) => iframe.contentWindow?.postMessage(msg, origin, transfer);
|
|
1295
|
+
post = send;
|
|
1296
|
+
const sendBundle = () => {
|
|
1297
|
+
const copy = bundle.bytes.slice(0);
|
|
1298
|
+
if (bundle.signed) send({
|
|
1299
|
+
type: "appos:load",
|
|
1300
|
+
bundle: copy,
|
|
1301
|
+
hash: bundle.hash
|
|
1302
|
+
}, [copy]);
|
|
1303
|
+
else send({
|
|
1304
|
+
type: "appos:load-url",
|
|
1305
|
+
bundle: copy,
|
|
1306
|
+
url: bundle.id,
|
|
1307
|
+
hash: bundle.hash
|
|
1308
|
+
}, [copy]);
|
|
1309
|
+
};
|
|
1310
|
+
const onMessage = (event) => {
|
|
1311
|
+
if (event.origin !== origin || event.source !== iframe.contentWindow) return;
|
|
1312
|
+
const data = event.data;
|
|
1313
|
+
const type = typeof data?.type === "string" ? data.type : "";
|
|
1314
|
+
const id = typeof data?.id === "string" ? data.id : "";
|
|
1315
|
+
switch (type) {
|
|
1316
|
+
case "appos:ready":
|
|
1317
|
+
clearTimeout(silent);
|
|
1318
|
+
send(colorSchemeMessage(scheme));
|
|
1319
|
+
send({
|
|
1320
|
+
type: "appos:open",
|
|
1321
|
+
hash: bundle.hash
|
|
1322
|
+
});
|
|
1323
|
+
return;
|
|
1324
|
+
case "appos:need-bundle":
|
|
1325
|
+
sendBundle();
|
|
1326
|
+
return;
|
|
1327
|
+
case "appos:loaded":
|
|
1328
|
+
expectAppLoad = true;
|
|
1329
|
+
return;
|
|
1330
|
+
case "appos:location":
|
|
1331
|
+
send(colorSchemeMessage(scheme));
|
|
1332
|
+
return;
|
|
1333
|
+
case "appos:error": {
|
|
1334
|
+
const d = event.data;
|
|
1335
|
+
fail(new EmbedError(typeof d.code === "string" ? d.code : "sandbox", String(d.message ?? "The sandbox refused the app.")));
|
|
1336
|
+
return;
|
|
1337
|
+
}
|
|
1338
|
+
case "appos:log": {
|
|
1339
|
+
const d = event.data;
|
|
1340
|
+
live.onLog?.({
|
|
1341
|
+
level: String(d.level ?? "log"),
|
|
1342
|
+
text: String(d.text ?? ""),
|
|
1343
|
+
time: Number(d.time) || Date.now()
|
|
1344
|
+
});
|
|
1345
|
+
return;
|
|
1346
|
+
}
|
|
1347
|
+
case "appos:ai": {
|
|
1348
|
+
const port = event.ports[0];
|
|
1349
|
+
if (port) cleanups.push(serveAiPort(port, live.services?.ai, () => allowed(app, "ai"), budget));
|
|
1350
|
+
return;
|
|
1351
|
+
}
|
|
1352
|
+
case "appos:permission": {
|
|
1353
|
+
const reply = (body) => send({
|
|
1354
|
+
type: "appos:permission:reply",
|
|
1355
|
+
id,
|
|
1356
|
+
...body
|
|
1357
|
+
});
|
|
1358
|
+
if (data?.cap !== "ai") {
|
|
1359
|
+
reply({ state: "denied" });
|
|
1360
|
+
return;
|
|
1361
|
+
}
|
|
1362
|
+
if (!live.services?.ai) reply({ state: "denied" });
|
|
1363
|
+
else if (data.request) allowed(app, "ai").then((yes) => reply({ state: yes ? "granted" : "denied" }));
|
|
1364
|
+
else reply({ state: state("ai") });
|
|
1365
|
+
return;
|
|
1366
|
+
}
|
|
1367
|
+
case "appos:open-settings":
|
|
1368
|
+
send({
|
|
1369
|
+
type: "appos:open-settings:reply",
|
|
1370
|
+
id
|
|
1371
|
+
});
|
|
1372
|
+
return;
|
|
1373
|
+
case "appos:open-external":
|
|
1374
|
+
if (openExternal(data?.url)) send({
|
|
1375
|
+
type: "appos:open-external:reply",
|
|
1376
|
+
id
|
|
1377
|
+
});
|
|
1378
|
+
else send({
|
|
1379
|
+
type: "appos:open-external:reply",
|
|
1380
|
+
id,
|
|
1381
|
+
error: "bad-request",
|
|
1382
|
+
message: "Only https links can be opened."
|
|
1383
|
+
});
|
|
1384
|
+
return;
|
|
1385
|
+
case "appos:voice": {
|
|
1386
|
+
const port = event.ports[0];
|
|
1387
|
+
port?.postMessage({
|
|
1388
|
+
event: "error",
|
|
1389
|
+
code: "unavailable",
|
|
1390
|
+
message: "This site doesn't offer voice to embedded apps."
|
|
1391
|
+
});
|
|
1392
|
+
port?.postMessage({ event: "end" });
|
|
1393
|
+
port?.close();
|
|
1394
|
+
return;
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
const port = event.ports[0];
|
|
1398
|
+
const message = "This site doesn't offer that to embedded apps.";
|
|
1399
|
+
if (port) {
|
|
1400
|
+
port.postMessage({ error: {
|
|
1401
|
+
code: "unavailable",
|
|
1402
|
+
message
|
|
1403
|
+
} });
|
|
1404
|
+
port.close();
|
|
1405
|
+
}
|
|
1406
|
+
if (UNSERVED_REQUESTS.has(type)) send({
|
|
1407
|
+
type: `${type}:reply`,
|
|
1408
|
+
id,
|
|
1409
|
+
error: "unavailable",
|
|
1410
|
+
message
|
|
1411
|
+
});
|
|
1412
|
+
};
|
|
1413
|
+
const onLoad = () => {
|
|
1414
|
+
if (!expectAppLoad) return;
|
|
1415
|
+
expectAppLoad = false;
|
|
1416
|
+
live.onLoad?.(app);
|
|
1417
|
+
};
|
|
1418
|
+
window.addEventListener("message", onMessage);
|
|
1419
|
+
iframe.addEventListener("load", onLoad);
|
|
1420
|
+
const offPinch = forwardFramePinch(iframe, origin);
|
|
1421
|
+
cleanups.push(() => {
|
|
1422
|
+
clearTimeout(silent);
|
|
1423
|
+
window.removeEventListener("message", onMessage);
|
|
1424
|
+
iframe.removeEventListener("load", onLoad);
|
|
1425
|
+
offPinch();
|
|
1426
|
+
});
|
|
1427
|
+
iframe.setAttribute("sandbox", SANDBOX_FLAGS);
|
|
1428
|
+
const extra = frameAllow(bundle.permissions);
|
|
1429
|
+
if (extra.length) iframe.allow = [.../* @__PURE__ */ new Set([...iframe.allow.split(";").map((f) => f.trim()).filter(Boolean), ...extra])].join("; ");
|
|
1430
|
+
iframe.src = `${origin}/__appos/boot.html`;
|
|
1431
|
+
})().catch((e) => {
|
|
1432
|
+
if (!abort.signal.aborted) fail(e);
|
|
1433
|
+
});
|
|
1434
|
+
return {
|
|
1435
|
+
update(next) {
|
|
1436
|
+
live = next;
|
|
1437
|
+
const nextPreference = next.colorScheme ?? "system";
|
|
1438
|
+
if (nextPreference !== preference) {
|
|
1439
|
+
preference = nextPreference;
|
|
1440
|
+
unwatch();
|
|
1441
|
+
unwatch = watchColorScheme(preference, setScheme);
|
|
1442
|
+
}
|
|
1443
|
+
},
|
|
1444
|
+
destroy() {
|
|
1445
|
+
destroyed = true;
|
|
1446
|
+
unwatch();
|
|
1447
|
+
post = void 0;
|
|
1448
|
+
abort.abort();
|
|
1449
|
+
for (const c of cleanups.splice(0)) c();
|
|
1450
|
+
iframe.removeAttribute("src");
|
|
1451
|
+
}
|
|
1452
|
+
};
|
|
1453
|
+
}
|
|
1454
|
+
// packages/appos-host/src/AppOSApp.tsx
|
|
1455
|
+
var LABELS = { ai: "use AI" };
|
|
1456
|
+
/**
|
|
1457
|
+
* An appOS app in a sandboxed frame, with this page as its shell. `services`
|
|
1458
|
+
* answer its capability calls; `permissions` are the defaults ("prompt" when
|
|
1459
|
+
* missing). Without onPermissionRequest, a "prompt" shows a small built-in
|
|
1460
|
+
* question over the frame. `colorScheme` ("light", "dark", default
|
|
1461
|
+
* "system") is the app's light or dark; pass the site's theme to have the
|
|
1462
|
+
* app follow it. Changing services, permissions, colorScheme or callbacks
|
|
1463
|
+
* doesn't reload the app; changing `src` or `sandbox` does.
|
|
1464
|
+
*/
|
|
1465
|
+
function AppOSApp({ src, sandbox, className, style, title, ...live }) {
|
|
1466
|
+
const frame = useRef(null);
|
|
1467
|
+
const embed = useRef(null);
|
|
1468
|
+
const [app, setApp] = useState();
|
|
1469
|
+
const [loaded, setLoaded] = useState(false);
|
|
1470
|
+
const [error, setError] = useState();
|
|
1471
|
+
const [prompt, setPrompt] = useState();
|
|
1472
|
+
const liveOptions = {
|
|
1473
|
+
...live,
|
|
1474
|
+
onVerified: (a) => {
|
|
1475
|
+
setApp(a);
|
|
1476
|
+
live.onVerified?.(a);
|
|
1477
|
+
},
|
|
1478
|
+
onLoad: (a) => {
|
|
1479
|
+
setLoaded(true);
|
|
1480
|
+
live.onLoad?.(a);
|
|
1481
|
+
},
|
|
1482
|
+
onError: (e) => {
|
|
1483
|
+
setError(e);
|
|
1484
|
+
live.onError?.(e);
|
|
1485
|
+
},
|
|
1486
|
+
onPermissionRequest: live.onPermissionRequest ?? ((request) => new Promise((answer) => setPrompt({
|
|
1487
|
+
request,
|
|
1488
|
+
answer
|
|
1489
|
+
})))
|
|
1490
|
+
};
|
|
1491
|
+
const latest = useRef(liveOptions);
|
|
1492
|
+
latest.current = liveOptions;
|
|
1493
|
+
useEffect(() => {
|
|
1494
|
+
embed.current?.update(latest.current);
|
|
1495
|
+
});
|
|
1496
|
+
useEffect(() => {
|
|
1497
|
+
const iframe = frame.current;
|
|
1498
|
+
if (!iframe) return;
|
|
1499
|
+
setApp(void 0);
|
|
1500
|
+
setLoaded(false);
|
|
1501
|
+
setError(void 0);
|
|
1502
|
+
const e = embedApp(iframe, {
|
|
1503
|
+
...latest.current,
|
|
1504
|
+
src,
|
|
1505
|
+
sandbox
|
|
1506
|
+
});
|
|
1507
|
+
embed.current = e;
|
|
1508
|
+
return () => {
|
|
1509
|
+
e.destroy();
|
|
1510
|
+
embed.current = null;
|
|
1511
|
+
setPrompt((p) => {
|
|
1512
|
+
p?.answer(false);
|
|
1513
|
+
});
|
|
1514
|
+
};
|
|
1515
|
+
}, [src, sandbox]);
|
|
1516
|
+
const answer = (yes) => {
|
|
1517
|
+
prompt?.answer(yes);
|
|
1518
|
+
setPrompt(void 0);
|
|
1519
|
+
};
|
|
1520
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
1521
|
+
className,
|
|
1522
|
+
style: {
|
|
1523
|
+
position: "relative",
|
|
1524
|
+
colorScheme: live.colorScheme && live.colorScheme !== "system" ? live.colorScheme : void 0,
|
|
1525
|
+
...style
|
|
1526
|
+
},
|
|
1527
|
+
"data-appos-app": app?.id,
|
|
1528
|
+
children: [
|
|
1529
|
+
/* @__PURE__ */ jsx("iframe", {
|
|
1530
|
+
ref: frame,
|
|
1531
|
+
title: title ?? app?.name ?? "appOS app",
|
|
1532
|
+
allow: BASE_FRAME_ALLOW.join("; "),
|
|
1533
|
+
style: {
|
|
1534
|
+
border: 0,
|
|
1535
|
+
width: "100%",
|
|
1536
|
+
height: "100%",
|
|
1537
|
+
display: "block",
|
|
1538
|
+
visibility: loaded ? "visible" : "hidden"
|
|
1539
|
+
}
|
|
1540
|
+
}),
|
|
1541
|
+
!loaded && !error && /* @__PURE__ */ jsxs("div", {
|
|
1542
|
+
role: "status",
|
|
1543
|
+
style: overlay,
|
|
1544
|
+
children: [
|
|
1545
|
+
"Loading ",
|
|
1546
|
+
app?.name ?? "app",
|
|
1547
|
+
"…"
|
|
1548
|
+
]
|
|
1549
|
+
}),
|
|
1550
|
+
error && /* @__PURE__ */ jsx("div", {
|
|
1551
|
+
role: "alert",
|
|
1552
|
+
style: overlay,
|
|
1553
|
+
children: /* @__PURE__ */ jsx("p", {
|
|
1554
|
+
style: {
|
|
1555
|
+
maxWidth: 420,
|
|
1556
|
+
margin: 0
|
|
1557
|
+
},
|
|
1558
|
+
children: error.message
|
|
1559
|
+
})
|
|
1560
|
+
}),
|
|
1561
|
+
prompt && /* @__PURE__ */ jsx("div", {
|
|
1562
|
+
role: "dialog",
|
|
1563
|
+
"aria-label": "Permission",
|
|
1564
|
+
style: {
|
|
1565
|
+
...overlay,
|
|
1566
|
+
background: "rgba(0,0,0,0.35)"
|
|
1567
|
+
},
|
|
1568
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
1569
|
+
style: card,
|
|
1570
|
+
children: [/* @__PURE__ */ jsxs("p", {
|
|
1571
|
+
style: { margin: "0 0 12px" },
|
|
1572
|
+
children: [
|
|
1573
|
+
/* @__PURE__ */ jsx("strong", { children: prompt.request.app.name }),
|
|
1574
|
+
" wants to ",
|
|
1575
|
+
LABELS[prompt.request.capability],
|
|
1576
|
+
"."
|
|
1577
|
+
]
|
|
1578
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
1579
|
+
style: {
|
|
1580
|
+
display: "flex",
|
|
1581
|
+
gap: 8,
|
|
1582
|
+
justifyContent: "flex-end"
|
|
1583
|
+
},
|
|
1584
|
+
children: [/* @__PURE__ */ jsx("button", {
|
|
1585
|
+
type: "button",
|
|
1586
|
+
onClick: () => answer(false),
|
|
1587
|
+
children: "Don't allow"
|
|
1588
|
+
}), /* @__PURE__ */ jsx("button", {
|
|
1589
|
+
type: "button",
|
|
1590
|
+
onClick: () => answer(true),
|
|
1591
|
+
children: "Allow"
|
|
1592
|
+
})]
|
|
1593
|
+
})]
|
|
1594
|
+
})
|
|
1595
|
+
})
|
|
1596
|
+
]
|
|
1597
|
+
});
|
|
1598
|
+
}
|
|
1599
|
+
var overlay = {
|
|
1600
|
+
position: "absolute",
|
|
1601
|
+
inset: 0,
|
|
1602
|
+
display: "flex",
|
|
1603
|
+
alignItems: "center",
|
|
1604
|
+
justifyContent: "center",
|
|
1605
|
+
padding: 16,
|
|
1606
|
+
textAlign: "center",
|
|
1607
|
+
font: "14px/1.4 system-ui, sans-serif"
|
|
1608
|
+
};
|
|
1609
|
+
var card = {
|
|
1610
|
+
background: "Canvas",
|
|
1611
|
+
color: "CanvasText",
|
|
1612
|
+
borderRadius: 10,
|
|
1613
|
+
padding: 16,
|
|
1614
|
+
maxWidth: 360,
|
|
1615
|
+
boxShadow: "0 8px 30px rgba(0,0,0,0.25)",
|
|
1616
|
+
textAlign: "left"
|
|
1617
|
+
};
|
|
1618
|
+
export { AiError, AppOSApp, DEFAULT_SANDBOX, EmbedError, aiGateway, embedApp, loadBundle };
|