@quo-systems/dock 0.2.0 → 0.2.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/beings/avatar.ts +9 -3
- package/beings/carry.ts +101 -0
- package/beings/desk.ts +2 -2
- package/beings/index.ts +3 -1
- package/beings/link.ts +54 -0
- package/beings/look.ts +96 -0
- package/beings/quo-dock.md +163 -277
- package/beings/side.ts +10 -1
- package/beings/user.ts +67 -13
- package/cli/daemon.ts +58 -251
- package/cli/http.ts +70 -0
- package/cli/quo.ts +13 -5
- package/dist/beings/avatar.js +10 -3
- package/dist/beings/carry.d.ts +10 -0
- package/dist/beings/carry.js +106 -0
- package/dist/beings/desk.d.ts +1 -0
- package/dist/beings/desk.js +1 -1
- package/dist/beings/index.d.ts +2 -0
- package/dist/beings/index.js +3 -1
- package/dist/beings/link.d.ts +7 -0
- package/dist/beings/link.js +42 -0
- package/dist/beings/look.d.ts +27 -0
- package/dist/beings/look.js +71 -0
- package/dist/beings/side.d.ts +8 -1
- package/dist/beings/user.d.ts +29 -3
- package/dist/beings/user.js +71 -14
- package/dist/cli/daemon.d.ts +7 -19
- package/dist/cli/daemon.js +51 -240
- package/dist/cli/http.d.ts +17 -0
- package/dist/cli/http.js +60 -0
- package/dist/cli/quo.js +15 -5
- package/dist/harbor/quo.d.ts +4 -0
- package/dist/harbor/quo.js +53 -0
- package/dist/human/door.d.ts +5 -0
- package/dist/human/door.js +19 -0
- package/dist/human/guest.d.ts +3 -0
- package/dist/human/guest.js +25 -0
- package/dist/human/html.d.ts +10 -2
- package/dist/human/html.js +61 -10
- package/dist/human/screen.d.ts +8 -3
- package/dist/human/screen.js +26 -6
- package/dist/human/tab.d.ts +5 -0
- package/dist/human/tab.js +161 -43
- package/dist/human/web.d.ts +9 -0
- package/dist/human/web.js +95 -0
- package/dist/human/worlds.d.ts +10 -0
- package/dist/human/worlds.js +38 -0
- package/dist/mcp/http.d.ts +4 -3
- package/dist/mcp/http.js +6 -6
- package/dist/mcp/oauth.d.ts +9 -4
- package/dist/mcp/oauth.js +15 -14
- package/dist/mcp/pilot.js +1 -1
- package/dist/mcp/route.d.ts +12 -0
- package/dist/mcp/route.js +34 -0
- package/dist/mcp/server.d.ts +5 -10
- package/dist/mcp/server.js +35 -4
- package/dist/mcp/web/exchange.d.ts +5 -2
- package/dist/mcp/web/exchange.js +21 -7
- package/harbor/quo-harbor.md +67 -30
- package/harbor/quo.ts +67 -0
- package/human/door.ts +26 -0
- package/human/guest.ts +26 -0
- package/human/html.ts +58 -10
- package/human/quo-human.md +158 -67
- package/human/screen.ts +34 -8
- package/human/tab.ts +193 -53
- package/human/web.ts +123 -0
- package/human/worlds.ts +52 -0
- package/mcp/http.ts +10 -9
- package/mcp/oauth.ts +20 -17
- package/mcp/pilot.ts +1 -1
- package/mcp/quo-mcp.md +20 -2
- package/mcp/route.ts +39 -0
- package/mcp/server.ts +37 -18
- package/mcp/web/exchange.ts +23 -9
- package/package.json +2 -2
package/harbor/quo.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// The quo. route: the socket door, served by the daemon under `/quo` and
|
|
3
|
+
// mapped by the proxy from the quo. hostname, so a URL of that route is the
|
|
4
|
+
// base of every reach. POST `/quo/<pk>` carries one ask to a pk this harbor
|
|
5
|
+
// holds or holds a socket for; an upgrade at `/quo` is a dialer's held
|
|
6
|
+
// socket, announcing its pks to be bound. Bytes from here go to an own door
|
|
7
|
+
// or a held socket, never onward. The listener half of the socket reach is
|
|
8
|
+
// the terrain's own, `ws` on Node, and lives here with it.
|
|
9
|
+
import type { IncomingMessage, Server as HttpServer } from 'node:http';
|
|
10
|
+
import { WebSocketServer } from 'ws';
|
|
11
|
+
import { Socket as Held, SUITE, type Line } from '@quo-systems/quo/harbor';
|
|
12
|
+
import type { DiskHarbor } from './disk.ts';
|
|
13
|
+
import { readAll, type Handler, type Quo } from '../cli/http.ts';
|
|
14
|
+
|
|
15
|
+
export function quoRoute(harbor: DiskHarbor, server: HttpServer, quo: Quo): Handler {
|
|
16
|
+
const pks = () => [...harbor.doors.keys()];
|
|
17
|
+
const wss = new WebSocketServer({ noServer: true });
|
|
18
|
+
server.on('upgrade', (req: IncomingMessage, socket, head) => {
|
|
19
|
+
const url = new URL(req.url ?? '/', 'http://localhost');
|
|
20
|
+
if (url.pathname.replace(/\/$/, '') !== '/quo') return void socket.destroy(); // the proxy rewrites the route root to /quo/
|
|
21
|
+
wss.handleUpgrade(req, socket, head, (ws) => {
|
|
22
|
+
const s: Held = new Held(
|
|
23
|
+
ws as unknown as Line,
|
|
24
|
+
(pk, bytes) => harbor.deliver(pk, bytes),
|
|
25
|
+
(far) => void harbor.bind(far, s, true), // a dialer's claims, each proven at its door: held here, reachable through this socket
|
|
26
|
+
() => {
|
|
27
|
+
harbor.unbind(s);
|
|
28
|
+
quo.sockets.delete(s);
|
|
29
|
+
},
|
|
30
|
+
);
|
|
31
|
+
quo.sockets.add(s);
|
|
32
|
+
s.announce(pks());
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
// The route is public and carries sealed bytes, so any origin may POST
|
|
36
|
+
// to it: a tab on a world's web. reaching another world's quo. is the
|
|
37
|
+
// ordinary case, and a binary POST needs the preflight answered.
|
|
38
|
+
const open = { 'access-control-allow-origin': '*', 'access-control-allow-methods': 'POST, OPTIONS', 'access-control-allow-headers': 'content-type, quo-suite' };
|
|
39
|
+
return async (req, res, rest) => {
|
|
40
|
+
if (req.method === 'OPTIONS') {
|
|
41
|
+
res.writeHead(204, open);
|
|
42
|
+
return void res.end();
|
|
43
|
+
}
|
|
44
|
+
// The wire suite the caller speaks. Absent is this one, because a caller
|
|
45
|
+
// older than the header is this one. Anything else this door cannot open
|
|
46
|
+
// and says so as nothing delivered, rather than taking bytes that will
|
|
47
|
+
// never open and answering a silence that names no reason.
|
|
48
|
+
const suite = req.headers['quo-suite'];
|
|
49
|
+
if (suite !== undefined && suite !== String(SUITE)) {
|
|
50
|
+
res.writeHead(404, { 'content-type': 'application/json', ...open });
|
|
51
|
+
return void res.end(JSON.stringify({ error: `this door speaks wire suite ${SUITE}` }));
|
|
52
|
+
}
|
|
53
|
+
const pk = rest.slice(1);
|
|
54
|
+
if (req.method !== 'POST' || !/^[0-9a-f]{128}$/.test(pk)) {
|
|
55
|
+
res.writeHead(404, { 'content-type': 'application/json', ...open });
|
|
56
|
+
return void res.end(JSON.stringify({ error: 'POST /quo/<pk>' }));
|
|
57
|
+
}
|
|
58
|
+
const raw = await readAll(req as AsyncIterable<Buffer>);
|
|
59
|
+
const back = raw === undefined ? undefined : await harbor.deliver(pk, new Uint8Array(raw));
|
|
60
|
+
if (back === undefined) {
|
|
61
|
+
res.writeHead(404, { 'content-type': 'application/json', ...open });
|
|
62
|
+
return void res.end(JSON.stringify({ error: 'no reach for that pk' }));
|
|
63
|
+
}
|
|
64
|
+
res.writeHead(200, { 'content-type': 'application/octet-stream', ...open });
|
|
65
|
+
res.end(Buffer.from(back));
|
|
66
|
+
};
|
|
67
|
+
}
|
package/human/door.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// The door page: what a stranger sees where nothing lets them in. No
|
|
3
|
+
// invitation in the fragment, no relation in this tab's harbor, and nobody
|
|
4
|
+
// at the ward's door; or a harbor's root with no world to list. It is
|
|
5
|
+
// Quo's page and not the estate's: it says what this is and that a world
|
|
6
|
+
// here is entered by a link someone sends you, and it asks for nothing,
|
|
7
|
+
// since there is nothing a stranger could type that would let them in. A
|
|
8
|
+
// world that wants a face of its own has a public being with a look, or
|
|
9
|
+
// its own page on its own origin; this is the default and nothing more.
|
|
10
|
+
// Pure, strings in and strings out, under the tab's policy: no script, no
|
|
11
|
+
// image that is not a data URI, styles from the one stylesheet.
|
|
12
|
+
import { escape } from './html.ts';
|
|
13
|
+
|
|
14
|
+
// The mark: a ring with a gap, one being's voice reaching another's door.
|
|
15
|
+
const MARK =
|
|
16
|
+
'data:image/svg+xml;base64,' +
|
|
17
|
+
btoa(
|
|
18
|
+
`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" fill="none" stroke="currentColor" stroke-width="4" stroke-linecap="round"><circle cx="32" cy="32" r="22" stroke-dasharray="110 30" transform="rotate(-60 32 32)"/><circle cx="32" cy="32" r="5" fill="currentColor" stroke="none"/></svg>`,
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
export type Door = { world?: string; host: string };
|
|
22
|
+
|
|
23
|
+
export function door(at: Door): string {
|
|
24
|
+
const where = at.world ? `<p class="where">${escape(at.world)} <span>at ${escape(at.host)}</span></p>` : `<p class="where">${escape(at.host)}</p>`;
|
|
25
|
+
return `<main class="door"><img class="mark" alt="" src="${MARK}"><h1>quo</h1>${where}<p class="lead">${at.world ? 'This world is entered by invitation.' : 'The worlds here are entered by invitation.'}</p><p>An invitation is a link someone sends you. Open it here, and you are in: no account, no password, nothing to type. What you can do inside is what the world shows you, and it is yours to keep on this device.</p><p class="quiet">Nothing on this page asks anything of you. If you were sent here without a link, ask the person who sent you for one.</p></main>`;
|
|
26
|
+
}
|
package/human/guest.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// A guest at a world's door: the world's public being, whatever class she
|
|
3
|
+
// is, as a subject the screen can render. Her describe for a stranger is the
|
|
4
|
+
// guest page; a form on it is a knock on the public invitation; and an
|
|
5
|
+
// answer that is an invitation is the way in, which the tab takes by
|
|
6
|
+
// joining. Nothing here knows the desk: the desk's `device` is one ask
|
|
7
|
+
// that answers an invitation, and any being may write another.
|
|
8
|
+
import { isSilence, isWord, wordOf } from '@quo-systems/quo';
|
|
9
|
+
import type { Answer, Blueprint, Invitation, JsonObject, Wanted } from '@quo-systems/quo';
|
|
10
|
+
import type { Avatar } from '../beings/avatar.ts';
|
|
11
|
+
import type { Subject } from '../beings/side.ts';
|
|
12
|
+
|
|
13
|
+
export function guest(avatar: Avatar, ward: string): Subject {
|
|
14
|
+
const at: Invitation = { ward };
|
|
15
|
+
return {
|
|
16
|
+
tools: async () => {
|
|
17
|
+
const bp = await avatar.knock(at);
|
|
18
|
+
if (isSilence(bp)) return { error: 'silence' };
|
|
19
|
+
if (isWord(bp)) return { error: wordOf(bp) };
|
|
20
|
+
if (bp === null || typeof bp !== 'object' || Array.isArray(bp) || !Array.isArray((bp as Blueprint).asks)) return { error: 'nobody is home' };
|
|
21
|
+
return bp as Blueprint;
|
|
22
|
+
},
|
|
23
|
+
call: (name: string, args: JsonObject = {}, wanted?: Wanted): Promise<Answer> => avatar.knock(at, name, args, wanted),
|
|
24
|
+
ears: new Set(),
|
|
25
|
+
};
|
|
26
|
+
}
|
package/human/html.ts
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
// page(model) the whole page: title, notice, forms, views, pushes
|
|
12
12
|
import type { Ask, Blueprint, Json, JsonObject } from '@quo-systems/quo';
|
|
13
13
|
import { SILENCE_TEXT, UNREACHED_TEXT, wordText, type Word } from '../beings/side.ts';
|
|
14
|
+
import { hint, hintFor, sanitise, groups as grouped, type Look, type Hint } from '../beings/look.ts';
|
|
14
15
|
|
|
15
16
|
// One property of an input schema, as the form needs it.
|
|
16
17
|
export type Property = { type?: string; description?: string; enum?: Json[]; format?: string; default?: Json };
|
|
@@ -47,12 +48,14 @@ export function field(name: string, p: Property, must: boolean): string {
|
|
|
47
48
|
|
|
48
49
|
// The ask as a form: its name is the button, its description the legend's
|
|
49
50
|
// small print, and `data-ask` is how the surface says which ask was sent.
|
|
50
|
-
export function form(ask: Ask): string {
|
|
51
|
+
export function form(ask: Ask, h: Hint = {}): string {
|
|
51
52
|
const must = required(ask.input);
|
|
52
53
|
const fields = props(ask.input)
|
|
53
54
|
.map(([name, p]) => field(name, p, must.has(name)))
|
|
54
55
|
.join('');
|
|
55
|
-
|
|
56
|
+
const label = `${h.icon ? `${escape(h.icon)} ` : ''}${escape(h.title ?? ask.name)}`;
|
|
57
|
+
const care = h.destructive ? ' data-confirm="true"' : '';
|
|
58
|
+
return `<form data-ask="${escape(ask.name)}"${care}><fieldset><legend>${label}${ask.description ? ` <small>${escape(ask.description)}</small>` : ''}</legend>${fields}<p><button>${label}</button></p></fieldset></form>`;
|
|
56
59
|
}
|
|
57
60
|
|
|
58
61
|
// ---- the form heard back
|
|
@@ -136,6 +139,7 @@ export function face(w: Word, schema?: JsonObject): string {
|
|
|
136
139
|
// hands it here after every change; the page is a function of it.
|
|
137
140
|
export type Model = {
|
|
138
141
|
blueprint: Blueprint | null; // her describe for this human, or nothing yet
|
|
142
|
+
look: Look; // her own look, from her `look` ask, or nothing
|
|
139
143
|
notice: string; // one line about where the human stands: in, not in, an error before an ask
|
|
140
144
|
answers: Record<string, Word>; // the last answer per ask, shown under its form
|
|
141
145
|
pushes: JsonObject[]; // every push from the world, newest last
|
|
@@ -143,22 +147,66 @@ export type Model = {
|
|
|
143
147
|
|
|
144
148
|
// The title is the one hint the notes may carry: a string named `name`.
|
|
145
149
|
// The rest of the notes is shown as a view and read as nothing else.
|
|
146
|
-
export function title(bp: Blueprint | null): string {
|
|
150
|
+
export function title(bp: Blueprint | null, l: Look = {}): string {
|
|
151
|
+
if (l.name) return l.name;
|
|
147
152
|
const n = bp?.notes;
|
|
148
153
|
return n !== null && typeof n === 'object' && !Array.isArray(n) && typeof n.name === 'string' && n.name ? n.name : 'quo';
|
|
149
154
|
}
|
|
150
155
|
|
|
156
|
+
// ---- a look
|
|
157
|
+
|
|
158
|
+
// A look as the page paints it: the tokens become CSS variables on one
|
|
159
|
+
// section, and the name and the logo its heading. The shape of every token
|
|
160
|
+
// is the dock's, `beings/look.ts`; this only writes what survived it.
|
|
161
|
+
export function look(l: Look | undefined): { style: string; head: string } {
|
|
162
|
+
if (!l) return { style: '', head: '' };
|
|
163
|
+
const vars: string[] = [];
|
|
164
|
+
if (l.accent) vars.push(`--accent:${l.accent}`);
|
|
165
|
+
if (l.background) vars.push(`--bg:${l.background}`);
|
|
166
|
+
if (l.foreground) vars.push(`--fg:${l.foreground}`);
|
|
167
|
+
if (l.font) vars.push(`--font:${l.font}`);
|
|
168
|
+
if (l.radius !== undefined) vars.push(`--radius:${l.radius}px`);
|
|
169
|
+
const logo = l.logo ? `<img class="logo" alt="" src="${l.logo}">` : '';
|
|
170
|
+
const name = l.name ? escape(l.name) : '';
|
|
171
|
+
return { style: vars.length ? ` style="${vars.join(';')}"` : '', head: logo || name ? `<h2>${logo}${name}</h2>` : '' };
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Her asks in the order her look asks for, the rest after in her own order.
|
|
175
|
+
export function ordered(asks: Ask[], l: Look | undefined): Ask[] {
|
|
176
|
+
const want = l?.order ?? [];
|
|
177
|
+
return [...want.map((n) => asks.find((a) => a.name === n)).filter((a): a is Ask => a !== undefined), ...asks.filter((a) => !want.includes(a.name))];
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export { hintFor };
|
|
181
|
+
|
|
151
182
|
export function page(m: Model): string {
|
|
152
183
|
const bp = m.blueprint;
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
184
|
+
const one = (l: Look | undefined, prefix = '') => (a: Ask) => {
|
|
185
|
+
const w = m.answers[a.name];
|
|
186
|
+
const h = hint(l, a.name.startsWith(prefix) ? a.name.slice(prefix.length) : a.name);
|
|
187
|
+
return `<section>${form(a, h)}${w ? face(w, a.output) : ''}</section>`;
|
|
188
|
+
};
|
|
189
|
+
const groups = grouped(bp);
|
|
190
|
+
const taken = new Set(Object.values(groups).flatMap((g) => g.asks ?? []));
|
|
191
|
+
const own = bp ? ordered(bp.asks.filter((a) => !taken.has(a.name) && a.name !== 'look'), m.look).map(one(m.look)).join('') : '';
|
|
192
|
+
const far = bp
|
|
193
|
+
? Object.entries(groups)
|
|
194
|
+
.map(([id, g]) => {
|
|
195
|
+
const asks = bp.asks.filter((a) => g.asks?.includes(a.name));
|
|
196
|
+
if (!asks.length) return '';
|
|
197
|
+
const kept = sanitise(g.look);
|
|
198
|
+
const l = look(kept);
|
|
199
|
+
const prefix = `${id}-`;
|
|
200
|
+
const want = (kept.order ?? []).map((n) => prefix + n);
|
|
201
|
+
const inOrder = ordered(asks, { order: want });
|
|
202
|
+
return `<section class="standing" data-standing="${escape(id)}"${l.style}>${l.head || `<h2>${escape(id)}</h2>`}${inOrder.map(one(kept, prefix)).join('')}</section>`;
|
|
158
203
|
})
|
|
159
204
|
.join('')
|
|
160
205
|
: '';
|
|
161
|
-
const
|
|
206
|
+
const asks = own + far;
|
|
207
|
+
const shown = bp && bp.notes !== null && typeof bp.notes === 'object' && !Array.isArray(bp.notes) ? Object.fromEntries(Object.entries(bp.notes).filter(([k]) => k !== 'standings' && k !== 'name')) : bp?.notes;
|
|
208
|
+
const notes = bp && shown !== null && shown !== undefined && !(typeof shown === 'object' && !Array.isArray(shown) && !Object.keys(shown).length) ? `<aside class="notes">${view(shown as Json)}</aside>` : '';
|
|
162
209
|
const pushes = m.pushes.length ? `<section class="pushes"><h2>pushes</h2><ol>${m.pushes.map((p) => `<li>${view(p)}</li>`).join('')}</ol></section>` : '';
|
|
163
|
-
|
|
210
|
+
const mine = look(m.look);
|
|
211
|
+
return `<header${mine.style}>${m.look.logo ? `<img class="logo" alt="" src="${m.look.logo}">` : ''}<h1>${escape(title(bp, m.look))}</h1><p class="notice">${escape(m.notice)}</p></header>${notes}<main${mine.style}>${asks}</main>${pushes}`;
|
|
164
212
|
}
|
package/human/quo-human.md
CHANGED
|
@@ -1,86 +1,177 @@
|
|
|
1
1
|
# The human side
|
|
2
2
|
|
|
3
3
|
This is how a Quo world speaks to a human, and how a human speaks back. It
|
|
4
|
-
is one side of the avatar described in `packages/dock/beings/quo-dock.md`,
|
|
5
|
-
owns the avatar, the front desk, the credential exchange
|
|
6
|
-
invariants; this document assumes all of that and
|
|
7
|
-
needs. It names no transport and no model. A tab is
|
|
8
|
-
of its own, and where its bytes go is
|
|
4
|
+
is one side of the avatar described in `packages/dock/beings/quo-dock.md`,
|
|
5
|
+
which owns the avatar, the front desk, the credential exchange, carrying,
|
|
6
|
+
the look and the shared invariants; this document assumes all of that and
|
|
7
|
+
adds only what a screen needs. It names no transport and no model. A tab is
|
|
8
|
+
a device with a harbor of its own, and where its bytes go is
|
|
9
|
+
`packages/dock/harbor/quo-harbor.md`.
|
|
9
10
|
|
|
10
|
-
The claim
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
The claim, made good on: a human needs no page written for them. A screen
|
|
12
|
+
is a blueprint spoken as HTML. A being's describe for this asker becomes the
|
|
13
|
+
forms the human sees, a submitted form becomes a named ask, an answer
|
|
14
|
+
becomes a view, a push becomes a notification, and the three words for "no
|
|
15
|
+
object" each have a face. Nothing the screen shows exists anywhere but in a
|
|
16
|
+
blueprint and a look, so every world gets a screen for free and no world
|
|
17
|
+
gets a screen it did not describe.
|
|
17
18
|
|
|
18
|
-
|
|
19
|
+
Three sides, one describe. The CLI, the model side and the screen are three
|
|
20
|
+
views of the same beings, and the screen adds no vocabulary of its own:
|
|
21
|
+
what a being can be asked is her blueprint, how she wants to be shown is
|
|
22
|
+
her `look`, and both are values that travel through the relation. A world
|
|
23
|
+
that wants a page of its own writes any HTML, CSS and JavaScript it likes on
|
|
24
|
+
its own origin, against the avatar's handles and nothing else; a world that
|
|
25
|
+
writes none gets this screen.
|
|
19
26
|
|
|
20
|
-
|
|
21
|
-
- how an output schema, and an answer, become a view;
|
|
22
|
-
- what the blueprint's notes may carry as rendering hints without becoming
|
|
23
|
-
state, and what they may never carry;
|
|
24
|
-
- how a standing is a page, and a digest change is a refreshed page;
|
|
25
|
-
- how the same screen is a guest one minute and an occupant the next, and
|
|
26
|
-
what the human sees at each of the three words;
|
|
27
|
-
- how a native app shows many worlds: one screen per ward, a switcher
|
|
28
|
-
between them, and the device's own beings offered to each through gates;
|
|
29
|
-
- what one avatar class, one `side` implementation and one suite look like
|
|
30
|
-
for a screen, proven on the memory harbor with no browser at all.
|
|
27
|
+
## How a screen is made
|
|
31
28
|
|
|
32
|
-
|
|
33
|
-
the human is an occupant, reached through an avatar, seeing what the gate
|
|
34
|
-
shows.
|
|
29
|
+
Read with the trunk's "Carrying" and "The look", which this applies.
|
|
35
30
|
|
|
36
|
-
|
|
31
|
+
- **A form from a schema, without a designer.** An input schema is a form
|
|
32
|
+
with one field per property by type: a string is a text input, and
|
|
33
|
+
`password`, `date`, `email` and `time` are the input's type; a number is a
|
|
34
|
+
number input; a boolean a checkbox; an enum a select; an object or an
|
|
35
|
+
array a box for JSON. The submitted strings come back as arguments typed by
|
|
36
|
+
the schema, an empty optional field left out. A hint from her look puts a
|
|
37
|
+
title and an icon on the button and marks a destructive ask.
|
|
38
|
+
- **A view from an answer.** A primitive is text, an object a table of its
|
|
39
|
+
keys in the output schema's order when she declared one, a list of objects
|
|
40
|
+
one table, null the word nothing. An error object is marked; silence and
|
|
41
|
+
each of the ward's words say what the side says of them.
|
|
42
|
+
- **A standing is a section.** The user being carries her standings, and
|
|
43
|
+
her notes say which asks are whose. The page draws her own asks first,
|
|
44
|
+
then one section per standing, headed by that being's name and logo and
|
|
45
|
+
painted with her tokens as CSS variables on that section and nowhere
|
|
46
|
+
else. A form in acme's section is an ask on the human's standing at acme,
|
|
47
|
+
and acme sees the human, never the device. The same section appears on
|
|
48
|
+
acme's own web, under the same look: one component, two relations.
|
|
49
|
+
- **The page follows the digest.** The side asks the describe again after
|
|
50
|
+
every call and asks `look` once per digest; a digest that moved is a page
|
|
51
|
+
that moved. A read-only ask with nothing to type is run on open, so a page
|
|
52
|
+
can open with what it shows and not only with buttons. Every one of those
|
|
53
|
+
asks rotates her keys, so the side saves after each, not only after a
|
|
54
|
+
form: a relation brought back from a reload with a stale count is refused
|
|
55
|
+
at the far door and hears silence.
|
|
56
|
+
- **What a look may carry, and never.** The trunk's table is the whole
|
|
57
|
+
list: a name, a logo as a data URI, three colours, a font, a radius, an
|
|
58
|
+
order, a hint per ask. No CSS, no URL, no script, ever. A token that fails
|
|
59
|
+
its shape is dropped. The page owns layout, typography and its own
|
|
60
|
+
palette; a far being paints inside her section and cannot reach out of it.
|
|
61
|
+
- **The tab shell.** One stylesheet honouring the variables, light and dark,
|
|
62
|
+
served by the daemon beside the bundle. Nothing else is designed.
|
|
63
|
+
- **A world is a ward with a public being, and the guest page is her
|
|
64
|
+
describe.** Whatever class she is. The tab knocks the ward's public
|
|
65
|
+
invitation, its pk alone, with the empty ask, and renders what she shows
|
|
66
|
+
strangers with this same screen: the desk shows `hello` and `device`, a
|
|
67
|
+
shop could show its availability, a garden its `enter`. A form on that
|
|
68
|
+
page is a knock on the public invitation, and an answer that is an
|
|
69
|
+
invitation is the way in: the side hands it to `admit`, the avatar joins,
|
|
70
|
+
and the page becomes hers. Nothing in the screen knows the word desk.
|
|
71
|
+
- **Worlds have addresses.** `web./<ward>` is that world's page, `web./`
|
|
72
|
+
lists the worlds, and a hostname per world is one proxy line, the
|
|
73
|
+
estate's choice. `quo.` stays one per harbor, since bytes route by pk.
|
|
74
|
+
- **A link is the page with the invitation in the fragment**, under the one
|
|
75
|
+
reserved key `quo`, the invitation compact as `ward.heir.secret` or
|
|
76
|
+
`ward` alone: `web.acme.com/shop#quo=...`. The fragment never leaves the
|
|
77
|
+
browser, where a query string would reach the server, its logs and every
|
|
78
|
+
referer. The tab reads it, strips it from the address bar before anything
|
|
79
|
+
else runs, and joins. A page's own routing keeps the query, the path and
|
|
80
|
+
the rest of the fragment; only `quo` is taken. `beings/link.ts`.
|
|
81
|
+
- **An invitation is self-addressing.** It names its ward by pk, so the
|
|
82
|
+
path of the page it was opened on is a hint for humans and nothing more:
|
|
83
|
+
the tab joins in the local ward of the ward the invitation names, and
|
|
84
|
+
the address follows. `web./#quo=...` is a complete way in for anyone
|
|
85
|
+
holding an invitation to any ward the harbor hosts, and every ward has a
|
|
86
|
+
page, whether or not anyone is at its door, so that a link into one has
|
|
87
|
+
somewhere to land; a ward with no public being says it admits by
|
|
88
|
+
invitation only.
|
|
89
|
+
- **The tab is a browser of worlds, and of the relations in each.** One
|
|
90
|
+
harbor per origin, one local ward per world joined, and inside it one
|
|
91
|
+
avatar per relation, since an avatar is one standing: a fresh invitation
|
|
92
|
+
is always a fresh avatar, never a join on one that already holds hers. A
|
|
93
|
+
link opened while in is one more relation; two humans on one family
|
|
94
|
+
tablet are two relations in one world; a switcher over worlds and
|
|
95
|
+
another over relations, and a switch is a switch of avatar and nothing
|
|
96
|
+
more. A world on another origin is another page, and the switcher links
|
|
97
|
+
there. `worlds.ts` is this without a document, and the memory harbor
|
|
98
|
+
proves it.
|
|
99
|
+
- **The policy.** The page carries a content security policy: scripts from
|
|
100
|
+
its origin only and never inline, connections to its origin and the `quo.`
|
|
101
|
+
route it dials, images from data URIs and its origin, no frames, no base.
|
|
102
|
+
The config crosses in a JSON script, which the policy allows. A bug in a
|
|
103
|
+
renderer cannot become a script, and no look can reach a server.
|
|
37
104
|
|
|
38
|
-
The
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
`packages/dock/human/`, and the tab that holds them:
|
|
105
|
+
## The pieces
|
|
106
|
+
|
|
107
|
+
Eight files under `packages/dock/human/`:
|
|
42
108
|
|
|
43
109
|
- `html.ts` is pure, strings in and strings out, and is the screen's whole
|
|
44
|
-
vocabulary
|
|
45
|
-
|
|
46
|
-
`time` are the input's type; a number is a number input; a boolean is a
|
|
47
|
-
checkbox; an enum is a select; an object or an array is a box for JSON.
|
|
48
|
-
The submitted strings come back as arguments typed by the schema, an
|
|
49
|
-
empty optional field left out. An answer is a view: a primitive is text,
|
|
50
|
-
an object a table of its keys in the output schema's order when she
|
|
51
|
-
declared one, a list of objects one table, null the word nothing. The
|
|
52
|
-
three words for "no object" each have a face, an error object marked,
|
|
53
|
-
silence and each of the ward's words saying what the side says of them.
|
|
54
|
-
The notes may carry one hint, a string `name` that titles the page; the
|
|
55
|
-
rest is shown as a view and read as nothing else.
|
|
110
|
+
vocabulary: `form`, `values`, `view`, `face`, `look`, `page`. It reads the
|
|
111
|
+
look's vocabulary from `beings/look.ts` and adds none.
|
|
56
112
|
- `screen.ts` is the side: one avatar and one surface, where a surface can
|
|
57
|
-
only show a page and hand back a submitted form.
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
describe that fails leaves the last page standing and says so in
|
|
62
|
-
notice.
|
|
113
|
+
only show a page and hand back a submitted form. It keeps the model,
|
|
114
|
+
speaks it as a page after every change, calls her when a form comes back,
|
|
115
|
+
re-asks her describe after every call, asks her look once per digest, and
|
|
116
|
+
runs her read-only asks on open. A push is appended and shown as it
|
|
117
|
+
lands. A describe that fails leaves the last page standing and says so in
|
|
118
|
+
the notice.
|
|
63
119
|
- `dom.ts` is the surface on an element, the one file that touches one.
|
|
64
|
-
- `
|
|
65
|
-
|
|
120
|
+
- `guest.ts` is a world's public being as a subject the screen renders:
|
|
121
|
+
her describe for a stranger, a form as a knock on the public invitation.
|
|
122
|
+
- `worlds.ts` is the tab's worlds and relations with no document in
|
|
123
|
+
sight: the local ward for a far pk, the relations in it, and a fresh
|
|
124
|
+
avatar for the next way in.
|
|
125
|
+
- `door.ts` is the door page, pure: what a stranger sees where nothing
|
|
126
|
+
lets them in, Quo's page and not the estate's, asking for nothing.
|
|
127
|
+
- `tab.ts` is the shell: the harbor in the tab, the config, the two
|
|
128
|
+
switchers and the two ways in, and hands one avatar at a time to the
|
|
129
|
+
side.
|
|
130
|
+
- `web.ts` is the web route the daemon mounts under `/web`: the list of
|
|
131
|
+
worlds or the door page at the root, a world's page with its config, the
|
|
132
|
+
bundle built from `tab.ts`, the policy header and the stylesheet. It
|
|
133
|
+
authenticates nothing and admits nobody; the knock is the tab's. Paths
|
|
134
|
+
it does not take fall through to the exchange pages.
|
|
66
135
|
|
|
67
136
|
Proven in `packages/dock/test/human.test.ts` on the memory harbor with a fake
|
|
68
|
-
surface and no browser
|
|
69
|
-
|
|
137
|
+
surface and no browser: the user being carrying a shop with a look, a guest
|
|
138
|
+
at a door that is not a desk let in by a form, the link read, stripped and
|
|
139
|
+
refused, and the worlds and relations on a harbor core over the memory
|
|
140
|
+
store, two invitations into one world being two avatars; and in
|
|
141
|
+
`packages/dock/test/terrain/browser.test.ts` in a real Chromium against a
|
|
142
|
+
daemon on loopback, behind `npm run check:terrain`: the guest page, the
|
|
143
|
+
way in by a link the root minted, a push, a reload, the policy header, a
|
|
144
|
+
link while in as a second relation and the switch back, a link into another
|
|
145
|
+
ward landing on that ward's page, the door page where nobody is at the
|
|
146
|
+
door, and a link at the root.
|
|
147
|
+
|
|
148
|
+
## Security, by structure
|
|
70
149
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
150
|
+
- Nothing executable crosses. What a screen receives is I-JSON, by the
|
|
151
|
+
spec: asks, args, answers, the three words, and a look. Every string is
|
|
152
|
+
escaped before it is written into the page; a JSON box is parsed and never
|
|
153
|
+
evaluated.
|
|
154
|
+
- A look is a closed vocabulary held to shapes. A logo is a data URI, so no
|
|
155
|
+
request leaves the page towards a far being's server; a colour is a hex
|
|
156
|
+
colour; there is no token for a stylesheet, a URL or a script.
|
|
157
|
+
- The gate is the permission. What a page can ask is what the being shows
|
|
158
|
+
that device, already. No page adds a right, and a form for an ask she does
|
|
159
|
+
not show is nothing.
|
|
160
|
+
- Origin is the boundary. A world's own page runs only on that world's
|
|
161
|
+
origin; on the human's own web only the dock's bundle and the estate's
|
|
162
|
+
classes run. A world can only ever damage itself.
|
|
75
163
|
|
|
76
164
|
## The tab
|
|
77
165
|
|
|
78
|
-
The tab is a device. The page boots a browser harbor on a
|
|
79
|
-
the tab's store the first time, one ward
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
and
|
|
85
|
-
|
|
86
|
-
|
|
166
|
+
The tab is a device. The page at `web./<ward>` boots a browser harbor on a
|
|
167
|
+
seed minted into the tab's store the first time, one local ward for this
|
|
168
|
+
world with an avatar per relation in it, and dials the world's `quo.`
|
|
169
|
+
route. Two ways in, one act, each a fresh avatar: a link's invitation,
|
|
170
|
+
joined at once in the ward it names; and a guest form on the public being's
|
|
171
|
+
page whose answer is an invitation. Nothing is typed to get in, no password
|
|
172
|
+
and no account, the root included: the root mints its own first invitation
|
|
173
|
+
on the box and opens the link. A ward with nobody at its door shows the
|
|
174
|
+
door page, `door.ts`, and a link is the only way. From then on there is no
|
|
175
|
+
cookie and no token anywhere, and a reload asks nothing: the seed and the
|
|
176
|
+
standings are in the tab's store, and the relation last on screen is the
|
|
177
|
+
one shown.
|
package/human/screen.ts
CHANGED
|
@@ -8,9 +8,13 @@
|
|
|
8
8
|
// moved. A push is appended and shown the moment it lands.
|
|
9
9
|
import { digest } from '@quo-systems/quo';
|
|
10
10
|
import type { Blueprint, JsonObject } from '@quo-systems/quo';
|
|
11
|
-
import type
|
|
12
|
-
import {
|
|
13
|
-
import
|
|
11
|
+
import { word, type Serving, type Subject } from '../beings/side.ts';
|
|
12
|
+
import { isInvitation } from '../beings/link.ts';
|
|
13
|
+
import type { Invitation } from '@quo-systems/quo';
|
|
14
|
+
import { page, values, hintFor, type Model, type Raw } from './html.ts';
|
|
15
|
+
import { sanitise } from '../beings/look.ts';
|
|
16
|
+
import { isSilence, isWord } from '@quo-systems/quo';
|
|
17
|
+
import type { Json } from '@quo-systems/quo';
|
|
14
18
|
|
|
15
19
|
export type Surface = {
|
|
16
20
|
show(html: string): void;
|
|
@@ -19,10 +23,19 @@ export type Surface = {
|
|
|
19
23
|
onSubmit: ((ask: string, raw: Raw) => void) | undefined;
|
|
20
24
|
};
|
|
21
25
|
|
|
22
|
-
// `after` runs
|
|
23
|
-
//
|
|
24
|
-
|
|
25
|
-
|
|
26
|
+
// `after` runs after every ask the side makes, a submitted form, her
|
|
27
|
+
// describe, her look and the read-only asks run on open alike, as it does
|
|
28
|
+
// for the model side: every ask rotates her keys, and a harbor that must
|
|
29
|
+
// write what the ward changed hooks it. A side that saved only after a form
|
|
30
|
+
// would bring her back from a reload with a stale count, and the far door
|
|
31
|
+
// would refuse her. `admit` is what to do
|
|
32
|
+
// with an answer that is an invitation: a guest at a world's door is let in
|
|
33
|
+
// by it, and a side with no `admit` shows it as any answer.
|
|
34
|
+
export type Options = { after?: () => Promise<void>; notice?: string; admit?: (invitation: Invitation) => Promise<void> };
|
|
35
|
+
export async function screenSide(avatar: Subject, surface: Surface, options: Options = {}): Promise<Serving & { model: Model; refresh(): Promise<void> }> {
|
|
36
|
+
const after = options.after ?? (async () => {});
|
|
37
|
+
const notice = options.notice ?? '';
|
|
38
|
+
const model: Model = { blueprint: null, look: {}, notice, answers: {}, pushes: [] };
|
|
26
39
|
let seen: string | null = null;
|
|
27
40
|
const show = () => surface.show(page(model));
|
|
28
41
|
|
|
@@ -39,8 +52,19 @@ export async function screenSide(avatar: Avatar, surface: Surface, after: () =>
|
|
|
39
52
|
seen = d;
|
|
40
53
|
model.blueprint = bp as Blueprint;
|
|
41
54
|
for (const k of Object.keys(model.answers)) if (!(bp as Blueprint).asks.some((a) => a.name === k)) delete model.answers[k];
|
|
55
|
+
// her look, once per digest: how she wants her page painted, and what each ask is
|
|
56
|
+
if ((bp as Blueprint).asks.some((a) => a.name === 'look')) {
|
|
57
|
+
const l = await avatar.call('look');
|
|
58
|
+
model.look = isSilence(l) || isWord(l) ? {} : sanitise(l as Json);
|
|
59
|
+
} else model.look = {};
|
|
60
|
+
// a read-only ask that needs nothing typed is run on her behalf, so the page opens with what it shows
|
|
61
|
+
for (const a of (bp as Blueprint).asks) {
|
|
62
|
+
const needs = ((a.input as { required?: string[] }).required ?? []).length > 0;
|
|
63
|
+
if (hintFor(bp as Blueprint, model.look, a.name).readOnly && !needs && !(a.name in model.answers)) model.answers[a.name] = word(await avatar.call(a.name, {}));
|
|
64
|
+
}
|
|
42
65
|
}
|
|
43
66
|
}
|
|
67
|
+
await after();
|
|
44
68
|
show();
|
|
45
69
|
};
|
|
46
70
|
|
|
@@ -53,8 +77,10 @@ export async function screenSide(avatar: Avatar, surface: Surface, after: () =>
|
|
|
53
77
|
model.answers[name] = { word: 'error', value: { error: v.error } };
|
|
54
78
|
return show();
|
|
55
79
|
}
|
|
56
|
-
|
|
80
|
+
const out = await avatar.call(name, v.args);
|
|
57
81
|
await after();
|
|
82
|
+
if (options.admit && isInvitation(out)) return options.admit(out);
|
|
83
|
+
model.answers[name] = word(out);
|
|
58
84
|
await refresh();
|
|
59
85
|
};
|
|
60
86
|
|