clavarium 0.2.360-next.1 → 0.2.362-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.
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.360-next.1",
3
+ "version": "0.2.362-next.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "clavarium",
9
- "version": "0.2.360-next.1",
9
+ "version": "0.2.362-next.1",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@xterm/addon-fit": "^0.11.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.360-next.1",
3
+ "version": "0.2.362-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.",
package/server/api.mjs CHANGED
@@ -95,6 +95,8 @@
95
95
  * POST /api/rooms {name, conversations: [names], boxes: [ids], host?}: a new room
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
+ * POST /api/rooms/<id>/give {asset, rights, shared?}: the same right given to each AI of it, its own
99
+ * conversation's -> {asset, rights, given: [{conversation, ok, kept?, error?}]}
98
100
  * GET /api/rooms/<id>/talk?last= its thread, with the room: {room, messages, ...}
99
101
  * POST /api/rooms/<id>/talk {text, to?: [AI member ids], files?}: said in it; to its host, or to the AIs named
100
102
  * POST /api/rooms/<id>/talk/file?name= the body IS a file the person attaches there -> {path, name, size}
@@ -156,6 +158,7 @@ import { writeFileSync } from 'node:fs';
156
158
  import { suggest } from './suggest.mjs';
157
159
  import { sameOrigin } from './bridge.mjs';
158
160
  import { Refusal, DISK_GB } from './conversations.mjs';
161
+ import { readRights, typeOf, nameOf } from './grants.mjs';
159
162
  import { VmUnknown } from './vm.mjs';
160
163
  import { list, download, importFile, page, PAGE_HEADERS, changeRoute, IMAGE_HEADERS, mailFile, mailPage } from './files.mjs';
161
164
  import { mailRoute } from './mailref.mjs';
@@ -684,6 +687,57 @@ export async function handleApi(request, response, conversations, headers, resou
684
687
  }
685
688
  /* A setting its tool is told about changed: its guide follows (never waking a machine). */
686
689
  const retell = (conversation) => { void guide?.changed(conversation).catch(() => {}); };
690
+ /* THE ONE GIVE TO A CONVERSATION, as its own settings do it: a folder, a repository, a mailbox attached at
691
+ an access; a secret handed or taken back. A room's « give to all its AIs » calls the same, once for each. */
692
+ const attachResource = async (conversation, name, access, shared) => {
693
+ if (!conversations.list().some((c) => c.name === conversation && c.phase === 'ready')) throw new Refusal(404, 'No such conversation, or it is not ready.');
694
+ /* A second writer next to one that sends by itself: confirmed first. */
695
+ if (access === 'write') gitKeeper?.beforeWriter(name, conversation, shared === true);
696
+ /* Its automatic sending goes with the write attachment -- forgotten
697
+ BEFORE the change, so that a change that fails half-way (unmounted,
698
+ not mounted again) never leaves settings to come back later. */
699
+ if (access !== 'write') gitKeeper?.forgetAttachment(name, conversation);
700
+ await resources.attach(conversation, name, access);
701
+ retell(conversation);
702
+ };
703
+ const handSecret = async (conversation, name, attached) => {
704
+ if (!conversations.list().some((c) => c.name === conversation)) throw new Refusal(404, 'No such conversation.');
705
+ secrets.attach(conversation, name, attached);
706
+ /* A machine that runs gets it (or loses it) now, in /run/secrets -- not only at the next
707
+ opening of a terminal; its tool's variables still wait for the tool's next start. */
708
+ const c = conversations.list().find((x) => x.name === conversation);
709
+ if (c?.phase === 'ready' && !c.asleep) await secrets.deliver(conversation).catch(() => {});
710
+ retell(conversation);
711
+ };
712
+ /* GIVE ONE ASSET TO EVERY AI OF A ROOM (06-11): there is no room asset -- each AI of the room gets the same
713
+ ordinary right of its own conversation, taken back one by one. A box or the person gets nothing; a secret
714
+ goes to conversations only. Checked once before any is given (the asset, its rights as for one
715
+ conversation); then each gets it whole or not at all, and the answer says which: {asset, rights, given:
716
+ [{conversation, ok, kept?, error?}]}. A right already wider is kept, never lowered. */
717
+ const roomGive = /^\/api\/rooms\/([0-9a-f-]{36})\/give$/.exec(pathname);
718
+ if (roomGive && rooms) {
719
+ const asset = String(body.asset ?? ''); const rights = readRights(asset, body.rights);
720
+ const type = typeOf(asset); const name = nameOf(asset);
721
+ if (type === 'secret') { if (!secrets?.list({ held: true }).some((x) => x.name === name)) throw new Refusal(404, 'No such secret.'); }
722
+ else if (['folder', 'git', 'mailbox'].includes(type)) { if (!resources?.list().some((r) => resources.assetOf(r) === asset)) throw new Refusal(404, 'No such asset.'); }
723
+ else throw new Refusal(400, 'A folder, a repository, a mailbox or a secret is given to the AIs of a room.');
724
+ const ais = rooms.ais(roomGive[1]);
725
+ if (!ais.length) throw new Refusal(409, 'This room has no AI.');
726
+ const given = [];
727
+ for (const conversation of ais) {
728
+ try {
729
+ if (type === 'secret') await handSecret(conversation, name, true);
730
+ else {
731
+ const access = rights.includes('w') ? 'write' : 'read';
732
+ const had = resources.of(conversation).find((r) => r.name === name)?.access;
733
+ if (had === 'write' && access === 'read') { given.push({ conversation, ok: true, kept: 'write' }); continue; }
734
+ await attachResource(conversation, name, access, body.shared === true);
735
+ }
736
+ given.push({ conversation, ok: true });
737
+ } catch (error) { given.push({ conversation, ok: false, error: error.message, ...(error.kind ? { kind: error.kind } : {}) }); }
738
+ }
739
+ return send(200, { asset, rights, given }), true;
740
+ }
687
741
  const talking = /^\/api\/conversations\/([^/]+)\/talk(\/invite|\/remind|\/react)?$/.exec(pathname);
