diff --git a/src/components/image-editor/EditorAgentConversation/ToolCallView.tsx b/src/components/image-editor/EditorAgentConversation/ToolCallView.tsx index fa45f5cb9..dd58bf376 100644 --- a/src/components/image-editor/EditorAgentConversation/ToolCallView.tsx +++ b/src/components/image-editor/EditorAgentConversation/ToolCallView.tsx @@ -31,20 +31,20 @@ function ToolCallView({ const [displayError, setDisplayError] = useState( toolCall.error ?? null, ); - const completionNotifiedRef = useRef(false); + const terminalNotifiedRef = useRef(false); const onJobCompletedRef = useRef(onJobCompleted); useEffect(() => { onJobCompletedRef.current = onJobCompleted; }, [onJobCompleted]); useEffect(() => { if (toolCall.status !== 'not_completed' || !jobId) { - completionNotifiedRef.current = false; + terminalNotifiedRef.current = false; return; } // Only a different job may reinitialize the local display state. setDisplayStatus(initialDisplayStatus); setDisplayError(toolCall.error ?? null); - completionNotifiedRef.current = false; + terminalNotifiedRef.current = false; let disposed = false; let timeoutId: ReturnType | undefined; const poll = async () => { @@ -57,11 +57,8 @@ function ToolCallView({ ) { setDisplayStatus(response.job.status); setDisplayError(response.job.error ?? null); - if ( - response.job.status === 'completed' && - !completionNotifiedRef.current - ) { - completionNotifiedRef.current = true; + if (!terminalNotifiedRef.current) { + terminalNotifiedRef.current = true; onJobCompletedRef.current?.(); } return; diff --git a/src/components/image-editor/EditorAgentConversation/useEditorAgentConversation.test.tsx b/src/components/image-editor/EditorAgentConversation/useEditorAgentConversation.test.tsx index 2968531c4..feef7df8f 100644 --- a/src/components/image-editor/EditorAgentConversation/useEditorAgentConversation.test.tsx +++ b/src/components/image-editor/EditorAgentConversation/useEditorAgentConversation.test.tsx @@ -492,7 +492,7 @@ describe('useEditorAgentConversation', () => { const getConversationCallsBeforeConfirm = vi.mocked(client.getConversation) .mock.calls.length; - let confirmationPromise: Promise | undefined; + let confirmationPromise: Promise | undefined; act(() => { confirmationPromise = result.current.confirmToolCall(7); }); diff --git a/src/components/image-editor/EditorAgentConversation/useEditorAgentConversation.ts b/src/components/image-editor/EditorAgentConversation/useEditorAgentConversation.ts index a08a0f5f8..131c959aa 100644 --- a/src/components/image-editor/EditorAgentConversation/useEditorAgentConversation.ts +++ b/src/components/image-editor/EditorAgentConversation/useEditorAgentConversation.ts @@ -426,7 +426,7 @@ export function useEditorAgentConversation({ async (messageId: number, action: EditorAgentToolCallAction) => { const conversationId = activeConversationIdRef.current; if (!conversationId || activeToolCallActionRef.current) { - return null; + return; } const nextAction = { messageId, action } as const; @@ -440,7 +440,7 @@ export function useEditorAgentConversation({ : client.cancelToolCall(conversationId, messageId)); if (activeConversationIdRef.current !== conversationId) { - return null; + return; } const detail = await loadConversation(conversationId); @@ -450,7 +450,6 @@ export function useEditorAgentConversation({ if (action === 'confirm' && updatedMessage?.toolCall?.externalJobId) { onConfirmSent?.(); } - return null; } catch (error) { if (activeConversationIdRef.current === conversationId) { setErrorMessage(