Skip to content

Commit 2811e76

Browse files
committed
feat(frontend/chat): update chat implementation and API integration
Refactored chat components and hooks to improve functionality and maintain conversation state. Updated API endpoints for sending messages and retrieving chat history with PostgreSQL persistence. Modified files (10): - page.tsx: Replaced ChatInterfaceClient with ChatInterface - ConversationList.tsx: Updated terminology from conversations to chats - ConversationSidebar.tsx: Updated terminology from conversations to chats - use-chat.ts: Enhanced chat state management with serialized state - use-conversations.ts: Updated error handling and terminology - chat-service.ts: Implemented new API endpoint for chat messages - constants.ts: Updated API base URL for backend - chat.ts: Updated types for chat messages and requests - types/chat.ts: Added serialized state for message requests - types/chat.ts: Updated response types for chat messages
1 parent 7b7d662 commit 2811e76

12 files changed

Lines changed: 467 additions & 314 deletions

File tree

src/frontend/task-agent-web/README.md

Lines changed: 71 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,35 @@ AI-powered task management interface built with **Next.js 16**, **React 19**, an
77
### Core Functionality
88

99
- 🤖 **AI Chat Interface** - Natural language task management
10+
- 🎯 **Custom AG-UI Integration** - SSE streaming with `/api/agent/chat` endpoint
1011
- 💡 **Smart Suggestions** - Clickable contextual suggestions from AI agent
11-
- 📂 **Conversation Management** - List, load, and delete conversations
12-
- 🗂️ **Sidebar Navigation** - Collapsible sidebar with conversation history
12+
- 📂 **Chat Management** - List, load, and delete chats
13+
- 🗂️ **Sidebar Navigation** - Collapsible sidebar with chat history
1314
- 🏷️ **Auto-generated Titles** - Titles extracted from first user message
1415
-**Enhanced Loading States** - Contextual loading messages with animations
1516
- 📱 **Responsive Design** - Works on desktop, tablet, and mobile
1617
- 🎨 **Modern UI** - ChatGPT-inspired clean design with Tailwind CSS
1718
- 📐 **Adaptive Layout** - Centered welcome state, fixed input when chatting
1819
- 🔄 **Smart Scrolling** - Independent message scroll with fixed header and input
19-
- 💾 **localStorage Persistence** - Remembers current conversation across sessions
20+
- 💾 **localStorage Persistence** - Remembers current chat across sessions
2021

2122
### Recent Updates (November 2025)
2223

2324
#### v2.1 - Content Safety UX Enhancements
2425

2526
-**Blocked Messages in Chat** - Content Safety violations appear as assistant messages (not toasts)
26-
-**Thread Continuity** - Blocked conversations create threads for seamless continuation
27+
-**Thread Continuity** - Blocked chats create threads for seamless continuation
2728
-**Smart Title Updates** - Titles regenerate when first valid message sent after block
2829
-**Optimized Sidebar Refresh** - Only reloads when title changes (efficient flag-based approach)
29-
-**ChatGPT-like Behavior** - Natural conversation flow even with blocked messages
30+
-**ChatGPT-like Behavior** - Natural chat flow even with blocked messages
3031

31-
#### v2.0 - Conversation Management
32+
#### v2.0 - Chat Management
3233

33-
-**ConversationSidebar Component** - Full conversation history with search
34+
-**ConversationSidebar Component** - Full chat history with search
3435
-**ConversationList Component** - Paginated list with auto-generated titles
35-
-**ConversationItem Component** - Individual conversation cards with metadata
36+
-**ConversationItem Component** - Individual chat cards with metadata
3637
-**DeleteConfirmModal Component** - Confirmation dialog with smooth animations
37-
-**useConversations Hook** - Conversation state management
38+
-**useConversations Hook** - Chat state management
3839
-**localStorage Integration** - Persists current thread ID
3940
-**API Integration** - List, load, and delete endpoints
4041

@@ -134,29 +135,78 @@ src/frontend/task-agent-web/
134135
│ │ ├── SuggestionsBar.tsx # Clickable suggestion buttons
135136
│ │ ├── ErrorToast.tsx # Error display
136137
│ │ └── LoadingIndicator.tsx # Contextual loading states
137-
│ ├── conversations/ # Conversation management
138+
│ ├── conversations/ # Chat management
138139
│ │ ├── ConversationSidebar.tsx # Sidebar layout
139-
│ │ ├── ConversationList.tsx # List of conversations
140-
│ │ ├── ConversationItem.tsx # Individual conversation card
140+
│ │ ├── ConversationList.tsx # List of chats
141+
│ │ ├── ConversationItem.tsx # Individual chat card
141142
│ │ └── DeleteConfirmModal.tsx # Delete confirmation
142143
│ └── shared/ # Shared components
143144
│ └── LoadingIndicator.tsx # Reusable loading component
144145
├── hooks/ # Custom React hooks
145146
│ ├── use-chat.ts # Chat state management
146-
│ └── use-conversations.ts # Conversation management
147+
│ └── use-conversations.ts # Chat management
147148
├── lib/ # Utilities
148149
│ ├── utils.ts # Helper functions (cn utility)
149150
│ ├── constants.ts # App constants
150151
│ └── api/ # API client functions
151-
│ └── chat-service.ts # Chat & conversation API
152+
│ └── chat-service.ts # Chat & API client
152153
├── types/ # TypeScript definitions
153154
│ ├── chat.ts # Chat types
154-
│ └── conversation.ts # Conversation types
155+
│ └── conversation.ts # Thread/conversation types (technical)
155156
├── public/ # Static assets
156157
└── types/ # TypeScript definitions
157158
└── chat.ts # Chat types
158159
```
159160
161+
## 🏗️ Architecture
162+
163+
**Custom Implementation with AG-UI Foundation**:
164+
165+
```
166+
Frontend (Next.js)
167+
├── Custom UI Components
168+
│ ├── ChatInterface.tsx
169+
│ ├── ConversationSidebar.tsx
170+
│ ├── ChatMessagesList.tsx
171+
│ └── use-chat.ts hook
172+
173+
↕️ SSE Streaming (Server-Sent Events)
174+
│ POST /api/agent/chat
175+
│ • serializedState → Backend
176+
│ • SSE events ← Backend
177+
│ • THREAD_STATE event (new serializedState)
178+
179+
Backend (.NET)
180+
├── AgentController (Custom SSE endpoint)
181+
│ └── Wraps Microsoft Agent Framework
182+
│ • Deserializes thread from serializedState
183+
│ • Streams responses via RunStreamingAsync
184+
│ • Returns updated serializedState
185+
186+
└── PostgresChatMessageStore
187+
└── Automatic persistence in PostgreSQL
188+
```
189+
190+
**Why Custom AG-UI Endpoint (not standard `/agui`)?**
191+
- ✅ **Full SSE control**: Custom event types (`CONTENT_START`, `CONTENT_DELTA`, `THREAD_STATE`)
192+
- ✅ **serializedState pattern**: Frontend receives updated state after each response
193+
- ✅ **Chat continuity**: Backend deserializes full thread from PostgreSQL
194+
- ✅ **No protocol limitations**: Can add custom events as needed
195+
- ✅ **Integrated chat sidebar**: 291 lines with auto-generated titles
196+
- ❌ Standard `/agui` doesn't return `serializedState` in streaming mode
197+
198+
**Why Custom UI (not CopilotKit)?**
199+
- ✅ **Chat-first application**: Not auxiliary chat over another app
200+
- ✅ **Full UX control**: ChatGPT-inspired adaptive layout
201+
- ✅ **Minimal dependencies**: No heavy UI framework
202+
- ❌ CopilotKit designed for auxiliary chat, not main application
203+
204+
**Microsoft Agent Framework Benefits**:
205+
- 🔄 Automatic message persistence via `ChatMessageStore`
206+
- 📡 SSE streaming with `RunStreamingAsync`
207+
- 🧵 Thread serialization/deserialization built-in
208+
- 📦 Function calling with `AIFunctionFactory`
209+
160210
## 🎯 Key Technologies
161211
162212
- **Next.js 16** - React framework with App Router
@@ -211,11 +261,11 @@ Main color palette:
211261
- `POST /api/Chat/send` - Send message (non-streaming)
212262
- `POST /api/Chat/stream` - Streaming support (paused for future releases)
213263

214-
#### Conversation Management
264+
#### Chat Management
215265

216-
- `GET /api/Chat/threads` - List conversations with pagination
217-
- `GET /api/Chat/threads/{threadId}/messages` - Get conversation history
218-
- `DELETE /api/Chat/threads/{threadId}` - Delete conversation
266+
- `GET /api/Chat/threads` - List chats with pagination
267+
- `GET /api/Chat/threads/{threadId}/messages` - Get chat history
268+
- `DELETE /api/Chat/threads/{threadId}` - Delete chat
219269

220270
### Request/Response Formats
221271

@@ -248,7 +298,7 @@ POST /api/Chat/send
248298
}
249299
```
250300

