修复会话有时无法关闭

This commit is contained in:
xintaofei
2026-03-22 23:00:34 +08:00
parent ba6e55ff74
commit 58ddcb818b

View File

@@ -1893,11 +1893,22 @@ export function AcpConnectionsProvider({ children }: { children: ReactNode }) {
[] []
) )
const cancel = useCallback(async (contextKey: string) => { const cancel = useCallback(
const conn = storeRef.current.connections.get(contextKey) async (contextKey: string) => {
if (!conn) return const conn = storeRef.current.connections.get(contextKey)
await acpCancel(conn.connectionId) 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 respondPermission = useCallback( const respondPermission = useCallback(
async (contextKey: string, requestId: string, optionId: string) => { async (contextKey: string, requestId: string, optionId: string) => {