Skip to content

Conversation

@dan-niles
Copy link
Contributor

@dan-niles dan-niles commented Nov 14, 2025

Purpose

Closes wso2/product-ballerina-integrator#1487

Adds support to configure the default Devant chunker by adding the following values to Config.toml:

[ballerina.ai.devant.chunkerConfig]
serviceUrl = "https://7eff1239-64bb-4663-b256-30a00d187a5c-prod.e1-us-east-azure.choreoapis.dev/rag-agent/rag-ingester/v1.0"
accessToken = ""

Introduced a new vscode command palette command: Ballerina: Configure default Devant chunker

Summary by CodeRabbit

  • New Features
    • Added support for configuring default Devant chunker in the Ballerina extension. Users can now set up and authenticate the Devant chunker through a new configuration command, expanding AI provider options alongside existing capabilities.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 14, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This pull request adds a new VS Code command to configure default Devant chunker settings in Config.toml. The implementation refactors the configuration system to support multiple AI provider types through a new enum, while adding command registration, constants, and RPC integration following existing patterns.

Changes

Cohort / File(s) Summary
VS Code Extension Manifest
package.json
Added new command contribution ballerina.configureDefaultDevantChunker titled "Configure default Devant chunker" under the Ballerina category.
Configuration Infrastructure
constants.ts
Added ~8 new exported constants for Devant chunker configuration: command identifier, progress/warning/success messages, config table names ([ballerina.ai.wso2ProviderConfig], [ballerina.ai.devant.chunkerConfig]), service URL, and config keys (serviceUrl, accessToken).
Configuration Utilities
utils.ts
Introduced AIProviderConfigType enum with WSO2_MODEL_PROVIDER and DEVANT_CHUNKER members; refactored addConfigFile() to accept optional configType parameter and internally compute config details via new getConfigDetails() helper; replaced hard-coded config values with dynamic enum-driven configuration.
Command Activation & Registration
activator.ts
Registered new CONFIGURE_DEFAULT_DEVANT_CHUNKER_COMMAND with logic mirroring the model provider flow: attempts config addition with AIProviderConfigType.DEVANT_CHUNKER, shows success message on completion, and handles token-related errors with login prompts. Also updated existing model provider call to explicitly pass AIProviderConfigType.WSO2_MODEL_PROVIDER.
RPC Manager Integration
rpc-manager.ts
Added public async method configureDefaultDevantChunker() to AiAgentRpcManager to execute the new command; updated imports to include CONFIGURE_DEFAULT_DEVANT_CHUNKER_COMMAND.

Sequence Diagram

sequenceDiagram
    actor User
    participant VSCode as VS Code
    participant Activator as activator.ts
    participant Utils as utils.ts
    participant Config as Config.toml

    User->>VSCode: Execute "Configure default Devant chunker"
    VSCode->>Activator: Trigger command handler
    Activator->>Activator: Call addConfigFile with<br/>AIProviderConfigType.DEVANT_CHUNKER
    Activator->>Utils: addConfigFile(configPath, DEVANT_CHUNKER)
    Utils->>Utils: getConfigDetails(DEVANT_CHUNKER)<br/>returns: configTable, serviceUrl, progressMessage
    Utils->>Utils: Show progress bar
    Utils->>Config: Update/Write [ballerina.ai.devant.chunkerConfig]<br/>serviceUrl = "..."<br/>accessToken = ""
    
    alt Success
        Utils-->>Activator: return true
        Activator-->>User: Show "Default Devant chunker<br/>configuration added"
    else Token Refresh Error
        Utils-->>Activator: throw error (REFRESH_TOKEN_NOT_AVAILABLE)
        Activator-->>User: Prompt "Sign in to BI Copilot"
        User->>Activator: Click "Sign In"
        Activator->>Activator: Trigger LOGIN state
    else Other Error
        Utils-->>Activator: throw error
        Activator-->>User: Display error message
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Areas requiring attention:

  • Verify the getConfigDetails() helper correctly maps both provider types and returns appropriate values (serviceUrl, progressMessage, configTable)
  • Confirm addConfigFile() default parameter maintains backward compatibility with existing calls
  • Validate error handling consistency between WSO2 and Devant chunker flows (both should handle REFRESH_TOKEN_NOT_AVAILABLE_ERROR_MESSAGE and TOKEN_REFRESH_ONLY_SUPPORTED_FOR_BI_INTEL identically)
  • Ensure the shared access token mechanism works correctly (same token used for both WSO2 model provider and Devant chunker per issue description)
  • Review the new enum values and their usage across multiple files for consistency

Suggested reviewers

  • hevayo
  • gigara

Poem

