feat(schedule): 优化排程任务配置与进度契约处理逻辑

This commit is contained in:
hugo committed 2026-07-08 16:09:28 +08:00
1 parent d54f51ddc3
commit 99453aa52a
65 files changed
+2837 -487

No files matched your search

@@ -12,10 +12,10 @@ from typing import Any
from app.models import Agent
from app.services.agent_registry.resolver import (
normalize_capabilities,
resolve_agent_code,
resolve_capabilities,
resolve_conversation_mode,
resolve_progress_contract,
resolve_runtime_provider,
)
@@ -43,6 +43,7 @@ def serialize_registry_fields(agent: Agent | Any) -> dict[str, Any]:
handler_config = getattr(agent, 'handler_config', None)
intent_meta = resolve_agent_intent_metadata(agent)
tool_run_progress = build_tool_run_progress_view(agent)
progress_contract = resolve_progress_contract(agent)
return {
'agent_code': resolve_agent_code(agent),
'runtime_provider': resolve_runtime_provider(agent),
@@ -60,12 +61,13 @@ def serialize_registry_fields(agent: Agent | Any) -> dict[str, Any]:
'bound_schedule_task_id': getattr(agent, 'bound_schedule_task_id', None),
'handler_config': handler_config if isinstance(handler_config, dict) else None,
'tool_run_progress': tool_run_progress,
'progress_contract': progress_contract,
**intent_meta,
}
def serialize_agent_for_admin(agent: Agent) -> dict[str, Any]:
"""Agent ORM → 管理端列表/详情 JSON(API Key 仅返回脱敏值,明文不可读)。"""
"""Agent ORM → 管理端列表/详情 JSON(含 dify_api_key 供编辑表单密码框回填)。"""
registry = serialize_registry_fields(agent)
return {
'id': agent.id,
@@ -75,6 +77,7 @@ def serialize_agent_for_admin(agent: Agent) -> dict[str, Any]:
'is_active': agent.is_active,
'type': agent.type,
'dify_app_id': agent.dify_app_id,
'dify_api_key': agent.dify_api_key,
'dify_api_key_masked': mask_dify_api_key(agent.dify_api_key),
'api_base_url': agent.api_base_url,
'extra_config': agent.extra_config if isinstance(agent.extra_config, dict) else {},
@@ -123,13 +126,18 @@ def serialize_agent_for_user_detail(
def build_tool_run_progress_view(agent: Agent) -> dict[str, Any] | None:
"""
从 Registry 列构建前端 tool_run_progress 视图(迁移期兼容 extra 读者)。
从 Registry 列构建前端 tool_run_progress 视图(schedule_run 进度兼容层)。
核心逻辑:capabilities.task_progress 为 true 且 bound_schedule_task_id 已注册时返回配置 dict。
核心逻辑:progress_contract.data_source.type=schedule_run 且 bound_schedule_task_id
已注册时返回配置 dict;domain_state 等其它进度类型不走本视图。
"""
caps = resolve_capabilities(agent)
if not caps.get('task_progress'):
contract = resolve_progress_contract(agent)
if not contract:
return None
data_source = contract.get('data_source') if isinstance(contract.get('data_source'), dict) else {}
if data_source.get('type') != 'schedule_run':
return None
task_id = getattr(agent, 'bound_schedule_task_id', None)
try:
schedule_task_id = int(task_id)
@@ -143,11 +151,12 @@ def build_tool_run_progress_view(agent: Agent) -> dict[str, Any] | None:
from app.services.agent_registry.resolver import resolve_agent_code
defaults = get_tool_run_progress_defaults()
update = contract.get('update') if isinstance(contract.get('update'), dict) else {}
cfg: dict[str, Any] = {
'type': str(defaults.get('progress_type') or resolve_agent_code(agent) or 'file_check'),
'schedule_task_id': schedule_task_id,
}
cfg['poll_interval_seconds'] = defaults.get('poll_interval_seconds', 2)
cfg['poll_interval_seconds'] = update.get('interval_seconds') or defaults.get('poll_interval_seconds', 2)
cfg['lock_input_when_running'] = defaults.get('lock_input_when_running', True)
if isinstance(handler_config, dict):
if handler_config.get('poll_interval_seconds') is not None: