Skip to content

Commit 14c9aca

Browse files
committed
best of n: Show which model was selected!
1 parent fb60040 commit 14c9aca

File tree

1 file changed

+44
-48
lines changed

1 file changed

+44
-48
lines changed

cli/src/components/message-block.tsx

Lines changed: 44 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -378,24 +378,6 @@ const AgentBody = memo(
378378
const nestedBlocks = agentBlock.blocks ?? []
379379
const nodes: React.ReactNode[] = []
380380

381-
// Pre-calculate numbering for all implementor siblings
382-
const implementorIndexMap = new Map<string, number>()
383-
nestedBlocks
384-
.filter(
385-
(block): block is AgentContentBlock =>
386-
block.type === 'agent' && isImplementorAgent(block.agentType),
387-
)
388-
.forEach((block) => {
389-
const index = getImplementorIndex(
390-
block.agentId,
391-
block.agentType,
392-
nestedBlocks,
393-
)
394-
if (index !== undefined) {
395-
implementorIndexMap.set(block.agentId, index)
396-
}
397-
})
398-
399381
const getAgentMarkdownOptions = useCallback(
400382
(indent: number) => {
401383
const indentationOffset = indent * 2
@@ -555,7 +537,6 @@ const AgentBody = memo(
555537

556538
case 'agent': {
557539
const agentBlock = nestedBlock as AgentContentBlock
558-
const numbering = implementorIndexMap.get(agentBlock.agentId)
559540
nodes.push(
560541
<AgentBranchWrapper
561542
key={`${keyPrefix}-agent-${nestedIdx}`}
@@ -568,7 +549,7 @@ const AgentBody = memo(
568549
onToggleCollapsed={onToggleCollapsed}
569550
onBuildFast={onBuildFast}
570551
onBuildMax={onBuildMax}
571-
implementorIndex={numbering}
552+
siblingBlocks={nestedBlocks}
572553
/>,
573554
)
574555
nestedIdx++
@@ -591,7 +572,7 @@ interface AgentBranchWrapperProps {
591572
onToggleCollapsed: (id: string) => void
592573
onBuildFast: () => void
593574
onBuildMax: () => void
594-
implementorIndex?: number
575+
siblingBlocks?: ContentBlock[]
595576
}
596577

597578
const AgentBranchWrapper = memo(
@@ -605,7 +586,7 @@ const AgentBranchWrapper = memo(
605586
onToggleCollapsed,
606587
onBuildFast,
607588
onBuildMax,
608-
implementorIndex,
589+
siblingBlocks,
609590
}: AgentBranchWrapperProps) => {
610591
const theme = useTheme()
611592

@@ -621,6 +602,38 @@ const AgentBranchWrapper = memo(
621602
? theme.foreground
622603
: theme.muted
623604

605+
let statusText = 'Selecting best'
606+
607+
// If complete, try to show which implementation was selected
608+
if (isComplete && siblingBlocks) {
609+
const blocks = agentBlock.blocks ?? []
610+
const lastBlock = blocks[blocks.length - 1] as
611+
| { input: { implementationId: string } }
612+
| undefined
613+
const implementationId = lastBlock?.input?.implementationId
614+
if (implementationId) {
615+
// Convert letter to index: 'A' -> 0, 'B' -> 1, etc.
616+
const letterIndex = implementationId.charCodeAt(0) - 65
617+
const implementors = siblingBlocks.filter(
618+
(b) => b.type === 'agent' && isImplementorAgent(b.agentType),
619+
) as AgentContentBlock[]
620+
621+
const selectedAgent = implementors[letterIndex]
622+
if (selectedAgent) {
623+
const index = getImplementorIndex(
624+
selectedAgent.agentId,
625+
selectedAgent.agentType,
626+
siblingBlocks,
627+
)
628+
const name = getImplementorDisplayName(
629+
selectedAgent.agentType,
630+
index,
631+
)
632+
statusText = `Selected ${name}`
633+
}
634+
}
635+
}
636+
624637
return (
625638
<box
626639
key={keyPrefix}
@@ -635,7 +648,7 @@ const AgentBranchWrapper = memo(
635648
<span fg={statusColor}>{statusIndicator}</span>
636649
<span fg={theme.foreground} attributes={TextAttributes.BOLD}>
637650
{' '}
638-
Selecting best
651+
{statusText}
639652
</span>
640653
</text>
641654
</box>
@@ -649,6 +662,13 @@ const AgentBranchWrapper = memo(
649662
streamingAgents.has(agentBlock.agentId)
650663
const isComplete = agentBlock.status === 'complete'
651664
const isFailed = agentBlock.status === 'failed'
665+
const implementorIndex = siblingBlocks
666+
? getImplementorIndex(
667+
agentBlock.agentId,
668+
agentBlock.agentType,
669+
siblingBlocks,
670+
)
671+
: undefined
652672
const displayName = getImplementorDisplayName(
653673
agentBlock.agentType,
654674
implementorIndex,
@@ -824,7 +844,6 @@ interface SingleBlockProps {
824844
onToggleCollapsed: (id: string) => void
825845
onBuildFast: () => void
826846
onBuildMax: () => void
827-
implementorIndex?: number
828847
}
829848

830849
const SingleBlock = memo(
@@ -843,7 +862,6 @@ const SingleBlock = memo(
843862
onToggleCollapsed,
844863
onBuildFast,
845864
onBuildMax,
846-
implementorIndex,
847865
}: SingleBlockProps): ReactNode => {
848866
const theme = useTheme()
849867
const codeBlockWidth = Math.max(10, availableWidth - 8)
@@ -940,7 +958,7 @@ const SingleBlock = memo(
940958
onToggleCollapsed={onToggleCollapsed}
941959
onBuildFast={onBuildFast}
942960
onBuildMax={onBuildMax}
943-
implementorIndex={implementorIndex}
961+
siblingBlocks={blocks}
944962
/>
945963
)
946964
}
@@ -994,23 +1012,6 @@ const BlocksRenderer = memo(
9941012
}: BlocksRendererProps) => {
9951013
const nodes: React.ReactNode[] = []
9961014

997-
// Pre-calculate numbering for all implementor siblings at the top level
998-
const topLevelImplementorIndexMap = new Map<string, number>()
999-
sourceBlocks
1000-
.filter(
1001-
(block): block is AgentContentBlock =>
1002-
block.type === 'agent' && isImplementorAgent(block.agentType),
1003-
)
1004-
.forEach((block) => {
1005-
const index = getImplementorIndex(
1006-
block.agentId,
1007-
block.agentType,
1008-
sourceBlocks,
1009-
)
1010-
if (index !== undefined) {
1011-
topLevelImplementorIndexMap.set(block.agentId, index)
1012-
}
1013-
})
10141015
for (let i = 0; i < sourceBlocks.length; ) {
10151016
const block = sourceBlocks[i]
10161017
// Handle reasoning text blocks
@@ -1091,10 +1092,6 @@ const BlocksRenderer = memo(
10911092
continue
10921093
}
10931094

1094-
const numbering =
1095-
block.type === 'agent'
1096-
? topLevelImplementorIndexMap.get(block.agentId)
1097-
: undefined
10981095
nodes.push(
10991096
<SingleBlock
11001097
key={`${messageId}-block-${i}`}
@@ -1112,7 +1109,6 @@ const BlocksRenderer = memo(
11121109
onToggleCollapsed={onToggleCollapsed}
11131110
onBuildFast={onBuildFast}
11141111
onBuildMax={onBuildMax}
1115-
implementorIndex={numbering}
11161112
/>,
11171113
)
11181114
i++

0 commit comments

Comments
 (0)