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