@@ -66,6 +66,7 @@ import { ITelemetryService } from '../../../../platform/telemetry/common/telemet
66
66
import { IThemeService } from '../../../../platform/theme/common/themeService.js' ;
67
67
import { ISharedWebContentExtractorService } from '../../../../platform/webContentExtractor/common/webContentExtractor.js' ;
68
68
import { ResourceLabels } from '../../../browser/labels.js' ;
69
+ import { IWorkbenchAssignmentService } from '../../../services/assignment/common/assignmentService.js' ;
69
70
import { ACTIVE_GROUP , IEditorService , SIDE_GROUP } from '../../../services/editor/common/editorService.js' ;
70
71
import { AccessibilityVerbositySettingId } from '../../accessibility/browser/accessibilityConfiguration.js' ;
71
72
import { AccessibilityCommandId } from '../../accessibility/common/accessibilityCommands.js' ;
@@ -123,6 +124,7 @@ interface IChatInputPartOptions {
123
124
renderWorkingSet ?: boolean ;
124
125
enableImplicitContext ?: boolean ;
125
126
supportsChangingModes ?: boolean ;
127
+ widgetViewKindTag : string ;
126
128
}
127
129
128
130
export interface IWorkingSetEntry {
@@ -355,6 +357,7 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
355
357
@IChatAgentService private readonly agentService : IChatAgentService ,
356
358
@IChatService private readonly chatService : IChatService ,
357
359
@ISharedWebContentExtractorService private readonly sharedWebExtracterService : ISharedWebContentExtractorService ,
360
+ @IWorkbenchAssignmentService private readonly experimentService : IWorkbenchAssignmentService ,
358
361
) {
359
362
super ( ) ;
360
363
@@ -538,7 +541,7 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
538
541
return localize ( 'chatInput' , "Chat Input" ) ;
539
542
}
540
543
541
- initForNewChatModel ( state : IChatViewState ) : void {
544
+ initForNewChatModel ( state : IChatViewState , modelIsEmpty : boolean ) : void {
542
545
this . history = this . loadHistory ( ) ;
543
546
this . history . add ( {
544
547
text : state . inputValue ?? this . history . current ( ) . text ,
@@ -556,6 +559,59 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
556
559
} else if ( this . location === ChatAgentLocation . EditingSession ) {
557
560
this . setChatMode ( ChatMode . Edit ) ;
558
561
}
562
+
563
+ if ( modelIsEmpty ) {
564
+ const storageKey = this . getDefaultModeExperimentStorageKey ( ) ;
565
+ const hasSetDefaultMode = this . storageService . getBoolean ( storageKey , StorageScope . WORKSPACE , false ) ;
566
+ if ( ! hasSetDefaultMode ) {
567
+ Promise . all ( [
568
+ this . experimentService . getTreatment ( 'chat.defaultMode' ) ,
569
+ this . experimentService . getTreatment ( 'chat.defaultLanguageModel' ) ,
570
+ ] ) . then ( ( [ defaultModeTreatment , defaultLanguageModelTreatment ] ) => {
571
+ if ( typeof defaultModeTreatment === 'string' ) {
572
+ this . storageService . store ( storageKey , true , StorageScope . WORKSPACE , StorageTarget . MACHINE ) ;
573
+ const defaultMode = validateChatMode ( defaultModeTreatment ) ;
574
+ if ( defaultMode ) {
575
+ this . logService . trace ( `Applying default mode from experiment: ${ defaultMode } ` ) ;
576
+ this . setChatMode ( defaultMode ) ;
577
+ this . checkModelSupported ( ) ;
578
+ }
579
+ }
580
+
581
+ if ( typeof defaultLanguageModelTreatment === 'string' && this . _currentMode === ChatMode . Agent ) {
582
+ this . storageService . store ( storageKey , true , StorageScope . WORKSPACE , StorageTarget . MACHINE ) ;
583
+ this . logService . trace ( `Applying default language model from experiment: ${ defaultLanguageModelTreatment } ` ) ;
584
+ this . setExpModelOrWait ( defaultLanguageModelTreatment ) ;
585
+ }
586
+ } ) ;
587
+ }
588
+ }
589
+ }
590
+
591
+ private setExpModelOrWait ( modelId : string ) {
592
+ const model = this . languageModelsService . lookupLanguageModel ( modelId ) ;
593
+ if ( model ) {
594
+ this . setCurrentLanguageModel ( { metadata : model , identifier : modelId } ) ;
595
+ this . checkModelSupported ( ) ;
596
+ this . _waitForPersistedLanguageModel . clear ( ) ;
597
+ } else {
598
+ this . _waitForPersistedLanguageModel . value = this . languageModelsService . onDidChangeLanguageModels ( e => {
599
+ const model = e . added ?. find ( m => m . identifier === modelId ) ;
600
+ if ( model ) {
601
+ this . _waitForPersistedLanguageModel . clear ( ) ;
602
+
603
+ if ( model . metadata . isUserSelectable ) {
604
+ this . setCurrentLanguageModel ( { metadata : model . metadata , identifier : modelId } ) ;
605
+ this . checkModelSupported ( ) ;
606
+ }
607
+ }
608
+ } ) ;
609
+ }
610
+ }
611
+
612
+ private getDefaultModeExperimentStorageKey ( ) : string {
613
+ const tag = this . options . widgetViewKindTag ;
614
+ return `chat.${ tag } .hasSetDefaultModeByExperiment` ;
559
615
}
560
616
561
617
logInputHistory ( ) : void {
0 commit comments