refactor(agent-runtime, shipping-notice, frontend): 重构上下文体系,修复重试RPA无响应问题
- 替换原有的hxops_context模块为全新的代理运行时上下文平台协议,统一跨业务上下文注入逻辑 - 新增多语言操作繁忙提示文案(覆盖中、繁、英、泰四语),前端绑定页面繁忙状态实现操作阻断 - 调整RPA库存导出重试策略:移除可配置的最大自动重试次数,改为固定单次自动重试,手动重试需用户显式触发 - 优化任务用户态状态展示逻辑,优先展示具体的pending原因而非通用状态文案 - 重构任务焦点切换逻辑,统一事件日志与处理流程,复用switch_batch_focus工具函数 - 修复clearAllHistory函数残留UI问题,确保清空会话后完全复位发货通知相关视图 - 更新OpenAPI文档与静态快照,补充工具使用约束说明 - 新增调试打点日志与问题排查文档,完善全套单元测试与快照校验用例 - 更新RPA脚本的README文档,调整登录方式说明与浏览器 profile 路径配置 - 删除废弃的hxops_context模块,迁移所有相关调用到新的上下文体系
This commit is contained in:
1 parent
60dd0c0f58
commit
8846ce159f
102 files changed
+18289
-9072
No files matched your search
@@ -15,7 +15,7 @@ import uuid
|
||||
from flask import current_app
|
||||
|
||||
from app import db
|
||||
from app.models import ShippingTask, ShippingTaskEvent
|
||||
from app.models import ShippingBatch, ShippingTask, ShippingTaskEvent
|
||||
from app.services.shipping_notice.constants import AUTO_CHAIN_FALLBACK
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ def auto_rpa_inventory_enabled() -> bool:
|
||||
|
||||
def rpa_inventory_timeout_seconds() -> int:
|
||||
"""RPA 库存导出等待超时秒数。"""
|
||||
return cfg_int("SHIPPING_NOTICE_RPA_INVENTORY_TIMEOUT_SECONDS", 120, min_value=5)
|
||||
return cfg_int("SHIPPING_NOTICE_RPA_INVENTORY_TIMEOUT_SECONDS", 360, min_value=5)
|
||||
|
||||
|
||||
def auto_mapping_allow_llm() -> bool:
|
||||
@@ -181,6 +181,58 @@ def generate_task_no() -> str:
|
||||
return f"SN-{datetime.utcnow().strftime('%Y%m%d')}-{uuid.uuid4().hex[:8].upper()}"
|
||||
|
||||
|
||||
def _clean_event_value(value: Any) -> str:
|
||||
"""把事件详情值规范化为短字符串;空值返回空字符串。"""
|
||||
return str(value or "").strip()
|
||||
|
||||
|
||||
def _task_batch_no(task: ShippingTask | None) -> str:
|
||||
"""从任务关系中提取批次号。"""
|
||||
batch = getattr(task, "batch", None)
|
||||
return _clean_event_value(getattr(batch, "batch_no", None))
|
||||
|
||||
|
||||
def build_task_action_event_detail(
|
||||
task: ShippingTask,
|
||||
*,
|
||||
action: str,
|
||||
source: str,
|
||||
comment: str | None = None,
|
||||
extra: dict[str, Any] | None = None,
|
||||
) -> dict[str, Any]:
|
||||
"""
|
||||
构建任务动作类事件详情。
|
||||
|
||||
核心逻辑:统一补齐 action/source/target/batch/conversation 等字段,保证 reference_context 后续可以稳定消费本地动作事件。
|
||||
|
||||
Args:
|
||||
task: 动作作用的目标任务。
|
||||
action: 规范化动作名,如 confirm/reject/rematch/reparse/switch_focus。
|
||||
source: 触发来源,如 workspace_api/tool_api/backend_orchestrator。
|
||||
comment: 用户附带备注。
|
||||
extra: 其他扩展字段,例如 previous_focus_task_no。
|
||||
|
||||
Returns:
|
||||
标准化的事件 detail_json。
|
||||
"""
|
||||
detail: dict[str, Any] = {
|
||||
"action": _clean_event_value(action),
|
||||
"source": _clean_event_value(source),
|
||||
"target_type": "task",
|
||||
"target_id": _clean_event_value(getattr(task, "task_no", None)),
|
||||
"batch_no": _task_batch_no(task),
|
||||
"conversation_id": _clean_event_value(getattr(task, "conversation_id", None)),
|
||||
}
|
||||
normalized_comment = _clean_event_value(comment)
|
||||
if normalized_comment:
|
||||
detail["comment"] = normalized_comment
|
||||
for key, value in (extra or {}).items():
|
||||
if value is None:
|
||||
continue
|
||||
detail[key] = value
|
||||
return detail
|
||||
|
||||
|
||||
def log_task_event(task: ShippingTask, event_type: str, detail: dict[str, Any] | None = None) -> None:
|
||||
"""写入 ShippingTaskEvent 审计记录(task 尚未 flush 时自动 flush)。"""
|
||||
if task.id is None:
|
||||
@@ -190,3 +242,81 @@ def log_task_event(task: ShippingTask, event_type: str, detail: dict[str, Any] |
|
||||
event_type=event_type,
|
||||
detail_json=detail or {},
|
||||
))
|
||||
|
||||
|
||||
def log_task_action_event(
|
||||
task: ShippingTask,
|
||||
event_type: str,
|
||||
*,
|
||||
action: str,
|
||||
source: str,
|
||||
comment: str | None = None,
|
||||
extra: dict[str, Any] | None = None,
|
||||
) -> None:
|
||||
"""
|
||||
写入标准化任务动作事件。
|
||||
|
||||
核心逻辑:在原始 event_type 之外,统一补足 reference_context 所需的动作元数据,避免各入口散落拼接。
|
||||
"""
|
||||
log_task_event(
|
||||
task,
|
||||
event_type,
|
||||
build_task_action_event_detail(
|
||||
task,
|
||||
action=action,
|
||||
source=source,
|
||||
comment=comment,
|
||||
extra=extra,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
def switch_batch_focus(
|
||||
batch: ShippingBatch,
|
||||
task: ShippingTask,
|
||||
*,
|
||||
source: str,
|
||||
event_type: str = "focus_switched",
|
||||
comment: str | None = None,
|
||||
emit_when_unchanged: bool = True,
|
||||
extra: dict[str, Any] | None = None,
|
||||
) -> bool:
|
||||
"""
|
||||
切换批次焦点任务并写入标准事件。
|
||||
|
||||
核心逻辑:统一处理 current_focus_task_no 更新与 focus 切换事件,供 workspace/tool/orchestrator 复用。
|
||||
|
||||
Args:
|
||||
batch: 所属批次。
|
||||
task: 新焦点任务。
|
||||
source: 触发来源,如 workspace_api/tool_api/backend_orchestrator。
|
||||
event_type: 事件名;用户态默认 focus_switched,系统自动切票可传 focus_auto_switched。
|
||||
comment: 用户备注。
|
||||
emit_when_unchanged: 焦点未变化时是否仍记事件。
|
||||
extra: 附加字段。
|
||||
|
||||
Returns:
|
||||
是否实际发生焦点变化。
|
||||
"""
|
||||
previous_focus_task_no = _clean_event_value(getattr(batch, "current_focus_task_no", None))
|
||||
next_focus_task_no = _clean_event_value(getattr(task, "task_no", None))
|
||||
changed = previous_focus_task_no != next_focus_task_no
|
||||
batch.current_focus_task_no = next_focus_task_no or None
|
||||
|
||||
if changed or emit_when_unchanged:
|
||||
detail_extra = {
|
||||
"previous_focus_task_no": previous_focus_task_no or None,
|
||||
"next_focus_task_no": next_focus_task_no or None,
|
||||
"changed": changed,
|
||||
}
|
||||
if extra:
|
||||
detail_extra.update(extra)
|
||||
log_task_action_event(
|
||||
task,
|
||||
event_type,
|
||||
action="switch_focus",
|
||||
source=source,
|
||||
comment=comment,
|
||||
extra=detail_extra,
|
||||
)
|
||||
return changed
|
||||
Reference in new issue
Block a user