@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/chunks/src.js
CHANGED
|
@@ -9,7 +9,7 @@ function releaseText(details) {
|
|
|
9
9
|
/** The sheet's text for update-required. Never prints a missing version. */
|
|
10
10
|
function updateRequiredText(appName, details) {
|
|
11
11
|
const runs = releaseText(details);
|
|
12
|
-
return runs ? `This
|
|
12
|
+
return runs ? `This live file runs ${appName} ${runs}. Update to join.` : `This live file needs a newer ${appName}. Update to join.`;
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
15
|
* The sheet for upgrade-pending / upgrade-denied. The owner (`canApprove`) gets
|
|
@@ -165,16 +165,147 @@ function tell(type, data) {
|
|
|
165
165
|
}, parentOrigin() ?? "*");
|
|
166
166
|
} catch {}
|
|
167
167
|
}
|
|
168
|
+
async function openFiles(arg = {}) {
|
|
169
|
+
if (typeof arg === "string") {
|
|
170
|
+
await ask("appos:files-open-address", { address: arg }, 6e4);
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
const { multiple = false, kind } = arg;
|
|
174
|
+
try {
|
|
175
|
+
return await ask("appos:files-open", {
|
|
176
|
+
multiple,
|
|
177
|
+
...kind ? { kind } : {}
|
|
178
|
+
}, 864e5);
|
|
179
|
+
} catch (e) {
|
|
180
|
+
if (e instanceof CloudError && e.code === "cancelled") return null;
|
|
181
|
+
throw e;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
168
184
|
var hello;
|
|
169
185
|
var getHello = () => hello ??= ask("appos:hello").then((h) => {
|
|
170
186
|
if (h.removed?.length) for (const fn of removedListeners) fn(h.removed);
|
|
171
187
|
removedSeen = h.removed ?? [];
|
|
188
|
+
if (h.embedded) shownBy(h.selection ?? null);
|
|
172
189
|
return h;
|
|
173
190
|
}, (e) => (hello = void 0, Promise.reject(e)));
|
|
174
191
|
var removedListeners = [];
|
|
175
192
|
var removedSeen;
|
|
176
193
|
/** "0.0.1 (12)" for apps with builds, else the version. */
|
|
177
194
|
var labelOf = (h) => h.build === void 0 ? h.version : `${h.version} (${h.build})`;
|
|
195
|
+
var embedSeq = 0;
|
|
196
|
+
/**
|
|
197
|
+
* Shows the page at `path` of the app with DID `app` in `slot`, a box of this page's that is the page's place: as wide
|
|
198
|
+
* as the slot, and as tall as the page's content (the slot's height is set to it). The shell runs the page as a frame of
|
|
199
|
+
* its own app, laid over the slot, so it keeps its own storage, files and grants, and this page never reaches into it.
|
|
200
|
+
* The app has to list `path` in its manifest's appos.embeddable. `remove()` takes it away. Outside a shell, nothing.
|
|
201
|
+
*/
|
|
202
|
+
function embed(slot, app, path) {
|
|
203
|
+
if (typeof app !== "string" || !app || typeof path !== "string" || !path.startsWith("/")) throw new TypeError("appos.embed takes an element, an app's DID and a path starting with /.");
|
|
204
|
+
if (window.parent === window) return { remove() {} };
|
|
205
|
+
const id = `embed-${++embedSeq}`;
|
|
206
|
+
let sent = "";
|
|
207
|
+
let frame = 0;
|
|
208
|
+
const send = () => {
|
|
209
|
+
frame = 0;
|
|
210
|
+
const r = slot.getBoundingClientRect();
|
|
211
|
+
const rect = {
|
|
212
|
+
x: r.left,
|
|
213
|
+
y: r.top,
|
|
214
|
+
width: r.width,
|
|
215
|
+
height: r.height
|
|
216
|
+
};
|
|
217
|
+
const key = JSON.stringify(rect);
|
|
218
|
+
if (key === sent) return;
|
|
219
|
+
sent = key;
|
|
220
|
+
tell("appos:embed", {
|
|
221
|
+
id,
|
|
222
|
+
app,
|
|
223
|
+
path,
|
|
224
|
+
rect
|
|
225
|
+
});
|
|
226
|
+
};
|
|
227
|
+
const later = () => void (frame ||= requestAnimationFrame(send));
|
|
228
|
+
const sizes = new ResizeObserver(later);
|
|
229
|
+
sizes.observe(slot);
|
|
230
|
+
sizes.observe(document.documentElement);
|
|
231
|
+
addEventListener("scroll", later, {
|
|
232
|
+
capture: true,
|
|
233
|
+
passive: true
|
|
234
|
+
});
|
|
235
|
+
addEventListener("resize", later);
|
|
236
|
+
const onSize = (e) => {
|
|
237
|
+
const d = e.data;
|
|
238
|
+
if (e.source !== window.parent || d?.type !== "appos:embed-size" || d.id !== id || typeof d.height !== "number") return;
|
|
239
|
+
slot.style.height = `${d.height}px`;
|
|
240
|
+
};
|
|
241
|
+
addEventListener("message", onSize);
|
|
242
|
+
send();
|
|
243
|
+
return { remove() {
|
|
244
|
+
if (frame) cancelAnimationFrame(frame);
|
|
245
|
+
sizes.disconnect();
|
|
246
|
+
removeEventListener("scroll", later, { capture: true });
|
|
247
|
+
removeEventListener("resize", later);
|
|
248
|
+
removeEventListener("message", onSize);
|
|
249
|
+
tell("appos:embed-end", { id });
|
|
250
|
+
} };
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Tells the pages this one shows (appos.embed) what is selected here, as it changes: the words, the address of what
|
|
254
|
+
* they are in, and their lines there. null: nothing is selected. Nothing comes back.
|
|
255
|
+
*/
|
|
256
|
+
function setSelection(selection) {
|
|
257
|
+
if (selection !== null && (typeof selection?.address !== "string" || typeof selection.text !== "string")) throw new TypeError("appos.setSelection takes { address, lines?, text } or null.");
|
|
258
|
+
tell("appos:selection", { selection: selection && {
|
|
259
|
+
address: selection.address,
|
|
260
|
+
...selection.lines && { lines: [selection.lines[0], selection.lines[1]] },
|
|
261
|
+
text: selection.text
|
|
262
|
+
} });
|
|
263
|
+
}
|
|
264
|
+
var shownSelection = null;
|
|
265
|
+
var shown = false;
|
|
266
|
+
var selectionListeners = /* @__PURE__ */ new Set();
|
|
267
|
+
/** This frame is a page another app shows: its selection from now on, and the page's height for the slot. */
|
|
268
|
+
function shownBy(first) {
|
|
269
|
+
if (shown) return;
|
|
270
|
+
shown = true;
|
|
271
|
+
shownSelection = first;
|
|
272
|
+
for (const fn of [...selectionListeners]) fn(shownSelection);
|
|
273
|
+
addEventListener("message", (e) => {
|
|
274
|
+
const d = e.data;
|
|
275
|
+
if (e.source !== window.parent || d?.type !== "appos:selection") return;
|
|
276
|
+
shownSelection = d.selection ?? null;
|
|
277
|
+
for (const fn of [...selectionListeners]) fn(shownSelection);
|
|
278
|
+
});
|
|
279
|
+
reportHeight();
|
|
280
|
+
}
|
|
281
|
+
/** The page's height is its body's: sent as it changes, for the slot. A page that is shown keeps its body as tall as what it shows. */
|
|
282
|
+
function reportHeight() {
|
|
283
|
+
let last = -1;
|
|
284
|
+
const send = () => {
|
|
285
|
+
const body = document.body;
|
|
286
|
+
if (!body) return;
|
|
287
|
+
const height = Math.ceil(body.getBoundingClientRect().bottom + scrollY + (parseFloat(getComputedStyle(body).marginBottom) || 0));
|
|
288
|
+
if (height === last) return;
|
|
289
|
+
last = height;
|
|
290
|
+
tell("appos:embed-size", { height });
|
|
291
|
+
};
|
|
292
|
+
const watch = () => {
|
|
293
|
+
new ResizeObserver(send).observe(document.body);
|
|
294
|
+
send();
|
|
295
|
+
};
|
|
296
|
+
if (document.body) watch();
|
|
297
|
+
else addEventListener("DOMContentLoaded", watch, { once: true });
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* For a page another app shows (appos.embed): `fn` hears what is selected in that app, now and each time it changes
|
|
301
|
+
* (null for nothing), with the app. Never called in a page no app shows. Returns the unsubscribe.
|
|
302
|
+
*/
|
|
303
|
+
function onSelection(fn) {
|
|
304
|
+
selectionListeners.add(fn);
|
|
305
|
+
if (shown) queueMicrotask(() => selectionListeners.has(fn) && fn(shownSelection));
|
|
306
|
+
else if (window.parent !== window) getHello().catch(() => {});
|
|
307
|
+
return () => void selectionListeners.delete(fn);
|
|
308
|
+
}
|
|
178
309
|
var current;
|
|
179
310
|
var upgradeListeners = [];
|
|
180
311
|
async function ready() {
|
|
@@ -250,17 +381,17 @@ function showSheet(opts) {
|
|
|
250
381
|
sheetHost = host;
|
|
251
382
|
}
|
|
252
383
|
var appName = document.title || "this app";
|
|
253
|
-
/** The
|
|
254
|
-
var
|
|
255
|
-
/** Shows the built-in sheet for a cloud problem the user can act on (`
|
|
256
|
-
function explain(error,
|
|
384
|
+
/** The LiveWorker a backend path belongs to ("/actor/<id>"), if any. */
|
|
385
|
+
var liveWorkerPathOf = (path) => /^\/actor\/[^/?#]+/.exec(path)?.[0];
|
|
386
|
+
/** Shows the built-in sheet for a cloud problem the user can act on (`liveWorkerPath`: the LiveWorker the call went to). */
|
|
387
|
+
function explain(error, liveWorkerPath) {
|
|
257
388
|
switch (error.code) {
|
|
258
389
|
case "signed-out":
|
|
259
390
|
showSheet({
|
|
260
391
|
title: "Sign in to continue",
|
|
261
|
-
text: `Sign in
|
|
392
|
+
text: `Sign in to appOS Cloud to use ${appName}'s shared data.`,
|
|
262
393
|
actions: [{
|
|
263
|
-
label: "Sign in
|
|
394
|
+
label: "Sign in to appOS Cloud",
|
|
264
395
|
primary: true,
|
|
265
396
|
run: () => void ask("appos:sign-in").catch(() => {})
|
|
266
397
|
}]
|
|
@@ -286,7 +417,7 @@ function explain(error, actorPath) {
|
|
|
286
417
|
const sheet = upgradeSheet(appName, error.code, error.message, error.details);
|
|
287
418
|
const decide = async (approve) => {
|
|
288
419
|
try {
|
|
289
|
-
await
|
|
420
|
+
await liveWorkerJson(`${liveWorkerPath}/_upgrade`, {
|
|
290
421
|
method: "POST",
|
|
291
422
|
json: { approve }
|
|
292
423
|
});
|
|
@@ -296,7 +427,7 @@ function explain(error, actorPath) {
|
|
|
296
427
|
showSheet({
|
|
297
428
|
title: sheet.title,
|
|
298
429
|
text: sheet.text,
|
|
299
|
-
actions:
|
|
430
|
+
actions: liveWorkerPath ? sheet.actions.map((a) => a === "approve" ? {
|
|
300
431
|
label: "Approve",
|
|
301
432
|
primary: true,
|
|
302
433
|
run: () => decide(true)
|
|
@@ -399,11 +530,11 @@ async function bodyBytes(body) {
|
|
|
399
530
|
/**
|
|
400
531
|
* The app's backend. It has no URL: `fetch()` can't reach it, so a URL that
|
|
401
532
|
* came from anywhere (a link, a message, another site) never becomes a call
|
|
402
|
-
* to it. Paths name
|
|
533
|
+
* to it. Paths name a LiveWorker and what to send it:
|
|
403
534
|
*
|
|
404
535
|
* /whoami
|
|
405
|
-
* /actors GET: the user's
|
|
406
|
-
* /actor/<id>/<path> one
|
|
536
|
+
* /actors GET: the user's LiveWorkers; POST /actors/<Class>: a new one
|
|
537
|
+
* /actor/<id>/<path> one LiveWorker
|
|
407
538
|
*/
|
|
408
539
|
var backend = {
|
|
409
540
|
/** Sends a request to the backend; resolves to its streamed response. */
|
|
@@ -541,7 +672,7 @@ function launchDataOnce() {
|
|
|
541
672
|
history.replaceState(history.state, "", location.pathname + location.search);
|
|
542
673
|
return m[1];
|
|
543
674
|
}
|
|
544
|
-
/** The
|
|
675
|
+
/** The LiveWorker a share link opened this app on, and the link's key, as the shell passes them. */
|
|
545
676
|
function launchLinkOnce() {
|
|
546
677
|
const m = /^#appos-actor=([^&]+)&k=([A-Za-z0-9_-]+)$/.exec(location.hash);
|
|
547
678
|
if (!m) return void 0;
|
|
@@ -551,7 +682,7 @@ function launchLinkOnce() {
|
|
|
551
682
|
key: m[2]
|
|
552
683
|
};
|
|
553
684
|
}
|
|
554
|
-
async function
|
|
685
|
+
async function liveWorkerJson(path, init = {}) {
|
|
555
686
|
const headers = new Headers(init.headers);
|
|
556
687
|
let body = init.body;
|
|
557
688
|
if (init.json !== void 0) {
|
|
@@ -566,13 +697,13 @@ async function actorJson(path, init = {}) {
|
|
|
566
697
|
});
|
|
567
698
|
if (!res.ok) {
|
|
568
699
|
const err = await errorOf(res) ?? new CloudError("error", `${path} failed (${res.status})`, res.status);
|
|
569
|
-
explain(err,
|
|
700
|
+
explain(err, liveWorkerPathOf(path));
|
|
570
701
|
throw err;
|
|
571
702
|
}
|
|
572
703
|
return await res.json();
|
|
573
704
|
}
|
|
574
|
-
/** A connection to one
|
|
575
|
-
var
|
|
705
|
+
/** A connection to one LiveWorker: RPC, fetch and a live socket, each with the user's claims. */
|
|
706
|
+
var LiveWorker = class {
|
|
576
707
|
id;
|
|
577
708
|
path;
|
|
578
709
|
/** The signed-in user's roles, as of open(). */
|
|
@@ -581,7 +712,7 @@ var Actor = class {
|
|
|
581
712
|
this.id = id;
|
|
582
713
|
this.path = `/actor/${encodeURIComponent(id)}`;
|
|
583
714
|
}
|
|
584
|
-
/** backend.fetch() to the
|
|
715
|
+
/** backend.fetch() to the LiveWorker's own fetch handler, at `sub` under it. Problems the user can act on get the SDK's sheets. */
|
|
585
716
|
async fetch(sub = "/", init = {}) {
|
|
586
717
|
const res = await backend.fetch(this.path + (sub.startsWith("/") ? sub : `/${sub}`).replace(/^\/$/, ""), init);
|
|
587
718
|
if (!res.ok) {
|
|
@@ -590,9 +721,9 @@ var Actor = class {
|
|
|
590
721
|
}
|
|
591
722
|
return res;
|
|
592
723
|
}
|
|
593
|
-
/** Calls a method of the
|
|
724
|
+
/** Calls a method of the LiveWorker's class. Throws CloudError on failure. */
|
|
594
725
|
async call(method, ...args) {
|
|
595
|
-
return (await
|
|
726
|
+
return (await liveWorkerJson(`${this.path}/_rpc`, {
|
|
596
727
|
method: "POST",
|
|
597
728
|
json: {
|
|
598
729
|
method,
|
|
@@ -600,7 +731,7 @@ var Actor = class {
|
|
|
600
731
|
}
|
|
601
732
|
})).result;
|
|
602
733
|
}
|
|
603
|
-
/** A WebSocket to the
|
|
734
|
+
/** A WebSocket to the LiveWorker's fetch handler. */
|
|
604
735
|
websocket(sub = "/", protocols = []) {
|
|
605
736
|
return backend.connect(this.path + (sub.startsWith("/") ? sub : `/${sub}`), protocols);
|
|
606
737
|
}
|
|
@@ -608,18 +739,18 @@ var Actor = class {
|
|
|
608
739
|
* The owner and members to show: [{ id, role, name?, image? }]. `name` and
|
|
609
740
|
* `image` (an https avatar URL) come from each person's assistant-ui
|
|
610
741
|
* account; someone who never signed in to appOS has only id and role.
|
|
611
|
-
* The backend reads the same list with env.appos.profiles(). Cloud
|
|
742
|
+
* The backend reads the same list with env.appos.profiles(). Cloud LiveWorkers only.
|
|
612
743
|
*/
|
|
613
744
|
async profiles() {
|
|
614
|
-
return (await
|
|
745
|
+
return (await liveWorkerJson(`${this.path}/_profiles`)).profiles;
|
|
615
746
|
}
|
|
616
747
|
/** Owner, roles, the build it runs. Shows the owner a newer build a member asked for (Approve / Deny). */
|
|
617
748
|
async info() {
|
|
618
|
-
const info = await
|
|
749
|
+
const info = await liveWorkerJson(`${this.path}/_info`);
|
|
619
750
|
this.roles = info.roles;
|
|
620
751
|
const p = info.pending;
|
|
621
752
|
if (info.isOwner && p && !p.denied) {
|
|
622
|
-
const decide = (approve) => void
|
|
753
|
+
const decide = (approve) => void liveWorkerJson(`${this.path}/_upgrade`, {
|
|
623
754
|
method: "POST",
|
|
624
755
|
json: { approve }
|
|
625
756
|
}).catch(() => {});
|
|
@@ -640,28 +771,28 @@ var Actor = class {
|
|
|
640
771
|
return info;
|
|
641
772
|
}
|
|
642
773
|
};
|
|
643
|
-
var
|
|
774
|
+
var liveWorkers = {
|
|
644
775
|
/**
|
|
645
|
-
* A new
|
|
776
|
+
* A new LiveWorker of class `name`, owned by the user, on their default host.
|
|
646
777
|
* `host` says where it went: "cloud" or the host's name.
|
|
647
778
|
*/
|
|
648
779
|
create(name) {
|
|
649
|
-
return
|
|
780
|
+
return liveWorkerJson(`/actors/${encodeURIComponent(name)}`, { method: "POST" });
|
|
650
781
|
},
|
|
651
|
-
/** A connection to
|
|
782
|
+
/** A connection to a LiveWorker the user holds a role in. Rejects with "not-member" otherwise. */
|
|
652
783
|
async open(id) {
|
|
653
|
-
const a = new
|
|
784
|
+
const a = new LiveWorker(id);
|
|
654
785
|
await a.info();
|
|
655
786
|
return a;
|
|
656
787
|
},
|
|
657
|
-
/** The
|
|
788
|
+
/** The LiveWorkers the user owns or holds a role in, on every host. */
|
|
658
789
|
async list() {
|
|
659
|
-
return (await
|
|
790
|
+
return (await liveWorkerJson("/actors")).actors;
|
|
660
791
|
},
|
|
661
|
-
/** Owner only: gives `user` a role in
|
|
662
|
-
/** Owner only: gives `user` (their appOS ID) a role in
|
|
792
|
+
/** Owner only: gives `user` a role in LiveWorker `id`. */
|
|
793
|
+
/** Owner only: gives `user` (their appOS ID) a role in LiveWorker `id`. */
|
|
663
794
|
async grant(id, user, role) {
|
|
664
|
-
await
|
|
795
|
+
await liveWorkerJson(`${new LiveWorker(id).path}/_members`, {
|
|
665
796
|
method: "POST",
|
|
666
797
|
json: {
|
|
667
798
|
user,
|
|
@@ -669,23 +800,23 @@ var actors = {
|
|
|
669
800
|
}
|
|
670
801
|
});
|
|
671
802
|
},
|
|
672
|
-
/** Owner only: takes `user`'s role in
|
|
803
|
+
/** Owner only: takes `user`'s role in LiveWorker `id` away. */
|
|
673
804
|
async revoke(id, user) {
|
|
674
|
-
await
|
|
805
|
+
await liveWorkerJson(`${new LiveWorker(id).path}/_members`, {
|
|
675
806
|
method: "DELETE",
|
|
676
807
|
json: { user }
|
|
677
808
|
});
|
|
678
809
|
},
|
|
679
810
|
/**
|
|
680
|
-
* The
|
|
811
|
+
* The LiveWorker a share link opened this app on, joined with the link's key
|
|
681
812
|
* (once per launch). Undefined when the app was not opened from one.
|
|
682
813
|
*/
|
|
683
814
|
async launched() {
|
|
684
815
|
const l = launchLink;
|
|
685
816
|
launchLink = void 0;
|
|
686
817
|
if (!l) return void 0;
|
|
687
|
-
const a = new
|
|
688
|
-
await
|
|
818
|
+
const a = new LiveWorker(l.actor);
|
|
819
|
+
await liveWorkerJson(`${a.path}/_join`, {
|
|
689
820
|
method: "POST",
|
|
690
821
|
json: { key: l.key }
|
|
691
822
|
});
|
|
@@ -694,19 +825,19 @@ var actors = {
|
|
|
694
825
|
}
|
|
695
826
|
};
|
|
696
827
|
/**
|
|
697
|
-
* A link that opens this app on
|
|
828
|
+
* A link that opens this app on LiveWorker `id` and gives whoever opens it `role`
|
|
698
829
|
* (editor by default; viewers can share only as viewers). The app shows it
|
|
699
830
|
* in its own share sheet.
|
|
700
831
|
*/
|
|
701
832
|
async function share(id, role = "editor") {
|
|
702
|
-
const { key } = await
|
|
833
|
+
const { key } = await liveWorkerJson(`${new LiveWorker(id).path}/_invite?role=${role}`);
|
|
703
834
|
return (await ask("appos:share-link", {
|
|
704
835
|
actor: id,
|
|
705
836
|
key
|
|
706
837
|
})).url;
|
|
707
838
|
}
|
|
708
839
|
/**
|
|
709
|
-
* Opens appOS's Share sheet for
|
|
840
|
+
* Opens appOS's Share sheet for LiveWorker `id`: the people on it with their role
|
|
710
841
|
* and the link each joined by, and, for its owner, the share links (new,
|
|
711
842
|
* copy, revoke). The same sheet for every app; resolves once it is shown.
|
|
712
843
|
*/
|
|
@@ -714,7 +845,7 @@ async function openShare(id) {
|
|
|
714
845
|
await ask("appos:share-sheet", { actor: id });
|
|
715
846
|
}
|
|
716
847
|
/**
|
|
717
|
-
* Calls `fn` when appOS finds the signed-in person's access to
|
|
848
|
+
* Calls `fn` when appOS finds the signed-in person's access to a LiveWorker
|
|
718
849
|
* changed (revoked, or they left on another device). Returns an unsubscribe.
|
|
719
850
|
*/
|
|
720
851
|
function onAccess(fn) {
|
|
@@ -731,8 +862,8 @@ function onAccess(fn) {
|
|
|
731
862
|
addEventListener("message", listener);
|
|
732
863
|
return () => removeEventListener("message", listener);
|
|
733
864
|
}
|
|
734
|
-
/** The live file this frame runs (appos.
|
|
735
|
-
var
|
|
865
|
+
/** The text of the live file this frame runs, when it is shared by link (appos.liveText()). */
|
|
866
|
+
var LiveText = class {
|
|
736
867
|
/** The link that opens this file, to copy and send. */
|
|
737
868
|
url;
|
|
738
869
|
#port;
|
|
@@ -855,11 +986,11 @@ var LiveFile = class {
|
|
|
855
986
|
}
|
|
856
987
|
}
|
|
857
988
|
};
|
|
858
|
-
async function
|
|
989
|
+
async function liveText() {
|
|
859
990
|
const channel = new MessageChannel();
|
|
860
991
|
try {
|
|
861
992
|
const r = await ask("appos:live-file", {}, 2e4, [channel.port2]);
|
|
862
|
-
return new
|
|
993
|
+
return new LiveText(channel.port1, r.url);
|
|
863
994
|
} catch (e) {
|
|
864
995
|
channel.port1.close();
|
|
865
996
|
if (e instanceof CloudError && e.code === "not-live") return void 0;
|
|
@@ -870,7 +1001,7 @@ async function liveFile() {
|
|
|
870
1001
|
* Moves the file this frame runs to the appOS cloud as a live file holding
|
|
871
1002
|
* `data` (text, at most 512 KB), and returns its link. Anyone with the link
|
|
872
1003
|
* opens the file and edits it live; no sign-in. Already live: its link.
|
|
873
|
-
* Afterwards appos.
|
|
1004
|
+
* Afterwards appos.liveText() connects to it.
|
|
874
1005
|
*/
|
|
875
1006
|
async function shareFile(data) {
|
|
876
1007
|
return ask("appos:share-file", { data }, 3e4);
|
|
@@ -1015,13 +1146,13 @@ var launchedData = launchDataOnce();
|
|
|
1015
1146
|
var appos = {
|
|
1016
1147
|
/** The app's backend: backend.fetch(path), backend.connect(path). No URL reaches it. */
|
|
1017
1148
|
backend,
|
|
1018
|
-
/** The app's
|
|
1019
|
-
|
|
1020
|
-
/** A share link to
|
|
1149
|
+
/** The app's LiveWorkers: create, open, list, grant, revoke, launched (appos.actors in the manifest). */
|
|
1150
|
+
liveWorkers,
|
|
1151
|
+
/** A share link to a LiveWorker for a role: share(id, "viewer"). */
|
|
1021
1152
|
share,
|
|
1022
|
-
/** appOS's Share sheet for
|
|
1153
|
+
/** appOS's Share sheet for a LiveWorker: openShare(id). */
|
|
1023
1154
|
openShare,
|
|
1024
|
-
/** Hears when the person's access to
|
|
1155
|
+
/** Hears when the person's access to a LiveWorker changed: onAccess(({ LiveWorker, role }) => …). */
|
|
1025
1156
|
onAccess,
|
|
1026
1157
|
/** { version, previousVersion }: previousVersion only on the first launch after an update. */
|
|
1027
1158
|
ready,
|
|
@@ -1071,23 +1202,38 @@ var appos = {
|
|
|
1071
1202
|
* save(), hear others with onChange(). Undefined when the file is not live
|
|
1072
1203
|
* (see shareFile()).
|
|
1073
1204
|
*/
|
|
1074
|
-
|
|
1205
|
+
liveText,
|
|
1075
1206
|
/** Moves this frame's file to the cloud as a live file; resolves to its link. */
|
|
1076
1207
|
shareFile,
|
|
1077
|
-
/** The file
|
|
1078
|
-
async
|
|
1208
|
+
/** The live file this frame runs; undefined in appOS from before live files. */
|
|
1209
|
+
async liveFile() {
|
|
1079
1210
|
return (await getHello()).grain;
|
|
1080
1211
|
},
|
|
1081
|
-
/**
|
|
1082
|
-
* The shell's file picker: this app's files on every host the user is
|
|
1083
|
-
* signed in to, and New (on the host the user picks). Resolves to what the
|
|
1084
|
-
* user picked or made, or null when they cancelled. Apps with
|
|
1085
|
-
* appos.multiple may ask for several; the shell saves them as a workspace.
|
|
1086
|
-
*/
|
|
1212
|
+
/** The person's files of this app: the shell's Open and New dialogs, and this app's own list of them. */
|
|
1087
1213
|
files: {
|
|
1088
|
-
|
|
1214
|
+
/** The shell's Open dialog, or with an address, one of this app's own files in its tab (see openFiles). */
|
|
1215
|
+
open: openFiles,
|
|
1216
|
+
/**
|
|
1217
|
+
* This app's files the person owns or that are shared with them, on every host the shell is signed in to and this
|
|
1218
|
+
* device, by name: what each is and where, never its data. Only this app's own type: other apps' files come only
|
|
1219
|
+
* through the shell's Open dialog. `folder`: only those in that folder ("" the top, "Work/Plans" deeper).
|
|
1220
|
+
*/
|
|
1221
|
+
async list({ folder } = {}) {
|
|
1222
|
+
return (await ask("appos:files-list", folder === void 0 ? {} : { folder }, 6e4)).files;
|
|
1223
|
+
},
|
|
1224
|
+
/** This app's files the person opened on this device lately, newest first: `limit` of them (10; at most 50). */
|
|
1225
|
+
async recent({ limit } = {}) {
|
|
1226
|
+
return (await ask("appos:files-recent", limit === void 0 ? {} : { limit }, 6e4)).files;
|
|
1227
|
+
},
|
|
1228
|
+
/**
|
|
1229
|
+
* The shell's New dialog: the user picks a host, a folder and a name, and the shell makes a file of this app
|
|
1230
|
+
* there (of `kind`, one of the app's LiveWorker classes, when given). Resolves to its LiveWorker id (open it with
|
|
1231
|
+
* appos.liveWorkers.open(id)), or null when the user cancelled. The app never sees the user's other files.
|
|
1232
|
+
*/
|
|
1233
|
+
async create({ kind } = {}) {
|
|
1089
1234
|
try {
|
|
1090
|
-
|
|
1235
|
+
const { actor } = await ask("appos:files-new", { ...kind ? { kind } : {} }, 864e5);
|
|
1236
|
+
return { id: actor };
|
|
1091
1237
|
} catch (e) {
|
|
1092
1238
|
if (e instanceof CloudError && e.code === "cancelled") return null;
|
|
1093
1239
|
throw e;
|
|
@@ -1104,17 +1250,159 @@ var appos = {
|
|
|
1104
1250
|
/** The Files app only: opens a file all() listed in its own app, in a tab. */
|
|
1105
1251
|
openInApp(key) {
|
|
1106
1252
|
return ask("appos:files-open-in", { key }, 6e4);
|
|
1253
|
+
},
|
|
1254
|
+
/** The Files app only: closes a file all() listed as openWeb to the web. */
|
|
1255
|
+
closeOpenWeb(key) {
|
|
1256
|
+
return ask("appos:files-close-open-web", { key }, 6e4);
|
|
1257
|
+
},
|
|
1258
|
+
/**
|
|
1259
|
+
* The Files app only: renames a file. Names are unique in a folder by name alone; a taken one rejects with
|
|
1260
|
+
* CloudError "name-taken". Resolves to the name it has now.
|
|
1261
|
+
*/
|
|
1262
|
+
async rename(key, name) {
|
|
1263
|
+
return (await ask("appos:files-do", {
|
|
1264
|
+
op: "rename",
|
|
1265
|
+
key,
|
|
1266
|
+
name
|
|
1267
|
+
}, 6e4)).title;
|
|
1268
|
+
},
|
|
1269
|
+
/** The Files app only: moves a file into a folder on its host ("" for the top). */
|
|
1270
|
+
async move(key, folder) {
|
|
1271
|
+
await ask("appos:files-do", {
|
|
1272
|
+
op: "move",
|
|
1273
|
+
key,
|
|
1274
|
+
folder
|
|
1275
|
+
}, 6e4);
|
|
1276
|
+
},
|
|
1277
|
+
/**
|
|
1278
|
+
* The Files app only: deletes a file. Its owner's goes to Trash where its host has one ("trash") and for good
|
|
1279
|
+
* elsewhere ("delete"); anyone else's leaves their view on this device ("remove") and stays for its owner.
|
|
1280
|
+
*/
|
|
1281
|
+
async delete(key) {
|
|
1282
|
+
return (await ask("appos:files-do", {
|
|
1283
|
+
op: "delete",
|
|
1284
|
+
key
|
|
1285
|
+
}, 6e4)).kind;
|
|
1286
|
+
},
|
|
1287
|
+
/** The Files app only: opens the shell's Share sheet on a file (its people, roles and links). */
|
|
1288
|
+
async share(key) {
|
|
1289
|
+
await ask("appos:files-do", {
|
|
1290
|
+
op: "share",
|
|
1291
|
+
key
|
|
1292
|
+
}, 6e4);
|
|
1293
|
+
},
|
|
1294
|
+
/** The Files app only: the files in Trash, newest first. */
|
|
1295
|
+
async trash() {
|
|
1296
|
+
return (await ask("appos:files-do", { op: "trash" }, 6e4)).files;
|
|
1297
|
+
},
|
|
1298
|
+
/** The Files app only: back from Trash, in its folder (or at the top), its name suffixed if it was taken. */
|
|
1299
|
+
async restore(key) {
|
|
1300
|
+
await ask("appos:files-do", {
|
|
1301
|
+
op: "restore",
|
|
1302
|
+
key
|
|
1303
|
+
}, 6e4);
|
|
1304
|
+
},
|
|
1305
|
+
/** The Files app only: deletes a file in Trash for good, for everyone. */
|
|
1306
|
+
async purge(key) {
|
|
1307
|
+
await ask("appos:files-do", {
|
|
1308
|
+
op: "purge",
|
|
1309
|
+
key
|
|
1310
|
+
}, 6e4);
|
|
1311
|
+
},
|
|
1312
|
+
/** The Files app only: the shell's New dialog at a host and folder; the user picks the app. The file opens in it. */
|
|
1313
|
+
async newFile(host, folder = "") {
|
|
1314
|
+
try {
|
|
1315
|
+
await ask("appos:files-do", {
|
|
1316
|
+
op: "new",
|
|
1317
|
+
host,
|
|
1318
|
+
folder
|
|
1319
|
+
}, 864e5);
|
|
1320
|
+
return true;
|
|
1321
|
+
} catch (e) {
|
|
1322
|
+
if (e instanceof CloudError && e.code === "cancelled") return false;
|
|
1323
|
+
throw e;
|
|
1324
|
+
}
|
|
1325
|
+
},
|
|
1326
|
+
/** The Files app only: deletes every file in Trash for good. */
|
|
1327
|
+
async emptyTrash() {
|
|
1328
|
+
await ask("appos:files-do", { op: "empty" }, 3e5);
|
|
1329
|
+
},
|
|
1330
|
+
/** The Files app only: a host's folders. Folders only organize; sharing is per file. */
|
|
1331
|
+
folders: {
|
|
1332
|
+
async create(host, name, parent = "") {
|
|
1333
|
+
return (await ask("appos:files-do", {
|
|
1334
|
+
op: "mkdir",
|
|
1335
|
+
host,
|
|
1336
|
+
name,
|
|
1337
|
+
parent
|
|
1338
|
+
}, 6e4)).folder;
|
|
1339
|
+
},
|
|
1340
|
+
async rename(host, id, name) {
|
|
1341
|
+
return (await ask("appos:files-do", {
|
|
1342
|
+
op: "folder",
|
|
1343
|
+
host,
|
|
1344
|
+
id,
|
|
1345
|
+
name
|
|
1346
|
+
}, 6e4)).folder;
|
|
1347
|
+
},
|
|
1348
|
+
async move(host, id, parent) {
|
|
1349
|
+
return (await ask("appos:files-do", {
|
|
1350
|
+
op: "folder",
|
|
1351
|
+
host,
|
|
1352
|
+
id,
|
|
1353
|
+
parent
|
|
1354
|
+
}, 6e4)).folder;
|
|
1355
|
+
},
|
|
1356
|
+
/** An empty folder only (CloudError "not-empty" otherwise). */
|
|
1357
|
+
async delete(host, id) {
|
|
1358
|
+
await ask("appos:files-do", {
|
|
1359
|
+
op: "rmdir",
|
|
1360
|
+
host,
|
|
1361
|
+
id
|
|
1362
|
+
}, 6e4);
|
|
1363
|
+
}
|
|
1107
1364
|
}
|
|
1108
1365
|
},
|
|
1109
|
-
/**
|
|
1110
|
-
|
|
1111
|
-
|
|
1366
|
+
/**
|
|
1367
|
+
* Makes a new file of this app and opens it in its own tab: through the shell's New dialog (host, folder, name)
|
|
1368
|
+
* when the app has LiveWorkers, else on this device. Null when the user cancelled the dialog.
|
|
1369
|
+
*/
|
|
1370
|
+
async newLiveFile() {
|
|
1371
|
+
try {
|
|
1372
|
+
const r = await ask("appos:new-grain", {}, 864e5);
|
|
1373
|
+
return {
|
|
1374
|
+
id: r.file,
|
|
1375
|
+
kind: r.kind
|
|
1376
|
+
};
|
|
1377
|
+
} catch (e) {
|
|
1378
|
+
if (e instanceof CloudError && e.code === "cancelled") return null;
|
|
1379
|
+
throw e;
|
|
1380
|
+
}
|
|
1381
|
+
},
|
|
1382
|
+
/**
|
|
1383
|
+
* Opens another of this app's files (its id from liveFile()) in its own tab, as App info does: an app that
|
|
1384
|
+
* lists its own files opens one this way. Rejects with CloudError "no-file" for an id that isn't this app's.
|
|
1385
|
+
*/
|
|
1386
|
+
async openLiveFile(id) {
|
|
1387
|
+
await ask("appos:open-grain", { file: id });
|
|
1388
|
+
},
|
|
1389
|
+
/**
|
|
1390
|
+
* Asks appOS to open the file this frame runs (a LiveWorker in the appOS cloud) to the open web, for an app whose
|
|
1391
|
+
* manifest declares appos.openWeb. appOS shows its own prompt to the file's owner; the app never sets it. Answers
|
|
1392
|
+
* { open: true, url } (already open: no prompt), or { open: false } when the owner said no. `url` is the file's
|
|
1393
|
+
* address plus ".git" (none while the file has no address yet): git's smart HTTP there (`<url>/info/refs`,
|
|
1394
|
+
* `/git-upload-pack`, `/git-receive-pack`) reaches the LiveWorker's fetch() at that route, with no user the platform
|
|
1395
|
+
* vouches for (caller() is { roles: [], web: true }) and Authorization untouched: the app checks who they are. Every
|
|
1396
|
+
* refusal there answers as an address that names nothing. The owner closes it in App info or the Files app.
|
|
1397
|
+
*/
|
|
1398
|
+
requestOpenWeb() {
|
|
1399
|
+
return ask("appos:open-web", {}, 864e5);
|
|
1112
1400
|
},
|
|
1113
1401
|
/**
|
|
1114
|
-
* Local
|
|
1402
|
+
* Local live files the user deleted since the app last ran: delete their data
|
|
1115
1403
|
* (it shares this origin). Called once per launch with the ids.
|
|
1116
1404
|
*/
|
|
1117
|
-
|
|
1405
|
+
onLiveFileRemoved(fn) {
|
|
1118
1406
|
removedListeners.push(fn);
|
|
1119
1407
|
if (removedSeen?.length) fn(removedSeen);
|
|
1120
1408
|
else getHello().catch(() => {});
|
|
@@ -1136,6 +1424,12 @@ var appos = {
|
|
|
1136
1424
|
if (!Number.isSafeInteger(count) || count < 0) throw new RangeError("appos.setBadge takes a whole number, 0 or more.");
|
|
1137
1425
|
tell("appos:badge", { count });
|
|
1138
1426
|
},
|
|
1427
|
+
/** Another app's page in this one: embed(slot, did, path); see appos.embeddable in that app's manifest. */
|
|
1428
|
+
embed,
|
|
1429
|
+
/** What is selected here, for the pages this one shows: setSelection({ address, lines?, text }) or null. */
|
|
1430
|
+
setSelection,
|
|
1431
|
+
/** In a page another app shows: what is selected in that app, now and as it changes. */
|
|
1432
|
+
onSelection,
|
|
1139
1433
|
/**
|
|
1140
1434
|
* 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
|
|
1141
1435
|
* the shell's hello: pad the header's start by it. 0 when the shell says nothing (appOS itself) or outside a shell.
|
|
@@ -1171,4 +1465,4 @@ var appos = {
|
|
|
1171
1465
|
/** Light or dark, from the shell: get(), onChange(fn), autoApply(false). Applied to <html> by default. */
|
|
1172
1466
|
theme
|
|
1173
1467
|
};
|
|
1174
|
-
export {
|
|
1468
|
+
export { BackendSocket, CloudError, LiveText, LiveWorker, aiCall, appos, appos as default, backend, explain, showSheet, theme };
|