clavarium 0.2.353-next.1 → 0.2.355-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 +6 -6
- package/package.json +2 -2
- package/server/api.mjs +19 -2
- package/server/main.mjs +2 -1
- package/server/rooms.mjs +66 -16
- package/web/app.js +9 -3
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.355-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.355-next.1",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
|
13
13
|
"@xterm/xterm": "^6.0.0",
|
|
14
14
|
"clavarium-binder": "0.1.61-next.1",
|
|
15
15
|
"clavarium-docket": "0.1.2-next.2",
|
|
16
|
-
"clavarium-parley": "0.17.
|
|
16
|
+
"clavarium-parley": "0.17.84-next.1",
|
|
17
17
|
"clavarium-tether": "0.1.0-next.55",
|
|
18
18
|
"mammoth": "1.13.0",
|
|
19
19
|
"mermaid": "11.17.2",
|
|
@@ -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.84-next.1",
|
|
791
|
+
"resolved": "https://registry.npmjs.org/clavarium-parley/-/clavarium-parley-0.17.84-next.1.tgz",
|
|
792
|
+
"integrity": "sha512-tvw4ahhxfwzbBZ1r22hhyEHts+41tt78zmEQl+DlUvR+V3GipiriOQSfLqiEWE1HbTeMZZO98lG69ipHLZ/rNg==",
|
|
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.355-next.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.",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"@xterm/xterm": "^6.0.0",
|
|
47
47
|
"clavarium-binder": "0.1.61-next.1",
|
|
48
48
|
"clavarium-docket": "0.1.2-next.2",
|
|
49
|
-
"clavarium-parley": "0.17.
|
|
49
|
+
"clavarium-parley": "0.17.84-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
|
@@ -5319,15 +5319,21 @@
|
|
|
5319
5319
|
load: (asked = {}) => fetch(`${API}/rooms/${id}/talk${asked.last ? `?last=${asked.last}` : ''}`).then((x) => x.json()).then((d) => {
|
|
5320
5320
|
/* Who was given a message and has not answered yet (#282): « Hugo réfléchit… ». */
|
|
5321
5321
|
const who = thinkingOf(d);
|
|
5322
|
-
|
|
5323
|
-
|
|
5322
|
+
/* What they say they do (06-11): on this line, « Thomas : je demande à MSM… », never in the thread. */
|
|
5323
|
+
const doing = (Array.isArray(d.doing) ? d.doing : []).filter((x) => x && typeof x.name === 'string' && typeof x.text === 'string' && x.text);
|
|
5324
|
+
$('salon-thinking').hidden = who.length === 0 && doing.length === 0;
|
|
5325
|
+
if (doing.length) $('salon-thinking').replaceChildren(KIT.StatusDot({ state: 'work' }), document.createTextNode(doing.map((x) => `${x.name} : ${x.text}`).join(' \u00b7 ')));
|
|
5326
|
+
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
5327
|
/* Its bar says it too, as its row in the list: its dot at work, « Cuisine parle… » under its name. */
|
|
5325
5328
|
salonLive(who);
|
|
5326
5329
|
const known = rooms.find((x) => x.id === id);
|
|
5327
5330
|
if (known && JSON.stringify(thinkingOf(known)) !== JSON.stringify(who)) { known.thinking = who; paint(); }
|
|
5328
5331
|
return d;
|
|
5329
5332
|
}),
|
|
5330
|
-
send: (text) => post(`${API}/rooms/${id}/talk`, { text }),
|
|
5333
|
+
send: (text, answers, files) => post(`${API}/rooms/${id}/talk`, { text, ...(files?.length ? { files: files.map((f) => f.path) } : {}) }),
|
|
5334
|
+
/* 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. */
|
|
5335
|
+
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; } },
|
|
5336
|
+
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
5337
|
/* The same chat as a conversation's (03-11): its view, its formulas, its dictation, its keyboard rule. */
|
|
5332
5338
|
view: chatView, onView: (v) => { chatView = v; try { localStorage.setItem('clavarium-chat-view', v); } catch { /* as above */ } },
|
|
5333
5339
|
math: { url: new URL('vendor/katex/katex.mjs', new URL('/', location.href)).href },
|