clavarium 0.2.405-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 +27 -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
|
@@ -23,6 +23,9 @@ const STEP_MS = 15 * 60_000;
|
|
|
23
23
|
export const DOOR = new URL('../config/machine/clavarium-enter', import.meta.url);
|
|
24
24
|
/* The most programs one conversation may run in a shared machine. */
|
|
25
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;
|
|
26
29
|
/* Moving a work folder: what must stay free after it, and how long a copy may take. */
|
|
27
30
|
export const ROOM_MB = 1024;
|
|
28
31
|
/* A file shown straight from a machine's disk: where, and how large at most. */
|
|
@@ -273,14 +276,15 @@ export class Conversations {
|
|
|
273
276
|
|
|
274
277
|
/* Whether a new machine may be made for this request: what `create`
|
|
275
278
|
checks, and the server's room (capacity.mjs). Asked before `create`. */
|
|
276
|
-
async admit({ name, title, tool, memoryMb, machine } = {}) {
|
|
279
|
+
async admit({ name, title, tool, memoryMb, machine, machineMb } = {}) {
|
|
277
280
|
if (!name && typeof title === 'string' && !titleProblem(title)) ({ name } = this.#naming({ title }));
|
|
278
281
|
/* Into a shared machine that is there already: no new machine, no room asked for it. */
|
|
279
|
-
if (typeof machine === 'string' && this.#
|
|
282
|
+
if (typeof machine === 'string' && this.#machineMbOf(machine) !== undefined) return;
|
|
280
283
|
const chosen = this.#tools.find((t) => t.id === tool);
|
|
281
284
|
/* What `create` refuses anyway is said by `create`. */
|
|
282
285
|
if (!chosen || !isConversationName(name) || this.#store.get(name)) return;
|
|
283
|
-
|
|
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);
|
|
284
288
|
if (!Number.isInteger(memory)) return;
|
|
285
289
|
await this.room({ kind: 'create', memoryMb: memory });
|
|
286
290
|
}
|
|
@@ -297,7 +301,15 @@ export class Conversations {
|
|
|
297
301
|
return { name: id, title: title !== undefined && title !== id ? title : undefined };
|
|
298
302
|
}
|
|
299
303
|
|
|
300
|
-
|
|
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 }) {
|
|
301
313
|
const { name, title } = this.#naming({ name: given, title: read });
|
|
302
314
|
/* IN A SHARED MACHINE (#221), named: its work is always kept here (mounted into its place there). */
|
|
303
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.');
|
|
@@ -315,9 +327,18 @@ export class Conversations {
|
|
|
315
327
|
if (!Number.isInteger(cores) || cores < 1 || cores > availableParallelism()) throw new Refusal(400, `Cores are 1 to ${availableParallelism()} (what this server has).`);
|
|
316
328
|
const disk = diskGb ?? DISK_GB;
|
|
317
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
|
+
}
|
|
318
339
|
if (this.#store.get(name)) throw new Refusal(409, 'A conversation already has this name.');
|
|
319
340
|
const now = new Date().toISOString();
|
|
320
|
-
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) };
|
|
321
342
|
/* A new one comes first in its folder (or first of those in none). */
|
|
322
343
|
const { order, groups } = this.#order();
|
|
323
344
|
this.#store.put(conversation);
|
|
@@ -428,7 +449,7 @@ export class Conversations {
|
|
|
428
449
|
let state = await this.#vms.state(name, { fresh: true }).catch(() => undefined);
|
|
429
450
|
if (state === undefined) {
|
|
430
451
|
this.#store.patch(name, { step: `Making the shared machine ${c.sharedMachine}` });
|
|
431
|
-
const launched = await this.#vms.launch(name, memoryMb);
|
|
452
|
+
const launched = await this.#vms.launch(name, Number.isInteger(c.machineMb) ? c.machineMb : memoryMb);
|
|
432
453
|
if (launched.code !== 0) return fail('The shared machine did not start', launched);
|
|
433
454
|
const sharing = await this.#vms.execMachine(name, [...SHARING_STEP], { timeoutMs: STEP_MS });
|
|
434
455
|
if (sharing.code !== 0) return fail('The shared machine could not be prepared for shared folders', sharing);
|
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>
|