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