@sparkelf/dsh-genui 0.11.4-patch.2 → 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.
- package/CHANGELOG.md +76 -0
- package/ICON-NAMES.md +30 -0
- package/README.md +26 -28
- package/README.zh-CN.md +26 -28
- package/SKILL.md +128 -19
- package/THIRD_PARTY_NOTICES.md +42 -0
- package/assets/genui-icon.svg +20 -0
- package/assets/genui-logo.svg +18 -0
- package/lib/assets/icons.js +1 -0
- package/lib/assets/mermaid.js +325 -325
- package/lib/assets/standalone-runtime.js +10 -9
- package/lib/client.js +32 -31
- package/lib/index.js +489 -80
- package/lib/types/client/action-context.d.ts +1 -1
- package/lib/types/client/artifact/types.d.ts +1 -1
- package/lib/types/client/asset-loader.d.ts +2 -2
- package/lib/types/client/blocks/blocks.d.ts +12 -0
- package/lib/types/client/blocks/icon.d.ts +4 -0
- package/lib/types/client/dom-fence.d.ts +2 -1
- package/lib/types/client/fence-render.d.ts +5 -21
- package/lib/types/client/file-address.d.ts +4 -0
- package/lib/types/client/file-link-context.d.ts +49 -0
- package/lib/types/client/file-link.d.ts +17 -0
- package/lib/types/client/gallery.d.ts +8 -2
- package/lib/types/client/genui-runtime/diagnostics.d.ts +1 -1
- package/lib/types/client/genui-runtime/limits.d.ts +4 -0
- package/lib/types/client/genui-runtime/schema.d.ts +14 -1
- package/lib/types/client/guard.d.ts +4 -1
- package/lib/types/client/i18n/en.d.ts +5 -1
- package/lib/types/client/i18n/index.d.ts +1 -1
- package/lib/types/client/icons/asset-icons.d.ts +1 -0
- package/lib/types/client/icons/icon-data-full.d.ts +23 -0
- package/lib/types/client/icons/icon-data.d.ts +24 -0
- package/lib/types/client/icons/icon-lazy.d.ts +18 -0
- package/lib/types/client/icons/icon-names-full.d.ts +12 -0
- package/lib/types/client/index.d.ts +5 -15
- package/lib/types/client/inline.d.ts +1 -1
- package/lib/types/client/mermaid-colors.d.ts +2 -0
- package/lib/types/client/mermaid-core.d.ts +2 -1
- package/lib/types/client/mermaid-lazy.d.ts +5 -1
- package/lib/types/client/panel-command.d.ts +21 -1
- package/lib/types/client/panel.d.ts +6 -1
- package/lib/types/client/primitive-adapter.d.ts +0 -2
- package/lib/types/client/session-resolver.d.ts +13 -2
- package/lib/types/client/source-fence.d.ts +1 -1
- package/lib/types/client/spec.d.ts +107 -3
- package/lib/types/client/standalone/asset-loader.d.ts +1 -1
- package/lib/types/client/standalone/primitive-adapter.d.ts +0 -4
- package/lib/types/plugin/fence-feedback.d.ts +11 -7
- package/lib/types/plugin/index.d.ts +6 -2
- package/lib/types/shared/fence-language.d.ts +14 -0
- package/lib/types/shared/fence-repair.d.ts +2 -1
- package/lib/types/shared/fence-resolve.d.ts +1 -1
- package/package.json +92 -83
- package/src/client/EChartNode.tsx +17 -3
- package/src/client/GenuiBlock.module.css +411 -76
- package/src/client/action-context.ts +5 -15
- package/src/client/artifact/ArtifactExport.module.css +34 -3
- package/src/client/artifact/ExportableGenuiBlock.tsx +23 -2
- package/src/client/artifact/portability.ts +6 -1
- package/src/client/artifact/types.ts +1 -1
- package/src/client/asset-loader.ts +3 -3
- package/src/client/blocks/advanced.tsx +101 -14
- package/src/client/blocks/blocks.tsx +143 -0
- package/src/client/blocks/charts.tsx +22 -6
- package/src/client/blocks/icon.tsx +93 -0
- package/src/client/blocks/image.tsx +1 -0
- package/src/client/blocks/render-node.tsx +84 -52
- package/src/client/dom-fence.tsx +546 -72
- package/src/client/fence-render.tsx +5 -21
- package/src/client/file-address.ts +37 -0
- package/src/client/file-link-context.tsx +116 -0
- package/src/client/file-link.ts +46 -0
- package/src/client/gallery.ts +161 -133
- package/src/client/genui-runtime/diagnostics.ts +1 -1
- package/src/client/genui-runtime/limits.ts +4 -0
- package/src/client/genui-runtime/normalize.ts +42 -6
- package/src/client/genui-runtime/schema.ts +39 -7
- package/src/client/guard.ts +170 -15
- package/src/client/i18n/en.ts +5 -1
- package/src/client/i18n/index.ts +1 -1
- package/src/client/i18n/zh.ts +5 -1
- package/src/client/icons/asset-icons.ts +16 -0
- package/src/client/icons/icon-data-full.ts +5715 -0
- package/src/client/icons/icon-data.ts +507 -0
- package/src/client/icons/icon-lazy.ts +80 -0
- package/src/client/icons/icon-names-full.ts +12 -0
- package/src/client/index.tsx +27 -51
- package/src/client/inline.ts +17 -6
- package/src/client/mermaid-colors.ts +40 -0
- package/src/client/mermaid-core.ts +69 -61
- package/src/client/mermaid-lazy.ts +99 -4
- package/src/client/panel-command.ts +16 -2
- package/src/client/panel.tsx +18 -5
- package/src/client/primitive-adapter.ts +0 -11
- package/src/client/session-resolver.ts +12 -21
- package/src/client/source-fence.ts +4 -2
- package/src/client/spec.ts +116 -2
- package/src/client/standalone/asset-loader.ts +1 -1
- package/src/client/standalone/primitive-adapter.tsx +1 -9
- package/src/client/table-details.ts +4 -3
- package/src/plugin/fence-feedback.ts +60 -14
- package/src/plugin/index.ts +45 -20
- package/src/plugin/tool.ts +11 -2
- package/src/shared/fence-language.ts +30 -0
- package/src/shared/fence-repair.ts +37 -1
- package/src/shared/fence-resolve.ts +1 -1
- package/tsdown.config.ts +7 -8
- package/lib/invariant.js +0 -19
- package/lib/types/plugin/invariant.d.ts +0 -15
- package/src/plugin/invariant.ts +0 -30
|
@@ -21,6 +21,14 @@ import type { GenuiSpec } from './spec.ts'
|
|
|
21
21
|
import { requestPanelExpand, setLocalPanel } from './panel-store.ts'
|
|
22
22
|
import { t } from './i18n/index.ts'
|
|
23
23
|
|
|
24
|
+
type PanelInputTriggerSource = InputTriggerSource & {
|
|
25
|
+
matchClaim: (
|
|
26
|
+
session: Parameters<InputTriggerSource['onPick']>[0]['session'],
|
|
27
|
+
token: string,
|
|
28
|
+
signal: AbortSignal,
|
|
29
|
+
) => Promise<ReturnType<typeof panelClaim> | undefined>
|
|
30
|
+
}
|
|
31
|
+
|
|
24
32
|
/**
|
|
25
33
|
* Default panel content published by `/panel`: the component overview.
|
|
26
34
|
*
|
|
@@ -108,8 +116,8 @@ function panelClaim(sessionId: SessionId, sendInstruction: (sessionId: SessionId
|
|
|
108
116
|
* works without opening the menu (leading-token adjudication), and it also
|
|
109
117
|
* catches `/panel clear` style args.
|
|
110
118
|
*/
|
|
111
|
-
export function createPanelSlashSource(sendInstruction: (sessionId: SessionId, instruction: string) => void):
|
|
112
|
-
|
|
119
|
+
export function createPanelSlashSource(sendInstruction: (sessionId: SessionId, instruction: string) => void): PanelInputTriggerSource {
|
|
120
|
+
const source: PanelInputTriggerSource = {
|
|
113
121
|
trigger: '/',
|
|
114
122
|
name: 'genui',
|
|
115
123
|
order: 60,
|
|
@@ -134,5 +142,11 @@ export function createPanelSlashSource(sendInstruction: (sessionId: SessionId, i
|
|
|
134
142
|
if (!/^\/panel(?:\s|$)/.test(line.trim())) return undefined
|
|
135
143
|
return { claim: panelClaim(session.sessionId, sendInstruction) }
|
|
136
144
|
},
|
|
145
|
+
matchClaim: async (session, token, signal) => {
|
|
146
|
+
signal.throwIfAborted()
|
|
147
|
+
if (token !== '/panel') return undefined
|
|
148
|
+
return panelClaim(session.sessionId, sendInstruction)
|
|
149
|
+
},
|
|
137
150
|
}
|
|
151
|
+
return source
|
|
138
152
|
}
|
package/src/client/panel.tsx
CHANGED
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
import { useCallback, useEffect, useRef, useState, useSyncExternalStore } from 'react'
|
|
27
27
|
import type {} from '@deepseek-ai/dsh-client-ui-session/client'
|
|
28
28
|
import { GenuiActionContext, type GenuiActionHandler } from './action-context.ts'
|
|
29
|
+
import { withFileLinkContext, type FileLinkAvailability, type FileLinkCordisContext } from './file-link-context.tsx'
|
|
29
30
|
import type { PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots'
|
|
30
31
|
import { ExportableGenuiBlock } from './artifact/ExportableGenuiBlock.tsx'
|
|
31
32
|
import { ErrorBoundary } from './ErrorBoundary.tsx'
|
|
@@ -50,6 +51,7 @@ import { recordPanel, recordTemplateUse } from './achievement-store.ts'
|
|
|
50
51
|
export interface GenuiPanelInjected {
|
|
51
52
|
sessionId: string
|
|
52
53
|
sendGenuiAction: GenuiActionHandler
|
|
54
|
+
fileLinkContext?: { ctx: FileLinkCordisContext; availability: FileLinkAvailability }
|
|
53
55
|
/** Template center "try it": insert the template instruction into the
|
|
54
56
|
* current composer draft (standard conversation.input.for channel). */
|
|
55
57
|
insertTemplate: (text: string) => void
|
|
@@ -63,7 +65,7 @@ export type GenuiPanelProps = PropsRuntime<'conversation.input.dock'> & GenuiPan
|
|
|
63
65
|
* default so the dock never steals the message flow's scroll room; the
|
|
64
66
|
* header always shows the current panel title.
|
|
65
67
|
*/
|
|
66
|
-
export function GenuiPanel({ sessionId, sendGenuiAction, insertTemplate }: GenuiPanelProps) {
|
|
68
|
+
export function GenuiPanel({ sessionId, sendGenuiAction, insertTemplate, fileLinkContext }: GenuiPanelProps) {
|
|
67
69
|
const t = useT()
|
|
68
70
|
const spec = useSyncExternalStore(subscribePanel, () => getPanelSpec(sessionId))
|
|
69
71
|
const expandToken = useSyncExternalStore(subscribePanelExpand, () => getPanelExpandToken(sessionId))
|
|
@@ -271,10 +273,21 @@ export function GenuiPanel({ sessionId, sendGenuiAction, insertTemplate }: Genui
|
|
|
271
273
|
/>
|
|
272
274
|
) : spec !== null ? (
|
|
273
275
|
<GenuiActionContext.Provider value={sendGenuiAction}>
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
276
|
+
{fileLinkContext === undefined
|
|
277
|
+
? <ErrorBoundary label={t('panel.boundary')}>
|
|
278
|
+
{/* content-fingerprinted: same panel spec re-published restores its state */}
|
|
279
|
+
<ExportableGenuiBlock spec={spec} stateKey={panelStateKey(sessionId, JSON.stringify(spec))} />
|
|
280
|
+
</ErrorBoundary>
|
|
281
|
+
: withFileLinkContext(
|
|
282
|
+
fileLinkContext.ctx,
|
|
283
|
+
fileLinkContext.availability,
|
|
284
|
+
sessionId,
|
|
285
|
+
false,
|
|
286
|
+
<ErrorBoundary label={t('panel.boundary')}>
|
|
287
|
+
{/* content-fingerprinted: same panel spec re-published restores its state */}
|
|
288
|
+
<ExportableGenuiBlock spec={spec} stateKey={panelStateKey(sessionId, JSON.stringify(spec))} />
|
|
289
|
+
</ErrorBoundary>,
|
|
290
|
+
)}
|
|
278
291
|
</GenuiActionContext.Provider>
|
|
279
292
|
) : null}
|
|
280
293
|
</div>
|
|
@@ -1,13 +1,2 @@
|
|
|
1
|
-
import * as primitives from '@deepseek-ai/dsh-client-ui-primitives'
|
|
2
|
-
|
|
3
1
|
export { CodeBlock, DiffBlock, JsonTree, writeClipboard } from '@deepseek-ai/dsh-client-ui-primitives'
|
|
4
2
|
export type { DiffBlockLabels, JsonTreeLabels } from '@deepseek-ai/dsh-client-ui-primitives'
|
|
5
|
-
|
|
6
|
-
type HostGenuiExtensions = {
|
|
7
|
-
getGenuiComponent?: (type: string) => unknown
|
|
8
|
-
GenuiActionContext?: typeof primitives extends { GenuiActionContext: infer T } ? T : unknown
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const hostExtensions = primitives as unknown as HostGenuiExtensions
|
|
12
|
-
export const getGenuiComponent = hostExtensions.getGenuiComponent
|
|
13
|
-
export const GenuiActionContext = hostExtensions.GenuiActionContext
|
|
@@ -1,33 +1,24 @@
|
|
|
1
1
|
import type { SessionId } from '@deepseek-ai/dsh-session/types'
|
|
2
|
+
import type { SessionListState } from '@deepseek-ai/dsh-api-session-controller/client'
|
|
2
3
|
|
|
3
|
-
interface
|
|
4
|
-
|
|
5
|
-
retainedBy?: unknown
|
|
4
|
+
interface SessionRetainSnapshot {
|
|
5
|
+
retainedBy: { mainView?: number }
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
interface
|
|
9
|
-
|
|
10
|
-
byId?: unknown
|
|
8
|
+
interface SessionRetainInfo {
|
|
9
|
+
getSnapshot(): SessionRetainSnapshot
|
|
11
10
|
}
|
|
12
11
|
|
|
13
12
|
/**
|
|
14
13
|
* 从宿主会话列表快照中解析当前主视图会话。
|
|
15
14
|
*
|
|
16
15
|
* @param list - 宿主提供的会话列表快照
|
|
17
|
-
* @
|
|
16
|
+
* @param retainInfo - 按会话标识读取的引用来源快照
|
|
17
|
+
* @returns 当前主视图会话标识;没有主视图引用时返回 undefined
|
|
18
18
|
*/
|
|
19
|
-
export function resolveViewedSessionId(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const viewed = Object.values(snapshot.byId as Record<string, unknown>).find((entry): entry is SessionListEntry => {
|
|
26
|
-
if (typeof entry !== 'object' || entry === null) return false
|
|
27
|
-
const retainedBy = (entry as SessionListEntry).retainedBy
|
|
28
|
-
if (typeof retainedBy !== 'object' || retainedBy === null || Array.isArray(retainedBy)) return false
|
|
29
|
-
const mainView = (retainedBy as { mainView?: unknown }).mainView
|
|
30
|
-
return typeof mainView === 'number' && mainView > 0
|
|
31
|
-
})
|
|
32
|
-
return typeof viewed?.id === 'string' ? viewed.id as SessionId : undefined
|
|
19
|
+
export function resolveViewedSessionId(
|
|
20
|
+
list: Pick<SessionListState, 'ids'>,
|
|
21
|
+
retainInfo: (sessionId: SessionId) => SessionRetainInfo,
|
|
22
|
+
): SessionId | undefined {
|
|
23
|
+
return list.ids.find(sessionId => (retainInfo(sessionId).getSnapshot().retainedBy.mainView ?? 0) > 0)
|
|
33
24
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { fromMarkdown } from 'mdast-util-from-markdown'
|
|
2
2
|
import type { AssistantBlock, ChatNode, ChatSnapshot } from '@deepseek-ai/dsh-client-ui-chat/client'
|
|
3
|
+
import { normalizeFenceLanguage } from '../shared/fence-language.ts'
|
|
3
4
|
|
|
4
5
|
export interface SourceFence {
|
|
5
6
|
lang: string | null
|
|
@@ -27,8 +28,9 @@ export function sourceFencesOf(markdown: string): SourceFence[] {
|
|
|
27
28
|
if (node.type === 'code') {
|
|
28
29
|
const openingOffset = node.position?.start.offset
|
|
29
30
|
const openingLineEnd = openingOffset === undefined ? -1 : markdown.indexOf('\n', openingOffset)
|
|
31
|
+
const rawLang = node.lang ?? null
|
|
30
32
|
fences.push({
|
|
31
|
-
lang:
|
|
33
|
+
lang: rawLang === null ? null : normalizeFenceLanguage(rawLang),
|
|
32
34
|
value: node.value as string,
|
|
33
35
|
openingLineComplete: openingLineEnd >= 0,
|
|
34
36
|
})
|
|
@@ -59,7 +61,7 @@ export function sourceFencesOfAssistant(blocks: readonly AssistantBlock[]): Sour
|
|
|
59
61
|
* @param chat - 当前会话的 ChatSnapshot
|
|
60
62
|
* @param nodeKey - DOM assistant row 对应的 Chat node key
|
|
61
63
|
* @param index - assistant row 内从零开始的宿主代码块序号
|
|
62
|
-
* @returns
|
|
64
|
+
* @returns 规范化后的 language;null 表示围栏没有 language,undefined 表示 source 不可用
|
|
63
65
|
*/
|
|
64
66
|
export function sourceLanguageAt(chat: ChatSnapshot | undefined, nodeKey: string, index: number): string | null | undefined {
|
|
65
67
|
const node = chat?.nodes.get(nodeKey)
|
package/src/client/spec.ts
CHANGED
|
@@ -64,6 +64,9 @@ export type GenuiNode = (
|
|
|
64
64
|
| GenuiBreadcrumb
|
|
65
65
|
| GenuiQuiz
|
|
66
66
|
| GenuiDiagram
|
|
67
|
+
| GenuiIcon
|
|
68
|
+
| GenuiBlocks
|
|
69
|
+
| GenuiArrow
|
|
67
70
|
) & GenuiLayoutHints
|
|
68
71
|
|
|
69
72
|
| GenuiEChart
|
|
@@ -93,9 +96,16 @@ export interface GenuiSpec {
|
|
|
93
96
|
|
|
94
97
|
export interface GenuiText {
|
|
95
98
|
type: 'text'
|
|
96
|
-
size?: 'h1' | 'h2' | 'h3' | 'body' | 'muted' | 'caption'
|
|
99
|
+
size?: 'display' | 'h1' | 'h2' | 'h3' | 'body' | 'muted' | 'caption'
|
|
97
100
|
content: string
|
|
101
|
+
/** Legacy boolean shorthand; `align: 'center'` is the canonical form. */
|
|
98
102
|
center?: boolean
|
|
103
|
+
/** Semantic colour for the run (danger renders red without a badge). */
|
|
104
|
+
tone?: 'danger' | 'success' | 'warning' | 'info' | 'muted'
|
|
105
|
+
/** Monospace run — hex, binary, identifiers — without the inline-code pill. */
|
|
106
|
+
mono?: boolean
|
|
107
|
+
/** Horizontal alignment; `center?: true` normalizes to `align: 'center'`. */
|
|
108
|
+
align?: 'left' | 'center' | 'right'
|
|
99
109
|
}
|
|
100
110
|
|
|
101
111
|
export interface GenuiButton {
|
|
@@ -172,8 +182,10 @@ export interface GenuiLink {
|
|
|
172
182
|
export interface GenuiImage {
|
|
173
183
|
type: 'image'
|
|
174
184
|
src: string
|
|
175
|
-
/** Visible
|
|
185
|
+
/** Visible label line above the image and accessible description. */
|
|
176
186
|
alt?: string
|
|
187
|
+
/** Caption line below the image (source, reading, credit). */
|
|
188
|
+
caption?: string
|
|
177
189
|
}
|
|
178
190
|
|
|
179
191
|
/** User-controlled audio from a browser-reachable URL. */
|
|
@@ -243,6 +255,8 @@ export interface GenuiProgress {
|
|
|
243
255
|
|
|
244
256
|
export interface GenuiDivider {
|
|
245
257
|
type: 'divider'
|
|
258
|
+
/** Chapter separator: hairline + centered meta label (anthology program). */
|
|
259
|
+
label?: string
|
|
246
260
|
}
|
|
247
261
|
|
|
248
262
|
export interface GenuiAvatar {
|
|
@@ -255,6 +269,96 @@ export interface GenuiSpacer {
|
|
|
255
269
|
type: 'spacer'
|
|
256
270
|
}
|
|
257
271
|
|
|
272
|
+
/* ---------------- v12: figure primitives ---------------- */
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* `arrow`: a thin connector between two blocks of a figure.
|
|
276
|
+
*
|
|
277
|
+
* The text glyph `↓` was the only way to draw a flow before this: it sits on
|
|
278
|
+
* the text baseline, inherits body size, and cannot hold a fixed gap. This node
|
|
279
|
+
* draws a hairline with a chevron head at a fixed length, so a vertical flow
|
|
280
|
+
* reads as a diagram instead of a paragraph.
|
|
281
|
+
*/
|
|
282
|
+
export interface GenuiArrow {
|
|
283
|
+
type: 'arrow'
|
|
284
|
+
dir?: 'down' | 'right'
|
|
285
|
+
/** Shaft length in px (16-96). Defaults to 26 (down) / 32 (right). */
|
|
286
|
+
length?: number
|
|
287
|
+
/** Optional caption beside/under the arrow. */
|
|
288
|
+
label?: string
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/** One glyph from the bundled (curated) icon catalogue. */
|
|
292
|
+
export interface GenuiIcon {
|
|
293
|
+
type: 'icon'
|
|
294
|
+
/** Canonical catalogue name, e.g. `Nodes`. See ICON_NAMES / SKILL.md. */
|
|
295
|
+
name: string
|
|
296
|
+
/** Accessible name. Omit when the icon is decorative beside a visible label. */
|
|
297
|
+
label?: string
|
|
298
|
+
tone?: 'default' | 'muted' | 'info' | 'success' | 'warning' | 'danger'
|
|
299
|
+
/** Optical size in px; the renderer clamps to the nearest of 16/20/24/32. */
|
|
300
|
+
size?: number
|
|
301
|
+
/** Tinted rounded-square plate (figure / stage-card use). */
|
|
302
|
+
tile?: boolean
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* One cell of a `blocks` row.
|
|
307
|
+
*
|
|
308
|
+
* A bare string is the common case (a label in a filled cell). The object form
|
|
309
|
+
* exists for figures that mark ONE cell out of many — a bit grid where the
|
|
310
|
+
* sign bit is highlighted, a lane where the current step is active — and for
|
|
311
|
+
* the small caption that hangs under a cell (`1` with `SF` beneath it).
|
|
312
|
+
*/
|
|
313
|
+
export type GenuiBlockCell = string | null | {
|
|
314
|
+
text: string
|
|
315
|
+
/** Per-cell fill (hex); overrides the row colour. */
|
|
316
|
+
color?: string
|
|
317
|
+
/** Per-cell semantic emphasis when no explicit hex is wanted. */
|
|
318
|
+
tone?: 'accent' | 'success' | 'warning' | 'danger' | 'muted'
|
|
319
|
+
/** Small caption under the cell (bit name, index, role…). */
|
|
320
|
+
sub?: string
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/** One row of a `blocks` figure: a label plus its cells. */
|
|
324
|
+
export interface GenuiBlocksRow {
|
|
325
|
+
/** Row label rendered to the left of the cells. */
|
|
326
|
+
label?: string
|
|
327
|
+
/** Cells, left to right. `null` renders a blank (unpainted) slot; use the
|
|
328
|
+
* string `"—"` when a visible dash is wanted. */
|
|
329
|
+
cells: GenuiBlockCell[]
|
|
330
|
+
/** Fill for this row's cells (hex). Falls back to the accent wash. */
|
|
331
|
+
color?: string
|
|
332
|
+
/**
|
|
333
|
+
* `fill` (default) paints every cell with the row colour.
|
|
334
|
+
* `outline` leaves cells unfilled with a hairline border — matrices where
|
|
335
|
+
* every cell is a box. `plain` removes the box entirely (a bit string like
|
|
336
|
+
* `1 0 1 0 0 0 0 0` reads as digits, not as a table), so only a cell with an
|
|
337
|
+
* explicit `tone`/`color` draws a surface.
|
|
338
|
+
*/
|
|
339
|
+
variant?: 'fill' | 'outline' | 'plain'
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* `blocks`: the declarative replacement for hand-written SVG block diagrams —
|
|
344
|
+
* a grid of filled cells grouped into labelled rows.
|
|
345
|
+
*
|
|
346
|
+
* Covers the three shapes models kept reaching for SVG to draw: a recursion /
|
|
347
|
+
* hierarchy ladder (each row divides its own width, 8 → 4 → 2 → 1), an equal
|
|
348
|
+
* row of parts (4 × "块 0"), and a lane/timeline grid (`columns` fixes the
|
|
349
|
+
* shared column count, `null` cells leave gaps).
|
|
350
|
+
*/
|
|
351
|
+
export interface GenuiBlocks {
|
|
352
|
+
type: 'blocks'
|
|
353
|
+
rows: GenuiBlocksRow[]
|
|
354
|
+
/** Fixed column count shared by every row. Omit to let each row divide its
|
|
355
|
+
* own width equally. */
|
|
356
|
+
columns?: number
|
|
357
|
+
/** Figure caption rendered under the cells (the "每格代表…" line). */
|
|
358
|
+
caption?: string
|
|
359
|
+
title?: string
|
|
360
|
+
}
|
|
361
|
+
|
|
258
362
|
/* ---------------- container nodes ---------------- */
|
|
259
363
|
|
|
260
364
|
export interface GenuiRow {
|
|
@@ -262,12 +366,17 @@ export interface GenuiRow {
|
|
|
262
366
|
items: GenuiNode[]
|
|
263
367
|
wrap?: boolean
|
|
264
368
|
spacer?: boolean
|
|
369
|
+
/** Main-axis alignment. `center` is what figure headers need (icon + title
|
|
370
|
+
* stacked over a caption); the default stays `start`. */
|
|
371
|
+
justify?: 'start' | 'center' | 'end' | 'between'
|
|
265
372
|
}
|
|
266
373
|
|
|
267
374
|
export interface GenuiCol {
|
|
268
375
|
type: 'col'
|
|
269
376
|
items: GenuiNode[]
|
|
270
377
|
gap?: number
|
|
378
|
+
/** Width as a percentage of the row (1-100). Omit to size by content. */
|
|
379
|
+
width?: number
|
|
271
380
|
}
|
|
272
381
|
|
|
273
382
|
export interface GenuiGrid {
|
|
@@ -279,10 +388,15 @@ export interface GenuiGrid {
|
|
|
279
388
|
export interface GenuiCard {
|
|
280
389
|
type: 'card'
|
|
281
390
|
title?: string
|
|
391
|
+
/** Meta overline above the title (chaptering for card groups; use sparingly). */
|
|
392
|
+
eyebrow?: string
|
|
282
393
|
/** Semantic tint for the card surface (default: neutral). */
|
|
283
394
|
tone?: 'info' | 'success' | 'warning' | 'danger'
|
|
284
395
|
/** Explicit accent (hex) driving the border, title and wash. */
|
|
285
396
|
accent?: string
|
|
397
|
+
/** Drop the elevation and use a faint neutral fill: figure panels read as
|
|
398
|
+
* printed blocks instead of floating cards. */
|
|
399
|
+
flat?: boolean
|
|
286
400
|
items: GenuiNode[]
|
|
287
401
|
}
|
|
288
402
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
type StandaloneAssets = { __GenuiAssets__?: Record<string, unknown> }
|
|
2
2
|
|
|
3
3
|
/** 从启动代码预先载入的全局资源读取引擎。 */
|
|
4
|
-
export function loadGenuiAsset<T>(name: 'mermaid' | 'three' | 'echarts-core' | 'echarts-full'): Promise<T> {
|
|
4
|
+
export function loadGenuiAsset<T>(name: 'mermaid' | 'three' | 'echarts-core' | 'echarts-full' | 'icons'): Promise<T> {
|
|
5
5
|
const key = name.replace(/-(\w)/g, (_match, character: string) => character.toUpperCase())
|
|
6
6
|
const asset = (window as unknown as StandaloneAssets).__GenuiAssets__?.[key]
|
|
7
7
|
if (asset === undefined) return Promise.reject(new Error(`standalone asset '${name}' was not preloaded`))
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useState, type CSSProperties, type ReactNode } from 'react'
|
|
2
2
|
import { t } from '../i18n/index.ts'
|
|
3
3
|
|
|
4
4
|
export interface DiffBlockLabels {
|
|
@@ -84,11 +84,3 @@ export async function writeClipboard(text: string): Promise<boolean> {
|
|
|
84
84
|
textarea.remove()
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
|
-
|
|
88
|
-
/** standalone 模式不连接 DSH 注册表,因此自定义组件始终不可用。 */
|
|
89
|
-
export function getGenuiComponent(_type: string): undefined {
|
|
90
|
-
return undefined
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/** standalone 模式专用的空动作上下文。 */
|
|
94
|
-
export const GenuiActionContext = createContext<((action: string, payload: Record<string, unknown>) => void) | undefined>(undefined)
|
|
@@ -82,7 +82,8 @@ function repairColumnValues(value: unknown): string[] {
|
|
|
82
82
|
const label = typeof column.label === 'string' ? column.label
|
|
83
83
|
: typeof column.value === 'string' ? column.value
|
|
84
84
|
: typeof column.title === 'string' ? column.title
|
|
85
|
-
:
|
|
85
|
+
: typeof column.name === 'string' && column.name !== '' ? column.name
|
|
86
|
+
: JSON.stringify(item)
|
|
86
87
|
columns.push(label.slice(0, 128))
|
|
87
88
|
}
|
|
88
89
|
}
|
|
@@ -126,7 +127,7 @@ function deriveTableColumns(rows: Array<Array<string | number>>): PreparedTableR
|
|
|
126
127
|
function columnKeyOf(value: unknown): string | undefined {
|
|
127
128
|
if (value === null || typeof value !== 'object' || Array.isArray(value)) return undefined
|
|
128
129
|
const column = value as Record<string, unknown>
|
|
129
|
-
for (const key of ['key', 'dataIndex', 'title', 'label'] as const) {
|
|
130
|
+
for (const key of ['key', 'dataIndex', 'title', 'label', 'name'] as const) {
|
|
130
131
|
if (typeof column[key] === 'string' && column[key] !== '') return column[key]
|
|
131
132
|
}
|
|
132
133
|
return undefined
|
|
@@ -144,7 +145,7 @@ function cellText(value: unknown): string | number {
|
|
|
144
145
|
function columnHeaderText(value: unknown): string {
|
|
145
146
|
if (value === null || typeof value !== 'object' || Array.isArray(value)) return String(value)
|
|
146
147
|
const column = value as Record<string, unknown>
|
|
147
|
-
for (const key of ['title', 'label', 'key', 'dataIndex'] as const) {
|
|
148
|
+
for (const key of ['title', 'label', 'key', 'dataIndex', 'name'] as const) {
|
|
148
149
|
if (typeof column[key] === 'string' && column[key] !== '') return column[key]
|
|
149
150
|
}
|
|
150
151
|
return JSON.stringify(value)
|
|
@@ -13,9 +13,9 @@
|
|
|
13
13
|
* - **仅含 reasoning 的恢复。** 已验证的 GenUI 回合若只以 reasoning block 结束,使用宿主的
|
|
14
14
|
* `EMPTY_RESPONSE` retry policy。
|
|
15
15
|
* - **Never for subagents.** A child session's fence belongs to a parent reply.
|
|
16
|
-
* - **
|
|
17
|
-
*
|
|
18
|
-
* never rewritten.
|
|
16
|
+
* - **Shared fence matching.** GenUI labels use the renderer's case/punctuation
|
|
17
|
+
* normalization. Unrelated labels such as ` ```dsh-ui-dark `, indented prose,
|
|
18
|
+
* and mentions of the name are never rewritten.
|
|
19
19
|
* - **Accounted before sending.** The fingerprint is recorded before `steer`,
|
|
20
20
|
* so a re-entrant boundary cannot deliver the same correction twice.
|
|
21
21
|
* - **Cancellation-aware.** An aborted turn or a missing session is left alone.
|
|
@@ -32,9 +32,10 @@ import type { Session, SessionEvent, SessionStore, UserMessage } from '@deepseek
|
|
|
32
32
|
import { createHash, randomUUID } from 'node:crypto'
|
|
33
33
|
import { droppedNodeFailure } from './genui-diagnostic.ts'
|
|
34
34
|
import { resolveFence } from '../shared/fence-resolve.ts'
|
|
35
|
+
import { isGenuiFenceLanguage } from '../shared/fence-language.ts'
|
|
35
36
|
|
|
36
37
|
/** Plugin name recorded on every message this loop steers. */
|
|
37
|
-
export const FEEDBACK_PLUGIN_NAME = '@
|
|
38
|
+
export const FEEDBACK_PLUGIN_NAME = '@sparkelf/dsh-genui'
|
|
38
39
|
/** Source kind persisted by this plugin in Session format v4. */
|
|
39
40
|
export const FEEDBACK_SOURCE_KIND = `plugin:${FEEDBACK_PLUGIN_NAME}` as const
|
|
40
41
|
|
|
@@ -49,8 +50,8 @@ export const MAX_CORRECTIONS_PER_TURN = 2
|
|
|
49
50
|
/** Marker prefix written by older plugin versions. */
|
|
50
51
|
const LEGACY_MARKER_PREFIX = '[genui 自修 #'
|
|
51
52
|
|
|
52
|
-
/**
|
|
53
|
-
const FENCE_OPEN = /^ {0,3}```[ \t]*
|
|
53
|
+
/** Read one language token (≤3 spaces indent); backticks are invalid in a backtick info string. */
|
|
54
|
+
const FENCE_OPEN = /^ {0,3}```[ \t]*([^` \t]+)[ \t]*$/u
|
|
54
55
|
/** Any fence closer (the renderer never nests fences in one body). */
|
|
55
56
|
const FENCE_CLOSE = /^ {0,3}```[ \t]*$/u
|
|
56
57
|
/** Upper bound on fences inspected per reply — a reply is text, not a corpus. */
|
|
@@ -79,7 +80,8 @@ export function extractDshUiFences(text: string): ExtractedFence[] {
|
|
|
79
80
|
for (let line = 0; line < lines.length; line++) {
|
|
80
81
|
const current = lines[line] ?? ''
|
|
81
82
|
if (open === null) {
|
|
82
|
-
|
|
83
|
+
const label = FENCE_OPEN.exec(current)?.[1]
|
|
84
|
+
if (isGenuiFenceLanguage(label)) open = { start: line + 1, index: fences.length + 1 }
|
|
83
85
|
continue
|
|
84
86
|
}
|
|
85
87
|
if (!FENCE_CLOSE.test(current)) continue
|
|
@@ -123,9 +125,10 @@ export function fenceFailures(text: string): FenceFailure[] {
|
|
|
123
125
|
|
|
124
126
|
/** `null` when this fence renders; otherwise the reason it does not. */
|
|
125
127
|
function fenceFailureDetail(fence: ExtractedFence): string | null {
|
|
126
|
-
if (!fence.closed) return 'error=unterminated_fence\nrequired=closing_fence'
|
|
127
128
|
const resolution = resolveFence(fence.raw, { settled: true })
|
|
128
129
|
if (resolution.spec !== null) return null
|
|
130
|
+
// 缺少 Markdown 收尾不等于渲染失败;先复用 renderer 判断,避免把已显示的卡片重发(#288)。
|
|
131
|
+
if (!fence.closed) return 'error=unterminated_fence\nrequired=closing_fence'
|
|
129
132
|
if (resolution.processed !== null) {
|
|
130
133
|
const dropped = droppedNodeFailure(resolution.processed, resolution.value)
|
|
131
134
|
return dropped?.join('\n')
|
|
@@ -243,6 +246,8 @@ export interface FenceFeedbackPlanInput {
|
|
|
243
246
|
readonly correctionsThisTurn?: number | undefined
|
|
244
247
|
/** Turn {@link correctionsThisTurn} counts (stale counts are ignored). */
|
|
245
248
|
readonly correctionsTurn?: number | undefined
|
|
249
|
+
/** Whether the host has registered the `render_ui` tool. Defaults to enabled. */
|
|
250
|
+
readonly renderUiToolEnabled?: boolean | undefined
|
|
246
251
|
}
|
|
247
252
|
|
|
248
253
|
/** A correction the caller must account for before steering. */
|
|
@@ -289,7 +294,12 @@ export function planFenceFeedback(input: FenceFeedbackPlanInput): FenceFeedbackP
|
|
|
289
294
|
// then delivered nothing, remind the model once for this turn.
|
|
290
295
|
if (input.validatedThisTurn !== true || input.deliveredThisTurn === true) return null
|
|
291
296
|
if (input.deliveryRemindedTurns?.has(input.turn) === true) return null
|
|
292
|
-
return {
|
|
297
|
+
return {
|
|
298
|
+
text: missingBodyCorrectionText(input.turn, used + 1, input.renderUiToolEnabled ?? true),
|
|
299
|
+
fingerprints: [],
|
|
300
|
+
turn: input.turn,
|
|
301
|
+
kind: 'delivery',
|
|
302
|
+
}
|
|
293
303
|
}
|
|
294
304
|
|
|
295
305
|
/**
|
|
@@ -298,24 +308,35 @@ export function planFenceFeedback(input: FenceFeedbackPlanInput): FenceFeedbackP
|
|
|
298
308
|
*
|
|
299
309
|
* @param turn - turn that reached the boundary.
|
|
300
310
|
* @param attempt - correction number within the shared turn budget.
|
|
311
|
+
* @param renderUiToolEnabled - whether the correction may recommend `render_ui`.
|
|
301
312
|
* @returns the message text to steer into the running turn.
|
|
302
313
|
*/
|
|
303
|
-
export function missingBodyCorrectionText(turn: number, attempt = 1): string {
|
|
314
|
+
export function missingBodyCorrectionText(turn: number, attempt = 1, renderUiToolEnabled = true): string {
|
|
304
315
|
const head = `${MARKER_PREFIX}turn-${turn}]\n\n[genui-fence-repair]\nstatus=nothing_delivered\nfences=0\nnext=emit_fence_in_body\nrepeat_rendered_content=false\nreply_language=conversation\n\n`
|
|
305
316
|
const emphasis = attempt <= 1 ? '' : `(第 ${attempt} 次提醒)`
|
|
306
|
-
|
|
317
|
+
const renderUiInstruction = renderUiToolEnabled ? ',或明确调用 render_ui' : ''
|
|
318
|
+
return `${head}本轮尚未产生正式回答,也没有通过支持的通道交付结果${emphasis}。请根据用户当前请求完成正式答复;需要 UI 时,在回答正文输出你最终选定的 dsh-ui 围栏${renderUiInstruction}。可以修改或放弃此前候选;不能完成时,请在正文说明原因。\n`
|
|
307
319
|
}
|
|
308
320
|
|
|
309
321
|
/**
|
|
310
322
|
* 将 GenUI 回合中仅含 reasoning 的完整响应转换为宿主已有的可重试空响应错误。
|
|
311
323
|
*
|
|
324
|
+
* 只有回合边界确实还能发送交付提醒时,才放行原始 stop,
|
|
325
|
+
* 让回合正常结束并走到 `agent/turn-stopping` 边界——那里会 steer 一条交付提醒,
|
|
326
|
+
* 回合因此继续到下一个 step,模型有机会在同一回合把内容补进正文。
|
|
327
|
+
* 提醒发过仍然只有 reasoning,才用 EMPTY_RESPONSE 交给宿主重试兜底。
|
|
328
|
+
*
|
|
312
329
|
* @param options - LLM stream waterfall 拦截的请求。
|
|
313
330
|
* @param source - 本次请求的 provider stream。
|
|
314
|
-
* @
|
|
331
|
+
* @param state - 当前回合状态;缺省时没有可用提醒,保留宿主重试。
|
|
332
|
+
* @param feedbackEnabled - 同回合修正是否启用。关闭时没有提醒可用,保持原有改写行为。
|
|
333
|
+
* @returns 原始 stream;仅在提醒已发出、或提醒不可用时改写 reasoning-only 终止。
|
|
315
334
|
*/
|
|
316
335
|
async function* retryReasoningOnlyGenuiStream(
|
|
317
336
|
options: GenerateOptions,
|
|
318
337
|
source: AsyncIterable<StreamChunk>,
|
|
338
|
+
state?: SessionFeedback,
|
|
339
|
+
feedbackEnabled = true,
|
|
319
340
|
): AsyncGenerator<StreamChunk> {
|
|
320
341
|
const { EMPTY_RESPONSE_CODE, isAgentLoopRequest } = await import('@deepseek-ai/dsh-llm')
|
|
321
342
|
if (!isAgentLoopRequest(options)) {
|
|
@@ -331,6 +352,29 @@ async function* retryReasoningOnlyGenuiStream(
|
|
|
331
352
|
else hasOtherBlock = true
|
|
332
353
|
}
|
|
333
354
|
if (chunk.type === 'finish' && chunk.reason.kind === 'stop' && hasReasoningBlock && !hasOtherBlock) {
|
|
355
|
+
// Reuse the boundary's decision: an unused reminder is not necessarily
|
|
356
|
+
// available (for example, a previous broken fence counts as body delivery).
|
|
357
|
+
// This response has no body, so its assistant/message will clear text;
|
|
358
|
+
// do not plan against the previous step's fence before that event arrives.
|
|
359
|
+
const reminderAvailable = feedbackEnabled
|
|
360
|
+
&& state !== undefined
|
|
361
|
+
&& state.currentTurn !== undefined
|
|
362
|
+
&& state.pendingRenders.size === 0
|
|
363
|
+
&& planFenceFeedback({
|
|
364
|
+
text: '',
|
|
365
|
+
turn: state.currentTurn,
|
|
366
|
+
correctedSpec: state.correctedSpec,
|
|
367
|
+
deliveryRemindedTurns: state.deliveryRemindedTurns,
|
|
368
|
+
validatedThisTurn: state.validatedThisTurn,
|
|
369
|
+
deliveredThisTurn: state.deliveredThisTurn,
|
|
370
|
+
aborted: options.signal?.aborted ?? false,
|
|
371
|
+
correctionsThisTurn: state.correctionsThisTurn,
|
|
372
|
+
correctionsTurn: state.correctionsTurn,
|
|
373
|
+
})?.kind === 'delivery'
|
|
374
|
+
if (reminderAvailable) {
|
|
375
|
+
yield chunk
|
|
376
|
+
continue
|
|
377
|
+
}
|
|
334
378
|
yield {
|
|
335
379
|
type: 'finish',
|
|
336
380
|
reason: {
|
|
@@ -471,8 +515,9 @@ function isFeedbackSource(source: { kind?: unknown; plugin?: unknown } | undefin
|
|
|
471
515
|
*
|
|
472
516
|
* @param ctx - 宿主 Context。
|
|
473
517
|
* @param enabled - 是否启用同回合围栏修正。
|
|
518
|
+
* @param renderUiToolEnabled - 是否已注册 `render_ui` 工具。
|
|
474
519
|
*/
|
|
475
|
-
export function installFenceFeedback(ctx: Context, enabled: boolean): void {
|
|
520
|
+
export function installFenceFeedback(ctx: Context, enabled: boolean, renderUiToolEnabled = true): void {
|
|
476
521
|
const sessions = new Map<string, SessionFeedback>()
|
|
477
522
|
const stateOf = (sessionId: string): SessionFeedback => {
|
|
478
523
|
let state = sessions.get(sessionId)
|
|
@@ -611,7 +656,7 @@ export function installFenceFeedback(ctx: Context, enabled: boolean): void {
|
|
|
611
656
|
if (options.sessionId === undefined || options.purpose !== undefined) return next()
|
|
612
657
|
const state = sessions.get(String(options.sessionId))
|
|
613
658
|
if (state?.validatedThisTurn !== true || state.isSubagent) return next()
|
|
614
|
-
return retryReasoningOnlyGenuiStream(options, next())
|
|
659
|
+
return retryReasoningOnlyGenuiStream(options, next(), state, enabled)
|
|
615
660
|
}, { global: true })
|
|
616
661
|
|
|
617
662
|
ctx.on('agent/turn-stopping', ({ agent, turn, signal }): void => {
|
|
@@ -637,6 +682,7 @@ export function installFenceFeedback(ctx: Context, enabled: boolean): void {
|
|
|
637
682
|
aborted: signal.aborted,
|
|
638
683
|
correctionsThisTurn: usedThisTurn,
|
|
639
684
|
correctionsTurn: state.correctionsTurn,
|
|
685
|
+
renderUiToolEnabled,
|
|
640
686
|
})
|
|
641
687
|
if (plan === null) return
|
|
642
688
|
// Account BEFORE sending: a re-entrant boundary must not deliver twice.
|