688
742
  if (talking && talk) {
689
743
  const conversation = decodeURIComponent(talking[1]);
@@ -729,13 +783,7 @@ export async function handleApi(request, response, conversations, headers, resou
729
783
  const handed = /^\/api\/conversations\/([^/]+)\/secrets$/.exec(pathname);
730
784
  if (handed && secrets) {
731
785
  const conversation = decodeURIComponent(handed[1]);
732
- if (!conversations.list().some((c) => c.name === conversation)) throw new Refusal(404, 'No such conversation.');
733
- secrets.attach(conversation, String(body.secret ?? ''), body.attached === true);
734
- /* A machine that runs gets it (or loses it) now, in /run/secrets -- not only at the next
735
- opening of a terminal; its tool's variables still wait for the tool's next start. */
736
- const c = conversations.list().find((x) => x.name === conversation);
737
- if (c?.phase === 'ready' && !c.asleep) await secrets.deliver(conversation).catch(() => {});
738
- retell(conversation);
786
+ await handSecret(conversation, String(body.secret ?? ''), body.attached === true);
739
787
  return send(200, { ok: true, secrets: secrets.of(conversation) }), true;
740
788
  }
741
789
  /* Forget an ephemeral secret now (its stars in the chat have a button): gone from the vault and the machine. */
@@ -798,16 +846,7 @@ export async function handleApi(request, response, conversations, headers, resou
798
846
  const attach = /^\/api\/conversations\/([^/]+)\/resources$/.exec(pathname);
799
847
  if (attach && resources) {
800
848
  const conversation = decodeURIComponent(attach[1]);
801
- if (!conversations.list().some((c) => c.name === conversation && c.phase === 'ready')) throw new Refusal(404, 'No such conversation, or it is not ready.');
802
- const name = String(body.resource ?? ''); const access = String(body.access ?? '');
803
- /* A second writer next to one that sends by itself: confirmed first. */
804
- if (access === 'write') gitKeeper?.beforeWriter(name, conversation, body.shared === true);
805
- /* Its automatic sending goes with the write attachment -- forgotten
806
- BEFORE the change, so that a change that fails half-way (unmounted,
807
- not mounted again) never leaves settings to come back later. */
808
- if (access !== 'write') gitKeeper?.forgetAttachment(name, conversation);
809
- await resources.attach(conversation, name, access);
810
- retell(conversation);
849
+ await attachResource(conversation, String(body.resource ?? ''), String(body.access ?? ''), body.shared === true);
811
850
  return send(200, { ok: true, resources: resources.of(conversation) }), true;
812
851
  }
813
852
  const moved = /^\/api\/conversations\/([^/]+)\/work$/.exec(pathname);
package/server/main.mjs CHANGED
@@ -23,12 +23,13 @@ import pty from 'node-pty';
23
23
  import { attachBridge } from './bridge.mjs';
24
24
  import { attachCommand } from './tmux.mjs';
25
25
  import { handleApi } from './api.mjs';
26
- import { Conversations, DRAWN_MS } from './conversations.mjs';
26
+ import { Conversations, DRAWN_MS, Refusal } from './conversations.mjs';
27
27
  import { Store, JsonFile } from './store.mjs';
28
28
  import { Instance } from './instance.mjs';
29
29
  import { loadTools } from './tools.mjs';
30
30
  import { Vms, runner } from './vm.mjs';
31
- import { Resources } from './resources.mjs';
31
+ import { Resources, WORK_TAB } from './resources.mjs';
32
+ import { download } from './files.mjs';
32
33
  import { makeGate, makeOriginCheck, readOperators } from './gate.mjs';
33
34
  import { Shortcuts } from './shortcuts.mjs';
34
35
  import { hearBox, Dictation } from './voice.mjs';
@@ -684,7 +685,18 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
684
685
  rooms: (name, list) => talk.rooms(name, list), conversations: () => all.list(), boxes: () => boxes.all(),
685
686
  speak: (where, text, ids, how) => { void boxes.agentSaid(where, text, ids, how); },
686
687
  /* 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) });
688
+ reach: (name, path) => talk.reachOf(name, path), shown: (name, ref) => talk.shown(name, ref),
689
+ /* What an AI gives another AI of the room: read from its own folders, as the room's /shown route does (api.mjs). */
690
+ read: async (name, ref) => {
691
+ const m = /^([a-z][a-z0-9-]{0,31}):(.+)$/.exec(String(ref ?? ''));
692
+ if (!m) throw new Refusal(404, 'No such file.');
693
+ if (m[1] === WORK_TAB) {
694
+ if (all.list().find((x) => x.name === name)?.work !== 'kept') throw new Refusal(404, 'No such file.');
695
+ return download(folders.workFolder(name), m[2]);
696
+ }
697
+ if (!folders.of(name).some((r) => r.name === m[1])) throw new Refusal(404, 'No such file.');
698
+ return download(folders.folder(m[1]), m[2]);
699
+ } });
688
700
  rooms.boxesBound(boxes.all());
689
701
  rooms.refresh();
690
702
  /* FEATURES (features.mjs): read from what the modules say, never a secret's value. The remote screen and the
package/server/rooms.mjs CHANGED
@@ -18,7 +18,7 @@ import { createReadStream, lstatSync, mkdirSync, rmSync } from 'node:fs';
18
18
  import { randomUUID } from 'node:crypto';
19
19
  import { join } from 'node:path';
20
20
  import { Parley, FILES_MAX } from 'clavarium-parley/host';
21
- import { importFile } from './files.mjs';
21
+ import { importFile, IMPORT_MAX } from './files.mjs';
22
22
  import { Refusal } from './conversations.mjs';
23
23
  import { scan } from './secret-scan.mjs';
24
24
 
@@ -40,6 +40,13 @@ const ROOM_FILE = /^\/room\/attached\/([0-9a-f-]{36})\/([^/]+)$/;
40
40
  rights -- never another's. In the thread, its reference reads `ai:<member id>:<how its chat opens it>` (work:report.html);
41
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
42
  const CITE = 'cite:';
43
+ /* A file name as a chat's files take it (files.mjs isFileName): one visible segment, at most 120 characters. */
44
+ const cleanName = (name) => {
45
+ const plain = String(name ?? '').replace(/[\\/\u0000-\u001f\u007f-\u009f]+/g, '-').replace(/^[.\s]+/, '').trim();
46
+ if (plain.length <= 120) return plain;
47
+ const dot = plain.lastIndexOf('.'); const ext = dot > 0 && plain.length - dot <= 16 ? plain.slice(dot) : '';
48
+ return plain.slice(0, 120 - ext.length) + ext;
49
+ };
43
50
  const AI_OPEN = /^ai:([0-9a-f-]{36}):([a-z][a-z0-9-]{0,31}):(.+)$/;
44
51
  const nameOf = (v) => String(v ?? '').replace(/\s+/g, ' ').trim().slice(0, ROOM_NAME_MAX);
45
52
 
@@ -53,15 +60,17 @@ export const masked = (text) => { const str = String(text ?? ''); const hits = s
53
60
  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 }; };
