Repository navigation
feat: integrate AIAssist for script editing - #8220
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughAdds AI-assisted script generation: backend prompt templates and IPC handler, renderer IPC wrapper and request-context helper, a styled AIAssist React popup component, and integrations placing the assistant beside script/tests editors across collection, folder, and request panes. ChangesAI Script Generation Feature
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (3)
packages/bruno-app/src/components/AIAssist/index.js (2)
48-49: 💤 Low valueRemove unnecessary memoization.
Lines 48–49 use
useMemofor simple object lookups (SUGGESTIONS[scriptType],TITLES[scriptType]). These are O(1) operations—not expensive enough to justify memoization. Per coding guidelines ("Memoize only when necessary"), inline them:- const suggestions = useMemo(() => SUGGESTIONS[scriptType] || [], [scriptType]); - const title = TITLES[scriptType] || 'Generate with AI'; + const suggestions = SUGGESTIONS[scriptType] || []; + const title = TITLES[scriptType] || 'Generate with AI';🤖 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/AIAssist/index.js` around lines 48 - 49, Remove the unnecessary useMemo wrappers around simple lookups: replace the memoized expressions that compute suggestions and title (the useMemo calls referencing SUGGESTIONS[scriptType] and TITLES[scriptType]) with direct assignments so suggestions = SUGGESTIONS[scriptType] || [] and title = TITLES[scriptType] || 'Generate with AI'; remove the import/use of useMemo if it becomes unused.
225-226: 💤 Low valueExtract inline style to StyledWrapper.
The inline style object at line 225 (
{ display: 'inline-flex', alignItems: 'center', gap: 4 }) could be extracted to StyledWrapper as a.back-button-contentclass for consistency with the rest of the component's styling approach.🤖 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/AIAssist/index.js` around lines 225 - 226, The inline style used for the back button content (display: 'inline-flex', alignItems: 'center', gap: 4) should be moved into the component's StyledWrapper as a CSS class named .back-button-content; update StyledWrapper to include rules for .back-button-content (display: inline-flex; align-items: center; gap: 4px) and replace the inline style on the element that currently renders <span style={{ display: 'inline-flex', alignItems: 'center', gap: 4 }}> (in AIAssist/index.js) with className="back-button-content" so styling is consistent with the rest of the component.packages/bruno-app/src/components/FolderSettings/Tests/index.js (1)
37-54: 💤 Low valueOptional: Consider adding data-testid for E2E testing.
The new wrapper divs could include
data-testidattributes (e.g.,data-testid="folder-tests-ai-assist-wrapper") to facilitate Playwright E2E testing of the AIAssist feature. This would align with the coding guidelines' emphasis on adding testable identifiers.🧪 Example enhancement
- <div className="relative h-full"> + <div className="relative h-full" data-testid="folder-tests-ai-assist-wrapper">Apply similar changes to all 4 integration files (collection/folder × script/tests).
🤖 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/FolderSettings/Tests/index.js` around lines 37 - 54, Add a data-testid to the new wrapper div around the CodeEditor and AIAssist so E2E tests can target the AI assist area; locate the JSX containing CodeEditor (ref testsEditorRef, props value={tests || ''}, onEdit, onSave={handleSave}, initialScroll={testsScroll}, onScroll={setTestsScroll}) and AIAssist (scriptType="tests", currentScript={tests || ''}, onApply={onEdit}) and add a descriptive attribute such as data-testid="folder-tests-ai-assist-wrapper" (repeat analogous additions for the other three integration files: collection/folder × script/tests).
🤖 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/AIAssist/index.js`:
- Around line 134-143: In the AIAssist component add Playwright data-testid
attributes to the interactive elements: add data-testid="ai-assist-trigger" to
the trigger button (the element using buttonRef and className
`ai-assist-trigger`), add data-testid="ai-assist-popup" to the popup container
element that shows when isOpen is true, add data-testid="ai-assist-input" to the
textarea/input used for user prompts, add data-testid="ai-assist-generate" to
the Generate button, add data-testid="ai-assist-back" to the Back button, add
data-testid="ai-assist-apply" to the Apply button, and add
data-testid={`ai-assist-suggestion-${s.label}`} to each suggestion chip where
chips are rendered (reference the variable s.label in the suggestion mapping) so
tests can reliably target these elements.
In `@packages/bruno-electron/src/ipc/ai/index.js`:
- Around line 147-181: The generateText call in the ipcMain handler for
'renderer:ai-generate-script' doesn't set temperature, making outputs
non-deterministic; update the generateText invocation inside the
'renderer:ai-generate-script' handler to pass a temperature value (use the
requested temperature if provided or default to 0.3 like the
'renderer:ai-generate-text' handler) so the call to generateText({ model,
system: SCRIPT_PROMPTS[scriptType], prompt: buildScriptUserPrompt(...),
maxOutputTokens: 2048 }) becomes generateText(..., temperature:
temperatureOrDefault) ensuring consistent code generation while keeping other
parameters (model, system, prompt, maxOutputTokens) unchanged.
In `@packages/bruno-electron/src/ipc/ai/script-prompts.js`:
- Around line 84-108: Update the "tests" prompt block so the anti-side-effect
rule is softened: replace the absolute prohibition text around bru.setEnvVar
with guidance to prefer pure assertions but allow bru.setEnvVar when necessary
to capture response data for follow-up requests; locate the string literal keyed
'tests' in script-prompts.js (the prompt content that currently says "Do NOT use
`bru.setEnvVar` or other side-effecting calls inside tests — keep tests pure
assertions.") and change it to something like "Prefer pure assertions; avoid
side effects unless you need to extract response data for subsequent requests —
use `bru.setEnvVar` only for that purpose." Ensure the rest of the tests
instructions and COMMON_OUTPUT_RULES references remain unchanged.
- Around line 148-177: formatRequestContext currently extracts only the GraphQL
query (body.graphql?.query) and omits GraphQL variables; update
formatRequestContext so that when body.mode === 'graphql' it also includes
body.graphql?.variables (serialized as JSON) alongside the query (truncate
combined text to the existing 2000-char slice logic) so the returned context
contains both the query and variables for AI consumption.
---
Nitpick comments:
In `@packages/bruno-app/src/components/AIAssist/index.js`:
- Around line 48-49: Remove the unnecessary useMemo wrappers around simple
lookups: replace the memoized expressions that compute suggestions and title
(the useMemo calls referencing SUGGESTIONS[scriptType] and TITLES[scriptType])
with direct assignments so suggestions = SUGGESTIONS[scriptType] || [] and title
= TITLES[scriptType] || 'Generate with AI'; remove the import/use of useMemo if
it becomes unused.
- Around line 225-226: The inline style used for the back button content
(display: 'inline-flex', alignItems: 'center', gap: 4) should be moved into the
component's StyledWrapper as a CSS class named .back-button-content; update
StyledWrapper to include rules for .back-button-content (display: inline-flex;
align-items: center; gap: 4px) and replace the inline style on the element that
currently renders <span style={{ display: 'inline-flex', alignItems: 'center',
gap: 4 }}> (in AIAssist/index.js) with className="back-button-content" so
styling is consistent with the rest of the component.
In `@packages/bruno-app/src/components/FolderSettings/Tests/index.js`:
- Around line 37-54: Add a data-testid to the new wrapper div around the
CodeEditor and AIAssist so E2E tests can target the AI assist area; locate the
JSX containing CodeEditor (ref testsEditorRef, props value={tests || ''},
onEdit, onSave={handleSave}, initialScroll={testsScroll},
onScroll={setTestsScroll}) and AIAssist (scriptType="tests",
currentScript={tests || ''}, onApply={onEdit}) and add a descriptive attribute
such as data-testid="folder-tests-ai-assist-wrapper" (repeat analogous additions
for the other three integration files: collection/folder × script/tests).
🪄 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: 83e14acf-e719-451c-8d4b-4c9ee06c47b0
📒 Files selected for processing (11)
packages/bruno-app/src/components/AIAssist/StyledWrapper.jspackages/bruno-app/src/components/AIAssist/index.jspackages/bruno-app/src/components/CollectionSettings/Script/index.jspackages/bruno-app/src/components/CollectionSettings/Tests/index.jspackages/bruno-app/src/components/FolderSettings/Script/index.jspackages/bruno-app/src/components/FolderSettings/Tests/index.jspackages/bruno-app/src/components/RequestPane/Script/index.jspackages/bruno-app/src/components/RequestPane/Tests/index.jspackages/bruno-app/src/utils/ai/index.jspackages/bruno-electron/src/ipc/ai/index.jspackages/bruno-electron/src/ipc/ai/script-prompts.js
sid-bruno
left a comment
There was a problem hiding this comment.
LGTM other than the useEffect dependency
Description
JIRA
Contribution Checklist:
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