mirror of
https://github.com/wassname/HumanAgent-MCP.git
synced 2026-09-10 11:40:39 +08:00
SUCCESSFUL: Complete message synchronization between web and VS Code
✅ FIXED: AI messages now stored in ChatManager when HumanAgent_Chat tool is called ✅ FIXED: User messages stored with source tracking (web vs vscode) ✅ FIXED: Eliminated redundant /chat endpoint - only /response endpoint needed ✅ CONFIRMED: API shows correct message flow: AI → User → AI with proper storage Key insight: AI communicates BY calling HumanAgent_Chat tool, not via responses afterward. Message storage working perfectly. Only remaining issue: web interface display showing duplicates (storage is correct per curl verification)
This commit is contained in:
Vendored
+249
-1206
File diff suppressed because it is too large
Load Diff
@@ -17,3 +17,8 @@
|
||||
2025-10-24T02:07:33.092Z - RESPONSE ENDPOINT CALLED - RequestID: 3-1761271635573
|
||||
2025-10-24T02:11:21.217Z - RESPONSE ENDPOINT CALLED - RequestID: 4-1761271658716
|
||||
2025-10-24T02:11:58.017Z - RESPONSE ENDPOINT CALLED - RequestID: 5-1761271885279
|
||||
2025-10-24T02:18:13.285Z - RESPONSE ENDPOINT CALLED - RequestID: 3-1761272278236
|
||||
2025-10-24T02:18:32.090Z - RESPONSE ENDPOINT CALLED - RequestID: 4-1761272296785
|
||||
2025-10-24T02:22:43.114Z - RESPONSE ENDPOINT CALLED - RequestID: 5-1761272315744
|
||||
2025-10-24T02:23:14.737Z - RESPONSE ENDPOINT CALLED - RequestID: 6-1761272566830
|
||||
2025-10-24T02:24:18.799Z - RESPONSE ENDPOINT CALLED - RequestID: 3-1761272641413
|
||||
|
||||
+14
-45
@@ -403,7 +403,7 @@ export class McpServer extends EventEmitter {
|
||||
// Web interface for multi-session chat
|
||||
await this.handleWebInterface(req, res);
|
||||
return;
|
||||
} else if (req.url?.startsWith('/sessions') || req.url === '/response' || req.url?.startsWith('/tools') || req.url === '/reload' || req.url?.startsWith('/messages/') || req.url?.startsWith('/chat/')) {
|
||||
} else if (req.url?.startsWith('/sessions') || req.url === '/response' || req.url?.startsWith('/tools') || req.url === '/reload' || req.url?.startsWith('/messages/')) {
|
||||
// Session management, response, tools, reload, messages, and chat endpoints
|
||||
await this.handleSessionEndpoint(req, res);
|
||||
return;
|
||||
@@ -650,50 +650,6 @@ export class McpServer extends EventEmitter {
|
||||
res.statusCode = 200;
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.end(JSON.stringify(state));
|
||||
} else if (req.method === 'POST' && url.pathname.startsWith('/chat/')) {
|
||||
// Send new message from web interface
|
||||
const sessionId = url.pathname.split('/')[2];
|
||||
if (!sessionId) {
|
||||
res.statusCode = 400;
|
||||
res.end(JSON.stringify({ success: false, error: 'Session ID required' }));
|
||||
return;
|
||||
}
|
||||
|
||||
let body = '';
|
||||
req.on('data', (chunk) => { body += chunk.toString(); });
|
||||
req.on('end', () => {
|
||||
try {
|
||||
const { message, sender = 'user' } = JSON.parse(body);
|
||||
if (!message) {
|
||||
res.statusCode = 400;
|
||||
res.end(JSON.stringify({ success: false, error: 'Message content required' }));
|
||||
return;
|
||||
}
|
||||
|
||||
// Create and store the message
|
||||
const chatMessage: ChatMessage = {
|
||||
id: Date.now().toString(),
|
||||
content: message,
|
||||
sender: sender as 'user' | 'agent',
|
||||
timestamp: new Date(),
|
||||
type: 'text',
|
||||
source: sender === 'user' ? 'vscode' : undefined
|
||||
};
|
||||
|
||||
this.chatManager.addMessage(sessionId, chatMessage);
|
||||
this.debugLogger.log('CHAT', `Stored message in ChatManager for session ${sessionId}: ${chatMessage.sender} - ${chatMessage.content.substring(0, 50)}...`);
|
||||
this.broadcastMessageToClients(sessionId, chatMessage);
|
||||
|
||||
// Auto-forwarding removed - both interfaces now use /response endpoint directly
|
||||
|
||||
res.statusCode = 200;
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.end(JSON.stringify({ success: true, message: chatMessage }));
|
||||
} catch (error) {
|
||||
res.statusCode = 400;
|
||||
res.end(JSON.stringify({ success: false, error: 'Invalid request body' }));
|
||||
}
|
||||
});
|
||||
} else if (req.method === 'POST' && url.pathname === '/response') {
|
||||
// Handle human response to pending request
|
||||
let body = '';
|
||||
@@ -1482,6 +1438,19 @@ export class McpServer extends EventEmitter {
|
||||
// Store the pending request using the extracted session ID
|
||||
const sessionToUse = sessionId || params.sessionId || 'default';
|
||||
this.debugLogger.log('TOOL', `Adding pending request ${requestId} to session: ${sessionToUse}`);
|
||||
|
||||
// Store the AI's message (this IS the AI communication - it talks by calling the tool)
|
||||
const aiMessage: ChatMessage = {
|
||||
id: requestId, // Use request ID to link with pending request
|
||||
content: displayMessage,
|
||||
sender: 'agent',
|
||||
timestamp: new Date(),
|
||||
type: 'text'
|
||||
};
|
||||
this.chatManager.addMessage(sessionToUse, aiMessage);
|
||||
this.debugLogger.log('CHAT', `Stored AI message in ChatManager for session ${sessionToUse}: ${aiMessage.content.substring(0, 50)}...`);
|
||||
this.broadcastMessageToClients(sessionToUse, aiMessage);
|
||||
|
||||
this.chatManager.addPendingRequest(sessionToUse, requestId, params);
|
||||
this.requestResolvers.set(requestId, {
|
||||
resolve: (response: string) => {
|
||||
|
||||
Reference in New Issue
Block a user