feat(sessions): add resuming to geminiChat and add CLI flags for session management (#10719)

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
This commit is contained in:
bl-ue
2025-11-10 18:31:00 -07:00
committed by GitHub
parent 51f952e700
commit 6893d27441
21 changed files with 2578 additions and 11 deletions
+19 -1
View File
@@ -255,6 +255,8 @@ export interface ConfigParameters {
model: string;
maxSessionTurns?: number;
experimentalZedIntegration?: boolean;
listSessions?: boolean;
deleteSession?: string;
listExtensions?: boolean;
extensionLoader?: ExtensionLoader;
enabledExtensions?: string[];
@@ -311,7 +313,7 @@ export class Config {
private blockedMcpServers: string[];
private promptRegistry!: PromptRegistry;
private agentRegistry!: AgentRegistry;
private readonly sessionId: string;
private sessionId: string;
private fileSystemService: FileSystemService;
private contentGeneratorConfig!: ContentGeneratorConfig;
private contentGenerator!: ContentGenerator;
@@ -360,6 +362,8 @@ export class Config {
private inFallbackMode = false;
private readonly maxSessionTurns: number;
private readonly listSessions: boolean;
private readonly deleteSession: string | undefined;
private readonly listExtensions: boolean;
private readonly _extensionLoader: ExtensionLoader;
private readonly _enabledExtensions: string[];
@@ -473,6 +477,8 @@ export class Config {
this.maxSessionTurns = params.maxSessionTurns ?? -1;
this.experimentalZedIntegration =
params.experimentalZedIntegration ?? false;
this.listSessions = params.listSessions ?? false;
this.deleteSession = params.deleteSession;
this.listExtensions = params.listExtensions ?? false;
this._extensionLoader =
params.extensionLoader ?? new SimpleExtensionLoader([]);
@@ -709,6 +715,10 @@ export class Config {
return this.sessionId;
}
setSessionId(sessionId: string): void {
this.sessionId = sessionId;
}
shouldLoadMemoryFromIncludeDirectories(): boolean {
return this.loadMemoryFromIncludeDirectories;
}
@@ -1033,6 +1043,14 @@ export class Config {
return this.listExtensions;
}
getListSessions(): boolean {
return this.listSessions;
}
getDeleteSession(): string | undefined {
return this.deleteSession;
}
getExtensionManagement(): boolean {
return this.extensionManagement;
}
+16 -2
View File
@@ -26,7 +26,10 @@ import { GeminiChat } from './geminiChat.js';
import { retryWithBackoff } from '../utils/retry.js';
import { getErrorMessage } from '../utils/errors.js';
import { tokenLimit } from './tokenLimits.js';
import type { ChatRecordingService } from '../services/chatRecordingService.js';
import type {
ChatRecordingService,
ResumedSessionData,
} from '../services/chatRecordingService.js';
import type { ContentGenerator } from './contentGenerator.js';
import {
DEFAULT_GEMINI_FLASH_MODEL,
@@ -152,6 +155,13 @@ export class GeminiClient {
this.updateTelemetryTokenCount();
}
async resumeChat(
history: Content[],
resumedSessionData?: ResumedSessionData,
): Promise<void> {
this.chat = await this.startChat(history, resumedSessionData);
}
getChatRecordingService(): ChatRecordingService | undefined {
return this.chat?.getChatRecordingService();
}
@@ -175,7 +185,10 @@ export class GeminiClient {
});
}
async startChat(extraHistory?: Content[]): Promise<GeminiChat> {
async startChat(
extraHistory?: Content[],
resumedSessionData?: ResumedSessionData,
): Promise<GeminiChat> {
this.forceFullIdeContext = true;
this.hasFailedCompressionAttempt = false;
@@ -207,6 +220,7 @@ export class GeminiClient {
tools,
},
history,
resumedSessionData,
);
} catch (error) {
await reportError(
+6 -2
View File
@@ -30,7 +30,10 @@ import {
logContentRetry,
logContentRetryFailure,
} from '../telemetry/loggers.js';
import { ChatRecordingService } from '../services/chatRecordingService.js';
import {
ChatRecordingService,
type ResumedSessionData,
} from '../services/chatRecordingService.js';
import {
ContentRetryEvent,
ContentRetryFailureEvent,
@@ -191,10 +194,11 @@ export class GeminiChat {
private readonly config: Config,
private readonly generationConfig: GenerateContentConfig = {},
private history: Content[] = [],
resumedSessionData?: ResumedSessionData,
) {
validateHistory(history);
this.chatRecordingService = new ChatRecordingService(config);
this.chatRecordingService.initialize();
this.chatRecordingService.initialize(resumedSessionData);
this.lastPromptTokenCount = Math.ceil(
JSON.stringify(this.history).length / 4,
);