Skip to content

Commit d8944e2

Browse files
authored
fix(app): rendering question tool when the step are collapsed (anomalyco#11539)
1 parent aef6272 commit d8944e2

2 files changed

Lines changed: 78 additions & 0 deletions

File tree

packages/ui/src/components/session-turn.css

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,4 +569,20 @@
569569
flex-direction: column;
570570
gap: 12px;
571571
}
572+
573+
[data-slot="session-turn-question-parts"] {
574+
width: 100%;
575+
min-width: 0;
576+
display: flex;
577+
flex-direction: column;
578+
gap: 12px;
579+
}
580+
581+
[data-slot="session-turn-answered-question-parts"] {
582+
width: 100%;
583+
min-width: 0;
584+
display: flex;
585+
flex-direction: column;
586+
gap: 12px;
587+
}
572588
}

packages/ui/src/components/session-turn.tsx

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
Message as MessageType,
55
Part as PartType,
66
type PermissionRequest,
7+
type QuestionRequest,
78
TextPart,
89
ToolPart,
910
} from "@opencode-ai/sdk/v2/client"
@@ -150,6 +151,8 @@ export function SessionTurn(
150151
const emptyAssistant: AssistantMessage[] = []
151152
const emptyPermissions: PermissionRequest[] = []
152153
const emptyPermissionParts: { part: ToolPart; message: AssistantMessage }[] = []
154+
const emptyQuestions: QuestionRequest[] = []
155+
const emptyQuestionParts: { part: ToolPart; message: AssistantMessage }[] = []
153156
const emptyDiffs: FileDiff[] = []
154157
const idle = { type: "idle" as const }
155158

@@ -281,6 +284,51 @@ export function SessionTurn(
281284
return emptyPermissionParts
282285
})
283286

287+
const questions = createMemo(() => data.store.question?.[props.sessionID] ?? emptyQuestions)
288+
const nextQuestion = createMemo(() => questions()[0])
289+
290+
const questionParts = createMemo(() => {
291+
if (props.stepsExpanded) return emptyQuestionParts
292+
293+
const next = nextQuestion()
294+
if (!next || !next.tool) return emptyQuestionParts
295+
296+
const message = findLast(assistantMessages(), (m) => m.id === next.tool!.messageID)
297+
if (!message) return emptyQuestionParts
298+
299+
const parts = data.store.part[message.id] ?? emptyParts
300+
for (const part of parts) {
301+
if (part?.type !== "tool") continue
302+
const tool = part as ToolPart
303+
if (tool.callID === next.tool?.callID) return [{ part: tool, message }]
304+
}
305+
306+
return emptyQuestionParts
307+
})
308+
309+
const answeredQuestionParts = createMemo(() => {
310+
if (props.stepsExpanded) return emptyQuestionParts
311+
if (questions().length > 0) return emptyQuestionParts
312+
313+
const result: { part: ToolPart; message: AssistantMessage }[] = []
314+
315+
for (const msg of assistantMessages()) {
316+
const parts = data.store.part[msg.id] ?? emptyParts
317+
for (const part of parts) {
318+
if (part?.type !== "tool") continue
319+
const tool = part as ToolPart
320+
if (tool.tool !== "question") continue
321+
// @ts-expect-error metadata may not exist on all tool states
322+
const answers = tool.state?.metadata?.answers
323+
if (answers && answers.length > 0) {
324+
result.push({ part: tool, message: msg })
325+
}
326+
}
327+
}
328+
329+
return result
330+
})
331+
284332
const shellModePart = createMemo(() => {
285333
const p = parts()
286334
if (p.length === 0) return
@@ -640,6 +688,20 @@ export function SessionTurn(
640688
</For>
641689
</div>
642690
</Show>
691+
<Show when={!props.stepsExpanded && questionParts().length > 0}>
692+
<div data-slot="session-turn-question-parts">
693+
<For each={questionParts()}>
694+
{({ part, message }) => <Part part={part} message={message} />}
695+
</For>
696+
</div>
697+
</Show>
698+
<Show when={!props.stepsExpanded && answeredQuestionParts().length > 0}>
699+
<div data-slot="session-turn-answered-question-parts">
700+
<For each={answeredQuestionParts()}>
701+
{({ part, message }) => <Part part={part} message={message} />}
702+
</For>
703+
</div>
704+
</Show>
643705
{/* Response */}
644706
<div class="sr-only" aria-live="polite">
645707
{!working() && response() ? response() : ""}

0 commit comments

Comments
 (0)