You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maka.apache.org by as...@apache.org on 2026/09/14 09:28:41 UTC
(maka) 02/02: refactor(ui): keep processing sequences stable across tool projection
This is an automated email from the ASF dual-hosted git repository.
Astro-Han pushed a commit to branch fix/transcript-viewport-mounting
in repository https://gitbox.apache.org/repos/asf/maka.git
commit 14e8581e1bbad25e24c6021a502bb5ce2da24ab1
Author: AstroHan <le...@outlook.com>
AuthorDate: Mon Sep 14 17:28:23 2026 +0800
refactor(ui): keep processing sequences stable across tool projection
---
.../__tests__/chat-turn-answer-identity.test.tsx | 17 ++++++++++++++
packages/ui/src/chat-turn.tsx | 11 +++++----
packages/ui/src/materialize.ts | 2 +-
packages/ui/src/timeline-fold.ts | 27 ++++++++--------------
4 files changed, 34 insertions(+), 23 deletions(-)
diff --git a/packages/ui/src/__tests__/chat-turn-answer-identity.test.tsx b/packages/ui/src/__tests__/chat-turn-answer-identity.test.tsx
index 25db1a595d..dfd58c8760 100644
--- a/packages/ui/src/__tests__/chat-turn-answer-identity.test.tsx
+++ b/packages/ui/src/__tests__/chat-turn-answer-identity.test.tsx
@@ -182,6 +182,23 @@ test('keeps the assistant answer element as a turn settles around it', async ()
);
});
+test('keeps reasoning expanded when its last neighboring tool is projected away', async () => {
+ const { container, root } = domRoot();
+ const thinking: TurnTimelineItem = {
+ kind: 'thinking', messageId: 'reason-1', text: 'First observation', live: false,
+ };
+ await renderTurn(root, turnWith([thinking, RUNNING_TOOL, ANSWER]));
+ const header = container.querySelector('[data-slot="activity-card-header"]');
+ assert.ok(header);
+ await act(() => { header.dispatchEvent(new window.Event('click', { bubbles: true })); });
+ assert.equal(header.getAttribute('aria-expanded'), 'true');
+ await renderTurn(root, turnWith([thinking, ANSWER]));
+ const after = container.querySelector('[data-slot="activity-card-header"]');
+ assert.ok(after);
+ assert.ok(after.isSameNode(header));
+ assert.equal(after.getAttribute('aria-expanded'), 'true');
+});
+
test('redacts secrets before rendering a settled collapsed reasoning preview', async () => {
const { container, root } = domRoot();
await renderTurn(root, turnWith([
diff --git a/packages/ui/src/chat-turn.tsx b/packages/ui/src/chat-turn.tsx
index 089b85dce4..41185a203b 100644
--- a/packages/ui/src/chat-turn.tsx
+++ b/packages/ui/src/chat-turn.tsx
@@ -483,7 +483,7 @@ export const TurnView = memo(function TurnView(props: {
turn.timeline.length > 0 ||
!!props.liveStreaming ||
(turn.user !== undefined && turn.statusSource === 'recorded' && turn.status !== 'running');
- // #1307: the collapsed "Processing" fold is derived at render time from the
+ // The processing layout sequence is derived at render time from the
// flat timeline. Settled turn identities are stable (memoized projections),
// so this only recomputes for the turn whose timeline actually changed.
const foldedTimeline = useMemo(() => foldTimeline(turn.timeline), [turn.timeline]);
@@ -675,7 +675,7 @@ export const TurnView = memo(function TurnView(props: {
(materialize.ts): each step's 深度思考 disclosure, answer bubble,
and Astryx tool group in the order the model produced them.
#1307: runs of reasoning + tools between answer texts render
- through the derived fold as collapsed Processing blocks. */}
+ through the derived grouping as processing sequences. */}
{segment.items.map((item, index) =>
item.kind === 'processing' ? (
<ProcessingBlock
@@ -814,8 +814,8 @@ type ConversationSegment =
* What this answer replies to: the steering message that opened it, or
* the turn itself for the first answer. This is the segment's identity —
* its React key must not be derived from its contents, because those
- * change as the turn runs (a Processing fold dissolves once its last
- * tools group is projected away) and a changing key remounts the whole
+ * change as the turn runs (a tools-only sequence disappears when its
+ * tools are projected away) and a changing key remounts the whole
* answer, costing the user their scroll position, any disclosure they
* had open, and any text Selection held inside it.
*
@@ -1289,6 +1289,9 @@ function ProcessingBlock(props: {
<div
className="maka-processing-sequence"
data-maka-transcript-boundary=""
+ // Pure reasoning keeps the answer column's spacing without changing
+ // component ancestry when neighboring tools appear or disappear.
+ style={entries.some((entry) => entry.kind === 'tools') ? undefined : { rowGap: 'inherit' }}
>
{entries.map((entry, index) => (
<TurnTimelineEntry
diff --git a/packages/ui/src/materialize.ts b/packages/ui/src/materialize.ts
index b97e645459..95ac6e3bdf 100644
--- a/packages/ui/src/materialize.ts
+++ b/packages/ui/src/materialize.ts
@@ -360,7 +360,7 @@ function mergeLiveOverPersisted(
* - `user`: an instruction inserted after the turn began, displayed where
* Runtime acknowledged it.
*
- * The model stays FLAT: the collapsed "Processing" fold (#1307) is a render
+ * The model stays FLAT: grouping adjacent reasoning/tools for spacing is a render
* concern applied by `foldTimeline` (timeline-fold.ts) at the component layer,
* so timeline-rewriting passes (overlayLiveTurn, projectTurnTools, shell-run
* folding) never have to maintain a nesting invariant.
diff --git a/packages/ui/src/timeline-fold.ts b/packages/ui/src/timeline-fold.ts
index 289d2af242..1f91a8813c 100644
--- a/packages/ui/src/timeline-fold.ts
+++ b/packages/ui/src/timeline-fold.ts
@@ -20,7 +20,7 @@
import type { TurnTimelineItem } from './materialize.js';
/**
- * Render-layer fold for the collapsed "Processing" block (#1307).
+ * Groups adjacent reasoning and tools for their shared layout spacing.
*
* The turn timeline model (`TurnTimelineItem`) stays FLAT — every
* timeline-rewriting pass (overlayLiveTurn, projectTurnTools, shell-run
@@ -29,22 +29,17 @@ import type { TurnTimelineItem } from './materialize.js';
* before rendering:
*
* - answer `text` and inserted `user` entries stay in place and bound groups;
- * - a maximal thinking+tools run between two texts folds into ONE
- * `processing` block when it contains at least one tools group, preserving
- * the run's interleaved order as `children`;
- * - a pure-thinking run stays bare (the 深度思考 disclosure renders it
- * directly — wrapping a lone reasoning block would just double the fold).
+ * - every thinking/tools run becomes one `processing` sequence, preserving
+ * the run's interleaved order as `children`. This wrapper has no disclosure;
+ * reasoning and tool components own their individual expansion states.
*
* Each block carries a stable `id` derived from the preceding text or inserted
* user entry's messageId (`'start'` when the block opens the turn). Between two boundaries there
* is at most one block, so the id is unique per turn — and, unlike a key
* guessed from the first child, it survives the first tool being projected
- * away (shell-run folding) without remounting the disclosure or dropping a
- * manual open/close. When projection removes a block's LAST tools group the
- * block itself dissolves (the remaining run is pure thinking), so the bare
- * 深度思考 entries remount and any manual open state inside is reset — the
- * accepted cost of deriving block existence at render time instead of
- * representing a tools-less block in the model.
+ * away (shell-run folding) without remounting the disclosure or dropping its
+ * expansion state. A remaining reasoning entry keeps the same wrapper even
+ * when the last tool disappears.
*/
/** An entry folded inside a processing block: reasoning or a tool group. */
@@ -57,7 +52,7 @@ export interface ProcessingFold {
children: FoldedTimelineChild[];
}
-export type FoldedTimelineEntry = TurnTimelineItem | ProcessingFold;
+export type FoldedTimelineEntry = Extract<TurnTimelineItem, { kind: 'user' | 'text' }> | ProcessingFold;
export function foldTimeline(items: readonly TurnTimelineItem[]): FoldedTimelineEntry[] {
const out: FoldedTimelineEntry[] = [];
@@ -65,11 +60,7 @@ export function foldTimeline(items: readonly TurnTimelineItem[]): FoldedTimeline
let buffer: FoldedTimelineChild[] | null = null;
const flush = (): void => {
if (buffer && buffer.length > 0) {
- if (buffer.some((child) => child.kind === 'tools')) {
- out.push({ kind: 'processing', id: anchor, children: buffer });
- } else {
- out.push(...buffer);
- }
+ out.push({ kind: 'processing', id: anchor, children: buffer });
}
buffer = null;
};
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org