π€― LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
π fix(conversation): keep final answer visible when a bookkeeping tool trails a folded turn (#16385)
Arvin Xu7494de499a11
diff --git a/src/features/Conversation/Messages/AssistantGroup/components/Group.tsx b/src/features/Conversation/Messages/AssistantGroup/components/Group.tsxindex 5592b393547..81e3d9f1757 100644--- a/src/features/Conversation/Messages/AssistantGroup/components/Group.tsx+++ b/src/features/Conversation/Messages/AssistantGroup/components/Group.tsx@@ -521,12 +521,12 @@ const Group = memo<GroupChildrenProps>(<><ProcessFold durationText={durationText} stepCount={blocks.length}><Flexbox gap={8}>- {processSegments.map((segment, index) => renderSegment(segment, index))}+ {processSegments.map((segment) =>+ renderSegment(segment, segments.indexOf(segment)),+ )}</Flexbox></ProcessFold>- {finalSegments.map((segment, index) =>- renderSegment(segment, processSegments.length + index),- )}+ {finalSegments.map((segment) => renderSegment(segment, segments.indexOf(segment)))}</>) : (<>diff --git a/src/features/Conversation/Messages/AssistantGroup/components/segments.test.ts b/src/features/Conversation/Messages/AssistantGroup/components/segments.test.tsindex 04bb29697b1..95d3e92b156 100644--- a/src/features/Conversation/Messages/AssistantGroup/components/segments.test.ts+++ b/src/features/Conversation/Messages/AssistantGroup/components/segments.test.ts@@ -21,10 +21,26 @@ describe('splitFinalAnswer', () => {expect(finalSegments).toEqual([a('a1'), a('a2')]);});- it('folds everything when the turn ends on a workflow segment', () => {+ it('keeps the final answer visible when a trailing bookkeeping tool follows it', () => {+ // The agent writes its summary, then ends the turn on a "mark task done" tool+ // call. The answer must stay out of the fold; only the trailing tool folds.+ const segments = [w('t1'), a('intro'), w('t2'), a('summary'), w('mark-done')];+ const { processSegments, finalSegments } = splitFinalAnswer(segments);+ expect(processSegments).toEqual([w('t1'), a('intro'), w('t2'), w('mark-done')]);+ expect(finalSegments).toEqual([a('summary')]);+ });++ it('surfaces the lone answer even when the turn ends on a workflow segment', () => {const segments = [a('intro'), w('t1')];const { processSegments, finalSegments } = splitFinalAnswer(segments);- expect(processSegments).toEqual([a('intro'), w('t1')]);+ expect(processSegments).toEqual([w('t1')]);+ expect(finalSegments).toEqual([a('intro')]);+ });++ it('folds everything when the turn has no answer segment at all', () => {+ const segments = [w('t1'), w('t2')];+ const { processSegments, finalSegments } = splitFinalAnswer(segments);+ expect(processSegments).toEqual([w('t1'), w('t2')]);expect(finalSegments).toEqual([]);});diff --git a/src/features/Conversation/Messages/AssistantGroup/components/segments.ts b/src/features/Conversation/Messages/AssistantGroup/components/segments.tsindex 7cde252a1ee..f8bb6c3efd9 100644--- a/src/features/Conversation/Messages/AssistantGroup/components/segments.ts+++ b/src/features/Conversation/Messages/AssistantGroup/components/segments.ts@@ -15,20 +15,38 @@ export type GroupRenderSegment = AnswerSegment | WorkflowSegment;/*** Split a turn's render segments into its process and its final answer.*- * The trailing run of `answer` segments is the final answer (always shown);- * everything before it β tools, reasoning, intermediate prose β is the process- * that folds under the Codex-style "ε·²ε€η {duration}" header.+ * The final answer is the *last run* of `answer` segments β even when one or+ * more bookkeeping tool calls (e.g. "mark task done", "update issue") trail it.+ * Those trailing workflow segments fold into the process alongside the leading+ * reasoning/tools so the answer text stays visible, rather than disappearing+ * inside the fold whenever a turn happens to end on a tool call. Everything that+ * is not the final answer β leading tools/reasoning/intermediate prose and any+ * trailing bookkeeping tools β folds under the Codex-style "ε·²ε€η {duration}"+ * header. A turn with no answer segment at all has no final answer to surface.*/export const splitFinalAnswer = (segments: GroupRenderSegment[],): { finalSegments: GroupRenderSegment[]; processSegments: GroupRenderSegment[] } => {- let splitIndex = segments.length;- while (splitIndex > 0 && segments[splitIndex - 1].kind === 'answer') {- splitIndex -= 1;+ let lastAnswerIndex = -1;+ for (let i = segments.length - 1; i >= 0; i--) {+ if (segments[i].kind === 'answer') {+ lastAnswerIndex = i;+ break;+ }}++ if (lastAnswerIndex === -1) {+ return { finalSegments: [], processSegments: segments };+ }++ let runStart = lastAnswerIndex;+ while (runStart > 0 && segments[runStart - 1].kind === 'answer') {+ runStart -= 1;+ }+return {- finalSegments: segments.slice(splitIndex),- processSegments: segments.slice(0, splitIndex),+ finalSegments: segments.slice(runStart, lastAnswerIndex + 1),+ processSegments: [...segments.slice(0, runStart), ...segments.slice(lastAnswerIndex + 1)],};};