| 1012 | }; |
| 1013 | |
| 1014 | const handleCompletion = () => { |
| 1015 | if (isCompleted) return; |
| 1016 | isCompleted = true; |
| 1017 | setIsChatFormulating(false); |
| 1018 | agentAbortRef.current = null; |
| 1019 | clearTimeout(timeoutId); |
| 1020 | |
| 1021 | // Clean up any remaining draft (the last step created a new draft that was never filled) |
| 1022 | if (currentDraftId) { |
| 1023 | dispatch(dfActions.removeDraftNode(currentDraftId)); |
| 1024 | currentDraftId = null; |
| 1025 | } |
| 1026 | |
| 1027 | const completionResult = allResults.find((r: any) => r.type === "completion"); |
| 1028 | if (completionResult) { |
| 1029 | setChatPrompt(""); |
| 1030 | setAttachedImages([]); |
| 1031 | } |
| 1032 | }; |
| 1033 | |
| 1034 | (async () => { |
| 1035 | try { |