Skip to content

Commit bde961f

Browse files
authored
refactor: removing some redundant code (#2364)
1 parent b29478f commit bde961f

File tree

3 files changed

+3
-71
lines changed

3 files changed

+3
-71
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,7 +1331,7 @@ export class AgenticChatController implements ChatHandlers {
13311331
if (result.data?.chatResult.body !== undefined) {
13321332
this.#chatHistoryDb.replaceWithSummary(tabId, 'cwc', conversationIdentifier ?? '', {
13331333
body: result.data?.chatResult.body,
1334-
type: 'prompt' as any,
1334+
type: 'prompt' as ChatMessage['type'],
13351335
shouldDisplayMessage: true,
13361336
timestamp: new Date(),
13371337
})
@@ -1451,7 +1451,7 @@ export class AgenticChatController implements ChatHandlers {
14511451
} else {
14521452
this.#chatHistoryDb.addMessage(tabId, 'cwc', conversationIdentifier, {
14531453
body: currentMessage.userInputMessage?.content ?? '',
1454-
type: 'prompt' as any,
1454+
type: 'prompt' as ChatMessage['type'],
14551455
userIntent: currentMessage.userInputMessage?.userIntent,
14561456
origin: currentMessage.userInputMessage?.origin,
14571457
userInputMessageContext: currentMessage.userInputMessage?.userInputMessageContext,
@@ -1527,7 +1527,7 @@ export class AgenticChatController implements ChatHandlers {
15271527
} else {
15281528
this.#chatHistoryDb.addMessage(tabId, 'cwc', conversationIdentifier ?? '', {
15291529
body: result.data?.chatResult.body,
1530-
type: 'answer' as any,
1530+
type: 'answer' as ChatMessage['type'],
15311531
codeReference: result.data.chatResult.codeReference,
15321532
relatedContent:
15331533
result.data.chatResult.relatedContent?.content &&

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

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -91,30 +91,6 @@ describe('ChatDatabase', () => {
9191
})
9292
})
9393

94-
describe('replaceHistory', () => {
95-
it('should replace history with messages', async () => {
96-
await chatDb.databaseInitialize(0)
97-
const tabId = 'tab-1'
98-
const tabType = 'cwc'
99-
const conversationId = 'conv-1'
100-
const messages = [
101-
{ body: 'Test', type: 'prompt' as any, timestamp: new Date() },
102-
{ body: 'Thinking...', type: 'answer', timestamp: new Date() },
103-
]
104-
105-
// Call the method
106-
chatDb.replaceHistory(tabId, tabType, conversationId, messages)
107-
108-
// Verify the messages array contains the summary and a dummy response
109-
const messagesFromDb = chatDb.getMessages(tabId, 250)
110-
assert.strictEqual(messagesFromDb.length, 2)
111-
assert.strictEqual(messagesFromDb[0].body, 'Test')
112-
assert.strictEqual(messagesFromDb[0].type, 'prompt')
113-
assert.strictEqual(messagesFromDb[1].body, 'Thinking...')
114-
assert.strictEqual(messagesFromDb[1].type, 'answer')
115-
})
116-
})
117-
11894
describe('ensureValidMessageSequence', () => {
11995
it('should preserve valid alternating sequence', () => {
12096
const messages: Message[] = [

server/aws-lsp-codewhisperer/src/language-server/agenticChat/tools/chatDb/chatDb.ts

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -636,50 +636,6 @@ export class ChatDatabase {
636636
}
637637
}
638638

639-
/**
640-
* Replace history with summary/dummyResponse pair within a specified tab.
641-
*
642-
* This method manages chat messages by creating a new history with compacted summary and dummy response pairs
643-
*/
644-
replaceHistory(tabId: string, tabType: TabType, conversationId: string, messages: Message[]) {
645-
if (this.isInitialized()) {
646-
const clientType = this.#features.lsp.getClientInitializeParams()?.clientInfo?.name || 'unknown'
647-
const tabCollection = this.#db.getCollection<Tab>(TabCollection)
648-
649-
this.#features.logging.log(
650-
`Update history with new messages: tabId=${tabId}, tabType=${tabType}, conversationId=${conversationId}`
651-
)
652-
653-
const oldHistoryId = this.getOrCreateHistoryId(tabId)
654-
// create a new historyId to start fresh
655-
const historyId = this.createHistoryId(tabId)
656-
657-
const tabData = historyId ? tabCollection.findOne({ historyId }) : undefined
658-
const tabTitle = tabData?.title || 'Amazon Q Chat'
659-
messages = messages.map(msg => this.formatChatHistoryMessage(msg))
660-
this.#features.logging.log(`Overriding tab with new historyId=${historyId}`)
661-
tabCollection.insert({
662-
historyId,
663-
updatedAt: new Date(),
664-
isOpen: true,
665-
tabType: tabType,
666-
title: tabTitle,
667-
conversations: [
668-
{
669-
conversationId,
670-
clientType,
671-
updatedAt: new Date(),
672-
messages: messages,
673-
},
674-
],
675-
})
676-
677-
if (oldHistoryId) {
678-
tabCollection.findAndRemove({ historyId: oldHistoryId })
679-
}
680-
}
681-
}
682-
683639
formatChatHistoryMessage(message: Message): Message {
684640
if (message.type === ('prompt' as ChatItemType)) {
685641
let hasToolResults = false

0 commit comments

Comments
 (0)