braidio 0.0.99__tar.gz → 0.0.100__tar.gz

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 (151) hide show
  1. {braidio-0.0.99 → braidio-0.0.100}/PKG-INFO +1 -1
  2. {braidio-0.0.99 → braidio-0.0.100}/braidio/cost.py +111 -59
  3. {braidio-0.0.99 → braidio-0.0.100}/braidio/mcp/tools.py +36 -38
  4. {braidio-0.0.99 → braidio-0.0.100}/braidio/rights.py +7 -1
  5. {braidio-0.0.99 → braidio-0.0.100}/pyproject.toml +1 -1
  6. {braidio-0.0.99 → braidio-0.0.100}/tests/test_cost.py +65 -0
  7. {braidio-0.0.99 → braidio-0.0.100}/tests/test_mcp.py +140 -0
  8. {braidio-0.0.99 → braidio-0.0.100}/.editorconfig +0 -0
  9. {braidio-0.0.99 → braidio-0.0.100}/.gitattributes +0 -0
  10. {braidio-0.0.99 → braidio-0.0.100}/.gitignore +0 -0
  11. {braidio-0.0.99 → braidio-0.0.100}/LICENSE +0 -0
  12. {braidio-0.0.99 → braidio-0.0.100}/README.md +0 -0
  13. {braidio-0.0.99 → braidio-0.0.100}/braidio/__init__.py +0 -0
  14. {braidio-0.0.99 → braidio-0.0.100}/braidio/_paths.py +0 -0
  15. {braidio-0.0.99 → braidio-0.0.100}/braidio/bodies/__init__.py +0 -0
  16. {braidio-0.0.99 → braidio-0.0.100}/braidio/bodies/_domain.py +0 -0
  17. {braidio-0.0.99 → braidio-0.0.100}/braidio/bodies/_render_nodes.py +0 -0
  18. {braidio-0.0.99 → braidio-0.0.100}/braidio/bodies/_tiers.py +0 -0
  19. {braidio-0.0.99 → braidio-0.0.100}/braidio/bodies/_video.py +0 -0
  20. {braidio-0.0.99 → braidio-0.0.100}/braidio/captions.py +0 -0
  21. {braidio-0.0.99 → braidio-0.0.100}/braidio/compose.py +0 -0
  22. {braidio-0.0.99 → braidio-0.0.100}/braidio/conversation.py +0 -0
  23. {braidio-0.0.99 → braidio-0.0.100}/braidio/data/skills/braidio/SKILL.md +0 -0
  24. {braidio-0.0.99 → braidio-0.0.100}/braidio/data/skills/braidio-commentary-video/SKILL.md +0 -0
  25. {braidio-0.0.99 → braidio-0.0.100}/braidio/defaults.py +0 -0
  26. {braidio-0.0.99 → braidio-0.0.100}/braidio/delivery.py +0 -0
  27. {braidio-0.0.99 → braidio-0.0.100}/braidio/downloads.py +0 -0
  28. {braidio-0.0.99 → braidio-0.0.100}/braidio/formats.py +0 -0
  29. {braidio-0.0.99 → braidio-0.0.100}/braidio/genre.py +0 -0
  30. {braidio-0.0.99 → braidio-0.0.100}/braidio/importing/__init__.py +0 -0
  31. {braidio-0.0.99 → braidio-0.0.100}/braidio/importing/__main__.py +0 -0
  32. {braidio-0.0.99 → braidio-0.0.100}/braidio/importing/_catalog.py +0 -0
  33. {braidio-0.0.99 → braidio-0.0.100}/braidio/importing/_manifest.py +0 -0
  34. {braidio-0.0.99 → braidio-0.0.100}/braidio/importing/_writer.py +0 -0
  35. {braidio-0.0.99 → braidio-0.0.100}/braidio/kinds.py +0 -0
  36. {braidio-0.0.99 → braidio-0.0.100}/braidio/leveling.py +0 -0
  37. {braidio-0.0.99 → braidio-0.0.100}/braidio/markdown_script.py +0 -0
  38. {braidio-0.0.99 → braidio-0.0.100}/braidio/mcp/__init__.py +0 -0
  39. {braidio-0.0.99 → braidio-0.0.100}/braidio/mcp/_docs.py +0 -0
  40. {braidio-0.0.99 → braidio-0.0.100}/braidio/mcp/_guide.py +0 -0
  41. {braidio-0.0.99 → braidio-0.0.100}/braidio/mcp/_helpers.py +0 -0
  42. {braidio-0.0.99 → braidio-0.0.100}/braidio/mcp/_media.py +0 -0
  43. {braidio-0.0.99 → braidio-0.0.100}/braidio/mcp/credentials.py +0 -0
  44. {braidio-0.0.99 → braidio-0.0.100}/braidio/mcp/metering.py +0 -0
  45. {braidio-0.0.99 → braidio-0.0.100}/braidio/mcp/workspace.py +0 -0
  46. {braidio-0.0.99 → braidio-0.0.100}/braidio/multivoice.py +0 -0
  47. {braidio-0.0.99 → braidio-0.0.100}/braidio/music.py +0 -0
  48. {braidio-0.0.99 → braidio-0.0.100}/braidio/pacing.py +0 -0
  49. {braidio-0.0.99 → braidio-0.0.100}/braidio/project.py +0 -0
  50. {braidio-0.0.99 → braidio-0.0.100}/braidio/provenance.py +0 -0
  51. {braidio-0.0.99 → braidio-0.0.100}/braidio/relevance.py +0 -0
  52. {braidio-0.0.99 → braidio-0.0.100}/braidio/render.py +0 -0
  53. {braidio-0.0.99 → braidio-0.0.100}/braidio/script.py +0 -0
  54. {braidio-0.0.99 → braidio-0.0.100}/braidio/sources.py +0 -0
  55. {braidio-0.0.99 → braidio-0.0.100}/braidio/structure.py +0 -0
  56. {braidio-0.0.99 → braidio-0.0.100}/braidio/style.py +0 -0
  57. {braidio-0.0.99 → braidio-0.0.100}/braidio/textprep.py +0 -0
  58. {braidio-0.0.99 → braidio-0.0.100}/braidio/timeline.py +0 -0
  59. {braidio-0.0.99 → braidio-0.0.100}/braidio/transforms/__init__.py +0 -0
  60. {braidio-0.0.99 → braidio-0.0.100}/braidio/transforms/_asset_refs.py +0 -0
  61. {braidio-0.0.99 → braidio-0.0.100}/braidio/transforms/_common.py +0 -0
  62. {braidio-0.0.99 → braidio-0.0.100}/braidio/transforms/_dialogue.py +0 -0
  63. {braidio-0.0.99 → braidio-0.0.100}/braidio/transforms/_episode.py +0 -0
  64. {braidio-0.0.99 → braidio-0.0.100}/braidio/transforms/_ingest.py +0 -0
  65. {braidio-0.0.99 → braidio-0.0.100}/braidio/transforms/_narration.py +0 -0
  66. {braidio-0.0.99 → braidio-0.0.100}/braidio/transforms/_segment.py +0 -0
  67. {braidio-0.0.99 → braidio-0.0.100}/braidio/transforms/_takes.py +0 -0
  68. {braidio-0.0.99 → braidio-0.0.100}/braidio/transforms/_video_cut.py +0 -0
  69. {braidio-0.0.99 → braidio-0.0.100}/braidio/transforms/_video_panels.py +0 -0
  70. {braidio-0.0.99 → braidio-0.0.100}/braidio/transforms/_voice.py +0 -0
  71. {braidio-0.0.99 → braidio-0.0.100}/braidio/tts.py +0 -0
  72. {braidio-0.0.99 → braidio-0.0.100}/braidio/video.py +0 -0
  73. {braidio-0.0.99 → braidio-0.0.100}/braidio/voice_library.py +0 -0
  74. {braidio-0.0.99 → braidio-0.0.100}/braidio/weave.py +0 -0
  75. {braidio-0.0.99 → braidio-0.0.100}/braidio/weave_config.py +0 -0
  76. {braidio-0.0.99 → braidio-0.0.100}/conftest.py +0 -0
  77. {braidio-0.0.99 → braidio-0.0.100}/misc/docs/Extraction and nw-App Design.md +0 -0
  78. {braidio-0.0.99 → braidio-0.0.100}/misc/docs/research/commentary-formats-and-styles.md +0 -0
  79. {braidio-0.0.99 → braidio-0.0.100}/misc/docs/research/conversational-vs-narration-tts.md +0 -0
  80. {braidio-0.0.99 → braidio-0.0.100}/misc/docs/research/notebooklm-and-conversational-pacing.md +0 -0
  81. {braidio-0.0.99 → braidio-0.0.100}/misc/docs/style/README.md +0 -0
  82. {braidio-0.0.99 → braidio-0.0.100}/misc/docs/style/anti-platitude-checklist.md +0 -0
  83. {braidio-0.0.99 → braidio-0.0.100}/misc/docs/style/commentary-voice-guide.md +0 -0
  84. {braidio-0.0.99 → braidio-0.0.100}/misc/docs/style/voices/_style-groups.md +0 -0
  85. {braidio-0.0.99 → braidio-0.0.100}/misc/docs/style/voices/amanda-dobbins.md +0 -0
  86. {braidio-0.0.99 → braidio-0.0.100}/misc/docs/style/voices/david-sims.md +0 -0
  87. {braidio-0.0.99 → braidio-0.0.100}/misc/docs/style/voices/griffin-newman.md +0 -0
  88. {braidio-0.0.99 → braidio-0.0.100}/misc/docs/style/voices/helen-molesworth.md +0 -0
  89. {braidio-0.0.99 → braidio-0.0.100}/misc/docs/style/voices/hrishikesh-hirway.md +0 -0
  90. {braidio-0.0.99 → braidio-0.0.100}/misc/docs/style/voices/jason-mantzoukas.md +0 -0
  91. {braidio-0.0.99 → braidio-0.0.100}/misc/docs/style/voices/john-mcwhorter.md +0 -0
  92. {braidio-0.0.99 → braidio-0.0.100}/misc/docs/style/voices/jon-caramanica.md +0 -0
  93. {braidio-0.0.99 → braidio-0.0.100}/misc/docs/style/voices/june-diane-raphael.md +0 -0
  94. {braidio-0.0.99 → braidio-0.0.100}/misc/docs/style/voices/karina-longworth.md +0 -0
  95. {braidio-0.0.99 → braidio-0.0.100}/misc/docs/style/voices/katy-hessel.md +0 -0
  96. {braidio-0.0.99 → braidio-0.0.100}/misc/docs/style/voices/louis-theroux.md +0 -0
  97. {braidio-0.0.99 → braidio-0.0.100}/misc/docs/style/voices/mallory-rubin.md +0 -0
  98. {braidio-0.0.99 → braidio-0.0.100}/misc/docs/style/voices/melvyn-bragg.md +0 -0
  99. {braidio-0.0.99 → braidio-0.0.100}/misc/docs/style/voices/michael-barbaro.md +0 -0
  100. {braidio-0.0.99 → braidio-0.0.100}/misc/docs/style/voices/nate-sloan-charlie-harding.md +0 -0
  101. {braidio-0.0.99 → braidio-0.0.100}/misc/docs/style/voices/paul-scheer.md +0 -0
  102. {braidio-0.0.99 → braidio-0.0.100}/misc/docs/style/voices/sean-fennessey.md +0 -0
  103. {braidio-0.0.99 → braidio-0.0.100}/misc/docs/style/voices/talk-art.md +0 -0
  104. {braidio-0.0.99 → braidio-0.0.100}/misc/docs/style/voices/yasi-salek.md +0 -0
  105. {braidio-0.0.99 → braidio-0.0.100}/misc/docs/youtube_ingest_credentials.md +0 -0
  106. {braidio-0.0.99 → braidio-0.0.100}/tests/_audio.py +0 -0
  107. {braidio-0.0.99 → braidio-0.0.100}/tests/test_body_schema_stability.py +0 -0
  108. {braidio-0.0.99 → braidio-0.0.100}/tests/test_conversation.py +0 -0
  109. {braidio-0.0.99 → braidio-0.0.100}/tests/test_credits_card.py +0 -0
  110. {braidio-0.0.99 → braidio-0.0.100}/tests/test_defaults.py +0 -0
  111. {braidio-0.0.99 → braidio-0.0.100}/tests/test_delivery.py +0 -0
  112. {braidio-0.0.99 → braidio-0.0.100}/tests/test_downloads.py +0 -0
  113. {braidio-0.0.99 → braidio-0.0.100}/tests/test_expressiveness.py +0 -0
  114. {braidio-0.0.99 → braidio-0.0.100}/tests/test_formats.py +0 -0
  115. {braidio-0.0.99 → braidio-0.0.100}/tests/test_genre_placement.py +0 -0
  116. {braidio-0.0.99 → braidio-0.0.100}/tests/test_graph_speak.py +0 -0
  117. {braidio-0.0.99 → braidio-0.0.100}/tests/test_importing.py +0 -0
  118. {braidio-0.0.99 → braidio-0.0.100}/tests/test_leveling.py +0 -0
  119. {braidio-0.0.99 → braidio-0.0.100}/tests/test_markdown_script.py +0 -0
  120. {braidio-0.0.99 → braidio-0.0.100}/tests/test_mcp_caller_key.py +0 -0
  121. {braidio-0.0.99 → braidio-0.0.100}/tests/test_media_auth.py +0 -0
  122. {braidio-0.0.99 → braidio-0.0.100}/tests/test_multivoice.py +0 -0
  123. {braidio-0.0.99 → braidio-0.0.100}/tests/test_music.py +0 -0
  124. {braidio-0.0.99 → braidio-0.0.100}/tests/test_namespaced_source.py +0 -0
  125. {braidio-0.0.99 → braidio-0.0.100}/tests/test_nw_app.py +0 -0
  126. {braidio-0.0.99 → braidio-0.0.100}/tests/test_pacing.py +0 -0
  127. {braidio-0.0.99 → braidio-0.0.100}/tests/test_packaging.py +0 -0
  128. {braidio-0.0.99 → braidio-0.0.100}/tests/test_render_settings.py +0 -0
  129. {braidio-0.0.99 → braidio-0.0.100}/tests/test_script.py +0 -0
  130. {braidio-0.0.99 → braidio-0.0.100}/tests/test_sources.py +0 -0
  131. {braidio-0.0.99 → braidio-0.0.100}/tests/test_speak_seam.py +0 -0
  132. {braidio-0.0.99 → braidio-0.0.100}/tests/test_structure.py +0 -0
  133. {braidio-0.0.99 → braidio-0.0.100}/tests/test_textprep_style.py +0 -0
  134. {braidio-0.0.99 → braidio-0.0.100}/tests/test_timeline.py +0 -0
  135. {braidio-0.0.99 → braidio-0.0.100}/tests/test_transforms.py +0 -0
  136. {braidio-0.0.99 → braidio-0.0.100}/tests/test_transforms_dialogue.py +0 -0
  137. {braidio-0.0.99 → braidio-0.0.100}/tests/test_transforms_episode_members.py +0 -0
  138. {braidio-0.0.99 → braidio-0.0.100}/tests/test_transforms_rights.py +0 -0
  139. {braidio-0.0.99 → braidio-0.0.100}/tests/test_transforms_secrets.py +0 -0
  140. {braidio-0.0.99 → braidio-0.0.100}/tests/test_transforms_structure.py +0 -0
  141. {braidio-0.0.99 → braidio-0.0.100}/tests/test_tts_api_key.py +0 -0
  142. {braidio-0.0.99 → braidio-0.0.100}/tests/test_turn_overlap.py +0 -0
  143. {braidio-0.0.99 → braidio-0.0.100}/tests/test_video.py +0 -0
  144. {braidio-0.0.99 → braidio-0.0.100}/tests/test_video_bodies.py +0 -0
  145. {braidio-0.0.99 → braidio-0.0.100}/tests/test_video_footage.py +0 -0
  146. {braidio-0.0.99 → braidio-0.0.100}/tests/test_video_transforms.py +0 -0
  147. {braidio-0.0.99 → braidio-0.0.100}/tests/test_voice_library.py +0 -0
  148. {braidio-0.0.99 → braidio-0.0.100}/tests/test_weave.py +0 -0
  149. {braidio-0.0.99 → braidio-0.0.100}/tests/test_weave_config.py +0 -0
  150. {braidio-0.0.99 → braidio-0.0.100}/tests/test_weave_master.py +0 -0
  151. {braidio-0.0.99 → braidio-0.0.100}/tests/test_wire_descriptions.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: braidio
