diff options
| author | Jaana Dogan <[email protected]> | 2025-04-17 12:03:02 -0700 |
|---|---|---|
| committer | N. Taylor Mullen <[email protected]> | 2025-04-17 14:15:20 -0700 |
| commit | 81ba61df7f967f141cd8abc57d58a3612dfd4c2b (patch) | |
| tree | e4cf1a244c0b79fb7167105672c037954144783c /packages/cli/src/core | |
| parent | 898a83031c695f6da8705848ebe9998a7b626019 (diff) | |
Improve readability issues
This is only the first change of many changes.
* Remove redundant autogenerated comments
* Use the recommended file name style
* Use camelCase for variable names
* Don't introduce submodules for relevant types
* Don't introduce constants like modules, these are implementation details
* Remove empty files
Diffstat (limited to 'packages/cli/src/core')
| -rw-r--r-- | packages/cli/src/core/GeminiStream.ts | 22 | ||||
| -rw-r--r-- | packages/cli/src/core/StreamingState.ts | 4 | ||||
| -rw-r--r-- | packages/cli/src/core/agent.ts | 0 | ||||
| -rw-r--r-- | packages/cli/src/core/constants.ts | 1 | ||||
| -rw-r--r-- | packages/cli/src/core/gemini-client.ts (renamed from packages/cli/src/core/GeminiClient.ts) | 6 | ||||
| -rw-r--r-- | packages/cli/src/core/gemini-stream.ts (renamed from packages/cli/src/core/geminiStreamProcessor.ts) | 31 | ||||
| -rw-r--r-- | packages/cli/src/core/history-updater.ts (renamed from packages/cli/src/core/historyUpdater.ts) | 7 | ||||
| -rw-r--r-- | packages/cli/src/core/prompts.ts | 3 |
8 files changed, 34 insertions, 40 deletions
diff --git a/packages/cli/src/core/GeminiStream.ts b/packages/cli/src/core/GeminiStream.ts deleted file mode 100644 index 28568306..00000000 --- a/packages/cli/src/core/GeminiStream.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { ToolCallEvent } from "../ui/types.js"; - -export enum GeminiEventType { - Content, - ToolCallInfo, -} - -export interface GeminiContentEvent { - type: GeminiEventType.Content; - value: string; -} - -export interface GeminiToolCallInfoEvent { - type: GeminiEventType.ToolCallInfo; - value: ToolCallEvent; -} - -export type GeminiEvent = - | GeminiContentEvent - | GeminiToolCallInfoEvent; - -export type GeminiStream = AsyncIterable<GeminiEvent>; diff --git a/packages/cli/src/core/StreamingState.ts b/packages/cli/src/core/StreamingState.ts deleted file mode 100644 index 5aed1ff0..00000000 --- a/packages/cli/src/core/StreamingState.ts +++ /dev/null @@ -1,4 +0,0 @@ -export enum StreamingState { - Idle, - Responding, -}
\ No newline at end of file diff --git a/packages/cli/src/core/agent.ts b/packages/cli/src/core/agent.ts deleted file mode 100644 index e69de29b..00000000 --- a/packages/cli/src/core/agent.ts +++ /dev/null diff --git a/packages/cli/src/core/constants.ts b/packages/cli/src/core/constants.ts deleted file mode 100644 index 16ac74d1..00000000 --- a/packages/cli/src/core/constants.ts +++ /dev/null @@ -1 +0,0 @@ -export const MEMORY_FILE_NAME = 'GEMINI.md';
\ No newline at end of file diff --git a/packages/cli/src/core/GeminiClient.ts b/packages/cli/src/core/gemini-client.ts index 0cdeed86..e41fda6f 100644 --- a/packages/cli/src/core/GeminiClient.ts +++ b/packages/cli/src/core/gemini-client.ts @@ -10,9 +10,9 @@ import { CoreSystemPrompt } from './prompts.js'; import { type ToolCallEvent, type ToolCallConfirmationDetails, ToolCallStatus } from '../ui/types.js'; import process from 'node:process'; import { toolRegistry } from '../tools/tool-registry.js'; -import { ToolResult } from '../tools/ToolResult.js'; +import { ToolResult } from '../tools/tool.js'; import { getFolderStructure } from '../utils/getFolderStructure.js'; -import { GeminiEventType, GeminiStream } from './GeminiStream.js'; +import { GeminiEventType, GeminiStream } from './gemini-stream.js'; type ToolExecutionOutcome = { callId: string; @@ -62,7 +62,7 @@ ${folderStructure} try { const chat = this.ai.chats.create({ - model: 'gemini-2.5-pro-preview-03-25',//'gemini-2.0-flash', + model: 'gemini-2.0-flash',//'gemini-2.0-flash', config: { systemInstruction: CoreSystemPrompt, ...this.defaultHyperParameters, diff --git a/packages/cli/src/core/geminiStreamProcessor.ts b/packages/cli/src/core/gemini-stream.ts index 12de49cb..b47eb1c6 100644 --- a/packages/cli/src/core/geminiStreamProcessor.ts +++ b/packages/cli/src/core/gemini-stream.ts @@ -1,7 +1,33 @@ +import { ToolCallEvent } from "../ui/types.js"; import { Part } from '@google/genai'; import { HistoryItem } from '../ui/types.js'; -import { GeminiEventType, GeminiStream } from './GeminiStream.js'; -import { handleToolCallChunk, addErrorMessageToHistory } from './historyUpdater.js'; +import { handleToolCallChunk, addErrorMessageToHistory } from './history-updater.js'; + +export enum GeminiEventType { + Content, + ToolCallInfo, +} + +export interface GeminiContentEvent { + type: GeminiEventType.Content; + value: string; +} + +export interface GeminiToolCallInfoEvent { + type: GeminiEventType.ToolCallInfo; + value: ToolCallEvent; +} + +export type GeminiEvent = + | GeminiContentEvent + | GeminiToolCallInfoEvent; + +export type GeminiStream = AsyncIterable<GeminiEvent>; + +export enum StreamingState { + Idle, + Responding, +} interface StreamProcessorParams { stream: GeminiStream; @@ -104,7 +130,6 @@ export const processGeminiStream = async ({ // Renamed function for clarity clearTimeout(renderTimeoutId); renderTimeoutId = null; } - // Flush any text buffer content. render(textBuffer); currentGeminiMessageId = null; // End text message context diff --git a/packages/cli/src/core/historyUpdater.ts b/packages/cli/src/core/history-updater.ts index 39eaca6a..4013728f 100644 --- a/packages/cli/src/core/historyUpdater.ts +++ b/packages/cli/src/core/history-updater.ts @@ -1,7 +1,7 @@ import { Part } from "@google/genai"; import { toolRegistry } from "../tools/tool-registry.js"; import { HistoryItem, IndividualToolCallDisplay, ToolCallEvent, ToolCallStatus, ToolConfirmationOutcome, ToolEditConfirmationDetails, ToolExecuteConfirmationDetails } from "../ui/types.js"; -import { ToolResultDisplay } from "../tools/ToolResult.js"; +import { ToolResultDisplay } from "../tools/tool.js"; /** * Processes a tool call chunk and updates the history state accordingly. @@ -46,13 +46,9 @@ export const handleToolCallChunk = ( if (!tool) { throw new Error(`Tool "${chunk.name}" not found or is not registered.`); } - handleToolCallChunk({ ...chunk, status: ToolCallStatus.Invoked, resultDisplay: "Executing...", confirmationDetails: undefined }, setHistory, submitQuery, getNextMessageId, currentToolGroupIdRef); - const result = await tool.execute(chunk.args); - handleToolCallChunk({ ...chunk, status: ToolCallStatus.Invoked, resultDisplay: result.returnDisplay, confirmationDetails: undefined }, setHistory, submitQuery, getNextMessageId, currentToolGroupIdRef); - const functionResponse: Part = { functionResponse: { name: chunk.name, @@ -60,7 +56,6 @@ export const handleToolCallChunk = ( response: { "output": result.llmContent }, }, } - await submitQuery(functionResponse); } } diff --git a/packages/cli/src/core/prompts.ts b/packages/cli/src/core/prompts.ts index 9e1f994f..92a6708d 100644 --- a/packages/cli/src/core/prompts.ts +++ b/packages/cli/src/core/prompts.ts @@ -1,6 +1,7 @@ import { ReadFileTool } from "../tools/read-file.tool.js"; import { TerminalTool } from "../tools/terminal.tool.js"; -import { MEMORY_FILE_NAME } from "./constants.js"; + +const MEMORY_FILE_NAME = 'GEMINI.md'; const contactEmail = '[email protected]'; export const CoreSystemPrompt = ` |
