diff options
| author | Jaana Dogan <[email protected]> | 2025-04-22 11:01:09 -0700 |
|---|---|---|
| committer | Jaana Dogan <[email protected]> | 2025-04-22 11:20:19 -0700 |
| commit | 8e0fb9ee2f9fa1a6c97fc2e8cebd67da0386c5e9 (patch) | |
| tree | 904f95ac59f3c715f2179272fab863f811a87b5e /packages/cli/src/gemini.ts | |
| parent | 3db2a796ec7c3aeba731da7b0f99e41c5c103d2b (diff) | |
Initiate the GeminiClient with a config
Also address the open readability improvement comments from #104.
Diffstat (limited to 'packages/cli/src/gemini.ts')
| -rw-r--r-- | packages/cli/src/gemini.ts | 68 |
1 files changed, 22 insertions, 46 deletions
diff --git a/packages/cli/src/gemini.ts b/packages/cli/src/gemini.ts index 0d8b1ac7..56a44e30 100644 --- a/packages/cli/src/gemini.ts +++ b/packages/cli/src/gemini.ts @@ -9,24 +9,9 @@ import { render } from 'ink'; import { App } from './ui/App.js'; import { loadCliConfig } from './config/config.js'; import { readStdin } from './utils/readStdin.js'; -import { GeminiClient, ServerTool } from '@gemini-code/server'; - -import { PartListUnion } from '@google/genai'; +import { GeminiClient } from '@gemini-code/server'; async function main() { - let initialInput: string | undefined = undefined; - - // Check if input is being piped - if (!process.stdin.isTTY) { - try { - initialInput = await readStdin(); - } catch (error) { - console.error('Error reading from stdin:', error); - process.exit(1); - } - } - - // Load configuration const config = loadCliConfig(); // Render UI, passing necessary config values and initial input @@ -34,42 +19,33 @@ async function main() { render( React.createElement(App, { config, - initialInput, }), ); - } else if (initialInput) { - // If not a TTY and we have initial input, process it directly - const geminiClient = new GeminiClient( - config.getApiKey(), - config.getModel(), - ); - const toolRegistry = config.getToolRegistry(); - const availableTools: ServerTool[] = toolRegistry.getAllTools(); - const toolDeclarations = toolRegistry.getFunctionDeclarations(); - const chat = await geminiClient.startChat(toolDeclarations); + return; + } - const request: PartListUnion = [{ text: initialInput }]; + const input = await readStdin(); + if (!input) { + console.error('No input provided via stdin.'); + process.exit(1); + } - try { - for await (const event of geminiClient.sendMessageStream( - chat, - request, - availableTools, - )) { - if (event.type === 'content') { - process.stdout.write(event.value); - } - // We might need to handle other event types later, but for now, just content. + // If not a TTY and we have initial input, process it directly + const geminiClient = new GeminiClient(config); + const chat = await geminiClient.startChat(); + try { + for await (const event of geminiClient.sendMessageStream(chat, [ + { text: input }, + ])) { + if (event.type === 'content') { + process.stdout.write(event.value); } - process.stdout.write('\n'); // Add a newline at the end - process.exit(0); - } catch (error) { - console.error('Error processing piped input:', error); - process.exit(1); + // We might need to handle other event types later, but for now, just content. } - } else { - // If not a TTY and no initial input, exit with an error - console.error('No input provided via stdin.'); + process.stdout.write('\n'); // Add a newline at the end + process.exit(0); + } catch (error) { + console.error('Error processing piped input:', error); process.exit(1); } } |
