-
Notifications
You must be signed in to change notification settings - Fork 0
Implement document upload and management system for AI agents #39
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
Implement document upload and management system for AI agents #39
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Co-authored-by: tikazyq <[email protected]>
Co-authored-by: tikazyq <[email protected]>
Co-authored-by: tikazyq <[email protected]>
There was a problem hiding this 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 implements a comprehensive document upload and management system that enables AI agents to attach files to devlog entries. The system supports various file types (text, images, PDFs, code files, etc.) with automatic type detection, content extraction for searchable documents, and full CRUD operations through both REST API endpoints and MCP tools.
Key changes include:
- New Document Infrastructure: Added
DevlogDocumenttypes,DocumentServicesingleton, andDevlogDocumentEntitywith TypeORM mappings - REST API Endpoints: Implemented document upload, listing, retrieval, and deletion endpoints following existing patterns
- MCP Tool Integration: Added 5 new MCP tools for AI agents to manage document attachments with proper validation
Reviewed Changes
Copilot reviewed 18 out of 19 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/mcp/src/tools/index.ts | Exported new document tools and updated tool count to 15 |
| packages/mcp/src/tools/document-tools.ts | Added 5 MCP tools for document operations with clear descriptions |
| packages/mcp/src/schemas/document-schemas.ts | Defined validation schemas for document operations |
| packages/mcp/src/handlers/tool-handlers.ts | Added document operation handlers with proper validation |
| packages/mcp/src/api/devlog-api-client.ts | Extended API client with document upload methods using FormData |
| packages/mcp/src/adapters/mcp-adapter.ts | Implemented document operation adapters with base64 handling |
| packages/core/src/utils/id-generator.ts | Added utilities for generating unique document IDs |
| packages/core/src/types/core.ts | Added DocumentType enum and DevlogDocument interface |
| packages/core/src/services/document-service.ts | Implemented core document service with CRUD operations and type detection |
| packages/core/src/services/devlog-service.ts | Enhanced to optionally include documents when retrieving devlogs |
| packages/core/src/entities/devlog-document.entity.ts | Created TypeORM entity for document storage with JSON metadata support |
| apps/web/app/api/projects/[name]/devlogs/[devlogId]/documents/route.ts | Implemented document upload and listing REST endpoints |
| apps/web/app/api/projects/[name]/devlogs/[devlogId]/documents/[documentId]/route.ts | Implemented document retrieval and deletion REST endpoints |
| // For getDocument, we need to find which devlog contains the document | ||
| // This is a limitation of the current API design - we'll try a simple approach | ||
| // by searching through recent devlogs | ||
| const devlogs = await this.apiClient.listDevlogs({ |
Copilot
AI
Aug 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The getDocument and deleteDocument methods search through up to 20 devlogs sequentially to find a document. This creates an O(n) search pattern that could become inefficient with many devlogs. Consider adding a direct document lookup API endpoint or maintaining a document-to-devlog mapping.
| // Search across all recent devlogs | ||
| const devlogs = await this.apiClient.listDevlogs({ | ||
| page: 1, | ||
| limit: 10, | ||
| sortBy: 'updatedAt', | ||
| sortOrder: 'desc' | ||
| }); | ||
|
|
||
| for (const devlog of devlogs.items || []) { | ||
| try { | ||
| const devlogDocuments = await this.apiClient.listDocuments(devlog.id!); | ||
|
|
||
| const matchingDocs = devlogDocuments.filter((doc: any) => | ||
| doc.originalName?.toLowerCase().includes(args.query.toLowerCase()) || | ||
| (doc.content && doc.content.toLowerCase().includes(args.query.toLowerCase())) || | ||
| doc.filename?.toLowerCase().includes(args.query.toLowerCase()) | ||
| ); | ||
|
|
||
| documents.push(...matchingDocs); | ||
| } catch (err) { | ||
| // Continue with other devlogs if one fails | ||
| console.warn(`Failed to search documents in devlog ${devlog.id}:`, err); | ||
| } | ||
| } |
Copilot
AI
Aug 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The searchDocuments method fetches documents from up to 10 devlogs sequentially when searching across all devlogs. This could be slow and resource-intensive. Consider implementing a server-side search endpoint that can efficiently query across all documents.
| // Search across all recent devlogs | |
| const devlogs = await this.apiClient.listDevlogs({ | |
| page: 1, | |
| limit: 10, | |
| sortBy: 'updatedAt', | |
| sortOrder: 'desc' | |
| }); | |
| for (const devlog of devlogs.items || []) { | |
| try { | |
| const devlogDocuments = await this.apiClient.listDocuments(devlog.id!); | |
| const matchingDocs = devlogDocuments.filter((doc: any) => | |
| doc.originalName?.toLowerCase().includes(args.query.toLowerCase()) || | |
| (doc.content && doc.content.toLowerCase().includes(args.query.toLowerCase())) || | |
| doc.filename?.toLowerCase().includes(args.query.toLowerCase()) | |
| ); | |
| documents.push(...matchingDocs); | |
| } catch (err) { | |
| // Continue with other devlogs if one fails | |
| console.warn(`Failed to search documents in devlog ${devlog.id}:`, err); | |
| } | |
| } | |
| // Search across all devlogs using server-side search | |
| const searchResults = await this.apiClient.searchDocuments(args.query, args.limit); | |
| documents = searchResults || []; |
| } | ||
|
|
||
| // Code files (check before general text types) | ||
| const codeExtensions = ['.js', '.ts', '.py', '.java', '.cpp', '.c', '.go', '.rs', '.php', '.rb', '.swift', '.kt']; |
Copilot
AI
Aug 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code extension list is hardcoded and may become outdated as new languages emerge. Consider moving this to a configuration file or constant that can be easily maintained and extended.
| } | ||
|
|
||
| // Config files (check before general text types) | ||
| const configExtensions = ['.env', '.conf', '.ini', '.yaml', '.yml', '.toml', '.properties']; |
Copilot
AI
Aug 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to code extensions, the config extension list is hardcoded. Consider consolidating all file type mappings into a centralized configuration structure for better maintainability.
| @Column({ | ||
| type: 'varchar', | ||
| length: 50, | ||
| enum: ['text', 'markdown', 'image', 'pdf', 'code', 'json', 'csv', 'log', 'config', 'other'], |
Copilot
AI
Aug 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The enum values are duplicated between the DocumentType type definition and the database column definition. Consider importing the DocumentType enum values to maintain consistency and avoid duplication.
| } | ||
|
|
||
| // Validate file size (10MB limit) | ||
| const maxSize = 10 * 1024 * 1024; // 10MB |
Copilot
AI
Aug 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 10MB file size limit is hardcoded and duplicated across multiple locations. Consider defining this as a constant in a shared configuration file to ensure consistency and make it easier to modify.
This PR implements a comprehensive document upload and management system that allows AI agents to upload relevant documents to devlog entries and save them to the database.
🎯 Problem Solved
Previously, AI agents had no way to attach supporting documents (code files, logs, screenshots, configuration files, etc.) to devlog entries. This limited their ability to provide comprehensive context and reference materials when documenting work.
🚀 Implementation
Core Infrastructure
DevlogDocumentinterface andDocumentTypeenum supporting text, markdown, images, PDFs, code files, JSON, CSV, logs, and config filesDevlogDocumentEntitywith TypeORM mappings for cross-database compatibility (PostgreSQL, MySQL, SQLite)DocumentServicewith singleton pattern matching existing architectureAPI Endpoints
Added RESTful endpoints following existing patterns:
MCP Tools for AI Agents
Added 5 new MCP tools with clear naming:
upload_devlog_document- Upload base64-encoded files with metadatalist_devlog_documents- List documents for a devlog entryget_devlog_document- Retrieve document details and contentdelete_devlog_document- Remove document attachmentssearch_devlog_documents- Search by filename and contentKey Features
🧪 Testing
🔄 Integration
DevlogService.get()method to optionally include documents alongside notesDevlogApiClientwith document upload methods using FormData📝 Usage Example
AI agents can now upload supporting files:
This enables AI agents to provide richer context by attaching relevant code samples, error logs, screenshots, and configuration files directly to their devlog entries.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.