🐰 A chunker now configured with care,
Devant defaults flowing through the air,
With tokens shared and URLs set true,
Commands refactored—patterns shine anew!
From WSO2's wisdom, reusable and bright, 🌟

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and clearly describes the main change: adding support for configuring the default Devant chunker in VS Code.
Description check ✅ Passed The description is minimal but includes the critical information: issue link, purpose, and specific configuration details being added. However, it omits most template sections.
Linked Issues check ✅ Passed All code changes successfully implement the requirements from issue #1487: a new VS Code command to configure Devant chunker with the specified toml configuration block and accessToken field.
Out of Scope Changes check ✅ Passed All changes are directly related to the Devant chunker configuration feature. The refactoring of addConfigFile to support multiple provider types is necessary infrastructure for this feature.

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.

@dan-niles dan-niles force-pushed the devant-chunker-vscode-command branch from ee9de65 to 9331173 Compare November 14, 2025 06:21
@dan-niles dan-niles marked this pull request as ready for review November 14, 2025 06:21
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
workspaces/ballerina/ballerina-extension/src/features/ai/activator.ts (1)

89-133: Shared configPath handling can misbehave when no Ballerina project is open

Both configuration commands use:

const configPath = await getConfigFilePath(ballerinaExternalInstance, projectPath);
if (configPath !== null) {
    // ...
}

However, getConfigFilePath can resolve to undefined (e.g., when there is no Ballerina project and only a warning is shown). In that case the !== null check passes and addConfigFile is called with a non-string path, which will end up throwing a low-level fs error and surfacing a confusing error message to the user.

You’re reusing this pattern for the new Devant chunker command as well, so the edge case now affects both flows.

A more robust guard would be to bail out on any falsy/invalid value:

const configPath = await getConfigFilePath(ballerinaExternalInstance, projectPath);
if (!configPath) {
    return;
}

const result = await addConfigFile(configPath, AIProviderConfigType.WSO2_MODEL_PROVIDER);
// ...

and similarly for the Devant chunker command.

🧹 Nitpick comments (2)
workspaces/ballerina/ballerina-extension/src/features/ai/activator.ts (1)

25-31: Minor import path nit for auth utilities

'../..//utils/ai/auth' will resolve correctly, but the double slash is unnecessary and slightly inconsistent with other imports. Consider normalizing to '../../utils/ai/auth' for clarity.

workspaces/ballerina/ballerina-extension/src/features/ai/utils.ts (1)

182-245: Config file mutation helper correctly handles both WSO2 and Devant chunker tables

addAIProviderConfig:

  • Uses CONFIG_FILE_NAME with a case-insensitive lookup, so it works with config.toml vs Config.toml.
  • Creates the target table if missing, and otherwise updates it in-place.
  • Ensures serviceUrl and accessToken lines are present and keeps accessToken immediately after serviceUrl, which keeps the table structure predictable.

Combined with addConfigFile and the shared token retrieval, this covers both WSO2 model provider and Devant chunker without duplicating file-IO logic.

If you want to harden it further, an optional improvement would be to early-return false from addAIProviderConfig when projectPath does not exist (instead of relying on fs.readdirSync to throw), but that’s already mitigated in practice by getConfigFilePath.

Also applies to: 247-283

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 20f6525 and 9331173.

