Skip to content

Commit 0980351

Browse files
ruotingxruotingx
andauthored
feat(amazonq): support JupyterLab conversation history on refresh (#2325)
Allow multiple loadChats() calls in JupyterLab environment. Co-authored-by: ruotingx <[email protected]>
1 parent 9f745a3 commit 0980351

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

server/aws-lsp-codewhisperer/src/language-server/agenticChat/tabBarController.test.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ describe('TabBarController', () => {
5050
afterEach(() => {
5151
sinon.restore()
5252
clock.restore()
53+
delete process.env.JUPYTER_LAB // Clean up JupyterLab environment variables
5354
testFeatures.dispose()
5455
})
5556

@@ -540,7 +541,7 @@ describe('TabBarController', () => {
540541
})
541542
})
542543

543-
it('should only load chats once', async () => {
544+
it('should only load chats once in non-JupyterLab environments', async () => {
544545
const mockTabs = [{ historyId: 'history1', conversations: [{ messages: [] }] }] as unknown as Tab[]
545546
;(chatHistoryDb.getOpenTabs as sinon.SinonStub).returns(mockTabs)
546547

@@ -559,6 +560,22 @@ describe('TabBarController', () => {
559560
result: 'Succeeded',
560561
})
561562
})
563+
564+
it('should allow multiple loads in JupyterLab environment', async () => {
565+
// Set JupyterLab environment
566+
process.env.JUPYTER_LAB = 'true'
567+
568+
const mockTabs = [{ historyId: 'history1', conversations: [{ messages: [] }] }] as unknown as Tab[]
569+
;(chatHistoryDb.getOpenTabs as sinon.SinonStub).returns(mockTabs)
570+
571+
const restoreTabStub = sinon.stub(tabBarController, 'restoreTab')
572+
573+
await tabBarController.loadChats()
574+
await tabBarController.loadChats() // Second call should NOT be ignored in JupyterLab
575+
576+
sinon.assert.calledTwice(restoreTabStub)
577+
sinon.assert.calledTwice(telemetryService.emitLoadHistory as sinon.SinonStub)
578+
})
562579
})
563580
})
564581

server/aws-lsp-codewhisperer/src/language-server/agenticChat/tabBarController.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,17 @@ export class TabBarController {
313313
* When IDE is opened, restore chats that were previously open in IDE for the current workspace.
314314
*/
315315
async loadChats() {
316-
if (this.#loadedChats) {
316+
const isJupyterLab = this.isJupyterLabEnvironment()
317+
318+
// For non-JupyterLab environments, prevent multiple loads
319+
if (!isJupyterLab && this.#loadedChats) {
317320
return
318321
}
319-
this.#loadedChats = true
322+
323+
if (!isJupyterLab) {
324+
this.#loadedChats = true
325+
}
326+
320327
const openConversations = this.#chatHistoryDb.getOpenTabs()
321328
if (openConversations) {
322329
for (const conversation of openConversations) {
@@ -332,6 +339,18 @@ export class TabBarController {
332339
}
333340
}
334341

342+
/**
343+
* Determines if the environment is JupyterLab.
344+
*/
345+
private isJupyterLabEnvironment(): boolean {
346+
try {
347+
return process.env.JUPYTER_LAB === 'true'
348+
} catch (error) {
349+
this.#features.logging.error(`Failed to read JUPYTER_LAB environment variable: ${error}`)
350+
return false
351+
}
352+
}
353+
335354
public static enableChatExport(params?: InitializeParams) {
336355
if (params?.initializationOptions?.aws?.awsClientCapabilities?.window?.showSaveFileDialog) {
337356
// Export Chat UX flow relies on show Save File dialog protocol supported by client

0 commit comments

Comments
 (0)