@sparkelf/dsh-genui 0.11.4-patch.1 → 0.13.0-sparkelf.2

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 (112) hide show
  1. package/CHANGELOG.md +76 -0
  2. package/ICON-NAMES.md +30 -0
  3. package/README.md +26 -28
  4. package/README.zh-CN.md +26 -28
  5. package/SKILL.md +128 -19
  6. package/THIRD_PARTY_NOTICES.md +42 -0
  7. package/assets/genui-icon.svg +20 -0
  8. package/assets/genui-logo.svg +18 -0
  9. package/cordis.patch.yml +1 -1
  10. package/lib/assets/icons.js +1 -0
  11. package/lib/assets/mermaid.js +325 -325
  12. package/lib/assets/standalone-runtime.js +10 -9
  13. package/lib/client.js +32 -31
  14. package/lib/index.js +489 -80
  15. package/lib/types/client/action-context.d.ts +1 -1
  16. package/lib/types/client/artifact/types.d.ts +1 -1
  17. package/lib/types/client/asset-loader.d.ts +2 -2
  18. package/lib/types/client/blocks/blocks.d.ts +12 -0
  19. package/lib/types/client/blocks/icon.d.ts +4 -0
  20. package/lib/types/client/dom-fence.d.ts +2 -1
  21. package/lib/types/client/fence-render.d.ts +5 -21
  22. package/lib/types/client/file-address.d.ts +4 -0
  23. package/lib/types/client/file-link-context.d.ts +49 -0
  24. package/lib/types/client/file-link.d.ts +17 -0
  25. package/lib/types/client/gallery.d.ts +8 -2
  26. package/lib/types/client/genui-runtime/diagnostics.d.ts +1 -1
  27. package/lib/types/client/genui-runtime/limits.d.ts +4 -0
  28. package/lib/types/client/genui-runtime/schema.d.ts +14 -1
  29. package/lib/types/client/guard.d.ts +4 -1
  30. package/lib/types/client/i18n/en.d.ts +5 -1
  31. package/lib/types/client/i18n/index.d.ts +1 -1
  32. package/lib/types/client/icons/asset-icons.d.ts +1 -0
  33. package/lib/types/client/icons/icon-data-full.d.ts +23 -0
  34. package/lib/types/client/icons/icon-data.d.ts +24 -0
  35. package/lib/types/client/icons/icon-lazy.d.ts +18 -0
  36. package/lib/types/client/icons/icon-names-full.d.ts +12 -0
  37. package/lib/types/client/index.d.ts +5 -15
  38. package/lib/types/client/inline.d.ts +1 -1
  39. package/lib/types/client/mermaid-colors.d.ts +2 -0
  40. package/lib/types/client/mermaid-core.d.ts +2 -1
  41. package/lib/types/client/mermaid-lazy.d.ts +5 -1
  42. package/lib/types/client/panel-command.d.ts +21 -1
  43. package/lib/types/client/panel.d.ts +6 -1
  44. package/lib/types/client/primitive-adapter.d.ts +0 -2
  45. package/lib/types/client/session-resolver.d.ts +13 -2
  46. package/lib/types/client/source-fence.d.ts +1 -1
  47. package/lib/types/client/spec.d.ts +107 -3
  48. package/lib/types/client/standalone/asset-loader.d.ts +1 -1
  49. package/lib/types/client/standalone/primitive-adapter.d.ts +0 -4
  50. package/lib/types/plugin/fence-feedback.d.ts +11 -7
  51. package/lib/types/plugin/index.d.ts +6 -2
  52. package/lib/types/shared/fence-language.d.ts +14 -0
  53. package/lib/types/shared/fence-repair.d.ts +2 -1
  54. package/lib/types/shared/fence-resolve.d.ts +1 -1
  55. package/package.json +92 -83
  56. package/src/client/EChartNode.tsx +17 -3
  57. package/src/client/GenuiBlock.module.css +411 -76
  58. package/src/client/action-context.ts +5 -15
  59. package/src/client/artifact/ArtifactExport.module.css +34 -3
  60. package/src/client/artifact/ExportableGenuiBlock.tsx +23 -2
  61. package/src/client/artifact/portability.ts +6 -1
  62. package/src/client/artifact/types.ts +1 -1
  63. package/src/client/asset-loader.ts +3 -3
  64. package/src/client/blocks/advanced.tsx +101 -14
  65. package/src/client/blocks/blocks.tsx +143 -0
  66. package/src/client/blocks/charts.tsx +22 -6
  67. package/src/client/blocks/icon.tsx +93 -0
  68. package/src/client/blocks/image.tsx +1 -0
  69. package/src/client/blocks/render-node.tsx +84 -52
  70. package/src/client/dom-fence.tsx +546 -72
  71. package/src/client/fence-render.tsx +5 -21
  72. package/src/client/file-address.ts +37 -0
  73. package/src/client/file-link-context.tsx +116 -0
  74. package/src/client/file-link.ts +46 -0
  75. package/src/client/gallery.ts +161 -133
  76. package/src/client/genui-runtime/diagnostics.ts +1 -1
  77. package/src/client/genui-runtime/limits.ts +4 -0
  78. package/src/client/genui-runtime/normalize.ts +42 -6
  79. package/src/client/genui-runtime/schema.ts +39 -7
  80. package/src/client/guard.ts +170 -15
  81. package/src/client/i18n/en.ts +5 -1
  82. package/src/client/i18n/index.ts +1 -1
  83. package/src/client/i18n/zh.ts +5 -1
  84. package/src/client/icons/asset-icons.ts +16 -0
  85. package/src/client/icons/icon-data-full.ts +5715 -0
  86. package/src/client/icons/icon-data.ts +507 -0
  87. package/src/client/icons/icon-lazy.ts +80 -0
  88. package/src/client/icons/icon-names-full.ts +12 -0
  89. package/src/client/index.tsx +27 -51
  90. package/src/client/inline.ts +17 -6
  91. package/src/client/mermaid-colors.ts +40 -0
  92. package/src/client/mermaid-core.ts +69 -61
  93. package/src/client/mermaid-lazy.ts +99 -4
  94. package/src/client/panel-command.ts +16 -2
  95. package/src/client/panel.tsx +18 -5
  96. package/src/client/primitive-adapter.ts +0 -11
  97. package/src/client/session-resolver.ts +12 -21
  98. package/src/client/source-fence.ts +4 -2
  99. package/src/client/spec.ts +116 -2
  100. package/src/client/standalone/asset-loader.ts +1 -1
  101. package/src/client/standalone/primitive-adapter.tsx +1 -9
  102. package/src/client/table-details.ts +4 -3
  103. package/src/plugin/fence-feedback.ts +60 -14
  104. package/src/plugin/index.ts +45 -20
  105. package/src/plugin/tool.ts +11 -2
  106. package/src/shared/fence-language.ts +30 -0
  107. package/src/shared/fence-repair.ts +37 -1
  108. package/src/shared/fence-resolve.ts +1 -1
  109. package/tsdown.config.ts +7 -8
  110. package/lib/invariant.js +0 -19
  111. package/lib/types/plugin/invariant.d.ts +0 -15
  112. package/src/plugin/invariant.ts +0 -30