📒 Files selected for processing (5)
  • workspaces/ballerina/ballerina-extension/package.json (1 hunks)
  • workspaces/ballerina/ballerina-extension/src/features/ai/activator.ts (3 hunks)
  • workspaces/ballerina/ballerina-extension/src/features/ai/constants.ts (2 hunks)
  • workspaces/ballerina/ballerina-extension/src/features/ai/utils.ts (7 hunks)
  • workspaces/ballerina/ballerina-extension/src/rpc-managers/ai-agent/rpc-manager.ts (2 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-11-10T15:05:11.309Z
Learnt from: madushajg
Repo: wso2/vscode-extensions PR: 868
File: workspaces/bi/bi-extension/src/utils.ts:224-242
Timestamp: 2025-11-10T15:05:11.309Z
Learning: The workspaces/bi/bi-extension and workspaces/ballerina/ballerina-extension are separate VS Code extensions that are packaged and distributed independently, so they cannot share code via imports and must maintain their own implementations of common utilities.

Applied to files:

  • workspaces/ballerina/ballerina-extension/package.json
📚 Learning: 2025-11-10T15:04:50.474Z
Learnt from: madushajg
Repo: wso2/vscode-extensions PR: 868
File: workspaces/bi/bi-extension/src/utils.ts:153-169
Timestamp: 2025-11-10T15:04:50.474Z
Learning: The workspaces/bi/bi-extension and workspaces/ballerina/ballerina-extension are separate, independently deployable VSCode extensions in the wso2/vscode-extensions repository. Code duplication between these extensions is acceptable and often necessary to maintain their independence, rather than creating cross-extension dependencies.

Applied to files:

  • workspaces/ballerina/ballerina-extension/package.json
🧬 Code graph analysis (3)
workspaces/ballerina/ballerina-extension/src/rpc-managers/ai-agent/rpc-manager.ts (1)
workspaces/ballerina/ballerina-extension/src/features/ai/constants.ts (1)
  • CONFIGURE_DEFAULT_DEVANT_CHUNKER_COMMAND (21-21)
workspaces/ballerina/ballerina-extension/src/features/ai/utils.ts (2)
workspaces/ballerina/ballerina-extension/src/features/ai/constants.ts (7)
  • CONFIG_KEY_SERVICE_URL (38-38)
  • CONFIG_KEY_ACCESS_TOKEN (39-39)
  • WSO2_PROVIDER_CONFIG_TABLE (35-35)
  • PROGRESS_BAR_MESSAGE_FROM_WSO2_DEFAULT_MODEL (25-25)
  • DEVANT_CHUNKER_CONFIG_TABLE (36-36)
  • DEVANT_CHUNKER_SERVICE_URL (37-37)
  • PROGRESS_BAR_MESSAGE_FROM_DEFAULT_DEVANT_CHUNKER (26-26)
workspaces/ballerina/ballerina-extension/src/features/natural-programming/utils.ts (1)
  • addConfigFile (703-725)
workspaces/ballerina/ballerina-extension/src/features/ai/activator.ts (3)
workspaces/ballerina/ballerina-extension/src/features/ai/utils.ts (2)
  • addConfigFile (247-283)
  • getConfigFilePath (103-145)
workspaces/ballerina/ballerina-extension/src/features/ai/constants.ts (4)
  • CONFIGURE_DEFAULT_DEVANT_CHUNKER_COMMAND (21-21)
  • DEFAULT_DEVANT_CHUNKER_ADDED (32-32)
  • LOGIN_REQUIRED_WARNING_FOR_DEFAULT_DEVANT_CHUNKER (31-31)
  • SIGN_IN_BI_COPILOT (24-24)
workspaces/ballerina/ballerina-extension/src/utils/ai/auth.ts (2)
  • REFRESH_TOKEN_NOT_AVAILABLE_ERROR_MESSAGE (26-26)
  • TOKEN_REFRESH_ONLY_SUPPORTED_FOR_BI_INTEL (27-27)
🔇 Additional comments (4)
workspaces/ballerina/ballerina-extension/package.json (1)

485-493: New Devant chunker command contribution is consistent and correctly wired

The new ballerina.configureDefaultDevantChunker contribution matches the constant in constants.ts, follows the existing naming pattern (Configure default ...), and is categorized under "Ballerina". No issues here.

workspaces/ballerina/ballerina-extension/src/rpc-managers/ai-agent/rpc-manager.ts (1)

49-50: RPC wiring for Devant chunker configuration is clean and symmetric

configureDefaultDevantChunker() mirrors configureDefaultModelProvider() and correctly uses CONFIGURE_DEFAULT_DEVANT_CHUNKER_COMMAND. This keeps the RPC manager thin and consistent with existing patterns.

Also applies to: 512-518

workspaces/ballerina/ballerina-extension/src/features/ai/utils.ts (1)

27-37: Enum‑based provider configuration details are well-structured

The introduction of AIProviderConfigType plus getConfigDetails cleanly separates provider-specific concerns (table name, service URL, progress message) from the generic config-writing logic. This will make it straightforward to add more provider types later without touching the core flow.

Also applies to: 51-55, 285-309

workspaces/ballerina/ballerina-extension/src/features/ai/constants.ts (1)

21-39: Devant chunker and shared config constants align with usage and spec

The new constants for:

  • CONFIGURE_DEFAULT_DEVANT_CHUNKER_COMMAND
  • Devant chunker progress/login/default-added messages
  • Provider config tables, keys, and DEVANT_CHUNKER_SERVICE_URL

are consistent with the PR description and with how they’re consumed in utils.ts, activator.ts, rpc-manager.ts, and package.json. No issues spotted.

@dan-niles dan-niles marked this pull request as draft December 1, 2025 04:33
@dan-niles dan-niles force-pushed the devant-chunker-vscode-command branch from 9331173 to f8d8cb5 Compare December 3, 2025 09:45
@dan-niles dan-niles force-pushed the devant-chunker-vscode-command branch from f8d8cb5 to 521be6c Compare December 5, 2025 06:21
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.

Add VS code command to configure default devant chunker

1 participant