3
- Version: 0.0.99
3
+ Version: 0.0.100
4
4
  Summary: Weave narration with extracted media segments into audiovisual productions
5
5
  Project-URL: Homepage, https://github.com/thorwhalen/braidio
6
6
  Project-URL: Repository, https://github.com/thorwhalen/braidio
@@ -30,9 +30,10 @@ from __future__ import annotations
30
30
  import math
31
31
  import os
32
32
  from dataclasses import dataclass
33
- from typing import Optional, Union
33
+ from typing import Iterable, Optional, Union
34
34
 
35
- from braidio.script import Script, Narration, Dialogue
35
+ from braidio.rights import DEFAULT_PROFILE, Profile, RenderPlan, plan_production
36
+ from braidio.script import Script, Dialogue
36
37
  from braidio.tts import DEFAULT_MODEL_ID, DIALOGUE_MODEL_ID
37
38
 
38
39
  #: Env var overriding the USD-per-1000-characters rate (global default for models
@@ -172,6 +173,24 @@ class CostRollup:
172
173
  unpriced: bool
173
174
  lines: tuple[CostLine, ...] = ()
174
175
 
176
+ @classmethod
177
+ def from_lines(cls, lines: Iterable[CostLine]) -> CostRollup:
178
+ """The rollup of ``lines``: exact characters, honest dollars.
179
+
180
+ ``usd`` sums the priced lines; billable text with no rate makes it a
181
+ lower bound (``unpriced``), and only when nothing at all is priced does
182
+ it become ``None``. No billable text is a genuine ``0.0``.
183
+
184
+ >>> CostRollup.from_lines([]).usd
185
+ 0.0
186
+ """
187
+ lines = tuple(lines)
188
+ characters = sum(ln.characters for ln in lines)
189
+ priced = [ln.usd for ln in lines if ln.usd is not None]
190
+ unpriced = any(ln.characters > 0 and ln.usd is None for ln in lines)
191
+ usd = round(sum(priced), 6) if priced else (None if unpriced else 0.0)
192
+ return cls(characters=characters, usd=usd, unpriced=unpriced, lines=lines)
193
+
175
194
  @property
