conversation object es el nuevo que inicia al agent

This commit is contained in:
2025-06-05 14:33:41 -06:00
parent 624d06530e
commit 021afb0cf9

View File

@@ -69,16 +69,27 @@ app.use(express.json());
app.post('/', async (req, res) => { app.post('/', async (req, res) => {
const conversation = req.body?.conversation as Conversation | undefined; const conversation = req.body?.conversation as Conversation | undefined;
if (!conversation) return res.status(400).json({ error: 'Missing conversation' }); if (!conversation) return res.status(400).json({ error: 'Missing conversation' });
const message = conversation.messages[conversation.messages.length - 1]?.text || ''; const lastMsg = conversation.messages[conversation.messages.length - 1];
const message = lastMsg?.text || '';
const context = conversation.messages
.slice(-10)
.map((m) => {
const sender =
conversation.participants.find((p) => p.id === m.from)?.name || m.from;
const content = m.text || `[${m.type}]`;
return `${sender}: ${content}`;
})
.join('\n');
if (!genAI) { if (!genAI) {
return res.json({ reply: repoInfo }); return res.json({ reply: repoInfo });
} }
try { try {
const contents = `Repo information: ${repoInfo}\nUser message: ${message}`; const contents = `Repo information: ${repoInfo}\nConversation:\n${context}\n`;
const config: any = {}; const config: any = {};
if (message.toLowerCase().includes('/planilla')) { if (true) {
console.log('Using Model Context Protocol tools ', MCP_URL); console.log('Using Model Context Protocol tools ', MCP_URL);
const client = await getMcpClient(); const client = await getMcpClient();
config.tools = [mcpToTool(client)]; config.tools = [mcpToTool(client)];
@@ -101,7 +112,7 @@ app.get('/', (req, res) => {
<h1>Conversation Layer Agent</h1> <h1>Conversation Layer Agent</h1>
<p>This service answers questions about the repository.</p> <p>This service answers questions about the repository.</p>
<p>Send a POST request to / with a JSON body containing {"conversation": {...}}</p> <p>Send a POST request to / with a JSON body containing {"conversation": {...}}</p>
<p>Example: {"conversation": {"chatId": "123@c.us", "title": "Alice", "isGroup": false, "unreadCount": 0, "participants": [{"id": "123@c.us", "name": "Alice", "isMe": false}], "messages": [{"id": "msg1", "from": "123@c.us", "to": "me@c.us", "ts": 0, "type": "chat", "text": "hello", "meta": {"ack": 0, "hasReaction": false, "isQuoted": false}}], "createdAt": 0 }}</p> <p>Example: {"conversation": {"chatId": "123@c.us", "title": "Chat", "isGroup": false, "unreadCount": 0, "participants": [{"id": "123@c.us", "name": "Alice", "isMe": false}], "messages": [{"id": "m1", "from": "123@c.us", "to": "me@c.us", "ts": 0, "type": "chat", "text": "hello", "meta": {"ack":0,"hasReaction":false,"isQuoted":false}}]}}</p>
<p>It will respond with a JSON object containing {"reply": "the answer"}</p> <p>It will respond with a JSON object containing {"reply": "the answer"}</p>
<p>Repository info: ${repoInfo}</p> <p>Repository info: ${repoInfo}</p>
@@ -111,4 +122,4 @@ app.get('/', (req, res) => {
app.listen(PORT, () => { app.listen(PORT, () => {
console.log(`conversation-layer-agent listening on ${PORT}`); console.log(`conversation-layer-agent listening on ${PORT}`);
}); });