import{r as e}from"./norm-CeclA1Tu.js";import{n as t}from"./cloudWorkspaceClient-CMlIQBWi.js";var n=t=>{let n=Array.isArray(t.jobIds)?t.jobIds.length:0,r=t.summary&&typeof t.summary==`object`&&!Array.isArray(t.summary)?t.summary:null,i=r&&typeof r==`object`?r?.score??r?.scores?.overall??r?.bestScore:null,a={reportType:t.reportType,jobCount:n};if(typeof t.progress==`number`&&Number.isFinite(t.progress)&&(a.progress=Math.max(0,Math.min(100,Math.floor(t.progress)))),t.status&&(a.status=t.status),t.error&&(a.error=e(t.error).slice(0,180)),r){e(r?.headline)?a.headline=e(r.headline).slice(0,200):e(r?.summary)&&(a.headline=e(r.summary).slice(0,200)),Number.isFinite(Number(i))&&(a.score=Math.max(0,Math.min(100,Math.round(Number(i))))),e(r?.level)&&(a.level=e(r.level).slice(0,40)),e(r?.primaryAction)&&(a.primaryAction=e(r.primaryAction).slice(0,120));try{JSON.stringify(r).length<=24e3&&(a.extra=r)}catch{}}return a},r=async r=>{let i=e(r.id);if(!i)return{ok:!1,error:`missing_id`};let a=await t({op:`upsert_report`,id:i,reportType:r.reportType,title:e(r.title).slice(0,200),jobIds:Array.from(new Set((r.jobIds||[]).map(e).filter(Boolean))).slice(0,12),status:r.status||void 0,progress:typeof r.progress==`number`?Math.max(0,Math.min(100,Math.floor(r.progress))):void 0,summary:n(r)});return a.ok?{ok:!0}:{ok:!1,error:a.error}};export{r as cloudWorkspaceUpsertReport};