from __future__ import annotations from dataclasses import dataclass from review_agent.models import Conversation, FileAttachment TRIGGER_KEYWORDS = ("自动汇总", "文件目录", "页数", "目录与页数", "文件清单") ATTACHMENT_READER_KEYWORDS = ( "阅读附件", "读取附件", "解析附件", "分析附件", "查看附件", "附件详情", "文件详情", "总结附件", "总结文件", "分析这个文件", "阅读这个文件", ) @dataclass(frozen=True) class TriggerResult: should_start: bool workflow_type: str = "" reason: str = "" def evaluate_file_summary_trigger(conversation: Conversation, content: str) -> TriggerResult: text = (content or "").strip() if not any(keyword in text for keyword in TRIGGER_KEYWORDS): return TriggerResult(should_start=False, reason="not_matched") has_attachment = FileAttachment.objects.filter( conversation=conversation, is_active=True, ).exclude(upload_status=FileAttachment.UploadStatus.DELETED).exists() if not has_attachment: return TriggerResult(should_start=False, reason="missing_attachment") return TriggerResult(should_start=True, workflow_type="file_summary") def evaluate_attachment_reader_trigger(conversation: Conversation, content: str) -> TriggerResult: text = (content or "").strip() if not any(keyword in text for keyword in ATTACHMENT_READER_KEYWORDS): return TriggerResult(should_start=False, reason="not_matched") has_attachment = FileAttachment.objects.filter( conversation=conversation, is_active=True, ).exclude(upload_status=FileAttachment.UploadStatus.DELETED).exists() if not has_attachment: return TriggerResult(should_start=False, reason="missing_attachment") return TriggerResult(should_start=True, workflow_type="attachment_reader")