合入瘦身第一批:切断派发与查单自动验图(R5-Z41)

This commit is contained in:
WuYongJie 2026-11-30 02:00:19 +08:00
commit a4546d627a
5 changed files with 64 additions and 62 deletions

View File

@ -30,10 +30,13 @@ export function summarizeImageWait({outputId,variantId,active,checking,timedOut,
const batches = [
['pendingWork',pendingWork,({slotId,candidateId,page,stage,elapsedMs})=>({slotId,candidateId,page,stage:excerpt(stage,40),elapsedMs})],
['screenChecks',screenChecks,screenSummary],
['generation',generation,({slotId,candidateId,operationId,requestId,sourceRequestId,phase,reason,error,resolutionSufficient,reworkOf,requestedSource,sourceNote,pendingOriginal,generationEvidence})=>({
slotId,candidateId,operationId,requestId,sourceRequestId,phase,reason:excerpt(reason??error,80),
resolutionSufficient,reworkOf,requestedSource,sourceNote:excerpt(sourceNote,60),pendingOriginal,
...(typeof generationEvidence?.promptHashMatches==='boolean'?{generationEvidence:{promptHashMatches:generationEvidence.promptHashMatches}}:null)})],
['generation',generation,({slotId,candidateId,operationId,requestId,sourceRequestId,phase,reason,error,resolutionSufficient,reworkOf,requestedSource,sourceNote,pendingOriginal,generationEvidence})=>{
const {actualPixels,promptHashMatches}=generationEvidence??{};
return {
slotId,candidateId,operationId,requestId,sourceRequestId,phase,reason:excerpt(reason??error,80),
resolutionSufficient,reworkOf,requestedSource,sourceNote:excerpt(sourceNote,60),pendingOriginal,
...(actualPixels||typeof promptHashMatches==='boolean'?{generationEvidence:{actualPixels:actualPixels??undefined,promptHashMatches}}:null)};
}],
['checks',checks,({slotId,candidateId,phase,verdict,recommendedAction,reason,error,drawLimitReached})=>({
slotId,candidateId,phase,verdict,recommendedAction,reason:excerpt(reason,80),error:excerpt(error),drawLimitReached})],
];

View File

@ -217,7 +217,7 @@ export async function callProductionTool(host, name, args, signal) {
const {referenceMode,mainImageAspects}=productionSettings(host.store,goal.template?.production);
return {referenceMode:referenceMode??null,...(!referenceMode?{referenceNotice:'参考方式未声明'}:null),
mainImageAspects:mainImageAspects??null,requestedOutputs:goal.requestedOutputs,pendingOutputs:goal.pendingOutputs,
workingOutput:null,dispatchReady:[],projectSlots:await projectSlotMap(host),template:{id,name,version,productionRoute},product:{...product,dimensions,note},
workingOutput:null,projectSlots:await projectSlotMap(host),template:{id,name,version,productionRoute},product:{...product,dimensions,note},
...(host.productionSkills?.versionNotice?{knowledgeVersionNotice:host.productionSkills.versionNotice}:null),
...(args.includeKnowledge?{knowledgeFiles:host.productionSkills?.files??[]}:null)};
}

View File

@ -93,7 +93,7 @@ export const productionOperationTools = [
referenceMode:optional(Type.Union([Type.Literal('template-base'),Type.Literal('composition-only'),Type.Literal('none')])),
mainImageAspects:optional(Type.Array(Type.String({pattern:'^[1-9][0-9]*:[1-9][0-9]*$'}),{minItems:1,uniqueItems:true})),
})],
['plan_production','读取商品、模板和成品进度。projectSlots 按成品和花色列出本轮所有图位的屏、图框像素、模板主体事实和候选号。framePending 表示像素值来自模板,实际图框待核对。adoptionRecorded 是已有采用记录的候选号,selectedCandidateId 是画布读到的当前采用。可指定输出和花色,省略时读取当前工作画布。按 slotIds 获取指定图位及其发布要求;includeKnowledge=true 列出固定版本的规则路径,可用 read 读取。返回已声明的参考方式和主图画幅。生图上限及来源适用于所有图位。dispatchReady 列出关联文案已写好且尚未派发或采纳的图位。图位工具优先使用 fieldId,重名时使用完整 id。',obj({...outputScope,slotIds:optional(ids),includeKnowledge:optional(Type.Boolean())})],
['plan_production','读取商品、模板和成品进度。projectSlots 按成品和花色列出本轮所有图位的屏、图框像素、模板主体事实和候选号。framePending 表示像素值来自模板,实际图框待核对。adoptionRecorded 是已有采用记录的候选号,selectedCandidateId 是画布读到的当前采用。可指定输出和花色,省略时读取当前工作画布。按 slotIds 获取指定图位及其发布要求;includeKnowledge=true 列出固定版本的规则路径,可用 read 读取。返回已声明的参考方式和主图画幅。生图上限及来源适用于所有图位。pictures 中的 copyReady 表示关联文案是否已写好。图位工具优先使用 fieldId,重名时使用完整 id。',obj({...outputScope,slotIds:optional(ids),includeKnowledge:optional(Type.Boolean())})],
['read_copy_fields','省略 pageId 和 fieldId 返回全页字段身份、当前文字、约束及修订号;指定页面或字段可读取图层样式、范围及关联字段。',obj({
pageId:optional(Type.String()),fieldId:optional(Type.String()),
})],
@ -102,7 +102,7 @@ export const productionOperationTools = [
basis:text,facts:optional(Type.Array(obj({kind:Type.Union(['quantity','material','color','specification'].map(value=>Type.Literal(value))),
productValue:text,templateValue:optional(text)})))})),
})],
['write_copy_fields','按 revision 原位写入指定文字格。可传 expectedText 核对原文,每个 layer 只传一次。原生命令已写过时可用 recordOnly 登记。dispatchReady 报告关联文案已写好且尚未派发或采纳的图位。retryWrite 表示画布暂不可写,rejected 列出保留原文的格子。可写入空文字并用 reason 记下依据。',obj({
['write_copy_fields','按 revision 原位写入指定文字格。可传 expectedText 核对原文,每个 layer 只传一次。原生命令已写过时可用 recordOnly 登记。copyUpdates 返回本次写入的文案事实。retryWrite 表示画布暂不可写,rejected 列出保留原文的格子。可写入空文字并用 reason 记下依据。',obj({
revision:rev,recordOnly:optional(Type.Boolean()),items:optional(Type.Array(obj({layer,text:Type.String(),expectedText:optional(Type.String()),sources:ids,pictures:ids,reason:optional(Type.String())}))),
})],
['read_slot_images','查看指定成品图位的同款实拍、模板构图和候选。adopted=true 读取当前可写画布上的实际回填。模板底图候选会同时返回该图位原图。用 includeReferences=true 查看本款实拍。',obj({
@ -111,12 +111,12 @@ export const productionOperationTools = [
['use_product_image','用本款原片或裁切区域创建候选。通过 adopt_production_image 回填时,放置回执会列出覆盖图位的模板叠层。',obj({...outputScope,slotId:slotRef,...productImageArgs})],
['transform_slot_image',transformDescription,obj({...outputScope,slotId:slotRef,...transformImageArgs})],
['prepare_image_request',imageRequestDescription,obj({...outputScope,slotId:slotRef,...preparationArgs})],
['dispatch_image_request','审阅准备回执后填写首个 requestId 确认派发生图批次。宿主从该编号绑定的请求读取版本和哈希。使用 await_image_slots 或 review_image_slots 查看实际结果。',obj({...outputScope,...dispatchArgs})],
['dispatch_image_request','审阅准备回执后填写首个 requestId 确认派发生图批次。宿主从该编号绑定的请求读取版本和哈希。使用 await_image_slots 或 review_image_slots 查看实际结果,状态为 complete 的候选可用 check_image_slots 验图。',obj({...outputScope,...dispatchArgs})],
['delegate_image_slots','异步分派制作任务。每个 job 的 slotId 是主图位,reuseTargets 可列同花色的额外目标图位,每项含 slotId 和可选 outputId。组内助手可查同花色候选并裁切到组内图位,可写画布上的候选可显式采用。返回分派状态与待写文案字段。',obj({
...outputScope,jobs:Type.Array(obj({slotId:slotRef,goal:text,reuseTargets:optional(Type.Array(reuseTarget)),reworkCandidateId:optional(Type.String({description:'返工时,指定之前被退回的候选号。'}))})),
})],
['await_image_slots','等待任一在途制作、验图或生图请求返回,提供状态、编号和修改摘要。单次最多等待 3 分钟,超时后原工作继续。省略 slotIds 时也关注整屏复核,完整意见用 read_screen_review 按屏读取;图位详情用 review_image_slots。omitted 是因体积限制省略的条数。未知结果用 reconcile_image_slots 核查,waiting_canvas 表示等待可写画布。',obj({...outputScope,slotIds:optional(ids)})],
['review_image_slots','只读查看指定成品和花色的候选、验图、原请求、覆盖统计与整屏复核进度。screensReadyForReview 是图位已齐、当前画面待复核的多图位屏。dispatchReady 列出关联文案已写好且尚未派发或采纳的图位;waiting_canvas 的图位在等待切回可写画布。指定 slotIds 查看详情,或在 slotIds 填写一个图位并指定 candidateId 查看实际候选像素;批量详情超出预算时返回摘要,用 nextOffset 作为 offset 翻页,再用单个 slotId 查看全文。',obj({...outputScope,slotIds:optional(Type.Array(Type.String())),candidateId:optional(text),offset:optional(Type.Integer({minimum:0}))})],
['await_image_slots','等待任一在途制作、验图或生图请求返回,提供状态、编号和修改摘要。状态为 complete 的候选可用 check_image_slots 验图。单次最多等待 3 分钟,超时后原工作继续。省略 slotIds 时也关注整屏复核,完整意见用 read_screen_review 按屏读取;图位详情用 review_image_slots。omitted 是因体积限制省略的条数。未知结果用 reconcile_image_slots 核查,waiting_canvas 表示等待可写画布。',obj({...outputScope,slotIds:optional(ids)})],
['review_image_slots','只读查看指定成品和花色的候选、验图、原请求、覆盖统计与整屏复核进度。screensReadyForReview 是图位已齐、当前画面待复核的多图位屏。waiting_canvas 的图位在等待切回可写画布。指定 slotIds 查看详情,或在 slotIds 填写一个图位并指定 candidateId 查看实际候选像素;批量详情超出预算时返回摘要,用 nextOffset 作为 offset 翻页,再用单个 slotId 查看全文。',obj({...outputScope,slotIds:optional(Type.Array(Type.String())),candidateId:optional(text),offset:optional(Type.Integer({minimum:0}))})],
['list_project_images','列出本项目已完成且可读的候选,包括有采纳记录的图。可按来源成品和花色筛选,生图次数取自宿主已派发的记录。sourceCandidateId 可引用任一成品的同花色候选做本地变换或复用。用 nextOffset 作为 offset 翻页,candidateId 展开单条。',obj({...outputScope,candidateId:optional(Type.String()),offset:optional(Type.Integer({minimum:0}))})],
['read_archived_images','只读查找其他本机项目同款的历史候选。可选 slotIds 查看有对应图位的结果。不同模板或花色的已完成候选也可放入当前图位复核。用 nextOffset 作为 offset 翻页,candidateId 展开单条,可用 projectId 指定来源项目。',obj({
slotIds:optional(Type.Array(Type.String())),candidateId:optional(Type.String()),projectId:optional(Type.String()),offset:optional(Type.Integer({minimum:0})),
@ -129,7 +129,7 @@ export const productionOperationTools = [
})],
['adopt_production_image','采用选定的候选,返回画布修订和模板叠层。可用 reason 记录采用理由。单图位屏与已有验图画面一致时附复核结论。screensReadyForReview 列出图位已齐、待复核的多图位屏。可用 read_output_screen 查看整屏合成画面。',obj({slotId:slotRef,candidateId:text,fit:optional(fit),reason:optional(text)})],
['retire_production_image','清理你已判为失败的当前图位候选,保留原因、提示词和原请求记录。若该图已在画布上,回执会给出应替换的图层。',obj({slotId:slotRef,candidateId:text,reason:text})],
['reconcile_image_slots','按已保存的原操作或原候选号核查结果。未绑定画布时核查本轮项目输出,可用完整图位 id 缩小范围。unknown 继续核查原号,结果有留存时按原号取回,不重新付费。expired 表示原结果已不可取回:网关确认结果过期(HTTP 410)、结果链接下载返回 404 或 410,或原请求在 180 秒恢复预算用完后仍是 unresolved。expired 可以为同图位另备新请求;已派发的原请求仍计入该图位的生图次数上限。',obj({...outputScope,slotIds:optional(ids)})],
['reconcile_image_slots','按已保存的原操作或原候选号核查结果。状态为 complete 的候选可用 check_image_slots 验图。未绑定画布时核查本轮项目输出,可用完整图位 id 缩小范围。unknown 继续核查原号,结果有留存时按原号取回,不重新付费。expired 表示原结果已不可取回:网关确认结果过期(HTTP 410)、结果链接下载返回 404 或 410,或原请求在 180 秒恢复预算用完后仍是 unresolved。expired 可以为同图位另备新请求;已派发的原请求仍计入该图位的生图次数上限。',obj({...outputScope,slotIds:optional(ids)})],
['read_output_screen',`读取整屏合成画面、模板差异摘要、overlayLayers、slotGeometry 和 annotationLayout。局部查看用 page 和 region(画布坐标 [x,y,w,h]),zoom 为 1–4 倍,图上网格标的是原画布坐标。annotationLayout 提供可见文字、线端点、穿线长度、主体框重叠比例和双向最近距离。用 includeTemplateImage 读取模板原屏,用 templateLayerId 查具体图层的完整原值与现值。若返回 nextChangeOffset,可用 templateChangeOffset 继续读差异。subjectBounds 是画布坐标 [x,y,w,h],由放置后的像素与边缘背景的色差估测,并裁到图位可见框内。测不出时由 subjectBoundsReason 说明原因。page 指定单屏,pages 可按需查看 2–4 屏,屏号从 0 开始。只保留最新一次查看图片。${OVERLAY_SCREEN_FIELDS}`,obj({
page:optional(page),pages:optional(Type.Array(page)),
region:optional(Type.Tuple([Type.Integer(),Type.Integer(),Type.Integer({minimum:1}),Type.Integer({minimum:1})])),
@ -637,10 +637,6 @@ export async function openProductionOperations(host,{target=host.productionGoal,
return new Map(linked.map(slot=>[slot.id,pending.filter(row=>slot.relatedFields.includes(row.field))
.map(({field,label,currentText,templateSample})=>({fieldId:field,label,...(templateSample?{templateExample:currentText}:null)}))]));
};
const dispatchReady=(selected,pending)=>selected.filter(slot=>
(!slot.relatedFields?.length||pending.has(slot.id)&&!pending.get(slot.id).length)
&& !slotWorking(slot.id)&&!slot.selectedCandidateId&&!(canvasReady&&filled.has(slot.id))
&& !nativeGenerations(slot).length).map(({fieldId,label})=>({fieldId,label}));
const liveSlotCopy=async(slot,screenFields)=>{
const copyFields=screenFields??((canvasReady?(await suspendedCopy)?.snapshot:await copySnapshot())??{}).fields;
const journalCopy=Object.values(evidenceMatches(plan)?journal.copyEvidence??{}:{});
@ -899,16 +895,12 @@ export async function openProductionOperations(host,{target=host.productionGoal,
const run=Promise.resolve().then(()=>dispatchImageRequest(slot,approval,request,row.number,submission.resolve))
.catch(error=>({candidateId:id,operationId:id,reason:error.message,
...(error.dispatched===false?{phase:'failed'}:{phase:'unknown',pendingOriginal:id})}))
.then(async result=>{
.then(result=>{
if(result.candidates){
for(const member of result.candidates){
generation.set(member.id,{slotId:slot.id,candidateId:member.id,operationId:member.id,
phase:member.status,reason:member.message,generationEvidence:member.generationEvidence});
}
const completed=result.candidates.filter(member=>member.status==='complete');
if(completed.length)await operations.check_image_slots({
candidates:completed.map(member=>({slotId:slot.id,candidateId:member.id})),
},signal);
}
return {slotId:slot.id,...result};
})
@ -1182,7 +1174,7 @@ export async function openProductionOperations(host,{target=host.productionGoal,
return {outputId,variantId,workingOutput:workingOutputId?{outputId:workingOutputId,variantId:workingVariantId}:null,
fieldConflicts:await fieldConflicts(await copySnapshot(),plan),fieldRequirements:fieldRequirements(plan),
template,product:{name,dimensions,note,variant:variant&&{id:variant.id,colorName:variant.colorName}},
candidatesPerSlot,maxCandidatesPerSlot:maxGenerationAttempts,maxGenerationAttempts,generationLimitSource,...picturePlan,...(productUpdate?{productUpdate}:null),pictures,dispatchReady:dispatchReady(selected,pendingCopy),
candidatesPerSlot,maxCandidatesPerSlot:maxGenerationAttempts,maxGenerationAttempts,generationLimitSource,...picturePlan,...(productUpdate?{productUpdate}:null),pictures,
inFlightImages:(await pendingNative()).map(row=>row.candidateId),
...(includeKnowledge?{knowledgeFiles:host.productionSkills?.files??[]}:null),
...(host.productionSkills?.versionNotice?{knowledgeVersionNotice:host.productionSkills.versionNotice}:null),
@ -1221,8 +1213,7 @@ export async function openProductionOperations(host,{target=host.productionGoal,
write_copy_fields({revision,recordOnly,items=[]},signal){
return serialize(async()=>{
const noUpdates={total:0,truncated:false,items:[]};
const ready=async()=>dispatchReady(await liveSlots(),await pendingCopyBySlot(slots));
if(!items.length)return {appliedLayers:[],revision:(await canvas.read()).revision,copyUpdates:noUpdates,dispatchReady:await ready()};
if(!items.length)return {appliedLayers:[],revision:(await canvas.read()).revision,copyUpdates:noUpdates};
const layers=new Set();
for(const {layer} of items){
if(!Number.isSafeInteger(layer)||layer<1)throw Error(`无效的文字格 layer ${layer},请使用文案读取回执中的编号`);
@ -1234,7 +1225,7 @@ export async function openProductionOperations(host,{target=host.productionGoal,
if(!recordOnly){
const edits=items.map(({layer,text,expectedText})=>({layer,text,...(expectedText===undefined?null:{expectedText})}));
result=await canvas.commitDetailCopy(edits,revision,signal);
if(result.retryWrite || !result.appliedLayers?.length)return {...result,appliedLayers:[],copyUpdates:noUpdates,dispatchReady:await ready()};
if(result.retryWrite || !result.appliedLayers?.length)return {...result,appliedLayers:[],copyUpdates:noUpdates};
}
return await registerCopy(result);
@ -1266,7 +1257,7 @@ export async function openProductionOperations(host,{target=host.productionGoal,
return copyUpdateItem(field,row.text);
}),
};
return {...result,appliedLayers:applied.map(row=>row.layer),revision:snapshot.revision,copyUpdates,...(productUpdate?{productUpdate}:null),dispatchReady:await ready()};
return {...result,appliedLayers:applied.map(row=>row.layer),revision:snapshot.revision,copyUpdates,...(productUpdate?{productUpdate}:null)};
}
});
},
@ -1449,28 +1440,25 @@ export async function openProductionOperations(host,{target=host.productionGoal,
row.step='正在准备';
notice('子代理正在制作');
const prior=journal.items[slot.id];
const reworkId=reworkCandidateId?.trim()||undefined;
const candidateId=reworkCandidateId?.trim();
let rejectedImage;
if(reworkId||prior?.review||prior?.reviewHistory?.length){
if(candidateId){
const live=(await readSlots()).slots.find(next=>next.id===slot.id)??slot;
const {attemptCount,rejections,reviews}=slotAttempts(live,prior);
const feedback=reworkId?reviews.findLast(entry=>entry.candidateId===reworkId):reviews.at(-1);
const candidateId=reworkId??feedback?.candidateId;
if(candidateId){
const old=await readImages(slot.id,{candidateId,includeProductReferences:false,includeTemplateReference:false})
.catch(error=>({unavailable:error.message}));
if(old.candidateId===candidateId&&old.images?.at(-1)?.type==='image')rejectedImage=old.images.at(-1);
const attempt=prior?.attempts?.find(entry=>entry.candidateId===candidateId);
rework={candidateId,attempt:attemptCount+1,reason:feedback?.reason,
recommendedAction:feedback?.recommendedAction,canvasTransform:feedback?.canvasTransform,
suggestions:feedback?.mustRedo,generationFixes:feedback?.generationFixes,
previousPrompt:old.candidateId===candidateId?old.candidatePrompt??undefined:undefined,
previousInstruction:attempt?.prompt,
previousOutcomes:rejections,
...(!feedback?{reviewUnavailable:'此候选号没有留存退回回执'}:null),
...(rejectedImage?{imageAttached:true}:{unavailable:old.unavailable??'未读到这张候选的原图'}),
};
}
const feedback=reviews.findLast(entry=>entry.candidateId===candidateId);
const old=await readImages(slot.id,{candidateId,includeProductReferences:false,includeTemplateReference:false})
.catch(error=>({unavailable:error.message}));
if(old.candidateId===candidateId&&old.images?.at(-1)?.type==='image')rejectedImage=old.images.at(-1);
const attempt=prior?.attempts?.find(entry=>entry.candidateId===candidateId);
rework={candidateId,attempt:attemptCount+1,reason:feedback?.reason,
recommendedAction:feedback?.recommendedAction,canvasTransform:feedback?.canvasTransform,
suggestions:feedback?.mustRedo,generationFixes:feedback?.generationFixes,
previousPrompt:old.candidateId===candidateId?old.candidatePrompt??undefined:undefined,
previousInstruction:attempt?.prompt,
previousOutcomes:rejections,
...(!feedback?{reviewUnavailable:'此候选号没有留存退回回执'}:null),
...(rejectedImage?{imageAttached:true}:{unavailable:old.unavailable??'未读到这张候选的原图'}),
};
}
const live=await liveSlot(slot);
const status=slotDrawStatus(live);
@ -1570,7 +1558,6 @@ export async function openProductionOperations(host,{target=host.productionGoal,
const summary=await progressSummary();
const result={outputId,variantId,active:jobs.size,coverage,progressSummary:summary,
screensReadyForReview:summary?.screensReadyForReview??[],
dispatchReady:dispatchReady(selected,await pendingCopyBySlot(selected)),
pictures:selected.map(slot=>{
const {id,fieldId,label,selectedCandidateId,candidates}=slot;
const record=journal.items[id];
@ -1717,8 +1704,6 @@ export async function openProductionOperations(host,{target=host.productionGoal,
const originals=await Promise.all(pending.filter(row=>ids.has(row.slotId))
.map(row=>readNativeOriginal(canvas,row,canvasReady?output:undefined)));
signal?.throwIfAborted();
const recovered=originals.filter(row=>row.phase==='complete'&&row.generationEvidence);
if(recovered.length)await operations.check_image_slots({candidates:recovered},signal);
const pendingSlots=new Set(originals.map(row=>row.slotId));
return [...originals,...results.filter(row=>row.phase!=='none'||!pendingSlots.has(row.slotId))];
},

View File

@ -289,7 +289,7 @@ test('explicit tools share one Pi transcript and submit each real canvas revisio
assert.match(instructions,/锁定的企业 Skill 及小壹补充/);
assert.match(instructions,/native_catalog 查原生命令与参数/);
const write=context.messages.find(message=>message.role==='toolResult'&&message.toolName==='write_copy_fields');
if(write)assert.deepEqual(JSON.parse(write.content[0].text),{appliedLayers:[1],revision:8,dispatchReady:[]});
if(write)assert.deepEqual(JSON.parse(write.content[0].text),{appliedLayers:[1],revision:8});
const call=steps.shift();
return call?stream([{type:'toolCall',name:call[0],id:'tool-'+(++serial),arguments:call[1]??{}}]):
stream([{type:'text',text:'当前进展已记在项目里。'}]);

View File

@ -671,7 +671,6 @@ test('a switched-away worker prepares and dispatches under its original output a
assert.deepEqual(worker.output,detail);
assert.deepEqual(worker.prompt.screenCopy.map(row=>row.text),['榫接结构']);
await callProductionTool(host,'open_production_output',main);
assert.deepEqual((await callProductionTool(host,'review_image_slots',detail)).dispatchReady,[]);
proceed.resolve();
const {slotId,instructions,id}=await posted.promise;
assert.deepEqual({slotId,instructions},{slotId:slot.id,instructions:'呈现榫接结构'});
@ -1057,7 +1056,8 @@ test('candidate review leaves placement to the main agent, even with an old temp
const policy={version:'studio-review-v3',candidateCount:2,priorityChecks:['templateStyle']};
const ledger=store.ledger('detail','oak');
const slotId='main-photo';
const posts=[],placements=[],seen=[];
const posts=[],placements=[],seen=[],imageReads=[];
const generationEvidence={actualPixels:{width:1,height:1}};
const firstStarted=Promise.withResolvers(), complete=Promise.withResolvers();
const tailWatchClock=tailClock();
const image={type:'image',mimeType:'image/png',
@ -1073,9 +1073,10 @@ test('candidate review leaves placement to the main agent, even with an old temp
async detailRecover(recoveredSlot,{candidateId}){
assert.equal(recoveredSlot,slotId);
assert.equal(candidateId,posts[0]);
return {id:candidateId,status:'complete'};
return {id:candidateId,status:'complete',generationEvidence};
},
async detailImages(_slot,candidateId,options){
imageReads.push(candidateId);
assert.deepEqual(options,{candidatePixels:true,includeTemplateReference:false});
return {candidateId,referenceCount:1,candidateFile:{width:1,height:1,...(recoverA?{sha256:digest}:null)},
prompt:'桌腿接口近景',requirements:'同一屏的各个部位分别用对应图位表现。桌腿接口近景。',
@ -1138,10 +1139,12 @@ test('candidate review leaves placement to the main agent, even with an old temp
const [recovered]=await actions.reconcile_image_slots({slotIds:[slotId]});
assert.equal(recovered.operationId,a.operationId);
assert.equal(recovered.phase,'complete');
assert.deepEqual(recovered.generationEvidence,generationEvidence);
}
for(const draft of [a,b])await actions.dispatch_image_request(approve(draft));
while(actions.active)await actions.await_image_slots({});
assert.deepEqual(posts,ids);
assert.deepEqual(imageReads,[],'dispatch and recovery leave review to the caller');
const [first]=await actions.check_image_slots({wait:true,candidates:[{slotId,candidateId:a.requestId}]});
assert.equal(first.adoption,undefined);
assert.deepEqual(placements,[]);
@ -1223,9 +1226,6 @@ test('plans and delegate receipts report only linked pending copy and enqueue ev
t.after(()=>actions.close());
const readiness=async()=>Object.fromEntries((await actions.plan_production()).pictures.map(row=>[row.id,row.copyReady]));
assert.deepEqual(await readiness(),{front:false,detail:true,photo:true});
const ready=[{fieldId:'detail-image',label:'细节图'},{fieldId:'photo-image',label:'实拍图'}];
assert.deepEqual((await actions.plan_production()).dispatchReady,ready);
assert.deepEqual((await actions.review_image_slots({})).dispatchReady,ready);
const receipt=await actions.delegate_image_slots({jobs:slots.map(({fieldId})=>({slotId:fieldId,goal:'展示本款实拍细节'}))});
assert.deepEqual(receipt.assigned.map(({id,state,pendingCopyFields})=>({id,state,pendingCopyFields})),[
@ -1255,9 +1255,8 @@ test('plans and delegate receipts report only linked pending copy and enqueue ev
const written=await actions.write_copy_fields({revision:1,items:[
{layer:1,text:'榫卯结构'},{layer:2,text:'牢固连接'},
]});
assert.deepEqual(written.dispatchReady,[{fieldId:'front-image',label:'首屏图'}]);
assert.deepEqual((await actions.plan_production()).dispatchReady,written.dispatchReady);
assert.deepEqual((await actions.review_image_slots({})).dispatchReady,written.dispatchReady);
assert.deepEqual(written.appliedLayers,[1,2]);
assert.deepEqual(await readiness(),{front:true,detail:true,photo:true});
Object.assign(title,{currentText:'实木餐椅',templateSample:false});
tagline.currentText='弧形靠背';
pending.splice(0,2);
@ -1296,6 +1295,11 @@ test('a rework delegate sees the rejected image, exact previous prompt and revie
},
async runDetailAgent(slotId,system,prompt,tools,images){
assert.equal(slotId,'photo');
if(JSON.parse(prompt).goal==='展示商品'){
assert.equal(JSON.parse(prompt).rework,undefined);
assert.deepEqual(images,[]);
return;
}
assert.match(system,/附件含退回图、验图回执和上次实发提示词/u);
assert.match(system,/reworkChange 记录改动/u);
const context=JSON.parse(prompt);
@ -1322,6 +1326,9 @@ test('a rework delegate sees the rejected image, exact previous prompt and revie
}};
imageBridge(host,async args=>{requests.push(args);return {status:'complete'};},()=> 'replacement');
const ops=await openProductionOperations(host);
await ops.delegate_image_slots({jobs:[{slotId:'front',goal:'展示商品'}]});
while(ops.active)await ops.await_image_slots({slotIds:['front']});
assert.deepEqual(reads,[]);
await ops.delegate_image_slots({jobs:[{slotId:'front',goal:'改掉多余支撑',reworkCandidateId:'old'}]});
while(ops.active)await ops.await_image_slots({slotIds:['front']});
const {generation:[result]}=await ops.await_image_slots({slotIds:['front']});
@ -1766,8 +1773,7 @@ test('Pi chooses each image operation and keeps an unresolved paid request on it
await actions.read_copy_fields({pageId:' one ',fieldId:' compact '});
assert.deepEqual(copyReads.at(-1),{includeFilled:true,pageId:'one',fieldId:'compact'});
assert.deepEqual(await actions.write_copy_fields({revision,items:[]}),
{appliedLayers:[],revision,copyUpdates:{total:0,truncated:false,items:[]},
dispatchReady:slots.map(({fieldId,label})=>({fieldId,label}))});
{appliedLayers:[],revision,copyUpdates:{total:0,truncated:false,items:[]}});
assert.deepEqual(await actions.review_image_slots({slotIds:[]}), await actions.review_image_slots({}));
assert.deepEqual(await actions.review_image_slots({slotIds:[' ']}), await actions.review_image_slots({}));
const mixedLookup=await actions.review_image_slots({slotIds:['main-only-field',' lamp ','lamp-photo','']});
@ -2122,7 +2128,7 @@ test('copy progress verifies each screen fingerprint and clears reviews when pro
const first=new Map(saved.screenReviews).get(0);
assert.equal(first.screenFingerprint,fingerprint(0));
await observe(()=>write([[9,'浅色自然木纹']]),['verified','verified','filled','empty']);
assert.equal(slotReads,beforeHeartbeat.slotReads+1,'the copy receipt checks current slot readiness once');
assert.equal(slotReads,beforeHeartbeat.slotReads,'the copy receipt does not reload slot readiness');
await observe(()=>review(1),['verified','verified','verified','empty']);
slots[1].selectedCandidateId='replacement';
revision++;
@ -2274,8 +2280,16 @@ test('a host batch returns both original requests and blocks only its slot until
const b=await prepare('hero');
assert.equal((await ops.dispatch_image_request(approve(b))).pendingOriginal,a.requestId);
const side=await prepare('side');
await send(side,'side');
while((await ops.await_image_slots({slotIds:['side']})).checking){}
const completed=await send(side,'side');
const candidateIds=side.candidates.map(row=>row.requestId);
assert.deepEqual([...new Set(completed.generation.map(row=>row.candidateId))].sort(),candidateIds.toSorted());
for(const candidateId of candidateIds){
const receipt=completed.generation.find(row=>row.candidateId===candidateId&&row.generationEvidence?.actualPixels);
assert.equal(receipt?.phase,'complete');
assert.deepEqual(receipt.generationEvidence.actualPixels,pixels);
}
assert.deepEqual(reviewed,[]);
await ops.check_image_slots({wait:true,candidates:candidateIds.map(candidateId=>({slotId:'side',candidateId}))});
assert.equal(dispatched.length,4);
assert.deepEqual(reviewed.sort(),side.candidates.map(row=>row.requestId).sort());
const [sideStatus]=(await ops.review_image_slots({slotIds:['side']})).pictures;