Skip to content

Commit 03e00ef

Browse files
committed
Updated documentations and agent instructions
1 parent 6d75589 commit 03e00ef

File tree

5 files changed

+154
-25
lines changed

5 files changed

+154
-25
lines changed

.github/copilot-instructions.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,49 @@ pnpm prisma:migrate # Create new migrations
5050
- **Message accumulation**: Frontend concatenates text chunks by message ID for smooth UX
5151
- **Tool approval flow**: Uses Command objects with `resume` action instead of regular inputs
5252

53+
## File Upload & Storage
54+
55+
### MinIO Setup (Development)
56+
57+
- **S3-compatible object storage** runs in Docker alongside Postgres
58+
- **Bucket**: `uploads` (auto-created on startup, public download access)
59+
- **Web Console**: http://localhost:9001 (credentials: minioadmin/minioadmin)
60+
- **S3 API**: http://localhost:9000
61+
62+
### Supported File Types
63+
64+
- **Images**: PNG, JPEG (max 5MB)
65+
- **Documents**: PDF (max 10MB)
66+
- **Text**: Markdown, Plain text (max 2MB)
67+
68+
### Production Migration
69+
70+
To switch to AWS S3, Cloudflare R2, or other S3-compatible storage:
71+
72+
1. Update `.env` variables:
73+
74+
```bash
75+
S3_ENDPOINT= # Empty for AWS S3, or your provider's endpoint
76+
S3_ACCESS_KEY_ID=your_production_key
77+
S3_SECRET_ACCESS_KEY=your_production_secret
78+
S3_FORCE_PATH_STYLE=false # false for AWS S3/R2
79+
```
80+
81+
2. No code changes required - AWS SDK handles the rest!
82+
83+
### File Upload Flow
84+
85+
1. User selects files in `MessageInput` component
86+
2. Files uploaded to MinIO via `/api/agent/upload` endpoint
87+
3. File metadata (URL, key, name, type, size) stored in message options
88+
4. Files can be passed to agent for multimodal processing
89+
90+
### Storage Libraries
91+
92+
- `@aws-sdk/client-s3` - S3 client (works with MinIO + AWS S3)
93+
- `@aws-sdk/lib-storage` - Multipart uploads for large files
94+
- Storage utilities in `src/lib/storage/`
95+
5396
### Database Schema Specifics
5497

5598
- `MCPServer` model supports both stdio and http MCP server types with conditional fields

README.md

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ _Complete agent workflow: user input → tool approval → execution → streami
4040
- Thread-based organization
4141
- Seamless resume across sessions
4242

43+
### **Multimodal File Uploads**
44+
45+
<div align="center">
46+
<img src="docs/images/file-upload.gif" alt="File upload" width="600" />
47+
<p><em>Tool approval dialog with detailed parameter inspection</em></p>
48+
</div>
49+
50+
- Upload images, PDFs, and text files with messages
51+
- S3-compatible storage (MinIO for development)
52+
- Automatic file processing for AI consumption
53+
- Production-ready with AWS S3, Cloudflare R2 support
54+
4355
### **Real-time Streaming Interface**
4456

4557
- Server-Sent Events (SSE) for live responses
@@ -50,7 +62,7 @@ _Complete agent workflow: user input → tool approval → execution → streami
5062
### **Modern Tech Stack**
5163

5264
- **Frontend**: Next.js 15, React 19, TypeScript, Tailwind CSS
53-
- **Backend**: Node.js, Prisma ORM, PostgreSQL
65+
- **Backend**: Node.js, Prisma ORM, PostgreSQL, MinIO/S3
5466
- **AI**: LangGraph.js, OpenAI/Google models
5567
- **UI**: shadcn/ui components, Lucide icons
5668

@@ -59,7 +71,7 @@ _Complete agent workflow: user input → tool approval → execution → streami
5971
### Prerequisites
6072

6173
- Node.js 18+ and pnpm
62-
- Docker (for PostgreSQL)
74+
- Docker (for PostgreSQL and MinIO)
6375
- OpenAI API key or Google AI API key
6476

