keyboard shortcuts for accept/reject tool calls
This commit is contained in:
parent
a9d969cd82
commit
d2cbbbe86a
7 changed files with 98 additions and 138 deletions
2
core/package-lock.json
generated
2
core/package-lock.json
generated
|
|
@ -134,7 +134,7 @@
|
|||
},
|
||||
"../packages/config-yaml": {
|
||||
"name": "@continuedev/config-yaml",
|
||||
"version": "1.0.78",
|
||||
"version": "1.0.87",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@continuedev/config-types": "^1.0.14",
|
||||
|
|
|
|||
2
gui/package-lock.json
generated
2
gui/package-lock.json
generated
|
|
@ -206,7 +206,7 @@
|
|||
},
|
||||
"../packages/config-yaml": {
|
||||
"name": "@continuedev/config-yaml",
|
||||
"version": "1.0.78",
|
||||
"version": "1.0.87",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@continuedev/config-types": "^1.0.14",
|
||||
|
|
|
|||
|
|
@ -3,14 +3,7 @@ import { InputModifiers } from "core";
|
|||
import { modelSupportsImages, modelSupportsTools } from "core/llm/autodetect";
|
||||
import { useRef } from "react";
|
||||
import styled from "styled-components";
|
||||
import {
|
||||
defaultBorderRadius,
|
||||
lightGray,
|
||||
vscButtonBackground,
|
||||
vscButtonForeground,
|
||||
vscForeground,
|
||||
vscInputBackground,
|
||||
} from "..";
|
||||
import { vscInputBackground } from "..";
|
||||
import { useAppDispatch, useAppSelector } from "../../redux/hooks";
|
||||
import { selectUseActiveFile } from "../../redux/selectors";
|
||||
import { selectCurrentToolCall } from "../../redux/selectors/selectCurrentToolCall";
|
||||
|
|
@ -31,6 +24,7 @@ import { ToolTip } from "../gui/Tooltip";
|
|||
import ModelSelect from "../modelSelection/ModelSelect";
|
||||
import ModeSelect from "../modelSelection/ModeSelect";
|
||||
import { useFontSize } from "../ui/font";
|
||||
import { EnterButton } from "./InputToolbar/EnterButton";
|
||||
import HoverItem from "./InputToolbar/HoverItem";
|
||||
|
||||
const StyledDiv = styled.div<{ isHidden?: boolean }>`
|
||||
|
|
@ -50,25 +44,6 @@ const StyledDiv = styled.div<{ isHidden?: boolean }>`
|
|||
}
|
||||
`;
|
||||
|
||||
const EnterButton = styled.button<{ isPrimary?: boolean }>`
|
||||
all: unset;
|
||||
padding: 2px 4px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
background-color: ${(props) =>
|
||||
!props.disabled && props.isPrimary
|
||||
? vscButtonBackground
|
||||
: lightGray + "33"};
|
||||
border-radius: ${defaultBorderRadius};
|
||||
color: ${(props) =>
|
||||
!props.disabled && props.isPrimary ? vscButtonForeground : vscForeground};
|
||||
cursor: pointer;
|
||||
|
||||
:disabled {
|
||||
cursor: wait;
|
||||
}
|
||||
`;
|
||||
|
||||
export interface ToolbarOptions {
|
||||
hideUseCodebase?: boolean;
|
||||
hideImageUpload?: boolean;
|
||||
|
|
|
|||
29
gui/src/components/mainInput/InputToolbar/EnterButton.tsx
Normal file
29
gui/src/components/mainInput/InputToolbar/EnterButton.tsx
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import styled from "styled-components";
|
||||
import {
|
||||
defaultBorderRadius,
|
||||
lightGray,
|
||||
vscButtonBackground,
|
||||
vscButtonForeground,
|
||||
vscForeground,
|
||||
} from "../..";
|
||||
import { fontSize } from "../../../util";
|
||||
|
||||
export const EnterButton = styled.button<{ isPrimary?: boolean }>`
|
||||
all: unset;
|
||||
font-size: ${fontSize(-3)};
|
||||
padding: 2px 4px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
background-color: ${(props) =>
|
||||
!props.disabled && props.isPrimary
|
||||
? vscButtonBackground
|
||||
: lightGray + "33"};
|
||||
border-radius: ${defaultBorderRadius};
|
||||
color: ${(props) =>
|
||||
!props.disabled && props.isPrimary ? vscButtonForeground : vscForeground};
|
||||
cursor: pointer;
|
||||
|
||||
:disabled {
|
||||
cursor: wait;
|
||||
}
|
||||
`;
|
||||
|
|
@ -1,10 +1,15 @@
|
|||
import { useContext } from "react";
|
||||
import { useContext, useEffect } from "react";
|
||||
import { useSelector } from "react-redux";
|
||||
import styled from "styled-components";
|
||||
import { AnimatedEllipsis } from "../..";
|
||||
import { IdeMessengerContext } from "../../../context/IdeMessenger";
|
||||
import { useAppDispatch, useAppSelector } from "../../../redux/hooks";
|
||||
import { selectCurrentToolCall } from "../../../redux/selectors/selectCurrentToolCall";
|
||||
import { callTool } from "../../../redux/thunks/callTool";
|
||||
import { cancelStream } from "../../../redux/thunks/cancelStream";
|
||||
import { cancelTool } from "../../../redux/thunks/cancelTool";
|
||||
import { getFontSize, getMetaKeyLabel } from "../../../util";
|
||||
import { EnterButton } from "../InputToolbar/EnterButton";
|
||||
import { BlockSettingsTopToolbar } from "./BlockSettingsTopToolbar";
|
||||
|
||||
const Container = styled.div`
|
||||
|
|
@ -36,6 +41,31 @@ export function LumpToolbar() {
|
|||
const ttsActive = useAppSelector((state) => state.ui.ttsActive);
|
||||
const isStreaming = useAppSelector((state) => state.session.isStreaming);
|
||||
|
||||
const toolCallState = useSelector(selectCurrentToolCall);
|
||||
|
||||
const handleKeyDown = (event: KeyboardEvent) => {
|
||||
if (toolCallState?.status === "generated") {
|
||||
const metaKey = event.metaKey || event.ctrlKey;
|
||||
|
||||
if (metaKey && event.key === "Enter") {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
dispatch(callTool());
|
||||
} else if (metaKey && event.key === "Backspace") {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
dispatch(cancelTool());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
document.addEventListener("keydown", handleKeyDown);
|
||||
return () => {
|
||||
document.removeEventListener("keydown", handleKeyDown);
|
||||
};
|
||||
}, [toolCallState]);
|
||||
|
||||
if (ttsActive) {
|
||||
return (
|
||||
<Container>
|
||||
|
|
@ -68,5 +98,31 @@ export function LumpToolbar() {
|
|||
);
|
||||
}
|
||||
|
||||
if (toolCallState?.status === "generated") {
|
||||
return (
|
||||
<Container>
|
||||
<GeneratingIndicator />
|
||||
|
||||
<div className="flex gap-2 pb-0.5">
|
||||
<StopButton
|
||||
className="text-gray-400"
|
||||
onClick={() => dispatch(cancelTool())}
|
||||
data-testid="reject-tool-call-button"
|
||||
>
|
||||
{getMetaKeyLabel()} ⌫ Cancel
|
||||
</StopButton>
|
||||
<EnterButton
|
||||
isPrimary={true}
|
||||
className="text-gray-400"
|
||||
onClick={() => dispatch(callTool())}
|
||||
data-testid="accept-tool-call-button"
|
||||
>
|
||||
{getMetaKeyLabel()} ⏎ Continue
|
||||
</EnterButton>
|
||||
</div>
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
return <BlockSettingsTopToolbar />;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ import {
|
|||
newSession,
|
||||
selectIsInEditMode,
|
||||
selectIsSingleRangeEditOrInsertion,
|
||||
updateToolCallOutput
|
||||
updateToolCallOutput,
|
||||
} from "../../redux/slices/sessionSlice";
|
||||
import {
|
||||
setDialogEntryOn,
|
||||
|
|
@ -58,7 +58,6 @@ import { getLocalStorage, setLocalStorage } from "../../util/localStorage";
|
|||
import { EmptyChatBody } from "./EmptyChatBody";
|
||||
import { ExploreDialogWatcher } from "./ExploreDialogWatcher";
|
||||
import { ToolCallDiv } from "./ToolCallDiv";
|
||||
import { ToolCallButtons } from "./ToolCallDiv/ToolCallButtonsDiv";
|
||||
import ToolOutput from "./ToolCallDiv/ToolOutput";
|
||||
import { useAutoScroll } from "./useAutoScroll";
|
||||
|
||||
|
|
@ -277,13 +276,13 @@ export function Chat() {
|
|||
useWebviewListener(
|
||||
"toolCallPartialOutput",
|
||||
async (data) => {
|
||||
// Update tool call output in Redux store
|
||||
dispatch(
|
||||
updateToolCallOutput({
|
||||
toolCallId: data.toolCallId,
|
||||
contextItems: data.contextItems,
|
||||
}),
|
||||
);
|
||||
// Update tool call output in Redux store
|
||||
dispatch(
|
||||
updateToolCallOutput({
|
||||
toolCallId: data.toolCallId,
|
||||
contextItems: data.contextItems,
|
||||
}),
|
||||
);
|
||||
},
|
||||
[dispatch],
|
||||
);
|
||||
|
|
@ -410,8 +409,6 @@ export function Chat() {
|
|||
))}
|
||||
</StepsDiv>
|
||||
<div className={"relative"}>
|
||||
{toolCallState?.status === "generated" && <ToolCallButtons />}
|
||||
|
||||
{isInEditMode && history.length === 0 && <CodeToEditCard />}
|
||||
|
||||
{isInEditMode && history.length > 0 ? null : (
|
||||
|
|
|
|||
|
|
@ -1,97 +0,0 @@
|
|||
import { useSelector } from "react-redux";
|
||||
import styled from "styled-components";
|
||||
import {
|
||||
defaultBorderRadius,
|
||||
lightGray,
|
||||
vscButtonBackground,
|
||||
vscButtonForeground,
|
||||
} from "../../../components";
|
||||
import Spinner from "../../../components/gui/Spinner";
|
||||
import { useAppDispatch } from "../../../redux/hooks";
|
||||
import { selectCurrentToolCall } from "../../../redux/selectors/selectCurrentToolCall";
|
||||
import { callTool } from "../../../redux/thunks/callTool";
|
||||
import { cancelTool } from "../../../redux/thunks/cancelTool";
|
||||
|
||||
const ButtonContainer = styled.div`
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
margin-top: 12px;
|
||||
margin: 8px;
|
||||
`;
|
||||
|
||||
const Button = styled.button`
|
||||
padding: 5px;
|
||||
border-radius: ${defaultBorderRadius};
|
||||
flex: 1;
|
||||
|
||||
&:hover {
|
||||
cursor: pointer;
|
||||
opacity: 0.8;
|
||||
}
|
||||
`;
|
||||
|
||||
const AcceptButton = styled(Button)`
|
||||
color: ${vscButtonForeground};
|
||||
border: none;
|
||||
background-color: ${vscButtonBackground};
|
||||
color: ${vscButtonForeground};
|
||||
|
||||
&:hover {
|
||||
cursor: pointer;
|
||||
}
|
||||
`;
|
||||
|
||||
const RejectButton = styled(Button)`
|
||||
color: ${lightGray};
|
||||
border: 1px solid ${lightGray};
|
||||
background-color: transparent;
|
||||
`;
|
||||
|
||||
interface ToolCallButtonsProps {}
|
||||
|
||||
export function ToolCallButtons(props: ToolCallButtonsProps) {
|
||||
const dispatch = useAppDispatch();
|
||||
const toolCallState = useSelector(selectCurrentToolCall);
|
||||
|
||||
if (!toolCallState) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<ButtonContainer>
|
||||
{toolCallState.status === "generating" ? (
|
||||
<div
|
||||
className="flex w-full items-center justify-center gap-4"
|
||||
style={{
|
||||
color: lightGray,
|
||||
minHeight: "40px",
|
||||
}}
|
||||
>
|
||||
Thinking...
|
||||
</div>
|
||||
) : toolCallState.status === "generated" ? (
|
||||
<>
|
||||
<RejectButton
|
||||
onClick={() => dispatch(cancelTool())}
|
||||
data-testid="reject-tool-call-button"
|
||||
>
|
||||
Cancel
|
||||
</RejectButton>
|
||||
<AcceptButton
|
||||
onClick={() => dispatch(callTool())}
|
||||
data-testid="accept-tool-call-button"
|
||||
>
|
||||
Continue
|
||||
</AcceptButton>
|
||||
</>
|
||||
) : toolCallState.status === "calling" ? (
|
||||
<div className="ml-auto flex items-center gap-4">
|
||||
Loading...
|
||||
<Spinner />
|
||||
</div>
|
||||
) : null}
|
||||
</ButtonContainer>
|
||||
</>
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue