Files
MoviePilot/app/agent/contracts.py
DDSRem 2de976f6b3 Merge pull request #7050 from DDSRem-Dev/codex-comment-migration
docs: 统一全项目中文注释和结构化契约说明
2026-10-17 19:26:29 +08:00

42 lines
1.1 KiB
Python

"""
Agent 轻量公共合同,不触发模型、工具或编排运行时加载。
"""
import uuid
from datetime import datetime
from typing import Any, Mapping, Optional, Sequence
from app.schemas.types import ReplyMode
def build_display_message(
role: str,
content: str = "",
attachments: Optional[Sequence[Mapping[str, object]]] = None,
status: str = "done",
) -> dict[str, Any]:
"""
构造前后端共享的 Agent 会话展示消息。
附件只读且不复制非空输入,字段值可以保留嵌套展示数据。
"""
normalized_content = content or ""
return {
"id": f"{role}-{uuid.uuid4().hex}",
"role": role,
"content": normalized_content,
"createdAt": int(datetime.now().timestamp() * 1000),
"status": status,
"tools": [],
"segments": (
[{"type": "text", "content": normalized_content}]
if normalized_content
else []
),
"attachments": attachments or [],
"choices": [],
}
__all__ = ["ReplyMode", "build_display_message"]