Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

Include thinking blocks in tool call grouping (#6415)

Eric Hayes0381f9765bb9
diff --git a/apps/web/src/features/block-agent/state/tool-groups.test.ts b/apps/web/src/features/block-agent/state/tool-groups.test.ts
index 438ed5eacc..5e67e06b99 100644
--- a/apps/web/src/features/block-agent/state/tool-groups.test.ts
+++ b/apps/web/src/features/block-agent/state/tool-groups.test.ts
@@ -10,6 +10,7 @@ const tool = (): MessagePart => ({
status: 'completed',
detail: { kind: 'read', paths: ['a.rs'] },
});
+const thought = (): MessagePart => ({ kind: 'thought', text: 'thinking...' });
const permission = (): MessagePart => ({
kind: 'permission',
toolCall: 'call',
@@ -62,4 +63,42 @@ describe('segmentParts', () => {
it('is empty for no parts', () => {
expect(segmentParts([])).toEqual([]);
});
+
+ it('groups thinking blocks with tool calls', () => {
+ expect(segmentParts([text(), thought(), tool(), tool(), text()])).toEqual([
+ { kind: 'part', start: 0, end: 1 },
+ { kind: 'tools', start: 1, end: 4 },
+ { kind: 'part', start: 4, end: 5 },
+ ]);
+ });
+
+ it('groups consecutive thinking blocks with tool calls', () => {
+ expect(
+ segmentParts([thought(), tool(), thought(), tool(), thought()])
+ ).toEqual([{ kind: 'tools', start: 0, end: 5 }]);
+ });
+
+ it('keeps a lone thinking block as its own part', () => {
+ expect(segmentParts([text(), thought(), text()])).toEqual([
+ { kind: 'part', start: 0, end: 1 },
+ { kind: 'part', start: 1, end: 2 },
+ { kind: 'part', start: 2, end: 3 },
+ ]);
+ });
+
+ it('groups thinking blocks at the start with tool calls', () => {
+ expect(segmentParts([thought(), thought(), tool()])).toEqual([
+ { kind: 'tools', start: 0, end: 3 },
+ ]);
+ });
+
+ it('breaks a run at permissions even with thinking blocks', () => {
+ expect(
+ segmentParts([thought(), tool(), permission(), thought(), tool()])
+ ).toEqual([
+ { kind: 'tools', start: 0, end: 2 },
+ { kind: 'part', start: 2, end: 3 },
+ { kind: 'tools', start: 3, end: 5 },
+ ]);
+ });
});
diff --git a/apps/web/src/features/block-agent/state/tool-groups.ts b/apps/web/src/features/block-agent/state/tool-groups.ts
index 048fb45971..9b70b80cbd 100644
--- a/apps/web/src/features/block-agent/state/tool-groups.ts
+++ b/apps/web/src/features/block-agent/state/tool-groups.ts
@@ -1,8 +1,8 @@
/**
* Where a message's parts fold for display: a run of two or more consecutive
- * tool calls reads as one collapsed row (`ui/ToolGroup`), everything else as
- * itself. A lone call stays a card of its own — a group of one would hide the
- * call behind a count that says nothing the card did not.
+ * tool calls and thinking blocks reads as one collapsed row (`ui/ToolGroup`),
+ * everything else as itself. A lone call stays a card of its own — a group of
+ * one would hide the call behind a count that says nothing the card did not.
*
* Segments are half-open index ranges into the parts array, so a grouped call
* keeps its position for the tool render context.
@@ -17,13 +17,17 @@ export type PartSegment = {
end: number;
};
+function isGroupable(part: MessagePart | undefined): boolean {
+ return part?.kind === 'tool_use' || part?.kind === 'thought';
+}
+
export function segmentParts(parts: readonly MessagePart[]): PartSegment[] {
const segments: PartSegment[] = [];
let start = 0;
while (start < parts.length) {
let end = start + 1;
- if (parts[start]?.kind === 'tool_use') {
- while (parts[end]?.kind === 'tool_use') end += 1;
+ if (isGroupable(parts[start])) {
+ while (isGroupable(parts[end])) end += 1;
}
segments.push({
kind: end - start >= 2 ? 'tools' : 'part',