fix: resolve detail reference sku to spu
This commit is contained in:
parent
84f105d4c8
commit
6937217634
@ -236,7 +236,35 @@ function getGoodsInfoBrandName(data: Record<string, unknown>) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchGoodsBrandByKeyword(params: {
|
function getGoodsInfoMatchedSpu(data: Record<string, unknown>) {
|
||||||
|
return (
|
||||||
|
sanitizeText(data["spu"], 64) ||
|
||||||
|
sanitizeText(data["SPU"], 64) ||
|
||||||
|
sanitizeText(data["productSpu"], 64) ||
|
||||||
|
sanitizeText(data["ProductSpu"], 64) ||
|
||||||
|
sanitizeText(data["商品SPU"], 64) ||
|
||||||
|
sanitizeText(data["商品spu"], 64) ||
|
||||||
|
sanitizeText(data["款号"], 64) ||
|
||||||
|
sanitizeText(data["商品款号"], 64) ||
|
||||||
|
null
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getGoodsInfoMatchedSku(data: Record<string, unknown>) {
|
||||||
|
return (
|
||||||
|
sanitizeText(data["sku"], 64) ||
|
||||||
|
sanitizeText(data["SKU"], 64) ||
|
||||||
|
sanitizeText(data["skuId"], 64) ||
|
||||||
|
sanitizeText(data["SkuId"], 64) ||
|
||||||
|
sanitizeText(data["skuoid"], 64) ||
|
||||||
|
sanitizeText(data["SKUOID"], 64) ||
|
||||||
|
sanitizeText(data["商品SKU"], 64) ||
|
||||||
|
sanitizeText(data["商品sku"], 64) ||
|
||||||
|
null
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function fetchGoodsLookupByKeyword(params: {
|
||||||
keyword: string;
|
keyword: string;
|
||||||
config: ReturnType<typeof normalizeAgentWorkflowGoodsInfoApiConfig>;
|
config: ReturnType<typeof normalizeAgentWorkflowGoodsInfoApiConfig>;
|
||||||
}) {
|
}) {
|
||||||
@ -270,13 +298,20 @@ async function fetchGoodsBrandByKeyword(params: {
|
|||||||
});
|
});
|
||||||
const result = (await response.json().catch(() => ({}))) as ExternalGoodsInfoResponse;
|
const result = (await response.json().catch(() => ({}))) as ExternalGoodsInfoResponse;
|
||||||
if (response.ok && result.success === true && result.data) {
|
if (response.ok && result.success === true && result.data) {
|
||||||
const brandName = getGoodsInfoBrandName(result.data);
|
const data = result.data;
|
||||||
if (brandName) {
|
const brandName = getGoodsInfoBrandName(data);
|
||||||
return brandName;
|
const matchedSpu = getGoodsInfoMatchedSpu(data);
|
||||||
|
const matchedSku = getGoodsInfoMatchedSku(data);
|
||||||
|
if (brandName || matchedSpu || matchedSku) {
|
||||||
|
return {
|
||||||
|
brandName,
|
||||||
|
matchedSpu,
|
||||||
|
matchedSku,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.warn("[Agent Workflow Reference Search] Goods brand query failed:", {
|
console.warn("[Agent Workflow Reference Search] Goods info lookup failed:", {
|
||||||
requestPath,
|
requestPath,
|
||||||
error,
|
error,
|
||||||
});
|
});
|
||||||
@ -910,15 +945,25 @@ export async function GET(request: NextRequest) {
|
|||||||
|
|
||||||
const materialQueryType = queryType as AgentWorkflowMaterialQueryType;
|
const materialQueryType = queryType as AgentWorkflowMaterialQueryType;
|
||||||
const requestedBrandName = String(parsed.brandName || "").trim();
|
const requestedBrandName = String(parsed.brandName || "").trim();
|
||||||
const verifiedGoodsBrandName = requestedBrandName
|
const goodsLookup = await fetchGoodsLookupByKeyword({
|
||||||
? await fetchGoodsBrandByKeyword({
|
keyword: normalizedKeyword,
|
||||||
keyword: normalizedKeyword,
|
config: goodsInfoConfig,
|
||||||
config: goodsInfoConfig,
|
}).catch((error) => {
|
||||||
}).catch((error) => {
|
console.warn("[Agent Workflow Reference Search] Goods info lookup failed:", error);
|
||||||
console.warn("[Agent Workflow Reference Search] Goods brand lookup failed:", error);
|
return null;
|
||||||
return null;
|
});
|
||||||
})
|
const verifiedGoodsBrandName = goodsLookup?.brandName || null;
|
||||||
: null;
|
const resolvedMaterialKeyword =
|
||||||
|
materialQueryType === "spu" && goodsLookup?.matchedSpu
|
||||||
|
? goodsLookup.matchedSpu.trim().toUpperCase()
|
||||||
|
: normalizedKeyword;
|
||||||
|
if (materialQueryType === "spu" && goodsLookup?.matchedSpu) {
|
||||||
|
console.info("[Agent Workflow Reference Search] Resolved SKU input to SPU:", {
|
||||||
|
keyword: normalizedKeyword,
|
||||||
|
resolvedSpu: resolvedMaterialKeyword,
|
||||||
|
matchedSku: goodsLookup.matchedSku || null,
|
||||||
|
});
|
||||||
|
}
|
||||||
if (
|
if (
|
||||||
requestedBrandName &&
|
requestedBrandName &&
|
||||||
verifiedGoodsBrandName &&
|
verifiedGoodsBrandName &&
|
||||||
@ -953,7 +998,7 @@ export async function GET(request: NextRequest) {
|
|||||||
|
|
||||||
for (const currentQueryType of queryTypesToTry) {
|
for (const currentQueryType of queryTypesToTry) {
|
||||||
const attempt = await requestTaskDetailAttempt({
|
const attempt = await requestTaskDetailAttempt({
|
||||||
keyword: normalizedKeyword,
|
keyword: resolvedMaterialKeyword,
|
||||||
queryType: currentQueryType,
|
queryType: currentQueryType,
|
||||||
target: parsed.target,
|
target: parsed.target,
|
||||||
requestedBrandName,
|
requestedBrandName,
|
||||||
@ -964,6 +1009,7 @@ export async function GET(request: NextRequest) {
|
|||||||
if (requestedBrandName) {
|
if (requestedBrandName) {
|
||||||
console.info("[Agent Workflow Reference Search] Brand gate:", {
|
console.info("[Agent Workflow Reference Search] Brand gate:", {
|
||||||
keyword: normalizedKeyword,
|
keyword: normalizedKeyword,
|
||||||
|
resolvedKeyword: resolvedMaterialKeyword,
|
||||||
queryType: currentQueryType,
|
queryType: currentQueryType,
|
||||||
target: parsed.target,
|
target: parsed.target,
|
||||||
requestedBrandName,
|
requestedBrandName,
|
||||||
@ -1048,6 +1094,7 @@ export async function GET(request: NextRequest) {
|
|||||||
if (selectedAttempt.queryType !== materialQueryType) {
|
if (selectedAttempt.queryType !== materialQueryType) {
|
||||||
console.info("[Agent Workflow Reference Search] Query type fallback succeeded:", {
|
console.info("[Agent Workflow Reference Search] Query type fallback succeeded:", {
|
||||||
keyword: normalizedKeyword,
|
keyword: normalizedKeyword,
|
||||||
|
resolvedKeyword: resolvedMaterialKeyword,
|
||||||
requestedQueryType: materialQueryType,
|
requestedQueryType: materialQueryType,
|
||||||
resolvedQueryType: selectedAttempt.queryType,
|
resolvedQueryType: selectedAttempt.queryType,
|
||||||
target: parsed.target,
|
target: parsed.target,
|
||||||
@ -1065,6 +1112,7 @@ export async function GET(request: NextRequest) {
|
|||||||
success: true,
|
success: true,
|
||||||
data: {
|
data: {
|
||||||
query: normalizedKeyword,
|
query: normalizedKeyword,
|
||||||
|
resolvedQuery: resolvedMaterialKeyword,
|
||||||
queryType: selectedAttempt.queryType,
|
queryType: selectedAttempt.queryType,
|
||||||
target: parsed.target,
|
target: parsed.target,
|
||||||
matchedSpu: String(selectedAttempt.upstreamResult.data?.spu || "").trim() || null,
|
matchedSpu: String(selectedAttempt.upstreamResult.data?.spu || "").trim() || null,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user