6577
### 1. Clone and Install
@@ -90,10 +102,10 @@ GOOGLE_API_KEY="..."
90102
DEFAULT_MODEL="gpt-4o-mini" # or "gemini-1.5-flash"
91103
```
92104

93-
### 3. Start Database
105+
### 3. Start Services
94106

95107
```bash
96-
docker compose up -d
108+
docker compose up -d # Starts PostgreSQL and MinIO
97109
```
98110

99111
### 4. Database Setup
@@ -209,10 +221,10 @@ _MCP server configuration form with example filesystem server setup_
209221
└─────────────────┘ └──────────────────┘ └─────────────────┘
210222
211223
212-
──────────────────┐
213-
PostgreSQL
214-
│ (Persistence)
215-
──────────────────┘
224+
┌──────────────────────────────┐
225+
PostgreSQLMinIO/S3
226+
│ (Persistence)│ (File Store)
227+
└──────────────────────────────┘
216228
```
217229

218230
### Core Components
@@ -241,6 +253,12 @@ _MCP server configuration form with example filesystem server setup_
241253
- Stream management and error handling
242254
- Tool approval user interface
243255

256+
#### File Storage (`src/lib/storage/`)
257+
258+
- S3-compatible storage with MinIO (development) or AWS S3 (production)
259+
- File validation, upload, and content processing for AI
260+
- Multimodal message building with base64 conversion
261+
244262
For detailed architecture documentation, see [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md).
245263

246264
## Development
@@ -266,12 +284,13 @@ pnpm prisma:studio # Open Prisma Studio (database UI)
266284
```
267285
src/
268286
├── app/ # Next.js App Router
269-
│ ├── api/ # API routes
287+
│ ├── api/ # API routes (stream, upload, mcp-servers)
270288
│ └── thread/ # Thread-specific pages
271289
├── components/ # React components
272290
├── hooks/ # Custom React hooks
273291
├── lib/ # Core utilities
274-
│ └── agent/ # Agent-related logic
292+
│ ├── agent/ # Agent-related logic
293+
│ └── storage/ # File upload & S3 utilities
275294
├── services/ # Business logic
276295
└── types/ # TypeScript definitions
277296
@@ -283,9 +302,10 @@ prisma/
283302
### Key Files
284303

285304
- **Agent Configuration**: `src/lib/agent/builder.ts`, `src/lib/agent/mcp.ts`
286-
- **API Endpoints**: `src/app/api/agent/stream/route.ts`
305+
- **API Endpoints**: `src/app/api/agent/stream/route.ts`, `src/app/api/agent/upload/route.ts`
306+
- **File Storage**: `src/lib/storage/` (validation, upload, content processing)
287307
- **Database Models**: `prisma/schema.prisma`
288-
- **Main Chat Interface**: `src/components/Thread.tsx`
308+
- **Main Chat Interface**: `src/components/Thread.tsx`, `src/components/MessageInput.tsx`
289309
- **Streaming Logic**: `src/hooks/useChatThread.ts`
290310

291311
## Contributing

docs/ARCHITECTURE.md

Lines changed: 79 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ This document provides a comprehensive overview of the LangGraph.js AI Agent Tem
1111
5. [Agent Workflow](#agent-workflow)
1212
6. [MCP Integration](#mcp-integration)
1313
7. [Tool Approval Process](#tool-approval-process)
14-
8. [Streaming Architecture](#streaming-architecture)
15-
9. [Error Handling](#error-handling)
16-
10. [Performance Considerations](#performance-considerations)
14+
8. [File Upload & Storage](#file-upload--storage)
15+
9. [Streaming Architecture](#streaming-architecture)
16+
10. [Error Handling](#error-handling)
17+
11. [Performance Considerations](#performance-considerations)
1718

1819
## 🌐 System Overview
1920

@@ -52,14 +53,14 @@ This document provides a comprehensive overview of the LangGraph.js AI Agent Tem
5253
5354
Database/Network
5455
55-
┌─────────────────────────────────────────────────────────────────┐
56-
│ External Systems │
57-
├─────────────────────────────────────────────────────────────────┤
58-
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │
59-
│ │ PostgreSQL │ │ OpenAI/Google │ │ MCP Servers │ │
60-
│ │ (Persistence) │ │ (LLM APIs) │ │ (Tools) │ │
61-
│ └─────────────────┘ └─────────────────┘ └─────────────────┘ │
62-
└─────────────────────────────────────────────────────────────────┘
56+
┌─────────────────────────────────────────────────────────────────────────────
57+
External Systems
58+
├─────────────────────────────────────────────────────────────────────────────
59+
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────┐ │
60+
│ │ PostgreSQL │ │OpenAI/Google│ │ MCP Servers │ │ MinIO/S3 (Storage) │ │
61+
│ │(Persistence)│ │ (LLM APIs) (Tools) │ (File Uploads) │ │
62+
│ └─────────────┘ └─────────────┘ └─────────────┘ └─────────────────────┘ │
63+
└─────────────────────────────────────────────────────────────────────────────
6364
```
6465

