Bind permanence stills to named lock keys instead of coded categories.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+27
-15
@@ -1,7 +1,3 @@
|
||||
export const PERMANENCE_REF_LABELS = ['Subject', 'Vehicle', 'Interior', 'Object'] as const
|
||||
|
||||
export type PermanenceRefLabel = (typeof PERMANENCE_REF_LABELS)[number]
|
||||
|
||||
export interface PermanenceRef {
|
||||
stillId: string
|
||||
label: string
|
||||
@@ -9,8 +5,6 @@ export interface PermanenceRef {
|
||||
|
||||
export const DEFAULT_GLOBAL_LOCKS = `[GLOBAL LOCKS]
|
||||
Subject:
|
||||
Vehicle:
|
||||
Interior:
|
||||
Object:
|
||||
Extras:
|
||||
Camera:
|
||||
@@ -18,7 +12,28 @@ Speech:
|
||||
Never:
|
||||
State:`
|
||||
|
||||
const LOCK_FIELD = /^(Subject|Vehicle|Interior|Object|Extras|Camera|Speech|Never|State)\s*:?\s*/i
|
||||
const KNOWN_LOCK_KEYS = 'Subject|Vehicle|Interior|Object|Extras|Camera|Speech|Never|State'
|
||||
const LOCK_FIELD = new RegExp(`^(?:(?:${KNOWN_LOCK_KEYS})\\s*:?|[A-Za-z][A-Za-z0-9 _-]{0,22}\\s*:)\\s*`, 'i')
|
||||
const LOCK_KEY_LINE = /^([A-Za-z][A-Za-z0-9 _-]{0,22})\s*:/
|
||||
const SKIP_BINDING_KEYS = /^(speech|never|state)$/i
|
||||
|
||||
export function parseLockBindingKeys(text: string): string[] {
|
||||
const keys: string[] = []
|
||||
const seen = new Set<string>()
|
||||
for (const line of String(text || '').replace(/\r\n/g, '\n').split('\n')) {
|
||||
const trimmed = line.trim()
|
||||
if (!trimmed || trimmed.startsWith('[')) continue
|
||||
const match = trimmed.match(LOCK_KEY_LINE)
|
||||
if (!match) continue
|
||||
const key = match[1].replace(/\s+/g, ' ').trim()
|
||||
if (!key || SKIP_BINDING_KEYS.test(key)) continue
|
||||
const id = key.toLowerCase()
|
||||
if (seen.has(id)) continue
|
||||
seen.add(id)
|
||||
keys.push(key)
|
||||
}
|
||||
return keys
|
||||
}
|
||||
|
||||
export function normalizePermanenceRefs(raw: unknown, limit = 8): PermanenceRef[] {
|
||||
if (!Array.isArray(raw)) return []
|
||||
@@ -36,15 +51,12 @@ export function normalizePermanenceRefs(raw: unknown, limit = 8): PermanenceRef[
|
||||
}
|
||||
|
||||
export function sanitizeRefLabel(raw: unknown) {
|
||||
const label = String(raw || '').trim().slice(0, 24)
|
||||
if (!label) return 'Object'
|
||||
const match = PERMANENCE_REF_LABELS.find(item => item.toLowerCase() === label.toLowerCase())
|
||||
return match || label
|
||||
return String(raw || '').replace(/\s+/g, ' ').trim().slice(0, 24)
|
||||
}
|
||||
|
||||
export function nextPermanenceLabel(existing: PermanenceRef[]) {
|
||||
const used = new Set(existing.map(item => item.label))
|
||||
return PERMANENCE_REF_LABELS.find(label => !used.has(label)) || 'Object'
|
||||
export function nextPermanenceLabel(existing: PermanenceRef[], lockKeys: string[] = []) {
|
||||
const used = new Set(existing.map(item => item.label.trim().toLowerCase()).filter(Boolean))
|
||||
return lockKeys.find(key => !used.has(key.trim().toLowerCase())) || ''
|
||||
}
|
||||
|
||||
export function mergePermanenceRefs(family?: PermanenceRef[] | null, shot?: PermanenceRef[] | null) {
|
||||
@@ -90,7 +102,7 @@ export function resolveGlobalLocks(locks: string, firstPrompt: string) {
|
||||
}
|
||||
|
||||
function extractState(locks: string) {
|
||||
const match = String(locks || '').match(/(?:^|\n)\s*State:\s*(.+?)(?=\n\s*(?:Subject|Vehicle|Interior|Object|Extras|Camera|Speech|Never)\s*:|\n\s*\[|$)/is)
|
||||
const match = String(locks || '').match(/(?:^|\n)\s*State:\s*(.+?)(?=\n\s*[A-Za-z][A-Za-z0-9 _-]{0,22}\s*:|\n\s*\[|$)/is)
|
||||
return String(match?.[1] || '').replace(/\s+/g, ' ').trim()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user