Skip to content

Conversation

@gtaylor
Copy link
Contributor

@gtaylor gtaylor commented Apr 3, 2025

Context

Continuing the work outlined in the How to configure Roo from outside of Roo? Discord thread, this PR adds several profile management functions to the Roo extension's exported API:

  • createProfile(name: string)
  • getProfiles(): string[]
  • setActiveProfile(name: string): Promise<void>
  • getActiveProfile(): string | undefined
  • deleteProfile(name: string): Promise<void>

I've tested all of these functions against our WIP Roo Configurator extension.

Implementation

Most of the changes of substance are in api.ts and build on the recent work to improve the configuration APIs.

I'm using names instead of profile IDs since the settings JSON seems to use them for specifying current active profile.

How to Test

Create a custom extension that calls these APIs and do something like this:

npm run build && code --uninstall-extension rooveterinaryinc.roo-cline && code --install-extension bin/roo-cline-3.11.4.vsix

Important

Adds profile management functions to the API, enabling creation, retrieval, activation, and deletion of profiles, with updates to RooCodeAPI interface and generateId method.

  • API Enhancements:
    • Adds profile management functions to API class in api.ts: createProfile, getProfiles, setActiveProfile, getActiveProfile, deleteProfile.
    • Functions handle profile creation, retrieval, activation, and deletion by name.
  • Interface Updates:
    • Updates RooCodeAPI interface in interface.ts and roo-code.d.ts to include new profile management functions.
  • Miscellaneous:
    • Changes generateId method in ProviderSettingsManager.ts to public to support profile ID generation.

This description was created by Ellipsis for d299739. It will automatically update as commits are pushed.

@gtaylor gtaylor requested review from cte and mrubens as code owners April 3, 2025 05:25
@changeset-bot
Copy link

changeset-bot bot commented Apr 3, 2025

⚠️ No Changeset found

Latest commit: d299739

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Apr 3, 2025
}

private generateId() {
public generateId() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exposing generateId() as public may allow external misuse. Consider documenting its intended use and, if IDs are security-sensitive, using a more robust method (e.g., crypto.randomUUID()).

public async createProfile(name: string): Promise<string> {
// Input validation
if (!name || !name.trim()) {
throw new Error("Profile name cannot be empty")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error messages in createProfile are user-facing. Consider internationalizing these strings (e.g., using i18next) to adhere to our standards.

Suggested change
throw new Error("Profile name cannot be empty")
throw new Error(i18next.t('error.profileNameEmpty'))

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure we need to worry about this for the API

public async createProfile(name: string): Promise<string> {
// Input validation
if (!name || !name.trim()) {
throw new Error("Profile name cannot be empty")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When checking for existing profiles, an error is thrown using a literal string. Please internationalize this message as well.

Suggested change
throw new Error("Profile name cannot be empty")
throw new Error(i18n.t('error.profileNameEmpty'))


const profile = profiles.find((p) => p.name === name)
if (!profile) {
throw new Error(`Profile with name "${name}" does not exist`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In setActiveProfile, the error message is hard-coded. Consider using internationalized strings for consistency with our development standards.

return this.getConfiguration().currentApiConfigName
}

public async deleteProfile(name: string): Promise<void> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The deleteProfile method throws user-facing errors and resets the active profile without fallback. Consider internationalizing the error and, if appropriate, selecting a different active profile rather than setting it to undefined.

Copy link
Collaborator

@mrubens mrubens Apr 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the API case is it better to have no active profile after deleting than to switch to another one like we do in the extension?

@dosubot dosubot bot added the enhancement New feature or request label Apr 3, 2025
Copy link
Collaborator

@mrubens mrubens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. What do you think @cte?

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Apr 3, 2025
const currentSettings = this.getConfiguration()
const profiles = currentSettings.listApiConfigMeta || []

if (profiles.some((profile) => profile.name === name)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a huge deal, but we might want to improve / expand the ProviderSettingsManager interface and just proxy these calls through to that object. It already has a few things you could use like fetching a profile by name or id. In general the current implementation seems fine though.

@cte
Copy link
Collaborator

cte commented Apr 3, 2025

Looks good to me. What do you think @cte?

Left one comment about pushing more of the logic into ProviderSettingsManager, but we can clean that up later.

@mrubens mrubens merged commit a3e6c91 into RooCodeInc:main Apr 3, 2025
21 checks passed
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Apr 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants