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

View File

@@ -40,7 +40,7 @@ class SettingsView:
self,
parent: tk.Widget,
env_path: Path,
on_save: Optional[Callable[[], None]] = None,
on_save: Optional[Callable[[bool], None]] = None,
on_back: Optional[Callable[[], None]] = None
):
self.parent = parent
@@ -342,10 +342,29 @@ class SettingsView:
# 同时更新环境变量
os.environ[key] = value
messagebox.showinfo("成功", "配置已保存!")
# 重置 LLM 客户端单例,强制使用新配置
from llm.client import reset_client, test_connection
reset_client()
# 进行连通性测试
messagebox.showinfo("提示", "配置已保存,正在测试连接...")
success, message = test_connection(timeout=15)
# 记录配置变更度量
from llm.config_metrics import get_config_metrics
metrics = get_config_metrics(self.env_path.parent / "workspace")
metrics.mark_config_changed(connection_test_success=success)
if success:
messagebox.showinfo("成功", f"配置已保存并生效!\n\n{message}")
else:
messagebox.showwarning(
"配置已保存",
f"配置已保存,但连接测试失败:\n\n{message}\n\n请检查配置是否正确。"
)
if self.on_save:
self.on_save()
self.on_save(success)
except Exception as e:
messagebox.showerror("错误", f"保存配置失败: {str(e)}")