Skip to content

Use VS Code native file dialog for AI panel attachments#2156

Open
VellummyilumVinoth wants to merge 1 commit into
wso2:release/ballerina-5.12.xfrom
VellummyilumVinoth:fix-attachment-picker
Open

Use VS Code native file dialog for AI panel attachments#2156
VellummyilumVinoth wants to merge 1 commit into
wso2:release/ballerina-5.12.xfrom
VellummyilumVinoth:fix-attachment-picker

Conversation

@VellummyilumVinoth

@VellummyilumVinoth VellummyilumVinoth commented May 4, 2026

Copy link
Copy Markdown
Contributor

Description

It resolves: wso2/product-integrator#344

We use VS Code’s native file picker instead of the browser’s hidden file input.

Goals

Describe the solutions that this feature/fix will introduce to resolve the problems described above

Approach

Describe how you are implementing the solutions. Include an animated GIF or screenshot if the change affects the UI (email documentation@wso2.com to review all UI text). Include a link to a Markdown file or Google doc if the feature write-up is too long to paste here.

UI Component Development

Specify the reason if following are not followed.

  • Added reusable UI components to the ui-toolkit. Follow the intructions when adding the componenent.
  • Use ui-toolkit components wherever possible. Run npm run storybook from the root directory to view current components.
  • Matches with the native VSCode look and feel.

Manage Icons

Specify the reason if following are not followed.

  • Added Icons to the font-wso2-vscode. Follow the instructions.

User stories

Summary of user stories addressed by this change>

Release note

Brief description of the new feature or bug fix as it will appear in the release notes

Documentation

Link(s) to product documentation that addresses the changes of this PR. If no doc impact, enter “N/A” plus brief explanation of why there’s no doc impact

Training

Link to the PR for changes to the training content in https://github.com/wso2/WSO2-Training, if applicable

Certification

Type “Sent” when you have provided new/updated certification questions, plus four answers for each question (correct answer highlighted in bold), based on this change. Certification questions/answers should be sent to certification@wso2.com and NOT pasted in this PR. If there is no impact on certification exams, type “N/A” and explain why.

Marketing

Link to drafts of marketing content that will describe and promote this feature, including product page changes, technical articles, blog posts, videos, etc., if applicable

Automation tests

  • Unit tests

    Code coverage information

  • Integration tests

    Details about the test cases and coverage

Security checks

Samples

Provide high-level details about the samples related to this feature

Related PRs

List any other related PRs

Migrations (if applicable)

Describe migration steps and platforms on which migration has been tested

Test environment

List all JDK versions, operating systems, databases, and browser/versions on which this feature/fix was tested

Learning

Describe the research phase and any blog posts, patterns, libraries, or add-ons you used to solve the problem.

Summary by CodeRabbit

  • New Features
    • AI Panel: users can attach files via an editor multi-file picker (files only) with a 5MB per-file size limit; oversized or failed reads are returned as non-success items.
    • Attach from chat UI: the attach control now supports an async picker flow that fetches selected context files and adds only successful attachments.
    • Attachments handling: successful items are merged, duplicates are replaced (matched by name + content), and content is encoded appropriately based on the active command/skill context.

@coderabbitai

coderabbitai Bot commented May 4, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds 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.

Changes

File Attachment Selection via VS Code Dialog

