clavarium 0.2.172-beta.1 → 0.2.173-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 +10 -10
- package/package.json +3 -3
- package/server/api.mjs +19 -2
- package/server/main.mjs +2 -1
- package/server/rooms.mjs +66 -16
- package/web/app.js +118 -40
- package/web/style.css +3 -0
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.173-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.173-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.62-next.1",
|
|
15
15
|
"clavarium-docket": "0.1.2-next.2",
|
|
16
|
-
"clavarium-parley": "0.17.
|
|
16
|
+
"clavarium-parley": "0.17.85-next.1",
|
|
17
17
|
"clavarium-tether": "0.1.0-next.55",
|
|
18
18
|
"mammoth": "1.13.0",
|
|
19
19
|
"mermaid": "11.17.2",
|
|
@@ -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.62-next.1",
|
|
765
|
+
"resolved": "https://registry.npmjs.org/clavarium-binder/-/clavarium-binder-0.1.62-next.1.tgz",
|
|
766
|
+
"integrity": "sha512-YhBt+k29zbASU931T5kPAnsZwo5JVgGw94HRs4UoKL2WHK4WVvmn54RCzTBSnHCWuvo4Lc27eLcxl0rNb+6Yug==",
|
|
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.85-next.1",
|
|
791
|
+
"resolved": "https://registry.npmjs.org/clavarium-parley/-/clavarium-parley-0.17.85-next.1.tgz",
|
|
792
|
+
"integrity": "sha512-eLXKOktwO2SUEh6b0OjxDOv4V5PlgCVhjfNTspBEFSgUiAb8pq0j5FUh+FBW7sCYClOy6ybOTOkH8gtcAk9AAA==",
|
|
793
793
|
"license": "MIT",
|
|
794
794
|
"bin": {
|
|
795
795
|
"parley": "bin/parley.mjs",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.173-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,9 +44,9 @@
|
|
|
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.62-next.1",
|
|
48
48
|
"clavarium-docket": "0.1.2-next.2",
|
|
49
|
-
"clavarium-parley": "0.17.
|
|
49
|
+
"clavarium-parley": "0.17.85-next.1",
|
|
50
50
|
"clavarium-tether": "0.1.0-next.55",
|
|
51
51
|
"mammoth": "1.13.0",
|
|
52
52
|
"mermaid": "11.17.2",
|
package/server/api.mjs
CHANGED
|
@@ -96,7 +96,9 @@
|
|
|
96
96
|
* POST /api/rooms/<id> {name?, host?, add?: {conversations, boxes}, remove?: [member ids]}
|
|
97
97
|
* POST /api/rooms/<id>/remove the room and its thread
|
|
98
98
|
* GET /api/rooms/<id>/talk?last= its thread, with the room: {room, messages, ...}
|
|
99
|
-
* POST /api/rooms/<id>/talk {text, to?: [AI member ids]}: said in it; to its host, or to the AIs named
|
|
99
|
+
* POST /api/rooms/<id>/talk {text, to?: [AI member ids], files?}: said in it; to its host, or to the AIs named
|
|
100
|
+
* POST /api/rooms/<id>/talk/file?name= the body IS a file the person attaches there -> {path, name, size}
|
|
101
|
+
* GET /api/rooms/<id>/file?p=<id>/<name> a file attached in it
|
|
100
102
|
* GET /api/conversations/<name>/health-react POST the same {on?, message?, command?}: what it does when its machine is short
|
|
101
103
|
* GET /api/machines/places GET /api/machines/moving POST /api/machines/move {to}: all the machines to another disk
|
|
102
104
|
* POST /api/machines/forget-old: the copy a move left behind, removed
|
|
@@ -299,6 +301,15 @@ export async function handleApi(request, response, conversations, headers, resou
|
|
|
299
301
|
/* Rooms (#268, rooms.mjs): a thread shared by several AIs, the person and boxes. */
|
|
300
302
|
if (pathname === '/api/rooms' && rooms) return send(200, rooms.list()), true;
|
|
301
303
|
const roomTalk = /^\/api\/rooms\/([0-9a-f-]{36})\/talk$/.exec(pathname);
|
|
304
|
+
/* A file attached in a room, opened from its thread. */
|
|
305
|
+
const roomFile = /^\/api\/rooms\/([0-9a-f-]{36})\/file$/.exec(pathname);
|
|
306
|
+
if (roomFile && rooms) {
|
|
307
|
+
const file = await download(rooms.filesOf(roomFile[1]), query.get('p') ?? '');
|
|
308
|
+
response.writeHead(200, { ...headers, 'content-type': 'application/octet-stream', 'content-length': file.size,
|
|
309
|
+
'content-disposition': `attachment; filename*=UTF-8''${encodeURIComponent(file.name)}` });
|
|
310
|
+
file.stream.pipe(response);
|
|
311
|
+
return true;
|
|
312
|
+
}
|
|
302
313
|
if (roomTalk && rooms) { const last = Number(query.get('last')); return send(200, rooms.read(roomTalk[1], Number.isInteger(last) && last > 0 ? { last } : undefined)), true; }
|
|
303
314
|
if (pathname === '/api/mailboxes' && mailboxes) return send(200, mailboxes.list()), true;
|
|
304
315
|
/* Which providers and kinds an account can be connected for here. */
|
|
@@ -433,6 +444,12 @@ export async function handleApi(request, response, conversations, headers, resou
|
|
|
433
444
|
if (!originOk(request.headers) || request.headers['content-type'] !== 'application/octet-stream') return send(403, { error: 'This request does not come from this site.' }), true;
|
|
434
445
|
return send(201, await talk.attach(decodeURIComponent(attaching[1]), query.get('name') ?? '', request)), true;
|
|
435
446
|
}
|
|
447
|
+
/* A file the person attaches in a room (06-11): the same as in a chat, kept in the room. */
|
|
448
|
+
const roomAttaching = /^\/api\/rooms\/([0-9a-f-]{36})\/talk\/file$/.exec(pathname);
|
|
449
|
+
if (roomAttaching && rooms) {
|
|
450
|
+
if (!originOk(request.headers) || request.headers['content-type'] !== 'application/octet-stream') return send(403, { error: 'This request does not come from this site.' }), true;
|
|
451
|
+
return send(201, await rooms.attach(roomAttaching[1], query.get('name') ?? '', request)), true;
|
|
452
|
+
}
|
|
436
453
|
/* A flow with its files, sent from the page: the body is the .tar.gz. */
|
|
437
454
|
if (pathname === '/api/setup/bundle' && setup && bundles) {
|
|
438
455
|
if (!originOk(request.headers) || request.headers['content-type'] !== 'application/octet-stream') return send(403, { error: 'This request does not come from this site.' }), true;
|
|
@@ -450,7 +467,7 @@ export async function handleApi(request, response, conversations, headers, resou
|
|
|
450
467
|
const r = /^\/api\/rooms\/([0-9a-f-]{36})(\/remove|\/talk)?$/.exec(pathname);
|
|
451
468
|
if (r && !r[2]) return send(200, rooms.change(r[1], body ?? {})), true;
|
|
452
469
|
if (r && r[2] === '/remove') { rooms.remove(r[1]); return send(200, { removed: r[1] }), true; }
|
|
453
|
-
if (r && r[2] === '/talk') return send(201, await rooms.say(r[1], body?.text, { to: body?.to })), true;
|
|
470
|
+
if (r && r[2] === '/talk') return send(201, await rooms.say(r[1], body?.text, { to: body?.to, files: body?.files })), true;
|
|
454
471
|
}
|
|
455
472
|
if (pathname === '/api/conversations') {
|
|
456
473
|
await conversations.admit?.(body);
|
package/server/main.mjs
CHANGED
|
@@ -679,7 +679,8 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
|
|
|
679
679
|
log: (line) => events.add({ kind: 'server', text: line }) });
|
|
680
680
|
/* Rooms (#268): a thread shared by several AIs, the person and boxes (rooms.mjs). */
|
|
681
681
|
rooms = new Rooms({ file: new JsonFile(`${dataDir}/rooms.json`, []), dir: `${dataDir}/rooms`,
|
|
682
|
-
say: (name, text, extra) => talk.say(name, text, undefined,
|
|
682
|
+
say: (name, text, extra, files) => talk.say(name, text, undefined, files, undefined, extra),
|
|
683
|
+
attach: (name, fileName, request) => talk.attach(name, fileName, request),
|
|
683
684
|
rooms: (name, list) => talk.rooms(name, list), conversations: () => all.list(), boxes: () => boxes.all(),
|
|
684
685
|
speak: (where, text, ids, how) => { void boxes.agentSaid(where, text, ids, how); } });
|
|
685
686
|
rooms.boxesBound(boxes.all());
|
package/server/rooms.mjs
CHANGED
|
@@ -14,9 +14,11 @@
|
|
|
14
14
|
*
|
|
15
15
|
* Each conversation of a room is told which rooms it is in, and who is there (Parley's rooms.json).
|
|
16
16
|
*/
|
|
17
|
-
import { mkdirSync, rmSync } from 'node:fs';
|
|
17
|
+
import { createReadStream, lstatSync, mkdirSync, rmSync } from 'node:fs';
|
|
18
18
|
import { randomUUID } from 'node:crypto';
|
|
19
|
-
import {
|
|
19
|
+
import { join } from 'node:path';
|
|
20
|
+
import { Parley, FILES_MAX } from 'clavarium-parley/host';
|
|
21
|
+
import { importFile } from './files.mjs';
|
|
20
22
|
import { Refusal } from './conversations.mjs';
|
|
21
23
|
import { scan } from './secret-scan.mjs';
|
|
22
24
|
|
|
@@ -28,6 +30,11 @@ export const HOPS_MAX = 8;
|
|
|
28
30
|
/* How long an AI given a message is said to be thinking, at most (it may never answer). */
|
|
29
31
|
export const THINKING_MS = 10 * 60_000;
|
|
30
32
|
const KINDS = ['person', 'ai', 'box'];
|
|
33
|
+
/* A FILE THE PERSON ATTACHES IN A ROOM (06-11: a room carries what the chat carries): kept in the room's own folder
|
|
34
|
+
(rooms/<id>/attached/<uuid>/<name>), named in its thread by ROOM_FILE's path; a copy goes to each AI the message
|
|
35
|
+
goes to, attached in its own chat as the person attaches one there (talk.attach) -- never to the others. */
|
|
36
|
+
export const ATTACHED_DIR = 'attached';
|
|
37
|
+
const ROOM_FILE = /^\/room\/attached\/([0-9a-f-]{36})\/([^/]+)$/;
|
|
31
38
|
const nameOf = (v) => String(v ?? '').replace(/\s+/g, ' ').trim().slice(0, ROOM_NAME_MAX);
|
|
32
39
|
|
|
33
40
|
/* A SECRET IN A ROOM (06-11): a room's thread is read by all its members, now and later -- a token, a key pasted
|
|
@@ -40,17 +47,18 @@ export const masked = (text) => { const str = String(text ?? ''); const hits = s
|
|
|
40
47
|
export const lookOf = (name) => { const text = String(name ?? ''); let h = 0; for (const ch of text) h = (h * 31 + ch.codePointAt(0)) >>> 0; return { initial: ([...text.trim()][0] ?? '?').toUpperCase(), hue: h % 360 }; };
|
|
41
48
|
|
|
42
49
|
export class Rooms {
|
|
43
|
-
#file; #dir; #say; #rooms; #conversations; #boxes; #now; #speak; #hops = new Map(); #thinking = new Map();
|
|
50
|
+
#file; #dir; #say; #attach; #rooms; #conversations; #boxes; #now; #speak; #hops = new Map(); #thinking = new Map();
|
|
44
51
|
/* file: a JsonFile of the rooms; dir: where their threads are; say(name, text, extra): a message written in a
|
|
45
|
-
conversation's own chat (talk.say
|
|
52
|
+
conversation's own chat (talk.say; its 4th argument the paths of its files there); attach(name, fileName,
|
|
53
|
+
request): a file put in a conversation's chat as the person attaches one (talk.attach); rooms(name, list): what a conversation is told of its rooms (talk.rooms);
|
|
46
54
|
conversations(): the conversations there are; boxes(): the voice boxes there are. */
|
|
47
|
-
constructor({ file, dir, say, rooms = () => {}, conversations = () => [], boxes = () => [], speak = () => {}, now = () => new Date() }) {
|
|
48
|
-
this.#speak = speak;
|
|
55
|
+
constructor({ file, dir, say, attach = async () => { throw new Refusal(409, 'Files cannot be given here.'); }, rooms = () => {}, conversations = () => [], boxes = () => [], speak = () => {}, now = () => new Date() }) {
|
|
56
|
+
this.#speak = speak; this.#attach = attach;
|
|
49
57
|
this.#file = file; this.#dir = dir; this.#say = say; this.#rooms = rooms; this.#conversations = conversations; this.#boxes = boxes; this.#now = now;
|
|
50
58
|
}
|
|
51
59
|
#all() { const v = this.#file.get(); return Array.isArray(v) ? v : []; }
|
|
52
60
|
#save(list) { this.#file.set(list); this.#tellConversations(list); }
|
|
53
|
-
#thread(id) { mkdirSync(`${this.#dir}/${id}`, { recursive: true }); return new Parley(`${this.#dir}/${id}`, { room: true, now: this.#now }); }
|
|
61
|
+
#thread(id) { mkdirSync(`${this.#dir}/${id}`, { recursive: true }); return new Parley(`${this.#dir}/${id}`, { room: true, now: this.#now, reach: (path) => { const m = ROOM_FILE.exec(String(path ?? '')); return m ? `room:${m[1]}/${m[2]}` : null; } }); }
|
|
54
62
|
#find(id) { const r = this.#all().find((x) => x.id === id); if (!r) throw new Refusal(404, 'No such room.'); return r; }
|
|
55
63
|
|
|
56
64
|
/* Its members as they are now: names of the moment (a conversation renamed, a box renamed). */
|
|
@@ -64,7 +72,8 @@ export class Rooms {
|
|
|
64
72
|
.map((m) => { const name = m.kind === 'box' ? (boxes.get(m.ref)?.name ?? m.name) : m.kind === 'ai' ? convs.get(m.ref) : m.name;
|
|
65
73
|
return { id: m.id, kind: m.kind, name, ref: m.ref, look: lookOf(m.kind === 'ai' ? titles.get(m.ref) : name), ...(m.id === room.host ? { host: true } : {}) }; });
|
|
66
74
|
}
|
|
67
|
-
|
|
75
|
+
/* Who works for the room now, and what it says it does (06-11: « je fais… » on the status line, never in the thread). */
|
|
76
|
+
#think(room, member, on, text = '') { const m = this.#thinking.get(room) ?? new Map(); if (on) m.set(member, { at: Date.now(), text: String(text ?? '').slice(0, 160) }); else m.delete(member); this.#thinking.set(room, m); }
|
|
68
77
|
has(id) { return this.#all().some((r) => r.id === id); }
|
|
69
78
|
/* What came since the owner last looked (#282): the AIs' and the boxes' messages after it. */
|
|
70
79
|
#unread(r) { try { const seen = Date.parse(r.seen ?? '') || 0; return this.#thread(r.id).read({ last: 200 }).messages.filter((m) => (m.from === 'agent' || m.by) && (Date.parse(m.at) || 0) > seen).length; } catch { return 0; } }
|
|
@@ -72,7 +81,8 @@ export class Rooms {
|
|
|
72
81
|
#last(r) { try { const m = this.#thread(r.id).read({ last: 1 }).messages.at(-1); return m ? { at: m.at, text: String(m.text ?? '').replace(/\s+/g, ' ').slice(0, 120), ...(m.by?.name ? { by: m.by.name } : {}) } : null; } catch { return null; } }
|
|
73
82
|
/* Who has a message of the room and has not answered yet (#282), by their names of the moment: « Hugo parle… »
|
|
74
83
|
in its row of the list and on its bar, « Hugo réfléchit… » in its thread. */
|
|
75
|
-
#thinkingOf(id, members) { return [...(this.#thinking.get(id) ?? new Map()).entries()].filter(([,
|
|
84
|
+
#thinkingOf(id, members) { return [...(this.#thinking.get(id) ?? new Map()).entries()].filter(([, v]) => Date.now() - v.at < THINKING_MS).map(([mid]) => members.find((m) => m.id === mid)?.name).filter(Boolean); }
|
|
85
|
+
#doingOf(id, members) { return [...(this.#thinking.get(id) ?? new Map()).entries()].filter(([, v]) => v.text && Date.now() - v.at < THINKING_MS).map(([mid, v]) => ({ name: members.find((m) => m.id === mid)?.name, text: v.text })).filter((x) => x.name); }
|
|
76
86
|
list() { return this.#all().map((r) => { const members = this.#shown(r); return { id: r.id, name: r.name, host: r.host, members, at: r.at, unread: this.#unread(r), last: this.#last(r), thinking: this.#thinkingOf(r.id, members) }; }); }
|
|
77
87
|
get(id) { const r = this.#find(id); return { id: r.id, name: r.name, host: r.host, members: this.#shown(r), at: r.at }; }
|
|
78
88
|
|
|
@@ -137,27 +147,59 @@ export class Rooms {
|
|
|
137
147
|
/* A member named in a text (@{id}): its name of the moment, on the screen. */
|
|
138
148
|
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; });
|
|
139
149
|
if (options?.seen !== false) { const list = this.#all(); const r = list.find((x) => x.id === id); if (r) { r.seen = this.#now().toISOString(); this.#file.set(list); } }
|
|
140
|
-
const thinking = this.#thinkingOf(id, members);
|
|
141
|
-
return { room: this.get(id), thinking, ...read, messages: (read.messages ?? []).map((m) => (typeof m.text === 'string' && m.text.includes('@{') ? { ...m, text: named(m.text) } : m)) };
|
|
150
|
+
const thinking = this.#thinkingOf(id, members); const doing = this.#doingOf(id, members);
|
|
151
|
+
return { room: this.get(id), thinking, doing, ...read, messages: (read.messages ?? []).map((m) => (typeof m.text === 'string' && m.text.includes('@{') ? { ...m, text: named(m.text) } : m)) };
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/* A FILE THE PERSON ATTACHES, before the message that carries it: the same checks as in a conversation's chat
|
|
155
|
+
(its name, its size: importFile). Resolves with its path in the room, what the message then carries. */
|
|
156
|
+
async attach(id, fileName, request) {
|
|
157
|
+
const room = this.#find(id);
|
|
158
|
+
const root = join(this.#dir, room.id, ATTACHED_DIR); const one = randomUUID();
|
|
159
|
+
mkdirSync(join(root, one), { recursive: true });
|
|
160
|
+
try {
|
|
161
|
+
const kept = await importFile(root, one, String(fileName ?? ''), request);
|
|
162
|
+
return { path: `/room/${ATTACHED_DIR}/${one}/${kept.name}`, name: kept.name, size: kept.size };
|
|
163
|
+
} catch (error) { rmSync(join(root, one), { recursive: true, force: true }); throw error; }
|
|
164
|
+
}
|
|
165
|
+
/* Where its files are, for one to be read (files.mjs download walks in it). */
|
|
166
|
+
filesOf(id) { const room = this.#find(id); const root = join(this.#dir, room.id, ATTACHED_DIR); mkdirSync(root, { recursive: true }); return root; }
|
|
167
|
+
/* The files a message carries: only those attached in this room first, each there. */
|
|
168
|
+
#filesSaid(roomId, files) {
|
|
169
|
+
const given = files === undefined || files === null ? [] : files;
|
|
170
|
+
if (!Array.isArray(given) || given.length > FILES_MAX) throw new Refusal(400, `A message has ${FILES_MAX} files at most.`);
|
|
171
|
+
return given.map((item) => {
|
|
172
|
+
const path = item && typeof item === 'object' ? item.path : item;
|
|
173
|
+
const m = typeof path === 'string' ? ROOM_FILE.exec(path) : null;
|
|
174
|
+
const file = m ? join(this.#dir, roomId, ATTACHED_DIR, m[1], m[2]) : undefined;
|
|
175
|
+
const info = file ? lstatSync(file, { throwIfNoEntry: false }) : undefined;
|
|
176
|
+
if (!info?.isFile()) throw new Refusal(400, 'A file of this message was not attached here first.');
|
|
177
|
+
return { path, name: m[2], size: info.size, file };
|
|
178
|
+
});
|
|
142
179
|
}
|
|
143
180
|
|
|
144
181
|
/* SOMEONE OF THE PERSON'S SIDE SPEAKS (the person here, a box): kept in the room, given to the host -- or to the
|
|
145
|
-
AIs named (to: their member ids). */
|
|
146
|
-
async say(id, text, { by, box, to } = {}) {
|
|
182
|
+
AIs named (to: their member ids). Its files (paths from attach): in the thread, and a copy to each of those AIs. */
|
|
183
|
+
async say(id, text, { by, box, to, files } = {}) {
|
|
147
184
|
const room = this.#find(id); const members = this.#shown(room);
|
|
148
185
|
/* A box bound to this room speaks in it in its own name (#281): found by its box id. */
|
|
149
186
|
const who = box ? members.find((m) => m.kind === 'box' && m.ref === box) : by ? members.find((m) => m.id === by && m.kind !== 'ai') : members.find((m) => m.kind === 'person');
|
|
150
187
|
if (!who) throw new Refusal(400, 'Not a member of this room.');
|
|
188
|
+
const attached = this.#filesSaid(room.id, files);
|
|
151
189
|
const t = this.#thread(room.id);
|
|
152
190
|
this.#hops.set(room.id, 0);
|
|
153
191
|
/* The owner is the room's own side (no name over their words, as in any chat); anyone else is named. */
|
|
154
|
-
|
|
192
|
+
let now;
|
|
193
|
+
try { now = t.say(masked(text), undefined, attached.map(({ path, name, size }) => ({ path, name, size })), who.ref === 'owner' ? {} : { by: { id: who.id, name: who.name, kind: who.kind, look: who.look } }); } catch (error) { if (error instanceof RangeError) throw new Refusal(400, error.message); throw error; }
|
|
155
194
|
const said = now.messages.at(-1);
|
|
156
195
|
const named = (Array.isArray(to) ? to : []).map((x) => members.find((m) => m.id === x && m.kind === 'ai')).filter(Boolean);
|
|
157
196
|
const host = members.find((m) => m.id === room.host);
|
|
158
197
|
for (const ai of named.length ? named : host ? [host] : []) {
|
|
159
198
|
this.#think(room.id, ai.id, true);
|
|
160
|
-
|
|
199
|
+
/* Its own copy of each file, in its chat's files: as if attached there (a fresh read of the room's file). */
|
|
200
|
+
const copies = [];
|
|
201
|
+
for (const f of attached) { const stream = createReadStream(f.file); stream.headers = { 'content-length': String(f.size) }; copies.push((await this.#attach(ai.ref, f.name, stream)).path); }
|
|
202
|
+
await this.#say(ai.ref, text, { by: { id: who.id, name: who.name, kind: who.kind, look: who.look }, room: { id: room.id, name: room.name, message: said.id } }, ...(copies.length ? [copies] : []));
|
|
161
203
|
}
|
|
162
204
|
/* Handed to its AIs: read, as a conversation's agent would say it (06-11: the clock stayed on every message). */
|
|
163
205
|
try { t.seen?.(); } catch { /* an older Parley */ }
|
|
@@ -176,7 +218,15 @@ export class Rooms {
|
|
|
176
218
|
const all = () => t.read({ all: true }).messages;
|
|
177
219
|
const find = (id) => (typeof id === 'string' && id.length >= 8 ? all().find((m) => m.id.startsWith(id)) : undefined);
|
|
178
220
|
const re = find(entry.re)?.id;
|
|
179
|
-
|
|
221
|
+
/* What it does: on the room's status line only, never a line of its thread (06-11, the owner's choice). */
|
|
222
|
+
if (kind === 'doing') {
|
|
223
|
+
this.#think(room.id, me.id, true, masked(entry.text));
|
|
224
|
+
/* A box it is said to still says it aloud (first, at once, what it is about to do). */
|
|
225
|
+
const boxes = (Array.isArray(entry.to) ? entry.to : []).map((x) => members.find((m) => m.id === x && m.kind === 'box')).filter(Boolean).map((m) => m.ref);
|
|
226
|
+
if (boxes.length) try { this.#speak(`room:${room.id}`, masked(entry.text), boxes, { doing: true, asked: false }); } catch { /* the boxes' */ }
|
|
227
|
+
return 'doing';
|
|
228
|
+
}
|
|
229
|
+
this.#think(room.id, me.id, false);
|
|
180
230
|
const ids = new Set(members.map((m) => m.id));
|
|
181
231
|
const to = Array.isArray(entry.to) ? entry.to.filter((x) => ids.has(x) && x !== me.id) : [];
|
|
182
232
|
/* The other AIs it is sent to (#280): they get it in their own chat, as said in the room -- never beyond a few
|
package/web/app.js
CHANGED
|
@@ -1088,7 +1088,8 @@
|
|
|
1088
1088
|
back to the list. Another one picked while one is open takes the
|
|
1089
1089
|
place of the first (the list is still one Back away). */
|
|
1090
1090
|
function select(name, { step = false } = {}) {
|
|
1091
|
-
|
|
1091
|
+
/* Another one: the chat of the one before goes at once -- never shown under this one's name while its own loads. */
|
|
1092
|
+
if (name !== current) { disconnect(); terminal.reset(); thread?.destroy(); thread = null; threadOf = ''; }
|
|
1092
1093
|
current = name;
|
|
1093
1094
|
/* The strip over the terminal is the one of the conversation now open, at once -- never the last one's until the next look. */
|
|
1094
1095
|
paintHealth();
|
|
@@ -1105,14 +1106,22 @@
|
|
|
1105
1106
|
paint();
|
|
1106
1107
|
enter();
|
|
1107
1108
|
void chatFirst();
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1109
|
+
if (step && name) foldOnOpen();
|
|
1110
|
+
}
|
|
1111
|
+
/* Opening a conversation or a room gets the list out of the way, so it has the room;
|
|
1112
|
+
the "»" button brings the list back. Only on a real pick by the owner, never on a
|
|
1113
|
+
device or when deselecting. */
|
|
1114
|
+
function foldOnOpen() {
|
|
1115
|
+
if (DEVICE || listFolded || listPinned) return;
|
|
1116
|
+
listFolded = true;
|
|
1117
|
+
try { localStorage.setItem('clavarium-list', 'folded'); } catch { /* a private window */ }
|
|
1118
|
+
applyFold(true); fit.fit?.();
|
|
1119
|
+
}
|
|
1120
|
+
/* NEW CONTENT FADES IN, barely (style.css .fade-in, none under reduced motion): never a delay before it shows. */
|
|
1121
|
+
function fadeIn(box) {
|
|
1122
|
+
if (!box) return;
|
|
1123
|
+
box.classList.remove('fade-in'); void box.offsetWidth; box.classList.add('fade-in');
|
|
1124
|
+
box.addEventListener('animationend', () => box.classList.remove('fade-in'), { once: true });
|
|
1116
1125
|
}
|
|
1117
1126
|
|
|
1118
1127
|
/* ---------- THE NAME OF THIS CLAVARIUM (server/instance.mjs) ----------
|
|
@@ -1348,7 +1357,7 @@
|
|
|
1348
1357
|
if (thinkingOf(r).length) b.dataset.live = 'true';
|
|
1349
1358
|
if (r.last) b.dataset.when = 'true';
|
|
1350
1359
|
if (r.id === roomOpenNow()) b.setAttribute('aria-current', 'true');
|
|
1351
|
-
b.addEventListener('click', () => { void openSalon(r.id); });
|
|
1360
|
+
b.addEventListener('click', () => { void openSalon(r.id, true, { step: true }); });
|
|
1352
1361
|
return b;
|
|
1353
1362
|
}
|
|
1354
1363
|
/* What was just unfolded comes in gently, once (the next paints show it as it is). */
|
|
@@ -2145,8 +2154,9 @@
|
|
|
2145
2154
|
listsShown = true; $('clists').hidden = false; paintViews();
|
|
2146
2155
|
if (listsView && listsOf === current) { if (at) await listsView.go(at); else void listsView.refresh(); listsAddress(listsView.place); return; }
|
|
2147
2156
|
const name = current; listsOf = name;
|
|
2148
|
-
|
|
2149
|
-
|
|
2157
|
+
/* The binders of the one before go at once: never shown under this one's name while its own load. */
|
|
2158
|
+
listsView?.destroy(); listsView = null; $('clists-binder').replaceChildren();
|
|
2159
|
+
const view = await mountBinder($('clists-binder'), (l) => Boolean(l.grants?.[`conversation:${name}`]), { of: () => name, place: at, steps: listsSteps, still: () => listsOf === name && current === name });
|
|
2150
2160
|
if (listsOf === name) listsView = view;
|
|
2151
2161
|
}
|
|
2152
2162
|
function closeRoomLists() {
|
|
@@ -2947,10 +2957,13 @@
|
|
|
2947
2957
|
/* Whether it is on, nothing of the thread: asked every few seconds. */
|
|
2948
2958
|
/* No answer (the network cut for a moment, the server restarting): what was known is kept. Taken
|
|
2949
2959
|
for "off", the chat would be taken down and drawn again -- its box with it, and a tablet's keyboard. */
|
|
2950
|
-
const
|
|
2960
|
+
const name = current;
|
|
2961
|
+
const known = talkOf === name ? talk : null;
|
|
2951
2962
|
const off = { on: false, messages: [] };
|
|
2952
|
-
|
|
2953
|
-
|
|
2963
|
+
const got = await fetch(talkPath(name, '', { state: 1 })).then((r) => (r.ok ? r.json() : r.status >= 500 ? known ?? off : off)).catch(() => known ?? off);
|
|
2964
|
+
/* Asked for the one before, answered once another was open: not taken for this one's. */
|
|
2965
|
+
if (name !== current) return talk;
|
|
2966
|
+
talk = got; talkOf = name;
|
|
2954
2967
|
return talk;
|
|
2955
2968
|
}
|
|
2956
2969
|
async function paintThread() {
|
|
@@ -2978,10 +2991,10 @@
|
|
|
2978
2991
|
paintSimple();
|
|
2979
2992
|
if (!wanted) { thread?.destroy(); thread = null; threadOf = ''; return; }
|
|
2980
2993
|
if (thread && threadOf === current) { void thread.refresh(); return; }
|
|
2981
|
-
thread?.destroy();
|
|
2994
|
+
thread?.destroy(); thread = null; threadOf = '';
|
|
2995
|
+
const name = current;
|
|
2982
2996
|
/* From where this page is: a device's page lives under /c/, and nothing else is open to it. */
|
|
2983
2997
|
const [{ mount }, words] = await Promise.all([import(new URL('vendor/parley-ui.js', new URL(DEVICE ? '/c/' : '/', location.href)).href), readWords()]);
|
|
2984
|
-
const name = current;
|
|
2985
2998
|
if (name !== current || (thread && threadOf === current)) return;
|
|
2986
2999
|
threadOf = name;
|
|
2987
3000
|
/* The short-lived secrets live in this conversation now (secret-scan.mjs): the chat shows each as
|
|
@@ -2997,12 +3010,13 @@
|
|
|
2997
3010
|
for (const m of data.messages) if (m.from === 'system') lines.set(m.id, m);
|
|
2998
3011
|
return data.since === true ? { ...data, messages: [...data.messages.filter((m) => m.from !== 'system'), ...lines.values()] } : data;
|
|
2999
3012
|
};
|
|
3013
|
+
let first = true;
|
|
3000
3014
|
thread = mount(box, {
|
|
3001
3015
|
words, view: chatView,
|
|
3002
3016
|
onView: (v) => { chatView = v; try { localStorage.setItem('clavarium-chat-view', v); } catch { /* as above */ } },
|
|
3003
3017
|
/* A part of the thread: its end at first, then what changed, the page before on demand (Parley's window). */
|
|
3004
3018
|
window: windowFor(chatWindow),
|
|
3005
|
-
load: (asked = {}) => fetch(talkPath(name, '', asked)).then((r) => r.json()).then((data) => withLines(data, asked)).then(machineLines).then((data) => withMachine(data, name)).then((data) =>
|
|
3019
|
+
load: (asked = {}) => fetch(talkPath(name, '', asked)).then((r) => r.json()).then((data) => withLines(data, asked)).then(machineLines).then((data) => withMachine(data, name)).then((data) => { refreshSecrets(); if (first) { first = false; fadeIn(box); } return data; }),
|
|
3006
3020
|
/* The whole thread searched, however little of it is shown. */
|
|
3007
3021
|
search: (q) => fetch(talkPath(name, '/search', { q })).then((r) => (r.ok ? r.json() : { matches: [], count: 0 })),
|
|
3008
3022
|
/* `via: 'voice'`: part of it was dictated, said to the tool. */
|
|
@@ -4914,11 +4928,14 @@
|
|
|
4914
4928
|
}
|
|
4915
4929
|
/* A Tether target given from Attach: Read watches, Write proposes (asks before each action). */
|
|
4916
4930
|
const targetLevel = (level) => (level === 'write' ? 'propose' : 'watch');
|
|
4931
|
+
let assetsPainting = 0;
|
|
4917
4932
|
async function paintAssets() {
|
|
4918
4933
|
if (place !== 'assets' || DEVICE) return;
|
|
4919
4934
|
watchTether();
|
|
4935
|
+
const mine = ++assetsPainting;
|
|
4920
4936
|
const [all, boxes, secrets, keys, lists, tether, assetGroups] = await Promise.all([getJson('/resources', []), getJson('/mailboxes', []), getJson('/secrets', []), getJson('/git-keys', []), binderCall('lists', {}), getJson('/tether', {}), getJson('/asset-groups', []), readDevices()]);
|
|
4921
|
-
|
|
4937
|
+
/* A later paint asked meanwhile: it draws, with what it read (never this older reading over it). */
|
|
4938
|
+
if (place !== 'assets' || mine !== assetsPainting) return;
|
|
4922
4939
|
paintKeys(keys);
|
|
4923
4940
|
markSecrets(secrets);
|
|
4924
4941
|
const items = [];
|
|
@@ -4954,7 +4971,7 @@
|
|
|
4954
4971
|
const allApprovals = Array.isArray(tether.approvals) ? tether.approvals : [];
|
|
4955
4972
|
const onDemandes = !assetsAdding && !chosen && !chosenGroup && assetOpen === 'demandes:all';
|
|
4956
4973
|
$('assets-as').dataset.open = chosen || chosenGroup || assetsAdding || onDemandes ? 'detail' : 'list';
|
|
4957
|
-
const choose = (key) => { placeAssetStep(); if (key !== assetOpen) groupGiveShow.clear(); assetOpen = key; assetsAdding = ''; remoteEditing = false; remember(); void paintAssets(); };
|
|
4974
|
+
const choose = (key) => { placeAssetStep(); if (key !== assetOpen) { groupGiveShow.clear(); clearAssetDetail(); } assetOpen = key; assetsAdding = ''; remoteEditing = false; remember(); void paintAssets(); };
|
|
4958
4975
|
/* THE ONE LIST (kit AssetList), scope all: groups by default once one exists; who has each on its right. */
|
|
4959
4976
|
const model = KIT.assetListModel({ items: items.map(cardOf), groups: assetGroups, scope: 'all', by: assetsBy, query: assetsQuery, folded: [...groupsFolded], kinds: ASSET_KINDS });
|
|
4960
4977
|
paintAssetsView(model.view);
|
|
@@ -4967,10 +4984,7 @@
|
|
|
4967
4984
|
onFold: (id) => { if (groupsFolded.has(id)) groupsFolded.delete(id); else groupsFolded.add(id); keepGroupsFolded(); void paintAssets(); },
|
|
4968
4985
|
onGroup: (id) => choose(`group:${id}`), noMatch: 'Nothing by that name.' });
|
|
4969
4986
|
if (model.view === 'group') dragToGroups($('assets-rows'));
|
|
4970
|
-
const detail =
|
|
4971
|
-
/* The forms go back to where they wait before the detail is drawn again. */
|
|
4972
|
-
for (const form of detail.querySelectorAll('.as-form, #gitview-remote-box')) $('assets-forms').append(form);
|
|
4973
|
-
detail.replaceChildren();
|
|
4987
|
+
const detail = clearAssetDetail();
|
|
4974
4988
|
const back = () => { assetOpen = ''; assetsAdding = ''; remember(); void paintAssets(); };
|
|
4975
4989
|
if (assetsAdding) {
|
|
4976
4990
|
/* The New asset box: from the map's "+" of Assets, which kind first ("<" goes back to the map);
|
|
@@ -5233,6 +5247,13 @@
|
|
|
5233
5247
|
void paintAssets();
|
|
5234
5248
|
}
|
|
5235
5249
|
/* One asset of the place opened (or a form to make one): a step; another one takes its place. */
|
|
5250
|
+
/* The detail emptied (its forms back where they wait): another asset picked shows nothing of the one before while it is read. */
|
|
5251
|
+
function clearAssetDetail() {
|
|
5252
|
+
const detail = $('assets-detail');
|
|
5253
|
+
for (const form of detail.querySelectorAll('.as-form, #gitview-remote-box')) $('assets-forms').append(form);
|
|
5254
|
+
detail.replaceChildren();
|
|
5255
|
+
return detail;
|
|
5256
|
+
}
|
|
5236
5257
|
function placeAssetStep() {
|
|
5237
5258
|
const a = nav.last(['asset']);
|
|
5238
5259
|
if (a >= 0 && a > nav.last(['place'])) { nav.cut(a + 1); return; }
|
|
@@ -5294,40 +5315,84 @@
|
|
|
5294
5315
|
if (dot) { dot.dataset.state = who.length ? 'work' : 'ok'; dot.title = who.length ? speaking(who) : ''; }
|
|
5295
5316
|
if (line) { line.hidden = who.length === 0; line.textContent = who.length ? speaking(who) : ''; }
|
|
5296
5317
|
}
|
|
5318
|
+
let salonAsked = 0;
|
|
5319
|
+
/* A room's bar: its name, its state, its members (folded). */
|
|
5320
|
+
function salonHead(r) {
|
|
5321
|
+
$('salon-name').textContent = r.name;
|
|
5322
|
+
salonLive(thinkingOf(r));
|
|
5323
|
+
$('salon-who').replaceChildren(memberChips(r.members), el('span', 'hint', `${countOf(r.members)} \u25BE`));
|
|
5324
|
+
$('salon-who').setAttribute('aria-expanded', 'false'); $('salon-members').hidden = true;
|
|
5325
|
+
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);
|
|
5326
|
+
$('salon-members').replaceChildren(...rows);
|
|
5327
|
+
}
|
|
5297
5328
|
function salonLeft() { clearInterval(salonTimer); salonTimer = null; salonThread?.destroy(); salonThread = null; salonId = ''; }
|
|
5298
|
-
|
|
5329
|
+
/* `step`: picked by the owner (the list, the deck): as a conversation picked, the list folds. */
|
|
5330
|
+
async function openSalon(id, push = true, { step = false } = {}) {
|
|
5299
5331
|
if (DEVICE) return;
|
|
5300
|
-
|
|
5332
|
+
const mine = ++salonAsked;
|
|
5333
|
+
/* The same room again: as the same conversation again, read again, not drawn again (its draft, where it was). */
|
|
5334
|
+
if (place === 'salon' && salonId === id && salonThread) {
|
|
5335
|
+
void salonThread.refresh();
|
|
5336
|
+
/* Shown by an address (Forward, a reload) with no step: picked, it takes one, as a conversation does -- Back and Escape go to the list. */
|
|
5337
|
+
if (step && nav.last(['place']) < 0) { placeFrom = 'list'; nav.push('place', ({ quiet }) => leftPlace(quiet), { address: placeAddress() }); }
|
|
5338
|
+
if (step) foldOnOpen();
|
|
5339
|
+
return;
|
|
5340
|
+
}
|
|
5341
|
+
/* Known (the list read the rooms): opened at once, read again behind; else read first. */
|
|
5342
|
+
if (!rooms.some((x) => x.id === id)) await loadRooms();
|
|
5343
|
+
else void loadRooms().then(() => { const fresh = rooms.find((x) => x.id === id); if (fresh && salonId === id && place === 'salon') salonHead(fresh); });
|
|
5344
|
+
/* Another room asked meanwhile: that one is shown, not this one (an answer come late). */
|
|
5345
|
+
if (mine !== salonAsked) return;
|
|
5301
5346
|
const r = rooms.find((x) => x.id === id); if (!r) return;
|
|
5347
|
+
/* Picked in the list while a conversation is open: it takes that one's place, as another conversation
|
|
5348
|
+
would -- Back (Escape) goes to the list, not to the conversation left. */
|
|
5349
|
+
if (step && place === 'conversations' && current) select('');
|
|
5302
5350
|
enterPlace('salon', push);
|
|
5303
5351
|
salonLeft(); salonId = id;
|
|
5352
|
+
/* Its address names it: a reload, Back and Forward find it again. */
|
|
5353
|
+
remember();
|
|
5304
5354
|
/* The list marks this room, and no conversation, at once. */
|
|
5305
5355
|
paint();
|
|
5306
|
-
|
|
5307
|
-
|
|
5308
|
-
$('salon-
|
|
5309
|
-
|
|
5310
|
-
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);
|
|
5311
|
-
$('salon-members').replaceChildren(...rows);
|
|
5356
|
+
salonHead(r);
|
|
5357
|
+
/* What the room before said of its AIs (« Chef is thinking… ») goes with it. */
|
|
5358
|
+
$('salon-thinking').hidden = true; $('salon-thinking').replaceChildren();
|
|
5359
|
+
if (step) foldOnOpen();
|
|
5312
5360
|
const [{ mount }, words] = await Promise.all([import(new URL('vendor/parley-ui.js', new URL('/', location.href)).href), readWords()]);
|
|
5313
|
-
if (salonId !== id) return;
|
|
5361
|
+
if (salonId !== id || mine !== salonAsked) return;
|
|
5362
|
+
let first = true;
|
|
5314
5363
|
$('salon-thread').dataset.theme = document.documentElement.dataset.theme === 'light' ? 'light' : 'dark';
|
|
5315
5364
|
salonThread = mount($('salon-thread'), {
|
|
5316
5365
|
words, markdown: true, agentName: '',
|
|
5317
5366
|
/* A mail an AI of the room cites: the same chip and viewer as in a conversation's chat. */
|
|
5318
5367
|
schemes: { mail: { icon: 'mail', open: (ref, label) => { void openMailRef(ref, { label }); } } },
|
|
5319
5368
|
load: (asked = {}) => fetch(`${API}/rooms/${id}/talk${asked.last ? `?last=${asked.last}` : ''}`).then((x) => x.json()).then((d) => {
|
|
5369
|
+
/* Read for a room no longer shown: its words go nowhere (Parley drops them with its screen). */
|
|
5370
|
+
if (salonId !== id || place !== 'salon') return d;
|
|
5371
|
+
/* Read, it is seen (the server says so): its count in the list goes at once, as a conversation's. */
|
|
5372
|
+
const seen = rooms.find((x) => x.id === id);
|
|
5373
|
+
if (seen?.unread) { seen.unread = 0; paint(); }
|
|
5374
|
+
if (first) {
|
|
5375
|
+
first = false; fadeIn($('salon-thread'));
|
|
5376
|
+
/* Its box takes what is typed, as a conversation's chat does (never on a touch screen: no keyboard raised). */
|
|
5377
|
+
requestAnimationFrame(() => { if (salonId === id && !touchScreen && !writingIn()) $('salon-thread').querySelector('textarea.parley-box')?.focus({ preventScroll: true }); });
|
|
5378
|
+
}
|
|
5320
5379
|
/* Who was given a message and has not answered yet (#282): « Hugo réfléchit… ». */
|
|
5321
5380
|
const who = thinkingOf(d);
|
|
5322
|
-
|
|
5323
|
-
|
|
5381
|
+
/* What they say they do (06-11): on this line, « Thomas : je demande à MSM… », never in the thread. */
|
|
5382
|
+
const doing = (Array.isArray(d.doing) ? d.doing : []).filter((x) => x && typeof x.name === 'string' && typeof x.text === 'string' && x.text);
|
|
5383
|
+
$('salon-thinking').hidden = who.length === 0 && doing.length === 0;
|
|
5384
|
+
if (doing.length) $('salon-thinking').replaceChildren(KIT.StatusDot({ state: 'work' }), document.createTextNode(doing.map((x) => `${x.name} : ${x.text}`).join(' \u00b7 ')));
|
|
5385
|
+
else $('salon-thinking').replaceChildren(KIT.StatusDot({ state: 'work' }), document.createTextNode(who.length > 1 ? uiSaid('room-thinking-many', '{names} are thinking\u2026', { names: who.join(', ') }) : uiSaid('room-thinking', '{name} is thinking\u2026', { name: who[0] ?? '' })));
|
|
5324
5386
|
/* Its bar says it too, as its row in the list: its dot at work, « Cuisine parle… » under its name. */
|
|
5325
5387
|
salonLive(who);
|
|
5326
5388
|
const known = rooms.find((x) => x.id === id);
|
|
5327
5389
|
if (known && JSON.stringify(thinkingOf(known)) !== JSON.stringify(who)) { known.thinking = who; paint(); }
|
|
5328
5390
|
return d;
|
|
5329
5391
|
}),
|
|
5330
|
-
send: (text) => post(`${API}/rooms/${id}/talk`, { text }),
|
|
5392
|
+
send: (text, answers, files) => post(`${API}/rooms/${id}/talk`, { text, ...(files?.length ? { files: files.map((f) => f.path) } : {}) }),
|
|
5393
|
+
/* A file attached in a room (06-11): as in a conversation's chat; kept in the room, a copy to each AI the message goes to. */
|
|
5394
|
+
attach: { upload: async (file) => { const x = await fetch(`${API}/rooms/${id}/talk/file?${new URLSearchParams({ name: file.name })}`, { method: 'POST', headers: { 'content-type': 'application/octet-stream' }, body: file }); const j = await x.json().catch(() => ({})); if (!x.ok) throw new Error(j.error || 'The file could not be sent.'); return j; } },
|
|
5395
|
+
open: (file) => { if (!String(file.open ?? '').startsWith('room:')) return; const inner = file.open.slice('room:'.length); void preview('room', inner, file.name || inner.split('/').pop(), file.size ?? 0, `${API}/rooms/${id}/file?${new URLSearchParams({ p: inner })}`, { within: r.name }); },
|
|
5331
5396
|
/* The same chat as a conversation's (03-11): its view, its formulas, its dictation, its keyboard rule. */
|
|
5332
5397
|
view: chatView, onView: (v) => { chatView = v; try { localStorage.setItem('clavarium-chat-view', v); } catch { /* as above */ } },
|
|
5333
5398
|
math: { url: new URL('vendor/katex/katex.mjs', new URL('/', location.href)).href },
|
|
@@ -5714,7 +5779,8 @@
|
|
|
5714
5779
|
$('salon').hidden = which !== 'salon'; $('salon-new').hidden = which !== 'salon-new';
|
|
5715
5780
|
/* The places of the whole have a part of the page of their own, over the conversation (03-11). */
|
|
5716
5781
|
$('places').hidden = !['access', 'settings', 'assets', 'deck', 'new', 'salon', 'salon-new'].includes(which);
|
|
5717
|
-
|
|
5782
|
+
/* A room left: its row no longer marked (as a conversation left). */
|
|
5783
|
+
if (which !== 'salon') { try { const was = salonId; salonLeft(); if (was) paint(); } catch { /* not yet set up */ } }
|
|
5718
5784
|
$('newconv').hidden = which !== 'new';
|
|
5719
5785
|
if (which !== 'access') composing = false;
|
|
5720
5786
|
/* What the conversation had open (its tab) waits under the place, as it was. */
|
|
@@ -5725,6 +5791,7 @@
|
|
|
5725
5791
|
const q = new URLSearchParams();
|
|
5726
5792
|
if (current) q.set('c', current);
|
|
5727
5793
|
if (place !== 'conversations') q.set('open', place);
|
|
5794
|
+
if (place === 'salon' && roomOpenNow()) q.set('room', roomOpenNow());
|
|
5728
5795
|
if (place === 'assets' && assetOpen) q.set('a', assetOpen);
|
|
5729
5796
|
if (place === 'assets' && assetOpen && assetOpen === listOpen && assetsView?.place.page === 'card') q.set('card', assetsView.place.card);
|
|
5730
5797
|
if (place === 'access') { q.set('tab', accessTab === 'map' && mapMode === 'flows' ? 'flows' : accessTab); if (accessFor) q.set('for', accessFor); }
|
|
@@ -5802,12 +5869,14 @@
|
|
|
5802
5869
|
/* What a page drew from the lists, to know when they changed. */
|
|
5803
5870
|
function binderSig(lists) { return JSON.stringify((Array.isArray(lists) ? lists : []).map((l) => [l.id, l.title, l.archived, l.count, l.grants])); }
|
|
5804
5871
|
/* `of`: the conversation its cards are of (its Binders tab); else the one the list was given to. */
|
|
5805
|
-
|
|
5872
|
+
/* `still()`: whether it is still wanted once its parts are read (another one asked meanwhile: not drawn). */
|
|
5873
|
+
async function mountBinder(holder, keep, { onLists, of, place: at = null, steps = null, still = () => true } = {}) {
|
|
5806
5874
|
binderParts ??= Promise.all([import(new URL('vendor/binder-ui.js', new URL('/', location.href)).href), fetch(`/vendor/binder-${binderLang()}.json`).then((r) => r.json()).catch(() => ({}))]);
|
|
5807
5875
|
const [[{ mount }, words], seen] = await Promise.all([binderParts, getJson('/binder/people', null)]);
|
|
5808
5876
|
if (seen) { binderPeople = seen.people; binderChanges = seen.changes; }
|
|
5809
|
-
if (!holder.isConnected) return null;
|
|
5877
|
+
if (!holder.isConnected || !still()) return null;
|
|
5810
5878
|
let shown = [];
|
|
5879
|
+
let first = true; let showing = null;
|
|
5811
5880
|
const whose = () => {
|
|
5812
5881
|
if (of) return of();
|
|
5813
5882
|
const given = [...new Set(shown.flatMap((l) => Object.keys(l.grants ?? {})).filter((k) => k.startsWith('conversation:')).map((k) => k.slice('conversation:'.length)))];
|
|
@@ -5816,8 +5885,16 @@
|
|
|
5816
5885
|
const view = mount(holder, {
|
|
5817
5886
|
words, lang: binderLang(), people: () => binderPeople,
|
|
5818
5887
|
call: async (op, args) => {
|
|
5819
|
-
const
|
|
5888
|
+
const asked = binderCall(op, args);
|
|
5889
|
+
if (op === 'show') showing = asked;
|
|
5890
|
+
let r = await asked;
|
|
5891
|
+
/* A binder read, answered after another was asked (one binder picked, then another): the last one
|
|
5892
|
+
asked is what Binder shows, never this late answer painted under the other's tab (clavarium-binder
|
|
5893
|
+
load() keeps no order of its own). */
|
|
5894
|
+
if (op === 'show') for (let seen = asked; seen !== showing;) { seen = showing; r = await seen; }
|
|
5820
5895
|
if (op === 'lists' && r.ok && Array.isArray(r.data)) { onLists?.(r.data); r.data = r.data.filter(keep); shown = r.data; }
|
|
5896
|
+
/* Its first binder read: drawn now, barely faded in. */
|
|
5897
|
+
if (op === 'show' && first) { first = false; fadeIn(holder); }
|
|
5821
5898
|
return r;
|
|
5822
5899
|
},
|
|
5823
5900
|
/* A thing attached opens where this page opens it. */
|
|
@@ -6065,6 +6142,7 @@
|
|
|
6065
6142
|
const open = q.get('open') ?? '';
|
|
6066
6143
|
if (open === 'new') { await openNew({ push: false }); return; }
|
|
6067
6144
|
if (open === 'deck') { openDeck(false); return; }
|
|
6145
|
+
if (open === 'salon' && q.get('room')) { await openSalon(q.get('room'), false); return; }
|
|
6068
6146
|
if (open === 'settings') {
|
|
6069
6147
|
await openSettings({ push: false });
|
|
6070
6148
|
/* A link to one chapter of Settings (?open=settings&at=resources): that one opened, and shown. */
|
package/web/style.css
CHANGED
|
@@ -61,6 +61,9 @@ button:focus-visible, input:focus-visible { outline: 2px solid var(--brass); out
|
|
|
61
61
|
@keyframes unfold { from { opacity: 0; transform: translateY(-6px); } }
|
|
62
62
|
@keyframes breathe { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .5; transform: scale(.85); } }
|
|
63
63
|
@media (prefers-reduced-motion: reduce) { .kit-conv > .state-dot, header.topbar .bar-state, .unfolding { animation: none !important; } }
|
|
64
|
+
/* Another chat, room or binder shown: its content fades in, barely (app.js fadeIn) -- never a delay before it shows. */
|
|
65
|
+
@media (prefers-reduced-motion: no-preference) { .fade-in { animation: fade-in .12s ease-out; } }
|
|
66
|
+
@keyframes fade-in { from { opacity: 0; } }
|
|
64
67
|
.choices { display: flex; flex-wrap: wrap; gap: 6px; }
|
|
65
68
|
.choices button[aria-checked="true"] { border-color: var(--brass); background: color-mix(in srgb, var(--brass) 14%, transparent); }
|
|
66
69
|
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
|