clavarium 0.2.173-beta.1 → 0.2.174-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.
@@ -1,19 +1,19 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.173-beta.1",
3
+ "version": "0.2.174-beta.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "clavarium",
9
- "version": "0.2.173-beta.1",
9
+ "version": "0.2.174-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
14
  "clavarium-binder": "0.1.62-next.1",
15
15
  "clavarium-docket": "0.1.2-next.2",
16
- "clavarium-parley": "0.17.85-next.1",
16
+ "clavarium-parley": "0.17.86-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.85-next.1",
791
- "resolved": "https://registry.npmjs.org/clavarium-parley/-/clavarium-parley-0.17.85-next.1.tgz",
792
- "integrity": "sha512-eLXKOktwO2SUEh6b0OjxDOv4V5PlgCVhjfNTspBEFSgUiAb8pq0j5FUh+FBW7sCYClOy6ybOTOkH8gtcAk9AAA==",
790
+ "version": "0.17.86-next.1",
791
+ "resolved": "https://registry.npmjs.org/clavarium-parley/-/clavarium-parley-0.17.86-next.1.tgz",
792
+ "integrity": "sha512-IPyRfk8mEVl3HR4uM+lbT+3z/njDnvf/VBsRH32XPL3RTxqk8/AXgqJTTGcIce8OQAiOQmJ0uH4CHGeEVypP0w==",
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.173-beta.1",
3
+ "version": "0.2.174-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.",
@@ -46,7 +46,7 @@
46
46
  "@xterm/xterm": "^6.0.0",
47
47
  "clavarium-binder": "0.1.62-next.1",
48
48
  "clavarium-docket": "0.1.2-next.2",
49
- "clavarium-parley": "0.17.85-next.1",
49
+ "clavarium-parley": "0.17.86-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
@@ -99,6 +99,8 @@
99
99
  * POST /api/rooms/<id>/talk {text, to?: [AI member ids], files?}: said in it; to its host, or to the AIs named
100
100
  * POST /api/rooms/<id>/talk/file?name= the body IS a file the person attaches there -> {path, name, size}
101
101
  * GET /api/rooms/<id>/file?p=<id>/<name> a file attached in it
102
+ * GET /api/rooms/<id>/shown?o=ai:<member>:<r>:<p>[&thumb=1] a file an AI of it showed or cited there, read from ITS conversation
103
+ * GET /api/rooms/<id>/mail/open|page?ref=mail:... a mail an AI of it cited there, opened as its conversation's chat opens it
102
104
  * GET /api/conversations/<name>/health-react POST the same {on?, message?, command?}: what it does when its machine is short
103
105
  * GET /api/machines/places GET /api/machines/moving POST /api/machines/move {to}: all the machines to another disk
104
106
  * POST /api/machines/forget-old: the copy a move left behind, removed
@@ -310,6 +312,38 @@ export async function handleApi(request, response, conversations, headers, resou
310
312
  file.stream.pipe(response);
311
313
  return true;
312
314
  }
