feat(server): 新增编排器和报销单API端点,扩展智能体对话服务接口

This commit is contained in:
caoxiaozhu
2026-05-14 15:42:39 +00:00
parent c99a423f6a
commit 910c959829

View File

@@ -125,6 +125,7 @@ class AgentConversationService:
user_id: str | None,
source: str | None = "user_message",
session_type: str | None = None,
prefer_recoverable: bool = False,
) -> AgentConversation | None:
self.prune_expired_conversations()
@@ -141,11 +142,36 @@ class AgentConversationService:
if not normalized_session_type:
return conversations[0] if conversations else None
fallback_conversation = None
for conversation in conversations:
current_session_type = str((conversation.state_json or {}).get("session_type") or "").strip() or "expense"
if current_session_type == normalized_session_type:
if current_session_type != normalized_session_type:
continue
if fallback_conversation is None:
fallback_conversation = conversation
if not prefer_recoverable or self._is_recoverable_conversation(conversation):
return conversation
return None
return fallback_conversation
@staticmethod
def _is_recoverable_conversation(conversation: AgentConversation) -> bool:
if str(conversation.draft_claim_id or "").strip():
return True
state_json = dict(conversation.state_json or {})
documents = state_json.get("ocr_documents")
if not isinstance(documents, list):
return False
for item in documents:
if not isinstance(item, dict):
continue
preview_url = str(item.get("preview_url") or "").strip()
preview_data_url = str(item.get("preview_data_url") or "").strip()
preview_kind = str(item.get("preview_kind") or "").strip()
if (preview_url or preview_data_url) and preview_kind in {"image", "pdf"}:
return True
return False
def hydrate_context_json(
self,