Skip to content

Commit 0b5d131

Browse files
committed
refactor interrupt component
1 parent 5a55fd4 commit 0b5d131

File tree

1 file changed

+39
-19
lines changed
  • src/components/thread/messages

1 file changed

+39
-19
lines changed

src/components/thread/messages/ai.tsx

Lines changed: 39 additions & 19 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,
@@ -118,15 +144,11 @@ export function AssistantMessage({
118144
{isToolResult ? (
119145
<>
120146
<ToolResult message={message} />
121-
{isAgentInboxInterruptSchema(threadInterrupt?.value) &&
122-
(isLastMessage || hasNoAIOrToolMessages) && (
123-
<ThreadView interrupt={threadInterrupt.value} />
124-
)}
125-
{threadInterrupt?.value &&
126-
!isAgentInboxInterruptSchema(threadInterrupt.value) &&
127-
isLastMessage ? (
128-
<GenericInterruptView interrupt={threadInterrupt.value} />
129-
) : null}
147+
<Interrupt
148+
interruptValue={threadInterrupt?.value}
149+
isLastMessage={isLastMessage}
150+
hasNoAIOrToolMessages={hasNoAIOrToolMessages}
151+
/>
130152
</>
131153
) : (
132154
<>
@@ -144,7 +166,9 @@ export function AssistantMessage({
144166
(hasAnthropicToolCalls && (
145167
<ToolCalls toolCalls={anthropicStreamedToolCalls} />
146168
)) ||
147-
(hasToolCalls && <ToolCalls toolCalls={message.tool_calls} />)}
169+
(hasToolCalls && (
170+
<ToolCalls toolCalls={message.tool_calls} />
171+
))}
148172
</>
149173
)}
150174

@@ -154,15 +178,11 @@ export function AssistantMessage({
154178
thread={thread}
155179
/>
156180
)}
157-
{isAgentInboxInterruptSchema(threadInterrupt?.value) &&
158-
(isLastMessage || hasNoAIOrToolMessages) && (
159-
<ThreadView interrupt={threadInterrupt.value} />
160-
)}
161-
{threadInterrupt?.value &&
162-
!isAgentInboxInterruptSchema(threadInterrupt.value) &&
163-
isLastMessage ? (
164-
<GenericInterruptView interrupt={threadInterrupt.value} />
165-
) : null}
181+
<Interrupt
182+
interruptValue={threadInterrupt?.value}
183+
isLastMessage={isLastMessage}
184+
hasNoAIOrToolMessages={hasNoAIOrToolMessages}
185+
/>
166186
<div
167187
className={cn(
168188
"mr-auto flex items-center gap-2 transition-opacity",

0 commit comments

Comments
 (0)