@@ -16,6 +16,7 @@ import {
1616 ChatTriggerType ,
1717 EditorContextExtractor ,
1818 PromptMessage ,
19+ TriggerEvent ,
1920 TriggerEventsStorage ,
2021 TriggerPayload ,
2122 triggerPayloadToChatRequest ,
@@ -30,6 +31,7 @@ import { extractAuthFollowUp } from 'aws-core-vscode/amazonq'
3031import { InlineChatParams , InlineChatResult } from '@aws/language-server-runtimes-types'
3132import { decryptResponse , encryptRequest } from '../../lsp/encryption'
3233import { getCursorState } from '../../lsp/utils'
34+ import { CwsprChatTriggerInteraction , telemetry } from 'aws-core-vscode/telemetry'
3335
3436export class InlineChatProvider {
3537 private readonly editorContextExtractor : EditorContextExtractor
@@ -68,11 +70,34 @@ export class InlineChatProvider {
6870 }
6971 }
7072
73+ private getTriggerInteractionFromTriggerEvent ( triggerEvent : TriggerEvent | undefined ) : CwsprChatTriggerInteraction {
74+ switch ( triggerEvent ?. type ) {
75+ case 'editor_context_command' :
76+ return triggerEvent . command ?. triggerType === 'keybinding' ? 'hotkeys' : 'contextMenu'
77+ case 'follow_up' :
78+ case 'chat_message' :
79+ default :
80+ return 'click'
81+ }
82+ }
83+
7184 public async processPromptMessageLSP ( message : PromptMessage ) : Promise < InlineChatResult > {
85+ const triggerInteraction = this . getTriggerInteractionFromTriggerEvent (
86+ this . triggerEventsStorage . getLastTriggerEventByTabID ( message . tabID )
87+ )
7288 if ( ! AuthUtil . instance . isSsoSession ( ) ) {
89+ telemetry . amazonq_messageResponseError . emit ( {
90+ result : 'Failed' ,
91+ cwsprChatConversationType : 'Chat' ,
92+ cwsprChatRequestLength : message . message ?. length ?? 0 ,
93+ cwsprChatResponseCode : 401 ,
94+ cwsprChatTriggerInteraction : triggerInteraction ,
95+ reason : 'AuthenticationError' ,
96+ reasonDesc : 'Inline chat requires SSO authentication, but current session is not' ,
97+ } )
7398 throw new ToolkitError ( 'Inline chat is only available with SSO authentication' )
7499 }
75-
100+
76101 // TODO: handle partial responses.
77102 getLogger ( ) . info ( 'Making inline chat request with message %O' , message )
78103 const params = this . getCurrentEditorParams ( message . message ?? '' )
@@ -87,10 +112,23 @@ export class InlineChatProvider {
87112
88113 // TODO: remove in favor of LSP implementation.
89114 public async processPromptMessage ( message : PromptMessage ) {
115+ const triggerInteraction = this . getTriggerInteractionFromTriggerEvent (
116+ this . triggerEventsStorage . getLastTriggerEventByTabID ( message . tabID )
117+ )
90118 if ( ! AuthUtil . instance . isSsoSession ( ) ) {
119+ telemetry . amazonq_messageResponseError . emit ( {
120+ result : 'Failed' ,
121+ cwsprChatConversationType : 'Chat' ,
122+ cwsprChatRequestLength : message . message ?. length ?? 0 ,
123+ cwsprChatResponseCode : 401 ,
124+ cwsprChatTriggerInteraction : triggerInteraction ,
125+ reason : 'AuthenticationError' ,
126+ reasonDesc : 'Inline chat requires SSO authentication, but current session is not' ,
127+ credentialStartUrl : AuthUtil . instance . connection ?. startUrl ,
128+ } )
91129 throw new ToolkitError ( 'Inline chat is only available with SSO authentication' )
92130 }
93-
131+
94132 return this . editorContextExtractor
95133 . extractContextForTrigger ( 'ChatMessage' )
96134 . then ( ( context ) => {
0 commit comments