Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions frontend/src/components/chat/chat-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export async function handleToolCall({

/**
* Checks if we should send a message automatically based on the messages.
* We only want to send a message if we have completed tool calls and there is no reply yet.
* We only want to send a message if all tool calls are completed and there is no reply yet.
*/
export function hasPendingToolCalls(messages: UIMessage[]): boolean {
if (messages.length === 0) {
Expand All @@ -177,7 +177,12 @@ export function hasPendingToolCalls(messages: UIMessage[]): boolean {
part.type.startsWith("tool-"),
) as ToolUIPart[];

const hasCompletedToolCalls = toolParts.some(
// Guard against no tool parts
if (toolParts.length === 0) {
return false;
}

const allToolCallsCompleted = toolParts.every(
(part) => part.state === "output-available",
);

Expand All @@ -186,6 +191,8 @@ export function hasPendingToolCalls(messages: UIMessage[]): boolean {
const hasTextContent =
lastPart.type === "text" && lastPart.text?.trim().length > 0;

Logger.warn("All tool calls completed: %s", allToolCallsCompleted);

// Only auto-send if we have completed tool calls and there is no reply yet
return hasCompletedToolCalls && !hasTextContent;
return allToolCallsCompleted && !hasTextContent;
}
Loading
Loading