Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Jul 25, 2025

This PR adds support for organizations to define default provider settings that are automatically applied when users switch to a provider for the first time.

Changes

  • Added defaultProviderSettings field to organization settings schema
  • Updated CloudService to expose organization settings including defaults
  • Modified state management to pass organization defaults to the UI
  • Implemented logic to apply defaults when creating new profiles or switching providers
  • Added comprehensive unit tests for schema changes and message handler behavior

How it works

  1. Organizations can define default settings for each provider (API keys, model selections, etc.)
  2. When a user switches to a provider for the first time, the defaults are automatically applied
  3. User-provided values always take precedence over organization defaults
  4. Only empty fields are populated with defaults to avoid overwriting existing configurations

Testing

  • Added unit tests for schema validation
  • Added tests for webview message handler behavior
  • All existing tests pass
  • Type checking and linting pass

Important

Adds support for organization-defined default provider settings, applied when users switch providers, with schema, state, and UI updates.

  • Behavior:
    • Adds defaultProviderSettings to organization settings schema in cloud.ts.
    • Updates CloudService in CloudService.ts to expose organization settings including defaults.
    • Modifies webviewMessageHandler.ts to apply defaults when creating new profiles or switching providers.
    • UI in ApiOptions.tsx applies organization defaults when provider changes.
  • Testing:
    • Adds unit tests in cloud-schema.test.ts for schema validation.
    • Adds tests in webviewMessageHandler-orgDefaults.spec.ts for message handler behavior.
  • State Management:
    • Updates ExtensionStateContext.tsx to include organizationDefaultProviderSettings in state.
    • Passes organization defaults to UI components via ExtensionStateContext.

This description was created by Ellipsis for 83b3cc3. You can customize this summary. It will automatically update as commits are pushed.

@roomote roomote bot requested review from cte and mrubens as code owners July 25, 2025 19:43
@roomote roomote bot requested a review from jr as a code owner July 25, 2025 19:43
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. enhancement New feature or request labels Jul 25, 2025

// Only apply defaults if the current value is undefined or empty
const currentValue = apiConfiguration[key as keyof ProviderSettings]
if (!currentValue || (typeof currentValue === "string" && currentValue.trim() === "")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Avoid using '!currentValue' to check if a field is empty. This check will override valid falsy values (like 0 or false). Instead, explicitly check for undefined or null (e.g., currentValue === undefined || currentValue === null || (typeof currentValue === 'string' && currentValue.trim() === '')).

Suggested change
if (!currentValue || (typeof currentValue === "string" && currentValue.trim() === "")) {
if (currentValue === undefined || currentValue === null || (typeof currentValue === "string" && currentValue.trim() === "")) {

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Jul 25, 2025
@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Jul 28, 2025
@hannesrudolph hannesrudolph added PR - Needs Preliminary Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Jul 28, 2025

// Only apply defaults if the current value is undefined or empty
const currentValue = apiConfiguration[key as keyof ProviderSettings]
if (!currentValue || (typeof currentValue === "string" && currentValue.trim() === "")) {
Copy link
Member

Choose a reason for hiding this comment

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

This falsy value check will incorrectly override valid falsy values. For example, if an organization sets temperature: 0 or a boolean setting to false, these valid values would be replaced with defaults.

Consider using a more explicit check:

if (currentValue === undefined || currentValue === null || (typeof currentValue === "string" && currentValue.trim() === "")) {

This issue was already raised by ellipsis-dev[bot] but hasn't been addressed yet.

// Get organization settings including default provider settings
let organizationDefaultProviderSettings: Record<string, any> = {}
try {
const orgSettings = await CloudService.instance.getOrganizationSettings()
Copy link
Member

Choose a reason for hiding this comment

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

When getOrganizationSettings() fails, the error is logged but organizationDefaultProviderSettings remains an empty object. This silent failure might be confusing for users who expect defaults to be applied.

Consider:

  1. Adding a user-visible notification when organization defaults fail to load
  2. Or propagating partial data if some defaults are available
  3. Or adding a flag to indicate whether defaults were successfully loaded

This would help users understand why their expected defaults aren't being applied.


if (orgDefaults) {
// Apply each default setting from the organization
Object.entries(orgDefaults).forEach(([key, defaultValue]) => {
Copy link
Member

Choose a reason for hiding this comment

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

There's a potential race condition here. When the provider changes, defaults are applied immediately in the same function, but the provider change might trigger other async operations (like fetching available models).

Consider using a useEffect hook to apply defaults after the provider change has been processed:

useEffect(() => {
  const orgDefaults = organizationDefaultProviderSettings?.[apiConfiguration.apiProvider];
  if (orgDefaults && isNewProfile) { // You'd need to track if this is a new profile
    // Apply defaults here
  }
}, [apiConfiguration.apiProvider, organizationDefaultProviderSettings]);

This would ensure defaults are applied at the right time in the component lifecycle.

@daniel-lxs daniel-lxs moved this from PR [Needs Prelim Review] to PR [Changes Requested] in Roo Code Roadmap Jul 28, 2025
@jr jr closed this Jul 28, 2025
@github-project-automation github-project-automation bot moved this from PR [Changes Requested] to Done in Roo Code Roadmap Jul 28, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Jul 28, 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 PR - Needs Preliminary Review size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

5 participants