Feat: Modify the style of the release confirmation box. (#13542)

### What problem does this PR solve?

Feat: Modify the style of the release confirmation box.

### Type of change


- [x] New Feature (non-breaking change which adds functionality)

---------

Co-authored-by: Yingfeng <yingfeng.zhang@gmail.com>
Co-authored-by: balibabu <assassin_cike@163.com>
Co-authored-by: 6ba3i <isbaaoui09@gmail.com>
This commit is contained in:
balibabu
2026-03-13 16:31:17 +08:00
committed by GitHub
parent 02070bab2a
commit 717f1f1362
12 changed files with 196 additions and 97 deletions

View File

@@ -22,6 +22,7 @@ from api.db import CanvasCategory, TenantPermission
from api.db.db_models import DB, CanvasTemplate, User, UserCanvas, API4Conversation, UserCanvasVersion
from api.db.services.api_service import API4ConversationService
from api.db.services.common_service import CommonService
from api.db.services.user_canvas_version import UserCanvasVersionService
from common.misc_utils import get_uuid
from api.utils.api_utils import get_data_openai
import tiktoken
@@ -204,6 +205,27 @@ class UserCanvasService(CommonService):
return False
return True
@classmethod
def get_agent_dsl_with_release(cls, agent_id, release_mode=False, tenant_id=None):
e, cvs = cls.get_by_id(agent_id)
if not e:
raise LookupError("Agent not found.")
if tenant_id and cvs.user_id != tenant_id:
raise PermissionError("You do not own the agent.")
if release_mode:
released_version = UserCanvasVersionService.get_latest_released(agent_id)
if not released_version:
raise PermissionError("No available published version")
dsl = released_version.dsl
else:
dsl = cvs.dsl
if not isinstance(dsl, str):
dsl = json.dumps(dsl, ensure_ascii=False)
return cvs, dsl
async def completion(tenant_id, agent_id, session_id=None, **kwargs):
query = kwargs.get("query", "") or kwargs.get("question", "")
@@ -223,28 +245,12 @@ async def completion(tenant_id, agent_id, session_id=None, **kwargs):
conv.dsl = json.dumps(conv.dsl, ensure_ascii=False)
canvas = Canvas(conv.dsl, tenant_id, agent_id, canvas_id=agent_id, custom_header=custom_header)
else:
e, cvs = UserCanvasService.get_by_id(agent_id)
if not e:
raise LookupError("Agent not found.")
if cvs.user_id != tenant_id:
raise PermissionError("You do not own the agent.")
if release_mode == "true" and not bool(cvs.release):
raise PermissionError("No available published version")
if not isinstance(cvs.dsl, str):
cvs.dsl = json.dumps(cvs.dsl, ensure_ascii=False)
cvs, dsl = UserCanvasService.get_agent_dsl_with_release(agent_id, release_mode=release_mode == "true", tenant_id=tenant_id)
session_id=get_uuid()
canvas = Canvas(cvs.dsl, tenant_id, agent_id, canvas_id=cvs.id, custom_header=custom_header)
session_id = get_uuid()
canvas = Canvas(dsl, tenant_id, agent_id, canvas_id=cvs.id, custom_header=custom_header)
canvas.reset()
conv = {
"id": session_id,
"dialog_id": cvs.id,
"user_id": user_id,
"message": [],
"source": "agent",
"dsl": cvs.dsl,
"reference": []
}
conv = {"id": session_id, "dialog_id": cvs.id, "user_id": user_id, "message": [], "source": "agent", "dsl": dsl, "reference": []}
API4ConversationService.save(**conv)
conv = API4Conversation(**conv)

View File

@@ -89,6 +89,17 @@ class UserCanvasVersionService(CommonService):
except Exception:
return None
@classmethod
@DB.connection_context()
def get_latest_released(cls, user_canvas_id):
try:
return cls.model.select().where((cls.model.user_canvas_id == user_canvas_id) & (cls.model.release)).order_by(cls.model.create_time.desc()).first()
except DoesNotExist:
return None
except Exception as e:
logging.exception(e)
return None
@classmethod
@DB.connection_context()
def save_or_replace_latest(cls, user_canvas_id, dsl, title=None, description=None, release=None):