Skip to content

feat: AI features into preferences and Redux store - #8048

Merged
naman-bruno merged 2 commits into
usebruno:release/v4.0.0from
naman-bruno:feat/ai-providers
May 20, 2026
Merged

naman-bruno merged 2 commits into
usebruno:release/v4.0.0from
naman-bruno:feat/ai-providers

Conversation

@naman-bruno

@naman-bruno naman-bruno commented May 20, 2026 •

Copy link
Copy Markdown
Collaborator

Description

JIRA

Contribution Checklist:

  • I've used AI significantly to create this pull request
  • The pull request only addresses one issue or adds one feature.
  • The pull request does not introduce any breaking changes
  • I have added screenshots or gifs to help explain the change if applicable.
  • I have read the contribution guidelines.
  • Create an issue and link to the pull request.

Note: Keeping the PR small and focused helps make it easier to review and merge. If you have multiple changes you want to make, please consider submitting them as separate pull requests.

Publishing to New Package Managers

Please see here for more information.

Summary by CodeRabbit

  • New Features

    • AI preferences tab with provider rows, masked API key controls, connectivity test, and per-provider enable/disable.
    • Per-model enable/disable controls and default model selection.
    • Non-streaming and streaming AI text generation with live progress and stop control.
    • Persistent, encrypted storage of provider API keys.
  • Improvements

    • Inline status, feedback and error notices in the AI UI.
    • More robust toggle input IDs for accessibility and stability.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 20, 2026 •

Copy link
Copy Markdown
Contributor

Walkthrough

Adds end-to-end AI support: Electron main IPC and provider registry with encrypted key storage, renderer IPC helpers (including streaming), and a Formik-based AI Preferences UI with ProviderCard components and themed styling.

Changes

AI Feature Implementation

Layer / File(s) Summary
Preferences State & Schema
packages/bruno-app/src/providers/ReduxStore/slices/app.js, packages/bruno-electron/src/store/preferences.js
Redux/app initial state gains ai subtree; Electron preferences schema validates ai (enabled, providers, models, defaultModel).
Provider Registry, Model Catalog & Key Store
packages/bruno-electron/package.json, packages/bruno-electron/src/ipc/ai/providers.js, packages/bruno-electron/src/store/ai-keys.js
Adds AI dependencies and implements provider definitions, model catalog, SDK instance cache and encrypted AiKeyStore with per-provider key lifecycle.
Electron IPC Handlers & Streaming
packages/bruno-electron/src/ipc/ai/index.js, packages/bruno-electron/src/index.js
Registers IPC handlers for status, API key CRUD, provider test, generate (non-streaming), and streaming with active stream tracking and abort support; integrates registration into app startup.
Frontend IPC Utilities & Streaming Client
packages/bruno-app/src/utils/ai/index.js
Renderer-side IPC wrappers: get/set/clear/get API keys, test provider, generate text, and aiStreamText streaming helper managing listeners, stop(), and done promise.
Frontend AI Preferences UI & Components
packages/bruno-app/src/components/Preferences/AI/StyledWrapper.js, packages/bruno-app/src/components/Preferences/AI/ProviderCard.js, packages/bruno-app/src/components/Preferences/AI/index.js, packages/bruno-app/src/components/Preferences/index.js, packages/bruno-app/src/components/ToggleSwitch/index.js
Styled wrapper and ProviderCard implement provider rows, masked/editable API key UI, test/save/clear actions, model enable toggles, and Formik-based AI preferences panel with debounced persistence; preferences tab integration and ToggleSwitch id fix.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant UI as Preferences UI
  participant Renderer as Renderer IPC
  participant Main as Electron Main
  participant Store as AiKeyStore
  participant Sdk as AI SDK

  User->>UI: Enter API key in ProviderCard
  UI->>Renderer: setAiApiKey({providerId, apiKey})
  Renderer->>Main: renderer:set-ai-api-key
  Main->>Store: encrypt and persist key
  Main->>Renderer: success
  Renderer->>UI: toast confirmation

  User->>UI: Start streaming generation
  UI->>Renderer: aiStreamText({streamId, modelId, messages})
  Renderer->>Main: renderer:ai-stream-text
  Main->>Sdk: streamText(model, messages)
  Sdk-->>Main: text chunk
  Main->>Renderer: main:ai-stream-chunk
  Renderer->>UI: onChunk callback
  Sdk-->>Main: complete
  Main->>Renderer: main:ai-stream-complete
  Renderer->>UI: done resolved
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Suggested reviewers

  • helloanoop
  • lohit-bruno
  • sid-bruno
  • bijin-bruno

Poem

🎛️ Keys wrapped in electron-store's embrace,
IPC bridges span the UI-to-main space,
Provider cards flip, models whisper “go”,
Streams flow in chunks, and Bruno learns to show.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: introducing AI features into preferences and Redux store, which is reflected across all file modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@naman-bruno
naman-bruno changed the base branch from main to release/v4.0.0 May 20, 2026 07:41

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 6

🧹 Nitpick comments (2)
packages/bruno-app/src/utils/ai/index.js (1)

34-36: ⚡ Quick win

Remove the renderer-side ipcRenderer existence guard.

In this codebase’s Electron renderer path, this guard is discouraged and can hide integration regressions.

🔧 Suggested fix
   const { ipcRenderer } = window;
-  if (!ipcRenderer) {
-    return { stop: () => {}, done: Promise.reject(new Error('IPC not available')) };
-  }
Based on learnings: In the Bruno Electron renderer code (packages/bruno-app), assume window.ipcRenderer is always available and skip existence checks.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/bruno-app/src/utils/ai/index.js` around lines 34 - 36, Remove the
renderer-side ipcRenderer existence guard: delete the conditional that checks if
(!ipcRenderer) and the fallback return ({ stop: () => {}, done:
Promise.reject(new Error('IPC not available')) }); and instead use
window.ipcRenderer (or ipcRenderer) directly throughout this module so code
always assumes the renderer IPC is present; update any callers expecting the
fallback to handle actual runtime errors from real ipc calls rather than a
synthetic Promise.reject.
packages/bruno-app/src/components/Preferences/AI/ProviderCard.js (1)

34-34: ⚡ Quick win

Wrap single-parameter arrow function params in parentheses.

stopBubble should follow the repo’s arrow-function formatting rule.

Proposed fix
-const stopBubble = (e) => e.stopPropagation();
+const stopBubble = ((e) => e.stopPropagation());

As per coding guidelines, "Always use parentheses around parameters in arrow functions, even for single parameters."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/bruno-app/src/components/Preferences/AI/ProviderCard.js` at line 34,
The arrow function stopBubble uses an unparenthesized single parameter; update
its declaration to include parentheses around the parameter (i.e., change
stopBubble = (e) => ... to use (e) explicitly) so it follows the repo's
arrow-function formatting rule and is consistent across the component; locate
the stopBubble function in ProviderCard.js to make this one-line change.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/bruno-app/src/components/Preferences/AI/index.js`:
- Around line 92-99: The effect currently calls debouncedSave.flush() in its
cleanup which forces pending saves to run on every re-render and defeats the
400ms debounce; change the cleanup to call debouncedSave.cancel() instead so
pending saves are cancelled on unmount/re-render rather than flushed, and keep
the effect body using debouncedSave(formik.values) when formik.dirty &&
formik.isValid; update the cleanup reference in the useEffect that uses
formik.values, formik.dirty, formik.isValid, debouncedSave to use
debouncedSave.cancel().

In `@packages/bruno-electron/package.json`:
- Around line 33-35: Add the missing peer dependency zod to the bruno-electron
package by adding "zod": "^4.1.8" to the dependencies section of package.json;
this ensures compatibility with the existing "`@ai-sdk/openai`" and
"`@ai-sdk/anthropic`" entries and satisfies their peer requirement (refer to the
dependency list containing "`@ai-sdk/anthropic`" and "`@ai-sdk/openai`"). Make sure
to run the package manager install afterwards to update the lockfile.

In `@packages/bruno-electron/src/ipc/ai/index.js`:
- Around line 136-161: Before creating and storing a new AbortController in the
ipcMain.on('renderer:ai-stream-text') handler, check activeStreams.has(streamId)
and reject the duplicate (send 'main:ai-stream-error' with a clear message) or
choose to abort the existing controller first; when cleaning up later (where
activeStreams.delete/controller.abort are used) only delete/abort if the stored
controller === controller you created to avoid tearing down a different stream.
Reference symbols: ipcMain.on('renderer:ai-stream-text'), streamId,
activeStreams, controller.
- Around line 77-82: The handler ipcMain.handle('renderer:get-ai-api-key', which
currently returns the raw decrypted key from aiKeyStore.getKey(providerId),
should not send secrets to the renderer; instead change this handler to only
return a non-secret indicator (e.g., boolean hasKey or a masked string) and
remove any path that sends the full key, and implement a main-side action
handler (e.g., ipcMain.handle('renderer:perform-ai-request' or similar) that
accepts providerId and request parameters and performs the external API call in
the main process using aiKeyStore.getKey(providerId) so the key never leaves
main; update references to 'renderer:get-ai-api-key' to use the new
presence/masked response and call the new main-side request handler for any
operation requiring the actual key.

In `@packages/bruno-electron/src/ipc/ai/providers.js`:
- Around line 27-35: Update the Anthropic modelId values in the providers
mapping: change the mapping for key 'claude-sonnet-4-5' (the object with
provider: 'anthropic') to use modelId 'claude-sonnet-4-5-20250929' instead of
the old '-20250514' value, and replace the modelId for key 'claude-opus-4-5'
with the correct Opus 4.5 model ID from the Anthropic docs/SDK (update the
object with provider: 'anthropic' and modelId for 'claude-opus-4-5'); leave the
OpenAI entries (gpt-4o-mini, gpt-4o, gpt-5, gpt-5-mini) unchanged. Ensure both
updated modelId strings are exact and valid per Anthropic's current API.

In `@packages/bruno-electron/src/store/ai-keys.js`:
- Around line 32-45: hasKey and getKeyStatus currently treat any stored
encrypted blob as "configured" even if decryption fails; update
hasKey(providerId) and getKeyStatus() to attempt to decrypt the stored key blob
(the same decryption used when reading keys earlier) and only return configured:
true or true from hasKey if decryption succeeds and yields a usable key; for
getKeyStatus iterate Object.keys(this.store.get('keys', {}) || {}) and try to
decrypt each stored[providerId] and set status[providerId] = { configured:
Boolean(decryptedKey) } (handle decryption errors quietly and treat them as not
configured). Ensure you reference the existing decryption routine used elsewhere
in this module rather than just checking blob presence.

---

Nitpick comments:
In `@packages/bruno-app/src/components/Preferences/AI/ProviderCard.js`:
- Line 34: The arrow function stopBubble uses an unparenthesized single
parameter; update its declaration to include parentheses around the parameter
(i.e., change stopBubble = (e) => ... to use (e) explicitly) so it follows the
repo's arrow-function formatting rule and is consistent across the component;
locate the stopBubble function in ProviderCard.js to make this one-line change.

In `@packages/bruno-app/src/utils/ai/index.js`:
- Around line 34-36: Remove the renderer-side ipcRenderer existence guard:
delete the conditional that checks if (!ipcRenderer) and the fallback return ({
stop: () => {}, done: Promise.reject(new Error('IPC not available')) }); and
instead use window.ipcRenderer (or ipcRenderer) directly throughout this module
so code always assumes the renderer IPC is present; update any callers expecting
the fallback to handle actual runtime errors from real ipc calls rather than a
synthetic Promise.reject.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f677c554-a726-43c6-8634-35b7a225f013

📥 Commits

Reviewing files that changed from the base of the PR and between e0de7d5 and 1c0a044.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (13)
  • packages/bruno-app/src/components/Preferences/AI/ProviderCard.js
  • packages/bruno-app/src/components/Preferences/AI/StyledWrapper.js
  • packages/bruno-app/src/components/Preferences/AI/index.js
  • packages/bruno-app/src/components/Preferences/index.js
  • packages/bruno-app/src/components/ToggleSwitch/index.js
  • packages/bruno-app/src/providers/ReduxStore/slices/app.js
  • packages/bruno-app/src/utils/ai/index.js
  • packages/bruno-electron/package.json
  • packages/bruno-electron/src/index.js
  • packages/bruno-electron/src/ipc/ai/index.js
  • packages/bruno-electron/src/ipc/ai/providers.js
  • packages/bruno-electron/src/store/ai-keys.js
  • packages/bruno-electron/src/store/preferences.js

Comment thread packages/bruno-electron/package.json Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
packages/bruno-electron/src/ipc/ai/index.js (1)

146-149: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Protect cleanup with controller ownership check.

The duplicate guard helps, but Line 204 still deletes by streamId unconditionally. If a stopped stream ID is quickly reused, the old handler’s finally can clear the newer active controller.

🔧 Suggested fix
     } finally {
-      activeStreams.delete(streamId);
+      if (activeStreams.get(streamId) === controller) {
+        activeStreams.delete(streamId);
+      }
     }

Also applies to: 204-205

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/bruno-electron/src/ipc/ai/index.js` around lines 146 - 149, The
finally cleanup currently deletes activeStreams by streamId unconditionally,
which can remove a newly created controller if streamId was reused; modify the
cleanup in the async handler so it only removes the entry if the stored
controller instance matches the activeStreams entry (i.e., capture the
controller you set into activeStreams and in the finally check that
activeStreams.get(streamId) === controller before calling
activeStreams.delete(streamId)); reference activeStreams, streamId and the
controller variable used when registering the stream to implement this ownership
check.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Duplicate comments:
In `@packages/bruno-electron/src/ipc/ai/index.js`:
- Around line 146-149: The finally cleanup currently deletes activeStreams by
streamId unconditionally, which can remove a newly created controller if
streamId was reused; modify the cleanup in the async handler so it only removes
the entry if the stored controller instance matches the activeStreams entry
(i.e., capture the controller you set into activeStreams and in the finally
check that activeStreams.get(streamId) === controller before calling
activeStreams.delete(streamId)); reference activeStreams, streamId and the
controller variable used when registering the stream to implement this ownership
check.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 75b9baf8-ab45-4325-be8b-63703f1509b4

📥 Commits

Reviewing files that changed from the base of the PR and between 1c0a044 and 23783d2.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (5)
  • packages/bruno-app/src/components/Preferences/AI/index.js
  • packages/bruno-electron/package.json
  • packages/bruno-electron/src/ipc/ai/index.js
  • packages/bruno-electron/src/ipc/ai/providers.js
  • packages/bruno-electron/src/store/ai-keys.js

Comment on lines +17 to +27
const OpenAiLogo = (props) => (
<svg viewBox="0 0 24 24" fill="currentColor" {...props}>
<path d="M22.2819 9.8211a5.9847 5.9847 0 0 0-.5157-4.9108 6.0462 6.0462 0 0 0-6.5098-2.9A6.0651 6.0651 0 0 0 4.9807 4.1818a5.9847 5.9847 0 0 0-3.9977 2.9 6.0462 6.0462 0 0 0 .7427 7.0966 5.98 5.98 0 0 0 .511 4.9107 6.051 6.051 0 0 0 6.5146 2.9001A5.9847 5.9847 0 0 0 13.2599 24a6.0557 6.0557 0 0 0 5.7718-4.2058 5.9894 5.9894 0 0 0 3.9977-2.9001 6.0557 6.0557 0 0 0-.7475-7.0729zm-9.022 12.6081a4.4755 4.4755 0 0 1-2.8764-1.0408l.1419-.0804 4.7783-2.7582a.7948.7948 0 0 0 .3927-.6813v-6.7369l2.02 1.1686a.071.071 0 0 1 .038.052v5.5826a4.504 4.504 0 0 1-4.4945 4.4944zm-9.6607-4.1254a4.4708 4.4708 0 0 1-.5346-3.0137l.142.0852 4.783 2.7582a.7712.7712 0 0 0 .7806 0l5.8428-3.3685v2.3324a.0804.0804 0 0 1-.0332.0615L9.74 19.9502a4.4992 4.4992 0 0 1-6.1408-1.6464zM2.3408 7.8956a4.485 4.485 0 0 1 2.3655-1.9728V11.6a.7664.7664 0 0 0 .3879.6765l5.8144 3.3543-2.0201 1.1685a.0757.0757 0 0 1-.071 0l-4.8303-2.7865A4.504 4.504 0 0 1 2.3408 7.8956zm16.5963 3.8558L13.1038 8.364 15.1192 7.2a.0757.0757 0 0 1 .071 0l4.8303 2.7913a4.4944 4.4944 0 0 1-.6765 8.1042v-5.6772a.79.79 0 0 0-.407-.667zm2.0107-3.0231l-.142-.0852-4.7735-2.7818a.7759.7759 0 0 0-.7854 0L9.409 9.2297V6.8974a.0662.0662 0 0 1 .0284-.0615l4.8303-2.7866a4.4992 4.4992 0 0 1 6.6802 4.66zM8.3065 12.863l-2.02-1.1638a.0804.0804 0 0 1-.038-.0567V6.0742a4.4992 4.4992 0 0 1 7.3757-3.4537l-.142.0805L8.704 5.459a.7948.7948 0 0 0-.3927.6813zm1.0976-2.3654l2.602-1.4998 2.6069 1.4998v2.9994l-2.5974 1.4997-2.6067-1.4997Z" />
</svg>
);

const AnthropicLogo = (props) => (
<svg viewBox="0 0 24 24" fill="currentColor" {...props}>
<path d="M17.304 3.541h-3.672l6.696 16.918h3.672l-6.696-16.918Zm-10.608 0L0 20.459h3.744l1.368-3.584h6.624l1.368 3.584h3.744L10.152 3.54H6.696Zm.432 10.418 2.208-5.784 2.208 5.784H7.128Z" />
</svg>
);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Move them to their own files

Comment on lines +21 to +30
getKey(providerId) {
const encrypted = this.store.get(`keys.${providerId}`);
if (!encrypted) return null;
try {
return decryptString(encrypted);
} catch (err) {
console.error(`Failed to decrypt AI key for ${providerId}:`, err.message);
return null;
}
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Make sure this is not fetched on the client

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants