clavarium 0.2.354-next.1 → 0.2.356-next.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 +2 -2
- package/package.json +1 -1
- package/server/api.mjs +19 -2
- package/server/main.mjs +2 -1
- package/server/rooms.mjs +51 -11
- package/web/app.js +113 -38
- package/web/style.css +3 -0
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.356-next.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.356-next.1",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
package/package.json
CHANGED
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). */
|
|
@@ -143,23 +151,55 @@ export class Rooms {
|
|
|
143
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)) };
|
|
144
152
|
}
|
|
145
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
|
+
});
|
|
179
|
+
}
|
|
180
|
+
|
|
146
181
|
/* SOMEONE OF THE PERSON'S SIDE SPEAKS (the person here, a box): kept in the room, given to the host -- or to the
|
|
147
|
-
AIs named (to: their member ids). */
|
|
148
|
-
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 } = {}) {
|
|
149
184
|
const room = this.#find(id); const members = this.#shown(room);
|
|
150
185
|
/* A box bound to this room speaks in it in its own name (#281): found by its box id. */
|
|
151
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');
|
|
152
187
|
if (!who) throw new Refusal(400, 'Not a member of this room.');
|
|
188
|
+
const attached = this.#filesSaid(room.id, files);
|
|
153
189
|
const t = this.#thread(room.id);
|
|
154
190
|
this.#hops.set(room.id, 0);
|
|
155
191
|
/* The owner is the room's own side (no name over their words, as in any chat); anyone else is named. */
|
|
156
|
-
|
|
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; }
|
|
157
194
|
const said = now.messages.at(-1);
|
|
158
195
|
const named = (Array.isArray(to) ? to : []).map((x) => members.find((m) => m.id === x && m.kind === 'ai')).filter(Boolean);
|
|
159
196
|
const host = members.find((m) => m.id === room.host);
|
|
160
197
|
for (const ai of named.length ? named : host ? [host] : []) {
|
|
161
198
|
this.#think(room.id, ai.id, true);
|
|
162
|
-
|
|
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] : []));
|
|
163
203
|
}
|
|
164
204
|
/* Handed to its AIs: read, as a conversation's agent would say it (06-11: the clock stayed on every message). */
|
|
165
205
|
try { t.seen?.(); } catch { /* an older Parley */ }
|
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,29 +5315,67 @@
|
|
|
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
5381
|
/* What they say they do (06-11): on this line, « Thomas : je demande à MSM… », never in the thread. */
|
|
@@ -5330,7 +5389,10 @@
|
|
|
5330
5389
|
if (known && JSON.stringify(thinkingOf(known)) !== JSON.stringify(who)) { known.thinking = who; paint(); }
|
|
5331
5390
|
return d;
|
|
5332
5391
|
}),
|
|
5333
|
-
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 }); },
|
|
5334
5396
|
/* The same chat as a conversation's (03-11): its view, its formulas, its dictation, its keyboard rule. */
|
|
5335
5397
|
view: chatView, onView: (v) => { chatView = v; try { localStorage.setItem('clavarium-chat-view', v); } catch { /* as above */ } },
|
|
5336
5398
|
math: { url: new URL('vendor/katex/katex.mjs', new URL('/', location.href)).href },
|
|
@@ -5717,7 +5779,8 @@
|
|
|
5717
5779
|
$('salon').hidden = which !== 'salon'; $('salon-new').hidden = which !== 'salon-new';
|
|
5718
5780
|
/* The places of the whole have a part of the page of their own, over the conversation (03-11). */
|
|
5719
5781
|
$('places').hidden = !['access', 'settings', 'assets', 'deck', 'new', 'salon', 'salon-new'].includes(which);
|
|
5720
|
-
|
|
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 */ } }
|
|
5721
5784
|
$('newconv').hidden = which !== 'new';
|
|
5722
5785
|
if (which !== 'access') composing = false;
|
|
5723
5786
|
/* What the conversation had open (its tab) waits under the place, as it was. */
|
|
@@ -5728,6 +5791,7 @@
|
|
|
5728
5791
|
const q = new URLSearchParams();
|
|
5729
5792
|
if (current) q.set('c', current);
|
|
5730
5793
|
if (place !== 'conversations') q.set('open', place);
|
|
5794
|
+
if (place === 'salon' && roomOpenNow()) q.set('room', roomOpenNow());
|
|
5731
5795
|
if (place === 'assets' && assetOpen) q.set('a', assetOpen);
|
|
5732
5796
|
if (place === 'assets' && assetOpen && assetOpen === listOpen && assetsView?.place.page === 'card') q.set('card', assetsView.place.card);
|
|
5733
5797
|
if (place === 'access') { q.set('tab', accessTab === 'map' && mapMode === 'flows' ? 'flows' : accessTab); if (accessFor) q.set('for', accessFor); }
|
|
@@ -5805,12 +5869,14 @@
|
|
|
5805
5869
|
/* What a page drew from the lists, to know when they changed. */
|
|
5806
5870
|
function binderSig(lists) { return JSON.stringify((Array.isArray(lists) ? lists : []).map((l) => [l.id, l.title, l.archived, l.count, l.grants])); }
|
|
5807
5871
|
/* `of`: the conversation its cards are of (its Binders tab); else the one the list was given to. */
|
|
5808
|
-
|
|
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 } = {}) {
|
|
5809
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(() => ({}))]);
|
|
5810
5875
|
const [[{ mount }, words], seen] = await Promise.all([binderParts, getJson('/binder/people', null)]);
|
|
5811
5876
|
if (seen) { binderPeople = seen.people; binderChanges = seen.changes; }
|
|
5812
|
-
if (!holder.isConnected) return null;
|
|
5877
|
+
if (!holder.isConnected || !still()) return null;
|
|
5813
5878
|
let shown = [];
|
|
5879
|
+
let first = true; let showing = null;
|
|
5814
5880
|
const whose = () => {
|
|
5815
5881
|
if (of) return of();
|
|
5816
5882
|
const given = [...new Set(shown.flatMap((l) => Object.keys(l.grants ?? {})).filter((k) => k.startsWith('conversation:')).map((k) => k.slice('conversation:'.length)))];
|
|
@@ -5819,8 +5885,16 @@
|
|
|
5819
5885
|
const view = mount(holder, {
|
|
5820
5886
|
words, lang: binderLang(), people: () => binderPeople,
|
|
5821
5887
|
call: async (op, args) => {
|
|
5822
|
-
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; }
|
|
5823
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); }
|
|
5824
5898
|
return r;
|
|
5825
5899
|
},
|
|
5826
5900
|
/* A thing attached opens where this page opens it. */
|
|
@@ -6068,6 +6142,7 @@
|
|
|
6068
6142
|
const open = q.get('open') ?? '';
|
|
6069
6143
|
if (open === 'new') { await openNew({ push: false }); return; }
|
|
6070
6144
|
if (open === 'deck') { openDeck(false); return; }
|
|
6145
|
+
if (open === 'salon' && q.get('room')) { await openSalon(q.get('room'), false); return; }
|
|
6071
6146
|
if (open === 'settings') {
|
|
6072
6147
|
await openSettings({ push: false });
|
|
6073
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; }
|