draftboard 0.0.1__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.
Files changed (51) hide show
  1. draftboard/__init__.py +41 -0
  2. draftboard/__main__.py +225 -0
  3. draftboard/agent.py +104 -0
  4. draftboard/api.py +901 -0
  5. draftboard/measure.py +225 -0
  6. draftboard/models.py +407 -0
  7. draftboard/pptx_export.py +479 -0
  8. draftboard/render.py +80 -0
  9. draftboard/static/404.html +1 -0
  10. draftboard/static/__next.__PAGE__.txt +27 -0
  11. draftboard/static/__next._full.txt +22 -0
  12. draftboard/static/__next._tree.txt +3 -0
  13. draftboard/static/_next/static/0t_Cdsf-nvbYcwqDy78ch/_buildManifest.js +11 -0
  14. draftboard/static/_next/static/0t_Cdsf-nvbYcwqDy78ch/_clientMiddlewareManifest.js +1 -0
  15. draftboard/static/_next/static/0t_Cdsf-nvbYcwqDy78ch/_ssgManifest.js +1 -0
  16. draftboard/static/_next/static/chunks/0cz1d0mv5g_q7.js +1 -0
  17. draftboard/static/_next/static/chunks/0oheds1fsp9jx.js +1 -0
  18. draftboard/static/_next/static/chunks/1vsonpqt4u2rw.js +1 -0
  19. draftboard/static/_next/static/chunks/24xul4hawiu8l.js +1 -0
  20. draftboard/static/_next/static/chunks/2r7iycbt4s29o.js +22 -0
  21. draftboard/static/_next/static/chunks/2utugak-w5oge.css +1 -0
  22. draftboard/static/_next/static/chunks/39_j1bdzreq0m.js +1 -0
  23. draftboard/static/_next/static/chunks/3qfy96eoyh-ek.js +1 -0
  24. draftboard/static/_next/static/chunks/3u8gxd9uztfzl.js +4 -0
  25. draftboard/static/_next/static/chunks/3v_59l1qr_8dp.js +31 -0
  26. draftboard/static/_next/static/chunks/turbopack-2u1d16houkiyo.js +1 -0
  27. draftboard/static/_not-found/__next._full.txt +20 -0
  28. draftboard/static/_not-found/__next._not-found/__PAGE__.txt +26 -0
  29. draftboard/static/_not-found/__next._tree.txt +4 -0
  30. draftboard/static/_not-found.html +1 -0
  31. draftboard/static/_not-found.txt +20 -0
  32. draftboard/static/index.html +1 -0
  33. draftboard/static/index.txt +22 -0
  34. draftboard/static/p/__placeholder__/__next._full.txt +27 -0
  35. draftboard/static/p/__placeholder__/__next._tree.txt +5 -0
  36. draftboard/static/p/__placeholder__/__next.p/$d$id/__PAGE__.txt +34 -0
  37. draftboard/static/p/__placeholder__/preview/__next._full.txt +27 -0
  38. draftboard/static/p/__placeholder__/preview/__next._tree.txt +6 -0
  39. draftboard/static/p/__placeholder__/preview/__next.p/$d$id/preview/__PAGE__.txt +35 -0
  40. draftboard/static/p/__placeholder__/preview.html +1 -0
  41. draftboard/static/p/__placeholder__/preview.txt +27 -0
  42. draftboard/static/p/__placeholder__.html +1 -0
  43. draftboard/static/p/__placeholder__.txt +27 -0
  44. draftboard/storage.py +183 -0
  45. draftboard/tasks.py +464 -0
  46. draftboard/themes.py +213 -0
  47. draftboard/tools.py +723 -0
  48. draftboard-0.0.1.dist-info/METADATA +16 -0
  49. draftboard-0.0.1.dist-info/RECORD +51 -0
  50. draftboard-0.0.1.dist-info/WHEEL +4 -0
  51. draftboard-0.0.1.dist-info/entry_points.txt +2 -0
