Replace Prompt Builder beats with complete set framings.
Sets are places with labeled full-text framings; selecting a framing copies only that text, and legacy beat-only sets migrate to a wide framing. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+105
-69
@@ -18,28 +18,26 @@ export type PromptSequenceCharacterState = {
|
||||
outfitId: string | null
|
||||
}
|
||||
|
||||
export type PromptSequenceShotSize = '' | 'wide' | 'medium' | 'close-up' | 'detail'
|
||||
/** Suggested labels only — not a hard enum. */
|
||||
export const PROMPT_SEQUENCE_FRAMING_SUGGESTIONS = ['wide', 'medium', 'narrow'] as const
|
||||
|
||||
export const PROMPT_SEQUENCE_SHOT_SIZES = ['wide', 'medium', 'close-up', 'detail'] as const
|
||||
|
||||
export type PromptSequenceBeat = {
|
||||
export type PromptSequenceFraming = {
|
||||
id: string
|
||||
name: string
|
||||
label: string
|
||||
text: string
|
||||
/** Empty = always include for any shot size. */
|
||||
framings: Array<'wide' | 'medium' | 'close-up' | 'detail'>
|
||||
}
|
||||
|
||||
export type PromptSequenceSet = {
|
||||
id: string
|
||||
name: string
|
||||
description: string
|
||||
beats: PromptSequenceBeat[]
|
||||
framings: PromptSequenceFraming[]
|
||||
}
|
||||
|
||||
export type PromptSequenceSetState = {
|
||||
setId: string
|
||||
on: boolean
|
||||
/** Chosen framing for this set in this scene (like outfitId). Empty = copy nothing. */
|
||||
framingId: string | null
|
||||
}
|
||||
|
||||
export type PromptSequenceScene = {
|
||||
@@ -47,7 +45,6 @@ export type PromptSequenceScene = {
|
||||
title: string
|
||||
style: string
|
||||
settings: string
|
||||
shotSize: PromptSequenceShotSize
|
||||
setStates: PromptSequenceSetState[]
|
||||
characterStates: PromptSequenceCharacterState[]
|
||||
prompt: string
|
||||
@@ -82,20 +79,20 @@ export function emptyCharacter(): PromptSequenceCharacter {
|
||||
return { id: newId(), name: '', description: '', outfits: [] }
|
||||
}
|
||||
|
||||
export function emptyBeat(): PromptSequenceBeat {
|
||||
return { id: newId(), name: '', text: '', framings: [] }
|
||||
export function emptyFraming(label = ''): PromptSequenceFraming {
|
||||
return { id: newId(), label, text: '' }
|
||||
}
|
||||
|
||||
export function emptySet(): PromptSequenceSet {
|
||||
return { id: newId(), name: '', description: '', beats: [emptyBeat()] }
|
||||
return { id: newId(), name: '', framings: [emptyFraming()] }
|
||||
}
|
||||
|
||||
export function defaultCharacterState(characterId: string, on = true): PromptSequenceCharacterState {
|
||||
return { characterId, on, outfitId: null }
|
||||
}
|
||||
|
||||
export function defaultSetState(setId: string, on = true): PromptSequenceSetState {
|
||||
return { setId, on }
|
||||
export function defaultSetState(setId: string, on = true, framingId: string | null = null): PromptSequenceSetState {
|
||||
return { setId, on, framingId }
|
||||
}
|
||||
|
||||
export function emptyScene(
|
||||
@@ -108,8 +105,7 @@ export function emptyScene(
|
||||
title: `Scene ${Math.max(1, index)}`,
|
||||
style: '',
|
||||
settings: '',
|
||||
shotSize: '',
|
||||
setStates: sets.map(set => defaultSetState(set.id, true)),
|
||||
setStates: sets.map(set => defaultSetState(set.id, true, null)),
|
||||
characterStates: characters.map(character => defaultCharacterState(character.id, true)),
|
||||
prompt: ''
|
||||
}
|
||||
@@ -121,10 +117,10 @@ export function cloneSceneForNext(previous: PromptSequenceScene, nextIndex: numb
|
||||
title: `Scene ${nextIndex}`,
|
||||
style: previous.style,
|
||||
settings: previous.settings,
|
||||
shotSize: previous.shotSize || '',
|
||||
setStates: (previous.setStates || []).map(state => ({
|
||||
setId: state.setId,
|
||||
on: !!state.on
|
||||
on: !!state.on,
|
||||
framingId: state.framingId || null
|
||||
})),
|
||||
characterStates: (previous.characterStates || []).map(state => ({
|
||||
characterId: state.characterId,
|
||||
@@ -160,19 +156,9 @@ export function formatCharacterLine(
|
||||
return `${base}. Outfit: ${outfitText}`
|
||||
}
|
||||
|
||||
export function beatMatchesShotSize(
|
||||
beat: { framings?: string[] },
|
||||
shotSize: string = ''
|
||||
) {
|
||||
const framings = Array.isArray(beat.framings) ? beat.framings.filter(Boolean) : []
|
||||
if (!framings.length) return true
|
||||
if (!shotSize) return true
|
||||
return framings.includes(shotSize)
|
||||
}
|
||||
|
||||
/** Set description + matching beat texts (one per line). No set/beat names or framing tags. */
|
||||
/** Selected framing text for each on set. No set name, no framing label. */
|
||||
export function assembleSetBlock(
|
||||
scene: { shotSize?: string; setStates?: PromptSequenceSetState[] },
|
||||
scene: { setStates?: PromptSequenceSetState[] },
|
||||
sets: PromptSequenceSet[] = []
|
||||
) {
|
||||
const states = scene.setStates || []
|
||||
@@ -181,13 +167,11 @@ export function assembleSetBlock(
|
||||
for (const set of sets) {
|
||||
const state = stateById.get(set.id)
|
||||
if (state && !state.on) continue
|
||||
const description = String(set.description || '').trim()
|
||||
const beatLines = (set.beats || [])
|
||||
.filter(beat => beatMatchesShotSize(beat, scene.shotSize || ''))
|
||||
.map(beat => String(beat.text || '').trim())
|
||||
.filter(Boolean)
|
||||
const lines = [description, ...beatLines].filter(Boolean)
|
||||
if (lines.length) chunks.push(lines.join('\n'))
|
||||
const framingId = state?.framingId || null
|
||||
if (!framingId) continue
|
||||
const framing = (set.framings || []).find(item => item.id === framingId)
|
||||
const text = String(framing?.text || '').trim()
|
||||
if (text) chunks.push(text)
|
||||
}
|
||||
return chunks.join('\n')
|
||||
}
|
||||
@@ -216,7 +200,6 @@ export function assembleSceneText(
|
||||
style?: string
|
||||
settings?: string
|
||||
prompt?: string
|
||||
shotSize?: string
|
||||
setStates?: PromptSequenceSetState[]
|
||||
characterStates?: PromptSequenceCharacterState[]
|
||||
/** Legacy per-scene characters (migration / old tests). */
|
||||
@@ -256,7 +239,6 @@ export function assembleSequenceText(sequence: {
|
||||
style?: string
|
||||
settings?: string
|
||||
prompt?: string
|
||||
shotSize?: string
|
||||
setStates?: PromptSequenceSetState[]
|
||||
characterStates?: PromptSequenceCharacterState[]
|
||||
characters?: Array<{ name?: string; description?: string }>
|
||||
@@ -287,12 +269,6 @@ export function normalizePromptSequenceTitle(raw: unknown, fallback: string) {
|
||||
return title || fallback
|
||||
}
|
||||
|
||||
export function normalizeShotSize(raw: unknown): PromptSequenceShotSize {
|
||||
const value = String(raw || '').trim()
|
||||
if (value === 'wide' || value === 'medium' || value === 'close-up' || value === 'detail') return value
|
||||
return ''
|
||||
}
|
||||
|
||||
export function normalizeOutfit(raw: unknown): PromptSequenceOutfit {
|
||||
const rec = (raw && typeof raw === 'object' ? raw : {}) as Record<string, unknown>
|
||||
return {
|
||||
@@ -313,29 +289,46 @@ export function normalizeCharacter(raw: unknown): PromptSequenceCharacter {
|
||||
}
|
||||
}
|
||||
|
||||
export function normalizeBeat(raw: unknown): PromptSequenceBeat {
|
||||
export function normalizeFraming(raw: unknown): PromptSequenceFraming {
|
||||
const rec = (raw && typeof raw === 'object' ? raw : {}) as Record<string, unknown>
|
||||
const framings = Array.isArray(rec.framings)
|
||||
? [...new Set(rec.framings.map(item => String(item || '').trim()).filter((item): item is 'wide' | 'medium' | 'close-up' | 'detail' =>
|
||||
item === 'wide' || item === 'medium' || item === 'close-up' || item === 'detail'
|
||||
))]
|
||||
: []
|
||||
return {
|
||||
id: String(rec.id || '').trim() || newId(),
|
||||
name: String(rec.name || '').trim().slice(0, 120),
|
||||
text: normalizePromptSequenceField(rec.text),
|
||||
framings
|
||||
label: String(rec.label || '').trim().slice(0, 120),
|
||||
text: normalizePromptSequenceField(rec.text)
|
||||
}
|
||||
}
|
||||
|
||||
/** Fold legacy beat-only sets into one framing labeled "wide". */
|
||||
function framingsFromLegacyBeats(rec: Record<string, unknown>): PromptSequenceFraming[] {
|
||||
const parts: string[] = []
|
||||
const description = normalizePromptSequenceField(rec.description).trim()
|
||||
if (description) parts.push(description)
|
||||
const beats = Array.isArray(rec.beats) ? rec.beats : []
|
||||
for (const beat of beats) {
|
||||
if (!beat || typeof beat !== 'object') continue
|
||||
const text = normalizePromptSequenceField((beat as Record<string, unknown>).text).trim()
|
||||
if (text) parts.push(text)
|
||||
}
|
||||
if (!parts.length) return [emptyFraming()]
|
||||
return [{ id: newId(), label: 'wide', text: parts.join('\n') }]
|
||||
}
|
||||
|
||||
export function normalizeSet(raw: unknown): PromptSequenceSet {
|
||||
const rec = (raw && typeof raw === 'object' ? raw : {}) as Record<string, unknown>
|
||||
const beats = Array.isArray(rec.beats) ? rec.beats.map(normalizeBeat) : []
|
||||
let framings: PromptSequenceFraming[]
|
||||
if (Array.isArray(rec.framings) && rec.framings.length) {
|
||||
framings = rec.framings.map(normalizeFraming)
|
||||
} else if (Array.isArray(rec.beats) && rec.beats.length) {
|
||||
framings = framingsFromLegacyBeats(rec)
|
||||
} else if (String(rec.description || '').trim()) {
|
||||
framings = framingsFromLegacyBeats(rec)
|
||||
} else {
|
||||
framings = [emptyFraming()]
|
||||
}
|
||||
return {
|
||||
id: String(rec.id || '').trim() || newId(),
|
||||
name: String(rec.name || '').trim().slice(0, 120),
|
||||
description: normalizePromptSequenceField(rec.description),
|
||||
beats: beats.length ? beats : [emptyBeat()]
|
||||
framings
|
||||
}
|
||||
}
|
||||
|
||||
@@ -351,11 +344,30 @@ export function normalizeCharacterState(raw: unknown, fallbackCharacterId = ''):
|
||||
}
|
||||
}
|
||||
|
||||
export function normalizeSetState(raw: unknown, fallbackSetId = ''): PromptSequenceSetState {
|
||||
export function normalizeSetState(
|
||||
raw: unknown,
|
||||
fallbackSetId = '',
|
||||
sets: PromptSequenceSet[] = [],
|
||||
legacyShotSize = ''
|
||||
): PromptSequenceSetState {
|
||||
const rec = (raw && typeof raw === 'object' ? raw : {}) as Record<string, unknown>
|
||||
const setId = String(rec.setId || fallbackSetId || '').trim()
|
||||
const framingRaw = rec.framingId
|
||||
let framingId = framingRaw == null || framingRaw === '' ? null : String(framingRaw).trim() || null
|
||||
const set = sets.find(item => item.id === setId)
|
||||
if (framingId && set && !set.framings.some(framing => framing.id === framingId)) {
|
||||
framingId = null
|
||||
}
|
||||
if (!framingId && legacyShotSize && set) {
|
||||
const match = set.framings.find(
|
||||
framing => framing.label.trim().toLowerCase() === legacyShotSize.trim().toLowerCase()
|
||||
)
|
||||
if (match) framingId = match.id
|
||||
}
|
||||
return {
|
||||
setId: String(rec.setId || fallbackSetId || '').trim(),
|
||||
on: rec.on === undefined ? true : !!rec.on
|
||||
setId,
|
||||
on: rec.on === undefined ? true : !!rec.on,
|
||||
framingId
|
||||
}
|
||||
}
|
||||
|
||||
@@ -400,16 +412,32 @@ function syncCharacterStates(
|
||||
function syncSetStates(
|
||||
statesRaw: unknown,
|
||||
sets: PromptSequenceSet[],
|
||||
defaultOn = true
|
||||
defaultOn = true,
|
||||
legacyShotSize = ''
|
||||
): PromptSequenceSetState[] {
|
||||
const incoming = Array.isArray(statesRaw)
|
||||
? statesRaw.map(state => normalizeSetState(state)).filter(state => state.setId)
|
||||
? statesRaw.map(state => normalizeSetState(state, '', sets, legacyShotSize)).filter(state => state.setId)
|
||||
: []
|
||||
const byId = new Map(incoming.map(state => [state.setId, state]))
|
||||
return sets.map((set) => {
|
||||
const existing = byId.get(set.id)
|
||||
if (existing) return { setId: set.id, on: existing.on }
|
||||
return defaultSetState(set.id, defaultOn)
|
||||
if (existing) {
|
||||
const framingOk = existing.framingId
|
||||
&& set.framings.some(framing => framing.id === existing.framingId)
|
||||
return {
|
||||
setId: set.id,
|
||||
on: existing.on,
|
||||
framingId: framingOk ? existing.framingId : null
|
||||
}
|
||||
}
|
||||
let framingId: string | null = null
|
||||
if (legacyShotSize) {
|
||||
const match = set.framings.find(
|
||||
framing => framing.label.trim().toLowerCase() === legacyShotSize.trim().toLowerCase()
|
||||
)
|
||||
if (match) framingId = match.id
|
||||
}
|
||||
return defaultSetState(set.id, defaultOn, framingId)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -420,13 +448,13 @@ export function normalizeScene(
|
||||
sets: PromptSequenceSet[] = []
|
||||
): PromptSequenceScene {
|
||||
const rec = (raw && typeof raw === 'object' ? raw : {}) as Record<string, unknown>
|
||||
const legacyShotSize = String(rec.shotSize || '').trim()
|
||||
return {
|
||||
id: String(rec.id || '').trim() || newId(),
|
||||
title: normalizePromptSequenceTitle(rec.title, `Scene ${index + 1}`),
|
||||
style: normalizePromptSequenceField(rec.style),
|
||||
settings: normalizePromptSequenceField(rec.settings),
|
||||
shotSize: normalizeShotSize(rec.shotSize),
|
||||
setStates: syncSetStates(rec.setStates, sets, true),
|
||||
setStates: syncSetStates(rec.setStates, sets, true, legacyShotSize),
|
||||
characterStates: syncCharacterStates(rec.characterStates, characters, true),
|
||||
prompt: normalizePromptSequenceField(rec.prompt)
|
||||
}
|
||||
@@ -493,11 +521,19 @@ export function ensureSceneStatesForSets(
|
||||
const byId = new Map((scene.setStates || []).map(state => [state.setId, state]))
|
||||
scene.setStates = sets.map((set) => {
|
||||
const existing = byId.get(set.id)
|
||||
if (existing) return existing
|
||||
if (existing) {
|
||||
const framingOk = existing.framingId
|
||||
&& set.framings.some(framing => framing.id === existing.framingId)
|
||||
return {
|
||||
setId: set.id,
|
||||
on: existing.on,
|
||||
framingId: framingOk ? existing.framingId : null
|
||||
}
|
||||
}
|
||||
const on = newSetId && set.id === newSetId
|
||||
? i === turnOnIndex
|
||||
: true
|
||||
return defaultSetState(set.id, on)
|
||||
return defaultSetState(set.id, on, null)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user