clavarium 0.2.164-next.1 → 0.2.166-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.164-next.1",
3
+ "version": "0.2.166-next.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "clavarium",
9
- "version": "0.2.164-next.1",
9
+ "version": "0.2.166-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.164-next.1",
3
+ "version": "0.2.166-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/boxes.mjs CHANGED
@@ -26,6 +26,14 @@ export const SENTENCE_MAX = 15 * 32_000 + 32_000; /* 15 s of 16 kHz 16-bit
26
26
  export const ANSWER_MINUTES = 5; /* after a sentence, what the tool says is spoken */
27
27
  export const TRIES_PER_MINUTE = 10;
28
28
  export const NAME_MAX = 40;
29
+ /* Where a box in setup answers, on its own Wi-Fi: ESP-IDF's access point address, the same on
30
+ every box (written from its parts: it is no machine of anybody's). */
31
+ export const SETUP_ADDRESS = `http://${[192, 168, 4, 1].join('.')}/`;
32
+
33
+ /* The setup key: this server's address, the room, a pairing code -- one paste, or one link. */
34
+ export function setupKey(origin, room, code) {
35
+ return `GAMBELI-${Buffer.from(JSON.stringify({ u: origin, r: room, c: code })).toString('base64url')}`;
36
+ }
29
37
  const ALPHABET = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789'; /* nothing read two ways: no 0/O, 1/I */
30
38
 
31
39
  export const hashOf = (key) => createHash('sha256').update(String(key)).digest('hex');
