@prismshadow/a2ui 0.0.0-stage → 0.2.19

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.
@@ -0,0 +1,857 @@
1
+ /**
2
+ * A2UI blocks: the catalog of components an assistant reply can carry as fenced JSON, and the
3
+ * shapes the grammar module shares with its renderers, the text fallback and the checker.
4
+ *
5
+ * A block is a ```a2ui fence holding ONE JSON object whose `type` names a catalog entry; the
6
+ * client draws it with its own components and theme, never with markup from the model. Markdown
7
+ * stays the carrier, so a surface that cannot render a block still has readable text (see
8
+ * fallback.ts), and a pick in the rendered block comes back as ordinary user text (see the
9
+ * fill-text helpers). Nothing in this directory depends on Node except cli.ts: the same code
10
+ * runs in the browser renderer and in the checker script bundled into the skill.
11
+ */
12
+ type A2uiType = "choice" | "form" | "steps" | "callout" | "weather" | "clock" | "countdown" | "metrics" | "chart" | "resources";
13
+ interface A2uiOption {
14
+ label: string;
15
+ /** What a pick fills into the composer; defaults to the label. */
16
+ value?: string;
17
+ description?: string;
18
+ recommended?: boolean;
19
+ }
20
+ /** One question with 2–7 options; the pick fills the composer and ends the model's turn. */
21
+ interface A2uiChoice {
22
+ type: "choice";
23
+ id?: string;
24
+ question: string;
25
+ options: A2uiOption[];
26
+ multiple?: boolean;
27
+ /** Adds an "Other…" control that clears the composer and focuses it, for the user's own answer. */
28
+ allowOther?: boolean;
29
+ }
30
+ /** What a form field asks for; each kind has its own control and its own answer. */
31
+ type A2uiFieldKind = "text" | "textarea" | "number" | "slider" | "single" | "multiple" | "select" | "switch" | "date" | "time" | "datetime";
32
+ /** The answer a field holds: text (and date/time strings), option labels, or a switch's state. */
33
+ type A2uiFormAnswer = string | string[] | boolean;
34
+ type A2uiFormAnswers = Record<string, A2uiFormAnswer>;
35
+ interface A2uiFormField {
36
+ /** `^[a-z][a-z0-9_]{0,31}$`, unique in the form. */
37
+ id: string;
38
+ /** ≤ 60. */
39
+ label: string;
40
+ kind: A2uiFieldKind;
41
+ /**
42
+ * A line under the control, ≤ 80: the format or the convention ("one per line", "in GB").
43
+ * Also the error line when the answer breaks the field's rule. Any kind.
44
+ */
45
+ hint?: string;
46
+ /** Any kind; a switch and a slider are always answered. */
47
+ required?: boolean;
48
+ /**
49
+ * single, multiple: 2–7 (warn > 5); select: 2–30 (warn > 12). Required for those three, not
50
+ * allowed elsewhere. A select ignores `description` (one-line rows).
51
+ */
52
+ options?: A2uiOption[];
53
+ /** text, textarea, number; select: the words of the empty row. ≤ 80. */
54
+ placeholder?: string;
55
+ /** number, slider: finite, min < max; a slider requires both. */
56
+ min?: number;
57
+ max?: number;
58
+ /** number, slider: > 0 (default 1). */
59
+ step?: number;
60
+ /** number, slider: ≤ 12, after the figure in the fill text and in the box. */
61
+ unit?: string;
62
+ /** text ≤ 500, textarea ≤ 2000: the answer's length ceiling (default: that ceiling). */
63
+ maxLength?: number;
64
+ /** text only: a JS regular expression (no flags, ≤ 120) the whole answer must match. */
65
+ pattern?: string;
66
+ /**
67
+ * The starting answer, typed by kind: text/textarea/date/time/datetime a string in the field's
68
+ * rule; number/slider a number in range; single/select an option label; multiple option labels;
69
+ * switch a boolean. Must satisfy the field's own rule.
70
+ */
71
+ default?: string | number | boolean | string[];
72
+ }
73
+ /** Several questions answered at once (1–6 fields); the answers fill the composer one line per field. */
74
+ interface A2uiForm {
75
+ type: "form";
76
+ id?: string;
77
+ title?: string;
78
+ fields: A2uiFormField[];
79
+ submitLabel?: string;
80
+ }
81
+ interface A2uiStep {
82
+ text: string;
83
+ /** Risk of irreversible loss, security or harm; rendered above the step. */
84
+ warning?: string;
85
+ /** Risk of breaking something recoverable; rendered above the step. */
86
+ caution?: string;
87
+ /** Useful information; rendered below the step. */
88
+ note?: string;
89
+ code?: string;
90
+ lang?: string;
91
+ }
92
+ /** A procedure, one instruction per step (1–15 steps). */
93
+ interface A2uiSteps {
94
+ type: "steps";
95
+ title?: string;
96
+ steps: A2uiStep[];
97
+ }
98
+ interface A2uiCallout {
99
+ type: "callout";
100
+ tone: "note" | "tip" | "caution" | "warning";
101
+ title?: string;
102
+ text: string;
103
+ }
104
+ type A2uiWeatherCondition = "clear" | "partly-cloudy" | "cloudy" | "fog" | "drizzle" | "rain" | "heavy-rain" | "thunder" | "snow" | "sleet" | "wind";
105
+ interface A2uiWeatherHour {
106
+ /** "HH:mm" (24 h) or an ISO date-time; the renderer shows the hour. */
107
+ time: string;
108
+ temp: number;
109
+ condition?: A2uiWeatherCondition;
110
+ /** Chance of precipitation, 0–100. */
111
+ precip?: number;
112
+ /** Draws the night variant of the hour's condition art. */
113
+ night?: boolean;
114
+ }
115
+ interface A2uiWeatherDay {
116
+ /** "YYYY-MM-DD" (or an ISO date-time; only the date is used). */
117
+ date: string;
118
+ high: number;
119
+ low: number;
120
+ condition: A2uiWeatherCondition;
121
+ /** Chance of precipitation, 0–100. */
122
+ precip?: number;
123
+ }
124
+ /** Current conditions at a place, optionally with the next hours and days. A snapshot. */
125
+ interface A2uiWeather {
126
+ type: "weather";
127
+ place: string;
128
+ condition: A2uiWeatherCondition;
129
+ temp: number;
130
+ /** Default "C". */
131
+ unit?: "C" | "F";
132
+ /** Night art (moon) for clear / partly-cloudy. */
133
+ night?: boolean;
134
+ /** One line in the model's words. */
135
+ summary?: string;
136
+ high?: number;
137
+ low?: number;
138
+ feelsLike?: number;
139
+ /** 0–100. */
140
+ humidity?: number;
141
+ /** At least 0. */
142
+ windSpeed?: number;
143
+ /** Default "km/h". */
144
+ windUnit?: "km/h" | "m/s" | "mph";
145
+ /** "NE", "东北". */
146
+ windDirection?: string;
147
+ /** 2–24 entries. */
148
+ hourly?: A2uiWeatherHour[];
149
+ /** 2–7 entries. */
150
+ daily?: A2uiWeatherDay[];
151
+ /** When the data was read (ISO date-time). */
152
+ asOf?: string;
153
+ /** Where the data came from, e.g. "Open-Meteo". */
154
+ source?: string;
155
+ }
156
+ interface A2uiClockZone {
157
+ /** An IANA zone ("Asia/Shanghai") or "local" for the viewer's own. */
158
+ zone: string;
159
+ /** "Beijing", "北京". */
160
+ label?: string;
161
+ }
162
+ /** The time now, in one to four zones. Live: ticks on the client. */
163
+ interface A2uiClock {
164
+ type: "clock";
165
+ title?: string;
166
+ /** 1–4 zones; omitted means one zone, "local". */
167
+ zones?: A2uiClockZone[];
168
+ /** Default "digital". */
169
+ style?: "digital" | "analog" | "both";
170
+ /** Default "auto": the interface locale decides. */
171
+ hourCycle?: "12" | "24" | "auto";
172
+ /** The digital figure shows seconds; default false. */
173
+ seconds?: boolean;
174
+ /** Shows the weekday and date under the time; default true. */
175
+ date?: boolean;
176
+ }
177
+ /** Time left until one instant. Live: counts down on the client. */
178
+ interface A2uiCountdown {
179
+ type: "countdown";
180
+ /** ISO date-time (no offset = the viewer's local time) or "YYYY-MM-DD" (local midnight). */
181
+ to: string;
182
+ /** What happens then. */
183
+ label: string;
184
+ /** Shown once the instant is reached; default: the UI's "Time's up". */
185
+ doneLabel?: string;
186
+ /** Shows the target date-time under the figure; default true. */
187
+ showTarget?: boolean;
188
+ }
189
+ type A2uiMetricKind = "reading" | "used" | "remaining" | "progress";
190
+ interface A2uiMetric {
191
+ label: string;
192
+ /** Finite. */
193
+ value: number;
194
+ /** The whole: required for used / remaining / progress and for a ring or bar gauge. */
195
+ max?: number;
196
+ /** Default 0; below max. */
197
+ min?: number;
198
+ /**
199
+ * reading — a measurement (CPU 37 %, load 1.2, latency 120 ms); default.
200
+ * used — part of a whole consumed (disk 320 of 512 GB).
201
+ * remaining — part of a whole still left (quota 1,240 of 5,000; budget ¥320 of ¥1,000).
202
+ * progress — how far a job got (upload 63 %, 7 of 12 tasks); at value ≥ max it is done.
203
+ */
204
+ kind?: A2uiMetricKind;
205
+ /** Default: progress → "bar"; max given → "ring"; else "none". ring/bar need max. */
206
+ gauge?: "ring" | "bar" | "none";
207
+ /** After the number: "%", "GB", "ms", "tasks". */
208
+ unit?: string;
209
+ /** Before the number: "¥", "$", "€". */
210
+ prefix?: string;
211
+ /** An integer 0–3; default: 0 for an integer value, else up to 2. */
212
+ decimals?: number;
213
+ /** Which way is bad. Default: remaining → "low"; everything else → "high". */
214
+ worse?: "high" | "low";
215
+ /** Thresholds in value units, read along `worse`: attention at warn, danger at danger. */
216
+ warn?: number;
217
+ danger?: number;
218
+ /** One quiet line ("resets in 3 days"); default from the kind (metricDetail). */
219
+ detail?: string;
220
+ /** Change since the previous reading, in the same unit. */
221
+ delta?: number;
222
+ /** "vs. yesterday". */
223
+ deltaLabel?: string;
224
+ /** 2–60 points in the same unit, oldest first. */
225
+ history?: number[];
226
+ }
227
+ /** A snapshot of one to eight readings. */
228
+ interface A2uiMetrics {
229
+ type: "metrics";
230
+ title?: string;
231
+ items: A2uiMetric[];
232
+ /** When the data was read (ISO date-time). */
233
+ asOf?: string;
234
+ }
235
+ type A2uiChartKind = "line" | "area" | "bar" | "pie" | "scatter" | "histogram" | "gauge";
236
+ interface A2uiChartSeries {
237
+ /** ≤ 40, unique in the block. */
238
+ label: string;
239
+ /** line/area/bar/pie/histogram: one per category (or bin); null = no reading (a gap). */
240
+ values?: (number | null)[];
241
+ /** scatter: 1–500 (warn > 200) finite [x, y] pairs. */
242
+ points?: [number, number][];
243
+ }
244
+ /** One basic chart. Which fields apply depends on `kind`; a field another kind uses is ignored with a warning. */
245
+ interface A2uiChart {
246
+ type: "chart";
247
+ kind: A2uiChartKind;
248
+ /** ≤ 60. */
249
+ title?: string;
250
+ /** line/area/bar: the x labels; pie: the slice names. 1–60 (warn > 24); pie 2–8 (warn > 6). */
251
+ categories?: string[];
252
+ /** histogram: n+1 strictly ascending bin edges, 3–61; the one series has n counts ≥ 0. */
253
+ edges?: number[];
254
+ /** 1–6 series (warn > 4); pie and histogram: exactly 1. Not for gauge. */
255
+ series?: A2uiChartSeries[];
256
+ /** Axis names, ≤ 24 ("Latency", "Day"). Not for pie. */
257
+ xLabel?: string;
258
+ yLabel?: string;
259
+ /**
260
+ * Units, ≤ 12, appended to tick labels and values ("ms", "%", "GB"). `yUnit` is the values'
261
+ * unit (pie: the slices'); `xUnit` is the numeric x axis' (scatter, histogram).
262
+ */
263
+ xUnit?: string;
264
+ yUnit?: string;
265
+ /** bar, area. */
266
+ stacked?: boolean;
267
+ /** bar only. */
268
+ horizontal?: boolean;
269
+ /** pie only. */
270
+ donut?: boolean;
271
+ /**
272
+ * Value-axis range; default 0..nice(max) (line/area/scatter: the data's range when `min` is
273
+ * given). Not for pie or gauge (a gauge's range is its `item`'s).
274
+ */
275
+ min?: number;
276
+ max?: number;
277
+ /** 0–3. Not for gauge (its `item` has its own). */
278
+ decimals?: number;
279
+ /** gauge only: ONE metrics item (label, value, max, kind, unit, warn/danger, delta, history…), parsed by parseMetric. */
280
+ item?: A2uiMetric;
281
+ /** ISO date-time; optional (data need not be a snapshot). */
282
+ asOf?: string;
283
+ }
284
+ interface A2uiResourcesCpu {
285
+ /** 0–100. */
286
+ percent: number;
287
+ /** 2–60 percents, oldest first. */
288
+ history?: number[];
289
+ /** A whole number ≥ 1. */
290
+ cores?: number;
291
+ }
292
+ interface A2uiResourcesMemory {
293
+ /** ≥ 0, ≤ total. */
294
+ used: number;
295
+ /** > 0. */
296
+ total: number;
297
+ /** Default "GB". */
298
+ unit?: "GB" | "MB";
299
+ /** 2–60 percents of the total, oldest first. */
300
+ history?: number[];
301
+ }
302
+ interface A2uiResourcesSwap {
303
+ used: number;
304
+ total: number;
305
+ /** Default "GB". */
306
+ unit?: "GB" | "MB";
307
+ }
308
+ interface A2uiResourcesDisk {
309
+ /** The mount point or drive, ≤ 40, unique in the block. */
310
+ path: string;
311
+ used: number;
312
+ total: number;
313
+ /** Default "GB". */
314
+ unit?: "GB" | "TB";
315
+ }
316
+ interface A2uiResourcesNetwork {
317
+ unit: "KB/s" | "MB/s" | "Mbps";
318
+ /** Received, 2–60 readings ≥ 0, oldest first. */
319
+ rx: number[];
320
+ /** Sent, as many readings as `rx`. */
321
+ tx: number[];
322
+ }
323
+ interface A2uiResourcesLoad {
324
+ /** The 1-minute load average, ≥ 0. */
325
+ one: number;
326
+ five?: number;
327
+ fifteen?: number;
328
+ /** A whole number ≥ 1: the thresholds read the load per core. */
329
+ cores: number;
330
+ }
331
+ /** A snapshot of one machine: at least one section. */
332
+ interface A2uiResources {
333
+ type: "resources";
334
+ /** ≤ 40. */
335
+ host?: string;
336
+ cpu?: A2uiResourcesCpu;
337
+ memory?: A2uiResourcesMemory;
338
+ swap?: A2uiResourcesSwap;
339
+ /** 1–6. */
340
+ disks?: A2uiResourcesDisk[];
341
+ network?: A2uiResourcesNetwork;
342
+ load?: A2uiResourcesLoad;
343
+ /** ≥ 0. */
344
+ uptimeSec?: number;
345
+ /** When the data was read (ISO date-time). */
346
+ asOf?: string;
347
+ }
348
+ type A2uiSpec = A2uiChoice | A2uiForm | A2uiSteps | A2uiCallout | A2uiWeather | A2uiClock | A2uiCountdown | A2uiMetrics | A2uiChart | A2uiResources;
349
+ type A2uiLevel = "error" | "warning";
350
+ /**
351
+ * Which bucket of the score an issue counts toward: `l1` protocol validity (always an error),
352
+ * `l2` task construction (block limits, cross-block heuristics; warnings). Set by checkReply;
353
+ * absent on issues from the single-block functions.
354
+ */
355
+ type A2uiScope = "l1" | "l2";
356
+ interface A2uiIssue {
357
+ level: A2uiLevel;
358
+ code: string;
359
+ /** English, and ends with what to do about it: the checker prints it verbatim to the model. */
360
+ message: string;
361
+ /** 1-based block index (a2ui and mermaid fences counted together, in order). */
362
+ block?: number;
363
+ /** JSON path inside the block, e.g. `options[2].label`. */
364
+ path?: string;
365
+ /** 1-based line: relative to the fence body from parseA2ui/checkMermaid, absolute in the reply from checkReply. */
366
+ line?: number;
367
+ scope?: A2uiScope;
368
+ }
369
+ /** One fenced block found in a reply. `index` is 1-based and counts a2ui + mermaid blocks in order. */
370
+ interface A2uiBlock {
371
+ index: number;
372
+ fence: "a2ui" | "mermaid";
373
+ /** The fence body, de-indented, without the fence lines. */
374
+ source: string;
375
+ /** 1-based line of the opening fence. */
376
+ startLine: number;
377
+ /** 1-based line of the closing fence, or of the reply's last line when the fence is unclosed. */
378
+ endLine: number;
379
+ closed: boolean;
380
+ /** The full info string, e.g. `a2ui json`. */
381
+ info?: string;
382
+ }
383
+ type A2uiLang = "zh" | "en";
384
+ type A2uiLangOption = A2uiLang | "auto";
385
+ interface A2uiReport {
386
+ /** No error-level issue. */
387
+ ok: boolean;
388
+ blocks: Array<{
389
+ index: number;
390
+ fence: "a2ui" | "mermaid";
391
+ type?: string;
392
+ ok: boolean;
393
+ }>;
394
+ issues: A2uiIssue[];
395
+ /** 0–100 each; any L1 error makes `total` 0, else it is L2. See A2UI_SCORING. */
396
+ score: {
397
+ l1: number;
398
+ l2: number;
399
+ total: number;
400
+ };
401
+ /** The language the rubric used (resolved from `auto`). */
402
+ lang: A2uiLang;
403
+ }
404
+ /** Field limits of the catalog. Over a limit is an L1 error; past a `warn` mark is an L2 warning. */
405
+ declare const A2UI_LIMITS: {
406
+ /** `id` of a choice or form. */
407
+ readonly idPattern: RegExp;
408
+ /** `id` of a form field (no hyphen: it doubles as an answer key). */
409
+ readonly fieldIdPattern: RegExp;
410
+ readonly question: 120;
411
+ readonly label: 60;
412
+ readonly labelWarn: 40;
413
+ readonly value: 500;
414
+ readonly description: 160;
415
+ readonly options: {
416
+ readonly min: 2;
417
+ readonly max: 7;
418
+ readonly warn: 5;
419
+ };
420
+ readonly fields: {
421
+ readonly min: 1;
422
+ readonly max: 6;
423
+ readonly warn: 4;
424
+ };
425
+ readonly fieldHint: 80;
426
+ readonly selectOptions: {
427
+ readonly min: 2;
428
+ readonly max: 30;
429
+ readonly warn: 12;
430
+ };
431
+ readonly textMaxLength: 500;
432
+ readonly textareaMaxLength: 2000;
433
+ readonly pattern: 120;
434
+ readonly steps: {
435
+ readonly min: 1;
436
+ readonly max: 15;
437
+ readonly warn: 10;
438
+ };
439
+ readonly title: 80;
440
+ readonly placeholder: 80;
441
+ readonly unit: 12;
442
+ readonly submitLabel: 24;
443
+ readonly stepText: 200;
444
+ readonly stepCode: 2000;
445
+ readonly lang: 20;
446
+ readonly calloutText: 400;
447
+ readonly mermaid: {
448
+ readonly statements: 30;
449
+ readonly lines: 400;
450
+ };
451
+ readonly place: 60;
452
+ readonly summary: 80;
453
+ readonly source: 40;
454
+ readonly windDirection: 6;
455
+ readonly hourly: {
456
+ readonly min: 2;
457
+ readonly max: 24;
458
+ readonly warn: 12;
459
+ };
460
+ readonly daily: {
461
+ readonly min: 2;
462
+ readonly max: 7;
463
+ };
464
+ readonly zones: {
465
+ readonly min: 1;
466
+ readonly max: 4;
467
+ };
468
+ readonly zoneLabel: 24;
469
+ readonly zone: 64;
470
+ readonly clockTitle: 40;
471
+ readonly countdownLabel: 60;
472
+ readonly metricsTitle: 40;
473
+ readonly metrics: {
474
+ readonly min: 1;
475
+ readonly max: 8;
476
+ readonly warn: 6;
477
+ };
478
+ readonly metricLabel: 40;
479
+ readonly metricDetail: 60;
480
+ readonly prefix: 4;
481
+ readonly deltaLabel: 24;
482
+ readonly history: {
483
+ readonly min: 2;
484
+ readonly max: 60;
485
+ };
486
+ readonly chartTitle: 60;
487
+ readonly seriesLabel: 40;
488
+ readonly categoryLabel: 40;
489
+ readonly axisLabel: 24;
490
+ readonly chartCategories: {
491
+ readonly min: 1;
492
+ readonly max: 60;
493
+ readonly warn: 24;
494
+ };
495
+ readonly pieSlices: {
496
+ readonly min: 2;
497
+ readonly max: 8;
498
+ readonly warn: 6;
499
+ };
500
+ readonly chartSeries: {
501
+ readonly min: 1;
502
+ readonly max: 6;
503
+ readonly warn: 4;
504
+ };
505
+ readonly scatterPoints: {
506
+ readonly min: 1;
507
+ readonly max: 500;
508
+ readonly warn: 200;
509
+ };
510
+ readonly edges: {
511
+ readonly min: 3;
512
+ readonly max: 61;
513
+ };
514
+ readonly host: 40;
515
+ readonly disks: {
516
+ readonly min: 1;
517
+ readonly max: 6;
518
+ };
519
+ readonly diskPath: 40;
520
+ };
521
+ /**
522
+ * The score's weights, in one place so the skill can quote them. l1 is 100 or 0; l2 loses points
523
+ * per block warning down to 0; total is 0 on any L1 error, else l2. `passTotal` is the gate the
524
+ * skill teaches ("errors 0, total at least 70"): at most two block warnings.
525
+ */
526
+ declare const A2UI_SCORING: {
527
+ readonly l2PerWarning: 15;
528
+ readonly passTotal: 70;
529
+ };
530
+
531
+ /**
532
+ * Fenced-block scanning on CommonMark's rules, so the checker, the text fallback and the language
533
+ * detection agree with the Markdown renderer about where a block starts and ends: 3+ backticks or
534
+ * tildes, at most 3 spaces of indentation, the language is the first word of the info string,
535
+ * the closing fence is the same character and at least as long, and the body is de-indented by
536
+ * the opening fence's indentation. Every fence is tracked, whatever its language, because a
537
+ * ```a2ui line inside a longer ````markdown fence is an example, not a block.
538
+ */
539
+
540
+ /** Every ```a2ui and ```mermaid block of a reply, unclosed ones included (`closed: false`). */
541
+ declare function findBlocks(markdown: string): A2uiBlock[];
542
+
543
+ interface A2uiParseResult {
544
+ /** Set only when there is no error-level issue. */
545
+ spec?: A2uiSpec;
546
+ issues: A2uiIssue[];
547
+ /** The `type` the block named, valid or not, so a report can label an invalid block. */
548
+ type?: string;
549
+ }
550
+ /** Parses and validates one ```a2ui body. `spec` is set only when there is no error. */
551
+ declare function parseA2ui(source: string): A2uiParseResult;
552
+
553
+ /**
554
+ * A form: several questions answered at once, one field per question, each field a kind with its
555
+ * own control and its own answer — text, several lines, a number, a slider, one or several of a
556
+ * few options, one of a long list, on/off, a date, a time, or both. This module is the grammar
557
+ * of a form (parseForm) and the ONE rule for whether an answer is acceptable (fieldProblem): the
558
+ * renderer's fill gate, its error line and its saved drafts ask the same function, and the
559
+ * grammar asks it of a field's `default`, so a form can never start from an answer it would
560
+ * refuse. The rule speaks in symbols ("1–10", "≤ 500", "YYYY-MM-DD"), never in words: the words
561
+ * around it are the renderer's, in the reader's language.
562
+ */
563
+
564
+ /** The answer formats of the date and time kinds: what the native inputs emit. */
565
+ declare const A2UI_FIELD_FORMATS: {
566
+ readonly date: RegExp;
567
+ readonly time: RegExp;
568
+ readonly datetime: RegExp;
569
+ };
570
+ type A2uiFieldProblemCode = "empty" | "not_a_number" | "out_of_range" | "too_long" | "pattern" | "format" | "not_an_option";
571
+ interface A2uiFieldProblem {
572
+ code: A2uiFieldProblemCode;
573
+ /** The rule in symbols: "1–10", "≤ 500", "YYYY-MM-DD". */
574
+ rule?: string;
575
+ }
576
+ /** The field's rule in symbols every language reads, or undefined (a plain text field). */
577
+ declare function fieldRule(field: A2uiFormField): string | undefined;
578
+ /**
579
+ * Whether an answer is acceptable for the field: null when it is (or when an optional field has
580
+ * none), else what is wrong. A switch is always answered; any other field is unanswered when the
581
+ * answer is missing, blank or an empty list, which only a required field refuses. An answer of
582
+ * the wrong shape for the kind — a boolean on a text field, a word on a switch — is refused too,
583
+ * so a stale draft cannot bring one back.
584
+ */
585
+ declare function fieldProblem(field: A2uiFormField, answer: A2uiFormAnswer | undefined): A2uiFieldProblem | null;
586
+ /**
587
+ * The answer a field starts with: its `default` as an answer (a number as its digits, several
588
+ * labels in the options' order), else a slider's `min`, else a switch's false, else nothing.
589
+ */
590
+ declare function initialAnswer(field: A2uiFormField): A2uiFormAnswer | undefined;
591
+
592
+ /**
593
+ * The basic charts: a `chart` block — line, area, bar, pie, scatter, histogram or gauge — as the
594
+ * grammar reads it (parseChart), the reading of a series a summary prints (seriesExtent), and the
595
+ * text a surface without a renderer shows instead (chartMarkdown). One data model serves every
596
+ * kind but the gauge: categories (or bin edges) × series, units on the axes. A gauge is one
597
+ * metrics item, read and printed by metric.ts, so a lone reading and a tile of a metrics block are
598
+ * the same thing.
599
+ */
600
+
601
+ declare const A2UI_CHART_KINDS: readonly A2uiChartKind[];
602
+ /** The readings of a list, nulls skipped: the smallest, the largest, the first, the last and how many. */
603
+ interface A2uiExtent {
604
+ min: number;
605
+ max: number;
606
+ first: number;
607
+ last: number;
608
+ count: number;
609
+ }
610
+ /** The extent of the readings in `values` (nulls are gaps); undefined when there is none. */
611
+ declare function seriesExtent(values: readonly (number | null)[]): A2uiExtent | undefined;
612
+
613
+ /**
614
+ * The system-resource board: a `resources` block — one machine's CPU, memory, swap, disks,
615
+ * network, load and uptime — as the grammar reads it (parseResources), as the renderer and the
616
+ * text judge it (resolveResources, with thresholds fixed here rather than chosen by the model),
617
+ * and as text (resourcesMarkdown). It is a composition of the basic charts: each reading becomes
618
+ * a metrics item (resourcesTiles), so it draws as the metrics block's tile and prints as its
619
+ * line; the disks are horizontal bars on a shared percent scale; the network is a line chart.
620
+ */
621
+
622
+ type A2uiResourceKey = "cpu" | "memory" | "swap" | "load" | "uptime";
623
+ type A2uiResourceTone = "attention" | "danger";
624
+ /** One reading of the board as a metrics item, without its label (the caller names it in its language). */
625
+ interface A2uiResourceTile {
626
+ key: A2uiResourceKey;
627
+ metric: Omit<A2uiMetric, "label">;
628
+ }
629
+ interface A2uiResolvedDisk {
630
+ path: string;
631
+ used: number;
632
+ total: number;
633
+ unit: "GB" | "TB";
634
+ /** used / total, 0–1. */
635
+ share: number;
636
+ tone?: A2uiResourceTone;
637
+ }
638
+ /** The tone of every section the fixed marks colour; a calm section has none. */
639
+ interface A2uiResolvedResources {
640
+ cpu?: A2uiResourceTone;
641
+ memory?: A2uiResourceTone;
642
+ swap?: A2uiResourceTone;
643
+ load?: A2uiResourceTone;
644
+ /** One per disk, in the block's order. */
645
+ disks: A2uiResolvedDisk[];
646
+ }
647
+ /**
648
+ * The board's readings as metrics items, in the order the board draws them: CPU, memory, swap,
649
+ * load, uptime (a section the block leaves out has no tile). Each carries the fixed marks as its
650
+ * `warn`/`danger`, so resolveMetric gives the tone the board judges; the memory history comes
651
+ * back in the memory's unit. `lang` words the few parts that are words: the cores under CPU and
652
+ * load, the load's 5- and 15-minute averages, and uptime's unit.
653
+ */
654
+ declare function resourcesTiles(spec: A2uiResources, lang: A2uiLang): A2uiResourceTile[];
655
+ /**
656
+ * The board's judgement with the fixed marks: CPU, memory and swap past 80 % need attention and
657
+ * past 95 % are danger; a disk past 85 % / 95 %; the load at or past one per core / two per core.
658
+ * Every tone is resolveMetric's over the same items the tiles and the text use, so the three agree.
659
+ */
660
+ declare function resolveResources(spec: A2uiResources): A2uiResolvedResources;
661
+
662
+ /**
663
+ * L1 checks on a ```mermaid body without a Mermaid parser: a supported diagram header, no
664
+ * configuration or link syntax from the model, and a best-effort balance check that catches the
665
+ * usual breakage (an unquoted parenthesis in a node label). The real parse happens in the
666
+ * browser; these rules exist so the model hears about the common mistakes before it sends, and
667
+ * so the renderer can refuse what the sanitiser would not.
668
+ *
669
+ * Why directives and frontmatter are errors even under `securityLevel: "strict"`: Mermaid only
670
+ * protects the keys on its `secure` list (securityLevel, startOnLoad, maxTextSize, …); a
671
+ * `%%{init: {"themeCSS": …}}%%` directive or a frontmatter `config:` block still injects CSS
672
+ * into the rendered SVG. The app sets the theme; the model names a diagram.
673
+ */
674
+
675
+ /** Diagram headers the renderer accepts (first non-comment line, first word). */
676
+ declare const MERMAID_TYPES: readonly ["flowchart", "graph", "sequenceDiagram", "stateDiagram", "stateDiagram-v2", "classDiagram", "erDiagram", "gantt", "journey", "pie", "mindmap", "timeline", "gitGraph", "quadrantChart", "xychart-beta", "requirementDiagram", "C4Context"];
677
+ /** L1 checks of one ```mermaid body; the issues' `line` is 1-based within the body. */
678
+ declare function checkMermaid(source: string): A2uiIssue[];
679
+
680
+ /** zh when CJK characters are at least half as many as Latin letters outside the fences. */
681
+ declare function detectLang(markdown: string): A2uiLang;
682
+
683
+ /** Checks a reply: L1 per block, L2 across blocks, and the score; `lang` is the rubric's. */
684
+ declare function checkReply(markdown: string, opts?: {
685
+ lang?: A2uiLangOption;
686
+ }): A2uiReport;
687
+
688
+ /** The moment and zone a widget's fallback is printed for. */
689
+ interface A2uiFallbackContext {
690
+ /** Default: the time of the call. */
691
+ now?: Date;
692
+ /** An IANA zone, the reader's; default: the runtime's. */
693
+ timeZone?: string;
694
+ }
695
+ /** The separator between several picked values: 「、」 in zh, ", " in en. */
696
+ declare const listSeparator: (lang: A2uiLang) => string;
697
+ /** Readable Markdown for one valid block; a widget is printed for `ctx`'s moment and zone. */
698
+ declare function specToMarkdown(spec: A2uiSpec, lang: A2uiLang, ctx?: A2uiFallbackContext): string;
699
+ /**
700
+ * The reply with every valid, closed ```a2ui fence replaced by readable Markdown. Mermaid fences
701
+ * stay as they are; an invalid or unclosed block stays as its source fence (the reader still sees
702
+ * what the model wrote). Language from `opts.lang`, else detected from the reply; widgets are
703
+ * printed for `opts.now` in `opts.timeZone` (defaults: the time of the call, the runtime's zone).
704
+ */
705
+ declare function toFallbackMarkdown(markdown: string, opts?: {
706
+ lang?: A2uiLang;
707
+ } & A2uiFallbackContext): string;
708
+ /**
709
+ * The text a choice fills into the composer. `picked` holds option LABELS (unique by L1); each
710
+ * maps to the option's `value` (default: the label). A string that is not a label passes through
711
+ * as typed, so an "Other…" answer can be given the same way. Several picks are joined with the
712
+ * language's list separator.
713
+ */
714
+ declare function choiceFillText(spec: A2uiChoice, picked: string[], lang: A2uiLang): string;
715
+ /**
716
+ * The text a form fills into the composer: one line per answered field in the form's order,
717
+ * `label: answer` (en) / `label:answer` (zh). Answers for option fields are LABELS and map to
718
+ * values like a choice's; several are joined with the list separator; a number or a slider gets
719
+ * its unit; a switch is Yes or No; a datetime's `T` is a space. Text of several lines starts on
720
+ * the next line, each line indented two spaces. A field with no answer (missing, blank text, no
721
+ * option) fills no line; the renderer starts every field at its initial answer (initialAnswer),
722
+ * so a switch and a slider always hold one and always fill a line.
723
+ */
724
+ declare function formFillText(spec: A2uiForm, answers: A2uiFormAnswers, lang: A2uiLang): string;
725
+
726
+ /**
727
+ * The options a choice's pick filled, as their labels in the options' order, or null when the
728
+ * text is not a pick of this choice — an "Other…" answer the reader wrote, or another message.
729
+ * A single choice is one option's value (or its label); a multiple choice may list several,
730
+ * joined by either language's separator.
731
+ */
732
+ declare function parseChoicePick(spec: A2uiChoice, text: string): string[] | null;
733
+ /**
734
+ * The answers a form was filled with, by field id, read back out of the message: a field's line
735
+ * found by its label in any order and in either language, each answer undone to what the form
736
+ * holds (an option's value back to its label, a list split on either separator, the unit off a
737
+ * figure, a datetime's space back to `T`, a longer answer's indent off). A field with no line, or
738
+ * whose answer it would not accept, is left out. Null when no line names any field: the message
739
+ * was not this form's answer.
740
+ */
741
+ declare function parseFormFill(spec: A2uiForm, text: string): A2uiFormAnswers | null;
742
+
743
+ /**
744
+ * Pure helpers the widget renderers share with the text fallback: reading a block's date-times,
745
+ * formatting numbers, values with units, temperatures and times in the block's language, and
746
+ * resolving a metric's defaults (kind, gauge, which way is worse, tone, the share a gauge draws).
747
+ * No DOM and no Node, `Intl` only, so the browser, the CLI and the bundled checker print a
748
+ * reading the same way.
749
+ */
750
+
751
+ /**
752
+ * Parses an ISO date-time or "YYYY-MM-DD" (local midnight). Null when invalid. Without `Z` or an
753
+ * offset a date-time is the viewer's local time. The date and the time must exist (no 2026-02-30,
754
+ * no 24:00); the parse is by hand so every engine reads the same string the same way.
755
+ */
756
+ declare function parseA2uiInstant(text: string): Date | null;
757
+ type A2uiLocale = "zh-CN" | "en-US";
758
+ /** The Intl locale of a block language. */
759
+ declare function localeOf(lang: A2uiLang): A2uiLocale;
760
+ /**
761
+ * "1,240", "0.75", "37" — grouping and fraction digits per locale. `decimals` fixes both the
762
+ * minimum and the maximum fraction digits; without it an integer prints none and anything else
763
+ * up to two.
764
+ */
765
+ declare function formatNumber(value: number, lang: A2uiLang, decimals?: number): string;
766
+ /**
767
+ * A number with its unit, the way every chart value and tick prints: "37%", "320 GB", "1,240";
768
+ * `decimals` as formatNumber takes it.
769
+ */
770
+ declare function formatValue(value: number, unit: string | undefined, lang: A2uiLang, decimals?: number): string;
771
+ /** `prefix` + number + unit; no space before "%", "°", "′", "″", a space before any other unit. */
772
+ declare function formatMetricValue(metric: A2uiMetric, lang: A2uiLang): string;
773
+ /** A metric with the catalog's defaults applied. */
774
+ interface A2uiResolvedMetric {
775
+ kind: A2uiMetricKind;
776
+ gauge: "ring" | "bar" | "none";
777
+ worse: "high" | "low";
778
+ /** "done" (progress complete), "danger", "attention" or undefined. */
779
+ tone?: "done" | "danger" | "attention";
780
+ /**
781
+ * The share the gauge draws, 0–1: (value − min) / (max − min), clamped; undefined without
782
+ * max.
783
+ */
784
+ share?: number;
785
+ }
786
+ /**
787
+ * The effective kind, gauge, worse and tone of a metric. Gauge: progress draws a bar, anything
788
+ * else with a `max` a ring, without a `max` nothing. Worse: remaining reads low as bad,
789
+ * everything else high. Tone: a complete progress is done; otherwise the thresholds read along
790
+ * `worse` — at or past `danger` is danger, at or past `warn` attention.
791
+ */
792
+ declare function resolveMetric(metric: A2uiMetric): A2uiResolvedMetric;
793
+ /**
794
+ * The default detail line when the model gives none: used "320 / 512 GB used", remaining
795
+ * "1,240 / 5,000 left", progress "7 / 12"; zh 「已用 320 / 512 GB」「剩余 1,240 / 5,000」「7 / 12」.
796
+ * Undefined for a reading or without `max`. A share of 100 % needs no "/ 100%": used and
797
+ * remaining say "37% used" / "40% left", and progress has nothing to add to its figure. A complete
798
+ * progress is not marked here: its tone ("done") carries that, and the renderer and the fallback
799
+ * print the tone.
800
+ */
801
+ declare function metricDetail(metric: A2uiMetric, lang: A2uiLang): string | undefined;
802
+ /**
803
+ * "+2.4" / "−0.3" with the metric's decimals, prefix and unit ("+0.4 GB", "−¥20"); the minus is
804
+ * U+2212, and a zero change has no sign. Undefined without `delta`.
805
+ */
806
+ declare function formatDelta(metric: A2uiMetric, lang: A2uiLang): string | undefined;
807
+ interface A2uiCountdownParts {
808
+ days: number;
809
+ hours: number;
810
+ minutes: number;
811
+ seconds: number;
812
+ /** The target is at or before `now`; every count is then 0. */
813
+ reached: boolean;
814
+ }
815
+ /**
816
+ * Whole days, hours, minutes and seconds left until `target` (all ≥ 0). A part of a second
817
+ * counts as a whole one, so the figure reads 0 only once the target is reached.
818
+ */
819
+ declare function countdownParts(target: Date, now: Date): A2uiCountdownParts;
820
+ /**
821
+ * The two largest units left: "3 days 4 hours" / "4 hours 12 min" / "12 min 5 sec" (en);
822
+ * 「3 天 4 小时」「4 小时 12 分」「12 分 5 秒」 (zh). A smaller unit at 0 is left out ("3 days");
823
+ * "" when reached.
824
+ */
825
+ declare function countdownText(parts: A2uiCountdownParts, lang: A2uiLang): string;
826
+ /** Weather condition name in the block's language. */
827
+ declare function conditionName(condition: A2uiWeatherCondition, lang: A2uiLang): string;
828
+ /** "18°", "18°C", "64°F" — degree sign tight to the number; `withUnit` appends the letter. */
829
+ declare function formatTemp(value: number, unit: "C" | "F" | undefined, withUnit: boolean, lang: A2uiLang): string;
830
+ /**
831
+ * HH:mm of an ISO date-time in `timeZone` (default: the runtime's), prefixed with "MM-DD " when
832
+ * its date differs from `now`'s and with "YYYY-MM-DD " when its year does. The same digits in
833
+ * both languages; an unparsable value comes back as written.
834
+ */
835
+ declare function formatAsOf(asOf: string, lang: A2uiLang, now: Date, timeZone?: string): string;
836
+ /**
837
+ * Short weekday ("Tue" / "周二") of a "YYYY-MM-DD" date (or the date of an ISO date-time),
838
+ * computed in UTC so the date never shifts. "Today" / 「今天」 when it equals `today`
839
+ * ("YYYY-MM-DD"). An unparsable value comes back as written.
840
+ */
841
+ declare function weekdayOf(date: string, lang: A2uiLang, today?: string): string;
842
+
843
+ /**
844
+ * The self-review questions the checker prints with `--rubric`: the L2/L3 judgements no rule can
845
+ * make (value over text, component–intent fit, grounding, completeness, cognitive load, the no-UI
846
+ * cases, and real data in widgets). The model answers them before sending; the skill quotes them.
847
+ */
848
+ declare const A2UI_RUBRIC: {
849
+ zh: string[];
850
+ en: string[];
851
+ };
852
+
853
+ declare function formatReport(report: A2uiReport, opts?: {
854
+ rubric?: boolean;
855
+ }): string;
856
+
857
+ export { A2UI_CHART_KINDS, A2UI_FIELD_FORMATS, A2UI_LIMITS, A2UI_RUBRIC, A2UI_SCORING, type A2uiBlock, type A2uiCallout, type A2uiChart, type A2uiChartKind, type A2uiChartSeries, type A2uiChoice, type A2uiClock, type A2uiClockZone, type A2uiCountdown, type A2uiCountdownParts, type A2uiExtent, type A2uiFallbackContext, type A2uiFieldKind, type A2uiFieldProblem, type A2uiFieldProblemCode, type A2uiForm, type A2uiFormAnswer, type A2uiFormAnswers, type A2uiFormField, type A2uiIssue, type A2uiLang, type A2uiLangOption, type A2uiLevel, type A2uiLocale, type A2uiMetric, type A2uiMetricKind, type A2uiMetrics, type A2uiOption, type A2uiParseResult, type A2uiReport, type A2uiResolvedDisk, type A2uiResolvedMetric, type A2uiResolvedResources, type A2uiResourceKey, type A2uiResourceTile, type A2uiResourceTone, type A2uiResources, type A2uiResourcesCpu, type A2uiResourcesDisk, type A2uiResourcesLoad, type A2uiResourcesMemory, type A2uiResourcesNetwork, type A2uiResourcesSwap, type A2uiScope, type A2uiSpec, type A2uiStep, type A2uiSteps, type A2uiType, type A2uiWeather, type A2uiWeatherCondition, type A2uiWeatherDay, type A2uiWeatherHour, MERMAID_TYPES, checkMermaid, checkReply, choiceFillText, conditionName, countdownParts, countdownText, detectLang, fieldProblem, fieldRule, findBlocks, formFillText, formatAsOf, formatDelta, formatMetricValue, formatNumber, formatReport, formatTemp, formatValue, initialAnswer, listSeparator, localeOf, metricDetail, parseA2ui, parseA2uiInstant, parseChoicePick, parseFormFill, resolveMetric, resolveResources, resourcesTiles, seriesExtent, specToMarkdown, toFallbackMarkdown, weekdayOf };