"""对话域 schema:ContentBlock 判别联合(垂直切片子集)。 完整 21 类型随 WP-03 落地;本切片登记 text/markdown 并拒绝未知类型, 契约真源为 openapi/openapi.yaml。 """ from typing import Annotated, Literal from pydantic import BaseModel, ConfigDict, Field class BlockBase(BaseModel): model_config = ConfigDict(extra="forbid") id: str | None = None # 创建请求可省略,由服务端生成 status: Literal["pending", "streaming", "completed", "failed", "cancelled"] | None = None class TextBlock(BlockBase): type: Literal["text"] text: str language: str | None = None class MarkdownBlock(BlockBase): type: Literal["markdown"] text: str flavor: Literal["hunjing-gfm-v1"] = "hunjing-gfm-v1" ContentBlock = Annotated[TextBlock | MarkdownBlock, Field(discriminator="type")] class MessageIn(BaseModel): model_config = ConfigDict(extra="forbid") content: list[ContentBlock] = Field(min_length=1, max_length=64) start_run: bool = True class MessageOut(BaseModel): id: str conversation_id: str branch_id: str role: str content: list[dict[str, object]] parser_version: str | None = None created_at: str class RunOut(BaseModel): id: str conversation_id: str | None status: str created_at: str completed_at: str | None = None class MessageCreatedOut(BaseModel): message: MessageOut run: RunOut | None