54
61
 
55
62
  export class Rooms {
56
- #file; #dir; #say; #attach; #rooms; #conversations; #boxes; #now; #speak; #reachOf; #shownIn; #hops = new Map(); #thinking = new Map();
63
+ #file; #dir; #say; #attach; #read; #rooms; #conversations; #boxes; #now; #speak; #reachOf; #shownIn; #hops = new Map(); #thinking = new Map();
57
64
  /* file: a JsonFile of the rooms; dir: where their threads are; say(name, text, extra): a message written in a
58
65
  conversation's own chat (talk.say; its 4th argument the paths of its files there); attach(name, fileName,
59
66
  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);
60
67
  conversations(): the conversations there are; boxes(): the voice boxes there are.
61
68
  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;
69
+ shown(name, ref): whether that chat has that file (talk.shown) -- what an AI shows in a room is read through them.
70
+ read(name, ref): that file of that conversation ({ name, size, stream }), read with its rights -- what an AI
71
+ shows or cites to another AI of the room is copied from it (#carried). */
72
+ 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, read = async () => { throw new Refusal(404, 'No such file.'); } }) {
73
+ this.#speak = speak; this.#attach = attach; this.#read = read; this.#reachOf = reach; this.#shownIn = shown;
65
74
  this.#file = file; this.#dir = dir; this.#say = say; this.#rooms = rooms; this.#conversations = conversations; this.#boxes = boxes; this.#now = now;
66
75
  }
