clavarium 0.2.241-next.1 → 0.2.242-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,17 +1,17 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.241-next.1",
3
+ "version": "0.2.242-next.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "clavarium",
9
- "version": "0.2.241-next.1",
9
+ "version": "0.2.242-next.1",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@xterm/addon-fit": "^0.11.0",
13
13
  "@xterm/xterm": "^6.0.0",
14
- "clavarium-binder": "0.1.44-next.1",
14
+ "clavarium-binder": "0.1.45-next.1",
15
15
  "clavarium-docket": "0.1.1",
16
16
  "clavarium-parley": "0.17.35-next.1",
17
17
  "clavarium-tether": "0.1.0-next.46",
@@ -761,9 +761,9 @@
761
761
  }
762
762
  },
763
763
  "node_modules/clavarium-binder": {
764
- "version": "0.1.44-next.1",
765
- "resolved": "https://registry.npmjs.org/clavarium-binder/-/clavarium-binder-0.1.44-next.1.tgz",
766
- "integrity": "sha512-GJMZBnxneV0775Aeo2bSnKgB/QkeBjH+3oCxpdr3qX9CQgu5gMrPaRLbQdfp/Q5uZLjRScKRlxdqlFajvnqs8g==",
764
+ "version": "0.1.45-next.1",
765
+ "resolved": "https://registry.npmjs.org/clavarium-binder/-/clavarium-binder-0.1.45-next.1.tgz",
766
+ "integrity": "sha512-AYoQxohx6H8Z0bjs5wAiV0uPLlNFqWu+3hS/4WvJHSEKHCBIuTeYoT7I/cQIyUnuar42czUyyUx4+Xo/gY5EYA==",
767
767
  "license": "MIT",
768
768
  "bin": {
769
769
  "binder": "bin/binder.mjs",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.241-next.1",
3
+ "version": "0.2.242-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.",
@@ -44,7 +44,7 @@
44
44
  "dependencies": {
45
45
  "@xterm/addon-fit": "^0.11.0",
46
46
  "@xterm/xterm": "^6.0.0",
47
- "clavarium-binder": "0.1.44-next.1",
47
+ "clavarium-binder": "0.1.45-next.1",
48
48
  "clavarium-docket": "0.1.1",
49
49
  "clavarium-parley": "0.17.35-next.1",
50
50
  "clavarium-tether": "0.1.0-next.46",
package/server/api.mjs CHANGED
@@ -14,6 +14,7 @@
14
14
  * POST /api/conversations/<name>/health/seen what it says now no longer calls its owner (Needs you)
15
15
  * POST /api/conversations/<name>/exit-report why its tool ended: { now (read in its machine, if it runs), last (kept at its end) }
16
16
  * POST /api/conversations/<name>/archive
17
+ * POST /api/binder/suggest {id}: at most three quick actions for that card -> {actions: [{key, label, why, on, ask?}]}
17
18
  * POST /api/mailboxes/<name>/live {smtp, email?}: that mailbox connected live too (send, move...), its password reused
18
19
  * POST /api/conversations/<name>/erase {confirm: <its name>}: deleted for good -- its machine and its work files
19
20
  * POST /api/conversations/<name>/rebuild {reset?, confirm?}: built again; reset (confirm: its name) for a working one too
@@ -119,7 +120,8 @@
119
120
  * GET /api/flows who gets what: devices, conversations, assets, the rights between them, the flows
120
121
  * POST /api/flows/name {around, name}: a flow named by the owner ('' gives it back its own)
121
122
  * POST /api/setup/export {flow?} -> {name, text}: the configuration as one file, never the data
122
- * POST /api/setup/preview {text, choices?}: what an import would do, said before anything is done
123
+ * POST /api/setup/preview {text, choices?}: what an import { suggest } from './suggest.mjs';
124
+ import would do, said before anything is done
123
125
  * POST /api/setup/import {text, choices?, bundle?}: made in the background; GET says how far it is
124
126
  * GET /api/setup/bundle?flow= the flow WITH the files of its folders, a .tar.gz (bundle.mjs) &stats=1: their sizes only
125
127
  * POST /api/setup/bundle the body IS such a file -> {id, text, folders}: then preview and import with {bundle: id}
@@ -399,6 +401,12 @@ export async function handleApi(request, response, conversations, headers, resou
399
401
  if (pathname === '/api/conversations') { await conversations.admit?.(body); return send(201, conversations.create(body)), true; }
400
402
  /* The lists: every answer is 200, a refusal said in it ({ ok: false, text }), as the keeper says it to a tool. */
401
403
  if (pathname === '/api/binder' && binders) return send(200, binders.act(body.op, body.args, identity)), true;
404
+ /* Quick actions on a card: suggested from its content (suggest.mjs), done by the page. */
405
+ if (pathname === '/api/binder/suggest' && binders) {
406
+ const got = binders.act('get', { id: String(body?.id ?? '') }, identity);
407
+ if (!got?.ok || !got.data?.record) return send(404, { error: 'No such card.' }), true;
408
+ return send(200, { actions: await suggest(got.data.record, got.data.list, { chat: voice?.chat?.() ?? null }) }), true;
409
+ }
402
410
  /* Who gets what, and a whole setup in one file: see setup.mjs. */
403
411
  if (pathname.startsWith('/api/setup/') || pathname === '/api/flows/name') {
404
412
  if (!setup) return send(404, { error: 'Not found.' }), true;
@@ -0,0 +1,62 @@
1
+ /* QUICK ACTIONS ON A CARD (02-11): at most three, from a FIXED catalogue -- so nothing is invented that the
2
+ * page cannot do. Rules first (a passed due date, a mail attached, a file attached), then, when the small
3
+ * fast chat model of the dictation service is set, its choice among the same keys, each with a short why.
4
+ * What is done with them is the page's: a change on the card itself (undone in a click), or a request to
5
+ * the assistant carrying it, in its chat (where the person follows and approves). Nothing leaves alone. */
6
+
7
+ export const CATALOGUE = Object.freeze({
8
+ done: { label: 'Mark it done', on: 'card' },
9
+ 'postpone-day': { label: 'Postpone to tomorrow', on: 'card' },
10
+ 'postpone-week': { label: 'Postpone a week', on: 'card' },
11
+ 'urgency-up': { label: 'More urgent', on: 'card' },
12
+ 'urgency-down': { label: 'Less urgent', on: 'card' },
13
+ 'reply-mail': { label: 'Draft the reply to the mail', on: 'agent', ask: 'Draft a reply to the mail attached to this card. Keep it as a draft: show it to me before anything is sent.' },
14
+ 'make-event': { label: 'Put it in the calendar', on: 'agent', ask: 'Create the calendar event this card speaks of (ask me before it is created).' },
15
+ split: { label: 'Split into smaller cards', on: 'agent', ask: 'Split this card into a few smaller cards, each one step, in the same binder.' },
16
+ summarise: { label: 'Summarise what is attached', on: 'agent', ask: 'Summarise what is attached to this card, in a note on it.' },
17
+ related: { label: 'Find related cards', on: 'agent', ask: 'Find the cards related to this one and attach them to it.' },
18
+ });
19
+ const KEYS = Object.keys(CATALOGUE);
20
+
21
+ /* Without a model: what the card plainly calls for. */
22
+ export function rulesFor(record, now = Date.now()) {
23
+ const out = [];
24
+ const attached = Array.isArray(record?.attached) ? record.attached : [];
25
+ if (record?.due && Date.parse(record.due) < now) out.push({ key: 'postpone-day', why: 'its due date has passed' });
26
+ if (attached.some((a) => a.kind === 'mail')) out.push({ key: 'reply-mail', why: 'a mail is attached' });
27
+ if (attached.some((a) => a.kind === 'file')) out.push({ key: 'summarise', why: 'files are attached' });
28
+ return out;
29
+ }
30
+
31
+ /* What a model answered, kept only when it is the catalogue's: three at most, no repeat, a short why. */
32
+ export function pickedOf(text) {
33
+ let list;
34
+ try { const t = String(text ?? ''); list = JSON.parse(t.slice(t.indexOf('['), t.lastIndexOf(']') + 1)); } catch { return []; }
35
+ if (!Array.isArray(list)) return [];
36
+ const seen = new Set(); const out = [];
37
+ for (const a of list) {
38
+ const key = String(a?.key ?? ''); if (!KEYS.includes(key) || seen.has(key)) continue;
39
+ seen.add(key); out.push({ key, why: String(a?.why ?? '').replace(/\s+/g, ' ').trim().slice(0, 60) });
40
+ if (out.length === 3) break;
41
+ }
42
+ return out;
43
+ }
44
+
45
+ /* The card in a few lines for the model: never more than it needs. */
46
+ export function cardText(record, list) {
47
+ const fields = Object.entries(record?.fields ?? {}).map(([k, v]) => `${k}=${v}`).join(', ');
48
+ const attached = (record?.attached ?? []).map((a) => `${a.kind}: ${String(a.title ?? a.ref ?? '').slice(0, 80)}`).join('; ');
49
+ return [`Binder: ${String(list?.title ?? '').slice(0, 80)}`, `Title: ${String(record?.title ?? '').slice(0, 200)}`,
50
+ record?.description ? `Description: ${String(record.description).slice(0, 1200)}` : '', record?.due ? `Due: ${record.due}` : '',
51
+ fields ? `Fields: ${fields}` : '', attached ? `Attached: ${attached}` : '', `Today: ${new Date().toISOString().slice(0, 10)}`].filter(Boolean).join('\n');
52
+ }
53
+
54
+ export const SUGGEST_SYSTEM = `You suggest quick actions for a to-do card. Choose AT MOST 3 keys from this list, the most useful first, only those that clearly fit the card: ${KEYS.map((k) => `${k} (${CATALOGUE[k].label})`).join(', ')}. Answer ONLY with JSON: [{"key": "...", "why": "a reason of 2 to 6 words, in the card's language"}]. No other text.`;
55
+
56
+ /* -> [{ key, label, why, on, ask? }] -- the model's choice when it answers, else the rules'. */
57
+ export async function suggest(record, list, { chat = null, now = Date.now() } = {}) {
58
+ let picked = [];
59
+ if (chat) { try { picked = pickedOf(await chat(SUGGEST_SYSTEM, cardText(record, list))); } catch { picked = []; } }
60
+ if (!picked.length) picked = rulesFor(record, now).slice(0, 3);
61
+ return picked.map((p) => ({ key: p.key, label: CATALOGUE[p.key].label, why: p.why, on: CATALOGUE[p.key].on, ...(CATALOGUE[p.key].ask ? { ask: CATALOGUE[p.key].ask } : {}) }));
62
+ }
package/server/voice.mjs CHANGED
@@ -219,6 +219,18 @@ export async function quickReaction(config, said, fetcher = fetch) {
219
219
  } catch { return null; }
220
220
  }
221
221
 
222
+ /* The same small fast model, for a short answer to a given instruction (quick actions on a card, 02-11). */
223
+ export async function quickChat(config, system, user, fetcher = fetch, { maxTokens = 160, timeoutMs = 6000 } = {}) {
224
+ if (!config?.key || !DIARIZES.test(String(config.url))) return null;
225
+ const base = String(config.url).replace(/\/audio\/transcriptions\/?$/, '');
226
+ const r = await fetcher(`${base}/chat/completions`, {
227
+ method: 'POST', redirect: 'error', headers: { 'content-type': 'application/json', authorization: `Bearer ${config.key}` }, signal: AbortSignal.timeout(timeoutMs),
228
+ body: JSON.stringify({ model: REACTION_MODEL, temperature: 0.2, max_tokens: maxTokens, messages: [{ role: 'system', content: system }, { role: 'user', content: String(user).slice(0, 3000) }] }),
229
+ });
230
+ if (!r.ok) return null;
231
+ return String((await r.json())?.choices?.[0]?.message?.content ?? '');
232
+ }
233
+
222
234
  /* ---------- THE ENGINE CHOSEN IN SETTINGS ----------
223
235
  * Settings > Dictation: a provider fills in the address and the model (both
224
236
  * may be changed); the key is one of the SECRETS already kept (Assets >
@@ -356,6 +368,12 @@ export class Dictation {
356
368
  const config = this.current();
357
369
  return config ? quickReaction(config, said, this.#fetcher) : null;
358
370
  }
371
+ /* null when no such model is set: the caller then does without. */
372
+ chat() {
373
+ const config = this.current();
374
+ if (!config?.key || !DIARIZES.test(String(config.url))) return null;
375
+ return (system, user) => quickChat(config, system, user, this.#fetcher);
376
+ }
359
377
  async transcribeParts(audio) {
360
378
  this.#fresh(this.#saved());
361
379
  const config = this.current();
package/web/app.js CHANGED
@@ -5245,11 +5245,41 @@
5245
5245
  },
5246
5246
  /* Where it is: a step of this page's Back (below). */
5247
5247
  place: at, onPlace: steps?.onPlace, onBack: steps?.onBack,
5248
+ /* ACT (02-11): quick actions suggested for a card (server/suggest.mjs); done here. */
5249
+ ...(DEVICE ? {} : { actions: (r, l) => cardActions(r, l, whose), discuss: (r, l) => discussCard(r, l, whose) }),
5248
5250
  });
5249
5251
  binderViews.add({ box: holder.firstElementChild, view });
5250
5252
  watchBinders();
5251
5253
  return view;
5252
5254
  }
5255
+ /* The conversation that carries a card: an assistant among its owners, else the one the binder is given to. */
5256
+ const carrierOf = (r, whose) => (r.owners ?? []).find((o) => o.startsWith('conversation:'))?.slice('conversation:'.length) || whose();
5257
+ const dayAfter = (days) => { const d = new Date(Date.now() + days * 86_400_000); return new Date(d.getTime() - d.getTimezoneOffset() * 60_000).toISOString().slice(0, 10); };
5258
+ async function cardActions(r, l, whose) {
5259
+ const got = await post(`${API}/binder/suggest`, { id: r.id }).catch(() => null);
5260
+ return (got?.actions ?? []).map((a) => ({ label: a.label, why: a.why, run: async () => {
5261
+ if (a.key === 'done') { const end = (l.states ?? []).find((x) => x.done); if (end) await binderCall('move', { id: r.id, state: end.id }); return; }
5262
+ if (a.key === 'postpone-day' || a.key === 'postpone-week') { await binderCall('edit', { id: r.id, due: dayAfter(a.key === 'postpone-day' ? 1 : 7) }); return; }
5263
+ if (a.key === 'urgency-up' || a.key === 'urgency-down') { const u = Number(r.fields?.urgence ?? 50); await binderCall('edit', { id: r.id, fields: { urgence: Math.max(0, Math.min(100, u + (a.key === 'urgency-up' ? 20 : -20))) } }); return; }
5264
+ /* Work for an assistant: asked in its chat, where the person follows and approves. */
5265
+ const name = carrierOf(r, whose);
5266
+ if (!name) return;
5267
+ await post(talkPath(name), { text: `Card #${r.id} « ${r.title} » (${l.title}): ${a.ask}` });
5268
+ if (toConversation(name)) goTab('chat');
5269
+ } }));
5270
+ }
5271
+ /* Discuss a card: its assistant's chat, the card named in what is being written -- the person finishes it. */
5272
+ function discussCard(r, l, whose) {
5273
+ const name = carrierOf(r, whose);
5274
+ if (!name || !toConversation(name)) return;
5275
+ goTab('chat');
5276
+ setTimeout(() => {
5277
+ const box = document.querySelector('#chat textarea.parley-box, textarea.parley-box');
5278
+ if (!box) return;
5279
+ box.value = `About card #${r.id} « ${r.title} » (${l.title}): `;
5280
+ box.dispatchEvent(new Event('input', { bubbles: true })); box.focus();
5281
+ }, 400);
5282
+ }
5253
5283
  /* A card's thing attached, of its conversation: that conversation shown first (from a place, or another one). */
5254
5284
  function toConversation(name) {
5255
5285
  if (!name || !conversations.some((c) => c.name === name)) return false;