@@ -344,7 +344,7 @@ enum ChatSetupStep {
344
344
Running
345
345
}
346
346
347
- class ChatSetupModel extends Disposable {
347
+ class ChatSetupController extends Disposable {
348
348
349
349
private readonly _onDidChange = this . _register ( new Emitter < void > ( ) ) ;
350
350
readonly onDidChange = this . _onDidChange . event ;
@@ -358,7 +358,16 @@ class ChatSetupModel extends Disposable {
358
358
return this . entitlementResolver . entitlement ;
359
359
}
360
360
361
- constructor ( private readonly entitlementResolver : ChatSetupEntitlementResolver ) {
361
+ constructor (
362
+ private readonly entitlementResolver : ChatSetupEntitlementResolver ,
363
+ @ITelemetryService private readonly telemetryService : ITelemetryService ,
364
+ @IAuthenticationService private readonly authenticationService : IAuthenticationService ,
365
+ @IInstantiationService private readonly instantiationService : IInstantiationService ,
366
+ @IViewsService private readonly viewsService : IViewsService ,
367
+ @IExtensionsWorkbenchService private readonly extensionsWorkbenchService : IExtensionsWorkbenchService ,
368
+ @IProductService private readonly productService : IProductService ,
369
+ @ILogService private readonly logService : ILogService
370
+ ) {
362
371
super ( ) ;
363
372
364
373
this . registerListeners ( ) ;
@@ -376,6 +385,86 @@ class ChatSetupModel extends Disposable {
376
385
this . _step = step ;
377
386
this . _onDidChange . fire ( ) ;
378
387
}
388
+
389
+ async setup ( enableTelemetry : boolean | undefined , enableDetection : boolean | undefined ) : Promise < void > {
390
+ this . setStep ( ChatSetupStep . Running ) ;
391
+ try {
392
+ await this . doSetup ( enableTelemetry , enableDetection ) ;
393
+ } finally {
394
+ this . setStep ( ChatSetupStep . Initial ) ;
395
+ }
396
+ }
397
+
398
+ private async doSetup ( enableTelemetry : boolean | undefined , enableDetection : boolean | undefined ) : Promise < void > {
399
+ let session : AuthenticationSession | undefined ;
400
+ if ( this . entitlement === ChatEntitlement . Unknown ) {
401
+ session = await this . signIn ( ) ;
402
+ if ( ! session ) {
403
+ return ; // user cancelled
404
+ }
405
+ }
406
+
407
+ return this . install ( session , enableTelemetry , enableDetection ) ;
408
+ }
409
+
410
+ private async signIn ( ) : Promise < AuthenticationSession | undefined > {
411
+ let session : AuthenticationSession | undefined ;
412
+ try {
413
+ showChatView ( this . viewsService ) ;
414
+ session = await this . authenticationService . createSession ( defaultChat . providerId , defaultChat . providerScopes [ 0 ] ) ;
415
+ } catch ( error ) {
416
+ // noop
417
+ }
418
+
419
+ if ( ! session ) {
420
+ this . telemetryService . publicLog2 < InstallChatEvent , InstallChatClassification > ( 'commandCenter.chatInstall' , { installResult : 'failedNotSignedIn' , signedIn : false } ) ;
421
+ }
422
+
423
+ return session ;
424
+ }
425
+
426
+ private async install ( session : AuthenticationSession | undefined , enableTelemetry : boolean | undefined , enableDetection : boolean | undefined ) : Promise < void > {
427
+ const signedIn = ! ! session ;
428
+ const activeElement = getActiveElement ( ) ;
429
+
430
+ let installResult : 'installed' | 'cancelled' | 'failedInstall' ;
431
+ try {
432
+ showChatView ( this . viewsService ) ;
433
+
434
+ if ( this . entitlement !== ChatEntitlement . Unavailable ) {
435
+ const body = {
436
+ public_code_suggestions : enableDetection ? 'enabled' : 'disabled' ,
437
+ restricted_telemetry : enableTelemetry ? 'enabled' : 'disabled'
438
+ } ;
439
+ this . logService . trace ( `[chat setup] install: signing up to limited SKU with ${ JSON . stringify ( body ) } ` ) ;
440
+
441
+ const response = await this . instantiationService . invokeFunction ( accessor => ChatSetupRequestHelper . request ( accessor , defaultChat . entitlementSignupLimitedUrl , 'POST' , body , session , CancellationToken . None ) ) ;
442
+ if ( response && this . logService . getLevel ( ) === LogLevel . Trace ) {
443
+ this . logService . trace ( `[chat setup] install: response from signing up to limited SKU ${ JSON . stringify ( await asText ( response ) ) } ` ) ;
444
+ }
445
+ } else {
446
+ this . logService . trace ( '[chat setup] install: not signing up to limited SKU' ) ;
447
+ }
448
+
449
+ await this . extensionsWorkbenchService . install ( defaultChat . extensionId , {
450
+ enable : true ,
451
+ isMachineScoped : false ,
452
+ installPreReleaseVersion : this . productService . quality !== 'stable'
453
+ } , ChatViewId ) ;
454
+
455
+ installResult = 'installed' ;
456
+ } catch ( error ) {
457
+ this . logService . trace ( `[chat setup] install: error ${ error } ` ) ;
458
+
459
+ installResult = isCancellationError ( error ) ? 'cancelled' : 'failedInstall' ;
460
+ }
461
+
462
+ this . telemetryService . publicLog2 < InstallChatEvent , InstallChatClassification > ( 'commandCenter.chatInstall' , { installResult, signedIn } ) ;
463
+
464
+ if ( activeElement === getActiveElement ( ) ) {
465
+ ( await showChatView ( this . viewsService ) ) ?. focusInput ( ) ;
466
+ }
467
+ }
379
468
}
380
469
381
470
class ChatSetupWelcomeContent extends Disposable {
@@ -391,21 +480,16 @@ class ChatSetupWelcomeContent extends Disposable {
391
480
392
481
readonly element = $ ( '.chat-setup-view' ) ;
393
482
394
- private readonly model : ChatSetupModel ;
483
+ private readonly controller : ChatSetupController ;
395
484
396
485
constructor (
397
486
entitlementResolver : ChatSetupEntitlementResolver ,
398
487
@ITelemetryService private readonly telemetryService : ITelemetryService ,
399
- @IAuthenticationService private readonly authenticationService : IAuthenticationService ,
400
- @IInstantiationService private readonly instantiationService : IInstantiationService ,
401
- @IViewsService private readonly viewsService : IViewsService ,
402
- @IExtensionsWorkbenchService private readonly extensionsWorkbenchService : IExtensionsWorkbenchService ,
403
- @IProductService private readonly productService : IProductService ,
404
- @ILogService private readonly logService : ILogService ,
488
+ @IInstantiationService private readonly instantiationService : IInstantiationService
405
489
) {
406
490
super ( ) ;
407
491
408
- this . model = this . _register ( new ChatSetupModel ( entitlementResolver ) ) ;
492
+ this . controller = this . _register ( instantiationService . createInstance ( ChatSetupController , entitlementResolver ) ) ;
409
493
410
494
this . create ( ) ;
411
495
}
@@ -429,23 +513,14 @@ class ChatSetupWelcomeContent extends Disposable {
429
513
// Setup Button
430
514
const buttonRow = this . element . appendChild ( $ ( 'p' ) ) ;
431
515
const button = this . _register ( new Button ( buttonRow , { ...defaultButtonStyles , supportIcons : true } ) ) ;
432
-
433
- this . _register ( button . onDidClick ( async ( ) => {
434
- this . model . setStep ( ChatSetupStep . Running ) ;
435
-
436
- try {
437
- await this . setup ( telemetryCheckbox ?. checked , detectionCheckbox ?. checked ) ;
438
- } finally {
439
- this . model . setStep ( ChatSetupStep . Initial ) ;
440
- }
441
- } ) ) ;
516
+ this . _register ( button . onDidClick ( ( ) => this . controller . setup ( telemetryCheckbox ?. checked , detectionCheckbox ?. checked ) ) ) ;
442
517
443
518
// Footer
444
519
const footer = localize ( { key : 'privacyFooter' , comment : [ '{Locked="]({0})"}' ] } , "By proceeding you agree to our [privacy statement]({0}). You can [learn more]({1}) about {2}." , defaultChat . privacyStatementUrl , defaultChat . documentationUrl , defaultChat . name ) ;
445
520
this . element . appendChild ( $ ( 'p' ) ) . appendChild ( this . _register ( markdown . render ( new MarkdownString ( footer , { isTrusted : true } ) ) ) . element ) ;
446
521
447
522
// Update based on model state
448
- this . _register ( Event . runAndSubscribe ( this . model . onDidChange , ( ) => this . update ( [ limitedSkuHeaderElement , telemetryContainer , detectionContainer ] , [ telemetryCheckbox , detectionCheckbox ] , button ) ) ) ;
523
+ this . _register ( Event . runAndSubscribe ( this . controller . onDidChange , ( ) => this . update ( [ limitedSkuHeaderElement , telemetryContainer , detectionContainer ] , [ telemetryCheckbox , detectionCheckbox ] , button ) ) ) ;
449
524
}
450
525
451
526
private createCheckBox ( label : string , checked : boolean ) : { container : HTMLElement ; checkbox : Checkbox } {
@@ -464,96 +539,28 @@ class ChatSetupWelcomeContent extends Disposable {
464
539
return { container, checkbox } ;
465
540
}
466
541
467
- private update ( limitedContainers : HTMLElement [ ] , checkboxes : Checkbox [ ] , button : Button , ) : void {
468
- if ( this . model . step === ChatSetupStep . Running ) {
469
- button . enabled = false ;
470
- button . label = localize ( 'setupChatInstalling' , "$(loading~spin) Completing Setup..." ) ;
471
-
472
- for ( const checkbox of checkboxes ) {
473
- checkbox . disable ( ) ;
474
- }
475
- } else {
476
- setVisibility ( this . model . entitlement !== ChatEntitlement . Unavailable , ...limitedContainers ) ;
477
-
478
- button . enabled = true ;
479
- button . label = this . model . entitlement === ChatEntitlement . Unknown ?
480
- localize ( 'signInAndSetup' , "Sign in and Complete Setup" ) :
481
- localize ( 'setup' , "Complete Setup" ) ;
482
-
483
- for ( const checkbox of checkboxes ) {
484
- checkbox . enable ( ) ;
485
- }
486
- }
487
- }
488
-
489
- private async setup ( enableTelemetry : boolean | undefined , enableDetection : boolean | undefined ) : Promise < void > {
490
- let session : AuthenticationSession | undefined ;
491
- if ( this . model . entitlement === ChatEntitlement . Unknown ) {
492
- session = await this . signIn ( ) ;
493
- if ( ! session ) {
494
- return ; // user cancelled
495
- }
496
- }
497
-
498
- return this . install ( session , enableTelemetry , enableDetection ) ;
499
- }
500
-
501
- private async signIn ( ) : Promise < AuthenticationSession | undefined > {
502
- let session : AuthenticationSession | undefined ;
503
- try {
504
- showChatView ( this . viewsService ) ;
505
- session = await this . authenticationService . createSession ( defaultChat . providerId , defaultChat . providerScopes [ 0 ] ) ;
506
- } catch ( error ) {
507
- // noop
508
- }
509
-
510
- if ( ! session ) {
511
- this . telemetryService . publicLog2 < InstallChatEvent , InstallChatClassification > ( 'commandCenter.chatInstall' , { installResult : 'failedNotSignedIn' , signedIn : false } ) ;
512
- }
513
-
514
- return session ;
515
- }
516
-
517
- private async install ( session : AuthenticationSession | undefined , enableTelemetry : boolean | undefined , enableDetection : boolean | undefined ) : Promise < void > {
518
- const signedIn = ! ! session ;
519
- const activeElement = getActiveElement ( ) ;
520
-
521
- let installResult : 'installed' | 'cancelled' | 'failedInstall' ;
522
- try {
523
- showChatView ( this . viewsService ) ;
542
+ private update ( limitedContainers : HTMLElement [ ] , limitedCheckboxes : Checkbox [ ] , button : Button ) : void {
543
+ switch ( this . controller . step ) {
544
+ case ChatSetupStep . Initial :
545
+ setVisibility ( this . controller . entitlement !== ChatEntitlement . Unavailable , ...limitedContainers ) ;
524
546
525
- if ( this . model . entitlement !== ChatEntitlement . Unavailable ) {
526
- const body = {
527
- public_code_suggestions : enableDetection ? 'enabled' : 'disabled' ,
528
- restricted_telemetry : enableTelemetry ? 'enabled' : 'disabled'
529
- } ;
530
- this . logService . trace ( `[chat setup] install: signing up to limited SKU with ${ JSON . stringify ( body ) } ` ) ;
547
+ button . enabled = true ;
548
+ button . label = this . controller . entitlement === ChatEntitlement . Unknown ?
549
+ localize ( 'signInAndSetup' , "Sign in and Complete Setup" ) :
550
+ localize ( 'setup' , "Complete Setup" ) ;
531
551
532
- const response = await this . instantiationService . invokeFunction ( accessor => ChatSetupRequestHelper . request ( accessor , defaultChat . entitlementSignupLimitedUrl , 'POST' , body , session , CancellationToken . None ) ) ;
533
- if ( response && this . logService . getLevel ( ) === LogLevel . Trace ) {
534
- this . logService . trace ( `[chat setup] install: response from signing up to limited SKU ${ JSON . stringify ( await asText ( response ) ) } ` ) ;
552
+ for ( const checkbox of limitedCheckboxes ) {
553
+ checkbox . enable ( ) ;
535
554
}
536
- } else {
537
- this . logService . trace ( '[chat setup] install: not signing up to limited SKU' ) ;
538
- }
539
-
540
- await this . extensionsWorkbenchService . install ( defaultChat . extensionId , {
541
- enable : true ,
542
- isMachineScoped : false ,
543
- installPreReleaseVersion : this . productService . quality !== 'stable'
544
- } , ChatViewId ) ;
545
-
546
- installResult = 'installed' ;
547
- } catch ( error ) {
548
- this . logService . trace ( `[chat setup] install: error ${ error } ` ) ;
549
-
550
- installResult = isCancellationError ( error ) ? 'cancelled' : 'failedInstall' ;
551
- }
555
+ break ;
556
+ case ChatSetupStep . Running :
557
+ button . enabled = false ;
558
+ button . label = localize ( 'setupChatInstalling' , "$(loading~spin) Completing Setup..." ) ;
552
559
553
- this . telemetryService . publicLog2 < InstallChatEvent , InstallChatClassification > ( 'commandCenter.chatInstall' , { installResult , signedIn } ) ;
554
-
555
- if ( activeElement === getActiveElement ( ) ) {
556
- ( await showChatView ( this . viewsService ) ) ?. focusInput ( ) ;
560
+ for ( const checkbox of limitedCheckboxes ) {
561
+ checkbox . disable ( ) ;
562
+ }
563
+ break ;
557
564
}
558
565
}
559
566
}
0 commit comments