Files
Netcatty/components/ai/draftSendGate.ts
T
Cursor Agentand陈大猫 4b79eb1332 fix: remount-safe AI send latch and skip stale MCP approval IPC
Replace the component sendInFlightRef with a module key latch so StrictMode
panel remount cannot reopen a mid-flight send, and no-op resolveApproval when
the pending entry is already drained.

Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com>
2026-08-07 14:38:00 +00:00

35 lines
914 B
TypeScript

export function tryBeginDraftSend(gate: { current: boolean }): boolean {
if (gate.current) {
return false;
}
gate.current = true;
return true;
}
export function endDraftSend(gate: { current: boolean }): void {
gate.current = false;
}
/** Alias kept for call sites that gate every send (draft + session), not just draft. */
export const tryBeginSend = tryBeginDraftSend;
export const endSend = endDraftSend;
/**
* Remount-safe send latch. Component refs reset when StrictMode remounts
* AIChatSidePanelActive mid-flight; a module Set keyed by session/draft scope
* does not.
*/
const sendInFlightByKey = new Set<string>();
export function tryBeginSendForKey(key: string): boolean {
if (!key || sendInFlightByKey.has(key)) return false;
sendInFlightByKey.add(key);
return true;
}
export function endSendForKey(key: string): void {
if (!key) return;
sendInFlightByKey.delete(key);
}