clavarium 0.2.360-next.1 → 0.2.361-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.361-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.361-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.361-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/rooms.mjs CHANGED
@@ -92,6 +92,9 @@ export class Rooms {
92
92
  #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
93
  #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
94
  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) }; }); }
95
+ /* ITS AIs, as conversations (06-11): the names of the conversations of its AI members that are there now --
96
+ never a box, never the person, never one taken out of the room. What « give to all its AIs » gives to. */
97
+ ais(id) { return this.#shown(this.#find(id)).filter((m) => m.kind === 'ai').map((m) => m.ref); }
95
98
  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
99
 
97
100
  /* A new room: its name, its AIs (conversation names), its boxes (ids), and which AI is the host (the first by default). */
@@ -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