sessions router mounted onto root

This commit is contained in:
Storme-bit
2026-04-05 23:12:10 -07:00
parent aebea6c231
commit 9af77438b3
3 changed files with 23 additions and 15 deletions

View File

@@ -2,6 +2,7 @@ require ('dotenv').config();
const express = require('express');
const {getEnv} = require('@nexusai/shared');
const chatRouter = require('./routes/chat');
const sessionsRouter = require('./routes/sessions');
const app = express();
app.use(express.json());
@@ -20,6 +21,7 @@ app.get('/health', (req, res) => {
});
app.use('/chat', chatRouter);
app.use('/sessions', sessionsRouter);
/******* Start the server ************/
app.listen(PORT, () => {

View File

@@ -22,19 +22,4 @@ router.post('/', async (req, res) => {
}
});
router.get('/sessions/:sessionId/history', async (req, res) => {
const { sessionId } = req.params;
const { limit = 20, offset = 0 } = req.query;
try {
const session = await memory.getSessionByExternalId(sessionId);
if (!session) return res.status(404).json({ error: 'Session not found' });
const history = await memory.getSessionHistory(session.id, Number(limit), Number(offset));
res.json({ sessionId, episodes: history });
} catch (err) {
res.status(500).json({ error: err.message });
}
});
module.exports = router;

View File

@@ -0,0 +1,21 @@
const { Router } = require('express');
const memory = require('../services/memory');
const router = Router();
router.get('/:sessionId/history', async (req, res) => {
const { sessionId } = req.params;
const { limit = 20, offset = 0 } = req.query;
try {
const session = await memory.getSessionByExternalId(sessionId);
if (!session) return res.status(404).json({ error: 'Session not found' });
const history = await memory.getSessionHistory(session.id, Number(limit), Number(offset));
res.json({ sessionId, episodes: history });
} catch (err) {
res.status(500).json({ error: err.message });
}
});
module.exports = router;