diff options
Diffstat (limited to 'packages/cli/src')
| -rw-r--r-- | packages/cli/src/ui/hooks/useGeminiStream.ts | 10 | ||||
| -rw-r--r-- | packages/cli/src/ui/hooks/useToolScheduler.ts | 70 |
2 files changed, 36 insertions, 44 deletions
diff --git a/packages/cli/src/ui/hooks/useGeminiStream.ts b/packages/cli/src/ui/hooks/useGeminiStream.ts index 324a4ffa..d3ecad95 100644 --- a/packages/cli/src/ui/hooks/useGeminiStream.ts +++ b/packages/cli/src/ui/hooks/useGeminiStream.ts @@ -383,6 +383,7 @@ export const useGeminiStream = ( toolCallRequests.push(event.value); } else if (event.type === ServerGeminiEventType.UserCancelled) { handleUserCancelledEvent(userMessageTimestamp); + cancel(); return StreamProcessingStatus.UserCancelled; } else if (event.type === ServerGeminiEventType.Error) { handleErrorEvent(event.value, userMessageTimestamp); @@ -393,12 +394,9 @@ export const useGeminiStream = ( return StreamProcessingStatus.Completed; }; - const streamingState: StreamingState = isResponding - ? StreamingState.Responding - : pendingToolCalls?.tools.some( - (t) => t.status === ToolCallStatus.Confirming, - ) - ? StreamingState.WaitingForConfirmation + const streamingState: StreamingState = + isResponding || toolCalls.some((t) => t.status === 'awaiting_approval') + ? StreamingState.Responding : StreamingState.Idle; const submitQuery = useCallback( diff --git a/packages/cli/src/ui/hooks/useToolScheduler.ts b/packages/cli/src/ui/hooks/useToolScheduler.ts index fde632df..e14241b6 100644 --- a/packages/cli/src/ui/hooks/useToolScheduler.ts +++ b/packages/cli/src/ui/hooks/useToolScheduler.ts @@ -184,61 +184,55 @@ export function useToolScheduler( useEffect(() => { // effect for executing scheduled tool calls - const scheduledCalls = toolCalls.filter((t) => t.status === 'scheduled'); - const awaitingConfirmation = toolCalls.some( - (t) => t.status === 'awaiting_approval', - ); - if (!awaitingConfirmation && scheduledCalls.length) { - scheduledCalls.forEach(async (c) => { + if (toolCalls.every((t) => t.status === 'scheduled')) { + toolCalls.forEach((c) => { const callId = c.request.callId; - try { - setToolCalls(setStatus(c.request.callId, 'executing')); - const result = await c.tool.execute( - c.request.args, - abortController.signal, - ); - const functionResponse: Part = { - functionResponse: { - name: c.request.name, - id: callId, - response: { output: result.llmContent }, - }, - }; - const response: ToolCallResponseInfo = { - callId, - responsePart: functionResponse, - resultDisplay: result.returnDisplay, - error: undefined, - }; - setToolCalls(setStatus(callId, 'success', response)); - } catch (e: unknown) { - setToolCalls( - setStatus( + setToolCalls(setStatus(c.request.callId, 'executing')); + c.tool + .execute(c.request.args, abortController.signal) + .then((result) => { + const functionResponse: Part = { + functionResponse: { + name: c.request.name, + id: callId, + response: { output: result.llmContent }, + }, + }; + const response: ToolCallResponseInfo = { callId, - 'error', - toolErrorResponse( - c.request, - e instanceof Error ? e : new Error(String(e)), + responsePart: functionResponse, + resultDisplay: result.returnDisplay, + error: undefined, + }; + setToolCalls(setStatus(callId, 'success', response)); + }) + .catch((e) => + setToolCalls( + setStatus( + callId, + 'error', + toolErrorResponse( + c.request, + e instanceof Error ? e : new Error(String(e)), + ), ), ), ); - } }); } }, [toolCalls, toolRegistry, abortController.signal]); useEffect(() => { - const completedTools = toolCalls.filter( + const allDone = toolCalls.every( (t) => t.status === 'success' || t.status === 'error' || t.status === 'cancelled', ); - const allDone = completedTools.length === toolCalls.length; if (toolCalls.length && allDone) { - onComplete(completedTools); setToolCalls([]); - setAbortController(new AbortController()); + onComplete(toolCalls); + setAbortController(() => new AbortController()); } }, [toolCalls, onComplete]); |
