@newrelic/preflight 1.56.0 → 1.57.0
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.
- package/dist/dashboard/routes/api-handler.d.ts +1 -1
- package/dist/dashboard/routes/api-handler.d.ts.map +1 -1
- package/dist/dashboard/routes/api-handler.js +105 -0
- package/dist/dashboard/routes/api-handler.js.map +1 -1
- package/dist/metrics/session-status.d.ts +19 -0
- package/dist/metrics/session-status.d.ts.map +1 -0
- package/dist/metrics/session-status.js +33 -0
- package/dist/metrics/session-status.js.map +1 -0
- package/dist/web/assets/{index-CTwtvuaF.js → index-BcFTZxKF.js} +2 -2
- package/dist/web/index.html +1 -1
- package/package.json +1 -1
|
@@ -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 FI(e,t){if(e){if(typeof e==`string`)return II(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)?II(e,t):void 0}}function II(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 LI(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 RI(e){if(Array.isArray(e))return e}function zI(e,t){if(e==null)return{};var n,r,i=BI(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 BI(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 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){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 UI(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?HI(Object(n),!0).forEach(function(t){WI(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):HI(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function WI(e,t,n){return(t=GI(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function GI(e){var t=KI(e,`string`);return typeof t==`symbol`?t:t+``}function KI(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 qI={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:Yv.axis};function JI(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=UI(UI(UI({},c),co(s)),{},{fill:`none`});if(a===`top`||a===`bottom`){var u=+(a===`top`&&!o||a===`bottom`&&o);l=UI(UI({},l),{},{x1:t,y1:n+u*i,x2:t+r,y2:n+u*i})}else{var d=+(a===`left`&&!o||a===`right`&&o);l=UI(UI({},l),{},{x1:t+d*r,y1:n,x2:t+d*r,y2:n+i})}return b.createElement(`line`,VI({},l,{className:G(`recharts-cartesian-axis-line`,(0,No.default)(s,`className`))}))}function YI(e,t,n,r,i,a,o,s,c){var l,u,d,f,p,m,h=s?-1:1,g=e.tickSize||o,_=q(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 XI(e,t){switch(e){case`left`:return t?`start`:`end`;case`right`:return t?`end`:`start`;default:return`middle`}}function ZI(e,t){switch(e){case`left`:case`right`:return`middle`;case`top`:return t?`start`:`end`;default:return t?`end`:`start`}}function QI(e){var t=e.option,n=e.tickProps,r=e.value,i,a=G(n.className,`recharts-cartesian-axis-tick-value`);if(b.isValidElement(t))i=b.cloneElement(t,UI(UI({},n),{},{className:a}));else if(typeof t==`function`)i=t(UI(UI({},n),{},{className:a}));else{var o=`recharts-cartesian-axis-tick-value`;typeof t!=`boolean`&&(o=G(o,dN(t))),i=b.createElement(bM,VI({},n,{className:o}),r)}return i}function $I(e){var t=e.ticks,n=e.axisType,r=e.axisId,i=Zc(),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,jI.default)(o.ticks,e)||(a.current={ticks:e,axisId:r,axisType:n},i(OI({ticks:e,axisId:r,axisType:n})))}},[i,t,r,n]),(0,b.useEffect)(()=>r==null||n==null?qo:()=>{i(kI({axisId:r,axisType:n}))},[i,r,n]),null}var eL=(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=CI(UI(UI({},S),{},{ticks:r}),y,x),D=co(S),O=lo(i),k=lM(D.textAnchor)?D.textAnchor:XI(d,f),A=ZI(d,f),j={};typeof a==`object`&&(j=a);var M=UI(UI({},D),{},{fill:`none`},j),N=E.map(e=>UI({entry:e},YI(e,p,m,h,g,d,_,f,v))),ee=N.map(e=>{var t=e.entry,n=e.line;return b.createElement(So,{className:`recharts-cartesian-axis-tick`,key:`tick-${t.value}-${t.coordinate}-${t.tickCoord}`},a&&b.createElement(`line`,VI({},M,n,{className:G(`recharts-cartesian-axis-tick-line`,(0,No.default)(a,`className`))})))}),te=N.map((e,t)=>{var n=e.entry,r=e.tick,a=UI(UI({},UI(UI(UI(UI({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(So,VI({className:`recharts-cartesian-axis-tick-label`,key:`tick-label-${n.value}-${n.coordinate}-${n.tickCoord}`},oc(C,n,t)),i&&b.createElement(QI,{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($I,{ticks:E,axisId:T,axisType:w}),te.length>0&&b.createElement(sA,{zIndex:Yv.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))}),tL=(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=zI(e,MI),d=NI((0,b.useState)(``),2),f=d[0],p=d[1],m=NI((0,b.useState)(``),2),h=m[0],g=m[1],_=(0,b.useRef)(null);(0,b.useImperativeHandle)(t,()=>({getCalculatedWidth:()=>wI({ticks:_.current,label:e.labelRef?.current,labelGapWithTick:5,tickSize:e.tickSize,tickMargin:e.tickMargin}),getCalculatedHeight:()=>TI({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(sA,{zIndex:e.zIndex},b.createElement(So,{className:G(`recharts-cartesian-axis`,a)},b.createElement(JI,{x:e.x,y:e.y,width:r,height:i,orientation:e.orientation,mirror:e.mirror,axisLine:n,otherSvgProps:co(e)}),b.createElement(eL,{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(MM,{x:e.x,y:e.y,width:e.width,height:e.height,lowerWidth:e.width,upperWidth:e.width},b.createElement(KM,{label:e.label,labelRef:e.labelRef}),e.children)))}),nL=b.forwardRef((e,t)=>{var n=fc(e,qI);return b.createElement(tL,VI({},n,{ref:t}))});nL.displayName=`CartesianAxis`;var rL=(0,b.createContext)({grid:{stroke:`#ccc`,fill:`none`}});rL.Provider;var iL=()=>(0,b.useContext)(rL),aL=[`x1`,`y1`,`x2`,`y2`,`key`],oL=[`offset`],sL=[`xAxisId`,`yAxisId`],cL=[`xAxisId`,`yAxisId`];function lL(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 uL(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?lL(Object(n),!0).forEach(function(t){dL(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):lL(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function dL(e,t,n){return(t=fL(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function fL(e){var t=pL(e,`string`);return typeof t==`symbol`?t:t+``}function pL(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 mL(){return mL=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},mL.apply(null,arguments)}function hL(e,t){if(e==null)return{};var n,r,i=gL(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 gL(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 _L=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 vL(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=co(hL(n,aL))??{};l.offset;var u=hL(l,oL),d=Array.isArray(u.strokeDasharray)?u.strokeDasharray.join(`,`):u.strokeDasharray;r=b.createElement(`line`,mL({},u,{strokeDasharray:d,x1:i,y1:a,x2:o,y2:s,fill:`none`,key:c}))}return r}function yL(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=hL(e,sL),s=a.map((e,r)=>{var a=uL(uL({},o),{},{x1:t,y1:e,x2:t+n,y2:e,key:`line-${r}`,index:r});return b.createElement(vL,{key:`line-${r}`,option:i,lineItemProps:a})});return b.createElement(`g`,{className:`recharts-cartesian-grid-horizontal`},s)}function bL(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=hL(e,cL),s=a.map((e,r)=>{var a=uL(uL({},o),{},{x1:e,y1:t,x2:e,y2:t+n,key:`line-${r}`,index:r});return b.createElement(vL,{option:i,lineItemProps:a,key:`line-${r}`})});return b.createElement(`g`,{className:`recharts-cartesian-grid-vertical`},s)}function xL(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 SL(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 CL=(e,t)=>{var n=e.xAxis,r=e.width,i=e.height,a=e.offset;return Uf(CI(uL(uL(uL({},qI),n),{},{ticks:Wf(n,!0),viewBox:{x:0,y:0,width:r,height:i}})),a.left,a.left+a.width,t)},wL=(e,t)=>{var n=e.yAxis,r=e.width,i=e.height,a=e.offset;return Uf(CI(uL(uL(uL({},qI),n),{},{ticks:Wf(n,!0),viewBox:{x:0,y:0,width:r,height:i}})),a.top,a.top+a.height,t)},TL={horizontal:!0,vertical:!0,horizontalPoints:[],verticalPoints:[],verticalFill:[],horizontalFill:[],xAxisId:0,yAxisId:0,syncWithTicks:!1,zIndex:Yv.grid};function EL(e){var t=gm(),n=_m(),r=hm(),i=uL(uL({},fc(e,TL)),{},{x:q(e.x)?e.x:r.left,y:q(e.y)?e.y:r.top,width:q(e.width)?e.width:r.width,height:q(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=kp(),h=J(e=>jD(e,`xAxis`,a,m)),g=J(e=>jD(e,`yAxis`,o,m)),_=iL(),v={stroke:i.stroke??_.grid.stroke,strokeWidth:i.strokeWidth??_.grid.strokeWidth,strokeOpacity:i.strokeOpacity??_.grid.strokeOpacity,strokeDasharray:i.strokeDasharray??_.grid.strokeDasharray};if(!Pf(l)||!Pf(u)||!q(s)||!q(c))return null;var y=i.verticalCoordinatesGenerator||CL,x=i.horizontalCoordinatesGenerator||wL,S=i.horizontalPoints,C=i.verticalPoints;if((!S||!S.length)&&typeof x==`function`){var w=f&&f.length,T=x({yAxis:g?uL(uL({},g),{},{ticks:w?f:g.ticks}):void 0,width:t??l,height:n??u,offset:r},w?!0:d);Ip(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?uL(uL({},h),{},{ticks:E?p:h.ticks}):void 0,width:t??l,height:n??u,offset:r},E?!0:d);Ip(Array.isArray(D),`verticalCoordinatesGenerator should return Array but instead it returned [${typeof D}]`),Array.isArray(D)&&(C=D)}return b.createElement(sA,{zIndex:i.zIndex},b.createElement(`g`,{className:`recharts-cartesian-grid`},b.createElement(_L,{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(xL,mL({},i,{horizontalPoints:S})),b.createElement(SL,mL({},i,{verticalPoints:C})),b.createElement(yL,mL({},i,v,{offset:r,horizontalPoints:S,xAxis:h,yAxis:g})),b.createElement(bL,mL({},i,v,{offset:r,verticalPoints:C,xAxis:h,yAxis:g}))))}EL.displayName=`CartesianGrid`;var DL=[`animationElapsedTime`,`isAnimating`,`isEntrance`,`visibleLength`,`strokeDasharray`,`connectNulls`];function OL(){return OL=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},OL.apply(null,arguments)}function kL(e,t){if(e==null)return{};var n,r,i=AL(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 AL(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 jL(e){try{return e&&e.getTotalLength&&e.getTotalLength()||0}catch{return 0}}function ML(e,t){return`${t}px ${e}px`}function NL(e){return e.length%2==0?e:[...e,...e]}function PL(e,t){for(var n=[],r=0;r<t;++r)n.push(...e);return n}function FL(e,t,n){var r=NL(n),i=r.reduce((e,t)=>e+t,0);if(!i)return ML(t,e);for(var a=Math.floor(e/i),o=e%i,s=[],c=0,l=0;c<r.length;l+=(u=r[c])??0,++c){var u,d=r[c];if(d!=null&&l+d>o){s=[...r.slice(0,c),o-l];break}}var f=s.length%2==0?[0,t]:[t];return[...PL(r,a),...s,...f].map(e=>`${e}px`).join(`, `)}function IL(e,t,n){return e?FL(n,t,`${e}`.split(/[,\s]+/gim).map(e=>parseFloat(e))):ML(t,n)}function LL(e){e.animationElapsedTime,e.isAnimating,e.isEntrance;var t=e.visibleLength,n=e.strokeDasharray,r=e.connectNulls,i=kL(e,DL),a=r??!1,o;if(t!=null){var s=i.pathRef;o=IL(n,jL(s?.current??null),t)}else n!=null&&(o=String(n));return b.createElement(eg,OL({},i,{connectNulls:a,strokeDasharray:o}))}function RL(e){var t=(0,b.useRef)(0),n=(0,b.useRef)(0),r=(0,b.useRef)(!1),i=(0,b.useRef)(e);return i.current!==e&&(t.current=n.current,i.current=e),(0,b.useCallback)((e,i)=>{if(r.current)return null;var a=Math.min(jo(t.current+e*i),i);return e>0&&i>0&&(n.current=Math.max(n.current,a),a>=i)?(r.current=!0,null):a},[])}var zL=Ld({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))}}}),BL=zL.actions;BL.addErrorBar,BL.replaceErrorBar,BL.removeErrorBar;var VL=zL.reducer,HL=[`children`];function UL(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 GL=(0,b.createContext)({data:[],xAxisId:`xAxis-0`,yAxisId:`yAxis-0`,dataPointFormatter:()=>({x:0,y:0,value:0}),errorBarOffset:0});function KL(e){var t=e.children,n=UL(e,HL);return b.createElement(GL.Provider,{value:n},t)}function qL(e,t){var n=J(t=>MT(t,e)),r=J(e=>FT(e,t)),i=n?.allowDataOverflow??AT.allowDataOverflow,a=r?.allowDataOverflow??NT.allowDataOverflow;return{needClip:i||a,needClipX:i,needClipY:a}}function JL(e){var t=e.xAxisId,n=e.yAxisId,r=e.clipPathId,i=ZP(),a=qL(t,n),o=a.needClipX,s=a.needClipY,c=a.needClip,l=J(e=>aD(e,t,!1)),u=J(e=>oD(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}))}var YL=(e,t,n,r)=>PD(e,`xAxis`,t,r),XL=(e,t,n,r)=>ND(e,`xAxis`,t,r),ZL=(e,t,n,r)=>PD(e,`yAxis`,n,r),QL=(e,t,n,r)=>ND(e,`yAxis`,n,r),$L=Y([vm,YL,ZL,XL,QL],(e,t,n,r,i)=>Hf(e,`xAxis`)?rp(t,r,!1):rp(n,i,!1)),eR=(e,t,n,r,i)=>i;function tR(e){return e.type===`line`}var nR=Y([vm,YL,ZL,XL,QL,Y([UT,eR],(e,t)=>e.filter(tR).find(e=>e.id===t)),$L,cv],(e,t,n,r,i,a,o,s)=>{var c=s.chartData,l=s.dataStartIndex,u=s.dataEndIndex;if(!(a==null||t==null||n==null||r==null||i==null||r.length===0||i.length===0||o==null||e!==`horizontal`&&e!==`vertical`)){var d=a.dataKey,f=a.data,p=f!=null&&f.length>0?f:c?.slice(l,u+1);if(p!=null)return OR({layout:e,xAxis:t,yAxis:n,xAxisTicks:r,yAxisTicks:i,dataKey:d,bandSize:o,displayedData:p})}});function rR(e){var t=lo(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}}var iR=[`id`],aR=[`type`,`layout`,`connectNulls`,`needClip`,`shape`,`strokeDasharray`],oR=[`activeDot`,`animateNewValues`,`animationBegin`,`animationDuration`,`animationEasing`,`connectNulls`,`dot`,`hide`,`isAnimationActive`,`label`,`legendType`,`xAxisId`,`yAxisId`,`id`];function sR(){return sR=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},sR.apply(null,arguments)}function cR(e,t){if(e==null)return{};var n,r,i=lR(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 lR(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 uR(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 dR(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?uR(Object(n),!0).forEach(function(t){fR(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):uR(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function fR(e,t,n){return(t=pR(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function pR(e){var t=mR(e,`string`);return typeof t==`symbol`?t:t+``}function mR(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 hR(e){try{return e&&e.getTotalLength&&e.getTotalLength()||0}catch{return 0}}function gR(e){var t=0,n=0;for(var r of e)r.status===`matched`&&r.prev.x!=null&&r.next.x!=null&&(t+=r.next.x-r.prev.x,n++);return n>0?t/n:0}var _R={activeDot:!0,animateNewValues:!0,animationBegin:0,animationDuration:1500,animationEasing:`ease`,animationInterpolateFn:(e,t)=>{if(e==null)return[];if(t===1)return e.flatMap(e=>e.status===`removed`?[]:[e.next]);var n=gR(e),r=[];for(var i of e)if(i.status===`matched`)r.push(dR(dR({},i.next),{},{x:Ho(i.prev.x,i.next.x,t),y:Ho(i.prev.y,i.next.y,t)}));else if(i.status===`added`){if(i.next.x!=null){var a=i.next.x-n;r.push(dR(dR({},i.next),{},{x:Ho(a,i.next.x,t),y:i.next.y}))}else r.push(i.next)}else if(i.status===`removed`&&i.prev.x!=null){var o=i.prev.x+n;r.push(dR(dR({},i.prev),{},{x:Ho(i.prev.x,o,t),y:i.prev.y}))}return r},animationMatchBy:HN,connectNulls:!1,dot:!0,fill:`#fff`,hide:!1,isAnimationActive:`auto`,label:!1,legendType:`line`,shape:LL,stroke:`#3182bd`,strokeWidth:1,xAxisId:0,yAxisId:0,zIndex:Yv.line,type:`linear`},vR=e=>{var t=e.dataKey,n=e.name,r=e.stroke,i=e.legendType;return[{inactive:e.hide,dataKey:t,type:i,color:r,value:ap(n,t),payload:e}]},yR=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:qo,settings:{stroke:r,strokeWidth:i,fill:a,dataKey:t,nameKey:void 0,name:ap(o,t),hide:s,type:u,color:r,unit:c,formatter:l,graphicalItemId:d}};return b.createElement(PN,{tooltipEntrySettings:f})});function bR(e){var t=e.clipPathId,n=e.points,r=e.props,i=r.dot,a=r.dataKey,o=r.needClip;r.id;var s=co(cR(r,iR));return b.createElement(NP,{points:n,dot:i,className:`recharts-line-dots`,dotClassName:`recharts-line-dot`,dataKey:a,baseProps:s,needClip:o,clipPathId:t})}function xR(e){var t=e.showLabels,n=e.children,r=e.points,i=(0,b.useMemo)(()=>r?.map(e=>{var t={x:e.x??0,y:e.y??0,width:0,lowerWidth:0,upperWidth:0,height:0};return dR(dR({},t),{},{value:e.value,payload:e.payload,viewBox:t,parentViewBox:void 0,fill:void 0})}),[r]);return b.createElement(eN,{value:t?i:void 0},n)}function SR(e){var t=e.clipPathId,n=e.pathRef,r=e.points,i=e.props,a=e.animationElapsedTime,o=e.isAnimating,s=e.isEntrance,c=e.visibleLength,l=i.type,u=i.layout,d=i.connectNulls,f=i.needClip,p=i.shape,m=i.strokeDasharray,h=dR(dR({},uo(cR(i,aR))),{},{fill:`none`,className:`recharts-line-curve`,clipPath:f?`url(#clipPath-${t})`:void 0,points:r,type:l,layout:u,connectNulls:d,strokeDasharray:m??i.strokeDasharray,pathRef:n,animationElapsedTime:a,isAnimating:o,isEntrance:i.animateNewValues?s:!1,visibleLength:c});return b.createElement(b.Fragment,null,r?.length>1&&b.createElement(AN,{option:p,DefaultShape:_R.shape,shapeProps:h}),b.createElement(bR,{points:r,clipPathId:t,props:i}))}function CR(e){var t=e.clipPathId,n=e.props,r=e.pathRef,i=e.previousPointsRef,a=n.points,o=n.isAnimationActive,s=n.animationBegin,c=n.animationDuration,l=n.animationEasing,u=n.animationMatchBy,d=n.animationInterpolateFn,f=n.layout,p=hR(r.current),m=rP(n.onAnimationStart,n.onAnimationEnd),h=m.isAnimating,g=m.handleAnimationStart,_=m.handleAnimationEnd,v=!h,y=RL(a),x=(0,b.useCallback)(e=>e>0&&p>0,[p]);return b.createElement(xR,{points:a,showLabels:v},n.children,b.createElement(iP,{animationInput:a,animationIdPrefix:`recharts-line-`,items:a,previousItemsRef:i,isAnimationActive:o,animationBegin:s,animationDuration:c,animationEasing:l,onAnimationStart:g,onAnimationEnd:_,animationInterpolateFn:d,animationMatchBy:u,shouldUpdatePreviousRef:x,layout:f},(e,i,a)=>{var o=h||i<1,s=o?y(i,p):null;return b.createElement(SR,{props:n,points:e,clipPathId:t,pathRef:r,animationElapsedTime:i,isAnimating:o,isEntrance:a,visibleLength:s})}),b.createElement(aN,{label:n.label}))}function wR(e){var t=e.clipPathId,n=e.props,r=(0,b.useRef)(null),i=(0,b.useRef)(null);return b.createElement(CR,{props:n,clipPathId:t,previousPointsRef:r,pathRef:i})}var TR=(e,t)=>({x:e.x??void 0,y:e.y??void 0,value:e.value,errorVal:Bf(e.payload,t)}),ER=class extends b.Component{render(){var e=this.props,t=e.hide,n=e.dot,r=e.points,i=e.className,a=e.xAxisId,o=e.yAxisId,s=e.top,c=e.left,l=e.width,u=e.height,d=e.id,f=e.needClip,p=e.zIndex;if(t)return null;var m=G(`recharts-line`,i),h=d,g=rR(n),_=g.r,v=g.strokeWidth,y=yN(n),x=_*2+v,S=f?`url(#clipPath-${y?``:`dots-`}${h})`:void 0;return b.createElement(sA,{zIndex:p},b.createElement(So,{className:m},f&&b.createElement(`defs`,null,b.createElement(JL,{clipPathId:h,xAxisId:a,yAxisId:o}),!y&&b.createElement(`clipPath`,{id:`clipPath-dots-${h}`},b.createElement(`rect`,{x:c-x/2,y:s-x/2,width:l+x,height:u+x}))),b.createElement(KL,{xAxisId:a,yAxisId:o,data:r,dataPointFormatter:TR,errorBarOffset:0},b.createElement(wR,{props:this.props,clipPathId:h}))),b.createElement(aF,{activeDot:this.props.activeDot,points:r,mainColor:this.props.stroke,itemDataKey:this.props.dataKey,clipPath:S}))}};function DR(e){var t=fc(e,_R),n=t.activeDot,r=t.animateNewValues,i=t.animationBegin,a=t.animationDuration,o=t.animationEasing,s=t.connectNulls,c=t.dot,l=t.hide,u=t.isAnimationActive,d=t.label,f=t.legendType,p=t.xAxisId,m=t.yAxisId,h=t.id,g=cR(t,oR),_=qL(p,m).needClip,v=ZP(),y=ym(),x=kp(),S=J(e=>nR(e,p,m,x,h));if(y!==`horizontal`&&y!==`vertical`||S==null||v==null)return null;var C=v.height,w=v.width,T=v.x,E=v.y;return b.createElement(ER,sR({},g,{id:h,connectNulls:s,dot:c,activeDot:n,animateNewValues:r,animationBegin:i,animationDuration:a,animationEasing:o,isAnimationActive:u,hide:l,label:d,legendType:f,xAxisId:p,yAxisId:m,points:S,layout:y,height:C,width:w,left:T,top:E,needClip:_}))}function OR(e){var t=e.layout,n=e.xAxis,r=e.yAxis,i=e.xAxisTicks,a=e.yAxisTicks,o=e.dataKey,s=e.bandSize;return e.displayedData.map((e,c)=>{var l=Bf(e,o);if(t===`horizontal`)return{x:Yf({axis:n,ticks:i,bandSize:s,entry:e,index:c}),y:(Wo(l)?null:r.scale.map(l))??null,value:l,payload:e};var u=Wo(l)?null:n.scale.map(l),d=Yf({axis:r,ticks:a,bandSize:s,entry:e,index:c});return u==null||d==null?null:{x:u,y:d,value:l,payload:e}}).filter(Boolean)}function kR(e){var t=fc(e,_R),n=kp();return b.createElement(mP,{id:t.id,type:`line`},e=>b.createElement(b.Fragment,null,b.createElement(FN,{legendPayload:vR(t)}),b.createElement(yR,{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(xP,{type:`line`,id:e,data:t.data,xAxisId:t.xAxisId,yAxisId:t.yAxisId,zAxisId:0,dataKey:t.dataKey,hide:t.hide,isPanorama:n}),b.createElement(DR,sR({},t,{id:e}))))}var AR=b.memo(kR,Jm);AR.displayName=`Line`;function jR(e,t){return e.graphicalItems.cartesianItems.find(e=>e.id===t)?.xAxisId??0}function MR(e,t){return e.graphicalItems.cartesianItems.find(e=>e.id===t)?.yAxisId??0}var NR=(e,t,n)=>PD(e,`xAxis`,jR(e,t),n),PR=(e,t,n)=>ND(e,`xAxis`,jR(e,t),n),FR=(e,t,n)=>PD(e,`yAxis`,MR(e,t),n),IR=(e,t,n)=>ND(e,`yAxis`,MR(e,t),n),LR=Y([vm,NR,FR,PR,IR],(e,t,n,r,i)=>Hf(e,`xAxis`)?rp(t,r,!1):rp(n,i,!1)),RR=Y([UT,(e,t)=>t],(e,t)=>e.filter(e=>e.type===`area`).find(e=>e.id===t)),zR=e=>Hf(vm(e),`xAxis`)?`yAxis`:`xAxis`,BR=(e,t)=>zR(e)===`yAxis`?MR(e,t):jR(e,t),VR=(e,t,n)=>hE(e,zR(e),BR(e,t),n),HR=Y([vm,NR,FR,PR,IR,Y([RR,VR],(e,t)=>{if(e!=null&&t!=null){var n=e.stackId,r=vy(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]])}}}),lv,LR,RR,Jv,Y([RR,VR],(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(Ko)}})],(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 xz({layout:e,xAxis:t,yAxis:n,xAxisTicks:r,yAxisTicks:i,dataStartIndex:f,areaSettings:c,stackedData:a,displayedData:h,chartBaseValue:l,bandSize:s,stackDataKeys:u})}}),UR=[`animationElapsedTime`,`isAnimating`,`isEntrance`,`layout`,`isRange`,`stroke`,`connectNulls`],WR=[`id`,`baseLine`];function GR(){return GR=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},GR.apply(null,arguments)}function KR(e,t){if(e==null)return{};var n,r,i=qR(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 qR(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 JR(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(!$(a)||!$(o))return null;var s=t*Math.abs(a-o),c=Math.max(...r.map(e=>e.y||0));return q(n)?c=Math.max(n,c):n&&Array.isArray(n)&&n.length&&(c=Math.max(...n.map(e=>e.y||0),c)),q(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 YR(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(!$(a)||!$(o))return null;var s=t*Math.abs(a-o),c=Math.max(...r.map(e=>e.x||0));return q(n)?c=Math.max(n,c):n&&Array.isArray(n)&&n.length&&(c=Math.max(...n.map(e=>e.x||0),c)),q(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 XR(e){var t=e.alpha,n=e.layout,r=e.points,i=e.baseLine,a=e.strokeWidth;return n===`vertical`?b.createElement(YR,{alpha:t,points:r,baseLine:i,strokeWidth:a}):b.createElement(JR,{alpha:t,points:r,baseLine:i,strokeWidth:a})}function ZR(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=KR(e,UR),f=s===`vertical`?`vertical`:`horizontal`,p=u??!1,m=dP(),h=d.id,g=d.baseLine,_=co(KR(d,WR)),v=b.createElement(eg,GR({},d,{id:h,baseLine:g,connectNulls:p,stroke:`none`,className:`recharts-area-area`,layout:f})),y=l!==`none`&&b.createElement(eg,GR({},_,{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(eg,GR({},_,{className:`recharts-area-curve`,layout:f,type:d.type,connectNulls:p,fill:`none`,stroke:l,points:g}));return o&&(i||n<1)?b.createElement(So,null,b.createElement(`defs`,null,b.createElement(`clipPath`,{id:m},b.createElement(XR,{alpha:n,points:d.points??[],baseLine:g,layout:f,strokeWidth:d.strokeWidth}))),b.createElement(So,{clipPath:`url(#${m})`},v,y,x)):b.createElement(b.Fragment,null,v,y,x)}var QR=[`id`],$R=[`activeDot`,`animationBegin`,`animationDuration`,`animationEasing`,`connectNulls`,`dot`,`fill`,`fillOpacity`,`hide`,`isAnimationActive`,`legendType`,`stroke`,`xAxisId`,`yAxisId`];function ez(){return ez=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},ez.apply(null,arguments)}function tz(e,t){if(e==null)return{};var n,r,i=nz(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 nz(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 rz(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 iz(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?rz(Object(n),!0).forEach(function(t){az(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):rz(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function az(e,t,n){return(t=oz(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function oz(e){var t=sz(e,`string`);return typeof t==`symbol`?t:t+``}function sz(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 cz={activeDot:!0,animationBegin:0,animationDuration:1500,animationEasing:`ease`,animationMatchBy:HN,animationInterpolateFn:(e,t)=>e==null?[]:t===1?e.flatMap(e=>e.status===`removed`?[]:[e.next]):e.flatMap(e=>e.status===`matched`?[iz(iz({},e.next),{},{x:Ho(e.prev.x,e.next.x,t),y:Ho(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:ZR,xAxisId:0,yAxisId:0,zIndex:Yv.area};function lz(e,t){return e&&e!==`none`?e:t}var uz=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:lz(r,i),value:ap(n,t),payload:e}]},dz=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:qo,settings:{stroke:r,strokeWidth:i,fill:a,dataKey:t,nameKey:void 0,name:ap(o,t),hide:s,type:u,color:lz(r,a),unit:c,formatter:l,graphicalItemId:d}};return b.createElement(PN,{tooltipEntrySettings:f})});function fz(e){var t=e.clipPathId,n=e.points,r=e.props,i=r.needClip,a=r.dot,o=r.dataKey,s=co(r);return b.createElement(NP,{points:n,dot:a,className:`recharts-area-dots`,dotClassName:`recharts-area-dot`,dataKey:o,baseProps:s,needClip:i,clipPathId:t})}function pz(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 iz(iz({},t),{},{value:e.value,payload:e.payload,parentViewBox:void 0,viewBox:t,fill:void 0})});return b.createElement(eN,{value:t?r:void 0},n)}function mz(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=tz(a,QR),_=iz(iz({},uo(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(So,{clipPath:r?`url(#clipPath-${i})`:void 0},b.createElement(AN,{option:m,DefaultShape:cz.shape,shapeProps:_})),b.createElement(fz,{points:t,props:g,clipPathId:i}))}function hz(e,t,n){return q(e)?Ho(q(t)?t:void 0,e,n):Wo(e)||Fo(e)?Ho(q(t)?t:void 0,0,n):e}function gz(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=XN(m,a),g=bm(),_=rP(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)?YN(S,s,f):Array.isArray(s)?YN(null,s,f):null;return b.createElement(iP,{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:hz(s,S,i);return h.syncStepValue(c,i),b.createElement(pz,{showLabels:!v,points:o},r.children,b.createElement(mz,{points:e,baseLine:c,needClip:t,clipPathId:n,props:r,animationElapsedTime:i,isAnimating:v||i<1,isEntrance:a}),b.createElement(aN,{label:r.label}))})}function _z(e){var t=e.needClip,n=e.clipPathId,r=e.props,i=(0,b.useRef)(null),a=(0,b.useRef)();return b.createElement(gz,{needClip:t,clipPathId:n,props:r,previousPointsRef:i,previousBaselineRef:a})}var vz=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=G(`recharts-area`,i),g=f,_=rR(n),v=_.r,y=_.strokeWidth,x=yN(n),S=v*2+y,C=s?`url(#clipPath-${x?``:`dots-`}${g})`:void 0;return b.createElement(sA,{zIndex:m},b.createElement(So,{className:h},s&&b.createElement(`defs`,null,b.createElement(JL,{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(_z,{needClip:s,clipPathId:g,props:this.props})),b.createElement(aF,{points:r,mainColor:lz(this.props.stroke,this.props.fill),itemDataKey:this.props.dataKey,activeDot:this.props.activeDot,clipPath:C}),this.props.isRange&&Array.isArray(p)&&b.createElement(aF,{points:p,mainColor:lz(this.props.stroke,this.props.fill),itemDataKey:this.props.dataKey,activeDot:this.props.activeDot,clipPath:C}))}};function yz(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=tz(e,$R),g=ym(),_=Dk(),v=qL(p,m).needClip,y=kp(),x=J(t=>HR(t,e.id,y))??{},S=x.points,C=x.isRange,w=x.baseLine,T=ZP();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(vz,ez({},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 bz=(e,t,n,r,i)=>{var a=n??t;if(q(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 xz(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,_=bz(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=Bf(e,i);Array.isArray(o)?(r=o,y=!0):r=[_,o]}var s=r?.[1]??null,u=Bf(e,i),b=g&&u==null&&h!=null&&h.length>0&&h.every(t=>Bf(e,t)==null),x=s==null||g&&!n&&u==null||b;return v?{x:Yf({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:Yf({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 Sz(e){var t=fc(e,cz),n=kp();return b.createElement(mP,{id:t.id,type:`area`},e=>b.createElement(b.Fragment,null,b.createElement(FN,{legendPayload:uz(t)}),b.createElement(dz,{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(xP,{type:`area`,id:e,data:t.data,dataKey:t.dataKey,xAxisId:t.xAxisId,yAxisId:t.yAxisId,zAxisId:0,stackId:Jf(t.stackId),hide:t.hide,barSize:void 0,baseValue:t.baseValue,isPanorama:n,connectNulls:t.connectNulls}),b.createElement(yz,ez({},t,{id:e}))))}var Cz=b.memo(Sz,Jm);Cz.displayName=`Area`;var wz=`Invariant failed`;function Tz(e,t){if(!e)throw Error(wz)}var Ez=[`option`];function Dz(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}var kz=w_;function Az(e){var t=e.option,n=Dz(e,Ez);return b.createElement(AN,{option:t,DefaultShape:kz,shapeProps:n,activeClassName:`recharts-active-bar`,inActiveClassName:`recharts-inactive-bar`})}var jz=function(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0;return(n,r)=>{if(q(e))return e;var i=q(n)||Wo(n);return i?e(n,r):(!i&&Tz(!1,`minPointSize callback function received a value with type of ${typeof n}. Currently only numbers or null/undefined are supported.`),t)}},Mz=(e,t,n)=>n,Nz=Y([UT,(e,t)=>t],(e,t)=>e.filter(e=>e.type===`bar`).find(e=>e.id===t)),Pz=Y([Nz],e=>e?.maxBarSize),Fz=(e,t,n,r)=>r,Iz=Y([vm,UT,jR,MR,Mz],(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`)),Lz=(e,t,n)=>{var r=vm(e),i=jR(e,t),a=MR(e,t);if(i!=null&&a!=null)return r===`horizontal`?hE(e,`yAxis`,a,n):hE(e,`xAxis`,i,n)},Rz=Y([Iz,Vv,(e,t)=>{var n=vm(e),r=jR(e,t),i=MR(e,t);if(r!=null&&i!=null)return n===`horizontal`?OD(e,`xAxis`,r):OD(e,`yAxis`,i)}],pF),zz=(e,t,n)=>{var r=Nz(e,t);if(r==null)return 0;var i=jR(e,t),a=MR(e,t);if(i==null||a==null)return 0;var o=vm(e),s=Rv(e),c=r.maxBarSize,l=Wo(c)?s:c,u,d;return o===`horizontal`?(u=PD(e,`xAxis`,i,n),d=ND(e,`xAxis`,i,n)):(u=PD(e,`yAxis`,a,n),d=ND(e,`yAxis`,a,n)),rp(u,d,!0)??l??0},Bz=(e,t,n)=>{var r=vm(e),i=jR(e,t),a=MR(e,t);if(i!=null&&a!=null){var o,s;return r===`horizontal`?(o=PD(e,`xAxis`,i,n),s=ND(e,`xAxis`,i,n)):(o=PD(e,`yAxis`,a,n),s=ND(e,`yAxis`,a,n)),rp(o,s)}},Vz=Y([Tp,Dp,(e,t,n)=>{var r=jR(e,t);if(r!=null)return PD(e,`xAxis`,r,n)},(e,t,n)=>{var r=MR(e,t);if(r!=null)return PD(e,`yAxis`,r,n)},(e,t,n)=>{var r=jR(e,t);if(r!=null)return ND(e,`xAxis`,r,n)},(e,t,n)=>{var r=MR(e,t);if(r!=null)return ND(e,`yAxis`,r,n)},Y([Y([Rz,Rv,zv,Bv,zz,Bz,Pz],bF),Nz],SF),vm,lv,Bz,Y([Lz,Nz],xF),Nz,Fz],(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 AB({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})}}),Hz=[`index`];function Uz(){return Uz=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},Uz.apply(null,arguments)}function Wz(e,t){if(e==null)return{};var n,r,i=Gz(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 Gz(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 Kz=(0,b.createContext)(void 0),qz=e=>{var t=(0,b.useContext)(Kz);if(t!=null)return t.stackId;if(e!=null)return Jf(e)},Jz=(e,t)=>`recharts-bar-stack-clip-path-${e}-${t}`,Yz=e=>{var t=(0,b.useContext)(Kz);if(t!=null){var n=t.stackId;return`url(#${Jz(n,e)})`}},Xz=e=>{var t=e.index,n=Wz(e,Hz),r=Yz(t);return b.createElement(So,Uz({className:`recharts-bar-stack-layer`,clipPath:r},n))},Zz=[`onMouseEnter`,`onMouseLeave`,`onClick`],Qz=[`value`,`background`,`tooltipPosition`],$z=[`id`],eB=[`onMouseEnter`,`onClick`,`onMouseLeave`];function tB(e,t){return oB(e)||aB(e,t)||rB(e,t)||nB()}function nB(){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 rB(e,t){if(e){if(typeof e==`string`)return iB(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)?iB(e,t):void 0}}function iB(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 aB(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 oB(e){if(Array.isArray(e))return e}function sB(){return sB=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},sB.apply(null,arguments)}function cB(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 lB(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?cB(Object(n),!0).forEach(function(t){uB(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):cB(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function uB(e,t,n){return(t=dB(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function dB(e){var t=fB(e,`string`);return typeof t==`symbol`?t:t+``}function fB(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 pB(e,t){if(e==null)return{};var n,r,i=mB(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 mB(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 hB=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:ap(n,t),payload:e}]},gB=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:qo,settings:{stroke:n,strokeWidth:r,fill:i,dataKey:t,nameKey:void 0,name:ap(a,t),hide:o,type:l,color:i,unit:s,formatter:c,graphicalItemId:u}};return b.createElement(PN,{tooltipEntrySettings:d})});function _B(e){var t=J(rk),n=e.data,r=e.dataKey,i=e.background,a=e.allOtherBarProps,o=a.onMouseEnter,s=a.onMouseLeave,c=a.onClick,l=pB(a,Zz),u=jN(o,r,a.id),d=MN(s),f=NN(c,r,a.id);if(!i||n==null)return null;var p=lo(i);return b.createElement(sA,{zIndex:CF(i,Yv.barBackground)},n.map((e,n)=>{e.value;var a=e.background;e.tooltipPosition;var o=pB(e,Qz);if(!a)return null;var s=u(e,e.originalDataIndex),c=d(e,e.originalDataIndex),m=f(e,e.originalDataIndex),h=lB(lB(lB(lB(lB({option:i,isActive:String(e.originalDataIndex)===t},o),{},{fill:`#eee`},a),p),oc(l,e,n)),{},{onMouseEnter:s,onMouseLeave:c,onClick:m,dataKey:r,index:n,className:`recharts-bar-background-rectangle`});return b.createElement(Az,sB({key:`background-bar-${n}`},h))}))}function vB(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 lB(lB({},t),{},{value:e.value,payload:e.payload,parentViewBox:e.parentViewBox,viewBox:t,fill:e.fill})});return b.createElement(eN,{value:t?r:void 0},n)}function yB(e){var t=e.shape,n=e.activeBar,r=e.baseProps,i=e.entry,a=e.index,o=e.dataKey,s=J(rk),c=J(ak),l=n&&String(i.originalDataIndex)===s&&(c==null||o===c),u=s!=null&&(String(i.originalDataIndex)!==s||c!=null&&o!==c),d=tB((0,b.useState)(!1),2),f=d[0],p=d[1],m=tB((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(Az,sB({},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(sA,{zIndex:Yv.activeBar},b.createElement(Xz,{index:i.originalDataIndex},S)):S}function bB(e){var t=e.shape,n=e.baseProps,r=e.entry,i=e.index,a=e.dataKey;return b.createElement(Az,sB({},n,{name:String(n.name)},r,{isActive:!1,option:t,index:i,dataKey:a,animationElapsedTime:e.animationElapsedTime,isAnimating:e.isAnimating,isEntrance:e.isEntrance}))}function xB(e){var t=e.data,n=e.props,r=e.animationElapsedTime,i=e.isAnimating,a=e.isEntrance,o=co(n)??{},s=o.id,c=pB(o,$z),l=n.shape,u=n.dataKey,d=n.activeBar,f=n.onMouseEnter,p=n.onClick,m=n.onMouseLeave,h=pB(n,eB),g=jN(f,u,s),_=MN(m),v=NN(p,u,s);return t?b.createElement(b.Fragment,null,t.map((e,t)=>b.createElement(Xz,sB({index:e.originalDataIndex,key:`rectangle-${e?.x}-${e?.y}-${e?.value}-${t}`,className:`recharts-bar-rectangle`},oc(h,e,t),{onMouseEnter:g(e,e.originalDataIndex),onMouseLeave:_(e,e.originalDataIndex),onClick:v(e,e.originalDataIndex)}),d?b.createElement(yB,{shape:l,activeBar:d,baseProps:c,entry:e,index:t,dataKey:u,animationElapsedTime:r,isAnimating:i,isEntrance:a}):b.createElement(bB,{shape:l,baseProps:c,entry:e,index:t,dataKey:u,animationElapsedTime:r,isAnimating:i,isEntrance:a})))):null}var SB=(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`?[lB(lB({},e.prev),{},{height:Ho(e.prev.height,0,t),y:Ho(e.prev.y,e.prev.y+e.prev.height,t)})]:[lB(lB({},e.prev),{},{width:Ho(e.prev.width,0,t)})];if(e.status===`matched`)return[lB(lB({},e.next),{},{x:Ho(e.prev.x,e.next.x,t),y:Ho(e.prev.y,e.next.y,t),width:Ho(e.prev.width,e.next.width,t),height:Ho(e.prev.height,e.next.height,t)})];var r=e.next;return n===`horizontal`?[lB(lB({},r),{},{height:Ho(0,r.height,t),y:Ho(r.stackedBarStart,r.y,t)})]:[lB(lB({},r),{},{width:Ho(0,r.width,t),x:Ho(r.stackedBarStart,r.x,t)})]});function CB(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=rP(t.onAnimationStart,t.onAnimationEnd),d=u.isAnimating,f=u.handleAnimationStart,p=u.handleAnimationEnd;return b.createElement(vB,{showLabels:!d,rects:r},b.createElement(iP,{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(So,null,b.createElement(xB,{props:t,data:e,animationElapsedTime:n,isAnimating:d||n<1,isEntrance:r}))),b.createElement(aN,{label:t.label}),t.children)}function wB(e){var t=(0,b.useRef)(null);return b.createElement(CB,{previousRectanglesRef:t,props:e})}var TB=0,EB=(e,t)=>{var n=Array.isArray(e.value)?e.value[1]:e.value;return{x:e.x,y:e.y,value:n,errorVal:Bf(e,t)}},DB=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=G(`recharts-bar`,i),d=l;return b.createElement(So,{className:u,id:l},s&&b.createElement(`defs`,null,b.createElement(JL,{clipPathId:d,xAxisId:a,yAxisId:o})),b.createElement(So,{className:`recharts-bar-rectangles`,clipPath:s?`url(#clipPath-${d})`:void 0},b.createElement(_B,{data:n,dataKey:r,background:c,allOtherBarProps:this.props}),b.createElement(wB,this.props)))}},OB={activeBar:!1,animationBegin:0,animationDuration:400,animationEasing:`ease`,animationInterpolateFn:SB,animationMatchBy:UN,background:!1,hide:!1,isAnimationActive:`auto`,label:!1,legendType:`rect`,minPointSize:TB,shape:kz,xAxisId:0,yAxisId:0,zIndex:Yv.bar};function kB(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=qL(t,n).needClip,f=ym(),p=kp(),m=vN(e.children,sj),h=J(t=>Vz(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(KL,{xAxisId:t,yAxisId:n,data:h,dataPointFormatter:EB,errorBarOffset:g},b.createElement(DB,sB({},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 AB(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=Zf({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=Gf(E,y)}else p=Bf(e,r),Array.isArray(p)||(p=[b,p]);var D=jz(i,TB)(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=Xf({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=Fo(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=Po(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=Xf({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=Po(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:lB(lB({},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 jB(e){var t=fc(e,OB),n=qz(t.stackId),r=kp();return b.createElement(mP,{id:t.id,type:`bar`},e=>b.createElement(b.Fragment,null,b.createElement(FN,{legendPayload:hB(t)}),b.createElement(gB,{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(xP,{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!==kz}),b.createElement(sA,{zIndex:t.zIndex},b.createElement(kB,sB({},t,{id:e})))))}var MB=b.memo(jB,Jm);MB.displayName=`Bar`;var NB=[`domain`,`range`],PB=[`domain`,`range`];function FB(e,t){if(e==null)return{};var n,r,i=IB(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 IB(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 LB(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 RB(e,t){if(e===t)return!0;var n=e.domain,r=e.range,i=FB(e,NB),a=t.domain,o=t.range,s=FB(t,PB);return!LB(n,a)||!LB(r,o)?!1:Jm(i,s)}var zB=[`type`],BB=[`dangerouslySetInnerHTML`,`ticks`,`scale`],VB=[`id`,`scale`];function HB(){return HB=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},HB.apply(null,arguments)}function UB(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 WB(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?UB(Object(n),!0).forEach(function(t){GB(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):UB(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function GB(e,t,n){return(t=KB(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function KB(e){var t=qB(e,`string`);return typeof t==`symbol`?t:t+``}function qB(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 JB(e,t){if(e==null)return{};var n,r,i=YB(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 YB(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 XB(e){var t=Zc(),n=(0,b.useRef)(null),r=bm(),i=e.type,a=JB(e,zB),o=$v(r,`xAxis`,i),s=(0,b.useMemo)(()=>{if(o!=null)return WB(WB({},a),{},{type:o})},[a,o]);return(0,b.useLayoutEffect)(()=>{s!=null&&(n.current===null?t(VP(s)):n.current!==s&&t(HP({prev:n.current,next:s})),n.current=s)},[s,t]),(0,b.useLayoutEffect)(()=>()=>{n.current&&=(t(UP(n.current)),null)},[t]),null}var ZB=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=J(Dp),c=kp(),l=Zc(),u=`xAxis`,d=J(e=>MD(e,u,t,c)),f=J(e=>bD(e,t)),p=J(e=>TD(e,t)),m=J(e=>jT(e,t));if((0,b.useLayoutEffect)(()=>{if(!(r!==`auto`||!f||LM(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(JP({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=JB(e,BB);m.id,m.scale;var g=JB(m,VB);return b.createElement(nL,HB({},h,g,{ref:a,labelRef:o,x:p.x,y:p.y,width:f.width,height:f.height,className:G(`recharts-${u} ${u}`,n),viewBox:s,ticks:d,axisType:u,axisId:t}))},QB={allowDataOverflow:AT.allowDataOverflow,allowDecimals:AT.allowDecimals,allowDuplicatedCategory:AT.allowDuplicatedCategory,angle:AT.angle,axisLine:qI.axisLine,height:AT.height,hide:!1,includeHidden:AT.includeHidden,interval:AT.interval,label:!1,minTickGap:AT.minTickGap,mirror:AT.mirror,orientation:AT.orientation,padding:AT.padding,reversed:AT.reversed,scale:AT.scale,tick:AT.tick,tickCount:AT.tickCount,tickLine:qI.tickLine,tickSize:qI.tickSize,type:AT.type,niceTicks:AT.niceTicks,xAxisId:0},$B=b.memo(e=>{var t=fc(e,QB);return b.createElement(b.Fragment,null,b.createElement(XB,{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(ZB,t))},RB);$B.displayName=`XAxis`;var eV=[`type`],tV=[`dangerouslySetInnerHTML`,`ticks`,`scale`],nV=[`id`,`scale`];function rV(){return rV=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},rV.apply(null,arguments)}function iV(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 aV(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?iV(Object(n),!0).forEach(function(t){oV(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):iV(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function oV(e,t,n){return(t=sV(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function sV(e){var t=cV(e,`string`);return typeof t==`symbol`?t:t+``}function cV(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 lV(e,t){if(e==null)return{};var n,r,i=uV(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 uV(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 dV(e){var t=Zc(),n=(0,b.useRef)(null),r=bm(),i=e.type,a=lV(e,eV),o=$v(r,`yAxis`,i),s=(0,b.useMemo)(()=>{if(o!=null)return aV(aV({},a),{},{type:o})},[o,a]);return(0,b.useLayoutEffect)(()=>{s!=null&&(n.current===null?t(WP(s)):n.current!==s&&t(GP({prev:n.current,next:s})),n.current=s)},[s,t]),(0,b.useLayoutEffect)(()=>()=>{n.current&&=(t(KP(n.current)),null)},[t]),null}function fV(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=J(Dp),c=kp(),l=Zc(),u=`yAxis`,d=J(e=>DD(e,t)),f=J(e=>ED(e,t)),p=J(e=>MD(e,u,t,c)),m=J(e=>PT(e,t));if((0,b.useLayoutEffect)(()=>{if(!(r!==`auto`||!d||LM(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(qP({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=lV(e,tV);m.id,m.scale;var g=lV(m,nV);return b.createElement(nL,rV({},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:G(`recharts-${u} ${u}`,n),viewBox:s,ticks:p,axisType:u,axisId:t}))}var pV={allowDataOverflow:NT.allowDataOverflow,allowDecimals:NT.allowDecimals,allowDuplicatedCategory:NT.allowDuplicatedCategory,angle:NT.angle,axisLine:qI.axisLine,hide:!1,includeHidden:NT.includeHidden,interval:NT.interval,label:!1,minTickGap:NT.minTickGap,mirror:NT.mirror,orientation:NT.orientation,padding:NT.padding,reversed:NT.reversed,scale:NT.scale,tick:NT.tick,tickCount:NT.tickCount,tickLine:qI.tickLine,tickSize:qI.tickSize,type:NT.type,niceTicks:NT.niceTicks,width:NT.width,yAxisId:0},mV=b.memo(e=>{var t=fc(e,pV);return b.createElement(b.Fragment,null,b.createElement(dV,{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(fV,t))},RB);mV.displayName=`YAxis`;var hV=Y([(e,t)=>t,vm,hy,wy,XO,QO,jk,Tp],Uk);function gV(e){return`getBBox`in e.currentTarget&&typeof e.currentTarget.getBBox==`function`}function _V(e){var t=e.currentTarget.getBoundingClientRect(),n,r;if(gV(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 vV=gd(`mouseClick`),yV=wf();yV.startListening({actionCreator:vV,effect:(e,t)=>{var n=e.payload,r=hV(t.getState(),_V(n));r?.activeIndex!=null&&t.dispatch(tO({activeIndex:r.activeIndex,activeDataKey:void 0,activeCoordinate:r.activeCoordinate}))}});var bV=gd(`mouseMove`),xV=wf(),SV=null,CV=null,wV=null;xV.startListening({actionCreator:bV,effect:(e,t)=>{var n=e.payload,r=t.getState().eventSettings,i=r.throttleDelay,a=r.throttledEvents,o=a===`all`||a?.includes(`mousemove`);SV!==null&&(cancelAnimationFrame(SV),SV=null),CV!==null&&(typeof i!=`number`||!o)&&(clearTimeout(CV),CV=null),wV=_V(n);var s=()=>{var e=t.getState(),n=zD(e,e.tooltip.settings.shared);if(!wV){SV=null,CV=null;return}if(n===`axis`){var r=hV(e,wV);r?.activeIndex==null?t.dispatch(QD()):t.dispatch(eO({activeIndex:r.activeIndex,activeDataKey:void 0,activeCoordinate:r.activeCoordinate}))}SV=null,CV=null};if(!o){s();return}i===`raf`?SV=requestAnimationFrame(s):typeof i==`number`&&CV===null&&(CV=setTimeout(s,i))}});function TV(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 EV={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},DV=Ld({name:`rootProps`,initialState:EV,reducers:{updateOptions:(e,t)=>{e.accessibilityLayer=t.payload.accessibilityLayer,e.barCategoryGap=t.payload.barCategoryGap,e.barGap=t.payload.barGap??EV.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}}}),OV=DV.reducer,kV=DV.actions.updateOptions,AV=Ld({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)}});AV.actions.updatePolarOptions;var jV=AV.reducer,MV=gd(`keyDown`),NV=gd(`focus`),PV=gd(`blur`),FV=wf(),IV=null,LV=null,RV=null;FV.startListening({actionCreator:MV,effect:(e,t)=>{RV=e.payload,IV!==null&&(cancelAnimationFrame(IV),IV=null);var n=t.getState().eventSettings,r=n.throttleDelay,i=n.throttledEvents,a=i===`all`||i.includes(`keydown`);LV!==null&&(typeof r!=`number`||!a)&&(clearTimeout(LV),LV=null);var o=()=>{try{var e=t.getState();if(e.rootProps.accessibilityLayer===!1)return;var n=e.tooltip.keyboardInteraction,r=RV;if(r!==`ArrowRight`&&r!==`ArrowLeft`&&r!==`Enter`)return;var i=gO(n,RO(e),fE(e),qO(e)),a=i==null?-1:Number(i),o=!Number.isFinite(a)||a<0,s=QO(e),c=RO(e),l=zD(e,e.tooltip.settings.shared);if(r===`Enter`){if(o)return;var u=Ik(e,l,`hover`,String(n.index));t.dispatch(rO({active:!n.active,activeIndex:n.index,activeCoordinate:u}));return}var d=FD(e)===`left-to-right`?1:-1,f=r===`ArrowRight`?1:-1,p;if(o){var m=fE(e),h=qO(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(gO(_(v),c,m,h)!=null){p=v;break}}else for(var y=c.length-1;y>=0;y--)if(gO(_(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=Ik(e,l,`hover`,String(p));t.dispatch(rO({active:!0,activeIndex:p.toString(),activeCoordinate:x}))}finally{IV=null,LV=null}};if(!a){o();return}r===`raf`?IV=requestAnimationFrame(o):typeof r==`number`&&LV===null&&(o(),RV=null,LV=setTimeout(()=>{RV?o():(LV=null,IV=null)},r))}}),FV.startListening({actionCreator:NV,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=Ik(n,zD(n,n.tooltip.settings.shared),`hover`,String(i));t.dispatch(rO({active:!0,activeIndex:i,activeCoordinate:a}))}}}}),FV.startListening({actionCreator:PV,effect:(e,t)=>{var n=t.getState();if(n.rootProps.accessibilityLayer!==!1){var r=n.tooltip.keyboardInteraction;r.active&&t.dispatch(rO({active:!1,activeIndex:r.index,activeCoordinate:r.coordinate}))}}});function zV(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 BV=gd(`externalEvent`),VV=wf(),HV=new Map,UV=new Map,WV=new Map;VV.startListening({actionCreator:BV,effect:(e,t)=>{var n=e.payload,r=n.handler,i=n.reactEvent;if(r!=null){var a=i.type,o=zV(i);WV.set(a,{handler:r,reactEvent:o});var s=HV.get(a);s!==void 0&&(cancelAnimationFrame(s),HV.delete(a));var c=t.getState().eventSettings,l=c.throttleDelay,u=c.throttledEvents,d=u===`all`||u?.includes(a),f=UV.get(a);f!==void 0&&(typeof l!=`number`||!d)&&(clearTimeout(f),UV.delete(a));var p=()=>{var e=WV.get(a);try{if(!e)return;var n=e.handler,r=e.reactEvent,i=t.getState(),o={activeCoordinate:ck(i),activeDataKey:ak(i),activeIndex:rk(i),activeLabel:ik(i),activeTooltipIndex:rk(i),isTooltipActive:lk(i)};n&&n(o,r)}finally{HV.delete(a),UV.delete(a),WV.delete(a)}};if(!d){p();return}if(l===`raf`){var m=requestAnimationFrame(p);HV.set(a,m)}else if(typeof l==`number`){if(!UV.has(a)){p();var h=setTimeout(p,l);UV.set(a,h)}}else p()}}});var GV=Y([Y([bO],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)}}}),KV=gd(`touchMove`),qV=wf(),JV=null,YV=null,XV=null,ZV=null;qV.startListening({actionCreator:KV,effect:(e,t)=>{var n=e.payload;if(n.touches!=null&&n.touches.length!==0){ZV=zV(n);var r=t.getState().eventSettings,i=r.throttleDelay,a=r.throttledEvents,o=a===`all`||a.includes(`touchmove`);JV!==null&&(cancelAnimationFrame(JV),JV=null),YV!==null&&(typeof i!=`number`||!o)&&(clearTimeout(YV),YV=null),XV=Array.from(n.touches).map(e=>_V({clientX:e.clientX,clientY:e.clientY,currentTarget:n.currentTarget}));var s=()=>{if(ZV!=null){var e=t.getState(),n=zD(e,e.tooltip.settings.shared);if(n===`axis`){var r=XV?.[0];if(r==null){JV=null,YV=null;return}var i=hV(e,r);i?.activeIndex!=null&&t.dispatch(eO({activeIndex:i.activeIndex,activeDataKey:void 0,activeCoordinate:i.activeCoordinate}))}else if(n===`item`){var a=ZV.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(mp),c=o.getAttribute(`data-recharts-item-id`)??void 0,l=PO(e).find(e=>e.id===c);if(s==null||l==null||c==null)return;var u=l.dataKey,d=GV(e,s,c);t.dispatch(XD({activeDataKey:u,activeIndex:s,activeCoordinate:d,activeGraphicalItemId:c}))}JV=null,YV=null}};if(!o){s();return}i===`raf`?JV=requestAnimationFrame(s):typeof i==`number`&&YV===null&&(s(),ZV=null,YV=setTimeout(()=>{ZV?s():(YV=null,JV=null)},i))}}});var QV={throttleDelay:`raf`,throttledEvents:[`mousemove`,`touchmove`,`pointermove`,`scroll`,`wheel`]},$V=Ld({name:`eventSettings`,initialState:QV,reducers:{setEventSettings:(e,t)=>{t.payload.throttleDelay!=null&&(e.throttleDelay=t.payload.throttleDelay),t.payload.throttledEvents!=null&&(e.throttledEvents=dd(t.payload.throttledEvents))}}}),eH=$V.actions.setEventSettings,tH=$V.reducer,nH=zl({brush:DF,cartesianAxis:YP,chartData:MA,errorBars:VL,eventSettings:tH,graphicalItems:bP,layout:Mf,legend:km,options:TA,polarAxis:uN,polarOptions:jV,referenceElements:FF,renderedTicks:AI,rootProps:OV,tooltip:iO,zIndex:oA}),rH=function(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:`Chart`;return Dd({reducer:nH,preloadedState:e,middleware:e=>e({serializableCheck:!1,immutableCheck:![`commonjs`,`es6`,`production`].includes(`es6`)}).concat([yV.middleware,xV.middleware,FV.middleware,VV.middleware,qV.middleware]),enhancers:e=>{var t=e;return typeof e==`function`&&(t=e()),t.concat(Td({type:`raf`}))},devTools:_h.devToolsEnabled&&{serialize:{replacer:TV},name:`recharts-${t}`}})};function iH(e){var t=e.preloadedState,n=e.children,r=e.reduxStoreName,i=kp(),a=(0,b.useRef)(null);if(i)return n;a.current??=rH(t,r);var o=Jc;return b.createElement(Gm,{context:o,store:a.current},n)}function aH(e){var t=e.layout,n=e.margin,r=Zc(),i=kp();return(0,b.useEffect)(()=>{i||(r(kf(t)),r(Of(n)))},[r,i,t,n]),null}var oH=(0,b.memo)(aH,Jm);function sH(e){var t=Zc();return(0,b.useEffect)(()=>{t(kV(e))},[t,e]),null}var cH=(0,b.memo)(e=>{var t=Zc();return(0,b.useEffect)(()=>{t(eH(e))},[t,e]),null},Jm);function lH(e){var t=e.zIndex,n=e.isPanorama,r=(0,b.useRef)(null),i=Zc();return(0,b.useLayoutEffect)(()=>(r.current&&i(iA({zIndex:t,element:r.current,isPanorama:n})),()=>{i(aA({zIndex:t,isPanorama:n}))}),[i,t,n]),b.createElement(`g`,{tabIndex:-1,ref:r,className:`recharts-zIndex-layer_${t}`})}function uH(e){var t=e.children,n=e.isPanorama,r=J(Gk);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(lH,{key:e,zIndex:e,isPanorama:n})),t,a.map(e=>b.createElement(lH,{key:e,zIndex:e,isPanorama:n})))}var dH=[`children`];function fH(e,t){if(e==null)return{};var n,r,i=pH(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 pH(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 mH(){return mH=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},mH.apply(null,arguments)}var hH={width:`100%`,height:`100%`,display:`block`},gH=(0,b.forwardRef)((e,t)=>{var n=gm(),r=_m(),i=zh();if(!Pf(n)||!Pf(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(_o,mH({},o,{title:s,desc:c,role:u,tabIndex:l,width:n,height:r,style:hH,ref:t}),a)}),_H=e=>{var t=e.children,n=J(jp);if(!n)return null;var r=n.width,i=n.height,a=n.y,o=n.x;return b.createElement(_o,{width:r,height:i,x:o,y:a},t)},vH=(0,b.forwardRef)((e,t)=>{var n=e.children,r=fH(e,dH);return kp()?b.createElement(_H,null,b.createElement(uH,{isPanorama:!0},n)):b.createElement(gH,mH({ref:t},r),b.createElement(uH,{isPanorama:!1},n))});function yH(e,t){return wH(e)||CH(e,t)||xH(e,t)||bH()}function bH(){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 xH(e,t){if(e){if(typeof e==`string`)return SH(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)?SH(e,t):void 0}}function SH(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 CH(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 wH(e){if(Array.isArray(e))return e}function TH(){var e=Zc(),t=yH((0,b.useState)(null),2),n=t[0],r=t[1],i=J(up);return(0,b.useEffect)(()=>{if(n!=null){var t=n.getBoundingClientRect().width/n.offsetWidth;$(t)&&t!==i&&e(jf(t))}},[n,e,i]),r}function EH(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 DH(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?EH(Object(n),!0).forEach(function(t){OH(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):EH(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function OH(e,t,n){return(t=kH(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function kH(e){var t=AH(e,`string`);return typeof t==`symbol`?t:t+``}function AH(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 jH(){return jH=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},jH.apply(null,arguments)}function MH(e,t){return LH(e)||IH(e,t)||PH(e,t)||NH()}function NH(){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 PH(e,t){if(e){if(typeof e==`string`)return FH(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)?FH(e,t):void 0}}function FH(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 IH(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 LH(e){if(Array.isArray(e))return e}var RH=()=>(UA(),null);function zH(e){if(typeof e==`number`)return e;if(typeof e==`string`){var t=parseFloat(e);if(!Number.isNaN(t))return t}return 0}var BH=(0,b.forwardRef)((e,t)=>{var n=(0,b.useRef)(null),r=MH((0,b.useState)({containerWidth:zH(e.style?.width),containerHeight:zH(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(Cm,{width:i.containerWidth,height:i.containerHeight}),b.createElement(`div`,jH({ref:s},e)))}),VH=(0,b.forwardRef)((e,t)=>{var n=e.width,r=e.height,i=MH((0,b.useState)({containerWidth:zH(n),containerHeight:zH(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(Cm,{width:a.containerWidth,height:a.containerHeight}),b.createElement(`div`,jH({ref:c},e)))}),HH=(0,b.forwardRef)((e,t)=>{var n=e.width,r=e.height;return b.createElement(b.Fragment,null,b.createElement(Cm,{width:n,height:r}),b.createElement(`div`,jH({ref:t},e)))}),UH=(0,b.forwardRef)((e,t)=>{var n=e.width,r=e.height;return typeof n==`string`||typeof r==`string`?b.createElement(VH,jH({},e,{ref:t})):typeof n==`number`&&typeof r==`number`?b.createElement(HH,jH({},e,{width:n,height:r,ref:t})):b.createElement(b.Fragment,null,b.createElement(Cm,{width:n,height:r}),b.createElement(`div`,jH({ref:t},e)))});function WH(e){return e?BH:UH}var GH=(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=Zc(),w=MH((0,b.useState)(null),2),T=w[0],E=w[1],D=MH((0,b.useState)(null),2),O=D[0],k=D[1],A=TH(),j=um(),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(vV(e)),C(BV({handler:a,reactEvent:e}))},[C,a]),P=(0,b.useCallback)(e=>{C(bV(e)),C(BV({handler:l,reactEvent:e}))},[C,l]),F=(0,b.useCallback)(e=>{C(QD()),C(BV({handler:u,reactEvent:e}))},[C,u]),ne=(0,b.useCallback)(e=>{C(bV(e)),C(BV({handler:d,reactEvent:e}))},[C,d]),re=(0,b.useCallback)(()=>{C(NV())},[C]),ie=(0,b.useCallback)(()=>{C(PV())},[C]),ae=(0,b.useCallback)(e=>{C(MV(e.key))},[C]),I=(0,b.useCallback)(e=>{C(BV({handler:o,reactEvent:e}))},[C,o]),oe=(0,b.useCallback)(e=>{C(BV({handler:s,reactEvent:e}))},[C,s]),se=(0,b.useCallback)(e=>{C(BV({handler:c,reactEvent:e}))},[C,c]),ce=(0,b.useCallback)(e=>{C(BV({handler:f,reactEvent:e}))},[C,f]),le=(0,b.useCallback)(e=>{C(BV({handler:h,reactEvent:e}))},[C,h]),ue=(0,b.useCallback)(e=>{x&&C(KV(e)),C(BV({handler:m,reactEvent:e}))},[C,x,m]),de=(0,b.useCallback)(e=>{C(BV({handler:p,reactEvent:e}))},[C,p]),fe=WH(v);return b.createElement(_A.Provider,{value:T},b.createElement(rs.Provider,{value:O},b.createElement(fe,{width:M??g?.width,height:N??g?.height,className:G(`recharts-wrapper`,r),style:DH({position:`relative`,cursor:`default`,width:M,height:N},g),onClick:te,onContextMenu:I,onDoubleClick:oe,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(RH,null),n)))}),KH=[`width`,`height`,`responsive`,`children`,`className`,`style`,`compact`,`title`,`desc`];function qH(e,t){if(e==null)return{};var n,r,i=JH(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 JH(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 YH=(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=co(qH(e,KH));return c?b.createElement(b.Fragment,null,b.createElement(Cm,{width:n,height:r}),b.createElement(vH,{otherAttributes:d,title:l,desc:u},a)):b.createElement(GH,{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(vH,{otherAttributes:d,title:l,desc:u,ref:t},b.createElement(UF,null,a)))});function XH(){return XH=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},XH.apply(null,arguments)}function ZH(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 QH(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?ZH(Object(n),!0).forEach(function(t){$H(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ZH(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function $H(e,t,n){return(t=eU(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function eU(e){var t=tU(e,`string`);return typeof t==`symbol`?t:t+``}function tU(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 nU=QH({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`},QV),rU=(0,b.forwardRef)(function(e,t){var n=fc(e.categoricalChartProps,nU),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(iH,{preloadedState:{options:c},reduxStoreName:s.id??r},b.createElement(wF,{chartData:s.data}),b.createElement(oH,{layout:n.layout,margin:n.margin}),b.createElement(cH,{throttleDelay:n.throttleDelay,throttledEvents:n.throttledEvents}),b.createElement(sH,{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(YH,XH({},n,{ref:t})))}),iU=[`axis`,`item`],aU=(0,b.forwardRef)((e,t)=>b.createElement(rU,{chartName:`BarChart`,defaultTooltipEventType:`axis`,validateTooltipEventTypes:iU,tooltipPayloadSearcher:CA,categoricalChartProps:e,ref:t})),oU=[`axis`],sU=(0,b.forwardRef)((e,t)=>b.createElement(rU,{chartName:`AreaChart`,defaultTooltipEventType:`axis`,validateTooltipEventTypes:oU,tooltipPayloadSearcher:CA,categoricalChartProps:e,ref:t})),cU=[`axis`],lU=(0,b.forwardRef)((e,t)=>b.createElement(rU,{chartName:`ComposedChart`,defaultTooltipEventType:`axis`,validateTooltipEventTypes:cU,tooltipPayloadSearcher:CA,categoricalChartProps:e,ref:t})),uU=[`system`,`tools`,`user`,`assistant`],dU={system:`bg-accent-indigo`,tools:`bg-accent-amber`,user:`bg-accent-blue`,assistant:`bg-accent-green`},fU={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)]`},pU={system:`bg-accent-indigo`,tools:`bg-accent-amber`,user:`bg-accent-blue`,assistant:`bg-accent-green`},mU={system:`System`,tools:`Tools`,user:`User`,assistant:`Assistant`},hU={system:`#6366f1`,tools:`#ffb224`,user:`#0095ff`,assistant:`#1ce783`},gU={fontSize:10,fill:`#6b7280`},_U=`#2a2a3a`;function vU({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)(fm,{width:`100%`,height:120,children:(0,x.jsxs)(sU,{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)(EL,{strokeDasharray:`3 3`,stroke:_U}),(0,x.jsx)($B,{dataKey:`turn`,tick:gU,stroke:_U}),(0,x.jsx)(mV,{domain:[0,100],unit:`%`,tick:gU,stroke:_U}),(0,x.jsx)(oj,{contentStyle:{backgroundColor:`#1a1a2e`,border:`1px solid #2a2a3a`,fontSize:11},formatter:(e,t)=>[`${e.toFixed(1)}%`,t],labelFormatter:e=>`Turn ${e}`}),(0,x.jsx)(rI,{y1:80,y2:100,fill:`url(#${n})`,ifOverflow:`visible`}),uU.map(e=>(0,x.jsx)(Cz,{type:`monotone`,dataKey:e,stackId:`context`,stroke:hU[e],fill:hU[e],fillOpacity:.4,strokeWidth:1,dot:!1},e))]})})})}function yU(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e)}function bU(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 xU({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:({signal:e})=>jr(t??void 0,e),refetchInterval:1e4,enabled:!e}),{data:m}=L({queryKey:[`context-composition`,t],queryFn:({signal:e})=>Mr(e),enabled:l}),{data:h}=L({queryKey:[`context-efficiency`,t],queryFn:({signal:e})=>Nr(e),enabled:l}),g=e??p,_=t??``,v=e?bU(e,_):i??(g?bU(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)(oi,{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:[yU(T.currentTokens),k&&k>0&&(0,x.jsx)(`span`,{className:`text-ink-muted`,children:` / ${yU(k)}`}),T.delta>0&&(0,x.jsxs)(`span`,{className:`text-accent-amber ml-1`,children:[`+`,yU(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:uU.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:`${dU[e]} transition-all duration-500 ease-out cursor-default relative ${r?`brightness-125 ${fU[e]}`:``}`,style:{width:`${t/D*S}%`},title:`${mU[e]}: ${yU(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:[uU.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 ${pU[e]} ${n?`scale-150`:``} transition-transform duration-200`}),mU[e],n&&t>0&&(0,x.jsx)(`span`,{className:`text-ink-subtle ml-0.5`,children:yU(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)(vU,{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 SU={success:`success`,failure:`danger`,unknown:`neutral`};function CU({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,Zr.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)(wU,{label:`Longest failure streak`,value:String(e.longestFailureStreak)}),(0,x.jsx)(wU,{label:`Success rate`,value:e.successRate===null?`—`:`${Math.round(e.successRate*100)}%`}),(0,x.jsx)(wU,{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)(oi,{tone:SU[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)(wU,{label:`Total attributed cost`,value:`$${t.totalAttributedCost.toFixed(2)}`}),(0,x.jsx)(wU,{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,` · `,Oi(e.inputTokens),` in /`,` `,Oi(e.outputTokens),` out /`,` `,Oi(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)(vU,{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 wU({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})]})}function TU({theme:e=`observatory`}){return(0,x.jsxs)(`div`,{className:`geo-banner`,"aria-hidden":`true`,children:[e===`observatory`&&(0,x.jsx)(EU,{}),e===`sessions`&&(0,x.jsx)(DU,{}),e===`history`&&(0,x.jsx)(OU,{}),e===`audit`&&(0,x.jsx)(kU,{}),e===`git`&&(0,x.jsx)(AU,{})]})}function EU(){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 DU(){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 OU(){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 kU(){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 AU(){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`})]})}var jU={good:`Healthy`,warn:`Watch`,bad:`Needs attention`,neutral:`No data`},MU={good:`text-accent-green`,warn:`text-accent-amber`,bad:`text-accent-red`,neutral:`text-ink-base`},NU={good:`success`,warn:`warning`,bad:`danger`,neutral:`neutral`};function PU({title:e,tooltip:t,value:n,tone:r,detail:i,rows:a}){return(0,x.jsxs)($r,{title:e,tooltip:t,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,x.jsx)(`span`,{className:`text-2xl font-semibold ${MU[r??`neutral`]}`,children:n}),r&&(0,x.jsx)(oi,{tone:NU[r],children:jU[r]})]}),i&&(0,x.jsx)(`div`,{className:`mt-1 text-[10px] text-ink-muted`,children:i}),a&&a.length>0&&(0,x.jsx)(`div`,{className:`mt-3 space-y-1`,children:a.slice(0,4).map(e=>(0,x.jsxs)(`div`,{className:`flex items-center justify-between text-[11px]`,children:[(0,x.jsx)(`span`,{className:`text-ink-muted`,children:e.label}),(0,x.jsx)(`span`,{className:`text-ink-base tabular-nums`,children:e.value})]},e.label))})]})}var FU=176,IU={fill:`var(--color-ink-muted)`,fontSize:10},LU=`var(--color-border-subtle)`,RU={background:`var(--color-bg-elevated)`,border:`1px solid var(--color-border-medium)`,borderRadius:8,fontSize:12,color:`var(--color-ink-base)`},zU=`var(--color-chart-block)`,BU=`var(--color-accent-green)`;function VU({active:e,payload:t,tooltipLabel:n}){if(!e||!t||t.length===0)return null;let r=t[0].payload,i=n?n(r):r.label,a=[`${i} — ${Ei(r.spendUsd)}`];return r.cumulativeUsd!=null&&a.push(`${i} — cumulative ${Ei(r.cumulativeUsd)}`),r.projectedUsd!=null&&a.push(`${i} — projected ${Ei(r.projectedUsd)}`),(0,x.jsx)(`div`,{style:RU,className:`px-2 py-1.5`,children:a.map(e=>(0,x.jsx)(`div`,{children:e},e))})}function HU({data:e,height:t=FU,xTickFormatter:n,yTickFormatter:r=Fi,tooltipLabel:i}){let a=e.some(e=>e.cumulativeUsd!=null),o=e.some(e=>e.projectedUsd!=null);return(0,x.jsx)(`div`,{className:`min-w-0`,style:{height:t},children:(0,x.jsx)(fm,{width:`100%`,height:`100%`,minWidth:1,minHeight:1,children:(0,x.jsxs)(lU,{data:e,children:[(0,x.jsx)(EL,{stroke:LU,strokeDasharray:`3 3`}),(0,x.jsx)($B,{dataKey:`key`,tick:IU,stroke:LU,tickFormatter:n,interval:`preserveStartEnd`,minTickGap:20}),(0,x.jsx)(mV,{tick:IU,stroke:LU,tickFormatter:r}),(0,x.jsx)(oj,{content:e=>(0,x.jsx)(VU,{...e,tooltipLabel:i}),cursor:!1}),(0,x.jsx)(MB,{dataKey:`spendUsd`,fill:zU,radius:[3,3,0,0],isAnimationActive:!1}),a&&(0,x.jsx)(AR,{type:`monotone`,dataKey:`cumulativeUsd`,isAnimationActive:!1,stroke:BU,strokeWidth:2,dot:!1}),o&&(0,x.jsx)(AR,{type:`monotone`,dataKey:`projectedUsd`,isAnimationActive:!1,stroke:BU,strokeWidth:2,strokeDasharray:`4 3`,dot:!1})]})})})}function UU({direction:e}){return e===null?(0,x.jsx)(fn,{className:`w-3 h-3 opacity-30`,"aria-hidden":`true`}):e===`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`})}function WU(e,t){return typeof e==`string`||typeof t==`string`?String(e).localeCompare(String(t)):e-t}function GU({title:e,columns:t,rows:n,rowKey:r,className:i,defaultSort:a,hideTitle:o,totalCount:s}){let c=s!==void 0&&s>n.length?`top ${n.length} of ${s}`:null,[l,u]=(0,b.useState)(a??null);function d(e){u(t=>t&&t.column===e?{column:e,direction:t.direction===`desc`?`asc`:`desc`}:{column:e,direction:`desc`})}let f=(l?t[l.column]:void 0)?.sortValue,p=l&&f?[...n].sort((e,t)=>{let n=WU(f(e),f(t));return l.direction===`asc`?n:-n}):n;return(0,x.jsxs)(`div`,{className:i?`text-xs ${i}`:`text-xs`,children:[!o&&(0,x.jsxs)(`h4`,{className:`text-ink-muted font-medium mb-2`,children:[e,c&&(0,x.jsx)(`span`,{className:`text-ink-subtle font-normal ml-1`,children:c})]}),o&&c&&(0,x.jsx)(`p`,{className:`text-ink-subtle mb-1`,children:c}),(0,x.jsx)(`div`,{className:`max-h-40 overflow-auto`,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.jsx)(`tr`,{children:t.map((e,t)=>{let n=e.align===`right`?`text-right pb-1`:`text-left pb-1`;if(!e.sortValue)return(0,x.jsx)(`th`,{className:n,children:e.header},e.header);let r=l?.column===t?l.direction:null;return(0,x.jsx)(`th`,{className:n,"aria-sort":r===`asc`?`ascending`:r===`desc`?`descending`:`none`,children:(0,x.jsxs)(`button`,{type:`button`,onClick:()=>d(t),className:`inline-flex items-center gap-1 hover:text-ink-subtle`,children:[e.header,(0,x.jsx)(UU,{direction:r})]})},e.header)})})}),(0,x.jsx)(`tbody`,{children:p.map(e=>(0,x.jsx)(`tr`,{className:`border-t border-bg-line`,children:t.map(t=>{let n=t.align===`right`?`py-1 text-right tabular-nums`:`py-1 text-ink-base`,r=typeof t.className==`function`?t.className(e):t.className;return(0,x.jsx)(`td`,{className:r?`${n} ${r}`:n,title:t.title?.(e),children:t.cell(e)},t.header)})},r(e)))})]})})]})}function KU({insights:e,emptyText:t=`Nothing stands out in this window.`}){return e.length===0?(0,x.jsx)(`p`,{className:`text-xs text-ink-muted`,children:t}):(0,x.jsx)(`div`,{className:`mb-4 space-y-2`,children:e.map(e=>(0,x.jsxs)(`div`,{className:`text-xs`,children:[(0,x.jsx)(`p`,{className:`text-ink-base font-medium`,children:e.headline}),(0,x.jsx)(`p`,{className:`text-ink-muted`,children:e.advice})]},e.id))})}function qU(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 JU(e,t){let n=qU(e),r=n.reduce((e,t)=>e+t.count,0),i=t?n.reduce((e,n)=>e+(t[n.tool]?.totalCost??0),0):0;return n.map(e=>{let n=t?.[e.tool],a=i>0?(n?.totalCost??0)/i*100:r>0?e.count/r*100:0;return{tool:Ai(e.tool),count:e.count,sharePct:a,costUsd:n?.totalCost,tokens:n?.tokens}})}function YU(e){return H(e.costUsd!==void 0&&e.costUsd>0&&e.sharePct===0?.1:e.sharePct)}function XU(e){return e.breakdown?ki(e.breakdown):void 0}function ZU({data:e,isError:t,title:n,subtitle:r,modelRows:i,toolRows:a,toolCostAvailable:o=!1,toolCoverageCaveat:s=null}){if(t)return(0,x.jsx)($r,{title:n,subtitle:r,children:(0,x.jsx)(W,{icon:`radar`,title:`Usage insights unavailable`})});if(!e)return(0,x.jsx)($r,{title:n,subtitle:r,children:(0,x.jsx)(W,{variant:`loading`,title:`Loading usage insights…`})});let c=e.insights??[],l=e.skills??[],u=e.subagents??[],d=e.plugins??[],f=e.loops??[];return(0,x.jsxs)($r,{title:n,subtitle:r,children:[(0,x.jsx)(`p`,{className:`text-xs text-ink-muted mb-3`,children:`Approximate, based on sessions recorded on this machine. These are independent characteristics of your spend, not a breakdown.`}),e.sessionCount===0?(0,x.jsx)(W,{icon:`clock`,title:`No sessions in this window.`}):(0,x.jsx)(KU,{insights:c}),e.sessionCount>0&&(0,x.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-4 text-xs mt-4`,children:[i&&i.length>0&&(0,x.jsx)(GU,{title:`Models`,rows:i,rowKey:e=>e.model,defaultSort:{column:4,direction:`desc`},columns:[{header:`Model`,align:`left`,className:`font-mono truncate max-w-[12rem]`,title:e=>e.model,cell:e=>e.model},{header:`Req`,align:`right`,cell:e=>e.requestCount,sortValue:e=>e.requestCount},{header:`$/1M tok`,align:`right`,cell:e=>Di(e.costPerMillionTokens),sortValue:e=>e.costPerMillionTokens??0},{header:`Cost`,align:`right`,cell:e=>Ei(e.totalCostUsd),sortValue:e=>e.totalCostUsd},{header:`Share`,align:`right`,cell:e=>H(e.sharePct),sortValue:e=>e.sharePct}]}),l.length>0&&(0,x.jsx)(GU,{title:`Skills`,rows:l,totalCount:e.skillsTotalCount,rowKey:e=>e.key,defaultSort:{column:4,direction:`desc`},columns:[{header:`Skill`,align:`left`,cell:e=>e.key},{header:`Calls`,align:`right`,cell:e=>e.count,sortValue:e=>e.count},{header:`Tokens`,align:`right`,cell:e=>Oi(e.tokens),sortValue:e=>e.tokens,title:XU},{header:`Cost`,align:`right`,cell:e=>Di(e.costUsd),sortValue:e=>e.costUsd,title:XU},{header:`% of spend`,align:`right`,cell:e=>YU(e),sortValue:e=>e.sharePct}]}),u.length>0&&(0,x.jsx)(GU,{title:`Subagents`,rows:u,totalCount:e.subagentsTotalCount,rowKey:e=>e.key,defaultSort:{column:4,direction:`desc`},columns:[{header:`Type`,align:`left`,cell:e=>e.key},{header:`Requests`,align:`right`,cell:e=>e.count,sortValue:e=>e.count},{header:`Tokens`,align:`right`,cell:e=>Oi(e.tokens),sortValue:e=>e.tokens,title:XU},{header:`Cost`,align:`right`,cell:e=>Di(e.costUsd),sortValue:e=>e.costUsd,title:XU},{header:`% of spend`,align:`right`,cell:e=>YU(e),sortValue:e=>e.sharePct}]}),d.length>0&&(0,x.jsx)(GU,{title:`Plugins`,rows:d,totalCount:e.pluginsTotalCount,rowKey:e=>e.key,defaultSort:{column:4,direction:`desc`},columns:[{header:`Plugin`,align:`left`,cell:e=>e.key},{header:`Calls`,align:`right`,cell:e=>e.count,sortValue:e=>e.count},{header:`Tokens`,align:`right`,cell:e=>Oi(e.tokens),sortValue:e=>e.tokens,title:XU},{header:`Cost`,align:`right`,cell:e=>Di(e.costUsd),sortValue:e=>e.costUsd,title:XU},{header:`% of spend`,align:`right`,cell:e=>YU(e),sortValue:e=>e.sharePct}]}),f.length>0&&(0,x.jsx)(GU,{title:`Loops`,className:`md:col-span-2`,rows:f,totalCount:e.loopsTotalCount,rowKey:e=>e.sessionId,defaultSort:{column:4,direction:`desc`},columns:[{header:`Session`,align:`left`,className:`truncate`,title:e=>e.sessionName||e.sessionId,cell:e=>(0,x.jsx)(Zt,{href:`/sessions?sessionIds=${encodeURIComponent(e.sessionId)}`,className:`text-accent-cyan hover:underline transition-colors duration-150`,children:e.sessionName||e.sessionId.slice(0,8)})},{header:`Runs`,align:`right`,cell:e=>e.runs,sortValue:e=>e.runs},{header:`Tokens`,align:`right`,cell:e=>Oi(e.tokens),sortValue:e=>e.tokens},{header:`Per run`,align:`right`,cell:e=>Oi(e.tokensPerRun),sortValue:e=>e.tokensPerRun},{header:`Cost`,align:`right`,cell:e=>Di(e.costUsd),sortValue:e=>e.costUsd},{header:`Last run`,align:`right`,className:`text-ink-muted`,cell:e=>wi(e.lastRunMs),sortValue:e=>e.lastRunMs}]}),a.length>0&&(0,x.jsx)(GU,{title:`Tools`,rows:a,rowKey:e=>e.tool,defaultSort:{column:o?4:2,direction:`desc`},columns:[{header:`Tool`,align:`left`,cell:e=>e.tool},{header:`Calls`,align:`right`,cell:e=>e.count,sortValue:e=>e.count},...o?[{header:`Cost`,align:`right`,cell:e=>Di(e.costUsd),sortValue:e=>e.costUsd??0},{header:`Tokens`,align:`right`,cell:e=>e.tokens===void 0?`—`:Oi(e.tokens),sortValue:e=>e.tokens??0}]:[],{header:o?`% of spend`:`Share of calls`,align:`right`,cell:e=>o?YU(e):H(e.sharePct),sortValue:e=>e.sharePct}]})]}),e.attributionRatePct!==null&&e.attributionRatePct<50&&(0,x.jsxs)(`p`,{className:`text-[10px] text-ink-muted italic mt-3`,children:[`Skill and tool shares are based on `,Math.round(e.attributionRatePct),`% of spend with attribution.`]}),s&&(0,x.jsx)(`p`,{className:`text-[10px] text-ink-muted italic mt-3`,children:s})]})}var QU={over_delegation:`Over-delegation`,re_reading:`Repeated reads`,stuck_loop:`Stuck loop`,blind_editing:`Blind editing`,thrashing:`Edit/test thrashing`,anti_pattern_flags:`Anti-pattern flags`},$U={re_reading:`Read a file once and keep it in context. Use /compact when the window fills instead of re-reading.`,blind_editing:`Read the file before editing it, and verify each edit before the next.`,thrashing:`Verify changes with a test between edits instead of alternating edit and test blindly.`,stuck_loop:`The same command keeps failing. Read the error and change the approach before retrying.`,over_delegation:`Spawn subagents only for work that needs its own context, and use a cheaper model for simple ones.`,anti_pattern_flags:`Detail lives in each session record. Open a session to see where the flags landed.`},eW=3;function tW(e){let t=QU[e];if(t)return t;let n=e.replace(/_/g,` `);return n.charAt(0).toUpperCase()+n.slice(1)}function nW(e){return e.split(`/`).pop()||e}function rW({rows:e,firingCount:t,alertsHref:n}){return e.length===0&&t===0?(0,x.jsx)(W,{variant:`inline`,title:`Nothing needs attention.`}):(0,x.jsxs)(`div`,{children:[t>0&&(0,x.jsxs)(`a`,{href:n,className:`text-[11px] text-accent-red hover:underline`,children:[t,` firing`]}),e.length>0&&(0,x.jsx)(`ul`,{className:`divide-y divide-border-subtle`,children:e.map(e=>{let t=e.targets.slice(0,eW).map(nW),n=e.targets.length-t.length,r=$U[e.type];return(0,x.jsxs)(`li`,{className:`py-1.5 first:pt-0 last:pb-0`,children:[(0,x.jsxs)(`div`,{className:`text-xs font-medium text-ink-base`,children:[tW(e.type),` ×`,e.count]}),t.length>0&&(0,x.jsxs)(`div`,{className:`text-[11px] font-mono text-ink-muted truncate`,children:[t.join(` · `),n>0?` +${n} more`:``]}),(r||e.sessionIds.length>0)&&(0,x.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[r&&(0,x.jsx)(`div`,{className:`text-[11px] text-ink-muted`,children:r}),e.sessionIds.length>0&&(0,x.jsx)(`a`,{href:`/sessions?sessionIds=${e.sessionIds.join(`,`)}`,className:`shrink-0 text-[11px] text-accent-cyan hover:underline`,children:`View sessions →`})]})]},e.type)})})]})}function iW(e){return new Intl.DateTimeFormat(`en-US`,{timeZone:e}).resolvedOptions().timeZone}var aW=new Map;function oW(e){let t=iW(e),n=aW.get(t);return n||(n=new Intl.DateTimeFormat(`en-US`,{timeZone:t,year:`numeric`,month:`2-digit`,day:`2-digit`}),aW.set(t,n)),n}var sW=new Map;function cW(e){let t=iW(e),n=sW.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}),sW.set(t,n)),n}function lW(e,t){let n=oW(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 uW(e,t){let n=cW(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 dW(e,t,n,r){let i=Date.UTC(e,t-1,n),a=uW(i,r),o=i-a,s=uW(o,r);if(s===a)return o;let c=i-s,l=lW(c,r);return l.year===e&&l.month===t&&l.day===n?c:o}function fW(e,t){if(t){let{year:n,month:r,day:i}=lW(e??Date.now(),t);return dW(n,r,i,t)}let n=e==null?new Date:new Date(e);return n.setHours(0,0,0,0),n.getTime()}function pW(e,t,n){if(n){let r=lW(e,n),i=lW(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 mW(e,t){let n=fW(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 hW=864e5;function gW(e){let t=fW(e),n=new Date(t).getDay();return t-(n===0?6:n-1)*hW}function _W(e,t,n,r){let i=Math.max(t,n),a=fW(r),o=gW(r),s=0;for(let t of e)t.startTime==null||t.estimatedCostUsd==null||t.estimatedCostUsd<=0||t.startTime<o||t.startTime>=a||(s+=t.estimatedCostUsd);let c=Math.round((a-o)/hW)+1,l=new Date(a).getDay(),u=l===0?0:7-l,d=(s+i)/Math.max(1,c),f=s+i+d*u;return Math.max(f,i)}function vW(e){let t=new Date(e);return new Date(t.getFullYear(),t.getMonth(),1).getTime()}function yW(e){let t=new Date(e);return new Date(t.getFullYear(),t.getMonth()+1,0).getDate()}function bW(e,t,n,r){let i=Math.max(t,n),a=fW(r),o=vW(r),s=0;for(let t of e)t.startTime==null||t.estimatedCostUsd==null||t.estimatedCostUsd<=0||t.startTime<o||t.startTime>=a||(s+=t.estimatedCostUsd);let c=Math.round((a-o)/hW)+1,l=new Date(a).getDate(),u=Math.max(0,yW(r)-l),d=(s+i)/Math.max(1,c),f=s+i+d*u;return Math.max(f,i)}var xW={weekday:`short`,month:`short`,day:`numeric`,hour:`numeric`,minute:`2-digit`},SW=3e4,CW={info:`text-ink-muted`,warning:`text-accent-amber`,critical:`text-accent-red`};function wW(e){return e.count??e.iterations??e.readCount??e.repeatCount??e.editCount??e.agentCount??0}function TW(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 EW=1e4;function DW(){let e=qn(e=>e.cost),t=qn(e=>e.antiPatterns),n=Zn(),{data:r}=L({queryKey:[`observability-health`],queryFn:({signal:e})=>Vr(e),refetchInterval:3e4}),{data:i,isPending:a}=L({queryKey:z.cost,queryFn:({signal:e})=>or(e),refetchInterval:1e4}),{data:o,isPending:s}=L({queryKey:z.sessionsTodayAggregate,queryFn:({signal:e})=>rr(e),refetchInterval:1e4}),{data:c,isPending:l}=L({queryKey:z.sessionsList(200),queryFn:({signal:e})=>nr(200,e),refetchInterval:1e4}),{data:u,isPending:d}=L({queryKey:z.antiPatterns,queryFn:({signal:e})=>sr(e)}),{data:f,isPending:p}=L({queryKey:z.concurrency,queryFn:({signal:e})=>Or(e),refetchInterval:1e4}),{data:m,isPending:h}=L({queryKey:z.activityHeatmap(`today`),queryFn:({signal:e})=>Ar(`today`,void 0,e),refetchInterval:3e4}),{data:g,isPending:_}=L({queryKey:z.sessionsLive,queryFn:({signal:e})=>ir(e),refetchInterval:1e4}),v=(0,b.useMemo)(()=>YW(c??[]),[c]),y=(0,b.useMemo)(()=>XW(c??[]),[c]),S=(0,b.useMemo)(()=>ZW(c??[]),[c]),C=(0,b.useMemo)(()=>(c??[]).filter(e=>qW(e)>0).flatMap(e=>(e.antiPatterns??[]).map(t=>({...t,sessionId:e.sessionId}))),[c]),w=(a||l||s)&&!e&&v===0&&o===void 0,T=Math.max(e?.todayTotalUsd??0,o?.totalCostUsd??0,v,i?.sessionTodayUsd??0),E=Math.max(u?.length??0,t.length),D=Math.max(o?.antiPatternCount??0,y+E),O=w?null:o?.forecastEndOfDayUsd??e?.forecastEodUsd??i?.forecast?.forecastEndOfDayUsd??null,k=Math.max(o?.subagentUsd??0,n.usd);(o!==void 0||n.turns>0)&&T>0&&`${H(k/T*100)}`;let A=r?.watcherActive===!1&&k===0,j=o&&o.totalCostUsd>=T?o.totalCostUsd:T,M=O===null?null:_W(c??[],O,j,Date.now()),[N,ee]=(0,b.useState)(()=>new Date().toLocaleString(void 0,xW)),te=(0,b.useRef)(Date.now());(0,b.useEffect)(()=>{let e=setInterval(()=>{let e=Date.now();ee(new Date(e).toLocaleString(void 0,xW)),pW(e,te.current)||(te.current=e,qn.getState().handleDayRollover())},6e4);return()=>clearInterval(e)},[]);let P=o?.avgEfficiencyScore??null,F=P!==null&&Number.isFinite(P)?H(P*100):`—`,ne=P===null?`needs more data`:Math.round(P*100)>=80?`strong session`:Math.round(P*100)>=50?`mixed signals`:`needs attention`,re=!w&&!s&&!l&&!d&&!p&&!h&&!_&&(o?.sessionCount??0)===0&&T===0&&D===0;return(0,x.jsxs)(`section`,{children:[(0,x.jsx)(TU,{}),(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:N})]}),re?(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(oa,{index:0,className:`glass-card p-8 mb-4`,children:(0,x.jsx)(W,{icon:`code`,title:`No activity yet today`,subtitle:`Metrics will appear here once you start a coding session with Claude.`})}),(0,x.jsx)(oa,{index:1,className:`mb-3`,children:(0,x.jsx)(AW,{todaySessions:c??[]})}),(0,x.jsx)(oa,{index:2,children:(0,x.jsx)(kW,{antiPatterns:t,apiAntiPatterns:u,persistedAntiPatterns:C,flagsCount:D})})]}):(0,x.jsxs)(x.Fragment,{children:[(0,x.jsxs)(oa,{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)(U,{label:`efficiency`,hero:!0,value:F,sub:ne,...P===null?{}:{animate:!0,numericValue:Math.round(P*100),suffix:`%`}}),(0,x.jsx)(U,{label:`spend today`,tone:`good`,value:w?`…`:Ei(T),sub:O!=null&&O>T?M==null?`→ ${Ei(O)} by end of day`:`→ ${Ei(O)} by end of day · ~${Ei(M)} by end of week`:void 0,...w?{}:{animate:!0,numericValue:T,format:Ei}}),(0,x.jsx)(U,{label:`avg cost / session`,value:Di(o&&o.sessionCount>0?T/o.sessionCount:null)}),(0,x.jsx)(U,{label:`sessions today`,value:o?String(o.sessionCount):`—`,...o?{animate:!0,numericValue:o.sessionCount}:{}}),(0,x.jsx)(U,{label:`flags`,tone:D>0?`warn`:`neutral`,value:String(D),animate:!0,numericValue:D})]})}),A&&(0,x.jsxs)(`div`,{className:`mt-2 text-[10px] text-ink-muted`,children:[`Subagent cost tracking is disabled (`,(0,x.jsx)(`code`,{className:`font-mono`,children:`NR_AI_ENABLE_SUBAGENT_WATCHER=0`}),`), so spend shown here excludes subagents. Unset it and restart to see full spend.`]})]}),(0,x.jsxs)(oa,{index:1,className:`grid grid-cols-3 gap-3 mb-3 items-start`,children:[(0,x.jsx)(`div`,{className:`col-span-2`,children:(0,x.jsx)(RW,{hourlySpend:S,forecastEod:O,weekForecast:M})}),(0,x.jsx)(HW,{todayHeatmap:m,concurrency:f})]}),(0,x.jsx)(oa,{index:2,className:`mb-3`,children:(0,x.jsx)(kW,{antiPatterns:t,apiAntiPatterns:u,persistedAntiPatterns:C,flagsCount:D})}),(0,x.jsx)(oa,{index:3,className:`mb-3`,children:(0,x.jsx)(AW,{todaySessions:c??[]})}),(0,x.jsx)(oa,{index:4,children:(0,x.jsx)(WW,{sessions:c??[],liveSessions:g??[]})}),(0,x.jsxs)(oa,{index:5,className:`grid grid-cols-3 gap-3 mb-3`,children:[(0,x.jsx)(MW,{aggregate:o}),(0,x.jsx)(NW,{}),(0,x.jsx)(PW,{}),(0,x.jsx)(FW,{liveSessions:g??[]}),(0,x.jsx)(IW,{aggregate:o}),(0,x.jsx)(LW,{})]})]})]})}function OW(e){let t=new Map;for(let n of e){let e=t.get(n.type)??{count:0,targets:new Set,sessionIds:new Set};e.count+=n.count,n.target&&n.target!==`unknown`&&e.targets.add(n.target),n.sessionId&&e.sessionIds.add(n.sessionId),t.set(n.type,e)}return[...t.entries()].map(([e,{count:t,targets:n,sessionIds:r}])=>({type:e,count:t,targets:[...n],sessionIds:[...r]})).sort((e,t)=>t.count-e.count)}function kW({antiPatterns:e,apiAntiPatterns:t,persistedAntiPatterns:n,flagsCount:r}){let{data:i,error:a}=L({queryKey:z.alertsRecent,queryFn:async({signal:e})=>{try{return await br(e)}catch(e){if(e instanceof $n)return null;throw e}},refetchInterval:SW,retry:!1}),o=[...i??[]].sort((e,t)=>t.firedAt-e.firedAt),s=o.filter(e=>e.state===`firing`).length,c=OW(e.length>0?e.map(e=>({type:e.type,count:e.count,target:e.target})):t&&t.length>0?t.map(e=>({type:e.type,count:wW(e),target:e.file??e.command??`unknown`})):n.map(e=>({type:e.type,count:wW(e),target:e.file??e.command??`unknown`,sessionId:e.sessionId}))),l=c.length===0&&r>0?[{type:`anti_pattern_flags`,count:r,targets:[],sessionIds:[]}]:c;return(0,x.jsxs)($r,{title:`Needs attention`,children:[a&&(0,x.jsx)(`div`,{className:`text-accent-red text-[11px] mb-2`,children:`Error loading recent alerts.`}),(0,x.jsx)(rW,{rows:l,firingCount:s,alertsHref:`/alerts`}),o.length>0&&(0,x.jsxs)(`table`,{className:`w-full text-xs mt-3`,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:o.slice(0,5).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:wi(e.firedAt)}),(0,x.jsxs)(`td`,{className:`py-1`,children:[(0,x.jsx)(`span`,{"aria-hidden":`true`,className:CW[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:[Ti(e.value),` / `,Ti(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 AW({todaySessions:e}){let{data:t}=L({queryKey:z.costPerTool(),queryFn:({signal:e})=>Ir(void 0,void 0,e),refetchInterval:EW,retry:!1}),{data:n}=L({queryKey:z.modelUsage,queryFn:({signal:e})=>Pr(e),refetchInterval:EW}),{data:r,isError:i}=L({queryKey:z.usageInsights(`today`),queryFn:({signal:e})=>hr(`today`,e),refetchInterval:EW}),a=n?.byModel?Object.entries(n.byModel).filter(([,e])=>e.requestCount>0):[],o=a.reduce((e,[,t])=>e+t.totalCostUsd,0),s=a.map(([e,t])=>({model:e,requestCount:t.requestCount,costPerMillionTokens:t.costPerMillionTokens,totalCostUsd:t.totalCostUsd,sharePct:o>0?t.totalCostUsd/o*100:0})),c=JU(e.filter(e=>qW(e)>0),t?.costByToolType),l=t?.attributionRate??1;return(0,x.jsx)(ZU,{data:r,isError:i,title:`Where today's spend went`,subtitle:`Since midnight`,modelRows:s,toolRows:c,toolCostAvailable:!0,toolCoverageCaveat:t!=null&&l<.5?`Tool and skill shares are based on ${H(l*100)} of session cost`:null})}function jW(e){switch(e){case`excellent`:return`Hit rate above 60%`;case`can_improve`:return`Hit rate between 30% and 60%`;case`needs_attention`:return`Hit rate below 30%`;default:return`No cache activity`}}function MW({aggregate:e}){let{data:t}=L({queryKey:z.cacheHealth,queryFn:({signal:e})=>Fr(e),refetchInterval:EW}),n=e?.cacheHealth,r=!n||n.status===`no_cache_activity`||n.cacheHitRatePct==null,i=`Prompt cache hit rate today, with a suggestion for improving it — usually by moving stable context earlier in the prompt.`;if(r)return(0,x.jsx)(PU,{title:`Cache Health`,tooltip:i,value:`—`,tone:`neutral`,detail:`Appears once token usage with cache reads is reported.`});let a=n.status===`excellent`?`good`:n.status===`can_improve`?`warn`:`bad`,o=[{label:`Cache read`,value:Oi(n.totalCacheReadTokens)},{label:`Cache write`,value:Oi(n.totalCacheCreationTokens)}];if(t?.week_over_week_delta_pts!=null&&t.week_over_week_delta_pts!==0){let e=t.week_over_week_delta_pts;o.push({label:`vs last week`,value:`${e>0?`+`:``}${e}pts`})}return(0,x.jsx)(PU,{title:`Cache Health`,tooltip:i,value:H(n.cacheHitRatePct),tone:a,detail:`${jW(n.status)} · ${Ei(n.totalSavingsUsd)} saved today`,rows:o})}function NW(){let{data:e}=L({queryKey:z.toolSelectionScore,queryFn:({signal:e})=>Tr(e),refetchInterval:EW}),t=`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.`;if(!e||Array.isArray(e)||e.totalCalls===0)return(0,x.jsx)(PU,{title:`Tool Selection`,tooltip:t,value:`—`,tone:`neutral`,detail:`Waiting for tool calls.`});let n=e.score>=.9?`good`:e.score>=.7?`warn`:`bad`;return(0,x.jsx)(PU,{title:`Tool Selection`,tooltip:t,value:H(e.score*100),tone:n,detail:`${e.penalizedCalls} of ${e.totalCalls} calls penalized`,rows:[{label:`Re-reads`,value:String(e.redundantReadCount)},{label:`Repeat fails`,value:String(e.repeatedFailureCount)},{label:`Unused output`,value:String(e.unusedOutputCount)}]})}function PW(){let{data:e}=L({queryKey:z.qualityProxy,queryFn:({signal:e})=>wr(e),refetchInterval:EW}),t=`Diff apply rate and test pass rate across today's sessions, plus how often you backtracked or self-corrected. Watch for the degrading status if quality drops mid-session.`;if(!e||e.totalSignals===0)return(0,x.jsx)(PU,{title:`Quality`,tooltip:t,value:`—`,tone:`neutral`,detail:`Waiting for edits and test runs.`});let n=e.degradationDetected?`bad`:`good`;return(0,x.jsx)(PU,{title:`Quality`,tooltip:t,value:e.diffApplyRate===null?`—`:H(e.diffApplyRate*100),tone:n,rows:[{label:`Test pass`,value:e.testPassRate===null?`—`:H(e.testPassRate*100)},{label:`Backtracks`,value:String(e.backtrackCount)},{label:`Self-corrections`,value:String(e.selfCorrectionCount)}]})}function FW({liveSessions:e}){let{data:t,isPending:n}=L({queryKey:z.computeWaste,queryFn:({signal:e})=>cr(e),retry:!1}),r=`Tokens wasted today on retried tool calls and anti-pattern activity (stuck loops, redundant reads, thrashing).`;if(n||!t||typeof t.total_tokens_wasted!=`number`)return(0,x.jsx)(PU,{title:`Compute Waste`,tooltip:r,value:`—`,tone:`neutral`,detail:`No compute waste data yet.`});let i=t.status===`clean`?`good`:t.status===`moderate`?`warn`:`bad`,a=t.by_session?.[0]??null,o=t.breakdown[0]??null,s=[{label:`Retry`,value:`~${Oi(t.retry_tokens_wasted)}`},{label:`Anti-pattern`,value:`~${Oi(t.anti_pattern_tokens_wasted)}`}];return a!==null&&s.push({label:`Top session`,value:`${GW(a.session_id,e)} (~${Oi(a.tokens_wasted)})`}),(0,x.jsx)(PU,{title:`Compute Waste`,tooltip:r,value:`~${Oi(t.total_tokens_wasted)} tokens`,tone:i,detail:TW(t.status,o?.type??null),rows:s})}function IW({aggregate:e}){let t=e?.latency,n=`How long tool calls took today — p50/p95/p99 across all calls, plus the slowest tools by p95.`;if(!t||!t.overall)return(0,x.jsx)(PU,{title:`Latency`,tooltip:n,value:`—`,tone:`neutral`,detail:`Waiting for tool calls.`});let r=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,2):[],i=[{label:`p50`,value:ji(t.overall.p50)},{label:`p99`,value:ji(t.overall.p99)},...r.map(([e,t])=>({label:Ai(e),value:ji(t.p95)}))];return(0,x.jsx)(PU,{title:`Latency`,tooltip:n,value:ji(t.overall.p95),rows:i})}function LW(){let{data:e}=L({queryKey:z.apiFailures,queryFn:({signal:e})=>Gr(e),refetchInterval:EW}),t=e?.byErrorType?Object.entries(e.byErrorType).filter(([,e])=>e>0):[],n=e?.totalFailures??0;return(0,x.jsx)(PU,{title:`API Failures`,tooltip:`Turns that failed outright after Claude Code's own retries were exhausted, captured via its StopFailure hook.`,value:String(n),tone:n===0?`good`:`bad`,detail:`Reflects Claude Code's StopFailure hook`,rows:t.length>0?t.map(([e,t])=>({label:e,value:String(t)})):void 0})}function RW({hourlySpend:e,forecastEod:t,weekForecast:n}){let r=e.some(e=>e.cost>0),i=(0,b.useMemo)(()=>QW(e,t,Date.now()),[e,t]);return(0,x.jsx)($r,{title:`Spend by hour`,subtitle:`Today`,children:r?(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(HU,{data:i,xTickFormatter:e=>BW(Number(e)),tooltipLabel:e=>e.label}),n!==null&&(0,x.jsxs)(`p`,{className:`mt-1.5 text-[10px] text-ink-muted`,children:[`On pace for ~`,Ei(n),` this week`]})]}):(0,x.jsx)(W,{variant:`inline`,title:`No spend data yet`})})}function zW(e,t,n=`sum`){let r=fW(t),i=r+864e5,a=Array(24).fill(0);for(let{ts:t,value:o}of e){if(t<r||t>=i)continue;let e=Math.min(23,Math.floor((t-r)/36e5));a[e]=n===`max`?Math.max(a[e],o):a[e]+o}return a}function BW(e){return`${String(e).padStart(2,`0`)}:00`}function VW(e,t){let n=Math.max(0,...e);return n===0?`No ${t} recorded yet.`:`Peak ${BW(e.indexOf(n))} — ${n} ${t}`}function HW({todayHeatmap:e,concurrency:t}){let n=Date.now(),r=(e?.buckets?.length??0)>0,i=(t?.buckets?.length??0)>0,a=r?zW(e.buckets.map((t,n)=>({ts:e.startTimestamp+n*e.bucketSizeMs,value:t})),n):[],o=a.map((e,t)=>({count:e,tooltip:`${BW(t)} — ${e} calls`})),s=(i?zW(t.buckets.map(e=>({ts:e.timestamp,value:e.count})),n,`max`):[]).map((e,t)=>({count:e,tooltip:`${BW(t)} — ${e} concurrent`}));return(0,x.jsx)($r,{title:`Activity today`,children:(0,x.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,x.jsxs)(`div`,{children:[(0,x.jsx)(V,{className:`mb-1.5`,children:`Tool calls`}),(0,x.jsx)(`div`,{className:`flex items-end`,children:r?(0,x.jsx)(da,{data:o,levels:6,ariaLabel:`Today's activity density by hour`}):(0,x.jsx)(W,{variant:`inline`,title:`No heatmap data yet`})}),(0,x.jsx)(`p`,{className:`mt-1.5 text-[10px] text-ink-muted`,children:VW(a,`calls`)})]}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(V,{className:`mb-1.5`,children:`Concurrent sessions`}),(0,x.jsx)(`div`,{className:`flex items-end`,children:i?(0,x.jsx)(da,{data:s,levels:6,ariaLabel:`Concurrency over time, peak ${t?.peak??0}`}):(0,x.jsx)(W,{variant:`inline`,title:`No session data yet`})}),(0,x.jsxs)(`p`,{className:`mt-1.5 text-[10px] text-ink-muted`,children:[`now `,t?.current??0,` · peak `,t?.peak??0]})]})]})})}var UW=3e3;function WW({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:({signal:e})=>tr(e)}),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=(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&&KW(t.startTime),a=r.has(t.sessionId),o=t.startTime!=null&&t.durationMs!=null?t.startTime+t.durationMs:null,s=o!=null&&o>=n&&KW(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]),p=(t.length>0?t[0].sessionId:null)??(d.size>0?[...d][0]:null)??(f.length>0?f[0].sessionId:null),m=n??p,h=m!==null&&d.has(m),g=n!==null&&!d.has(n);(0,b.useEffect)(()=>{l(m)},[m,l]);let{data:_}=L({queryKey:m?z.sessionReplay(m):[`replay`,`none`],queryFn:({signal:e})=>xr(m,e),enabled:m!==null,retry:!1,refetchInterval:h?UW:!1}),{data:v}=L({queryKey:m?z.sessionSubagents(m):[`subagents`,`none`],queryFn:({signal:e})=>Sr(m,e),enabled:m!==null,retry:!1,refetchInterval:h?UW:!1}),{data:y}=L({queryKey:z.workflows,queryFn:({signal:e})=>Hr(e),refetchInterval:h?1e4:!1}),{data:S}=L({queryKey:m?[`turn-costs`,m]:[`turn-costs`],queryFn:({signal:e})=>ur(m??void 0,e),refetchInterval:1e4}),{data:C}=L({queryKey:m?[`decision-tree`,m]:[`decision-tree`],queryFn:({signal:e})=>lr(m??void 0,e),refetchInterval:1e4}),{data:w}=L({queryKey:m?[`context`,m]:z.context,queryFn:({signal:e})=>jr(m??void 0,e),refetchInterval:1e4,enabled:h&&!!m}),{data:T}=L({queryKey:[`context-composition`],queryFn:({signal:e})=>Mr(e),refetchInterval:1e4}),{data:E}=L({queryKey:[`context-efficiency`],queryFn:({signal:e})=>Nr(e),refetchInterval:1e4}),D=(0,b.useRef)(null);(0,b.useEffect)(()=>{h&&D.current&&(D.current.scrollTop=D.current.scrollHeight)},[_?.timeline?.length,h]);let O=(0,b.useMemo)(()=>_?.timeline??[],[_]),k=(0,b.useMemo)(()=>Array.isArray(v?.agents)?v.agents:[],[v]),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=(v?.agents?.length??0)>0?v.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,v]),j=(0,b.useMemo)(()=>{let e={};if(Array.isArray(y))for(let t of y)t&&typeof t.runId==`string`&&typeof t.status==`string`&&t.parentSessionId===m&&(e[t.runId]=t.status);return e},[y,m]);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)(Qr,{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:[f.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 `+(m===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)(ci,{label:`live`,size:`sm`}):(0,x.jsx)(`span`,{className:`text-[10px] text-ink-muted`,title:e.startTime?`Started ${xi(e.startTime)}`:void 0,children:e.startTime?xi(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:Ei(e.estimatedCostUsd)}):(0,x.jsx)(`span`,{children:`—`})]})]},e.sessionId)}),d.size===0&&f.length===0&&(0,x.jsx)(W,{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:[m&&(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:[g&&(0,x.jsx)(`span`,{"data-testid":`session-ended-badge`,children:(0,x.jsx)(oi,{tone:`neutral`,size:`sm`,uppercase:!0,children:`Session ended`})}),(0,x.jsx)(`button`,{type:`button`,onClick:()=>c(`/sessions?id=${m}`),className:`text-[10px] text-accent-cyan hover:underline transition-colors duration-150`,children:`full session →`})]})]}),(0,x.jsxs)(`div`,{ref:D,className:`overflow-auto flex-1 p-2`,children:[!m&&(0,x.jsx)(`div`,{className:`text-ink-muted text-xs p-2`,children:`Select a session to view its timeline.`}),m&&O.length===0&&k.length===0&&(0,x.jsx)(W,{icon:`timeline`,title:h?`Waiting for tool calls`:`No tool calls`,subtitle:h?`Tool calls will appear here in real time.`:`This session has no recorded tool calls.`}),m&&(O.length>0||k.length>0)&&(0,x.jsx)(Ma,{sessionId:m,parentEntries:O,agents:k,window:A,runStatusById:j,parentSegments:_?.segments??[],onSelectRun:e=>a(e)},m)]}),h&&m&&(0,x.jsx)(`div`,{className:`border-t border-bg-line px-3 py-2 shrink-0`,children:(0,x.jsx)(xU,{sessionId:m,expandable:!1})}),((C?.totalBranches??0)>0||(S?.turns?.length??0)>0||(w?.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 C&&C.totalBranches>0&&e.push(`${C.longestFailureStreak} failure streak`),S?.turns&&S.turns.length>0&&e.push(`${S.turns.length} turns · ${Ei(S.totalAttributedCost)}`),e.length>0?`${e.join(` · `)} — session detail →`:`session detail →`})()})})]})]}),i!=null&&(0,x.jsx)(no,{runId:i,onClose:()=>a(null)}),o&&(0,x.jsx)(CU,{decisionTree:C,turnCosts:S,contextHistory:w?.history,contextWindow:w?.contextWindow,contextComposition:T,contextEfficiency:E,onClose:()=>s(!1)})]})}function GW(e,t){let n=t.find(t=>t.sessionId===e);return n?.sessionName?n.sessionName:e.slice(0,8)}var KW=e=>pW(e);function qW(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 mW({startTime:e.startTime,endTime:t})}function JW(e){let t=e.estimatedCostUsd;return t==null||t<=0?0:t*qW(e)}function YW(e){let t=0;for(let n of e)t+=JW(n);return t}function XW(e){let t=0;for(let n of e){let e=qW(n);e>0&&(t+=(n.antiPatterns?.length??0)*e)}return Math.round(t)}function ZW(e){let t=Array(24).fill(0),n=fW(),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 QW(e,t,n){let r=new Date(n).getHours(),i=Array(24),a=0;for(let t=0;t<24;t++)a+=e[t]?.cost??0,i[t]=a;let o=i[r]??0,s=t!=null&&Number.isFinite(t)&&t>o,c=s&&23>r?(t-o)/(23-r):0;return Array.from({length:24},(n,a)=>{let l=a<=r?i[a]:null,u=null;return s&&a>=r&&(u=a===23?t:o+c*(a-r)),{key:String(a),label:BW(a),spendUsd:e[a]?.cost??0,cumulativeUsd:l,projectedUsd:u}})}var $W=[`var(--color-heatmap-0)`,`var(--color-heatmap-1)`,`var(--color-heatmap-2)`,`var(--color-heatmap-3)`,`var(--color-heatmap-4)`];function eG(e,t){if(e===0)return $W[0];let n=e/t;return $W[Math.min(Math.ceil(n*4),4)]}function tG(e,t,n){let r=e+n*t;return new Date(r).toLocaleTimeString(void 0,{hour:`numeric`,minute:`2-digit`})}function nG({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)(aG,{days:c,maxCount:n,width:a,height:o,ariaLabel:s}):(0,x.jsx)(rG,{buckets:t,maxCount:n,bucketSizeMs:r,startTimestamp:i,width:a,height:o,ariaLabel:s})}function rG({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:eG(e,t),className:`heatmap-cell`,style:{animationDelay:`${Math.min(i*8,400)}ms`},onMouseEnter:t=>{let a=tG(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 iG=[`Mon`,``,`Wed`,``,`Fri`,``,`Sun`];function aG({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:[iG.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:eG(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`}),$W.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 oG(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 sG(e){return e<6e5?3e4:e<36e5?6e4:e<144e5?3e5:9e5}var cG=50,lG={thrashing:`Edit/Test Thrashing`,stuck_loop:`Stuck Loop`,blind_editing:`Blind Editing`,re_reading:`Repeated Reads`,over_delegation:`Over-Delegation`},uG={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`}},dG=[{value:`today`,label:`Today`},{value:`7d`,label:`7 days`},{value:`30d`,label:`30 days`},{value:`all`,label:`All`}],fG=[{value:`all`,label:`All sources`},{value:`script`,label:`Script`},{value:`agent_tool`,label:`Agent tool`}],pG=[{value:`all`,label:`All`},{value:`running`,label:`Running`},{value:`completed`,label:`Completed`},{value:`failed`,label:`Failed`},{value:`cancelled`,label:`Cancelled`}];function mG(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 hG(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 gG(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 _G(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 vG(e){return typeof e.startTime==`number`?e.startTime:new Date(e.startTime??0).getTime()}function yG(e){return vG(e)+(e.durationMs??0)}function bG(e,t){let n=[...e];switch(t){case`date`:n.sort((e,t)=>vG(t)-vG(e));break;case`lastActive`:n.sort((e,t)=>yG(t)-yG(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 xG(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function SG(){let e=Gt(),[t,n]=(0,b.useState)(()=>hG(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)(()=>hG(e),[e]);(0,b.useEffect)(()=>{_&&n(_)},[_]);let[v,y]=(0,b.useState)(()=>gG(window.location.search)),S=(0,b.useMemo)(()=>gG(e),[e]);(0,b.useEffect)(()=>{S&&y(S)},[S]);let[C,w]=(0,b.useState)(()=>_G(window.location.search)),T=(0,b.useMemo)(()=>_G(e),[e]);(0,b.useEffect)(()=>{T&&w(T)},[T]);let E=L({queryKey:z.sessionsList(cG),queryFn:({signal:e})=>nr(cG,e),refetchInterval:1e4}),{data:D}=L({queryKey:z.workflows,queryFn:({signal:e})=>Hr(e),refetchInterval:1e4}),O=L({queryKey:z.sessionCurrent,queryFn:({signal:e})=>tr(e),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:({signal:e})=>ar(t,e),enabled:t!==null,refetchInterval:O.isLoading||t&&k.has(t)?1e4:!1}),j=(0,b.useMemo)(()=>bG(E.data??[],r),[E.data,r]),M=(0,b.useMemo)(()=>Array.isArray(D)?D:[],[D]),N=(0,b.useMemo)(()=>M.filter(e=>!(!mG(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=>mG(vG(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)},I=(0,b.useCallback)(e=>{m(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),oe=(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)(TU,{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)(U,{label:`Workflow runs`,value:String(ee.totalRuns),numericValue:ee.totalRuns,animate:!0})}),(0,x.jsx)(`div`,{className:`px-3`,children:(0,x.jsx)(U,{label:`Subagents`,value:String(ee.totalAgents),numericValue:ee.totalAgents,animate:!0})}),(0,x.jsx)(`div`,{className:`px-3`,children:(0,x.jsx)(U,{label:`Workflow spend`,value:Di(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)(U,{label:`Avg duration`,value:ee.avgDurationMs===null?`—`:Ci(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)(di,{value:a,onChange:o,options:dG,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:fG.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:pG.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`,` `,cG,` 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)(W,{variant:`loading`,icon:`timeline`,title:`Loading sessions`}),!E.isLoading&&ne.length===0&&k.size===0&&(0,x.jsx)(W,{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)(CG,{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:I,onToggleRun:oe,onOpenRun:se},e.sessionId)),j.length>=cG&&(0,x.jsxs)(`div`,{className:`p-2 text-[10px] text-ink-muted text-center border-t border-border-subtle`,children:[`Only the `,cG,` 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)(W,{icon:`timeline`,title:`Loading sessions`,subtitle:`Selecting the most recent session…`}),t&&A.isLoading&&(0,x.jsx)(W,{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)(W,{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)(EG,{data:A.data,isLive:!!t&&k.has(t),onOpenRun:se})]})]}),d!=null&&(0,x.jsx)(no,{runId:d,onClose:()=>f(null)})]})}function CG({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)(ci,{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 ${bi(e.startTime)}`:void 0,children:e.startTime?bi(i===`lastActive`?yG(e):e.startTime):`—`}),(0,x.jsx)(`span`,{children:Di(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)(wG,{run:e,isExpanded:o.has(e.runId),onToggleRun:l,onOpenRun:u},e.runId))})]})}function wG({run:e,isExpanded:t,onToggleRun:n,onOpenRun:r}){let{data:i}=L({queryKey:z.workflowDetail(e.runId),queryFn:({signal:t})=>Ur(e.runId,t),enabled:t}),a=(0,b.useMemo)(()=>i?.agents??[],[i]),o=uG[e.status]??uG.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:Di(e.totalUsd)}),(0,x.jsx)(oi,{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:xG(t.tokens)})]},t.agentId))})]})}function TG(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 EG({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:Ci(e.durationMs),s=e.timeline??[],c=s.length>0?s[0].timestamp:0,l=Object.entries(e.modelBreakdown??{}).map(([e,t])=>({model:e,...t})).sort((e,t)=>t.totalCostUsd-e.totalCostUsd),u=e.tokensInput!=null&&e.tokensCacheRead!=null&&e.tokensCacheCreation!=null&&e.tokensInput+e.tokensCacheRead+e.tokensCacheCreation>0&&e.tokensCacheRead+e.tokensCacheCreation>0?Math.round(e.tokensCacheRead/(e.tokensInput+e.tokensCacheRead+e.tokensCacheCreation)*100):null;return s.length===0&&i.length===0?(0,x.jsx)(W,{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)(ci,{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`})}),(e.linesAdded!=null||e.linesRemoved!=null||e.attribution?.apiDurationMs!=null||u!=null)&&(0,x.jsxs)(`div`,{className:`text-[11px] text-ink-muted mt-2 flex flex-wrap gap-2`,children:[(e.linesAdded!=null||e.linesRemoved!=null)&&(0,x.jsxs)(`span`,{children:[e.linesAdded!=null&&`+${e.linesAdded}`,e.linesAdded!=null&&e.linesRemoved!=null&&` / `,e.linesRemoved!=null&&`−${e.linesRemoved}`,` lines`]}),e.attribution?.apiDurationMs!=null&&(0,x.jsxs)(`span`,{children:[`API `,Ci(e.attribution.apiDurationMs),` · wall`,` `,Ci(e.durationMs??0)]}),u!=null&&(0,x.jsxs)(`span`,{children:[`cache `,u,`%`]})]})]})}),l.length>0?(0,x.jsxs)(`div`,{className:`mb-4`,children:[(0,x.jsx)(V,{className:`mb-2`,children:`Usage by model`}),(0,x.jsx)(`div`,{className:`max-h-48 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:`Input`}),(0,x.jsx)(`th`,{className:`text-right pb-1`,children:`Output`}),(0,x.jsx)(`th`,{className:`text-right pb-1`,children:`Cache read`}),(0,x.jsx)(`th`,{className:`text-right pb-1`,children:`Cache write`}),(0,x.jsx)(`th`,{className:`text-right pb-1`,children:`Cost`})]})}),(0,x.jsx)(`tbody`,{children:l.map(e=>(0,x.jsxs)(`tr`,{className:`border-t border-bg-line`,children:[(0,x.jsx)(`td`,{className:`py-1 font-mono text-[11px] truncate`,title:e.model,children:e.model}),(0,x.jsx)(`td`,{className:`py-1 text-right tabular-nums`,children:Oi(e.totalInputTokens)}),(0,x.jsx)(`td`,{className:`py-1 text-right tabular-nums`,children:Oi(e.totalOutputTokens)}),(0,x.jsx)(`td`,{className:`py-1 text-right tabular-nums`,children:Oi(e.totalCacheReadTokens)}),(0,x.jsx)(`td`,{className:`py-1 text-right tabular-nums`,children:Oi(e.totalCacheCreationTokens)}),(0,x.jsx)(`td`,{className:`py-1 text-right tabular-nums`,children:Ei(e.totalCostUsd)})]},e.model))})]})})]}):e.model?(0,x.jsxs)(`div`,{className:`mb-4 bg-surface-3 rounded-lg p-2.5 text-xs`,children:[(0,x.jsx)(V,{children:`Model`}),(0,x.jsx)(`div`,{className:`font-mono`,children:e.model})]}):null,(0,x.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 mb-4 text-xs`,children:[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:Ei(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)(oi,{tone:`warning`,size:`sm`,bordered:!0,children:[lG[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:vi(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:vi(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 ${yi(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)(xU,{sessionId:e.sessionId})}),i.length>0&&(0,x.jsx)(OG,{breakdownEntries:i,totalCalls:a,isLive:t,sessionId:e.sessionId},`tools-${e.sessionId}`),(0,x.jsx)(AG,{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)(DG,{sessionId:e.sessionId,isLive:t,parentEntries:s,onOpenRun:n},e.sessionId)]})}function DG({sessionId:e,isLive:t,parentEntries:n,onOpenRun:r}){let{data:i,isLoading:a,isError:o}=L({queryKey:z.sessionSubagents(e),queryFn:({signal:t})=>Sr(e,t),retry:!1,refetchInterval:t?1e4:!1}),{data:s}=L({queryKey:z.workflows,queryFn:({signal:e})=>Hr(e),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)(W,{variant:`loading`,icon:`radar`,title:`Loading subagents`}):o||i===void 0?(0,x.jsx)(Ma,{sessionId:e,parentEntries:d,agents:[],window:u??{startMs:0,endMs:1},onSelectRun:r,runStatusById:c}):(0,x.jsx)(Ma,{sessionId:e,parentEntries:d,agents:l,window:u??i.window,onSelectRun:r,runStatusById:c})})]})}function OG({breakdownEntries:e,totalCalls:t,isLive:n,sessionId:r}){let[i,a]=(0,b.useState)(`calls`),{data:o}=L({queryKey:[`context`,r],queryFn:({signal:e})=>jr(r,e),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)(di,{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:Ai(e)}),(0,x.jsx)(`div`,{className:`flex-1 h-3 bg-surface-3 relative rounded`,children:(0,x.jsx)(`div`,{className:`h-3 rounded ${TG(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:Ai(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:[`~`,kG(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 kG(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function AG({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=sG(r),a=oG(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)(nG,{variant:`strip`,buckets:t.buckets,maxCount:t.maxCount,bucketSizeMs:t.bucketSizeMs,startTimestamp:t.startMs,ariaLabel:`Session activity density`})]}):null}var jG=`bg-accent-cyan`;function MG({rows:e,max:t=8,emptyText:n=`No data yet`}){if(e.length===0)return(0,x.jsx)(`div`,{className:`text-[11px] text-ink-muted`,children:n});let r=e.slice(0,t),i=e.length-r.length,a=Math.max(...r.map(e=>e.share),0);return(0,x.jsxs)(`div`,{children:[(0,x.jsxs)(`table`,{className:`sr-only`,children:[(0,x.jsx)(`caption`,{children:`Ranked breakdown`}),(0,x.jsx)(`thead`,{children:(0,x.jsxs)(`tr`,{children:[(0,x.jsx)(`th`,{children:`Label`}),(0,x.jsx)(`th`,{children:`Value`}),(0,x.jsx)(`th`,{children:`Share`})]})}),(0,x.jsx)(`tbody`,{children:r.map(e=>(0,x.jsxs)(`tr`,{children:[(0,x.jsx)(`td`,{children:e.label}),(0,x.jsx)(`td`,{children:e.value}),(0,x.jsx)(`td`,{children:H(e.share)})]},e.key))})]}),(0,x.jsx)(`div`,{className:`space-y-0.5`,"aria-hidden":`true`,children:r.map(e=>{let t=a>0?e.share/a*100:0;return(0,x.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_5rem_auto_2.5rem] items-center gap-2 text-[11px]`,children:[(0,x.jsx)(`span`,{className:`truncate text-ink-subtle`,children:e.label}),(0,x.jsx)(`span`,{className:`h-1 rounded-full bg-surface-5`,children:(0,x.jsx)(`span`,{className:`block h-1 rounded-full ${e.tone??jG}`,style:{width:`${t}%`}})}),(0,x.jsx)(`span`,{className:`text-right text-ink-base tabular-nums`,children:e.value}),(0,x.jsx)(`span`,{className:`text-right text-ink-muted tabular-nums`,children:H(e.share)})]},e.key)})}),i>0&&(0,x.jsxs)(`div`,{className:`mt-1.5 text-[10px] italic text-ink-muted`,children:[`+`,i,` more not shown`]})]})}var NG={fill:`var(--color-ink-muted)`,fontSize:10},PG=`var(--color-border-subtle)`,FG={background:`var(--color-bg-elevated)`,border:`1px solid var(--color-border-medium)`,borderRadius:8,fontSize:12,color:`var(--color-ink-base)`},IG=`var(--color-accent-green)`,LG=`var(--color-accent-amber)`;function RG(e){return`Last ${e} days`}var zG=`Compares session outcomes before and after your most recent edit to an instruction file (CLAUDE.md, or the active platform's equivalent) — efficiency, cost, and correction rate. The pill shows whether the most recent edit measured as an improvement.`,BG={improved:`success`,degraded:`danger`,neutral:`neutral`,insufficient_data:`neutral`};function VG(e){return e.startsWith(`Positive`)?`text-accent-green`:e.startsWith(`Negative`)?`text-accent-red`:`text-accent-amber`}function HG(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 UG(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 WG({impact:e,impactError:t,drift:n}){if(t)return(0,x.jsx)($r,{title:`Instruction file`,tooltip:zG,children:(0,x.jsx)(W,{icon:`radar`,title:`Instruction file impact unavailable`})});if(!e)return(0,x.jsx)($r,{title:`Instruction file`,tooltip:zG,children:(0,x.jsx)(W,{variant:`loading`,title:`Loading instruction file impact…`})});let r=n?.recentCorrelations[n.recentCorrelations.length-1],i=r?(0,x.jsx)(oi,{tone:BG[r.verdict],children:r.verdict}):void 0;if(e.message||!e.change||!e.before||!e.after||!e.deltas||!e.verdict)return r?(0,x.jsx)($r,{title:`Instruction file`,tooltip:zG,action:i,children:(0,x.jsx)(W,{variant:`inline`,title:`No instruction file impact tracked yet.`})}):(0,x.jsx)($r,{title:`Instruction file`,tooltip:zG,children:(0,x.jsx)(W,{variant:`inline`,title:`No instruction file changes tracked yet.`})});let a=new Date(e.change.timestamp).toLocaleDateString(void 0,{month:`short`,day:`numeric`}),o=e.before.avgEfficiencyScore===null?null:Math.round(e.before.avgEfficiencyScore*100),s=e.after.avgEfficiencyScore===null?null:Math.round(e.after.avgEfficiencyScore*100);return(0,x.jsxs)($r,{title:`Instruction file`,tooltip:zG,action:i,children:[(0,x.jsxs)(`div`,{className:`text-xs mb-3`,children:[(0,x.jsx)(`span`,{className:`font-medium ${VG(e.verdict)}`,children:e.verdict}),(0,x.jsxs)(`span`,{className:`text-[10px] text-ink-muted`,children:[` · `,e.change.changeType,` `,e.change.filePath.split(`/`).pop(),` · `,a]})]}),(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:o??`—`}),(0,x.jsx)(`span`,{className:`font-mono`,children:s??`—`}),(0,x.jsx)(`span`,{className:e.deltas.efficiencyScore==null?`text-ink-muted`:e.deltas.efficiencyScore.improved?`text-accent-green`:`text-accent-amber`,children:HG(e.deltas.efficiencyScore)}),(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`Cost/session`}),(0,x.jsx)(`span`,{className:`font-mono`,children:Ei(e.before.avgCostUsd)}),(0,x.jsx)(`span`,{className:`font-mono`,children:Ei(e.after.avgCostUsd)}),(0,x.jsx)(`span`,{className:e.deltas.cost.improved?`text-accent-green`:`text-accent-amber`,children:UG(e.deltas.cost)}),(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`Correction rate`}),(0,x.jsx)(`span`,{className:`font-mono`,children:H(e.before.avgCorrectionRate*100)}),(0,x.jsx)(`span`,{className:`font-mono`,children:H(e.after.avgCorrectionRate*100)}),(0,x.jsx)(`span`,{className:e.deltas.correctionRate.improved?`text-accent-green`:`text-accent-amber`,children:UG(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 GG(){let[e,t]=(0,b.useState)(`30`),n=Number(e),r=L({queryKey:z.weekly,queryFn:({signal:e})=>fr(e)}),i=L({queryKey:z.sessionsList(200),queryFn:({signal:e})=>nr(200,e)}),a=L({queryKey:z.costPerOutcome(n),queryFn:({signal:e})=>mr(n,e)}),o=L({queryKey:z.costPerTool(n),queryFn:({signal:e})=>Ir(void 0,n,e)}),s=L({queryKey:z.personalCoach,queryFn:({signal:e})=>gr(e)}),c=L({queryKey:z.recommendations,queryFn:({signal:e})=>_r(e),retry:!1}),l=L({queryKey:z.claudeMdImpact,queryFn:({signal:e})=>vr(e),retry:!1}),u=L({queryKey:z.collaborationProfile,queryFn:({signal:e})=>yr(e),retry:!1}),d=L({queryKey:z.activityHeatmap(`history`),queryFn:({signal:e})=>Ar(`history`,12,e)}),f=L({queryKey:z.concurrencyHistory(n),queryFn:({signal:e})=>kr(n,e)}),p=L({queryKey:z.instructionDrift,queryFn:({signal:e})=>Wr(e)}),m=L({queryKey:z.usageInsights(n),queryFn:({signal:e})=>hr(n,e)}),h=L({queryKey:z.sessionsTodayAggregate,queryFn:({signal:e})=>rr(e),refetchInterval:1e4}),g=r.isError||i.isError||a.isError||f.isError,_=[...r.data??[]].reverse(),v=_.map(e=>{let t=e.avgEfficiencyScore;return{week:e.week||`?`,efficiency:t===null?null:Math.round(t*100)}}),y=i.data??[],S=rK(y,n),C=oK(eK(y,n),n),w=y.length>=200&&tK(y,n),T=w?nK(y):null,E=h.data?.forecastEndOfDayUsd??null,D=h.data?.totalCostUsd??0,O=y.map(e=>({startTime:typeof e.startTime==`string`?new Date(e.startTime).getTime():e.startTime,estimatedCostUsd:e.estimatedCostUsd})),k=E==null?null:_W(O,E,D,Date.now()),A=E==null?null:bW(O,E,D,Date.now()),j=[k==null?null:`~${Ei(k)} this week`,A==null?null:`~${Ei(A)} this month`].filter(e=>e!=null).join(` · `)||null,M=aK(a.data),N=a.data?.totalCost??M.reduce((e,t)=>e+t.totalCost,0),ee=sK(_),te=dK(S),P=te.reduce((e,t)=>e+t.totalCost,0),F=JU(S,o.data?.costByToolType),ne=o.data?.costByToolType!==void 0,{attributedSessionCount:re,totalSessionCount:ie}=o.data??{},ae=re!==void 0&&ie!==void 0&&re<ie?`Cost/token breakdown only available for ${re} of ${ie} sessions in this window — older sessions predate per-tool attribution.`:null,I=iK(S);return(0,x.jsxs)(`section`,{children:[(0,x.jsx)(TU,{theme:`history`}),(0,x.jsxs)(`div`,{className:`flex items-center justify-between gap-2 mb-4`,children:[(0,x.jsx)(`h1`,{className:`text-xl font-semibold gradient-text`,children:`History`}),(0,x.jsx)(di,{value:e,onChange:t,options:[{value:`7`,label:`7d`},{value:`30`,label:`30d`},{value:`90`,label:`90d`}],ariaLabel:`History window`})]}),g&&(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)(B,{padding:`lg`,tone:`elevated`,glow:`green`,className:`mb-4`,children:[(0,x.jsxs)(`div`,{className:`grid grid-cols-5 gap-4`,children:[(0,x.jsx)(U,{label:`spend`,value:Ei(I.spendUsd),animate:!0,numericValue:I.spendUsd,format:Ei}),(0,x.jsx)(U,{label:`sessions`,value:String(I.sessionCount),animate:!0,numericValue:I.sessionCount}),(0,x.jsx)(U,{label:`avg efficiency`,value:I.avgEfficiency===null?`—`:H(I.avgEfficiency*100),...I.avgEfficiency===null?{}:{animate:!0,numericValue:Math.round(I.avgEfficiency*100),suffix:`%`}}),(0,x.jsx)(U,{label:`avg cost / session`,value:Di(I.avgCostPerSession)}),(0,x.jsx)(U,{label:`flags`,tone:I.flags>0?`warn`:`neutral`,value:String(I.flags),animate:!0,numericValue:I.flags})]}),(0,x.jsxs)(`div`,{className:`text-[10px] text-ink-muted mt-3`,children:[I.sessionCount,` sessions`,T!==null&&` · oldest ${T} days shown`]})]}),(0,x.jsxs)($r,{title:`Daily spend`,subtitle:RG(n),className:`mb-3`,children:[(0,x.jsx)(`div`,{className:`h-44 min-w-0`,children:(0,x.jsx)(HU,{data:C.map(e=>({key:e.day,label:e.day,spendUsd:e.cost,cumulativeUsd:null,projectedUsd:null})),xTickFormatter:Ni,tooltipLabel:e=>Ni(e.key)})}),j&&(0,x.jsxs)(`p`,{className:`mt-1.5 text-[10px] text-ink-muted`,children:[`On pace for `,j]}),w&&(0,x.jsxs)(`div`,{className:`text-[10px] text-ink-muted italic mt-1`,children:[`Sample doesn't reach back `,n,` days — early days in this chart may undercount actual spend.`]})]}),(0,x.jsx)(`div`,{className:`mt-3`,children:(0,x.jsx)(ZU,{data:m.data,isError:m.isError,title:`What's contributing to your spend`,subtitle:RG(n),toolRows:F,toolCostAvailable:ne,toolCoverageCaveat:ae})}),(0,x.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 mt-3`,children:[(0,x.jsx)($r,{title:`Model performance`,subtitle:RG(n),footnote:te.some(e=>e.flagged)?`▲ Highlighted models had sessions with elevated error rates`:void 0,children:te.length===0?(0,x.jsx)(W,{icon:`radar`,title:`No model data yet`,subtitle:`Complete a few sessions to see model performance.`}):(0,x.jsx)(GU,{title:`Model performance`,hideTitle:!0,rows:te,rowKey:e=>e.model,defaultSort:{column:5,direction:`desc`},columns:[{header:`Model`,align:`left`,className:`font-medium`,cell:e=>e.model},{header:`Sessions`,align:`right`,cell:e=>e.sessions,sortValue:e=>e.sessions},{header:`Eff.`,align:`right`,cell:e=>e.avgEfficiency===null?`—`:H(Math.min(100,e.avgEfficiency*100)),sortValue:e=>e.avgEfficiency??-1},{header:`Success`,align:`right`,className:e=>e.flagged?`text-accent-amber`:void 0,cell:e=>(0,x.jsxs)(x.Fragment,{children:[e.flagged&&`▲ `,e.avgSuccessRate===null?`—`:H(Math.min(100,e.avgSuccessRate*100))]}),sortValue:e=>e.avgSuccessRate??-1},{header:`Avg $`,align:`right`,cell:e=>Di(e.avgCost),sortValue:e=>e.avgCost??-1},{header:`Share`,align:`right`,cell:e=>{let t=cK(e,P);return t===null?`—`:H(t)},sortValue:e=>cK(e,P)??-1},{header:`$/1M tok`,align:`right`,className:`text-ink-subtle`,cell:e=>Di(e.costPerMillionTokens),sortValue:e=>e.costPerMillionTokens??-1}]})}),(0,x.jsx)($r,{title:`Cost per outcome`,subtitle:RG(n),children:M.length===0?(0,x.jsx)(W,{icon:`radar`,title:`No outcomes yet`}):(0,x.jsx)(GU,{title:`Outcomes`,hideTitle:!0,rows:M,rowKey:e=>e.outcome,defaultSort:{column:3,direction:`desc`},columns:[{header:`Outcome`,align:`left`,cell:e=>e.outcome},{header:`Sessions`,align:`right`,cell:e=>e.count,sortValue:e=>e.count},{header:`Cost`,align:`right`,cell:e=>Ei(e.totalCost),sortValue:e=>e.totalCost},{header:`Share`,align:`right`,cell:e=>H(N>0?e.totalCost/N*100:0),sortValue:e=>N>0?e.totalCost/N*100:0}]})})]}),(0,x.jsxs)(`div`,{className:`grid grid-cols-3 gap-3 mt-3`,children:[(0,x.jsx)($r,{title:`Weekly efficiency`,subtitle:`Last 12 weeks`,children:(0,x.jsx)(`div`,{className:`h-44 min-w-0`,children:(0,x.jsx)(fm,{width:`100%`,height:`100%`,minWidth:1,minHeight:1,children:(0,x.jsxs)(sU,{data:v,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:IG,stopOpacity:.3}),(0,x.jsx)(`stop`,{offset:`100%`,stopColor:IG,stopOpacity:0})]})}),(0,x.jsx)(EL,{stroke:PG,strokeDasharray:`3 3`}),(0,x.jsx)($B,{dataKey:`week`,tick:NG,stroke:PG,tickFormatter:Pi}),(0,x.jsx)(mV,{tick:NG,stroke:PG,domain:[0,100],unit:`%`}),(0,x.jsx)(oj,{contentStyle:FG}),(0,x.jsx)(Cz,{type:`monotone`,dataKey:`efficiency`,stroke:IG,strokeWidth:2,fill:`url(#effGradient)`,dot:{r:2,fill:IG}})]})})})}),(0,x.jsx)($r,{title:`Anti-pattern frequency`,subtitle:`Last 12 weeks`,children:ee.length===0||ee.every(e=>e.count===0)?(0,x.jsx)(W,{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)(fm,{width:`100%`,height:`100%`,minWidth:1,minHeight:1,children:(0,x.jsxs)(aU,{data:ee,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:LG,stopOpacity:.9}),(0,x.jsx)(`stop`,{offset:`100%`,stopColor:LG,stopOpacity:.4})]})}),(0,x.jsx)(EL,{stroke:PG,strokeDasharray:`3 3`}),(0,x.jsx)($B,{dataKey:`week`,tick:NG,stroke:PG,tickFormatter:Pi}),(0,x.jsx)(mV,{tick:NG,stroke:PG}),(0,x.jsx)(oj,{contentStyle:FG}),(0,x.jsx)(MB,{dataKey:`count`,fill:`url(#antiPatternGradient)`,radius:[3,3,0,0]})]})})})}),(0,x.jsx)(QG,{data:d.data})]}),(0,x.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 mt-3`,children:[(0,x.jsx)(ZG,{data:s.data}),(0,x.jsx)(YG,{data:c.data,isError:c.isError})]}),(0,x.jsx)(`div`,{className:`mt-3`,children:(0,x.jsx)(WG,{impact:l.data,impactError:l.isError,drift:p.data})}),(0,x.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 mt-3`,children:[(0,x.jsx)(XG,{data:u.data,isError:u.isError}),(0,x.jsx)($G,{data:f.data,windowNum:n})]})]})}function KG({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.jsx)(`span`,{className:`font-mono`,children:Ei(e.avgCostPerSession)}),(0,x.jsx)(`span`,{className:s(r),children:u(r)}),(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`Anti-pattern rate`}),(0,x.jsx)(`span`,{className:`font-mono`,children:H(e.antiPatternRate*100)}),(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 qG(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 JG(e){return e===`high`?`var(--color-accent-amber)`:e===`medium`?`var(--color-accent-blue)`:`var(--color-ink-muted)`}function YG({data:e,isError:t}){if(t)return(0,x.jsx)($r,{title:`Recommendations`,children:(0,x.jsx)(W,{icon:`radar`,title:`Recommendations unavailable`,subtitle:`Connect a full Preflight session to enable recommendations.`})});if(!e)return(0,x.jsx)($r,{title:`Recommendations`,children:(0,x.jsx)(W,{variant:`loading`,title:`Loading recommendations…`})});if(e.recommendations.length===0)return(0,x.jsx)($r,{title:`Recommendations`,children:(0,x.jsx)(W,{variant:`inline`,title:`No recommendations yet`,subtitle:`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)($r,{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:qG(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:JG(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 XG({data:e,isError:t}){if(t)return(0,x.jsx)($r,{title:`Collaboration profile`,children:(0,x.jsx)(W,{icon:`radar`,title:`Collaboration profile unavailable`})});if(!e)return(0,x.jsx)($r,{title:`Collaboration profile`,children:(0,x.jsx)(W,{variant:`loading`,title:`Loading collaboration profile…`})});if(e.sessionCount===0)return(0,x.jsx)($r,{title:`Collaboration profile`,children:(0,x.jsx)(W,{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:``}],r=n.map(e=>({key:e.key,label:e.name,value:H(e.value),share:e.value}));return(0,x.jsxs)($r,{title:`Collaboration profile`,subtitle:e.developerCount<=1?`No team data yet`:void 0,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`]})]}),(0,x.jsx)(MG,{rows:r,max:4}),e.developerCount>1&&(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 ZG({data:e}){return e?e.status===`insufficient_data`?(0,x.jsx)($r,{title:`Personal coach`,children:(0,x.jsx)(`div`,{className:`text-ink-muted text-xs`,children:e.message})}):(0,x.jsx)($r,{title:`Personal coach`,children:(0,x.jsxs)(`div`,{className:`text-xs space-y-2`,children:[(0,x.jsx)(KG,{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)($r,{title:`Personal coach`,children:(0,x.jsx)(W,{variant:`loading`,title:`Loading coaching insights…`})})}function QG({data:e}){return(0,x.jsx)($r,{title:`Activity heatmap`,subtitle:`Last 12 weeks`,children:e?e.days.length===0?(0,x.jsx)(W,{variant:`inline`,title:`No activity yet`}):(0,x.jsx)(nG,{variant:`grid`,buckets:[],maxCount:e.maxCount,days:e.days,ariaLabel:`Daily activity heatmap for the last 12 weeks`}):(0,x.jsx)(W,{variant:`loading`,title:`Loading activity…`})})}function $G({data:e,windowNum:t}){let n=e?.dailyPeaks??[],r=n.some(e=>e.peak>0);return(0,x.jsx)($r,{title:`Peak concurrent sessions`,subtitle:RG(t),children:e?r?(0,x.jsxs)(`div`,{className:`flex flex-col items-center gap-2`,children:[(0,x.jsx)(`div`,{className:`text-2xl font-bold tabular-nums gradient-text`,children:Math.max(...n.map(e=>e.peak))}),(0,x.jsx)(fK,{data:n})]}):(0,x.jsx)(W,{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.jsx)(W,{variant:`loading`,title:`Loading concurrency…`})})}function eK(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 tK(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 nK(e,t=new Date){let n=null;for(let t of e){if(t.startTime==null)continue;let e=new Date(t.startTime).getTime();Number.isNaN(e)||(n===null||e<n)&&(n=e)}if(n===null)return 0;let r=t.getTime()-n;return Math.max(1,Math.ceil(r/864e5))}function rK(e,t,n=new Date){let r=new Date(n);r.setDate(r.getDate()-(t-1)),r.setHours(0,0,0,0);let i=r.getTime();return e.filter(e=>{if(e.startTime==null)return!1;let t=new Date(e.startTime).getTime();return Number.isFinite(t)&&t>=i})}function iK(e){let t=0,n=0,r=0,i=0;for(let a of e)a.estimatedCostUsd!=null&&(t+=a.estimatedCostUsd),a.efficiencyScore!=null&&(n+=a.efficiencyScore,r++),i+=a.antiPatterns?.length??0;return{spendUsd:t,sessionCount:e.length,avgEfficiency:r>0?n/r:null,avgCostPerSession:e.length>0?t/e.length:null,flags:i}}function aK(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 oK(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 sK(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}function cK(e,t){return t<=0||e.costedSessions===0?null:e.totalCost/t*100}var lK=.85,uK=.3;function dK(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<lK&&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,totalCost:r.costSum,costedSessions:r.costCount,costPerMillionTokens:r.blendedTokensSum>0?r.blendedCostSum/r.blendedTokensSum*1e6:null,flagged:r.successCount>0&&r.lowSuccessSessions/r.successCount>uK});return n.sort((e,t)=>t.sessions-e.sessions)}function fK({data:e}){let t=e.map(e=>({count:e.peak,tooltip:`${e.date.slice(5)}: ${e.peak}`}));return(0,x.jsx)(da,{data:t,ariaLabel:`Peak concurrent sessions over ${e.length} days`})}var pK=[{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`}],mK={critical:`danger`,high:`warning`,medium:`info`},hK={sensitive_file:`Sensitive files`,destructive_command:`Destructive`,external_network:`External network`,file_deletion:`File deletion`,other:`Other`};function gK(e){let t=e.map(e=>JSON.stringify(e)).join(`
|
|
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 _K(){let[e,t]=(0,b.useState)(`all`),{data:n,isLoading:r,error:i,refetch:a}=L({queryKey:z.audit,queryFn:({signal:e})=>dr(e),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)(TU,{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)(ni,{variant:`secondary`,size:`md`,onClick:()=>gK(c),children:[`Export JSONL (max `,200,` rows)`]})]}),(0,x.jsx)(`div`,{className:`flex gap-2 mb-3 flex-wrap`,children:pK.map(({key:n,label:r})=>(0,x.jsx)(ni,{variant:e===n?`primary`:`secondary`,size:`sm`,onClick:()=>t(n),children:r},n))}),r&&(0,x.jsx)(W,{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)(oi,{tone:e.severity?mK[e.severity]??`neutral`:`neutral`,size:`sm`,children:hK[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 vK(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 yK={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`},bK={info:`info`,warning:`warning`,critical:`danger`},xK={resolved:`text-accent-green`,aborted:`text-accent-red`,pending:`text-accent-amber`},SK={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 CK(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 wK(e){return e.replace(/_/g,` `)}function TK(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 EK(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 DK(e,t){let n=e=>new Date(e).toLocaleDateString(void 0,{month:`short`,day:`numeric`});return`${n(e)} – ${n(t-1)}`}function OK(e){return e===null?`neutral`:e>20?`bad`:e>5?`warn`:`good`}function kK(e,t){return e===0?`—`:t>0?`${e} (${t} merged)`:String(e)}function AK({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 jK(e){return e.length===1?`/sessions?session=${encodeURIComponent(e[0])}`:`/sessions?sessionIds=${e.map(encodeURIComponent).join(`,`)}`}function MK(e,t){return e===null&&t===null?0:e===null?1:t===null?-1:t-e}function NK(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)=>MK(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)=>MK(e.lastActivityMs,t.lastActivityMs))}function PK({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)(W,{icon:`code`,title:`No git activity in this window`});let s=NK(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)(`th`,{className:`text-left p-2`,children:`PRs`})]})}),(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:6,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(jK(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:`—`})}),(0,x.jsx)(`td`,{className:`p-2 tabular-nums`,children:kK(e.rows.reduce((e,t)=>e+t.metrics.prMetrics.created,0),e.rows.reduce((e,t)=>e+t.metrics.prMetrics.merged,0))})]}),!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(jK(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:`—`})}),(0,x.jsx)(`td`,{className:`p-2 tabular-nums`,children:kK(e.metrics.prMetrics.created,e.metrics.prMetrics.merged)})]},e.identity.worktreeKey)})]},e.repoKey)})})]})})}function FK(){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`,Er(t)),queryFn:({signal:e})=>Dr(`week`,Er(t),e),refetchInterval:5e3}),{data:c}=L({queryKey:z.gitEfficiency(`previous_week`,Er(t)),queryFn:({signal:e})=>Dr(`previous_week`,Er(t),e),refetchInterval:6e4}),{data:l}=L({queryKey:z.gitEfficiency(`30`,`all`),queryFn:({signal:e})=>Dr(`30`,`all`,e),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)(W,{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)(W,{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)(TU,{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)(AK,{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)(AK,{score:m.efficiencyScore})]})]})]}),(0,x.jsx)(oa,{index:0,className:`mb-3`,children:(0,x.jsxs)(B,{padding:`md`,children:[(0,x.jsx)(fi,{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 (${DK(l.since,l.until)})`:`Loading…`}),l?(0,x.jsx)(PK,{rows:l.rows,scope:t,onSelectRepo:u,onSelectWorktree:d}):(0,x.jsx)(W,{icon:`clock`,variant:`loading`,title:`Loading...`})]})}),m.totalGitCommands===0?(0,x.jsx)(W,{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)(oa,{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 (`,DK(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)(U,{label:`commits`,hero:!0,value:String(m.commitCount),sub:vK(m.commitCount,g)??void 0,animate:!0,numericValue:m.commitCount}),(0,x.jsx)(U,{label:`PRs created`,tone:m.prMetrics.created>0?`good`:`neutral`,value:String(m.prMetrics.created),sub:vK(m.prMetrics.created,_)??void 0,animate:!0,numericValue:m.prMetrics.created}),(0,x.jsx)(U,{label:`conflicts`,tone:y>0?`bad`:`good`,value:String(y),sub:[y===0?`clean session`:`${h} resolved`,vK(y,v)].filter(e=>e!==null).join(` · `),animate:!0,numericValue:y}),a.scope.kind===`worktree`?(0,x.jsx)(U,{label:`behind ${m.liveState?.defaultBranch??`upstream`}`,tone:OK(m.liveState?.behind??null),value:m.liveState?.behind==null?`—`:String(m.liveState.behind),sub:m.liveState?.measuredAtMs==null?void 0:EK(m.liveState.measuredAtMs),animate:!0,numericValue:m.liveState?.behind??null}):(0,x.jsx)(U,{label:`worst behind`,tone:OK(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)(oa,{index:2,className:`mb-3`,children:(0,x.jsxs)(B,{padding:`md`,children:[(0,x.jsx)(fi,{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)(U,{label:`Avg time between commits`,value:CK(m.velocityMetrics.avgTimeBetweenCommitsMs)}),(0,x.jsx)(U,{label:`Longest gap`,value:CK(m.velocityMetrics.longestGapMs),sub:`biggest idle stretch between commits`}),(0,x.jsx)(U,{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)(U,{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)(oa,{index:3,className:`mb-3`,children:(0,x.jsxs)(B,{padding:`md`,children:[(0,x.jsx)(fi,{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)(U,{label:`PRs created`,value:String(m.prMetrics.created),tone:m.prMetrics.created>0?`good`:`neutral`}),(0,x.jsx)(U,{label:`PRs merged`,value:String(m.prMetrics.merged),tone:m.prMetrics.merged>0?`good`:`neutral`}),(0,x.jsx)(U,{label:`CI checks viewed`,value:String(m.prMetrics.checksViewed),sub:"times you ran `gh pr checks`"}),(0,x.jsx)(U,{label:`Time to PR`,value:CK(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)(oi,{tone:t,size:`sm`,children:[e.action,e.prNumber?` #${e.prNumber}`:``]},`${e.timestamp}-${e.action}`)})})]})]})}),(m.mergeConflicts>0||m.rebaseConflicts>0)&&(0,x.jsx)(oa,{index:4,className:`mb-3`,children:(0,x.jsxs)(B,{padding:`md`,children:[(0,x.jsx)(fi,{title:`Conflict Resolution`}),(0,x.jsxs)(`div`,{className:`grid grid-cols-2 sm:grid-cols-4 gap-3`,children:[(0,x.jsx)(U,{label:`Resolution rate`,value:m.conflictResolutionRate===null?`—`:`${Math.round(m.conflictResolutionRate*100)}%`}),(0,x.jsx)(U,{label:`Avg resolution time`,value:CK(m.avgConflictResolutionMs)}),(0,x.jsx)(U,{label:`Aborted ops`,value:String(m.abortedOperations)}),(0,x.jsx)(U,{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 ${xK[e.resolution]}`,children:e.resolution}),(0,x.jsx)(`span`,{className:`text-ink-muted`,children:CK(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)(oa,{index:5,className:`mb-3`,children:(0,x.jsxs)(B,{padding:`md`,children:[(0,x.jsx)(fi,{title:`Conflict Resolution Strategy`}),(0,x.jsxs)(`div`,{className:`grid grid-cols-2 sm:grid-cols-4 gap-3`,children:[(0,x.jsx)(U,{label:`Accept ours`,value:String(m.conflictResolutionStrategy.oursCount)}),(0,x.jsx)(U,{label:`Accept theirs`,value:String(m.conflictResolutionStrategy.theirsCount)}),(0,x.jsx)(U,{label:`Manual merge`,value:String(m.conflictResolutionStrategy.manualMergeCount)}),(0,x.jsx)(U,{label:`Cherry-picks`,value:String(m.conflictResolutionStrategy.cherryPickCount)})]})]})}),(m.resetHards>0||m.discardedChanges>0||m.forcePushes>0)&&(0,x.jsx)(oa,{index:6,className:`mb-3`,children:(0,x.jsxs)(B,{padding:`md`,children:[(0,x.jsx)(fi,{title:`Destructive Operations`}),(0,x.jsxs)(`div`,{className:`grid grid-cols-3 gap-3`,children:[(0,x.jsx)(U,{label:`Hard resets`,value:String(m.resetHards)}),(0,x.jsx)(U,{label:`Discarded changes`,value:String(m.discardedChanges)}),(0,x.jsx)(U,{label:`Force pushes`,value:String(m.forcePushes)})]})]})}),m.bestPractices.length>0&&(0,x.jsx)(oa,{index:7,className:`mb-3`,children:(0,x.jsxs)(B,{padding:`md`,children:[(0,x.jsx)(fi,{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)(oi,{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)(oi,{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)(oa,{index:8,className:`mb-3`,children:(0,x.jsxs)(B,{padding:`md`,children:[(0,x.jsx)(fi,{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 ${yK[e.severity]}`,children:(0,x.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,x.jsx)(oi,{tone:bK[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)(oa,{index:9,children:(0,x.jsxs)(B,{padding:`md`,children:[(0,x.jsx)(fi,{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:TK(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 ${SK[e.type]??`bg-surface-8 text-ink-subtle`}`,children:wK(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:CK(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 IK({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 LK({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 RK={ok:`●`,warn:`▲`,fail:`✗`,skip:`–`},zK={ok:`text-accent-green`,warn:`text-accent-amber`,fail:`text-accent-red`,skip:`text-ink-muted`};function BK(){let{data:e,isLoading:t,isError:n,refetch:r}=L({queryKey:z.diagnostics,queryFn:({signal:e})=>Rr(e),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)(fi,{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)(W,{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 ${zK[e.status]??`text-ink-muted`}`,children:RK[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 VK(){let e=C(),{data:t,isLoading:n,error:r}=L({queryKey:z.settings,queryFn:({signal:e})=>Lr(e)}),{data:i}=L({queryKey:[`observability-health`],queryFn:({signal:e})=>Vr(e),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=>zr(e),onSuccess:()=>{e.invalidateQueries({queryKey:z.settings}),S(null)},onError:e=>{S(String(e))}});if(n)return(0,x.jsx)(W,{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)(BK,{}),(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)(fi,{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)(IK,{label:`Account ID`,value:t.accountId}),(0,x.jsx)(IK,{label:`App name`,value:t.appName}),(0,x.jsx)(IK,{label:`Mode`,value:t.mode}),(0,x.jsx)(IK,{label:`Storage path`,value:t.storagePath}),(0,x.jsx)(IK,{label:`High security`,value:t.highSecurity?`enabled`:`disabled`}),(0,x.jsx)(IK,{label:`License key`,value:t.licenseKey}),(0,x.jsx)(`div`,{className:`mt-3 flex items-center gap-3`,children:(0,x.jsx)(ni,{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)(fi,{title:`Cost & Retention`,subtitle:`Budget caps trigger warnings at 50%, 80%, and 100%. Leave blank for no limit.`}),(0,x.jsx)(LK,{label:`Session budget (USD)`,value:D,onChange:u,min:.01}),(0,x.jsx)(LK,{label:`Daily budget (USD)`,value:O,onChange:f,min:.01}),(0,x.jsx)(LK,{label:`Weekly budget (USD)`,value:k,onChange:m,min:.01}),(0,x.jsx)(LK,{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)(ni,{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 HK({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 UK({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)(HK,{pct:t.pctUsed,exceeded:t.exceeded}),(0,x.jsxs)(`span`,{className:`text-xs tabular-nums text-ink-base`,children:[Ei(t.spentUsd),t.budgetUsd===null?``:` / ${Ei(t.budgetUsd)}`,t.pctUsed===null?``:` (${t.pctUsed.toFixed(0)}%)`]}),t.exceeded&&(0,x.jsx)(oi,{tone:`danger`,size:`sm`,children:`exceeded`})]})}function WK(){let e=C(),t=L({queryKey:z.budget,queryFn:({signal:e})=>pr(e),refetchInterval:1e4}),n=L({queryKey:z.settings,queryFn:({signal:e})=>Lr(e)}),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=>zr(e),onSuccess:()=>void e.invalidateQueries({queryKey:z.settings})}),g=st({mutationFn:()=>Br(),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)(fi,{title:`Budget Status`}),t.isLoading&&(0,x.jsx)(W,{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)(UK,{label:`session`,p:r.session}),(0,x.jsx)(UK,{label:`daily`,p:r.daily}),(0,x.jsx)(UK,{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:[Ei(e.spentUsd),` / `,Ei(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)(fi,{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)(W,{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)(ni,{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)(fi,{title:`Slack Digest`,subtitle:`Weekly digest sent to a Slack incoming webhook. URL changes take effect immediately.`}),n.isLoading&&(0,x.jsx)(W,{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)(oi,{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)(ni,{variant:`primary`,size:`md`,onClick:v,disabled:h.isPending,loading:h.isPending,children:h.isPending?`Saving…`:`Save`}),i.digestWebhookUrl&&(0,x.jsx)(ni,{variant:`danger`,size:`md`,onClick:()=>h.mutate({digestWebhookUrl:null},{onSuccess:()=>u(void 0)}),disabled:h.isPending,children:`Unsubscribe`}),(0,x.jsx)(ni,{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 GK(){Zi();let e=qn(e=>e.connected),[t,n]=Wt(),[r,i]=(0,b.useState)(!1),{theme:a,toggleTheme:o}=na(),s=(0,b.useCallback)(()=>i(e=>!e),[]),c=(0,b.useCallback)(()=>i(!1),[]);return Qi({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)(Wi,{}),(0,x.jsxs)(`div`,{className:`flex flex-1 min-h-0`,children:[(0,x.jsx)(_i,{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)(Gi,{resetKey:t,children:(0,x.jsxs)($t,{children:[(0,x.jsx)(Xt,{path:`/sessions`,component:SG}),(0,x.jsx)(Xt,{path:`/history`,component:GG}),(0,x.jsx)(Xt,{path:`/audit`,component:_K}),(0,x.jsx)(Xt,{path:`/git`,component:FK}),(0,x.jsx)(Xt,{path:`/settings`,component:VK}),(0,x.jsx)(Xt,{path:`/alerts`,component:WK}),(0,x.jsx)(Xt,{path:`/`,component:DW}),(0,x.jsx)(Xt,{children:(0,x.jsx)(`div`,{className:`text-ink-muted`,children:`Not found`})})]})})})]})]}),(0,x.jsx)(qi,{open:r,onClose:c})]})}var KK=new Je({defaultOptions:{queries:{staleTime:5e3,retry:0,refetchOnWindowFocus:!1}}}),qK=document.getElementById(`root`);if(!qK)throw Error(`Mount node #root not found`);(0,ct.createRoot)(qK).render((0,x.jsx)(b.StrictMode,{children:(0,x.jsx)(w,{client:KK,children:(0,x.jsx)(GK,{})})}));
|
|
63
|
+
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function PH(e,t){if(e){if(typeof e==`string`)return FH(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)?FH(e,t):void 0}}function FH(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 IH(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 LH(e){if(Array.isArray(e))return e}var RH=()=>(UA(),null);function zH(e){if(typeof e==`number`)return e;if(typeof e==`string`){var t=parseFloat(e);if(!Number.isNaN(t))return t}return 0}var BH=(0,b.forwardRef)((e,t)=>{var n=(0,b.useRef)(null),r=MH((0,b.useState)({containerWidth:zH(e.style?.width),containerHeight:zH(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(Cm,{width:i.containerWidth,height:i.containerHeight}),b.createElement(`div`,jH({ref:s},e)))}),VH=(0,b.forwardRef)((e,t)=>{var n=e.width,r=e.height,i=MH((0,b.useState)({containerWidth:zH(n),containerHeight:zH(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(Cm,{width:a.containerWidth,height:a.containerHeight}),b.createElement(`div`,jH({ref:c},e)))}),HH=(0,b.forwardRef)((e,t)=>{var n=e.width,r=e.height;return b.createElement(b.Fragment,null,b.createElement(Cm,{width:n,height:r}),b.createElement(`div`,jH({ref:t},e)))}),UH=(0,b.forwardRef)((e,t)=>{var n=e.width,r=e.height;return typeof n==`string`||typeof r==`string`?b.createElement(VH,jH({},e,{ref:t})):typeof n==`number`&&typeof r==`number`?b.createElement(HH,jH({},e,{width:n,height:r,ref:t})):b.createElement(b.Fragment,null,b.createElement(Cm,{width:n,height:r}),b.createElement(`div`,jH({ref:t},e)))});function WH(e){return e?BH:UH}var GH=(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=Zc(),w=MH((0,b.useState)(null),2),T=w[0],E=w[1],D=MH((0,b.useState)(null),2),O=D[0],k=D[1],A=TH(),j=um(),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(vV(e)),C(BV({handler:a,reactEvent:e}))},[C,a]),P=(0,b.useCallback)(e=>{C(bV(e)),C(BV({handler:l,reactEvent:e}))},[C,l]),F=(0,b.useCallback)(e=>{C(QD()),C(BV({handler:u,reactEvent:e}))},[C,u]),ne=(0,b.useCallback)(e=>{C(bV(e)),C(BV({handler:d,reactEvent:e}))},[C,d]),re=(0,b.useCallback)(()=>{C(NV())},[C]),ie=(0,b.useCallback)(()=>{C(PV())},[C]),ae=(0,b.useCallback)(e=>{C(MV(e.key))},[C]),I=(0,b.useCallback)(e=>{C(BV({handler:o,reactEvent:e}))},[C,o]),oe=(0,b.useCallback)(e=>{C(BV({handler:s,reactEvent:e}))},[C,s]),se=(0,b.useCallback)(e=>{C(BV({handler:c,reactEvent:e}))},[C,c]),ce=(0,b.useCallback)(e=>{C(BV({handler:f,reactEvent:e}))},[C,f]),le=(0,b.useCallback)(e=>{C(BV({handler:h,reactEvent:e}))},[C,h]),ue=(0,b.useCallback)(e=>{x&&C(KV(e)),C(BV({handler:m,reactEvent:e}))},[C,x,m]),de=(0,b.useCallback)(e=>{C(BV({handler:p,reactEvent:e}))},[C,p]),fe=WH(v);return b.createElement(_A.Provider,{value:T},b.createElement(rs.Provider,{value:O},b.createElement(fe,{width:M??g?.width,height:N??g?.height,className:G(`recharts-wrapper`,r),style:DH({position:`relative`,cursor:`default`,width:M,height:N},g),onClick:te,onContextMenu:I,onDoubleClick:oe,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(RH,null),n)))}),KH=[`width`,`height`,`responsive`,`children`,`className`,`style`,`compact`,`title`,`desc`];function qH(e,t){if(e==null)return{};var n,r,i=JH(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 JH(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 YH=(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=co(qH(e,KH));return c?b.createElement(b.Fragment,null,b.createElement(Cm,{width:n,height:r}),b.createElement(vH,{otherAttributes:d,title:l,desc:u},a)):b.createElement(GH,{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(vH,{otherAttributes:d,title:l,desc:u,ref:t},b.createElement(UF,null,a)))});function XH(){return XH=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},XH.apply(null,arguments)}function ZH(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 QH(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?ZH(Object(n),!0).forEach(function(t){$H(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ZH(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function $H(e,t,n){return(t=eU(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function eU(e){var t=tU(e,`string`);return typeof t==`symbol`?t:t+``}function tU(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 nU=QH({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`},QV),rU=(0,b.forwardRef)(function(e,t){var n=fc(e.categoricalChartProps,nU),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(iH,{preloadedState:{options:c},reduxStoreName:s.id??r},b.createElement(wF,{chartData:s.data}),b.createElement(oH,{layout:n.layout,margin:n.margin}),b.createElement(cH,{throttleDelay:n.throttleDelay,throttledEvents:n.throttledEvents}),b.createElement(sH,{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(YH,XH({},n,{ref:t})))}),iU=[`axis`,`item`],aU=(0,b.forwardRef)((e,t)=>b.createElement(rU,{chartName:`BarChart`,defaultTooltipEventType:`axis`,validateTooltipEventTypes:iU,tooltipPayloadSearcher:CA,categoricalChartProps:e,ref:t})),oU=[`axis`],sU=(0,b.forwardRef)((e,t)=>b.createElement(rU,{chartName:`AreaChart`,defaultTooltipEventType:`axis`,validateTooltipEventTypes:oU,tooltipPayloadSearcher:CA,categoricalChartProps:e,ref:t})),cU=[`axis`],lU=(0,b.forwardRef)((e,t)=>b.createElement(rU,{chartName:`ComposedChart`,defaultTooltipEventType:`axis`,validateTooltipEventTypes:cU,tooltipPayloadSearcher:CA,categoricalChartProps:e,ref:t})),uU=[`system`,`tools`,`user`,`assistant`],dU={system:`bg-accent-indigo`,tools:`bg-accent-amber`,user:`bg-accent-blue`,assistant:`bg-accent-green`},fU={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)]`},pU={system:`bg-accent-indigo`,tools:`bg-accent-amber`,user:`bg-accent-blue`,assistant:`bg-accent-green`},mU={system:`System`,tools:`Tools`,user:`User`,assistant:`Assistant`},hU={system:`#6366f1`,tools:`#ffb224`,user:`#0095ff`,assistant:`#1ce783`},gU={fontSize:10,fill:`#6b7280`},_U=`#2a2a3a`;function vU({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)(fm,{width:`100%`,height:120,children:(0,x.jsxs)(sU,{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)(EL,{strokeDasharray:`3 3`,stroke:_U}),(0,x.jsx)($B,{dataKey:`turn`,tick:gU,stroke:_U}),(0,x.jsx)(mV,{domain:[0,100],unit:`%`,tick:gU,stroke:_U}),(0,x.jsx)(oj,{contentStyle:{backgroundColor:`#1a1a2e`,border:`1px solid #2a2a3a`,fontSize:11},formatter:(e,t)=>[`${e.toFixed(1)}%`,t],labelFormatter:e=>`Turn ${e}`}),(0,x.jsx)(rI,{y1:80,y2:100,fill:`url(#${n})`,ifOverflow:`visible`}),uU.map(e=>(0,x.jsx)(Cz,{type:`monotone`,dataKey:e,stackId:`context`,stroke:hU[e],fill:hU[e],fillOpacity:.4,strokeWidth:1,dot:!1},e))]})})})}function yU(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e)}function bU(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 xU({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:({signal:e})=>jr(t??void 0,e),refetchInterval:1e4,enabled:!e}),{data:m}=L({queryKey:[`context-composition`,t],queryFn:({signal:e})=>Mr(e),enabled:l}),{data:h}=L({queryKey:[`context-efficiency`,t],queryFn:({signal:e})=>Nr(e),enabled:l}),g=e??p,_=t??``,v=e?bU(e,_):i??(g?bU(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)(oi,{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:[yU(T.currentTokens),k&&k>0&&(0,x.jsx)(`span`,{className:`text-ink-muted`,children:` / ${yU(k)}`}),T.delta>0&&(0,x.jsxs)(`span`,{className:`text-accent-amber ml-1`,children:[`+`,yU(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:uU.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:`${dU[e]} transition-all duration-500 ease-out cursor-default relative ${r?`brightness-125 ${fU[e]}`:``}`,style:{width:`${t/D*S}%`},title:`${mU[e]}: ${yU(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:[uU.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 ${pU[e]} ${n?`scale-150`:``} transition-transform duration-200`}),mU[e],n&&t>0&&(0,x.jsx)(`span`,{className:`text-ink-subtle ml-0.5`,children:yU(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)(vU,{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 SU={success:`success`,failure:`danger`,unknown:`neutral`};function CU({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,Zr.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)(wU,{label:`Longest failure streak`,value:String(e.longestFailureStreak)}),(0,x.jsx)(wU,{label:`Success rate`,value:e.successRate===null?`—`:`${Math.round(e.successRate*100)}%`}),(0,x.jsx)(wU,{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)(oi,{tone:SU[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)(wU,{label:`Total attributed cost`,value:`$${t.totalAttributedCost.toFixed(2)}`}),(0,x.jsx)(wU,{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,` · `,Oi(e.inputTokens),` in /`,` `,Oi(e.outputTokens),` out /`,` `,Oi(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)(vU,{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 wU({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})]})}function TU({theme:e=`observatory`}){return(0,x.jsxs)(`div`,{className:`geo-banner`,"aria-hidden":`true`,children:[e===`observatory`&&(0,x.jsx)(EU,{}),e===`sessions`&&(0,x.jsx)(DU,{}),e===`history`&&(0,x.jsx)(OU,{}),e===`audit`&&(0,x.jsx)(kU,{}),e===`git`&&(0,x.jsx)(AU,{})]})}function EU(){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 DU(){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 OU(){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 kU(){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 AU(){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`})]})}var jU={good:`Healthy`,warn:`Watch`,bad:`Needs attention`,neutral:`No data`},MU={good:`text-accent-green`,warn:`text-accent-amber`,bad:`text-accent-red`,neutral:`text-ink-base`},NU={good:`success`,warn:`warning`,bad:`danger`,neutral:`neutral`};function PU({title:e,tooltip:t,value:n,tone:r,detail:i,rows:a}){return(0,x.jsxs)($r,{title:e,tooltip:t,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,x.jsx)(`span`,{className:`text-2xl font-semibold ${MU[r??`neutral`]}`,children:n}),r&&(0,x.jsx)(oi,{tone:NU[r],children:jU[r]})]}),i&&(0,x.jsx)(`div`,{className:`mt-1 text-[10px] text-ink-muted`,children:i}),a&&a.length>0&&(0,x.jsx)(`div`,{className:`mt-3 space-y-1`,children:a.slice(0,4).map(e=>(0,x.jsxs)(`div`,{className:`flex items-center justify-between text-[11px]`,children:[(0,x.jsx)(`span`,{className:`text-ink-muted`,children:e.label}),(0,x.jsx)(`span`,{className:`text-ink-base tabular-nums`,children:e.value})]},e.label))})]})}var FU=176,IU={fill:`var(--color-ink-muted)`,fontSize:10},LU=`var(--color-border-subtle)`,RU={background:`var(--color-bg-elevated)`,border:`1px solid var(--color-border-medium)`,borderRadius:8,fontSize:12,color:`var(--color-ink-base)`},zU=`var(--color-chart-block)`,BU=`var(--color-accent-green)`;function VU({active:e,payload:t,tooltipLabel:n}){if(!e||!t||t.length===0)return null;let r=t[0].payload,i=n?n(r):r.label,a=[`${i} — ${Ei(r.spendUsd)}`];return r.cumulativeUsd!=null&&a.push(`${i} — cumulative ${Ei(r.cumulativeUsd)}`),r.projectedUsd!=null&&a.push(`${i} — projected ${Ei(r.projectedUsd)}`),(0,x.jsx)(`div`,{style:RU,className:`px-2 py-1.5`,children:a.map(e=>(0,x.jsx)(`div`,{children:e},e))})}function HU({data:e,height:t=FU,xTickFormatter:n,yTickFormatter:r=Fi,tooltipLabel:i}){let a=e.some(e=>e.cumulativeUsd!=null),o=e.some(e=>e.projectedUsd!=null);return(0,x.jsx)(`div`,{className:`min-w-0`,style:{height:t},children:(0,x.jsx)(fm,{width:`100%`,height:`100%`,minWidth:1,minHeight:1,children:(0,x.jsxs)(lU,{data:e,children:[(0,x.jsx)(EL,{stroke:LU,strokeDasharray:`3 3`}),(0,x.jsx)($B,{dataKey:`key`,tick:IU,stroke:LU,tickFormatter:n,interval:`preserveStartEnd`,minTickGap:20}),(0,x.jsx)(mV,{tick:IU,stroke:LU,tickFormatter:r}),(0,x.jsx)(oj,{content:e=>(0,x.jsx)(VU,{...e,tooltipLabel:i}),cursor:!1}),(0,x.jsx)(MB,{dataKey:`spendUsd`,fill:zU,radius:[3,3,0,0],isAnimationActive:!1}),a&&(0,x.jsx)(AR,{type:`monotone`,dataKey:`cumulativeUsd`,isAnimationActive:!1,stroke:BU,strokeWidth:2,dot:!1}),o&&(0,x.jsx)(AR,{type:`monotone`,dataKey:`projectedUsd`,isAnimationActive:!1,stroke:BU,strokeWidth:2,strokeDasharray:`4 3`,dot:!1})]})})})}function UU({direction:e}){return e===null?(0,x.jsx)(fn,{className:`w-3 h-3 opacity-30`,"aria-hidden":`true`}):e===`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`})}function WU(e,t){return typeof e==`string`||typeof t==`string`?String(e).localeCompare(String(t)):e-t}function GU({title:e,columns:t,rows:n,rowKey:r,className:i,defaultSort:a,hideTitle:o,totalCount:s}){let c=s!==void 0&&s>n.length?`top ${n.length} of ${s}`:null,[l,u]=(0,b.useState)(a??null);function d(e){u(t=>t&&t.column===e?{column:e,direction:t.direction===`desc`?`asc`:`desc`}:{column:e,direction:`desc`})}let f=(l?t[l.column]:void 0)?.sortValue,p=l&&f?[...n].sort((e,t)=>{let n=WU(f(e),f(t));return l.direction===`asc`?n:-n}):n;return(0,x.jsxs)(`div`,{className:i?`text-xs ${i}`:`text-xs`,children:[!o&&(0,x.jsxs)(`h4`,{className:`text-ink-muted font-medium mb-2`,children:[e,c&&(0,x.jsx)(`span`,{className:`text-ink-subtle font-normal ml-1`,children:c})]}),o&&c&&(0,x.jsx)(`p`,{className:`text-ink-subtle mb-1`,children:c}),(0,x.jsx)(`div`,{className:`max-h-40 overflow-auto`,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.jsx)(`tr`,{children:t.map((e,t)=>{let n=e.align===`right`?`text-right pb-1`:`text-left pb-1`;if(!e.sortValue)return(0,x.jsx)(`th`,{className:n,children:e.header},e.header);let r=l?.column===t?l.direction:null;return(0,x.jsx)(`th`,{className:n,"aria-sort":r===`asc`?`ascending`:r===`desc`?`descending`:`none`,children:(0,x.jsxs)(`button`,{type:`button`,onClick:()=>d(t),className:`inline-flex items-center gap-1 hover:text-ink-subtle`,children:[e.header,(0,x.jsx)(UU,{direction:r})]})},e.header)})})}),(0,x.jsx)(`tbody`,{children:p.map(e=>(0,x.jsx)(`tr`,{className:`border-t border-bg-line`,children:t.map(t=>{let n=t.align===`right`?`py-1 text-right tabular-nums`:`py-1 text-ink-base`,r=typeof t.className==`function`?t.className(e):t.className;return(0,x.jsx)(`td`,{className:r?`${n} ${r}`:n,title:t.title?.(e),children:t.cell(e)},t.header)})},r(e)))})]})})]})}function KU({insights:e,emptyText:t=`Nothing stands out in this window.`}){return e.length===0?(0,x.jsx)(`p`,{className:`text-xs text-ink-muted`,children:t}):(0,x.jsx)(`div`,{className:`mb-4 space-y-2`,children:e.map(e=>(0,x.jsxs)(`div`,{className:`text-xs`,children:[(0,x.jsx)(`p`,{className:`text-ink-base font-medium`,children:e.headline}),(0,x.jsx)(`p`,{className:`text-ink-muted`,children:e.advice})]},e.id))})}function qU(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 JU(e,t){let n=qU(e),r=n.reduce((e,t)=>e+t.count,0),i=t?n.reduce((e,n)=>e+(t[n.tool]?.totalCost??0),0):0;return n.map(e=>{let n=t?.[e.tool],a=i>0?(n?.totalCost??0)/i*100:r>0?e.count/r*100:0;return{tool:Ai(e.tool),count:e.count,sharePct:a,costUsd:n?.totalCost,tokens:n?.tokens}})}function YU(e){return H(e.costUsd!==void 0&&e.costUsd>0&&e.sharePct===0?.1:e.sharePct)}function XU(e){return e.breakdown?ki(e.breakdown):void 0}function ZU({data:e,isError:t,title:n,subtitle:r,modelRows:i,toolRows:a,toolCostAvailable:o=!1,toolCoverageCaveat:s=null}){if(t)return(0,x.jsx)($r,{title:n,subtitle:r,children:(0,x.jsx)(W,{icon:`radar`,title:`Usage insights unavailable`})});if(!e)return(0,x.jsx)($r,{title:n,subtitle:r,children:(0,x.jsx)(W,{variant:`loading`,title:`Loading usage insights…`})});let c=e.insights??[],l=e.skills??[],u=e.subagents??[],d=e.plugins??[],f=e.loops??[];return(0,x.jsxs)($r,{title:n,subtitle:r,children:[(0,x.jsx)(`p`,{className:`text-xs text-ink-muted mb-3`,children:`Approximate, based on sessions recorded on this machine. These are independent characteristics of your spend, not a breakdown.`}),e.sessionCount===0?(0,x.jsx)(W,{icon:`clock`,title:`No sessions in this window.`}):(0,x.jsx)(KU,{insights:c}),e.sessionCount>0&&(0,x.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-4 text-xs mt-4`,children:[i&&i.length>0&&(0,x.jsx)(GU,{title:`Models`,rows:i,rowKey:e=>e.model,defaultSort:{column:4,direction:`desc`},columns:[{header:`Model`,align:`left`,className:`font-mono truncate max-w-[12rem]`,title:e=>e.model,cell:e=>e.model},{header:`Req`,align:`right`,cell:e=>e.requestCount,sortValue:e=>e.requestCount},{header:`$/1M tok`,align:`right`,cell:e=>Di(e.costPerMillionTokens),sortValue:e=>e.costPerMillionTokens??0},{header:`Cost`,align:`right`,cell:e=>Ei(e.totalCostUsd),sortValue:e=>e.totalCostUsd},{header:`Share`,align:`right`,cell:e=>H(e.sharePct),sortValue:e=>e.sharePct}]}),l.length>0&&(0,x.jsx)(GU,{title:`Skills`,rows:l,totalCount:e.skillsTotalCount,rowKey:e=>e.key,defaultSort:{column:4,direction:`desc`},columns:[{header:`Skill`,align:`left`,cell:e=>e.key},{header:`Calls`,align:`right`,cell:e=>e.count,sortValue:e=>e.count},{header:`Tokens`,align:`right`,cell:e=>Oi(e.tokens),sortValue:e=>e.tokens,title:XU},{header:`Cost`,align:`right`,cell:e=>Di(e.costUsd),sortValue:e=>e.costUsd,title:XU},{header:`% of spend`,align:`right`,cell:e=>YU(e),sortValue:e=>e.sharePct}]}),u.length>0&&(0,x.jsx)(GU,{title:`Subagents`,rows:u,totalCount:e.subagentsTotalCount,rowKey:e=>e.key,defaultSort:{column:4,direction:`desc`},columns:[{header:`Type`,align:`left`,cell:e=>e.key},{header:`Requests`,align:`right`,cell:e=>e.count,sortValue:e=>e.count},{header:`Tokens`,align:`right`,cell:e=>Oi(e.tokens),sortValue:e=>e.tokens,title:XU},{header:`Cost`,align:`right`,cell:e=>Di(e.costUsd),sortValue:e=>e.costUsd,title:XU},{header:`% of spend`,align:`right`,cell:e=>YU(e),sortValue:e=>e.sharePct}]}),d.length>0&&(0,x.jsx)(GU,{title:`Plugins`,rows:d,totalCount:e.pluginsTotalCount,rowKey:e=>e.key,defaultSort:{column:4,direction:`desc`},columns:[{header:`Plugin`,align:`left`,cell:e=>e.key},{header:`Calls`,align:`right`,cell:e=>e.count,sortValue:e=>e.count},{header:`Tokens`,align:`right`,cell:e=>Oi(e.tokens),sortValue:e=>e.tokens,title:XU},{header:`Cost`,align:`right`,cell:e=>Di(e.costUsd),sortValue:e=>e.costUsd,title:XU},{header:`% of spend`,align:`right`,cell:e=>YU(e),sortValue:e=>e.sharePct}]}),f.length>0&&(0,x.jsx)(GU,{title:`Loops`,className:`md:col-span-2`,rows:f,totalCount:e.loopsTotalCount,rowKey:e=>e.sessionId,defaultSort:{column:4,direction:`desc`},columns:[{header:`Session`,align:`left`,className:`truncate`,title:e=>e.sessionName||e.sessionId,cell:e=>(0,x.jsx)(Zt,{href:`/sessions?sessionIds=${encodeURIComponent(e.sessionId)}`,className:`text-accent-cyan hover:underline transition-colors duration-150`,children:e.sessionName||e.sessionId.slice(0,8)})},{header:`Runs`,align:`right`,cell:e=>e.runs,sortValue:e=>e.runs},{header:`Tokens`,align:`right`,cell:e=>Oi(e.tokens),sortValue:e=>e.tokens},{header:`Per run`,align:`right`,cell:e=>Oi(e.tokensPerRun),sortValue:e=>e.tokensPerRun},{header:`Cost`,align:`right`,cell:e=>Di(e.costUsd),sortValue:e=>e.costUsd},{header:`Last run`,align:`right`,className:`text-ink-muted`,cell:e=>wi(e.lastRunMs),sortValue:e=>e.lastRunMs}]}),a.length>0&&(0,x.jsx)(GU,{title:`Tools`,rows:a,rowKey:e=>e.tool,defaultSort:{column:o?4:2,direction:`desc`},columns:[{header:`Tool`,align:`left`,cell:e=>e.tool},{header:`Calls`,align:`right`,cell:e=>e.count,sortValue:e=>e.count},...o?[{header:`Cost`,align:`right`,cell:e=>Di(e.costUsd),sortValue:e=>e.costUsd??0},{header:`Tokens`,align:`right`,cell:e=>e.tokens===void 0?`—`:Oi(e.tokens),sortValue:e=>e.tokens??0}]:[],{header:o?`% of spend`:`Share of calls`,align:`right`,cell:e=>o?YU(e):H(e.sharePct),sortValue:e=>e.sharePct}]})]}),e.attributionRatePct!==null&&e.attributionRatePct<50&&(0,x.jsxs)(`p`,{className:`text-[10px] text-ink-muted italic mt-3`,children:[`Skill and tool shares are based on `,Math.round(e.attributionRatePct),`% of spend with attribution.`]}),s&&(0,x.jsx)(`p`,{className:`text-[10px] text-ink-muted italic mt-3`,children:s})]})}var QU={over_delegation:`Over-delegation`,re_reading:`Repeated reads`,stuck_loop:`Stuck loop`,blind_editing:`Blind editing`,thrashing:`Edit/test thrashing`,anti_pattern_flags:`Anti-pattern flags`},$U={re_reading:`Read a file once and keep it in context. Use /compact when the window fills instead of re-reading.`,blind_editing:`Read the file before editing it, and verify each edit before the next.`,thrashing:`Verify changes with a test between edits instead of alternating edit and test blindly.`,stuck_loop:`The same command keeps failing. Read the error and change the approach before retrying.`,over_delegation:`Spawn subagents only for work that needs its own context, and use a cheaper model for simple ones.`,anti_pattern_flags:`Detail lives in each session record. Open a session to see where the flags landed.`},eW=3;function tW(e){let t=QU[e];if(t)return t;let n=e.replace(/_/g,` `);return n.charAt(0).toUpperCase()+n.slice(1)}function nW(e){return e.split(`/`).pop()||e}function rW({rows:e,firingCount:t,alertsHref:n}){return e.length===0&&t===0?(0,x.jsx)(W,{variant:`inline`,title:`Nothing needs attention.`}):(0,x.jsxs)(`div`,{children:[t>0&&(0,x.jsxs)(`a`,{href:n,className:`text-[11px] text-accent-red hover:underline`,children:[t,` firing`]}),e.length>0&&(0,x.jsx)(`ul`,{className:`divide-y divide-border-subtle`,children:e.map(e=>{let t=e.targets.slice(0,eW).map(nW),n=e.targets.length-t.length,r=$U[e.type];return(0,x.jsxs)(`li`,{className:`py-1.5 first:pt-0 last:pb-0`,children:[(0,x.jsxs)(`div`,{className:`text-xs font-medium text-ink-base`,children:[tW(e.type),` ×`,e.count]}),t.length>0&&(0,x.jsxs)(`div`,{className:`text-[11px] font-mono text-ink-muted truncate`,children:[t.join(` · `),n>0?` +${n} more`:``]}),(r||e.sessionIds.length>0)&&(0,x.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[r&&(0,x.jsx)(`div`,{className:`text-[11px] text-ink-muted`,children:r}),e.sessionIds.length>0&&(0,x.jsx)(`a`,{href:`/sessions?sessionIds=${e.sessionIds.join(`,`)}`,className:`shrink-0 text-[11px] text-accent-cyan hover:underline`,children:`View sessions →`})]})]},e.type)})})]})}function iW(e){return new Intl.DateTimeFormat(`en-US`,{timeZone:e}).resolvedOptions().timeZone}var aW=new Map;function oW(e){let t=iW(e),n=aW.get(t);return n||(n=new Intl.DateTimeFormat(`en-US`,{timeZone:t,year:`numeric`,month:`2-digit`,day:`2-digit`}),aW.set(t,n)),n}var sW=new Map;function cW(e){let t=iW(e),n=sW.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}),sW.set(t,n)),n}function lW(e,t){let n=oW(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 uW(e,t){let n=cW(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 dW(e,t,n,r){let i=Date.UTC(e,t-1,n),a=uW(i,r),o=i-a,s=uW(o,r);if(s===a)return o;let c=i-s,l=lW(c,r);return l.year===e&&l.month===t&&l.day===n?c:o}function fW(e,t){if(t){let{year:n,month:r,day:i}=lW(e??Date.now(),t);return dW(n,r,i,t)}let n=e==null?new Date:new Date(e);return n.setHours(0,0,0,0),n.getTime()}function pW(e,t,n){if(n){let r=lW(e,n),i=lW(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 mW(e,t){let n=fW(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 hW=864e5;function gW(e){let t=fW(e),n=new Date(t).getDay();return t-(n===0?6:n-1)*hW}function _W(e,t,n,r){let i=Math.max(t,n),a=fW(r),o=gW(r),s=0;for(let t of e)t.startTime==null||t.estimatedCostUsd==null||t.estimatedCostUsd<=0||t.startTime<o||t.startTime>=a||(s+=t.estimatedCostUsd);let c=Math.round((a-o)/hW)+1,l=new Date(a).getDay(),u=l===0?0:7-l,d=(s+i)/Math.max(1,c),f=s+i+d*u;return Math.max(f,i)}function vW(e){let t=new Date(e);return new Date(t.getFullYear(),t.getMonth(),1).getTime()}function yW(e){let t=new Date(e);return new Date(t.getFullYear(),t.getMonth()+1,0).getDate()}function bW(e,t,n,r){let i=Math.max(t,n),a=fW(r),o=vW(r),s=0;for(let t of e)t.startTime==null||t.estimatedCostUsd==null||t.estimatedCostUsd<=0||t.startTime<o||t.startTime>=a||(s+=t.estimatedCostUsd);let c=Math.round((a-o)/hW)+1,l=new Date(a).getDate(),u=Math.max(0,yW(r)-l),d=(s+i)/Math.max(1,c),f=s+i+d*u;return Math.max(f,i)}var xW={weekday:`short`,month:`short`,day:`numeric`,hour:`numeric`,minute:`2-digit`},SW=3e4,CW={info:`text-ink-muted`,warning:`text-accent-amber`,critical:`text-accent-red`};function wW(e){return e.count??e.iterations??e.readCount??e.repeatCount??e.editCount??e.agentCount??0}function TW(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 EW=1e4;function DW(){let e=qn(e=>e.cost),t=qn(e=>e.antiPatterns),n=Zn(),{data:r}=L({queryKey:[`observability-health`],queryFn:({signal:e})=>Vr(e),refetchInterval:3e4}),{data:i,isPending:a}=L({queryKey:z.cost,queryFn:({signal:e})=>or(e),refetchInterval:1e4}),{data:o,isPending:s}=L({queryKey:z.sessionsTodayAggregate,queryFn:({signal:e})=>rr(e),refetchInterval:1e4}),{data:c,isPending:l}=L({queryKey:z.sessionsList(200),queryFn:({signal:e})=>nr(200,e),refetchInterval:1e4}),{data:u,isPending:d}=L({queryKey:z.antiPatterns,queryFn:({signal:e})=>sr(e)}),{data:f,isPending:p}=L({queryKey:z.concurrency,queryFn:({signal:e})=>Or(e),refetchInterval:1e4}),{data:m,isPending:h}=L({queryKey:z.activityHeatmap(`today`),queryFn:({signal:e})=>Ar(`today`,void 0,e),refetchInterval:3e4}),{data:g,isPending:_}=L({queryKey:z.sessionsLive,queryFn:({signal:e})=>ir(e),refetchInterval:1e4}),v=(0,b.useMemo)(()=>QW(c??[]),[c]),y=(0,b.useMemo)(()=>$W(c??[]),[c]),S=(0,b.useMemo)(()=>eG(c??[]),[c]),C=(0,b.useMemo)(()=>(c??[]).filter(e=>XW(e)>0).flatMap(e=>(e.antiPatterns??[]).map(t=>({...t,sessionId:e.sessionId}))),[c]),w=(a||l||s)&&!e&&v===0&&o===void 0,T=Math.max(e?.todayTotalUsd??0,o?.totalCostUsd??0,v,i?.sessionTodayUsd??0),E=Math.max(u?.length??0,t.length),D=Math.max(o?.antiPatternCount??0,y+E),O=w?null:o?.forecastEndOfDayUsd??e?.forecastEodUsd??i?.forecast?.forecastEndOfDayUsd??null,k=Math.max(o?.subagentUsd??0,n.usd);(o!==void 0||n.turns>0)&&T>0&&`${H(k/T*100)}`;let A=r?.watcherActive===!1&&k===0,j=o&&o.totalCostUsd>=T?o.totalCostUsd:T,M=O===null?null:_W(c??[],O,j,Date.now()),[N,ee]=(0,b.useState)(()=>new Date().toLocaleString(void 0,xW)),te=(0,b.useRef)(Date.now());(0,b.useEffect)(()=>{let e=setInterval(()=>{let e=Date.now();ee(new Date(e).toLocaleString(void 0,xW)),pW(e,te.current)||(te.current=e,qn.getState().handleDayRollover())},6e4);return()=>clearInterval(e)},[]);let P=o?.avgEfficiencyScore??null,F=P!==null&&Number.isFinite(P)?H(P*100):`—`,ne=P===null?`needs more data`:Math.round(P*100)>=80?`strong session`:Math.round(P*100)>=50?`mixed signals`:`needs attention`,re=!w&&!s&&!l&&!d&&!p&&!h&&!_&&(o?.sessionCount??0)===0&&T===0&&D===0;return(0,x.jsxs)(`section`,{children:[(0,x.jsx)(TU,{}),(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:N})]}),re?(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(oa,{index:0,className:`glass-card p-8 mb-4`,children:(0,x.jsx)(W,{icon:`code`,title:`No activity yet today`,subtitle:`Metrics will appear here once you start a coding session with Claude.`})}),(0,x.jsx)(oa,{index:1,className:`mb-3`,children:(0,x.jsx)(NW,{todaySessions:c??[]})}),(0,x.jsx)(oa,{index:2,children:(0,x.jsx)(MW,{antiPatterns:t,apiAntiPatterns:u,persistedAntiPatterns:C,flagsCount:D})})]}):(0,x.jsxs)(x.Fragment,{children:[(0,x.jsxs)(oa,{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)(U,{label:`efficiency`,hero:!0,value:F,sub:ne,...P===null?{}:{animate:!0,numericValue:Math.round(P*100),suffix:`%`}}),(0,x.jsx)(U,{label:`spend today`,tone:`good`,value:w?`…`:Ei(T),sub:O!=null&&O>T?M==null?`→ ${Ei(O)} by end of day`:`→ ${Ei(O)} by end of day · ~${Ei(M)} by end of week`:void 0,...w?{}:{animate:!0,numericValue:T,format:Ei}}),(0,x.jsx)(U,{label:`avg cost / session`,value:Di(o&&o.sessionCount>0?T/o.sessionCount:null)}),(0,x.jsx)(U,{label:`sessions today`,value:o?String(o.sessionCount):`—`,sub:AW(o?.sessionStatus),...o?{animate:!0,numericValue:o.sessionCount}:{}}),(0,x.jsx)(U,{label:`flags`,tone:D>0?`warn`:`neutral`,value:String(D),animate:!0,numericValue:D})]})}),A&&(0,x.jsxs)(`div`,{className:`mt-2 text-[10px] text-ink-muted`,children:[`Subagent cost tracking is disabled (`,(0,x.jsx)(`code`,{className:`font-mono`,children:`NR_AI_ENABLE_SUBAGENT_WATCHER=0`}),`), so spend shown here excludes subagents. Unset it and restart to see full spend.`]})]}),(0,x.jsxs)(oa,{index:1,className:`grid grid-cols-3 gap-3 mb-3 items-start`,children:[(0,x.jsx)(`div`,{className:`col-span-2`,children:(0,x.jsx)(VW,{hourlySpend:S,forecastEod:O,weekForecast:M})}),(0,x.jsx)(GW,{todayHeatmap:m,concurrency:f})]}),(0,x.jsx)(oa,{index:2,className:`mb-3`,children:(0,x.jsx)(MW,{antiPatterns:t,apiAntiPatterns:u,persistedAntiPatterns:C,flagsCount:D})}),(0,x.jsx)(oa,{index:3,className:`mb-3`,children:(0,x.jsx)(NW,{todaySessions:c??[]})}),(0,x.jsx)(oa,{index:4,children:(0,x.jsx)(qW,{sessions:c??[],liveSessions:g??[]})}),(0,x.jsxs)(oa,{index:5,className:`grid grid-cols-3 gap-3 mb-3`,children:[(0,x.jsx)(FW,{aggregate:o}),(0,x.jsx)(IW,{}),(0,x.jsx)(LW,{}),(0,x.jsx)(RW,{liveSessions:g??[]}),(0,x.jsx)(zW,{aggregate:o}),(0,x.jsx)(BW,{})]})]})]})}var OW=[`needs_input`,`ready_for_review`,`working`];function kW(e,t){return e===`needs_input`?t===1?`needs input`:`need input`:e===`ready_for_review`?`ready for review`:`working`}function AW(e){if(!e)return;let t=OW.map(t=>({status:t,count:e.counts[t],sessionIds:e.sessionIds[t]})).filter(e=>e.count>0);if(t.length!==0)return(0,x.jsx)(x.Fragment,{children:t.map((e,t)=>(0,x.jsxs)(`span`,{children:[t>0?` · `:null,(0,x.jsxs)(Zt,{href:`/sessions?sessionIds=${e.sessionIds.map(encodeURIComponent).join(`,`)}`,className:`text-accent-cyan hover:underline`,children:[e.count,` `,kW(e.status,e.count)]})]},e.status))})}function jW(e){let t=new Map;for(let n of e){let e=t.get(n.type)??{count:0,targets:new Set,sessionIds:new Set};e.count+=n.count,n.target&&n.target!==`unknown`&&e.targets.add(n.target),n.sessionId&&e.sessionIds.add(n.sessionId),t.set(n.type,e)}return[...t.entries()].map(([e,{count:t,targets:n,sessionIds:r}])=>({type:e,count:t,targets:[...n],sessionIds:[...r]})).sort((e,t)=>t.count-e.count)}function MW({antiPatterns:e,apiAntiPatterns:t,persistedAntiPatterns:n,flagsCount:r}){let{data:i,error:a}=L({queryKey:z.alertsRecent,queryFn:async({signal:e})=>{try{return await br(e)}catch(e){if(e instanceof $n)return null;throw e}},refetchInterval:SW,retry:!1}),o=[...i??[]].sort((e,t)=>t.firedAt-e.firedAt),s=o.filter(e=>e.state===`firing`).length,c=jW(e.length>0?e.map(e=>({type:e.type,count:e.count,target:e.target})):t&&t.length>0?t.map(e=>({type:e.type,count:wW(e),target:e.file??e.command??`unknown`})):n.map(e=>({type:e.type,count:wW(e),target:e.file??e.command??`unknown`,sessionId:e.sessionId}))),l=c.length===0&&r>0?[{type:`anti_pattern_flags`,count:r,targets:[],sessionIds:[]}]:c;return(0,x.jsxs)($r,{title:`Needs attention`,children:[a&&(0,x.jsx)(`div`,{className:`text-accent-red text-[11px] mb-2`,children:`Error loading recent alerts.`}),(0,x.jsx)(rW,{rows:l,firingCount:s,alertsHref:`/alerts`}),o.length>0&&(0,x.jsxs)(`table`,{className:`w-full text-xs mt-3`,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:o.slice(0,5).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:wi(e.firedAt)}),(0,x.jsxs)(`td`,{className:`py-1`,children:[(0,x.jsx)(`span`,{"aria-hidden":`true`,className:CW[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:[Ti(e.value),` / `,Ti(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 NW({todaySessions:e}){let{data:t}=L({queryKey:z.costPerTool(),queryFn:({signal:e})=>Ir(void 0,void 0,e),refetchInterval:EW,retry:!1}),{data:n}=L({queryKey:z.modelUsage,queryFn:({signal:e})=>Pr(e),refetchInterval:EW}),{data:r,isError:i}=L({queryKey:z.usageInsights(`today`),queryFn:({signal:e})=>hr(`today`,e),refetchInterval:EW}),a=n?.byModel?Object.entries(n.byModel).filter(([,e])=>e.requestCount>0):[],o=a.reduce((e,[,t])=>e+t.totalCostUsd,0),s=a.map(([e,t])=>({model:e,requestCount:t.requestCount,costPerMillionTokens:t.costPerMillionTokens,totalCostUsd:t.totalCostUsd,sharePct:o>0?t.totalCostUsd/o*100:0})),c=JU(e.filter(e=>XW(e)>0),t?.costByToolType),l=t?.attributionRate??1;return(0,x.jsx)(ZU,{data:r,isError:i,title:`Where today's spend went`,subtitle:`Since midnight`,modelRows:s,toolRows:c,toolCostAvailable:!0,toolCoverageCaveat:t!=null&&l<.5?`Tool and skill shares are based on ${H(l*100)} of session cost`:null})}function PW(e){switch(e){case`excellent`:return`Hit rate above 60%`;case`can_improve`:return`Hit rate between 30% and 60%`;case`needs_attention`:return`Hit rate below 30%`;default:return`No cache activity`}}function FW({aggregate:e}){let{data:t}=L({queryKey:z.cacheHealth,queryFn:({signal:e})=>Fr(e),refetchInterval:EW}),n=e?.cacheHealth,r=!n||n.status===`no_cache_activity`||n.cacheHitRatePct==null,i=`Prompt cache hit rate today, with a suggestion for improving it — usually by moving stable context earlier in the prompt.`;if(r)return(0,x.jsx)(PU,{title:`Cache Health`,tooltip:i,value:`—`,tone:`neutral`,detail:`Appears once token usage with cache reads is reported.`});let a=n.status===`excellent`?`good`:n.status===`can_improve`?`warn`:`bad`,o=[{label:`Cache read`,value:Oi(n.totalCacheReadTokens)},{label:`Cache write`,value:Oi(n.totalCacheCreationTokens)}];if(t?.week_over_week_delta_pts!=null&&t.week_over_week_delta_pts!==0){let e=t.week_over_week_delta_pts;o.push({label:`vs last week`,value:`${e>0?`+`:``}${e}pts`})}return(0,x.jsx)(PU,{title:`Cache Health`,tooltip:i,value:H(n.cacheHitRatePct),tone:a,detail:`${PW(n.status)} · ${Ei(n.totalSavingsUsd)} saved today`,rows:o})}function IW(){let{data:e}=L({queryKey:z.toolSelectionScore,queryFn:({signal:e})=>Tr(e),refetchInterval:EW}),t=`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.`;if(!e||Array.isArray(e)||e.totalCalls===0)return(0,x.jsx)(PU,{title:`Tool Selection`,tooltip:t,value:`—`,tone:`neutral`,detail:`Waiting for tool calls.`});let n=e.score>=.9?`good`:e.score>=.7?`warn`:`bad`;return(0,x.jsx)(PU,{title:`Tool Selection`,tooltip:t,value:H(e.score*100),tone:n,detail:`${e.penalizedCalls} of ${e.totalCalls} calls penalized`,rows:[{label:`Re-reads`,value:String(e.redundantReadCount)},{label:`Repeat fails`,value:String(e.repeatedFailureCount)},{label:`Unused output`,value:String(e.unusedOutputCount)}]})}function LW(){let{data:e}=L({queryKey:z.qualityProxy,queryFn:({signal:e})=>wr(e),refetchInterval:EW}),t=`Diff apply rate and test pass rate across today's sessions, plus how often you backtracked or self-corrected. Watch for the degrading status if quality drops mid-session.`;if(!e||e.totalSignals===0)return(0,x.jsx)(PU,{title:`Quality`,tooltip:t,value:`—`,tone:`neutral`,detail:`Waiting for edits and test runs.`});let n=e.degradationDetected?`bad`:`good`;return(0,x.jsx)(PU,{title:`Quality`,tooltip:t,value:e.diffApplyRate===null?`—`:H(e.diffApplyRate*100),tone:n,rows:[{label:`Test pass`,value:e.testPassRate===null?`—`:H(e.testPassRate*100)},{label:`Backtracks`,value:String(e.backtrackCount)},{label:`Self-corrections`,value:String(e.selfCorrectionCount)}]})}function RW({liveSessions:e}){let{data:t,isPending:n}=L({queryKey:z.computeWaste,queryFn:({signal:e})=>cr(e),retry:!1}),r=`Tokens wasted today on retried tool calls and anti-pattern activity (stuck loops, redundant reads, thrashing).`;if(n||!t||typeof t.total_tokens_wasted!=`number`)return(0,x.jsx)(PU,{title:`Compute Waste`,tooltip:r,value:`—`,tone:`neutral`,detail:`No compute waste data yet.`});let i=t.status===`clean`?`good`:t.status===`moderate`?`warn`:`bad`,a=t.by_session?.[0]??null,o=t.breakdown[0]??null,s=[{label:`Retry`,value:`~${Oi(t.retry_tokens_wasted)}`},{label:`Anti-pattern`,value:`~${Oi(t.anti_pattern_tokens_wasted)}`}];return a!==null&&s.push({label:`Top session`,value:`${JW(a.session_id,e)} (~${Oi(a.tokens_wasted)})`}),(0,x.jsx)(PU,{title:`Compute Waste`,tooltip:r,value:`~${Oi(t.total_tokens_wasted)} tokens`,tone:i,detail:TW(t.status,o?.type??null),rows:s})}function zW({aggregate:e}){let t=e?.latency,n=`How long tool calls took today — p50/p95/p99 across all calls, plus the slowest tools by p95.`;if(!t||!t.overall)return(0,x.jsx)(PU,{title:`Latency`,tooltip:n,value:`—`,tone:`neutral`,detail:`Waiting for tool calls.`});let r=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,2):[],i=[{label:`p50`,value:ji(t.overall.p50)},{label:`p99`,value:ji(t.overall.p99)},...r.map(([e,t])=>({label:Ai(e),value:ji(t.p95)}))];return(0,x.jsx)(PU,{title:`Latency`,tooltip:n,value:ji(t.overall.p95),rows:i})}function BW(){let{data:e}=L({queryKey:z.apiFailures,queryFn:({signal:e})=>Gr(e),refetchInterval:EW}),t=e?.byErrorType?Object.entries(e.byErrorType).filter(([,e])=>e>0):[],n=e?.totalFailures??0;return(0,x.jsx)(PU,{title:`API Failures`,tooltip:`Turns that failed outright after Claude Code's own retries were exhausted, captured via its StopFailure hook.`,value:String(n),tone:n===0?`good`:`bad`,detail:`Reflects Claude Code's StopFailure hook`,rows:t.length>0?t.map(([e,t])=>({label:e,value:String(t)})):void 0})}function VW({hourlySpend:e,forecastEod:t,weekForecast:n}){let r=e.some(e=>e.cost>0),i=(0,b.useMemo)(()=>tG(e,t,Date.now()),[e,t]);return(0,x.jsx)($r,{title:`Spend by hour`,subtitle:`Today`,children:r?(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(HU,{data:i,xTickFormatter:e=>UW(Number(e)),tooltipLabel:e=>e.label}),n!==null&&(0,x.jsxs)(`p`,{className:`mt-1.5 text-[10px] text-ink-muted`,children:[`On pace for ~`,Ei(n),` this week`]})]}):(0,x.jsx)(W,{variant:`inline`,title:`No spend data yet`})})}function HW(e,t,n=`sum`){let r=fW(t),i=r+864e5,a=Array(24).fill(0);for(let{ts:t,value:o}of e){if(t<r||t>=i)continue;let e=Math.min(23,Math.floor((t-r)/36e5));a[e]=n===`max`?Math.max(a[e],o):a[e]+o}return a}function UW(e){return`${String(e).padStart(2,`0`)}:00`}function WW(e,t){let n=Math.max(0,...e);return n===0?`No ${t} recorded yet.`:`Peak ${UW(e.indexOf(n))} — ${n} ${t}`}function GW({todayHeatmap:e,concurrency:t}){let n=Date.now(),r=(e?.buckets?.length??0)>0,i=(t?.buckets?.length??0)>0,a=r?HW(e.buckets.map((t,n)=>({ts:e.startTimestamp+n*e.bucketSizeMs,value:t})),n):[],o=a.map((e,t)=>({count:e,tooltip:`${UW(t)} — ${e} calls`})),s=(i?HW(t.buckets.map(e=>({ts:e.timestamp,value:e.count})),n,`max`):[]).map((e,t)=>({count:e,tooltip:`${UW(t)} — ${e} concurrent`}));return(0,x.jsx)($r,{title:`Activity today`,children:(0,x.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,x.jsxs)(`div`,{children:[(0,x.jsx)(V,{className:`mb-1.5`,children:`Tool calls`}),(0,x.jsx)(`div`,{className:`flex items-end`,children:r?(0,x.jsx)(da,{data:o,levels:6,ariaLabel:`Today's activity density by hour`}):(0,x.jsx)(W,{variant:`inline`,title:`No heatmap data yet`})}),(0,x.jsx)(`p`,{className:`mt-1.5 text-[10px] text-ink-muted`,children:WW(a,`calls`)})]}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(V,{className:`mb-1.5`,children:`Concurrent sessions`}),(0,x.jsx)(`div`,{className:`flex items-end`,children:i?(0,x.jsx)(da,{data:s,levels:6,ariaLabel:`Concurrency over time, peak ${t?.peak??0}`}):(0,x.jsx)(W,{variant:`inline`,title:`No session data yet`})}),(0,x.jsxs)(`p`,{className:`mt-1.5 text-[10px] text-ink-muted`,children:[`now `,t?.current??0,` · peak `,t?.peak??0]})]})]})})}var KW=3e3;function qW({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:({signal:e})=>tr(e)}),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=(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&&YW(t.startTime),a=r.has(t.sessionId),o=t.startTime!=null&&t.durationMs!=null?t.startTime+t.durationMs:null,s=o!=null&&o>=n&&YW(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]),p=(t.length>0?t[0].sessionId:null)??(d.size>0?[...d][0]:null)??(f.length>0?f[0].sessionId:null),m=n??p,h=m!==null&&d.has(m),g=n!==null&&!d.has(n);(0,b.useEffect)(()=>{l(m)},[m,l]);let{data:_}=L({queryKey:m?z.sessionReplay(m):[`replay`,`none`],queryFn:({signal:e})=>xr(m,e),enabled:m!==null,retry:!1,refetchInterval:h?KW:!1}),{data:v}=L({queryKey:m?z.sessionSubagents(m):[`subagents`,`none`],queryFn:({signal:e})=>Sr(m,e),enabled:m!==null,retry:!1,refetchInterval:h?KW:!1}),{data:y}=L({queryKey:z.workflows,queryFn:({signal:e})=>Hr(e),refetchInterval:h?1e4:!1}),{data:S}=L({queryKey:m?[`turn-costs`,m]:[`turn-costs`],queryFn:({signal:e})=>ur(m??void 0,e),refetchInterval:1e4}),{data:C}=L({queryKey:m?[`decision-tree`,m]:[`decision-tree`],queryFn:({signal:e})=>lr(m??void 0,e),refetchInterval:1e4}),{data:w}=L({queryKey:m?[`context`,m]:z.context,queryFn:({signal:e})=>jr(m??void 0,e),refetchInterval:1e4,enabled:h&&!!m}),{data:T}=L({queryKey:[`context-composition`],queryFn:({signal:e})=>Mr(e),refetchInterval:1e4}),{data:E}=L({queryKey:[`context-efficiency`],queryFn:({signal:e})=>Nr(e),refetchInterval:1e4}),D=(0,b.useRef)(null);(0,b.useEffect)(()=>{h&&D.current&&(D.current.scrollTop=D.current.scrollHeight)},[_?.timeline?.length,h]);let O=(0,b.useMemo)(()=>_?.timeline??[],[_]),k=(0,b.useMemo)(()=>Array.isArray(v?.agents)?v.agents:[],[v]),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=(v?.agents?.length??0)>0?v.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,v]),j=(0,b.useMemo)(()=>{let e={};if(Array.isArray(y))for(let t of y)t&&typeof t.runId==`string`&&typeof t.status==`string`&&t.parentSessionId===m&&(e[t.runId]=t.status);return e},[y,m]);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)(Qr,{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:[f.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 `+(m===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)(ci,{label:`live`,size:`sm`}):(0,x.jsx)(`span`,{className:`text-[10px] text-ink-muted`,title:e.startTime?`Started ${xi(e.startTime)}`:void 0,children:e.startTime?xi(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:Ei(e.estimatedCostUsd)}):(0,x.jsx)(`span`,{children:`—`})]})]},e.sessionId)}),d.size===0&&f.length===0&&(0,x.jsx)(W,{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:[m&&(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:[g&&(0,x.jsx)(`span`,{"data-testid":`session-ended-badge`,children:(0,x.jsx)(oi,{tone:`neutral`,size:`sm`,uppercase:!0,children:`Session ended`})}),(0,x.jsx)(`button`,{type:`button`,onClick:()=>c(`/sessions?id=${m}`),className:`text-[10px] text-accent-cyan hover:underline transition-colors duration-150`,children:`full session →`})]})]}),(0,x.jsxs)(`div`,{ref:D,className:`overflow-auto flex-1 p-2`,children:[!m&&(0,x.jsx)(`div`,{className:`text-ink-muted text-xs p-2`,children:`Select a session to view its timeline.`}),m&&O.length===0&&k.length===0&&(0,x.jsx)(W,{icon:`timeline`,title:h?`Waiting for tool calls`:`No tool calls`,subtitle:h?`Tool calls will appear here in real time.`:`This session has no recorded tool calls.`}),m&&(O.length>0||k.length>0)&&(0,x.jsx)(Ma,{sessionId:m,parentEntries:O,agents:k,window:A,runStatusById:j,parentSegments:_?.segments??[],onSelectRun:e=>a(e)},m)]}),h&&m&&(0,x.jsx)(`div`,{className:`border-t border-bg-line px-3 py-2 shrink-0`,children:(0,x.jsx)(xU,{sessionId:m,expandable:!1})}),((C?.totalBranches??0)>0||(S?.turns?.length??0)>0||(w?.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 C&&C.totalBranches>0&&e.push(`${C.longestFailureStreak} failure streak`),S?.turns&&S.turns.length>0&&e.push(`${S.turns.length} turns · ${Ei(S.totalAttributedCost)}`),e.length>0?`${e.join(` · `)} — session detail →`:`session detail →`})()})})]})]}),i!=null&&(0,x.jsx)(no,{runId:i,onClose:()=>a(null)}),o&&(0,x.jsx)(CU,{decisionTree:C,turnCosts:S,contextHistory:w?.history,contextWindow:w?.contextWindow,contextComposition:T,contextEfficiency:E,onClose:()=>s(!1)})]})}function JW(e,t){let n=t.find(t=>t.sessionId===e);return n?.sessionName?n.sessionName:e.slice(0,8)}var YW=e=>pW(e);function XW(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 mW({startTime:e.startTime,endTime:t})}function ZW(e){let t=e.estimatedCostUsd;return t==null||t<=0?0:t*XW(e)}function QW(e){let t=0;for(let n of e)t+=ZW(n);return t}function $W(e){let t=0;for(let n of e){let e=XW(n);e>0&&(t+=(n.antiPatterns?.length??0)*e)}return Math.round(t)}function eG(e){let t=Array(24).fill(0),n=fW(),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 tG(e,t,n){let r=new Date(n).getHours(),i=Array(24),a=0;for(let t=0;t<24;t++)a+=e[t]?.cost??0,i[t]=a;let o=i[r]??0,s=t!=null&&Number.isFinite(t)&&t>o,c=s&&23>r?(t-o)/(23-r):0;return Array.from({length:24},(n,a)=>{let l=a<=r?i[a]:null,u=null;return s&&a>=r&&(u=a===23?t:o+c*(a-r)),{key:String(a),label:UW(a),spendUsd:e[a]?.cost??0,cumulativeUsd:l,projectedUsd:u}})}var nG=[`var(--color-heatmap-0)`,`var(--color-heatmap-1)`,`var(--color-heatmap-2)`,`var(--color-heatmap-3)`,`var(--color-heatmap-4)`];function rG(e,t){if(e===0)return nG[0];let n=e/t;return nG[Math.min(Math.ceil(n*4),4)]}function iG(e,t,n){let r=e+n*t;return new Date(r).toLocaleTimeString(void 0,{hour:`numeric`,minute:`2-digit`})}function aG({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)(cG,{days:c,maxCount:n,width:a,height:o,ariaLabel:s}):(0,x.jsx)(oG,{buckets:t,maxCount:n,bucketSizeMs:r,startTimestamp:i,width:a,height:o,ariaLabel:s})}function oG({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:rG(e,t),className:`heatmap-cell`,style:{animationDelay:`${Math.min(i*8,400)}ms`},onMouseEnter:t=>{let a=iG(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 sG=[`Mon`,``,`Wed`,``,`Fri`,``,`Sun`];function cG({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:[sG.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:rG(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`}),nG.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 lG(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 uG(e){return e<6e5?3e4:e<36e5?6e4:e<144e5?3e5:9e5}var dG=50,fG={thrashing:`Edit/Test Thrashing`,stuck_loop:`Stuck Loop`,blind_editing:`Blind Editing`,re_reading:`Repeated Reads`,over_delegation:`Over-Delegation`},pG={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`}},mG=[{value:`today`,label:`Today`},{value:`7d`,label:`7 days`},{value:`30d`,label:`30 days`},{value:`all`,label:`All`}],hG=[{value:`all`,label:`All sources`},{value:`script`,label:`Script`},{value:`agent_tool`,label:`Agent tool`}],gG=[{value:`all`,label:`All`},{value:`running`,label:`Running`},{value:`completed`,label:`Completed`},{value:`failed`,label:`Failed`},{value:`cancelled`,label:`Cancelled`}];function _G(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 vG(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 yG(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 bG(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 xG(e){return typeof e.startTime==`number`?e.startTime:new Date(e.startTime??0).getTime()}function SG(e){return xG(e)+(e.durationMs??0)}function CG(e,t){let n=[...e];switch(t){case`date`:n.sort((e,t)=>xG(t)-xG(e));break;case`lastActive`:n.sort((e,t)=>SG(t)-SG(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 wG(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function TG(){let e=Gt(),[t,n]=(0,b.useState)(()=>vG(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)(()=>vG(e),[e]);(0,b.useEffect)(()=>{_&&n(_)},[_]);let[v,y]=(0,b.useState)(()=>yG(window.location.search)),S=(0,b.useMemo)(()=>yG(e),[e]);(0,b.useEffect)(()=>{S&&y(S)},[S]);let[C,w]=(0,b.useState)(()=>bG(window.location.search)),T=(0,b.useMemo)(()=>bG(e),[e]);(0,b.useEffect)(()=>{T&&w(T)},[T]);let E=L({queryKey:z.sessionsList(dG),queryFn:({signal:e})=>nr(dG,e),refetchInterval:1e4}),{data:D}=L({queryKey:z.workflows,queryFn:({signal:e})=>Hr(e),refetchInterval:1e4}),O=L({queryKey:z.sessionCurrent,queryFn:({signal:e})=>tr(e),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:({signal:e})=>ar(t,e),enabled:t!==null,refetchInterval:O.isLoading||t&&k.has(t)?1e4:!1}),j=(0,b.useMemo)(()=>CG(E.data??[],r),[E.data,r]),M=(0,b.useMemo)(()=>Array.isArray(D)?D:[],[D]),N=(0,b.useMemo)(()=>M.filter(e=>!(!_G(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=>_G(xG(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)},I=(0,b.useCallback)(e=>{m(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),oe=(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)(TU,{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)(U,{label:`Workflow runs`,value:String(ee.totalRuns),numericValue:ee.totalRuns,animate:!0})}),(0,x.jsx)(`div`,{className:`px-3`,children:(0,x.jsx)(U,{label:`Subagents`,value:String(ee.totalAgents),numericValue:ee.totalAgents,animate:!0})}),(0,x.jsx)(`div`,{className:`px-3`,children:(0,x.jsx)(U,{label:`Workflow spend`,value:Di(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)(U,{label:`Avg duration`,value:ee.avgDurationMs===null?`—`:Ci(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)(di,{value:a,onChange:o,options:mG,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:hG.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:gG.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`,` `,dG,` 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)(W,{variant:`loading`,icon:`timeline`,title:`Loading sessions`}),!E.isLoading&&ne.length===0&&k.size===0&&(0,x.jsx)(W,{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)(EG,{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:I,onToggleRun:oe,onOpenRun:se},e.sessionId)),j.length>=dG&&(0,x.jsxs)(`div`,{className:`p-2 text-[10px] text-ink-muted text-center border-t border-border-subtle`,children:[`Only the `,dG,` 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)(W,{icon:`timeline`,title:`Loading sessions`,subtitle:`Selecting the most recent session…`}),t&&A.isLoading&&(0,x.jsx)(W,{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)(W,{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)(kG,{data:A.data,isLive:!!t&&k.has(t),onOpenRun:se})]})]}),d!=null&&(0,x.jsx)(no,{runId:d,onClose:()=>f(null)})]})}function EG({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)(ci,{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 ${bi(e.startTime)}`:void 0,children:e.startTime?bi(i===`lastActive`?SG(e):e.startTime):`—`}),(0,x.jsx)(`span`,{children:Di(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)(DG,{run:e,isExpanded:o.has(e.runId),onToggleRun:l,onOpenRun:u},e.runId))})]})}function DG({run:e,isExpanded:t,onToggleRun:n,onOpenRun:r}){let{data:i}=L({queryKey:z.workflowDetail(e.runId),queryFn:({signal:t})=>Ur(e.runId,t),enabled:t}),a=(0,b.useMemo)(()=>i?.agents??[],[i]),o=pG[e.status]??pG.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:Di(e.totalUsd)}),(0,x.jsx)(oi,{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:wG(t.tokens)})]},t.agentId))})]})}function OG(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 kG({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:Ci(e.durationMs),s=e.timeline??[],c=s.length>0?s[0].timestamp:0,l=Object.entries(e.modelBreakdown??{}).map(([e,t])=>({model:e,...t})).sort((e,t)=>t.totalCostUsd-e.totalCostUsd),u=e.tokensInput!=null&&e.tokensCacheRead!=null&&e.tokensCacheCreation!=null&&e.tokensInput+e.tokensCacheRead+e.tokensCacheCreation>0&&e.tokensCacheRead+e.tokensCacheCreation>0?Math.round(e.tokensCacheRead/(e.tokensInput+e.tokensCacheRead+e.tokensCacheCreation)*100):null;return s.length===0&&i.length===0?(0,x.jsx)(W,{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)(ci,{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`})}),(e.linesAdded!=null||e.linesRemoved!=null||e.attribution?.apiDurationMs!=null||u!=null)&&(0,x.jsxs)(`div`,{className:`text-[11px] text-ink-muted mt-2 flex flex-wrap gap-2`,children:[(e.linesAdded!=null||e.linesRemoved!=null)&&(0,x.jsxs)(`span`,{children:[e.linesAdded!=null&&`+${e.linesAdded}`,e.linesAdded!=null&&e.linesRemoved!=null&&` / `,e.linesRemoved!=null&&`−${e.linesRemoved}`,` lines`]}),e.attribution?.apiDurationMs!=null&&(0,x.jsxs)(`span`,{children:[`API `,Ci(e.attribution.apiDurationMs),` · wall`,` `,Ci(e.durationMs??0)]}),u!=null&&(0,x.jsxs)(`span`,{children:[`cache `,u,`%`]})]})]})}),l.length>0?(0,x.jsxs)(`div`,{className:`mb-4`,children:[(0,x.jsx)(V,{className:`mb-2`,children:`Usage by model`}),(0,x.jsx)(`div`,{className:`max-h-48 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:`Input`}),(0,x.jsx)(`th`,{className:`text-right pb-1`,children:`Output`}),(0,x.jsx)(`th`,{className:`text-right pb-1`,children:`Cache read`}),(0,x.jsx)(`th`,{className:`text-right pb-1`,children:`Cache write`}),(0,x.jsx)(`th`,{className:`text-right pb-1`,children:`Cost`})]})}),(0,x.jsx)(`tbody`,{children:l.map(e=>(0,x.jsxs)(`tr`,{className:`border-t border-bg-line`,children:[(0,x.jsx)(`td`,{className:`py-1 font-mono text-[11px] truncate`,title:e.model,children:e.model}),(0,x.jsx)(`td`,{className:`py-1 text-right tabular-nums`,children:Oi(e.totalInputTokens)}),(0,x.jsx)(`td`,{className:`py-1 text-right tabular-nums`,children:Oi(e.totalOutputTokens)}),(0,x.jsx)(`td`,{className:`py-1 text-right tabular-nums`,children:Oi(e.totalCacheReadTokens)}),(0,x.jsx)(`td`,{className:`py-1 text-right tabular-nums`,children:Oi(e.totalCacheCreationTokens)}),(0,x.jsx)(`td`,{className:`py-1 text-right tabular-nums`,children:Ei(e.totalCostUsd)})]},e.model))})]})})]}):e.model?(0,x.jsxs)(`div`,{className:`mb-4 bg-surface-3 rounded-lg p-2.5 text-xs`,children:[(0,x.jsx)(V,{children:`Model`}),(0,x.jsx)(`div`,{className:`font-mono`,children:e.model})]}):null,(0,x.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 mb-4 text-xs`,children:[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:Ei(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)(oi,{tone:`warning`,size:`sm`,bordered:!0,children:[fG[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:vi(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:vi(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 ${yi(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)(xU,{sessionId:e.sessionId})}),i.length>0&&(0,x.jsx)(jG,{breakdownEntries:i,totalCalls:a,isLive:t,sessionId:e.sessionId},`tools-${e.sessionId}`),(0,x.jsx)(NG,{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)(AG,{sessionId:e.sessionId,isLive:t,parentEntries:s,onOpenRun:n},e.sessionId)]})}function AG({sessionId:e,isLive:t,parentEntries:n,onOpenRun:r}){let{data:i,isLoading:a,isError:o}=L({queryKey:z.sessionSubagents(e),queryFn:({signal:t})=>Sr(e,t),retry:!1,refetchInterval:t?1e4:!1}),{data:s}=L({queryKey:z.workflows,queryFn:({signal:e})=>Hr(e),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)(W,{variant:`loading`,icon:`radar`,title:`Loading subagents`}):o||i===void 0?(0,x.jsx)(Ma,{sessionId:e,parentEntries:d,agents:[],window:u??{startMs:0,endMs:1},onSelectRun:r,runStatusById:c}):(0,x.jsx)(Ma,{sessionId:e,parentEntries:d,agents:l,window:u??i.window,onSelectRun:r,runStatusById:c})})]})}function jG({breakdownEntries:e,totalCalls:t,isLive:n,sessionId:r}){let[i,a]=(0,b.useState)(`calls`),{data:o}=L({queryKey:[`context`,r],queryFn:({signal:e})=>jr(r,e),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)(di,{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:Ai(e)}),(0,x.jsx)(`div`,{className:`flex-1 h-3 bg-surface-3 relative rounded`,children:(0,x.jsx)(`div`,{className:`h-3 rounded ${OG(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:Ai(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:[`~`,MG(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 MG(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function NG({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=uG(r),a=lG(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)(aG,{variant:`strip`,buckets:t.buckets,maxCount:t.maxCount,bucketSizeMs:t.bucketSizeMs,startTimestamp:t.startMs,ariaLabel:`Session activity density`})]}):null}var PG=`bg-accent-cyan`;function FG({rows:e,max:t=8,emptyText:n=`No data yet`}){if(e.length===0)return(0,x.jsx)(`div`,{className:`text-[11px] text-ink-muted`,children:n});let r=e.slice(0,t),i=e.length-r.length,a=Math.max(...r.map(e=>e.share),0);return(0,x.jsxs)(`div`,{children:[(0,x.jsxs)(`table`,{className:`sr-only`,children:[(0,x.jsx)(`caption`,{children:`Ranked breakdown`}),(0,x.jsx)(`thead`,{children:(0,x.jsxs)(`tr`,{children:[(0,x.jsx)(`th`,{children:`Label`}),(0,x.jsx)(`th`,{children:`Value`}),(0,x.jsx)(`th`,{children:`Share`})]})}),(0,x.jsx)(`tbody`,{children:r.map(e=>(0,x.jsxs)(`tr`,{children:[(0,x.jsx)(`td`,{children:e.label}),(0,x.jsx)(`td`,{children:e.value}),(0,x.jsx)(`td`,{children:H(e.share)})]},e.key))})]}),(0,x.jsx)(`div`,{className:`space-y-0.5`,"aria-hidden":`true`,children:r.map(e=>{let t=a>0?e.share/a*100:0;return(0,x.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_5rem_auto_2.5rem] items-center gap-2 text-[11px]`,children:[(0,x.jsx)(`span`,{className:`truncate text-ink-subtle`,children:e.label}),(0,x.jsx)(`span`,{className:`h-1 rounded-full bg-surface-5`,children:(0,x.jsx)(`span`,{className:`block h-1 rounded-full ${e.tone??PG}`,style:{width:`${t}%`}})}),(0,x.jsx)(`span`,{className:`text-right text-ink-base tabular-nums`,children:e.value}),(0,x.jsx)(`span`,{className:`text-right text-ink-muted tabular-nums`,children:H(e.share)})]},e.key)})}),i>0&&(0,x.jsxs)(`div`,{className:`mt-1.5 text-[10px] italic text-ink-muted`,children:[`+`,i,` more not shown`]})]})}var IG={fill:`var(--color-ink-muted)`,fontSize:10},LG=`var(--color-border-subtle)`,RG={background:`var(--color-bg-elevated)`,border:`1px solid var(--color-border-medium)`,borderRadius:8,fontSize:12,color:`var(--color-ink-base)`},zG=`var(--color-accent-green)`,BG=`var(--color-accent-amber)`;function VG(e){return`Last ${e} days`}var HG=`Compares session outcomes before and after your most recent edit to an instruction file (CLAUDE.md, or the active platform's equivalent) — efficiency, cost, and correction rate. The pill shows whether the most recent edit measured as an improvement.`,UG={improved:`success`,degraded:`danger`,neutral:`neutral`,insufficient_data:`neutral`};function WG(e){return e.startsWith(`Positive`)?`text-accent-green`:e.startsWith(`Negative`)?`text-accent-red`:`text-accent-amber`}function GG(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 KG(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 qG({impact:e,impactError:t,drift:n}){if(t)return(0,x.jsx)($r,{title:`Instruction file`,tooltip:HG,children:(0,x.jsx)(W,{icon:`radar`,title:`Instruction file impact unavailable`})});if(!e)return(0,x.jsx)($r,{title:`Instruction file`,tooltip:HG,children:(0,x.jsx)(W,{variant:`loading`,title:`Loading instruction file impact…`})});let r=n?.recentCorrelations[n.recentCorrelations.length-1],i=r?(0,x.jsx)(oi,{tone:UG[r.verdict],children:r.verdict}):void 0;if(e.message||!e.change||!e.before||!e.after||!e.deltas||!e.verdict)return r?(0,x.jsx)($r,{title:`Instruction file`,tooltip:HG,action:i,children:(0,x.jsx)(W,{variant:`inline`,title:`No instruction file impact tracked yet.`})}):(0,x.jsx)($r,{title:`Instruction file`,tooltip:HG,children:(0,x.jsx)(W,{variant:`inline`,title:`No instruction file changes tracked yet.`})});let a=new Date(e.change.timestamp).toLocaleDateString(void 0,{month:`short`,day:`numeric`}),o=e.before.avgEfficiencyScore===null?null:Math.round(e.before.avgEfficiencyScore*100),s=e.after.avgEfficiencyScore===null?null:Math.round(e.after.avgEfficiencyScore*100);return(0,x.jsxs)($r,{title:`Instruction file`,tooltip:HG,action:i,children:[(0,x.jsxs)(`div`,{className:`text-xs mb-3`,children:[(0,x.jsx)(`span`,{className:`font-medium ${WG(e.verdict)}`,children:e.verdict}),(0,x.jsxs)(`span`,{className:`text-[10px] text-ink-muted`,children:[` · `,e.change.changeType,` `,e.change.filePath.split(`/`).pop(),` · `,a]})]}),(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:o??`—`}),(0,x.jsx)(`span`,{className:`font-mono`,children:s??`—`}),(0,x.jsx)(`span`,{className:e.deltas.efficiencyScore==null?`text-ink-muted`:e.deltas.efficiencyScore.improved?`text-accent-green`:`text-accent-amber`,children:GG(e.deltas.efficiencyScore)}),(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`Cost/session`}),(0,x.jsx)(`span`,{className:`font-mono`,children:Ei(e.before.avgCostUsd)}),(0,x.jsx)(`span`,{className:`font-mono`,children:Ei(e.after.avgCostUsd)}),(0,x.jsx)(`span`,{className:e.deltas.cost.improved?`text-accent-green`:`text-accent-amber`,children:KG(e.deltas.cost)}),(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`Correction rate`}),(0,x.jsx)(`span`,{className:`font-mono`,children:H(e.before.avgCorrectionRate*100)}),(0,x.jsx)(`span`,{className:`font-mono`,children:H(e.after.avgCorrectionRate*100)}),(0,x.jsx)(`span`,{className:e.deltas.correctionRate.improved?`text-accent-green`:`text-accent-amber`,children:KG(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 JG(){let[e,t]=(0,b.useState)(`30`),n=Number(e),r=L({queryKey:z.weekly,queryFn:({signal:e})=>fr(e)}),i=L({queryKey:z.sessionsList(200),queryFn:({signal:e})=>nr(200,e)}),a=L({queryKey:z.costPerOutcome(n),queryFn:({signal:e})=>mr(n,e)}),o=L({queryKey:z.costPerTool(n),queryFn:({signal:e})=>Ir(void 0,n,e)}),s=L({queryKey:z.personalCoach,queryFn:({signal:e})=>gr(e)}),c=L({queryKey:z.recommendations,queryFn:({signal:e})=>_r(e),retry:!1}),l=L({queryKey:z.claudeMdImpact,queryFn:({signal:e})=>vr(e),retry:!1}),u=L({queryKey:z.collaborationProfile,queryFn:({signal:e})=>yr(e),retry:!1}),d=L({queryKey:z.activityHeatmap(`history`),queryFn:({signal:e})=>Ar(`history`,12,e)}),f=L({queryKey:z.concurrencyHistory(n),queryFn:({signal:e})=>kr(n,e)}),p=L({queryKey:z.instructionDrift,queryFn:({signal:e})=>Wr(e)}),m=L({queryKey:z.usageInsights(n),queryFn:({signal:e})=>hr(n,e)}),h=L({queryKey:z.sessionsTodayAggregate,queryFn:({signal:e})=>rr(e),refetchInterval:1e4}),g=r.isError||i.isError||a.isError||f.isError,_=[...r.data??[]].reverse(),v=_.map(e=>{let t=e.avgEfficiencyScore;return{week:e.week||`?`,efficiency:t===null?null:Math.round(t*100)}}),y=i.data??[],S=oK(y,n),C=lK(rK(y,n),n),w=y.length>=200&&iK(y,n),T=w?aK(y):null,E=h.data?.forecastEndOfDayUsd??null,D=h.data?.totalCostUsd??0,O=y.map(e=>({startTime:typeof e.startTime==`string`?new Date(e.startTime).getTime():e.startTime,estimatedCostUsd:e.estimatedCostUsd})),k=E==null?null:_W(O,E,D,Date.now()),A=E==null?null:bW(O,E,D,Date.now()),j=[k==null?null:`~${Ei(k)} this week`,A==null?null:`~${Ei(A)} this month`].filter(e=>e!=null).join(` · `)||null,M=cK(a.data),N=a.data?.totalCost??M.reduce((e,t)=>e+t.totalCost,0),ee=uK(_),te=mK(S),P=te.reduce((e,t)=>e+t.totalCost,0),F=JU(S,o.data?.costByToolType),ne=o.data?.costByToolType!==void 0,{attributedSessionCount:re,totalSessionCount:ie}=o.data??{},ae=re!==void 0&&ie!==void 0&&re<ie?`Cost/token breakdown only available for ${re} of ${ie} sessions in this window — older sessions predate per-tool attribution.`:null,I=sK(S);return(0,x.jsxs)(`section`,{children:[(0,x.jsx)(TU,{theme:`history`}),(0,x.jsxs)(`div`,{className:`flex items-center justify-between gap-2 mb-4`,children:[(0,x.jsx)(`h1`,{className:`text-xl font-semibold gradient-text`,children:`History`}),(0,x.jsx)(di,{value:e,onChange:t,options:[{value:`7`,label:`7d`},{value:`30`,label:`30d`},{value:`90`,label:`90d`}],ariaLabel:`History window`})]}),g&&(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)(B,{padding:`lg`,tone:`elevated`,glow:`green`,className:`mb-4`,children:[(0,x.jsxs)(`div`,{className:`grid grid-cols-5 gap-4`,children:[(0,x.jsx)(U,{label:`spend`,value:Ei(I.spendUsd),animate:!0,numericValue:I.spendUsd,format:Ei}),(0,x.jsx)(U,{label:`sessions`,value:String(I.sessionCount),animate:!0,numericValue:I.sessionCount}),(0,x.jsx)(U,{label:`avg efficiency`,value:I.avgEfficiency===null?`—`:H(I.avgEfficiency*100),...I.avgEfficiency===null?{}:{animate:!0,numericValue:Math.round(I.avgEfficiency*100),suffix:`%`}}),(0,x.jsx)(U,{label:`avg cost / session`,value:Di(I.avgCostPerSession)}),(0,x.jsx)(U,{label:`flags`,tone:I.flags>0?`warn`:`neutral`,value:String(I.flags),animate:!0,numericValue:I.flags})]}),(0,x.jsxs)(`div`,{className:`text-[10px] text-ink-muted mt-3`,children:[I.sessionCount,` sessions`,T!==null&&` · oldest ${T} days shown`]})]}),(0,x.jsxs)($r,{title:`Daily spend`,subtitle:VG(n),className:`mb-3`,children:[(0,x.jsx)(`div`,{className:`h-44 min-w-0`,children:(0,x.jsx)(HU,{data:C.map(e=>({key:e.day,label:e.day,spendUsd:e.cost,cumulativeUsd:null,projectedUsd:null})),xTickFormatter:Ni,tooltipLabel:e=>Ni(e.key)})}),j&&(0,x.jsxs)(`p`,{className:`mt-1.5 text-[10px] text-ink-muted`,children:[`On pace for `,j]}),w&&(0,x.jsxs)(`div`,{className:`text-[10px] text-ink-muted italic mt-1`,children:[`Sample doesn't reach back `,n,` days — early days in this chart may undercount actual spend.`]})]}),(0,x.jsx)(`div`,{className:`mt-3`,children:(0,x.jsx)(ZU,{data:m.data,isError:m.isError,title:`What's contributing to your spend`,subtitle:VG(n),toolRows:F,toolCostAvailable:ne,toolCoverageCaveat:ae})}),(0,x.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 mt-3`,children:[(0,x.jsx)($r,{title:`Model performance`,subtitle:VG(n),footnote:te.some(e=>e.flagged)?`▲ Highlighted models had sessions with elevated error rates`:void 0,children:te.length===0?(0,x.jsx)(W,{icon:`radar`,title:`No model data yet`,subtitle:`Complete a few sessions to see model performance.`}):(0,x.jsx)(GU,{title:`Model performance`,hideTitle:!0,rows:te,rowKey:e=>e.model,defaultSort:{column:5,direction:`desc`},columns:[{header:`Model`,align:`left`,className:`font-medium`,cell:e=>e.model},{header:`Sessions`,align:`right`,cell:e=>e.sessions,sortValue:e=>e.sessions},{header:`Eff.`,align:`right`,cell:e=>e.avgEfficiency===null?`—`:H(Math.min(100,e.avgEfficiency*100)),sortValue:e=>e.avgEfficiency??-1},{header:`Success`,align:`right`,className:e=>e.flagged?`text-accent-amber`:void 0,cell:e=>(0,x.jsxs)(x.Fragment,{children:[e.flagged&&`▲ `,e.avgSuccessRate===null?`—`:H(Math.min(100,e.avgSuccessRate*100))]}),sortValue:e=>e.avgSuccessRate??-1},{header:`Avg $`,align:`right`,cell:e=>Di(e.avgCost),sortValue:e=>e.avgCost??-1},{header:`Share`,align:`right`,cell:e=>{let t=dK(e,P);return t===null?`—`:H(t)},sortValue:e=>dK(e,P)??-1},{header:`$/1M tok`,align:`right`,className:`text-ink-subtle`,cell:e=>Di(e.costPerMillionTokens),sortValue:e=>e.costPerMillionTokens??-1}]})}),(0,x.jsx)($r,{title:`Cost per outcome`,subtitle:VG(n),children:M.length===0?(0,x.jsx)(W,{icon:`radar`,title:`No outcomes yet`}):(0,x.jsx)(GU,{title:`Outcomes`,hideTitle:!0,rows:M,rowKey:e=>e.outcome,defaultSort:{column:3,direction:`desc`},columns:[{header:`Outcome`,align:`left`,cell:e=>e.outcome},{header:`Sessions`,align:`right`,cell:e=>e.count,sortValue:e=>e.count},{header:`Cost`,align:`right`,cell:e=>Ei(e.totalCost),sortValue:e=>e.totalCost},{header:`Share`,align:`right`,cell:e=>H(N>0?e.totalCost/N*100:0),sortValue:e=>N>0?e.totalCost/N*100:0}]})})]}),(0,x.jsxs)(`div`,{className:`grid grid-cols-3 gap-3 mt-3`,children:[(0,x.jsx)($r,{title:`Weekly efficiency`,subtitle:`Last 12 weeks`,children:(0,x.jsx)(`div`,{className:`h-44 min-w-0`,children:(0,x.jsx)(fm,{width:`100%`,height:`100%`,minWidth:1,minHeight:1,children:(0,x.jsxs)(sU,{data:v,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:zG,stopOpacity:.3}),(0,x.jsx)(`stop`,{offset:`100%`,stopColor:zG,stopOpacity:0})]})}),(0,x.jsx)(EL,{stroke:LG,strokeDasharray:`3 3`}),(0,x.jsx)($B,{dataKey:`week`,tick:IG,stroke:LG,tickFormatter:Pi}),(0,x.jsx)(mV,{tick:IG,stroke:LG,domain:[0,100],unit:`%`}),(0,x.jsx)(oj,{contentStyle:RG}),(0,x.jsx)(Cz,{type:`monotone`,dataKey:`efficiency`,stroke:zG,strokeWidth:2,fill:`url(#effGradient)`,dot:{r:2,fill:zG}})]})})})}),(0,x.jsx)($r,{title:`Anti-pattern frequency`,subtitle:`Last 12 weeks`,children:ee.length===0||ee.every(e=>e.count===0)?(0,x.jsx)(W,{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)(fm,{width:`100%`,height:`100%`,minWidth:1,minHeight:1,children:(0,x.jsxs)(aU,{data:ee,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:BG,stopOpacity:.9}),(0,x.jsx)(`stop`,{offset:`100%`,stopColor:BG,stopOpacity:.4})]})}),(0,x.jsx)(EL,{stroke:LG,strokeDasharray:`3 3`}),(0,x.jsx)($B,{dataKey:`week`,tick:IG,stroke:LG,tickFormatter:Pi}),(0,x.jsx)(mV,{tick:IG,stroke:LG}),(0,x.jsx)(oj,{contentStyle:RG}),(0,x.jsx)(MB,{dataKey:`count`,fill:`url(#antiPatternGradient)`,radius:[3,3,0,0]})]})})})}),(0,x.jsx)(tK,{data:d.data})]}),(0,x.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 mt-3`,children:[(0,x.jsx)(eK,{data:s.data}),(0,x.jsx)(QG,{data:c.data,isError:c.isError})]}),(0,x.jsx)(`div`,{className:`mt-3`,children:(0,x.jsx)(qG,{impact:l.data,impactError:l.isError,drift:p.data})}),(0,x.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 mt-3`,children:[(0,x.jsx)($G,{data:u.data,isError:u.isError}),(0,x.jsx)(nK,{data:f.data,windowNum:n})]})]})}function YG({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.jsx)(`span`,{className:`font-mono`,children:Ei(e.avgCostPerSession)}),(0,x.jsx)(`span`,{className:s(r),children:u(r)}),(0,x.jsx)(`span`,{className:`text-ink-muted`,children:`Anti-pattern rate`}),(0,x.jsx)(`span`,{className:`font-mono`,children:H(e.antiPatternRate*100)}),(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 XG(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 ZG(e){return e===`high`?`var(--color-accent-amber)`:e===`medium`?`var(--color-accent-blue)`:`var(--color-ink-muted)`}function QG({data:e,isError:t}){if(t)return(0,x.jsx)($r,{title:`Recommendations`,children:(0,x.jsx)(W,{icon:`radar`,title:`Recommendations unavailable`,subtitle:`Connect a full Preflight session to enable recommendations.`})});if(!e)return(0,x.jsx)($r,{title:`Recommendations`,children:(0,x.jsx)(W,{variant:`loading`,title:`Loading recommendations…`})});if(e.recommendations.length===0)return(0,x.jsx)($r,{title:`Recommendations`,children:(0,x.jsx)(W,{variant:`inline`,title:`No recommendations yet`,subtitle:`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)($r,{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:XG(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:ZG(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 $G({data:e,isError:t}){if(t)return(0,x.jsx)($r,{title:`Collaboration profile`,children:(0,x.jsx)(W,{icon:`radar`,title:`Collaboration profile unavailable`})});if(!e)return(0,x.jsx)($r,{title:`Collaboration profile`,children:(0,x.jsx)(W,{variant:`loading`,title:`Loading collaboration profile…`})});if(e.sessionCount===0)return(0,x.jsx)($r,{title:`Collaboration profile`,children:(0,x.jsx)(W,{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:``}],r=n.map(e=>({key:e.key,label:e.name,value:H(e.value),share:e.value}));return(0,x.jsxs)($r,{title:`Collaboration profile`,subtitle:e.developerCount<=1?`No team data yet`:void 0,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`]})]}),(0,x.jsx)(FG,{rows:r,max:4}),e.developerCount>1&&(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 eK({data:e}){return e?e.status===`insufficient_data`?(0,x.jsx)($r,{title:`Personal coach`,children:(0,x.jsx)(`div`,{className:`text-ink-muted text-xs`,children:e.message})}):(0,x.jsx)($r,{title:`Personal coach`,children:(0,x.jsxs)(`div`,{className:`text-xs space-y-2`,children:[(0,x.jsx)(YG,{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)($r,{title:`Personal coach`,children:(0,x.jsx)(W,{variant:`loading`,title:`Loading coaching insights…`})})}function tK({data:e}){return(0,x.jsx)($r,{title:`Activity heatmap`,subtitle:`Last 12 weeks`,children:e?e.days.length===0?(0,x.jsx)(W,{variant:`inline`,title:`No activity yet`}):(0,x.jsx)(aG,{variant:`grid`,buckets:[],maxCount:e.maxCount,days:e.days,ariaLabel:`Daily activity heatmap for the last 12 weeks`}):(0,x.jsx)(W,{variant:`loading`,title:`Loading activity…`})})}function nK({data:e,windowNum:t}){let n=e?.dailyPeaks??[],r=n.some(e=>e.peak>0);return(0,x.jsx)($r,{title:`Peak concurrent sessions`,subtitle:VG(t),children:e?r?(0,x.jsxs)(`div`,{className:`flex flex-col items-center gap-2`,children:[(0,x.jsx)(`div`,{className:`text-2xl font-bold tabular-nums gradient-text`,children:Math.max(...n.map(e=>e.peak))}),(0,x.jsx)(hK,{data:n})]}):(0,x.jsx)(W,{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.jsx)(W,{variant:`loading`,title:`Loading concurrency…`})})}function rK(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 iK(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 aK(e,t=new Date){let n=null;for(let t of e){if(t.startTime==null)continue;let e=new Date(t.startTime).getTime();Number.isNaN(e)||(n===null||e<n)&&(n=e)}if(n===null)return 0;let r=t.getTime()-n;return Math.max(1,Math.ceil(r/864e5))}function oK(e,t,n=new Date){let r=new Date(n);r.setDate(r.getDate()-(t-1)),r.setHours(0,0,0,0);let i=r.getTime();return e.filter(e=>{if(e.startTime==null)return!1;let t=new Date(e.startTime).getTime();return Number.isFinite(t)&&t>=i})}function sK(e){let t=0,n=0,r=0,i=0;for(let a of e)a.estimatedCostUsd!=null&&(t+=a.estimatedCostUsd),a.efficiencyScore!=null&&(n+=a.efficiencyScore,r++),i+=a.antiPatterns?.length??0;return{spendUsd:t,sessionCount:e.length,avgEfficiency:r>0?n/r:null,avgCostPerSession:e.length>0?t/e.length:null,flags:i}}function cK(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 lK(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 uK(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}function dK(e,t){return t<=0||e.costedSessions===0?null:e.totalCost/t*100}var fK=.85,pK=.3;function mK(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<fK&&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,totalCost:r.costSum,costedSessions:r.costCount,costPerMillionTokens:r.blendedTokensSum>0?r.blendedCostSum/r.blendedTokensSum*1e6:null,flagged:r.successCount>0&&r.lowSuccessSessions/r.successCount>pK});return n.sort((e,t)=>t.sessions-e.sessions)}function hK({data:e}){let t=e.map(e=>({count:e.peak,tooltip:`${e.date.slice(5)}: ${e.peak}`}));return(0,x.jsx)(da,{data:t,ariaLabel:`Peak concurrent sessions over ${e.length} days`})}var gK=[{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`}],_K={critical:`danger`,high:`warning`,medium:`info`},vK={sensitive_file:`Sensitive files`,destructive_command:`Destructive`,external_network:`External network`,file_deletion:`File deletion`,other:`Other`};function yK(e){let t=e.map(e=>JSON.stringify(e)).join(`
|
|
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 bK(){let[e,t]=(0,b.useState)(`all`),{data:n,isLoading:r,error:i,refetch:a}=L({queryKey:z.audit,queryFn:({signal:e})=>dr(e),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)(TU,{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)(ni,{variant:`secondary`,size:`md`,onClick:()=>yK(c),children:[`Export JSONL (max `,200,` rows)`]})]}),(0,x.jsx)(`div`,{className:`flex gap-2 mb-3 flex-wrap`,children:gK.map(({key:n,label:r})=>(0,x.jsx)(ni,{variant:e===n?`primary`:`secondary`,size:`sm`,onClick:()=>t(n),children:r},n))}),r&&(0,x.jsx)(W,{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)(oi,{tone:e.severity?_K[e.severity]??`neutral`:`neutral`,size:`sm`,children:vK[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 xK(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 SK={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`},CK={info:`info`,warning:`warning`,critical:`danger`},wK={resolved:`text-accent-green`,aborted:`text-accent-red`,pending:`text-accent-amber`},TK={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 EK(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 DK(e){return e.replace(/_/g,` `)}function OK(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 kK(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 AK(e,t){let n=e=>new Date(e).toLocaleDateString(void 0,{month:`short`,day:`numeric`});return`${n(e)} – ${n(t-1)}`}function jK(e){return e===null?`neutral`:e>20?`bad`:e>5?`warn`:`good`}function MK(e,t){return e===0?`—`:t>0?`${e} (${t} merged)`:String(e)}function NK({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 PK(e){return e.length===1?`/sessions?session=${encodeURIComponent(e[0])}`:`/sessions?sessionIds=${e.map(encodeURIComponent).join(`,`)}`}function FK(e,t){return e===null&&t===null?0:e===null?1:t===null?-1:t-e}function IK(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)=>FK(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)=>FK(e.lastActivityMs,t.lastActivityMs))}function LK({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)(W,{icon:`code`,title:`No git activity in this window`});let s=IK(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)(`th`,{className:`text-left p-2`,children:`PRs`})]})}),(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:6,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(PK(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:`—`})}),(0,x.jsx)(`td`,{className:`p-2 tabular-nums`,children:MK(e.rows.reduce((e,t)=>e+t.metrics.prMetrics.created,0),e.rows.reduce((e,t)=>e+t.metrics.prMetrics.merged,0))})]}),!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(PK(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:`—`})}),(0,x.jsx)(`td`,{className:`p-2 tabular-nums`,children:MK(e.metrics.prMetrics.created,e.metrics.prMetrics.merged)})]},e.identity.worktreeKey)})]},e.repoKey)})})]})})}function RK(){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`,Er(t)),queryFn:({signal:e})=>Dr(`week`,Er(t),e),refetchInterval:5e3}),{data:c}=L({queryKey:z.gitEfficiency(`previous_week`,Er(t)),queryFn:({signal:e})=>Dr(`previous_week`,Er(t),e),refetchInterval:6e4}),{data:l}=L({queryKey:z.gitEfficiency(`30`,`all`),queryFn:({signal:e})=>Dr(`30`,`all`,e),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)(W,{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)(W,{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)(TU,{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)(NK,{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)(NK,{score:m.efficiencyScore})]})]})]}),(0,x.jsx)(oa,{index:0,className:`mb-3`,children:(0,x.jsxs)(B,{padding:`md`,children:[(0,x.jsx)(fi,{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 (${AK(l.since,l.until)})`:`Loading…`}),l?(0,x.jsx)(LK,{rows:l.rows,scope:t,onSelectRepo:u,onSelectWorktree:d}):(0,x.jsx)(W,{icon:`clock`,variant:`loading`,title:`Loading...`})]})}),m.totalGitCommands===0?(0,x.jsx)(W,{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)(oa,{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 (`,AK(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)(U,{label:`commits`,hero:!0,value:String(m.commitCount),sub:xK(m.commitCount,g)??void 0,animate:!0,numericValue:m.commitCount}),(0,x.jsx)(U,{label:`PRs created`,tone:m.prMetrics.created>0?`good`:`neutral`,value:String(m.prMetrics.created),sub:xK(m.prMetrics.created,_)??void 0,animate:!0,numericValue:m.prMetrics.created}),(0,x.jsx)(U,{label:`conflicts`,tone:y>0?`bad`:`good`,value:String(y),sub:[y===0?`clean session`:`${h} resolved`,xK(y,v)].filter(e=>e!==null).join(` · `),animate:!0,numericValue:y}),a.scope.kind===`worktree`?(0,x.jsx)(U,{label:`behind ${m.liveState?.defaultBranch??`upstream`}`,tone:jK(m.liveState?.behind??null),value:m.liveState?.behind==null?`—`:String(m.liveState.behind),sub:m.liveState?.measuredAtMs==null?void 0:kK(m.liveState.measuredAtMs),animate:!0,numericValue:m.liveState?.behind??null}):(0,x.jsx)(U,{label:`worst behind`,tone:jK(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)(oa,{index:2,className:`mb-3`,children:(0,x.jsxs)(B,{padding:`md`,children:[(0,x.jsx)(fi,{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)(U,{label:`Avg time between commits`,value:EK(m.velocityMetrics.avgTimeBetweenCommitsMs)}),(0,x.jsx)(U,{label:`Longest gap`,value:EK(m.velocityMetrics.longestGapMs),sub:`biggest idle stretch between commits`}),(0,x.jsx)(U,{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)(U,{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)(oa,{index:3,className:`mb-3`,children:(0,x.jsxs)(B,{padding:`md`,children:[(0,x.jsx)(fi,{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)(U,{label:`PRs created`,value:String(m.prMetrics.created),tone:m.prMetrics.created>0?`good`:`neutral`}),(0,x.jsx)(U,{label:`PRs merged`,value:String(m.prMetrics.merged),tone:m.prMetrics.merged>0?`good`:`neutral`}),(0,x.jsx)(U,{label:`CI checks viewed`,value:String(m.prMetrics.checksViewed),sub:"times you ran `gh pr checks`"}),(0,x.jsx)(U,{label:`Time to PR`,value:EK(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)(oi,{tone:t,size:`sm`,children:[e.action,e.prNumber?` #${e.prNumber}`:``]},`${e.timestamp}-${e.action}`)})})]})]})}),(m.mergeConflicts>0||m.rebaseConflicts>0)&&(0,x.jsx)(oa,{index:4,className:`mb-3`,children:(0,x.jsxs)(B,{padding:`md`,children:[(0,x.jsx)(fi,{title:`Conflict Resolution`}),(0,x.jsxs)(`div`,{className:`grid grid-cols-2 sm:grid-cols-4 gap-3`,children:[(0,x.jsx)(U,{label:`Resolution rate`,value:m.conflictResolutionRate===null?`—`:`${Math.round(m.conflictResolutionRate*100)}%`}),(0,x.jsx)(U,{label:`Avg resolution time`,value:EK(m.avgConflictResolutionMs)}),(0,x.jsx)(U,{label:`Aborted ops`,value:String(m.abortedOperations)}),(0,x.jsx)(U,{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 ${wK[e.resolution]}`,children:e.resolution}),(0,x.jsx)(`span`,{className:`text-ink-muted`,children:EK(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)(oa,{index:5,className:`mb-3`,children:(0,x.jsxs)(B,{padding:`md`,children:[(0,x.jsx)(fi,{title:`Conflict Resolution Strategy`}),(0,x.jsxs)(`div`,{className:`grid grid-cols-2 sm:grid-cols-4 gap-3`,children:[(0,x.jsx)(U,{label:`Accept ours`,value:String(m.conflictResolutionStrategy.oursCount)}),(0,x.jsx)(U,{label:`Accept theirs`,value:String(m.conflictResolutionStrategy.theirsCount)}),(0,x.jsx)(U,{label:`Manual merge`,value:String(m.conflictResolutionStrategy.manualMergeCount)}),(0,x.jsx)(U,{label:`Cherry-picks`,value:String(m.conflictResolutionStrategy.cherryPickCount)})]})]})}),(m.resetHards>0||m.discardedChanges>0||m.forcePushes>0)&&(0,x.jsx)(oa,{index:6,className:`mb-3`,children:(0,x.jsxs)(B,{padding:`md`,children:[(0,x.jsx)(fi,{title:`Destructive Operations`}),(0,x.jsxs)(`div`,{className:`grid grid-cols-3 gap-3`,children:[(0,x.jsx)(U,{label:`Hard resets`,value:String(m.resetHards)}),(0,x.jsx)(U,{label:`Discarded changes`,value:String(m.discardedChanges)}),(0,x.jsx)(U,{label:`Force pushes`,value:String(m.forcePushes)})]})]})}),m.bestPractices.length>0&&(0,x.jsx)(oa,{index:7,className:`mb-3`,children:(0,x.jsxs)(B,{padding:`md`,children:[(0,x.jsx)(fi,{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)(oi,{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)(oi,{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)(oa,{index:8,className:`mb-3`,children:(0,x.jsxs)(B,{padding:`md`,children:[(0,x.jsx)(fi,{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 ${SK[e.severity]}`,children:(0,x.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,x.jsx)(oi,{tone:CK[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)(oa,{index:9,children:(0,x.jsxs)(B,{padding:`md`,children:[(0,x.jsx)(fi,{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:OK(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 ${TK[e.type]??`bg-surface-8 text-ink-subtle`}`,children:DK(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:EK(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 zK({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 BK({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 VK={ok:`●`,warn:`▲`,fail:`✗`,skip:`–`},HK={ok:`text-accent-green`,warn:`text-accent-amber`,fail:`text-accent-red`,skip:`text-ink-muted`};function UK(){let{data:e,isLoading:t,isError:n,refetch:r}=L({queryKey:z.diagnostics,queryFn:({signal:e})=>Rr(e),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)(fi,{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)(W,{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 ${HK[e.status]??`text-ink-muted`}`,children:VK[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 WK(){let e=C(),{data:t,isLoading:n,error:r}=L({queryKey:z.settings,queryFn:({signal:e})=>Lr(e)}),{data:i}=L({queryKey:[`observability-health`],queryFn:({signal:e})=>Vr(e),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=>zr(e),onSuccess:()=>{e.invalidateQueries({queryKey:z.settings}),S(null)},onError:e=>{S(String(e))}});if(n)return(0,x.jsx)(W,{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)(UK,{}),(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)(fi,{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)(zK,{label:`Account ID`,value:t.accountId}),(0,x.jsx)(zK,{label:`App name`,value:t.appName}),(0,x.jsx)(zK,{label:`Mode`,value:t.mode}),(0,x.jsx)(zK,{label:`Storage path`,value:t.storagePath}),(0,x.jsx)(zK,{label:`High security`,value:t.highSecurity?`enabled`:`disabled`}),(0,x.jsx)(zK,{label:`License key`,value:t.licenseKey}),(0,x.jsx)(`div`,{className:`mt-3 flex items-center gap-3`,children:(0,x.jsx)(ni,{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)(fi,{title:`Cost & Retention`,subtitle:`Budget caps trigger warnings at 50%, 80%, and 100%. Leave blank for no limit.`}),(0,x.jsx)(BK,{label:`Session budget (USD)`,value:D,onChange:u,min:.01}),(0,x.jsx)(BK,{label:`Daily budget (USD)`,value:O,onChange:f,min:.01}),(0,x.jsx)(BK,{label:`Weekly budget (USD)`,value:k,onChange:m,min:.01}),(0,x.jsx)(BK,{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)(ni,{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 GK({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 KK({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)(GK,{pct:t.pctUsed,exceeded:t.exceeded}),(0,x.jsxs)(`span`,{className:`text-xs tabular-nums text-ink-base`,children:[Ei(t.spentUsd),t.budgetUsd===null?``:` / ${Ei(t.budgetUsd)}`,t.pctUsed===null?``:` (${t.pctUsed.toFixed(0)}%)`]}),t.exceeded&&(0,x.jsx)(oi,{tone:`danger`,size:`sm`,children:`exceeded`})]})}function qK(){let e=C(),t=L({queryKey:z.budget,queryFn:({signal:e})=>pr(e),refetchInterval:1e4}),n=L({queryKey:z.settings,queryFn:({signal:e})=>Lr(e)}),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=>zr(e),onSuccess:()=>void e.invalidateQueries({queryKey:z.settings})}),g=st({mutationFn:()=>Br(),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)(fi,{title:`Budget Status`}),t.isLoading&&(0,x.jsx)(W,{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)(KK,{label:`session`,p:r.session}),(0,x.jsx)(KK,{label:`daily`,p:r.daily}),(0,x.jsx)(KK,{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:[Ei(e.spentUsd),` / `,Ei(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)(fi,{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)(W,{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)(ni,{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)(fi,{title:`Slack Digest`,subtitle:`Weekly digest sent to a Slack incoming webhook. URL changes take effect immediately.`}),n.isLoading&&(0,x.jsx)(W,{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)(oi,{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)(ni,{variant:`primary`,size:`md`,onClick:v,disabled:h.isPending,loading:h.isPending,children:h.isPending?`Saving…`:`Save`}),i.digestWebhookUrl&&(0,x.jsx)(ni,{variant:`danger`,size:`md`,onClick:()=>h.mutate({digestWebhookUrl:null},{onSuccess:()=>u(void 0)}),disabled:h.isPending,children:`Unsubscribe`}),(0,x.jsx)(ni,{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 JK(){Zi();let e=qn(e=>e.connected),[t,n]=Wt(),[r,i]=(0,b.useState)(!1),{theme:a,toggleTheme:o}=na(),s=(0,b.useCallback)(()=>i(e=>!e),[]),c=(0,b.useCallback)(()=>i(!1),[]);return Qi({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)(Wi,{}),(0,x.jsxs)(`div`,{className:`flex flex-1 min-h-0`,children:[(0,x.jsx)(_i,{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)(Gi,{resetKey:t,children:(0,x.jsxs)($t,{children:[(0,x.jsx)(Xt,{path:`/sessions`,component:TG}),(0,x.jsx)(Xt,{path:`/history`,component:JG}),(0,x.jsx)(Xt,{path:`/audit`,component:bK}),(0,x.jsx)(Xt,{path:`/git`,component:RK}),(0,x.jsx)(Xt,{path:`/settings`,component:WK}),(0,x.jsx)(Xt,{path:`/alerts`,component:qK}),(0,x.jsx)(Xt,{path:`/`,component:DW}),(0,x.jsx)(Xt,{children:(0,x.jsx)(`div`,{className:`text-ink-muted`,children:`Not found`})})]})})})]})]}),(0,x.jsx)(qi,{open:r,onClose:c})]})}var YK=new Je({defaultOptions:{queries:{staleTime:5e3,retry:0,refetchOnWindowFocus:!1}}}),XK=document.getElementById(`root`);if(!XK)throw Error(`Mount node #root not found`);(0,ct.createRoot)(XK).render((0,x.jsx)(b.StrictMode,{children:(0,x.jsx)(w,{client:YK,children:(0,x.jsx)(JK,{})})}));
|