@@ -178,90 +178,6 @@ export class API extends EventEmitter<RooCodeEvents> implements RooCodeAPI {
178178 await this . sidebarProvider . postMessageToWebview ( { type : "invoke" , invoke : "secondaryButtonClick" } )
179179 }
180180
181- public getConfiguration ( ) {
182- return this . sidebarProvider . getValues ( )
183- }
184-
185- public async setConfiguration ( values : RooCodeSettings ) {
186- await this . sidebarProvider . setValues ( values )
187- await this . sidebarProvider . providerSettingsManager . saveConfig ( values . currentApiConfigName || "default" , values )
188- await this . sidebarProvider . postStateToWebview ( )
189- }
190-
191- public async createProfile ( name : string ) {
192- if ( ! name || ! name . trim ( ) ) {
193- throw new Error ( "Profile name cannot be empty" )
194- }
195-
196- const currentSettings = this . getConfiguration ( )
197- const profiles = currentSettings . listApiConfigMeta || [ ]
198-
199- if ( profiles . some ( ( profile ) => profile . name === name ) ) {
200- throw new Error ( `A profile with the name "${ name } " already exists` )
201- }
202-
203- const id = this . sidebarProvider . providerSettingsManager . generateId ( )
204-
205- await this . setConfiguration ( {
206- ...currentSettings ,
207- listApiConfigMeta : [
208- ...profiles ,
209- {
210- id,
211- name : name . trim ( ) ,
212- apiProvider : "openai" as const ,
213- } ,
214- ] ,
215- } )
216-
217- return id
218- }
219-
220- private getProfilesMeta ( ) {
221- return this . getConfiguration ( ) . listApiConfigMeta || [ ]
222- }
223-
224- public getProfiles ( ) {
225- return this . getProfilesMeta ( ) . map ( ( profile ) => profile . name )
226- }
227-
228- public hasProfile ( name : string ) : boolean {
229- return ! ! ( this . getConfiguration ( ) . listApiConfigMeta || [ ] ) . find ( ( profile ) => profile . name === name )
230- }
231-
232- public async setActiveProfile ( name : string ) {
233- if ( ! this . hasProfile ( name ) ) {
234- throw new Error ( `Profile with name "${ name } " does not exist` )
235- }
236-
237- await this . sidebarProvider . activateProviderProfile ( { name } )
238- }
239-
240- public getActiveProfile ( ) {
241- return this . getConfiguration ( ) . currentApiConfigName
242- }
243-
244- public async deleteProfile ( name : string ) {
245- const currentSettings = this . getConfiguration ( )
246- const listApiConfigMeta = this . getProfilesMeta ( )
247- const targetIndex = listApiConfigMeta . findIndex ( ( p ) => p . name === name )
248-
249- if ( targetIndex === - 1 ) {
250- throw new Error ( `Profile with name "${ name } " does not exist` )
251- }
252-
253- const profileToDelete = listApiConfigMeta [ targetIndex ]
254- listApiConfigMeta . splice ( targetIndex , 1 )
255-
256- // If we're deleting the active profile, clear the currentApiConfigName.
257- const currentApiConfigName =
258- currentSettings . currentApiConfigName === profileToDelete . name
259- ? undefined
260- : currentSettings . currentApiConfigName
261-
262- await this . setConfiguration ( { ...currentSettings , listApiConfigMeta, currentApiConfigName } )
263- }
264-
265181 public isReady ( ) {
266182 return this . sidebarProvider . viewLaunched
267183 }
@@ -327,4 +243,92 @@ export class API extends EventEmitter<RooCodeEvents> implements RooCodeAPI {
327243 this . logfile = undefined
328244 }
329245 }
246+
247+ // Global Settings Management
248+
249+ public getConfiguration ( ) {
250+ return this . sidebarProvider . getValues ( )
251+ }
252+
253+ public async setConfiguration ( values : RooCodeSettings ) {
254+ await this . sidebarProvider . contextProxy . setValues ( values )
255+ await this . sidebarProvider . providerSettingsManager . saveConfig ( values . currentApiConfigName || "default" , values )
256+ await this . sidebarProvider . postStateToWebview ( )
257+ }
258+
259+ // Provider Profile Management
260+
261+ private getProfilesMeta ( ) {
262+ return this . getConfiguration ( ) . listApiConfigMeta || [ ]
263+ }
264+
265+ public getProfiles ( ) {
266+ return this . getProfilesMeta ( ) . map ( ( profile ) => profile . name )
267+ }
268+
269+ public hasProfile ( name : string ) : boolean {
270+ return ! ! ( this . getConfiguration ( ) . listApiConfigMeta || [ ] ) . find ( ( profile ) => profile . name === name )
271+ }
272+
273+ public async createProfile ( name : string ) {
274+ if ( ! name || ! name . trim ( ) ) {
275+ throw new Error ( "Profile name cannot be empty" )
276+ }
277+
278+ const currentSettings = this . getConfiguration ( )
279+ const profiles = currentSettings . listApiConfigMeta || [ ]
280+
281+ if ( profiles . some ( ( profile ) => profile . name === name ) ) {
282+ throw new Error ( `A profile with the name "${ name } " already exists` )
283+ }
284+
285+ const id = this . sidebarProvider . providerSettingsManager . generateId ( )
286+
287+ await this . setConfiguration ( {
288+ ...currentSettings ,
289+ listApiConfigMeta : [
290+ ...profiles ,
291+ {
292+ id,
293+ name : name . trim ( ) ,
294+ apiProvider : "openai" as const ,
295+ } ,
296+ ] ,
297+ } )
298+
299+ return id
300+ }
301+
302+ public async deleteProfile ( name : string ) {
303+ const currentSettings = this . getConfiguration ( )
304+ const listApiConfigMeta = this . getProfilesMeta ( )
305+ const targetIndex = listApiConfigMeta . findIndex ( ( p ) => p . name === name )
306+
307+ if ( targetIndex === - 1 ) {
308+ throw new Error ( `Profile with name "${ name } " does not exist` )
309+ }
310+
311+ const profileToDelete = listApiConfigMeta [ targetIndex ]
312+ listApiConfigMeta . splice ( targetIndex , 1 )
313+
314+ // If we're deleting the active profile, clear the currentApiConfigName.
315+ const currentApiConfigName =
316+ currentSettings . currentApiConfigName === profileToDelete . name
317+ ? undefined
318+ : currentSettings . currentApiConfigName
319+
320+ await this . setConfiguration ( { ...currentSettings , listApiConfigMeta, currentApiConfigName } )
321+ }
322+
323+ public getActiveProfile ( ) : string | undefined {
324+ return this . getConfiguration ( ) . currentApiConfigName
325+ }
326+
327+ public async setActiveProfile ( name : string ) {
328+ if ( ! this . hasProfile ( name ) ) {
329+ throw new Error ( `Profile with name "${ name } " does not exist` )
330+ }
331+
332+ await this . sidebarProvider . activateProviderProfile ( { name } )
333+ }
330334}
0 commit comments