@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,27 @@
1
+ /**
2
+ * ECharts FULL asset-bundle entry: the complete engine, fetched only when a
3
+ * spec needs a chart type outside the core set or ships a raw `option`.
4
+ * Registers on `window.__GenuiAssets__.echartsFull`. Built as a standalone IIFE into
5
+ * `lib/assets/echarts.js` and served by the plugin's node-half route; loaded
6
+ * on demand by echarts-lazy when a spec contains an `echart` node.
7
+ * @module @changfenhuang/dsh-genui/client/asset-echarts
8
+ */
9
+ import { init as echartsInit, type EChartsType, type EChartsCoreOption } from 'echarts'
10
+ import 'echarts-wordcloud'
11
+
12
+ /** The engine surface registered by the echarts asset bundle. */
13
+ export interface EChartsAssetApi {
14
+ /** Create an ECharts instance on `el`, apply `option`, return the instance. */
15
+ createChart: (el: HTMLElement, option: EChartsCoreOption, opts?: { height?: number }) => EChartsType
16
+ }
17
+
18
+ function createChart(el: HTMLElement, option: EChartsCoreOption, opts?: { height?: number }): EChartsType {
19
+ const initOpts = opts !== undefined && opts.height !== undefined ? { height: opts.height } : undefined
20
+ const instance = echartsInit(el, undefined, initOpts)
21
+ instance.setOption(option)
22
+ return instance
23
+ }
24
+
25
+ const win = globalThis as unknown as { __GenuiAssets__?: Record<string, unknown> }
26
+ const assets = win.__GenuiAssets__ ?? (win.__GenuiAssets__ = {})
27
+ assets.echartsFull = { createChart }
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Asset-bundle loader: fetches one of the plugin's lazy engine bundles
3
+ * (`lib/assets/mermaid.js` / `lib/assets/three.js`) by script injection and
4
+ * hands back the engine surface the bundle registered on
5
+ * `window.__GenuiAssets__`.
6
+ *
7
+ * The bundles are served by the plugin's OWN node-half HTTP route
8
+ * (`/plugins/@changfenhuang/dsh-genui/assets/*`), registered through the host
9
+ * webserver service — no host source change needed, and the longest-prefix
10
+ * rule lets this route win over the generic `/plugins` bundle route. Each
11
+ * file is loaded at most once per page (promise memoized); a rejection is
12
+ * final for the page (the node's fallback UI takes over).
13
+ *
14
+ * The rev query rides the boot graph: the plugin's own row in
15
+ * `window.__DSH_BOOT__` carries the client bundle rev, so a plugin rebuild
16
+ * busts the asset cache together with the main bundle. Absent graph = no
17
+ * query; the route serves no-cache anyway.
18
+ * @module @changfenhuang/dsh-genui/client/asset-loader
19
+ */
20
+
21
+ /** The plugin's entry id — mirrors the loader entry name (package name). */
22
+ const PLUGIN_ID = '@changfenhuang/dsh-genui'
23
+
24
+ /** Assets directory served by the node-half route. */
25
+ const ASSET_DIR = `/plugins/${PLUGIN_ID}/assets`
26
+ let embeddedAssetBase: string | undefined
27
+
28
+ /** Set once before rendering when the host bundles engines locally. */
29
+ export function setGenuiAssetBase(baseURL: string): void {
30
+ embeddedAssetBase = new URL(baseURL, document.baseURI).href.replace(/\/?$/, '/')
31
+ }
32
+
33
+ /** Boot graph shape read from `window.__DSH_BOOT__` (subset, defensive). */
34
+ interface BootGraphLike {
35
+ entries?: Array<{ id?: string; rev?: string }>
36
+ }
37
+
38
+ /** The global the asset bundles register their engines on. */
39
+ interface AssetGlobal {
40
+ __GenuiAssets__?: Record<string, unknown>
41
+ }
42
+
43
+ /** Resolve an engine API registered by an inline standalone bundle. */
44
+ function preloadedAsset(name: string): unknown {
45
+ const key = name.replace(/-(\w)/g, (_match, char: string) => char.toUpperCase())
46
+ return (window as unknown as AssetGlobal).__GenuiAssets__?.[key]
47
+ }
48
+
49
+ /** Resolve an asset URL, appending the bundle rev for cache busting when the
50
+ * boot graph exposes it. */
51
+ export function assetUrl(file: string): string {
52
+ if (embeddedAssetBase !== undefined) return new URL(file, embeddedAssetBase).href
53
+ const graph = (window as unknown as { __DSH_BOOT__?: BootGraphLike }).__DSH_BOOT__
54
+ const rev = graph?.entries?.find(entry => entry.id === PLUGIN_ID)?.rev
55
+ return `${ASSET_DIR}/${file}${rev === undefined ? '' : `?rev=${rev}`}`
56
+ }
57
+
58
+ const pending = new Map<string, Promise<Record<string, unknown>>>()
59
+
60
+ /**
61
+ * Load one asset bundle and return the engines it registered. Memoized per
62
+ * file: repeated requests (several mermaid nodes, re-renders) share one
63
+ * script load; a failed load stays failed for the page (the component shows
64
+ * its fallback).
65
+ * @param name - 'mermaid', 'three', 'echarts-core', or 'echarts-full'.
66
+ * @returns the registered engine surface.
67
+ */
68
+ export function loadGenuiAsset<T>(name: 'mermaid' | 'three' | 'echarts-core' | 'echarts-full'): Promise<T> {
69
+ const preloaded = preloadedAsset(name)
70
+ if (preloaded !== undefined) return Promise.resolve(preloaded as T)
71
+ const file = `${name}.js`
72
+ const existing = pending.get(file)
73
+ if (existing !== undefined) return existing as Promise<T>
74
+ const task = new Promise<T>((resolve, reject) => {
75
+ const script = document.createElement('script')
76
+ script.src = assetUrl(file)
77
+ script.async = true
78
+ script.onload = () => {
79
+ const global = (window as unknown as AssetGlobal).__GenuiAssets__ ?? {}
80
+ // Asset files are kebab-case; the keys they register are camelCase.
81
+ const key = name.replace(/-(\w)/g, (_m, ch: string) => ch.toUpperCase())
82
+ const api = global[key]
83
+ if (api === undefined) {
84
+ reject(new Error(`genui asset '${file}' loaded but registered no '${name}' engine`))
85
+ return
86
+ }
87
+ resolve(api as T)
88
+ }
89
+ script.onerror = () => {
90
+ reject(new Error(`genui asset '${file}' failed to load (host asset route missing?)`))
91
+ }
92
+ document.head.appendChild(script)
93
+ })
94
+ pending.set(file, task as unknown as Promise<Record<string, unknown>>)
95
+ return task
96
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Mermaid asset-bundle entry: registers the mermaid engine on
3
+ * `window.__GenuiAssets__.mermaid`. Built as a standalone IIFE into
4
+ * `lib/assets/mermaid.js` and served by the plugin's node-half route; loaded
5
+ * on demand by mermaid-lazy.
6
+ * @module @changfenhuang/dsh-genui/client/asset-mermaid
7
+ */
8
+ import { renderMermaid } from './mermaid-core.ts'
9
+ import { assertSafeSvg, repairMermaidSource } from './mermaid-safe.ts'
10
+
11
+ const win = globalThis as unknown as { __GenuiAssets__?: Record<string, unknown> }
12
+ const assets = win.__GenuiAssets__ ?? (win.__GenuiAssets__ = {})
13
+ assets.mermaid = { assertSafeSvg, repairMermaidSource, renderMermaid }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * three.js asset-bundle entry: registers the scene renderer on
3
+ * `window.__GenuiAssets__.three`. Built as a standalone IIFE into
4
+ * `lib/assets/three.js` and served by the plugin's node-half route; loaded on
5
+ * demand by scene3d-lazy.
6
+ * @module @changfenhuang/dsh-genui/client/asset-three
7
+ */
8
+ import { mountScene } from './scene3d-core.ts'
9
+
10
+ const win = globalThis as unknown as { __GenuiAssets__?: Record<string, unknown> }
11
+ const assets = win.__GenuiAssets__ ?? (win.__GenuiAssets__ = {})
12
+ assets.three = { mountScene }