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