@sparkelf/dsh-genui 0.0.0-stage → 0.11.4-patch.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 +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,287 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session GenUI panel: the dock surface that renders the latest `render_ui`
|
|
3
|
+
* spec IN PLACE. The toolview publishes every new result into the panel
|
|
4
|
+
* store; this component subscribes and re-renders the same block, so a
|
|
5
|
+
* refresh (model calls render_ui again) updates the panel instead of the
|
|
6
|
+
* message flow accumulating new UI per round.
|
|
7
|
+
*
|
|
8
|
+
* Mounted through the 'conversation.input.dock' list slot (TodoDock posture)
|
|
9
|
+
* — a session-scoped, always-present seat above the composer — so the panel
|
|
10
|
+
* coexists with the message flow on one screen. Absent spec = no panel.
|
|
11
|
+
*
|
|
12
|
+
* The dock is COLLAPSIBLE (TodoDock pattern), defaulting to a one-line
|
|
13
|
+
* header: a tall always-open panel pins above the composer and crushes the
|
|
14
|
+
* message flow's visible area, making history feel unreachable. Collapsed,
|
|
15
|
+
* it takes a single row; expanded, the body caps its height and scrolls
|
|
16
|
+
* internally, so the conversation stays scrollable either way.
|
|
17
|
+
*
|
|
18
|
+
* The expanded body is vertically RESIZABLE: a drag strip between the header
|
|
19
|
+
* and the body adjusts the body height (clamped to sane bounds); the custom
|
|
20
|
+
* height survives expand/collapse cycles for the session's life.
|
|
21
|
+
*
|
|
22
|
+
* Actions ride the same GenuiActionContext contract as inline fences: the
|
|
23
|
+
* sendGenuiAction injection (built from the scoped conversation service in
|
|
24
|
+
* apply) queues a [genui-action] user message back to the model.
|
|
25
|
+
*/
|
|
26
|
+
import { useCallback, useEffect, useRef, useState, useSyncExternalStore } from 'react'
|
|
27
|
+
import type {} from '@deepseek-ai/dsh-client-ui-session/client'
|
|
28
|
+
import { GenuiActionContext, type GenuiActionHandler } from './action-context.ts'
|
|
29
|
+
import type { PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots'
|
|
30
|
+
import { ExportableGenuiBlock } from './artifact/ExportableGenuiBlock.tsx'
|
|
31
|
+
import { ErrorBoundary } from './ErrorBoundary.tsx'
|
|
32
|
+
import { panelStateKey } from './interaction-store.ts'
|
|
33
|
+
import { TemplateDrawer } from './TemplateDrawer.tsx'
|
|
34
|
+
import { clearSessionPanel, getPanelExpandToken, getPanelSpec, setLocalPanel, subscribePanel, subscribePanelExpand } from './panel-store.ts'
|
|
35
|
+
import { useT } from './i18n/index.ts'
|
|
36
|
+
import css from './GenuiBlock.module.css'
|
|
37
|
+
|
|
38
|
+
/** Resize bounds for the panel body, in px. */
|
|
39
|
+
const PANEL_HEIGHT_MIN = 120
|
|
40
|
+
const PANEL_HEIGHT_MAX = 600
|
|
41
|
+
|
|
42
|
+
/** First-panel hint dismissal flag (module-level localStorage key):
|
|
43
|
+
* shown once beside the first rendered spec, never again. */
|
|
44
|
+
const ONBOARD_KEY = 'dsh.genui.panel-hint'
|
|
45
|
+
|
|
46
|
+
// Achievement telemetry re-exports (already injected at apply).
|
|
47
|
+
import { recordPanel, recordTemplateUse } from './achievement-store.ts'
|
|
48
|
+
|
|
49
|
+
/** Injection face built per session in apply (scoped conversation send). */
|
|
50
|
+
export interface GenuiPanelInjected {
|
|
51
|
+
sessionId: string
|
|
52
|
+
sendGenuiAction: GenuiActionHandler
|
|
53
|
+
/** Template center "try it": insert the template instruction into the
|
|
54
|
+
* current composer draft (standard conversation.input.for channel). */
|
|
55
|
+
insertTemplate: (text: string) => void
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export type GenuiPanelProps = PropsRuntime<'conversation.input.dock'> & GenuiPanelInjected
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Panel dock entry. Renders nothing until the session's toolview published a
|
|
62
|
+
* spec; afterwards the SAME block re-renders on every publish. Collapsed by
|
|
63
|
+
* default so the dock never steals the message flow's scroll room; the
|
|
64
|
+
* header always shows the current panel title.
|
|
65
|
+
*/
|
|
66
|
+
export function GenuiPanel({ sessionId, sendGenuiAction, insertTemplate }: GenuiPanelProps) {
|
|
67
|
+
const t = useT()
|
|
68
|
+
const spec = useSyncExternalStore(subscribePanel, () => getPanelSpec(sessionId))
|
|
69
|
+
const expandToken = useSyncExternalStore(subscribePanelExpand, () => getPanelExpandToken(sessionId))
|
|
70
|
+
const [collapsed, setCollapsed] = useState(true)
|
|
71
|
+
// Custom body height from the resize drag; null = the CSS default (360px).
|
|
72
|
+
const [bodyHeight, setBodyHeight] = useState<number | null>(null)
|
|
73
|
+
const [resizing, setResizing] = useState(false)
|
|
74
|
+
const dragStart = useRef<{ y: number; height: number } | null>(null)
|
|
75
|
+
const bodyRef = useRef<HTMLDivElement | null>(null)
|
|
76
|
+
// Template center (0.9.4) + achievements (0.9.5): the drawer host —
|
|
77
|
+
// null = closed, 'templates' | 'achievements' = open on that tab.
|
|
78
|
+
const [drawer, setDrawer] = useState<null | 'templates' | 'achievements'>(null)
|
|
79
|
+
const [flash, setFlash] = useState<string | null>(null)
|
|
80
|
+
const flashTimer = useRef(0)
|
|
81
|
+
const hasSpec = spec !== null && spec.items.length > 0
|
|
82
|
+
// First-panel hint: shown once beside the first rendered spec (never on the
|
|
83
|
+
// hero — the host composer hero flex-compresses dock items with no content,
|
|
84
|
+
// and the template button is a permanent header entry anyway).
|
|
85
|
+
const [hint, setHint] = useState<boolean>(() => {
|
|
86
|
+
try {
|
|
87
|
+
return hasSpec && localStorage.getItem(ONBOARD_KEY) !== '1'
|
|
88
|
+
} catch {
|
|
89
|
+
return hasSpec
|
|
90
|
+
}
|
|
91
|
+
})
|
|
92
|
+
useEffect(() => {
|
|
93
|
+
if (!hint) return
|
|
94
|
+
const t = window.setTimeout(() => {
|
|
95
|
+
try {
|
|
96
|
+
localStorage.setItem(ONBOARD_KEY, '1')
|
|
97
|
+
} catch {
|
|
98
|
+
// Private-mode storage failures are non-fatal: the hint may reappear.
|
|
99
|
+
}
|
|
100
|
+
setHint(false)
|
|
101
|
+
}, 6000)
|
|
102
|
+
return () => window.clearTimeout(t)
|
|
103
|
+
}, [hint])
|
|
104
|
+
// Achievement telemetry (0.9.5): one panel appearance per dock mount.
|
|
105
|
+
useEffect(() => {
|
|
106
|
+
if (!hasSpec) return
|
|
107
|
+
recordPanel()
|
|
108
|
+
}, [hasSpec])
|
|
109
|
+
|
|
110
|
+
// Explicit expand requests (the /panel command) open the dock even when the
|
|
111
|
+
// user collapsed it manually: the monotone token guarantees a fresh request
|
|
112
|
+
// is never mistaken for the previous one.
|
|
113
|
+
useEffect(() => {
|
|
114
|
+
if (expandToken > 0) setCollapsed(false)
|
|
115
|
+
}, [expandToken])
|
|
116
|
+
|
|
117
|
+
// Session teardown: the dock is session-scoped, so unmount means the host
|
|
118
|
+
// pruned or destroyed the session's scope. Release the session's panel
|
|
119
|
+
// state (snapshot, ops, overflow diagnostics, expand token) — without this
|
|
120
|
+
// the module-level store grows one entry per session for the app's whole
|
|
121
|
+
// lifetime. A reopen lazily rebuilds from history replays, which is the
|
|
122
|
+
// host's own lifecycle contract.
|
|
123
|
+
useEffect(() => {
|
|
124
|
+
return () => {
|
|
125
|
+
clearSessionPanel(sessionId)
|
|
126
|
+
}
|
|
127
|
+
}, [sessionId])
|
|
128
|
+
|
|
129
|
+
// Cleanup safety net: if the component unmounts mid-drag (spec cleared),
|
|
130
|
+
// the window listeners must not outlive it.
|
|
131
|
+
useEffect(() => {
|
|
132
|
+
if (!resizing) return
|
|
133
|
+
return () => {
|
|
134
|
+
dragStart.current = null
|
|
135
|
+
}
|
|
136
|
+
}, [resizing])
|
|
137
|
+
|
|
138
|
+
// Template-center flash timer must not outlive the dock.
|
|
139
|
+
useEffect(() => () => window.clearTimeout(flashTimer.current), [])
|
|
140
|
+
|
|
141
|
+
/** Start a vertical resize drag on the panel's top edge. Dragging UP grows
|
|
142
|
+
* the panel (the edge moves toward the message flow); dragging down shrinks
|
|
143
|
+
* it. Pointer capture binds move/up/cancel to the HANDLE, so dragging past
|
|
144
|
+
* the element edge keeps tracking and nothing global is registered — no
|
|
145
|
+
* window listeners, nothing to leak on unmount. */
|
|
146
|
+
const startResize = useCallback((e: React.PointerEvent<HTMLDivElement>) => {
|
|
147
|
+
e.preventDefault()
|
|
148
|
+
const handle = e.currentTarget
|
|
149
|
+
// Track from the current committed height (state mirrors the drag, the
|
|
150
|
+
// CSS default otherwise) — no DOM measurement needed.
|
|
151
|
+
const startHeight = bodyHeight ?? 360
|
|
152
|
+
dragStart.current = { y: e.clientY, height: startHeight }
|
|
153
|
+
setResizing(true)
|
|
154
|
+
try {
|
|
155
|
+
handle.setPointerCapture(e.pointerId)
|
|
156
|
+
} catch {
|
|
157
|
+
// jsdom / capture unsupported: listeners below still track the drag.
|
|
158
|
+
}
|
|
159
|
+
const onMove = (ev: PointerEvent): void => {
|
|
160
|
+
const start = dragStart.current
|
|
161
|
+
if (start === null) return
|
|
162
|
+
// Upward drag (clientY decreasing) grows the body height.
|
|
163
|
+
const next = Math.min(PANEL_HEIGHT_MAX, Math.max(PANEL_HEIGHT_MIN, start.height + (start.y - ev.clientY)))
|
|
164
|
+
setBodyHeight(next)
|
|
165
|
+
}
|
|
166
|
+
const onUp = (): void => {
|
|
167
|
+
dragStart.current = null
|
|
168
|
+
setResizing(false)
|
|
169
|
+
handle.removeEventListener('pointermove', onMove)
|
|
170
|
+
handle.removeEventListener('pointerup', onUp)
|
|
171
|
+
handle.removeEventListener('pointercancel', onUp)
|
|
172
|
+
}
|
|
173
|
+
handle.addEventListener('pointermove', onMove)
|
|
174
|
+
handle.addEventListener('pointerup', onUp)
|
|
175
|
+
handle.addEventListener('pointercancel', onUp)
|
|
176
|
+
}, [bodyHeight])
|
|
177
|
+
|
|
178
|
+
if (!hasSpec) return null
|
|
179
|
+
|
|
180
|
+
const showFlash = (text: string): void => {
|
|
181
|
+
setFlash(text)
|
|
182
|
+
window.clearTimeout(flashTimer.current)
|
|
183
|
+
flashTimer.current = window.setTimeout(() => setFlash(null), 2500)
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return (
|
|
187
|
+
<div className={css.panel} data-genui-panel>
|
|
188
|
+
{/* Resize grip on the panel's TOP EDGE (above the header): the drag
|
|
189
|
+
target the user described — the outermost top border, not a strip
|
|
190
|
+
under the title. */}
|
|
191
|
+
{!collapsed && (
|
|
192
|
+
<div
|
|
193
|
+
role="separator"
|
|
194
|
+
aria-orientation="horizontal"
|
|
195
|
+
aria-label={t('panel.resize.aria')}
|
|
196
|
+
className={`${css.panelResizeHandle}${resizing ? ` ${css.panelResizeHandleActive}` : ''}`}
|
|
197
|
+
onPointerDown={startResize}
|
|
198
|
+
/>
|
|
199
|
+
)}
|
|
200
|
+
<div className={css.panelHeader}>
|
|
201
|
+
<button
|
|
202
|
+
type="button"
|
|
203
|
+
className={css.panelToggle}
|
|
204
|
+
aria-expanded={!collapsed}
|
|
205
|
+
onClick={() => setCollapsed(c => !c)}
|
|
206
|
+
>
|
|
207
|
+
<span className={css.panelBadge}>{t('panel.badge')}</span>
|
|
208
|
+
<span className={css.panelTitle}>{spec?.title ?? t(drawer !== null ? 'panel.title.explore' : 'panel.title.default')}</span>
|
|
209
|
+
<span className={css.panelChevron} aria-hidden>
|
|
210
|
+
{/* 折叠状态对应的箭头。 */}
|
|
211
|
+
<svg width="14" height="14" viewBox="0 0 16 16" fill="none" aria-hidden="true">
|
|
212
|
+
<path d={collapsed ? 'M12 10L8.70711 6.70711C8.31658 6.31658 7.68342 6.31658 7.29289 6.70711L4 10' : 'M4 6L7.29289 9.29289C7.68342 9.68342 8.31658 9.68342 8.70711 9.29289L12 6'} stroke="currentColor" />
|
|
213
|
+
</svg>
|
|
214
|
+
</span>
|
|
215
|
+
</button>
|
|
216
|
+
{/* Template center (0.9.4): one button — the discovery surface for
|
|
217
|
+
new users and a quick-start entry for everyone. */}
|
|
218
|
+
<button
|
|
219
|
+
type="button"
|
|
220
|
+
className={`${css.panelTpl}${drawer === 'templates' ? ` ${css.panelTplActive}` : ''}`}
|
|
221
|
+
aria-label={t('panel.templates.aria')}
|
|
222
|
+
title={t('panel.templates.title')}
|
|
223
|
+
onClick={() => { setCollapsed(false); setDrawer(d => (d === 'templates' ? null : 'templates')) }}
|
|
224
|
+
>
|
|
225
|
+
{t('panel.templates')}
|
|
226
|
+
</button>
|
|
227
|
+
{/* Achievements (0.9.5): the exploration trophies, rendered by GenUI
|
|
228
|
+
itself (dogfooding). */}
|
|
229
|
+
<button
|
|
230
|
+
type="button"
|
|
231
|
+
className={`${css.panelTpl}${drawer === 'achievements' ? ` ${css.panelTplActive}` : ''}`}
|
|
232
|
+
aria-label={t('panel.achievements.aria')}
|
|
233
|
+
title={t('panel.achievements.title')}
|
|
234
|
+
onClick={() => { setCollapsed(false); setDrawer(d => (d === 'achievements' ? null : 'achievements')) }}
|
|
235
|
+
>
|
|
236
|
+
{t('panel.achievements')}
|
|
237
|
+
</button>
|
|
238
|
+
{/* In-place dismiss (issue #23): the same local override `/panel
|
|
239
|
+
clear` applies — persists to localStorage, notifies subscribers,
|
|
240
|
+
unmounts the dock without any navigation or reload. */}
|
|
241
|
+
<button
|
|
242
|
+
type="button"
|
|
243
|
+
className={css.panelClose}
|
|
244
|
+
aria-label={t('panel.close.aria')}
|
|
245
|
+
title={t('panel.close.aria')}
|
|
246
|
+
onClick={() => setLocalPanel(sessionId, null)}
|
|
247
|
+
>
|
|
248
|
+
<span aria-hidden>✕</span>
|
|
249
|
+
</button>
|
|
250
|
+
</div>
|
|
251
|
+
{hint && drawer === null && (
|
|
252
|
+
<div className={css.panelHint} role="status">
|
|
253
|
+
{t('panel.hint')}
|
|
254
|
+
</div>
|
|
255
|
+
)}
|
|
256
|
+
{!collapsed && (
|
|
257
|
+
<div
|
|
258
|
+
ref={bodyRef}
|
|
259
|
+
className={css.panelBody}
|
|
260
|
+
data-genui-panel-body
|
|
261
|
+
style={bodyHeight === null ? undefined : { height: bodyHeight }}
|
|
262
|
+
>
|
|
263
|
+
{drawer !== null ? (
|
|
264
|
+
<TemplateDrawer
|
|
265
|
+
tab={drawer}
|
|
266
|
+
onUse={(text) => {
|
|
267
|
+
recordTemplateUse()
|
|
268
|
+
insertTemplate(text)
|
|
269
|
+
showFlash(t('panel.flash.inserted'))
|
|
270
|
+
}}
|
|
271
|
+
/>
|
|
272
|
+
) : spec !== null ? (
|
|
273
|
+
<GenuiActionContext.Provider value={sendGenuiAction}>
|
|
274
|
+
<ErrorBoundary label={t('panel.boundary')}>
|
|
275
|
+
{/* content-fingerprinted: same panel spec re-published restores its state */}
|
|
276
|
+
<ExportableGenuiBlock spec={spec} stateKey={panelStateKey(sessionId, JSON.stringify(spec))} />
|
|
277
|
+
</ErrorBoundary>
|
|
278
|
+
</GenuiActionContext.Provider>
|
|
279
|
+
) : null}
|
|
280
|
+
</div>
|
|
281
|
+
)}
|
|
282
|
+
{flash !== null && (
|
|
283
|
+
<div className={css.panelFlash} role="status">{flash}</div>
|
|
284
|
+
)}
|
|
285
|
+
</div>
|
|
286
|
+
)
|
|
287
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Partial GenUI spec parsing: extract the components that are already
|
|
3
|
+
* complete from a still-growing ```dsh-ui fence body, so the UI can render
|
|
4
|
+
* top-down as the model writes — each finished component appears the moment
|
|
5
|
+
* its JSON object closes, instead of the whole block waiting for the fence.
|
|
6
|
+
*
|
|
7
|
+
* Strategy (tolerant, white-list-agnostic, BOUNDED):
|
|
8
|
+
* 1. Full parse first (the common settled case) — at most one.
|
|
9
|
+
* 2. ONE left-to-right scan collects the repair candidates: every position
|
|
10
|
+
* where the prefix is bracket-balanced (trailing comma / fence tail) and
|
|
11
|
+
* every top-level `items[]` component close (an unfinished trailing
|
|
12
|
+
* component is dropped by closing the root array/object). Partial candidates
|
|
13
|
+
* must parse as a spec root; bare components wait for their own root close.
|
|
14
|
+
* The ring buffer keeps only the longest-direction candidates (≤ MAX_PARTIAL_REPAIR_ATTEMPTS),
|
|
15
|
+
* so the work is O(n) with a hard parse-attempt cap — a pathological
|
|
16
|
+
* input can never re-scan prefixes or burn seconds in JSON.parse.
|
|
17
|
+
* 3. Candidates are tried longest first; the first that parses as a GenUI
|
|
18
|
+
* spec wins. Nothing parses → null (streaming partial, wait for more).
|
|
19
|
+
*
|
|
20
|
+
* The result is only ever a PREFIX of the intended spec, so it is always
|
|
21
|
+
* safe to render: components already present are complete and valid.
|
|
22
|
+
*
|
|
23
|
+
* `ponytail:` the 32-candidate / 33-parse budget is the protection ceiling;
|
|
24
|
+
* only real streaming samples proving a recovery shortfall justify switching
|
|
25
|
+
* to a tokenizing parser.
|
|
26
|
+
*/
|
|
27
|
+
import { isGenuiSpec, type GenuiSpec } from './spec.ts'
|
|
28
|
+
import { wrapSingleComponentRoot } from './spec.ts'
|
|
29
|
+
|
|
30
|
+
/** Default repair-candidate budget (adjustable; see the design doc). */
|
|
31
|
+
export const MAX_PARTIAL_REPAIR_ATTEMPTS = 32
|
|
32
|
+
|
|
33
|
+
let repairAttemptsLimit = MAX_PARTIAL_REPAIR_ATTEMPTS
|
|
34
|
+
|
|
35
|
+
/** Override the repair-candidate budget (tests / tuning). */
|
|
36
|
+
export function setMaxPartialRepairAttempts(n: number): void {
|
|
37
|
+
repairAttemptsLimit = n
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** One repair candidate: a balanced prefix of the body ending at `end`,
|
|
41
|
+
* plus the closing brackets to append (empty when already balanced). */
|
|
42
|
+
export interface PartialCandidate {
|
|
43
|
+
end: number
|
|
44
|
+
closingSuffix: string
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Single left-to-right pass over the raw body. Tracks the bracket stack
|
|
48
|
+
* (skipping strings/escapes correctly) and records:
|
|
49
|
+
* - every position where the prefix is fully balanced (trailing comma or
|
|
50
|
+
* fence tail) — candidate with an empty closing suffix;
|
|
51
|
+
* - every top-level `items[]` component close — candidate with the root
|
|
52
|
+
* array/object closed (an unfinished trailing component is dropped). Nested
|
|
53
|
+
* object closes are not candidates because their component is still partial.
|
|
54
|
+
* Candidates are ring-buffered to the attempts budget (the LAST pushes are
|
|
55
|
+
* the longest), then returned longest-first, deduplicated by end. The scan
|
|
56
|
+
* stops at the first unbalanced close — earlier balanced prefixes remain
|
|
57
|
+
* valid candidates.
|
|
58
|
+
*
|
|
59
|
+
* Exposed for tests (the `scannedChars` diagnostic); not exported from the
|
|
60
|
+
* package entry. The parser calls this exactly once per parse.
|
|
61
|
+
*/
|
|
62
|
+
export function collectPartialCandidates(raw: string): { candidates: PartialCandidate[]; scannedChars: number } {
|
|
63
|
+
const stack: string[] = []
|
|
64
|
+
const candidates: PartialCandidate[] = []
|
|
65
|
+
const push = (c: PartialCandidate): void => {
|
|
66
|
+
if (candidates.length >= repairAttemptsLimit) candidates.shift()
|
|
67
|
+
candidates.push(c)
|
|
68
|
+
}
|
|
69
|
+
let inString = false
|
|
70
|
+
let escaped = false
|
|
71
|
+
let scanned = 0
|
|
72
|
+
for (; scanned < raw.length; scanned++) {
|
|
73
|
+
const ch = raw[scanned]!
|
|
74
|
+
if (inString) {
|
|
75
|
+
if (escaped) escaped = false
|
|
76
|
+
else if (ch === '\\') escaped = true
|
|
77
|
+
else if (ch === '"') inString = false
|
|
78
|
+
continue
|
|
79
|
+
}
|
|
80
|
+
if (ch === '"') {
|
|
81
|
+
inString = true
|
|
82
|
+
continue
|
|
83
|
+
}
|
|
84
|
+
if (ch === '{' || ch === '[') {
|
|
85
|
+
stack.push(ch)
|
|
86
|
+
continue
|
|
87
|
+
}
|
|
88
|
+
if (ch === '}' || ch === ']') {
|
|
89
|
+
const open = stack.pop()
|
|
90
|
+
const expects = ch === '}' ? '{' : '['
|
|
91
|
+
if (open !== expects) {
|
|
92
|
+
// Unbalanced (mismatched or stray close): the tail is unusable, but
|
|
93
|
+
// balanced prefixes recorded earlier stay valid. Stop scanning.
|
|
94
|
+
break
|
|
95
|
+
}
|
|
96
|
+
if (ch === '}' && stack.length === 2 && stack[0] === '{' && stack[1] === '[') {
|
|
97
|
+
// Only a direct root-array member can be a finished component.
|
|
98
|
+
// Partial parsing later requires an actual spec root, so a bare
|
|
99
|
+
// component's data[] member cannot become a candidate.
|
|
100
|
+
push({ end: scanned + 1, closingSuffix: ']}' })
|
|
101
|
+
}
|
|
102
|
+
if (stack.length === 0) {
|
|
103
|
+
// Whole prefix balanced: a complete-JSON candidate (trailing comma /
|
|
104
|
+
// fence tail cases).
|
|
105
|
+
push({ end: scanned + 1, closingSuffix: '' })
|
|
106
|
+
}
|
|
107
|
+
continue
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
candidates.sort((a, b) => b.end - a.end)
|
|
111
|
+
const deduped: PartialCandidate[] = []
|
|
112
|
+
for (const c of candidates) {
|
|
113
|
+
if (deduped.length === 0 || deduped[deduped.length - 1]!.end !== c.end) deduped.push(c)
|
|
114
|
+
}
|
|
115
|
+
return { candidates: deduped.slice(0, repairAttemptsLimit), scannedChars: scanned }
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** Try to parse a candidate as a GenuiSpec. */
|
|
119
|
+
function trySpec(candidate: string, allowSingleComponentRoot: boolean): GenuiSpec | null {
|
|
120
|
+
try {
|
|
121
|
+
let value: unknown = JSON.parse(candidate)
|
|
122
|
+
// Double-encoded body (issue #186): the whole spec arrived as a JSON
|
|
123
|
+
// string — decode exactly once so the fence channel reaches the guard,
|
|
124
|
+
// which reports the rewrite when the same value arrives un-parsed from a
|
|
125
|
+
// tool call.
|
|
126
|
+
if (typeof value === 'string') {
|
|
127
|
+
try {
|
|
128
|
+
value = JSON.parse(value)
|
|
129
|
+
} catch {
|
|
130
|
+
return null
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (isGenuiSpec(value)) return value
|
|
134
|
+
// A root-level component list is the envelope minus its braces (issue
|
|
135
|
+
// #186): adopt it as `items` instead of rejecting the body.
|
|
136
|
+
if (Array.isArray(value) && value.length > 0) return { items: value }
|
|
137
|
+
// Single-component roots are part of the documented fence vocabulary
|
|
138
|
+
// (e.g. a bare {"type":"callout",…} body) — wrap into a col so the
|
|
139
|
+
// items-gated pipeline renders them (panel/append hoisted).
|
|
140
|
+
return allowSingleComponentRoot ? wrapSingleComponentRoot(value) : null
|
|
141
|
+
} catch {
|
|
142
|
+
return null
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Parse a possibly incomplete genui spec body.
|
|
148
|
+
* @param raw - the fence body as accumulated so far.
|
|
149
|
+
* @returns a spec containing only finished components, or null when nothing
|
|
150
|
+
* usable has been written yet.
|
|
151
|
+
*/
|
|
152
|
+
export function parsePartialGenuiSpec(raw: string): GenuiSpec | null {
|
|
153
|
+
const text = raw.trim()
|
|
154
|
+
if (text === '') return null
|
|
155
|
+
|
|
156
|
+
// 1. Full parse (settled / already-complete body).
|
|
157
|
+
const full = trySpec(text, true)
|
|
158
|
+
if (full !== null) return full
|
|
159
|
+
|
|
160
|
+
// 2. Bounded repair: ONE forward scan, at most `repairAttemptsLimit`
|
|
161
|
+
// candidates, longest first — never a re-scan per `}`.
|
|
162
|
+
const { candidates } = collectPartialCandidates(text)
|
|
163
|
+
for (const candidate of candidates) {
|
|
164
|
+
const spec = trySpec(text.slice(0, candidate.end) + candidate.closingSuffix, false)
|
|
165
|
+
if (spec !== null) return spec
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// 3. Not even one complete element yet (e.g. `{"items":[{"type":"tex`).
|
|
169
|
+
return null
|
|
170
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as primitives from '@deepseek-ai/dsh-client-ui-primitives'
|
|
2
|
+
|
|
3
|
+
export { CodeBlock, DiffBlock, JsonTree, writeClipboard } from '@deepseek-ai/dsh-client-ui-primitives'
|
|
4
|
+
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
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Localized labels required by the DSH UI primitives.
|
|
3
|
+
*
|
|
4
|
+
* The primitives take their chrome as plain label objects, so these are built
|
|
5
|
+
* PER RENDER from the active locale (`labelsOf*()`) rather than frozen at
|
|
6
|
+
* module load — a language switch must reach a diff or JSON tree that is
|
|
7
|
+
* already on screen.
|
|
8
|
+
*/
|
|
9
|
+
import type { DiffBlockLabels, JsonTreeLabels } from './primitive-adapter.ts'
|
|
10
|
+
import { t } from './i18n/index.ts'
|
|
11
|
+
|
|
12
|
+
/** Chrome labels for an inline GenUI diff block, in the active locale. */
|
|
13
|
+
export function diffBlockLabels(): DiffBlockLabels {
|
|
14
|
+
const labels = {
|
|
15
|
+
copy: t('label.copy'),
|
|
16
|
+
copied: t('label.copied'),
|
|
17
|
+
codeLabel: t('label.code'),
|
|
18
|
+
wrapLabel: t('label.wrap'),
|
|
19
|
+
unwrapLabel: t('label.unwrap'),
|
|
20
|
+
collapseAria: t('label.collapseDiff.aria'),
|
|
21
|
+
/** Accessible label for expanding a collapsed diff tail. */
|
|
22
|
+
expandAria(hidden: number) { return t('label.expandDiff.aria', { hidden }) },
|
|
23
|
+
collapse: t('label.collapse'),
|
|
24
|
+
/** Visible label for expanding a collapsed diff tail. */
|
|
25
|
+
expand(hidden: number) { return t('label.expandDiff', { hidden }) },
|
|
26
|
+
/** Localized file-count summary in the diff footer. */
|
|
27
|
+
files(count: number) { return t('label.diffFiles', { count }) },
|
|
28
|
+
}
|
|
29
|
+
return labels
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Copy labels for a code block rendered inside a GenUI fence or node. */
|
|
33
|
+
export function codeBlockLabels(): { copyLabel: string, copiedLabel: string } {
|
|
34
|
+
return {
|
|
35
|
+
copyLabel: t('label.copy'),
|
|
36
|
+
copiedLabel: t('label.copied'),
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Chrome labels for an inline GenUI JSON tree, in the active locale. */
|
|
41
|
+
export function jsonTreeLabels(): JsonTreeLabels {
|
|
42
|
+
return {
|
|
43
|
+
copyValue: t('label.copyValue'),
|
|
44
|
+
copyJson: t('label.copyJson'),
|
|
45
|
+
copyPath: t('label.copyPath'),
|
|
46
|
+
copyPrettyJson: t('label.copyPrettyJson'),
|
|
47
|
+
copyCompactJson: t('label.copyCompactJson'),
|
|
48
|
+
copied: t('label.copiedDone'),
|
|
49
|
+
copyFailed: t('label.copyFailed'),
|
|
50
|
+
collapseNode: t('label.collapseNode'),
|
|
51
|
+
expandNode: t('label.expandNode'),
|
|
52
|
+
/** Tooltip for a JSON tree copy action. */
|
|
53
|
+
copyButtonTitle(action) { return t('label.copyButtonTitle', { action }) },
|
|
54
|
+
}
|
|
55
|
+
}
|