draftboard/measure.py ADDED
@@ -0,0 +1,225 @@
1
+ """
2
+ Line-wrapping and height estimation (phase 1, step 5).
3
+
4
+ Character advances come from real font files via fonttools. This is an
5
+ estimation, not a full shaping engine: no kerning, no ligatures, no complex
6
+ scripts. Results must be paired with real-render checks in the target
7
+ environment. Unbreakable text that cannot fit is reported as an issue,
8
+ never silently truncated.
9
+ """
10
+
11
+ import os
12
+ import pathlib
13
+ from dataclasses import dataclass, field
14
+
15
+ from fontTools.ttLib import TTFont
16
+
17
+ # Trial value from the phase-1 plan. Calibrated 2026-11-19 against headless
18
+ # LibreOffice 26.8 renders of the regression decks (scripts/probe_render.py):
19
+ # max occupied/required ratio 1.046, all line counts matched. LibreOffice
20
+ # only proves its own environment; re-check in PowerPoint before trusting it.
21
+ HEIGHT_MARGIN = 0.08
22
+
23
+ # Characters that must not start a line (closing punctuation / kinsoku).
24
+ NO_LINE_START = set("。,、;:!?)]}〉》」』】…~·‰℃") | set(",.;:!?)]}%")
25
+ # Characters that must not end a line (opening punctuation).
26
+ NO_LINE_END = set("([{〈《「『【") | set("([{")
27
+
28
+
29
+ def _is_ea(ch: str) -> bool:
30
+ return ord(ch) >= 0x2E80
31
+
32
+
33
+ def _breakable(prev: str, cur: str) -> bool:
34
+ if prev in NO_LINE_END or cur in NO_LINE_START:
35
+ return False
36
+ if prev in " \t-":
37
+ return True
38
+ return _is_ea(prev) and _is_ea(cur)
39
+
40
+
41
+ class FontMetrics:
42
+ """Per-character advance widths read from one font file."""
43
+
44
+ def __init__(self, path: pathlib.Path | str) -> None:
45
+ path = pathlib.Path(path)
46
+ if not path.exists():
47
+ raise FileNotFoundError(
48
+ f"Font file not found: {path}. Configure a valid font path; "
49
+ "measurement refuses to guess without the real font."
50
+ )
51
+ font = TTFont(str(path), fontNumber=0, lazy=True)
52
+ self._upem = font["head"].unitsPerEm
53
+ self._cmap = font.getBestCmap()
54
+ self._hmtx = font["hmtx"]
55
+ self._units: dict[str, int] = {}
56
+
57
+ def has_glyph(self, ch: str) -> bool:
58
+ return ord(ch) in self._cmap
59
+
60
+ def advance_pt(self, ch: str, size_pt: float) -> float:
61
+ units = self._units.get(ch)
62
+ if units is None:
63
+ glyph = self._cmap.get(ord(ch), ".notdef")
64
+ units = self._hmtx[glyph][0]
65
+ self._units[ch] = units
66
+ return units * size_pt / self._upem
67
+
68
+
69
+ @dataclass
70
+ class FontPair:
71
+ latin: FontMetrics
72
+ ea: FontMetrics
73
+
74
+
75
+ def load_fonts(
76
+ latin_path: str | pathlib.Path | None = None,
77
+ ea_path: str | pathlib.Path | None = None,
78
+ ) -> FontPair:
79
+ """Resolve font files: explicit path > env override > Windows default."""
80
+ fonts_dir = pathlib.Path(os.environ.get("WINDIR", r"C:\Windows")) / "Fonts"
81
+ latin = latin_path or os.environ.get("DRAFTBOARD_LATIN_FONT") or fonts_dir / "calibri.ttf"
82
+ ea = ea_path or os.environ.get("DRAFTBOARD_EA_FONT") or fonts_dir / "msyh.ttc"
83
+ return FontPair(latin=FontMetrics(latin), ea=FontMetrics(ea))
84
+
85
+
86
+ @dataclass
87
+ class MeasureIssue:
88
+ code: str
89
+ message: str
90
+
91
+
92
+ @dataclass
93
+ class ParagraphMeasurement:
94
+ lines: list[str]
95
+ issues: list[MeasureIssue] = field(default_factory=list)
96
+
97
+ @property
98
+ def line_count(self) -> int:
99
+ return len(self.lines)
100
+
101
+
102
+ @dataclass
103
+ class BoxMeasurement:
104
+ paragraphs: list[ParagraphMeasurement]
105
+ required_height_pt: float
106
+ fits: bool
107
+
108
+ @property
109
+ def total_lines(self) -> int:
110
+ return sum(p.line_count for p in self.paragraphs)
111
+
112
+ @property
113
+ def issues(self) -> list[MeasureIssue]:
114
+ return [i for p in self.paragraphs for i in p.issues]
115
+
116
+
117
+ def _wrap_segment(
118
+ seg: str, avail_pt: float, width_of
119
+ ) -> tuple[list[str], list[MeasureIssue]]:
120
+ if not seg:
121
+ return [""], []
122
+ issues: list[MeasureIssue] = []
123
+ lines: list[str] = []
124
+ start = 0
125
+ last_break: int | None = None
126
+ width = 0.0
127
+ i = 0
128
+ while i < len(seg):
129
+ cw = width_of(seg[i])
130
+ if i > start and _breakable(seg[i - 1], seg[i]):
131
+ last_break = i
132
+ if width + cw > avail_pt and i > start:
133
+ if last_break is not None and last_break > start:
134
+ end = last_break
135
+ else:
136
+ end = i
137
+ run = seg[start:end]
138
+ issues.append(
139
+ MeasureIssue(
140
+ code="OVERLONG_WORD",
141
+ message=(
142
+ "Unbreakable text exceeds the line width "
143
+ f"({avail_pt:.1f}pt): {run[:40]!r}"
144
+ ),
145
+ )
146
+ )
147
+ lines.append(seg[start:end])
148
+ start = end
149
+ width = sum(width_of(c) for c in seg[start:i])
150
+ last_break = None
151
+ for j in range(start + 1, i):
152
+ if _breakable(seg[j - 1], seg[j]):
153
+ last_break = j
154
+ continue
155
+ width += cw
156
+ i += 1
157
+ lines.append(seg[start:])
158
+ return lines, issues
159
+
160
+
161
+ def measure_box(
162
+ texts: list[str],
163
+ *,
164
+ fonts: FontPair,
165
+ width_pt: float,
166
+ height_pt: float,
167
+ size_pt: float,
168
+ line_pt: float,
169
+ space_after_pt: float = 0,
170
+ pad_x_pt: float = 8,
171
+ pad_y_pt: float = 4,
172
+ indent_pt: float = 0,
173
+ margin: float = HEIGHT_MARGIN,
174
+ ) -> BoxMeasurement:
175
+ """Estimate wrapping and required height for one text box.
176
+
177
+ Each entry in *texts* is one paragraph; '\\n' inside an entry is an
178
+ explicit in-paragraph line break. space_after is counted for every
179
+ paragraph including the last (conservative). An empty paragraph still
180
+ occupies one line.
181
+ """
182
+ avail = width_pt - 2 * pad_x_pt - indent_pt
183
+ missing: set[str] = set()
184
+ width_cache: dict[str, float] = {}
185
+
186
+ def width_of(ch: str) -> float:
187
+ w = width_cache.get(ch)
188
+ if w is not None:
189
+ return w
190
+ primary = fonts.ea if _is_ea(ch) else fonts.latin
191
+ fallback = fonts.latin if primary is fonts.ea else fonts.ea
192
+ if primary.has_glyph(ch):
193
+ font = primary
194
+ elif fallback.has_glyph(ch):
195
+ font = fallback
196
+ else:
197
+ font = primary
198
+ if ch not in missing:
199
+ missing.add(ch)
200
+ w = font.advance_pt(ch, size_pt)
201
+ width_cache[ch] = w
202
+ return w
203
+
204
+ paragraphs: list[ParagraphMeasurement] = []
205
+ for text in texts:
206
+ lines: list[str] = []
207
+ issues: list[MeasureIssue] = []
208
+ for seg in text.split("\n"):
209
+ seg_lines, seg_issues = _wrap_segment(seg, avail, width_of)
210
+ lines.extend(seg_lines)
211
+ issues.extend(seg_issues)
212
+ paragraphs.append(ParagraphMeasurement(lines=lines, issues=issues))
213
+
214
+ for ch in sorted(missing):
215
+ issue = MeasureIssue(
216
+ code="MISSING_GLYPH",
217
+ message=f"Character {ch!r} (U+{ord(ch):04X}) has no glyph in either font.",
218
+ )
219
+ paragraphs[0].issues.append(issue)
220
+
221
+ total_lines = sum(p.line_count for p in paragraphs)
222
+ # Conservative: space_after after every paragraph, plus vertical padding.
223
+ required = total_lines * line_pt + space_after_pt * len(paragraphs) + 2 * pad_y_pt
224
+ fits = required * (1 + margin) <= height_pt
225
+ return BoxMeasurement(paragraphs=paragraphs, required_height_pt=required, fits=fits)
draftboard/models.py ADDED
@@ -0,0 +1,407 @@
1
+ """
2
+ Data models for the Draftboard workbench.
3
+ All Pydantic v2 models with field descriptions for schema clarity.
4
+ """
5
+
6
+ from enum import Enum
7
+ from pydantic import BaseModel, Field
8
+ from typing import Optional
9
+
10
+
11
+ class EvidenceStatus(str, Enum):
12
+ SUPPORTED = "supported"
13
+ PARTIAL = "partial"
14
+ UNSUPPORTED = "unsupported"
15
+
16
+
17
+ class AssetType(str, Enum):
18
+ MARKDOWN = "markdown"
19
+ IMAGE = "image"
20
+
21
+
22
+ class SlideLayout(str, Enum):
23
+ COVER = "cover"
24
+ CONTENT = "content"
25
+ BULLETS = "bullets"
26
+ TWO_COLUMN = "two_column"
27
+ TEXT_IMAGE = "text_image"
28
+ CLOSING = "closing"
29
+
30
+
31
+ class SourceFragment(BaseModel):
32
+ source_id: str = Field(description="Unique source fragment ID")
33
+ asset_id: str = Field(description="Asset this fragment comes from")
34
+ location: str = Field(
35
+ description="Line range (Markdown) or asset ID (image), never fabricated"
36
+ )
37
+ content_preview: Optional[str] = Field(
38
+ None, description="Short preview text, None for images"
39
+ )
40
+
41
+
42
+ class OutlineItem(BaseModel):
43
+ outline_item_id: str = Field(description="Unique ID for this outline item")
44
+ title: str = Field(description="Title of the slide/section")
45
+ summary: str = Field(
46
+ description="Summary must NOT upgrade unsupported evidence to fact"
47
+ )
48
+ source_ids: list[str] = Field(description="List of source fragment IDs cited")
49
+ evidence_status: EvidenceStatus = Field(
50
+ description="Evidence quality: supported, partial, or unsupported"
51
+ )
52
+ layout: Optional[SlideLayout] = Field(
53
+ None,
54
+ description=(
55
+ "Requested slide layout; None lets the program apply its default "
56
+ "rule (first item cover, last closing, others content). "
57
+ "two_column requires column_right; text_image requires image_asset_id."
58
+ ),
59
+ )
60
+ column_right: Optional[str] = Field(
61
+ None,
62
+ description="Right-column content when layout is two_column",
63
+ )
64
+ image_asset_id: Optional[str] = Field(
65
+ None,
66
+ description="Uploaded image asset ID (or filename) when layout is text_image",
67
+ )
68
+ speaker_notes: Optional[str] = Field(
69
+ None,
70
+ description="Optional presenter talking points exported to PPTX notes",
71
+ )
72
+
73
+
74
+ # Layouts the program can build from a confirmed outline item.
75
+ OUTLINE_LAYOUTS = {
76
+ SlideLayout.COVER,
77
+ SlideLayout.CONTENT,
78
+ SlideLayout.BULLETS,
79
+ SlideLayout.TWO_COLUMN,
80
+ SlideLayout.TEXT_IMAGE,
81
+ SlideLayout.CLOSING,
82
+ }
83
+
84
+
85
+ def validate_outline(
86
+ items: list[OutlineItem],
87
+ known_source_ids: set[str],
88
+ *,
89
+ allow_empty_sources_for_unsupported: bool = False,
90
+ ) -> list[str]:
91
+ """Program-side outline validation; returns error messages (empty = valid)."""
92
+ errors: list[str] = []
93
+ if not items:
94
+ return ["Outline must contain at least one item."]
95
+ seen: set[str] = set()
96
+ for item in items:
97
+ iid = item.outline_item_id
98
+ if not iid.strip():
99
+ errors.append("Outline item has an empty outline_item_id.")
100
+ if iid in seen:
101
+ errors.append(f"Duplicate outline_item_id '{iid}'.")
102
+ seen.add(iid)
103
+ if not item.title.strip():
104
+ errors.append(f"Outline item '{iid}' has an empty title.")
105
+ if not item.summary.strip():
106
+ errors.append(f"Outline item '{iid}' has an empty summary.")
107
+ if not item.source_ids:
108
+ if not (
109
+ allow_empty_sources_for_unsupported
110
+ and item.evidence_status == EvidenceStatus.UNSUPPORTED
111
+ ):
112
+ errors.append(f"Outline item '{iid}' cites no source_ids.")
113
+ for sid in item.source_ids:
114
+ if sid not in known_source_ids:
115
+ errors.append(
116
+ f"Outline item '{iid}' cites unknown source_id '{sid}'."
117
+ )
118
+ if item.layout is not None and item.layout not in OUTLINE_LAYOUTS:
119
+ errors.append(
120
+ f"Outline item '{iid}': layout '{item.layout.value}' cannot be "
121
+ "generated from an outline; author the IR directly instead."
122
+ )
123
+ if item.layout == SlideLayout.TWO_COLUMN and not (
124
+ item.column_right and item.column_right.strip()
125
+ ):
126
+ errors.append(
127
+ f"Outline item '{iid}': layout 'two_column' requires non-empty "
128
+ "column_right content."
129
+ )
130
+ if item.layout == SlideLayout.TEXT_IMAGE and not (
131
+ item.image_asset_id and item.image_asset_id.strip()
132
+ ):
133
+ errors.append(
134
+ f"Outline item '{iid}': layout 'text_image' requires an "
135
+ "image_asset_id from uploaded project images."
136
+ )
137
+ return errors
138
+
139
+
140
+ class Outline(BaseModel):
141
+ outline_version: str = Field(description="Version identifier, format v-{uuid[:8]}")
142
+ project_id: str = Field(description="Project this outline belongs to")
143
+ items: list[OutlineItem] = Field(description="Ordered list of outline items")
144
+ is_confirmed: bool = Field(
145
+ False, description="True when user has approved this outline"
146
+ )
147
+
148
+
149
+ # Element roles allowed in the IR. image/shape are reserved from M0 and
150
+ # not yet renderable by the exporter.
151
+ ELEMENT_TYPES = {
152
+ "title",
153
+ "subtitle",
154
+ "text",
155
+ "bullet",
156
+ "column_left",
157
+ "column_right",
158
+ "conclusion",
159
+ "image",
160
+ "shape",
161
+ }
162
+
163
+ # Roles each layout accepts besides the mandatory title.
164
+ LAYOUT_ROLES: dict[SlideLayout, set[str]] = {
165
+ SlideLayout.COVER: {"subtitle"},
166
+ SlideLayout.CONTENT: {"text", "image", "shape"},
167
+ SlideLayout.BULLETS: {"bullet"},
168
+ SlideLayout.TWO_COLUMN: {"column_left", "column_right"},
169
+ SlideLayout.TEXT_IMAGE: {"text", "bullet", "image"},
170
+ SlideLayout.CLOSING: {"conclusion"},
171
+ }
172
+
173
+
174
+ class SlideElement(BaseModel):
175
+ element_id: str = Field(description="Unique element ID within the slide")
176
+ type: str = Field(
177
+ description=(
178
+ "Content role: title, subtitle, text, bullet, column_left, "
179
+ "column_right, conclusion, image, shape"
180
+ )
181
+ )
182
+ content: str = Field(description="Element content (text or image reference)")
183
+ source_id: Optional[str] = Field(
184
+ None, description="Source fragment ID this element was drawn from"
185
+ )
186
+
187
+
188
+ class Slide(BaseModel):
189
+ slide_id: str = Field(description="Unique slide ID within the artifact")
190
+ layout: SlideLayout = Field(
191
+ SlideLayout.CONTENT, description="Fixed layout template for this slide"
192
+ )
193
+ elements: list[SlideElement] = Field(description="Elements composing this slide")
194
+ speaker_notes: Optional[str] = Field(
195
+ None, description="Optional presenter notes written to the PPTX notes slide"
196
+ )
197
+
198
+
199
+ class Artifact(BaseModel):
200
+ artifact_id: str = Field(description="Unique artifact identifier")
201
+ project_id: str = Field(description="Project this artifact belongs to")
202
+ artifact_revision: int = Field(ge=1, description="Revision number, starts at 1")
203
+ slides: list[Slide] = Field(description="Ordered list of slides")
204
+ outline_version: str = Field(
205
+ description="Outline version this artifact was generated from"
206
+ )
207
+ template_id: str = Field("default", description="Slide template/theme identifier")
208
+ auto_fit: bool = Field(
209
+ False,
210
+ description="When True, step font size down to floor before failing on overflow",
211
+ )
212
+ schema_version: str = Field("1.0", description="Artifact schema version")
213
+
214
+
215
+ def validate_ir(artifact: Artifact) -> list[str]:
216
+ """Check IR integrity; return a list of error messages (empty = valid).
217
+
218
+ Rejects empty titles, duplicate slide/element IDs, unknown element
219
+ types, and elements whose role does not belong to the slide's layout.
220
+ """
221
+ errors: list[str] = []
222
+ seen_slides: set[str] = set()
223
+ for slide in artifact.slides:
224
+ sid = slide.slide_id
225
+ if sid in seen_slides:
226
+ errors.append(f"Duplicate slide_id '{sid}'.")
227
+ seen_slides.add(sid)
228
+
229
+ titles = [el for el in slide.elements if el.type == "title"]
230
+ if len(titles) != 1:
231
+ errors.append(
232
+ f"Slide '{sid}' must have exactly one title element, "
233
+ f"found {len(titles)}."
234
+ )
235
+ elif not titles[0].content.strip():
236
+ errors.append(f"Slide '{sid}' has an empty title.")
237
+
238
+ allowed = LAYOUT_ROLES[slide.layout] | {"title"}
239
+ seen_elements: set[str] = set()
240
+ for el in slide.elements:
241
+ if el.element_id in seen_elements:
242
+ errors.append(
243
+ f"Duplicate element_id '{el.element_id}' in slide '{sid}'."
244
+ )
245
+ seen_elements.add(el.element_id)
246
+ if el.type not in ELEMENT_TYPES:
247
+ errors.append(
248
+ f"Unknown element type '{el.type}' "
249
+ f"(element '{el.element_id}', slide '{sid}')."
250
+ )
251
+ elif el.type not in allowed:
252
+ errors.append(
253
+ f"Role '{el.type}' is not allowed in layout "
254
+ f"'{slide.layout.value}' (element '{el.element_id}', "
255
+ f"slide '{sid}')."
256
+ )
257
+
258
+ present = {el.type for el in slide.elements}
259
+ if slide.layout == SlideLayout.TWO_COLUMN:
260
+ for role in ("column_left", "column_right"):
261
+ if role not in present:
262
+ errors.append(f"Slide '{sid}' (two_column) is missing {role}.")
263
+ elif slide.layout == SlideLayout.TEXT_IMAGE:
264
+ if "image" not in present:
265
+ errors.append(f"Slide '{sid}' (text_image) is missing image.")
266
+ if not (present & {"text", "bullet"}):
267
+ errors.append(
268
+ f"Slide '{sid}' (text_image) is missing text or bullet content."
269
+ )
270
+ for el in slide.elements:
271
+ if el.type == "image" and not el.content.strip():
272
+ errors.append(
273
+ f"Slide '{sid}' image element '{el.element_id}' has empty content."
274
+ )
275
+ else:
276
+ required = {
277
+ SlideLayout.COVER: set(),
278
+ SlideLayout.CONTENT: {"text"},
279
+ SlideLayout.BULLETS: {"bullet"},
280
+ SlideLayout.CLOSING: {"conclusion"},
281
+ }[slide.layout]
282
+ for role in sorted(required):
283
+ if role not in present:
284
+ errors.append(
285
+ f"Slide '{sid}' ({slide.layout.value}) is missing {role}."
286
+ )
287
+ return errors
288
+
289
+
290
+ class ValidationLevel(str, Enum):
291
+ ERROR = "error"
292
+ WARNING = "warning"
293
+ INFO = "info"
294
+
295
+
296
+ class ValidationIssue(BaseModel):
297
+ level: ValidationLevel = Field(description="Severity of the issue")
298
+ code: str = Field(description="Machine-readable issue code")
299
+ message: str = Field(description="Human-readable description")
300
+ slide_id: Optional[str] = Field(None, description="Affected slide ID, if any")
301
+
302
+
303
+ class ValidationReport(BaseModel):
304
+ artifact_id: str = Field(description="Artifact that was validated")
305
+ artifact_revision: int = Field(description="Revision that was validated")
306
+ issues: list[ValidationIssue] = Field(description="All validation issues found")
307
+
308
+ @property
309
+ def has_errors(self) -> bool:
310
+ """Return True if any issue has ERROR level."""
311
+ return any(i.level == ValidationLevel.ERROR for i in self.issues)
312
+
313
+
314
+ class ExportResult(BaseModel):
315
+ success: bool = Field(description="True only if the file was written and checks passed")
316
+ artifact_id: str = Field(description="Artifact that was exported")
317
+ artifact_revision: int = Field(description="Revision that was exported")
318
+ pptx_path: Optional[str] = Field(None, description="Written file path on success")
319
+ slide_count: int = Field(0, description="Number of slides in the written file")
320
+ issues: list[ValidationIssue] = Field(
321
+ default_factory=list, description="Problems that blocked the export"
322
+ )
323
+
324
+
325
+ class TaskStatus(str, Enum):
326
+ QUEUED = "queued"
327
+ RUNNING = "running"
328
+ SUCCEEDED = "succeeded"
329
+ FAILED = "failed"
330
+
331
+
332
+ class TaskRecord(BaseModel):
333
+ task_id: str = Field(description="Unique task identifier")
334
+ project_id: str = Field(description="Project the task belongs to")
335
+ kind: str = Field(description="Task kind: 'outline' or 'generate'")
336
+ status: TaskStatus = Field(TaskStatus.QUEUED, description="Current task status")
337
+ step: str = Field("", description="Human-readable label of the current real step")
338
+ error: Optional[str] = Field(None, description="Failure reason, if failed")
339
+ result: dict = Field(
340
+ default_factory=dict,
341
+ description="References to saved intermediate/final products",
342
+ )
343
+ created_at: str = Field(description="ISO timestamp of submission")
344
+ updated_at: str = Field(description="ISO timestamp of last status change")
345
+
346
+
347
+ # ── Tool input / output schemas ──────────────────────────────────────────────
348
+
349
+
350
+ class ReadMaterialsInput(BaseModel):
351
+ project_id: str = Field(description="Project to read assets from")
352
+ asset_ids: Optional[list[str]] = Field(
353
+ None, description="Specific asset IDs to read; None means read all"
354
+ )
355
+
356
+
357
+ class MaterialContent(BaseModel):
358
+ asset_id: str = Field(description="Asset identifier (filename without extension)")
359
+ asset_type: AssetType = Field(description="Type of asset")
360
+ content: str = Field(
361
+ description=(
362
+ "Text content for markdown; "
363
+ "description stub for images (not fabricated analysis)"
364
+ )
365
+ )
366
+
367
+
368
+ class ReadMaterialsOutput(BaseModel):
369
+ project_id: str = Field(description="Project ID")
370
+ materials: list[MaterialContent] = Field(description="All loaded material contents")
371
+ source_fragments: list[SourceFragment] = Field(
372
+ description="All derived source fragments"
373
+ )
374
+
375
+
376
+ class ProposeOutlineInput(BaseModel):
377
+ project_id: str = Field(description="Target project")
378
+ material_snapshot_id: str = Field(
379
+ description="Identifier for the material snapshot used"
380
+ )
381
+
382
+
383
+ class GenerateSlidesInput(BaseModel):
384
+ project_id: str = Field(description="Target project")
385
+ approved_outline_version: str = Field(
386
+ description="Version of the confirmed outline"
387
+ )
388
+ template_id: str = Field("default", description="Slide template to apply")
389
+ idempotency_key: str = Field(
390
+ description="Unique key; identical keys return the cached result"
391
+ )
392
+
393
+
394
+ class PatchSlideInput(BaseModel):
395
+ artifact_id: str = Field(description="Artifact to patch")
396
+ slide_id: str = Field(description="Slide to patch")
397
+ expected_revision: int = Field(
398
+ description="Current revision; must match or the patch is rejected"
399
+ )
400
+ operation_type: str = Field(
401
+ description="One of: replace_text, replace_existing_image"
402
+ )
403
+ element_id: str = Field(description="Element to modify")
404
+ new_content: str = Field(description="Replacement content")
405
+ idempotency_key: str = Field(
406
+ description="Unique key; identical keys return the cached result"
407
+ )