Split prompts into pre/prompt/post and tidy the AIGen video form.
Keep wrappers off the library mid-prompt so Use as input and Extend restore the same split, send stills to xAIGen as hidden inputs, and stop the two-column library from growing with the list. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -34,6 +34,8 @@ export default defineEventHandler(async (event) => {
|
||||
}
|
||||
|
||||
const prompt = (fields.prompt || '').trim()
|
||||
const promptPre = (fields.promptPre || '').trim()
|
||||
const promptPost = (fields.promptPost || '').trim()
|
||||
const extraPasses = parsePasses(fields.passes)
|
||||
const passMode = parseImagePassMode(fields.passMode)
|
||||
const aspect = parseImageAspect(fields.aspect)
|
||||
@@ -127,6 +129,8 @@ export default defineEventHandler(async (event) => {
|
||||
kind: 'edit',
|
||||
payload: {
|
||||
prompt,
|
||||
promptPre: promptPre || undefined,
|
||||
promptPost: promptPost || undefined,
|
||||
name: clipName,
|
||||
folderId,
|
||||
aspect,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { copyFileSync, existsSync, readFileSync } from 'node:fs'
|
||||
import { join } from 'node:path'
|
||||
import { composeShotPrompt } from '~/utils/globalLocks'
|
||||
import { composePromptParts } from '~/utils/promptParts'
|
||||
import { parsePostedLoraStack, listStudioLoras, persistLoraFields, ensureComfyLoraNames } from '~/server/utils/loras'
|
||||
import { readLoraStack } from '~/utils/loras'
|
||||
import { clampVideoCfg } from '~/utils/generationPresets'
|
||||
@@ -39,7 +40,7 @@ function parseScheduler(raw: unknown) {
|
||||
}
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const body = await readBody<{ clipId?: string; prompt?: string; duration?: number; lora?: unknown; loraStack?: unknown }>(event).catch(() => ({}))
|
||||
const body = await readBody<{ clipId?: string; prompt?: string; promptPre?: string; promptPost?: string; duration?: number; lora?: unknown; loraStack?: unknown }>(event).catch(() => ({}))
|
||||
const clipId = String(body?.clipId || '').trim()
|
||||
const prompt = String(body?.prompt || '').trim()
|
||||
if (!clipId) {
|
||||
@@ -60,9 +61,11 @@ export default defineEventHandler(async (event) => {
|
||||
const destFolder = publicLibrary(event).folders.find(folder => folder.id === source.folderId)
|
||||
const folderLocked = Boolean(destFolder?.protected && !destFolder.unlocked)
|
||||
const durationSeconds = parseExtendDuration(body?.duration)
|
||||
const promptPre = String(body?.promptPre ?? source.promptPre ?? '').trim()
|
||||
const promptPost = String(body?.promptPost ?? source.promptPost ?? '').trim()
|
||||
const composedPrompt = composeShotPrompt({
|
||||
globalLocks: source.globalLocks,
|
||||
prompt,
|
||||
prompt: composePromptParts(promptPre, prompt, promptPost),
|
||||
shotIndex: (source.chainIndex || 0) + 1,
|
||||
familyRefs: source.permanenceRefs
|
||||
})
|
||||
@@ -99,7 +102,10 @@ export default defineEventHandler(async (event) => {
|
||||
hideThumbnail: source.hideThumbnail,
|
||||
folderLocked,
|
||||
name: clipName,
|
||||
prompt: composedPrompt,
|
||||
prompt,
|
||||
promptMid: prompt,
|
||||
promptPre: promptPre || undefined,
|
||||
promptPost: promptPost || undefined,
|
||||
aspect: source.aspect || '16:9',
|
||||
width,
|
||||
height,
|
||||
|
||||
@@ -5,6 +5,7 @@ import type { LoraStackItem } from '~/utils/loras'
|
||||
import { clampVideoCfg } from '~/utils/generationPresets'
|
||||
import { defaultVideoSteps, isLtxWorkflow, isTextToVideo, LTX_DISABLED_MESSAGE, ltxWorkflowEnabled, parseVideoWorkflow, videoEngineOf } from '~/utils/videoModels'
|
||||
import { allowIdentityRefs, normalizePermanenceRefs, resolveGlobalLocks, type PermanenceRef } from '~/utils/globalLocks'
|
||||
import { composePromptParts } from '~/utils/promptParts'
|
||||
|
||||
function parseDuration(raw: unknown) {
|
||||
const seconds = Number(raw)
|
||||
@@ -137,11 +138,13 @@ export default defineEventHandler(async (event) => {
|
||||
if (!image && !textToVideo) {
|
||||
throw createError({ statusCode: 400, statusMessage: 'An initial image is required' })
|
||||
}
|
||||
const promptRaw = (fields.prompt || '').trim()
|
||||
if (!promptRaw) {
|
||||
const promptMid = (fields.prompt || '').trim()
|
||||
const promptPre = (fields.promptPre || '').trim()
|
||||
const promptPost = (fields.promptPost || '').trim()
|
||||
if (!composePromptParts(promptPre, promptMid, promptPost)) {
|
||||
throw createError({ statusCode: 400, statusMessage: 'A motion prompt is required' })
|
||||
}
|
||||
const resolvedLocks = resolveGlobalLocks(fields.globalLocks || '', promptRaw)
|
||||
const resolvedLocks = resolveGlobalLocks(fields.globalLocks || '', promptMid)
|
||||
const prompt = resolvedLocks.prompt
|
||||
const globalLocks = resolvedLocks.locks
|
||||
const extensions = parseExtensions(fields.extensions)
|
||||
@@ -243,6 +246,9 @@ export default defineEventHandler(async (event) => {
|
||||
familyId,
|
||||
payload: {
|
||||
prompt,
|
||||
promptMid: promptMid || undefined,
|
||||
promptPre: promptPre || undefined,
|
||||
promptPost: promptPost || undefined,
|
||||
name: clipName,
|
||||
folderId,
|
||||
aspect: fields.aspect || 'auto',
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
import { passwordAuthEnabled, privateInstanceId } from '~/server/utils/localAuth'
|
||||
import { saveStill } from '~/server/utils/library'
|
||||
|
||||
function ingestOwner() {
|
||||
if (passwordAuthEnabled()) return privateInstanceId()
|
||||
return 'local'
|
||||
}
|
||||
|
||||
function assertIngestToken(event: Parameters<typeof getHeader>[0]) {
|
||||
const expected = String(useRuntimeConfig().backupIngestToken || process.env.BACKUP_INGEST_TOKEN || '').trim()
|
||||
if (!expected) {
|
||||
throw createError({ statusCode: 503, statusMessage: 'Backup ingest is not configured' })
|
||||
}
|
||||
const header = String(getHeader(event, 'authorization') || '')
|
||||
if (header !== `Bearer ${expected}`) {
|
||||
throw createError({ statusCode: 401, statusMessage: 'Unauthorized' })
|
||||
}
|
||||
}
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
assertIngestToken(event)
|
||||
const form = await readMultipartFormData(event)
|
||||
if (!form?.length) throw createError({ statusCode: 400, statusMessage: 'Expected an image upload' })
|
||||
const fields: Record<string, string> = {}
|
||||
let image: { filename: string; data: Buffer } | null = null
|
||||
for (const part of form) {
|
||||
if (part.name === 'image' && part.filename && part.data?.length) {
|
||||
image = { filename: part.filename, data: part.data }
|
||||
} else if (part.name && part.data) {
|
||||
fields[part.name] = part.data.toString('utf8')
|
||||
}
|
||||
}
|
||||
if (!image) throw createError({ statusCode: 400, statusMessage: 'An image is required' })
|
||||
const owner = ingestOwner()
|
||||
const still = await saveStill({
|
||||
ownerKey: owner,
|
||||
folderId: 'inbox',
|
||||
filename: image.filename,
|
||||
data: image.data,
|
||||
width: Number(fields.width || 0),
|
||||
height: Number(fields.height || 0),
|
||||
hideInput: true,
|
||||
role: 'input',
|
||||
name: (fields.name || '').trim().slice(0, 80) || undefined
|
||||
})
|
||||
if (!still) throw createError({ statusCode: 400, statusMessage: 'Backup studio already has that still' })
|
||||
return { ok: true, id: still.id }
|
||||
})
|
||||
@@ -0,0 +1,38 @@
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { isXaigenStudio } from '~/utils/videoModels'
|
||||
import { assertLibraryOwner, getStill, stillPath } from '~/server/utils/library'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
if (isXaigenStudio()) {
|
||||
throw createError({ statusCode: 404, statusMessage: 'Not found' })
|
||||
}
|
||||
const config = useRuntimeConfig()
|
||||
const url = String(config.backupStudioUrl || process.env.BACKUP_STUDIO_URL || '').replace(/\/$/, '')
|
||||
const token = String(config.backupStudioToken || process.env.BACKUP_STUDIO_TOKEN || '').trim()
|
||||
if (!url || !token) {
|
||||
throw createError({ statusCode: 503, statusMessage: 'Backup studio is not configured' })
|
||||
}
|
||||
const { owner } = assertLibraryOwner(event)
|
||||
const id = String(getRouterParam(event, 'id') || '')
|
||||
const still = getStill(owner, id)
|
||||
const path = stillPath(owner, still.id)
|
||||
const data = readFileSync(path)
|
||||
const body = new FormData()
|
||||
body.append('image', new Blob([Uint8Array.from(data)]), still.filename || 'still.png')
|
||||
body.append('name', still.name || still.filename || 'still')
|
||||
body.append('width', String(still.width || 0))
|
||||
body.append('height', String(still.height || 0))
|
||||
const res = await fetch(`${url}/api/library/backup-ingest`, {
|
||||
method: 'POST',
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
body
|
||||
})
|
||||
if (!res.ok) {
|
||||
const message = await res.text().catch(() => '')
|
||||
throw createError({
|
||||
statusCode: res.status === 401 ? 502 : res.status,
|
||||
statusMessage: message || 'Backup studio refused the still'
|
||||
})
|
||||
}
|
||||
return { ok: true }
|
||||
})
|
||||
@@ -136,6 +136,8 @@ export default defineEventHandler(async (event) => {
|
||||
mode === 'generate' ? 't2i' : mode === 'refine' ? 'refine' : 'scene'
|
||||
)
|
||||
const prompt = String(fields.prompt || '').trim()
|
||||
const promptPre = String(fields.promptPre || '').trim()
|
||||
const promptPost = String(fields.promptPost || '').trim()
|
||||
const extraPasses = parsePasses(fields.passes)
|
||||
const passMode = parseImagePassMode(fields.passMode)
|
||||
const aspect = parseImageAspect(fields.aspect)
|
||||
@@ -305,6 +307,8 @@ export default defineEventHandler(async (event) => {
|
||||
kind: 'edit',
|
||||
payload: {
|
||||
prompt,
|
||||
promptPre: promptPre || undefined,
|
||||
promptPost: promptPost || undefined,
|
||||
name: clipName,
|
||||
folderId,
|
||||
aspect: mode === 'generate' ? generateSize.aspect : aspect,
|
||||
|
||||
@@ -8,6 +8,7 @@ import { imageDimensions } from '~/server/utils/resolution'
|
||||
import { emitChainJob } from '~/server/utils/watch'
|
||||
import { saveStill, stillChainName } from '~/server/utils/library'
|
||||
import { comfyJobPrefix } from '~/utils/outputNames'
|
||||
import { composePromptParts } from '~/utils/promptParts'
|
||||
|
||||
export type EditImageFile = { filename: string; data: Buffer; type?: string }
|
||||
|
||||
@@ -66,7 +67,8 @@ export async function runEdit(job: Job, params: EditRunParams) {
|
||||
for (let index = 0; index < prompts.length; index++) {
|
||||
if (job.status === 'cancelled') throw new Error('Job interrupted.')
|
||||
if (index > 0 && library.stopAfterCurrent === true) break
|
||||
const prompt = (batch || index === 0) ? composeFillPrompt(prompts[index], filled.padded) : prompts[index]
|
||||
const mid = (batch || index === 0) ? composeFillPrompt(prompts[index], filled.padded) : prompts[index]
|
||||
const prompt = composePromptParts(library.promptPre || '', mid, library.promptPost || '')
|
||||
const last = index === prompts.length - 1
|
||||
if (index > 0) {
|
||||
await ensureComfyReady((status) => {
|
||||
@@ -79,7 +81,7 @@ export async function runEdit(job: Job, params: EditRunParams) {
|
||||
}, { skipBusyWait: true })
|
||||
}
|
||||
const seed = index === 0 ? params.seed : Math.floor(Math.random() * 2_147_483_647)
|
||||
library.prompt = prompt
|
||||
library.prompt = mid
|
||||
library.seed = seed
|
||||
library.chainIndex = index
|
||||
library.chainStep = index + 1
|
||||
@@ -164,7 +166,9 @@ export async function runEdit(job: Job, params: EditRunParams) {
|
||||
hideInput: job.hideThumbnail === true,
|
||||
role: 'output',
|
||||
name: passName || undefined,
|
||||
prompt,
|
||||
prompt: mid,
|
||||
promptPre: library.promptPre,
|
||||
promptPost: library.promptPost,
|
||||
familyId: library.familyId,
|
||||
parentStillId: batch ? library.stillId : parentStillId,
|
||||
chainIndex: index,
|
||||
|
||||
@@ -8,6 +8,7 @@ import { imageDimensions } from '~/server/utils/resolution'
|
||||
import { emitChainJob } from '~/server/utils/watch'
|
||||
import { saveStill, stillChainName } from '~/server/utils/library'
|
||||
import { comfyJobPrefix } from '~/utils/outputNames'
|
||||
import { composePromptParts } from '~/utils/promptParts'
|
||||
import { parseImageV2Engine, type ImageV2Engine, type ImageV2Mode, type ImageV2Task } from '~/utils/imageV2'
|
||||
import type { EditImageFile } from '~/server/utils/imageChain'
|
||||
|
||||
@@ -194,7 +195,7 @@ export async function runEditV2(job: Job, params: EditV2RunParams) {
|
||||
mode: params.mode,
|
||||
engine,
|
||||
task: params.task,
|
||||
prompt,
|
||||
prompt: composePromptParts(library.promptPre || '', prompt, library.promptPost || ''),
|
||||
negative: params.negative,
|
||||
imageAName: uploaded?.name,
|
||||
imageBName: uploadedRef?.name,
|
||||
@@ -264,6 +265,8 @@ export async function runEditV2(job: Job, params: EditV2RunParams) {
|
||||
role: 'output',
|
||||
name: passName || undefined,
|
||||
prompt,
|
||||
promptPre: library.promptPre,
|
||||
promptPost: library.promptPost,
|
||||
familyId: library.familyId,
|
||||
parentStillId: batch ? (params.sourceStillId || library.stillId) : parentStillId,
|
||||
chainIndex: index,
|
||||
|
||||
@@ -53,6 +53,9 @@ export interface Job {
|
||||
folderLocked?: boolean
|
||||
name?: string
|
||||
prompt: string
|
||||
promptMid?: string
|
||||
promptPre?: string
|
||||
promptPost?: string
|
||||
aspect: string
|
||||
width: number
|
||||
height: number
|
||||
|
||||
+19
-1
@@ -58,6 +58,8 @@ export interface LibraryClip {
|
||||
permanenceRefs?: PermanenceRef[]
|
||||
loraName?: string
|
||||
loraStack?: import('~/utils/loras').LoraStackItem[]
|
||||
promptPre?: string
|
||||
promptPost?: string
|
||||
}
|
||||
|
||||
export type StillRole = 'input' | 'output'
|
||||
@@ -74,6 +76,8 @@ export interface LibraryStill {
|
||||
role: StillRole
|
||||
name?: string
|
||||
prompt?: string
|
||||
promptPre?: string
|
||||
promptPost?: string
|
||||
familyId?: string
|
||||
parentStillId?: string
|
||||
chainIndex?: number
|
||||
@@ -220,6 +224,8 @@ function normalizeStill(still: LibraryStill): LibraryStill {
|
||||
role: stillRole(still),
|
||||
name: still.name,
|
||||
prompt: still.prompt,
|
||||
promptPre: still.promptPre,
|
||||
promptPost: still.promptPost,
|
||||
familyId: still.familyId,
|
||||
parentStillId: still.parentStillId,
|
||||
chainIndex: still.chainIndex,
|
||||
@@ -1210,6 +1216,8 @@ export async function saveStill(params: {
|
||||
role?: StillRole
|
||||
name?: string
|
||||
prompt?: string
|
||||
promptPre?: string
|
||||
promptPost?: string
|
||||
familyId?: string
|
||||
parentStillId?: string
|
||||
chainIndex?: number
|
||||
@@ -1238,6 +1246,8 @@ export async function saveStill(params: {
|
||||
item.role = role
|
||||
if (name) item.name = name
|
||||
if (prompt) item.prompt = prompt
|
||||
if (params.promptPre != null) item.promptPre = params.promptPre || undefined
|
||||
if (params.promptPost != null) item.promptPost = params.promptPost || undefined
|
||||
if (params.familyId) item.familyId = params.familyId
|
||||
if (params.parentStillId) item.parentStillId = params.parentStillId
|
||||
if (typeof params.chainIndex === 'number') item.chainIndex = params.chainIndex
|
||||
@@ -1247,6 +1257,8 @@ export async function saveStill(params: {
|
||||
existing.role = role
|
||||
if (name) existing.name = name
|
||||
if (prompt) existing.prompt = prompt
|
||||
if (params.promptPre != null) existing.promptPre = params.promptPre || undefined
|
||||
if (params.promptPost != null) existing.promptPost = params.promptPost || undefined
|
||||
if (nextSettings) existing.settings = nextSettings
|
||||
}
|
||||
return existing
|
||||
@@ -1266,6 +1278,8 @@ export async function saveStill(params: {
|
||||
role,
|
||||
name: params.name?.trim().slice(0, 80) || undefined,
|
||||
prompt: params.prompt || undefined,
|
||||
promptPre: params.promptPre || undefined,
|
||||
promptPost: params.promptPost || undefined,
|
||||
familyId: params.familyId,
|
||||
parentStillId: params.parentStillId,
|
||||
chainIndex: params.chainIndex,
|
||||
@@ -1554,6 +1568,8 @@ export async function saveClip(params: {
|
||||
permanenceRefs?: PermanenceRef[]
|
||||
loraName?: string
|
||||
loraStack?: import('~/utils/loras').LoraStackItem[]
|
||||
promptPre?: string
|
||||
promptPost?: string
|
||||
segmentFirstFrame?: Buffer
|
||||
}) {
|
||||
const catalog = readCatalog(params.ownerKey)
|
||||
@@ -1587,7 +1603,9 @@ export async function saveClip(params: {
|
||||
globalLocks: params.globalLocks,
|
||||
permanenceRefs: params.permanenceRefs?.length ? normalizePermanenceRefs(params.permanenceRefs) : undefined,
|
||||
loraName: params.loraName || undefined,
|
||||
loraStack: params.loraStack?.length ? params.loraStack : undefined
|
||||
loraStack: params.loraStack?.length ? params.loraStack : undefined,
|
||||
promptPre: params.promptPre || undefined,
|
||||
promptPost: params.promptPost || undefined
|
||||
}
|
||||
mkdirSync(clipDir(params.ownerKey, clip.id), { recursive: true })
|
||||
const videoPath = clipVideoPath(params.ownerKey, clip.id)
|
||||
|
||||
@@ -14,6 +14,8 @@ export interface PendingJob {
|
||||
folderLocked?: boolean
|
||||
name?: string
|
||||
prompt: string
|
||||
promptPre?: string
|
||||
promptPost?: string
|
||||
aspect: string
|
||||
width: number
|
||||
height: number
|
||||
@@ -107,6 +109,8 @@ export function pendingFromJob(job: Job, overrides: Partial<PendingJob> = {}): P
|
||||
folderLocked: library.folderLocked,
|
||||
name: library.name,
|
||||
prompt: library.prompt,
|
||||
promptPre: library.promptPre,
|
||||
promptPost: library.promptPost,
|
||||
aspect: library.aspect,
|
||||
width: library.width,
|
||||
height: library.height,
|
||||
@@ -164,6 +168,8 @@ export function libraryFromPending(pending: PendingJob): NonNullable<Job['librar
|
||||
folderLocked: pending.folderLocked,
|
||||
name: pending.name,
|
||||
prompt: pending.prompt,
|
||||
promptPre: pending.promptPre,
|
||||
promptPost: pending.promptPost,
|
||||
aspect: pending.aspect,
|
||||
width: pending.width,
|
||||
height: pending.height,
|
||||
@@ -313,6 +319,8 @@ export async function completePendingIfReady(pending: PendingJob) {
|
||||
folderId: pending.folderId,
|
||||
name: pending.name,
|
||||
prompt: pending.prompt,
|
||||
promptPre: pending.promptPre,
|
||||
promptPost: pending.promptPost,
|
||||
aspect: pending.aspect,
|
||||
width: pending.width,
|
||||
height: pending.height,
|
||||
|
||||
@@ -14,6 +14,9 @@ export type StudioJobKind = 'video' | 'edit'
|
||||
|
||||
export interface StudioJobPayload {
|
||||
prompt: string
|
||||
promptMid?: string
|
||||
promptPre?: string
|
||||
promptPost?: string
|
||||
name: string
|
||||
folderId: string
|
||||
aspect: string
|
||||
@@ -942,6 +945,9 @@ export async function startStudioJob(item: StudioJob) {
|
||||
folderLocked: payload.folderLocked,
|
||||
name: payload.name,
|
||||
prompt: payload.prompt,
|
||||
promptMid: payload.promptMid,
|
||||
promptPre: payload.promptPre,
|
||||
promptPost: payload.promptPost,
|
||||
aspect: payload.aspect,
|
||||
width: payload.width,
|
||||
height: payload.height,
|
||||
|
||||
@@ -22,6 +22,7 @@ import {
|
||||
updateShotQueue
|
||||
} from '~/server/utils/shotQueue'
|
||||
import { composeShotPrompt, allowIdentityRefs, type PermanenceRef } from '~/utils/globalLocks'
|
||||
import { composePromptParts } from '~/utils/promptParts'
|
||||
import { persistLoraFields, ensureComfyLoraNames } from '~/server/utils/loras'
|
||||
import { readLoraStack, resolveLoraStack } from '~/utils/loras'
|
||||
import type { LoraStackItem } from '~/utils/loras'
|
||||
@@ -186,7 +187,7 @@ export async function queueMiniMax(
|
||||
const shotIndex = job.library?.chainIndex || 0
|
||||
const composedPrompt = composeShotPrompt({
|
||||
globalLocks: job.library?.globalLocks || params.globalLocks,
|
||||
prompt: params.prompt,
|
||||
prompt: composePromptParts(job.library?.promptPre || '', params.prompt, job.library?.promptPost || ''),
|
||||
shotIndex,
|
||||
familyRefs: job.library?.permanenceRefs || params.permanenceRefs,
|
||||
shotRefs: job.library?.shotPermanenceRefs?.[shotIndex] || params.shotPermanenceRefs?.[shotIndex]
|
||||
|
||||
@@ -216,7 +216,9 @@ export function watchComfyJob(job: Job, options: { persist?: boolean } = {}): Pr
|
||||
ownerKey: job.library.ownerKey,
|
||||
folderId: job.library.folderId,
|
||||
name: job.library.name,
|
||||
prompt: job.library.prompt,
|
||||
prompt: job.library.promptMid || job.library.prompt,
|
||||
promptPre: job.library.promptPre,
|
||||
promptPost: job.library.promptPost,
|
||||
aspect: job.library.aspect,
|
||||
width: job.library.width,
|
||||
height: job.library.height,
|
||||
|
||||
Reference in New Issue
Block a user