feat(xiaoyi): let Pi inspect and stage archived image candidates
This commit is contained in:
parent
e32535492d
commit
f460fe62bd
@ -12,6 +12,7 @@ const labels = Object.freeze({
|
||||
read_copy_fields: '查看待处理图文', delegate_image_slots: '分派图片图位', review_image_slots: '查看图位结果',
|
||||
read_slot_images: '查看图位图片', generate_slot_image: '生成候选图片',
|
||||
await_image_slots: '等待子代理回执', adopt_production_image: '回填候选图片', reconcile_image_slots: '核查图片原请求',
|
||||
read_archived_images: '查找同款历史候选', stage_archived_image: '加入待验历史候选',
|
||||
read_output_screen: '查看实际画布', record_screen_check: '记录本屏复核', check_page_copy: '发起文案复核',
|
||||
defer_production_output: '保留当前草稿', check_image_slots: '发起验图', finish_production: '提交成品导出',
|
||||
save_product_strategy: '保存商品策划', review_product_strategy: '核对卖点证据',
|
||||
|
||||
@ -62,7 +62,7 @@ const PRODUCTION_SYSTEM = `你是由壹点详情页的制作 Agent 小壹。用
|
||||
先用 read 加载已提供且适用于当前任务的企业 Skill。制作软件已选 PhotoCraft。按正文及引用,使用当前画布工具写入、回填、复核和交付。
|
||||
企业 Skill 中的命令行编修可在当前画布用等价的 PhotoCraft 原生命令完成。复核也覆盖文字格以外看得见的内容,例如旧商品标签、标线、规格和声明。使用 native_catalog 和 native_call 定位这些原图层或图层组。保留品牌固定元素和版式,按模板许可和 Skill 修改旧商品信息。
|
||||
根据已确认的产品事实、品牌和模板规划整页卖点和逐屏图文关系。由你决定要做什么、顺序、并行和返工。用 PhotoCraft 工具读、改实际画布。
|
||||
可直接制作候选,也可用 delegate_image_slots 把已明确的图位交给 Pi 子代理,继续做其他工作。review_image_slots 查看候选与已记录结论。check_image_slots 发起独立验图。你根据验图结果决定采用哪张图,或按具体退回原因给出新方案。
|
||||
可直接制作候选,也可用 delegate_image_slots 把已明确的图位交给 Pi 子代理,继续做其他工作。review_image_slots 查看当前候选与已记录结论。也可用 read_archived_images 查找同款历史候选,用 stage_archived_image 放入待验。check_image_slots 发起独立验图。你根据验图结果决定采用哪张图,或按具体退回原因给出新方案。
|
||||
写入图文以后查看实际画面,复核结构、品牌语气、标注和图文关系。达到当前输出要求时用 finish_production 提交画布修订号。客户端保存和导出后才算交付。
|
||||
文案是给买家读的。标题说清这一屏的重点,短句说清买家能看到什么、怎么使用。拍摄说明、验图用语和部件清单只用于制作。逐屏连读标题和正文,改掉重复词、拼接的半句话及样稿里的卖点。
|
||||
保留用户编辑。缺失的商品事实不得编造。按需读取当前屏或字段的模板填写规则,按原规则验收。规则明确要求缺值时留空的,用空文字和留空依据替换模板样文。生图和画布操作结果未确认时,只核查原编号。原结果仍不可取得时保留原编号,继续制作、复核或交付其他可以处理的部分。操作须通过标准工具提交。
|
||||
|
||||
@ -42,6 +42,12 @@ export const productionOperationTools = [
|
||||
})],
|
||||
['await_image_slots','等待指定图位的任一子代理或验图返回。',obj({slotIds:optional(ids)})],
|
||||
['review_image_slots','只读查看当前制作输出的候选、验图结论和原请求状态。未指定图位时查看该输出的全部图位。指定图位可同时查看该图位的原生图提示词。',obj({slotIds:optional(Type.Array(Type.String()))})],
|
||||
['read_archived_images','只读查找其他本机项目同款、同模板图位的历史候选和原请求编号。可按 slotIds 缩小范围。',obj({
|
||||
slotIds:optional(Type.Array(Type.String())),
|
||||
})],
|
||||
['stage_archived_image','按 read_archived_images 的身份把一张已完成历史候选加入当前图位待验,保留原请求来源。请按当前版式和文案验图后自行决定是否采用。',obj({
|
||||
slotId:slotRef,projectId:text,candidateId:text,
|
||||
})],
|
||||
['check_image_slots','请验图代理审核指定候选,是否采用由你决定。wait=false 时先返回受理结果,可继续工作并用 review_image_slots 查看结论。',obj({
|
||||
wait:optional(Type.Boolean()),candidates:Type.Array(obj({slotId:slotRef,candidateId:text,adopted:optional(Type.Boolean())})),
|
||||
})],
|
||||
@ -92,6 +98,16 @@ export async function openProductionOperations(host) {
|
||||
return slot;
|
||||
};
|
||||
const selections=slotIds=>slotIds?.length?[...new Set(slotIds.map(matches))]:slots;
|
||||
const readSelection=slotIds=>{
|
||||
const requested=new Set(slotIds?.map(id=>id.trim()).filter(Boolean));
|
||||
const matched=new Set(), unmatched=[];
|
||||
for(const reference of requested){
|
||||
const slot=findSlot(reference);
|
||||
if(slot) matched.add(slot.id);
|
||||
else unmatched.push({slotId:reference,reason:slotNotFound});
|
||||
}
|
||||
return {requested,matched,unmatched};
|
||||
};
|
||||
const jobs=new Map(), reviewWork=new Set(), candidates=new Map(), filled=new Set(slots.filter(s=>s.selectedCandidateId).map(s=>s.id));
|
||||
const pendingReviews=()=>[...reviewWork].filter(job=>job.run);
|
||||
const running=()=>[...jobs.values(),...pendingReviews()];
|
||||
@ -355,27 +371,32 @@ export async function openProductionOperations(host) {
|
||||
},
|
||||
async review_image_slots({slotIds}){
|
||||
const live=await loadSlots(canvas,outputId);
|
||||
const requested=slotIds?.map(id=>id.trim()).filter(Boolean)??[];
|
||||
const scopes=new Set();
|
||||
const unmatched=[];
|
||||
for(const slotId of new Set(requested)){
|
||||
const slot=findSlot(slotId);
|
||||
if(slot) scopes.add(slot.id);
|
||||
else unmatched.push({slotId,reason:slotNotFound});
|
||||
}
|
||||
const {requested,matched,unmatched}=readSelection(slotIds);
|
||||
const checks=Map.groupBy([...reviewWork],job=>job.row.slotId);
|
||||
const slotRecord=id=>{
|
||||
const record=journal.items[id];
|
||||
if(!record||requested.length) return record;
|
||||
if(!record||requested.size) return record;
|
||||
const {prompt,...progress}=record;
|
||||
return prompt?{...progress,hasPrompt:true}:progress;
|
||||
};
|
||||
return {outputId,variantId,active:jobs.size,
|
||||
pictures:live.slots.filter(slot=>!requested.length||scopes.has(slot.id)).map(({id,fieldId,label,selectedCandidateId,candidates})=>({
|
||||
pictures:live.slots.filter(slot=>!requested.size||matched.has(slot.id)).map(({id,fieldId,label,selectedCandidateId,candidates})=>({
|
||||
id,fieldId,label,selectedCandidateId,candidates,working:jobs.has(id),record:slotRecord(id),
|
||||
checks:checks.get(id)?.map(job=>job.receipt)??[],
|
||||
})),...(unmatched.length?{unmatched}:{})};
|
||||
},
|
||||
async read_archived_images({slotIds}){
|
||||
const {requested,matched,unmatched}=readSelection(slotIds);
|
||||
const history=await canvas.detailHistory();
|
||||
const candidates=history.filter(row=>!requested.size||matched.has(row.slotId))
|
||||
.map(row=>({...row,fieldId:byId.get(row.slotId)?.fieldId}));
|
||||
return {outputId,variantId,candidates,...(unmatched.length?{unmatched}:{})};
|
||||
},
|
||||
async stage_archived_image({slotId,projectId,candidateId},signal){
|
||||
const slot=matches(slotId);
|
||||
signal?.throwIfAborted();
|
||||
return canvas.detailArchive(slot.id,{projectId,candidateId,forReview:true});
|
||||
},
|
||||
async check_image_slots({candidates:requested,wait=true},signal){
|
||||
const batch=requested.map(({slotId,candidateId,adopted})=>{
|
||||
let slot;
|
||||
|
||||
@ -29,7 +29,7 @@ export class StdioCanvas {
|
||||
detailCopyFields(options) { return this.#observe('pi-detail-copy-fields', options); }
|
||||
detailApplyCopy(items,revision) { return this.action('pi-detail-copy-apply',{items,revision}); }
|
||||
detailHistory() { return this.action('pi-detail-archive'); }
|
||||
detailArchive(slotId,{projectId,candidateId}) { return this.action('pi-detail-archive',{slotId,source:{projectId,candidateId}}); }
|
||||
detailArchive(slotId,{projectId,candidateId,forReview}) { return this.action('pi-detail-archive',{slotId,source:{projectId,candidateId,forReview}}); }
|
||||
detailRecover(slotId,{projectId,candidateId}) { return this.action('pi-detail-archive',{slotId,source:{projectId,candidateId,recover:true}}); }
|
||||
detailImages(slotId,candidateId,options) { return this.#observe('pi-detail-images', {slotId,candidateId,...options}); }
|
||||
detailCropPreview(slotId,referenceIndex,referenceCrop) {
|
||||
|
||||
@ -45,6 +45,41 @@ test('a malformed slot reference does not strand the other explicitly delegated
|
||||
assert.deepEqual(await actions.delegate_image_slots({jobs:[]}),{assigned:[]});
|
||||
});
|
||||
|
||||
test('Pi can inspect and stage an archived same-product image without a model call or adoption',async t=>{
|
||||
const dir=await fs.mkdtemp(path.join(os.tmpdir(),'jiansun-pi-'));
|
||||
t.after(()=>cleanup(dir));
|
||||
const history=[
|
||||
{slotId:'photo',projectId:'prior',candidateId:'first',phase:'complete',requestId:'original-request'},
|
||||
{slotId:'photo',projectId:'prior',candidateId:'second',phase:'unknown',requestId:'pending-request'},
|
||||
{slotId:'join',projectId:'prior',candidateId:'third',phase:'complete',requestId:'different-request'},
|
||||
];
|
||||
const calls=[];
|
||||
const host={store:{dir,get:async()=>null},productionGoal:{outputId:'detail',variantId:'natural'},canvas:{
|
||||
workflowRead:async()=>({available:true,canvasFirst:true,outputId:'detail',productVariantId:'natural',
|
||||
template:{contentHash:'fixture'},totalSlots:2,slots:[
|
||||
{id:'photo',fieldId:'front',candidates:[]},{id:'join',fieldId:'joint',candidates:[]},
|
||||
]}),
|
||||
detailHistory:async()=>history,
|
||||
detailArchive:async(slot,source)=>{
|
||||
calls.push({slot,source});
|
||||
return {id:'staged',status:'complete',sourceType:'archived-candidate',sourceRequestId:'original-request'};
|
||||
},
|
||||
workflowExecute(){assert.fail('archive inspection or staging dispatched a job');},
|
||||
requestWrite(){assert.fail('archive inspection or staging requested a canvas write');},
|
||||
},runDetailAgent(){assert.fail('archive inspection or staging invoked a model');}};
|
||||
const actions=await openProductionOperations(host);
|
||||
const result=await actions.read_archived_images({slotIds:[' front ','different-output']});
|
||||
assert.equal(result.outputId,'detail');
|
||||
assert.deepEqual(result.candidates.map(row=>[row.fieldId,row.phase,row.requestId]),
|
||||
[['front','complete','original-request'],['front','unknown','pending-request']]);
|
||||
assert.equal(result.unmatched[0].slotId,'different-output');
|
||||
assert.equal((await actions.read_archived_images({slotIds:['']})).candidates.length,3);
|
||||
assert.deepEqual(calls,[]);
|
||||
const staged=await actions.stage_archived_image({slotId:'front',projectId:'prior',candidateId:'first'});
|
||||
assert.equal(staged.sourceRequestId,'original-request');
|
||||
assert.deepEqual(calls,[{slot:'photo',source:{projectId:'prior',candidateId:'first',forReview:true}}]);
|
||||
});
|
||||
|
||||
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));
|
||||
|
||||
@ -1098,6 +1098,10 @@ fn candidate_receipt(record: &Value) -> Value {
|
||||
if matches!(record["sourceType"].as_str(), Some("product-reference" | "archived-candidate")) {
|
||||
receipt["sourceType"] = record["sourceType"].clone();
|
||||
}
|
||||
if record["sourceType"] == "archived-candidate" {
|
||||
receipt["reusedFrom"] = record["reusedFrom"].clone();
|
||||
receipt["sourceRequestId"] = record["sourceRequestId"].clone();
|
||||
}
|
||||
receipt
|
||||
}
|
||||
fn same_production_product(current: &Value, source: &Value) -> bool {
|
||||
@ -1264,12 +1268,13 @@ fn reuse_archived_candidate(dir: &Path, state: Value, input: &Value, preflight:
|
||||
if input["detailBatch"] == true { binding["detailBatch"] = json!(true); }
|
||||
let job = dir.join("image-jobs").join(&id);
|
||||
let journal = json!({"id":id,"version":1,"slotBinding":binding,"phase":"complete","requestId":null,
|
||||
"sourceType":"archived-candidate","sha256":artwork["sha256"]});
|
||||
"sourceType":"archived-candidate","reusedFrom":origin,"sourceRequestId":source_task["requestId"],"sha256":artwork["sha256"]});
|
||||
write_json(&job.join("task.json"), &journal)?;
|
||||
photocraft_format::atomic_write(&job.join("generated.png"), &pixels).map_err(|_| "历史候选无法保存")?;
|
||||
let artifact = template_slots::artifact(dir,&id,&journal)?;
|
||||
let record = json!({"version":2,"id":id,"binding":binding,"phase":"complete","sourceType":"archived-candidate",
|
||||
"reusedFrom":origin,"requestId":null,"inputHash":input_hash(dir,&state,&variant_id)?,"references":original_refs,
|
||||
"reusedFrom":origin,"sourceRequestId":source_task["requestId"],"requestId":null,
|
||||
"inputHash":input_hash(dir,&state,&variant_id)?,"references":original_refs,
|
||||
"instructions":"历史候选,等待当前图位验收","artifact":artifact,"createdAt":now()});
|
||||
reserve(dir,state,&record)?;
|
||||
Ok(record)
|
||||
@ -1652,8 +1657,9 @@ impl Backend {
|
||||
}
|
||||
return Ok(candidate_receipt(&record));
|
||||
}
|
||||
let preflight = (target["source"]["forReview"] != true).then_some(&*self);
|
||||
let record = reuse_archived_candidate(&dir, state, &json!({"slotId":target["slotId"],"variantId":variant_id,
|
||||
"sourceProjectId":target["source"]["projectId"],"sourceCandidateId":target["source"]["candidateId"],"detailBatch":true}), Some(self))?;
|
||||
"sourceProjectId":target["source"]["projectId"],"sourceCandidateId":target["source"]["candidateId"],"detailBatch":true}), preflight)?;
|
||||
if record["status"] == "skipped" {
|
||||
return Ok(record);
|
||||
}
|
||||
@ -3468,6 +3474,7 @@ mod tests {
|
||||
let archive = json!({
|
||||
"id": "complete-local-archive", "phase": "complete", "sourceType": "archived-candidate",
|
||||
"requestId": null, "reusedFrom": {"projectId": "previous", "candidateId": "original"},
|
||||
"sourceRequestId": "original-request",
|
||||
"binding": {"slotId": "current-slot", "variantId": "current-variant"},
|
||||
});
|
||||
let response = candidate_receipt(&archive);
|
||||
@ -3475,6 +3482,61 @@ mod tests {
|
||||
assert_eq!(response["status"], "complete");
|
||||
assert_eq!(response["sourceType"], "archived-candidate");
|
||||
assert_eq!(response["slotId"], "current-slot");
|
||||
assert_eq!(response["reusedFrom"], archive["reusedFrom"]);
|
||||
assert_eq!(response["sourceRequestId"], "original-request");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "requires the original paid image files in an isolated project fixture"]
|
||||
fn staged_real_archive_retains_the_original_request_after_rework() {
|
||||
let fixture = PathBuf::from(std::env::var_os("JIANSUN_ARCHIVE_REPLAY_FIXTURE").expect("fixture path"));
|
||||
let input = read_json(&fixture).unwrap();
|
||||
let projects = fixture.parent().unwrap().join("projects");
|
||||
let target = projects.join(input["targetProjectId"].as_str().unwrap());
|
||||
let source = projects.join(input["sourceProjectId"].as_str().unwrap());
|
||||
let staged_from = input["olderCandidateId"].as_str().unwrap();
|
||||
let reworked = input["reworkedCandidateId"].as_str().unwrap();
|
||||
let older_file = source.join("image-jobs").join(staged_from).join("task.json");
|
||||
let reworked_file = source.join("image-jobs").join(reworked).join("task.json");
|
||||
let original_tasks = [fs::read(&older_file).unwrap(), fs::read(&reworked_file).unwrap()];
|
||||
let older = read_json(&older_file).unwrap();
|
||||
let newer = read_json(&reworked_file).unwrap();
|
||||
assert_ne!(older["requestId"], newer["requestId"]);
|
||||
assert_ne!(older["prompt"], newer["prompt"]);
|
||||
assert_eq!(older["slotBinding"]["fieldId"], newer["slotBinding"]["fieldId"]);
|
||||
let output = input["outputId"].as_str().unwrap();
|
||||
let mut state = load(&target).unwrap();
|
||||
state["template"] = state["productTemplates"][output].clone();
|
||||
state["activeOutput"] = json!(output);
|
||||
state["structureHash"] = json!(hash(&json!([state["template"]["contentHash"],state["width"]]).to_string()));
|
||||
let current = revision(&state);
|
||||
let state = persist(&target, state, current).unwrap();
|
||||
let variant = state["activeVariantId"].as_str().unwrap();
|
||||
let field = older["slotBinding"]["fieldId"].as_str().unwrap();
|
||||
let slot = slot_id(&state["template"]["contentHash"], variant, field);
|
||||
let history = production_image_history(&target,&state,variant,"isolated-fixture").unwrap();
|
||||
for row in [&older, &newer] {
|
||||
assert!(history.as_array().unwrap().iter().any(|item|
|
||||
item["slotId"] == slot && item["candidateId"] == row["id"] && item["requestId"] == row["requestId"]));
|
||||
}
|
||||
|
||||
let request = json!({"slotId":slot,"variantId":variant,"sourceProjectId":input["sourceProjectId"],
|
||||
"sourceCandidateId":staged_from,"detailBatch":true});
|
||||
let record = reuse_archived_candidate(&target, state.clone(), &request, None).unwrap();
|
||||
let receipt = candidate_receipt(&record);
|
||||
assert_eq!(receipt["sourceRequestId"], older["requestId"]);
|
||||
assert_eq!(receipt["reusedFrom"]["candidateId"], staged_from);
|
||||
let staged_id = record["id"].as_str().unwrap();
|
||||
let data = target.join("image-jobs").join(staged_id);
|
||||
let staged_task = read_json(&data.join("task.json")).unwrap();
|
||||
assert_eq!(staged_task["sourceRequestId"], older["requestId"]);
|
||||
assert!(staged_task["requestId"].is_null());
|
||||
assert_eq!(fs::read(data.join("generated.png")).unwrap(), fs::read(older_file.with_file_name("generated.png")).unwrap());
|
||||
assert_eq!(fs::read(&older_file).unwrap(), original_tasks[0]);
|
||||
assert_eq!(fs::read(&reworked_file).unwrap(), original_tasks[1]);
|
||||
assert_eq!(reuse_archived_candidate(&target,state,&request,None).unwrap()["id"], staged_id);
|
||||
println!("{}",json!({"field":field,"sameBytes":true,"staged":receipt,
|
||||
"reworkedRequestId":newer["requestId"],"originalRecordsUnchanged":true,"newPaidRequests":0}));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user