Skip to content

Commit 1bc1490

Browse files
committed
Fix for editor multi prompt to show the selected strategy and reason!
1 parent 699733c commit 1bc1490

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

cli/src/components/blocks/agent-branch-wrapper.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,15 +353,17 @@ export const AgentBranchWrapper = memo(
353353
(b): b is ToolContentBlock =>
354354
b.type === 'tool' && b.toolName === 'set_output',
355355
)
356-
const implementationId = setOutputBlock?.input?.implementationId as string | undefined
356+
// set_output wraps data in a 'data' property, so we need to access input.data
357+
const outputData = (setOutputBlock?.input as { data?: Record<string, unknown> })?.data
358+
const implementationId = outputData?.implementationId as string | undefined
357359
if (implementationId) {
358360
const letterIndex = implementationId.charCodeAt(0) - 65
359361
const implementors = siblingBlocks.filter(
360362
(b): b is AgentContentBlock =>
361363
b.type === 'agent' && isImplementorAgent(b),
362364
)
363365

364-
reason = setOutputBlock?.input?.reason as string | undefined
366+
reason = outputData?.reason as string | undefined
365367

366368
const selectedAgent = implementors[letterIndex]
367369
if (selectedAgent) {

cli/src/utils/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export const shouldCollapseForParent = (
8585
export const SIMPLE_TEXT_AGENT_IDS = [
8686
'best-of-n-selector',
8787
'best-of-n-selector-gemini',
88+
'best-of-n-selector2',
8889
] as const
8990

9091
/**

cli/src/utils/implementor-helpers.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -533,26 +533,34 @@ export function getMultiPromptProgress(
533533
}
534534
}
535535

536-
/** Expected shape of the set_output input from editor-multi-prompt */
537-
interface MultiPromptSetOutputInput {
536+
/** Expected shape of the set_output data from editor-multi-prompt */
537+
interface MultiPromptSetOutputData {
538+
implementationId?: string
538539
chosenStrategy?: string
539540
reason?: string
540541
suggestedImprovements?: string
541542
toolResults?: unknown[]
542543
error?: string
543544
}
544545

545-
/** Type guard for MultiPromptSetOutputInput */
546-
function isMultiPromptSetOutput(input: unknown): input is MultiPromptSetOutputInput {
546+
/** Expected shape of the set_output input (data is wrapped in a 'data' property) */
547+
interface SetOutputInput {
548+
data?: MultiPromptSetOutputData
549+
}
550+
551+
/** Type guard for set_output input with data property */
552+
function hasSetOutputData(input: unknown): input is SetOutputInput {
547553
return (
548554
typeof input === 'object' &&
549555
input !== null &&
550-
('reason' in input || 'chosenStrategy' in input || 'error' in input)
556+
'data' in input &&
557+
typeof (input as SetOutputInput).data === 'object'
551558
)
552559
}
553560

554561
/**
555562
* Extract the selection reason from multi-prompt agent's set_output block.
563+
* set_output wraps data in a 'data' property, so we need to access input.data.reason
556564
*/
557565
function extractSelectionReason(blocks: ContentBlock[] | undefined): string | null {
558566
if (!blocks || blocks.length === 0) return null
@@ -561,15 +569,15 @@ function extractSelectionReason(blocks: ContentBlock[] | undefined): string | nu
561569
(block): block is ToolContentBlock =>
562570
block.type === 'tool' &&
563571
block.toolName === 'set_output' &&
564-
isMultiPromptSetOutput(block.input) &&
565-
typeof block.input.reason === 'string',
572+
hasSetOutputData(block.input) &&
573+
typeof block.input.data?.reason === 'string',
566574
)
567575

568-
if (!setOutputBlock || !isMultiPromptSetOutput(setOutputBlock.input)) {
576+
if (!setOutputBlock || !hasSetOutputData(setOutputBlock.input)) {
569577
return null
570578
}
571579

572-
return setOutputBlock.input.reason ?? null
580+
return setOutputBlock.input.data?.reason ?? null
573581
}
574582

575583
/**

0 commit comments

Comments
 (0)