Skip to content
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
21 changes: 14 additions & 7 deletions packages/core/src/amazonq/webview/ui/apps/cwChatConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { ChatItem, ChatItemAction, ChatItemType, FeedbackPayload } from '@aws/mynah-ui'
import { ChatItemAction, ChatItemType, FeedbackPayload } from '@aws/mynah-ui'
import { ExtensionMessage } from '../commands'
import { CodeReference } from './amazonqCommonsConnector'
import { TabOpenType, TabsStorage } from '../storages/tabsStorage'
import { FollowUpGenerator } from '../followUps/generator'
import { CWCChatItem } from '../connector'

interface ChatPayload {
chatMessage: string
Expand All @@ -17,8 +18,8 @@ interface ChatPayload {
export interface ConnectorProps {
sendMessageToExtension: (message: ExtensionMessage) => void
onMessageReceived?: (tabID: string, messageData: any, needToShowAPIDocsTab: boolean) => void
onChatAnswerReceived?: (tabID: string, message: ChatItem) => void
onCWCContextCommandMessage: (message: ChatItem, command?: string) => string | undefined
onChatAnswerReceived?: (tabID: string, message: CWCChatItem) => void
onCWCContextCommandMessage: (message: CWCChatItem, command?: string) => string | undefined
onError: (tabID: string, message: string, title: string) => void
onWarning: (tabID: string, message: string, title: string) => void
onOpenSettingsMessage: (tabID: string) => void
Expand Down Expand Up @@ -109,7 +110,8 @@ export class Connector {
codeReference?: CodeReference[],
eventId?: string,
codeBlockIndex?: number,
totalCodeBlocks?: number
totalCodeBlocks?: number,
userIntent?: string
): void => {
this.sendMessageToExtension({
tabID: tabID,
Expand All @@ -122,6 +124,7 @@ export class Connector {
eventId,
codeBlockIndex,
totalCodeBlocks,
userIntent,
})
}

Expand All @@ -133,7 +136,8 @@ export class Connector {
codeReference?: CodeReference[],
eventId?: string,
codeBlockIndex?: number,
totalCodeBlocks?: number
totalCodeBlocks?: number,
userIntent?: string
): void => {
this.sendMessageToExtension({
tabID: tabID,
Expand All @@ -146,6 +150,7 @@ export class Connector {
eventId,
codeBlockIndex,
totalCodeBlocks,
userIntent,
})
}

Expand Down Expand Up @@ -282,13 +287,14 @@ export class Connector {
}
: undefined

const answer: ChatItem = {
const answer: CWCChatItem = {
type: messageData.messageType,
messageId: messageData.messageID ?? messageData.triggerID,
body: messageData.message,
followUp: followUps,
canBeVoted: true,
codeReference: messageData.codeReference,
userIntent: messageData.userIntent,
}

// If it is not there we will not set it
Expand All @@ -315,12 +321,13 @@ export class Connector {
return
}
if (messageData.messageType === ChatItemType.ANSWER) {
const answer: ChatItem = {
const answer: CWCChatItem = {
type: messageData.messageType,
body: undefined,
relatedContent: undefined,
messageId: messageData.messageID,
codeReference: messageData.codeReference,
userIntent: messageData.userIntent,
followUp:
messageData.followUps !== undefined && messageData.followUps.length > 0
? {
Expand Down
19 changes: 15 additions & 4 deletions packages/core/src/amazonq/webview/ui/connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { TabType, TabsStorage } from './storages/tabsStorage'
import { WelcomeFollowupType } from './apps/amazonqCommonsConnector'
import { AuthFollowUpType } from './followUps/generator'
import { DiffTreeFileInfo } from './diffTree/types'
import { UserIntent } from '@amzn/codewhisperer-streaming'

export interface CodeReference {
licenseName?: string
Expand All @@ -29,6 +30,12 @@ export interface ChatPayload {
chatCommand?: string
}

// Adding userIntent param by extending ChatItem to send userIntent as part of amazonq_interactWithMessage telemetry event
export interface CWCChatItem extends ChatItem {
traceId?: string
userIntent?: UserIntent
}

export interface ConnectorProps {
sendMessageToExtension: (message: ExtensionMessage) => void
onMessageReceived?: (tabID: string, messageData: any, needToShowAPIDocsTab: boolean) => void
Expand Down Expand Up @@ -214,7 +221,8 @@ export class Connector {
codeReference?: CodeReference[],
eventId?: string,
codeBlockIndex?: number,
totalCodeBlocks?: number
totalCodeBlocks?: number,
userIntent?: string
): void => {
switch (this.tabsStorage.getTab(tabID)?.type) {
case 'cwc':
Expand All @@ -226,7 +234,8 @@ export class Connector {
codeReference,
eventId,
codeBlockIndex,
totalCodeBlocks
totalCodeBlocks,
userIntent
)
break
case 'featuredev':
Expand All @@ -243,7 +252,8 @@ export class Connector {
codeReference?: CodeReference[],
eventId?: string,
codeBlockIndex?: number,
totalCodeBlocks?: number
totalCodeBlocks?: number,
userIntent?: string
): void => {
switch (this.tabsStorage.getTab(tabID)?.type) {
case 'cwc':
Expand All @@ -255,7 +265,8 @@ export class Connector {
codeReference,
eventId,
codeBlockIndex,
totalCodeBlocks
totalCodeBlocks,
userIntent
)
break
case 'featuredev':
Expand Down
35 changes: 31 additions & 4 deletions packages/core/src/amazonq/webview/ui/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
import { Connector } from './connector'
import { Connector, CWCChatItem } from './connector'
import { ChatItem, ChatItemType, MynahIcons, MynahUI, MynahUIDataModel, NotificationType } from '@aws/mynah-ui'
import { ChatPrompt } from '@aws/mynah-ui/dist/static'
import { TabsStorage, TabType } from './storages/tabsStorage'
Expand All @@ -22,6 +22,8 @@ export const createMynahUI = (ideApi: any, amazonQEnabled: boolean) => {
let mynahUI: MynahUI
// eslint-disable-next-line prefer-const
let connector: Connector
//Store the mapping between messageId and messageUserIntent for amazonq_interactWithMessage telemetry
const messageUserIntentMap = new Map<string, string>()

window.addEventListener('error', (e) => {
const { error, message } = e
Expand Down Expand Up @@ -199,7 +201,7 @@ export const createMynahUI = (ideApi: any, amazonQEnabled: boolean) => {
} as ChatItem)
}
},
onChatAnswerReceived: (tabID: string, item: ChatItem) => {
onChatAnswerReceived: (tabID: string, item: CWCChatItem) => {
if (item.type === ChatItemType.ANSWER_PART || item.type === ChatItemType.CODE_RESULT) {
mynahUI.updateLastChatAnswer(tabID, {
...(item.messageId !== undefined ? { messageId: item.messageId } : {}),
Expand All @@ -211,6 +213,9 @@ export const createMynahUI = (ideApi: any, amazonQEnabled: boolean) => {
? { type: ChatItemType.CODE_RESULT, fileList: item.fileList }
: {}),
})
if (item.messageId !== undefined && item.userIntent !== undefined) {
messageUserIntentMap.set(item.messageId, item.userIntent)
}
ideApi.postMessage({
command: 'update-chat-message-telemetry',
tabID,
Expand Down Expand Up @@ -429,7 +434,28 @@ export const createMynahUI = (ideApi: any, amazonQEnabled: boolean) => {
content: 'Thanks for your feedback.',
})
},
onCodeInsertToCursorPosition: connector.onCodeInsertToCursorPosition,
onCodeInsertToCursorPosition: (
tabId,
messageId,
code,
type,
referenceTrackerInfo,
eventId,
codeBlockIndex,
totalCodeBlocks
) => {
connector.onCodeInsertToCursorPosition(
tabId,
messageId,
code,
type,
referenceTrackerInfo,
eventId,
codeBlockIndex,
totalCodeBlocks,
messageUserIntentMap.get(messageId) ?? undefined
Copy link
Contributor

Choose a reason for hiding this comment

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

nice

)
},
onCopyCodeToClipboard: (
tabId,
messageId,
Expand All @@ -448,7 +474,8 @@ export const createMynahUI = (ideApi: any, amazonQEnabled: boolean) => {
referenceTrackerInfo,
eventId,
codeBlockIndex,
totalCodeBlocks
totalCodeBlocks,
messageUserIntentMap.get(messageId) ?? undefined
)
mynahUI.notify({
type: NotificationType.SUCCESS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export class Messenger {
relatedSuggestions: undefined,
triggerID,
messageID: '',
userIntent: undefined,
},
tabID
)
Expand Down Expand Up @@ -193,6 +194,7 @@ export class Messenger {
codeReference,
triggerID,
messageID,
userIntent: triggerPayload.userIntent,
},
tabID
)
Expand Down Expand Up @@ -269,6 +271,7 @@ export class Messenger {
relatedSuggestions: undefined,
triggerID,
messageID,
userIntent: triggerPayload.userIntent,
},
tabID
)
Expand All @@ -286,6 +289,7 @@ export class Messenger {
relatedSuggestions,
triggerID,
messageID,
userIntent: triggerPayload.userIntent,
},
tabID
)
Expand All @@ -302,6 +306,7 @@ export class Messenger {
relatedSuggestions: undefined,
triggerID,
messageID,
userIntent: triggerPayload.userIntent,
},
tabID
)
Expand Down Expand Up @@ -425,6 +430,7 @@ export class Messenger {
relatedSuggestions: undefined,
triggerID,
messageID: 'static_message_' + triggerID,
userIntent: undefined,
},
tabID
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ export interface ChatMessageProps {
readonly codeReference?: CodeReference[]
readonly triggerID: string
readonly messageID: string
readonly userIntent: string | undefined
}

export class ChatMessage extends UiMessage {
Expand All @@ -153,6 +154,7 @@ export class ChatMessage extends UiMessage {
readonly followUpsHeader: string | undefined
readonly triggerID: string
readonly messageID: string | undefined
readonly userIntent: string | undefined
override type = 'chatMessage'

constructor(props: ChatMessageProps, tabID: string) {
Expand All @@ -165,6 +167,7 @@ export class ChatMessage extends UiMessage {
this.codeReference = props.codeReference
this.triggerID = props.triggerID
this.messageID = props.messageID
this.userIntent = props.userIntent
}
}

Expand Down
Loading