clavarium 0.2.144-beta.1 → 0.2.145-beta.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/npm-shrinkwrap.json +14 -14
- package/package.json +4 -4
- package/server/api.mjs +18 -1
- package/server/main.mjs +11 -5
- package/server/rooms.mjs +188 -0
- package/server/talk.mjs +8 -4
- package/web/app.js +100 -8
- package/web/index.html +18 -0
- package/web/style.css +25 -0
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.145-beta.1",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "clavarium",
|
|
9
|
-
"version": "0.2.
|
|
9
|
+
"version": "0.2.145-beta.1",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
|
13
13
|
"@xterm/xterm": "^6.0.0",
|
|
14
|
-
"clavarium-binder": "0.1.
|
|
14
|
+
"clavarium-binder": "0.1.59-next.1",
|
|
15
15
|
"clavarium-docket": "0.1.2-next.2",
|
|
16
|
-
"clavarium-parley": "0.17.
|
|
17
|
-
"clavarium-tether": "0.1.0-next.
|
|
16
|
+
"clavarium-parley": "0.17.52-next.1",
|
|
17
|
+
"clavarium-tether": "0.1.0-next.49",
|
|
18
18
|
"mammoth": "1.13.0",
|
|
19
19
|
"mermaid": "11.17.2",
|
|
20
20
|
"node-pty": "^1.1.0",
|
|
@@ -761,9 +761,9 @@
|
|
|
761
761
|
}
|
|
762
762
|
},
|
|
763
763
|
"node_modules/clavarium-binder": {
|
|
764
|
-
"version": "0.1.
|
|
765
|
-
"resolved": "https://registry.npmjs.org/clavarium-binder/-/clavarium-binder-0.1.
|
|
766
|
-
"integrity": "sha512-
|
|
764
|
+
"version": "0.1.59-next.1",
|
|
765
|
+
"resolved": "https://registry.npmjs.org/clavarium-binder/-/clavarium-binder-0.1.59-next.1.tgz",
|
|
766
|
+
"integrity": "sha512-uvsmMS7mP18f7yRQZoXSnhyM8tzr0cjDPiZx4ofKP+YJ2jHZz01jA+ggrJ0l4e1evY3bVfnF+jwXa7MilHLRQg==",
|
|
767
767
|
"license": "MIT",
|
|
768
768
|
"bin": {
|
|
769
769
|
"binder": "bin/binder.mjs",
|
|
@@ -787,9 +787,9 @@
|
|
|
787
787
|
}
|
|
788
788
|
},
|
|
789
789
|
"node_modules/clavarium-parley": {
|
|
790
|
-
"version": "0.17.
|
|
791
|
-
"resolved": "https://registry.npmjs.org/clavarium-parley/-/clavarium-parley-0.17.
|
|
792
|
-
"integrity": "sha512-
|
|
790
|
+
"version": "0.17.52-next.1",
|
|
791
|
+
"resolved": "https://registry.npmjs.org/clavarium-parley/-/clavarium-parley-0.17.52-next.1.tgz",
|
|
792
|
+
"integrity": "sha512-He/rzgLU8zQR0jDtQdoyTQqEaaHibPDJVopM5QlBRFGOvjw6R4TWXLPGL1kznjdyo3uKkfEgdv5snhdy5rq3Ng==",
|
|
793
793
|
"license": "MIT",
|
|
794
794
|
"bin": {
|
|
795
795
|
"parley": "bin/parley.mjs",
|
|
@@ -800,9 +800,9 @@
|
|
|
800
800
|
}
|
|
801
801
|
},
|
|
802
802
|
"node_modules/clavarium-tether": {
|
|
803
|
-
"version": "0.1.0-next.
|
|
804
|
-
"resolved": "https://registry.npmjs.org/clavarium-tether/-/clavarium-tether-0.1.0-next.
|
|
805
|
-
"integrity": "sha512-
|
|
803
|
+
"version": "0.1.0-next.49",
|
|
804
|
+
"resolved": "https://registry.npmjs.org/clavarium-tether/-/clavarium-tether-0.1.0-next.49.tgz",
|
|
805
|
+
"integrity": "sha512-r2TNj/eC6U5drx4GDxo05iZKPwJ8M4cgq4l6IQhMDdys61x9Q1TKp9gTY7WFa4TOVQ1k8prRwChgvFB9kOWAXA==",
|
|
806
806
|
"license": "MIT",
|
|
807
807
|
"bin": {
|
|
808
808
|
"tether": "bin/cli.mjs",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.145-beta.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "A conversation is a VM with a terminal in it. Everything else is a folder.",
|
|
@@ -44,10 +44,10 @@
|
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@xterm/addon-fit": "^0.11.0",
|
|
46
46
|
"@xterm/xterm": "^6.0.0",
|
|
47
|
-
"clavarium-binder": "0.1.
|
|
47
|
+
"clavarium-binder": "0.1.59-next.1",
|
|
48
48
|
"clavarium-docket": "0.1.2-next.2",
|
|
49
|
-
"clavarium-parley": "0.17.
|
|
50
|
-
"clavarium-tether": "0.1.0-next.
|
|
49
|
+
"clavarium-parley": "0.17.52-next.1",
|
|
50
|
+
"clavarium-tether": "0.1.0-next.49",
|
|
51
51
|
"mammoth": "1.13.0",
|
|
52
52
|
"mermaid": "11.17.2",
|
|
53
53
|
"node-pty": "^1.1.0",
|
package/server/api.mjs
CHANGED
|
@@ -89,6 +89,12 @@
|
|
|
89
89
|
* POST /api/asset-groups/place {asset, group}: put an asset in a group (group null to take it out)
|
|
90
90
|
* POST /api/asset-groups/<id>/rename {label}
|
|
91
91
|
* POST /api/asset-groups/<id>/remove
|
|
92
|
+
* GET /api/rooms the rooms (#268): [{id, name, host, members: [{id, kind, name, ref, host?}]}]
|
|
93
|
+
* POST /api/rooms {name, conversations: [names], boxes: [ids], host?}: a new room
|
|
94
|
+
* POST /api/rooms/<id> {name?, host?, add?: {conversations, boxes}, remove?: [member ids]}
|
|
95
|
+
* POST /api/rooms/<id>/remove the room and its thread
|
|
96
|
+
* GET /api/rooms/<id>/talk?last= its thread, with the room: {room, messages, ...}
|
|
97
|
+
* POST /api/rooms/<id>/talk {text, to?: [AI member ids]}: said in it; to its host, or to the AIs named
|
|
92
98
|
* GET /api/conversations/<name>/health-react POST the same {on?, message?, command?}: what it does when its machine is short
|
|
93
99
|
* GET /api/machines/places GET /api/machines/moving POST /api/machines/move {to}: all the machines to another disk
|
|
94
100
|
* POST /api/machines/forget-old: the copy a move left behind, removed
|
|
@@ -165,7 +171,7 @@ function readBody(request, max = BODY_MAX) {
|
|
|
165
171
|
/* This run of the server: a page's count of binder changes is of one run, and starts again with the next. */
|
|
166
172
|
const BOOT = Math.random().toString(36).slice(2, 10);
|
|
167
173
|
|
|
168
|
-
export async function handleApi(request, response, conversations, headers, resources, originOk = sameOrigin, shortcuts, voice, sharing, secrets, network, signin, mailboxes, gitReview, platform, answerer, wakeups, alerts, talk, gitAccess, gitKeeper, shelf, health, setup, repair, guide, capacity, updates, instance, certificate, team, reacting, machinesMove, serverLogs, history, events, bundles, wifi, binders, meshcentral, tethers, accounts, groups, catalogue) {
|
|
174
|
+
export async function handleApi(request, response, conversations, headers, resources, originOk = sameOrigin, shortcuts, voice, sharing, secrets, network, signin, mailboxes, gitReview, platform, answerer, wakeups, alerts, talk, gitAccess, gitKeeper, shelf, health, setup, repair, guide, capacity, updates, instance, certificate, team, reacting, machinesMove, serverLogs, history, events, bundles, wifi, binders, meshcentral, tethers, accounts, groups, catalogue, rooms) {
|
|
169
175
|
const { pathname } = new URL(request.url ?? '/', 'http://local');
|
|
170
176
|
if (!pathname.startsWith('/api/')) return false;
|
|
171
177
|
let send = (status, body) => {
|
|
@@ -265,6 +271,10 @@ export async function handleApi(request, response, conversations, headers, resou
|
|
|
265
271
|
holds. Distinct from /api/groups/* above, which are the conversation
|
|
266
272
|
list's folders. */
|
|
267
273
|
if (pathname === '/api/asset-groups' && groups) return send(200, groups.list()), true;
|
|
274
|
+
/* Rooms (#268, rooms.mjs): a thread shared by several AIs, the person and boxes. */
|
|
275
|
+
if (pathname === '/api/rooms' && rooms) return send(200, rooms.list()), true;
|
|
276
|
+
const roomTalk = /^\/api\/rooms\/([0-9a-f-]{36})\/talk$/.exec(pathname);
|
|
277
|
+
if (roomTalk && rooms) { const last = Number(query.get('last')); return send(200, rooms.read(roomTalk[1], Number.isInteger(last) && last > 0 ? { last } : undefined)), true; }
|
|
268
278
|
if (pathname === '/api/mailboxes' && mailboxes) return send(200, mailboxes.list()), true;
|
|
269
279
|
/* Which providers and kinds an account can be connected for here. */
|
|
270
280
|
if (pathname === '/api/accounts' && accounts) return send(200, { supported: accounts.supported() }), true;
|
|
@@ -402,6 +412,13 @@ export async function handleApi(request, response, conversations, headers, resou
|
|
|
402
412
|
const body = await readBody(request, pathname === '/api/setup/preview' || pathname === '/api/setup/import' ? SETUP_BODY_MAX : BODY_MAX);
|
|
403
413
|
/* What was done, once it was done: said in What happened (events.mjs), for those worth saying. */
|
|
404
414
|
if (events) { const answer = send; send = (status, out) => { if (status < 300) { try { events.fromRequest(pathname, body, identity, out); } catch { /* never in the way */ } } answer(status, out); }; }
|
|
415
|
+
if (rooms && pathname.startsWith('/api/rooms')) {
|
|
416
|
+
if (pathname === '/api/rooms') return send(201, rooms.create(body ?? {})), true;
|
|
417
|
+
const r = /^\/api\/rooms\/([0-9a-f-]{36})(\/remove|\/talk)?$/.exec(pathname);
|
|
418
|
+
if (r && !r[2]) return send(200, rooms.change(r[1], body ?? {})), true;
|
|
419
|
+
if (r && r[2] === '/remove') { rooms.remove(r[1]); return send(200, { removed: r[1] }), true; }
|
|
420
|
+
if (r && r[2] === '/talk') return send(201, await rooms.say(r[1], body?.text, { to: body?.to })), true;
|
|
421
|
+
}
|
|
405
422
|
if (pathname === '/api/conversations') {
|
|
406
423
|
await conversations.admit?.(body);
|
|
407
424
|
const made = conversations.create(body);
|
package/server/main.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Rooms } from './rooms.mjs';
|
|
1
2
|
import { Catalogue } from './catalog.mjs';
|
|
2
3
|
/* The server. Loopback only: what faces the internet is the edge in front of it.
|
|
3
4
|
*
|
|
@@ -173,7 +174,7 @@ const withoutTmux = (env) => Object.fromEntries(Object.entries(env).filter(([key
|
|
|
173
174
|
|
|
174
175
|
const REFUSED = 'This Clavarium belongs to someone else: your account is not one of its operators.\n';
|
|
175
176
|
|
|
176
|
-
function serve(port, conversations, resources, { gate = () => 'local', originOk, shortcuts, voice, sharing, door, secrets, network, signin, mailboxes, gitReview, platform, answerer, wakeups, alerts, talk, gitAccess, gitKeeper, shelf, health, setup, guide, repair, capacity, updates, instance = new Instance(), certificate, team, reacting, machinesMove, serverLogs, history, events, bundles, wifi, binders, meshcentral, tethers, accounts, groups, boxes, catalogue } = {}) {
|
|
177
|
+
function serve(port, conversations, resources, { gate = () => 'local', originOk, shortcuts, voice, sharing, door, secrets, network, signin, mailboxes, gitReview, platform, answerer, wakeups, alerts, talk, gitAccess, gitKeeper, shelf, health, setup, guide, repair, capacity, updates, instance = new Instance(), certificate, team, reacting, machinesMove, serverLogs, history, events, bundles, wifi, binders, meshcentral, tethers, accounts, groups, boxes, catalogue, rooms } = {}) {
|
|
177
178
|
/* Its manifest carries the name of this Clavarium, or the one a device chose (instance.mjs). */
|
|
178
179
|
const sendManifest = (response, url) => response.writeHead(200, { ...HEADERS, 'content-type': 'application/manifest+json' }).end(instance.manifest(new URL(url ?? '/', 'http://local').searchParams.get('name') ?? undefined));
|
|
179
180
|
const sendFile = async (response, file) => {
|
|
@@ -234,7 +235,7 @@ function serve(port, conversations, resources, { gate = () => 'local', originOk,
|
|
|
234
235
|
return;
|
|
235
236
|
}
|
|
236
237
|
if (boxes && pathname.startsWith('/api/boxes') && await handleBoxes(request, response, boxes, originOk, HEADERS, (text) => QRCode.toString(text, { type: 'svg', margin: 1, errorCorrectionLevel: 'M' }))) return;
|
|
237
|
-
if (conversations && await handleApi(request, response, conversations, HEADERS, resources, originOk, shortcuts, voice, sharing, secrets, network, signin, mailboxes, gitReview, platform, answerer, wakeups, alerts, talk, gitAccess, gitKeeper, shelf, health, setup, repair, guide, capacity, updates, instance, certificate, team, reacting, machinesMove, serverLogs, history, events, bundles, wifi, binders, meshcentral, tethers, accounts, groups, catalogue)) return;
|
|
238
|
+
if (conversations && await handleApi(request, response, conversations, HEADERS, resources, originOk, shortcuts, voice, sharing, secrets, network, signin, mailboxes, gitReview, platform, answerer, wakeups, alerts, talk, gitAccess, gitKeeper, shelf, health, setup, repair, guide, capacity, updates, instance, certificate, team, reacting, machinesMove, serverLogs, history, events, bundles, wifi, binders, meshcentral, tethers, accounts, groups, catalogue, rooms)) return;
|
|
238
239
|
if (pathname === '/manifest.webmanifest' && request.method === 'GET') { sendManifest(response, request.url); return; }
|
|
239
240
|
const file = FILES[pathname];
|
|
240
241
|
if (!file || (request.method !== 'GET' && request.method !== 'HEAD')) {
|
|
@@ -483,8 +484,8 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
|
|
|
483
484
|
const gitTimer = gitKeeper.start(gitEveryMs);
|
|
484
485
|
/* A conversation with a tool on a screen that is not its terminal: see talk.mjs. */
|
|
485
486
|
/* Voice boxes: what the tool says in their conversation is read aloud (boxes.mjs). */
|
|
486
|
-
let boxes;
|
|
487
|
-
const talk = new Talk({ spoke: (name, text, to, how) => { void boxes?.agentSaid(name, text, to, how); }, store: talkStore, words: new Store(`${dataDir}/talk-words.json`), keptDir: `${dataDir}/talk-kept`, vms, conversations: all, resources: folders, toolbox, warm: (name) => bridge?.warm(name), ...(talkEveryMs ? { listenEveryMs: talkEveryMs } : {}),
|
|
487
|
+
let boxes; let rooms;
|
|
488
|
+
const talk = new Talk({ spoke: (name, text, to, how) => { void boxes?.agentSaid(name, text, to, how); }, inRoom: (name, entry, kind) => rooms?.answered(name, entry, kind), store: talkStore, words: new Store(`${dataDir}/talk-words.json`), keptDir: `${dataDir}/talk-kept`, vms, conversations: all, resources: folders, toolbox, warm: (name) => bridge?.warm(name), ...(talkEveryMs ? { listenEveryMs: talkEveryMs } : {}),
|
|
488
489
|
...(rereadAfterMs === undefined ? {} : { rereadAfterMs }),
|
|
489
490
|
/* A line typed down the terminal already open when there is one, and
|
|
490
491
|
what is already known of a machine used instead of asking (talk.mjs). */
|
|
@@ -641,7 +642,12 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
|
|
|
641
642
|
changed: () => { for (const c of all.list()) talk.speakers(c.name, boxes.speakersOf(c.name)); try { syncTargets(tethers.store(), boxes.all()); } catch (error) { console.error(`voice boxes in Tether: ${error.message}`); } },
|
|
642
643
|
speak: (text) => speech.speak(text),
|
|
643
644
|
log: (line) => events.add({ kind: 'server', text: line }) });
|
|
644
|
-
|
|
645
|
+
/* Rooms (#268): a thread shared by several AIs, the person and boxes (rooms.mjs). */
|
|
646
|
+
rooms = new Rooms({ file: new JsonFile(`${dataDir}/rooms.json`, []), dir: `${dataDir}/rooms`,
|
|
647
|
+
say: (name, text, extra) => talk.say(name, text, undefined, undefined, undefined, extra),
|
|
648
|
+
rooms: (name, list) => talk.rooms(name, list), conversations: () => all.list(), boxes: () => boxes.all() });
|
|
649
|
+
rooms.refresh();
|
|
650
|
+
const { server, listening } = serve(port, all, folders, { gate, originOk, shortcuts, voice, sharing, door, secrets, network, signin, mailboxes, gitReview, platform, answerer, wakeups, alerts, talk, gitAccess, gitKeeper, shelf, health, setup, guide, capacity, updates, instance, certificate, team, reacting, machinesMove, serverLogs, history, events, wifi, binders, meshcentral, tethers, accounts, groups, boxes, catalogue, rooms, bundles: new Bundles({ dir: `${dataDir}/imports`, folder: (name) => folders.folder(name) }), repair: (name) => repairTerminal(name) });
|
|
645
651
|
server.on('close', () => { closing = true; stopBinders(); stopTethers(); clearInterval(historyTimer); clearInterval(secretsTimer); history.save(); stopVmWatch(); stopShelf(); stopHealth(); stopUpdates(); stopWatch(); clearInterval(mailTimer); clearInterval(restartTimer); clearInterval(expiryTimer); clearInterval(answerTimer); clearInterval(wakeTimer); clearInterval(docketTimer); dockets.stop(); clearInterval(gitTimer); talk.stop(); });
|
|
646
652
|
let closing = false;
|
|
647
653
|
boxes.attach(server, WebSocketServer);
|
package/server/rooms.mjs
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/* ROOMS (#268, #279): a thread shared by several conversations (AIs), the person and voice boxes.
|
|
2
|
+
*
|
|
3
|
+
* A room is kept here, never in a machine: its thread is a Parley folder of this server's (rooms/<id>/),
|
|
4
|
+
* written by this server alone -- the person's side (the person, a box) and, signed, each AI's words. No
|
|
5
|
+
* AI can write there: what it answers comes from its own folder, and is signed by WHERE it came from
|
|
6
|
+
* (which conversation), never by what it says of itself (03-11).
|
|
7
|
+
*
|
|
8
|
+
* members each with an id of its own (a uuid), whatever it is: the person, an AI (a conversation),
|
|
9
|
+
* a box. The name is only shown; the kind picks the shape of its chip.
|
|
10
|
+
* the host one AI of the room: what is said with nobody named goes to it alone (it answers, or
|
|
11
|
+
* hands it on -- #280).
|
|
12
|
+
* to an AI a person's message goes to the host; the host's (and any AI's) answer comes back here
|
|
13
|
+
* when it says so (parley tell --room), and only to a room it is a member of.
|
|
14
|
+
*
|
|
15
|
+
* Each conversation of a room is told which rooms it is in, and who is there (Parley's rooms.json).
|
|
16
|
+
*/
|
|
17
|
+
import { mkdirSync, rmSync } from 'node:fs';
|
|
18
|
+
import { randomUUID } from 'node:crypto';
|
|
19
|
+
import { Parley } from 'clavarium-parley/host';
|
|
20
|
+
import { Refusal } from './conversations.mjs';
|
|
21
|
+
|
|
22
|
+
export const ROOM_NAME_MAX = 60;
|
|
23
|
+
export const ROOMS_MAX = 20;
|
|
24
|
+
export const MEMBERS_MAX = 40;
|
|
25
|
+
/* Hand-overs between AIs after the person (or a box) last spoke in a room: a few, never a loop. */
|
|
26
|
+
export const HOPS_MAX = 8;
|
|
27
|
+
const KINDS = ['person', 'ai', 'box'];
|
|
28
|
+
const nameOf = (v) => String(v ?? '').replace(/\s+/g, ' ').trim().slice(0, ROOM_NAME_MAX);
|
|
29
|
+
|
|
30
|
+
export class Rooms {
|
|
31
|
+
#file; #dir; #say; #rooms; #conversations; #boxes; #now; #hops = new Map();
|
|
32
|
+
/* file: a JsonFile of the rooms; dir: where their threads are; say(name, text, extra): a message written in a
|
|
33
|
+
conversation's own chat (talk.say); rooms(name, list): what a conversation is told of its rooms (talk.rooms);
|
|
34
|
+
conversations(): the conversations there are; boxes(): the voice boxes there are. */
|
|
35
|
+
constructor({ file, dir, say, rooms = () => {}, conversations = () => [], boxes = () => [], now = () => new Date() }) {
|
|
36
|
+
this.#file = file; this.#dir = dir; this.#say = say; this.#rooms = rooms; this.#conversations = conversations; this.#boxes = boxes; this.#now = now;
|
|
37
|
+
}
|
|
38
|
+
#all() { const v = this.#file.get(); return Array.isArray(v) ? v : []; }
|
|
39
|
+
#save(list) { this.#file.set(list); this.#tellConversations(list); }
|
|
40
|
+
#thread(id) { mkdirSync(`${this.#dir}/${id}`, { recursive: true }); return new Parley(`${this.#dir}/${id}`, { room: true, now: this.#now }); }
|
|
41
|
+
#find(id) { const r = this.#all().find((x) => x.id === id); if (!r) throw new Refusal(404, 'No such room.'); return r; }
|
|
42
|
+
|
|
43
|
+
/* Its members as they are now: names of the moment (a conversation renamed, a box renamed). */
|
|
44
|
+
#shown(room) {
|
|
45
|
+
const boxes = new Map(this.#boxes().map((b) => [b.id, b]));
|
|
46
|
+
/* An AI is named as its chat names it (the name the owner gave it in its chat settings), else its title, else its name. */
|
|
47
|
+
const convs = new Map(this.#conversations().map((c) => [c.name, c.chatName || c.title || c.name]));
|
|
48
|
+
return room.members.filter((m) => (m.kind === 'ai' ? convs.has(m.ref) : m.kind === 'box' ? boxes.has(m.ref) : true))
|
|
49
|
+
.map((m) => ({ id: m.id, kind: m.kind, name: m.kind === 'box' ? (boxes.get(m.ref)?.name ?? m.name) : m.kind === 'ai' ? convs.get(m.ref) : m.name, ref: m.ref, ...(m.id === room.host ? { host: true } : {}) }));
|
|
50
|
+
}
|
|
51
|
+
list() { return this.#all().map((r) => ({ id: r.id, name: r.name, host: r.host, members: this.#shown(r), at: r.at })); }
|
|
52
|
+
get(id) { const r = this.#find(id); return { id: r.id, name: r.name, host: r.host, members: this.#shown(r), at: r.at }; }
|
|
53
|
+
|
|
54
|
+
/* A new room: its name, its AIs (conversation names), its boxes (ids), and which AI is the host (the first by default). */
|
|
55
|
+
create({ name, conversations = [], boxes = [], host } = {}) {
|
|
56
|
+
const n = nameOf(name);
|
|
57
|
+
if (!n) throw new Refusal(400, 'Give the room a name.');
|
|
58
|
+
const list = this.#all();
|
|
59
|
+
if (list.length >= ROOMS_MAX) throw new Refusal(409, `${ROOMS_MAX} rooms at most.`);
|
|
60
|
+
if (list.some((r) => r.name.toLowerCase() === n.toLowerCase())) throw new Refusal(409, 'A room has that name already.');
|
|
61
|
+
const room = { id: randomUUID(), name: n, at: this.#now().toISOString(), members: [{ id: randomUUID(), kind: 'person', ref: 'owner', name: 'Toi' }] };
|
|
62
|
+
this.#add(room, conversations, boxes);
|
|
63
|
+
const ais = room.members.filter((m) => m.kind === 'ai');
|
|
64
|
+
if (!ais.length) throw new Refusal(400, 'A room has one AI at least: its host.');
|
|
65
|
+
room.host = (ais.find((m) => m.ref === host) ?? ais[0]).id;
|
|
66
|
+
this.#save([...list, room]);
|
|
67
|
+
this.#thread(room.id);
|
|
68
|
+
return this.get(room.id);
|
|
69
|
+
}
|
|
70
|
+
#add(room, conversations, boxes) {
|
|
71
|
+
const known = new Set(this.#conversations().map((c) => c.name));
|
|
72
|
+
const knownBoxes = new Map(this.#boxes().map((b) => [b.id, b]));
|
|
73
|
+
for (const c of Array.isArray(conversations) ? conversations : []) {
|
|
74
|
+
if (!known.has(c)) throw new Refusal(400, `No conversation is called ${String(c).slice(0, 40)}.`);
|
|
75
|
+
if (!room.members.some((m) => m.kind === 'ai' && m.ref === c)) room.members.push({ id: randomUUID(), kind: 'ai', ref: c, name: c });
|
|
76
|
+
}
|
|
77
|
+
for (const b of Array.isArray(boxes) ? boxes : []) {
|
|
78
|
+
const box = knownBoxes.get(b);
|
|
79
|
+
if (!box) throw new Refusal(400, 'No such voice box.');
|
|
80
|
+
if (!room.members.some((m) => m.kind === 'box' && m.ref === b)) room.members.push({ id: randomUUID(), kind: 'box', ref: b, name: box.name });
|
|
81
|
+
}
|
|
82
|
+
/* One name, one member (03-11): who is who is never in doubt, in the thread or said aloud. */
|
|
83
|
+
const names = this.#shown({ ...room, host: null }).map((m) => m.name.toLowerCase());
|
|
84
|
+
if (new Set(names).size !== names.length) throw new Refusal(409, 'Two members of a room cannot have the same name: rename one first.');
|
|
85
|
+
if (room.members.length > MEMBERS_MAX) throw new Refusal(409, `${MEMBERS_MAX} members at most.`);
|
|
86
|
+
}
|
|
87
|
+
/* Its name, its host, members added or taken away. */
|
|
88
|
+
change(id, { name, host, add = {}, remove = [] } = {}) {
|
|
89
|
+
const list = this.#all(); const room = list.find((r) => r.id === id);
|
|
90
|
+
if (!room) throw new Refusal(404, 'No such room.');
|
|
91
|
+
if (name !== undefined) {
|
|
92
|
+
const n = nameOf(name); if (!n) throw new Refusal(400, 'Give the room a name.');
|
|
93
|
+
if (list.some((r) => r.id !== id && r.name.toLowerCase() === n.toLowerCase())) throw new Refusal(409, 'A room has that name already.');
|
|
94
|
+
room.name = n;
|
|
95
|
+
}
|
|
96
|
+
room.members = room.members.filter((m) => m.kind === 'person' || !(Array.isArray(remove) ? remove : []).includes(m.id));
|
|
97
|
+
this.#add(room, add.conversations ?? [], add.boxes ?? []);
|
|
98
|
+
const ais = room.members.filter((m) => m.kind === 'ai');
|
|
99
|
+
if (!ais.length) throw new Refusal(400, 'A room keeps one AI at least: its host.');
|
|
100
|
+
if (host !== undefined) { if (!ais.some((m) => m.id === host)) throw new Refusal(400, 'The host is one of its AIs.'); room.host = host; }
|
|
101
|
+
if (!ais.some((m) => m.id === room.host)) room.host = ais[0].id;
|
|
102
|
+
this.#save(list);
|
|
103
|
+
return this.get(id);
|
|
104
|
+
}
|
|
105
|
+
remove(id) { this.#find(id); this.#save(this.#all().filter((r) => r.id !== id)); rmSync(`${this.#dir}/${id}`, { recursive: true, force: true }); }
|
|
106
|
+
|
|
107
|
+
/* ITS THREAD, as a screen reads it (Parley's read, the members' names of the moment). */
|
|
108
|
+
read(id, options) {
|
|
109
|
+
const room = this.#find(id); const t = this.#thread(room.id); const members = this.#shown(room);
|
|
110
|
+
t.setSpeakers(members.map((m) => ({ id: m.id, name: m.name, kind: m.kind })));
|
|
111
|
+
const read = t.read(options);
|
|
112
|
+
/* A member named in a text (@{id}): its name of the moment, on the screen. */
|
|
113
|
+
const named = (text) => String(text ?? '').replace(/@\{([0-9a-f-]{36})\}/g, (whole, mid) => { const m = members.find((x) => x.id === mid); return m ? `@${m.name}` : whole; });
|
|
114
|
+
return { room: this.get(id), ...read, messages: (read.messages ?? []).map((m) => (typeof m.text === 'string' && m.text.includes('@{') ? { ...m, text: named(m.text) } : m)) };
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/* SOMEONE OF THE PERSON'S SIDE SPEAKS (the person here, a box): kept in the room, given to the host -- or to the
|
|
118
|
+
AIs named (to: their member ids). */
|
|
119
|
+
async say(id, text, { by, to } = {}) {
|
|
120
|
+
const room = this.#find(id); const members = this.#shown(room);
|
|
121
|
+
const who = by ? members.find((m) => m.id === by && m.kind !== 'ai') : members.find((m) => m.kind === 'person');
|
|
122
|
+
if (!who) throw new Refusal(400, 'Not a member of this room.');
|
|
123
|
+
const t = this.#thread(room.id);
|
|
124
|
+
this.#hops.set(room.id, 0);
|
|
125
|
+
/* The owner is the room's own side (no name over their words, as in any chat); anyone else is named. */
|
|
126
|
+
const now = t.say(text, undefined, [], who.ref === 'owner' ? {} : { by: { id: who.id, name: who.name, kind: who.kind } });
|
|
127
|
+
const said = now.messages.at(-1);
|
|
128
|
+
const named = (Array.isArray(to) ? to : []).map((x) => members.find((m) => m.id === x && m.kind === 'ai')).filter(Boolean);
|
|
129
|
+
const host = members.find((m) => m.id === room.host);
|
|
130
|
+
for (const ai of named.length ? named : host ? [host] : []) {
|
|
131
|
+
await this.#say(ai.ref, said.text, { by: { id: who.id, name: who.name, kind: who.kind }, room: { id: room.id, name: room.name, message: said.id } });
|
|
132
|
+
}
|
|
133
|
+
return this.read(id);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/* AN AI ANSWERS IN A ROOM (what its own folder says, entry.room): only to a room it is in; signed by where it
|
|
137
|
+
came from; the message it answers found by its id or its first characters. */
|
|
138
|
+
answered(conversation, entry, kind = 'say') {
|
|
139
|
+
const room = this.#all().find((r) => r.id === entry?.room);
|
|
140
|
+
if (!room) return null;
|
|
141
|
+
const members = this.#shown(room);
|
|
142
|
+
const me = members.find((m) => m.kind === 'ai' && m.ref === conversation);
|
|
143
|
+
if (!me) return null;
|
|
144
|
+
const t = this.#thread(room.id);
|
|
145
|
+
const all = () => t.read({ all: true }).messages;
|
|
146
|
+
const find = (id) => (typeof id === 'string' && id.length >= 8 ? all().find((m) => m.id.startsWith(id)) : undefined);
|
|
147
|
+
const re = find(entry.re)?.id;
|
|
148
|
+
const ids = new Set(members.map((m) => m.id));
|
|
149
|
+
const to = Array.isArray(entry.to) ? entry.to.filter((x) => ids.has(x) && x !== me.id) : [];
|
|
150
|
+
/* The other AIs it is sent to (#280): they get it in their own chat, as said in the room -- never beyond a few
|
|
151
|
+
hand-overs after the person last spoke (no two AIs talking for ever). */
|
|
152
|
+
const ais = to.map((x) => members.find((m) => m.id === x && m.kind === 'ai')).filter(Boolean);
|
|
153
|
+
const handOver = (ai, text, from, message) => {
|
|
154
|
+
const n = (this.#hops.get(room.id) ?? 0) + 1;
|
|
155
|
+
if (n > HOPS_MAX) return false;
|
|
156
|
+
this.#hops.set(room.id, n);
|
|
157
|
+
void this.#say(ai.ref, text, { by: from, room: { id: room.id, name: room.name, message } }).catch(() => {});
|
|
158
|
+
return true;
|
|
159
|
+
};
|
|
160
|
+
/* Handed on as it is: the message itself, by who said it; the room's thread keeps no copy. */
|
|
161
|
+
const forwarded = find(entry.forward);
|
|
162
|
+
if (forwarded) {
|
|
163
|
+
const from = forwarded.by ? { id: forwarded.by.id, name: forwarded.by.name, kind: forwarded.by.kind ?? 'person' } : { id: members.find((m) => m.kind === 'person')?.id ?? 'owner', name: members.find((m) => m.kind === 'person')?.name ?? 'Owner', kind: 'person' };
|
|
164
|
+
for (const ai of ais) handOver(ai, forwarded.text, from, forwarded.id);
|
|
165
|
+
if (!String(entry.text ?? '').trim()) return forwarded.id;
|
|
166
|
+
}
|
|
167
|
+
if (!String(entry.text ?? '').trim()) return null;
|
|
168
|
+
/* @Name of a member, exactly: kept as its id (the screen says its name of the moment). */
|
|
169
|
+
const text = String(entry.text).replace(/@([^\s@{][^@\n]{0,40}?)(?=[\s,.;:!?)]|$)/g, (whole, name) => { const m = members.find((x) => x.name.toLowerCase() === name.toLowerCase()); return m ? `@{${m.id}}` : whole; });
|
|
170
|
+
const id = t.relay({ text, by: { id: me.id, name: me.name, kind: 'ai' }, to, re, kind: kind === 'doing' ? 'doing' : 'say' });
|
|
171
|
+
if (!forwarded && kind !== 'doing') for (const ai of ais) handOver(ai, text, { id: me.id, name: me.name, kind: 'ai' }, id);
|
|
172
|
+
return id;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/* Each conversation told the rooms it is in, and who is there. */
|
|
176
|
+
#tellConversations(list) {
|
|
177
|
+
const shown = list.map((r) => ({ ...r, members: this.#shown(r) }));
|
|
178
|
+
for (const c of this.#conversations()) {
|
|
179
|
+
const mine = shown.filter((r) => r.members.some((m) => m.kind === 'ai' && m.ref === c.name))
|
|
180
|
+
.map((r) => ({ id: r.id, name: r.name, members: r.members.map((m) => ({ id: m.id, name: m.name, kind: m.kind })) }));
|
|
181
|
+
try { this.#rooms(c.name, mine); } catch { /* its folder is not there yet */ }
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
refresh() { this.#tellConversations(this.#all()); }
|
|
185
|
+
/* A conversation renamed: its member follows it. */
|
|
186
|
+
conversationRenamed(from, to) { const list = this.#all(); let moved = false; for (const r of list) for (const m of r.members) if (m.kind === 'ai' && m.ref === from) { m.ref = to; m.name = to; moved = true; } if (moved) this.#save(list); }
|
|
187
|
+
}
|
|
188
|
+
export { KINDS };
|
package/server/talk.mjs
CHANGED
|
@@ -191,7 +191,7 @@ export const windowOf = (choice) => { const [kind, n] = String(choice).split(':'
|
|
|
191
191
|
/* What the page may ask for: a part of the thread (Parley's read(options)), its own cursor for "since". */
|
|
192
192
|
const PART = /^[A-Za-z0-9._~-]{1,200}$/;
|
|
193
193
|
export class Talk {
|
|
194
|
-
#store; #words; #vms; #conversations; #resources; #toolbox; #warm; #alert; #spoke; #listening = new Map(); #every; #now;
|
|
194
|
+
#store; #words; #vms; #conversations; #resources; #toolbox; #warm; #alert; #spoke; #inRoom; #listening = new Map(); #every; #now;
|
|
195
195
|
#typedAt = new Map(); #nextTry = new Map(); #trying = new Map(); #timer; #lastLang = 'en'; #rereadAfter;
|
|
196
196
|
#terminal; #health; #ranAt = new Map(); #kept; #screen; #dropSecret;
|
|
197
197
|
|
|
@@ -203,9 +203,9 @@ export class Talk {
|
|
|
203
203
|
/* `keptDir`: where each conversation's thread is kept (its own folder),
|
|
204
204
|
in this server's data -- never in the work folder, which its machine
|
|
205
205
|
writes. Without it, the bridge folder is all there is. */
|
|
206
|
-
constructor({ store, words, vms, conversations, resources, toolbox = null, warm = async () => {}, alert = () => {}, spoke = () => {}, listenEveryMs = 2000, now = () => Date.now(), rereadAfterMs = REREAD_AFTER_MS, terminal = null, health = null, keptDir = null, screen = null, dropSecret = null }) {
|
|
206
|
+
constructor({ store, words, vms, conversations, resources, toolbox = null, warm = async () => {}, alert = () => {}, spoke = () => {}, inRoom = () => {}, listenEveryMs = 2000, now = () => Date.now(), rereadAfterMs = REREAD_AFTER_MS, terminal = null, health = null, keptDir = null, screen = null, dropSecret = null }) {
|
|
207
207
|
this.#terminal = terminal; this.#health = health; this.#kept = keptDir; this.#screen = screen; this.#dropSecret = dropSecret;
|
|
208
|
-
this.#store = store; this.#words = words; this.#vms = vms; this.#conversations = conversations; this.#resources = resources; this.#toolbox = toolbox; this.#warm = warm; this.#alert = alert; this.#spoke = spoke; this.#every = listenEveryMs; this.#now = now; this.#rereadAfter = rereadAfterMs;
|
|
208
|
+
this.#store = store; this.#words = words; this.#vms = vms; this.#conversations = conversations; this.#resources = resources; this.#toolbox = toolbox; this.#warm = warm; this.#alert = alert; this.#spoke = spoke; this.#inRoom = inRoom; this.#every = listenEveryMs; this.#now = now; this.#rereadAfter = rereadAfterMs;
|
|
209
209
|
for (const s of store.all()) if (s.on === true) this.#listen(s.name);
|
|
210
210
|
this.#timer = setInterval(() => { void this.#tick(); }, Math.min(listenEveryMs, 1000));
|
|
211
211
|
this.#timer.unref?.();
|
|
@@ -292,6 +292,8 @@ export class Talk {
|
|
|
292
292
|
if (event.type === 'person-reacted') { reacted(event); return; }
|
|
293
293
|
if (event.type === 'person-wrote') { this.#want(name); return; }
|
|
294
294
|
/* What the tool says or asks: a voice box of this conversation may read it aloud (boxes.mjs). */
|
|
295
|
+
/* Answered in a room it is in (#268): the room takes it, signed by where it came from (rooms.mjs). */
|
|
296
|
+
if (['agent-said', 'agent-asked', 'agent-doing'].includes(event.type) && typeof event.message?.room === 'string') { try { this.#inRoom(name, event.message, event.type === 'agent-doing' ? 'doing' : 'say'); } catch { /* the room's */ } return; }
|
|
295
297
|
if (event.type === 'agent-said' || event.type === 'agent-asked') this.#spoke(name, event.message?.text ?? '', Array.isArray(event.message?.to) ? event.message.to : null, { asked: event.type === 'agent-asked' });
|
|
296
298
|
/* What it is doing: said by a box that was just spoken to, so nobody waits in silence. */
|
|
297
299
|
if (event.type === 'agent-doing') this.#spoke(name, event.message?.text ?? '', Array.isArray(event.message?.to) ? event.message.to : null, { doing: true });
|
|
@@ -458,6 +460,8 @@ export class Talk {
|
|
|
458
460
|
|
|
459
461
|
/* The voice boxes of a conversation, as Parley names them to its agent and its screen (#215). */
|
|
460
462
|
speakers(name, list) { try { this.#parley(name).setSpeakers(list); } catch { /* its folder is not there yet */ } }
|
|
463
|
+
/* The rooms it is in, and who is there (#268): told to its agent, which answers there by their ids. */
|
|
464
|
+
rooms(name, list) { try { this.#parley(name).setRooms(list); } catch { /* its folder is not there yet */ } }
|
|
461
465
|
|
|
462
466
|
async say(name, text, answers, files, via, extra) {
|
|
463
467
|
if (!this.of(name).on) throw new Refusal(409, 'Talking through the app is not turned on for this conversation.');
|
|
@@ -480,7 +484,7 @@ export class Talk {
|
|
|
480
484
|
never lose a message: on any trouble the text is sent as it came. */
|
|
481
485
|
let said = text ?? '';
|
|
482
486
|
if (this.#screen && said) { try { said = await this.#screen(name, said); } catch { said = text ?? ''; } }
|
|
483
|
-
try { this.#parley(name).say(said, answers, attached, { via: via === 'voice' ? 'voice' : undefined, ...(extra && typeof extra === 'object' ? { picked: extra.picked, replies: extra.replies, about: extra.about, by: extra.by } : {}) }); } catch (error) { if (error instanceof RangeError) throw new Refusal(400, error.message); throw error; }
|
|
487
|
+
try { this.#parley(name).say(said, answers, attached, { via: via === 'voice' ? 'voice' : undefined, ...(extra && typeof extra === 'object' ? { picked: extra.picked, replies: extra.replies, about: extra.about, by: extra.by, room: extra.room } : {}) }); } catch (error) { if (error instanceof RangeError) throw new Refusal(400, error.message); throw error; }
|
|
484
488
|
const told = await this.#wake(name);
|
|
485
489
|
return { ...this.of(name), told };
|
|
486
490
|
}
|
package/web/app.js
CHANGED
|
@@ -145,6 +145,18 @@
|
|
|
145
145
|
const was = m.dataset.pose ?? '';
|
|
146
146
|
/* Trying to wake (03-11): it lifts its head, and lies back, again, until it is up (a restart, a build). */
|
|
147
147
|
if (pose === 'trying') { m.classList.remove('waking', 'stirring', 'asleep'); m.classList.add('trying'); m.dataset.pose = 'trying'; return; }
|
|
148
|
+
/* From trying to waking (03-11, no jolt): wait till its head lies down again -- the end of a try, the
|
|
149
|
+
very pose it wakes from -- then rise. At most one try's length (with less motion: no try, no wait). */
|
|
150
|
+
if (pose === 'waking' && was === 'trying') {
|
|
151
|
+
if (m.dataset.rising) return;
|
|
152
|
+
m.dataset.rising = 'yes';
|
|
153
|
+
/* Where it is in its try (2.6 s: lying until 15 %, lying again from 80 %), read from the animation itself. */
|
|
154
|
+
const tryNow = m.querySelector('.m-head')?.getAnimations?.().find((x) => x.animationName === 'm-try');
|
|
155
|
+
const at = Number(tryNow?.currentTime ?? 0) % 2600;
|
|
156
|
+
const rise = () => { delete m.dataset.rising; m.dataset.pose = 'tried'; mascot('waking'); };
|
|
157
|
+
if (at <= 390 || at >= 2080) rise(); else setTimeout(rise, 2080 - at);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
148
160
|
m.classList.remove('trying');
|
|
149
161
|
if (pose === 'waking') {
|
|
150
162
|
if (was === 'waking') return;
|
|
@@ -261,8 +273,9 @@
|
|
|
261
273
|
const s = Math.max(0, Math.floor((Date.now() - (Date.parse(p.since ?? '') || Date.now())) / 1000));
|
|
262
274
|
$('notice-title').textContent = PROGRESS_TITLES[p.kind] ?? 'Starting';
|
|
263
275
|
/* 03-11, less is more: the sheep trying to wake (a wake, a restart, a build), the step under way in one
|
|
264
|
-
line; the list of the steps stays one tap away, and the usual time is said only when it is passed.
|
|
265
|
-
|
|
276
|
+
line; the list of the steps stays one tap away, and the usual time is said only when it is passed.
|
|
277
|
+
It wakes for real at the last step only (03-11, his idea): until then, it tries. */
|
|
278
|
+
mascot(at >= p.steps.length - 1 ? 'waking' : 'trying');
|
|
266
279
|
$('notice-steps').hidden = !panel.open; $('notice-spin').hidden = true;
|
|
267
280
|
$('notice-count').textContent = `${at + 1} / ${p.steps.length} \u00b7 ${clockOf(s)}`;
|
|
268
281
|
$('notice-text').textContent = `${stepNow(p, tool)}${s >= 180 ? ` \u2014 ${usualFor(p.kind, s)}` : ''}`;
|
|
@@ -1280,7 +1293,7 @@
|
|
|
1280
1293
|
/* NEEDS YOU: whatever its date, until its owner acts; hidden ones too (they said so). */
|
|
1281
1294
|
const needs = conversations.filter(needsYou).sort((a, b) => activityOf(b) - activityOf(a));
|
|
1282
1295
|
if (needs.length && section(NEEDS, 'Needs you', needs)) top.append(...unfolding(NEEDS, needs.map((c) => itemButton(c, true))));
|
|
1283
|
-
/* RECENT: by when it was last used;
|
|
1296
|
+
/* RECENT: by when it was last used; up to seven awake, then all. Never a hidden one. Only once there
|
|
1284
1297
|
are groups: before, the one list below says the same, in the order chosen by hand. */
|
|
1285
1298
|
/* One in Needs you just above is not said twice. */
|
|
1286
1299
|
/* The last day only: what is older is found in its group. */
|
|
@@ -1288,9 +1301,14 @@
|
|
|
1288
1301
|
/* Asleep ones go to the bottom of Recent: they are frozen, not what you came back to. */
|
|
1289
1302
|
const recent = conversations.filter((c) => (c.hidden !== true || c.name === current) && !needsYou(c) && activityOf(c) >= dayAgo)
|
|
1290
1303
|
.sort((a, b) => (Number(a.asleep === true) - Number(b.asleep === true)) || (activityOf(b) - activityOf(a)));
|
|
1291
|
-
|
|
1304
|
+
/* In sight (03-11, his rule): up to seven awake ones, and the one open even asleep (it never vanishes
|
|
1305
|
+
under the eyes); the rest -- asleep, or past seven -- under the arrow. */
|
|
1306
|
+
const inSight = recent.filter((c) => c.asleep !== true).slice(0, 7);
|
|
1307
|
+
const openOne = recent.find((c) => c.name === current);
|
|
1308
|
+
if (openOne && !inSight.includes(openOne)) inSight.push(openOne);
|
|
1309
|
+
const few = inSight.length;
|
|
1292
1310
|
if (recent.length && groups.length && section(RECENT, 'Recent', recent)) {
|
|
1293
|
-
top.append(...unfolding(RECENT,
|
|
1311
|
+
top.append(...unfolding(RECENT, (showAllRecent ? recent : recent.filter((c) => inSight.includes(c))).map((c) => itemButton(c, true))));
|
|
1294
1312
|
if (recent.length > few) {
|
|
1295
1313
|
const more = document.createElement('button'); more.type = 'button'; more.className = 'inline more-recent';
|
|
1296
1314
|
/* A chevron, centred: the words for the pointer and for a screen reader. */
|
|
@@ -5040,16 +5058,88 @@
|
|
|
5040
5058
|
return card;
|
|
5041
5059
|
}
|
|
5042
5060
|
const cardAgo = (at) => { const s = Math.max(0, (Date.now() - Date.parse(at)) / 1000); return s < 90 ? 'Just now' : s < 5400 ? `${Math.round(s / 60)} min ago` : s < 129600 ? `${Math.round(s / 3600)} h ago` : `${Math.round(s / 86400)} days ago`; };
|
|
5043
|
-
|
|
5061
|
+
/* ---------- ROOMS (#268): one thread for several AIs, the person and boxes ---------- */
|
|
5062
|
+
let rooms = [];
|
|
5063
|
+
const loadRooms = async () => { try { const r = await fetch(`${API}/rooms`); rooms = r.ok ? await r.json() : []; } catch { rooms = []; } return rooms; };
|
|
5064
|
+
const huePick = (text) => { let h = 0; for (const ch of String(text)) h = (h * 31 + ch.codePointAt(0)) >>> 0; return h % 360; };
|
|
5065
|
+
/* Its members as small chips, each by its shape: a person round, an AI a rounded square, a box an outline. */
|
|
5066
|
+
const memberChips = (members, max = 7) => {
|
|
5067
|
+
const stack = el('span', 'salon-stack');
|
|
5068
|
+
for (const m of members.slice(0, max)) { const i = el('i', `salon-chip salon-chip-${m.kind}`, m.kind === 'box' ? '' : (m.name.trim()[0] ?? '?').toUpperCase()); if (m.kind !== 'box') i.style.setProperty('--h', String(huePick(m.name))); i.title = m.name; stack.append(i); }
|
|
5069
|
+
return stack;
|
|
5070
|
+
};
|
|
5071
|
+
const countOf = (members) => { const n = (k) => members.filter((m) => m.kind === k).length; const say = (k, one, many) => (n(k) ? `${n(k)} ${n(k) > 1 ? many : one}` : ''); return [say('person', 'person', 'people'), say('ai', 'AI', 'AIs'), say('box', 'box', 'boxes')].filter(Boolean).join(' \u00b7 '); };
|
|
5072
|
+
/* A ROOM AS A CARD: like a conversation's, a little thicker (a card behind it), its members' chips on its picture. */
|
|
5073
|
+
function roomCard(r) {
|
|
5074
|
+
const card = el('button', 'conv-card conv-card-room'); card.type = 'button'; card.dataset.room = r.id;
|
|
5075
|
+
const plate = el('span', 'conv-card-plate'); const dot = el('span', 'conv-card-dot'); dot.dataset.state = 'ready';
|
|
5076
|
+
plate.append(dot, el('b', '', r.name));
|
|
5077
|
+
const art = el('span', 'conv-card-art'); art.style.setProperty('--h', String(huePick(r.name)));
|
|
5078
|
+
art.append(el('span', 'conv-card-initial', '\u2302'), memberChips(r.members));
|
|
5079
|
+
card.append(plate, art, el('span', 'conv-card-type', `Room \u00b7 ${countOf(r.members)}`), el('span', 'conv-card-text'));
|
|
5080
|
+
card.setAttribute('aria-label', `${r.name}, room`);
|
|
5081
|
+
card.addEventListener('click', () => { void openSalon(r.id); });
|
|
5082
|
+
return card;
|
|
5083
|
+
}
|
|
5084
|
+
let salonThread = null; let salonId = ''; let salonTimer = null;
|
|
5085
|
+
function salonLeft() { clearInterval(salonTimer); salonTimer = null; salonThread?.destroy(); salonThread = null; salonId = ''; }
|
|
5086
|
+
async function openSalon(id, push = true) {
|
|
5087
|
+
if (DEVICE) return;
|
|
5088
|
+
await loadRooms();
|
|
5089
|
+
const r = rooms.find((x) => x.id === id); if (!r) return;
|
|
5090
|
+
enterPlace('salon', push);
|
|
5091
|
+
salonLeft(); salonId = id;
|
|
5092
|
+
$('salon-title').textContent = r.name;
|
|
5093
|
+
$('salon-who').replaceChildren(memberChips(r.members), el('span', 'hint', `${countOf(r.members)} \u25BE`));
|
|
5094
|
+
$('salon-who').setAttribute('aria-expanded', 'false'); $('salon-members').hidden = true;
|
|
5095
|
+
const rows = ['person', 'ai', 'box'].map((k) => { const of = r.members.filter((m) => m.kind === k); if (!of.length) return null; const row = el('div', 'salon-members-row'); row.append(el('span', 'hint', k === 'person' ? 'People' : k === 'ai' ? 'AIs' : 'Boxes'), ...of.map((m) => { const x = el('span', 'salon-member'); x.append(memberChips([m], 1), document.createTextNode(m.name)); if (m.host) x.append(el('span', 'salon-host', 'host')); return x; })); return row; }).filter(Boolean);
|
|
5096
|
+
$('salon-members').replaceChildren(...rows);
|
|
5097
|
+
const [{ mount }, words] = await Promise.all([import(new URL('vendor/parley-ui.js', new URL('/', location.href)).href), readWords()]);
|
|
5098
|
+
if (salonId !== id) return;
|
|
5099
|
+
salonThread = mount($('salon-thread'), {
|
|
5100
|
+
words, markdown: true, agentName: '',
|
|
5101
|
+
load: (asked = {}) => fetch(`${API}/rooms/${id}/talk${asked.last ? `?last=${asked.last}` : ''}`).then((x) => x.json()),
|
|
5102
|
+
send: (text) => post(`${API}/rooms/${id}/talk`, { text }),
|
|
5103
|
+
diagram: drawDiagram, highlight: colourCode, touch: touchScreen,
|
|
5104
|
+
});
|
|
5105
|
+
salonTimer = setInterval(() => { if (salonThread && salonId === id) void salonThread.refresh(); }, 3000);
|
|
5106
|
+
}
|
|
5107
|
+
$('salon-close').addEventListener('click', () => leavePlace());
|
|
5108
|
+
$('salon-who').addEventListener('click', () => { const open = $('salon-members').hidden; $('salon-members').hidden = !open; $('salon-who').setAttribute('aria-expanded', String(open)); });
|
|
5109
|
+
/* A NEW ROOM: its name, its AIs (the first ticked is its host), its boxes. */
|
|
5110
|
+
async function openSalonNew(push = true) {
|
|
5111
|
+
if (DEVICE) return;
|
|
5112
|
+
enterPlace('salon-new', push);
|
|
5113
|
+
$('salon-new-error').hidden = true; $('salon-new-name').value = '';
|
|
5114
|
+
const tick = (value, label) => { const l = el('label', 'check'); const i = document.createElement('input'); i.type = 'checkbox'; i.value = value; l.append(i, document.createTextNode(label)); return l; };
|
|
5115
|
+
$('salon-new-ais').replaceChildren(...conversations.map((c) => tick(c.name, shownName(c))));
|
|
5116
|
+
let boxes = []; try { const x = await fetch(`${API}/boxes`); boxes = x.ok ? await x.json() : []; } catch { boxes = []; }
|
|
5117
|
+
$('salon-new-boxes').replaceChildren(...(boxes.length ? boxes.map((b) => tick(b.id, b.name)) : [el('span', 'hint', 'None')]));
|
|
5118
|
+
$('salon-new-name').focus();
|
|
5119
|
+
}
|
|
5120
|
+
$('salon-new-close').addEventListener('click', () => leavePlace());
|
|
5121
|
+
$('salon-new-create').addEventListener('click', async () => {
|
|
5122
|
+
const picked = (box) => [...$(box).querySelectorAll('input:checked')].map((i) => i.value);
|
|
5123
|
+
try {
|
|
5124
|
+
const made = await post(`${API}/rooms`, { name: $('salon-new-name').value, conversations: picked('salon-new-ais'), boxes: picked('salon-new-boxes') });
|
|
5125
|
+
await openSalon(made.id, false);
|
|
5126
|
+
} catch (error) { $('salon-new-error').textContent = error.message; $('salon-new-error').hidden = false; }
|
|
5127
|
+
});
|
|
5128
|
+
async function paintDeck() {
|
|
5044
5129
|
$('deck-title').textContent = appName;
|
|
5045
5130
|
const list = [...conversations];
|
|
5046
5131
|
const add = el('button', 'conv-card conv-card-new'); add.type = 'button';
|
|
5047
5132
|
add.append(el('span', 'conv-card-plus', '+'), el('small', '', 'New conversation'));
|
|
5048
5133
|
add.addEventListener('click', () => { void openNew(); });
|
|
5049
|
-
|
|
5134
|
+
const addRoom = el('button', 'conv-card conv-card-new conv-card-new-room'); addRoom.type = 'button';
|
|
5135
|
+
addRoom.append(el('span', 'conv-card-plus', '+'), el('small', '', 'New room'));
|
|
5136
|
+
addRoom.addEventListener('click', () => { void openSalonNew(); });
|
|
5137
|
+
const paint = () => $('deck-cards').replaceChildren(...rooms.map((r) => roomCard(r)), ...list.map((c) => convCard(c, (x) => { leavePlace(); select(x.name); })), add, ...(list.length ? [addRoom] : []));
|
|
5138
|
+
paint();
|
|
5050
5139
|
$('deck-cards').hidden = list.length === 0; $('deck-empty').hidden = list.length > 0;
|
|
5140
|
+
await loadRooms(); paint();
|
|
5051
5141
|
}
|
|
5052
|
-
function openDeck(push = true) { if (DEVICE) return; enterPlace('deck', push); paintDeck(); }
|
|
5142
|
+
function openDeck(push = true) { if (DEVICE) return; enterPlace('deck', push); void paintDeck(); }
|
|
5053
5143
|
$('deck-close').addEventListener('click', () => leavePlace());
|
|
5054
5144
|
$('deck-empty-new').addEventListener('click', () => { void openNew(); });
|
|
5055
5145
|
/* Import a configuration: the import of the map (Access, Flows), a file chosen at once. */
|
|
@@ -5229,6 +5319,8 @@
|
|
|
5229
5319
|
$('settings').hidden = which !== 'settings';
|
|
5230
5320
|
$('assets').hidden = which !== 'assets';
|
|
5231
5321
|
$('deck').hidden = which !== 'deck';
|
|
5322
|
+
$('salon').hidden = which !== 'salon'; $('salon-new').hidden = which !== 'salon-new';
|
|
5323
|
+
if (which !== 'salon') { try { salonLeft(); } catch { /* not yet set up */ } }
|
|
5232
5324
|
$('newconv').hidden = which !== 'new';
|
|
5233
5325
|
if (which !== 'access') composing = false;
|
|
5234
5326
|
/* What the conversation had open (its tab) waits under the place, as it was. */
|
package/web/index.html
CHANGED
|
@@ -485,6 +485,24 @@
|
|
|
485
485
|
<div id="deck-cards" class="deck"></div>
|
|
486
486
|
<div id="deck-empty" class="deck-empty" hidden><p>No conversation yet.</p><div class="deck-empty-acts"><button type="button" id="deck-empty-new" class="primary">+ Create a conversation</button><button type="button" id="deck-empty-import">Import a configuration</button></div></div>
|
|
487
487
|
</div>
|
|
488
|
+
<!-- A room (#268): one thread for several AIs, the person and voice boxes. -->
|
|
489
|
+
<div id="salon" class="sheet as-place" hidden>
|
|
490
|
+
<div class="panel-top"><b id="salon-title">Room</b><button type="button" id="salon-close" class="as-link place-back">‹ Back</button></div>
|
|
491
|
+
<button type="button" id="salon-who" class="salon-who" aria-expanded="false"></button>
|
|
492
|
+
<div id="salon-members" class="salon-members" hidden></div>
|
|
493
|
+
<div id="salon-thread" class="salon-thread"></div>
|
|
494
|
+
</div>
|
|
495
|
+
<div id="salon-new" class="sheet as-place" hidden>
|
|
496
|
+
<div class="panel-top"><b>New room</b><button type="button" id="salon-new-close" class="as-link place-back">‹ Back</button></div>
|
|
497
|
+
<div class="salon-new-body">
|
|
498
|
+
<label class="salon-field">Name<input id="salon-new-name" maxlength="60" placeholder="Home" autocomplete="off"></label>
|
|
499
|
+
<h3 class="list-head">AIs</h3><div id="salon-new-ais" class="salon-pick"></div>
|
|
500
|
+
<h3 class="list-head">Voice boxes</h3><div id="salon-new-boxes" class="salon-pick"></div>
|
|
501
|
+
<p class="hint">The first AI ticked welcomes the room: it answers, or hands the message on.</p>
|
|
502
|
+
<p id="salon-new-error" class="error" hidden></p>
|
|
503
|
+
<div class="salon-new-acts"><button type="button" id="salon-new-create" class="primary">Create</button></div>
|
|
504
|
+
</div>
|
|
505
|
+
</div>
|
|
488
506
|
<div id="assets" class="sheet as-place" hidden>
|
|
489
507
|
<div class="panel-top"><b>Assets</b><button type="button" id="assets-close" class="as-link place-back">‹ Conversations</button></div>
|
|
490
508
|
<p id="assets-error" class="error" role="alert" hidden></p>
|
package/web/style.css
CHANGED
|
@@ -2214,3 +2214,28 @@ body.as-dragging #assets-rows .as-row { touch-action: none; }
|
|
|
2214
2214
|
@keyframes m-try-shut { 0% { opacity: 1; } 35% { opacity: 0; } 70% { opacity: 1; } }
|
|
2215
2215
|
@media (prefers-reduced-motion: reduce) { .mascot.trying .m-head, .mascot.trying .m-ear, .mascot.trying .m-eye, .mascot.trying .m-shut { animation: none; } }
|
|
2216
2216
|
#notice-count { cursor: pointer; }
|
|
2217
|
+
|
|
2218
|
+
/* ROOMS (#268): a room's card is a conversation's, a little thicker (a card behind it), its members' chips on its picture. */
|
|
2219
|
+
.conv-card-room { box-shadow: 6px 6px 0 -1px var(--panel), 6px 6px 0 0 var(--line), 0 6px 18px rgba(0, 0, 0, .18); }
|
|
2220
|
+
.conv-card-room .conv-card-art { position: relative; }
|
|
2221
|
+
.conv-card-room .salon-stack { position: absolute; left: 6px; bottom: 6px; }
|
|
2222
|
+
.salon-stack { display: inline-flex; }
|
|
2223
|
+
.salon-chip { width: 20px; height: 20px; margin-left: -6px; display: grid; place-items: center; border: 2px solid var(--panel); font: 600 .6875rem/1 var(--sans); font-style: normal; color: #fff; background: hsl(var(--h, 210) 40% 38%); }
|
|
2224
|
+
.salon-chip:first-child { margin-left: 0; }
|
|
2225
|
+
.salon-chip-person { border-radius: 50%; }
|
|
2226
|
+
.salon-chip-ai { border-radius: 5px; }
|
|
2227
|
+
.salon-chip-box { border-radius: 50%; background: var(--panel); border-color: var(--line); color: var(--ink2); }
|
|
2228
|
+
.salon-chip-box::before { content: ""; width: 9px; height: 9px; background: currentColor; -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M11 5 6 9H3v6h3l5 4z'/%3E%3Cpath d='M15.5 8.5a5 5 0 0 1 0 7'/%3E%3C/svg%3E") center / contain no-repeat; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M11 5 6 9H3v6h3l5 4z'/%3E%3Cpath d='M15.5 8.5a5 5 0 0 1 0 7'/%3E%3C/svg%3E") center / contain no-repeat; }
|
|
2229
|
+
#salon { display: flex; flex-direction: column; min-height: 0; }
|
|
2230
|
+
#salon[hidden] { display: none; }
|
|
2231
|
+
.salon-who { align-self: flex-start; display: inline-flex; align-items: center; gap: 8px; border: 0; background: transparent; padding: 4px 14px; min-height: 44px; }
|
|
2232
|
+
.salon-members { display: flex; flex-direction: column; gap: 8px; padding: 0 14px 10px; border-bottom: 1px solid var(--line); }
|
|
2233
|
+
.salon-members-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; }
|
|
2234
|
+
.salon-members-row > .hint { width: 4.5rem; }
|
|
2235
|
+
.salon-member { display: inline-flex; align-items: center; gap: 6px; font-size: .8125rem; }
|
|
2236
|
+
.salon-host { font-size: .6875rem; color: var(--ink2); border: 1px solid var(--line); border-radius: 999px; padding: 0 6px; }
|
|
2237
|
+
.salon-thread { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 0 14px 12px; --parley-bg: var(--bg); --parley-text: var(--ink); --parley-dim: var(--ink2); --parley-line: var(--line); --parley-agent: var(--panel); --parley-person: var(--bar); --parley-ask: var(--brass-ink); --parley-wait: var(--wait); --parley-ok: var(--ok); --parley-action: var(--brass-ink); --parley-on-action: var(--on-brass); --parley-live: var(--danger); }
|
|
2238
|
+
.salon-new-body { display: flex; flex-direction: column; gap: 10px; padding: 0 14px 24px; max-width: 32rem; }
|
|
2239
|
+
.salon-field { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: .8125rem; }
|
|
2240
|
+
.salon-pick { display: flex; flex-direction: column; gap: 4px; }
|
|
2241
|
+
.salon-new-acts { display: flex; justify-content: flex-end; }
|