feat: Add natural language to query feature#2859
Merged
Conversation
* Initial plan * Remove getConnectionInfo references from OperationParser and CosmosDbOperationsService Co-authored-by: languy <21954022+languy@users.noreply.github.com>
…out with chatBox styling
…generation and content restrictions
…/cdb-chat-participant-with-copilot-query
…ide-by-side; refactor imports for consistency
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a GitHub Copilot–backed natural-language-to-query workflow for the Cosmos DB Query Editor and introduces a new @cosmosdb VS Code chat participant with query generation/explanation commands, schema sampling tool support, and related utilities.
Changes:
- Introduces
@cosmosdbchat participant with/editQuery,/generateQuery,/explainQuery,/question, plus supporting prompts/payload formatting and tooling. - Adds an “AI” entry point in the Query Editor UI (toolbar + generate input) and wires webview ↔ extension commands/events for query generation and explanation.
- Adds schema sampling + sanitization + Copilot availability utilities, along with unit tests and a NoSQL query language reference asset.
Reviewed changes
Copilot reviewed 37 out of 38 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/webviews/cosmosdb/QueryEditor/state/QueryEditorState.tsx | Adds AI-related UI state flags and actions. |
| src/webviews/cosmosdb/QueryEditor/state/QueryEditorContextProvider.tsx | Adds new AI commands/events wiring (query generation + AI enablement). |
| src/webviews/cosmosdb/QueryEditor/state/QueryEditorContext.tsx | Exposes internal reducer dispatch via context for UI components. |
| src/webviews/cosmosdb/QueryEditor/QueryPanel/usePromptHistory.ts | New hook to support prompt history navigation in the generate input. |
| src/webviews/cosmosdb/QueryEditor/QueryPanel/QueryToolbarOverflow.tsx | Adds conditional AI button/menu item and adjusts overflow IDs. |
| src/webviews/cosmosdb/QueryEditor/QueryPanel/QueryPanel.tsx | Renders the new query-generation input area. |
| src/webviews/cosmosdb/QueryEditor/QueryPanel/QueryMonaco.tsx | Syncs initial Monaco value back to state/extension on mount. |
| src/webviews/cosmosdb/QueryEditor/QueryPanel/GenerateQueryInput.tsx | New UI for NL prompt entry, model selection, loading, confirmation, feedback. |
| src/webviews/cosmosdb/QueryEditor/QueryPanel/ExplainQueryButton.tsx | New button to open Copilot chat for query explanation. |
| src/webviews/cosmosdb/QueryEditor/QueryPanel/AIButton.tsx | New AI menu/button that routes to generate/explain actions. |
| src/webviews/cosmosdb/QueryEditor/QueryEditor.tsx | Adjusts pane size defaults to accommodate new UI. |
| src/utils/sanitization.ts | Adds shared sanitization helpers for markdown/code/URIs and SQL comments. |
| src/utils/sanitization.test.ts | Unit tests for sanitization helpers. |
| src/utils/json/nosql/SchemaAnalyzer.ts | Adds schema inference/aggregation utilities for sampled documents. |
| src/utils/json/nosql/NoSqlTypes.ts | Adds NoSQL type inference and JSON type mapping helpers. |
| src/utils/copilotUtils.ts | Adds Copilot availability detection + retry/listeners. |
| src/utils/copilotUtils.test.ts | Unit tests for Copilot availability utilities. |
| src/panels/QueryEditorTab.ts | Adds extension-side query generation, model selection, and AI state broadcast to webviews. |
| src/extensionVariables.ts | Adds a global AI-enabled flag to the extension namespace. |
| src/extension.ts | Registers chat participant + tool, initializes AI availability tracking. |
| src/cosmosdb/session/QuerySession.ts | Records query execution history for AI context. |
| src/commands/registerCommands.ts | Registers chat button commands for applying/opening suggested queries. |
| src/chat/userPayload.ts | Defines and formats user payload blocks with delimiters for LLM requests. |
| src/chat/systemPrompt.ts | Adds system prompts/defense rules and query generation/explanation instructions. |
| src/chat/systemPrompt.test.ts | Tests prompt composition/defense rule inclusion. |
| src/chat/sampleDataTool.ts | Adds LM tool to sample container schema and return inferred structure. |
| src/chat/queryOneShotExamples.ts | Adds few-shot examples to guide query generation. |
| src/chat/index.ts | Exports chat module surface area. |
| src/chat/cosmosDbChatParticipant.ts | Implements the @cosmosdb chat participant and routing/operations. |
| src/chat/chatUtils.ts | Adds LM request helpers, message ordering utilities, and active editor helpers. |
| src/chat/chatUtils.test.ts | Unit tests for message ordering helper. |
| src/chat/README.md | Documents chat participant usage and capabilities. |
| src/chat/OperationParser.ts | Adds suggestion text for next operations based on context. |
| resources/azurecosmosdb-nosql-query-language.md | Adds a NoSQL query language reference used for query generation guidance. |
| package.json | Registers chat participant, tool activation events, commands, and dependency updates. |
| l10n/bundle.l10n.json | Updates localization bundle with new user-facing strings. |
bk201-
reviewed
Mar 20, 2026
Co-authored-by: Vsevolod Kukol <sevoku@microsoft.com>
sevoku
reviewed
Mar 26, 2026
…s DB chat participant
…rors for better handling
…t.tsx Co-authored-by: Dmitry Shilov <dshilov@microsoft.com>
…ted functions in SchemaAnalyzer
…ttps://github.com/microsoft/vscode-cosmosdb into dev/languye/cdb-chat-participant-with-copilot-query
…endency in GenerateQueryInput Agent-Logs-Url: https://github.com/microsoft/vscode-cosmosdb/sessions/8dd257b6-5cb4-4224-997a-8e9279cf9269 Co-authored-by: languy <21954022+languy@users.noreply.github.com>
…ttps://github.com/microsoft/vscode-cosmosdb into dev/languye/cdb-chat-participant-with-copilot-query
sevoku
previously approved these changes
Mar 27, 2026
bk201-
previously approved these changes
Mar 27, 2026
…related messages. Show error on vscode, not in webview. Display LLM output as debug instead of info.
sevoku
approved these changes
Mar 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds AI-powered natural language to Cosmos DB NoSQL query capabilities, integrating GitHub Copilot into the Azure Cosmos DB VS Code extension. Users can generate, explain, and edit queries using natural language — both from the Query Editor toolbar and via a
@cosmosdbchat participant in VS Code Chat.Key Features
@cosmosdbChat Participant@cosmosdb) with dedicated slash commands:/generateQuery— Generate a new Cosmos DB NoSQL query from a natural language description/explainQuery— Get an AI-powered explanation of the current query/editQuery— Edit/optimize an existing query with AI suggestions/question— Ask general Azure Cosmos DB questions/help— Show available commandsQuery Editor AI Integration
GenerateQueryInputcomponent: a text area for entering natural language prompts directly in the query editor panel@cosmosdb /explainQuerypre-filledSchema Sampling Tool (
cosmosdb_sampleContainerSchema)SELECT TOP 10 * FROM c WHERE c._ts % 2 = 0 ORDER BY c._ts DESC) to minimize RU costQuery Execution History
CosmosDbOperationsServicemaintains per-container in-memory query history (last 20 executions per container)Architecture
CosmosDbChatParticipantCosmosDbOperationsServicesystemPrompt.tsuserPayload.tsqueryOneShotExamples.tssampleDataTool.tssanitization.tscopilotUtils.tsSchemaAnalyzer.tsdenquefor efficient queue)Security
systemPrompt.test.ts)BEGIN_USER_DATA/END_USER_DATA) to prevent instruction injection--comment contextcommand:URI injectionOther Changes
denque(efficient double-ended queue for schema analyzer BFS traversal)chatUtils,systemPrompt,sanitization, andcopilotUtils39 files changed | +7,313 additions | -35 deletions