feat(editor): per-scene AI polish with mode picker + undo - #62
Merged
Merged
Conversation
The mode_refine LLM stage was wired into the pipeline run but invisible in the editor — once the draft was generated, the author had no way to ask "redo this scene with low fidelity / rich expansion" without regenerating the whole document. Exposes a per-scene polish toolbar that hits a new POST /api/v1/refine/scene endpoint. Backend: new endpoint deserializes the YAML, finds the scene by id, reconstructs the Scene / Beat / Character pydantic instances the existing ai_refine_scene_beats helper expects, and returns the refined beat list. 503 when no LLM provider is configured, 404 on unknown scene id, 422 on empty beats, 502 when the LLM call returns nothing usable (rule_fallback fired). Tests cover the four error paths without burning quota. Frontend: a dashed-bordered toolbar at the top of each scene with two selects (fidelity / expansion) + 润色场景 button + 撤销 button. The default (medium, balanced) mode disables the button because the backend would no-op it anyway. A polish snapshots the pre-polish YAML to a ref for one-level undo so the author can try a mode, hate it, and revert without losing their other edits. Beats are spliced back wholesale rather than per-beat patched — expansion=rich can change the beat count, so a positional patch would leave the YAML inconsistent. The full splice round-trips through js-yaml.dump to keep the file structurally clean. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
shanchuann
force-pushed
the
feat/scene-ai-polish
branch
from
June 7, 2026 09:28
d3ef3c1 to
43c3ab8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
功能描述
`mode_refine` 这个 LLM stage 之前只在改编时跑一次,作者改完想"让 AI 重新润色这一场"没有入口——只能整文档重跑。这版在编辑器场景头部加 AI 整体润色 toolbar:选 `保真度` × `扩写量` → 点 `润色场景` → 跑 `POST /api/v1/refine/scene` → 用结果替换该场景所有 beats。一键"撤销"回退到润色前。
实现思路
后端 `POST /api/v1/refine/scene`:
实现上:YAML→dict→挑出对应 scene→重建 Scene/Beat/Character pydantic 实例→喂给已有的 `ai_refine_scene_beats`。`Paragraph` 用 scene.summary 做一个 stub(refine prompt 主要用 beats + roster + summary,原始 paragraph 用不到)。
前端: