Repository navigation
feat: AI Workspace assistant with document search, autocomplete & production fixes - #1
Merged
Merged
Conversation
…websocket protocol
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Pull request overview
Adds an AI assistant feature to the collaborative editor, including document mention autocomplete and backend Gemini integration, while also introducing a few production-oriented reliability adjustments.
Changes:
- Added new backend AI router with
/api/ai/ask(Gemini) and/api/documents/search(mention autocomplete support). - Added an AI sidebar UI in the editor with
@filenameautocomplete and “Accept & Insert” behavior. - Updated server dependencies (adds
@google/genai, bumpsws) and documentedGEMINI_API_KEYin.env.example.
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| server/routes/ai.js | New authenticated endpoints for doc search (mentions) and Gemini-backed AI Q&A with optional referenced-doc extraction. |
| server/index.js | Mounts the new AI router under /api. |
| server/package.json | Adds @google/genai and bumps ws. |
| server/package-lock.json | Locks new dependency graph for @google/genai and the ws version bump. |
| server/.env.example | Adds GEMINI_API_KEY example env var. |
| client/src/components/TextEditor.jsx | Adds AI assistant sidebar UI, mention autocomplete logic, and HTTPS→WSS WebSocket upgrade handling. |
Files not reviewed (1)
- server/package-lock.json: Generated file
Comments suppressed due to low confidence (2)
client/src/components/TextEditor.jsx:759
- The icon-only send button lacks an accessible name. Add aria-label/title so keyboard and screen-reader users can understand the control.
<button
onClick={handleSendPrompt}
disabled={isAiLoading || !promptText.trim()}
className="p-1.5 rounded-full bg-purple-600 hover:bg-purple-700 text-white disabled:opacity-50 disabled:hover:bg-purple-600 transition-colors shrink-0 cursor-pointer"
>
<Send className="w-3.5 h-3.5" />
</button>
server/routes/ai.js:83
- This block both (1) logs extracted document text content (via substring) and (2) appends unbounded document text into the Gemini prompt. Avoid logging any document content, and truncate per-document (and ideally cap total context) to reduce cost/latency and prevent exceeding model limits.
Y.applyUpdate(ydoc, new Uint8Array(updateData));
const text = ydoc.getText('quill').toString();
console.log(`[Server AI Ask] Extracted Yjs text for "${doc.title}" (length: ${text.length}): "${text.substring(0, 100)}..."`);
extractedContext += `\n--- Document: ${doc.title} ---\n${text}\n`;
} else {
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+39
to
+41
| const { prompt, currentDocText } = req.body; | ||
| console.log(`[Server AI Ask] Prompt received: "${prompt}"`); | ||
| console.log(`[Server AI Ask] Current doc text length: ${currentDocText ? currentDocText.length : 0}`); |
Comment on lines
+22
to
+29
| if (q && q.trim() !== '') { | ||
| const safeQuery = q.trim().replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); | ||
| filter.title = { $regex: safeQuery, $options: 'i' }; | ||
| } | ||
|
|
||
| const documents = await Document.find(filter).select('_id title owner collaborators updatedAt'); | ||
| console.log(`[Server AI Search] Found ${documents.length} matching documents.`); | ||
| res.json(documents); |
Comment on lines
+43
to
+45
| if (!prompt) { | ||
| return res.status(400).json({ error: 'Prompt is required' }); | ||
| } |
| "dev": "nodemon index.js" | ||
| }, | ||
| "dependencies": { | ||
| "@google/genai": "^2.12.0", |
Comment on lines
+412
to
+421
| const mention = getActiveMention(value, cursor); | ||
| if (mention) { | ||
| console.log(`[AI Autocomplete] Mentions pattern triggered. Query: "${mention.query}"`); | ||
| setShowMentions(true); | ||
| setMentionIndex(mention.index); | ||
|
|
||
| try { | ||
| const apiUrl = import.meta.env.VITE_API_URL || 'http://localhost:5000/api'; | ||
| const searchUrl = `${apiUrl}/documents/search?q=${encodeURIComponent(mention.query)}`; | ||
| console.log(`[AI Autocomplete] Fetching suggestions from: ${searchUrl}`); |
Comment on lines
+730
to
+735
| <button | ||
| onClick={() => setIsAiOpen(false)} | ||
| className="p-1 rounded-lg text-zinc-500 hover:bg-zinc-100 dark:hover:bg-zinc-800 transition-colors cursor-pointer" | ||
| > | ||
| <X className="w-5 h-5" /> | ||
| </button> |
This branch was successfully deployed
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 of Changes
gemini-2.5-flash) into the collaborative text editor.@filenameautocomplete and document content extraction from referenced Yjs documents.@google/genaiSDK implementation to useai.models.generateContent./api/documents/searchto prevent MongoDB crashes.wss://WebSockets for live HTTPS environments (Vercel/Railway).✅ Verification
npm run build(Frontend): Passed cleanly.node --check(Backend): Syntax verified with zero errors.