feat: Add update_theme functionality with UI support

Backend:
- Add PUT /api/themes/:id endpoint for updating existing themes

Store:
- Add updateTheme method to theme store

MCP:
- Add update_theme tool to modify name, description, or save current variables

UI:
- Add edit button to ThemeListItem (custom themes only)
- Add edit modal with name and description fields
- Support editing from both desktop sidebar and mobile dropdown
This commit is contained in:
2026-02-13 05:50:13 -06:00
parent d5518cb6d1
commit 2e64dceb1e
6 changed files with 263 additions and 0 deletions

View File

@@ -393,6 +393,47 @@ Bun.serve({
return Response.json({ success: true }, { headers: corsHeaders })
}
// PUT /api/themes/:id - Actualizar un tema existente
if (req.method === 'PUT' && !action) {
const theme = db.query('SELECT * FROM themes WHERE id = ?').get(id) as any
if (!theme) {
return Response.json({ error: 'Theme not found' }, { status: 404, headers: corsHeaders })
}
const body = await req.json()
// Build update query dynamically based on provided fields
const updates: string[] = []
const values: any[] = []
if (body.name !== undefined) {
updates.push('name = ?')
values.push(body.name)
}
if (body.description !== undefined) {
updates.push('description = ?')
values.push(body.description)
}
if (body.variables !== undefined) {
updates.push('variables = ?')
values.push(JSON.stringify(body.variables))
}
if (body.metadata !== undefined) {
updates.push('metadata = ?')
values.push(JSON.stringify(body.metadata))
}
if (updates.length > 0) {
updates.push('updated_at = CURRENT_TIMESTAMP')
values.push(id)
const sql = `UPDATE themes SET ${updates.join(', ')} WHERE id = ?`
db.run(sql, values)
}
return Response.json({ success: true, id }, { headers: corsHeaders })
}
// GET /api/themes/:id - Obtener un tema
if (req.method === 'GET' && !action) {
const row = db.query('SELECT * FROM themes WHERE id = ?').get(id) as any