From a4483a0d6456f9249ac002bbd2c29a06f09ba57f Mon Sep 17 00:00:00 2001 From: WuYongJie <549727955@qq.com> Date: Sat, 28 Nov 2026 00:28:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8C=89=E5=AE=BF=E4=B8=BB=E5=B7=B2=E6=B4=BE?= =?UTF-8?q?=E5=8F=91=E8=AE=B0=E5=BD=95=E8=AE=A1=E7=AE=97=E5=9B=BE=E4=BD=8D?= =?UTF-8?q?=E9=A2=84=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/production-operations.mjs | 8 ++--- .../src/project-repository.mjs | 30 ------------------- .../test/production-operations.test.mjs | 4 ++- 3 files changed, 5 insertions(+), 37 deletions(-) diff --git a/apps/detail-agent-pi/src/production-operations.mjs b/apps/detail-agent-pi/src/production-operations.mjs index d2bf1c07..db9e0a87 100644 --- a/apps/detail-agent-pi/src/production-operations.mjs +++ b/apps/detail-agent-pi/src/production-operations.mjs @@ -462,12 +462,8 @@ export async function openProductionOperations(host,{maxActiveDelegates=6,maxGen remainingGenerationAttempts:Math.max(0,maxGenerationAttempts-generationAttempts), drawLimitReached:generationAttempts>=maxGenerationAttempts, }); - const drawStatuses=selected=>{ - const ids=new Map(selected.map(slot=>[slot.id,nativeGenerations(slot)])); - const counts=repository.countImageGenerations(binding,ids,journal.items); - return new Map([...counts].map(([id,count])=>[id,drawStatus(count)])); - }; - const slotDrawStatus=slot=>drawStatuses([slot]).get(slot.id); + const slotDrawStatus=slot=>drawStatus(new Set(nativeGenerations(slot)).size); + const drawStatuses=selected=>new Map(selected.map(slot=>[slot.id,slotDrawStatus(slot)])); const drawLimit=(slot,status)=>({slotId:slot.id,phase:'draw_limit_reached',limitReached:true,...status, candidates:slot.candidates??[], reason:`该图位已达到单张最多 ${maxGenerationAttempts} 次生图上限,请从已有候选中择优采纳(或使用实拍裁切/调整),后续可由人工通过引用精修。`, diff --git a/apps/detail-agent-pi/src/project-repository.mjs b/apps/detail-agent-pi/src/project-repository.mjs index b591900b..938e326a 100644 --- a/apps/detail-agent-pi/src/project-repository.mjs +++ b/apps/detail-agent-pi/src/project-repository.mjs @@ -229,36 +229,6 @@ export class ProjectRepository { return this.#open(db => this.#readRequest(db, requestId)); } - #countImageGenerations(requests, nativeIds, item) { - const ids = new Set(nativeIds); - for (const {request_id, state} of requests) { - if (state !== 'prepared') ids.add(request_id); - } - for (const row of item?.attempts ?? []) if (row.source === 'generate' && row.candidateId) ids.add(row.candidateId); - for (const id of Object.keys(item?.pendingGenerations ?? {})) ids.add(id); - const originalId = item?.pendingOperation?.candidateId; - if (originalId && !item.attempts?.some(row => row.candidateId === originalId && row.source === 'product')) { - ids.add(originalId); - } - return ids.size; - } - - #generationRequests(db, binding, slotId) { - return db.prepare(`SELECT slot_id, request_id, state FROM image_requests - WHERE ${scopeWhere} AND json_extract(prepared_json, '$.binding') = ?${slotId ? ' AND slot_id = ?' : ''}`) - .all(...this.scope, binding, ...(slotId ? [slotId] : [])); - } - - countImageGenerations(binding, nativeIdsBySlot, items) { - if (!nativeIdsBySlot.size) return new Map(); - return this.#open(db => { - const slotId = nativeIdsBySlot.size === 1 ? nativeIdsBySlot.keys().next().value : undefined; - const requests = Map.groupBy(this.#generationRequests(db, binding, slotId), row => row.slot_id); - return new Map([...nativeIdsBySlot].map(([id, nativeIds]) => - [id, this.#countImageGenerations(requests.get(id) ?? [], nativeIds, items[id])])); - }); - } - #recordCandidate(db, slotId, candidateId, kind, detail) { db.prepare(`INSERT INTO candidate_evidence (${scopeColumns}, slot_id, candidate_id, kind, detail_json) VALUES (${scopeValues}, ?, ?, ?, ?)`).run(...this.scope, slotId, candidateId, kind, json(detail)); diff --git a/apps/detail-agent-pi/test/production-operations.test.mjs b/apps/detail-agent-pi/test/production-operations.test.mjs index bfdeaa67..06428c0a 100644 --- a/apps/detail-agent-pi/test/production-operations.test.mjs +++ b/apps/detail-agent-pi/test/production-operations.test.mjs @@ -160,7 +160,9 @@ test('a host-owned original survives a Pi restart and is recovered without anoth }); test('a candidate reserved before POST neither owns the slot nor spends its draw budget',async t=>{ - const {host}=await tailFixture(t,['hero']); + const {host}=await tailFixture(t,['hero'],{ + hero:{state:'unknown',pendingGenerations:{'reserved-before-send':{candidateId:'reserved-before-send'}}}, + }); const workflowRead=host.canvas.workflowRead; host.canvas.workflowRead=async input=>{ const view=await workflowRead(input);