@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.
Files changed (210) hide show
  1. package/CHANGELOG.md +597 -0
  2. package/LICENSE +21 -0
  3. package/README.md +292 -2
  4. package/README.zh-CN.md +307 -0
  5. package/SKILL.md +261 -0
  6. package/cordis.patch.yml +9 -0
  7. package/demo-prompts.md +118 -0
  8. package/lib/assets/echarts-core.js +43 -0
  9. package/lib/assets/echarts-full.js +72 -0
  10. package/lib/assets/mermaid.js +3591 -0
  11. package/lib/assets/standalone-runtime.js +1506 -0
  12. package/lib/assets/three.js +3844 -0
  13. package/lib/client.js +405 -0
  14. package/lib/index.js +5187 -0
  15. package/lib/invariant.js +19 -0
  16. package/lib/types/client/EChartNode.d.ts +13 -0
  17. package/lib/types/client/ErrorBoundary.d.ts +30 -0
  18. package/lib/types/client/GenuiBlock.d.ts +9 -0
  19. package/lib/types/client/PlotBlock.d.ts +44 -0
  20. package/lib/types/client/TemplateDrawer.d.ts +7 -0
  21. package/lib/types/client/achievement-store.d.ts +35 -0
  22. package/lib/types/client/achievement-toast.d.ts +2 -0
  23. package/lib/types/client/achievements.d.ts +63 -0
  24. package/lib/types/client/action-context.d.ts +7 -0
  25. package/lib/types/client/artifact/ExportableGenuiBlock.d.ts +6 -0
  26. package/lib/types/client/artifact/create.d.ts +5 -0
  27. package/lib/types/client/artifact/download.d.ts +9 -0
  28. package/lib/types/client/artifact/html.d.ts +5 -0
  29. package/lib/types/client/artifact/index.d.ts +8 -0
  30. package/lib/types/client/artifact/json.d.ts +3 -0
  31. package/lib/types/client/artifact/parse.d.ts +3 -0
  32. package/lib/types/client/artifact/portability.d.ts +4 -0
  33. package/lib/types/client/artifact/standalone-theme.d.ts +2 -0
  34. package/lib/types/client/artifact/types.d.ts +33 -0
  35. package/lib/types/client/asset-echarts-core.d.ts +1 -0
  36. package/lib/types/client/asset-echarts.d.ts +17 -0
  37. package/lib/types/client/asset-loader.d.ts +33 -0
  38. package/lib/types/client/asset-mermaid.d.ts +1 -0
  39. package/lib/types/client/asset-three.d.ts +1 -0
  40. package/lib/types/client/blocks/advanced.d.ts +101 -0
  41. package/lib/types/client/blocks/basic.d.ts +22 -0
  42. package/lib/types/client/blocks/charts.d.ts +53 -0
  43. package/lib/types/client/blocks/checkbox.d.ts +17 -0
  44. package/lib/types/client/blocks/diagram/geometry.d.ts +73 -0
  45. package/lib/types/client/blocks/diagram/index.d.ts +5 -0
  46. package/lib/types/client/blocks/diagram/layout.d.ts +41 -0
  47. package/lib/types/client/blocks/diagram/theme.d.ts +37 -0
  48. package/lib/types/client/blocks/forms.d.ts +77 -0
  49. package/lib/types/client/blocks/image.d.ts +6 -0
  50. package/lib/types/client/blocks/render-node.d.ts +10 -0
  51. package/lib/types/client/blocks/state.d.ts +63 -0
  52. package/lib/types/client/blocks/svg.d.ts +4 -0
  53. package/lib/types/client/dom-fence.d.ts +30 -0
  54. package/lib/types/client/echarts-engine.d.ts +4 -0
  55. package/lib/types/client/echarts-lazy.d.ts +18 -0
  56. package/lib/types/client/embed.d.ts +10 -0
  57. package/lib/types/client/fence-render.d.ts +106 -0
  58. package/lib/types/client/gallery.d.ts +7 -0
  59. package/lib/types/client/genui-runtime/diagnostics.d.ts +18 -0
  60. package/lib/types/client/genui-runtime/index.d.ts +1 -0
  61. package/lib/types/client/genui-runtime/limits.d.ts +54 -0
  62. package/lib/types/client/genui-runtime/normalize.d.ts +15 -0
  63. package/lib/types/client/genui-runtime/schema.d.ts +87 -0
  64. package/lib/types/client/genui-runtime/value-utils.d.ts +18 -0
  65. package/lib/types/client/guard.d.ts +144 -0
  66. package/lib/types/client/i18n/en.d.ts +307 -0
  67. package/lib/types/client/i18n/index.d.ts +44 -0
  68. package/lib/types/client/i18n/runtime.d.ts +64 -0
  69. package/lib/types/client/i18n/zh.d.ts +8 -0
  70. package/lib/types/client/index.d.ts +36 -0
  71. package/lib/types/client/inline.d.ts +5 -0
  72. package/lib/types/client/interaction-store.d.ts +48 -0
  73. package/lib/types/client/mermaid-core.d.ts +8 -0
  74. package/lib/types/client/mermaid-lazy.d.ts +9 -0
  75. package/lib/types/client/mermaid-safe.d.ts +52 -0
  76. package/lib/types/client/panel-command.d.ts +34 -0
  77. package/lib/types/client/panel-store.d.ts +94 -0
  78. package/lib/types/client/panel.d.ts +18 -0
  79. package/lib/types/client/parse-partial.d.ts +63 -0
  80. package/lib/types/client/primitive-adapter.d.ts +4 -0
  81. package/lib/types/client/primitive-labels.d.ts +18 -0
  82. package/lib/types/client/safe-math.d.ts +43 -0
  83. package/lib/types/client/scene3d-core.d.ts +21 -0
  84. package/lib/types/client/scene3d-lazy.d.ts +8 -0
  85. package/lib/types/client/session-resolver.d.ts +8 -0
  86. package/lib/types/client/source-fence.d.ts +29 -0
  87. package/lib/types/client/spec.d.ts +709 -0
  88. package/lib/types/client/standalone/asset-loader.d.ts +2 -0
  89. package/lib/types/client/standalone/bootstrap-types.d.ts +9 -0
  90. package/lib/types/client/standalone/katex-style.d.ts +1 -0
  91. package/lib/types/client/standalone/primitive-adapter.d.ts +54 -0
  92. package/lib/types/client/standalone/runtime.d.ts +2 -0
  93. package/lib/types/client/submission-registry.d.ts +51 -0
  94. package/lib/types/client/svg-fence.d.ts +2 -0
  95. package/lib/types/client/table-details.d.ts +20 -0
  96. package/lib/types/client/templates.d.ts +41 -0
  97. package/lib/types/client/toolview.d.ts +7 -0
  98. package/lib/types/client/walk-spec.d.ts +3 -0
  99. package/lib/types/index.d.ts +1 -0
  100. package/lib/types/plugin/chart-contract.d.ts +9 -0
  101. package/lib/types/plugin/fence-feedback.d.ts +151 -0
  102. package/lib/types/plugin/genui-diagnostic.d.ts +13 -0
  103. package/lib/types/plugin/index.d.ts +35 -0
  104. package/lib/types/plugin/inline-content-diagnostic.d.ts +8 -0
  105. package/lib/types/plugin/invariant.d.ts +15 -0
  106. package/lib/types/plugin/tool.d.ts +27 -0
  107. package/lib/types/shared/fence-repair.d.ts +78 -0
  108. package/lib/types/shared/fence-resolve.d.ts +39 -0
  109. package/package.json +249 -4
  110. package/src/client/EChartNode.tsx +466 -0
  111. package/src/client/ErrorBoundary.tsx +67 -0
  112. package/src/client/GenuiBlock.module.css +2221 -0
  113. package/src/client/GenuiBlock.tsx +235 -0
  114. package/src/client/PlotBlock.module.css +171 -0
  115. package/src/client/PlotBlock.tsx +492 -0
  116. package/src/client/TemplateDrawer.module.css +152 -0
  117. package/src/client/TemplateDrawer.tsx +147 -0
  118. package/src/client/achievement-store.ts +151 -0
  119. package/src/client/achievement-toast.tsx +71 -0
  120. package/src/client/achievements.ts +160 -0
  121. package/src/client/action-context.ts +32 -0
  122. package/src/client/artifact/ArtifactExport.module.css +64 -0
  123. package/src/client/artifact/ExportableGenuiBlock.tsx +100 -0
  124. package/src/client/artifact/create.ts +69 -0
  125. package/src/client/artifact/download.ts +42 -0
  126. package/src/client/artifact/html.ts +157 -0
  127. package/src/client/artifact/index.ts +15 -0
  128. package/src/client/artifact/json.ts +6 -0
  129. package/src/client/artifact/parse.ts +32 -0
  130. package/src/client/artifact/portability.ts +47 -0
  131. package/src/client/artifact/standalone-theme.ts +94 -0
  132. package/src/client/artifact/types.ts +44 -0
  133. package/src/client/asset-echarts-core.ts +39 -0
  134. package/src/client/asset-echarts.ts +27 -0
  135. package/src/client/asset-loader.ts +96 -0
  136. package/src/client/asset-mermaid.ts +13 -0
  137. package/src/client/asset-three.ts +12 -0
  138. package/src/client/blocks/advanced.tsx +537 -0
  139. package/src/client/blocks/basic.tsx +121 -0
  140. package/src/client/blocks/charts.tsx +999 -0
  141. package/src/client/blocks/checkbox.tsx +61 -0
  142. package/src/client/blocks/diagram/geometry.ts +151 -0
  143. package/src/client/blocks/diagram/index.tsx +293 -0
  144. package/src/client/blocks/diagram/layout.ts +202 -0
  145. package/src/client/blocks/diagram/theme.ts +127 -0
  146. package/src/client/blocks/forms.tsx +531 -0
  147. package/src/client/blocks/image.tsx +28 -0
  148. package/src/client/blocks/render-node.tsx +494 -0
  149. package/src/client/blocks/state.ts +65 -0
  150. package/src/client/blocks/svg.tsx +66 -0
  151. package/src/client/dom-fence.tsx +1123 -0
  152. package/src/client/echarts-engine.ts +9 -0
  153. package/src/client/echarts-lazy.ts +41 -0
  154. package/src/client/embed.ts +19 -0
  155. package/src/client/fence-render.tsx +266 -0
  156. package/src/client/gallery.ts +215 -0
  157. package/src/client/genui-runtime/diagnostics.ts +165 -0
  158. package/src/client/genui-runtime/index.ts +1 -0
  159. package/src/client/genui-runtime/limits.ts +54 -0
  160. package/src/client/genui-runtime/normalize.ts +329 -0
  161. package/src/client/genui-runtime/schema.ts +352 -0
  162. package/src/client/genui-runtime/value-utils.ts +67 -0
  163. package/src/client/guard.ts +1965 -0
  164. package/src/client/i18n/en.ts +335 -0
  165. package/src/client/i18n/index.ts +125 -0
  166. package/src/client/i18n/runtime.ts +130 -0
  167. package/src/client/i18n/zh.ts +330 -0
  168. package/src/client/index.tsx +228 -0
  169. package/src/client/inline.ts +106 -0
  170. package/src/client/interaction-store.ts +127 -0
  171. package/src/client/mermaid-core.ts +158 -0
  172. package/src/client/mermaid-lazy.ts +31 -0
  173. package/src/client/mermaid-safe.ts +122 -0
  174. package/src/client/panel-command.ts +138 -0
  175. package/src/client/panel-store.ts +471 -0
  176. package/src/client/panel.tsx +287 -0
  177. package/src/client/parse-partial.ts +170 -0
  178. package/src/client/primitive-adapter.ts +13 -0
  179. package/src/client/primitive-labels.ts +55 -0
  180. package/src/client/safe-math.ts +298 -0
  181. package/src/client/scene3d-core.ts +195 -0
  182. package/src/client/scene3d-lazy.ts +26 -0
  183. package/src/client/session-resolver.ts +33 -0
  184. package/src/client/source-fence.ts +70 -0
  185. package/src/client/spec.ts +896 -0
  186. package/src/client/standalone/asset-loader.ts +9 -0
  187. package/src/client/standalone/bootstrap-types.ts +11 -0
  188. package/src/client/standalone/katex-style.ts +1 -0
  189. package/src/client/standalone/primitive-adapter.tsx +94 -0
  190. package/src/client/standalone/runtime.tsx +27 -0
  191. package/src/client/submission-registry.ts +150 -0
  192. package/src/client/svg-fence.tsx +39 -0
  193. package/src/client/table-details.ts +151 -0
  194. package/src/client/templates.ts +322 -0
  195. package/src/client/toolview.tsx +67 -0
  196. package/src/client/walk-spec.ts +43 -0
  197. package/src/css-modules.d.ts +5 -0
  198. package/src/index.ts +9 -0
  199. package/src/plugin/chart-contract.ts +13 -0
  200. package/src/plugin/fence-feedback.ts +655 -0
  201. package/src/plugin/genui-diagnostic.ts +112 -0
  202. package/src/plugin/index.ts +224 -0
  203. package/src/plugin/inline-content-diagnostic.ts +178 -0
  204. package/src/plugin/invariant.ts +30 -0
  205. package/src/plugin/node-shims.d.ts +31 -0
  206. package/src/plugin/tool.ts +424 -0
  207. package/src/shared/fence-repair.ts +536 -0
  208. package/src/shared/fence-resolve.ts +80 -0
  209. package/tsconfig.json +35 -0
  210. package/tsdown.config.ts +275 -0
