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:
hugo committed 2026-07-03 17:01:42 +08:00
1 parent 60dd0c0f58
commit 8846ce159f
102 files changed
+18289 -9072

No files matched your search

@@ -0,0 +1,130 @@
"""
backend/app/services/agent_runtime_context/adapters/generic.py
用途:为未接入专用业务 adapter 的 Dify Agent 构建最小可用的 agent_runtime_context。
依赖:agent_runtime_context.builder、标准库 typing。
逻辑:由平台级 dify_inputs 分发入口调用;当 Agent 既不是 shipping_notice 也不是 file_check 时,
使用本模块生成通用会话快照,让 Dify Start 节点也能稳定拿到 platform/session 上下文。
"""
from __future__ import annotations
from typing import Any
from app.services.agent_runtime_context.builder import (
build_agent_runtime_context,
build_dify_inputs,
)
def _agent_extra_config(agent) -> dict[str, Any]:
"""读取 Agent.extra_config;非字典时回退为空,避免通用适配器因脏配置报错。"""
extra_config = getattr(agent, "extra_config", None)
return extra_config if isinstance(extra_config, dict) else {}
def resolve_agent_code(agent) -> str:
"""
解析通用 Agent 的稳定 code。
核心逻辑:优先读取 extra_config.agent_code;未配置或为空时回退为 generic,
让知识库/普通问答类 Agent 也能在 Runtime 中暴露稳定标识。
Args:
agent: 当前对话 Agent 记录或代理对象。
Returns:
Agent code 字符串;缺省为 generic。
"""
agent_code = str(_agent_extra_config(agent).get("agent_code") or "").strip()
return agent_code or "generic"
def _resolve_domain_summary(agent) -> str:
"""按优先级提取通用摘要,避免无业务状态 Agent 的 domain.summary 为空。"""
extra_config = _agent_extra_config(agent)
runtime_context_summary = str(extra_config.get("runtime_context_summary") or "").strip()
if runtime_context_summary:
return runtime_context_summary
agent_description = str(getattr(agent, "description", None) or "").strip()
if agent_description:
return agent_description
return "通用对话"
def build_generic_runtime_context(
*,
session_id: str,
agent,
request_id: str | None = None,
trigger_source: str | None = "frontend_chat",
locale: str | None = None,
scope: str = "chat_turn",
) -> dict[str, Any]:
"""
为通用 Dify Agent 构建最小 Runtime Context。
核心逻辑:仅注入 platform/session 锚点与 generic domain 摘要,
不附带 refs/reference_context,适用于纯 Q&A 或知识库类 Agent。
Args:
session_id: HXOPS 会话 ID;为空时返回空 dict。
agent: 当前对话 Agent,读取 extra_config.agent_code/runtime_context_summary。
request_id: 本次请求追踪 ID。
trigger_source: 触发来源,默认 frontend_chat。
locale: 用户语言。
scope: 上下文作用域,默认 chat_turn。
Returns:
通用 agent_runtime_context 字典;session_id 为空时返回空 dict。
"""
return build_agent_runtime_context(
agent_code=resolve_agent_code(agent),
scope=scope,
session_id=session_id,
request_id=request_id,
trigger_source=trigger_source,
locale=locale,
domain={
"type": "generic",
"summary": _resolve_domain_summary(agent),
},
)
def build_generic_dify_inputs(
*,
session_id: str,
agent,
request_id: str | None = None,
trigger_source: str | None = "frontend_chat",
locale: str | None = None,
scope: str = "chat_turn",
) -> dict[str, str]:
"""
构建通用 Agent 的 Dify Start inputs。
核心逻辑:统一把最小 Runtime Context 序列化到 agent_runtime_context,
让未接入专用 adapter 的 Agent 也能消费平台会话快照。
Args:
session_id: HXOPS 会话 ID。
agent: 当前对话 Agent。
request_id: 本次请求追踪 ID。
trigger_source: 触发来源。
locale: 用户语言。
scope: 上下文作用域。
Returns:
仅含 agent_runtime_context 的 inputs;session_id 为空时返回空 dict。
"""
runtime_context = build_generic_runtime_context(
session_id=session_id,
agent=agent,
request_id=request_id,
trigger_source=trigger_source,
locale=locale,
scope=scope,
)
return build_dify_inputs(runtime_context)