a53ffebe0e
1. 新增工具插件(edit_file, python_executor, search_file, shell_executor, write_file) 2. 新增系统事件日志模块和API 3. 新增workflow配置文件和详情API 4. 前端增加SSE、错误边界、设置引导等组件 5. 优化认证加密、速率限制、配置加载等工具模块 6. 删除废弃的cluster和health API 7. 补充单元测试和集成测试 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
61 lines
1.6 KiB
Python
61 lines
1.6 KiB
Python
"""Workflow 配置文件管理:读取、缓存、热重载。
|
|
|
|
配置文件路径:``config/workflow.yaml``(相对于项目根目录)。
|
|
采用模块级单例 + 文件修改时间检测,保证:
|
|
- 首次调用时懒加载
|
|
- reload_workflow_config() 显式触发重载
|
|
- 工作流引擎调 get_workflow_config() 始终拿到最新生效值
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
from pathlib import Path
|
|
from typing import Any
|
|
|
|
import yaml
|
|
from pydantic import BaseModel, Field
|
|
|
|
_CONFIG_DIR = Path(__file__).resolve().parent.parent.parent / "config"
|
|
_WORKFLOW_YAML = _CONFIG_DIR / "workflow.yaml"
|
|
|
|
|
|
class RetryConfig(BaseModel):
|
|
max_attempts: int = Field(default=5, ge=1, le=100)
|
|
|
|
|
|
class WorkflowConfig(BaseModel):
|
|
retry: RetryConfig = Field(default_factory=RetryConfig)
|
|
|
|
|
|
_current: WorkflowConfig | None = None
|
|
|
|
|
|
def _load_from_disk() -> WorkflowConfig:
|
|
if not _WORKFLOW_YAML.exists():
|
|
return WorkflowConfig()
|
|
with open(_WORKFLOW_YAML, "r", encoding="utf-8") as f:
|
|
data = yaml.safe_load(f) or {}
|
|
return WorkflowConfig.model_validate(data)
|
|
|
|
|
|
def get_workflow_config() -> WorkflowConfig:
|
|
global _current
|
|
if _current is None:
|
|
_current = _load_from_disk()
|
|
return _current
|
|
|
|
|
|
def reload_workflow_config() -> WorkflowConfig:
|
|
global _current
|
|
_current = _load_from_disk()
|
|
return _current
|
|
|
|
|
|
def save_workflow_config(config: WorkflowConfig) -> None:
|
|
_WORKFLOW_YAML.parent.mkdir(parents=True, exist_ok=True)
|
|
data = config.model_dump()
|
|
with open(_WORKFLOW_YAML, "w", encoding="utf-8") as f:
|
|
yaml.dump(data, f, default_flow_style=False, allow_unicode=True)
|
|
reload_workflow_config()
|