From 22c7c47dac5b54e2f87f40d594abf57cc1547240 Mon Sep 17 00:00:00 2001 From: xintaofei Date: Mon, 23 Mar 2026 19:05:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=96=B0=E4=BC=9A=E8=AF=9D?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E8=BF=9E=E6=8E=A5=E5=88=B0=E6=9C=AA=E5=AE=89?= =?UTF-8?q?=E8=A3=85=E7=9A=84agent=E6=97=B6=EF=BC=8C=E5=90=8E=E7=BB=AD?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E5=85=B6=E5=AE=83agent=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E5=8F=8D=E5=BA=94=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../conversation-detail-panel.tsx | 40 ++++++++++--------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/src/components/conversations/conversation-detail-panel.tsx b/src/components/conversations/conversation-detail-panel.tsx index c59cd01..c352500 100644 --- a/src/components/conversations/conversation-detail-panel.tsx +++ b/src/components/conversations/conversation-detail-panel.tsx @@ -717,30 +717,34 @@ const ConversationTabView = memo(function ConversationTabView({ setModeId(null) setAgentConnectError(null) - // If not yet connected, just update state — auto-connect will use the - // new agentType once canAutoConnect is satisfied. const s = connStatusRef.current - if (!s || s === "disconnected" || s === "error") return + const doConnect = () => { + if (!workingDirForConnection) return + connConnect(nextAgentType, workingDirForConnection, undefined, { + source: "auto_link", + }) + .then(() => { + setAgentConnectError(null) + }) + .catch((e) => { + setAgentConnectError(normalizeErrorMessage(e)) + if (!isExpectedAutoLinkError(e)) { + console.error("[ConversationTabView] switch agent:", e) + } + }) + } + + // If not yet connected, directly attempt to connect with the new agent. + if (!s || s === "disconnected" || s === "error") { + doConnect() + return + } connDisconnect() .catch((e) => console.error("[ConversationTabView] disconnect old agent:", e) ) - .finally(() => { - if (!workingDirForConnection) return - connConnect(nextAgentType, workingDirForConnection, undefined, { - source: "auto_link", - }) - .then(() => { - setAgentConnectError(null) - }) - .catch((e) => { - setAgentConnectError(normalizeErrorMessage(e)) - if (!isExpectedAutoLinkError(e)) { - console.error("[ConversationTabView] switch agent:", e) - } - }) - }) + .finally(doConnect) }, [connConnect, connDisconnect, workingDirForConnection] )