@@ -35,7 +35,7 @@ import { installFenceFeedback } from './fence-feedback.ts'
35
35
  */
36
36
 
37
37
  /** Route prefix under /plugins; anything under it is this plugin's asset. */
38
- const ASSET_ROUTE_PATH = '/plugins/@changfenhuang/dsh-genui/assets'
38
+ const ASSET_ROUTE_PATH = '/plugins/@sparkelf/dsh-genui/assets'
39
39
 
40
40
  /** Safe flat file names only: no slashes, no traversal, js assets only. */
41
41
  const ASSET_FILE_RE = /^[A-Za-z0-9][A-Za-z0-9._-]*\.js$/
@@ -83,11 +83,13 @@ async function serveGenuiAsset(req: IncomingMessage, res: ServerResponse): Promi
83
83
  }
84
84
  }
85
85
 
86
+ const RENDER_UI_TOOL_GUIDANCE = '- Tool channel: render_ui 工具把同一 spec 渲染为工具行卡片;围栏用于回答内联 UI。'
87
+
86
88
  /** The fence language description injected into every assembled system prompt.
87
89
  * Deliberately slim: the `genui` skill carries the full component→field
88
90
  * mapping; this section keeps only the contract that must always be
89
91
  * present (fence syntax, type whitelist, and critical behavioral rules). */
