diff options
| author | Shreya Keshive <[email protected]> | 2025-08-05 18:52:58 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-08-05 22:52:58 +0000 |
| commit | 268627469b384ba3fa8dfe2e05b5186248013070 (patch) | |
| tree | 27d6421c6d7cc7986d284fa8f7bf0fece9c607e3 /packages/core/src/config | |
| parent | 6a72cd064bccb5fda4618671c2da63c4e22c1ef9 (diff) | |
Refactor IDE client state management, improve user-facing error messages, and add logging of connection events (#5591)
Co-authored-by: matt korwel <[email protected]>
Diffstat (limited to 'packages/core/src/config')
| -rw-r--r-- | packages/core/src/config/config.test.ts | 2 | ||||
| -rw-r--r-- | packages/core/src/config/config.ts | 27 | ||||
| -rw-r--r-- | packages/core/src/config/flashFallback.test.ts | 5 |
3 files changed, 18 insertions, 16 deletions
diff --git a/packages/core/src/config/config.test.ts b/packages/core/src/config/config.test.ts index dd50fd41..64692139 100644 --- a/packages/core/src/config/config.test.ts +++ b/packages/core/src/config/config.test.ts @@ -18,7 +18,6 @@ import { } from '../core/contentGenerator.js'; import { GeminiClient } from '../core/client.js'; import { GitService } from '../services/gitService.js'; -import { IdeClient } from '../ide/ide-client.js'; vi.mock('fs', async (importOriginal) => { const actual = await importOriginal<typeof import('fs')>(); @@ -120,7 +119,6 @@ describe('Server Config (config.ts)', () => { telemetry: TELEMETRY_SETTINGS, sessionId: SESSION_ID, model: MODEL, - ideClient: IdeClient.getInstance(false), }; beforeEach(() => { diff --git a/packages/core/src/config/config.ts b/packages/core/src/config/config.ts index 22996f3e..fa51a6af 100644 --- a/packages/core/src/config/config.ts +++ b/packages/core/src/config/config.ts @@ -48,6 +48,8 @@ import { shouldAttemptBrowserLaunch } from '../utils/browser.js'; import { MCPOAuthConfig } from '../mcp/oauth-provider.js'; import { IdeClient } from '../ide/ide-client.js'; import type { Content } from '@google/genai'; +import { logIdeConnection } from '../telemetry/loggers.js'; +import { IdeConnectionEvent, IdeConnectionType } from '../telemetry/types.js'; // Re-export OAuth config type export type { MCPOAuthConfig }; @@ -187,7 +189,6 @@ export interface ConfigParameters { summarizeToolOutput?: Record<string, SummarizeToolOutputSettings>; ideModeFeature?: boolean; ideMode?: boolean; - ideClient: IdeClient; loadMemoryFromIncludeDirectories?: boolean; } @@ -305,7 +306,11 @@ export class Config { this.summarizeToolOutput = params.summarizeToolOutput; this.ideModeFeature = params.ideModeFeature ?? false; this.ideMode = params.ideMode ?? false; - this.ideClient = params.ideClient; + this.ideClient = IdeClient.getInstance(); + if (this.ideMode && this.ideModeFeature) { + this.ideClient.connect(); + logIdeConnection(this, new IdeConnectionEvent(IdeConnectionType.START)); + } this.loadMemoryFromIncludeDirectories = params.loadMemoryFromIncludeDirectories ?? false; @@ -633,10 +638,6 @@ export class Config { return this.ideModeFeature; } - getIdeClient(): IdeClient { - return this.ideClient; - } - getIdeMode(): boolean { return this.ideMode; } @@ -645,12 +646,18 @@ export class Config { this.ideMode = value; } - setIdeClientDisconnected(): void { - this.ideClient.setDisconnected(); + async setIdeModeAndSyncConnection(value: boolean): Promise<void> { + this.ideMode = value; + if (value) { + await this.ideClient.connect(); + logIdeConnection(this, new IdeConnectionEvent(IdeConnectionType.SESSION)); + } else { + this.ideClient.disconnect(); + } } - setIdeClientConnected(): void { - this.ideClient.reconnect(this.ideMode && this.ideModeFeature); + getIdeClient(): IdeClient { + return this.ideClient; } async getGitService(): Promise<GitService> { diff --git a/packages/core/src/config/flashFallback.test.ts b/packages/core/src/config/flashFallback.test.ts index 0b68f993..5665a7e0 100644 --- a/packages/core/src/config/flashFallback.test.ts +++ b/packages/core/src/config/flashFallback.test.ts @@ -7,7 +7,7 @@ import { describe, it, expect, beforeEach, vi } from 'vitest'; import { Config } from './config.js'; import { DEFAULT_GEMINI_MODEL, DEFAULT_GEMINI_FLASH_MODEL } from './models.js'; -import { IdeClient } from '../ide/ide-client.js'; + import fs from 'node:fs'; vi.mock('node:fs'); @@ -26,7 +26,6 @@ describe('Flash Model Fallback Configuration', () => { debugMode: false, cwd: '/test', model: DEFAULT_GEMINI_MODEL, - ideClient: IdeClient.getInstance(false), }); // Initialize contentGeneratorConfig for testing @@ -51,7 +50,6 @@ describe('Flash Model Fallback Configuration', () => { debugMode: false, cwd: '/test', model: DEFAULT_GEMINI_MODEL, - ideClient: IdeClient.getInstance(false), }); // Should not crash when contentGeneratorConfig is undefined @@ -75,7 +73,6 @@ describe('Flash Model Fallback Configuration', () => { debugMode: false, cwd: '/test', model: 'custom-model', - ideClient: IdeClient.getInstance(false), }); expect(newConfig.getModel()).toBe('custom-model'); |
