@@ -16,7 +16,6 @@ import {
16
16
ChatTriggerType ,
17
17
EditorContextExtractor ,
18
18
PromptMessage ,
19
- TriggerEvent ,
20
19
TriggerEventsStorage ,
21
20
TriggerPayload ,
22
21
triggerPayloadToChatRequest ,
@@ -70,33 +69,8 @@ export class InlineChatProvider {
70
69
}
71
70
}
72
71
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
-
84
72
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
- }
73
+ this . throwOnIamSession ( message )
100
74
101
75
// TODO: handle partial responses.
102
76
getLogger ( ) . info ( 'Making inline chat request with message %O' , message )
@@ -112,22 +86,7 @@ export class InlineChatProvider {
112
86
113
87
// TODO: remove in favor of LSP implementation.
114
88
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
- }
89
+ this . throwOnIamSession ( message )
131
90
132
91
return this . editorContextExtractor
133
92
. extractContextForTrigger ( 'ChatMessage' )
@@ -271,6 +230,34 @@ export class InlineChatProvider {
271
230
} )
272
231
}
273
232
233
+ private throwOnIamSession ( message : PromptMessage ) {
234
+ const triggerEvent = this . triggerEventsStorage . getLastTriggerEventByTabID ( message . tabID )
235
+ let triggerInteraction : CwsprChatTriggerInteraction
236
+ switch ( triggerEvent ?. type ) {
237
+ case 'editor_context_command' :
238
+ triggerInteraction = triggerEvent . command ?. triggerType === 'keybinding' ? 'hotkeys' : 'contextMenu'
239
+ break
240
+ case 'follow_up' :
241
+ case 'chat_message' :
242
+ default :
243
+ triggerInteraction = 'click'
244
+ break
245
+ }
246
+
247
+ if ( ! AuthUtil . instance . isSsoSession ( ) ) {
248
+ telemetry . amazonq_messageResponseError . emit ( {
249
+ result : 'Failed' ,
250
+ cwsprChatConversationType : 'Chat' ,
251
+ cwsprChatRequestLength : message . message ?. length ?? 0 ,
252
+ cwsprChatResponseCode : 401 ,
253
+ cwsprChatTriggerInteraction : triggerInteraction ,
254
+ reason : 'AuthenticationError' ,
255
+ reasonDesc : 'Inline chat requires SSO authentication, but current session is not' ,
256
+ } )
257
+ throw new ToolkitError ( 'Inline chat is only available with SSO authentication' )
258
+ }
259
+ }
260
+
274
261
public sendTelemetryEvent ( inlineChatEvent : InlineChatEvent , currentTask ?: InlineTask ) {
275
262
codeWhispererClient
276
263
. sendTelemetryEvent ( {
0 commit comments