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

@@ -23,6 +23,16 @@ function getSession(id) {
return parseSession(stmt.get(id));
}
function getSessions(limit = EPISODIC.DEFAULT_PAGE_SIZE, offset = 0) {
const db = getDB();
const stmt = db.prepare(`
SELECT * FROM sessions
ORDER BY updated_at DESC
LIMIT ? OFFSET ?
`);
return stmt.all(limit, offset).map(parseSession);
}
// Retrieves a session by its external ID
function getSessionByExternalId(externalId) {
const db = getDB();
@@ -172,6 +182,7 @@ async function getEpisodeEmbedding(userMessage, aiResponse){
module.exports = {
createSession,
getSession,
getSessions,
getSessionByExternalId,
deleteSession,
createEpisode,

View File

@@ -41,6 +41,12 @@ app.post('/sessions', (req, res) => {
}
});
app.get('/sessions', (req, res) => {
const {limit = 20, offset = 0 } = req.query;
const sessions = episodic.getSessions(Number(limit), Number(offset));
res.json(sessions);
})
// Retrieves a session by its external ID
app.get('/sessions/by-external/:externalId', (req, res) => {
const session = episodic.getSessionByExternalId(req.params.externalId);
@@ -48,6 +54,8 @@ app.get('/sessions/by-external/:externalId', (req, res) => {
res.json(session);
});
// Retrieves a session by its internal ID
app.get('/sessions/:id', (req, res) => {
const session = episodic.getSession(req.params.id);