@@ -66,6 +66,8 @@ import {
66
66
ShowOpenDialogParams ,
67
67
openFileDialogRequestType ,
68
68
OpenFileDialogResult ,
69
+ subscriptionDetailsNotificationType ,
70
+ subscriptionUpgradeNotificationType ,
69
71
} from '@aws/language-server-runtimes/protocol'
70
72
import { v4 as uuidv4 } from 'uuid'
71
73
import * as vscode from 'vscode'
@@ -94,7 +96,7 @@ import { isValidResponseError } from './error'
94
96
import { decryptResponse , encryptRequest } from '../encryption'
95
97
import { getCursorState } from '../utils'
96
98
import { focusAmazonQPanel } from './commands'
97
- import { ChatMessage } from '@aws/language-server-runtimes/server-interface'
99
+ import { ChatMessage , SUBSCRIPTION_UPGRADE_NOTIFICATION_METHOD } from '@aws/language-server-runtimes/server-interface'
98
100
99
101
export function registerActiveEditorChangeListener ( languageClient : LanguageClient ) {
100
102
let debounceTimer : NodeJS . Timeout | undefined
@@ -126,6 +128,22 @@ export function registerLanguageServerEventListener(languageClient: LanguageClie
126
128
)
127
129
128
130
const chatOptions = languageClient . initializeResult ?. awsServerCapabilities ?. chatOptions
131
+ /*
132
+ Set subscriptionDetails based on request
133
+ Set to false if subscriptionDetails is not in the request
134
+ Set to true if subscriptionDetails is true in the request
135
+ Set to false otherwise
136
+ */
137
+ if ( chatOptions ) {
138
+ languageClient . info (
139
+ 'Subscription details capability:' ,
140
+ `Server:${ languageClient . initializeResult ?. awsServerCapabilities ?. chatOptions ?. subscriptionDetails } `
141
+ )
142
+
143
+ const requestSubscriptionDetails =
144
+ languageClient . initializeResult ?. awsServerCapabilities ?. chatOptions ?. subscriptionDetails
145
+ chatOptions . subscriptionDetails = requestSubscriptionDetails === true
146
+ }
129
147
130
148
// overide the quick action commands provided by flare server initialization, which doesn't provide the group header
131
149
if ( chatOptions ?. quickActions ?. quickActionsCommandGroups ?. [ 0 ] ) {
@@ -244,6 +262,18 @@ export function registerMessageListeners(
244
262
}
245
263
break
246
264
}
265
+ case SUBSCRIPTION_UPGRADE_NOTIFICATION_METHOD : {
266
+ languageClient . info ( '[VSCode Client] Subscription upgrade clicked' )
267
+ try {
268
+ // Forward the upgrade request to Flare
269
+ languageClient . sendNotification ( subscriptionUpgradeNotificationType . method , message . params )
270
+ } catch ( e ) {
271
+ languageClient . error (
272
+ `[VSCode Client] Failed to send subscription upgrade notification: ${ ( e as Error ) . message } `
273
+ )
274
+ }
275
+ break
276
+ }
247
277
case DISCLAIMER_ACKNOWLEDGED : {
248
278
void AmazonQPromptSettings . instance . update ( 'amazonQChatDisclaimer' , true )
249
279
break
@@ -653,6 +683,46 @@ export function registerMessageListeners(
653
683
params : params ,
654
684
} )
655
685
} )
686
+
687
+ // Handle subscription details response from Flare
688
+ languageClient . onNotification ( subscriptionDetailsNotificationType . method , ( params ) => {
689
+ languageClient . info ( `[VSCode Client] Received subscription details: ${ JSON . stringify ( params ) } ` )
690
+ // Forward the subscription details to the Chat UI
691
+ void provider . webview ?. postMessage ( {
692
+ command : subscriptionDetailsNotificationType . method ,
693
+ params : params ,
694
+ } )
695
+ } )
696
+ // TODO: After implementing the "Upgrade" feature, test its functionality in the Account Details tab.
697
+ // Handle window/showDocument requests from Flare for subscription upgrade
698
+ languageClient . onRequest < ShowDocumentParams , ShowDocumentResult > (
699
+ ShowDocumentRequest . method ,
700
+ async ( params : ShowDocumentParams ) : Promise < ShowDocumentParams | ResponseError < ShowDocumentResult > > => {
701
+ try {
702
+ const uri = vscode . Uri . parse ( params . uri )
703
+
704
+ if ( params . external ) {
705
+ languageClient . info ( `[VSCode Client] Opening external URL for subscription upgrade: ${ params . uri } ` )
706
+ // Open the URL in the external browser
707
+ await vscode . env . openExternal ( uri )
708
+
709
+ // Return success to indicate the URL was opened
710
+ return params
711
+ }
712
+
713
+ // If not external, handle as a regular document
714
+ const doc = await vscode . workspace . openTextDocument ( uri )
715
+ await vscode . window . showTextDocument ( doc , { preview : false } )
716
+ return params
717
+ } catch ( e ) {
718
+ languageClient . error ( `[VSCode Client] Failed to open subscription upgrade URL: ${ ( e as Error ) . message } ` )
719
+ return new ResponseError (
720
+ LSPErrorCodes . RequestFailed ,
721
+ `Failed to open subscription upgrade URL: ${ ( e as Error ) . message } `
722
+ )
723
+ }
724
+ }
725
+ )
656
726
}
657
727
658
728
function isServerEvent ( command : string ) {
0 commit comments