Skip to content

feat: AI Workspace assistant with document search, autocomplete & production fixes - #1

Merged
Aditya-XR merged 6 commits into
mainfrom
feature/ai-workspace
Jul 28, 2026
Merged

Aditya-XR merged 6 commits into
mainfrom
feature/ai-workspace

Conversation

@Aditya-XR

Copy link
Copy Markdown
Owner

🚀 Summary of Changes

  • AI Assistant Sidebar: Integrated Gemini AI assistant (gemini-2.5-flash) into the collaborative text editor.
  • Document Mentions & Search: Added @filename autocomplete and document content extraction from referenced Yjs documents.
  • Production Reliability Fixes:
    • Updated @google/genai SDK implementation to use ai.models.generateContent.
    • Added regex input escaping to /api/documents/search to prevent MongoDB crashes.
    • Added auto-upgrade logic to wss:// WebSockets for live HTTPS environments (Vercel/Railway).

✅ Verification

  • npm run build (Frontend): Passed cleanly.
  • node --check (Backend): Syntax verified with zero errors.

Copilot AI review requested due to automatic review settings July 28, 2026 11:33
@vercel

vercel Bot commented Jul 28, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
collaborative-editor Ready Ready Preview, Comment Jul 28, 2026 11:33am

@Aditya-XR
Aditya-XR merged commit a4a39a6 into main Jul 28, 2026
3 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 @filename autocomplete and “Accept & Insert” behavior.
  • Updated server dependencies (adds @google/genai, bumps ws) and documented GEMINI_API_KEY in .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 thread server/routes/ai.js
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 thread server/routes/ai.js
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 thread server/routes/ai.js
Comment on lines +43 to +45
if (!prompt) {
return res.status(400).json({ error: 'Prompt is required' });
}
Comment thread server/package.json
"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

1 active deployment
Preview — 47f32fd4 Deployed Jul 28, 2026 by vercel[bot]
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