mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-02 08:33:36 +00:00
- Integrated a centralized logging system using createLogger from @automaker/utils, replacing console.log and console.error statements with logger methods for consistent log formatting and improved readability. - Updated various modules, including auth, events, and services, to utilize the new logging system, enhancing error tracking and operational visibility. - Refactored logging messages to provide clearer context and information, ensuring better maintainability and debugging capabilities. This update significantly enhances the observability of the server components, facilitating easier troubleshooting and monitoring.
71 lines
2.2 KiB
TypeScript
71 lines
2.2 KiB
TypeScript
/**
|
|
* POST /send endpoint - Send a message
|
|
*/
|
|
|
|
import type { Request, Response } from 'express';
|
|
import type { ThinkingLevel } from '@automaker/types';
|
|
import { AgentService } from '../../../services/agent-service.js';
|
|
import { createLogger } from '@automaker/utils';
|
|
import { getErrorMessage, logError } from '../common.js';
|
|
const logger = createLogger('Agent');
|
|
|
|
export function createSendHandler(agentService: AgentService) {
|
|
return async (req: Request, res: Response): Promise<void> => {
|
|
try {
|
|
const { sessionId, message, workingDirectory, imagePaths, model, thinkingLevel } =
|
|
req.body as {
|
|
sessionId: string;
|
|
message: string;
|
|
workingDirectory?: string;
|
|
imagePaths?: string[];
|
|
model?: string;
|
|
thinkingLevel?: ThinkingLevel;
|
|
};
|
|
|
|
logger.debug('Received request:', {
|
|
sessionId,
|
|
messageLength: message?.length,
|
|
workingDirectory,
|
|
imageCount: imagePaths?.length || 0,
|
|
model,
|
|
thinkingLevel,
|
|
});
|
|
|
|
if (!sessionId || !message) {
|
|
logger.warn('Validation failed - missing sessionId or message');
|
|
res.status(400).json({
|
|
success: false,
|
|
error: 'sessionId and message are required',
|
|
});
|
|
return;
|
|
}
|
|
|
|
logger.debug('Validation passed, calling agentService.sendMessage()');
|
|
|
|
// Start the message processing (don't await - it streams via WebSocket)
|
|
agentService
|
|
.sendMessage({
|
|
sessionId,
|
|
message,
|
|
workingDirectory,
|
|
imagePaths,
|
|
model,
|
|
thinkingLevel,
|
|
})
|
|
.catch((error) => {
|
|
logger.error('Background error in sendMessage():', error);
|
|
logError(error, 'Send message failed (background)');
|
|
});
|
|
|
|
logger.debug('Returning immediate response to client');
|
|
|
|
// Return immediately - responses come via WebSocket
|
|
res.json({ success: true, message: 'Message sent' });
|
|
} catch (error) {
|
|
logger.error('Synchronous error:', error);
|
|
logError(error, 'Send message failed');
|
|
res.status(500).json({ success: false, error: getErrorMessage(error) });
|
|
}
|
|
};
|
|
}
|