@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,2 @@
1
+ /** 从启动代码预先载入的全局资源读取引擎。 */
2
+ export declare function loadGenuiAsset<T>(name: 'mermaid' | 'three' | 'echarts-core' | 'echarts-full'): Promise<T>;
@@ -0,0 +1,9 @@
1
+ import type { GenuiArtifactV1 } from '../artifact/types.ts';
2
+ declare global {
3
+ interface Window {
4
+ __GenuiStandalone__?: {
5
+ mount(root: HTMLElement, artifact: GenuiArtifactV1): () => void;
6
+ };
7
+ }
8
+ }
9
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,54 @@
1
+ import { type ReactNode } from 'react';
2
+ export interface DiffBlockLabels {
3
+ copy: string;
4
+ copied: string;
5
+ codeLabel: string;
6
+ wrapLabel: string;
7
+ unwrapLabel: string;
8
+ collapseAria: string;
9
+ expandAria: (hidden: number) => string;
10
+ collapse: string;
11
+ expand: (hidden: number) => string;
12
+ files: (count: number) => string;
13
+ }
14
+ export interface JsonTreeLabels {
15
+ copyValue: string;
16
+ copyJson: string;
17
+ copyPath: string;
18
+ copyPrettyJson: string;
19
+ copyCompactJson: string;
20
+ copied: string;
21
+ copyFailed: string;
22
+ collapseNode: string;
23
+ expandNode: string;
24
+ copyButtonTitle: (action: string) => string;
25
+ }
26
+ /** 在独立页面显示可复制的代码内容。 */
27
+ export declare function CodeBlock({ code, lang, copyLabel, copiedLabel }: {
28
+ code: string;
29
+ lang?: string;
30
+ copyLabel?: string;
31
+ copiedLabel?: string;
32
+ }): ReactNode;
33
+ /** 在独立页面以差异文本显示文件变更。 */
34
+ export declare function DiffBlock({ diffs }: {
35
+ diffs: Array<{
36
+ path: string;
37
+ oldText?: string;
38
+ newText?: string;
39
+ }>;
40
+ labels?: DiffBlockLabels;
41
+ }): ReactNode;
42
+ /** 在独立页面显示 JSON,并提供本地折叠控制。 */
43
+ export declare function JsonTree({ data, label, copyable, labels }: {
44
+ data: object | unknown[];
45
+ label?: string;
46
+ copyable?: boolean;
47
+ labels?: JsonTreeLabels;
48
+ }): ReactNode;
49
+ /** 将文本复制到系统剪贴板。 */
50
+ export declare function writeClipboard(text: string): Promise<boolean>;
51
+ /** standalone 模式不连接 DSH 注册表,因此自定义组件始终不可用。 */
52
+ export declare function getGenuiComponent(_type: string): undefined;
53
+ /** standalone 模式专用的空动作上下文。 */
54
+ export declare const GenuiActionContext: import("react").Context<((action: string, payload: Record<string, unknown>) => void) | undefined>;
@@ -0,0 +1,2 @@
1
+ import './katex-style.ts';
2
+ import './bootstrap-types.ts';
@@ -0,0 +1,51 @@
1
+ import type { GenuiSpec } from './spec.ts';
2
+ export type SubmissionMember = RadioSubmissionMember | CheckboxSubmissionMember | FieldSubmissionMember;
3
+ export interface RadioSubmissionMember {
4
+ kind: 'radio';
5
+ key: string;
6
+ label: string;
7
+ options: string[];
8
+ answer?: number | string;
9
+ explanation?: string;
10
+ }
11
+ export interface CheckboxSubmissionMember {
12
+ kind: 'checkbox';
13
+ key: string;
14
+ }
15
+ export interface FieldSubmissionMember {
16
+ kind: 'field';
17
+ key: string;
18
+ fieldType: 'input' | 'textarea' | 'select' | 'slider';
19
+ secret: boolean;
20
+ }
21
+ export interface SubmissionRegistry {
22
+ members: ReadonlyMap<string, SubmissionMember>;
23
+ }
24
+ export interface SubmitInteractionState {
25
+ answers: Record<string, string>;
26
+ multiAnswers: Record<string, string[]>;
27
+ fields: Record<string, string>;
28
+ secretFields: ReadonlySet<string>;
29
+ }
30
+ export interface ResolvedSubmitState {
31
+ scope: SubmissionMember[];
32
+ answered: number;
33
+ total: number;
34
+ localGradeEligible: boolean;
35
+ hasOutOfScopePayload: boolean;
36
+ }
37
+ /** 从 spec 建立成员表,并诊断 submission key 和 submit.groups。 */
38
+ export declare function analyzeSubmissionRegistry(spec: GenuiSpec): {
39
+ registry: SubmissionRegistry;
40
+ diagnostics: string[];
41
+ };
42
+ /** 编译供运行时读取的静态 submission 成员表。 */
43
+ export declare function compileSubmissionRegistry(spec: GenuiSpec): SubmissionRegistry;
44
+ /** 根据当前交互状态判断一个 submission member 是否完成。 */
45
+ export declare function isSubmissionMemberAnswered(member: SubmissionMember, state: SubmitInteractionState): boolean;
46
+ /** 计算 submit 进度和纯本地判卷条件。 */
47
+ export declare function resolveSubmitState({ registry, groups, state }: {
48
+ registry: SubmissionRegistry;
49
+ groups?: string[];
50
+ state: SubmitInteractionState;
51
+ }): ResolvedSubmitState;
@@ -0,0 +1,2 @@
1
+ import { type Key } from 'react';
2
+ export declare function renderSvgFence(raw: string, key: Key): import("react").JSX.Element;
@@ -0,0 +1,20 @@
1
+ /** 保存 repair 所需的原始 table 字段。 */
2
+ export interface TableDetailSource {
3
+ columns?: unknown;
4
+ rows?: unknown;
5
+ data?: unknown;
6
+ types?: unknown;
7
+ }
8
+ /** 保存 repair 后的 table 列和行。 */
9
+ export interface PreparedTableRows {
10
+ columns: string[];
11
+ rows: Array<Array<string | number>>;
12
+ }
13
+ /** 使用 table repair 相同的转换规则处理列和行。 */
14
+ export declare function prepareTableRows(table: TableDetailSource): PreparedTableRows | null;
15
+ /** 返回 repair 后可显示详情的 table 行。 */
16
+ export declare function tableRowsForDetails<Row = unknown>(table: TableDetailSource): Row[];
17
+ /** 按照 table renderer 的规则识别分组标题行。 */
18
+ export declare function isTableGroupHeaderRow(row: unknown, types: unknown): boolean;
19
+ /** 判断详情索引对应的行是否可展开并显示。 */
20
+ export declare function isTableDetailReachable(table: TableDetailSource, rowIndex: number): boolean;
@@ -0,0 +1,41 @@
1
+ /**
2
+ * templates.ts — template center data.
3
+ *
4
+ * Each template = a natural-language `instruction` (inserted into the
5
+ * composer on "try it", so the model generates the matching interface via the
6
+ * genui skill) + a VALID `demo` spec (rendered directly by GenuiBlock in the
7
+ * preview, so the user sees the result before deciding). Fields track the
8
+ * real schema in spec.ts / guard.ts (tests/templates.spec.ts validates each
9
+ * one with validateGenuiSpec).
10
+ *
11
+ * Templates double as documentation: they cover layout, data, charts,
12
+ * interaction, quizzes and the advanced families.
13
+ *
14
+ * All display text resolves through the i18n dictionaries, so the list is
15
+ * built PER CALL from the active locale rather than frozen at module load.
16
+ */
17
+ import type { GenuiSpec } from './spec.ts';
18
+ /** Stable, locale-independent category ids. */
19
+ export declare const TEMPLATE_CATEGORIES: readonly ["dashboard", "data", "flow", "chart", "interactive", "quiz", "advanced"];
20
+ export type TemplateCategory = (typeof TEMPLATE_CATEGORIES)[number];
21
+ /** Dictionary key carrying a category's display name. */
22
+ export declare function categoryLabelKey(category: TemplateCategory | 'all'): string;
23
+ export interface GenuiTemplate {
24
+ id: string;
25
+ /** Stable id; the display name comes from {@link categoryLabelKey}. */
26
+ category: TemplateCategory;
27
+ name: string;
28
+ description: string;
29
+ /** Natural-language instruction inserted into the composer on "try it". */
30
+ instruction: string;
31
+ /** Valid preview spec (≤200 nodes, ≤8 levels deep). */
32
+ demo: GenuiSpec;
33
+ }
34
+ /**
35
+ * Build the template list in the ACTIVE locale.
36
+ *
37
+ * A function rather than a constant: the user can switch language at runtime,
38
+ * and a module-level array would pin whatever locale happened to be active
39
+ * when the bundle first loaded.
40
+ */
41
+ export declare function genuiTemplates(): readonly GenuiTemplate[];
@@ -0,0 +1,7 @@
1
+ import type { ToolCallViewProps } from '@deepseek-ai/dsh-client-ui-tool/client';
2
+ /**
3
+ * Keyed toolview for the `render_ui` tool. `block` is the settled result
4
+ * node once the call completes; while it runs (or on replay without meta)
5
+ * the summary fallback is shown.
6
+ */
7
+ export declare function GenuiToolView({ toolName, block, sessionId }: ToolCallViewProps): import("react").JSX.Element;
@@ -0,0 +1,3 @@
1
+ import type { GenuiNode, GenuiSpec } from './spec.ts';
2
+ /** 遍历完整 GenUI 组件树,并提供每个组件在 spec 中的路径。 */
3
+ export declare function walkGenuiNodes(spec: GenuiSpec, visitor: (node: GenuiNode, path: string) => void): void;
@@ -0,0 +1 @@
1
+ export * from './plugin/index';
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Validate chart nodes using the guard's shared native renderability contract.
3
+ * The plugin-facing API remains stable while the guard remains the single
4
+ * owner of chart field and renderer-semantic rules.
5
+ *
6
+ * @param value - Raw GenUI spec or bare chart node.
7
+ * @returns Chart errors in deterministic tree order.
8
+ */
9
+ export declare function validateRenderableChartSemantics(value: unknown): string[];
@@ -0,0 +1,151 @@
1
+ /**
2
+ * Fence feedback loop (issue #160): a reply whose ```dsh-ui fence the guard
3
+ * cannot render should not stay broken for the reader. The host's
4
+ * `agent/turn-stopping` boundary lets a plugin steer input into the SAME turn —
5
+ * the machine re-reads its inbox and runs another step instead of closing
6
+ * (see the `dsh-agent` runtime contract) — so the model can resend a corrected
7
+ * fence while the user is still looking at the raw JSON.
8
+ *
9
+ * The loop is deliberately narrow, matching the contract agreed on the issue:
10
+ * - **默认开启。** 插件配置中的 `fenceFeedback: false` 可以关闭回合转向。
11
+ * - **修正上限。** 每个 turn 最多发送两条 correction;render failure 和 delivery reminder 共用上限,
12
+ * 每个 fence body 在当前回合中最多修正一次,新回合可重新修正。
13
+ * - **仅含 reasoning 的恢复。** 已验证的 GenUI 回合若只以 reasoning block 结束,使用宿主的
14
+ * `EMPTY_RESPONSE` retry policy。
15
+ * - **Never for subagents.** A child session's fence belongs to a parent reply.
16
+ * - **Exact fence matching.** Only an info string of exactly `dsh-ui` opens a
17
+ * fence, so ` ```dsh-ui-dark `, indented prose, or a mention of the name is
18
+ * never rewritten.
19
+ * - **Accounted before sending.** The fingerprint is recorded before `steer`,
20
+ * so a re-entrant boundary cannot deliver the same correction twice.
21
+ * - **Cancellation-aware.** An aborted turn or a missing session is left alone.
22
+ *
23
+ * 检查会复用 renderer 在回合结束后的流程,包括 JSON 修复和坏节点清理;
24
+ * 已经可以渲染的最终回复不会收到修正请求。
25
+ * @module @changfenhuang/dsh-genui/plugin/fence-feedback
26
+ */
27
+ import type { Context } from '@deepseek-ai/cordis';
28
+ import type { UserMessage } from '@deepseek-ai/dsh-session';
29
+ /** Plugin name recorded on every message this loop steers. */
30
+ export declare const FEEDBACK_PLUGIN_NAME = "@changfenhuang/dsh-genui";
31
+ /** Source kind persisted by this plugin in Session format v4. */
32
+ export declare const FEEDBACK_SOURCE_KIND: "plugin:@changfenhuang/dsh-genui";
33
+ /**
34
+ * 同一个 turn 内 fence-feedback correction 的共享上限。
35
+ * Render failure 和 nothing-delivered reminder 共用该 budget;各自的 ledger 独立阻止重复修正。
36
+ */
37
+ export declare const MAX_CORRECTIONS_PER_TURN = 2;
38
+ /** One ```dsh-ui fence found in an assistant reply. */
39
+ export interface ExtractedFence {
40
+ /** Raw body between the fences (no delimiters). */
41
+ readonly raw: string;
42
+ /** False when the reply ended before the closing fence. */
43
+ readonly closed: boolean;
44
+ /** 1-based position among this reply's fences. */
45
+ readonly index: number;
46
+ }
47
+ /**
48
+ * Extract every ```dsh-ui fence from one assistant reply.
49
+ *
50
+ * @param text - the assistant message text.
51
+ * @returns the fences in document order (at most {@link MAX_FENCES}).
52
+ */
53
+ export declare function extractDshUiFences(text: string): ExtractedFence[];
54
+ /** Stable, log-safe identity of one fence body (same body → same fingerprint). */
55
+ export declare function fenceFingerprint(raw: string): string;
56
+ /** One fence the guard refuses to render, with its model-facing reason. */
57
+ export interface FenceFailure {
58
+ readonly index: number;
59
+ readonly fingerprint: string;
60
+ /** Actionable diagnosis, in the same wording the validator tool uses. */
61
+ readonly detail: string;
62
+ }
63
+ /**
64
+ * Validate every fence in a reply the way the DOM channel would render it.
65
+ *
66
+ * @param text - the assistant message text.
67
+ * @returns the fences that would stay a raw code block, in document order.
68
+ */
69
+ export declare function fenceFailures(text: string): FenceFailure[];
70
+ /**
71
+ * Build the correction input for a reply with unrenderable fences.
72
+ *
73
+ * @param failures - fences {@link fenceFailures} rejected.
74
+ * @returns the message text to steer into the running turn.
75
+ */
76
+ export declare function fenceCorrectionText(failures: readonly FenceFailure[]): string;
77
+ /**
78
+ * Create the identified user-role message this loop steers.
79
+ *
80
+ * Mirrors `createUserMessage` from `@deepseek-ai/dsh-llm` (id + role + frozen)
81
+ * without a runtime dependency on that package: the node half of this plugin
82
+ * deliberately imports no `@deepseek-ai/*` values, so a linked or npm-installed
83
+ * copy resolves identically on every host.
84
+ *
85
+ * @param text - the correction text.
86
+ * @param sessionFormatVersion - the format recorded by the active session.
87
+ * @returns a frozen user message attributed to this plugin as a notice.
88
+ */
89
+ export declare function createFeedbackMessage(text: string, sessionFormatVersion: number): UserMessage;
90
+ /** What the pure planner needs to decide whether a correction may be sent. */
91
+ export interface FenceFeedbackPlanInput {
92
+ /** Latest assistant reply text of the current turn. */
93
+ readonly text: string;
94
+ readonly turn: number;
95
+ /** Fence bodies already corrected for a render failure in the current turn. */
96
+ readonly correctedSpec: ReadonlySet<string>;
97
+ /** Turns already given the delivery reminder. */
98
+ readonly deliveryRemindedTurns?: ReadonlySet<number> | undefined;
99
+ /** A `validate_dsh_ui` call happened this turn (formal GenUI signal). */
100
+ readonly validatedThisTurn?: boolean | undefined;
101
+ /** The turn already delivered a body or a successful `render_ui` result. */
102
+ readonly deliveredThisTurn?: boolean | undefined;
103
+ readonly aborted: boolean;
104
+ /** Corrections already steered in this turn (shared hard cap). */
105
+ readonly correctionsThisTurn?: number | undefined;
106
+ /** Turn {@link correctionsThisTurn} counts (stale counts are ignored). */
107
+ readonly correctionsTurn?: number | undefined;
108
+ }
109
+ /** A correction the caller must account for before steering. */
110
+ export interface FenceFeedbackPlan {
111
+ readonly text: string;
112
+ readonly fingerprints: readonly string[];
113
+ readonly turn: number;
114
+ /**
115
+ * `render` corrects a fence that failed to resolve; `delivery` reminds the
116
+ * model that the turn produced nothing formal. They share the per-turn budget
117
+ * but keep separate ledgers.
118
+ */
119
+ readonly kind: 'render' | 'delivery';
120
+ }
121
+ /**
122
+ * Decide whether this turn boundary should steer a correction — the pure core of
123
+ * the loop, so every bound (per-turn cap, per-fence ledger, cancellation) is
124
+ * testable without a host.
125
+ *
126
+ * The decision is driven by FORMAL events only: fences in the reply body, a
127
+ * `validate_dsh_ui` call, a delivered body text or a successful `render_ui`
128
+ * result. The reasoning block is
129
+ * never read here — a draft inside the thinking block is not proof that the model
130
+ * chose to deliver it, so it must not change any decision.
131
+ *
132
+ * @param input - reply text, turn identity, formal signals, and the accounting.
133
+ * @returns the correction to send, or null when the loop must stay silent.
134
+ */
135
+ export declare function planFenceFeedback(input: FenceFeedbackPlanInput): FenceFeedbackPlan | null;
136
+ /**
137
+ * Correction for a validated GenUI turn that reached the boundary without any
138
+ * formal delivery.
139
+ *
140
+ * @param turn - turn that reached the boundary.
141
+ * @param attempt - correction number within the shared turn budget.
142
+ * @returns the message text to steer into the running turn.
143
+ */
144
+ export declare function missingBodyCorrectionText(turn: number, attempt?: number): string;
145
+ /**
146
+ * 注册 GenUI 回合跟踪、宿主重试判定和可选的围栏修正流程。
147
+ *
148
+ * @param ctx - 宿主 Context。
149
+ * @param enabled - 是否启用同回合围栏修正。
150
+ */
151
+ export declare function installFenceFeedback(ctx: Context, enabled: boolean): void;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * GenUI 节点诊断共享逻辑。
3
+ * @module @changfenhuang/dsh-genui/plugin/genui-diagnostic
4
+ */
5
+ import type { GenuiProcessResult } from '../client/guard.ts';
6
+ /**
7
+ * 报告被丢弃的组件,并保留模型可以直接修正的字段信息。
8
+ *
9
+ * @param processed - 节点处理结果。
10
+ * @param raw - 节点处理使用的原始值。
11
+ * @returns 可嵌入调用方协议的诊断字段;没有节点被丢弃时返回 undefined。
12
+ */
13
+ export declare function droppedNodeFailure(processed: GenuiProcessResult, raw: unknown): string[] | undefined;
@@ -0,0 +1,35 @@
1
+ /**
2
+ * GenUI plugin: teaches the model the ```dsh-ui fence syntax for emitting
3
+ * declarative UI components inline in its reply. The browser half renders the
4
+ * fence through GenuiBlock (ui-primitives); this host half only tells the
5
+ * model the language exists, so a session without the plugin simply never
6
+ * emits fences and nothing changes.
7
+ *
8
+ * The section uses the host's centrally allocated structured-output placement.
9
+ * @module @changfenhuang/dsh-genui
10
+ */
11
+ import { Context } from '@deepseek-ai/cordis';
12
+ /** The fence language description injected into every assembled system prompt.
13
+ * Deliberately slim: the `genui` skill carries the full component→field
14
+ * mapping; this section keeps only the contract that must always be
15
+ * present (fence syntax, type whitelist, and critical behavioral rules). */
16
+ export declare const GENUI_SECTION_TEXT = "You can render interactive UI components INSIDE your reply \u2014 between paragraphs \u2014 by emitting a fenced block with the language tag `dsh-ui` containing a JSON spec:\n\n```dsh-ui\n{\"title\":\"<user-language text>\",\"gap\":14,\"items\":[...]}\n```\n\nAllowed `type` values; the `genui` skill, when available, carries the full content\u2192component mapping and per-component field details:\n\n- \u5E03\u5C40: text \u00B7 row \u00B7 col \u00B7 grid \u00B7 card \u00B7 divider \u00B7 spacer \u00B7 hero\uFF08\u5C01\u9762\u5757\uFF0C\u4E00\u6761\u56DE\u7B54\u6700\u591A\u4E00\u4E2A\uFF09\n- \u5C55\u793A: badge \u00B7 stat \u00B7 progress \u00B7 list \u00B7 table \u00B7 keyvalue \u00B7 timeline \u00B7 file-tree \u00B7 breadcrumb \u00B7 callout \u00B7 steps \u00B7 diff \u00B7 json \u00B7 code \u00B7 copy \u00B7 avatar \u00B7 audio \u00B7 video\n- \u56FE\u8868: chart {\"kind\":\"bars|line|donut\",\"data\":[{\"label\":\"...\",\"value\":n}],\"series\":[{\"label\":\"...\",\"data\":[...]}]?,\"horizontal\":true?,\"stacked\":true?}\uFF08series\uFF1Abars \u5206\u7EC4/\u5806\u53E0 / line \u591A\u5E8F\u5217\uFF1Bhorizontal \u6A2A\u5411\u67F1\uFF09 \u00B7 echart (preset \u540D\u6216 option \u76F4\u901A\uFF0C\u9884\u8BBE\u6E05\u5355\u89C1 skill) \u00B7 plot (\u51FD\u6570\u56FE)\n- \u4EA4\u4E92: button \u00B7 input \u00B7 textarea \u00B7 select \u00B7 checkbox \u00B7 switch \u00B7 slider \u00B7 radio \u00B7 submit \u00B7 quiz \u00B7 link \u00B7 tabs \u00B7 accordion\n- \u9AD8\u7EA7: mermaid (\u6D41\u7A0B\u56FE/\u65F6\u5E8F/\u7518\u7279/ER \u7B49\uFF0C\u5173\u952E\u5B57\u89C1 skill) \u00B7 diagram (\u67B6\u6784/\u6D41\u7A0B\u56FE\uFF0C27 \u79CD kind) \u00B7 scene3d (3D WebGL)\n\n**\u9ED8\u8BA4\u5C31\u8BE5\u51FA UI**\uFF1A\u51FA\u73B0\u4E0B\u5217\u60C5\u51B5\u81F3\u5C11\u51FA\u4E00\u4E2A\u56F4\u680F\uFF1A\n- \u22653 \u6761\u5E76\u5217\u8981\u70B9 \u2192 `list`\uFF1B\u6570\u5B57\u5BF9\u6BD4 \u2192 `table`\uFF1B\u6307\u6807/\u8FDB\u5EA6/\u72B6\u6001 \u2192 `stat`/`progress`/`badge`\n- \u6B65\u9AA4/\u65F6\u95F4\u7EBF \u2192 `steps`/`timeline`/`mermaid`\uFF1B\u67B6\u6784/\u6D41\u7A0B \u2192 `diagram` \u6216 `mermaid`\uFF1B\u98CE\u9669/\u7ED3\u8BBA \u2192 `callout`\uFF1B\u4EE3\u7801/\u6539\u52A8 \u2192 `code`/`diff`/`json`\n- \u884C\u5185\u5BCC\u6587\u672C\uFF1A\u652F\u6301\u516C\u5F0F\u3001`code`\u3001\u52A0\u7C97\u3001\u9AD8\u4EAE\u3001\u94FE\u63A5\uFF1B\u7981\u7528 Markdown table / fenced code\uFF0C\u6539\u7528 table / code / diff / json\u3002\n- \u9ED8\u8BA4\u65E0\u5361\uFF1A\u6309\u89E6\u53D1\u6761\u4EF6\u4F7F\u7528\u7EC4\u4EF6\uFF0C\u6BCF\u4E2A\u7EC4\u4EF6\u627F\u8F7D\u4E0D\u540C\u4FE1\u606F\uFF1B\u5361\u7247\u53EA\u7528\u4E8E\u5E76\u6392\u9879\u4E0E\u6570\u636E\u5BF9\u8C61\uFF0C\u5355\u6BB5\u6587\u5B57\u7528\u6807\u9898\u3001\u6B63\u6587\u4E0E\u95F4\u8DDD\u3002\n\n**\u53D1\u56DE\u7B54\u524D\u6700\u540E\u81EA\u68C0\u4E00\u6B21**\uFF1A\u8FD9\u6BB5\u5185\u5BB9\u91CC\u6709\u6CA1\u6709 \u22653 \u6761\u5E76\u5217\u8981\u70B9\u3001\u4EFB\u4F55\u5BF9\u6BD4\u3001\u4EFB\u4F55\u6570\u5B57/\u6307\u6807\u3001\u4EFB\u4F55\u6B65\u9AA4\u6216\u6D41\u7A0B\uFF1F\u6709\u5C31\u5148\u8F6C\u6210\u7EC4\u4EF6\u518D\u5F00\u53E3\u3002**\u72B6\u6001\u6C47\u62A5\u3001\u8FDB\u5EA6\u8BF4\u660E\u3001\u63D0\u4EA4\u4E0E\u6539\u52A8\u6E05\u5355\u540C\u6837\u7B97**\u3002\n- \u8D8B\u52BF/\u5360\u6BD4 \u2192 `chart`\uFF08\u22648 \u70B9\uFF09\u6216 `echart`\uFF08\u591A\u5E8F\u5217/\u8981\u4EA4\u4E92\u65F6\uFF09\uFF1B\u914D\u8272\u9ED8\u8BA4\u8DDF\u968F\u4E3B\u9898\uFF0C\u53EA\u6709\u8BED\u4E49\u9700\u8981\u65F6\u624D\u7528 `palette`/`card.accent`\uFF1Bgrid \u5B50\u8282\u70B9\u7528 `\"span\":2` \u8DE8\u5217\u505A\u5BBD\u7A84\u6DF7\u6392\uFF1B\u6570\u636E\u591A\u65F6\u7ED9 `table`/`chart`/`list` \u914D\u4E00\u4E2A `input`(id) + `filter` \u7ED1\u5B9A\uFF0C\u8BFB\u8005\u80FD\u5C31\u5730\u7B5B\u9009\u3002\n\n**\u5B57\u6BB5\u901F\u67E5**\uFF08\u5B8C\u6574\u89C1 genui skill\uFF09\uFF1A`stat` `{\"label\",\"value\",\"delta\"?}` \u00B7 `table` `{\"columns\":[...],\"rows\":[[...]],\"types\"?,\"details\"?,\"filter\"?,\"export\"?}` \u00B7 `progress` `{\"value\":0-100,\"label\"?,\"variant\"?,\"target\"?}` \u00B7 `keyvalue` `{\"pairs\":[{\"key\",\"value\"}]}` \u00B7 `steps` `{\"steps\":[{\"title\",\"desc\"?}]}` \u00B7 `file-tree` `{\"items\":[{\"name\",\"type\":\"file|dir\",\"children\"?}]}` \u00B7 `callout` `{\"content\",\"tone\"?,\"title\"?}`\n\n**\u5B57\u6BB5\u540D\u5199\u9519 = \u8BE5\u7EC4\u4EF6\u88AB\u4E22\u5F03**\uFF08\u5176\u4F59\u7EC4\u4EF6\u7167\u5E38\u6E32\u67D3\uFF09\uFF1A`callout` \u6B63\u6587\u662F `content` \u4E0D\u662F text/desc\uFF1B`table` \u8981 `columns`+`rows` \u4E0D\u662F items\uFF1B`keyvalue` \u8BB0\u5F55\u662F `{key,value}` \u4E0D\u662F `{label,value}`\uFF1B`file-tree` \u8BB0\u5F55\u662F `{name,type}` \u4E0D\u662F `{label}`\uFF1Bcallout tone \u662F info/success/warning/error\uFF08\u65E0 danger\uFF09\u3002\u4E0D\u786E\u5B9A\u5C31\u8C03 `validate_dsh_ui`\u3002\n\nRules:\n- LANGUAGE: reply+UI=conversation language; schema fixed. NEVER infer it from prompt/skill/examples/tools. Replace `<user-language ...>`; never emit these placeholders literally.\n- JSON \u4E25\u683C\uFF1A\u574F\u7EC4\u4EF6\u88AB\u4E22\u5F03\uFF0C\u574F\u56F4\u680F\u53D8\u4EE3\u7801\u5757\uFF1B\u22653 \u8282\u70B9\u6216\u542B table \u65F6\u8C03 validate_dsh_ui\uFF0C\u6309\u8BCA\u65AD\u4FEE\u6539\u5E76\u91CD\u9A8C\uFF1B\u5C0F\u56F4\u680F\u5B57\u6BB5\u5B58\u7591\u4E5F\u5148\u9A8C\u8BC1\u3002\n- warning=block_markdown\uFF1A\u6309 replacement \u6539\u5199\u5E76\u91CD\u9A8C\u3002\n- \u89C4\u6A21: \u2264200 \u8282\u70B9\u3001\u5D4C\u5957\u22648 \u5C42\uFF08\u8D85\u51FA\u88AB\u622A\u65AD\uFF09\uFF1B\u4E00\u6761\u56DE\u7B54 3\u20138 \u4E2A\u7EC4\u4EF6\uFF0C\u4E00\u4E2A\u4E3B\u9898\u4E00\u4E2A\u4E3B\u7EC4\u4EF6\uFF1B3D mesh 1\u20135\uFF1Bplot \u7ED9\u5408\u7406 xMin/xMax\u3002\n- LOCAL-FIRST + actions: UI \u80FD\u81EA\u5DF1\u505A\u7684\u72B6\u6001\u53D8\u5316\uFF08\u5224\u5377\u3001\u5224\u9898\u3001\u91CD\u7F6E\u3001\u5C55\u5F00\u3001\u9009\u4E2D\uFF09\u5C31\u5730\u5B8C\u6210\uFF0C\u96F6\u5F80\u8FD4\uFF1Baction \u53EA\u7528\u4E8E\u5FC5\u987B\u6A21\u578B\u53C2\u4E0E\u7684\u4E8B\u3002\u4EA4\u4E92\u4EE5 [genui-action] name + \u7EC4\u4EF6\u6570\u636E\u56DE\u4F20\uFF0C\u5C4A\u65F6\u91CD\u6E32\u67D3\u66F4\u65B0 UI\uFF1B\u65E0 action \u7684\u6309\u94AE\u7981\u7528\u3002\n- Durable state: \u4EA4\u4E92\u72B6\u6001\u6309\u300C\u4F1A\u8BDD+\u5185\u5BB9\u6307\u7EB9\u300D\u6301\u4E45\u5316\u2014\u2014\u5237\u65B0/\u91CD\u653E\u6062\u590D\uFF1B\u76F8\u540C\u5185\u5BB9\u4FDD\u7559\uFF0C\u65B0\u5185\u5BB9\u91CD\u7F6E\u3002\n- \u5377\u5B50\u6A21\u5F0F: \u6BCF\u9898\u4E00\u4E2A radio\uFF08group+answer+explanation\uFF09+ \u4E00\u4E2A submit\uFF08groups \u5168\u5217\uFF09\uFF0C\u672C\u5730\u5224\u5206\u3002\n- Secrets ban: \u4E0D\u7D22\u53D6\u5BC6\u7801\u3001API Key\u3001Token\u3001\u6062\u590D\u7801\uFF1B\u9700\u8981\u65F6\u62D2\u7EDD\u5E76\u89E3\u91CA\u3002\n- Tool channel: render_ui \u5DE5\u5177\u628A\u540C\u4E00 spec \u6E32\u67D3\u4E3A\u5DE5\u5177\u884C\u5361\u7247\uFF1B\u56F4\u680F\u7528\u4E8E\u56DE\u7B54\u5185\u8054 UI\u3002\n- \u56F4\u680F\u4F4D\u7F6E\uFF1A`dsh-ui` \u53EA\u5199\u5728**\u56DE\u7B54\u6B63\u6587**\uFF1B\u5199\u5728 reasoning/\u601D\u8003\u5757\u91CC\u4E0D\u6E32\u67D3\u3001\u7528\u6237\u770B\u4E0D\u5230\u2014\u2014\u601D\u8003\u91CC\u9A8C\u8BC1\u597D spec\uFF0C\u6B63\u6587\u518D\u8F93\u51FA\u540C\u4E00\u4EFD\u3002\n- Panel: \"panel\":true \u53EA\u6E32\u67D3\u8FDB\u4F1A\u8BDD\u9762\u677F dock \u5E76\u539F\u5730\u66F4\u65B0\uFF1B\"append\":true \u8FFD\u52A0\u5408\u5E76\uFF1B\u4E0A\u9650 200 \u8282\u70B9/200 \u6B21\u8FFD\u52A0\uFF0C\u6EE1\u4E86\u53D1 replace \u91CD\u5EFA\u3002\u9762\u677F\u6765\u7684 [genui-action] \u53EA\u56DE\u4E00\u4E2A panel:true \u56F4\u680F + \u81F3\u591A\u4E00\u884C 10 \u5B57\u5185\u786E\u8BA4\u3002";
17
+ /**
18
+ * Register the GenUI output-language section and the render_ui tool.
19
+ * @param ctx - cordis context.
20
+ */
21
+ export declare const name = "@changfenhuang/dsh-genui";
22
+ export declare const inject: string[];
23
+ /**
24
+ * Plugin config as the host passes it (unvalidated: the node half deliberately
25
+ * imports no schema library, so a profile can set these keys directly).
26
+ */
27
+ export interface GenuiPluginConfig {
28
+ /**
29
+ * 在最终 dsh-ui 围栏无法渲染的回合中请求模型发送一次修正版(issue #160)。
30
+ * 默认开启,设置为 false 可以关闭同回合围栏修正。GenUI 回合的 reasoning-only 响应仍会交给宿主重试策略处理。
31
+ * 每回合和每个围栏正文最多请求一次,子代理不触发,每次修正请求会消耗模型步数。
32
+ */
33
+ fenceFeedback?: boolean;
34
+ }
35
+ export declare function apply(ctx: Context, config?: GenuiPluginConfig): void;
@@ -0,0 +1,8 @@
1
+ import type { GenuiSpec } from '../client/spec.ts';
2
+ export interface InlineContentWarning {
3
+ path: string;
4
+ kind: 'fenced_code' | 'markdown_table';
5
+ replacement: 'code' | 'table';
6
+ }
7
+ /** 按组件结构检查需要块级内容诊断的 canonical 显示字段。 */
8
+ export declare function collectInlineContentWarnings(spec: GenuiSpec): InlineContentWarning[];
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Package-owned invariant companion for `@changfenhuang/dsh-genui`.
3
+ * @module @changfenhuang/dsh-genui/invariant
4
+ */
5
+ import type { Context } from '@deepseek-ai/cordis';
6
+ /** Cordis companion plugin name. */
7
+ export declare const name = "genui-invariant";
8
+ /** Service required before the companion can reserve package ownership. */
9
+ export declare const inject: string[];
10
+ /**
11
+ * Register this package's invariant companion.
12
+ * @param ctx - Cordis context carrying the invariant service.
13
+ * @returns the installed registration's disposer after setup succeeds.
14
+ */
15
+ export declare const apply: (ctx: Context) => Promise<() => void>;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * The `render_ui` tool: a model-facing channel that renders a GenUI spec as
3
+ * an interactive card in the conversation TOOL ROW (route A of the design
4
+ * doc). The ```dsh-ui fence channel renders inline in the reply; this tool
5
+ * renders in the tool row and rides the harness's result `meta` projection:
6
+ * `presentationMeta` stores the repaired spec, the browser toolview
7
+ * (`src/client/toolview.tsx`) reads it from the result node and renders.
8
+ *
9
+ * Zero runtime harness imports, deliberately: an external plugin's node half
10
+ * must not depend on the harness module graph at runtime (the profile
11
+ * resolves only the plugin package itself). The definition is therefore a
12
+ * plain `ToolDefinition` object — the exact shape `defineTool` returns — with
13
+ * the arguments schema authored as JSON Schema (the harness validates args
14
+ * and output with the same JSON Schema validator defineTool uses). Deep
15
+ * validation, deterministic repair, and resource limits live in the shared
16
+ * guard (`src/client/guard.ts`), which the schema deliberately stays loose
17
+ * enough to reach.
18
+ * @module @changfenhuang/dsh-genui/plugin/tool
19
+ */
20
+ import type { ToolDefinition } from '@deepseek-ai/dsh-tools';
21
+ /**
22
+ * Build the render_ui tool definition. Registered by the plugin node half;
23
+ * `ctx.tools.register` consumes it exactly like a `defineTool` result.
24
+ */
25
+ export declare function createRenderUiTool(): ToolDefinition;
26
+ /** Build the validate_dsh_ui tool definition (registered alongside render_ui). */
27
+ export declare function createValidateDshUiTool(): ToolDefinition;
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Shared fence-body JSON repair — pure string functions, no DOM, no I/O.
3
+ * Used by BOTH the client fence renderer (tier-1/tier-2 auto-repair before
4
+ * rendering) and the node-side validate_dsh_ui tool (which returns the
5
+ * repaired JSON to the model instead of making it re-author the fix).
6
+ *
7
+ * Two tiers, deliberately gated differently by the callers:
8
+ * - Tier-1 (`repairFenceJson`): heals the most common model JSON typos that
9
+ * do NOT change the body's structure — unescaped half-width quotes inside
10
+ * string values and trailing commas. Safe at any time (streaming included),
11
+ * adopted only when the WHOLE body parses afterwards.
12
+ * - Tier-2 (`completeFenceJson`): heals structural incompleteness — missing
13
+ * closing quotes/brackets — by appending the missing terminators, and
14
+ * skips mismatched closers (a `]` mistyped as `}`, duplicated terminators).
15
+ * SETTLED MESSAGES ONLY: a streaming half must never be adopted as a
16
+ * finished prefix.
17
+ * @module @changfenhuang/dsh-genui/shared/fence-repair
18
+ */
19
+ /** A fence body counts as complete when it parses as a whole JSON value. */
20
+ export declare function isCompleteJson(raw: string): boolean;
21
+ /** Short human-readable reason for a body that fails whole-JSON parsing, or
22
+ * null when it parses. Positions come from the host's JSON.parse error. */
23
+ export declare function describeJsonFailure(raw: string): string | null;
24
+ /**
25
+ * Tier-1 repair — SAFE AT ANY TIME (streaming included): heals the most
26
+ * common model JSON typos that do NOT change the body's structure, and only
27
+ * when the whole body parses afterwards (so a still-growing streaming half
28
+ * can never be adopted):
29
+ *
30
+ * 1. Unescaped half-width `"` inside a string value — Chinese text quoted
31
+ * with ASCII quotes (e.g. `对"别名路径"判定失败`), which makes JSON.parse
32
+ * fail near that quote with "Expected ',' or ']'...".
33
+ * 2. Trailing commas before `}` / `]` or at end of input.
34
+ *
35
+ * A shared grammar-aware scan distinguishes object keys from values and
36
+ * checks the continuation after a potential string terminator. Ambiguous
37
+ * value quotes use bounded backtracking; trailing commas are dropped only
38
+ * outside strings.
39
+ *
40
+ * Returns `{ text, repairs }` on success, or null when nothing needed fixing
41
+ * or the body still does not parse (callers fall through to tier-2 / banner).
42
+ */
43
+ export declare function repairFenceJson(raw: string): {
44
+ text: string;
45
+ repairs: number;
46
+ } | null;
47
+ /**
48
+ * 取**第一个平衡根值**的文本(丢弃其后的杂字符);没有平衡根时返回 null。
49
+ *
50
+ * 与 {@link completeFenceJson} 里的前缀回退同源,但**只做裁剪、不做结构补全**:
51
+ * 内容识别用它来容忍「合法 JSON + 尾部泄漏文本」(真实样本:模型把自己的工具调用
52
+ * 模板泄漏在 JSON 之后,且围栏没闭合)。根值正好结束在末尾时返回 null —— 那种情况
53
+ * `JSON.parse` 本来就会成功。
54
+ *
55
+ * @param text - 候选正文。
56
+ * @returns 平衡根前缀;无可裁剪内容时 null。
57
+ */
58
+ export declare function trimToBalancedRoot(text: string): string | null;
59
+ /**
60
+ * Tier-2 repair — SETTLED MESSAGES ONLY (never while streaming): heals
61
+ * structural incompleteness — missing closing quotes/brackets — by appending
62
+ * the missing terminators, and heals stray closers — a `]` mistyped as `}` or
63
+ * a duplicated terminator — by skipping closers that do not match the open
64
+ * stack (they cannot be legal JSON). Callers gate it on settled messages (the
65
+ * client uses the host-provided fence source; the validate tool is by
66
+ * definition pre-emission), so a streaming half can never flash premature UI.
67
+ *
68
+ * One shared scan implementation folds the tier-1 fixes (quote escaping +
69
+ * trailing-comma drops) into structural completion, so bodies with BOTH defects
70
+ * (a trailing comma AND a missing closer) heal in one shot — the old
71
+ * two-phase chain lost tier-1's partial work when its whole-body parse
72
+ * failed, and re-scanning the raw text could not compose the repairs.
73
+ * Adopted only when the completed body parses as whole JSON.
74
+ */
75
+ export declare function completeFenceJson(raw: string): {
76
+ text: string;
77
+ repairs: number;
78
+ } | null;
@@ -0,0 +1,39 @@
1
+ /**
2
+ * 使用浏览器 renderer 与 Node 侧最终回复反馈守卫共用的流程解析 dsh-ui 围栏正文。
3
+ * @module @changfenhuang/dsh-genui/shared/fence-resolve
4
+ */
5
+ import { type GenuiProcessResult } from '../client/guard.ts';
6
+ import type { GenuiSpec } from '../client/spec.ts';
7
+ /** 控制是否允许采用结构化 JSON 修复的选项。 */
8
+ export interface FenceResolveOptions {
9
+ /** 回合结束后的回复允许使用 tier-2 补全修复。 */
10
+ readonly settled: boolean;
11
+ }
12
+ /** 一次围栏候选正文经过规格守卫后的结果。 */
13
+ export interface FenceResolution {
14
+ /** 参与本次规格处理的解析值;没有可解析值时为 null。 */
15
+ readonly value: unknown | null;
16
+ /** 规格守卫输出的诊断;没有可解析值时为 null。 */
17
+ readonly processed: GenuiProcessResult | null;
18
+ /** 可渲染的 spec;无法渲染时为 null。 */
19
+ readonly spec: GenuiSpec | null;
20
+ }
21
+ /**
22
+ * 使用 renderer 的统一流程解析原始 dsh-ui 正文。
23
+ *
24
+ * 流式生成期间可以使用 tier-1 修复。tier-2 补全修复只允许用于回合结束后的回复,
25
+ * 防止未完成的正文提前渲染。
26
+ *
27
+ * @param raw - dsh-ui 围栏标记之间的原始正文。
28
+ * @param options - 流式或回合结束后的解析策略。
29
+ * @returns 通过规格守卫的渲染 spec;正文无法渲染时返回 null。
30
+ */
31
+ export declare function resolveFence(raw: string, options: FenceResolveOptions): FenceResolution;
32
+ /**
33
+ * 只返回统一围栏解析流程的可渲染 spec。
34
+ *
35
+ * @param raw - dsh-ui 围栏标记之间的原始正文。
36
+ * @param options - 流式或回合结束后的解析策略。
37
+ * @returns 通过规格守卫的渲染 spec;正文无法渲染时返回 null。
38
+ */
39
+ export declare function resolveFenceSpec(raw: string, options: FenceResolveOptions): GenuiSpec | null;