6566
### Technology Stack
@@ -79,6 +80,7 @@ This document provides a comprehensive overview of the LangGraph.js AI Agent Tem
7980
- **Prisma ORM**: Type-safe database access
8081
- **PostgreSQL**: Primary database
8182
- **Server-Sent Events**: Real-time streaming
83+
- **MinIO/S3**: Object storage for file uploads
8284

8385
#### AI & Tools
8486

@@ -471,6 +473,72 @@ Database MCPServer → getMCPServerConfigs() → MultiServerMCPClient → Agent
471473
4. **Name Prefixing**: Add server name prefix to prevent conflicts
472474
5. **Agent Binding**: Bind tools to language model
473475

476+
## 📁 File Upload & Storage
477+
478+
The application supports multimodal AI conversations through file uploads. Files are stored in S3-compatible storage (MinIO for development) and processed for AI consumption.
479+
480+
### Upload Flow
481+
482+
```
483+
User → MessageInput → Upload API → MinIO/S3 → File Metadata
484+
485+
Agent Request ← processAttachmentsForAI ← Download & Convert to Base64
486+
```
487+
488+
### Supported File Types
489+
490+
| Type | Extensions | Max Size | AI Processing |
491+
| --------- | ---------- | -------- | --------------------- |
492+
| Images | PNG, JPEG | 10MB | Base64 data URL |
493+
| Documents | PDF | 32MB | Base64 data URL |
494+
| Text | MD, TXT | 1MB | UTF-8 text extraction |
495+
496+
### Key Components
497+
498+
#### Upload Endpoint (`src/app/api/agent/upload/route.ts`)
499+
500+
Handles file validation and storage:
501+
502+
- Validates MIME type and file size
503+
- Handles `application/octet-stream` for text files by extension
504+
- Uploads to MinIO/S3 with unique keys
505+
- Returns file metadata (URL, key, name, type, size)
506+
507+
#### Storage Utilities (`src/lib/storage/`)
508+
509+
- **s3-client.ts**: AWS SDK S3 client configuration
510+
- **upload.ts**: Upload functions with multipart support for large files
511+
- **validation.ts**: File type and size validation rules
512+
- **content.ts**: File processing for AI (base64 conversion, text extraction)
513+
514+
#### Multimodal Message Building (`src/services/agentService.ts`)
515+
516+
```typescript
517+
if (opts?.attachments && opts.attachments.length > 0) {
518+
const attachmentContents = await processAttachmentsForAI(opts.attachments);
519+
messageContent = [{ type: "text", text: userText }, ...attachmentContents];
520+
}
521+
```
522+
523+
### Storage Architecture
524+
525+
```
526+
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
527+
│ MessageInput │────►│ Upload API │────►│ MinIO/S3 │
528+
│ (File Select) │ │ (Validation) │ │ (Storage) │
529+
└─────────────────┘ └─────────────────┘ └─────────────────┘
530+
531+
532+
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
533+
│ LangChain │◄────│ processAttach- │◄────│ Download & │
534+
│ HumanMessage │ │ mentsForAI() │ │ Base64 Convert │
535+
└─────────────────┘ └─────────────────┘ └─────────────────┘
536+
```
537+
538+
### Production Migration
539+
540+
The storage layer uses AWS SDK v3, which works with any S3-compatible service. To switch from MinIO to production storage (AWS S3, Cloudflare R2, etc.), update the environment variables - no code changes required.
541+
474542
## ✅ Tool Approval Process
475543

476544
### User Interface Flow

docs/images/file-upload.gif

886 KB
Loading

src/lib/agent/mcp.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ export async function getMCPServerConfigs(): Promise<Record<string, MCPServerCon
2424
const servers = await prisma.mCPServer.findMany({
2525
where: { enabled: true },
2626
});
27-
console.log("Fetched MCP servers from DB:", servers);
2827

2928
const configs: Record<string, MCPServerConfig> = {};
3029

@@ -70,7 +69,6 @@ export async function getMCPServerConfigs(): Promise<Record<string, MCPServerCon
7069
export async function createMCPClient(): Promise<MultiServerMCPClient | null> {
7170
try {
7271
const mcpServers = await getMCPServerConfigs();
73-
console.log("MCP Server Configs:", mcpServers);
7472

7573
if (Object.keys(mcpServers).length === 0) {
7674
return null;

0 commit comments

Comments
 (0)