修正小壹候选复核字段和资料刷新回执

This commit is contained in:
WuYongJie 2026-11-28 21:47:57 +08:00
parent 17cae200a4
commit 2fc959e741
6 changed files with 52 additions and 13 deletions

View File

@ -73,11 +73,12 @@ export async function reviewProductionCandidate({
...(guides.length?{structureGuides:Type.Optional(params(Object.fromEntries(guides.map(([id,spec])=>
[id,Type.Array(guidePoint,{description:typeof spec==='string'?spec:spec.target})]))))}:null),
});
const fields=screenCopy.filter(row=>row.field!==undefined).map(row=>row.field);
const fieldList=screenCopy.filter(row=>row.field!==undefined).map(({field,label})=>({field,label}));
const fields=new Set(fieldList.map(row=>row.field));
const facts=()=>[
`本次可用 candidateId ${JSON.stringify(candidateId)}`,
`本次图位 slotId ${JSON.stringify(slot.id)}`,
`本次可用 field ${JSON.stringify(fields)}`,
`本次可用 field ${JSON.stringify(fieldList)}`,
findings.facts(),
...(guides.length?[`本次结构标注编号 ${JSON.stringify(guides.map(([id])=>id))}`]:[]),
].join('\n');
@ -86,7 +87,7 @@ export async function reviewProductionCandidate({
const errors=[];
if(value.candidateId!==candidateId)errors.push(`candidateId ${JSON.stringify(value.candidateId)} 与本次受审候选不一致`);
value.shownFields?.forEach(({field},index)=>{
if(!fields.includes(field))errors.push(`shownFields[${index}].field ${JSON.stringify(field)} 不在本次文案清单中`);
if(!fields.has(field))errors.push(`shownFields[${index}].field ${JSON.stringify(field)} 不在本次文案清单中`);
});
if(errors.length)throw new InvalidToolReply([...errors,facts()].join('\n'));
findings.validate(value.screenReview);
@ -124,7 +125,7 @@ export async function reviewProductionCandidate({
'在 screenReview 中提交问题及位置。使用 composite 提供的图位、叠层编号和文案字段。找不到编号时省略编号并填写 location。有问题时填 needs_fix,通过时三组问题均为空。',
'subjectBounds 是按放置后像素与边缘背景色差估测的画布坐标 [x,y,w,h],并已裁到可见图框。',
'原件信息见 candidateFile,图框见 frame。requirements 是当前图位的要求,screenCopy 是实时文案。',
'用 shownSubject 描述实际画面,用 shownFields 标明与文案对应的画面依据。mustRedo 和 canvasFixes 分别记录建议重做和能用画布处理的问题。裁切坐标以未裁切原图为准。',
'用 shownSubject 描述实际画面,用 shownFields 标明与文案对应的画面依据,其中 field 填 screenCopy 的字段号,label 用于识别文案。mustRedo 和 canvasFixes 分别记录建议重做和能用画布处理的问题。裁切坐标以未裁切原图为准。',
...(guides.length?['模板要求的结构标注落点用图框内 [0,0] 到 [1000,1000] 的坐标。']:[]),
'调用 review_candidate 提交结论。',
].join('\n');

View File

@ -161,6 +161,21 @@ function productionInputs(plan,variantId){
plan.productEvidence.sellingPoints?.selected]);
}
function changedProductionFields(previous,current,variantId){
const inputs=value=>{
const {variants,...brief}=value.productEvidence?.brief??{};
return {brief,variant:variants?.find(row=>row.id===variantId)??{},
options:{multipleVariants:(variants?.length??0)>1,
sellingPoints:value.productEvidence?.sellingPoints?.selected}};
};
const before=inputs(previous),after=inputs(current);
const changed=Object.keys(before).flatMap(group=>
[...new Set([...Object.keys(before[group]),...Object.keys(after[group])])]
.filter(field=>JSON.stringify(before[group][field])!==JSON.stringify(after[group][field]))
.map(field=>group==='options'?field:group+'.'+field));
return changed.length?changed:['revisions.creation'];
}
function slotAttempts(slot, record) {
const reviews=(record?.reviewHistory??[]).filter(row=>row.verdict==='revise');
const latest=record?.review;
@ -551,7 +566,10 @@ export async function openProductionOperations(host,{target=host.productionGoal,
}
plan=value;
}else if(changed){
throw Error('当前款式资料已更新,请重新读取制作计划');
const oldVersion=plan.revisions?.creation??plan.version;
const newVersion=value.revisions?.creation??value.version;
const changedFields=changedProductionFields(plan,value,variantId);
throw Error(`当前款式资料已更新(版本 ${oldVersion} → ${newVersion},变化字段 ${changedFields.join('、')})。请用 plan_production 刷新制作计划后继续。`);
}
return value;
};
@ -681,8 +699,7 @@ export async function openProductionOperations(host,{target=host.productionGoal,
const args={version:(await current()).version,intent,outputId,slotId:slot.id,productVariantId:variantId,...values};
let prepared;
const archive=async operation=>{
const candidateId=adopting?values.candidateId:
canvas.durableGenerationIds&&values.useProductReference!==true?operation.operationId:null;
const candidateId=adopting?values.candidateId:null;
prepared={...operation,intent,candidateId};
dispatchingImages.set(operation.operationId,undefined);
await save(slot,{[pendingKey]:prepared,...(!adopting?{state:'dispatching'}:null)});

View File

@ -8,7 +8,6 @@ export function canvasReplyTimedOut(error) {
/** Private parent/child pipes; no production terminal or general control socket. */
export class StdioCanvas {
durableGenerationIds = true;
constructor(call, documentId) { this.call = call; this.documentId = documentId; }
action(action, input = {}, execution) {
return this.call(action, { ...input, run: this.run, documentId: this.documentId,

View File

@ -0,0 +1,22 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { reviewProductionCandidate } from '../src/candidate-review.mjs';
test('candidate review lists copy identifiers and labels and accepts only identifiers',async()=>{
const slot={id:'cover',fieldId:'S01-I01',label:'主图'};
const pixels={type:'image',mimeType:'image/png',data:'fixture'};
const screenCopy=[{field:'K02',label:'颜色名称',text:'橡木'}];
const canvas={detailImages:async()=>({candidateId:'photo',referenceCount:1,images:[pixels,pixels]})};
const screen={image:pixels,details:{page:0,screenFingerprint:'fixture',slots:[slot],screenCopy,overlayLayers:[]}};
const runAgent=async(_slot,_system,prompt,[review])=>{
assert.deepEqual(JSON.parse(prompt).screenCopy,screenCopy);
const result={candidateId:'photo',verdict:'pass',reason:'颜色与文案相符',
checks:{structure:true,color:true,composition:true,evidence:true},
screenReview:{verdict:'pass',summary:'通过',imageIssues:[],overlayFixes:[],copyFixes:[]}};
assert.throws(()=>review.execute('',{...result,shownFields:[{field:'颜色名称',evidence:'橡木色'}]}),
/"field":"K02","label":"颜色名称"/u);
review.execute('',{...result,shownFields:[{field:'K02',evidence:'橡木色'}]});
};
const result=await reviewProductionCandidate({canvas,runAgent,slot,screen,candidateId:'photo',liveScreenCopy:screenCopy});
assert.equal(result.verdict,'pass');
});

View File

@ -1315,7 +1315,7 @@ test('a sibling variant edit leaves the current plan usable, and a local edit ca
const prepared=Promise.withResolvers();
t.after(()=>submit.resolve());
const canvas={
run:'native-run',documentId:3,durableGenerationIds:true,
run:'native-run',documentId:3,
workflowRead:async()=>({available:true,canvasFirst:true,version:creation,outputId,productVariantId:variantId,
revisions:{creation},template:{contentHash:'fixture'},totalSlots:1,slots:[{id:slotId,fieldId:'front',candidates:[]}],
productEvidence:{brief:{name:'餐桌',dimensions,note,variants:structuredClone(variants)}}}),
@ -1380,7 +1380,7 @@ test('a sibling variant edit leaves the current plan usable, and a local edit ca
creation++;
const stale=await generateAndWait(actions,request);
assert.equal(stale.phase,'failed');
assert.match(stale.reason,/当前款式资料已更新/u);
assert.match(stale.reason,/当前款式资料已更新.*版本 2 → 3.*variant\.colorName/u);
assert.equal(submissions.length,1);
const plan=await actions.plan_production();
assert.equal(plan.product.variant.colorName,'烟熏橡木');
@ -1401,7 +1401,7 @@ test('a lost native acknowledgement can be recovered with the saved generation o
let recoveredStatus='unknown';
const tailWatchClock=tailClock();
const canvas={
durableGenerationIds:true,run:'original-run',documentId:23,
run:'original-run',documentId:23,
workflowRead:async()=>({available:true,canvasFirst:true,version:1,outputId:'detail',productVariantId:'ink',
template:{contentHash:'fixture'},totalSlots:1,slots:[{id:slotId,fieldId:'front',label:'正面图',candidates:[]}]}),
detailCopyFields:async()=>({fields:[]}),delta:async()=>{},

View File

@ -315,12 +315,12 @@ test('await_image_slots releases a candidate review that never submits a valid c
const {host,actions}=await fixture(t);
const candidateId=randomUUID();
host.canvas.detailImages=async()=>({candidateId,referenceCount:1,images:[pixels,pixels],
relatedCopy:[{field:'wood',text:'橡胶木'}]});
relatedCopy:[{field:'wood',label:'木材',text:'橡胶木'}]});
const worker=await usePiWorker(t,host,'review_candidate',(round,previous)=>{
if(round>1){
const reason=previous.content[0].text;
for(const fact of [`candidateId "wrong-${round-1}"`,`本次可用 candidateId "${candidateId}"`,
'shownFields[0].field "unknown"','本次可用 field ["wood","title-2"]'])assert.ok(reason.includes(fact),reason);
'shownFields[0].field "unknown"','本次可用 field [{"field":"wood","label":"木材"},{"field":"title-2"}]'])assert.ok(reason.includes(fact),reason);
}
return {screenReview:pass,candidateId:`wrong-${round}`,verdict:'pass',reason:'与原图相符',
checks:{structure:true,color:true,composition:true,evidence:true},shownFields:[{field:'unknown',location:'画面中央'}]};