updated updateSession and deleteSession routes to use external Ids, and added 'name' column to sessions table

This commit is contained in:
Storme-bit
2026-04-13 02:50:38 -07:00
parent 1f0d9acea8
commit f6d538f68a
3 changed files with 42 additions and 2 deletions

View File

@@ -52,6 +52,29 @@ function deleteSession(id) {
db.prepare(`DELETE FROM sessions WHERE id = ?`).run(id);
}
function updateSession(id, { name } = {}){
const db = getDB();
db.prepare(`
UPDATE sessions
SET name = ?, updated_at = unixepoch()
WHERE id = ?
`).run(name ?? null, id);
return getSession(id);
}
function updateSessionByExternalId(externalId, fields) {
const session = getSessionByExternalId(externalId);
if (!session) throw new Error('Session not found');
return updateSession(session.id, fields);
}
function deleteSessionByExternalId(externalId) {
const session = getSessionByExternalId(externalId);
if(!session) throw new Error('Session not found');
deleteSession(session.id);
}
// --Episodes --------------------------------------------------
// Creates a new episode linked to a session, with user message, AI response, optional token count, and metadata
async function createEpisode(sessionId, userMessage, aiResponse, tokenCount = null, metadata = null) {
@@ -165,6 +188,9 @@ module.exports = {
getSessions,
getSessionByExternalId,
deleteSession,
updateSession,
updateSessionByExternalId,
deleteSessionByExternalId,
createEpisode,
getEpisode,
getEpisodesBySession,