修复新会话页面连接到未安装的agent时,后续连接其它agent没有反应了

This commit is contained in:
xintaofei
2026-03-23 19:05:34 +08:00
parent ccff5ac7d9
commit 22c7c47dac

View File

@@ -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]
)