Coverage for app / documents / visuals / mermaid / vocabulary.py: 100%
11 statements
« prev ^ index » next coverage.py v7.13.4, created at 2026-10-31 11:23 +0000
« prev ^ index » next coverage.py v7.13.4, created at 2026-10-31 11:23 +0000
1"""The Mermaid diagram types CHAIN-R offers, and the words each opens with.
3Kept apart from the drawers (no reportlab here), so ``render_mermaid``'s
4description and the rendering hint can name the types without importing
5them; ``visual`` checks both vocabularies against the registry of drawers at
6import, so a type is offered exactly when the PDF can draw it.
7"""
9from __future__ import annotations
11from typing import Literal
13from app.util import vocab
15#: One canonical first word per type: what the model is told to write.
16MermaidType = Literal[
17 "flowchart",
18 "sequenceDiagram",
19 "stateDiagram-v2",
20 "classDiagram",
21 "erDiagram",
22 "pie",
23 "gantt",
24]
26#: Every first word read: the canonical ones and Mermaid's other names for
27#: the same types.
28MermaidKeyword = Literal[
29 "flowchart",
30 "flowchart-elk",
31 "graph",
32 "sequenceDiagram",
33 "stateDiagram",
34 "stateDiagram-v2",
35 "classDiagram",
36 "classDiagram-v2",
37 "erDiagram",
38 "pie",
39 "gantt",
40]
42#: What each type draws, as the prompt's table names it.
43TYPE_LABELS: dict[str, str] = {
44 "flowchart": "flowchart (also written graph)",
45 "sequenceDiagram": "sequence diagram",
46 "stateDiagram-v2": "state diagram",
47 "classDiagram": "class diagram",
48 "erDiagram": "entity relationship diagram",
49 "pie": "pie chart",
50 "gantt": "Gantt chart",
51}
52vocab.check(TYPE_LABELS, MermaidType)
55def offered() -> str:
56 """``flowchart, sequenceDiagram, …``: the first words a diagram may
57 open with, for a description or a refusal."""
58 return vocab.listing(MermaidType, sep=", ")
61def described() -> str:
62 """The types in words, for the prompt's table."""
63 return vocab.one_of([TYPE_LABELS[t] for t in vocab.values(MermaidType)], quote="")