Pass through PE refusals to the raw prompt and pin adult PE system prompts.
Enhance no longer fails the studio job when the rewrite refuses or comes back empty; host prompt copies keep the official steps plus the adult appendix after a node re-clone. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -18,6 +18,7 @@ import { nativeVideoGraph, attachHeroReference, applyResolvedImageSize } from '~
|
||||
import { compilePrompt, scopedFile } from '~/shared/studio2/contracts.mjs';
|
||||
import { resolveQwen21Size } from '~/shared/studio2/qwen21-size.mjs';
|
||||
import { ensureQwen21EditPrompt, stitchQwen21PeEditPrompt } from '~/shared/studio2/qwen21-edit.mjs';
|
||||
import { qwen21PeRefusal } from '~/shared/studio2/qwen21-pe.mjs';
|
||||
import { QWEN21_TURBO_LORA, QWEN21_TURBO_SIGMAS, QWEN21_TURBO_STEPS } from '~/shared/studio2/qwen21-turbo.mjs';
|
||||
import { createJob, restoreJob, getJob, emitJob, type Job } from '../jobs';
|
||||
import { markStudioLive, onLiveVideoSettled, type StudioJob } from '../studioQueue';
|
||||
@@ -104,10 +105,10 @@ async function runQwen21PromptEnhance(r: any, job: Job) {
|
||||
throw new Error('Qwen Edit requires Start still (image_1). Hero is ignored.')
|
||||
update(r, 'enhancing')
|
||||
emitJob(job, { type: 'status', message: 'Enhancing prompt…' })
|
||||
let prompt = String(q.compiledPrompt || '')
|
||||
if (edit) prompt = ensureQwen21EditPrompt(prompt)
|
||||
const userPrompt = String(q.compiledPrompt || '')
|
||||
const peInput = edit ? ensureQwen21EditPrompt(userPrompt) : userPrompt
|
||||
const graph = structuredClone(edit ? qwen21PeEditTemplate : qwen21PeT2iTemplate)
|
||||
graph['9'].inputs.prompt = prompt
|
||||
graph['9'].inputs.prompt = peInput
|
||||
graph['9'].inputs.seed = s.seed
|
||||
if (edit) {
|
||||
// Same Start still pixels as Edit image_1 — never Hero.
|
||||
@@ -136,19 +137,33 @@ async function runQwen21PromptEnhance(r: any, job: Job) {
|
||||
saveRecord(r)
|
||||
const history = await waitPromptHistory(r, job, queued.prompt_id)
|
||||
const result = harvestQwen21Pe(history, queued.prompt_id, edit)
|
||||
if (!result.parse_ok || !result.positive_prompt)
|
||||
throw new Error('Prompt enhance failed to parse a rewrite. Try again or turn Enhance prompt off.')
|
||||
r.request.promptRaw = q.compiledPrompt
|
||||
// PE-I2I: if rewrite dropped every <imageN>, stitch keep-identity onto the rewrite.
|
||||
r.request.compiledPrompt = edit
|
||||
? stitchQwen21PeEditPrompt(result.positive_prompt)
|
||||
: result.positive_prompt
|
||||
r.request.enhance = {
|
||||
wh_ratio: result.wh_ratio || '',
|
||||
...(edit ? { ratio_follow: result.ratio_follow || '' } : {}),
|
||||
parse_ok: true,
|
||||
thinking: result.thinking || '',
|
||||
comfyPromptId: queued.prompt_id,
|
||||
r.request.promptRaw = userPrompt
|
||||
const refusal = qwen21PeRefusal(userPrompt, result)
|
||||
if (refusal.refused) {
|
||||
// Fail open: keep the job, send the raw brief (Edit keep-identity prefix still applies).
|
||||
r.request.compiledPrompt = edit ? ensureQwen21EditPrompt(userPrompt) : userPrompt
|
||||
r.request.enhance = {
|
||||
wh_ratio: '',
|
||||
...(edit ? { ratio_follow: '' } : {}),
|
||||
parse_ok: !!result.parse_ok,
|
||||
refused: true,
|
||||
skipReason: refusal.reason,
|
||||
thinking: result.thinking || '',
|
||||
comfyPromptId: queued.prompt_id,
|
||||
}
|
||||
} else {
|
||||
// PE-I2I: if rewrite dropped every <imageN>, stitch keep-identity onto the rewrite.
|
||||
r.request.compiledPrompt = edit
|
||||
? stitchQwen21PeEditPrompt(result.positive_prompt)
|
||||
: result.positive_prompt
|
||||
r.request.enhance = {
|
||||
wh_ratio: result.wh_ratio || '',
|
||||
...(edit ? { ratio_follow: result.ratio_follow || '' } : {}),
|
||||
parse_ok: !!result.parse_ok,
|
||||
refused: false,
|
||||
thinking: result.thinking || '',
|
||||
comfyPromptId: queued.prompt_id,
|
||||
}
|
||||
}
|
||||
// Stage flip PE → generate: clear PE prompt id and reset the bar (no leftover 100%).
|
||||
r.pePromptId = ''
|
||||
|
||||
Reference in New Issue
Block a user