Skip to content

Commit 00fd5b1

Browse files
authored
Merge pull request #112 from hylkesybesma/fix-render-interrupt
fix: render interrupt after tool result
2 parents 89e58cf + 0b5d131 commit 00fd5b1

File tree

1 file changed

+86
-53
lines changed
  • src/components/thread/messages

1 file changed

+86
-53
lines changed

src/components/thread/messages/ai.tsx

Lines changed: 86 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,32 @@ function parseAnthropicStreamedToolCalls(
6565
});
6666
}
6767

68+
interface InterruptProps {
69+
interruptValue?: unknown;
70+
isLastMessage: boolean;
71+
hasNoAIOrToolMessages: boolean;
72+
}
73+
74+
function Interrupt({
75+
interruptValue,
76+
isLastMessage,
77+
hasNoAIOrToolMessages,
78+
}: InterruptProps) {
79+
return (
80+
<>
81+
{isAgentInboxInterruptSchema(interruptValue) &&
82+
(isLastMessage || hasNoAIOrToolMessages) && (
83+
<ThreadView interrupt={interruptValue} />
84+
)}
85+
{interruptValue &&
86+
!isAgentInboxInterruptSchema(interruptValue) &&
87+
isLastMessage ? (
88+
<GenericInterruptView interrupt={interruptValue} />
89+
) : null}
90+
</>
91+
);
92+
}
93+
6894
export function AssistantMessage({
6995
message,
7096
isLoading,
@@ -114,64 +140,71 @@ export function AssistantMessage({
114140

115141
return (
116142
<div className="group mr-auto flex items-start gap-2">
117-
{isToolResult ? (
118-
<ToolResult message={message} />
119-
) : (
120-
<div className="flex flex-col gap-2">
121-
{contentString.length > 0 && (
122-
<div className="py-1">
123-
<MarkdownText>{contentString}</MarkdownText>
124-
</div>
125-
)}
143+
<div className="flex flex-col gap-2">
144+
{isToolResult ? (
145+
<>
146+
<ToolResult message={message} />
147+
<Interrupt
148+
interruptValue={threadInterrupt?.value}
149+
isLastMessage={isLastMessage}
150+
hasNoAIOrToolMessages={hasNoAIOrToolMessages}
151+
/>
152+
</>
153+
) : (
154+
<>
155+
{contentString.length > 0 && (
156+
<div className="py-1">
157+
<MarkdownText>{contentString}</MarkdownText>
158+
</div>
159+
)}
126160

127-
{!hideToolCalls && (
128-
<>
129-
{(hasToolCalls && toolCallsHaveContents && (
130-
<ToolCalls toolCalls={message.tool_calls} />
131-
)) ||
132-
(hasAnthropicToolCalls && (
133-
<ToolCalls toolCalls={anthropicStreamedToolCalls} />
161+
{!hideToolCalls && (
162+
<>
163+
{(hasToolCalls && toolCallsHaveContents && (
164+
<ToolCalls toolCalls={message.tool_calls} />
134165
)) ||
135-
(hasToolCalls && <ToolCalls toolCalls={message.tool_calls} />)}
136-
</>
137-
)}
138-
139-
{message && (
140-
<CustomComponent
141-
message={message}
142-
thread={thread}
143-
/>
144-
)}
145-
{isAgentInboxInterruptSchema(threadInterrupt?.value) &&
146-
(isLastMessage || hasNoAIOrToolMessages) && (
147-
<ThreadView interrupt={threadInterrupt.value} />
166+
(hasAnthropicToolCalls && (
167+
<ToolCalls toolCalls={anthropicStreamedToolCalls} />
168+
)) ||
169+
(hasToolCalls && (
170+
<ToolCalls toolCalls={message.tool_calls} />
171+
))}
172+
</>
148173
)}
149-
{threadInterrupt?.value &&
150-
!isAgentInboxInterruptSchema(threadInterrupt.value) &&
151-
isLastMessage ? (
152-
<GenericInterruptView interrupt={threadInterrupt.value} />
153-
) : null}
154-
<div
155-
className={cn(
156-
"mr-auto flex items-center gap-2 transition-opacity",
157-
"opacity-0 group-focus-within:opacity-100 group-hover:opacity-100",
174+
175+
{message && (
176+
<CustomComponent
177+
message={message}
178+
thread={thread}
179+
/>
158180
)}
159-
>
160-
<BranchSwitcher
161-
branch={meta?.branch}
162-
branchOptions={meta?.branchOptions}
163-
onSelect={(branch) => thread.setBranch(branch)}
164-
isLoading={isLoading}
181+
<Interrupt
182+
interruptValue={threadInterrupt?.value}
183+
isLastMessage={isLastMessage}
184+
hasNoAIOrToolMessages={hasNoAIOrToolMessages}
165185
/>
166-
<CommandBar
167-
content={contentString}
168-
isLoading={isLoading}
169-
isAiMessage={true}
170-
handleRegenerate={() => handleRegenerate(parentCheckpoint)}
171-
/>
172-
</div>
173-
</div>
174-
)}
186+
<div
187+
className={cn(
188+
"mr-auto flex items-center gap-2 transition-opacity",
189+
"opacity-0 group-focus-within:opacity-100 group-hover:opacity-100",
190+
)}
191+
>
192+
<BranchSwitcher
193+
branch={meta?.branch}
194+
branchOptions={meta?.branchOptions}
195+
onSelect={(branch) => thread.setBranch(branch)}
196+
isLoading={isLoading}
197+
/>
198+
<CommandBar
199+
content={contentString}
200+
isLoading={isLoading}
201+
isAiMessage={true}
202+
handleRegenerate={() => handleRegenerate(parentCheckpoint)}
203+
/>
204+
</div>
205+
</>
206+
)}
207+
</div>
175208
</div>
176209
);
177210
}

0 commit comments

Comments
 (0)