@@ -0,0 +1,335 @@
1
+ /**
2
+ * English dictionary — the CANONICAL key set.
3
+ *
4
+ * `GenuiTextKey` derives from this object, so a key added here becomes a
5
+ * compile error in every other dictionary until it is translated. English is
6
+ * also the per-key fallback chain terminus (see runtime.ts).
7
+ *
8
+ * Keys are namespaced by surface: `panel.*`, `tpl.*`, `ach.*`, `label.*`,
9
+ * `block.*`, `err.*`.
10
+ */
11
+ export const EN = {
12
+ // --------------------------------------------------------- artifacts
13
+ 'artifact.export': 'Export',
14
+ 'artifact.exportHtml': 'HTML',
15
+ 'artifact.exportJson': 'GenUI JSON',
16
+ 'artifact.exportFailed': 'Export failed. Try again.',
17
+ 'artifact.unsupportedCustom': 'Cannot export HTML because the standalone runtime cannot render custom components: {types}. Export GenUI JSON to preserve these nodes.',
18
+ 'artifact.externalMediaNotice': 'External media may not appear when this file is opened offline.',
19
+
20
+ // ---------------------------------------------------------------- panel
21
+ 'panel.badge': 'Panel',
22
+ 'panel.title.default': 'GenUI panel',
23
+ 'panel.title.explore': 'GenUI explorer',
24
+ 'panel.templates': 'Templates',
25
+ 'panel.templates.aria': 'Template center',
26
+ 'panel.templates.title': 'Template center: preview and try GenUI examples',
27
+ 'panel.achievements': 'Trophies',
28
+ 'panel.achievements.aria': 'Exploration trophies',
29
+ 'panel.achievements.title': 'Exploration trophies: badges and progress',
30
+ 'panel.close.aria': 'Close panel',
31
+ 'panel.resize.aria': 'Resize panel height',
32
+ 'panel.hint': '💡 This is the GenUI session panel — hit “Templates” above to browse runnable examples',
33
+ 'panel.boundary': 'panel',
34
+ 'panel.flash.inserted': 'Instruction inserted into the composer — send it to generate',
35
+
36
+ // -------------------------------------------------------- panel command
37
+ 'panel.cmd.hint': 'Open the GenUI panel; /panel <instruction> to customize; /panel clear to empty',
38
+ 'panel.cmd.description': 'Open the GenUI panel (/panel clear empties it; /panel <instruction> tailors the content)',
39
+ 'panel.default.heading': 'GenUI generative interface',
40
+ 'panel.default.subtitle': 'The panel updates in place: say “update the panel” in chat, or run /panel again to refresh.',
41
+ 'panel.default.stat.components': 'Components',
42
+ 'panel.default.stat.single': 'Primitives',
43
+ 'panel.default.stat.composite': 'Composites',
44
+ 'panel.default.stat.advanced': 'Advanced',
45
+ 'panel.default.group.single': 'Primitives ×12',
46
+ 'panel.default.group.composite': 'Composites ×8',
47
+ 'panel.default.group.data': 'Data ×7',
48
+ 'panel.default.group.interactive': 'Interactive ×5',
49
+ 'panel.default.group.advanced': 'Advanced ×5',
50
+ 'panel.default.group.teaching': 'Teaching ×1',
51
+ 'panel.default.callout.title': 'How to update',
52
+ 'panel.default.callout.body': 'Say “update the panel” in chat → the model emits a panel:true fence; /panel clear empties it.',
53
+
54
+ // ------------------------------------------------------ template center
55
+ 'tpl.category.all': 'All',
56
+ 'tpl.category.dashboard': 'Dashboard',
57
+ 'tpl.category.data': 'Data',
58
+ 'tpl.category.flow': 'Flow',
59
+ 'tpl.category.chart': 'Charts',
60
+ 'tpl.category.interactive': 'Interactive',
61
+ 'tpl.category.quiz': 'Quiz',
62
+ 'tpl.category.advanced': 'Advanced',
63
+ 'tpl.categories.aria': 'Template categories',
64
+ 'tpl.try': 'Try it: insert into composer',
65
+ 'tpl.copy': 'Copy instruction',
66
+ 'tpl.copied': '✓ Copied',
67
+ 'tpl.boundary.preview': 'template preview',
68
+ 'tpl.boundary.achievements': 'trophy page',
69
+
70
+ 'tpl.dashboard.name': 'Project dashboard',
71
+ 'tpl.dashboard.desc': 'Core metrics on one card: numbers, deltas and a progress bar — the decision at a glance.',
72
+ 'tpl.dashboard.instruction': 'Use dsh-ui to build a dashboard for this project: 4 key-metric stat cards (with deltas), an overall progress bar, and a list of today’s 3 todos. Title it “Project dashboard”.',
73
+ 'tpl.dashboard.demo.title': 'Project dashboard (example)',
74
+ 'tpl.dashboard.demo.metrics': 'This week’s key metrics',
75
+ 'tpl.dashboard.demo.done': 'Completed',
76
+ 'tpl.dashboard.demo.blocked': 'Blocked',
77
+ 'tpl.dashboard.demo.duration': 'Avg. cycle time',
78
+ 'tpl.dashboard.demo.coverage': 'Coverage',
79
+ 'tpl.dashboard.demo.progress': 'Overall progress',
80
+ 'tpl.dashboard.demo.milestone': 'v1.0 milestone',
81
+ 'tpl.dashboard.demo.todo': 'Today’s todos',
82
+ 'tpl.dashboard.demo.todo1': 'Review the M1 template-center PR',
83
+ 'tpl.dashboard.demo.todo2': 'Sync vendor to SSiD',
84
+ 'tpl.dashboard.demo.todo3': 'Wednesday standup deck',
85
+
86
+ 'tpl.compare.name': 'Option comparison',
87
+ 'tpl.compare.desc': 'Options scored dimension by dimension — the contested cells jump out.',
88
+ 'tpl.compare.instruction': 'Use dsh-ui to turn these options into a comparison table: options A/B/C × dimensions (cost / complexity / risk / payoff), marking the recommended column; add a callout at the top stating the conclusion.',
89
+ 'tpl.compare.demo.title': 'Option comparison (example)',
90
+ 'tpl.compare.demo.conclusion': 'Conclusion',
91
+ 'tpl.compare.demo.body': 'Option B wins overall: medium cost, low complexity, low risk.',
92
+ 'tpl.compare.demo.dimension': 'Dimension',
93
+ 'tpl.compare.demo.optionA': 'Option A',
94
+ 'tpl.compare.demo.optionB': 'Option B ★',
95
+ 'tpl.compare.demo.optionC': 'Option C',
96
+ 'tpl.compare.demo.cost': 'Cost',
97
+ 'tpl.compare.demo.complexity': 'Complexity',
98
+ 'tpl.compare.demo.risk': 'Risk',
99
+ 'tpl.compare.demo.payoff': 'Payoff',
100
+ 'tpl.compare.demo.high': 'High',
101
+ 'tpl.compare.demo.medium': 'Medium',
102
+ 'tpl.compare.demo.low': 'Low',
103
+ 'tpl.compare.demo.large': 'Large',
104
+ 'tpl.compare.demo.small': 'Small',
105
+
106
+ 'tpl.steps.name': 'Five-step walkthrough',
107
+ 'tpl.steps.desc': 'Key steps on a timeline, one line each — for tutorials, handovers and release runbooks.',
108
+ 'tpl.steps.instruction': 'Use dsh-ui to turn the procedure into a steps walkthrough: 5 steps following the real flow, each with a title and a line or two of detail, with a badge at the top showing the expected duration.',
109
+ 'tpl.steps.demo.title': 'Getting started (example)',
110
+ 'tpl.steps.demo.badge': 'About 5 minutes',
111
+ 'tpl.steps.demo.s1': 'Install the plugin',
112
+ 'tpl.steps.demo.s1desc': 'From the plugin center, or npm-install it into your profile',
113
+ 'tpl.steps.demo.s2': 'Send your first instruction',
114
+ 'tpl.steps.demo.s2desc': 'Ask the model to answer with a dsh-ui interface',
115
+ 'tpl.steps.demo.s3': 'Try the interaction',
116
+ 'tpl.steps.demo.s3desc': 'Click a button, grade a quiz, switch a tab — actions travel back to the model',
117
+ 'tpl.steps.demo.s4': 'Pin a panel',
118
+ 'tpl.steps.demo.s4desc': 'The model uses panel:true to pin results to the session panel',
119
+ 'tpl.steps.demo.s5': 'Advanced components',
120
+ 'tpl.steps.demo.s5desc': 'Charts, diagrams and 3D load lazily, on demand',
121
+
122
+ 'tpl.quiz.name': 'Pop quiz',
123
+ 'tpl.quiz.desc': 'Graded the moment you answer: right or wrong plus an explanation — good for training.',
124
+ 'tpl.quiz.instruction': 'Use dsh-ui to write 3 pop-quiz questions (quiz component: question + options, exactly one correct, each with an explanation), titled “Pop quiz”, graded as soon as an option is picked.',
125
+ 'tpl.quiz.demo.title': 'Pop quiz (example)',
126
+ 'tpl.quiz.demo.hint': 'Picking an option grades it instantly and reveals the explanation.',
127
+ 'tpl.quiz.demo.q1': 'What is the smallest unit of a DSH plugin?',
128
+ 'tpl.quiz.demo.q1a': 'A service',
129
+ 'tpl.quiz.demo.q1b': 'A plugin (a cordis plugin)',
130
+ 'tpl.quiz.demo.q1bfx': '✓ Everything is a plugin: services, tools and UI all register through one.',
131
+ 'tpl.quiz.demo.q1c': 'A tool',
132
+ 'tpl.quiz.demo.q1exp': 'DSH is built on cordis: every capability, services and tools included, registers as a plugin.',
133
+ 'tpl.quiz.demo.q2': 'Who emits a dsh-ui fence?',
134
+ 'tpl.quiz.demo.q2a': 'The user',
135
+ 'tpl.quiz.demo.q2b': 'The model',
136
+ 'tpl.quiz.demo.q2bfx': '✓ The model writes the dsh-ui fence into its reply.',
137
+ 'tpl.quiz.demo.q2c': 'The host',
138
+ 'tpl.quiz.demo.q2exp': 'The model emits the fence; the renderer paints it into real components.',
139
+ 'tpl.quiz.demo.q3': 'Where does a panel:true fence render?',
140
+ 'tpl.quiz.demo.q3a': 'The message flow',
141
+ 'tpl.quiz.demo.q3b': 'The session panel dock',
142
+ 'tpl.quiz.demo.q3bfx': '✓ Panel updates never spam the transcript.',
143
+ 'tpl.quiz.demo.q3c': 'The settings page',
144
+
145
+ 'tpl.stats.name': 'Key figures + progress',
146
+ 'tpl.stats.desc': 'Numbers, progress and milestones in one delivery — the standard weekly report.',
147
+ 'tpl.stats.instruction': 'Use dsh-ui to summarize this week: a keyvalue block with 3 key figures, two progress bars (planned vs actual), and a timeline with 3 milestones. Title it “Weekly snapshot”.',
148
+ 'tpl.stats.demo.title': 'Weekly snapshot (example)',
149
+ 'tpl.stats.demo.done': 'Completed',
150
+ 'tpl.stats.demo.late': 'Late',
151
+ 'tpl.stats.demo.risk': 'Risks',
152
+ 'tpl.stats.demo.riskValue': '2 (both mitigated)',
153
+ 'tpl.stats.demo.planned': 'Planned progress',
154
+ 'tpl.stats.demo.actual': 'Actual progress',
155
+ 'tpl.stats.demo.mon': 'Monday',
156
+ 'tpl.stats.demo.monDesc': 'M1 development complete',
157
+ 'tpl.stats.demo.wed': 'Wednesday',
158
+ 'tpl.stats.demo.wedDesc': 'End-to-end verification passed',
159
+ 'tpl.stats.demo.fri': 'Friday',
160
+ 'tpl.stats.demo.friDesc': 'Shipped 0.9.4',
161
+
162
+ 'tpl.chart.name': 'Trend chart',
163
+ 'tpl.chart.desc': 'Data drawn straight into a chart — multiple series, trend visible at a glance.',
164
+ 'tpl.chart.instruction': 'Use dsh-ui to plot this data as a chart (bars, multi-series): completed vs planned over the last 6 weeks, with a one-line trend conclusion above the chart.',
165
+ 'tpl.chart.demo.title': 'Trend comparison (example)',
166
+ 'tpl.chart.demo.conclusion': 'Conclusion: completions rose 3 weeks running and overtook plan for the first time this week.',
167
+
168
+ 'tpl.tabs.name': 'Tabbed sections',
169
+ 'tpl.tabs.desc': 'A big block split into tabs: clear anchors, an uncluttered panel, no transcript spam.',
170
+ 'tpl.tabs.instruction': 'Use dsh-ui to split the content into three tabs: Overview / Details / FAQ, at most 3 points per tab. Title it “Feature tour”.',
171
+ 'tpl.tabs.demo.title': 'Feature tour (example)',
172
+ 'tpl.tabs.demo.overview': 'Overview',
173
+ 'tpl.tabs.demo.overviewBody': 'Three capabilities: live rendering, action round-trips, and a persistent panel.',
174
+ 'tpl.tabs.demo.details': 'Details',
175
+ 'tpl.tabs.demo.d1': 'Rendering: incremental fence parsing, painted as it streams',
176
+ 'tpl.tabs.demo.d2': 'Interaction: actions travel back and the model updates in place',
177
+ 'tpl.tabs.demo.d3': 'Panel: a session-level dock you can collapse and resize',
178
+ 'tpl.tabs.demo.faqBody': 'Q: What if the model never replies? A: Components still grade and expand locally.',
179
+
180
+ 'tpl.checklist.name': 'Release checklist',
181
+ 'tpl.checklist.desc': 'Tick every box before you ship: the list is the process, and gaps are visible.',
182
+ 'tpl.checklist.instruction': 'Use dsh-ui to build a release checklist: 6 tickable checkbox items (tests / docs / release / rollback / monitoring / announcement), with a badge at the top reading “Tick everything before merging”.',
183
+ 'tpl.checklist.demo.title': 'Release checklist (example)',
184
+ 'tpl.checklist.demo.badge': 'Tick everything before merging',
185
+ 'tpl.checklist.demo.c1': 'Unit tests pass',
186
+ 'tpl.checklist.demo.c2': 'Docs updated',
187
+ 'tpl.checklist.demo.c3': 'Release bundle ready',
188
+ 'tpl.checklist.demo.c4': 'Rollback plan',
189
+
190
+ 'tpl.accordion.name': 'FAQ accordion',
191
+ 'tpl.accordion.desc': 'Questions and answers folded away: long documents get short and answers stop intimidating.',
192
+ 'tpl.accordion.instruction': 'Use dsh-ui to build an FAQ accordion: 5 common questions, the question as the header and the answer inside, with the first one expanded by default.',
193
+ 'tpl.accordion.demo.title': 'FAQ (example)',
194
+ 'tpl.accordion.demo.q1': 'Which chart types are supported?',
195
+ 'tpl.accordion.demo.a1': 'chart (bars/line/donut), plot for function graphs, and echart for the full chart library.',
196
+ 'tpl.accordion.demo.q2': 'Does the panel persist?',
197
+ 'tpl.accordion.demo.a2': 'The same content fingerprint restores its state across refresh and replay; new content resets.',
198
+ 'tpl.accordion.demo.q3': 'Do interactions disturb the model?',
199
+ 'tpl.accordion.demo.a3': 'Only components carrying an action send anything; pure display costs zero round-trips.',
200
+
201
+ 'tpl.diagram.name': 'System architecture',
202
+ 'tpl.diagram.desc': 'Architecture drawn as SVG: layered nodes, real edges, labelled zones — clearer than a screenshot.',
203
+ 'tpl.diagram.instruction': 'Use dsh-ui to draw an architecture diagram: 5 nodes of this system and their connections (kind: architecture or flowchart), including one security zone.',
204
+ 'tpl.diagram.demo.title': 'Architecture (example)',
205
+ 'tpl.diagram.demo.caption': 'DSH plugin path',
206
+ 'tpl.diagram.demo.model': 'Model',
207
+ 'tpl.diagram.demo.plugin': 'Plugin',
208
+ 'tpl.diagram.demo.host': 'Host',
209
+
210
+ 'tpl.3d.name': '3D scene',
211
+ 'tpl.3d.desc': 'A rotatable 3D scene — for product demos and spatial explanations.',
212
+ 'tpl.3d.instruction': 'Use dsh-ui to render a 3D scene (scene3d): a cube and a sphere, titled “Example scene”, with a sentence on when to use it.',
213
+ 'tpl.3d.demo.title': '3D scene (example)',
214
+ 'tpl.3d.demo.note': 'The first load downloads three.js (~700KB, lazily); afterwards it comes from cache.',
215
+ 'tpl.3d.demo.scene': 'Example scene',
216
+
217
+ 'tpl.breadcrumb.name': 'Path breadcrumb',
218
+ 'tpl.breadcrumb.desc': 'Long paths as breadcrumbs: file location and org hierarchy read instantly.',
219
+ 'tpl.breadcrumb.instruction': 'Use dsh-ui to show the current workspace layout: a breadcrumb for the file path (4 segments) and a file-tree of the project (3 directories, 2 children each).',
220
+ 'tpl.breadcrumb.demo.title': 'Directory layout (example)',
221
+ 'tpl.breadcrumb.demo.workspace': 'Workspace',
222
+
223
+ // ------------------------------------------------------- achievements
224
+ 'ach.page.title': 'GenUI exploration trophies',
225
+ 'ach.stat.unlocked': 'Unlocked',
226
+ 'ach.stat.rendered': 'Interfaces rendered',
227
+ 'ach.stat.interactions': 'Interactions',
228
+ 'ach.progress': 'Exploration progress',
229
+ 'ach.rarity.common': 'Common',
230
+ 'ach.rarity.rare': 'Rare',
231
+ 'ach.rarity.legendary': 'Legendary',
232
+ 'ach.hidden.name': '?',
233
+ 'ach.hidden.desc': 'Keep exploring to reveal',
234
+ 'ach.toast.unlocked': 'Trophy unlocked: {name}',
235
+
236
+ 'ach.first-fence.name': 'First contact',
237
+ 'ach.first-fence.desc': 'Rendered your first GenUI interface.',
238
+ 'ach.fence-5.name': 'Getting the hang of it',
239
+ 'ach.fence-5.desc': 'Rendered 5 interfaces.',
240
+ 'ach.fence-25.name': 'Interface weaver',
241
+ 'ach.fence-25.desc': 'Rendered 25 interfaces.',
242
+ 'ach.fence-50.name': 'Soul of the blueprint',
243
+ 'ach.fence-50.desc': 'Rendered 50 interfaces — you and GenUI go way back.',
244
+ 'ach.first-interaction.name': 'The button works',
245
+ 'ach.first-interaction.desc': 'Triggered a component interaction for the first time.',
246
+ 'ach.interaction-10.name': 'Little puppeteer',
247
+ 'ach.interaction-10.desc': 'Triggered 10 component interactions.',
248
+ 'ach.first-panel.name': 'Pinned to the wall',
249
+ 'ach.first-panel.desc': 'Pinned content to the session panel for the first time.',
250
+ 'ach.panel-5.name': 'Panel keeper',
251
+ 'ach.panel-5.desc': 'Used the panel in 5 different sessions.',
252
+ 'ach.first-chart.name': 'Chart enthusiast',
253
+ 'ach.first-chart.desc': 'Rendered your first chart (chart/plot/echart).',
254
+ 'ach.chart-10.name': 'Data visualizer',
255
+ 'ach.chart-10.desc': 'Charts appeared in 10 interfaces.',
256
+ 'ach.first-advanced.name': 'Power user',
257
+ 'ach.first-advanced.desc': 'Used 3D, a chart engine, or an architecture diagram.',
258
+ 'ach.template-1.name': 'Template student',
259
+ 'ach.template-1.desc': 'Tried a template from the template center.',
260
+
261
+ // ------------------------------------------------- primitive chrome
262
+ 'label.copy': 'Copy',
263
+ /** CodeBlock's post-copy button label. */
264
+ 'label.copied': 'Copied',
265
+ /** Bare "done" state used by JsonTree and the table copy chips. */
266
+ 'label.copiedDone': 'Copied',
267
+ /** Inline chip with its check mark. */
268
+ 'label.copiedShort': '✓ Copied',
269
+ 'label.copiedToClipboard': 'Copied to clipboard',
270
+ 'label.copyFailed': 'Copy failed',
271
+ 'label.code': 'Code',
272
+ 'label.wrap': 'Wrap lines',
273
+ 'label.unwrap': 'Unwrap lines',
274
+ 'label.collapse': 'Collapse',
275
+ 'label.collapseDiff.aria': 'Collapse diff',
276
+ 'label.expandDiff.aria': 'Show the remaining {hidden} diff lines',
277
+ 'label.expandDiff': '… {hidden} more lines',
278
+ 'label.diffFiles': '{count} files',
279
+ 'label.copyValue': 'Copy value',
280
+ 'label.copyJson': 'Copy JSON',
281
+ 'label.copyPath': 'Copy property path',
282
+ 'label.copyPrettyJson': 'Copy formatted JSON',
283
+ 'label.copyCompactJson': 'Copy compact JSON',
284
+ 'label.collapseNode': 'Collapse JSON node',
285
+ 'label.expandNode': 'Expand JSON node',
286
+ 'label.copyButtonTitle': '{action}; right-click for copy options',
287
+
288
+ // ------------------------------------------------- component chrome
289
+ 'block.copyMarkdown': 'Copy Markdown',
290
+ 'block.copyCsv': 'Copy CSV',
291
+ 'block.total': 'Total',
292
+ 'block.filteredRows': '{visible} / {total} rows after filtering',
293
+ 'block.filterMatch': '{shown} / {total} matched',
294
+ 'block.triggered': '✓ Sent',
295
+ 'block.triggeredPlain': 'Sent',
296
+ 'block.audio': 'Audio',
297
+ 'block.audioError': 'Audio cannot be played',
298
+ 'block.video': 'Video',
299
+ 'block.videoError': 'Video cannot be played',
300
+ 'block.image': 'Image',
301
+ 'block.imageError': 'Image failed to load',
302
+ 'block.svgLabel': 'SVG diagram',
303
+ 'block.svgPreview': 'Preview',
304
+ 'block.svgSource': 'Source',
305
+ 'block.svgError': 'SVG could not be displayed — showing the source instead',
306
+ 'block.mermaidError': 'Invalid diagram syntax — showing the source instead',
307
+ 'block.mermaidLoading': 'Rendering…',
308
+ 'block.scene3dLoading': 'Loading 3D scene…',
309
+ 'block.scene3dError': '3D rendering failed',
310
+ 'block.quizCorrect': '✓ Correct!',
311
+ 'block.quizWrong': '✗ Try again',
312
+ 'block.quizRetry': 'Start over',
313
+ 'block.selectPlaceholder': 'Choose…',
314
+ 'block.score': 'Score',
315
+ 'block.scoreUngraded': ' ({count} unanswered, not scored)',
316
+ 'block.yourAnswer': 'Your answer:',
317
+ 'block.correctAnswer': ' Correct answer:',
318
+ 'block.selectedCount': '{answered}/{total} answered',
319
+ 'block.target': 'Target {value}%',
320
+ 'block.chart.barsAria': 'Horizontal bar chart, {count} groups',
321
+ 'block.chart.barsSummary': 'Bar chart, {count} groups, max {max}',
322
+ 'block.chart.lineSeries': 'Line chart, {count} series, range {min} to {max}',
323
+ 'block.chart.linePoints': 'Line chart, {count} points, range {min} to {max}',
324
+ 'block.chart.donutSummary': 'Donut chart, {count} slices, total {total}',
325
+ 'block.chart.node': 'Point',
326
+
327
+ // -------------------------------------------------------- error text
328
+ 'err.boundary.generic': 'this interface',
329
+ 'err.boundary.fence': 'this interface',
330
+ 'err.boundary.body': '⚠️ {label} failed to render (isolated — the rest of the reply is unaffected)',
331
+ 'err.fieldValidation': 'GenUI field validation failed: {errors}',
332
+ 'err.chartValidation': 'chart field validation failed: {errors}',
333
+ 'err.fenceKeptAsCode': '⚠️ dsh-ui {diagnostic} — the fence stays a code block; fix it and resend.',
334
+ 'err.fenceParse': '⚠️ dsh-ui fence JSON failed to parse{diagnostic} — the fence stays a code block; ask the model to fix the JSON and resend.',
335
+ } as const
@@ -0,0 +1,125 @@
1
+ /**
2
+ * i18n public face: the translate function, the React binding, and the host
3
+ * locale bridge.
4
+ *
5
+ * @module i18n
6
+ */
7
+ import { useSyncExternalStore } from 'react'
8
+ import {
9
+ dictOf,
10
+ getLocale,
11
+ getLocaleRevision,
12
+ LOCALE_IDS,
13
+ setLocale,
14
+ subscribeLocale,
15
+ t,
16
+ type LocaleId,
17
+ } from './runtime.ts'
18
+
19
+ export {
20
+ detectLocale,
21
+ dictOf,
22
+ FALLBACK_LOCALE,
23
+ getLocale,
24
+ getLocaleRevision,
25
+ LOCALE_IDS,
26
+ normalizeLocale,
27
+ setLocale,
28
+ subscribeLocale,
29
+ t,
30
+ type GenuiTextKey,
31
+ type LocaleDict,
32
+ type LocaleId,
33
+ } from './runtime.ts'
34
+
35
+ /**
36
+ * Subscribe a component to locale changes.
37
+ *
38
+ * Returns the translate function itself (stable identity — `t` reads the
39
+ * active locale at call time), so a component calls `const t = useT()` and
40
+ * re-renders whenever the language switches.
41
+ */
42
+ export function useT(): typeof t {
43
+ useSyncExternalStore(subscribeLocale, getLocaleRevision, getLocaleRevision)
44
+ return t
45
+ }
46
+
47
+ /**
48
+ * Subscribe to locale changes and return the current revision.
49
+ *
50
+ * `t` keeps a STABLE identity on purpose (so it can ride inject surfaces
51
+ * without breaking memoization), which means it cannot serve as a `useMemo`
52
+ * dependency. Use this revision instead when a memoized value embeds
53
+ * translated text.
54
+ */
55
+ export function useLocaleRevision(): number {
56
+ return useSyncExternalStore(subscribeLocale, getLocaleRevision, getLocaleRevision)
57
+ }
58
+
59
+ /** The minimal shape this package needs from the host locale runtime. */
60
+ interface HostLocaleRuntime {
61
+ getLocale?: () => { active?: string }
62
+ subscribe?: (fn: () => void) => () => void
63
+ register?: (ns: string, locale: string, dict: Record<string, string>) => () => void
64
+ }
65
+
66
+ /** Namespace this package registers its dictionaries under on the host. */
67
+ export const GENUI_LOCALE_NS = 'genui'
68
+
69
+ /**
70
+ * Bridge this package's locale to the DSH host language preference.
71
+ *
72
+ * Hosts that ship `@deepseek-ai/dsh-client-locale` own the user's language
73
+ * choice; GenUI must follow it rather than keep a second, divergent setting.
74
+ * The bridge:
75
+ * - publishes both dictionaries into the host registry (so host-side
76
+ * surfaces can read GenUI keys), and
77
+ * - mirrors the host's active locale into this runtime, now and on change.
78
+ *
79
+ * Hosts WITHOUT the locale service degrade silently to browser detection —
80
+ * the service is read optionally, never declared in `inject`, because a
81
+ * declared-but-absent service parks the fiber forever and would kill all
82
+ * GenUI rendering on pristine hosts.
83
+ *
84
+ * @param ctx - client cordis context (read optionally).
85
+ * @returns disposer removing the registrations and the subscription.
86
+ */
87
+ export function bridgeHostLocale(ctx: { get?: (name: string) => unknown }): () => void {
88
+ const locale = typeof ctx.get === 'function'
89
+ ? (ctx.get('locale') as HostLocaleRuntime | undefined)
90
+ : undefined
91
+ if (locale === undefined) return () => {}
92
+
93
+ const disposers: Array<() => void> = []
94
+
95
+ // Publish our dictionaries under the plugin's own namespace. Untyped form:
96
+ // `genui` is not merged into the host's LocaleNamespaceMap.
97
+ if (typeof locale.register === 'function') {
98
+ for (const id of LOCALE_IDS) {
99
+ try {
100
+ disposers.push(locale.register(GENUI_LOCALE_NS, id, { ...dictOf(id) }))
101
+ } catch {
102
+ // A duplicate (ns, locale) registration throws — another GenUI
103
+ // instance already owns the namespace. Rendering is unaffected:
104
+ // this package always reads its own runtime, not the host registry.
105
+ }
106
+ }
107
+ }
108
+
109
+ // Mirror the host's active locale, now and on every change.
110
+ const sync = (): void => {
111
+ const active = locale.getLocale?.().active
112
+ if (typeof active === 'string') setLocale(active)
113
+ }
114
+ sync()
115
+ if (typeof locale.subscribe === 'function') disposers.push(locale.subscribe(sync))
116
+
117
+ return () => {
118
+ for (const dispose of disposers) dispose()
119
+ }
120
+ }
121
+
122
+ /** Current locale id, for non-React call sites. */
123
+ export function currentLocale(): LocaleId {
124
+ return getLocale()
125
+ }
@@ -0,0 +1,130 @@
1
+ /**
2
+ * i18n runtime — the single source of user-facing text for the browser half.
3
+ *
4
+ * Every string the USER reads (panel chrome, primitive labels, template
5
+ * center, achievements, component chrome, in-page error text) resolves
6
+ * through `t(key)` instead of being written into the component. Two
7
+ * dictionaries ship: `en` and `zh`.
8
+ *
9
+ * Locale resolution, in priority order:
10
+ * 1. An explicit {@link setLocale} call — the host locale bridge uses this
11
+ * to mirror the DSH language preference.
12
+ * 2. The browser's ordered language list (`navigator.languages`).
13
+ * 3. {@link FALLBACK_LOCALE} (English).
14
+ *
15
+ * English is also the per-key fallback: a key missing from the active
16
+ * dictionary resolves against `en` before degrading to the key itself, so a
17
+ * partially translated dictionary can never blank out the UI.
18
+ *
19
+ * MODEL-FACING text is deliberately NOT routed through here. The `[genui-action]`
20
+ * prompts and the fence vocabulary injected into the system prompt are a
21
+ * protocol between the plugin and the model, not chrome the user reads;
22
+ * translating them would change model behaviour rather than the UI language.
23
+ */
24
+ import { EN } from './en.ts'
25
+ import { ZH } from './zh.ts'
26
+
27
+ /** Locale ids this package ships dictionaries for. */
28
+ export type LocaleId = 'en' | 'zh'
29
+
30
+ /** The locale used when nothing else resolves, and the per-key fallback. */
31
+ export const FALLBACK_LOCALE: LocaleId = 'en'
32
+
33
+ /** Locale ids in display order. */
34
+ export const LOCALE_IDS: readonly LocaleId[] = ['en', 'zh']
35
+
36
+ /** A flat dictionary: key → template string with `{name}` placeholders. */
37
+ export type LocaleDict = Record<string, string>
38
+
39
+ /** Key domain of the shipped dictionaries (English is the complete set). */
40
+ export type GenuiTextKey = keyof typeof EN
41
+
42
+ const DICTS: Record<LocaleId, LocaleDict> = { en: EN, zh: ZH }
43
+
44
+ /** Narrow an arbitrary BCP 47-ish tag onto a shipped locale, or undefined. */
45
+ export function normalizeLocale(tag: string | undefined | null): LocaleId | undefined {
46
+ if (typeof tag !== 'string' || tag === '') return undefined
47
+ // Match on the primary subtag so `zh-CN`, `zh-Hant`, `en-GB` all resolve.
48
+ const primary = tag.toLowerCase().split(/[-_]/)[0]
49
+ return LOCALE_IDS.find(id => id === primary)
50
+ }
51
+
52
+ /** Resolve the browser's preferred shipped locale, else the fallback. */
53
+ export function detectLocale(): LocaleId {
54
+ if (typeof navigator === 'undefined') return FALLBACK_LOCALE
55
+ const nav = navigator as Navigator & { languages?: readonly string[] }
56
+ const tags: readonly string[] = Array.isArray(nav.languages) && nav.languages.length > 0
57
+ ? nav.languages
58
+ : [nav.language]
59
+ for (const tag of tags) {
60
+ const hit = normalizeLocale(tag)
61
+ if (hit !== undefined) return hit
62
+ }
63
+ return FALLBACK_LOCALE
64
+ }
65
+
66
+ let active: LocaleId = detectLocale()
67
+ /** Monotonic counter: the uSES snapshot every localized surface subscribes to. */
68
+ let revision = 0
69
+ const listeners = new Set<() => void>()
70
+
71
+ /** The active locale id. */
72
+ export function getLocale(): LocaleId {
73
+ return active
74
+ }
75
+
76
+ /**
77
+ * Snapshot for `useSyncExternalStore`: bumped on every locale change, so a
78
+ * component reading text through {@link t} re-renders when the user switches
79
+ * language. Stable between changes (uSES-safe).
80
+ */
81
+ export function getLocaleRevision(): number {
82
+ return revision
83
+ }
84
+
85
+ /** Subscribe to locale changes. Returns an idempotent unsubscribe. */
86
+ export function subscribeLocale(fn: () => void): () => void {
87
+ listeners.add(fn)
88
+ return () => {
89
+ listeners.delete(fn)
90
+ }
91
+ }
92
+
93
+ /**
94
+ * Switch the active locale. Unknown or unshipped tags are ignored (the UI
95
+ * keeps whatever it had rather than blanking out). Re-setting the current
96
+ * locale is a no-op: republishing would churn every subscriber for nothing.
97
+ */
98
+ export function setLocale(tag: string | LocaleId): void {
99
+ const next = normalizeLocale(tag)
100
+ if (next === undefined || next === active) return
101
+ active = next
102
+ revision += 1
103
+ for (const fn of [...listeners]) fn()
104
+ }
105
+
106
+ /** Interpolate `{name}` placeholders; a missing param keeps its placeholder. */
107
+ function interpolate(template: string, params?: Record<string, unknown>): string {
108
+ if (params === undefined) return template
109
+ return template.replace(/\{(\w+)\}/g, (whole, name: string) => {
110
+ const value = params[name]
111
+ return value === undefined ? whole : String(value)
112
+ })
113
+ }
114
+
115
+ /**
116
+ * Translate a key in the active locale.
117
+ *
118
+ * Lookup chain: active dictionary → English → the key itself. Returning the
119
+ * key (rather than an empty string) keeps an untranslated surface diagnosable
120
+ * in a screenshot instead of silently blank.
121
+ */
122
+ export function t(key: GenuiTextKey | string, params?: Record<string, unknown>): string {
123
+ const template = DICTS[active][key] ?? DICTS[FALLBACK_LOCALE][key] ?? key
124
+ return interpolate(template, params)
125
+ }
126
+
127
+ /** Read a full dictionary (the host locale bridge registers these). */
128
+ export function dictOf(id: LocaleId): LocaleDict {
129
+ return DICTS[id]
130
+ }