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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user