Skip to content

Commit

Permalink
clear shell and notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
SmartManoj committed Aug 18, 2024
1 parent f7117d7 commit 6eeca42
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
6 changes: 5 additions & 1 deletion frontend/src/components/AgentControlBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import { changeAgentState } from "#/services/agentStateService";
import store, { RootState } from "#/store";
import AgentState from "#/types/AgentState";
import { clearMessages } from "#/state/chatSlice";
import { clearCells } from "#/state/jupyterSlice";
import Session from "#/services/session";
import { clearCommands } from "#/state/commandSlice";

const IgnoreTaskStateMap: { [k: string]: AgentState[] } = {
[AgentState.PAUSED]: [
Expand All @@ -29,7 +31,7 @@ const IgnoreTaskStateMap: { [k: string]: AgentState[] } = {
AgentState.AWAITING_USER_INPUT,
AgentState.AWAITING_USER_CONFIRMATION,
],
[AgentState.STOPPED]: [AgentState.INIT, AgentState.STOPPED],
[AgentState.STOPPED]: [AgentState.STOPPED],
[AgentState.USER_CONFIRMED]: [AgentState.RUNNING],
[AgentState.USER_REJECTED]: [AgentState.RUNNING],
[AgentState.AWAITING_USER_CONFIRMATION]: [],
Expand Down Expand Up @@ -89,6 +91,8 @@ function AgentControlBar() {
if (action === AgentState.STOPPED) {
Session._history = [];
store.dispatch(clearMessages());
store.dispatch(clearCells());
store.dispatch(clearCommands());
} else {
setIsLoading(true);
}
Expand Down
7 changes: 7 additions & 0 deletions frontend/src/hooks/useTerminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const useTerminal = (commands: Command[] = []) => {
const fitAddon = React.useRef<FitAddon | null>(null);
const ref = React.useRef<HTMLDivElement>(null);
const lastCommandIndex = React.useRef(0);
let lastCommand = React.useRef("");

React.useEffect(() => {
/* Create a new terminal instance */
Expand Down Expand Up @@ -47,6 +48,7 @@ export const useTerminal = (commands: Command[] = []) => {
if (domEvent.key === "Enter") {
terminal.current?.write("\r\n");
sendTerminalCommand(commandBuffer);
lastCommand.current = commandBuffer;
commandBuffer = "";
} else if (domEvent.key === "Backspace") {
if (commandBuffer.length > 0) {
Expand Down Expand Up @@ -106,6 +108,11 @@ export const useTerminal = (commands: Command[] = []) => {
React.useEffect(() => {
/* Write commands to the terminal */
if (terminal.current && commands.length > 0) {
// commands would be cleared. Reset the last command index
if (lastCommandIndex.current >= commands.length) {
lastCommandIndex.current = 0;
terminal.current?.clear();
}
// Start writing commands from the last command index
for (let i = lastCommandIndex.current; i < commands.length; i += 1) {
const command = commands[i];
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/state/commandSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ export const commandSlice = createSlice({
appendOutput: (state, action) => {
state.commands.push({ content: action.payload, type: "output" });
},
clearCommands: (state) => {
state.commands = [];
},
},
});

export const { appendInput, appendOutput } = commandSlice.actions;
export const { appendInput, appendOutput, clearCommands } =
commandSlice.actions;

export default commandSlice.reducer;
4 changes: 4 additions & 0 deletions frontend/src/state/jupyterSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@ export const cellSlice = createSlice({
handleInputSubmission: (state, action) => {
state.cells.push({ content: action.payload, type: "input" });
},
clearCells: (state) => {
state.cells = [];
},
},
});

export const {
appendJupyterInput,
appendJupyterOutput,
handleInputSubmission,
clearCells,
} = cellSlice.actions;

export default cellSlice.reducer;

0 comments on commit 6eeca42

Please sign in to comment.