added endpoints and routes to get sessions

This commit is contained in:
Storme-bit
2026-04-06 01:16:19 -07:00
parent 710107ce5a
commit 461438e81b
4 changed files with 39 additions and 1 deletions

View File

@@ -18,4 +18,14 @@ router.get('/:sessionId/history', async (req, res) => {
}
});
router.get('/', async (req, res) => {
const {limit = 20, offset = 0 } = req.query;
try {
const sessions = await memory.getSessions(Number(limit), Number(offset));
res.json(sessions);
} catch (err) {
res.status(500).json({error: err.message});
}
})
module.exports = router;

View File

@@ -56,11 +56,20 @@ async function getSessionHistory(sessionId, limit = 20, offset = 0) {
return res.json();
}
async function getSessions(limit = 20, offset = 0) {
const res = await fetch(
`${BASE_URL}/sessions?limit${limit}&offset=${offset}`
);
if (!res.ok) throw new Error(`Failed to fetch sessions: ${res.status}`);
return res.json();
}
module.exports = {
getSessionByExternalId,
createSession,
getRecentEpisodes,
createEpisode,
getEpisodeById,
getSessionHistory
getSessionHistory,
getSessions
}