67
76
  #all() { const v = this.#file.get(); return Array.isArray(v) ? v : []; }
@@ -92,6 +101,9 @@ export class Rooms {
92
101
  #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); }
93
102
  #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); }
94
103
  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) }; }); }
104
+ /* ITS AIs, as conversations (06-11): the names of the conversations of its AI members that are there now --
105
+ never a box, never the person, never one taken out of the room. What « give to all its AIs » gives to. */
106
+ ais(id) { return this.#shown(this.#find(id)).filter((m) => m.kind === 'ai').map((m) => m.ref); }
95
107
  get(id) { const r = this.#find(id); return { id: r.id, name: r.name, host: r.host, members: this.#shown(r), at: r.at }; }
96
108
 
97
109
  /* A new room: its name, its AIs (conversation names), its boxes (ids), and which AI is the host (the first by default). */
@@ -287,12 +299,16 @@ export class Rooms {
287
299
  /* The other AIs it is sent to (#280): they get it in their own chat, as said in the room -- never beyond a few
288
300
  hand-overs after the person last spoke (no two AIs talking for ever). */
289
301
  const ais = to.map((x) => members.find((m) => m.id === x && m.kind === 'ai')).filter(Boolean);
290
- const handOver = (ai, text, from, message) => {
302
+ /* `paths`: the files it shows or cites in it -- each AI it goes to gets its own copy, as when the person attaches one. */
303
+ const handOver = (ai, text, from, message, paths = []) => {
291
304
  const n = (this.#hops.get(room.id) ?? 0) + 1;
292
305
  if (n > HOPS_MAX) return false;
293
306
  this.#hops.set(room.id, n);
294
307
  this.#think(room.id, ai.id, true);
295
- void this.#say(ai.ref, text, { by: from, room: { id: room.id, name: room.name, message } }).catch(() => {});
308
+ void (async () => {
309
+ const copies = paths.length ? await this.#carried(me, ai, paths) : [];
310
+ await this.#say(ai.ref, text, { by: from, room: { id: room.id, name: room.name, message } }, ...(copies.length ? [copies] : []));
311
+ })().catch(() => {});
296
312
  return true;
297
313
  };
298
314
  /* Handed on as it is: the message itself, by who said it; the room's thread keeps no copy. */
@@ -316,10 +332,41 @@ export class Rooms {
316
332
  /* The boxes it is sent to say it aloud (#281): its words, a member named by its name, never an id. */
317
333
  const boxes = to.map((x) => members.find((m) => m.id === x && m.kind === 'box')).filter(Boolean).map((m) => m.ref);
318
334
  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' */ } }
319
- if (!forwarded && kind !== 'doing') for (const ai of ais) handOver(ai, text, { id: me.id, name: me.name, kind: 'ai', look: me.look }, id);
335
+ if (!forwarded && kind !== 'doing' && ais.length) {
336
+ /* What it shows, and the paths it cites (its message's refs, as the room's thread read them). */
337
+ const said = all().find((m) => m.id === id);
338
+ const paths = [...new Set([...(show?.path ? [show.path] : []), ...(show?.files ?? []).map((f) => f.path),
339
+ ...(Array.isArray(said?.refs) ? said.refs.filter((r) => String(r.open ?? '').startsWith(CITE)).map((r) => r.path) : [])])].slice(0, FILES_MAX);
340
+ for (const ai of ais) handOver(ai, text, { id: me.id, name: me.name, kind: 'ai', look: me.look }, id, paths);
341
+ }
320
342
  return id;
321
343
  }
322
344
 
345
+ /* A FILE AN AI GIVES ANOTHER AI OF THE ROOM (06-11): read from the giver's conversation, with its rights -- a path
346
+ its own chat opens (its /work, a folder attached to it) and has (shown or cited there), as the room's preview --
347
+ then put in the receiver's chat files, as if the person attached it there. One it may not give, too large, or
348
+ of a name that cannot be cleaned: not given (the message still goes). Resolves with the receiver's paths. */
349
+ async #carried(from, to, paths) {
350
+ const copies = [];
351
+ for (const path of paths) {
352
+ if (typeof path !== 'string' || path.split('/').includes('..')) continue;
353
+ let own = null; try { own = this.#reachOf(from.ref, path); } catch { own = null; }
354
+ if (typeof own !== 'string' || !own) continue;
355
+ let has = false; try { has = this.#shownIn(from.ref, own) === true; } catch { has = false; }
356
+ if (!has) continue;
357
+ let file = null;
358
+ try {
359
+ file = await this.#read(from.ref, own);
360
+ if (!file?.stream || !(file.size <= IMPORT_MAX)) continue;
361
+ const name = cleanName(file.name);
362
+ if (!name) continue;
363
+ file.stream.headers = { 'content-length': String(file.size) };
364
+ copies.push((await this.#attach(to.ref, name, file.stream)).path);
365
+ } catch { /* not given */ } finally { file?.stream?.destroy?.(); }
366
+ }
367
+ return copies;
368
+ }
369
+
323
370
  /* Each conversation told the rooms it is in, and who is there. */
324
371
  #tellConversations(list) {
325
372
  const shown = list.map((r) => ({ ...r, members: this.#shown(r) }));
@@ -87,5 +87,9 @@ export const SETTINGS_WORDS_FR = {
87
87
  'set-as-fold': 'Replier', 'set-as-unfold': 'Déplier', 'set-as-group-open': 'Réglages de {name}', 'set-as-group-gear': 'Donner, renommer, supprimer',
88
88
  'set-as-group-empty': 'Vide : glissez un asset ici', 'set-as-all-grouped': 'Chaque asset est dans un groupe',
89
89
  'set-as-no-groups': 'Créez un groupe, puis glissez-y un asset',
90
+ /* A room's settings (06-11): each AI's own assets; one right given to each of them. */
91
+ 'set-room-assets': 'Leurs assets', 'set-room-give': '+ Donner…', 'set-room-give-all': 'Donner à toutes ses IA…',
92
+ 'set-room-assets-none': 'Rien encore', 'set-room-give-pick': 'Choisissez un asset', 'set-room-give-go': 'Donner à {n} IA',
93
+ 'set-room-give-done': 'Donné à {name}', 'set-room-give-kept': '{name} a déjà plus', 'set-room-give-cancel': 'Annuler',
90
94
  };
91
95
  export const settingsWords = (lang) => (String(lang ?? '').toLowerCase().split('-')[0] === 'fr' ? { ...SETTINGS_WORDS_FR } : {});
package/web/app.js CHANGED
@@ -5438,6 +5438,70 @@
5438
5438
  }));
5439
5439
  }
5440
5440
  $('salon-new-search').addEventListener('input', paintSalonMembers);
5441
+ /* EACH AI'S ASSETS (06-11), in a room's settings: what each of its AIs has, as its own conversation has it --
5442
+ there is no room asset. « + Give… » opens that conversation's own give; « Give to all its AIs… » gives one
5443
+ asset at one right to each (POST /rooms/<id>/give): ordinary rights of each conversation, taken back one by one. */
5444
+ let salonGive = null;
5445
+ const GIVE_LETTERS = { read: 'r', write: 'rw', use: 'x' };
5446
+ const salonOpenConv = (name, pick) => { salonEditing = null; salonGive = null; select(name, { step: true }); if (pick) { goTab('assets', { pick }); assetStep(); } else void openAccess(true); };
5447
+ async function paintSalonAssets() {
5448
+ const r = salonEditing; const card = $('salon-assets-card');
5449
+ card.hidden = !r; if (!r) return;
5450
+ const [all, held] = await Promise.all([getJson('/resources', []), getJson('/secrets', [])]);
5451
+ if (salonEditing !== r) return;
5452
+ const list = (Array.isArray(all) ? all : []).map((x) => { const kind = kindOf(x); return { key: `${kind}:${x.name}`, kind, name: x.name }; });
5453
+ const keys = Array.isArray(held) ? held : [];
5454
+ const ais = r.members.filter((m) => m.kind === 'ai').sort((a, b) => Number(Boolean(b.host)) - Number(Boolean(a.host)));
5455
+ const assetsOf = (name) => {
5456
+ const mine = new Map((conversations.find((x) => x.name === name)?.resources ?? []).map((x) => [x.name, x.access]));
5457
+ return [...list.filter((a) => mine.has(a.name)).map((a) => ({ ...a, right: { key: a.kind, value: mine.get(a.name) } })),
5458
+ ...keys.filter((k) => (k.conversations ?? []).includes(name)).map((k) => ({ key: `secret:${k.name}`, kind: 'secret', name: k.name, right: { key: 'secret', level: 'use' } }))];
5459
+ };
5460
+ $('salon-assets').replaceChildren(...ais.map((m) => {
5461
+ const c = conversations.find((x) => x.name === m.ref);
5462
+ const give = el('button', 'salon-give-btn', uiSaid('set-room-give', '+ Give\u2026')); give.type = 'button';
5463
+ give.setAttribute('aria-label', `Give to ${shownName(c) || m.name}`);
5464
+ give.addEventListener('click', () => salonOpenConv(m.ref));
5465
+ const head = c ? KIT.ConvCard(convModel(c), { size: 'member', actions: [give] }) : el('b', '', m.name);
5466
+ const chips = el('div', 'salon-asset-chips'); const mine = assetsOf(m.ref);
5467
+ if (mine.length) chips.append(...mine.map((a) => KIT.AssetCard(a, { size: 'chip', onOpen: (key) => salonOpenConv(m.ref, key) })));
5468
+ else chips.append(el('small', 'hint', uiSaid('set-room-assets-none', 'Nothing yet')));
5469
+ const row = el('div', 'salon-asset-ai'); row.setAttribute('role', 'listitem'); row.dataset.name = m.ref;
5470
+ row.append(head, chips);
5471
+ return row;
5472
+ }));
5473
+ $('salon-assets-all').setAttribute('aria-expanded', String(Boolean(salonGive)));
5474
+ paintSalonGive(r, [...list, ...keys.map((k) => ({ key: `secret:${k.name}`, kind: 'secret', name: k.name }))], ais.length);
5475
+ }
5476
+ /* « Give to all its AIs… »: an asset, a right (None first), then given to each. What each got is said below. */
5477
+ function paintSalonGive(r, items, n) {
5478
+ const box = $('salon-assets-give'); box.hidden = !salonGive;
5479
+ if (!salonGive) { box.replaceChildren(); return; }
5480
+ const chosen = items.find((a) => a.key === salonGive.asset);
5481
+ const pick = el('div', 'salon-give-assets');
5482
+ pick.append(...items.map((a) => KIT.AssetCard(a, { size: 'chip', current: a.key === salonGive.asset, onOpen: (key) => { salonGive = { asset: key, level: '', said: [] }; paintSalonGive(r, items, n); } })));
5483
+ const go = el('button', 'primary', uiSaid('set-room-give-go', 'Give to {n} AIs', { n })); go.type = 'button';
5484
+ go.disabled = !(chosen && salonGive.level);
5485
+ const parts = [el('small', 'hint', uiSaid('set-room-give-pick', 'Pick an asset')), pick];
5486
+ if (chosen) parts.push(KIT.RightsPicker({ key: chosen.kind, level: salonGive.level || 'none', label: `Right on ${chosen.name}`, cls: 'salon-give-right',
5487
+ onChange: (l) => { salonGive.level = l === 'none' ? '' : l; go.disabled = !salonGive.level; } }));
5488
+ go.addEventListener('click', async () => {
5489
+ go.disabled = true; $('salon-new-error').hidden = true;
5490
+ try { const out = await post(`${API}/rooms/${r.id}/give`, { asset: chosen.key, rights: GIVE_LETTERS[salonGive.level] }); salonGive.said = Array.isArray(out.given) ? out.given : []; await refresh(); }
5491
+ catch (error) { $('salon-new-error').textContent = error.message; $('salon-new-error').hidden = false; }
5492
+ await paintSalonAssets();
5493
+ });
5494
+ const cancel = el('button', '', uiSaid('set-room-give-cancel', 'Cancel')); cancel.type = 'button';
5495
+ cancel.addEventListener('click', () => { salonGive = null; void paintSalonAssets(); });
5496
+ const said = el('div', 'salon-give-said'); said.setAttribute('role', 'status');
5497
+ for (const g of salonGive.said) {
5498
+ const who = shownName(conversations.find((x) => x.name === g.conversation)) || g.conversation;
5499
+ said.append(el('small', g.ok ? 'hint' : 'err', !g.ok ? `${who}: ${g.error}` : g.kept ? uiSaid('set-room-give-kept', '{name} already has more', { name: who }) : `\u2713 ${uiSaid('set-room-give-done', 'Given to {name}', { name: who })}`));
5500
+ }
5501
+ const actions = el('div', 'action-row'); actions.append(cancel, go);
5502
+ box.replaceChildren(...parts, ...(said.children.length ? [said] : []), actions);
5503
+ }
5504
+ $('salon-assets-all').addEventListener('click', () => { salonGive = salonGive ? null : { asset: '', level: '', said: [] }; void paintSalonAssets(); });
5441
5505
  /* A ROOM'S "+ Voice box": the New asset box, its kind a voice box, speaking in this room; once it answers, it is
5442
5506
  among the room's boxes, switched on (kept with Save). */
5443
5507
  function paintSalonBoxNew() {
@@ -5488,6 +5552,7 @@
5488
5552
  $('salon-new-boxes-card').hidden = $('salon-new-voice-head').hidden = salonBoxList.length === 0 && !editing;
5489
5553
  $('salon-new-box-add').hidden = !editing; closeSalonBoxNew();
5490
5554
  paintSalonMembers();
5555
+ salonGive = null; void paintSalonAssets();
5491
5556
  $('salon-new-name').focus();
5492
5557
  }
5493
5558
  $('salon-settings').addEventListener('click', async () => { await loadRooms(); const r = rooms.find((x) => x.id === salonId); if (r) await openSalonNew(true, r); });
package/web/index.html CHANGED
@@ -733,6 +733,12 @@
733
733
  <div class="salon-members-tools"><input id="salon-new-search" type="search" placeholder="Find a conversation" aria-label="Find a conversation" autocomplete="off"></div>
734
734
  <div id="salon-new-ais" class="salon-member-list" role="list" aria-label="AIs"></div>
735
735
  </div>
736
+ <!-- Each AI's assets (06-11): its own, as its conversation has them; no room asset. -->
737
+ <div class="nc-card" id="salon-assets-card" hidden>
738
+ <div class="row"><span class="sub-head" data-said="set-room-assets">Their assets</span><span class="sp"></span><button type="button" id="salon-assets-all" data-said="set-room-give-all">Give to all its AIs…</button></div>
739
+ <div id="salon-assets-give" class="salon-give" hidden></div>
740
+ <div id="salon-assets" class="salon-member-list salon-assets-list" role="list" aria-label="Their assets"></div>
741
+ </div>
736
742
  <h3 class="room-group" id="salon-new-voice-head" data-said="set-tab-chat">Chat &amp; voice</h3>
737
743
  <div class="nc-card" id="salon-new-boxes-card">
738
744
  <div class="row"><span class="sub-head">Voice boxes</span><span class="sp"></span><button type="button" id="salon-new-box-add" data-said="set-na-plus-box">+ Voice box</button></div>
package/web/style.css CHANGED
@@ -2383,6 +2383,18 @@ button.salon-welcome-btn[aria-pressed="true"] { color: var(--brass-ink); border-
2383
2383
  .nc-card > .salon-host-box { padding: 8px 12px; }
2384
2384
  .nc-card > .salon-members-tools { padding-bottom: 4px; }
2385
2385
  .nc-card > .salon-host-box + *, .nc-card > .salon-member-list + * { border-top: 0; }
2386
+ /* Each AI's assets in a room's settings (06-11): its member card, its assets as chips below; give to all its AIs. */
2387
+ .salon-assets-list { max-height: none; }
2388
+ .salon-asset-ai { display: flex; flex-direction: column; gap: 2px; padding-bottom: 10px; border-top: 1px solid var(--line); }
2389
+ .salon-asset-ai:first-child { border-top: 0; }
2390
+ .salon-asset-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 12px; }
2391
+ button.salon-give-btn { border-radius: 999px; padding: 4px 10px; font-size: .75rem; min-height: 32px; background: transparent; color: var(--ink2); white-space: nowrap; }
2392
+ .nc-card > .salon-give { margin: 4px 16px 12px; padding: 10px 12px; border: 1px solid var(--brass); border-radius: 10px; background: color-mix(in srgb, var(--brass) 6%, var(--panel)); display: flex; flex-direction: column; gap: 8px; }
2393
+ .salon-give-assets { display: flex; flex-wrap: wrap; gap: 6px; max-height: 12rem; overflow-y: auto; }
2394
+ .salon-give-said { display: flex; flex-direction: column; gap: 2px; }
2395
+ .salon-give .action-row { padding: 0; border: 0; }
2396
+ button.kit-asset-chip { min-height: 32px; color: var(--ink); cursor: pointer; }
2397
+ .kit-asset-chip[aria-current="true"] { border-color: var(--brass); background: color-mix(in srgb, var(--brass) 16%, transparent); }
2386
2398
  /* The list's button on each page of its own (03-11), as the conversation's. */
2387
2399
  /* THE TOP BAR of every page (03-11; 06-11: kit.js TopBar, one look everywhere): a conversation's, a room's, their
2388
2400
  settings', Assets', Access', Settings', the deck's, a new conversation's -- the same height, padding, type, button