From 021afb0cf9e7c213e898e88cae916745689fce0e Mon Sep 17 00:00:00 2001 From: josedario87 Date: Thu, 5 Jun 2025 14:33:41 -0600 Subject: [PATCH] conversation object es el nuevo que inicia al agent --- conversation-layer-agent/src/index.ts | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/conversation-layer-agent/src/index.ts b/conversation-layer-agent/src/index.ts index 8db03b2..02cc489 100644 --- a/conversation-layer-agent/src/index.ts +++ b/conversation-layer-agent/src/index.ts @@ -69,16 +69,27 @@ app.use(express.json()); app.post('/', async (req, res) => { const conversation = req.body?.conversation as Conversation | undefined; 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) { return res.json({ reply: repoInfo }); } try { - const contents = `Repo information: ${repoInfo}\nUser message: ${message}`; + const contents = `Repo information: ${repoInfo}\nConversation:\n${context}\n`; const config: any = {}; - if (message.toLowerCase().includes('/planilla')) { + if (true) { console.log('Using Model Context Protocol tools ', MCP_URL); const client = await getMcpClient(); config.tools = [mcpToTool(client)]; @@ -101,7 +112,7 @@ app.get('/', (req, res) => {

Conversation Layer Agent

This service answers questions about the repository.

Send a POST request to / with a JSON body containing {"conversation": {...}}

-

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 }}

+

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}}]}}

It will respond with a JSON object containing {"reply": "the answer"}

Repository info: ${repoInfo}

@@ -111,4 +122,4 @@ app.get('/', (req, res) => { app.listen(PORT, () => { console.log(`conversation-layer-agent listening on ${PORT}`); -}); +}); \ No newline at end of file