## 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:
@@ -51,6 +51,11 @@ class FileEditDialog(QDialog):
|
||||
"""Pick/view a file and apply AI edits to it (see module docstring)."""
|
||||
|
||||
def __init__(self, ctx=None, path: str = "", parent=None):
|
||||
"""Hộp thoại xem/sửa một tệp.
|
||||
|
||||
Mở ở chế độ CHỈ ĐỌC; muốn sửa phải bật rõ ràng, và lần ghi đầu tiên tự sao
|
||||
lưu bản gốc.
|
||||
"""
|
||||
super().__init__(parent)
|
||||
self.ctx = ctx
|
||||
self._worker: Optional[AgentWorker] = None
|
||||
@@ -121,11 +126,13 @@ class FileEditDialog(QDialog):
|
||||
|
||||
# ---- loading -----------------------------------------------------------
|
||||
def _browse(self) -> None:
|
||||
"""Chọn tệp cần sửa."""
|
||||
path, _ = QFileDialog.getOpenFileName(self, tr("fileedit.title"))
|
||||
if path:
|
||||
self.load_file(path)
|
||||
|
||||
def _reload(self) -> None:
|
||||
"""Đọc lại tệp đang mở từ đĩa, bỏ mọi sửa đổi chưa lưu."""
|
||||
if self.path_edit.text():
|
||||
self.load_file(self.path_edit.text())
|
||||
|
||||
@@ -167,6 +174,7 @@ class FileEditDialog(QDialog):
|
||||
+ (f" ({note})" if note else ""))
|
||||
|
||||
def _set_editable(self, editable: bool) -> None:
|
||||
"""Bật/tắt chế độ sửa được (tệp nhị phân hoặc chỉ đọc thì tắt)."""
|
||||
self._editable = editable
|
||||
self.editor.setReadOnly(not editable)
|
||||
self.save_btn.setEnabled(editable)
|
||||
@@ -175,6 +183,7 @@ class FileEditDialog(QDialog):
|
||||
|
||||
# ---- AI edit -------------------------------------------------------------
|
||||
def _ai_edit(self) -> None:
|
||||
"""Nhờ AI sửa tệp theo yêu cầu; thiếu yêu cầu hoặc đang chạy dở thì bỏ qua."""
|
||||
instruction = self.instruction_edit.text().strip()
|
||||
if (not instruction or not self._editable or self.ctx is None
|
||||
or self._worker is not None):
|
||||
@@ -188,6 +197,7 @@ class FileEditDialog(QDialog):
|
||||
ctx = self.ctx
|
||||
|
||||
def job(worker: AgentWorker):
|
||||
"""Chạy nền: gọi model sửa nội dung tệp theo yêu cầu."""
|
||||
provider = ctx.build_active_provider()
|
||||
messages = [
|
||||
{"role": "system", "content": _SYSTEM_PROMPT},
|
||||
@@ -199,6 +209,10 @@ class FileEditDialog(QDialog):
|
||||
return {"text": (a.get("content") or "").strip()}
|
||||
|
||||
def done(result: dict) -> None:
|
||||
"""Đổ nội dung đã sửa vào ô soạn thảo, bỏ hàng rào code của model.
|
||||
|
||||
KHÔNG tự ghi đĩa: người dùng phải bấm Lưu.
|
||||
"""
|
||||
self._worker = None
|
||||
self.ai_btn.setEnabled(True)
|
||||
new_text = _strip_fences(result.get("text", ""))
|
||||
@@ -209,6 +223,7 @@ class FileEditDialog(QDialog):
|
||||
self.status_lbl.setText(tr("fileedit.ai_empty"))
|
||||
|
||||
def failed(err: str) -> None:
|
||||
"""Sửa lỗi: hiện lý do (cắt ở 300 ký tự) và mở khoá lại nút."""
|
||||
self._worker = None
|
||||
self.ai_btn.setEnabled(True)
|
||||
self.status_lbl.setText(tr("fileedit.ai_failed", err=err[:300]))
|
||||
@@ -221,6 +236,7 @@ class FileEditDialog(QDialog):
|
||||
|
||||
# ---- save -----------------------------------------------------------------
|
||||
def _save(self) -> None:
|
||||
"""Ghi nội dung đang sửa xuống tệp."""
|
||||
path = self.path_edit.text()
|
||||
if not path or not self._editable:
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user