import express, { Request, Response } from 'express'; import axios from 'axios'; import bodyParser from 'body-parser'; import path from 'path'; const app = express(); const port = Number(process.env.PORT) || 3000; const agentUrl = process.env.LLM_AGENT_URL as string | undefined; app.use(bodyParser.json()); app.use(express.static(path.join(__dirname, 'public'))); app.post('/send', async (req: Request, res: Response) => { if (!agentUrl) { return res.status(500).json({ error: 'LLM_AGENT_URL not configured' }); } try { const { message } = req.body; const response = await axios.post(agentUrl, { message }); res.json(response.data); } catch (err: any) { console.error('Failed to forward message', err.message); res.status(500).json({ error: 'Failed to communicate with agent' }); } }); app.listen(port, () => console.log(`Chat UI listening on port ${port}`));