diff options
| author | Brandon Keiji <[email protected]> | 2025-05-16 16:45:58 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-05-16 09:45:58 -0700 |
| commit | 458fd8642909ca71bcf00b90f5f00adc00cad006 (patch) | |
| tree | 9b956afc1b1e8fb15f65a6a7d7a2d266c8e83d43 /packages/cli/src/ui/hooks/shellCommandProcessor.ts | |
| parent | 609757f911949b2c24241ab0e6b6f20a78a9e40a (diff) | |
refactor: derive streaming state from tool calls and isresponding state (#376)
Diffstat (limited to 'packages/cli/src/ui/hooks/shellCommandProcessor.ts')
| -rw-r--r-- | packages/cli/src/ui/hooks/shellCommandProcessor.ts | 47 |
1 files changed, 26 insertions, 21 deletions
diff --git a/packages/cli/src/ui/hooks/shellCommandProcessor.ts b/packages/cli/src/ui/hooks/shellCommandProcessor.ts index d0615ce5..980a6572 100644 --- a/packages/cli/src/ui/hooks/shellCommandProcessor.ts +++ b/packages/cli/src/ui/hooks/shellCommandProcessor.ts @@ -8,7 +8,6 @@ import { exec as _exec } from 'child_process'; import { useCallback } from 'react'; import { Config } from '@gemini-code/server'; import { type PartListUnion } from '@google/genai'; -import { StreamingState } from '../types.js'; import { getCommandFromQuery } from '../utils/commandUtils.js'; import { UseHistoryManagerReturn } from './useHistoryManager.js'; @@ -18,7 +17,7 @@ import { UseHistoryManagerReturn } from './useHistoryManager.js'; */ export const useShellCommandProcessor = ( addItemToHistory: UseHistoryManagerReturn['addItem'], - setStreamingState: React.Dispatch<React.SetStateAction<StreamingState>>, + onExec: (command: Promise<void>) => void, onDebugMessage: (message: string) => void, config: Config, ) => { @@ -57,30 +56,36 @@ export const useShellCommandProcessor = ( cwd: targetDir, }; - setStreamingState(StreamingState.Responding); + const execPromise = new Promise<void>((resolve) => { + _exec(commandToExecute, execOptions, (error, stdout, stderr) => { + if (error) { + addItemToHistory( + { type: 'error', text: error.message }, + userMessageTimestamp, + ); + } else { + let output = ''; + if (stdout) output += stdout; + if (stderr) output += (output ? '\n' : '') + stderr; // Include stderr as info - _exec(commandToExecute, execOptions, (error, stdout, stderr) => { - if (error) { - addItemToHistory( - { type: 'error', text: error.message }, - userMessageTimestamp, - ); - } else { - let output = ''; - if (stdout) output += stdout; - if (stderr) output += (output ? '\n' : '') + stderr; // Include stderr as info - - addItemToHistory( - { type: 'info', text: output || '(Command produced no output)' }, - userMessageTimestamp, - ); - } - setStreamingState(StreamingState.Idle); + addItemToHistory( + { type: 'info', text: output || '(Command produced no output)' }, + userMessageTimestamp, + ); + } + resolve(); + }); }); + try { + onExec(execPromise); + } catch (_e) { + // silently ignore errors from this since it's from the caller + } + return true; // Command was initiated }, - [config, onDebugMessage, addItemToHistory, setStreamingState], + [config, onDebugMessage, addItemToHistory, onExec], ); return { handleShellCommand }; |
