Join turn controls and records into one process frame

This commit is contained in:
QQ 2026-11-28 18:57:42 +08:00
parent a388edf343
commit 2020a6ebc3
6 changed files with 74 additions and 40 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

@ -101,10 +101,10 @@ function FlowCell({ hidden, instant, motion, rowKey, children, summary = false,
</div>; </div>;
} }
export function ChoreographedFlow({ frame, motion, enabled, urgent, open, onOpenChange, processOpen, renderStep, id }: { export function ChoreographedFlow({ frame, motion, enabled, urgent, open, onOpenChange, processOpen, renderStep, id, status }: {
frame: PresentationFrame; motion: boolean; enabled: boolean; urgent: boolean; frame: PresentationFrame; motion: boolean; enabled: boolean; urgent: boolean;
open: Readonly<Record<string, boolean>>; onOpenChange: (key: string, value: boolean) => void; open: Readonly<Record<string, boolean>>; onOpenChange: (key: string, value: boolean) => void;
processOpen: boolean; renderStep: (step: LiveStep, folded: boolean) => ReactNode; id: string; processOpen: boolean; renderStep: (step: LiveStep, folded: boolean) => ReactNode; id: string; status?: ReactNode;
}) { }) {
const root = useRef<HTMLDivElement>(null); const root = useRef<HTMLDivElement>(null);
const stream = useContext(StreamMotionContext); const stream = useContext(StreamMotionContext);
@ -207,7 +207,8 @@ export function ChoreographedFlow({ frame, motion, enabled, urgent, open, onOpen
el.dispatchEvent(new CustomEvent('reader-layout-start', { bubbles: true })); el.dispatchEvent(new CustomEvent('reader-layout-start', { bubbles: true }));
// Opacity alone still inserts the new layout in one frame. Open real space // Opacity alone still inserts the new layout in one frame. Open real space
// first; text stays paused until this entry finishes, then catches up. // first; text stays paused until this entry finishes, then catches up.
const animations = Array.from(el.children).filter(child => !(child as HTMLElement).hidden && !state.beforeKeys.has((child as HTMLElement).dataset.flowKey!)) const animations = Array.from(el.querySelectorAll<HTMLElement>(':scope > [data-flow-key]:not([hidden])'))
.filter(child => !state.beforeKeys.has(child.dataset.flowKey!))
.map(child => child.animate([ .map(child => child.animate([
{ height: '0px', opacity: 0 }, { height: '0px', opacity: 0 },
{ height: `${child.getBoundingClientRect().height}px`, opacity: 1 }, { height: `${child.getBoundingClientRect().height}px`, opacity: 1 },
@ -223,16 +224,20 @@ export function ChoreographedFlow({ frame, motion, enabled, urgent, open, onOpen
const rows = state.phase === 'collapse' ? collapseRows(state.shown.items, state.target.items) : flowRows(source.items); const rows = state.phase === 'collapse' ? collapseRows(state.shown.items, state.target.items) : flowRows(source.items);
const cells = rows.map(row => { const cells = rows.map(row => {
if (row.kind === 'summary') return { row, key: row.key, hidden: false, process: true }; if (row.kind === 'summary') return { row, key: row.key, hidden: false, process: true };
const process = row.step.kind === 'reasoning' || row.step.kind === 'tool' const node = row.step.kind === 'other' ? source.snapshot.nodes.get(row.step.nodeKey) : undefined;
|| (row.step.kind === 'other' && isProcessRecord(source.snapshot.nodes.get(row.step.nodeKey))); const trigger = !!status && node?.kind === 'turn-trigger';
const hidden = !!row.foldKey && (!processOpen || !open[row.foldKey]) const process = row.step.kind === 'reasoning' || row.step.kind === 'tool' || trigger || isProcessRecord(node);
const hidden = (trigger && !processOpen) || !!row.foldKey && (!processOpen || !open[row.foldKey])
|| node?.kind === 'turn-process'
|| (blocked && state.phase !== 'collapse' && !state.beforeKeys.has(row.key)); || (blocked && state.phase !== 'collapse' && !state.beforeKeys.has(row.key));
return { row, key: row.key, hidden, process: processOpen && process }; return { row, key: row.key, hidden, process: processOpen && process };
}); });
const frames = processFrames(cells); const header = { key: 'process-status', hidden: false, process: true };
const frames = processFrames(status ? [header, ...cells] : cells);
return <FlowSnapshot.Provider value={source.snapshot}> return <FlowSnapshot.Provider value={source.snapshot}>
<StreamMotionContext.Provider value={{ ...stream, paused: state.phase !== 'idle', resumed: state.phase === 'reveal' }}> <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"> <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 }) => { {cells.map(({ row, hidden }) => {
const processFrame = frames.get(row.key); 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}> if (row.kind === 'summary') return <FlowCell key={row.key} rowKey={row.key} hidden={false} instant motion={motion} summary processFrame={processFrame}>

View File

@ -568,6 +568,7 @@
/* A null-rendered ProcessFragment must contribute no cumulative row spacing. */ /* A null-rendered ProcessFragment must contribute no cumulative row spacing. */
.flowCellInner:empty { padding-bottom: 0; } .flowCellInner:empty { padding-bottom: 0; }
/* Join contiguous process cells visually so each step keeps its render key and animation. */ /* 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) { .flowCell[data-flow-process] > .flowCellInner:not(:empty) {
margin-bottom: 16px; margin-bottom: 16px;
padding: 4px 8px; padding: 4px 8px;
@ -575,6 +576,7 @@
border-radius: 12px; border-radius: 12px;
background: var(--dsw-alias-bg-module-platform); 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) { .flowCell:is([data-flow-process=start], [data-flow-process=middle]) > .flowCellInner:not(:empty) {
margin-bottom: 0; margin-bottom: 0;
border-bottom: 0; border-bottom: 0;
@ -586,7 +588,7 @@
border-start-start-radius: 0; border-start-start-radius: 0;
border-start-end-radius: 0; border-start-end-radius: 0;
} }
.flowCell[data-flow-process] :is(.reasonCard, .toolActivity, .processCard) { .flowCell[data-flow-process] :is(.reasonCard, .toolActivity, .processCard, .toolDetails, :global([data-turn-trigger])) {
border: 0; border: 0;
background: transparent; background: transparent;
} }
@ -729,9 +731,21 @@
padding-left: 10px; padding-left: 10px;
border-radius: 0; border-radius: 0;
} }
.root[data-reader-glass] .turnStickyLanes { display: contents; position: static; top: auto; z-index: auto; }
.root[data-reader-glass] .turnStickyRegion { --reader-code-summary-height: 0px; } .root[data-reader-glass] .turnStickyRegion { --reader-code-summary-height: 0px; }
.root[data-reader-glass] .turnStickyLanes .turnProcessSticky { position: sticky; top: var(--reader-toolbar-height, var(--reader-lane-block, 40px)); z-index: 6; } .turnStickyLanes[data-flow-process] { background-image: none; }
.root[data-reader-glass] .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 {
border: 0;
border-radius: 7px;
background: transparent;
backdrop-filter: none;
}
.turnStickyLanes[data-flow-process] .disclosureButton:hover,
.flowCell[data-flow-process][data-flow-summary] .disclosureButton:hover {
background: var(--dsw-alias-interactive-bg-hover);
}
/* User bubble becomes a sleek translucent frosted pill in skin mode */ /* User bubble becomes a sleek translucent frosted pill in skin mode */
.root[data-reader-glass] .user { .root[data-reader-glass] .user {
background: color-mix(in srgb, var(--dsw-specific-bubble, rgba(0,0,0,.08)) 25%, transparent); background: color-mix(in srgb, var(--dsw-specific-bubble, rgba(0,0,0,.08)) 25%, transparent);

View File

@ -605,16 +605,14 @@ const TurnGroup = memo(function TurnGroup({ group, motion, autoFold, pinnedKeys,
return <section className={css.turn} data-reader-turn={group.turn ?? 'unresolved'} data-reader-turn-state={boundary.status} data-reader-turn-result={boundary.reason ?? undefined}> return <section className={css.turn} data-reader-turn={group.turn ?? 'unresolved'} data-reader-turn-state={boundary.status} data-reader-turn-result={boundary.reason ?? undefined}>
{startsWithUser && <BlockBoundary><MainNode {...shared} useChat={props.useChat} boundary={boundary} nodeKey={group.keys[0]} /></BlockBoundary>} {startsWithUser && <BlockBoundary><MainNode {...shared} useChat={props.useChat} boundary={boundary} nodeKey={group.keys[0]} /></BlockBoundary>}
<div className={css.turnStickyRegion} data-reader-sticky-region> <div className={css.turnStickyRegion} data-reader-sticky-region>
{(showStatusLane || showClosedSummary) && <div className={css.turnStickyLanes}> <ChoreographedFlow id={flowId} frame={presentation} motion={motion} enabled={autoFold && boundary.status === 'open' && !holdingSelection}
<StickyLane kind="status" className={css.turnProcessSticky}> urgent={hasTurnError || interaction !== undefined || !sessionRunning} open={foldOpenByKey} processOpen={expanded}
status={(showStatusLane || showClosedSummary) && <StickyLane kind="status" className={css.turnProcessSticky}>
{showStatusLane && <Disclosure open={expanded} onChange={setExpanded} controls={flowId} buttonRef={processButton} {showStatusLane && <Disclosure open={expanded} onChange={setExpanded} controls={flowId} buttonRef={processButton}
label={<GroupStatus group={group} useChat={props.useChat} pending={interaction} motion={motion} />} />} label={<GroupStatus group={group} useChat={props.useChat} pending={interaction} motion={motion} />} />}
{showClosedSummary && <ClosedProcessSummary open={expanded} onChange={setExpanded} controls={flowId} {showClosedSummary && <ClosedProcessSummary open={expanded} onChange={setExpanded} controls={flowId}
steps={steps.filter(step => step.kind !== 'user' && step.kind !== 'body')} />} steps={steps.filter(step => step.kind !== 'user' && step.kind !== 'body')} />}
</StickyLane> </StickyLane>}
</div>}
<ChoreographedFlow id={flowId} frame={presentation} motion={motion} enabled={autoFold && boundary.status === 'open' && !holdingSelection}
urgent={hasTurnError || interaction !== undefined || !sessionRunning} open={foldOpenByKey} processOpen={expanded}
onOpenChange={(key, value) => { pinProcess(); setFoldOpenByKey(current => ({ ...current, [key]: value })); }} renderStep={renderStep} /> onOpenChange={(key, value) => { pinProcess(); setFoldOpenByKey(current => ({ ...current, [key]: value })); }} renderStep={renderStep} />
</div> </div>
{/* 状态指示永远排在流程之后:AI 的响应永远出现在最新消息(含补充消息)的下方 */} {/* 状态指示永远排在流程之后:AI 的响应永远出现在最新消息(含补充消息)的下方 */}

View File

@ -94,3 +94,11 @@ test('all Reader attachment previews delegate the full reference to the host loa
assert.match(blocks, /loadImage\(attachment\)/u); assert.match(blocks, /loadImage\(attachment\)/u);
assert.doesNotMatch(source, /readAttachment\(attachment\.attachmentId\)/u); assert.doesNotMatch(source, /readAttachment\(attachment\.attachmentId\)/u);
}); });
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, /const hidden = \(trigger && !processOpen\)/u);
assert.match(readerCss, /\.turnStickyLanes\[data-flow-process\],\s*\.flowCell\[data-flow-process\]/u);
assert.match(readerCss, /\[data-flow-process\]\[data-flow-summary\] \.disclosureButton \{[^}]*border: 0/u);
});