From c7a0c47ccc47e1138af3707578ac5c010c3cf770 Mon Sep 17 00:00:00 2001 From: cfdaily Date: Sun, 24 May 2026 10:58:14 +0800 Subject: [PATCH] auto-sync: 2026-05-24 10:58:14 --- src/api/mail_routes.py | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/src/api/mail_routes.py b/src/api/mail_routes.py index 92049a2..a24d2d2 100644 --- a/src/api/mail_routes.py +++ b/src/api/mail_routes.py @@ -166,19 +166,42 @@ async def get_mail(mail_id: str): return result -@router.post("") +@router.post(""") async def send_mail(body: Dict[str, Any]): """发送 Mail(创建 Task)""" bb = _bb() mail_id = body.get("id", f"mail-{int(datetime.now().timestamp() * 1000)}") + + # 自动处理 conversation_id:有 in_reply_to 时继承原邮件的 conversation_id + conversation_id = body.get("conversation_id") + in_reply_to = body.get("in_reply_to") + if not conversation_id and in_reply_to: + original = bb.get_task(in_reply_to) + if original: + try: + orig_meta = json.loads(original.must_haves) if original.must_haves else {} + conversation_id = orig_meta.get("conversation_id") + except Exception: + pass + if not conversation_id: + conversation_id = f"conv-{int(datetime.now().timestamp() * 1000)}" + + # 自动处理 type:有 in_reply_to 且未显式指定 type 时默认 inform(防循环) + mail_type = body.get("type") + if mail_type is None: + mail_type = "inform" if in_reply_to else "request" + + # performative 与 type 同义,type 优先 + performative = body.get("performative", mail_type) + meta = { "from": body.get("from", "user"), - "type": body.get("type", "text"), - "performative": body.get("performative", "inform"), + "type": mail_type, + "performative": performative, "is_read": False, - "conversation_id": body.get("conversation_id"), - "in_reply_to": body.get("in_reply_to"), + "conversation_id": conversation_id, + "in_reply_to": in_reply_to, } task = Task(