Use VS Code native file dialog for AI panel attachments#2156
Use VS Code native file dialog for AI panel attachments#2156VellummyilumVinoth wants to merge 1 commit into
Conversation
📝 WalkthroughWalkthroughAdds a selectContextFiles RPC and types, implements extension-side file selection and encoding, registers RPC handling, exposes a client method, and wires the AI panel UI to attach returned files. ChangesFile Attachment Selection via VS Code Dialog
Sequence Diagram(s)sequenceDiagram
actor User
participant AIChat as AI Chat Footer
participant RpcClient as AiPanelRpcClient
participant RpcHandler as AiPanelRpcHandler
participant RpcManager as AiPanelRpcManager
participant VSCode as VS Code
participant FileSystem as File System
participant Hooks as useAttachments
User->>AIChat: Click attach context
AIChat->>RpcClient: selectContextFiles({ command, skillCommand })
RpcClient->>RpcHandler: sendRequest(selectContextFiles)
RpcHandler->>RpcManager: selectContextFiles(args)
RpcManager->>VSCode: showOpenDialog(defaultUri, multiSelect)
VSCode->>RpcManager: selected files
RpcManager->>FileSystem: stat/read selected files
FileSystem->>RpcManager: file bytes and metadata
RpcManager->>RpcClient: Attachment[]
RpcClient->>AIChat: Attachment[]
AIChat->>Hooks: onAttachClick result
Hooks->>Hooks: filter success, de-dupe, merge attachments
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 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: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@workspaces/ballerina/ballerina-visualizer/src/views/AIPanel/components/AIChatInput/hooks/useAttachments.ts`:
- Around line 41-57: handleAttachClick currently merges every item returned by
attachmentOptions.onAttachClick into attachments, including error entries like
FileSizeExceeded/UnknownError; update handleAttachClick to filter the results
before calling setAttachments so only valid/successful attachment objects (e.g.,
entries that have expected fields such as name and content or a success/type ===
'success' marker) are merged into attachments, and keep any non-sendable error
entries in a separate state (e.g., rejectedAttachments or attachErrors) for UI
display rather than including them in the sendable attachments list; make the
change around the results processing inside handleAttachClick (where
setAttachments is called) so only filteredResults are pushed into updated.
🪄 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: d397a1da-3ef8-46d5-b964-7fb1c76087ae
📒 Files selected for processing (8)
workspaces/ballerina/ballerina-core/src/rpc-types/ai-panel/index.tsworkspaces/ballerina/ballerina-core/src/rpc-types/ai-panel/interfaces.tsworkspaces/ballerina/ballerina-core/src/rpc-types/ai-panel/rpc-type.tsworkspaces/ballerina/ballerina-extension/src/rpc-managers/ai-panel/rpc-handler.tsworkspaces/ballerina/ballerina-extension/src/rpc-managers/ai-panel/rpc-manager.tsworkspaces/ballerina/ballerina-rpc-client/src/rpc-clients/ai-panel/rpc-client.tsworkspaces/ballerina/ballerina-visualizer/src/views/AIPanel/components/AIChat/index.tsxworkspaces/ballerina/ballerina-visualizer/src/views/AIPanel/components/AIChatInput/hooks/useAttachments.ts
2a02785 to
cb10dca
Compare
cb10dca to
e615cfb
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@workspaces/ballerina/ballerina-visualizer/src/views/AIPanel/components/AIChatInput/hooks/useAttachments.ts`:
- Around line 41-59: The async call to attachmentOptions.onAttachClick in
handleAttachClick can reject and currently bubbles out; wrap the await
attachmentOptions.onAttachClick(activeCommand) call in a try/catch inside
handleAttachClick (the function in useAttachments.ts) and handle failures
gracefully (e.g., log the error and return early or surface a user-friendly
error state) before calling setAttachments; ensure you only call setAttachments
when results is defined and valid so RPC/dialog failures don't produce unhandled
promise rejections.
🪄 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: 6832811c-a48f-4aab-88c1-9244af03deac
📒 Files selected for processing (8)
workspaces/ballerina/ballerina-core/src/rpc-types/ai-panel/index.tsworkspaces/ballerina/ballerina-core/src/rpc-types/ai-panel/interfaces.tsworkspaces/ballerina/ballerina-core/src/rpc-types/ai-panel/rpc-type.tsworkspaces/ballerina/ballerina-extension/src/rpc-managers/ai-panel/rpc-handler.tsworkspaces/ballerina/ballerina-extension/src/rpc-managers/ai-panel/rpc-manager.tsworkspaces/ballerina/ballerina-rpc-client/src/rpc-clients/ai-panel/rpc-client.tsworkspaces/ballerina/ballerina-visualizer/src/views/AIPanel/components/AIChat/index.tsxworkspaces/ballerina/ballerina-visualizer/src/views/AIPanel/components/AIChatInput/hooks/useAttachments.ts
✅ Files skipped from review due to trivial changes (3)
- workspaces/ballerina/ballerina-core/src/rpc-types/ai-panel/rpc-type.ts
- workspaces/ballerina/ballerina-extension/src/rpc-managers/ai-panel/rpc-manager.ts
- workspaces/ballerina/ballerina-rpc-client/src/rpc-clients/ai-panel/rpc-client.ts
🚧 Files skipped from review as they are similar to previous changes (3)
- workspaces/ballerina/ballerina-visualizer/src/views/AIPanel/components/AIChat/index.tsx
- workspaces/ballerina/ballerina-extension/src/rpc-managers/ai-panel/rpc-handler.ts
- workspaces/ballerina/ballerina-core/src/rpc-types/ai-panel/index.ts
e615cfb to
6c89dc1
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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
`@workspaces/ballerina/ballerina-extension/src/rpc-managers/ai-panel/rpc-manager.ts`:
- Around line 870-904: selectContextFiles uses blocking fs.statSync and
fs.readFileSync which can freeze the host; update selectContextFiles (handling
SelectContextFilesRequest/Command and returning Attachment[]) to use fs.promises
(or fs.promises.stat and fs.promises.readFile) and process the selected uris
concurrently (e.g., map uris to async tasks and await Promise.all) while
preserving the existing logic for MAX_FILE_SIZE, isDataMapper,
AttachmentStatus.FileSizeExceeded and AttachmentStatus.UnknownError so each file
returns the same Attachment shape but without synchronous I/O blocking.
🪄 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: f758617e-dcf1-4a9f-bf87-48005212218f
📒 Files selected for processing (8)
workspaces/ballerina/ballerina-core/src/rpc-types/ai-panel/index.tsworkspaces/ballerina/ballerina-core/src/rpc-types/ai-panel/interfaces.tsworkspaces/ballerina/ballerina-core/src/rpc-types/ai-panel/rpc-type.tsworkspaces/ballerina/ballerina-extension/src/rpc-managers/ai-panel/rpc-handler.tsworkspaces/ballerina/ballerina-extension/src/rpc-managers/ai-panel/rpc-manager.tsworkspaces/ballerina/ballerina-rpc-client/src/rpc-clients/ai-panel/rpc-client.tsworkspaces/ballerina/ballerina-visualizer/src/views/AIPanel/components/AIChat/index.tsxworkspaces/ballerina/ballerina-visualizer/src/views/AIPanel/components/AIChatInput/hooks/useAttachments.ts
✅ Files skipped from review due to trivial changes (1)
- workspaces/ballerina/ballerina-rpc-client/src/rpc-clients/ai-panel/rpc-client.ts
🚧 Files skipped from review as they are similar to previous changes (6)
- workspaces/ballerina/ballerina-core/src/rpc-types/ai-panel/interfaces.ts
- workspaces/ballerina/ballerina-core/src/rpc-types/ai-panel/index.ts
- workspaces/ballerina/ballerina-extension/src/rpc-managers/ai-panel/rpc-handler.ts
- workspaces/ballerina/ballerina-visualizer/src/views/AIPanel/components/AIChatInput/hooks/useAttachments.ts
- workspaces/ballerina/ballerina-visualizer/src/views/AIPanel/components/AIChat/index.tsx
- workspaces/ballerina/ballerina-core/src/rpc-types/ai-panel/rpc-type.ts
68b167d to
9a0b47f
Compare
9a0b47f to
0dd1697
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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
`@workspaces/ballerina/ballerina-extension/src/rpc-managers/ai-panel/rpc-manager.ts`:
- Around line 1281-1282: The picker default directory is still derived only from
StateMachine.context().projectPath, which can miss the resolved workspace root
in workspace-root flows and open outside the current project. Update the default
URI logic in the rpc-manager.ts picker setup to use the resolved project root
(prefer workspacePath when available, falling back to projectPath, then home
directory) so the picker always starts inside the active workspace. Keep the
change localized around the projectPath/defaultUri assignment in rpc-manager.ts.
🪄 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: 1d095f3a-820f-41ce-97b5-1f2d80d065f2
📒 Files selected for processing (8)
workspaces/ballerina/ballerina-core/src/rpc-types/ai-panel/index.tsworkspaces/ballerina/ballerina-core/src/rpc-types/ai-panel/interfaces.tsworkspaces/ballerina/ballerina-core/src/rpc-types/ai-panel/rpc-type.tsworkspaces/ballerina/ballerina-extension/src/rpc-managers/ai-panel/rpc-handler.tsworkspaces/ballerina/ballerina-extension/src/rpc-managers/ai-panel/rpc-manager.tsworkspaces/ballerina/ballerina-rpc-client/src/rpc-clients/ai-panel/rpc-client.tsworkspaces/ballerina/ballerina-visualizer/src/views/AIPanel/components/AIChat/index.tsxworkspaces/ballerina/ballerina-visualizer/src/views/AIPanel/components/AIChatInput/hooks/useAttachments.ts
💤 Files with no reviewable changes (2)
- workspaces/ballerina/ballerina-visualizer/src/views/AIPanel/components/AIChat/index.tsx
- workspaces/ballerina/ballerina-visualizer/src/views/AIPanel/components/AIChatInput/hooks/useAttachments.ts
✅ Files skipped from review due to trivial changes (1)
- workspaces/ballerina/ballerina-core/src/rpc-types/ai-panel/rpc-type.ts
🚧 Files skipped from review as they are similar to previous changes (3)
- workspaces/ballerina/ballerina-rpc-client/src/rpc-clients/ai-panel/rpc-client.ts
- workspaces/ballerina/ballerina-extension/src/rpc-managers/ai-panel/rpc-handler.ts
- workspaces/ballerina/ballerina-core/src/rpc-types/ai-panel/index.ts
| const projectPath = StateMachine.context().projectPath; | ||
| const defaultUri = projectPath ? vscode.Uri.file(projectPath) : vscode.Uri.file(os.homedir()); |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Use resolved project root for the picker default directory.
Line 1281 uses only StateMachine.context().projectPath. In workspace-root flows, workspacePath can be the active root, so this can still open outside the current project (the issue this PR is fixing).
Suggested fix
- const projectPath = StateMachine.context().projectPath;
- const defaultUri = projectPath ? vscode.Uri.file(projectPath) : vscode.Uri.file(os.homedir());
+ const projectRootPath = resolveProjectRootPath();
+ const defaultUri = projectRootPath ? vscode.Uri.file(projectRootPath) : vscode.Uri.file(os.homedir());📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const projectPath = StateMachine.context().projectPath; | |
| const defaultUri = projectPath ? vscode.Uri.file(projectPath) : vscode.Uri.file(os.homedir()); | |
| const projectRootPath = resolveProjectRootPath(); | |
| const defaultUri = projectRootPath ? vscode.Uri.file(projectRootPath) : vscode.Uri.file(os.homedir()); |
🤖 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
`@workspaces/ballerina/ballerina-extension/src/rpc-managers/ai-panel/rpc-manager.ts`
around lines 1281 - 1282, The picker default directory is still derived only
from StateMachine.context().projectPath, which can miss the resolved workspace
root in workspace-root flows and open outside the current project. Update the
default URI logic in the rpc-manager.ts picker setup to use the resolved project
root (prefer workspacePath when available, falling back to projectPath, then
home directory) so the picker always starts inside the active workspace. Keep
the change localized around the projectPath/defaultUri assignment in
rpc-manager.ts.
Description
It resolves: wso2/product-integrator#344
We use VS Code’s native file picker instead of the browser’s hidden file input.
Goals
Approach
UI Component Development
npm run storybookfrom the root directory to view current components.Manage Icons
User stories
Release note
Documentation
Training
Certification
Marketing
Automation tests
Security checks
Samples
Related PRs
Migrations (if applicable)
Test environment
Learning
Summary by CodeRabbit