Files
meida_backend/packages/report/schemas.py
T
xsl 7bcbb8d40b
CI / lint / typecheck / import-linter / tests / secrets (push) Canceled after 0s
feat(agent,report): 会话持久化与画像注入、报告反馈与预约留资——PM/开发双Agent迭代1-3
- agent: ag_conversation/ag_message 表(迁移0007),上下文组装注入最近报告画像摘要
  (report.profile.latest_profile_summary 经 apps 层闭包注入,同层不互调),历史带最近
  AGENT_HISTORY_TURNS=10 轮;POST/GET /agent/conversations 与消息历史接口
- agent 修复:ChatRequest.conversation_id 改 str(雪花ID超2^53,JS Number丢精度);
  _build_context 挪进 reserve commit 后同一 try,异常走 refund 兜底
- report: rp_feedback(维度反馈 upsert,认同率/修正率 SQL 可算,T-P3-21 最小版——
  L1 记忆未建,不回写结论)+ rp_reservation(预约留资幂等,T-P3-22,预约率口径
  行数/full_report.card_view 去重曝光,门槛≥8%),迁移0008
- 测试:全量 606 passed;ruff/mypy/lint-imports 全绿;E2E 真实 deepseek-v4-flash 验证
  画像注入与历史携带
2026-09-11 21:50:58 +08:00

107 lines
3.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.
"""报告域的请求/响应模型。
Wire 响应统一走 ok() 信封(架构文档 §9.2),这里的模型只描述 ``data`` 部分;
雪花 ID 一律以字符串返回,避免 JS 精度丢失(NFR-MAINT-01 契约先行)。
"""
from __future__ import annotations
from datetime import datetime
from typing import Literal
from pydantic import BaseModel, Field
class ReportCreateRequest(BaseModel):
questionnaire: dict[str, object] = Field(
default_factory=dict, description="问卷答案;字段结构由产品定稿后在路由层收紧"
)
photo_object_key: str = Field(
min_length=1, max_length=255, description="临时桶里已上传照片的对象键(report_photo 场景)"
)
request_key: str | None = Field(
default=None, max_length=128, description="幂等键;相同键返回同一任务且不重复扣配额"
)
class ReportRegenerateRequest(BaseModel):
request_key: str | None = Field(
default=None, max_length=128, description="幂等键;相同键返回同一任务且不重复扣配额"
)
class ReportExportRequest(BaseModel):
request_key: str | None = Field(
default=None, max_length=128, description="幂等键;相同键返回同一导出任务且不重复扣配额"
)
class ReportExportResponse(BaseModel):
task_id: str
status: str = Field(description="tk_task 状态;导出完成后任务中心可取到 asset_key")
class ReportSubmitResponse(BaseModel):
task_id: str
report_id: str
status: str = Field(description="tk_task 状态;报告本体状态与其同步推进")
version: int
class ReportItem(BaseModel):
report_id: str
tier: str
status: str
version: int
result: dict[str, object] = Field(
description="按阶段键组织的产物;failed 报告只透错误摘要(中间态留给流水线复用)"
)
created_at: datetime
completed_at: datetime | None
# ---------------------------------------------------------------------------
# T-P3-21:维度级结论反馈
# ---------------------------------------------------------------------------
FeedbackVerdict = Literal["accurate", "inaccurate"]
class FeedbackCreateRequest(BaseModel):
dimension_key: str = Field(
min_length=1, max_length=64, description="报告 result.diagnosis.dimensions 的 key"
)
verdict: FeedbackVerdict = Field(description="准(accurate)/ 不准(inaccurate)")
correction: str | None = Field(
default=None, max_length=200, description="verdict=inaccurate 时的可选修正,≤200 字"
)
class FeedbackUpsertResponse(BaseModel):
dimension_key: str
verdict: str
updated: bool = Field(description="true=同维度已有反馈被覆盖更新;false=新建")
class FeedbackItem(BaseModel):
dimension_key: str
verdict: str
correction: str | None
created_at: datetime
# ---------------------------------------------------------------------------
# T-P3-22:预约留资(topic 预留通用性,首期 full_report)
# ---------------------------------------------------------------------------
class ReservationCreateRequest(BaseModel):
topic: str = Field(min_length=1, max_length=32)
class ReservationResponse(BaseModel):
topic: str
created: bool = Field(description="false=已存在(幂等命中,HTTP 仍 200)")
created_at: datetime
class ReservationListResponse(BaseModel):
topics: list[str]