@celljs/ta-glance 4.27.0 → 4.28.0
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/extension/index.mjs +188 -26
- package/package.json +3 -3
- package/web/index.js +211 -35
package/extension/index.mjs
CHANGED
|
@@ -113,7 +113,8 @@ var GlanceJson;
|
|
|
113
113
|
((GlanceJson) => {
|
|
114
114
|
const TRIES = 40;
|
|
115
115
|
const CONTROLS = { "\n": "\\n", "\r": "\\r", "\t": "\\t" };
|
|
116
|
-
|
|
116
|
+
const CURLY = "“”";
|
|
117
|
+
function parse(text) {
|
|
117
118
|
const source = text.trim().replace(/,\s*([}\]])/g, "$1");
|
|
118
119
|
if (!source) {
|
|
119
120
|
return;
|
|
@@ -121,16 +122,11 @@ var GlanceJson;
|
|
|
121
122
|
try {
|
|
122
123
|
return JSON.parse(source);
|
|
123
124
|
} catch {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
if (balanced === undefined || balanced.open.length || balanced.inString) {
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
125
|
+
const balanced = balance(source);
|
|
126
|
+
if (!balanced.open.length && !balanced.inString) {
|
|
129
127
|
try {
|
|
130
|
-
return JSON.parse(balanced.text);
|
|
131
|
-
} catch {
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
128
|
+
return JSON.parse(balanced.text.replace(/,\s*([}\]])/g, "$1"));
|
|
129
|
+
} catch {}
|
|
134
130
|
}
|
|
135
131
|
}
|
|
136
132
|
let end = source.length;
|
|
@@ -166,22 +162,49 @@ var GlanceJson;
|
|
|
166
162
|
const open = [];
|
|
167
163
|
let inString = false;
|
|
168
164
|
let escaped = false;
|
|
165
|
+
let last = "";
|
|
169
166
|
let out = "";
|
|
170
|
-
for (
|
|
167
|
+
for (let index = 0;index < text.length; index++) {
|
|
168
|
+
const char = text[index];
|
|
171
169
|
if (inString) {
|
|
172
170
|
if (escaped) {
|
|
173
171
|
escaped = false;
|
|
174
172
|
} else if (char === "\\") {
|
|
175
173
|
escaped = true;
|
|
176
|
-
} else if (char === '"') {
|
|
174
|
+
} else if (char === '"' || char === CURLY[1]) {
|
|
175
|
+
if (char === '"' && !ends(text, index)) {
|
|
176
|
+
out += "\\\"";
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
if (char === CURLY[1] && !ends(text, index)) {
|
|
180
|
+
out += char;
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
177
183
|
inString = false;
|
|
184
|
+
last = '"';
|
|
185
|
+
out += '"';
|
|
186
|
+
continue;
|
|
178
187
|
} else if (char < " ") {
|
|
179
188
|
out += CONTROLS[char] ?? `\\u${char.charCodeAt(0).toString(16).padStart(4, "0")}`;
|
|
180
189
|
continue;
|
|
181
190
|
}
|
|
182
|
-
|
|
191
|
+
out += char;
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
if (char <= " ") {
|
|
195
|
+
out += char;
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
const starts = char === '"' || CURLY.includes(char) || char === "{" || char === "[";
|
|
199
|
+
if (starts && /["}\]\w.]/.test(last)) {
|
|
200
|
+
out += ",";
|
|
201
|
+
}
|
|
202
|
+
if (char === '"' || CURLY.includes(char)) {
|
|
183
203
|
inString = true;
|
|
184
|
-
|
|
204
|
+
out += '"';
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
if (char === "{" || char === "[") {
|
|
185
208
|
open.push(char === "{" ? "}" : "]");
|
|
186
209
|
} else if (char === "}" || char === "]") {
|
|
187
210
|
if (open[open.length - 1] !== char) {
|
|
@@ -189,10 +212,20 @@ var GlanceJson;
|
|
|
189
212
|
}
|
|
190
213
|
open.pop();
|
|
191
214
|
}
|
|
215
|
+
last = char;
|
|
192
216
|
out += char;
|
|
193
217
|
}
|
|
194
218
|
return { text: out, open, inString, escaped };
|
|
195
219
|
}
|
|
220
|
+
function ends(text, index) {
|
|
221
|
+
for (let next = index + 1;next < text.length; next++) {
|
|
222
|
+
const char = text[next];
|
|
223
|
+
if (char > " ") {
|
|
224
|
+
return ",:}]".includes(char) || (char === '"' || CURLY.includes(char)) && /[\r\n]/.test(text.slice(index + 1, next));
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return true;
|
|
228
|
+
}
|
|
196
229
|
})(GlanceJson ||= {});
|
|
197
230
|
|
|
198
231
|
// web-src/glance-protocol.ts
|
|
@@ -232,6 +265,54 @@ var GLANCE_ICONS = [
|
|
|
232
265
|
"Sparkles"
|
|
233
266
|
];
|
|
234
267
|
|
|
268
|
+
// ../ta-protocol/esm/common/figure-protocol.js
|
|
269
|
+
var TaFigure;
|
|
270
|
+
(function(TaFigure2) {
|
|
271
|
+
TaFigure2.DEFAULT_LANGUAGE = "ta-plot";
|
|
272
|
+
function markdown(value) {
|
|
273
|
+
if (typeof value === "string") {
|
|
274
|
+
return value.trim() || undefined;
|
|
275
|
+
}
|
|
276
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
const keys = Object.keys(value);
|
|
280
|
+
const wrapped = keys.length === 1 && /^ta-[a-z0-9-]+$/.test(keys[0]);
|
|
281
|
+
const language = wrapped ? keys[0] : TaFigure2.DEFAULT_LANGUAGE;
|
|
282
|
+
const spec = wrapped ? value[language] : value;
|
|
283
|
+
return spec && typeof spec === "object" && Object.keys(spec).length ? `\`\`\`${language}
|
|
284
|
+
${JSON.stringify(spec)}
|
|
285
|
+
\`\`\`` : undefined;
|
|
286
|
+
}
|
|
287
|
+
TaFigure2.markdown = markdown;
|
|
288
|
+
})(TaFigure || (TaFigure = {}));
|
|
289
|
+
|
|
290
|
+
// web-src/glance-mermaid.ts
|
|
291
|
+
var SYNTAX = /[()[\]{}"<>|;#&@]/;
|
|
292
|
+
var NODE = /(^|[\s;&>|-])([\w\u00c0-\uffff]+)(?:\[(?!["[(/\\])(.*?)\]|\((?!["([])(.*?)\)|\{(?!["{])(.*?)\})(?=\s*(?:$|;|&|-|=|\.|~|<|:::))/g;
|
|
293
|
+
var GlanceMermaid;
|
|
294
|
+
((GlanceMermaid) => {
|
|
295
|
+
function repair(source) {
|
|
296
|
+
const body = source.trim().replace(/^\x60{3,}\s*mermaid[^\n]*\n/i, "").replace(/\n\x60{3,}\s*$/, "");
|
|
297
|
+
if (!/^\s*(?:graph|flowchart)\b/i.test(body)) {
|
|
298
|
+
return body;
|
|
299
|
+
}
|
|
300
|
+
return body.split(`
|
|
301
|
+
`).map((line) => line.replace(NODE, (whole, before, name, square, round, curly) => {
|
|
302
|
+
const label = square ?? round ?? curly ?? "";
|
|
303
|
+
const open = square !== undefined ? "[" : round !== undefined ? "(" : "{";
|
|
304
|
+
const close = square !== undefined ? "]" : round !== undefined ? ")" : "}";
|
|
305
|
+
const shown = label.replace(/\\n/g, "<br/>");
|
|
306
|
+
if (!SYNTAX.test(shown.replace(/<br\s*\/?>/gi, ""))) {
|
|
307
|
+
return shown === label ? whole : before + name + open + shown + close;
|
|
308
|
+
}
|
|
309
|
+
return before + name + open + '"' + shown.replace(/"/g, "#quot;") + '"' + close;
|
|
310
|
+
})).join(`
|
|
311
|
+
`);
|
|
312
|
+
}
|
|
313
|
+
GlanceMermaid.repair = repair;
|
|
314
|
+
})(GlanceMermaid ||= {});
|
|
315
|
+
|
|
235
316
|
// web-src/glance-spec.ts
|
|
236
317
|
var ITEMS = 12;
|
|
237
318
|
var FOLDED = 40;
|
|
@@ -397,9 +478,72 @@ function block(item, partial, labels) {
|
|
|
397
478
|
const words = fold === true ? "" : text(fold, 40);
|
|
398
479
|
return made && words !== undefined ? { ...made, fold: words } : made;
|
|
399
480
|
}
|
|
481
|
+
var KINDS = {
|
|
482
|
+
metrics: "stats",
|
|
483
|
+
metric: "stats",
|
|
484
|
+
kpi: "stats",
|
|
485
|
+
kpis: "stats",
|
|
486
|
+
numbers: "stats",
|
|
487
|
+
stat: "stats",
|
|
488
|
+
files: "changes",
|
|
489
|
+
diff: "changes",
|
|
490
|
+
change: "changes",
|
|
491
|
+
checklist: "steps",
|
|
492
|
+
todo: "steps",
|
|
493
|
+
todos: "steps",
|
|
494
|
+
tasks: "steps",
|
|
495
|
+
plan: "steps",
|
|
496
|
+
progress: "steps",
|
|
497
|
+
timeline: "steps",
|
|
498
|
+
step: "steps",
|
|
499
|
+
comparison: "compare",
|
|
500
|
+
bar: "bars",
|
|
501
|
+
chart: "bars",
|
|
502
|
+
pie: "share",
|
|
503
|
+
donut: "share",
|
|
504
|
+
trend: "line",
|
|
505
|
+
path: "flow",
|
|
506
|
+
process: "flow",
|
|
507
|
+
pipeline: "flow",
|
|
508
|
+
mermaid: "diagram",
|
|
509
|
+
graph: "diagram",
|
|
510
|
+
choices: "options",
|
|
511
|
+
choice: "options",
|
|
512
|
+
poll: "options",
|
|
513
|
+
question: "options",
|
|
514
|
+
list: "notes",
|
|
515
|
+
bullets: "notes",
|
|
516
|
+
points: "notes",
|
|
517
|
+
risks: "notes",
|
|
518
|
+
warnings: "notes",
|
|
519
|
+
note: "notes",
|
|
520
|
+
text: "notes",
|
|
521
|
+
summary: "notes",
|
|
522
|
+
callout: "notes",
|
|
523
|
+
suggestions: "next",
|
|
524
|
+
actions: "next",
|
|
525
|
+
buttons: "next",
|
|
526
|
+
followups: "next",
|
|
527
|
+
markdown: "details",
|
|
528
|
+
detail: "details",
|
|
529
|
+
plot: "figure"
|
|
530
|
+
};
|
|
531
|
+
function mended(value, named, type) {
|
|
532
|
+
const list = [value.items, value.list, value.entries, value[named], value[type]].find(Array.isArray);
|
|
533
|
+
const words = text(value.text) ?? text(value.content) ?? text(value.body);
|
|
534
|
+
return {
|
|
535
|
+
...value,
|
|
536
|
+
...list ? { items: list } : type === "notes" && words ? { items: [words] } : {},
|
|
537
|
+
markdown: value.markdown ?? value.content ?? value.text ?? value.body,
|
|
538
|
+
mermaid: value.mermaid ?? value.code ?? value.source
|
|
539
|
+
};
|
|
540
|
+
}
|
|
400
541
|
function blockOf(item, partial, labels) {
|
|
401
|
-
const
|
|
402
|
-
const
|
|
542
|
+
const raw = object(item);
|
|
543
|
+
const named = typeof raw?.type === "string" ? raw.type.trim().toLowerCase().replace(/[\s_]+/g, "-") : undefined;
|
|
544
|
+
const kind = named && typeof raw?.mermaid === "string" ? "diagram" : named && (KINDS[named] ?? named);
|
|
545
|
+
const value = raw && named && kind ? mended(raw, named, kind) : raw;
|
|
546
|
+
const type = kind;
|
|
403
547
|
const unit = text(value?.unit, 16);
|
|
404
548
|
switch (type) {
|
|
405
549
|
case "stats": {
|
|
@@ -407,10 +551,10 @@ function blockOf(item, partial, labels) {
|
|
|
407
551
|
return list.length ? { type, items: list, ...passed(list, CHECKS) ? { checks: true } : {} } : undefined;
|
|
408
552
|
}
|
|
409
553
|
case "changes": {
|
|
410
|
-
const
|
|
554
|
+
const raw2 = Array.isArray(value?.items) ? value.items : [];
|
|
411
555
|
const pathless = (entry) => typeof entry === "string" ? !isPath(entry) : !!object(entry) && !text(object(entry)?.path ?? object(entry)?.file);
|
|
412
|
-
if (
|
|
413
|
-
const list2 = items(
|
|
556
|
+
if (raw2.length && raw2.every(pathless)) {
|
|
557
|
+
const list2 = items(raw2, point);
|
|
414
558
|
return list2.length ? { type: "notes", items: list2 } : undefined;
|
|
415
559
|
}
|
|
416
560
|
const list = items(value?.items, change, FOLDED);
|
|
@@ -463,7 +607,7 @@ function blockOf(item, partial, labels) {
|
|
|
463
607
|
}
|
|
464
608
|
case "diagram": {
|
|
465
609
|
const mermaid = text(value?.mermaid, MARKDOWN);
|
|
466
|
-
return mermaid ? { type, mermaid } : undefined;
|
|
610
|
+
return mermaid ? { type, mermaid: GlanceMermaid.repair(mermaid) } : undefined;
|
|
467
611
|
}
|
|
468
612
|
case "table": {
|
|
469
613
|
const columns = items(value?.columns, (column) => text(column) ?? (typeof column === "string" ? "" : undefined), 6);
|
|
@@ -483,13 +627,28 @@ function blockOf(item, partial, labels) {
|
|
|
483
627
|
const list = items(value?.items, listItem).slice(0, 3);
|
|
484
628
|
return list.length ? { type, items: list } : undefined;
|
|
485
629
|
}
|
|
630
|
+
case "figure": {
|
|
631
|
+
const own = Object.fromEntries(Object.entries(raw ?? {}).filter(([key]) => key !== "type" && key !== "fold"));
|
|
632
|
+
const markdown = TaFigure.markdown(own.figure ?? own.markdown ?? own);
|
|
633
|
+
return markdown ? { type, markdown } : undefined;
|
|
634
|
+
}
|
|
486
635
|
case "details": {
|
|
487
636
|
const markdown = text(value?.markdown, MARKDOWN);
|
|
488
637
|
const title = text(value?.title);
|
|
489
638
|
return markdown ? { type, markdown, ...title ? { title } : {} } : undefined;
|
|
490
639
|
}
|
|
491
|
-
default:
|
|
492
|
-
|
|
640
|
+
default: {
|
|
641
|
+
const list = items(value?.items, point);
|
|
642
|
+
if (list.length) {
|
|
643
|
+
return { type: "notes", items: list };
|
|
644
|
+
}
|
|
645
|
+
const markdown = text(value?.markdown, MARKDOWN);
|
|
646
|
+
if (!markdown) {
|
|
647
|
+
return;
|
|
648
|
+
}
|
|
649
|
+
return markdown.length > TEXT || markdown.includes(`
|
|
650
|
+
`) ? { type: "details", markdown } : { type: "notes", items: [{ text: markdown, tone: "info" }] };
|
|
651
|
+
}
|
|
493
652
|
}
|
|
494
653
|
}
|
|
495
654
|
function loose(card) {
|
|
@@ -500,7 +659,8 @@ function loose(card) {
|
|
|
500
659
|
out.push({ type, items: entries, ...type === "options" ? { question: card.question } : {} });
|
|
501
660
|
}
|
|
502
661
|
}
|
|
503
|
-
|
|
662
|
+
const words = text(card.summary) ?? text(card.text) ?? text(card.message);
|
|
663
|
+
return out.length || !words ? out : [{ type: "notes", items: [words] }];
|
|
504
664
|
}
|
|
505
665
|
var LISTS = ["stats", "changes", "steps", "flow", "options", "notes", "next"];
|
|
506
666
|
var PLACE = { stats: -1, notes: 1, next: 2, details: 3 };
|
|
@@ -513,13 +673,14 @@ function placed(blocks) {
|
|
|
513
673
|
var GlanceSpec;
|
|
514
674
|
((GlanceSpec) => {
|
|
515
675
|
function read(value, partial = false, labels = LABELS) {
|
|
516
|
-
const card = object(value);
|
|
676
|
+
const card = Array.isArray(value) ? { blocks: value } : object(value);
|
|
517
677
|
if (!card) {
|
|
518
678
|
return;
|
|
519
679
|
}
|
|
520
680
|
const status = oneOf(card.status, STATUSES);
|
|
521
681
|
const title = text(card.title);
|
|
522
|
-
const
|
|
682
|
+
const written = Array.isArray(card.blocks) ? card.blocks : object(card.blocks) ? [card.blocks] : loose(card);
|
|
683
|
+
const blocks = placed(items(written, (entry) => block(entry, partial, labels)).slice(0, BLOCKS)).map((made) => made.type === "stats" && !made.checks && status && !QUIET.includes(status) && passed(made.items, 1) ? { ...made, checks: true } : made);
|
|
523
684
|
if (!blocks.length && !title) {
|
|
524
685
|
return;
|
|
525
686
|
}
|
|
@@ -545,7 +706,7 @@ var GlanceAsk;
|
|
|
545
706
|
let asked;
|
|
546
707
|
let asks = false;
|
|
547
708
|
for (const code of cards(reply)) {
|
|
548
|
-
const card = GlanceSpec.read(GlanceJson.parse(code
|
|
709
|
+
const card = GlanceSpec.read(GlanceJson.parse(code));
|
|
549
710
|
if (!card) {
|
|
550
711
|
continue;
|
|
551
712
|
}
|
|
@@ -629,6 +790,7 @@ Blocks, 1 to 3 of them, the most important first (Ta puts stats on top and notes
|
|
|
629
790
|
- {"type":"share","unit":"MB","items":[{"label":"pi","value":129},{"label":"ta","value":66}]}: the parts of a whole.
|
|
630
791
|
- {"type":"flow","items":["Request",{"text":"Gateway","icon":"Server"},"Session","Model"]}: a sequence or a path.
|
|
631
792
|
- {"type":"diagram","mermaid":"graph LR; A-->B"}: relations a flow cannot show, under 12 nodes.
|
|
793
|
+
- {"type":"figure","ta-plot":{…}}: a plot (or "ta-3d": a 3D figure) the card speaks of, the JSON of that block, drawn in the card.
|
|
632
794
|
- {"type":"table","columns":["",""],"rows":[["",""]]}: a few rows that compare things on several points, the first column naming each row (columns ["", "Before", "After"] for before and after in words); cells of a few words, never sentences, and no row for what is fine.
|
|
633
795
|
- {"type":"options","question":"Which one?","items":[{"label":"A","detail":"one line","pros":["..."],"cons":["..."],"recommended":true}]}: when the user must choose; each is a button that answers with its label. Add "multi": true when they may choose several. Several things to decide at once: an options block for each, in the same card; the user picks in all of them and sends the choices together.
|
|
634
796
|
- {"type":"notes","items":[{"text":"...","tone":"risk"}]}: risks, caveats, what the user must do, at most 3, a line each; tone risk | info | todo.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@celljs/ta-glance",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.28.0",
|
|
4
4
|
"description": "A pi package for Ta: replies lead with the answer, short, and show results as cards (key numbers, files, steps, comparisons, choices) rather than paragraphs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package"
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
"watch": "tsc -b -w --preserveWatchOutput"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@celljs/ta-protocol": "4.
|
|
30
|
-
"@celljs/ta-web": "4.
|
|
29
|
+
"@celljs/ta-protocol": "4.28.0",
|
|
30
|
+
"@celljs/ta-web": "4.28.0",
|
|
31
31
|
"@types/react": "^19.3.0"
|
|
32
32
|
},
|
|
33
33
|
"publishConfig": {
|
package/web/index.js
CHANGED
|
@@ -539,7 +539,8 @@ var GlanceJson;
|
|
|
539
539
|
((GlanceJson) => {
|
|
540
540
|
const TRIES = 40;
|
|
541
541
|
const CONTROLS = { "\n": "\\n", "\r": "\\r", "\t": "\\t" };
|
|
542
|
-
|
|
542
|
+
const CURLY = "“”";
|
|
543
|
+
function parse(text) {
|
|
543
544
|
const source = text.trim().replace(/,\s*([}\]])/g, "$1");
|
|
544
545
|
if (!source) {
|
|
545
546
|
return;
|
|
@@ -547,16 +548,11 @@ var GlanceJson;
|
|
|
547
548
|
try {
|
|
548
549
|
return JSON.parse(source);
|
|
549
550
|
} catch {
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
if (balanced === undefined || balanced.open.length || balanced.inString) {
|
|
553
|
-
return;
|
|
554
|
-
}
|
|
551
|
+
const balanced = balance(source);
|
|
552
|
+
if (!balanced.open.length && !balanced.inString) {
|
|
555
553
|
try {
|
|
556
|
-
return JSON.parse(balanced.text);
|
|
557
|
-
} catch {
|
|
558
|
-
return;
|
|
559
|
-
}
|
|
554
|
+
return JSON.parse(balanced.text.replace(/,\s*([}\]])/g, "$1"));
|
|
555
|
+
} catch {}
|
|
560
556
|
}
|
|
561
557
|
}
|
|
562
558
|
let end = source.length;
|
|
@@ -592,22 +588,49 @@ var GlanceJson;
|
|
|
592
588
|
const open = [];
|
|
593
589
|
let inString = false;
|
|
594
590
|
let escaped = false;
|
|
591
|
+
let last = "";
|
|
595
592
|
let out = "";
|
|
596
|
-
for (
|
|
593
|
+
for (let index = 0;index < text.length; index++) {
|
|
594
|
+
const char = text[index];
|
|
597
595
|
if (inString) {
|
|
598
596
|
if (escaped) {
|
|
599
597
|
escaped = false;
|
|
600
598
|
} else if (char === "\\") {
|
|
601
599
|
escaped = true;
|
|
602
|
-
} else if (char === '"') {
|
|
600
|
+
} else if (char === '"' || char === CURLY[1]) {
|
|
601
|
+
if (char === '"' && !ends(text, index)) {
|
|
602
|
+
out += "\\\"";
|
|
603
|
+
continue;
|
|
604
|
+
}
|
|
605
|
+
if (char === CURLY[1] && !ends(text, index)) {
|
|
606
|
+
out += char;
|
|
607
|
+
continue;
|
|
608
|
+
}
|
|
603
609
|
inString = false;
|
|
610
|
+
last = '"';
|
|
611
|
+
out += '"';
|
|
612
|
+
continue;
|
|
604
613
|
} else if (char < " ") {
|
|
605
614
|
out += CONTROLS[char] ?? `\\u${char.charCodeAt(0).toString(16).padStart(4, "0")}`;
|
|
606
615
|
continue;
|
|
607
616
|
}
|
|
608
|
-
|
|
617
|
+
out += char;
|
|
618
|
+
continue;
|
|
619
|
+
}
|
|
620
|
+
if (char <= " ") {
|
|
621
|
+
out += char;
|
|
622
|
+
continue;
|
|
623
|
+
}
|
|
624
|
+
const starts = char === '"' || CURLY.includes(char) || char === "{" || char === "[";
|
|
625
|
+
if (starts && /["}\]\w.]/.test(last)) {
|
|
626
|
+
out += ",";
|
|
627
|
+
}
|
|
628
|
+
if (char === '"' || CURLY.includes(char)) {
|
|
609
629
|
inString = true;
|
|
610
|
-
|
|
630
|
+
out += '"';
|
|
631
|
+
continue;
|
|
632
|
+
}
|
|
633
|
+
if (char === "{" || char === "[") {
|
|
611
634
|
open.push(char === "{" ? "}" : "]");
|
|
612
635
|
} else if (char === "}" || char === "]") {
|
|
613
636
|
if (open[open.length - 1] !== char) {
|
|
@@ -615,12 +638,70 @@ var GlanceJson;
|
|
|
615
638
|
}
|
|
616
639
|
open.pop();
|
|
617
640
|
}
|
|
641
|
+
last = char;
|
|
618
642
|
out += char;
|
|
619
643
|
}
|
|
620
644
|
return { text: out, open, inString, escaped };
|
|
621
645
|
}
|
|
646
|
+
function ends(text, index) {
|
|
647
|
+
for (let next = index + 1;next < text.length; next++) {
|
|
648
|
+
const char = text[next];
|
|
649
|
+
if (char > " ") {
|
|
650
|
+
return ",:}]".includes(char) || (char === '"' || CURLY.includes(char)) && /[\r\n]/.test(text.slice(index + 1, next));
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
return true;
|
|
654
|
+
}
|
|
622
655
|
})(GlanceJson ||= {});
|
|
623
656
|
|
|
657
|
+
// ../ta-protocol/esm/common/figure-protocol.js
|
|
658
|
+
var TaFigure;
|
|
659
|
+
(function(TaFigure2) {
|
|
660
|
+
TaFigure2.DEFAULT_LANGUAGE = "ta-plot";
|
|
661
|
+
function markdown(value) {
|
|
662
|
+
if (typeof value === "string") {
|
|
663
|
+
return value.trim() || undefined;
|
|
664
|
+
}
|
|
665
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
666
|
+
return;
|
|
667
|
+
}
|
|
668
|
+
const keys = Object.keys(value);
|
|
669
|
+
const wrapped = keys.length === 1 && /^ta-[a-z0-9-]+$/.test(keys[0]);
|
|
670
|
+
const language = wrapped ? keys[0] : TaFigure2.DEFAULT_LANGUAGE;
|
|
671
|
+
const spec = wrapped ? value[language] : value;
|
|
672
|
+
return spec && typeof spec === "object" && Object.keys(spec).length ? `\`\`\`${language}
|
|
673
|
+
${JSON.stringify(spec)}
|
|
674
|
+
\`\`\`` : undefined;
|
|
675
|
+
}
|
|
676
|
+
TaFigure2.markdown = markdown;
|
|
677
|
+
})(TaFigure || (TaFigure = {}));
|
|
678
|
+
|
|
679
|
+
// web-src/glance-mermaid.ts
|
|
680
|
+
var SYNTAX = /[()[\]{}"<>|;#&@]/;
|
|
681
|
+
var NODE = /(^|[\s;&>|-])([\w\u00c0-\uffff]+)(?:\[(?!["[(/\\])(.*?)\]|\((?!["([])(.*?)\)|\{(?!["{])(.*?)\})(?=\s*(?:$|;|&|-|=|\.|~|<|:::))/g;
|
|
682
|
+
var GlanceMermaid;
|
|
683
|
+
((GlanceMermaid) => {
|
|
684
|
+
function repair(source) {
|
|
685
|
+
const body = source.trim().replace(/^\x60{3,}\s*mermaid[^\n]*\n/i, "").replace(/\n\x60{3,}\s*$/, "");
|
|
686
|
+
if (!/^\s*(?:graph|flowchart)\b/i.test(body)) {
|
|
687
|
+
return body;
|
|
688
|
+
}
|
|
689
|
+
return body.split(`
|
|
690
|
+
`).map((line) => line.replace(NODE, (whole, before, name, square, round, curly) => {
|
|
691
|
+
const label = square ?? round ?? curly ?? "";
|
|
692
|
+
const open = square !== undefined ? "[" : round !== undefined ? "(" : "{";
|
|
693
|
+
const close = square !== undefined ? "]" : round !== undefined ? ")" : "}";
|
|
694
|
+
const shown = label.replace(/\\n/g, "<br/>");
|
|
695
|
+
if (!SYNTAX.test(shown.replace(/<br\s*\/?>/gi, ""))) {
|
|
696
|
+
return shown === label ? whole : before + name + open + shown + close;
|
|
697
|
+
}
|
|
698
|
+
return before + name + open + '"' + shown.replace(/"/g, "#quot;") + '"' + close;
|
|
699
|
+
})).join(`
|
|
700
|
+
`);
|
|
701
|
+
}
|
|
702
|
+
GlanceMermaid.repair = repair;
|
|
703
|
+
})(GlanceMermaid ||= {});
|
|
704
|
+
|
|
624
705
|
// web-src/glance-spec.ts
|
|
625
706
|
var ITEMS = 12;
|
|
626
707
|
var FOLDED = 40;
|
|
@@ -786,9 +867,72 @@ function block(item, partial, labels) {
|
|
|
786
867
|
const words = fold === true ? "" : text(fold, 40);
|
|
787
868
|
return made && words !== undefined ? { ...made, fold: words } : made;
|
|
788
869
|
}
|
|
870
|
+
var KINDS = {
|
|
871
|
+
metrics: "stats",
|
|
872
|
+
metric: "stats",
|
|
873
|
+
kpi: "stats",
|
|
874
|
+
kpis: "stats",
|
|
875
|
+
numbers: "stats",
|
|
876
|
+
stat: "stats",
|
|
877
|
+
files: "changes",
|
|
878
|
+
diff: "changes",
|
|
879
|
+
change: "changes",
|
|
880
|
+
checklist: "steps",
|
|
881
|
+
todo: "steps",
|
|
882
|
+
todos: "steps",
|
|
883
|
+
tasks: "steps",
|
|
884
|
+
plan: "steps",
|
|
885
|
+
progress: "steps",
|
|
886
|
+
timeline: "steps",
|
|
887
|
+
step: "steps",
|
|
888
|
+
comparison: "compare",
|
|
889
|
+
bar: "bars",
|
|
890
|
+
chart: "bars",
|
|
891
|
+
pie: "share",
|
|
892
|
+
donut: "share",
|
|
893
|
+
trend: "line",
|
|
894
|
+
path: "flow",
|
|
895
|
+
process: "flow",
|
|
896
|
+
pipeline: "flow",
|
|
897
|
+
mermaid: "diagram",
|
|
898
|
+
graph: "diagram",
|
|
899
|
+
choices: "options",
|
|
900
|
+
choice: "options",
|
|
901
|
+
poll: "options",
|
|
902
|
+
question: "options",
|
|
903
|
+
list: "notes",
|
|
904
|
+
bullets: "notes",
|
|
905
|
+
points: "notes",
|
|
906
|
+
risks: "notes",
|
|
907
|
+
warnings: "notes",
|
|
908
|
+
note: "notes",
|
|
909
|
+
text: "notes",
|
|
910
|
+
summary: "notes",
|
|
911
|
+
callout: "notes",
|
|
912
|
+
suggestions: "next",
|
|
913
|
+
actions: "next",
|
|
914
|
+
buttons: "next",
|
|
915
|
+
followups: "next",
|
|
916
|
+
markdown: "details",
|
|
917
|
+
detail: "details",
|
|
918
|
+
plot: "figure"
|
|
919
|
+
};
|
|
920
|
+
function mended(value, named, type) {
|
|
921
|
+
const list = [value.items, value.list, value.entries, value[named], value[type]].find(Array.isArray);
|
|
922
|
+
const words = text(value.text) ?? text(value.content) ?? text(value.body);
|
|
923
|
+
return {
|
|
924
|
+
...value,
|
|
925
|
+
...list ? { items: list } : type === "notes" && words ? { items: [words] } : {},
|
|
926
|
+
markdown: value.markdown ?? value.content ?? value.text ?? value.body,
|
|
927
|
+
mermaid: value.mermaid ?? value.code ?? value.source
|
|
928
|
+
};
|
|
929
|
+
}
|
|
789
930
|
function blockOf(item, partial, labels) {
|
|
790
|
-
const
|
|
791
|
-
const
|
|
931
|
+
const raw = object(item);
|
|
932
|
+
const named = typeof raw?.type === "string" ? raw.type.trim().toLowerCase().replace(/[\s_]+/g, "-") : undefined;
|
|
933
|
+
const kind = named && typeof raw?.mermaid === "string" ? "diagram" : named && (KINDS[named] ?? named);
|
|
934
|
+
const value = raw && named && kind ? mended(raw, named, kind) : raw;
|
|
935
|
+
const type = kind;
|
|
792
936
|
const unit = text(value?.unit, 16);
|
|
793
937
|
switch (type) {
|
|
794
938
|
case "stats": {
|
|
@@ -796,10 +940,10 @@ function blockOf(item, partial, labels) {
|
|
|
796
940
|
return list.length ? { type, items: list, ...passed(list, CHECKS) ? { checks: true } : {} } : undefined;
|
|
797
941
|
}
|
|
798
942
|
case "changes": {
|
|
799
|
-
const
|
|
943
|
+
const raw2 = Array.isArray(value?.items) ? value.items : [];
|
|
800
944
|
const pathless = (entry) => typeof entry === "string" ? !isPath(entry) : !!object(entry) && !text(object(entry)?.path ?? object(entry)?.file);
|
|
801
|
-
if (
|
|
802
|
-
const list2 = items(
|
|
945
|
+
if (raw2.length && raw2.every(pathless)) {
|
|
946
|
+
const list2 = items(raw2, point);
|
|
803
947
|
return list2.length ? { type: "notes", items: list2 } : undefined;
|
|
804
948
|
}
|
|
805
949
|
const list = items(value?.items, change, FOLDED);
|
|
@@ -852,7 +996,7 @@ function blockOf(item, partial, labels) {
|
|
|
852
996
|
}
|
|
853
997
|
case "diagram": {
|
|
854
998
|
const mermaid = text(value?.mermaid, MARKDOWN);
|
|
855
|
-
return mermaid ? { type, mermaid } : undefined;
|
|
999
|
+
return mermaid ? { type, mermaid: GlanceMermaid.repair(mermaid) } : undefined;
|
|
856
1000
|
}
|
|
857
1001
|
case "table": {
|
|
858
1002
|
const columns = items(value?.columns, (column) => text(column) ?? (typeof column === "string" ? "" : undefined), 6);
|
|
@@ -872,13 +1016,28 @@ function blockOf(item, partial, labels) {
|
|
|
872
1016
|
const list = items(value?.items, listItem).slice(0, 3);
|
|
873
1017
|
return list.length ? { type, items: list } : undefined;
|
|
874
1018
|
}
|
|
1019
|
+
case "figure": {
|
|
1020
|
+
const own = Object.fromEntries(Object.entries(raw ?? {}).filter(([key]) => key !== "type" && key !== "fold"));
|
|
1021
|
+
const markdown = TaFigure.markdown(own.figure ?? own.markdown ?? own);
|
|
1022
|
+
return markdown ? { type, markdown } : undefined;
|
|
1023
|
+
}
|
|
875
1024
|
case "details": {
|
|
876
1025
|
const markdown = text(value?.markdown, MARKDOWN);
|
|
877
1026
|
const title = text(value?.title);
|
|
878
1027
|
return markdown ? { type, markdown, ...title ? { title } : {} } : undefined;
|
|
879
1028
|
}
|
|
880
|
-
default:
|
|
881
|
-
|
|
1029
|
+
default: {
|
|
1030
|
+
const list = items(value?.items, point);
|
|
1031
|
+
if (list.length) {
|
|
1032
|
+
return { type: "notes", items: list };
|
|
1033
|
+
}
|
|
1034
|
+
const markdown = text(value?.markdown, MARKDOWN);
|
|
1035
|
+
if (!markdown) {
|
|
1036
|
+
return;
|
|
1037
|
+
}
|
|
1038
|
+
return markdown.length > TEXT || markdown.includes(`
|
|
1039
|
+
`) ? { type: "details", markdown } : { type: "notes", items: [{ text: markdown, tone: "info" }] };
|
|
1040
|
+
}
|
|
882
1041
|
}
|
|
883
1042
|
}
|
|
884
1043
|
function loose(card) {
|
|
@@ -889,7 +1048,8 @@ function loose(card) {
|
|
|
889
1048
|
out.push({ type, items: entries, ...type === "options" ? { question: card.question } : {} });
|
|
890
1049
|
}
|
|
891
1050
|
}
|
|
892
|
-
|
|
1051
|
+
const words = text(card.summary) ?? text(card.text) ?? text(card.message);
|
|
1052
|
+
return out.length || !words ? out : [{ type: "notes", items: [words] }];
|
|
893
1053
|
}
|
|
894
1054
|
var LISTS = ["stats", "changes", "steps", "flow", "options", "notes", "next"];
|
|
895
1055
|
var PLACE = { stats: -1, notes: 1, next: 2, details: 3 };
|
|
@@ -902,13 +1062,14 @@ function placed(blocks) {
|
|
|
902
1062
|
var GlanceSpec;
|
|
903
1063
|
((GlanceSpec) => {
|
|
904
1064
|
function read(value, partial = false, labels = LABELS) {
|
|
905
|
-
const card = object(value);
|
|
1065
|
+
const card = Array.isArray(value) ? { blocks: value } : object(value);
|
|
906
1066
|
if (!card) {
|
|
907
1067
|
return;
|
|
908
1068
|
}
|
|
909
1069
|
const status = oneOf(card.status, STATUSES);
|
|
910
1070
|
const title = text(card.title);
|
|
911
|
-
const
|
|
1071
|
+
const written = Array.isArray(card.blocks) ? card.blocks : object(card.blocks) ? [card.blocks] : loose(card);
|
|
1072
|
+
const blocks = placed(items(written, (entry) => block(entry, partial, labels)).slice(0, BLOCKS)).map((made) => made.type === "stats" && !made.checks && status && !QUIET.includes(status) && passed(made.items, 1) ? { ...made, checks: true } : made);
|
|
912
1073
|
if (!blocks.length && !title) {
|
|
913
1074
|
return;
|
|
914
1075
|
}
|
|
@@ -929,17 +1090,30 @@ function directory(path) {
|
|
|
929
1090
|
const trimmed = path.replace(/\/+$/, "");
|
|
930
1091
|
return trimmed.slice(0, Math.max(0, trimmed.lastIndexOf("/")));
|
|
931
1092
|
}
|
|
1093
|
+
var measuring = new Map;
|
|
1094
|
+
function measureClamp(node, set) {
|
|
1095
|
+
if (!measuring.size) {
|
|
1096
|
+
queueMicrotask(() => {
|
|
1097
|
+
const clamps = [...measuring];
|
|
1098
|
+
measuring.clear();
|
|
1099
|
+
const cuts = clamps.map(([one]) => one.isConnected && one.scrollHeight > one.clientHeight + 1);
|
|
1100
|
+
clamps.forEach(([, tell], index) => {
|
|
1101
|
+
tell(cuts[index]);
|
|
1102
|
+
});
|
|
1103
|
+
});
|
|
1104
|
+
}
|
|
1105
|
+
measuring.set(node, set);
|
|
1106
|
+
}
|
|
932
1107
|
function glanceCard(pi) {
|
|
933
1108
|
const icons = pi.ui.icons;
|
|
934
1109
|
const Markdown = pi.ui.Markdown;
|
|
935
1110
|
const Reply = React.createContext(undefined);
|
|
936
1111
|
const Answer = React.createContext({ known: false });
|
|
937
1112
|
function Text({ text: text2 }) {
|
|
938
|
-
return MARKS.test(text2) ? /* @__PURE__ */ React.createElement(
|
|
939
|
-
|
|
940
|
-
}, /* @__PURE__ */ React.createElement(Markdown, {
|
|
1113
|
+
return MARKS.test(text2) ? /* @__PURE__ */ React.createElement(Markdown, {
|
|
1114
|
+
inline: true,
|
|
941
1115
|
text: text2
|
|
942
|
-
})
|
|
1116
|
+
}) : text2;
|
|
943
1117
|
}
|
|
944
1118
|
function Clamp({ text: text2 }) {
|
|
945
1119
|
const ref = React.useRef(null);
|
|
@@ -948,7 +1122,7 @@ function glanceCard(pi) {
|
|
|
948
1122
|
React.useLayoutEffect(() => {
|
|
949
1123
|
const node = ref.current;
|
|
950
1124
|
if (node && !open) {
|
|
951
|
-
|
|
1125
|
+
measureClamp(node, setCut);
|
|
952
1126
|
}
|
|
953
1127
|
}, [text2, open]);
|
|
954
1128
|
const folds = cut || open;
|
|
@@ -1363,6 +1537,10 @@ ${block2.mermaid}
|
|
|
1363
1537
|
block: block2,
|
|
1364
1538
|
words
|
|
1365
1539
|
});
|
|
1540
|
+
case "figure":
|
|
1541
|
+
return closed ? /* @__PURE__ */ React.createElement(Markdown, {
|
|
1542
|
+
text: block2.markdown
|
|
1543
|
+
}) : null;
|
|
1366
1544
|
}
|
|
1367
1545
|
}
|
|
1368
1546
|
function Folded({ block: block2, words, closed }) {
|
|
@@ -1406,7 +1584,7 @@ ${block2.mermaid}
|
|
|
1406
1584
|
const answer = React.useMemo(() => ({ known, text: props.answer }), [known, props.answer]);
|
|
1407
1585
|
const words = GlanceWords.of(pi.ui.language);
|
|
1408
1586
|
const Loading = pi.ui.Loading ?? pi.ui.Skeleton;
|
|
1409
|
-
const card = React.useMemo(() => GlanceSpec.read(GlanceJson.parse(code
|
|
1587
|
+
const card = React.useMemo(() => GlanceSpec.read(GlanceJson.parse(code), !closed, words), [code, closed, words]);
|
|
1410
1588
|
const form = useForm(card, words, send, props.answer);
|
|
1411
1589
|
if (!card) {
|
|
1412
1590
|
return closed ? /* @__PURE__ */ React.createElement(Markdown, {
|
|
@@ -1452,7 +1630,7 @@ ${code}
|
|
|
1452
1630
|
|
|
1453
1631
|
// web-src/glance-protocol.ts
|
|
1454
1632
|
var LANGUAGE = "ta-glance";
|
|
1455
|
-
var ALIASES = ["glance", "glance-choice"];
|
|
1633
|
+
var ALIASES = ["glance", "glance-choice", "glance-card", "ta_glance", "taglance", "ta-glance-card", "ta-card"];
|
|
1456
1634
|
|
|
1457
1635
|
// web-src/glance-speech.ts
|
|
1458
1636
|
var GlanceSpeech;
|
|
@@ -1530,8 +1708,6 @@ var STYLE = `
|
|
|
1530
1708
|
.tag-card button { font-family: inherit; }
|
|
1531
1709
|
.tag-part { padding: var(--tag-y) var(--tag-x); min-width: 0; }
|
|
1532
1710
|
.tag-card[data-streaming] > .tag-part:last-child { animation: ta-in 200ms var(--ta-ease, ease) both; }
|
|
1533
|
-
.tag-inline .ta-markdown, .tag-inline .ta-markdown > p { display: inline; margin: 0; }
|
|
1534
|
-
.tag-inline .ta-markdown :not(pre) > code { padding: 0 4px; font-size: 0.92em; }
|
|
1535
1711
|
.tag-num { font-variant-numeric: tabular-nums; }
|
|
1536
1712
|
|
|
1537
1713
|
/* The head: how it went, as a pill, and a title beside it that wraps under it when long */
|
|
@@ -1871,7 +2047,7 @@ function activate(pi) {
|
|
|
1871
2047
|
const card = glanceCard(pi);
|
|
1872
2048
|
const spoken = (code) => {
|
|
1873
2049
|
const words = GlanceWords.of(pi.ui.language);
|
|
1874
|
-
const glance = GlanceSpec.read(GlanceJson.parse(code
|
|
2050
|
+
const glance = GlanceSpec.read(GlanceJson.parse(code), false, words);
|
|
1875
2051
|
return glance && GlanceSpeech.of(glance, words);
|
|
1876
2052
|
};
|
|
1877
2053
|
for (const language of [LANGUAGE, ...ALIASES]) {
|