43 lines
3.2 KiB
JavaScript
43 lines
3.2 KiB
JavaScript
/** Bounded model views. Full task records/evidence remain owned by the desktop. */
|
|
const short=(text,limit=600)=>typeof text==='string'?text.slice(0,limit):text;
|
|
const fields=(value,keys)=>Object.fromEntries(keys.filter(k=>value?.[k]!==undefined).map(k=>[k,value[k]]));
|
|
const run=row=>({...fields(row,['run_id','queue_id','status','task_ids','remaining_task_ids','counters','blockers','resume_ready','started_utc']),
|
|
result:row.result?fields(row.result,['status','tasks','message']):undefined});
|
|
const schedule=row=>fields(row,['schedule_id','title','task_ids','priority','not_before','due_at','dependencies','auto_start','status','ready','blockers','run_id']);
|
|
const experience=row=>({...fields(row,['incident_id','issue_code','verified','verification','evidence','evidence_refs','evidence_references','status']),
|
|
attempts:row.attempts,analyses:row.analyses?.slice(0,2),outcome:row.outcome,
|
|
summary:short(row.summary,1200),message:short(row.message)});
|
|
const ticket=row=>({...fields(row,['incident_id','number','url','state','status','last_sync_at','last_attempt_at','error','reason']),
|
|
comments:row.comments?.slice(-3).map(c=>({...fields(c,['id','created_at','updated_at','author']),body:short(c.body)}))});
|
|
function impact(report){
|
|
if(!report||typeof report!=='object')return report;
|
|
const rows=report.rows||[];
|
|
return {...fields(report,['coverage','task_ids','component_count','known_component_count','enabled_scope','total_rows','omitted_row_count','truncated','tasks']),
|
|
rows:rows.slice(0,20),model_omitted_rows:Math.max(0,rows.length-20)};
|
|
}
|
|
export function compactResult(value){
|
|
if(!value||typeof value!=='object')return value;
|
|
const result={...value};
|
|
delete result.plan_hashes;delete result.fingerprint;delete result.full_fingerprint;
|
|
if(result.rows)Object.assign(result,impact(result));
|
|
if(result.impact)result.impact=impact(result.impact);
|
|
if(result.tasks?.length>50){result.model_omitted_tasks=result.tasks.length-50;result.tasks=result.tasks.slice(0,50);}
|
|
if(result.tasks)result.tasks=result.tasks.map(t=>({...t,...t.note?{note:short(t.note,300)}:{}}));
|
|
if(result.runs)result.runs=result.runs.slice(0,5).map(run);
|
|
if(result.schedules)result.schedules=result.schedules.slice(0,10).map(schedule);
|
|
if(result.schedule)result.schedule=schedule(result.schedule);
|
|
if(result.experiences)result.experiences=result.experiences.slice(0,5).map(experience);
|
|
if(result.tickets)result.tickets=result.tickets.slice(0,5).map(ticket);
|
|
if(result.ticket)result.ticket=ticket(result.ticket);
|
|
return JSON.parse(JSON.stringify(result));
|
|
}
|
|
export function modelSnapshot(value){
|
|
const result=fields(value,['task_id','revision','task_name','status','progress','rules_count','issue','issue_code','events','action_result']);
|
|
const ops=value.operations||{};
|
|
result.operations=compactResult({busy:ops.busy===true,live_run:ops.live_run,last_execution:ops.last_execution,
|
|
runs:ops.runs||[],schedules:ops.schedules||[],experiences:ops.experiences||[],tickets:ops.tickets||[]});
|
|
if(value.automation?.incident_id)result.automation=fields(value.automation,['incident_id','task_id','issue_code','status','attempts','verification']);
|
|
if(value.lifecycle?.status)result.lifecycle=fields(value.lifecycle,['request_id','status','task_ids','run_id']);
|
|
return result;
|
|
}
|