dsh-better-display 0.3.8 → 0.3.10
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 +11 -0
- package/DESIGN.md +43 -3
- package/README.en.md +10 -2
- package/README.md +10 -2
- package/compat/harness-rc2.json +17 -13
- package/docs/dependency-update-policy.md +9 -0
- package/docs/extension-points.md +172 -0
- package/docs/official-rendering-bridge.md +49 -20
- package/docs/openapi.yaml +147 -0
- package/docs/runbooks/blank-reader.md +39 -0
- package/lib/client.js +1802 -872
- package/lib/client.js.map +1 -1
- package/lib/dsh-better-display.js +376 -151
- package/lib/types/client/AssistantNode.d.ts +20 -0
- package/lib/types/client/AssistantNode.d.ts.map +1 -0
- package/lib/types/client/AssistantNode.js +46 -0
- package/lib/types/client/AssistantNode.js.map +1 -0
- package/lib/types/client/Blocks.d.ts.map +1 -1
- package/lib/types/client/Blocks.js +33 -10
- package/lib/types/client/Blocks.js.map +1 -1
- package/lib/types/client/ChoreographedFlow.d.ts.map +1 -1
- package/lib/types/client/ChoreographedFlow.js +2 -0
- package/lib/types/client/ChoreographedFlow.js.map +1 -1
- package/lib/types/client/ClosedProcessSummary.d.ts.map +1 -1
- package/lib/types/client/ClosedProcessSummary.js +3 -1
- package/lib/types/client/ClosedProcessSummary.js.map +1 -1
- package/lib/types/client/McpAppFrame.d.ts.map +1 -1
- package/lib/types/client/McpAppFrame.js +5 -11
- package/lib/types/client/McpAppFrame.js.map +1 -1
- package/lib/types/client/OfficialContent.d.ts +17 -3
- package/lib/types/client/OfficialContent.d.ts.map +1 -1
- package/lib/types/client/OfficialContent.js +37 -12
- package/lib/types/client/OfficialContent.js.map +1 -1
- package/lib/types/client/Reader.d.ts.map +1 -1
- package/lib/types/client/Reader.js +45 -77
- package/lib/types/client/Reader.js.map +1 -1
- package/lib/types/client/SettingsSection.d.ts.map +1 -1
- package/lib/types/client/SettingsSection.js +0 -5
- package/lib/types/client/SettingsSection.js.map +1 -1
- package/lib/types/client/StickyLane.d.ts +12 -0
- package/lib/types/client/StickyLane.d.ts.map +1 -1
- package/lib/types/client/StickyLane.js +78 -2
- package/lib/types/client/StickyLane.js.map +1 -1
- package/lib/types/client/ToolActivity.js.map +1 -1
- package/lib/types/client/index.d.ts +3 -1
- package/lib/types/client/index.d.ts.map +1 -1
- package/lib/types/client/index.js +6 -0
- package/lib/types/client/index.js.map +1 -1
- package/lib/types/client/live-turn.d.ts +17 -5
- package/lib/types/client/live-turn.d.ts.map +1 -1
- package/lib/types/client/live-turn.js +106 -76
- package/lib/types/client/live-turn.js.map +1 -1
- package/lib/types/client/motion.d.ts +26 -2
- package/lib/types/client/motion.d.ts.map +1 -1
- package/lib/types/client/motion.js +136 -10
- package/lib/types/client/motion.js.map +1 -1
- package/lib/types/client/official-slots.d.ts +24 -3
- package/lib/types/client/official-slots.d.ts.map +1 -1
- package/lib/types/client/official-slots.js +59 -11
- package/lib/types/client/official-slots.js.map +1 -1
- package/lib/types/client/primitive-labels.d.ts.map +1 -1
- package/lib/types/client/primitive-labels.js +1 -0
- package/lib/types/client/primitive-labels.js.map +1 -1
- package/lib/types/client/projection.d.ts +15 -2
- package/lib/types/client/projection.d.ts.map +1 -1
- package/lib/types/client/projection.js +16 -4
- package/lib/types/client/projection.js.map +1 -1
- package/lib/types/client/rewind-cut.d.ts +131 -0
- package/lib/types/client/rewind-cut.d.ts.map +1 -0
- package/lib/types/client/rewind-cut.js +321 -0
- package/lib/types/client/rewind-cut.js.map +1 -0
- package/lib/types/client/text-transform.d.ts +93 -0
- package/lib/types/client/text-transform.d.ts.map +1 -0
- package/lib/types/client/text-transform.js +183 -0
- package/lib/types/client/text-transform.js.map +1 -0
- package/lib/types/client/timeline.d.ts.map +1 -1
- package/lib/types/client/timeline.js.map +1 -1
- package/lib/types/client/tool-activity.d.ts +9 -2
- package/lib/types/client/tool-activity.d.ts.map +1 -1
- package/lib/types/client/tool-activity.js +42 -2
- package/lib/types/client/tool-activity.js.map +1 -1
- package/lib/types/client/turn-slots.d.ts +29 -0
- package/lib/types/client/turn-slots.d.ts.map +1 -0
- package/lib/types/client/turn-slots.js +62 -0
- package/lib/types/client/turn-slots.js.map +1 -0
- package/lib/types/client/types.d.ts +18 -0
- package/lib/types/client/types.d.ts.map +1 -1
- package/lib/types/dsh-better-display.d.ts +4 -1
- package/lib/types/dsh-better-display.d.ts.map +1 -1
- package/lib/types/dsh-better-display.js +56 -7
- package/lib/types/dsh-better-display.js.map +1 -1
- package/lib/types/flags.d.ts +7 -0
- package/lib/types/flags.d.ts.map +1 -0
- package/lib/types/flags.js +37 -0
- package/lib/types/flags.js.map +1 -0
- package/lib/types/log.d.ts +17 -0
- package/lib/types/log.d.ts.map +1 -0
- package/lib/types/log.js +122 -0
- package/lib/types/log.js.map +1 -0
- package/lib/types/metrics.d.ts +18 -0
- package/lib/types/metrics.d.ts.map +1 -0
- package/lib/types/metrics.js +35 -0
- package/lib/types/metrics.js.map +1 -0
- package/package.json +55 -23
- package/scripts/changelog.mjs +20 -0
- package/scripts/check-agents-md.mjs +67 -0
- package/scripts/check-bundle-size.mjs +38 -0
- package/scripts/check-dead-flags.mjs +55 -0
- package/scripts/check-harness-compat.mjs +4 -2
- package/scripts/check-todo-debt.mjs +69 -0
- package/scripts/link-harness-dependencies.mjs +48 -11
- package/scripts/security-audit-report.mjs +92 -0
- package/scripts/verify-commentary-visible.mjs +627 -0
- package/src/client/AssistantNode.tsx +72 -0
- package/src/client/Blocks.tsx +49 -10
- package/src/client/ChoreographedFlow.tsx +3 -1
- package/src/client/ClosedProcessSummary.tsx +3 -1
- package/src/client/McpAppFrame.tsx +5 -13
- package/src/client/OfficialContent.tsx +52 -14
- package/src/client/Reader.module.css +68 -18
- package/src/client/Reader.tsx +38 -82
- package/src/client/SettingsSection.tsx +1 -7
- package/src/client/StickyLane.tsx +81 -2
- package/src/client/ToolActivity.tsx +1 -1
- package/src/client/index.tsx +8 -1
- package/src/client/live-turn.ts +100 -69
- package/src/client/motion.tsx +135 -7
- package/src/client/official-slots.tsx +61 -12
- package/src/client/primitive-labels.ts +1 -0
- package/src/client/projection.ts +16 -4
- package/src/client/rewind-cut.ts +340 -0
- package/src/client/text-transform.ts +265 -0
- package/src/client/timeline.ts +0 -2
- package/src/client/tool-activity.ts +49 -2
- package/src/client/turn-slots.ts +80 -0
- package/src/client/types.ts +19 -0
- package/src/dsh-better-display.ts +58 -7
- package/src/flags.ts +40 -0
- package/src/log.ts +137 -0
- package/src/metrics.ts +50 -0
- package/tests/browser-commentary.tsx +191 -0
- package/tests/browser-official-bridge.tsx +2 -1
- package/tests/chat-flow-hook.test.ts +1 -1
- package/tests/cloud-gate.test.ts +1 -1
- package/tests/context-tool-update.test.ts +1 -1
- package/tests/conversation-scroll.test.ts +1 -1
- package/tests/deliverables.test.ts +1 -1
- package/tests/entry.test.ts +1 -1
- package/tests/fixtures/reader-lane-owners.tsx +46 -0
- package/tests/fixtures/reader-official-users.tsx +64 -0
- package/tests/fixtures/reader-theme-overlap.html +80 -0
- package/tests/fixtures/reader-user-bubble.tsx +244 -0
- package/tests/flags.test.ts +66 -0
- package/tests/fold-choreography.test.ts +32 -8
- package/tests/fold-intensity.test.ts +11 -6
- package/tests/footer-precedence.test.ts +1 -1
- package/tests/history-word-regression.test.ts +1 -1
- package/tests/live-turn.test.ts +125 -54
- package/tests/log.test.ts +99 -0
- package/tests/mcp-apps.test.ts +1 -1
- package/tests/message-chrome.test.ts +1 -1
- package/tests/metrics.test.ts +52 -0
- package/tests/official-slots.test.ts +41 -2
- package/tests/open-file.test.ts +1 -1
- package/tests/pending-submission.test.ts +12 -1
- package/tests/pinned-selection.test.ts +16 -0
- package/tests/platform-media.test.ts +1 -1
- package/tests/projection.test.ts +66 -3
- package/tests/reader-glass-css.test.ts +1 -1
- package/tests/reader-official-users.test.ts +11 -1
- package/tests/reader-sticky-surface.test.ts +377 -0
- package/tests/reader-theme-lanes.test.ts +54 -0
- package/tests/reader-theme-overlap.test.ts +151 -0
- package/tests/reader-user-bubble.test.ts +138 -0
- package/tests/reasoning-follow.test.ts +1 -1
- package/tests/retiring-content.test.ts +98 -6
- package/tests/reveal.test.ts +3 -3
- package/tests/rewind-cut.test.ts +1090 -0
- package/tests/settings-copy.test.ts +1 -1
- package/tests/skill-status.test.ts +1 -1
- package/tests/stock-install.test.ts +11 -7
- package/tests/stream-buffer.test.ts +1 -1
- package/tests/styles.test.ts +30 -3
- package/tests/terminal-input-preview.test.ts +1 -1
- package/tests/text-transform.test.ts +272 -0
- package/tests/timeline.test.ts +1 -1
- package/tests/tool-clock.test.ts +1 -1
- package/tests/tool-diff.test.ts +1 -1
- package/tests/waiting-clock.test.ts +1 -1
- package/tests/word-timeline.test.ts +1 -1
package/src/client/motion.tsx
CHANGED
|
@@ -2,6 +2,7 @@ import { useCallback, useContext, useEffect, useLayoutEffect, useRef, useState }
|
|
|
2
2
|
import type { ReactNode, RefObject } from 'react';
|
|
3
3
|
import css from './Reader.module.css';
|
|
4
4
|
import { StreamMotionContext } from './streaming.js';
|
|
5
|
+
import { reconcileTurnSlots, type TurnSlot } from './turn-slots.js';
|
|
5
6
|
|
|
6
7
|
const EASING = 'cubic-bezier(.22,1,.36,1)';
|
|
7
8
|
|
|
@@ -16,7 +17,7 @@ export function useMotionAllowed(enabled: boolean): boolean {
|
|
|
16
17
|
return enabled && !reduced;
|
|
17
18
|
}
|
|
18
19
|
|
|
19
|
-
export function usePinnedSelection(root: RefObject<HTMLElement>, selector = '[data-reader-answer], [data-reader-process]'): readonly string[] {
|
|
20
|
+
export function usePinnedSelection(root: RefObject<HTMLElement>, selector = '[data-reader-answer], [data-reader-body], [data-reader-process]'): readonly string[] {
|
|
20
21
|
const [keys, setKeys] = useState<readonly string[]>([]);
|
|
21
22
|
useEffect(() => {
|
|
22
23
|
const update = () => {
|
|
@@ -89,7 +90,7 @@ export function StatusText({ text, motion, shimmer = false }: { text: string; mo
|
|
|
89
90
|
|
|
90
91
|
export function Disclosure({ open, onChange, label, controls, buttonRef, ariaLabel }: {
|
|
91
92
|
open: boolean; onChange: (value: boolean) => void; label: ReactNode;
|
|
92
|
-
controls?: string; buttonRef
|
|
93
|
+
controls?: string; buttonRef?: RefObject<HTMLButtonElement>;
|
|
93
94
|
ariaLabel?: string;
|
|
94
95
|
}) {
|
|
95
96
|
const name = ariaLabel ?? '思考与过程';
|
|
@@ -170,12 +171,16 @@ export function ProcessFragment({ open, motion, onRead, returnFocusTo, nodeKey,
|
|
|
170
171
|
}
|
|
171
172
|
|
|
172
173
|
/** Retire only narration that was actually visible; historical rows stay folded. */
|
|
173
|
-
export function RetiringContent({ visible, children }: { visible: boolean; children: ReactNode }) {
|
|
174
|
+
export function RetiringContent({ visible, children, onRetired }: { visible: boolean; children: ReactNode; onRetired?: () => void }) {
|
|
174
175
|
const { enabled } = useContext(StreamMotionContext);
|
|
175
176
|
const root = useRef<HTMLDivElement>(null);
|
|
176
177
|
const animation = useRef<Animation | null>(null);
|
|
177
178
|
const [present, setPresent] = useState(visible);
|
|
178
179
|
const [focusHeld, setFocusHeld] = useState(false);
|
|
180
|
+
// Held in a ref so a caller passing an inline closure does not restart the
|
|
181
|
+
// collapse every render, and so the settle path always sees the latest one.
|
|
182
|
+
const retired = useRef(onRetired);
|
|
183
|
+
retired.current = onRetired;
|
|
179
184
|
useLayoutEffect(() => {
|
|
180
185
|
const element = root.current;
|
|
181
186
|
if (visible) {
|
|
@@ -184,18 +189,49 @@ export function RetiringContent({ visible, children }: { visible: boolean; child
|
|
|
184
189
|
return;
|
|
185
190
|
}
|
|
186
191
|
if (!element) return;
|
|
187
|
-
|
|
188
|
-
|
|
192
|
+
// Reduced motion and a hidden page settle immediately. Focus may defer a
|
|
193
|
+
// collapse that will actually play; it must not pin a reduced-motion rewind.
|
|
194
|
+
// Move it to a surviving turn or the reading column first, or the browser
|
|
195
|
+
// drops it on the document when this subtree unmounts.
|
|
196
|
+
let retiredNow = false;
|
|
197
|
+
const retireNow = () => {
|
|
198
|
+
if (retiredNow) return;
|
|
199
|
+
retiredNow = true;
|
|
200
|
+
animation.current?.cancel(); animation.current = null;
|
|
201
|
+
focusSurvivesRetire(element);
|
|
202
|
+
setPresent(false); retired.current?.();
|
|
203
|
+
};
|
|
204
|
+
if (!enabled || document.hidden) { retireNow(); return; }
|
|
205
|
+
// The retiring-content harness stubs document without addEventListener.
|
|
206
|
+
const canListen = typeof document.addEventListener === 'function';
|
|
207
|
+
const holdsFocus = element.contains(document.activeElement);
|
|
208
|
+
if (holdsFocus || focusHeld) {
|
|
209
|
+
if (holdsFocus) setFocusHeld(true);
|
|
210
|
+
// Focus defers only a collapse that will play. `document.hidden` is not
|
|
211
|
+
// state, so a page hidden while focus waits must retire from here.
|
|
212
|
+
const onHiddenWhileHeld = () => { if (document.hidden) retireNow(); };
|
|
213
|
+
if (canListen) document.addEventListener('visibilitychange', onHiddenWhileHeld);
|
|
214
|
+
return () => { if (canListen) document.removeEventListener('visibilitychange', onHiddenWhileHeld); };
|
|
215
|
+
}
|
|
189
216
|
const from = element.getBoundingClientRect().height;
|
|
190
217
|
animation.current?.cancel(); animation.current = null;
|
|
191
|
-
if (
|
|
218
|
+
if (from < 1) { setPresent(false); retired.current?.(); return; }
|
|
192
219
|
const next = element.animate([{ height: `${from}px`, opacity: 1 }, { height: '0px', opacity: 0 }], { duration: 220, easing: EASING, fill: 'both' });
|
|
193
220
|
animation.current = next;
|
|
194
|
-
|
|
221
|
+
let settled = false;
|
|
222
|
+
const settle = () => {
|
|
223
|
+
if (settled || animation.current !== next) return;
|
|
224
|
+
settled = true;
|
|
225
|
+
animation.current = null; next.cancel(); setPresent(false); retired.current?.();
|
|
226
|
+
};
|
|
195
227
|
next.onfinish = settle;
|
|
228
|
+
// #60: a stalled WAAPI finish must not leave the row mounted.
|
|
196
229
|
const deadline = window.setTimeout(settle, 220 + 240);
|
|
230
|
+
const onHide = () => { if (document.hidden) settle(); };
|
|
231
|
+
if (canListen) document.addEventListener('visibilitychange', onHide);
|
|
197
232
|
return () => {
|
|
198
233
|
window.clearTimeout(deadline);
|
|
234
|
+
if (canListen) document.removeEventListener('visibilitychange', onHide);
|
|
199
235
|
if (animation.current === next) animation.current = null;
|
|
200
236
|
next.cancel();
|
|
201
237
|
};
|
|
@@ -208,6 +244,98 @@ export function RetiringContent({ visible, children }: { visible: boolean; child
|
|
|
208
244
|
</div>;
|
|
209
245
|
}
|
|
210
246
|
|
|
247
|
+
/**
|
|
248
|
+
* Keeps a departing turn mounted for the length of its own collapse.
|
|
249
|
+
*
|
|
250
|
+
* A rewind removes turns from the visible order, and unmounting them outright
|
|
251
|
+
* snapped the transcript: every withdrawn row disappeared in one frame with
|
|
252
|
+
* nothing to scroll. Instead each departing turn is retained, rendered with
|
|
253
|
+
* `visible={false}` so it animates to zero height, and released only once the
|
|
254
|
+
* collapse has settled — so the reader watches the rows fold away and the rows
|
|
255
|
+
* below glide up into their place.
|
|
256
|
+
*
|
|
257
|
+
* Live slots follow the incoming group order, so older history stays above the
|
|
258
|
+
* tail. A collapsing turn stays next to the live neighbour that preceded it;
|
|
259
|
+
* appending it would jump it to the bottom for the length of the animation.
|
|
260
|
+
* Retention is bounded by the animation itself: `onRetired`
|
|
261
|
+
* drops the slot, so a departing turn lives for one collapse and no longer —
|
|
262
|
+
* and a key that comes back later is re-added as a live slot.
|
|
263
|
+
*/
|
|
264
|
+
export function RetiringTurns<T extends { readonly key: string }>({ groups, render }: {
|
|
265
|
+
groups: readonly T[];
|
|
266
|
+
render: (group: T) => ReactNode;
|
|
267
|
+
}) {
|
|
268
|
+
const [slots, setSlots] = useState<readonly TurnSlot<T>[]>(() =>
|
|
269
|
+
groups.map((group) => ({ group, live: true })),
|
|
270
|
+
);
|
|
271
|
+
// Reconcile after every commit rather than during render: a key that left the
|
|
272
|
+
// order becomes `live: false` and keeps its index, which is what lets the
|
|
273
|
+
// collapse play in place instead of jumping the turn to the bottom.
|
|
274
|
+
useLayoutEffect(() => {
|
|
275
|
+
setSlots(current => reconcileTurnSlots(current, groups));
|
|
276
|
+
}, [groups]);
|
|
277
|
+
return (
|
|
278
|
+
<>
|
|
279
|
+
{slots.map((slot) => (
|
|
280
|
+
<RetiringContent
|
|
281
|
+
key={slot.group.key}
|
|
282
|
+
visible={slot.live}
|
|
283
|
+
onRetired={() => setSlots((current) => current.filter((candidate) =>
|
|
284
|
+
candidate.live || candidate.group.key !== slot.group.key))}
|
|
285
|
+
>
|
|
286
|
+
{render(slot.group)}
|
|
287
|
+
</RetiringContent>
|
|
288
|
+
))}
|
|
289
|
+
</>
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/** A turn that is still on screen, not one this commit is about to unmount. */
|
|
294
|
+
function survivingTurn(node: Element): HTMLElement | null {
|
|
295
|
+
if (!(node instanceof HTMLElement) || node.dataset.readerRetiring === 'retiring') return null;
|
|
296
|
+
const turn = node.hasAttribute('data-reader-turn') ? node : node.querySelector<HTMLElement>('[data-reader-turn]');
|
|
297
|
+
if (turn === null) return null;
|
|
298
|
+
const retiring = turn.closest('[data-reader-retiring]');
|
|
299
|
+
if (retiring instanceof HTMLElement && retiring.dataset.readerRetiring === 'retiring') return null;
|
|
300
|
+
return turn;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Where focus goes when cut content is removed without an animation.
|
|
305
|
+
* Prefer the nearest turn that is still live. Otherwise the reading column
|
|
306
|
+
* (or the host scrollport) so focus does not fall through to the document.
|
|
307
|
+
*/
|
|
308
|
+
function retireFocusTarget(element: HTMLElement): HTMLElement | null {
|
|
309
|
+
const parent = element.parentElement;
|
|
310
|
+
if (parent) {
|
|
311
|
+
const siblings = [...parent.children];
|
|
312
|
+
const index = siblings.indexOf(element);
|
|
313
|
+
for (let cursor = index - 1; cursor >= 0; cursor--) {
|
|
314
|
+
const turn = survivingTurn(siblings[cursor]!);
|
|
315
|
+
if (turn) return turn;
|
|
316
|
+
}
|
|
317
|
+
for (let cursor = index + 1; cursor < siblings.length; cursor++) {
|
|
318
|
+
const turn = survivingTurn(siblings[cursor]!);
|
|
319
|
+
if (turn) return turn;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
const column = element.closest<HTMLElement>('[data-chat-flow]');
|
|
323
|
+
if (column && !element.contains(column)) return column;
|
|
324
|
+
const scroll = element.closest<HTMLElement>('[data-conversation-scroll]');
|
|
325
|
+
if (scroll && !element.contains(scroll)) return scroll;
|
|
326
|
+
return null;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/** Move focus out of `element` before it unmounts. A no-op when focus is elsewhere. */
|
|
330
|
+
function focusSurvivesRetire(element: HTMLElement): void {
|
|
331
|
+
const active = document.activeElement;
|
|
332
|
+
if (active === null || !element.contains(active)) return;
|
|
333
|
+
const target = retireFocusTarget(element);
|
|
334
|
+
if (target === null || element.contains(target)) return;
|
|
335
|
+
if (target.tabIndex < 0) target.tabIndex = -1;
|
|
336
|
+
target.focus({ preventScroll: true });
|
|
337
|
+
}
|
|
338
|
+
|
|
211
339
|
// DOM-only behavior: the native Session remains the sole source of business data.
|
|
212
340
|
export function useReadingScroll(root: RefObject<HTMLElement>, motion: boolean): {
|
|
213
341
|
detached: boolean;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { createElement, memo, useMemo, type ComponentType, type ReactNode } from 'react';
|
|
1
|
+
import { createElement, memo, useEffect, useLayoutEffect, useMemo, useRef, type ComponentType, type ReactNode, type RefObject } from 'react';
|
|
2
2
|
import type { Context } from '@deepseek-ai/cordis';
|
|
3
|
+
import type { UseGroupAction } from '@deepseek-ai/dsh-client-ui-chat/client';
|
|
3
4
|
import type { SlotEntryDef, SlotMap, SlotSpec, StoredEntry } from '@deepseek-ai/dsh-client-ui-slots';
|
|
4
5
|
import type {} from '@deepseek-ai/dsh-client-ui-renderer/client';
|
|
5
6
|
|
|
@@ -18,7 +19,8 @@ export const OFFICIAL_SLOTS = {
|
|
|
18
19
|
tools: 'tool.call.toolview',
|
|
19
20
|
tail: 'conversation.chat.turnTail',
|
|
20
21
|
nodes: 'conversation.chat.node',
|
|
21
|
-
|
|
22
|
+
messageImages: 'conversation.chat.message.images',
|
|
23
|
+
userImages: 'conversation.chat.user.images',
|
|
22
24
|
} as const;
|
|
23
25
|
export type OfficialFamily = keyof typeof OFFICIAL_SLOTS;
|
|
24
26
|
export const OFFICIAL_SEATS = {
|
|
@@ -26,7 +28,8 @@ export const OFFICIAL_SEATS = {
|
|
|
26
28
|
tools: 'dsh-better-display.official.tools/tool.call.toolview',
|
|
27
29
|
tail: 'dsh-better-display.official.tail/conversation.chat.turnTail',
|
|
28
30
|
nodes: 'dsh-better-display.official.nodes/conversation.chat.node',
|
|
29
|
-
|
|
31
|
+
messageImages: 'dsh-better-display.official.messageImages/conversation.chat.message.images',
|
|
32
|
+
userImages: 'dsh-better-display.official.userImages/conversation.chat.user.images',
|
|
30
33
|
} as const;
|
|
31
34
|
export type OfficialSeat = typeof OFFICIAL_SEATS[OfficialFamily];
|
|
32
35
|
export const officialSeat = (family: OfficialFamily, source: string = OFFICIAL_SLOTS[family]) =>
|
|
@@ -52,22 +55,68 @@ declare module '@deepseek-ai/dsh-client-ui-slots' {
|
|
|
52
55
|
'dsh-better-display.official.tools/tool.call.toolview': SlotMap['tool.call.toolview'];
|
|
53
56
|
'dsh-better-display.official.tail/conversation.chat.turnTail': SlotMap['conversation.chat.turnTail'];
|
|
54
57
|
'dsh-better-display.official.nodes/conversation.chat.node': SlotMap['conversation.chat.node'];
|
|
55
|
-
'dsh-better-display.official.
|
|
58
|
+
'dsh-better-display.official.messageImages/conversation.chat.message.images': SlotMap['conversation.chat.message.images'];
|
|
59
|
+
'dsh-better-display.official.userImages/conversation.chat.user.images': SlotMap['conversation.chat.user.images'];
|
|
56
60
|
}
|
|
57
61
|
}
|
|
58
62
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
/**
|
|
64
|
+
* Searchable hide for official nodes drawn outside the Chat flow viewport.
|
|
65
|
+
* The flow's own `useGroupAction` is not in scope here; this keeps the same
|
|
66
|
+
* `hidden="until-found"` contract so browser find can still reveal the row.
|
|
67
|
+
*/
|
|
68
|
+
export function useReaderGroupAction(hidden: boolean, reveal: () => void): RefObject<HTMLDivElement> {
|
|
69
|
+
const ref = useRef<HTMLDivElement>(null);
|
|
70
|
+
useLayoutEffect(() => {
|
|
71
|
+
const element = ref.current;
|
|
72
|
+
if (element === null) return;
|
|
73
|
+
if (hidden && element.contains(element.ownerDocument.activeElement)) {
|
|
74
|
+
reveal();
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (hidden) element.setAttribute('hidden', 'until-found');
|
|
78
|
+
else element.removeAttribute('hidden');
|
|
79
|
+
}, [hidden, reveal]);
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
const element = ref.current;
|
|
82
|
+
if (element === null) return;
|
|
83
|
+
element.addEventListener('beforematch', reveal);
|
|
84
|
+
return () => { element.removeEventListener('beforematch', reveal); };
|
|
85
|
+
}, [reveal]);
|
|
86
|
+
return ref;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export const readerGroupAction: UseGroupAction = useReaderGroupAction;
|
|
90
|
+
|
|
91
|
+
// Reader draws these rows itself. Everything else, including future kinds, is
|
|
92
|
+
// mirrored so the official renderer still runs inside the reading view.
|
|
93
|
+
// 'user' and 'steering' stay mirrored (message-recall buttons and the like).
|
|
94
|
+
// 'assistant-step' is special: the official renderer is priority 0 and Reader
|
|
95
|
+
// keeps that presentation. A strictly lower priority is a keyed-slot
|
|
96
|
+
// replacement (lowest priority renders) and is mirrored for body content.
|
|
97
|
+
const READER_OWNED_NODES = new Set(['tool-call', 'turn-tail', 'turn-process']);
|
|
98
|
+
|
|
99
|
+
/** Official `AssistantNodeView` registers at priority 0. Lower wins. */
|
|
100
|
+
export const OFFICIAL_ASSISTANT_PRIORITY = 0;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Mirror a chat-node registration into the Reader seat.
|
|
104
|
+
* Assistant replacements are the entries that would actually replace the
|
|
105
|
+
* official renderer on the host. The official priority itself stays out, so
|
|
106
|
+
* Reader keeps its own answer markdown until a plugin opts in.
|
|
107
|
+
*/
|
|
108
|
+
export function acceptMirroredChatNode(entry: StoredEntry): boolean {
|
|
109
|
+
const key = entry.options.key ?? '';
|
|
110
|
+
if (key === 'assistant-step') return (entry.options.priority ?? OFFICIAL_ASSISTANT_PRIORITY) < OFFICIAL_ASSISTANT_PRIORITY;
|
|
111
|
+
return !READER_OWNED_NODES.has(key);
|
|
112
|
+
}
|
|
65
113
|
const EXPECTED: Record<OfficialFamily, Spec> = {
|
|
66
114
|
actions: { kind: 'list', scope: 'session' },
|
|
67
115
|
tools: { kind: 'keyed', scope: 'session' },
|
|
68
116
|
tail: { kind: 'list', scope: 'session' },
|
|
69
117
|
nodes: { kind: 'keyed', scope: 'session' },
|
|
70
|
-
|
|
118
|
+
messageImages: { kind: 'single', scope: 'session' },
|
|
119
|
+
userImages: { kind: 'single', scope: 'session' },
|
|
71
120
|
};
|
|
72
121
|
|
|
73
122
|
/**
|
|
@@ -201,7 +250,7 @@ export function installOfficialSlots(ctx: Context): () => void {
|
|
|
201
250
|
throw new Error(`Official slot contract changed: ${source}`);
|
|
202
251
|
}
|
|
203
252
|
return mirrorOfficialSlot(slots, source, target, `dsh-better-display.official.${family}`,
|
|
204
|
-
family === 'nodes' ?
|
|
253
|
+
family === 'nodes' ? acceptMirroredChatNode : undefined);
|
|
205
254
|
}));
|
|
206
255
|
}
|
|
207
256
|
} catch (error) {
|
|
@@ -21,6 +21,7 @@ export const readBlockLabels: ReadBlockLabels = {
|
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
export const terminalBlockLabels: TerminalBlockLabels = {
|
|
24
|
+
commandLine: line => `命令第 ${line} 行`,
|
|
24
25
|
signal: signal => `信号 ${signal}`, exitCode: code => `退出码 ${code}`, noExitCode: '无退出码',
|
|
25
26
|
running: '执行中', failed: '失败', done: '已完成', copy: '复制', copied: '已复制',
|
|
26
27
|
noOutput: '没有输出', collapseAria: '收起命令输出', collapse: '收起',
|
package/src/client/projection.ts
CHANGED
|
@@ -33,6 +33,13 @@ export function boundaryOf(turn: TurnLocation | undefined): TurnBoundary {
|
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
/**
|
|
37
|
+
* A settled body step before the closing step of a successful turn.
|
|
38
|
+
*
|
|
39
|
+
* This is presentation classification only. Narration is never process content
|
|
40
|
+
* and never folds. The flag only marks body text that is no longer the turn's
|
|
41
|
+
* final answer, so copy and fork stay on that final answer.
|
|
42
|
+
*/
|
|
36
43
|
export function isEarlierNarration(data: AssistantChatData, boundary: TurnBoundary): boolean {
|
|
37
44
|
// New body text, a tool call, or a settled step is not a completed turn.
|
|
38
45
|
if (data.status !== 'settled' || boundary.status !== 'closed' || boundary.reason !== 'completed') return false;
|
|
@@ -49,13 +56,18 @@ export function processChoiceKey(groupKey: string, boundary: TurnBoundary): stri
|
|
|
49
56
|
return `${groupKey}:${boundary.status}:${boundary.reason ?? 'pending'}`;
|
|
50
57
|
}
|
|
51
58
|
|
|
52
|
-
/**
|
|
53
|
-
|
|
59
|
+
/**
|
|
60
|
+
* A body-only assistant step is not a thinking/process disclosure.
|
|
61
|
+
*
|
|
62
|
+
* Narration (text/image/other blocks) is always visible, so it never counts as
|
|
63
|
+
* foldable process content; only literal reasoning does. Tool calls arrive as
|
|
64
|
+
* their own flow entries and are checked separately by the reader.
|
|
65
|
+
*/
|
|
66
|
+
export function hasProcessContent(node: ChatConversationViewNode | undefined, _boundary: TurnBoundary): boolean {
|
|
54
67
|
if (!node || node.visibility === 'hidden') return false;
|
|
55
68
|
if (node.kind === 'assistant-step') {
|
|
56
69
|
const data = node.data as AssistantChatData;
|
|
57
|
-
return data.blocks.some(block => block.kind === 'reasoning' && block.text.trim() !== '')
|
|
58
|
-
|| (isEarlierNarration(data, boundary) && hasVisibleBody(data.blocks));
|
|
70
|
+
return data.blocks.some(block => block.kind === 'reasoning' && block.text.trim() !== '');
|
|
59
71
|
}
|
|
60
72
|
return node.kind === 'context' || node.kind === 'model-retry' || node.kind === 'system-prompt' || node.kind === 'turn-process'
|
|
61
73
|
|| node.kind === 'command' || node.kind === 'manual-compaction' || node.kind === 'compaction';
|