Rename repo-agent to conversation-layer-agent

This commit is contained in:
josedario87
2025-06-05 00:10:10 -06:00
parent 5d512994ad
commit cc6e378f8c
10 changed files with 1106 additions and 3 deletions

View File

@@ -0,0 +1,43 @@
import express from 'express';
import { GoogleGenerativeAI } from '@google/generative-ai';
import dotenv from 'dotenv';
dotenv.config();
const PORT = Number(process.env.PORT) || 8001;
const API_KEY = process.env.GEMINI_API_KEY || '';
const genAI = API_KEY ? new GoogleGenerativeAI(API_KEY) : null;
const model = genAI ? genAI.getGenerativeModel({ model: 'gemini-pro' }) : null;
const repoInfo = `This repository contains a WhatsApp router, a simple chat UI and now a conversation-layer-agent service.
- whatsapp-router: Forwards WhatsApp messages to configured agents.
- chat-ui: Minimal web interface that also talks to an agent.
- conversation-layer-agent: Answers questions about the repository.
Run all services with docker-compose. Configure handler mappings in whatsapp-router/src/chatHandlers.ts.`;
const app = express();
app.use(express.json());
app.post('/', async (req, res) => {
const message = req.body?.message as string | undefined;
if (!message) return res.status(400).json({ error: 'Missing message' });
if (!model) {
return res.json({ reply: repoInfo });
}
try {
const prompt = `Repo information: ${repoInfo}\nUser message: ${message}`;
const result = await model.generateContent(prompt);
const reply = result.response.text().trim();
res.json({ reply });
} catch (err: any) {
console.error('Gemini error', err.message);
res.status(500).json({ error: 'Failed to generate reply' });
}
});
app.listen(PORT, () => {
console.log(`conversation-layer-agent listening on ${PORT}`);
});