validation.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. from __future__ import annotations
  2. """方案校验结果模型:PlanValidationResult包含问题清单、预算估算与修改意见。"""
  3. from typing import Literal
  4. from pydantic import Field
  5. from app.schemas.common import AppModel
  6. ValidationSeverity = Literal[
  7. "error",
  8. "warning",
  9. ]
  10. BudgetStatus = Literal[
  11. "within_known_budget",
  12. "over_budget",
  13. "unknown",
  14. ]
  15. class ValidationIssue(AppModel):
  16. """行程校验发现的单个问题。"""
  17. code: str
  18. severity: ValidationSeverity
  19. message: str
  20. day_index: int | None = None
  21. activity_sequence: int | None = None
  22. class BudgetEstimate(AppModel):
  23. """当前能够确定的预算估算。
  24. 航班仍标记为接口报价,不擅自解释为
  25. 单人价格或全部旅客总价。
  26. """
  27. currency: str = "CNY"
  28. flight_quote: float | None = Field(
  29. default=None,
  30. ge=0,
  31. )
  32. hotel_estimate: float | None = Field(
  33. default=None,
  34. ge=0,
  35. )
  36. explicit_activity_costs: float = Field(
  37. default=0,
  38. ge=0,
  39. )
  40. known_total: float | None = Field(
  41. default=None,
  42. ge=0,
  43. )
  44. user_budget: float | None = Field(
  45. default=None,
  46. ge=0,
  47. )
  48. remaining_known_budget: float | None = None
  49. status: BudgetStatus = "unknown"
  50. coverage_note: str
  51. class PlanValidationResult(AppModel):
  52. """确定性校验阶段的完整结果。"""
  53. is_valid: bool
  54. error_count: int = Field(ge=0)
  55. warning_count: int = Field(ge=0)
  56. issues: list[ValidationIssue] = Field(
  57. default_factory=list
  58. )
  59. budget: BudgetEstimate
  60. # 后续Supervisor将这些信息交给Planner重写。
  61. revision_feedback: list[str] = Field(
  62. default_factory=list
  63. )