auto-sync: 2026-05-24 10:58:14

This commit is contained in:
cfdaily
2026-05-24 10:58:14 +08:00
parent 160c7a06e7
commit c7a0c47ccc
+28 -5
View File
@@ -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(