@sparkelf/dsh-genui 0.0.0-stage → 0.11.4-patch.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 +597 -0
- package/LICENSE +21 -0
- package/README.md +292 -2
- package/README.zh-CN.md +307 -0
- package/SKILL.md +261 -0
- package/cordis.patch.yml +9 -0
- package/demo-prompts.md +118 -0
- package/lib/assets/echarts-core.js +43 -0
- package/lib/assets/echarts-full.js +72 -0
- package/lib/assets/mermaid.js +3591 -0
- package/lib/assets/standalone-runtime.js +1506 -0
- package/lib/assets/three.js +3844 -0
- package/lib/client.js +405 -0
- package/lib/index.js +5187 -0
- package/lib/invariant.js +19 -0
- package/lib/types/client/EChartNode.d.ts +13 -0
- package/lib/types/client/ErrorBoundary.d.ts +30 -0
- package/lib/types/client/GenuiBlock.d.ts +9 -0
- package/lib/types/client/PlotBlock.d.ts +44 -0
- package/lib/types/client/TemplateDrawer.d.ts +7 -0
- package/lib/types/client/achievement-store.d.ts +35 -0
- package/lib/types/client/achievement-toast.d.ts +2 -0
- package/lib/types/client/achievements.d.ts +63 -0
- package/lib/types/client/action-context.d.ts +7 -0
- package/lib/types/client/artifact/ExportableGenuiBlock.d.ts +6 -0
- package/lib/types/client/artifact/create.d.ts +5 -0
- package/lib/types/client/artifact/download.d.ts +9 -0
- package/lib/types/client/artifact/html.d.ts +5 -0
- package/lib/types/client/artifact/index.d.ts +8 -0
- package/lib/types/client/artifact/json.d.ts +3 -0
- package/lib/types/client/artifact/parse.d.ts +3 -0
- package/lib/types/client/artifact/portability.d.ts +4 -0
- package/lib/types/client/artifact/standalone-theme.d.ts +2 -0
- package/lib/types/client/artifact/types.d.ts +33 -0
- package/lib/types/client/asset-echarts-core.d.ts +1 -0
- package/lib/types/client/asset-echarts.d.ts +17 -0
- package/lib/types/client/asset-loader.d.ts +33 -0
- package/lib/types/client/asset-mermaid.d.ts +1 -0
- package/lib/types/client/asset-three.d.ts +1 -0
- package/lib/types/client/blocks/advanced.d.ts +101 -0
- package/lib/types/client/blocks/basic.d.ts +22 -0
- package/lib/types/client/blocks/charts.d.ts +53 -0
- package/lib/types/client/blocks/checkbox.d.ts +17 -0
- package/lib/types/client/blocks/diagram/geometry.d.ts +73 -0
- package/lib/types/client/blocks/diagram/index.d.ts +5 -0
- package/lib/types/client/blocks/diagram/layout.d.ts +41 -0
- package/lib/types/client/blocks/diagram/theme.d.ts +37 -0
- package/lib/types/client/blocks/forms.d.ts +77 -0
- package/lib/types/client/blocks/image.d.ts +6 -0
- package/lib/types/client/blocks/render-node.d.ts +10 -0
- package/lib/types/client/blocks/state.d.ts +63 -0
- package/lib/types/client/blocks/svg.d.ts +4 -0
- package/lib/types/client/dom-fence.d.ts +30 -0
- package/lib/types/client/echarts-engine.d.ts +4 -0
- package/lib/types/client/echarts-lazy.d.ts +18 -0
- package/lib/types/client/embed.d.ts +10 -0
- package/lib/types/client/fence-render.d.ts +106 -0
- package/lib/types/client/gallery.d.ts +7 -0
- package/lib/types/client/genui-runtime/diagnostics.d.ts +18 -0
- package/lib/types/client/genui-runtime/index.d.ts +1 -0
- package/lib/types/client/genui-runtime/limits.d.ts +54 -0
- package/lib/types/client/genui-runtime/normalize.d.ts +15 -0
- package/lib/types/client/genui-runtime/schema.d.ts +87 -0
- package/lib/types/client/genui-runtime/value-utils.d.ts +18 -0
- package/lib/types/client/guard.d.ts +144 -0
- package/lib/types/client/i18n/en.d.ts +307 -0
- package/lib/types/client/i18n/index.d.ts +44 -0
- package/lib/types/client/i18n/runtime.d.ts +64 -0
- package/lib/types/client/i18n/zh.d.ts +8 -0
- package/lib/types/client/index.d.ts +36 -0
- package/lib/types/client/inline.d.ts +5 -0
- package/lib/types/client/interaction-store.d.ts +48 -0
- package/lib/types/client/mermaid-core.d.ts +8 -0
- package/lib/types/client/mermaid-lazy.d.ts +9 -0
- package/lib/types/client/mermaid-safe.d.ts +52 -0
- package/lib/types/client/panel-command.d.ts +34 -0
- package/lib/types/client/panel-store.d.ts +94 -0
- package/lib/types/client/panel.d.ts +18 -0
- package/lib/types/client/parse-partial.d.ts +63 -0
- package/lib/types/client/primitive-adapter.d.ts +4 -0
- package/lib/types/client/primitive-labels.d.ts +18 -0
- package/lib/types/client/safe-math.d.ts +43 -0
- package/lib/types/client/scene3d-core.d.ts +21 -0
- package/lib/types/client/scene3d-lazy.d.ts +8 -0
- package/lib/types/client/session-resolver.d.ts +8 -0
- package/lib/types/client/source-fence.d.ts +29 -0
- package/lib/types/client/spec.d.ts +709 -0
- package/lib/types/client/standalone/asset-loader.d.ts +2 -0
- package/lib/types/client/standalone/bootstrap-types.d.ts +9 -0
- package/lib/types/client/standalone/katex-style.d.ts +1 -0
- package/lib/types/client/standalone/primitive-adapter.d.ts +54 -0
- package/lib/types/client/standalone/runtime.d.ts +2 -0
- package/lib/types/client/submission-registry.d.ts +51 -0
- package/lib/types/client/svg-fence.d.ts +2 -0
- package/lib/types/client/table-details.d.ts +20 -0
- package/lib/types/client/templates.d.ts +41 -0
- package/lib/types/client/toolview.d.ts +7 -0
- package/lib/types/client/walk-spec.d.ts +3 -0
- package/lib/types/index.d.ts +1 -0
- package/lib/types/plugin/chart-contract.d.ts +9 -0
- package/lib/types/plugin/fence-feedback.d.ts +151 -0
- package/lib/types/plugin/genui-diagnostic.d.ts +13 -0
- package/lib/types/plugin/index.d.ts +35 -0
- package/lib/types/plugin/inline-content-diagnostic.d.ts +8 -0
- package/lib/types/plugin/invariant.d.ts +15 -0
- package/lib/types/plugin/tool.d.ts +27 -0
- package/lib/types/shared/fence-repair.d.ts +78 -0
- package/lib/types/shared/fence-resolve.d.ts +39 -0
- package/package.json +249 -4
- package/src/client/EChartNode.tsx +466 -0
- package/src/client/ErrorBoundary.tsx +67 -0
- package/src/client/GenuiBlock.module.css +2221 -0
- package/src/client/GenuiBlock.tsx +235 -0
- package/src/client/PlotBlock.module.css +171 -0
- package/src/client/PlotBlock.tsx +492 -0
- package/src/client/TemplateDrawer.module.css +152 -0
- package/src/client/TemplateDrawer.tsx +147 -0
- package/src/client/achievement-store.ts +151 -0
- package/src/client/achievement-toast.tsx +71 -0
- package/src/client/achievements.ts +160 -0
- package/src/client/action-context.ts +32 -0
- package/src/client/artifact/ArtifactExport.module.css +64 -0
- package/src/client/artifact/ExportableGenuiBlock.tsx +100 -0
- package/src/client/artifact/create.ts +69 -0
- package/src/client/artifact/download.ts +42 -0
- package/src/client/artifact/html.ts +157 -0
- package/src/client/artifact/index.ts +15 -0
- package/src/client/artifact/json.ts +6 -0
- package/src/client/artifact/parse.ts +32 -0
- package/src/client/artifact/portability.ts +47 -0
- package/src/client/artifact/standalone-theme.ts +94 -0
- package/src/client/artifact/types.ts +44 -0
- package/src/client/asset-echarts-core.ts +39 -0
- package/src/client/asset-echarts.ts +27 -0
- package/src/client/asset-loader.ts +96 -0
- package/src/client/asset-mermaid.ts +13 -0
- package/src/client/asset-three.ts +12 -0
- package/src/client/blocks/advanced.tsx +537 -0
- package/src/client/blocks/basic.tsx +121 -0
- package/src/client/blocks/charts.tsx +999 -0
- package/src/client/blocks/checkbox.tsx +61 -0
- package/src/client/blocks/diagram/geometry.ts +151 -0
- package/src/client/blocks/diagram/index.tsx +293 -0
- package/src/client/blocks/diagram/layout.ts +202 -0
- package/src/client/blocks/diagram/theme.ts +127 -0
- package/src/client/blocks/forms.tsx +531 -0
- package/src/client/blocks/image.tsx +28 -0
- package/src/client/blocks/render-node.tsx +494 -0
- package/src/client/blocks/state.ts +65 -0
- package/src/client/blocks/svg.tsx +66 -0
- package/src/client/dom-fence.tsx +1123 -0
- package/src/client/echarts-engine.ts +9 -0
- package/src/client/echarts-lazy.ts +41 -0
- package/src/client/embed.ts +19 -0
- package/src/client/fence-render.tsx +266 -0
- package/src/client/gallery.ts +215 -0
- package/src/client/genui-runtime/diagnostics.ts +165 -0
- package/src/client/genui-runtime/index.ts +1 -0
- package/src/client/genui-runtime/limits.ts +54 -0
- package/src/client/genui-runtime/normalize.ts +329 -0
- package/src/client/genui-runtime/schema.ts +352 -0
- package/src/client/genui-runtime/value-utils.ts +67 -0
- package/src/client/guard.ts +1965 -0
- package/src/client/i18n/en.ts +335 -0
- package/src/client/i18n/index.ts +125 -0
- package/src/client/i18n/runtime.ts +130 -0
- package/src/client/i18n/zh.ts +330 -0
- package/src/client/index.tsx +228 -0
- package/src/client/inline.ts +106 -0
- package/src/client/interaction-store.ts +127 -0
- package/src/client/mermaid-core.ts +158 -0
- package/src/client/mermaid-lazy.ts +31 -0
- package/src/client/mermaid-safe.ts +122 -0
- package/src/client/panel-command.ts +138 -0
- package/src/client/panel-store.ts +471 -0
- package/src/client/panel.tsx +287 -0
- package/src/client/parse-partial.ts +170 -0
- package/src/client/primitive-adapter.ts +13 -0
- package/src/client/primitive-labels.ts +55 -0
- package/src/client/safe-math.ts +298 -0
- package/src/client/scene3d-core.ts +195 -0
- package/src/client/scene3d-lazy.ts +26 -0
- package/src/client/session-resolver.ts +33 -0
- package/src/client/source-fence.ts +70 -0
- package/src/client/spec.ts +896 -0
- package/src/client/standalone/asset-loader.ts +9 -0
- package/src/client/standalone/bootstrap-types.ts +11 -0
- package/src/client/standalone/katex-style.ts +1 -0
- package/src/client/standalone/primitive-adapter.tsx +94 -0
- package/src/client/standalone/runtime.tsx +27 -0
- package/src/client/submission-registry.ts +150 -0
- package/src/client/svg-fence.tsx +39 -0
- package/src/client/table-details.ts +151 -0
- package/src/client/templates.ts +322 -0
- package/src/client/toolview.tsx +67 -0
- package/src/client/walk-spec.ts +43 -0
- package/src/css-modules.d.ts +5 -0
- package/src/index.ts +9 -0
- package/src/plugin/chart-contract.ts +13 -0
- package/src/plugin/fence-feedback.ts +655 -0
- package/src/plugin/genui-diagnostic.ts +112 -0
- package/src/plugin/index.ts +224 -0
- package/src/plugin/inline-content-diagnostic.ts +178 -0
- package/src/plugin/invariant.ts +30 -0
- package/src/plugin/node-shims.d.ts +31 -0
- package/src/plugin/tool.ts +424 -0
- package/src/shared/fence-repair.ts +536 -0
- package/src/shared/fence-resolve.ts +80 -0
- package/tsconfig.json +35 -0
- package/tsdown.config.ts +275 -0
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
/** Runtime metadata shared by GenUI normalization and diagnostics. */
|
|
2
|
+
|
|
3
|
+
export type ComponentFieldKind =
|
|
4
|
+
| 'string'
|
|
5
|
+
| 'string-or-null'
|
|
6
|
+
| 'number'
|
|
7
|
+
| 'boolean'
|
|
8
|
+
| 'nodes'
|
|
9
|
+
| 'array'
|
|
10
|
+
| 'object'
|
|
11
|
+
| 'unknown'
|
|
12
|
+
|
|
13
|
+
/** A conditional rule for fields whose presence depends on another field. */
|
|
14
|
+
export interface ComponentConditionalRule {
|
|
15
|
+
readonly kind: 'required-if'
|
|
16
|
+
readonly when: { readonly field: string; readonly equals: unknown }
|
|
17
|
+
readonly required: readonly string[]
|
|
18
|
+
readonly message?: string
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** A field rule that requires at least one member of a field group. */
|
|
22
|
+
export interface ComponentOneOfRule {
|
|
23
|
+
readonly kind: 'one-of-required'
|
|
24
|
+
readonly fields: readonly string[]
|
|
25
|
+
readonly message?: string
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Runtime metadata naming a component-specific semantic validator. */
|
|
29
|
+
export interface ComponentValidatorMetadata {
|
|
30
|
+
readonly name: string
|
|
31
|
+
readonly [key: string]: unknown
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Runtime schema for an object nested inside a native component field. */
|
|
35
|
+
export interface ComponentRecordSchema {
|
|
36
|
+
readonly required: readonly string[]
|
|
37
|
+
readonly fields: Readonly<Record<string, ComponentFieldKind>>
|
|
38
|
+
readonly enums: Readonly<Record<string, readonly string[]>>
|
|
39
|
+
readonly nested: Readonly<Record<string, ComponentRecordSchema>>
|
|
40
|
+
/** Field-name aliases applied to each record before validation/repair. */
|
|
41
|
+
readonly aliases: Readonly<Record<string, string>>
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface ComponentSchema {
|
|
45
|
+
readonly required: readonly string[]
|
|
46
|
+
readonly fields: Readonly<Record<string, ComponentFieldKind>>
|
|
47
|
+
readonly enums: Readonly<Record<string, readonly string[]>>
|
|
48
|
+
/** Explicit optional field kinds; `fields` remains the complete field map. */
|
|
49
|
+
readonly optional: Readonly<Record<string, ComponentFieldKind>>
|
|
50
|
+
readonly aliases: Readonly<Record<string, string>>
|
|
51
|
+
/** Written enum values deterministically mapped to canonical ones (field → value → canonical). */
|
|
52
|
+
readonly valueAliases: Readonly<Record<string, Readonly<Record<string, string>>>>
|
|
53
|
+
readonly oneOfRequired: readonly (readonly string[])[]
|
|
54
|
+
readonly conditionalRequired: readonly ComponentConditionalRule[]
|
|
55
|
+
readonly rules: readonly (ComponentOneOfRule | ComponentConditionalRule)[]
|
|
56
|
+
readonly nested: Readonly<Record<string, ComponentRecordSchema>>
|
|
57
|
+
readonly validator?: ComponentValidatorMetadata
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
/** Canonical enum domains shared by schema validation and repair. */
|
|
62
|
+
export const TEXT_SIZES = ['h1', 'h2', 'h3', 'body', 'muted', 'caption'] as const
|
|
63
|
+
export const BUTTON_TONES = ['primary', 'danger', 'success', 'ghost'] as const
|
|
64
|
+
export const BADGE_TONES = ['success', 'warn', 'danger', 'accent'] as const
|
|
65
|
+
export const INPUT_TYPES = ['text', 'email', 'password', 'color'] as const
|
|
66
|
+
export const CALLOUT_TONES = ['info', 'success', 'warning', 'error'] as const
|
|
67
|
+
export const CHART_KINDS = ['bars', 'line', 'donut'] as const
|
|
68
|
+
export const PLOT_KINDS = ['line', 'area', 'scatter'] as const
|
|
69
|
+
export const MEDIA_ASPECT_RATIOS = ['16:9', '4:3', '1:1', '9:16'] as const
|
|
70
|
+
export const MESH_SHAPES = ['box', 'sphere', 'cone', 'cylinder', 'torus'] as const
|
|
71
|
+
export const FILE_TYPES = ['file', 'dir'] as const
|
|
72
|
+
export const DIAGRAM_KINDS = [
|
|
73
|
+
'architecture', 'it-state', 'flowchart', 'sequence', 'state', 'er', 'timeline',
|
|
74
|
+
'swimlane', 'quadrant', 'radar', 'loop', 'nested', 'tree', 'org-chart', 'layers',
|
|
75
|
+
'venn', 'pyramid', 'bar', 'line', 'gantt', 'scatter', 'high-level', 'process',
|
|
76
|
+
'medallion', 'data-flow', 'dp-integration', 'dp-security-matrix',
|
|
77
|
+
] as const
|
|
78
|
+
export const DIAGRAM_NODE_TYPES = ['focal', 'backend', 'store', 'external', 'input', 'optional', 'security'] as const
|
|
79
|
+
export const DIAGRAM_VARIANTS = ['light', 'dark', 'editorial'] as const
|
|
80
|
+
export const DIAGRAM_EDGE_KINDS = ['solid', 'dashed', 'accent', 'link'] as const
|
|
81
|
+
export const DIAGRAM_ROUTES = ['auto', 'orthogonal', 'straight'] as const
|
|
82
|
+
export const ECHART_PRESETS = [
|
|
83
|
+
'bar', 'line', 'area', 'pie', 'scatter',
|
|
84
|
+
'radar', 'gauge', 'funnel', 'treemap', 'sankey', 'graph', 'heatmap', 'bigline', 'wordCloud',
|
|
85
|
+
] as const
|
|
86
|
+
/** Oversized single-number stat (one per fence as the visual anchor). */
|
|
87
|
+
export const STAT_SIZES = ['hero'] as const
|
|
88
|
+
/** Progress shapes: a track (default) or a circular gauge. */
|
|
89
|
+
export const PROGRESS_VARIANTS = ['bar', 'ring'] as const
|
|
90
|
+
/** Semantic card surfaces. */
|
|
91
|
+
export const CARD_TONES = ['info', 'success', 'warning', 'danger'] as const
|
|
92
|
+
/** Hero cover tones. */
|
|
93
|
+
export const HERO_TONES = ['accent', 'success', 'warning', 'danger'] as const
|
|
94
|
+
/** Table cell renderers (`table.types`, one entry per column). */
|
|
95
|
+
export const TABLE_CELL_TYPES = ['text', 'num', 'delta', 'bar', 'badge', 'spark', 'ring', 'index', 'group'] as const
|
|
96
|
+
|
|
97
|
+
const schema = (
|
|
98
|
+
required: readonly string[],
|
|
99
|
+
fields: Readonly<Record<string, ComponentFieldKind>>,
|
|
100
|
+
aliases: Readonly<Record<string, string>> = {},
|
|
101
|
+
options: {
|
|
102
|
+
oneOfRequired?: readonly (readonly string[])[]
|
|
103
|
+
conditionalRequired?: readonly ComponentConditionalRule[]
|
|
104
|
+
nested?: Readonly<Record<string, ComponentRecordSchema>>
|
|
105
|
+
enums?: Readonly<Record<string, readonly string[]>>
|
|
106
|
+
valueAliases?: Readonly<Record<string, Readonly<Record<string, string>>>>
|
|
107
|
+
validator?: ComponentValidatorMetadata
|
|
108
|
+
} = {},
|
|
109
|
+
): ComponentSchema => {
|
|
110
|
+
const optional = Object.fromEntries(
|
|
111
|
+
Object.entries(fields).filter(([field]) => field !== 'type' && !required.includes(field)),
|
|
112
|
+
) as Record<string, ComponentFieldKind>
|
|
113
|
+
const oneOfRequired = options.oneOfRequired ?? []
|
|
114
|
+
const conditionalRequired = options.conditionalRequired ?? []
|
|
115
|
+
const rules: Array<ComponentOneOfRule | ComponentConditionalRule> = [
|
|
116
|
+
...oneOfRequired.map(fieldsInRule => ({ kind: 'one-of-required' as const, fields: fieldsInRule })),
|
|
117
|
+
...conditionalRequired,
|
|
118
|
+
]
|
|
119
|
+
return {
|
|
120
|
+
required,
|
|
121
|
+
fields,
|
|
122
|
+
optional,
|
|
123
|
+
aliases,
|
|
124
|
+
valueAliases: options.valueAliases ?? {},
|
|
125
|
+
oneOfRequired,
|
|
126
|
+
conditionalRequired,
|
|
127
|
+
rules,
|
|
128
|
+
enums: options.enums ?? {},
|
|
129
|
+
nested: options.nested ?? {},
|
|
130
|
+
...(options.validator === undefined ? {} : { validator: options.validator }),
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const recordSchema = (
|
|
135
|
+
required: readonly string[],
|
|
136
|
+
fields: Readonly<Record<string, ComponentFieldKind>>,
|
|
137
|
+
nested: Readonly<Record<string, ComponentRecordSchema>> = {},
|
|
138
|
+
enums: Readonly<Record<string, readonly string[]>> = {},
|
|
139
|
+
aliases: Readonly<Record<string, string>> = {},
|
|
140
|
+
): ComponentRecordSchema => ({ required, fields, enums, nested, aliases })
|
|
141
|
+
|
|
142
|
+
const nodeFields = { type: 'string', span: 'number' } as const
|
|
143
|
+
|
|
144
|
+
const chartDatumSchema = recordSchema(['label', 'value'], {
|
|
145
|
+
label: 'string',
|
|
146
|
+
value: 'number',
|
|
147
|
+
color: 'string',
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
const chartSeriesSchema = recordSchema(['label', 'data'], {
|
|
151
|
+
label: 'string',
|
|
152
|
+
color: 'string',
|
|
153
|
+
data: 'array',
|
|
154
|
+
}, { data: chartDatumSchema })
|
|
155
|
+
|
|
156
|
+
const stepsRecordSchema = recordSchema(['title'], { title: 'string', desc: 'string' })
|
|
157
|
+
// `label` is what models write for the left-hand column (issue #186); the
|
|
158
|
+
// record otherwise fails "requires key" and the whole keyvalue drops.
|
|
159
|
+
const keyValueRecordSchema = recordSchema(['key', 'value'], { key: 'string', value: 'string' }, {}, {}, { label: 'key' })
|
|
160
|
+
const timelineRecordSchema = recordSchema(['title'], { title: 'string', desc: 'string', time: 'string' })
|
|
161
|
+
const diffRecordSchema = recordSchema(['path', 'newText'], { path: 'string', oldText: 'string-or-null', newText: 'string' })
|
|
162
|
+
const plotParamSchema = recordSchema(['name', 'value'], {
|
|
163
|
+
name: 'string', value: 'number', min: 'number', max: 'number', step: 'number', animateTo: 'number', durationMs: 'number', loop: 'boolean',
|
|
164
|
+
})
|
|
165
|
+
const plotSeriesSchema = recordSchema(['expr'], {
|
|
166
|
+
expr: 'string', label: 'string', color: 'string', kind: 'string', params: 'array',
|
|
167
|
+
}, { params: plotParamSchema }, { kind: PLOT_KINDS })
|
|
168
|
+
const sceneMeshSchema = recordSchema(['shape'], {
|
|
169
|
+
shape: 'string', color: 'string', position: 'array', rotation: 'array', scale: 'unknown', size: 'unknown',
|
|
170
|
+
}, {}, { shape: MESH_SHAPES })
|
|
171
|
+
|
|
172
|
+
function fileTreeRecordSchema(depth: number): ComponentRecordSchema {
|
|
173
|
+
return recordSchema(
|
|
174
|
+
['name'],
|
|
175
|
+
{ name: 'string', type: 'string', children: 'array' },
|
|
176
|
+
depth > 0 ? { children: fileTreeRecordSchema(depth - 1) } : {},
|
|
177
|
+
{ type: FILE_TYPES },
|
|
178
|
+
// Tree records read like outline items to models: they reach for `label`
|
|
179
|
+
// (and `desc`) instead of `name` (issue #186).
|
|
180
|
+
{ label: 'name' },
|
|
181
|
+
)
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const fileTreeNodeSchema = fileTreeRecordSchema(6)
|
|
185
|
+
|
|
186
|
+
const tabHolderSchema = recordSchema(['label', 'items'], {
|
|
187
|
+
label: 'string',
|
|
188
|
+
items: 'nodes',
|
|
189
|
+
content: 'nodes',
|
|
190
|
+
})
|
|
191
|
+
|
|
192
|
+
const accordionHolderSchema = recordSchema(['title', 'items'], {
|
|
193
|
+
title: 'string',
|
|
194
|
+
items: 'nodes',
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
const diagramNodeSchema = recordSchema(['id', 'label'], {
|
|
198
|
+
id: 'string',
|
|
199
|
+
label: 'string',
|
|
200
|
+
sub: 'string',
|
|
201
|
+
type: 'string',
|
|
202
|
+
x: 'number',
|
|
203
|
+
y: 'number',
|
|
204
|
+
w: 'number',
|
|
205
|
+
h: 'number',
|
|
206
|
+
tag: 'string',
|
|
207
|
+
}, {}, { type: DIAGRAM_NODE_TYPES })
|
|
208
|
+
|
|
209
|
+
const diagramEdgeSchema = recordSchema(['from', 'to'], {
|
|
210
|
+
from: 'string',
|
|
211
|
+
to: 'string',
|
|
212
|
+
label: 'string',
|
|
213
|
+
kind: 'string',
|
|
214
|
+
route: 'string',
|
|
215
|
+
}, {}, { kind: DIAGRAM_EDGE_KINDS, route: DIAGRAM_ROUTES })
|
|
216
|
+
|
|
217
|
+
const diagramZoneSchema = recordSchema(['label'], {
|
|
218
|
+
label: 'string',
|
|
219
|
+
x: 'number',
|
|
220
|
+
y: 'number',
|
|
221
|
+
w: 'number',
|
|
222
|
+
h: 'number',
|
|
223
|
+
})
|
|
224
|
+
|
|
225
|
+
const diagramThemeSchema = recordSchema([], {
|
|
226
|
+
paper: 'string',
|
|
227
|
+
'paper-2': 'string',
|
|
228
|
+
ink: 'string',
|
|
229
|
+
muted: 'string',
|
|
230
|
+
soft: 'string',
|
|
231
|
+
rule: 'string',
|
|
232
|
+
accent: 'string',
|
|
233
|
+
'accent-tint': 'string',
|
|
234
|
+
link: 'string',
|
|
235
|
+
})
|
|
236
|
+
|
|
237
|
+
/** Root GenUI specification metadata used by diagnostics. */
|
|
238
|
+
export const GENUI_SPEC_SCHEMA = schema(['items'], {
|
|
239
|
+
title: 'string',
|
|
240
|
+
gap: 'number',
|
|
241
|
+
panel: 'boolean',
|
|
242
|
+
append: 'boolean',
|
|
243
|
+
items: 'nodes',
|
|
244
|
+
})
|
|
245
|
+
|
|
246
|
+
/** Backwards-friendly short alias for the root specification schema. */
|
|
247
|
+
export const SPEC_SCHEMA = GENUI_SPEC_SCHEMA
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Native component field metadata.
|
|
251
|
+
*
|
|
252
|
+
* This is intentionally explicit rather than inferred from TypeScript
|
|
253
|
+
* interfaces: the registry is also consumed at runtime by normalization and
|
|
254
|
+
* diagnostics, where erased interfaces are unavailable.
|
|
255
|
+
*/
|
|
256
|
+
export const COMPONENT_SCHEMAS: Readonly<Record<string, ComponentSchema>> = {
|
|
257
|
+
accordion: schema(['items'], { ...nodeFields, items: 'array' }, {}, { nested: { items: accordionHolderSchema } }),
|
|
258
|
+
audio: schema(['src'], { ...nodeFields, src: 'string', alt: 'string', loop: 'boolean' }, { url: 'src', link: 'src' }),
|
|
259
|
+
avatar: schema(['name'], { ...nodeFields, name: 'string', color: 'string' }),
|
|
260
|
+
badge: schema(['label'], { ...nodeFields, label: 'string', tone: 'string', icon: 'string' }, { text: 'label', value: 'label' }, { enums: { tone: BADGE_TONES } }),
|
|
261
|
+
breadcrumb: schema(['items'], { ...nodeFields, items: 'array' }),
|
|
262
|
+
button: schema(['label'], { ...nodeFields, label: 'string', tone: 'string', full: 'boolean', small: 'boolean', icon: 'string', action: 'string' }, {}, { enums: { tone: BUTTON_TONES } }),
|
|
263
|
+
// `text`/`body`/`desc` are the model's default names for "the callout's
|
|
264
|
+
// prose": a callout missing `content` is dropped by repair, which takes the
|
|
265
|
+
// WHOLE fence down with it (issue: dsh-ui 围栏字段名). Adopt them as aliases.
|
|
266
|
+
// `tone` value aliases: card/hero/badge/button all accept `danger` (and
|
|
267
|
+
// badge uses `warn`), so models cross-write them onto callout — map them
|
|
268
|
+
// onto the closest canonical tone instead of failing the enum (issue #186).
|
|
269
|
+
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
|
+
card: schema(['items'], { ...nodeFields, title: 'string', items: 'nodes', tone: 'string', accent: 'string' }, { label: 'title', content: 'items' }, { enums: { tone: CARD_TONES } }),
|
|
271
|
+
chart: schema([], {
|
|
272
|
+
...nodeFields,
|
|
273
|
+
kind: 'string',
|
|
274
|
+
data: 'array',
|
|
275
|
+
series: 'array',
|
|
276
|
+
horizontal: 'boolean',
|
|
277
|
+
stacked: 'boolean',
|
|
278
|
+
filter: 'string',
|
|
279
|
+
palette: 'array',
|
|
280
|
+
}, {}, {
|
|
281
|
+
oneOfRequired: [['data', 'series']],
|
|
282
|
+
// `line` may carry its points in `series` (multi-series line); only the
|
|
283
|
+
// donut is a single-series shape that always needs `data`.
|
|
284
|
+
conditionalRequired: [
|
|
285
|
+
{ kind: 'required-if', when: { field: 'kind', equals: 'donut' }, required: ['data'] },
|
|
286
|
+
],
|
|
287
|
+
nested: { data: chartDatumSchema, series: chartSeriesSchema },
|
|
288
|
+
enums: { kind: CHART_KINDS },
|
|
289
|
+
validator: { name: 'chart-renderability' },
|
|
290
|
+
}),
|
|
291
|
+
checkbox: schema(['label'], { ...nodeFields, label: 'string', checked: 'boolean', action: 'string', group: 'string' }),
|
|
292
|
+
code: schema(['code'], { ...nodeFields, lang: 'string', code: 'string' }, { content: 'code', text: 'code' }),
|
|
293
|
+
col: schema(['items'], { ...nodeFields, items: 'nodes', gap: 'number' }),
|
|
294
|
+
copy: schema(['text'], { ...nodeFields, label: 'string', text: 'string' }, { content: 'text', code: 'text', value: 'text' }),
|
|
295
|
+
diagram: schema(['kind', 'nodes'], { ...nodeFields, kind: 'string', variant: 'string', title: 'string', nodes: 'array', edges: 'array', zones: 'array', theme: 'object' }, {}, {
|
|
296
|
+
nested: { nodes: diagramNodeSchema, edges: diagramEdgeSchema, zones: diagramZoneSchema, theme: diagramThemeSchema },
|
|
297
|
+
enums: { kind: DIAGRAM_KINDS, variant: DIAGRAM_VARIANTS },
|
|
298
|
+
}),
|
|
299
|
+
// `items` is the container field name every other component uses, so models
|
|
300
|
+
// reach for it here too; without the alias the whole node (and fence) drops.
|
|
301
|
+
diff: schema(['diffs'], { ...nodeFields, diffs: 'array' }, { items: 'diffs', files: 'diffs' }, { nested: { diffs: diffRecordSchema } }),
|
|
302
|
+
divider: schema([], nodeFields),
|
|
303
|
+
echart: schema([], { ...nodeFields, title: 'string', height: 'number', preset: 'string', data: 'array', series: 'array', links: 'array', palette: 'array', option: 'object' }, {}, {
|
|
304
|
+
// `links` alone is valid: the sankey/graph presets are edge-driven.
|
|
305
|
+
oneOfRequired: [['option', 'data', 'series', 'links']],
|
|
306
|
+
enums: { preset: ECHART_PRESETS },
|
|
307
|
+
}),
|
|
308
|
+
'file-tree': schema(['items'], { ...nodeFields, items: 'array' }, { nodes: 'items' }, { nested: { items: fileTreeNodeSchema } }),
|
|
309
|
+
grid: schema(['items'], { ...nodeFields, cols: 'number', items: 'nodes' }),
|
|
310
|
+
image: schema(['src'], { ...nodeFields, src: 'string', alt: 'string' }, { url: 'src', link: 'src' }),
|
|
311
|
+
input: schema([], { ...nodeFields, label: 'string', placeholder: 'string', value: 'string', inputType: 'string', action: 'string', id: 'string' }, {}, { enums: { inputType: INPUT_TYPES } }),
|
|
312
|
+
json: schema(['value'], { ...nodeFields, value: 'unknown' }),
|
|
313
|
+
keyvalue: schema(['pairs'], { ...nodeFields, pairs: 'array' }, { items: 'pairs', rows: 'pairs', entries: 'pairs' }, { nested: { pairs: keyValueRecordSchema } }),
|
|
314
|
+
link: schema(['label'], { ...nodeFields, label: 'string', href: 'string' }),
|
|
315
|
+
list: schema(['items'], { ...nodeFields, items: 'array', filter: 'string' }),
|
|
316
|
+
mermaid: schema(['code'], { ...nodeFields, code: 'string' }),
|
|
317
|
+
svg: schema(['code'], { ...nodeFields, code: 'string', title: 'string', height: 'number' }),
|
|
318
|
+
plot: schema(['series'], { ...nodeFields, series: 'array', xMin: 'number', xMax: 'number', yMin: 'number', yMax: 'number', title: 'string' }, {}, { nested: { series: plotSeriesSchema } }),
|
|
319
|
+
progress: schema(['value'], { ...nodeFields, value: 'number', label: 'string', valueLabel: 'string', variant: 'string', target: 'number' }, {}, { enums: { variant: PROGRESS_VARIANTS } }),
|
|
320
|
+
// `items` joins the §175 aliases: it is the field name models reach for when
|
|
321
|
+
// they enumerate a component's choices, and without it the node (and with it
|
|
322
|
+
// the whole fence) is dropped.
|
|
323
|
+
quiz: schema(['question', 'options'], { ...nodeFields, question: 'string', options: 'array', explanation: 'string', id: 'string', action: 'string' }, { title: 'question', text: 'question', choices: 'options', items: 'options' }),
|
|
324
|
+
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' }),
|
|
326
|
+
scene3d: schema(['meshes'], { ...nodeFields, title: 'string', meshes: 'array', ambient: 'number', background: 'string' }, {}, { nested: { meshes: sceneMeshSchema } }),
|
|
327
|
+
select: schema(['options'], { ...nodeFields, label: 'string', options: 'array', action: 'string', selected: 'number', id: 'string' }, { items: 'options' }),
|
|
328
|
+
slider: schema([], { ...nodeFields, label: 'string', min: 'number', max: 'number', step: 'number', value: 'number', action: 'string', id: 'string' }),
|
|
329
|
+
spacer: schema([], nodeFields),
|
|
330
|
+
hero: schema(['title'], {
|
|
331
|
+
...nodeFields,
|
|
332
|
+
title: 'string',
|
|
333
|
+
subtitle: 'string',
|
|
334
|
+
value: 'string',
|
|
335
|
+
label: 'string',
|
|
336
|
+
delta: 'string',
|
|
337
|
+
spark: 'array',
|
|
338
|
+
tone: 'string',
|
|
339
|
+
}, {}, { enums: { tone: HERO_TONES } }),
|
|
340
|
+
stat: schema(['label', 'value'], { ...nodeFields, label: 'string', value: 'string', delta: 'string', spark: 'array', size: 'string' }, {}, { enums: { size: STAT_SIZES } }),
|
|
341
|
+
steps: schema(['steps'], { ...nodeFields, steps: 'array', current: 'number' }, { items: 'steps' }, { nested: { steps: stepsRecordSchema } }),
|
|
342
|
+
submit: schema(['label'], { ...nodeFields, label: 'string', action: 'string', resetAction: 'string', groups: 'array' }),
|
|
343
|
+
switch: schema(['label'], { ...nodeFields, label: 'string', checked: 'boolean', action: 'string' }),
|
|
344
|
+
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
|
+
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 } }),
|
|
347
|
+
textarea: schema([], { ...nodeFields, label: 'string', placeholder: 'string', rows: 'number', value: 'string', action: 'string', id: 'string' }),
|
|
348
|
+
timeline: schema(['items'], { ...nodeFields, items: 'array' }, {}, { nested: { items: timelineRecordSchema } }),
|
|
349
|
+
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 } }),
|
|
350
|
+
} as const
|
|
351
|
+
|
|
352
|
+
export const GENUI_NATIVE_TYPES: ReadonlySet<string> = new Set(Object.keys(COMPONENT_SCHEMAS))
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/** Shared primitive sanitizers used by the GenUI guard. */
|
|
2
|
+
|
|
3
|
+
/** Is `value` one of `values`? */
|
|
4
|
+
function inEnum<T extends string>(value: unknown, values: readonly T[]): value is T {
|
|
5
|
+
return typeof value === 'string' && (values as readonly string[]).includes(value)
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/** String field: truncate a string to `cap`, or undefined when not a string. */
|
|
9
|
+
export function str(value: unknown, cap: number): string | undefined {
|
|
10
|
+
return typeof value === 'string' ? value.slice(0, cap) : undefined
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Color field: the value lands in an inline `style` (background/stroke) or
|
|
15
|
+
* THREE.Color. Arbitrary CSS values are an exfiltration channel, so only
|
|
16
|
+
* literal color formats and host design tokens are accepted.
|
|
17
|
+
*/
|
|
18
|
+
const SAFE_COLOR_RE = /^(?:#[\da-fA-F]{3,8}|rgba?\([^)]{0,64}\)|hsla?\([^)]{0,64}\)|var\(--dsw-[\w-]+(?:,\s*#[0-9a-fA-F]{3,8})?\))$/
|
|
19
|
+
|
|
20
|
+
export function color(value: unknown): string | undefined {
|
|
21
|
+
if (typeof value !== 'string') return undefined
|
|
22
|
+
const normalized = value.trim()
|
|
23
|
+
return normalized.length <= 64 && SAFE_COLOR_RE.test(normalized) ? normalized : undefined
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Keep only http(s) and mailto link targets. */
|
|
27
|
+
export function safeHref(value: unknown): string | undefined {
|
|
28
|
+
if (typeof value !== 'string') return undefined
|
|
29
|
+
const normalized = value.trim()
|
|
30
|
+
if (normalized.length > 2048) return undefined
|
|
31
|
+
return /^https?:\/\//i.test(normalized) || /^mailto:[^@\s]+@[^@\s]+$/i.test(normalized) ? normalized : undefined
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Keep browser-reachable http(s) or same-origin relative media paths. */
|
|
35
|
+
export function safeMediaSrc(value: unknown): string | undefined {
|
|
36
|
+
if (typeof value !== 'string') return undefined
|
|
37
|
+
const normalized = value.trim()
|
|
38
|
+
if (normalized === '' || normalized.length > 2048) return undefined
|
|
39
|
+
if (/^https?:\/\//i.test(normalized)) return normalized
|
|
40
|
+
if (/^[a-z][a-z0-9+.-]*:/i.test(normalized) || /^[/\\]{2}/.test(normalized)) return undefined
|
|
41
|
+
return normalized
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Finite-number field: clamp into [min, max], or undefined when not finite. */
|
|
45
|
+
export function num(value: unknown, min: number, max: number): number | undefined {
|
|
46
|
+
return typeof value === 'number' && Number.isFinite(value) ? Math.min(max, Math.max(min, value)) : undefined
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Integer field: clamp into [min, max], or undefined when not a finite number. */
|
|
50
|
+
export function int(value: unknown, min: number, max: number): number | undefined {
|
|
51
|
+
return typeof value === 'number' && Number.isFinite(value) ? Math.min(max, Math.max(min, Math.trunc(value))) : undefined
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Optional enum field: the value when it matches, otherwise undefined. */
|
|
55
|
+
export function enu<T extends string>(value: unknown, values: readonly T[]): T | undefined {
|
|
56
|
+
return inEnum(value, values) ? value : undefined
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Plain object (not array, not null). */
|
|
60
|
+
export function obj(value: unknown): Record<string, unknown> | undefined {
|
|
61
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value) ? value as Record<string, unknown> : undefined
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Preserve an optional field only when its value exists. */
|
|
65
|
+
export function opt<K extends string, V>(key: K, value: V | undefined): Partial<Record<K, V>> {
|
|
66
|
+
return value === undefined ? {} : { [key]: value } as Partial<Record<K, V>>
|
|
67
|
+
}
|