-
-
Notifications
You must be signed in to change notification settings - Fork 108
feat(runner): adds sql query runner ai tab auto completion #223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 2 commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
3347494
feat: adds sql query runner ai auto completion
Rudra-Sankha-Sinhamahapatra 17d4827
Merge branch 'main' into feat/sql-auto-completions
Rudra-Sankha-Sinhamahapatra 92aeaeb
fix: catalog monacopilot version and console.logs removed
Rudra-Sankha-Sinhamahapatra eb72623
fix: remove typescript error
Rudra-Sankha-Sinhamahapatra ab12ba8
fix: removing endpoint since fetching from orpc
Rudra-Sankha-Sinhamahapatra 3ad7228
fix: handle mount
Rudra-Sankha-Sinhamahapatra 3a2d975
fix: added completion cache to reduce unnecessary api calls
Rudra-Sankha-Sinhamahapatra c7938f9
Merge branch 'main' into feat/sql-auto-completions
Rudra-Sankha-Sinhamahapatra 6e492be
fix: lint issue during push
Rudra-Sankha-Sinhamahapatra b782c7e
fix: merge conflicts
Rudra-Sankha-Sinhamahapatra 3f9d557
Merge branch 'main' of https://github.com/wannabespace/conar into fea…
letstri 167a4b8
refactor: made useEffect as a separate component
Rudra-Sankha-Sinhamahapatra b9f2149
fix: merge conflicts
Rudra-Sankha-Sinhamahapatra 55ec7e4
fix: merge conflicts
Rudra-Sankha-Sinhamahapatra 13e9da7
refactor: merge with main
Rudra-Sankha-Sinhamahapatra a8e8de2
Merge branch 'main' of https://github.com/wannabespace/conar into fea…
Rudra-Sankha-Sinhamahapatra 72ba4cf
fix: using DatabaseType instead of manually defining
Rudra-Sankha-Sinhamahapatra c23bbbf
refactor: moved a lot of code from useEffect to outside
Rudra-Sankha-Sinhamahapatra 37f3deb
Merge branch 'feat/sql-auto-completions' of https://github.com/wannab…
letstri bb01f51
Merge branch 'main' of https://github.com/wannabespace/conar into fea…
letstri d94244f
Merge branch 'main' of https://github.com/wannabespace/conar into fea…
Rudra-Sankha-Sinhamahapatra bf83f7e
fix: monaco console errors & added abort prev api call
Rudra-Sankha-Sinhamahapatra 648250c
fix: eslint issue
Rudra-Sankha-Sinhamahapatra d45f548
Merge branch 'main' of https://github.com/wannabespace/conar into fea…
letstri 4880fd0
refactor: update AI tab completion logic
letstri 4ff2090
refactor: improve context generation in database AI completion
letstri 5ddd450
refactor: enhance prompt formatting for SQL code completion assistant
letstri ccd6157
refactor: replace auth middleware with subscription requirement for c…
letstri f7a61c3
chore: merge with main
Rudra-Sankha-Sinhamahapatra af5e1a4
fix: auto completion issue
Rudra-Sankha-Sinhamahapatra fa6e954
Merge branch 'main' of https://github.com/wannabespace/conar into fea…
Rudra-Sankha-Sinhamahapatra ad7ffbb
Merge branch 'main' of https://github.com/wannabespace/conar into fea…
Rudra-Sankha-Sinhamahapatra 9bf0187
refactor: merge with main
Rudra-Sankha-Sinhamahapatra 1806867
refactor: merge with main
Rudra-Sankha-Sinhamahapatra 4d56616
refactor: merge with main
Rudra-Sankha-Sinhamahapatra b0f89c3
Merge branch 'main' of https://github.com/wannabespace/conar into fea…
letstri dbcdb68
fix: merge conflicts
Rudra-Sankha-Sinhamahapatra 6aea6db
chore(deps): update monacopilot to v1.2.12
Rudra-Sankha-Sinhamahapatra 0dff40b
Merge branch 'main' of https://github.com/wannabespace/conar into fea…
Rudra-Sankha-Sinhamahapatra e29d3ce
Merge branch 'main' of https://github.com/wannabespace/conar into fea…
Rudra-Sankha-Sinhamahapatra fb58058
fix: lint errors
Rudra-Sankha-Sinhamahapatra 7d994ed
Merge branch 'main' of https://github.com/wannabespace/conar into fea…
Rudra-Sankha-Sinhamahapatra d4eabbd
Merge branch 'main' of https://github.com/wannabespace/conar into fea…
Rudra-Sankha-Sinhamahapatra b3e4dee
Merge branch 'main' of https://github.com/wannabespace/conar into fea…
Rudra-Sankha-Sinhamahapatra 1e1fa70
Merge branch 'main' of https://github.com/wannabespace/conar into fea…
letstri 05eeb21
chore: change gemini model
letstri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| import { google } from '@ai-sdk/google' | ||
| import { generateText } from 'ai' | ||
| import { z } from 'zod' | ||
| import { authMiddleware, orpc } from '~/orpc' | ||
|
|
||
| export const codeCompletion = orpc | ||
| .use(authMiddleware) | ||
| .input(z.object({ | ||
| context: z.string(), | ||
| suffix: z.string().optional(), | ||
| instruction: z.string().optional(), | ||
| fileContent: z.string(), | ||
| databaseType: z.enum(['postgres', 'mysql', 'clickhouse']), | ||
| schemaContext: z.string().optional(), | ||
| })) | ||
| .output(z.object({ | ||
| completion: z.string(), | ||
| })) | ||
| .handler(async ({ input }) => { | ||
| try { | ||
| const databaseType = input.databaseType || 'postgres' | ||
| const schemaContext = input.schemaContext || '' | ||
|
|
||
| const enhancedPrompt = `You are an expert SQL code completion assistant. | ||
|
|
||
| Database Type: ${databaseType} | ||
|
|
||
| Database Schema: | ||
| ${schemaContext} | ||
|
|
||
| Current Code BEFORE Cursor: | ||
| ${input.context || ''} | ||
|
|
||
| Current Code AFTER Cursor: | ||
| ${input.suffix || ''} | ||
|
|
||
| Full File Content: | ||
| ${input.fileContent || ''} | ||
|
|
||
| Task: ${input.instruction || 'Complete the SQL query'} | ||
|
|
||
| General Safety Rules: | ||
| - Prioritize SELECT queries (read-only) when the intent is ambiguous. | ||
| - If the user explicitly starts writing a data modification query (INSERT, UPDATE, etc.), complete it validly. | ||
| - Do NOT generate destructive schema changes (DROP TABLE, TRUNCATE, ALTER) unless explicitly requested in a generic comment. | ||
|
|
||
| Specific Instructions: | ||
| - If the context is empty (start of file), return an empty string. | ||
| - For UUID/CUID: Use generation functions (e.g. gen_random_uuid()) instead of hardcoded strings if possible. | ||
| - For Foreign Keys: Do NOT plain guess IDs. Use subqueries (e.g. "(SELECT id FROM users ... LIMIT 1)") to make the query robust without needing external tools. | ||
| - Look at "Current Code AFTER Cursor". Do NOT generate code that is already present there (like closing parenthesis or semicolons). Make your completion join smoothly with the suffix. | ||
|
|
||
| Generate ONLY the completion text that should be inserted at the cursor position. | ||
| - Do NOT repeat the code that is already present before the cursor. | ||
| - Do NOT wrap in markdown code blocks. | ||
| - If no completion is needed, return an empty string.` | ||
|
|
||
| const result = await generateText({ | ||
| model: google('gemini-2.0-flash'), | ||
| prompt: enhancedPrompt, | ||
| }) | ||
|
|
||
| console.log('Generated completion (raw):', result.text.substring(0, 100)) | ||
|
Rudra-Sankha-Sinhamahapatra marked this conversation as resolved.
Outdated
|
||
|
|
||
| let cleanText = result.text.trim() | ||
| if (cleanText.startsWith('```')) { | ||
| cleanText = cleanText.replace(/^```\w*\s*/, '').replace(/\s*```$/, '') | ||
| } | ||
|
|
||
| return { | ||
| completion: cleanText, | ||
| } | ||
| } | ||
| catch (error) { | ||
| console.error('Error in completion handler:', error instanceof Error ? error.message : 'Unknown error') | ||
| return { | ||
| completion: '', | ||
| } | ||
| } | ||
| }) | ||
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
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
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.