Skip to content

Conversation

jerrinot
Copy link
Contributor

@jerrinot jerrinot commented Aug 4, 2025

explain.webm

@emrberk emrberk self-assigned this Aug 25, 2025
@emrberk emrberk requested a review from Copilot September 1, 2025 13:04
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR integrates LLM-powered query assistance capabilities into the QuestDB web console using Anthropic's Claude API. It adds AI-powered features for explaining SQL queries, generating queries from natural language descriptions, and fixing broken queries through a comprehensive system.

  • Adds Anthropic Claude SDK integration with API key management and validation
  • Implements AI assistant features: query explanation, SQL generation, and error fixing
  • Creates a new diff editor component for query fix previews with accept/reject functionality

Reviewed Changes

Copilot reviewed 29 out of 34 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
packages/web-console/src/utils/claude.ts Core Claude API integration with query explanation, generation, and fixing functionality
packages/web-console/src/components/SetupAIAssistant/index.tsx AI assistant configuration UI component with API key management
packages/web-console/src/scenes/Editor/DiffEditor/index.tsx Diff editor component for previewing and applying query fixes
packages/web-console/src/scenes/Editor/ButtonBar/FixQueryButton.tsx Query fixing button with error detection and AI assistance
packages/web-console/src/components/ExplainQueryButton/index.tsx Query explanation button with AI-powered explanations
packages/web-console/src/components/GenerateSQLButton/index.tsx SQL generation dialog with natural language input
packages/web-console/src/providers/LocalStorageProvider/types.ts Type definitions for AI assistant settings
packages/web-console/src/store/buffers.ts Buffer store extensions for diff buffer support
Files not reviewed (1)
  • .pnp.cjs: Language not supported

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

errorMessage: string,
settings: AiAssistantSettings,
schemaClient?: SchemaToolsClient
): Promise<Partial<GeneratedSQL> | ClaudeAPIError> => {
Copy link

Copilot AI Sep 1, 2025

Choose a reason for hiding this comment

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

Inconsistent return type with other functions. The fixQuery function returns Partial<GeneratedSQL> while generateSQL returns GeneratedSQL. This inconsistency makes the API harder to use and understand.

Suggested change
): Promise<Partial<GeneratedSQL> | ClaudeAPIError> => {
): Promise<GeneratedSQL | ClaudeAPIError> => {

Copilot uses AI. Check for mistakes.

Comment on lines 60 to 65
const extractError = (
queryToFix: Request,
executionRefs: React.MutableRefObject<ExecutionRefs> | undefined,
activeBufferId: string | number | undefined,
editorRef: MutableRefObject<IStandaloneCodeEditor | null>
): { errorMessage: string; fixStart: number; queryText: string } | null => {
Copy link

Copilot AI Sep 1, 2025

Choose a reason for hiding this comment

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

This function has too many parameters and complex logic. Consider extracting this into a custom hook or utility class to improve readability and testability.

Copilot uses AI. Check for mistakes.

Comment on lines 275 to 281
case "'": {
inQuote = !inQuote
if (!inSingleLineComment && !inMultiLineComment) {
inQuote = !inQuote
}
column++
break
}
Copy link

Copilot AI Sep 1, 2025

Choose a reason for hiding this comment

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

The quote handling logic is incomplete. It doesn't differentiate between single quotes (') and double quotes ("), and doesn't handle escaped quotes properly. This could lead to incorrect query parsing when quotes are used inside comments or strings.

Copilot uses AI. Check for mistakes.

Comment on lines 752 to 753
// Anthropic API keys typically start with 'sk-ant-api' and are around 100+ chars
return /^sk-ant-api\d{2}-[\w-]{90,}$/i.test(key)
Copy link

Copilot AI Sep 1, 2025

Choose a reason for hiding this comment

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

The API key validation regex is overly restrictive and may reject valid keys if Anthropic changes their format. Consider using a more flexible validation or making this configurable.

Suggested change
// Anthropic API keys typically start with 'sk-ant-api' and are around 100+ chars
return /^sk-ant-api\d{2}-[\w-]{90,}$/i.test(key)
// Anthropic API keys typically start with 'sk-' and are at least 40+ chars; format may change
return typeof key === 'string' && key.startsWith('sk-') && key.length >= 40

Copilot uses AI. Check for mistakes.

Comment on lines +812 to +816
if (pendingFixRef.current && pendingFixRef.current.originalBufferId === activeBuffer.id) {
const { modifiedContent, queryStartOffset, originalQuery } = pendingFixRef.current
const model = editor.getModel()
if (!model) return
const isValid = model.getValue().slice(queryStartOffset, queryStartOffset + originalQuery.length) === originalQuery
Copy link

Copilot AI Sep 1, 2025

Choose a reason for hiding this comment

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

The pending fix application logic is embedded in the editor setup, making it difficult to test and maintain. This should be extracted into a separate function or utility.

Copilot uses AI. Check for mistakes.

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.

2 participants