176
195
  def summary(self) -> str:
177
196
  """One-line human summary (handy for a CLI/MCP preview)."""
@@ -180,49 +199,76 @@ class CostRollup:
180
199
  return f"{self.characters:,} chars → {dollars}{tail}"
181
200
 
182
201
 
183
- def _script_lines(script: Script, *, model_id: str) -> list[CostLine]:
184
- """Billable lines of ``script``: narration + dialogue beats (segments are free).
185
-
186
- Narration is priced at ``model_id``. A dialogue beat is always
187
- :data:`~braidio.tts.DIALOGUE_MODEL_ID`, the one model Text-to-Dialogue runs on.
188
-
189
- Estimates the *default* (personal) cut. Published-cut costing (rights-safe
190
- rewrites + synthesized clip substitutes) must reuse :func:`braidio.plan_production`
191
- rather than re-deriving the rights rules here — a follow-up.
192
- """
202
+ def _plan_lines(
203
+ plan: RenderPlan,
204
+ *,
205
+ model_id: Optional[str] = None,
206
+ dialogue_model_id: Optional[str] = None,
207
+ script: Optional[Script] = None,
208
+ ) -> list[CostLine]:
209
+ """The billable :class:`CostLine`\\ s of ``plan`` — :func:`price_plan`'s body."""
210
+ model_id = model_id or DEFAULT_MODEL_ID
211
+ dialogue_model_id = dialogue_model_id or DIALOGUE_MODEL_ID
193
212
  lines: list[CostLine] = []
