clavarium 0.2.330-next.1 → 0.2.331-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 +6 -6
- package/package.json +2 -2
- package/server/talk.mjs +23 -5
- package/server/tethers.mjs +45 -11
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.331-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.331-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
14
|
"clavarium-binder": "0.1.60-next.1",
|
|
15
15
|
"clavarium-docket": "0.1.2-next.2",
|
|
16
|
-
"clavarium-parley": "0.17.
|
|
16
|
+
"clavarium-parley": "0.17.71-next.1",
|
|
17
17
|
"clavarium-tether": "0.1.0-next.53",
|
|
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.71-next.1",
|
|
791
|
+
"resolved": "https://registry.npmjs.org/clavarium-parley/-/clavarium-parley-0.17.71-next.1.tgz",
|
|
792
|
+
"integrity": "sha512-98RGnKFb8sCl05HSzrWY7qCvlqBGY4wAL4kwNVKTO69d8F1x3++pLCHjyE8AXjKNNlt2BE5fCrxtbsu/BTsnLA==",
|
|
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.331-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.",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"@xterm/xterm": "^6.0.0",
|
|
47
47
|
"clavarium-binder": "0.1.60-next.1",
|
|
48
48
|
"clavarium-docket": "0.1.2-next.2",
|
|
49
|
-
"clavarium-parley": "0.17.
|
|
49
|
+
"clavarium-parley": "0.17.71-next.1",
|
|
50
50
|
"clavarium-tether": "0.1.0-next.53",
|
|
51
51
|
"mammoth": "1.13.0",
|
|
52
52
|
"mermaid": "11.17.2",
|
package/server/talk.mjs
CHANGED
|
@@ -179,6 +179,22 @@ const ACTIONS_MAX = 4;
|
|
|
179
179
|
const ACTION = /^[a-z]{1,20}(:[a-z0-9][a-z0-9._-]{0,63})?$/;
|
|
180
180
|
const REQUEST_MAX = 8000;
|
|
181
181
|
const OUTCOMES = ['yes', 'always', 'no', 'timeout', 'withdrawn', 'stopped'];
|
|
182
|
+
/* A LINE'S TEXT IN THE READER'S WORDS (Parley 0.17.71): plain text, or `{k, v, t}` -- a word of Parley's
|
|
183
|
+
dictionary, its values (text, a number, or such a word again), and `t`, the plain English an older screen
|
|
184
|
+
says. Kept bounded: `t` as long as a plain text may be; a word without its `t` is none. */
|
|
185
|
+
const WORD = /^[a-z0-9-]{1,60}$/;
|
|
186
|
+
function lineWords(x, max, depth = 0) {
|
|
187
|
+
if (typeof x === 'string') { const t = x.trim(); return t ? t.slice(0, max) : null; }
|
|
188
|
+
if (typeof x === 'number') return Number.isFinite(x) ? x : null;
|
|
189
|
+
if (!x || typeof x !== 'object' || Array.isArray(x) || depth > 3 || typeof x.k !== 'string' || !WORD.test(x.k)) return null;
|
|
190
|
+
const t = typeof x.t === 'string' ? x.t.trim().slice(0, max) : '';
|
|
191
|
+
if (!t) return null;
|
|
192
|
+
const v = x.v && typeof x.v === 'object' && !Array.isArray(x.v)
|
|
193
|
+
? Object.fromEntries(Object.entries(x.v).filter(([n]) => /^[a-z]{1,20}$/.test(n)).slice(0, 8).map(([n, y]) => [n, lineWords(y, EVENT_TEXT_MAX, depth + 1)]).filter(([, y]) => y !== null)) : null;
|
|
194
|
+
return { k: x.k, ...(v && Object.keys(v).length ? { v } : {}), t };
|
|
195
|
+
}
|
|
196
|
+
/* A line's text, topic or brief as given: text, or such a word; null when it says nothing. */
|
|
197
|
+
const lineSaid = (x, max) => lineWords(x && typeof x === 'object' ? x : String(x ?? ''), max);
|
|
182
198
|
/* Where the person's files go, in the bridge folder; one folder per file, named by an id. */
|
|
183
199
|
const FILES = 'files';
|
|
184
200
|
const ATTACHED = new RegExp(`^/work/\\${FOLDER}/${FILES}/([0-9a-f-]{36})/([^/]+)$`);
|
|
@@ -581,18 +597,20 @@ export class Talk {
|
|
|
581
597
|
line kept, or null. `actions`: ids the page maps to buttons. */
|
|
582
598
|
event(name, { kind, text, level, tone, topic, brief, actions = [], request, outcome } = {}) {
|
|
583
599
|
if (!Object.hasOwn(EVENT_LEVELS, kind)) throw new RangeError(`No such kind of event: ${kind}`);
|
|
584
|
-
const said =
|
|
585
|
-
if (
|
|
600
|
+
const said = lineSaid(text, EVENT_TEXT_MAX);
|
|
601
|
+
if (said === null) return null;
|
|
602
|
+
const group = lineSaid(topic, TOPIC_MAX);
|
|
603
|
+
const short = lineSaid(brief, BRIEF_MAX);
|
|
586
604
|
/* The owner's choice when there is one (stored only where it differs from the kind's own). */
|
|
587
605
|
const chosen = this.thread().levels[kind];
|
|
588
606
|
const line = {
|
|
589
607
|
/* Not `kind`: the page reads that of every message ('system' for these). */
|
|
590
608
|
event: kind,
|
|
591
|
-
text: said
|
|
609
|
+
text: said,
|
|
592
610
|
level: chosen !== EVENT_LEVELS[kind] ? chosen : LEVELS.includes(level) ? level : chosen,
|
|
593
611
|
...(TONES.includes(tone) ? { tone } : {}),
|
|
594
|
-
...(
|
|
595
|
-
...(
|
|
612
|
+
...(group !== null ? { topic: group } : {}),
|
|
613
|
+
...(short !== null ? { brief: short } : {}),
|
|
596
614
|
actions: (Array.isArray(actions) ? actions : []).filter((a) => typeof a === 'string' && ACTION.test(a)).slice(0, ACTIONS_MAX),
|
|
597
615
|
/* A request's card, as Parley draws it (demandes.mjs): plain data, bounded. */
|
|
598
616
|
...(request && typeof request === 'object' && !Array.isArray(request) && JSON.stringify(request).length <= REQUEST_MAX ? { request } : {}),
|
package/server/tethers.mjs
CHANGED
|
@@ -50,8 +50,41 @@ const NOTICE_HEADS = {
|
|
|
50
50
|
};
|
|
51
51
|
const NOTICE_INFO = /\.(delayed|later-late|sent-late)$/;
|
|
52
52
|
export const noticeHead = (kind) => NOTICE_HEADS[kind] ?? 'Later news';
|
|
53
|
+
/* The same head as a word of Parley's (notice-mail-bounced...), said in the reader's language. */
|
|
54
|
+
export const noticeWord = (kind) => (Object.hasOwn(NOTICE_HEADS, kind) ? { k: `notice-${kind.replace(/\./g, '-')}`, t: NOTICE_HEADS[kind] } : { k: 'notice-later', t: 'Later news' });
|
|
53
55
|
export const noticeWarns = (kind) => !NOTICE_INFO.test(String(kind ?? ''));
|
|
54
56
|
|
|
57
|
+
/* A LINE IN THE READER'S WORDS (Parley 0.17.71, as a request's card since 0.17.70, demandes.mjs): a word of
|
|
58
|
+
Parley's dictionary and its values, said by each screen in its own language; `t`, the plain English an
|
|
59
|
+
older screen says. Values that are data (a verb, a name, a reason, Tether's own sentence) stay as given. */
|
|
60
|
+
const said = (k, v, t) => ({ k, ...(v ? { v } : {}), t });
|
|
61
|
+
const TOPIC_REQUEST = Object.freeze({ k: 'line-topic-request', t: 'Request' });
|
|
62
|
+
const TOPIC_NOTICE = Object.freeze({ k: 'line-topic-notice', t: 'Later news' });
|
|
63
|
+
/* A call that ended without being done (not accepted): how it ended, by its outcome. */
|
|
64
|
+
const ENDED = {
|
|
65
|
+
no: ['line-refused', 'Refused'],
|
|
66
|
+
timeout: ['line-timeout', 'No answer in time'],
|
|
67
|
+
withdrawn: ['line-withdrawn', 'Withdrawn by the agent'],
|
|
68
|
+
stopped: ['line-stopped', 'Stopped'],
|
|
69
|
+
};
|
|
70
|
+
export function endedLine(verb, outcome) {
|
|
71
|
+
if (outcome === 'yes' || outcome === 'always') return said('line-accepted', { verb }, `Accepted: ${verb} — being done`);
|
|
72
|
+
const [k, head] = ENDED[outcome] ?? ['line-handled', 'Request handled'];
|
|
73
|
+
return said(k, { verb }, `${head}: ${verb}`);
|
|
74
|
+
}
|
|
75
|
+
export function resultLine(verb, error) {
|
|
76
|
+
if (error === undefined) return said('line-done', { verb }, `Done: ${verb}`);
|
|
77
|
+
const reason = String(error ?? '').trim();
|
|
78
|
+
return reason ? said('line-failed', { verb, reason }, `Failed: ${verb} — ${reason}`) : said('line-failed-plain', { verb }, `Failed: ${verb}`);
|
|
79
|
+
}
|
|
80
|
+
export function noticeLine(kind, target, text) {
|
|
81
|
+
const head = noticeWord(kind);
|
|
82
|
+
if (target && text) return said('line-notice', { head, target, text }, `${head.t} (${target}): ${text}`);
|
|
83
|
+
if (text) return said('line-notice-said', { head, text }, `${head.t}: ${text}`);
|
|
84
|
+
if (target) return said('line-notice-at', { head, target }, `${head.t} (${target})`);
|
|
85
|
+
return head;
|
|
86
|
+
}
|
|
87
|
+
|
|
55
88
|
export class Tethers {
|
|
56
89
|
#keeper; #resources; #conversations; #secrets; #dockets; #timers = []; #changes = 0; #seen = new Map(); #offered; #noticed; #ended = new Map(); #acting = [];
|
|
57
90
|
/* Set by the server once the thread is ready (main.mjs): (name, event) => talk.event(...).
|
|
@@ -106,7 +139,7 @@ export class Tethers {
|
|
|
106
139
|
/* `request`: the card Parley draws (demandes.mjs); the text and its buttons stay for an older screen. */
|
|
107
140
|
let request;
|
|
108
141
|
try { request = demandeView(r); } catch { request = undefined; }
|
|
109
|
-
try { this.announce(name, { kind: 'tether-demande', text: text || (r.verb ?? 'A Tether call'), topic:
|
|
142
|
+
try { this.announce(name, { kind: 'tether-demande', text: text || (r.verb ?? 'A Tether call'), topic: TOPIC_REQUEST, tone: 'warn', actions: [`allow:${r.id}`, `deny:${r.id}`], ...(request ? { request } : {}) }); } catch { /* its chat is off */ }
|
|
110
143
|
}
|
|
111
144
|
/* An approved call only the owner's browser can do (a device to flash): said once, with where to do it. */
|
|
112
145
|
let jobs = [];
|
|
@@ -118,7 +151,9 @@ export class Tethers {
|
|
|
118
151
|
if (!who.startsWith(AGENT)) continue;
|
|
119
152
|
const name = who.slice(AGENT.length);
|
|
120
153
|
this.#seen.set(j.id, { name, verb: j.verb });
|
|
121
|
-
|
|
154
|
+
const text = j.args?.name ? said('line-flash', { name: String(j.args.name) }, `To do in your browser: flash ${j.args.name}. Plug it in by USB here, then start.`)
|
|
155
|
+
: said('line-flash-device', undefined, 'To do in your browser: flash a device. Plug it in by USB here, then start.');
|
|
156
|
+
try { this.announce(name, { kind: 'tether-job', text, topic: TOPIC_REQUEST, tone: 'warn', actions: [`flash:${j.id}`] }); } catch { /* its chat is off */ }
|
|
122
157
|
}
|
|
123
158
|
for (const [id, info] of [...this.#seen]) {
|
|
124
159
|
if (live.has(id)) continue;
|
|
@@ -129,8 +164,8 @@ export class Tethers {
|
|
|
129
164
|
fail): said as being done, and its result said when Tether journals it (#tellResult). */
|
|
130
165
|
const accepted = outcome === 'yes' || outcome === 'always';
|
|
131
166
|
if (accepted) { this.#acting.push({ id, ...info }); if (this.#acting.length > ACTING_MAX) this.#acting.shift(); }
|
|
132
|
-
const text =
|
|
133
|
-
try { this.announce(info.name, { kind: 'tether-done', text, topic:
|
|
167
|
+
const text = endedLine(info.verb, outcome);
|
|
168
|
+
try { this.announce(info.name, { kind: 'tether-done', text, topic: TOPIC_REQUEST, brief: id, ...(outcome ? { outcome } : {}) }); } catch { /* its chat is off */ }
|
|
134
169
|
}
|
|
135
170
|
for (const id of [...this.#ended.keys()]) if (!this.#seen.has(id)) this.#ended.delete(id);
|
|
136
171
|
}
|
|
@@ -146,8 +181,8 @@ export class Tethers {
|
|
|
146
181
|
if (i < 0) return;
|
|
147
182
|
const [call] = this.#acting.splice(i, 1);
|
|
148
183
|
const failed = l.ok === false;
|
|
149
|
-
const text =
|
|
150
|
-
try { this.announce(call.name, { kind: 'tether-done', text, topic:
|
|
184
|
+
const text = resultLine(call.verb, failed ? (l.error ?? '') : undefined);
|
|
185
|
+
try { this.announce(call.name, { kind: 'tether-done', text, topic: TOPIC_REQUEST, ...(failed ? { tone: 'bad', level: 'needs-you' } : {}) }); } catch { /* its chat is off */ }
|
|
151
186
|
}
|
|
152
187
|
|
|
153
188
|
/* A NOTICE (Tether calls `notify`): said once in the thread of the conversation whose agent did it,
|
|
@@ -166,12 +201,11 @@ export class Tethers {
|
|
|
166
201
|
if (!Array.isArray(seen) || seen.includes(id)) return;
|
|
167
202
|
try { this.#noticed.set([...seen, id].slice(-NOTICES_MAX)); } catch { /* said anyway, this once */ }
|
|
168
203
|
const kind = String(n.kind ?? '');
|
|
169
|
-
const head = noticeHead(kind);
|
|
170
204
|
const warns = noticeWarns(kind);
|
|
171
|
-
|
|
172
|
-
const
|
|
173
|
-
const text =
|
|
174
|
-
try { this.announce?.(name, { kind: 'tether-notice', text, topic:
|
|
205
|
+
/* Clavarium's head and frame in the reader's words; Tether's own sentence as Tether wrote it. */
|
|
206
|
+
const line = noticeLine(kind, n.target?.title ? String(n.target.title) : '', String(n.text ?? '').trim());
|
|
207
|
+
const text = line.t;
|
|
208
|
+
try { this.announce?.(name, { kind: 'tether-notice', text: line, topic: TOPIC_NOTICE, ...(warns ? { tone: 'warn', level: 'needs-you' } : {}) }); } catch { /* its chat is off */ }
|
|
175
209
|
try {
|
|
176
210
|
if (this.#dockets?.on(name)) {
|
|
177
211
|
this.#dockets.post(name, { kind: 'tether-notice', text: `${text}${/[.!?]$/.test(text) ? '' : '.'} See more: tether notices.`,
|