Wire T5A normalizedProduct through jiansun_pi_runtime and plan_production

This commit is contained in:
WuYongJie 2026-12-02 18:56:15 +08:00
parent 750dee7911
commit c37780889e
3 changed files with 142 additions and 8 deletions

View File

@ -1241,10 +1241,13 @@ export async function openProductionOperations(host,{target=host.productionConte
if(!canvasReady)recordProductionInputs(repository,plan,slots);
const {requested,matched,unmatched}=readSelection(slotIds);
const {brief,variant}=scopedProductionBrief(plan.productEvidence?.brief??{},variantId,outputId);
const {name,spu,dimensions,note,intake,barcodes,detailBarcode,platformFacts}=brief;
const {name,spu,dimensions,note,intake,barcodes,detailBarcode,platformFacts,normalizedProduct}=brief;
const imageBindings=[...(brief.images??[]),...(variant?.images??[])]
.filter(image=>image.imageRole||image.barcode)
.map(({name,purpose,imageRole,fieldKey,barcode})=>({name,purpose,imageRole,fieldKey,barcode}));
.filter(image=>image.imageRole||image.barcode||image.kind)
.map(({name,purpose,imageRole,fieldKey,barcode,kind,label})=>({
name,purpose,imageRole,fieldKey,barcode,
...(kind?{kind}:null),...(label?{label}:null),
}));
const settings=productionSettings(store,plan.template.production);
const {plannedSlots,...picturePlan}=productionPicturePlan(outputId,await liveSlots(),settings);
const selected=plannedSlots.filter(slot=>!requested.size||matched.has(slot.id));
@ -1266,7 +1269,8 @@ export async function openProductionOperations(host,{target=host.productionConte
fieldConflicts:await fieldConflicts(await copySnapshot(),plan),fieldRequirements:fieldRequirements(plan),
template,product:{name,dimensions,note,...(spu?{spu}:null),variant:variant&&{id:variant.id,colorName:variant.colorName},
...(intake?{intake}:null),...(barcodes?{barcodes}:null),...(detailBarcode?{detailBarcode}:null),
...(platformFacts?{platformFacts}:null),...(imageBindings.length?{imageBindings}:null)},
...(platformFacts?{platformFacts}:null),...(normalizedProduct?{normalizedProduct}:null),
...(imageBindings.length?{imageBindings}:null)},
candidatesPerSlot,maxCandidatesPerSlot,maxGenerationAttempts,generationLimitSource,...picturePlan,...facts(),...(productUpdate?{productUpdate}:null),pictures,
inFlightImages:(await pendingNative()).map(row=>row.candidateId),
...(includeKnowledge?{knowledgeFiles:host.productionSkills?.files??[]}:null),

View File

@ -2632,3 +2632,68 @@ test('main and grouped assistants crop a candidate into another output of the sa
assert.equal(requests.length,2);
assert.equal(host.productionGoal.outputId,'detail');
});
test('plan_production forwards scoped normalizedProduct and normalized image kinds while keeping legacy briefs compatible', async t => {
const dir = await fs.mkdtemp(path.join(os.tmpdir(), 'jiansun-pi-plan-normalized-'));
t.after(() => cleanup(dir));
const store = productionStore(dir);
const barcode = 'CY001307N35V01';
const normalizedProduct = {
identity: { spu: 'A01', productName: '实木书桌', platformBrand: '顾家', platformCategory: '电脑桌', seriesOrModel: null },
specs: { dimensions: { length: 1400, width: 700, height: 750, unit: 'mm', display: '1400×700×750 mm' },
packageDimensions: null, materials: ['实木'], colors: ['白色', '黑色'], attributes: [] },
copy: { summary: '实木书桌', sellingPoints: ['稳固承重'] },
variants: [
{ id: 'white', colorName: '白色', barcodes: [{ barcode, skuCode: null, skuName: null, spec: null, dimensions: null, sellingPoints: [], attributes: [], imageIds: ['white-img'] }] },
{ id: 'black', colorName: '黑色', barcodes: [{ barcode: 'OTHER999', skuCode: null, skuName: null, spec: null, dimensions: null, sellingPoints: [], attributes: [], imageIds: ['black-img'] }] },
],
assets: [
{ id: 'common-img', kind: 'main', label: '主图', barcode: null, colorName: null, selectedForProject: true },
{ id: 'white-img', kind: 'whiteBackground', label: '白底图 · 白色', barcode, colorName: '白色', selectedForProject: true },
{ id: 'black-img', kind: 'sku', label: 'SKU 图 · 黑色', barcode: 'OTHER999', colorName: '黑色', selectedForProject: true },
],
};
const host = {
store,
productionGoal: { outputId: 'detail', variantId: 'white' },
canvas: {
workflowRead: async () => ({
available: true,
canvasFirst: true,
outputId: 'detail',
productVariantId: 'white',
template: { contentHash: 'studio-normalized' },
totalSlots: 1,
slots: [{ id: 'hero', fieldId: 'S01-I01' }],
productEvidence: {
brief: {
name: '实木书桌',
detailBarcode: barcode,
images: [
{ name: '白底主图', purpose: 'product', kind: 'whiteBackground', label: '白底图 · 白色', assetId: 'white-img', barcode },
{ name: '其他色图', purpose: 'product', kind: 'sku', label: 'SKU 图 · 黑色', assetId: 'black-img', barcode: 'OTHER999' },
],
normalizedProduct,
},
},
}),
detailCopyFields: async () => ({ fields: [] }),
delta: async () => {},
imageRequest: async () => [],
},
};
const actions = await openOperations(host);
t.after(() => actions.close());
const plan = await actions.plan_production();
assert.equal(plan.product.normalizedProduct.identity.spu, 'A01');
assert.deepEqual(plan.product.normalizedProduct.assets.map(a => a.id), ['common-img', 'white-img']);
assert.deepEqual(plan.product.imageBindings, [{
name: '白底主图',
purpose: 'product',
imageRole: undefined,
fieldKey: undefined,
barcode,
kind: 'whiteBackground',
label: '白底图 · 白色',
}]);
});

View File

@ -380,7 +380,7 @@ fn evidence_images(value: &Value) -> Value {
.map(|hash| format!("sha256:{}", hash.to_ascii_lowercase()));
let mut evidence = json!({"ref":reference,"purpose":image["purpose"].as_str().filter(|purpose| matches!(*purpose,"product"|"scene")),
"name":evidence_safe_text(&image["name"],160),"description":evidence_safe_text(&image["description"],160)});
for key in ["imageRole","fieldKey","templateId","barcode"] {
for key in ["imageRole","fieldKey","templateId","barcode","kind","label","assetId"] {
if let Some(value) = image.get(key) { evidence[key] = value.clone(); }
}
evidence
@ -399,9 +399,17 @@ fn project_evidence(c: &Value, scope: &str, project: &str, doc: u64, current_var
.filter_map(|key| c["brief"].get(key).map(|value| (key.to_owned(), value.clone())))
.collect();
let mut brief = brief;
for field in ["intake", "barcodeBindings", "deliverySpu", "platformFacts"] {
if let Some(value) = c["brief"].get(field) {
brief.insert(field.to_owned(), value.clone());
for field in ["intake", "barcodeBindings", "deliverySpu", "platformFacts", "normalizedProduct"] {
if let Some(mut value) = c["brief"].get(field).cloned() {
if field == "normalizedProduct" {
if let Some(assets) = value.get_mut("assets").and_then(Value::as_array_mut) {
for asset in assets.iter_mut().filter_map(Value::as_object_mut) {
asset.remove("url");
asset.remove("localSource");
}
}
}
brief.insert(field.to_owned(), value);
}
}
if let Some(barcode) = super::creation::detail_barcode(&c["brief"]) {
@ -418,6 +426,11 @@ fn project_evidence(c: &Value, scope: &str, project: &str, doc: u64, current_var
let variants: Vec<Value> = variants.iter().take(64).map(|variant| {
let mut row = json!({"id":evidence_safe_text(&variant["id"],100),"name":evidence_safe_text(&variant["name"],160),
"colorName":evidence_safe_text(&variant["colorName"],160),"colorMaterialId":evidence_safe_text(&variant["colorMaterialId"],150)});
for key in ["barcode", "barcodes", "colorId"] {
if let Some(value) = variant.get(key) {
row[key] = value.clone();
}
}
if let Some(colors) = variant.get("outputColors") {
row["outputColors"] = evidence_output_colors(colors);
}
@ -1491,6 +1504,58 @@ mod tests {
assert!(evidence["plan"]["screens"][0]["imagePrompt"].is_null());
}
#[test]
fn discussion_product_snapshot_forwards_normalized_product_and_image_kinds() {
let c = json!({
"revision": 3,
"brief": {
"name": "实木书桌",
"images": [{
"source": format!("local:{}", "b".repeat(64)),
"purpose": "product",
"name": "白底主图",
"kind": "whiteBackground",
"label": "白底图 · 白色",
"assetId": "asset-1",
"barcode": "CY001"
}],
"variants": [{
"id": "white",
"name": "白色",
"colorName": "白色",
"colorId": "c-white",
"barcode": "CY001",
"barcodes": ["CY001"]
}],
"normalizedProduct": {
"identity": {"spu": "SPU01"},
"specs": {},
"copy": {},
"variants": [],
"assets": [{
"id": "asset-1",
"kind": "whiteBackground",
"label": "白底图 · 白色",
"url": "https://cdn.example/signed?token=secret",
"localSource": "local:should-not-forward"
}]
}
},
"facts": {"status": "ready", "items": [], "missing": []},
"sellingPoints": {"selected": [], "batches": []},
"plan": {"status": "confirmed", "screens": []}
});
let evidence = project_evidence(&c, "account-scope", "project-id", 8, &json!("white"));
assert_eq!(evidence["brief"]["normalizedProduct"]["identity"]["spu"], "SPU01");
assert!(evidence["brief"]["normalizedProduct"]["assets"][0]["url"].is_null());
assert!(evidence["brief"]["normalizedProduct"]["assets"][0]["localSource"].is_null());
assert_eq!(evidence["brief"]["images"][0]["kind"], "whiteBackground");
assert_eq!(evidence["brief"]["images"][0]["label"], "白底图 · 白色");
assert_eq!(evidence["brief"]["images"][0]["assetId"], "asset-1");
assert_eq!(evidence["brief"]["variants"][0]["colorId"], "c-white");
assert_eq!(evidence["brief"]["variants"][0]["barcode"], "CY001");
assert_eq!(evidence["brief"]["variants"][0]["barcodes"], json!(["CY001"]));
}
#[test]
fn public_default_is_pinned_without_changing_credentials_or_path() {
let model = json!({"id":"qa","path":"/v1/chat/completions"});
let mut catalog = json!({"data":{"sections":[{"models":[{"id":"qa","invocation":{"method":"POST","path":"/v1/chat/completions","content_type":"application/json","headers":{"X-Relay-Route-Option":"a3830b3b-6fa5-4a2b-80d0-9e7a1c5cf61a"}}}]}]}});