Skip to content

Commit fdcc69a

Browse files
authored
feat(amazonq): clean up all sessions storage on profileChanged #2115
## Problem Profile(a.k.a Q region) change is supposed to clear ALL chat history (everything happening within mynah UI). Therefore, IDE backend should also clear session states otherwise wrong telemetry would be published. UI (mynahUI webview) will be re-initiate on profile changed https://github.com/aws/aws-toolkit-vscode-staging/blob/feature/q-region-expansion/packages/core/src/amazonq/webview/webView.ts#L40-L47 and plugins backend doesn't yet. This pr aims to cover all Q features to reset session states on profile changed. Q features covered in this PR to clean up session states 1. /doc 2. /dev 3. /transform 4. /review 5. /test 6. generic chat
1 parent 5f3d53b commit fdcc69a

File tree

9 files changed

+30
-6
lines changed

9 files changed

+30
-6
lines changed

packages/amazonq/src/app/amazonqScan/chat/controller/controller.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ export class ScanController {
108108
interactionType: data.vote,
109109
})
110110
})
111+
112+
AuthUtil.instance.regionProfileManager.onDidChangeRegionProfile(() => {
113+
this.sessionStorage.removeActiveTab()
114+
})
111115
}
112116

113117
private async tabOpened(message: any) {

packages/core/src/amazonq/commons/baseChatStorage.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,8 @@ export abstract class BaseChatSessionStorage<T extends { isAuthenticating: boole
3535
public deleteSession(tabID: string) {
3636
this.sessions.delete(tabID)
3737
}
38+
39+
public deleteAllSessions() {
40+
this.sessions.clear()
41+
}
3842
}

packages/core/src/amazonqDoc/controllers/chat/controller.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ export class DocController {
113113
this.chatControllerMessageListeners.openDiff.event(async (data) => {
114114
return await this.openDiff(data)
115115
})
116+
AuthUtil.instance.regionProfileManager.onDidChangeRegionProfile(() => {
117+
this.sessionStorage.deleteAllSessions()
118+
})
116119
}
117120

118121
/** Prompts user to choose a folder in current workspace for README creation/update.

packages/core/src/amazonqFeatureDev/controllers/chat/controller.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ export class FeatureDevController {
203203
this.chatControllerMessageListeners.storeCodeResultMessageId.event(async (data) => {
204204
return await this.storeCodeResultMessageId(data)
205205
})
206+
AuthUtil.instance.regionProfileManager.onDidChangeRegionProfile(() => {
207+
this.sessionStorage.deleteAllSessions()
208+
})
206209
}
207210

208211
private async processChatItemVotedMessage(tabId: string, vote: string) {

packages/core/src/amazonqGumby/chat/controller/controller.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ export class GumbyController {
147147
this.chatControllerMessageListeners.errorThrown.event((data) => {
148148
return this.handleError(data)
149149
})
150+
151+
AuthUtil.instance.regionProfileManager.onDidChangeRegionProfile(() => {
152+
this.sessionStorage.removeActiveTab()
153+
})
150154
}
151155

152156
private async tabOpened(message: any) {

packages/core/src/amazonqTest/chat/controller/controller.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,10 @@ export class TestController {
202202
return this.openDiff(data)
203203
}
204204
})
205+
206+
AuthUtil.instance.regionProfileManager.onDidChangeRegionProfile(() => {
207+
this.sessionStorage.removeActiveTab()
208+
})
205209
}
206210

207211
/**

packages/core/src/amazonqTest/chat/storages/chatSession.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import { Session } from '../session/session'
88
import { getLogger } from '../../../shared/logger/logger'
9-
import { AuthUtil } from '../../../codewhisperer/util/authUtil'
109

1110
export class SessionNotFoundError extends Error {}
1211

@@ -15,11 +14,7 @@ export class ChatSessionManager {
1514
private activeSession: Session | undefined
1615
private isInProgress: boolean = false
1716

18-
constructor() {
19-
AuthUtil.instance.regionProfileManager.onDidChangeRegionProfile(() => {
20-
this.removeActiveTab()
21-
})
22-
}
17+
constructor() {}
2318

2419
public static get Instance() {
2520
return this._instance || (this._instance = new this())

packages/core/src/codewhispererChat/controllers/chat/controller.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,9 @@ export class ChatController {
268268
this.chatControllerMessageListeners.processFileClick.onMessage((data) => {
269269
return this.processFileClickMessage(data)
270270
})
271+
AuthUtil.instance.regionProfileManager.onDidChangeRegionProfile(() => {
272+
this.sessionStorage.deleteAllSessions()
273+
})
271274
}
272275

273276
private registerUserPromptsWatcher() {

packages/core/src/codewhispererChat/storages/chatSession.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,8 @@ export class ChatSessionStorage {
2323
public deleteSession(tabID: string) {
2424
this.sessions.delete(tabID)
2525
}
26+
27+
public deleteAllSessions() {
28+
this.sessions.clear()
29+
}
2630
}

0 commit comments

Comments
 (0)