## Summary epic r04 - begin refactor ## Change Type - [x] Cowork feature - [ ] Bug fix - [ ] Core AI contribution - [ ] Test / hardening - [ ] Performance - [ ] Documentation ## Related Work Cowork Task: Core Repo: http://34.143.229.138/gitea-admin/fsg-ai-core-assets Core AI Issue: Core Task: Related PR: ## Scope What is intentionally included? What is intentionally NOT included? ## Validation - [ ] Unit tests - [ ] Integration tests - [ ] Manual verification - [ ] Regression check Commands / evidence: ## Security Impact Permission / credential / network / customer data impact: ## Compatibility - [ ] No breaking change - [ ] Breaking change documented ## Reviewer Notes Anything Cowork reviewers should pay attention to. --------- Co-authored-by: Anh Tran Nguyen Minh <anhtnm1@fpt.com> Co-authored-by: Huong Le Thi Thien <huongltt35@fpt.com> Co-authored-by: Nam Pham Dinh Thanh <nampdt@fpt.com> Co-authored-by: Vu Dam Tuan <vudt15@fpt.com> Co-authored-by: Hiep Ha Van <hiephv3@fpt.com> Co-authored-by: Lam Hoang Van <lamhv7@fpt.com> Reviewed-on: #7 Co-authored-by: Duy Le Huu <duylh19@fpt.com>
This commit was merged in pull request #7.
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
"""Agent và skill dùng trong flow — R08-T09.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
from typing import Dict, List
|
||||
from PySide6.QtCore import QSize, Qt
|
||||
from ...core import co4e, skills as skills_mod
|
||||
from ...i18n import tr
|
||||
from ...presentation.co4e.co4e_chat_view import _skill_names
|
||||
|
||||
|
||||
class Co4EAgentsMixin:
|
||||
"""Quản lý agent tự tạo và thư viện skill dùng trong luồng Co4E."""
|
||||
def _new_agent(self) -> None:
|
||||
"""Mở hộp thoại tạo agent tự tạo mới."""
|
||||
self._edit_agent_dialog(co4e.new_custom_agent(""))
|
||||
def _edit_agent(self) -> None:
|
||||
"""Sửa agent đang chọn; chưa chọn gì thì nhắc người dùng chọn."""
|
||||
item = self.agent_list.currentItem()
|
||||
cid = item.data(Qt.UserRole + 1) if item else None
|
||||
if not cid:
|
||||
self.status_message.emit(tr("co4e.select_custom_agent"))
|
||||
return
|
||||
agent = next((a for a in co4e.list_custom_agents() if a.id == cid), None)
|
||||
if agent is not None:
|
||||
self._edit_agent_dialog(agent)
|
||||
def _edit_agent_dialog(self, agent: co4e.CustomAgent) -> None:
|
||||
"""Mở hộp thoại sửa agent; bấm OK thì lưu và nạp lại cột bên trái."""
|
||||
from ...ui.co4e_agent_dialog import Co4EAgentDialog
|
||||
|
||||
dlg = Co4EAgentDialog(self.ctx, agent, _skill_names(), self)
|
||||
if dlg.exec():
|
||||
co4e.save_custom_agent(dlg.result_agent())
|
||||
self._reload_sidebar()
|
||||
def _delete_agent(self) -> None:
|
||||
"""Xoá agent đang chọn; chưa chọn gì thì nhắc người dùng chọn."""
|
||||
item = self.agent_list.currentItem()
|
||||
cid = item.data(Qt.UserRole + 1) if item else None
|
||||
if not cid:
|
||||
self.status_message.emit(tr("co4e.select_custom_agent"))
|
||||
return
|
||||
co4e.delete_custom_agent(cid)
|
||||
self._reload_sidebar()
|
||||
def _manage_skills(self) -> None:
|
||||
"""Mở trình quản lý Skill, đóng xong thì nạp lại cột bên trái."""
|
||||
from ...ui.skills_dialog import SkillsDialog
|
||||
|
||||
SkillsDialog(self, self.ctx).exec()
|
||||
self._reload_sidebar()
|
||||
def _skill_map(self) -> Dict[str, str]:
|
||||
"""Bảng ``{tên skill: nội dung chỉ dẫn}`` để truyền cho một lượt chạy luồng.
|
||||
|
||||
Cắt bỏ dòng tiêu đề của khối chỉ dẫn, chỉ giữ phần nội dung.
|
||||
"""
|
||||
out = {}
|
||||
for name in _skill_names():
|
||||
block = skills_mod.skill_prefix_for(name)
|
||||
if block:
|
||||
out[name] = block.split("\n", 1)[1] if "\n" in block else block
|
||||
return out
|
||||
Reference in New Issue
Block a user