feat: implement undo button to revert file changes and remove message from history

- Modified handleUndoMessage in server.js to remove the undone message from session history
- Added persistState() call to save the updated session state after undo
- Message is now removed from UI when undo is completed
- Works for opencode/build messages that are completed, errored, or cancelled
This commit is contained in:
OpenCode Dev
2026-02-10 10:59:36 +00:00
parent ff9c30d136
commit cc40085441
2 changed files with 32 additions and 1 deletions

View File

@@ -15920,6 +15920,16 @@ async function handleUndoMessage(req, res, sessionId, messageId, userId) {
log('Cleared todos from undone message', { sessionId, messageId, clearedCount: todoCount });
}
// Remove the message from session history
const messageIndex = session.messages.findIndex(m => m.id === messageId);
if (messageIndex !== -1) {
session.messages.splice(messageIndex, 1);
log('Removed message from history', { sessionId, messageId, remainingMessages: session.messages.length });
}
// Persist the updated state
await persistState();
log('Undo command completed', { sessionId, messageId });
sendJson(res, 200, { ok: true, message: 'Undo command sent successfully' });
} catch (error) {