Bound process frames with an internal scroll area

This commit is contained in:
QQ 2026-11-28 19:12:39 +08:00
parent 59c6e6e2f5
commit a163b7fd32
7 changed files with 142 additions and 111 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -3,8 +3,8 @@ import type { ReactNode } from 'react';
import type { ChatSnapshot } from '@deepseek-ai/dsh-client-ui-chat/client';
import type { ReaderProps } from './types.js';
import type { LiveStep, LiveTurnItem } from './live-turn.js';
import { collapseRows, containsNewUser, flowRows, FOLD_TIMING, processFrames, retiringKeys } from './fold-choreography.js';
import type { FoldPhase, ProcessFrame } from './fold-choreography.js';
import { collapseRows, containsNewUser, flowRows, FOLD_TIMING, groupProcessRows, retiringKeys } from './fold-choreography.js';
import type { FlowRow, FoldPhase } from './fold-choreography.js';
import { Disclosure } from './motion.js';
import { FoldSummaryText } from './LiveFold.js';
import { DiffStat } from './DiffPanel.js';
@ -12,6 +12,7 @@ import { StreamMotionContext } from './streaming.js';
import css from './Reader.module.css';
import { useSummaryLane } from './StickyLane.js';
const FLOW_CELLS = ':scope > [data-flow-key], :scope > [data-reader-process-frame] > [data-reader-process-scroll] > [data-flow-key]';
const FlowSnapshot = createContext<ChatSnapshot | null>(null);
/** Public projection only. Descendants cannot leak live data through a frozen frame. */
export const useFlowChat: ReaderProps['useChat'] = selector => {
@ -41,8 +42,8 @@ function Summary({ item, open, onChange, motion }: {
}
/** Manual disclosure shares the measured-size path; children survive until finish. */
function FlowCell({ hidden, instant, motion, rowKey, children, summary = false, processFrame }: {
hidden: boolean; instant: boolean; motion: boolean; rowKey: string; children: ReactNode; summary?: boolean; processFrame?: ProcessFrame | undefined;
function FlowCell({ hidden, instant, motion, rowKey, children, summary = false, process }: {
hidden: boolean; instant: boolean; motion: boolean; rowKey: string; children: ReactNode; summary?: boolean; process?: boolean;
}) {
const ref = useRef<HTMLDivElement>(null);
useSummaryLane(ref, summary);
@ -94,7 +95,7 @@ function FlowCell({ hidden, instant, motion, rowKey, children, summary = false,
// applied, which is the only moment the fill can be dropped safely. Without
// it the animation was never cancelled at all and every folded cell kept one.
}, [hidden, instant, motion, present]);
return <div ref={ref} className={css.flowCell} data-flow-key={rowKey} data-flow-summary={summary || undefined} data-flow-process={processFrame}
return <div ref={ref} className={css.flowCell} data-flow-key={rowKey} data-flow-summary={summary || undefined} data-flow-process={process || undefined}
hidden={hidden && !present} aria-hidden={hidden || undefined} {...(hidden ? { inert: '' } : {})}>
{present && <div className={css.flowCellInner}>{children}</div>}
</div>;
@ -135,7 +136,7 @@ export function ChoreographedFlow({ frame, motion, enabled, urgent, open, onOpen
const retiring = new Set(state.retiring);
const animations: Animation[] = [];
el.dispatchEvent(new CustomEvent('reader-layout-start', { bubbles: true }));
for (const cell of el.querySelectorAll<HTMLElement>(':scope > [data-flow-key]')) {
for (const cell of el.querySelectorAll<HTMLElement>(FLOW_CELLS)) {
const key = cell.dataset.flowKey!;
const isHeader = cell.dataset.flowSummary && !state.beforeKeys.has(key);
if (!retiring.has(key) && !isHeader) continue;
@ -210,8 +211,8 @@ export function ChoreographedFlow({ frame, motion, enabled, urgent, open, onOpen
el.dispatchEvent(new CustomEvent('reader-layout-start', { bubbles: true }));
// Opacity alone still inserts the new layout in one frame. Open real space
// first; text stays paused until this entry finishes, then catches up.
const animations = Array.from(el.querySelectorAll<HTMLElement>(':scope > [data-flow-key]:not([hidden])'))
.filter(child => !state.beforeKeys.has(child.dataset.flowKey!))
const animations = Array.from(el.querySelectorAll<HTMLElement>(FLOW_CELLS))
.filter(child => !child.hidden && !state.beforeKeys.has(child.dataset.flowKey!))
.map(child => child.animate([
{ height: '0px', opacity: 0 },
{ height: `${child.getBoundingClientRect().height}px`, opacity: 1 },
@ -235,22 +236,29 @@ export function ChoreographedFlow({ frame, motion, enabled, urgent, open, onOpen
|| (blocked && state.phase !== 'collapse' && !state.beforeKeys.has(row.key));
return { row, key: row.key, hidden, process: processOpen && process };
});
const header = { key: 'process-status', hidden: false, process: true };
const frames = processFrames(status ? [header, ...cells] : cells);
const header = { row: null, key: 'process-status', hidden: false, process: true };
const groups = groupProcessRows(status ? [header, ...cells] : cells);
const renderCell = ({ row, hidden, process }: { row: FlowRow; hidden: boolean; process: boolean }) => {
if (row.kind === 'summary') return <FlowCell key={row.key} rowKey={row.key} hidden={false} instant motion={motion} summary process={process}>
<Summary item={row.item} open={processOpen && !!open[row.key]} onChange={value => onOpenChange(row.key, value)} motion={motion && state.phase !== 'collapse'} />
</FlowCell>;
return <FlowCell key={row.key} rowKey={row.key} hidden={hidden} instant={state.phase !== 'idle'} motion={motion} process={process}>
{renderStep(row.step, !!row.foldKey)}
</FlowCell>;
};
return <FlowSnapshot.Provider value={source.snapshot}>
<StreamMotionContext.Provider value={{ ...stream, paused: state.phase !== 'idle', resumed: state.phase === 'reveal' }}>
<div id={id} ref={root} className={css.choreographedFlow} data-reader-flow data-reader-transition={state.phase} data-ud-motion="fold-choreography">
{status && <div className={css.turnStickyLanes} data-flow-process={frames.get(header.key)}>{status}</div>}
{cells.map(({ row, hidden }) => {
const processFrame = frames.get(row.key);
if (row.kind === 'summary') return <FlowCell key={row.key} rowKey={row.key} hidden={false} instant motion={motion} summary processFrame={processFrame}>
<Summary item={row.item} open={processOpen && !!open[row.key]} onChange={value => onOpenChange(row.key, value)} motion={motion && state.phase !== 'collapse'} />
</FlowCell>;
// Keep retiring child props unchanged until it has actually shrunk.
return <FlowCell key={row.key} rowKey={row.key} hidden={hidden} instant={state.phase !== 'idle'} motion={motion}
processFrame={processFrame}>
{renderStep(row.step, !!row.foldKey)}
</FlowCell>;
{groups.map(group => {
const first = group[0]!;
if (!first.process && first.row) return renderCell({ ...first, row: first.row });
const key = first.row?.kind === 'summary' ? first.row.item.steps[0]?.key ?? first.key : first.key;
return <div key={`process:${key}`} className={css.processViewport} data-reader-process-frame>
{!first.row && <div className={css.turnStickyLanes} data-flow-process>{status}</div>}
<div className={css.processScroll} data-reader-process-scroll tabIndex={0} role="region" aria-label="执行过程">
{group.map(cell => cell.row && renderCell({ ...cell, row: cell.row }))}
</div>
</div>;
})}
</div>
</StreamMotionContext.Provider>

View File

@ -567,33 +567,34 @@
.flowCellInner { display: flex; flex-direction: column; min-width: 0; padding-bottom: 16px; }
/* A null-rendered ProcessFragment must contribute no cumulative row spacing. */
.flowCellInner:empty { padding-bottom: 0; }
/* Join contiguous process cells visually so each step keeps its render key and animation. */
.turnStickyLanes[data-flow-process],
.flowCell[data-flow-process] > .flowCellInner:not(:empty) {
.processViewport {
display: flex;
flex-direction: column;
min-width: 0;
max-height: min(320px, 45vh);
margin-bottom: 16px;
padding: 4px 8px;
box-sizing: border-box;
border: 1px solid var(--dsw-alias-border-l2);
border-radius: 12px;
background: var(--dsw-alias-bg-module-platform);
}
.turnStickyLanes[data-flow-process=start],
.flowCell:is([data-flow-process=start], [data-flow-process=middle]) > .flowCellInner:not(:empty) {
margin-bottom: 0;
border-bottom: 0;
border-end-start-radius: 0;
border-end-end-radius: 0;
}
.flowCell:is([data-flow-process=middle], [data-flow-process=end]) > .flowCellInner:not(:empty) {
border-top: 0;
border-start-start-radius: 0;
border-start-end-radius: 0;
.processScroll {
min-height: 0;
overflow: auto;
overscroll-behavior-y: contain;
padding: 0 8px;
}
.processScroll:not(:has(> .flowCell:not([hidden]))),
.processViewport:not(:has(> .turnStickyLanes, .flowCell:not([hidden]))) { display: none; }
.processScroll > .flowCell > .flowCellInner:not(:empty) { padding: 4px 0; }
.processScroll:focus-visible { outline: 2px solid var(--dsw-alias-state-business-primary); outline-offset: -2px; }
.processViewport > .turnStickyLanes { position: static; flex: none; padding: 4px 8px; }
.root[data-reader-glass] .processViewport { background: transparent; }
.flowCell[data-flow-process] :is(.reasonCard, .toolActivity, .processCard, .toolDetails, :global([data-turn-trigger])) {
border: 0;
background: transparent;
}
.flowCell[data-flow-process] .processCard { padding: 0; }
.root[data-reader-glass] .flowCell[data-flow-process] > .flowCellInner { background: transparent; }
.choreographedFlow[data-reader-transition=collapse] .flowCell * { animation-play-state: paused !important; }
.numberRollExit, .numberRollEnter { animation-duration: 160ms; }
/* A flex item's intrinsic width must include its real label and chevron.
@ -643,7 +644,7 @@
.foldStop { border: 0; background: transparent; color: var(--dsw-alias-label-secondary); padding: 2px 8px; border-radius: 6px; white-space: nowrap; font: inherit; font-size: 12px; line-height: 18px; cursor: pointer; }
.foldStop[data-on] { background: var(--dsw-alias-bg-base); color: var(--dsw-alias-label-primary); }
.flowCell[data-flow-summary]:not([data-flow-process]) > .flowCellInner { padding-bottom: 0; }
.flowCell[data-flow-summary][data-flow-process] { padding-block: 0; box-shadow: none; }
.processScroll > .flowCell[data-flow-summary][data-flow-process] { position: static; min-height: 0; padding-block: 0; box-shadow: none; background: transparent; }
.root[data-reader-glass] .flowCell[data-flow-summary][data-flow-process] { border-left: 0; padding-left: 0; }
.flowCell[data-flow-summary] .disclosureButton, .closedProcessSummary .disclosureButton { width: auto; max-width: 100%; }
.disclosureButton:has([data-reader-fold-summary]),
@ -732,8 +733,7 @@
border-radius: 0;
}
.root[data-reader-glass] .turnStickyRegion { --reader-code-summary-height: 0px; }
.turnStickyLanes[data-flow-process] { background-image: none; }
.root[data-reader-glass] .turnStickyLanes[data-flow-process] { background: transparent; }
.turnStickyLanes[data-flow-process] { background: transparent; }
.turnStickyLanes[data-flow-process] .turnProcessSticky { width: 100%; background: transparent; box-shadow: none; }
.turnStickyLanes[data-flow-process] .disclosureButton,
.flowCell[data-flow-process][data-flow-summary] .disclosureButton {

View File

@ -24,22 +24,18 @@ export type FlowRow =
| { kind: 'summary'; key: string; item: Extract<LiveTurnItem, { kind: 'fold' }> }
| { kind: 'step'; key: string; step: LiveStep; foldKey?: string };
export type ProcessFrame = 'single' | 'start' | 'middle' | 'end';
/** Hidden cells are kept in the flow for animation but do not divide a visible frame. */
export function processFrames(rows: readonly { key: string; hidden: boolean; process: boolean }[]): Map<string, ProcessFrame> {
const visible = rows.filter(row => !row.hidden);
const frames = new Map<string, ProcessFrame>();
visible.forEach((row, index) => {
if (!row.process) return;
const previous = visible[index - 1]?.process;
const next = visible[index + 1]?.process;
frames.set(row.key, previous ? (next ? 'middle' : 'end') : (next ? 'start' : 'single'));
});
return frames;
/** Keep process cells together, including rows temporarily hidden by a fold. */
export function groupProcessRows<T extends { process: boolean }>(rows: readonly T[]): T[][] {
const groups: T[][] = [];
for (const row of rows) {
const previous = groups.at(-1);
if (row.process && previous?.[0]?.process) previous.push(row);
else groups.push([row]);
}
return groups;
}
/** A step always has the same parent and React key, even when its membership changes. */
/** Each step keeps its React key when its fold membership changes. */
export function flowRows(items: readonly LiveTurnItem[]): FlowRow[] {
return items.flatMap((item): FlowRow[] => item.kind === 'fold'
? [{ kind: 'summary', key: item.key, item }, ...item.steps.map(step => ({ kind: 'step' as const, key: step.key, step, foldKey: item.key }))]

View File

@ -1,6 +1,6 @@
import { test } from 'vitest';
import assert from 'node:assert/strict';
import { collapseRows, containsNewUser, flowRows, FOLD_TIMING, processFrames, retiringKeys } from '../src/client/fold-choreography.js';
import { collapseRows, containsNewUser, flowRows, FOLD_TIMING, groupProcessRows, retiringKeys } from '../src/client/fold-choreography.js';
import { presentLiveTurn } from '../src/client/live-turn.js';
import type { LiveStep } from '../src/client/live-turn.js';
const reasoning = (n: number): LiveStep => ({ kind: 'reasoning', key: `r${n}`, nodeKey: `n${n}`, start: 0, blocks: [], step: n });
@ -77,13 +77,16 @@ test('every phase has a bounded budget and a watchdog strictly beyond it', () =>
}
});
test('one frame joins the summary, thought and tool across hidden members', () => {
assert.deepEqual([...processFrames([
test('one scroll box joins process rows across hidden members and ends before the answer', () => {
const groups = groupProcessRows([
{ key: 'summary', process: true, hidden: false },
{ key: 'folded-record', process: true, hidden: true },
{ key: 'thought', process: true, hidden: false },
{ key: 'tool', process: true, hidden: false },
{ key: 'answer', process: false, hidden: false },
{ key: 'next-thought', process: true, hidden: false },
])], [['summary', 'start'], ['thought', 'middle'], ['tool', 'end'], ['next-thought', 'single']]);
]);
assert.deepEqual(groups.map(group => group.map(row => row.key)), [
['summary', 'folded-record', 'thought', 'tool'], ['answer'], ['next-thought'],
]);
});

View File

@ -84,7 +84,8 @@ test('tool rendering reads a snapshot that survives the plugin context', () => {
test('live summaries and visible work share a frame that is removed when folded', () => {
assert.match(flow, /row.kind === 'summary'\) return \{ row, key: row.key, hidden: false, process: true \}/u);
assert.match(flow, /hidden, process: processOpen && process/u);
assert.match(readerCss, /\[data-flow-process\] > \.flowCellInner:not\(:empty\)/u);
assert.match(readerCss, /\.processViewport \{[^}]*max-height: min\(320px, 45vh\)/u);
assert.match(readerCss, /\.processScroll \{[^}]*overflow: auto/u);
assert.match(reader, /const expanded = !autoFold \|\| holdingSelection \|\| processExpanded\(expansionChoice, boundary\)/u);
});
@ -97,8 +98,8 @@ test('all Reader attachment previews delegate the full reference to the host loa
test('the status lane joins the visible process frame and the execution request folds with it', () => {
assert.match(reader, /status=\{\(showStatusLane \|\| showClosedSummary\) && <StickyLane/u);
assert.match(flow, /processFrames\(status \? \[header, \.\.\.cells\] : cells\)/u);
assert.match(flow, /groupProcessRows\(status \? \[header, \.\.\.cells\] : cells\)/u);
assert.match(flow, /const hidden = \(trigger && !processOpen\)/u);
assert.match(readerCss, /\.turnStickyLanes\[data-flow-process\],\s*\.flowCell\[data-flow-process\]/u);
assert.match(flow, /data-reader-process-frame>[\s\S]*?\{status\}[\s\S]*?data-reader-process-scroll/u);
assert.match(readerCss, /\[data-flow-process\]\[data-flow-summary\] \.disclosureButton \{[^}]*border: 0/u);
});