@sparkelf/dsh-genui 0.11.4-patch.2 → 0.13.0-sparkelf.2
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/CHANGELOG.md +76 -0
- package/ICON-NAMES.md +30 -0
- package/README.md +26 -28
- package/README.zh-CN.md +26 -28
- package/SKILL.md +128 -19
- package/THIRD_PARTY_NOTICES.md +42 -0
- package/assets/genui-icon.svg +20 -0
- package/assets/genui-logo.svg +18 -0
- package/lib/assets/icons.js +1 -0
- package/lib/assets/mermaid.js +325 -325
- package/lib/assets/standalone-runtime.js +10 -9
- package/lib/client.js +32 -31
- package/lib/index.js +489 -80
- package/lib/types/client/action-context.d.ts +1 -1
- package/lib/types/client/artifact/types.d.ts +1 -1
- package/lib/types/client/asset-loader.d.ts +2 -2
- package/lib/types/client/blocks/blocks.d.ts +12 -0
- package/lib/types/client/blocks/icon.d.ts +4 -0
- package/lib/types/client/dom-fence.d.ts +2 -1
- package/lib/types/client/fence-render.d.ts +5 -21
- package/lib/types/client/file-address.d.ts +4 -0
- package/lib/types/client/file-link-context.d.ts +49 -0
- package/lib/types/client/file-link.d.ts +17 -0
- package/lib/types/client/gallery.d.ts +8 -2
- package/lib/types/client/genui-runtime/diagnostics.d.ts +1 -1
- package/lib/types/client/genui-runtime/limits.d.ts +4 -0
- package/lib/types/client/genui-runtime/schema.d.ts +14 -1
- package/lib/types/client/guard.d.ts +4 -1
- package/lib/types/client/i18n/en.d.ts +5 -1
- package/lib/types/client/i18n/index.d.ts +1 -1
- package/lib/types/client/icons/asset-icons.d.ts +1 -0
- package/lib/types/client/icons/icon-data-full.d.ts +23 -0
- package/lib/types/client/icons/icon-data.d.ts +24 -0
- package/lib/types/client/icons/icon-lazy.d.ts +18 -0
- package/lib/types/client/icons/icon-names-full.d.ts +12 -0
- package/lib/types/client/index.d.ts +5 -15
- package/lib/types/client/inline.d.ts +1 -1
- package/lib/types/client/mermaid-colors.d.ts +2 -0
- package/lib/types/client/mermaid-core.d.ts +2 -1
- package/lib/types/client/mermaid-lazy.d.ts +5 -1
- package/lib/types/client/panel-command.d.ts +21 -1
- package/lib/types/client/panel.d.ts +6 -1
- package/lib/types/client/primitive-adapter.d.ts +0 -2
- package/lib/types/client/session-resolver.d.ts +13 -2
- package/lib/types/client/source-fence.d.ts +1 -1
- package/lib/types/client/spec.d.ts +107 -3
- package/lib/types/client/standalone/asset-loader.d.ts +1 -1
- package/lib/types/client/standalone/primitive-adapter.d.ts +0 -4
- package/lib/types/plugin/fence-feedback.d.ts +11 -7
- package/lib/types/plugin/index.d.ts +6 -2
- package/lib/types/shared/fence-language.d.ts +14 -0
- package/lib/types/shared/fence-repair.d.ts +2 -1
- package/lib/types/shared/fence-resolve.d.ts +1 -1
- package/package.json +92 -83
- package/src/client/EChartNode.tsx +17 -3
- package/src/client/GenuiBlock.module.css +411 -76
- package/src/client/action-context.ts +5 -15
- package/src/client/artifact/ArtifactExport.module.css +34 -3
- package/src/client/artifact/ExportableGenuiBlock.tsx +23 -2
- package/src/client/artifact/portability.ts +6 -1
- package/src/client/artifact/types.ts +1 -1
- package/src/client/asset-loader.ts +3 -3
- package/src/client/blocks/advanced.tsx +101 -14
- package/src/client/blocks/blocks.tsx +143 -0
- package/src/client/blocks/charts.tsx +22 -6
- package/src/client/blocks/icon.tsx +93 -0
- package/src/client/blocks/image.tsx +1 -0
- package/src/client/blocks/render-node.tsx +84 -52
- package/src/client/dom-fence.tsx +546 -72
- package/src/client/fence-render.tsx +5 -21
- package/src/client/file-address.ts +37 -0
- package/src/client/file-link-context.tsx +116 -0
- package/src/client/file-link.ts +46 -0
- package/src/client/gallery.ts +161 -133
- package/src/client/genui-runtime/diagnostics.ts +1 -1
- package/src/client/genui-runtime/limits.ts +4 -0
- package/src/client/genui-runtime/normalize.ts +42 -6
- package/src/client/genui-runtime/schema.ts +39 -7
- package/src/client/guard.ts +170 -15
- package/src/client/i18n/en.ts +5 -1
- package/src/client/i18n/index.ts +1 -1
- package/src/client/i18n/zh.ts +5 -1
- package/src/client/icons/asset-icons.ts +16 -0
- package/src/client/icons/icon-data-full.ts +5715 -0
- package/src/client/icons/icon-data.ts +507 -0
- package/src/client/icons/icon-lazy.ts +80 -0
- package/src/client/icons/icon-names-full.ts +12 -0
- package/src/client/index.tsx +27 -51
- package/src/client/inline.ts +17 -6
- package/src/client/mermaid-colors.ts +40 -0
- package/src/client/mermaid-core.ts +69 -61
- package/src/client/mermaid-lazy.ts +99 -4
- package/src/client/panel-command.ts +16 -2
- package/src/client/panel.tsx +18 -5
- package/src/client/primitive-adapter.ts +0 -11
- package/src/client/session-resolver.ts +12 -21
- package/src/client/source-fence.ts +4 -2
- package/src/client/spec.ts +116 -2
- package/src/client/standalone/asset-loader.ts +1 -1
- package/src/client/standalone/primitive-adapter.tsx +1 -9
- package/src/client/table-details.ts +4 -3
- package/src/plugin/fence-feedback.ts +60 -14
- package/src/plugin/index.ts +45 -20
- package/src/plugin/tool.ts +11 -2
- package/src/shared/fence-language.ts +30 -0
- package/src/shared/fence-repair.ts +37 -1
- package/src/shared/fence-resolve.ts +1 -1
- package/tsdown.config.ts +7 -8
- package/lib/invariant.js +0 -19
- package/lib/types/plugin/invariant.d.ts +0 -15
- package/src/plugin/invariant.ts +0 -30
|
@@ -5,7 +5,7 @@ import type { ComponentRecordSchema, ComponentSchema } from './schema.ts'
|
|
|
5
5
|
import { isTableDetailReachable } from '../table-details.ts'
|
|
6
6
|
|
|
7
7
|
export interface GenuiDiagnostic {
|
|
8
|
-
readonly kind: 'alias' | 'unknown-field'
|
|
8
|
+
readonly kind: 'alias' | 'unknown-field' | 'truncated'
|
|
9
9
|
readonly path: string
|
|
10
10
|
readonly message: string
|
|
11
11
|
readonly type?: string
|
|
@@ -39,6 +39,10 @@ export const GENUI_LIMITS = {
|
|
|
39
39
|
maxKeyValuePairs: 24,
|
|
40
40
|
/** Maximum `file-tree` nesting. */
|
|
41
41
|
maxTreeDepth: 6,
|
|
42
|
+
/** Maximum `blocks` figure rows / cells per row. Cells are data, not nodes,
|
|
43
|
+
* so a wide figure still costs one node against `maxNodes`. */
|
|
44
|
+
maxBlocksRows: 14,
|
|
45
|
+
maxBlocksCells: 16,
|
|
42
46
|
/** Maximum `diagram` nodes / edges / zones / focal accents. */
|
|
43
47
|
maxDiagramNodes: 9,
|
|
44
48
|
maxDiagramEdges: 12,
|
|
@@ -11,9 +11,35 @@ function record(value: unknown): Record<string, unknown> | undefined {
|
|
|
11
11
|
: undefined
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Resolve an explicit component type or a type uniquely identified by fields.
|
|
16
|
+
*
|
|
17
|
+
* @param value - Value to inspect without changing it.
|
|
18
|
+
* @returns The explicit or inferred component type when available.
|
|
19
|
+
*/
|
|
20
|
+
function nodeTypeOf(value: unknown): string | undefined {
|
|
15
21
|
const candidate = record(value)
|
|
16
|
-
|
|
22
|
+
if (candidate === undefined) return undefined
|
|
23
|
+
if (typeof candidate.type === 'string') return candidate.type
|
|
24
|
+
if ('type' in candidate) return undefined
|
|
25
|
+
const matches: string[] = []
|
|
26
|
+
if (Array.isArray(candidate.columns) && Array.isArray(candidate.rows)) matches.push('table')
|
|
27
|
+
if (Array.isArray(candidate.pairs)) matches.push('keyvalue')
|
|
28
|
+
if (Array.isArray(candidate.steps)) matches.push('steps')
|
|
29
|
+
if (Array.isArray(candidate.diffs)) matches.push('diff')
|
|
30
|
+
if (Array.isArray(candidate.meshes)) matches.push('scene3d')
|
|
31
|
+
if (Array.isArray(candidate.tabs)) matches.push('tabs')
|
|
32
|
+
return matches.length === 1 ? matches[0] : undefined
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Check whether a value can be treated as a component node.
|
|
37
|
+
*
|
|
38
|
+
* @param value - Value to inspect without changing it.
|
|
39
|
+
* @returns Whether the value has an explicit or uniquely inferred type.
|
|
40
|
+
*/
|
|
41
|
+
function isNode(value: unknown): value is Record<string, unknown> {
|
|
42
|
+
return nodeTypeOf(value) !== undefined
|
|
17
43
|
}
|
|
18
44
|
|
|
19
45
|
/** Fields a `stat` keeps when a metric record is folded into its own node. */
|
|
@@ -144,13 +170,23 @@ function defaultFileTreeDirectories(value: unknown): unknown {
|
|
|
144
170
|
return out
|
|
145
171
|
}
|
|
146
172
|
|
|
173
|
+
/**
|
|
174
|
+
* Normalize one component node and its renderer-reachable children.
|
|
175
|
+
*
|
|
176
|
+
* @param value - Raw component or other value.
|
|
177
|
+
* @param path - Stable diagnostic path for this node.
|
|
178
|
+
* @param warnings - Alias and structural normalization diagnostics.
|
|
179
|
+
* @returns The normalized component, or the original value when it is not a node.
|
|
180
|
+
*/
|
|
147
181
|
function normalizeNode(value: unknown, path: string, warnings: GenuiDiagnostic[]): unknown {
|
|
148
|
-
|
|
149
|
-
const
|
|
182
|
+
const type = nodeTypeOf(value)
|
|
183
|
+
const candidate = record(value)
|
|
184
|
+
if (type === undefined || candidate === undefined) return value
|
|
185
|
+
const node = typeof candidate.type === 'string' ? candidate : { ...candidate, type }
|
|
150
186
|
const definition = COMPONENT_SCHEMAS[type]
|
|
151
187
|
// Custom nodes are opaque by contract: don't inspect or rewrite their data.
|
|
152
|
-
if (definition === undefined) return
|
|
153
|
-
const out = normalizeAliasFields(
|
|
188
|
+
if (definition === undefined) return node
|
|
189
|
+
const out = normalizeAliasFields(node, path, type, warnings)
|
|
154
190
|
// Nested data records (keyvalue pairs, file-tree items, …) carry their own
|
|
155
191
|
// field aliases — apply them before validation/repair see the records.
|
|
156
192
|
for (const [field, nested] of Object.entries(definition.nested)) {
|
|
@@ -59,7 +59,8 @@ export interface ComponentSchema {
|
|
|
59
59
|
|
|
60
60
|
|
|
61
61
|
/** Canonical enum domains shared by schema validation and repair. */
|
|
62
|
-
export const TEXT_SIZES = ['h1', 'h2', 'h3', 'body', 'muted', 'caption'] as const
|
|
62
|
+
export const TEXT_SIZES = ['display', 'h1', 'h2', 'h3', 'body', 'muted', 'caption'] as const
|
|
63
|
+
export const TEXT_ALIGNS = ['left', 'center', 'right'] as const
|
|
63
64
|
export const BUTTON_TONES = ['primary', 'danger', 'success', 'ghost'] as const
|
|
64
65
|
export const BADGE_TONES = ['success', 'warn', 'danger', 'accent'] as const
|
|
65
66
|
export const INPUT_TYPES = ['text', 'email', 'password', 'color'] as const
|
|
@@ -89,6 +90,18 @@ export const STAT_SIZES = ['hero'] as const
|
|
|
89
90
|
export const PROGRESS_VARIANTS = ['bar', 'ring'] as const
|
|
90
91
|
/** Semantic card surfaces. */
|
|
91
92
|
export const CARD_TONES = ['info', 'success', 'warning', 'danger'] as const
|
|
93
|
+
/** Text run tones (semantic colour without a badge). */
|
|
94
|
+
export const TEXT_TONES = ['danger', 'success', 'warning', 'info', 'muted'] as const
|
|
95
|
+
/** Arrow directions. */
|
|
96
|
+
export const ARROW_DIRS = ['down', 'right'] as const
|
|
97
|
+
/** Row main-axis alignment values. */
|
|
98
|
+
export const ROW_JUSTIFY = ['start', 'center', 'end', 'between'] as const
|
|
99
|
+
/** Block-row paint modes: filled cells, or outlined cells for bit grids. */
|
|
100
|
+
export const BLOCKS_VARIANTS = ['fill', 'outline', 'plain'] as const
|
|
101
|
+
/** 单格强调的语义档位。 */
|
|
102
|
+
export const BLOCK_CELL_TONES = ['accent', 'success', 'warning', 'danger', 'muted'] as const
|
|
103
|
+
/** Icon tones: the four semantic roles plus neutral/muted text colours. */
|
|
104
|
+
export const ICON_TONES = ['default', 'muted', 'info', 'success', 'warning', 'danger'] as const
|
|
92
105
|
/** Hero cover tones. */
|
|
93
106
|
export const HERO_TONES = ['accent', 'success', 'warning', 'danger'] as const
|
|
94
107
|
/** Table cell renderers (`table.types`, one entry per column). */
|
|
@@ -158,6 +171,12 @@ const stepsRecordSchema = recordSchema(['title'], { title: 'string', desc: 'stri
|
|
|
158
171
|
// record otherwise fails "requires key" and the whole keyvalue drops.
|
|
159
172
|
const keyValueRecordSchema = recordSchema(['key', 'value'], { key: 'string', value: 'string' }, {}, {}, { label: 'key' })
|
|
160
173
|
const timelineRecordSchema = recordSchema(['title'], { title: 'string', desc: 'string', time: 'string' })
|
|
174
|
+
// One `blocks` row. `cells` entries are text-or-null; `null` means "gap".
|
|
175
|
+
// `cells` is a UNION (string | null | record), so it cannot hang off
|
|
176
|
+
// `nested` — that path assumes every array entry is a record and would demand
|
|
177
|
+
// objects for the plain-string cells. The object arm is validated by
|
|
178
|
+
// validateNode's `blocks` case instead; the row schema only declares kinds.
|
|
179
|
+
const blocksRowSchema = recordSchema(['cells'], { label: 'string', cells: 'array', color: 'string', variant: 'string' }, {}, { variant: BLOCKS_VARIANTS }, { title: 'label' })
|
|
161
180
|
const diffRecordSchema = recordSchema(['path', 'newText'], { path: 'string', oldText: 'string-or-null', newText: 'string' })
|
|
162
181
|
const plotParamSchema = recordSchema(['name', 'value'], {
|
|
163
182
|
name: 'string', value: 'number', min: 'number', max: 'number', step: 'number', animateTo: 'number', durationMs: 'number', loop: 'boolean',
|
|
@@ -254,6 +273,8 @@ export const SPEC_SCHEMA = GENUI_SPEC_SCHEMA
|
|
|
254
273
|
* diagnostics, where erased interfaces are unavailable.
|
|
255
274
|
*/
|
|
256
275
|
export const COMPONENT_SCHEMAS: Readonly<Record<string, ComponentSchema>> = {
|
|
276
|
+
// Thin connector for figures; the `↓` text glyph was the only option before.
|
|
277
|
+
arrow: schema([], { ...nodeFields, dir: 'string', length: 'number', label: 'string' }, { direction: 'dir' }, { enums: { dir: ARROW_DIRS } }),
|
|
257
278
|
accordion: schema(['items'], { ...nodeFields, items: 'array' }, {}, { nested: { items: accordionHolderSchema } }),
|
|
258
279
|
audio: schema(['src'], { ...nodeFields, src: 'string', alt: 'string', loop: 'boolean' }, { url: 'src', link: 'src' }),
|
|
259
280
|
avatar: schema(['name'], { ...nodeFields, name: 'string', color: 'string' }),
|
|
@@ -267,7 +288,9 @@ export const COMPONENT_SCHEMAS: Readonly<Record<string, ComponentSchema>> = {
|
|
|
267
288
|
// badge uses `warn`), so models cross-write them onto callout — map them
|
|
268
289
|
// onto the closest canonical tone instead of failing the enum (issue #186).
|
|
269
290
|
callout: schema(['content'], { ...nodeFields, title: 'string', content: 'string', tone: 'string' }, { kind: 'tone', text: 'content', body: 'content', desc: 'content' }, { enums: { tone: CALLOUT_TONES }, valueAliases: { tone: { danger: 'error', warn: 'warning' } } }),
|
|
270
|
-
|
|
291
|
+
// `flat` drops the elevation/shadow: figure panels must read as printed
|
|
292
|
+
// blocks, not as floating cards (the reference diagrams are drawn flat).
|
|
293
|
+
card: schema(['items'], { ...nodeFields, title: 'string', eyebrow: 'string', items: 'nodes', tone: 'string', accent: 'string', flat: 'boolean' }, { label: 'title', content: 'items' }, { enums: { tone: CARD_TONES } }),
|
|
271
294
|
chart: schema([], {
|
|
272
295
|
...nodeFields,
|
|
273
296
|
kind: 'string',
|
|
@@ -290,7 +313,7 @@ export const COMPONENT_SCHEMAS: Readonly<Record<string, ComponentSchema>> = {
|
|
|
290
313
|
}),
|
|
291
314
|
checkbox: schema(['label'], { ...nodeFields, label: 'string', checked: 'boolean', action: 'string', group: 'string' }),
|
|
292
315
|
code: schema(['code'], { ...nodeFields, lang: 'string', code: 'string' }, { content: 'code', text: 'code' }),
|
|
293
|
-
col: schema(['items'], { ...nodeFields, items: 'nodes', gap: 'number' }),
|
|
316
|
+
col: schema(['items'], { ...nodeFields, items: 'nodes', gap: 'number', width: 'number' }),
|
|
294
317
|
copy: schema(['text'], { ...nodeFields, label: 'string', text: 'string' }, { content: 'text', code: 'text', value: 'text' }),
|
|
295
318
|
diagram: schema(['kind', 'nodes'], { ...nodeFields, kind: 'string', variant: 'string', title: 'string', nodes: 'array', edges: 'array', zones: 'array', theme: 'object' }, {}, {
|
|
296
319
|
nested: { nodes: diagramNodeSchema, edges: diagramEdgeSchema, zones: diagramZoneSchema, theme: diagramThemeSchema },
|
|
@@ -299,7 +322,9 @@ export const COMPONENT_SCHEMAS: Readonly<Record<string, ComponentSchema>> = {
|
|
|
299
322
|
// `items` is the container field name every other component uses, so models
|
|
300
323
|
// reach for it here too; without the alias the whole node (and fence) drops.
|
|
301
324
|
diff: schema(['diffs'], { ...nodeFields, diffs: 'array' }, { items: 'diffs', files: 'diffs' }, { nested: { diffs: diffRecordSchema } }),
|
|
302
|
-
|
|
325
|
+
// `title`/`text` are what models reach for on a labeled separator; adopt
|
|
326
|
+
// them as aliases so the whole node (and fence) never drops for it.
|
|
327
|
+
divider: schema([], { ...nodeFields, label: 'string' }, { title: 'label', text: 'label' }),
|
|
303
328
|
echart: schema([], { ...nodeFields, title: 'string', height: 'number', preset: 'string', data: 'array', series: 'array', links: 'array', palette: 'array', option: 'object' }, {}, {
|
|
304
329
|
// `links` alone is valid: the sankey/graph presets are edge-driven.
|
|
305
330
|
oneOfRequired: [['option', 'data', 'series', 'links']],
|
|
@@ -307,7 +332,14 @@ export const COMPONENT_SCHEMAS: Readonly<Record<string, ComponentSchema>> = {
|
|
|
307
332
|
}),
|
|
308
333
|
'file-tree': schema(['items'], { ...nodeFields, items: 'array' }, { nodes: 'items' }, { nested: { items: fileTreeNodeSchema } }),
|
|
309
334
|
grid: schema(['items'], { ...nodeFields, cols: 'number', items: 'nodes' }),
|
|
310
|
-
|
|
335
|
+
// Figure primitives (v12). `blocks` exists so models stop hand-writing SVG
|
|
336
|
+
// coordinates for block diagrams; `icon` gives them the bundled glyph set
|
|
337
|
+
// instead of reaching for emoji. Both accept the field names models guess
|
|
338
|
+
// (`items`/`data` for rows, `icon` for name) so a near-miss never takes the
|
|
339
|
+
// whole fence down.
|
|
340
|
+
blocks: schema(['rows'], { ...nodeFields, rows: 'array', columns: 'number', caption: 'string', title: 'string' }, { items: 'rows', data: 'rows' }, { nested: { rows: blocksRowSchema } }),
|
|
341
|
+
icon: schema(['name'], { ...nodeFields, name: 'string', label: 'string', tone: 'string', size: 'number', tile: 'boolean' }, { icon: 'name' }, { enums: { tone: ICON_TONES } }),
|
|
342
|
+
image: schema(['src'], { ...nodeFields, src: 'string', alt: 'string', caption: 'string' }, { url: 'src', link: 'src' }),
|
|
311
343
|
input: schema([], { ...nodeFields, label: 'string', placeholder: 'string', value: 'string', inputType: 'string', action: 'string', id: 'string' }, {}, { enums: { inputType: INPUT_TYPES } }),
|
|
312
344
|
json: schema(['value'], { ...nodeFields, value: 'unknown' }),
|
|
313
345
|
keyvalue: schema(['pairs'], { ...nodeFields, pairs: 'array' }, { items: 'pairs', rows: 'pairs', entries: 'pairs' }, { nested: { pairs: keyValueRecordSchema } }),
|
|
@@ -322,7 +354,7 @@ export const COMPONENT_SCHEMAS: Readonly<Record<string, ComponentSchema>> = {
|
|
|
322
354
|
// the whole fence) is dropped.
|
|
323
355
|
quiz: schema(['question', 'options'], { ...nodeFields, question: 'string', options: 'array', explanation: 'string', id: 'string', action: 'string' }, { title: 'question', text: 'question', choices: 'options', items: 'options' }),
|
|
324
356
|
radio: schema(['options'], { ...nodeFields, label: 'string', options: 'array', selected: 'number', action: 'string', group: 'string', answer: 'unknown', explanation: 'string' }, { items: 'options' }),
|
|
325
|
-
row: schema(['items'], { ...nodeFields, items: 'nodes', wrap: 'boolean', spacer: 'boolean' }),
|
|
357
|
+
row: schema(['items'], { ...nodeFields, items: 'nodes', wrap: 'boolean', spacer: 'boolean', justify: 'string' }, {}, { enums: { justify: ROW_JUSTIFY } }),
|
|
326
358
|
scene3d: schema(['meshes'], { ...nodeFields, title: 'string', meshes: 'array', ambient: 'number', background: 'string' }, {}, { nested: { meshes: sceneMeshSchema } }),
|
|
327
359
|
select: schema(['options'], { ...nodeFields, label: 'string', options: 'array', action: 'string', selected: 'number', id: 'string' }, { items: 'options' }),
|
|
328
360
|
slider: schema([], { ...nodeFields, label: 'string', min: 'number', max: 'number', step: 'number', value: 'number', action: 'string', id: 'string' }),
|
|
@@ -343,7 +375,7 @@ export const COMPONENT_SCHEMAS: Readonly<Record<string, ComponentSchema>> = {
|
|
|
343
375
|
switch: schema(['label'], { ...nodeFields, label: 'string', checked: 'boolean', action: 'string' }),
|
|
344
376
|
table: schema(['columns', 'rows'], { ...nodeFields, columns: 'array', rows: 'array', types: 'array', total: 'boolean', details: 'array', filter: 'string', filterColumn: 'number', sortField: 'string', export: 'boolean' }, { headers: 'columns', data: 'rows', items: 'rows' }),
|
|
345
377
|
tabs: schema(['tabs'], { ...nodeFields, tabs: 'array' }, {}, { nested: { tabs: tabHolderSchema } }),
|
|
346
|
-
text: schema(['content'], { ...nodeFields, content: 'string', size: 'string', center: 'boolean' }, { text: 'content' }, { enums: { size: TEXT_SIZES } }),
|
|
378
|
+
text: schema(['content'], { ...nodeFields, content: 'string', size: 'string', center: 'boolean', align: 'string', tone: 'string', mono: 'boolean' }, { text: 'content' }, { enums: { size: TEXT_SIZES, align: TEXT_ALIGNS, tone: TEXT_TONES } }),
|
|
347
379
|
textarea: schema([], { ...nodeFields, label: 'string', placeholder: 'string', rows: 'number', value: 'string', action: 'string', id: 'string' }),
|
|
348
380
|
timeline: schema(['items'], { ...nodeFields, items: 'array' }, {}, { nested: { items: timelineRecordSchema } }),
|
|
349
381
|
video: schema(['src'], { ...nodeFields, src: 'string', alt: 'string', poster: 'string', loop: 'boolean', muted: 'boolean', aspectRatio: 'string' }, { url: 'src', link: 'src' }, { enums: { aspectRatio: MEDIA_ASPECT_RATIOS } }),
|
package/src/client/guard.ts
CHANGED
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
BADGE_TONES, BUTTON_TONES, CALLOUT_TONES, CARD_TONES, CHART_KINDS, COMPONENT_SCHEMAS, HERO_TONES,
|
|
25
25
|
DIAGRAM_EDGE_KINDS, DIAGRAM_KINDS, DIAGRAM_NODE_TYPES, DIAGRAM_ROUTES, DIAGRAM_VARIANTS,
|
|
26
26
|
ECHART_PRESETS, FILE_TYPES, GENUI_NATIVE_TYPES, GENUI_SPEC_SCHEMA, INPUT_TYPES,
|
|
27
|
-
MEDIA_ASPECT_RATIOS, MESH_SHAPES, PLOT_KINDS, PROGRESS_VARIANTS, TABLE_CELL_TYPES, TEXT_SIZES,
|
|
27
|
+
ARROW_DIRS, BLOCKS_VARIANTS, BLOCK_CELL_TONES, ICON_TONES, MEDIA_ASPECT_RATIOS, MESH_SHAPES, PLOT_KINDS, PROGRESS_VARIANTS, ROW_JUSTIFY, TABLE_CELL_TYPES, TEXT_ALIGNS, TEXT_SIZES, TEXT_TONES,
|
|
28
28
|
} from './genui-runtime/schema.ts'
|
|
29
29
|
import type { ComponentFieldKind, ComponentRecordSchema, ComponentSchema } from './genui-runtime/schema.ts'
|
|
30
30
|
import { normalizeGenuiSpec } from './genui-runtime/normalize.ts'
|
|
@@ -33,7 +33,8 @@ import type { GenuiDiagnostic } from './genui-runtime/diagnostics.ts'
|
|
|
33
33
|
import { GENUI_LIMITS } from './genui-runtime/limits.ts'
|
|
34
34
|
import { analyzeSubmissionRegistry } from './submission-registry.ts'
|
|
35
35
|
import { isTableDetailReachable, prepareTableRows, tableRowsForDetails } from './table-details.ts'
|
|
36
|
-
import { color, enu, int, num, obj, opt,
|
|
36
|
+
import { color, enu, int, num, obj, opt, safeMediaSrc, str } from './genui-runtime/value-utils.ts'
|
|
37
|
+
import { classifyLinkTarget } from './file-link.ts'
|
|
37
38
|
|
|
38
39
|
/** Result of `validateGenuiSpec`. */
|
|
39
40
|
export interface GenuiValidation {
|
|
@@ -269,13 +270,94 @@ function repairNodeFields(value: unknown, ctx: RepairCtx, depth: number): GenuiN
|
|
|
269
270
|
case 'text': {
|
|
270
271
|
const content = str(v.content, GENUI_LIMITS.maxString) ?? str(v.text, GENUI_LIMITS.maxString)
|
|
271
272
|
if (content === undefined) return null
|
|
272
|
-
|
|
273
|
+
// `center: true` is the legacy shorthand; a display-level size is the
|
|
274
|
+
// one-per-answer focal tier (B1), so it rides the same enum gate.
|
|
275
|
+
return {
|
|
276
|
+
type: 'text', content,
|
|
277
|
+
...opt('size', enu(v.size, TEXT_SIZES)),
|
|
278
|
+
...opt('align', enu(v.align, TEXT_ALIGNS)),
|
|
279
|
+
...opt('tone', enu(v.tone, TEXT_TONES)),
|
|
280
|
+
...opt('mono', v.mono === true ? true : undefined),
|
|
281
|
+
...opt('center', v.center === true ? true : undefined),
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
case 'icon': {
|
|
285
|
+
// `name` 是原型链攻击面(渲染器用 Object.hasOwn 兜住),但长度仍要截断;
|
|
286
|
+
// `size` 走 clamp。未知名字不在这里判死——渲染层降级成圆点。
|
|
287
|
+
const name = str(v.name, 64)
|
|
288
|
+
if (name === undefined) return null
|
|
289
|
+
return {
|
|
290
|
+
type: 'icon', name,
|
|
291
|
+
...opt('label', str(v.label, GENUI_LIMITS.maxString)),
|
|
292
|
+
...opt('tone', enu(v.tone, ICON_TONES)),
|
|
293
|
+
...opt('size', int(v.size, 8, 96)),
|
|
294
|
+
...opt('tile', v.tile === true ? true : undefined),
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
case 'blocks': {
|
|
298
|
+
// rows/cells 是数据不是节点,此前走 default 透传,于是颜色绕过了
|
|
299
|
+
// color()/SAFE_COLOR_RE、字符串绕过了 maxString。这里补齐:
|
|
300
|
+
// 颜色只接受字面色或宿主令牌,字符串按 maxString 截断,行/格按 limits 截断。
|
|
301
|
+
if (!Array.isArray(v.rows)) return null
|
|
302
|
+
const rows = v.rows.slice(0, GENUI_LIMITS.maxBlocksRows).flatMap((entry) => {
|
|
303
|
+
const row = obj(entry)
|
|
304
|
+
if (row === undefined || !Array.isArray(row.cells)) return []
|
|
305
|
+
const cells = row.cells.slice(0, GENUI_LIMITS.maxBlocksCells).map((cell) => {
|
|
306
|
+
if (cell === null) return null
|
|
307
|
+
if (typeof cell === 'string') return str(cell, GENUI_LIMITS.maxString) ?? ''
|
|
308
|
+
const holder = obj(cell)
|
|
309
|
+
if (holder === undefined) return null
|
|
310
|
+
const text = str(holder.text, GENUI_LIMITS.maxString)
|
|
311
|
+
if (text === undefined) return null
|
|
312
|
+
return {
|
|
313
|
+
text,
|
|
314
|
+
...opt('color', color(holder.color)),
|
|
315
|
+
...opt('tone', enu(holder.tone, BLOCK_CELL_TONES)),
|
|
316
|
+
...opt('sub', str(holder.sub, 128)),
|
|
317
|
+
}
|
|
318
|
+
})
|
|
319
|
+
return [{
|
|
320
|
+
cells,
|
|
321
|
+
...opt('label', str(row.label, 128)),
|
|
322
|
+
...opt('color', color(row.color)),
|
|
323
|
+
...opt('variant', enu(row.variant, BLOCKS_VARIANTS)),
|
|
324
|
+
}]
|
|
325
|
+
})
|
|
326
|
+
if (rows.length === 0) return null
|
|
327
|
+
return {
|
|
328
|
+
type: 'blocks', rows,
|
|
329
|
+
...opt('columns', int(v.columns, 1, GENUI_LIMITS.maxBlocksCells)),
|
|
330
|
+
...opt('title', str(v.title, GENUI_LIMITS.maxString)),
|
|
331
|
+
...opt('caption', str(v.caption, GENUI_LIMITS.maxString)),
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
case 'arrow': {
|
|
335
|
+
return {
|
|
336
|
+
type: 'arrow',
|
|
337
|
+
...opt('dir', enu(v.dir, ARROW_DIRS)),
|
|
338
|
+
...opt('length', int(v.length, 16, 96)),
|
|
339
|
+
...opt('label', str(v.label, 200)),
|
|
340
|
+
}
|
|
273
341
|
}
|
|
274
342
|
case 'row': {
|
|
275
|
-
return {
|
|
343
|
+
return {
|
|
344
|
+
type: 'row',
|
|
345
|
+
items: repairItems(v.items, ctx, depth + 1),
|
|
346
|
+
...opt('wrap', v.wrap === true ? true : undefined),
|
|
347
|
+
...opt('spacer', v.spacer === true ? true : undefined),
|
|
348
|
+
// Repair rebuilds every node from a hand-written field list, so a
|
|
349
|
+
// schema-only addition is silently dropped here. Keep the two in sync:
|
|
350
|
+
// figure headers need `justify: "center"` (icon + title over a caption).
|
|
351
|
+
...opt('justify', enu(v.justify, ROW_JUSTIFY)),
|
|
352
|
+
}
|
|
276
353
|
}
|
|
277
354
|
case 'col': {
|
|
278
|
-
return {
|
|
355
|
+
return {
|
|
356
|
+
type: 'col',
|
|
357
|
+
items: repairItems(v.items, ctx, depth + 1),
|
|
358
|
+
...opt('gap', num(v.gap, 0, 96)),
|
|
359
|
+
...opt('width', num(v.width, 1, 100)),
|
|
360
|
+
}
|
|
279
361
|
}
|
|
280
362
|
case 'grid': {
|
|
281
363
|
return { type: 'grid', cols: int(v.cols, 1, GENUI_LIMITS.maxGridCols) ?? 1, items: repairItems(v.items, ctx, depth + 1) }
|
|
@@ -284,9 +366,11 @@ function repairNodeFields(value: unknown, ctx: RepairCtx, depth: number): GenuiN
|
|
|
284
366
|
return {
|
|
285
367
|
type: 'card',
|
|
286
368
|
items: repairItems(v.items, ctx, depth + 1),
|
|
369
|
+
...opt('eyebrow', str(v.eyebrow, 64)),
|
|
287
370
|
...opt('title', str(v.title, GENUI_LIMITS.maxString)),
|
|
288
371
|
...opt('tone', enu(v.tone, CARD_TONES)),
|
|
289
372
|
...opt('accent', color(v.accent)),
|
|
373
|
+
...opt('flat', v.flat === true ? true : undefined),
|
|
290
374
|
}
|
|
291
375
|
}
|
|
292
376
|
case 'button': {
|
|
@@ -336,7 +420,9 @@ function repairNodeFields(value: unknown, ctx: RepairCtx, depth: number): GenuiN
|
|
|
336
420
|
case 'link': {
|
|
337
421
|
const label = str(v.label, GENUI_LIMITS.maxString)
|
|
338
422
|
if (label === undefined) return null
|
|
339
|
-
|
|
423
|
+
const target = classifyLinkTarget(v.href)
|
|
424
|
+
const href = target.type === 'external' ? target.href : target.type === 'file' ? String(v.href).trim() : undefined
|
|
425
|
+
return { type: 'link', label, ...opt('href', href) }
|
|
340
426
|
}
|
|
341
427
|
case 'image': {
|
|
342
428
|
const src = safeMediaSrc(v.src)
|
|
@@ -344,6 +430,7 @@ function repairNodeFields(value: unknown, ctx: RepairCtx, depth: number): GenuiN
|
|
|
344
430
|
return {
|
|
345
431
|
type: 'image', src,
|
|
346
432
|
...opt('alt', str(v.alt, GENUI_LIMITS.maxString)),
|
|
433
|
+
...opt('caption', str(v.caption, GENUI_LIMITS.maxString)),
|
|
347
434
|
}
|
|
348
435
|
}
|
|
349
436
|
case 'audio': {
|
|
@@ -407,7 +494,7 @@ function repairNodeFields(value: unknown, ctx: RepairCtx, depth: number): GenuiN
|
|
|
407
494
|
...opt('target', num(v.target, 0, 100)),
|
|
408
495
|
}
|
|
409
496
|
}
|
|
410
|
-
case 'divider': return { type: 'divider' }
|
|
497
|
+
case 'divider': return { type: 'divider', ...opt('label', str(v.label, 64)) }
|
|
411
498
|
case 'spacer': return { type: 'spacer' }
|
|
412
499
|
case 'avatar': {
|
|
413
500
|
const name = str(v.name, 64)
|
|
@@ -1290,12 +1377,19 @@ export const GENUI_NODE_TYPES: ReadonlySet<string> = GENUI_NATIVE_TYPES
|
|
|
1290
1377
|
* white-listed string, descending the same containers `countGenuiNodes`
|
|
1291
1378
|
* walks. Callers can inspect field semantics or compare the count with the
|
|
1292
1379
|
* repaired tree without maintaining another traversal.
|
|
1380
|
+
*
|
|
1381
|
+
* With `familyCaps` (default) the traversal applies the same per-family
|
|
1382
|
+
* policy caps repair enforces (tabs ≤ maxTabs, accordion items ≤
|
|
1383
|
+
* maxAccordionItems): nodes beyond a cap are policy-truncated, not defects,
|
|
1384
|
+
* so the declared-vs-rendered ledger must not count them as vanished (#298).
|
|
1293
1385
|
*/
|
|
1294
1386
|
function visitDeclaredGenuiNodes(
|
|
1295
1387
|
value: unknown,
|
|
1296
1388
|
cap: number,
|
|
1297
1389
|
visit: (node: Record<string, unknown>, at: string) => void,
|
|
1390
|
+
options: { familyCaps?: boolean } = {},
|
|
1298
1391
|
): number {
|
|
1392
|
+
const familyCaps = options.familyCaps !== false
|
|
1299
1393
|
let count = 0
|
|
1300
1394
|
const declared = (candidate: unknown): boolean => {
|
|
1301
1395
|
const o = obj(candidate)
|
|
@@ -1315,11 +1409,13 @@ function visitDeclaredGenuiNodes(
|
|
|
1315
1409
|
count += 1
|
|
1316
1410
|
visit(v, at)
|
|
1317
1411
|
if (v.type === 'tabs' && Array.isArray(v.tabs)) {
|
|
1318
|
-
|
|
1412
|
+
const tabCount = familyCaps ? Math.min(v.tabs.length, GENUI_LIMITS.maxTabs) : v.tabs.length
|
|
1413
|
+
for (let tab = 0; tab < tabCount; tab++) {
|
|
1319
1414
|
walkItemsOf(v.tabs[tab], `${at}.tabs[${tab}]`)
|
|
1320
1415
|
}
|
|
1321
1416
|
} else if (v.type === 'accordion' && Array.isArray(v.items)) {
|
|
1322
|
-
|
|
1417
|
+
const rowCount = familyCaps ? Math.min(v.items.length, GENUI_LIMITS.maxAccordionItems) : v.items.length
|
|
1418
|
+
for (let row = 0; row < rowCount; row++) {
|
|
1323
1419
|
walkItemsOf(v.items[row], `${at}.items[${row}]`)
|
|
1324
1420
|
}
|
|
1325
1421
|
} else if ((v.type === 'row' || v.type === 'col' || v.type === 'grid' || v.type === 'card') && Array.isArray(v.items)) {
|
|
@@ -1355,10 +1451,11 @@ function visitDeclaredGenuiNodes(
|
|
|
1355
1451
|
* Count white-listed nodes declared by a raw spec before repair drops invalid entries.
|
|
1356
1452
|
* @param value - raw GenUI spec.
|
|
1357
1453
|
* @param cap - traversal ceiling.
|
|
1454
|
+
* @param options - `familyCaps: false` counts beyond per-family policy caps too.
|
|
1358
1455
|
* @returns declared node count up to the ceiling.
|
|
1359
1456
|
*/
|
|
1360
|
-
export function countDeclaredGenuiNodes(value: unknown, cap = Number.POSITIVE_INFINITY): number {
|
|
1361
|
-
return visitDeclaredGenuiNodes(value, cap, () => {})
|
|
1457
|
+
export function countDeclaredGenuiNodes(value: unknown, cap = Number.POSITIVE_INFINITY, options: { familyCaps?: boolean } = {}): number {
|
|
1458
|
+
return visitDeclaredGenuiNodes(value, cap, () => {}, options)
|
|
1362
1459
|
}
|
|
1363
1460
|
|
|
1364
1461
|
/** Count native nodes that survived repair, excluding opaque custom nodes. */
|
|
@@ -1485,7 +1582,14 @@ export function processGenuiSpec(value: unknown): GenuiProcessResult {
|
|
|
1485
1582
|
const normalized = normalizeGenuiSpec(value)
|
|
1486
1583
|
const repaired = repairCanonicalGenuiSpec(normalized.value)
|
|
1487
1584
|
const validation = validateCanonicalGenuiSpec(normalized.value)
|
|
1585
|
+
// Policy-aware ledger (#298): nodes beyond a per-family cap (tabs ≤
|
|
1586
|
+
// maxTabs, accordion items ≤ maxAccordionItems) are truncated BY DESIGN, so
|
|
1587
|
+
// they are not counted as "declared but vanished" — otherwise the fence
|
|
1588
|
+
// below would always degrade to a code block and the truncation in repair
|
|
1589
|
+
// could never take effect. The uncapped pass measures the truncation for
|
|
1590
|
+
// the teaching warning instead.
|
|
1488
1591
|
const declaredNativeCount = countDeclaredGenuiNodes(normalized.value, GENUI_LIMITS.maxNodes + 1)
|
|
1592
|
+
const uncappedDeclaredCount = countDeclaredGenuiNodes(normalized.value, GENUI_LIMITS.maxNodes + 1, { familyCaps: false })
|
|
1489
1593
|
const renderedNativeCount = repaired === null ? 0 : countRenderedNativeGenuiNodes(repaired)
|
|
1490
1594
|
const renderedTotalCount = repaired === null ? 0 : countGenuiNodes(repaired)
|
|
1491
1595
|
// The shared public validator preserves its historical diagnostic for an
|
|
@@ -1498,13 +1602,21 @@ export function processGenuiSpec(value: unknown): GenuiProcessResult {
|
|
|
1498
1602
|
if (declaredNativeCount > renderedNativeCount) {
|
|
1499
1603
|
errors.push(`repair dropped ${declaredNativeCount - renderedNativeCount} declared native node(s): declared ${declaredNativeCount}, rendered ${renderedNativeCount}`)
|
|
1500
1604
|
}
|
|
1605
|
+
const warnings: GenuiDiagnostic[] = [...normalized.warnings, ...diagnoseUnknownGenuiFields(normalized.value)]
|
|
1606
|
+
if (uncappedDeclaredCount > declaredNativeCount) {
|
|
1607
|
+
warnings.push({
|
|
1608
|
+
kind: 'truncated',
|
|
1609
|
+
path: 'spec',
|
|
1610
|
+
message: `策略上限截断:${uncappedDeclaredCount - declaredNativeCount} 个声明节点超出 tabs ≤ ${GENUI_LIMITS.maxTabs} / accordion ≤ ${GENUI_LIMITS.maxAccordionItems} 的上限,未渲染;围栏照常渲染,重发时可拆分为多个组件`,
|
|
1611
|
+
})
|
|
1612
|
+
}
|
|
1501
1613
|
return {
|
|
1502
1614
|
value: normalized.value,
|
|
1503
1615
|
normalized: normalized.value,
|
|
1504
1616
|
repaired,
|
|
1505
1617
|
spec: repaired,
|
|
1506
1618
|
errors: [...new Set(errors)],
|
|
1507
|
-
warnings
|
|
1619
|
+
warnings,
|
|
1508
1620
|
// Compatibility fields retain their historical meanings: declaredCount
|
|
1509
1621
|
// is native declarations, while renderedCount is the total rendered tree.
|
|
1510
1622
|
declaredCount: declaredNativeCount,
|
|
@@ -1894,6 +2006,12 @@ function validateNode(value: unknown, depth: number, at: string, errors: string[
|
|
|
1894
2006
|
case 'diff':
|
|
1895
2007
|
if (!Array.isArray(v.diffs)) errors.push(`${at}: type 'diff' requires diffs (array)`)
|
|
1896
2008
|
break
|
|
2009
|
+
case 'divider':
|
|
2010
|
+
case 'spacer':
|
|
2011
|
+
// No required fields; declared-field kinds are covered by the registry
|
|
2012
|
+
// check below. Missing cases here made validate_dsh_ui reject ANY fence
|
|
2013
|
+
// containing them as "unknown type" (found via the divider.label test).
|
|
2014
|
+
break
|
|
1897
2015
|
case 'json':
|
|
1898
2016
|
if (!('value' in v)) errors.push(`${at}: type 'json' requires value`)
|
|
1899
2017
|
break
|
|
@@ -1937,6 +2055,36 @@ function validateNode(value: unknown, depth: number, at: string, errors: string[
|
|
|
1937
2055
|
if (typeof v.question !== 'string') errors.push(`${at}: type 'quiz' requires question (string)`)
|
|
1938
2056
|
if (!Array.isArray(v.options)) errors.push(`${at}: type 'quiz' requires options (array)`)
|
|
1939
2057
|
break
|
|
2058
|
+
case 'blocks': {
|
|
2059
|
+
// cells 是联合类型(string | null | record),无法挂到 schema 的 nested 上,
|
|
2060
|
+
// 所以在这里显式校验对象那一半的形状与枚举。
|
|
2061
|
+
if (!Array.isArray(v.rows)) { errors.push(`${at}: type 'blocks' requires rows (array)`); break }
|
|
2062
|
+
isNum('columns')
|
|
2063
|
+
v.rows.forEach((entry, i) => {
|
|
2064
|
+
const row = obj(entry)
|
|
2065
|
+
if (row === undefined) { errors.push(`${at}.rows[${i}] must be an object`); return }
|
|
2066
|
+
if (!Array.isArray(row.cells)) { errors.push(`${at}.rows[${i}].cells must be an array`); return }
|
|
2067
|
+
row.cells.forEach((cell, j) => {
|
|
2068
|
+
if (cell === null || typeof cell === 'string') return
|
|
2069
|
+
const holder = obj(cell)
|
|
2070
|
+
if (holder === undefined) { errors.push(`${at}.rows[${i}].cells[${j}] must be a string, null, or object`); return }
|
|
2071
|
+
if (typeof holder.text !== 'string') errors.push(`${at}.rows[${i}].cells[${j}].text must be a string`)
|
|
2072
|
+
if (holder.tone !== undefined && !BLOCK_CELL_TONES.includes(holder.tone as never)) {
|
|
2073
|
+
errors.push(`${at}.rows[${i}].cells[${j}].tone must be one of ${BLOCK_CELL_TONES.join(', ')}`)
|
|
2074
|
+
}
|
|
2075
|
+
if (holder.color !== undefined && color(holder.color) === undefined) {
|
|
2076
|
+
errors.push(`${at}.rows[${i}].cells[${j}].color must be a literal colour or host token`)
|
|
2077
|
+
}
|
|
2078
|
+
})
|
|
2079
|
+
})
|
|
2080
|
+
break
|
|
2081
|
+
}
|
|
2082
|
+
case 'icon':
|
|
2083
|
+
if (typeof v.name !== 'string') errors.push(`${at}: type 'icon' requires name (string)`)
|
|
2084
|
+
isNum('size')
|
|
2085
|
+
break
|
|
2086
|
+
case 'arrow':
|
|
2087
|
+
break
|
|
1940
2088
|
case 'diagram':
|
|
1941
2089
|
if (typeof v.kind !== 'string') errors.push(`${at}: type 'diagram' requires kind (string)`)
|
|
1942
2090
|
if (!Array.isArray(v.nodes)) errors.push(`${at}: type 'diagram' requires nodes (array)`)
|
|
@@ -1954,9 +2102,16 @@ function validateNode(value: unknown, depth: number, at: string, errors: string[
|
|
|
1954
2102
|
isNum('height')
|
|
1955
2103
|
break
|
|
1956
2104
|
default:
|
|
1957
|
-
//
|
|
1958
|
-
//
|
|
1959
|
-
|
|
2105
|
+
// Registered native types (icon/blocks/arrow/…) reach here because this
|
|
2106
|
+
// switch is a second, hand-written table. Falling through to "unknown
|
|
2107
|
+
// type" made validateGenuiSpec() answer false for perfectly valid specs
|
|
2108
|
+
// — the render pipeline only survived because processGenuiSpec filters
|
|
2109
|
+
// that one error string. Consult the schema instead: anything registered
|
|
2110
|
+
// is validated by validateRegistryFields below, and only genuinely
|
|
2111
|
+
// unregistered types are reported as custom-renderer unknowns.
|
|
2112
|
+
if (!Object.hasOwn(COMPONENT_SCHEMAS, type)) {
|
|
2113
|
+
errors.push(`${at}: unknown type '${type}' (custom renderer?)`)
|
|
2114
|
+
}
|
|
1960
2115
|
}
|
|
1961
2116
|
const definition = COMPONENT_SCHEMAS[type]
|
|
1962
2117
|
if (definition !== undefined) {
|
package/src/client/i18n/en.ts
CHANGED
|
@@ -288,6 +288,10 @@ export const EN = {
|
|
|
288
288
|
// ------------------------------------------------- component chrome
|
|
289
289
|
'block.copyMarkdown': 'Copy Markdown',
|
|
290
290
|
'block.copyCsv': 'Copy CSV',
|
|
291
|
+
'block.table.expandDetails': 'Expand details for {label}',
|
|
292
|
+
'block.table.collapseDetails': 'Collapse details for {label}',
|
|
293
|
+
'block.table.expandGroup': 'Expand group {label}',
|
|
294
|
+
'block.table.collapseGroup': 'Collapse group {label}',
|
|
291
295
|
'block.total': 'Total',
|
|
292
296
|
'block.filteredRows': '{visible} / {total} rows after filtering',
|
|
293
297
|
'block.filterMatch': '{shown} / {total} matched',
|
|
@@ -303,7 +307,7 @@ export const EN = {
|
|
|
303
307
|
'block.svgPreview': 'Preview',
|
|
304
308
|
'block.svgSource': 'Source',
|
|
305
309
|
'block.svgError': 'SVG could not be displayed — showing the source instead',
|
|
306
|
-
'block.mermaidError': '
|
|
310
|
+
'block.mermaidError': 'Diagram rendering failed — showing the source instead',
|
|
307
311
|
'block.mermaidLoading': 'Rendering…',
|
|
308
312
|
'block.scene3dLoading': 'Loading 3D scene…',
|
|
309
313
|
'block.scene3dError': '3D rendering failed',
|
package/src/client/i18n/index.ts
CHANGED
|
@@ -79,7 +79,7 @@ export const GENUI_LOCALE_NS = 'genui'
|
|
|
79
79
|
* Hosts WITHOUT the locale service degrade silently to browser detection —
|
|
80
80
|
* the service is read optionally, never declared in `inject`, because a
|
|
81
81
|
* declared-but-absent service parks the fiber forever and would kill all
|
|
82
|
-
* GenUI rendering
|
|
82
|
+
* GenUI rendering when the host has no locale service.
|
|
83
83
|
*
|
|
84
84
|
* @param ctx - client cordis context (read optionally).
|
|
85
85
|
* @returns disposer removing the registrations and the subscription.
|
package/src/client/i18n/zh.ts
CHANGED
|
@@ -283,6 +283,10 @@ export const ZH: Record<keyof typeof EN, string> = {
|
|
|
283
283
|
// ------------------------------------------------- component chrome
|
|
284
284
|
'block.copyMarkdown': '复制 Markdown',
|
|
285
285
|
'block.copyCsv': '复制 CSV',
|
|
286
|
+
'block.table.expandDetails': '展开 {label} 的明细',
|
|
287
|
+
'block.table.collapseDetails': '收起 {label} 的明细',
|
|
288
|
+
'block.table.expandGroup': '展开分组 {label}',
|
|
289
|
+
'block.table.collapseGroup': '收起分组 {label}',
|
|
286
290
|
'block.total': '合计',
|
|
287
291
|
'block.filteredRows': '筛选后 {visible} / {total} 行',
|
|
288
292
|
'block.filterMatch': '匹配 {shown} / {total} 项',
|
|
@@ -298,7 +302,7 @@ export const ZH: Record<keyof typeof EN, string> = {
|
|
|
298
302
|
'block.svgPreview': '预览',
|
|
299
303
|
'block.svgSource': '源码',
|
|
300
304
|
'block.svgError': 'SVG 无法显示,已降级显示源码',
|
|
301
|
-
'block.mermaidError': '
|
|
305
|
+
'block.mermaidError': '图表渲染失败,已显示源码',
|
|
302
306
|
'block.mermaidLoading': '渲染中…',
|
|
303
307
|
'block.scene3dLoading': '加载 3D 场景…',
|
|
304
308
|
'block.scene3dError': '3D 渲染失败',
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Icon asset-bundle entry: registers the FULL glyph catalogue on
|
|
3
|
+
* `window.__GenuiAssets__.icons`.
|
|
4
|
+
*
|
|
5
|
+
* Built as a standalone IIFE into `lib/assets/icons.js` and served by the
|
|
6
|
+
* plugin's node-half route; `icon-lazy` fetches it the first time a spec uses
|
|
7
|
+
* an `icon` name that is not in the 64-glyph inline set. Keeping it here (and
|
|
8
|
+
* not in the client bundle) is what stops ~1 MB of path data from riding
|
|
9
|
+
* along on every conversation load.
|
|
10
|
+
* @module @changfenhuang/dsh-genui/client/icons/asset-icons
|
|
11
|
+
*/
|
|
12
|
+
import { ICONS_FULL } from './icon-data-full.ts'
|
|
13
|
+
|
|
14
|
+
const win = globalThis as unknown as { __GenuiAssets__?: Record<string, unknown> }
|
|
15
|
+
const assets = win.__GenuiAssets__ ?? (win.__GenuiAssets__ = {})
|
|
16
|
+
assets.icons = ICONS_FULL
|