315
+ /* WHAT AN AI SHOWED IN A ROOM (06-11): read from its own conversation, with that conversation's rights --
316
+ its work folder, a folder attached to it -- only when it showed or cited it in this room (rooms.shownFile). */
317
+ const roomShown = /^\/api\/rooms\/([0-9a-f-]{36})\/shown$/.exec(pathname);
318
+ if (roomShown && rooms) {
319
+ const { conversation, tab, inner } = rooms.shownFile(roomShown[1], query.get('o') ?? '');
320
+ const folder = (need) => {
321
+ if (need === 'write') throw new Refusal(403, 'Read only, from a room.');
322
+ if (tab === WORK_TAB) {
323
+ if (conversations.list().find((x) => x.name === conversation)?.work !== 'kept' || !resources) throw new Refusal(404, 'This conversation works on the disk of its machine: its files are not kept here.');
324
+ return resources.workFolder(conversation);
325
+ }
326
+ if (!resources?.of(conversation).some((r) => r.name === tab)) throw new Refusal(404, 'No such folder.');
327
+ return resources.folder(tab);
328
+ };
329
+ if (query.get('thumb') === '1') {
330
+ const answer = await changeRoute('GET', '/files/thumb', new URLSearchParams({ p: inner }), request, folder);
331
+ response.writeHead(200, { ...headers, ...IMAGE_HEADERS, 'content-type': answer.picture.type, 'content-length': answer.picture.bytes.length, etag: `"${answer.picture.version}"` });
332
+ response.end(answer.picture.bytes);
333
+ return true;
334
+ }
335
+ const file = await download(folder(), inner);
336
+ response.writeHead(200, { ...headers, 'content-type': 'application/octet-stream', 'content-length': file.size,
337
+ 'content-disposition': `attachment; filename*=UTF-8''${encodeURIComponent(file.name)}`, 'x-shown-by': encodeURIComponent(conversation) });
338
+ file.stream.pipe(response);
339
+ return true;
340
+ }
341
+ /* A mail an AI of a room cited there: opened as in its conversation's chat (Reply goes to that chat, x-mail-of). */
342
+ const roomMail = /^\/api\/rooms\/([0-9a-f-]{36})(\/mail\/open|\/mail\/page)$/.exec(pathname);
343
+ if (roomMail && rooms) {
344
+ const c = rooms.mailFrom(roomMail[1], query.get('ref') ?? '');
345
+ return await mailRoute(roomMail[2], query, response, { tethers, headers: { ...headers, 'x-mail-of': encodeURIComponent(c) }, who: { id: `person:${identity || 'owner'}`, name: identity || 'Owner' }, may: () => true, offline: conversations.list().find((x) => x.name === c)?.offline === true, of: c });
346
+ }
313
347
  if (roomTalk && rooms) { const last = Number(query.get('last')); return send(200, rooms.read(roomTalk[1], Number.isInteger(last) && last > 0 ? { last } : undefined)), true; }
314
348
  if (pathname === '/api/mailboxes' && mailboxes) return send(200, mailboxes.list()), true;
315
349
  /* Which providers and kinds an account can be connected for here. */
