From eb1cddaf9026be6237165bbeea93f0d86a466504 Mon Sep 17 00:00:00 2001 From: Nate Date: Mon, 18 Nov 2024 19:24:57 -0800 Subject: [PATCH] tab and cmd+backspace for continue and cancel buttons --- gui/src/pages/gui/ToolCallDiv/index.tsx | 29 +++++++++++++++++++++++-- gui/src/pages/gui/ToolCallDiv/types.ts | 7 +++++- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/gui/src/pages/gui/ToolCallDiv/index.tsx b/gui/src/pages/gui/ToolCallDiv/index.tsx index f234f2640..092468f06 100644 --- a/gui/src/pages/gui/ToolCallDiv/index.tsx +++ b/gui/src/pages/gui/ToolCallDiv/index.tsx @@ -16,6 +16,10 @@ import { RunTerminalCommand } from "./RunTerminalCommand"; import { ToolState } from "./types"; const Container = styled.div` + display: flex; + flex-direction: column; + justify-content: center; + margin: 8px; overflow: hidden; border-left: 1px solid ${lightGray}; @@ -120,6 +124,26 @@ export function ToolCallDiv(props: ToolCallDivProps) { } }, [props.toolCall.function.arguments]); + useEffect(() => { + function handleKeyDown(e: KeyboardEvent) { + if (e.key === "Tab") { + e.preventDefault(); + callTool(); + } + if (e.key === "Backspace" && e.metaKey) { + e.preventDefault(); + cancelTool(); + } + } + + window.addEventListener("keydown", handleKeyDown); + return () => window.removeEventListener("keydown", handleKeyDown); + }, []); + + async function cancelTool() { + setState("canceled"); + } + async function callTool() { let setCallingState = true; @@ -157,14 +181,15 @@ export function ToolCallDiv(props: ToolCallDivProps) { className="flex w-full items-center justify-center gap-4" style={{ color: lightGray, + minHeight: "40px", }} > Thinking... - + {/* */} ) : state === "generated" ? ( <> - {}}>Cancel + Cancel Continue ) : state === "calling" ? ( diff --git a/gui/src/pages/gui/ToolCallDiv/types.ts b/gui/src/pages/gui/ToolCallDiv/types.ts index fa041be64..2a21a7bb9 100644 --- a/gui/src/pages/gui/ToolCallDiv/types.ts +++ b/gui/src/pages/gui/ToolCallDiv/types.ts @@ -1 +1,6 @@ -export type ToolState = "generating" | "generated" | "calling" | "done"; +export type ToolState = + | "generating" + | "generated" + | "calling" + | "done" + | "canceled";