@@ -66,6 +66,8 @@ import {
6666 ShowOpenDialogParams ,
6767 openFileDialogRequestType ,
6868 OpenFileDialogResult ,
69+ subscriptionDetailsNotificationType ,
70+ subscriptionUpgradeNotificationType ,
6971} from '@aws/language-server-runtimes/protocol'
7072import { v4 as uuidv4 } from 'uuid'
7173import * as vscode from 'vscode'
@@ -94,7 +96,7 @@ import { isValidResponseError } from './error'
9496import { decryptResponse , encryptRequest } from '../encryption'
9597import { getCursorState } from '../utils'
9698import { 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'
98100
99101export function registerActiveEditorChangeListener ( languageClient : LanguageClient ) {
100102 let debounceTimer : NodeJS . Timeout | undefined
@@ -126,6 +128,22 @@ export function registerLanguageServerEventListener(languageClient: LanguageClie
126128 )
127129
128130 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+ }
129147
130148 // overide the quick action commands provided by flare server initialization, which doesn't provide the group header
131149 if ( chatOptions ?. quickActions ?. quickActionsCommandGroups ?. [ 0 ] ) {
@@ -244,6 +262,18 @@ export function registerMessageListeners(
244262 }
245263 break
246264 }
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+ }
247277 case DISCLAIMER_ACKNOWLEDGED : {
248278 void AmazonQPromptSettings . instance . update ( 'amazonQChatDisclaimer' , true )
249279 break
@@ -653,6 +683,46 @@ export function registerMessageListeners(
653683 params : params ,
654684 } )
655685 } )
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+ )
656726}
657727
658728function isServerEvent ( command : string ) {
0 commit comments