From 5a7f8bc1f17f743b5340c40a660fe13e97c3bc5d Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 2 Jun 2026 12:59:14 +0800 Subject: [PATCH] fix: streamline detail reference template lookup --- .../agent-workflow/reference-search/route.ts | 18 +- .../agents/AgentGenerationWorkspaceDarkV2.tsx | 205 ++++++++---------- 2 files changed, 107 insertions(+), 116 deletions(-) diff --git a/app/api/agent-workflow/reference-search/route.ts b/app/api/agent-workflow/reference-search/route.ts index 328687632..b3c29f651 100644 --- a/app/api/agent-workflow/reference-search/route.ts +++ b/app/api/agent-workflow/reference-search/route.ts @@ -33,6 +33,7 @@ const querySchema = z.object({ target: z.enum(["main", "detail", "sku"]), brandName: z.string().trim().max(64).optional(), channel: productDetailChannelSchema, + strictQueryType: z.enum(["true", "false", "1", "0"]).optional(), }); function jsonNoStore( @@ -854,6 +855,8 @@ export async function GET(request: NextRequest) { target: request.nextUrl.searchParams.get("target"), brandName: request.nextUrl.searchParams.get("brandName") || undefined, channel: request.nextUrl.searchParams.get("channel") || undefined, + strictQueryType: + request.nextUrl.searchParams.get("strictQueryType") || undefined, }); const setting = await getSystemSetting({ key: AGENT_WORKFLOW_MATERIAL_API_CONFIG_KEY }); @@ -928,12 +931,15 @@ export async function GET(request: NextRequest) { }); } - const queryTypesToTry = Array.from( - new Set([ - materialQueryType, - materialQueryType === "spu" ? "sku" : "spu", - ]) - ); + const strictQueryType = parsed.strictQueryType === "true" || parsed.strictQueryType === "1"; + const queryTypesToTry = strictQueryType + ? [materialQueryType] + : Array.from( + new Set([ + materialQueryType, + materialQueryType === "spu" ? "sku" : "spu", + ]) + ); let selectedAttempt: | Awaited> diff --git a/components/agents/AgentGenerationWorkspaceDarkV2.tsx b/components/agents/AgentGenerationWorkspaceDarkV2.tsx index eb2fc942c..2f4c7170a 100644 --- a/components/agents/AgentGenerationWorkspaceDarkV2.tsx +++ b/components/agents/AgentGenerationWorkspaceDarkV2.tsx @@ -1609,6 +1609,14 @@ export function AgentGenerationWorkspaceDarkV2({ [getLatestWorkflowContext, workflowContext] ); const workflowBrandName = getCurrentWorkflowBrandName(); + const getCurrentWorkflowPrimarySpu = useCallback( + () => + String((getLatestWorkflowContext?.() ?? workflowContext)?.primarySku || "") + .trim(), + [getLatestWorkflowContext, workflowContext] + ); + const workflowPrimarySpu = getCurrentWorkflowPrimarySpu(); + const normalizedWorkflowPrimarySpu = workflowPrimarySpu.toUpperCase(); const shouldAllowModelOverride = !isWorkflowModelLocked && (isDirectModelGenerationMode || !isSceneGenerationPreset || presetModeConfig.scene.allowModelOverride); @@ -4836,19 +4844,6 @@ export function AgentGenerationWorkspaceDarkV2({ setPendingGeneration(null); } } - const handleDetailReplacementQueryTypeChange = useCallback( - (queryType: AgentWorkflowReferenceQueryType) => { - updateDetailReplacementState((current) => ({ - ...current, - queryType, - candidates: current.queryType === queryType ? current.candidates : [], - selectedCandidateId: - current.queryType === queryType ? current.selectedCandidateId : null, - references: current.queryType === queryType ? current.references : [], - })); - }, - [updateDetailReplacementState] - ); const handleDetailReplacementProductDetailChannelChange = useCallback( (channel: AgentWorkflowProductDetailChannel) => { updateDetailReplacementState((current) => ({ @@ -4960,25 +4955,22 @@ export function AgentGenerationWorkspaceDarkV2({ }, [detailReplacementReferenceCards.length, updateDetailReplacementState] ); - const handleDetailReplacementSearch = useCallback(async () => { + const handleDetailReplacementSearch = useCallback(async ( + queryType: Extract + ) => { + const rawPrimarySpu = getCurrentWorkflowPrimarySpu(); const normalized = - detailReplacementQueryType === "productId" - ? detailReplacementQueryInput.trim() - : detailReplacementQueryInput.trim().toUpperCase(); + queryType === "productId" ? rawPrimarySpu.trim() : rawPrimarySpu.trim().toUpperCase(); const currentWorkflowBrandName = getCurrentWorkflowBrandName(); - if (!currentWorkflowBrandName && detailReplacementQueryType !== "productId") { - toast.error("请先在第一步完成品牌选择后再查询参考图"); + if (!currentWorkflowBrandName && queryType !== "productId") { + toast.error("请先在第一步完成品牌选择后再检索可用模版"); return; } if (!normalized) { toast.error( - `请输入${ - detailReplacementQueryType === "productId" - ? "商品ID" - : detailReplacementQueryType === "sku" - ? "SKU" - : "SPU" - }后再查询${detailReferenceSourceLabel}` + queryType === "productId" + ? "请先在第一步输入主商品市场ID后再查询详情" + : "请先在第一步输入主商品SPU后再检索可用模版" ); return; } @@ -4991,14 +4983,16 @@ export function AgentGenerationWorkspaceDarkV2({ try { const searchParams = new URLSearchParams({ keyword: normalized, - queryType: detailReplacementQueryType, + queryType, target: detailReferenceTarget, }); if (currentWorkflowBrandName) { searchParams.set("brandName", currentWorkflowBrandName); } - if (detailReplacementQueryType === "productId") { + if (queryType === "productId") { searchParams.set("channel", detailReplacementProductDetailChannel); + } else { + searchParams.set("strictQueryType", "true"); } const response = await fetch( `/api/agent-workflow/reference-search?${searchParams.toString()}`, @@ -5012,7 +5006,7 @@ export function AgentGenerationWorkspaceDarkV2({ updateDetailReplacementState({ query: normalized, - queryType: result.data.queryType || detailReplacementQueryType, + queryType: result.data.queryType || queryType, productDetailChannel: result.data.channel || detailReplacementProductDetailChannel, candidates: result.data.candidates || [], @@ -5036,8 +5030,7 @@ export function AgentGenerationWorkspaceDarkV2({ detailReferenceSourceLabel, detailReferenceTarget, detailReplacementProductDetailChannel, - detailReplacementQueryInput, - detailReplacementQueryType, + getCurrentWorkflowPrimarySpu, getCurrentWorkflowBrandName, updateDetailReplacementState, ]); @@ -6241,87 +6234,79 @@ export function AgentGenerationWorkspaceDarkV2({
-
- {([ - ["spu", "按SPU查询"], - ["sku", "按SKU查询"], - ["productId", "按商品ID查询"], - ] as Array<[AgentWorkflowReferenceQueryType, string]>).map(([queryType, label]) => ( - - ))} + +
+
+
+
+ 自动复用第一步主商品信息检索参考详情,不需要重复输入 SPU / SKU。 +
+
+ + 主 SPU / {normalizedWorkflowPrimarySpu || "未填写"} + + + 品牌 / {workflowBrandName || "未选择"} + + + 目标 / {detailReferenceSourceLabel} + +
+
+
+ + + +
+
- - {detailReplacementQueryType === "productId" ? ( - - ) : null} - - updateDetailReplacementState({ - query: e.target.value, - }) - } - placeholder={ - detailReplacementQueryType === "productId" - ? "输入商品ID,查询并拉取详情图片" - : `输入 ${detailReplacementQueryType === "sku" ? "SKU" : "SPU"},查询任务整套中的${detailReferenceSourceLabel}参考图` - } - className="h-12 rounded-[22px] border-white/10 bg-black/20 text-sm text-white placeholder:text-white/22 focus:border-emerald-400/30" - /> -