semantic search within project
This commit is contained in:
@@ -65,13 +65,20 @@ function deleteSession(id) {
|
||||
|
||||
function updateSession(id, { name, projectId } = {}) {
|
||||
const db = getDB();
|
||||
db.prepare(`
|
||||
UPDATE sessions
|
||||
SET name = ?,
|
||||
project_id = COALESCE(?, project_id),
|
||||
updated_at = unixepoch()
|
||||
WHERE id = ?
|
||||
`).run(name ?? null, projectId ?? null, id);
|
||||
|
||||
// Build update dynamically based on what was provided
|
||||
const updates = [];
|
||||
const values = [];
|
||||
|
||||
if (name !== undefined) { updates.push('name = ?'); values.push(name ?? null); }
|
||||
if (projectId !== undefined) { updates.push('project_id = ?'); values.push(projectId ?? null); }
|
||||
|
||||
if (updates.length === 0) return getSession(id);
|
||||
|
||||
updates.push('updated_at = unixepoch()');
|
||||
values.push(id);
|
||||
|
||||
db.prepare(`UPDATE sessions SET ${updates.join(', ')} WHERE id = ?`).run(...values);
|
||||
return getSession(id);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,15 +31,22 @@ router.get('/', async (req, res) => {
|
||||
});
|
||||
|
||||
router.patch('/:sessionId', async (req, res) => {
|
||||
const { name, projectId } = req.body;
|
||||
if (!name?.trim()) return res.status(400).json({ error: 'name is required' });
|
||||
const { name, projectId } = req.body;
|
||||
|
||||
try {
|
||||
const session = await memory.updateSession(req.params.sessionId, { name, projectId });
|
||||
res.json(session);
|
||||
} catch (err) {
|
||||
res.status(500).json({ error: err.message });
|
||||
}
|
||||
// Allow patch with just projectId, or just name, or both
|
||||
if (!name?.trim() && projectId === undefined) {
|
||||
return res.status(400).json({ error: 'name or projectId is required' });
|
||||
}
|
||||
|
||||
try {
|
||||
const session = await memory.updateSession(req.params.sessionId, {
|
||||
name: name?.trim() || undefined,
|
||||
projectId
|
||||
});
|
||||
res.json(session);
|
||||
} catch (err) {
|
||||
res.status(500).json({ error: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
router.delete('/:sessionId', async (req, res) => {
|
||||
|
||||
Reference in New Issue
Block a user