90
- export const GENUI_SECTION_TEXT = `You can render interactive UI components INSIDE your reply — between paragraphs — by emitting a fenced block with the language tag \`dsh-ui\` containing a JSON spec:
92
+ export const GENUI_SECTION_TEXT = `Render UI inside your reply with a fenced \`dsh-ui\` JSON block:
91
93
 
92
94
  \`\`\`dsh-ui
93
95
  {"title":"<user-language text>","gap":14,"items":[...]}
@@ -96,21 +98,23 @@ export const GENUI_SECTION_TEXT = `You can render interactive UI components INSI
96
98
  Allowed \`type\` values; the \`genui\` skill, when available, carries the full content→component mapping and per-component field details:
97
99
 
98
100
  - 布局: text · row · col · grid · card · divider · spacer · hero(封面块,一条回答最多一个)
99
- - 展示: badge · stat · progress · list · table · keyvalue · timeline · file-tree · breadcrumb · callout · steps · diff · json · code · copy · avatar · audio · video
100
- - 图表: chart {"kind":"bars|line|donut","data":[{"label":"...","value":n}],"series":[{"label":"...","data":[...]}]?,"horizontal":true?,"stacked":true?}(series:bars 分组/堆叠 / line 多序列;horizontal 横向柱) · echart (preset 名或 option 直通,预设清单见 skill) · plot (函数图)
101
- - 交互: button · input · textarea · select · checkbox · switch · slider · radio · submit · quiz · link · tabs · accordion
102
- - 高级: mermaid (流程图/时序/甘特/ER 等,关键字见 skill) · diagram (架构/流程图,27 种 kind) · scene3d (3D WebGL)
101
+ - 展示: badge · stat · progress · list · table · keyvalue · timeline · file-tree · breadcrumb · callout · steps · diff · json · code · copy · avatar · image · audio · video · icon · blocks · arrow
102
+ - 图表: chart {"kind":"bars|line|donut","data":[{"label":"...","value":n}]}(series:bars 分组/堆叠 / line 多序列) · echart (preset 名或 option 直通,清单见 skill) · plot (函数图) · svg (单图预览)
103
+ - 交互: button · input · textarea · select · checkbox · switch · slider · radio · submit · quiz · link · tabs · accordion(row.justify / col.width / card.flat 见图元)
104
+ - 高级: mermaid (流程图/时序/甘特/ER 等,关键字见 skill) · diagram (架构/流程图) · scene3d (3D WebGL)
103
105
 
104
106
  **默认就该出 UI**:出现下列情况至少出一个围栏:
105
107
  - ≥3 条并列要点 → \`list\`;数字对比 → \`table\`;指标/进度/状态 → \`stat\`/\`progress\`/\`badge\`
106
- - 步骤/时间线 → \`steps\`/\`timeline\`/\`mermaid\`;架构/流程 → \`diagram\` 或 \`mermaid\`;风险/结论 → \`callout\`;代码/改动 → \`code\`/\`diff\`/\`json\`
107
- - 行内富文本:支持公式、\`code\`、加粗、高亮、链接;禁用 Markdown table / fenced code,改用 table / code / diff / json。
108
- - 默认无卡:按触发条件使用组件,每个组件承载不同信息;卡片只用于并排项与数据对象,单段文字用标题、正文与间距。
108
+ - 步骤/时间线 → \`steps\`/\`timeline\`/\`mermaid\`;架构/流程 → \`diagram\` 或 \`mermaid\`;单条风险/结论摘要 → \`callout\`;代码/改动 → \`code\`/\`diff\`/\`json\`
109
+ - 行内富文本:支持公式、\`code\`、加粗、高亮、链接;禁用 Markdown table 与 fenced code,改用 table/code/diff/json。
110
+ - 默认无卡:卡片用于并排项、数据对象或需底色的风险清单。
109
111
 
110
- **发回答前最后自检一次**:这段内容里有没有 ≥3 条并列要点、任何对比、任何数字/指标、任何步骤或流程?有就先转成组件再开口。**状态汇报、进度说明、提交与改动清单同样算**。
111
- - 趋势/占比 → \`chart\`(≤8 点)或 \`echart\`(多序列/要交互时);配色默认跟随主题,只有语义需要时才用 \`palette\`/\`card.accent\`;grid 子节点用 \`"span":2\` 跨列做宽窄混排;数据多时给 \`table\`/\`chart\`/\`list\` 配一个 \`input\`(id) + \`filter\` 绑定,读者能就地筛选。
112
+ **发回答前最后自检一次**:有没有 ≥3 条并列要点、任何对比、任何数字/指标、任何步骤或流程?有就先转成组件。**状态汇报、进度说明、提交与改动清单同样算**。
113
+ - 趋势/占比 → \`chart\`(≤8 点)或 \`echart\`;配色跟随主题,语义需要时才用 \`palette\`/\`card.accent\`;grid 子节点用 \`"span":2\` 做宽窄混排;数据多时给 \`table\`/\`list\` 配 \`input\`(id)+\`filter\` 就地筛选。
114
+ - 多组件回答先套 skill「编排范式」,别一行一个往下堆;章节分隔 \`divider\` 带 \`label\`。
112
115
 
113
- **字段速查**(完整见 genui skill):\`stat\` \`{"label","value","delta"?}\` · \`table\` \`{"columns":[...],"rows":[[...]],"types"?,"details"?,"filter"?,"export"?}\` · \`progress\` \`{"value":0-100,"label"?,"variant"?,"target"?}\` · \`keyvalue\` \`{"pairs":[{"key","value"}]}\` · \`steps\` \`{"steps":[{"title","desc"?}]}\` · \`file-tree\` \`{"items":[{"name","type":"file|dir","children"?}]}\` · \`callout\` \`{"content","tone"?,"title"?}\`
116
+ **字段速查**(完整见 genui skill):\`stat\` \`{"type":"stat","label","value"}\` · \`table\` \`{"type":"table","columns":[...],"rows":[[...]]}\` · \`progress\` \`{"type":"progress","value":0-100}\` · \`keyvalue\` \`{"type":"keyvalue","pairs":[{"key","value"}]}\` · \`steps\` \`{"type":"steps","steps":[{"title"}]}\` · \`file-tree\` \`{"type":"file-tree","items":[{"name","type":"file|dir"}]}\` · \`callout\` \`{"type":"callout","content"}\`
117
+ **节点规则:** 组件节点必须带字符串 \`type\`,值为组件名;\`file-tree.items[].type\` 表示 \`file\` 或 \`dir\`。
114
118
 
115
119
  **字段名写错 = 该组件被丢弃**(其余组件照常渲染):\`callout\` 正文是 \`content\` 不是 text/desc;\`table\` 要 \`columns\`+\`rows\` 不是 items;\`keyvalue\` 记录是 \`{key,value}\` 不是 \`{label,value}\`;\`file-tree\` 记录是 \`{name,type}\` 不是 \`{label}\`;callout tone 是 info/success/warning/error(无 danger)。不确定就调 \`validate_dsh_ui\`。
116
120
 
@@ -123,7 +127,7 @@ Rules:
123
127
  - Durable state: 交互状态按「会话+内容指纹」持久化——刷新/重放恢复;相同内容保留,新内容重置。
124
128
  - 卷子模式: 每题一个 radio(group+answer+explanation)+ 一个 submit(groups 全列),本地判分。
125
129
  - Secrets ban: 不索取密码、API Key、Token、恢复码;需要时拒绝并解释。
126
- - Tool channel: render_ui 工具把同一 spec 渲染为工具行卡片;围栏用于回答内联 UI。
130
+ ${RENDER_UI_TOOL_GUIDANCE}
127
131
  - 围栏位置:\`dsh-ui\` 只写在**回答正文**;写在 reasoning/思考块里不渲染、用户看不到——思考里验证好 spec,正文再输出同一份。
128
132
  - Panel: "panel":true 只渲染进会话面板 dock 并原地更新;"append":true 追加合并;上限 200 节点/200 次追加,满了发 replace 重建。面板来的 [genui-action] 只回一个 panel:true 围栏 + 至多一行 10 字内确认。`
