clavarium 0.2.141-beta.1 → 0.2.142-beta.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 +6 -6
- package/package.json +2 -2
- package/server/api.mjs +19 -1
- package/server/boxes.mjs +10 -5
- package/server/catalog.mjs +48 -0
- package/server/main.mjs +6 -3
- package/web/app.js +54 -3
- package/web/index.html +10 -0
- package/web/style.css +8 -0
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.142-beta.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.142-beta.1",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
|
13
13
|
"@xterm/xterm": "^6.0.0",
|
|
14
14
|
"clavarium-binder": "0.1.58-next.1",
|
|
15
15
|
"clavarium-docket": "0.1.2-next.2",
|
|
16
|
-
"clavarium-parley": "0.17.
|
|
16
|
+
"clavarium-parley": "0.17.50-next.1",
|
|
17
17
|
"clavarium-tether": "0.1.0-next.48",
|
|
18
18
|
"mammoth": "1.13.0",
|
|
19
19
|
"mermaid": "11.17.2",
|
|
@@ -787,9 +787,9 @@
|
|
|
787
787
|
}
|
|
788
788
|
},
|
|
789
789
|
"node_modules/clavarium-parley": {
|
|
790
|
-
"version": "0.17.
|
|
791
|
-
"resolved": "https://registry.npmjs.org/clavarium-parley/-/clavarium-parley-0.17.
|
|
792
|
-
"integrity": "sha512-
|
|
790
|
+
"version": "0.17.50-next.1",
|
|
791
|
+
"resolved": "https://registry.npmjs.org/clavarium-parley/-/clavarium-parley-0.17.50-next.1.tgz",
|
|
792
|
+
"integrity": "sha512-0IcZLJ4uWqY393Zi7XEkIMzDHZsyCMw3ti9voB6nIuqzDBtsUf9Dy/wMT7y5kFBnU9cRZZqNMhoZNexOVnccBQ==",
|
|
793
793
|
"license": "MIT",
|
|
794
794
|
"bin": {
|
|
795
795
|
"parley": "bin/parley.mjs",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.142-beta.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.",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"@xterm/xterm": "^6.0.0",
|
|
47
47
|
"clavarium-binder": "0.1.58-next.1",
|
|
48
48
|
"clavarium-docket": "0.1.2-next.2",
|
|
49
|
-
"clavarium-parley": "0.17.
|
|
49
|
+
"clavarium-parley": "0.17.50-next.1",
|
|
50
50
|
"clavarium-tether": "0.1.0-next.48",
|
|
51
51
|
"mammoth": "1.13.0",
|
|
52
52
|
"mermaid": "11.17.2",
|
package/server/api.mjs
CHANGED
|
@@ -133,6 +133,8 @@
|
|
|
133
133
|
* A request that changes something must come from this site's own pages: the
|
|
134
134
|
* Origin header is compared, and the body must be JSON, which a form on
|
|
135
135
|
* another site cannot send. */
|
|
136
|
+
import { openCodeConfig } from './catalog.mjs';
|
|
137
|
+
import { writeFileSync } from 'node:fs';
|
|
136
138
|
import { suggest } from './suggest.mjs';
|
|
137
139
|
import { sameOrigin } from './bridge.mjs';
|
|
138
140
|
import { Refusal, DISK_GB } from './conversations.mjs';
|
|
@@ -163,7 +165,7 @@ function readBody(request, max = BODY_MAX) {
|
|
|
163
165
|
/* This run of the server: a page's count of binder changes is of one run, and starts again with the next. */
|
|
164
166
|
const BOOT = Math.random().toString(36).slice(2, 10);
|
|
165
167
|
|
|
166
|
-
export async function handleApi(request, response, conversations, headers, resources, originOk = sameOrigin, 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) {
|
|
168
|
+
export async function handleApi(request, response, conversations, headers, resources, originOk = sameOrigin, 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, catalogue) {
|
|
167
169
|
const { pathname } = new URL(request.url ?? '/', 'http://local');
|
|
168
170
|
if (!pathname.startsWith('/api/')) return false;
|
|
169
171
|
let send = (status, body) => {
|
|
@@ -257,6 +259,8 @@ export async function handleApi(request, response, conversations, headers, resou
|
|
|
257
259
|
if (pathname === '/api/resources' && resources) return send(200, resources.list()), true;
|
|
258
260
|
if (pathname === '/api/shortcuts' && shortcuts) return send(200, shortcuts.list()), true;
|
|
259
261
|
if (pathname === '/api/secrets' && secrets) return send(200, secrets.list()), true;
|
|
262
|
+
/* The providers and models OpenCode knows (models.dev), for a conversation made with it (03-11). */
|
|
263
|
+
if (pathname === '/api/catalog/models' && catalogue) return send(200, { providers: await catalogue.providers() }), true;
|
|
260
264
|
/* The owner's asset groups (groups.mjs): a label and the asset ids each
|
|
261
265
|
holds. Distinct from /api/groups/* above, which are the conversation
|
|
262
266
|
list's folders. */
|
|
@@ -403,6 +407,20 @@ export async function handleApi(request, response, conversations, headers, resou
|
|
|
403
407
|
const made = conversations.create(body);
|
|
404
408
|
/* Its chat on from the start (02-11), unless asked otherwise ("More": Chat off); a work folder on the
|
|
405
409
|
machine's disk has no place for it. */
|
|
410
|
+
/* Made with OpenCode and its settings (03-11): its key given to it, and its model written where OpenCode
|
|
411
|
+
reads it (its work folder's opencode.json), once its machine is built. */
|
|
412
|
+
const oc = made.tool === 'opencode' && body?.opencode ? openCodeConfig(body.opencode) : null;
|
|
413
|
+
if (oc) {
|
|
414
|
+
const name = made.name; const until = Date.now() + 30 * 60_000;
|
|
415
|
+
const setUp = async () => {
|
|
416
|
+
const c = conversations.list().find((x) => x.name === name);
|
|
417
|
+
if (!c || Date.now() > until) return;
|
|
418
|
+
if (c.phase !== 'ready') { setTimeout(() => { void setUp(); }, 2000).unref?.(); return; }
|
|
419
|
+
try { secrets?.attach(name, String(body.opencode.secret), true); await secrets?.deliver(name).catch(() => {}); } catch { /* given from its settings */ }
|
|
420
|
+
try { const dir = resources.workFolder(name); writeFileSync(`${dir}/opencode.json`, `${JSON.stringify(oc, null, 2)}\n`, { flag: 'wx', mode: 0o644 }); } catch { /* one there already is kept */ }
|
|
421
|
+
};
|
|
422
|
+
void setUp();
|
|
423
|
+
}
|
|
406
424
|
if (body?.chat !== false && talk) {
|
|
407
425
|
/* Its work folder exists once it is built: the chat is put in then (a few minutes at most). */
|
|
408
426
|
const name = made.name; const until = Date.now() + 30 * 60_000;
|
package/server/boxes.mjs
CHANGED
|
@@ -180,6 +180,8 @@ export function soundOf(pcm) {
|
|
|
180
180
|
}
|
|
181
181
|
|
|
182
182
|
export const DOING_WITHIN_MS = 120_000;
|
|
183
|
+
export const CHAT_IN = /\b(?:mode conversation|on discute|discutons|let'?s (?:talk|chat))\b/i;
|
|
184
|
+
export const CHAT_OUT = /\b(?:merci,? c'est tout|c'est tout pour (?:moi|l'instant)|(?:fin|arr[eê]te|stop)\w*\b.{0,20}\b(?:conversation|[ée]couter)|that'?s all)\b/i;
|
|
183
185
|
export const TEST_SOUND = 'Test du son. Un, deux, trois. Si tu m\'entends, le son marche.';
|
|
184
186
|
export const TEST_MIC = 'Test du micro. Parle-moi, je t\'écoute.';
|
|
185
187
|
export const TEST_MIC_MS = 45_000;
|
|
@@ -566,10 +568,11 @@ export class Boxes {
|
|
|
566
568
|
const answering = l.heardAt && this.#now() - l.heardAt < ANSWER_WITHIN_MS;
|
|
567
569
|
const chatting = !doing && answering && this.#chatting(l);
|
|
568
570
|
const opening = chatting && !l.chat;
|
|
571
|
+
if (chatting && !l.chat) l.send({ t: 'chat', on: true });
|
|
569
572
|
if (chatting) l.chat = true;
|
|
570
573
|
/* SENTENCE BY SENTENCE: the first is said while the next ones are made -- the answer starts sooner
|
|
571
574
|
(31-10: a few seconds of silence before each answer). The box queues them, one after the other. */
|
|
572
|
-
const parts = sentencesOf(opening ? `
|
|
575
|
+
const parts = sentencesOf(opening ? `On discute. ${words}` : words);
|
|
573
576
|
let next = this.#speak(parts[0]);
|
|
574
577
|
for (const [i, part] of parts.entries()) {
|
|
575
578
|
let pcm;
|
|
@@ -662,7 +665,7 @@ export class Boxes {
|
|
|
662
665
|
/* Listened again, nobody spoke: a conversation ends there, in silence. */
|
|
663
666
|
sentence = null;
|
|
664
667
|
if (this.#tested(link, 'nothing')) { link.send({ t: 'cue', name: 'done' }); return; }
|
|
665
|
-
if (link.chat) this.#log(`voice box ${box.name}: conversation ended, nobody answered`);
|
|
668
|
+
if (link.chat) { this.#log(`voice box ${box.name}: conversation ended, nobody answered`); link.send({ t: 'chat', on: false }); }
|
|
666
669
|
link.chat = false; link.recent = [];
|
|
667
670
|
link.send({ t: 'cue', name: 'done' });
|
|
668
671
|
return;
|
|
@@ -773,13 +776,15 @@ export class Boxes {
|
|
|
773
776
|
link.relay = 0;
|
|
774
777
|
text = `(réponse entendue de l'appareil, pas de la personne) ${text}`;
|
|
775
778
|
}
|
|
776
|
-
try { await this.#say(box.conversation, text, { id: box.id, name: box.name, ...(box.place ? { place: box.place } : {}), why: `${link.why ? `${link.why} · ` : ''}${soundOf(pcm)}` }); } catch (error) { this.#log(`voice box ${box.name}: ${seconds} s heard and dictated, but not said in ${box.conversation} (${error.message})`); await lost("Pardon, je n'ai pas pu transmettre ta phrase. Tu peux répéter ?"); return; }
|
|
779
|
+
try { await this.#say(box.conversation, text, { id: box.id, name: box.name, ...(box.place ? { place: box.place } : {}), why: `${(link.chat || CHAT_IN.test(text)) && !CHAT_OUT.test(text) ? 'en conversation : réponse courte, parlée · ' : ''}${link.why ? `${link.why} · ` : ''}${soundOf(pcm)}` }); } catch (error) { this.#log(`voice box ${box.name}: ${seconds} s heard and dictated, but not said in ${box.conversation} (${error.message})`); await lost("Pardon, je n'ai pas pu transmettre ta phrase. Tu peux répéter ?"); return; }
|
|
777
780
|
this.#log(`voice box ${box.name}: ${seconds} s heard, said in ${box.conversation}`);
|
|
778
781
|
link.heardAt = this.#now();
|
|
779
782
|
if (WAITING_WORDS) this.#waitFor(link, text);
|
|
780
783
|
link.recent = [...(link.recent ?? []), link.heardAt];
|
|
781
|
-
|
|
782
|
-
|
|
784
|
+
/* CONVERSATION MODE (03-11, as he set it): in by « on discute » (or « mode conversation »), out by « merci,
|
|
785
|
+
c'est tout » (or « fin de la conversation »), or by nobody speaking after an answer. */
|
|
786
|
+
if (CHAT_IN.test(text) && !link.chat) { link.chat = true; link.send({ t: 'chat', on: true }); } /* its ring, its chime (0.1.46) */
|
|
787
|
+
if (CHAT_OUT.test(text) && link.chat) { link.chat = false; link.recent = []; link.send({ t: 'chat', on: false }); }
|
|
783
788
|
link.doingSaid = false;
|
|
784
789
|
}
|
|
785
790
|
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/* THE CATALOGUE OF MODELS (03-11): the providers and their models as OpenCode itself reads them -- models.dev,
|
|
2
|
+
* a public catalogue, not its code -- for a conversation made with OpenCode to be set up from here: a provider,
|
|
3
|
+
* one of its models, and the name of the key it reads. Read once a day at most; the last one kept for when
|
|
4
|
+
* the catalogue cannot be reached. */
|
|
5
|
+
import { readFileSync, writeFileSync, mkdirSync } from 'node:fs';
|
|
6
|
+
import { dirname } from 'node:path';
|
|
7
|
+
|
|
8
|
+
export const CATALOGUE_URL = 'https://models.dev/api.json';
|
|
9
|
+
export const CATALOGUE_TTL_MS = 24 * 3600_000;
|
|
10
|
+
const ID = /^[A-Za-z0-9][A-Za-z0-9._:/@-]{0,120}$/;
|
|
11
|
+
const ENV = /^[A-Z][A-Z0-9_]{0,63}$/;
|
|
12
|
+
|
|
13
|
+
/* models.dev's own shape -> [{ id, name, env, models: [{ id, name }] }], providers by name, models by name. */
|
|
14
|
+
export function providersOf(raw) {
|
|
15
|
+
if (!raw || typeof raw !== 'object') return [];
|
|
16
|
+
return Object.entries(raw).flatMap(([id, p]) => {
|
|
17
|
+
if (!ID.test(id) || !p || typeof p !== 'object') return [];
|
|
18
|
+
const env = (Array.isArray(p.env) ? p.env : []).map(String).filter((e) => ENV.test(e)).slice(0, 4);
|
|
19
|
+
const models = Object.entries(p.models ?? {}).flatMap(([mid, m]) => (ID.test(mid) ? [{ id: mid, name: String(m?.name ?? mid).slice(0, 80) }] : []))
|
|
20
|
+
.sort((a, b) => a.name.localeCompare(b.name));
|
|
21
|
+
return models.length ? [{ id, name: String(p.name ?? id).slice(0, 60), env, models }] : [];
|
|
22
|
+
}).sort((a, b) => a.name.localeCompare(b.name));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export class Catalogue {
|
|
26
|
+
#file; #fetch; #now; #got = null; #at = 0;
|
|
27
|
+
constructor({ file, fetcher = fetch, now = () => Date.now() }) { this.#file = file; this.#fetch = fetcher; this.#now = now; }
|
|
28
|
+
async providers() {
|
|
29
|
+
if (this.#got && this.#now() - this.#at < CATALOGUE_TTL_MS) return this.#got;
|
|
30
|
+
try {
|
|
31
|
+
const r = await this.#fetch(CATALOGUE_URL, { signal: AbortSignal.timeout(15_000), redirect: 'error' });
|
|
32
|
+
if (!r.ok) throw new Error(String(r.status));
|
|
33
|
+
const list = providersOf(await r.json());
|
|
34
|
+
if (!list.length) throw new Error('empty');
|
|
35
|
+
this.#got = list; this.#at = this.#now();
|
|
36
|
+
try { mkdirSync(dirname(this.#file), { recursive: true }); writeFileSync(this.#file, JSON.stringify(list)); } catch { /* kept in memory */ }
|
|
37
|
+
} catch {
|
|
38
|
+
if (!this.#got) { try { this.#got = JSON.parse(readFileSync(this.#file, 'utf8')); } catch { this.#got = []; } }
|
|
39
|
+
}
|
|
40
|
+
return this.#got;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/* What OpenCode reads in its work folder (opencode.json): the model chosen, its key read from the secret given. */
|
|
45
|
+
export function openCodeConfig({ provider, model, secret }) {
|
|
46
|
+
if (!ID.test(String(provider ?? '')) || !ID.test(String(model ?? '')) || !ENV.test(String(secret ?? ''))) return null;
|
|
47
|
+
return { $schema: 'https://opencode.ai/config.json', model: `${provider}/${model}`, provider: { [provider]: { options: { apiKey: `{env:${secret}}` } } } };
|
|
48
|
+
}
|
package/server/main.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Catalogue } from './catalog.mjs';
|
|
1
2
|
/* The server. Loopback only: what faces the internet is the edge in front of it.
|
|
2
3
|
*
|
|
3
4
|
* Two ways to run it:
|
|
@@ -172,7 +173,7 @@ const withoutTmux = (env) => Object.fromEntries(Object.entries(env).filter(([key
|
|
|
172
173
|
|
|
173
174
|
const REFUSED = 'This Clavarium belongs to someone else: your account is not one of its operators.\n';
|
|
174
175
|
|
|
175
|
-
function serve(port, conversations, resources, { gate = () => 'local', originOk, shortcuts, voice, sharing, door, secrets, network, signin, mailboxes, gitReview, platform, answerer, wakeups, alerts, talk, gitAccess, gitKeeper, shelf, health, setup, guide, repair, capacity, updates, instance = new Instance(), certificate, team, reacting, machinesMove, serverLogs, history, events, bundles, wifi, binders, meshcentral, tethers, accounts, groups, boxes } = {}) {
|
|
176
|
+
function serve(port, conversations, resources, { gate = () => 'local', originOk, shortcuts, voice, sharing, door, secrets, network, signin, mailboxes, gitReview, platform, answerer, wakeups, alerts, talk, gitAccess, gitKeeper, shelf, health, setup, guide, repair, capacity, updates, instance = new Instance(), certificate, team, reacting, machinesMove, serverLogs, history, events, bundles, wifi, binders, meshcentral, tethers, accounts, groups, boxes, catalogue } = {}) {
|
|
176
177
|
/* Its manifest carries the name of this Clavarium, or the one a device chose (instance.mjs). */
|
|
177
178
|
const sendManifest = (response, url) => response.writeHead(200, { ...HEADERS, 'content-type': 'application/manifest+json' }).end(instance.manifest(new URL(url ?? '/', 'http://local').searchParams.get('name') ?? undefined));
|
|
178
179
|
const sendFile = async (response, file) => {
|
|
@@ -233,7 +234,7 @@ function serve(port, conversations, resources, { gate = () => 'local', originOk,
|
|
|
233
234
|
return;
|
|
234
235
|
}
|
|
235
236
|
if (boxes && pathname.startsWith('/api/boxes') && await handleBoxes(request, response, boxes, originOk, HEADERS, (text) => QRCode.toString(text, { type: 'svg', margin: 1, errorCorrectionLevel: 'M' }))) return;
|
|
236
|
-
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;
|
|
237
|
+
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, catalogue)) return;
|
|
237
238
|
if (pathname === '/manifest.webmanifest' && request.method === 'GET') { sendManifest(response, request.url); return; }
|
|
238
239
|
const file = FILES[pathname];
|
|
239
240
|
if (!file || (request.method !== 'GET' && request.method !== 'HEAD')) {
|
|
@@ -286,6 +287,8 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
|
|
|
286
287
|
const grants = new Grants(new Store(`${dataDir}/grants.json`));
|
|
287
288
|
/* Folder-style boxes the owner drops assets into, to tidy the views and hand a whole box at once (groups.mjs). */
|
|
288
289
|
const groups = new Groups({ store: new Store(`${dataDir}/groups.json`) });
|
|
290
|
+
/* The providers and models OpenCode knows (models.dev), for a conversation set up from here (03-11). */
|
|
291
|
+
const catalogue = new Catalogue({ file: `${dataDir}/models-catalogue.json` });
|
|
289
292
|
/* What happened, in one dated list (events.mjs): the owner's actions, and what the server did by itself. */
|
|
290
293
|
const events = new Events({ file: `${dataDir}/events.log` });
|
|
291
294
|
const vault = new Vault(vaultKey ?? `${dataDir}/vault.key`);
|
|
@@ -638,7 +641,7 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
|
|
|
638
641
|
changed: () => { for (const c of all.list()) talk.speakers(c.name, boxes.speakersOf(c.name)); try { syncTargets(tethers.store(), boxes.all()); } catch (error) { console.error(`voice boxes in Tether: ${error.message}`); } },
|
|
639
642
|
speak: (text) => speech.speak(text),
|
|
640
643
|
log: (line) => events.add({ kind: 'server', text: line }) });
|
|
641
|
-
const { server, listening } = serve(port, all, folders, { gate, originOk, shortcuts, voice, sharing, door, secrets, network, signin, mailboxes, gitReview, platform, answerer, wakeups, alerts, talk, gitAccess, gitKeeper, shelf, health, setup, guide, capacity, updates, instance, certificate, team, reacting, machinesMove, serverLogs, history, events, wifi, binders, meshcentral, tethers, accounts, groups, boxes, bundles: new Bundles({ dir: `${dataDir}/imports`, folder: (name) => folders.folder(name) }), repair: (name) => repairTerminal(name) });
|
|
644
|
+
const { server, listening } = serve(port, all, folders, { gate, originOk, shortcuts, voice, sharing, door, secrets, network, signin, mailboxes, gitReview, platform, answerer, wakeups, alerts, talk, gitAccess, gitKeeper, shelf, health, setup, guide, capacity, updates, instance, certificate, team, reacting, machinesMove, serverLogs, history, events, wifi, binders, meshcentral, tethers, accounts, groups, boxes, catalogue, bundles: new Bundles({ dir: `${dataDir}/imports`, folder: (name) => folders.folder(name) }), repair: (name) => repairTerminal(name) });
|
|
642
645
|
server.on('close', () => { closing = true; stopBinders(); stopTethers(); clearInterval(historyTimer); clearInterval(secretsTimer); history.save(); stopVmWatch(); stopShelf(); stopHealth(); stopUpdates(); stopWatch(); clearInterval(mailTimer); clearInterval(restartTimer); clearInterval(expiryTimer); clearInterval(answerTimer); clearInterval(wakeTimer); clearInterval(docketTimer); dockets.stop(); clearInterval(gitTimer); talk.stop(); });
|
|
643
646
|
let closing = false;
|
|
644
647
|
boxes.attach(server, WebSocketServer);
|
package/web/app.js
CHANGED
|
@@ -1595,11 +1595,61 @@
|
|
|
1595
1595
|
b.addEventListener('click', () => {
|
|
1596
1596
|
chosenTool = t.id;
|
|
1597
1597
|
for (const other of box.children) other.setAttribute('aria-checked', String(other === b));
|
|
1598
|
-
paintNewMemory();
|
|
1598
|
+
paintNewMemory(); void paintOpenCode();
|
|
1599
1599
|
});
|
|
1600
1600
|
return b;
|
|
1601
1601
|
}));
|
|
1602
|
-
paintNewMemory();
|
|
1602
|
+
paintNewMemory(); void paintOpenCode();
|
|
1603
|
+
}
|
|
1604
|
+
/* OPENCODE SET UP HERE (03-11): a provider and one of its models from OpenCode's own catalogue (models.dev),
|
|
1605
|
+
its key one of the secrets (the one named as the provider reads it, when there is one) or a new one. */
|
|
1606
|
+
let ocProviders = null; let ocMode = 'set';
|
|
1607
|
+
const ocNew = '+';
|
|
1608
|
+
async function paintOpenCode() {
|
|
1609
|
+
const on = chosenTool === 'opencode';
|
|
1610
|
+
$('newconv-oc').hidden = !on;
|
|
1611
|
+
if (!on) return;
|
|
1612
|
+
if (!ocProviders) { try { ocProviders = (await (await fetch(`${API}/catalog/models`)).json()).providers ?? []; } catch { ocProviders = []; } }
|
|
1613
|
+
try { markSecrets(await (await fetch(`${API}/secrets`)).json()); } catch { /* the ones known */ }
|
|
1614
|
+
const prov = $('newconv-oc-provider');
|
|
1615
|
+
if (!prov.options.length) {
|
|
1616
|
+
prov.replaceChildren(...ocProviders.map((p) => { const o = el('option', '', p.name); o.value = p.id; return o; }));
|
|
1617
|
+
if (ocProviders.some((p) => p.id === 'mistral')) prov.value = 'mistral';
|
|
1618
|
+
}
|
|
1619
|
+
ocProvider();
|
|
1620
|
+
}
|
|
1621
|
+
function ocProvider() {
|
|
1622
|
+
const p = (ocProviders ?? []).find((x) => x.id === $('newconv-oc-provider').value);
|
|
1623
|
+
$('newconv-oc-model').replaceChildren(...(p?.models ?? []).map((m) => { const o = el('option', '', m.name); o.value = m.id; return o; }));
|
|
1624
|
+
const names = (secretsKnown ?? []).map((x) => x.name);
|
|
1625
|
+
const want = p?.env?.[0] ?? '';
|
|
1626
|
+
const key = $('newconv-oc-key');
|
|
1627
|
+
key.replaceChildren(...names.map((n) => { const o = el('option', '', `Secret: ${n}`); o.value = n; return o; }), Object.assign(el('option', '', want ? `+ New secret: ${want}` : '+ New secret'), { value: ocNew }));
|
|
1628
|
+
key.value = names.includes(want) ? want : ocNew;
|
|
1629
|
+
$('newconv-oc-new').hidden = key.value !== ocNew;
|
|
1630
|
+
}
|
|
1631
|
+
$('newconv-oc-provider').addEventListener('change', ocProvider);
|
|
1632
|
+
$('newconv-oc-key').addEventListener('change', () => { $('newconv-oc-new').hidden = $('newconv-oc-key').value !== ocNew; });
|
|
1633
|
+
for (const b of $('newconv-oc-mode').querySelectorAll('[data-m]')) b.addEventListener('click', () => {
|
|
1634
|
+
ocMode = b.dataset.m;
|
|
1635
|
+
for (const x of $('newconv-oc-mode').querySelectorAll('[data-m]')) x.setAttribute('aria-checked', String(x === b));
|
|
1636
|
+
$('newconv-oc-set').hidden = ocMode !== 'set'; $('newconv-oc-raw').hidden = ocMode === 'set';
|
|
1637
|
+
});
|
|
1638
|
+
/* -> { provider, model, secret } for the server, a new secret made first; null: nothing to set up. */
|
|
1639
|
+
async function openCodeChoice() {
|
|
1640
|
+
if (chosenTool !== 'opencode' || ocMode !== 'set') return null;
|
|
1641
|
+
const provider = $('newconv-oc-provider').value; const model = $('newconv-oc-model').value;
|
|
1642
|
+
if (!provider || !model) return null;
|
|
1643
|
+
let secret = $('newconv-oc-key').value;
|
|
1644
|
+
if (secret === ocNew) {
|
|
1645
|
+
const value = $('newconv-oc-value').value.trim();
|
|
1646
|
+
const p = (ocProviders ?? []).find((x) => x.id === provider);
|
|
1647
|
+
if (!value) throw new Error('Paste the API key, or choose « Install only ».');
|
|
1648
|
+
secret = p?.env?.[0] ?? `${provider.toUpperCase().replace(/[^A-Z0-9]+/g, '_')}_API_KEY`;
|
|
1649
|
+
await post(`${API}/secrets`, { name: secret, value });
|
|
1650
|
+
$('newconv-oc-value').value = '';
|
|
1651
|
+
}
|
|
1652
|
+
return { provider, model, secret };
|
|
1603
1653
|
}
|
|
1604
1654
|
for (const b of $('newconv-work').querySelectorAll('[data-work]')) {
|
|
1605
1655
|
b.addEventListener('click', () => { for (const other of $('newconv-work').querySelectorAll('[data-work]')) other.setAttribute('aria-checked', String(other === b)); });
|
|
@@ -1659,7 +1709,8 @@
|
|
|
1659
1709
|
newError('', '');
|
|
1660
1710
|
creating = true; $('newconv-create').disabled = true;
|
|
1661
1711
|
try {
|
|
1662
|
-
const
|
|
1712
|
+
const opencode = await openCodeChoice();
|
|
1713
|
+
const made = await post(`${API}/conversations`, { ...(opencode ? { opencode } : {}), title, ...(id ? { name: id } : {}), ...(group ? { group } : {}), tool: chosenTool, workOnDisk: newOnDisk(), ...(document.getElementById('newconv-chat')?.checked === false ? { chat: false } : {}), ...(memoryMb && memoryMb !== least ? { memoryMb } : {}), ...(cpus && cpus !== 1 ? { cpus } : {}), ...(diskGb && diskGb !== 8 ? { diskGb } : {}) });
|
|
1663
1714
|
$('newconv-name').value = ''; $('newconv-id').value = ''; $('newconv-id').placeholder = 'website-redesign'; $('newconv-group').value = '';
|
|
1664
1715
|
$('newconv-work').querySelector('[data-work="kept"]').click(); $('newconv-more').open = false; { const ch = document.getElementById('newconv-chat'); if (ch) ch.checked = true; }
|
|
1665
1716
|
await refresh();
|
package/web/index.html
CHANGED
|
@@ -1015,6 +1015,16 @@
|
|
|
1015
1015
|
<span class="sub-head">Tool</span>
|
|
1016
1016
|
<div id="newconv-tools" class="pick" role="radiogroup" aria-label="Tool"></div>
|
|
1017
1017
|
</div>
|
|
1018
|
+
<div class="nc-card" id="newconv-oc" hidden>
|
|
1019
|
+
<div class="seg" id="newconv-oc-mode" role="radiogroup" aria-label="OpenCode"><button type="button" role="radio" aria-checked="true" data-m="set">Install and set up</button><button type="button" role="radio" aria-checked="false" data-m="raw">Install only</button></div>
|
|
1020
|
+
<div id="newconv-oc-set" class="oc-set">
|
|
1021
|
+
<label>Provider<select id="newconv-oc-provider"></select></label>
|
|
1022
|
+
<label>Model<select id="newconv-oc-model"></select></label>
|
|
1023
|
+
<label>API key<select id="newconv-oc-key"></select></label>
|
|
1024
|
+
<div id="newconv-oc-new" class="oc-new" hidden><input id="newconv-oc-value" type="password" autocomplete="off" placeholder="Paste the key"><small class="hint">Kept in your secrets, given to this conversation only.</small></div>
|
|
1025
|
+
</div>
|
|
1026
|
+
<small id="newconv-oc-raw" class="hint" hidden>Set it up yourself in its terminal.</small>
|
|
1027
|
+
</div>
|
|
1018
1028
|
<div class="nc-card">
|
|
1019
1029
|
<span class="sub-head">Its files</span>
|
|
1020
1030
|
<div id="newconv-work" class="pick two" role="radiogroup" aria-label="Its files">
|
package/web/style.css
CHANGED
|
@@ -2193,3 +2193,11 @@ body.as-dragging #assets-rows .as-row { touch-action: none; }
|
|
|
2193
2193
|
.deck-empty { text-align: center; padding: 48px 16px; color: var(--ink2); }
|
|
2194
2194
|
.deck-empty-acts { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 12px; }
|
|
2195
2195
|
@media (max-width: 520px) { .deck { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; } }
|
|
2196
|
+
|
|
2197
|
+
/* OpenCode set up from the new conversation (03-11). */
|
|
2198
|
+
#newconv-oc .seg { display: flex; flex-wrap: wrap; gap: 6px; }
|
|
2199
|
+
#newconv-oc .seg button[aria-checked="true"] { border-color: var(--brass); color: var(--brass-ink); }
|
|
2200
|
+
.oc-set { display: grid; gap: 10px; margin-top: 10px; }
|
|
2201
|
+
.oc-set label { display: grid; gap: 4px; font-weight: 600; font-size: .8125rem; }
|
|
2202
|
+
.oc-set select, .oc-new input { width: 100%; }
|
|
2203
|
+
.oc-new { display: grid; gap: 4px; }
|