@sparkelf/dsh-genui 0.0.0-stage → 0.11.4-patch.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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,322 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* templates.ts — template center data.
|
|
3
|
+
*
|
|
4
|
+
* Each template = a natural-language `instruction` (inserted into the
|
|
5
|
+
* composer on "try it", so the model generates the matching interface via the
|
|
6
|
+
* genui skill) + a VALID `demo` spec (rendered directly by GenuiBlock in the
|
|
7
|
+
* preview, so the user sees the result before deciding). Fields track the
|
|
8
|
+
* real schema in spec.ts / guard.ts (tests/templates.spec.ts validates each
|
|
9
|
+
* one with validateGenuiSpec).
|
|
10
|
+
*
|
|
11
|
+
* Templates double as documentation: they cover layout, data, charts,
|
|
12
|
+
* interaction, quizzes and the advanced families.
|
|
13
|
+
*
|
|
14
|
+
* All display text resolves through the i18n dictionaries, so the list is
|
|
15
|
+
* built PER CALL from the active locale rather than frozen at module load.
|
|
16
|
+
*/
|
|
17
|
+
import type { GenuiSpec } from './spec.ts'
|
|
18
|
+
import { t } from './i18n/index.ts'
|
|
19
|
+
|
|
20
|
+
/** Stable, locale-independent category ids. */
|
|
21
|
+
export const TEMPLATE_CATEGORIES = [
|
|
22
|
+
'dashboard', 'data', 'flow', 'chart', 'interactive', 'quiz', 'advanced',
|
|
23
|
+
] as const
|
|
24
|
+
|
|
25
|
+
export type TemplateCategory = (typeof TEMPLATE_CATEGORIES)[number]
|
|
26
|
+
|
|
27
|
+
/** Dictionary key carrying a category's display name. */
|
|
28
|
+
export function categoryLabelKey(category: TemplateCategory | 'all'): string {
|
|
29
|
+
return `tpl.category.${category}`
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface GenuiTemplate {
|
|
33
|
+
id: string
|
|
34
|
+
/** Stable id; the display name comes from {@link categoryLabelKey}. */
|
|
35
|
+
category: TemplateCategory
|
|
36
|
+
name: string
|
|
37
|
+
description: string
|
|
38
|
+
/** Natural-language instruction inserted into the composer on "try it". */
|
|
39
|
+
instruction: string
|
|
40
|
+
/** Valid preview spec (≤200 nodes, ≤8 levels deep). */
|
|
41
|
+
demo: GenuiSpec
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Build the template list in the ACTIVE locale.
|
|
46
|
+
*
|
|
47
|
+
* A function rather than a constant: the user can switch language at runtime,
|
|
48
|
+
* and a module-level array would pin whatever locale happened to be active
|
|
49
|
+
* when the bundle first loaded.
|
|
50
|
+
*/
|
|
51
|
+
export function genuiTemplates(): readonly GenuiTemplate[] {
|
|
52
|
+
return [
|
|
53
|
+
{
|
|
54
|
+
id: 'tpl-dashboard',
|
|
55
|
+
category: 'dashboard',
|
|
56
|
+
name: t('tpl.dashboard.name'),
|
|
57
|
+
description: t('tpl.dashboard.desc'),
|
|
58
|
+
instruction: t('tpl.dashboard.instruction'),
|
|
59
|
+
demo: {
|
|
60
|
+
title: t('tpl.dashboard.demo.title'),
|
|
61
|
+
gap: 12,
|
|
62
|
+
items: [
|
|
63
|
+
{ type: 'card', title: t('tpl.dashboard.demo.metrics'), items: [
|
|
64
|
+
{ type: 'grid', cols: 2, items: [
|
|
65
|
+
{ type: 'stat', label: t('tpl.dashboard.demo.done'), value: '12 / 18', delta: '+4' },
|
|
66
|
+
{ type: 'stat', label: t('tpl.dashboard.demo.blocked'), value: '2', delta: '-1' },
|
|
67
|
+
{ type: 'stat', label: t('tpl.dashboard.demo.duration'), value: '3.2h', delta: '-8%' },
|
|
68
|
+
{ type: 'stat', label: t('tpl.dashboard.demo.coverage'), value: '86%' },
|
|
69
|
+
] },
|
|
70
|
+
] },
|
|
71
|
+
{ type: 'card', title: t('tpl.dashboard.demo.progress'), items: [
|
|
72
|
+
{ type: 'progress', label: t('tpl.dashboard.demo.milestone'), value: 68, valueLabel: '68 / 100' },
|
|
73
|
+
] },
|
|
74
|
+
{ type: 'card', title: t('tpl.dashboard.demo.todo'), items: [
|
|
75
|
+
{ type: 'list', items: [
|
|
76
|
+
t('tpl.dashboard.demo.todo1'),
|
|
77
|
+
t('tpl.dashboard.demo.todo2'),
|
|
78
|
+
t('tpl.dashboard.demo.todo3'),
|
|
79
|
+
] },
|
|
80
|
+
] },
|
|
81
|
+
],
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
id: 'tpl-compare',
|
|
86
|
+
category: 'data',
|
|
87
|
+
name: t('tpl.compare.name'),
|
|
88
|
+
description: t('tpl.compare.desc'),
|
|
89
|
+
instruction: t('tpl.compare.instruction'),
|
|
90
|
+
demo: {
|
|
91
|
+
title: t('tpl.compare.demo.title'),
|
|
92
|
+
items: [
|
|
93
|
+
{ type: 'callout', tone: 'info', title: t('tpl.compare.demo.conclusion'), content: t('tpl.compare.demo.body') },
|
|
94
|
+
{ type: 'table', columns: [
|
|
95
|
+
t('tpl.compare.demo.dimension'),
|
|
96
|
+
t('tpl.compare.demo.optionA'),
|
|
97
|
+
t('tpl.compare.demo.optionB'),
|
|
98
|
+
t('tpl.compare.demo.optionC'),
|
|
99
|
+
], rows: [
|
|
100
|
+
[t('tpl.compare.demo.cost'), t('tpl.compare.demo.high'), t('tpl.compare.demo.medium'), t('tpl.compare.demo.low')],
|
|
101
|
+
[t('tpl.compare.demo.complexity'), t('tpl.compare.demo.high'), t('tpl.compare.demo.medium'), t('tpl.compare.demo.low')],
|
|
102
|
+
[t('tpl.compare.demo.risk'), t('tpl.compare.demo.low'), t('tpl.compare.demo.low'), t('tpl.compare.demo.high')],
|
|
103
|
+
[t('tpl.compare.demo.payoff'), t('tpl.compare.demo.large'), t('tpl.compare.demo.medium'), t('tpl.compare.demo.small')],
|
|
104
|
+
] },
|
|
105
|
+
],
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
id: 'tpl-steps',
|
|
110
|
+
category: 'flow',
|
|
111
|
+
name: t('tpl.steps.name'),
|
|
112
|
+
description: t('tpl.steps.desc'),
|
|
113
|
+
instruction: t('tpl.steps.instruction'),
|
|
114
|
+
demo: {
|
|
115
|
+
title: t('tpl.steps.demo.title'),
|
|
116
|
+
items: [
|
|
117
|
+
{ type: 'badge', label: t('tpl.steps.demo.badge'), tone: 'accent' },
|
|
118
|
+
{ type: 'steps', current: 2, steps: [
|
|
119
|
+
{ title: t('tpl.steps.demo.s1'), desc: t('tpl.steps.demo.s1desc') },
|
|
120
|
+
{ title: t('tpl.steps.demo.s2'), desc: t('tpl.steps.demo.s2desc') },
|
|
121
|
+
{ title: t('tpl.steps.demo.s3'), desc: t('tpl.steps.demo.s3desc') },
|
|
122
|
+
{ title: t('tpl.steps.demo.s4'), desc: t('tpl.steps.demo.s4desc') },
|
|
123
|
+
{ title: t('tpl.steps.demo.s5'), desc: t('tpl.steps.demo.s5desc') },
|
|
124
|
+
] },
|
|
125
|
+
],
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
id: 'tpl-quiz',
|
|
130
|
+
category: 'quiz',
|
|
131
|
+
name: t('tpl.quiz.name'),
|
|
132
|
+
description: t('tpl.quiz.desc'),
|
|
133
|
+
instruction: t('tpl.quiz.instruction'),
|
|
134
|
+
demo: {
|
|
135
|
+
title: t('tpl.quiz.demo.title'),
|
|
136
|
+
gap: 10,
|
|
137
|
+
items: [
|
|
138
|
+
{ type: 'text', content: t('tpl.quiz.demo.hint'), size: 'muted' },
|
|
139
|
+
{ type: 'quiz', id: 'q-dsh', question: t('tpl.quiz.demo.q1'), options: [
|
|
140
|
+
{ label: t('tpl.quiz.demo.q1a') },
|
|
141
|
+
{ label: t('tpl.quiz.demo.q1b'), correct: true, feedback: t('tpl.quiz.demo.q1bfx') },
|
|
142
|
+
{ label: t('tpl.quiz.demo.q1c') },
|
|
143
|
+
], explanation: t('tpl.quiz.demo.q1exp') },
|
|
144
|
+
{ type: 'quiz', id: 'q-fence', question: t('tpl.quiz.demo.q2'), options: [
|
|
145
|
+
{ label: t('tpl.quiz.demo.q2a') },
|
|
146
|
+
{ label: t('tpl.quiz.demo.q2b'), correct: true, feedback: t('tpl.quiz.demo.q2bfx') },
|
|
147
|
+
{ label: t('tpl.quiz.demo.q2c') },
|
|
148
|
+
], explanation: t('tpl.quiz.demo.q2exp') },
|
|
149
|
+
{ type: 'quiz', id: 'q-panel', question: t('tpl.quiz.demo.q3'), options: [
|
|
150
|
+
{ label: t('tpl.quiz.demo.q3a') },
|
|
151
|
+
{ label: t('tpl.quiz.demo.q3b'), correct: true, feedback: t('tpl.quiz.demo.q3bfx') },
|
|
152
|
+
{ label: t('tpl.quiz.demo.q3c') },
|
|
153
|
+
] },
|
|
154
|
+
],
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
id: 'tpl-stats',
|
|
159
|
+
category: 'data',
|
|
160
|
+
name: t('tpl.stats.name'),
|
|
161
|
+
description: t('tpl.stats.desc'),
|
|
162
|
+
instruction: t('tpl.stats.instruction'),
|
|
163
|
+
demo: {
|
|
164
|
+
title: t('tpl.stats.demo.title'),
|
|
165
|
+
items: [
|
|
166
|
+
{ type: 'keyvalue', pairs: [
|
|
167
|
+
{ key: t('tpl.stats.demo.done'), value: '12' },
|
|
168
|
+
{ key: t('tpl.stats.demo.late'), value: '1' },
|
|
169
|
+
{ key: t('tpl.stats.demo.risk'), value: t('tpl.stats.demo.riskValue') },
|
|
170
|
+
] },
|
|
171
|
+
{ type: 'progress', label: t('tpl.stats.demo.planned'), value: 75, valueLabel: '75%' },
|
|
172
|
+
{ type: 'progress', label: t('tpl.stats.demo.actual'), value: 82, valueLabel: '82%' },
|
|
173
|
+
{ type: 'timeline', items: [
|
|
174
|
+
{ title: t('tpl.stats.demo.mon'), desc: t('tpl.stats.demo.monDesc'), time: '08-25' },
|
|
175
|
+
{ title: t('tpl.stats.demo.wed'), desc: t('tpl.stats.demo.wedDesc'), time: '08-27' },
|
|
176
|
+
{ title: t('tpl.stats.demo.fri'), desc: t('tpl.stats.demo.friDesc'), time: '08-29' },
|
|
177
|
+
] },
|
|
178
|
+
],
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
id: 'tpl-chart',
|
|
183
|
+
category: 'chart',
|
|
184
|
+
name: t('tpl.chart.name'),
|
|
185
|
+
description: t('tpl.chart.desc'),
|
|
186
|
+
instruction: t('tpl.chart.instruction'),
|
|
187
|
+
demo: {
|
|
188
|
+
title: t('tpl.chart.demo.title'),
|
|
189
|
+
items: [
|
|
190
|
+
{ type: 'text', content: t('tpl.chart.demo.conclusion') },
|
|
191
|
+
{ type: 'chart', kind: 'line', data: [
|
|
192
|
+
{ label: 'W21', value: 8 },
|
|
193
|
+
{ label: 'W22', value: 10 },
|
|
194
|
+
{ label: 'W23', value: 9 },
|
|
195
|
+
{ label: 'W24', value: 12 },
|
|
196
|
+
{ label: 'W25', value: 15 },
|
|
197
|
+
{ label: 'W26', value: 18 },
|
|
198
|
+
] },
|
|
199
|
+
],
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
id: 'tpl-tabs',
|
|
204
|
+
category: 'interactive',
|
|
205
|
+
name: t('tpl.tabs.name'),
|
|
206
|
+
description: t('tpl.tabs.desc'),
|
|
207
|
+
instruction: t('tpl.tabs.instruction'),
|
|
208
|
+
demo: {
|
|
209
|
+
title: t('tpl.tabs.demo.title'),
|
|
210
|
+
items: [
|
|
211
|
+
{ type: 'tabs', tabs: [
|
|
212
|
+
{ label: t('tpl.tabs.demo.overview'), items: [{ type: 'text', content: t('tpl.tabs.demo.overviewBody') }] },
|
|
213
|
+
{ label: t('tpl.tabs.demo.details'), items: [{ type: 'list', items: [
|
|
214
|
+
t('tpl.tabs.demo.d1'),
|
|
215
|
+
t('tpl.tabs.demo.d2'),
|
|
216
|
+
t('tpl.tabs.demo.d3'),
|
|
217
|
+
] }] },
|
|
218
|
+
{ label: 'FAQ', items: [{ type: 'text', content: t('tpl.tabs.demo.faqBody') }] },
|
|
219
|
+
] },
|
|
220
|
+
],
|
|
221
|
+
},
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
id: 'tpl-checklist',
|
|
225
|
+
category: 'flow',
|
|
226
|
+
name: t('tpl.checklist.name'),
|
|
227
|
+
description: t('tpl.checklist.desc'),
|
|
228
|
+
instruction: t('tpl.checklist.instruction'),
|
|
229
|
+
demo: {
|
|
230
|
+
title: t('tpl.checklist.demo.title'),
|
|
231
|
+
items: [
|
|
232
|
+
{ type: 'badge', label: t('tpl.checklist.demo.badge'), tone: 'warn' },
|
|
233
|
+
{ type: 'list', items: [
|
|
234
|
+
{ type: 'checkbox', label: t('tpl.checklist.demo.c1') },
|
|
235
|
+
{ type: 'checkbox', label: t('tpl.checklist.demo.c2') },
|
|
236
|
+
{ type: 'checkbox', label: t('tpl.checklist.demo.c3') },
|
|
237
|
+
{ type: 'checkbox', label: t('tpl.checklist.demo.c4') },
|
|
238
|
+
] },
|
|
239
|
+
],
|
|
240
|
+
},
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
id: 'tpl-accordion',
|
|
244
|
+
category: 'advanced',
|
|
245
|
+
name: t('tpl.accordion.name'),
|
|
246
|
+
description: t('tpl.accordion.desc'),
|
|
247
|
+
instruction: t('tpl.accordion.instruction'),
|
|
248
|
+
demo: {
|
|
249
|
+
title: t('tpl.accordion.demo.title'),
|
|
250
|
+
items: [
|
|
251
|
+
{ type: 'accordion', items: [
|
|
252
|
+
{ title: t('tpl.accordion.demo.q1'), items: [{ type: 'text', content: t('tpl.accordion.demo.a1') }] },
|
|
253
|
+
{ title: t('tpl.accordion.demo.q2'), items: [{ type: 'text', content: t('tpl.accordion.demo.a2') }] },
|
|
254
|
+
{ title: t('tpl.accordion.demo.q3'), items: [{ type: 'text', content: t('tpl.accordion.demo.a3') }] },
|
|
255
|
+
] },
|
|
256
|
+
],
|
|
257
|
+
},
|
|
258
|
+
},
|
|
259
|
+
{
|
|
260
|
+
id: 'tpl-diagram',
|
|
261
|
+
category: 'advanced',
|
|
262
|
+
name: t('tpl.diagram.name'),
|
|
263
|
+
description: t('tpl.diagram.desc'),
|
|
264
|
+
instruction: t('tpl.diagram.instruction'),
|
|
265
|
+
demo: {
|
|
266
|
+
title: t('tpl.diagram.demo.title'),
|
|
267
|
+
items: [
|
|
268
|
+
{ type: 'diagram', kind: 'flowchart', title: t('tpl.diagram.demo.caption'), nodes: [
|
|
269
|
+
{ id: 'a', label: t('tpl.diagram.demo.model'), x: 20, y: 20, w: 120, h: 48 },
|
|
270
|
+
{ id: 'b', label: t('tpl.diagram.demo.plugin'), x: 20, y: 120, w: 120, h: 48 },
|
|
271
|
+
{ id: 'c', label: t('tpl.diagram.demo.host'), x: 200, y: 70, w: 120, h: 48 },
|
|
272
|
+
], edges: [
|
|
273
|
+
{ from: 'a', to: 'b' },
|
|
274
|
+
{ from: 'b', to: 'c' },
|
|
275
|
+
] },
|
|
276
|
+
],
|
|
277
|
+
},
|
|
278
|
+
},
|
|
279
|
+
{
|
|
280
|
+
id: 'tpl-3d',
|
|
281
|
+
category: 'advanced',
|
|
282
|
+
name: t('tpl.3d.name'),
|
|
283
|
+
description: t('tpl.3d.desc'),
|
|
284
|
+
instruction: t('tpl.3d.instruction'),
|
|
285
|
+
demo: {
|
|
286
|
+
title: t('tpl.3d.demo.title'),
|
|
287
|
+
items: [
|
|
288
|
+
{ type: 'text', content: t('tpl.3d.demo.note'), size: 'muted' },
|
|
289
|
+
{ type: 'scene3d', title: t('tpl.3d.demo.scene'), meshes: [
|
|
290
|
+
{ shape: 'box', size: 1, color: '#4FC3F7', position: [-1.2, 0, 0] },
|
|
291
|
+
{ shape: 'sphere', size: 0.6, color: '#81C784', position: [1.2, 0, 0] },
|
|
292
|
+
] },
|
|
293
|
+
],
|
|
294
|
+
},
|
|
295
|
+
},
|
|
296
|
+
{
|
|
297
|
+
id: 'tpl-breadcrumb',
|
|
298
|
+
category: 'data',
|
|
299
|
+
name: t('tpl.breadcrumb.name'),
|
|
300
|
+
description: t('tpl.breadcrumb.desc'),
|
|
301
|
+
instruction: t('tpl.breadcrumb.instruction'),
|
|
302
|
+
demo: {
|
|
303
|
+
title: t('tpl.breadcrumb.demo.title'),
|
|
304
|
+
items: [
|
|
305
|
+
{ type: 'breadcrumb', items: [t('tpl.breadcrumb.demo.workspace'), 'dsh-genui', 'src', 'client'] },
|
|
306
|
+
{ type: 'file-tree', items: [
|
|
307
|
+
{ name: 'src', type: 'dir', children: [
|
|
308
|
+
{ name: 'client', type: 'dir', children: [
|
|
309
|
+
{ name: 'panel.tsx' },
|
|
310
|
+
{ name: 'templates.ts' },
|
|
311
|
+
] },
|
|
312
|
+
{ name: 'index.tsx' },
|
|
313
|
+
] },
|
|
314
|
+
{ name: 'tests', type: 'dir', children: [
|
|
315
|
+
{ name: 'templates.spec.ts' },
|
|
316
|
+
] },
|
|
317
|
+
] },
|
|
318
|
+
],
|
|
319
|
+
},
|
|
320
|
+
},
|
|
321
|
+
]
|
|
322
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `render_ui` tool's card in the tool row. The host projected the
|
|
3
|
+
* repaired spec into the result's `meta` (the tool's `presentationMeta`);
|
|
4
|
+
* this keyed toolview reads it and renders through GenuiBlock — the same
|
|
5
|
+
* renderer the ```dsh-ui fence uses. Falls back to a compact summary row
|
|
6
|
+
* when the meta is missing or invalid (e.g. a replay of a log recorded
|
|
7
|
+
* before the projection existed).
|
|
8
|
+
*
|
|
9
|
+
* Every settled spec is ALSO published to the session panel store: the
|
|
10
|
+
* conversation dock re-renders the same panel block in place, so repeated
|
|
11
|
+
* render_ui calls update one surface instead of stacking tool-row cards.
|
|
12
|
+
*/
|
|
13
|
+
import { useEffect, useMemo } from 'react'
|
|
14
|
+
import type {} from '@deepseek-ai/dsh-client-ui-session/client'
|
|
15
|
+
import type {} from '@deepseek-ai/dsh-client-ui-chat/client'
|
|
16
|
+
import type { ToolCallViewProps } from '@deepseek-ai/dsh-client-ui-tool/client'
|
|
17
|
+
import { ExportableGenuiBlock } from './artifact/ExportableGenuiBlock.tsx'
|
|
18
|
+
import { ErrorBoundary } from './ErrorBoundary.tsx'
|
|
19
|
+
import { repairGenuiSpec } from './guard.ts'
|
|
20
|
+
import { toolStateKey } from './interaction-store.ts'
|
|
21
|
+
import { applyPanelOperation } from './panel-store.ts'
|
|
22
|
+
import css from './GenuiBlock.module.css'
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Keyed toolview for the `render_ui` tool. `block` is the settled result
|
|
26
|
+
* node once the call completes; while it runs (or on replay without meta)
|
|
27
|
+
* the summary fallback is shown.
|
|
28
|
+
*/
|
|
29
|
+
export function GenuiToolView({ toolName, block, sessionId }: ToolCallViewProps) {
|
|
30
|
+
// `meta` exists only on the settled result node; running calls (and
|
|
31
|
+
// replayed logs without the projection) fall back to the summary row.
|
|
32
|
+
// Memoized so the publish effect only fires when the settled spec
|
|
33
|
+
// actually changes (same block → same object → no panel churn).
|
|
34
|
+
const meta = 'meta' in block ? block.meta : undefined
|
|
35
|
+
const spec = useMemo(() => (meta === undefined ? null : repairGenuiSpec(meta)), [meta])
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
// Publish the settled spec to the session panel (dock) as a REPLACE op
|
|
38
|
+
// with the result block's call identity and message seq: the same block
|
|
39
|
+
// re-rendered (replay/refresh) is idempotent, and an older result can
|
|
40
|
+
// never clobber a newer panel fence (real ordering in the fold). Running
|
|
41
|
+
// calls publish nothing — the panel keeps its last content.
|
|
42
|
+
if (spec !== null && spec.items.length > 0) {
|
|
43
|
+
applyPanelOperation(sessionId, {
|
|
44
|
+
sourceId: JSON.stringify(['render_ui', block.callId]),
|
|
45
|
+
order: ['seq' in block && typeof block.seq === 'number' ? block.seq : 0, -1, 0],
|
|
46
|
+
mode: 'replace',
|
|
47
|
+
spec,
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
}, [sessionId, spec, block])
|
|
51
|
+
if (spec === null || spec.items.length === 0) {
|
|
52
|
+
return (
|
|
53
|
+
<div className={css.toolFallback} data-genui-tool>
|
|
54
|
+
<span className={css.toolFallbackTitle}>{toolName}</span>
|
|
55
|
+
<span className={css.toolFallbackMeta}>{block.callId}</span>
|
|
56
|
+
</div>
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
return (
|
|
60
|
+
<div className={css.tool} data-genui-tool>
|
|
61
|
+
<ErrorBoundary label="工具卡片">
|
|
62
|
+
{/* callId is stable across replay → tool-card interaction state is durable */}
|
|
63
|
+
<ExportableGenuiBlock spec={spec} stateKey={toolStateKey(sessionId, block.callId)} />
|
|
64
|
+
</ErrorBoundary>
|
|
65
|
+
</div>
|
|
66
|
+
)
|
|
67
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { GenuiNode, GenuiSpec } from './spec.ts'
|
|
2
|
+
import { GENUI_LIMITS } from './genui-runtime/index.ts'
|
|
3
|
+
import { isTableDetailReachable, tableRowsForDetails } from './table-details.ts'
|
|
4
|
+
|
|
5
|
+
/** 遍历完整 GenUI 组件树,并提供每个组件在 spec 中的路径。 */
|
|
6
|
+
export function walkGenuiNodes(spec: GenuiSpec, visitor: (node: GenuiNode, path: string) => void): void {
|
|
7
|
+
const walk = (nodes: GenuiNode[], path: string, depth: number): void => {
|
|
8
|
+
if (depth > GENUI_LIMITS.maxDepth) return
|
|
9
|
+
nodes.forEach((node, index) => visit(node, `${path}[${index}]`, depth))
|
|
10
|
+
}
|
|
11
|
+
const visit = (node: GenuiNode, at: string, depth: number): void => {
|
|
12
|
+
if (depth > GENUI_LIMITS.maxDepth) return
|
|
13
|
+
visitor(node, at)
|
|
14
|
+
if (depth >= GENUI_LIMITS.maxDepth) return
|
|
15
|
+
switch (node.type) {
|
|
16
|
+
case 'row':
|
|
17
|
+
case 'col':
|
|
18
|
+
case 'grid':
|
|
19
|
+
case 'card':
|
|
20
|
+
walk(node.items, `${at}.items`, depth + 1)
|
|
21
|
+
break
|
|
22
|
+
case 'tabs':
|
|
23
|
+
node.tabs.forEach((tab, tabIndex) => walk(tab.items, `${at}.tabs[${tabIndex}].items`, depth + 1))
|
|
24
|
+
break
|
|
25
|
+
case 'accordion':
|
|
26
|
+
node.items.forEach((item, itemIndex) => walk(item.items, `${at}.items[${itemIndex}].items`, depth + 1))
|
|
27
|
+
break
|
|
28
|
+
case 'list':
|
|
29
|
+
node.items.forEach((item, itemIndex) => {
|
|
30
|
+
if (item !== null && typeof item === 'object' && 'type' in item) visit(item, `${at}.items[${itemIndex}]`, depth + 1)
|
|
31
|
+
})
|
|
32
|
+
break
|
|
33
|
+
case 'table':
|
|
34
|
+
node.details?.slice(0, tableRowsForDetails(node).length).forEach((detail, rowIndex) => {
|
|
35
|
+
if (detail !== null && isTableDetailReachable(node, rowIndex)) {
|
|
36
|
+
walk(detail, `${at}.details[${rowIndex}]`, depth + 1)
|
|
37
|
+
}
|
|
38
|
+
})
|
|
39
|
+
break
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
walk(spec.items, 'items', 0)
|
|
43
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bundle source entry (plugin_check tool-bundle contract): the node-half
|
|
3
|
+
* surface the host loader resolves through `package.json#main`.
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
// Load the owner package's client augmentation before the plugin re-export so
|
|
7
|
+
// TypeScript resolves client context members consistently from this root entry.
|
|
8
|
+
import type {} from '@deepseek-ai/dsh-api-session-controller/client'
|
|
9
|
+
export * from './plugin/index'
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { validateGenuiChartSemantics } from '../client/guard.ts'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Validate chart nodes using the guard's shared native renderability contract.
|
|
5
|
+
* The plugin-facing API remains stable while the guard remains the single
|
|
6
|
+
* owner of chart field and renderer-semantic rules.
|
|
7
|
+
*
|
|
8
|
+
* @param value - Raw GenUI spec or bare chart node.
|
|
9
|
+
* @returns Chart errors in deterministic tree order.
|
|
10
|
+
*/
|
|
11
|
+
export function validateRenderableChartSemantics(value: unknown): string[] {
|
|
12
|
+
return validateGenuiChartSemantics(value)
|
|
13
|
+
}
|