@@ -244,7 +252,7 @@ export class Boxes {
244
252
 
245
253
  /* The operator's side, behind the sign-on:
246
254
  * GET /api/boxes the boxes, online or not
247
- * POST /api/boxes/code {conversation, name?} -> {code, minutes}
255
+ * POST /api/boxes/code {conversation, name?, origin?} -> {code, minutes, key?, link?, qr?}
248
256
  * POST /api/boxes/<id>/rename {name}
249
257
  * POST /api/boxes/<id>/move {conversation}
250
258
  * POST /api/boxes/<id>/revoke
@@ -254,7 +262,7 @@ export class Boxes {
254
262
  * POST /api/boxes/<id>/alert {text?}
255
263
  * POST /api/boxes/<id>/reboot
256
264
  */
257
- export async function handleBoxes(request, response, boxes, originOk, headers = {}) {
265
+ export async function handleBoxes(request, response, boxes, originOk, headers = {}, qr = null) {
258
266
  const { pathname } = new URL(request.url ?? '/', 'http://local');
259
267
  const send = (status, body) => { response.writeHead(status, { ...headers, 'content-type': 'application/json; charset=utf-8' }).end(JSON.stringify(body)); return true; };
260
268
  try {
@@ -264,7 +272,15 @@ export async function handleBoxes(request, response, boxes, originOk, headers =
264
272
  let text = '';
265
273
  for await (const piece of request) { text += piece; if (text.length > 8192) return send(413, { error: 'Too long.' }); }
266
274
  const body = text ? JSON.parse(text) : {};
267
- if (pathname === '/api/boxes/code') return send(201, boxes.code(String(body.conversation ?? ''), body.name));
275
+ if (pathname === '/api/boxes/code') {
276
+ const made = boxes.code(String(body.conversation ?? ''), body.name);
277
+ /* With this page's address: the key, and a link (its QR code) that opens the box's page filled in. */
278
+ const origin = /^https?:\/\/[^/\s]+$/.test(String(body.origin ?? '')) ? String(body.origin) : '';
279
+ if (!origin) return send(201, made);
280
+ const key = setupKey(origin, String(body.name ?? '').trim().slice(0, NAME_MAX), made.code);
281
+ const link = `${SETUP_ADDRESS}?k=${key}`;
282
+ return send(201, { ...made, key, link, qr: qr ? await qr(link) : undefined });
283
+ }
268
284
  const m = /^\/api\/boxes\/([0-9a-f-]{36})\/([a-z-]+)$/.exec(pathname);
269
285
  if (!m) return false;
270
286
  const [, id, what] = m;
package/server/main.mjs CHANGED
@@ -220,7 +220,7 @@ function serve(port, conversations, resources, { gate = () => 'local', originOk,
220
220
  response.writeHead(403, { ...HEADERS, 'content-type': 'text/plain; charset=utf-8' }).end(REFUSED);
221
221
  return;
222
222
  }
223
- if (boxes && pathname.startsWith('/api/boxes') && await handleBoxes(request, response, boxes, originOk, HEADERS)) return;
223
+ if (boxes && pathname.startsWith('/api/boxes') && await handleBoxes(request, response, boxes, originOk, HEADERS, (text) => QRCode.toString(text, { type: 'svg', margin: 1, errorCorrectionLevel: 'M' }))) return;
224
224
  if (conversations && await handleApi(request, response, conversations, HEADERS, resources, originOk, shortcuts, voice, sharing, secrets, network, signin, mailboxes, gitReview, platform, answerer, wakeups, alerts, talk, gitAccess, gitKeeper, shelf, health, setup, repair, guide, capacity, updates, instance, certificate, team, reacting, machinesMove, serverLogs, history, events, bundles, wifi, binders, meshcentral, tethers, accounts, groups)) return;
225
225
  if (pathname === '/manifest.webmanifest' && request.method === 'GET') { sendManifest(response, request.url); return; }
226
226
  const file = FILES[pathname];
package/web/app.js CHANGED
@@ -5269,6 +5269,8 @@
5269
5269
  $('map-new-device').addEventListener('click', () => { void openCompose(accessFor ? [[`conversation:${accessFor}`, partsFor(accessFor)]] : []); });
5270
5270
  /* Every device and what each was given, by device or by thing: a step over the map. */
5271
5271
  $('map-all-devices').addEventListener('click', () => { void openAccessPage('devices'); });
5272
+ /* Voice boxes are on the page of all devices: opened there, at them. */
5273
+ $('map-voice-boxes').addEventListener('click', async () => { await openAccessPage('devices'); $('boxes')?.scrollIntoView({ block: 'start' }); });
5272
5274
  $('share-manage-close').addEventListener('click', () => { if (!nav.close('sub')) void openAccessPage('map', { push: false }); });
5273
5275
  $('nav-settings').addEventListener('click', () => { if (place !== 'settings') void openSettings(); });
5274
5276
  $('access-close').addEventListener('click', () => leavePlace());
@@ -8816,16 +8818,24 @@
8816
8818
  });
8817
8819
  const remove = el('button', '', 'Remove'); remove.type = 'button';
8818
8820
  remove.addEventListener('click', () => takeBack(remove, `Remove ${b.name}: its key stops working now, and it goes back to its setup`, () => post(`${API}/boxes/${b.id}/revoke`)));
8819
- const acts = el('div', 'action-row'); acts.append(rename, remove);
8821
+ /* Its conversation: where what it hears is said, and whose answers it speaks. Changed here at any time. */
8822
+ const where = el('select'); where.setAttribute('aria-label', `Conversation of ${b.name}`);
8823
+ for (const c of conversations) { const o = el('option', '', shownName(c)); o.value = c.name; where.append(o); }
8824
+ where.value = b.conversation;
8825
+ where.addEventListener('change', async () => { await post(`${API}/boxes/${b.id}/move`, { conversation: where.value }).catch(() => {}); await paintBoxes(); });
8826
+ const whereRow = el('label', 'box-where'); whereRow.append('Speaks in ', where);
8827
+ const acts = el('div', 'action-row'); acts.append(whereRow, rename, remove);
8820
8828
  card.append(head, acts);
8821
8829
  rows.append(card);
8822
8830
  }
8823
8831
  }
8824
8832
  $('box-new').addEventListener('click', () => {
8825
8833
  const add = $('box-add'); add.hidden = !add.hidden;
8834
+ /* Which conversation it speaks in: chosen on purpose, never a silent default. */
8826
8835
  const pick = $('box-conversation'); pick.replaceChildren();
8836
+ const none = el('option', '', 'Choose a conversation...'); none.value = ''; pick.append(none);
8827
8837
  for (const c of conversations) { const o = el('option', '', shownName(c)); o.value = c.name; pick.append(o); }
8828
- if (accessFor && conversations.some((c) => c.name === accessFor)) pick.value = accessFor;
8838
+ pick.value = accessFor && conversations.some((c) => c.name === accessFor) ? accessFor : '';
8829
8839
  $('box-ready').hidden = true;
8830
8840
  });
8831
8841
  $('box-key-copy').addEventListener('click', async () => {
@@ -8835,12 +8845,13 @@
8835
8845
  setTimeout(() => { $('box-key-copy').textContent = 'Copy the key'; }, 2000);
8836
8846
  });
8837
8847
  $('box-code').addEventListener('click', async () => {
8848
+ if (!$('box-conversation').value) { $('box-conversation').focus(); $('box-code-minutes').textContent = 'Choose the conversation it speaks in first.'; $('box-ready').hidden = false; return; }
8838
8849
  try {
8839
- const r = await post(`${API}/boxes/code`, { conversation: $('box-conversation').value, name: $('box-room').value.trim() });
8850
+ const r = await post(`${API}/boxes/code`, { conversation: $('box-conversation').value, name: $('box-room').value.trim(), origin: location.origin });
8840
8851
  $('box-code-shown').textContent = r.code; $('box-code-minutes').textContent = `valid ${r.minutes} minutes, once`;
8841
- /* One paste instead of three fields on the box's page: this address, the room, the code. */
8842
- const json = JSON.stringify({ u: location.origin, r: $('box-room').value.trim(), c: r.code });
8843
- $('box-key').textContent = `GAMBELI-${btoa(unescape(encodeURIComponent(json))).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '')}`;
8852
+ $('box-key').textContent = r.key ?? '';
8853
+ $('box-link').href = r.link ?? '#';
8854
+ $('box-qr').innerHTML = r.qr ?? '';
8844
8855
  $('box-ready').hidden = false;
8845
8856
  } catch (error) { $('box-code-minutes').textContent = error.message; $('box-ready').hidden = false; }
8846
8857
  });
package/web/index.html CHANGED
@@ -379,6 +379,7 @@
379
379
  </div>
380
380
  <label class="lk-switch"><input type="checkbox" id="links-all"> All links at once</label>
381
381
  <button type="button" id="map-all-devices" class="as-link">All devices</button>
382
+ <button type="button" id="map-voice-boxes" class="as-link">Voice boxes</button>
382
383
  <button type="button" id="map-new-device">+ New device</button>
383
384
  </div>
384
385
  <!-- THE MAP (once "Who gets what"): every device, conversation and asset, and the rights between them (links.js). -->
@@ -462,10 +463,10 @@
462
463
  <button type="button" id="box-code" class="primary">Get a code</button>
463
464
  </div>
464
465
  <div id="box-ready" hidden>
465
- <p>Setup key <span class="hint" id="box-code-minutes"></span></p>
466
- <div class="row"><code id="box-key" class="box-key"></code><button type="button" id="box-key-copy" class="primary">Copy the key</button></div>
467
- <p class="hint">Or the pairing code alone: <b id="box-code-shown"></b></p>
468
- <p class="hint">Hold the box's button 5 s, join its Wi-Fi « Gambeli-… » with a phone, choose your Wi-Fi and paste this key. A new box: ask the assistant of its conversation to flash it; you plug it in here when it asks.</p>
466
+ <p class="hint">Phone on the box's Wi-Fi « Gambeli-… »: open this link, or scan the code. Its page opens filled in; choose your Wi-Fi. <span id="box-code-minutes"></span></p>
467
+ <div class="row box-setup"><div id="box-qr" class="box-qr"></div><a id="box-link" class="primary button-link" href="#">Open the box's page</a></div>
468
+ <div class="row"><code id="box-key" class="box-key"></code><button type="button" id="box-key-copy">Copy the key</button></div>
469
+ <p class="hint">Pairing code alone: <b id="box-code-shown"></b></p>
469
470
  </div>
470
471
  </div>
471
472
  <div id="box-list"></div>
package/web/style.css CHANGED
@@ -2071,3 +2071,7 @@ body.as-dragging #assets-rows .as-row { touch-action: none; }
2071
2071
  .job-panel .tether-flash-extra { display: grid; gap: 8px; }
2072
2072
  .job-panel .tether-flash-bad { color: var(--bad, #ff8a80); }
2073
2073
  .box-key { overflow-wrap: anywhere; font-size: .8rem; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; user-select: all; flex: 1 1 260px; min-width: 0; }
2074
+ .box-setup { align-items: center; gap: 14px; flex-wrap: wrap; }
2075
+ .box-qr { width: 180px; max-width: 100%; background: #fff; border-radius: 8px; padding: 6px; }
2076
+ .box-qr svg { display: block; width: 100%; height: auto; }
2077
+ .button-link { display: inline-block; padding: 8px 12px; border-radius: 7px; background: var(--accent, #d4a64a); color: #111; font-weight: 600; text-decoration: none; }