braidio 0.0.76__tar.gz → 0.0.78__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 (146) hide show
  1. {braidio-0.0.76 → braidio-0.0.78}/PKG-INFO +2 -2
  2. {braidio-0.0.76 → braidio-0.0.78}/braidio/delivery.py +13 -0
  3. {braidio-0.0.76 → braidio-0.0.78}/braidio/mcp/tools.py +33 -86
  4. braidio-0.0.78/braidio/project.py +144 -0
  5. {braidio-0.0.76 → braidio-0.0.78}/braidio/render.py +20 -13
  6. {braidio-0.0.76 → braidio-0.0.78}/braidio/transforms/_common.py +5 -0
  7. {braidio-0.0.76 → braidio-0.0.78}/braidio/transforms/_narration.py +76 -17
  8. {braidio-0.0.76 → braidio-0.0.78}/braidio/transforms/_voice.py +2 -1
  9. {braidio-0.0.76 → braidio-0.0.78}/pyproject.toml +2 -2
  10. {braidio-0.0.76 → braidio-0.0.78}/tests/test_mcp.py +146 -89
  11. {braidio-0.0.76 → braidio-0.0.78}/tests/test_pacing.py +52 -0
  12. {braidio-0.0.76 → braidio-0.0.78}/tests/test_transforms.py +53 -0
  13. {braidio-0.0.76 → braidio-0.0.78}/tests/test_transforms_rights.py +45 -0
  14. braidio-0.0.76/braidio/project.py +0 -60
  15. {braidio-0.0.76 → braidio-0.0.78}/.editorconfig +0 -0
  16. {braidio-0.0.76 → braidio-0.0.78}/.gitattributes +0 -0
  17. {braidio-0.0.76 → braidio-0.0.78}/.gitignore +0 -0
  18. {braidio-0.0.76 → braidio-0.0.78}/LICENSE +0 -0
  19. {braidio-0.0.76 → braidio-0.0.78}/README.md +0 -0
  20. {braidio-0.0.76 → braidio-0.0.78}/braidio/__init__.py +0 -0
  21. {braidio-0.0.76 → braidio-0.0.78}/braidio/_paths.py +0 -0
  22. {braidio-0.0.76 → braidio-0.0.78}/braidio/bodies/__init__.py +0 -0
  23. {braidio-0.0.76 → braidio-0.0.78}/braidio/bodies/_domain.py +0 -0
  24. {braidio-0.0.76 → braidio-0.0.78}/braidio/bodies/_render_nodes.py +0 -0
  25. {braidio-0.0.76 → braidio-0.0.78}/braidio/bodies/_tiers.py +0 -0
  26. {braidio-0.0.76 → braidio-0.0.78}/braidio/bodies/_video.py +0 -0
  27. {braidio-0.0.76 → braidio-0.0.78}/braidio/captions.py +0 -0
  28. {braidio-0.0.76 → braidio-0.0.78}/braidio/compose.py +0 -0
  29. {braidio-0.0.76 → braidio-0.0.78}/braidio/conversation.py +0 -0
  30. {braidio-0.0.76 → braidio-0.0.78}/braidio/cost.py +0 -0
  31. {braidio-0.0.76 → braidio-0.0.78}/braidio/data/skills/braidio/SKILL.md +0 -0
  32. {braidio-0.0.76 → braidio-0.0.78}/braidio/data/skills/braidio-commentary-video/SKILL.md +0 -0
  33. {braidio-0.0.76 → braidio-0.0.78}/braidio/defaults.py +0 -0
  34. {braidio-0.0.76 → braidio-0.0.78}/braidio/downloads.py +0 -0
  35. {braidio-0.0.76 → braidio-0.0.78}/braidio/formats.py +0 -0
  36. {braidio-0.0.76 → braidio-0.0.78}/braidio/genre.py +0 -0
  37. {braidio-0.0.76 → braidio-0.0.78}/braidio/importing/__init__.py +0 -0
  38. {braidio-0.0.76 → braidio-0.0.78}/braidio/importing/__main__.py +0 -0
  39. {braidio-0.0.76 → braidio-0.0.78}/braidio/importing/_catalog.py +0 -0
  40. {braidio-0.0.76 → braidio-0.0.78}/braidio/importing/_manifest.py +0 -0
  41. {braidio-0.0.76 → braidio-0.0.78}/braidio/importing/_writer.py +0 -0
  42. {braidio-0.0.76 → braidio-0.0.78}/braidio/kinds.py +0 -0
  43. {braidio-0.0.76 → braidio-0.0.78}/braidio/markdown_script.py +0 -0
  44. {braidio-0.0.76 → braidio-0.0.78}/braidio/mcp/__init__.py +0 -0
  45. {braidio-0.0.76 → braidio-0.0.78}/braidio/mcp/_docs.py +0 -0
  46. {braidio-0.0.76 → braidio-0.0.78}/braidio/mcp/_guide.py +0 -0
  47. {braidio-0.0.76 → braidio-0.0.78}/braidio/mcp/_helpers.py +0 -0
  48. {braidio-0.0.76 → braidio-0.0.78}/braidio/mcp/_media.py +0 -0
  49. {braidio-0.0.76 → braidio-0.0.78}/braidio/mcp/credentials.py +0 -0
  50. {braidio-0.0.76 → braidio-0.0.78}/braidio/mcp/metering.py +0 -0
  51. {braidio-0.0.76 → braidio-0.0.78}/braidio/mcp/workspace.py +0 -0
  52. {braidio-0.0.76 → braidio-0.0.78}/braidio/multivoice.py +0 -0
  53. {braidio-0.0.76 → braidio-0.0.78}/braidio/music.py +0 -0
  54. {braidio-0.0.76 → braidio-0.0.78}/braidio/pacing.py +0 -0
  55. {braidio-0.0.76 → braidio-0.0.78}/braidio/provenance.py +0 -0
  56. {braidio-0.0.76 → braidio-0.0.78}/braidio/relevance.py +0 -0
  57. {braidio-0.0.76 → braidio-0.0.78}/braidio/rights.py +0 -0
  58. {braidio-0.0.76 → braidio-0.0.78}/braidio/script.py +0 -0
  59. {braidio-0.0.76 → braidio-0.0.78}/braidio/sources.py +0 -0
  60. {braidio-0.0.76 → braidio-0.0.78}/braidio/structure.py +0 -0
  61. {braidio-0.0.76 → braidio-0.0.78}/braidio/style.py +0 -0
  62. {braidio-0.0.76 → braidio-0.0.78}/braidio/textprep.py +0 -0
  63. {braidio-0.0.76 → braidio-0.0.78}/braidio/timeline.py +0 -0
  64. {braidio-0.0.76 → braidio-0.0.78}/braidio/transforms/__init__.py +0 -0
  65. {braidio-0.0.76 → braidio-0.0.78}/braidio/transforms/_asset_refs.py +0 -0
  66. {braidio-0.0.76 → braidio-0.0.78}/braidio/transforms/_dialogue.py +0 -0
  67. {braidio-0.0.76 → braidio-0.0.78}/braidio/transforms/_episode.py +0 -0
  68. {braidio-0.0.76 → braidio-0.0.78}/braidio/transforms/_ingest.py +0 -0
  69. {braidio-0.0.76 → braidio-0.0.78}/braidio/transforms/_segment.py +0 -0
  70. {braidio-0.0.76 → braidio-0.0.78}/braidio/transforms/_video_cut.py +0 -0
  71. {braidio-0.0.76 → braidio-0.0.78}/braidio/transforms/_video_panels.py +0 -0
  72. {braidio-0.0.76 → braidio-0.0.78}/braidio/tts.py +0 -0
  73. {braidio-0.0.76 → braidio-0.0.78}/braidio/video.py +0 -0
  74. {braidio-0.0.76 → braidio-0.0.78}/braidio/voice_library.py +0 -0
  75. {braidio-0.0.76 → braidio-0.0.78}/braidio/weave.py +0 -0
  76. {braidio-0.0.76 → braidio-0.0.78}/braidio/weave_config.py +0 -0
  77. {braidio-0.0.76 → braidio-0.0.78}/conftest.py +0 -0
  78. {braidio-0.0.76 → braidio-0.0.78}/misc/docs/Extraction and nw-App Design.md +0 -0
  79. {braidio-0.0.76 → braidio-0.0.78}/misc/docs/research/commentary-formats-and-styles.md +0 -0
  80. {braidio-0.0.76 → braidio-0.0.78}/misc/docs/research/conversational-vs-narration-tts.md +0 -0
  81. {braidio-0.0.76 → braidio-0.0.78}/misc/docs/research/notebooklm-and-conversational-pacing.md +0 -0
  82. {braidio-0.0.76 → braidio-0.0.78}/misc/docs/style/README.md +0 -0
  83. {braidio-0.0.76 → braidio-0.0.78}/misc/docs/style/anti-platitude-checklist.md +0 -0
  84. {braidio-0.0.76 → braidio-0.0.78}/misc/docs/style/commentary-voice-guide.md +0 -0
  85. {braidio-0.0.76 → braidio-0.0.78}/misc/docs/style/voices/_style-groups.md +0 -0
  86. {braidio-0.0.76 → braidio-0.0.78}/misc/docs/style/voices/amanda-dobbins.md +0 -0
  87. {braidio-0.0.76 → braidio-0.0.78}/misc/docs/style/voices/david-sims.md +0 -0
  88. {braidio-0.0.76 → braidio-0.0.78}/misc/docs/style/voices/griffin-newman.md +0 -0
  89. {braidio-0.0.76 → braidio-0.0.78}/misc/docs/style/voices/helen-molesworth.md +0 -0
  90. {braidio-0.0.76 → braidio-0.0.78}/misc/docs/style/voices/hrishikesh-hirway.md +0 -0
  91. {braidio-0.0.76 → braidio-0.0.78}/misc/docs/style/voices/jason-mantzoukas.md +0 -0
  92. {braidio-0.0.76 → braidio-0.0.78}/misc/docs/style/voices/john-mcwhorter.md +0 -0
  93. {braidio-0.0.76 → braidio-0.0.78}/misc/docs/style/voices/jon-caramanica.md +0 -0
  94. {braidio-0.0.76 → braidio-0.0.78}/misc/docs/style/voices/june-diane-raphael.md +0 -0
  95. {braidio-0.0.76 → braidio-0.0.78}/misc/docs/style/voices/karina-longworth.md +0 -0
  96. {braidio-0.0.76 → braidio-0.0.78}/misc/docs/style/voices/katy-hessel.md +0 -0
  97. {braidio-0.0.76 → braidio-0.0.78}/misc/docs/style/voices/louis-theroux.md +0 -0
  98. {braidio-0.0.76 → braidio-0.0.78}/misc/docs/style/voices/mallory-rubin.md +0 -0
  99. {braidio-0.0.76 → braidio-0.0.78}/misc/docs/style/voices/melvyn-bragg.md +0 -0
  100. {braidio-0.0.76 → braidio-0.0.78}/misc/docs/style/voices/michael-barbaro.md +0 -0
  101. {braidio-0.0.76 → braidio-0.0.78}/misc/docs/style/voices/nate-sloan-charlie-harding.md +0 -0
  102. {braidio-0.0.76 → braidio-0.0.78}/misc/docs/style/voices/paul-scheer.md +0 -0
  103. {braidio-0.0.76 → braidio-0.0.78}/misc/docs/style/voices/sean-fennessey.md +0 -0
  104. {braidio-0.0.76 → braidio-0.0.78}/misc/docs/style/voices/talk-art.md +0 -0
  105. {braidio-0.0.76 → braidio-0.0.78}/misc/docs/style/voices/yasi-salek.md +0 -0
  106. {braidio-0.0.76 → braidio-0.0.78}/misc/docs/youtube_ingest_credentials.md +0 -0
  107. {braidio-0.0.76 → braidio-0.0.78}/tests/_audio.py +0 -0
  108. {braidio-0.0.76 → braidio-0.0.78}/tests/test_body_schema_stability.py +0 -0
  109. {braidio-0.0.76 → braidio-0.0.78}/tests/test_conversation.py +0 -0
  110. {braidio-0.0.76 → braidio-0.0.78}/tests/test_cost.py +0 -0
  111. {braidio-0.0.76 → braidio-0.0.78}/tests/test_credits_card.py +0 -0
  112. {braidio-0.0.76 → braidio-0.0.78}/tests/test_defaults.py +0 -0
  113. {braidio-0.0.76 → braidio-0.0.78}/tests/test_delivery.py +0 -0
  114. {braidio-0.0.76 → braidio-0.0.78}/tests/test_downloads.py +0 -0
  115. {braidio-0.0.76 → braidio-0.0.78}/tests/test_expressiveness.py +0 -0
  116. {braidio-0.0.76 → braidio-0.0.78}/tests/test_formats.py +0 -0
  117. {braidio-0.0.76 → braidio-0.0.78}/tests/test_genre_placement.py +0 -0
  118. {braidio-0.0.76 → braidio-0.0.78}/tests/test_importing.py +0 -0
  119. {braidio-0.0.76 → braidio-0.0.78}/tests/test_markdown_script.py +0 -0
  120. {braidio-0.0.76 → braidio-0.0.78}/tests/test_mcp_caller_key.py +0 -0
  121. {braidio-0.0.76 → braidio-0.0.78}/tests/test_media_auth.py +0 -0
  122. {braidio-0.0.76 → braidio-0.0.78}/tests/test_multivoice.py +0 -0
  123. {braidio-0.0.76 → braidio-0.0.78}/tests/test_music.py +0 -0
  124. {braidio-0.0.76 → braidio-0.0.78}/tests/test_namespaced_source.py +0 -0
  125. {braidio-0.0.76 → braidio-0.0.78}/tests/test_nw_app.py +0 -0
  126. {braidio-0.0.76 → braidio-0.0.78}/tests/test_packaging.py +0 -0
  127. {braidio-0.0.76 → braidio-0.0.78}/tests/test_render_settings.py +0 -0
  128. {braidio-0.0.76 → braidio-0.0.78}/tests/test_script.py +0 -0
  129. {braidio-0.0.76 → braidio-0.0.78}/tests/test_sources.py +0 -0
  130. {braidio-0.0.76 → braidio-0.0.78}/tests/test_structure.py +0 -0
  131. {braidio-0.0.76 → braidio-0.0.78}/tests/test_textprep_style.py +0 -0
  132. {braidio-0.0.76 → braidio-0.0.78}/tests/test_timeline.py +0 -0
  133. {braidio-0.0.76 → braidio-0.0.78}/tests/test_transforms_dialogue.py +0 -0
  134. {braidio-0.0.76 → braidio-0.0.78}/tests/test_transforms_episode_members.py +0 -0
  135. {braidio-0.0.76 → braidio-0.0.78}/tests/test_transforms_secrets.py +0 -0
  136. {braidio-0.0.76 → braidio-0.0.78}/tests/test_transforms_structure.py +0 -0
  137. {braidio-0.0.76 → braidio-0.0.78}/tests/test_tts_api_key.py +0 -0
  138. {braidio-0.0.76 → braidio-0.0.78}/tests/test_turn_overlap.py +0 -0
  139. {braidio-0.0.76 → braidio-0.0.78}/tests/test_video.py +0 -0
  140. {braidio-0.0.76 → braidio-0.0.78}/tests/test_video_bodies.py +0 -0
  141. {braidio-0.0.76 → braidio-0.0.78}/tests/test_video_footage.py +0 -0
  142. {braidio-0.0.76 → braidio-0.0.78}/tests/test_video_transforms.py +0 -0
  143. {braidio-0.0.76 → braidio-0.0.78}/tests/test_voice_library.py +0 -0
  144. {braidio-0.0.76 → braidio-0.0.78}/tests/test_weave.py +0 -0
  145. {braidio-0.0.76 → braidio-0.0.78}/tests/test_weave_config.py +0 -0
  146. {braidio-0.0.76 → braidio-0.0.78}/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.76
3
+ Version: 0.0.78
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
@@ -56,7 +56,7 @@ Requires-Dist: mdit-py-plugins; extra == 'mcp'
56
56
  Requires-Dist: nw>=0.0.65; extra == 'mcp'
57
57
  Requires-Dist: py2mcp>=0.1.9; extra == 'mcp'
58
58
  Requires-Dist: pypdf; extra == 'mcp'
59
- Requires-Dist: yb[download]>=0.1.7; extra == 'mcp'
59
+ Requires-Dist: yb[download]>=0.1.24; extra == 'mcp'
60
60
  Provides-Extra: nw-app
61
61
  Requires-Dist: falaw[fal]; extra == 'nw-app'
62
62
  Requires-Dist: lacing; extra == 'nw-app'
@@ -16,6 +16,19 @@ from __future__ import annotations
16
16
  from dataclasses import dataclass, field
17
17
 
18
18
 
19
+ #: Models that ignore ``voice_settings["speed"]`` (eleven v3 has no speed control).
20
+ SPEEDLESS_MODELS = frozenset({"eleven_v3"})
21
+
22
+
23
+ def model_supports_speed(model_id: str) -> bool:
24
+ """Whether ``model_id`` honors ``voice_settings["speed"]``.
25
+
26
+ >>> model_supports_speed("eleven_v3"), model_supports_speed("eleven_multilingual_v2")
27
+ (False, True)
28
+ """
29
+ return model_id not in SPEEDLESS_MODELS
30
+
31
+
19
32
  @dataclass(frozen=True)
20
33
  class Delivery:
21
34
  """A named narration delivery: which model + voice settings to synthesize with."""
@@ -323,23 +323,16 @@ def list_projects() -> dict:
323
323
 
324
324
 
325
325
  def project_status(project_id: str) -> dict:
326
- """A project's status: its finished episode renders (url + duration), if any.
327
-
328
- Each episode row carries ``episode_id`` — the id ``resolve`` accepts and a
329
- download claim is minted against. The body's own ``artifact_id`` is the
330
- lacing CONTENT hash: an identity for provenance, not a retrieval key
331
- (braidio#32 — the tool used to return only the body, so the one id a
332
- caller could see was the one no download tool accepted).
326
+ """A project's status: beat/render counts, the next step, and its finished
327
+ episodes (url + duration). Each episode's ``episode_id`` is the id ``resolve``
328
+ accepts; the body's ``artifact_id`` is a content hash, not a download key.
333
329
  """
334
330
  _require_nw("project_status")
335
- import nw
336
-
337
331
  proj = _workspace().open_project(project_id)
338
- episodes = [
339
- {"episode_id": str(a.id), **to_json(a.body)}
340
- for a in nw.annotations_at_tier(proj.root, "episode-renders")
341
- ]
342
- return {"project_id": project_id, "episodes": episodes}
332
+ # The genre's status (what a host's one project_status door serves) plus every
333
+ # episode's full body, url included: this caller owns the workspace.
334
+ episodes = [{"episode_id": str(a.id), **to_json(a.body)} for a in proj.episodes()]
335
+ return {"project_id": project_id, **proj.genre_status(), "episodes": episodes}
343
336
 
344
337
 
345
338
  #: Content types whose extracted text has lost its markdown structure, so
@@ -558,21 +551,12 @@ def download_audio(url: str, name: str | None = None) -> dict:
558
551
  size/duration-bounded; best audio stream → mp3 via yt-dlp (no login/API
559
552
  key). Needs ``braidio[mcp]`` + ffmpeg.
560
553
  """
561
- from pathlib import Path
554
+ import shutil
562
555
 
563
556
  from braidio.mcp import _docs, _media
564
557
 
565
- # SSRF pre-check (matches upload_asset/ingest_document): refuse non-http(s) and
566
- # loopback/private/link-local/cloud-metadata hosts. NOTE: yt-dlp resolves the page +
567
- # follows redirects itself, so this closes the direct-target vector but is not a full
568
- # egress sandbox — the driving agent's `url` can be steered by prompt injection.
569
558
  try:
570
- _docs._validate_target(url)
571
- except ValueError as exc:
572
- raise ToolError(str(exc)) from exc
573
-
574
- try:
575
- from yb.download import download_youtube_video, youtube_video_info
559
+ from yb.download import download_audio_bounded
576
560
  except ImportError as exc:
577
561
  raise ToolError(
578
562
  "audio download needs yt-dlp — install braidio[mcp] (which pulls yb[download])"
@@ -584,82 +568,45 @@ def download_audio(url: str, name: str | None = None) -> dict:
584
568
  creds = _media.SourceCredentials.from_env()
585
569
  creds.check()
586
570
 
587
- # Reject over-long sources (livestreams / multi-hour) BEFORE fetching any bytes.
588
- # Credentials go on this call too — the bot gate fires during metadata extraction.
589
- try:
590
- preview = youtube_video_info(url, extra_opts=dict(creds.opts))
591
- except Exception as exc: # noqa: BLE001 — extractor errors
592
- raise _media.as_tool_error(
593
- exc, fallback="could not read the source", credentials=creds
594
- ) from exc
595
- duration = preview.get("duration")
596
- if isinstance(duration, (int, float)) and duration > _AUDIO_MAX_DURATION_S:
597
- raise ToolError(
598
- f"source is {int(duration)}s long; exceeds the "
599
- f"{_AUDIO_MAX_DURATION_S}s audio-download limit"
600
- )
601
-
571
+ # The link-to-audio policy (target check before the network and again on the
572
+ # resolved page, playlist/live/duration refusal before any media bytes, pinned
573
+ # caps, mp3) is yb's. braidio supplies its SSRF check — loopback/private/
574
+ # link-local/cloud-metadata hosts refused; not a full egress sandbox, since
575
+ # yt-dlp follows redirects itself — and its env-tunable caps.
602
576
  ws = _workspace()
603
- work = ws.renders_dir / "_downloads"
604
- work.mkdir(parents=True, exist_ok=True)
605
577
  try:
606
- result = download_youtube_video(
578
+ got = download_audio_bounded(
607
579
  url,
608
- download_dir=str(work),
609
- fmt="bestaudio/best",
610
- merge_to=None, # audio-only; no video+audio merge
611
- extra_opts={
612
- **creds.opts,
613
- # braidio's own bounds are written AFTER the deployment's options, so a
614
- # configured option can never widen a safety bound.
615
- "max_filesize": _AUDIO_MAX_BYTES, # yt-dlp skips/aborts oversized formats
616
- "postprocessors": [
617
- {
618
- "key": "FFmpegExtractAudio",
619
- "preferredcodec": "mp3",
620
- "preferredquality": "192",
621
- }
622
- ],
623
- },
580
+ download_dir=ws.renders_dir / "_downloads",
581
+ max_bytes=_AUDIO_MAX_BYTES,
582
+ max_duration_s=_AUDIO_MAX_DURATION_S,
583
+ validate_target=_docs._validate_target,
584
+ extra_opts=creds.opts,
585
+ cookies_file=False, # braidio's credentials are the only cookie source
624
586
  )
625
- except Exception as exc: # noqa: BLE001 — yt-dlp raises many extractor error types
587
+ except Exception as exc: # noqa: BLE001 — a refusal, a cap, or any yt-dlp error
626
588
  raise _media.as_tool_error(
627
589
  exc, fallback="audio download failed", credentials=creds
628
590
  ) from exc
629
591
 
630
- audio_path = Path(result.path)
631
- if audio_path.suffix.lower() != ".mp3": # the postprocessor rewrites to .mp3
632
- mp3 = audio_path.with_suffix(".mp3")
633
- if mp3.exists():
634
- audio_path = mp3
635
- # Belt-and-braces size gate before loading into RAM (post-processing can grow a file,
636
- # and max_filesize bounds the download, not the extracted output).
637
- if audio_path.stat().st_size > _AUDIO_MAX_BYTES:
638
- try:
639
- audio_path.unlink()
640
- except OSError:
641
- pass
642
- raise ToolError(f"downloaded audio exceeds the {_AUDIO_MAX_BYTES}-byte limit")
643
- data = audio_path.read_bytes()
644
- info = result.info or {}
645
- title = name or info.get("title") or audio_path.stem
646
- ref = ws.content_store().add(data, mime_type="audio/mpeg", name=title)
592
+ try:
593
+ title = name or got.title
594
+ ref = ws.content_store().add(
595
+ got.path.read_bytes(), mime_type="audio/mpeg", name=title
596
+ )
597
+ finally:
598
+ # yb hands over a per-call directory; the content-addressed store owns the
599
+ # bytes now (or the ingest failed), so it goes either way.
600
+ shutil.rmtree(got.path.parent, ignore_errors=True)
647
601
  meta = {
648
602
  **ref.to_json(),
649
603
  "name": title,
650
604
  "source": url,
651
605
  "kind": "audio",
652
- "duration": info.get("duration"),
653
- "copyright_notice": (
654
- "Downloaded from a user-supplied link — respect the source's copyright and "
655
- "terms of service; you are responsible for having the right to use it."
656
- ),
606
+ "duration": got.duration_s,
607
+ "copyright_notice": got.notice,
657
608
  }
658
609
  ws.asset_meta()[ref.item_id] = meta
659
- try:
660
- audio_path.unlink() # the content-addressed store owns the bytes now
661
- except OSError:
662
- pass
663
610
  return meta
664
611
 
665
612
 
@@ -0,0 +1,144 @@
1
+ """braidio as an nw app: a :class:`nw.Project` for commentary-weave productions.
2
+
3
+ Subclassing ``nw.Project`` inherits the whole folder facade + lacing graph +
4
+ freshness (``stale_after``) machinery; braidio adds its production kind and its
5
+ domain/render body-schema vocabulary (registered on import of
6
+ :mod:`braidio.bodies`). This module requires ``nw``; it is imported lazily by
7
+ ``braidio/__init__`` only when ``nw`` is available.
8
+
9
+ The costed ``plan``/``execute`` Transform pipeline (each transform delegating to
10
+ braidio's functional core for the actual audio, and recording provenance via
11
+ :mod:`braidio.provenance`) is the next increment — see the design doc and
12
+ nw#9 (generalizing nw's shot/mp4 render seam).
13
+ """
14
+
15
+ from __future__ import annotations
16
+
17
+ from pathlib import Path
18
+
19
+ import nw
20
+
21
+ from braidio import bodies as _bodies # noqa: F401 (import registers schemas)
22
+ from braidio.kinds import WeaveKind
23
+
24
+
25
+ #: The next step, by how far the project has got: ``(op, why)``, ``op`` in
26
+ #: braidio's own vocabulary (a host maps it to its tool name, prefix and all).
27
+ NEXT_STEP_SAVE_SCRIPT = ("save_script", "there is no script yet")
28
+ NEXT_STEP_WEAVE = ("weave_project", "the script has not been rendered yet")
29
+ NEXT_STEP_DONE = (
30
+ "weave_project",
31
+ "an episode is made — download it by its episode_id, or weave again after "
32
+ "changing the script",
33
+ )
34
+
35
+
36
+ def _tiers():
37
+ """The tier names, from the one table the transforms write by (lazy: the
38
+ transforms package is heavy and this module is imported with ``braidio``)."""
39
+ from braidio.transforms import _common
40
+
41
+ return _common
42
+
43
+
44
+ def _episode_row(annotation) -> dict:
45
+ """One finished episode, path-free: the body's ``file://`` url and its
46
+ (large) timeline are left out."""
47
+ body = annotation.body
48
+ duration = body.get("duration_s")
49
+ return {
50
+ "episode_id": str(annotation.id),
51
+ "profile": body.get("profile"),
52
+ "duration_s": None if duration is None else round(float(duration), 2),
53
+ }
54
+
55
+
56
+ class Project(nw.Project):
57
+ """An nw project for a braidio commentary-weave production."""
58
+
59
+ KIND: WeaveKind = WeaveKind.COMMENTARY_WEAVE
60
+
61
+ def episodes(self) -> list:
62
+ """The project's finished episodes (``episode-renders`` nodes), oldest first.
63
+
64
+ A re-weave adds an episode and keeps the earlier ones, so the last is
65
+ the current one.
66
+ """
67
+ tiers = _tiers()
68
+ return sorted(
69
+ nw.annotations_at_tier(self.root, tiers.TIER_EPISODE_RENDER),
70
+ # generation time, then id: nw's own order (ties: legacy tick-0 stamps)
71
+ key=lambda a: (a.provenance.generated_at_time.to_seconds(), str(a.id)),
72
+ )
73
+
74
+ def genre_status(self) -> dict:
75
+ """Where this production stands, for a host's one ``project_status`` door
76
+ (``nw.Project.genre_status``, nw#133; braidio#125).
77
+
78
+ Counted, in muvid's shape: the script's beats by kind, how many episodes
79
+ were rendered, the latest one (path-free), and the next step as
80
+ ``{"op", "why"}``. Indexed tier reads only — no freshness walk, no file
81
+ probe — and no per-item list, so it stays small however often the
82
+ project is re-woven, and never names a path.
83
+
84
+ >>> import tempfile
85
+ >>> with tempfile.TemporaryDirectory() as d:
86
+ ... status = create_project_at(d, "ep").genre_status()
87
+ >>> status["episode_count"], status["next_step"]["op"]
88
+ (0, 'save_script')
89
+ """
90
+ tiers = _tiers()
91
+ counts = {
92
+ key: len(nw.annotations_at_tier(self.root, tier))
93
+ for key, tier in (
94
+ ("narration_beats", tiers.TIER_NARRATIVE_BEAT),
95
+ ("dialogue_beats", tiers.TIER_DIALOGUE_BEAT),
96
+ ("clips", tiers.TIER_AUDIO_CLIP),
97
+ ("scene_breaks", tiers.TIER_SCENE_BREAK),
98
+ )
99
+ }
100
+ episodes = self.episodes()
101
+ if episodes:
102
+ op, why = NEXT_STEP_DONE
103
+ elif any(counts.values()):
104
+ op, why = NEXT_STEP_WEAVE
105
+ else:
106
+ op, why = NEXT_STEP_SAVE_SCRIPT
107
+ return {
108
+ **counts,
109
+ "episode_count": len(episodes),
110
+ "latest_episode": _episode_row(episodes[-1]) if episodes else None,
111
+ "next_step": {"op": op, "why": why},
112
+ }
113
+
114
+
115
+ def create_project_at(
116
+ projects_dir: "str | Path", project_id: str, *, title: str = "", force: bool = False
117
+ ) -> Project:
118
+ """Create a braidio project at ``projects_dir/<project_id>`` — the *host-placed* create.
119
+
120
+ The counterpart to :meth:`braidio.mcp.workspace.Workspace.create_project`, which
121
+ places a project in braidio's own per-caller workspace. This one takes the
122
+ directory from its caller, because a host that will **serve** the project
123
+ (reelee, over HTTP) has to put it where its own resolver and lister look — under
124
+ braidio's data home it would be a sibling of nothing the host can address. See
125
+ nw's ``projects_dir`` placement contract (thorwhalen/nw#84).
126
+
127
+ Deliberately here and not in ``braidio.mcp.workspace``: importing that module
128
+ runs ``braidio/mcp/__init__.py`` and pulls **fastmcp**, and the host-placed path
129
+ has no reason to require the MCP extra. ``project_id`` is validated as a single
130
+ traversal-safe component, so the result is always a direct child of
131
+ ``projects_dir`` — which is the property the host's lister depends on, and which
132
+ nw verifies after the fact.
133
+
134
+ >>> import tempfile
135
+ >>> with tempfile.TemporaryDirectory() as d:
136
+ ... p = create_project_at(d, "ep_01", title="Episode 1")
137
+ ... p.root.name
138
+ 'ep_01'
139
+ """
140
+ from braidio._paths import safe_component
141
+
142
+ root = Path(projects_dir) / safe_component(project_id, label="project_id")
143
+ root.parent.mkdir(parents=True, exist_ok=True)
144
+ return Project.init(root, title=title or project_id, force=force)
@@ -100,26 +100,28 @@ def _tail_gap(src: Path, dst: Path, *, gap_s: float) -> Path:
100
100
  return dst
101
101
 
102
102
 
103
- def _plan_beat_turns(
103
+ def plan_beat_turns(
104
104
  text: str,
105
105
  *,
106
106
  config: WeaveConfig | None,
107
- delivery: Delivery,
107
+ supports_speed: bool,
108
108
  settings: dict,
109
109
  seed_offset: int,
110
110
  ) -> list[NarrationTurn]:
111
111
  """Plan one narration beat's turns, or ``[]`` for the unpaced single call.
112
112
 
113
- The speed each turn is jittered around is the *delivery's* own ``speed``
113
+ The speed each turn is jittered around is the beat's own ``speed`` setting
114
114
  when it sets one (so a grave ``v2-narrator``'s 0.94 survives being paced),
115
115
  falling back to ``WeaveConfig.speed_base``. A model with no speed control
116
- (eleven v3 — :attr:`braidio.delivery.Delivery.supports_speed`) plans none.
116
+ (eleven v3 — :attr:`braidio.delivery.Delivery.supports_speed`,
117
+ :func:`braidio.delivery.model_supports_speed`) plans none.
118
+
119
+ Shared by the fast path and the graph's ``narration_render.tts``, which is
120
+ what keeps their per-beat durations (and so their timelines) equal.
117
121
  """
118
122
  if config is None or not config.paces_narration:
119
123
  return []
120
- speed_base = (
121
- settings.get("speed", config.speed_base) if delivery.supports_speed else None
122
- )
124
+ speed_base = settings.get("speed", config.speed_base) if supports_speed else None
123
125
  return plan_turns(
124
126
  text,
125
127
  unit=config.segmentation_unit,
@@ -132,7 +134,7 @@ def _plan_beat_turns(
132
134
  )
133
135
 
134
136
 
135
- def _narrate_turns(
137
+ def narrate_turns(
136
138
  turns: list[NarrationTurn],
137
139
  *,
138
140
  stem: Path,
@@ -140,6 +142,7 @@ def _narrate_turns(
140
142
  voice_id: str | None,
141
143
  model_id: str,
142
144
  voice_settings: dict,
145
+ narrate_fn=None,
143
146
  ) -> Path:
144
147
  """Synthesize a paced narration beat: one TTS call per turn, real silence between.
145
148
 
@@ -147,13 +150,17 @@ def _narrate_turns(
147
150
  varies (a fresh prosodic arc per turn, a per-turn speed where the model has
148
151
  one) and the silence between turns is proportional to how strongly the
149
152
  boundary closes, instead of one flat arc with nothing inside it.
153
+
154
+ ``narrate_fn`` is the synthesis call (default: this module's ``narrate``);
155
+ a caller that wants the cache status, or a stub, passes its own.
150
156
  """
157
+ synthesize = narrate_fn or narrate
151
158
  parts: list[Path] = []
152
159
  for j, turn in enumerate(turns):
153
160
  settings = dict(voice_settings)
154
161
  if turn.speed is not None:
155
162
  settings["speed"] = turn.speed
156
- part = narrate(
163
+ part = synthesize(
157
164
  turn.text,
158
165
  stem.with_name(f"{stem.name}-turn{j:02d}.mp3"),
159
166
  api_key=api_key,
@@ -375,15 +382,15 @@ def render_production(
375
382
  )
376
383
  # Intra-beat pacing — empty plan (the default `segmentation_unit=
377
384
  # "beat"`) keeps the historical one-call-per-beat path untouched.
378
- turns = _plan_beat_turns(
385
+ turns = plan_beat_turns(
379
386
  pb.content,
380
387
  config=config,
381
- delivery=delivery,
388
+ supports_speed=delivery.supports_speed,
382
389
  settings=beat_settings,
383
- seed_offset=i,
390
+ seed_offset=pb.from_index, # the script position, as the graph's beat_id
384
391
  )
385
392
  if turns:
386
- raw = _narrate_turns(
393
+ raw = narrate_turns(
387
394
  turns,
388
395
  stem=beat_stem,
389
396
  api_key=api_key,
@@ -141,6 +141,11 @@ def beat_id(index: int) -> str:
141
141
  return f"{index:0{BEAT_ID_WIDTH}d}"
142
142
 
143
143
 
144
+ def beat_ordinal(beat: Annotation) -> int:
145
+ """A narrative beat's script position — what casting and pacing seed on."""
146
+ return int(beat.body.get("beat_id", "0") or 0)
147
+
148
+
144
149
  def planned_value(ann: Annotation) -> dict:
145
150
  """``ann.body`` minus its :data:`RENDER_OUTPUT_KEYS` — what its plan decided.
146
151
 
@@ -21,7 +21,9 @@ audio-affecting input). ``None`` falls back to the process environment
21
21
  from __future__ import annotations
22
22
 
23
23
  import json
24
+ import shutil
24
25
  import uuid
26
+ from dataclasses import asdict
25
27
  from pathlib import Path
26
28
 
27
29
  from falaw import Plan
@@ -37,12 +39,16 @@ from braidio.bodies._render_nodes import (
37
39
  NarrationRenderBodyV1,
38
40
  )
39
41
  from braidio.cost import tts_cost_usd
42
+ from braidio.delivery import model_supports_speed
43
+ from braidio.render import narrate_turns, plan_beat_turns
40
44
  from braidio.tts import DEFAULT_MODEL_ID, DEFAULT_VOICE_ID
45
+ from braidio.weave_config import WeaveConfig
41
46
  from braidio.transforms._common import (
42
47
  TIER_NARRATIVE_BEAT,
43
48
  TIER_VOICE_ASSIGNMENT,
44
49
  TIER_WEAVE_CONFIG,
45
50
  TIER_NARRATION_RENDER,
51
+ beat_ordinal,
46
52
  child_at_tier,
47
53
  singleton,
48
54
  graph_index,
@@ -61,7 +67,7 @@ NAME = "narration_render.tts"
61
67
 
62
68
 
63
69
  def _narration_cache_key(
64
- transform, text: str, voice_id: str, model_id: str, settings
70
+ transform, text: str, voice_id: str, model_id: str, settings, turns=()
65
71
  ) -> str:
66
72
  """The output identity for one TTS render — nw's shared derivation.
67
73
 
@@ -71,17 +77,23 @@ def _narration_cache_key(
71
77
  bump — which is then the first salt (nw#54; drift in the previous
72
78
  private ``mixing._cache`` import would have silently changed cache keys
73
79
  on PAID calls).
80
+
81
+ ``turns`` is the paced plan (:func:`_beat_turns`): what is synthesized when
82
+ the config paces narration. Unpaced, it is empty and adds nothing, so an
83
+ unpaced project keeps its keys.
74
84
  """
75
85
  from nw.transforms import cache_key as transform_cache_key
76
86
 
77
- return transform_cache_key(
78
- transform,
87
+ parts = [
79
88
  "narration",
80
89
  text,
81
90
  voice_id,
82
91
  model_id,
83
92
  json.dumps(settings or {}, sort_keys=True),
84
- )
93
+ ]
94
+ if turns:
95
+ parts.append(json.dumps([asdict(t) for t in turns], sort_keys=True))
96
+ return transform_cache_key(transform, *parts)
85
97
 
86
98
 
87
99
  def _beat_settings(beat, config: dict) -> dict:
@@ -89,6 +101,24 @@ def _beat_settings(beat, config: dict) -> dict:
89
101
  return beat.body.get("voice_settings") or config.get("voice_settings", {})
90
102
 
91
103
 
104
+ def _beat_turns(beat, config: dict, *, model_id: str, settings: dict) -> list:
105
+ """The beat's paced turns — ``[]`` when the config does not pace narration.
106
+
107
+ The fast path's planner (:func:`braidio.render.plan_beat_turns`), so a
108
+ ``segmentation_unit`` other than ``"beat"`` cuts a beat the same way on both
109
+ paths. Seeded by the beat's script position (``beat_id`` here,
110
+ ``PlannedBeat.from_index`` on the fast path), which a dropped beat leaves
111
+ unchanged.
112
+ """
113
+ return plan_beat_turns(
114
+ beat.body.get("text", ""),
115
+ config=WeaveConfig.from_snapshot(config),
116
+ supports_speed=model_supports_speed(model_id),
117
+ settings=settings,
118
+ seed_offset=beat_ordinal(beat),
119
+ )
120
+
121
+
92
122
  @register_transform(NAME)
93
123
  class NarrationRenderTTS(BaseTransform):
94
124
  """Narrative beat (+ voice-assignment + weave-config) → ``narration-render/v1``."""
@@ -108,8 +138,9 @@ class NarrationRenderTTS(BaseTransform):
108
138
  voice_id = va.body.get("voice_id") or DEFAULT_VOICE_ID
109
139
  model_id = config.get("model_id", DEFAULT_MODEL_ID)
110
140
  settings = _beat_settings(beat, config)
141
+ turns = _beat_turns(beat, config, model_id=model_id, settings=settings)
111
142
  cache_key = _narration_cache_key(
112
- self, beat.body.get("text", ""), voice_id, model_id, settings
143
+ self, beat.body.get("text", ""), voice_id, model_id, settings, turns
113
144
  )
114
145
 
115
146
  full = TransformInputs(
@@ -180,18 +211,46 @@ class NarrationRenderTTS(BaseTransform):
180
211
  out_path.parent.mkdir(parents=True, exist_ok=True)
181
212
  # was_cached: mixing served this from its on-disk cache (no ElevenLabs call
182
213
  # = $0 real spend) even though our graph cache missed — braidio#8.
183
- _, was_cached = braidio.narrate(
184
- text,
185
- out_path,
186
- # The caller's key, if the driver handed one in (nw's `secrets=`
187
- # seam; thorwhalen/braidio#58) — else None, the process env. Never
188
- # persisted: not in the node, not in the cache_key.
189
- api_key=elevenlabs_key(secrets),
190
- voice_id=va.body.get("voice_id") or DEFAULT_VOICE_ID,
191
- model_id=model_id,
192
- voice_settings=_beat_settings(beat, config),
193
- return_cache_status=True,
194
- )
214
+ voice_id = va.body.get("voice_id") or DEFAULT_VOICE_ID
215
+ settings = _beat_settings(beat, config)
216
+ # The caller's key, if the driver handed one in (nw's `secrets=` seam;
217
+ # thorwhalen/braidio#58) — else None, the process env. Never persisted:
218
+ # not in the node, not in the cache_key.
219
+ api_key = elevenlabs_key(secrets)
220
+ turns = _beat_turns(beat, config, model_id=model_id, settings=settings)
221
+ if turns: # paced: one call per turn, real silence between (braidio#118)
222
+ cached: list[bool] = []
223
+
224
+ def synthesize(turn_text, turn_path, **kwargs):
225
+ path, hit = braidio.narrate(
226
+ turn_text, turn_path, return_cache_status=True, **kwargs
227
+ )
228
+ cached.append(hit)
229
+ return path
230
+
231
+ paced = narrate_turns(
232
+ turns,
233
+ stem=out_path.with_suffix(""),
234
+ api_key=api_key,
235
+ voice_id=voice_id,
236
+ model_id=model_id,
237
+ voice_settings=settings,
238
+ narrate_fn=synthesize,
239
+ )
240
+ shutil.move(paced, out_path)
241
+ for leftover in out_path.parent.glob(f"{skel.id}-turn*"):
242
+ leftover.unlink() # per-turn parts and gaps: only the mix is a node
243
+ was_cached = all(cached)
244
+ else:
245
+ _, was_cached = braidio.narrate(
246
+ text,
247
+ out_path,
248
+ api_key=api_key,
249
+ voice_id=voice_id,
250
+ model_id=model_id,
251
+ voice_settings=settings,
252
+ return_cache_status=True,
253
+ )
195
254
  duration = safe_duration(out_path)
196
255
  artifact = audio_artifact(
197
256
  out_path,
@@ -32,6 +32,7 @@ from braidio.tts import resolve_voice_id
32
32
  from braidio.weave_config import WeaveConfig
33
33
  from braidio.transforms._common import (
34
34
  TIER_VOICE_ASSIGNMENT,
35
+ beat_ordinal,
35
36
  fresh_equivalent,
36
37
  singleton,
37
38
  )
@@ -53,7 +54,7 @@ class BeatToVoiceAssignment(BaseTransform):
53
54
  beat = inputs.primary[0]
54
55
  cfg = singleton(project, "weave-configs")
55
56
  config = WeaveConfig.from_snapshot(cfg.body.get("config", {}))
56
- ordinal = int(beat.body.get("beat_id", "0") or 0)
57
+ ordinal = beat_ordinal(beat)
57
58
  # the beat's own override, else the pool — the fast path's rule exactly
58
59
  voice_id = config.cast_voice(
59
60
  ordinal, override=beat.body.get("voice")
@@ -6,7 +6,7 @@ build-backend = "hatchling.build"
6
6
 
7
7
  [project]
8
8
  name = "braidio"
9
- version = "0.0.76"
9
+ version = "0.0.78"
10
10
  description = "Weave narration with extracted media segments into audiovisual productions"
11
11
  readme = "README.md"
12
12
  requires-python = ">=3.10"
@@ -139,7 +139,7 @@ nw-app = ["lacing", "nw>=0.0.65", "falaw[fal]"]
139
139
  # older dol without it.
140
140
  # nw>=0.0.58: see the nw-app note above (the `secrets=` seam, braidio#58; the
141
141
  # asset-ref declarations `braidio.transforms` makes on import, nw#55).
142
- mcp = ["fastmcp", "py2mcp>=0.1.9", "pypdf", "dol>=0.3.57", "lacing", "nw>=0.0.65", "falaw[fal]", "yb[download]>=0.1.7", "graze>=0.1.45", "markdown-it-py", "mdit-py-plugins"]
142
+ mcp = ["fastmcp", "py2mcp>=0.1.9", "pypdf", "dol>=0.3.57", "lacing", "nw>=0.0.65", "falaw[fal]", "yb[download]>=0.1.24", "graze>=0.1.45", "markdown-it-py", "mdit-py-plugins"]
143
143
  # The importer (`braidio.importing`): a finished commentary production ->
144
144
  # a real project graph. Needs the nw-app layer (it writes annotations) plus
145
145
  # `illustration` for licence normalization.