clavarium 0.2.404-next.1 → 0.2.406-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/server/conversations.mjs +35 -6
- package/web/app.js +4 -1
- package/web/index.html +1 -0
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.406-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.406-next.1",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
package/package.json
CHANGED
package/server/conversations.mjs
CHANGED
|
@@ -21,6 +21,11 @@ export const STOP_DELAY_MS = 60_000;
|
|
|
21
21
|
const STEP_MS = 15 * 60_000;
|
|
22
22
|
/* The door of a conversation in a shared machine (#221), put in the machine by the server. */
|
|
23
23
|
export const DOOR = new URL('../config/machine/clavarium-enter', import.meta.url);
|
|
24
|
+
/* The most programs one conversation may run in a shared machine. */
|
|
25
|
+
export const SHARED_PROCS = 1024;
|
|
26
|
+
/* A NEW SHARED MACHINE's memory (12-11, operator): chosen when it is made, 4 GB unless said; the conversations
|
|
27
|
+
that live in it share it, each within its own limit. */
|
|
28
|
+
export const SHARED_MB = 4096;
|
|
24
29
|
/* Moving a work folder: what must stay free after it, and how long a copy may take. */
|
|
25
30
|
export const ROOM_MB = 1024;
|
|
26
31
|
/* A file shown straight from a machine's disk: where, and how large at most. */
|
|
@@ -271,14 +276,15 @@ export class Conversations {
|
|
|
271
276
|
|
|
272
277
|
/* Whether a new machine may be made for this request: what `create`
|
|
273
278
|
checks, and the server's room (capacity.mjs). Asked before `create`. */
|
|
274
|
-
async admit({ name, title, tool, memoryMb, machine } = {}) {
|
|
279
|
+
async admit({ name, title, tool, memoryMb, machine, machineMb } = {}) {
|
|
275
280
|
if (!name && typeof title === 'string' && !titleProblem(title)) ({ name } = this.#naming({ title }));
|
|
276
281
|
/* Into a shared machine that is there already: no new machine, no room asked for it. */
|
|
277
|
-
if (typeof machine === 'string' && this.#
|
|
282
|
+
if (typeof machine === 'string' && this.#machineMbOf(machine) !== undefined) return;
|
|
278
283
|
const chosen = this.#tools.find((t) => t.id === tool);
|
|
279
284
|
/* What `create` refuses anyway is said by `create`. */
|
|
280
285
|
if (!chosen || !isConversationName(name) || this.#store.get(name)) return;
|
|
281
|
-
|
|
286
|
+
/* A new shared machine: the room it takes is its own size, not the conversation's. */
|
|
287
|
+
const memory = typeof machine === 'string' ? (machineMb ?? SHARED_MB) : (memoryMb ?? chosen.memoryMb);
|
|
282
288
|
if (!Number.isInteger(memory)) return;
|
|
283
289
|
await this.room({ kind: 'create', memoryMb: memory });
|
|
284
290
|
}
|
|
@@ -295,7 +301,15 @@ export class Conversations {
|
|
|
295
301
|
return { name: id, title: title !== undefined && title !== id ? title : undefined };
|
|
296
302
|
}
|
|
297
303
|
|
|
298
|
-
|
|
304
|
+
/* The size of a shared machine: what its first conversation made it with (each of its conversations carries
|
|
305
|
+
it); undefined while none lives in it. */
|
|
306
|
+
#machineMbOf(machine) {
|
|
307
|
+
const there = this.#store.all().filter((x) => x.sharedMachine === machine);
|
|
308
|
+
if (!there.length) return undefined;
|
|
309
|
+
return there.map((x) => x.machineMb).find(Number.isInteger) ?? Math.max(...there.map((x) => Number(x.memoryMb) || 0));
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
create({ name: given, title: read, tool, memoryMb, cpus, diskGb, workOnDisk, group, machine, machineMb }) {
|
|
299
313
|
const { name, title } = this.#naming({ name: given, title: read });
|
|
300
314
|
/* IN A SHARED MACHINE (#221), named: its work is always kept here (mounted into its place there). */
|
|
301
315
|
if (machine !== undefined && (typeof machine !== 'string' || !isConversationName(machine))) throw new Refusal(400, 'A machine name is 1 to 32 lower-case letters, digits or hyphens; it starts with a letter.');
|
|
@@ -313,9 +327,18 @@ export class Conversations {
|
|
|
313
327
|
if (!Number.isInteger(cores) || cores < 1 || cores > availableParallelism()) throw new Refusal(400, `Cores are 1 to ${availableParallelism()} (what this server has).`);
|
|
314
328
|
const disk = diskGb ?? DISK_GB;
|
|
315
329
|
if (!Number.isInteger(disk) || disk < DISK_GB || disk > DISK_MAX_GB) throw new Refusal(400, `Disk is ${DISK_GB} to ${DISK_MAX_GB} GB.`);
|
|
330
|
+
/* Its shared machine's size: chosen when it is made (4 GB unless said), then the same for all in it; a
|
|
331
|
+
conversation never asks more than its machine has. */
|
|
332
|
+
let size;
|
|
333
|
+
if (machine !== undefined) {
|
|
334
|
+
const there = this.#machineMbOf(machine);
|
|
335
|
+
size = there ?? machineMb ?? SHARED_MB;
|
|
336
|
+
if (there === undefined && (!Number.isInteger(size) || size < 1024 || size > 16384)) throw new Refusal(400, 'A shared machine has 1024 to 16384 MB of memory.');
|
|
337
|
+
if (memory > size) throw new Refusal(400, `The machine ${machine} has ${size} MB of memory: this conversation cannot have more (${memory} MB).`);
|
|
338
|
+
}
|
|
316
339
|
if (this.#store.get(name)) throw new Refusal(409, 'A conversation already has this name.');
|
|
317
340
|
const now = new Date().toISOString();
|
|
318
|
-
const conversation = { name, ...(title ? { title } : {}), ...(group ? { group } : {}), tool, memoryMb: memory, cpus: cores, diskGb: disk, fixed: FIXES, ...(machine ? { sharedMachine: machine } : {}), work: workOnDisk === true && !machine ? 'disk' : 'kept', phase: 'building', step: 'Starting the machine', createdAt: now, buildingSince: now, progress: buildProgress(now) };
|
|
341
|
+
const conversation = { name, ...(title ? { title } : {}), ...(group ? { group } : {}), tool, memoryMb: memory, cpus: cores, diskGb: disk, fixed: FIXES, ...(machine ? { sharedMachine: machine, machineMb: size } : {}), work: workOnDisk === true && !machine ? 'disk' : 'kept', phase: 'building', step: 'Starting the machine', createdAt: now, buildingSince: now, progress: buildProgress(now) };
|
|
319
342
|
/* A new one comes first in its folder (or first of those in none). */
|
|
320
343
|
const { order, groups } = this.#order();
|
|
321
344
|
this.#store.put(conversation);
|
|
@@ -426,7 +449,7 @@ export class Conversations {
|
|
|
426
449
|
let state = await this.#vms.state(name, { fresh: true }).catch(() => undefined);
|
|
427
450
|
if (state === undefined) {
|
|
428
451
|
this.#store.patch(name, { step: `Making the shared machine ${c.sharedMachine}` });
|
|
429
|
-
const launched = await this.#vms.launch(name, memoryMb);
|
|
452
|
+
const launched = await this.#vms.launch(name, Number.isInteger(c.machineMb) ? c.machineMb : memoryMb);
|
|
430
453
|
if (launched.code !== 0) return fail('The shared machine did not start', launched);
|
|
431
454
|
const sharing = await this.#vms.execMachine(name, [...SHARING_STEP], { timeoutMs: STEP_MS });
|
|
432
455
|
if (sharing.code !== 0) return fail('The shared machine could not be prepared for shared folders', sharing);
|
|
@@ -444,6 +467,11 @@ export class Conversations {
|
|
|
444
467
|
const [uid, gid] = String(me.stdout ?? '').trim().split('\n').map(Number);
|
|
445
468
|
if (me.code !== 0 || !Number.isInteger(uid) || !Number.isInteger(gid)) return fail('Its own user could not be made', me);
|
|
446
469
|
this.#store.patch(name, { machineUser: { uid, gid } });
|
|
470
|
+
/* Its limits, read by its door at each entry: the memory chosen for it, and a bound on its programs -- one
|
|
471
|
+
conversation that runs away never takes the machine from the others. */
|
|
472
|
+
const limits = await this.#vms.execMachine(name, ['sudo', '-n', 'install', '-D', '-m', '0644', '-o', 'root', '-g', 'root', '/dev/stdin', `/etc/clavarium/limits/${name}`],
|
|
473
|
+
{ input: `mem=${Number(c.memoryMb) || tool.memoryMb}\nprocs=${SHARED_PROCS}\n`, timeoutMs: STEP_MS });
|
|
474
|
+
if (limits.code !== 0) return fail('Its limits could not be set in the shared machine', limits);
|
|
447
475
|
const kept = await this.#vms.workMake(name);
|
|
448
476
|
const shown = kept.code === 0 ? await this.#vms.workMount(name, this.#uid, this.#gid) : kept;
|
|
449
477
|
if (shown.code !== 0) return fail('The work folder could not be shown in the shared machine', shown);
|
|
@@ -1695,6 +1723,7 @@ export class Conversations {
|
|
|
1695
1723
|
await this.#vms.execMachine(name, ['sudo', '-n', 'pkill', '-KILL', '-u', `c-${name}`], { timeoutMs: 30_000 }).catch(() => {});
|
|
1696
1724
|
await this.#vms.workUnmount(name).catch(() => {});
|
|
1697
1725
|
if (erase) await this.#vms.execMachine(name, ['sudo', '-n', 'userdel', '--remove', `c-${name}`], { timeoutMs: 60_000 }).catch(() => {});
|
|
1726
|
+
if (erase) await this.#vms.execMachine(name, ['sudo', '-n', 'rm', '-f', `/etc/clavarium/limits/${name}`], { timeoutMs: 30_000 }).catch(() => {});
|
|
1698
1727
|
}
|
|
1699
1728
|
await this.#vms.unshare(name).catch(() => {});
|
|
1700
1729
|
const last = others.length === 0;
|
package/web/app.js
CHANGED
|
@@ -2111,7 +2111,10 @@
|
|
|
2111
2111
|
const names = [...new Set(conversations.map((c) => c.sharedMachine).filter(Boolean))].sort();
|
|
2112
2112
|
$('machine-names').replaceChildren(...names.map((n) => Object.assign(document.createElement('option'), { value: n })));
|
|
2113
2113
|
if (shared && !$('newconv-machine').value && names.length) $('newconv-machine').value = names[0];
|
|
2114
|
+
/* A new shared machine: its memory chosen here (12-11); one that is there keeps its own. */
|
|
2115
|
+
$('newconv-machine-mb-row').hidden = !shared || names.includes($('newconv-machine').value.trim());
|
|
2114
2116
|
};
|
|
2117
|
+
$('newconv-machine').addEventListener('input', () => paintWhere());
|
|
2115
2118
|
for (const b of $('newconv-where').querySelectorAll('[data-where]')) {
|
|
2116
2119
|
b.addEventListener('click', () => { for (const other of $('newconv-where').querySelectorAll('[data-where]')) other.setAttribute('aria-checked', String(other === b)); paintWhere(); });
|
|
2117
2120
|
}
|
|
@@ -2171,7 +2174,7 @@
|
|
|
2171
2174
|
creating = true; $('newconv-create').disabled = true;
|
|
2172
2175
|
try {
|
|
2173
2176
|
const opencode = await openCodeChoice();
|
|
2174
|
-
const made = await post(`${API}/conversations`, { ...(opencode ? { opencode } : {}), title, ...(id ? { name: id } : {}), ...(group ? { group } : {}), tool: chosenTool, workOnDisk: newShared() ? false : newOnDisk(), ...(newShared() ? { machine: $('newconv-machine').value.trim() } : {}), ...(document.getElementById('newconv-chat')?.checked === false ? { chat: false } : {}), ...(memoryMb && memoryMb !== least ? { memoryMb } : {}), ...(cpus && cpus !== 1 ? { cpus } : {}), ...(diskGb && diskGb !== 8 ? { diskGb } : {}) });
|
|
2177
|
+
const made = await post(`${API}/conversations`, { ...(opencode ? { opencode } : {}), title, ...(id ? { name: id } : {}), ...(group ? { group } : {}), tool: chosenTool, workOnDisk: newShared() ? false : newOnDisk(), ...(newShared() ? { machine: $('newconv-machine').value.trim(), ...($('newconv-machine-mb-row').hidden ? {} : { machineMb: Number($('newconv-machine-mb').value) }) } : {}), ...(document.getElementById('newconv-chat')?.checked === false ? { chat: false } : {}), ...(memoryMb && memoryMb !== least ? { memoryMb } : {}), ...(cpus && cpus !== 1 ? { cpus } : {}), ...(diskGb && diskGb !== 8 ? { diskGb } : {}) });
|
|
2175
2178
|
$('newconv-name').value = ''; $('newconv-id').value = ''; $('newconv-id').placeholder = 'website-redesign'; $('newconv-group').value = '';
|
|
2176
2179
|
$('newconv-work').querySelector('[data-work="kept"]').click(); $('newconv-where').querySelector('[data-where="own"]').click(); $('newconv-machine').value = ''; $('newconv-more').open = false; { const ch = document.getElementById('newconv-chat'); if (ch) ch.checked = true; }
|
|
2177
2180
|
await refresh();
|
package/web/index.html
CHANGED
|
@@ -1442,6 +1442,7 @@
|
|
|
1442
1442
|
<button type="button" role="radio" data-where="shared" aria-checked="false"><b>A shared machine</b><small>Lighter. For assistants</small></button>
|
|
1443
1443
|
</div>
|
|
1444
1444
|
<div class="set-row" id="newconv-machine-row" hidden><div class="set-what"><label for="newconv-machine">Machine</label><small>An existing one, or a new name</small><span id="newconv-machine-error" class="err" role="alert" hidden></span></div><div class="set-control"><input id="newconv-machine" maxlength="32" list="machine-names" placeholder="assistants" spellcheck="false" autocapitalize="off" autocomplete="off"><datalist id="machine-names"></datalist></div></div>
|
|
1445
|
+
<div class="set-row" id="newconv-machine-mb-row" hidden><div class="set-what"><label for="newconv-machine-mb">Its memory</label><small>Shared by the conversations in it</small></div><div class="set-control"><select id="newconv-machine-mb"><option value="2048">2 GB</option><option value="4096" selected>4 GB</option><option value="6144">6 GB</option><option value="8192">8 GB</option><option value="12288">12 GB</option><option value="16384">16 GB</option></select></div></div>
|
|
1445
1446
|
</div>
|
|
1446
1447
|
<div class="nc-card" id="newconv-files-card">
|
|
1447
1448
|
<span class="sub-head">Its files</span>
|