@assistant-ui/appos 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/src.js +365 -71
- package/dist/index.js +58 -14
- package/dist/next-page.js +1 -1
- package/dist/pack.js +8 -3
- package/dist/types/packages/appos-client/src/index.d.ts +270 -76
- package/dist/types/src/lib/pack.d.ts +1 -1
- package/dist/types/src/lib/swbn/manifest.d.ts +53 -15
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -650,10 +650,20 @@ function parsePermissions(v) {
|
|
|
650
650
|
const out = [...new Set(v.filter((p) => typeof p === "string" && Object.hasOwn(FRAME_PERMISSIONS, p)))];
|
|
651
651
|
return out.length ? out : void 0;
|
|
652
652
|
}
|
|
653
|
+
/** A page's path as appos.embeddable lists it: on the app's origin, never the sandbox's own (/__appos/). */
|
|
654
|
+
var EMBEDDABLE_PATH = /^\/(?!\/|\\|__appos\/)[^?#\s]{0,255}$/;
|
|
655
|
+
/** appos.embeddable: the paths it lists, once each, at most 16; anything else is ignored. */
|
|
656
|
+
function parseEmbeddable(v) {
|
|
657
|
+
if (!Array.isArray(v)) return void 0;
|
|
658
|
+
const out = [...new Set(v.filter((p) => typeof p === "string" && EMBEDDABLE_PATH.test(p)))].slice(0, 16);
|
|
659
|
+
return out.length ? out : void 0;
|
|
660
|
+
}
|
|
653
661
|
/**
|
|
654
662
|
* What every app's frame gets: copying (share links and the like) and keeping the screen on while it's in front (a
|
|
655
663
|
* dictation, a recipe). Without screen-wake-lock Chrome refuses navigator.wakeLock in the frame by permissions policy.
|
|
656
664
|
*/
|
|
665
|
+
/** appos.extension: 1 to 16 lowercase letters or digits, no dot. */
|
|
666
|
+
var EXTENSION_RE = /^[a-z0-9]{1,16}$/;
|
|
657
667
|
var BASE_FRAME_ALLOW = ["clipboard-write", "screen-wake-lock"];
|
|
658
668
|
/** The allow features for an app's frame: what it declared (FRAME_PERMISSIONS). */
|
|
659
669
|
function frameAllow(permissions) {
|
|
@@ -668,24 +678,24 @@ var cleanMain = (m) => {
|
|
|
668
678
|
};
|
|
669
679
|
/**
|
|
670
680
|
* appos.actors: { Name: { main } }. v1 runs one bundled module per app, so
|
|
671
|
-
* every
|
|
681
|
+
* every LiveWorker names the same main. Returns the normalized LiveWorkers or an error.
|
|
672
682
|
*/
|
|
673
|
-
function
|
|
674
|
-
if (!v || typeof v !== "object" || Array.isArray(v)) return { error: "appos.actors must be { \"Name\": { \"main\": \"
|
|
683
|
+
function parseLiveWorkers(v) {
|
|
684
|
+
if (!v || typeof v !== "object" || Array.isArray(v)) return { error: "appos.actors must be { \"Name\": { \"main\": \"worker.js\" } }." };
|
|
675
685
|
const entries = Object.entries(v);
|
|
676
|
-
if (entries.length === 0 || entries.length > 16) return { error: `appos.actors must list 1 to 16
|
|
677
|
-
const
|
|
686
|
+
if (entries.length === 0 || entries.length > 16) return { error: `appos.actors must list 1 to 16 LiveWorker classes.` };
|
|
687
|
+
const liveWorkers = {};
|
|
678
688
|
let main;
|
|
679
689
|
for (const [name, a] of entries) {
|
|
680
690
|
if (!CLASS_NAME.test(name)) return { error: `appos.actors: "${name}" is not a class name, like Board.` };
|
|
681
691
|
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
|
|
683
|
-
if (main !== void 0 && m !== main) return { error: "appos.actors: every
|
|
692
|
+
if (!m) return { error: `appos.actors.${name}.main must be a .js path inside the bundle, like worker.js.` };
|
|
693
|
+
if (main !== void 0 && m !== main) return { error: "appos.actors: every LiveWorker class must name the same main module for now." };
|
|
684
694
|
main = m;
|
|
685
|
-
|
|
695
|
+
liveWorkers[name] = { main: m };
|
|
686
696
|
}
|
|
687
697
|
return {
|
|
688
|
-
actors,
|
|
698
|
+
actors: liveWorkers,
|
|
689
699
|
main
|
|
690
700
|
};
|
|
691
701
|
}
|
|
@@ -702,7 +712,19 @@ function parseServer(v) {
|
|
|
702
712
|
routes: [...new Set(routes)]
|
|
703
713
|
};
|
|
704
714
|
}
|
|
705
|
-
|
|
715
|
+
var OPEN_WEB_DEFAULT_BODY = 1048576;
|
|
716
|
+
/** The most the platform streams to a LiveWorker in one request from the open web (the Workers runtime's own cap). */
|
|
717
|
+
var OPEN_WEB_MAX_BODY = 104857600;
|
|
718
|
+
/** appos.openWeb: true, {} or { maxBody: <bytes> }, the body capped at OPEN_WEB_MAX_BODY. */
|
|
719
|
+
function parseOpenWeb(v) {
|
|
720
|
+
if (v === true) return { maxBody: OPEN_WEB_DEFAULT_BODY };
|
|
721
|
+
if (!v || typeof v !== "object" || Array.isArray(v)) return { error: "appos.openWeb must be { \"maxBody\": <bytes> }." };
|
|
722
|
+
const max = v.maxBody;
|
|
723
|
+
if (max === void 0) return { maxBody: OPEN_WEB_DEFAULT_BODY };
|
|
724
|
+
if (!Number.isSafeInteger(max) || max < 1) return { error: "appos.openWeb.maxBody must be a whole number of bytes." };
|
|
725
|
+
return { maxBody: Math.min(max, OPEN_WEB_MAX_BODY) };
|
|
726
|
+
}
|
|
727
|
+
/** Validates appos.actors, appos.server, appos.network, appos.openWeb and appos.mcp; never throws. */
|
|
706
728
|
function parseBackend(appos) {
|
|
707
729
|
const out = {};
|
|
708
730
|
const net = appos.network;
|
|
@@ -718,7 +740,7 @@ function parseBackend(appos) {
|
|
|
718
740
|
if (!out.backendError) out.server = server;
|
|
719
741
|
}
|
|
720
742
|
if (!("actors" in appos)) return out;
|
|
721
|
-
const r =
|
|
743
|
+
const r = parseLiveWorkers(appos.actors);
|
|
722
744
|
if ("error" in r) {
|
|
723
745
|
out.backendError = r.error;
|
|
724
746
|
return out;
|
|
@@ -730,6 +752,15 @@ function parseBackend(appos) {
|
|
|
730
752
|
};
|
|
731
753
|
out.actors = r.actors;
|
|
732
754
|
}
|
|
755
|
+
if ("openWeb" in appos && !out.backendError) {
|
|
756
|
+
const open = parseOpenWeb(appos.openWeb);
|
|
757
|
+
if ("error" in open) out.backendError = open.error;
|
|
758
|
+
else out.openWeb = open;
|
|
759
|
+
}
|
|
760
|
+
if ("mcp" in appos && !out.backendError) {
|
|
761
|
+
if (appos.mcp === true) out.mcp = true;
|
|
762
|
+
else out.backendError = "appos.mcp must be true: each file serves MCP at its address + /mcp (onMcp).";
|
|
763
|
+
}
|
|
733
764
|
return out;
|
|
734
765
|
}
|
|
735
766
|
/** A channel name: lowercase, like "beta" or "dev". */
|
|
@@ -784,9 +815,13 @@ function readManifest(wbn) {
|
|
|
784
815
|
if (m.appos && typeof m.appos === "object" && typeof m.appos.update === "string") out.update = m.appos.update;
|
|
785
816
|
if (m.appos && typeof m.appos === "object" && m.appos.home === true) out.home = true;
|
|
786
817
|
if (m.appos && typeof m.appos === "object" && m.appos.multiple === true) out.multiple = true;
|
|
818
|
+
if (m.appos && typeof m.appos === "object" && typeof m.appos.extension === "string" && EXTENSION_RE.test(m.appos.extension)) out.extension = m.appos.extension;
|
|
819
|
+
if (m.appos && typeof m.appos === "object" && m.appos.placement === "server") out.placement = "server";
|
|
787
820
|
if (m.appos && typeof m.appos === "object") {
|
|
788
821
|
const permissions = parsePermissions(m.appos.permissions);
|
|
789
822
|
if (permissions) out.permissions = permissions;
|
|
823
|
+
const embeddable = parseEmbeddable(m.appos.embeddable);
|
|
824
|
+
if (embeddable) out.embeddable = embeddable;
|
|
790
825
|
}
|
|
791
826
|
if (m.version !== void 0) out.version = typeof m.version === "string" ? m.version : JSON.stringify(m.version);
|
|
792
827
|
if (m.appos && typeof m.appos === "object" && "build" in m.appos) {
|
|
@@ -1216,7 +1251,12 @@ var READY_TIMEOUT_MS = 15e3;
|
|
|
1216
1251
|
var UNSERVED_REQUESTS = /* @__PURE__ */ new Set([
|
|
1217
1252
|
"appos:hello",
|
|
1218
1253
|
"appos:new-grain",
|
|
1254
|
+
"appos:open-grain",
|
|
1255
|
+
"appos:open-web",
|
|
1219
1256
|
"appos:files-open",
|
|
1257
|
+
"appos:files-list",
|
|
1258
|
+
"appos:files-recent",
|
|
1259
|
+
"appos:files-open-address",
|
|
1220
1260
|
"appos:set-title",
|
|
1221
1261
|
"appos:share-link",
|
|
1222
1262
|
"appos:share-file",
|
|
@@ -1298,13 +1338,15 @@ function embedApp(iframe, options) {
|
|
|
1298
1338
|
if (bundle.signed) send({
|
|
1299
1339
|
type: "appos:load",
|
|
1300
1340
|
bundle: copy,
|
|
1301
|
-
hash: bundle.hash
|
|
1341
|
+
hash: bundle.hash,
|
|
1342
|
+
ack: true
|
|
1302
1343
|
}, [copy]);
|
|
1303
1344
|
else send({
|
|
1304
1345
|
type: "appos:load-url",
|
|
1305
1346
|
bundle: copy,
|
|
1306
1347
|
url: bundle.id,
|
|
1307
|
-
hash: bundle.hash
|
|
1348
|
+
hash: bundle.hash,
|
|
1349
|
+
ack: true
|
|
1308
1350
|
}, [copy]);
|
|
1309
1351
|
};
|
|
1310
1352
|
const onMessage = (event) => {
|
|
@@ -1318,7 +1360,8 @@ function embedApp(iframe, options) {
|
|
|
1318
1360
|
send(colorSchemeMessage(scheme));
|
|
1319
1361
|
send({
|
|
1320
1362
|
type: "appos:open",
|
|
1321
|
-
hash: bundle.hash
|
|
1363
|
+
hash: bundle.hash,
|
|
1364
|
+
ack: true
|
|
1322
1365
|
});
|
|
1323
1366
|
return;
|
|
1324
1367
|
case "appos:need-bundle":
|
|
@@ -1326,6 +1369,7 @@ function embedApp(iframe, options) {
|
|
|
1326
1369
|
return;
|
|
1327
1370
|
case "appos:loaded":
|
|
1328
1371
|
expectAppLoad = true;
|
|
1372
|
+
send({ type: "appos:loaded:reply" });
|
|
1329
1373
|
return;
|
|
1330
1374
|
case "appos:location":
|
|
1331
1375
|
send(colorSchemeMessage(scheme));
|
package/dist/next-page.js
CHANGED
|
@@ -15,7 +15,7 @@ var server;
|
|
|
15
15
|
var local = () => server ??= import(SERVER_URL).then((m) => m.default);
|
|
16
16
|
/** Set once this page has no cloud at all (outside appOS, or an embed); signed out is checked again each time. */
|
|
17
17
|
var noCloud = false;
|
|
18
|
-
/** A route handler request: the app's
|
|
18
|
+
/** A route handler request: the app's server Worker in the cloud, else the module in this page. */
|
|
19
19
|
async function serverFetch(request, signal) {
|
|
20
20
|
if (!noCloud) {
|
|
21
21
|
const url = new URL(request.url);
|
package/dist/pack.js
CHANGED
|
@@ -50,14 +50,19 @@ function normalizePath(input) {
|
|
|
50
50
|
return path;
|
|
51
51
|
}
|
|
52
52
|
/**
|
|
53
|
+
* TypeScript declarations and their maps, which a library build (aui-build)
|
|
54
|
+
* writes beside its JavaScript. An app has no use for them, so a pack skips them.
|
|
55
|
+
*/
|
|
56
|
+
var DECLARATION = /\.d\.[cm]?ts(\.map)?$/;
|
|
57
|
+
/**
|
|
53
58
|
* Builds a .wbn. `/index.html` is also served at `/`, the primary URL, and
|
|
54
|
-
* `/a/index.html` at `/a`.
|
|
59
|
+
* `/a/index.html` at `/a`. Declaration files (.d.ts, .d.ts.map) stay out.
|
|
55
60
|
*/
|
|
56
61
|
function packFiles(files) {
|
|
57
|
-
const sorted =
|
|
62
|
+
const sorted = files.map((f) => ({
|
|
58
63
|
...f,
|
|
59
64
|
path: normalizePath(f.path)
|
|
60
|
-
})).sort((a, b) => a.path < b.path ? -1 : a.path > b.path ? 1 : 0);
|
|
65
|
+
})).filter((f) => !DECLARATION.test(f.path)).sort((a, b) => a.path < b.path ? -1 : a.path > b.path ? 1 : 0);
|
|
61
66
|
if (!sorted.find((f) => f.path === "/index.html")) throw new Error("An app needs an index.html at its root");
|
|
62
67
|
const builder = new BundleBuilder("b2");
|
|
63
68
|
for (const file of sorted) {
|