| ... | ... | @@ -263,12 +263,23 @@ export default function ChatView() { |
| 263 | 263 | const toggleTerminalVisibility = useCallback(() => { |
| 264 | 264 | if (!activeThreadId) return; |
| 265 | 265 | const isOpen = Boolean(activeThread?.terminalOpen); |
| 266 | |
| 267 | if (isOpen && api) { |
| 268 | if (typeof api.terminal.close === "function") { |
| 269 | void api.terminal.close({ threadId: activeThreadId }).catch(() => { |
| 270 | void api.terminal.write({ threadId: activeThreadId, data: "exit\n" }).catch(() => undefined); |
| 271 | }); |
| 272 | } else { |
| 273 | void api.terminal.write({ threadId: activeThreadId, data: "exit\n" }).catch(() => undefined); |
| 274 | } |
| 275 | } |
| 276 | |
| 266 | 277 | dispatch({ |
| 267 | 278 | type: "SET_THREAD_TERMINAL_OPEN", |
| 268 | 279 | threadId: activeThreadId, |
| 269 | 280 | open: !isOpen, |
| 270 | 281 | }); |
| 271 | | }, [activeThread?.terminalOpen, activeThreadId, dispatch]); |
| 282 | }, [activeThread?.terminalOpen, activeThreadId, api, dispatch]); |
| 272 | 283 | const splitTerminal = useCallback(() => { |
| 273 | 284 | if (!activeThreadId) return; |
| 274 | 285 | dispatch({ |
| ... | ... | @@ -303,21 +314,13 @@ export default function ChatView() { |
| 303 | 314 | (terminalId: string) => { |
| 304 | 315 | if (!activeThreadId || !api) return; |
| 305 | 316 | const fallbackExitWrite = () => |
| 306 | | api.terminal |
| 307 | | .write({ threadId: activeThreadId, terminalId, data: "exit\n" }) |
| 308 | | .catch(() => undefined); |
| 309 | | const fallbackClearAndExit = () => |
| 310 | | api.terminal |
| 311 | | .clear({ threadId: activeThreadId, terminalId }) |
| 312 | | .catch(() => undefined) |
| 313 | | .then(() => fallbackExitWrite()) |
| 314 | | .catch(() => undefined); |
| 317 | api.terminal.write({ threadId: activeThreadId, terminalId, data: "exit\n" }).catch(() => undefined); |
| 315 | 318 | if ("close" in api.terminal && typeof api.terminal.close === "function") { |
| 316 | 319 | void api.terminal |
| 317 | | .close({ threadId: activeThreadId, terminalId, deleteHistory: true }) |
| 318 | | .catch(() => fallbackClearAndExit()); |
| 320 | .close({ threadId: activeThreadId, terminalId }) |
| 321 | .catch(() => fallbackExitWrite()); |
| 319 | 322 | } else { |
| 320 | | void fallbackClearAndExit(); |
| 323 | void fallbackExitWrite(); |
| 321 | 324 | } |
| 322 | 325 | dispatch({ |
| 323 | 326 | type: "CLOSE_THREAD_TERMINAL", |