91
92
constructor(
94
>
@IChatAgentService private readonly chatAgentService: IChatAgentService,
95
>
@IContextKeyService contextKeyService: IContextKeyService,
96
>
@ILogService private readonly logService: ILogService,
97
>
@IStorageService private readonly storageService: IStorageService,
98
>
@IConfigurationService private readonly configurationService: IConfigurationService,
99
>
@ICustomizationHarnessService private readonly customizationHarnessService: ICustomizationHarnessService,
100
>
) {
101
>
super();
102
>
103
>
const sessionType = getChatSessionType(sessionResource);
104
>
105
>
this._storageKey = ChatModes.CUSTOM_MODES_STORAGE_KEY_PREFIX + sessionType;
106
>
this.hasCustomModes = ChatContextKeys.Modes.hasCustomChatModes.bindTo(contextKeyService);
107
>
108
>
// Load cached modes from storage first
109
>
this.loadCachedModes();
110
>
111
>
this._pendingRefresh = this.triggerRefresh();
112
>
// When the harness service is the source, also react to its change events for our session type.
113
>
this._register(this.customizationHarnessService.onDidChangeCustomAgents(e => {
114
if (e.sessionType === sessionType) {
115
this._pendingRefresh = this.triggerRefresh();
116
}
118
>
this._register(this.storageService.onWillSaveState(() => this.saveCachedModes()));
119
>
120
>
// Builtin mode availability depends on configuration policy and tools-agent availability.
121
>
this._register(this.configurationService.onDidChangeConfiguration(e => {
122
if (e.affectsConfiguration(ChatConfiguration.AgentEnabled)) {
123
this._onDidChange.fire();
124
}
126
>
let didHaveToolsAgent = this.chatAgentService.hasToolsAgent;
127
>
this._register(this.chatAgentService.onDidChangeAgents(() => {
128
if (didHaveToolsAgent !== this.chatAgentService.hasToolsAgent) {
129
didHaveToolsAgent = this.chatAgentService.hasToolsAgent;
130
this._onDidChange.fire();
131
}
133
>
}
134
135
get builtin(): readonly IChatMode[] {