194
- for i, beat in enumerate(script.beats):
195
- if isinstance(beat, Narration):
196
- lines.append(
197
- CostLine(
198
- label=f"beat[{i}] narration",
199
- kind="narration",
200
- characters=billable_chars(beat.text),
201
- usd=tts_cost_usd(beat.text, model_id=model_id),
202
- model_id=model_id,
203
- )
213
+ for beat in plan.beats:
214
+ if beat.kind == "narration":
215
+ text, model, kind = beat.content, model_id, "narration"
216
+ elif beat.kind == "dialogue":
217
+ text, model, kind = (
218
+ "".join(t for _role, t in (beat.turns or ())),
219
+ dialogue_model_id,
220
+ "dialogue",
204
221
  )
205
- elif isinstance(beat, Dialogue):
206
- text = "".join(t for _role, t in beat.turns)
207
- label = f"beat[{i}] dialogue"
208
- if beat.label:
209
- label += f" ({beat.label})"
210
- lines.append(
211
- CostLine(
212
- label=label,
213
- kind="dialogue",
214
- characters=billable_chars(text),
215
- usd=tts_cost_usd(text, model_id=DIALOGUE_MODEL_ID),
216
- model_id=DIALOGUE_MODEL_ID,
217
- )
222
+ else:
223
+ continue # a clip is extracted media, a break is structure: free
224
+ label = f"beat[{beat.from_index}] {kind}"
225
+ source = script.beats[beat.from_index] if script is not None else None
226
+ if isinstance(source, Dialogue) and source.label:
227
+ label += f" ({source.label})"
228
+ lines.append(
229
+ CostLine(
230
+ label=label,
231
+ kind=kind,
232
+ characters=billable_chars(text),
233
+ usd=tts_cost_usd(text, model_id=model),
234
+ model_id=model,
218
235
  )
219
- # a SegmentBeat is extracted media and a SceneBreak is structure (a
220
- # sting or silence, nothing synthesized) = free; neither contributes a line.
236
+ )
221
237
  return lines
222
238
 
223
239
 
240
+ def price_plan(
241
+ plan: RenderPlan,
242
+ *,
243
+ model_id: Optional[str] = None,
244
+ dialogue_model_id: Optional[str] = None,
245
+ script: Optional[Script] = None,
246
+ ) -> CostRollup:
247
+ """The estimated spend of a :class:`~braidio.rights.RenderPlan` — the one pricer.
248
+
249
+ :func:`estimate_cost` and every render's spend report are this function
250
+ over :func:`braidio.plan_production`'s output, each with the models it
251
+ renders with. Narration is priced at ``model_id`` and dialogue at
252
+ ``dialogue_model_id`` (``None`` = :data:`~braidio.tts.DEFAULT_MODEL_ID` /
253
+ ``DIALOGUE_MODEL_ID``, resolved at call time); clips and scene breaks are
254
+ local work, free, and contribute no line. Pricing the plan rather than the
255
+ raw script is what makes a ``published`` cut honest: dropped clips cost
256
+ nothing and synthesized substitutes are billed. ``script`` (the one
257
+ planned) only lends a dialogue line its label.
258
+ """
259
+ return CostRollup.from_lines(
260
+ _plan_lines(
261
+ plan, model_id=model_id, dialogue_model_id=dialogue_model_id, script=script
262
+ )
263
+ )
264
+
265
+
224
266
  def estimate_cost(
225
- source: Union[Script, str], *, model_id: Optional[str] = None
267
+ source: Union[Script, str],
268
+ *,
269
+ model_id: Optional[str] = None,
270
+ dialogue_model_id: Optional[str] = None,
271
+ profile: Union[Profile, str, None] = None,
226
272
  ) -> CostRollup:
227
273
  """Estimate ElevenLabs spend for a :class:`braidio.Script` or a raw string.
228
274
 
@@ -231,10 +277,18 @@ def estimate_cost(
231
277
  bound when some text is unpriced; see :func:`usd_per_1k_chars`).
232
278
 
233
279
  ``model_id`` is the model the narration will be voiced with (default
234
- :data:`~braidio.tts.DEFAULT_MODEL_ID`); its rate resolves like any other
280
+ :data:`~braidio.tts.DEFAULT_MODEL_ID`) and ``dialogue_model_id`` the one
281
+ its dialogue beats are (default :data:`~braidio.tts.DIALOGUE_MODEL_ID`,
282
+ what the default cast uses); each rate resolves like any other
235
283
  (:func:`usd_per_1k_chars`), so a model with no confirmed rate of its own
236
- gets the general rate, never another model's. Dialogue beats are priced
237
- at :data:`~braidio.tts.DIALOGUE_MODEL_ID` whatever ``model_id`` says.
284
+ gets the general rate, never another model's. A script is priced through
285
+ :func:`braidio.plan_production` under ``profile`` (a :class:`~braidio.Profile`
286
+ or its value, e.g. ``"published"``; default :data:`~braidio.rights.DEFAULT_PROFILE`,
287
+ which plays every beat), so the estimate is of what renders: under
288
+ ``"published"`` a dropped clip costs nothing and a ``published_text`` or
289
+ ``published_substitute`` is billed in its beat's place. A beat of a type
290
+ the planner does not know raises ``TypeError`` (from ``plan_production``)
291
+ rather than being skipped, so an estimate is never silently short.
238
292
 
239
293
  >>> from braidio import Script, Narration, SegmentBeat
240
294
  >>> s = Script(title="x", id_slug="01", beats=[
@@ -244,22 +298,20 @@ def estimate_cost(
244
298
  """
245
299
  model_id = model_id or DEFAULT_MODEL_ID
246
300
  if isinstance(source, str):
247
- lines = [
248
- CostLine(
249
- label="text",
250
- kind="narration",
251
- characters=billable_chars(source),
252
- usd=tts_cost_usd(source, model_id=model_id),
253
- model_id=model_id,
254
- )
255
- ]
256
- else:
257
- lines = _script_lines(source, model_id=model_id)
258
-
259
- characters = sum(ln.characters for ln in lines)
260
- priced = [ln.usd for ln in lines if ln.usd is not None]
261
- unpriced = any(ln.characters > 0 and ln.usd is None for ln in lines)
262
- usd = round(sum(priced), 6) if priced else (None if unpriced else 0.0)
263
- return CostRollup(
264
- characters=characters, usd=usd, unpriced=unpriced, lines=tuple(lines)
301
+ return CostRollup.from_lines(
302
+ [
303
+ CostLine(
304
+ label="text",
305
+ kind="narration",
306
+ characters=billable_chars(source),
307
+ usd=tts_cost_usd(source, model_id=model_id),
308
+ model_id=model_id,
309
+ )
310
+ ]
311
+ )
312
+ # a str profile must become the enum: plan_production compares by identity
313
+ # (``is Profile.PUBLISHED``), so "published" would plan a half-published cut
314
+ plan = plan_production(source, DEFAULT_PROFILE if profile is None else profile)
315
+ return price_plan(
316
+ plan, model_id=model_id, dialogue_model_id=dialogue_model_id, script=source
265
317
  )
@@ -32,7 +32,6 @@ from braidio.rights import DEFAULT_PROFILE
32
32
  from braidio.mcp.credentials import caller_elevenlabs_key
33
33
  from braidio.mcp.metering import current_email
34
34
  from braidio.mcp.workspace import Workspace
35
- from braidio.tts import DEFAULT_MODEL_ID
36
35
 
37
36
 
38
37
  def _workspace() -> Workspace:
@@ -665,45 +664,29 @@ def _check_source(scr, source) -> None:
665
664
  )
666
665
 
667
666
 
668
- def _render_cost(scr, profile: str, *, cast=None) -> dict:
667
+ def _render_cost(scr, profile: str, *, model_id: str, cast=None) -> dict:
669
668
  """Estimate the spend of the beats that WILL render under ``profile``.
670
669
 
671
- Costs :func:`braidio.plan_production`'s output (the SSOT for the rights
672
- projection), so under ``"published"`` dropped clips cost nothing and synthesized
673
- substitutes are billed — unlike costing the raw script. The figure is a rate
674
- estimate (``cost_basis="estimate"``; see :mod:`braidio.cost` + braidio#8).
675
-
676
- ``cast`` is the :class:`~braidio.conversation.ConversationCast` the dialogue
677
- beats render under (``None`` = the default cast, as on every render entry
678
- point): a dialogue beat is priced at *its* model, the same one the render —
679
- fast path and ``dialogue_render.tts`` alike — actually submits, so the
680
- estimate cannot drift from the spend when a format casts another model.
670
+ :func:`braidio.cost.price_plan` over :func:`braidio.plan_production`'s output
671
+ (the SSOT for the rights projection, so under ``"published"`` dropped clips
672
+ cost nothing and synthesized substitutes are billed), at the models the
673
+ render actually submits: ``model_id`` for narration (the delivery's, or the
674
+ graph's weave-config), the ``cast``'s for dialogue (``None`` = the default
675
+ cast, as on every render entry point). The figure is a rate estimate
676
+ (``cost_basis="estimate"``; see :mod:`braidio.cost` + braidio#8).
681
677
  """
682
678
  from braidio.conversation import DEFAULT_CAST
679
+ from braidio.cost import price_plan
683
680
 
684
- dialogue_model = (cast if cast is not None else DEFAULT_CAST).model_id
685
- plan = braidio.plan_production(scr, _profile(profile))
686
- chars = 0
687
- priced: list[float] = []
688
- unpriced = False
689
- for b in plan.beats:
690
- if b.kind == "narration":
691
- text, model = b.content, DEFAULT_MODEL_ID
692
- elif b.kind == "dialogue":
693
- text, model = "".join(t for _r, t in (b.turns or ())), dialogue_model
694
- else:
695
- continue # clip = free (local ffmpeg)
696
- chars += braidio.billable_chars(text)
697
- cost = braidio.tts_cost_usd(text, model_id=model)
698
- if cost is None and text:
699
- unpriced = True
700
- elif cost is not None:
701
- priced.append(cost)
702
- usd = round(sum(priced), 6) if priced else (None if unpriced else 0.0)
681
+ roll = price_plan(
682
+ braidio.plan_production(scr, _profile(profile)),
683
+ model_id=model_id,
684
+ dialogue_model_id=(cast if cast is not None else DEFAULT_CAST).model_id,
685
+ )
703
686
  return {
704
- "cost_usd": usd,
705
- "characters": chars,
706
- "unpriced": unpriced,
687
+ "cost_usd": roll.usd,
688
+ "characters": roll.characters,
689
+ "unpriced": roll.unpriced,
707
690
  "cost_basis": "estimate",
708
691
  }
709
692
 
@@ -887,11 +870,12 @@ def render_production(
887
870
  out = ws.render_path(stem)
888
871
  bed_path = _resolve_asset(ws, bed_asset_id)
889
872
  sting_path = _resolve_asset(ws, sting_asset_id)
873
+ voiced_with = _delivery(delivery)
890
874
  braidio.render_production(
891
875
  scr,
892
876
  source=src,
893
877
  profile=_profile(profile),
894
- delivery=_delivery(delivery),
878
+ delivery=voiced_with,
895
879
  api_key=caller_elevenlabs_key(),
896
880
  out_path=out,
897
881
  tts_dir=_work_dir(ws, stem) + "/tts",
@@ -900,7 +884,10 @@ def render_production(
900
884
  music_bed=MusicBed(asset_path=bed_path) if bed_path else None,
901
885
  structure=MusicStructure(sting=Sting(sting_path)) if sting_path else None,
902
886
  )
903
- return {**_retrieval(out), **_render_cost(scr, profile)}
887
+ return {
888
+ **_retrieval(out),
889
+ **_render_cost(scr, profile, model_id=voiced_with.model_id),
890
+ }
904
891
 
905
892
 
906
893
  def render_format(
@@ -953,7 +940,9 @@ def render_format(
953
940
  )
954
941
  return {
955
942
  **_retrieval(out),
956
- **_render_cost(scr, profile, cast=fmt.cast),
943
+ **_render_cost(
944
+ scr, profile, model_id=fmt.narration_delivery.model_id, cast=fmt.cast
945
+ ),
957
946
  "sting_applied": application["sting_applied"],
958
947
  "sting_ignored_reason": application["sting_ignored_reason"],
959
948
  }
@@ -1006,7 +995,16 @@ def weave_project(
1006
995
  "episode": to_json(body),
1007
996
  "url": body.get("url"),
1008
997
  **_episode_retrieval(project_id, str(episode.id)),
1009
- **_render_cost(scr, profile, cast=fmt.cast if fmt is not None else None),
998
+ **_render_cost(
999
+ scr,
1000
+ profile,
1001
+ # what the graph voiced the narration with: the project's config
1002
+ # (None = ingest's default WeaveConfig, as ingest itself resolves it)
1003
+ model_id=(
1004
+ braidio.transforms.resolve_config(proj, fmt) or braidio.WeaveConfig()
1005
+ ).model_id,
1006
+ cast=fmt.cast if fmt is not None else None,
1007
+ ),
1010
1008
  "sting_applied": sting_applied,
1011
1009
  "sting_ignored_reason": sting_ignored_reason,
1012
1010
  }
@@ -149,7 +149,13 @@ def plan_production(
149
149
  *,
150
150
  publishable_clip_rights: frozenset[str] = PUBLISHABLE_CLIP_RIGHTS,
151
151
  ) -> RenderPlan:
152
- """Filter ``script`` into the beats renderable under ``profile``."""
152
+ """Filter ``script`` into the beats renderable under ``profile``.
153
+
154
+ ``profile`` may be its value (``"published"``): it is coerced here, the one
155
+ door every render and estimate plans through, because the rules below
156
+ compare by identity and a string would plan half a published cut.
157
+ """
158
+ profile = Profile(profile)
153
159
  plan = RenderPlan(profile=profile)
154
160
  for i, beat in enumerate(script.beats):
155
161
  if isinstance(beat, SegmentBeat):
@@ -6,7 +6,7 @@ build-backend = "hatchling.build"
6
6
 
7
7
  [project]
8
8
  name = "braidio"
9
- version = "0.0.99"
9
+ version = "0.0.100"
10
10
  description = "Weave narration with extracted media segments into audiovisual productions"
11
11
  readme = "README.md"
12
12
  requires-python = ">=3.10"
@@ -193,3 +193,68 @@ def test_estimate_summary_is_human_readable():
193
193
  est = estimate_cost("a" * 1000)
194
194
  assert "1,000 chars" in est.summary
195
195
  assert "$" in est.summary
196
+
197
+
198
+ # --- the estimate is of what renders: profile + the models voiced with (#155) --
199
+
200
+
201
+ @pytest.mark.parametrize("published", ["published", "PUBLISHED_ENUM"])
202
+ def test_estimate_prices_the_published_cut_not_the_raw_script(published):
203
+ # A published estimate drops the unpublishable clip with no substitute,
204
+ # bills the substitute in place of the one that has one, and bills a
205
+ # narration's published_text instead of its text. The profile given as
206
+ # its string value must plan the SAME cut as the enum: plan_production
207
+ # compares by identity, so an uncoerced "published" would drop the clips
208
+ # yet keep the original narration (a half-published plan).
209
+ from braidio import Profile
210
+
211
+ profile = Profile.PUBLISHED if published == "PUBLISHED_ENUM" else published
212
+ script = Script(
213
+ title="t",
214
+ id_slug="01",
215
+ beats=[
216
+ Narration(text="n" * 100, published_text="p" * 10),
217
+ SegmentBeat(reference="clip:dropped"),
218
+ SegmentBeat(reference="clip:swapped", published_substitute="s" * 7),
219
+ ],
220
+ )
221
+ assert estimate_cost(script).characters == 100 # personal: clips are free
222
+ est = estimate_cost(script, profile=profile)
223
+ assert est.characters == 10 + 7
224
+ assert [ln.characters for ln in est.lines] == [10, 7]
225
+
226
+
227
+ def test_estimate_prices_dialogue_at_the_named_dialogue_model(monkeypatch):
228
+ # The dialogue model is the cast's, not the narration's and not the
229
+ # module default: three distinct rates make each one visible in the sum.
230
+ monkeypatch.setitem(MODEL_USD_PER_1K_CHARS, "test-narration-model", 0.5)
231
+ monkeypatch.setitem(MODEL_USD_PER_1K_CHARS, "test-cast-model", 0.7)
232
+ monkeypatch.setitem(MODEL_USD_PER_1K_CHARS, DIALOGUE_MODEL_ID, 0.9)
233
+ script = Script(
234
+ title="t",
235
+ id_slug="01",
236
+ beats=[Narration(text="n" * 1000), Dialogue(turns=(("A", "d" * 1000),))],
237
+ )
238
+ est = estimate_cost(
239
+ script, model_id="test-narration-model", dialogue_model_id="test-cast-model"
240
+ )
241
+ assert est.usd == pytest.approx(0.5 + 0.7)
242
+ assert [ln.model_id for ln in est.lines] == [
243
+ "test-narration-model",
244
+ "test-cast-model",
245
+ ]
246
+
247
+
248
+ def test_plan_production_takes_a_profile_by_its_value():
249
+ """Every render path plans through plan_production: a profile given as its
250
+ string value must plan the same cut as the enum (published_text and all)."""
251
+ from braidio import Profile, plan_production
252
+
253
+ script = Script(
254
+ title="t",
255
+ id_slug="01",
256
+ beats=[Narration(text="original", published_text="cleared")],
257
+ )
258
+ by_value = plan_production(script, "published")
259
+ assert [b.content for b in by_value.beats] == ["cleared"]
260
+ assert by_value.profile is Profile.PUBLISHED
@@ -1948,3 +1948,143 @@ def test_ingest_document_refuses_a_zip_based_document(monkeypatch):
1948
1948
  "ingest_document",
1949
1949
  {"project_id": "d", "uri": "https://example.com/essay.docx"},
1950
1950
  )
1951
+
1952
+
1953
+ # --- every render is priced at the model it voices with (braidio#155) ------------
1954
+
1955
+ _V2, _V3, _CAST = "eleven_multilingual_v2", "eleven_v3", "test-cast-model"
1956
+ _THOUSAND = {
1957
+ "title": "t",
1958
+ "id_slug": "01",
1959
+ "beats": [{"type": "narration", "text": "a" * 1000}],
1960
+ }
1961
+ _TALK = {
1962
+ "title": "t",
1963
+ "id_slug": "01",
1964
+ "beats": [
1965
+ {"type": "narration", "text": "a" * 1000},
1966
+ {"type": "dialogue", "turns": [["A", "d" * 1000]]},
1967
+ ],
1968
+ }
1969
+
1970
+
1971
+ @pytest.fixture
1972
+ def distinct_rates(monkeypatch):
1973
+ """v2, v3 and a cast's model at different confirmed rates, so the model
1974
+ each line is voiced with shows in the price."""
1975
+ from braidio.cost import MODEL_USD_PER_1K_CHARS
1976
+
1977
+ monkeypatch.setitem(MODEL_USD_PER_1K_CHARS, _V2, 0.11)
1978
+ monkeypatch.setitem(MODEL_USD_PER_1K_CHARS, _V3, 0.33)
1979
+ monkeypatch.setitem(MODEL_USD_PER_1K_CHARS, _CAST, 0.77)
1980
+
1981
+
1982
+ @pytest.fixture
1983
+ def v2_cast_format(monkeypatch):
1984
+ """A registered format whose narration is the v2 default and whose cast
1985
+ voices dialogue on its own model — unlike every shipped format (all v3,
1986
+ all casting v3), so a model the tool hardcodes cannot pass for it."""
1987
+ fmt = braidio.Format(
1988
+ id="test_v2_cast",
1989
+ name="test",
1990
+ summary="v2 narration, a cast on its own model",
1991
+ cast=braidio.ConversationCast(model_id=_CAST),
1992
+ )
1993
+ monkeypatch.setitem(braidio.FORMATS, fmt.id, fmt)
1994
+ assert fmt.narration_delivery.model_id == _V2
1995
+ return fmt
1996
+
1997
+
1998
+ def _render_stub(*args, out_path, **kw):
1999
+ Path(out_path).parent.mkdir(parents=True, exist_ok=True)
2000
+ Path(out_path).write_bytes(b"EP")
2001
+ return Path(out_path)
2002
+
2003
+
2004
+ def test_render_production_is_priced_at_its_delivery_s_model(
2005
+ monkeypatch, distinct_rates
2006
+ ):
2007
+ monkeypatch.setattr(braidio, "render_production", _render_stub)
2008
+ server = _local_server(ledger={})
2009
+ default = _call(server, "render_production", {"script": _THOUSAND})
2010
+ v3 = _call(
2011
+ server, "render_production", {"script": _THOUSAND, "delivery": "v3-presenter"}
2012
+ )
2013
+ assert braidio.DELIVERIES["narration"].model_id == _V2 # the tool's default
2014
+ assert default.structured_content["cost_usd"] == pytest.approx(0.11)
2015
+ assert v3.structured_content["cost_usd"] == pytest.approx(0.33)
2016
+
2017
+
2018
+ def test_render_format_is_priced_at_the_format_s_narration_model(
2019
+ monkeypatch, distinct_rates, v2_cast_format
2020
+ ):
2021
+ monkeypatch.setattr(braidio, "render_format", _render_stub)
2022
+ server = _local_server(ledger={})
2023
+ shipped = _call(
2024
+ server, "render_format", {"format_id": "solo_explainer", "script": _THOUSAND}
2025
+ )
2026
+ assert braidio.FORMATS["solo_explainer"].narration_delivery.model_id == _V3
2027
+ assert shipped.structured_content["cost_usd"] == pytest.approx(0.33)
2028
+ v2 = _call(
2029
+ server, "render_format", {"format_id": v2_cast_format.id, "script": _THOUSAND}
2030
+ )
2031
+ assert v2.structured_content["cost_usd"] == pytest.approx(0.11)
2032
+
2033
+
2034
+ def test_render_format_prices_dialogue_at_the_cast_s_model(
2035
+ monkeypatch, distinct_rates, v2_cast_format
2036
+ ):
2037
+ # the cast's model, not the default cast's (v3) nor the narration's (v2)
2038
+ monkeypatch.setattr(braidio, "render_format", _render_stub)
2039
+ r = _call(
2040
+ _local_server(ledger={}),
2041
+ "render_format",
2042
+ {"format_id": v2_cast_format.id, "script": _TALK},
2043
+ )
2044
+ assert r.structured_content["characters"] == 2000
2045
+ assert r.structured_content["cost_usd"] == pytest.approx(0.11 + 0.77)
2046
+
2047
+
2048
+ @_NW
2049
+ def test_weave_project_is_priced_at_the_weave_config_s_model(
2050
+ monkeypatch, distinct_rates
2051
+ ):
2052
+ """Unwoven: the default WeaveConfig's model (v2). Once the project has
2053
+ narration renders, the model its weave-config RECORDED — which a re-weave
2054
+ keeps (resolve_config) whatever the format or default would say."""
2055
+ episode = type(
2056
+ "Ann",
2057
+ (),
2058
+ {"id": "9a23da78-0a3e-4acf-a557-48bd6e519038", "body": {"url": "file:///x"}},
2059
+ )()
2060
+ server = _local_server(ledger={})
2061
+ _call(server, "create_project", {"project_id": "demo", "title": "Demo"})
2062
+ with monkeypatch.context() as m:
2063
+ m.setattr(braidio, "weave_project", lambda proj, scr, **kw: episode)
2064
+ r = _call(server, "weave_project", {"project_id": "demo", "script": _THOUSAND})
2065
+ assert braidio.WeaveConfig().model_id == _V2
2066
+ assert r.structured_content["cost_usd"] == pytest.approx(0.11)
2067
+
2068
+ # a real first weave, voiced with v3 (synthesis stubbed)
2069
+ def _write(out, tag=b"A"):
2070
+ Path(out).parent.mkdir(parents=True, exist_ok=True)
2071
+ Path(out).write_bytes(tag)
2072
+ return Path(out)
2073
+
2074
+ monkeypatch.setattr(
2075
+ braidio,
2076
+ "narrate",
2077
+ lambda text, out, *, return_cache_status=False, **kw: (
2078
+ (_write(out), False) if return_cache_status else _write(out)
2079
+ ),
2080
+ )
2081
+ monkeypatch.setattr(braidio, "weave_timeline", lambda items, out, **kw: _write(out))
2082
+ monkeypatch.setattr(braidio, "duration_s", lambda path: 3.0)
2083
+ proj = Workspace.for_email(OWNER).open_project("demo")
2084
+ braidio.weave_project(
2085
+ proj, script_from_json(_THOUSAND), config=braidio.WeaveConfig(model_id=_V3)
2086
+ )
2087
+
2088
+ monkeypatch.setattr(braidio, "weave_project", lambda proj, scr, **kw: episode)
2089
+ r = _call(server, "weave_project", {"project_id": "demo", "script": _THOUSAND})
2090
+ assert r.structured_content["cost_usd"] == pytest.approx(0.33)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes