Skip to content
Merged
Show file tree
Hide file tree
Changes from 15 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
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ mockitoKotlin = "5.4.0"
mockk = "1.13.10"
nimbus-jose-jwt = "9.40"
node-gradle = "7.0.2"
telemetryGenerator = "1.0.262"
telemetryGenerator = "1.0.272"
testLogger = "4.0.0"
testRetry = "1.5.10"
# test-only; platform provides slf4j transitively at runtime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
private val codeReferences = mutableListOf<CodeReference>()
private var requestId: String = ""
private var statusCode: Int = 0
private val defaultTestGenResponseLanguage: String = "plaintext"
private var codeBlockLanguage: String = defaultTestGenResponseLanguage

companion object {
private val CODE_BLOCK_PATTERN = Regex("<pre>\\s*<code")
Expand Down Expand Up @@ -143,6 +145,24 @@
}
}

private fun extractCodeBlockLanguage(message: String): String {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please add a test for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved extractCodeBlockLanguage to shared/TextUtils file and added test cases.

// This fulfills both the cases of unit test generation(java, python) and general use case(Non java and Non python) languages.
val codeBlockStart = message.indexOf("```")
if (codeBlockStart == -1) {
return defaultTestGenResponseLanguage
}

val languageStart = codeBlockStart + 3
val languageEnd = message.indexOf('\n', languageStart)

if (languageEnd == -1) {
return defaultTestGenResponseLanguage
}

val language = message.substring(languageStart, languageEnd).trim()
return if (language.isNotEmpty()) language else defaultTestGenResponseLanguage

Check notice on line 163 in plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/cwc/controller/chat/messenger/ChatPromptHandler.kt

View workflow job for this annotation

GitHub Actions / qodana

'if' condition can be replaced with lambda call

Replace with 'ifEmpty {...}'
}

private fun processChatEvent(
tabId: String,
triggerId: String,
Expand Down Expand Up @@ -209,6 +229,10 @@
} else {
responseText.toString()
}
if (codeBlockLanguage == defaultTestGenResponseLanguage) {
// To get the language of generated code in Q chat.
codeBlockLanguage = extractCodeBlockLanguage(message)
}
ChatMessage(
tabId = tabId,
triggerId = triggerId,
Expand All @@ -217,6 +241,7 @@
message = message,
codeReference = codeReferences,
userIntent = data.userIntent,
codeBlockLanguage = codeBlockLanguage,
)
} else {
null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ class TelemetryHelper(private val context: AmazonQAppInitContext, private val se
credentialStartUrl = getStartUrl(context.project),
cwsprChatCodeBlockIndex = message.codeBlockIndex?.toLong(),
cwsprChatTotalCodeBlocks = message.totalCodeBlocks?.toLong(),
cwsprChatHasProjectContext = getMessageHasProjectContext(message.messageId)
cwsprChatHasProjectContext = getMessageHasProjectContext(message.messageId),
cwsprChatProgrammingLanguage = message.codeBlockLanguage,
)
ChatInteractWithMessageEvent.builder().apply {
conversationId(getConversationId(message.tabId).orEmpty())
Expand All @@ -244,7 +245,8 @@ class TelemetryHelper(private val context: AmazonQAppInitContext, private val se
credentialStartUrl = getStartUrl(context.project),
cwsprChatCodeBlockIndex = message.codeBlockIndex?.toLong(),
cwsprChatTotalCodeBlocks = message.totalCodeBlocks?.toLong(),
cwsprChatHasProjectContext = getMessageHasProjectContext(message.messageId)
cwsprChatHasProjectContext = getMessageHasProjectContext(message.messageId),
cwsprChatProgrammingLanguage = message.codeBlockLanguage,
)
ChatInteractWithMessageEvent.builder().apply {
conversationId(getConversationId(message.tabId).orEmpty())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ sealed interface IncomingCwcMessage : CwcMessage {
val eventId: String?,
val codeBlockIndex: Int?,
val totalCodeBlocks: Int?,
val codeBlockLanguage: String?,
) : IncomingCwcMessage

data class InsertCodeAtCursorPosition(
Expand All @@ -84,6 +85,7 @@ sealed interface IncomingCwcMessage : CwcMessage {
val eventId: String?,
val codeBlockIndex: Int?,
val totalCodeBlocks: Int?,
val codeBlockLanguage: String?,
) : IncomingCwcMessage

data class TriggerTabIdReceived(
Expand Down Expand Up @@ -214,6 +216,7 @@ data class ChatMessage(
val relatedSuggestions: List<Suggestion>? = null,
val codeReference: List<CodeReference>? = null,
val userIntent: UserIntent? = null,
val codeBlockLanguage: String? = "plaintext",
) : UiMessage(
tabId = tabId,
type = "chatMessage",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,8 @@ class TelemetryHelperTest {
"insertionTargetType",
"eventId",
codeBlockIndex,
totalCodeBlocks
totalCodeBlocks,
lang
)
)

Expand Down Expand Up @@ -484,7 +485,8 @@ class TelemetryHelperTest {
emptyList(),
eventId,
codeBlockIndex,
totalCodeBlocks
totalCodeBlocks,
lang
)
)

Expand Down
10 changes: 8 additions & 2 deletions plugins/amazonq/mynah-ui/src/mynah-ui/ui/apps/cwChatConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export class Connector {
codeBlockIndex?: number,
totalCodeBlocks?: number,
userIntent?: string,
codeBlockLanguage?: string,
): void => {
this.sendMessageToExtension({
tabID: tabID,
Expand All @@ -113,7 +114,8 @@ export class Connector {
eventId,
codeBlockIndex,
totalCodeBlocks,
userIntent
userIntent,
codeBlockLanguage
})
}

Expand All @@ -127,6 +129,7 @@ export class Connector {
codeBlockIndex?: number,
totalCodeBlocks?: number,
userIntent?: string,
codeBlockLanguage?: string,
): void => {
this.sendMessageToExtension({
tabID: tabID,
Expand All @@ -139,7 +142,8 @@ export class Connector {
eventId,
codeBlockIndex,
totalCodeBlocks,
userIntent
userIntent,
codeBlockLanguage
})
}

Expand Down Expand Up @@ -271,6 +275,7 @@ export class Connector {
canBeVoted: true,
codeReference: messageData.codeReference,
userIntent: messageData.userIntent,
codeBlockLanguage: messageData.codeBlockLanguage,
}

// If it is not there we will not set it
Expand Down Expand Up @@ -304,6 +309,7 @@ export class Connector {
messageId: messageData.messageId,
codeReference: messageData.codeReference,
userIntent: messageData.userIntent,
codeBlockLanguage: messageData.codeBlockLanguage,
followUp:
messageData.followUps !== undefined && messageData.followUps.length > 0
? {
Expand Down
15 changes: 10 additions & 5 deletions plugins/amazonq/mynah-ui/src/mynah-ui/ui/connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export interface ChatPayload {
}

export interface CWCChatItem extends ChatItem {
userIntent?: string
userIntent?: string,
codeBlockLanguage?: string,
}

export interface ConnectorProps {
Expand Down Expand Up @@ -235,7 +236,8 @@ export class Connector {
eventId?: string,
codeBlockIndex?: number,
totalCodeBlocks?: number,
userIntent?: string
userIntent?: string,
codeBlockLanguage?: string
): void => {
switch (this.tabsStorage.getTab(tabID)?.type) {
case 'cwc':
Expand All @@ -248,7 +250,8 @@ export class Connector {
eventId,
codeBlockIndex,
totalCodeBlocks,
userIntent
userIntent,
codeBlockLanguage
)
break
case 'featuredev':
Expand All @@ -266,7 +269,8 @@ export class Connector {
eventId?: string,
codeBlockIndex?: number,
totalCodeBlocks?: number,
userIntent?: string
userIntent?: string,
codeBlockLanguage?: string
): void => {
switch (this.tabsStorage.getTab(tabID)?.type) {
case 'cwc':
Expand All @@ -279,7 +283,8 @@ export class Connector {
eventId,
codeBlockIndex,
totalCodeBlocks,
userIntent
userIntent,
codeBlockLanguage
)
break
case 'featuredev':
Expand Down
12 changes: 7 additions & 5 deletions plugins/amazonq/mynah-ui/src/mynah-ui/ui/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const createMynahUI = (ideApi: any, featureDevInitEnabled: boolean, codeT
let mynahUI: MynahUI
// eslint-disable-next-line prefer-const
let connector: Connector
const messageUserIntentMap = new Map<string, string>()
const responseMetadata = new Map<string, string[]>()

const tabsStorage = new TabsStorage({
onTabTimeout: tabID => {
Expand Down Expand Up @@ -254,8 +254,8 @@ export const createMynahUI = (ideApi: any, featureDevInitEnabled: boolean, codeT
? { type: ChatItemType.CODE_RESULT, fileList: item.fileList }
: {}),
})
if (item.messageId !== undefined && item.userIntent !== undefined) {
messageUserIntentMap.set(item.messageId, item.userIntent)
if (item.messageId !== undefined && item.userIntent !== undefined && item.codeBlockLanguage !== undefined) {
responseMetadata.set(item.messageId, [item.userIntent, item.codeBlockLanguage])
}
return
}
Expand Down Expand Up @@ -466,7 +466,8 @@ export const createMynahUI = (ideApi: any, featureDevInitEnabled: boolean, codeT
eventId,
codeBlockIndex,
totalCodeBlocks,
messageUserIntentMap.get(messageId) ?? undefined
responseMetadata.get(messageId)?.[0] ?? undefined,
responseMetadata.get(messageId)?.[1] ?? undefined
)
break
case 'copy':
Expand All @@ -479,7 +480,8 @@ export const createMynahUI = (ideApi: any, featureDevInitEnabled: boolean, codeT
eventId,
codeBlockIndex,
totalCodeBlocks,
messageUserIntentMap.get(messageId) ?? undefined
responseMetadata.get(messageId)?.[0] ?? undefined,
responseMetadata.get(messageId)?.[1] ?? undefined
)
mynahUI.notify({
type: NotificationType.SUCCESS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,6 @@
"type": "int",
"description": "Cpu usage of LSP server"
},
{
"name": "cwsprChatProgrammingLanguage",
"type": "string",
"description": "Programming language associated with the message"
},
{
"name": "cwsprChatConversationType",
"type": "string",
Expand Down Expand Up @@ -644,57 +639,6 @@
}
]
},
{
"name": "amazonq_interactWithMessage",
"description": "When a user interacts with a message in the conversation",
"metadata": [
{
"type": "cwsprChatConversationId"
},
{
"type": "cwsprChatMessageId"
},
{
"type": "cwsprChatUserIntent",
"required": false
},
{
"type": "cwsprChatInteractionType"
},
{
"type": "cwsprChatInteractionTarget",
"required": false
},
{
"type": "cwsprChatCodeBlockIndex",
"required": false
},
{
"type": "cwsprChatTotalCodeBlocks",
"required": false
},
{
"type": "cwsprChatAcceptedCharactersLength",
"required": false
},
{
"type": "cwsprChatAcceptedNumberOfLines",
"required": false
},
{
"type": "cwsprChatHasReference",
"required": false
},
{
"type": "credentialStartUrl",
"required": false
},
{
"type": "cwsprChatHasProjectContext",
"required": false
}
]
},
{
"name": "amazonq_modifyCode",
"description": "Percentage of code modified by the user after copying/inserting code from a message",
Expand Down
Loading