mirror of
https://github.com/CopilotKit/CopilotKit.git
synced 2026-09-14 16:26:20 +08:00
7633e333c5
Split RunHandler.runAgent into a synchronous public wrapper plus a private _runAgentInner so the inner run promise can be captured BEFORE any await. For top-level runs (not recursive tool follow-ups), register a normalized completion promise in a per-agent WeakMap, exposed via runCompletion(agent) and surfaced on CopilotKitCore as runAgentCompletion(agent). The promise resolves (never rejects) once the run settles either way, including a pre-RUN_STARTED rejection. This closes the structural seam in intelligence-agent.ts, where activeRunCompletionPromise is only assigned AFTER await onInitialize — too late for a caller to gate on. A synchronous handle lets the CopilotChat send queue hold a slot until the prior run genuinely finishes.