feat(schedule): 优化排程任务配置与进度契约处理逻辑
This commit is contained in:
1 parent
d54f51ddc3
commit
99453aa52a
65 files changed
+2837
-487
No files matched your search
@@ -2,7 +2,7 @@
|
||||
backend/app/services/agent_registry/handlers/file_check.py
|
||||
|
||||
用途:文件检核 Agent Handler — 聊天流 turn 注册与 Dify 进度绑定。
|
||||
依赖:file_check_tools.chat_turn_registry、agent_registry.handlers.registry。
|
||||
依赖:file_check_tools.chat_turn_registry、agent_registry.handlers.registry、resolver。
|
||||
逻辑:DifyChatExecutor 经 resolve_handler_for_agent_code 调用 prepare_stream 注册 hxops_turn_id。
|
||||
"""
|
||||
|
||||
@@ -12,7 +12,16 @@ import uuid
|
||||
|
||||
from app.services.agent_registry.handlers.base import AgentHandler, ChatStreamContext
|
||||
from app.services.agent_registry.handlers.registry import register_handler
|
||||
from app.services.agent_registry.resolver import agent_declares_task_progress
|
||||
from app.services.agent_registry.resolver import resolve_progress_contract
|
||||
|
||||
|
||||
def _uses_schedule_run_progress(agent) -> bool:
|
||||
"""progress_contract 声明 schedule_run 数据源时才注册检核 turn。"""
|
||||
contract = resolve_progress_contract(agent)
|
||||
if not contract:
|
||||
return False
|
||||
data_source = contract.get('data_source') if isinstance(contract.get('data_source'), dict) else {}
|
||||
return data_source.get('type') == 'schedule_run'
|
||||
|
||||
|
||||
@register_handler('file_check')
|
||||
@@ -20,12 +29,12 @@ class FileCheckHandler(AgentHandler):
|
||||
"""
|
||||
文件检核业务 Handler。
|
||||
|
||||
核心逻辑:capabilities.task_progress === true 时在 Dify 流开始前注册 hxops_turn_id,
|
||||
供检核进度轮询绑定 chat_log;capabilities 本身仅控制前端是否展示进度 UI。
|
||||
核心逻辑:progress_contract.data_source=schedule_run 时在 Dify 流开始前注册 hxops_turn_id,
|
||||
供检核进度轮询绑定 chat_log;capabilities.task_progress 仅作能力门禁。
|
||||
"""
|
||||
|
||||
def prepare_stream(self, ctx: ChatStreamContext) -> ChatStreamContext:
|
||||
if not agent_declares_task_progress(ctx.agent):
|
||||
if not _uses_schedule_run_progress(ctx.agent):
|
||||
return ctx
|
||||
|
||||
turn_id = uuid.uuid4().hex
|
||||
|
||||
@@ -15,6 +15,22 @@ from flask import current_app
|
||||
|
||||
from app.services.agent_registry.handlers.base import AgentHandler, ChatStreamContext
|
||||
from app.services.agent_registry.handlers.registry import register_handler
|
||||
from app.services.agent_registry.resolver import resolve_progress_contract
|
||||
|
||||
|
||||
def _uses_shipping_ui_state_progress(agent) -> bool:
|
||||
"""progress_contract 声明 domain_state + shipping_ui_state SSE 时才下发 UI State。"""
|
||||
contract = resolve_progress_contract(agent)
|
||||
if not contract:
|
||||
return False
|
||||
data_source = contract.get('data_source') if isinstance(contract.get('data_source'), dict) else {}
|
||||
update = contract.get('update') if isinstance(contract.get('update'), dict) else {}
|
||||
return (
|
||||
data_source.get('type') == 'domain_state'
|
||||
and data_source.get('domain') == 'shipping_notice'
|
||||
and update.get('transport') == 'sse'
|
||||
and update.get('event') == 'shipping_ui_state'
|
||||
)
|
||||
|
||||
|
||||
@register_handler('shipping_notice')
|
||||
@@ -31,6 +47,9 @@ class ShippingNoticeHandler(AgentHandler):
|
||||
|
||||
核心逻辑:优先显式 task_id,其次 batch 焦点任务;失败时记录日志并返回 None。
|
||||
"""
|
||||
if not _uses_shipping_ui_state_progress(ctx.agent):
|
||||
return None
|
||||
|
||||
task_id = str(ctx.shipping_task_id or '').strip()
|
||||
batch_no = str(ctx.shipping_batch_no or '').strip()
|
||||
if not task_id and not batch_no:
|
||||
|
||||
Reference in new issue
Block a user