diff --git a/electron/main/index.ts b/electron/main/index.ts index af7152835..dd0394ed0 100644 --- a/electron/main/index.ts +++ b/electron/main/index.ts @@ -312,6 +312,24 @@ function registerIpcHandlers() { }); ipcMain.handle('get-app-version', () => app.getVersion()); ipcMain.handle('get-backend-port', () => backendPort); + ipcMain.handle('restart-backend', async () => { + try { + if (backendPort) { + log.info('Restarting backend service...'); + await cleanupPythonProcess(); + await checkAndStartBackend(); + log.info('Backend restart completed successfully'); + return { success: true }; + } else { + log.warn('No backend port found, starting fresh backend'); + await checkAndStartBackend(); + return { success: true }; + } + } catch (error) { + log.error('Failed to restart backend:', error); + return { success: false, error: String(error) }; + } + }); ipcMain.handle('get-system-language', getSystemLanguage); ipcMain.handle('is-fullscreen', () => win?.isFullScreen() || false); ipcMain.handle('get-home-dir', () => { diff --git a/electron/main/webview.ts b/electron/main/webview.ts index 20816fd1b..123d464d2 100644 --- a/electron/main/webview.ts +++ b/electron/main/webview.ts @@ -112,18 +112,23 @@ export class WebViewManager { } console.log(`Webview ${id} navigated to: ${navigationUrl}`) if (webViewInfo.isActive && webViewInfo.isShow && navigationUrl !== 'about:blank?use=0' && navigationUrl !== 'about:blank') { - console.log("did-navigate", id, url) - this.win?.webContents.send("url-updated", url); + console.log("did-navigate", id, navigationUrl) + this.win?.webContents.send("url-updated", navigationUrl); return } webViewInfo.view.setBounds({ x: -1919, y: -1079, width: 1920, height: 1080 }) const activeSize = this.getActiveWebview().length const allSize = Array.from(this.webViews.values()).length if (allSize - activeSize <= 3) { - const newId = Array.from(this.webViews.keys()).length + 2 - this.createWebview(newId.toString(), 'about:blank?use=0') - this.createWebview((newId + 1).toString(), 'about:blank?use=0') - this.createWebview((newId + 2).toString(), 'about:blank?use=0') + const existingKeys = Array.from(this.webViews.keys()).map(Number).filter(n => !isNaN(n)) + const maxId = existingKeys.length > 0 ? Math.max(...existingKeys) : 0 + const startId = maxId + 1 + + // Create webviews sequentially to avoid race conditions + for (let i = 0; i < 3; i++) { + const nextId = (startId + i).toString() + this.createWebview(nextId, 'about:blank?use=0') + } } // setTimeout(() => { @@ -242,8 +247,12 @@ export class WebViewManager { } } - public distroy() { - // TODO: Destroy all webviews + public destroy() { + // Destroy all webviews + Array.from(this.webViews.keys()).forEach(id => { + this.destroyWebview(id) + }) + this.webViews.clear() } } diff --git a/src/pages/Setting/Models.tsx b/src/pages/Setting/Models.tsx index 5bb082586..577119b80 100644 --- a/src/pages/Setting/Models.tsx +++ b/src/pages/Setting/Models.tsx @@ -682,9 +682,6 @@ export default function SettingModels() { GPT-5 GPT-5 mini GPT-5 nano - - Claude Opus 4.1 - Claude Sonnet 4 diff --git a/src/store/chatStore.ts b/src/store/chatStore.ts index 7069fa406..64649dabe 100644 --- a/src/store/chatStore.ts +++ b/src/store/chatStore.ts @@ -497,7 +497,7 @@ const chatStore = create()( setTaskAssigning(taskId, taskAssigning) return; } - + // Activate agent if (agentMessages.step === "activate_agent" || agentMessages.step === "deactivate_agent") { let taskAssigning = [...tasks[taskId].taskAssigning] @@ -607,7 +607,7 @@ const chatStore = create()( if (taskAssigning && taskAssigning[assigneeAgentIndex]) { // Check if task already exists in the agent's task list const existingTaskIndex = taskAssigning[assigneeAgentIndex].tasks.findIndex(item => item.id === task_id); - + if (existingTaskIndex !== -1) { // Task already exists, update its status taskAssigning[assigneeAgentIndex].tasks[existingTaskIndex].status = "running"; @@ -624,7 +624,7 @@ const chatStore = create()( taskAssigning[assigneeAgentIndex].tasks.push(taskTemp ?? { id: task_id, content, status: "running", }); } } - + // Only update or add to taskRunning, never duplicate if (taskRunningIndex === -1) { // Task not in taskRunning, add it @@ -1638,7 +1638,17 @@ const chatStore = create()( clearTasks: () => { const { create } = get() console.log('clearTasks') - fetchDelete('/task/stop-all') + + window.ipcRenderer.invoke('restart-backend') + .then((res) => { + console.log('restart-backend', res) + }) + .catch((error) => { + console.error('Error in clearTasks cleanup:', error) + }) + + + // Immediately create new task to maintain UI responsiveness const newTaskId = create() set((state) => ({ ...state,