修复进行中会话有时无法被取消

This commit is contained in:
xintaofei
2026-03-22 23:20:01 +08:00
parent 58ddcb818b
commit ad49d9e9ec
3 changed files with 57 additions and 25 deletions

View File

@@ -1893,22 +1893,11 @@ export function AcpConnectionsProvider({ children }: { children: ReactNode }) {
[]
)
const cancel = useCallback(
async (contextKey: string) => {
const conn = storeRef.current.connections.get(contextKey)
if (!conn) return
await acpCancel(conn.connectionId)
// Optimistically transition status so the UI stops showing
// "responding" immediately. If the agent was slow to respond to
// the CancelNotification the frontend would otherwise stay stuck
// in the "prompting" state indefinitely.
const current = storeRef.current.connections.get(contextKey)
if (current?.status === "prompting") {
dispatch({ type: "STATUS_CHANGED", contextKey, status: "connected" })
}
},
[dispatch]
)
const cancel = useCallback(async (contextKey: string) => {
const conn = storeRef.current.connections.get(contextKey)
if (!conn) return
await acpCancel(conn.connectionId)
}, [])
const respondPermission = useCallback(
async (contextKey: string, requestId: string, optionId: string) => {