Pulled manual commands to seperate function

This commit is contained in:
Seth Troisi
2025-04-25 00:12:20 +00:00
parent 4ce897d19d
commit ed12a2e133

View File

@@ -98,22 +98,22 @@ export const useGeminiStream = (
[setHistory], [setHistory],
); );
// Improved submit query function // Possibly handle a query manually, return true if handled.
const submitQuery = useCallback( const handleQueryManually = (rawQuery: PartListUnion): boolean => {
async (query: PartListUnion) => { if (typeof rawQuery !== 'string') {
if (streamingState === StreamingState.Responding) return; return false;
if (typeof query === 'string' && query.trim().length === 0) return; }
if (typeof query === 'string') { const query = rawQuery.trim();
setDebugMessage(`User query: ${query}`);
const maybeCommand = query.split(/\s+/)[0]; const maybeCommand = query.split(/\s+/)[0];
if (query.trim() === 'clear') { if (query === 'clear') {
// This just clears the *UI* history, not the model history. // This just clears the *UI* history, not the model history.
// TODO: add a slash command for that. // TODO: add a slash command for that.
setDebugMessage('Clearing terminal.'); setDebugMessage('Clearing terminal.');
setHistory((_) => []); setHistory((_) => []);
return; return true;
} else if (config.getPassthroughCommands().includes(maybeCommand)) { }
if (config.getPassthroughCommands().includes(maybeCommand)) {
// Execute and capture output // Execute and capture output
const targetDir = config.getTargetDir(); const targetDir = config.getTargetDir();
setDebugMessage(`Executing shell command in ${targetDir}: ${query}`); setDebugMessage(`Executing shell command in ${targetDir}: ${query}`);
@@ -147,8 +147,24 @@ export const useGeminiStream = (
}); });
// Set state to Responding while the command runs // Set state to Responding while the command runs
setStreamingState(StreamingState.Responding); setStreamingState(StreamingState.Responding);
return; // Prevent Gemini call return true; // Prevent Gemini call
} }
return true;
}
// Improved submit query function
const submitQuery = useCallback(
async (query: PartListUnion) => {
if (streamingState === StreamingState.Responding) return;
if (typeof query === 'string' && query.trim().length === 0) return;
if (typeof query === 'string') {
setDebugMessage(`User query: '${query}'`);
}
if (handleQueryManually(query)) {
return;
} }
const userMessageTimestamp = Date.now(); const userMessageTimestamp = Date.now();