@@ -163,6 +163,82 @@ export class API extends EventEmitter<RooCodeEvents> implements RooCodeAPI {
163163 await this . sidebarProvider . postStateToWebview ( )
164164 }
165165
166+ public async createProfile ( name : string ) : Promise < string > {
167+ // Input validation
168+ if ( ! name || ! name . trim ( ) ) {
169+ throw new Error ( "Profile name cannot be empty" )
170+ }
171+
172+ const currentSettings = this . getConfiguration ( )
173+ const profiles = currentSettings . listApiConfigMeta || [ ]
174+
175+ if ( profiles . some ( ( profile ) => profile . name === name ) ) {
176+ throw new Error ( `A profile with the name "${ name } " already exists` )
177+ }
178+
179+ // Generate unique ID and create profile
180+ const id = this . sidebarProvider . providerSettingsManager . generateId ( )
181+ const newProfile = {
182+ id,
183+ name : name . trim ( ) ,
184+ apiProvider : "openai" as const , // Type assertion for better type safety
185+ }
186+
187+ // Update configuration with new profile
188+ await this . setConfiguration ( {
189+ ...currentSettings ,
190+ listApiConfigMeta : [ ...profiles , newProfile ] ,
191+ } )
192+ return id
193+ }
194+
195+ public getProfiles ( ) : string [ ] {
196+ const profiles = this . getConfiguration ( ) . listApiConfigMeta || [ ]
197+ return profiles . map ( ( profile ) => profile . name )
198+ }
199+
200+ public async setActiveProfile ( name : string ) : Promise < void > {
201+ const currentSettings = this . getConfiguration ( )
202+ const profiles = currentSettings . listApiConfigMeta || [ ]
203+
204+ const profile = profiles . find ( ( p ) => p . name === name )
205+ if ( ! profile ) {
206+ throw new Error ( `Profile with name "${ name } " does not exist` )
207+ }
208+
209+ await this . setConfiguration ( {
210+ ...currentSettings ,
211+ currentApiConfigName : profile . name ,
212+ } )
213+ }
214+
215+ public getActiveProfile ( ) : string | undefined {
216+ return this . getConfiguration ( ) . currentApiConfigName
217+ }
218+
219+ public async deleteProfile ( name : string ) : Promise < void > {
220+ const currentSettings = this . getConfiguration ( )
221+ const profiles = currentSettings . listApiConfigMeta || [ ]
222+ const targetIndex = profiles . findIndex ( ( p ) => p . name === name )
223+ if ( targetIndex === - 1 ) {
224+ throw new Error ( `Profile with name "${ name } " does not exist` )
225+ }
226+
227+ const profileToDelete = profiles [ targetIndex ]
228+ profiles . splice ( targetIndex , 1 )
229+
230+ // If we're deleting the active profile, clear the currentApiConfigName
231+ const newSettings : RooCodeSettings = {
232+ ...currentSettings ,
233+ listApiConfigMeta : profiles ,
234+ currentApiConfigName :
235+ currentSettings . currentApiConfigName === profileToDelete . name
236+ ? undefined
237+ : currentSettings . currentApiConfigName ,
238+ }
239+ await this . setConfiguration ( newSettings )
240+ }
241+
166242 public isReady ( ) {
167243 return this . sidebarProvider . viewLaunched
168244 }
0 commit comments