summaryrefslogtreecommitdiff
path: root/packages/cli/src/ui/hooks/useToolScheduler.ts
diff options
context:
space:
mode:
authorBrandon Keiji <[email protected]>2025-05-23 05:28:31 +0000
committerGitHub <[email protected]>2025-05-23 05:28:31 +0000
commit01971741e05a22e0402ac6c755ce0eced8f2930b (patch)
treed7dfc19b41e325b19d9fe1301a83fabd311440c8 /packages/cli/src/ui/hooks/useToolScheduler.ts
parent1d0856dcc8c1bb4cf32fbdeb5135a4df67e71ad1 (diff)
feat: add emphasis to tool confirmations (#502)
Diffstat (limited to 'packages/cli/src/ui/hooks/useToolScheduler.ts')
-rw-r--r--packages/cli/src/ui/hooks/useToolScheduler.ts81
1 files changed, 43 insertions, 38 deletions
diff --git a/packages/cli/src/ui/hooks/useToolScheduler.ts b/packages/cli/src/ui/hooks/useToolScheduler.ts
index 8bcc0ae9..a5770d36 100644
--- a/packages/cli/src/ui/hooks/useToolScheduler.ts
+++ b/packages/cli/src/ui/hooks/useToolScheduler.ts
@@ -184,48 +184,53 @@ export function useToolScheduler(
useEffect(() => {
// effect for executing scheduled tool calls
- if (toolCalls.every((t) => t.status === 'scheduled')) {
+ const allToolsConfirmed = toolCalls.every(
+ (t) => t.status === 'scheduled' || t.status === 'cancelled',
+ );
+ if (allToolsConfirmed) {
const signal = abortController.signal;
- toolCalls.forEach((c) => {
- const callId = c.request.callId;
- setToolCalls(setStatus(c.request.callId, 'executing'));
- c.tool
- .execute(c.request.args, signal)
- .then((result) => {
- if (signal.aborted) {
- setToolCalls(
- setStatus(callId, 'cancelled', 'Cancelled during execution'),
- );
- return;
- }
- 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) =>
- setToolCalls(
- setStatus(
+ toolCalls
+ .filter((t) => t.status === 'scheduled')
+ .forEach((t) => {
+ const callId = t.request.callId;
+ setToolCalls(setStatus(t.request.callId, 'executing'));
+ t.tool
+ .execute(t.request.args, signal)
+ .then((result) => {
+ if (signal.aborted) {
+ setToolCalls(
+ setStatus(callId, 'cancelled', 'Cancelled during execution'),
+ );
+ return;
+ }
+ const functionResponse: Part = {
+ functionResponse: {
+ name: t.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(
+ t.request,
+ e instanceof Error ? e : new Error(String(e)),
+ ),
),
),
- ),
- );
- });
+ );
+ });
}
}, [toolCalls, toolRegistry, abortController.signal]);