feat: refactor API key configuration and enhance application initialization

- Renamed `check_environment` to `check_api_key_configured` for clarity, simplifying the API key validation logic.
- Removed the blocking behavior of the API key check during application startup, allowing the app to run while providing a prompt for configuration.
- Updated `LocalAgentApp` to accept an `api_configured` parameter, enabling conditional messaging for API key setup.
- Enhanced the `SandboxRunner` to support backup management and improved execution result handling with detailed metrics.
- Integrated data governance strategies into the `HistoryManager`, ensuring compliance and improved data management.
- Added privacy settings and metrics tracking across various components to enhance user experience and application safety.
This commit is contained in:
Mimikko-zeus
2026-02-27 14:32:30 +08:00
parent ab5bbff6f7
commit 8a538bb950
58 changed files with 13457 additions and 350 deletions

192
ui/clear_confirm_dialog.py Normal file
View File

@@ -0,0 +1,192 @@
"""
清理确认对话框
在清空工作区前显示确认对话框,支持备份和恢复
"""
import tkinter as tk
from tkinter import ttk
from typing import Callable, Optional
class ClearConfirmDialog:
"""
清理确认对话框
功能:
1. 显示当前工作区内容统计
2. 提供"清空并备份""仅清空""取消"选项
3. 显示最近的备份信息
"""
def __init__(
self,
parent: tk.Tk,
file_count: int,
total_size: str,
has_recent_backup: bool,
on_confirm: Callable[[bool], None], # 参数:是否创建备份
on_cancel: Callable[[], None]
):
self.parent = parent
self.file_count = file_count
self.total_size = total_size
self.has_recent_backup = has_recent_backup
self.on_confirm = on_confirm
self.on_cancel = on_cancel
self.dialog = None
self.result = None
def show(self):
"""显示对话框"""
self.dialog = tk.Toplevel(self.parent)
self.dialog.title("确认清空工作区")
self.dialog.geometry("500x300")
self.dialog.resizable(False, False)
# 居中显示
self.dialog.transient(self.parent)
self.dialog.grab_set()
# 主容器
main_frame = ttk.Frame(self.dialog, padding="20")
main_frame.pack(fill=tk.BOTH, expand=True)
# 警告图标和标题
title_frame = ttk.Frame(main_frame)
title_frame.pack(fill=tk.X, pady=(0, 15))
warning_label = ttk.Label(
title_frame,
text="⚠️",
font=("Segoe UI Emoji", 24)
)
warning_label.pack(side=tk.LEFT, padx=(0, 10))
title_label = ttk.Label(
title_frame,
text="即将清空工作区",
font=("Microsoft YaHei UI", 14, "bold")
)
title_label.pack(side=tk.LEFT)
# 内容统计
info_frame = ttk.LabelFrame(main_frame, text="当前工作区内容", padding="10")
info_frame.pack(fill=tk.X, pady=(0, 15))
info_text = f"• 文件数量:{self.file_count}\n• 总大小:{self.total_size}"
info_label = ttk.Label(
info_frame,
text=info_text,
font=("Microsoft YaHei UI", 10)
)
info_label.pack(anchor=tk.W)
# 备份提示
if self.has_recent_backup:
backup_hint = ttk.Label(
main_frame,
text="💡 提示:检测到最近的备份,您可以随时恢复",
font=("Microsoft YaHei UI", 9),
foreground="#666666"
)
backup_hint.pack(fill=tk.X, pady=(0, 15))
# 说明文字
desc_label = ttk.Label(
main_frame,
text="清空后input 和 output 目录中的所有文件将被删除。\n建议选择\"清空并备份\"以便后续恢复。",
font=("Microsoft YaHei UI", 9),
foreground="#666666",
wraplength=450
)
desc_label.pack(fill=tk.X, pady=(0, 20))
# 按钮区域
button_frame = ttk.Frame(main_frame)
button_frame.pack(fill=tk.X)
# 取消按钮
cancel_btn = ttk.Button(
button_frame,
text="取消",
command=self._on_cancel,
width=12
)
cancel_btn.pack(side=tk.RIGHT, padx=(5, 0))
# 仅清空按钮
clear_only_btn = ttk.Button(
button_frame,
text="仅清空(不备份)",
command=self._on_clear_only,
width=15
)
clear_only_btn.pack(side=tk.RIGHT, padx=(5, 0))
# 清空并备份按钮(推荐)
clear_backup_btn = ttk.Button(
button_frame,
text="清空并备份(推荐)",
command=self._on_clear_with_backup,
width=18
)
clear_backup_btn.pack(side=tk.RIGHT)
# 设置默认焦点
clear_backup_btn.focus_set()
# 绑定 ESC 键
self.dialog.bind("<Escape>", lambda e: self._on_cancel())
# 等待对话框关闭
self.dialog.wait_window()
def _on_clear_with_backup(self):
"""清空并备份"""
self.result = "backup"
self.dialog.destroy()
self.on_confirm(True)
def _on_clear_only(self):
"""仅清空"""
self.result = "clear"
self.dialog.destroy()
self.on_confirm(False)
def _on_cancel(self):
"""取消"""
self.result = "cancel"
self.dialog.destroy()
self.on_cancel()
def show_clear_confirm_dialog(
parent: tk.Tk,
file_count: int,
total_size: str,
has_recent_backup: bool,
on_confirm: Callable[[bool], None],
on_cancel: Callable[[], None]
):
"""
显示清理确认对话框
Args:
parent: 父窗口
file_count: 文件数量
total_size: 总大小(格式化字符串)
has_recent_backup: 是否有最近的备份
on_confirm: 确认回调(参数:是否创建备份)
on_cancel: 取消回调
"""
dialog = ClearConfirmDialog(
parent=parent,
file_count=file_count,
total_size=total_size,
has_recent_backup=has_recent_backup,
on_confirm=on_confirm,
on_cancel=on_cancel
)
dialog.show()