@@ -38,24 +38,27 @@ import { activate as activateDev } from './dev/activation'
3838import { activate as activateApplicationComposer } from './applicationcomposer/activation'
3939import { activate as activateRedshift } from './awsService/redshift/activation'
4040import { activate as activateIamPolicyChecks } from './awsService/accessanalyzer/activation'
41+ import { activate as activateNotifications } from './notifications/activate'
4142import { SchemaService } from './shared/schemas'
4243import { AwsResourceManager } from './dynamicResources/awsResourceManager'
4344import globals from './shared/extensionGlobals'
4445import { Experiments , Settings , showSettingsFailedMsg } from './shared/settings'
4546import { isReleaseVersion } from './shared/vscode/env'
46- import { telemetry } from './shared/telemetry/telemetry'
47+ import { AuthStatus , AuthUserState , telemetry } from './shared/telemetry/telemetry'
4748import { Auth , SessionSeparationPrompt } from './auth/auth'
49+ import { getTelemetryMetadataForConn } from './auth/connection'
4850import { registerSubmitFeedback } from './feedback/vue/submitFeedback'
49- import { activateCommon , deactivateCommon , emitUserState } from './extension'
51+ import { activateCommon , deactivateCommon } from './extension'
5052import { learnMoreAmazonQCommand , qExtensionPageCommand , dismissQTree } from './amazonq/explorer/amazonQChildrenNodes'
5153import { AuthUtil , codeWhispererCoreScopes , isPreviousQUser } from './codewhisperer/util/authUtil'
5254import { installAmazonQExtension } from './codewhisperer/commands/basicCommands'
5355import { isExtensionInstalled , VSCODE_EXTENSION_ID } from './shared/utilities'
54- import { ExtensionUse , initializeCredentialsProviderManager } from './auth/utils'
56+ import { ExtensionUse , getAuthFormIdsFromConnection , initializeCredentialsProviderManager } from './auth/utils'
5557import { ExtStartUpSources } from './shared/telemetry'
5658import { activate as activateThreatComposerEditor } from './threatComposer/activation'
5759import { isSsoConnection , hasScopes } from './auth/connection'
5860import { CrashMonitoring , setContext } from './shared'
61+ import { AuthFormId } from './login/webview/vue/types'
5962
6063let localize : nls . LocalizeFunc
6164
@@ -231,7 +234,14 @@ export async function activate(context: vscode.ExtensionContext) {
231234 globals . telemetry . assertPassiveTelemetry ( globals . didReload )
232235 }
233236
234- await emitUserState ( )
237+ const authState = await getAuthState ( )
238+ telemetry . auth_userState . emit ( {
239+ passive : true ,
240+ source : ExtensionUse . instance . sourceForTelemetry ( ) ,
241+ ...authState ,
242+ } )
243+
244+ await activateNotifications ( context , authState , getAuthState )
235245 } catch ( error ) {
236246 const stacktrace = ( error as Error ) . stack ?. split ( '\n' )
237247 // truncate if the stacktrace is unusually long
@@ -322,3 +332,36 @@ function recordToolkitInitialization(activationStartedOn: number, settingsValid:
322332 logger ?. error ( err as Error )
323333 }
324334}
335+
336+ async function getAuthState ( ) : Promise < Omit < AuthUserState , 'source' > > {
337+ let authStatus : AuthStatus = 'notConnected'
338+ const enabledConnections : Set < AuthFormId > = new Set ( )
339+ const enabledScopes : Set < string > = new Set ( )
340+ if ( Auth . instance . hasConnections ) {
341+ authStatus = 'expired'
342+ ; ( await Auth . instance . listConnections ( ) ) . forEach ( ( conn ) => {
343+ const state = Auth . instance . getConnectionState ( conn )
344+ if ( state === 'valid' ) {
345+ authStatus = 'connected'
346+ }
347+
348+ getAuthFormIdsFromConnection ( conn ) . forEach ( ( id ) => enabledConnections . add ( id ) )
349+ if ( isSsoConnection ( conn ) ) {
350+ conn . scopes ?. forEach ( ( s ) => enabledScopes . add ( s ) )
351+ }
352+ } )
353+ }
354+
355+ // There may be other SSO connections in toolkit, but there is no use case for
356+ // displaying registration info for non-active connections at this time.
357+ const activeConn = Auth . instance . activeConnection
358+ if ( activeConn ?. type === 'sso' ) {
359+ telemetry . record ( await getTelemetryMetadataForConn ( activeConn ) )
360+ }
361+
362+ return {
363+ authStatus,
364+ authEnabledConnections : [ ...enabledConnections ] . sort ( ) . join ( ',' ) ,
365+ authScopes : [ ...enabledScopes ] . sort ( ) . join ( ',' ) ,
366+ }
367+ }
0 commit comments