From a4460698692a763b4dcd0710968ff8a06bfc7fb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=AE=AE=E0=AE=A9=E0=AF=8B=E0=AE=9C=E0=AF=8D=E0=AE=95?= =?UTF-8?q?=E0=AF=81=E0=AE=AE=E0=AE=BE=E0=AE=B0=E0=AF=8D=20=E0=AE=AA?= =?UTF-8?q?=E0=AE=B4=E0=AE=A9=E0=AE=BF=E0=AE=9A=E0=AF=8D=E0=AE=9A=E0=AE=BE?= =?UTF-8?q?=E0=AE=AE=E0=AE=BF?= Date: Mon, 29 Jul 2024 17:58:59 +0530 Subject: [PATCH 1/5] UI: Enable right click to paste in terminal --- frontend/src/hooks/useTerminal.ts | 9 ++++++++- frontend/src/services/terminalService.ts | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/frontend/src/hooks/useTerminal.ts b/frontend/src/hooks/useTerminal.ts index d2665d33b543..f44c4e689cd1 100644 --- a/frontend/src/hooks/useTerminal.ts +++ b/frontend/src/hooks/useTerminal.ts @@ -73,7 +73,14 @@ export const useTerminal = (commands: Command[] = []) => { } return true; }); - + // right click to paste + terminal.current.element?.addEventListener("contextmenu", (e) => { + e.preventDefault(); + navigator.clipboard.readText().then((text) => { + terminal.current?.write(text); + commandBuffer += text; + }); + }); /* Listen for resize events */ resizeObserver = new ResizeObserver(() => { fitAddon.current?.fit(); diff --git a/frontend/src/services/terminalService.ts b/frontend/src/services/terminalService.ts index 7f3608245bef..0b9552349298 100644 --- a/frontend/src/services/terminalService.ts +++ b/frontend/src/services/terminalService.ts @@ -2,6 +2,8 @@ import ActionType from "#/types/ActionType"; import Session from "./session"; export function sendTerminalCommand(command: string): void { + // replace END OF TEXT character + command = command.replace(/\u0003+/, ''); const event = { action: ActionType.RUN, args: { command } }; const eventString = JSON.stringify(event); Session.send(eventString); From d00f54fcf5fc7467d203c02f98a55fcf73be48e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=AE=AE=E0=AE=A9=E0=AF=8B=E0=AE=9C=E0=AF=8D=E0=AE=95?= =?UTF-8?q?=E0=AF=81=E0=AE=AE=E0=AE=BE=E0=AE=B0=E0=AF=8D=20=E0=AE=AA?= =?UTF-8?q?=E0=AE=B4=E0=AE=A9=E0=AE=BF=E0=AE=9A=E0=AF=8D=E0=AE=9A=E0=AE=BE?= =?UTF-8?q?=E0=AE=AE=E0=AE=BF?= Date: Mon, 29 Jul 2024 18:13:46 +0530 Subject: [PATCH 2/5] lint --- frontend/src/services/terminalService.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/frontend/src/services/terminalService.ts b/frontend/src/services/terminalService.ts index 0b9552349298..8e5dcf1ffa60 100644 --- a/frontend/src/services/terminalService.ts +++ b/frontend/src/services/terminalService.ts @@ -2,9 +2,10 @@ import ActionType from "#/types/ActionType"; import Session from "./session"; export function sendTerminalCommand(command: string): void { - // replace END OF TEXT character - command = command.replace(/\u0003+/, ''); - const event = { action: ActionType.RUN, args: { command } }; + // replace END OF TEXT character copied from terminal + // eslint-disable-next-line no-control-regex + const cleanedCommand = command.replace(/\u0003+/, ""); + const event = { action: ActionType.RUN, args: { command: cleanedCommand } }; const eventString = JSON.stringify(event); Session.send(eventString); } From f5bdb32db47c04c31149df9216abf59ddb7def65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=AE=AE=E0=AE=A9=E0=AF=8B=E0=AE=9C=E0=AF=8D=E0=AE=95?= =?UTF-8?q?=E0=AF=81=E0=AE=AE=E0=AE=BE=E0=AE=B0=E0=AF=8D=20=E0=AE=AA?= =?UTF-8?q?=E0=AE=B4=E0=AE=A9=E0=AE=BF=E0=AE=9A=E0=AF=8D=E0=AE=9A=E0=AE=BE?= =?UTF-8?q?=E0=AE=AE=E0=AE=BF?= Date: Mon, 29 Jul 2024 19:59:12 +0530 Subject: [PATCH 3/5] reject empty commands --- frontend/src/services/terminalService.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/src/services/terminalService.ts b/frontend/src/services/terminalService.ts index 8e5dcf1ffa60..e37e5698f1cd 100644 --- a/frontend/src/services/terminalService.ts +++ b/frontend/src/services/terminalService.ts @@ -5,6 +5,7 @@ export function sendTerminalCommand(command: string): void { // replace END OF TEXT character copied from terminal // eslint-disable-next-line no-control-regex const cleanedCommand = command.replace(/\u0003+/, ""); + if (!cleanedCommand) return; const event = { action: ActionType.RUN, args: { command: cleanedCommand } }; const eventString = JSON.stringify(event); Session.send(eventString); From 4d76ac22889567773a3a81d30bd4f29455181c69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=AE=AE=E0=AE=A9=E0=AF=8B=E0=AE=9C=E0=AF=8D=E0=AE=95?= =?UTF-8?q?=E0=AF=81=E0=AE=AE=E0=AE=BE=E0=AE=B0=E0=AF=8D=20=E0=AE=AA?= =?UTF-8?q?=E0=AE=B4=E0=AE=A9=E0=AE=BF=E0=AE=9A=E0=AF=8D=E0=AE=9A=E0=AE=BE?= =?UTF-8?q?=E0=AE=AE=E0=AE=BF?= Date: Wed, 14 Aug 2024 17:24:59 +0530 Subject: [PATCH 4/5] prettify --- frontend/src/components/AgentControlBar.tsx | 1 - frontend/src/components/Jupyter.tsx | 8 +++++--- frontend/src/components/chat/ChatInterface.tsx | 7 +++++-- frontend/src/services/chatService.ts | 2 +- frontend/src/state/chatSlice.ts | 8 ++++++-- frontend/src/state/jupyterSlice.ts | 6 +++++- 6 files changed, 22 insertions(+), 10 deletions(-) diff --git a/frontend/src/components/AgentControlBar.tsx b/frontend/src/components/AgentControlBar.tsx index ad00039ed7e0..fde432e8270f 100644 --- a/frontend/src/components/AgentControlBar.tsx +++ b/frontend/src/components/AgentControlBar.tsx @@ -83,7 +83,6 @@ function AgentControlBar() { return; } - setDesiredState(action); changeAgentState(action); diff --git a/frontend/src/components/Jupyter.tsx b/frontend/src/components/Jupyter.tsx index a36389c12983..f54266e4276f 100644 --- a/frontend/src/components/Jupyter.tsx +++ b/frontend/src/components/Jupyter.tsx @@ -105,7 +105,7 @@ function Jupyter(): JSX.Element { const onKeyPress = (event: React.KeyboardEvent) => { if (event.key === "Enter" && !event.shiftKey) { event.preventDefault(); // prevent a new line - handleInputSubmit(); + handleInputSubmit(); } }; @@ -135,8 +135,10 @@ function Jupyter(): JSX.Element { )} -
+
{ dispatch(removeLastAssistantMessage()); regenerateLastMessage(); diff --git a/frontend/src/services/chatService.ts b/frontend/src/services/chatService.ts index 9795f9ae251c..d2667dfe835e 100644 --- a/frontend/src/services/chatService.ts +++ b/frontend/src/services/chatService.ts @@ -22,7 +22,7 @@ export function regenerateLastMessage(): void { export function sendJupyterCode(code: string): void { const event = { action: ActionType.RUN_IPYTHON, - args: { code}, + args: { code }, }; const eventString = JSON.stringify(event); Session.send(eventString); diff --git a/frontend/src/state/chatSlice.ts b/frontend/src/state/chatSlice.ts index d83048e871a0..6a5f83201807 100644 --- a/frontend/src/state/chatSlice.ts +++ b/frontend/src/state/chatSlice.ts @@ -41,6 +41,10 @@ export const chatSlice = createSlice({ }, }); -export const { addUserMessage, addAssistantMessage, clearMessages, removeLastAssistantMessage } = - chatSlice.actions; +export const { + addUserMessage, + addAssistantMessage, + clearMessages, + removeLastAssistantMessage, +} = chatSlice.actions; export default chatSlice.reducer; diff --git a/frontend/src/state/jupyterSlice.ts b/frontend/src/state/jupyterSlice.ts index 573323676d2a..e70e5989439f 100644 --- a/frontend/src/state/jupyterSlice.ts +++ b/frontend/src/state/jupyterSlice.ts @@ -25,6 +25,10 @@ export const cellSlice = createSlice({ }, }); -export const { appendJupyterInput, appendJupyterOutput, handleInputSubmission } = cellSlice.actions; +export const { + appendJupyterInput, + appendJupyterOutput, + handleInputSubmission, +} = cellSlice.actions; export default cellSlice.reducer; From 302d3395bbb1a43e9b996111e800e9081658616a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=AE=AE=E0=AE=A9=E0=AF=8B=E0=AE=9C=E0=AF=8D=E0=AE=95?= =?UTF-8?q?=E0=AF=81=E0=AE=AE=E0=AE=BE=E0=AE=B0=E0=AF=8D=20=E0=AE=AA?= =?UTF-8?q?=E0=AE=B4=E0=AE=A9=E0=AE=BF=E0=AE=9A=E0=AF=8D=E0=AE=9A=E0=AE=BE?= =?UTF-8?q?=E0=AE=AE=E0=AE=BF?= Date: Thu, 15 Aug 2024 15:47:52 +0530 Subject: [PATCH 5/5] apply suggestion --- frontend/src/hooks/useTerminal.ts | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/frontend/src/hooks/useTerminal.ts b/frontend/src/hooks/useTerminal.ts index b6f852d19700..a1b6d6e0b1cf 100644 --- a/frontend/src/hooks/useTerminal.ts +++ b/frontend/src/hooks/useTerminal.ts @@ -28,6 +28,14 @@ export const useTerminal = (commands: Command[] = []) => { let resizeObserver: ResizeObserver; let commandBuffer = ""; + const terminalElement = terminal.current?.element; + const handleContextMenu = (e: MouseEvent) => { + e.preventDefault(); + navigator.clipboard.readText().then((text) => { + terminal.current?.write(text); + commandBuffer += text; + }); + }; if (ref.current) { /* Initialize the terminal in the DOM */ @@ -73,14 +81,12 @@ export const useTerminal = (commands: Command[] = []) => { } return true; }); - // right click to paste - terminal.current.element?.addEventListener("contextmenu", (e) => { - e.preventDefault(); - navigator.clipboard.readText().then((text) => { - terminal.current?.write(text); - commandBuffer += text; - }); - }); + + if (terminalElement) { + // right click to paste + terminalElement.addEventListener("contextmenu", handleContextMenu); + } + /* Listen for resize events */ resizeObserver = new ResizeObserver(() => { fitAddon.current?.fit(); @@ -89,6 +95,9 @@ export const useTerminal = (commands: Command[] = []) => { } return () => { + if (terminalElement) { + terminalElement.removeEventListener("contextmenu", handleContextMenu); + } terminal.current?.dispose(); resizeObserver.disconnect(); };