refactor(agent): update task completion fields and enhance status handling
- Rename 'finished_at' to 'completed_at' in AgentTaskResponse and related functions for clarity. - Introduce 'RUNNING' status in AgentTaskStatus to better represent task states. - Update task configuration handling in AgentRunner to improve initialization logic. - Enhance UI to reflect new 'RUNNING' and 'REPORTING' statuses in the AgentAudit component.
This commit is contained in:
parent
129112e4d7
commit
a43ebf1793
|
|
@ -90,7 +90,7 @@ class AgentTaskResponse(BaseModel):
|
|||
# 时间
|
||||
created_at: datetime
|
||||
started_at: Optional[datetime] = None
|
||||
finished_at: Optional[datetime] = None
|
||||
completed_at: Optional[datetime] = None
|
||||
|
||||
# 配置
|
||||
config: Optional[dict] = None
|
||||
|
|
@ -193,7 +193,7 @@ async def _execute_agent_task(task_id: str, project_root: str):
|
|||
if task:
|
||||
task.status = AgentTaskStatus.FAILED
|
||||
task.error_message = str(e)
|
||||
task.finished_at = datetime.now(timezone.utc)
|
||||
task.completed_at = datetime.now(timezone.utc)
|
||||
await db.commit()
|
||||
|
||||
finally:
|
||||
|
|
@ -344,7 +344,7 @@ async def cancel_agent_task(
|
|||
|
||||
# 更新状态
|
||||
task.status = AgentTaskStatus.CANCELLED
|
||||
task.finished_at = datetime.now(timezone.utc)
|
||||
task.completed_at = datetime.now(timezone.utc)
|
||||
await db.commit()
|
||||
|
||||
return {"message": "任务已取消", "task_id": task_id}
|
||||
|
|
@ -554,8 +554,8 @@ async def get_task_summary(
|
|||
|
||||
# 计算持续时间
|
||||
duration = None
|
||||
if task.started_at and task.finished_at:
|
||||
duration = int((task.finished_at - task.started_at).total_seconds())
|
||||
if task.started_at and task.completed_at:
|
||||
duration = int((task.completed_at - task.started_at).total_seconds())
|
||||
|
||||
# 获取已完成的阶段
|
||||
phases_result = await db.execute(
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ class AgentTaskStatus:
|
|||
"""Agent 任务状态"""
|
||||
PENDING = "pending" # 等待执行
|
||||
INITIALIZING = "initializing" # 初始化中
|
||||
RUNNING = "running" # 运行中
|
||||
PLANNING = "planning" # 规划阶段
|
||||
INDEXING = "indexing" # 索引阶段
|
||||
ANALYZING = "analyzing" # 分析阶段
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ class LLMService:
|
|||
"""LLM 服务封装"""
|
||||
|
||||
def __init__(self, model: Optional[str] = None, api_key: Optional[str] = None):
|
||||
self.model = model or settings.DEFAULT_LLM_MODEL
|
||||
self.model = model or settings.LLM_MODEL or "gpt-4o-mini"
|
||||
self.api_key = api_key or settings.LLM_API_KEY
|
||||
|
||||
async def chat_completion_raw(
|
||||
|
|
@ -281,10 +281,20 @@ class AgentRunner:
|
|||
project_info = await self._collect_project_info()
|
||||
|
||||
# 3. 构建初始状态
|
||||
# 从任务字段构建配置
|
||||
task_config = {
|
||||
"target_vulnerabilities": self.task.target_vulnerabilities or [],
|
||||
"verification_level": self.task.verification_level or "sandbox",
|
||||
"exclude_patterns": self.task.exclude_patterns or [],
|
||||
"target_files": self.task.target_files or [],
|
||||
"max_iterations": self.task.max_iterations or 50,
|
||||
"timeout_seconds": self.task.timeout_seconds or 1800,
|
||||
}
|
||||
|
||||
initial_state: AuditState = {
|
||||
"project_root": self.project_root,
|
||||
"project_info": project_info,
|
||||
"config": self.task.config or {},
|
||||
"config": task_config,
|
||||
"task_id": self.task.id,
|
||||
"tech_stack": {},
|
||||
"entry_points": [],
|
||||
|
|
@ -295,7 +305,7 @@ class AgentRunner:
|
|||
"false_positives": [],
|
||||
"current_phase": "start",
|
||||
"iteration": 0,
|
||||
"max_iterations": (self.task.config or {}).get("max_iterations", 3),
|
||||
"max_iterations": self.task.max_iterations or 50,
|
||||
"should_continue_analysis": False,
|
||||
"messages": [],
|
||||
"events": [],
|
||||
|
|
|
|||
|
|
@ -495,10 +495,12 @@ function StatusBadge({ status }: { status: string }) {
|
|||
const statusConfig: Record<string, { text: string; className: string }> = {
|
||||
pending: { text: "PENDING", className: "bg-gray-800 text-gray-400 border-gray-600" },
|
||||
initializing: { text: "INIT", className: "bg-blue-900/50 text-blue-400 border-blue-600 animate-pulse" },
|
||||
running: { text: "RUNNING", className: "bg-green-900/50 text-green-400 border-green-600 animate-pulse" },
|
||||
planning: { text: "PLANNING", className: "bg-purple-900/50 text-purple-400 border-purple-600 animate-pulse" },
|
||||
indexing: { text: "INDEXING", className: "bg-cyan-900/50 text-cyan-400 border-cyan-600 animate-pulse" },
|
||||
analyzing: { text: "ANALYZING", className: "bg-yellow-900/50 text-yellow-400 border-yellow-600 animate-pulse" },
|
||||
verifying: { text: "VERIFYING", className: "bg-orange-900/50 text-orange-400 border-orange-600 animate-pulse" },
|
||||
reporting: { text: "REPORTING", className: "bg-indigo-900/50 text-indigo-400 border-indigo-600 animate-pulse" },
|
||||
completed: { text: "COMPLETED", className: "bg-green-900/50 text-green-400 border-green-600" },
|
||||
failed: { text: "FAILED", className: "bg-red-900/50 text-red-400 border-red-600" },
|
||||
cancelled: { text: "CANCELLED", className: "bg-yellow-900/50 text-yellow-400 border-yellow-600" },
|
||||
|
|
|
|||
Loading…
Reference in New Issue