129
133
 
@@ -135,14 +139,25 @@ Rules:
135
139
  // plugin — hosts without tool access keep the fence channel working. Cordis
136
140
  // inject entries are hard requirements, so the registry is probed at runtime
137
141
  // instead (see apply).
138
- export const name = '@changfenhuang/dsh-genui'
142
+ export const name = '@sparkelf/dsh-genui'
139
143
  export const inject = ['systemPrompt']
140
144
 
141
145
  const BUNDLED_SKILL_RANK = 600
142
146
  const BUNDLED_SKILL_PROVIDER = 'dsh-genui'
143
- const BUNDLED_SKILL_DESCRIPTION = 'GenUI dsh-ui component/schema reference. Preserve conversation language for all user-visible text.'
144
147
  const BUNDLED_SKILL_INVOCATION = { modelInvocable: true, userInvocable: true } as const
145
148
 
149
+ /**
150
+ * The frontmatter field the routing description comes from.
151
+ *
152
+ * A second copy of this sentence in code drifted from SKILL.md unnoticed, and the
153
+ * panel showed the code copy while the model read the same string — so an edit to
154
+ * the skill's own frontmatter changed nothing. The file is the only source.
155
+ */
156
+ function frontmatterField(front: string, key: string): string | undefined {
157
+ const line = new RegExp('^\\s*' + key + '\\s*:\\s*(.+?)\\s*$', 'mu').exec(front)
158
+ return line?.[1]?.replace(/^['"]|['"]$/gu, '')
159
+ }
160
+
146
161
  /** Register through the provider path so source=bundled also gets bundled precedence. */
147
162
  function bundledSkillProvider(): SkillProvider {
148
163
  const moduleDirectory = dirname(fileURLToPath(new URL(import.meta.url)))
@@ -152,11 +167,13 @@ function bundledSkillProvider(): SkillProvider {
152
167
  const raw = readFileSync(path, 'utf8')
153
168
  const end = raw.indexOf('\n---\n', 4)
154
169
  if (!raw.startsWith('---\n') || end < 0) throw new Error('genui SKILL.md has invalid frontmatter')
170
+ const description = frontmatterField(raw.slice(4, end), 'description')
171
+ if (description === undefined) throw new Error('genui SKILL.md frontmatter has no description')
155
172
  return {
156
173
  name: BUNDLED_SKILL_PROVIDER,
157
174
  list: () => Promise.resolve([{
158
175
  name: 'genui',
159
- description: BUNDLED_SKILL_DESCRIPTION,
176
+ description,
160
177
  invocation: BUNDLED_SKILL_INVOCATION,
161
178
  source: 'bundled',
162
179
  provider: BUNDLED_SKILL_PROVIDER,
@@ -167,7 +184,7 @@ function bundledSkillProvider(): SkillProvider {
167
184
  }]),
168
185
  get: () => Promise.resolve({
169
186
  name: 'genui',
170
- description: BUNDLED_SKILL_DESCRIPTION,
187
+ description,
171
188
  invocation: BUNDLED_SKILL_INVOCATION,
172
189
  source: 'bundled',
173
190
  provider: BUNDLED_SKILL_PROVIDER,
@@ -189,21 +206,29 @@ export interface GenuiPluginConfig {
189
206
  * 每回合和每个围栏正文最多请求一次,子代理不触发,每次修正请求会消耗模型步数。
190
207
  */
191
208
  fenceFeedback?: boolean
209
+
210
+ /**
211
+ * 是否注册 render_ui 模型工具。默认开启,设置为 false 时关闭;不影响 validate_dsh_ui 和 dsh-ui 围栏渲染。
212
+ */
213
+ renderUiTool?: boolean
192
214
  }
193
215
 
194
216
  export function apply(ctx: Context, config?: GenuiPluginConfig): void {
217
+ const renderUiToolEnabled = config?.renderUiTool !== false
195
218
  ctx.systemPrompt.section({
196
219
  name: 'genui:fence',
197
220
  order: ctx.systemPrompt.getSectionOrder('STRUCTURED_OUTPUT'),
198
- text: GENUI_SECTION_TEXT,
221
+ text: renderUiToolEnabled ? GENUI_SECTION_TEXT : GENUI_SECTION_TEXT.replace(`${RENDER_UI_TOOL_GUIDANCE}\n`, ''),
199
222
  })
200
- installFenceFeedback(ctx, config?.fenceFeedback !== false)
223
+ installFenceFeedback(ctx, config?.fenceFeedback !== false, renderUiToolEnabled)
201
224
  // Hosts without tool access keep the fence channel. The dependency fiber
202
225
  // starts whenever tools becomes available and unloads its registrations
203
226
  // before either the service or this plugin is replaced.
204
227
  ctx.inject(['tools'], (toolsCtx) => {
205
228
  toolsCtx.effect(function* () {
206
- yield toolsCtx.tools.register(createRenderUiTool())
229
+ if (renderUiToolEnabled) {
230
+ yield toolsCtx.tools.register(createRenderUiTool())
231
+ }
207
232
  yield toolsCtx.tools.register(createValidateDshUiTool())
208
233
  }, 'dsh-genui: model tools')
209
234
  })
@@ -162,6 +162,12 @@ function formatProcessWarnings(processed: GenuiProcessResult): string[] {
162
162
  ? `warning=alias_ignored path=${warning.path} canonical=${canonicalPath}`
163
163
  : `warning=alias_normalized path=${warning.path} canonical=${canonicalPath}`
164
164
  }
165
+ if (warning.kind === 'unknown-field') {
166
+ return `warning=unknown_field path=${JSON.stringify(warning.path)} detail=${JSON.stringify(warning.message)}`
167
+ }
168
+ if (warning.kind === 'truncated') {
169
+ return `warning=policy_truncated path=${JSON.stringify(warning.path)} detail=${JSON.stringify(warning.message)}`
170
+ }
165
171
  return `warning=process detail=${JSON.stringify(warning.message)}`
166
172
  })
167
173
  }
@@ -260,6 +266,7 @@ const VALIDATE_DESCRIPTION =
260
266
  + 'Pass the exact JSON text you are about to put inside the fence as the "spec" argument (a string). '
261
267
  + 'Returns a [genui-validation] protocol block with status, diagnostics, next action, and reply_language=conversation. '
262
268
  + 'When invalid JSON is repairable, repaired_json contains the fixed body; emit it only with next=emit_repaired_fence. '
269
+ + 'A warning=unknown_field requires fixing the indicated path and another validation call. '
263
270
  + 'A warning=block_markdown requires the indicated replacement node and another validation call.'
264
271
 
265
272
  const VALIDATE_PARAMETERS: Record<string, unknown> = {
@@ -368,6 +375,7 @@ export function createValidateDshUiTool(): ToolDefinition {
368
375
  if (processed.spec !== null && processed.errors.length === 0) {
369
376
  const warnings = formatProcessWarnings(processed)
370
377
  const inlineWarnings = formatInlineContentWarnings(processed.spec)
378
+ const requiresCorrection = inlineWarnings.length > 0 || processed.warnings.some(warning => warning.kind === 'unknown-field')
371
379
  return `${validationProtocol([
372
380
  'status=invalid',
373
381
  'error=invalid_json',
@@ -377,7 +385,7 @@ export function createValidateDshUiTool(): ToolDefinition {
377
385
  ...inlineWarnings,
378
386
  'repair=applied',
379
387
  `repair_count=${repaired.repairs}`,
380
- inlineWarnings.length === 0 ? 'next=emit_repaired_fence' : 'next=fix_and_revalidate',
388
+ requiresCorrection ? 'next=fix_and_revalidate' : 'next=emit_repaired_fence',
381
389
  ])}\nrepaired_json:\n\`\`\`\n${repaired.text}\n\`\`\``
382
390
  }
383
391
  }
@@ -409,9 +417,10 @@ export function createValidateDshUiTool(): ToolDefinition {
409
417
  }
410
418
  const warnings = formatProcessWarnings(processed)
411
419
  const inlineWarnings = formatInlineContentWarnings(processed.spec)
420
+ const requiresCorrection = inlineWarnings.length > 0 || processed.warnings.some(warning => warning.kind === 'unknown-field')
412
421
  return validationProtocol([
413
422
  'status=valid', `rendered=${processed.renderedCount}`, ...warnings, ...inlineWarnings,
414
- inlineWarnings.length === 0 ? 'next=emit_fence' : 'next=fix_and_revalidate',
423
+ requiresCorrection ? 'next=fix_and_revalidate' : 'next=emit_fence',
415
424
  ])
416
425
  },
417
426
  presentCall(): GenericCallView | undefined {
@@ -0,0 +1,30 @@
1
+ /** 围栏开头的 `dsh-ui` 标签在书写时可能被带上标点(```dsh-ui> / ```dsh-ui` …)。
2
+ * 这类标记在 mdast 里原样留在 `lang` 上,严格相等判断会让整条围栏静默退化成
3
+ * 普通代码块——真实会话里同一个模型可以在一条消息里写出 182 个这样的围栏。
4
+ * 这里只吸收**标签之后**的标点,`dsh-ui-something` 这样的真实语言名不受影响。 */
5
+ const GENUI_LABEL_PATTERN = /^dsh-ui$/
6
+ const GENUI_TRAILING_PUNCTUATION = /[>`"'.,;:)\]】」』]+$/
7
+
8
+ /**
9
+ * 把宿主的围栏语言标记规范化成 GenUI 能识别的写法。
10
+ *
11
+ * @param lang - 宿主 markdown 里的原始 language(可能含尾部标点或大小写差异)
12
+ * @returns 规范化后的语言名;无法规范化时返回输入本身
13
+ */
14
+ export function normalizeFenceLanguage(lang: string): string {
15
+ const trimmed = lang.trim()
16
+ if (GENUI_LABEL_PATTERN.test(trimmed.toLowerCase())) return 'dsh-ui'
17
+ const stripped = trimmed.replace(GENUI_TRAILING_PUNCTUATION, '').trim().toLowerCase()
18
+ if (GENUI_LABEL_PATTERN.test(stripped)) return 'dsh-ui'
19
+ return lang
20
+ }
21
+
22
+ /**
23
+ * 判断语言标记是否指向 GenUI 围栏。
24
+ *
25
+ * @param lang - 宿主暴露的围栏语言(`null` = 围栏没有语言)
26
+ * @returns 规范化为 `dsh-ui` 时返回 true
27
+ */
28
+ export function isGenuiFenceLanguage(lang: string | null | undefined): boolean {
29
+ return typeof lang === 'string' && normalizeFenceLanguage(lang) === 'dsh-ui'
30
+ }
@@ -14,7 +14,7 @@
14
14
  * skips mismatched closers (a `]` mistyped as `}`, duplicated terminators).
15
15
  * SETTLED MESSAGES ONLY: a streaming half must never be adopted as a
16
16
  * finished prefix.
17
- * @module @changfenhuang/dsh-genui/shared/fence-repair
17
+ * @module @sparkelf/dsh-genui/shared/fence-repair
18
18
  */
19
19
 
20
20
  /** A fence body counts as complete when it parses as a whole JSON value. */
@@ -51,6 +51,7 @@ export function describeJsonFailure(raw: string): string | null {
51
51
  * with ASCII quotes (e.g. `对"别名路径"判定失败`), which makes JSON.parse
52
52
  * fail near that quote with "Expected ',' or ']'...".
53
53
  * 2. Trailing commas before `}` / `]` or at end of input.
54
+ * 3. Valueless object keys immediately before a complete key-and-colon pair.
54
55
  *
55
56
  * A shared grammar-aware scan distinguishes object keys from values and
56
57
  * checks the continuation after a potential string terminator. Ambiguous
@@ -92,6 +93,29 @@ function isJsonSpace(ch: string | undefined): boolean {
92
93
  return ch === ' ' || ch === '\t' || ch === '\n' || ch === '\r'
93
94
  }
94
95
 
96
+ /** Skip only complete, valueless object keys followed by a valued member. */
97
+ function skipValuelessKeys(raw: string, start: number, limit = raw.length): { start: number; repairs: number } | null {
98
+ let cursor = start
99
+ let repairs = 0
100
+ while (cursor < limit && raw[cursor] === '"') {
101
+ const keyStart = cursor++
102
+ while (cursor < limit && raw[cursor] !== '"') {
103
+ if (raw[cursor] === '\\') cursor += 2
104
+ else cursor++
105
+ }
106
+ if (cursor >= limit) return null
107
+ cursor++
108
+ try { JSON.parse(raw.slice(keyStart, cursor)) } catch { return null }
109
+ while (cursor < limit && isJsonSpace(raw[cursor])) cursor++
110
+ if (raw[cursor] === ':') return repairs > 0 ? { start: keyStart, repairs } : null
111
+ if (raw[cursor] !== ',') return null
112
+ repairs++
113
+ cursor++
114
+ while (cursor < limit && isJsonSpace(raw[cursor])) cursor++
115
+ }
116
+ return null
117
+ }
118
+
95
119
  /**
96
120
  * Quote closure is contextual: only keys may be followed by `:`, and a comma
97
121
  * must introduce the next member of the enclosing object/array. Walk closing
@@ -130,6 +154,10 @@ function quoteCanClose(raw: string, index: number, key: boolean, scopes: JsonSco
130
154
  if (raw[cursor] === scope.closer) return true // a removable trailing comma
131
155
  if (scope.closer === ']') return /["[{tfn\-0-9]/.test(raw[cursor]!)
132
156
  if (raw[cursor] !== '"') return false
157
+ // A valueless sibling is removable; it must not make a real value's
158
+ // closing quote absorb that sibling into the preceding string.
159
+ const valueless = skipValuelessKeys(raw, cursor, limit)
160
+ if (valueless !== null) cursor = valueless.start
133
161
  // An object comma must be followed by a quoted key and its colon. Escapes
134
162
  // in that key are skipped without changing them.
135
163
  cursor++
@@ -205,6 +233,14 @@ function scanFenceCandidate(raw: string, complete: boolean, contentQuotes: Reado
205
233
  }
206
234
  if (ch === '"') {
207
235
  key = scopes[scopes.length - 1]?.expecting === 'key'
236
+ if (key) {
237
+ const valueless = skipValuelessKeys(raw, i)
238
+ if (valueless !== null) {
239
+ repairs += valueless.repairs
240
+ i = valueless.start - 1
241
+ continue
242
+ }
243
+ }
208
244
  interiorQuote = false
209
245
  inString = true
210
246
  out += ch
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * 使用浏览器 renderer 与 Node 侧最终回复反馈守卫共用的流程解析 dsh-ui 围栏正文。
3
- * @module @changfenhuang/dsh-genui/shared/fence-resolve
3
+ * @module @sparkelf/dsh-genui/shared/fence-resolve
4
4
  */
5
5
 
6
6
  import { partialRepairGenuiSpec, processGenuiSpec, type GenuiProcessResult } from '../client/guard.ts'
package/tsdown.config.ts CHANGED
@@ -216,7 +216,7 @@ const standaloneConfig: UserConfig = {
216
216
  * main client bundle never contains either engine, so the eager download
217
217
  * drops from ~9 MB to the small renderer core.
218
218
  */
219
- function assetConfig(name: 'mermaid' | 'three' | 'echarts', entry: string): UserConfig {
219
+ function assetConfig(name: 'mermaid' | 'three' | 'echarts' | 'echarts-core' | 'echarts-full' | 'icons', entry: string): UserConfig {
220
220
  return {
221
221
  name: `${ID}/assets/${name}`,
222
222
  entry: { [`assets/${name}`]: entry },
@@ -245,19 +245,15 @@ function assetConfig(name: 'mermaid' | 'three' | 'echarts', entry: string): User
245
245
 
246
246
  const libConfig: UserConfig = {
247
247
  name: ID,
248
- // Named entries keep the published layout stable (lib/index.js +
249
- // lib/invariant.js) while src/index.ts becomes the canonical bundle
250
- // source entry that plugin_check's tool-bundle contract expects.
251
- entry: { index: 'src/index.ts', invariant: 'src/plugin/invariant.ts' },
248
+ // Keep the root plugin bundle at lib/index.js, built from src/index.ts.
249
+ entry: { index: 'src/index.ts' },
252
250
  outDir: 'lib',
253
251
  format: ['esm'],
254
252
  platform: 'node',
255
253
  target: 'es2024',
256
254
  fixedExtension: false,
257
255
  dts: false,
258
- // Flatten entry outputs to lib/<basename>.js so package exports keep the
259
- // stable paths lib/index.js + lib/invariant.js (a directory-mirroring
260
- // default would emit lib/plugin/invariant.js).
256
+ // Keep the output name aligned with the package's root export.
261
257
  outputOptions: { entryFileNames: '[name].js' },
262
258
  // Cleanup happens in the build script (`rm -rf lib` before tsc): tsdown
263
259
  // must never wipe lib/types (tsc's declaration output) mid-pipeline.
@@ -272,4 +268,7 @@ export default [
272
268
  assetConfig('three', 'src/client/asset-three.ts'),
273
269
  assetConfig('echarts-core', 'src/client/asset-echarts-core.ts'),
274
270
  assetConfig('echarts-full', 'src/client/asset-echarts.ts'),
271
+ // Full 749-glyph icon catalogue (~1 MB of path data): fetched once, only
272
+ // when a spec names a glyph outside the 64 inlined in icon-data.ts.
273
+ assetConfig('icons', 'src/client/icons/asset-icons.ts'),
275
274
  ]
package/lib/invariant.js DELETED
@@ -1,19 +0,0 @@
1
- //#region src/plugin/invariant.ts
2
- const PACKAGE_NAME = "@changfenhuang/dsh-genui";
3
- /** Cordis companion plugin name. */
4
- const name = "genui-invariant";
5
- /** Service required before the companion can reserve package ownership. */
6
- const inject = ["invariants"];
7
- /**
8
- * No runtime invariant: this host plugin only registers a static prompt
9
- * section; the section text is pinned by its own tests.
10
- */
11
- const install = () => {};
12
- /**
13
- * Register this package's invariant companion.
14
- * @param ctx - Cordis context carrying the invariant service.
15
- * @returns the installed registration's disposer after setup succeeds.
16
- */
17
- const apply = (ctx) => Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install));
18
- //#endregion
19
- export { apply, inject, name };
@@ -1,15 +0,0 @@
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>;
@@ -1,30 +0,0 @@
1
- /**
2
- * Package-owned invariant companion for `@changfenhuang/dsh-genui`.
3
- * @module @changfenhuang/dsh-genui/invariant
4
- */
5
-
6
- /* jscpd:ignore-start */
7
- import type { Context } from '@deepseek-ai/cordis'
8
- import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
9
-
10
- const PACKAGE_NAME = '@changfenhuang/dsh-genui'
11
-
12
- /** Cordis companion plugin name. */
13
- export const name = 'genui-invariant'
14
- /** Service required before the companion can reserve package ownership. */
15
- export const inject = ['invariants']
16
-
17
- /**
18
- * No runtime invariant: this host plugin only registers a static prompt
19
- * section; the section text is pinned by its own tests.
20
- */
21
- const install: InvariantInstaller = () => {}
22
-
23
- /**
24
- * Register this package's invariant companion.
25
- * @param ctx - Cordis context carrying the invariant service.
26
- * @returns the installed registration's disposer after setup succeeds.
27
- */
28
- export const apply = (ctx: Context): Promise<() => void> =>
29
- Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
30
- /* jscpd:ignore-end */