Feat: support agent version history. (#6130)

### What problem does this PR solve?
Add history version save
- Allows users to view and download agent files by version revision
history

![image](https://github.com/user-attachments/assets/c300375d-8b97-4230-9fc4-83d148137132)

_Briefly describe what this PR aims to solve. Include background context
that will help reviewers understand the purpose of the PR._

### Type of change

- [ ] Bug Fix (non-breaking change which fixes an issue)
- [x] New Feature (non-breaking change which adds functionality)
- [ ] Documentation Update
- [ ] Refactoring
- [ ] Performance Improvement
- [ ] Other (please describe):

---------

Co-authored-by: Kevin Hu <kevinhu.sh@gmail.com>
This commit is contained in:
so95
2025-03-19 14:22:53 +07:00
committed by GitHub
parent e689532e6e
commit 53ac27c3ff
11 changed files with 362 additions and 7 deletions

View File

@ -988,6 +988,16 @@ class CanvasTemplate(DataBaseModel):
class Meta:
db_table = "canvas_template"
class UserCanvasVersion(DataBaseModel):
id = CharField(max_length=32, primary_key=True)
user_canvas_id = CharField(max_length=255, null=False, help_text="user_canvas_id", index=True)
title = CharField(max_length=255, null=True, help_text="Canvas title")
description = TextField(null=True, help_text="Canvas description")
dsl = JSONField(null=True, default={})
class Meta:
db_table = "user_canvas_version"
def migrate_db():
with DB.transaction():

View File

@ -0,0 +1,43 @@
from api.db.db_models import UserCanvasVersion, DB
from api.db.services.common_service import CommonService
from peewee import DoesNotExist
class UserCanvasVersionService(CommonService):
model = UserCanvasVersion
@classmethod
@DB.connection_context()
def list_by_canvas_id(cls, user_canvas_id):
try:
user_canvas_version = cls.model.select(
*[cls.model.id,
cls.model.create_time,
cls.model.title,
cls.model.create_date,
cls.model.update_date,
cls.model.user_canvas_id,
cls.model.update_time]
).where(cls.model.user_canvas_id == user_canvas_id)
return user_canvas_version
except DoesNotExist:
return None
except Exception:
return None
@classmethod
@DB.connection_context()
def delete_all_versions(cls, user_canvas_id):
try:
user_canvas_version = cls.model.select().where(cls.model.user_canvas_id == user_canvas_id).order_by(cls.model.create_time.desc())
if user_canvas_version.count() > 20:
for i in range(20, user_canvas_version.count()):
cls.delete(user_canvas_version[i].id)
return True
except DoesNotExist:
return None
except Exception:
return None