fix: use spu for detail reference search
This commit is contained in:
parent
51e8393f95
commit
70cf96afaf
@ -97,6 +97,14 @@ function sanitizeGoodsInfoText(value: unknown, maxLength = 255) {
|
|||||||
return String(value || "").trim().slice(0, maxLength);
|
return String(value || "").trim().slice(0, maxLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function deriveSpuFromSku(value: unknown) {
|
||||||
|
const normalized = String(value || "").trim().toUpperCase();
|
||||||
|
if (!/[0-9]{2}$/.test(normalized) || normalized.length <= 2) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return normalized.slice(0, -2);
|
||||||
|
}
|
||||||
|
|
||||||
function createGoodsInfoSignature(timespan: string, secret: string) {
|
function createGoodsInfoSignature(timespan: string, secret: string) {
|
||||||
const secretBuffer = Buffer.from(String(secret || "").trim(), "utf8");
|
const secretBuffer = Buffer.from(String(secret || "").trim(), "utf8");
|
||||||
if (secretBuffer.length !== 8) {
|
if (secretBuffer.length !== 8) {
|
||||||
@ -817,7 +825,7 @@ export async function GET(request: NextRequest) {
|
|||||||
query: normalizedKeyword,
|
query: normalizedKeyword,
|
||||||
queryType: "sku",
|
queryType: "sku",
|
||||||
matchedSku,
|
matchedSku,
|
||||||
matchedSpu: goodsInfo?.matchedSpu || productModel,
|
matchedSpu: goodsInfo?.matchedSpu || productModel || deriveSpuFromSku(matchedSku),
|
||||||
materialId: String(upstreamResult.data.materialId || "").trim() || null,
|
materialId: String(upstreamResult.data.materialId || "").trim() || null,
|
||||||
productModel,
|
productModel,
|
||||||
zipUrl: String(upstreamResult.data.downloadUrls?.zip || "").trim() || null,
|
zipUrl: String(upstreamResult.data.downloadUrls?.zip || "").trim() || null,
|
||||||
|
|||||||
@ -957,11 +957,11 @@ export async function GET(request: NextRequest) {
|
|||||||
materialQueryType === "spu" && goodsLookup?.matchedSpu
|
materialQueryType === "spu" && goodsLookup?.matchedSpu
|
||||||
? goodsLookup.matchedSpu.trim().toUpperCase()
|
? goodsLookup.matchedSpu.trim().toUpperCase()
|
||||||
: normalizedKeyword;
|
: normalizedKeyword;
|
||||||
if (materialQueryType === "spu" && goodsLookup?.matchedSpu) {
|
if (materialQueryType === "spu" && resolvedMaterialKeyword !== normalizedKeyword) {
|
||||||
console.info("[Agent Workflow Reference Search] Resolved SKU input to SPU:", {
|
console.info("[Agent Workflow Reference Search] Resolved SPU query keyword:", {
|
||||||
keyword: normalizedKeyword,
|
keyword: normalizedKeyword,
|
||||||
resolvedSpu: resolvedMaterialKeyword,
|
resolvedSpu: resolvedMaterialKeyword,
|
||||||
matchedSku: goodsLookup.matchedSku || null,
|
matchedSku: goodsLookup?.matchedSku || null,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
|
|||||||
@ -1610,9 +1610,22 @@ export function AgentGenerationWorkspaceDarkV2({
|
|||||||
);
|
);
|
||||||
const workflowBrandName = getCurrentWorkflowBrandName();
|
const workflowBrandName = getCurrentWorkflowBrandName();
|
||||||
const getCurrentWorkflowPrimarySpu = useCallback(
|
const getCurrentWorkflowPrimarySpu = useCallback(
|
||||||
() =>
|
() => {
|
||||||
String((getLatestWorkflowContext?.() ?? workflowContext)?.primarySku || "")
|
const latestWorkflowContext = getLatestWorkflowContext?.() ?? workflowContext;
|
||||||
.trim(),
|
const explicitSpu = String(latestWorkflowContext?.primarySpu || "").trim();
|
||||||
|
if (explicitSpu) {
|
||||||
|
return explicitSpu;
|
||||||
|
}
|
||||||
|
|
||||||
|
const primaryReferenceSpu = latestWorkflowContext?.referenceImages
|
||||||
|
?.find((image) => image.source === "primary" && image.productModel)
|
||||||
|
?.productModel?.trim();
|
||||||
|
if (primaryReferenceSpu) {
|
||||||
|
return primaryReferenceSpu;
|
||||||
|
}
|
||||||
|
|
||||||
|
return String(latestWorkflowContext?.primarySku || "").trim();
|
||||||
|
},
|
||||||
[getLatestWorkflowContext, workflowContext]
|
[getLatestWorkflowContext, workflowContext]
|
||||||
);
|
);
|
||||||
const workflowPrimarySpu = getCurrentWorkflowPrimarySpu();
|
const workflowPrimarySpu = getCurrentWorkflowPrimarySpu();
|
||||||
@ -4210,16 +4223,17 @@ export function AgentGenerationWorkspaceDarkV2({
|
|||||||
modelSlotEnabled && AGENT_DETAIL_MODEL_SLOT_INDEX >= 0
|
modelSlotEnabled && AGENT_DETAIL_MODEL_SLOT_INDEX >= 0
|
||||||
? getAttachmentIdentityKey(selectedModelAttachment)
|
? getAttachmentIdentityKey(selectedModelAttachment)
|
||||||
: null;
|
: null;
|
||||||
|
const latestWorkflowContext = getLatestWorkflowContext?.() ?? workflowContext;
|
||||||
|
const workflowPrimarySpu = getCurrentWorkflowPrimarySpu().trim().toUpperCase();
|
||||||
|
const workflowPriceBand = String(latestWorkflowContext?.priceBand || "").trim();
|
||||||
|
|
||||||
updateDetailReplacementState((current) => {
|
updateDetailReplacementState((current) => {
|
||||||
let changed = false;
|
let changed = false;
|
||||||
const nextBrief = {
|
const nextBrief = {
|
||||||
...(current.brief || createEmptyAgentDetailBriefForm()),
|
...(current.brief || createEmptyAgentDetailBriefForm()),
|
||||||
};
|
};
|
||||||
const workflowPrimarySku = String(workflowContext?.primarySku || "").trim();
|
if (!nextBrief.productSpu && workflowPrimarySpu) {
|
||||||
const workflowPriceBand = String(workflowContext?.priceBand || "").trim();
|
nextBrief.productSpu = workflowPrimarySpu;
|
||||||
if (!nextBrief.productSpu && workflowPrimarySku) {
|
|
||||||
nextBrief.productSpu = workflowPrimarySku;
|
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
if (!nextBrief.priceBand && workflowPriceBand) {
|
if (!nextBrief.priceBand && workflowPriceBand) {
|
||||||
@ -4346,14 +4360,15 @@ export function AgentGenerationWorkspaceDarkV2({
|
|||||||
});
|
});
|
||||||
}, [
|
}, [
|
||||||
detailGenerationProductSlotIndexes,
|
detailGenerationProductSlotIndexes,
|
||||||
|
getCurrentWorkflowPrimarySpu,
|
||||||
|
getLatestWorkflowContext,
|
||||||
isDetailReplacementPreset,
|
isDetailReplacementPreset,
|
||||||
modelSlotEnabled,
|
modelSlotEnabled,
|
||||||
referenceImages,
|
referenceImages,
|
||||||
selectedModelAttachment,
|
selectedModelAttachment,
|
||||||
selectedProductAttachments,
|
selectedProductAttachments,
|
||||||
updateDetailReplacementState,
|
updateDetailReplacementState,
|
||||||
workflowContext?.priceBand,
|
workflowContext,
|
||||||
workflowContext?.primarySku,
|
|
||||||
]);
|
]);
|
||||||
const updateDetailGenerationMethod = useCallback(
|
const updateDetailGenerationMethod = useCallback(
|
||||||
(method: "reference_replace" | "ai_detail_generate") => {
|
(method: "reference_replace" | "ai_detail_generate") => {
|
||||||
|
|||||||
@ -219,6 +219,33 @@ function normalizeWorkflowText(value: string) {
|
|||||||
.trim();
|
.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function normalizeWorkflowProductCode(value: unknown) {
|
||||||
|
return String(value || "").trim().toUpperCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
function deriveSpuFromSku(value: unknown) {
|
||||||
|
const normalized = normalizeWorkflowProductCode(value);
|
||||||
|
if (!/[0-9]{2}$/.test(normalized) || normalized.length <= 2) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return normalized.slice(0, -2);
|
||||||
|
}
|
||||||
|
|
||||||
|
function resolveWorkflowSpu(params: {
|
||||||
|
inputValue: string;
|
||||||
|
result?: AgentWorkflowMaterialSelections["primary"]["result"] | null;
|
||||||
|
}) {
|
||||||
|
const result = params.result || null;
|
||||||
|
return (
|
||||||
|
normalizeWorkflowProductCode(result?.matchedSpu) ||
|
||||||
|
normalizeWorkflowProductCode(result?.productModel) ||
|
||||||
|
(result?.queryType === "spu" ? normalizeWorkflowProductCode(result?.query) : "") ||
|
||||||
|
(result?.queryType === "sku"
|
||||||
|
? deriveSpuFromSku(result?.matchedSku || result?.query || params.inputValue)
|
||||||
|
: "")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function sanitizeWorkflowPromptFragment(value: string) {
|
function sanitizeWorkflowPromptFragment(value: string) {
|
||||||
return normalizeWorkflowText(value)
|
return normalizeWorkflowText(value)
|
||||||
.replace(/请按选项[\d一二三四五六七八九十]+执行[。.]?/g, "")
|
.replace(/请按选项[\d一二三四五六七八九十]+执行[。.]?/g, "")
|
||||||
@ -416,11 +443,22 @@ export function buildAgentWorkflowComposerContext(params: {
|
|||||||
materials: params.materials,
|
materials: params.materials,
|
||||||
selectedBrandModel: params.selectedBrandModel,
|
selectedBrandModel: params.selectedBrandModel,
|
||||||
});
|
});
|
||||||
|
const primaryWorkflowSpu = resolveWorkflowSpu({
|
||||||
|
inputValue: params.inputs.primarySku,
|
||||||
|
result: params.materials?.primary?.result || null,
|
||||||
|
});
|
||||||
|
const secondaryWorkflowSpu = resolveWorkflowSpu({
|
||||||
|
inputValue: params.inputs.secondarySku,
|
||||||
|
result: params.materials?.secondary?.result || null,
|
||||||
|
});
|
||||||
|
|
||||||
const summaryParts: string[] = [];
|
const summaryParts: string[] = [];
|
||||||
if (params.inputs.primarySku.trim()) {
|
if (params.inputs.primarySku.trim()) {
|
||||||
summaryParts.push(`主SKU:${params.inputs.primarySku.trim()}`);
|
summaryParts.push(`主SKU:${params.inputs.primarySku.trim()}`);
|
||||||
}
|
}
|
||||||
|
if (primaryWorkflowSpu && primaryWorkflowSpu !== params.inputs.primarySku.trim().toUpperCase()) {
|
||||||
|
summaryParts.push(`主SPU:${primaryWorkflowSpu}`);
|
||||||
|
}
|
||||||
if (params.inputs.secondarySku.trim()) {
|
if (params.inputs.secondarySku.trim()) {
|
||||||
summaryParts.push(`搭配SKU:${params.inputs.secondarySku.trim()}`);
|
summaryParts.push(`搭配SKU:${params.inputs.secondarySku.trim()}`);
|
||||||
}
|
}
|
||||||
@ -592,7 +630,9 @@ export function buildAgentWorkflowComposerContext(params: {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
primarySku: params.inputs.primarySku.trim() || undefined,
|
primarySku: params.inputs.primarySku.trim() || undefined,
|
||||||
|
primarySpu: primaryWorkflowSpu || undefined,
|
||||||
secondarySku: params.inputs.secondarySku.trim() || undefined,
|
secondarySku: params.inputs.secondarySku.trim() || undefined,
|
||||||
|
secondarySpu: secondaryWorkflowSpu || undefined,
|
||||||
brand: params.inputs.brand.trim() || undefined,
|
brand: params.inputs.brand.trim() || undefined,
|
||||||
store: params.inputs.store.trim() || undefined,
|
store: params.inputs.store.trim() || undefined,
|
||||||
officialSecondCategory: params.inputs.officialSecondCategory.trim() || undefined,
|
officialSecondCategory: params.inputs.officialSecondCategory.trim() || undefined,
|
||||||
@ -641,7 +681,7 @@ export function getSelectedWorkflowReferenceImages(params: {
|
|||||||
source,
|
source,
|
||||||
sourceLabel,
|
sourceLabel,
|
||||||
sku: result.matchedSku || fallbackSku || undefined,
|
sku: result.matchedSku || fallbackSku || undefined,
|
||||||
productModel: result.productModel || null,
|
productModel: result.productModel || result.matchedSpu || null,
|
||||||
label: item.label,
|
label: item.label,
|
||||||
name: item.fileName || item.label,
|
name: item.fileName || item.label,
|
||||||
url: item.imageUrl,
|
url: item.imageUrl,
|
||||||
|
|||||||
@ -348,7 +348,9 @@ export interface AgentWorkflowComposerSelection {
|
|||||||
|
|
||||||
export interface AgentWorkflowComposerContext {
|
export interface AgentWorkflowComposerContext {
|
||||||
primarySku?: string;
|
primarySku?: string;
|
||||||
|
primarySpu?: string;
|
||||||
secondarySku?: string;
|
secondarySku?: string;
|
||||||
|
secondarySpu?: string;
|
||||||
brand?: string;
|
brand?: string;
|
||||||
store?: string;
|
store?: string;
|
||||||
officialSecondCategory?: string;
|
officialSecondCategory?: string;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user