@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,64 @@
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
+ /** Locale ids this package ships dictionaries for. */
26
+ export type LocaleId = 'en' | 'zh';
27
+ /** The locale used when nothing else resolves, and the per-key fallback. */
28
+ export declare const FALLBACK_LOCALE: LocaleId;
29
+ /** Locale ids in display order. */
30
+ export declare const LOCALE_IDS: readonly LocaleId[];
31
+ /** A flat dictionary: key → template string with `{name}` placeholders. */
32
+ export type LocaleDict = Record<string, string>;
33
+ /** Key domain of the shipped dictionaries (English is the complete set). */
34
+ export type GenuiTextKey = keyof typeof EN;
35
+ /** Narrow an arbitrary BCP 47-ish tag onto a shipped locale, or undefined. */
36
+ export declare function normalizeLocale(tag: string | undefined | null): LocaleId | undefined;
37
+ /** Resolve the browser's preferred shipped locale, else the fallback. */
38
+ export declare function detectLocale(): LocaleId;
39
+ /** The active locale id. */
40
+ export declare function getLocale(): LocaleId;
41
+ /**
42
+ * Snapshot for `useSyncExternalStore`: bumped on every locale change, so a
43
+ * component reading text through {@link t} re-renders when the user switches
44
+ * language. Stable between changes (uSES-safe).
45
+ */
46
+ export declare function getLocaleRevision(): number;
47
+ /** Subscribe to locale changes. Returns an idempotent unsubscribe. */
48
+ export declare function subscribeLocale(fn: () => void): () => void;
49
+ /**
50
+ * Switch the active locale. Unknown or unshipped tags are ignored (the UI
51
+ * keeps whatever it had rather than blanking out). Re-setting the current
52
+ * locale is a no-op: republishing would churn every subscriber for nothing.
53
+ */
54
+ export declare function setLocale(tag: string | LocaleId): void;
55
+ /**
56
+ * Translate a key in the active locale.
57
+ *
58
+ * Lookup chain: active dictionary → English → the key itself. Returning the
59
+ * key (rather than an empty string) keeps an untranslated surface diagnosable
60
+ * in a screenshot instead of silently blank.
61
+ */
62
+ export declare function t(key: GenuiTextKey | string, params?: Record<string, unknown>): string;
63
+ /** Read a full dictionary (the host locale bridge registers these). */
64
+ export declare function dictOf(id: LocaleId): LocaleDict;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * 中文词典 — 与 en.ts 的键集完全一致(类型强制:缺键/多键都是编译错误)。
3
+ *
4
+ * 这些文案原本硬编码在组件里;此处保留原有措辞,仅把它们搬进词典,
5
+ * 因此中文用户看到的界面与 0.11.0 之前逐字相同。
6
+ */
7
+ import type { EN } from './en.ts';
8
+ export declare const ZH: Record<keyof typeof EN, string>;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * dsh-genui browser half: the ```dsh-ui fence renderer, the keyed toolview
3
+ * for the `render_ui` tool, and the session panel dock.
4
+ *
5
+ * Fence rendering is dual-mode, chosen at boot:
6
+ * - **Registry channel** (contract hosts): the host's MarkdownText resolves
7
+ * ```dsh-ui fences through the fence-registry extension point; this package
8
+ * registers `renderGenuiFence`. Action callbacks ride the host-installed
9
+ * GenuiActionContext.
10
+ * - **DOM channel** (pristine hosts): no extension point exists, so
11
+ * `dom-fence.ts` observes the conversation DOM, finds settled stock code
12
+ * blocks labelled `dsh-ui`, and mounts the same render pipeline in its own
13
+ * React roots — wrapped in the plugin-owned GenuiActionContext that relays
14
+ * `[genui-action]` through the scoped conversation send. Either way the
15
+ * deployment is the STOCK DSH snapshot plus this plugin.
16
+ *
17
+ * The renderer parses the fence body with the partial parser: while the reply
18
+ * streams, every FINISHED component appears the moment its JSON object
19
+ * closes, so the UI assembles top-down before the fence (or reply) completes.
20
+ * A body with no finished component yet falls back to a plain code block.
21
+ * @module @changfenhuang/dsh-genui/client
22
+ */
23
+ import type { Context } from '@deepseek-ai/cordis';
24
+ import { renderGenuiFence } from './fence-render.tsx';
25
+ /** Add low-priority prefetch links for the lazy engine assets (mermaid/three).
26
+ * Browser-dependent: some engines ignore `<link rel=prefetch>`; harmless
27
+ * either way — the on-demand loader still covers a cache miss. Exported for
28
+ * tests. */
29
+ export declare function prefetchGenuiAssets(): void;
30
+ /** Cordis client entry: register the fence renderer on boot, the keyed
31
+ * toolview for the render_ui tool, and the session panel dock; returning the
32
+ * disposers lets cordis tear all registrations down on plugin unload. */
33
+ export declare function apply(ctx: Context): () => void;
34
+ export declare const inject: string[];
35
+ export { renderGenuiFence };
36
+ export type { GenuiFenceContext } from './fence-render.tsx';
@@ -0,0 +1,5 @@
1
+ /** Shared rich text for GenUI labels and content. Data values stay unchanged. */
2
+ import { type ReactNode } from 'react';
3
+ export declare function hasInlineMarkup(text: string): boolean;
4
+ /** Render safe phrasing content, usable in headings, buttons and labels too. */
5
+ export declare function renderInline(text: string, allowLinks?: boolean, depth?: number): ReactNode;
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Interaction-state store: durable per-block GenUI interaction state
3
+ * (radio answers, checkbox groups, submit lock, input/textarea values) in
4
+ * localStorage.
5
+ *
6
+ * LOCAL-FIRST persistence: a ```dsh-ui block's interactive state survives
7
+ * page refresh and session reopen because it is keyed by
8
+ * `session + block slot + content fingerprint` — replaying the same message
9
+ * (same content) restores the exact state, while NEW content (换题, edited
10
+ * spec) gets a fresh key and thus a clean slate. Different messages never
11
+ * share state because their content fingerprints differ.
12
+ *
13
+ * Bounded: at most MAX_BLOCKS entries, LRU-evicted on write; each block's
14
+ * payload is small (answer maps + a few field values).
15
+ * @module @changfenhuang/dsh-genui/client/interaction-store
16
+ */
17
+ /** Durable state of one UI block. */
18
+ export interface BlockInteractionState {
19
+ /** group → chosen option label (radio aggregation answers). */
20
+ answers?: Record<string, string>;
21
+ /** group → chosen option labels (checkbox aggregation answers). Empty arrays
22
+ * are retained so an explicitly cleared group wins over `checked` defaults
23
+ * after refresh. */
24
+ multiAnswers?: Record<string, string[]>;
25
+ /** True after a local grading: the paper stays graded across refresh. */
26
+ locked?: boolean;
27
+ /** field id → current value (input/textarea with an `id`). */
28
+ fields?: Record<string, string>;
29
+ }
30
+ /** Load a block's durable state, or null when absent/corrupt. */
31
+ export declare function loadBlockState(stateKey: string): BlockInteractionState | null;
32
+ /** Save a block's durable state (LRU: touched keys move to the front). */
33
+ export declare function saveBlockState(stateKey: string, state: BlockInteractionState): void;
34
+ /** Forget a block's durable state (e.g. after a reset-to-empty). */
35
+ export declare function clearBlockState(stateKey: string): void;
36
+ /**
37
+ * Deterministic content fingerprint (djb2) for a block's raw fence body.
38
+ * Two render passes of the SAME content share a fingerprint (state restores);
39
+ * edited content gets a new one (fresh state). Not a security hash — the
40
+ * store only uses it for equality/identity.
41
+ */
42
+ export declare function fingerprint(raw: string): string;
43
+ /** Build the durable state key for a fence block: session + fence slot + content fingerprint. */
44
+ export declare function fenceStateKey(sessionId: string, fenceKey: number | string, raw: string): string;
45
+ /** Build the durable state key for a panel publish (content-keyed). */
46
+ export declare function panelStateKey(sessionId: string, raw: string): string;
47
+ /** Build the durable state key for a render_ui tool card (call-keyed). */
48
+ export declare function toolStateKey(sessionId: string, callId: string): string;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Render mermaid source to an SVG string.
3
+ * @param code - the mermaid diagram source.
4
+ * @returns the rendered SVG markup (verified free of script/event handlers).
5
+ * @throws when the kind is not whitelisted, rendering fails, or the output
6
+ * fails the sanitization check.
7
+ */
8
+ export declare function renderMermaid(code: string): Promise<string>;
@@ -0,0 +1,9 @@
1
+ export { assertSafeSvg, ensureFlowchartKind, repairMermaidSource } from './mermaid-safe.ts';
2
+ /**
3
+ * Render mermaid source to an SVG string (engine loaded on demand).
4
+ * @param code - the mermaid diagram source.
5
+ * @returns the rendered SVG markup (verified free of script/event handlers).
6
+ * @throws when the asset cannot load, the kind is not whitelisted, rendering
7
+ * fails, or the output fails the sanitization check.
8
+ */
9
+ export declare function renderMermaid(code: string): Promise<string>;
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Pure mermaid source utilities — no mermaid import, so this module can ship
3
+ * in the main client bundle while the heavy mermaid engine lives in a lazy
4
+ * asset bundle (`lib/assets/mermaid.js`, loaded on demand by mermaid-lazy).
5
+ * @module @changfenhuang/dsh-genui/client/mermaid-safe
6
+ */
7
+ /** Throws when `svg` carries script, event-handler attributes, or
8
+ * `javascript:` URIs. Exported for tests; `renderMermaid` is the only caller
9
+ * in production. */
10
+ export declare function assertSafeSvg(svg: string): void;
11
+ /**
12
+ * Best-effort repair of common model-authored label mistakes in graph /
13
+ * flowchart sources, used only when the original fails to render:
14
+ * - drop backticks — lexically illegal in mermaid labels (models embed
15
+ * ```dsh-ui style fences, which break the parser with "Lexical error");
16
+ * - strip `<br/>` tags, which require htmlLabels (never enabled here);
17
+ * - quote unquoted node labels containing CJK, spaces, or other characters
18
+ * mermaid's bare-label grammar rejects (observed live: `A[模型生成 spec]`).
19
+ * Conservative by design: already-quoted labels, plain ASCII labels without
20
+ * spaces, and non-flowchart kinds are left untouched (apart from the
21
+ * backtick/`<br/>` sanitation above, which is harmless everywhere in a
22
+ * flowchart).
23
+ *
24
+ * Labeled-edge spans (`-- 文本 -->`, `== 文本 ==>`, `-. 文本 .->`) are free
25
+ * text and must never be quoted: wrapping them breaks the parser
26
+ * ("Expecting 'LINK' … got 'STR'"), observed live with
27
+ * `H -- 否(流式中) --> J`. Each span is swapped for a bracket-free
28
+ * placeholder before quoting and restored verbatim afterwards, so the quote
29
+ * pass can neither corrupt it nor be thrown off by inserted quotes
30
+ * elsewhere on the line.
31
+ *
32
+ * Pipe-style edge labels (`-->|文本|`) are the opposite: an UNQUOTED pipe
33
+ * label containing `[` or `]` breaks the parser ("Parse error", observed
34
+ * live with `-->|6. 用户交互 → [genui-action]|`) because the brackets are
35
+ * node grammar. Quoting the label text is display-neutral (mermaid renders
36
+ * `-->|"文本"|` without the quotes) and parses. These spans are masked too,
37
+ * so the node-label quote pass below cannot reach inside them and produce
38
+ * nested quotes, and restored last.
39
+ */
40
+ export declare function repairMermaidSource(code: string): string;
41
+ /**
42
+ * Lenient repair for sources that omit the mandatory diagram-type
43
+ * declaration line — the #1 failure mode of model-generated mermaid (chat
44
+ * assistants routinely emit `A --> B` without the leading `graph TD`).
45
+ *
46
+ * When the first token is not an already-declared `graph`/`flowchart` kind
47
+ * but the body contains flowchart edge arrows, prepend `graph TD` so the
48
+ * diagram renders instead of tripping the kind gate. Anything else — an
49
+ * explicitly declared kind, a sequence/gantt/pie body (no flowchart edges),
50
+ * or plain text — is returned unchanged: we never guess at the diagram type.
51
+ */
52
+ export declare function ensureFlowchartKind(code: string): string;
@@ -0,0 +1,34 @@
1
+ /**
2
+ * /panel slash command + the default panel spec.
3
+ *
4
+ * The session panel dock is an always-present seat, but it only becomes
5
+ * visible once a spec has been published — both existing publish paths
6
+ * (render_ui tool result, panel:true fence) are model-driven. The /panel
7
+ * command gives a deterministic, client-side entry point:
8
+ * - `/panel` — publishes the default spec and requests the dock to expand
9
+ * instantly, with zero model round-trip;
10
+ * - `/panel clear` (off/close) — empties the panel so the dock retracts;
11
+ * - `/panel <instruction>` — shows the default spec for immediate feedback,
12
+ * then relays the instruction to the model, which replaces the panel with
13
+ * content tailored to the request (panel:true fence).
14
+ * Panel updates afterwards still flow through the model (say "update the
15
+ * panel", or re-run render_ui) or through another /panel.
16
+ */
17
+ import type { InputTriggerSource } from '@deepseek-ai/dsh-client-ui-input-trigger/client';
18
+ import type { SessionId } from '@deepseek-ai/dsh-session/types';
19
+ import type { GenuiSpec } from './spec.ts';
20
+ /**
21
+ * Default panel content published by `/panel`: the component overview.
22
+ *
23
+ * Built PER CALL so the panel opens in whatever language is active now,
24
+ * rather than the one that happened to be active at module load.
25
+ */
26
+ export declare function defaultPanelSpec(): GenuiSpec;
27
+ /**
28
+ * The /panel source. Menu group `genui` under the '/' trigger; the panel
29
+ * candidate claims the line so both the menu pick and a bare `/panel` enter
30
+ * resolve to the same command. `matchEnter` is implemented so the command
31
+ * works without opening the menu (leading-token adjudication), and it also
32
+ * catches `/panel clear` style args.
33
+ */
34
+ export declare function createPanelSlashSource(sendInstruction: (sessionId: SessionId, instruction: string) => void): InputTriggerSource;
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Session GenUI panel store: folds stable per-source panel operations into
3
+ * one read-only snapshot per session. The toolview and the settled-fence
4
+ * publisher submit operations (`replace`/`append`) carrying a stable
5
+ * sourceId and a three-part order; the store deduplicates by source, sorts
6
+ * by order, applies a deterministic fold under a node/append budget, and
7
+ * notifies subscribers only when the folded snapshot actually changes.
8
+ *
9
+ * Ordering: no "last caller wins", no Infinity. Operations from DIFFERENT
10
+ * sources always both apply; replays of the same source are idempotent; a
11
+ * later replace resets everything earlier; an append beyond the budget is
12
+ * remembered as an overflow barrier so an out-of-order earlier replace can
13
+ * re-fold deterministically. A local `/panel` override (default panel or
14
+ * clear) is the fold base and blocks every replay at/below the highest
15
+ * message seq seen so far — old history can never resurrect the panel.
16
+ *
17
+ * Scale limits live in `PANEL_LIMITS` (adjustable defaults, not law — see
18
+ * docs/plans/2026-08-12-dsh-genui-design-optimization.md). Budget
19
+ * rejections are DETERMINISTIC (no LRU eviction: eviction would make the
20
+ * fold depend on arrival order).
21
+ *
22
+ */
23
+ import type { GenuiSpec } from './spec.ts';
24
+ /** Panel scale limits — adjustable defaults (design doc: scale limits are
25
+ * configurable, not law). Folds read the CURRENT limits, so tuning applies
26
+ * from the next operation on. */
27
+ export declare const PANEL_LIMITS: {
28
+ /** Max nodes in the folded panel snapshot. */
29
+ readonly maxNodes: 200;
30
+ /** Max append operations kept after the latest replace. */
31
+ readonly maxAppends: 200;
32
+ };
33
+ type PanelLimits = {
34
+ maxNodes: number;
35
+ maxAppends: number;
36
+ };
37
+ /** Override the panel limits (operator tuning / tests). Applied at the next fold. */
38
+ export declare function setPanelLimits(next: Partial<PanelLimits>): void;
39
+ /** Three-part stable order: [messageSeq, textBlockIndex, fenceIndex]. */
40
+ export type PanelOrder = readonly [number, number, number];
41
+ /** One persistent panel operation from a settled source. */
42
+ export interface PanelOperation {
43
+ /** Stable source identity (fence source id or `['render_ui', callId]`). */
44
+ sourceId: string;
45
+ order: PanelOrder;
46
+ mode: 'replace' | 'append';
47
+ spec: GenuiSpec;
48
+ }
49
+ export type PanelOperationStatus = 'accepted' | 'idempotent' | 'blocked' | 'overflow';
50
+ /**
51
+ * Submit one panel operation. Idempotent per sourceId; ordering and budget
52
+ * per the module doc. Returns the outcome so callers can diagnose once per
53
+ * source (e.g. "panel at its node/appends budget — send a replace").
54
+ */
55
+ export declare function applyPanelOperation(sessionId: string, op: PanelOperation): PanelOperationStatus;
56
+ /**
57
+ * Apply the local `/panel` override: `spec` (the default panel) or null
58
+ * (clear) becomes the fold base, and every operation at/below the highest
59
+ * message seq seen so far is dead — old history replays cannot resurrect
60
+ * the panel. A later real operation (order[0] > barrier) replaces or merges
61
+ * into the override as usual.
62
+ */
63
+ export declare function setLocalPanel(sessionId: string, spec: GenuiSpec | null): void;
64
+ /** Log one budget-overflow diagnostic per source (replays stay silent). */
65
+ export declare function diagnosePanelBudget(sessionId: string, sourceId: string): void;
66
+ /** Tear down a session's panel state (session destroy / hard clear). Memory
67
+ * only: drops the in-memory record, the session's expand token, and overflow
68
+ * diagnostics, so a long-lived app never accumulates per-session state for
69
+ * closed sessions. The localStorage entry SURVIVES — reopening the session
70
+ * restores the panel instantly (that is the persistence feature); an explicit
71
+ * user clear goes through setLocalPanel(null), which persists the cleared
72
+ * state + barrier. */
73
+ export declare function clearSessionPanel(sessionId: string): void;
74
+ /** Current folded spec for a session (useSyncExternalStore getSnapshot).
75
+ * Lazily hydrates from localStorage on first access after a reload. */
76
+ export declare function getPanelSpec(sessionId: string): GenuiSpec | null;
77
+ /** Subscribe to panel changes. Returns the disposer. */
78
+ export declare function subscribePanel(listener: () => void): () => void;
79
+ /**
80
+ * Merge an `append` spec into the current panel spec:
81
+ * - both sides single-tabs containers → merge BY TAB LABEL: items of
82
+ * same-labelled tabs are appended, new labels are added (order preserved);
83
+ * - otherwise → plain item lists are appended to the tail.
84
+ * The previous title wins unless it was absent. `next` is returned as-is when
85
+ * there is nothing to merge into. Export for tests.
86
+ */
87
+ export declare function mergePanelSpecs(prev: GenuiSpec | null, next: GenuiSpec): GenuiSpec;
88
+ /** Request the panel dock to expand for a session (e.g. the /panel command). */
89
+ export declare function requestPanelExpand(sessionId: string): void;
90
+ /** Current expand token for a session (useSyncExternalStore getSnapshot). */
91
+ export declare function getPanelExpandToken(sessionId: string): number;
92
+ /** Subscribe to expand requests. Returns the disposer. */
93
+ export declare function subscribePanelExpand(listener: () => void): () => void;
94
+ export {};
@@ -0,0 +1,18 @@
1
+ import { type GenuiActionHandler } from './action-context.ts';
2
+ import type { PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots';
3
+ /** Injection face built per session in apply (scoped conversation send). */
4
+ export interface GenuiPanelInjected {
5
+ sessionId: string;
6
+ sendGenuiAction: GenuiActionHandler;
7
+ /** Template center "try it": insert the template instruction into the
8
+ * current composer draft (standard conversation.input.for channel). */
9
+ insertTemplate: (text: string) => void;
10
+ }
11
+ export type GenuiPanelProps = PropsRuntime<'conversation.input.dock'> & GenuiPanelInjected;
12
+ /**
13
+ * Panel dock entry. Renders nothing until the session's toolview published a
14
+ * spec; afterwards the SAME block re-renders on every publish. Collapsed by
15
+ * default so the dock never steals the message flow's scroll room; the
16
+ * header always shows the current panel title.
17
+ */
18
+ export declare function GenuiPanel({ sessionId, sendGenuiAction, insertTemplate }: GenuiPanelProps): import("react").JSX.Element | null;
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Partial GenUI spec parsing: extract the components that are already
3
+ * complete from a still-growing ```dsh-ui fence body, so the UI can render
4
+ * top-down as the model writes — each finished component appears the moment
5
+ * its JSON object closes, instead of the whole block waiting for the fence.
6
+ *
7
+ * Strategy (tolerant, white-list-agnostic, BOUNDED):
8
+ * 1. Full parse first (the common settled case) — at most one.
9
+ * 2. ONE left-to-right scan collects the repair candidates: every position
10
+ * where the prefix is bracket-balanced (trailing comma / fence tail) and
11
+ * every top-level `items[]` component close (an unfinished trailing
12
+ * component is dropped by closing the root array/object). Partial candidates
13
+ * must parse as a spec root; bare components wait for their own root close.
14
+ * The ring buffer keeps only the longest-direction candidates (≤ MAX_PARTIAL_REPAIR_ATTEMPTS),
15
+ * so the work is O(n) with a hard parse-attempt cap — a pathological
16
+ * input can never re-scan prefixes or burn seconds in JSON.parse.
17
+ * 3. Candidates are tried longest first; the first that parses as a GenUI
18
+ * spec wins. Nothing parses → null (streaming partial, wait for more).
19
+ *
20
+ * The result is only ever a PREFIX of the intended spec, so it is always
21
+ * safe to render: components already present are complete and valid.
22
+ *
23
+ * `ponytail:` the 32-candidate / 33-parse budget is the protection ceiling;
24
+ * only real streaming samples proving a recovery shortfall justify switching
25
+ * to a tokenizing parser.
26
+ */
27
+ import { type GenuiSpec } from './spec.ts';
28
+ /** Default repair-candidate budget (adjustable; see the design doc). */
29
+ export declare const MAX_PARTIAL_REPAIR_ATTEMPTS = 32;
30
+ /** Override the repair-candidate budget (tests / tuning). */
31
+ export declare function setMaxPartialRepairAttempts(n: number): void;
32
+ /** One repair candidate: a balanced prefix of the body ending at `end`,
33
+ * plus the closing brackets to append (empty when already balanced). */
34
+ export interface PartialCandidate {
35
+ end: number;
36
+ closingSuffix: string;
37
+ }
38
+ /** Single left-to-right pass over the raw body. Tracks the bracket stack
39
+ * (skipping strings/escapes correctly) and records:
40
+ * - every position where the prefix is fully balanced (trailing comma or
41
+ * fence tail) — candidate with an empty closing suffix;
42
+ * - every top-level `items[]` component close — candidate with the root
43
+ * array/object closed (an unfinished trailing component is dropped). Nested
44
+ * object closes are not candidates because their component is still partial.
45
+ * Candidates are ring-buffered to the attempts budget (the LAST pushes are
46
+ * the longest), then returned longest-first, deduplicated by end. The scan
47
+ * stops at the first unbalanced close — earlier balanced prefixes remain
48
+ * valid candidates.
49
+ *
50
+ * Exposed for tests (the `scannedChars` diagnostic); not exported from the
51
+ * package entry. The parser calls this exactly once per parse.
52
+ */
53
+ export declare function collectPartialCandidates(raw: string): {
54
+ candidates: PartialCandidate[];
55
+ scannedChars: number;
56
+ };
57
+ /**
58
+ * Parse a possibly incomplete genui spec body.
59
+ * @param raw - the fence body as accumulated so far.
60
+ * @returns a spec containing only finished components, or null when nothing
61
+ * usable has been written yet.
62
+ */
63
+ export declare function parsePartialGenuiSpec(raw: string): GenuiSpec | null;
@@ -0,0 +1,4 @@
1
+ export { CodeBlock, DiffBlock, JsonTree, writeClipboard } from '@deepseek-ai/dsh-client-ui-primitives';
2
+ export type { DiffBlockLabels, JsonTreeLabels } from '@deepseek-ai/dsh-client-ui-primitives';
3
+ export declare const getGenuiComponent: ((type: string) => unknown) | undefined;
4
+ export declare const GenuiActionContext: unknown;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Localized labels required by the DSH UI primitives.
3
+ *
4
+ * The primitives take their chrome as plain label objects, so these are built
5
+ * PER RENDER from the active locale (`labelsOf*()`) rather than frozen at
6
+ * module load — a language switch must reach a diff or JSON tree that is
7
+ * already on screen.
8
+ */
9
+ import type { DiffBlockLabels, JsonTreeLabels } from './primitive-adapter.ts';
10
+ /** Chrome labels for an inline GenUI diff block, in the active locale. */
11
+ export declare function diffBlockLabels(): DiffBlockLabels;
12
+ /** Copy labels for a code block rendered inside a GenUI fence or node. */
13
+ export declare function codeBlockLabels(): {
14
+ copyLabel: string;
15
+ copiedLabel: string;
16
+ };
17
+ /** Chrome labels for an inline GenUI JSON tree, in the active locale. */
18
+ export declare function jsonTreeLabels(): JsonTreeLabels;
@@ -0,0 +1,43 @@
1
+ /**
2
+ * SafeMath: a restricted math expression evaluator for GenUI plot specs.
3
+ *
4
+ * The model supplies an expression string like "sin(x) * 2 + 1". It is parsed
5
+ * and evaluated here WITHOUT eval / new Function: a hand-written recursive
6
+ * descent parser over a white-listed function/constant vocabulary. Unknown
7
+ * identifiers, object property access, and call syntax other than the
8
+ * white-listed functions are parse errors, so an adversarial expression
9
+ * cannot reach globals, prototypes, or side effects.
10
+ *
11
+ * Supported grammar:
12
+ * expr := term (('+' | '-') term)*
13
+ * term := unary (('*' | '/' | '%') unary)*
14
+ * unary := ('-' | '+') unary | power
15
+ * power := atom ('^' atom)?
16
+ * atom := number | variable | constant | func '(' expr ')' | '(' expr ')'
17
+ * variable: 'x' (and any single-letter variable present in vars)
18
+ * constant: 'pi' | 'e' | 'tau'
19
+ * func : sin cos tan asin acos atan sqrt cbrt exp log ln abs floor ceil round min max pow
20
+ */
21
+ export interface SafeMathOptions {
22
+ /** Variable values; only names present here may be referenced as variables. */
23
+ vars?: Record<string, number>;
24
+ }
25
+ /**
26
+ * Compile an expression into an evaluable function.
27
+ * @param expr - the math expression. `x` is the sampling variable; any other
28
+ * name in `vars` is a parameter whose captured value the evaluator returns
29
+ * (recompile with new vars to change a parameter — expressions are short).
30
+ * @param options - parameter values; `x` is reserved and ignored here.
31
+ * @returns evaluator, or null when the expression is invalid.
32
+ */
33
+ export declare function compileMathExpr(expr: string, options?: SafeMathOptions): ((x: number) => number) | null;
34
+ /**
35
+ * Sample an expression over a range.
36
+ * @param expr - math expression in x, with optional parameters.
37
+ * @param xMin - inclusive start.
38
+ * @param xMax - inclusive end.
39
+ * @param samples - number of samples (>= 2).
40
+ * @param params - parameter values (e.g. { a: 2, b: 3 }); recompile per change.
41
+ * @returns [x, y] pairs; non-finite samples are dropped.
42
+ */
43
+ export declare function sampleExpr(expr: string, xMin: number, xMax: number, samples?: number, params?: Record<string, number>): Array<[number, number]>;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * three.js scene renderer — the HEAVY half. This module imports three and is
3
+ * bundled ONLY into the lazy asset bundle `lib/assets/three.js`, loaded on
4
+ * demand by the scene3d-lazy loader when a spec contains a `scene3d` node;
5
+ * the main client bundle stays small.
6
+ *
7
+ * Security: the model only supplies white-listed primitive shapes, numeric
8
+ * transforms, and colors. No textures, no external URLs, no scripts, no
9
+ * custom shaders — everything is geometry + material colors constructed
10
+ * locally. The renderer mounts into a caller-owned container and returns a
11
+ * disposer that tears down the WebGL context.
12
+ * @module @changfenhuang/dsh-genui/client/scene3d-core
13
+ */
14
+ import type { GenuiScene3D } from './spec.ts';
15
+ /**
16
+ * Mount a GenUI 3D scene into `container`.
17
+ * @param container - the DOM node to host the WebGL canvas.
18
+ * @param scene - the declarative scene spec.
19
+ * @returns a disposer that removes the renderer and its context.
20
+ */
21
+ export declare function mountScene(container: HTMLElement, scene: GenuiScene3D): Promise<() => void>;
@@ -0,0 +1,8 @@
1
+ import type { GenuiScene3D } from './spec.ts';
2
+ /**
3
+ * Mount a GenUI 3D scene into `container` (engine loaded on demand).
4
+ * @param container - the DOM node to host the WebGL canvas.
5
+ * @param scene - the declarative scene spec.
6
+ * @returns a disposer that removes the renderer and its context.
7
+ */
8
+ export declare function mountScene(container: HTMLElement, scene: GenuiScene3D): Promise<() => void>;
@@ -0,0 +1,8 @@
1
+ import type { SessionId } from '@deepseek-ai/dsh-session/types';
2
+ /**
3
+ * 从宿主会话列表快照中解析当前主视图会话。
4
+ *
5
+ * @param list - 宿主提供的会话列表快照
6
+ * @returns 当前会话标识;无法识别快照结构时返回 undefined
7
+ */
8
+ export declare function resolveViewedSessionId(list: unknown): SessionId | undefined;
@@ -0,0 +1,29 @@
1
+ import type { AssistantBlock, ChatSnapshot } from '@deepseek-ai/dsh-client-ui-chat/client';
2
+ export interface SourceFence {
3
+ lang: string | null;
4
+ value: string;
5
+ openingLineComplete: boolean;
6
+ }
7
+ /**
8
+ * 按 Markdown 文档顺序读取所有代码围栏。
9
+ *
10
+ * @param markdown - assistant text block 中的 Markdown 内容
11
+ * @returns Markdown AST 中的代码围栏
12
+ */
13
+ export declare function sourceFencesOf(markdown: string): SourceFence[];
14
+ /**
15
+ * 只从 assistant 的 text blocks 中读取代码围栏。
16
+ *
17
+ * @param blocks - ChatSnapshot 提供的 assistant 内容块
18
+ * @returns 按内容块顺序排列的代码围栏
19
+ */
20
+ export declare function sourceFencesOfAssistant(blocks: readonly AssistantBlock[]): SourceFence[];
21
+ /**
22
+ * 根据 assistant node key 和围栏序号读取公开 ChatSnapshot 中的 language。
23
+ *
24
+ * @param chat - 当前会话的 ChatSnapshot
25
+ * @param nodeKey - DOM assistant row 对应的 Chat node key
26
+ * @param index - assistant row 内从零开始的宿主代码块序号
27
+ * @returns 原始 language;null 表示围栏没有 language,undefined 表示 source 不可用
28
+ */
29
+ export declare function sourceLanguageAt(chat: ChatSnapshot | undefined, nodeKey: string, index: number): string | null | undefined;