updated updateSession and deleteSession routes to use external Ids, and added 'name' column to sessions table
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user