Skip to content

fix: add formatChatHistoryMessage to chatDb #1110

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 24, 2025
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
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

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 (Windows)

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

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 (Windows)

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 { ChatMessage, ToolResultStatus } from '@amzn/codewhisperer-streaming'
Expand Down Expand Up @@ -314,6 +314,7 @@
const tabTitle =
(message.type === 'prompt' && message.body.trim().length > 0 ? message.body : tabData?.title) ||
'Amazon Q Chat'
message = this.formatChatHistoryMessage(message)
if (tabData) {
this.#features.logging.log(`Updating existing tab with historyId=${historyId}`)
tabData.conversations = updateOrCreateConversation(
Expand All @@ -339,6 +340,19 @@
}
}

formatChatHistoryMessage(message: Message): Message {
if (message.type === ('prompt' as ChatItemType)) {
return {
...message,
userInputMessageContext: {
// Only keep toolResults in history
toolResults: message.userInputMessageContext?.toolResults,
},
}
}
return message
}

/**
* Fixes the history to maintain the following invariants:
* 1. The history contains at most MaxConversationHistoryMessages messages. Oldest messages are dropped.
Expand Down
Loading