251-
#### List Conversations
301+
#### List Chats
252302

253303
```typescript
254304
// Request
@@ -274,7 +324,7 @@ GET /api/Chat/threads?page=1&pageSize=20&sortBy=UpdatedAt&sortOrder=desc&isActiv
274324
}
275325
```
276326
277-
#### Get Conversation History
327+
#### Get Chat History
278328
279329
```typescript
280330
// Request
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
import { ChatInterfaceClient } from "@/components/chat/ChatInterfaceClient";
1+
import { ChatInterface } from "@/components/chat/ChatInterface";
22

3+
/**
4+
* Home Page - Task Agent AI
5+
* Main chat interface with custom implementation
6+
*/
37
export default function Home() {
4-
return <ChatInterfaceClient />;
8+
return <ChatInterface />;
59
}
10+
11+

src/frontend/task-agent-web/components/chat/ChatInterfaceClient.tsx

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/frontend/task-agent-web/components/conversations/ConversationList.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
/**
44
* ConversationList Component
5-
* Displays a list of conversations with loading and empty states
5+
* Displays a list of chats with loading and empty states
66
*/
77

88
import type { ConversationThread } from "@/types/chat";
@@ -28,7 +28,7 @@ export function ConversationList({
2828
return (
2929
<div className="flex flex-col items-center justify-center py-12 px-4">
3030
<div className="animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600 mb-3" />
31-
<p className="text-sm text-gray-500">Loading conversations...</p>
31+
<p className="text-sm text-gray-500">Loading chats...</p>
3232
</div>
3333
);
3434
}
@@ -53,10 +53,10 @@ export function ConversationList({
5353
</svg>
5454
</div>
5555
<p className="text-sm text-gray-600 font-medium mb-1">
56-
No conversations yet
56+
No chats yet
5757
</p>
5858
<p className="text-xs text-gray-500">
59-
Start a new conversation to get started
59+
Start a new chat to get started
6060
</p>
6161
</div>
6262
);

src/frontend/task-agent-web/components/conversations/ConversationSidebar.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
/**
44
* ConversationSidebar Component
5-
* Sidebar for managing conversations (list, create, delete)
5+
* Sidebar for managing chats (list, create, delete)
66
* Responsive: Drawer on mobile, persistent sidebar on desktop
77
*/
88

@@ -77,7 +77,7 @@ export function ConversationSidebar({
7777
onConversationDeleted(threadId);
7878
}
7979
} catch (error) {
80-
console.error("Failed to delete conversation:", error);
80+
console.error("Failed to delete chat:", error);
8181
}
8282
};
8383

@@ -168,7 +168,7 @@ export function ConversationSidebar({
168168
</div>
169169
</div>
170170

171-
{/* New conversation button */}
171+
{/* New chat button */}
172172
{!isCollapsed && (
173173
<button
174174
onClick={handleNewConversation}

0 commit comments

Comments
 (0)