@sparkelf/dsh-genui 0.0.0-stage → 0.11.4-patch.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +597 -0
- package/LICENSE +21 -0
- package/README.md +292 -2
- package/README.zh-CN.md +307 -0
- package/SKILL.md +261 -0
- package/cordis.patch.yml +9 -0
- package/demo-prompts.md +118 -0
- package/lib/assets/echarts-core.js +43 -0
- package/lib/assets/echarts-full.js +72 -0
- package/lib/assets/mermaid.js +3591 -0
- package/lib/assets/standalone-runtime.js +1506 -0
- package/lib/assets/three.js +3844 -0
- package/lib/client.js +405 -0
- package/lib/index.js +5187 -0
- package/lib/invariant.js +19 -0
- package/lib/types/client/EChartNode.d.ts +13 -0
- package/lib/types/client/ErrorBoundary.d.ts +30 -0
- package/lib/types/client/GenuiBlock.d.ts +9 -0
- package/lib/types/client/PlotBlock.d.ts +44 -0
- package/lib/types/client/TemplateDrawer.d.ts +7 -0
- package/lib/types/client/achievement-store.d.ts +35 -0
- package/lib/types/client/achievement-toast.d.ts +2 -0
- package/lib/types/client/achievements.d.ts +63 -0
- package/lib/types/client/action-context.d.ts +7 -0
- package/lib/types/client/artifact/ExportableGenuiBlock.d.ts +6 -0
- package/lib/types/client/artifact/create.d.ts +5 -0
- package/lib/types/client/artifact/download.d.ts +9 -0
- package/lib/types/client/artifact/html.d.ts +5 -0
- package/lib/types/client/artifact/index.d.ts +8 -0
- package/lib/types/client/artifact/json.d.ts +3 -0
- package/lib/types/client/artifact/parse.d.ts +3 -0
- package/lib/types/client/artifact/portability.d.ts +4 -0
- package/lib/types/client/artifact/standalone-theme.d.ts +2 -0
- package/lib/types/client/artifact/types.d.ts +33 -0
- package/lib/types/client/asset-echarts-core.d.ts +1 -0
- package/lib/types/client/asset-echarts.d.ts +17 -0
- package/lib/types/client/asset-loader.d.ts +33 -0
- package/lib/types/client/asset-mermaid.d.ts +1 -0
- package/lib/types/client/asset-three.d.ts +1 -0
- package/lib/types/client/blocks/advanced.d.ts +101 -0
- package/lib/types/client/blocks/basic.d.ts +22 -0
- package/lib/types/client/blocks/charts.d.ts +53 -0
- package/lib/types/client/blocks/checkbox.d.ts +17 -0
- package/lib/types/client/blocks/diagram/geometry.d.ts +73 -0
- package/lib/types/client/blocks/diagram/index.d.ts +5 -0
- package/lib/types/client/blocks/diagram/layout.d.ts +41 -0
- package/lib/types/client/blocks/diagram/theme.d.ts +37 -0
- package/lib/types/client/blocks/forms.d.ts +77 -0
- package/lib/types/client/blocks/image.d.ts +6 -0
- package/lib/types/client/blocks/render-node.d.ts +10 -0
- package/lib/types/client/blocks/state.d.ts +63 -0
- package/lib/types/client/blocks/svg.d.ts +4 -0
- package/lib/types/client/dom-fence.d.ts +30 -0
- package/lib/types/client/echarts-engine.d.ts +4 -0
- package/lib/types/client/echarts-lazy.d.ts +18 -0
- package/lib/types/client/embed.d.ts +10 -0
- package/lib/types/client/fence-render.d.ts +106 -0
- package/lib/types/client/gallery.d.ts +7 -0
- package/lib/types/client/genui-runtime/diagnostics.d.ts +18 -0
- package/lib/types/client/genui-runtime/index.d.ts +1 -0
- package/lib/types/client/genui-runtime/limits.d.ts +54 -0
- package/lib/types/client/genui-runtime/normalize.d.ts +15 -0
- package/lib/types/client/genui-runtime/schema.d.ts +87 -0
- package/lib/types/client/genui-runtime/value-utils.d.ts +18 -0
- package/lib/types/client/guard.d.ts +144 -0
- package/lib/types/client/i18n/en.d.ts +307 -0
- package/lib/types/client/i18n/index.d.ts +44 -0
- package/lib/types/client/i18n/runtime.d.ts +64 -0
- package/lib/types/client/i18n/zh.d.ts +8 -0
- package/lib/types/client/index.d.ts +36 -0
- package/lib/types/client/inline.d.ts +5 -0
- package/lib/types/client/interaction-store.d.ts +48 -0
- package/lib/types/client/mermaid-core.d.ts +8 -0
- package/lib/types/client/mermaid-lazy.d.ts +9 -0
- package/lib/types/client/mermaid-safe.d.ts +52 -0
- package/lib/types/client/panel-command.d.ts +34 -0
- package/lib/types/client/panel-store.d.ts +94 -0
- package/lib/types/client/panel.d.ts +18 -0
- package/lib/types/client/parse-partial.d.ts +63 -0
- package/lib/types/client/primitive-adapter.d.ts +4 -0
- package/lib/types/client/primitive-labels.d.ts +18 -0
- package/lib/types/client/safe-math.d.ts +43 -0
- package/lib/types/client/scene3d-core.d.ts +21 -0
- package/lib/types/client/scene3d-lazy.d.ts +8 -0
- package/lib/types/client/session-resolver.d.ts +8 -0
- package/lib/types/client/source-fence.d.ts +29 -0
- package/lib/types/client/spec.d.ts +709 -0
- package/lib/types/client/standalone/asset-loader.d.ts +2 -0
- package/lib/types/client/standalone/bootstrap-types.d.ts +9 -0
- package/lib/types/client/standalone/katex-style.d.ts +1 -0
- package/lib/types/client/standalone/primitive-adapter.d.ts +54 -0
- package/lib/types/client/standalone/runtime.d.ts +2 -0
- package/lib/types/client/submission-registry.d.ts +51 -0
- package/lib/types/client/svg-fence.d.ts +2 -0
- package/lib/types/client/table-details.d.ts +20 -0
- package/lib/types/client/templates.d.ts +41 -0
- package/lib/types/client/toolview.d.ts +7 -0
- package/lib/types/client/walk-spec.d.ts +3 -0
- package/lib/types/index.d.ts +1 -0
- package/lib/types/plugin/chart-contract.d.ts +9 -0
- package/lib/types/plugin/fence-feedback.d.ts +151 -0
- package/lib/types/plugin/genui-diagnostic.d.ts +13 -0
- package/lib/types/plugin/index.d.ts +35 -0
- package/lib/types/plugin/inline-content-diagnostic.d.ts +8 -0
- package/lib/types/plugin/invariant.d.ts +15 -0
- package/lib/types/plugin/tool.d.ts +27 -0
- package/lib/types/shared/fence-repair.d.ts +78 -0
- package/lib/types/shared/fence-resolve.d.ts +39 -0
- package/package.json +249 -4
- package/src/client/EChartNode.tsx +466 -0
- package/src/client/ErrorBoundary.tsx +67 -0
- package/src/client/GenuiBlock.module.css +2221 -0
- package/src/client/GenuiBlock.tsx +235 -0
- package/src/client/PlotBlock.module.css +171 -0
- package/src/client/PlotBlock.tsx +492 -0
- package/src/client/TemplateDrawer.module.css +152 -0
- package/src/client/TemplateDrawer.tsx +147 -0
- package/src/client/achievement-store.ts +151 -0
- package/src/client/achievement-toast.tsx +71 -0
- package/src/client/achievements.ts +160 -0
- package/src/client/action-context.ts +32 -0
- package/src/client/artifact/ArtifactExport.module.css +64 -0
- package/src/client/artifact/ExportableGenuiBlock.tsx +100 -0
- package/src/client/artifact/create.ts +69 -0
- package/src/client/artifact/download.ts +42 -0
- package/src/client/artifact/html.ts +157 -0
- package/src/client/artifact/index.ts +15 -0
- package/src/client/artifact/json.ts +6 -0
- package/src/client/artifact/parse.ts +32 -0
- package/src/client/artifact/portability.ts +47 -0
- package/src/client/artifact/standalone-theme.ts +94 -0
- package/src/client/artifact/types.ts +44 -0
- package/src/client/asset-echarts-core.ts +39 -0
- package/src/client/asset-echarts.ts +27 -0
- package/src/client/asset-loader.ts +96 -0
- package/src/client/asset-mermaid.ts +13 -0
- package/src/client/asset-three.ts +12 -0
- package/src/client/blocks/advanced.tsx +537 -0
- package/src/client/blocks/basic.tsx +121 -0
- package/src/client/blocks/charts.tsx +999 -0
- package/src/client/blocks/checkbox.tsx +61 -0
- package/src/client/blocks/diagram/geometry.ts +151 -0
- package/src/client/blocks/diagram/index.tsx +293 -0
- package/src/client/blocks/diagram/layout.ts +202 -0
- package/src/client/blocks/diagram/theme.ts +127 -0
- package/src/client/blocks/forms.tsx +531 -0
- package/src/client/blocks/image.tsx +28 -0
- package/src/client/blocks/render-node.tsx +494 -0
- package/src/client/blocks/state.ts +65 -0
- package/src/client/blocks/svg.tsx +66 -0
- package/src/client/dom-fence.tsx +1123 -0
- package/src/client/echarts-engine.ts +9 -0
- package/src/client/echarts-lazy.ts +41 -0
- package/src/client/embed.ts +19 -0
- package/src/client/fence-render.tsx +266 -0
- package/src/client/gallery.ts +215 -0
- package/src/client/genui-runtime/diagnostics.ts +165 -0
- package/src/client/genui-runtime/index.ts +1 -0
- package/src/client/genui-runtime/limits.ts +54 -0
- package/src/client/genui-runtime/normalize.ts +329 -0
- package/src/client/genui-runtime/schema.ts +352 -0
- package/src/client/genui-runtime/value-utils.ts +67 -0
- package/src/client/guard.ts +1965 -0
- package/src/client/i18n/en.ts +335 -0
- package/src/client/i18n/index.ts +125 -0
- package/src/client/i18n/runtime.ts +130 -0
- package/src/client/i18n/zh.ts +330 -0
- package/src/client/index.tsx +228 -0
- package/src/client/inline.ts +106 -0
- package/src/client/interaction-store.ts +127 -0
- package/src/client/mermaid-core.ts +158 -0
- package/src/client/mermaid-lazy.ts +31 -0
- package/src/client/mermaid-safe.ts +122 -0
- package/src/client/panel-command.ts +138 -0
- package/src/client/panel-store.ts +471 -0
- package/src/client/panel.tsx +287 -0
- package/src/client/parse-partial.ts +170 -0
- package/src/client/primitive-adapter.ts +13 -0
- package/src/client/primitive-labels.ts +55 -0
- package/src/client/safe-math.ts +298 -0
- package/src/client/scene3d-core.ts +195 -0
- package/src/client/scene3d-lazy.ts +26 -0
- package/src/client/session-resolver.ts +33 -0
- package/src/client/source-fence.ts +70 -0
- package/src/client/spec.ts +896 -0
- package/src/client/standalone/asset-loader.ts +9 -0
- package/src/client/standalone/bootstrap-types.ts +11 -0
- package/src/client/standalone/katex-style.ts +1 -0
- package/src/client/standalone/primitive-adapter.tsx +94 -0
- package/src/client/standalone/runtime.tsx +27 -0
- package/src/client/submission-registry.ts +150 -0
- package/src/client/svg-fence.tsx +39 -0
- package/src/client/table-details.ts +151 -0
- package/src/client/templates.ts +322 -0
- package/src/client/toolview.tsx +67 -0
- package/src/client/walk-spec.ts +43 -0
- package/src/css-modules.d.ts +5 -0
- package/src/index.ts +9 -0
- package/src/plugin/chart-contract.ts +13 -0
- package/src/plugin/fence-feedback.ts +655 -0
- package/src/plugin/genui-diagnostic.ts +112 -0
- package/src/plugin/index.ts +224 -0
- package/src/plugin/inline-content-diagnostic.ts +178 -0
- package/src/plugin/invariant.ts +30 -0
- package/src/plugin/node-shims.d.ts +31 -0
- package/src/plugin/tool.ts +424 -0
- package/src/shared/fence-repair.ts +536 -0
- package/src/shared/fence-resolve.ts +80 -0
- package/tsconfig.json +35 -0
- package/tsdown.config.ts +275 -0
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 中文词典 — 与 en.ts 的键集完全一致(类型强制:缺键/多键都是编译错误)。
|
|
3
|
+
*
|
|
4
|
+
* 这些文案原本硬编码在组件里;此处保留原有措辞,仅把它们搬进词典,
|
|
5
|
+
* 因此中文用户看到的界面与 0.11.0 之前逐字相同。
|
|
6
|
+
*/
|
|
7
|
+
import type { EN } from './en.ts'
|
|
8
|
+
|
|
9
|
+
export const ZH: Record<keyof typeof EN, string> = {
|
|
10
|
+
// --------------------------------------------------------- 成果文件
|
|
11
|
+
'artifact.export': '导出',
|
|
12
|
+
'artifact.exportHtml': 'HTML',
|
|
13
|
+
'artifact.exportJson': 'GenUI JSON',
|
|
14
|
+
'artifact.exportFailed': '导出失败,请重试。',
|
|
15
|
+
'artifact.unsupportedCustom': '无法导出 HTML:独立运行环境无法显示自定义组件 {types}。可导出 GenUI JSON 保存这些节点。',
|
|
16
|
+
'artifact.externalMediaNotice': '此页面含有外部媒体,离线打开时部分内容可能无法显示。',
|
|
17
|
+
|
|
18
|
+
// ---------------------------------------------------------------- panel
|
|
19
|
+
'panel.badge': '面板',
|
|
20
|
+
'panel.title.default': 'GenUI 面板',
|
|
21
|
+
'panel.title.explore': 'GenUI 探索',
|
|
22
|
+
'panel.templates': '模板',
|
|
23
|
+
'panel.templates.aria': '模板中心',
|
|
24
|
+
'panel.templates.title': '模板中心:预览并试用 GenUI 示例',
|
|
25
|
+
'panel.achievements': '成就',
|
|
26
|
+
'panel.achievements.aria': '探索成就',
|
|
27
|
+
'panel.achievements.title': '探索成就:解锁徽章与进度',
|
|
28
|
+
'panel.close.aria': '关闭面板',
|
|
29
|
+
'panel.resize.aria': '调整面板高度',
|
|
30
|
+
'panel.hint': '💡 这是 GenUI 会话面板:点右上角「模板」可浏览并试用示例',
|
|
31
|
+
'panel.boundary': '面板',
|
|
32
|
+
'panel.flash.inserted': '指令已插入输入框,发送即可让模型生成',
|
|
33
|
+
|
|
34
|
+
// -------------------------------------------------------- panel command
|
|
35
|
+
'panel.cmd.hint': '开启 GenUI 面板;/panel <指令> 让模型定制;/panel clear 清空',
|
|
36
|
+
'panel.cmd.description': '开启 GenUI 面板(/panel clear 清空;/panel <指令> 定制内容)',
|
|
37
|
+
'panel.default.heading': 'GenUI 生成式界面',
|
|
38
|
+
'panel.default.subtitle': '面板会原地更新:对话里说「更新面板」,或再次执行 /panel 刷新。',
|
|
39
|
+
'panel.default.stat.components': '组件',
|
|
40
|
+
'panel.default.stat.single': '单个',
|
|
41
|
+
'panel.default.stat.composite': '组合',
|
|
42
|
+
'panel.default.stat.advanced': '高级',
|
|
43
|
+
'panel.default.group.single': '单个 ×12',
|
|
44
|
+
'panel.default.group.composite': '组合 ×8',
|
|
45
|
+
'panel.default.group.data': '数据 ×7',
|
|
46
|
+
'panel.default.group.interactive': '交互 ×5',
|
|
47
|
+
'panel.default.group.advanced': '高级 ×5',
|
|
48
|
+
'panel.default.group.teaching': '教学 ×1',
|
|
49
|
+
'panel.default.callout.title': '更新方式',
|
|
50
|
+
'panel.default.callout.body': '对话说「更新面板」→ 模型输出 panel:true 围栏;/panel clear 清空面板。',
|
|
51
|
+
|
|
52
|
+
// ------------------------------------------------------ template center
|
|
53
|
+
'tpl.category.all': '全部',
|
|
54
|
+
'tpl.category.dashboard': '仪表盘',
|
|
55
|
+
'tpl.category.data': '数据',
|
|
56
|
+
'tpl.category.flow': '流程',
|
|
57
|
+
'tpl.category.chart': '图表',
|
|
58
|
+
'tpl.category.interactive': '交互',
|
|
59
|
+
'tpl.category.quiz': '测验',
|
|
60
|
+
'tpl.category.advanced': '高级',
|
|
61
|
+
'tpl.categories.aria': '模板分类',
|
|
62
|
+
'tpl.try': '试用:插入输入框',
|
|
63
|
+
'tpl.copy': '复制指令',
|
|
64
|
+
'tpl.copied': '✓ 已复制',
|
|
65
|
+
'tpl.boundary.preview': '模板预览',
|
|
66
|
+
'tpl.boundary.achievements': '成就页',
|
|
67
|
+
|
|
68
|
+
'tpl.dashboard.name': '项目仪表盘',
|
|
69
|
+
'tpl.dashboard.desc': '一张卡片汇总核心指标:数字 + 环比 + 进度条,决策一眼可见。',
|
|
70
|
+
'tpl.dashboard.instruction': '请用 dsh-ui 给当前项目做一个仪表盘:4 个关键指标的 stat 卡片(带环比 delta)、整体进度 progress 条、今天的 3 件待办 list。标题用「项目仪表盘」。',
|
|
71
|
+
'tpl.dashboard.demo.title': '项目仪表盘(示例)',
|
|
72
|
+
'tpl.dashboard.demo.metrics': '本周关键指标',
|
|
73
|
+
'tpl.dashboard.demo.done': '本周完成',
|
|
74
|
+
'tpl.dashboard.demo.blocked': '阻塞事项',
|
|
75
|
+
'tpl.dashboard.demo.duration': '平均耗时',
|
|
76
|
+
'tpl.dashboard.demo.coverage': '覆盖率',
|
|
77
|
+
'tpl.dashboard.demo.progress': '整体进度',
|
|
78
|
+
'tpl.dashboard.demo.milestone': 'v1.0 里程碑',
|
|
79
|
+
'tpl.dashboard.demo.todo': '今日待办',
|
|
80
|
+
'tpl.dashboard.demo.todo1': '评审 M1 模板中心 PR',
|
|
81
|
+
'tpl.dashboard.demo.todo2': '同步 vendor 到 SSiD',
|
|
82
|
+
'tpl.dashboard.demo.todo3': '周三周会材料',
|
|
83
|
+
|
|
84
|
+
'tpl.compare.name': '方案对比表',
|
|
85
|
+
'tpl.compare.desc': '多方案逐维度对照,表格直接可读,争议点一目了然。',
|
|
86
|
+
'tpl.compare.instruction': '请用 dsh-ui 把以下方案的对比做成一张 table:方案 A/B/C × 维度(成本/复杂度/风险/收益),列首高亮推荐项;顶部加一行 callout 说明结论。',
|
|
87
|
+
'tpl.compare.demo.title': '方案对比(示例)',
|
|
88
|
+
'tpl.compare.demo.conclusion': '结论',
|
|
89
|
+
'tpl.compare.demo.body': '方案 B 综合最优:成本中、复杂度低、风险低。',
|
|
90
|
+
'tpl.compare.demo.dimension': '维度',
|
|
91
|
+
'tpl.compare.demo.optionA': '方案 A',
|
|
92
|
+
'tpl.compare.demo.optionB': '方案 B ★',
|
|
93
|
+
'tpl.compare.demo.optionC': '方案 C',
|
|
94
|
+
'tpl.compare.demo.cost': '成本',
|
|
95
|
+
'tpl.compare.demo.complexity': '复杂度',
|
|
96
|
+
'tpl.compare.demo.risk': '风险',
|
|
97
|
+
'tpl.compare.demo.payoff': '收益',
|
|
98
|
+
'tpl.compare.demo.high': '高',
|
|
99
|
+
'tpl.compare.demo.medium': '中',
|
|
100
|
+
'tpl.compare.demo.low': '低',
|
|
101
|
+
'tpl.compare.demo.large': '大',
|
|
102
|
+
'tpl.compare.demo.small': '小',
|
|
103
|
+
|
|
104
|
+
'tpl.steps.name': '五步上手流程',
|
|
105
|
+
'tpl.steps.desc': '关键步骤排成时间线,每步一句要点,适合教程/交接/发布流程。',
|
|
106
|
+
'tpl.steps.instruction': '请用 dsh-ui 把操作步骤做成 steps 教程:5 步(按实际流程),每步标题 + 一两句要点,顶部用 badge 标出预计耗时。',
|
|
107
|
+
'tpl.steps.demo.title': '上手流程(示例)',
|
|
108
|
+
'tpl.steps.demo.badge': '约 5 分钟',
|
|
109
|
+
'tpl.steps.demo.s1': '安装插件',
|
|
110
|
+
'tpl.steps.demo.s1desc': '从插件中心安装,或 npm 安装到 profile',
|
|
111
|
+
'tpl.steps.demo.s2': '发送第一条指令',
|
|
112
|
+
'tpl.steps.demo.s2desc': '让模型用 dsh-ui 输出一个界面',
|
|
113
|
+
'tpl.steps.demo.s3': '体验交互',
|
|
114
|
+
'tpl.steps.demo.s3desc': '点按钮/判卷/切 tab,动作会回传模型',
|
|
115
|
+
'tpl.steps.demo.s4': '常驻面板',
|
|
116
|
+
'tpl.steps.demo.s4desc': '模型用 panel:true 把结果钉在会话面板',
|
|
117
|
+
'tpl.steps.demo.s5': '进阶组件',
|
|
118
|
+
'tpl.steps.demo.s5desc': '图表/流程/3D 按需懒加载',
|
|
119
|
+
|
|
120
|
+
'tpl.quiz.name': '随堂测验',
|
|
121
|
+
'tpl.quiz.desc': '一题一答即时判卷:选中即知对错,附讲解,适合培训问答。',
|
|
122
|
+
'tpl.quiz.instruction': '请用 dsh-ui 出 3 道随堂测验(quiz 组件:question + options,其中一项 correct,附 explanation),标题「随堂测验」,每题即选即评。',
|
|
123
|
+
'tpl.quiz.demo.title': '随堂测验(示例)',
|
|
124
|
+
'tpl.quiz.demo.hint': '选中即判卷并显示讲解。',
|
|
125
|
+
'tpl.quiz.demo.q1': 'DSH 插件的最小单位是?',
|
|
126
|
+
'tpl.quiz.demo.q1a': '服务',
|
|
127
|
+
'tpl.quiz.demo.q1b': '插件(cordis 插件)',
|
|
128
|
+
'tpl.quiz.demo.q1bfx': '✓ 一切皆插件:服务、工具、UI 都通过插件注册。',
|
|
129
|
+
'tpl.quiz.demo.q1c': '工具',
|
|
130
|
+
'tpl.quiz.demo.q1exp': 'DSH 基于 cordis,任何能力(含服务与工具)都以插件形式注册。',
|
|
131
|
+
'tpl.quiz.demo.q2': 'dsh-ui 围栏由谁输出?',
|
|
132
|
+
'tpl.quiz.demo.q2a': '用户',
|
|
133
|
+
'tpl.quiz.demo.q2b': '模型',
|
|
134
|
+
'tpl.quiz.demo.q2bfx': '✓ 模型在回复中输出 dsh-ui fence。',
|
|
135
|
+
'tpl.quiz.demo.q2c': '宿主',
|
|
136
|
+
'tpl.quiz.demo.q2exp': '模型输出 fence,渲染器将其画成真实组件。',
|
|
137
|
+
'tpl.quiz.demo.q3': 'panel:true 的围栏渲染到哪里?',
|
|
138
|
+
'tpl.quiz.demo.q3a': '消息流',
|
|
139
|
+
'tpl.quiz.demo.q3b': '会话面板 dock',
|
|
140
|
+
'tpl.quiz.demo.q3bfx': '✓ 面板更新不刷屏。',
|
|
141
|
+
'tpl.quiz.demo.q3c': '设置页',
|
|
142
|
+
|
|
143
|
+
'tpl.stats.name': '关键值 + 进度',
|
|
144
|
+
'tpl.stats.desc': '一次交付:数值、进度、里程碑三件套,周报/复盘通用。',
|
|
145
|
+
'tpl.stats.instruction': '请用 dsh-ui 总结本周关键数据:keyvalue 列 3 组关键值、两根 progress 进度(计划 vs 实际)、timeline 放 3 个里程碑,标题「周报速览」。',
|
|
146
|
+
'tpl.stats.demo.title': '周报速览(示例)',
|
|
147
|
+
'tpl.stats.demo.done': '完成项',
|
|
148
|
+
'tpl.stats.demo.late': '延期',
|
|
149
|
+
'tpl.stats.demo.risk': '风险',
|
|
150
|
+
'tpl.stats.demo.riskValue': '2(均已有缓解)',
|
|
151
|
+
'tpl.stats.demo.planned': '计划进度',
|
|
152
|
+
'tpl.stats.demo.actual': '实际进度',
|
|
153
|
+
'tpl.stats.demo.mon': '周一',
|
|
154
|
+
'tpl.stats.demo.monDesc': '完成 M1 开发',
|
|
155
|
+
'tpl.stats.demo.wed': '周三',
|
|
156
|
+
'tpl.stats.demo.wedDesc': '全链路验证通过',
|
|
157
|
+
'tpl.stats.demo.fri': '周五',
|
|
158
|
+
'tpl.stats.demo.friDesc': '发布 0.9.4',
|
|
159
|
+
|
|
160
|
+
'tpl.chart.name': '趋势柱状图',
|
|
161
|
+
'tpl.chart.desc': '数据直接画成柱状图,多序列对比,走势一眼看清。',
|
|
162
|
+
'tpl.chart.instruction': '请用 dsh-ui 把下列数据画成 chart(bars,多序列):近 6 周完成量 vs 计划量;图表上方给一句趋势结论。',
|
|
163
|
+
'tpl.chart.demo.title': '趋势对比(示例)',
|
|
164
|
+
'tpl.chart.demo.conclusion': '结论:近 3 周完成量连续上升,本周首次反超计划。',
|
|
165
|
+
|
|
166
|
+
'tpl.tabs.name': '分标签页',
|
|
167
|
+
'tpl.tabs.desc': '一大块内容拆成标签页,锚点清晰;面板不挤、消息不刷屏。',
|
|
168
|
+
'tpl.tabs.instruction': '请用 dsh-ui 把内容分成 tabs 三个标签:概览/明细/FAQ,每个标签 3 条以内要点;标题「功能速览」。',
|
|
169
|
+
'tpl.tabs.demo.title': '功能速览(示例)',
|
|
170
|
+
'tpl.tabs.demo.overview': '概览',
|
|
171
|
+
'tpl.tabs.demo.overviewBody': '三项能力:实时渲染、交互回传、常驻面板。',
|
|
172
|
+
'tpl.tabs.demo.details': '明细',
|
|
173
|
+
'tpl.tabs.demo.d1': '渲染:fence 增量解析,边流边出',
|
|
174
|
+
'tpl.tabs.demo.d2': '交互:动作回传模型增量更新',
|
|
175
|
+
'tpl.tabs.demo.d3': '面板:会话级 dock,折叠/调高',
|
|
176
|
+
'tpl.tabs.demo.faqBody': '问:不动模型会怎样?答:组件仍可本地判卷/展开。',
|
|
177
|
+
|
|
178
|
+
'tpl.checklist.name': '交付检查清单',
|
|
179
|
+
'tpl.checklist.desc': '提交前逐项打勾:清单即流程,漏项看得见。',
|
|
180
|
+
'tpl.checklist.instruction': '请用 dsh-ui 做一张交付检查清单:6 项(测试/文档/发布/回滚/监控/公告),checkbox 可勾选,顶部 badge 提示「全部勾选再合并」。',
|
|
181
|
+
'tpl.checklist.demo.title': '交付清单(示例)',
|
|
182
|
+
'tpl.checklist.demo.badge': '全部勾选再合并',
|
|
183
|
+
'tpl.checklist.demo.c1': '单元测试通过',
|
|
184
|
+
'tpl.checklist.demo.c2': '文档同步',
|
|
185
|
+
'tpl.checklist.demo.c3': '发布套餐就绪',
|
|
186
|
+
'tpl.checklist.demo.c4': '回滚预案',
|
|
187
|
+
|
|
188
|
+
'tpl.accordion.name': 'FAQ 手风琴',
|
|
189
|
+
'tpl.accordion.desc': '一问一答收在折叠面板里,长文档变短,回答不吓人。',
|
|
190
|
+
'tpl.accordion.instruction': '请用 dsh-ui 做 FAQ 手风琴(accordion):5 个高频问题,标题栏就是问题、展开一条给答案;第一问默认展开。',
|
|
191
|
+
'tpl.accordion.demo.title': 'FAQ(示例)',
|
|
192
|
+
'tpl.accordion.demo.q1': '支持哪些图表?',
|
|
193
|
+
'tpl.accordion.demo.a1': 'chart(bars/line/donut)、plot 函数图、echart 全功能图表。',
|
|
194
|
+
'tpl.accordion.demo.q2': '面板能持久吗?',
|
|
195
|
+
'tpl.accordion.demo.a2': '同一内容指纹刷新/重放恢复状态;新内容重置。',
|
|
196
|
+
'tpl.accordion.demo.q3': '交互会打扰模型吗?',
|
|
197
|
+
'tpl.accordion.demo.a3': '带 action 的组件才回传;纯展示组件零往返。',
|
|
198
|
+
|
|
199
|
+
'tpl.diagram.name': '系统架构图',
|
|
200
|
+
'tpl.diagram.desc': '框架图画成 SVG:节点分层、连接线、分区标注,比截图清楚。',
|
|
201
|
+
'tpl.diagram.instruction': '请用 dsh-ui 画一幅架构图(diagram):描述当前系统的 5 个节点与连接(kind: architecture 或 flowchart),包含一个安全区 zone。',
|
|
202
|
+
'tpl.diagram.demo.title': '架构图(示例)',
|
|
203
|
+
'tpl.diagram.demo.caption': 'DSH 插件链路',
|
|
204
|
+
'tpl.diagram.demo.model': '模型',
|
|
205
|
+
'tpl.diagram.demo.plugin': '插件',
|
|
206
|
+
'tpl.diagram.demo.host': '宿主',
|
|
207
|
+
|
|
208
|
+
'tpl.3d.name': '3D 场景',
|
|
209
|
+
'tpl.3d.desc': '一个可旋转的 3D 场景:产品演示/空间示意用得上。',
|
|
210
|
+
'tpl.3d.instruction': '请用 dsh-ui 渲染一个 3D 场景(scene3d):一个立方体 + 一个球体,标题「示例场景」,附一句使用场景说明。',
|
|
211
|
+
'tpl.3d.demo.title': '3D 场景(示例)',
|
|
212
|
+
'tpl.3d.demo.note': '首次加载需下载 three.js(约 700KB,懒加载),之后走缓存。',
|
|
213
|
+
'tpl.3d.demo.scene': '示例场景',
|
|
214
|
+
|
|
215
|
+
'tpl.breadcrumb.name': '路径面包屑',
|
|
216
|
+
'tpl.breadcrumb.desc': '长路径拆成面包屑:文件位置、组织层级一读就懂。',
|
|
217
|
+
'tpl.breadcrumb.instruction': '请用 dsh-ui 展示当前工作区结构:breadcrumb 显示文件路径(4 段)、file-tree 描述项目目录(3 个目录、每个 2 个子项)。',
|
|
218
|
+
'tpl.breadcrumb.demo.title': '目录结构(示例)',
|
|
219
|
+
'tpl.breadcrumb.demo.workspace': '工作区',
|
|
220
|
+
|
|
221
|
+
// ------------------------------------------------------- achievements
|
|
222
|
+
'ach.page.title': 'GenUI 探索成就',
|
|
223
|
+
'ach.stat.unlocked': '已解锁',
|
|
224
|
+
'ach.stat.rendered': '渲染界面',
|
|
225
|
+
'ach.stat.interactions': '组件交互',
|
|
226
|
+
'ach.progress': '探索进度',
|
|
227
|
+
'ach.rarity.common': '普通',
|
|
228
|
+
'ach.rarity.rare': '稀有',
|
|
229
|
+
'ach.rarity.legendary': '传说',
|
|
230
|
+
'ach.hidden.name': '?',
|
|
231
|
+
'ach.hidden.desc': '继续探索以揭示',
|
|
232
|
+
'ach.toast.unlocked': '成就解锁:{name}',
|
|
233
|
+
|
|
234
|
+
'ach.first-fence.name': '初次相见',
|
|
235
|
+
'ach.first-fence.desc': '渲染了第一块 GenUI 界面。',
|
|
236
|
+
'ach.fence-5.name': '渐入佳境',
|
|
237
|
+
'ach.fence-5.desc': '累计渲染 5 个界面。',
|
|
238
|
+
'ach.fence-25.name': '界面编织者',
|
|
239
|
+
'ach.fence-25.desc': '累计渲染 25 个界面。',
|
|
240
|
+
'ach.fence-50.name': '蓝图之魂',
|
|
241
|
+
'ach.fence-50.desc': '累计渲染 50 个界面——你是 GenUI 的老朋友了。',
|
|
242
|
+
'ach.first-interaction.name': '按钮按得动',
|
|
243
|
+
'ach.first-interaction.desc': '触发了一次组件交互(动作回传)。',
|
|
244
|
+
'ach.interaction-10.name': '小小操纵者',
|
|
245
|
+
'ach.interaction-10.desc': '累计触发 10 次组件交互。',
|
|
246
|
+
'ach.first-panel.name': '钉在墙上',
|
|
247
|
+
'ach.first-panel.desc': '第一次把内容钉进了会话面板。',
|
|
248
|
+
'ach.panel-5.name': '面板管家',
|
|
249
|
+
'ach.panel-5.desc': '5 个会话都用过面板。',
|
|
250
|
+
'ach.first-chart.name': '图表爱好者',
|
|
251
|
+
'ach.first-chart.desc': '渲染了第一张图表(chart/plot/echart)。',
|
|
252
|
+
'ach.chart-10.name': '数据可视化人',
|
|
253
|
+
'ach.chart-10.desc': '10 个界面里出现过图表。',
|
|
254
|
+
'ach.first-advanced.name': '高级玩家',
|
|
255
|
+
'ach.first-advanced.desc': '用上了 3D/图表引擎/架构图之一。',
|
|
256
|
+
'ach.template-1.name': '模板学员',
|
|
257
|
+
'ach.template-1.desc': '从模板中心试用了一个模板。',
|
|
258
|
+
|
|
259
|
+
// ------------------------------------------------- primitive chrome
|
|
260
|
+
'label.copy': '复制',
|
|
261
|
+
'label.copied': '复制成功',
|
|
262
|
+
'label.copiedDone': '已复制',
|
|
263
|
+
'label.copiedShort': '✓ 已复制',
|
|
264
|
+
'label.copiedToClipboard': '已复制到剪贴板',
|
|
265
|
+
'label.copyFailed': '复制失败',
|
|
266
|
+
'label.code': '代码',
|
|
267
|
+
'label.wrap': '自动换行',
|
|
268
|
+
'label.unwrap': '取消自动换行',
|
|
269
|
+
'label.collapse': '收起',
|
|
270
|
+
'label.collapseDiff.aria': '收起差异',
|
|
271
|
+
'label.expandDiff.aria': '展开其余 {hidden} 行差异',
|
|
272
|
+
'label.expandDiff': '… 其余 {hidden} 行',
|
|
273
|
+
'label.diffFiles': '{count} 个文件',
|
|
274
|
+
'label.copyValue': '复制值',
|
|
275
|
+
'label.copyJson': '复制 JSON',
|
|
276
|
+
'label.copyPath': '复制属性路径',
|
|
277
|
+
'label.copyPrettyJson': '复制格式化 JSON',
|
|
278
|
+
'label.copyCompactJson': '复制紧凑 JSON',
|
|
279
|
+
'label.collapseNode': '收起 JSON 节点',
|
|
280
|
+
'label.expandNode': '展开 JSON 节点',
|
|
281
|
+
'label.copyButtonTitle': '{action};右键查看复制选项',
|
|
282
|
+
|
|
283
|
+
// ------------------------------------------------- component chrome
|
|
284
|
+
'block.copyMarkdown': '复制 Markdown',
|
|
285
|
+
'block.copyCsv': '复制 CSV',
|
|
286
|
+
'block.total': '合计',
|
|
287
|
+
'block.filteredRows': '筛选后 {visible} / {total} 行',
|
|
288
|
+
'block.filterMatch': '匹配 {shown} / {total} 项',
|
|
289
|
+
'block.triggered': '✓ 已触发',
|
|
290
|
+
'block.triggeredPlain': '已触发',
|
|
291
|
+
'block.audio': '音频',
|
|
292
|
+
'block.audioError': '音频无法播放',
|
|
293
|
+
'block.video': '视频',
|
|
294
|
+
'block.videoError': '视频无法播放',
|
|
295
|
+
'block.image': '图片',
|
|
296
|
+
'block.imageError': '图片无法加载',
|
|
297
|
+
'block.svgLabel': 'SVG 图形',
|
|
298
|
+
'block.svgPreview': '预览',
|
|
299
|
+
'block.svgSource': '源码',
|
|
300
|
+
'block.svgError': 'SVG 无法显示,已降级显示源码',
|
|
301
|
+
'block.mermaidError': '图语法有误,已降级显示源码',
|
|
302
|
+
'block.mermaidLoading': '渲染中…',
|
|
303
|
+
'block.scene3dLoading': '加载 3D 场景…',
|
|
304
|
+
'block.scene3dError': '3D 渲染失败',
|
|
305
|
+
'block.quizCorrect': '✓ 回答正确!',
|
|
306
|
+
'block.quizWrong': '✗ 再想想看',
|
|
307
|
+
'block.quizRetry': '重新作答',
|
|
308
|
+
'block.selectPlaceholder': '请选择…',
|
|
309
|
+
'block.score': '得分',
|
|
310
|
+
'block.scoreUngraded': '({count} 题无答案未计分)',
|
|
311
|
+
'block.yourAnswer': '你的答案:',
|
|
312
|
+
'block.correctAnswer': ' 正确答案:',
|
|
313
|
+
'block.selectedCount': '已选 {answered}/{total}',
|
|
314
|
+
'block.target': '目标 {value}%',
|
|
315
|
+
'block.chart.barsAria': '横向柱状图,{count} 组',
|
|
316
|
+
'block.chart.barsSummary': '柱状图,{count} 组,最大 {max}',
|
|
317
|
+
'block.chart.lineSeries': '折线图,{count} 条序列,范围 {min} 到 {max}',
|
|
318
|
+
'block.chart.linePoints': '折线图,{count} 个点,范围 {min} 到 {max}',
|
|
319
|
+
'block.chart.donutSummary': '环形图,{count} 项,合计 {total}',
|
|
320
|
+
'block.chart.node': '节点',
|
|
321
|
+
|
|
322
|
+
// -------------------------------------------------------- error text
|
|
323
|
+
'err.boundary.generic': '此界面',
|
|
324
|
+
'err.boundary.fence': '该界面',
|
|
325
|
+
'err.boundary.body': '⚠️ {label}渲染失败(已隔离,不影响其他内容)',
|
|
326
|
+
'err.fieldValidation': 'GenUI 字段验证失败:{errors}',
|
|
327
|
+
'err.chartValidation': 'chart 字段验证失败:{errors}',
|
|
328
|
+
'err.fenceKeptAsCode': '⚠️ dsh-ui {diagnostic} —— 围栏保持为代码块;请修正后重发。',
|
|
329
|
+
'err.fenceParse': '⚠️ dsh-ui fence JSON 解析失败{diagnostic} —— 围栏保持为代码块;请让模型检查并修复 JSON 后重发。',
|
|
330
|
+
}
|
|
@@ -0,0 +1,228 @@
|
|
|
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
|
+
|
|
24
|
+
import type { Context } from '@deepseek-ai/cordis'
|
|
25
|
+
import type {} from '@deepseek-ai/dsh-api-session-controller/client'
|
|
26
|
+
import type {} from '@deepseek-ai/dsh-client-ui-renderer/client'
|
|
27
|
+
import type { SessionId } from '@deepseek-ai/dsh-session/types'
|
|
28
|
+
import type { IConversation } from '@deepseek-ai/dsh-client-ui-conversation/client'
|
|
29
|
+
import type { Key, ReactNode } from 'react'
|
|
30
|
+
import * as primitives from '@deepseek-ai/dsh-client-ui-primitives'
|
|
31
|
+
import { installDomFenceRenderer } from './dom-fence.tsx'
|
|
32
|
+
import { renderGenuiFence, type GenuiFenceContext } from './fence-render.tsx'
|
|
33
|
+
import { renderSvgFence } from './svg-fence.tsx'
|
|
34
|
+
import { createPanelSlashSource } from './panel-command.ts'
|
|
35
|
+
import { GenuiPanel, type GenuiPanelInjected } from './panel.tsx'
|
|
36
|
+
import { GenuiToolView } from './toolview.tsx'
|
|
37
|
+
import { mountAchievementToasts } from './achievement-toast.tsx'
|
|
38
|
+
import { bridgeHostLocale } from './i18n/index.ts'
|
|
39
|
+
import type { InputTriggerServiceContract } from '@deepseek-ai/dsh-client-ui-input-trigger/client'
|
|
40
|
+
import { assetUrl } from './asset-loader.ts'
|
|
41
|
+
|
|
42
|
+
/** Host extension surface the registry channel needs (absent on pristine). */
|
|
43
|
+
type HostFenceExt = {
|
|
44
|
+
registerFenceRenderer?: (lang: string, renderer: (raw: string, key: Key, context?: GenuiFenceContext) => ReactNode) => () => void
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Add low-priority prefetch links for the lazy engine assets (mermaid/three).
|
|
48
|
+
* Browser-dependent: some engines ignore `<link rel=prefetch>`; harmless
|
|
49
|
+
* either way — the on-demand loader still covers a cache miss. Exported for
|
|
50
|
+
* tests. */
|
|
51
|
+
export function prefetchGenuiAssets(): void {
|
|
52
|
+
if (typeof document === 'undefined') return
|
|
53
|
+
for (const file of ['mermaid.js', 'three.js']) {
|
|
54
|
+
if (document.head.querySelector(`link[rel="prefetch"][href="${assetUrl(file)}"]`) !== null) continue
|
|
55
|
+
const link = document.createElement('link')
|
|
56
|
+
link.rel = 'prefetch'
|
|
57
|
+
link.as = 'script'
|
|
58
|
+
link.href = assetUrl(file)
|
|
59
|
+
document.head.appendChild(link)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Session panel action loop: same [genui-action] contract as inline fences,
|
|
64
|
+
* routed through the scoped conversation send (queued user message). The
|
|
65
|
+
* prompt asks the model to re-run render_ui so the panel updates in place. */
|
|
66
|
+
function panelActionSend(ctx: Context, sessionId: SessionId): GenuiPanelInjected {
|
|
67
|
+
const scoped = ctx.sessions.scope(sessionId)
|
|
68
|
+
const conversation = scoped?.get('conversation') as IConversation | undefined
|
|
69
|
+
return {
|
|
70
|
+
sessionId,
|
|
71
|
+
sendGenuiAction: (action, payload) => {
|
|
72
|
+
if (conversation === undefined) return
|
|
73
|
+
const payloadText = Object.keys(payload).length === 0
|
|
74
|
+
? ''
|
|
75
|
+
: ` 组件数据: ${JSON.stringify(payload)}`
|
|
76
|
+
void conversation.send(`[genui-action] ${action}。用户刚刚在面板中触发了动作 "${action}",请根据组件数据执行相应操作,只输出一个 panel:true 的 dsh-ui 围栏来更新面板,回复文本至多一行 10 字以内的确认(如"已刷新"),不要解释、不要普通围栏。${payloadText}`).catch((err: unknown) => {
|
|
77
|
+
// A failed prompt (session gone, agent busy) drops the action; the
|
|
78
|
+
// panel stays interactive — the component is not disabled. Log the
|
|
79
|
+
// failure WITHOUT the action payload or any secret values (the
|
|
80
|
+
// message may contain field content).
|
|
81
|
+
console.warn(`[genui] 面板动作 "${action}" 发送失败(session ${sessionId}):`, err instanceof Error ? err.message : String(err))
|
|
82
|
+
})
|
|
83
|
+
},
|
|
84
|
+
insertTemplate: (text) => {
|
|
85
|
+
// Same insert channel as dsh-memory's organizeMemory: the standard
|
|
86
|
+
// conversation.input.for(scope).setDraft — templates land in the
|
|
87
|
+
// composer draft, not a queued message, so the user can edit before
|
|
88
|
+
// sending.
|
|
89
|
+
const input = (conversation as unknown as {
|
|
90
|
+
input?: { for?(actx: unknown): { setDraft(text: string): void } | undefined }
|
|
91
|
+
} | undefined)?.input?.for?.(scoped)
|
|
92
|
+
input?.setDraft(text)
|
|
93
|
+
},
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Relay a `/panel <指令>` instruction to the model: the scoped conversation
|
|
98
|
+
* send with an explicit panel-only directive, so the model replaces the
|
|
99
|
+
* default panel with content tailored to the request. */
|
|
100
|
+
function sendPanelInstruction(ctx: Context, sessionId: SessionId, instruction: string): void {
|
|
101
|
+
const scoped = ctx.sessions.scope(sessionId)
|
|
102
|
+
const conversation = scoped?.get('conversation') as IConversation | undefined
|
|
103
|
+
if (conversation === undefined) return
|
|
104
|
+
void conversation.send(`用户执行了 /panel 并请求:${instruction}。请只输出一个 panel:true 的 dsh-ui 围栏来更新会话面板,内容按请求定制;回复文本至多一行 10 字以内的确认(如"已更新"),不要解释、不要普通围栏。`).catch((err: unknown) => {
|
|
105
|
+
// A failed prompt drops the instruction; the default panel stays
|
|
106
|
+
// visible. Log without the instruction text (may contain secrets).
|
|
107
|
+
console.warn(`[genui] /panel 指令发送失败(session ${sessionId}):`, err instanceof Error ? err.message : String(err))
|
|
108
|
+
})
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Inline-fence action relay (DOM channel): the same message template the
|
|
113
|
+
* contract host's sendGenuiAction uses, so the model sees one identical
|
|
114
|
+
* [genui-action] contract on both channels.
|
|
115
|
+
*/
|
|
116
|
+
function sendInlineGenuiAction(ctx: Context, sessionId: SessionId, action: string, payload: Record<string, unknown>): void {
|
|
117
|
+
const scoped = ctx.sessions.scope(sessionId)
|
|
118
|
+
const conversation = scoped?.get('conversation') as IConversation | undefined
|
|
119
|
+
if (conversation === undefined) return
|
|
120
|
+
const payloadText = Object.keys(payload).length === 0
|
|
121
|
+
? ''
|
|
122
|
+
: ` 组件数据: ${JSON.stringify(payload)}`
|
|
123
|
+
void conversation.send(`[genui-action] ${action}。用户刚刚在界面中触发了动作 "${action}",请根据组件数据执行相应操作,并用 dsh-ui 输出更新后的界面。${payloadText}`).catch(() => {
|
|
124
|
+
// A failed prompt (session gone, agent busy) drops the action;
|
|
125
|
+
// the UI stays interactive — the component is not disabled.
|
|
126
|
+
})
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** Visual-regression flag: `scripts/e2e-visual.mts` sets
|
|
130
|
+
* `window.__DSH_GENUI_E2E__ = true` via an init script BEFORE this bundle
|
|
131
|
+
* boots, which pins the DOM channel even on hosts that ship the registry
|
|
132
|
+
* extension point. The DOM channel is what lets the harness inject a gallery
|
|
133
|
+
* fence into an empty scratch profile and screenshot the real React tree
|
|
134
|
+
* without a model round trip; production pages never set the flag. */
|
|
135
|
+
function forcedDomChannel(): boolean {
|
|
136
|
+
return (globalThis as { __DSH_GENUI_E2E__?: boolean }).__DSH_GENUI_E2E__ === true
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** Cordis client entry: register the fence renderer on boot, the keyed
|
|
140
|
+
* toolview for the render_ui tool, and the session panel dock; returning the
|
|
141
|
+
* disposers lets cordis tear all registrations down on plugin unload. */
|
|
142
|
+
export function apply(ctx: Context): () => void {
|
|
143
|
+
// Fence channel selection: the registry extension point when the host
|
|
144
|
+
// ships it (contract line), the DOM observer otherwise (pristine line).
|
|
145
|
+
// One plugin build serves both deployments.
|
|
146
|
+
// Language: follow the host's DSH language preference when the deployment
|
|
147
|
+
// ships the locale service, otherwise fall back to browser detection. Read
|
|
148
|
+
// OPTIONALLY (never declared in `inject`) so a pristine host without the
|
|
149
|
+
// service still renders — a declared-but-absent service would park the
|
|
150
|
+
// fiber forever and kill all GenUI rendering.
|
|
151
|
+
const localeDispose = bridgeHostLocale(ctx)
|
|
152
|
+
const registerFn = (primitives as unknown as HostFenceExt).registerFenceRenderer
|
|
153
|
+
const useRegistry = typeof registerFn === 'function' && !forcedDomChannel()
|
|
154
|
+
const channel = useRegistry ? 'registry' : 'dom'
|
|
155
|
+
console.info(`[genui] client active; fence-channel=${channel}`)
|
|
156
|
+
const disposers: Array<() => void> = useRegistry
|
|
157
|
+
? [localeDispose, registerFn!('dsh-ui', renderGenuiFence), registerFn!('svg', renderSvgFence)]
|
|
158
|
+
: [localeDispose, installDomFenceRenderer(ctx, (sessionId, action, payload) => sendInlineGenuiAction(ctx, sessionId, action, payload))]
|
|
159
|
+
// Idle prefetch of the lazy engine assets: the browser downloads them at
|
|
160
|
+
// LOW priority whenever the page is idle, so the first mermaid/3D node in
|
|
161
|
+
// a session usually hits a warm cache instead of paying the fetch on first
|
|
162
|
+
// use. Never blocks first paint; the loader still handles a miss.
|
|
163
|
+
prefetchGenuiAssets()
|
|
164
|
+
// Achievement toasts (0.9.5): a body-level stack independent of the panel.
|
|
165
|
+
disposers.push(mountAchievementToasts())
|
|
166
|
+
// Keyed toolview: the harness dispatches 'tool.call.toolview' by wire tool
|
|
167
|
+
// name; registering under 'render_ui' gives the tool's result card the
|
|
168
|
+
// GenUI renderer (reading the repaired spec from result meta). The toolview
|
|
169
|
+
// also publishes every settled spec to the session panel store.
|
|
170
|
+
disposers.push(ctx.slots.inject('tool.call.toolview', () => ctx.slots.register({
|
|
171
|
+
name: 'tool.call.toolview',
|
|
172
|
+
key: 'render_ui',
|
|
173
|
+
}, GenuiToolView)))
|
|
174
|
+
// Session panel dock: a session-scoped, always-present seat above the
|
|
175
|
+
// composer (TodoDock posture). Renders the session's latest render_ui
|
|
176
|
+
// spec in place; absent spec = no panel.
|
|
177
|
+
disposers.push(ctx.slots.inject('conversation.input.dock', () => ctx.slots.register({
|
|
178
|
+
name: 'conversation.input.dock',
|
|
179
|
+
id: 'genui-panel',
|
|
180
|
+
order: 50,
|
|
181
|
+
inject: (sessionId: SessionId): GenuiPanelInjected => panelActionSend(ctx, sessionId),
|
|
182
|
+
}, GenuiPanel)))
|
|
183
|
+
// /panel slash command: a deterministic, client-side entry point that
|
|
184
|
+
// opens the panel dock (publishes the default spec + expand request),
|
|
185
|
+
// clears it (/panel clear), or relays an instruction to the model
|
|
186
|
+
// (/panel <指令>) so the panel gets tailored content.
|
|
187
|
+
//
|
|
188
|
+
// inputTriggers is subscribed via cordis OPTIONAL injection (ctx.inject),
|
|
189
|
+
// NOT a one-shot ctx.get() at apply time: the service is typically
|
|
190
|
+
// provided by a different bundle than slots/sessions, so it can arrive
|
|
191
|
+
// AFTER apply() runs — a one-shot lookup would silently disable /panel
|
|
192
|
+
// even on hosts that DO ship the service (service arrival order race).
|
|
193
|
+
// ctx.inject activates the callback only when the service arrives (any
|
|
194
|
+
// order) and disposes with the subscription fiber; hosts without the
|
|
195
|
+
// service simply never register /panel, and rendering is unaffected
|
|
196
|
+
// either way.
|
|
197
|
+
ctx.inject(['inputTriggers'], (scope) => {
|
|
198
|
+
const slash = scope.get('inputTriggers') as InputTriggerServiceContract | undefined
|
|
199
|
+
if (slash === undefined) return
|
|
200
|
+
scope.effect(() => slash.registerSource(
|
|
201
|
+
createPanelSlashSource((sessionId, instruction) => sendPanelInstruction(ctx, sessionId, instruction)),
|
|
202
|
+
), 'genui: /panel')
|
|
203
|
+
})
|
|
204
|
+
return () => {
|
|
205
|
+
for (const dispose of disposers) dispose()
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// Browser services the client entry needs: the slots registry (toolview +
|
|
210
|
+
// dock) and sessions (scoped conversation send behind actions). This
|
|
211
|
+
// declaration is what the host's fiber inject waiting uses — without it
|
|
212
|
+
// apply() runs before the services bind and the whole plugin tree fails the
|
|
213
|
+
// boot sweep.
|
|
214
|
+
//
|
|
215
|
+
// inputTriggers (the /panel command source) is deliberately NOT declared:
|
|
216
|
+
// cordis `inject` is a hard activation gate — a declared service that is
|
|
217
|
+
// never provided (pristine DSH shells ship no inputTriggers provider) parks
|
|
218
|
+
// the fiber in waiting forever and apply() never runs, silently killing all
|
|
219
|
+
// GenUI rendering. Instead the apply() body subscribes via ctx.inject
|
|
220
|
+
// (optional injection): hosts with the service get /panel registered in any
|
|
221
|
+
// arrival order, hosts without it never register /panel — and the renderer
|
|
222
|
+
// itself never depends on the service either way.
|
|
223
|
+
export const inject = ['slots', 'sessions']
|
|
224
|
+
|
|
225
|
+
// Re-export the registry renderer for the test suite (setup.ts registers it
|
|
226
|
+
// exactly like apply() does on contract hosts).
|
|
227
|
+
export { renderGenuiFence }
|
|
228
|
+
export type { GenuiFenceContext } from './fence-render.tsx'
|