针对 PR 审阅 P1「组合复杂度仍可长时间占满导出线程」与 P3「EXPORT_OUTPUT_TOO_LARGE 误标 HTTP 413」: - plot: FunctionPlot 记录整块 AST 节点数(node_count),parser 累计 - html: 单篇文档累计节点预算 _MAX_TOTAL_PLOT_NODES=8000,超限回退占位 - service: 并发渲染信号量 MAX_CONCURRENT_RENDERS=2,超限额任务排队等待 - docs: 错误码区分同步 HTTP 错误与异步任务错误,EXPORT_OUTPUT_TOO_LARGE 由 error_code 返回而非 HTTP 413 - 补充节点预算与并发限制两条回归测试(全量 627 通过) Co-Authored-By: Claude Code <noreply@anthropic.com>
58 lines
1.6 KiB
Python
58 lines
1.6 KiB
Python
"""Function Plot 内部数据模型。
|
|
|
|
契约 §12.2 的 FunctionPlot 结构与 §10.4 的 StaticRenderResult 只在导出链路的后端内部
|
|
流转,不进入 HTTP 契约,因此与 Document AST 一样放在独立包内,不进 contracts.py。
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Literal
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
class FunctionPlotExpression(BaseModel):
|
|
"""单条函数表达式;expression 为数学表达式文本(不含 ``y =`` 前缀)。"""
|
|
|
|
expression: str
|
|
label: str | None = None
|
|
color: str | None = None
|
|
|
|
|
|
class PlotAxes(BaseModel):
|
|
xlabel: str | None = None
|
|
ylabel: str | None = None
|
|
grid: bool = True
|
|
|
|
|
|
class FunctionPlot(BaseModel):
|
|
version: int = 1
|
|
expressions: list[FunctionPlotExpression]
|
|
domain: tuple[float, float] = (-10.0, 10.0)
|
|
range: tuple[float, float] | None = None
|
|
axes: PlotAxes = Field(default_factory=PlotAxes)
|
|
# 该块所有表达式 AST 节点数之和,供导出器做文档级累计复杂度预算
|
|
node_count: int = 0
|
|
|
|
|
|
class PlotDiagnostic(BaseModel):
|
|
severity: Literal["warning", "error"]
|
|
code: str
|
|
message: str
|
|
line: int | None = None
|
|
|
|
|
|
class FunctionPlotParseResult(BaseModel):
|
|
"""解析结果:任一表达式 error 时 plot 为 None(整块回退占位),仅 warning 时 plot 有效。"""
|
|
|
|
plot: FunctionPlot | None = None
|
|
diagnostics: list[PlotDiagnostic] = Field(default_factory=list)
|
|
|
|
|
|
class StaticRenderResult(BaseModel):
|
|
content: str
|
|
mime_type: str = "image/svg+xml"
|
|
width: int
|
|
height: int
|
|
warnings: list[str] = Field(default_factory=list)
|