summaryrefslogtreecommitdiff
path: root/packages/core/src
diff options
context:
space:
mode:
Diffstat (limited to 'packages/core/src')
-rw-r--r--packages/core/src/core/client.test.ts28
-rw-r--r--packages/core/src/core/client.ts5
2 files changed, 33 insertions, 0 deletions
diff --git a/packages/core/src/core/client.test.ts b/packages/core/src/core/client.test.ts
index 032c9efc..675d1c26 100644
--- a/packages/core/src/core/client.test.ts
+++ b/packages/core/src/core/client.test.ts
@@ -331,6 +331,34 @@ describe('Gemini Client (client.ts)', () => {
});
});
+ describe('resetChat', () => {
+ it('should create a new chat session, clearing the old history', async () => {
+ // 1. Get the initial chat instance and add some history.
+ const initialChat = await client.getChat();
+ const initialHistory = await client.getHistory();
+ await client.addHistory({
+ role: 'user',
+ parts: [{ text: 'some old message' }],
+ });
+ const historyWithOldMessage = await client.getHistory();
+ expect(historyWithOldMessage.length).toBeGreaterThan(
+ initialHistory.length,
+ );
+
+ // 2. Call resetChat.
+ await client.resetChat();
+
+ // 3. Get the new chat instance and its history.
+ const newChat = await client.getChat();
+ const newHistory = await client.getHistory();
+
+ // 4. Assert that the chat instance is new and the history is reset.
+ expect(newChat).not.toBe(initialChat);
+ expect(newHistory.length).toBe(initialHistory.length);
+ expect(JSON.stringify(newHistory)).not.toContain('some old message');
+ });
+ });
+
describe('sendMessageStream', () => {
it('should return the turn instance after the stream is complete', async () => {
// Arrange
diff --git a/packages/core/src/core/client.ts b/packages/core/src/core/client.ts
index 7cfb6b53..94c598bf 100644
--- a/packages/core/src/core/client.ts
+++ b/packages/core/src/core/client.ts
@@ -86,6 +86,11 @@ export class GeminiClient {
chat.setHistory(history);
}
+ async resetChat(): Promise<void> {
+ this.chat = this.startChat();
+ await this.chat;
+ }
+
private async getEnvironment(): Promise<Part[]> {
const cwd = this.config.getWorkingDir();
const today = new Date().toLocaleDateString(undefined, {