Skip to content

Conversation

@daniel-lxs
Copy link
Member

@daniel-lxs daniel-lxs commented Aug 29, 2025

Summary

This PR refactors the image generation settings to use a flattened structure instead of nested objects, simplifying the codebase and improving maintainability.

Changes

Core Changes

  • Moved openRouterImageApiKey and imageGenerationSelectedModel from nested imageGenerationSettings object to top-level properties
  • Removed the imageGenerationSettings nested object entirely
  • Added GLOBAL_SECRET_KEYS array to handle global secrets properly
  • Updated SecretState type to include global secret keys

ContextProxy Simplification

  • Removed complex nested secret handling logic (NESTED_SECRET_PATHS, hasNestedSecrets, etc.)
  • Simplified getValue, setValue, and getValues methods
  • Removed extractAndStoreNestedSecrets and mergeNestedSecrets helper functions

Component Updates

  • Updated ImageGenerationSettings component to accept flattened props
  • Updated ExperimentalSettings to pass flattened props
  • Updated SettingsView to handle flattened state structure
  • Fixed all related tests to work with the new structure

Type Fixes

  • Added SecretState to RooCodeSettings type definition to properly handle global secrets
  • Updated ExtensionState type to include openRouterImageApiKey as an optional property

Benefits

  • Eliminates complex nested secret extraction/merging logic
  • Improves code readability and maintainability
  • Reduces potential for runtime errors from object mutations
  • Simplifies state management in UI components

Testing

  • All existing tests have been updated and pass
  • TypeScript compilation succeeds
  • Linting passes with no warnings

Important

Refactor image generation settings to a flattened structure, simplifying code and improving maintainability across components and types.

  • Behavior:
    • Flattened image generation settings by moving openRouterImageApiKey and imageGenerationSelectedModel to top-level properties in global-settings.ts.
    • Removed imageGenerationSettings nested object.
    • Added GLOBAL_SECRET_KEYS for global secrets.
    • Updated SecretState type to include global secret keys.
  • ContextProxy Simplification:
    • Removed nested secret handling logic in ContextProxy.ts.
    • Simplified getValue, setValue, and getValues methods.
    • Removed extractAndStoreNestedSecrets and mergeNestedSecrets functions.
  • Component Updates:
    • Updated ImageGenerationSettings and ExperimentalSettings components to use flattened props.
    • Updated SettingsView to handle flattened state structure.
    • Adjusted related tests in ImageGenerationSettings.spec.tsx.
  • Type Fixes:
    • Updated ExtensionState type in ExtensionMessage.ts to include openRouterImageApiKey and openRouterImageGenerationSelectedModel.
  • Misc:
    • Updated webviewMessageHandler.ts to handle new message types for image generation settings.

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

Copy link
Contributor

@roomote roomote bot left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution! I've reviewed the changes and found several issues that need attention before this can be merged. The refactoring to flatten the image generation settings structure is a good improvement, but there are some critical issues to address.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this intentional? Adding SecretState directly to RooCodeSettings creates a type intersection that might cause confusion. The SecretState type now includes both provider secrets and global secrets. Consider documenting this change or using a more explicit type composition:

Suggested change
export type RooCodeSettings = GlobalSettings & ProviderSettings & SecretState
export type RooCodeSettings = GlobalSettings & ProviderSettings & { openRouterImageApiKey?: string }

Copy link
Contributor

Choose a reason for hiding this comment

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

Could we add JSDoc comments here to explain the distinction between GLOBAL_SECRET_KEYS and SECRET_STATE_KEYS? This would help future maintainers understand why we need two separate arrays for secrets.

Copy link
Contributor

Choose a reason for hiding this comment

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

The cast to any here breaks type safety. Could we update the type definitions to properly include openRouterImageApiKey in the state values type? This suggests the types aren't properly aligned with the actual data structure.

Copy link
Contributor

Choose a reason for hiding this comment

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

For consistency with other model ID fields in the codebase, should this be named imageGenerationModelId instead of imageGenerationSelectedModel?

@roomote
Copy link
Contributor

roomote bot commented Aug 29, 2025

Additional Review Notes

I noticed a couple of additional issues that need attention:

1. Merge Conflicts

The PR currently has merge conflicts that need to be resolved before it can be merged. Please rebase or merge the latest changes from the main branch.

2. Migration Logic

Since this PR removes the nested openRouterImageGenerationSettings structure, existing users who have data stored in the old format will lose their settings. Consider adding migration logic to:

  • Check for existing nested settings on first load
  • Move the values to the new flattened structure
  • Clean up the old nested structure

This could be done in the ContextProxy initialization or in a dedicated migration utility.

3. Test Coverage

While the tests have been updated to work with the new structure, consider adding specific test cases for:

  • Migration from old nested structure to new flattened structure
  • Secret storage and retrieval for the new global secrets
  • Proper type checking for the flattened fields

Overall, this is a good refactoring that simplifies the codebase! Once these issues are addressed, it should be ready to merge.

@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Review] in Roo Code Roadmap Aug 29, 2025
@hannesrudolph hannesrudolph added Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. PR - Needs Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Aug 29, 2025
- Move openRouterImageApiKey and imageGenerationSelectedModel to top-level
- Remove nested imageGenerationSettings object
- Update all dependent components and tests
- Handle secrets properly with GLOBAL_SECRET_KEYS
- Simplify ContextProxy to handle flattened structure
This fixes TypeScript error when setting global secret keys
@daniel-lxs daniel-lxs force-pushed the refactor/flatten-image-generation-settings branch from 5e042fd to 1744d47 Compare August 29, 2025 19:13
- Added openRouterImageApiKey to GlobalSettings schema instead of including all SecretState
- Fixed compilation errors by properly typing the settings
- Updated tests to account for GLOBAL_SECRET_KEYS
- Added migration logic to convert old nested settings to flattened structure
- Added comprehensive tests for migration functionality
- Adjusted test expectations for GLOBAL_SECRET_KEYS.length
- Updated initialize test to check for migration call
- Fixed mock counts to reflect new openRouterImageApiKey secret
@daniel-lxs daniel-lxs marked this pull request as ready for review August 29, 2025 20:57
@daniel-lxs daniel-lxs requested review from cte, jr and mrubens as code owners August 29, 2025 20:57
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Aug 29, 2025

// Image generation settings (experimental) - flattened for simplicity
openRouterImageApiKey: z.string().optional(),
imageGenerationSelectedModel: z.string().optional(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this be openRouterImageGenerationSelectedModel?

Copy link
Member Author

Choose a reason for hiding this comment

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

Should we leave this generic in case we want to add other models from other providers?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah I'm just not sure the right structure to support multiple providers. If we don't care about preserving the key when you switch between them, we might want imageApiProvider, imageApiKey, imageApiModelId?

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Aug 29, 2025
@mrubens mrubens merged commit c3d84d2 into main Aug 29, 2025
13 checks passed
@mrubens mrubens deleted the refactor/flatten-image-generation-settings branch August 29, 2025 22:35
@github-project-automation github-project-automation bot moved this from PR [Needs Review] to Done in Roo Code Roadmap Aug 29, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Aug 29, 2025
mini2s added a commit to zgsm-ai/costrict that referenced this pull request Aug 31, 2025
* Follow symlinks in rooignore checks (RooCodeInc#7405)

* Sonic -> Grok Code Fast (RooCodeInc#7426)

* chore: add changeset for v3.26.0 (RooCodeInc#7428)

* Changeset version bump (RooCodeInc#7429)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Matt Rubens <[email protected]>

* feat: Add Vercel AI Gateway provider integration (RooCodeInc#7396)

Co-authored-by: daniel-lxs <[email protected]>
Co-authored-by: cte <[email protected]>

* feat: Enable on-disk storage for Qdrant vectors and HNSW index (RooCodeInc#7182)

* fix: use anthropic protocol for token counting when using anthropic models via Vercel AI Gateway (RooCodeInc#7433)

- Added condition in getApiProtocol to return 'anthropic' for vercel-ai-gateway when modelId starts with 'anthropic/'
- Added tests for Vercel AI Gateway provider protocol detection

This ensures proper token counting for Anthropic models accessed through Vercel AI Gateway, as Anthropic and OpenAI count tokens differently (Anthropic excludes cache tokens from input count, OpenAI includes them).

* fix: remove duplicate cache display in task header (RooCodeInc#7443)

* Random chat text area cleanup (RooCodeInc#7436)

* Update @roo-code/cloud to enable roomote control for cloud agents (RooCodeInc#7446)

Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>

* Always set remoteControlEnabled to true for cloud agents (RooCodeInc#7448)

* chore: add changeset for v3.26.1 (RooCodeInc#7459)

* feat: show model ID in API configuration dropdown (RooCodeInc#7423)

* feat: update tooltip component to match native VSCode tooltip shadow styling (RooCodeInc#7457)

Co-authored-by: Roo Code <[email protected]>
Co-authored-by: cte <[email protected]>

* Add support for Vercel embeddings (RooCodeInc#7445)

Co-authored-by: daniel-lxs <[email protected]>

* Remove dot before model display (RooCodeInc#7461)

* Update contributors list (RooCodeInc#7109)

Co-authored-by: mrubens <[email protected]>

* Update 3.26.1 changeset (RooCodeInc#7463)

* Changeset version bump (RooCodeInc#7460)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Matt Rubens <[email protected]>

* Add type for RooCodeEventName.TaskSpawned (RooCodeInc#7465)

* fix: hide .rooignore'd files from environment details by default (RooCodeInc#7369)

* fix: change default showRooIgnoredFiles to false to hide ignored files

- Changed default value from true to false across all files
- Updated tests to reflect the new default behavior
- This prevents ignored files from appearing in environment details

Fixes RooCodeInc#7368

* fix: update tests to match new showRooIgnoredFiles default

* fix: update test expectation to match new showRooIgnoredFiles default value

The PR changed the default value of showRooIgnoredFiles from true to false,
so the test needs to expect false instead of true when calling formatFilesList.

---------

Co-authored-by: Roo Code <[email protected]>
Co-authored-by: daniel-lxs <[email protected]>

* fix: exclude browser scroll actions from repetition detection (RooCodeInc#7471)

- Modified ToolRepetitionDetector to skip repetition detection for browser_action scroll_down and scroll_up actions
- Added isBrowserScrollAction() helper method to identify scroll actions
- Added comprehensive tests for the new behavior
- Fixes issue where multiple scroll actions were incorrectly flagged as being stuck in a loop

Resolves: RooCodeInc#7470

Co-authored-by: Roo Code <[email protected]>

* Fix GPT-5 Responses API issues with condensing and image support (RooCodeInc#7067)

Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>
Co-authored-by: Roo Code <[email protected]>
Co-authored-by: Hannes Rudolph <[email protected]>

* Bump cloud to 0.25.0 (RooCodeInc#7475)

* feat: add image generation tool with OpenRouter integration (RooCodeInc#7474)

Co-authored-by: Matt Rubens <[email protected]>
Co-authored-by: cte <[email protected]>

* Make the default image filename more generic (RooCodeInc#7479)

* Release v3.26.2 (RooCodeInc#7490)

* Support free imagegen (RooCodeInc#7493)

* feat: update OpenRouter API to support input/output modalities and filter image generation models (RooCodeInc#7492)

* Add padding to image model picker (RooCodeInc#7494)

* fix: prevent dirty state on initial mount in ImageGenerationSettings (RooCodeInc#7495)

* Changeset version bump (RooCodeInc#7491)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Matt Rubens <[email protected]>

* Show console logging in vitests when the --no-silent flag is set (RooCodeInc#7467)

By default, all of the tests run in silent mode with monkey-patched the console logging so no console logging will ever appear in test output.
This confuses the agent- sometimes it will add console logging to help it debug things, and it won't see the logs that it expects.

Adds src/utils/vitest-verbosity.ts to handle verbosity resolution and console logging.
Modifies src/vitest.config.ts and webview-ui/vitest.config.ts to integrate the new verbosity control.
Removes manual console suppression from src/vitest.setup.ts and webview-ui/vitest.setup.ts as it's now handled dynamically.

Co-authored-by: Chris Hasson <[email protected]>

* Move @roo-code/cloud to the Roo-Code repo (RooCodeInc#7503)

* Refactor the extension bridge (RooCodeInc#7515)

* Implement deferred task subscriptions (RooCodeInc#7517)

* feat: add optional input image parameter to image generation tool (RooCodeInc#7525)

Co-authored-by: Roo Code <[email protected]>
Co-authored-by: Daniel Riccio <[email protected]>

* feat: sync extension bridge settings with cloud (RooCodeInc#7535)

- Use CloudService.getUserSettings() for remoteControlEnabled instead of global state
- Update CloudService.updateUserSettings when toggling remote control
- Add BridgeOrchestrator.connectOrDisconnect handling in settings update handler
- Remove dependency on contentProxy/globalSettings for remote control state
---------

Co-authored-by: Roo Code <[email protected]>
Co-authored-by: John Richmond <[email protected]>

* refactor: flatten image generation settings structure (RooCodeInc#7536)

* chore: add changeset for v3.26.3 (RooCodeInc#7541)

* Changeset version bump (RooCodeInc#7542)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Matt Rubens <[email protected]>

* Mode and provider profile selector (RooCodeInc#7545)

* Putting the Roo in Roo-leases (RooCodeInc#7546)

* Fix evals (RooCodeInc#7547)

* fix: special tokens should not break task processing (RooCodeInc#7540)

* docs: update PR template branding from Roo Code to Costrict

* feat: optimize memory usage for image handling in webview (RooCodeInc#7556)

* feat: optimize memory usage for image handling in webview

- Replace base64 image data with webview URIs to reduce memory footprint
- Add proper resource roots to webview for workspace file access
- Implement convertToWebviewUri method for safe file-to-URI conversion
- Update ImageViewer to handle both webview URIs and file paths separately
- Add image message type for proper image rendering in chat
- Improve error handling and display for failed image loads
- Add comprehensive tests for ImageViewer component
- Format display paths as relative for better readability

This change significantly reduces memory usage by avoiding base64 encoding
of images and instead using VSCode's webview URI system for direct file
access. Images are now loaded on-demand from disk rather than being held
in memory as base64 strings.

* fix: address PR review comments

- Use safeJsonParse instead of JSON.parse in ChatRow.tsx
- Add type definition for parsed image info
- Add more specific error types in ClineProvider.ts
- Add comprehensive JSDoc comments to ImageBlock.tsx
- Improve error handling and type safety

* fix: address MrUbens' review comments

- Remove hardcoded 'rc1' pattern in formatDisplayPath, use generic workspace detection
- Internationalize 'No image data' text using i18n system

* chore: remove useless comment

* chore(i18n): add image.noData to all locales to fix translation check

* test: update ImageViewer.spec to align with i18n key and flexible path formatting

* feat: rename Account tab to Cloud tab (RooCodeInc#7558)

Co-authored-by: Roo Code <[email protected]>
Co-authored-by: Matt Rubens <[email protected]>

* feat: add Ollama API key support for Turbo mode (RooCodeInc#7425)

* feat: add Ollama API key support for Turbo mode

- Add ollamaApiKey field to ProviderSettings schema
- Add ollamaApiKey to SECRET_STATE_KEYS for secure storage
- Update Ollama and NativeOllama providers to use API key for authentication
- Add UI field for Ollama API key (shown when custom base URL is provided)
- Add test coverage for API key functionality

This enables users to use Ollama Turbo with datacenter-grade hardware by providing an API key for authenticated Ollama instances or cloud services.

* fix: use VSCodeTextField for Ollama API key field

Remove non-existent ApiKeyField import and use standard VSCodeTextField with password type, matching other provider implementations

* Add missing translation keys for Ollama API key support

- Add providers.ollama.apiKey and providers.ollama.apiKeyHelp to all 18 language files
- Support for authenticated Ollama instances and cloud services
- Relates to PR RooCodeInc#7425

* refactor: improve type safety for Ollama client configuration

- Replace 'any' type with proper OllamaOptions (Config) type
- Import Config type from ollama package for better type checking

---------

Co-authored-by: Roo Code <[email protected]>
Co-authored-by: Daniel Riccio <[email protected]>

---------

Co-authored-by: Matt Rubens <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Josh <[email protected]>
Co-authored-by: daniel-lxs <[email protected]>
Co-authored-by: cte <[email protected]>
Co-authored-by: Daniel <[email protected]>
Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>
Co-authored-by: roomote[bot] <219738659+roomote[bot]@users.noreply.github.com>
Co-authored-by: Roo Code <[email protected]>
Co-authored-by: mrubens <[email protected]>
Co-authored-by: Hannes Rudolph <[email protected]>
Co-authored-by: Chris Hasson <[email protected]>
Co-authored-by: Chris Hasson <[email protected]>
Co-authored-by: John Richmond <[email protected]>
Co-authored-by: Piotr Wilkin (ilintar) <[email protected]>
mini2s added a commit to zgsm-ai/costrict that referenced this pull request Sep 2, 2025
* Follow symlinks in rooignore checks (RooCodeInc#7405)

* Sonic -> Grok Code Fast (RooCodeInc#7426)

* chore: add changeset for v3.26.0 (RooCodeInc#7428)

* Changeset version bump (RooCodeInc#7429)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Matt Rubens <[email protected]>

* feat: Add Vercel AI Gateway provider integration (RooCodeInc#7396)

Co-authored-by: daniel-lxs <[email protected]>
Co-authored-by: cte <[email protected]>

* feat: Enable on-disk storage for Qdrant vectors and HNSW index (RooCodeInc#7182)

* fix: use anthropic protocol for token counting when using anthropic models via Vercel AI Gateway (RooCodeInc#7433)

- Added condition in getApiProtocol to return 'anthropic' for vercel-ai-gateway when modelId starts with 'anthropic/'
- Added tests for Vercel AI Gateway provider protocol detection

This ensures proper token counting for Anthropic models accessed through Vercel AI Gateway, as Anthropic and OpenAI count tokens differently (Anthropic excludes cache tokens from input count, OpenAI includes them).

* fix: remove duplicate cache display in task header (RooCodeInc#7443)

* Random chat text area cleanup (RooCodeInc#7436)

* Update @roo-code/cloud to enable roomote control for cloud agents (RooCodeInc#7446)

Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>

* Always set remoteControlEnabled to true for cloud agents (RooCodeInc#7448)

* chore: add changeset for v3.26.1 (RooCodeInc#7459)

* feat: show model ID in API configuration dropdown (RooCodeInc#7423)

* feat: update tooltip component to match native VSCode tooltip shadow styling (RooCodeInc#7457)

Co-authored-by: Roo Code <[email protected]>
Co-authored-by: cte <[email protected]>

* Add support for Vercel embeddings (RooCodeInc#7445)

Co-authored-by: daniel-lxs <[email protected]>

* Remove dot before model display (RooCodeInc#7461)

* Update contributors list (RooCodeInc#7109)

Co-authored-by: mrubens <[email protected]>

* Update 3.26.1 changeset (RooCodeInc#7463)

* Changeset version bump (RooCodeInc#7460)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Matt Rubens <[email protected]>

* Add type for RooCodeEventName.TaskSpawned (RooCodeInc#7465)

* fix: hide .rooignore'd files from environment details by default (RooCodeInc#7369)

* fix: change default showRooIgnoredFiles to false to hide ignored files

- Changed default value from true to false across all files
- Updated tests to reflect the new default behavior
- This prevents ignored files from appearing in environment details

Fixes RooCodeInc#7368

* fix: update tests to match new showRooIgnoredFiles default

* fix: update test expectation to match new showRooIgnoredFiles default value

The PR changed the default value of showRooIgnoredFiles from true to false,
so the test needs to expect false instead of true when calling formatFilesList.

---------

Co-authored-by: Roo Code <[email protected]>
Co-authored-by: daniel-lxs <[email protected]>

* fix: exclude browser scroll actions from repetition detection (RooCodeInc#7471)

- Modified ToolRepetitionDetector to skip repetition detection for browser_action scroll_down and scroll_up actions
- Added isBrowserScrollAction() helper method to identify scroll actions
- Added comprehensive tests for the new behavior
- Fixes issue where multiple scroll actions were incorrectly flagged as being stuck in a loop

Resolves: RooCodeInc#7470

Co-authored-by: Roo Code <[email protected]>

* Fix GPT-5 Responses API issues with condensing and image support (RooCodeInc#7067)

Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>
Co-authored-by: Roo Code <[email protected]>
Co-authored-by: Hannes Rudolph <[email protected]>

* Bump cloud to 0.25.0 (RooCodeInc#7475)

* feat: add image generation tool with OpenRouter integration (RooCodeInc#7474)

Co-authored-by: Matt Rubens <[email protected]>
Co-authored-by: cte <[email protected]>

* Make the default image filename more generic (RooCodeInc#7479)

* Release v3.26.2 (RooCodeInc#7490)

* Support free imagegen (RooCodeInc#7493)

* feat: update OpenRouter API to support input/output modalities and filter image generation models (RooCodeInc#7492)

* Add padding to image model picker (RooCodeInc#7494)

* fix: prevent dirty state on initial mount in ImageGenerationSettings (RooCodeInc#7495)

* Changeset version bump (RooCodeInc#7491)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Matt Rubens <[email protected]>

* Show console logging in vitests when the --no-silent flag is set (RooCodeInc#7467)

By default, all of the tests run in silent mode with monkey-patched the console logging so no console logging will ever appear in test output.
This confuses the agent- sometimes it will add console logging to help it debug things, and it won't see the logs that it expects.

Adds src/utils/vitest-verbosity.ts to handle verbosity resolution and console logging.
Modifies src/vitest.config.ts and webview-ui/vitest.config.ts to integrate the new verbosity control.
Removes manual console suppression from src/vitest.setup.ts and webview-ui/vitest.setup.ts as it's now handled dynamically.

Co-authored-by: Chris Hasson <[email protected]>

* Move @roo-code/cloud to the Roo-Code repo (RooCodeInc#7503)

* Refactor the extension bridge (RooCodeInc#7515)

* Implement deferred task subscriptions (RooCodeInc#7517)

* feat: add optional input image parameter to image generation tool (