@newrelic/preflight 1.50.6 → 1.50.8

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.
@@ -60,5 +60,5 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
60
60
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function wF(e,t){if(e){if(typeof e==`string`)return TF(e,t);var n={}.toString.call(e).slice(8,-1);return n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`?Array.from(e):n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?TF(e,t):void 0}}function TF(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function EF(e,t){var n=e==null?null:typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(n!=null){var r,i,a,o,s=[],c=!0,l=!1;try{if(a=(n=n.call(e)).next,t===0){if(Object(n)!==n)return;c=!1}else for(;!(c=(r=a.call(n)).done)&&(s.push(r.value),s.length!==t);c=!0);}catch(e){l=!0,i=e}finally{try{if(!c&&n.return!=null&&(o=n.return(),Object(o)!==o))return}finally{if(l)throw i}}return s}}function DF(e){if(Array.isArray(e))return e}function OF(e,t){if(e==null)return{};var n,r,i=kF(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function kF(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}function AF(){return AF=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},AF.apply(null,arguments)}function jF(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function MF(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?jF(Object(n),!0).forEach(function(t){NF(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):jF(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function NF(e,t,n){return(t=PF(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function PF(e){var t=FF(e,`string`);return typeof t==`symbol`?t:t+``}function FF(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}var IF={x:0,y:0,width:0,height:0,viewBox:{x:0,y:0,width:0,height:0},orientation:`bottom`,ticks:[],stroke:`#666`,tickLine:!0,axisLine:!0,tick:!0,mirror:!1,minTickGap:5,tickSize:6,tickMargin:2,interval:`preserveEnd`,zIndex:R_.axis};function LF(e){var t=e.x,n=e.y,r=e.width,i=e.height,a=e.orientation,o=e.mirror,s=e.axisLine,c=e.otherSvgProps;if(!s)return null;var l=MF(MF(MF({},c),ea(s)),{},{fill:`none`});if(a===`top`||a===`bottom`){var u=+(a===`top`&&!o||a===`bottom`&&o);l=MF(MF({},l),{},{x1:t,y1:n+u*i,x2:t+r,y2:n+u*i})}else{var d=+(a===`left`&&!o||a===`right`&&o);l=MF(MF({},l),{},{x1:t+d*r,y1:n,x2:t+d*r,y2:n+i})}return b.createElement(`line`,AF({},l,{className:Ji(`recharts-cartesian-axis-line`,(0,wa.default)(s,`className`))}))}function RF(e,t,n,r,i,a,o,s,c){var l,u,d,f,p,m,h=s?-1:1,g=e.tickSize||o,_=U(e.tickCoord)?e.tickCoord:e.coordinate;switch(a){case`top`:l=u=e.coordinate,f=n+ +!s*i,d=f-h*g,m=d-h*c,p=_;break;case`left`:d=f=e.coordinate,u=t+ +!s*r,l=u-h*g,p=l-h*c,m=_;break;case`right`:d=f=e.coordinate,u=t+ +s*r,l=u+h*g,p=l+h*c,m=_;break;default:l=u=e.coordinate,f=n+ +s*i,d=f+h*g,m=d+h*c,p=_}return{line:{x1:l,y1:d,x2:u,y2:f},tick:{x:p,y:m}}}function zF(e,t){switch(e){case`left`:return t?`start`:`end`;case`right`:return t?`end`:`start`;default:return`middle`}}function BF(e,t){switch(e){case`left`:case`right`:return`middle`;case`top`:return t?`start`:`end`;default:return t?`end`:`start`}}function VF(e){var t=e.option,n=e.tickProps,r=e.value,i,a=Ji(n.className,`recharts-cartesian-axis-tick-value`);if(b.isValidElement(t))i=b.cloneElement(t,MF(MF({},n),{},{className:a}));else if(typeof t==`function`)i=t(MF(MF({},n),{},{className:a}));else{var o=`recharts-cartesian-axis-tick-value`;typeof t!=`boolean`&&(o=Ji(o,eM(t))),i=b.createElement(lj,AF({},n,{className:o}),r)}return i}function HF(e){var t=e.ticks,n=e.axisType,r=e.axisId,i=Hs(),a=(0,b.useRef)(null);return(0,b.useEffect)(()=>{if(r!=null&&n!=null){var e=t.map(e=>({value:e.value,coordinate:e.coordinate,offset:e.offset,index:e.index})),o=a.current;o!=null&&o.axisId===r&&o.axisType===n&&(0,bF.default)(o.ticks,e)||(a.current={ticks:e,axisId:r,axisType:n},i(_F({ticks:e,axisId:r,axisType:n})))}},[i,t,r,n]),(0,b.useEffect)(()=>r==null||n==null?Ra:()=>{i(vF({axisId:r,axisType:n}))},[i,r,n]),null}var UF=(0,b.forwardRef)((e,t)=>{var n=e.ticks,r=n===void 0?[]:n,i=e.tick,a=e.tickLine,o=e.stroke,s=e.tickFormatter,c=e.unit,l=e.padding,u=e.tickTextProps,d=e.orientation,f=e.mirror,p=e.x,m=e.y,h=e.width,g=e.height,_=e.tickSize,v=e.tickMargin,y=e.fontSize,x=e.letterSpacing,S=e.getTicksConfig,C=e.events,w=e.axisType,T=e.axisId,E=fF(MF(MF({},S),{},{ticks:r}),y,x),D=ea(S),O=ta(i),k=QA(D.textAnchor)?D.textAnchor:zF(d,f),A=BF(d,f),j={};typeof a==`object`&&(j=a);var M=MF(MF({},D),{},{fill:`none`},j),N=E.map(e=>MF({entry:e},RF(e,p,m,h,g,d,_,f,v))),ee=N.map(e=>{var t=e.entry,n=e.line;return b.createElement(pa,{className:`recharts-cartesian-axis-tick`,key:`tick-${t.value}-${t.coordinate}-${t.tickCoord}`},a&&b.createElement(`line`,AF({},M,n,{className:Ji(`recharts-cartesian-axis-tick-line`,(0,wa.default)(a,`className`))})))}),te=N.map((e,t)=>{var n=e.entry,r=e.tick,a=MF(MF({},MF(MF(MF(MF({verticalAnchor:A},D),{},{textAnchor:k,stroke:`none`,fill:o},r),{},{index:t,payload:n,visibleTicksCount:E.length,tickFormatter:s,padding:l},u),{},{angle:u?.angle??D.angle??0})),O);return b.createElement(pa,AF({className:`recharts-cartesian-axis-tick-label`,key:`tick-label-${n.value}-${n.coordinate}-${n.tickCoord}`},Zo(C,n,t)),i&&b.createElement(VF,{option:i,tickProps:a,value:`${typeof s==`function`?s(n.value,t):n.value}${c||``}`}))});return b.createElement(`g`,{className:`recharts-cartesian-axis-ticks recharts-${w}-ticks`},b.createElement(HF,{ticks:E,axisId:T,axisType:w}),te.length>0&&b.createElement(XO,{zIndex:R_.label},b.createElement(`g`,{className:`recharts-cartesian-axis-tick-labels recharts-${w}-tick-labels`,ref:t},te)),ee.length>0&&b.createElement(`g`,{className:`recharts-cartesian-axis-tick-lines recharts-${w}-tick-lines`},ee))}),WF=(0,b.forwardRef)((e,t)=>{var n=e.axisLine,r=e.width,i=e.height,a=e.className,o=e.hide,s=e.ticks,c=e.axisType,l=e.axisId,u=OF(e,xF),d=SF((0,b.useState)(``),2),f=d[0],p=d[1],m=SF((0,b.useState)(``),2),h=m[0],g=m[1],_=(0,b.useRef)(null);(0,b.useImperativeHandle)(t,()=>({getCalculatedWidth:()=>pF({ticks:_.current,label:e.labelRef?.current,labelGapWithTick:5,tickSize:e.tickSize,tickMargin:e.tickMargin}),getCalculatedHeight:()=>mF({ticks:_.current,label:e.labelRef?.current,labelGapWithTick:5,tickSize:e.tickSize,tickMargin:e.tickMargin})}));var v=(0,b.useCallback)(e=>{if(e){var t=e.getElementsByClassName(`recharts-cartesian-axis-tick-value`);_.current=t;var n=t[0];if(n){var r=window.getComputedStyle(n),i=r.fontSize,a=r.letterSpacing;(i!==f||a!==h)&&(p(i),g(a))}}},[f,h]);return o||r!=null&&r<=0||i!=null&&i<=0?null:b.createElement(XO,{zIndex:e.zIndex},b.createElement(pa,{className:Ji(`recharts-cartesian-axis`,a)},b.createElement(LF,{x:e.x,y:e.y,width:r,height:i,orientation:e.orientation,mirror:e.mirror,axisLine:n,otherSvgProps:ea(e)}),b.createElement(UF,{ref:v,axisType:c,events:u,fontSize:f,getTicksConfig:e,height:e.height,letterSpacing:h,mirror:e.mirror,orientation:e.orientation,padding:e.padding,stroke:e.stroke,tick:e.tick,tickFormatter:e.tickFormatter,tickLine:e.tickLine,tickMargin:e.tickMargin,tickSize:e.tickSize,tickTextProps:e.tickTextProps,ticks:s,unit:e.unit,width:e.width,x:e.x,y:e.y,axisId:l}),b.createElement(xj,{x:e.x,y:e.y,width:e.width,height:e.height,lowerWidth:e.width,upperWidth:e.width},b.createElement(Fj,{label:e.label,labelRef:e.labelRef}),e.children)))}),GF=b.forwardRef((e,t)=>{var n=rs(e,IF);return b.createElement(WF,AF({},n,{ref:t}))});GF.displayName=`CartesianAxis`;var KF=(0,b.createContext)({grid:{stroke:`#ccc`,fill:`none`}});KF.Provider;var qF=()=>(0,b.useContext)(KF),JF=[`x1`,`y1`,`x2`,`y2`,`key`],YF=[`offset`],XF=[`xAxisId`,`yAxisId`],ZF=[`xAxisId`,`yAxisId`];function QF(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function $F(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?QF(Object(n),!0).forEach(function(t){eI(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):QF(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function eI(e,t,n){return(t=tI(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function tI(e){var t=nI(e,`string`);return typeof t==`symbol`?t:t+``}function nI(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function rI(){return rI=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},rI.apply(null,arguments)}function iI(e,t){if(e==null)return{};var n,r,i=aI(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function aI(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}var oI=e=>{var t=e.fill;if(!t||t===`none`)return null;var n=e.fillOpacity,r=e.x,i=e.y,a=e.width,o=e.height,s=e.ry;return b.createElement(`rect`,{x:r,y:i,ry:s,width:a,height:o,stroke:`none`,fill:t,fillOpacity:n,className:`recharts-cartesian-grid-bg`})};function sI(e){var t=e.option,n=e.lineItemProps,r;if(b.isValidElement(t))r=b.cloneElement(t,n);else if(typeof t==`function`)r=t(n);else{var i=n.x1,a=n.y1,o=n.x2,s=n.y2,c=n.key,l=ea(iI(n,JF))??{};l.offset;var u=iI(l,YF),d=Array.isArray(u.strokeDasharray)?u.strokeDasharray.join(`,`):u.strokeDasharray;r=b.createElement(`line`,rI({},u,{strokeDasharray:d,x1:i,y1:a,x2:o,y2:s,fill:`none`,key:c}))}return r}function cI(e){var t=e.x,n=e.width,r=e.horizontal,i=r===void 0||r,a=e.horizontalPoints;if(!i||!a||!a.length)return null;e.xAxisId,e.yAxisId;var o=iI(e,XF),s=a.map((e,r)=>{var a=$F($F({},o),{},{x1:t,y1:e,x2:t+n,y2:e,key:`line-${r}`,index:r});return b.createElement(sI,{key:`line-${r}`,option:i,lineItemProps:a})});return b.createElement(`g`,{className:`recharts-cartesian-grid-horizontal`},s)}function lI(e){var t=e.y,n=e.height,r=e.vertical,i=r===void 0||r,a=e.verticalPoints;if(!i||!a||!a.length)return null;e.xAxisId,e.yAxisId;var o=iI(e,ZF),s=a.map((e,r)=>{var a=$F($F({},o),{},{x1:e,y1:t,x2:e,y2:t+n,key:`line-${r}`,index:r});return b.createElement(sI,{option:i,lineItemProps:a,key:`line-${r}`})});return b.createElement(`g`,{className:`recharts-cartesian-grid-vertical`},s)}function uI(e){var t=e.horizontalFill,n=e.fillOpacity,r=e.x,i=e.y,a=e.width,o=e.height,s=e.horizontalPoints,c=e.horizontal;if(!(c===void 0||c)||!t||!t.length||s==null)return null;var l=s.map(e=>Math.round(e+i-i)).sort((e,t)=>e-t);i!==l[0]&&l.unshift(0);var u=l.map((e,s)=>{var c=l[s+1],u=c==null?i+o-e:c-e;if(u<=0)return null;var d=s%t.length;return b.createElement(`rect`,{key:`react-${s}`,y:e,x:r,height:u,width:a,stroke:`none`,fill:t[d],fillOpacity:n,className:`recharts-cartesian-grid-bg`})});return b.createElement(`g`,{className:`recharts-cartesian-gridstripes-horizontal`},u)}function dI(e){var t=e.vertical,n=t===void 0||t,r=e.verticalFill,i=e.fillOpacity,a=e.x,o=e.y,s=e.width,c=e.height,l=e.verticalPoints;if(!n||!r||!r.length)return null;var u=l.map(e=>Math.round(e+a-a)).sort((e,t)=>e-t);a!==u[0]&&u.unshift(0);var d=u.map((e,t)=>{var n=u[t+1],l=n==null?a+s-e:n-e;if(l<=0)return null;var d=t%r.length;return b.createElement(`rect`,{key:`react-${t}`,x:e,y:o,width:l,height:c,stroke:`none`,fill:r[d],fillOpacity:i,className:`recharts-cartesian-grid-bg`})});return b.createElement(`g`,{className:`recharts-cartesian-gridstripes-vertical`},d)}var fI=(e,t)=>{var n=e.xAxis,r=e.width,i=e.height,a=e.offset;return Md(fF($F($F($F({},IF),n),{},{ticks:Nd(n,!0),viewBox:{x:0,y:0,width:r,height:i}})),a.left,a.left+a.width,t)},pI=(e,t)=>{var n=e.yAxis,r=e.width,i=e.height,a=e.offset;return Md(fF($F($F($F({},IF),n),{},{ticks:Nd(n,!0),viewBox:{x:0,y:0,width:r,height:i}})),a.top,a.top+a.height,t)},mI={horizontal:!0,vertical:!0,horizontalPoints:[],verticalPoints:[],verticalFill:[],horizontalFill:[],xAxisId:0,yAxisId:0,syncWithTicks:!1,zIndex:R_.grid};function hI(e){var t=op(),n=sp(),r=ap(),i=$F($F({},rs(e,mI)),{},{x:U(e.x)?e.x:r.left,y:U(e.y)?e.y:r.top,width:U(e.width)?e.width:r.width,height:U(e.height)?e.height:r.height}),a=i.xAxisId,o=i.yAxisId,s=i.x,c=i.y,l=i.width,u=i.height,d=i.syncWithTicks,f=i.horizontalValues,p=i.verticalValues,m=yf(),h=G(e=>bE(e,`xAxis`,a,m)),g=G(e=>bE(e,`yAxis`,o,m)),_=qF(),v={stroke:i.stroke??_.grid.stroke,strokeWidth:i.strokeWidth??_.grid.strokeWidth,strokeOpacity:i.strokeOpacity??_.grid.strokeOpacity,strokeDasharray:i.strokeDasharray??_.grid.strokeDasharray};if(!Cd(l)||!Cd(u)||!U(s)||!U(c))return null;var y=i.verticalCoordinatesGenerator||fI,x=i.horizontalCoordinatesGenerator||pI,S=i.horizontalPoints,C=i.verticalPoints;if((!S||!S.length)&&typeof x==`function`){var w=f&&f.length,T=x({yAxis:g?$F($F({},g),{},{ticks:w?f:g.ticks}):void 0,width:t??l,height:n??u,offset:r},w?!0:d);Ef(Array.isArray(T),`horizontalCoordinatesGenerator should return Array but instead it returned [${typeof T}]`),Array.isArray(T)&&(S=T)}if((!C||!C.length)&&typeof y==`function`){var E=p&&p.length,D=y({xAxis:h?$F($F({},h),{},{ticks:E?p:h.ticks}):void 0,width:t??l,height:n??u,offset:r},E?!0:d);Ef(Array.isArray(D),`verticalCoordinatesGenerator should return Array but instead it returned [${typeof D}]`),Array.isArray(D)&&(C=D)}return b.createElement(XO,{zIndex:i.zIndex},b.createElement(`g`,{className:`recharts-cartesian-grid`},b.createElement(oI,{fill:i.fill??_.grid.fill,fillOpacity:i.fillOpacity??_.grid.fillOpacity,x:i.x,y:i.y,width:i.width,height:i.height,ry:i.ry}),b.createElement(uI,rI({},i,{horizontalPoints:S})),b.createElement(dI,rI({},i,{verticalPoints:C})),b.createElement(cI,rI({},i,v,{offset:r,horizontalPoints:S,xAxis:h,yAxis:g})),b.createElement(lI,rI({},i,v,{offset:r,verticalPoints:C,xAxis:h,yAxis:g}))))}hI.displayName=`CartesianGrid`;var gI=Ou({name:`errorBars`,initialState:{},reducers:{addErrorBar:(e,t)=>{var n=t.payload,r=n.itemId,i=n.errorBar;e[r]||(e[r]=[]),e[r].push(i)},replaceErrorBar:(e,t)=>{var n=t.payload,r=n.itemId,i=n.prev,a=n.next;e[r]&&(e[r]=e[r].map(e=>e.dataKey===i.dataKey&&e.direction===i.direction?a:e))},removeErrorBar:(e,t)=>{var n=t.payload,r=n.itemId,i=n.errorBar;e[r]&&(e[r]=e[r].filter(e=>e.dataKey!==i.dataKey||e.direction!==i.direction))}}}),_I=gI.actions;_I.addErrorBar,_I.replaceErrorBar,_I.removeErrorBar;var vI=gI.reducer,yI=[`children`];function bI(e,t){if(e==null)return{};var n,r,i=xI(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function xI(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}var SI=(0,b.createContext)({data:[],xAxisId:`xAxis-0`,yAxisId:`yAxis-0`,dataPointFormatter:()=>({x:0,y:0,value:0}),errorBarOffset:0});function CI(e){var t=e.children,n=bI(e,yI);return b.createElement(SI.Provider,{value:n},t)}function wI(e,t){var n=G(t=>xw(t,e)),r=G(e=>ww(e,t)),i=n?.allowDataOverflow??yw.allowDataOverflow,a=r?.allowDataOverflow??Sw.allowDataOverflow;return{needClip:i||a,needClipX:i,needClipY:a}}function TI(e){var t=e.xAxisId,n=e.yAxisId,r=e.clipPathId,i=BN(),a=wI(t,n),o=a.needClipX,s=a.needClipY,c=a.needClip,l=G(e=>JT(e,t,!1)),u=G(e=>YT(e,n,!1));if(!c||!i)return null;var d=i.x,f=i.y,p=i.width,m=i.height,h=o&&l?Math.min(l[0],l[1]):d-p/2,g=s&&u?Math.min(u[0],u[1]):f-m/2,_=o&&l?Math.abs(l[1]-l[0]):p*2,v=s&&u?Math.abs(u[1]-u[0]):m*2;return b.createElement(`clipPath`,{id:`clipPath-${r}`},b.createElement(`rect`,{x:h,y:g,width:_,height:v}))}function EI(e){var t=ta(e),n=3,r=2;if(t!=null){var i=t.r,a=t.strokeWidth,o=Number(i),s=Number(a);return(Number.isNaN(o)||o<0)&&(o=n),(Number.isNaN(s)||s<0)&&(s=r),{r:o,strokeWidth:s}}return{r:n,strokeWidth:r}}function DI(e,t){return e.graphicalItems.cartesianItems.find(e=>e.id===t)?.xAxisId??0}function OI(e,t){return e.graphicalItems.cartesianItems.find(e=>e.id===t)?.yAxisId??0}var kI=(e,t,n)=>CE(e,`xAxis`,DI(e,t),n),AI=(e,t,n)=>SE(e,`xAxis`,DI(e,t),n),jI=(e,t,n)=>CE(e,`yAxis`,OI(e,t),n),MI=(e,t,n)=>SE(e,`yAxis`,OI(e,t),n),NI=K([cp,kI,jI,AI,MI],(e,t,n,r,i)=>jd(e,`xAxis`)?Kd(t,r,!1):Kd(n,i,!1)),PI=K([Mw,(e,t)=>t],(e,t)=>e.filter(e=>e.type===`area`).find(e=>e.id===t)),FI=e=>jd(cp(e),`xAxis`)?`yAxis`:`xAxis`,II=(e,t)=>FI(e)===`yAxis`?OI(e,t):DI(e,t),LI=(e,t,n)=>iT(e,FI(e),II(e,t),n),RI=K([cp,kI,jI,AI,MI,K([PI,LI],(e,t)=>{if(e!=null&&t!=null){var n=e.stackId,r=sv(e);if(n!=null&&r!=null){var i=(t[n]?.stackedData)?.find(e=>e.key===r);if(i!=null)return i.map(e=>[e[0],e[1]])}}}),$g,NI,PI,L_,K([PI,LI],(e,t)=>{if(e!=null&&e.stackId!=null&&t!=null){var n=t[e.stackId];if(n!=null)return n.graphicalItems.map(e=>e.dataKey).filter(La)}})],(e,t,n,r,i,a,o,s,c,l,u)=>{var d=o.chartData,f=o.dataStartIndex,p=o.dataEndIndex;if(!(c==null||e!==`horizontal`&&e!==`vertical`||t==null||n==null||r==null||i==null||r.length===0||i.length===0||s==null)){var m=c.data,h=m&&m.length>0?m:d?.slice(f,p+1);if(h!=null)return _L({layout:e,xAxis:t,yAxis:n,xAxisTicks:r,yAxisTicks:i,dataStartIndex:f,areaSettings:c,stackedData:a,displayedData:h,chartBaseValue:l,bandSize:s,stackDataKeys:u})}}),zI=[`animationElapsedTime`,`isAnimating`,`isEntrance`,`layout`,`isRange`,`stroke`,`connectNulls`],BI=[`id`,`baseLine`];function VI(){return VI=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},VI.apply(null,arguments)}function HI(e,t){if(e==null)return{};var n,r,i=UI(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function UI(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}function WI(e){var t=e.alpha,n=e.baseLine,r=e.points,i=e.strokeWidth,a=r[0]?.x,o=r[r.length-1]?.x;if(!Z(a)||!Z(o))return null;var s=t*Math.abs(a-o),c=Math.max(...r.map(e=>e.y||0));return U(n)?c=Math.max(n,c):n&&Array.isArray(n)&&n.length&&(c=Math.max(...n.map(e=>e.y||0),c)),U(c)?b.createElement(`rect`,{x:a<o?a:a-s,y:0,width:s,height:Math.floor(c+(i?parseInt(`${i}`,10):1))}):null}function GI(e){var t=e.alpha,n=e.baseLine,r=e.points,i=e.strokeWidth,a=r[0]?.y,o=r[r.length-1]?.y;if(!Z(a)||!Z(o))return null;var s=t*Math.abs(a-o),c=Math.max(...r.map(e=>e.x||0));return U(n)?c=Math.max(n,c):n&&Array.isArray(n)&&n.length&&(c=Math.max(...n.map(e=>e.x||0),c)),U(c)?b.createElement(`rect`,{x:0,y:a<o?a:a-s,width:c+(i?parseInt(`${i}`,10):1),height:Math.floor(s)}):null}function KI(e){var t=e.alpha,n=e.layout,r=e.points,i=e.baseLine,a=e.strokeWidth;return n===`vertical`?b.createElement(GI,{alpha:t,points:r,baseLine:i,strokeWidth:a}):b.createElement(WI,{alpha:t,points:r,baseLine:i,strokeWidth:a})}function qI(e){var t=e.animationElapsedTime,n=t===void 0?1:t,r=e.isAnimating,i=r!==void 0&&r,a=e.isEntrance,o=a!==void 0&&a,s=e.layout,c=e.isRange,l=e.stroke,u=e.connectNulls,d=HI(e,zI),f=s===`vertical`?`vertical`:`horizontal`,p=u??!1,m=eN(),h=d.id,g=d.baseLine,_=ea(HI(d,BI)),v=b.createElement(Wm,VI({},d,{id:h,baseLine:g,connectNulls:p,stroke:`none`,className:`recharts-area-area`,layout:f})),y=l!==`none`&&b.createElement(Wm,VI({},_,{className:`recharts-area-curve`,layout:f,type:d.type,connectNulls:p,fill:`none`,stroke:l,points:d.points})),x=l!==`none`&&c&&Array.isArray(g)&&b.createElement(Wm,VI({},_,{className:`recharts-area-curve`,layout:f,type:d.type,connectNulls:p,fill:`none`,stroke:l,points:g}));return o&&(i||n<1)?b.createElement(pa,null,b.createElement(`defs`,null,b.createElement(`clipPath`,{id:m},b.createElement(KI,{alpha:n,points:d.points??[],baseLine:g,layout:f,strokeWidth:d.strokeWidth}))),b.createElement(pa,{clipPath:`url(#${m})`},v,y,x)):b.createElement(b.Fragment,null,v,y,x)}var JI=[`id`],YI=[`activeDot`,`animationBegin`,`animationDuration`,`animationEasing`,`connectNulls`,`dot`,`fill`,`fillOpacity`,`hide`,`isAnimationActive`,`legendType`,`stroke`,`xAxisId`,`yAxisId`];function XI(){return XI=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},XI.apply(null,arguments)}function ZI(e,t){if(e==null)return{};var n,r,i=QI(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function QI(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}function $I(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function eL(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?$I(Object(n),!0).forEach(function(t){tL(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):$I(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function tL(e,t,n){return(t=nL(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function nL(e){var t=rL(e,`string`);return typeof t==`symbol`?t:t+``}function rL(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}var iL={activeDot:!0,animationBegin:0,animationDuration:1500,animationEasing:`ease`,animationMatchBy:jM,animationInterpolateFn:(e,t)=>e==null?[]:t===1?e.flatMap(e=>e.status===`removed`?[]:[e.next]):e.flatMap(e=>e.status===`matched`?[eL(eL({},e.next),{},{x:Na(e.prev.x,e.next.x,t),y:Na(e.prev.y,e.next.y,t)})]:e.status===`added`?[e.next]:[]),connectNulls:!1,dot:!1,fill:`#3182bd`,fillOpacity:.6,hide:!1,isAnimationActive:`auto`,legendType:`line`,stroke:`#3182bd`,strokeWidth:1,type:`linear`,label:!1,shape:qI,xAxisId:0,yAxisId:0,zIndex:R_.area};function aL(e,t){return e&&e!==`none`?e:t}var oL=e=>{var t=e.dataKey,n=e.name,r=e.stroke,i=e.fill,a=e.legendType;return[{inactive:e.hide,dataKey:t,type:a,color:aL(r,i),value:Jd(n,t),payload:e}]},sL=b.memo(e=>{var t=e.dataKey,n=e.data,r=e.stroke,i=e.strokeWidth,a=e.fill,o=e.name,s=e.hide,c=e.unit,l=e.formatter,u=e.tooltipType,d=e.id,f={dataDefinedOnItem:n,getPosition:Ra,settings:{stroke:r,strokeWidth:i,fill:a,dataKey:t,nameKey:void 0,name:Jd(o,t),hide:s,type:u,color:aL(r,a),unit:c,formatter:l,graphicalItemId:d}};return b.createElement(CM,{tooltipEntrySettings:f})});function cL(e){var t=e.clipPathId,n=e.points,r=e.props,i=r.needClip,a=r.dot,o=r.dataKey,s=ea(r);return b.createElement(SN,{points:n,dot:a,className:`recharts-area-dots`,dotClassName:`recharts-area-dot`,dataKey:o,baseProps:s,needClip:i,clipPathId:t})}function lL(e){var t=e.showLabels,n=e.children,r=e.points.map(e=>{var t={x:e.x??0,y:e.y??0,width:0,lowerWidth:0,upperWidth:0,height:0};return eL(eL({},t),{},{value:e.value,payload:e.payload,parentViewBox:void 0,viewBox:t,fill:void 0})});return b.createElement(Uj,{value:t?r:void 0},n)}function uL(e){var t=e.points,n=e.baseLine,r=e.needClip,i=e.clipPathId,a=e.props,o=e.animationElapsedTime,s=e.isAnimating,c=e.isEntrance,l=a.layout,u=a.type,d=a.stroke,f=a.connectNulls,p=a.isRange,m=a.shape,h=a.id,g=ZI(a,JI),_=eL(eL({},na(g)),{},{id:h,points:t,connectNulls:f,type:u,baseLine:n,layout:l,stroke:d,isRange:p,animationElapsedTime:o,isAnimating:s,isEntrance:c});return b.createElement(b.Fragment,null,t?.length>1&&b.createElement(pa,{clipPath:r?`url(#clipPath-${i})`:void 0},b.createElement(yM,{option:m,DefaultShape:iL.shape,shapeProps:_})),b.createElement(cL,{points:t,props:g,clipPathId:i}))}function dL(e,t,n){return U(e)?Na(U(t)?t:void 0,e,n):Fa(e)||Ea(e)?Na(U(t)?t:void 0,0,n):e}function fL(e){var t=e.needClip,n=e.clipPathId,r=e.props,i=e.previousPointsRef,a=e.previousBaselineRef,o=r.points,s=r.baseLine,c=r.isAnimationActive,l=r.animationBegin,u=r.animationDuration,d=r.animationEasing,f=r.animationMatchBy,p=r.animationInterpolateFn,m=(0,b.useMemo)(()=>({points:o,baseLine:s}),[o,s]),h=zM(m,a),g=up(),_=KM(r.onAnimationStart,r.onAnimationEnd),v=_.isAnimating,y=_.handleAnimationStart,x=_.handleAnimationEnd,S=h.startValue;if(g==null)return null;var C=Array.isArray(s)&&Array.isArray(S)?RM(S,s,f):Array.isArray(s)?RM(null,s,f):null;return b.createElement(qM,{animationInput:m,animationIdPrefix:`recharts-area-`,items:o,previousItemsRef:i,isAnimationActive:c,animationBegin:l,animationDuration:u,animationEasing:d,onAnimationStart:y,onAnimationEnd:x,animationInterpolateFn:p,animationMatchBy:f,layout:g},(e,i,a)=>{var c=i===1?s:Array.isArray(s)?p(C,i,g):a?s:dL(s,S,i);return h.syncStepValue(c,i),b.createElement(lL,{showLabels:!v,points:o},r.children,b.createElement(uL,{points:e,baseLine:c,needClip:t,clipPathId:n,props:r,animationElapsedTime:i,isAnimating:v||i<1,isEntrance:a}),b.createElement(Jj,{label:r.label}))})}function pL(e){var t=e.needClip,n=e.clipPathId,r=e.props,i=(0,b.useRef)(null),a=(0,b.useRef)();return b.createElement(fL,{needClip:t,clipPathId:n,props:r,previousPointsRef:i,previousBaselineRef:a})}var mL=class extends b.PureComponent{render(){var e=this.props,t=e.hide,n=e.dot,r=e.points,i=e.className,a=e.top,o=e.left,s=e.needClip,c=e.xAxisId,l=e.yAxisId,u=e.width,d=e.height,f=e.id,p=e.baseLine,m=e.zIndex;if(t)return null;var h=Ji(`recharts-area`,i),g=f,_=EI(n),v=_.r,y=_.strokeWidth,x=cM(n),S=v*2+y,C=s?`url(#clipPath-${x?``:`dots-`}${g})`:void 0;return b.createElement(XO,{zIndex:m},b.createElement(pa,{className:h},s&&b.createElement(`defs`,null,b.createElement(TI,{clipPathId:g,xAxisId:c,yAxisId:l}),!x&&b.createElement(`clipPath`,{id:`clipPath-dots-${g}`},b.createElement(`rect`,{x:o-S/2,y:a-S/2,width:u+S,height:d+S}))),b.createElement(pL,{needClip:s,clipPathId:g,props:this.props})),b.createElement(JN,{points:r,mainColor:aL(this.props.stroke,this.props.fill),itemDataKey:this.props.dataKey,activeDot:this.props.activeDot,clipPath:C}),this.props.isRange&&Array.isArray(p)&&b.createElement(JN,{points:p,mainColor:aL(this.props.stroke,this.props.fill),itemDataKey:this.props.dataKey,activeDot:this.props.activeDot,clipPath:C}))}};function hL(e){var t=e.activeDot,n=e.animationBegin,r=e.animationDuration,i=e.animationEasing,a=e.connectNulls,o=e.dot,s=e.fill,c=e.fillOpacity,l=e.hide,u=e.isAnimationActive,d=e.legendType,f=e.stroke,p=e.xAxisId,m=e.yAxisId,h=ZI(e,YI),g=lp(),_=gO(),v=wI(p,m).needClip,y=yf(),x=G(t=>RI(t,e.id,y))??{},S=x.points,C=x.isRange,w=x.baseLine,T=BN();if(g!==`horizontal`&&g!==`vertical`||T==null||_!==`AreaChart`&&_!==`ComposedChart`)return null;var E=T.height,D=T.width,O=T.x,k=T.y;return!S||!S.length?null:b.createElement(mL,XI({},h,{activeDot:t,animationBegin:n,animationDuration:r,animationEasing:i,baseLine:w,connectNulls:a,dot:o,fill:s,fillOpacity:c,height:E,hide:l,layout:g,isAnimationActive:u,isRange:C,legendType:d,needClip:v,points:S,stroke:f,width:D,left:O,top:k,xAxisId:p,yAxisId:m}))}var gL=(e,t,n,r,i)=>{var a=n??t;if(U(a))return a;var o=e===`horizontal`?i:r,s=o.scale.domain();if(o.type===`number`){var c=Math.max(s[0],s[1]),l=Math.min(s[0],s[1]);return a===`dataMin`?l:a===`dataMax`||c<0?c:Math.max(Math.min(s[0],s[1]),0)}return a===`dataMin`?s[0]:a===`dataMax`?s[1]:s[0]};function _L(e){var t=e.areaSettings,n=t.connectNulls,r=t.baseValue,i=t.dataKey,a=e.stackedData,o=e.layout,s=e.chartBaseValue,c=e.xAxis,l=e.yAxis,u=e.displayedData,d=e.dataStartIndex,f=e.xAxisTicks,p=e.yAxisTicks,m=e.bandSize,h=e.stackDataKeys,g=a&&a.length,_=gL(o,s,r,c,l),v=o===`horizontal`,y=!1,b=u.map((e,t)=>{var r;if(g)r=a[d+t];else{var o=kd(e,i);Array.isArray(o)?(r=o,y=!0):r=[_,o]}var s=r?.[1]??null,u=kd(e,i),b=g&&u==null&&h!=null&&h.length>0&&h.every(t=>kd(e,t)==null),x=s==null||g&&!n&&u==null||b;return v?{x:Rd({axis:c,ticks:f,bandSize:m,entry:e,index:t}),y:x?null:l.scale.map(s)??null,value:r,payload:e}:{x:x?null:c.scale.map(s)??null,y:Rd({axis:l,ticks:p,bandSize:m,entry:e,index:t}),value:r,payload:e}});return{points:b,baseLine:(g||y?b.map(e=>{var t=Array.isArray(e.value)?e.value[0]:null;return v?{x:e.x,y:t!=null&&e.y!=null?l.scale.map(t)??null:null,payload:e.payload}:{x:t==null?null:c.scale.map(t)??null,y:e.y,payload:e.payload}}):v?l.scale.map(_):c.scale.map(_))??0,isRange:y}}function vL(e){var t=rs(e,iL),n=yf();return b.createElement(rN,{id:t.id,type:`area`},e=>b.createElement(b.Fragment,null,b.createElement(wM,{legendPayload:oL(t)}),b.createElement(sL,{dataKey:t.dataKey,data:t.data,stroke:t.stroke,strokeWidth:t.strokeWidth,fill:t.fill,name:t.name,hide:t.hide,unit:t.unit,formatter:t.formatter,tooltipType:t.tooltipType,id:e}),b.createElement(uN,{type:`area`,id:e,data:t.data,dataKey:t.dataKey,xAxisId:t.xAxisId,yAxisId:t.yAxisId,zAxisId:0,stackId:Ld(t.stackId),hide:t.hide,barSize:void 0,baseValue:t.baseValue,isPanorama:n,connectNulls:t.connectNulls}),b.createElement(hL,XI({},t,{id:e}))))}var yL=b.memo(vL,Rp);yL.displayName=`Area`;var bL=`Invariant failed`;function xL(e,t){if(!e)throw Error(bL)}var SL=[`option`];function CL(e,t){if(e==null)return{};var n,r,i=wL(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function wL(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}var TL=mg;function EL(e){var t=e.option,n=CL(e,SL);return b.createElement(yM,{option:t,DefaultShape:TL,shapeProps:n,activeClassName:`recharts-active-bar`,inActiveClassName:`recharts-inactive-bar`})}var DL=function(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0;return(n,r)=>{if(U(e))return e;var i=U(n)||Fa(n);return i?e(n,r):(!i&&xL(!1,`minPointSize callback function received a value with type of ${typeof n}. Currently only numbers or null/undefined are supported.`),t)}},OL=(e,t,n)=>n,kL=K([Mw,(e,t)=>t],(e,t)=>e.filter(e=>e.type===`bar`).find(e=>e.id===t)),AL=K([kL],e=>e?.maxBarSize),jL=(e,t,n,r)=>r,ML=K([cp,Mw,DI,OI,OL],(e,t,n,r,i)=>t.filter(t=>e===`horizontal`?t.xAxisId===n:t.yAxisId===r).filter(e=>e.isPanorama===i).filter(e=>e.hide===!1).filter(e=>e.type===`bar`)),NL=(e,t,n)=>{var r=cp(e),i=DI(e,t),a=OI(e,t);if(i!=null&&a!=null)return r===`horizontal`?iT(e,`yAxis`,a,n):iT(e,`xAxis`,i,n)},PL=K([ML,A_,(e,t)=>{var n=cp(e),r=DI(e,t),i=OI(e,t);if(r!=null&&i!=null)return n===`horizontal`?_E(e,`xAxis`,r):_E(e,`yAxis`,i)}],nP),FL=(e,t,n)=>{var r=kL(e,t);if(r==null)return 0;var i=DI(e,t),a=OI(e,t);if(i==null||a==null)return 0;var o=cp(e),s=D_(e),c=r.maxBarSize,l=Fa(c)?s:c,u,d;return o===`horizontal`?(u=CE(e,`xAxis`,i,n),d=SE(e,`xAxis`,i,n)):(u=CE(e,`yAxis`,a,n),d=SE(e,`yAxis`,a,n)),Kd(u,d,!0)??l??0},IL=(e,t,n)=>{var r=cp(e),i=DI(e,t),a=OI(e,t);if(i!=null&&a!=null){var o,s;return r===`horizontal`?(o=CE(e,`xAxis`,i,n),s=SE(e,`xAxis`,i,n)):(o=CE(e,`yAxis`,a,n),s=SE(e,`yAxis`,a,n)),Kd(o,s)}},LL=K([hf,_f,(e,t,n)=>{var r=DI(e,t);if(r!=null)return CE(e,`xAxis`,r,n)},(e,t,n)=>{var r=OI(e,t);if(r!=null)return CE(e,`yAxis`,r,n)},(e,t,n)=>{var r=DI(e,t);if(r!=null)return SE(e,`xAxis`,r,n)},(e,t,n)=>{var r=OI(e,t);if(r!=null)return SE(e,`yAxis`,r,n)},K([K([PL,D_,O_,k_,FL,IL,AL],lP),kL],dP),cp,$g,IL,K([NL,kL],uP),kL,jL],(e,t,n,r,i,a,o,s,c,l,u,d,f)=>{var p=c.chartData,m=c.dataStartIndex,h=c.dataEndIndex;if(!(d==null||o==null||t==null||s!==`horizontal`&&s!==`vertical`||n==null||r==null||i==null||a==null||l==null)){var g=d.data,_=g!=null&&g.length>0?g:p?.slice(m,h+1);if(_!=null)return ER({layout:s,barSettings:d,pos:o,parentViewBox:t,bandSize:l,xAxis:n,yAxis:r,xAxisTicks:i,yAxisTicks:a,stackedData:u,displayedData:_,offset:e,cells:f,dataStartIndex:m})}}),RL=[`index`];function zL(){return zL=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},zL.apply(null,arguments)}function BL(e,t){if(e==null)return{};var n,r,i=VL(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function VL(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}var HL=(0,b.createContext)(void 0),UL=e=>{var t=(0,b.useContext)(HL);if(t!=null)return t.stackId;if(e!=null)return Ld(e)},WL=(e,t)=>`recharts-bar-stack-clip-path-${e}-${t}`,GL=e=>{var t=(0,b.useContext)(HL);if(t!=null){var n=t.stackId;return`url(#${WL(n,e)})`}},KL=e=>{var t=e.index,n=BL(e,RL),r=GL(t);return b.createElement(pa,zL({className:`recharts-bar-stack-layer`,clipPath:r},n))},qL=[`onMouseEnter`,`onMouseLeave`,`onClick`],JL=[`value`,`background`,`tooltipPosition`],YL=[`id`],XL=[`onMouseEnter`,`onClick`,`onMouseLeave`];function ZL(e,t){return nR(e)||tR(e,t)||$L(e,t)||QL()}function QL(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
61
61
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function $L(e,t){if(e){if(typeof e==`string`)return eR(e,t);var n={}.toString.call(e).slice(8,-1);return n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`?Array.from(e):n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?eR(e,t):void 0}}function eR(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function tR(e,t){var n=e==null?null:typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(n!=null){var r,i,a,o,s=[],c=!0,l=!1;try{if(a=(n=n.call(e)).next,t===0){if(Object(n)!==n)return;c=!1}else for(;!(c=(r=a.call(n)).done)&&(s.push(r.value),s.length!==t);c=!0);}catch(e){l=!0,i=e}finally{try{if(!c&&n.return!=null&&(o=n.return(),Object(o)!==o))return}finally{if(l)throw i}}return s}}function nR(e){if(Array.isArray(e))return e}function rR(){return rR=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},rR.apply(null,arguments)}function iR(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function aR(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?iR(Object(n),!0).forEach(function(t){oR(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):iR(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function oR(e,t,n){return(t=sR(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function sR(e){var t=cR(e,`string`);return typeof t==`symbol`?t:t+``}function cR(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function lR(e,t){if(e==null)return{};var n,r,i=uR(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function uR(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}var dR=e=>{var t=e.dataKey,n=e.name,r=e.fill,i=e.legendType;return[{inactive:e.hide,dataKey:t,type:i,color:r,value:Jd(n,t),payload:e}]},fR=b.memo(e=>{var t=e.dataKey,n=e.stroke,r=e.strokeWidth,i=e.fill,a=e.name,o=e.hide,s=e.unit,c=e.formatter,l=e.tooltipType,u=e.id,d={dataDefinedOnItem:void 0,getPosition:Ra,settings:{stroke:n,strokeWidth:r,fill:i,dataKey:t,nameKey:void 0,name:Jd(a,t),hide:o,type:l,color:i,unit:s,formatter:c,graphicalItemId:u}};return b.createElement(CM,{tooltipEntrySettings:d})});function pR(e){var t=G(KD),n=e.data,r=e.dataKey,i=e.background,a=e.allOtherBarProps,o=a.onMouseEnter,s=a.onMouseLeave,c=a.onClick,l=lR(a,qL),u=bM(o,r,a.id),d=xM(s),f=SM(c,r,a.id);if(!i||n==null)return null;var p=ta(i);return b.createElement(XO,{zIndex:fP(i,R_.barBackground)},n.map((e,n)=>{e.value;var a=e.background;e.tooltipPosition;var o=lR(e,JL);if(!a)return null;var s=u(e,e.originalDataIndex),c=d(e,e.originalDataIndex),m=f(e,e.originalDataIndex),h=aR(aR(aR(aR(aR({option:i,isActive:String(e.originalDataIndex)===t},o),{},{fill:`#eee`},a),p),Zo(l,e,n)),{},{onMouseEnter:s,onMouseLeave:c,onClick:m,dataKey:r,index:n,className:`recharts-bar-background-rectangle`});return b.createElement(EL,rR({key:`background-bar-${n}`},h))}))}function mR(e){var t=e.showLabels,n=e.children,r=e.rects?.map(e=>{var t={x:e.x,y:e.y,width:e.width,lowerWidth:e.width,upperWidth:e.width,height:e.height};return aR(aR({},t),{},{value:e.value,payload:e.payload,parentViewBox:e.parentViewBox,viewBox:t,fill:e.fill})});return b.createElement(Uj,{value:t?r:void 0},n)}function hR(e){var t=e.shape,n=e.activeBar,r=e.baseProps,i=e.entry,a=e.index,o=e.dataKey,s=G(KD),c=G(JD),l=n&&String(i.originalDataIndex)===s&&(c==null||o===c),u=s!=null&&(String(i.originalDataIndex)!==s||c!=null&&o!==c),d=ZL((0,b.useState)(!1),2),f=d[0],p=d[1],m=ZL((0,b.useState)(!1),2),h=m[0],g=m[1];(0,b.useEffect)(()=>{var e;return l?(p(!0),e=requestAnimationFrame(()=>{g(!0)})):(g(!1),u&&p(!1)),()=>{cancelAnimationFrame(e)}},[l,u]);var _=(0,b.useCallback)(()=>{l||p(!1)},[l]),v=l&&h,y=l||f,x=l?n===!0?t:n:t,S=b.createElement(EL,rR({},r,{name:String(r.name)},i,{isActive:v,option:x,index:a,dataKey:o,animationElapsedTime:e.animationElapsedTime,isAnimating:e.isAnimating,isEntrance:e.isEntrance,onTransitionEnd:_}));return y?b.createElement(XO,{zIndex:R_.activeBar},b.createElement(KL,{index:i.originalDataIndex},S)):S}function gR(e){var t=e.shape,n=e.baseProps,r=e.entry,i=e.index,a=e.dataKey;return b.createElement(EL,rR({},n,{name:String(n.name)},r,{isActive:!1,option:t,index:i,dataKey:a,animationElapsedTime:e.animationElapsedTime,isAnimating:e.isAnimating,isEntrance:e.isEntrance}))}function _R(e){var t=e.data,n=e.props,r=e.animationElapsedTime,i=e.isAnimating,a=e.isEntrance,o=ea(n)??{},s=o.id,c=lR(o,YL),l=n.shape,u=n.dataKey,d=n.activeBar,f=n.onMouseEnter,p=n.onClick,m=n.onMouseLeave,h=lR(n,XL),g=bM(f,u,s),_=xM(m),v=SM(p,u,s);return t?b.createElement(b.Fragment,null,t.map((e,t)=>b.createElement(KL,rR({index:e.originalDataIndex,key:`rectangle-${e?.x}-${e?.y}-${e?.value}-${t}`,className:`recharts-bar-rectangle`},Zo(h,e,t),{onMouseEnter:g(e,e.originalDataIndex),onMouseLeave:_(e,e.originalDataIndex),onClick:v(e,e.originalDataIndex)}),d?b.createElement(hR,{shape:l,activeBar:d,baseProps:c,entry:e,index:t,dataKey:u,animationElapsedTime:r,isAnimating:i,isEntrance:a}):b.createElement(gR,{shape:l,baseProps:c,entry:e,index:t,dataKey:u,animationElapsedTime:r,isAnimating:i,isEntrance:a})))):null}var vR=(e,t,n)=>e==null?[]:t===1?e.flatMap(e=>e.status===`removed`?[]:[e.next]):e.flatMap(e=>{if(e.status===`removed`)return n===`horizontal`?[aR(aR({},e.prev),{},{height:Na(e.prev.height,0,t),y:Na(e.prev.y,e.prev.y+e.prev.height,t)})]:[aR(aR({},e.prev),{},{width:Na(e.prev.width,0,t)})];if(e.status===`matched`)return[aR(aR({},e.next),{},{x:Na(e.prev.x,e.next.x,t),y:Na(e.prev.y,e.next.y,t),width:Na(e.prev.width,e.next.width,t),height:Na(e.prev.height,e.next.height,t)})];var r=e.next;return n===`horizontal`?[aR(aR({},r),{},{height:Na(0,r.height,t),y:Na(r.stackedBarStart,r.y,t)})]:[aR(aR({},r),{},{width:Na(0,r.width,t),x:Na(r.stackedBarStart,r.x,t)})]});function yR(e){var t=e.props,n=e.previousRectanglesRef,r=t.data,i=t.isAnimationActive,a=t.animationBegin,o=t.animationDuration,s=t.animationEasing,c=t.animationInterpolateFn,l=t.layout,u=KM(t.onAnimationStart,t.onAnimationEnd),d=u.isAnimating,f=u.handleAnimationStart,p=u.handleAnimationEnd;return b.createElement(mR,{showLabels:!d,rects:r},b.createElement(qM,{animationInput:r,animationIdPrefix:`recharts-bar-`,items:r,previousItemsRef:n,isAnimationActive:i,animationBegin:a,animationDuration:o,animationEasing:s,onAnimationStart:f,onAnimationEnd:p,animationInterpolateFn:c,animationMatchBy:t.animationMatchBy,layout:l},(e,n,r)=>b.createElement(pa,null,b.createElement(_R,{props:t,data:e,animationElapsedTime:n,isAnimating:d||n<1,isEntrance:r}))),b.createElement(Jj,{label:t.label}),t.children)}function bR(e){var t=(0,b.useRef)(null);return b.createElement(yR,{previousRectanglesRef:t,props:e})}var xR=0,SR=(e,t)=>{var n=Array.isArray(e.value)?e.value[1]:e.value;return{x:e.x,y:e.y,value:n,errorVal:kd(e,t)}},CR=class extends b.PureComponent{render(){var e=this.props,t=e.hide,n=e.data,r=e.dataKey,i=e.className,a=e.xAxisId,o=e.yAxisId,s=e.needClip,c=e.background,l=e.id;if(t||n==null)return null;var u=Ji(`recharts-bar`,i),d=l;return b.createElement(pa,{className:u,id:l},s&&b.createElement(`defs`,null,b.createElement(TI,{clipPathId:d,xAxisId:a,yAxisId:o})),b.createElement(pa,{className:`recharts-bar-rectangles`,clipPath:s?`url(#clipPath-${d})`:void 0},b.createElement(pR,{data:n,dataKey:r,background:c,allOtherBarProps:this.props}),b.createElement(bR,this.props)))}},wR={activeBar:!1,animationBegin:0,animationDuration:400,animationEasing:`ease`,animationInterpolateFn:vR,animationMatchBy:MM,background:!1,hide:!1,isAnimationActive:`auto`,label:!1,legendType:`rect`,minPointSize:xR,shape:TL,xAxisId:0,yAxisId:0,zIndex:R_.bar};function TR(e){var t=e.xAxisId,n=e.yAxisId,r=e.hide,i=e.legendType,a=e.minPointSize,o=e.activeBar,s=e.animationBegin,c=e.animationDuration,l=e.animationEasing,u=e.isAnimationActive,d=wI(t,n).needClip,f=lp(),p=yf(),m=sM(e.children,Xk),h=G(t=>LL(t,e.id,p,m));if(f!==`vertical`&&f!==`horizontal`)return null;var g,_=h?.[0];return g=_==null||_.height==null||_.width==null?0:f===`vertical`?_.height/2:_.width/2,b.createElement(CI,{xAxisId:t,yAxisId:n,data:h,dataPointFormatter:SR,errorBarOffset:g},b.createElement(CR,rR({},e,{layout:f,needClip:d,data:h,xAxisId:t,yAxisId:n,hide:r,legendType:i,minPointSize:a,activeBar:o,animationBegin:s,animationDuration:c,animationEasing:l,isAnimationActive:u})))}function ER(e){var t=e.layout,n=e.barSettings,r=n.dataKey,i=n.minPointSize,a=n.hasCustomShape,o=e.pos,s=e.bandSize,c=e.xAxis,l=e.yAxis,u=e.xAxisTicks,d=e.yAxisTicks,f=e.stackedData,p=e.displayedData,m=e.offset,h=e.cells,g=e.parentViewBox,_=e.dataStartIndex,v=t===`horizontal`?l:c,y=f?v.scale.domain():null,b=Bd({numericAxis:v}),x=v.scale.map(b);return p.map((e,n)=>{var p,v,S,C,w,T;if(f){var E=f[n+_];if(E==null)return null;p=Pd(E,y)}else p=kd(e,r),Array.isArray(p)||(p=[b,p]);var D=DL(i,xR)(p[1],n);if(t===`horizontal`){var O=l.scale.map(p[0]),k=l.scale.map(p[1]);if(O==null||k==null)return null;v=zd({axis:c,ticks:u,bandSize:s,offset:o.offset,entry:e,index:n}),S=k??O??void 0,C=o.size;var A=O-k;if(w=Ea(A)?0:A,T={x:v,y:m.top,width:C,height:m.height},Math.abs(D)>0&&Math.abs(w)<Math.abs(D)){var j=Ta(w||D)*(Math.abs(D)-Math.abs(w));S-=j,w+=j}}else{var M=c.scale.map(p[0]),N=c.scale.map(p[1]);if(M==null||N==null)return null;if(v=M,S=zd({axis:l,ticks:d,bandSize:s,offset:o.offset,entry:e,index:n}),C=N-M,w=o.size,T={x:m.left,y:S,width:m.width,height:w},Math.abs(D)>0&&Math.abs(C)<Math.abs(D)){var ee=Ta(C||D)*(Math.abs(D)-Math.abs(C));C+=ee}}return v==null||S==null||C==null||w==null||!a&&(C===0||w===0)?null:aR(aR({},e),{},{stackedBarStart:x,x:v,y:S,width:C,height:w,value:f?p:p[1],payload:e,background:T,tooltipPosition:{x:v+C/2,y:S+w/2},parentViewBox:g,originalDataIndex:n},h&&h[n]&&h[n].props)}).filter(Boolean)}function DR(e){var t=rs(e,wR),n=UL(t.stackId),r=yf();return b.createElement(rN,{id:t.id,type:`bar`},e=>b.createElement(b.Fragment,null,b.createElement(wM,{legendPayload:dR(t)}),b.createElement(fR,{dataKey:t.dataKey,stroke:t.stroke,strokeWidth:t.strokeWidth,fill:t.fill,name:t.name,hide:t.hide,unit:t.unit,formatter:t.formatter,tooltipType:t.tooltipType,id:e}),b.createElement(uN,{type:`bar`,id:e,data:void 0,xAxisId:t.xAxisId,yAxisId:t.yAxisId,zAxisId:0,dataKey:t.dataKey,stackId:n,hide:t.hide,barSize:t.barSize,minPointSize:t.minPointSize,maxBarSize:t.maxBarSize,isPanorama:r,hasCustomShape:t.shape!=null&&t.shape!==TL}),b.createElement(XO,{zIndex:t.zIndex},b.createElement(TR,rR({},t,{id:e})))))}var OR=b.memo(DR,Rp);OR.displayName=`Bar`;var kR=[`domain`,`range`],AR=[`domain`,`range`];function jR(e,t){if(e==null)return{};var n,r,i=MR(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function MR(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}function NR(e,t){return e===t?!0:Array.isArray(e)&&e.length===2&&Array.isArray(t)&&t.length===2?e[0]===t[0]&&e[1]===t[1]:!1}function PR(e,t){if(e===t)return!0;var n=e.domain,r=e.range,i=jR(e,kR),a=t.domain,o=t.range,s=jR(t,AR);return!NR(n,a)||!NR(r,o)?!1:Rp(i,s)}var FR=[`type`],IR=[`dangerouslySetInnerHTML`,`ticks`,`scale`],LR=[`id`,`scale`];function RR(){return RR=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},RR.apply(null,arguments)}function zR(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function BR(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?zR(Object(n),!0).forEach(function(t){VR(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):zR(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function VR(e,t,n){return(t=HR(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function HR(e){var t=UR(e,`string`);return typeof t==`symbol`?t:t+``}function UR(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function WR(e,t){if(e==null)return{};var n,r,i=GR(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function GR(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}function KR(e){var t=Hs(),n=(0,b.useRef)(null),r=up(),i=e.type,a=WR(e,FR),o=H_(r,`xAxis`,i),s=(0,b.useMemo)(()=>{if(o!=null)return BR(BR({},a),{},{type:o})},[a,o]);return(0,b.useLayoutEffect)(()=>{s!=null&&(n.current===null?t(AN(s)):n.current!==s&&t(jN({prev:n.current,next:s})),n.current=s)},[s,t]),(0,b.useLayoutEffect)(()=>()=>{n.current&&=(t(MN(n.current)),null)},[t]),null}var qR=e=>{var t=e.xAxisId,n=e.className,r=e.height,i=e.label,a=(0,b.useRef)(null),o=(0,b.useRef)(null),s=G(_f),c=yf(),l=Hs(),u=`xAxis`,d=G(e=>xE(e,u,t,c)),f=G(e=>lE(e,t)),p=G(e=>mE(e,t)),m=G(e=>bw(e,t));if((0,b.useLayoutEffect)(()=>{if(!(r!==`auto`||!f||Ej(i)||(0,b.isValidElement)(i)||m==null)){var e=a.current;if(e){var n=e.getCalculatedHeight();Math.round(f.height)!==Math.round(n)&&l(LN({id:t,height:n}))}}},[d,f,l,i,t,r,m]),f==null||p==null||m==null)return null;e.dangerouslySetInnerHTML,e.ticks,e.scale;var h=WR(e,IR);m.id,m.scale;var g=WR(m,LR);return b.createElement(GF,RR({},h,g,{ref:a,labelRef:o,x:p.x,y:p.y,width:f.width,height:f.height,className:Ji(`recharts-${u} ${u}`,n),viewBox:s,ticks:d,axisType:u,axisId:t}))},JR={allowDataOverflow:yw.allowDataOverflow,allowDecimals:yw.allowDecimals,allowDuplicatedCategory:yw.allowDuplicatedCategory,angle:yw.angle,axisLine:IF.axisLine,height:yw.height,hide:!1,includeHidden:yw.includeHidden,interval:yw.interval,label:!1,minTickGap:yw.minTickGap,mirror:yw.mirror,orientation:yw.orientation,padding:yw.padding,reversed:yw.reversed,scale:yw.scale,tick:yw.tick,tickCount:yw.tickCount,tickLine:IF.tickLine,tickSize:IF.tickSize,type:yw.type,niceTicks:yw.niceTicks,xAxisId:0},YR=b.memo(e=>{var t=rs(e,JR);return b.createElement(b.Fragment,null,b.createElement(KR,{allowDataOverflow:t.allowDataOverflow,allowDecimals:t.allowDecimals,allowDuplicatedCategory:t.allowDuplicatedCategory,angle:t.angle,dataKey:t.dataKey,domain:t.domain,height:t.height,hide:t.hide,id:t.xAxisId,includeHidden:t.includeHidden,interval:t.interval,minTickGap:t.minTickGap,mirror:t.mirror,name:t.name,orientation:t.orientation,padding:t.padding,reversed:t.reversed,scale:t.scale,tick:t.tick,tickCount:t.tickCount,tickFormatter:t.tickFormatter,ticks:t.ticks,type:t.type,unit:t.unit,niceTicks:t.niceTicks}),b.createElement(qR,t))},PR);YR.displayName=`XAxis`;var XR=[`type`],ZR=[`dangerouslySetInnerHTML`,`ticks`,`scale`],QR=[`id`,`scale`];function $R(){return $R=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},$R.apply(null,arguments)}function ez(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function tz(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?ez(Object(n),!0).forEach(function(t){nz(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ez(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function nz(e,t,n){return(t=rz(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function rz(e){var t=iz(e,`string`);return typeof t==`symbol`?t:t+``}function iz(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function az(e,t){if(e==null)return{};var n,r,i=oz(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function oz(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}function sz(e){var t=Hs(),n=(0,b.useRef)(null),r=up(),i=e.type,a=az(e,XR),o=H_(r,`yAxis`,i),s=(0,b.useMemo)(()=>{if(o!=null)return tz(tz({},a),{},{type:o})},[o,a]);return(0,b.useLayoutEffect)(()=>{s!=null&&(n.current===null?t(NN(s)):n.current!==s&&t(PN({prev:n.current,next:s})),n.current=s)},[s,t]),(0,b.useLayoutEffect)(()=>()=>{n.current&&=(t(FN(n.current)),null)},[t]),null}function cz(e){var t=e.yAxisId,n=e.className,r=e.width,i=e.label,a=(0,b.useRef)(null),o=(0,b.useRef)(null),s=G(_f),c=yf(),l=Hs(),u=`yAxis`,d=G(e=>gE(e,t)),f=G(e=>hE(e,t)),p=G(e=>xE(e,u,t,c)),m=G(e=>Cw(e,t));if((0,b.useLayoutEffect)(()=>{if(!(r!==`auto`||!d||Ej(i)||(0,b.isValidElement)(i)||m==null)){var e=a.current;if(e){var n=e.getCalculatedWidth();Math.round(d.width)!==Math.round(n)&&l(IN({id:t,width:n}))}}},[p,d,l,i,t,r,m]),d==null||f==null||m==null)return null;e.dangerouslySetInnerHTML,e.ticks,e.scale;var h=az(e,ZR);m.id,m.scale;var g=az(m,QR);return b.createElement(GF,$R({},h,g,{ref:a,labelRef:o,x:f.x,y:f.y,tickTextProps:r===`auto`?{width:void 0}:{width:r},width:d.width,height:d.height,className:Ji(`recharts-${u} ${u}`,n),viewBox:s,ticks:p,axisType:u,axisId:t}))}var lz={allowDataOverflow:Sw.allowDataOverflow,allowDecimals:Sw.allowDecimals,allowDuplicatedCategory:Sw.allowDuplicatedCategory,angle:Sw.angle,axisLine:IF.axisLine,hide:!1,includeHidden:Sw.includeHidden,interval:Sw.interval,label:!1,minTickGap:Sw.minTickGap,mirror:Sw.mirror,orientation:Sw.orientation,padding:Sw.padding,reversed:Sw.reversed,scale:Sw.scale,tick:Sw.tick,tickCount:Sw.tickCount,tickLine:IF.tickLine,tickSize:IF.tickSize,type:Sw.type,niceTicks:Sw.niceTicks,width:Sw.width,yAxisId:0},uz=b.memo(e=>{var t=rs(e,lz);return b.createElement(b.Fragment,null,b.createElement(sz,{interval:t.interval,id:t.yAxisId,scale:t.scale,type:t.type,domain:t.domain,allowDataOverflow:t.allowDataOverflow,dataKey:t.dataKey,allowDuplicatedCategory:t.allowDuplicatedCategory,allowDecimals:t.allowDecimals,tickCount:t.tickCount,padding:t.padding,includeHidden:t.includeHidden,reversed:t.reversed,ticks:t.ticks,width:t.width,orientation:t.orientation,mirror:t.mirror,hide:t.hide,unit:t.unit,name:t.name,angle:t.angle,minTickGap:t.minTickGap,tick:t.tick,tickFormatter:t.tickFormatter,niceTicks:t.niceTicks}),b.createElement(cz,t))},PR);uz.displayName=`YAxis`;var dz=K([(e,t)=>t,cp,iv,pv,zD,VD,bO,hf],MO);function fz(e){return`getBBox`in e.currentTarget&&typeof e.currentTarget.getBBox==`function`}function pz(e){var t=e.currentTarget.getBoundingClientRect(),n,r;if(fz(e)){var i=e.currentTarget.getBBox();n=i.width>0?t.width/i.width:1,r=i.height>0?t.height/i.height:1}else{var a=e.currentTarget;n=a.offsetWidth>0?t.width/a.offsetWidth:1,r=a.offsetHeight>0?t.height/a.offsetHeight:1}var o=(e,i)=>({relativeX:Math.round((e-t.left)/n),relativeY:Math.round((i-t.top)/r)});return`touches`in e?Array.from(e.touches).map(e=>o(e.clientX,e.clientY)):o(e.clientX,e.clientY)}var mz=ou(`mouseClick`),hz=md();hz.startListening({actionCreator:mz,effect:(e,t)=>{var n=e.payload,r=dz(t.getState(),pz(n));r?.activeIndex!=null&&t.dispatch(WE({activeIndex:r.activeIndex,activeDataKey:void 0,activeCoordinate:r.activeCoordinate}))}});var gz=ou(`mouseMove`),_z=md(),vz=null,yz=null,bz=null;_z.startListening({actionCreator:gz,effect:(e,t)=>{var n=e.payload,r=t.getState().eventSettings,i=r.throttleDelay,a=r.throttledEvents,o=a===`all`||a?.includes(`mousemove`);vz!==null&&(cancelAnimationFrame(vz),vz=null),yz!==null&&(typeof i!=`number`||!o)&&(clearTimeout(yz),yz=null),bz=pz(n);var s=()=>{var e=t.getState(),n=OE(e,e.tooltip.settings.shared);if(!bz){vz=null,yz=null;return}if(n===`axis`){var r=dz(e,bz);r?.activeIndex==null?t.dispatch(VE()):t.dispatch(UE({activeIndex:r.activeIndex,activeDataKey:void 0,activeCoordinate:r.activeCoordinate}))}vz=null,yz=null};if(!o){s();return}i===`raf`?vz=requestAnimationFrame(s):typeof i==`number`&&yz===null&&(yz=setTimeout(s,i))}});function xz(e,t){return t instanceof HTMLElement?`HTMLElement <${t.tagName} class="${t.className}">`:t===window?`global.window`:e===`children`&&typeof t==`object`&&t?`<<CHILDREN>>`:t}var Sz={accessibilityLayer:!0,barCategoryGap:`10%`,barGap:4,barSize:void 0,className:void 0,maxBarSize:void 0,stackOffset:`none`,syncId:void 0,syncMethod:`index`,baseValue:void 0,reverseStackOrder:!1},Cz=Ou({name:`rootProps`,initialState:Sz,reducers:{updateOptions:(e,t)=>{e.accessibilityLayer=t.payload.accessibilityLayer,e.barCategoryGap=t.payload.barCategoryGap,e.barGap=t.payload.barGap??Sz.barGap,e.barSize=t.payload.barSize,e.maxBarSize=t.payload.maxBarSize,e.stackOffset=t.payload.stackOffset,e.syncId=t.payload.syncId,e.syncMethod=t.payload.syncMethod,e.className=t.payload.className,e.baseValue=t.payload.baseValue,e.reverseStackOrder=t.payload.reverseStackOrder}}}),wz=Cz.reducer,Tz=Cz.actions.updateOptions,Ez=Ou({name:`polarOptions`,initialState:null,reducers:{updatePolarOptions:(e,t)=>e===null?t.payload:(e.startAngle=t.payload.startAngle,e.endAngle=t.payload.endAngle,e.cx=t.payload.cx,e.cy=t.payload.cy,e.innerRadius=t.payload.innerRadius,e.outerRadius=t.payload.outerRadius,e)}});Ez.actions.updatePolarOptions;var Dz=Ez.reducer,Oz=ou(`keyDown`),kz=ou(`focus`),Az=ou(`blur`),jz=md(),Mz=null,Nz=null,Pz=null;jz.startListening({actionCreator:Oz,effect:(e,t)=>{Pz=e.payload,Mz!==null&&(cancelAnimationFrame(Mz),Mz=null);var n=t.getState().eventSettings,r=n.throttleDelay,i=n.throttledEvents,a=i===`all`||i.includes(`keydown`);Nz!==null&&(typeof r!=`number`||!a)&&(clearTimeout(Nz),Nz=null);var o=()=>{try{var e=t.getState();if(e.rootProps.accessibilityLayer===!1)return;var n=e.tooltip.keyboardInteraction,r=Pz;if(r!==`ArrowRight`&&r!==`ArrowLeft`&&r!==`Enter`)return;var i=aD(n,DD(e),tT(e),ID(e)),a=i==null?-1:Number(i),o=!Number.isFinite(a)||a<0,s=VD(e),c=DD(e),l=OE(e,e.tooltip.settings.shared);if(r===`Enter`){if(o)return;var u=TO(e,l,`hover`,String(n.index));t.dispatch(KE({active:!n.active,activeIndex:n.index,activeCoordinate:u}));return}var d=wE(e)===`left-to-right`?1:-1,f=r===`ArrowRight`?1:-1,p;if(o){var m=tT(e),h=ID(e),g=f*d,_=e=>({active:!1,index:String(e),dataKey:void 0,graphicalItemId:void 0,coordinate:void 0});if(p=-1,g>0){for(var v=0;v<c.length;v++)if(aD(_(v),c,m,h)!=null){p=v;break}}else for(var y=c.length-1;y>=0;y--)if(aD(_(y),c,m,h)!=null){p=y;break}if(p<0)return}else{p=a+f*d;var b=s?.length||c.length;if(b===0||p>=b||p<0)return}var x=TO(e,l,`hover`,String(p));t.dispatch(KE({active:!0,activeIndex:p.toString(),activeCoordinate:x}))}finally{Mz=null,Nz=null}};if(!a){o();return}r===`raf`?Mz=requestAnimationFrame(o):typeof r==`number`&&Nz===null&&(o(),Pz=null,Nz=setTimeout(()=>{Pz?o():(Nz=null,Mz=null)},r))}}),jz.startListening({actionCreator:kz,effect:(e,t)=>{var n=t.getState();if(n.rootProps.accessibilityLayer!==!1){var r=n.tooltip.keyboardInteraction;if(!r.active&&r.index==null){var i=`0`,a=TO(n,OE(n,n.tooltip.settings.shared),`hover`,String(i));t.dispatch(KE({active:!0,activeIndex:i,activeCoordinate:a}))}}}}),jz.startListening({actionCreator:Az,effect:(e,t)=>{var n=t.getState();if(n.rootProps.accessibilityLayer!==!1){var r=n.tooltip.keyboardInteraction;r.active&&t.dispatch(KE({active:!1,activeIndex:r.index,activeCoordinate:r.coordinate}))}}});function Fz(e){e.persist();var t=e.currentTarget;return new Proxy(e,{get:(e,n)=>{if(n===`currentTarget`)return t;var r=Reflect.get(e,n);return typeof r==`function`?r.bind(e):r}})}var Iz=ou(`externalEvent`),Lz=md(),Rz=new Map,zz=new Map,Bz=new Map;Lz.startListening({actionCreator:Iz,effect:(e,t)=>{var n=e.payload,r=n.handler,i=n.reactEvent;if(r!=null){var a=i.type,o=Fz(i);Bz.set(a,{handler:r,reactEvent:o});var s=Rz.get(a);s!==void 0&&(cancelAnimationFrame(s),Rz.delete(a));var c=t.getState().eventSettings,l=c.throttleDelay,u=c.throttledEvents,d=u===`all`||u?.includes(a),f=zz.get(a);f!==void 0&&(typeof l!=`number`||!d)&&(clearTimeout(f),zz.delete(a));var p=()=>{var e=Bz.get(a);try{if(!e)return;var n=e.handler,r=e.reactEvent,i=t.getState(),o={activeCoordinate:ZD(i),activeDataKey:JD(i),activeIndex:KD(i),activeLabel:qD(i),activeTooltipIndex:KD(i),isTooltipActive:QD(i)};n&&n(o,r)}finally{Rz.delete(a),zz.delete(a),Bz.delete(a)}};if(!d){p();return}if(l===`raf`){var m=requestAnimationFrame(p);Rz.set(a,m)}else if(typeof l==`number`){if(!zz.has(a)){p();var h=setTimeout(p,l);zz.set(a,h)}}else p()}}});var Vz=K([K([lD],e=>e.tooltipItemPayloads),(e,t)=>t,(e,t,n)=>n],(e,t,n)=>{if(t!=null){var r=e.find(e=>e.settings.graphicalItemId===n);if(r!=null){var i=r.getPosition;if(i!=null)return i(t)}}}),Hz=ou(`touchMove`),Uz=md(),Wz=null,Gz=null,Kz=null,qz=null;Uz.startListening({actionCreator:Hz,effect:(e,t)=>{var n=e.payload;if(n.touches!=null&&n.touches.length!==0){qz=Fz(n);var r=t.getState().eventSettings,i=r.throttleDelay,a=r.throttledEvents,o=a===`all`||a.includes(`touchmove`);Wz!==null&&(cancelAnimationFrame(Wz),Wz=null),Gz!==null&&(typeof i!=`number`||!o)&&(clearTimeout(Gz),Gz=null),Kz=Array.from(n.touches).map(e=>pz({clientX:e.clientX,clientY:e.clientY,currentTarget:n.currentTarget}));var s=()=>{if(qz!=null){var e=t.getState(),n=OE(e,e.tooltip.settings.shared);if(n===`axis`){var r=Kz?.[0];if(r==null){Wz=null,Gz=null;return}var i=dz(e,r);i?.activeIndex!=null&&t.dispatch(UE({activeIndex:i.activeIndex,activeDataKey:void 0,activeCoordinate:i.activeCoordinate}))}else if(n===`item`){var a=qz.touches[0];if(document.elementFromPoint==null||a==null)return;var o=document.elementFromPoint(a.clientX,a.clientY);if(!o||!o.getAttribute)return;var s=o.getAttribute(rf),c=o.getAttribute(`data-recharts-item-id`)??void 0,l=CD(e).find(e=>e.id===c);if(s==null||l==null||c==null)return;var u=l.dataKey,d=Vz(e,s,c);t.dispatch(zE({activeDataKey:u,activeIndex:s,activeCoordinate:d,activeGraphicalItemId:c}))}Wz=null,Gz=null}};if(!o){s();return}i===`raf`?Wz=requestAnimationFrame(s):typeof i==`number`&&Gz===null&&(s(),qz=null,Gz=setTimeout(()=>{qz?s():(Gz=null,Wz=null)},i))}}});var Jz={throttleDelay:`raf`,throttledEvents:[`mousemove`,`touchmove`,`pointermove`,`scroll`,`wheel`]},Yz=Ou({name:`eventSettings`,initialState:Jz,reducers:{setEventSettings:(e,t)=>{t.payload.throttleDelay!=null&&(e.throttleDelay=t.payload.throttleDelay),t.payload.throttledEvents!=null&&(e.throttledEvents=Y(t.payload.throttledEvents))}}}),Xz=Yz.actions.setEventSettings,Zz=Yz.reducer,Qz=Mc({brush:gP,cartesianAxis:RN,chartData:xk,errorBars:vI,eventSettings:Zz,graphicalItems:lN,layout:X,legend:yp,options:mk,polarAxis:$j,polarOptions:Dz,referenceElements:wP,renderedTicks:yF,rootProps:wz,tooltip:qE,zIndex:YO}),$z=function(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:`Chart`;return vu({reducer:Qz,preloadedState:e,middleware:e=>e({serializableCheck:!1,immutableCheck:![`commonjs`,`es6`,`production`].includes(`es6`)}).concat([hz.middleware,_z.middleware,jz.middleware,Lz.middleware,Uz.middleware]),enhancers:e=>{var t=e;return typeof e==`function`&&(t=e()),t.concat(gu({type:`raf`}))},devTools:sm.devToolsEnabled&&{serialize:{replacer:xz},name:`recharts-${t}`}})};function eB(e){var t=e.preloadedState,n=e.children,r=e.reduxStoreName,i=yf(),a=(0,b.useRef)(null);if(i)return n;a.current??=$z(t,r);var o=zs;return b.createElement(Fp,{context:o,store:a.current},n)}function tB(e){var t=e.layout,n=e.margin,r=Hs(),i=yf();return(0,b.useEffect)(()=>{i||(r(yd(t)),r(vd(n)))},[r,i,t,n]),null}var nB=(0,b.memo)(tB,Rp);function rB(e){var t=Hs();return(0,b.useEffect)(()=>{t(Tz(e))},[t,e]),null}var iB=(0,b.memo)(e=>{var t=Hs();return(0,b.useEffect)(()=>{t(Xz(e))},[t,e]),null},Rp);function aB(e){var t=e.zIndex,n=e.isPanorama,r=(0,b.useRef)(null),i=Hs();return(0,b.useLayoutEffect)(()=>(r.current&&i(qO({zIndex:t,element:r.current,isPanorama:n})),()=>{i(JO({zIndex:t,isPanorama:n}))}),[i,t,n]),b.createElement(`g`,{tabIndex:-1,ref:r,className:`recharts-zIndex-layer_${t}`})}function oB(e){var t=e.children,n=e.isPanorama,r=G(PO);if(!r||r.length===0)return t;var i=r.filter(e=>e<0),a=r.filter(e=>e>0);return b.createElement(b.Fragment,null,i.map(e=>b.createElement(aB,{key:e,zIndex:e,isPanorama:n})),t,a.map(e=>b.createElement(aB,{key:e,zIndex:e,isPanorama:n})))}var sB=[`children`];function cB(e,t){if(e==null)return{};var n,r,i=lB(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function lB(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}function uB(){return uB=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},uB.apply(null,arguments)}var dB={width:`100%`,height:`100%`,display:`block`},fB=(0,b.forwardRef)((e,t)=>{var n=op(),r=sp(),i=km();if(!Cd(n)||!Cd(r))return null;var a=e.children,o=e.otherAttributes,s=e.title,c=e.desc,l,u;return o!=null&&(l=typeof o.tabIndex==`number`?o.tabIndex:i?0:void 0,u=typeof o.role==`string`?o.role:i?`application`:void 0),b.createElement(ca,uB({},o,{title:s,desc:c,role:u,tabIndex:l,width:n,height:r,style:dB,ref:t}),a)}),pB=e=>{var t=e.children,n=G(xf);if(!n)return null;var r=n.width,i=n.height,a=n.y,o=n.x;return b.createElement(ca,{width:r,height:i,x:o,y:a},t)},mB=(0,b.forwardRef)((e,t)=>{var n=e.children,r=cB(e,sB);return yf()?b.createElement(pB,null,b.createElement(oB,{isPanorama:!0},n)):b.createElement(fB,uB({ref:t},r),b.createElement(oB,{isPanorama:!1},n))});function hB(e,t){return bB(e)||yB(e,t)||_B(e,t)||gB()}function gB(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
62
62
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function _B(e,t){if(e){if(typeof e==`string`)return vB(e,t);var n={}.toString.call(e).slice(8,-1);return n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`?Array.from(e):n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?vB(e,t):void 0}}function vB(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function yB(e,t){var n=e==null?null:typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(n!=null){var r,i,a,o,s=[],c=!0,l=!1;try{if(a=(n=n.call(e)).next,t===0){if(Object(n)!==n)return;c=!1}else for(;!(c=(r=a.call(n)).done)&&(s.push(r.value),s.length!==t);c=!0);}catch(e){l=!0,i=e}finally{try{if(!c&&n.return!=null&&(o=n.return(),Object(o)!==o))return}finally{if(l)throw i}}return s}}function bB(e){if(Array.isArray(e))return e}function xB(){var e=Hs(),t=hB((0,b.useState)(null),2),n=t[0],r=t[1],i=G($d);return(0,b.useEffect)(()=>{if(n!=null){var t=n.getBoundingClientRect().width/n.offsetWidth;Z(t)&&t!==i&&e(xd(t))}},[n,e,i]),r}function SB(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function CB(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?SB(Object(n),!0).forEach(function(t){wB(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):SB(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function wB(e,t,n){return(t=TB(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function TB(e){var t=EB(e,`string`);return typeof t==`symbol`?t:t+``}function EB(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function DB(){return DB=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},DB.apply(null,arguments)}function OB(e,t){return NB(e)||MB(e,t)||AB(e,t)||kB()}function kB(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
63
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function AB(e,t){if(e){if(typeof e==`string`)return jB(e,t);var n={}.toString.call(e).slice(8,-1);return n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`?Array.from(e):n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?jB(e,t):void 0}}function jB(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function MB(e,t){var n=e==null?null:typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(n!=null){var r,i,a,o,s=[],c=!0,l=!1;try{if(a=(n=n.call(e)).next,t===0){if(Object(n)!==n)return;c=!1}else for(;!(c=(r=a.call(n)).done)&&(s.push(r.value),s.length!==t);c=!0);}catch(e){l=!0,i=e}finally{try{if(!c&&n.return!=null&&(o=n.return(),Object(o)!==o))return}finally{if(l)throw i}}return s}}function NB(e){if(Array.isArray(e))return e}var PB=()=>(Mk(),null);function FB(e){if(typeof e==`number`)return e;if(typeof e==`string`){var t=parseFloat(e);if(!Number.isNaN(t))return t}return 0}var IB=(0,b.forwardRef)((e,t)=>{var n=(0,b.useRef)(null),r=OB((0,b.useState)({containerWidth:FB(e.style?.width),containerHeight:FB(e.style?.height)}),2),i=r[0],a=r[1],o=(0,b.useCallback)((e,t)=>{a(n=>{var r=Math.round(e),i=Math.round(t);return n.containerWidth===r&&n.containerHeight===i?n:{containerWidth:r,containerHeight:i}})},[]),s=(0,b.useCallback)(e=>{if(typeof t==`function`&&t(e),n.current!=null&&(n.current.disconnect(),n.current=null),e!=null&&typeof ResizeObserver<`u`){var r=e.getBoundingClientRect(),i=r.width,a=r.height;o(i,a);var s=new ResizeObserver(e=>{var t=e[0];if(t!=null){var n=t.contentRect,r=n.width,i=n.height;o(r,i)}});s.observe(e),n.current=s}},[t,o]);return(0,b.useEffect)(()=>()=>{n.current?.disconnect()},[o]),b.createElement(b.Fragment,null,b.createElement(pp,{width:i.containerWidth,height:i.containerHeight}),b.createElement(`div`,DB({ref:s},e)))}),LB=(0,b.forwardRef)((e,t)=>{var n=e.width,r=e.height,i=OB((0,b.useState)({containerWidth:FB(n),containerHeight:FB(r)}),2),a=i[0],o=i[1],s=(0,b.useCallback)((e,t)=>{o(n=>{var r=Math.round(e),i=Math.round(t);return n.containerWidth===r&&n.containerHeight===i?n:{containerWidth:r,containerHeight:i}})},[]),c=(0,b.useCallback)(e=>{if(typeof t==`function`&&t(e),e!=null){var n=e.getBoundingClientRect(),r=n.width,i=n.height;s(r,i)}},[t,s]);return b.createElement(b.Fragment,null,b.createElement(pp,{width:a.containerWidth,height:a.containerHeight}),b.createElement(`div`,DB({ref:c},e)))}),RB=(0,b.forwardRef)((e,t)=>{var n=e.width,r=e.height;return b.createElement(b.Fragment,null,b.createElement(pp,{width:n,height:r}),b.createElement(`div`,DB({ref:t},e)))}),zB=(0,b.forwardRef)((e,t)=>{var n=e.width,r=e.height;return typeof n==`string`||typeof r==`string`?b.createElement(LB,DB({},e,{ref:t})):typeof n==`number`&&typeof r==`number`?b.createElement(RB,DB({},e,{width:n,height:r,ref:t})):b.createElement(b.Fragment,null,b.createElement(pp,{width:n,height:r}),b.createElement(`div`,DB({ref:t},e)))});function BB(e){return e?IB:zB}var VB=(0,b.forwardRef)((e,t)=>{var n=e.children,r=e.className,i=e.height,a=e.onClick,o=e.onContextMenu,s=e.onDoubleClick,c=e.onMouseDown,l=e.onMouseEnter,u=e.onMouseLeave,d=e.onMouseMove,f=e.onMouseUp,p=e.onTouchEnd,m=e.onTouchMove,h=e.onTouchStart,g=e.style,_=e.width,v=e.responsive,y=e.dispatchTouchEvents,x=y===void 0||y,S=(0,b.useRef)(null),C=Hs(),w=OB((0,b.useState)(null),2),T=w[0],E=w[1],D=OB((0,b.useState)(null),2),O=D[0],k=D[1],A=xB(),j=ep(),M=j?.width>0?j.width:_,N=j?.height>0?j.height:i,ee=(0,b.useCallback)(e=>{A(e),typeof t==`function`&&t(e),E(e),k(e),e!=null&&(S.current=e)},[A,t,E,k]),te=(0,b.useCallback)(e=>{C(mz(e)),C(Iz({handler:a,reactEvent:e}))},[C,a]),P=(0,b.useCallback)(e=>{C(gz(e)),C(Iz({handler:l,reactEvent:e}))},[C,l]),F=(0,b.useCallback)(e=>{C(VE()),C(Iz({handler:u,reactEvent:e}))},[C,u]),ne=(0,b.useCallback)(e=>{C(gz(e)),C(Iz({handler:d,reactEvent:e}))},[C,d]),re=(0,b.useCallback)(()=>{C(kz())},[C]),ie=(0,b.useCallback)(()=>{C(Az())},[C]),ae=(0,b.useCallback)(e=>{C(Oz(e.key))},[C]),oe=(0,b.useCallback)(e=>{C(Iz({handler:o,reactEvent:e}))},[C,o]),I=(0,b.useCallback)(e=>{C(Iz({handler:s,reactEvent:e}))},[C,s]),se=(0,b.useCallback)(e=>{C(Iz({handler:c,reactEvent:e}))},[C,c]),ce=(0,b.useCallback)(e=>{C(Iz({handler:f,reactEvent:e}))},[C,f]),le=(0,b.useCallback)(e=>{C(Iz({handler:h,reactEvent:e}))},[C,h]),ue=(0,b.useCallback)(e=>{x&&C(Hz(e)),C(Iz({handler:m,reactEvent:e}))},[C,x,m]),de=(0,b.useCallback)(e=>{C(Iz({handler:p,reactEvent:e}))},[C,p]),fe=BB(v);return b.createElement(ok.Provider,{value:T},b.createElement(Ja.Provider,{value:O},b.createElement(fe,{width:M??g?.width,height:N??g?.height,className:Ji(`recharts-wrapper`,r),style:CB({position:`relative`,cursor:`default`,width:M,height:N},g),onClick:te,onContextMenu:oe,onDoubleClick:I,onFocus:re,onBlur:ie,onKeyDown:ae,onMouseDown:se,onMouseEnter:P,onMouseLeave:F,onMouseMove:ne,onMouseUp:ce,onTouchEnd:de,onTouchMove:ue,onTouchStart:le,ref:ee},b.createElement(PB,null),n)))}),HB=[`width`,`height`,`responsive`,`children`,`className`,`style`,`compact`,`title`,`desc`];function UB(e,t){if(e==null)return{};var n,r,i=WB(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function WB(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}var GB=(0,b.forwardRef)((e,t)=>{var n=e.width,r=e.height,i=e.responsive,a=e.children,o=e.className,s=e.style,c=e.compact,l=e.title,u=e.desc,d=ea(UB(e,HB));return c?b.createElement(b.Fragment,null,b.createElement(pp,{width:n,height:r}),b.createElement(mB,{otherAttributes:d,title:l,desc:u},a)):b.createElement(VB,{className:o,style:s,width:n,height:r,responsive:i??!1,onClick:e.onClick,onMouseLeave:e.onMouseLeave,onMouseEnter:e.onMouseEnter,onMouseMove:e.onMouseMove,onMouseDown:e.onMouseDown,onMouseUp:e.onMouseUp,onContextMenu:e.onContextMenu,onDoubleClick:e.onDoubleClick,onTouchStart:e.onTouchStart,onTouchMove:e.onTouchMove,onTouchEnd:e.onTouchEnd},b.createElement(mB,{otherAttributes:d,title:l,desc:u,ref:t},b.createElement(MP,null,a)))});function KB(){return KB=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},KB.apply(null,arguments)}function qB(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function JB(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?qB(Object(n),!0).forEach(function(t){YB(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):qB(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function YB(e,t,n){return(t=XB(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function XB(e){var t=ZB(e,`string`);return typeof t==`symbol`?t:t+``}function ZB(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}var QB=JB({accessibilityLayer:!0,barCategoryGap:`10%`,barGap:4,layout:`horizontal`,margin:{top:5,right:5,bottom:5,left:5},responsive:!1,reverseStackOrder:!1,stackOffset:`none`,syncMethod:`index`},Jz),$B=(0,b.forwardRef)(function(e,t){var n=rs(e.categoricalChartProps,QB),r=e.chartName,i=e.defaultTooltipEventType,a=e.validateTooltipEventTypes,o=e.tooltipPayloadSearcher,s=e.categoricalChartProps,c={chartName:r,defaultTooltipEventType:i,validateTooltipEventTypes:a,tooltipPayloadSearcher:o,eventEmitter:void 0};return b.createElement(eB,{preloadedState:{options:c},reduxStoreName:s.id??r},b.createElement(pP,{chartData:s.data}),b.createElement(nB,{layout:n.layout,margin:n.margin}),b.createElement(iB,{throttleDelay:n.throttleDelay,throttledEvents:n.throttledEvents}),b.createElement(rB,{baseValue:n.baseValue,accessibilityLayer:n.accessibilityLayer,barCategoryGap:n.barCategoryGap,maxBarSize:n.maxBarSize,stackOffset:n.stackOffset,barGap:n.barGap,barSize:n.barSize,syncId:n.syncId,syncMethod:n.syncMethod,className:n.className,reverseStackOrder:n.reverseStackOrder}),b.createElement(GB,KB({},n,{ref:t})))}),eV=[`axis`,`item`],tV=(0,b.forwardRef)((e,t)=>b.createElement($B,{chartName:`BarChart`,defaultTooltipEventType:`axis`,validateTooltipEventTypes:eV,tooltipPayloadSearcher:fk,categoricalChartProps:e,ref:t})),nV=[`axis`],rV=(0,b.forwardRef)((e,t)=>b.createElement($B,{chartName:`AreaChart`,defaultTooltipEventType:`axis`,validateTooltipEventTypes:nV,tooltipPayloadSearcher:fk,categoricalChartProps:e,ref:t}));function iV(){return typeof window>`u`||typeof window.matchMedia!=`function`?!1:!window.matchMedia(`(prefers-reduced-motion: reduce)`).matches}function aV(e,t={}){let{duration:n=800,decimals:r=0,enabled:i=!0,format:a}=t,o=i&&iV(),[s,c]=(0,b.useState)(()=>o?0:e),l=(0,b.useRef)(0);return(0,b.useEffect)(()=>{if(!o){c(e);return}let t=performance.now();function r(i){let a=i-t,o=Math.min(a/n,1),s=1-(1-o)**3;c(s*e),o<1&&(l.current=requestAnimationFrame(r))}return l.current=requestAnimationFrame(r),()=>{l.current&&cancelAnimationFrame(l.current)}},[e,n,o]),a?a(s):s.toFixed(r)}var oV={neutral:`text-ink-base`,good:`text-accent-green`,warn:`text-accent-amber`,bad:`text-accent-red`};function sV({label:e,value:t,sub:n,tone:r=`neutral`,hero:i=!1,animate:a=!1,numericValue:o,prefix:s=``,suffix:c=``,decimals:l=0,format:u}){let d=o!=null,f=aV(o??0,{decimals:l,enabled:a&&d,format:u}),p=a&&d?u?f:`${s}${f}${c}`:t,m=i?`text-3xl font-bold mt-1 tabular-nums gradient-text`:`text-3xl font-bold mt-1 tabular-nums ${oV[r]}`;return(0,x.jsxs)(`div`,{className:`px-1`,children:[(0,x.jsx)(`div`,{className:`text-[10px] text-ink-muted uppercase tracking-wider font-medium`,children:e}),(0,x.jsx)(`div`,{className:m,children:p}),n&&(0,x.jsx)(`div`,{className:`text-[10px] text-ink-muted mt-0.5`,children:n})]})}function cV({children:e,index:t=0,className:n=``}){let r=`${t*120}ms`;return(0,x.jsx)(`div`,{className:`animate-card-enter ${n}`,style:{animationDelay:r},children:e})}var lV=`var(--color-chart-block)`,uV=`var(--color-chart-block-peak)`,dV=10,fV=13;function pV({data:e,maxCount:t,ariaLabel:n}){let[r,i]=(0,b.useState)(null);if((0,b.useEffect)(()=>{if(!r)return;let e=()=>i(null);return window.addEventListener(`scroll`,e,{capture:!0}),window.addEventListener(`resize`,e),()=>{window.removeEventListener(`scroll`,e,{capture:!0}),window.removeEventListener(`resize`,e)}},[r]),e.length===0||e.every(e=>e.count===0))return null;let a=Math.max(t??0,...e.map(e=>e.count),1),o=a*12,s=e.length*fV;return(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(`svg`,{width:`100%`,height:o,role:`img`,"aria-label":n,viewBox:`0 0 ${s} ${o}`,preserveAspectRatio:`xMidYMax meet`,onMouseLeave:()=>i(null),children:e.map((e,t)=>{let n=[];for(let r=0;r<e.count;r++){let i=e.isPeak??e.count===a;n.push((0,x.jsx)(`rect`,{x:t*fV,y:o-(r+1)*12,width:dV,height:dV,rx:1,fill:i?uV:lV,className:`heatmap-cell`,style:{animationDelay:`${t*20+r*10}ms`}},`${t}-${r}`))}return(0,x.jsxs)(`g`,{onMouseEnter:t=>{let n=t.currentTarget,r=n.querySelectorAll(`rect.heatmap-cell`),a=(r[r.length-1]??n).getBoundingClientRect();i({x:a.left+a.width/2,y:a.top,text:e.tooltip})},children:[(0,x.jsx)(`rect`,{x:t*fV,y:0,width:fV,height:o,fill:`transparent`}),n]},t)})}),r&&(0,li.createPortal)((0,x.jsx)(`div`,{className:`fixed z-50 px-1.5 py-0.5 bg-bg-elevated border border-border-subtle text-[10px] text-ink-base rounded-md shadow-md pointer-events-none whitespace-nowrap tabular-nums`,style:{left:r.x,top:r.y,transform:`translate(-50%, calc(-100% - 4px))`},children:r.text}),document.body)]})}function mV(){return(0,x.jsxs)(`svg`,{width:`48`,height:`48`,viewBox:`0 0 48 48`,fill:`none`,"aria-hidden":`true`,children:[(0,x.jsx)(`circle`,{cx:`24`,cy:`24`,r:`20`,stroke:`var(--color-ink-muted)`,strokeWidth:`1`,opacity:`0.3`}),(0,x.jsx)(`circle`,{cx:`24`,cy:`24`,r:`13`,stroke:`var(--color-ink-muted)`,strokeWidth:`1`,opacity:`0.3`}),(0,x.jsx)(`circle`,{cx:`24`,cy:`24`,r:`6`,stroke:`var(--color-ink-muted)`,strokeWidth:`1`,opacity:`0.3`}),(0,x.jsx)(`line`,{x1:`24`,y1:`24`,x2:`24`,y2:`4`,stroke:`var(--color-accent-green)`,strokeWidth:`1.5`,strokeLinecap:`round`,className:`animate-radar-sweep`}),(0,x.jsx)(`circle`,{cx:`24`,cy:`24`,r:`2`,fill:`var(--color-accent-green)`})]})}function hV(){return(0,x.jsxs)(`svg`,{width:`48`,height:`48`,viewBox:`0 0 48 48`,fill:`none`,"aria-hidden":`true`,children:[(0,x.jsx)(`path`,{d:`M16 14 L6 24 L16 34`,stroke:`var(--color-ink-muted)`,strokeWidth:`1.5`,strokeLinecap:`round`,strokeLinejoin:`round`}),(0,x.jsx)(`path`,{d:`M32 14 L42 24 L32 34`,stroke:`var(--color-ink-muted)`,strokeWidth:`1.5`,strokeLinecap:`round`,strokeLinejoin:`round`}),(0,x.jsx)(`line`,{x1:`24`,y1:`18`,x2:`24`,y2:`30`,stroke:`var(--color-accent-green)`,strokeWidth:`2`,strokeLinecap:`round`,opacity:`0.8`})]})}function gV(){return(0,x.jsxs)(`svg`,{width:`48`,height:`48`,viewBox:`0 0 48 48`,fill:`none`,"aria-hidden":`true`,children:[(0,x.jsx)(`line`,{x1:`4`,y1:`24`,x2:`44`,y2:`24`,stroke:`var(--color-ink-muted)`,strokeWidth:`1`,opacity:`0.4`}),(0,x.jsx)(`circle`,{cx:`12`,cy:`24`,r:`3`,stroke:`var(--color-ink-muted)`,strokeWidth:`1.5`}),(0,x.jsx)(`circle`,{cx:`24`,cy:`24`,r:`3`,stroke:`var(--color-accent-green)`,strokeWidth:`1.5`}),(0,x.jsx)(`circle`,{cx:`36`,cy:`24`,r:`3`,stroke:`var(--color-ink-muted)`,strokeWidth:`1.5`}),(0,x.jsx)(`line`,{x1:`12`,y1:`16`,x2:`12`,y2:`20`,stroke:`var(--color-ink-muted)`,strokeWidth:`1`,strokeLinecap:`round`,opacity:`0.5`}),(0,x.jsx)(`line`,{x1:`24`,y1:`16`,x2:`24`,y2:`20`,stroke:`var(--color-accent-green)`,strokeWidth:`1`,strokeLinecap:`round`,opacity:`0.7`}),(0,x.jsx)(`line`,{x1:`36`,y1:`16`,x2:`36`,y2:`20`,stroke:`var(--color-ink-muted)`,strokeWidth:`1`,strokeLinecap:`round`,opacity:`0.5`})]})}function _V(){return(0,x.jsxs)(`svg`,{width:`48`,height:`48`,viewBox:`0 0 48 48`,fill:`none`,"aria-hidden":`true`,children:[(0,x.jsx)(`circle`,{cx:`24`,cy:`24`,r:`18`,stroke:`var(--color-ink-muted)`,strokeWidth:`1`,opacity:`0.3`}),(0,x.jsx)(`path`,{d:`M16 24 L22 30 L34 18`,stroke:`var(--color-accent-green)`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})]})}function vV(){return(0,x.jsxs)(`svg`,{width:`48`,height:`48`,viewBox:`0 0 48 48`,fill:`none`,"aria-hidden":`true`,children:[(0,x.jsx)(`circle`,{cx:`24`,cy:`24`,r:`18`,stroke:`var(--color-ink-muted)`,strokeWidth:`1`,opacity:`0.3`}),(0,x.jsx)(`path`,{d:`M24 14 L24 24 L31 28`,stroke:`var(--color-ink-subtle)`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})]})}var yV={radar:mV,code:hV,timeline:gV,checkmark:_V,clock:vV};function bV(){return(0,x.jsx)(`div`,{className:`flex items-center justify-center`,style:{width:48,height:48},"aria-hidden":`true`,children:(0,x.jsx)(`span`,{className:`rounded-full animate-pulse`,style:{width:10,height:10,backgroundColor:`var(--color-accent-green)`,boxShadow:`0 0 0 4px color-mix(in srgb, var(--color-accent-green) 15%, transparent)`}})})}function $({icon:e,title:t,subtitle:n,variant:r=`empty`}){let i=e===void 0?void 0:yV[e];return(0,x.jsxs)(`div`,{className:`py-8 flex flex-col items-center justify-center gap-3`,children:[r===`loading`?(0,x.jsx)(bV,{}):i&&(0,x.jsx)(i,{}),(0,x.jsx)(`span`,{className:`text-sm font-medium text-ink-subtle`,children:t}),n&&(0,x.jsx)(`span`,{className:`text-xs text-ink-muted text-center max-w-[240px]`,children:n})]})}function xV(e){return e===`Read`?`bg-accent-blue`:e===`Edit`||e===`Write`?`bg-accent-green`:e===`Bash`?`bg-accent-purple`:e===`Agent`?`bg-accent-teal`:`bg-ink-subtle`}var SV={thrashing:`Edit/Test Thrashing`,stuck_loop:`Stuck Loop`,blind_editing:`Blind Editing`,re_reading:`Repeated Reads`};function CV(e){let t=Math.floor(e/1e3),n=Math.floor(t/60),r=t%60;return`${n}:${String(r).padStart(2,`0`)}`}function wV({entries:e,segments:t,windowStartMs:n,windowEndMs:r,showTicks:i=!0,gutterClass:a=`w-24`}){let[o,s]=(0,b.useState)(null),c=(0,b.useMemo)(()=>e.map((e,t)=>({entry:e,originalIdx:t})).sort((e,t)=>e.entry.timestamp-t.entry.timestamp),[e]),l=(0,b.useMemo)(()=>{let n=new Map;for(let e=0;e<c.length;e++)n.set(c[e].originalIdx,e);let r=Array(c.length).fill(null);for(let i of t){let t=Math.max(0,i.startIndex),a=Math.min(i.endIndex,e.length-1);for(let e=t;e<=a;e++){let t=n.get(e);t!==void 0&&(r[t]===null||i.severity===`critical`&&r[t].severity!==`critical`)&&(r[t]=i)}}return r},[c,t,e.length]);if(e.length===0)return(0,x.jsx)(`div`,{className:`text-ink-muted text-xs`,children:`No tool calls recorded.`});let u=n!==void 0&&r!==void 0,d=u?n:c[0].entry.timestamp,f=c.reduce((e,{entry:t})=>Math.max(e,t.timestamp+(t.durationMs??50)),0),p=Math.max(u?r-n:f-d,1),m=[1e4,3e4,6e4,12e4,3e5,6e5,9e5,18e5].find(e=>p/e<=8)??Math.ceil(p/8),h=[];for(let e=m;e<p;e+=m)h.push(e);let g=Math.min(30,800/Math.max(e.length,1));return(0,x.jsxs)(`div`,{className:`p-2 overflow-x-hidden`,children:[i&&(0,x.jsxs)(`div`,{className:`flex`,children:[(0,x.jsx)(`div`,{className:`${a} shrink-0`}),(0,x.jsx)(`div`,{className:`relative flex-1 h-5 border-b border-bg-line overflow-x-auto`,children:h.map(e=>{let t=e/p*100;return(0,x.jsx)(`span`,{className:`absolute top-0 text-[9px] text-ink-muted tabular-nums -translate-x-1/2`,style:{left:`${t}%`},children:CV(e)},e)})})]}),(0,x.jsx)(`div`,{className:i?`mt-1`:``,children:c.map(({entry:e,originalIdx:t},n)=>{let r=e.timestamp-d,i=e.durationMs??50,u=r/p*100,f=i/p*100,m=l[n],h=m?m.severity===`critical`?`border-l-2 border-l-accent-red`:`border-l-2 border-l-accent-amber`:`border-l-2 border-l-transparent`;return(0,x.jsxs)(`div`,{className:`flex items-center h-7 ${h}`,children:[(0,x.jsx)(`div`,{className:`${a} shrink-0 truncate text-[11px] text-ink-subtle pr-2 text-right`,title:e.toolName,children:Ei(e.toolName)}),(0,x.jsxs)(`div`,{className:`relative flex-1 h-full flex items-center`,children:[(0,x.jsx)(`div`,{role:`img`,"aria-label":`${e.toolName} · ${e.durationMs==null?`unknown`:`${e.durationMs}ms`} · ${e.success?`success`:`failed`}`,className:`gantt-bar absolute h-5 rounded-sm opacity-80 ${xV(Ei(e.toolName))} ${e.success?``:`ring-1 ring-accent-red/60`}`,style:{left:`${u}%`,width:`${f}%`,minWidth:`4px`,animationDelay:`${Math.round(n*g)}ms`},onMouseEnter:()=>s(n),onMouseLeave:()=>s(null)}),o===n&&(0,x.jsxs)(`div`,{className:`absolute z-50 px-2 py-1.5 rounded-lg bg-bg-elevated border border-bg-line text-[11px] text-ink-base shadow-lg whitespace-nowrap pointer-events-none ${n>=3&&n>c.length-4?`bottom-full mb-1`:`top-full mt-1`}`,style:u>=50?{right:`${Math.max(0,100-u-f)}%`}:{left:`${u}%`},children:[(0,x.jsx)(`div`,{className:`font-medium`,children:e.toolName}),(e.filePath??e.command)&&(0,x.jsx)(`div`,{className:`text-ink-subtle truncate max-w-[200px]`,children:e.filePath??e.command}),(0,x.jsxs)(`div`,{className:`text-ink-muted`,children:[e.durationMs==null?`unknown`:`${e.durationMs}ms`,` ·`,` `,e.success?`success`:`failed`]}),m&&(0,x.jsx)(`div`,{className:`mt-0.5 font-medium ${m.severity===`critical`?`text-accent-red`:`text-accent-amber`}`,children:SV[m.type]??m.type})]})]})]},`${t}-${e.timestamp}`)})})]})}function TV(e){let t=new Map;for(let n of e){let e=n.workflowRunId,r=t.get(e);r?r.push(n):t.set(e,[n])}let n=[];for(let[e,r]of t){let t=[...r].sort((e,t)=>e.startMs-t.startMs),i=t.reduce((e,t)=>Math.min(e,t.startMs),1/0),a=e===null?`Ad-hoc subagents`:r[0]?.workflowName??`Workflow run`;n.push({runId:e,name:a,earliestStartMs:i,agents:t})}return n.sort((e,t)=>e.earliestStartMs-t.earliestStartMs),n}var EV=[`bg-series-1`,`bg-series-2`,`bg-series-3`,`bg-series-4`,`bg-series-5`,`bg-series-6`],DV=`__parent__`,OV=`__adhoc__`;function kV(e){return e===null?OV:`run:${e}`}function AV(e){let t=Math.floor(e/1e3),n=Math.floor(t/60),r=t%60;return`${n}:${String(r).padStart(2,`0`)}`}var jV=15,MV=`w-44`;function NV({status:e}){return e===`completed`?(0,x.jsx)(_n,{size:12,className:`shrink-0 text-accent-green`,"aria-label":`completed`,role:`img`}):e===`failed`?(0,x.jsx)(vn,{size:12,className:`shrink-0 text-accent-red`,"aria-label":`failed`,role:`img`}):e===`running`?(0,x.jsx)(wn,{size:12,className:`shrink-0 text-accent-cyan animate-spin`,"aria-label":`running`,role:`img`}):e===`cancelled`?(0,x.jsx)(yn,{size:12,className:`shrink-0 text-accent-amber`,"aria-label":`cancelled`,role:`img`}):null}function PV({sessionId:e,parentEntries:t,agents:n,window:r,onSelectRun:i,runStatusById:a,parentSegments:o}){let[s,c]=(0,b.useState)(`gantt`),l=(0,b.useMemo)(()=>TV(n),[n]),u=(0,b.useMemo)(()=>{let e=[];t.length>0&&e.push(DV);for(let t of l)e.push(kV(t.runId));return e},[l,t.length]),d=(0,b.useMemo)(()=>n.map(e=>e.agentId),[n]),[f,p]=(0,b.useState)(()=>{let e=new Set;for(let t of l)t.agents.length>jV&&e.add(kV(t.runId));return e}),[m,h]=(0,b.useState)(()=>new Set),g=e=>{p(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},_=e=>{h(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},v=e=>{e===`collapsed`?(p(new Set(u)),h(new Set)):e===`agents`?(p(t.length>0?new Set([DV]):new Set),h(new Set)):(p(new Set),h(new Set(d)))},y=(0,b.useMemo)(()=>{let e=t.length>0,n=u.filter(e=>e!==DV),r=!e||f.has(`__parent__`),i=f.size===0,a=u.length>0&&u.every(e=>f.has(e)),o=n.every(e=>!f.has(e)),s=m.size===0,c=d.length>0?d.every(e=>m.has(e)):m.size===0;return a&&s?`collapsed`:i&&c?`expanded`:r&&o&&s?`agents`:null},[f,m,u,d,t.length]),S=t.length,C=(0,b.useMemo)(()=>[...t],[t]);return t.length===0&&n.length===0?(0,x.jsx)(`div`,{className:`text-ink-muted text-xs`,children:`No activity recorded.`}):(0,x.jsxs)(`div`,{children:[(0,x.jsxs)(`div`,{className:`flex items-center justify-between gap-2 mb-2`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,x.jsx)(si,{value:s,onChange:c,options:[{value:`gantt`,label:`Gantt`},{value:`list`,label:`List`}],size:`sm`,tone:`green`,ariaLabel:`Session trace view mode`}),(0,x.jsx)(`div`,{className:`h-4 w-px bg-border-subtle`,"aria-hidden":`true`}),(0,x.jsx)(FV,{active:y,onSelect:v})]}),(0,x.jsxs)(`span`,{className:`text-[10px] uppercase tracking-wider text-ink-muted tabular-nums`,children:[S,` parent call`,S===1?``:`s`,` · `,n.length,` agent`,n.length===1?``:`s`]})]}),s===`gantt`?(0,x.jsx)(LV,{parentRows:C,groups:l,window:r,sessionId:e,onSelectRun:i,runStatusById:a,parentSegments:o,collapsedGroups:f,toggleGroup:g,expandedAgents:m,toggleAgent:_}):(0,x.jsx)(VV,{parentRows:C,groups:l,window:r,sessionId:e,onSelectRun:i,runStatusById:a,collapsedGroups:f,toggleGroup:g,expandedAgents:m,toggleAgent:_})]})}function FV({active:e,onSelect:t}){return(0,x.jsx)(`div`,{role:`group`,"aria-label":`Trace expand level`,className:`inline-flex items-center gap-1`,children:[{value:`collapsed`,label:`Collapsed`},{value:`agents`,label:`Agents`},{value:`expanded`,label:`Expand all`}].map(n=>{let r=e===n.value;return(0,x.jsx)(`button`,{type:`button`,"aria-pressed":r,onClick:()=>t(n.value),className:`px-2 py-0.5 text-[10px] rounded-md transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-cyan/40 `+(r?`bg-accent-cyan/20 text-accent-cyan font-medium`:`text-ink-muted hover:text-ink-subtle`),children:n.label},n.value)})})}function IV({window:e}){let t=Math.max(e.endMs-e.startMs,1),n=(0,b.useMemo)(()=>{let e=[1e4,3e4,6e4,12e4,3e5,6e5,9e5,18e5].find(e=>t/e<=8)??Math.ceil(t/8),n=[];for(let r=e;r<t;r+=e)n.push(r);return n},[t]);return(0,x.jsxs)(`div`,{className:`flex px-2`,children:[(0,x.jsx)(`div`,{className:`${MV} shrink-0`}),(0,x.jsx)(`div`,{className:`relative flex-1 h-5 border-b border-bg-line overflow-x-auto`,children:n.map(e=>{let n=e/t*100;return(0,x.jsx)(`span`,{className:`absolute top-0 text-[9px] text-ink-muted tabular-nums -translate-x-1/2`,style:{left:`${n}%`},children:AV(e)},e)})})]})}function LV({parentRows:e,groups:t,window:n,sessionId:r,onSelectRun:i,runStatusById:a,parentSegments:o,collapsedGroups:s,toggleGroup:c,expandedAgents:l,toggleAgent:u}){let d=s.has(DV),f=e.length>0;return(0,x.jsxs)(`div`,{className:`overflow-x-hidden`,children:[(0,x.jsx)(IV,{window:n}),f&&(0,x.jsxs)(`div`,{className:`mb-2 mt-1`,children:[(0,x.jsx)(KV,{collapsed:d,onToggle:()=>c(`__parent__`),label:`Parent`,count:`${e.length} tool call${e.length===1?``:`s`}`}),!d&&(0,x.jsx)(wV,{entries:e,segments:o?[...o]:[],windowStartMs:n.startMs,windowEndMs:n.endMs,showTicks:!1,gutterClass:MV})]}),t.map((e,t)=>{let o=EV[t%EV.length],d=kV(e.runId),f=s.has(d),p=e.runId===null?void 0:a?.[e.runId],m=e.runId!==null&&i?()=>i(e.runId):void 0,h=e.agents.map(e=>e.usd).filter(e=>e!=null),g=h.length>0?h.reduce((e,t)=>e+t,0):null,_=e.agents.reduce((e,t)=>Math.max(e,t.endMs),0),v=_-e.earliestStartMs,y=`${e.agents.length} agent${e.agents.length===1?``:`s`} · ${wi(g)} · ${AV(Math.max(0,v))} span`;return(0,x.jsx)(`div`,{className:`mb-2`,children:f?(0,x.jsx)(RV,{onToggle:()=>c(d),label:e.name,summary:y,barColor:o,window:n,startMs:e.earliestStartMs,endMs:_,status:p,onOpenRun:m}):(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(KV,{collapsed:!1,onToggle:()=>c(d),label:e.name,swatchColor:o,count:`${e.agents.length} agent${e.agents.length===1?``:`s`}`,status:p,onOpenRun:m}),e.agents.map(e=>(0,x.jsx)(zV,{agent:e,barColor:o,window:n,sessionId:r,onSelectRun:i,expanded:l.has(e.agentId),onToggle:()=>u(e.agentId)},e.agentId))]})},e.runId??`__adhoc__`)})]})}function RV({onToggle:e,label:t,summary:n,barColor:r,window:i,startMs:a,endMs:o,status:s,onOpenRun:c}){let l=Math.max(i.endMs-i.startMs,1),u=a-i.startMs,d=Math.max(0,u/l*100),f=Math.max(0,o-a)/l*100,p=`${t} · ${n}`,m=s===`failed`,h=`absolute inset-y-0 my-auto h-4 rounded-sm opacity-85 ${r}`+(m?` ring-1 ring-accent-red/60`:``);return(0,x.jsxs)(`div`,{className:`flex items-center h-7 px-2`,children:[(0,x.jsxs)(`div`,{className:`${MV} shrink-0 flex items-center gap-1.5 pr-2`,children:[(0,x.jsxs)(`button`,{type:`button`,onClick:e,"aria-expanded":!1,className:`shrink-0 flex items-center gap-1.5 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-cyan/40 rounded-sm`,title:n,children:[(0,x.jsx)(gn,{size:13,className:`shrink-0 text-ink-muted`,"aria-hidden":`true`}),(0,x.jsx)(`span`,{className:`inline-block w-2 h-2 rounded-sm shrink-0 ${r}`,"aria-hidden":`true`})]}),c?(0,x.jsx)(`span`,{role:`button`,tabIndex:0,title:`${t} · open run`,onClick:e=>{e.stopPropagation(),c()},onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),e.stopPropagation(),c())},className:`text-[11px] font-medium text-ink-subtle truncate cursor-pointer hover:text-accent-cyan hover:underline underline-offset-2 rounded-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-cyan/40`,children:t}):(0,x.jsx)(`span`,{className:`text-[11px] font-medium text-ink-subtle truncate`,title:t,children:t}),(0,x.jsx)(NV,{status:s})]}),(0,x.jsx)(`div`,{className:`relative flex-1 h-full flex items-center`,children:(0,x.jsx)(`div`,{role:`img`,"aria-label":p,title:p,className:h,style:{left:`${d}%`,width:`${f}%`,minWidth:`4px`}})})]})}function zV({agent:e,barColor:t,window:n,sessionId:r,onSelectRun:i,expanded:a,onToggle:o}){let[s,c]=(0,b.useState)(!1),l=Math.max(n.endMs-n.startMs,1),u=e.startMs-n.startMs,d=Math.max(0,u/l*100),f=e.durationMs/l*100,p=e.workflowRunId!==null&&i!==void 0,m=e.workflowRunId,h=d>=50?{right:`${Math.max(0,100-d-f)}%`}:{left:`${d}%`},g=`${e.label} · ${e.model} · ${e.turnCount} turns · ${Ti(e.totalTokens)} tokens · ${wi(e.usd)} · ${xi(e.durationMs)}`+(p?` · open workflow run`:``),_=`absolute inset-y-0 my-auto h-5 rounded-sm opacity-85 ${t} `+(p?`cursor-pointer hover:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-cyan/40`:`cursor-default`);return(0,x.jsxs)(`div`,{children:[(0,x.jsxs)(`div`,{className:`flex items-center h-7 px-2`,children:[(0,x.jsxs)(`div`,{className:`${MV} shrink-0 flex items-center gap-1 pl-4 pr-2`,children:[(0,x.jsx)(`button`,{type:`button`,onClick:o,"aria-expanded":a,"aria-label":`${a?`Collapse`:`Expand`} calls for ${e.label}`,className:`shrink-0 rounded-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-cyan/40`,children:a?(0,x.jsx)(hn,{size:11,className:`text-ink-muted`,"aria-hidden":`true`}):(0,x.jsx)(gn,{size:11,className:`text-ink-muted`,"aria-hidden":`true`})}),(0,x.jsx)(`span`,{className:`truncate text-[11px] text-ink-subtle`,title:e.label,children:e.label})]}),(0,x.jsxs)(`div`,{className:`relative flex-1 h-full flex items-center`,children:[p?(0,x.jsx)(`button`,{type:`button`,"aria-label":g,className:_,style:{left:`${d}%`,width:`${f}%`,minWidth:`4px`},onClick:()=>i(m),onMouseEnter:()=>c(!0),onMouseLeave:()=>c(!1),onFocus:()=>c(!0),onBlur:()=>c(!1)}):(0,x.jsx)(`div`,{role:`img`,"aria-label":g,className:_,style:{left:`${d}%`,width:`${f}%`,minWidth:`4px`},onMouseEnter:()=>c(!0),onMouseLeave:()=>c(!1)}),s&&(0,x.jsxs)(`div`,{className:`absolute z-50 top-full mt-1 px-2 py-1.5 rounded-lg bg-bg-elevated border border-bg-line text-[11px] text-ink-base shadow-lg whitespace-nowrap pointer-events-none`,style:h,children:[(0,x.jsx)(`div`,{className:`font-medium`,children:e.label}),(0,x.jsx)(`div`,{className:`text-ink-subtle font-mono`,children:e.model}),(0,x.jsxs)(`div`,{className:`text-ink-muted`,children:[e.turnCount,` turn`,e.turnCount===1?``:`s`,` ·`,` `,Ti(e.totalTokens),` tokens`]}),(0,x.jsxs)(`div`,{className:`text-ink-muted`,children:[wi(e.usd),` · `,xi(e.durationMs)]})]})]})]}),a&&(0,x.jsx)(BV,{agentId:e.agentId,sessionId:r,window:n})]})}function BV({agentId:e,sessionId:t,window:n}){let{data:r,isLoading:i,isError:a}=L({queryKey:z.agentCalls(t,e),queryFn:()=>Sr(t,e),retry:!1});if(i)return(0,x.jsx)(`div`,{className:`pl-6 py-1 text-[10px] text-ink-muted`,children:`Loading calls…`});if(a)return(0,x.jsx)(`div`,{className:`pl-6 py-1 text-[10px] text-accent-red`,children:`Failed to load calls.`});let o=r?.calls??[];return o.length===0?(0,x.jsx)(`div`,{className:`pl-6 py-1 text-[10px] text-ink-muted`,children:`No calls recorded.`}):(0,x.jsx)(`div`,{className:`pl-3 border-l border-bg-line ml-3`,children:(0,x.jsx)(wV,{entries:[...o],segments:[],windowStartMs:n.startMs,windowEndMs:n.endMs,showTicks:!1,gutterClass:MV})})}function VV({parentRows:e,groups:t,window:n,sessionId:r,onSelectRun:i,runStatusById:a,collapsedGroups:o,toggleGroup:s,expandedAgents:c,toggleAgent:l}){let u=n.startMs,d=o.has(DV),f=(0,b.useMemo)(()=>{let t=1/0,n=0;for(let r of e){r.timestamp<t&&(t=r.timestamp);let e=r.timestamp+(r.durationMs??50);e>n&&(n=e)}return Number.isFinite(t)?Math.max(0,n-t):0},[e]);return(0,x.jsxs)(`div`,{className:`text-[11px]`,children:[e.length>0&&(0,x.jsxs)(`div`,{className:`mb-3`,children:[(0,x.jsx)(KV,{collapsed:d,onToggle:()=>s(`__parent__`),label:`Parent`,count:`${e.length} tool call${e.length===1?``:`s`}`,trailing:(0,x.jsx)(GV,{durationMs:f})}),!d&&(0,x.jsx)(`div`,{className:`flex flex-col`,children:[...e].sort((e,t)=>e.timestamp-t.timestamp).map((e,t)=>(0,x.jsx)(HV,{entry:e,firstTs:u,detail:e.filePath??e.command??``},`${t}-${e.timestamp}`))})]}),t.map((e,t)=>{let u=EV[t%EV.length],d=kV(e.runId),f=o.has(d),p=e.runId===null?void 0:a?.[e.runId],m=e.runId!==null&&i?()=>i(e.runId):void 0,h=e.agents.reduce((e,t)=>e+t.turnCount,0),g=e.agents.reduce((e,t)=>e+t.totalTokens,0),_=e.agents.map(e=>e.usd).filter(e=>e!=null),v=_.length>0?_.reduce((e,t)=>e+t,0):null,y=Math.max(0,e.agents.reduce((e,t)=>Math.max(e,t.endMs),0)-e.earliestStartMs);return(0,x.jsxs)(`div`,{className:`mb-3`,children:[(0,x.jsx)(KV,{collapsed:f,onToggle:()=>s(d),label:e.name,swatchColor:u,count:`${e.agents.length} agent${e.agents.length===1?``:`s`}`,status:p,onOpenRun:m,trailing:(0,x.jsx)(GV,{turns:h,tokens:g,usd:v,durationMs:y})}),!f&&(0,x.jsx)(`div`,{className:`flex flex-col gap-0.5`,children:e.agents.map(e=>(0,x.jsx)(UV,{agent:e,window:n,sessionId:r,onSelectRun:i,expanded:c.has(e.agentId),onToggle:()=>l(e.agentId)},e.agentId))})]},e.runId??`__adhoc__`)})]})}function HV({entry:e,firstTs:t,detail:n}){let r=Math.max(0,e.timestamp-t);return(0,x.jsxs)(`div`,{className:`flex items-center gap-1.5 px-2 py-0.5`,children:[(0,x.jsxs)(`span`,{className:`w-10 text-ink-muted tabular-nums shrink-0`,children:[`+`,bi(r)]}),(0,x.jsx)(`span`,{className:`w-28 truncate font-medium text-ink-base shrink-0`,title:e.toolName,children:Ei(e.toolName)}),(0,x.jsx)(`span`,{className:`flex-1 truncate font-mono text-ink-subtle min-w-0`,title:n??``,children:n??``}),(0,x.jsx)(`span`,{className:`w-14 text-right tabular-nums text-ink-muted shrink-0`,children:e.durationMs==null?`—`:`${e.durationMs}ms`}),(0,x.jsx)(`span`,{className:`w-3 text-center shrink-0 ${e.success?`text-accent-green`:`text-accent-red`}`,"aria-label":e.success?`success`:`failed`,children:e.success?`✓`:`✗`})]})}function UV({agent:e,window:t,sessionId:n,onSelectRun:r,expanded:i,onToggle:a}){let o=e.workflowRunId!==null&&r!==void 0,s=e.workflowRunId;return(0,x.jsxs)(`div`,{children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-1.5 px-2 py-0.5`,children:[(0,x.jsx)(`button`,{type:`button`,onClick:a,"aria-expanded":i,"aria-label":`${i?`Collapse`:`Expand`} calls for ${e.label}`,className:`shrink-0 rounded-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-cyan/40`,children:i?(0,x.jsx)(hn,{size:11,className:`text-ink-muted`,"aria-hidden":`true`}):(0,x.jsx)(gn,{size:11,className:`text-ink-muted`,"aria-hidden":`true`})}),o?(0,x.jsx)(`button`,{type:`button`,onClick:()=>r(s),className:`truncate font-medium text-accent-cyan hover:underline text-left shrink-0 max-w-[160px] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-cyan/40 rounded-sm`,title:`${e.label} · open workflow run`,children:e.label}):(0,x.jsx)(`span`,{className:`truncate font-medium text-ink-base shrink-0 max-w-[160px]`,title:e.label,children:e.label}),(0,x.jsx)(`span`,{className:`font-mono text-ink-muted truncate min-w-0 flex-1`,title:e.model,children:e.model}),(0,x.jsxs)(`span`,{className:`text-ink-muted tabular-nums shrink-0`,children:[e.turnCount,` turn`,e.turnCount===1?``:`s`]}),(0,x.jsxs)(`span`,{className:`text-ink-muted tabular-nums shrink-0`,children:[Ti(e.totalTokens),` tok`]}),(0,x.jsx)(`span`,{className:`text-accent-amber tabular-nums shrink-0 w-12 text-right`,children:wi(e.usd)}),(0,x.jsx)(`span`,{className:`text-ink-muted tabular-nums shrink-0 w-12 text-right`,children:xi(e.durationMs)})]}),i&&(0,x.jsx)(WV,{agentId:e.agentId,sessionId:n,firstTs:t.startMs})]})}function WV({agentId:e,sessionId:t,firstTs:n}){let{data:r,isLoading:i,isError:a}=L({queryKey:z.agentCalls(t,e),queryFn:()=>Sr(t,e),retry:!1});if(i)return(0,x.jsx)(`div`,{className:`pl-9 py-1 text-[10px] text-ink-muted`,children:`Loading calls…`});if(a)return(0,x.jsx)(`div`,{className:`pl-9 py-1 text-[10px] text-accent-red`,children:`Failed to load calls.`});let o=r?.calls??[];return o.length===0?(0,x.jsx)(`div`,{className:`pl-9 py-1 text-[10px] text-ink-muted`,children:`No calls recorded.`}):(0,x.jsx)(`div`,{className:`pl-6 border-l border-bg-line ml-3 flex flex-col`,children:[...o].sort((e,t)=>e.timestamp-t.timestamp).map((e,t)=>(0,x.jsx)(HV,{entry:e,firstTs:n},`${t}-${e.timestamp}`))})}function GV({turns:e,tokens:t,usd:n,durationMs:r}){return(0,x.jsxs)(`span`,{className:`ml-auto flex items-center gap-2 text-[10px] tabular-nums shrink-0 pl-2`,children:[e!=null&&(0,x.jsxs)(`span`,{className:`text-ink-muted`,children:[e,` turn`,e===1?``:`s`]}),t!=null&&(0,x.jsxs)(`span`,{className:`text-ink-muted`,children:[Ti(t),` tok`]}),n!=null&&(0,x.jsx)(`span`,{className:`text-accent-amber`,children:Ci(n)}),r!=null&&(0,x.jsx)(`span`,{className:`text-ink-muted`,children:xi(r)})]})}function KV({collapsed:e,onToggle:t,label:n,count:r,swatchColor:i,status:a,trailing:o,onOpenRun:s}){return(0,x.jsxs)(`div`,{className:`flex w-full items-center gap-1.5 mb-0.5 px-2 text-left`,children:[(0,x.jsxs)(`button`,{type:`button`,onClick:t,"aria-expanded":!e,className:`flex items-center gap-1.5 shrink-0 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-cyan/40 rounded-sm`,children:[e?(0,x.jsx)(gn,{size:13,className:`shrink-0 text-ink-muted`,"aria-hidden":`true`}):(0,x.jsx)(hn,{size:13,className:`shrink-0 text-ink-muted`,"aria-hidden":`true`}),i!=null&&(0,x.jsx)(`span`,{className:`inline-block w-2 h-2 rounded-sm shrink-0 ${i}`,"aria-hidden":`true`})]}),s?(0,x.jsx)(`span`,{role:`button`,tabIndex:0,title:`${n} · open run`,onClick:e=>{e.stopPropagation(),s()},onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),e.stopPropagation(),s())},className:`text-[11px] font-medium text-ink-subtle truncate min-w-0 cursor-pointer hover:text-accent-cyan hover:underline underline-offset-2 rounded-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-cyan/40`,children:n}):(0,x.jsx)(`span`,{className:`text-[11px] font-medium text-ink-subtle truncate min-w-0`,title:n,children:n}),(0,x.jsx)(`span`,{className:`text-[10px] text-ink-muted tabular-nums truncate shrink-0`,children:r}),(0,x.jsx)(NV,{status:a}),o]})}function qV(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function JV(e,t=16){return e.length<=t?e:`${e.slice(0,6)}…${e.slice(-6)}`}function YV({column:e,sortKey:t,sortDir:n}){return e===t?n===`asc`?(0,x.jsx)(pn,{className:`w-3 h-3 text-accent-amber`,"aria-hidden":`true`}):(0,x.jsx)(dn,{className:`w-3 h-3 text-accent-amber`,"aria-hidden":`true`}):(0,x.jsx)(fn,{className:`w-3 h-3 opacity-30`,"aria-hidden":`true`})}function XV({column:e,label:t,sortKey:n,sortDir:r,onSort:i,className:a=``}){return(0,x.jsx)(`th`,{scope:`col`,"aria-sort":e===n?r===`asc`?`ascending`:`descending`:`none`,className:`px-3 py-2 text-left text-[10px] uppercase tracking-wider text-ink-muted font-semibold whitespace-nowrap select-none ${a}`,children:(0,x.jsxs)(`button`,{type:`button`,onClick:()=>i(e),className:`inline-flex items-center gap-1 cursor-pointer hover:text-ink-subtle transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-cyan/40 rounded-sm`,children:[t,(0,x.jsx)(YV,{column:e,sortKey:n,sortDir:r})]})})}function ZV({agents:e}){let[t,n]=(0,b.useState)(`tokens`),[r,i]=(0,b.useState)(`desc`),[a,o]=(0,b.useState)(null);function s(e){e===t?i(e=>e===`asc`?`desc`:`asc`):(n(e),i(`desc`))}async function c(e){try{await navigator.clipboard.writeText(e),o(e),setTimeout(()=>o(null),1500)}catch{}}let l=[...e].sort((e,n)=>{let i=e[t]??-1/0,a=n[t]??-1/0;if(typeof i==`string`&&typeof a==`string`)return r===`asc`?i.localeCompare(a):a.localeCompare(i);let o=i,s=a;return r===`asc`?o-s:s-o});return e.length===0?(0,x.jsx)(`div`,{className:`py-6 text-center text-xs text-ink-muted`,children:`No agent data recorded for this run.`}):(0,x.jsx)(`div`,{className:`overflow-x-auto rounded-lg border border-border-subtle`,children:(0,x.jsxs)(`table`,{className:`w-full text-xs`,"aria-label":`Agent activity`,children:[(0,x.jsx)(`thead`,{className:`bg-surface-5 border-b border-border-subtle`,children:(0,x.jsxs)(`tr`,{children:[(0,x.jsx)(XV,{column:`label`,label:`Agent`,sortKey:t,sortDir:r,onSort:s}),(0,x.jsx)(XV,{column:`model`,label:`Model`,sortKey:t,sortDir:r,onSort:s}),(0,x.jsx)(XV,{column:`state`,label:`State`,sortKey:t,sortDir:r,onSort:s}),(0,x.jsx)(XV,{column:`tokens`,label:`Tokens`,sortKey:t,sortDir:r,onSort:s,className:`text-right`}),(0,x.jsx)(XV,{column:`toolCalls`,label:`Tool Calls`,sortKey:t,sortDir:r,onSort:s,className:`text-right`}),(0,x.jsx)(XV,{column:`durationMs`,label:`Duration`,sortKey:t,sortDir:r,onSort:s,className:`text-right`})]})}),(0,x.jsx)(`tbody`,{className:`divide-y divide-border-subtle`,children:l.map(e=>(0,x.jsxs)(`tr`,{className:`hover:bg-surface-5 transition-colors`,children:[(0,x.jsx)(`td`,{className:`px-3 py-2 min-w-0`,children:(0,x.jsxs)(`div`,{className:`flex flex-col gap-0.5 min-w-0`,children:[(0,x.jsx)(`button`,{type:`button`,title:e.agentId,"aria-label":`Copy agent ID ${e.agentId}`,onClick:()=>void c(e.agentId),className:`text-left text-ink-base font-medium truncate hover:text-accent-cyan transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-cyan/40 rounded`,children:a===e.agentId?(0,x.jsx)(`span`,{className:`text-accent-green`,children:`Copied!`}):e.label||JV(e.agentId)}),e.phaseTitle&&(0,x.jsxs)(`span`,{className:`text-[10px] text-ink-muted truncate`,children:[e.phaseTitle,e.attempt>1?` · attempt ${e.attempt}`:``]})]})}),(0,x.jsx)(`td`,{className:`px-3 py-2`,children:(0,x.jsx)(`span`,{className:`inline-flex items-center px-1.5 py-0.5 rounded text-[10px] bg-surface-5 text-ink-subtle font-mono`,children:e.model||`—`})}),(0,x.jsx)(`td`,{className:`px-3 py-2`,children:(0,x.jsx)(`span`,{className:`text-ink-subtle`,children:e.state||`—`})}),(0,x.jsx)(`td`,{className:`px-3 py-2 text-right tabular-nums text-ink-base font-medium`,children:e.tokens>0?qV(e.tokens):(0,x.jsx)(`span`,{className:`text-ink-muted opacity-40`,children:`—`})}),(0,x.jsx)(`td`,{className:`px-3 py-2 text-right tabular-nums text-ink-muted`,children:e.toolCalls>0?e.toolCalls.toLocaleString():(0,x.jsx)(`span`,{className:`text-ink-muted opacity-40`,children:`—`})}),(0,x.jsx)(`td`,{className:`px-3 py-2 text-right tabular-nums text-ink-muted`,children:e.durationMs==null?(0,x.jsx)(`span`,{className:`text-ink-muted opacity-40`,children:`—`}):xi(e.durationMs)})]},e.agentId))})]})})}function QV(e){return e===`Read`?`bg-accent-blue`:e===`Edit`||e===`Write`?`bg-accent-green`:e===`Bash`?`bg-accent-purple`:e===`Agent`?`bg-accent-teal`:`bg-ink-subtle`}var $V=15;function eH({agents:e,window:t,parentEntries:n,onSelectRun:r}){let[i,a]=(0,b.useState)(null),o=Math.max(t.endMs-t.startMs,1),s=(0,b.useMemo)(()=>{let e=[1e4,3e4,6e4,12e4,3e5,6e5,9e5,18e5].find(e=>o/e<=8)??Math.ceil(o/8),t=[];for(let n=e;n<o;n+=e)t.push(n);return t},[o]),c=(0,b.useMemo)(()=>TV(e),[e]),l=(0,b.useMemo)(()=>n?[...n].sort((e,t)=>e.timestamp-t.timestamp):[],[n]),u=n!==void 0,d=(0,b.useMemo)(()=>c.reduce((e,t)=>e+t.agents.length,0),[c])+ +!!u,[f,p]=(0,b.useState)(()=>{let e=new Set;for(let t of c)t.agents.length>$V&&e.add(kV(t.runId));return e}),m=e=>{p(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};if(e.length===0&&!u)return(0,x.jsx)(`div`,{className:`text-ink-muted text-xs`,children:`No subagents ran in this session.`});let h=-1,g=e=>e>=3&&e>d-4?`bottom-full mb-1`:`top-full mt-1`,_=f.has(DV);return(0,x.jsxs)(`div`,{className:`p-2 overflow-x-hidden`,children:[(0,x.jsxs)(`div`,{className:`flex`,children:[(0,x.jsx)(`div`,{className:`w-24 shrink-0`}),(0,x.jsx)(`div`,{className:`relative flex-1 h-5 border-b border-bg-line overflow-x-auto`,children:s.map(e=>{let t=e/o*100;return(0,x.jsx)(`span`,{className:`absolute top-0 text-[9px] text-ink-muted tabular-nums -translate-x-1/2`,style:{left:`${t}%`},children:AV(e)},e)})})]}),(0,x.jsxs)(`div`,{className:`mt-1`,children:[u&&(0,x.jsxs)(`div`,{className:`mb-2`,children:[(0,x.jsxs)(`button`,{type:`button`,onClick:()=>m(`__parent__`),"aria-expanded":!_,className:`flex w-full items-center gap-1.5 mb-0.5 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-cyan/40 rounded-sm`,children:[_?(0,x.jsx)(gn,{size:13,className:`shrink-0 text-ink-muted`,"aria-hidden":`true`}):(0,x.jsx)(hn,{size:13,className:`shrink-0 text-ink-muted`,"aria-hidden":`true`}),(0,x.jsx)(`span`,{className:`text-[11px] font-medium text-ink-subtle truncate`,children:`Parent activity`}),(0,x.jsxs)(`span`,{className:`text-[10px] text-ink-muted tabular-nums`,children:[l.length,` tool call`,l.length===1?``:`s`]})]}),!_&&(()=>{h+=1;let e=h;return(0,x.jsxs)(`div`,{className:`flex items-center h-7`,children:[(0,x.jsx)(`div`,{className:`w-24 shrink-0 truncate text-[11px] text-ink-subtle pr-2 text-right`,children:`Parent`}),(0,x.jsx)(`div`,{className:`relative flex-1 h-full flex items-center`,children:l.map((n,r)=>{let s=n.timestamp-t.startMs,c=Math.max(0,s/o*100),l=(n.durationMs??50)/o*100,u=`parent:${r}`,d=Ei(n.toolName),f=c>=50?{right:`${Math.max(0,100-c-l)}%`}:{left:`${c}%`},p=`${n.toolName} · ${n.durationMs==null?`unknown`:`${n.durationMs}ms`} · ${n.success?`success`:`failed`}`;return(0,x.jsxs)(`div`,{className:`contents`,children:[(0,x.jsx)(`div`,{role:`img`,"aria-label":p,className:`absolute inset-y-0 my-auto h-5 rounded-sm opacity-80 cursor-default ${QV(d)} `+(n.success?``:`ring-1 ring-accent-red/60`),style:{left:`${c}%`,width:`${l}%`,minWidth:`4px`},onMouseEnter:()=>a(u),onMouseLeave:()=>a(null)}),i===u&&(0,x.jsxs)(`div`,{className:`absolute z-50 ${g(e)} px-2 py-1.5 rounded-lg bg-bg-elevated border border-bg-line text-[11px] text-ink-base shadow-lg whitespace-nowrap pointer-events-none`,style:f,children:[(0,x.jsx)(`div`,{className:`font-medium`,children:n.toolName}),(0,x.jsxs)(`div`,{className:`text-ink-muted`,children:[n.durationMs==null?`unknown`:`${n.durationMs}ms`,` `,`· `,n.success?`success`:`failed`]})]})]},u)})})]})})()]}),c.map((e,n)=>{let s=EV[n%EV.length],c=kV(e.runId),l=f.has(c),u=e.agents.map(e=>e.usd).filter(e=>e!=null),d=u.length>0?u.reduce((e,t)=>e+t,0):null,p=e.agents.reduce((e,t)=>Math.max(e,t.endMs),0)-e.earliestStartMs,_=`${e.agents.length} agent${e.agents.length===1?``:`s`} · ${wi(d)} · ${AV(Math.max(0,p))} span`;return(0,x.jsxs)(`div`,{className:`mb-2`,children:[(0,x.jsxs)(`button`,{type:`button`,onClick:()=>m(c),"aria-expanded":!l,className:`flex w-full items-center gap-1.5 mb-0.5 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-cyan/40 rounded-sm`,children:[l?(0,x.jsx)(gn,{size:13,className:`shrink-0 text-ink-muted`,"aria-hidden":`true`}):(0,x.jsx)(hn,{size:13,className:`shrink-0 text-ink-muted`,"aria-hidden":`true`}),(0,x.jsx)(`span`,{className:`inline-block w-2 h-2 rounded-sm shrink-0 ${s}`,"aria-hidden":`true`}),(0,x.jsx)(`span`,{className:`text-[11px] font-medium text-ink-subtle truncate`,title:e.name,children:e.name}),l?(0,x.jsx)(`span`,{className:`text-[10px] text-ink-muted tabular-nums truncate`,children:_}):(0,x.jsxs)(`span`,{className:`text-[10px] text-ink-muted tabular-nums`,children:[e.agents.length,` agent`,e.agents.length===1?``:`s`]})]}),!l&&e.agents.map(e=>{h+=1;let c=h,l=e.startMs-t.startMs,u=Math.max(0,l/o*100),d=e.durationMs/o*100,f=`${n}:${e.agentId}`,p=e.workflowRunId!==null&&r!==void 0,m=e.workflowRunId,_=u>=50?{right:`${Math.max(0,100-u-d)}%`}:{left:`${u}%`},v=`${e.label} · ${e.model} · ${e.turnCount} turns · ${Si(e.totalTokens)} tokens · ${wi(e.usd)} · ${xi(e.durationMs)}`+(p?` · open workflow run`:``),y=`absolute inset-y-0 my-auto h-5 rounded-sm opacity-85 ${s} `+(p?`cursor-pointer hover:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-cyan/40`:`cursor-default`);return(0,x.jsxs)(`div`,{className:`flex items-center h-7`,children:[(0,x.jsx)(`div`,{className:`w-24 shrink-0 truncate text-[11px] text-ink-subtle pr-2 text-right`,title:e.label,children:e.label}),(0,x.jsxs)(`div`,{className:`relative flex-1 h-full flex items-center`,children:[p?(0,x.jsx)(`button`,{type:`button`,"aria-label":v,className:y,style:{left:`${u}%`,width:`${d}%`,minWidth:`4px`},onClick:()=>r(m),onMouseEnter:()=>a(f),onMouseLeave:()=>a(null),onFocus:()=>a(f),onBlur:()=>a(null)}):(0,x.jsx)(`div`,{role:`img`,"aria-label":v,className:y,style:{left:`${u}%`,width:`${d}%`,minWidth:`4px`},onMouseEnter:()=>a(f),onMouseLeave:()=>a(null)}),i===f&&(0,x.jsxs)(`div`,{className:`absolute z-50 ${g(c)} px-2 py-1.5 rounded-lg bg-bg-elevated border border-bg-line text-[11px] text-ink-base shadow-lg whitespace-nowrap pointer-events-none`,style:_,children:[(0,x.jsx)(`div`,{className:`font-medium`,children:e.label}),(0,x.jsx)(`div`,{className:`text-ink-subtle font-mono`,children:e.model}),(0,x.jsxs)(`div`,{className:`text-ink-muted`,children:[e.turnCount,` turn`,e.turnCount===1?``:`s`,` ·`,` `,Si(e.totalTokens),` tokens`]}),(0,x.jsxs)(`div`,{className:`text-ink-muted`,children:[wi(e.usd),` ·`,` `,xi(e.durationMs)]})]})]})]},f)})]},e.runId??`__adhoc__`)})]})]})}var tH={running:{tone:`info`,label:`Running`},completed:{tone:`success`,label:`Completed`},failed:{tone:`danger`,label:`Failed`},cancelled:{tone:`warning`,label:`Cancelled`},unknown:{tone:`neutral`,label:`Unknown`}};function nH({status:e}){switch(e){case`completed`:return(0,x.jsx)(_n,{className:`w-4 h-4 text-accent-green`,"aria-hidden":`true`});case`failed`:return(0,x.jsx)(vn,{className:`w-4 h-4 text-accent-red`,"aria-hidden":`true`});case`running`:return(0,x.jsx)(wn,{className:`w-4 h-4 text-accent-cyan animate-spin`,"aria-hidden":`true`});case`cancelled`:return(0,x.jsx)(yn,{className:`w-4 h-4 text-accent-amber`,"aria-hidden":`true`});default:return(0,x.jsx)(yn,{className:`w-4 h-4 text-ink-muted`,"aria-hidden":`true`})}}function rH(e,t,n){let r=[];for(let i of e){if(i.startedAt==null)continue;let e=i.durationMs??0;r.push({agentId:i.agentId,workflowRunId:t,workflowName:n,label:i.label||i.agentId,model:i.model,startMs:i.startedAt,endMs:i.startedAt+e,durationMs:e,turnCount:i.toolCalls,totalTokens:i.tokens,usd:null})}return r}function iH({runId:e,onClose:t}){let n=(0,b.useRef)(null),r=(0,b.useRef)(null);(0,b.useEffect)(()=>{function e(e){if(e.key===`Escape`){t();return}if(e.key===`Tab`&&n.current){let t=n.current.querySelectorAll(`button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])`),r=t[0],i=t[t.length-1];!e.shiftKey&&document.activeElement===i?(e.preventDefault(),r?.focus()):e.shiftKey&&document.activeElement===r&&(e.preventDefault(),i?.focus())}}return document.addEventListener(`keydown`,e),r.current?.focus(),()=>document.removeEventListener(`keydown`,e)},[t]);let{data:i,isLoading:a,isError:o}=L({queryKey:z.workflowDetail(e),queryFn:()=>Hr(e),refetchInterval:5e3}),s=i?.run,c=(0,b.useMemo)(()=>i?.agents??[],[i?.agents]),l=i?.topology??null,u=s==null?null:tH[s.status]??tH.unknown,d=s!=null&&(s.status===`failed`||s.status===`cancelled`)&&typeof s.errorReason==`string`&&s.errorReason.trim()!==``?s.errorReason:null,f=c.reduce((e,t)=>e+(t.tokens??0),0),p=s?.totalTokens??null,m=p==null?null:p-f,h=(0,b.useMemo)(()=>s==null?[]:rH(c,s.runId,s.workflowName??null),[c,s]),g=(0,b.useMemo)(()=>{if(h.length===0)return{startMs:0,endMs:1};let e=1/0,t=-1/0;for(let n of h)n.startMs<e&&(e=n.startMs),n.endMs>t&&(t=n.endMs);return{startMs:e,endMs:t>e?t:e+1}},[h]);return(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(`div`,{className:`fixed inset-0 z-40 bg-black/40 backdrop-blur-sm`,"aria-hidden":`true`,onClick:t}),(0,x.jsxs)(`div`,{ref:n,role:`dialog`,"aria-modal":`true`,"aria-label":`Workflow run details: ${s?.workflowName??e}`,className:`fixed right-0 top-0 bottom-0 z-50 w-[640px] max-w-full flex flex-col bg-bg-panel border-l border-border-medium shadow-2xl overflow-hidden`,children:[(0,x.jsxs)(`div`,{className:`flex items-start justify-between gap-3 px-5 py-4 border-b border-border-subtle shrink-0`,children:[(0,x.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[a&&(0,x.jsxs)(`div`,{className:`flex items-center gap-2 text-ink-muted`,children:[(0,x.jsx)(wn,{className:`w-4 h-4 animate-spin`,"aria-hidden":`true`}),(0,x.jsx)(`span`,{className:`text-sm`,children:`Loading run details…`})]}),o&&(0,x.jsx)(`span`,{className:`text-sm text-accent-red`,children:`Failed to load run details.`}),s!=null&&(0,x.jsxs)(x.Fragment,{children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,x.jsx)(nH,{status:s.status}),(0,x.jsx)(`h2`,{className:`text-sm font-semibold text-ink-base truncate`,children:s.workflowName}),u!=null&&(0,x.jsx)(ni,{tone:u.tone,size:`sm`,bordered:!0,children:u.label}),s.runSource!=null&&(0,x.jsx)(ni,{tone:`neutral`,size:`sm`,children:s.runSource})]}),(0,x.jsxs)(`div`,{className:`mt-1 flex items-center gap-3 text-[10px] text-ink-muted flex-wrap`,children:[(0,x.jsx)(`span`,{className:`font-mono`,children:e}),s.startedAt!=null&&(0,x.jsx)(`span`,{children:new Date(s.startedAt).toLocaleString()}),s.durationMs!=null&&(0,x.jsx)(`span`,{children:xi(s.durationMs)}),s.defaultModel&&(0,x.jsx)(`span`,{className:`font-mono`,children:s.defaultModel})]})]})]}),(0,x.jsx)(`button`,{ref:r,type:`button`,"aria-label":`Close run details`,onClick:t,className:`shrink-0 p-1.5 rounded-md text-ink-muted hover:text-ink-base hover:bg-surface-5 transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-cyan/40`,children:(0,x.jsx)(An,{className:`w-4 h-4`,"aria-hidden":`true`})})]}),(0,x.jsx)(`div`,{className:`flex-1 overflow-y-auto px-5 py-4 space-y-5`,children:s!=null&&(0,x.jsxs)(x.Fragment,{children:[d!=null&&(0,x.jsxs)(B,{tone:`static`,padding:`sm`,children:[(0,x.jsx)(V,{className:`mb-2`,children:`Failure reason`}),(0,x.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,x.jsx)(vn,{className:`w-4 h-4 text-accent-red shrink-0 mt-0.5`,"aria-hidden":`true`}),(0,x.jsx)(`p`,{className:`text-xs text-accent-red font-mono break-words`,children:d})]})]}),(s.totalTokens!=null||p!=null)&&(0,x.jsxs)(B,{tone:`static`,padding:`sm`,children:[(0,x.jsx)(V,{className:`mb-2`,children:`Token Reconciliation`}),(0,x.jsxs)(`div`,{className:`grid grid-cols-3 gap-3`,children:[(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`div`,{className:`text-[10px] text-ink-muted uppercase tracking-wider`,children:`Rollup`}),(0,x.jsx)(`div`,{className:`text-sm font-bold tabular-nums text-ink-base mt-0.5`,children:p==null?`—`:p.toLocaleString()})]}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`div`,{className:`text-[10px] text-ink-muted uppercase tracking-wider`,children:`Agent Sum`}),(0,x.jsx)(`div`,{className:`text-sm font-bold tabular-nums text-ink-base mt-0.5`,children:f.toLocaleString()})]}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`div`,{className:`text-[10px] text-ink-muted uppercase tracking-wider`,children:`Delta`}),(0,x.jsx)(`div`,{className:`text-sm font-bold tabular-nums mt-0.5 ${m===null?`text-ink-muted`:m===0?`text-accent-green`:`text-accent-amber`}`,children:m===null?`—`:m===0?`0`:`${m>0?`+`:``}${m.toLocaleString()}`})]})]}),s.totalUsd!=null&&(0,x.jsxs)(`div`,{className:`mt-2 pt-2 border-t border-border-subtle flex items-center justify-between`,children:[(0,x.jsx)(`span`,{className:`text-[10px] text-ink-muted uppercase tracking-wider`,children:`Total Cost`}),(0,x.jsx)(`span`,{className:`text-xs font-bold text-accent-amber tabular-nums`,children:Ci(s.totalUsd)})]})]}),l!=null&&(0,x.jsxs)(B,{tone:`static`,padding:`sm`,children:[(0,x.jsx)(V,{className:`mb-2`,children:`Topology`}),(0,x.jsxs)(`div`,{className:`grid grid-cols-3 gap-3`,children:[(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`div`,{className:`text-[10px] text-ink-muted uppercase tracking-wider`,children:`Declared Phases`}),(0,x.jsx)(`div`,{className:`text-sm font-bold tabular-nums text-ink-base mt-0.5`,children:l.declaredPhases==null?`—`:l.declaredPhases})]}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`div`,{className:`text-[10px] text-ink-muted uppercase tracking-wider`,children:`Observed Phases`}),(0,x.jsx)(`div`,{className:`text-sm font-bold tabular-nums text-ink-base mt-0.5`,children:s.observedPhases==null?`—`:s.observedPhases})]}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`div`,{className:`text-[10px] text-ink-muted uppercase tracking-wider`,children:`Declared Agents`}),(0,x.jsx)(`div`,{className:`text-sm font-bold tabular-nums text-ink-base mt-0.5`,children:l.declaredAgents==null?`—`:l.declaredAgents})]})]}),l.declaredParallelWidths!=null&&l.declaredParallelWidths.length>0&&(0,x.jsxs)(`div`,{className:`mt-2 pt-2 border-t border-border-subtle flex items-center gap-2 flex-wrap`,children:[(0,x.jsx)(`span`,{className:`text-[10px] text-ink-muted uppercase tracking-wider`,children:`Parallel Widths`}),l.declaredParallelWidths.map((e,t)=>(0,x.jsx)(`span`,{className:`inline-flex items-center px-1.5 py-0.5 rounded text-[10px] bg-surface-5 text-ink-subtle font-mono`,children:e},`${e}-${t}`))]})]}),h.length>0&&(0,x.jsxs)(`section`,{"aria-label":`Agent fan-out timeline`,children:[(0,x.jsx)(V,{className:`mb-3`,children:`Fan-out timeline`}),(0,x.jsx)(B,{tone:`static`,padding:`sm`,children:(0,x.jsx)(eH,{agents:h,window:g})})]}),c.length>0?(0,x.jsxs)(`section`,{"aria-label":`Agent activity`,children:[(0,x.jsxs)(V,{className:`mb-3`,children:[`Agents (`,c.length,`)`]}),(0,x.jsx)(ZV,{agents:c})]}):(0,x.jsx)(`div`,{className:`py-6 text-center text-xs text-ink-muted`,children:`No agent data recorded for this run.`})]})})]})]})}var aH=[`system`,`tools`,`user`,`assistant`],oH={system:`bg-accent-indigo`,tools:`bg-accent-amber`,user:`bg-accent-blue`,assistant:`bg-accent-green`},sH={system:`shadow-[0_0_8px_rgba(99,102,241,0.4)]`,tools:`shadow-[0_0_8px_rgba(255,178,36,0.4)]`,user:`shadow-[0_0_8px_rgba(0,149,255,0.4)]`,assistant:`shadow-[0_0_8px_rgba(28,231,131,0.4)]`},cH={system:`bg-accent-indigo`,tools:`bg-accent-amber`,user:`bg-accent-blue`,assistant:`bg-accent-green`},lH={system:`System`,tools:`Tools`,user:`User`,assistant:`Assistant`},uH={system:`#6366f1`,tools:`#ffb224`,user:`#0095ff`,assistant:`#1ce783`},dH={fontSize:10,fill:`#6b7280`},fH=`#2a2a3a`;function pH({history:e,contextWindow:t}){let n=(0,b.useId)();if(e.length<2)return null;let r=e.map(e=>({turn:e.turnNumber,system:t>0?e.breakdown.system/t*100:0,tools:t>0?e.breakdown.tools/t*100:0,user:t>0?e.breakdown.user/t*100:0,assistant:t>0?e.breakdown.assistant/t*100:0}));return(0,x.jsx)(`div`,{className:`mt-2 pt-2 border-t border-surface-3`,children:(0,x.jsx)(np,{width:`100%`,height:120,children:(0,x.jsxs)(rV,{data:r,margin:{top:4,right:4,bottom:0,left:-20},children:[(0,x.jsx)(`defs`,{children:(0,x.jsxs)(`linearGradient`,{id:n,x1:`0`,y1:`1`,x2:`0`,y2:`0`,children:[(0,x.jsx)(`stop`,{offset:`0%`,stopColor:`#f59e0b`,stopOpacity:.15}),(0,x.jsx)(`stop`,{offset:`100%`,stopColor:`#ef4444`,stopOpacity:.25})]})}),(0,x.jsx)(hI,{strokeDasharray:`3 3`,stroke:fH}),(0,x.jsx)(YR,{dataKey:`turn`,tick:dH,stroke:fH}),(0,x.jsx)(uz,{domain:[0,100],unit:`%`,tick:dH,stroke:fH}),(0,x.jsx)(Yk,{contentStyle:{backgroundColor:`#1a1a2e`,border:`1px solid #2a2a3a`,fontSize:11},formatter:(e,t)=>[`${e.toFixed(1)}%`,t],labelFormatter:e=>`Turn ${e}`}),(0,x.jsx)(KP,{y1:80,y2:100,fill:`url(#${n})`,ifOverflow:`visible`}),aH.map(e=>(0,x.jsx)(yL,{type:`monotone`,dataKey:e,stackId:`context`,stroke:uH[e],fill:uH[e],fillOpacity:.4,strokeWidth:1,dot:!1},e))]})})})}function mH(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e)}function hH(e,t=``){return{sessionId:t,turnNumber:e.turnCount,totalTokens:e.growth.currentTokens,fillPercent:e.fillPercent,contextWindow:e.contextWindow,breakdown:e.currentBreakdown,growth:{startTokens:e.growth.startTokens,currentTokens:e.growth.currentTokens,delta:e.growth.deltaTokens},topTools:e.toolContributions.map(e=>({tool:e.tool,estimatedTokens:e.estimatedTokens}))}}function gH({data:e,sessionId:t,expandable:n=!0}){let r=qn(e=>e.contextBySession),i=t?r.get(t)??null:null,[a,o]=(0,b.useState)(null),[s,c]=(0,b.useState)(!1),[l,u]=(0,b.useState)(!1),d=(0,b.useRef)(0),f=(0,b.useRef)(0);(0,b.useEffect)(()=>{u(!1)},[t]);let{data:p}=L({queryKey:t?[`context`,t]:z.context,queryFn:()=>Ar(t??void 0),refetchInterval:1e4,enabled:!e}),{data:m}=L({queryKey:[`context-composition`,t],queryFn:jr,enabled:l}),{data:h}=L({queryKey:[`context-efficiency`,t],queryFn:Mr,enabled:l}),g=e??p,_=t??``,v=e?hH(e,_):i??(g?hH(g,_):null),y=v?.growth.currentTokens??0,S=Math.min(v?.fillPercent??0,100),C=f.current>0&&S>d.current;if((0,b.useEffect)(()=>{if(f.current>0&&y<f.current*.7){c(!0);let e=setTimeout(()=>c(!1),1e3);return f.current=y,d.current=S,()=>clearTimeout(e)}f.current=y,d.current=S},[S,y]),!v||v.totalTokens===0)return null;let{breakdown:w,growth:T,fillPercent:E,totalTokens:D}=v,O=E>=100,k=v.contextWindow,A=l&&g?.history&&g.history.length>=2?g.history:null;return(0,x.jsxs)(`div`,{className:`group`,children:[(0,x.jsxs)(`div`,{className:`flex items-center justify-between mb-1.5`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,x.jsx)(V,{children:`Context`}),O&&(0,x.jsx)(ni,{tone:`danger`,size:`sm`,uppercase:!0,className:`animate-pulse motion-reduce:animate-none`,children:`at capacity`})]}),(0,x.jsxs)(`div`,{className:`flex items-center gap-1 text-[11px] text-ink-subtle tabular-nums`,children:[mH(T.currentTokens),k&&k>0&&(0,x.jsx)(`span`,{className:`text-ink-muted`,children:` / ${mH(k)}`}),T.delta>0&&(0,x.jsxs)(`span`,{className:`text-accent-amber ml-1`,children:[`+`,mH(T.delta)]}),T.delta<0&&(0,x.jsx)(`span`,{className:`text-accent-cyan ml-1`,children:`compacted`}),n&&(g?.history?.length??0)>=2&&(0,x.jsx)(`button`,{onClick:()=>u(e=>!e),className:`ml-1 text-ink-muted hover:text-ink-base transition-colors`,"aria-label":`Toggle context timeline`,"aria-expanded":l,children:l?`▾`:`▸`})]})]}),(0,x.jsxs)(`div`,{className:`relative`,children:[s&&(0,x.jsx)(`div`,{className:`absolute inset-0 rounded-full bg-accent-cyan/20 animate-compact-flash pointer-events-none`}),(0,x.jsx)(`div`,{className:`w-full h-3 bg-surface-3 rounded-full overflow-hidden flex transition-colors duration-150 ${C?`shadow-[0_0_12px_rgba(255,178,36,0.3)]`:``} ${s?`animate-compact`:``}`,children:aH.map(e=>{let t=w[e];if(t<=0)return null;let n=Math.round(t/D*100),r=a===e;return(0,x.jsx)(`div`,{className:`${oH[e]} transition-all duration-500 ease-out cursor-default relative ${r?`brightness-125 ${sH[e]}`:``}`,style:{width:`${t/D*S}%`},title:`${lH[e]}: ${mH(t)} (${n}%)`,onMouseEnter:()=>o(e),onMouseLeave:()=>o(null)},e)})})]}),(0,x.jsxs)(`div`,{className:`flex items-center gap-3 mt-1.5 text-[10px] text-ink-muted`,children:[aH.map(e=>{let t=w[e],n=a===e;return(0,x.jsxs)(`span`,{className:`flex items-center gap-1 transition-colors duration-200 cursor-default ${n?`text-ink-base`:``}`,onMouseEnter:()=>o(e),onMouseLeave:()=>o(null),children:[(0,x.jsx)(`span`,{className:`inline-block w-1.5 h-1.5 rounded-full ${cH[e]} ${n?`scale-150`:``} transition-transform duration-200`}),lH[e],n&&t>0&&(0,x.jsx)(`span`,{className:`text-ink-subtle ml-0.5`,children:mH(t)})]},e)}),(0,x.jsxs)(`span`,{className:`ml-auto tabular-nums ${O?`text-accent-red`:S>=75?`text-accent-amber`:``}`,children:[S.toFixed(0),`%`]})]}),n&&(0,x.jsxs)(`div`,{className:`overflow-hidden transition-all duration-300 ${l?`max-h-56`:`max-h-0`}`,children:[A&&(0,x.jsx)(pH,{history:A,contextWindow:k}),l&&h&&h.repeatedReadRatio!==null&&(0,x.jsxs)(`div`,{className:`mt-2 text-xs text-ink-muted`,children:[(0,x.jsxs)(`span`,{children:[`Repeated reads: `,Math.round(h.repeatedReadRatio*100),`%`]}),h.topRepeatedFiles[0]&&(0,x.jsxs)(`span`,{className:`ml-2`,children:[`top:`,` `,(0,x.jsx)(`code`,{className:`bg-surface-5 px-1 rounded`,children:h.topRepeatedFiles[0].file}),` `,`(`,h.topRepeatedFiles[0].readCount,`x)`]})]}),l&&m&&(0,x.jsxs)(`div`,{className:`mt-1 text-xs text-ink-muted`,children:[`Dominant this turn:`,` `,Object.entries(m.currentBreakdown).sort((e,t)=>t[1]-e[1])[0]?.[0]]})]})]})}var _H={success:`success`,failure:`danger`,unknown:`neutral`};function vH({decisionTree:e,turnCosts:t,contextHistory:n,contextWindow:r,contextComposition:i,contextEfficiency:a,onClose:o}){let s=(0,b.useRef)(null),c=(0,b.useRef)(null);(0,b.useEffect)(()=>{function e(e){if(e.key===`Escape`){o();return}if(e.key===`Tab`&&s.current){let t=s.current.querySelectorAll(`button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])`),n=t[0],r=t[t.length-1];!e.shiftKey&&document.activeElement===r?(e.preventDefault(),n?.focus()):e.shiftKey&&document.activeElement===n&&(e.preventDefault(),r?.focus())}}return document.addEventListener(`keydown`,e),c.current?.focus(),()=>document.removeEventListener(`keydown`,e)},[o]);let l=e!=null&&e.totalBranches>0,u=t?.turns!=null&&t.turns.length>0,d=(n?.length??0)>=2;return(0,li.createPortal)((0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(`div`,{className:`fixed inset-0 z-40 bg-black/40 backdrop-blur-sm`,"aria-hidden":`true`,onClick:o}),(0,x.jsxs)(`div`,{ref:s,role:`dialog`,"aria-modal":`true`,"aria-label":`Session decision-tree and turn-cost detail`,className:`fixed right-0 top-0 bottom-0 z-50 w-[640px] max-w-full flex flex-col bg-bg-panel border-l border-border-medium shadow-2xl overflow-hidden`,children:[(0,x.jsxs)(`div`,{className:`flex items-start justify-between gap-3 px-5 py-4 border-b border-border-subtle shrink-0`,children:[(0,x.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,x.jsx)(`h2`,{className:`text-sm font-semibold text-ink-base`,children:`Session Detail`}),(0,x.jsx)(`p`,{className:`mt-1 text-[10px] text-ink-muted`,children:`Decision Tree and Turn Costs below are scoped to the selected session. Context Composition & Efficiency remain live, current-process-only — they reflect this dashboard process’s own current session, not necessarily the one selected above.`})]}),(0,x.jsx)(`button`,{ref:c,type:`button`,"aria-label":`Close session detail`,onClick:o,className:`shrink-0 p-1.5 rounded-md text-ink-muted hover:text-ink-base hover:bg-surface-5 transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-cyan/40`,children:(0,x.jsx)(An,{className:`w-4 h-4`,"aria-hidden":`true`})})]}),(0,x.jsxs)(`div`,{className:`flex-1 overflow-y-auto px-5 py-4 space-y-5`,children:[(0,x.jsxs)(`section`,{"aria-label":`Decision tree`,children:[(0,x.jsx)(V,{className:`mb-3`,children:`Decision Tree`}),(0,x.jsx)(B,{tone:`static`,padding:`sm`,children:l?(0,x.jsxs)(x.Fragment,{children:[(0,x.jsxs)(`div`,{className:`grid grid-cols-3 gap-3`,children:[(0,x.jsx)(yH,{label:`Longest failure streak`,value:String(e.longestFailureStreak)}),(0,x.jsx)(yH,{label:`Success rate`,value:e.successRate===null?`—`:`${Math.round(e.successRate*100)}%`}),(0,x.jsx)(yH,{label:`Total branches`,value:String(e.totalBranches)})]}),e.failurePoints.length>0&&(0,x.jsx)(`div`,{className:`mt-3 pt-3 border-t border-border-subtle space-y-2`,children:e.failurePoints.map((e,t)=>(0,x.jsx)(`div`,{className:`flex items-start justify-between gap-2 text-xs`,children:(0,x.jsxs)(`div`,{className:`min-w-0`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:[(0,x.jsxs)(`span`,{className:`text-ink-muted`,children:[`Turn `,e.turnNumber]}),e.toolName&&(0,x.jsx)(`code`,{className:`text-[10px] bg-surface-5 px-1 rounded`,children:e.toolName}),(0,x.jsx)(ni,{tone:_H[e.outcome],size:`sm`,children:e.outcome})]}),(0,x.jsx)(`p`,{className:`mt-0.5 text-ink-subtle break-words`,children:e.reasoning})]})},`${e.turnNumber}-${t}`))}),e.note&&(0,x.jsx)(`p`,{className:`mt-3 pt-3 border-t border-border-subtle text-[10px] text-ink-muted`,children:e.note})]}):(0,x.jsx)(`div`,{className:`py-2 text-center text-xs text-ink-muted`,children:`No decision-tree data yet.`})})]}),(0,x.jsxs)(`section`,{"aria-label":`Turn costs`,children:[(0,x.jsx)(V,{className:`mb-3`,children:`Turn Costs`}),(0,x.jsx)(B,{tone:`static`,padding:`sm`,children:u?(0,x.jsxs)(x.Fragment,{children:[(0,x.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 mb-3 pb-3 border-b border-border-subtle`,children:[(0,x.jsx)(yH,{label:`Total attributed cost`,value:`$${t.totalAttributedCost.toFixed(2)}`}),(0,x.jsx)(yH,{label:`Attribution rate`,value:`${Math.round(t.attributionRate*100)}%`})]}),(0,x.jsx)(`div`,{className:`space-y-2`,children:t.turns.map(e=>(0,x.jsxs)(`div`,{className:`flex items-center justify-between gap-2 text-xs`,children:[(0,x.jsxs)(`div`,{className:`min-w-0`,children:[(0,x.jsx)(`div`,{className:`text-ink-base`,children:e.toolNames.join(`, `)}),(0,x.jsxs)(`div`,{className:`text-[10px] text-ink-muted font-mono`,children:[e.model,` · `,Ti(e.inputTokens),` in /`,` `,Ti(e.outputTokens),` out /`,` `,Ti(e.cacheReadTokens),` cache`]})]}),(0,x.jsxs)(`span`,{className:`shrink-0 tabular-nums text-ink-base`,children:[`$`,e.estimatedCostUsd.toFixed(2)]})]},e.turnId))})]}):(0,x.jsx)(`div`,{className:`py-2 text-center text-xs text-ink-muted`,children:`No turn-cost data yet.`})})]}),(0,x.jsxs)(`section`,{"aria-label":`Context timeline`,children:[(0,x.jsx)(V,{className:`mb-3`,children:`Context Timeline`}),(0,x.jsx)(B,{tone:`static`,padding:`sm`,children:d?(0,x.jsx)(pH,{history:n??[],contextWindow:r??0}):(0,x.jsx)(`div`,{className:`py-2 text-center text-xs text-ink-muted`,children:`No context timeline data yet.`})})]}),(0,x.jsxs)(`section`,{"aria-label":`Context composition and efficiency`,children:[(0,x.jsx)(V,{className:`mb-3`,children:`Context Composition & Efficiency`}),(0,x.jsx)(B,{tone:`static`,padding:`sm`,children:!i&&!a?(0,x.jsx)(`div`,{className:`py-2 text-center text-xs text-ink-muted`,children:`No composition/efficiency data yet.`}):(0,x.jsxs)(`div`,{className:`space-y-2 text-xs`,children:[i&&(0,x.jsxs)(`div`,{className:`text-ink-muted`,children:[`Dominant this turn:`,` `,(0,x.jsx)(`span`,{className:`text-ink-base`,children:Object.entries(i.currentBreakdown).sort((e,t)=>t[1]-e[1])[0]?.[0]})]}),a&&a.repeatedReadRatio!==null&&(0,x.jsxs)(`div`,{className:`text-ink-muted`,children:[`Repeated reads:`,` `,(0,x.jsxs)(`span`,{className:`text-ink-base`,children:[Math.round(a.repeatedReadRatio*100),`%`]}),a.topRepeatedFiles[0]&&(0,x.jsxs)(x.Fragment,{children:[` `,`— top:`,` `,(0,x.jsx)(`code`,{className:`bg-surface-5 px-1 rounded`,children:a.topRepeatedFiles[0].file}),` `,`(`,a.topRepeatedFiles[0].readCount,`x)`]})]})]})})]})]})]})]}),document.body)}function yH({label:e,value:t}){return(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`div`,{className:`text-[10px] text-ink-muted uppercase tracking-wider`,children:e}),(0,x.jsx)(`div`,{className:`text-sm font-bold tabular-nums text-ink-base mt-0.5`,children:t})]})}var bH=`nr-observe-peak-concurrent`;function xH({current:e,peak:t,allTimePeak:n,buckets:r}){let[i,a]=(0,b.useState)(!1),o=(0,b.useRef)(null),s=r.some(e=>e.count>0);(0,b.useEffect)(()=>{let e=n??t;if(e<=0)return;let r=parseInt(localStorage.getItem(bH)??`0`,10);if(o.current===null&&(o.current=r),e>o.current){localStorage.setItem(bH,String(e)),o.current=e,a(!0);let t=setTimeout(()=>a(!1),3e3);return()=>clearTimeout(t)}},[t,n]);let c=r.map(e=>{let t=new Date(e.timestamp).toLocaleTimeString(void 0,{hour:`numeric`,minute:`2-digit`});return{count:e.count,tooltip:`${t} — ${e.count} concurrent`}});return(0,x.jsxs)(B,{padding:`sm`,className:`relative overflow-hidden${i?` new-peak-glow`:``}`,children:[i&&(0,x.jsx)(SH,{}),(0,x.jsx)(V,{className:`mb-1.5`,children:`Concurrent Sessions`}),(0,x.jsxs)(`div`,{className:`flex items-baseline gap-3`,children:[(0,x.jsx)(`span`,{className:`text-lg font-semibold text-accent-teal tabular-nums`,children:e}),(0,x.jsxs)(`span`,{className:`text-xs text-ink-muted tabular-nums`,children:[`today peak `,t,n&&n>t?` · all-time ${n}`:``]}),i&&(0,x.jsx)(`span`,{className:`text-[10px] text-accent-green font-semibold animate-bounce`,children:`NEW RECORD!`})]}),s&&(0,x.jsx)(`div`,{className:`mt-2`,children:(0,x.jsx)(pV,{data:c,ariaLabel:`Concurrency over time, peak ${t}`})})]})}function SH(){let e=Array.from({length:12},(e,t)=>{let n=t/12*360,r=40+Math.random()*30;return(0,x.jsx)(`span`,{className:`absolute w-1.5 h-1.5 rounded-full`,style:{left:`50%`,top:`50%`,backgroundColor:t%3==0?`#1CE783`:t%3==1?`#00D4AA`:`#9945FF`,animation:`particle-burst 1s ease-out forwards`,animationDelay:`${t*40}ms`,transform:`translate(-50%, -50%) rotate(${n}deg) translateY(-${r}px)`,opacity:0}},t)});return(0,x.jsx)(x.Fragment,{children:e})}var CH=[`var(--color-heatmap-0)`,`var(--color-heatmap-1)`,`var(--color-heatmap-2)`,`var(--color-heatmap-3)`,`var(--color-heatmap-4)`];function wH(e,t){if(e===0)return CH[0];let n=e/t;return CH[Math.min(Math.ceil(n*4),4)]}function TH(e,t,n){let r=e+n*t;return new Date(r).toLocaleTimeString(void 0,{hour:`numeric`,minute:`2-digit`})}function EH({variant:e,buckets:t,maxCount:n,bucketSizeMs:r,startTimestamp:i,width:a,height:o,ariaLabel:s,days:c}){return e===`grid`&&c?(0,x.jsx)(kH,{days:c,maxCount:n,width:a,height:o,ariaLabel:s}):(0,x.jsx)(DH,{buckets:t,maxCount:n,bucketSizeMs:r,startTimestamp:i,width:a,height:o,ariaLabel:s})}function DH({buckets:e,maxCount:t,bucketSizeMs:n=9e5,startTimestamp:r=0,width:i,height:a=24,ariaLabel:o}){let[s,c]=(0,b.useState)(null),l=Math.max(4,Math.min(12,i?(i-e.length*1)/e.length:8)),u=i??e.length*(l+1);return(0,x.jsxs)(`div`,{className:`relative`,children:[(0,x.jsx)(`svg`,{width:u,height:a,role:`img`,"aria-label":o??`Activity heatmap: ${e.length} time buckets`,className:`w-full`,style:{maxWidth:u},viewBox:`0 0 ${u} ${a}`,preserveAspectRatio:`none`,onMouseLeave:()=>c(null),children:e.map((e,i)=>(0,x.jsx)(`rect`,{x:i*(l+1),y:0,width:l,height:a,rx:2,fill:wH(e,t),className:`heatmap-cell`,style:{animationDelay:`${Math.min(i*8,400)}ms`},onMouseEnter:t=>{let a=TH(r,n,i);c({x:t.currentTarget.x.baseVal.value,text:`${a}: ${e} calls`})}},i))}),s&&(0,x.jsx)(`div`,{className:`absolute -top-7 px-1.5 py-0.5 bg-bg-elevated border border-border-subtle text-[10px] text-ink-base rounded-md shadow-md pointer-events-none whitespace-nowrap tabular-nums`,style:{left:s.x},children:s.text})]})}var OH=[`Mon`,``,`Wed`,``,`Fri`,``,`Sun`];function kH({days:e,maxCount:t,ariaLabel:n}){let[r,i]=(0,b.useState)(null),a=(0,b.useMemo)(()=>{if(e.length===0)return{weeks:0,cells:[]};let t=(new Date(e[0].date).getUTCDay()+6)%7,n=[];for(let r=0;r<e.length;r++){let i=r+t,a=i%7,o=Math.floor(i/7);n.push({...e[r],row:a,col:o})}return{weeks:n.length>0?n[n.length-1].col+1:0,cells:n}},[e]),o=28+a.weeks*12,s=(0,b.useMemo)(()=>{let e=[],t=``;for(let n of a.cells){if(n.row!==0)continue;let r=new Date(n.date).toLocaleString(void 0,{month:`short`,timeZone:`UTC`});r!==t&&(e.push({text:r,col:n.col}),t=r)}return e},[a.cells]);return(0,x.jsxs)(`div`,{className:`relative flex justify-center`,children:[(0,x.jsxs)(`svg`,{width:`100%`,height:98,role:`img`,"aria-label":n??`Activity grid: ${e.length} days`,viewBox:`0 0 ${o} 98`,preserveAspectRatio:`xMidYMid meet`,onMouseLeave:()=>i(null),children:[OH.map((e,t)=>e?(0,x.jsx)(`text`,{x:0,y:14+t*12+10-2,className:`fill-ink-muted`,fontSize:10,children:e},t):null),s.map(({text:e,col:t})=>(0,x.jsx)(`text`,{x:28+t*12,y:10,className:`fill-ink-muted`,fontSize:10,children:e},`${e}-${t}`)),a.cells.map((e,n)=>(0,x.jsx)(`rect`,{x:28+e.col*12,y:14+e.row*12,width:10,height:10,rx:2,fill:wH(e.count,t),className:`heatmap-cell`,style:{animationDelay:`${Math.min(n*3,300)}ms`},onMouseEnter:t=>{let n=t.currentTarget;i({x:n.x.baseVal.value,y:n.y.baseVal.value-16,text:`${e.date}: ${e.count} calls`})}},n))]}),r&&(0,x.jsx)(`div`,{className:`absolute px-1.5 py-0.5 bg-bg-elevated border border-border-subtle text-[10px] text-ink-base rounded-md shadow-md pointer-events-none whitespace-nowrap tabular-nums`,style:{left:r.x,top:r.y},children:r.text}),(0,x.jsxs)(`div`,{className:`flex items-center gap-1 mt-1.5 text-[10px] text-ink-muted`,children:[(0,x.jsx)(`span`,{children:`Less`}),CH.map((e,t)=>(0,x.jsx)(`span`,{className:`inline-block w-2.5 h-2.5 rounded-sm`,style:{backgroundColor:e}},t)),(0,x.jsx)(`span`,{children:`More`})]})]})}function AH({theme:e=`observatory`}){return(0,x.jsxs)(`div`,{className:`geo-banner`,"aria-hidden":`true`,children:[e===`observatory`&&(0,x.jsx)(jH,{}),e===`sessions`&&(0,x.jsx)(MH,{}),e===`history`&&(0,x.jsx)(NH,{}),e===`audit`&&(0,x.jsx)(PH,{}),e===`git`&&(0,x.jsx)(FH,{})]})}function jH(){return(0,x.jsxs)(`svg`,{viewBox:`0 0 800 80`,preserveAspectRatio:`xMidYMid slice`,className:`w-full h-full`,children:[(0,x.jsx)(`defs`,{children:(0,x.jsxs)(`linearGradient`,{id:`obsSky`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,x.jsx)(`stop`,{offset:`0%`,stopColor:`#1a3a5c`}),(0,x.jsx)(`stop`,{offset:`40%`,stopColor:`#2d5a7b`}),(0,x.jsx)(`stop`,{offset:`70%`,stopColor:`#e8834a`}),(0,x.jsx)(`stop`,{offset:`100%`,stopColor:`#f4a261`})]})}),(0,x.jsx)(`rect`,{width:`800`,height:`80`,fill:`url(#obsSky)`}),(0,x.jsx)(`polygon`,{points:`0,80 0,45 80,38 160,48 240,30 340,42 420,25 500,38 580,32 660,40 740,28 800,35 800,80`,fill:`#1a3a5c`,opacity:`0.7`}),(0,x.jsx)(`polygon`,{points:`0,80 0,55 60,48 140,58 220,42 300,52 380,40 460,50 520,38 600,48 680,42 760,52 800,48 800,80`,fill:`#234e6f`}),(0,x.jsx)(`polygon`,{points:`0,80 0,62 100,58 200,65 300,55 400,60 500,54 600,62 700,56 800,60 800,80`,fill:`#2a6b4a`,opacity:`0.8`}),(0,x.jsx)(`circle`,{cx:`680`,cy:`28`,r:`14`,fill:`#f4a261`,opacity:`0.6`}),(0,x.jsx)(`circle`,{cx:`680`,cy:`28`,r:`8`,fill:`#ffd166`,opacity:`0.5`}),(0,x.jsx)(`ellipse`,{cx:`150`,cy:`56`,rx:`18`,ry:`10`,fill:`#1a3a5c`}),(0,x.jsx)(`line`,{x1:`150`,y1:`46`,x2:`172`,y2:`34`,stroke:`#5ce0d8`,strokeWidth:`1.5`,opacity:`0.8`})]})}function MH(){return(0,x.jsxs)(`svg`,{viewBox:`0 0 800 80`,preserveAspectRatio:`xMidYMid slice`,className:`w-full h-full`,children:[(0,x.jsx)(`defs`,{children:(0,x.jsxs)(`linearGradient`,{id:`seaSky`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,x.jsx)(`stop`,{offset:`0%`,stopColor:`#4aa8c7`}),(0,x.jsx)(`stop`,{offset:`60%`,stopColor:`#3a8fb7`}),(0,x.jsx)(`stop`,{offset:`100%`,stopColor:`#2d7a9e`})]})}),(0,x.jsx)(`rect`,{width:`800`,height:`80`,fill:`url(#seaSky)`}),(0,x.jsx)(`polygon`,{points:`600,48 640,35 680,48`,fill:`#2d7a4a`,opacity:`0.4`}),(0,x.jsx)(`polygon`,{points:`700,50 730,40 760,50`,fill:`#3d9b5b`,opacity:`0.3`}),(0,x.jsx)(`polygon`,{points:`0,80 0,15 40,12 80,20 120,18 160,25 180,30 180,80`,fill:`#c05a3c`}),(0,x.jsx)(`polygon`,{points:`0,80 0,25 30,22 60,28 100,25 140,30 160,35 160,80`,fill:`#e8834a`,opacity:`0.6`}),(0,x.jsx)(`polygon`,{points:`20,20 35,8 50,20`,fill:`#3d9b5b`}),(0,x.jsx)(`polygon`,{points:`60,22 72,12 84,24`,fill:`#4aad6b`}),(0,x.jsx)(`polygon`,{points:`100,20 115,10 130,22`,fill:`#3d9b5b`}),(0,x.jsx)(`polygon`,{points:`140,28 150,18 160,28`,fill:`#4aad6b`,opacity:`0.8`}),(0,x.jsx)(`rect`,{x:`120`,y:`30`,width:`8`,height:`50`,fill:`#87ceeb`,opacity:`0.5`}),(0,x.jsx)(`rect`,{x:`122`,y:`30`,width:`4`,height:`50`,fill:`#fff`,opacity:`0.3`}),(0,x.jsx)(`polygon`,{points:`620,80 620,30 660,25 700,32 740,28 780,35 800,30 800,80`,fill:`#c05a3c`,opacity:`0.8`}),(0,x.jsx)(`polygon`,{points:`650,30 665,18 680,30`,fill:`#3d9b5b`}),(0,x.jsx)(`polygon`,{points:`720,32 732,22 744,32`,fill:`#4aad6b`}),(0,x.jsx)(`polygon`,{points:`180,80 180,55 250,52 350,56 450,52 550,55 620,52 620,80`,fill:`#2d7a9e`,opacity:`0.6`}),(0,x.jsx)(`line`,{x1:`200`,y1:`60`,x2:`280`,y2:`58`,stroke:`#5ce0d8`,strokeWidth:`0.8`,opacity:`0.3`}),(0,x.jsx)(`line`,{x1:`350`,y1:`56`,x2:`450`,y2:`55`,stroke:`#5ce0d8`,strokeWidth:`0.8`,opacity:`0.25`}),(0,x.jsx)(`line`,{x1:`480`,y1:`58`,x2:`580`,y2:`56`,stroke:`#87ceeb`,strokeWidth:`0.8`,opacity:`0.3`})]})}function NH(){return(0,x.jsxs)(`svg`,{viewBox:`0 0 800 80`,preserveAspectRatio:`xMidYMid slice`,className:`w-full h-full`,children:[(0,x.jsx)(`defs`,{children:(0,x.jsxs)(`linearGradient`,{id:`histSky`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,x.jsx)(`stop`,{offset:`0%`,stopColor:`#3a7ca5`}),(0,x.jsx)(`stop`,{offset:`60%`,stopColor:`#5bb8d4`}),(0,x.jsx)(`stop`,{offset:`100%`,stopColor:`#8ed4c0`})]})}),(0,x.jsx)(`rect`,{width:`800`,height:`80`,fill:`url(#histSky)`}),(0,x.jsx)(`polygon`,{points:`100,50 140,20 180,50`,fill:`#e8834a`,opacity:`0.7`}),(0,x.jsx)(`polygon`,{points:`160,50 210,15 260,50`,fill:`#d4694a`,opacity:`0.6`}),(0,x.jsx)(`polygon`,{points:`550,50 600,18 650,50`,fill:`#e8834a`,opacity:`0.6`}),(0,x.jsx)(`polygon`,{points:`620,50 660,22 700,50`,fill:`#c05a3c`,opacity:`0.5`}),(0,x.jsx)(`polygon`,{points:`350,50 370,12 390,50`,fill:`#5ce0d8`,opacity:`0.4`}),(0,x.jsx)(`polygon`,{points:`380,50 395,20 410,50`,fill:`#87ceeb`,opacity:`0.3`}),(0,x.jsx)(`polygon`,{points:`700,50 715,25 730,50`,fill:`#5ce0d8`,opacity:`0.35`}),(0,x.jsx)(`polygon`,{points:`300,80 380,50 420,50 500,80`,fill:`#2a5a6b`,opacity:`0.6`}),(0,x.jsx)(`line`,{x1:`390`,y1:`52`,x2:`350`,y2:`78`,stroke:`#f4a261`,strokeWidth:`1`,opacity:`0.4`}),(0,x.jsx)(`line`,{x1:`410`,y1:`52`,x2:`450`,y2:`78`,stroke:`#f4a261`,strokeWidth:`1`,opacity:`0.4`}),(0,x.jsx)(`polygon`,{points:`0,80 0,55 80,52 160,58 240,50 320,55 500,52 580,56 660,50 740,55 800,52 800,80`,fill:`#2d8a4a`,opacity:`0.5`}),(0,x.jsx)(`polygon`,{points:`0,80 0,65 60,62 140,68 220,60 400,65 500,62 600,66 700,60 800,65 800,80`,fill:`#1e6b3a`,opacity:`0.6`}),(0,x.jsx)(`polygon`,{points:`30,65 42,42 54,65`,fill:`#3d9b5b`,opacity:`0.8`}),(0,x.jsx)(`polygon`,{points:`50,65 60,48 70,65`,fill:`#2d8a4a`,opacity:`0.7`}),(0,x.jsx)(`polygon`,{points:`720,65 732,45 744,65`,fill:`#3d9b5b`,opacity:`0.7`}),(0,x.jsx)(`polygon`,{points:`760,65 770,50 780,65`,fill:`#2d8a4a`,opacity:`0.8`})]})}function PH(){return(0,x.jsxs)(`svg`,{viewBox:`0 0 800 80`,preserveAspectRatio:`xMidYMid slice`,className:`w-full h-full`,children:[(0,x.jsx)(`defs`,{children:(0,x.jsxs)(`linearGradient`,{id:`auditSky`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,x.jsx)(`stop`,{offset:`0%`,stopColor:`#1a5c3a`}),(0,x.jsx)(`stop`,{offset:`50%`,stopColor:`#2d7a4a`}),(0,x.jsx)(`stop`,{offset:`100%`,stopColor:`#3d9b5b`})]})}),(0,x.jsx)(`rect`,{width:`800`,height:`80`,fill:`url(#auditSky)`}),(0,x.jsx)(`polygon`,{points:`200,0 210,80 220,0`,fill:`#ffd166`,opacity:`0.08`}),(0,x.jsx)(`polygon`,{points:`500,0 510,80 520,0`,fill:`#ffd166`,opacity:`0.06`}),(0,x.jsx)(`polygon`,{points:`650,0 660,80 670,0`,fill:`#fff`,opacity:`0.05`}),(0,x.jsx)(`rect`,{x:`80`,y:`20`,width:`6`,height:`60`,fill:`#1a4a2e`}),(0,x.jsx)(`rect`,{x:`180`,y:`10`,width:`7`,height:`70`,fill:`#1a4a2e`}),(0,x.jsx)(`rect`,{x:`320`,y:`15`,width:`6`,height:`65`,fill:`#1a4a2e`}),(0,x.jsx)(`rect`,{x:`500`,y:`8`,width:`7`,height:`72`,fill:`#1a4a2e`}),(0,x.jsx)(`rect`,{x:`620`,y:`18`,width:`6`,height:`62`,fill:`#1a4a2e`}),(0,x.jsx)(`rect`,{x:`740`,y:`12`,width:`7`,height:`68`,fill:`#1a4a2e`}),(0,x.jsx)(`polygon`,{points:`55,25 83,5 111,25`,fill:`#4aad6b`}),(0,x.jsx)(`polygon`,{points:`60,35 83,15 106,35`,fill:`#3d9b5b`}),(0,x.jsx)(`polygon`,{points:`155,15 183,0 211,18`,fill:`#5bc47a`}),(0,x.jsx)(`polygon`,{points:`160,28 183,8 206,28`,fill:`#4aad6b`}),(0,x.jsx)(`polygon`,{points:`295,20 323,2 351,22`,fill:`#5bc47a`}),(0,x.jsx)(`polygon`,{points:`300,32 323,12 346,32`,fill:`#3d9b5b`}),(0,x.jsx)(`polygon`,{points:`475,12 503,0 531,15`,fill:`#4aad6b`}),(0,x.jsx)(`polygon`,{points:`480,25 503,5 526,25`,fill:`#3d9b5b`}),(0,x.jsx)(`polygon`,{points:`595,22 623,5 651,22`,fill:`#5bc47a`}),(0,x.jsx)(`polygon`,{points:`600,34 623,14 646,34`,fill:`#4aad6b`}),(0,x.jsx)(`polygon`,{points:`715,16 743,0 771,18`,fill:`#5bc47a`}),(0,x.jsx)(`polygon`,{points:`720,30 743,10 766,30`,fill:`#3d9b5b`}),(0,x.jsx)(`polygon`,{points:`0,80 0,68 100,65 200,70 300,64 400,68 500,63 600,67 700,64 800,68 800,80`,fill:`#1e6b3a`}),(0,x.jsx)(`polygon`,{points:`250,80 258,65 266,80`,fill:`#e8834a`,opacity:`0.6`}),(0,x.jsx)(`polygon`,{points:`450,80 456,68 462,80`,fill:`#f4a261`,opacity:`0.5`}),(0,x.jsx)(`polygon`,{points:`650,80 656,66 662,80`,fill:`#e8834a`,opacity:`0.55`})]})}function FH(){return(0,x.jsxs)(`svg`,{viewBox:`0 0 800 80`,preserveAspectRatio:`xMidYMid slice`,className:`w-full h-full`,children:[(0,x.jsx)(`defs`,{children:(0,x.jsxs)(`linearGradient`,{id:`gitSky`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,x.jsx)(`stop`,{offset:`0%`,stopColor:`#2d5a7b`}),(0,x.jsx)(`stop`,{offset:`60%`,stopColor:`#3a8fb7`}),(0,x.jsx)(`stop`,{offset:`100%`,stopColor:`#5bb8d4`})]})}),(0,x.jsx)(`rect`,{width:`800`,height:`80`,fill:`url(#gitSky)`}),(0,x.jsx)(`polygon`,{points:`0,80 0,20 60,25 120,18 180,28 220,22 260,30 260,80`,fill:`#2d7a4a`,opacity:`0.7`}),(0,x.jsx)(`polygon`,{points:`540,80 540,22 600,28 660,20 720,25 780,18 800,22 800,80`,fill:`#2d7a4a`,opacity:`0.7`}),(0,x.jsx)(`path`,{d:`M 260,50 Q 320,48 400,45 Q 480,42 540,50`,fill:`none`,stroke:`#5ce0d8`,strokeWidth:`4`,opacity:`0.5`}),(0,x.jsx)(`path`,{d:`M 350,45 Q 370,35 400,28`,fill:`none`,stroke:`#87ceeb`,strokeWidth:`2`,opacity:`0.4`}),(0,x.jsx)(`path`,{d:`M 420,44 Q 440,52 470,60`,fill:`none`,stroke:`#87ceeb`,strokeWidth:`2`,opacity:`0.4`}),(0,x.jsx)(`path`,{d:`M 400,28 Q 430,25 460,30`,fill:`none`,stroke:`#5ce0d8`,strokeWidth:`1.5`,opacity:`0.35`}),(0,x.jsx)(`circle`,{cx:`400`,cy:`45`,r:`3`,fill:`#5ce0d8`,opacity:`0.6`}),(0,x.jsx)(`circle`,{cx:`350`,cy:`45`,r:`2`,fill:`#1ce783`,opacity:`0.5`}),(0,x.jsx)(`circle`,{cx:`460`,cy:`44`,r:`2`,fill:`#1ce783`,opacity:`0.5`}),(0,x.jsx)(`polygon`,{points:`300,65 310,55 320,65`,fill:`#3a6b4a`,opacity:`0.6`}),(0,x.jsx)(`polygon`,{points:`480,62 492,52 504,62`,fill:`#3a6b4a`,opacity:`0.6`}),(0,x.jsx)(`polygon`,{points:`240,35 250,18 260,35`,fill:`#4aad6b`}),(0,x.jsx)(`polygon`,{points:`540,35 550,20 560,35`,fill:`#4aad6b`}),(0,x.jsx)(`polygon`,{points:`270,50 278,38 286,50`,fill:`#3d9b5b`,opacity:`0.8`}),(0,x.jsx)(`polygon`,{points:`520,48 528,36 536,48`,fill:`#3d9b5b`,opacity:`0.8`})]})}function IH(e){return new Intl.DateTimeFormat(`en-US`,{timeZone:e}).resolvedOptions().timeZone}var LH=new Map;function RH(e){let t=IH(e),n=LH.get(t);return n||(n=new Intl.DateTimeFormat(`en-US`,{timeZone:t,year:`numeric`,month:`2-digit`,day:`2-digit`}),LH.set(t,n)),n}var zH=new Map;function BH(e){let t=IH(e),n=zH.get(t);return n||(n=new Intl.DateTimeFormat(`en-US`,{timeZone:t,year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`,hour12:!1}),zH.set(t,n)),n}function VH(e,t){let n=RH(t).formatToParts(e),r=0,i=0,a=0;for(let e of n)e.type===`year`?r=Number(e.value):e.type===`month`?i=Number(e.value):e.type===`day`&&(a=Number(e.value));return{year:r,month:i,day:a}}function HH(e,t){let n=BH(t).formatToParts(e),r={};for(let e of n)e.type!==`literal`&&(r[e.type]=Number(e.value));let i=r.hour===24?0:r.hour;return Date.UTC(r.year,r.month-1,r.day,i,r.minute,r.second)-e}function UH(e,t,n,r){let i=Date.UTC(e,t-1,n),a=HH(i,r),o=i-a,s=HH(o,r);if(s===a)return o;let c=i-s,l=VH(c,r);return l.year===e&&l.month===t&&l.day===n?c:o}function WH(e,t){if(t){let{year:n,month:r,day:i}=VH(e??Date.now(),t);return UH(n,r,i,t)}let n=e==null?new Date:new Date(e);return n.setHours(0,0,0,0),n.getTime()}function GH(e,t,n){if(n){let r=VH(e,n),i=VH(t??Date.now(),n);return r.year===i.year&&r.month===i.month&&r.day===i.day}let r=new Date(e),i=t==null?new Date:new Date(t);return r.getFullYear()===i.getFullYear()&&r.getMonth()===i.getMonth()&&r.getDate()===i.getDate()}function KH(e,t){let n=WH(t),r=n+864e5;if(e.endTime<n||e.startTime>=r)return 0;if(e.startTime>=n&&e.endTime<r)return 1;if(e.timeline&&e.timeline.length>0){let t=e.timeline.length,i=e.timeline.filter(e=>e.timestamp>=n&&e.timestamp<r).length;if(t>0)return i/t}return(Math.min(e.endTime,r)-Math.max(e.startTime,n))/Math.max(1,e.endTime-e.startTime)}var qH={weekday:`short`,month:`short`,day:`numeric`,hour:`numeric`,minute:`2-digit`},JH=3e4,YH={info:`text-ink-muted`,warning:`text-accent-amber`,critical:`text-accent-red`};function XH(e,t){return e===`clean`?`No compute waste detected this session.`:(t===null?null:{stuck_loop:`Address the command output before re-running the same command.`,re_reading:`Read each file once and keep relevant sections in mind.`,thrashing:`Read the test failure output carefully before editing again.`,blind_editing:`Verify changes with tests between edit batches.`,over_delegation:`Multiple sub-agent spawns failed or were interrupted — investigate why before retrying.`}[t]??null)??`Review anti-patterns to reduce repeated tool calls.`}var ZH=1e4,QH={fill:`var(--color-ink-muted)`,fontSize:10},$H=`var(--color-border-subtle)`,eU={background:`var(--color-bg-elevated)`,border:`1px solid var(--color-border-medium)`,borderRadius:8,fontSize:12,color:`var(--color-ink-base)`},tU={color:`var(--color-ink-base)`};function nU(e){return e===`Read`?`var(--color-accent-blue)`:e===`Edit`||e===`Write`?`var(--color-accent-green)`:e===`Bash`?`var(--color-accent-purple)`:e===`Agent`?`var(--color-accent-teal)`:`var(--color-ink-muted)`}function rU(){let e=qn(e=>e.cost),t=qn(e=>e.antiPatterns),n=Zn(),{data:r}=L({queryKey:[`observability-health`],queryFn:Br,refetchInterval:3e4}),{data:i,isPending:a}=L({queryKey:z.cost,queryFn:or,refetchInterval:1e4}),{data:o,isPending:s}=L({queryKey:z.sessionsTodayAggregate,queryFn:rr,refetchInterval:1e4}),{data:c,isPending:l}=L({queryKey:z.sessionsList(200),queryFn:()=>nr(200),refetchInterval:1e4}),{data:u,isPending:d}=L({queryKey:z.antiPatterns,queryFn:sr}),{data:f,isPending:p}=L({queryKey:z.concurrency,queryFn:Dr,refetchInterval:1e4}),{data:m,isPending:h}=L({queryKey:z.activityHeatmap(`today`),queryFn:()=>kr(`today`),refetchInterval:3e4}),{data:g,isPending:_}=L({queryKey:z.sessionsLive,queryFn:ir,refetchInterval:1e4}),v=(0,b.useMemo)(()=>SU(c??[]),[c]),y=(0,b.useMemo)(()=>CU(c??[]),[c]),S=(0,b.useMemo)(()=>wU(c??[]),[c]),C=(0,b.useMemo)(()=>jU(c??[]),[c]),w=(0,b.useMemo)(()=>(c??[]).flatMap(e=>e.antiPatterns??[]),[c]),T=Math.max(o?.toolCallCount??0,y),E=(a||l||s)&&!e&&v===0&&o===void 0,D=Math.max(e?.todayTotalUsd??0,o?.totalCostUsd??0,v,i?.sessionTodayUsd??0),O=Math.max(u?.length??0,t.length),k=Math.max(o?.antiPatternCount??0,S+O),A=Math.max(o?.subagentUsd??0,n.usd),j=Math.max(o?.subagentTurnCount??0,n.turns),M=o!==void 0||n.turns>0,N=o&&o.totalCostUsd>=D?o.totalCostUsd:D,ee=o&&o.totalCostUsd>=D?o.subagentUsd??0:A,[te,P]=(0,b.useState)(()=>new Date().toLocaleString(void 0,qH)),F=(0,b.useRef)(Date.now());(0,b.useEffect)(()=>{let e=setInterval(()=>{let e=Date.now();P(new Date(e).toLocaleString(void 0,qH)),GH(e,F.current)||(F.current=e,qn.getState().handleDayRollover())},6e4);return()=>clearInterval(e)},[]);let ne=o?.avgEfficiencyScore??null,re=ne!==null&&Number.isFinite(ne)?`${Math.round(ne*100)}%`:`—`,ie=ne===null?`needs more data`:Math.round(ne*100)>=80?`strong session`:Math.round(ne*100)>=50?`mixed signals`:`needs attention`;return(0,x.jsxs)(`section`,{children:[(0,x.jsx)(AH,{}),(0,x.jsxs)(`header`,{className:`flex items-baseline justify-between mb-4`,children:[(0,x.jsx)(`h1`,{className:`text-xl font-semibold gradient-text`,children:`Today`}),(0,x.jsx)(`span`,{className:`text-xs text-ink-muted`,children:te})]}),!E&&!s&&!l&&!d&&!p&&!h&&!_&&T===0&&D===0&&k===0?(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(cV,{index:0,className:`glass-card p-8 mb-4`,children:(0,x.jsx)($,{icon:`code`,title:`No activity yet today`,subtitle:`Metrics will appear here once you start a coding session with Claude.`})}),(0,x.jsx)(cV,{index:1,className:`mb-3`,children:(0,x.jsx)(iU,{})}),(0,x.jsx)(cV,{index:2,children:(0,x.jsx)(aU,{})}),(0,x.jsx)(cV,{index:3,children:(0,x.jsx)(_U,{})})]}):(0,x.jsxs)(x.Fragment,{children:[r?.watcherActive===!1&&j===0&&r?.watcherDisabledReason!==`mode_mismatch`&&(0,x.jsxs)(`div`,{className:`rounded-lg border border-border-subtle bg-surface-5 px-4 py-3 text-sm text-ink-muted mb-4`,children:[`Subagent cost tracking is disabled (`,(0,x.jsx)(`code`,{className:`font-mono text-xs`,children:`NR_AI_ENABLE_SUBAGENT_WATCHER=0`}),`), so spend shown here excludes subagents. Unset that variable (it is on by default) and restart to see full spend.`]}),r?.watcherActive===!1&&j===0&&r?.watcherDisabledReason===`mode_mismatch`&&(0,x.jsxs)(`div`,{className:`rounded-lg border border-border-subtle bg-surface-5 px-4 py-3 text-sm text-ink-muted mb-4`,children:[`This dashboard process isn’t running its own subagent watcher — expected for a background `,(0,x.jsx)(`code`,{className:`font-mono text-xs`,children:`--local`}),` dashboard (the watcher only auto-starts in `,(0,x.jsx)(`code`,{className:`font-mono text-xs`,children:`--stdio`}),` mode). Spend shown here still includes subagent activity from other sessions, read from their persisted totals. To track subagents live from this process too, set`,` `,(0,x.jsx)(`code`,{className:`font-mono text-xs`,children:`NR_AI_WATCHER_MODE=local`}),` and restart.`]}),(0,x.jsx)(cV,{index:0,className:`mb-4`,children:(0,x.jsx)(B,{padding:`lg`,tone:`elevated`,glow:`green`,children:(0,x.jsxs)(`div`,{className:`grid grid-cols-5 gap-4`,children:[(0,x.jsx)(sV,{label:`efficiency`,hero:!0,value:re,sub:ie,...ne===null?{}:{animate:!0,numericValue:Math.round(ne*100),suffix:`%`}}),(0,x.jsx)(sV,{label:`spend today`,tone:`good`,value:E?`…`:Ci(D),...E?{}:{animate:!0,numericValue:D,format:Ci}}),(0,x.jsx)(sV,{label:`subagent spend`,value:M?Ci(A):`—`,sub:`${j} turns`,...M?{animate:!0,numericValue:A,format:Ci}:{}}),(0,x.jsx)(sV,{label:`tool calls`,value:String(T),animate:!0,numericValue:T}),(0,x.jsx)(sV,{label:`flags`,tone:k>0?`warn`:`neutral`,value:String(k),animate:!0,numericValue:k})]})})}),(0,x.jsxs)(cV,{index:1,className:`grid grid-cols-2 gap-3 mb-3`,children:[(0,x.jsx)(MU,{todayTotal:N,forecastEod:E?null:e?.forecastEodUsd??o?.forecastEndOfDayUsd??i?.forecast?.forecastEndOfDayUsd??null,hourlySpend:C,subagentUsd:ee,forecastSessionEnd:i?.forecast?.forecastSessionEndUsd??null,forecastWeek:i?.forecast?.forecastEndOfWeekUsd??null,confidenceNote:i?.forecast?.confidenceNote??null}),f&&f.buckets&&(0,x.jsx)(xH,{current:f.current,peak:f.peak,allTimePeak:f.allTimePeak,bucketSizeMs:f.bucketSizeMs,startTimestamp:f.startTimestamp,buckets:f.buckets})]}),k>0&&(0,x.jsx)(cV,{index:2,className:`mb-3`,children:(0,x.jsx)(B,{padding:`sm`,tone:`warning`,className:`text-xs`,children:t.length>0?(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(ni,{tone:`warning`,size:`sm`,className:`mr-2`,children:t[0].type}),(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`— `}),(0,x.jsxs)(`span`,{children:[t[0].count,`× on `]}),(0,x.jsx)(`code`,{className:`bg-surface-5 px-1 rounded`,children:t[0].target}),t[0].sessionId&&(0,x.jsxs)(ni,{tone:`neutral`,size:`sm`,className:`ml-2`,children:[`Session: `,gU(t[0].sessionId,g??[])]})]}):u&&u.length>0?(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(ni,{tone:`warning`,size:`sm`,className:`mr-2`,children:u[0].type}),(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`— `}),(0,x.jsxs)(`span`,{children:[u[0].count??u[0].iterations??u[0].readCount??u[0].repeatCount??u[0].editCount??u[0].agentCount??`?`,`× on`,` `]}),(0,x.jsx)(`code`,{className:`bg-surface-5 px-1 rounded`,children:u[0].file??u[0].command??`unknown`})]}):w.length>0?(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(ni,{tone:`warning`,size:`sm`,className:`mr-2`,children:w[0].type}),(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`— `}),(0,x.jsxs)(`span`,{children:[w[0].count??w[0].iterations??w[0].readCount??w[0].repeatCount??w[0].editCount??w[0].agentCount??`?`,`× on`,` `]}),(0,x.jsx)(`code`,{className:`bg-surface-5 px-1 rounded`,children:w[0].file??w[0].command??`unknown`})]}):(0,x.jsxs)(`span`,{children:[k,` flag(s) detected today — details unavailable.`]})})}),(0,x.jsxs)(cV,{index:3,className:`grid grid-cols-3 gap-3 mb-3`,children:[(0,x.jsx)(oU,{}),(0,x.jsx)(sU,{}),(0,x.jsx)(cU,{}),(0,x.jsx)(lU,{aggregate:o}),(0,x.jsx)(pU,{liveSessions:g??[]}),(0,x.jsx)(uU,{}),(0,x.jsx)(fU,{aggregate:o}),(0,x.jsx)(`div`,{className:`col-span-3`,children:(0,x.jsx)(iU,{})}),(0,x.jsx)(`div`,{className:`col-span-3`,children:(0,x.jsx)(aU,{})})]}),(0,x.jsx)(cV,{index:4,children:(0,x.jsx)(hU,{sessions:c??[],liveSessions:g??[]})}),m&&m.buckets?.length>0&&(0,x.jsx)(cV,{index:5,className:`mb-3`,children:(0,x.jsxs)(B,{padding:`sm`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-1.5 mb-2`,children:[(0,x.jsx)(V,{children:`Activity Today`}),(0,x.jsx)(ui,{text:`Tool-call activity in 15-minute blocks across today. Darker blocks mean more calls in that window.`})]}),(0,x.jsx)(EH,{variant:`strip`,buckets:m.buckets,maxCount:m.maxCount,bucketSizeMs:m.bucketSizeMs,startTimestamp:m.startTimestamp,ariaLabel:`Today's activity density in 15-minute blocks`})]})}),(0,x.jsx)(cV,{index:6,children:(0,x.jsx)(_U,{})})]})]})}function iU(){let{data:e,isError:t}=L({queryKey:z.costPerTool,queryFn:()=>Fr(),refetchInterval:ZH,retry:!1}),n=e?.costByToolType?Object.entries(e.costByToolType).filter(([,e])=>e.totalCost>0).sort((e,t)=>t[1].totalCost-e[1].totalCost).map(([e,t])=>({tool:e,totalCost:t.totalCost,callCount:t.callCount})):[],r=e!=null&&(e.attributionRate??1)<.5;return t?(0,x.jsxs)(B,{padding:`sm`,className:`h-full`,children:[(0,x.jsx)(V,{className:`mb-2`,children:`Cost by Tool`}),(0,x.jsx)($,{icon:`radar`,title:`Cost attribution unavailable`,subtitle:`Start a Claude Code session to enable cost attribution.`})]}):e?(0,x.jsxs)(B,{padding:`sm`,className:`h-full`,children:[(0,x.jsx)(V,{className:`mb-2`,children:`Cost by Tool`}),n.length===0?(0,x.jsx)($,{icon:`radar`,title:`No cost data yet`,subtitle:`Cost attribution appears after token data is recorded.`}):(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(`div`,{className:`min-w-0`,style:{height:`${Math.max(96,n.length*28+24)}px`},children:(0,x.jsx)(np,{width:`100%`,height:`100%`,minWidth:1,minHeight:1,children:(0,x.jsxs)(tV,{data:n,layout:`vertical`,children:[(0,x.jsx)(hI,{stroke:$H,strokeDasharray:`3 3`}),(0,x.jsx)(YR,{type:`number`,tick:QH,stroke:$H,unit:`$`}),(0,x.jsx)(uz,{type:`category`,dataKey:`tool`,tick:QH,tickFormatter:e=>{let t=n.find(t=>t.tool===e),r=Ei(e);return t?`${r} (${t.callCount})`:r},stroke:$H,width:90,interval:0}),(0,x.jsx)(Yk,{contentStyle:eU,itemStyle:tU,labelFormatter:e=>Ei(String(e))}),(0,x.jsx)(OR,{dataKey:`totalCost`,name:`Cost ($)`,radius:[0,3,3,0],children:n.map(e=>(0,x.jsx)(Xk,{fill:nU(Ei(e.tool)),fillOpacity:.8},e.tool))})]})})}),r&&(0,x.jsxs)(`div`,{className:`text-[10px] text-ink-muted italic mt-1`,children:[`Based on `,Math.round((e.attributionRate??0)*100),`% of session cost`]})]})]}):(0,x.jsxs)(B,{padding:`sm`,className:`h-full`,children:[(0,x.jsx)(V,{className:`mb-2`,children:`Cost by Tool`}),(0,x.jsx)($,{icon:`radar`,title:`No cost data yet`,subtitle:`Cost attribution appears after token data is recorded.`})]})}function aU(){let{data:e,isError:t}=L({queryKey:z.costPerTool,queryFn:()=>Fr(),refetchInterval:ZH,retry:!1});if(t||!e||!e.costBySkill)return null;let n=Object.entries(e.costBySkill).sort((e,t)=>t[1].totalCost-e[1].totalCost||t[1].callCount-e[1].callCount).slice(0,10);if(n.length===0)return null;let r=(e.attributionRate??1)<.5;return(0,x.jsxs)(B,{padding:`sm`,className:`h-full`,children:[(0,x.jsx)(V,{className:`mb-2`,children:`Cost by Skill`}),(0,x.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,x.jsx)(`thead`,{children:(0,x.jsxs)(`tr`,{className:`border-b border-border-subtle text-ink-muted`,children:[(0,x.jsx)(`th`,{className:`text-left py-1.5 px-1`,children:`Skill`}),(0,x.jsx)(`th`,{className:`text-right py-1.5 px-1`,children:`Calls`}),(0,x.jsx)(`th`,{className:`text-right py-1.5 px-1`,children:`Cost`}),(0,x.jsx)(`th`,{className:`text-right py-1.5 px-1`,children:`Tokens`}),(0,x.jsx)(`th`,{className:`text-right py-1.5 px-1`,children:`Time`})]})}),(0,x.jsx)(`tbody`,{children:n.map(([e,t])=>(0,x.jsxs)(`tr`,{className:`border-b border-border-subtle hover:bg-surface-5`,children:[(0,x.jsx)(`td`,{className:`py-1.5 px-1 text-ink-base font-mono text-xs`,children:e}),(0,x.jsx)(`td`,{className:`text-right py-1.5 px-1 text-ink-subtle`,children:t.callCount}),(0,x.jsx)(`td`,{className:`text-right py-1.5 px-1 text-ink-base`,title:t.attributedCallCount<t.callCount?`Cost covers ${t.attributedCallCount} of ${t.callCount} calls`:void 0,children:Ci(t.totalCost)}),(0,x.jsx)(`td`,{className:`text-right py-1.5 px-1 text-ink-subtle`,children:Ti(t.inputTokens+t.outputTokens+t.cacheReadTokens)}),(0,x.jsx)(`td`,{className:`text-right py-1.5 px-1 text-ink-subtle`,children:xi(t.totalDurationMs)})]},e))})]}),r&&(0,x.jsxs)(`div`,{className:`text-[10px] text-ink-muted italic mt-1`,children:[`Based on `,Math.round((e.attributionRate??0)*100),`% of session cost`]})]})}function oU(){let{data:e}=L({queryKey:z.qualityProxy,queryFn:Cr,refetchInterval:ZH});return(0,x.jsxs)(B,{padding:`sm`,className:`h-full`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-1.5 mb-2`,children:[(0,x.jsx)(V,{children:`Quality`}),(0,x.jsx)(ui,{text:`Diff apply rate and test pass rate across today's sessions, plus how often you backtracked or self-corrected. Watch for the degrading flag if quality drops mid-session.`})]}),!e||e.totalSignals===0?(0,x.jsx)($,{icon:`checkmark`,title:`Waiting for edits and test runs`,subtitle:`Quality metrics appear after editing files and running tests.`}):(0,x.jsxs)(x.Fragment,{children:[(0,x.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 text-xs`,children:[(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`Diff Apply `}),(0,x.jsx)(`span`,{className:gi(e.diffApplyRate),children:e.diffApplyRate===null?`—`:`${(e.diffApplyRate*100).toFixed(0)}%`})]}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`Test Pass `}),(0,x.jsx)(`span`,{className:gi(e.testPassRate),children:e.testPassRate===null?`—`:`${(e.testPassRate*100).toFixed(0)}%`})]}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`Backtracks `}),(0,x.jsx)(`span`,{className:e.backtrackCount>0?`text-accent-amber`:``,children:e.backtrackCount})]}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`Self-corrections `}),(0,x.jsx)(`span`,{className:`text-ink-subtle`,children:e.selfCorrectionCount})]})]}),e.degradationDetected&&(0,x.jsx)(`div`,{className:`text-accent-amber text-xs mt-2`,children:`⚠ Quality degrading`})]})]})}function sU(){let{data:e}=L({queryKey:z.apiFailures,queryFn:Wr,refetchInterval:ZH}),t=e?.byErrorType?Object.entries(e.byErrorType).filter(([,e])=>e>0):[],n=e?.throttleAlerts??[];return(0,x.jsxs)(B,{padding:`sm`,className:`h-full`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-1.5 mb-2`,children:[(0,x.jsx)(V,{children:`API Failures`}),(0,x.jsx)(ui,{text:`Turns that failed outright after Claude Code's own retries were exhausted, captured via its StopFailure hook.`})]}),!e||e.totalFailures===0?(0,x.jsx)($,{icon:`radar`,title:`No API failures`,subtitle:`Reflects Claude Code's own StopFailure hook, not proxy-mode traffic.`}):(0,x.jsxs)(x.Fragment,{children:[(0,x.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 text-xs`,children:[(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`Total `}),(0,x.jsx)(`span`,{className:`text-accent-amber`,children:e.totalFailures})]}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`Throttle alerts `}),(0,x.jsx)(`span`,{className:n.length>0?`text-accent-amber`:``,children:n.length})]})]}),t.length>0&&(0,x.jsx)(`div`,{className:`text-[10px] text-ink-subtle mt-1`,children:t.map(([e,t])=>`${e}: ${t}`).join(`, `)}),n.length>0&&(0,x.jsx)(`div`,{className:`text-accent-amber text-xs mt-2`,children:`⚠ Rate-limit throttling detected`})]})]})}function cU(){let{data:e}=L({queryKey:z.toolSelectionScore,queryFn:wr,refetchInterval:ZH});return(0,x.jsxs)(B,{padding:`sm`,className:`h-full`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-1.5 mb-2`,children:[(0,x.jsx)(V,{children:`Tool Selection`}),(0,x.jsx)(ui,{text:`Scores how efficiently tools were chosen today: penalizes re-reading a file without editing it, retrying a failing call, or fetching output that's never used.`})]}),!e||Array.isArray(e)||e.totalCalls===0?(0,x.jsx)($,{icon:`radar`,title:`Waiting for tool calls`,subtitle:`Start a Claude Code session to begin scoring. Reflects today's activity across all sessions.`}):(0,x.jsxs)(x.Fragment,{children:[(0,x.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,x.jsx)(`span`,{className:`text-2xl font-semibold tabular-nums ${_i(e.score)}`,children:e.score.toFixed(2)}),(0,x.jsx)(`span`,{className:`text-[10px] text-ink-muted`,children:`/ 1.0`})]}),(0,x.jsxs)(`div`,{className:`text-[10px] text-ink-muted mt-1`,children:[e.penalizedCalls,` of `,e.totalCalls,` calls penalized`]}),(e.redundantReadCount>0||e.repeatedFailureCount>0||e.unusedOutputCount>0)&&(0,x.jsxs)(`div`,{className:`text-[10px] text-ink-subtle mt-1 space-x-2`,children:[e.redundantReadCount>0&&(0,x.jsxs)(`span`,{children:[`re-reads: `,e.redundantReadCount]}),e.repeatedFailureCount>0&&(0,x.jsxs)(`span`,{children:[`repeat fails: `,e.repeatedFailureCount]}),e.unusedOutputCount>0&&(0,x.jsxs)(`span`,{children:[`unused output: `,e.unusedOutputCount]})]}),(0,x.jsx)(`div`,{className:`text-[10px] text-ink-subtle/60 mt-2`,children:`Penalizes: reading the same file 3+ times without editing, repeated tool failures, fetching large outputs never referenced.`})]})]})}function lU({aggregate:e}){let t=e?.latency,n=t?.byTool?Object.entries(t.byTool).filter(e=>e[1]!==null&&e[1].count>0).sort((e,t)=>t[1].p95-e[1].p95).slice(0,4):[];return(0,x.jsxs)(B,{padding:`sm`,className:`h-full`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-1.5 mb-2`,children:[(0,x.jsx)(V,{children:`Latency (ms)`}),(0,x.jsx)(ui,{text:`How long tool calls took today — p50/p95/p99 across all calls, plus the slowest tools by p95.`})]}),!t||!t.overall?(0,x.jsx)($,{icon:`clock`,title:`Waiting for tool calls`,subtitle:`Latency percentiles appear after tool calls complete.`}):(0,x.jsxs)(x.Fragment,{children:[(0,x.jsxs)(`div`,{className:`flex gap-4 text-xs mb-2`,children:[(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`p50 `}),(0,x.jsx)(`span`,{className:`text-ink-base tabular-nums`,children:t.overall.p50})]}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`p95 `}),(0,x.jsx)(`span`,{className:`text-ink-base tabular-nums`,children:t.overall.p95})]}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`p99 `}),(0,x.jsx)(`span`,{className:`text-ink-base tabular-nums`,children:t.overall.p99})]})]}),n.length>0&&(0,x.jsx)(`div`,{className:`space-y-1`,children:n.map(([e,t])=>(0,x.jsxs)(`div`,{className:`flex items-center gap-2 text-xs`,children:[(0,x.jsx)(`span`,{className:`text-ink-muted truncate w-28 shrink-0`,children:Ei(e)}),(0,x.jsxs)(`span`,{className:`tabular-nums text-ink-subtle`,children:[t.p95,`ms p95`]})]},e))})]})]})}function uU(){let{data:e}=L({queryKey:z.modelUsage,queryFn:Nr,refetchInterval:ZH}),t=e?.byModel?Object.entries(e.byModel).filter(([,e])=>e.requestCount>0).sort((e,t)=>t[1].totalCostUsd-e[1].totalCostUsd).slice(0,4):[];return(0,x.jsxs)(B,{padding:`sm`,className:`h-full`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-1.5 mb-2`,children:[(0,x.jsx)(V,{children:`Model Usage`}),(0,x.jsx)(ui,{text:`Cost and request volume per model used today, combining this server's live usage with every other session's saved totals. $/1M tok counts every billed token, cache reads and cache writes included, so it is comparable with list prices. The live slice resets if the server process restarts.`})]}),!e||t.length===0?(0,x.jsx)($,{icon:`radar`,title:`No model data yet`,subtitle:`Start a Claude Code session to see model cost breakdown. Resets when the process restarts.`}):(0,x.jsx)(`div`,{className:`space-y-1.5`,children:t.map(([e,t])=>(0,x.jsxs)(`div`,{className:`flex items-center justify-between text-xs gap-2`,children:[(0,x.jsx)(`span`,{className:`text-ink-muted truncate`,children:e}),(0,x.jsxs)(`div`,{className:`flex gap-3 shrink-0 tabular-nums`,children:[(0,x.jsxs)(`span`,{className:`text-ink-subtle`,children:[t.requestCount,`req`]}),(0,x.jsxs)(`span`,{className:`text-ink-subtle`,children:[wi(t.costPerMillionTokens),`/1M tok`]}),(0,x.jsx)(`span`,{className:`text-ink-base`,children:Ci(t.totalCostUsd)})]})]},e))})]})}function dU(e,t){let n=t===null?null:`${t}%`;return e===`excellent`?n?`Cache hit rate is ${n}. Cache is well-structured.`:`Cache is well-structured. No changes needed.`:e===`can_improve`?n?`Cache hit rate is ${n}. Placing stable content before variable content in prompts could improve this.`:`Place stable content before variable content in prompts to improve.`:n?`Cache hit rate is ${n}. Restructuring your system prompt so stable context appears at the top could bring this above 60%.`:`Restructure your system prompt so stable context appears at the top.`}function fU({aggregate:e}){let{data:t}=L({queryKey:z.cacheHealth,queryFn:Pr,refetchInterval:ZH}),n=e?.cacheHealth,r=!n||n.status===`no_cache_activity`||n.cacheHitRatePct==null;return(0,x.jsxs)(B,{padding:`sm`,className:`h-full`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-1.5 mb-2`,children:[(0,x.jsx)(V,{children:`Cache Health`}),(0,x.jsx)(ui,{text:`Prompt cache hit rate today, with a suggestion for improving it — usually by moving stable context earlier in the prompt.`})]}),r?(0,x.jsx)($,{icon:`radar`,title:`No cache data yet`,subtitle:`Appears once token usage with cache reads is reported.`}):(0,x.jsxs)(x.Fragment,{children:[(0,x.jsxs)(`div`,{className:`flex items-baseline gap-2 mb-1`,children:[(0,x.jsxs)(`span`,{className:`text-2xl font-semibold tabular-nums ${n.status===`excellent`?`text-accent-green`:n.status===`needs_attention`?`text-accent-amber`:`text-ink-base`}`,children:[n.cacheHitRatePct,`%`]}),(0,x.jsx)(ni,{tone:n.status===`needs_attention`?`warning`:`neutral`,size:`sm`,children:n.status===`excellent`?`excellent`:n.status.replace(`_`,` `)})]}),n.totalSavingsUsd>0&&(0,x.jsxs)(`div`,{className:`text-xs text-accent-green mb-1`,children:[`$`,n.totalSavingsUsd.toFixed(4),` saved`]}),t?.week_over_week_delta_pts!=null&&t.week_over_week_delta_pts!==0&&(0,x.jsxs)(`div`,{className:`text-[10px] font-medium mb-1 ${t.week_over_week_delta_pts>0?`text-accent-green`:`text-accent-amber`}`,children:[t.week_over_week_delta_pts>0?`↑`:`↓`,Math.abs(t.week_over_week_delta_pts),`pts vs last week`]}),(0,x.jsx)(`div`,{className:`text-[10px] text-ink-subtle/70 leading-snug`,children:dU(n.status,n.cacheHitRatePct)})]})]})}function pU({liveSessions:e}){let{data:t,isPending:n}=L({queryKey:z.computeWaste,queryFn:cr,retry:!1}),r=qn(e=>e.retryAlerts);if(n||!t||typeof t.total_tokens_wasted!=`number`)return null;let i=r[r.length-1]??null,a=t.by_session?.[0]??null,o=t.status===`clean`?`text-accent-green`:t.status===`moderate`?`text-accent-amber`:`text-accent-red`,s=t.status===`clean`?`clean`:t.status===`moderate`?`moderate`:`needs attention`,c=t.breakdown[0]??null;return(0,x.jsxs)(B,{padding:`sm`,className:`h-full`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-1.5 mb-2`,children:[(0,x.jsx)(V,{children:`Compute Waste`}),(0,x.jsx)(ui,{text:`Tokens wasted today on retried tool calls and anti-pattern activity (stuck loops, redundant reads, thrashing).`})]}),(0,x.jsxs)(`div`,{className:`text-lg font-semibold tabular-nums ${o}`,children:[`~`,t.total_tokens_wasted.toLocaleString(),` wasted tokens`]}),(0,x.jsx)(ni,{tone:t.status===`clean`?`success`:t.status===`moderate`?`warning`:`danger`,size:`sm`,className:`mt-1`,children:s}),(0,x.jsxs)(`div`,{className:`text-xs text-ink-muted mt-1`,children:[`retry: ~`,t.retry_tokens_wasted.toLocaleString(),` · anti-pattern: ~`,t.anti_pattern_tokens_wasted.toLocaleString()]}),a!==null&&(0,x.jsxs)(`div`,{className:`text-[10px] text-ink-subtle/70 mt-0.5`,children:[`top session: `,gU(a.session_id,e),` (~`,a.tokens_wasted.toLocaleString(),`)`]}),c!==null&&(0,x.jsxs)(`div`,{className:`text-[10px] font-medium text-accent-amber mb-1`,children:[c.type.replace(/_/g,` `),` · ~`,c.tokens_wasted.toLocaleString(),` `,`tokens`]}),i!==null&&(0,x.jsxs)(`div`,{className:`text-[10px] mb-1`,children:[(0,x.jsx)(ni,{tone:`warning`,size:`sm`,className:`mr-1`,children:i.toolName}),(0,x.jsxs)(`span`,{className:`text-ink-muted`,children:[`retried `,i.occurrences,`× `]}),i.sessionId&&(0,x.jsxs)(ni,{tone:`neutral`,size:`sm`,className:`ml-1`,children:[`Session: `,gU(i.sessionId,e)]})]}),(0,x.jsx)(`div`,{className:`text-[10px] text-ink-subtle/70 leading-snug`,children:XH(t.status,c?.type??null)})]})}var mU=3e3;function hU({sessions:e,liveSessions:t}){let[n,r]=(0,b.useState)(null),[i,a]=(0,b.useState)(null),[o,s]=(0,b.useState)(!1),[,c]=Wt(),l=qn(e=>e.setActiveSession),{data:u}=L({queryKey:z.sessionCurrent,queryFn:tr}),d=(0,b.useMemo)(()=>{let e=new Set;for(let n of t)e.add(n.sessionId);if(e.size===0){if(u?.liveSessions?.length)for(let t of u.liveSessions)e.add(t);else u?.sessionId&&e.add(u.sessionId)}return e},[t,u]),f=(t.length>0?t[0].sessionId:null)??(d.size>0?[...d][0]:null),p=n??f,m=p!==null&&d.has(p),h=n!==null&&!d.has(n);(0,b.useEffect)(()=>{l(p)},[p,l]);let{data:g}=L({queryKey:p?z.sessionReplay(p):[`replay`,`none`],queryFn:()=>br(p),enabled:p!==null,retry:!1,refetchInterval:m?mU:!1}),{data:_}=L({queryKey:p?z.sessionSubagents(p):[`subagents`,`none`],queryFn:()=>xr(p),enabled:p!==null,retry:!1,refetchInterval:m?mU:!1}),{data:v}=L({queryKey:z.workflows,queryFn:Vr,refetchInterval:m?1e4:!1}),{data:y}=L({queryKey:p?[`turn-costs`,p]:[`turn-costs`],queryFn:()=>ur(p??void 0),refetchInterval:1e4}),{data:S}=L({queryKey:p?[`decision-tree`,p]:[`decision-tree`],queryFn:()=>lr(p??void 0),refetchInterval:1e4}),{data:C}=L({queryKey:p?[`context`,p]:z.context,queryFn:()=>Ar(p??void 0),refetchInterval:1e4,enabled:m&&!!p}),{data:w}=L({queryKey:[`context-composition`],queryFn:jr,refetchInterval:1e4}),{data:T}=L({queryKey:[`context-efficiency`],queryFn:Mr,refetchInterval:1e4}),E=(0,b.useRef)(null);(0,b.useEffect)(()=>{m&&E.current&&(E.current.scrollTop=E.current.scrollHeight)},[g?.timeline.length,m]);let D=(0,b.useMemo)(()=>{let n=Date.now()-216e5,r=new Map;for(let e of t)r.set(e.sessionId,e);let i=new Map;for(let t of e){if(!t.sessionId)continue;let e=t.startTime!=null&&yU(t.startTime),a=r.has(t.sessionId),o=t.startTime!=null&&t.durationMs!=null?t.startTime+t.durationMs:null,s=o!=null&&o>=n&&yU(o);(e||a||s)&&i.set(t.sessionId,t)}for(let e of t)e.sessionId&&(i.has(e.sessionId)||i.set(e.sessionId,{sessionId:e.sessionId,sessionName:e.sessionName,startTime:e.startTime,toolCallCount:0,estimatedCostUsd:null}));let a=e=>{let t=r.get(e.sessionId);return t?t.lastActivity:e.startTime!=null&&e.durationMs!=null?e.startTime+e.durationMs:e.startTime??0};return[...i.values()].sort((e,t)=>a(t)-a(e)).slice(0,10)},[e,t]),O=(0,b.useMemo)(()=>g?.timeline??[],[g]),k=(0,b.useMemo)(()=>Array.isArray(_?.agents)?_.agents:[],[_]),A=(0,b.useMemo)(()=>{let e=null,t=null;for(let n of O){let r=n.timestamp+(n.durationMs??50);(e===null||n.timestamp<e)&&(e=n.timestamp),(t===null||r>t)&&(t=r)}let n=(_?.agents?.length??0)>0?_.window:null;return n&&(e=e===null?n.startMs:Math.min(e,n.startMs),t=t===null?n.endMs:Math.max(t,n.endMs)),e===null||t===null?{startMs:0,endMs:1}:{startMs:e,endMs:t>e?t:e+1}},[O,_]),j=(0,b.useMemo)(()=>{let e={};if(Array.isArray(v))for(let t of v)t&&typeof t.runId==`string`&&typeof t.status==`string`&&t.parentSessionId===p&&(e[t.runId]=t.status);return e},[v,p]);return(0,x.jsxs)(x.Fragment,{children:[(0,x.jsxs)(`div`,{className:`glass-card mb-3 grid grid-cols-[220px_1fr] overflow-hidden`,style:{height:`320px`},children:[(0,x.jsxs)(`div`,{className:`border-r border-border-subtle flex flex-col overflow-hidden`,children:[(0,x.jsxs)(`div`,{className:`flex items-center justify-between gap-1.5 p-2 border-b border-border-subtle shrink-0`,children:[(0,x.jsx)(V,{children:`Session Live Tail`}),(0,x.jsx)(ui,{text:`Today's sessions on the left; select one to stream its live tool-call trace on the right.`})]}),(0,x.jsxs)(`div`,{className:`overflow-auto flex-1`,children:[D.map(e=>{let t=d.has(e.sessionId);return(0,x.jsxs)(`button`,{type:`button`,onClick:()=>r(e.sessionId),className:`block w-full text-left p-2 border-b border-border-subtle text-xs transition-colors duration-150 hover:bg-surface-5 `+(p===e.sessionId?`bg-surface-5`:``),children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,x.jsx)(`span`,{className:`font-mono text-ink-base`,children:e.sessionName||e.sessionId.slice(0,8)}),t?(0,x.jsx)(ii,{label:`live`,size:`sm`}):(0,x.jsx)(`span`,{className:`text-[10px] text-ink-muted`,title:e.startTime?`Started ${yi(e.startTime)}`:void 0,children:e.startTime?yi(e.startTime+(e.durationMs??0)):``})]}),(0,x.jsxs)(`div`,{className:`flex gap-2 mt-0.5 text-[10px] text-ink-subtle`,children:[(0,x.jsxs)(`span`,{children:[e.toolCallCount??0,` calls`]}),e.estimatedCostUsd!=null&&e.estimatedCostUsd>0?(0,x.jsx)(`span`,{children:Ci(e.estimatedCostUsd)}):(0,x.jsx)(`span`,{children:`—`})]})]},e.sessionId)}),d.size===0&&D.length===0&&(0,x.jsx)($,{icon:`code`,title:`No sessions today`,subtitle:`Start coding with Claude to see sessions here.`})]})]}),(0,x.jsxs)(`div`,{className:`flex flex-col overflow-hidden`,children:[p&&(0,x.jsxs)(`div`,{className:`flex items-center justify-between px-2 py-1 border-b border-border-subtle shrink-0`,children:[(0,x.jsx)(V,{children:`Trace`}),(0,x.jsxs)(`div`,{className:`flex items-center gap-2`,children:[h&&(0,x.jsx)(`span`,{"data-testid":`session-ended-badge`,children:(0,x.jsx)(ni,{tone:`neutral`,size:`sm`,uppercase:!0,children:`Session ended`})}),(0,x.jsx)(`button`,{type:`button`,onClick:()=>c(`/sessions?id=${p}`),className:`text-[10px] text-accent-cyan hover:underline transition-colors duration-150`,children:`full session →`})]})]}),(0,x.jsxs)(`div`,{ref:E,className:`overflow-auto flex-1 p-2`,children:[!p&&(0,x.jsx)(`div`,{className:`text-ink-muted text-xs p-2`,children:`Select a session to view its timeline.`}),p&&O.length===0&&k.length===0&&(0,x.jsx)($,{icon:`timeline`,title:m?`Waiting for tool calls`:`No tool calls`,subtitle:m?`Tool calls will appear here in real time.`:`This session has no recorded tool calls.`}),p&&(O.length>0||k.length>0)&&(0,x.jsx)(PV,{sessionId:p,parentEntries:O,agents:k,window:A,runStatusById:j,parentSegments:g?.segments??[],onSelectRun:e=>a(e)},p)]}),m&&p&&(0,x.jsx)(`div`,{className:`border-t border-bg-line px-3 py-2 shrink-0`,children:(0,x.jsx)(gH,{sessionId:p,expandable:!1})}),((S?.totalBranches??0)>0||(y?.turns?.length??0)>0||(C?.history?.length??0)>=2)&&(0,x.jsx)(`div`,{className:`border-t border-bg-line px-3 py-2 shrink-0`,children:(0,x.jsx)(`button`,{type:`button`,onClick:()=>s(!0),className:`text-[10px] text-accent-cyan hover:underline transition-colors duration-150 text-left`,children:(()=>{let e=[];return S&&S.totalBranches>0&&e.push(`${S.longestFailureStreak} failure streak`),y?.turns&&y.turns.length>0&&e.push(`${y.turns.length} turns · $${y.totalAttributedCost.toFixed(2)}`),e.length>0?`${e.join(` · `)} — session detail →`:`session detail →`})()})})]})]}),i!=null&&(0,x.jsx)(iH,{runId:i,onClose:()=>a(null)}),o&&(0,x.jsx)(vH,{decisionTree:S,turnCosts:y,contextHistory:C?.history,contextWindow:C?.contextWindow,contextComposition:w,contextEfficiency:T,onClose:()=>s(!1)})]})}function gU(e,t){let n=t.find(t=>t.sessionId===e);return n?.sessionName?n.sessionName:e.slice(0,8)}function _U(){let{data:e,isLoading:t,error:n}=L({queryKey:z.alertsRecent,queryFn:async()=>{try{return await yr()}catch(e){if(e instanceof $n)return null;throw e}},refetchInterval:JH,retry:!1});if(e===null)return null;let r=[...e??[]].sort((e,t)=>t.firedAt-e.firedAt);return(0,x.jsxs)(B,{padding:`sm`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-1.5 mb-2`,children:[(0,x.jsx)(V,{children:`Recent Alerts`}),(0,x.jsx)(ui,{text:`The most recent alert firings and resolutions from your configured alert rules, newest first.`})]}),t&&(0,x.jsx)($,{variant:`loading`,title:`Loading...`}),n&&(0,x.jsx)(`div`,{className:`text-accent-red text-xs`,children:`Error loading recent alerts.`}),!t&&!n&&r.length===0&&(0,x.jsx)(`div`,{className:`text-ink-muted text-xs`,children:`No alerts in recent history.`}),!t&&!n&&r.length>0&&(0,x.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,x.jsx)(`thead`,{className:`text-ink-muted`,children:(0,x.jsxs)(`tr`,{children:[(0,x.jsx)(`th`,{className:`text-left pb-1`,children:`when`}),(0,x.jsx)(`th`,{className:`text-left pb-1`,children:`sev`}),(0,x.jsx)(`th`,{className:`text-left pb-1`,children:`rule`}),(0,x.jsx)(`th`,{className:`text-right pb-1`,children:`value / threshold`}),(0,x.jsx)(`th`,{className:`text-left pb-1 pl-2`,children:`state`})]})}),(0,x.jsx)(`tbody`,{children:r.slice(0,50).map(e=>(0,x.jsxs)(`tr`,{className:`border-t border-border-subtle`,children:[(0,x.jsx)(`td`,{className:`py-1 text-ink-subtle tabular-nums whitespace-nowrap`,children:vU(e.firedAt)}),(0,x.jsxs)(`td`,{className:`py-1`,children:[(0,x.jsx)(`span`,{"aria-hidden":`true`,className:YH[e.severity],children:`●`}),` `,(0,x.jsx)(`span`,{className:`text-ink-subtle uppercase tracking-wider text-[10px]`,children:e.severity})]}),(0,x.jsx)(`td`,{className:`py-1`,children:e.title}),(0,x.jsxs)(`td`,{className:`py-1 text-right tabular-nums`,children:[Si(e.value),` / `,Si(e.threshold)]}),(0,x.jsx)(`td`,{className:`py-1 pl-2 `+(e.state===`firing`?`text-accent-amber`:`text-ink-muted`),children:e.state})]},`${e.id}-${e.firedAt}-${e.state}`))})]})]})}function vU(e){let t=Math.max(0,Date.now()-e),n=Math.floor(t/6e4);if(n<1)return`just now`;if(n<60)return`${n}m ago`;let r=Math.floor(n/60);return r<24?`${r}h ago`:`${Math.floor(r/24)}d ago`}var yU=e=>GH(e);function bU(e){if(e.startTime==null)return 0;let t=typeof e.endTime==`number`?e.endTime:typeof e.durationMs==`number`?e.startTime+e.durationMs:Date.now();return KH({startTime:e.startTime,endTime:t})}function xU(e){let t=e.estimatedCostUsd;return t==null||t<=0?0:t*bU(e)}function SU(e){let t=0;for(let n of e)t+=xU(n);return t}function CU(e){let t=0;for(let n of e){let e=bU(n);e>0&&(t+=(n.toolCallCount??0)*e)}return Math.round(t)}function wU(e){let t=0;for(let n of e){let e=bU(n);e>0&&(t+=(n.antiPatterns?.length??0)*e)}return Math.round(t)}var TU=[.01,.02,.05,.1,.25,.5,1,2,5,10,25,50,100,250,500,1e3],EU=5;function DU(e){if(e<=0)return .01;for(let t of TU)if(t>=e)return t;return TU[TU.length-1]}function OU(e){return e===0?`12am`:e<12?`${e}am`:e===12?`12pm`:`${e-12}pm`}function kU(e){let t=e.reduce((e,t)=>e+t.cost,0),n=e.reduce((e,t)=>Math.max(e,t.cost),0),r=e.find(e=>e.cost===n);return r===void 0||n===0?`Hourly spend today: no activity yet.`:`Hourly spend today: ${Ci(t)} total, peak ${Ci(n)} at ${OU(r.hour)}`}function AU(e){let t=e.reduce((e,t)=>Math.max(e,t.cost),0),n=DU(t/EU);return e.map(e=>({count:Math.max(0,Math.round(e.cost/n)),tooltip:`${OU(e.hour)}: ${Ci(e.cost)} (start hour)`,isPeak:t>0&&e.cost===t}))}function jU(e){let t=Array(24).fill(0),n=WH(),r=n+864e5;for(let i of e){if(!i.startTime||i.estimatedCostUsd==null||i.estimatedCostUsd<=0)continue;let e=i.startTime,a=typeof i.endTime==`number`?i.endTime:typeof i.durationMs==`number`?i.startTime+i.durationMs:Date.now(),o=Math.max(e,n),s=Math.min(a,r);if(s<=o)continue;let c=Math.max(1,a-e),l=s-o,u=i.estimatedCostUsd*(l/c),d=o;for(;d<s;){let e=new Date(d),n=e.getHours(),r=new Date(e);r.setMinutes(0,0,0),r.setHours(n+1);let i=Math.min(s,r.getTime()),a=i-d;t[n]+=a/l*u,d=i}}return t.map((e,t)=>({hour:t,cost:e}))}function MU({todayTotal:e,forecastEod:t,hourlySpend:n,subagentUsd:r=0,forecastSessionEnd:i,forecastWeek:a,confidenceNote:o}){let s=t!==null&&Number.isFinite(t),c=s?Math.max(t,e):0,l=s?c-e:0,u=s&&e>0?l/e*100:0,d=n.some(e=>e.cost>0),f=r>0?Math.max(0,e-r):0;return(0,x.jsxs)(B,{padding:`sm`,className:`mb-3 h-full`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-1.5 mb-1.5`,children:[(0,x.jsx)(V,{children:`Forecast · End of Day`}),(0,x.jsx)(ui,{text:`Projects today's total spend by midnight, based on the spending trend so far this hour-by-hour.`})]}),s?(0,x.jsxs)(x.Fragment,{children:[(0,x.jsxs)(`div`,{className:`flex items-baseline gap-3`,children:[(0,x.jsx)(`span`,{className:`text-lg font-semibold text-accent-cyan tabular-nums`,children:Ci(c)}),(0,x.jsx)(`span`,{className:`text-xs text-ink-muted tabular-nums`,children:l>0?(0,x.jsxs)(x.Fragment,{children:[`+`,Ci(l),e>0&&` (+${u.toFixed(0)}%)`,` from now`]}):(0,x.jsx)(x.Fragment,{children:`on pace`})})]}),d&&(0,x.jsxs)(`div`,{className:`mt-2`,children:[(0,x.jsx)(pV,{data:AU(n),ariaLabel:kU(n)}),r>0&&(0,x.jsxs)(`div`,{className:`flex gap-3 mt-1 text-[10px] text-ink-muted tabular-nums`,children:[(0,x.jsxs)(`span`,{children:[`parent `,Ci(f)]}),(0,x.jsx)(`span`,{className:`text-ink-subtle`,children:`·`}),(0,x.jsxs)(`span`,{children:[`subagent `,Ci(r)]})]})]}),(i!==null||a!==null)&&(0,x.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-3 mt-2 pt-2 border-t border-border-subtle text-xs`,children:[i!==null&&(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`div`,{className:`text-ink-muted`,children:`End of session`}),(0,x.jsxs)(`div`,{className:`font-mono tabular-nums`,children:[`~$`,i.toFixed(2)]})]}),a!==null&&(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`div`,{className:`text-ink-muted`,children:`End of week`}),(0,x.jsxs)(`div`,{className:`font-mono tabular-nums`,children:[`~$`,a.toFixed(2)]})]})]}),o&&(0,x.jsx)(`div`,{className:`text-[10px] text-ink-muted italic mt-1`,children:o})]}):(0,x.jsx)(`div`,{className:`text-ink-muted text-xs`,children:`Insufficient data — forecast appears once burn rate stabilizes.`})]})}function NU(e,t){let{startMs:n,endMs:r,bucketSizeMs:i}=t,a=Math.max(1,Math.ceil((r-n)/i)),o=Array(a).fill(0);for(let t of e){let e=Math.floor((t.timestamp-n)/i);e>=0&&e<a&&o[e]++}return o}function PU(e){return e<6e5?3e4:e<36e5?6e4:e<144e5?3e5:9e5}var FU=50,IU={thrashing:`Edit/Test Thrashing`,stuck_loop:`Stuck Loop`,blind_editing:`Blind Editing`,re_reading:`Repeated Reads`,over_delegation:`Over-Delegation`},LU={running:{tone:`info`,label:`Running`},completed:{tone:`success`,label:`Completed`},failed:{tone:`danger`,label:`Failed`},cancelled:{tone:`warning`,label:`Cancelled`},unknown:{tone:`neutral`,label:`Unknown`}},RU=[{value:`today`,label:`Today`},{value:`7d`,label:`7 days`},{value:`30d`,label:`30 days`},{value:`all`,label:`All`}],zU=[{value:`all`,label:`All sources`},{value:`script`,label:`Script`},{value:`agent_tool`,label:`Agent tool`}],BU=[{value:`all`,label:`All`},{value:`running`,label:`Running`},{value:`completed`,label:`Completed`},{value:`failed`,label:`Failed`},{value:`cancelled`,label:`Cancelled`}];function VU(e,t){if(t===`all`||e==null)return!0;let n=typeof e==`number`?e:Date.parse(e);if(!Number.isFinite(n))return!0;let r=Date.now();return n>={today:new Date().setHours(0,0,0,0),"7d":r-6048e5,"30d":r-2592e6}[t]}function HU(e){let t;try{let n=new URLSearchParams(e);t=n.get(`session`)??n.get(`id`)}catch{return null}if(t==null)return null;let n=t.trim();return n.length===0||n.length>256?null:n}function UU(e){let t;try{t=new URLSearchParams(e).get(`repo`)}catch{return null}if(t==null)return null;let n=t.trim();return n.length===0||n.length>256?null:n}function WU(e){let t;try{t=new URLSearchParams(e).get(`sessionIds`)}catch{return null}if(t==null)return null;let n=t.split(`,`).map(e=>e.trim()).filter(e=>e.length>0&&e.length<=256);return n.length>0?new Set(n):null}function GU(e){return typeof e.startTime==`number`?e.startTime:new Date(e.startTime??0).getTime()}function KU(e){return GU(e)+(e.durationMs??0)}function qU(e,t){let n=[...e];switch(t){case`date`:n.sort((e,t)=>GU(t)-GU(e));break;case`lastActive`:n.sort((e,t)=>KU(t)-KU(e));break;case`cost`:n.sort((e,t)=>(t.estimatedCostUsd??0)-(e.estimatedCostUsd??0));break;case`calls`:n.sort((e,t)=>(t.toolCallCount??0)-(e.toolCallCount??0))}return n}function JU(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function YU(){let e=Gt(),[t,n]=(0,b.useState)(()=>HU(window.location.search)),[r,i]=(0,b.useState)(`date`),[a,o]=(0,b.useState)(`all`),[s,c]=(0,b.useState)(`all`),[l,u]=(0,b.useState)(`all`),[d,f]=(0,b.useState)(null),[p,m]=(0,b.useState)(()=>new Set),[h,g]=(0,b.useState)(()=>new Set),_=(0,b.useMemo)(()=>HU(e),[e]);(0,b.useEffect)(()=>{_&&n(_)},[_]);let[v,y]=(0,b.useState)(()=>UU(window.location.search)),S=(0,b.useMemo)(()=>UU(e),[e]);(0,b.useEffect)(()=>{S&&y(S)},[S]);let[C,w]=(0,b.useState)(()=>WU(window.location.search)),T=(0,b.useMemo)(()=>WU(e),[e]);(0,b.useEffect)(()=>{T&&w(T)},[T]);let E=L({queryKey:z.sessionsList(FU),queryFn:()=>nr(FU),refetchInterval:1e4}),{data:D}=L({queryKey:z.workflows,queryFn:Vr,refetchInterval:1e4}),O=L({queryKey:z.sessionCurrent,queryFn:tr,refetchInterval:1e4}),k=(0,b.useMemo)(()=>{let e=new Set;if(O.data?.liveSessions?.length)for(let t of O.data.liveSessions)e.add(t);return e},[O.data]),A=L({queryKey:t?z.sessionDetail(t):[`session`,`none`],queryFn:()=>ar(t),enabled:t!==null,refetchInterval:O.isLoading||t&&k.has(t)?1e4:!1}),j=(0,b.useMemo)(()=>qU(E.data??[],r),[E.data,r]),M=(0,b.useMemo)(()=>Array.isArray(D)?D:[],[D]),N=(0,b.useMemo)(()=>M.filter(e=>!(!VU(e.startedAt,a)||s!==`all`&&e.runSource!==s||l!==`all`&&e.status!==l)),[M,a,s,l]),ee=(0,b.useMemo)(()=>{let e=N.length,t=N.reduce((e,t)=>e+(t.agentCount??0),0),n=N.map(e=>e.totalUsd).filter(e=>e!=null),r=n.length>0?n.reduce((e,t)=>e+t,0):null,i=N.some(e=>e.costUnknown===!0),a=N.map(e=>e.durationMs).filter(e=>e!=null);return{totalRuns:e,totalAgents:t,totalSpend:r,spendIsPartial:i,avgDurationMs:a.length>0?a.reduce((e,t)=>e+t,0)/a.length:null}},[N]),te=(0,b.useMemo)(()=>{let e=new Map;for(let t of N){let n=t.parentSessionId;if(typeof n!=`string`)continue;let r=e.get(n);r?r.push(t):e.set(n,[t])}return e},[N]),P=a!==`all`||s!==`all`||l!==`all`||v!==null||C!==null,F=s!==`all`||l!==`all`,ne=(0,b.useMemo)(()=>{let e=j;return a!==`all`&&(e=e.filter(e=>VU(GU(e),a)||te.has(e.sessionId))),F&&(e=e.filter(e=>te.has(e.sessionId))),v!==null&&(e=e.filter(e=>e.repoName===v)),C!==null&&(e=e.filter(e=>C.has(e.sessionId))),e},[j,a,F,te,v,C]),re=(0,b.useMemo)(()=>{if(C===null)return 0;let e=new Set(j.map(e=>e.sessionId)),t=0;for(let n of C)e.has(n)||t++;return t},[C,j]),ie=(0,b.useMemo)(()=>{let e=new Set(ne.map(e=>e.sessionId)),t=0;for(let n of N)typeof n.parentSessionId==`string`&&!e.has(n.parentSessionId)&&t++;return t},[N,ne]);(0,b.useEffect)(()=>{if(t)return;let e=k.size>0?[...k][0]:null;e?n(e):!O.isLoading&&j.length>0&&n(j[0].sessionId)},[k,j,t,O.isLoading]);let ae=e=>{n(e)},oe=(0,b.useCallback)(e=>{m(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),I=(0,b.useCallback)(e=>{g(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),se=(0,b.useCallback)(e=>{f(e)},[]);return(0,x.jsxs)(`section`,{className:`flex flex-col h-full`,children:[(0,x.jsx)(`div`,{className:`h-8 overflow-hidden rounded-lg mb-2 shrink-0`,children:(0,x.jsx)(AH,{theme:`sessions`})}),(0,x.jsx)(`h1`,{className:`text-lg font-semibold gradient-text mb-2 shrink-0`,children:`Sessions`}),(0,x.jsxs)(B,{tone:`static`,padding:`sm`,className:`mb-2 shrink-0`,children:[(0,x.jsxs)(`div`,{className:`grid grid-cols-2 sm:grid-cols-4 gap-4 divide-x divide-border-subtle`,children:[(0,x.jsx)(`div`,{className:`px-3 first:pl-0`,children:(0,x.jsx)(sV,{label:`Workflow runs`,value:String(ee.totalRuns),numericValue:ee.totalRuns,animate:!0})}),(0,x.jsx)(`div`,{className:`px-3`,children:(0,x.jsx)(sV,{label:`Subagents`,value:String(ee.totalAgents),numericValue:ee.totalAgents,animate:!0})}),(0,x.jsx)(`div`,{className:`px-3`,children:(0,x.jsx)(sV,{label:`Workflow spend`,value:wi(ee.totalSpend)+(ee.spendIsPartial?`*`:``),tone:ee.totalSpend===null?`neutral`:`warn`,sub:ee.spendIsPartial?`*partial — some runs have cost never observed by any process`:void 0})}),(0,x.jsx)(`div`,{className:`px-3`,children:(0,x.jsx)(sV,{label:`Avg duration`,value:ee.avgDurationMs===null?`—`:xi(ee.avgDurationMs)})})]}),ie>0&&(0,x.jsxs)(`div`,{className:`text-[11px] text-ink-subtle mt-2 pt-2 border-t border-border-subtle`,children:[`+`,ie,` run`,ie===1?``:`s`,` above from `,ie===1?`a session`:`sessions`,` outside the`,` `,ne.length,` shown below`]})]}),(0,x.jsxs)(`div`,{className:`flex items-center gap-3 flex-wrap mb-2 shrink-0`,children:[(0,x.jsx)(si,{value:a,onChange:o,options:RU,ariaLabel:`Time window`}),(0,x.jsx)(`div`,{className:`h-4 w-px bg-border-subtle`,"aria-hidden":`true`}),(0,x.jsx)(`div`,{className:`flex items-center gap-1.5`,role:`group`,"aria-label":`Run source filter`,children:zU.map(e=>(0,x.jsx)(`button`,{type:`button`,"aria-pressed":s===e.value,onClick:()=>c(e.value),className:[`px-2.5 py-1 rounded-full text-[11px] transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-cyan/40`,s===e.value?`bg-accent-cyan/20 text-accent-cyan font-medium`:`text-ink-muted hover:text-ink-subtle`].join(` `),children:e.label},e.value))}),(0,x.jsx)(`div`,{className:`h-4 w-px bg-border-subtle`,"aria-hidden":`true`}),(0,x.jsx)(`div`,{className:`flex items-center gap-1.5`,role:`group`,"aria-label":`Status filter`,children:BU.map(e=>{let t=l===e.value;return(0,x.jsx)(`button`,{type:`button`,"aria-pressed":t,onClick:()=>u(e.value),className:[`px-2.5 py-1 rounded-full text-[11px] transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-cyan/40`,t?`bg-accent-green/20 text-accent-green font-medium`:`text-ink-muted hover:text-ink-subtle`].join(` `),children:e.label},e.value)})}),v!==null&&(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(`div`,{className:`h-4 w-px bg-border-subtle`,"aria-hidden":`true`}),(0,x.jsxs)(`span`,{className:`flex items-center gap-1 px-2.5 py-1 rounded-full text-[11px] bg-accent-cyan/20 text-accent-cyan font-medium`,children:[`Repo: `,v,(0,x.jsx)(`button`,{type:`button`,onClick:()=>y(null),"aria-label":`Clear repo filter`,className:`hover:text-ink-base focus-visible:outline-none`,children:`✕`})]})]}),C!==null&&(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(`div`,{className:`h-4 w-px bg-border-subtle`,"aria-hidden":`true`}),(0,x.jsxs)(`span`,{className:`flex items-center gap-1 px-2.5 py-1 rounded-full text-[11px] bg-accent-cyan/20 text-accent-cyan font-medium`,children:[C.size,` session`,C.size===1?``:`s`,` selected`,(0,x.jsx)(`button`,{type:`button`,onClick:()=>w(null),"aria-label":`Clear session filter`,className:`hover:text-ink-base focus-visible:outline-none`,children:`✕`})]}),re>0&&(0,x.jsxs)(`span`,{className:`text-[11px] text-accent-amber`,children:[re,` of `,C.size,` not shown — older than the`,` `,FU,` most recent sessions`]})]}),P&&(0,x.jsx)(`button`,{type:`button`,onClick:()=>{o(`all`),c(`all`),u(`all`),y(null),w(null)},className:`text-[10px] text-ink-muted hover:text-ink-subtle underline-offset-2 hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-cyan/40 rounded-sm`,children:`Clear filters`})]}),(0,x.jsxs)(`div`,{className:`grid grid-cols-[260px_1fr] gap-3 flex-1 min-h-0`,children:[(0,x.jsxs)(B,{padding:`none`,tone:`static`,className:`overflow-hidden flex flex-col`,children:[(0,x.jsx)(`header`,{className:`p-2 border-b border-border-subtle`,children:(0,x.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,x.jsx)(V,{as:`h2`,children:`List`}),(0,x.jsxs)(`select`,{value:r,onChange:e=>i(e.target.value),className:`text-[10px] bg-surface-5 border border-border-medium rounded-md px-1.5 py-0.5 text-ink-subtle`,children:[(0,x.jsx)(`option`,{value:`date`,children:`Newest`}),(0,x.jsx)(`option`,{value:`lastActive`,children:`Last active`}),(0,x.jsx)(`option`,{value:`cost`,children:`Cost`}),(0,x.jsx)(`option`,{value:`calls`,children:`Calls`})]})]})}),(0,x.jsxs)(`div`,{className:`overflow-auto`,children:[E.isLoading&&(0,x.jsx)($,{variant:`loading`,icon:`timeline`,title:`Loading sessions`}),!E.isLoading&&ne.length===0&&k.size===0&&(0,x.jsx)($,{icon:`code`,title:P?`No matching sessions`:`No sessions yet`,subtitle:P?F?`No sessions own a workflow run matching these filters.`:`No sessions in this time window.`:`Start coding with Claude to see your sessions here.`}),ne.map(e=>(0,x.jsx)(XU,{row:e,isLive:k.has(e.sessionId),isSelected:t===e.sessionId,isExpanded:p.has(e.sessionId),sortKey:r,runs:te.get(e.sessionId)??[],expandedRuns:h,onSelect:ae,onToggleSession:oe,onToggleRun:I,onOpenRun:se},e.sessionId)),j.length>=FU&&(0,x.jsxs)(`div`,{className:`p-2 text-[10px] text-ink-muted text-center border-t border-border-subtle`,children:[`Only the `,FU,` most recent sessions are loaded`,P?`; filters narrow this further`:``,`.`]})]})]}),(0,x.jsxs)(`div`,{className:`glass-card glass-card-static p-4 overflow-auto`,children:[!t&&(0,x.jsx)($,{icon:`timeline`,title:`Loading sessions`,subtitle:`Selecting the most recent session…`}),t&&A.isLoading&&(0,x.jsx)($,{variant:`loading`,icon:`timeline`,title:`Loading detail`}),t&&A.isError&&(0,x.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-8 gap-4`,children:[(0,x.jsx)($,{icon:`timeline`,title:`Session not found`,subtitle:`This session could not be loaded.`}),(0,x.jsx)(`button`,{type:`button`,onClick:()=>n(null),className:`text-accent-cyan hover:text-accent-cyan/80 text-sm font-medium`,children:`Clear selection`})]}),t&&A.data&&(0,x.jsx)($U,{data:A.data,isLive:!!t&&k.has(t),onOpenRun:se})]})]}),d!=null&&(0,x.jsx)(iH,{runId:d,onClose:()=>f(null)})]})}function XU({row:e,isLive:t,isSelected:n,isExpanded:r,sortKey:i,runs:a,expandedRuns:o,onSelect:s,onToggleSession:c,onToggleRun:l,onOpenRun:u}){return(0,x.jsxs)(`div`,{className:`border-b border-border-subtle`,children:[(0,x.jsxs)(`div`,{className:`flex items-stretch text-xs transition-colors duration-150 hover:bg-surface-5 `+(n?`bg-surface-5`:``),children:[(0,x.jsx)(`button`,{type:`button`,"aria-label":r?`Collapse workflows`:`Expand workflows`,"aria-expanded":r,onClick:t=>{t.stopPropagation(),c(e.sessionId)},className:`shrink-0 flex items-center justify-center w-6 text-ink-muted hover:text-ink-base focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-cyan/40`,children:r?(0,x.jsx)(hn,{size:13,"aria-hidden":`true`}):(0,x.jsx)(gn,{size:13,"aria-hidden":`true`})}),(0,x.jsxs)(`button`,{type:`button`,onClick:()=>s(e.sessionId),className:`flex-1 min-w-0 text-left py-2 pr-2`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,x.jsx)(`span`,{className:`font-mono text-ink-base truncate`,children:e.sessionName||e.sessionId.slice(0,8)}),t&&(0,x.jsx)(ii,{size:`sm`,label:`live`,className:`shrink-0`})]}),(0,x.jsxs)(`div`,{className:`flex justify-between mt-1 text-ink-subtle text-[11px] tabular-nums`,children:[(0,x.jsxs)(`span`,{children:[e.toolCallCount??0,` calls`]}),(0,x.jsx)(`span`,{className:`text-ink-muted`,title:i===`lastActive`&&e.startTime?`Started ${vi(e.startTime)}`:void 0,children:e.startTime?vi(i===`lastActive`?KU(e):e.startTime):`—`}),(0,x.jsx)(`span`,{children:wi(e.estimatedCostUsd)})]})]})]}),r&&(0,x.jsx)(`div`,{className:`pl-3 border-l border-border-subtle ml-3 mb-1`,children:a.length===0?(0,x.jsx)(`div`,{className:`py-1.5 pl-1 text-[10px] text-ink-muted`,children:`No workflows in this session.`}):a.map(e=>(0,x.jsx)(ZU,{run:e,isExpanded:o.has(e.runId),onToggleRun:l,onOpenRun:u},e.runId))})]})}function ZU({run:e,isExpanded:t,onToggleRun:n,onOpenRun:r}){let{data:i}=L({queryKey:z.workflowDetail(e.runId),queryFn:()=>Hr(e.runId),enabled:t}),a=(0,b.useMemo)(()=>i?.agents??[],[i]),o=LU[e.status]??LU.unknown;return(0,x.jsxs)(`div`,{children:[(0,x.jsxs)(`div`,{className:`flex items-stretch hover:bg-surface-5 rounded transition-colors`,children:[(0,x.jsx)(`button`,{type:`button`,"aria-label":t?`Collapse agents`:`Expand agents`,"aria-expanded":t,onClick:t=>{t.stopPropagation(),n(e.runId)},className:`shrink-0 flex items-center justify-center w-5 text-ink-muted hover:text-ink-base focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-cyan/40`,children:t?(0,x.jsx)(hn,{size:12,"aria-hidden":`true`}):(0,x.jsx)(gn,{size:12,"aria-hidden":`true`})}),(0,x.jsxs)(`button`,{type:`button`,"aria-label":`View workflow run ${e.workflowName??e.runId}`,onClick:()=>r(e.runId),className:`flex-1 min-w-0 flex items-center gap-1.5 text-left py-1.5 pr-1 text-[10px] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-cyan/40 rounded`,children:[(0,x.jsx)(`span`,{className:`flex-1 min-w-0 font-medium text-ink-base truncate`,children:e.workflowName??e.runId}),(0,x.jsxs)(`span`,{className:`text-ink-muted tabular-nums shrink-0`,children:[e.agentCount==null?0:e.agentCount,`a`]}),(0,x.jsx)(`span`,{className:`text-ink-muted tabular-nums shrink-0`,children:wi(e.totalUsd)}),(0,x.jsx)(ni,{tone:o.tone,size:`sm`,bordered:!0,children:o.label})]})]}),t&&(0,x.jsx)(`div`,{className:`pl-3 border-l border-border-subtle ml-2.5`,children:a.length===0?(0,x.jsx)(`div`,{className:`py-1 pl-1 text-[10px] text-ink-muted`,children:`No agents recorded.`}):a.map(t=>(0,x.jsxs)(`button`,{type:`button`,"aria-label":`View agent ${t.label} in run ${e.workflowName??e.runId}`,onClick:()=>r(e.runId),className:`flex w-full items-center gap-1.5 text-left py-1 pr-1 text-[10px] hover:bg-surface-5 rounded transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-cyan/40`,children:[(0,x.jsx)(`span`,{className:`flex-1 min-w-0 text-ink-subtle truncate`,title:t.label,children:t.label}),(0,x.jsx)(`span`,{className:`font-mono text-ink-muted truncate max-w-[72px] shrink-0`,title:t.model,children:t.model}),(0,x.jsx)(`span`,{className:`text-ink-muted tabular-nums shrink-0`,children:JU(t.tokens)})]},t.agentId))})]})}function QU(e){return e===`Read`?`bg-accent-blue/80`:e===`Edit`||e===`Write`?`bg-accent-green/80`:e===`Bash`?`bg-accent-purple/80`:e===`Agent`?`bg-accent-teal/80`:`bg-ink-subtle/80`}function $U({data:e,isLive:t,onOpenRun:n}){let r=e.toolBreakdown??{},i=Object.entries(r).sort((e,t)=>t[1]-e[1]),a=e.toolCallCount??0,o=e.durationMs==null?null:xi(e.durationMs),s=e.timeline??[],c=s.length>0?s[0].timestamp:0,l=Object.entries(e.modelBreakdown??{}),u=l.length>0?l.sort((e,t)=>t[1].requestCount-e[1].requestCount).map(([e])=>e):e.model?[e.model]:[];return s.length===0&&i.length===0?(0,x.jsx)($,{icon:`timeline`,title:`No tool calls`,subtitle:`This session has no recorded tool calls.`}):(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`div`,{className:`flex items-baseline justify-between mb-3`,children:(0,x.jsxs)(`div`,{children:[(0,x.jsxs)(`h2`,{className:`text-xs tracking-wider text-ink-muted flex items-center gap-2`,children:[(0,x.jsx)(`span`,{className:`font-mono text-ink-base ${e.sessionName?`font-medium`:`uppercase`}`,children:e.sessionName||e.sessionId.slice(0,8)}),(0,x.jsx)(`span`,{"aria-hidden":`true`,children:`·`}),(0,x.jsxs)(`span`,{className:`uppercase`,children:[a,` calls`]}),o&&(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(`span`,{"aria-hidden":`true`,children:`·`}),(0,x.jsx)(`span`,{className:`tabular-nums`,children:o})]}),t&&(0,x.jsx)(ii,{size:`sm`,label:`live`})]}),c>0&&(0,x.jsx)(`div`,{className:`text-[11px] text-ink-subtle mt-0.5`,children:new Date(c).toLocaleString(void 0,{weekday:`short`,month:`short`,day:`numeric`,hour:`numeric`,minute:`2-digit`})})]})}),(0,x.jsxs)(`div`,{className:`grid grid-cols-3 gap-2 mb-4 text-xs`,children:[u.length>0&&(0,x.jsxs)(`div`,{className:`bg-surface-3 rounded-lg p-2.5`,children:[(0,x.jsx)(V,{children:u.length>1?`Models (${u.length})`:`Model`}),u.length>1?(0,x.jsx)(`div`,{className:`flex flex-col gap-0.5 mt-0.5`,children:u.map(e=>(0,x.jsx)(`div`,{className:`font-mono text-[11px] truncate`,title:e,children:e},e))}):(0,x.jsx)(`div`,{className:`font-mono`,children:u[0]})]}),e.estimatedCostUsd!=null&&(0,x.jsxs)(`div`,{className:`bg-surface-3 rounded-lg p-2.5`,children:[(0,x.jsx)(V,{children:`Cost`}),(0,x.jsx)(`div`,{className:`tabular-nums`,children:Ci(e.estimatedCostUsd)})]}),e.outcome&&(0,x.jsxs)(`div`,{className:`bg-surface-3 rounded-lg p-2.5`,children:[(0,x.jsx)(V,{children:`Status`}),(0,x.jsx)(`div`,{className:`capitalize`,children:e.outcome})]})]}),(e.antiPatterns?.length??0)>0&&(0,x.jsxs)(`div`,{className:`mb-4`,children:[(0,x.jsx)(V,{className:`mb-1`,children:`Anti-Patterns`}),(0,x.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:Object.entries((e.antiPatterns??[]).reduce((e,t)=>{let n=t.iterations??t.readCount??t.repeatCount??t.editCount??t.agentCount??1;return e[t.type]=(e[t.type]??0)+n,e},{})).map(([e,t])=>(0,x.jsxs)(ni,{tone:`warning`,size:`sm`,bordered:!0,children:[IU[e]??e,(0,x.jsxs)(`span`,{className:`opacity-70`,children:[`× `,t]})]},e))})]}),(e.qualityProxy||e.toolSelectionScore)&&(0,x.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 mb-4`,children:[e.qualityProxy&&(0,x.jsxs)(`div`,{className:`bg-surface-3 rounded-lg p-3`,children:[(0,x.jsx)(V,{className:`mb-2`,children:`Session Quality`}),(0,x.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 text-xs`,children:[(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`Diff Apply `}),(0,x.jsx)(`span`,{className:gi(e.qualityProxy.diffApplyRate),children:e.qualityProxy.diffApplyRate===null?`—`:`${(e.qualityProxy.diffApplyRate*100).toFixed(0)}%`})]}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`Test Pass `}),(0,x.jsx)(`span`,{className:gi(e.qualityProxy.testPassRate),children:e.qualityProxy.testPassRate===null?`—`:`${(e.qualityProxy.testPassRate*100).toFixed(0)}%`})]}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`Backtracks `}),(0,x.jsx)(`span`,{className:e.qualityProxy.backtrackCount>0?`text-accent-amber`:``,children:e.qualityProxy.backtrackCount})]}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`Self-corrections `}),(0,x.jsx)(`span`,{className:`text-ink-subtle`,children:e.qualityProxy.selfCorrectionCount})]})]})]}),e.toolSelectionScore&&(0,x.jsxs)(`div`,{className:`bg-surface-3 rounded-lg p-3`,children:[(0,x.jsx)(V,{className:`mb-2`,children:`Tool Selection`}),(0,x.jsx)(`div`,{className:`text-2xl font-semibold tabular-nums ${_i(e.toolSelectionScore.score)}`,children:e.toolSelectionScore.score.toFixed(2)}),(0,x.jsxs)(`div`,{className:`text-[10px] text-ink-muted mt-1`,children:[`re-reads: `,e.toolSelectionScore.redundantReadCount,` · repeat fails:`,` `,e.toolSelectionScore.repeatedFailureCount,` · unused:`,` `,e.toolSelectionScore.unusedOutputCount]})]})]}),t&&(0,x.jsx)(`div`,{className:`mb-4`,children:(0,x.jsx)(gH,{sessionId:e.sessionId})}),i.length>0&&(0,x.jsx)(tW,{breakdownEntries:i,totalCalls:a,isLive:t,sessionId:e.sessionId},`tools-${e.sessionId}`),(0,x.jsx)(rW,{timeline:s}),(e.filesRead?.length??0)>0&&(0,x.jsxs)(`div`,{className:`mb-4`,children:[(0,x.jsx)(V,{className:`mb-1`,children:`Files Read`}),(0,x.jsx)(`ul`,{className:`text-[11px] text-ink-subtle space-y-0.5`,children:e.filesRead.map(e=>(0,x.jsx)(`li`,{className:`font-mono truncate`,children:e.split(`/`).slice(-2).join(`/`)},e))})]}),(e.filesModified?.length??0)>0&&(0,x.jsxs)(`div`,{className:`mb-4`,children:[(0,x.jsx)(V,{className:`mb-1`,children:`Files Modified`}),(0,x.jsx)(`ul`,{className:`text-[11px] text-ink-subtle space-y-0.5`,children:e.filesModified.map(e=>(0,x.jsx)(`li`,{className:`font-mono truncate`,children:e.split(`/`).slice(-2).join(`/`)},e))})]}),(0,x.jsx)(eW,{sessionId:e.sessionId,isLive:t,parentEntries:s,onOpenRun:n},e.sessionId)]})}function eW({sessionId:e,isLive:t,parentEntries:n,onOpenRun:r}){let{data:i,isLoading:a,isError:o}=L({queryKey:z.sessionSubagents(e),queryFn:()=>xr(e),retry:!1,refetchInterval:t?1e4:!1}),{data:s}=L({queryKey:z.workflows,queryFn:Vr,refetchInterval:t?1e4:3e4}),c=(0,b.useMemo)(()=>{let t={};if(!Array.isArray(s))return t;for(let n of s)n.parentSessionId===e&&(t[n.runId]=n.status);return t},[s,e]),l=(0,b.useMemo)(()=>i?.agents??[],[i]),u=(0,b.useMemo)(()=>{let e=i!==void 0&&(i.agents?.length??0)>0,t=e?i.window.startMs:null,r=e?i.window.endMs:null,a=null,o=null;for(let e of n){let t=e.timestamp,n=e.timestamp+(e.durationMs??50);(a===null||t<a)&&(a=t),(o===null||n>o)&&(o=n)}let s=[a,t].filter(e=>e!==null),c=[o,r].filter(e=>e!==null);return s.length===0||c.length===0?null:{startMs:Math.min(...s),endMs:Math.max(...c)}},[i,n]),d=(0,b.useMemo)(()=>n.map(e=>({timestamp:e.timestamp,toolName:e.toolName,durationMs:e.durationMs,success:e.success,filePath:e.filePath,command:e.command})),[n]);return(0,x.jsxs)(`div`,{className:`mb-4`,children:[(0,x.jsx)(V,{className:`mb-2`,children:`Session trace`}),(0,x.jsx)(B,{tone:`static`,padding:`sm`,children:a?(0,x.jsx)($,{variant:`loading`,icon:`radar`,title:`Loading subagents`}):o||i===void 0?(0,x.jsx)(PV,{sessionId:e,parentEntries:d,agents:[],window:u??{startMs:0,endMs:1},onSelectRun:r,runStatusById:c}):(0,x.jsx)(PV,{sessionId:e,parentEntries:d,agents:l,window:u??i.window,onSelectRun:r,runStatusById:c})})]})}function tW({breakdownEntries:e,totalCalls:t,isLive:n,sessionId:r}){let[i,a]=(0,b.useState)(`calls`),{data:o}=L({queryKey:[`context`,r],queryFn:()=>Ar(r),refetchInterval:1e4,enabled:n&&i===`context`}),s=o?.toolContributions??[],c=s.length>0?s[0].estimatedTokens:0;return(0,x.jsxs)(`div`,{className:`mb-4`,children:[(0,x.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,x.jsx)(V,{children:`Tools`}),n&&(0,x.jsx)(si,{value:i,onChange:a,options:[{value:`calls`,label:`Calls`},{value:`context`,label:`Context`}],size:`sm`,tone:`cyan`,ariaLabel:`Tools view`})]}),(0,x.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[i===`calls`&&e.map(([e,n])=>{let r=t>0?n/t*100:0;return(0,x.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px]`,children:[(0,x.jsx)(`span`,{className:`w-28 text-ink-subtle truncate`,title:e,children:Ei(e)}),(0,x.jsx)(`div`,{className:`flex-1 h-3 bg-surface-3 relative rounded`,children:(0,x.jsx)(`div`,{className:`h-3 rounded ${QU(e)}`,style:{width:`${r}%`}})}),(0,x.jsx)(`span`,{className:`w-10 text-right text-ink-muted tabular-nums`,children:n})]},e)}),i===`context`&&s.map(e=>{let t=c>0?e.estimatedTokens/c*100:0;return(0,x.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px]`,children:[(0,x.jsx)(`span`,{className:`w-28 text-ink-subtle truncate`,title:e.tool,children:Ei(e.tool)}),(0,x.jsx)(`div`,{className:`flex-1 h-3 bg-surface-3 relative rounded`,children:(0,x.jsx)(`div`,{className:`h-3 rounded bg-accent-amber/80`,style:{width:`${t}%`}})}),(0,x.jsxs)(`span`,{className:`w-16 text-right text-ink-muted tabular-nums text-[10px]`,children:[`~`,nW(e.estimatedTokens)]})]},e.tool)}),i===`context`&&s.length===0&&(0,x.jsx)(`div`,{className:`text-[11px] text-ink-muted`,children:`No context data available yet`})]})]})}function nW(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function rW({timeline:e}){let t=(0,b.useMemo)(()=>{if(e.length<2)return null;let t=e[0].timestamp,n=e[e.length-1].timestamp,r=n-t;if(r<1e3)return null;let i=PU(r),a=NU(e,{startMs:t,endMs:n+i,bucketSizeMs:i});return{buckets:a,maxCount:Math.max(...a,1),bucketSizeMs:i,startMs:t}},[e]);return t?(0,x.jsxs)(`div`,{className:`mb-4`,children:[(0,x.jsx)(V,{className:`mb-1`,children:`Activity Density`}),(0,x.jsx)(EH,{variant:`strip`,buckets:t.buckets,maxCount:t.maxCount,bucketSizeMs:t.bucketSizeMs,startTimestamp:t.startMs,ariaLabel:`Session activity density`})]}):null}var iW={fill:`var(--color-ink-muted)`,fontSize:10},aW=`var(--color-border-subtle)`,oW={background:`var(--color-bg-elevated)`,border:`1px solid var(--color-border-medium)`,borderRadius:8,fontSize:12,color:`var(--color-ink-base)`},sW={color:`var(--color-ink-base)`},cW=`var(--color-accent-green)`,lW=`var(--color-accent-amber)`,uW=`var(--color-accent-green)`,dW=`var(--color-accent-purple)`,fW=`var(--color-accent-blue)`,pW=`var(--color-accent-teal)`;function mW(e){return e===`Read`?fW:e===`Edit`||e===`Write`?uW:e===`Bash`?dW:e===`Agent`?pW:`var(--color-ink-muted)`}function hW(e){let t=e.toLowerCase();return t===`bug fix`||t===`fix`?`#FF6B6B`:t===`feature`?uW:t===`refactor`?fW:t===`configuration`||t===`config`?lW:t===`test`?pW:t===`docs`?`#C4B5FD`:dW}function gW(e){return typeof e==`string`&&e.length>=10?e.slice(5,10):e}var _W=`Compares session outcomes before and after your most recent change to an instruction file (CLAUDE.md, or the active platform's equivalent) — success rate, token usage, and thrashing incidents. A degraded verdict means sessions got worse after the edit, not better.`;function vW({label:e,value:t}){return(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`div`,{className:`text-[10px] text-ink-muted uppercase tracking-wider`,children:e}),(0,x.jsx)(`div`,{className:`text-sm font-bold tabular-nums mt-0.5`,children:t})]})}function yW({data:e}){if(!e)return(0,x.jsx)(xW,{title:`Instruction Drift`,tooltip:_W,children:(0,x.jsx)($,{variant:`loading`,title:`Loading drift data…`})});let t=e.recentCorrelations[e.recentCorrelations.length-1];return t?(0,x.jsx)(xW,{title:`Instruction Drift — most recent instruction file change`,tooltip:_W,children:(0,x.jsxs)(`div`,{className:`flex items-center gap-6`,children:[(0,x.jsx)(ni,{tone:{improved:`success`,degraded:`danger`,neutral:`neutral`,insufficient_data:`neutral`}[t.verdict],children:t.verdict}),(0,x.jsx)(vW,{label:`Success`,value:t.successRateDelta===null?`—`:`${t.successRateDelta>0?`+`:``}${Math.round(t.successRateDelta*100)}%`}),(0,x.jsx)(vW,{label:`Tokens`,value:`${t.tokensDelta>0?`+`:``}${t.tokensDelta}`}),(0,x.jsx)(vW,{label:`Thrashing`,value:`${t.thrashingDelta>0?`+`:``}${t.thrashingDelta}`})]})}):(0,x.jsx)(xW,{title:`Instruction Drift`,tooltip:_W,children:(0,x.jsx)(`div`,{className:`text-ink-muted text-xs`,children:`No instruction file changes tracked yet.`})})}function bW(){let e=L({queryKey:z.weekly,queryFn:fr}),t=L({queryKey:z.sessionsList(200),queryFn:()=>nr(200)}),n=L({queryKey:z.costPerOutcome(30),queryFn:()=>mr(30)}),r=L({queryKey:z.personalCoach,queryFn:hr}),i=L({queryKey:z.recommendations,queryFn:gr,retry:!1}),a=L({queryKey:z.claudeMdImpact,queryFn:_r,retry:!1}),o=L({queryKey:z.collaborationProfile,queryFn:vr,retry:!1}),s=L({queryKey:z.activityHeatmap(`history`),queryFn:()=>kr(`history`,12)}),c=L({queryKey:z.concurrencyHistory(30),queryFn:()=>Or(30)}),l=L({queryKey:z.instructionDrift,queryFn:Ur}),u=e.isError||t.isError||n.isError||c.isError,d=[...e.data??[]].reverse(),f=d.map(e=>{let t=e.avgEfficiencyScore;return{week:e.week||`?`,efficiency:t===null?null:Math.round(t*100)}}),p=FW(MW(t.data??[],30),30),m=(t.data?.length??0)>=200&&NW(t.data??[],30),h=PW(n.data),g=IW(d),_=zW(t.data??[]),v=BW(t.data??[]),y=new Set((t.data??[]).flatMap(e=>e.toolBreakdown?Object.keys(e.toolBreakdown):[])).size,b=Math.max(0,y-v.length),S=c.data?.dailyPeaks??[],C=S.some(e=>e.peak>0);return(0,x.jsxs)(`section`,{children:[(0,x.jsx)(AH,{theme:`history`}),(0,x.jsx)(`h1`,{className:`text-xl font-semibold gradient-text mb-4`,children:`History`}),u&&(0,x.jsx)(`div`,{className:`text-accent-red text-xs mb-3`,children:`Error loading some history data. Charts below may be incomplete.`}),(0,x.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,x.jsx)(xW,{title:`Weekly Efficiency · Last 12`,children:(0,x.jsx)(`div`,{className:`h-44 min-w-0`,children:(0,x.jsx)(np,{width:`100%`,height:`100%`,minWidth:1,minHeight:1,children:(0,x.jsxs)(rV,{data:f,children:[(0,x.jsx)(`defs`,{children:(0,x.jsxs)(`linearGradient`,{id:`effGradient`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,x.jsx)(`stop`,{offset:`0%`,stopColor:cW,stopOpacity:.3}),(0,x.jsx)(`stop`,{offset:`100%`,stopColor:cW,stopOpacity:0})]})}),(0,x.jsx)(hI,{stroke:aW,strokeDasharray:`3 3`}),(0,x.jsx)(YR,{dataKey:`week`,tick:iW,stroke:aW,tickFormatter:gW}),(0,x.jsx)(uz,{tick:iW,stroke:aW,domain:[0,100],unit:`%`}),(0,x.jsx)(Yk,{contentStyle:oW}),(0,x.jsx)(yL,{type:`monotone`,dataKey:`efficiency`,stroke:cW,strokeWidth:2,fill:`url(#effGradient)`,dot:{r:2,fill:cW}})]})})})}),(0,x.jsxs)(xW,{title:`Daily Spend · Last 30 Days (most recent 200)`,children:[(0,x.jsx)(`div`,{className:`h-44 min-w-0`,children:(0,x.jsx)(np,{width:`100%`,height:`100%`,minWidth:1,minHeight:1,children:(0,x.jsxs)(tV,{data:p,children:[(0,x.jsx)(`defs`,{children:(0,x.jsxs)(`linearGradient`,{id:`costGradient`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,x.jsx)(`stop`,{offset:`0%`,stopColor:cW,stopOpacity:.9}),(0,x.jsx)(`stop`,{offset:`100%`,stopColor:cW,stopOpacity:.4})]})}),(0,x.jsx)(hI,{stroke:aW,strokeDasharray:`3 3`}),(0,x.jsx)(YR,{dataKey:`day`,tick:iW,stroke:aW,tickFormatter:gW,interval:`preserveStartEnd`,minTickGap:20}),(0,x.jsx)(uz,{tick:iW,stroke:aW,unit:`$`}),(0,x.jsx)(Yk,{contentStyle:oW,labelFormatter:e=>gW(String(e)),cursor:!1}),(0,x.jsx)(OR,{dataKey:`cost`,fill:`url(#costGradient)`,radius:[3,3,0,0]})]})})}),m&&(0,x.jsx)(`div`,{className:`text-[10px] text-ink-muted italic mt-1`,children:`Sample doesn't reach back 30 days — early days in this chart may undercount actual spend.`})]}),(0,x.jsx)(xW,{title:`Cost Per Outcome · Last 30 Days`,children:h.length===0?(0,x.jsx)($,{icon:`radar`,title:`No outcomes yet`,subtitle:`Finish a few sessions and check back.`}):(0,x.jsx)(`div`,{className:`min-w-0`,style:{height:`${Math.max(176,h.length*32+40)}px`},children:(0,x.jsx)(np,{width:`100%`,height:`100%`,minWidth:1,minHeight:1,children:(0,x.jsxs)(tV,{data:h,layout:`vertical`,children:[(0,x.jsx)(hI,{stroke:aW,strokeDasharray:`3 3`}),(0,x.jsx)(YR,{type:`number`,tick:iW,stroke:aW,unit:`$`}),(0,x.jsx)(uz,{type:`category`,dataKey:`outcome`,tick:iW,stroke:aW,width:110}),(0,x.jsx)(Yk,{contentStyle:oW,itemStyle:sW}),(0,x.jsx)(OR,{dataKey:`totalCost`,radius:[0,3,3,0],children:h.map(e=>(0,x.jsx)(Xk,{fill:hW(e.outcome),fillOpacity:.8},e.outcome))})]})})})}),(0,x.jsx)(xW,{title:`Anti-Pattern Frequency · Weekly`,children:g.length===0||g.every(e=>e.count===0)?(0,x.jsx)($,{icon:`checkmark`,title:`No anti-patterns detected`,subtitle:`No anti-patterns detected in the loaded weeks.`}):(0,x.jsx)(`div`,{className:`h-44 min-w-0`,children:(0,x.jsx)(np,{width:`100%`,height:`100%`,minWidth:1,minHeight:1,children:(0,x.jsxs)(tV,{data:g,children:[(0,x.jsx)(`defs`,{children:(0,x.jsxs)(`linearGradient`,{id:`antiPatternGradient`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,x.jsx)(`stop`,{offset:`0%`,stopColor:lW,stopOpacity:.9}),(0,x.jsx)(`stop`,{offset:`100%`,stopColor:lW,stopOpacity:.4})]})}),(0,x.jsx)(hI,{stroke:aW,strokeDasharray:`3 3`}),(0,x.jsx)(YR,{dataKey:`week`,tick:iW,stroke:aW,tickFormatter:gW}),(0,x.jsx)(uz,{tick:iW,stroke:aW}),(0,x.jsx)(Yk,{contentStyle:oW}),(0,x.jsx)(OR,{dataKey:`count`,fill:`url(#antiPatternGradient)`,radius:[3,3,0,0]})]})})})}),(0,x.jsx)(xW,{title:`Model Performance · Most Recent 200 Sessions`,children:_.length===0?(0,x.jsx)($,{icon:`radar`,title:`No model data yet`,subtitle:`Complete a few sessions to see model performance.`}):(0,x.jsxs)(`div`,{className:`h-44 overflow-y-auto text-xs`,children:[(0,x.jsxs)(`table`,{className:`w-full`,children:[(0,x.jsx)(`thead`,{className:`text-ink-muted sticky top-0 bg-bg-panel`,children:(0,x.jsxs)(`tr`,{children:[(0,x.jsx)(`th`,{className:`text-left pb-1`,children:`Model`}),(0,x.jsx)(`th`,{className:`text-right pb-1`,children:`Sessions`}),(0,x.jsx)(`th`,{className:`text-right pb-1`,children:`Eff.`}),(0,x.jsx)(`th`,{className:`text-right pb-1`,children:`Success`}),(0,x.jsx)(`th`,{className:`text-right pb-1`,children:`Avg $`}),(0,x.jsx)(`th`,{className:`text-right pb-1`,children:`$/1M tok`})]})}),(0,x.jsx)(`tbody`,{children:_.map(e=>(0,x.jsxs)(`tr`,{className:`border-t border-bg-line`,children:[(0,x.jsx)(`td`,{className:`py-1 font-medium`,children:e.model}),(0,x.jsx)(`td`,{className:`py-1 text-right tabular-nums`,children:e.sessions}),(0,x.jsx)(`td`,{className:`py-1 text-right tabular-nums`,children:e.avgEfficiency===null?`—`:`${Math.min(100,Math.round(e.avgEfficiency*100))}%`}),(0,x.jsx)(`td`,{className:`py-1 text-right tabular-nums ${e.flagged?`text-accent-amber`:``}`,children:e.avgSuccessRate===null?`—`:`${Math.min(100,Math.round(e.avgSuccessRate*100))}%`}),(0,x.jsx)(`td`,{className:`py-1 text-right tabular-nums`,children:wi(e.avgCost)}),(0,x.jsx)(`td`,{className:`py-1 text-right tabular-nums text-ink-subtle`,children:wi(e.costPerMillionTokens)})]},e.model))})]}),_.some(e=>e.flagged)&&(0,x.jsx)(`div`,{className:`text-accent-amber text-[10px] mt-1`,children:`⚠ Highlighted models had sessions with elevated error rates`})]})}),(0,x.jsxs)(xW,{title:`Top Tools · Most Recent 200 Sessions`,children:[v.length===0?(0,x.jsx)($,{icon:`code`,title:`No tool data yet`,subtitle:`Tool usage data will appear after coding sessions.`}):(0,x.jsx)(`div`,{className:`min-w-0`,style:{height:`${Math.max(176,v.length*28+40)}px`},children:(0,x.jsx)(np,{width:`100%`,height:`100%`,minWidth:1,minHeight:1,children:(0,x.jsxs)(tV,{data:v,layout:`vertical`,children:[(0,x.jsx)(hI,{stroke:aW,strokeDasharray:`3 3`}),(0,x.jsx)(YR,{type:`number`,tick:iW,stroke:aW}),(0,x.jsx)(uz,{type:`category`,dataKey:`tool`,tick:iW,tickFormatter:Ei,stroke:aW,width:120}),(0,x.jsx)(Yk,{contentStyle:oW,itemStyle:sW,labelFormatter:e=>Ei(String(e))}),(0,x.jsx)(OR,{dataKey:`count`,radius:[0,3,3,0],children:v.map(e=>(0,x.jsx)(Xk,{fill:mW(Ei(e.tool)),fillOpacity:.8},e.tool))})]})})}),b>0&&(0,x.jsxs)(`div`,{className:`text-[10px] text-ink-muted italic mt-1`,children:[`+`,b,` more tool`,b===1?``:`s`,` not shown`]})]})]}),(0,x.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 mt-3`,children:[s.data&&s.data.days.length>0&&(0,x.jsx)(xW,{title:`Activity · Last 12 Weeks`,children:(0,x.jsx)(EH,{variant:`grid`,buckets:[],maxCount:s.data.maxCount,days:s.data.days,ariaLabel:`Daily activity heatmap for the last 12 weeks`})}),(0,x.jsxs)(B,{padding:`md`,className:`flex flex-col`,children:[(0,x.jsxs)(V,{className:`mb-3`,children:[`Peak Concurrent Sessions · Last 30 Days`,C&&`: ${Math.max(...S.map(e=>e.peak))}`]}),C?(0,x.jsx)(`div`,{className:`flex-1 flex items-end justify-center`,children:(0,x.jsx)(VW,{data:S})}):(0,x.jsx)($,{icon:`code`,title:`No concurrent sessions yet`,subtitle:`Run two or more Claude Code sessions at the same time to populate this chart.`})]})]}),(0,x.jsxs)(`div`,{className:`mt-3 space-y-3`,children:[(0,x.jsx)(AW,{data:o.data,isError:o.isError}),(0,x.jsx)(kW,{data:a.data,isError:a.isError})]}),(0,x.jsx)(`div`,{className:`mt-3`,children:(0,x.jsx)(yW,{data:l.data})}),(0,x.jsx)(`div`,{className:`mt-3`,children:(0,x.jsx)(jW,{data:r.data})}),(0,x.jsx)(`div`,{className:`mt-3`,children:(0,x.jsx)(TW,{data:i.data,isError:i.isError})})]})}function xW({title:e,tooltip:t,children:n}){return(0,x.jsxs)(B,{padding:`md`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,x.jsx)(V,{children:e}),t&&(0,x.jsx)(ui,{text:t})]}),(0,x.jsx)(`div`,{className:`mt-3`,children:n})]})}function SW({thisWeek:e,baseline:t}){let n=e.avgEfficiencyScore!==null&&t.avgEfficiencyScore!==null?Math.round((e.avgEfficiencyScore-t.avgEfficiencyScore)*100):null,r=t.avgCostPerSession>0?(e.avgCostPerSession-t.avgCostPerSession)/t.avgCostPerSession:null,i=t.antiPatternRate>0?(e.antiPatternRate-t.antiPatternRate)/t.antiPatternRate:null,a=Math.round(e.sessionsCount-t.sessionsCount);function o(e){return e===null?`text-ink-muted`:e>=5?`text-accent-green`:e<=-5?`text-accent-amber`:`text-ink-muted`}function s(e){return e===null?`text-ink-muted`:e<=-.15?`text-accent-green`:e>=.25?`text-accent-amber`:`text-ink-muted`}function c(e){return e===null?`text-ink-muted`:e<=-.2?`text-accent-green`:e>=.25?`text-accent-amber`:`text-ink-muted`}function l(e){return e===null?`—`:e===0?`0pts`:`${e>0?`↑`:`↓`}${Math.abs(e)}pts`}function u(e){return e===null?`—`:e===0?`0%`:`${e>0?`↑`:`↓`}${Math.abs(Math.round(e*100))}%`}function d(e){return e===0?`0`:e>0?`+${e}`:`${e}`}let f=e.avgEfficiencyScore===null?`—`:Math.round(e.avgEfficiencyScore*100).toString();return(0,x.jsxs)(`div`,{className:`grid grid-cols-3 gap-x-4 gap-y-1 text-xs mb-3`,children:[(0,x.jsx)(`span`,{className:`text-ink-muted`}),(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`This wk`}),(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`vs baseline`}),(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`Efficiency`}),(0,x.jsx)(`span`,{className:`font-mono`,children:f}),(0,x.jsx)(`span`,{className:o(n),children:l(n)}),(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`Cost / session`}),(0,x.jsxs)(`span`,{className:`font-mono`,children:[`$`,e.avgCostPerSession.toFixed(2)]}),(0,x.jsx)(`span`,{className:s(r),children:u(r)}),(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`Anti-pattern rate`}),(0,x.jsxs)(`span`,{className:`font-mono`,children:[(e.antiPatternRate*100).toFixed(1),`%`]}),(0,x.jsx)(`span`,{className:c(i),children:u(i)}),(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`Sessions`}),(0,x.jsx)(`span`,{className:`font-mono`,children:Math.round(e.sessionsCount)}),(0,x.jsx)(`span`,{className:`text-ink-muted`,children:d(a)})]})}function CW(e){return e===`cost_optimization`?`var(--color-accent-amber)`:e===`efficiency`?`var(--color-accent-red)`:e===`prompt_engineering`?`var(--color-accent-blue)`:e===`claudemd`?`var(--color-accent-purple)`:e===`model_selection`?`var(--color-accent-teal)`:`var(--color-ink-muted)`}function wW(e){return e===`high`?`var(--color-accent-amber)`:e===`medium`?`var(--color-accent-blue)`:`var(--color-ink-muted)`}function TW({data:e,isError:t}){if(t)return(0,x.jsx)(xW,{title:`Recommendations`,children:(0,x.jsx)($,{icon:`radar`,title:`Recommendations unavailable`,subtitle:`Connect a full Preflight session to enable recommendations.`})});if(!e)return(0,x.jsx)(xW,{title:`Recommendations`,children:(0,x.jsx)($,{variant:`loading`,title:`Loading recommendations…`})});if(e.recommendations.length===0)return(0,x.jsx)(xW,{title:`Recommendations`,children:(0,x.jsx)($,{icon:`radar`,title:`No recommendations yet`,subtitle:`Keep using Preflight — recommendations appear after a few sessions of data.`})});let n=e.recommendations.filter(e=>e.priority===`high`),r=e.recommendations.filter(e=>e.priority!==`high`);return(0,x.jsx)(xW,{title:`Recommendations`,children:(0,x.jsxs)(`div`,{className:`space-y-3`,children:[n.map(e=>(0,x.jsxs)(`div`,{className:`border-l-2 pl-3`,style:{borderColor:CW(e.category)},children:[(0,x.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,x.jsx)(`span`,{className:`text-sm font-medium text-ink-base`,children:e.title}),e.estimatedSavings&&(0,x.jsx)(`span`,{className:`text-[10px] text-accent-green shrink-0`,children:e.estimatedSavings})]}),(0,x.jsx)(`div`,{className:`text-xs text-ink-muted mt-0.5`,children:e.detail}),(0,x.jsx)(`div`,{className:`text-[10px] text-ink-muted italic mt-0.5`,children:e.evidence})]},e.id)),r.length>0&&(0,x.jsx)(`div`,{className:n.length>0?`border-t border-border-subtle pt-3`:``,children:(0,x.jsx)(`div`,{className:`space-y-2`,children:r.map(e=>(0,x.jsxs)(`div`,{className:`min-w-0`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,x.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full shrink-0`,style:{backgroundColor:wW(e.priority)}}),(0,x.jsx)(`span`,{className:`text-xs text-ink-base`,children:e.title})]}),(0,x.jsx)(`div`,{className:`text-[10px] text-ink-muted mt-0.5 pl-3.5`,children:e.detail})]},e.id))})})]})})}function EW(e){return e.startsWith(`Positive`)?`text-accent-green`:e.startsWith(`Negative`)?`text-accent-red`:`text-accent-amber`}function DW(e){if(!e)return`—`;if(e.value===0)return`0pts`;let t=Math.round(Math.abs(e.value)*100);return`${e.value>0?`↑`:`↓`}${t}pts`}function OW(e){if(!e||e.percentChange==null)return`—`;if(e.value===0)return`0%`;let t=Math.round(Math.abs(e.percentChange));return`${e.value>0?`↑`:`↓`}${t}%`}function kW({data:e,isError:t}){if(t)return(0,x.jsx)(xW,{title:`Instruction File Impact`,children:(0,x.jsx)($,{icon:`radar`,title:`Instruction file impact unavailable`})});if(!e)return(0,x.jsx)(xW,{title:`Instruction File Impact`,children:(0,x.jsx)($,{variant:`loading`,title:`Loading instruction file impact…`})});if(e.message||!e.change||!e.before||!e.after||!e.deltas||!e.verdict)return(0,x.jsx)(xW,{title:`Instruction File Impact`,children:(0,x.jsx)($,{icon:`radar`,title:`No instruction file changes yet`,subtitle:`Edit your instruction file (CLAUDE.md, or your platform's equivalent) to start tracking impact.`})});let n=new Date(e.change.timestamp).toLocaleDateString(void 0,{month:`short`,day:`numeric`}),r=e.before.avgEfficiencyScore===null?null:Math.round(e.before.avgEfficiencyScore*100),i=e.after.avgEfficiencyScore===null?null:Math.round(e.after.avgEfficiencyScore*100);return(0,x.jsxs)(xW,{title:`Instruction File Impact`,children:[(0,x.jsxs)(`div`,{className:`text-xs mb-3`,children:[(0,x.jsx)(`span`,{className:`font-medium ${EW(e.verdict)}`,children:e.verdict}),(0,x.jsxs)(`span`,{className:`text-[10px] text-ink-muted`,children:[` · `,e.change.changeType,` `,e.change.filePath.split(`/`).pop(),` · `,n]})]}),(0,x.jsxs)(`div`,{className:`grid grid-cols-4 gap-x-4 gap-y-1 text-xs`,children:[(0,x.jsx)(`span`,{className:`text-ink-muted`}),(0,x.jsxs)(`span`,{className:`text-ink-muted`,children:[`Before (n=`,e.before.sessionCount,`)`]}),(0,x.jsxs)(`span`,{className:`text-ink-muted`,children:[`After (n=`,e.after.sessionCount,`)`]}),(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`Δ`}),(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`Efficiency`}),(0,x.jsx)(`span`,{className:`font-mono`,children:r??`—`}),(0,x.jsx)(`span`,{className:`font-mono`,children:i??`—`}),(0,x.jsx)(`span`,{className:e.deltas.efficiencyScore==null?`text-ink-muted`:e.deltas.efficiencyScore.improved?`text-accent-green`:`text-accent-amber`,children:DW(e.deltas.efficiencyScore)}),(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`Cost/session`}),(0,x.jsxs)(`span`,{className:`font-mono`,children:[`$`,e.before.avgCostUsd.toFixed(2)]}),(0,x.jsxs)(`span`,{className:`font-mono`,children:[`$`,e.after.avgCostUsd.toFixed(2)]}),(0,x.jsx)(`span`,{className:e.deltas.cost.improved?`text-accent-green`:`text-accent-amber`,children:OW(e.deltas.cost)}),(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`Correction rate`}),(0,x.jsxs)(`span`,{className:`font-mono`,children:[Math.round(e.before.avgCorrectionRate*100),`%`]}),(0,x.jsxs)(`span`,{className:`font-mono`,children:[Math.round(e.after.avgCorrectionRate*100),`%`]}),(0,x.jsx)(`span`,{className:e.deltas.correctionRate.improved?`text-accent-green`:`text-accent-amber`,children:OW(e.deltas.correctionRate)})]}),e.contextTokensForClaudeMd!=null&&e.contextTokensForClaudeMd>0&&(0,x.jsxs)(`div`,{className:`text-[10px] text-ink-muted italic mt-2`,children:[`Instruction file adds ~`,e.contextTokensForClaudeMd.toLocaleString(),` tokens/turn`]})]})}function AW({data:e,isError:t}){if(t)return(0,x.jsx)(xW,{title:`Collaboration Profile`,children:(0,x.jsx)($,{icon:`radar`,title:`Collaboration profile unavailable`})});if(!e)return(0,x.jsx)(xW,{title:`Collaboration Profile`,children:(0,x.jsx)($,{variant:`loading`,title:`Loading collaboration profile…`})});if(e.sessionCount===0)return(0,x.jsx)(xW,{title:`Collaboration Profile`,children:(0,x.jsx)($,{icon:`radar`,title:`No collaboration data yet`,subtitle:`Profile appears after a few sessions.`})});let n=[{name:`Specificity`,key:`specificity`,value:Math.round(e.dimensions.specificity*100),delta:e.teamDeltas.specificity,lowerIsBetter:!1,note:``},{name:`Autonomy`,key:`autonomy`,value:Math.round(e.dimensions.autonomy*100),delta:e.teamDeltas.autonomy,lowerIsBetter:!1,note:``},{name:`Correction-free rate`,key:`correctionRate`,value:Math.round(e.dimensions.correctionRate*100),delta:e.teamDeltas.correctionRate,lowerIsBetter:!1,note:` (higher = better)`},{name:`Task complexity`,key:`taskComplexity`,value:Math.round(e.dimensions.taskComplexity*100),delta:e.teamDeltas.taskComplexity,lowerIsBetter:!1,note:``}];return(0,x.jsxs)(xW,{title:`Collaboration Profile`,children:[(0,x.jsxs)(`div`,{className:`text-xs mb-3`,children:[(0,x.jsx)(`span`,{className:`text-sm font-medium text-ink-base`,children:e.classification}),(0,x.jsxs)(`span`,{className:`text-ink-muted`,children:[` · `,e.sessionCount,` sessions`]})]}),e.developerCount<=1&&(0,x.jsx)(`div`,{className:`text-[10px] text-ink-muted italic mb-2`,children:`No team data yet — "vs team" comparisons below will reflect other developers once their sessions are recorded.`}),(0,x.jsx)(`div`,{className:`min-w-0`,style:{height:`${n.length*28+40}px`},children:(0,x.jsx)(np,{width:`100%`,height:`100%`,minWidth:1,minHeight:1,children:(0,x.jsxs)(tV,{data:n,layout:`vertical`,children:[(0,x.jsx)(hI,{stroke:aW,strokeDasharray:`3 3`}),(0,x.jsx)(YR,{type:`number`,domain:[0,100],tick:iW,stroke:aW,tickFormatter:e=>`${e}%`}),(0,x.jsx)(uz,{type:`category`,dataKey:`name`,tick:iW,stroke:aW,width:110}),(0,x.jsx)(Yk,{contentStyle:oW,formatter:e=>[`${e}%`]}),(0,x.jsx)(OR,{dataKey:`value`,fill:pW,fillOpacity:.8,radius:[0,3,3,0]})]})})}),(0,x.jsx)(`div`,{className:`space-y-1 mt-2`,children:n.map(e=>{let t=Math.round(Math.abs(e.delta)*100),n=e.lowerIsBetter?e.delta<0:e.delta>0,r=e.delta===0?`text-ink-muted`:n?`text-accent-green`:`text-accent-amber`,i=e.delta>0?`+`:e.delta<0?`-`:``,a=e.lowerIsBetter?` (lower = better)`:e.note;return(0,x.jsxs)(`div`,{className:`flex items-center justify-between text-[10px]`,children:[(0,x.jsxs)(`span`,{className:`text-ink-muted`,children:[e.name,a]}),(0,x.jsxs)(`span`,{className:r,children:[i,t,`% vs team`]})]},e.key)})})]})}function jW({data:e}){return e?e.status===`insufficient_data`?(0,x.jsx)(xW,{title:`Personal Coach`,children:(0,x.jsx)(`div`,{className:`text-ink-muted text-xs`,children:e.message})}):(0,x.jsx)(xW,{title:`Personal coach`,children:(0,x.jsxs)(`div`,{className:`text-xs space-y-2`,children:[(0,x.jsx)(SW,{thisWeek:e.thisWeek,baseline:e.baseline}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`span`,{className:`text-accent-cyan font-semibold`,children:`Top recommendation: `}),e.topRecommendation]}),e.highlights.length>0&&(0,x.jsx)(`ul`,{className:`list-disc list-inside text-accent-green`,children:e.highlights.map(e=>(0,x.jsx)(`li`,{children:e},`hl-${e}`))}),e.regressions.length>0&&(0,x.jsx)(`ul`,{className:`list-disc list-inside text-accent-amber`,children:e.regressions.map(e=>(0,x.jsx)(`li`,{children:e},`rg-${e}`))}),e.streaks.length>0&&(0,x.jsx)(`ul`,{className:`list-disc list-inside text-ink-muted`,children:e.streaks.map(e=>(0,x.jsx)(`li`,{children:e},`st-${e}`))})]})}):(0,x.jsx)(xW,{title:`Personal Coach`,children:(0,x.jsx)($,{variant:`loading`,title:`Loading coaching insights…`})})}function MW(e,t){let n=new Map;for(let t of e){if(t.estimatedCostUsd==null||t.startTime==null)continue;let e=new Date(t.startTime),r=`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`;n.set(r,(n.get(r)??0)+t.estimatedCostUsd)}return Array.from(n.entries()).sort((e,t)=>e[0].localeCompare(t[0])).slice(-t).map(([e,t])=>({day:e,cost:Number(t.toFixed(2))}))}function NW(e,t,n=new Date){if(e.length===0)return!1;let r=null;for(let t of e){if(t.startTime==null)continue;let e=new Date(t.startTime).getTime();Number.isNaN(e)||(r===null||e<r)&&(r=e)}if(r===null)return!1;let i=new Date(n);return i.setDate(i.getDate()-(t-1)),i.setHours(0,0,0,0),r>i.getTime()}function PW(e){return e?Object.entries(e.outcomeDistribution).map(([e,t])=>({outcome:e.replace(/_/g,` `),totalCost:Number(t.totalCost.toFixed(2)),count:t.count})).filter(e=>e.totalCost>0).sort((e,t)=>t.totalCost-e.totalCost):[]}function FW(e,t,n=new Date){let r=new Map(e.map(e=>[e.day,e.cost])),i=[];for(let e=t-1;e>=0;e--){let t=new Date(n);t.setDate(t.getDate()-e);let a=`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,`0`)}-${String(t.getDate()).padStart(2,`0`)}`;i.push({day:a,cost:r.get(a)??0})}return i}function IW(e){let t=[];for(let n of e){let e=n.antiPatternCounts??{},r=Object.values(e).reduce((e,t)=>e+t,0);t.push({week:n.week||`?`,count:r})}return t}var LW=.85,RW=.3;function zW(e){let t=new Map;for(let n of e){let e=n.model??`unknown`,r=t.get(e);if(r||(r={sessions:0,effSum:0,effCount:0,successSum:0,successCount:0,costSum:0,costCount:0,blendedCostSum:0,blendedTokensSum:0,lowSuccessSessions:0},t.set(e,r)),r.sessions++,n.efficiencyScore!=null&&(r.effSum+=n.efficiencyScore,r.effCount++),n.toolSuccessRate!=null&&(r.successSum+=n.toolSuccessRate,r.successCount++,n.toolSuccessRate<LW&&r.lowSuccessSessions++),n.estimatedCostUsd!=null){r.costSum+=n.estimatedCostUsd,r.costCount++;let e=(n.tokensInput??0)+(n.tokensOutput??0)+(n.tokensThinking??0)+(n.tokensCacheRead??0)+(n.tokensCacheCreation??0);e>0&&(r.blendedCostSum+=n.estimatedCostUsd,r.blendedTokensSum+=e)}}let n=[];for(let[e,r]of t)n.push({model:e,sessions:r.sessions,avgEfficiency:r.effCount>0?r.effSum/r.effCount:null,avgSuccessRate:r.successCount>0?r.successSum/r.successCount:null,avgCost:r.costCount>0?r.costSum/r.costCount:null,costPerMillionTokens:r.blendedTokensSum>0?r.blendedCostSum/r.blendedTokensSum*1e6:null,flagged:r.successCount>0&&r.lowSuccessSessions/r.successCount>RW});return n.sort((e,t)=>t.sessions-e.sessions)}function BW(e){let t=new Map;for(let n of e)if(n.toolBreakdown)for(let[e,r]of Object.entries(n.toolBreakdown))t.set(e,(t.get(e)??0)+r);return Array.from(t.entries()).map(([e,t])=>({tool:e,count:t})).sort((e,t)=>t.count-e.count).slice(0,8)}function VW({data:e}){let t=e.map(e=>({count:e.peak,tooltip:`${e.date.slice(5)}: ${e.peak}`}));return(0,x.jsx)(pV,{data:t,ariaLabel:`Peak concurrent sessions over ${e.length} days`})}var HW=[{key:`all`,label:`All`},{key:`sensitive_file`,label:`Sensitive files`},{key:`destructive_command`,label:`Destructive`},{key:`external_network`,label:`External network`},{key:`file_deletion`,label:`File deletion`}],UW={critical:`danger`,high:`warning`,medium:`info`},WW={sensitive_file:`Sensitive files`,destructive_command:`Destructive`,external_network:`External network`,file_deletion:`File deletion`,other:`Other`};function GW(e){let t=e.map(e=>JSON.stringify(e)).join(`
63
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function AB(e,t){if(e){if(typeof e==`string`)return jB(e,t);var n={}.toString.call(e).slice(8,-1);return n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`?Array.from(e):n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?jB(e,t):void 0}}function jB(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function MB(e,t){var n=e==null?null:typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(n!=null){var r,i,a,o,s=[],c=!0,l=!1;try{if(a=(n=n.call(e)).next,t===0){if(Object(n)!==n)return;c=!1}else for(;!(c=(r=a.call(n)).done)&&(s.push(r.value),s.length!==t);c=!0);}catch(e){l=!0,i=e}finally{try{if(!c&&n.return!=null&&(o=n.return(),Object(o)!==o))return}finally{if(l)throw i}}return s}}function NB(e){if(Array.isArray(e))return e}var PB=()=>(Mk(),null);function FB(e){if(typeof e==`number`)return e;if(typeof e==`string`){var t=parseFloat(e);if(!Number.isNaN(t))return t}return 0}var IB=(0,b.forwardRef)((e,t)=>{var n=(0,b.useRef)(null),r=OB((0,b.useState)({containerWidth:FB(e.style?.width),containerHeight:FB(e.style?.height)}),2),i=r[0],a=r[1],o=(0,b.useCallback)((e,t)=>{a(n=>{var r=Math.round(e),i=Math.round(t);return n.containerWidth===r&&n.containerHeight===i?n:{containerWidth:r,containerHeight:i}})},[]),s=(0,b.useCallback)(e=>{if(typeof t==`function`&&t(e),n.current!=null&&(n.current.disconnect(),n.current=null),e!=null&&typeof ResizeObserver<`u`){var r=e.getBoundingClientRect(),i=r.width,a=r.height;o(i,a);var s=new ResizeObserver(e=>{var t=e[0];if(t!=null){var n=t.contentRect,r=n.width,i=n.height;o(r,i)}});s.observe(e),n.current=s}},[t,o]);return(0,b.useEffect)(()=>()=>{n.current?.disconnect()},[o]),b.createElement(b.Fragment,null,b.createElement(pp,{width:i.containerWidth,height:i.containerHeight}),b.createElement(`div`,DB({ref:s},e)))}),LB=(0,b.forwardRef)((e,t)=>{var n=e.width,r=e.height,i=OB((0,b.useState)({containerWidth:FB(n),containerHeight:FB(r)}),2),a=i[0],o=i[1],s=(0,b.useCallback)((e,t)=>{o(n=>{var r=Math.round(e),i=Math.round(t);return n.containerWidth===r&&n.containerHeight===i?n:{containerWidth:r,containerHeight:i}})},[]),c=(0,b.useCallback)(e=>{if(typeof t==`function`&&t(e),e!=null){var n=e.getBoundingClientRect(),r=n.width,i=n.height;s(r,i)}},[t,s]);return b.createElement(b.Fragment,null,b.createElement(pp,{width:a.containerWidth,height:a.containerHeight}),b.createElement(`div`,DB({ref:c},e)))}),RB=(0,b.forwardRef)((e,t)=>{var n=e.width,r=e.height;return b.createElement(b.Fragment,null,b.createElement(pp,{width:n,height:r}),b.createElement(`div`,DB({ref:t},e)))}),zB=(0,b.forwardRef)((e,t)=>{var n=e.width,r=e.height;return typeof n==`string`||typeof r==`string`?b.createElement(LB,DB({},e,{ref:t})):typeof n==`number`&&typeof r==`number`?b.createElement(RB,DB({},e,{width:n,height:r,ref:t})):b.createElement(b.Fragment,null,b.createElement(pp,{width:n,height:r}),b.createElement(`div`,DB({ref:t},e)))});function BB(e){return e?IB:zB}var VB=(0,b.forwardRef)((e,t)=>{var n=e.children,r=e.className,i=e.height,a=e.onClick,o=e.onContextMenu,s=e.onDoubleClick,c=e.onMouseDown,l=e.onMouseEnter,u=e.onMouseLeave,d=e.onMouseMove,f=e.onMouseUp,p=e.onTouchEnd,m=e.onTouchMove,h=e.onTouchStart,g=e.style,_=e.width,v=e.responsive,y=e.dispatchTouchEvents,x=y===void 0||y,S=(0,b.useRef)(null),C=Hs(),w=OB((0,b.useState)(null),2),T=w[0],E=w[1],D=OB((0,b.useState)(null),2),O=D[0],k=D[1],A=xB(),j=ep(),M=j?.width>0?j.width:_,N=j?.height>0?j.height:i,ee=(0,b.useCallback)(e=>{A(e),typeof t==`function`&&t(e),E(e),k(e),e!=null&&(S.current=e)},[A,t,E,k]),te=(0,b.useCallback)(e=>{C(mz(e)),C(Iz({handler:a,reactEvent:e}))},[C,a]),P=(0,b.useCallback)(e=>{C(gz(e)),C(Iz({handler:l,reactEvent:e}))},[C,l]),F=(0,b.useCallback)(e=>{C(VE()),C(Iz({handler:u,reactEvent:e}))},[C,u]),ne=(0,b.useCallback)(e=>{C(gz(e)),C(Iz({handler:d,reactEvent:e}))},[C,d]),re=(0,b.useCallback)(()=>{C(kz())},[C]),ie=(0,b.useCallback)(()=>{C(Az())},[C]),ae=(0,b.useCallback)(e=>{C(Oz(e.key))},[C]),oe=(0,b.useCallback)(e=>{C(Iz({handler:o,reactEvent:e}))},[C,o]),I=(0,b.useCallback)(e=>{C(Iz({handler:s,reactEvent:e}))},[C,s]),se=(0,b.useCallback)(e=>{C(Iz({handler:c,reactEvent:e}))},[C,c]),ce=(0,b.useCallback)(e=>{C(Iz({handler:f,reactEvent:e}))},[C,f]),le=(0,b.useCallback)(e=>{C(Iz({handler:h,reactEvent:e}))},[C,h]),ue=(0,b.useCallback)(e=>{x&&C(Hz(e)),C(Iz({handler:m,reactEvent:e}))},[C,x,m]),de=(0,b.useCallback)(e=>{C(Iz({handler:p,reactEvent:e}))},[C,p]),fe=BB(v);return b.createElement(ok.Provider,{value:T},b.createElement(Ja.Provider,{value:O},b.createElement(fe,{width:M??g?.width,height:N??g?.height,className:Ji(`recharts-wrapper`,r),style:CB({position:`relative`,cursor:`default`,width:M,height:N},g),onClick:te,onContextMenu:oe,onDoubleClick:I,onFocus:re,onBlur:ie,onKeyDown:ae,onMouseDown:se,onMouseEnter:P,onMouseLeave:F,onMouseMove:ne,onMouseUp:ce,onTouchEnd:de,onTouchMove:ue,onTouchStart:le,ref:ee},b.createElement(PB,null),n)))}),HB=[`width`,`height`,`responsive`,`children`,`className`,`style`,`compact`,`title`,`desc`];function UB(e,t){if(e==null)return{};var n,r,i=WB(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function WB(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}var GB=(0,b.forwardRef)((e,t)=>{var n=e.width,r=e.height,i=e.responsive,a=e.children,o=e.className,s=e.style,c=e.compact,l=e.title,u=e.desc,d=ea(UB(e,HB));return c?b.createElement(b.Fragment,null,b.createElement(pp,{width:n,height:r}),b.createElement(mB,{otherAttributes:d,title:l,desc:u},a)):b.createElement(VB,{className:o,style:s,width:n,height:r,responsive:i??!1,onClick:e.onClick,onMouseLeave:e.onMouseLeave,onMouseEnter:e.onMouseEnter,onMouseMove:e.onMouseMove,onMouseDown:e.onMouseDown,onMouseUp:e.onMouseUp,onContextMenu:e.onContextMenu,onDoubleClick:e.onDoubleClick,onTouchStart:e.onTouchStart,onTouchMove:e.onTouchMove,onTouchEnd:e.onTouchEnd},b.createElement(mB,{otherAttributes:d,title:l,desc:u,ref:t},b.createElement(MP,null,a)))});function KB(){return KB=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},KB.apply(null,arguments)}function qB(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function JB(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?qB(Object(n),!0).forEach(function(t){YB(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):qB(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function YB(e,t,n){return(t=XB(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function XB(e){var t=ZB(e,`string`);return typeof t==`symbol`?t:t+``}function ZB(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}var QB=JB({accessibilityLayer:!0,barCategoryGap:`10%`,barGap:4,layout:`horizontal`,margin:{top:5,right:5,bottom:5,left:5},responsive:!1,reverseStackOrder:!1,stackOffset:`none`,syncMethod:`index`},Jz),$B=(0,b.forwardRef)(function(e,t){var n=rs(e.categoricalChartProps,QB),r=e.chartName,i=e.defaultTooltipEventType,a=e.validateTooltipEventTypes,o=e.tooltipPayloadSearcher,s=e.categoricalChartProps,c={chartName:r,defaultTooltipEventType:i,validateTooltipEventTypes:a,tooltipPayloadSearcher:o,eventEmitter:void 0};return b.createElement(eB,{preloadedState:{options:c},reduxStoreName:s.id??r},b.createElement(pP,{chartData:s.data}),b.createElement(nB,{layout:n.layout,margin:n.margin}),b.createElement(iB,{throttleDelay:n.throttleDelay,throttledEvents:n.throttledEvents}),b.createElement(rB,{baseValue:n.baseValue,accessibilityLayer:n.accessibilityLayer,barCategoryGap:n.barCategoryGap,maxBarSize:n.maxBarSize,stackOffset:n.stackOffset,barGap:n.barGap,barSize:n.barSize,syncId:n.syncId,syncMethod:n.syncMethod,className:n.className,reverseStackOrder:n.reverseStackOrder}),b.createElement(GB,KB({},n,{ref:t})))}),eV=[`axis`,`item`],tV=(0,b.forwardRef)((e,t)=>b.createElement($B,{chartName:`BarChart`,defaultTooltipEventType:`axis`,validateTooltipEventTypes:eV,tooltipPayloadSearcher:fk,categoricalChartProps:e,ref:t})),nV=[`axis`],rV=(0,b.forwardRef)((e,t)=>b.createElement($B,{chartName:`AreaChart`,defaultTooltipEventType:`axis`,validateTooltipEventTypes:nV,tooltipPayloadSearcher:fk,categoricalChartProps:e,ref:t}));function iV(){return typeof window>`u`||typeof window.matchMedia!=`function`?!1:!window.matchMedia(`(prefers-reduced-motion: reduce)`).matches}function aV(e,t={}){let{duration:n=800,decimals:r=0,enabled:i=!0,format:a}=t,o=i&&iV(),[s,c]=(0,b.useState)(()=>o?0:e),l=(0,b.useRef)(0);return(0,b.useEffect)(()=>{if(!o){c(e);return}let t=performance.now();function r(i){let a=i-t,o=Math.min(a/n,1),s=1-(1-o)**3;c(s*e),o<1&&(l.current=requestAnimationFrame(r))}return l.current=requestAnimationFrame(r),()=>{l.current&&cancelAnimationFrame(l.current)}},[e,n,o]),a?a(s):s.toFixed(r)}var oV={neutral:`text-ink-base`,good:`text-accent-green`,warn:`text-accent-amber`,bad:`text-accent-red`};function sV({label:e,value:t,sub:n,tone:r=`neutral`,hero:i=!1,animate:a=!1,numericValue:o,prefix:s=``,suffix:c=``,decimals:l=0,format:u}){let d=o!=null,f=aV(o??0,{decimals:l,enabled:a&&d,format:u}),p=a&&d?u?f:`${s}${f}${c}`:t,m=i?`text-3xl font-bold mt-1 tabular-nums gradient-text`:`text-3xl font-bold mt-1 tabular-nums ${oV[r]}`;return(0,x.jsxs)(`div`,{className:`px-1`,children:[(0,x.jsx)(`div`,{className:`text-[10px] text-ink-muted uppercase tracking-wider font-medium`,children:e}),(0,x.jsx)(`div`,{className:m,children:p}),n&&(0,x.jsx)(`div`,{className:`text-[10px] text-ink-muted mt-0.5`,children:n})]})}function cV({children:e,index:t=0,className:n=``}){let r=`${t*120}ms`;return(0,x.jsx)(`div`,{className:`animate-card-enter ${n}`,style:{animationDelay:r},children:e})}var lV=`var(--color-chart-block)`,uV=`var(--color-chart-block-peak)`,dV=10,fV=13;function pV({data:e,maxCount:t,ariaLabel:n}){let[r,i]=(0,b.useState)(null);if((0,b.useEffect)(()=>{if(!r)return;let e=()=>i(null);return window.addEventListener(`scroll`,e,{capture:!0}),window.addEventListener(`resize`,e),()=>{window.removeEventListener(`scroll`,e,{capture:!0}),window.removeEventListener(`resize`,e)}},[r]),e.length===0||e.every(e=>e.count===0))return null;let a=Math.max(t??0,...e.map(e=>e.count),1),o=a*12,s=e.length*fV;return(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(`svg`,{width:`100%`,height:o,role:`img`,"aria-label":n,viewBox:`0 0 ${s} ${o}`,preserveAspectRatio:`xMidYMax meet`,onMouseLeave:()=>i(null),children:e.map((e,t)=>{let n=[];for(let r=0;r<e.count;r++){let i=e.isPeak??e.count===a;n.push((0,x.jsx)(`rect`,{x:t*fV,y:o-(r+1)*12,width:dV,height:dV,rx:1,fill:i?uV:lV,className:`heatmap-cell`,style:{animationDelay:`${t*20+r*10}ms`}},`${t}-${r}`))}return(0,x.jsxs)(`g`,{onMouseEnter:t=>{let n=t.currentTarget,r=n.querySelectorAll(`rect.heatmap-cell`),a=(r[r.length-1]??n).getBoundingClientRect();i({x:a.left+a.width/2,y:a.top,text:e.tooltip})},children:[(0,x.jsx)(`rect`,{x:t*fV,y:0,width:fV,height:o,fill:`transparent`}),n]},t)})}),r&&(0,li.createPortal)((0,x.jsx)(`div`,{className:`fixed z-50 px-1.5 py-0.5 bg-bg-elevated border border-border-subtle text-[10px] text-ink-base rounded-md shadow-md pointer-events-none whitespace-nowrap tabular-nums`,style:{left:r.x,top:r.y,transform:`translate(-50%, calc(-100% - 4px))`},children:r.text}),document.body)]})}function mV(){return(0,x.jsxs)(`svg`,{width:`48`,height:`48`,viewBox:`0 0 48 48`,fill:`none`,"aria-hidden":`true`,children:[(0,x.jsx)(`circle`,{cx:`24`,cy:`24`,r:`20`,stroke:`var(--color-ink-muted)`,strokeWidth:`1`,opacity:`0.3`}),(0,x.jsx)(`circle`,{cx:`24`,cy:`24`,r:`13`,stroke:`var(--color-ink-muted)`,strokeWidth:`1`,opacity:`0.3`}),(0,x.jsx)(`circle`,{cx:`24`,cy:`24`,r:`6`,stroke:`var(--color-ink-muted)`,strokeWidth:`1`,opacity:`0.3`}),(0,x.jsx)(`line`,{x1:`24`,y1:`24`,x2:`24`,y2:`4`,stroke:`var(--color-accent-green)`,strokeWidth:`1.5`,strokeLinecap:`round`,className:`animate-radar-sweep`}),(0,x.jsx)(`circle`,{cx:`24`,cy:`24`,r:`2`,fill:`var(--color-accent-green)`})]})}function hV(){return(0,x.jsxs)(`svg`,{width:`48`,height:`48`,viewBox:`0 0 48 48`,fill:`none`,"aria-hidden":`true`,children:[(0,x.jsx)(`path`,{d:`M16 14 L6 24 L16 34`,stroke:`var(--color-ink-muted)`,strokeWidth:`1.5`,strokeLinecap:`round`,strokeLinejoin:`round`}),(0,x.jsx)(`path`,{d:`M32 14 L42 24 L32 34`,stroke:`var(--color-ink-muted)`,strokeWidth:`1.5`,strokeLinecap:`round`,strokeLinejoin:`round`}),(0,x.jsx)(`line`,{x1:`24`,y1:`18`,x2:`24`,y2:`30`,stroke:`var(--color-accent-green)`,strokeWidth:`2`,strokeLinecap:`round`,opacity:`0.8`})]})}function gV(){return(0,x.jsxs)(`svg`,{width:`48`,height:`48`,viewBox:`0 0 48 48`,fill:`none`,"aria-hidden":`true`,children:[(0,x.jsx)(`line`,{x1:`4`,y1:`24`,x2:`44`,y2:`24`,stroke:`var(--color-ink-muted)`,strokeWidth:`1`,opacity:`0.4`}),(0,x.jsx)(`circle`,{cx:`12`,cy:`24`,r:`3`,stroke:`var(--color-ink-muted)`,strokeWidth:`1.5`}),(0,x.jsx)(`circle`,{cx:`24`,cy:`24`,r:`3`,stroke:`var(--color-accent-green)`,strokeWidth:`1.5`}),(0,x.jsx)(`circle`,{cx:`36`,cy:`24`,r:`3`,stroke:`var(--color-ink-muted)`,strokeWidth:`1.5`}),(0,x.jsx)(`line`,{x1:`12`,y1:`16`,x2:`12`,y2:`20`,stroke:`var(--color-ink-muted)`,strokeWidth:`1`,strokeLinecap:`round`,opacity:`0.5`}),(0,x.jsx)(`line`,{x1:`24`,y1:`16`,x2:`24`,y2:`20`,stroke:`var(--color-accent-green)`,strokeWidth:`1`,strokeLinecap:`round`,opacity:`0.7`}),(0,x.jsx)(`line`,{x1:`36`,y1:`16`,x2:`36`,y2:`20`,stroke:`var(--color-ink-muted)`,strokeWidth:`1`,strokeLinecap:`round`,opacity:`0.5`})]})}function _V(){return(0,x.jsxs)(`svg`,{width:`48`,height:`48`,viewBox:`0 0 48 48`,fill:`none`,"aria-hidden":`true`,children:[(0,x.jsx)(`circle`,{cx:`24`,cy:`24`,r:`18`,stroke:`var(--color-ink-muted)`,strokeWidth:`1`,opacity:`0.3`}),(0,x.jsx)(`path`,{d:`M16 24 L22 30 L34 18`,stroke:`var(--color-accent-green)`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})]})}function vV(){return(0,x.jsxs)(`svg`,{width:`48`,height:`48`,viewBox:`0 0 48 48`,fill:`none`,"aria-hidden":`true`,children:[(0,x.jsx)(`circle`,{cx:`24`,cy:`24`,r:`18`,stroke:`var(--color-ink-muted)`,strokeWidth:`1`,opacity:`0.3`}),(0,x.jsx)(`path`,{d:`M24 14 L24 24 L31 28`,stroke:`var(--color-ink-subtle)`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})]})}var yV={radar:mV,code:hV,timeline:gV,checkmark:_V,clock:vV};function bV(){return(0,x.jsx)(`div`,{className:`flex items-center justify-center`,style:{width:48,height:48},"aria-hidden":`true`,children:(0,x.jsx)(`span`,{className:`rounded-full animate-pulse`,style:{width:10,height:10,backgroundColor:`var(--color-accent-green)`,boxShadow:`0 0 0 4px color-mix(in srgb, var(--color-accent-green) 15%, transparent)`}})})}function $({icon:e,title:t,subtitle:n,variant:r=`empty`}){let i=e===void 0?void 0:yV[e];return(0,x.jsxs)(`div`,{className:`py-8 flex flex-col items-center justify-center gap-3`,children:[r===`loading`?(0,x.jsx)(bV,{}):i&&(0,x.jsx)(i,{}),(0,x.jsx)(`span`,{className:`text-sm font-medium text-ink-subtle`,children:t}),n&&(0,x.jsx)(`span`,{className:`text-xs text-ink-muted text-center max-w-[240px]`,children:n})]})}function xV(e){return e===`Read`?`bg-accent-blue`:e===`Edit`||e===`Write`?`bg-accent-green`:e===`Bash`?`bg-accent-purple`:e===`Agent`?`bg-accent-teal`:`bg-ink-subtle`}var SV={thrashing:`Edit/Test Thrashing`,stuck_loop:`Stuck Loop`,blind_editing:`Blind Editing`,re_reading:`Repeated Reads`};function CV(e){let t=Math.floor(e/1e3),n=Math.floor(t/60),r=t%60;return`${n}:${String(r).padStart(2,`0`)}`}function wV({entries:e,segments:t,windowStartMs:n,windowEndMs:r,showTicks:i=!0,gutterClass:a=`w-24`}){let[o,s]=(0,b.useState)(null),c=(0,b.useMemo)(()=>e.map((e,t)=>({entry:e,originalIdx:t})).sort((e,t)=>e.entry.timestamp-t.entry.timestamp),[e]),l=(0,b.useMemo)(()=>{let n=new Map;for(let e=0;e<c.length;e++)n.set(c[e].originalIdx,e);let r=Array(c.length).fill(null);for(let i of t){let t=Math.max(0,i.startIndex),a=Math.min(i.endIndex,e.length-1);for(let e=t;e<=a;e++){let t=n.get(e);t!==void 0&&(r[t]===null||i.severity===`critical`&&r[t].severity!==`critical`)&&(r[t]=i)}}return r},[c,t,e.length]);if(e.length===0)return(0,x.jsx)(`div`,{className:`text-ink-muted text-xs`,children:`No tool calls recorded.`});let u=n!==void 0&&r!==void 0,d=u?n:c[0].entry.timestamp,f=c.reduce((e,{entry:t})=>Math.max(e,t.timestamp+(t.durationMs??50)),0),p=Math.max(u?r-n:f-d,1),m=[1e4,3e4,6e4,12e4,3e5,6e5,9e5,18e5].find(e=>p/e<=8)??Math.ceil(p/8),h=[];for(let e=m;e<p;e+=m)h.push(e);let g=Math.min(30,800/Math.max(e.length,1));return(0,x.jsxs)(`div`,{className:`p-2 overflow-x-hidden`,children:[i&&(0,x.jsxs)(`div`,{className:`flex`,children:[(0,x.jsx)(`div`,{className:`${a} shrink-0`}),(0,x.jsx)(`div`,{className:`relative flex-1 h-5 border-b border-bg-line overflow-x-auto`,children:h.map(e=>{let t=e/p*100;return(0,x.jsx)(`span`,{className:`absolute top-0 text-[9px] text-ink-muted tabular-nums -translate-x-1/2`,style:{left:`${t}%`},children:CV(e)},e)})})]}),(0,x.jsx)(`div`,{className:i?`mt-1`:``,children:c.map(({entry:e,originalIdx:t},n)=>{let r=e.timestamp-d,i=e.durationMs??50,u=r/p*100,f=i/p*100,m=l[n],h=m?m.severity===`critical`?`border-l-2 border-l-accent-red`:`border-l-2 border-l-accent-amber`:`border-l-2 border-l-transparent`;return(0,x.jsxs)(`div`,{className:`flex items-center h-7 ${h}`,children:[(0,x.jsx)(`div`,{className:`${a} shrink-0 truncate text-[11px] text-ink-subtle pr-2 text-right`,title:e.toolName,children:Ei(e.toolName)}),(0,x.jsxs)(`div`,{className:`relative flex-1 h-full flex items-center`,children:[(0,x.jsx)(`div`,{role:`img`,"aria-label":`${e.toolName} · ${e.durationMs==null?`unknown`:`${e.durationMs}ms`} · ${e.success?`success`:`failed`}`,className:`gantt-bar absolute h-5 rounded-sm opacity-80 ${xV(Ei(e.toolName))} ${e.success?``:`ring-1 ring-accent-red/60`}`,style:{left:`${u}%`,width:`${f}%`,minWidth:`4px`,animationDelay:`${Math.round(n*g)}ms`},onMouseEnter:()=>s(n),onMouseLeave:()=>s(null)}),o===n&&(0,x.jsxs)(`div`,{className:`absolute z-50 px-2 py-1.5 rounded-lg bg-bg-elevated border border-bg-line text-[11px] text-ink-base shadow-lg whitespace-nowrap pointer-events-none ${n>=3&&n>c.length-4?`bottom-full mb-1`:`top-full mt-1`}`,style:u>=50?{right:`${Math.max(0,100-u-f)}%`}:{left:`${u}%`},children:[(0,x.jsx)(`div`,{className:`font-medium`,children:e.toolName}),(e.filePath??e.command)&&(0,x.jsx)(`div`,{className:`text-ink-subtle truncate max-w-[200px]`,children:e.filePath??e.command}),(0,x.jsxs)(`div`,{className:`text-ink-muted`,children:[e.durationMs==null?`unknown`:`${e.durationMs}ms`,` ·`,` `,e.success?`success`:`failed`]}),m&&(0,x.jsx)(`div`,{className:`mt-0.5 font-medium ${m.severity===`critical`?`text-accent-red`:`text-accent-amber`}`,children:SV[m.type]??m.type})]})]})]},`${t}-${e.timestamp}`)})})]})}function TV(e){let t=new Map;for(let n of e){let e=n.workflowRunId,r=t.get(e);r?r.push(n):t.set(e,[n])}let n=[];for(let[e,r]of t){let t=[...r].sort((e,t)=>e.startMs-t.startMs),i=t.reduce((e,t)=>Math.min(e,t.startMs),1/0),a=e===null?`Ad-hoc subagents`:r[0]?.workflowName??`Workflow run`;n.push({runId:e,name:a,earliestStartMs:i,agents:t})}return n.sort((e,t)=>e.earliestStartMs-t.earliestStartMs),n}var EV=[`bg-series-1`,`bg-series-2`,`bg-series-3`,`bg-series-4`,`bg-series-5`,`bg-series-6`],DV=`__parent__`,OV=`__adhoc__`;function kV(e){return e===null?OV:`run:${e}`}function AV(e){let t=Math.floor(e/1e3),n=Math.floor(t/60),r=t%60;return`${n}:${String(r).padStart(2,`0`)}`}var jV=15,MV=`w-44`;function NV({status:e}){return e===`completed`?(0,x.jsx)(_n,{size:12,className:`shrink-0 text-accent-green`,"aria-label":`completed`,role:`img`}):e===`failed`?(0,x.jsx)(vn,{size:12,className:`shrink-0 text-accent-red`,"aria-label":`failed`,role:`img`}):e===`running`?(0,x.jsx)(wn,{size:12,className:`shrink-0 text-accent-cyan animate-spin`,"aria-label":`running`,role:`img`}):e===`cancelled`?(0,x.jsx)(yn,{size:12,className:`shrink-0 text-accent-amber`,"aria-label":`cancelled`,role:`img`}):null}function PV({sessionId:e,parentEntries:t,agents:n,window:r,onSelectRun:i,runStatusById:a,parentSegments:o}){let[s,c]=(0,b.useState)(`gantt`),l=(0,b.useMemo)(()=>TV(n),[n]),u=(0,b.useMemo)(()=>{let e=[];t.length>0&&e.push(DV);for(let t of l)e.push(kV(t.runId));return e},[l,t.length]),d=(0,b.useMemo)(()=>n.map(e=>e.agentId),[n]),[f,p]=(0,b.useState)(()=>{let e=new Set;for(let t of l)t.agents.length>jV&&e.add(kV(t.runId));return e}),[m,h]=(0,b.useState)(()=>new Set),g=e=>{p(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},_=e=>{h(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},v=e=>{e===`collapsed`?(p(new Set(u)),h(new Set)):e===`agents`?(p(t.length>0?new Set([DV]):new Set),h(new Set)):(p(new Set),h(new Set(d)))},y=(0,b.useMemo)(()=>{let e=t.length>0,n=u.filter(e=>e!==DV),r=!e||f.has(`__parent__`),i=f.size===0,a=u.length>0&&u.every(e=>f.has(e)),o=n.every(e=>!f.has(e)),s=m.size===0,c=d.length>0?d.every(e=>m.has(e)):m.size===0;return a&&s?`collapsed`:i&&c?`expanded`:r&&o&&s?`agents`:null},[f,m,u,d,t.length]),S=t.length,C=(0,b.useMemo)(()=>[...t],[t]);return t.length===0&&n.length===0?(0,x.jsx)(`div`,{className:`text-ink-muted text-xs`,children:`No activity recorded.`}):(0,x.jsxs)(`div`,{children:[(0,x.jsxs)(`div`,{className:`flex items-center justify-between gap-2 mb-2`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,x.jsx)(si,{value:s,onChange:c,options:[{value:`gantt`,label:`Gantt`},{value:`list`,label:`List`}],size:`sm`,tone:`green`,ariaLabel:`Session trace view mode`}),(0,x.jsx)(`div`,{className:`h-4 w-px bg-border-subtle`,"aria-hidden":`true`}),(0,x.jsx)(FV,{active:y,onSelect:v})]}),(0,x.jsxs)(`span`,{className:`text-[10px] uppercase tracking-wider text-ink-muted tabular-nums`,children:[S,` parent call`,S===1?``:`s`,` · `,n.length,` agent`,n.length===1?``:`s`]})]}),s===`gantt`?(0,x.jsx)(LV,{parentRows:C,groups:l,window:r,sessionId:e,onSelectRun:i,runStatusById:a,parentSegments:o,collapsedGroups:f,toggleGroup:g,expandedAgents:m,toggleAgent:_}):(0,x.jsx)(VV,{parentRows:C,groups:l,window:r,sessionId:e,onSelectRun:i,runStatusById:a,collapsedGroups:f,toggleGroup:g,expandedAgents:m,toggleAgent:_})]})}function FV({active:e,onSelect:t}){return(0,x.jsx)(`div`,{role:`group`,"aria-label":`Trace expand level`,className:`inline-flex items-center gap-1`,children:[{value:`collapsed`,label:`Collapsed`},{value:`agents`,label:`Agents`},{value:`expanded`,label:`Expand all`}].map(n=>{let r=e===n.value;return(0,x.jsx)(`button`,{type:`button`,"aria-pressed":r,onClick:()=>t(n.value),className:`px-2 py-0.5 text-[10px] rounded-md transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-cyan/40 `+(r?`bg-accent-cyan/20 text-accent-cyan font-medium`:`text-ink-muted hover:text-ink-subtle`),children:n.label},n.value)})})}function IV({window:e}){let t=Math.max(e.endMs-e.startMs,1),n=(0,b.useMemo)(()=>{let e=[1e4,3e4,6e4,12e4,3e5,6e5,9e5,18e5].find(e=>t/e<=8)??Math.ceil(t/8),n=[];for(let r=e;r<t;r+=e)n.push(r);return n},[t]);return(0,x.jsxs)(`div`,{className:`flex px-2`,children:[(0,x.jsx)(`div`,{className:`${MV} shrink-0`}),(0,x.jsx)(`div`,{className:`relative flex-1 h-5 border-b border-bg-line overflow-x-auto`,children:n.map(e=>{let n=e/t*100;return(0,x.jsx)(`span`,{className:`absolute top-0 text-[9px] text-ink-muted tabular-nums -translate-x-1/2`,style:{left:`${n}%`},children:AV(e)},e)})})]})}function LV({parentRows:e,groups:t,window:n,sessionId:r,onSelectRun:i,runStatusById:a,parentSegments:o,collapsedGroups:s,toggleGroup:c,expandedAgents:l,toggleAgent:u}){let d=s.has(DV),f=e.length>0;return(0,x.jsxs)(`div`,{className:`overflow-x-hidden`,children:[(0,x.jsx)(IV,{window:n}),f&&(0,x.jsxs)(`div`,{className:`mb-2 mt-1`,children:[(0,x.jsx)(KV,{collapsed:d,onToggle:()=>c(`__parent__`),label:`Parent`,count:`${e.length} tool call${e.length===1?``:`s`}`}),!d&&(0,x.jsx)(wV,{entries:e,segments:o?[...o]:[],windowStartMs:n.startMs,windowEndMs:n.endMs,showTicks:!1,gutterClass:MV})]}),t.map((e,t)=>{let o=EV[t%EV.length],d=kV(e.runId),f=s.has(d),p=e.runId===null?void 0:a?.[e.runId],m=e.runId!==null&&i?()=>i(e.runId):void 0,h=e.agents.map(e=>e.usd).filter(e=>e!=null),g=h.length>0?h.reduce((e,t)=>e+t,0):null,_=e.agents.reduce((e,t)=>Math.max(e,t.endMs),0),v=_-e.earliestStartMs,y=`${e.agents.length} agent${e.agents.length===1?``:`s`} · ${wi(g)} · ${AV(Math.max(0,v))} span`;return(0,x.jsx)(`div`,{className:`mb-2`,children:f?(0,x.jsx)(RV,{onToggle:()=>c(d),label:e.name,summary:y,barColor:o,window:n,startMs:e.earliestStartMs,endMs:_,status:p,onOpenRun:m}):(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(KV,{collapsed:!1,onToggle:()=>c(d),label:e.name,swatchColor:o,count:`${e.agents.length} agent${e.agents.length===1?``:`s`}`,status:p,onOpenRun:m}),e.agents.map(e=>(0,x.jsx)(zV,{agent:e,barColor:o,window:n,sessionId:r,onSelectRun:i,expanded:l.has(e.agentId),onToggle:()=>u(e.agentId)},e.agentId))]})},e.runId??`__adhoc__`)})]})}function RV({onToggle:e,label:t,summary:n,barColor:r,window:i,startMs:a,endMs:o,status:s,onOpenRun:c}){let l=Math.max(i.endMs-i.startMs,1),u=a-i.startMs,d=Math.max(0,u/l*100),f=Math.max(0,o-a)/l*100,p=`${t} · ${n}`,m=s===`failed`,h=`absolute inset-y-0 my-auto h-4 rounded-sm opacity-85 ${r}`+(m?` ring-1 ring-accent-red/60`:``);return(0,x.jsxs)(`div`,{className:`flex items-center h-7 px-2`,children:[(0,x.jsxs)(`div`,{className:`${MV} shrink-0 flex items-center gap-1.5 pr-2`,children:[(0,x.jsxs)(`button`,{type:`button`,onClick:e,"aria-expanded":!1,className:`shrink-0 flex items-center gap-1.5 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-cyan/40 rounded-sm`,title:n,children:[(0,x.jsx)(gn,{size:13,className:`shrink-0 text-ink-muted`,"aria-hidden":`true`}),(0,x.jsx)(`span`,{className:`inline-block w-2 h-2 rounded-sm shrink-0 ${r}`,"aria-hidden":`true`})]}),c?(0,x.jsx)(`span`,{role:`button`,tabIndex:0,title:`${t} · open run`,onClick:e=>{e.stopPropagation(),c()},onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),e.stopPropagation(),c())},className:`text-[11px] font-medium text-ink-subtle truncate cursor-pointer hover:text-accent-cyan hover:underline underline-offset-2 rounded-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-cyan/40`,children:t}):(0,x.jsx)(`span`,{className:`text-[11px] font-medium text-ink-subtle truncate`,title:t,children:t}),(0,x.jsx)(NV,{status:s})]}),(0,x.jsx)(`div`,{className:`relative flex-1 h-full flex items-center`,children:(0,x.jsx)(`div`,{role:`img`,"aria-label":p,title:p,className:h,style:{left:`${d}%`,width:`${f}%`,minWidth:`4px`}})})]})}function zV({agent:e,barColor:t,window:n,sessionId:r,onSelectRun:i,expanded:a,onToggle:o}){let[s,c]=(0,b.useState)(!1),l=Math.max(n.endMs-n.startMs,1),u=e.startMs-n.startMs,d=Math.max(0,u/l*100),f=e.durationMs/l*100,p=e.workflowRunId!==null&&i!==void 0,m=e.workflowRunId,h=d>=50?{right:`${Math.max(0,100-d-f)}%`}:{left:`${d}%`},g=`${e.label} · ${e.model} · ${e.turnCount} turns · ${Ti(e.totalTokens)} tokens · ${wi(e.usd)} · ${xi(e.durationMs)}`+(p?` · open workflow run`:``),_=`absolute inset-y-0 my-auto h-5 rounded-sm opacity-85 ${t} `+(p?`cursor-pointer hover:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-cyan/40`:`cursor-default`);return(0,x.jsxs)(`div`,{children:[(0,x.jsxs)(`div`,{className:`flex items-center h-7 px-2`,children:[(0,x.jsxs)(`div`,{className:`${MV} shrink-0 flex items-center gap-1 pl-4 pr-2`,children:[(0,x.jsx)(`button`,{type:`button`,onClick:o,"aria-expanded":a,"aria-label":`${a?`Collapse`:`Expand`} calls for ${e.label}`,className:`shrink-0 rounded-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-cyan/40`,children:a?(0,x.jsx)(hn,{size:11,className:`text-ink-muted`,"aria-hidden":`true`}):(0,x.jsx)(gn,{size:11,className:`text-ink-muted`,"aria-hidden":`true`})}),(0,x.jsx)(`span`,{className:`truncate text-[11px] text-ink-subtle`,title:e.label,children:e.label})]}),(0,x.jsxs)(`div`,{className:`relative flex-1 h-full flex items-center`,children:[p?(0,x.jsx)(`button`,{type:`button`,"aria-label":g,className:_,style:{left:`${d}%`,width:`${f}%`,minWidth:`4px`},onClick:()=>i(m),onMouseEnter:()=>c(!0),onMouseLeave:()=>c(!1),onFocus:()=>c(!0),onBlur:()=>c(!1)}):(0,x.jsx)(`div`,{role:`img`,"aria-label":g,className:_,style:{left:`${d}%`,width:`${f}%`,minWidth:`4px`},onMouseEnter:()=>c(!0),onMouseLeave:()=>c(!1)}),s&&(0,x.jsxs)(`div`,{className:`absolute z-50 top-full mt-1 px-2 py-1.5 rounded-lg bg-bg-elevated border border-bg-line text-[11px] text-ink-base shadow-lg whitespace-nowrap pointer-events-none`,style:h,children:[(0,x.jsx)(`div`,{className:`font-medium`,children:e.label}),(0,x.jsx)(`div`,{className:`text-ink-subtle font-mono`,children:e.model}),(0,x.jsxs)(`div`,{className:`text-ink-muted`,children:[e.turnCount,` turn`,e.turnCount===1?``:`s`,` ·`,` `,Ti(e.totalTokens),` tokens`]}),(0,x.jsxs)(`div`,{className:`text-ink-muted`,children:[wi(e.usd),` · `,xi(e.durationMs)]})]})]})]}),a&&(0,x.jsx)(BV,{agentId:e.agentId,sessionId:r,window:n})]})}function BV({agentId:e,sessionId:t,window:n}){let{data:r,isLoading:i,isError:a}=L({queryKey:z.agentCalls(t,e),queryFn:()=>Sr(t,e),retry:!1});if(i)return(0,x.jsx)(`div`,{className:`pl-6 py-1 text-[10px] text-ink-muted`,children:`Loading calls…`});if(a)return(0,x.jsx)(`div`,{className:`pl-6 py-1 text-[10px] text-accent-red`,children:`Failed to load calls.`});let o=r?.calls??[];return o.length===0?(0,x.jsx)(`div`,{className:`pl-6 py-1 text-[10px] text-ink-muted`,children:`No calls recorded.`}):(0,x.jsx)(`div`,{className:`pl-3 border-l border-bg-line ml-3`,children:(0,x.jsx)(wV,{entries:[...o],segments:[],windowStartMs:n.startMs,windowEndMs:n.endMs,showTicks:!1,gutterClass:MV})})}function VV({parentRows:e,groups:t,window:n,sessionId:r,onSelectRun:i,runStatusById:a,collapsedGroups:o,toggleGroup:s,expandedAgents:c,toggleAgent:l}){let u=n.startMs,d=o.has(DV),f=(0,b.useMemo)(()=>{let t=1/0,n=0;for(let r of e){r.timestamp<t&&(t=r.timestamp);let e=r.timestamp+(r.durationMs??50);e>n&&(n=e)}return Number.isFinite(t)?Math.max(0,n-t):0},[e]);return(0,x.jsxs)(`div`,{className:`text-[11px]`,children:[e.length>0&&(0,x.jsxs)(`div`,{className:`mb-3`,children:[(0,x.jsx)(KV,{collapsed:d,onToggle:()=>s(`__parent__`),label:`Parent`,count:`${e.length} tool call${e.length===1?``:`s`}`,trailing:(0,x.jsx)(GV,{durationMs:f})}),!d&&(0,x.jsx)(`div`,{className:`flex flex-col`,children:[...e].sort((e,t)=>e.timestamp-t.timestamp).map((e,t)=>(0,x.jsx)(HV,{entry:e,firstTs:u,detail:e.filePath??e.command??``},`${t}-${e.timestamp}`))})]}),t.map((e,t)=>{let u=EV[t%EV.length],d=kV(e.runId),f=o.has(d),p=e.runId===null?void 0:a?.[e.runId],m=e.runId!==null&&i?()=>i(e.runId):void 0,h=e.agents.reduce((e,t)=>e+t.turnCount,0),g=e.agents.reduce((e,t)=>e+t.totalTokens,0),_=e.agents.map(e=>e.usd).filter(e=>e!=null),v=_.length>0?_.reduce((e,t)=>e+t,0):null,y=Math.max(0,e.agents.reduce((e,t)=>Math.max(e,t.endMs),0)-e.earliestStartMs);return(0,x.jsxs)(`div`,{className:`mb-3`,children:[(0,x.jsx)(KV,{collapsed:f,onToggle:()=>s(d),label:e.name,swatchColor:u,count:`${e.agents.length} agent${e.agents.length===1?``:`s`}`,status:p,onOpenRun:m,trailing:(0,x.jsx)(GV,{turns:h,tokens:g,usd:v,durationMs:y})}),!f&&(0,x.jsx)(`div`,{className:`flex flex-col gap-0.5`,children:e.agents.map(e=>(0,x.jsx)(UV,{agent:e,window:n,sessionId:r,onSelectRun:i,expanded:c.has(e.agentId),onToggle:()=>l(e.agentId)},e.agentId))})]},e.runId??`__adhoc__`)})]})}function HV({entry:e,firstTs:t,detail:n}){let r=Math.max(0,e.timestamp-t);return(0,x.jsxs)(`div`,{className:`flex items-center gap-1.5 px-2 py-0.5`,children:[(0,x.jsxs)(`span`,{className:`w-10 text-ink-muted tabular-nums shrink-0`,children:[`+`,bi(r)]}),(0,x.jsx)(`span`,{className:`w-28 truncate font-medium text-ink-base shrink-0`,title:e.toolName,children:Ei(e.toolName)}),(0,x.jsx)(`span`,{className:`flex-1 truncate font-mono text-ink-subtle min-w-0`,title:n??``,children:n??``}),(0,x.jsx)(`span`,{className:`w-14 text-right tabular-nums text-ink-muted shrink-0`,children:e.durationMs==null?`—`:`${e.durationMs}ms`}),(0,x.jsx)(`span`,{className:`w-3 text-center shrink-0 ${e.success?`text-accent-green`:`text-accent-red`}`,"aria-label":e.success?`success`:`failed`,children:e.success?`✓`:`✗`})]})}function UV({agent:e,window:t,sessionId:n,onSelectRun:r,expanded:i,onToggle:a}){let o=e.workflowRunId!==null&&r!==void 0,s=e.workflowRunId;return(0,x.jsxs)(`div`,{children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-1.5 px-2 py-0.5`,children:[(0,x.jsx)(`button`,{type:`button`,onClick:a,"aria-expanded":i,"aria-label":`${i?`Collapse`:`Expand`} calls for ${e.label}`,className:`shrink-0 rounded-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-cyan/40`,children:i?(0,x.jsx)(hn,{size:11,className:`text-ink-muted`,"aria-hidden":`true`}):(0,x.jsx)(gn,{size:11,className:`text-ink-muted`,"aria-hidden":`true`})}),o?(0,x.jsx)(`button`,{type:`button`,onClick:()=>r(s),className:`truncate font-medium text-accent-cyan hover:underline text-left shrink-0 max-w-[160px] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-cyan/40 rounded-sm`,title:`${e.label} · open workflow run`,children:e.label}):(0,x.jsx)(`span`,{className:`truncate font-medium text-ink-base shrink-0 max-w-[160px]`,title:e.label,children:e.label}),(0,x.jsx)(`span`,{className:`font-mono text-ink-muted truncate min-w-0 flex-1`,title:e.model,children:e.model}),(0,x.jsxs)(`span`,{className:`text-ink-muted tabular-nums shrink-0`,children:[e.turnCount,` turn`,e.turnCount===1?``:`s`]}),(0,x.jsxs)(`span`,{className:`text-ink-muted tabular-nums shrink-0`,children:[Ti(e.totalTokens),` tok`]}),(0,x.jsx)(`span`,{className:`text-accent-amber tabular-nums shrink-0 w-12 text-right`,children:wi(e.usd)}),(0,x.jsx)(`span`,{className:`text-ink-muted tabular-nums shrink-0 w-12 text-right`,children:xi(e.durationMs)})]}),i&&(0,x.jsx)(WV,{agentId:e.agentId,sessionId:n,firstTs:t.startMs})]})}function WV({agentId:e,sessionId:t,firstTs:n}){let{data:r,isLoading:i,isError:a}=L({queryKey:z.agentCalls(t,e),queryFn:()=>Sr(t,e),retry:!1});if(i)return(0,x.jsx)(`div`,{className:`pl-9 py-1 text-[10px] text-ink-muted`,children:`Loading calls…`});if(a)return(0,x.jsx)(`div`,{className:`pl-9 py-1 text-[10px] text-accent-red`,children:`Failed to load calls.`});let o=r?.calls??[];return o.length===0?(0,x.jsx)(`div`,{className:`pl-9 py-1 text-[10px] text-ink-muted`,children:`No calls recorded.`}):(0,x.jsx)(`div`,{className:`pl-6 border-l border-bg-line ml-3 flex flex-col`,children:[...o].sort((e,t)=>e.timestamp-t.timestamp).map((e,t)=>(0,x.jsx)(HV,{entry:e,firstTs:n},`${t}-${e.timestamp}`))})}function GV({turns:e,tokens:t,usd:n,durationMs:r}){return(0,x.jsxs)(`span`,{className:`ml-auto flex items-center gap-2 text-[10px] tabular-nums shrink-0 pl-2`,children:[e!=null&&(0,x.jsxs)(`span`,{className:`text-ink-muted`,children:[e,` turn`,e===1?``:`s`]}),t!=null&&(0,x.jsxs)(`span`,{className:`text-ink-muted`,children:[Ti(t),` tok`]}),n!=null&&(0,x.jsx)(`span`,{className:`text-accent-amber`,children:Ci(n)}),r!=null&&(0,x.jsx)(`span`,{className:`text-ink-muted`,children:xi(r)})]})}function KV({collapsed:e,onToggle:t,label:n,count:r,swatchColor:i,status:a,trailing:o,onOpenRun:s}){return(0,x.jsxs)(`div`,{className:`flex w-full items-center gap-1.5 mb-0.5 px-2 text-left`,children:[(0,x.jsxs)(`button`,{type:`button`,onClick:t,"aria-expanded":!e,className:`flex items-center gap-1.5 shrink-0 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-cyan/40 rounded-sm`,children:[e?(0,x.jsx)(gn,{size:13,className:`shrink-0 text-ink-muted`,"aria-hidden":`true`}):(0,x.jsx)(hn,{size:13,className:`shrink-0 text-ink-muted`,"aria-hidden":`true`}),i!=null&&(0,x.jsx)(`span`,{className:`inline-block w-2 h-2 rounded-sm shrink-0 ${i}`,"aria-hidden":`true`})]}),s?(0,x.jsx)(`span`,{role:`button`,tabIndex:0,title:`${n} · open run`,onClick:e=>{e.stopPropagation(),s()},onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),e.stopPropagation(),s())},className:`text-[11px] font-medium text-ink-subtle truncate min-w-0 cursor-pointer hover:text-accent-cyan hover:underline underline-offset-2 rounded-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-cyan/40`,children:n}):(0,x.jsx)(`span`,{className:`text-[11px] font-medium text-ink-subtle truncate min-w-0`,title:n,children:n}),(0,x.jsx)(`span`,{className:`text-[10px] text-ink-muted tabular-nums truncate shrink-0`,children:r}),(0,x.jsx)(NV,{status:a}),o]})}function qV(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function JV(e,t=16){return e.length<=t?e:`${e.slice(0,6)}…${e.slice(-6)}`}function YV({column:e,sortKey:t,sortDir:n}){return e===t?n===`asc`?(0,x.jsx)(pn,{className:`w-3 h-3 text-accent-amber`,"aria-hidden":`true`}):(0,x.jsx)(dn,{className:`w-3 h-3 text-accent-amber`,"aria-hidden":`true`}):(0,x.jsx)(fn,{className:`w-3 h-3 opacity-30`,"aria-hidden":`true`})}function XV({column:e,label:t,sortKey:n,sortDir:r,onSort:i,className:a=``}){return(0,x.jsx)(`th`,{scope:`col`,"aria-sort":e===n?r===`asc`?`ascending`:`descending`:`none`,className:`px-3 py-2 text-left text-[10px] uppercase tracking-wider text-ink-muted font-semibold whitespace-nowrap select-none ${a}`,children:(0,x.jsxs)(`button`,{type:`button`,onClick:()=>i(e),className:`inline-flex items-center gap-1 cursor-pointer hover:text-ink-subtle transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-cyan/40 rounded-sm`,children:[t,(0,x.jsx)(YV,{column:e,sortKey:n,sortDir:r})]})})}function ZV({agents:e}){let[t,n]=(0,b.useState)(`tokens`),[r,i]=(0,b.useState)(`desc`),[a,o]=(0,b.useState)(null);function s(e){e===t?i(e=>e===`asc`?`desc`:`asc`):(n(e),i(`desc`))}async function c(e){try{await navigator.clipboard.writeText(e),o(e),setTimeout(()=>o(null),1500)}catch{}}let l=[...e].sort((e,n)=>{let i=e[t]??-1/0,a=n[t]??-1/0;if(typeof i==`string`&&typeof a==`string`)return r===`asc`?i.localeCompare(a):a.localeCompare(i);let o=i,s=a;return r===`asc`?o-s:s-o});return e.length===0?(0,x.jsx)(`div`,{className:`py-6 text-center text-xs text-ink-muted`,children:`No agent data recorded for this run.`}):(0,x.jsx)(`div`,{className:`overflow-x-auto rounded-lg border border-border-subtle`,children:(0,x.jsxs)(`table`,{className:`w-full text-xs`,"aria-label":`Agent activity`,children:[(0,x.jsx)(`thead`,{className:`bg-surface-5 border-b border-border-subtle`,children:(0,x.jsxs)(`tr`,{children:[(0,x.jsx)(XV,{column:`label`,label:`Agent`,sortKey:t,sortDir:r,onSort:s}),(0,x.jsx)(XV,{column:`model`,label:`Model`,sortKey:t,sortDir:r,onSort:s}),(0,x.jsx)(XV,{column:`state`,label:`State`,sortKey:t,sortDir:r,onSort:s}),(0,x.jsx)(XV,{column:`tokens`,label:`Tokens`,sortKey:t,sortDir:r,onSort:s,className:`text-right`}),(0,x.jsx)(XV,{column:`toolCalls`,label:`Tool Calls`,sortKey:t,sortDir:r,onSort:s,className:`text-right`}),(0,x.jsx)(XV,{column:`durationMs`,label:`Duration`,sortKey:t,sortDir:r,onSort:s,className:`text-right`})]})}),(0,x.jsx)(`tbody`,{className:`divide-y divide-border-subtle`,children:l.map(e=>(0,x.jsxs)(`tr`,{className:`hover:bg-surface-5 transition-colors`,children:[(0,x.jsx)(`td`,{className:`px-3 py-2 min-w-0`,children:(0,x.jsxs)(`div`,{className:`flex flex-col gap-0.5 min-w-0`,children:[(0,x.jsx)(`button`,{type:`button`,title:e.agentId,"aria-label":`Copy agent ID ${e.agentId}`,onClick:()=>void c(e.agentId),className:`text-left text-ink-base font-medium truncate hover:text-accent-cyan transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-cyan/40 rounded`,children:a===e.agentId?(0,x.jsx)(`span`,{className:`text-accent-green`,children:`Copied!`}):e.label||JV(e.agentId)}),e.phaseTitle&&(0,x.jsxs)(`span`,{className:`text-[10px] text-ink-muted truncate`,children:[e.phaseTitle,e.attempt>1?` · attempt ${e.attempt}`:``]})]})}),(0,x.jsx)(`td`,{className:`px-3 py-2`,children:(0,x.jsx)(`span`,{className:`inline-flex items-center px-1.5 py-0.5 rounded text-[10px] bg-surface-5 text-ink-subtle font-mono`,children:e.model||`—`})}),(0,x.jsx)(`td`,{className:`px-3 py-2`,children:(0,x.jsx)(`span`,{className:`text-ink-subtle`,children:e.state||`—`})}),(0,x.jsx)(`td`,{className:`px-3 py-2 text-right tabular-nums text-ink-base font-medium`,children:e.tokens>0?qV(e.tokens):(0,x.jsx)(`span`,{className:`text-ink-muted opacity-40`,children:`—`})}),(0,x.jsx)(`td`,{className:`px-3 py-2 text-right tabular-nums text-ink-muted`,children:e.toolCalls>0?e.toolCalls.toLocaleString():(0,x.jsx)(`span`,{className:`text-ink-muted opacity-40`,children:`—`})}),(0,x.jsx)(`td`,{className:`px-3 py-2 text-right tabular-nums text-ink-muted`,children:e.durationMs==null?(0,x.jsx)(`span`,{className:`text-ink-muted opacity-40`,children:`—`}):xi(e.durationMs)})]},e.agentId))})]})})}function QV(e){return e===`Read`?`bg-accent-blue`:e===`Edit`||e===`Write`?`bg-accent-green`:e===`Bash`?`bg-accent-purple`:e===`Agent`?`bg-accent-teal`:`bg-ink-subtle`}var $V=15;function eH({agents:e,window:t,parentEntries:n,onSelectRun:r}){let[i,a]=(0,b.useState)(null),o=Math.max(t.endMs-t.startMs,1),s=(0,b.useMemo)(()=>{let e=[1e4,3e4,6e4,12e4,3e5,6e5,9e5,18e5].find(e=>o/e<=8)??Math.ceil(o/8),t=[];for(let n=e;n<o;n+=e)t.push(n);return t},[o]),c=(0,b.useMemo)(()=>TV(e),[e]),l=(0,b.useMemo)(()=>n?[...n].sort((e,t)=>e.timestamp-t.timestamp):[],[n]),u=n!==void 0,d=(0,b.useMemo)(()=>c.reduce((e,t)=>e+t.agents.length,0),[c])+ +!!u,[f,p]=(0,b.useState)(()=>{let e=new Set;for(let t of c)t.agents.length>$V&&e.add(kV(t.runId));return e}),m=e=>{p(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};if(e.length===0&&!u)return(0,x.jsx)(`div`,{className:`text-ink-muted text-xs`,children:`No subagents ran in this session.`});let h=-1,g=e=>e>=3&&e>d-4?`bottom-full mb-1`:`top-full mt-1`,_=f.has(DV);return(0,x.jsxs)(`div`,{className:`p-2 overflow-x-hidden`,children:[(0,x.jsxs)(`div`,{className:`flex`,children:[(0,x.jsx)(`div`,{className:`w-24 shrink-0`}),(0,x.jsx)(`div`,{className:`relative flex-1 h-5 border-b border-bg-line overflow-x-auto`,children:s.map(e=>{let t=e/o*100;return(0,x.jsx)(`span`,{className:`absolute top-0 text-[9px] text-ink-muted tabular-nums -translate-x-1/2`,style:{left:`${t}%`},children:AV(e)},e)})})]}),(0,x.jsxs)(`div`,{className:`mt-1`,children:[u&&(0,x.jsxs)(`div`,{className:`mb-2`,children:[(0,x.jsxs)(`button`,{type:`button`,onClick:()=>m(`__parent__`),"aria-expanded":!_,className:`flex w-full items-center gap-1.5 mb-0.5 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-cyan/40 rounded-sm`,children:[_?(0,x.jsx)(gn,{size:13,className:`shrink-0 text-ink-muted`,"aria-hidden":`true`}):(0,x.jsx)(hn,{size:13,className:`shrink-0 text-ink-muted`,"aria-hidden":`true`}),(0,x.jsx)(`span`,{className:`text-[11px] font-medium text-ink-subtle truncate`,children:`Parent activity`}),(0,x.jsxs)(`span`,{className:`text-[10px] text-ink-muted tabular-nums`,children:[l.length,` tool call`,l.length===1?``:`s`]})]}),!_&&(()=>{h+=1;let e=h;return(0,x.jsxs)(`div`,{className:`flex items-center h-7`,children:[(0,x.jsx)(`div`,{className:`w-24 shrink-0 truncate text-[11px] text-ink-subtle pr-2 text-right`,children:`Parent`}),(0,x.jsx)(`div`,{className:`relative flex-1 h-full flex items-center`,children:l.map((n,r)=>{let s=n.timestamp-t.startMs,c=Math.max(0,s/o*100),l=(n.durationMs??50)/o*100,u=`parent:${r}`,d=Ei(n.toolName),f=c>=50?{right:`${Math.max(0,100-c-l)}%`}:{left:`${c}%`},p=`${n.toolName} · ${n.durationMs==null?`unknown`:`${n.durationMs}ms`} · ${n.success?`success`:`failed`}`;return(0,x.jsxs)(`div`,{className:`contents`,children:[(0,x.jsx)(`div`,{role:`img`,"aria-label":p,className:`absolute inset-y-0 my-auto h-5 rounded-sm opacity-80 cursor-default ${QV(d)} `+(n.success?``:`ring-1 ring-accent-red/60`),style:{left:`${c}%`,width:`${l}%`,minWidth:`4px`},onMouseEnter:()=>a(u),onMouseLeave:()=>a(null)}),i===u&&(0,x.jsxs)(`div`,{className:`absolute z-50 ${g(e)} px-2 py-1.5 rounded-lg bg-bg-elevated border border-bg-line text-[11px] text-ink-base shadow-lg whitespace-nowrap pointer-events-none`,style:f,children:[(0,x.jsx)(`div`,{className:`font-medium`,children:n.toolName}),(0,x.jsxs)(`div`,{className:`text-ink-muted`,children:[n.durationMs==null?`unknown`:`${n.durationMs}ms`,` `,`· `,n.success?`success`:`failed`]})]})]},u)})})]})})()]}),c.map((e,n)=>{let s=EV[n%EV.length],c=kV(e.runId),l=f.has(c),u=e.agents.map(e=>e.usd).filter(e=>e!=null),d=u.length>0?u.reduce((e,t)=>e+t,0):null,p=e.agents.reduce((e,t)=>Math.max(e,t.endMs),0)-e.earliestStartMs,_=`${e.agents.length} agent${e.agents.length===1?``:`s`} · ${wi(d)} · ${AV(Math.max(0,p))} span`;return(0,x.jsxs)(`div`,{className:`mb-2`,children:[(0,x.jsxs)(`button`,{type:`button`,onClick:()=>m(c),"aria-expanded":!l,className:`flex w-full items-center gap-1.5 mb-0.5 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-cyan/40 rounded-sm`,children:[l?(0,x.jsx)(gn,{size:13,className:`shrink-0 text-ink-muted`,"aria-hidden":`true`}):(0,x.jsx)(hn,{size:13,className:`shrink-0 text-ink-muted`,"aria-hidden":`true`}),(0,x.jsx)(`span`,{className:`inline-block w-2 h-2 rounded-sm shrink-0 ${s}`,"aria-hidden":`true`}),(0,x.jsx)(`span`,{className:`text-[11px] font-medium text-ink-subtle truncate`,title:e.name,children:e.name}),l?(0,x.jsx)(`span`,{className:`text-[10px] text-ink-muted tabular-nums truncate`,children:_}):(0,x.jsxs)(`span`,{className:`text-[10px] text-ink-muted tabular-nums`,children:[e.agents.length,` agent`,e.agents.length===1?``:`s`]})]}),!l&&e.agents.map(e=>{h+=1;let c=h,l=e.startMs-t.startMs,u=Math.max(0,l/o*100),d=e.durationMs/o*100,f=`${n}:${e.agentId}`,p=e.workflowRunId!==null&&r!==void 0,m=e.workflowRunId,_=u>=50?{right:`${Math.max(0,100-u-d)}%`}:{left:`${u}%`},v=`${e.label} · ${e.model} · ${e.turnCount} turns · ${Si(e.totalTokens)} tokens · ${wi(e.usd)} · ${xi(e.durationMs)}`+(p?` · open workflow run`:``),y=`absolute inset-y-0 my-auto h-5 rounded-sm opacity-85 ${s} `+(p?`cursor-pointer hover:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-cyan/40`:`cursor-default`);return(0,x.jsxs)(`div`,{className:`flex items-center h-7`,children:[(0,x.jsx)(`div`,{className:`w-24 shrink-0 truncate text-[11px] text-ink-subtle pr-2 text-right`,title:e.label,children:e.label}),(0,x.jsxs)(`div`,{className:`relative flex-1 h-full flex items-center`,children:[p?(0,x.jsx)(`button`,{type:`button`,"aria-label":v,className:y,style:{left:`${u}%`,width:`${d}%`,minWidth:`4px`},onClick:()=>r(m),onMouseEnter:()=>a(f),onMouseLeave:()=>a(null),onFocus:()=>a(f),onBlur:()=>a(null)}):(0,x.jsx)(`div`,{role:`img`,"aria-label":v,className:y,style:{left:`${u}%`,width:`${d}%`,minWidth:`4px`},onMouseEnter:()=>a(f),onMouseLeave:()=>a(null)}),i===f&&(0,x.jsxs)(`div`,{className:`absolute z-50 ${g(c)} px-2 py-1.5 rounded-lg bg-bg-elevated border border-bg-line text-[11px] text-ink-base shadow-lg whitespace-nowrap pointer-events-none`,style:_,children:[(0,x.jsx)(`div`,{className:`font-medium`,children:e.label}),(0,x.jsx)(`div`,{className:`text-ink-subtle font-mono`,children:e.model}),(0,x.jsxs)(`div`,{className:`text-ink-muted`,children:[e.turnCount,` turn`,e.turnCount===1?``:`s`,` ·`,` `,Si(e.totalTokens),` tokens`]}),(0,x.jsxs)(`div`,{className:`text-ink-muted`,children:[wi(e.usd),` ·`,` `,xi(e.durationMs)]})]})]})]},f)})]},e.runId??`__adhoc__`)})]})]})}var tH={running:{tone:`info`,label:`Running`},completed:{tone:`success`,label:`Completed`},failed:{tone:`danger`,label:`Failed`},cancelled:{tone:`warning`,label:`Cancelled`},unknown:{tone:`neutral`,label:`Unknown`}};function nH({status:e}){switch(e){case`completed`:return(0,x.jsx)(_n,{className:`w-4 h-4 text-accent-green`,"aria-hidden":`true`});case`failed`:return(0,x.jsx)(vn,{className:`w-4 h-4 text-accent-red`,"aria-hidden":`true`});case`running`:return(0,x.jsx)(wn,{className:`w-4 h-4 text-accent-cyan animate-spin`,"aria-hidden":`true`});case`cancelled`:return(0,x.jsx)(yn,{className:`w-4 h-4 text-accent-amber`,"aria-hidden":`true`});default:return(0,x.jsx)(yn,{className:`w-4 h-4 text-ink-muted`,"aria-hidden":`true`})}}function rH(e,t,n){let r=[];for(let i of e){if(i.startedAt==null)continue;let e=i.durationMs??0;r.push({agentId:i.agentId,workflowRunId:t,workflowName:n,label:i.label||i.agentId,model:i.model,startMs:i.startedAt,endMs:i.startedAt+e,durationMs:e,turnCount:i.toolCalls,totalTokens:i.tokens,usd:null})}return r}function iH({runId:e,onClose:t}){let n=(0,b.useRef)(null),r=(0,b.useRef)(null);(0,b.useEffect)(()=>{function e(e){if(e.key===`Escape`){t();return}if(e.key===`Tab`&&n.current){let t=n.current.querySelectorAll(`button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])`),r=t[0],i=t[t.length-1];!e.shiftKey&&document.activeElement===i?(e.preventDefault(),r?.focus()):e.shiftKey&&document.activeElement===r&&(e.preventDefault(),i?.focus())}}return document.addEventListener(`keydown`,e),r.current?.focus(),()=>document.removeEventListener(`keydown`,e)},[t]);let{data:i,isLoading:a,isError:o}=L({queryKey:z.workflowDetail(e),queryFn:()=>Hr(e),refetchInterval:5e3}),s=i?.run,c=(0,b.useMemo)(()=>i?.agents??[],[i?.agents]),l=i?.topology??null,u=s==null?null:tH[s.status]??tH.unknown,d=s!=null&&(s.status===`failed`||s.status===`cancelled`)&&typeof s.errorReason==`string`&&s.errorReason.trim()!==``?s.errorReason:null,f=c.reduce((e,t)=>e+(t.tokens??0),0),p=s?.totalTokens??null,m=p==null?null:p-f,h=(0,b.useMemo)(()=>s==null?[]:rH(c,s.runId,s.workflowName??null),[c,s]),g=(0,b.useMemo)(()=>{if(h.length===0)return{startMs:0,endMs:1};let e=1/0,t=-1/0;for(let n of h)n.startMs<e&&(e=n.startMs),n.endMs>t&&(t=n.endMs);return{startMs:e,endMs:t>e?t:e+1}},[h]);return(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(`div`,{className:`fixed inset-0 z-40 bg-black/40 backdrop-blur-sm`,"aria-hidden":`true`,onClick:t}),(0,x.jsxs)(`div`,{ref:n,role:`dialog`,"aria-modal":`true`,"aria-label":`Workflow run details: ${s?.workflowName??e}`,className:`fixed right-0 top-0 bottom-0 z-50 w-[640px] max-w-full flex flex-col bg-bg-panel border-l border-border-medium shadow-2xl overflow-hidden`,children:[(0,x.jsxs)(`div`,{className:`flex items-start justify-between gap-3 px-5 py-4 border-b border-border-subtle shrink-0`,children:[(0,x.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[a&&(0,x.jsxs)(`div`,{className:`flex items-center gap-2 text-ink-muted`,children:[(0,x.jsx)(wn,{className:`w-4 h-4 animate-spin`,"aria-hidden":`true`}),(0,x.jsx)(`span`,{className:`text-sm`,children:`Loading run details…`})]}),o&&(0,x.jsx)(`span`,{className:`text-sm text-accent-red`,children:`Failed to load run details.`}),s!=null&&(0,x.jsxs)(x.Fragment,{children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,x.jsx)(nH,{status:s.status}),(0,x.jsx)(`h2`,{className:`text-sm font-semibold text-ink-base truncate`,children:s.workflowName}),u!=null&&(0,x.jsx)(ni,{tone:u.tone,size:`sm`,bordered:!0,children:u.label}),s.runSource!=null&&(0,x.jsx)(ni,{tone:`neutral`,size:`sm`,children:s.runSource})]}),(0,x.jsxs)(`div`,{className:`mt-1 flex items-center gap-3 text-[10px] text-ink-muted flex-wrap`,children:[(0,x.jsx)(`span`,{className:`font-mono`,children:e}),s.startedAt!=null&&(0,x.jsx)(`span`,{children:new Date(s.startedAt).toLocaleString()}),s.durationMs!=null&&(0,x.jsx)(`span`,{children:xi(s.durationMs)}),s.defaultModel&&(0,x.jsx)(`span`,{className:`font-mono`,children:s.defaultModel})]})]})]}),(0,x.jsx)(`button`,{ref:r,type:`button`,"aria-label":`Close run details`,onClick:t,className:`shrink-0 p-1.5 rounded-md text-ink-muted hover:text-ink-base hover:bg-surface-5 transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-cyan/40`,children:(0,x.jsx)(An,{className:`w-4 h-4`,"aria-hidden":`true`})})]}),(0,x.jsx)(`div`,{className:`flex-1 overflow-y-auto px-5 py-4 space-y-5`,children:s!=null&&(0,x.jsxs)(x.Fragment,{children:[d!=null&&(0,x.jsxs)(B,{tone:`static`,padding:`sm`,children:[(0,x.jsx)(V,{className:`mb-2`,children:`Failure reason`}),(0,x.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,x.jsx)(vn,{className:`w-4 h-4 text-accent-red shrink-0 mt-0.5`,"aria-hidden":`true`}),(0,x.jsx)(`p`,{className:`text-xs text-accent-red font-mono break-words`,children:d})]})]}),(s.totalTokens!=null||p!=null)&&(0,x.jsxs)(B,{tone:`static`,padding:`sm`,children:[(0,x.jsx)(V,{className:`mb-2`,children:`Token Reconciliation`}),(0,x.jsxs)(`div`,{className:`grid grid-cols-3 gap-3`,children:[(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`div`,{className:`text-[10px] text-ink-muted uppercase tracking-wider`,children:`Rollup`}),(0,x.jsx)(`div`,{className:`text-sm font-bold tabular-nums text-ink-base mt-0.5`,children:p==null?`—`:p.toLocaleString()})]}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`div`,{className:`text-[10px] text-ink-muted uppercase tracking-wider`,children:`Agent Sum`}),(0,x.jsx)(`div`,{className:`text-sm font-bold tabular-nums text-ink-base mt-0.5`,children:f.toLocaleString()})]}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`div`,{className:`text-[10px] text-ink-muted uppercase tracking-wider`,children:`Delta`}),(0,x.jsx)(`div`,{className:`text-sm font-bold tabular-nums mt-0.5 ${m===null?`text-ink-muted`:m===0?`text-accent-green`:`text-accent-amber`}`,children:m===null?`—`:m===0?`0`:`${m>0?`+`:``}${m.toLocaleString()}`})]})]}),s.totalUsd!=null&&(0,x.jsxs)(`div`,{className:`mt-2 pt-2 border-t border-border-subtle flex items-center justify-between`,children:[(0,x.jsx)(`span`,{className:`text-[10px] text-ink-muted uppercase tracking-wider`,children:`Total Cost`}),(0,x.jsx)(`span`,{className:`text-xs font-bold text-accent-amber tabular-nums`,children:Ci(s.totalUsd)})]})]}),l!=null&&(0,x.jsxs)(B,{tone:`static`,padding:`sm`,children:[(0,x.jsx)(V,{className:`mb-2`,children:`Topology`}),(0,x.jsxs)(`div`,{className:`grid grid-cols-3 gap-3`,children:[(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`div`,{className:`text-[10px] text-ink-muted uppercase tracking-wider`,children:`Declared Phases`}),(0,x.jsx)(`div`,{className:`text-sm font-bold tabular-nums text-ink-base mt-0.5`,children:l.declaredPhases==null?`—`:l.declaredPhases})]}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`div`,{className:`text-[10px] text-ink-muted uppercase tracking-wider`,children:`Observed Phases`}),(0,x.jsx)(`div`,{className:`text-sm font-bold tabular-nums text-ink-base mt-0.5`,children:s.observedPhases==null?`—`:s.observedPhases})]}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`div`,{className:`text-[10px] text-ink-muted uppercase tracking-wider`,children:`Declared Agents`}),(0,x.jsx)(`div`,{className:`text-sm font-bold tabular-nums text-ink-base mt-0.5`,children:l.declaredAgents==null?`—`:l.declaredAgents})]})]}),l.declaredParallelWidths!=null&&l.declaredParallelWidths.length>0&&(0,x.jsxs)(`div`,{className:`mt-2 pt-2 border-t border-border-subtle flex items-center gap-2 flex-wrap`,children:[(0,x.jsx)(`span`,{className:`text-[10px] text-ink-muted uppercase tracking-wider`,children:`Parallel Widths`}),l.declaredParallelWidths.map((e,t)=>(0,x.jsx)(`span`,{className:`inline-flex items-center px-1.5 py-0.5 rounded text-[10px] bg-surface-5 text-ink-subtle font-mono`,children:e},`${e}-${t}`))]})]}),h.length>0&&(0,x.jsxs)(`section`,{"aria-label":`Agent fan-out timeline`,children:[(0,x.jsx)(V,{className:`mb-3`,children:`Fan-out timeline`}),(0,x.jsx)(B,{tone:`static`,padding:`sm`,children:(0,x.jsx)(eH,{agents:h,window:g})})]}),c.length>0?(0,x.jsxs)(`section`,{"aria-label":`Agent activity`,children:[(0,x.jsxs)(V,{className:`mb-3`,children:[`Agents (`,c.length,`)`]}),(0,x.jsx)(ZV,{agents:c})]}):(0,x.jsx)(`div`,{className:`py-6 text-center text-xs text-ink-muted`,children:`No agent data recorded for this run.`})]})})]})]})}var aH=[`system`,`tools`,`user`,`assistant`],oH={system:`bg-accent-indigo`,tools:`bg-accent-amber`,user:`bg-accent-blue`,assistant:`bg-accent-green`},sH={system:`shadow-[0_0_8px_rgba(99,102,241,0.4)]`,tools:`shadow-[0_0_8px_rgba(255,178,36,0.4)]`,user:`shadow-[0_0_8px_rgba(0,149,255,0.4)]`,assistant:`shadow-[0_0_8px_rgba(28,231,131,0.4)]`},cH={system:`bg-accent-indigo`,tools:`bg-accent-amber`,user:`bg-accent-blue`,assistant:`bg-accent-green`},lH={system:`System`,tools:`Tools`,user:`User`,assistant:`Assistant`},uH={system:`#6366f1`,tools:`#ffb224`,user:`#0095ff`,assistant:`#1ce783`},dH={fontSize:10,fill:`#6b7280`},fH=`#2a2a3a`;function pH({history:e,contextWindow:t}){let n=(0,b.useId)();if(e.length<2)return null;let r=e.map(e=>({turn:e.turnNumber,system:t>0?e.breakdown.system/t*100:0,tools:t>0?e.breakdown.tools/t*100:0,user:t>0?e.breakdown.user/t*100:0,assistant:t>0?e.breakdown.assistant/t*100:0}));return(0,x.jsx)(`div`,{className:`mt-2 pt-2 border-t border-surface-3`,children:(0,x.jsx)(np,{width:`100%`,height:120,children:(0,x.jsxs)(rV,{data:r,margin:{top:4,right:4,bottom:0,left:-20},children:[(0,x.jsx)(`defs`,{children:(0,x.jsxs)(`linearGradient`,{id:n,x1:`0`,y1:`1`,x2:`0`,y2:`0`,children:[(0,x.jsx)(`stop`,{offset:`0%`,stopColor:`#f59e0b`,stopOpacity:.15}),(0,x.jsx)(`stop`,{offset:`100%`,stopColor:`#ef4444`,stopOpacity:.25})]})}),(0,x.jsx)(hI,{strokeDasharray:`3 3`,stroke:fH}),(0,x.jsx)(YR,{dataKey:`turn`,tick:dH,stroke:fH}),(0,x.jsx)(uz,{domain:[0,100],unit:`%`,tick:dH,stroke:fH}),(0,x.jsx)(Yk,{contentStyle:{backgroundColor:`#1a1a2e`,border:`1px solid #2a2a3a`,fontSize:11},formatter:(e,t)=>[`${e.toFixed(1)}%`,t],labelFormatter:e=>`Turn ${e}`}),(0,x.jsx)(KP,{y1:80,y2:100,fill:`url(#${n})`,ifOverflow:`visible`}),aH.map(e=>(0,x.jsx)(yL,{type:`monotone`,dataKey:e,stackId:`context`,stroke:uH[e],fill:uH[e],fillOpacity:.4,strokeWidth:1,dot:!1},e))]})})})}function mH(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e)}function hH(e,t=``){return{sessionId:t,turnNumber:e.turnCount,totalTokens:e.growth.currentTokens,fillPercent:e.fillPercent,contextWindow:e.contextWindow,breakdown:e.currentBreakdown,growth:{startTokens:e.growth.startTokens,currentTokens:e.growth.currentTokens,delta:e.growth.deltaTokens},topTools:e.toolContributions.map(e=>({tool:e.tool,estimatedTokens:e.estimatedTokens}))}}function gH({data:e,sessionId:t,expandable:n=!0}){let r=qn(e=>e.contextBySession),i=t?r.get(t)??null:null,[a,o]=(0,b.useState)(null),[s,c]=(0,b.useState)(!1),[l,u]=(0,b.useState)(!1),d=(0,b.useRef)(0),f=(0,b.useRef)(0);(0,b.useEffect)(()=>{u(!1)},[t]);let{data:p}=L({queryKey:t?[`context`,t]:z.context,queryFn:()=>Ar(t??void 0),refetchInterval:1e4,enabled:!e}),{data:m}=L({queryKey:[`context-composition`,t],queryFn:jr,enabled:l}),{data:h}=L({queryKey:[`context-efficiency`,t],queryFn:Mr,enabled:l}),g=e??p,_=t??``,v=e?hH(e,_):i??(g?hH(g,_):null),y=v?.growth.currentTokens??0,S=Math.min(v?.fillPercent??0,100),C=f.current>0&&S>d.current;if((0,b.useEffect)(()=>{if(f.current>0&&y<f.current*.7){c(!0);let e=setTimeout(()=>c(!1),1e3);return f.current=y,d.current=S,()=>clearTimeout(e)}f.current=y,d.current=S},[S,y]),!v||v.totalTokens===0)return null;let{breakdown:w,growth:T,fillPercent:E,totalTokens:D}=v,O=E>=100,k=v.contextWindow,A=l&&g?.history&&g.history.length>=2?g.history:null;return(0,x.jsxs)(`div`,{className:`group`,children:[(0,x.jsxs)(`div`,{className:`flex items-center justify-between mb-1.5`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,x.jsx)(V,{children:`Context`}),O&&(0,x.jsx)(ni,{tone:`danger`,size:`sm`,uppercase:!0,className:`animate-pulse motion-reduce:animate-none`,children:`at capacity`})]}),(0,x.jsxs)(`div`,{className:`flex items-center gap-1 text-[11px] text-ink-subtle tabular-nums`,children:[mH(T.currentTokens),k&&k>0&&(0,x.jsx)(`span`,{className:`text-ink-muted`,children:` / ${mH(k)}`}),T.delta>0&&(0,x.jsxs)(`span`,{className:`text-accent-amber ml-1`,children:[`+`,mH(T.delta)]}),T.delta<0&&(0,x.jsx)(`span`,{className:`text-accent-cyan ml-1`,children:`compacted`}),n&&(g?.history?.length??0)>=2&&(0,x.jsx)(`button`,{onClick:()=>u(e=>!e),className:`ml-1 text-ink-muted hover:text-ink-base transition-colors`,"aria-label":`Toggle context timeline`,"aria-expanded":l,children:l?`▾`:`▸`})]})]}),(0,x.jsxs)(`div`,{className:`relative`,children:[s&&(0,x.jsx)(`div`,{className:`absolute inset-0 rounded-full bg-accent-cyan/20 animate-compact-flash pointer-events-none`}),(0,x.jsx)(`div`,{className:`w-full h-3 bg-surface-3 rounded-full overflow-hidden flex transition-colors duration-150 ${C?`shadow-[0_0_12px_rgba(255,178,36,0.3)]`:``} ${s?`animate-compact`:``}`,children:aH.map(e=>{let t=w[e];if(t<=0)return null;let n=Math.round(t/D*100),r=a===e;return(0,x.jsx)(`div`,{className:`${oH[e]} transition-all duration-500 ease-out cursor-default relative ${r?`brightness-125 ${sH[e]}`:``}`,style:{width:`${t/D*S}%`},title:`${lH[e]}: ${mH(t)} (${n}%)`,onMouseEnter:()=>o(e),onMouseLeave:()=>o(null)},e)})})]}),(0,x.jsxs)(`div`,{className:`flex items-center gap-3 mt-1.5 text-[10px] text-ink-muted`,children:[aH.map(e=>{let t=w[e],n=a===e;return(0,x.jsxs)(`span`,{className:`flex items-center gap-1 transition-colors duration-200 cursor-default ${n?`text-ink-base`:``}`,onMouseEnter:()=>o(e),onMouseLeave:()=>o(null),children:[(0,x.jsx)(`span`,{className:`inline-block w-1.5 h-1.5 rounded-full ${cH[e]} ${n?`scale-150`:``} transition-transform duration-200`}),lH[e],n&&t>0&&(0,x.jsx)(`span`,{className:`text-ink-subtle ml-0.5`,children:mH(t)})]},e)}),(0,x.jsxs)(`span`,{className:`ml-auto tabular-nums ${O?`text-accent-red`:S>=75?`text-accent-amber`:``}`,children:[S.toFixed(0),`%`]})]}),n&&(0,x.jsxs)(`div`,{className:`overflow-hidden transition-all duration-300 ${l?`max-h-56`:`max-h-0`}`,children:[A&&(0,x.jsx)(pH,{history:A,contextWindow:k}),l&&h&&h.repeatedReadRatio!==null&&(0,x.jsxs)(`div`,{className:`mt-2 text-xs text-ink-muted`,children:[(0,x.jsxs)(`span`,{children:[`Repeated reads: `,Math.round(h.repeatedReadRatio*100),`%`]}),h.topRepeatedFiles[0]&&(0,x.jsxs)(`span`,{className:`ml-2`,children:[`top:`,` `,(0,x.jsx)(`code`,{className:`bg-surface-5 px-1 rounded`,children:h.topRepeatedFiles[0].file}),` `,`(`,h.topRepeatedFiles[0].readCount,`x)`]})]}),l&&m&&(0,x.jsxs)(`div`,{className:`mt-1 text-xs text-ink-muted`,children:[`Dominant this turn:`,` `,Object.entries(m.currentBreakdown).sort((e,t)=>t[1]-e[1])[0]?.[0]]})]})]})}var _H={success:`success`,failure:`danger`,unknown:`neutral`};function vH({decisionTree:e,turnCosts:t,contextHistory:n,contextWindow:r,contextComposition:i,contextEfficiency:a,onClose:o}){let s=(0,b.useRef)(null),c=(0,b.useRef)(null);(0,b.useEffect)(()=>{function e(e){if(e.key===`Escape`){o();return}if(e.key===`Tab`&&s.current){let t=s.current.querySelectorAll(`button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])`),n=t[0],r=t[t.length-1];!e.shiftKey&&document.activeElement===r?(e.preventDefault(),n?.focus()):e.shiftKey&&document.activeElement===n&&(e.preventDefault(),r?.focus())}}return document.addEventListener(`keydown`,e),c.current?.focus(),()=>document.removeEventListener(`keydown`,e)},[o]);let l=e!=null&&e.totalBranches>0,u=t?.turns!=null&&t.turns.length>0,d=(n?.length??0)>=2;return(0,li.createPortal)((0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(`div`,{className:`fixed inset-0 z-40 bg-black/40 backdrop-blur-sm`,"aria-hidden":`true`,onClick:o}),(0,x.jsxs)(`div`,{ref:s,role:`dialog`,"aria-modal":`true`,"aria-label":`Session decision-tree and turn-cost detail`,className:`fixed right-0 top-0 bottom-0 z-50 w-[640px] max-w-full flex flex-col bg-bg-panel border-l border-border-medium shadow-2xl overflow-hidden`,children:[(0,x.jsxs)(`div`,{className:`flex items-start justify-between gap-3 px-5 py-4 border-b border-border-subtle shrink-0`,children:[(0,x.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,x.jsx)(`h2`,{className:`text-sm font-semibold text-ink-base`,children:`Session Detail`}),(0,x.jsx)(`p`,{className:`mt-1 text-[10px] text-ink-muted`,children:`Decision Tree and Turn Costs below are scoped to the selected session. Context Composition & Efficiency remain live, current-process-only — they reflect this dashboard process’s own current session, not necessarily the one selected above.`})]}),(0,x.jsx)(`button`,{ref:c,type:`button`,"aria-label":`Close session detail`,onClick:o,className:`shrink-0 p-1.5 rounded-md text-ink-muted hover:text-ink-base hover:bg-surface-5 transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-cyan/40`,children:(0,x.jsx)(An,{className:`w-4 h-4`,"aria-hidden":`true`})})]}),(0,x.jsxs)(`div`,{className:`flex-1 overflow-y-auto px-5 py-4 space-y-5`,children:[(0,x.jsxs)(`section`,{"aria-label":`Decision tree`,children:[(0,x.jsx)(V,{className:`mb-3`,children:`Decision Tree`}),(0,x.jsx)(B,{tone:`static`,padding:`sm`,children:l?(0,x.jsxs)(x.Fragment,{children:[(0,x.jsxs)(`div`,{className:`grid grid-cols-3 gap-3`,children:[(0,x.jsx)(yH,{label:`Longest failure streak`,value:String(e.longestFailureStreak)}),(0,x.jsx)(yH,{label:`Success rate`,value:e.successRate===null?`—`:`${Math.round(e.successRate*100)}%`}),(0,x.jsx)(yH,{label:`Total branches`,value:String(e.totalBranches)})]}),e.failurePoints.length>0&&(0,x.jsx)(`div`,{className:`mt-3 pt-3 border-t border-border-subtle space-y-2`,children:e.failurePoints.map((e,t)=>(0,x.jsx)(`div`,{className:`flex items-start justify-between gap-2 text-xs`,children:(0,x.jsxs)(`div`,{className:`min-w-0`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:[(0,x.jsxs)(`span`,{className:`text-ink-muted`,children:[`Turn `,e.turnNumber]}),e.toolName&&(0,x.jsx)(`code`,{className:`text-[10px] bg-surface-5 px-1 rounded`,children:e.toolName}),(0,x.jsx)(ni,{tone:_H[e.outcome],size:`sm`,children:e.outcome})]}),(0,x.jsx)(`p`,{className:`mt-0.5 text-ink-subtle break-words`,children:e.reasoning})]})},`${e.turnNumber}-${t}`))}),e.note&&(0,x.jsx)(`p`,{className:`mt-3 pt-3 border-t border-border-subtle text-[10px] text-ink-muted`,children:e.note})]}):(0,x.jsx)(`div`,{className:`py-2 text-center text-xs text-ink-muted`,children:`No decision-tree data yet.`})})]}),(0,x.jsxs)(`section`,{"aria-label":`Turn costs`,children:[(0,x.jsx)(V,{className:`mb-3`,children:`Turn Costs`}),(0,x.jsx)(B,{tone:`static`,padding:`sm`,children:u?(0,x.jsxs)(x.Fragment,{children:[(0,x.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 mb-3 pb-3 border-b border-border-subtle`,children:[(0,x.jsx)(yH,{label:`Total attributed cost`,value:`$${t.totalAttributedCost.toFixed(2)}`}),(0,x.jsx)(yH,{label:`Attribution rate`,value:`${Math.round(t.attributionRate*100)}%`})]}),(0,x.jsx)(`div`,{className:`space-y-2`,children:t.turns.map(e=>(0,x.jsxs)(`div`,{className:`flex items-center justify-between gap-2 text-xs`,children:[(0,x.jsxs)(`div`,{className:`min-w-0`,children:[(0,x.jsx)(`div`,{className:`text-ink-base`,children:e.toolNames.join(`, `)}),(0,x.jsxs)(`div`,{className:`text-[10px] text-ink-muted font-mono`,children:[e.model,` · `,Ti(e.inputTokens),` in /`,` `,Ti(e.outputTokens),` out /`,` `,Ti(e.cacheReadTokens),` cache`]})]}),(0,x.jsxs)(`span`,{className:`shrink-0 tabular-nums text-ink-base`,children:[`$`,e.estimatedCostUsd.toFixed(2)]})]},e.turnId))})]}):(0,x.jsx)(`div`,{className:`py-2 text-center text-xs text-ink-muted`,children:`No turn-cost data yet.`})})]}),(0,x.jsxs)(`section`,{"aria-label":`Context timeline`,children:[(0,x.jsx)(V,{className:`mb-3`,children:`Context Timeline`}),(0,x.jsx)(B,{tone:`static`,padding:`sm`,children:d?(0,x.jsx)(pH,{history:n??[],contextWindow:r??0}):(0,x.jsx)(`div`,{className:`py-2 text-center text-xs text-ink-muted`,children:`No context timeline data yet.`})})]}),(0,x.jsxs)(`section`,{"aria-label":`Context composition and efficiency`,children:[(0,x.jsx)(V,{className:`mb-3`,children:`Context Composition & Efficiency`}),(0,x.jsx)(B,{tone:`static`,padding:`sm`,children:!i&&!a?(0,x.jsx)(`div`,{className:`py-2 text-center text-xs text-ink-muted`,children:`No composition/efficiency data yet.`}):(0,x.jsxs)(`div`,{className:`space-y-2 text-xs`,children:[i&&(0,x.jsxs)(`div`,{className:`text-ink-muted`,children:[`Dominant this turn:`,` `,(0,x.jsx)(`span`,{className:`text-ink-base`,children:Object.entries(i.currentBreakdown).sort((e,t)=>t[1]-e[1])[0]?.[0]})]}),a&&a.repeatedReadRatio!==null&&(0,x.jsxs)(`div`,{className:`text-ink-muted`,children:[`Repeated reads:`,` `,(0,x.jsxs)(`span`,{className:`text-ink-base`,children:[Math.round(a.repeatedReadRatio*100),`%`]}),a.topRepeatedFiles[0]&&(0,x.jsxs)(x.Fragment,{children:[` `,`— top:`,` `,(0,x.jsx)(`code`,{className:`bg-surface-5 px-1 rounded`,children:a.topRepeatedFiles[0].file}),` `,`(`,a.topRepeatedFiles[0].readCount,`x)`]})]})]})})]})]})]})]}),document.body)}function yH({label:e,value:t}){return(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`div`,{className:`text-[10px] text-ink-muted uppercase tracking-wider`,children:e}),(0,x.jsx)(`div`,{className:`text-sm font-bold tabular-nums text-ink-base mt-0.5`,children:t})]})}var bH=`nr-observe-peak-concurrent`;function xH({current:e,peak:t,allTimePeak:n,buckets:r}){let[i,a]=(0,b.useState)(!1),o=(0,b.useRef)(null),s=r.some(e=>e.count>0);(0,b.useEffect)(()=>{let e=n??t;if(e<=0)return;let r=parseInt(localStorage.getItem(bH)??`0`,10);if(o.current===null&&(o.current=r),e>o.current){localStorage.setItem(bH,String(e)),o.current=e,a(!0);let t=setTimeout(()=>a(!1),3e3);return()=>clearTimeout(t)}},[t,n]);let c=r.map(e=>{let t=new Date(e.timestamp).toLocaleTimeString(void 0,{hour:`numeric`,minute:`2-digit`});return{count:e.count,tooltip:`${t} — ${e.count} concurrent`}});return(0,x.jsxs)(B,{padding:`sm`,className:`relative overflow-hidden${i?` new-peak-glow`:``}`,children:[i&&(0,x.jsx)(SH,{}),(0,x.jsx)(V,{className:`mb-1.5`,children:`Concurrent Sessions`}),(0,x.jsxs)(`div`,{className:`flex items-baseline gap-3`,children:[(0,x.jsx)(`span`,{className:`text-lg font-semibold text-accent-teal tabular-nums`,children:e}),(0,x.jsxs)(`span`,{className:`text-xs text-ink-muted tabular-nums`,children:[`today peak `,t,n&&n>t?` · all-time ${n}`:``]}),i&&(0,x.jsx)(`span`,{className:`text-[10px] text-accent-green font-semibold animate-bounce`,children:`NEW RECORD!`})]}),s&&(0,x.jsx)(`div`,{className:`mt-2`,children:(0,x.jsx)(pV,{data:c,ariaLabel:`Concurrency over time, peak ${t}`})})]})}function SH(){let e=Array.from({length:12},(e,t)=>{let n=t/12*360,r=40+Math.random()*30;return(0,x.jsx)(`span`,{className:`absolute w-1.5 h-1.5 rounded-full`,style:{left:`50%`,top:`50%`,backgroundColor:t%3==0?`#1CE783`:t%3==1?`#00D4AA`:`#9945FF`,animation:`particle-burst 1s ease-out forwards`,animationDelay:`${t*40}ms`,transform:`translate(-50%, -50%) rotate(${n}deg) translateY(-${r}px)`,opacity:0}},t)});return(0,x.jsx)(x.Fragment,{children:e})}var CH=[`var(--color-heatmap-0)`,`var(--color-heatmap-1)`,`var(--color-heatmap-2)`,`var(--color-heatmap-3)`,`var(--color-heatmap-4)`];function wH(e,t){if(e===0)return CH[0];let n=e/t;return CH[Math.min(Math.ceil(n*4),4)]}function TH(e,t,n){let r=e+n*t;return new Date(r).toLocaleTimeString(void 0,{hour:`numeric`,minute:`2-digit`})}function EH({variant:e,buckets:t,maxCount:n,bucketSizeMs:r,startTimestamp:i,width:a,height:o,ariaLabel:s,days:c}){return e===`grid`&&c?(0,x.jsx)(kH,{days:c,maxCount:n,width:a,height:o,ariaLabel:s}):(0,x.jsx)(DH,{buckets:t,maxCount:n,bucketSizeMs:r,startTimestamp:i,width:a,height:o,ariaLabel:s})}function DH({buckets:e,maxCount:t,bucketSizeMs:n=9e5,startTimestamp:r=0,width:i,height:a=24,ariaLabel:o}){let[s,c]=(0,b.useState)(null),l=Math.max(4,Math.min(12,i?(i-e.length*1)/e.length:8)),u=i??e.length*(l+1);return(0,x.jsxs)(`div`,{className:`relative`,children:[(0,x.jsx)(`svg`,{width:u,height:a,role:`img`,"aria-label":o??`Activity heatmap: ${e.length} time buckets`,className:`w-full`,style:{maxWidth:u},viewBox:`0 0 ${u} ${a}`,preserveAspectRatio:`none`,onMouseLeave:()=>c(null),children:e.map((e,i)=>(0,x.jsx)(`rect`,{x:i*(l+1),y:0,width:l,height:a,rx:2,fill:wH(e,t),className:`heatmap-cell`,style:{animationDelay:`${Math.min(i*8,400)}ms`},onMouseEnter:t=>{let a=TH(r,n,i);c({x:t.currentTarget.x.baseVal.value,text:`${a}: ${e} calls`})}},i))}),s&&(0,x.jsx)(`div`,{className:`absolute -top-7 px-1.5 py-0.5 bg-bg-elevated border border-border-subtle text-[10px] text-ink-base rounded-md shadow-md pointer-events-none whitespace-nowrap tabular-nums`,style:{left:s.x},children:s.text})]})}var OH=[`Mon`,``,`Wed`,``,`Fri`,``,`Sun`];function kH({days:e,maxCount:t,ariaLabel:n}){let[r,i]=(0,b.useState)(null),a=(0,b.useMemo)(()=>{if(e.length===0)return{weeks:0,cells:[]};let t=(new Date(e[0].date).getUTCDay()+6)%7,n=[];for(let r=0;r<e.length;r++){let i=r+t,a=i%7,o=Math.floor(i/7);n.push({...e[r],row:a,col:o})}return{weeks:n.length>0?n[n.length-1].col+1:0,cells:n}},[e]),o=28+a.weeks*12,s=(0,b.useMemo)(()=>{let e=[],t=``;for(let n of a.cells){if(n.row!==0)continue;let r=new Date(n.date).toLocaleString(void 0,{month:`short`,timeZone:`UTC`});r!==t&&(e.push({text:r,col:n.col}),t=r)}return e},[a.cells]);return(0,x.jsxs)(`div`,{className:`relative flex justify-center`,children:[(0,x.jsxs)(`svg`,{width:`100%`,height:98,role:`img`,"aria-label":n??`Activity grid: ${e.length} days`,viewBox:`0 0 ${o} 98`,preserveAspectRatio:`xMidYMid meet`,onMouseLeave:()=>i(null),children:[OH.map((e,t)=>e?(0,x.jsx)(`text`,{x:0,y:14+t*12+10-2,className:`fill-ink-muted`,fontSize:10,children:e},t):null),s.map(({text:e,col:t})=>(0,x.jsx)(`text`,{x:28+t*12,y:10,className:`fill-ink-muted`,fontSize:10,children:e},`${e}-${t}`)),a.cells.map((e,n)=>(0,x.jsx)(`rect`,{x:28+e.col*12,y:14+e.row*12,width:10,height:10,rx:2,fill:wH(e.count,t),className:`heatmap-cell`,style:{animationDelay:`${Math.min(n*3,300)}ms`},onMouseEnter:t=>{let n=t.currentTarget;i({x:n.x.baseVal.value,y:n.y.baseVal.value-16,text:`${e.date}: ${e.count} calls`})}},n))]}),r&&(0,x.jsx)(`div`,{className:`absolute px-1.5 py-0.5 bg-bg-elevated border border-border-subtle text-[10px] text-ink-base rounded-md shadow-md pointer-events-none whitespace-nowrap tabular-nums`,style:{left:r.x,top:r.y},children:r.text}),(0,x.jsxs)(`div`,{className:`flex items-center gap-1 mt-1.5 text-[10px] text-ink-muted`,children:[(0,x.jsx)(`span`,{children:`Less`}),CH.map((e,t)=>(0,x.jsx)(`span`,{className:`inline-block w-2.5 h-2.5 rounded-sm`,style:{backgroundColor:e}},t)),(0,x.jsx)(`span`,{children:`More`})]})]})}function AH({theme:e=`observatory`}){return(0,x.jsxs)(`div`,{className:`geo-banner`,"aria-hidden":`true`,children:[e===`observatory`&&(0,x.jsx)(jH,{}),e===`sessions`&&(0,x.jsx)(MH,{}),e===`history`&&(0,x.jsx)(NH,{}),e===`audit`&&(0,x.jsx)(PH,{}),e===`git`&&(0,x.jsx)(FH,{})]})}function jH(){return(0,x.jsxs)(`svg`,{viewBox:`0 0 800 80`,preserveAspectRatio:`xMidYMid slice`,className:`w-full h-full`,children:[(0,x.jsx)(`defs`,{children:(0,x.jsxs)(`linearGradient`,{id:`obsSky`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,x.jsx)(`stop`,{offset:`0%`,stopColor:`#1a3a5c`}),(0,x.jsx)(`stop`,{offset:`40%`,stopColor:`#2d5a7b`}),(0,x.jsx)(`stop`,{offset:`70%`,stopColor:`#e8834a`}),(0,x.jsx)(`stop`,{offset:`100%`,stopColor:`#f4a261`})]})}),(0,x.jsx)(`rect`,{width:`800`,height:`80`,fill:`url(#obsSky)`}),(0,x.jsx)(`polygon`,{points:`0,80 0,45 80,38 160,48 240,30 340,42 420,25 500,38 580,32 660,40 740,28 800,35 800,80`,fill:`#1a3a5c`,opacity:`0.7`}),(0,x.jsx)(`polygon`,{points:`0,80 0,55 60,48 140,58 220,42 300,52 380,40 460,50 520,38 600,48 680,42 760,52 800,48 800,80`,fill:`#234e6f`}),(0,x.jsx)(`polygon`,{points:`0,80 0,62 100,58 200,65 300,55 400,60 500,54 600,62 700,56 800,60 800,80`,fill:`#2a6b4a`,opacity:`0.8`}),(0,x.jsx)(`circle`,{cx:`680`,cy:`28`,r:`14`,fill:`#f4a261`,opacity:`0.6`}),(0,x.jsx)(`circle`,{cx:`680`,cy:`28`,r:`8`,fill:`#ffd166`,opacity:`0.5`}),(0,x.jsx)(`ellipse`,{cx:`150`,cy:`56`,rx:`18`,ry:`10`,fill:`#1a3a5c`}),(0,x.jsx)(`line`,{x1:`150`,y1:`46`,x2:`172`,y2:`34`,stroke:`#5ce0d8`,strokeWidth:`1.5`,opacity:`0.8`})]})}function MH(){return(0,x.jsxs)(`svg`,{viewBox:`0 0 800 80`,preserveAspectRatio:`xMidYMid slice`,className:`w-full h-full`,children:[(0,x.jsx)(`defs`,{children:(0,x.jsxs)(`linearGradient`,{id:`seaSky`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,x.jsx)(`stop`,{offset:`0%`,stopColor:`#4aa8c7`}),(0,x.jsx)(`stop`,{offset:`60%`,stopColor:`#3a8fb7`}),(0,x.jsx)(`stop`,{offset:`100%`,stopColor:`#2d7a9e`})]})}),(0,x.jsx)(`rect`,{width:`800`,height:`80`,fill:`url(#seaSky)`}),(0,x.jsx)(`polygon`,{points:`600,48 640,35 680,48`,fill:`#2d7a4a`,opacity:`0.4`}),(0,x.jsx)(`polygon`,{points:`700,50 730,40 760,50`,fill:`#3d9b5b`,opacity:`0.3`}),(0,x.jsx)(`polygon`,{points:`0,80 0,15 40,12 80,20 120,18 160,25 180,30 180,80`,fill:`#c05a3c`}),(0,x.jsx)(`polygon`,{points:`0,80 0,25 30,22 60,28 100,25 140,30 160,35 160,80`,fill:`#e8834a`,opacity:`0.6`}),(0,x.jsx)(`polygon`,{points:`20,20 35,8 50,20`,fill:`#3d9b5b`}),(0,x.jsx)(`polygon`,{points:`60,22 72,12 84,24`,fill:`#4aad6b`}),(0,x.jsx)(`polygon`,{points:`100,20 115,10 130,22`,fill:`#3d9b5b`}),(0,x.jsx)(`polygon`,{points:`140,28 150,18 160,28`,fill:`#4aad6b`,opacity:`0.8`}),(0,x.jsx)(`rect`,{x:`120`,y:`30`,width:`8`,height:`50`,fill:`#87ceeb`,opacity:`0.5`}),(0,x.jsx)(`rect`,{x:`122`,y:`30`,width:`4`,height:`50`,fill:`#fff`,opacity:`0.3`}),(0,x.jsx)(`polygon`,{points:`620,80 620,30 660,25 700,32 740,28 780,35 800,30 800,80`,fill:`#c05a3c`,opacity:`0.8`}),(0,x.jsx)(`polygon`,{points:`650,30 665,18 680,30`,fill:`#3d9b5b`}),(0,x.jsx)(`polygon`,{points:`720,32 732,22 744,32`,fill:`#4aad6b`}),(0,x.jsx)(`polygon`,{points:`180,80 180,55 250,52 350,56 450,52 550,55 620,52 620,80`,fill:`#2d7a9e`,opacity:`0.6`}),(0,x.jsx)(`line`,{x1:`200`,y1:`60`,x2:`280`,y2:`58`,stroke:`#5ce0d8`,strokeWidth:`0.8`,opacity:`0.3`}),(0,x.jsx)(`line`,{x1:`350`,y1:`56`,x2:`450`,y2:`55`,stroke:`#5ce0d8`,strokeWidth:`0.8`,opacity:`0.25`}),(0,x.jsx)(`line`,{x1:`480`,y1:`58`,x2:`580`,y2:`56`,stroke:`#87ceeb`,strokeWidth:`0.8`,opacity:`0.3`})]})}function NH(){return(0,x.jsxs)(`svg`,{viewBox:`0 0 800 80`,preserveAspectRatio:`xMidYMid slice`,className:`w-full h-full`,children:[(0,x.jsx)(`defs`,{children:(0,x.jsxs)(`linearGradient`,{id:`histSky`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,x.jsx)(`stop`,{offset:`0%`,stopColor:`#3a7ca5`}),(0,x.jsx)(`stop`,{offset:`60%`,stopColor:`#5bb8d4`}),(0,x.jsx)(`stop`,{offset:`100%`,stopColor:`#8ed4c0`})]})}),(0,x.jsx)(`rect`,{width:`800`,height:`80`,fill:`url(#histSky)`}),(0,x.jsx)(`polygon`,{points:`100,50 140,20 180,50`,fill:`#e8834a`,opacity:`0.7`}),(0,x.jsx)(`polygon`,{points:`160,50 210,15 260,50`,fill:`#d4694a`,opacity:`0.6`}),(0,x.jsx)(`polygon`,{points:`550,50 600,18 650,50`,fill:`#e8834a`,opacity:`0.6`}),(0,x.jsx)(`polygon`,{points:`620,50 660,22 700,50`,fill:`#c05a3c`,opacity:`0.5`}),(0,x.jsx)(`polygon`,{points:`350,50 370,12 390,50`,fill:`#5ce0d8`,opacity:`0.4`}),(0,x.jsx)(`polygon`,{points:`380,50 395,20 410,50`,fill:`#87ceeb`,opacity:`0.3`}),(0,x.jsx)(`polygon`,{points:`700,50 715,25 730,50`,fill:`#5ce0d8`,opacity:`0.35`}),(0,x.jsx)(`polygon`,{points:`300,80 380,50 420,50 500,80`,fill:`#2a5a6b`,opacity:`0.6`}),(0,x.jsx)(`line`,{x1:`390`,y1:`52`,x2:`350`,y2:`78`,stroke:`#f4a261`,strokeWidth:`1`,opacity:`0.4`}),(0,x.jsx)(`line`,{x1:`410`,y1:`52`,x2:`450`,y2:`78`,stroke:`#f4a261`,strokeWidth:`1`,opacity:`0.4`}),(0,x.jsx)(`polygon`,{points:`0,80 0,55 80,52 160,58 240,50 320,55 500,52 580,56 660,50 740,55 800,52 800,80`,fill:`#2d8a4a`,opacity:`0.5`}),(0,x.jsx)(`polygon`,{points:`0,80 0,65 60,62 140,68 220,60 400,65 500,62 600,66 700,60 800,65 800,80`,fill:`#1e6b3a`,opacity:`0.6`}),(0,x.jsx)(`polygon`,{points:`30,65 42,42 54,65`,fill:`#3d9b5b`,opacity:`0.8`}),(0,x.jsx)(`polygon`,{points:`50,65 60,48 70,65`,fill:`#2d8a4a`,opacity:`0.7`}),(0,x.jsx)(`polygon`,{points:`720,65 732,45 744,65`,fill:`#3d9b5b`,opacity:`0.7`}),(0,x.jsx)(`polygon`,{points:`760,65 770,50 780,65`,fill:`#2d8a4a`,opacity:`0.8`})]})}function PH(){return(0,x.jsxs)(`svg`,{viewBox:`0 0 800 80`,preserveAspectRatio:`xMidYMid slice`,className:`w-full h-full`,children:[(0,x.jsx)(`defs`,{children:(0,x.jsxs)(`linearGradient`,{id:`auditSky`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,x.jsx)(`stop`,{offset:`0%`,stopColor:`#1a5c3a`}),(0,x.jsx)(`stop`,{offset:`50%`,stopColor:`#2d7a4a`}),(0,x.jsx)(`stop`,{offset:`100%`,stopColor:`#3d9b5b`})]})}),(0,x.jsx)(`rect`,{width:`800`,height:`80`,fill:`url(#auditSky)`}),(0,x.jsx)(`polygon`,{points:`200,0 210,80 220,0`,fill:`#ffd166`,opacity:`0.08`}),(0,x.jsx)(`polygon`,{points:`500,0 510,80 520,0`,fill:`#ffd166`,opacity:`0.06`}),(0,x.jsx)(`polygon`,{points:`650,0 660,80 670,0`,fill:`#fff`,opacity:`0.05`}),(0,x.jsx)(`rect`,{x:`80`,y:`20`,width:`6`,height:`60`,fill:`#1a4a2e`}),(0,x.jsx)(`rect`,{x:`180`,y:`10`,width:`7`,height:`70`,fill:`#1a4a2e`}),(0,x.jsx)(`rect`,{x:`320`,y:`15`,width:`6`,height:`65`,fill:`#1a4a2e`}),(0,x.jsx)(`rect`,{x:`500`,y:`8`,width:`7`,height:`72`,fill:`#1a4a2e`}),(0,x.jsx)(`rect`,{x:`620`,y:`18`,width:`6`,height:`62`,fill:`#1a4a2e`}),(0,x.jsx)(`rect`,{x:`740`,y:`12`,width:`7`,height:`68`,fill:`#1a4a2e`}),(0,x.jsx)(`polygon`,{points:`55,25 83,5 111,25`,fill:`#4aad6b`}),(0,x.jsx)(`polygon`,{points:`60,35 83,15 106,35`,fill:`#3d9b5b`}),(0,x.jsx)(`polygon`,{points:`155,15 183,0 211,18`,fill:`#5bc47a`}),(0,x.jsx)(`polygon`,{points:`160,28 183,8 206,28`,fill:`#4aad6b`}),(0,x.jsx)(`polygon`,{points:`295,20 323,2 351,22`,fill:`#5bc47a`}),(0,x.jsx)(`polygon`,{points:`300,32 323,12 346,32`,fill:`#3d9b5b`}),(0,x.jsx)(`polygon`,{points:`475,12 503,0 531,15`,fill:`#4aad6b`}),(0,x.jsx)(`polygon`,{points:`480,25 503,5 526,25`,fill:`#3d9b5b`}),(0,x.jsx)(`polygon`,{points:`595,22 623,5 651,22`,fill:`#5bc47a`}),(0,x.jsx)(`polygon`,{points:`600,34 623,14 646,34`,fill:`#4aad6b`}),(0,x.jsx)(`polygon`,{points:`715,16 743,0 771,18`,fill:`#5bc47a`}),(0,x.jsx)(`polygon`,{points:`720,30 743,10 766,30`,fill:`#3d9b5b`}),(0,x.jsx)(`polygon`,{points:`0,80 0,68 100,65 200,70 300,64 400,68 500,63 600,67 700,64 800,68 800,80`,fill:`#1e6b3a`}),(0,x.jsx)(`polygon`,{points:`250,80 258,65 266,80`,fill:`#e8834a`,opacity:`0.6`}),(0,x.jsx)(`polygon`,{points:`450,80 456,68 462,80`,fill:`#f4a261`,opacity:`0.5`}),(0,x.jsx)(`polygon`,{points:`650,80 656,66 662,80`,fill:`#e8834a`,opacity:`0.55`})]})}function FH(){return(0,x.jsxs)(`svg`,{viewBox:`0 0 800 80`,preserveAspectRatio:`xMidYMid slice`,className:`w-full h-full`,children:[(0,x.jsx)(`defs`,{children:(0,x.jsxs)(`linearGradient`,{id:`gitSky`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,x.jsx)(`stop`,{offset:`0%`,stopColor:`#2d5a7b`}),(0,x.jsx)(`stop`,{offset:`60%`,stopColor:`#3a8fb7`}),(0,x.jsx)(`stop`,{offset:`100%`,stopColor:`#5bb8d4`})]})}),(0,x.jsx)(`rect`,{width:`800`,height:`80`,fill:`url(#gitSky)`}),(0,x.jsx)(`polygon`,{points:`0,80 0,20 60,25 120,18 180,28 220,22 260,30 260,80`,fill:`#2d7a4a`,opacity:`0.7`}),(0,x.jsx)(`polygon`,{points:`540,80 540,22 600,28 660,20 720,25 780,18 800,22 800,80`,fill:`#2d7a4a`,opacity:`0.7`}),(0,x.jsx)(`path`,{d:`M 260,50 Q 320,48 400,45 Q 480,42 540,50`,fill:`none`,stroke:`#5ce0d8`,strokeWidth:`4`,opacity:`0.5`}),(0,x.jsx)(`path`,{d:`M 350,45 Q 370,35 400,28`,fill:`none`,stroke:`#87ceeb`,strokeWidth:`2`,opacity:`0.4`}),(0,x.jsx)(`path`,{d:`M 420,44 Q 440,52 470,60`,fill:`none`,stroke:`#87ceeb`,strokeWidth:`2`,opacity:`0.4`}),(0,x.jsx)(`path`,{d:`M 400,28 Q 430,25 460,30`,fill:`none`,stroke:`#5ce0d8`,strokeWidth:`1.5`,opacity:`0.35`}),(0,x.jsx)(`circle`,{cx:`400`,cy:`45`,r:`3`,fill:`#5ce0d8`,opacity:`0.6`}),(0,x.jsx)(`circle`,{cx:`350`,cy:`45`,r:`2`,fill:`#1ce783`,opacity:`0.5`}),(0,x.jsx)(`circle`,{cx:`460`,cy:`44`,r:`2`,fill:`#1ce783`,opacity:`0.5`}),(0,x.jsx)(`polygon`,{points:`300,65 310,55 320,65`,fill:`#3a6b4a`,opacity:`0.6`}),(0,x.jsx)(`polygon`,{points:`480,62 492,52 504,62`,fill:`#3a6b4a`,opacity:`0.6`}),(0,x.jsx)(`polygon`,{points:`240,35 250,18 260,35`,fill:`#4aad6b`}),(0,x.jsx)(`polygon`,{points:`540,35 550,20 560,35`,fill:`#4aad6b`}),(0,x.jsx)(`polygon`,{points:`270,50 278,38 286,50`,fill:`#3d9b5b`,opacity:`0.8`}),(0,x.jsx)(`polygon`,{points:`520,48 528,36 536,48`,fill:`#3d9b5b`,opacity:`0.8`})]})}function IH(e){return new Intl.DateTimeFormat(`en-US`,{timeZone:e}).resolvedOptions().timeZone}var LH=new Map;function RH(e){let t=IH(e),n=LH.get(t);return n||(n=new Intl.DateTimeFormat(`en-US`,{timeZone:t,year:`numeric`,month:`2-digit`,day:`2-digit`}),LH.set(t,n)),n}var zH=new Map;function BH(e){let t=IH(e),n=zH.get(t);return n||(n=new Intl.DateTimeFormat(`en-US`,{timeZone:t,year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`,hour12:!1}),zH.set(t,n)),n}function VH(e,t){let n=RH(t).formatToParts(e),r=0,i=0,a=0;for(let e of n)e.type===`year`?r=Number(e.value):e.type===`month`?i=Number(e.value):e.type===`day`&&(a=Number(e.value));return{year:r,month:i,day:a}}function HH(e,t){let n=BH(t).formatToParts(e),r={};for(let e of n)e.type!==`literal`&&(r[e.type]=Number(e.value));let i=r.hour===24?0:r.hour;return Date.UTC(r.year,r.month-1,r.day,i,r.minute,r.second)-e}function UH(e,t,n,r){let i=Date.UTC(e,t-1,n),a=HH(i,r),o=i-a,s=HH(o,r);if(s===a)return o;let c=i-s,l=VH(c,r);return l.year===e&&l.month===t&&l.day===n?c:o}function WH(e,t){if(t){let{year:n,month:r,day:i}=VH(e??Date.now(),t);return UH(n,r,i,t)}let n=e==null?new Date:new Date(e);return n.setHours(0,0,0,0),n.getTime()}function GH(e,t,n){if(n){let r=VH(e,n),i=VH(t??Date.now(),n);return r.year===i.year&&r.month===i.month&&r.day===i.day}let r=new Date(e),i=t==null?new Date:new Date(t);return r.getFullYear()===i.getFullYear()&&r.getMonth()===i.getMonth()&&r.getDate()===i.getDate()}function KH(e,t){let n=WH(t),r=n+864e5;if(e.endTime<n||e.startTime>=r)return 0;if(e.startTime>=n&&e.endTime<r)return 1;if(e.timeline&&e.timeline.length>0){let t=e.timeline.length,i=e.timeline.filter(e=>e.timestamp>=n&&e.timestamp<r).length;if(t>0)return i/t}return(Math.min(e.endTime,r)-Math.max(e.startTime,n))/Math.max(1,e.endTime-e.startTime)}var qH={weekday:`short`,month:`short`,day:`numeric`,hour:`numeric`,minute:`2-digit`},JH=3e4,YH={info:`text-ink-muted`,warning:`text-accent-amber`,critical:`text-accent-red`};function XH(e,t){return e===`clean`?`No compute waste detected this session.`:(t===null?null:{stuck_loop:`Address the command output before re-running the same command.`,re_reading:`Read each file once and keep relevant sections in mind.`,thrashing:`Read the test failure output carefully before editing again.`,blind_editing:`Verify changes with tests between edit batches.`,over_delegation:`Multiple sub-agent spawns failed or were interrupted — investigate why before retrying.`}[t]??null)??`Review anti-patterns to reduce repeated tool calls.`}var ZH=1e4,QH={fill:`var(--color-ink-muted)`,fontSize:10},$H=`var(--color-border-subtle)`,eU={background:`var(--color-bg-elevated)`,border:`1px solid var(--color-border-medium)`,borderRadius:8,fontSize:12,color:`var(--color-ink-base)`},tU={color:`var(--color-ink-base)`};function nU(e){return e===`Read`?`var(--color-accent-blue)`:e===`Edit`||e===`Write`?`var(--color-accent-green)`:e===`Bash`?`var(--color-accent-purple)`:e===`Agent`?`var(--color-accent-teal)`:`var(--color-ink-muted)`}function rU(){let e=qn(e=>e.cost),t=qn(e=>e.antiPatterns),n=Zn(),{data:r}=L({queryKey:[`observability-health`],queryFn:Br,refetchInterval:3e4}),{data:i,isPending:a}=L({queryKey:z.cost,queryFn:or,refetchInterval:1e4}),{data:o,isPending:s}=L({queryKey:z.sessionsTodayAggregate,queryFn:rr,refetchInterval:1e4}),{data:c,isPending:l}=L({queryKey:z.sessionsList(200),queryFn:()=>nr(200),refetchInterval:1e4}),{data:u,isPending:d}=L({queryKey:z.antiPatterns,queryFn:sr}),{data:f,isPending:p}=L({queryKey:z.concurrency,queryFn:Dr,refetchInterval:1e4}),{data:m,isPending:h}=L({queryKey:z.activityHeatmap(`today`),queryFn:()=>kr(`today`),refetchInterval:3e4}),{data:g,isPending:_}=L({queryKey:z.sessionsLive,queryFn:ir,refetchInterval:1e4}),v=(0,b.useMemo)(()=>SU(c??[]),[c]),y=(0,b.useMemo)(()=>CU(c??[]),[c]),S=(0,b.useMemo)(()=>wU(c??[]),[c]),C=(0,b.useMemo)(()=>jU(c??[]),[c]),w=(0,b.useMemo)(()=>(c??[]).flatMap(e=>e.antiPatterns??[]),[c]),T=Math.max(o?.toolCallCount??0,y),E=(a||l||s)&&!e&&v===0&&o===void 0,D=Math.max(e?.todayTotalUsd??0,o?.totalCostUsd??0,v,i?.sessionTodayUsd??0),O=Math.max(u?.length??0,t.length),k=Math.max(o?.antiPatternCount??0,S+O),A=Math.max(o?.subagentUsd??0,n.usd),j=Math.max(o?.subagentTurnCount??0,n.turns),M=o!==void 0||n.turns>0,N=o&&o.totalCostUsd>=D?o.totalCostUsd:D,ee=o&&o.totalCostUsd>=D?o.subagentUsd??0:A,[te,P]=(0,b.useState)(()=>new Date().toLocaleString(void 0,qH)),F=(0,b.useRef)(Date.now());(0,b.useEffect)(()=>{let e=setInterval(()=>{let e=Date.now();P(new Date(e).toLocaleString(void 0,qH)),GH(e,F.current)||(F.current=e,qn.getState().handleDayRollover())},6e4);return()=>clearInterval(e)},[]);let ne=o?.avgEfficiencyScore??null,re=ne!==null&&Number.isFinite(ne)?`${Math.round(ne*100)}%`:`—`,ie=ne===null?`needs more data`:Math.round(ne*100)>=80?`strong session`:Math.round(ne*100)>=50?`mixed signals`:`needs attention`;return(0,x.jsxs)(`section`,{children:[(0,x.jsx)(AH,{}),(0,x.jsxs)(`header`,{className:`flex items-baseline justify-between mb-4`,children:[(0,x.jsx)(`h1`,{className:`text-xl font-semibold gradient-text`,children:`Today`}),(0,x.jsx)(`span`,{className:`text-xs text-ink-muted`,children:te})]}),!E&&!s&&!l&&!d&&!p&&!h&&!_&&T===0&&D===0&&k===0?(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(cV,{index:0,className:`glass-card p-8 mb-4`,children:(0,x.jsx)($,{icon:`code`,title:`No activity yet today`,subtitle:`Metrics will appear here once you start a coding session with Claude.`})}),(0,x.jsx)(cV,{index:1,className:`mb-3`,children:(0,x.jsx)(iU,{})}),(0,x.jsx)(cV,{index:2,children:(0,x.jsx)(aU,{})}),(0,x.jsx)(cV,{index:3,children:(0,x.jsx)(_U,{})})]}):(0,x.jsxs)(x.Fragment,{children:[r?.watcherActive===!1&&A===0&&r?.watcherDisabledReason!==`mode_mismatch`&&(0,x.jsxs)(`div`,{className:`rounded-lg border border-border-subtle bg-surface-5 px-4 py-3 text-sm text-ink-muted mb-4`,children:[`Subagent cost tracking is disabled (`,(0,x.jsx)(`code`,{className:`font-mono text-xs`,children:`NR_AI_ENABLE_SUBAGENT_WATCHER=0`}),`), so spend shown here excludes subagents. Unset that variable (it is on by default) and restart to see full spend.`]}),(0,x.jsx)(cV,{index:0,className:`mb-4`,children:(0,x.jsx)(B,{padding:`lg`,tone:`elevated`,glow:`green`,children:(0,x.jsxs)(`div`,{className:`grid grid-cols-5 gap-4`,children:[(0,x.jsx)(sV,{label:`efficiency`,hero:!0,value:re,sub:ie,...ne===null?{}:{animate:!0,numericValue:Math.round(ne*100),suffix:`%`}}),(0,x.jsx)(sV,{label:`spend today`,tone:`good`,value:E?`…`:Ci(D),...E?{}:{animate:!0,numericValue:D,format:Ci}}),(0,x.jsx)(sV,{label:`subagent spend`,value:M?Ci(A):`—`,sub:`${j} turns`,...M?{animate:!0,numericValue:A,format:Ci}:{}}),(0,x.jsx)(sV,{label:`tool calls`,value:String(T),animate:!0,numericValue:T}),(0,x.jsx)(sV,{label:`flags`,tone:k>0?`warn`:`neutral`,value:String(k),animate:!0,numericValue:k})]})})}),(0,x.jsxs)(cV,{index:1,className:`grid grid-cols-2 gap-3 mb-3`,children:[(0,x.jsx)(MU,{todayTotal:N,forecastEod:E?null:e?.forecastEodUsd??o?.forecastEndOfDayUsd??i?.forecast?.forecastEndOfDayUsd??null,hourlySpend:C,subagentUsd:ee,forecastSessionEnd:i?.forecast?.forecastSessionEndUsd??null,forecastWeek:i?.forecast?.forecastEndOfWeekUsd??null,confidenceNote:i?.forecast?.confidenceNote??null}),f&&f.buckets&&(0,x.jsx)(xH,{current:f.current,peak:f.peak,allTimePeak:f.allTimePeak,bucketSizeMs:f.bucketSizeMs,startTimestamp:f.startTimestamp,buckets:f.buckets})]}),k>0&&(0,x.jsx)(cV,{index:2,className:`mb-3`,children:(0,x.jsx)(B,{padding:`sm`,tone:`warning`,className:`text-xs`,children:t.length>0?(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(ni,{tone:`warning`,size:`sm`,className:`mr-2`,children:t[0].type}),(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`— `}),(0,x.jsxs)(`span`,{children:[t[0].count,`× on `]}),(0,x.jsx)(`code`,{className:`bg-surface-5 px-1 rounded`,children:t[0].target}),t[0].sessionId&&(0,x.jsxs)(ni,{tone:`neutral`,size:`sm`,className:`ml-2`,children:[`Session: `,gU(t[0].sessionId,g??[])]})]}):u&&u.length>0?(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(ni,{tone:`warning`,size:`sm`,className:`mr-2`,children:u[0].type}),(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`— `}),(0,x.jsxs)(`span`,{children:[u[0].count??u[0].iterations??u[0].readCount??u[0].repeatCount??u[0].editCount??u[0].agentCount??`?`,`× on`,` `]}),(0,x.jsx)(`code`,{className:`bg-surface-5 px-1 rounded`,children:u[0].file??u[0].command??`unknown`})]}):w.length>0?(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(ni,{tone:`warning`,size:`sm`,className:`mr-2`,children:w[0].type}),(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`— `}),(0,x.jsxs)(`span`,{children:[w[0].count??w[0].iterations??w[0].readCount??w[0].repeatCount??w[0].editCount??w[0].agentCount??`?`,`× on`,` `]}),(0,x.jsx)(`code`,{className:`bg-surface-5 px-1 rounded`,children:w[0].file??w[0].command??`unknown`})]}):(0,x.jsxs)(`span`,{children:[k,` flag(s) detected today — details unavailable.`]})})}),(0,x.jsxs)(cV,{index:3,className:`grid grid-cols-3 gap-3 mb-3`,children:[(0,x.jsx)(oU,{}),(0,x.jsx)(sU,{}),(0,x.jsx)(cU,{}),(0,x.jsx)(lU,{aggregate:o}),(0,x.jsx)(pU,{liveSessions:g??[]}),(0,x.jsx)(uU,{}),(0,x.jsx)(fU,{aggregate:o}),(0,x.jsx)(`div`,{className:`col-span-3`,children:(0,x.jsx)(iU,{})}),(0,x.jsx)(`div`,{className:`col-span-3`,children:(0,x.jsx)(aU,{})})]}),(0,x.jsx)(cV,{index:4,children:(0,x.jsx)(hU,{sessions:c??[],liveSessions:g??[]})}),m&&m.buckets?.length>0&&(0,x.jsx)(cV,{index:5,className:`mb-3`,children:(0,x.jsxs)(B,{padding:`sm`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-1.5 mb-2`,children:[(0,x.jsx)(V,{children:`Activity Today`}),(0,x.jsx)(ui,{text:`Tool-call activity in 15-minute blocks across today. Darker blocks mean more calls in that window.`})]}),(0,x.jsx)(EH,{variant:`strip`,buckets:m.buckets,maxCount:m.maxCount,bucketSizeMs:m.bucketSizeMs,startTimestamp:m.startTimestamp,ariaLabel:`Today's activity density in 15-minute blocks`})]})}),(0,x.jsx)(cV,{index:6,children:(0,x.jsx)(_U,{})})]})]})}function iU(){let{data:e,isError:t}=L({queryKey:z.costPerTool,queryFn:()=>Fr(),refetchInterval:ZH,retry:!1}),n=e?.costByToolType?Object.entries(e.costByToolType).filter(([,e])=>e.totalCost>0).sort((e,t)=>t[1].totalCost-e[1].totalCost).map(([e,t])=>({tool:e,totalCost:t.totalCost,callCount:t.callCount})):[],r=e!=null&&(e.attributionRate??1)<.5;return t?(0,x.jsxs)(B,{padding:`sm`,className:`h-full`,children:[(0,x.jsx)(V,{className:`mb-2`,children:`Cost by Tool`}),(0,x.jsx)($,{icon:`radar`,title:`Cost attribution unavailable`,subtitle:`Start a Claude Code session to enable cost attribution.`})]}):e?(0,x.jsxs)(B,{padding:`sm`,className:`h-full`,children:[(0,x.jsx)(V,{className:`mb-2`,children:`Cost by Tool`}),n.length===0?(0,x.jsx)($,{icon:`radar`,title:`No cost data yet`,subtitle:`Cost attribution appears after token data is recorded.`}):(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(`div`,{className:`min-w-0`,style:{height:`${Math.max(96,n.length*28+24)}px`},children:(0,x.jsx)(np,{width:`100%`,height:`100%`,minWidth:1,minHeight:1,children:(0,x.jsxs)(tV,{data:n,layout:`vertical`,children:[(0,x.jsx)(hI,{stroke:$H,strokeDasharray:`3 3`}),(0,x.jsx)(YR,{type:`number`,tick:QH,stroke:$H,unit:`$`}),(0,x.jsx)(uz,{type:`category`,dataKey:`tool`,tick:QH,tickFormatter:e=>{let t=n.find(t=>t.tool===e),r=Ei(e);return t?`${r} (${t.callCount})`:r},stroke:$H,width:90,interval:0}),(0,x.jsx)(Yk,{contentStyle:eU,itemStyle:tU,labelFormatter:e=>Ei(String(e))}),(0,x.jsx)(OR,{dataKey:`totalCost`,name:`Cost ($)`,radius:[0,3,3,0],children:n.map(e=>(0,x.jsx)(Xk,{fill:nU(Ei(e.tool)),fillOpacity:.8},e.tool))})]})})}),r&&(0,x.jsxs)(`div`,{className:`text-[10px] text-ink-muted italic mt-1`,children:[`Based on `,Math.round((e.attributionRate??0)*100),`% of session cost`]})]})]}):(0,x.jsxs)(B,{padding:`sm`,className:`h-full`,children:[(0,x.jsx)(V,{className:`mb-2`,children:`Cost by Tool`}),(0,x.jsx)($,{icon:`radar`,title:`No cost data yet`,subtitle:`Cost attribution appears after token data is recorded.`})]})}function aU(){let{data:e,isError:t}=L({queryKey:z.costPerTool,queryFn:()=>Fr(),refetchInterval:ZH,retry:!1});if(t||!e||!e.costBySkill)return null;let n=Object.entries(e.costBySkill).sort((e,t)=>t[1].totalCost-e[1].totalCost||t[1].callCount-e[1].callCount).slice(0,10);if(n.length===0)return null;let r=(e.attributionRate??1)<.5;return(0,x.jsxs)(B,{padding:`sm`,className:`h-full`,children:[(0,x.jsx)(V,{className:`mb-2`,children:`Cost by Skill`}),(0,x.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,x.jsx)(`thead`,{children:(0,x.jsxs)(`tr`,{className:`border-b border-border-subtle text-ink-muted`,children:[(0,x.jsx)(`th`,{className:`text-left py-1.5 px-1`,children:`Skill`}),(0,x.jsx)(`th`,{className:`text-right py-1.5 px-1`,children:`Calls`}),(0,x.jsx)(`th`,{className:`text-right py-1.5 px-1`,children:`Cost`}),(0,x.jsx)(`th`,{className:`text-right py-1.5 px-1`,children:`Tokens`}),(0,x.jsx)(`th`,{className:`text-right py-1.5 px-1`,children:`Time`})]})}),(0,x.jsx)(`tbody`,{children:n.map(([e,t])=>(0,x.jsxs)(`tr`,{className:`border-b border-border-subtle hover:bg-surface-5`,children:[(0,x.jsx)(`td`,{className:`py-1.5 px-1 text-ink-base font-mono text-xs`,children:e}),(0,x.jsx)(`td`,{className:`text-right py-1.5 px-1 text-ink-subtle`,children:t.callCount}),(0,x.jsx)(`td`,{className:`text-right py-1.5 px-1 text-ink-base`,title:t.attributedCallCount<t.callCount?`Cost covers ${t.attributedCallCount} of ${t.callCount} calls`:void 0,children:Ci(t.totalCost)}),(0,x.jsx)(`td`,{className:`text-right py-1.5 px-1 text-ink-subtle`,children:Ti(t.inputTokens+t.outputTokens+t.cacheReadTokens)}),(0,x.jsx)(`td`,{className:`text-right py-1.5 px-1 text-ink-subtle`,children:xi(t.totalDurationMs)})]},e))})]}),r&&(0,x.jsxs)(`div`,{className:`text-[10px] text-ink-muted italic mt-1`,children:[`Based on `,Math.round((e.attributionRate??0)*100),`% of session cost`]})]})}function oU(){let{data:e}=L({queryKey:z.qualityProxy,queryFn:Cr,refetchInterval:ZH});return(0,x.jsxs)(B,{padding:`sm`,className:`h-full`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-1.5 mb-2`,children:[(0,x.jsx)(V,{children:`Quality`}),(0,x.jsx)(ui,{text:`Diff apply rate and test pass rate across today's sessions, plus how often you backtracked or self-corrected. Watch for the degrading flag if quality drops mid-session.`})]}),!e||e.totalSignals===0?(0,x.jsx)($,{icon:`checkmark`,title:`Waiting for edits and test runs`,subtitle:`Quality metrics appear after editing files and running tests.`}):(0,x.jsxs)(x.Fragment,{children:[(0,x.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 text-xs`,children:[(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`Diff Apply `}),(0,x.jsx)(`span`,{className:gi(e.diffApplyRate),children:e.diffApplyRate===null?`—`:`${(e.diffApplyRate*100).toFixed(0)}%`})]}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`Test Pass `}),(0,x.jsx)(`span`,{className:gi(e.testPassRate),children:e.testPassRate===null?`—`:`${(e.testPassRate*100).toFixed(0)}%`})]}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`Backtracks `}),(0,x.jsx)(`span`,{className:e.backtrackCount>0?`text-accent-amber`:``,children:e.backtrackCount})]}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`Self-corrections `}),(0,x.jsx)(`span`,{className:`text-ink-subtle`,children:e.selfCorrectionCount})]})]}),e.degradationDetected&&(0,x.jsx)(`div`,{className:`text-accent-amber text-xs mt-2`,children:`⚠ Quality degrading`})]})]})}function sU(){let{data:e}=L({queryKey:z.apiFailures,queryFn:Wr,refetchInterval:ZH}),t=e?.byErrorType?Object.entries(e.byErrorType).filter(([,e])=>e>0):[],n=e?.throttleAlerts??[];return(0,x.jsxs)(B,{padding:`sm`,className:`h-full`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-1.5 mb-2`,children:[(0,x.jsx)(V,{children:`API Failures`}),(0,x.jsx)(ui,{text:`Turns that failed outright after Claude Code's own retries were exhausted, captured via its StopFailure hook.`})]}),!e||e.totalFailures===0?(0,x.jsx)($,{icon:`radar`,title:`No API failures`,subtitle:`Reflects Claude Code's own StopFailure hook, not proxy-mode traffic.`}):(0,x.jsxs)(x.Fragment,{children:[(0,x.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 text-xs`,children:[(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`Total `}),(0,x.jsx)(`span`,{className:`text-accent-amber`,children:e.totalFailures})]}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`Throttle alerts `}),(0,x.jsx)(`span`,{className:n.length>0?`text-accent-amber`:``,children:n.length})]})]}),t.length>0&&(0,x.jsx)(`div`,{className:`text-[10px] text-ink-subtle mt-1`,children:t.map(([e,t])=>`${e}: ${t}`).join(`, `)}),n.length>0&&(0,x.jsx)(`div`,{className:`text-accent-amber text-xs mt-2`,children:`⚠ Rate-limit throttling detected`})]})]})}function cU(){let{data:e}=L({queryKey:z.toolSelectionScore,queryFn:wr,refetchInterval:ZH});return(0,x.jsxs)(B,{padding:`sm`,className:`h-full`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-1.5 mb-2`,children:[(0,x.jsx)(V,{children:`Tool Selection`}),(0,x.jsx)(ui,{text:`Scores how efficiently tools were chosen today: penalizes re-reading a file without editing it, retrying a failing call, or fetching output that's never used.`})]}),!e||Array.isArray(e)||e.totalCalls===0?(0,x.jsx)($,{icon:`radar`,title:`Waiting for tool calls`,subtitle:`Start a Claude Code session to begin scoring. Reflects today's activity across all sessions.`}):(0,x.jsxs)(x.Fragment,{children:[(0,x.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,x.jsx)(`span`,{className:`text-2xl font-semibold tabular-nums ${_i(e.score)}`,children:e.score.toFixed(2)}),(0,x.jsx)(`span`,{className:`text-[10px] text-ink-muted`,children:`/ 1.0`})]}),(0,x.jsxs)(`div`,{className:`text-[10px] text-ink-muted mt-1`,children:[e.penalizedCalls,` of `,e.totalCalls,` calls penalized`]}),(e.redundantReadCount>0||e.repeatedFailureCount>0||e.unusedOutputCount>0)&&(0,x.jsxs)(`div`,{className:`text-[10px] text-ink-subtle mt-1 space-x-2`,children:[e.redundantReadCount>0&&(0,x.jsxs)(`span`,{children:[`re-reads: `,e.redundantReadCount]}),e.repeatedFailureCount>0&&(0,x.jsxs)(`span`,{children:[`repeat fails: `,e.repeatedFailureCount]}),e.unusedOutputCount>0&&(0,x.jsxs)(`span`,{children:[`unused output: `,e.unusedOutputCount]})]}),(0,x.jsx)(`div`,{className:`text-[10px] text-ink-subtle/60 mt-2`,children:`Penalizes: reading the same file 3+ times without editing, repeated tool failures, fetching large outputs never referenced.`})]})]})}function lU({aggregate:e}){let t=e?.latency,n=t?.byTool?Object.entries(t.byTool).filter(e=>e[1]!==null&&e[1].count>0).sort((e,t)=>t[1].p95-e[1].p95).slice(0,4):[];return(0,x.jsxs)(B,{padding:`sm`,className:`h-full`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-1.5 mb-2`,children:[(0,x.jsx)(V,{children:`Latency (ms)`}),(0,x.jsx)(ui,{text:`How long tool calls took today — p50/p95/p99 across all calls, plus the slowest tools by p95.`})]}),!t||!t.overall?(0,x.jsx)($,{icon:`clock`,title:`Waiting for tool calls`,subtitle:`Latency percentiles appear after tool calls complete.`}):(0,x.jsxs)(x.Fragment,{children:[(0,x.jsxs)(`div`,{className:`flex gap-4 text-xs mb-2`,children:[(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`p50 `}),(0,x.jsx)(`span`,{className:`text-ink-base tabular-nums`,children:t.overall.p50})]}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`p95 `}),(0,x.jsx)(`span`,{className:`text-ink-base tabular-nums`,children:t.overall.p95})]}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`p99 `}),(0,x.jsx)(`span`,{className:`text-ink-base tabular-nums`,children:t.overall.p99})]})]}),n.length>0&&(0,x.jsx)(`div`,{className:`space-y-1`,children:n.map(([e,t])=>(0,x.jsxs)(`div`,{className:`flex items-center gap-2 text-xs`,children:[(0,x.jsx)(`span`,{className:`text-ink-muted truncate w-28 shrink-0`,children:Ei(e)}),(0,x.jsxs)(`span`,{className:`tabular-nums text-ink-subtle`,children:[t.p95,`ms p95`]})]},e))})]})]})}function uU(){let{data:e}=L({queryKey:z.modelUsage,queryFn:Nr,refetchInterval:ZH}),t=e?.byModel?Object.entries(e.byModel).filter(([,e])=>e.requestCount>0).sort((e,t)=>t[1].totalCostUsd-e[1].totalCostUsd).slice(0,4):[];return(0,x.jsxs)(B,{padding:`sm`,className:`h-full`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-1.5 mb-2`,children:[(0,x.jsx)(V,{children:`Model Usage`}),(0,x.jsx)(ui,{text:`Cost and request volume per model used today, combining this server's live usage with every other session's saved totals. $/1M tok counts every billed token, cache reads and cache writes included, so it is comparable with list prices. The live slice resets if the server process restarts.`})]}),!e||t.length===0?(0,x.jsx)($,{icon:`radar`,title:`No model data yet`,subtitle:`Start a Claude Code session to see model cost breakdown. Resets when the process restarts.`}):(0,x.jsx)(`div`,{className:`space-y-1.5`,children:t.map(([e,t])=>(0,x.jsxs)(`div`,{className:`flex items-center justify-between text-xs gap-2`,children:[(0,x.jsx)(`span`,{className:`text-ink-muted truncate`,children:e}),(0,x.jsxs)(`div`,{className:`flex gap-3 shrink-0 tabular-nums`,children:[(0,x.jsxs)(`span`,{className:`text-ink-subtle`,children:[t.requestCount,`req`]}),(0,x.jsxs)(`span`,{className:`text-ink-subtle`,children:[wi(t.costPerMillionTokens),`/1M tok`]}),(0,x.jsx)(`span`,{className:`text-ink-base`,children:Ci(t.totalCostUsd)})]})]},e))})]})}function dU(e,t){let n=t===null?null:`${t}%`;return e===`excellent`?n?`Cache hit rate is ${n}. Cache is well-structured.`:`Cache is well-structured. No changes needed.`:e===`can_improve`?n?`Cache hit rate is ${n}. Placing stable content before variable content in prompts could improve this.`:`Place stable content before variable content in prompts to improve.`:n?`Cache hit rate is ${n}. Restructuring your system prompt so stable context appears at the top could bring this above 60%.`:`Restructure your system prompt so stable context appears at the top.`}function fU({aggregate:e}){let{data:t}=L({queryKey:z.cacheHealth,queryFn:Pr,refetchInterval:ZH}),n=e?.cacheHealth,r=!n||n.status===`no_cache_activity`||n.cacheHitRatePct==null;return(0,x.jsxs)(B,{padding:`sm`,className:`h-full`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-1.5 mb-2`,children:[(0,x.jsx)(V,{children:`Cache Health`}),(0,x.jsx)(ui,{text:`Prompt cache hit rate today, with a suggestion for improving it — usually by moving stable context earlier in the prompt.`})]}),r?(0,x.jsx)($,{icon:`radar`,title:`No cache data yet`,subtitle:`Appears once token usage with cache reads is reported.`}):(0,x.jsxs)(x.Fragment,{children:[(0,x.jsxs)(`div`,{className:`flex items-baseline gap-2 mb-1`,children:[(0,x.jsxs)(`span`,{className:`text-2xl font-semibold tabular-nums ${n.status===`excellent`?`text-accent-green`:n.status===`needs_attention`?`text-accent-amber`:`text-ink-base`}`,children:[n.cacheHitRatePct,`%`]}),(0,x.jsx)(ni,{tone:n.status===`needs_attention`?`warning`:`neutral`,size:`sm`,children:n.status===`excellent`?`excellent`:n.status.replace(`_`,` `)})]}),n.totalSavingsUsd>0&&(0,x.jsxs)(`div`,{className:`text-xs text-accent-green mb-1`,children:[`$`,n.totalSavingsUsd.toFixed(4),` saved`]}),t?.week_over_week_delta_pts!=null&&t.week_over_week_delta_pts!==0&&(0,x.jsxs)(`div`,{className:`text-[10px] font-medium mb-1 ${t.week_over_week_delta_pts>0?`text-accent-green`:`text-accent-amber`}`,children:[t.week_over_week_delta_pts>0?`↑`:`↓`,Math.abs(t.week_over_week_delta_pts),`pts vs last week`]}),(0,x.jsx)(`div`,{className:`text-[10px] text-ink-subtle/70 leading-snug`,children:dU(n.status,n.cacheHitRatePct)})]})]})}function pU({liveSessions:e}){let{data:t,isPending:n}=L({queryKey:z.computeWaste,queryFn:cr,retry:!1}),r=qn(e=>e.retryAlerts);if(n||!t||typeof t.total_tokens_wasted!=`number`)return null;let i=r[r.length-1]??null,a=t.by_session?.[0]??null,o=t.status===`clean`?`text-accent-green`:t.status===`moderate`?`text-accent-amber`:`text-accent-red`,s=t.status===`clean`?`clean`:t.status===`moderate`?`moderate`:`needs attention`,c=t.breakdown[0]??null;return(0,x.jsxs)(B,{padding:`sm`,className:`h-full`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-1.5 mb-2`,children:[(0,x.jsx)(V,{children:`Compute Waste`}),(0,x.jsx)(ui,{text:`Tokens wasted today on retried tool calls and anti-pattern activity (stuck loops, redundant reads, thrashing).`})]}),(0,x.jsxs)(`div`,{className:`text-lg font-semibold tabular-nums ${o}`,children:[`~`,t.total_tokens_wasted.toLocaleString(),` wasted tokens`]}),(0,x.jsx)(ni,{tone:t.status===`clean`?`success`:t.status===`moderate`?`warning`:`danger`,size:`sm`,className:`mt-1`,children:s}),(0,x.jsxs)(`div`,{className:`text-xs text-ink-muted mt-1`,children:[`retry: ~`,t.retry_tokens_wasted.toLocaleString(),` · anti-pattern: ~`,t.anti_pattern_tokens_wasted.toLocaleString()]}),a!==null&&(0,x.jsxs)(`div`,{className:`text-[10px] text-ink-subtle/70 mt-0.5`,children:[`top session: `,gU(a.session_id,e),` (~`,a.tokens_wasted.toLocaleString(),`)`]}),c!==null&&(0,x.jsxs)(`div`,{className:`text-[10px] font-medium text-accent-amber mb-1`,children:[c.type.replace(/_/g,` `),` · ~`,c.tokens_wasted.toLocaleString(),` `,`tokens`]}),i!==null&&(0,x.jsxs)(`div`,{className:`text-[10px] mb-1`,children:[(0,x.jsx)(ni,{tone:`warning`,size:`sm`,className:`mr-1`,children:i.toolName}),(0,x.jsxs)(`span`,{className:`text-ink-muted`,children:[`retried `,i.occurrences,`× `]}),i.sessionId&&(0,x.jsxs)(ni,{tone:`neutral`,size:`sm`,className:`ml-1`,children:[`Session: `,gU(i.sessionId,e)]})]}),(0,x.jsx)(`div`,{className:`text-[10px] text-ink-subtle/70 leading-snug`,children:XH(t.status,c?.type??null)})]})}var mU=3e3;function hU({sessions:e,liveSessions:t}){let[n,r]=(0,b.useState)(null),[i,a]=(0,b.useState)(null),[o,s]=(0,b.useState)(!1),[,c]=Wt(),l=qn(e=>e.setActiveSession),{data:u}=L({queryKey:z.sessionCurrent,queryFn:tr}),d=(0,b.useMemo)(()=>{let e=new Set;for(let n of t)e.add(n.sessionId);if(e.size===0){if(u?.liveSessions?.length)for(let t of u.liveSessions)e.add(t);else u?.sessionId&&e.add(u.sessionId)}return e},[t,u]),f=(t.length>0?t[0].sessionId:null)??(d.size>0?[...d][0]:null),p=n??f,m=p!==null&&d.has(p),h=n!==null&&!d.has(n);(0,b.useEffect)(()=>{l(p)},[p,l]);let{data:g}=L({queryKey:p?z.sessionReplay(p):[`replay`,`none`],queryFn:()=>br(p),enabled:p!==null,retry:!1,refetchInterval:m?mU:!1}),{data:_}=L({queryKey:p?z.sessionSubagents(p):[`subagents`,`none`],queryFn:()=>xr(p),enabled:p!==null,retry:!1,refetchInterval:m?mU:!1}),{data:v}=L({queryKey:z.workflows,queryFn:Vr,refetchInterval:m?1e4:!1}),{data:y}=L({queryKey:p?[`turn-costs`,p]:[`turn-costs`],queryFn:()=>ur(p??void 0),refetchInterval:1e4}),{data:S}=L({queryKey:p?[`decision-tree`,p]:[`decision-tree`],queryFn:()=>lr(p??void 0),refetchInterval:1e4}),{data:C}=L({queryKey:p?[`context`,p]:z.context,queryFn:()=>Ar(p??void 0),refetchInterval:1e4,enabled:m&&!!p}),{data:w}=L({queryKey:[`context-composition`],queryFn:jr,refetchInterval:1e4}),{data:T}=L({queryKey:[`context-efficiency`],queryFn:Mr,refetchInterval:1e4}),E=(0,b.useRef)(null);(0,b.useEffect)(()=>{m&&E.current&&(E.current.scrollTop=E.current.scrollHeight)},[g?.timeline.length,m]);let D=(0,b.useMemo)(()=>{let n=Date.now()-216e5,r=new Map;for(let e of t)r.set(e.sessionId,e);let i=new Map;for(let t of e){if(!t.sessionId)continue;let e=t.startTime!=null&&yU(t.startTime),a=r.has(t.sessionId),o=t.startTime!=null&&t.durationMs!=null?t.startTime+t.durationMs:null,s=o!=null&&o>=n&&yU(o);(e||a||s)&&i.set(t.sessionId,t)}for(let e of t)e.sessionId&&(i.has(e.sessionId)||i.set(e.sessionId,{sessionId:e.sessionId,sessionName:e.sessionName,startTime:e.startTime,toolCallCount:0,estimatedCostUsd:null}));let a=e=>{let t=r.get(e.sessionId);return t?t.lastActivity:e.startTime!=null&&e.durationMs!=null?e.startTime+e.durationMs:e.startTime??0};return[...i.values()].sort((e,t)=>a(t)-a(e)).slice(0,10)},[e,t]),O=(0,b.useMemo)(()=>g?.timeline??[],[g]),k=(0,b.useMemo)(()=>Array.isArray(_?.agents)?_.agents:[],[_]),A=(0,b.useMemo)(()=>{let e=null,t=null;for(let n of O){let r=n.timestamp+(n.durationMs??50);(e===null||n.timestamp<e)&&(e=n.timestamp),(t===null||r>t)&&(t=r)}let n=(_?.agents?.length??0)>0?_.window:null;return n&&(e=e===null?n.startMs:Math.min(e,n.startMs),t=t===null?n.endMs:Math.max(t,n.endMs)),e===null||t===null?{startMs:0,endMs:1}:{startMs:e,endMs:t>e?t:e+1}},[O,_]),j=(0,b.useMemo)(()=>{let e={};if(Array.isArray(v))for(let t of v)t&&typeof t.runId==`string`&&typeof t.status==`string`&&t.parentSessionId===p&&(e[t.runId]=t.status);return e},[v,p]);return(0,x.jsxs)(x.Fragment,{children:[(0,x.jsxs)(`div`,{className:`glass-card mb-3 grid grid-cols-[220px_1fr] overflow-hidden`,style:{height:`320px`},children:[(0,x.jsxs)(`div`,{className:`border-r border-border-subtle flex flex-col overflow-hidden`,children:[(0,x.jsxs)(`div`,{className:`flex items-center justify-between gap-1.5 p-2 border-b border-border-subtle shrink-0`,children:[(0,x.jsx)(V,{children:`Session Live Tail`}),(0,x.jsx)(ui,{text:`Today's sessions on the left; select one to stream its live tool-call trace on the right.`})]}),(0,x.jsxs)(`div`,{className:`overflow-auto flex-1`,children:[D.map(e=>{let t=d.has(e.sessionId);return(0,x.jsxs)(`button`,{type:`button`,onClick:()=>r(e.sessionId),className:`block w-full text-left p-2 border-b border-border-subtle text-xs transition-colors duration-150 hover:bg-surface-5 `+(p===e.sessionId?`bg-surface-5`:``),children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,x.jsx)(`span`,{className:`font-mono text-ink-base`,children:e.sessionName||e.sessionId.slice(0,8)}),t?(0,x.jsx)(ii,{label:`live`,size:`sm`}):(0,x.jsx)(`span`,{className:`text-[10px] text-ink-muted`,title:e.startTime?`Started ${yi(e.startTime)}`:void 0,children:e.startTime?yi(e.startTime+(e.durationMs??0)):``})]}),(0,x.jsxs)(`div`,{className:`flex gap-2 mt-0.5 text-[10px] text-ink-subtle`,children:[(0,x.jsxs)(`span`,{children:[e.toolCallCount??0,` calls`]}),e.estimatedCostUsd!=null&&e.estimatedCostUsd>0?(0,x.jsx)(`span`,{children:Ci(e.estimatedCostUsd)}):(0,x.jsx)(`span`,{children:`—`})]})]},e.sessionId)}),d.size===0&&D.length===0&&(0,x.jsx)($,{icon:`code`,title:`No sessions today`,subtitle:`Start coding with Claude to see sessions here.`})]})]}),(0,x.jsxs)(`div`,{className:`flex flex-col overflow-hidden`,children:[p&&(0,x.jsxs)(`div`,{className:`flex items-center justify-between px-2 py-1 border-b border-border-subtle shrink-0`,children:[(0,x.jsx)(V,{children:`Trace`}),(0,x.jsxs)(`div`,{className:`flex items-center gap-2`,children:[h&&(0,x.jsx)(`span`,{"data-testid":`session-ended-badge`,children:(0,x.jsx)(ni,{tone:`neutral`,size:`sm`,uppercase:!0,children:`Session ended`})}),(0,x.jsx)(`button`,{type:`button`,onClick:()=>c(`/sessions?id=${p}`),className:`text-[10px] text-accent-cyan hover:underline transition-colors duration-150`,children:`full session →`})]})]}),(0,x.jsxs)(`div`,{ref:E,className:`overflow-auto flex-1 p-2`,children:[!p&&(0,x.jsx)(`div`,{className:`text-ink-muted text-xs p-2`,children:`Select a session to view its timeline.`}),p&&O.length===0&&k.length===0&&(0,x.jsx)($,{icon:`timeline`,title:m?`Waiting for tool calls`:`No tool calls`,subtitle:m?`Tool calls will appear here in real time.`:`This session has no recorded tool calls.`}),p&&(O.length>0||k.length>0)&&(0,x.jsx)(PV,{sessionId:p,parentEntries:O,agents:k,window:A,runStatusById:j,parentSegments:g?.segments??[],onSelectRun:e=>a(e)},p)]}),m&&p&&(0,x.jsx)(`div`,{className:`border-t border-bg-line px-3 py-2 shrink-0`,children:(0,x.jsx)(gH,{sessionId:p,expandable:!1})}),((S?.totalBranches??0)>0||(y?.turns?.length??0)>0||(C?.history?.length??0)>=2)&&(0,x.jsx)(`div`,{className:`border-t border-bg-line px-3 py-2 shrink-0`,children:(0,x.jsx)(`button`,{type:`button`,onClick:()=>s(!0),className:`text-[10px] text-accent-cyan hover:underline transition-colors duration-150 text-left`,children:(()=>{let e=[];return S&&S.totalBranches>0&&e.push(`${S.longestFailureStreak} failure streak`),y?.turns&&y.turns.length>0&&e.push(`${y.turns.length} turns · $${y.totalAttributedCost.toFixed(2)}`),e.length>0?`${e.join(` · `)} — session detail →`:`session detail →`})()})})]})]}),i!=null&&(0,x.jsx)(iH,{runId:i,onClose:()=>a(null)}),o&&(0,x.jsx)(vH,{decisionTree:S,turnCosts:y,contextHistory:C?.history,contextWindow:C?.contextWindow,contextComposition:w,contextEfficiency:T,onClose:()=>s(!1)})]})}function gU(e,t){let n=t.find(t=>t.sessionId===e);return n?.sessionName?n.sessionName:e.slice(0,8)}function _U(){let{data:e,isLoading:t,error:n}=L({queryKey:z.alertsRecent,queryFn:async()=>{try{return await yr()}catch(e){if(e instanceof $n)return null;throw e}},refetchInterval:JH,retry:!1});if(e===null)return null;let r=[...e??[]].sort((e,t)=>t.firedAt-e.firedAt);return(0,x.jsxs)(B,{padding:`sm`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-1.5 mb-2`,children:[(0,x.jsx)(V,{children:`Recent Alerts`}),(0,x.jsx)(ui,{text:`The most recent alert firings and resolutions from your configured alert rules, newest first.`})]}),t&&(0,x.jsx)($,{variant:`loading`,title:`Loading...`}),n&&(0,x.jsx)(`div`,{className:`text-accent-red text-xs`,children:`Error loading recent alerts.`}),!t&&!n&&r.length===0&&(0,x.jsx)(`div`,{className:`text-ink-muted text-xs`,children:`No alerts in recent history.`}),!t&&!n&&r.length>0&&(0,x.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,x.jsx)(`thead`,{className:`text-ink-muted`,children:(0,x.jsxs)(`tr`,{children:[(0,x.jsx)(`th`,{className:`text-left pb-1`,children:`when`}),(0,x.jsx)(`th`,{className:`text-left pb-1`,children:`sev`}),(0,x.jsx)(`th`,{className:`text-left pb-1`,children:`rule`}),(0,x.jsx)(`th`,{className:`text-right pb-1`,children:`value / threshold`}),(0,x.jsx)(`th`,{className:`text-left pb-1 pl-2`,children:`state`})]})}),(0,x.jsx)(`tbody`,{children:r.slice(0,50).map(e=>(0,x.jsxs)(`tr`,{className:`border-t border-border-subtle`,children:[(0,x.jsx)(`td`,{className:`py-1 text-ink-subtle tabular-nums whitespace-nowrap`,children:vU(e.firedAt)}),(0,x.jsxs)(`td`,{className:`py-1`,children:[(0,x.jsx)(`span`,{"aria-hidden":`true`,className:YH[e.severity],children:`●`}),` `,(0,x.jsx)(`span`,{className:`text-ink-subtle uppercase tracking-wider text-[10px]`,children:e.severity})]}),(0,x.jsx)(`td`,{className:`py-1`,children:e.title}),(0,x.jsxs)(`td`,{className:`py-1 text-right tabular-nums`,children:[Si(e.value),` / `,Si(e.threshold)]}),(0,x.jsx)(`td`,{className:`py-1 pl-2 `+(e.state===`firing`?`text-accent-amber`:`text-ink-muted`),children:e.state})]},`${e.id}-${e.firedAt}-${e.state}`))})]})]})}function vU(e){let t=Math.max(0,Date.now()-e),n=Math.floor(t/6e4);if(n<1)return`just now`;if(n<60)return`${n}m ago`;let r=Math.floor(n/60);return r<24?`${r}h ago`:`${Math.floor(r/24)}d ago`}var yU=e=>GH(e);function bU(e){if(e.startTime==null)return 0;let t=typeof e.endTime==`number`?e.endTime:typeof e.durationMs==`number`?e.startTime+e.durationMs:Date.now();return KH({startTime:e.startTime,endTime:t})}function xU(e){let t=e.estimatedCostUsd;return t==null||t<=0?0:t*bU(e)}function SU(e){let t=0;for(let n of e)t+=xU(n);return t}function CU(e){let t=0;for(let n of e){let e=bU(n);e>0&&(t+=(n.toolCallCount??0)*e)}return Math.round(t)}function wU(e){let t=0;for(let n of e){let e=bU(n);e>0&&(t+=(n.antiPatterns?.length??0)*e)}return Math.round(t)}var TU=[.01,.02,.05,.1,.25,.5,1,2,5,10,25,50,100,250,500,1e3],EU=5;function DU(e){if(e<=0)return .01;for(let t of TU)if(t>=e)return t;return TU[TU.length-1]}function OU(e){return e===0?`12am`:e<12?`${e}am`:e===12?`12pm`:`${e-12}pm`}function kU(e){let t=e.reduce((e,t)=>e+t.cost,0),n=e.reduce((e,t)=>Math.max(e,t.cost),0),r=e.find(e=>e.cost===n);return r===void 0||n===0?`Hourly spend today: no activity yet.`:`Hourly spend today: ${Ci(t)} total, peak ${Ci(n)} at ${OU(r.hour)}`}function AU(e){let t=e.reduce((e,t)=>Math.max(e,t.cost),0),n=DU(t/EU);return e.map(e=>({count:Math.max(0,Math.round(e.cost/n)),tooltip:`${OU(e.hour)}: ${Ci(e.cost)} (start hour)`,isPeak:t>0&&e.cost===t}))}function jU(e){let t=Array(24).fill(0),n=WH(),r=n+864e5;for(let i of e){if(!i.startTime||i.estimatedCostUsd==null||i.estimatedCostUsd<=0)continue;let e=i.startTime,a=typeof i.endTime==`number`?i.endTime:typeof i.durationMs==`number`?i.startTime+i.durationMs:Date.now(),o=Math.max(e,n),s=Math.min(a,r);if(s<=o)continue;let c=Math.max(1,a-e),l=s-o,u=i.estimatedCostUsd*(l/c),d=o;for(;d<s;){let e=new Date(d),n=e.getHours(),r=new Date(e);r.setMinutes(0,0,0),r.setHours(n+1);let i=Math.min(s,r.getTime()),a=i-d;t[n]+=a/l*u,d=i}}return t.map((e,t)=>({hour:t,cost:e}))}function MU({todayTotal:e,forecastEod:t,hourlySpend:n,subagentUsd:r=0,forecastSessionEnd:i,forecastWeek:a,confidenceNote:o}){let s=t!==null&&Number.isFinite(t),c=s?Math.max(t,e):0,l=s?c-e:0,u=s&&e>0?l/e*100:0,d=n.some(e=>e.cost>0),f=r>0?Math.max(0,e-r):0;return(0,x.jsxs)(B,{padding:`sm`,className:`mb-3 h-full`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-1.5 mb-1.5`,children:[(0,x.jsx)(V,{children:`Forecast · End of Day`}),(0,x.jsx)(ui,{text:`Projects today's total spend by midnight, based on the spending trend so far this hour-by-hour.`})]}),s?(0,x.jsxs)(x.Fragment,{children:[(0,x.jsxs)(`div`,{className:`flex items-baseline gap-3`,children:[(0,x.jsx)(`span`,{className:`text-lg font-semibold text-accent-cyan tabular-nums`,children:Ci(c)}),(0,x.jsx)(`span`,{className:`text-xs text-ink-muted tabular-nums`,children:l>0?(0,x.jsxs)(x.Fragment,{children:[`+`,Ci(l),e>0&&` (+${u.toFixed(0)}%)`,` from now`]}):(0,x.jsx)(x.Fragment,{children:`on pace`})})]}),d&&(0,x.jsxs)(`div`,{className:`mt-2`,children:[(0,x.jsx)(pV,{data:AU(n),ariaLabel:kU(n)}),r>0&&(0,x.jsxs)(`div`,{className:`flex gap-3 mt-1 text-[10px] text-ink-muted tabular-nums`,children:[(0,x.jsxs)(`span`,{children:[`parent `,Ci(f)]}),(0,x.jsx)(`span`,{className:`text-ink-subtle`,children:`·`}),(0,x.jsxs)(`span`,{children:[`subagent `,Ci(r)]})]})]}),(i!==null||a!==null)&&(0,x.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-3 mt-2 pt-2 border-t border-border-subtle text-xs`,children:[i!==null&&(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`div`,{className:`text-ink-muted`,children:`End of session`}),(0,x.jsxs)(`div`,{className:`font-mono tabular-nums`,children:[`~$`,i.toFixed(2)]})]}),a!==null&&(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`div`,{className:`text-ink-muted`,children:`End of week`}),(0,x.jsxs)(`div`,{className:`font-mono tabular-nums`,children:[`~$`,a.toFixed(2)]})]})]}),o&&(0,x.jsx)(`div`,{className:`text-[10px] text-ink-muted italic mt-1`,children:o})]}):(0,x.jsx)(`div`,{className:`text-ink-muted text-xs`,children:`Insufficient data — forecast appears once burn rate stabilizes.`})]})}function NU(e,t){let{startMs:n,endMs:r,bucketSizeMs:i}=t,a=Math.max(1,Math.ceil((r-n)/i)),o=Array(a).fill(0);for(let t of e){let e=Math.floor((t.timestamp-n)/i);e>=0&&e<a&&o[e]++}return o}function PU(e){return e<6e5?3e4:e<36e5?6e4:e<144e5?3e5:9e5}var FU=50,IU={thrashing:`Edit/Test Thrashing`,stuck_loop:`Stuck Loop`,blind_editing:`Blind Editing`,re_reading:`Repeated Reads`,over_delegation:`Over-Delegation`},LU={running:{tone:`info`,label:`Running`},completed:{tone:`success`,label:`Completed`},failed:{tone:`danger`,label:`Failed`},cancelled:{tone:`warning`,label:`Cancelled`},unknown:{tone:`neutral`,label:`Unknown`}},RU=[{value:`today`,label:`Today`},{value:`7d`,label:`7 days`},{value:`30d`,label:`30 days`},{value:`all`,label:`All`}],zU=[{value:`all`,label:`All sources`},{value:`script`,label:`Script`},{value:`agent_tool`,label:`Agent tool`}],BU=[{value:`all`,label:`All`},{value:`running`,label:`Running`},{value:`completed`,label:`Completed`},{value:`failed`,label:`Failed`},{value:`cancelled`,label:`Cancelled`}];function VU(e,t){if(t===`all`||e==null)return!0;let n=typeof e==`number`?e:Date.parse(e);if(!Number.isFinite(n))return!0;let r=Date.now();return n>={today:new Date().setHours(0,0,0,0),"7d":r-6048e5,"30d":r-2592e6}[t]}function HU(e){let t;try{let n=new URLSearchParams(e);t=n.get(`session`)??n.get(`id`)}catch{return null}if(t==null)return null;let n=t.trim();return n.length===0||n.length>256?null:n}function UU(e){let t;try{t=new URLSearchParams(e).get(`repo`)}catch{return null}if(t==null)return null;let n=t.trim();return n.length===0||n.length>256?null:n}function WU(e){let t;try{t=new URLSearchParams(e).get(`sessionIds`)}catch{return null}if(t==null)return null;let n=t.split(`,`).map(e=>e.trim()).filter(e=>e.length>0&&e.length<=256);return n.length>0?new Set(n):null}function GU(e){return typeof e.startTime==`number`?e.startTime:new Date(e.startTime??0).getTime()}function KU(e){return GU(e)+(e.durationMs??0)}function qU(e,t){let n=[...e];switch(t){case`date`:n.sort((e,t)=>GU(t)-GU(e));break;case`lastActive`:n.sort((e,t)=>KU(t)-KU(e));break;case`cost`:n.sort((e,t)=>(t.estimatedCostUsd??0)-(e.estimatedCostUsd??0));break;case`calls`:n.sort((e,t)=>(t.toolCallCount??0)-(e.toolCallCount??0))}return n}function JU(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function YU(){let e=Gt(),[t,n]=(0,b.useState)(()=>HU(window.location.search)),[r,i]=(0,b.useState)(`date`),[a,o]=(0,b.useState)(`all`),[s,c]=(0,b.useState)(`all`),[l,u]=(0,b.useState)(`all`),[d,f]=(0,b.useState)(null),[p,m]=(0,b.useState)(()=>new Set),[h,g]=(0,b.useState)(()=>new Set),_=(0,b.useMemo)(()=>HU(e),[e]);(0,b.useEffect)(()=>{_&&n(_)},[_]);let[v,y]=(0,b.useState)(()=>UU(window.location.search)),S=(0,b.useMemo)(()=>UU(e),[e]);(0,b.useEffect)(()=>{S&&y(S)},[S]);let[C,w]=(0,b.useState)(()=>WU(window.location.search)),T=(0,b.useMemo)(()=>WU(e),[e]);(0,b.useEffect)(()=>{T&&w(T)},[T]);let E=L({queryKey:z.sessionsList(FU),queryFn:()=>nr(FU),refetchInterval:1e4}),{data:D}=L({queryKey:z.workflows,queryFn:Vr,refetchInterval:1e4}),O=L({queryKey:z.sessionCurrent,queryFn:tr,refetchInterval:1e4}),k=(0,b.useMemo)(()=>{let e=new Set;if(O.data?.liveSessions?.length)for(let t of O.data.liveSessions)e.add(t);return e},[O.data]),A=L({queryKey:t?z.sessionDetail(t):[`session`,`none`],queryFn:()=>ar(t),enabled:t!==null,refetchInterval:O.isLoading||t&&k.has(t)?1e4:!1}),j=(0,b.useMemo)(()=>qU(E.data??[],r),[E.data,r]),M=(0,b.useMemo)(()=>Array.isArray(D)?D:[],[D]),N=(0,b.useMemo)(()=>M.filter(e=>!(!VU(e.startedAt,a)||s!==`all`&&e.runSource!==s||l!==`all`&&e.status!==l)),[M,a,s,l]),ee=(0,b.useMemo)(()=>{let e=N.length,t=N.reduce((e,t)=>e+(t.agentCount??0),0),n=N.map(e=>e.totalUsd).filter(e=>e!=null),r=n.length>0?n.reduce((e,t)=>e+t,0):null,i=N.some(e=>e.costUnknown===!0),a=N.map(e=>e.durationMs).filter(e=>e!=null);return{totalRuns:e,totalAgents:t,totalSpend:r,spendIsPartial:i,avgDurationMs:a.length>0?a.reduce((e,t)=>e+t,0)/a.length:null}},[N]),te=(0,b.useMemo)(()=>{let e=new Map;for(let t of N){let n=t.parentSessionId;if(typeof n!=`string`)continue;let r=e.get(n);r?r.push(t):e.set(n,[t])}return e},[N]),P=a!==`all`||s!==`all`||l!==`all`||v!==null||C!==null,F=s!==`all`||l!==`all`,ne=(0,b.useMemo)(()=>{let e=j;return a!==`all`&&(e=e.filter(e=>VU(GU(e),a)||te.has(e.sessionId))),F&&(e=e.filter(e=>te.has(e.sessionId))),v!==null&&(e=e.filter(e=>e.repoName===v)),C!==null&&(e=e.filter(e=>C.has(e.sessionId))),e},[j,a,F,te,v,C]),re=(0,b.useMemo)(()=>{if(C===null)return 0;let e=new Set(j.map(e=>e.sessionId)),t=0;for(let n of C)e.has(n)||t++;return t},[C,j]),ie=(0,b.useMemo)(()=>{let e=new Set(ne.map(e=>e.sessionId)),t=0;for(let n of N)typeof n.parentSessionId==`string`&&!e.has(n.parentSessionId)&&t++;return t},[N,ne]);(0,b.useEffect)(()=>{if(t)return;let e=k.size>0?[...k][0]:null;e?n(e):!O.isLoading&&j.length>0&&n(j[0].sessionId)},[k,j,t,O.isLoading]);let ae=e=>{n(e)},oe=(0,b.useCallback)(e=>{m(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),I=(0,b.useCallback)(e=>{g(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),se=(0,b.useCallback)(e=>{f(e)},[]);return(0,x.jsxs)(`section`,{className:`flex flex-col h-full`,children:[(0,x.jsx)(`div`,{className:`h-8 overflow-hidden rounded-lg mb-2 shrink-0`,children:(0,x.jsx)(AH,{theme:`sessions`})}),(0,x.jsx)(`h1`,{className:`text-lg font-semibold gradient-text mb-2 shrink-0`,children:`Sessions`}),(0,x.jsxs)(B,{tone:`static`,padding:`sm`,className:`mb-2 shrink-0`,children:[(0,x.jsxs)(`div`,{className:`grid grid-cols-2 sm:grid-cols-4 gap-4 divide-x divide-border-subtle`,children:[(0,x.jsx)(`div`,{className:`px-3 first:pl-0`,children:(0,x.jsx)(sV,{label:`Workflow runs`,value:String(ee.totalRuns),numericValue:ee.totalRuns,animate:!0})}),(0,x.jsx)(`div`,{className:`px-3`,children:(0,x.jsx)(sV,{label:`Subagents`,value:String(ee.totalAgents),numericValue:ee.totalAgents,animate:!0})}),(0,x.jsx)(`div`,{className:`px-3`,children:(0,x.jsx)(sV,{label:`Workflow spend`,value:wi(ee.totalSpend)+(ee.spendIsPartial?`*`:``),tone:ee.totalSpend===null?`neutral`:`warn`,sub:ee.spendIsPartial?`*partial — some runs have cost never observed by any process`:void 0})}),(0,x.jsx)(`div`,{className:`px-3`,children:(0,x.jsx)(sV,{label:`Avg duration`,value:ee.avgDurationMs===null?`—`:xi(ee.avgDurationMs)})})]}),ie>0&&(0,x.jsxs)(`div`,{className:`text-[11px] text-ink-subtle mt-2 pt-2 border-t border-border-subtle`,children:[`+`,ie,` run`,ie===1?``:`s`,` above from `,ie===1?`a session`:`sessions`,` outside the`,` `,ne.length,` shown below`]})]}),(0,x.jsxs)(`div`,{className:`flex items-center gap-3 flex-wrap mb-2 shrink-0`,children:[(0,x.jsx)(si,{value:a,onChange:o,options:RU,ariaLabel:`Time window`}),(0,x.jsx)(`div`,{className:`h-4 w-px bg-border-subtle`,"aria-hidden":`true`}),(0,x.jsx)(`div`,{className:`flex items-center gap-1.5`,role:`group`,"aria-label":`Run source filter`,children:zU.map(e=>(0,x.jsx)(`button`,{type:`button`,"aria-pressed":s===e.value,onClick:()=>c(e.value),className:[`px-2.5 py-1 rounded-full text-[11px] transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-cyan/40`,s===e.value?`bg-accent-cyan/20 text-accent-cyan font-medium`:`text-ink-muted hover:text-ink-subtle`].join(` `),children:e.label},e.value))}),(0,x.jsx)(`div`,{className:`h-4 w-px bg-border-subtle`,"aria-hidden":`true`}),(0,x.jsx)(`div`,{className:`flex items-center gap-1.5`,role:`group`,"aria-label":`Status filter`,children:BU.map(e=>{let t=l===e.value;return(0,x.jsx)(`button`,{type:`button`,"aria-pressed":t,onClick:()=>u(e.value),className:[`px-2.5 py-1 rounded-full text-[11px] transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-cyan/40`,t?`bg-accent-green/20 text-accent-green font-medium`:`text-ink-muted hover:text-ink-subtle`].join(` `),children:e.label},e.value)})}),v!==null&&(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(`div`,{className:`h-4 w-px bg-border-subtle`,"aria-hidden":`true`}),(0,x.jsxs)(`span`,{className:`flex items-center gap-1 px-2.5 py-1 rounded-full text-[11px] bg-accent-cyan/20 text-accent-cyan font-medium`,children:[`Repo: `,v,(0,x.jsx)(`button`,{type:`button`,onClick:()=>y(null),"aria-label":`Clear repo filter`,className:`hover:text-ink-base focus-visible:outline-none`,children:`✕`})]})]}),C!==null&&(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(`div`,{className:`h-4 w-px bg-border-subtle`,"aria-hidden":`true`}),(0,x.jsxs)(`span`,{className:`flex items-center gap-1 px-2.5 py-1 rounded-full text-[11px] bg-accent-cyan/20 text-accent-cyan font-medium`,children:[C.size,` session`,C.size===1?``:`s`,` selected`,(0,x.jsx)(`button`,{type:`button`,onClick:()=>w(null),"aria-label":`Clear session filter`,className:`hover:text-ink-base focus-visible:outline-none`,children:`✕`})]}),re>0&&(0,x.jsxs)(`span`,{className:`text-[11px] text-accent-amber`,children:[re,` of `,C.size,` not shown — older than the`,` `,FU,` most recent sessions`]})]}),P&&(0,x.jsx)(`button`,{type:`button`,onClick:()=>{o(`all`),c(`all`),u(`all`),y(null),w(null)},className:`text-[10px] text-ink-muted hover:text-ink-subtle underline-offset-2 hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-cyan/40 rounded-sm`,children:`Clear filters`})]}),(0,x.jsxs)(`div`,{className:`grid grid-cols-[260px_1fr] gap-3 flex-1 min-h-0`,children:[(0,x.jsxs)(B,{padding:`none`,tone:`static`,className:`overflow-hidden flex flex-col`,children:[(0,x.jsx)(`header`,{className:`p-2 border-b border-border-subtle`,children:(0,x.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,x.jsx)(V,{as:`h2`,children:`List`}),(0,x.jsxs)(`select`,{value:r,onChange:e=>i(e.target.value),className:`text-[10px] bg-surface-5 border border-border-medium rounded-md px-1.5 py-0.5 text-ink-subtle`,children:[(0,x.jsx)(`option`,{value:`date`,children:`Newest`}),(0,x.jsx)(`option`,{value:`lastActive`,children:`Last active`}),(0,x.jsx)(`option`,{value:`cost`,children:`Cost`}),(0,x.jsx)(`option`,{value:`calls`,children:`Calls`})]})]})}),(0,x.jsxs)(`div`,{className:`overflow-auto`,children:[E.isLoading&&(0,x.jsx)($,{variant:`loading`,icon:`timeline`,title:`Loading sessions`}),!E.isLoading&&ne.length===0&&k.size===0&&(0,x.jsx)($,{icon:`code`,title:P?`No matching sessions`:`No sessions yet`,subtitle:P?F?`No sessions own a workflow run matching these filters.`:`No sessions in this time window.`:`Start coding with Claude to see your sessions here.`}),ne.map(e=>(0,x.jsx)(XU,{row:e,isLive:k.has(e.sessionId),isSelected:t===e.sessionId,isExpanded:p.has(e.sessionId),sortKey:r,runs:te.get(e.sessionId)??[],expandedRuns:h,onSelect:ae,onToggleSession:oe,onToggleRun:I,onOpenRun:se},e.sessionId)),j.length>=FU&&(0,x.jsxs)(`div`,{className:`p-2 text-[10px] text-ink-muted text-center border-t border-border-subtle`,children:[`Only the `,FU,` most recent sessions are loaded`,P?`; filters narrow this further`:``,`.`]})]})]}),(0,x.jsxs)(`div`,{className:`glass-card glass-card-static p-4 overflow-auto`,children:[!t&&(0,x.jsx)($,{icon:`timeline`,title:`Loading sessions`,subtitle:`Selecting the most recent session…`}),t&&A.isLoading&&(0,x.jsx)($,{variant:`loading`,icon:`timeline`,title:`Loading detail`}),t&&A.isError&&(0,x.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-8 gap-4`,children:[(0,x.jsx)($,{icon:`timeline`,title:`Session not found`,subtitle:`This session could not be loaded.`}),(0,x.jsx)(`button`,{type:`button`,onClick:()=>n(null),className:`text-accent-cyan hover:text-accent-cyan/80 text-sm font-medium`,children:`Clear selection`})]}),t&&A.data&&(0,x.jsx)($U,{data:A.data,isLive:!!t&&k.has(t),onOpenRun:se})]})]}),d!=null&&(0,x.jsx)(iH,{runId:d,onClose:()=>f(null)})]})}function XU({row:e,isLive:t,isSelected:n,isExpanded:r,sortKey:i,runs:a,expandedRuns:o,onSelect:s,onToggleSession:c,onToggleRun:l,onOpenRun:u}){return(0,x.jsxs)(`div`,{className:`border-b border-border-subtle`,children:[(0,x.jsxs)(`div`,{className:`flex items-stretch text-xs transition-colors duration-150 hover:bg-surface-5 `+(n?`bg-surface-5`:``),children:[(0,x.jsx)(`button`,{type:`button`,"aria-label":r?`Collapse workflows`:`Expand workflows`,"aria-expanded":r,onClick:t=>{t.stopPropagation(),c(e.sessionId)},className:`shrink-0 flex items-center justify-center w-6 text-ink-muted hover:text-ink-base focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-cyan/40`,children:r?(0,x.jsx)(hn,{size:13,"aria-hidden":`true`}):(0,x.jsx)(gn,{size:13,"aria-hidden":`true`})}),(0,x.jsxs)(`button`,{type:`button`,onClick:()=>s(e.sessionId),className:`flex-1 min-w-0 text-left py-2 pr-2`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,x.jsx)(`span`,{className:`font-mono text-ink-base truncate`,children:e.sessionName||e.sessionId.slice(0,8)}),t&&(0,x.jsx)(ii,{size:`sm`,label:`live`,className:`shrink-0`})]}),(0,x.jsxs)(`div`,{className:`flex justify-between mt-1 text-ink-subtle text-[11px] tabular-nums`,children:[(0,x.jsxs)(`span`,{children:[e.toolCallCount??0,` calls`]}),(0,x.jsx)(`span`,{className:`text-ink-muted`,title:i===`lastActive`&&e.startTime?`Started ${vi(e.startTime)}`:void 0,children:e.startTime?vi(i===`lastActive`?KU(e):e.startTime):`—`}),(0,x.jsx)(`span`,{children:wi(e.estimatedCostUsd)})]})]})]}),r&&(0,x.jsx)(`div`,{className:`pl-3 border-l border-border-subtle ml-3 mb-1`,children:a.length===0?(0,x.jsx)(`div`,{className:`py-1.5 pl-1 text-[10px] text-ink-muted`,children:`No workflows in this session.`}):a.map(e=>(0,x.jsx)(ZU,{run:e,isExpanded:o.has(e.runId),onToggleRun:l,onOpenRun:u},e.runId))})]})}function ZU({run:e,isExpanded:t,onToggleRun:n,onOpenRun:r}){let{data:i}=L({queryKey:z.workflowDetail(e.runId),queryFn:()=>Hr(e.runId),enabled:t}),a=(0,b.useMemo)(()=>i?.agents??[],[i]),o=LU[e.status]??LU.unknown;return(0,x.jsxs)(`div`,{children:[(0,x.jsxs)(`div`,{className:`flex items-stretch hover:bg-surface-5 rounded transition-colors`,children:[(0,x.jsx)(`button`,{type:`button`,"aria-label":t?`Collapse agents`:`Expand agents`,"aria-expanded":t,onClick:t=>{t.stopPropagation(),n(e.runId)},className:`shrink-0 flex items-center justify-center w-5 text-ink-muted hover:text-ink-base focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-cyan/40`,children:t?(0,x.jsx)(hn,{size:12,"aria-hidden":`true`}):(0,x.jsx)(gn,{size:12,"aria-hidden":`true`})}),(0,x.jsxs)(`button`,{type:`button`,"aria-label":`View workflow run ${e.workflowName??e.runId}`,onClick:()=>r(e.runId),className:`flex-1 min-w-0 flex items-center gap-1.5 text-left py-1.5 pr-1 text-[10px] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-cyan/40 rounded`,children:[(0,x.jsx)(`span`,{className:`flex-1 min-w-0 font-medium text-ink-base truncate`,children:e.workflowName??e.runId}),(0,x.jsxs)(`span`,{className:`text-ink-muted tabular-nums shrink-0`,children:[e.agentCount==null?0:e.agentCount,`a`]}),(0,x.jsx)(`span`,{className:`text-ink-muted tabular-nums shrink-0`,children:wi(e.totalUsd)}),(0,x.jsx)(ni,{tone:o.tone,size:`sm`,bordered:!0,children:o.label})]})]}),t&&(0,x.jsx)(`div`,{className:`pl-3 border-l border-border-subtle ml-2.5`,children:a.length===0?(0,x.jsx)(`div`,{className:`py-1 pl-1 text-[10px] text-ink-muted`,children:`No agents recorded.`}):a.map(t=>(0,x.jsxs)(`button`,{type:`button`,"aria-label":`View agent ${t.label} in run ${e.workflowName??e.runId}`,onClick:()=>r(e.runId),className:`flex w-full items-center gap-1.5 text-left py-1 pr-1 text-[10px] hover:bg-surface-5 rounded transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-cyan/40`,children:[(0,x.jsx)(`span`,{className:`flex-1 min-w-0 text-ink-subtle truncate`,title:t.label,children:t.label}),(0,x.jsx)(`span`,{className:`font-mono text-ink-muted truncate max-w-[72px] shrink-0`,title:t.model,children:t.model}),(0,x.jsx)(`span`,{className:`text-ink-muted tabular-nums shrink-0`,children:JU(t.tokens)})]},t.agentId))})]})}function QU(e){return e===`Read`?`bg-accent-blue/80`:e===`Edit`||e===`Write`?`bg-accent-green/80`:e===`Bash`?`bg-accent-purple/80`:e===`Agent`?`bg-accent-teal/80`:`bg-ink-subtle/80`}function $U({data:e,isLive:t,onOpenRun:n}){let r=e.toolBreakdown??{},i=Object.entries(r).sort((e,t)=>t[1]-e[1]),a=e.toolCallCount??0,o=e.durationMs==null?null:xi(e.durationMs),s=e.timeline??[],c=s.length>0?s[0].timestamp:0,l=Object.entries(e.modelBreakdown??{}),u=l.length>0?l.sort((e,t)=>t[1].requestCount-e[1].requestCount).map(([e])=>e):e.model?[e.model]:[];return s.length===0&&i.length===0?(0,x.jsx)($,{icon:`timeline`,title:`No tool calls`,subtitle:`This session has no recorded tool calls.`}):(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`div`,{className:`flex items-baseline justify-between mb-3`,children:(0,x.jsxs)(`div`,{children:[(0,x.jsxs)(`h2`,{className:`text-xs tracking-wider text-ink-muted flex items-center gap-2`,children:[(0,x.jsx)(`span`,{className:`font-mono text-ink-base ${e.sessionName?`font-medium`:`uppercase`}`,children:e.sessionName||e.sessionId.slice(0,8)}),(0,x.jsx)(`span`,{"aria-hidden":`true`,children:`·`}),(0,x.jsxs)(`span`,{className:`uppercase`,children:[a,` calls`]}),o&&(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(`span`,{"aria-hidden":`true`,children:`·`}),(0,x.jsx)(`span`,{className:`tabular-nums`,children:o})]}),t&&(0,x.jsx)(ii,{size:`sm`,label:`live`})]}),c>0&&(0,x.jsx)(`div`,{className:`text-[11px] text-ink-subtle mt-0.5`,children:new Date(c).toLocaleString(void 0,{weekday:`short`,month:`short`,day:`numeric`,hour:`numeric`,minute:`2-digit`})})]})}),(0,x.jsxs)(`div`,{className:`grid grid-cols-3 gap-2 mb-4 text-xs`,children:[u.length>0&&(0,x.jsxs)(`div`,{className:`bg-surface-3 rounded-lg p-2.5`,children:[(0,x.jsx)(V,{children:u.length>1?`Models (${u.length})`:`Model`}),u.length>1?(0,x.jsx)(`div`,{className:`flex flex-col gap-0.5 mt-0.5`,children:u.map(e=>(0,x.jsx)(`div`,{className:`font-mono text-[11px] truncate`,title:e,children:e},e))}):(0,x.jsx)(`div`,{className:`font-mono`,children:u[0]})]}),e.estimatedCostUsd!=null&&(0,x.jsxs)(`div`,{className:`bg-surface-3 rounded-lg p-2.5`,children:[(0,x.jsx)(V,{children:`Cost`}),(0,x.jsx)(`div`,{className:`tabular-nums`,children:Ci(e.estimatedCostUsd)})]}),e.outcome&&(0,x.jsxs)(`div`,{className:`bg-surface-3 rounded-lg p-2.5`,children:[(0,x.jsx)(V,{children:`Status`}),(0,x.jsx)(`div`,{className:`capitalize`,children:e.outcome})]})]}),(e.antiPatterns?.length??0)>0&&(0,x.jsxs)(`div`,{className:`mb-4`,children:[(0,x.jsx)(V,{className:`mb-1`,children:`Anti-Patterns`}),(0,x.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:Object.entries((e.antiPatterns??[]).reduce((e,t)=>{let n=t.iterations??t.readCount??t.repeatCount??t.editCount??t.agentCount??1;return e[t.type]=(e[t.type]??0)+n,e},{})).map(([e,t])=>(0,x.jsxs)(ni,{tone:`warning`,size:`sm`,bordered:!0,children:[IU[e]??e,(0,x.jsxs)(`span`,{className:`opacity-70`,children:[`× `,t]})]},e))})]}),(e.qualityProxy||e.toolSelectionScore)&&(0,x.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 mb-4`,children:[e.qualityProxy&&(0,x.jsxs)(`div`,{className:`bg-surface-3 rounded-lg p-3`,children:[(0,x.jsx)(V,{className:`mb-2`,children:`Session Quality`}),(0,x.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 text-xs`,children:[(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`Diff Apply `}),(0,x.jsx)(`span`,{className:gi(e.qualityProxy.diffApplyRate),children:e.qualityProxy.diffApplyRate===null?`—`:`${(e.qualityProxy.diffApplyRate*100).toFixed(0)}%`})]}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`Test Pass `}),(0,x.jsx)(`span`,{className:gi(e.qualityProxy.testPassRate),children:e.qualityProxy.testPassRate===null?`—`:`${(e.qualityProxy.testPassRate*100).toFixed(0)}%`})]}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`Backtracks `}),(0,x.jsx)(`span`,{className:e.qualityProxy.backtrackCount>0?`text-accent-amber`:``,children:e.qualityProxy.backtrackCount})]}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`Self-corrections `}),(0,x.jsx)(`span`,{className:`text-ink-subtle`,children:e.qualityProxy.selfCorrectionCount})]})]})]}),e.toolSelectionScore&&(0,x.jsxs)(`div`,{className:`bg-surface-3 rounded-lg p-3`,children:[(0,x.jsx)(V,{className:`mb-2`,children:`Tool Selection`}),(0,x.jsx)(`div`,{className:`text-2xl font-semibold tabular-nums ${_i(e.toolSelectionScore.score)}`,children:e.toolSelectionScore.score.toFixed(2)}),(0,x.jsxs)(`div`,{className:`text-[10px] text-ink-muted mt-1`,children:[`re-reads: `,e.toolSelectionScore.redundantReadCount,` · repeat fails:`,` `,e.toolSelectionScore.repeatedFailureCount,` · unused:`,` `,e.toolSelectionScore.unusedOutputCount]})]})]}),t&&(0,x.jsx)(`div`,{className:`mb-4`,children:(0,x.jsx)(gH,{sessionId:e.sessionId})}),i.length>0&&(0,x.jsx)(tW,{breakdownEntries:i,totalCalls:a,isLive:t,sessionId:e.sessionId},`tools-${e.sessionId}`),(0,x.jsx)(rW,{timeline:s}),(e.filesRead?.length??0)>0&&(0,x.jsxs)(`div`,{className:`mb-4`,children:[(0,x.jsx)(V,{className:`mb-1`,children:`Files Read`}),(0,x.jsx)(`ul`,{className:`text-[11px] text-ink-subtle space-y-0.5`,children:e.filesRead.map(e=>(0,x.jsx)(`li`,{className:`font-mono truncate`,children:e.split(`/`).slice(-2).join(`/`)},e))})]}),(e.filesModified?.length??0)>0&&(0,x.jsxs)(`div`,{className:`mb-4`,children:[(0,x.jsx)(V,{className:`mb-1`,children:`Files Modified`}),(0,x.jsx)(`ul`,{className:`text-[11px] text-ink-subtle space-y-0.5`,children:e.filesModified.map(e=>(0,x.jsx)(`li`,{className:`font-mono truncate`,children:e.split(`/`).slice(-2).join(`/`)},e))})]}),(0,x.jsx)(eW,{sessionId:e.sessionId,isLive:t,parentEntries:s,onOpenRun:n},e.sessionId)]})}function eW({sessionId:e,isLive:t,parentEntries:n,onOpenRun:r}){let{data:i,isLoading:a,isError:o}=L({queryKey:z.sessionSubagents(e),queryFn:()=>xr(e),retry:!1,refetchInterval:t?1e4:!1}),{data:s}=L({queryKey:z.workflows,queryFn:Vr,refetchInterval:t?1e4:3e4}),c=(0,b.useMemo)(()=>{let t={};if(!Array.isArray(s))return t;for(let n of s)n.parentSessionId===e&&(t[n.runId]=n.status);return t},[s,e]),l=(0,b.useMemo)(()=>i?.agents??[],[i]),u=(0,b.useMemo)(()=>{let e=i!==void 0&&(i.agents?.length??0)>0,t=e?i.window.startMs:null,r=e?i.window.endMs:null,a=null,o=null;for(let e of n){let t=e.timestamp,n=e.timestamp+(e.durationMs??50);(a===null||t<a)&&(a=t),(o===null||n>o)&&(o=n)}let s=[a,t].filter(e=>e!==null),c=[o,r].filter(e=>e!==null);return s.length===0||c.length===0?null:{startMs:Math.min(...s),endMs:Math.max(...c)}},[i,n]),d=(0,b.useMemo)(()=>n.map(e=>({timestamp:e.timestamp,toolName:e.toolName,durationMs:e.durationMs,success:e.success,filePath:e.filePath,command:e.command})),[n]);return(0,x.jsxs)(`div`,{className:`mb-4`,children:[(0,x.jsx)(V,{className:`mb-2`,children:`Session trace`}),(0,x.jsx)(B,{tone:`static`,padding:`sm`,children:a?(0,x.jsx)($,{variant:`loading`,icon:`radar`,title:`Loading subagents`}):o||i===void 0?(0,x.jsx)(PV,{sessionId:e,parentEntries:d,agents:[],window:u??{startMs:0,endMs:1},onSelectRun:r,runStatusById:c}):(0,x.jsx)(PV,{sessionId:e,parentEntries:d,agents:l,window:u??i.window,onSelectRun:r,runStatusById:c})})]})}function tW({breakdownEntries:e,totalCalls:t,isLive:n,sessionId:r}){let[i,a]=(0,b.useState)(`calls`),{data:o}=L({queryKey:[`context`,r],queryFn:()=>Ar(r),refetchInterval:1e4,enabled:n&&i===`context`}),s=o?.toolContributions??[],c=s.length>0?s[0].estimatedTokens:0;return(0,x.jsxs)(`div`,{className:`mb-4`,children:[(0,x.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,x.jsx)(V,{children:`Tools`}),n&&(0,x.jsx)(si,{value:i,onChange:a,options:[{value:`calls`,label:`Calls`},{value:`context`,label:`Context`}],size:`sm`,tone:`cyan`,ariaLabel:`Tools view`})]}),(0,x.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[i===`calls`&&e.map(([e,n])=>{let r=t>0?n/t*100:0;return(0,x.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px]`,children:[(0,x.jsx)(`span`,{className:`w-28 text-ink-subtle truncate`,title:e,children:Ei(e)}),(0,x.jsx)(`div`,{className:`flex-1 h-3 bg-surface-3 relative rounded`,children:(0,x.jsx)(`div`,{className:`h-3 rounded ${QU(e)}`,style:{width:`${r}%`}})}),(0,x.jsx)(`span`,{className:`w-10 text-right text-ink-muted tabular-nums`,children:n})]},e)}),i===`context`&&s.map(e=>{let t=c>0?e.estimatedTokens/c*100:0;return(0,x.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px]`,children:[(0,x.jsx)(`span`,{className:`w-28 text-ink-subtle truncate`,title:e.tool,children:Ei(e.tool)}),(0,x.jsx)(`div`,{className:`flex-1 h-3 bg-surface-3 relative rounded`,children:(0,x.jsx)(`div`,{className:`h-3 rounded bg-accent-amber/80`,style:{width:`${t}%`}})}),(0,x.jsxs)(`span`,{className:`w-16 text-right text-ink-muted tabular-nums text-[10px]`,children:[`~`,nW(e.estimatedTokens)]})]},e.tool)}),i===`context`&&s.length===0&&(0,x.jsx)(`div`,{className:`text-[11px] text-ink-muted`,children:`No context data available yet`})]})]})}function nW(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function rW({timeline:e}){let t=(0,b.useMemo)(()=>{if(e.length<2)return null;let t=e[0].timestamp,n=e[e.length-1].timestamp,r=n-t;if(r<1e3)return null;let i=PU(r),a=NU(e,{startMs:t,endMs:n+i,bucketSizeMs:i});return{buckets:a,maxCount:Math.max(...a,1),bucketSizeMs:i,startMs:t}},[e]);return t?(0,x.jsxs)(`div`,{className:`mb-4`,children:[(0,x.jsx)(V,{className:`mb-1`,children:`Activity Density`}),(0,x.jsx)(EH,{variant:`strip`,buckets:t.buckets,maxCount:t.maxCount,bucketSizeMs:t.bucketSizeMs,startTimestamp:t.startMs,ariaLabel:`Session activity density`})]}):null}var iW={fill:`var(--color-ink-muted)`,fontSize:10},aW=`var(--color-border-subtle)`,oW={background:`var(--color-bg-elevated)`,border:`1px solid var(--color-border-medium)`,borderRadius:8,fontSize:12,color:`var(--color-ink-base)`},sW={color:`var(--color-ink-base)`},cW=`var(--color-accent-green)`,lW=`var(--color-accent-amber)`,uW=`var(--color-accent-green)`,dW=`var(--color-accent-purple)`,fW=`var(--color-accent-blue)`,pW=`var(--color-accent-teal)`;function mW(e){return e===`Read`?fW:e===`Edit`||e===`Write`?uW:e===`Bash`?dW:e===`Agent`?pW:`var(--color-ink-muted)`}function hW(e){let t=e.toLowerCase();return t===`bug fix`||t===`fix`?`#FF6B6B`:t===`feature`?uW:t===`refactor`?fW:t===`configuration`||t===`config`?lW:t===`test`?pW:t===`docs`?`#C4B5FD`:dW}function gW(e){return typeof e==`string`&&e.length>=10?e.slice(5,10):e}var _W=`Compares session outcomes before and after your most recent change to an instruction file (CLAUDE.md, or the active platform's equivalent) — success rate, token usage, and thrashing incidents. A degraded verdict means sessions got worse after the edit, not better.`;function vW({label:e,value:t}){return(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`div`,{className:`text-[10px] text-ink-muted uppercase tracking-wider`,children:e}),(0,x.jsx)(`div`,{className:`text-sm font-bold tabular-nums mt-0.5`,children:t})]})}function yW({data:e}){if(!e)return(0,x.jsx)(xW,{title:`Instruction Drift`,tooltip:_W,children:(0,x.jsx)($,{variant:`loading`,title:`Loading drift data…`})});let t=e.recentCorrelations[e.recentCorrelations.length-1];return t?(0,x.jsx)(xW,{title:`Instruction Drift — most recent instruction file change`,tooltip:_W,children:(0,x.jsxs)(`div`,{className:`flex items-center gap-6`,children:[(0,x.jsx)(ni,{tone:{improved:`success`,degraded:`danger`,neutral:`neutral`,insufficient_data:`neutral`}[t.verdict],children:t.verdict}),(0,x.jsx)(vW,{label:`Success`,value:t.successRateDelta===null?`—`:`${t.successRateDelta>0?`+`:``}${Math.round(t.successRateDelta*100)}%`}),(0,x.jsx)(vW,{label:`Tokens`,value:`${t.tokensDelta>0?`+`:``}${t.tokensDelta}`}),(0,x.jsx)(vW,{label:`Thrashing`,value:`${t.thrashingDelta>0?`+`:``}${t.thrashingDelta}`})]})}):(0,x.jsx)(xW,{title:`Instruction Drift`,tooltip:_W,children:(0,x.jsx)(`div`,{className:`text-ink-muted text-xs`,children:`No instruction file changes tracked yet.`})})}function bW(){let e=L({queryKey:z.weekly,queryFn:fr}),t=L({queryKey:z.sessionsList(200),queryFn:()=>nr(200)}),n=L({queryKey:z.costPerOutcome(30),queryFn:()=>mr(30)}),r=L({queryKey:z.personalCoach,queryFn:hr}),i=L({queryKey:z.recommendations,queryFn:gr,retry:!1}),a=L({queryKey:z.claudeMdImpact,queryFn:_r,retry:!1}),o=L({queryKey:z.collaborationProfile,queryFn:vr,retry:!1}),s=L({queryKey:z.activityHeatmap(`history`),queryFn:()=>kr(`history`,12)}),c=L({queryKey:z.concurrencyHistory(30),queryFn:()=>Or(30)}),l=L({queryKey:z.instructionDrift,queryFn:Ur}),u=e.isError||t.isError||n.isError||c.isError,d=[...e.data??[]].reverse(),f=d.map(e=>{let t=e.avgEfficiencyScore;return{week:e.week||`?`,efficiency:t===null?null:Math.round(t*100)}}),p=FW(MW(t.data??[],30),30),m=(t.data?.length??0)>=200&&NW(t.data??[],30),h=PW(n.data),g=IW(d),_=zW(t.data??[]),v=BW(t.data??[]),y=new Set((t.data??[]).flatMap(e=>e.toolBreakdown?Object.keys(e.toolBreakdown):[])).size,b=Math.max(0,y-v.length),S=c.data?.dailyPeaks??[],C=S.some(e=>e.peak>0);return(0,x.jsxs)(`section`,{children:[(0,x.jsx)(AH,{theme:`history`}),(0,x.jsx)(`h1`,{className:`text-xl font-semibold gradient-text mb-4`,children:`History`}),u&&(0,x.jsx)(`div`,{className:`text-accent-red text-xs mb-3`,children:`Error loading some history data. Charts below may be incomplete.`}),(0,x.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,x.jsx)(xW,{title:`Weekly Efficiency · Last 12`,children:(0,x.jsx)(`div`,{className:`h-44 min-w-0`,children:(0,x.jsx)(np,{width:`100%`,height:`100%`,minWidth:1,minHeight:1,children:(0,x.jsxs)(rV,{data:f,children:[(0,x.jsx)(`defs`,{children:(0,x.jsxs)(`linearGradient`,{id:`effGradient`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,x.jsx)(`stop`,{offset:`0%`,stopColor:cW,stopOpacity:.3}),(0,x.jsx)(`stop`,{offset:`100%`,stopColor:cW,stopOpacity:0})]})}),(0,x.jsx)(hI,{stroke:aW,strokeDasharray:`3 3`}),(0,x.jsx)(YR,{dataKey:`week`,tick:iW,stroke:aW,tickFormatter:gW}),(0,x.jsx)(uz,{tick:iW,stroke:aW,domain:[0,100],unit:`%`}),(0,x.jsx)(Yk,{contentStyle:oW}),(0,x.jsx)(yL,{type:`monotone`,dataKey:`efficiency`,stroke:cW,strokeWidth:2,fill:`url(#effGradient)`,dot:{r:2,fill:cW}})]})})})}),(0,x.jsxs)(xW,{title:`Daily Spend · Last 30 Days (most recent 200)`,children:[(0,x.jsx)(`div`,{className:`h-44 min-w-0`,children:(0,x.jsx)(np,{width:`100%`,height:`100%`,minWidth:1,minHeight:1,children:(0,x.jsxs)(tV,{data:p,children:[(0,x.jsx)(`defs`,{children:(0,x.jsxs)(`linearGradient`,{id:`costGradient`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,x.jsx)(`stop`,{offset:`0%`,stopColor:cW,stopOpacity:.9}),(0,x.jsx)(`stop`,{offset:`100%`,stopColor:cW,stopOpacity:.4})]})}),(0,x.jsx)(hI,{stroke:aW,strokeDasharray:`3 3`}),(0,x.jsx)(YR,{dataKey:`day`,tick:iW,stroke:aW,tickFormatter:gW,interval:`preserveStartEnd`,minTickGap:20}),(0,x.jsx)(uz,{tick:iW,stroke:aW,unit:`$`}),(0,x.jsx)(Yk,{contentStyle:oW,labelFormatter:e=>gW(String(e)),cursor:!1}),(0,x.jsx)(OR,{dataKey:`cost`,fill:`url(#costGradient)`,radius:[3,3,0,0]})]})})}),m&&(0,x.jsx)(`div`,{className:`text-[10px] text-ink-muted italic mt-1`,children:`Sample doesn't reach back 30 days — early days in this chart may undercount actual spend.`})]}),(0,x.jsx)(xW,{title:`Cost Per Outcome · Last 30 Days`,children:h.length===0?(0,x.jsx)($,{icon:`radar`,title:`No outcomes yet`,subtitle:`Finish a few sessions and check back.`}):(0,x.jsx)(`div`,{className:`min-w-0`,style:{height:`${Math.max(176,h.length*32+40)}px`},children:(0,x.jsx)(np,{width:`100%`,height:`100%`,minWidth:1,minHeight:1,children:(0,x.jsxs)(tV,{data:h,layout:`vertical`,children:[(0,x.jsx)(hI,{stroke:aW,strokeDasharray:`3 3`}),(0,x.jsx)(YR,{type:`number`,tick:iW,stroke:aW,unit:`$`}),(0,x.jsx)(uz,{type:`category`,dataKey:`outcome`,tick:iW,stroke:aW,width:110}),(0,x.jsx)(Yk,{contentStyle:oW,itemStyle:sW}),(0,x.jsx)(OR,{dataKey:`totalCost`,radius:[0,3,3,0],children:h.map(e=>(0,x.jsx)(Xk,{fill:hW(e.outcome),fillOpacity:.8},e.outcome))})]})})})}),(0,x.jsx)(xW,{title:`Anti-Pattern Frequency · Weekly`,children:g.length===0||g.every(e=>e.count===0)?(0,x.jsx)($,{icon:`checkmark`,title:`No anti-patterns detected`,subtitle:`No anti-patterns detected in the loaded weeks.`}):(0,x.jsx)(`div`,{className:`h-44 min-w-0`,children:(0,x.jsx)(np,{width:`100%`,height:`100%`,minWidth:1,minHeight:1,children:(0,x.jsxs)(tV,{data:g,children:[(0,x.jsx)(`defs`,{children:(0,x.jsxs)(`linearGradient`,{id:`antiPatternGradient`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,x.jsx)(`stop`,{offset:`0%`,stopColor:lW,stopOpacity:.9}),(0,x.jsx)(`stop`,{offset:`100%`,stopColor:lW,stopOpacity:.4})]})}),(0,x.jsx)(hI,{stroke:aW,strokeDasharray:`3 3`}),(0,x.jsx)(YR,{dataKey:`week`,tick:iW,stroke:aW,tickFormatter:gW}),(0,x.jsx)(uz,{tick:iW,stroke:aW}),(0,x.jsx)(Yk,{contentStyle:oW}),(0,x.jsx)(OR,{dataKey:`count`,fill:`url(#antiPatternGradient)`,radius:[3,3,0,0]})]})})})}),(0,x.jsx)(xW,{title:`Model Performance · Most Recent 200 Sessions`,children:_.length===0?(0,x.jsx)($,{icon:`radar`,title:`No model data yet`,subtitle:`Complete a few sessions to see model performance.`}):(0,x.jsxs)(`div`,{className:`h-44 overflow-y-auto text-xs`,children:[(0,x.jsxs)(`table`,{className:`w-full`,children:[(0,x.jsx)(`thead`,{className:`text-ink-muted sticky top-0 bg-bg-panel`,children:(0,x.jsxs)(`tr`,{children:[(0,x.jsx)(`th`,{className:`text-left pb-1`,children:`Model`}),(0,x.jsx)(`th`,{className:`text-right pb-1`,children:`Sessions`}),(0,x.jsx)(`th`,{className:`text-right pb-1`,children:`Eff.`}),(0,x.jsx)(`th`,{className:`text-right pb-1`,children:`Success`}),(0,x.jsx)(`th`,{className:`text-right pb-1`,children:`Avg $`}),(0,x.jsx)(`th`,{className:`text-right pb-1`,children:`$/1M tok`})]})}),(0,x.jsx)(`tbody`,{children:_.map(e=>(0,x.jsxs)(`tr`,{className:`border-t border-bg-line`,children:[(0,x.jsx)(`td`,{className:`py-1 font-medium`,children:e.model}),(0,x.jsx)(`td`,{className:`py-1 text-right tabular-nums`,children:e.sessions}),(0,x.jsx)(`td`,{className:`py-1 text-right tabular-nums`,children:e.avgEfficiency===null?`—`:`${Math.min(100,Math.round(e.avgEfficiency*100))}%`}),(0,x.jsx)(`td`,{className:`py-1 text-right tabular-nums ${e.flagged?`text-accent-amber`:``}`,children:e.avgSuccessRate===null?`—`:`${Math.min(100,Math.round(e.avgSuccessRate*100))}%`}),(0,x.jsx)(`td`,{className:`py-1 text-right tabular-nums`,children:wi(e.avgCost)}),(0,x.jsx)(`td`,{className:`py-1 text-right tabular-nums text-ink-subtle`,children:wi(e.costPerMillionTokens)})]},e.model))})]}),_.some(e=>e.flagged)&&(0,x.jsx)(`div`,{className:`text-accent-amber text-[10px] mt-1`,children:`⚠ Highlighted models had sessions with elevated error rates`})]})}),(0,x.jsxs)(xW,{title:`Top Tools · Most Recent 200 Sessions`,children:[v.length===0?(0,x.jsx)($,{icon:`code`,title:`No tool data yet`,subtitle:`Tool usage data will appear after coding sessions.`}):(0,x.jsx)(`div`,{className:`min-w-0`,style:{height:`${Math.max(176,v.length*28+40)}px`},children:(0,x.jsx)(np,{width:`100%`,height:`100%`,minWidth:1,minHeight:1,children:(0,x.jsxs)(tV,{data:v,layout:`vertical`,children:[(0,x.jsx)(hI,{stroke:aW,strokeDasharray:`3 3`}),(0,x.jsx)(YR,{type:`number`,tick:iW,stroke:aW}),(0,x.jsx)(uz,{type:`category`,dataKey:`tool`,tick:iW,tickFormatter:Ei,stroke:aW,width:120}),(0,x.jsx)(Yk,{contentStyle:oW,itemStyle:sW,labelFormatter:e=>Ei(String(e))}),(0,x.jsx)(OR,{dataKey:`count`,radius:[0,3,3,0],children:v.map(e=>(0,x.jsx)(Xk,{fill:mW(Ei(e.tool)),fillOpacity:.8},e.tool))})]})})}),b>0&&(0,x.jsxs)(`div`,{className:`text-[10px] text-ink-muted italic mt-1`,children:[`+`,b,` more tool`,b===1?``:`s`,` not shown`]})]})]}),(0,x.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 mt-3`,children:[s.data&&s.data.days.length>0&&(0,x.jsx)(xW,{title:`Activity · Last 12 Weeks`,children:(0,x.jsx)(EH,{variant:`grid`,buckets:[],maxCount:s.data.maxCount,days:s.data.days,ariaLabel:`Daily activity heatmap for the last 12 weeks`})}),(0,x.jsxs)(B,{padding:`md`,className:`flex flex-col`,children:[(0,x.jsxs)(V,{className:`mb-3`,children:[`Peak Concurrent Sessions · Last 30 Days`,C&&`: ${Math.max(...S.map(e=>e.peak))}`]}),C?(0,x.jsx)(`div`,{className:`flex-1 flex items-end justify-center`,children:(0,x.jsx)(VW,{data:S})}):(0,x.jsx)($,{icon:`code`,title:`No concurrent sessions yet`,subtitle:`Run two or more Claude Code sessions at the same time to populate this chart.`})]})]}),(0,x.jsxs)(`div`,{className:`mt-3 space-y-3`,children:[(0,x.jsx)(AW,{data:o.data,isError:o.isError}),(0,x.jsx)(kW,{data:a.data,isError:a.isError})]}),(0,x.jsx)(`div`,{className:`mt-3`,children:(0,x.jsx)(yW,{data:l.data})}),(0,x.jsx)(`div`,{className:`mt-3`,children:(0,x.jsx)(jW,{data:r.data})}),(0,x.jsx)(`div`,{className:`mt-3`,children:(0,x.jsx)(TW,{data:i.data,isError:i.isError})})]})}function xW({title:e,tooltip:t,children:n}){return(0,x.jsxs)(B,{padding:`md`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,x.jsx)(V,{children:e}),t&&(0,x.jsx)(ui,{text:t})]}),(0,x.jsx)(`div`,{className:`mt-3`,children:n})]})}function SW({thisWeek:e,baseline:t}){let n=e.avgEfficiencyScore!==null&&t.avgEfficiencyScore!==null?Math.round((e.avgEfficiencyScore-t.avgEfficiencyScore)*100):null,r=t.avgCostPerSession>0?(e.avgCostPerSession-t.avgCostPerSession)/t.avgCostPerSession:null,i=t.antiPatternRate>0?(e.antiPatternRate-t.antiPatternRate)/t.antiPatternRate:null,a=Math.round(e.sessionsCount-t.sessionsCount);function o(e){return e===null?`text-ink-muted`:e>=5?`text-accent-green`:e<=-5?`text-accent-amber`:`text-ink-muted`}function s(e){return e===null?`text-ink-muted`:e<=-.15?`text-accent-green`:e>=.25?`text-accent-amber`:`text-ink-muted`}function c(e){return e===null?`text-ink-muted`:e<=-.2?`text-accent-green`:e>=.25?`text-accent-amber`:`text-ink-muted`}function l(e){return e===null?`—`:e===0?`0pts`:`${e>0?`↑`:`↓`}${Math.abs(e)}pts`}function u(e){return e===null?`—`:e===0?`0%`:`${e>0?`↑`:`↓`}${Math.abs(Math.round(e*100))}%`}function d(e){return e===0?`0`:e>0?`+${e}`:`${e}`}let f=e.avgEfficiencyScore===null?`—`:Math.round(e.avgEfficiencyScore*100).toString();return(0,x.jsxs)(`div`,{className:`grid grid-cols-3 gap-x-4 gap-y-1 text-xs mb-3`,children:[(0,x.jsx)(`span`,{className:`text-ink-muted`}),(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`This wk`}),(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`vs baseline`}),(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`Efficiency`}),(0,x.jsx)(`span`,{className:`font-mono`,children:f}),(0,x.jsx)(`span`,{className:o(n),children:l(n)}),(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`Cost / session`}),(0,x.jsxs)(`span`,{className:`font-mono`,children:[`$`,e.avgCostPerSession.toFixed(2)]}),(0,x.jsx)(`span`,{className:s(r),children:u(r)}),(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`Anti-pattern rate`}),(0,x.jsxs)(`span`,{className:`font-mono`,children:[(e.antiPatternRate*100).toFixed(1),`%`]}),(0,x.jsx)(`span`,{className:c(i),children:u(i)}),(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`Sessions`}),(0,x.jsx)(`span`,{className:`font-mono`,children:Math.round(e.sessionsCount)}),(0,x.jsx)(`span`,{className:`text-ink-muted`,children:d(a)})]})}function CW(e){return e===`cost_optimization`?`var(--color-accent-amber)`:e===`efficiency`?`var(--color-accent-red)`:e===`prompt_engineering`?`var(--color-accent-blue)`:e===`claudemd`?`var(--color-accent-purple)`:e===`model_selection`?`var(--color-accent-teal)`:`var(--color-ink-muted)`}function wW(e){return e===`high`?`var(--color-accent-amber)`:e===`medium`?`var(--color-accent-blue)`:`var(--color-ink-muted)`}function TW({data:e,isError:t}){if(t)return(0,x.jsx)(xW,{title:`Recommendations`,children:(0,x.jsx)($,{icon:`radar`,title:`Recommendations unavailable`,subtitle:`Connect a full Preflight session to enable recommendations.`})});if(!e)return(0,x.jsx)(xW,{title:`Recommendations`,children:(0,x.jsx)($,{variant:`loading`,title:`Loading recommendations…`})});if(e.recommendations.length===0)return(0,x.jsx)(xW,{title:`Recommendations`,children:(0,x.jsx)($,{icon:`radar`,title:`No recommendations yet`,subtitle:`Keep using Preflight — recommendations appear after a few sessions of data.`})});let n=e.recommendations.filter(e=>e.priority===`high`),r=e.recommendations.filter(e=>e.priority!==`high`);return(0,x.jsx)(xW,{title:`Recommendations`,children:(0,x.jsxs)(`div`,{className:`space-y-3`,children:[n.map(e=>(0,x.jsxs)(`div`,{className:`border-l-2 pl-3`,style:{borderColor:CW(e.category)},children:[(0,x.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,x.jsx)(`span`,{className:`text-sm font-medium text-ink-base`,children:e.title}),e.estimatedSavings&&(0,x.jsx)(`span`,{className:`text-[10px] text-accent-green shrink-0`,children:e.estimatedSavings})]}),(0,x.jsx)(`div`,{className:`text-xs text-ink-muted mt-0.5`,children:e.detail}),(0,x.jsx)(`div`,{className:`text-[10px] text-ink-muted italic mt-0.5`,children:e.evidence})]},e.id)),r.length>0&&(0,x.jsx)(`div`,{className:n.length>0?`border-t border-border-subtle pt-3`:``,children:(0,x.jsx)(`div`,{className:`space-y-2`,children:r.map(e=>(0,x.jsxs)(`div`,{className:`min-w-0`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,x.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full shrink-0`,style:{backgroundColor:wW(e.priority)}}),(0,x.jsx)(`span`,{className:`text-xs text-ink-base`,children:e.title})]}),(0,x.jsx)(`div`,{className:`text-[10px] text-ink-muted mt-0.5 pl-3.5`,children:e.detail})]},e.id))})})]})})}function EW(e){return e.startsWith(`Positive`)?`text-accent-green`:e.startsWith(`Negative`)?`text-accent-red`:`text-accent-amber`}function DW(e){if(!e)return`—`;if(e.value===0)return`0pts`;let t=Math.round(Math.abs(e.value)*100);return`${e.value>0?`↑`:`↓`}${t}pts`}function OW(e){if(!e||e.percentChange==null)return`—`;if(e.value===0)return`0%`;let t=Math.round(Math.abs(e.percentChange));return`${e.value>0?`↑`:`↓`}${t}%`}function kW({data:e,isError:t}){if(t)return(0,x.jsx)(xW,{title:`Instruction File Impact`,children:(0,x.jsx)($,{icon:`radar`,title:`Instruction file impact unavailable`})});if(!e)return(0,x.jsx)(xW,{title:`Instruction File Impact`,children:(0,x.jsx)($,{variant:`loading`,title:`Loading instruction file impact…`})});if(e.message||!e.change||!e.before||!e.after||!e.deltas||!e.verdict)return(0,x.jsx)(xW,{title:`Instruction File Impact`,children:(0,x.jsx)($,{icon:`radar`,title:`No instruction file changes yet`,subtitle:`Edit your instruction file (CLAUDE.md, or your platform's equivalent) to start tracking impact.`})});let n=new Date(e.change.timestamp).toLocaleDateString(void 0,{month:`short`,day:`numeric`}),r=e.before.avgEfficiencyScore===null?null:Math.round(e.before.avgEfficiencyScore*100),i=e.after.avgEfficiencyScore===null?null:Math.round(e.after.avgEfficiencyScore*100);return(0,x.jsxs)(xW,{title:`Instruction File Impact`,children:[(0,x.jsxs)(`div`,{className:`text-xs mb-3`,children:[(0,x.jsx)(`span`,{className:`font-medium ${EW(e.verdict)}`,children:e.verdict}),(0,x.jsxs)(`span`,{className:`text-[10px] text-ink-muted`,children:[` · `,e.change.changeType,` `,e.change.filePath.split(`/`).pop(),` · `,n]})]}),(0,x.jsxs)(`div`,{className:`grid grid-cols-4 gap-x-4 gap-y-1 text-xs`,children:[(0,x.jsx)(`span`,{className:`text-ink-muted`}),(0,x.jsxs)(`span`,{className:`text-ink-muted`,children:[`Before (n=`,e.before.sessionCount,`)`]}),(0,x.jsxs)(`span`,{className:`text-ink-muted`,children:[`After (n=`,e.after.sessionCount,`)`]}),(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`Δ`}),(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`Efficiency`}),(0,x.jsx)(`span`,{className:`font-mono`,children:r??`—`}),(0,x.jsx)(`span`,{className:`font-mono`,children:i??`—`}),(0,x.jsx)(`span`,{className:e.deltas.efficiencyScore==null?`text-ink-muted`:e.deltas.efficiencyScore.improved?`text-accent-green`:`text-accent-amber`,children:DW(e.deltas.efficiencyScore)}),(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`Cost/session`}),(0,x.jsxs)(`span`,{className:`font-mono`,children:[`$`,e.before.avgCostUsd.toFixed(2)]}),(0,x.jsxs)(`span`,{className:`font-mono`,children:[`$`,e.after.avgCostUsd.toFixed(2)]}),(0,x.jsx)(`span`,{className:e.deltas.cost.improved?`text-accent-green`:`text-accent-amber`,children:OW(e.deltas.cost)}),(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`Correction rate`}),(0,x.jsxs)(`span`,{className:`font-mono`,children:[Math.round(e.before.avgCorrectionRate*100),`%`]}),(0,x.jsxs)(`span`,{className:`font-mono`,children:[Math.round(e.after.avgCorrectionRate*100),`%`]}),(0,x.jsx)(`span`,{className:e.deltas.correctionRate.improved?`text-accent-green`:`text-accent-amber`,children:OW(e.deltas.correctionRate)})]}),e.contextTokensForClaudeMd!=null&&e.contextTokensForClaudeMd>0&&(0,x.jsxs)(`div`,{className:`text-[10px] text-ink-muted italic mt-2`,children:[`Instruction file adds ~`,e.contextTokensForClaudeMd.toLocaleString(),` tokens/turn`]})]})}function AW({data:e,isError:t}){if(t)return(0,x.jsx)(xW,{title:`Collaboration Profile`,children:(0,x.jsx)($,{icon:`radar`,title:`Collaboration profile unavailable`})});if(!e)return(0,x.jsx)(xW,{title:`Collaboration Profile`,children:(0,x.jsx)($,{variant:`loading`,title:`Loading collaboration profile…`})});if(e.sessionCount===0)return(0,x.jsx)(xW,{title:`Collaboration Profile`,children:(0,x.jsx)($,{icon:`radar`,title:`No collaboration data yet`,subtitle:`Profile appears after a few sessions.`})});let n=[{name:`Specificity`,key:`specificity`,value:Math.round(e.dimensions.specificity*100),delta:e.teamDeltas.specificity,lowerIsBetter:!1,note:``},{name:`Autonomy`,key:`autonomy`,value:Math.round(e.dimensions.autonomy*100),delta:e.teamDeltas.autonomy,lowerIsBetter:!1,note:``},{name:`Correction-free rate`,key:`correctionRate`,value:Math.round(e.dimensions.correctionRate*100),delta:e.teamDeltas.correctionRate,lowerIsBetter:!1,note:` (higher = better)`},{name:`Task complexity`,key:`taskComplexity`,value:Math.round(e.dimensions.taskComplexity*100),delta:e.teamDeltas.taskComplexity,lowerIsBetter:!1,note:``}];return(0,x.jsxs)(xW,{title:`Collaboration Profile`,children:[(0,x.jsxs)(`div`,{className:`text-xs mb-3`,children:[(0,x.jsx)(`span`,{className:`text-sm font-medium text-ink-base`,children:e.classification}),(0,x.jsxs)(`span`,{className:`text-ink-muted`,children:[` · `,e.sessionCount,` sessions`]})]}),e.developerCount<=1&&(0,x.jsx)(`div`,{className:`text-[10px] text-ink-muted italic mb-2`,children:`No team data yet — "vs team" comparisons below will reflect other developers once their sessions are recorded.`}),(0,x.jsx)(`div`,{className:`min-w-0`,style:{height:`${n.length*28+40}px`},children:(0,x.jsx)(np,{width:`100%`,height:`100%`,minWidth:1,minHeight:1,children:(0,x.jsxs)(tV,{data:n,layout:`vertical`,children:[(0,x.jsx)(hI,{stroke:aW,strokeDasharray:`3 3`}),(0,x.jsx)(YR,{type:`number`,domain:[0,100],tick:iW,stroke:aW,tickFormatter:e=>`${e}%`}),(0,x.jsx)(uz,{type:`category`,dataKey:`name`,tick:iW,stroke:aW,width:110}),(0,x.jsx)(Yk,{contentStyle:oW,formatter:e=>[`${e}%`]}),(0,x.jsx)(OR,{dataKey:`value`,fill:pW,fillOpacity:.8,radius:[0,3,3,0]})]})})}),(0,x.jsx)(`div`,{className:`space-y-1 mt-2`,children:n.map(e=>{let t=Math.round(Math.abs(e.delta)*100),n=e.lowerIsBetter?e.delta<0:e.delta>0,r=e.delta===0?`text-ink-muted`:n?`text-accent-green`:`text-accent-amber`,i=e.delta>0?`+`:e.delta<0?`-`:``,a=e.lowerIsBetter?` (lower = better)`:e.note;return(0,x.jsxs)(`div`,{className:`flex items-center justify-between text-[10px]`,children:[(0,x.jsxs)(`span`,{className:`text-ink-muted`,children:[e.name,a]}),(0,x.jsxs)(`span`,{className:r,children:[i,t,`% vs team`]})]},e.key)})})]})}function jW({data:e}){return e?e.status===`insufficient_data`?(0,x.jsx)(xW,{title:`Personal Coach`,children:(0,x.jsx)(`div`,{className:`text-ink-muted text-xs`,children:e.message})}):(0,x.jsx)(xW,{title:`Personal coach`,children:(0,x.jsxs)(`div`,{className:`text-xs space-y-2`,children:[(0,x.jsx)(SW,{thisWeek:e.thisWeek,baseline:e.baseline}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`span`,{className:`text-accent-cyan font-semibold`,children:`Top recommendation: `}),e.topRecommendation]}),e.highlights.length>0&&(0,x.jsx)(`ul`,{className:`list-disc list-inside text-accent-green`,children:e.highlights.map(e=>(0,x.jsx)(`li`,{children:e},`hl-${e}`))}),e.regressions.length>0&&(0,x.jsx)(`ul`,{className:`list-disc list-inside text-accent-amber`,children:e.regressions.map(e=>(0,x.jsx)(`li`,{children:e},`rg-${e}`))}),e.streaks.length>0&&(0,x.jsx)(`ul`,{className:`list-disc list-inside text-ink-muted`,children:e.streaks.map(e=>(0,x.jsx)(`li`,{children:e},`st-${e}`))})]})}):(0,x.jsx)(xW,{title:`Personal Coach`,children:(0,x.jsx)($,{variant:`loading`,title:`Loading coaching insights…`})})}function MW(e,t){let n=new Map;for(let t of e){if(t.estimatedCostUsd==null||t.startTime==null)continue;let e=new Date(t.startTime),r=`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`;n.set(r,(n.get(r)??0)+t.estimatedCostUsd)}return Array.from(n.entries()).sort((e,t)=>e[0].localeCompare(t[0])).slice(-t).map(([e,t])=>({day:e,cost:Number(t.toFixed(2))}))}function NW(e,t,n=new Date){if(e.length===0)return!1;let r=null;for(let t of e){if(t.startTime==null)continue;let e=new Date(t.startTime).getTime();Number.isNaN(e)||(r===null||e<r)&&(r=e)}if(r===null)return!1;let i=new Date(n);return i.setDate(i.getDate()-(t-1)),i.setHours(0,0,0,0),r>i.getTime()}function PW(e){return e?Object.entries(e.outcomeDistribution).map(([e,t])=>({outcome:e.replace(/_/g,` `),totalCost:Number(t.totalCost.toFixed(2)),count:t.count})).filter(e=>e.totalCost>0).sort((e,t)=>t.totalCost-e.totalCost):[]}function FW(e,t,n=new Date){let r=new Map(e.map(e=>[e.day,e.cost])),i=[];for(let e=t-1;e>=0;e--){let t=new Date(n);t.setDate(t.getDate()-e);let a=`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,`0`)}-${String(t.getDate()).padStart(2,`0`)}`;i.push({day:a,cost:r.get(a)??0})}return i}function IW(e){let t=[];for(let n of e){let e=n.antiPatternCounts??{},r=Object.values(e).reduce((e,t)=>e+t,0);t.push({week:n.week||`?`,count:r})}return t}var LW=.85,RW=.3;function zW(e){let t=new Map;for(let n of e){let e=n.model??`unknown`,r=t.get(e);if(r||(r={sessions:0,effSum:0,effCount:0,successSum:0,successCount:0,costSum:0,costCount:0,blendedCostSum:0,blendedTokensSum:0,lowSuccessSessions:0},t.set(e,r)),r.sessions++,n.efficiencyScore!=null&&(r.effSum+=n.efficiencyScore,r.effCount++),n.toolSuccessRate!=null&&(r.successSum+=n.toolSuccessRate,r.successCount++,n.toolSuccessRate<LW&&r.lowSuccessSessions++),n.estimatedCostUsd!=null){r.costSum+=n.estimatedCostUsd,r.costCount++;let e=(n.tokensInput??0)+(n.tokensOutput??0)+(n.tokensThinking??0)+(n.tokensCacheRead??0)+(n.tokensCacheCreation??0);e>0&&(r.blendedCostSum+=n.estimatedCostUsd,r.blendedTokensSum+=e)}}let n=[];for(let[e,r]of t)n.push({model:e,sessions:r.sessions,avgEfficiency:r.effCount>0?r.effSum/r.effCount:null,avgSuccessRate:r.successCount>0?r.successSum/r.successCount:null,avgCost:r.costCount>0?r.costSum/r.costCount:null,costPerMillionTokens:r.blendedTokensSum>0?r.blendedCostSum/r.blendedTokensSum*1e6:null,flagged:r.successCount>0&&r.lowSuccessSessions/r.successCount>RW});return n.sort((e,t)=>t.sessions-e.sessions)}function BW(e){let t=new Map;for(let n of e)if(n.toolBreakdown)for(let[e,r]of Object.entries(n.toolBreakdown))t.set(e,(t.get(e)??0)+r);return Array.from(t.entries()).map(([e,t])=>({tool:e,count:t})).sort((e,t)=>t.count-e.count).slice(0,8)}function VW({data:e}){let t=e.map(e=>({count:e.peak,tooltip:`${e.date.slice(5)}: ${e.peak}`}));return(0,x.jsx)(pV,{data:t,ariaLabel:`Peak concurrent sessions over ${e.length} days`})}var HW=[{key:`all`,label:`All`},{key:`sensitive_file`,label:`Sensitive files`},{key:`destructive_command`,label:`Destructive`},{key:`external_network`,label:`External network`},{key:`file_deletion`,label:`File deletion`}],UW={critical:`danger`,high:`warning`,medium:`info`},WW={sensitive_file:`Sensitive files`,destructive_command:`Destructive`,external_network:`External network`,file_deletion:`File deletion`,other:`Other`};function GW(e){let t=e.map(e=>JSON.stringify(e)).join(`
64
64
  `),n=new Blob([t],{type:`application/x-ndjson`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`audit-${new Date().toISOString().slice(0,10)}.jsonl`,i.rel=`noopener`,document.body.appendChild(i);try{i.click()}finally{document.body.removeChild(i),URL.revokeObjectURL(r)}}function KW(){let[e,t]=(0,b.useState)(`all`),{data:n,isLoading:r,error:i,refetch:a}=L({queryKey:z.audit,queryFn:()=>dr(),refetchInterval:1e4}),o=n??[],s=e===`all`?o:o.filter(t=>t.classification===e),c=s.slice(0,200);return(0,x.jsxs)(`section`,{children:[(0,x.jsx)(AH,{theme:`audit`}),(0,x.jsxs)(`header`,{className:`flex items-baseline justify-between mb-4`,children:[(0,x.jsx)(`h1`,{className:`text-xl font-semibold gradient-text`,children:`Audit`}),(0,x.jsxs)(Qr,{variant:`secondary`,size:`md`,onClick:()=>GW(c),children:[`Export JSONL (max `,200,` rows)`]})]}),(0,x.jsx)(`div`,{className:`flex gap-2 mb-3 flex-wrap`,children:HW.map(({key:n,label:r})=>(0,x.jsx)(Qr,{variant:e===n?`primary`:`secondary`,size:`sm`,onClick:()=>t(n),children:r},n))}),r&&(0,x.jsx)($,{icon:`clock`,variant:`loading`,title:`Loading...`}),i&&(0,x.jsxs)(`div`,{className:`text-accent-red text-xs flex items-center gap-2`,children:[(0,x.jsx)(`span`,{children:`Error loading audit log.`}),(0,x.jsx)(`button`,{onClick:()=>void a(),className:`text-[10px] text-ink-muted hover:text-ink-base transition-colors`,children:`Retry`})]}),!r&&!i&&s.length>200&&(0,x.jsxs)(`div`,{className:`text-[11px] text-ink-muted mb-2`,children:[`Showing first `,200,` of `,s.length,` entries.`]}),!r&&!i&&(0,x.jsx)(B,{padding:`sm`,tone:`static`,className:`overflow-hidden`,children:(0,x.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,x.jsx)(`thead`,{className:`text-ink-muted bg-surface-3`,children:(0,x.jsxs)(`tr`,{children:[(0,x.jsx)(`th`,{className:`text-left p-2`,children:`When`}),(0,x.jsx)(`th`,{className:`text-left p-2`,children:`Tool`}),(0,x.jsx)(`th`,{className:`text-left p-2`,children:`Target`}),(0,x.jsx)(`th`,{className:`text-left p-2`,children:`Classification`}),(0,x.jsx)(`th`,{className:`text-left p-2`,children:`Agent`}),(0,x.jsx)(`th`,{className:`text-left p-2`,children:`Session`})]})}),(0,x.jsxs)(`tbody`,{children:[s.length===0&&(0,x.jsx)(`tr`,{children:(0,x.jsx)(`td`,{colSpan:6,className:`p-3 text-ink-muted text-center`,children:`No matching entries.`})}),c.map(e=>(0,x.jsxs)(`tr`,{className:`border-t border-border-subtle`,children:[(0,x.jsx)(`td`,{className:`p-2 tabular-nums`,children:new Date(e.ts).toLocaleString(void 0,{month:`short`,day:`numeric`,hour:`numeric`,minute:`2-digit`})}),(0,x.jsx)(`td`,{className:`p-2`,children:e.tool}),(0,x.jsx)(`td`,{className:`p-2 font-mono text-[11px] break-all`,title:e.target,children:e.target}),(0,x.jsx)(`td`,{className:`p-2`,children:(0,x.jsx)(ni,{tone:e.severity?UW[e.severity]??`neutral`:`neutral`,size:`sm`,children:WW[e.classification]??e.classification})}),(0,x.jsx)(`td`,{className:`p-2 text-ink-subtle`,title:e.agentId,children:e.agentType??e.agentId??`—`}),(0,x.jsx)(`td`,{className:`p-2 text-ink-subtle`,children:e.sessionId?(0,x.jsx)(Zt,{href:`/sessions?session=${encodeURIComponent(e.sessionId)}`,className:`text-accent-cyan hover:underline transition-colors duration-150`,children:e.sessionId}):`—`})]},e.id))]})]})})]})}function qW(e,t){if(t===null)return null;let n=e-t;return n===0?`same as last week`:n>0?`+${n} vs last week`:`${n} vs last week`}var JW={info:`border-l-accent-blue bg-accent-blue/5`,warning:`border-l-accent-amber bg-accent-amber/5`,critical:`border-l-accent-red bg-accent-red/5`},YW={info:`info`,warning:`warning`,critical:`danger`},XW={resolved:`text-accent-green`,aborted:`text-accent-red`,pending:`text-accent-amber`},ZW={merge_conflict:`bg-accent-red/20 text-accent-red`,rebase_conflict:`bg-accent-red/20 text-accent-red`,merge_abort:`bg-accent-amber/20 text-accent-amber`,rebase_abort:`bg-accent-amber/20 text-accent-amber`,force_push:`bg-accent-red/20 text-accent-red`,reset_hard:`bg-accent-amber/20 text-accent-amber`,commit:`bg-accent-green/20 text-accent-green`,push:`bg-accent-blue/20 text-accent-blue`,pull:`bg-accent-blue/20 text-accent-blue`};function QW(e){return e===null?`—`:e<1e3?`${e}ms`:e<6e4?`${(e/1e3).toFixed(1)}s`:e<36e5?`${(e/6e4).toFixed(1)}m`:e<864e5?`${(e/36e5).toFixed(1)}h`:`${(e/864e5).toFixed(1)}d`}function $W(e){return e.replace(/_/g,` `)}function eG(e){let t=new Date(e);if(Number.isNaN(t.getTime()))return`—`;let n=t.toLocaleTimeString(void 0,{hour:`numeric`,minute:`2-digit`,second:`2-digit`});return t.toDateString()===new Date().toDateString()?n:`${t.toLocaleDateString(void 0,{month:`short`,day:`numeric`})} ${n}`}function tG(e){let t=Date.now()-e;if(t<0||t<1e3)return`as of just now`;let n=Math.floor(t/1e3);if(n<60)return`as of ${n}s ago`;let r=Math.floor(n/60);if(r<60)return`as of ${r}m ago`;let i=Math.floor(r/60);return i<24?`as of ${i}h ago`:`as of ${Math.floor(i/24)}d ago`}function nG(e,t){let n=e=>new Date(e).toLocaleDateString(void 0,{month:`short`,day:`numeric`});return`${n(e)} – ${n(t-1)}`}function rG(e){return e===null?`neutral`:e>20?`bad`:e>5?`warn`:`good`}function iG({score:e}){if(e===null)return(0,x.jsx)(`div`,{className:`flex items-center justify-center w-20 h-20 rounded-full border-4 border-border-medium`,children:(0,x.jsx)(`span`,{className:`text-ink-muted text-xs`,children:`N/A`})});let t=Math.max(0,Math.min(100,e)),[n,r]=t>=80?[`text-accent-green`,`border-accent-green`]:t>=60?[`text-accent-amber`,`border-accent-amber`]:[`text-accent-red`,`border-accent-red`],i=2*Math.PI*34,a=i-t/100*i;return(0,x.jsxs)(`div`,{className:`relative w-20 h-20`,children:[(0,x.jsxs)(`svg`,{className:`w-20 h-20 -rotate-90`,viewBox:`0 0 80 80`,children:[(0,x.jsx)(`circle`,{cx:`40`,cy:`40`,r:`34`,fill:`none`,stroke:`rgba(255,255,255,0.08)`,strokeWidth:`6`}),(0,x.jsx)(`circle`,{cx:`40`,cy:`40`,r:`34`,fill:`none`,className:r,stroke:`currentColor`,strokeWidth:`6`,strokeLinecap:`round`,strokeDasharray:i,strokeDashoffset:a,style:{transition:`stroke-dashoffset 0.8s ease-out`}})]}),(0,x.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center text-lg font-bold ${n}`,children:e})]})}function aG(e){return e.length===1?`/sessions?session=${encodeURIComponent(e[0])}`:`/sessions?sessionIds=${e.map(encodeURIComponent).join(`,`)}`}function oG(e,t){return e===null&&t===null?0:e===null?1:t===null?-1:t-e}function sG(e){let t=new Map;for(let n of e){let e=t.get(n.identity.repoKey);e?e.push(n):t.set(n.identity.repoKey,[n])}let n=[];for(let[e,r]of t){let t=[...r].sort((e,t)=>oG(e.metrics.lastActivityMs,t.metrics.lastActivityMs)),i=t.reduce((e,t)=>{let n=t.metrics.lastActivityMs;return n===null?e:e===null||n>e?n:e},null);n.push({repoKey:e,repoName:t[0]?.identity.repoName??null,rows:t,lastActivityMs:i,sessionIds:[...new Set(t.flatMap(e=>e.metrics.sessionIds))]})}return n.sort((e,t)=>oG(e.lastActivityMs,t.lastActivityMs))}function cG({rows:e,scope:t,onSelectRepo:n,onSelectWorktree:r}){let[,i]=Wt(),[a,o]=(0,b.useState)(new Set);if(e.length===0)return(0,x.jsx)($,{icon:`code`,title:`No git activity in this window`});let s=sG(e),c=typeof t==`object`&&`repo`in t?t.repo:null,l=typeof t==`object`&&`worktree`in t?t.worktree:null,u=e=>{o(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return(0,x.jsx)(`div`,{className:`max-h-64 overflow-auto`,children:(0,x.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,x.jsx)(`thead`,{className:`text-ink-muted bg-bg-panel sticky top-0`,children:(0,x.jsxs)(`tr`,{children:[(0,x.jsx)(`th`,{className:`text-left p-2`,children:`Repo / worktree`}),(0,x.jsx)(`th`,{className:`text-left p-2`,children:`Branch`}),(0,x.jsx)(`th`,{className:`text-left p-2`,children:`Commits`}),(0,x.jsx)(`th`,{className:`text-left p-2`,children:`Conflicts`}),(0,x.jsx)(`th`,{className:`text-left p-2`,children:`Best practices`}),(0,x.jsx)(`th`,{className:`text-left p-2`,children:`Sessions`})]})}),(0,x.jsx)(`tbody`,{children:s.map(e=>{let t=a.has(e.repoKey),o=c===e.repoKey&&l===null,s=e.rows[0].identity;return(0,x.jsxs)(b.Fragment,{children:[(0,x.jsxs)(`tr`,{className:`border-t border-border-subtle ${o?`bg-accent-blue/10`:``}`,children:[(0,x.jsx)(`td`,{className:`p-2 whitespace-nowrap`,colSpan:5,children:(0,x.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,x.jsx)(`button`,{type:`button`,onClick:()=>u(e.repoKey),"aria-label":t?`Expand`:`Collapse`,"aria-expanded":!t,className:`text-ink-muted hover:text-ink-base w-4 shrink-0 text-center`,children:t?`▸`:`▾`}),(0,x.jsxs)(`button`,{type:`button`,onClick:()=>n(s),className:`font-mono font-semibold hover:underline ${o?`text-accent-blue`:`text-ink-base`}`,children:[o&&(0,x.jsx)(`span`,{"aria-hidden":`true`,className:`mr-1`,children:`●`}),e.repoName??e.repoKey]}),(0,x.jsxs)(`span`,{className:`text-ink-muted text-[10px]`,children:[e.rows.length,` worktree`,e.rows.length===1?``:`s`]})]})}),(0,x.jsx)(`td`,{className:`p-2 tabular-nums`,children:e.sessionIds.length>0?(0,x.jsx)(`button`,{type:`button`,onClick:()=>i(aG(e.sessionIds)),className:`text-accent-blue hover:underline`,title:e.rows.reduce((e,t)=>e+t.metrics.sessionIds.length,0)>e.sessionIds.length?`${e.sessionIds.length} distinct sessions — some touched more than one worktree`:`View these sessions`,children:e.sessionIds.length}):(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`—`})})]}),!t&&e.rows.map(e=>{let t=e.metrics.bestPractices.filter(e=>e.status!==`unknown`&&e.status!==`n/a`),n=e.metrics.bestPractices.filter(e=>e.status===`pass`).length,a=e.metrics.mergeConflicts+e.metrics.rebaseConflicts,o=l===e.identity.worktreeKey;return(0,x.jsxs)(`tr`,{className:`border-t border-border-subtle ${o?`bg-accent-blue/10`:``}`,children:[(0,x.jsx)(`td`,{className:`p-2 pl-8 whitespace-nowrap`,children:(0,x.jsxs)(`button`,{type:`button`,onClick:()=>r(e.identity),className:`font-mono hover:underline ${o?`text-accent-blue font-semibold`:`text-ink-subtle`}`,children:[o&&(0,x.jsx)(`span`,{"aria-hidden":`true`,className:`mr-1`,children:`●`}),e.identity.worktreeLabel]})}),(0,x.jsx)(`td`,{className:`p-2 font-mono text-ink-subtle whitespace-nowrap`,children:e.identity.branch??`—`}),(0,x.jsx)(`td`,{className:`p-2 tabular-nums`,children:e.metrics.commitCount}),(0,x.jsx)(`td`,{className:`p-2 tabular-nums`,children:a}),(0,x.jsx)(`td`,{className:`p-2 tabular-nums text-ink-subtle`,children:t.length>0?`${n}/${t.length}`:`—`}),(0,x.jsx)(`td`,{className:`p-2 tabular-nums`,children:e.metrics.sessionIds.length>0?(0,x.jsx)(`button`,{type:`button`,onClick:()=>i(aG(e.metrics.sessionIds)),className:`text-accent-blue hover:underline`,title:`View these sessions`,children:e.metrics.sessionIds.length}):(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`—`})})]},e.identity.worktreeKey)})]},e.repoKey)})})]})})}function lG(){let[,e]=Wt(),[t,n]=(0,b.useState)(`all`),[r,i]=(0,b.useState)(null),{data:a,isLoading:o,error:s}=L({queryKey:z.gitEfficiency(`week`,Tr(t)),queryFn:()=>Er(`week`,Tr(t)),refetchInterval:5e3}),{data:c}=L({queryKey:z.gitEfficiency(`previous_week`,Tr(t)),queryFn:()=>Er(`previous_week`,Tr(t)),refetchInterval:6e4}),{data:l}=L({queryKey:z.gitEfficiency(`30`,`all`),queryFn:()=>Er(`30`,`all`),refetchInterval:3e4}),u=e=>{n({repo:e.repoKey}),i(e)},d=e=>{n({worktree:e.worktreeKey}),i(e)},f=()=>{n(`all`),i(null)},p=()=>{r&&n({repo:r.repoKey})};if(o)return(0,x.jsx)($,{icon:`clock`,variant:`loading`,title:`Loading...`});if(s)return(0,x.jsx)(`div`,{className:`text-accent-red text-xs`,children:`Error loading git efficiency data.`});if(!a)return(0,x.jsx)($,{icon:`clock`,variant:`loading`,title:`Loading...`});let m=a.metrics,h=m.conflictHistory.filter(e=>e.resolution===`resolved`).length,g=c?.metrics.commitCount??null,_=c?.metrics.prMetrics.created??null,v=c?c.metrics.mergeConflicts+c.metrics.rebaseConflicts:null,y=m.mergeConflicts+m.rebaseConflicts;return(0,x.jsxs)(`section`,{children:[(0,x.jsx)(AH,{theme:`git`}),(0,x.jsxs)(`header`,{className:`flex items-end justify-between mb-3`,children:[(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`h1`,{className:`text-xl font-semibold gradient-text`,children:`Git Efficiency`}),(0,x.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-1 text-[11px]`,children:[t===`all`?(0,x.jsx)(`span`,{className:`text-ink-subtle`,children:`All repos`}):(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(`button`,{type:`button`,onClick:f,className:`text-ink-muted hover:text-ink-base hover:underline`,children:`All repos`}),(0,x.jsx)(`span`,{"aria-hidden":`true`,className:`text-ink-muted`,children:`/`}),`worktree`in t?(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(`button`,{type:`button`,onClick:p,className:`font-mono text-ink-muted hover:text-ink-base hover:underline`,children:r?.repoName??r?.repoKey??`repo`}),(0,x.jsx)(`span`,{"aria-hidden":`true`,className:`text-ink-muted`,children:`/`}),(0,x.jsx)(`span`,{className:`font-mono text-ink-subtle`,children:r?.worktreeLabel??t.worktree})]}):(0,x.jsx)(`span`,{className:`font-mono text-ink-subtle`,children:r?.repoName??t.repo})]}),t!==`all`&&r?.repoName&&(0,x.jsx)(`button`,{type:`button`,onClick:()=>e(`/sessions?repo=${encodeURIComponent(r.repoName)}`),className:`text-accent-blue hover:underline ml-1`,children:`View sessions →`})]})]}),(0,x.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,x.jsxs)(`div`,{className:`text-center`,children:[(0,x.jsx)(V,{as:`div`,className:`mb-1`,children:`Prevention`}),(0,x.jsx)(iG,{score:m.preventionScore})]}),(0,x.jsxs)(`div`,{className:`text-center`,children:[(0,x.jsx)(V,{as:`div`,className:`mb-1`,children:`Efficiency`}),(0,x.jsx)(iG,{score:m.efficiencyScore})]})]})]}),(0,x.jsx)(cV,{index:0,className:`mb-3`,children:(0,x.jsxs)(B,{padding:`md`,children:[(0,x.jsx)(ci,{title:`Repos & Worktrees`,action:(0,x.jsx)(`span`,{className:`text-[11px] text-ink-muted`,children:(()=>{let e=l?.rows??[],t=new Set(e.map(e=>e.identity.repoKey)).size;return`${t} repo${t===1?``:`s`} · ${e.length} worktree${e.length===1?``:`s`}`})()})}),(0,x.jsx)(`div`,{className:`mb-2 text-[11px] text-ink-muted`,children:l?`Last 30 days (${nG(l.since,l.until)})`:`Loading…`}),l?(0,x.jsx)(cG,{rows:l.rows,scope:t,onSelectRepo:u,onSelectWorktree:d}):(0,x.jsx)($,{icon:`clock`,variant:`loading`,title:`Loading...`})]})}),m.totalGitCommands===0?(0,x.jsx)($,{icon:`code`,title:`No Git activity yet`,subtitle:`Git efficiency metrics will appear here as git commands are executed during the session.`}):(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(cV,{index:1,className:`mb-3`,children:(0,x.jsxs)(B,{padding:`lg`,tone:`elevated`,glow:`green`,children:[(0,x.jsxs)(`div`,{className:`mb-3 text-[11px] text-ink-muted`,children:[`Last 7 days (`,nG(a.since,a.until),`) · compared to the previous 7 days`]}),(0,x.jsxs)(`div`,{className:`grid grid-cols-2 sm:grid-cols-4 gap-4`,children:[(0,x.jsx)(sV,{label:`commits`,hero:!0,value:String(m.commitCount),sub:qW(m.commitCount,g)??void 0,animate:!0,numericValue:m.commitCount}),(0,x.jsx)(sV,{label:`PRs created`,tone:m.prMetrics.created>0?`good`:`neutral`,value:String(m.prMetrics.created),sub:qW(m.prMetrics.created,_)??void 0,animate:!0,numericValue:m.prMetrics.created}),(0,x.jsx)(sV,{label:`conflicts`,tone:y>0?`bad`:`good`,value:String(y),sub:[y===0?`clean session`:`${h} resolved`,qW(y,v)].filter(e=>e!==null).join(` · `),animate:!0,numericValue:y}),a.scope.kind===`worktree`?(0,x.jsx)(sV,{label:`behind ${m.liveState?.defaultBranch??`upstream`}`,tone:rG(m.liveState?.behind??null),value:m.liveState?.behind==null?`—`:String(m.liveState.behind),sub:m.liveState?.measuredAtMs==null?void 0:tG(m.liveState.measuredAtMs),animate:!0,numericValue:m.liveState?.behind??null}):(0,x.jsx)(sV,{label:`worst behind`,tone:rG(a.worstBehind?.behind??null),value:a.worstBehind?String(a.worstBehind.behind):`—`,sub:a.worstBehind?a.worstBehind.identity.repoName?`${a.worstBehind.identity.worktreeLabel} · ${a.worstBehind.identity.repoName}`:a.worstBehind.identity.worktreeLabel:void 0,animate:!0,numericValue:a.worstBehind?.behind??null})]}),(0,x.jsxs)(`div`,{className:`mt-3 text-[11px] text-ink-muted leading-relaxed`,children:[(0,x.jsx)(`strong`,{className:`text-ink-subtle`,children:`Conflicts`}),` = merge/rebase/pull attempts that git itself reported a real conflict on (not a live GitHub check).`,` `,(0,x.jsx)(`strong`,{className:`text-ink-subtle`,children:`Behind`}),` = commits your branch is missing vs. its upstream (or the repo's default branch), as of your last local`,` `,(0,x.jsx)(`code`,{className:`font-mono`,children:`git fetch`}),` — Preflight never fetches on your behalf, so this can be stale if you haven't synced recently.`]})]})}),m.commitCount>=2&&(0,x.jsx)(cV,{index:2,className:`mb-3`,children:(0,x.jsxs)(B,{padding:`md`,children:[(0,x.jsx)(ci,{title:`Velocity & Workflow`,subtitle:`How your commits were paced — steady, incremental work is easier to review and revert than one big batch at the end.`}),(0,x.jsxs)(`div`,{className:`grid grid-cols-2 sm:grid-cols-4 gap-3`,children:[(0,x.jsx)(sV,{label:`Avg time between commits`,value:QW(m.velocityMetrics.avgTimeBetweenCommitsMs)}),(0,x.jsx)(sV,{label:`Longest gap`,value:QW(m.velocityMetrics.longestGapMs),sub:`biggest idle stretch between commits`}),(0,x.jsx)(sV,{label:`Commit bursts`,value:String(m.velocityMetrics.commitBurstCount),sub:`3+ commits within 2 min — often splitting one change up after the fact`}),(0,x.jsx)(sV,{label:`Worktree ops`,value:String(m.velocityMetrics.worktreeCount),sub:`git worktree add/remove commands run`})]}),m.velocityMetrics.buildBeforePush!==null&&(0,x.jsxs)(`div`,{className:`mt-3 text-xs`,children:[(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`Verified before push: `}),m.velocityMetrics.buildBeforePush?(0,x.jsx)(`span`,{className:`text-accent-green`,children:`yes (build/test ran first)`}):(0,x.jsx)(`span`,{className:`text-accent-amber`,children:`no build/test detected before push`})]})]})}),(m.prMetrics.created>0||m.prMetrics.merged>0||m.prMetrics.checksViewed>0)&&(0,x.jsx)(cV,{index:3,className:`mb-3`,children:(0,x.jsxs)(B,{padding:`md`,children:[(0,x.jsx)(ci,{title:`Pull Requests`,subtitle:`Counts commands you (or the AI) ran — gh CLI and MCP PR tools — not live GitHub state.`}),(0,x.jsxs)(`div`,{className:`grid grid-cols-2 sm:grid-cols-4 gap-3`,children:[(0,x.jsx)(sV,{label:`PRs created`,value:String(m.prMetrics.created),tone:m.prMetrics.created>0?`good`:`neutral`}),(0,x.jsx)(sV,{label:`PRs merged`,value:String(m.prMetrics.merged),tone:m.prMetrics.merged>0?`good`:`neutral`}),(0,x.jsx)(sV,{label:`CI checks viewed`,value:String(m.prMetrics.checksViewed),sub:"times you ran `gh pr checks`"}),(0,x.jsx)(sV,{label:`Time to PR`,value:QW(m.prMetrics.avgTimeToCreateMs),sub:m.prMetrics.avgTimeToCreateMs===null?`no commit found in this window before the PR was created`:void 0})]}),m.prMetrics.prActivity.length>0&&(0,x.jsxs)(`div`,{className:`mt-3`,children:[(0,x.jsx)(V,{as:`h3`,className:`mb-2`,children:`Activity`}),(0,x.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:m.prMetrics.prActivity.map(e=>{let t=e.action===`create`?`success`:e.action===`merge`?`info`:`neutral`;return(0,x.jsxs)(ni,{tone:t,size:`sm`,children:[e.action,e.prNumber?` #${e.prNumber}`:``]},`${e.timestamp}-${e.action}`)})})]})]})}),(m.mergeConflicts>0||m.rebaseConflicts>0)&&(0,x.jsx)(cV,{index:4,className:`mb-3`,children:(0,x.jsxs)(B,{padding:`md`,children:[(0,x.jsx)(ci,{title:`Conflict Resolution`}),(0,x.jsxs)(`div`,{className:`grid grid-cols-2 sm:grid-cols-4 gap-3`,children:[(0,x.jsx)(sV,{label:`Resolution rate`,value:m.conflictResolutionRate===null?`—`:`${Math.round(m.conflictResolutionRate*100)}%`}),(0,x.jsx)(sV,{label:`Avg resolution time`,value:QW(m.avgConflictResolutionMs)}),(0,x.jsx)(sV,{label:`Aborted ops`,value:String(m.abortedOperations)}),(0,x.jsx)(sV,{label:`Stale branch pulls`,value:String(m.staleBranchPulls)})]}),m.conflictHistory.length>0&&(0,x.jsxs)(`div`,{className:`mt-3`,children:[(0,x.jsx)(V,{as:`h3`,className:`mb-2`,children:`Conflict History`}),(0,x.jsx)(`div`,{className:`space-y-1`,children:m.conflictHistory.map(e=>(0,x.jsxs)(`div`,{className:`flex items-center gap-3 text-xs py-1 border-t border-border-subtle`,children:[(0,x.jsx)(`span`,{className:`tabular-nums text-ink-subtle w-28 shrink-0`,children:new Date(e.timestamp).toLocaleTimeString(void 0,{hour:`numeric`,minute:`2-digit`,second:`2-digit`})}),(0,x.jsx)(`span`,{className:`font-medium ${XW[e.resolution]}`,children:e.resolution}),(0,x.jsx)(`span`,{className:`text-ink-muted`,children:QW(e.resolutionTimeMs)}),(0,x.jsx)(`span`,{className:`text-ink-subtle font-mono text-[11px] truncate`,children:e.command})]},`${e.timestamp}-${e.command}`))})]})]})}),m.conflictResolutionStrategy.totalResolutions>0&&(0,x.jsx)(cV,{index:5,className:`mb-3`,children:(0,x.jsxs)(B,{padding:`md`,children:[(0,x.jsx)(ci,{title:`Conflict Resolution Strategy`}),(0,x.jsxs)(`div`,{className:`grid grid-cols-2 sm:grid-cols-4 gap-3`,children:[(0,x.jsx)(sV,{label:`Accept ours`,value:String(m.conflictResolutionStrategy.oursCount)}),(0,x.jsx)(sV,{label:`Accept theirs`,value:String(m.conflictResolutionStrategy.theirsCount)}),(0,x.jsx)(sV,{label:`Manual merge`,value:String(m.conflictResolutionStrategy.manualMergeCount)}),(0,x.jsx)(sV,{label:`Cherry-picks`,value:String(m.conflictResolutionStrategy.cherryPickCount)})]})]})}),(m.resetHards>0||m.discardedChanges>0||m.forcePushes>0)&&(0,x.jsx)(cV,{index:6,className:`mb-3`,children:(0,x.jsxs)(B,{padding:`md`,children:[(0,x.jsx)(ci,{title:`Destructive Operations`}),(0,x.jsxs)(`div`,{className:`grid grid-cols-3 gap-3`,children:[(0,x.jsx)(sV,{label:`Hard resets`,value:String(m.resetHards)}),(0,x.jsx)(sV,{label:`Discarded changes`,value:String(m.discardedChanges)}),(0,x.jsx)(sV,{label:`Force pushes`,value:String(m.forcePushes)})]})]})}),m.bestPractices.length>0&&(0,x.jsx)(cV,{index:7,className:`mb-3`,children:(0,x.jsxs)(B,{padding:`md`,children:[(0,x.jsx)(ci,{title:`Best Practices`,action:(0,x.jsx)(`span`,{className:`text-[11px] text-ink-muted`,children:(()=>{let e=m.bestPractices.filter(e=>e.status!==`unknown`&&e.status!==`n/a`).length;return e===0?`No data yet`:`${m.bestPractices.filter(e=>e.status===`pass`).length}/${e} passing`})()})}),(0,x.jsxs)(`div`,{className:`flex flex-wrap gap-1.5 mb-2`,children:[m.bestPractices.filter(e=>e.status===`pass`).map(e=>(0,x.jsxs)(ni,{tone:`success`,size:`sm`,bordered:!0,children:[(0,x.jsx)(`span`,{children:`✓`}),` `,e.label]},e.id)),m.bestPractices.filter(e=>e.status===`unknown`||e.status===`n/a`).map(e=>(0,x.jsxs)(ni,{tone:`neutral`,size:`sm`,bordered:!0,children:[(0,x.jsx)(`span`,{children:`●`}),` `,e.label]},e.id))]}),m.bestPractices.filter(e=>e.status===`fail`||e.status===`warn`).map(e=>(0,x.jsxs)(`div`,{className:`flex items-start gap-2 px-2.5 py-2 rounded-lg mt-1.5 ${e.status===`fail`?`bg-accent-red/5 border border-accent-red/20`:`bg-accent-amber/5 border border-accent-amber/20`}`,children:[(0,x.jsx)(`span`,{className:`shrink-0 mt-0.5 text-xs`,children:e.status===`fail`?(0,x.jsx)(`span`,{className:`text-accent-red`,children:`✗`}):(0,x.jsx)(`span`,{className:`text-accent-amber`,children:`⚠`})}),(0,x.jsxs)(`div`,{className:`min-w-0`,children:[(0,x.jsx)(`div`,{className:`text-xs font-medium text-ink-base`,children:e.label}),(0,x.jsx)(`div`,{className:`text-[11px] text-ink-muted mt-0.5 leading-relaxed`,children:e.detail})]})]},e.id))]})}),m.suggestions.length>0&&(0,x.jsx)(cV,{index:8,className:`mb-3`,children:(0,x.jsxs)(B,{padding:`md`,children:[(0,x.jsx)(ci,{title:`Suggestions`}),(0,x.jsx)(`div`,{className:`space-y-2`,children:m.suggestions.map((e,t)=>(0,x.jsx)(`div`,{className:`border-l-[3px] rounded-r-lg px-3 py-2 ${JW[e.severity]}`,children:(0,x.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,x.jsx)(ni,{tone:YW[e.severity],size:`sm`,className:`font-semibold`,children:e.severity}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`p`,{className:`text-xs text-ink-base`,children:e.message}),(0,x.jsx)(`p`,{className:`text-[11px] text-ink-muted mt-0.5`,children:e.evidence})]})]})},`${e.category}-${e.severity}-${t}`))})]})}),(0,x.jsx)(cV,{index:9,children:(0,x.jsxs)(B,{padding:`md`,children:[(0,x.jsx)(ci,{title:`Recent Git Activity`}),(0,x.jsx)(`div`,{className:`max-h-64 overflow-auto`,children:(0,x.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,x.jsx)(`thead`,{className:`text-ink-muted bg-bg-panel sticky top-0`,children:(0,x.jsxs)(`tr`,{children:[(0,x.jsx)(`th`,{className:`text-left p-2`,children:`Time`}),(0,x.jsx)(`th`,{className:`text-left p-2`,children:`Type`}),(0,x.jsx)(`th`,{className:`text-left p-2`,children:`Repo`}),(0,x.jsx)(`th`,{className:`text-left p-2`,children:`Detail`}),(0,x.jsx)(`th`,{className:`text-left p-2`,children:`Duration`}),(0,x.jsx)(`th`,{className:`text-left p-2`,children:`Status`})]})}),(0,x.jsx)(`tbody`,{children:[...m.gitCommandTimeline].sort((e,t)=>t.timestamp-e.timestamp).slice(0,30).map(e=>(0,x.jsxs)(`tr`,{className:`border-t border-border-subtle`,children:[(0,x.jsx)(`td`,{className:`p-2 tabular-nums text-ink-subtle whitespace-nowrap`,children:eG(e.timestamp)}),(0,x.jsx)(`td`,{className:`p-2`,children:(0,x.jsx)(`span`,{className:`px-1.5 py-0.5 rounded text-[10px] font-medium ${ZW[e.type]??`bg-surface-8 text-ink-subtle`}`,children:$W(e.type)})}),(0,x.jsx)(`td`,{className:`p-2 text-ink-subtle whitespace-nowrap`,children:e.repo?e.repo.split(`/`).pop():`—`}),(0,x.jsx)(`td`,{className:`p-2 max-w-xs truncate`,title:e.subject??e.command??void 0,children:e.url?(0,x.jsx)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,className:`text-accent-blue hover:underline`,children:e.subject??`view commit`}):e.subject??e.command??`—`}),(0,x.jsx)(`td`,{className:`p-2 tabular-nums text-ink-subtle`,children:QW(e.durationMs)}),(0,x.jsx)(`td`,{className:`p-2`,children:e.success?(0,x.jsx)(`span`,{className:`text-accent-green`,children:`ok`}):(0,x.jsx)(`span`,{className:`text-accent-red`,children:`fail`})})]},`${e.type}-${e.timestamp}`))})]})})]})})]})]})}function uG({label:e,value:t}){return(0,x.jsxs)(`div`,{className:`flex items-center gap-3 py-1.5`,children:[(0,x.jsx)(`span`,{className:`text-xs text-ink-muted w-36 shrink-0`,children:e}),(0,x.jsx)(`span`,{className:`text-xs font-mono text-ink-subtle bg-surface-3 px-2 py-0.5 rounded-md`,children:t??`—`})]})}function dG({label:e,value:t,onChange:n,placeholder:r,min:i}){return(0,x.jsxs)(`div`,{className:`flex items-center gap-3 py-1.5`,children:[(0,x.jsx)(`label`,{className:`text-xs text-ink-muted w-36 shrink-0`,children:e}),(0,x.jsx)(`input`,{type:`number`,min:i,step:`any`,value:t??``,placeholder:r??`unlimited`,onChange:e=>{let t=e.target.value;n(t===``?null:Number(t))},className:`text-xs bg-surface-3 border border-border-subtle rounded-md px-2 py-1 w-32 focus:outline-none focus:border-accent-green text-ink-base placeholder:text-ink-muted`})]})}var fG={ok:`●`,warn:`▲`,fail:`✗`,skip:`–`},pG={ok:`text-accent-green`,warn:`text-accent-amber`,fail:`text-accent-red`,skip:`text-ink-muted`};function mG(){let{data:e,isLoading:t,isError:n,refetch:r}=L({queryKey:z.diagnostics,queryFn:()=>Lr(),refetchInterval:6e4,staleTime:55e3}),i=e??[],a=i.some(e=>e.status===`fail`||e.status===`warn`);return(0,x.jsxs)(B,{padding:`md`,className:`mb-4`,children:[(0,x.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,x.jsx)(ci,{title:`System Health`}),(0,x.jsx)(`button`,{onClick:()=>void r(),className:`text-[10px] text-ink-muted hover:text-ink-base transition-colors`,children:`Re-check`})]}),t&&(0,x.jsx)($,{icon:`clock`,variant:`loading`,title:`Checking system…`}),n&&(0,x.jsx)(`div`,{className:`text-xs text-accent-red`,children:`Failed to load diagnostics.`}),!t&&!n&&!a&&(0,x.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-accent-green`,children:[(0,x.jsx)(`span`,{children:`●`}),(0,x.jsx)(`span`,{children:`System healthy`})]}),!t&&!n&&a&&(0,x.jsx)(`div`,{className:`space-y-1.5`,children:i.map(e=>(0,x.jsxs)(`div`,{children:[(0,x.jsxs)(`div`,{className:`flex items-baseline gap-2 text-xs`,children:[(0,x.jsx)(`span`,{className:`shrink-0 ${pG[e.status]??`text-ink-muted`}`,children:fG[e.status]??`?`}),(0,x.jsx)(`span`,{className:`text-ink-muted w-36 shrink-0`,children:e.check}),(0,x.jsx)(`span`,{className:`text-ink-subtle`,children:e.detail})]}),e.fix&&(e.status===`fail`||e.status===`warn`)&&(0,x.jsxs)(`div`,{className:`ml-[1.25rem] mt-0.5 flex items-center gap-2`,children:[(0,x.jsx)(`span`,{className:`text-[10px] font-mono text-ink-subtle bg-surface-3 px-1.5 py-0.5 rounded`,children:e.fix}),(0,x.jsx)(`button`,{className:`text-[10px] text-ink-muted hover:text-ink-base transition-colors`,onClick:()=>void navigator.clipboard.writeText(e.fix??``),children:`copy`})]})]},e.check))})]})}function hG(){let e=C(),{data:t,isLoading:n,error:r}=L({queryKey:z.settings,queryFn:()=>Ir()}),{data:i}=L({queryKey:[`observability-health`],queryFn:Br,refetchInterval:3e4}),[a,o]=(0,b.useState)(null),[s,c]=(0,b.useState)(void 0),[l,u]=(0,b.useState)(void 0),[d,f]=(0,b.useState)(void 0),[p,m]=(0,b.useState)(void 0),[h,g]=(0,b.useState)(void 0),[_,v]=(0,b.useState)(null),[y,S]=(0,b.useState)(null),w=st({mutationFn:e=>Rr(e),onSuccess:()=>{e.invalidateQueries({queryKey:z.settings}),S(null)},onError:e=>{S(String(e))}});if(n)return(0,x.jsx)($,{icon:`clock`,variant:`loading`,title:`Loading...`});if(r||!t)return(0,x.jsx)(`div`,{className:`text-accent-red text-xs`,children:`Failed to load settings.`});let T=a??t.developer,E=s===void 0?t.teamId:s,D=l===void 0?t.sessionBudgetUsd:l,O=d===void 0?t.dailyBudgetUsd:d,k=p===void 0?t.weeklyBudgetUsd:p,A=h===void 0?t.retainSessionsDays:h;function j(){let e={};a!==null&&(e.developer=a),s!==void 0&&(e.teamId=s),w.mutate(e,{onSuccess:()=>{v(`identity`),setTimeout(()=>v(null),3e3)}})}function M(){let e={};l!==void 0&&(e.sessionBudgetUsd=l),d!==void 0&&(e.dailyBudgetUsd=d),p!==void 0&&(e.weeklyBudgetUsd=p),h!==void 0&&(e.retainSessionsDays=h),w.mutate(e,{onSuccess:()=>{v(`budgets`),setTimeout(()=>v(null),3e3)}})}let N=e=>_===e?(0,x.jsx)(`div`,{className:`mt-2 text-xs text-accent-amber`,children:`Saved. Restart the server for changes to take effect.`}):null;return(0,x.jsxs)(`section`,{children:[(0,x.jsx)(mG,{}),(0,x.jsxs)(`header`,{className:`mb-6`,children:[(0,x.jsx)(`h1`,{className:`text-xl font-semibold gradient-text`,children:`Settings`}),(0,x.jsx)(`p`,{className:`text-xs text-ink-muted mt-1`,children:`Changes are written to config.json on disk. Most require a server restart.`})]}),y&&(0,x.jsx)(`div`,{className:`mb-4 text-xs text-accent-red bg-accent-red/10 border border-accent-red/30 rounded-md px-3 py-2`,children:y}),(0,x.jsxs)(B,{padding:`md`,className:`mb-4`,children:[(0,x.jsx)(ci,{title:`Identity & Account`}),(0,x.jsxs)(`div`,{className:`flex items-center gap-3 py-1.5`,children:[(0,x.jsx)(`label`,{className:`text-xs text-ink-muted w-36 shrink-0`,children:`Developer name`}),(0,x.jsx)(`input`,{type:`text`,value:T,maxLength:128,onChange:e=>o(e.target.value),className:`text-xs bg-surface-3 border border-border-subtle rounded-md px-2 py-1 w-48 focus:outline-none focus:border-accent-green text-ink-base`})]}),(0,x.jsxs)(`div`,{className:`flex items-center gap-3 py-1.5`,children:[(0,x.jsx)(`label`,{className:`text-xs text-ink-muted w-36 shrink-0`,children:`Team ID`}),(0,x.jsx)(`input`,{type:`text`,value:E??``,placeholder:`optional`,onChange:e=>c(e.target.value===``?null:e.target.value),className:`text-xs bg-surface-3 border border-border-subtle rounded-md px-2 py-1 w-48 focus:outline-none focus:border-accent-green text-ink-base placeholder:text-ink-muted`})]}),(0,x.jsx)(uG,{label:`Account ID`,value:t.accountId}),(0,x.jsx)(uG,{label:`App name`,value:t.appName}),(0,x.jsx)(uG,{label:`Mode`,value:t.mode}),(0,x.jsx)(uG,{label:`Storage path`,value:t.storagePath}),(0,x.jsx)(uG,{label:`High security`,value:t.highSecurity?`enabled`:`disabled`}),(0,x.jsx)(uG,{label:`License key`,value:t.licenseKey}),(0,x.jsx)(`div`,{className:`mt-3 flex items-center gap-3`,children:(0,x.jsx)(Qr,{variant:`primary`,size:`md`,onClick:j,disabled:w.isPending,loading:w.isPending,children:w.isPending?`Saving…`:`Save identity`})}),N(`identity`)]}),(0,x.jsxs)(B,{padding:`md`,children:[(0,x.jsx)(ci,{title:`Cost & Retention`,subtitle:`Budget caps trigger warnings at 50%, 80%, and 100%. Leave blank for no limit.`}),(0,x.jsx)(dG,{label:`Session budget (USD)`,value:D,onChange:u,min:.01}),(0,x.jsx)(dG,{label:`Daily budget (USD)`,value:O,onChange:f,min:.01}),(0,x.jsx)(dG,{label:`Weekly budget (USD)`,value:k,onChange:m,min:.01}),(0,x.jsx)(dG,{label:`Retain sessions (days)`,value:A,onChange:g,placeholder:`forever`,min:1}),(0,x.jsx)(`div`,{className:`mt-3 flex items-center gap-3`,children:(0,x.jsx)(Qr,{variant:`primary`,size:`md`,onClick:M,disabled:w.isPending,loading:w.isPending,children:w.isPending?`Saving…`:`Save budgets`})}),N(`budgets`)]}),(0,x.jsxs)(`section`,{className:`mt-8`,children:[(0,x.jsx)(V,{children:`Observability`}),(0,x.jsxs)(B,{padding:`md`,className:`mt-3`,children:[(0,x.jsx)(`h3`,{className:`text-sm font-medium text-ink mb-3`,children:`Subagent & Workflow Watcher`}),(0,x.jsx)(`p`,{className:`text-xs text-ink-muted mb-4`,children:`Monitors subagent JSONL transcripts and workflow records to provide accurate cost tracking. Default: enabled in --stdio mode.`}),(0,x.jsxs)(`div`,{className:`flex flex-col gap-2 text-xs text-ink-muted`,children:[(0,x.jsxs)(`div`,{children:[`Subagent watcher:`,` `,i?.watcherActive===!0?(0,x.jsx)(`span`,{className:`text-accent-green`,children:`enabled`}):i?.watcherActive===!1?(0,x.jsx)(`span`,{className:`text-accent-red`,children:`disabled`}):(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`checking…`}),i?.watcherActive===!0&&(0,x.jsxs)(`span`,{className:`text-ink-muted`,children:[` `,`(`,i.filesWatched??0,` files watched, `,i.parseErrors??0,` parse errors)`]})]}),(0,x.jsxs)(`div`,{children:[`Set`,` `,(0,x.jsx)(`code`,{className:`font-mono bg-surface-5 px-1 rounded`,children:`NR_AI_ENABLE_SUBAGENT_WATCHER=0`}),` `,`to disable, or`,` `,(0,x.jsx)(`code`,{className:`font-mono bg-surface-5 px-1 rounded`,children:`NR_AI_ENABLE_SUBAGENT_WATCHER=1`}),` `,`to explicitly enable.`]})]})]})]})]})}function gG({pct:e,exceeded:t}){let n=e??0;return(0,x.jsx)(`div`,{className:`w-24 h-1.5 bg-surface-5 rounded-full overflow-hidden`,children:(0,x.jsx)(`div`,{className:`h-full rounded-full ${t?`bg-accent-red`:n>=80?`bg-accent-amber`:`bg-accent-green`}`,style:{width:`${Math.min(n,100)}%`}})})}function _G({label:e,p:t}){return(0,x.jsxs)(`div`,{className:`flex items-center gap-3 py-1.5`,children:[(0,x.jsx)(`span`,{className:`text-xs text-ink-muted w-20 shrink-0 capitalize`,children:e}),(0,x.jsx)(gG,{pct:t.pctUsed,exceeded:t.exceeded}),(0,x.jsxs)(`span`,{className:`text-xs tabular-nums text-ink-base`,children:[Ci(t.spentUsd),t.budgetUsd===null?``:` / ${Ci(t.budgetUsd)}`,t.pctUsed===null?``:` (${t.pctUsed.toFixed(0)}%)`]}),t.exceeded&&(0,x.jsx)(ni,{tone:`danger`,size:`sm`,children:`exceeded`})]})}function vG(){let e=C(),t=L({queryKey:z.budget,queryFn:()=>pr(),refetchInterval:1e4}),n=L({queryKey:z.settings,queryFn:()=>Ir()}),r=t.data,i=n.data,[a,o]=(0,b.useState)({}),[s,c]=(0,b.useState)(!1),[l,u]=(0,b.useState)(void 0),[d,f]=(0,b.useState)(null),[p,m]=(0,b.useState)(null),h=st({mutationFn:e=>Rr(e),onSuccess:()=>void e.invalidateQueries({queryKey:z.settings})}),g=st({mutationFn:()=>zr(),onSuccess:e=>{let t=e.content[0]?.text??``;try{let e=JSON.parse(t);m(e.ok?`Digest sent.`:e.error??`Failed to send.`)}catch{m(`Done.`)}setTimeout(()=>m(null),4e3)},onError:e=>{m(`Error: ${String(e)}`)}});function _(){Object.keys(a).length!==0&&h.mutate({alerts:{personal:a}},{onSuccess:()=>{c(!0),setTimeout(()=>c(!1),3e3)}})}function v(){let e={};l!==void 0&&(e.digestWebhookUrl=l),d!==null&&(e.digestSchedule=d??i?.digestSchedule),h.mutate(e)}function y(e){return a[e]??i?.alerts.personal[e]??0}function S(e,t,n={}){return(0,x.jsxs)(`div`,{className:`flex items-center gap-3 py-1.5`,children:[(0,x.jsx)(`label`,{className:`text-xs text-ink-muted w-44 shrink-0`,children:e}),(0,x.jsx)(`input`,{type:`number`,value:y(t),min:n.min,max:n.max,step:n.step??`any`,onChange:e=>o(n=>({...n,[t]:Number(e.target.value)})),className:`text-xs bg-surface-3 border border-border-subtle rounded-md px-2 py-1 w-24 focus:outline-none focus:border-accent-green text-ink-base`})]})}return(0,x.jsxs)(`section`,{children:[(0,x.jsx)(`header`,{className:`mb-6`,children:(0,x.jsx)(`h1`,{className:`text-xl font-semibold gradient-text`,children:`Alerts`})}),(0,x.jsxs)(B,{padding:`md`,className:`mb-4`,children:[(0,x.jsx)(ci,{title:`Budget Status`}),t.isLoading&&(0,x.jsx)($,{icon:`clock`,variant:`loading`,title:`Loading...`}),t.isError&&(0,x.jsx)(`div`,{className:`text-accent-red text-xs`,children:`Error loading budget status.`}),r&&(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(_G,{label:`session`,p:r.session}),(0,x.jsx)(_G,{label:`daily`,p:r.daily}),(0,x.jsx)(_G,{label:`weekly`,p:r.weekly}),r.alerts.length>0&&(0,x.jsxs)(`div`,{className:`mt-3 border-t border-border-subtle pt-3`,children:[(0,x.jsx)(V,{className:`mb-2`,children:`Recent Warnings`}),(0,x.jsx)(`div`,{className:`flex flex-col gap-1`,children:r.alerts.slice(-5).reverse().map((e,t)=>(0,x.jsxs)(`div`,{className:`text-xs text-ink-subtle flex gap-2`,children:[(0,x.jsxs)(`span`,{className:`text-accent-amber tabular-nums`,children:[e.thresholdPct,`%`]}),(0,x.jsx)(`span`,{className:`capitalize`,children:e.period}),(0,x.jsxs)(`span`,{className:`text-ink-muted tabular-nums`,children:[Ci(e.spentUsd),` / `,Ci(e.budgetUsd)]}),(0,x.jsx)(`span`,{className:`text-ink-muted ml-auto tabular-nums`,children:new Date(e.timestamp).toLocaleTimeString(void 0,{hour:`numeric`,minute:`2-digit`})})]},t))})]}),r.alerts.length===0&&r.session.budgetUsd===null&&r.daily.budgetUsd===null&&r.weekly.budgetUsd===null&&(0,x.jsxs)(`p`,{className:`text-xs text-ink-muted mt-2`,children:[`No budget caps configured.`,` `,(0,x.jsx)(Zt,{href:`/settings`,className:`text-accent-cyan hover:underline transition-colors duration-150`,children:`Set limits in Settings`}),` `,`to enable warnings.`]})]})]}),(0,x.jsxs)(B,{padding:`md`,className:`mb-4`,children:[(0,x.jsx)(ci,{title:`Alert Thresholds`,subtitle:"Thresholds used by the `deploy-alerts` CLI (`npm run deploy:alerts`) when templating cloud alert conditions. Have no effect on this dashboard or any running session."}),n.isLoading&&(0,x.jsx)($,{icon:`clock`,variant:`loading`,title:`Loading...`}),i&&(0,x.jsxs)(x.Fragment,{children:[S(`Daily cost ($)`,`dailyCostUsd`,{min:0,step:.1}),S(`Session cost ($)`,`sessionCostUsd`,{min:0,step:.1}),S(`Min efficiency score (0–1)`,`efficiencyScoreMin`,{min:0,max:1,step:.05}),S(`Max anti-patterns`,`antiPatternCountMax`,{min:0,step:1}),S(`Max stuck loops`,`stuckLoopCountMax`,{min:0,step:1}),(0,x.jsxs)(`div`,{className:`mt-3 flex items-center gap-3`,children:[(0,x.jsx)(Qr,{variant:`primary`,size:`md`,onClick:_,disabled:h.isPending||Object.keys(a).length===0,loading:h.isPending,children:h.isPending?`Saving…`:`Save thresholds`}),s&&(0,x.jsx)(`span`,{className:`text-xs text-accent-amber`,children:"Saved. Run `npm run deploy:alerts` to apply these to your cloud alert conditions."})]})]})]}),(0,x.jsxs)(B,{padding:`md`,children:[(0,x.jsx)(ci,{title:`Slack Digest`,subtitle:`Weekly digest sent to a Slack incoming webhook. URL changes take effect immediately.`}),n.isLoading&&(0,x.jsx)($,{icon:`clock`,variant:`loading`,title:`Loading...`}),i&&(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(`div`,{className:`flex items-center gap-2 mb-3`,children:(0,x.jsx)(ni,{tone:i.digestWebhookUrl?`success`:`neutral`,size:`sm`,children:i.digestWebhookUrl?`Configured`:`Not configured`})}),(0,x.jsxs)(`div`,{className:`flex items-center gap-3 py-1.5`,children:[(0,x.jsx)(`label`,{className:`text-xs text-ink-muted w-28 shrink-0`,children:`Webhook URL`}),(0,x.jsx)(`input`,{type:`url`,value:l===void 0?i.digestWebhookUrl??``:l??``,placeholder:`https://hooks.slack.com/...`,onChange:e=>u(e.target.value===``?null:e.target.value),className:`text-xs bg-surface-3 border border-border-subtle rounded-md px-2 py-1 w-72 focus:outline-none focus:border-accent-green text-ink-base placeholder:text-ink-muted`})]}),(0,x.jsxs)(`div`,{className:`flex items-center gap-3 py-1.5`,children:[(0,x.jsxs)(`label`,{className:`text-xs text-ink-muted w-28 shrink-0`,children:[`Schedule`,(0,x.jsx)(`span`,{className:`block text-[10px] text-ink-muted font-normal`,children:`(cron, restart req.)`})]}),(0,x.jsx)(`input`,{type:`text`,value:d??i.digestSchedule,onChange:e=>f(e.target.value),className:`text-xs bg-surface-3 border border-border-subtle rounded-md px-2 py-1 w-36 focus:outline-none focus:border-accent-green text-ink-base font-mono`}),(0,x.jsx)(`span`,{className:`text-[10px] text-ink-muted`,children:`default: Mon 9am`})]}),(0,x.jsxs)(`div`,{className:`mt-3 flex items-center gap-3 flex-wrap`,children:[(0,x.jsx)(Qr,{variant:`primary`,size:`md`,onClick:v,disabled:h.isPending,loading:h.isPending,children:h.isPending?`Saving…`:`Save`}),i.digestWebhookUrl&&(0,x.jsx)(Qr,{variant:`danger`,size:`md`,onClick:()=>h.mutate({digestWebhookUrl:null},{onSuccess:()=>u(void 0)}),disabled:h.isPending,children:`Unsubscribe`}),(0,x.jsx)(Qr,{variant:`secondary`,size:`md`,onClick:()=>g.mutate(),disabled:g.isPending||!i.digestWebhookUrl,loading:g.isPending,children:g.isPending?`Sending…`:`Send test now`}),p&&(0,x.jsx)(`span`,{className:`text-xs text-ink-subtle`,children:p})]})]})]})]})}function yG(){Vi();let e=qn(e=>e.connected),[t,n]=Wt(),[r,i]=(0,b.useState)(!1),{theme:a,toggleTheme:o}=Ki(),s=(0,b.useCallback)(()=>i(e=>!e),[]),c=(0,b.useCallback)(()=>i(!1),[]);return Hi({navigate:n,onToggleHelp:s,onToggleTheme:o}),(0,x.jsxs)(x.Fragment,{children:[(0,x.jsxs)(`div`,{className:`flex flex-col h-full mesh-bg`,children:[(0,x.jsx)(Pi,{}),(0,x.jsxs)(`div`,{className:`flex flex-1 min-h-0`,children:[(0,x.jsx)(hi,{currentPath:t,onNavigate:n,connected:e,theme:a,onToggleTheme:o}),(0,x.jsx)(`main`,{className:`flex-1 overflow-auto p-6`,children:(0,x.jsx)(Fi,{resetKey:t,children:(0,x.jsxs)($t,{children:[(0,x.jsx)(Xt,{path:`/sessions`,component:YU}),(0,x.jsx)(Xt,{path:`/history`,component:bW}),(0,x.jsx)(Xt,{path:`/audit`,component:KW}),(0,x.jsx)(Xt,{path:`/git`,component:lG}),(0,x.jsx)(Xt,{path:`/settings`,component:hG}),(0,x.jsx)(Xt,{path:`/alerts`,component:vG}),(0,x.jsx)(Xt,{path:`/`,component:rU}),(0,x.jsx)(Xt,{children:(0,x.jsx)(`div`,{className:`text-ink-muted`,children:`Not found`})})]})})})]})]}),(0,x.jsx)(Li,{open:r,onClose:c})]})}var bG=new Je({defaultOptions:{queries:{staleTime:5e3,retry:0,refetchOnWindowFocus:!1}}}),xG=document.getElementById(`root`);if(!xG)throw Error(`Mount node #root not found`);(0,ct.createRoot)(xG).render((0,x.jsx)(b.StrictMode,{children:(0,x.jsx)(w,{client:bG,children:(0,x.jsx)(yG,{})})}));