@hoknie/aip 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/dist/feature/runs/services/progress.js +24 -18
  2. package/dist/feature/runs/services/progress.js.map +1 -1
  3. package/dist/feature/swarm-edit/services/editor-settings.js +5 -0
  4. package/dist/feature/swarm-edit/services/editor-settings.js.map +1 -1
  5. package/dist/feature/swarm-edit/services/plan-settings.js +18 -8
  6. package/dist/feature/swarm-edit/services/plan-settings.js.map +1 -1
  7. package/dist/feature/swarm-edit/types/editor.js.map +1 -1
  8. package/dist/feature/swarm-edit/types/setting-fields.js +7 -0
  9. package/dist/feature/swarm-edit/types/setting-fields.js.map +1 -1
  10. package/dist/presentation/ipc/contract/config.js +2 -2
  11. package/dist/presentation/ipc/contract/config.js.map +1 -1
  12. package/dist/presentation/web/routes/settings.js +2 -2
  13. package/dist/presentation/web/routes/settings.js.map +1 -1
  14. package/dist/web/assets/{SharedPipelinesGroup-CDmnXmIK.js → SharedPipelinesGroup-CgUJ-sUc.js} +1 -1
  15. package/dist/web/assets/{deliveryModes-BCAw5jcd.js → deliveryModes-BGIYJzWQ.js} +1 -1
  16. package/dist/web/assets/index-Cg7gL5P8.css +2 -0
  17. package/dist/web/assets/index-LD1g1Vkm.js +43 -0
  18. package/dist/web/assets/locales-D85Vnmev.js +1 -0
  19. package/dist/web/assets/{pipelines-Bs3be_lB.js → pipelines-Cej37cah.js} +3 -3
  20. package/dist/web/assets/{settingFields-CjOFaEa6.js → settingFields-gm9TlqxP.js} +1 -1
  21. package/dist/web/assets/settings-CDiTeiYL.js +6 -0
  22. package/dist/web/assets/specialists-BGKB5BLI.js +4 -0
  23. package/dist/web/assets/{stats-CzMDDzr9.js → stats-BM-bGkGX.js} +1 -1
  24. package/dist/web/assets/{topology-5cpl0v2g.js → topology-BE6orrOL.js} +1 -1
  25. package/dist/web/index.html +4 -4
  26. package/integrations/claude-code/.claude-plugin/plugin.json +1 -1
  27. package/package.json +1 -1
  28. package/dist/web/assets/index-BAeOzr94.js +0 -43
  29. package/dist/web/assets/index-D3ty-b_t.css +0 -2
  30. package/dist/web/assets/locales-9kiK4pzD.js +0 -1
  31. package/dist/web/assets/settings-CeKVFMz7.js +0 -6
  32. package/dist/web/assets/specialists-BPyAYlk1.js +0 -4
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{A as t,D as n,O as r,St as i,k as a}from"./index-BAeOzr94.js";import{F as o,a as s,d as c,f as l,g as u,i as d,j as f,k as p,n as m,r as h,s as g,t as _,ut as v}from"./card-4euJkmfJ.js";import{a as y,n as b,o as ee,r as te,s as ne,t as x}from"./empty-OZRGgwa5.js";import{i as S,t as C}from"./vendor-react-C1iE8mnY.js";import{t as w}from"./trash-xUZ90-AG.js";var T=e(S(),1),E=C();function D({caption:e,columns:t,rows:n,pinned:r,sort:i,onSort:a,rowKey:s}){let c=(e,n)=>(0,E.jsx)(`tr`,{className:o(`border-t`,n&&`bg-muted/40 font-medium`),children:t.map(t=>(0,E.jsx)(`td`,{className:o(`px-3 py-1.5`,t.numeric&&`text-right tabular-nums`),children:t.cell(e)},t.key))},s(e));return(0,E.jsx)(`div`,{className:`overflow-x-auto`,"data-testid":`stats-table-scroll`,children:(0,E.jsxs)(`table`,{className:`w-full min-w-max text-sm`,children:[(0,E.jsx)(`caption`,{className:`sr-only`,children:e}),(0,E.jsx)(`thead`,{children:(0,E.jsx)(`tr`,{className:`text-xs text-muted-foreground`,children:t.map(e=>{let t=i?.key===e.key;return(0,E.jsx)(`th`,{scope:`col`,"aria-sort":t?i.direction===`asc`?`ascending`:`descending`:`none`,className:o(`px-3 py-1.5 font-medium`,e.numeric&&`text-right`),children:(0,E.jsxs)(`button`,{type:`button`,className:`rounded-sm hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring`,onClick:()=>a(e.key),children:[e.label,t?i.direction===`asc`?` ↑`:` ↓`:``]})},e.key)})})}),(0,E.jsxs)(`tbody`,{children:[r===void 0?null:c(r,!0),n.map(e=>c(e,!1))]})]})})}function re(e,t){let n=e/t,r=10**Math.floor(Math.log10(n)),i=n/r;return(i<=1?1:i<=2?2:i<=2.5?2.5:i<=5?5:10)*r}function ie(e,t=4){if(!Number.isFinite(e)||e<=0)return{ticks:[0,1],max:1};let n=re(e,t),r=Math.ceil(e/n-1e-9),i=Array.from({length:r+1},(e,t)=>Number((t*n).toPrecision(12)));return{ticks:i,max:i[i.length-1]??1}}function ae(e,t,n){return t<=0||e<=0?0:Math.min(n,e/t*n)}var oe=`__other`;function se(e,t,n){if(e.length<=t)return e;let r=e=>e.values.reduce((e,t)=>e+t,0),i=[...e].sort((e,t)=>r(t)-r(e)),a=new Set(i.slice(0,t).map(e=>e.key)),o=e.filter(e=>!a.has(e.key)),s=e[0]?.values.length??0,c=Array.from({length:s},(e,t)=>o.reduce((e,n)=>e+(n.values[t]??0),0));return[...e.filter(e=>a.has(e.key)),{key:oe,label:n.label,color:n.color,values:c}]}function ce(e,t){return Array.from({length:t},(t,n)=>e.reduce((e,t)=>e+(t.values[n]??0),0))}var O=[`tokens`,`agent`,`tasks`],k=[`projects`,`models`];function le(e){return O.filter(t=>t!==`tasks`||e===`projects`)}function ue(e){return[...new Set([...e.byModel.map(e=>e.key),...e.series.flatMap(e=>e.models.map(e=>e.model))])]}var de={"7d":7,"30d":30,"90d":90};function fe(e,t){if(e===`all`)return;let n=new Date(t);return new Date(n.getFullYear(),n.getMonth(),n.getDate()-(de[e]-1)).getTime()}function A(e){let t=e=>String(Number(e.toFixed(1)));return e>=1e6?`${t(e/1e6)}M`:e>=1e3?`${t(e/1e3)}k`:String(Math.round(e))}function j(e,t){let n=Math.round(Math.max(0,e)/6e4);if(n<1)return t(`stats.unit.seconds`,{count:Math.round(e/1e3)});let r=Math.floor(n/60),i=n%60;return r===0?t(`stats.unit.minutes`,{count:i}):i===0?t(`stats.unit.hours`,{count:r}):`${t(`stats.unit.hours`,{count:r})} ${t(`stats.unit.minutes`,{count:i})}`}function M(e,t){return e===`tokens`?t.tokens:e===`agent`?t.agentMs:t.tasks??0}function N(e,t,n,r){let i=e=>n===`models`?e.models.map(e=>({key:e.model,entry:e})):e.projects.map(e=>({key:e.repository,entry:e}));return se([...new Set(e.series.flatMap(e=>i(e).map(e=>e.key)))].map(a=>({key:a,label:n===`models`?r.modelLabelOf?.(a)??a:r.labelOf(a),color:r.colors[a]??r.other.color,values:e.series.map(e=>{let n=i(e).find(e=>e.key===a);return n===void 0?0:M(t,n.entry)})})),8,r.other)}function P(e,t){return e?.key===t?{key:t,direction:e.direction===`asc`?`desc`:`asc`}:{key:t,direction:`asc`}}function F(e,t,n){if(t===null)return[...e];let r=t.direction===`asc`?1:-1;return[...e].sort((e,i)=>{let a=n(e,t.key),o=n(i,t.key);return a===null&&o===null?0:a===null?1:o===null?-1:typeof a==`string`||typeof o==`string`?r*String(a).localeCompare(String(o),`en`,{sensitivity:`base`}):r*(a-o)})}function I(e,t){let{totals:n,perTask:r}=e;switch(t){case`tasks`:return n.tasks;case`tokens`:return n.tokens;case`agent`:return n.agentMs;case`wall`:return n.wallMs;case`meanTokens`:return r.tokens.mean;case`medianTokens`:return r.tokens.median;case`meanAgent`:return r.agentMs.mean;case`medianAgent`:return r.agentMs.median;default:return null}}var L=`unknown`,R=[`claude`,`opencode`,`agy`,`command`];function z(e,t){return e===L?t(`stats.breakdown.keys.unknown`):e}function B(e,t,n){let r=t.name??t.key;return t.name===null&&(e===`specialist`&&t.key===`naming`?r=n(`stats.breakdown.keys.naming`):e===`model`?r=z(t.key,n):e===`runtime`&&R.includes(t.key)&&(r=n(`stats.breakdown.runtimes.${t.key}`))),{text:r,title:r===t.key?void 0:t.key}}function V(e,t){switch(t){case`name`:return e.key;case`attempts`:return e.attempts;case`input`:return e.inputTokens;case`output`:return e.outputTokens;case`agent`:return e.agentMs;case`perAttempt`:return e.tokensPerAttempt;default:return null}}function pe(e,t){return e.projects.map(e=>({repository:e.repository,value:t===`tokens`?e.totals.tokens:e.totals.agentMs})).filter(e=>e.value>0).sort((e,t)=>t.value-e.value)}function me(e){return e.totals.tasks===0&&e.totals.attempts===0}var H=e=>String(e).padStart(2,`0`);function he(e,t,n){let r=new Intl.DateTimeFormat(n,{day:`numeric`,month:`short`}),i=new Intl.DateTimeFormat(n,{dateStyle:`medium`});return e.map(e=>{if(t===`6h`){let t=new Date(e.start),n=H(t.getHours()),a=H(new Date(t.getFullYear(),t.getMonth(),t.getDate(),t.getHours()+6).getHours()),o=t.getHours()===0?r.format(e.start):``,s=`${i.format(e.start)}, ${n}:00–${a}:00`;return{key:e.day,label:o,title:s}}if(t===`week`){let t=new Date(e.start),n=new Date(t.getFullYear(),t.getMonth(),t.getDate()+6).getTime(),i=r.format(e.start),a=`${r.format(e.start)} – ${r.format(n)}`;return{key:e.day,label:i,title:a}}return{key:e.day,label:r.format(e.start),title:i.format(e.start)}})}var U=[{id:`specialist`,rows:e=>e.bySpecialist},{id:`model`,rows:e=>e.byModel},{id:`pipeline`,rows:e=>e.byPipeline},{id:`runtime`,rows:e=>e.byRuntime}];function ge({report:e}){let{t:i}=v(),[o,s]=(0,T.useState)(`specialist`),[c,l]=(0,T.useState)(null),u=(e,t,n)=>({key:e,label:t,numeric:!0,cell:n}),d=e=>[{key:`name`,label:i(`stats.breakdown.name`),cell:t=>{let{text:n,title:r}=B(e,t,i);return r===void 0?n:(0,E.jsx)(`span`,{title:r,children:n})}},u(`attempts`,i(`stats.breakdown.attempts`),e=>String(e.attempts)),u(`input`,i(`stats.breakdown.input`),e=>A(e.inputTokens)),u(`output`,i(`stats.breakdown.output`),e=>A(e.outputTokens)),u(`agent`,i(`stats.tiles.agent`),e=>j(e.agentMs,i)),u(`perAttempt`,i(`stats.breakdown.perAttempt`),e=>A(e.tokensPerAttempt))],f=e=>(t,n)=>n===`name`?B(e,t,i).text:V(t,n);return(0,E.jsx)(_,{className:`p-4`,children:(0,E.jsxs)(n,{value:o,onValueChange:s,children:[(0,E.jsx)(a,{"aria-label":i(`stats.breakdown.title`),children:U.map(({id:e})=>(0,E.jsx)(t,{value:e,children:i(`stats.breakdown.tabs.${e}`)},e))}),U.map(({id:t,rows:n})=>(0,E.jsx)(r,{value:t,children:(0,E.jsx)(D,{caption:i(`stats.breakdown.tabs.${t}`),columns:d(t),rows:F(n(e),c,f(t)),sort:c,onSort:e=>l(t=>P(t,e)),rowKey:e=>e.key})},t))]})})}function _e({title:e,total:t,rows:n,left:r}){return(0,E.jsxs)(`div`,{role:`status`,"data-testid":`chart-tooltip`,className:`pointer-events-none absolute top-0 z-10 min-w-40 max-w-64 -translate-x-1/2 rounded-md border bg-card p-2 text-xs text-card-foreground shadow-md`,style:{left:r??0},children:[(0,E.jsxs)(`div`,{className:`flex justify-between gap-3 font-medium`,children:[(0,E.jsx)(`span`,{children:e}),(0,E.jsx)(`span`,{children:t})]}),(0,E.jsx)(`ul`,{className:`mt-1 flex flex-col gap-0.5`,children:n.map(e=>(0,E.jsxs)(`li`,{className:`flex items-center justify-between gap-3`,children:[(0,E.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1.5`,children:[(0,E.jsx)(`span`,{"aria-hidden":`true`,className:`size-2 shrink-0 rounded-full`,style:{backgroundColor:e.color}}),(0,E.jsx)(`span`,{className:`truncate`,children:e.label})]}),(0,E.jsx)(`span`,{className:`shrink-0 tabular-nums`,children:e.value})]},e.key))})]})}var W={fill:`var(--color-muted-foreground)`};function ve({series:e,idPrefix:t}){return(0,E.jsx)(`defs`,{children:e.map((e,n)=>(0,E.jsxs)(`linearGradient`,{id:`${t}-grad-${n}`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,E.jsx)(`stop`,{offset:`0%`,stopColor:e.color,stopOpacity:`0.40`}),(0,E.jsx)(`stop`,{offset:`100%`,stopColor:e.color,stopOpacity:`0.05`})]},e.key))})}function ye({ticks:e,max:t,plotWidth:n,plotHeight:r,format:i}){return(0,E.jsx)(`g`,{"data-testid":`chart-grid`,children:e.map(e=>{let a=t<=0?r:r-Math.min(r,e/t*r);return(0,E.jsxs)(`g`,{children:[(0,E.jsx)(`line`,{x1:0,x2:n,y1:a,y2:a,stroke:`var(--color-border)`,strokeWidth:1,strokeDasharray:e===0?void 0:`3 3`}),(0,E.jsx)(`text`,{x:-6,y:a,textAnchor:`end`,dominantBaseline:`middle`,fontSize:11,style:W,children:i(e)})]},e)})})}function be({layers:e,idPrefix:t,plotWidth:n,plotHeight:r,isSingle:i}){if(i){let t=n/2;return(0,E.jsxs)(`g`,{"data-testid":`area-single-point`,children:[(0,E.jsx)(`line`,{x1:t,x2:t,y1:0,y2:r,stroke:`var(--color-border)`,strokeWidth:1,strokeDasharray:`2 2`}),e.map(e=>{let t=e.points[0],n=e.series.values[0]??0;return!t||n<=0?null:(0,E.jsx)(`circle`,{cx:t.x,cy:t.y,r:4,fill:e.series.color,stroke:`var(--color-card)`,strokeWidth:2,"data-testid":`point-${e.series.key}`},e.series.key)})]})}return(0,E.jsxs)(`g`,{"data-testid":`area-layers`,children:[e.map((e,n)=>(0,E.jsx)(`path`,{d:e.areaPath,fill:`url(#${t}-grad-${n})`,"data-testid":`area-series-${e.series.key}`},e.series.key)),e.map(e=>e.strokePaths.map((t,n)=>(0,E.jsx)(`path`,{d:t,fill:`none`,stroke:e.series.color,strokeWidth:1.75,strokeLinecap:`round`,strokeLinejoin:`round`},`${e.series.key}-${n}`)))]})}function xe({categories:e,xs:t,plotWidth:n,plotHeight:r,labels:i,onEnter:a}){let o=e.length;return(0,E.jsx)(`g`,{"data-testid":`chart-slots`,children:e.map((e,s)=>{let c=0,l=n;if(o>1){let e=s===0?t[0]:(t[s-1]+t[s])/2,n=s===o-1?t[o-1]:(t[s]+t[s+1])/2;c=e,l=Math.max(1,n-e)}return(0,E.jsxs)(`g`,{"data-testid":`slot-${e.key}`,children:[(0,E.jsx)(`rect`,{x:c,y:0,width:l,height:r,fill:`transparent`,onMouseEnter:()=>a(s),children:(0,E.jsx)(`title`,{children:e.title})}),i.has(s)?(0,E.jsx)(`text`,{x:t[s]??0,y:r+16,textAnchor:`middle`,fontSize:11,style:W,children:e.label}):null]},e.key)})})}function Se({active:e,activeX:t,plotHeight:n,layers:r}){return e===null||t===void 0?null:(0,E.jsxs)(`g`,{"data-testid":`crosshair`,children:[(0,E.jsx)(`line`,{x1:t,x2:t,y1:0,y2:n,stroke:`var(--color-muted-foreground)`,strokeWidth:1,strokeDasharray:`2 2`}),r.map(t=>{let n=t.points[e],r=t.series.values[e]??0;return!n||r<=0?null:(0,E.jsx)(`circle`,{cx:n.x,cy:n.y,r:4,fill:t.series.color,stroke:`var(--color-card)`,strokeWidth:2,"data-testid":`marker-${t.series.key}`},t.series.key)})]})}function Ce({category:e,series:t,index:n,total:r,left:i,format:a}){return(0,E.jsx)(_e,{title:e.title,total:r,left:i,rows:t.filter(e=>(e.values[n]??0)>0).map(e=>({key:e.key,label:e.label,color:e.color,value:a(e.values[n]??0)}))})}function we({series:e}){return(0,E.jsx)(`ul`,{className:`flex flex-wrap gap-x-4 gap-y-1 text-xs`,children:e.map(e=>(0,E.jsxs)(`li`,{className:`flex items-center gap-1.5`,children:[(0,E.jsx)(`span`,{"aria-hidden":`true`,className:`size-2 rounded-full`,style:{backgroundColor:e.color}}),e.label]},e.key))})}function G({caption:e,head:t,rows:n}){return(0,E.jsxs)(`table`,{className:`sr-only`,children:[(0,E.jsx)(`caption`,{children:e}),(0,E.jsx)(`thead`,{children:(0,E.jsx)(`tr`,{children:t.map(e=>(0,E.jsx)(`th`,{scope:`col`,children:e},e))})}),(0,E.jsx)(`tbody`,{children:n.map(e=>(0,E.jsx)(`tr`,{children:e.map((e,t)=>t===0?(0,E.jsx)(`th`,{scope:`row`,children:e},e):(0,E.jsx)(`td`,{children:e},`${t}:${e}`))},e.join(`\0`)))})]})}function Te(e,t=4){return!Number.isFinite(e)||e<=0?{ticks:[0,1],max:1}:ie(e*1.08,t)}function Ee(e){let t=e.length;if(t<=1)return t===1?[0]:[];if(t===2){let t=e[1].x-e[0].x,n=t===0?0:(e[1].y-e[0].y)/t;return[n,n]}let n=[];for(let r=0;r<t-1;r+=1){let t=e[r+1].x-e[r].x;n.push(t===0?0:(e[r+1].y-e[r].y)/t)}let r=[n[0]];for(let e=1;e<t-1;e+=1){let t=n[e-1],i=n[e];r.push(t>0&&i>0||t<0&&i<0?(t+i)/2:0)}r.push(n[t-2]);for(let e=0;e<t-1;e+=1){let t=n[e];if(Math.abs(t)<1e-9){r[e]=0,r[e+1]=0;continue}let i=r[e]/t,a=r[e+1]/t;i<0&&(r[e]=0),a<0&&(r[e+1]=0);let o=i*i+a*a;if(o>9){let n=3/Math.sqrt(o);r[e]=n*i*t,r[e+1]=n*a*t}}return r}function De(e,t){let n=[];for(let r=0;r<e.length-1;r+=1){let i=e[r],a=e[r+1],o=(a.x-i.x)/3;n.push({cp1:{x:i.x+o,y:i.y+(t[r]??0)*o},cp2:{x:a.x-o,y:a.y-(t[r+1]??0)*o}})}return n}var K=e=>Number(e.toFixed(2)).toString();function Oe(e,t,n,r){let i=e.length;if(i<=1)return``;let a=e[0],o=[`M ${K(a.x)} ${K(a.y)}`];for(let n=0;n<i-1;n+=1){let r=t[n],i=e[n+1];o.push(`C ${K(r.cp1.x)} ${K(r.cp1.y)}, ${K(r.cp2.x)} ${K(r.cp2.y)}, ${K(i.x)} ${K(i.y)}`)}let s=n[i-1];o.push(`L ${K(s.x)} ${K(s.y)}`);for(let e=i-2;e>=0;--e){let t=r[e],i=n[e];o.push(`C ${K(t.cp2.x)} ${K(t.cp2.y)}, ${K(t.cp1.x)} ${K(t.cp1.y)}, ${K(i.x)} ${K(i.y)}`)}return o.push(`Z`),o.join(` `)}function ke(e,t,n){let r=e.length;if(r<=1)return[];let i=[],a=[];for(let o=0;o<r-1;o+=1)if((n[o]??0)>0||(n[o+1]??0)>0){a.length===0&&a.push(`M ${K(e[o].x)} ${K(e[o].y)}`);let n=t[o],r=e[o+1];a.push(`C ${K(n.cp1.x)} ${K(n.cp1.y)}, ${K(n.cp2.x)} ${K(n.cp2.y)}, ${K(r.x)} ${K(r.y)}`)}else a.length>0&&(i.push(a.join(` `)),a=[]);return a.length>0&&i.push(a.join(` `)),i}function Ae(e,t,n){let r=new Set,i=-1/0;for(let a=0;a<e.length;a+=1){let o=e[a]?.label;if(!o||o.trim().length===0)continue;let s=t[a]??0;(s-i>=n||i===-1/0)&&(r.add(a),i=s)}return r}function q(e,t){return e<=0?[]:e===1?[t/2]:Array.from({length:e},(n,r)=>r*t/(e-1))}function je({series:e,count:t,plotWidth:n,plotHeight:r,max:i}){if(t<=0)return[];let a=q(t,n),o=[Array(t).fill(0)];e.forEach((e,t)=>{let n=o[t];o.push(n.map((t,n)=>t+(e.values[n]??0)))});let s=o.map(e=>{let t=e.map((e,t)=>({x:a[t]??0,y:r-ae(e,i,r)})),n=Ee(t);return{points:t,tangents:n,controls:De(t,n)}});return e.map((e,t)=>{let n=s[t],r=s[t+1];return{series:e,areaPath:Oe(r.points,r.controls,n.points,n.controls),strokePaths:ke(r.points,r.controls,e.values),points:r.points}})}var J=260,Y={top:12,right:12,bottom:26,left:52},Me=44,Ne=640;function Pe(){let e=(0,T.useRef)(null),[t,n]=(0,T.useState)(Ne);return(0,T.useEffect)(()=>{let t=e.current;if(t===null)return;let r=()=>{t.clientWidth>0&&n(t.clientWidth)};r();let i=new ResizeObserver(r);return i.observe(t),()=>i.disconnect()},[]),[e,t]}function Fe(e,t,n){return e===`ArrowRight`?Math.min(n,t+1):e===`ArrowLeft`?Math.max(0,t-1):e===`Home`?0:e===`End`?n:null}function Ie({width:e,series:t,idPrefix:n,ticks:r,max:i,plotWidth:a,plotHeight:o,format:s,layers:c,isSingle:l,categories:u,xs:d,labels:f,active:p,activeX:m,onEnter:h}){return(0,E.jsxs)(`svg`,{viewBox:`0 0 ${e} ${J}`,className:`block w-full overflow-visible`,style:{height:`${J}px`},children:[(0,E.jsx)(ve,{series:t,idPrefix:n}),(0,E.jsxs)(`g`,{transform:`translate(${Y.left}, ${Y.top})`,children:[(0,E.jsx)(ye,{ticks:r,max:i,plotWidth:a,plotHeight:o,format:s}),(0,E.jsx)(be,{layers:c,idPrefix:n,plotWidth:a,plotHeight:o,isSingle:l}),(0,E.jsx)(xe,{categories:u,xs:d,plotWidth:a,plotHeight:o,labels:f,onEnter:h}),(0,E.jsx)(Se,{active:p,activeX:m,plotHeight:o,layers:c})]})]})}function Le(e){return(0,E.jsx)(G,{caption:e.caption,head:[e.categoryHead,...e.series.map(e=>e.label),e.totalLabel],rows:e.categories.map((t,n)=>[t.title,...e.series.map(t=>e.format(t.values[n]??0)),e.format(e.totals[n]??0)])})}function Re(e,t,n){let r=e.length,i=Math.max(n,Y.left+Y.right+10),a=i-Y.left-Y.right,o=J-Y.top-Y.bottom,s=ce(t,r),{ticks:c,max:l}=Te(Math.max(0,...s)),u=q(r,a);return{width:i,plotWidth:a,plotHeight:o,totals:s,ticks:c,max:l,xs:u,layers:je({series:t,count:r,plotWidth:a,plotHeight:o,max:l}),labels:Ae(e,u,Me*1.2)}}function ze(e){return e.active===null||e.category===void 0||e.activeX===void 0?null:(0,E.jsx)(Ce,{category:e.category,series:e.series,index:e.active,total:e.format(e.totals[e.active]??0),left:Math.min(Math.max(Y.left+e.activeX,80),e.width-80),format:e.format})}function Be(e){let{label:t,categories:n,series:r,format:i,categoryHead:a,totalLabel:o}=e,[s,c]=Pe(),l=(0,T.useId)().replace(/[^a-zA-Z0-9-_]/g,``),[u,d]=(0,T.useState)(null),f=n.length,p=Re(n,r,c),m=e=>{if(f<=0)return;let t=Fe(e.key,u??0,f-1);t!==null&&(e.preventDefault(),d(t))},h=u===null?void 0:p.xs[u],g=u===null?void 0:n[u];return(0,E.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,E.jsxs)(`div`,{ref:s,role:`group`,"aria-label":t,tabIndex:0,className:`relative rounded-md outline-none focus-visible:ring-2 focus-visible:ring-ring`,onFocus:()=>d(e=>e??0),onBlur:()=>d(null),onKeyDown:m,onMouseLeave:()=>d(null),children:[(0,E.jsx)(Ie,{width:p.width,series:r,idPrefix:l,ticks:p.ticks,max:p.max,plotWidth:p.plotWidth,plotHeight:p.plotHeight,format:i,layers:p.layers,isSingle:f===1,categories:n,xs:p.xs,labels:p.labels,active:u,activeX:h,onEnter:d}),(0,E.jsx)(ze,{active:u,category:g,activeX:h,series:r,totals:p.totals,width:p.width,format:i})]}),(0,E.jsx)(we,{series:r}),(0,E.jsx)(Le,{caption:t,categoryHead:a,totalLabel:o,categories:n,series:r,totals:p.totals,format:i})]})}function X({label:e,rows:t,valueHead:n,nameHead:r}){let i=t.reduce((e,t)=>e+t.value,0),a=e=>i>0?Math.round(e/i*100):0;return(0,E.jsxs)(`div`,{role:`group`,"aria-label":e,className:`flex flex-col gap-2`,children:[(0,E.jsx)(`ul`,{className:`flex flex-col gap-2`,children:t.map(e=>(0,E.jsxs)(`li`,{tabIndex:0,"aria-label":`${e.label}: ${e.text} · ${a(e.value)}%`,className:`flex flex-col gap-1 rounded-sm text-sm outline-none focus-visible:ring-2 focus-visible:ring-ring`,children:[(0,E.jsxs)(`span`,{className:`flex justify-between gap-2`,children:[(0,E.jsx)(`span`,{className:`truncate`,children:e.label}),(0,E.jsxs)(`span`,{className:`shrink-0 tabular-nums text-muted-foreground`,children:[e.text,` · `,a(e.value),`%`]})]}),(0,E.jsx)(`span`,{className:`h-2 rounded-full bg-muted`,"aria-hidden":`true`,children:(0,E.jsx)(`span`,{className:`block h-2 rounded-full`,style:{width:`${a(e.value)}%`,backgroundColor:e.color}})})]},e.key))}),(0,E.jsx)(G,{caption:e,head:[r,n,`%`],rows:t.map(e=>[e.label,e.text,`${a(e.value)}%`])})]})}function Ve({label:e,segments:t,valueHead:n,nameHead:r}){let i=t.reduce((e,t)=>e+t.value,0);return(0,E.jsxs)(`div`,{role:`group`,"aria-label":e,className:`flex flex-col gap-2`,children:[(0,E.jsx)(`div`,{className:`flex h-3 overflow-hidden rounded-full bg-muted`,"aria-hidden":`true`,children:t.filter(e=>e.value>0).map(e=>(0,E.jsx)(`span`,{"data-testid":`stack-${e.key}`,style:{width:`${e.value/i*100}%`,backgroundColor:e.color}},e.key))}),(0,E.jsx)(`ul`,{className:`flex flex-wrap gap-x-4 gap-y-1 text-sm`,children:t.map(e=>(0,E.jsxs)(`li`,{className:`flex items-center gap-1.5`,children:[(0,E.jsx)(`span`,{"aria-hidden":`true`,className:`size-2 rounded-full`,style:{backgroundColor:e.color}}),(0,E.jsx)(`span`,{children:e.label}),(0,E.jsx)(`span`,{className:`tabular-nums text-muted-foreground`,children:e.value})]},e.key))}),(0,E.jsx)(G,{caption:e,head:[r,n],rows:t.map(e=>[e.label,String(e.value)])})]})}var He=Array.from({length:8},(e,t)=>`var(--color-chart-${t+1})`),Ue=`var(--color-status-mute)`,We={finished:`var(--color-status-ok)`,failed:`var(--color-status-err)`,cancelled:`var(--color-status-mute)`};function Ge(e){return e===null?null:/#[0-9a-f]{6}/i.exec(ee[e]??``)?.[0]??null}function Z(e,t){let n={},r=0;for(let i of e){let e=Ge(t(i));e===null?(n[i]=He[r%8]??`var(--color-status-mute)`,r+=1):n[i]=e}return n}function Ke(e){let{t}=v();return(0,E.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,E.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,E.jsx)(`h2`,{className:`text-sm font-semibold`,children:t(`stats.daily.title`)}),(0,E.jsx)(p,{variant:`outline`,className:`font-normal text-muted-foreground`,children:t(`stats.daily.buckets.${e.bucket}`)})]}),(0,E.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,E.jsx)(m,{type:`single`,value:e.split,"aria-label":t(`stats.daily.split`),onValueChange:t=>{let n=k.find(e=>e===t);n!==void 0&&e.onSplit(n)},children:k.map(e=>(0,E.jsx)(h,{value:e,children:t(`stats.daily.splits.${e}`)},e))}),(0,E.jsx)(m,{type:`single`,value:e.metric,"aria-label":t(`stats.daily.metric`),onValueChange:t=>{let n=O.find(e=>e===t);n!==void 0&&e.onMetric(n)},children:e.metrics.map(e=>(0,E.jsx)(h,{value:e,children:t(`stats.daily.metrics.${e}`)},e))})]})]})}function qe({report:e}){let{t,i18n:n}=v(),[r,i]=(0,T.useState)(`tokens`),[a,o]=(0,T.useState)(`projects`),s=le(a),u=s.includes(r)?r:`tokens`,d=e.bucket??`day`,f=a===`models`?ue(e):[...new Set(e.series.flatMap(e=>e.projects.map(e=>e.repository)))],p=N(e,u,a,{labelOf:l,modelLabelOf:e=>z(e,t),colors:Z(f,a===`models`?()=>null:c),other:{label:t(`stats.daily.other`),color:Ue}}),m=he(e.series,d,n.language),h=e=>u===`tokens`?A(e):u===`agent`?j(e,t):String(Math.round(e)),g=t(`stats.daily.metrics.${u}`);return(0,E.jsxs)(_,{className:`flex flex-col gap-3 p-4`,children:[(0,E.jsx)(Ke,{bucket:d,metrics:s,metric:u,split:a,onMetric:i,onSplit:o}),(0,E.jsx)(Be,{label:t(a===`models`?`stats.daily.chartLabelModels`:`stats.daily.chartLabel`,{metric:g}),categories:m,series:p,format:h,categoryHead:t(`stats.daily.categoryHeads.${d}`),totalLabel:t(`stats.daily.total`)})]})}function Q({label:e,value:t,title:n,children:r}){return(0,E.jsxs)(_,{className:`flex flex-col gap-1 p-3`,"data-testid":`kpi-tile`,children:[(0,E.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e}),(0,E.jsx)(`span`,{className:`text-2xl font-semibold tabular-nums`,title:n,children:t}),r?(0,E.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:r}):null]})}function Je({report:e}){let{t,i18n:n}=v(),{totals:r,perTask:i,outcomes:a}=e,o=e=>e.toLocaleString(n.language);return(0,E.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,E.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 xl:grid-cols-4`,children:[(0,E.jsx)(Q,{label:t(`stats.tiles.tokens`),value:A(r.tokens),title:o(r.tokens),children:t(`stats.tiles.tokensSplit`,{input:A(r.inputTokens),output:A(r.outputTokens)})}),(0,E.jsx)(Q,{label:t(`stats.tiles.agent`),value:j(r.agentMs,t)}),(0,E.jsx)(Q,{label:t(`stats.tiles.tasks`),value:String(r.tasks),children:t(`stats.tiles.outcomes`,a)})]}),(0,E.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,E.jsx)(Q,{label:t(`stats.tiles.perTaskTokens`),value:A(i.tokens.mean),title:o(Math.round(i.tokens.mean)),children:t(`stats.tiles.median`,{value:A(i.tokens.median)})}),(0,E.jsx)(Q,{label:t(`stats.tiles.perTaskAgent`),value:j(i.agentMs.mean,t),children:t(`stats.tiles.median`,{value:j(i.agentMs.median,t)})})]})]})}var $=[`finished`,`failed`,`cancelled`];function Ye({report:e}){let{t}=v(),n=e.repository===null,r=Z(e.projects.map(e=>e.repository),c),i=n=>pe(e,n).map(e=>({key:e.repository,label:l(e.repository),color:r[e.repository]??``,value:e.value,text:n===`tokens`?A(e.value):j(e.value,t)}));return(0,E.jsxs)(`div`,{className:`grid gap-3 ${n?`xl:grid-cols-3`:``}`,children:[n?(0,E.jsxs)(E.Fragment,{children:[(0,E.jsxs)(_,{className:`p-4`,children:[(0,E.jsx)(`h2`,{className:`mb-3 text-sm font-semibold`,children:t(`stats.shares.tokens`)}),(0,E.jsx)(X,{label:t(`stats.shares.tokens`),rows:i(`tokens`),nameHead:t(`stats.projects.project`),valueHead:t(`stats.tiles.tokens`)})]}),(0,E.jsxs)(_,{className:`p-4`,children:[(0,E.jsx)(`h2`,{className:`mb-3 text-sm font-semibold`,children:t(`stats.shares.agent`)}),(0,E.jsx)(X,{label:t(`stats.shares.agent`),rows:i(`agent`),nameHead:t(`stats.projects.project`),valueHead:t(`stats.tiles.agent`)})]})]}):null,(0,E.jsxs)(_,{className:`p-4`,children:[(0,E.jsx)(`h2`,{className:`mb-3 text-sm font-semibold`,children:t(`stats.shares.outcomes`)}),(0,E.jsx)(Ve,{label:t(`stats.shares.outcomes`),nameHead:t(`stats.shares.outcome`),valueHead:t(`stats.tiles.tasks`),segments:$.map(n=>({key:n,label:t(`stats.shares.outcomeNames.${n}`),color:We[n],value:e.outcomes[n]}))})]})]})}function Xe({api:e,repository:t,onCleared:n}){let{t:r}=v(),i=y(),a=l(t),o=async()=>{if(await i({title:r(`stats.clear.title`,{name:a}),description:r(`stats.clear.description`),confirmLabel:r(`stats.clear.confirm`),destructive:!0}))try{let{removed:i}=await e.statsClear(t);te(r(`stats.clear.done`,{count:i,name:a})),n()}catch(e){b(e)}};return(0,E.jsx)(f,{type:`button`,variant:`ghost`,size:`sm`,"aria-label":r(`stats.clear.action`,{name:a}),title:r(`stats.clear.action`,{name:a}),onClick:()=>void o(),children:(0,E.jsx)(w,{})})}function Ze(e){let{t,onSelect:n,actions:r}=e,i=(e,t,n)=>({key:e,label:t,numeric:!0,cell:e=>n(e)??`—`}),a=e=>j(e,t);return[{key:`name`,label:t(`stats.projects.project`),cell:e=>e.repository===null?t(`stats.projects.all`):(0,E.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,E.jsx)(ne,{path:e.repository}),(0,E.jsx)(`button`,{type:`button`,className:`rounded-sm text-left hover:underline`,title:e.repository,onClick:()=>n(e.repository),children:l(e.repository)})]})},i(`tasks`,t(`stats.projects.tasks`),e=>String(e.totals.tasks)),i(`tokens`,t(`stats.tiles.tokens`),e=>A(e.totals.tokens)),i(`agent`,t(`stats.tiles.agent`),e=>a(e.totals.agentMs)),i(`wall`,t(`stats.projects.wall`),e=>a(e.totals.wallMs)),i(`meanTokens`,t(`stats.projects.meanTokens`),e=>A(e.perTask.tokens.mean)),i(`medianTokens`,t(`stats.projects.medianTokens`),e=>A(e.perTask.tokens.median)),i(`meanAgent`,t(`stats.projects.meanAgent`),e=>a(e.perTask.agentMs.mean)),i(`medianAgent`,t(`stats.projects.medianAgent`),e=>a(e.perTask.agentMs.median)),{key:`actions`,label:``,cell:e=>e.repository===null?null:r(e.repository)}]}function Qe({api:e,report:t,onSelect:n,onCleared:r}){let{t:i}=v(),[a,o]=(0,T.useState)(null),s=F(t.projects,a,(e,t)=>t===`name`?l(e.repository):I(e,t)),c={repository:null,totals:t.totals,perTask:t.perTask},u=Ze({t:i,onSelect:n,actions:t=>(0,E.jsx)(Xe,{api:e,repository:t,onCleared:r})});return(0,E.jsxs)(_,{className:`p-4`,children:[(0,E.jsx)(`h2`,{className:`mb-3 text-sm font-semibold`,children:i(`stats.projects.title`)}),(0,E.jsx)(D,{caption:i(`stats.projects.title`),columns:u,rows:s,pinned:c,sort:a,onSort:e=>o(t=>P(t,e)),rowKey:e=>e.repository??`\0all`})]})}var $e=[`7d`,`30d`,`90d`,`all`];function et({period:e,project:t,registry:n,onChange:r}){let{t:i}=v(),a=n.some(e=>e.path===t);return(0,E.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,E.jsx)(m,{type:`single`,value:e,"aria-label":i(`stats.filters.period`),onValueChange:e=>{let n=u.find(t=>t===e);n!==void 0&&r(n,t)},children:$e.map(e=>(0,E.jsx)(h,{value:e,children:i(`stats.filters.periods.${e}`)},e))}),(0,E.jsxs)(`label`,{className:`flex items-center gap-2 text-sm`,children:[(0,E.jsx)(`span`,{className:`text-muted-foreground`,children:i(`stats.filters.project`)}),(0,E.jsxs)(`select`,{className:`h-8 max-w-64 rounded-md border border-input bg-card px-2 text-sm`,value:t??``,onChange:t=>r(e,t.target.value===``?null:t.target.value),children:[(0,E.jsx)(`option`,{value:``,children:i(`stats.filters.allProjects`)}),t!==null&&!a?(0,E.jsx)(`option`,{value:t,children:g(t)}):null,n.map(e=>(0,E.jsx)(`option`,{value:e.path,children:e.label},e.path))]})]})]})}var tt=5e3;function nt(e){return e.map(e=>`${e.id}:${e.state}:${e.counts}:${JSON.stringify(e.usage)}`).join(`|`)}function rt(e,t,n,r){let[i,a]=(0,T.useState)(null),[o,s]=(0,T.useState)(null),[c,l]=(0,T.useState)(!0),u=(0,T.useRef)(0),d=(0,T.useRef)(0),f=(0,T.useCallback)(r=>{u.current+=1;let i=u.current;d.current=Date.now(),r&&l(!0),e.statsReport({bucket:`auto`,since:fe(t,Date.now()),...n===null?{}:{repository:n}}).then(e=>{i===u.current&&(a(e),s(null),l(!1))}).catch(e=>{i===u.current&&(s(e instanceof Error?e.message:String(e)),l(!1))})},[e,t,n]);(0,T.useEffect)(()=>(a(null),f(!0),()=>{u.current+=1}),[f]);let p=nt(r),m=(0,T.useRef)(p);return(0,T.useEffect)(()=>{if(m.current===p)return;m.current=p;let e=Math.max(0,d.current+tt-Date.now()),t=setTimeout(()=>f(!1),e);return()=>clearTimeout(t)},[p,f]),{report:i,error:o,loading:c,reload:()=>f(!0)}}function it({api:e,report:t,onProject:n,onCleared:r}){let{t:a}=v();return me(t)?(0,E.jsx)(x,{icon:(0,E.jsx)(i,{}),title:a(`stats.empty.title`),children:(0,E.jsx)(`p`,{children:a(`stats.empty.hint`)})}):(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(Je,{report:t}),(0,E.jsx)(qe,{report:t}),(0,E.jsx)(Ye,{report:t}),(0,E.jsx)(Qe,{api:e,report:t,onSelect:n,onCleared:r}),(0,E.jsx)(ge,{report:t})]})}function at({api:e,registry:t,runs:n,period:r,project:i,onFilter:a}){let{t:o}=v(),{report:c,error:l,loading:u,reload:p}=rt(e,r,i,n);return(0,E.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-4 p-4`,"data-testid":`stats-page`,children:[(0,E.jsx)(et,{period:r,project:i,registry:t,onChange:a}),c!==null&&!c.settings.enabled?(0,E.jsxs)(s,{variant:`warn`,className:`flex flex-wrap items-center gap-2`,children:[(0,E.jsx)(`span`,{children:o(`stats.disabled.title`)}),(0,E.jsx)(`a`,{href:`#settings/global/system`,className:`underline underline-offset-2`,children:o(`stats.disabled.open`)})]}):null,l===null?null:(0,E.jsxs)(s,{variant:`destructive`,className:`flex flex-wrap items-center gap-2`,children:[(0,E.jsx)(`span`,{children:o(`stats.error`,{message:l})}),(0,E.jsx)(f,{type:`button`,variant:`outline`,size:`sm`,onClick:p,children:o(`stats.retry`)})]}),c===null&&u?(0,E.jsxs)(`div`,{role:`status`,"aria-label":o(`stats.loading`),className:`flex flex-col gap-3`,children:[(0,E.jsx)(d,{className:`h-24`}),(0,E.jsx)(d,{className:`h-64`})]}):null,c===null?null:(0,E.jsx)(it,{api:e,report:c,onProject:e=>a(r,e),onCleared:p})]})}export{at as StatsPage};
1
+ import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{A as t,D as n,O as r,St as i,k as a}from"./index-LD1g1Vkm.js";import{F as o,a as s,d as c,f as l,g as u,i as d,j as f,k as p,n as m,r as h,s as g,t as _,ut as v}from"./card-4euJkmfJ.js";import{a as y,n as b,o as ee,r as te,s as ne,t as x}from"./empty-OZRGgwa5.js";import{i as S,t as C}from"./vendor-react-C1iE8mnY.js";import{t as w}from"./trash-xUZ90-AG.js";var T=e(S(),1),E=C();function D({caption:e,columns:t,rows:n,pinned:r,sort:i,onSort:a,rowKey:s}){let c=(e,n)=>(0,E.jsx)(`tr`,{className:o(`border-t`,n&&`bg-muted/40 font-medium`),children:t.map(t=>(0,E.jsx)(`td`,{className:o(`px-3 py-1.5`,t.numeric&&`text-right tabular-nums`),children:t.cell(e)},t.key))},s(e));return(0,E.jsx)(`div`,{className:`overflow-x-auto`,"data-testid":`stats-table-scroll`,children:(0,E.jsxs)(`table`,{className:`w-full min-w-max text-sm`,children:[(0,E.jsx)(`caption`,{className:`sr-only`,children:e}),(0,E.jsx)(`thead`,{children:(0,E.jsx)(`tr`,{className:`text-xs text-muted-foreground`,children:t.map(e=>{let t=i?.key===e.key;return(0,E.jsx)(`th`,{scope:`col`,"aria-sort":t?i.direction===`asc`?`ascending`:`descending`:`none`,className:o(`px-3 py-1.5 font-medium`,e.numeric&&`text-right`),children:(0,E.jsxs)(`button`,{type:`button`,className:`rounded-sm hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring`,onClick:()=>a(e.key),children:[e.label,t?i.direction===`asc`?` ↑`:` ↓`:``]})},e.key)})})}),(0,E.jsxs)(`tbody`,{children:[r===void 0?null:c(r,!0),n.map(e=>c(e,!1))]})]})})}function re(e,t){let n=e/t,r=10**Math.floor(Math.log10(n)),i=n/r;return(i<=1?1:i<=2?2:i<=2.5?2.5:i<=5?5:10)*r}function ie(e,t=4){if(!Number.isFinite(e)||e<=0)return{ticks:[0,1],max:1};let n=re(e,t),r=Math.ceil(e/n-1e-9),i=Array.from({length:r+1},(e,t)=>Number((t*n).toPrecision(12)));return{ticks:i,max:i[i.length-1]??1}}function ae(e,t,n){return t<=0||e<=0?0:Math.min(n,e/t*n)}var oe=`__other`;function se(e,t,n){if(e.length<=t)return e;let r=e=>e.values.reduce((e,t)=>e+t,0),i=[...e].sort((e,t)=>r(t)-r(e)),a=new Set(i.slice(0,t).map(e=>e.key)),o=e.filter(e=>!a.has(e.key)),s=e[0]?.values.length??0,c=Array.from({length:s},(e,t)=>o.reduce((e,n)=>e+(n.values[t]??0),0));return[...e.filter(e=>a.has(e.key)),{key:oe,label:n.label,color:n.color,values:c}]}function ce(e,t){return Array.from({length:t},(t,n)=>e.reduce((e,t)=>e+(t.values[n]??0),0))}var O=[`tokens`,`agent`,`tasks`],k=[`projects`,`models`];function le(e){return O.filter(t=>t!==`tasks`||e===`projects`)}function ue(e){return[...new Set([...e.byModel.map(e=>e.key),...e.series.flatMap(e=>e.models.map(e=>e.model))])]}var de={"7d":7,"30d":30,"90d":90};function fe(e,t){if(e===`all`)return;let n=new Date(t);return new Date(n.getFullYear(),n.getMonth(),n.getDate()-(de[e]-1)).getTime()}function A(e){let t=e=>String(Number(e.toFixed(1)));return e>=1e6?`${t(e/1e6)}M`:e>=1e3?`${t(e/1e3)}k`:String(Math.round(e))}function j(e,t){let n=Math.round(Math.max(0,e)/6e4);if(n<1)return t(`stats.unit.seconds`,{count:Math.round(e/1e3)});let r=Math.floor(n/60),i=n%60;return r===0?t(`stats.unit.minutes`,{count:i}):i===0?t(`stats.unit.hours`,{count:r}):`${t(`stats.unit.hours`,{count:r})} ${t(`stats.unit.minutes`,{count:i})}`}function M(e,t){return e===`tokens`?t.tokens:e===`agent`?t.agentMs:t.tasks??0}function N(e,t,n,r){let i=e=>n===`models`?e.models.map(e=>({key:e.model,entry:e})):e.projects.map(e=>({key:e.repository,entry:e}));return se([...new Set(e.series.flatMap(e=>i(e).map(e=>e.key)))].map(a=>({key:a,label:n===`models`?r.modelLabelOf?.(a)??a:r.labelOf(a),color:r.colors[a]??r.other.color,values:e.series.map(e=>{let n=i(e).find(e=>e.key===a);return n===void 0?0:M(t,n.entry)})})),8,r.other)}function P(e,t){return e?.key===t?{key:t,direction:e.direction===`asc`?`desc`:`asc`}:{key:t,direction:`asc`}}function F(e,t,n){if(t===null)return[...e];let r=t.direction===`asc`?1:-1;return[...e].sort((e,i)=>{let a=n(e,t.key),o=n(i,t.key);return a===null&&o===null?0:a===null?1:o===null?-1:typeof a==`string`||typeof o==`string`?r*String(a).localeCompare(String(o),`en`,{sensitivity:`base`}):r*(a-o)})}function I(e,t){let{totals:n,perTask:r}=e;switch(t){case`tasks`:return n.tasks;case`tokens`:return n.tokens;case`agent`:return n.agentMs;case`wall`:return n.wallMs;case`meanTokens`:return r.tokens.mean;case`medianTokens`:return r.tokens.median;case`meanAgent`:return r.agentMs.mean;case`medianAgent`:return r.agentMs.median;default:return null}}var L=`unknown`,R=[`claude`,`opencode`,`agy`,`command`];function z(e,t){return e===L?t(`stats.breakdown.keys.unknown`):e}function B(e,t,n){let r=t.name??t.key;return t.name===null&&(e===`specialist`&&t.key===`naming`?r=n(`stats.breakdown.keys.naming`):e===`model`?r=z(t.key,n):e===`runtime`&&R.includes(t.key)&&(r=n(`stats.breakdown.runtimes.${t.key}`))),{text:r,title:r===t.key?void 0:t.key}}function V(e,t){switch(t){case`name`:return e.key;case`attempts`:return e.attempts;case`input`:return e.inputTokens;case`output`:return e.outputTokens;case`agent`:return e.agentMs;case`perAttempt`:return e.tokensPerAttempt;default:return null}}function pe(e,t){return e.projects.map(e=>({repository:e.repository,value:t===`tokens`?e.totals.tokens:e.totals.agentMs})).filter(e=>e.value>0).sort((e,t)=>t.value-e.value)}function me(e){return e.totals.tasks===0&&e.totals.attempts===0}var H=e=>String(e).padStart(2,`0`);function he(e,t,n){let r=new Intl.DateTimeFormat(n,{day:`numeric`,month:`short`}),i=new Intl.DateTimeFormat(n,{dateStyle:`medium`});return e.map(e=>{if(t===`6h`){let t=new Date(e.start),n=H(t.getHours()),a=H(new Date(t.getFullYear(),t.getMonth(),t.getDate(),t.getHours()+6).getHours()),o=t.getHours()===0?r.format(e.start):``,s=`${i.format(e.start)}, ${n}:00–${a}:00`;return{key:e.day,label:o,title:s}}if(t===`week`){let t=new Date(e.start),n=new Date(t.getFullYear(),t.getMonth(),t.getDate()+6).getTime(),i=r.format(e.start),a=`${r.format(e.start)} – ${r.format(n)}`;return{key:e.day,label:i,title:a}}return{key:e.day,label:r.format(e.start),title:i.format(e.start)}})}var U=[{id:`specialist`,rows:e=>e.bySpecialist},{id:`model`,rows:e=>e.byModel},{id:`pipeline`,rows:e=>e.byPipeline},{id:`runtime`,rows:e=>e.byRuntime}];function ge({report:e}){let{t:i}=v(),[o,s]=(0,T.useState)(`specialist`),[c,l]=(0,T.useState)(null),u=(e,t,n)=>({key:e,label:t,numeric:!0,cell:n}),d=e=>[{key:`name`,label:i(`stats.breakdown.name`),cell:t=>{let{text:n,title:r}=B(e,t,i);return r===void 0?n:(0,E.jsx)(`span`,{title:r,children:n})}},u(`attempts`,i(`stats.breakdown.attempts`),e=>String(e.attempts)),u(`input`,i(`stats.breakdown.input`),e=>A(e.inputTokens)),u(`output`,i(`stats.breakdown.output`),e=>A(e.outputTokens)),u(`agent`,i(`stats.tiles.agent`),e=>j(e.agentMs,i)),u(`perAttempt`,i(`stats.breakdown.perAttempt`),e=>A(e.tokensPerAttempt))],f=e=>(t,n)=>n===`name`?B(e,t,i).text:V(t,n);return(0,E.jsx)(_,{className:`p-4`,children:(0,E.jsxs)(n,{value:o,onValueChange:s,children:[(0,E.jsx)(a,{"aria-label":i(`stats.breakdown.title`),children:U.map(({id:e})=>(0,E.jsx)(t,{value:e,children:i(`stats.breakdown.tabs.${e}`)},e))}),U.map(({id:t,rows:n})=>(0,E.jsx)(r,{value:t,children:(0,E.jsx)(D,{caption:i(`stats.breakdown.tabs.${t}`),columns:d(t),rows:F(n(e),c,f(t)),sort:c,onSort:e=>l(t=>P(t,e)),rowKey:e=>e.key})},t))]})})}function _e({title:e,total:t,rows:n,left:r}){return(0,E.jsxs)(`div`,{role:`status`,"data-testid":`chart-tooltip`,className:`pointer-events-none absolute top-0 z-10 min-w-40 max-w-64 -translate-x-1/2 rounded-md border bg-card p-2 text-xs text-card-foreground shadow-md`,style:{left:r??0},children:[(0,E.jsxs)(`div`,{className:`flex justify-between gap-3 font-medium`,children:[(0,E.jsx)(`span`,{children:e}),(0,E.jsx)(`span`,{children:t})]}),(0,E.jsx)(`ul`,{className:`mt-1 flex flex-col gap-0.5`,children:n.map(e=>(0,E.jsxs)(`li`,{className:`flex items-center justify-between gap-3`,children:[(0,E.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1.5`,children:[(0,E.jsx)(`span`,{"aria-hidden":`true`,className:`size-2 shrink-0 rounded-full`,style:{backgroundColor:e.color}}),(0,E.jsx)(`span`,{className:`truncate`,children:e.label})]}),(0,E.jsx)(`span`,{className:`shrink-0 tabular-nums`,children:e.value})]},e.key))})]})}var W={fill:`var(--color-muted-foreground)`};function ve({series:e,idPrefix:t}){return(0,E.jsx)(`defs`,{children:e.map((e,n)=>(0,E.jsxs)(`linearGradient`,{id:`${t}-grad-${n}`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,E.jsx)(`stop`,{offset:`0%`,stopColor:e.color,stopOpacity:`0.40`}),(0,E.jsx)(`stop`,{offset:`100%`,stopColor:e.color,stopOpacity:`0.05`})]},e.key))})}function ye({ticks:e,max:t,plotWidth:n,plotHeight:r,format:i}){return(0,E.jsx)(`g`,{"data-testid":`chart-grid`,children:e.map(e=>{let a=t<=0?r:r-Math.min(r,e/t*r);return(0,E.jsxs)(`g`,{children:[(0,E.jsx)(`line`,{x1:0,x2:n,y1:a,y2:a,stroke:`var(--color-border)`,strokeWidth:1,strokeDasharray:e===0?void 0:`3 3`}),(0,E.jsx)(`text`,{x:-6,y:a,textAnchor:`end`,dominantBaseline:`middle`,fontSize:11,style:W,children:i(e)})]},e)})})}function be({layers:e,idPrefix:t,plotWidth:n,plotHeight:r,isSingle:i}){if(i){let t=n/2;return(0,E.jsxs)(`g`,{"data-testid":`area-single-point`,children:[(0,E.jsx)(`line`,{x1:t,x2:t,y1:0,y2:r,stroke:`var(--color-border)`,strokeWidth:1,strokeDasharray:`2 2`}),e.map(e=>{let t=e.points[0],n=e.series.values[0]??0;return!t||n<=0?null:(0,E.jsx)(`circle`,{cx:t.x,cy:t.y,r:4,fill:e.series.color,stroke:`var(--color-card)`,strokeWidth:2,"data-testid":`point-${e.series.key}`},e.series.key)})]})}return(0,E.jsxs)(`g`,{"data-testid":`area-layers`,children:[e.map((e,n)=>(0,E.jsx)(`path`,{d:e.areaPath,fill:`url(#${t}-grad-${n})`,"data-testid":`area-series-${e.series.key}`},e.series.key)),e.map(e=>e.strokePaths.map((t,n)=>(0,E.jsx)(`path`,{d:t,fill:`none`,stroke:e.series.color,strokeWidth:1.75,strokeLinecap:`round`,strokeLinejoin:`round`},`${e.series.key}-${n}`)))]})}function xe({categories:e,xs:t,plotWidth:n,plotHeight:r,labels:i,onEnter:a}){let o=e.length;return(0,E.jsx)(`g`,{"data-testid":`chart-slots`,children:e.map((e,s)=>{let c=0,l=n;if(o>1){let e=s===0?t[0]:(t[s-1]+t[s])/2,n=s===o-1?t[o-1]:(t[s]+t[s+1])/2;c=e,l=Math.max(1,n-e)}return(0,E.jsxs)(`g`,{"data-testid":`slot-${e.key}`,children:[(0,E.jsx)(`rect`,{x:c,y:0,width:l,height:r,fill:`transparent`,onMouseEnter:()=>a(s),children:(0,E.jsx)(`title`,{children:e.title})}),i.has(s)?(0,E.jsx)(`text`,{x:t[s]??0,y:r+16,textAnchor:`middle`,fontSize:11,style:W,children:e.label}):null]},e.key)})})}function Se({active:e,activeX:t,plotHeight:n,layers:r}){return e===null||t===void 0?null:(0,E.jsxs)(`g`,{"data-testid":`crosshair`,children:[(0,E.jsx)(`line`,{x1:t,x2:t,y1:0,y2:n,stroke:`var(--color-muted-foreground)`,strokeWidth:1,strokeDasharray:`2 2`}),r.map(t=>{let n=t.points[e],r=t.series.values[e]??0;return!n||r<=0?null:(0,E.jsx)(`circle`,{cx:n.x,cy:n.y,r:4,fill:t.series.color,stroke:`var(--color-card)`,strokeWidth:2,"data-testid":`marker-${t.series.key}`},t.series.key)})]})}function Ce({category:e,series:t,index:n,total:r,left:i,format:a}){return(0,E.jsx)(_e,{title:e.title,total:r,left:i,rows:t.filter(e=>(e.values[n]??0)>0).map(e=>({key:e.key,label:e.label,color:e.color,value:a(e.values[n]??0)}))})}function we({series:e}){return(0,E.jsx)(`ul`,{className:`flex flex-wrap gap-x-4 gap-y-1 text-xs`,children:e.map(e=>(0,E.jsxs)(`li`,{className:`flex items-center gap-1.5`,children:[(0,E.jsx)(`span`,{"aria-hidden":`true`,className:`size-2 rounded-full`,style:{backgroundColor:e.color}}),e.label]},e.key))})}function G({caption:e,head:t,rows:n}){return(0,E.jsxs)(`table`,{className:`sr-only`,children:[(0,E.jsx)(`caption`,{children:e}),(0,E.jsx)(`thead`,{children:(0,E.jsx)(`tr`,{children:t.map(e=>(0,E.jsx)(`th`,{scope:`col`,children:e},e))})}),(0,E.jsx)(`tbody`,{children:n.map(e=>(0,E.jsx)(`tr`,{children:e.map((e,t)=>t===0?(0,E.jsx)(`th`,{scope:`row`,children:e},e):(0,E.jsx)(`td`,{children:e},`${t}:${e}`))},e.join(`\0`)))})]})}function Te(e,t=4){return!Number.isFinite(e)||e<=0?{ticks:[0,1],max:1}:ie(e*1.08,t)}function Ee(e){let t=e.length;if(t<=1)return t===1?[0]:[];if(t===2){let t=e[1].x-e[0].x,n=t===0?0:(e[1].y-e[0].y)/t;return[n,n]}let n=[];for(let r=0;r<t-1;r+=1){let t=e[r+1].x-e[r].x;n.push(t===0?0:(e[r+1].y-e[r].y)/t)}let r=[n[0]];for(let e=1;e<t-1;e+=1){let t=n[e-1],i=n[e];r.push(t>0&&i>0||t<0&&i<0?(t+i)/2:0)}r.push(n[t-2]);for(let e=0;e<t-1;e+=1){let t=n[e];if(Math.abs(t)<1e-9){r[e]=0,r[e+1]=0;continue}let i=r[e]/t,a=r[e+1]/t;i<0&&(r[e]=0),a<0&&(r[e+1]=0);let o=i*i+a*a;if(o>9){let n=3/Math.sqrt(o);r[e]=n*i*t,r[e+1]=n*a*t}}return r}function De(e,t){let n=[];for(let r=0;r<e.length-1;r+=1){let i=e[r],a=e[r+1],o=(a.x-i.x)/3;n.push({cp1:{x:i.x+o,y:i.y+(t[r]??0)*o},cp2:{x:a.x-o,y:a.y-(t[r+1]??0)*o}})}return n}var K=e=>Number(e.toFixed(2)).toString();function Oe(e,t,n,r){let i=e.length;if(i<=1)return``;let a=e[0],o=[`M ${K(a.x)} ${K(a.y)}`];for(let n=0;n<i-1;n+=1){let r=t[n],i=e[n+1];o.push(`C ${K(r.cp1.x)} ${K(r.cp1.y)}, ${K(r.cp2.x)} ${K(r.cp2.y)}, ${K(i.x)} ${K(i.y)}`)}let s=n[i-1];o.push(`L ${K(s.x)} ${K(s.y)}`);for(let e=i-2;e>=0;--e){let t=r[e],i=n[e];o.push(`C ${K(t.cp2.x)} ${K(t.cp2.y)}, ${K(t.cp1.x)} ${K(t.cp1.y)}, ${K(i.x)} ${K(i.y)}`)}return o.push(`Z`),o.join(` `)}function ke(e,t,n){let r=e.length;if(r<=1)return[];let i=[],a=[];for(let o=0;o<r-1;o+=1)if((n[o]??0)>0||(n[o+1]??0)>0){a.length===0&&a.push(`M ${K(e[o].x)} ${K(e[o].y)}`);let n=t[o],r=e[o+1];a.push(`C ${K(n.cp1.x)} ${K(n.cp1.y)}, ${K(n.cp2.x)} ${K(n.cp2.y)}, ${K(r.x)} ${K(r.y)}`)}else a.length>0&&(i.push(a.join(` `)),a=[]);return a.length>0&&i.push(a.join(` `)),i}function Ae(e,t,n){let r=new Set,i=-1/0;for(let a=0;a<e.length;a+=1){let o=e[a]?.label;if(!o||o.trim().length===0)continue;let s=t[a]??0;(s-i>=n||i===-1/0)&&(r.add(a),i=s)}return r}function q(e,t){return e<=0?[]:e===1?[t/2]:Array.from({length:e},(n,r)=>r*t/(e-1))}function je({series:e,count:t,plotWidth:n,plotHeight:r,max:i}){if(t<=0)return[];let a=q(t,n),o=[Array(t).fill(0)];e.forEach((e,t)=>{let n=o[t];o.push(n.map((t,n)=>t+(e.values[n]??0)))});let s=o.map(e=>{let t=e.map((e,t)=>({x:a[t]??0,y:r-ae(e,i,r)})),n=Ee(t);return{points:t,tangents:n,controls:De(t,n)}});return e.map((e,t)=>{let n=s[t],r=s[t+1];return{series:e,areaPath:Oe(r.points,r.controls,n.points,n.controls),strokePaths:ke(r.points,r.controls,e.values),points:r.points}})}var J=260,Y={top:12,right:12,bottom:26,left:52},Me=44,Ne=640;function Pe(){let e=(0,T.useRef)(null),[t,n]=(0,T.useState)(Ne);return(0,T.useEffect)(()=>{let t=e.current;if(t===null)return;let r=()=>{t.clientWidth>0&&n(t.clientWidth)};r();let i=new ResizeObserver(r);return i.observe(t),()=>i.disconnect()},[]),[e,t]}function Fe(e,t,n){return e===`ArrowRight`?Math.min(n,t+1):e===`ArrowLeft`?Math.max(0,t-1):e===`Home`?0:e===`End`?n:null}function Ie({width:e,series:t,idPrefix:n,ticks:r,max:i,plotWidth:a,plotHeight:o,format:s,layers:c,isSingle:l,categories:u,xs:d,labels:f,active:p,activeX:m,onEnter:h}){return(0,E.jsxs)(`svg`,{viewBox:`0 0 ${e} ${J}`,className:`block w-full overflow-visible`,style:{height:`${J}px`},children:[(0,E.jsx)(ve,{series:t,idPrefix:n}),(0,E.jsxs)(`g`,{transform:`translate(${Y.left}, ${Y.top})`,children:[(0,E.jsx)(ye,{ticks:r,max:i,plotWidth:a,plotHeight:o,format:s}),(0,E.jsx)(be,{layers:c,idPrefix:n,plotWidth:a,plotHeight:o,isSingle:l}),(0,E.jsx)(xe,{categories:u,xs:d,plotWidth:a,plotHeight:o,labels:f,onEnter:h}),(0,E.jsx)(Se,{active:p,activeX:m,plotHeight:o,layers:c})]})]})}function Le(e){return(0,E.jsx)(G,{caption:e.caption,head:[e.categoryHead,...e.series.map(e=>e.label),e.totalLabel],rows:e.categories.map((t,n)=>[t.title,...e.series.map(t=>e.format(t.values[n]??0)),e.format(e.totals[n]??0)])})}function Re(e,t,n){let r=e.length,i=Math.max(n,Y.left+Y.right+10),a=i-Y.left-Y.right,o=J-Y.top-Y.bottom,s=ce(t,r),{ticks:c,max:l}=Te(Math.max(0,...s)),u=q(r,a);return{width:i,plotWidth:a,plotHeight:o,totals:s,ticks:c,max:l,xs:u,layers:je({series:t,count:r,plotWidth:a,plotHeight:o,max:l}),labels:Ae(e,u,Me*1.2)}}function ze(e){return e.active===null||e.category===void 0||e.activeX===void 0?null:(0,E.jsx)(Ce,{category:e.category,series:e.series,index:e.active,total:e.format(e.totals[e.active]??0),left:Math.min(Math.max(Y.left+e.activeX,80),e.width-80),format:e.format})}function Be(e){let{label:t,categories:n,series:r,format:i,categoryHead:a,totalLabel:o}=e,[s,c]=Pe(),l=(0,T.useId)().replace(/[^a-zA-Z0-9-_]/g,``),[u,d]=(0,T.useState)(null),f=n.length,p=Re(n,r,c),m=e=>{if(f<=0)return;let t=Fe(e.key,u??0,f-1);t!==null&&(e.preventDefault(),d(t))},h=u===null?void 0:p.xs[u],g=u===null?void 0:n[u];return(0,E.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,E.jsxs)(`div`,{ref:s,role:`group`,"aria-label":t,tabIndex:0,className:`relative rounded-md outline-none focus-visible:ring-2 focus-visible:ring-ring`,onFocus:()=>d(e=>e??0),onBlur:()=>d(null),onKeyDown:m,onMouseLeave:()=>d(null),children:[(0,E.jsx)(Ie,{width:p.width,series:r,idPrefix:l,ticks:p.ticks,max:p.max,plotWidth:p.plotWidth,plotHeight:p.plotHeight,format:i,layers:p.layers,isSingle:f===1,categories:n,xs:p.xs,labels:p.labels,active:u,activeX:h,onEnter:d}),(0,E.jsx)(ze,{active:u,category:g,activeX:h,series:r,totals:p.totals,width:p.width,format:i})]}),(0,E.jsx)(we,{series:r}),(0,E.jsx)(Le,{caption:t,categoryHead:a,totalLabel:o,categories:n,series:r,totals:p.totals,format:i})]})}function X({label:e,rows:t,valueHead:n,nameHead:r}){let i=t.reduce((e,t)=>e+t.value,0),a=e=>i>0?Math.round(e/i*100):0;return(0,E.jsxs)(`div`,{role:`group`,"aria-label":e,className:`flex flex-col gap-2`,children:[(0,E.jsx)(`ul`,{className:`flex flex-col gap-2`,children:t.map(e=>(0,E.jsxs)(`li`,{tabIndex:0,"aria-label":`${e.label}: ${e.text} · ${a(e.value)}%`,className:`flex flex-col gap-1 rounded-sm text-sm outline-none focus-visible:ring-2 focus-visible:ring-ring`,children:[(0,E.jsxs)(`span`,{className:`flex justify-between gap-2`,children:[(0,E.jsx)(`span`,{className:`truncate`,children:e.label}),(0,E.jsxs)(`span`,{className:`shrink-0 tabular-nums text-muted-foreground`,children:[e.text,` · `,a(e.value),`%`]})]}),(0,E.jsx)(`span`,{className:`h-2 rounded-full bg-muted`,"aria-hidden":`true`,children:(0,E.jsx)(`span`,{className:`block h-2 rounded-full`,style:{width:`${a(e.value)}%`,backgroundColor:e.color}})})]},e.key))}),(0,E.jsx)(G,{caption:e,head:[r,n,`%`],rows:t.map(e=>[e.label,e.text,`${a(e.value)}%`])})]})}function Ve({label:e,segments:t,valueHead:n,nameHead:r}){let i=t.reduce((e,t)=>e+t.value,0);return(0,E.jsxs)(`div`,{role:`group`,"aria-label":e,className:`flex flex-col gap-2`,children:[(0,E.jsx)(`div`,{className:`flex h-3 overflow-hidden rounded-full bg-muted`,"aria-hidden":`true`,children:t.filter(e=>e.value>0).map(e=>(0,E.jsx)(`span`,{"data-testid":`stack-${e.key}`,style:{width:`${e.value/i*100}%`,backgroundColor:e.color}},e.key))}),(0,E.jsx)(`ul`,{className:`flex flex-wrap gap-x-4 gap-y-1 text-sm`,children:t.map(e=>(0,E.jsxs)(`li`,{className:`flex items-center gap-1.5`,children:[(0,E.jsx)(`span`,{"aria-hidden":`true`,className:`size-2 rounded-full`,style:{backgroundColor:e.color}}),(0,E.jsx)(`span`,{children:e.label}),(0,E.jsx)(`span`,{className:`tabular-nums text-muted-foreground`,children:e.value})]},e.key))}),(0,E.jsx)(G,{caption:e,head:[r,n],rows:t.map(e=>[e.label,String(e.value)])})]})}var He=Array.from({length:8},(e,t)=>`var(--color-chart-${t+1})`),Ue=`var(--color-status-mute)`,We={finished:`var(--color-status-ok)`,failed:`var(--color-status-err)`,cancelled:`var(--color-status-mute)`};function Ge(e){return e===null?null:/#[0-9a-f]{6}/i.exec(ee[e]??``)?.[0]??null}function Z(e,t){let n={},r=0;for(let i of e){let e=Ge(t(i));e===null?(n[i]=He[r%8]??`var(--color-status-mute)`,r+=1):n[i]=e}return n}function Ke(e){let{t}=v();return(0,E.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,E.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,E.jsx)(`h2`,{className:`text-sm font-semibold`,children:t(`stats.daily.title`)}),(0,E.jsx)(p,{variant:`outline`,className:`font-normal text-muted-foreground`,children:t(`stats.daily.buckets.${e.bucket}`)})]}),(0,E.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,E.jsx)(m,{type:`single`,value:e.split,"aria-label":t(`stats.daily.split`),onValueChange:t=>{let n=k.find(e=>e===t);n!==void 0&&e.onSplit(n)},children:k.map(e=>(0,E.jsx)(h,{value:e,children:t(`stats.daily.splits.${e}`)},e))}),(0,E.jsx)(m,{type:`single`,value:e.metric,"aria-label":t(`stats.daily.metric`),onValueChange:t=>{let n=O.find(e=>e===t);n!==void 0&&e.onMetric(n)},children:e.metrics.map(e=>(0,E.jsx)(h,{value:e,children:t(`stats.daily.metrics.${e}`)},e))})]})]})}function qe({report:e}){let{t,i18n:n}=v(),[r,i]=(0,T.useState)(`tokens`),[a,o]=(0,T.useState)(`projects`),s=le(a),u=s.includes(r)?r:`tokens`,d=e.bucket??`day`,f=a===`models`?ue(e):[...new Set(e.series.flatMap(e=>e.projects.map(e=>e.repository)))],p=N(e,u,a,{labelOf:l,modelLabelOf:e=>z(e,t),colors:Z(f,a===`models`?()=>null:c),other:{label:t(`stats.daily.other`),color:Ue}}),m=he(e.series,d,n.language),h=e=>u===`tokens`?A(e):u===`agent`?j(e,t):String(Math.round(e)),g=t(`stats.daily.metrics.${u}`);return(0,E.jsxs)(_,{className:`flex flex-col gap-3 p-4`,children:[(0,E.jsx)(Ke,{bucket:d,metrics:s,metric:u,split:a,onMetric:i,onSplit:o}),(0,E.jsx)(Be,{label:t(a===`models`?`stats.daily.chartLabelModels`:`stats.daily.chartLabel`,{metric:g}),categories:m,series:p,format:h,categoryHead:t(`stats.daily.categoryHeads.${d}`),totalLabel:t(`stats.daily.total`)})]})}function Q({label:e,value:t,title:n,children:r}){return(0,E.jsxs)(_,{className:`flex flex-col gap-1 p-3`,"data-testid":`kpi-tile`,children:[(0,E.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e}),(0,E.jsx)(`span`,{className:`text-2xl font-semibold tabular-nums`,title:n,children:t}),r?(0,E.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:r}):null]})}function Je({report:e}){let{t,i18n:n}=v(),{totals:r,perTask:i,outcomes:a}=e,o=e=>e.toLocaleString(n.language);return(0,E.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,E.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 xl:grid-cols-4`,children:[(0,E.jsx)(Q,{label:t(`stats.tiles.tokens`),value:A(r.tokens),title:o(r.tokens),children:t(`stats.tiles.tokensSplit`,{input:A(r.inputTokens),output:A(r.outputTokens)})}),(0,E.jsx)(Q,{label:t(`stats.tiles.agent`),value:j(r.agentMs,t)}),(0,E.jsx)(Q,{label:t(`stats.tiles.tasks`),value:String(r.tasks),children:t(`stats.tiles.outcomes`,a)})]}),(0,E.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,E.jsx)(Q,{label:t(`stats.tiles.perTaskTokens`),value:A(i.tokens.mean),title:o(Math.round(i.tokens.mean)),children:t(`stats.tiles.median`,{value:A(i.tokens.median)})}),(0,E.jsx)(Q,{label:t(`stats.tiles.perTaskAgent`),value:j(i.agentMs.mean,t),children:t(`stats.tiles.median`,{value:j(i.agentMs.median,t)})})]})]})}var $=[`finished`,`failed`,`cancelled`];function Ye({report:e}){let{t}=v(),n=e.repository===null,r=Z(e.projects.map(e=>e.repository),c),i=n=>pe(e,n).map(e=>({key:e.repository,label:l(e.repository),color:r[e.repository]??``,value:e.value,text:n===`tokens`?A(e.value):j(e.value,t)}));return(0,E.jsxs)(`div`,{className:`grid gap-3 ${n?`xl:grid-cols-3`:``}`,children:[n?(0,E.jsxs)(E.Fragment,{children:[(0,E.jsxs)(_,{className:`p-4`,children:[(0,E.jsx)(`h2`,{className:`mb-3 text-sm font-semibold`,children:t(`stats.shares.tokens`)}),(0,E.jsx)(X,{label:t(`stats.shares.tokens`),rows:i(`tokens`),nameHead:t(`stats.projects.project`),valueHead:t(`stats.tiles.tokens`)})]}),(0,E.jsxs)(_,{className:`p-4`,children:[(0,E.jsx)(`h2`,{className:`mb-3 text-sm font-semibold`,children:t(`stats.shares.agent`)}),(0,E.jsx)(X,{label:t(`stats.shares.agent`),rows:i(`agent`),nameHead:t(`stats.projects.project`),valueHead:t(`stats.tiles.agent`)})]})]}):null,(0,E.jsxs)(_,{className:`p-4`,children:[(0,E.jsx)(`h2`,{className:`mb-3 text-sm font-semibold`,children:t(`stats.shares.outcomes`)}),(0,E.jsx)(Ve,{label:t(`stats.shares.outcomes`),nameHead:t(`stats.shares.outcome`),valueHead:t(`stats.tiles.tasks`),segments:$.map(n=>({key:n,label:t(`stats.shares.outcomeNames.${n}`),color:We[n],value:e.outcomes[n]}))})]})]})}function Xe({api:e,repository:t,onCleared:n}){let{t:r}=v(),i=y(),a=l(t),o=async()=>{if(await i({title:r(`stats.clear.title`,{name:a}),description:r(`stats.clear.description`),confirmLabel:r(`stats.clear.confirm`),destructive:!0}))try{let{removed:i}=await e.statsClear(t);te(r(`stats.clear.done`,{count:i,name:a})),n()}catch(e){b(e)}};return(0,E.jsx)(f,{type:`button`,variant:`ghost`,size:`sm`,"aria-label":r(`stats.clear.action`,{name:a}),title:r(`stats.clear.action`,{name:a}),onClick:()=>void o(),children:(0,E.jsx)(w,{})})}function Ze(e){let{t,onSelect:n,actions:r}=e,i=(e,t,n)=>({key:e,label:t,numeric:!0,cell:e=>n(e)??`—`}),a=e=>j(e,t);return[{key:`name`,label:t(`stats.projects.project`),cell:e=>e.repository===null?t(`stats.projects.all`):(0,E.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,E.jsx)(ne,{path:e.repository}),(0,E.jsx)(`button`,{type:`button`,className:`rounded-sm text-left hover:underline`,title:e.repository,onClick:()=>n(e.repository),children:l(e.repository)})]})},i(`tasks`,t(`stats.projects.tasks`),e=>String(e.totals.tasks)),i(`tokens`,t(`stats.tiles.tokens`),e=>A(e.totals.tokens)),i(`agent`,t(`stats.tiles.agent`),e=>a(e.totals.agentMs)),i(`wall`,t(`stats.projects.wall`),e=>a(e.totals.wallMs)),i(`meanTokens`,t(`stats.projects.meanTokens`),e=>A(e.perTask.tokens.mean)),i(`medianTokens`,t(`stats.projects.medianTokens`),e=>A(e.perTask.tokens.median)),i(`meanAgent`,t(`stats.projects.meanAgent`),e=>a(e.perTask.agentMs.mean)),i(`medianAgent`,t(`stats.projects.medianAgent`),e=>a(e.perTask.agentMs.median)),{key:`actions`,label:``,cell:e=>e.repository===null?null:r(e.repository)}]}function Qe({api:e,report:t,onSelect:n,onCleared:r}){let{t:i}=v(),[a,o]=(0,T.useState)(null),s=F(t.projects,a,(e,t)=>t===`name`?l(e.repository):I(e,t)),c={repository:null,totals:t.totals,perTask:t.perTask},u=Ze({t:i,onSelect:n,actions:t=>(0,E.jsx)(Xe,{api:e,repository:t,onCleared:r})});return(0,E.jsxs)(_,{className:`p-4`,children:[(0,E.jsx)(`h2`,{className:`mb-3 text-sm font-semibold`,children:i(`stats.projects.title`)}),(0,E.jsx)(D,{caption:i(`stats.projects.title`),columns:u,rows:s,pinned:c,sort:a,onSort:e=>o(t=>P(t,e)),rowKey:e=>e.repository??`\0all`})]})}var $e=[`7d`,`30d`,`90d`,`all`];function et({period:e,project:t,registry:n,onChange:r}){let{t:i}=v(),a=n.some(e=>e.path===t);return(0,E.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,E.jsx)(m,{type:`single`,value:e,"aria-label":i(`stats.filters.period`),onValueChange:e=>{let n=u.find(t=>t===e);n!==void 0&&r(n,t)},children:$e.map(e=>(0,E.jsx)(h,{value:e,children:i(`stats.filters.periods.${e}`)},e))}),(0,E.jsxs)(`label`,{className:`flex items-center gap-2 text-sm`,children:[(0,E.jsx)(`span`,{className:`text-muted-foreground`,children:i(`stats.filters.project`)}),(0,E.jsxs)(`select`,{className:`h-8 max-w-64 rounded-md border border-input bg-card px-2 text-sm`,value:t??``,onChange:t=>r(e,t.target.value===``?null:t.target.value),children:[(0,E.jsx)(`option`,{value:``,children:i(`stats.filters.allProjects`)}),t!==null&&!a?(0,E.jsx)(`option`,{value:t,children:g(t)}):null,n.map(e=>(0,E.jsx)(`option`,{value:e.path,children:e.label},e.path))]})]})]})}var tt=5e3;function nt(e){return e.map(e=>`${e.id}:${e.state}:${e.counts}:${JSON.stringify(e.usage)}`).join(`|`)}function rt(e,t,n,r){let[i,a]=(0,T.useState)(null),[o,s]=(0,T.useState)(null),[c,l]=(0,T.useState)(!0),u=(0,T.useRef)(0),d=(0,T.useRef)(0),f=(0,T.useCallback)(r=>{u.current+=1;let i=u.current;d.current=Date.now(),r&&l(!0),e.statsReport({bucket:`auto`,since:fe(t,Date.now()),...n===null?{}:{repository:n}}).then(e=>{i===u.current&&(a(e),s(null),l(!1))}).catch(e=>{i===u.current&&(s(e instanceof Error?e.message:String(e)),l(!1))})},[e,t,n]);(0,T.useEffect)(()=>(a(null),f(!0),()=>{u.current+=1}),[f]);let p=nt(r),m=(0,T.useRef)(p);return(0,T.useEffect)(()=>{if(m.current===p)return;m.current=p;let e=Math.max(0,d.current+tt-Date.now()),t=setTimeout(()=>f(!1),e);return()=>clearTimeout(t)},[p,f]),{report:i,error:o,loading:c,reload:()=>f(!0)}}function it({api:e,report:t,onProject:n,onCleared:r}){let{t:a}=v();return me(t)?(0,E.jsx)(x,{icon:(0,E.jsx)(i,{}),title:a(`stats.empty.title`),children:(0,E.jsx)(`p`,{children:a(`stats.empty.hint`)})}):(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(Je,{report:t}),(0,E.jsx)(qe,{report:t}),(0,E.jsx)(Ye,{report:t}),(0,E.jsx)(Qe,{api:e,report:t,onSelect:n,onCleared:r}),(0,E.jsx)(ge,{report:t})]})}function at({api:e,registry:t,runs:n,period:r,project:i,onFilter:a}){let{t:o}=v(),{report:c,error:l,loading:u,reload:p}=rt(e,r,i,n);return(0,E.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-4 p-4`,"data-testid":`stats-page`,children:[(0,E.jsx)(et,{period:r,project:i,registry:t,onChange:a}),c!==null&&!c.settings.enabled?(0,E.jsxs)(s,{variant:`warn`,className:`flex flex-wrap items-center gap-2`,children:[(0,E.jsx)(`span`,{children:o(`stats.disabled.title`)}),(0,E.jsx)(`a`,{href:`#settings/global/system`,className:`underline underline-offset-2`,children:o(`stats.disabled.open`)})]}):null,l===null?null:(0,E.jsxs)(s,{variant:`destructive`,className:`flex flex-wrap items-center gap-2`,children:[(0,E.jsx)(`span`,{children:o(`stats.error`,{message:l})}),(0,E.jsx)(f,{type:`button`,variant:`outline`,size:`sm`,onClick:p,children:o(`stats.retry`)})]}),c===null&&u?(0,E.jsxs)(`div`,{role:`status`,"aria-label":o(`stats.loading`),className:`flex flex-col gap-3`,children:[(0,E.jsx)(d,{className:`h-24`}),(0,E.jsx)(d,{className:`h-64`})]}):null,c===null?null:(0,E.jsx)(it,{api:e,report:c,onProject:e=>a(r,e),onCleared:p})]})}export{at as StatsPage};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{_ as t,a as n,c as r,d as i,f as a,g as o,h as s,i as c,l,m as u,o as d,p as f,r as p,s as m,u as h}from"./pipelines-Bs3be_lB.js";import{i as g,t as _}from"./vendor-react-C1iE8mnY.js";import{F as v,_ as y,a as b,f as x,i as S,j as C,n as w,r as ee,t as te,ut as T}from"./card-4euJkmfJ.js";import{E,P as D,T as O,j as k}from"./index-BAeOzr94.js";import{d as A,l as ne,u as re}from"./specialists-BPyAYlk1.js";var j=e(g(),1),M=_();function N(){return(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(a,{type:`target`,position:t.Left,id:`in`}),(0,M.jsx)(a,{type:`source`,position:t.Right,id:`out`}),(0,M.jsx)(a,{type:`target`,position:t.Bottom,id:`back-in`}),(0,M.jsx)(a,{type:`source`,position:t.Bottom,id:`back-out`}),(0,M.jsx)(a,{type:`source`,position:t.Bottom,id:`down`}),(0,M.jsx)(a,{type:`target`,position:t.Top,id:`up`})]})}function P({data:e,testId:t}){return(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(`div`,{className:`truncate text-muted-foreground`,title:e.subtitleHint??e.subtitle,children:e.subtitle}),e.performer&&e.performer!==e.subtitle?(0,M.jsx)(`div`,{className:`truncate text-muted-foreground`,"data-testid":`performer-${t}`,title:e.performer,children:e.performer}):null,e.condition===null?null:(0,M.jsx)(`div`,{className:`truncate font-medium`,"data-testid":`condition-${t}`,children:e.condition}),e.detail?(0,M.jsx)(`div`,{className:`truncate text-muted-foreground`,children:e.detail}):null,e.groups.length>0?(0,M.jsx)(`div`,{className:`flex min-w-0 flex-wrap gap-1`,children:e.groups.map(e=>(0,M.jsx)(O,{status:e.status,label:e.title,title:e.title},`${e.runId}/${e.slug}`))}):null]})}function F({data:e,testId:t}){let{t:n}=T(),r=D({inputTokens:e.inputTokens??0,outputTokens:e.outputTokens??0})||`—`;return(0,M.jsxs)(M.Fragment,{children:[e.busy&&(e.busy.running>0||e.busy.max!==null)?(0,M.jsxs)(`div`,{className:v(`truncate text-muted-foreground`,e.busy.full&&`font-medium`),"data-testid":`busy-${t}`,children:[e.busy.max===null?n(`topology.busyUnlimited`,{n:e.busy.running}):n(`topology.busy`,{n:e.busy.running,max:e.busy.max}),e.busy.elsewhere>0?` · ${n(`topology.busyElsewhere`,{n:e.busy.elsewhere})}`:``]}):null,e.attempts===null?null:(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(`div`,{className:`truncate text-muted-foreground`,children:n(`topology.attempts`,{n:e.attempts})}),(0,M.jsx)(`div`,{className:`truncate text-muted-foreground tabular-nums`,"data-testid":`usage-${e.step}`,title:r,children:r})]})]})}function I({data:e,selected:t}){let{t:n}=T(),r=e.step??(e.kind===`action`?e.stageId:e.kind);return(0,M.jsxs)(te,{className:v(`relative grid w-[170px] grid-cols-[minmax(0,1fr)] gap-1 px-3 py-2.5 text-xs`,e.kind!==`step`&&`bg-muted`,e.condition!==null&&`border-dashed`,e.skipped&&`opacity-60`,e.active&&`border-status-run ring-4 ring-status-run-bg`,e.busy?.full&&`border-status-warn bg-status-warn-bg`,t&&`border-primary`),"data-testid":`stage-${r}`,"data-conditional":e.condition===null?void 0:`true`,"data-skipped":e.skipped?`true`:void 0,children:[e.sectionStart?(0,M.jsx)(`div`,{className:`pointer-events-none absolute -top-5 left-0 text-[10px] font-medium tracking-wide whitespace-nowrap text-muted-foreground uppercase`,"data-testid":`section-${e.section}`,children:n(`topology.stages.section.${e.section}`)}):null,(0,M.jsx)(N,{}),(0,M.jsx)(`div`,{className:v(`truncate text-sm font-bold`,e.skipped&&`line-through`),title:e.title,children:e.title}),e.skipped?(0,M.jsx)(`div`,{className:`text-muted-foreground`,children:n(`variants.schemaSkipped`)}):null,(0,M.jsx)(P,{data:e,testId:r}),(0,M.jsx)(F,{data:e,testId:r})]})}function L(e,t,n){let r=new Set(t.runIds),i=e.get(n);return{running:(i?.running??[]).filter(e=>!r.has(e.runId)),waiting:(i?.waiting??[]).filter(e=>!r.has(e.runId))}}function R(e,t,n,r){let i=n.get(r),a=[i?.max??null,e.limits?.[r]??null].filter(e=>e!==null&&e>0),o=a.length>0?Math.min(...a):null,s=i?.running.length??0;return{running:s,elsewhere:L(n,t,r).running.length,max:o,full:o!==null&&s>=o}}function z(e){return e.some(e=>e.status===`running`||e.status===`merging`)}var B={attempts:null,inputTokens:null,outputTokens:null,step:null,specialist:null,busy:null};function V(e,t,r){return{stageId:e.id,section:e.section,sectionStart:e.section!==t,performer:n(e.performer,r),condition:c(e.condition,r),link:m(e)}}function H({pipeline:e,live:t,load:n,t:r},i){let a=e.split;if(!a)return null;let o=e.stages.find(e=>e.id===`split`),s=o?.performer.type===`specialist`&&o.performer.name?o.performer.name:a.specialist,c=a.pipeline?[r(`topology.splitPipeline`,{id:a.pipelineName??a.pipeline})]:[];return{id:`split`,data:{kind:`split`,title:r(`topology.split`),subtitle:s,...s===a.specialist?{}:{subtitleHint:a.specialist},detail:[r(`topology.splitDetail`,{n:a.maxGroups}),...c].join(` · `),groups:t.splitting,active:t.splitting.some(e=>e.status===`running`),...B,...i,specialist:a.specialist,busy:R(e,t,n,a.specialist)}}}function U(e,t,n){let{pipeline:r,live:i,load:a}=e,o=r.steps.find(e=>`step:${e.id}`===t.id);if(!o)return null;let s=i.steps.get(o.id)??[];return{id:`step:${o.id}`,data:{kind:`step`,title:o.name,subtitle:o.specialist,detail:`${o.runtime}${o.model?` ${o.model}`:``} · ${o.permissions}`,groups:s,attempts:i.attempts.get(o.id)??0,inputTokens:i.inputTokens.get(o.id)??0,outputTokens:i.outputTokens.get(o.id)??0,active:z(s),step:o.id,...o.skipped?{skipped:!0}:{},specialist:o.specialist,busy:R(r,i,a,o.specialist),...n}}}function W(e,t,i){let{pipeline:a,live:o,load:s,t:c}=e,l=t.performer.type===`specialist`?t.performer.slug:null,u=t.kind===`action`||t.kind===`message`?t.kind:`cleanup`,d=t.kind===`message`?c(`topology.stages.name.message`):t.kind===`cleanup`?c(`topology.stages.name.cleanup`):t.name;return{id:r(t),data:{kind:u,title:d,subtitle:n(t.performer,c),detail:null,groups:[],active:!1,...B,...i,specialist:l,busy:l?R(a,o,s,l):null}}}function G(e,t,n){let{t:r,live:i,pipeline:a}=e;switch(t.kind){case`split`:return H(e,n);case`step`:return U(e,t,n);case`merge`:return{id:`merge`,data:{kind:`merge`,title:r(`topology.merge`),subtitle:r(`topology.mergeSubtitle`),detail:null,groups:i.merging,active:z(i.merging),...B,...n}};case`delivery`:return{id:`delivery`,data:{kind:`delivery`,title:r(`topology.deliveryNode`),subtitle:a.delivery.mode,detail:null,groups:i.merged,active:!1,...B,...n}};default:return W(e,t,n)}}function K(e,t,n,r){let{pipeline:i,live:a,load:o,t:s,sizes:c}=e,l=t.performer.type===`specialist`?t.performer.slug:null,u=i.delivery.resolver??l;if(!u||!r)return null;let d=e=>c.get(e)?.height??90;return{id:`resolver`,position:{x:r.position.x,y:d(`delivery`)/2+60+d(`resolver`)/2},data:{kind:`resolver`,title:s(`topology.resolver`),subtitle:u,detail:null,groups:[],active:!1,...B,...n,sectionStart:!1,specialist:u,busy:R(i,a,o,u)}}}function q(e,t,n,r=null){let i={steps:new Map,attempts:new Map,inputTokens:new Map,outputTokens:new Map,merging:[],merged:[],splitting:[],elsewhere:[],runs:0,runIds:[]},a=new Set(e.steps.map(e=>e.id));for(let o of t){if(o.finished||o.pipeline!==e.id||n!==null&&o.repository!==n||r!==null&&(o.variant??`default`)!==r)continue;i.runs+=1,i.runIds.push(o.id);let t=e=>({runId:o.id,runTitle:o.title,...e});o.split&&o.split.status!==`done`&&i.splitting.push({runId:o.id,runTitle:o.title,slug:`_split`,title:o.title,status:o.split.status});for(let e of o.topology?.steps??[]){let n=a.has(e.id)?i.steps.get(e.id)??[]:i.elsewhere;n.push(...e.groups.map(t)),a.has(e.id)&&(i.steps.set(e.id,n),i.attempts.set(e.id,(i.attempts.get(e.id)??0)+e.attempts),i.inputTokens.set(e.id,(i.inputTokens.get(e.id)??0)+(e.usage?.inputTokens??0)),i.outputTokens.set(e.id,(i.outputTokens.get(e.id)??0)+(e.usage?.outputTokens??0)))}i.merging.push(...(o.topology?.merging??[]).map(t)),i.merged.push(...(o.topology?.merged??[]).map(t))}return i}function J(e,t){return JSON.stringify(e)===JSON.stringify(t)}function Y(e,t,n,r){let i=new Map(e.map(e=>[e.id,e]));return t.map(e=>{let t=e.id===r,a=i.get(e.id);if(a&&a.position.x===e.position.x&&a.position.y===e.position.y&&!!a.selected===t&&J(a.data,e.data))return a;let o=n.get(e.id)??a?.measured;return{...e,selected:t,...o?{measured:{...o}}:{}}})}function X(e,t){let n=new Map(e.map(e=>[e.id,e]));return t.map(e=>{let t=n.get(e.id);return t&&J(t,e)?t:e})}var ie=210;function ae(e,t){return{id:`${e.id}->${t.id}`,source:e.id,target:t.id,sourceHandle:`out`,targetHandle:`in`,animated:t.data.active,type:`orthogonal`,className:`edge-forward`}}var oe=e=>({id:`delivery->resolver`,source:`delivery`,target:`resolver`,sourceHandle:`down`,targetHandle:`up`,type:`orthogonal`,label:e(`topology.conflict`),className:`edge-resolver`});function se(e){return e.steps.flatMap(e=>e.onReject?[{id:`reject:${e.id}->${e.onReject.goto}`,source:`step:${e.id}`,target:`step:${e.onReject.goto}`,sourceHandle:`back-out`,targetHandle:`back-in`,type:`orthogonal`,label:`≤ ${e.onReject.maxRounds}`,className:`edge-reject`}]:[])}function ce(e,t,n,r=new Map,i=new Map){let a={pipeline:e,live:t,load:i,t:n,sizes:r},o=[],s=[],c=null,l=null;for(let t of d(e)){let e=V(t,l,n);if(t.kind===`resolve`){let r=K(a,t,e,o.find(e=>e.id===`delivery`));if(!r)continue;o.push({id:r.id,type:`stage`,position:r.position,data:r.data}),s.push(oe(n));continue}let r=G(a,t,e);if(!r)continue;let i={id:r.id,type:`stage`,position:{x:o.filter(e=>e.id!==`resolver`).length*ie,y:0},data:r.data};o.push(i),l=r.data.section,c&&s.push(ae(c,r)),c=i}return{nodes:o,edges:le(o,[...s,...se(e)],r)}}function le(e,t,n){let r=p(e.map(e=>{let t=n.get(e.id),r=t?.height??90;return{id:e.id,x:e.position.x,y:e.position.y-r/2,width:t?.width??170,height:r}}),t.map(e=>{let t=e.id.startsWith(`reject:`)?`return`:e.id===`delivery->resolver`?`down`:`next`;return{id:e.id,source:e.source,target:e.target,kind:t}}));return t.map(e=>({...e,data:{route:r.get(e.id)}}))}var Z={padding:.15,maxZoom:1},ue=[0,.5];function de({pipeline:e}){let{fitView:t}=o(),n=s(),r=(0,j.useRef)(null);return(0,j.useEffect)(()=>{n&&r.current!==e&&(r.current!==null&&t(Z),r.current=e)},[n,e,t]),null}var fe={stage:I},pe={orthogonal:l};function me({pipeline:e,live:t,load:n,selected:r=null,onSelect:a,onNodes:o,className:s}){let{t:c}=T(),{resolved:l}=k(),d=(0,j.useMemo)(()=>t??q(e,[],null),[t,e]),p=(0,j.useRef)(new Map),[m,g]=(0,j.useState)(0),_=(0,j.useCallback)(e=>{let t=!1;for(let n of e){if(n.type!==`dimensions`||!n.dimensions)continue;let e=p.current.get(n.id),{width:r,height:i}=n.dimensions;e&&e.width===r&&e.height===i||(p.current.set(n.id,{width:r,height:i}),t=!0)}t&&g(e=>e+1)},[]),y=(0,j.useRef)([]),b=(0,j.useRef)([]),x=(0,j.useMemo)(()=>{let t=ce(e,d,c,p.current,n??void 0),i=Y(y.current,t.nodes,p.current,r),a=X(b.current,t.edges);return y.current=i,b.current=a,{nodes:i,edges:a}},[e,d,n,r,m,c]);return(0,j.useEffect)(()=>o?.(x.nodes),[x.nodes,o]),(0,M.jsx)(`div`,{className:v(`h-[420px] overflow-hidden rounded-lg border bg-card`,s),children:(0,M.jsx)(f,{children:(0,M.jsxs)(u,{nodes:x.nodes,edges:x.edges,nodeTypes:fe,edgeTypes:pe,nodeOrigin:ue,fitView:!0,colorMode:l,fitViewOptions:Z,minZoom:.3,nodesDraggable:!1,nodesConnectable:!1,proOptions:{hideAttribution:!0},onNodesChange:_,onNodeClick:(e,t)=>a?.(t.id),onPaneClick:()=>a?.(null),children:[(0,M.jsx)(de,{pipeline:e.id}),(0,M.jsx)(h,{}),(0,M.jsx)(i,{showInteractive:!1})]})})})}function he({pipeline:e,runs:t,repository:n,selected:r,onSelect:i}){let{t:a}=T();return e.variants.length<2?null:(0,M.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-sm`,children:[(0,M.jsx)(`span`,{children:a(`variants.topologyLabel`)}),(0,M.jsx)(w,{type:`single`,className:`h-auto flex-wrap`,"aria-label":a(`variants.topologyLabel`),value:r,onValueChange:e=>e&&i(e),children:e.variants.map(r=>(0,M.jsxs)(ee,{value:r.id,title:r.id,children:[r.name,` `,(0,M.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:a(`variants.topologyRuns`,{count:q(e,t,n,r.id).runs})})]},r.id))})]})}function ge(e,t){let n=e?.variants.find(e=>e.id===t);return!e||!n||e.variants.length<2?{pipeline:e,id:n?.id??`default`}:{pipeline:{...e,steps:n.steps,split:n.split},id:n.id}}function _e(e,t,n,r,i){let a=e?.pipelines.find(e=>e.id===n)??e?.pipelines[0]??null,{pipeline:o,id:s}=(0,j.useMemo)(()=>ge(a,r),[a,r]),c=r!==null&&a!==null&&!a.variants.some(e=>e.id===r);return(0,j.useEffect)(()=>{c&&i?.(null)},[c,i]),{base:a,pipeline:o,variantId:s,live:(0,j.useMemo)(()=>o?q(o,t,e?.repository??null,(a?.variants.length??0)>1?s:null):null,[o,a,s,t,e])}}function Q({title:e,status:t,onOpen:n,children:r}){return(0,M.jsxs)(`li`,{className:`flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1`,children:[(0,M.jsx)(C,{variant:`link`,size:`sm`,className:`h-auto max-w-full min-w-0 shrink p-0 text-left whitespace-normal`,onClick:n,children:e}),(0,M.jsx)(O,{status:t}),r]})}function ve({node:e}){let{t}=T(),{data:n}=e;return(0,M.jsxs)(`div`,{className:`flex flex-col gap-1`,"data-testid":`stage-about`,children:[(0,M.jsx)(`p`,{children:t(`topology.stages.about.${n.kind}`)}),(0,M.jsxs)(`p`,{className:`text-muted-foreground`,children:[t(`topology.stages.performer`),`: `,n.performer]}),n.condition===null?null:(0,M.jsxs)(`p`,{className:`text-muted-foreground`,children:[t(`topology.stages.conditionLabel`),`: `,n.condition]}),n.link?(0,M.jsx)(`a`,{className:`text-primary underline-offset-4 hover:underline`,href:n.link,children:t(`topology.stages.open`)}):null]})}function ye({node:e,onOpenGroup:t}){let{t:n}=T(),{data:r}=e;return(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(`h3`,{className:`font-semibold`,children:r.title}),(0,M.jsx)(`p`,{className:`text-muted-foreground`,children:r.subtitle}),r.kind===`step`?null:(0,M.jsx)(ve,{node:e}),r.groups.length===0?(0,M.jsx)(`p`,{className:`text-muted-foreground`,children:n(`topology.noGroups`)}):null,(0,M.jsx)(`ul`,{className:`flex flex-col gap-1.5`,children:r.groups.map(e=>(0,M.jsx)(Q,{title:e.title,status:e.status,onOpen:()=>t(e,r.step),children:(0,M.jsx)(`span`,{className:`min-w-0 text-muted-foreground`,children:e.runTitle})},`${e.runId}/${e.slug}`))})]})}function be({node:e,others:t,load:n,onOpenGroup:r}){let{t:i}=T(),a=e?.data.specialist??``;return(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(`h3`,{className:`font-semibold`,children:i(`topology.occupied`)}),(0,M.jsx)(`p`,{className:`text-muted-foreground`,children:i(`topology.occupiedHint`,{specialist:n.get(a)?.name??a})}),(0,M.jsx)(`ul`,{className:`flex flex-col gap-1.5`,"aria-label":i(`topology.occupied`),children:[...t.running,...t.waiting].map(e=>(0,M.jsx)(Q,{title:e.title,status:e.status,onOpen:()=>r({runId:e.runId,runTitle:e.runTitle,slug:e.group,title:e.title,status:e.status},e.step),children:(0,M.jsxs)(`span`,{className:`min-w-0 text-muted-foreground`,children:[e.stepName,` · `,e.runTitle,` · `,x(e.repository)]})},`${e.runId}/${e.group}/${e.status}`))})]})}function xe({node:e,live:t,load:n,onOpenGroup:r}){let{t:i}=T(),a=e?.data.specialist?L(n,t,e.data.specialist):null;return(0,M.jsxs)(`aside`,{className:`flex min-w-0 flex-col gap-2 rounded-lg border bg-card p-3 text-sm [overflow-wrap:anywhere]`,"aria-label":e?i(`topology.nodeNamed`,{title:e.data.title}):i(`topology.node`),children:[e?(0,M.jsx)(ye,{node:e,onOpenGroup:r}):(0,M.jsx)(`p`,{className:`text-muted-foreground`,children:i(`topology.selectNode`)}),a&&(a.running.length>0||a.waiting.length>0)?(0,M.jsx)(be,{node:e,others:a,load:n,onOpenGroup:r}):null,t.elsewhere.length>0?(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(`h3`,{className:`font-semibold`,children:i(`topology.elsewhere`)}),(0,M.jsx)(`p`,{className:`text-muted-foreground`,children:i(`topology.elsewhereHint`)}),(0,M.jsx)(`ul`,{className:`flex flex-col gap-1.5`,children:t.elsewhere.map(e=>(0,M.jsx)(Q,{title:e.title,status:e.status,onOpen:()=>r(e,null)},`${e.runId}/${e.slug}`))})]}):null]})}function Se(e,t,n){return new Map(e.map(e=>[e.id,q(e,t,n).runs]))}function Ce(e,t,n){return e.map(e=>({id:e.id,title:e.name,hint:e.id,subtitle:e.steps.map(e=>e.name).join(` → `),extra:t.get(e.id)?(0,M.jsx)(O,{status:`running`,label:n(`topology.active`,{n:t.get(e.id)??0})}):(0,M.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:n(`topology.noActive`)})}))}function $({pipeline:e,repository:t,runs:n,onEdit:r}){let{t:i}=T();return(0,M.jsxs)(`header`,{className:`flex flex-col gap-1`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,M.jsx)(`h2`,{className:`text-lg font-semibold`,title:e.id,children:e.name}),r?(0,M.jsx)(C,{variant:`link`,size:`sm`,asChild:!0,children:(0,M.jsx)(`a`,{href:y({view:`pipelines`,run:e.id,group:null,step:null,tab:null}),onClick:t=>{t.preventDefault(),r(e.id)},children:i(`topology.edit`)})}):null]}),(0,M.jsxs)(`div`,{className:`flex flex-wrap gap-x-3 text-sm text-muted-foreground`,children:[(0,M.jsx)(`span`,{children:t}),(0,M.jsx)(`span`,{children:i(`topology.delivery`,{mode:e.delivery.mode})}),n>0?(0,M.jsx)(`span`,{children:i(`topology.activeRuns`,{n})}):(0,M.jsx)(`span`,{children:i(`topology.noActive`)})]})]})}function we(e){let[t,n]=(0,j.useState)(null),[r,i]=(0,j.useState)(null);return(0,j.useEffect)(()=>{let t=!1;return e.pipelines().then(e=>!t&&n(e),e=>!t&&i(e.message)),()=>{t=!0}},[e]),{view:t,failure:r}}function Te({pipeline:e,base:t,live:n,runs:r,view:i,variantId:a,selected:o,onSelectNode:s,onEdit:c,onSelectVariant:l,onOpenGroup:u}){let d=(0,j.useMemo)(()=>E(r),[r]),[f,p]=(0,j.useState)([]),m=f.find(e=>e.id===o)??null;return(0,M.jsxs)(`section`,{"aria-label":`pipeline ${e.id}`,className:`flex flex-col gap-3`,children:[(0,M.jsx)($,{pipeline:e,repository:i?.repository,runs:n.runs,onEdit:c}),t?(0,M.jsx)(he,{pipeline:t,runs:r,repository:i?.repository??null,selected:a,onSelect:e=>l?.(e==="default"?null:e)}):null,(0,M.jsxs)(`div`,{className:`grid gap-3 lg:grid-cols-[minmax(0,1fr)_18rem]`,children:[(0,M.jsx)(me,{pipeline:e,live:n,load:d,selected:o,onSelect:s,onNodes:p}),(0,M.jsx)(xe,{node:m,live:n,load:d,onOpenGroup:u})]})]})}function Ee({api:e,runs:t,pipeline:n,variant:r=null,onSelectVariant:i,onSelectPipeline:a,onEditPipeline:o,onOpenGroup:s}){let{t:c}=T(),{view:l,failure:u}=we(e),[d,f]=(0,j.useState)(null),{base:p,pipeline:m,variantId:h,live:g}=_e(l,t,n,r,i),_=(0,j.useMemo)(()=>Se(l?.pipelines??[],t,l?.repository??null),[l,t]);return(0,M.jsx)(A,{side:(0,M.jsxs)(M.Fragment,{children:[l===null&&u===null?(0,M.jsx)(`div`,{role:`status`,"aria-label":c(`topology.loading`),children:(0,M.jsx)(S,{className:`h-16`})}):null,(0,M.jsx)(re,{label:`pipeline`,selected:m?.id??null,onSelect:e=>{f(null),a(e)},entries:Ce(l?.pipelines??[],_,c)})]}),children:(0,M.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[u?(0,M.jsx)(b,{variant:`destructive`,children:u}):null,l?(0,M.jsx)(ne,{errors:l.errors}):null,m&&g?(0,M.jsx)(Te,{pipeline:m,base:p,live:g,runs:t,view:l,variantId:h,selected:d,onSelectNode:f,onEdit:o,onSelectVariant:i,onOpenGroup:s}):null]})})}export{Ee as TopologyPage};
1
+ import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{_ as t,a as n,c as r,d as i,f as a,g as o,h as s,i as c,l,m as u,o as d,p as f,r as p,s as m,u as h}from"./pipelines-Cej37cah.js";import{i as g,t as _}from"./vendor-react-C1iE8mnY.js";import{F as v,_ as y,a as b,f as x,i as S,j as C,n as w,r as ee,t as te,ut as T}from"./card-4euJkmfJ.js";import{E,P as D,T as O,j as k}from"./index-LD1g1Vkm.js";import{d as A,l as ne,u as re}from"./specialists-BGKB5BLI.js";var j=e(g(),1),M=_();function N(){return(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(a,{type:`target`,position:t.Left,id:`in`}),(0,M.jsx)(a,{type:`source`,position:t.Right,id:`out`}),(0,M.jsx)(a,{type:`target`,position:t.Bottom,id:`back-in`}),(0,M.jsx)(a,{type:`source`,position:t.Bottom,id:`back-out`}),(0,M.jsx)(a,{type:`source`,position:t.Bottom,id:`down`}),(0,M.jsx)(a,{type:`target`,position:t.Top,id:`up`})]})}function P({data:e,testId:t}){return(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(`div`,{className:`truncate text-muted-foreground`,title:e.subtitleHint??e.subtitle,children:e.subtitle}),e.performer&&e.performer!==e.subtitle?(0,M.jsx)(`div`,{className:`truncate text-muted-foreground`,"data-testid":`performer-${t}`,title:e.performer,children:e.performer}):null,e.condition===null?null:(0,M.jsx)(`div`,{className:`truncate font-medium`,"data-testid":`condition-${t}`,children:e.condition}),e.detail?(0,M.jsx)(`div`,{className:`truncate text-muted-foreground`,children:e.detail}):null,e.groups.length>0?(0,M.jsx)(`div`,{className:`flex min-w-0 flex-wrap gap-1`,children:e.groups.map(e=>(0,M.jsx)(O,{status:e.status,label:e.title,title:e.title},`${e.runId}/${e.slug}`))}):null]})}function F({data:e,testId:t}){let{t:n}=T(),r=D({inputTokens:e.inputTokens??0,outputTokens:e.outputTokens??0})||`—`;return(0,M.jsxs)(M.Fragment,{children:[e.busy&&(e.busy.running>0||e.busy.max!==null)?(0,M.jsxs)(`div`,{className:v(`truncate text-muted-foreground`,e.busy.full&&`font-medium`),"data-testid":`busy-${t}`,children:[e.busy.max===null?n(`topology.busyUnlimited`,{n:e.busy.running}):n(`topology.busy`,{n:e.busy.running,max:e.busy.max}),e.busy.elsewhere>0?` · ${n(`topology.busyElsewhere`,{n:e.busy.elsewhere})}`:``]}):null,e.attempts===null?null:(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(`div`,{className:`truncate text-muted-foreground`,children:n(`topology.attempts`,{n:e.attempts})}),(0,M.jsx)(`div`,{className:`truncate text-muted-foreground tabular-nums`,"data-testid":`usage-${e.step}`,title:r,children:r})]})]})}function I({data:e,selected:t}){let{t:n}=T(),r=e.step??(e.kind===`action`?e.stageId:e.kind);return(0,M.jsxs)(te,{className:v(`relative grid w-[170px] grid-cols-[minmax(0,1fr)] gap-1 px-3 py-2.5 text-xs`,e.kind!==`step`&&`bg-muted`,e.condition!==null&&`border-dashed`,e.skipped&&`opacity-60`,e.active&&`border-status-run ring-4 ring-status-run-bg`,e.busy?.full&&`border-status-warn bg-status-warn-bg`,t&&`border-primary`),"data-testid":`stage-${r}`,"data-conditional":e.condition===null?void 0:`true`,"data-skipped":e.skipped?`true`:void 0,children:[e.sectionStart?(0,M.jsx)(`div`,{className:`pointer-events-none absolute -top-5 left-0 text-[10px] font-medium tracking-wide whitespace-nowrap text-muted-foreground uppercase`,"data-testid":`section-${e.section}`,children:n(`topology.stages.section.${e.section}`)}):null,(0,M.jsx)(N,{}),(0,M.jsx)(`div`,{className:v(`truncate text-sm font-bold`,e.skipped&&`line-through`),title:e.title,children:e.title}),e.skipped?(0,M.jsx)(`div`,{className:`text-muted-foreground`,children:n(`variants.schemaSkipped`)}):null,(0,M.jsx)(P,{data:e,testId:r}),(0,M.jsx)(F,{data:e,testId:r})]})}function L(e,t,n){let r=new Set(t.runIds),i=e.get(n);return{running:(i?.running??[]).filter(e=>!r.has(e.runId)),waiting:(i?.waiting??[]).filter(e=>!r.has(e.runId))}}function R(e,t,n,r){let i=n.get(r),a=[i?.max??null,e.limits?.[r]??null].filter(e=>e!==null&&e>0),o=a.length>0?Math.min(...a):null,s=i?.running.length??0;return{running:s,elsewhere:L(n,t,r).running.length,max:o,full:o!==null&&s>=o}}function z(e){return e.some(e=>e.status===`running`||e.status===`merging`)}var B={attempts:null,inputTokens:null,outputTokens:null,step:null,specialist:null,busy:null};function V(e,t,r){return{stageId:e.id,section:e.section,sectionStart:e.section!==t,performer:n(e.performer,r),condition:c(e.condition,r),link:m(e)}}function H({pipeline:e,live:t,load:n,t:r},i){let a=e.split;if(!a)return null;let o=e.stages.find(e=>e.id===`split`),s=o?.performer.type===`specialist`&&o.performer.name?o.performer.name:a.specialist,c=a.pipeline?[r(`topology.splitPipeline`,{id:a.pipelineName??a.pipeline})]:[];return{id:`split`,data:{kind:`split`,title:r(`topology.split`),subtitle:s,...s===a.specialist?{}:{subtitleHint:a.specialist},detail:[r(`topology.splitDetail`,{n:a.maxGroups}),...c].join(` · `),groups:t.splitting,active:t.splitting.some(e=>e.status===`running`),...B,...i,specialist:a.specialist,busy:R(e,t,n,a.specialist)}}}function U(e,t,n){let{pipeline:r,live:i,load:a}=e,o=r.steps.find(e=>`step:${e.id}`===t.id);if(!o)return null;let s=i.steps.get(o.id)??[];return{id:`step:${o.id}`,data:{kind:`step`,title:o.name,subtitle:o.specialist,detail:`${o.runtime}${o.model?` ${o.model}`:``} · ${o.permissions}`,groups:s,attempts:i.attempts.get(o.id)??0,inputTokens:i.inputTokens.get(o.id)??0,outputTokens:i.outputTokens.get(o.id)??0,active:z(s),step:o.id,...o.skipped?{skipped:!0}:{},specialist:o.specialist,busy:R(r,i,a,o.specialist),...n}}}function W(e,t,i){let{pipeline:a,live:o,load:s,t:c}=e,l=t.performer.type===`specialist`?t.performer.slug:null,u=t.kind===`action`||t.kind===`message`?t.kind:`cleanup`,d=t.kind===`message`?c(`topology.stages.name.message`):t.kind===`cleanup`?c(`topology.stages.name.cleanup`):t.name;return{id:r(t),data:{kind:u,title:d,subtitle:n(t.performer,c),detail:null,groups:[],active:!1,...B,...i,specialist:l,busy:l?R(a,o,s,l):null}}}function G(e,t,n){let{t:r,live:i,pipeline:a}=e;switch(t.kind){case`split`:return H(e,n);case`step`:return U(e,t,n);case`merge`:return{id:`merge`,data:{kind:`merge`,title:r(`topology.merge`),subtitle:r(`topology.mergeSubtitle`),detail:null,groups:i.merging,active:z(i.merging),...B,...n}};case`delivery`:return{id:`delivery`,data:{kind:`delivery`,title:r(`topology.deliveryNode`),subtitle:a.delivery.mode,detail:null,groups:i.merged,active:!1,...B,...n}};default:return W(e,t,n)}}function K(e,t,n,r){let{pipeline:i,live:a,load:o,t:s,sizes:c}=e,l=t.performer.type===`specialist`?t.performer.slug:null,u=i.delivery.resolver??l;if(!u||!r)return null;let d=e=>c.get(e)?.height??90;return{id:`resolver`,position:{x:r.position.x,y:d(`delivery`)/2+60+d(`resolver`)/2},data:{kind:`resolver`,title:s(`topology.resolver`),subtitle:u,detail:null,groups:[],active:!1,...B,...n,sectionStart:!1,specialist:u,busy:R(i,a,o,u)}}}function q(e,t,n,r=null){let i={steps:new Map,attempts:new Map,inputTokens:new Map,outputTokens:new Map,merging:[],merged:[],splitting:[],elsewhere:[],runs:0,runIds:[]},a=new Set(e.steps.map(e=>e.id));for(let o of t){if(o.finished||o.pipeline!==e.id||n!==null&&o.repository!==n||r!==null&&(o.variant??`default`)!==r)continue;i.runs+=1,i.runIds.push(o.id);let t=e=>({runId:o.id,runTitle:o.title,...e});o.split&&o.split.status!==`done`&&i.splitting.push({runId:o.id,runTitle:o.title,slug:`_split`,title:o.title,status:o.split.status});for(let e of o.topology?.steps??[]){let n=a.has(e.id)?i.steps.get(e.id)??[]:i.elsewhere;n.push(...e.groups.map(t)),a.has(e.id)&&(i.steps.set(e.id,n),i.attempts.set(e.id,(i.attempts.get(e.id)??0)+e.attempts),i.inputTokens.set(e.id,(i.inputTokens.get(e.id)??0)+(e.usage?.inputTokens??0)),i.outputTokens.set(e.id,(i.outputTokens.get(e.id)??0)+(e.usage?.outputTokens??0)))}i.merging.push(...(o.topology?.merging??[]).map(t)),i.merged.push(...(o.topology?.merged??[]).map(t))}return i}function J(e,t){return JSON.stringify(e)===JSON.stringify(t)}function Y(e,t,n,r){let i=new Map(e.map(e=>[e.id,e]));return t.map(e=>{let t=e.id===r,a=i.get(e.id);if(a&&a.position.x===e.position.x&&a.position.y===e.position.y&&!!a.selected===t&&J(a.data,e.data))return a;let o=n.get(e.id)??a?.measured;return{...e,selected:t,...o?{measured:{...o}}:{}}})}function X(e,t){let n=new Map(e.map(e=>[e.id,e]));return t.map(e=>{let t=n.get(e.id);return t&&J(t,e)?t:e})}var ie=210;function ae(e,t){return{id:`${e.id}->${t.id}`,source:e.id,target:t.id,sourceHandle:`out`,targetHandle:`in`,animated:t.data.active,type:`orthogonal`,className:`edge-forward`}}var oe=e=>({id:`delivery->resolver`,source:`delivery`,target:`resolver`,sourceHandle:`down`,targetHandle:`up`,type:`orthogonal`,label:e(`topology.conflict`),className:`edge-resolver`});function se(e){return e.steps.flatMap(e=>e.onReject?[{id:`reject:${e.id}->${e.onReject.goto}`,source:`step:${e.id}`,target:`step:${e.onReject.goto}`,sourceHandle:`back-out`,targetHandle:`back-in`,type:`orthogonal`,label:`≤ ${e.onReject.maxRounds}`,className:`edge-reject`}]:[])}function ce(e,t,n,r=new Map,i=new Map){let a={pipeline:e,live:t,load:i,t:n,sizes:r},o=[],s=[],c=null,l=null;for(let t of d(e)){let e=V(t,l,n);if(t.kind===`resolve`){let r=K(a,t,e,o.find(e=>e.id===`delivery`));if(!r)continue;o.push({id:r.id,type:`stage`,position:r.position,data:r.data}),s.push(oe(n));continue}let r=G(a,t,e);if(!r)continue;let i={id:r.id,type:`stage`,position:{x:o.filter(e=>e.id!==`resolver`).length*ie,y:0},data:r.data};o.push(i),l=r.data.section,c&&s.push(ae(c,r)),c=i}return{nodes:o,edges:le(o,[...s,...se(e)],r)}}function le(e,t,n){let r=p(e.map(e=>{let t=n.get(e.id),r=t?.height??90;return{id:e.id,x:e.position.x,y:e.position.y-r/2,width:t?.width??170,height:r}}),t.map(e=>{let t=e.id.startsWith(`reject:`)?`return`:e.id===`delivery->resolver`?`down`:`next`;return{id:e.id,source:e.source,target:e.target,kind:t}}));return t.map(e=>({...e,data:{route:r.get(e.id)}}))}var Z={padding:.15,maxZoom:1},ue=[0,.5];function de({pipeline:e}){let{fitView:t}=o(),n=s(),r=(0,j.useRef)(null);return(0,j.useEffect)(()=>{n&&r.current!==e&&(r.current!==null&&t(Z),r.current=e)},[n,e,t]),null}var fe={stage:I},pe={orthogonal:l};function me({pipeline:e,live:t,load:n,selected:r=null,onSelect:a,onNodes:o,className:s}){let{t:c}=T(),{resolved:l}=k(),d=(0,j.useMemo)(()=>t??q(e,[],null),[t,e]),p=(0,j.useRef)(new Map),[m,g]=(0,j.useState)(0),_=(0,j.useCallback)(e=>{let t=!1;for(let n of e){if(n.type!==`dimensions`||!n.dimensions)continue;let e=p.current.get(n.id),{width:r,height:i}=n.dimensions;e&&e.width===r&&e.height===i||(p.current.set(n.id,{width:r,height:i}),t=!0)}t&&g(e=>e+1)},[]),y=(0,j.useRef)([]),b=(0,j.useRef)([]),x=(0,j.useMemo)(()=>{let t=ce(e,d,c,p.current,n??void 0),i=Y(y.current,t.nodes,p.current,r),a=X(b.current,t.edges);return y.current=i,b.current=a,{nodes:i,edges:a}},[e,d,n,r,m,c]);return(0,j.useEffect)(()=>o?.(x.nodes),[x.nodes,o]),(0,M.jsx)(`div`,{className:v(`h-[420px] overflow-hidden rounded-lg border bg-card`,s),children:(0,M.jsx)(f,{children:(0,M.jsxs)(u,{nodes:x.nodes,edges:x.edges,nodeTypes:fe,edgeTypes:pe,nodeOrigin:ue,fitView:!0,colorMode:l,fitViewOptions:Z,minZoom:.3,nodesDraggable:!1,nodesConnectable:!1,proOptions:{hideAttribution:!0},onNodesChange:_,onNodeClick:(e,t)=>a?.(t.id),onPaneClick:()=>a?.(null),children:[(0,M.jsx)(de,{pipeline:e.id}),(0,M.jsx)(h,{}),(0,M.jsx)(i,{showInteractive:!1})]})})})}function he({pipeline:e,runs:t,repository:n,selected:r,onSelect:i}){let{t:a}=T();return e.variants.length<2?null:(0,M.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-sm`,children:[(0,M.jsx)(`span`,{children:a(`variants.topologyLabel`)}),(0,M.jsx)(w,{type:`single`,className:`h-auto flex-wrap`,"aria-label":a(`variants.topologyLabel`),value:r,onValueChange:e=>e&&i(e),children:e.variants.map(r=>(0,M.jsxs)(ee,{value:r.id,title:r.id,children:[r.name,` `,(0,M.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:a(`variants.topologyRuns`,{count:q(e,t,n,r.id).runs})})]},r.id))})]})}function ge(e,t){let n=e?.variants.find(e=>e.id===t);return!e||!n||e.variants.length<2?{pipeline:e,id:n?.id??`default`}:{pipeline:{...e,steps:n.steps,split:n.split},id:n.id}}function _e(e,t,n,r,i){let a=e?.pipelines.find(e=>e.id===n)??e?.pipelines[0]??null,{pipeline:o,id:s}=(0,j.useMemo)(()=>ge(a,r),[a,r]),c=r!==null&&a!==null&&!a.variants.some(e=>e.id===r);return(0,j.useEffect)(()=>{c&&i?.(null)},[c,i]),{base:a,pipeline:o,variantId:s,live:(0,j.useMemo)(()=>o?q(o,t,e?.repository??null,(a?.variants.length??0)>1?s:null):null,[o,a,s,t,e])}}function Q({title:e,status:t,onOpen:n,children:r}){return(0,M.jsxs)(`li`,{className:`flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1`,children:[(0,M.jsx)(C,{variant:`link`,size:`sm`,className:`h-auto max-w-full min-w-0 shrink p-0 text-left whitespace-normal`,onClick:n,children:e}),(0,M.jsx)(O,{status:t}),r]})}function ve({node:e}){let{t}=T(),{data:n}=e;return(0,M.jsxs)(`div`,{className:`flex flex-col gap-1`,"data-testid":`stage-about`,children:[(0,M.jsx)(`p`,{children:t(`topology.stages.about.${n.kind}`)}),(0,M.jsxs)(`p`,{className:`text-muted-foreground`,children:[t(`topology.stages.performer`),`: `,n.performer]}),n.condition===null?null:(0,M.jsxs)(`p`,{className:`text-muted-foreground`,children:[t(`topology.stages.conditionLabel`),`: `,n.condition]}),n.link?(0,M.jsx)(`a`,{className:`text-primary underline-offset-4 hover:underline`,href:n.link,children:t(`topology.stages.open`)}):null]})}function ye({node:e,onOpenGroup:t}){let{t:n}=T(),{data:r}=e;return(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(`h3`,{className:`font-semibold`,children:r.title}),(0,M.jsx)(`p`,{className:`text-muted-foreground`,children:r.subtitle}),r.kind===`step`?null:(0,M.jsx)(ve,{node:e}),r.groups.length===0?(0,M.jsx)(`p`,{className:`text-muted-foreground`,children:n(`topology.noGroups`)}):null,(0,M.jsx)(`ul`,{className:`flex flex-col gap-1.5`,children:r.groups.map(e=>(0,M.jsx)(Q,{title:e.title,status:e.status,onOpen:()=>t(e,r.step),children:(0,M.jsx)(`span`,{className:`min-w-0 text-muted-foreground`,children:e.runTitle})},`${e.runId}/${e.slug}`))})]})}function be({node:e,others:t,load:n,onOpenGroup:r}){let{t:i}=T(),a=e?.data.specialist??``;return(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(`h3`,{className:`font-semibold`,children:i(`topology.occupied`)}),(0,M.jsx)(`p`,{className:`text-muted-foreground`,children:i(`topology.occupiedHint`,{specialist:n.get(a)?.name??a})}),(0,M.jsx)(`ul`,{className:`flex flex-col gap-1.5`,"aria-label":i(`topology.occupied`),children:[...t.running,...t.waiting].map(e=>(0,M.jsx)(Q,{title:e.title,status:e.status,onOpen:()=>r({runId:e.runId,runTitle:e.runTitle,slug:e.group,title:e.title,status:e.status},e.step),children:(0,M.jsxs)(`span`,{className:`min-w-0 text-muted-foreground`,children:[e.stepName,` · `,e.runTitle,` · `,x(e.repository)]})},`${e.runId}/${e.group}/${e.status}`))})]})}function xe({node:e,live:t,load:n,onOpenGroup:r}){let{t:i}=T(),a=e?.data.specialist?L(n,t,e.data.specialist):null;return(0,M.jsxs)(`aside`,{className:`flex min-w-0 flex-col gap-2 rounded-lg border bg-card p-3 text-sm [overflow-wrap:anywhere]`,"aria-label":e?i(`topology.nodeNamed`,{title:e.data.title}):i(`topology.node`),children:[e?(0,M.jsx)(ye,{node:e,onOpenGroup:r}):(0,M.jsx)(`p`,{className:`text-muted-foreground`,children:i(`topology.selectNode`)}),a&&(a.running.length>0||a.waiting.length>0)?(0,M.jsx)(be,{node:e,others:a,load:n,onOpenGroup:r}):null,t.elsewhere.length>0?(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(`h3`,{className:`font-semibold`,children:i(`topology.elsewhere`)}),(0,M.jsx)(`p`,{className:`text-muted-foreground`,children:i(`topology.elsewhereHint`)}),(0,M.jsx)(`ul`,{className:`flex flex-col gap-1.5`,children:t.elsewhere.map(e=>(0,M.jsx)(Q,{title:e.title,status:e.status,onOpen:()=>r(e,null)},`${e.runId}/${e.slug}`))})]}):null]})}function Se(e,t,n){return new Map(e.map(e=>[e.id,q(e,t,n).runs]))}function Ce(e,t,n){return e.map(e=>({id:e.id,title:e.name,hint:e.id,subtitle:e.steps.map(e=>e.name).join(` → `),extra:t.get(e.id)?(0,M.jsx)(O,{status:`running`,label:n(`topology.active`,{n:t.get(e.id)??0})}):(0,M.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:n(`topology.noActive`)})}))}function $({pipeline:e,repository:t,runs:n,onEdit:r}){let{t:i}=T();return(0,M.jsxs)(`header`,{className:`flex flex-col gap-1`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,M.jsx)(`h2`,{className:`text-lg font-semibold`,title:e.id,children:e.name}),r?(0,M.jsx)(C,{variant:`link`,size:`sm`,asChild:!0,children:(0,M.jsx)(`a`,{href:y({view:`pipelines`,run:e.id,group:null,step:null,tab:null}),onClick:t=>{t.preventDefault(),r(e.id)},children:i(`topology.edit`)})}):null]}),(0,M.jsxs)(`div`,{className:`flex flex-wrap gap-x-3 text-sm text-muted-foreground`,children:[(0,M.jsx)(`span`,{children:t}),(0,M.jsx)(`span`,{children:i(`topology.delivery`,{mode:e.delivery.mode})}),n>0?(0,M.jsx)(`span`,{children:i(`topology.activeRuns`,{n})}):(0,M.jsx)(`span`,{children:i(`topology.noActive`)})]})]})}function we(e){let[t,n]=(0,j.useState)(null),[r,i]=(0,j.useState)(null);return(0,j.useEffect)(()=>{let t=!1;return e.pipelines().then(e=>!t&&n(e),e=>!t&&i(e.message)),()=>{t=!0}},[e]),{view:t,failure:r}}function Te({pipeline:e,base:t,live:n,runs:r,view:i,variantId:a,selected:o,onSelectNode:s,onEdit:c,onSelectVariant:l,onOpenGroup:u}){let d=(0,j.useMemo)(()=>E(r),[r]),[f,p]=(0,j.useState)([]),m=f.find(e=>e.id===o)??null;return(0,M.jsxs)(`section`,{"aria-label":`pipeline ${e.id}`,className:`flex flex-col gap-3`,children:[(0,M.jsx)($,{pipeline:e,repository:i?.repository,runs:n.runs,onEdit:c}),t?(0,M.jsx)(he,{pipeline:t,runs:r,repository:i?.repository??null,selected:a,onSelect:e=>l?.(e==="default"?null:e)}):null,(0,M.jsxs)(`div`,{className:`grid gap-3 lg:grid-cols-[minmax(0,1fr)_18rem]`,children:[(0,M.jsx)(me,{pipeline:e,live:n,load:d,selected:o,onSelect:s,onNodes:p}),(0,M.jsx)(xe,{node:m,live:n,load:d,onOpenGroup:u})]})]})}function Ee({api:e,runs:t,pipeline:n,variant:r=null,onSelectVariant:i,onSelectPipeline:a,onEditPipeline:o,onOpenGroup:s}){let{t:c}=T(),{view:l,failure:u}=we(e),[d,f]=(0,j.useState)(null),{base:p,pipeline:m,variantId:h,live:g}=_e(l,t,n,r,i),_=(0,j.useMemo)(()=>Se(l?.pipelines??[],t,l?.repository??null),[l,t]);return(0,M.jsx)(A,{side:(0,M.jsxs)(M.Fragment,{children:[l===null&&u===null?(0,M.jsx)(`div`,{role:`status`,"aria-label":c(`topology.loading`),children:(0,M.jsx)(S,{className:`h-16`})}):null,(0,M.jsx)(re,{label:`pipeline`,selected:m?.id??null,onSelect:e=>{f(null),a(e)},entries:Ce(l?.pipelines??[],_,c)})]}),children:(0,M.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[u?(0,M.jsx)(b,{variant:`destructive`,children:u}):null,l?(0,M.jsx)(ne,{errors:l.errors}):null,m&&g?(0,M.jsx)(Te,{pipeline:m,base:p,live:g,runs:t,view:l,variantId:h,selected:d,onSelectNode:f,onEdit:o,onSelectVariant:i,onOpenGroup:s}):null]})})}export{Ee as TopologyPage};
@@ -5,16 +5,16 @@
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1" />
6
6
  <meta name="color-scheme" content="light dark" />
7
7
  <title>aip</title>
8
- <script type="module" crossorigin src="/assets/index-BAeOzr94.js"></script>
8
+ <script type="module" crossorigin src="/assets/index-LD1g1Vkm.js"></script>
9
9
  <link rel="modulepreload" crossorigin href="/assets/rolldown-runtime-XKyaHtl9.js">
10
10
  <link rel="modulepreload" crossorigin href="/assets/vendor-react-C1iE8mnY.js">
11
11
  <link rel="modulepreload" crossorigin href="/assets/card-4euJkmfJ.js">
12
- <link rel="modulepreload" crossorigin href="/assets/deliveryModes-BCAw5jcd.js">
12
+ <link rel="modulepreload" crossorigin href="/assets/deliveryModes-BGIYJzWQ.js">
13
13
  <link rel="modulepreload" crossorigin href="/assets/FilterColumn-z60UZhkk.js">
14
14
  <link rel="modulepreload" crossorigin href="/assets/empty-OZRGgwa5.js">
15
- <link rel="modulepreload" crossorigin href="/assets/locales-9kiK4pzD.js">
15
+ <link rel="modulepreload" crossorigin href="/assets/locales-D85Vnmev.js">
16
16
  <link rel="modulepreload" crossorigin href="/assets/vendor-markdown-DwXfjc7L.js">
17
- <link rel="stylesheet" crossorigin href="/assets/index-D3ty-b_t.css">
17
+ <link rel="stylesheet" crossorigin href="/assets/index-Cg7gL5P8.css">
18
18
  </head>
19
19
  <body>
20
20
  <div id="root"></div>
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aip",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Watch and control the aip agent swarm from Claude Code: a pane, a status line, toasts and slash commands",
5
5
  "author": {
6
6
  "name": "hoknie"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hoknie/aip",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "aip: local orchestrator for a swarm of AI agents (Claude Code, OpenCode)",
5
5
  "type": "module",
6
6
  "license": "MIT",