Skip to content

Commit a22bab6

Browse files
committed
Acceptance metrics for CWC
1 parent de9d7cf commit a22bab6

File tree

6 files changed

+71
-17
lines changed

6 files changed

+71
-17
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/core/src/amazonq/webview/ui/apps/cwChatConnector.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import { ChatItem, ChatItemAction, ChatItemType, FeedbackPayload } from '@aws/mynah-ui'
6+
import { ChatItemAction, ChatItemType, FeedbackPayload } from '@aws/mynah-ui'
77
import { ExtensionMessage } from '../commands'
88
import { CodeReference } from './amazonqCommonsConnector'
99
import { TabOpenType, TabsStorage } from '../storages/tabsStorage'
1010
import { FollowUpGenerator } from '../followUps/generator'
11+
import { CWCChatItem } from '../connector'
1112

1213
interface ChatPayload {
1314
chatMessage: string
@@ -17,8 +18,8 @@ interface ChatPayload {
1718
export interface ConnectorProps {
1819
sendMessageToExtension: (message: ExtensionMessage) => void
1920
onMessageReceived?: (tabID: string, messageData: any, needToShowAPIDocsTab: boolean) => void
20-
onChatAnswerReceived?: (tabID: string, message: ChatItem) => void
21-
onCWCContextCommandMessage: (message: ChatItem, command?: string) => string | undefined
21+
onChatAnswerReceived?: (tabID: string, message: CWCChatItem) => void
22+
onCWCContextCommandMessage: (message: CWCChatItem, command?: string) => string | undefined
2223
onError: (tabID: string, message: string, title: string) => void
2324
onWarning: (tabID: string, message: string, title: string) => void
2425
onOpenSettingsMessage: (tabID: string) => void
@@ -109,7 +110,8 @@ export class Connector {
109110
codeReference?: CodeReference[],
110111
eventId?: string,
111112
codeBlockIndex?: number,
112-
totalCodeBlocks?: number
113+
totalCodeBlocks?: number,
114+
userIntent?: string
113115
): void => {
114116
this.sendMessageToExtension({
115117
tabID: tabID,
@@ -122,6 +124,7 @@ export class Connector {
122124
eventId,
123125
codeBlockIndex,
124126
totalCodeBlocks,
127+
userIntent,
125128
})
126129
}
127130

@@ -133,7 +136,8 @@ export class Connector {
133136
codeReference?: CodeReference[],
134137
eventId?: string,
135138
codeBlockIndex?: number,
136-
totalCodeBlocks?: number
139+
totalCodeBlocks?: number,
140+
userIntent?: string
137141
): void => {
138142
this.sendMessageToExtension({
139143
tabID: tabID,
@@ -146,6 +150,7 @@ export class Connector {
146150
eventId,
147151
codeBlockIndex,
148152
totalCodeBlocks,
153+
userIntent,
149154
})
150155
}
151156

@@ -282,13 +287,14 @@ export class Connector {
282287
}
283288
: undefined
284289

285-
const answer: ChatItem = {
290+
const answer: CWCChatItem = {
286291
type: messageData.messageType,
287292
messageId: messageData.messageID ?? messageData.triggerID,
288293
body: messageData.message,
289294
followUp: followUps,
290295
canBeVoted: true,
291296
codeReference: messageData.codeReference,
297+
userIntent: messageData.userIntent,
292298
}
293299

294300
// If it is not there we will not set it
@@ -315,12 +321,13 @@ export class Connector {
315321
return
316322
}
317323
if (messageData.messageType === ChatItemType.ANSWER) {
318-
const answer: ChatItem = {
324+
const answer: CWCChatItem = {
319325
type: messageData.messageType,
320326
body: undefined,
321327
relatedContent: undefined,
322328
messageId: messageData.messageID,
323329
codeReference: messageData.codeReference,
330+
userIntent: messageData.userIntent,
324331
followUp:
325332
messageData.followUps !== undefined && messageData.followUps.length > 0
326333
? {

packages/core/src/amazonq/webview/ui/connector.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { TabType, TabsStorage } from './storages/tabsStorage'
1313
import { WelcomeFollowupType } from './apps/amazonqCommonsConnector'
1414
import { AuthFollowUpType } from './followUps/generator'
1515
import { DiffTreeFileInfo } from './diffTree/types'
16+
import { UserIntent } from '@amzn/codewhisperer-streaming'
1617

1718
export interface CodeReference {
1819
licenseName?: string
@@ -29,6 +30,12 @@ export interface ChatPayload {
2930
chatCommand?: string
3031
}
3132

33+
// Adding userIntent param by extending ChatItem to send userIntent as part of amazonq_interactWithMessage event
34+
export interface CWCChatItem extends ChatItem {
35+
traceId?: string
36+
userIntent?: UserIntent
37+
}
38+
3239
export interface ConnectorProps {
3340
sendMessageToExtension: (message: ExtensionMessage) => void
3441
onMessageReceived?: (tabID: string, messageData: any, needToShowAPIDocsTab: boolean) => void
@@ -214,7 +221,8 @@ export class Connector {
214221
codeReference?: CodeReference[],
215222
eventId?: string,
216223
codeBlockIndex?: number,
217-
totalCodeBlocks?: number
224+
totalCodeBlocks?: number,
225+
userIntent?: string
218226
): void => {
219227
switch (this.tabsStorage.getTab(tabID)?.type) {
220228
case 'cwc':
@@ -226,7 +234,8 @@ export class Connector {
226234
codeReference,
227235
eventId,
228236
codeBlockIndex,
229-
totalCodeBlocks
237+
totalCodeBlocks,
238+
userIntent
230239
)
231240
break
232241
case 'featuredev':
@@ -243,7 +252,8 @@ export class Connector {
243252
codeReference?: CodeReference[],
244253
eventId?: string,
245254
codeBlockIndex?: number,
246-
totalCodeBlocks?: number
255+
totalCodeBlocks?: number,
256+
userIntent?: string
247257
): void => {
248258
switch (this.tabsStorage.getTab(tabID)?.type) {
249259
case 'cwc':
@@ -255,7 +265,8 @@ export class Connector {
255265
codeReference,
256266
eventId,
257267
codeBlockIndex,
258-
totalCodeBlocks
268+
totalCodeBlocks,
269+
userIntent
259270
)
260271
break
261272
case 'featuredev':

packages/core/src/amazonq/webview/ui/main.ts

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
* SPDX-License-Identifier: Apache-2.0
44
*/
5-
import { Connector } from './connector'
5+
import { Connector, CWCChatItem } from './connector'
66
import { ChatItem, ChatItemType, MynahIcons, MynahUI, MynahUIDataModel, NotificationType } from '@aws/mynah-ui'
77
import { ChatPrompt } from '@aws/mynah-ui/dist/static'
88
import { TabsStorage, TabType } from './storages/tabsStorage'
@@ -22,6 +22,8 @@ export const createMynahUI = (ideApi: any, amazonQEnabled: boolean) => {
2222
let mynahUI: MynahUI
2323
// eslint-disable-next-line prefer-const
2424
let connector: Connector
25+
//Store the mapping between messageId and messageUserIntent for amazonq_interactWithMessage telemetry
26+
const messageUserIntentMap = new Map<string, string>()
2527

2628
window.addEventListener('error', (e) => {
2729
const { error, message } = e
@@ -199,7 +201,7 @@ export const createMynahUI = (ideApi: any, amazonQEnabled: boolean) => {
199201
} as ChatItem)
200202
}
201203
},
202-
onChatAnswerReceived: (tabID: string, item: ChatItem) => {
204+
onChatAnswerReceived: (tabID: string, item: CWCChatItem) => {
203205
if (item.type === ChatItemType.ANSWER_PART || item.type === ChatItemType.CODE_RESULT) {
204206
mynahUI.updateLastChatAnswer(tabID, {
205207
...(item.messageId !== undefined ? { messageId: item.messageId } : {}),
@@ -211,6 +213,9 @@ export const createMynahUI = (ideApi: any, amazonQEnabled: boolean) => {
211213
? { type: ChatItemType.CODE_RESULT, fileList: item.fileList }
212214
: {}),
213215
})
216+
if (item.messageId !== undefined && item.userIntent !== undefined) {
217+
messageUserIntentMap.set(item.messageId, item.userIntent)
218+
}
214219
ideApi.postMessage({
215220
command: 'update-chat-message-telemetry',
216221
tabID,
@@ -429,7 +434,28 @@ export const createMynahUI = (ideApi: any, amazonQEnabled: boolean) => {
429434
content: 'Thanks for your feedback.',
430435
})
431436
},
432-
onCodeInsertToCursorPosition: connector.onCodeInsertToCursorPosition,
437+
onCodeInsertToCursorPosition: (
438+
tabId,
439+
messageId,
440+
code,
441+
type,
442+
referenceTrackerInfo,
443+
eventId,
444+
codeBlockIndex,
445+
totalCodeBlocks
446+
) => {
447+
connector.onCodeInsertToCursorPosition(
448+
tabId,
449+
messageId,
450+
code,
451+
type,
452+
referenceTrackerInfo,
453+
eventId,
454+
codeBlockIndex,
455+
totalCodeBlocks,
456+
messageUserIntentMap.get(messageId) ?? undefined
457+
)
458+
},
433459
onCopyCodeToClipboard: (
434460
tabId,
435461
messageId,
@@ -448,7 +474,8 @@ export const createMynahUI = (ideApi: any, amazonQEnabled: boolean) => {
448474
referenceTrackerInfo,
449475
eventId,
450476
codeBlockIndex,
451-
totalCodeBlocks
477+
totalCodeBlocks,
478+
messageUserIntentMap.get(messageId) ?? undefined
452479
)
453480
mynahUI.notify({
454481
type: NotificationType.SUCCESS,

packages/core/src/codewhispererChat/controllers/chat/messenger/messenger.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ export class Messenger {
8686
relatedSuggestions: undefined,
8787
triggerID,
8888
messageID: '',
89+
userIntent: undefined,
8990
},
9091
tabID
9192
)
@@ -193,6 +194,7 @@ export class Messenger {
193194
codeReference,
194195
triggerID,
195196
messageID,
197+
userIntent: triggerPayload.userIntent,
196198
},
197199
tabID
198200
)
@@ -269,6 +271,7 @@ export class Messenger {
269271
relatedSuggestions: undefined,
270272
triggerID,
271273
messageID,
274+
userIntent: triggerPayload.userIntent,
272275
},
273276
tabID
274277
)
@@ -286,6 +289,7 @@ export class Messenger {
286289
relatedSuggestions,
287290
triggerID,
288291
messageID,
292+
userIntent: triggerPayload.userIntent,
289293
},
290294
tabID
291295
)
@@ -302,6 +306,7 @@ export class Messenger {
302306
relatedSuggestions: undefined,
303307
triggerID,
304308
messageID,
309+
userIntent: triggerPayload.userIntent,
305310
},
306311
tabID
307312
)
@@ -425,6 +430,7 @@ export class Messenger {
425430
relatedSuggestions: undefined,
426431
triggerID,
427432
messageID: 'static_message_' + triggerID,
433+
userIntent: undefined,
428434
},
429435
tabID
430436
)

packages/core/src/codewhispererChat/view/connector/connector.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ export interface ChatMessageProps {
141141
readonly codeReference?: CodeReference[]
142142
readonly triggerID: string
143143
readonly messageID: string
144+
readonly userIntent: string | undefined
144145
}
145146

146147
export class ChatMessage extends UiMessage {
@@ -153,6 +154,7 @@ export class ChatMessage extends UiMessage {
153154
readonly followUpsHeader: string | undefined
154155
readonly triggerID: string
155156
readonly messageID: string | undefined
157+
readonly userIntent: string | undefined
156158
override type = 'chatMessage'
157159

158160
constructor(props: ChatMessageProps, tabID: string) {
@@ -165,6 +167,7 @@ export class ChatMessage extends UiMessage {
165167
this.codeReference = props.codeReference
166168
this.triggerID = props.triggerID
167169
this.messageID = props.messageID
170+
this.userIntent = props.userIntent
168171
}
169172
}
170173

0 commit comments

Comments
 (0)