Files
hunjing/backend/app/conversations/schemas.py
T
chenxin 491136c770 ✨ feat: 灵台引擎 Python 绑定与消息路径接入(WP-15/WP-03 交界)
- engine/bindings:nanobind 官方薄绑定包 hunjing-lingtai(LingtaiEngine RAII、HjStatus→LingtaiError 映射、HJ_ABI_VERSION 导出);scikit-build-core 构建,直接编译引擎源码自包含
- backend 以 editable 路径依赖接入;typings/lingtai.pyi 类型存根(mypy strict 全绿)
- app/core/lingtai.py:懒初始化单例 + LingtaiUnavailable fail-closed(禁止宿主第二实现降级)
- 迁移 3:message.parser_version;post_message 的 markdown 输入经 hj_transform 规范化为 canonical blocks(展开 code/mermaid/math 并标注 parser_version,契约第 4 节)
- 测试 29 项全绿:消息展开、Python/C++ golden 字节一致、引擎注入失败时消息路径显式 500(fail-closed 验证)
2026-09-10 11:26:40 +08:00

62 lines
1.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""对话域 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