diff --git a/app/api/canvas/local-edit/route.ts b/app/api/canvas/local-edit/route.ts index 1901eeb9e..36604e476 100644 --- a/app/api/canvas/local-edit/route.ts +++ b/app/api/canvas/local-edit/route.ts @@ -5164,7 +5164,7 @@ function buildScaleAdjustProductLockBackgroundPrompt( regions: NormalizedLocalEditRegion[], scalePercent: ScaleAdjustPercent | null | undefined, sourceSize: { width: number; height: number }, - options: { draftInput?: boolean; maskEdit?: boolean } = {} + options: { draftInput?: boolean; guidedFinalInput?: boolean; maskEdit?: boolean } = {} ) { const regionLines = regions .map((region) => { @@ -5177,18 +5177,28 @@ function buildScaleAdjustProductLockBackgroundPrompt( .join("\n"); return [ - "Full-frame masked background repair for product-locked scale adjustment.", + options.guidedFinalInput + ? "Full-frame guided cleanup for product-locked scale adjustment." + : "Full-frame masked background repair for product-locked scale adjustment.", "Return exactly one clean realistic full image with the same framing, camera, aspect ratio, and canvas extent as input image 1. Do not crop, zoom, pan, resize, or redesign the whole photo.", - options.maskEdit + options.guidedFinalInput + ? "Input image 1 is the current full photo. Input image 2 is a rough target-layout draft showing the selected furniture/product moved/scaled into the requested target footprint. If an additional background-plate reference is provided, use it only as a cleanup hint for the old footprint." + : options.maskEdit ? options.draftInput ? "Input image 1 is a full-photo rough background plate from the original photo. The old selected furniture/product footprint has been roughly wiped, and the target product is intentionally absent. The supplied edit mask marks only that rough old footprint area; repair it into natural background and do not edit outside the masked area." : "Input image 1 is the current full photo. The supplied edit mask is the only allowed edit area: white or transparent pixels must be repaired; black/opaque pixels outside the mask must be copied exactly from input image 1." : "Input image 1 is the original clean full photo. Input image 2 is a background plate reference that removes the selected furniture/product footprint and keeps the room/person/background layout stable.", - "Important: do not draw, recreate, move, scale, duplicate, or redesign the selected furniture/product in the returned image. The returned image must be a background plate only; the system will composite the locked original product pixels into the final target footprint after your background image is returned.", + options.guidedFinalInput + ? "Important: use input image 2 only to understand the target placement. The selected furniture/product may appear only once in the target footprint; remove the old-size copy completely. The system will overwrite the target product with locked original pixels after your image is returned, so prioritize natural background, contact shadow, and clean fusion." + : "Important: do not draw, recreate, move, scale, duplicate, or redesign the selected furniture/product in the returned image. The returned image must be a background plate only; the system will composite the locked original product pixels into the final target footprint after your background image is returned.", options.draftInput ? "Your job is only to turn the rough wiped footprint and any visible draft haze, gray wash, ghost product silhouette, or edge patch into natural wall, curtain, floor, rug, shadow, sofa edge, and background. Keep the target footprint empty and clean for the locked product layer; do not invent a product, second product, or old-size remnant." + : options.guidedFinalInput + ? "Your job is to clean the rough target-layout draft into one natural photograph: erase the old selected furniture/product from its original location, remove translucent old-size silhouettes and rectangular haze/panels, complete the exposed wall, curtain, floor, rug, shadows, sofa edge, and background, and keep only the target-position product placement." : "Your job is only to erase the old selected furniture/product, erase any translucent old-size silhouette, erase any rectangular haze/panel/plate left by previous edits, and complete newly exposed wall, curtain, floor, rug, shadow, sofa edge, and background naturally. Leave no placeholder where the product used to be.", - options.maskEdit + options.guidedFinalInput + ? "Do not copy rough draft haze, wash blocks, hard mask shapes, or pasted edges from the target-layout draft. It is a layout hint, not final content." + : options.maskEdit ? "The mask may be wider than the object silhouette because it also covers old edit artifacts. Do not interpret the mask shape as a box or object to render. Fill the entire editable white/transparent area with continuous real room background." : "Use the background plate reference only as a repair guide, not as visible final content.", "Preserve all non-target people exactly as foreground/background context: do not move, cover, deform, redraw, change face, change body, change hands, change legs, change clothes, or change pose.", @@ -5197,7 +5207,9 @@ function buildScaleAdjustProductLockBackgroundPrompt( ? "The edit mask is only an invisible repair permission map. Do not output pale wash blocks, rough mask shapes, hard rectangular edges, black holes, ghost fragments, pasted silhouettes, old-size residues, or a gray copy of the removed product." : "Remove draft artifacts from input image 2: pale wash blocks, rough masks, missing patches, hard rectangular edges, black holes, ghost fragments, pasted silhouettes, and old-size residues. They are only edit guides, not final content.", "Do not output boxes, masks, labels, coordinate marks, UI marks, arrows, guide overlays, crop borders, or any annotation artifacts.", - "中文硬约束:这是产品结构锁定流程。你只生成背景底图,不要生成、移动、缩放或重绘目标家具/商品;目标家具/商品会在你输出后由系统用原图锁定像素叠回目标位置。白色/透明 mask 内必须清空旧产品、旧尺寸残影、灰色雾块、矩形贴片和旧标注痕迹,只补成连续自然的墙面、窗帘、地面、阴影和背景。黑色/不透明 mask 外必须保持原图不变。非目标人物必须保持原样,不能变脸、变形、改变衣服、手、腿、脚或姿势。最终背景图不能有矩形雾块、贴片边、黑洞、残影、标注框,也不能出现第二个目标家具/商品。", + options.guidedFinalInput + ? "中文硬约束:这是产品结构锁定流程。输入2只是目标位置草稿,不能把草稿的灰雾、贴片边、硬边或旧残影带到最终图。必须删除旧位置的目标家具/商品,只保留目标位置的一份家具/商品,并自然补全旧位置暴露出来的墙面、窗帘、地面、阴影和背景。目标家具/商品最终会由系统用原图锁定像素覆盖,所以你不要改坏产品结构;重点做好背景补全、接触阴影和融合。非目标人物必须保持原样,不能变脸、变形、改变衣服、手、腿、脚或姿势。最终图不能有矩形雾块、贴片边、黑洞、残影、标注框,也不能出现第二个目标家具/商品。" + : "中文硬约束:这是产品结构锁定流程。你只生成背景底图,不要生成、移动、缩放或重绘目标家具/商品;目标家具/商品会在你输出后由系统用原图锁定像素叠回目标位置。白色/透明 mask 内必须清空旧产品、旧尺寸残影、灰色雾块、矩形贴片和旧标注痕迹,只补成连续自然的墙面、窗帘、地面、阴影和背景。黑色/不透明 mask 外必须保持原图不变。非目标人物必须保持原样,不能变脸、变形、改变衣服、手、腿、脚或姿势。最终背景图不能有矩形雾块、贴片边、黑洞、残影、标注框,也不能出现第二个目标家具/商品。", "", "Region instructions:", regionLines, @@ -5555,8 +5567,12 @@ export async function POST(request: NextRequest) { useScaleAdjustFullFrameStructurePatch && Boolean(scaleAdjustPatchReference?.backgroundPlateFullUrl) && Boolean(scaleAdjustPatchReference?.productLockOverlayUrl); + const useScaleAdjustProductLockGuidedFinal = + useScaleAdjustProductLockComposite && + Boolean(scaleAdjustPatchReference?.targetDraftFullUrl); const useScaleAdjustProductLockMaskEdit = useScaleAdjustProductLockComposite && + !useScaleAdjustProductLockGuidedFinal && isScaleAdjustMaskCapableModel(resolvedScaleAdjustModelEntry) && Boolean(scaleAdjustPatchReference?.productLockEditMaskUrl); const useScaleAdjustPatchTargetDraftPrimary = Boolean(scaleAdjustPatchReference); @@ -5575,6 +5591,7 @@ export async function POST(request: NextRequest) { scalePercent, { width: sourceWidth, height: sourceHeight }, { + guidedFinalInput: useScaleAdjustProductLockGuidedFinal, maskEdit: useScaleAdjustProductLockMaskEdit, } ) @@ -5637,6 +5654,8 @@ export async function POST(request: NextRequest) { "boxes, labels, UI marks, arrows, text, overlays, seams, rectangular patch edge, haze block, ghost copy, old-size subject, unchanged subject, duplicate subject, stretched subject, distorted product, changed product structure, changed person, changed face, deformed person, extra limbs, changed hands, changed feet, whole-image zoom, crop, pan"; const scaleAdjustProductLockBackgroundNegativePrompt = "selected furniture, selected product, moved furniture, scaled furniture, recreated product, duplicate furniture, duplicate product, old-size furniture, target object visible, product ghost, product remnant, boxes, labels, UI marks, arrows, text, overlays, seams, rectangular patch edge, haze block, black hole, changed person, changed face, deformed person, extra limbs, changed hands, changed feet, whole-image zoom, crop, pan"; + const scaleAdjustProductLockGuidedNegativePrompt = + "old-size furniture, old-position furniture, duplicate furniture, duplicate product, second copy, product ghost, product remnant, pasted edge, rectangular patch edge, rectangular haze block, gray wash block, black hole, boxes, labels, UI marks, arrows, text, overlays, changed locked product structure, changed person, changed face, deformed person, extra limbs, changed hands, changed feet, whole-image zoom, crop, pan"; const manualRegionReferenceImageUrls = regions.flatMap((region) => region.referenceImages.map((reference) => reference.url) ); @@ -5653,6 +5672,16 @@ export async function POST(request: NextRequest) { ...scaleAdjustCropReferenceImageUrls, ...manualRegionReferenceImageUrls, ] + : useScaleAdjustProductLockGuidedFinal + ? [ + scaleAdjustPatchReference.sourceFullUrl || sourceImageUrl, + scaleAdjustPatchReference.targetDraftFullUrl as string, + ...(scaleAdjustPatchReference.backgroundPlateFullUrl + ? [scaleAdjustPatchReference.backgroundPlateFullUrl] + : []), + ...scaleAdjustCropReferenceImageUrls, + ...manualRegionReferenceImageUrls, + ] : [ sourceImageUrl, scaleAdjustPatchReference.backgroundPlateFullUrl as string, @@ -5808,6 +5837,8 @@ export async function POST(request: NextRequest) { scaleAdjustPatchReference && useScaleAdjustFullFrameStructurePatch ? useScaleAdjustProductLockMaskEdit ? "product-lock-source-edit-mask" + : useScaleAdjustProductLockGuidedFinal + ? "product-lock-source-target-draft-guide" : "full-source-full-target-draft" : scaleAdjustPatchReference && useScaleAdjustPatchTargetDraftPrimary ? includeScaleAdjustPatchSourceReference @@ -5832,6 +5863,8 @@ export async function POST(request: NextRequest) { scaleAdjustPatchReference?.productLockMethod || null, scaleAdjustProductLockMaskEditApplied: useScaleAdjustProductLockMaskEdit, + scaleAdjustProductLockGuidedFinalApplied: + useScaleAdjustProductLockGuidedFinal, scaleAdjustRequiresProviderMaskInput: useScaleAdjustProductLockMaskEdit, scaleAdjustProductLockEditMaskUrl: @@ -5904,6 +5937,8 @@ export async function POST(request: NextRequest) { ? useScaleAdjustProductLockComposite ? useScaleAdjustProductLockMaskEdit ? "product-lock-source-mask-edit-rmbg-one-shot" + : useScaleAdjustProductLockGuidedFinal + ? "product-lock-target-draft-guided-rmbg-one-shot" : "product-lock-background-plate-rmbg-v2-source-patch-one-shot" : useScaleAdjustFullFrameStructurePatch ? "full-frame-source-locked-target-guide-v8-one-shot" @@ -5950,7 +5985,9 @@ export async function POST(request: NextRequest) { ? scaleAdjustPatchReference ? useScaleAdjustFullFrameStructurePatch ? useScaleAdjustProductLockComposite - ? scaleAdjustProductLockBackgroundNegativePrompt + ? useScaleAdjustProductLockGuidedFinal + ? scaleAdjustProductLockGuidedNegativePrompt + : scaleAdjustProductLockBackgroundNegativePrompt : scaleAdjustFullFramePatchNegativePrompt : useFalScaleAdjustPatchPrompt ? scaleAdjustFalPatchNegativePrompt