feat(shipping-notice): 新增通用解析能力,优化性能并清理遗留废弃代码
This commit is contained in:
1 parent
935bf26fa6
commit
7cfd5d167e
230 files changed
+9337
-10989
No files matched your search
@@ -3,7 +3,7 @@ services/shipping_notice/dify_inputs.py
|
||||
|
||||
用途:识别发货通知 Dify Chatflow Agent,并构建会话级 Dify inputs。
|
||||
依赖:agent_runtime_context 平台协议、models.ShippingNotice、shipping_notice.runtime_context。
|
||||
逻辑:由 Context Adapter / api/chat 调用;本模块按会话号解析当前批次/任务焦点,
|
||||
逻辑:由 Context Adapter / api/chat 调用;本模块只使用显式任务锚点,
|
||||
仅输出 agent_runtime_context JSON 字符串,供 Dify 画布统一读取平台运行态快照。
|
||||
发货通知识别请使用 agent_registry.resolver.resolve_agent_code == 'shipping_notice'。
|
||||
"""
|
||||
@@ -19,14 +19,8 @@ from app.services.agent_runtime_context.schema import AGENT_RUNTIME_CONTEXT_INPU
|
||||
from app.services.shipping_notice.runtime_context import build_shipping_runtime_context
|
||||
|
||||
|
||||
def _latest_batch_for_conversation(conversation_id: str) -> None:
|
||||
"""shipping_batches 已删除;固定返回 None。"""
|
||||
del conversation_id
|
||||
return None
|
||||
|
||||
|
||||
def _task_by_task_no(task_id: str) -> ShippingNotice | None:
|
||||
"""按显式 task_id 获取任务;仅用于补齐批次 ref,禁止按会话号猜测当前任务。"""
|
||||
"""按显式 task_id 获取任务;禁止按会话号猜测当前任务。"""
|
||||
normalized = str(task_id or "").strip().upper()
|
||||
if not normalized:
|
||||
return None
|
||||
@@ -66,8 +60,7 @@ def _focus_task_row(focus_task: str, explicit_task_row: ShippingNotice | None) -
|
||||
"""
|
||||
解析当前显式焦点任务行。
|
||||
|
||||
核心逻辑:优先复用已查出的显式 task;若焦点来自 batch.current_focus_task_no,再按 task_no 查询,
|
||||
但不在无焦点时回退到最近任务,避免多票批次串单。
|
||||
核心逻辑:优先复用已查出的显式 task;不在无焦点时回退到最近任务,避免多票串单。
|
||||
|
||||
Args:
|
||||
focus_task: 已解析出的焦点任务号。
|
||||
@@ -88,7 +81,6 @@ def build_dify_chat_inputs(
|
||||
conversation_id: str | None = None,
|
||||
*,
|
||||
task_id: str | None = None,
|
||||
batch_no: str | None = None,
|
||||
trigger_source: str | None = None,
|
||||
request_id: str | None = None,
|
||||
locale: str | None = None,
|
||||
@@ -108,7 +100,6 @@ def build_dify_chat_inputs(
|
||||
return {}
|
||||
|
||||
explicit_task = str(task_id or "").strip().upper()
|
||||
explicit_batch = str(batch_no or "").strip().upper()
|
||||
explicit_temporary_session = str(temporary_inventory_session_no or '').strip().upper()
|
||||
resolved_temporary_session = (
|
||||
explicit_temporary_session
|
||||
@@ -119,28 +110,12 @@ def build_dify_chat_inputs(
|
||||
)
|
||||
)
|
||||
|
||||
batch = _latest_batch_for_conversation(conv_id)
|
||||
explicit_task_row = _task_by_task_no(explicit_task)
|
||||
|
||||
focus_task = explicit_task
|
||||
if not focus_task and batch and batch.current_focus_task_no:
|
||||
focus_task = str(batch.current_focus_task_no or "").strip().upper()
|
||||
|
||||
focus_batch = explicit_batch
|
||||
if not focus_batch and batch and batch.batch_no:
|
||||
focus_batch = str(batch.batch_no or "").strip().upper()
|
||||
elif (
|
||||
not focus_batch
|
||||
and explicit_task_row
|
||||
and getattr(explicit_task_row, "batch", None) is not None
|
||||
and getattr(explicit_task_row.batch, "batch_no", None)
|
||||
):
|
||||
focus_batch = str(explicit_task_row.batch.batch_no or "").strip().upper()
|
||||
|
||||
runtime_context = build_shipping_runtime_context(
|
||||
session_id=conv_id,
|
||||
task=_focus_task_row(focus_task, explicit_task_row),
|
||||
batch=batch or getattr(explicit_task_row, "batch", None),
|
||||
trigger_source=trigger_source,
|
||||
request_id=request_id,
|
||||
locale=locale,
|
||||
@@ -161,7 +136,7 @@ def build_dify_chat_inputs(
|
||||
session = ChatSession.query.filter_by(session_id=conv_id).one_or_none()
|
||||
capability_token = issue_chat_capability(
|
||||
user_id=session.user_id, session_id=conv_id, agent_id=session.agent_id,
|
||||
task_no=focus_task, batch_no=focus_batch,
|
||||
task_no=focus_task,
|
||||
) if session is not None else None
|
||||
return {
|
||||
AGENT_RUNTIME_CONTEXT_INPUT: serialize_for_dify(runtime_context),
|
||||
|
||||
Reference in new issue
Block a user