package/server/boxes.mjs CHANGED
@@ -40,6 +40,9 @@ export const WAKE_DROP = process.env.CLAVARIUM_WAKE_DROP === '1';
40
40
  the room (« Oui, à l'ombre ») not. */
41
41
  const WAKE_SOUND = /^(?:\S+ )?[ml](?:a|e|i|ai|ei)(?:s|z|ss|se|ze|sse) (?:a|e|o)n|^m[ae]s doi/;
42
42
  export const wakeHeard = (text) => { const t = plainWords(text); return WAKE_HEARD.test(t) || WAKE_SOUND.test(t.replace(/^l /, '')); };
43
+ /* Heard by its sound only (« Mise en œuvre », « Mise en jeu »), not by its spelling: the real calls read so had a
44
+ firm voice; with a faint one it is the room's talk (06-11, 23h20: « Mise en œuvre… moment », voice 396). */
45
+ export const wakeBySoundOnly = (text) => { const t = plainWords(text); return !WAKE_HEARD.test(t) && WAKE_SOUND.test(t.replace(/^l /, '')); };
43
46
  /* DROPPED IN SILENCE (05-11, the owner's go): a wake whose word is not heard again AND whose voice was faint --
44
47
  the room's talk from afar, not someone speaking to the box. Every real call of 05-11 that the word missed
45
48
  had a firm voice or none measured; the false wake of 05-11, 429. Said by one discreet line in the thread. */
@@ -937,7 +940,8 @@ export class Boxes {
937
940
  /* First in the line: Parley keeps 120 characters of `why`, and the end stats after it can pass that. */
938
941
  link.why = `mot ${check.ok ? '\u2713' : '\u2717'} « ${check.heard.slice(0, 30)} »${link.why ? ` · ${link.why}` : ''}`;
939
942
  this.#log(`voice box ${box.name}: wake word heard again: ${check.ok ? 'yes' : 'NO'} (« ${check.heard.slice(0, 40)} »)`);
940
- if (dropsWake(check.ok, link.voice, link.endReason, check.heard)) {
943
+ const soundOnlyFaint = check.ok && wakeBySoundOnly(check.heard) && Number.isFinite(link.voice) && link.voice > 0 && link.voice < WAKE_FAINT;
944
+ if (dropsWake(check.ok, link.voice, link.endReason, check.heard) || soundOnlyFaint) {
941
945
  link.send({ t: 'cue', name: 'done' });
942
946
  this.#log(`voice box ${box.name}: wake ignored (word not heard again, ${link.endReason === 'timeout' ? 'a sentence that never ended' : !check.heard.trim() ? 'no word in its clip' : `faint voice ${Math.round(link.voice || 0)}`})`);
943
947
  try { this.#note?.(box.conversation, { kind: 'box-wake-ignored', text: `Wake ignored on ${box.name}: « ${check.heard.slice(0, 40)} », ${link.endReason === 'timeout' ? 'a sound that never stopped (radio, TV)' : !check.heard.trim() ? 'no word where the wake word should be' : 'faint voice'}`, topic: 'Voice box', tone: 'info' }); } catch { /* the log has it */ }
package/server/main.mjs CHANGED
@@ -682,7 +682,9 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
682
682
  say: (name, text, extra, files) => talk.say(name, text, undefined, files, undefined, extra),
683
683
  attach: (name, fileName, request) => talk.attach(name, fileName, request),
684
684
  rooms: (name, list) => talk.rooms(name, list), conversations: () => all.list(), boxes: () => boxes.all(),
685
- speak: (where, text, ids, how) => { void boxes.agentSaid(where, text, ids, how); } });
685
+ speak: (where, text, ids, how) => { void boxes.agentSaid(where, text, ids, how); },
686
+ /* What an AI shows in a room: opened through its own conversation, with its rights (talk.mjs). */
687
+ reach: (name, path) => talk.reachOf(name, path), shown: (name, ref) => talk.shown(name, ref) });
686
688
  rooms.boxesBound(boxes.all());
687
689
  rooms.refresh();
688
690
  /* FEATURES (features.mjs): read from what the modules say, never a secret's value. The remote screen and the
package/server/rooms.mjs CHANGED
@@ -35,6 +35,12 @@ const KINDS = ['person', 'ai', 'box'];
35
35
  goes to, attached in its own chat as the person attaches one there (talk.attach) -- never to the others. */
36
36
  export const ATTACHED_DIR = 'attached';
37
37
  const ROOM_FILE = /^\/room\/attached\/([0-9a-f-]{36})\/([^/]+)$/;
38
+ /* WHAT AN AI SHOWS IN A ROOM (06-11: a room carries what the chat carries): a file of its own it cites (a path, a
39
+ picture placed in its text) or shows (a file, a gallery) is opened FROM ITS CONVERSATION, with that conversation's
40
+ rights -- never another's. In the thread, its reference reads `ai:<member id>:<how its chat opens it>` (work:report.html);
41
+ the room's /shown route opens it only when that AI cited it in this room AND its own chat has it (talk.shown). */
42
+ const CITE = 'cite:';
43
+ const AI_OPEN = /^ai:([0-9a-f-]{36}):([a-z][a-z0-9-]{0,31}):(.+)$/;
38
44
  const nameOf = (v) => String(v ?? '').replace(/\s+/g, ' ').trim().slice(0, ROOM_NAME_MAX);
39
45
 
40
46
  /* 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
@@ -47,18 +53,20 @@ export const masked = (text) => { const str = String(text ?? ''); const hits = s
47
53
  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 }; };
48
54
 
49
55
  export class Rooms {
50
- #file; #dir; #say; #attach; #rooms; #conversations; #boxes; #now; #speak; #hops = new Map(); #thinking = new Map();
56
+ #file; #dir; #say; #attach; #rooms; #conversations; #boxes; #now; #speak; #reachOf; #shownIn; #hops = new Map(); #thinking = new Map();
51
57
  /* file: a JsonFile of the rooms; dir: where their threads are; say(name, text, extra): a message written in a
52
58
  conversation's own chat (talk.say; its 4th argument the paths of its files there); attach(name, fileName,
53
59
  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);
54
- conversations(): the conversations there are; boxes(): the voice boxes there are. */
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;
60
+ conversations(): the conversations there are; boxes(): the voice boxes there are.
61
+ reach(name, path): how a conversation's chat opens a path of its own ("work:a.png"), or null (talk.reachOf);
62
+ shown(name, ref): whether that chat has that file (talk.shown) -- what an AI shows in a room is read through them. */
63
+ constructor({ file, dir, say, attach = async () => { throw new Refusal(409, 'Files cannot be given here.'); }, rooms = () => {}, conversations = () => [], boxes = () => [], speak = () => {}, now = () => new Date(), reach = () => null, shown = () => false }) {
64
+ this.#speak = speak; this.#attach = attach; this.#reachOf = reach; this.#shownIn = shown;
57
65
  this.#file = file; this.#dir = dir; this.#say = say; this.#rooms = rooms; this.#conversations = conversations; this.#boxes = boxes; this.#now = now;
58
66
  }
59
67
  #all() { const v = this.#file.get(); return Array.isArray(v) ? v : []; }
60
68
  #save(list) { this.#file.set(list); this.#tellConversations(list); }
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; } }); }
69
+ #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 ?? '')); if (m) return `room:${m[1]}/${m[2]}`; return /^\/(work|resources)\//.test(String(path ?? '')) ? `${CITE}${path}` : null; } }); }
62
70
  #find(id) { const r = this.#all().find((x) => x.id === id); if (!r) throw new Refusal(404, 'No such room.'); return r; }
63
71
 
64
72
  /* Its members as they are now: names of the moment (a conversation renamed, a box renamed). */
@@ -148,7 +156,54 @@ export class Rooms {
148
156
  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; });
149
157
  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); } }
150
158
  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)) };
159
+ const messages = (read.messages ?? []).map((m) => this.#opened(m, members)).map((m) => (typeof m.text === 'string' && m.text.includes('@{') ? { ...m, text: named(m.text) } : m));
160
+ /* The files of the thread (shown, cited): each as the message that has it opens it; one nobody opens here, not listed. */
161
+ const opens = new Map(); for (const m of messages) for (const f of [...(m.refs ?? []), ...(m.files ?? []), ...(m.open ? [m] : [])]) if (f.path && f.open) opens.set(f.path, f.open);
162
+ const files = Array.isArray(read.files) ? read.files.map((f) => (String(f.open ?? '').startsWith(CITE) ? (opens.has(f.path) ? { ...f, open: opens.get(f.path) } : null) : f)).filter(Boolean) : read.files;
163
+ return { room: this.get(id), thinking, doing, ...read, messages, ...(files !== undefined ? { files } : {}) };
164
+ }
165
+ /* A message of an AI of the room: each path it cites or shows, opened through ITS conversation (its chat's own
166
+ reference, signed with its member id); anyone else's, or one its conversation cannot open, opens nothing. */
167
+ #opened(m, members) {
168
+ const ai = m.by?.kind === 'ai' ? members.find((x) => x.id === m.by.id && x.kind === 'ai') : undefined;
169
+ const through = (path, open) => {
170
+ if (!String(open ?? '').startsWith(CITE)) return open ?? null;
171
+ if (!ai) return null;
172
+ let own = null; try { own = this.#reachOf(ai.ref, path); } catch { own = null; }
173
+ return typeof own === 'string' && own ? `ai:${ai.id}:${own}` : null;
174
+ };
175
+ const out = { ...m };
176
+ if (Array.isArray(m.refs)) { out.refs = m.refs.map((r) => ({ ...r, open: through(r.path, r.open) })).filter((r) => r.open !== null); if (!out.refs.length) delete out.refs; }
177
+ if (m.kind === 'show' && typeof m.path === 'string') out.open = through(m.path, m.open);
178
+ if (m.kind === 'show' && Array.isArray(m.files)) out.files = m.files.map((f) => ({ ...f, open: through(f.path, f.open) }));
179
+ return out;
180
+ }
181
+ /* A FILE AN AI SHOWED HERE, to be opened (the /shown route): which conversation it is read from, and where in
182
+ it -- only when that AI (a member now) cited or showed it in this room, and its own chat has it. */
183
+ shownFile(id, open) {
184
+ const room = this.#find(id); const members = this.#shown(room);
185
+ const m = AI_OPEN.exec(String(open ?? ''));
186
+ const no = () => new Refusal(404, 'Nothing of that was shown in this room.');
187
+ if (!m) throw no();
188
+ const ai = members.find((x) => x.id === m[1] && x.kind === 'ai');
189
+ if (!ai) throw no();
190
+ const own = `${m[2]}:${m[3]}`;
191
+ const here = this.#thread(room.id).read({ all: true }).messages.filter((x) => x.by?.id === ai.id).map((x) => this.#opened(x, members))
192
+ .some((x) => [...(x.refs ?? []), ...(x.files ?? []), ...(x.open ? [x] : [])].some((f) => f.open === open));
193
+ if (!here) throw no();
194
+ let has = false; try { has = this.#shownIn(ai.ref, own) === true; } catch { has = false; }
195
+ if (!has) throw no();
196
+ return { conversation: ai.ref, tab: m[2], inner: m[3] };
197
+ }
198
+ /* A MAIL AN AI CITED HERE ([Subject](mail:...)): the conversation it is read for, as its own chat would (its
199
+ last AI of the room, a member now, to have cited it); none, refused. */
200
+ mailFrom(id, ref) {
201
+ const room = this.#find(id); const members = this.#shown(room);
202
+ const r = String(ref ?? '').trim();
203
+ if (!/^mail:\S+$/i.test(r)) throw new Refusal(400, 'Not a mail reference.');
204
+ const by = this.#thread(room.id).read({ all: true }).messages.filter((x) => x.by?.kind === 'ai' && [`(${r})`, `(${r} `].some((w) => String(x.text ?? '').includes(w))).map((x) => members.find((y) => y.id === x.by.id && y.kind === 'ai')).filter(Boolean).at(-1);
205
+ if (!by) throw new Refusal(404, 'No AI of this room cited that mail.');
206
+ return by.ref;
152
207
  }
153
208
 
154
209
  /* A FILE THE PERSON ATTACHES, before the message that carries it: the same checks as in a conversation's chat
@@ -247,10 +302,17 @@ export class Rooms {
247
302
  for (const ai of ais) handOver(ai, forwarded.text, from, forwarded.id);
248
303
  if (!String(entry.text ?? '').trim()) return forwarded.id;
249
304
  }
305
+ /* A file it shows (06-11), or a gallery: its paths as it gave them, opened here through its conversation (#opened). */
306
+ const show = kind === 'show' ? {
307
+ ...(typeof entry.path === 'string' && entry.path ? { path: entry.path } : {}),
308
+ ...(Array.isArray(entry.files) && entry.files.length ? { files: entry.files.filter((f) => f && typeof f.path === 'string').map((f) => ({ path: f.path, ...(f.title ? { title: f.title } : {}) })) } : {}),
309
+ } : null;
310
+ if (show && !show.path && !show.files?.length) return null;
311
+ if (show && !String(entry.text ?? '').trim()) entry = { ...entry, text: (show.files?.[0] ?? show).path.split('/').pop() };
250
312
  if (!String(entry.text ?? '').trim()) return null;
251
313
  /* @Name of a member, exactly: kept as its id (the screen says its name of the moment). */
252
314
  const text = masked(entry.text).replace(/@([^\s@{][^@\n]{0,40}?)(?=[\s,.;:!?)]|$)/g, (whole, name) => { const m = members.find((x) => x.name.toLowerCase() === name.toLowerCase()); return m ? `@{${m.id}}` : whole; });
253
- const id = t.relay({ text, by: { id: me.id, name: me.name, kind: 'ai', look: me.look }, to, re, kind: kind === 'doing' ? 'doing' : 'say' });
315
+ const id = t.relay({ text, by: { id: me.id, name: me.name, kind: 'ai', look: me.look }, to, re, kind: show ? 'show' : 'say', ...(show ?? {}) });
254
316
  /* The boxes it is sent to say it aloud (#281): its words, a member named by its name, never an id. */
255
317
  const boxes = to.map((x) => members.find((m) => m.id === x && m.kind === 'box')).filter(Boolean).map((m) => m.ref);
256
318
  if (boxes.length) { const aloud = text.replace(/@\{([0-9a-f-]{36})\}/g, (w, mid) => members.find((x) => x.id === mid)?.name ?? ''); try { this.#speak(`room:${room.id}`, aloud, boxes, { doing: kind === 'doing', asked: kind === 'ask' }); } catch { /* the boxes' */ } }
package/server/talk.mjs CHANGED
@@ -310,6 +310,10 @@ export class Talk {
310
310
  return m && this.#resources.of(name).some((x) => x.name === m[1]) ? `${m[1]}:${m[2]}` : null;
311
311
  }
312
312
 
313
+ /* How this conversation's chat opens a path of its own ("work:report.html"), or null: what a room it is in
314
+ opens of what it shows there (rooms.mjs), with its rights. */
315
+ reachOf(name, path) { return this.#reach(name, path); }
316
+
313
317
  #parley(name, reacted = () => {}) {
314
318
  return new Parley(this.#dir(name), {
315
319
  keep: this.#keep(name),
@@ -319,7 +323,8 @@ export class Talk {
319
323
  if (event.type === 'person-wrote') { this.#want(name); return; }
320
324
  /* What the tool says or asks: a voice box of this conversation may read it aloud (boxes.mjs). */
321
325
  /* Answered in a room it is in (#268): the room takes it, signed by where it came from (rooms.mjs). */
322
- if (['agent-said', 'agent-asked', 'agent-doing'].includes(event.type) && typeof event.message?.room === 'string') { try { this.#inRoom(name, event.message, event.type === 'agent-doing' ? 'doing' : event.type === 'agent-asked' ? 'ask' : 'say'); } catch { /* the room's */ } return; }
326
+ /* A file it shows there too (06-11), once its Parley carries `room` on a show: opened through this conversation. */
327
+ if (['agent-said', 'agent-asked', 'agent-doing', 'agent-showed'].includes(event.type) && typeof event.message?.room === 'string') { try { this.#inRoom(name, event.message, event.type === 'agent-doing' ? 'doing' : event.type === 'agent-asked' ? 'ask' : event.type === 'agent-showed' ? 'show' : 'say'); } catch { /* the room's */ } return; }
323
328
  if (event.type === 'agent-said' || event.type === 'agent-asked') this.#spoke(name, event.message?.text ?? '', Array.isArray(event.message?.to) ? event.message.to : null, { asked: event.type === 'agent-asked' });
324
329
  /* What it is doing: said by a box that was just spoken to, so nobody waits in silence. */
325
330
  if (event.type === 'agent-doing') this.#spoke(name, event.message?.text ?? '', Array.isArray(event.message?.to) ? event.message.to : null, { doing: true });
package/web/app.js CHANGED
@@ -5363,8 +5363,8 @@
5363
5363
  $('salon-thread').dataset.theme = document.documentElement.dataset.theme === 'light' ? 'light' : 'dark';
5364
5364
  salonThread = mount($('salon-thread'), {
5365
5365
  words, markdown: true, agentName: '',
5366
- /* A mail an AI of the room cites: the same chip and viewer as in a conversation's chat. */
5367
- schemes: { mail: { icon: 'mail', open: (ref, label) => { void openMailRef(ref, { label }); } } },
5366
+ /* A mail an AI of the room cites: the same chip and viewer as in a conversation's chat, read for the conversation of the AI that cited it. */
5367
+ schemes: { mail: { icon: 'mail', open: (ref, label) => { void openMailRef(ref, { label, of: '', room: id }); } } },
5368
5368
  load: (asked = {}) => fetch(`${API}/rooms/${id}/talk${asked.last ? `?last=${asked.last}` : ''}`).then((x) => x.json()).then((d) => {
5369
5369
  /* Read for a room no longer shown: its words go nowhere (Parley drops them with its screen). */
5370
5370
  if (salonId !== id || place !== 'salon') return d;
@@ -5392,7 +5392,10 @@
5392
5392
  send: (text, answers, files) => post(`${API}/rooms/${id}/talk`, { text, ...(files?.length ? { files: files.map((f) => f.path) } : {}) }),
5393
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
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 }); },
5395
+ /* A file an AI of the room showed or cited (ai:<member>:work:a.png): read from its own conversation, in the same viewer as in its chat. */
5396
+ open: (file) => { const o = String(file.open ?? ''); if (o.startsWith('ai:')) { const at = o.split(':').slice(3).join(':'); void preview('', '', at.split('/').pop() || 'file', 0, `${API}/rooms/${id}/shown?${new URLSearchParams({ o })}`, { origin: '' }); return; } if (!o.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 }); },
5397
+ /* Its pictures, as its chat shows them: those its AIs showed, read from their own conversations (type proved by the bytes). */
5398
+ picture: (file) => (String(file.open ?? '').startsWith('ai:') ? `${API}/rooms/${id}/shown?${new URLSearchParams({ o: file.open, thumb: '1' })}` : null),
5396
5399
  /* The same chat as a conversation's (03-11): its view, its formulas, its dictation, its keyboard rule. */
5397
5400
  view: chatView, onView: (v) => { chatView = v; try { localStorage.setItem('clavarium-chat-view', v); } catch { /* as above */ } },
5398
5401
  math: { url: new URL('vendor/katex/katex.mjs', new URL('/', location.href)).href },
@@ -5984,7 +5987,9 @@
5984
5987
  page, its bytes read by the server through Tether when it is opened -- never before, kept nowhere --
5985
5988
  and only by whoever may read that mailbox. `of`: the conversation it was cited in, whose chat Reply
5986
5989
  writes in. */
5987
- function openMailRef(ref, { label = '', of = current } = {}) {
5990
+ function openMailRef(ref, { label = '', of = current, room = '' } = {}) {
5991
+ /* Cited in a room: read for the conversation of the AI that cited it (the server finds it, and says which). */
5992
+ if (room) return preview('', '', `${String(label || '').trim() || uiSaid('set-mail-mail', 'Mail')}.eml`, 0, `${API}/rooms/${room}/mail/open?${new URLSearchParams({ ref })}`, { mailRef: { ref, of: '', label, room } });
5988
5993
  const q = new URLSearchParams({ ref, ...(of ? { c: of } : {}) });
5989
5994
  const name = `${String(label || '').trim() || uiSaid('set-mail-mail', 'Mail')}.eml`;
5990
5995
  return preview('', '', name, 0, `${API}/mail/open?${q}`, { mailRef: { ref, of, label } });
@@ -9522,7 +9527,7 @@
9522
9527
  $('preview-full').onclick = () => full(!$('viewer').classList.contains('viewer-full'));
9523
9528
  $('preview-attach').onclick = () => void attachToCard(opts.mailRef ? { kind: 'mail', ref: opts.mailRef.got?.ref || opts.mailRef.ref, title: opts.mailRef.title || opts.mailRef.label || name } : { kind: 'file', ref: tab === 'work' ? `/work/${inner}` : `/resources/${tab}/${inner}`, title: name });
9524
9529
  /* A file read from the machine's disk says so, whatever else is said. */
9525
- const origin = opts.within ? uiSaid('set-mail-of', 'An attachment of {name}', { name: opts.within }) : opts.mailRef ? '' : from ? 'Read from the disk of the machine: this file is not kept here, and goes with the machine.' : '';
9530
+ const origin = typeof opts.origin === 'string' ? opts.origin : opts.within ? uiSaid('set-mail-of', 'An attachment of {name}', { name: opts.within }) : opts.mailRef ? '' : from ? 'Read from the disk of the machine: this file is not kept here, and goes with the machine.' : '';
9526
9531
  const note = (text) => { const all = [text, text === 'Loading...' ? '' : origin].filter(Boolean).join(' '); $('preview-note').textContent = all; $('preview-note').hidden = !all; };
9527
9532
  /* NOTHING TO SHOW (02-11): not an empty frame, but a file, why, and a Download button that is seen. */
9528
9533
  const cannot = (why) => {
@@ -9541,7 +9546,7 @@
9541
9546
  const r = await fetch(address);
9542
9547
  if (!r.ok) { const said = await r.json().catch(() => ({})); throw Object.assign(new Error(said.error || 'The file could not be read.'), { kind: said.kind }); }
9543
9548
  /* A mail read by its reference: where it was found, and its reference as it is now. */
9544
- if (opts.mailRef) { const h = (k) => { try { return decodeURIComponent(r.headers.get(k) ?? ''); } catch { return ''; } }; opts.mailRef.got = { box: h('x-mail-box'), folder: h('x-mail-folder'), ref: h('x-mail-ref') || opts.mailRef.ref, cut: r.headers.get('x-mail-cut') === '1' }; }
9549
+ if (opts.mailRef) { const h = (k) => { try { return decodeURIComponent(r.headers.get(k) ?? ''); } catch { return ''; } }; opts.mailRef.got = { box: h('x-mail-box'), folder: h('x-mail-folder'), ref: h('x-mail-ref') || opts.mailRef.ref, cut: r.headers.get('x-mail-cut') === '1' }; if (h('x-mail-of')) opts.mailRef.of = h('x-mail-of'); }
9545
9550
  return r.arrayBuffer();
9546
9551
  };
9547
9552
  /* A mail that cannot be opened by its reference: one clear line (gone, not theirs, unreachable), never a download. */
@@ -9554,7 +9559,7 @@
9554
9559
  box.append(icon, el('b', 'mail-state-line', line ? uiSaid(line[0], line[1]) : error.message));
9555
9560
  if (error.kind === 'unreachable' || !line) {
9556
9561
  const again = el('button', 'quiet mail-state-retry', uiSaid('set-mail-retry', 'Try again')); again.type = 'button';
9557
- again.addEventListener('click', () => { void openMailRef(opts.mailRef.ref, { label: opts.mailRef.label, of: opts.mailRef.of }); });
9562
+ again.addEventListener('click', () => { void openMailRef(opts.mailRef.ref, { label: opts.mailRef.label, of: opts.mailRef.of, room: opts.mailRef.of ? '' : opts.mailRef.room }); });
9558
9563
  box.append(again);
9559
9564
  }
9560
9565
  $('preview-name').textContent = opts.mailRef.label || uiSaid('set-mail-mail', 'Mail');