|
| 1 | +/** |
| 2 | + * Shot → prompt composition. |
| 3 | + * |
| 4 | + * One pure module so the editor (`useGenerateShot`) and the headless render |
| 5 | + * capabilities (`render_storyboard_stills`, `render_storyboard_clips`) send the |
| 6 | + * same words to the same model. A prompt that differs between the two surfaces |
| 7 | + * makes a board impossible to reason about: the same shot would come back |
| 8 | + * looking different depending on who pressed render. |
| 9 | + * |
| 10 | + * The field → mode mapping is the contract (PRD § 7.7.5): |
| 11 | + * |
| 12 | + * | Field | Still | Clip (keyframe) | Clip (direct) | |
| 13 | + * | ------------------ | ---------------- | --------------- | --------------- | |
| 14 | + * | `action` | yes | yes | yes | |
| 15 | + * | `camera.framing` | `<framing> shot` | — | `<framing> shot`| |
| 16 | + * | `camera.angle` | yes | — | yes | |
| 17 | + * | `camera.lens` | `<lens> lens` | — | `<lens> lens` | |
| 18 | + * | scene `lighting` | yes | — | yes | |
| 19 | + * | `motion` | — | yes | yes | |
| 20 | + * | `camera.movement` | — | yes | yes | |
| 21 | + * | `camera.equipment` | — | yes | yes | |
| 22 | + * | board `style` | yes | — | yes | |
| 23 | + * |
| 24 | + * A keyframe-mode clip animates a still that already carries framing, lens, |
| 25 | + * lighting and style, so repeating them in the video prompt only fights the |
| 26 | + * first-frame conditioning. A direct clip has no still, so it carries |
| 27 | + * everything. |
| 28 | + * |
| 29 | + * `dialogue`, `notes` and `duration_seconds` never enter a prompt: the first |
| 30 | + * two are words for people, the third is a render parameter. |
| 31 | + * |
| 32 | + * Entity seasoning is not here — the two surfaces pass entities differently |
| 33 | + * (the editor appends `entity://` tokens for the server to expand, the |
| 34 | + * capabilities send a structured `entities` param), and both start from |
| 35 | + * `entitiesForShot`. |
| 36 | + */ |
| 37 | + |
| 38 | +import type { Scene, Shot } from "./creative.js"; |
| 39 | + |
| 40 | +/** What a prompt needs beyond the shot itself. */ |
| 41 | +export interface ShotPromptContext { |
| 42 | + /** The shot's scene, when it has one. Supplies `lighting`. */ |
| 43 | + scene?: Scene | null; |
| 44 | + /** The board's style descriptor, applied to every shot. */ |
| 45 | + style?: string; |
| 46 | +} |
| 47 | + |
| 48 | +/** Trimmed, comma-separated, empties dropped. */ |
| 49 | +const compose = (parts: (string | undefined | null)[]): string => |
| 50 | + parts |
| 51 | + .map((part) => (part ?? "").trim()) |
| 52 | + .filter((part) => part.length > 0) |
| 53 | + .join(", "); |
| 54 | + |
| 55 | +/** `"85mm"` + `"lens"` → `"85mm lens"`, so the model reads it as direction. */ |
| 56 | +const qualified = ( |
| 57 | + value: string | undefined, |
| 58 | + noun: string |
| 59 | +): string | undefined => { |
| 60 | + const trimmed = (value ?? "").trim(); |
| 61 | + return trimmed.length > 0 ? `${trimmed} ${noun}` : undefined; |
| 62 | +}; |
| 63 | + |
| 64 | +/** |
| 65 | + * The scene a shot belongs to, or null when it has none (legacy shots) or the |
| 66 | + * scene has been dropped. Both render surfaces need it to reach `lighting`. |
| 67 | + */ |
| 68 | +export function sceneForShot( |
| 69 | + shot: Shot, |
| 70 | + scenes?: readonly Scene[] | null |
| 71 | +): Scene | null { |
| 72 | + if (!shot.scene_id || !scenes) { |
| 73 | + return null; |
| 74 | + } |
| 75 | + return scenes.find((scene) => scene.id === shot.scene_id) ?? null; |
| 76 | +} |
| 77 | + |
| 78 | +/** Still prompt: what is in frame, how it is shot, how it is lit, the look. */ |
| 79 | +export function keyframePrompt( |
| 80 | + shot: Shot, |
| 81 | + context: ShotPromptContext = {} |
| 82 | +): string { |
| 83 | + const camera = shot.camera; |
| 84 | + return compose([ |
| 85 | + shot.action, |
| 86 | + qualified(camera?.framing, "shot"), |
| 87 | + camera?.angle, |
| 88 | + qualified(camera?.lens, "lens"), |
| 89 | + context.scene?.lighting, |
| 90 | + context.style |
| 91 | + ]); |
| 92 | +} |
| 93 | + |
| 94 | +/** |
| 95 | + * Keyframe-mode clip prompt: what moves, what is in frame, and how the camera |
| 96 | + * moves. Framing, lighting and style come from the still being animated, so |
| 97 | + * they are deliberately absent — this takes no context. |
| 98 | + */ |
| 99 | +export function clipPrompt(shot: Shot): string { |
| 100 | + const camera = shot.camera; |
| 101 | + return compose([ |
| 102 | + shot.motion, |
| 103 | + shot.action, |
| 104 | + camera?.movement, |
| 105 | + camera?.equipment |
| 106 | + ]); |
| 107 | +} |
| 108 | + |
| 109 | +/** |
| 110 | + * Direct-mode clip prompt: no still carries the look into the render, so the |
| 111 | + * prompt carries all of it — the still's fields plus the motion ones. |
| 112 | + */ |
| 113 | +export function directClipPrompt( |
| 114 | + shot: Shot, |
| 115 | + context: ShotPromptContext = {} |
| 116 | +): string { |
| 117 | + const camera = shot.camera; |
| 118 | + return compose([ |
| 119 | + shot.action, |
| 120 | + qualified(camera?.framing, "shot"), |
| 121 | + camera?.angle, |
| 122 | + qualified(camera?.lens, "lens"), |
| 123 | + context.scene?.lighting, |
| 124 | + shot.motion, |
| 125 | + camera?.movement, |
| 126 | + camera?.equipment, |
| 127 | + context.style |
| 128 | + ]); |
| 129 | +} |
0 commit comments