Give video extensions the same pre-text, prompt, and post-text fields as the main form.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Towsty
2026-09-02 15:01:20 -05:00
co-authored by Cursor
parent c4e18eeb2c
commit e7298d9693
11 changed files with 195 additions and 83 deletions
+40
View File
@@ -36,6 +36,46 @@ export function restorePromptParts(saved: string, stored?: Partial<PromptParts>
}
}
export type PromptWrapperFields = {
promptPre?: string
promptPost?: string
}
function hasWrapperKey(item: object | null | undefined, key: 'promptPre' | 'promptPost') {
return Boolean(item && Object.prototype.hasOwnProperty.call(item, key))
}
/** First source that actually sent the key wins, including empty string. Omitted keys fall through. */
export function resolvePromptWrappers(
...sources: Array<PromptWrapperFields | null | undefined>
) {
let promptPre = ''
let promptPost = ''
let sawPre = false
let sawPost = false
for (const source of sources) {
if (!source) continue
if (!sawPre && hasWrapperKey(source, 'promptPre') && source.promptPre != null) {
promptPre = sanitizePromptPart(source.promptPre)
sawPre = true
}
if (!sawPost && hasWrapperKey(source, 'promptPost') && source.promptPost != null) {
promptPost = sanitizePromptPart(source.promptPost)
sawPost = true
}
if (sawPre && sawPost) break
}
return { promptPre, promptPost }
}
export function persistPromptWrappers(item?: PromptWrapperFields | null): PromptWrapperFields {
if (!item) return {}
const next: PromptWrapperFields = {}
if (hasWrapperKey(item, 'promptPre') && item.promptPre != null) next.promptPre = sanitizePromptPart(item.promptPre)
if (hasWrapperKey(item, 'promptPost') && item.promptPost != null) next.promptPost = sanitizePromptPart(item.promptPost)
return next
}
export function formatPromptParts(
stored?: { prompt?: string; promptPre?: string; promptPost?: string } | null,
midOverride?: string