@@ -16,6 +16,7 @@ import {
16
16
ChatTriggerType ,
17
17
EditorContextExtractor ,
18
18
PromptMessage ,
19
+ TriggerEvent ,
19
20
TriggerEventsStorage ,
20
21
TriggerPayload ,
21
22
triggerPayloadToChatRequest ,
@@ -30,6 +31,7 @@ import { extractAuthFollowUp } from 'aws-core-vscode/amazonq'
30
31
import { InlineChatParams , InlineChatResult } from '@aws/language-server-runtimes-types'
31
32
import { decryptResponse , encryptRequest } from '../../lsp/encryption'
32
33
import { getCursorState } from '../../lsp/utils'
34
+ import { CwsprChatTriggerInteraction , telemetry } from 'aws-core-vscode/telemetry'
33
35
34
36
export class InlineChatProvider {
35
37
private readonly editorContextExtractor : EditorContextExtractor
@@ -68,7 +70,34 @@ export class InlineChatProvider {
68
70
}
69
71
}
70
72
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
+
71
84
public async processPromptMessageLSP ( message : PromptMessage ) : Promise < InlineChatResult > {
85
+ const triggerInteraction = this . getTriggerInteractionFromTriggerEvent (
86
+ this . triggerEventsStorage . getLastTriggerEventByTabID ( message . tabID )
87
+ )
88
+ 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
+ } )
98
+ throw new ToolkitError ( 'Inline chat is only available with SSO authentication' )
99
+ }
100
+
72
101
// TODO: handle partial responses.
73
102
getLogger ( ) . info ( 'Making inline chat request with message %O' , message )
74
103
const params = this . getCurrentEditorParams ( message . message ?? '' )
@@ -83,6 +112,23 @@ export class InlineChatProvider {
83
112
84
113
// TODO: remove in favor of LSP implementation.
85
114
public async processPromptMessage ( message : PromptMessage ) {
115
+ const triggerInteraction = this . getTriggerInteractionFromTriggerEvent (
116
+ this . triggerEventsStorage . getLastTriggerEventByTabID ( message . tabID )
117
+ )
118
+ 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
+ } )
129
+ throw new ToolkitError ( 'Inline chat is only available with SSO authentication' )
130
+ }
131
+
86
132
return this . editorContextExtractor
87
133
. extractContextForTrigger ( 'ChatMessage' )
88
134
. then ( ( context ) => {
0 commit comments