From 704937bf4dc98dcaee5ad3a856fae9bfc107503d Mon Sep 17 00:00:00 2001 From: WuYongJie <549727955@qq.com> Date: Thu, 26 Nov 2026 18:08:41 +0800 Subject: [PATCH] Keep production active through image work and dispatch by prepared ID --- apps/detail-agent-pi/src/agent.mjs | 1 + apps/detail-agent-pi/src/production-goal.mjs | 2 +- apps/detail-agent-pi/src/production-operations.mjs | 14 +++++++++----- .../src/skills/product-image-sources/SKILL.md | 2 +- .../test/production-operations.test.mjs | 3 +++ .../test/project-repository.test.mjs | 2 +- 6 files changed, 16 insertions(+), 8 deletions(-) diff --git a/apps/detail-agent-pi/src/agent.mjs b/apps/detail-agent-pi/src/agent.mjs index c9bbd608..27063a10 100644 --- a/apps/detail-agent-pi/src/agent.mjs +++ b/apps/detail-agent-pi/src/agent.mjs @@ -61,6 +61,7 @@ references是用户提交时冻结的本轮引用;component为pixelMask或vect const PRODUCTION_SYSTEM = `你是小壹的制作 Agent。先读本项目适用的企业 Skill,并按它及模板在 PhotoCraft 制作和复核。由你决定要做什么、顺序、并行和返工。 用 plan_production 读取本轮输出和工作画布。尚未绑定时,单独调用 open_production_output 打开所选画布,收到已保存的绑定回执后再查询 native_catalog 或调用画布工具。打开失败时按回执处理,可重新打开或选择另一待制作输出。用户查看的页面和制作画布独立。 企业 Skill 中的命令行编修可在当前画布用等价的 PhotoCraft 原生命令完成。用已有产品资料写买家看得懂的文案,检查实际画面的图文对应、品牌元素和旧商品信息。 +读取文案和图位后,在当前输出继续写入、采用和复核。子代理工作期间可并行处理其他图文,收到回执后继续当前输出。保留草稿时说明本轮无法解除的具体阻塞。 复核后提交当前修订。PhotoCraft 按实际导出回执交接下一项。生图或画布操作结果未确认时按原编号核查。用简短中文说明实际进展。`; const plain = value => ({ content: [{ type: 'text', text: JSON.stringify(value) }], details: value }); diff --git a/apps/detail-agent-pi/src/production-goal.mjs b/apps/detail-agent-pi/src/production-goal.mjs index 958427f3..136be93f 100644 --- a/apps/detail-agent-pi/src/production-goal.mjs +++ b/apps/detail-agent-pi/src/production-goal.mjs @@ -112,7 +112,7 @@ export async function callProductionTool(host, name, args, signal) { catch(error) { if(host.productionOperations===pending)host.productionOperations=null; throw error; } signal?.throwIfAborted(); const result=await operations[name](args,signal); - if(name==='finish_production'||name==='defer_production_output'){ + if((name==='finish_production'||name==='defer_production_output')&&result.production){ host.goalStageResult=result; return {submitted:true,revision:result.production.canvasRevision}; } diff --git a/apps/detail-agent-pi/src/production-operations.mjs b/apps/detail-agent-pi/src/production-operations.mjs index 73c1ca24..809f73c8 100644 --- a/apps/detail-agent-pi/src/production-operations.mjs +++ b/apps/detail-agent-pi/src/production-operations.mjs @@ -45,7 +45,7 @@ const preparationArgs={ prefer2k:optional(Type.Boolean()), retryOf:optional(Type.String({description:'仅限已确认可重试的失败候选。'})), }; -const dispatchArgs={requestId:text,expectedRevision:rev,expectedHash:text}; +const dispatchArgs={requestId:text,expectedRevision:optional(rev),expectedHash:optional(text)}; export const productionOperationTools = [ ['open_production_output','打开本轮待制作的工作画布,返回已保存画布的绑定回执。用 plan_production 获取输出和花色。请单独调用,收到绑定回执后再查询原生命令或操作画布。',obj({outputId:text,variantId:text})], @@ -62,7 +62,7 @@ export const productionOperationTools = [ })], ['use_product_image','用本款原片或裁切区域创建候选,返回后可继续处理其他图位。',obj({slotId:slotRef,...productImageArgs})], ['prepare_image_request','保存完整生图请求。回执含可审阅的正式文本、实际参考顺序和模型参数,以及 requestId、revision 和 requestSpecHash。',obj({slotId:slotRef,...preparationArgs})], - ['dispatch_image_request','审阅准备回执后,以 requestId、expectedRevision 和 expectedHash 确认派发。使用 await_image_slots 或 review_image_slots 查看实际结果。',obj(dispatchArgs)], + ['dispatch_image_request','审阅准备回执后填写 requestId 确认派发。宿主从该编号绑定的请求读取版本和哈希。使用 await_image_slots 或 review_image_slots 查看实际结果。',obj(dispatchArgs)], ['delegate_image_slots','把图位和可执行要求交给 Pi 子代理并行制作。每个图位单独返回已接收或无法定位的结果。',obj({ jobs:Type.Array(obj({slotId:slotRef,goal:text,reworkCandidateId:optional(Type.String({description:'返工时,指定之前被退回的候选号。'}))})), })], @@ -86,7 +86,7 @@ export const productionOperationTools = [ ['record_screen_check','登记你对本屏实际画布的复核。',obj({ page,revision:rev,issues:Type.Array(obj({field:text,reason:text})), })], - ['defer_production_output','保留确有未解决问题的当前输出为草稿,记录具体缺项,交接其余输出。可从 plan_production 的 pendingOutputs 选择 nextOutput。',obj({reason:text,nextOutput})], + ['defer_production_output','在当前输出仍有本轮无法解决的阻塞时保留草稿,记录阻塞及剩余工作。制作或验图仍在执行时,继续可做的图文工作并用 await_image_slots 等回执。可从 plan_production 的 pendingOutputs 选择 nextOutput。',obj({reason:text,nextOutput})], ['finish_production','提交你已核验的当前输出给客户端保存和导出,客户端核对文件与提交版本。可从 plan_production 的 pendingOutputs 选择 nextOutput。',obj({ revision:rev,nextOutput,issues:optional(Type.Array(obj({field:optional(text),reason:text}))), })], @@ -356,6 +356,8 @@ export async function openProductionOperations(host) { const dispatchImageRequest=async(slot,approval,request,signal)=>{ signal?.throwIfAborted(); await current(); + approval={requestId:approval.requestId,expectedRevision:approval.expectedRevision??request.revision, + expectedHash:approval.expectedHash??request.requestSpecHash}; const {candidateSet}=request; if(candidateSet&&repository.candidateSet(slot.id,candidateSet.id).length!==candidateSet.policy.candidateCount){ throw Error('请先按政策准备齐全同批候选,再分别确认派发'); @@ -676,7 +678,7 @@ export async function openProductionOperations(host) { (args,activeSignal)=>useProductImage(slot,args,activeSignal),true), workerTool('prepare_image_request','准备并持久保存完整生图请求',preparationArgs, (args,activeSignal)=>prepareImageRequest(slot,{...args,reworkCandidateId:rework?.candidateId},activeSignal)), - workerTool('dispatch_image_request','用已审阅回执的 requestId、expectedRevision 和 expectedHash 确认派发',dispatchArgs, + workerTool('dispatch_image_request','审阅准备回执后填写 requestId 确认派发',dispatchArgs, (approval,activeSignal)=>{ const request=preparedRequest(approval.requestId,slot); row.step='正在生图'; @@ -936,7 +938,9 @@ export async function openProductionOperations(host) { return {page,issues}; }, async defer_production_output({reason,nextOutput}){ - await drain(); + const active=jobs.size,checking=pendingReviews().length; + if(active||checking)return {submitted:false,active,checking, + reason:'当前输出的制作或验图仍在执行,请继续可做的图文工作,并用 await_image_slots 读取回执后再判断。'}; await journalWrite; return {text:reason,production:{outputId,variantId,complete:false,issues:[{reason}],...(nextOutput?{nextOutput}:null)}}; }, diff --git a/apps/detail-agent-pi/src/skills/product-image-sources/SKILL.md b/apps/detail-agent-pi/src/skills/product-image-sources/SKILL.md index 1e1b07b2..ebdb933d 100644 --- a/apps/detail-agent-pi/src/skills/product-image-sources/SKILL.md +++ b/apps/detail-agent-pi/src/skills/product-image-sources/SKILL.md @@ -9,7 +9,7 @@ description: Use product image sources and Image Request tools in PhotoCraft. - `read_slot_images` 读取实拍、模板参考和候选。`use_product_image` 可直接用原片或指定裁切区域。 - 按已发布规则撰写完整的 `prompt`,包括商品外观、构图、颜色、参考用途和返工要求。用 `referenceIndexes` 指定发送的原片及顺序,按需指定模板参考、画幅规格或实拍合成。实拍合成时,提示词描述在模板场景中擦除旧商品,本款实拍由客户端合成。 -- 审阅 `prepare_image_request` 回执中的正式文本、参考顺序与模型参数。用该回执的 `requestId`、`revision` 和 `requestSpecHash` 确认 `dispatch_image_request` 的 `requestId`、`expectedRevision` 和 `expectedHash`。 +- 审阅 `prepare_image_request` 回执中的正式文本、参考顺序与模型参数。调用 `dispatch_image_request` 时填写该回执的 `requestId`,宿主从该编号绑定的请求读取版本和哈希。 - `plan_production` 返回 `autoAdoptionPolicy` 时,按 `candidateCount` 准备同批样本。第二张起传入首张的 `candidateSet.id` 和相同的正式请求。备齐后分别确认派发,完成后将整批编号交给 `check_image_slots`。验完会自动采用合格图,全部退回时可在图位回执查看待返工记录。 - `review_image_slots` 读取候选及已有结论,`check_image_slots` 委托独立审稿。返工可带原候选号和具体改动。用 `reconcile_image_slots` 查看原请求的结果。 - 用 `native_catalog`、`native_call` 在模板允许的范围内调整画布。用 `read_output_screen` 回看实际图框与文字。 diff --git a/apps/detail-agent-pi/test/production-operations.test.mjs b/apps/detail-agent-pi/test/production-operations.test.mjs index c86aa545..9db80ab8 100644 --- a/apps/detail-agent-pi/test/production-operations.test.mjs +++ b/apps/detail-agent-pi/test/production-operations.test.mjs @@ -462,6 +462,9 @@ test('a sibling variant edit leaves the current plan usable, and a local edit ca assert.equal(submissions.length,0); assert.equal((await actions.dispatch_image_request(approved)).phase,'accepted'); await prepared.promise; + const blocked=await actions.defer_production_output({reason:'等待候选回执',nextOutput}); + assert.equal(blocked.submitted,false); + assert.equal(blocked.active,1); assert.equal((await actions.dispatch_image_request(approved)).phase,'already_running'); assert.equal((await actions.review_image_slots({slotIds:[slotId]})).pictures[0].generation.phase,'accepted'); assert.deepEqual((await actions.write_copy_fields({revision:3,recordOnly:true, diff --git a/apps/detail-agent-pi/test/project-repository.test.mjs b/apps/detail-agent-pi/test/project-repository.test.mjs index e8c5a52b..bb2092f2 100644 --- a/apps/detail-agent-pi/test/project-repository.test.mjs +++ b/apps/detail-agent-pi/test/project-repository.test.mjs @@ -156,7 +156,7 @@ test('P03 the production bridge sends only the reviewed identity after an atomic assert.equal((await tools.await_image_slots({ slotIds: ['cover'] })).generation[0].phase, 'failed'); assert.equal(calls.length, 0); for (let attempt = 0; attempt < 2; attempt++) { - await tools.dispatch_image_request(approve(prepared)); + await tools.dispatch_image_request({ requestId: prepared.requestId }); assert.equal((await tools.await_image_slots({ slotIds: ['cover'] })).generation[0].phase, 'complete'); } assert.deepEqual(calls, [{ ...approve(draft), slotId: 'front' }]);