From 0a3301912bebf13e5b09aea3f11c75088ab7b506 Mon Sep 17 00:00:00 2001 From: Roo Code Date: Fri, 29 Aug 2025 06:59:46 +0000 Subject: [PATCH] docs: add JSDoc comments and fix minor issues - Add comprehensive JSDoc comments for public methods - Remove unused maxTokens variable - Improve code documentation for better maintainability --- src/api/providers/gemini-cli.ts | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/api/providers/gemini-cli.ts b/src/api/providers/gemini-cli.ts index 0df6afc46a..19ead8b4e5 100644 --- a/src/api/providers/gemini-cli.ts +++ b/src/api/providers/gemini-cli.ts @@ -65,6 +65,13 @@ export class GeminiCliHandler extends BaseProvider implements SingleCompletionHa } } + /** + * Creates a streaming message response using the Gemini CLI client. + * @param systemInstruction - System prompt to guide the model's behavior + * @param messages - Array of conversation messages + * @param metadata - Optional metadata for the API call + * @yields Stream of response chunks including text, reasoning, and usage data + */ async *createMessage( systemInstruction: string, messages: Anthropic.Messages.MessageParam[], @@ -76,7 +83,7 @@ export class GeminiCliHandler extends BaseProvider implements SingleCompletionHa throw new Error("Gemini CLI client not initialized") } - const { id: model, info, maxTokens } = this.getModel() + const { id: model, info } = this.getModel() const contents = messages.map(convertAnthropicMessageToGemini) try { @@ -114,7 +121,7 @@ export class GeminiCliHandler extends BaseProvider implements SingleCompletionHa for await (const event of stream) { // The stream returns Turn objects at the end - turnResult = event + turnResult = event as any // Handle content events if (event.type === "content" && event.value) { @@ -170,6 +177,10 @@ export class GeminiCliHandler extends BaseProvider implements SingleCompletionHa } } + /** + * Gets the model configuration for the current provider settings. + * @returns Model ID and information including pricing and capabilities + */ override getModel() { const modelId = this.options.apiModelId let id = modelId && modelId in geminiCliModels ? (modelId as GeminiCliModelId) : geminiCliDefaultModelId @@ -179,6 +190,11 @@ export class GeminiCliHandler extends BaseProvider implements SingleCompletionHa return { id, info, ...params } } + /** + * Completes a single prompt without streaming. + * @param prompt - The prompt text to complete + * @returns The completed text response + */ async completePrompt(prompt: string): Promise { await this.ensureInitialized() @@ -232,6 +248,13 @@ export class GeminiCliHandler extends BaseProvider implements SingleCompletionHa } } + /** + * Counts tokens for the given content blocks. + * Note: The Gemini CLI library doesn't expose a direct token counting method, + * so this falls back to the base implementation using tiktoken. + * @param content - Array of content blocks to count tokens for + * @returns The estimated token count + */ override async countTokens(content: Array): Promise { // The Gemini CLI library doesn't expose a direct token counting method // Fall back to the base implementation