Skip to content

Commit 6eff7d4

Browse files
committed
fix: cli uses parentAgentId to distinguish tools from subagents
1 parent cf76b12 commit 6eff7d4

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

cli/src/hooks/use-send-message.ts

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@ import {
2828

2929
import type { ElapsedTimeTracker } from './use-elapsed-time'
3030
import type { StreamStatus } from './use-message-queue'
31-
import type { ChatMessage, ContentBlock, ToolContentBlock, AskUserContentBlock } from '../types/chat'
31+
import type {
32+
ChatMessage,
33+
ContentBlock,
34+
ToolContentBlock,
35+
AskUserContentBlock,
36+
} from '../types/chat'
3237
import type { SendMessageFn } from '../types/contracts/send-message'
3338
import type { ParamsOf } from '../types/function-params'
3439
import type { SetElement } from '../types/utils'
@@ -1123,7 +1128,7 @@ export const useSendMessage = ({
11231128
] of spawnAgentsMapRef.current.entries()) {
11241129
const eventType = event.agentType || ''
11251130
const storedType = info.agentType || ''
1126-
1131+
11271132
// Extract base names without version or scope
11281133
// e.g., 'codebuff/file-picker@0.0.2' -> 'file-picker'
11291134
// 'file-picker' -> 'file-picker'
@@ -1135,10 +1140,10 @@ export const useSendMessage = ({
11351140
// Handle simple names, possibly with version
11361141
return type.split('@')[0]
11371142
}
1138-
1143+
11391144
const eventBaseName = getBaseName(eventType)
11401145
const storedBaseName = getBaseName(storedType)
1141-
1146+
11421147
// Match if base names are the same
11431148
const isMatch = eventBaseName === storedBaseName
11441149
if (isMatch) {
@@ -1416,6 +1421,7 @@ export const useSendMessage = ({
14161421
input,
14171422
agentId,
14181423
includeToolCall,
1424+
parentAgentId,
14191425
} = event
14201426

14211427
if (toolName === 'spawn_agents' && input?.agents) {
@@ -1487,7 +1493,7 @@ export const useSendMessage = ({
14871493
}
14881494

14891495
// If this tool call belongs to a subagent, add it to that agent's blocks
1490-
if (agentId) {
1496+
if (parentAgentId && agentId) {
14911497
applyMessageUpdate((prev) =>
14921498
prev.map((msg) => {
14931499
if (msg.id !== aiMessageId || !msg.blocks) {
@@ -1557,18 +1563,24 @@ export const useSendMessage = ({
15571563
}
15581564

15591565
setStreamingAgents((prev) => new Set(prev).add(toolCallId))
1560-
} else if (event.type === 'tool_result' && event.toolCallId) {
1566+
} else if (event.type === 'tool_result' && event.toolCallId) {
15611567
const { toolCallId } = event
15621568

15631569
// Handle ask_user result transformation
1564-
applyMessageUpdate((prev) =>
1570+
applyMessageUpdate((prev) =>
15651571
prev.map((msg) => {
15661572
if (msg.id !== aiMessageId || !msg.blocks) return msg
15671573

15681574
// Recursively check for tool blocks to transform
1569-
const transformAskUser = (blocks: ContentBlock[]): ContentBlock[] => {
1575+
const transformAskUser = (
1576+
blocks: ContentBlock[],
1577+
): ContentBlock[] => {
15701578
return blocks.map((block) => {
1571-
if (block.type === 'tool' && block.toolCallId === toolCallId && block.toolName === 'ask_user') {
1579+
if (
1580+
block.type === 'tool' &&
1581+
block.toolCallId === toolCallId &&
1582+
block.toolName === 'ask_user'
1583+
) {
15721584
const resultValue = (event.output?.[0] as any)?.value
15731585
const skipped = resultValue?.skipped
15741586
const answers = resultValue?.answers
@@ -1587,7 +1599,7 @@ export const useSendMessage = ({
15871599
skipped,
15881600
} as AskUserContentBlock
15891601
}
1590-
1602+
15911603
if (block.type === 'agent' && block.blocks) {
15921604
const updatedBlocks = transformAskUser(block.blocks)
15931605
if (updatedBlocks !== block.blocks) {
@@ -1600,10 +1612,10 @@ export const useSendMessage = ({
16001612

16011613
const newBlocks = transformAskUser(msg.blocks)
16021614
if (newBlocks !== msg.blocks) {
1603-
return { ...msg, blocks: newBlocks }
1615+
return { ...msg, blocks: newBlocks }
16041616
}
16051617
return msg
1606-
})
1618+
}),
16071619
)
16081620

16091621
// Check if this is a spawn_agents result

0 commit comments

Comments
 (0)