Skip to content

fix(chat-client): disable click event for empty history list item #973

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions chat-client/src/client/features/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ export class ChatHistoryList {
if (!item.id) {
throw new Error('Conversation id is not defined')
}

if (item.id === 'empty') {
return
}

this.messager.onConversationClick(item.id)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { TestFeatures } from '@aws/language-server-runtimes/testing'
import sinon from 'ts-sinon'
import * as assert from 'assert'
import { TabBarController } from './tabBarController'
import { ChatDatabase } from './tools/chatDb/chatDb'
import { ChatDatabase, EMPTY_CONVERSATION_LIST_ID } from './tools/chatDb/chatDb'
import { Tab } from './tools/chatDb/util'
import { ConversationItemGroup, OpenTabParams, OpenTabResult } from '@aws/language-server-runtimes-types'
import { InitializeParams } from '@aws/language-server-runtimes/protocol'
Expand Down Expand Up @@ -244,6 +244,23 @@ describe('TabBarController', () => {
sinon.assert.calledWith(chatHistoryDb.deleteHistory as sinon.SinonStub, historyId)
assert.strictEqual(result.success, true)
})

it('should not perform actions when item with `empty` historyId is clicked', async () => {
const historyId = EMPTY_CONVERSATION_LIST_ID
const openTabId = 'tab1'
;(chatHistoryDb.getOpenTabId as sinon.SinonStub).withArgs(historyId).returns(openTabId)

const openTabStub = sinon.stub<[OpenTabParams], Promise<OpenTabResult>>()
testFeatures.chat.openTab = openTabStub

const result = await tabBarController.onConversationClick({ id: historyId })

sinon.assert.notCalled(openTabStub)
assert.deepStrictEqual(result, {
id: EMPTY_CONVERSATION_LIST_ID,
success: true,
})
})
})

describe('export conversation', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { ChatDatabase } from './tools/chatDb/chatDb'
import { ChatDatabase, EMPTY_CONVERSATION_LIST_ID } from './tools/chatDb/chatDb'
import { Conversation, messageToChatMessage, Tab } from './tools/chatDb/util'
import { Features } from '@aws/language-server-runtimes/server-interface/server'
import {
Expand Down Expand Up @@ -58,7 +58,9 @@ export class TabBarController {
const items =
group.items?.map(item => ({
...item,
...(item.id !== 'empty' ? { actions: this.getConversationActions(item.id) } : {}),
...(item.id !== EMPTY_CONVERSATION_LIST_ID
? { actions: this.getConversationActions(item.id) }
: {}),
})) || []

return {
Expand Down Expand Up @@ -128,6 +130,11 @@ export class TabBarController {
async onConversationClick(params: ConversationClickParams): Promise<ConversationClickResult> {
const historyID = params.id

if (historyID === EMPTY_CONVERSATION_LIST_ID) {
this.#features.logging.debug('Empty conversation history list item clicked')
return { ...params, success: true }
}

// Handle user click on conversation in history
if (!params.action) {
const openTabID = this.#chatHistoryDb.getOpenTabId(historyID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
TabType,
updateOrCreateConversation,
} from './util'
import * as crypto from 'crypto'

Check warning on line 17 in server/aws-lsp-codewhisperer/src/language-server/agenticChat/tools/chatDb/chatDb.ts

View workflow job for this annotation

GitHub Actions / Test (Windows)

Do not import Node.js builtin module "crypto"

Check warning on line 17 in server/aws-lsp-codewhisperer/src/language-server/agenticChat/tools/chatDb/chatDb.ts

View workflow job for this annotation

GitHub Actions / Test

Do not import Node.js builtin module "crypto"
import * as path from 'path'

Check warning on line 18 in server/aws-lsp-codewhisperer/src/language-server/agenticChat/tools/chatDb/chatDb.ts

View workflow job for this annotation

GitHub Actions / Test (Windows)

Do not import Node.js builtin module "path"

Check warning on line 18 in server/aws-lsp-codewhisperer/src/language-server/agenticChat/tools/chatDb/chatDb.ts

View workflow job for this annotation

GitHub Actions / Test

Do not import Node.js builtin module "path"
import { Features } from '@aws/language-server-runtimes/server-interface/server'
import { ConversationItemGroup } from '@aws/language-server-runtimes/protocol'
import { getUserHomeDir } from '@aws/lsp-core/out/util/path'

export const EMPTY_CONVERSATION_LIST_ID = 'empty'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could move empty key to types package to properly share it between Chat Client and language server.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or we could introduce isClickable property on item level to decouple a bit.


/**
* A singleton database class that manages chat history persistence using LokiJS.
* This class handles storage and retrieval of chat conversations, messages, and tab states
Expand Down Expand Up @@ -212,7 +214,7 @@
}
if (searchResults.length === 0) {
this.#features.logging.log(`No matches found`)
searchResults = [{ items: [{ id: 'empty', description: 'No matches found' }] }]
searchResults = [{ items: [{ id: EMPTY_CONVERSATION_LIST_ID, description: 'No matches found' }] }]
}
return searchResults
}
Expand Down Expand Up @@ -253,7 +255,7 @@
let groupedTabs = groupTabsByDate(tabs)
this.#features.logging.log(`Found ${tabs.length} conversations from history`)
if (groupedTabs.length === 0) {
return [{ items: [{ id: 'empty', description: 'No chat history found' }] }]
return [{ items: [{ id: EMPTY_CONVERSATION_LIST_ID, description: 'No chat history found' }] }]
} else {
return groupedTabs
}
Expand Down
Loading