Skip to content

Conversation

Amrrx
Copy link
Contributor

@Amrrx Amrrx commented Aug 5, 2025

Implement version control system for ChatFlows and Assistants

Overview

This PR introduces a comprehensive version control system that automatically creates snapshots for every save operation in ChatFlows and Assistants, enabling users to view version history, restore previous versions, and manage their AI workflow iterations effectively.

Problem Statement

Users frequently modify ChatFlows and Assistants during development and testing, but currently have no way to:

  • Track changes over time
  • Rollback to previous working versions when modifications fail
  • View historical versions of their workflows
  • Understand what changed between versions

This creates significant productivity issues when experimenting with AI workflows, as users cannot easily recover from breaking changes.

Solution

Implemented a complete version control system with the following capabilities:

Core Features

  • Automatic snapshot creation on every save operation
  • Version history viewer with paginated list of all versions
  • One-click restore to any previous version
  • Snapshot comparison and detailed version viewing
  • Smart duplicate prevention - only creates snapshots when data actually changes
  • Automatic cleanup - maintains last 50 versions per entity
  • Current version highlighting - clearly shows which version is currently active

User Experience

  • Seamless integration - History button appears in existing toolbars
  • Permission-aware - Respects existing RBAC system
  • Workspace isolation - Version history is isolated per workspace
  • Real-time updates - UI updates immediately after restore operations
  • Descriptive metadata - Each version includes change descriptions and timestamps

Implementation

Database Schema

  • New FlowHistory entity with optimized indexes for performance
  • Added currentHistoryVersion field to existing ChatFlow and Assistant entities
  • Support for all database types (MySQL, PostgreSQL, MariaDB, SQLite)

Backend Services

  • Comprehensive history service with CRUD operations
  • Automatic snapshot creation hooks integrated into existing save flows
  • Deep comparison logic prevents unnecessary snapshots
  • RESTful API endpoints with proper error handling

Frontend Components

  • Reusable HistoryDialog component with Material-UI design
  • HistoryButton component for toolbar integration
  • Snapshot viewer with JSON formatting and syntax highlighting
  • Pagination support for large version histories

Security & Performance

  • Workspace-based access control
  • Database indexes for optimal query performance
  • Configurable retention policies
  • Error handling with graceful degradation

Technical Details

The system integrates seamlessly with existing workflows by hooking into current save operations. When a user saves a ChatFlow or Assistant, the system:

  1. Compares new data with the latest snapshot using deep comparison.
  2. Creates a new version only if changes are detected.
  3. Updates the entity's current version pointer.
  4. Automatically cleans up old versions beyond the retention limit.

Version restoration creates a new snapshot of the restored state, maintaining a complete audit trail of all changes.

Testing

  • All existing functionality remains unchanged.
  • New database migrations tested across all supported database types.
  • UI components tested for responsive design and accessibility.
  • Error scenarios handled gracefully with user-friendly messages.

Migration

  • Zero-downtime database migrations
  • Backward compatibility maintained
  • No breaking changes to existing APIs
  • Progressive enhancement - works with existing data

Amrrx added 8 commits July 28, 2025 00:53
- Added history service to manage snapshots of chatflows and assistants.
- Integrated history snapshot creation on chatflow save and update operations.
- Created API endpoints for fetching, restoring, and deleting history snapshots.
- Developed UI components for displaying and managing version history in the assistant and chatflow configurations.
- Added HistoryButton and HistoryDialog components for user interaction with version history.
- Implemented flow reload functionality to update the canvas with restored chatflow data.
@Amrrx Amrrx changed the title Implement version control system for ChatFlows and Assistants Feature - Implement version control system for ChatFlows and Assistants Aug 5, 2025
@toi500
Copy link
Contributor

toi500 commented Aug 12, 2025

@Amrrx This amazing! Thank you for adding this to the open source version.

Testing in Chrome (Win 11), I got this small glich:

chrome_D3sN4hcQ5l

@Amrrx
Copy link
Contributor Author

Amrrx commented Aug 12, 2025

@Amrrx This amazing! Thank you for adding this to the open source version.

Testing in Chrome (Win 11), I got this small glich:

It should work now. give it a try!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants