Revert streaming fixes and preserve parallel tool calls progress
- Reverted ID-based streaming logic back to index-based approach - Reverted permission processing changes - Preserved existing parallel tool calls infrastructure - Tests show tool calls are stored but not transitioning to "generated" status - Ready to start fresh on the parallel tool calling issue 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
bcf0969f34
commit
c49f8412c3
13 changed files with 390 additions and 137 deletions
1
core/index.d.ts
vendored
1
core/index.d.ts
vendored
|
|
@ -461,7 +461,6 @@ export interface ChatHistoryItem {
|
|||
editorState?: any;
|
||||
modifiers?: InputModifiers;
|
||||
promptLogs?: PromptLog[];
|
||||
toolCallState?: ToolCallState;
|
||||
toolCallStates?: ToolCallState[]; // Support for multiple parallel tool calls
|
||||
isGatheringContext?: boolean;
|
||||
reasoning?: Reasoning;
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import { BUILT_IN_GROUP_NAME, BuiltInToolNames } from "../builtIn";
|
|||
|
||||
export const lsTool: Tool = {
|
||||
type: "function",
|
||||
displayTitle: "LS Tool",
|
||||
displayTitle: "ls",
|
||||
wouldLikeTo: "list files and folders in {{{ dirPath }}}",
|
||||
isCurrently: "listing files and folders in {{{ dirPath }}}",
|
||||
hasAlready: "listed files and folders in {{{ dirPath }}}",
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import { vscBackground } from "..";
|
|||
import { useAppSelector } from "../../redux/hooks";
|
||||
import { selectUIConfig } from "../../redux/slices/configSlice";
|
||||
import { deleteMessage } from "../../redux/slices/sessionSlice";
|
||||
import { selectCurrentToolCallsByStatus } from "../../redux/selectors/selectCurrentToolCall";
|
||||
import { getFontSize } from "../../util";
|
||||
import StyledMarkdownPreview from "../StyledMarkdownPreview";
|
||||
import Reasoning from "./Reasoning";
|
||||
|
|
@ -38,10 +39,15 @@ export default function StepContainer(props: StepContainerProps) {
|
|||
);
|
||||
const uiConfig = useAppSelector(selectUIConfig);
|
||||
|
||||
const pendingToolCalls = useAppSelector((state) =>
|
||||
selectCurrentToolCallsByStatus(state, "generated")
|
||||
);
|
||||
const hasPendingToolCalls = pendingToolCalls.length > 0;
|
||||
|
||||
const hideActionSpace =
|
||||
historyItemAfterThis?.message.role === "assistant" ||
|
||||
historyItemAfterThis?.message.role === "thinking";
|
||||
const hideActions = hideActionSpace || (isStreaming && props.isLast);
|
||||
const hideActions = hideActionSpace || (isStreaming && props.isLast) || hasPendingToolCalls;
|
||||
|
||||
useEffect(() => {
|
||||
if (!isStreaming) {
|
||||
|
|
|
|||
|
|
@ -1,35 +1,15 @@
|
|||
import styled from "styled-components";
|
||||
import { useAppDispatch, useAppSelector } from "../../../../redux/hooks";
|
||||
import { selectCurrentToolCallsByStatus } from "../../../../redux/selectors/selectCurrentToolCall";
|
||||
import { cancelToolCall } from "../../../../redux/slices/sessionSlice";
|
||||
import { callToolById } from "../../../../redux/thunks/callToolById";
|
||||
import {
|
||||
getAltKeyLabel,
|
||||
getFontSize,
|
||||
getMetaKeyLabel,
|
||||
isJetBrains,
|
||||
} from "../../../../util";
|
||||
import { cancelToolCallById } from "../../../../redux/thunks/cancelToolCallById";
|
||||
import { getAltKeyLabel, getMetaKeyLabel, isJetBrains } from "../../../../util";
|
||||
import { EnterButton } from "../../InputToolbar/EnterButton";
|
||||
|
||||
const Container = styled.div`
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
`;
|
||||
|
||||
const StopButton = styled.div`
|
||||
font-size: ${getFontSize() - 3}px;
|
||||
padding: 2px;
|
||||
padding-right: 4px;
|
||||
cursor: pointer;
|
||||
`;
|
||||
|
||||
export function PendingToolCallToolbar() {
|
||||
const dispatch = useAppDispatch();
|
||||
const jetbrains = isJetBrains();
|
||||
const pendingToolCalls = useAppSelector((state) =>
|
||||
selectCurrentToolCallsByStatus(state, "generated")
|
||||
const pendingToolCalls = useAppSelector((state) =>
|
||||
selectCurrentToolCallsByStatus(state, "generated"),
|
||||
);
|
||||
|
||||
if (pendingToolCalls.length === 0) {
|
||||
|
|
@ -37,55 +17,44 @@ export function PendingToolCallToolbar() {
|
|||
}
|
||||
|
||||
const handleAccept = (toolCallId: string) => {
|
||||
dispatch(callToolById({ toolCallId }));
|
||||
void dispatch(callToolById({ toolCallId }));
|
||||
};
|
||||
|
||||
const handleReject = (toolCallId: string) => {
|
||||
dispatch(cancelToolCall({ toolCallId }));
|
||||
void dispatch(cancelToolCallById({ toolCallId }));
|
||||
};
|
||||
|
||||
return (
|
||||
<Container>
|
||||
<div className="text-description flex flex-row items-center pb-0.5 pr-1 text-xs">
|
||||
<span className="hidden sm:flex">
|
||||
{pendingToolCalls.length === 1
|
||||
? "Pending tool call"
|
||||
: `${pendingToolCalls.length} pending tool calls`
|
||||
}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex w-full flex-col gap-2 pb-0.5">
|
||||
{pendingToolCalls.map((toolCall) => (
|
||||
<div
|
||||
key={toolCall.toolCallId}
|
||||
className="border-input bg-input flex items-center gap-2 rounded border"
|
||||
>
|
||||
<span className="text-description flex-1 truncate text-xs italic">
|
||||
{toolCall.tool?.displayTitle ?? toolCall.toolCall.function.name}
|
||||
</span>
|
||||
|
||||
<div className="flex flex-col gap-2 pb-0.5 w-full">
|
||||
{pendingToolCalls.map((toolCall) => (
|
||||
<div
|
||||
key={toolCall.toolCallId}
|
||||
className="flex items-center gap-2 p-2 border border-input rounded bg-input"
|
||||
>
|
||||
<span className="text-foreground font-medium text-sm flex-1">
|
||||
{toolCall.toolCall.function.name}
|
||||
</span>
|
||||
|
||||
<div className="flex gap-2">
|
||||
<StopButton
|
||||
className="text-description text-xs cursor-pointer px-2 py-1"
|
||||
onClick={() => handleReject(toolCall.toolCallId)}
|
||||
data-testid={`reject-tool-call-button-${toolCall.toolCallId}`}
|
||||
>
|
||||
{jetbrains ? getAltKeyLabel() : getMetaKeyLabel()} ⌫ Cancel
|
||||
</StopButton>
|
||||
|
||||
<EnterButton
|
||||
isPrimary={true}
|
||||
className="text-description text-xs"
|
||||
onClick={() => handleAccept(toolCall.toolCallId)}
|
||||
data-testid={`accept-tool-call-button-${toolCall.toolCallId}`}
|
||||
>
|
||||
{getMetaKeyLabel()} ⏎ Continue
|
||||
</EnterButton>
|
||||
<div className="flex gap-2">
|
||||
<div
|
||||
className="text-description cursor-pointer px-2 py-1 text-xs hover:brightness-125"
|
||||
onClick={() => handleReject(toolCall.toolCallId)}
|
||||
data-testid={`reject-tool-call-button-${toolCall.toolCallId}`}
|
||||
>
|
||||
{jetbrains ? getAltKeyLabel() : getMetaKeyLabel()} ⌫ Cancel
|
||||
</div>
|
||||
|
||||
<EnterButton
|
||||
isPrimary={true}
|
||||
className="text-description text-xs hover:brightness-125"
|
||||
onClick={() => handleAccept(toolCall.toolCallId)}
|
||||
data-testid={`accept-tool-call-button-${toolCall.toolCallId}`}
|
||||
>
|
||||
{getMetaKeyLabel()} ⏎ Continue
|
||||
</EnterButton>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</Container>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -321,13 +321,20 @@ export function Chat() {
|
|||
) : item.message.role === "tool" ? null : item.message.role ===
|
||||
"assistant" &&
|
||||
item.message.toolCalls &&
|
||||
item.toolCallState ? (
|
||||
item.toolCallStates ? (
|
||||
<div className="">
|
||||
{item.message.toolCalls?.map((toolCall, i) => {
|
||||
// Find the corresponding tool call state for this tool call
|
||||
const toolCallState = item.toolCallStates?.find(
|
||||
state => state.toolCallId === toolCall.id
|
||||
);
|
||||
|
||||
if (!toolCallState) return null;
|
||||
|
||||
return (
|
||||
<ToolCallDiv
|
||||
key={i}
|
||||
toolCallState={item.toolCallState!}
|
||||
key={toolCall.id}
|
||||
toolCallState={toolCallState}
|
||||
toolCall={toolCall}
|
||||
historyIndex={index}
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -2,18 +2,15 @@ import { act } from "@testing-library/react";
|
|||
import { ChatMessage } from "core";
|
||||
import { addAndSelectMockLlm } from "../../../util/test/config";
|
||||
import { renderWithProviders } from "../../../util/test/render";
|
||||
import {
|
||||
getElementByTestId,
|
||||
getElementByText,
|
||||
sendInputWithMockedResponse,
|
||||
} from "../../../util/test/utils";
|
||||
import { sendInputWithMockedResponse } from "../../../util/test/utils";
|
||||
import { Chat } from "../Chat";
|
||||
|
||||
describe("Parallel Tool Calls", () => {
|
||||
const PARALLEL_TOOL_CALL_RESPONSE: ChatMessage[] = [
|
||||
{
|
||||
role: "assistant",
|
||||
content: "I'll call the get_weather function in parallel for both San Francisco and Monterey, California.",
|
||||
content:
|
||||
"I'll call the get_weather function in parallel for both San Francisco and Monterey, California.",
|
||||
toolCalls: [
|
||||
{
|
||||
id: "toolu_0112JmA95qW6WhAsvkKb7Avp",
|
||||
|
|
@ -56,9 +53,9 @@ describe("Parallel Tool Calls", () => {
|
|||
PARALLEL_TOOL_CALL_RESPONSE,
|
||||
);
|
||||
|
||||
// Wait for the message to be processed
|
||||
// Wait for the message to be processed
|
||||
await act(async () => {
|
||||
await new Promise(resolve => setTimeout(resolve, 100));
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
});
|
||||
|
||||
// Currently this will fail because we only support one tool call
|
||||
|
|
@ -80,35 +77,44 @@ describe("Parallel Tool Calls", () => {
|
|||
PARALLEL_TOOL_CALL_RESPONSE,
|
||||
);
|
||||
|
||||
// Wait for the message to be processed
|
||||
// Wait for the message to be processed
|
||||
await act(async () => {
|
||||
await new Promise(resolve => setTimeout(resolve, 100));
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
});
|
||||
|
||||
// Wait for any state updates to complete
|
||||
await act(async () => {
|
||||
await new Promise(resolve => setTimeout(resolve, 100));
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
});
|
||||
|
||||
// Verify multiple tool calls are stored in Redux state
|
||||
const state = store.getState();
|
||||
const history = state.session.history;
|
||||
|
||||
|
||||
// Find the assistant message (might not be at index 1 if tool messages were created)
|
||||
const assistantMessage = history.find(item =>
|
||||
item.message.role === "assistant" && (item.message as any).toolCalls?.length
|
||||
const assistantMessage = history.find(
|
||||
(item) =>
|
||||
item.message.role === "assistant" &&
|
||||
(item.message as any).toolCalls?.length,
|
||||
);
|
||||
|
||||
|
||||
expect(assistantMessage).toBeDefined();
|
||||
expect((assistantMessage!.message as any).toolCalls).toHaveLength(2);
|
||||
expect(assistantMessage!.toolCallStates).toHaveLength(2);
|
||||
|
||||
|
||||
// Verify each tool call has correct ID and function name
|
||||
expect(assistantMessage!.toolCallStates![0].toolCallId).toBe("toolu_0112JmA95qW6WhAsvkKb7Avp");
|
||||
expect(assistantMessage!.toolCallStates![0].toolCall.function.name).toBe("get_weather");
|
||||
expect(assistantMessage!.toolCallStates![1].toolCallId).toBe("toolu_01UFK4ZUmbpkeFJGg7mdoT6T");
|
||||
expect(assistantMessage!.toolCallStates![1].toolCall.function.name).toBe("get_weather");
|
||||
|
||||
expect(assistantMessage!.toolCallStates![0].toolCallId).toBe(
|
||||
"toolu_0112JmA95qW6WhAsvkKb7Avp",
|
||||
);
|
||||
expect(assistantMessage!.toolCallStates![0].toolCall.function.name).toBe(
|
||||
"get_weather",
|
||||
);
|
||||
expect(assistantMessage!.toolCallStates![1].toolCallId).toBe(
|
||||
"toolu_01UFK4ZUmbpkeFJGg7mdoT6T",
|
||||
);
|
||||
expect(assistantMessage!.toolCallStates![1].toolCall.function.name).toBe(
|
||||
"get_weather",
|
||||
);
|
||||
});
|
||||
|
||||
test("should use utility functions for finding tool calls", async () => {
|
||||
|
|
@ -126,36 +132,285 @@ describe("Parallel Tool Calls", () => {
|
|||
PARALLEL_TOOL_CALL_RESPONSE,
|
||||
);
|
||||
|
||||
// Wait for the message to be processed
|
||||
// Wait for the message to be processed
|
||||
await act(async () => {
|
||||
await new Promise(resolve => setTimeout(resolve, 100));
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
});
|
||||
|
||||
await act(async () => {
|
||||
await new Promise(resolve => setTimeout(resolve, 100));
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
});
|
||||
|
||||
// Test our utility functions work with the new state
|
||||
const state = store.getState();
|
||||
|
||||
|
||||
// Import the utility functions to test them
|
||||
const { findCurrentToolCalls, hasCurrentToolCalls, findToolCall } = await import("../../../redux/util");
|
||||
|
||||
const { findCurrentToolCalls, hasCurrentToolCalls, findToolCall } =
|
||||
await import("../../../redux/util");
|
||||
|
||||
// Test findCurrentToolCalls finds both tool calls
|
||||
const currentToolCalls = findCurrentToolCalls(state.session.history);
|
||||
expect(currentToolCalls).toHaveLength(2);
|
||||
expect(currentToolCalls[0].toolCallId).toBe("toolu_0112JmA95qW6WhAsvkKb7Avp");
|
||||
expect(currentToolCalls[1].toolCallId).toBe("toolu_01UFK4ZUmbpkeFJGg7mdoT6T");
|
||||
|
||||
expect(currentToolCalls[0].toolCallId).toBe(
|
||||
"toolu_0112JmA95qW6WhAsvkKb7Avp",
|
||||
);
|
||||
expect(currentToolCalls[1].toolCallId).toBe(
|
||||
"toolu_01UFK4ZUmbpkeFJGg7mdoT6T",
|
||||
);
|
||||
|
||||
// Test hasCurrentToolCalls returns true
|
||||
expect(hasCurrentToolCalls(state.session.history)).toBe(true);
|
||||
|
||||
|
||||
// Test findToolCall can find specific tool calls by ID
|
||||
const toolCall1 = findToolCall(state.session.history, "toolu_0112JmA95qW6WhAsvkKb7Avp");
|
||||
const toolCall2 = findToolCall(state.session.history, "toolu_01UFK4ZUmbpkeFJGg7mdoT6T");
|
||||
const toolCall1 = findToolCall(
|
||||
state.session.history,
|
||||
"toolu_0112JmA95qW6WhAsvkKb7Avp",
|
||||
);
|
||||
const toolCall2 = findToolCall(
|
||||
state.session.history,
|
||||
"toolu_01UFK4ZUmbpkeFJGg7mdoT6T",
|
||||
);
|
||||
expect(toolCall1?.toolCall.function.name).toBe("get_weather");
|
||||
expect(toolCall2?.toolCall.function.name).toBe("get_weather");
|
||||
expect(toolCall1?.toolCall.function.arguments).toContain("San Francisco");
|
||||
expect(toolCall2?.toolCall.function.arguments).toContain("Monterey");
|
||||
});
|
||||
});
|
||||
|
||||
test("should complete streaming but hide ResponseActions when pending tool calls exist", async () => {
|
||||
const { ideMessenger, store } = await renderWithProviders(<Chat />);
|
||||
|
||||
await act(async () => {
|
||||
addAndSelectMockLlm(store, ideMessenger);
|
||||
});
|
||||
|
||||
const INPUT = "Read a file using the read_file tool";
|
||||
|
||||
await sendInputWithMockedResponse(
|
||||
ideMessenger,
|
||||
INPUT,
|
||||
PARALLEL_TOOL_CALL_RESPONSE,
|
||||
);
|
||||
|
||||
// Wait for the message to be processed
|
||||
await act(async () => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
});
|
||||
|
||||
await act(async () => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
});
|
||||
|
||||
// Verify streaming is complete (so tool calls can be shown)
|
||||
const state = store.getState();
|
||||
expect(state.session.isStreaming).toBe(false);
|
||||
|
||||
// Verify we have pending tool calls
|
||||
const { findCurrentToolCallsByStatus } = await import("../../../redux/util");
|
||||
const pendingToolCalls = findCurrentToolCallsByStatus(state.session.history, "generated");
|
||||
expect(pendingToolCalls).toHaveLength(2);
|
||||
|
||||
// Note: ResponseActions should be hidden by the hasPendingToolCalls condition in StepContainer
|
||||
// The individual tool calls should now show with "Continue wants to..." text and accept/reject buttons
|
||||
});
|
||||
|
||||
test("should show tool name in pending toolbar instead of generic text", async () => {
|
||||
const { ideMessenger, store } = await renderWithProviders(<Chat />);
|
||||
|
||||
await act(async () => {
|
||||
addAndSelectMockLlm(store, ideMessenger);
|
||||
});
|
||||
|
||||
// Test with single tool call to check the specific name display
|
||||
// Use get_weather which should stay in generated status for this test
|
||||
const SINGLE_TOOL_CALL_RESPONSE: ChatMessage[] = [
|
||||
{
|
||||
role: "assistant",
|
||||
content: "I'll check the weather for you.",
|
||||
toolCalls: [
|
||||
{
|
||||
id: "single-tool-call",
|
||||
type: "function",
|
||||
function: {
|
||||
name: "get_weather",
|
||||
arguments: JSON.stringify({
|
||||
location: "San Francisco, CA",
|
||||
}),
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
await sendInputWithMockedResponse(
|
||||
ideMessenger,
|
||||
"Check weather",
|
||||
SINGLE_TOOL_CALL_RESPONSE,
|
||||
);
|
||||
|
||||
// Wait for processing
|
||||
await act(async () => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
});
|
||||
|
||||
const state = store.getState();
|
||||
const { findCurrentToolCallsByStatus } = await import("../../../redux/util");
|
||||
const pendingToolCalls = findCurrentToolCallsByStatus(state.session.history, "generated");
|
||||
|
||||
// Should have one pending tool call with the correct name
|
||||
expect(pendingToolCalls).toHaveLength(1);
|
||||
expect(pendingToolCalls[0].toolCall.function.name).toBe("get_weather");
|
||||
});
|
||||
|
||||
test("should show individual tool call UI with 'Continue wants to...' text", async () => {
|
||||
const { ideMessenger, store } = await renderWithProviders(<Chat />);
|
||||
|
||||
await act(async () => {
|
||||
addAndSelectMockLlm(store, ideMessenger);
|
||||
});
|
||||
|
||||
// Test with a tool that requires approval (not auto-executed)
|
||||
const TOOL_CALL_RESPONSE: ChatMessage[] = [
|
||||
{
|
||||
role: "assistant",
|
||||
content: "I'll use a tool that requires approval.",
|
||||
toolCalls: [
|
||||
{
|
||||
id: "approval-required-tool-call",
|
||||
type: "function",
|
||||
function: {
|
||||
name: "unknown_tool_requiring_approval",
|
||||
arguments: JSON.stringify({
|
||||
param: "test.js",
|
||||
}),
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
await sendInputWithMockedResponse(
|
||||
ideMessenger,
|
||||
"Use a tool",
|
||||
TOOL_CALL_RESPONSE,
|
||||
);
|
||||
|
||||
// Wait for processing
|
||||
await act(async () => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
});
|
||||
|
||||
const state = store.getState();
|
||||
|
||||
// Verify we have a pending tool call
|
||||
const { findCurrentToolCallsByStatus } = await import("../../../redux/util");
|
||||
const pendingToolCalls = findCurrentToolCallsByStatus(state.session.history, "generated");
|
||||
expect(pendingToolCalls).toHaveLength(1);
|
||||
expect(pendingToolCalls[0].toolCall.function.name).toBe("unknown_tool_requiring_approval");
|
||||
|
||||
// Verify the individual tool call UI should now show up in the DOM
|
||||
// Since we fixed Chat.tsx to use toolCallStates instead of toolCallState,
|
||||
// the ToolCallDiv components should now render
|
||||
const state2 = store.getState();
|
||||
const history = state2.session.history;
|
||||
|
||||
// Find the message with tool calls
|
||||
const messageWithToolCalls = history.find(item =>
|
||||
item.message.role === "assistant" && item.toolCallStates?.length
|
||||
);
|
||||
|
||||
// Verify that both condition parts are met for rendering in Chat.tsx:
|
||||
// 1. item.message.toolCalls exists
|
||||
// 2. item.toolCallStates exists
|
||||
expect((messageWithToolCalls?.message as any).toolCalls).toBeDefined();
|
||||
expect(messageWithToolCalls?.toolCallStates).toBeDefined();
|
||||
expect(messageWithToolCalls?.toolCallStates).toHaveLength(1);
|
||||
});
|
||||
|
||||
test("should show all pending tool calls requiring permissions simultaneously", async () => {
|
||||
const { ideMessenger, store } = await renderWithProviders(<Chat />);
|
||||
|
||||
await act(async () => {
|
||||
addAndSelectMockLlm(store, ideMessenger);
|
||||
});
|
||||
|
||||
// Test with multiple tools that require approval
|
||||
const MULTIPLE_TOOL_CALLS_RESPONSE: ChatMessage[] = [
|
||||
{
|
||||
role: "assistant",
|
||||
content: "I'll use multiple tools that require approval.",
|
||||
toolCalls: [
|
||||
{
|
||||
id: "approval-required-tool-call-1",
|
||||
type: "function",
|
||||
function: {
|
||||
name: "write_file",
|
||||
arguments: JSON.stringify({
|
||||
file_path: "test1.js",
|
||||
content: "console.log('test1');"
|
||||
}),
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "approval-required-tool-call-2",
|
||||
type: "function",
|
||||
function: {
|
||||
name: "run_terminal_command",
|
||||
arguments: JSON.stringify({
|
||||
command: "npm test"
|
||||
}),
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "approval-required-tool-call-3",
|
||||
type: "function",
|
||||
function: {
|
||||
name: "edit_file",
|
||||
arguments: JSON.stringify({
|
||||
file_path: "test2.js",
|
||||
content: "console.log('test2');"
|
||||
}),
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
await sendInputWithMockedResponse(
|
||||
ideMessenger,
|
||||
"Use multiple tools",
|
||||
MULTIPLE_TOOL_CALLS_RESPONSE,
|
||||
);
|
||||
|
||||
// Wait for processing
|
||||
await act(async () => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
});
|
||||
|
||||
const state = store.getState();
|
||||
|
||||
// Verify we have multiple pending tool calls
|
||||
const { findCurrentToolCallsByStatus } = await import("../../../redux/util");
|
||||
const pendingToolCalls = findCurrentToolCallsByStatus(state.session.history, "generated");
|
||||
expect(pendingToolCalls).toHaveLength(3);
|
||||
|
||||
// Verify all tool calls are in "generated" status (requiring permissions)
|
||||
expect(pendingToolCalls[0].toolCall.function.name).toBe("write_file");
|
||||
expect(pendingToolCalls[0].status).toBe("generated");
|
||||
expect(pendingToolCalls[1].toolCall.function.name).toBe("run_terminal_command");
|
||||
expect(pendingToolCalls[1].status).toBe("generated");
|
||||
expect(pendingToolCalls[2].toolCall.function.name).toBe("edit_file");
|
||||
expect(pendingToolCalls[2].status).toBe("generated");
|
||||
|
||||
// The key test: All pending tool calls should be visible in the toolbar simultaneously
|
||||
// This verifies that the PendingToolCallToolbar shows all pending tools at once
|
||||
// rather than prompting for permissions one at a time
|
||||
|
||||
// Verify the PendingToolCallToolbar would show all three tool calls
|
||||
// by checking that all three are in the "generated" state
|
||||
const allGeneratedCalls = pendingToolCalls.filter(call => call.status === "generated");
|
||||
expect(allGeneratedCalls).toHaveLength(3);
|
||||
|
||||
// This test documents the expected behavior: all pending tool calls should
|
||||
// be shown simultaneously in the UI, not one at a time
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ export const selectLastToolCall = createSelector(
|
|||
break;
|
||||
}
|
||||
}
|
||||
return lastToolCallHistoryItem?.toolCallState ?? null;
|
||||
// Return the first tool call state from the states array
|
||||
return lastToolCallHistoryItem?.toolCallStates?.[0] ?? null;
|
||||
},
|
||||
);
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ import {
|
|||
Session,
|
||||
SessionMetadata,
|
||||
Tool,
|
||||
ToolCallState,
|
||||
} from "core";
|
||||
import { NEW_SESSION_TITLE } from "core/util/constants";
|
||||
import {
|
||||
|
|
@ -414,15 +415,21 @@ export const sessionSlice = createSlice({
|
|||
message.toolCalls?.length &&
|
||||
lastMessage.role === "assistant"
|
||||
) {
|
||||
// Handle multiple tool calls in streaming updates
|
||||
// Handle multiple tool calls in streaming updates - simplified index-based approach
|
||||
const existingToolCallStates = lastItem.toolCallStates || [];
|
||||
const updatedToolCallStates = message.toolCalls.map((toolCallDelta, index) => {
|
||||
const existingState = existingToolCallStates[index];
|
||||
return addToolCallDeltaToState(toolCallDelta, existingState);
|
||||
});
|
||||
const newToolCallStates: ToolCallState[] = [];
|
||||
|
||||
// Process each incoming tool call delta by index
|
||||
for (let i = 0; i < message.toolCalls.length; i++) {
|
||||
const toolCallDelta = message.toolCalls[i];
|
||||
const existingState = existingToolCallStates[i];
|
||||
const updatedState = addToolCallDeltaToState(toolCallDelta, existingState);
|
||||
newToolCallStates.push(updatedState);
|
||||
}
|
||||
|
||||
lastItem.toolCallStates = newToolCallStates;
|
||||
lastMessage.toolCalls = newToolCallStates.map(state => state.toolCall);
|
||||
|
||||
lastItem.toolCallStates = updatedToolCallStates;
|
||||
lastMessage.toolCalls = updatedToolCallStates.map(state => state.toolCall);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -575,6 +582,7 @@ export const sessionSlice = createSlice({
|
|||
state.history,
|
||||
action.payload.toolCallId,
|
||||
);
|
||||
|
||||
if (toolCallState) {
|
||||
toolCallState.status = "generated";
|
||||
|
||||
|
|
|
|||
15
gui/src/redux/thunks/cancelToolCallById.ts
Normal file
15
gui/src/redux/thunks/cancelToolCallById.ts
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import { createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import { RootState } from "../store";
|
||||
import { cancelToolCall } from "../slices/sessionSlice";
|
||||
|
||||
export const cancelToolCallById = createAsyncThunk<
|
||||
void,
|
||||
{ toolCallId: string },
|
||||
{ state: RootState }
|
||||
>("session/cancelToolCallById", async ({ toolCallId }, { dispatch }) => {
|
||||
// Cancel the specific tool call
|
||||
dispatch(cancelToolCall({ toolCallId }));
|
||||
|
||||
// Note: We don't need to manage streaming state here since streaming should
|
||||
// already be complete when tool calls are pending user approval
|
||||
});
|
||||
|
|
@ -6,6 +6,7 @@ import {
|
|||
updateToolCallOutput,
|
||||
} from "../slices/sessionSlice";
|
||||
import { ThunkApiType } from "../store";
|
||||
import { findToolCall } from "../util";
|
||||
import { streamResponseAfterToolCall } from "./streamResponseAfterToolCall";
|
||||
|
||||
/**
|
||||
|
|
@ -22,20 +23,12 @@ export const moveTerminalProcessToBackground = createAsyncThunk<
|
|||
>(
|
||||
"chat/moveTerminalProcessToBackground",
|
||||
async ({ toolCallId }, { dispatch, getState, extra }) => {
|
||||
// Find the current tool call
|
||||
// Find the current tool call using utility function
|
||||
const state = getState();
|
||||
const toolCalls = state.session.history.filter(
|
||||
(item) => item.toolCallState?.toolCallId === toolCallId,
|
||||
);
|
||||
|
||||
if (toolCalls.length === 0) {
|
||||
console.error("Could not find tool call with ID:", toolCallId);
|
||||
return;
|
||||
}
|
||||
|
||||
const toolCall = toolCalls[0].toolCallState;
|
||||
const toolCall = findToolCall(state.session.history, toolCallId);
|
||||
|
||||
if (!toolCall) {
|
||||
console.error("Tool call state is missing");
|
||||
console.error("Could not find tool call with ID:", toolCallId);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import { LLMFullCompletionOptions } from "core";
|
|||
import { modelSupportsTools } from "core/llm/autodetect";
|
||||
import { ToCoreProtocol } from "core/protocol";
|
||||
import { selectActiveTools } from "../selectors/selectActiveTools";
|
||||
import { selectCurrentToolCalls } from "../selectors/selectCurrentToolCall";
|
||||
import { selectCurrentToolCall } from "../selectors/selectCurrentToolCall";
|
||||
import { selectSelectedChatModel } from "../slices/configSlice";
|
||||
import {
|
||||
abortStream,
|
||||
|
|
|
|||
|
|
@ -316,7 +316,7 @@ describe("constructMessages", () => {
|
|||
{
|
||||
message: assistantWithToolCall,
|
||||
contextItems: [],
|
||||
toolCallState: {
|
||||
toolCallStates: [{
|
||||
toolCallId: "tool-call-1",
|
||||
toolCall: {
|
||||
id: "tool-call-1",
|
||||
|
|
@ -329,7 +329,7 @@ describe("constructMessages", () => {
|
|||
status: "done",
|
||||
parsedArgs: { query: "test" },
|
||||
output: [createContextItem("search-result", "Search result content")],
|
||||
},
|
||||
}],
|
||||
},
|
||||
];
|
||||
|
||||
|
|
@ -370,7 +370,7 @@ describe("constructMessages", () => {
|
|||
{
|
||||
message: assistantWithToolCall,
|
||||
contextItems: [],
|
||||
toolCallState: {
|
||||
toolCallStates: [{
|
||||
toolCallId: "tool-call-1",
|
||||
toolCall: {
|
||||
id: "tool-call-1",
|
||||
|
|
@ -382,7 +382,7 @@ describe("constructMessages", () => {
|
|||
},
|
||||
status: "canceled",
|
||||
parsedArgs: { query: "test" },
|
||||
},
|
||||
}],
|
||||
},
|
||||
];
|
||||
|
||||
|
|
@ -422,7 +422,7 @@ describe("constructMessages", () => {
|
|||
{
|
||||
message: assistantWithToolCall,
|
||||
contextItems: [],
|
||||
toolCallState: {
|
||||
toolCallStates: [{
|
||||
toolCallId: "tool-call-1",
|
||||
toolCall: {
|
||||
id: "tool-call-1",
|
||||
|
|
@ -434,7 +434,7 @@ describe("constructMessages", () => {
|
|||
},
|
||||
status: "generating", // Not done yet
|
||||
parsedArgs: { query: "test" },
|
||||
},
|
||||
}],
|
||||
},
|
||||
];
|
||||
|
||||
|
|
@ -499,7 +499,7 @@ describe("constructMessages", () => {
|
|||
{
|
||||
message: assistantWithMultipleToolCalls,
|
||||
contextItems: [],
|
||||
toolCallState: {
|
||||
toolCallStates: [{
|
||||
toolCallId: "tool-call-1",
|
||||
toolCall: {
|
||||
id: "tool-call-1",
|
||||
|
|
@ -512,7 +512,7 @@ describe("constructMessages", () => {
|
|||
status: "done",
|
||||
parsedArgs: { query: "test" },
|
||||
output: [createContextItem("search-result", "Search result content")],
|
||||
},
|
||||
}],
|
||||
},
|
||||
];
|
||||
|
||||
|
|
@ -665,7 +665,7 @@ describe("constructMessages", () => {
|
|||
{
|
||||
message: assistantWithToolCall,
|
||||
contextItems: [],
|
||||
toolCallState: {
|
||||
toolCallStates: [{
|
||||
toolCallId: "tool-call-1",
|
||||
toolCall: {
|
||||
id: "tool-call-1",
|
||||
|
|
@ -678,7 +678,7 @@ describe("constructMessages", () => {
|
|||
status: "done",
|
||||
parsedArgs: { query: "test" },
|
||||
output: [triggeringToolOutput],
|
||||
},
|
||||
}],
|
||||
},
|
||||
];
|
||||
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ export function constructMessages(
|
|||
// Find the corresponding tool call state for this specific tool call
|
||||
const toolCallState = item.toolCallStates?.find(
|
||||
state => state.toolCallId === toolCall.id
|
||||
) || (item.toolCallState?.toolCallId === toolCall.id ? item.toolCallState : undefined);
|
||||
);
|
||||
|
||||
if (toolCallState?.status === "canceled") {
|
||||
content = CANCELLED_TOOL_CALL_MESSAGE;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue