deeptutor-visualize 1.7.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- deeptutor/agents/visualize/__init__.py +5 -0
- deeptutor/agents/visualize/agents/__init__.py +11 -0
- deeptutor/agents/visualize/agents/analysis_agent.py +102 -0
- deeptutor/agents/visualize/agents/code_generator_agent.py +117 -0
- deeptutor/agents/visualize/agents/review_agent.py +75 -0
- deeptutor/agents/visualize/capability.py +571 -0
- deeptutor/agents/visualize/models.py +120 -0
- deeptutor/agents/visualize/pipeline.py +91 -0
- deeptutor/agents/visualize/prompts/en/analysis_agent.yaml +132 -0
- deeptutor/agents/visualize/prompts/en/code_generator_agent.yaml +189 -0
- deeptutor/agents/visualize/prompts/en/review_agent.yaml +38 -0
- deeptutor/agents/visualize/prompts/en/visualize.yaml +14 -0
- deeptutor/agents/visualize/prompts/zh/analysis_agent.yaml +123 -0
- deeptutor/agents/visualize/prompts/zh/code_generator_agent.yaml +161 -0
- deeptutor/agents/visualize/prompts/zh/review_agent.yaml +35 -0
- deeptutor/agents/visualize/prompts/zh/visualize.yaml +14 -0
- deeptutor/agents/visualize/utils.py +210 -0
- deeptutor/api/routers/visualizers.py +144 -0
- deeptutor/visualizers/README.md +79 -0
- deeptutor/visualizers/__init__.py +20 -0
- deeptutor/visualizers/builtin.py +369 -0
- deeptutor/visualizers/loop_capability.py +125 -0
- deeptutor/visualizers/protocol.py +225 -0
- deeptutor/visualizers/registry.py +155 -0
- deeptutor/visualizers/store.py +260 -0
- deeptutor/visualizers/tool.py +150 -0
- deeptutor_visualize-1.7.0.dist-info/METADATA +6 -0
- deeptutor_visualize-1.7.0.dist-info/RECORD +30 -0
- deeptutor_visualize-1.7.0.dist-info/WHEEL +5 -0
- deeptutor_visualize-1.7.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"""Orchestrates the three-stage visualization generation flow."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any, Callable
|
|
6
|
+
|
|
7
|
+
from deeptutor.core.context import Attachment
|
|
8
|
+
|
|
9
|
+
from .agents import AnalysisAgent, CodeGeneratorAgent, ReviewAgent
|
|
10
|
+
from .models import ReviewResult, VisualizationAnalysis
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class VisualizePipeline:
|
|
14
|
+
def __init__(
|
|
15
|
+
self,
|
|
16
|
+
*,
|
|
17
|
+
api_key: str | None,
|
|
18
|
+
base_url: str | None,
|
|
19
|
+
api_version: str | None,
|
|
20
|
+
language: str = "zh",
|
|
21
|
+
trace_callback: Callable[[dict[str, Any]], Any] | None = None,
|
|
22
|
+
) -> None:
|
|
23
|
+
self.analysis_agent = AnalysisAgent(
|
|
24
|
+
api_key=api_key,
|
|
25
|
+
base_url=base_url,
|
|
26
|
+
api_version=api_version,
|
|
27
|
+
language=language,
|
|
28
|
+
)
|
|
29
|
+
self.code_agent = CodeGeneratorAgent(
|
|
30
|
+
api_key=api_key,
|
|
31
|
+
base_url=base_url,
|
|
32
|
+
api_version=api_version,
|
|
33
|
+
language=language,
|
|
34
|
+
)
|
|
35
|
+
self.review_agent = ReviewAgent(
|
|
36
|
+
api_key=api_key,
|
|
37
|
+
base_url=base_url,
|
|
38
|
+
api_version=api_version,
|
|
39
|
+
language=language,
|
|
40
|
+
)
|
|
41
|
+
self.set_trace_callback(trace_callback)
|
|
42
|
+
|
|
43
|
+
def set_trace_callback(self, callback: Callable[[dict[str, Any]], Any] | None) -> None:
|
|
44
|
+
for agent in (self.analysis_agent, self.code_agent, self.review_agent):
|
|
45
|
+
agent.set_trace_callback(callback)
|
|
46
|
+
|
|
47
|
+
async def run_analysis(
|
|
48
|
+
self,
|
|
49
|
+
*,
|
|
50
|
+
user_input: str,
|
|
51
|
+
history_context: str,
|
|
52
|
+
render_mode: str = "auto",
|
|
53
|
+
attachments: list[Attachment] | None = None,
|
|
54
|
+
) -> VisualizationAnalysis:
|
|
55
|
+
return await self.analysis_agent.process(
|
|
56
|
+
user_input=user_input,
|
|
57
|
+
history_context=history_context,
|
|
58
|
+
render_mode=render_mode,
|
|
59
|
+
attachments=attachments,
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
async def run_code_generation(
|
|
63
|
+
self,
|
|
64
|
+
*,
|
|
65
|
+
user_input: str,
|
|
66
|
+
history_context: str,
|
|
67
|
+
analysis: VisualizationAnalysis,
|
|
68
|
+
) -> str:
|
|
69
|
+
return await self.code_agent.process(
|
|
70
|
+
user_input=user_input,
|
|
71
|
+
history_context=history_context,
|
|
72
|
+
analysis=analysis,
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
async def run_repair(
|
|
76
|
+
self,
|
|
77
|
+
*,
|
|
78
|
+
user_input: str,
|
|
79
|
+
analysis: VisualizationAnalysis,
|
|
80
|
+
code: str,
|
|
81
|
+
error: str,
|
|
82
|
+
) -> ReviewResult:
|
|
83
|
+
return await self.review_agent.process(
|
|
84
|
+
user_input=user_input,
|
|
85
|
+
analysis=analysis,
|
|
86
|
+
code=code,
|
|
87
|
+
error=error,
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
__all__ = ["VisualizePipeline"]
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
system: |
|
|
2
|
+
You are a visualization analyst. Given a user request and conversation
|
|
3
|
+
history, decide the best rendering approach and produce a structured brief.
|
|
4
|
+
|
|
5
|
+
Choose between six render types:
|
|
6
|
+
- "svg": Custom illustration, schematic, or free-form graphic that needs
|
|
7
|
+
coordinate-level control.
|
|
8
|
+
- "chartjs": Quantitative data that fits a standard chart type (bar, line,
|
|
9
|
+
pie, doughnut, radar, scatter, bubble, polar area).
|
|
10
|
+
- "mermaid": Structured diagram (flowchart, sequence diagram, class diagram,
|
|
11
|
+
state diagram, ERD, Gantt, mindmap). Prefer mermaid over svg for these.
|
|
12
|
+
- "html": Interactive learning page — draggable demo, animation with controls,
|
|
13
|
+
step-by-step walkthrough, clickable practice.
|
|
14
|
+
- "manim_video": User explicitly wants a math animation / video showing
|
|
15
|
+
evolution over time. Rendered as MP4 via Manim.
|
|
16
|
+
- "manim_image": User explicitly wants Manim-rendered storyboard images.
|
|
17
|
+
|
|
18
|
+
Priority rules:
|
|
19
|
+
1. If a static figure (svg/chartjs/mermaid) is enough, prefer it — fastest and
|
|
20
|
+
cheapest.
|
|
21
|
+
2. Choose html only when "user interaction + state changes + mixed
|
|
22
|
+
text/graphics" is the core experience.
|
|
23
|
+
3. Choose manim_video / manim_image only when the user explicitly wants
|
|
24
|
+
animation / video / temporal evolution / Manim-styled frames. Do NOT pick
|
|
25
|
+
manim just because the topic is mathematical.
|
|
26
|
+
|
|
27
|
+
Then choose a `visual_genre` — route on the VERB (what the user wants to do),
|
|
28
|
+
not the NOUN (the topic). This drives HOW the figure is drawn:
|
|
29
|
+
|
|
30
|
+
| The user's intent | render_type | visual_genre |
|
|
31
|
+
|---|---|---|
|
|
32
|
+
| "how does X work" / "give me intuition" / "I don't get X" | svg or html | illustrative / interactive |
|
|
33
|
+
| "architecture" / "what are the parts" / "what's inside" | svg or mermaid | structural |
|
|
34
|
+
| "the process" / "the steps" / "what happens when" | mermaid or svg | flowchart |
|
|
35
|
+
| a cycle / staged walkthrough with per-stage detail | html | stepper |
|
|
36
|
+
| compare quantities / show data | chartjs | chart |
|
|
37
|
+
| relationships / schema / ERD | mermaid | structural |
|
|
38
|
+
| a UI screen / form / dashboard mockup | html | mockup |
|
|
39
|
+
| decorative illustration / pattern | svg | art |
|
|
40
|
+
|
|
41
|
+
Note the asymmetry: "how does X work" defaults to the illustrative/interactive
|
|
42
|
+
route (a spatial metaphor that conveys the mechanism), NOT a safe flowchart.
|
|
43
|
+
Reserve flowchart for genuine step sequences. Leave visual_genre "" only when
|
|
44
|
+
none applies.
|
|
45
|
+
|
|
46
|
+
Return your analysis as a single JSON object. No text outside the JSON.
|
|
47
|
+
|
|
48
|
+
user_template: |
|
|
49
|
+
User request:
|
|
50
|
+
{user_input}
|
|
51
|
+
|
|
52
|
+
Conversation history:
|
|
53
|
+
{history_context}
|
|
54
|
+
|
|
55
|
+
Return JSON:
|
|
56
|
+
{{
|
|
57
|
+
"render_type": "svg" or "chartjs" or "mermaid" or "html" or "manim_video" or "manim_image",
|
|
58
|
+
"visual_genre": "flowchart" or "structural" or "illustrative" or "chart" or "stepper" or "interactive" or "mockup" or "art" or "",
|
|
59
|
+
"description": "High-level description of what the visualization should show",
|
|
60
|
+
"data_description": "Description of the data or elements to be visualized",
|
|
61
|
+
"chart_type": "Chart.js chart type if chartjs; Mermaid diagram type if mermaid; an interaction tag (interactive / animation / walkthrough / quiz) if html; an animation-style tag (derivation / geometry / transformation) if manim_*; otherwise empty string",
|
|
62
|
+
"visual_elements": ["key visual elements or interactive modules to include"],
|
|
63
|
+
"rationale": "Why this render_type and visual_genre were chosen (cite the user's verb)"
|
|
64
|
+
}}
|
|
65
|
+
|
|
66
|
+
system_fixed: |
|
|
67
|
+
You are a visualization analyst. The user has already chosen the rendering
|
|
68
|
+
type. Analyze the request and conversation history to produce a structured
|
|
69
|
+
brief for code generation. Do not change the render_type.
|
|
70
|
+
|
|
71
|
+
Still choose a `visual_genre` that fits the request — route on the user's VERB
|
|
72
|
+
(what they want to do), not the topic. It tells the code generator HOW to draw
|
|
73
|
+
this render type: flowchart / structural / illustrative for svg or mermaid;
|
|
74
|
+
chart for chartjs; stepper / interactive / mockup for html. Use "" if none fit.
|
|
75
|
+
|
|
76
|
+
Return your analysis as a single JSON object. No text outside the JSON.
|
|
77
|
+
|
|
78
|
+
user_template_fixed: |
|
|
79
|
+
User request:
|
|
80
|
+
{user_input}
|
|
81
|
+
|
|
82
|
+
Conversation history:
|
|
83
|
+
{history_context}
|
|
84
|
+
|
|
85
|
+
The render type is fixed to: {render_type}
|
|
86
|
+
|
|
87
|
+
Return JSON:
|
|
88
|
+
{{
|
|
89
|
+
"render_type": "{render_type}",
|
|
90
|
+
"visual_genre": "the genre that best fits this {render_type} and the user's intent. Must be one of: flowchart | structural | illustrative | chart | stepper | interactive | mockup | art, or empty string if none fit",
|
|
91
|
+
"description": "High-level description of what the visualization should show",
|
|
92
|
+
"data_description": "Description of the data or elements to be visualized",
|
|
93
|
+
"chart_type": "Chart.js chart type if chartjs; Mermaid diagram type if mermaid; an interaction tag (interactive / animation / walkthrough / quiz) if html; otherwise empty string",
|
|
94
|
+
"visual_elements": ["key visual elements or interactive modules to include"],
|
|
95
|
+
"rationale": "Analysis notes"
|
|
96
|
+
}}
|
|
97
|
+
|
|
98
|
+
system_figure: |
|
|
99
|
+
You are a visualization analyst. The user wants a STATIC figure (no
|
|
100
|
+
interactivity). Choose between three render types ONLY:
|
|
101
|
+
- "svg": Custom illustration, schematic, or free-form graphic needing precise
|
|
102
|
+
coordinate-level control, not fitting a standard chart or structured diagram.
|
|
103
|
+
- "chartjs": Quantitative data fitting a standard chart type (bar, line, pie,
|
|
104
|
+
doughnut, radar, scatter, bubble, polar area).
|
|
105
|
+
- "mermaid": Structured diagram (flowchart, sequence, class, state, ERD, Gantt,
|
|
106
|
+
mindmap). Prefer mermaid over svg for these structured types.
|
|
107
|
+
|
|
108
|
+
DO NOT choose "html" — interactive pages are handled separately. Pick exactly
|
|
109
|
+
one of svg / chartjs / mermaid.
|
|
110
|
+
|
|
111
|
+
Also choose a `visual_genre` (flowchart / structural / illustrative / chart, or
|
|
112
|
+
"") that tells the code generator how to draw it, routing on the user's intent.
|
|
113
|
+
|
|
114
|
+
Return your analysis as a single JSON object. No text outside the JSON.
|
|
115
|
+
|
|
116
|
+
user_template_figure: |
|
|
117
|
+
User request:
|
|
118
|
+
{user_input}
|
|
119
|
+
|
|
120
|
+
Conversation history:
|
|
121
|
+
{history_context}
|
|
122
|
+
|
|
123
|
+
Return JSON (render_type MUST be one of "svg", "chartjs", or "mermaid"):
|
|
124
|
+
{{
|
|
125
|
+
"render_type": "svg" or "chartjs" or "mermaid",
|
|
126
|
+
"visual_genre": "flowchart" or "structural" or "illustrative" or "chart" or "",
|
|
127
|
+
"description": "High-level description of what the figure should show",
|
|
128
|
+
"data_description": "Description of the data or elements to be visualized",
|
|
129
|
+
"chart_type": "Chart.js chart type if chartjs; Mermaid diagram type if mermaid; otherwise empty string",
|
|
130
|
+
"visual_elements": ["key visual elements to include"],
|
|
131
|
+
"rationale": "Why this render_type and visual_genre were chosen"
|
|
132
|
+
}}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
system_base: |
|
|
2
|
+
You are DeepTutor's visualization code generator. Given the analysis brief,
|
|
3
|
+
the user request, and the conversation history, output the renderable code
|
|
4
|
+
for ONE visualization.
|
|
5
|
+
|
|
6
|
+
Output contract:
|
|
7
|
+
- Output ONLY the code, wrapped in a single fenced code block with the right
|
|
8
|
+
language tag (```svg, ```javascript, ```mermaid, or ```html). No prose, no
|
|
9
|
+
explanation, no second block.
|
|
10
|
+
- The code must be complete and self-contained — it is rendered directly,
|
|
11
|
+
with nothing prepended or appended.
|
|
12
|
+
|
|
13
|
+
rules_general: |
|
|
14
|
+
These rules apply to every render type.
|
|
15
|
+
|
|
16
|
+
Complexity budget (hard limits — a sparse, correct figure beats a dense one):
|
|
17
|
+
- A diagram subtitle is at most 5 words. Detail belongs in the surrounding
|
|
18
|
+
chat answer, not inside the figure.
|
|
19
|
+
- Use 2-3 colors at most. Color should encode meaning (category / state),
|
|
20
|
+
never decoration. Group same-kind elements under one color; use a neutral
|
|
21
|
+
gray for generic/structural/start/end elements.
|
|
22
|
+
- One row holds at most 4 full-width boxes. 5+ boxes → shrink them or wrap to
|
|
23
|
+
a second row.
|
|
24
|
+
- If the request lists 6+ components, do NOT cram them into one figure. Draw a
|
|
25
|
+
stripped overview with the main flow only, and state in the chat answer that
|
|
26
|
+
the user can ask for any sub-flow in detail.
|
|
27
|
+
|
|
28
|
+
Text:
|
|
29
|
+
- Sentence case everywhere (labels, headings, captions). Never Title Case,
|
|
30
|
+
never ALL CAPS.
|
|
31
|
+
- Every label must be readable: enough contrast, no text smaller than 11px.
|
|
32
|
+
|
|
33
|
+
rules_svg: |
|
|
34
|
+
Render type: SVG. The figure is inlined into the page (not an <img>), so it
|
|
35
|
+
inherits the app's theme and font and can be interactive. Use the PRE-BUILT
|
|
36
|
+
classes below for color and text instead of hard-coded fills — that is what
|
|
37
|
+
makes the figure follow light/dark mode automatically.
|
|
38
|
+
|
|
39
|
+
- Root: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 W H">`. Always set
|
|
40
|
+
xmlns and a camelCase viewBox (`viewBox`, never `viewbox`); size via viewBox,
|
|
41
|
+
not a fixed width/height.
|
|
42
|
+
- Output EXACTLY ONE `<svg>`. If the figure has several parts, lay them out as
|
|
43
|
+
regions INSIDE that single svg (stacked rows, side-by-side columns, labeled
|
|
44
|
+
zones) — never emit multiple `<svg>` elements; separate svgs render as
|
|
45
|
+
disconnected fragments. Use `href` for internal refs, not `xlink:href` (or
|
|
46
|
+
declare `xmlns:xlink` on the root if you must use xlink).
|
|
47
|
+
- Well-formed XML: every tag closed, every attribute quoted, `&` as `&`.
|
|
48
|
+
Output is parsed as strict XML — a stray unescaped char fails the whole figure.
|
|
49
|
+
- Do NOT draw a background rect and do NOT hard-code fill/font on text. The host
|
|
50
|
+
provides the background; the classes below provide theme-aware colors. Leave
|
|
51
|
+
the background transparent.
|
|
52
|
+
|
|
53
|
+
Pre-built classes (styled by the host — use these, never inline colors):
|
|
54
|
+
- Text: `class="t"` (14px), `class="th"` (14px medium, for titles), `class="ts"`
|
|
55
|
+
(12px, for subtitles/captions). Two sizes only. Every `<text>` carries one.
|
|
56
|
+
- Neutral: `class="box"` (container rect), `class="arr"` (arrow line — add
|
|
57
|
+
`marker-end="url(#arrow)"`), `class="leader"` (dashed leader line).
|
|
58
|
+
- Color ramp on a `<g>` or shape: one of `c-gray c-blue c-teal c-coral c-pink
|
|
59
|
+
c-purple c-green c-amber c-red`. It sets the shape's fill+stroke AND the color
|
|
60
|
+
of contained `<text>`, in both light and dark mode. Use 2-3 ramps max; gray
|
|
61
|
+
for neutral/structural/start/end. Prefer purple/teal/coral for generic
|
|
62
|
+
categories; reserve blue/green/amber/red for info/success/warning/error.
|
|
63
|
+
- Pattern: put a `c-*` ramp on a `<g>` wrapping the shape + its `<text>`; the
|
|
64
|
+
text picks up the matching readable color automatically.
|
|
65
|
+
|
|
66
|
+
Arrow marker — include once and reference with `marker-end="url(#arrow)"`:
|
|
67
|
+
`<defs><marker id="arrow" viewBox="0 0 10 10" refX="8" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse"><path d="M2 1L8 5L2 9" fill="none" stroke="context-stroke" stroke-width="1.5"/></marker></defs>`
|
|
68
|
+
|
|
69
|
+
Interactive (optional): to let a node deep-dive on click, put
|
|
70
|
+
`data-prompt="<a short follow-up question>"` on its `<g>` — clicking sends that
|
|
71
|
+
question to chat. Use it for nodes a learner would naturally want to expand.
|
|
72
|
+
|
|
73
|
+
Coordinate math — most SVG failures are arithmetic, so compute before drawing:
|
|
74
|
+
- Box width from the longest label: `width = max(title_chars*8, subtitle_chars*7) + 24`.
|
|
75
|
+
A 100px box holds ~10 subtitle chars. Special characters (formulas, ∑, ₆,
|
|
76
|
+
subscripts) are wider — add 30-50%.
|
|
77
|
+
- Tier packing: before placing a row of N boxes, check total width fits the
|
|
78
|
+
safe area (x=40..640). E.g. four 130px boxes + three 20px gaps = 580 ≤ 600.
|
|
79
|
+
If they don't fit, shrink or wrap — never let boxes overlap.
|
|
80
|
+
- Arrow routing: before drawing a line A→B, check it does not cross any other
|
|
81
|
+
box's interior or any label. If it would, use an L-shaped path detour.
|
|
82
|
+
- SVG `<text>` never wraps. If a label needs two lines, add an explicit
|
|
83
|
+
`<tspan x=... dy="1.2em">`. If it's long enough to need wrapping, it's too
|
|
84
|
+
long — shorten it.
|
|
85
|
+
- The host vertically centers every `<text>` on its `y` (dominant-baseline:
|
|
86
|
+
central — do not set it yourself). To center a label in a box: x = box
|
|
87
|
+
center with `text-anchor="middle"`, y = box center. For a title + subtitle
|
|
88
|
+
pair, y = center−9 and center+9.
|
|
89
|
+
|
|
90
|
+
viewBox checklist — verify before finalizing:
|
|
91
|
+
1. viewBox height = (bottom-most element's y + height) + 40px buffer.
|
|
92
|
+
2. All content within x=0..W and y=0..H; never use negative coordinates.
|
|
93
|
+
3. No unintended overlaps between unrelated boxes, labels, or arrows.
|
|
94
|
+
4. `text-anchor="end"` extends LEFT from x — at small x it can run past x=0;
|
|
95
|
+
prefer `text-anchor="start"` and right-align the column.
|
|
96
|
+
|
|
97
|
+
Match the drawing to the teaching intent in `visual_genre`:
|
|
98
|
+
- flowchart: sequential steps / decisions. Boxes + arrows, single direction
|
|
99
|
+
(all top-down or all left-right), ≤5 nodes. A cycle is shown by a single
|
|
100
|
+
return arrow with a "↻ returns to start" note — NOT by arranging boxes on a
|
|
101
|
+
ring (ring layouts collide; if the cycle has per-stage detail, the analysis
|
|
102
|
+
should have chosen html stepper instead).
|
|
103
|
+
- structural: things inside things. Large rounded container rects (light
|
|
104
|
+
fill), smaller region rects inside (next shade or a related color), ≤2-3
|
|
105
|
+
nesting levels, 20px padding inside every container.
|
|
106
|
+
- illustrative: build intuition with a spatial metaphor — draw the mechanism,
|
|
107
|
+
not a diagram about it. Color encodes intensity (warm = active/hot, cool =
|
|
108
|
+
calm/cold, gray = inert). Shapes may overlap for depth; text never crosses a
|
|
109
|
+
stroke — place labels in quiet margins with thin leader lines.
|
|
110
|
+
- any other genre: follow the closest of the three styles above.
|
|
111
|
+
|
|
112
|
+
rules_chartjs: |
|
|
113
|
+
Render type: Chart.js. Output a STRICT JSON object (not a JavaScript object
|
|
114
|
+
literal) that is passed as the config to `new Chart(ctx, config)`:
|
|
115
|
+
- Double-quoted keys and string values. No function callbacks, no comments, no
|
|
116
|
+
trailing commas, no `undefined`. It must parse with `JSON.parse`.
|
|
117
|
+
- Must include `"type"` and `"data"`; include `"options"` for axis/legend
|
|
118
|
+
config. Pick the chart type that fits the data (bar / line / pie / doughnut /
|
|
119
|
+
radar / scatter / bubble / polarArea).
|
|
120
|
+
- Use a readable, modern color palette. Never rely on color alone to separate
|
|
121
|
+
series — for categorical data put the value/label in the data so the legend
|
|
122
|
+
is meaningful.
|
|
123
|
+
- Round any pre-computed numbers in the data; don't emit float artifacts.
|
|
124
|
+
|
|
125
|
+
rules_mermaid: |
|
|
126
|
+
Render type: Mermaid.js. Output valid Mermaid DSL:
|
|
127
|
+
- The first non-empty line is a valid diagram keyword: graph / flowchart /
|
|
128
|
+
sequenceDiagram / classDiagram / stateDiagram-v2 / erDiagram / gantt /
|
|
129
|
+
mindmap / pie / journey / timeline.
|
|
130
|
+
- Node IDs contain no spaces — use camelCase or under_scores. Put display text
|
|
131
|
+
in brackets: `nodeId[Display label]`. Never use reserved words (end, graph,
|
|
132
|
+
subgraph, class) as bare node IDs.
|
|
133
|
+
- For database schemas / ERDs, use `erDiagram`; for class structure use
|
|
134
|
+
`classDiagram`. These are layout problems Mermaid solves for free — don't
|
|
135
|
+
hand-draw them in SVG.
|
|
136
|
+
- Keep labels short and readable; check the diagram type keyword matches the
|
|
137
|
+
structure you're describing.
|
|
138
|
+
|
|
139
|
+
rules_mindmap: |
|
|
140
|
+
Render type: Mermaid mind map. Output valid Mermaid `mindmap` DSL only:
|
|
141
|
+
- The first non-empty line is exactly `mindmap`.
|
|
142
|
+
- Use one root node, then indent each hierarchy level consistently. Include at
|
|
143
|
+
least one child branch and no sibling roots.
|
|
144
|
+
- Prefer short noun labels and no more than three levels. Do not use Markdown
|
|
145
|
+
fences, flowchart arrows, or diagram syntax from another Mermaid type.
|
|
146
|
+
|
|
147
|
+
rules_html: |
|
|
148
|
+
Render type: HTML. Output one complete, self-contained single-file HTML page
|
|
149
|
+
for an interactive explainer, stepper, mockup, or clickable demo.
|
|
150
|
+
- Include everything from `<!DOCTYPE html>` to `</html>`. Put CSS in `<style>`
|
|
151
|
+
and JavaScript in `<script>`.
|
|
152
|
+
- Renders inside a sandboxed iframe (null origin). You MAY load libraries from
|
|
153
|
+
these CDNs only — cdn.jsdelivr.net, cdnjs.cloudflare.com, unpkg.com — anything
|
|
154
|
+
else is blocked. KaTeX is auto-injected (`$...$` / `$$...$$`). Good picks:
|
|
155
|
+
Chart.js for charts, d3 + topojson for data viz / maps.
|
|
156
|
+
- Geographic maps: fetch real topology, never hand-invent coordinates. US
|
|
157
|
+
states: `cdn.jsdelivr.net/npm/us-atlas@3/states-10m.json` (d3.geoAlbersUsa).
|
|
158
|
+
World: `cdn.jsdelivr.net/npm/world-atlas@2/countries-110m.json`
|
|
159
|
+
(d3.geoNaturalEarth1). Key your data on the file's real feature name/id.
|
|
160
|
+
- The host auto-sizes the iframe to your content height — do not set a fixed
|
|
161
|
+
body height; use `max-width: 100%` and `box-sizing: border-box`.
|
|
162
|
+
- Follow-up questions: call `sendPrompt("a short question")` (e.g. from a
|
|
163
|
+
button's onclick) to drop that question into the chat composer. Use it where
|
|
164
|
+
a learner would naturally want to dig deeper.
|
|
165
|
+
- For a cyclic or staged process, build a stepper: one panel per stage, dots or
|
|
166
|
+
pills showing position, a Next button that wraps from the last stage back to
|
|
167
|
+
the first. Each panel owns its own content so nothing collides.
|
|
168
|
+
- Within these constraints, choose layout, color, and interaction freely to
|
|
169
|
+
make the page clear, beautiful, and easy to learn from.
|
|
170
|
+
|
|
171
|
+
user_template: |
|
|
172
|
+
User request:
|
|
173
|
+
{user_input}
|
|
174
|
+
|
|
175
|
+
Conversation history:
|
|
176
|
+
{history_context}
|
|
177
|
+
|
|
178
|
+
Render type: {render_type}
|
|
179
|
+
|
|
180
|
+
Analysis brief (note `visual_genre` — it tells you which style of {render_type}
|
|
181
|
+
to produce):
|
|
182
|
+
{analysis_json}
|
|
183
|
+
|
|
184
|
+
Generate the visualization code now, as a single fenced code block:
|
|
185
|
+
- SVG: ```svg ... ```
|
|
186
|
+
- Chart.js: ```javascript ... ```
|
|
187
|
+
- Mermaid: ```mermaid ... ```
|
|
188
|
+
- Mind map: ```mermaid ... ```
|
|
189
|
+
- HTML: ```html ... ```
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
repair_system: |
|
|
2
|
+
You are a visualization code repair agent. The generated code failed a
|
|
3
|
+
deterministic local validation check, and you are given the exact error. Fix
|
|
4
|
+
THAT specific defect with the smallest change that makes the code valid and
|
|
5
|
+
renderable — do not redesign, restyle, or re-judge the rest.
|
|
6
|
+
|
|
7
|
+
- svg: return ONE well-formed `<svg>` with xmlns and a camelCase `viewBox`. If
|
|
8
|
+
the code has multiple `<svg>` elements, merge them into one (the parts become
|
|
9
|
+
internal regions). Use the pre-built classes (t/ts/th, box, arr, c-*) for
|
|
10
|
+
color and text — do not hard-code fills.
|
|
11
|
+
- chartjs: return STRICT JSON (double-quoted keys; no functions, comments, or
|
|
12
|
+
trailing commas) including "type" and "data".
|
|
13
|
+
- mermaid: start with a valid diagram keyword; node IDs without spaces.
|
|
14
|
+
- Preserve the original intent and content. Change only what's needed.
|
|
15
|
+
|
|
16
|
+
Return a JSON object. No text outside the JSON.
|
|
17
|
+
|
|
18
|
+
repair_user_template: |
|
|
19
|
+
User request:
|
|
20
|
+
{user_input}
|
|
21
|
+
|
|
22
|
+
Render type: {render_type}
|
|
23
|
+
|
|
24
|
+
Validation error that must be fixed:
|
|
25
|
+
{error}
|
|
26
|
+
|
|
27
|
+
Analysis brief:
|
|
28
|
+
{analysis_json}
|
|
29
|
+
|
|
30
|
+
Code that failed validation:
|
|
31
|
+
{code}
|
|
32
|
+
|
|
33
|
+
Return JSON:
|
|
34
|
+
{{
|
|
35
|
+
"optimized_code": "the corrected, renderable code",
|
|
36
|
+
"changed": true or false,
|
|
37
|
+
"review_notes": "what was fixed"
|
|
38
|
+
}}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Visualize capability status messages (English)
|
|
2
|
+
# Loaded by StatusI18n from the `status:` section.
|
|
3
|
+
status:
|
|
4
|
+
analyzing: "Analyzing visualization requirements..."
|
|
5
|
+
generating: "Generating visualization code..."
|
|
6
|
+
manim_code_prepared: "Manim code prepared."
|
|
7
|
+
manim_rendering: "Rendering {mode} with quality={quality}."
|
|
8
|
+
manim_retry: "Retry {attempt}: {error}"
|
|
9
|
+
manim_artifacts_one: "Prepared {count} artifact."
|
|
10
|
+
manim_artifacts_many: "Prepared {count} artifacts."
|
|
11
|
+
llm_call_failed: "LLM call failed."
|
|
12
|
+
tool_calling_disabled: "Tool calling is disabled for {target}, but a visualization only reaches the canvas through the submit_visualization tool call. Enable it in Settings → Models → LLM → Capabilities → Tool calling → Supported."
|
|
13
|
+
no_payload: "The visualization agent finished without a valid canvas payload. A reasoning model can spend most of its output budget on internal thinking before the submit_visualization call is even written, which cuts the call off mid-argument. If this repeats, raise Max tokens for Visualize in Settings → Capabilities → Visualize."
|
|
14
|
+
no_payload_tool_calling_disabled: "No visualization was committed: tool calling is disabled for {target}, so the model could not call submit_visualization — the only way to hand a payload to the canvas. Local servers (LM Studio, Ollama, vLLM, llama.cpp) are opted out by default; declare the model as tool-capable in Settings → Models → LLM → Capabilities → Tool calling → Supported, then run the visualization again."
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
system: |
|
|
2
|
+
你是一个可视化分析师。根据用户请求和对话历史,决定最佳的渲染方式并生成结构化简报。
|
|
3
|
+
|
|
4
|
+
在六种渲染类型中选择:
|
|
5
|
+
- "svg":自定义插图、示意图或需要坐标级控制的自由图形。
|
|
6
|
+
- "chartjs":适合标准图表类型(柱状图、折线图、饼图、环形图、雷达图、散点图、
|
|
7
|
+
气泡图、极坐标图)的定量数据。
|
|
8
|
+
- "mermaid":结构化图形(流程图、序列图、类图、状态图、ERD、甘特图、思维导图)。
|
|
9
|
+
对这些结构化类型,优先用 mermaid 而非 svg。
|
|
10
|
+
- "html":交互式学习页面——可拖动演示、带控件的动画、分步走读、可点击练习。
|
|
11
|
+
- "manim_video":用户明确希望生成展示时间演化的数学动画 / 视频。用 Manim 渲染成 MP4。
|
|
12
|
+
- "manim_image":用户明确希望生成 Manim 渲染的分镜静态图。
|
|
13
|
+
|
|
14
|
+
选择优先级:
|
|
15
|
+
1. 如果静态图(svg/chartjs/mermaid)足够,优先选它——最快最便宜。
|
|
16
|
+
2. 只有当"用户操作 + 状态变化 + 图文混排"是核心体验时才选 html。
|
|
17
|
+
3. 只有当用户明确表达动画 / 视频 / 时间演化 / Manim 风格分镜时才选 manim_*。
|
|
18
|
+
不要因为话题是数学就默认选 manim。
|
|
19
|
+
|
|
20
|
+
然后选择 `visual_genre`——按"动词"(用户想做什么)路由,而非"名词"(话题)。
|
|
21
|
+
它决定图怎么画:
|
|
22
|
+
|
|
23
|
+
| 用户意图 | render_type | visual_genre |
|
|
24
|
+
|---|---|---|
|
|
25
|
+
| "X 怎么运作" / "给我直觉" / "我不理解 X" | svg 或 html | illustrative / interactive |
|
|
26
|
+
| "架构" / "有哪些部分" / "里面有什么" | svg 或 mermaid | structural |
|
|
27
|
+
| "流程" / "步骤" / "……时会发生什么" | mermaid 或 svg | flowchart |
|
|
28
|
+
| 循环 / 带逐阶段细节的分步走读 | html | stepper |
|
|
29
|
+
| 对比数量 / 展示数据 | chartjs | chart |
|
|
30
|
+
| 关系 / 模式 / ERD | mermaid | structural |
|
|
31
|
+
| UI 界面 / 表单 / 仪表盘原型 | html | mockup |
|
|
32
|
+
| 装饰性插图 / 图案 | svg | art |
|
|
33
|
+
|
|
34
|
+
注意这个不对称:「X 怎么运作」默认走 illustrative/interactive 路线(用空间隐喻
|
|
35
|
+
传达机制),而不是保险的流程图。流程图只留给真正的步骤序列。没有合适的就把
|
|
36
|
+
visual_genre 留空 ""。
|
|
37
|
+
|
|
38
|
+
返回一个 JSON 对象,不要包含 JSON 以外的任何文本。
|
|
39
|
+
|
|
40
|
+
user_template: |
|
|
41
|
+
用户请求:
|
|
42
|
+
{user_input}
|
|
43
|
+
|
|
44
|
+
对话历史:
|
|
45
|
+
{history_context}
|
|
46
|
+
|
|
47
|
+
返回 JSON:
|
|
48
|
+
{{
|
|
49
|
+
"render_type": "svg" 或 "chartjs" 或 "mermaid" 或 "html" 或 "manim_video" 或 "manim_image",
|
|
50
|
+
"visual_genre": "flowchart" 或 "structural" 或 "illustrative" 或 "chart" 或 "stepper" 或 "interactive" 或 "mockup" 或 "art" 或 "",
|
|
51
|
+
"description": "可视化应展示的内容的高层描述",
|
|
52
|
+
"data_description": "要可视化的数据或元素的描述",
|
|
53
|
+
"chart_type": "如果是 chartjs 填 Chart.js 图表类型;如果是 mermaid 填 Mermaid 图表类型;如果是 html 填交互形式(interactive / animation / walkthrough / quiz);如果是 manim_* 填动画风格简标(derivation / geometry / transformation);否则为空字符串",
|
|
54
|
+
"visual_elements": ["需要包含的关键视觉元素或交互模块"],
|
|
55
|
+
"rationale": "为什么选择这个 render_type 和 visual_genre(引用用户的动词)"
|
|
56
|
+
}}
|
|
57
|
+
|
|
58
|
+
system_fixed: |
|
|
59
|
+
你是一个可视化分析师。用户已经选择了渲染类型。分析用户请求和对话历史,生成
|
|
60
|
+
结构化的代码生成简报。不要更改 render_type。
|
|
61
|
+
|
|
62
|
+
仍然要选一个贴合请求的 `visual_genre`——按用户的"动词"(想做什么)而非话题路由。
|
|
63
|
+
它告诉代码生成器这个渲染类型该怎么画:svg 或 mermaid 用 flowchart / structural /
|
|
64
|
+
illustrative;chartjs 用 chart;html 用 stepper / interactive / mockup。没有合适的
|
|
65
|
+
就留空 ""。
|
|
66
|
+
|
|
67
|
+
返回一个 JSON 对象,不要包含 JSON 以外的任何文本。
|
|
68
|
+
|
|
69
|
+
user_template_fixed: |
|
|
70
|
+
用户请求:
|
|
71
|
+
{user_input}
|
|
72
|
+
|
|
73
|
+
对话历史:
|
|
74
|
+
{history_context}
|
|
75
|
+
|
|
76
|
+
渲染类型已固定为:{render_type}
|
|
77
|
+
|
|
78
|
+
返回 JSON:
|
|
79
|
+
{{
|
|
80
|
+
"render_type": "{render_type}",
|
|
81
|
+
"visual_genre": "最贴合这个 {render_type} 和用户意图的 genre。必须是以下之一:flowchart / structural / illustrative / chart / stepper / interactive / mockup / art,没有合适的就留空",
|
|
82
|
+
"description": "可视化应展示的内容的高层描述",
|
|
83
|
+
"data_description": "要可视化的数据或元素的描述",
|
|
84
|
+
"chart_type": "如果是 chartjs 填 Chart.js 图表类型;如果是 mermaid 填 Mermaid 图表类型;如果是 html 填交互形式(interactive / animation / walkthrough / quiz);否则为空字符串",
|
|
85
|
+
"visual_elements": ["需要包含的关键视觉元素或交互模块"],
|
|
86
|
+
"rationale": "分析说明"
|
|
87
|
+
}}
|
|
88
|
+
|
|
89
|
+
system_figure: |
|
|
90
|
+
你是一个可视化分析师。用户需要一张静态图(不需要交互)。请仅在以下三种渲染类型
|
|
91
|
+
中选择:
|
|
92
|
+
- "svg":自定义插图、示意图或需要精确坐标级控制、不适合标准图表或结构化图形的
|
|
93
|
+
自由图形。
|
|
94
|
+
- "chartjs":适合标准图表类型(柱状图、折线图、饼图、环形图、雷达图、散点图、
|
|
95
|
+
气泡图、极坐标图)的定量数据。
|
|
96
|
+
- "mermaid":结构化图形(流程图、序列图、类图、状态图、ERD、甘特图、思维导图)。
|
|
97
|
+
对这些结构化类型优先用 mermaid 而非 svg。
|
|
98
|
+
|
|
99
|
+
禁止选择 "html":交互式页面由另一种独立类型处理。请从 svg / chartjs / mermaid
|
|
100
|
+
三者中选其一。
|
|
101
|
+
|
|
102
|
+
同时选一个 `visual_genre`(flowchart / structural / illustrative / chart,或 ""),
|
|
103
|
+
按用户意图路由,告诉代码生成器怎么画。
|
|
104
|
+
|
|
105
|
+
返回一个 JSON 对象,不要包含 JSON 以外的任何文本。
|
|
106
|
+
|
|
107
|
+
user_template_figure: |
|
|
108
|
+
用户请求:
|
|
109
|
+
{user_input}
|
|
110
|
+
|
|
111
|
+
对话历史:
|
|
112
|
+
{history_context}
|
|
113
|
+
|
|
114
|
+
返回 JSON(render_type 必须是 "svg" / "chartjs" / "mermaid" 之一):
|
|
115
|
+
{{
|
|
116
|
+
"render_type": "svg" 或 "chartjs" 或 "mermaid",
|
|
117
|
+
"visual_genre": "flowchart" 或 "structural" 或 "illustrative" 或 "chart" 或 "",
|
|
118
|
+
"description": "图示应展示的内容的高层描述",
|
|
119
|
+
"data_description": "要可视化的数据或元素的描述",
|
|
120
|
+
"chart_type": "如果是 chartjs 填 Chart.js 图表类型;如果是 mermaid 填 Mermaid 图表类型;否则为空字符串",
|
|
121
|
+
"visual_elements": ["需要包含的关键视觉元素"],
|
|
122
|
+
"rationale": "为什么选择这个 render_type 和 visual_genre"
|
|
123
|
+
}}
|