code clean up pass

This commit is contained in:
Storme-bit
2026-04-26 05:38:47 -07:00
parent 785047a824
commit bdc5947fcb
3 changed files with 15 additions and 30 deletions

View File

@@ -98,27 +98,26 @@ function deleteSessionByExternalId(externalId) {
// --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, projectId=null) {
async function createEpisode(sessionId, userMessage, aiResponse, tokenCount = null, projectId=null) {
const db = getDB();
// Wrap insert + session touch in a transaction — both succeed or neither does
const insert = db.transaction(() => {
const stmt = db.prepare(`
INSERT INTO episodes (session_id, user_message, ai_response, token_count, metadata)
VALUES (?, ?, ?, ?, ?)
INSERT INTO episodes (session_id, user_message, ai_response, token_count)
VALUES (?, ?, ?, ?)
`);
const result = stmt.run(
sessionId,
userMessage,
aiResponse,
tokenCount,
metadata ? JSON.stringify(metadata) : null
);
touchSession(sessionId);
return getEpisode(result.lastInsertRowid);
});
const episode= insert();
const episode = insert();
//embed ascynchronously after SQLite completes, non-blocking. If embedding fail, the episode still saved.
getEpisodeEmbedding(userMessage, aiResponse)
@@ -155,11 +154,12 @@ function getEpisodesBySession(sessionId, limit = EPISODIC.DEFAULT_PAGE_SIZE, off
}
// Retrieves recent episodes across all sessions, ordered by creation time descending, with a limit
function getRecentEpisodes(limit = EPISODIC.DEFAULT_RECENT_LIMIT) {
function getRecentEpisodes(sessionId, limit = EPISODIC.DEFAULT_RECENT_LIMIT) {
// Cross-session recent episodes — useful for recency-based retrieval
const db = getDB();
const stmt = db.prepare(`
SELECT * FROM episodes
WHERE session_id = ?
ORDER BY created_at DESC
LIMIT ?
`);