From 66ce00b0f80f577498e84efddccee203dff091e6 Mon Sep 17 00:00:00 2001 From: WuYongJie <549727955@qq.com> Date: Thu, 26 Nov 2026 04:17:37 +0800 Subject: [PATCH] fix(xiaoyi): keep valid image delegations in a mixed batch --- .../src/production-operations.mjs | 35 +++++++++------- .../test/production-operations.test.mjs | 40 ++++++++++++++++++- docs/development/xiaoyi/implementation.md | 9 +++++ 3 files changed, 69 insertions(+), 15 deletions(-) diff --git a/apps/detail-agent-pi/src/production-operations.mjs b/apps/detail-agent-pi/src/production-operations.mjs index 1c3abdca..9bd930c8 100644 --- a/apps/detail-agent-pi/src/production-operations.mjs +++ b/apps/detail-agent-pi/src/production-operations.mjs @@ -10,6 +10,7 @@ import { executeWorkflow, reconcileWorkflowReceipt } from './workflow-execute.mj const obj=fields=>Type.Object(fields,{additionalProperties:false}); const text=Type.String({minLength:1}); const ids=Type.Array(text); +const slotRef=Type.String({minLength:1,description:'优先填写 plan_production 返回的当前画布 fieldId;字段编号重复时使用对应的完整 id。'}); const layer=Type.Integer({minimum:1}); const page=Type.Integer({minimum:0}); const rev=Type.Integer({minimum:0}); @@ -26,7 +27,7 @@ const imageArgs=obj({ }); export const productionOperationTools = [ - ['plan_production','读取当前商品、模板、图位和资料索引。',obj({})], + ['plan_production','读取当前商品、模板、图位和资料索引。调用图位工具时优先使用 pictures 中的 fieldId。',obj({})], ['read_production_knowledge','读取已选模板的固定版本规则,按回执的 nextOffset 翻页。',obj({fileId:text,offset:optional(page)})], ['read_copy_fields','读取画布文字格、当前文案和修订号。指定 pageId 或 fieldId 时一并读取该范围的模板样稿与发布要求,供撰写和复核。',obj({ pageId:optional(Type.String()),fieldId:optional(Type.String()), @@ -34,17 +35,17 @@ export const productionOperationTools = [ ['write_copy_fields','写入指定文字格并记录与实拍、配图的关联。原生命令已经写过时可用 recordOnly 登记现有文字。retryWrite 表示本次没写入,请查看原因后继续。模板规定缺资料时留空的字段,可传空文字并用 reason 记录依据。',obj({ revision:rev,recordOnly:optional(Type.Boolean()),items:optional(Type.Array(obj({layer,text:Type.String(),sources:ids,pictures:ids,reason:optional(Type.String())}))), })], - ['read_slot_images','查看当前图位的实拍和模板原图。检视某张已生成候选时,附上回执中的 candidateId。',obj({slotId:text,candidateId:optional(Type.String()),adopted:optional(Type.Boolean())})], - ['generate_slot_image','制作一张候选。'+imageSourceDescription+' 已有未知生图时核查原编号。',obj({slotId:text,...imageArgs.properties})], - ['delegate_image_slots','把图位和可执行要求交给 Pi 子代理。子代理生成候选并返回;可以并发分派。',obj({ - jobs:Type.Array(obj({slotId:text,goal:text})), + ['read_slot_images','查看当前图位的实拍和模板原图。检视某张已生成候选时,附上回执中的 candidateId。',obj({slotId:slotRef,candidateId:optional(Type.String()),adopted:optional(Type.Boolean())})], + ['generate_slot_image','制作一张候选。'+imageSourceDescription+' 已有未知生图时核查原编号。',obj({slotId:slotRef,...imageArgs.properties})], + ['delegate_image_slots','把图位和可执行要求交给 Pi 子代理并行制作。每个图位单独返回已接收或无法定位的结果。',obj({ + jobs:Type.Array(obj({slotId:slotRef,goal:text})), })], ['await_image_slots','等待指定图位的任一子代理或验图返回。',obj({slotIds:optional(ids)})], ['review_image_slots','只读查看图位的候选、验图结论和原请求状态。省略 slotIds 或传空数组时查看全部。',obj({slotIds:optional(ids)})], ['check_image_slots','请验图代理审核指定候选,是否采用由你决定。wait=false 时先返回受理结果,可继续工作并用 review_image_slots 查看结论。',obj({ - wait:optional(Type.Boolean()),candidates:Type.Array(obj({slotId:text,candidateId:text,adopted:optional(Type.Boolean())})), + wait:optional(Type.Boolean()),candidates:Type.Array(obj({slotId:slotRef,candidateId:text,adopted:optional(Type.Boolean())})), })], - ['adopt_production_image','采用你选择的候选,返回实际的画布放置回执。',obj({slotId:text,candidateId:text,fit:optional(fit)})], + ['adopt_production_image','采用你选择的候选,返回实际的画布放置回执。',obj({slotId:slotRef,candidateId:text,fit:optional(fit)})], ['reconcile_image_slots','按已保存的原操作或原候选号核查结果。',obj({slotIds:optional(ids)})], ['read_output_screen','读取当前画布的实际像素。page 指定单屏。用 pages 一次查看多屏,再分别记录结论。屏号从 0 开始。',obj({ page:optional(page),pages:optional(Type.Array(page)), @@ -79,10 +80,15 @@ export async function openProductionOperations(host) { } const knowledge=productionKnowledge(host.productionSkills?.knowledge??host.knowledgeContext); const reviews=productionKnowledge(host.productionSkills?.knowledge??host.knowledgeContext,'review'); - const matches=id=>{ + const findSlot=reference=>{ + const id=reference.trim(); const named=byField.get(id); - const slot=byId.get(id)??(named?.length===1?named[0]:null); - if(!slot)throw Error('图位不属于当前制作画布'); + return byId.get(id)??(named?.length===1?named[0]:null); + }; + const slotNotFound='图位不属于当前制作画布,请使用制作计划中的 fieldId'; + const matches=reference=>{ + const slot=findSlot(reference); + if(!slot)throw Error(slotNotFound); return slot; }; const selections=slotIds=>slotIds?.length?[...new Set(slotIds.map(matches))]:slots; @@ -311,9 +317,10 @@ export async function openProductionOperations(host) { async read_slot_images(args){return imageResult(await readImages(args.slotId,args));}, generate_slot_image({slotId,...args},signal){return generate(matches(slotId),args,signal);}, async delegate_image_slots({jobs:requested},signal){ - const assigned=[]; + const assigned=[],unmatched=[]; for(const {slotId,goal} of requested){ - const slot=matches(slotId); + const slot=findSlot(slotId); + if(!slot){unmatched.push({slotId,reason:slotNotFound});continue;} if(jobs.has(slot.id)){assigned.push({id:slot.id,state:'already_running'});continue;} const row={number:Math.max(0,...[...jobs.values()].map(job=>job.row.number))+1,slotId:slot.id,label:slot.label,step:'正在准备',active:true}; const generateTool={name:'generate_slot_image',label:'制作候选',description:'制作一张候选。'+imageSourceDescription, @@ -337,8 +344,8 @@ export async function openProductionOperations(host) { jobs.set(slot.id,{row,run}); assigned.push({id:slot.id,state:'assigned'}); } - await notice('子代理正在制作'); - return {assigned}; + if(assigned.length)await notice('子代理正在制作'); + return {assigned,...(unmatched.length?{unmatched}:{})}; }, async await_image_slots({slotIds}){ const wanted=new Set(selections(slotIds).map(slot=>slot.id)); diff --git a/apps/detail-agent-pi/test/production-operations.test.mjs b/apps/detail-agent-pi/test/production-operations.test.mjs index 6728e88b..d15fa71c 100644 --- a/apps/detail-agent-pi/test/production-operations.test.mjs +++ b/apps/detail-agent-pi/test/production-operations.test.mjs @@ -7,6 +7,44 @@ import { openProductionOperations } from '../src/production-operations.mjs'; import { cleanup } from './cleanup.mjs'; import { bindRecovery } from '../src/desktop-host.mjs'; +test('a malformed slot reference does not strand the other explicitly delegated slots',async t=>{ + const dir=await fs.mkdtemp(path.join(os.tmpdir(),'jiansun-pi-')); + t.after(()=>cleanup(dir)); + const slots=[ + {id:'lamp-full',fieldId:'overview',label:'灯具全景'}, + {id:'lamp-switch',fieldId:'switch',label:'开关局部'}, + ]; + const requests=[]; + const host={ + canvas:{ + workflowRead:async()=>({available:true,canvasFirst:true,outputId:'detail',productVariantId:'ivory', + template:{contentHash:'lamp-template'},totalSlots:slots.length,slots}), + delta:async()=>{}, + }, + productionGoal:{outputId:'detail',variantId:'ivory'}, + store:{dir,get:async()=>null}, + runDetailAgent:async(slot,_system,input)=>requests.push([slot,JSON.parse(input).goal]), + }; + const actions=await openProductionOperations(host); + const result=await actions.delegate_image_slots({jobs:[ + {slotId:'lamp-ful',goal:'不存在的图位'}, + {slotId:' overview ',goal:'实拍全景'}, + {slotId:'lamp-swtch',goal:'不存在的图位'}, + {slotId:'lamp-switch',goal:'实拍开关'}, + {slotId:'switch',goal:'同批重复分派'}, + ]}); + await actions.close(); + assert.deepEqual(requests,[['lamp-full','实拍全景'],['lamp-switch','实拍开关']]); + assert.deepEqual(result.assigned,[ + {id:'lamp-full',state:'assigned'}, + {id:'lamp-switch',state:'assigned'}, + {id:'lamp-switch',state:'already_running'}, + ]); + assert.deepEqual(result.unmatched.map(row=>row.slotId),['lamp-ful','lamp-swtch']); + assert.ok(result.unmatched.every(row=>row.reason.includes('fieldId'))); + assert.deepEqual(await actions.delegate_image_slots({jobs:[]}),{assigned:[]}); +}); + test('Pi chooses each image operation and keeps an unresolved paid request on its original',async t=>{ const dir=await fs.mkdtemp(path.join(os.tmpdir(),'jiansun-pi-')); t.after(()=>cleanup(dir)); @@ -148,7 +186,7 @@ test('Pi chooses each image operation and keeps an unresolved paid request on it {slotId:'lamp?',candidateId:'other-candidate'}, {slotId:'lamp',candidateId:'existing-candidate'}, ]}); - assert.deepEqual(invalid,{slotId:'lamp?',candidateId:'other-candidate',error:'图位不属于当前制作画布'}); + assert.deepEqual(invalid,{slotId:'lamp?',candidateId:'other-candidate',error:'图位不属于当前制作画布,请使用制作计划中的 fieldId'}); assert.equal(checked.verdict,'pass'); assert.equal(modelCalls,1); assert.equal(submissions.length,2,'verifying must not adopt or generate'); diff --git a/docs/development/xiaoyi/implementation.md b/docs/development/xiaoyi/implementation.md index 023a81b4..0756a1a2 100644 --- a/docs/development/xiaoyi/implementation.md +++ b/docs/development/xiaoyi/implementation.md @@ -548,3 +548,12 @@ R7 原生 `f101fda3`、Agent `4ee5a5b4` 用最新构建新建电脑桌项目, - 生图本机记录 19 份,18 份完成,1 笔未知保留原号。正常关闭该隔离窗口时没有在途派发。17 笔已取得原号的普通候选仍使用旧构建,实际出站任务文本与其冻结候选均不一致。刷新模型线路和冻结提示词的实机验证接到 R8。 证据位于 `batch-09/desk-published-copy-r7/`。运行记录 `run-evidence.json`、工具计时 `tool-timing.json`、工具错误 `codemode-errors.json`、模型与生图记录 `activity-summary.json`、保存稿 `disk-draft-inspection.json`、普通候选摘要 `ordinary-image-dispatched-prompt.json`、交付核查 `export-verification.json`、原生重开 `export-native-reopen.json`、关窗记录 `window-closed-after-settlement.json`。 + + +### 图位批次逐项返回 + +电脑桌 R8 首批分派提交 4 个图位。首个长编号漏掉一个字符,其余 3 个与计划中的图位完全相同。整批中断,Pi 在详情页仅写入第一批文案后将其保留为草稿。原始调用和比对证据在 `batch-09/desk-verified-route-r8/delegate-slot-id-evidence.json`。 + +`delegate_image_slots` 逐项解析当前画布的图位。有效项继续交给 Pi 子代理,无法解析的项单独回传输入和修正方式。工具说明优先提示使用模板短字段编号,重复编号仍可用完整 ID。界面只在有效分派时显示子代理状态。不增加新的申请条件或等待时间。无效编号不推断目标,当前项目和画布的范围仍由既有工具契约确定。 + +灯具夹具覆盖批次开头和中间各有一个无效编号、有效短编号和完整编号均分派、重复图位只启动一次、空批次返回无任务。两项定向回归和 261 项 Node 回归通过,见 `batch-09/batch-slot-delegation-targeted.log` 及 `batch-09/batch-slot-delegation-npm.log`。电脑桌实机使用独立运行包,不在运行期间替换工具。