Layer / File(s) Summary
Data shapes and RPC declarations
workspaces/ballerina/ballerina-core/src/rpc-types/ai-panel/*
Adds SelectContextFilesRequest and exposes selectContextFiles on the AI panel RPC and public API using Attachment[].
Extension file selection
workspaces/ballerina/ballerina-extension/src/rpc-managers/ai-panel/rpc-manager.ts
AiPanelRpcManager.selectContextFiles opens a multi-file picker, roots it in the current project or home directory, enforces a 5MB limit, reads file content, and assigns AttachmentStatus values.
RPC handler and client
workspaces/ballerina/ballerina-extension/src/rpc-managers/ai-panel/rpc-handler.ts, workspaces/ballerina/ballerina-rpc-client/src/rpc-clients/ai-panel/rpc-client.ts
Registers messenger.onRequest(selectContextFiles, ...) in the extension and adds AiPanelRpcClient.selectContextFiles to send the request and return Attachment[].
UI attachment flow
workspaces/ballerina/ballerina-visualizer/src/views/AIPanel/components/AIChat/index.tsx, .../AIChatInput/hooks/useAttachments.ts
Footer attachment options call selectContextFiles, and useAttachments accepts an onAttachClick callback, filters successful attachments, de-dupes by name and content, and merges them into state.

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • hevayo
  • gigara

Poem

🐰
I hop to the picker, swift and bright,
Into the working folder, just right.
Files come back in a tidy stream,
Base64 or text in a rabbit dream.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description has the issue link and intent, but most required template sections are left as placeholders or blank. Fill the required template sections, especially Purpose, Goals, Approach, Release note, Documentation, tests, security, and test environment.
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: switching AI panel attachments to VS Code's native file dialog.
Linked Issues check ✅ Passed The changes satisfy #344 by routing Attach context through VS Code's native picker and rooting it in the current project path.
Out of Scope Changes check ✅ Passed The added RPC plumbing, UI hook changes, and file-selection logic all support the attachment-picker fix and appear in scope.

✏️ 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.

@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: 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

📥 Commits

Reviewing files that changed from the base of the PR and between 1f256ea and 2a02785.

📒 Files selected for processing (8)
  • workspaces/ballerina/ballerina-core/src/rpc-types/ai-panel/index.ts
  • workspaces/ballerina/ballerina-core/src/rpc-types/ai-panel/interfaces.ts
  • workspaces/ballerina/ballerina-core/src/rpc-types/ai-panel/rpc-type.ts
  • workspaces/ballerina/ballerina-extension/src/rpc-managers/ai-panel/rpc-handler.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
  • workspaces/ballerina/ballerina-visualizer/src/views/AIPanel/components/AIChat/index.tsx
  • workspaces/ballerina/ballerina-visualizer/src/views/AIPanel/components/AIChatInput/hooks/useAttachments.ts

@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: 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

📥 Commits

Reviewing files that changed from the base of the PR and between 2a02785 and cb10dca.

📒 Files selected for processing (8)
  • workspaces/ballerina/ballerina-core/src/rpc-types/ai-panel/index.ts
  • workspaces/ballerina/ballerina-core/src/rpc-types/ai-panel/interfaces.ts
  • workspaces/ballerina/ballerina-core/src/rpc-types/ai-panel/rpc-type.ts
  • workspaces/ballerina/ballerina-extension/src/rpc-managers/ai-panel/rpc-handler.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
  • 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 (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

@VellummyilumVinoth VellummyilumVinoth marked this pull request as draft May 8, 2026 04:15
@VellummyilumVinoth VellummyilumVinoth marked this pull request as ready for review May 19, 2026 06:33

@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: 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

📥 Commits

Reviewing files that changed from the base of the PR and between cb10dca and 6c89dc1.

📒 Files selected for processing (8)
  • workspaces/ballerina/ballerina-core/src/rpc-types/ai-panel/index.ts
  • workspaces/ballerina/ballerina-core/src/rpc-types/ai-panel/interfaces.ts
  • workspaces/ballerina/ballerina-core/src/rpc-types/ai-panel/rpc-type.ts
  • workspaces/ballerina/ballerina-extension/src/rpc-managers/ai-panel/rpc-handler.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
  • 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-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

@VellummyilumVinoth VellummyilumVinoth force-pushed the fix-attachment-picker branch 2 times, most recently from 68b167d to 9a0b47f Compare June 24, 2026 09:05

@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: 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

📥 Commits

Reviewing files that changed from the base of the PR and between 6c89dc1 and 0dd1697.

📒 Files selected for processing (8)
  • workspaces/ballerina/ballerina-core/src/rpc-types/ai-panel/index.ts
  • workspaces/ballerina/ballerina-core/src/rpc-types/ai-panel/interfaces.ts
  • workspaces/ballerina/ballerina-core/src/rpc-types/ai-panel/rpc-type.ts
  • workspaces/ballerina/ballerina-extension/src/rpc-managers/ai-panel/rpc-handler.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
  • workspaces/ballerina/ballerina-visualizer/src/views/AIPanel/components/AIChat/index.tsx
  • workspaces/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

Comment on lines +1281 to +1282
const projectPath = StateMachine.context().projectPath;
const defaultUri = projectPath ? vscode.Uri.file(projectPath) : vscode.Uri.file(os.homedir());

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.

🎯 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.

Suggested change
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.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant