specrails-desktop 2.43.2 → 2.44.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/client/dist/assets/{ActivityFeedPage-C7XJ5-bJ.js → ActivityFeedPage-CL1BUXoj.js} +1 -1
- package/client/dist/assets/{AgentBrowserCapture-C_WpXceT.js → AgentBrowserCapture-BQem50z4.js} +1 -1
- package/client/dist/assets/{AgentModeAnalyticsPane-PEZKjyZS.js → AgentModeAnalyticsPane-BC_xbT_l.js} +2 -2
- package/client/dist/assets/{AgentModeCodePane-D_Xcq5t5.js → AgentModeCodePane-DK-q3K6Y.js} +2 -2
- package/client/dist/assets/{AgentModeJobsPane-CDSkOuNP.js → AgentModeJobsPane-C7ELTPC1.js} +1 -1
- package/client/dist/assets/{AgentsPage-D577NzIM.js → AgentsPage-DbLezyI6.js} +1 -1
- package/client/dist/assets/{AnalyticsPage-C6ZZI_zg.js → AnalyticsPage-DTsg-N5z.js} +1 -1
- package/client/dist/assets/{CodePage-B5z5oLnP.js → CodePage-DwgbeqQ_.js} +1 -1
- package/client/dist/assets/{DesktopAnalyticsPage-D_V9RuGg.js → DesktopAnalyticsPage-Y0Z1ryQr.js} +1 -1
- package/client/dist/assets/{DocsDialog-Beg82MEe.js → DocsDialog-KeCOxvGH.js} +1 -1
- package/client/dist/assets/{DocsPage-BkE4m4wp.js → DocsPage-Bt1PgYPO.js} +1 -1
- package/client/dist/assets/{ExportDropdown-ophapHrT.js → ExportDropdown-DczgU4at.js} +1 -1
- package/client/dist/assets/InteractiveJobComposer-BcR6xlHU.js +19 -0
- package/client/dist/assets/{JobDetailModal-BCxue_Do.js → JobDetailModal-DKA_DUHe.js} +1 -1
- package/client/dist/assets/{JobDetailPage-_rIDpNfo.js → JobDetailPage-vaOcE-cI.js} +1 -1
- package/client/dist/assets/{JobsPage-C6xcijbs.js → JobsPage-Bwoe-Fb0.js} +1 -1
- package/client/dist/assets/{LoopBuilderPage-A-Mt6EjT.js → LoopBuilderPage-CqC4hbXb.js} +1 -1
- package/client/dist/assets/{LoopPreviewModal-DqHiG4Dt.js → LoopPreviewModal-T0zuFv6y.js} +1 -1
- package/client/dist/assets/{LoopsPage-B-ketPET.js → LoopsPage-DrQGcZv2.js} +1 -1
- package/client/dist/assets/{MinimizedChatsContext-Deg39peL.js → MinimizedChatsContext-C843Y13h.js} +1 -1
- package/client/dist/assets/{PluginsPage-Dn2jPvJL.js → PluginsPage-CTUHX_Lu.js} +1 -1
- package/client/dist/assets/{ProjectSettingsDialog-CVTj4VLt.js → ProjectSettingsDialog-DeL8md1s.js} +1 -1
- package/client/dist/assets/{RepositoryDeliveries-IiQCcndQ.js → RepositoryDeliveries-bgIHE8ep.js} +1 -1
- package/client/dist/assets/{RepositoryScopeSelector-D-RCaknl.js → RepositoryScopeSelector-CZ_U_R3U.js} +1 -1
- package/client/dist/assets/{ReviewPacketPage-BBd617OM.js → ReviewPacketPage-DbKO6pT8.js} +1 -1
- package/client/dist/assets/{TemplatePreviewModal-COHFkUS4.js → TemplatePreviewModal-_CgCCV7L.js} +1 -1
- package/client/dist/assets/{TicketDetailModalContext-BNa1mdXq.js → TicketDetailModalContext-BbRA6cb7.js} +1 -1
- package/client/dist/assets/{Trans-SnMX4MhW.js → Trans-mjFZpHw1.js} +1 -1
- package/client/dist/assets/{formatDistanceToNow-DSj5DprF.js → formatDistanceToNow-BIL-HxGy.js} +1 -1
- package/client/dist/assets/{getTimezoneOffsetInMilliseconds-YhD8rIEs.js → getTimezoneOffsetInMilliseconds-Cs9z2sdO.js} +1 -1
- package/client/dist/assets/{index-D5n_jg_I.css → index-Bfj8HvX1.css} +1 -1
- package/client/dist/assets/{index-m5pKr1T6.js → index-UnaJTMIy.js} +6 -6
- package/client/dist/assets/{jira-api-CSCqGr-Q.js → jira-api-B2BBZQTx.js} +1 -1
- package/client/dist/assets/{jobs-BS6RTurf.js → jobs-5PQJbdOf.js} +1 -1
- package/client/dist/assets/{jobs-CezU69AE.js → jobs-B2B08Oy9.js} +1 -1
- package/client/dist/assets/{jobs-ClFJae0s.js → jobs-BJZtBbwb.js} +1 -1
- package/client/dist/assets/{jobs-BTT0Bsks.js → jobs-BlWEsQb7.js} +1 -1
- package/client/dist/assets/{jobs-DJSFIFVy.js → jobs-ConfD8xD.js} +1 -1
- package/client/dist/assets/jobs-DMPU64ms.js +1 -0
- package/client/dist/assets/{jobs-DhgGr8vm.js → jobs-DojASiTp.js} +1 -1
- package/client/dist/assets/{jobs-B8rrzfyZ.js → jobs-kVHkNpB-.js} +1 -1
- package/client/dist/assets/{project-repositories-DYhTvwQ1.js → project-repositories-xSqimlaj.js} +1 -1
- package/client/dist/assets/settings-2Yx_9yJM.js +1 -0
- package/client/dist/assets/settings-BLOsrXEw.js +1 -0
- package/client/dist/assets/settings-C6s9PtRD.js +1 -0
- package/client/dist/assets/settings-CCNZN5Q-.js +1 -0
- package/client/dist/assets/{settings-Deupji9c.js → settings-CpKwTew1.js} +1 -1
- package/client/dist/assets/settings-DPjNiUsS.js +1 -0
- package/client/dist/assets/settings-FIqwhTup.js +1 -0
- package/client/dist/assets/{settings-CrMi3kSi.js → settings-NSWQjY5B.js} +1 -1
- package/client/dist/assets/{spending-BqbdPm_4.js → spending-DXOcv1tn.js} +1 -1
- package/client/dist/assets/{useDesktop-RSMTyy7V.js → useDesktop-gVGoWWiY.js} +1 -1
- package/client/dist/assets/{useSharedWebSocket-BOdS5_Iz.js → useSharedWebSocket-DbGL_YOt.js} +2 -2
- package/client/dist/index.html +16 -16
- package/docs/README.md +6 -1
- package/docs/agents/README.md +13 -0
- package/docs/agents/mcp.md +103 -0
- package/docs/guide/de/integrations/5-mcp-server.md +2 -0
- package/docs/guide/de/settings/3-pipeline-telemetry-and-diagnostics.md +1 -1
- package/docs/guide/en/integrations/5-mcp-server.md +3 -30
- package/docs/guide/en/pipeline/3-batch-implement-and-multi-feature.md +29 -0
- package/docs/guide/en/settings/3-pipeline-telemetry-and-diagnostics.md +10 -1
- package/docs/guide/es/integrations/5-mcp-server.md +3 -30
- package/docs/guide/es/pipeline/3-batch-implement-and-multi-feature.md +30 -0
- package/docs/guide/es/settings/3-pipeline-telemetry-and-diagnostics.md +11 -1
- package/docs/guide/fr/integrations/5-mcp-server.md +2 -0
- package/docs/guide/fr/settings/3-pipeline-telemetry-and-diagnostics.md +1 -1
- package/docs/guide/it/integrations/5-mcp-server.md +2 -0
- package/docs/guide/it/settings/3-pipeline-telemetry-and-diagnostics.md +1 -1
- package/docs/guide/ja/integrations/5-mcp-server.md +2 -0
- package/docs/guide/ja/settings/3-pipeline-telemetry-and-diagnostics.md +1 -1
- package/docs/guide/pt/integrations/5-mcp-server.md +2 -0
- package/docs/guide/pt/settings/3-pipeline-telemetry-and-diagnostics.md +1 -1
- package/docs/guide/zh/integrations/5-mcp-server.md +2 -0
- package/docs/guide/zh/settings/3-pipeline-telemetry-and-diagnostics.md +1 -1
- package/docs/mcp.md +18 -48
- package/package.json +1 -1
- package/server/dist/core-completion.js +58 -0
- package/server/dist/core-execution.js +2 -1
- package/server/dist/db.js +1 -1
- package/server/dist/loop-executors.js +15 -2
- package/server/dist/loop-graph.js +2 -1
- package/server/dist/loop-run-manager.js +18 -1
- package/client/dist/assets/InteractiveJobComposer-wBBBNaJn.js +0 -19
- package/client/dist/assets/jobs-DzMjUcaN.js +0 -1
- package/client/dist/assets/settings-BBt2xtDQ.js +0 -1
- package/client/dist/assets/settings-BJB9RKJj.js +0 -1
- package/client/dist/assets/settings-CHwQR2rB.js +0 -1
- package/client/dist/assets/settings-DKyhDGD1.js +0 -1
- package/client/dist/assets/settings-DqRMmwAM.js +0 -1
- package/client/dist/assets/settings-J4rj6vo-.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-zu2_FqZY.js";import{f as r}from"./chunk-KS7C4IRE-DEKu087k.js";import{m as i,r as a}from"./useSharedWebSocket-BOdS5_Iz.js";import{t as o}from"./Trans-SnMX4MhW.js";import{n as s,t as c}from"./createLucideIcon-Bjbbp_KS.js";import{a as l,n as u,r as d}from"./useDesktop-RSMTyy7V.js";import{n as f,r as p,t as m}from"./spending-BqbdPm_4.js";import{t as h}from"./clsx-CjueKrWZ.js";import{t as g}from"./formatDistanceToNow-DSj5DprF.js";import{r as _}from"./provider-capabilities-B-wOHfLP.js";import{Ft as v,ft as y}from"./index-m5pKr1T6.js";import{t as b}from"./ExportDropdown-ophapHrT.js";import{A as x,B as S,C,D as ee,E as w,F as T,G as E,H as D,I as O,J as k,K as A,L as j,M,N,O as P,P as F,Q as I,R as te,S as L,T as R,V as z,X as B,Z as V,_ as ne,_t as H,a as U,at as re,b as ie,c as ae,ct as oe,et as W,f as se,g as G,gt as ce,h as le,i as ue,j as de,k as fe,l as pe,lt as K,m as me,n as he,nt as ge,o as _e,ot as ve,p as ye,pt as q,q as be,r as xe,rt as Se,s as Ce,st as we,t as Te,tt as Ee,ut as J,v as De,x as Oe,y as ke,z as Ae}from"./BarChart-nBOMNfiy.js";var je=c(`arrow-down-right`,[[`path`,{d:`m7 7 10 10`,key:`1fmybs`}],[`path`,{d:`M17 7v10H7`,key:`6fjiku`}]]),Y=e(t(),1),X=n();function Me(e){return e>=100?`$${e.toFixed(0)}`:e>=10?`$${e.toFixed(1)}`:`$${e.toFixed(2)}`}function Ne(e){return e>=1e3?`$${(e/1e3).toFixed(1)}k`:`$${e.toFixed(2)}`}function Pe(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:`${e}`}var Fe=[`job`,`explore-spec`,`quick-spec`,`ai-edit`,`chat-sidebar`,`spec-launcher`,`proposal`,`agent-studio`,`setup`,`smash`,`file-summary`,`loop`];function Ie({data:e,loading:t,period:n}){let{t:r}=s(`analytics`),[i,a]=(0,Y.useState)(0),o=(0,Y.useRef)(0),c=(0,Y.useRef)(null),l=(0,Y.useRef)(0);if((0,Y.useEffect)(()=>{if(!e)return;let t=e.summary.totalCostUsd,n=++l.current;if(c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),o.current===0&&t>0){let e=performance.now(),r=i=>{if(n!==l.current)return;let o=Math.min(1,(i-e)/600),s=1-(1-o)**3;a(0+(t-0)*s),o<1?c.current=requestAnimationFrame(r):c.current=null};c.current=requestAnimationFrame(r)}else a(t);return o.current=t,()=>{c.current!==null&&(cancelAnimationFrame(c.current),c.current=null)}},[e]),t&&!e)return(0,X.jsx)(`div`,{className:`h-44 rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let u=e.summary.totalCostUsd,d=e.summary.totalRuns,h=e.summary.totalTokens,g=e.summary.totalEstimatedCostUsd??0,_=typeof e.summary.pricedRuns==`number`||typeof e.summary.unpricedRuns==`number`,v=e.summary.unpricedRuns??0,y=e.summary.pricedRuns??(_?Math.max(0,d-v):d),b=_&&d>0&&y===0&&v>0,x=y>0&&v>0,S=typeof e.summary.usageReportedRuns==`number`||typeof e.summary.usageUnavailableRuns==`number`,C=e.summary.usageUnavailableRuns??0,ee=e.summary.usageReportedRuns??(S?Math.max(0,d-C):d),w=S&&d>0&&ee===0&&C>0,T=ee>0&&C>0,E=v>0?null:e.summary.deltaPct,D=e.trackingStartedAt,O=g>0,k=e.bySurface.map(e=>e.surface).filter(e=>!Fe.includes(e)),A=[...Fe,...k].map(t=>{let n=e.bySurface.find(e=>e.surface===t);return{surface:t,costUsd:n?.costUsd??0,count:n?.count??0}}),j=n?r(`windowLabels.${n}`):null;return(0,X.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-gradient-to-br from-card/80 to-card/40 p-5`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-end justify-between gap-3 mb-4`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`div`,{className:`text-[11px] uppercase tracking-wider text-muted-foreground mb-1 flex items-center gap-1.5`,children:[(0,X.jsx)(`span`,{children:r(`hero.spending`)}),j&&(0,X.jsxs)(`span`,{"data-testid":`hero-window-label`,className:`normal-case tracking-normal text-muted-foreground/70 font-normal`,children:[`· `,j]})]}),(0,X.jsxs)(`div`,{className:`flex items-baseline gap-3`,children:[(0,X.jsx)(`div`,{className:`text-5xl font-semibold tabular-nums tracking-tight`,"data-testid":b?`hero-cost-unavailable`:void 0,title:b?r(`hero.costUnavailableTooltip`):void 0,children:b?`—`:Ne(i)}),E!==null&&(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 text-xs font-medium ${E>=0?`text-accent-warning`:`text-accent-success`}`,children:[E>=0?(0,X.jsx)(p,{className:`w-3 h-3`}):(0,X.jsx)(je,{className:`w-3 h-3`}),r(`hero.vsPrev`,{pct:Math.abs(E).toFixed(0)})]})]}),(0,X.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-1 tabular-nums flex items-center gap-2`,children:[(0,X.jsx)(`span`,{children:r(`hero.invocations`,{count:d})}),w?(0,X.jsx)(`span`,{"data-testid":`hero-usage-unavailable`,className:`text-muted-foreground/80 italic`,title:r(`hero.usageUnavailableTooltip`),children:r(`hero.usageUnavailable`)}):T&&h!=null?(0,X.jsx)(`span`,{className:`text-muted-foreground/80 italic`,title:r(`hero.usagePartiallyUnavailableTooltip`),children:r(`hero.usagePartiallyUnavailable`,{tokens:Pe(h),count:C})}):h!=null&&h>0?(0,X.jsx)(`span`,{className:`text-muted-foreground/80`,title:r(`hero.tokensTooltip`),children:r(`hero.tokens`,{tokens:Pe(h)})}):null,b&&(0,X.jsx)(`span`,{className:`text-muted-foreground/80 italic`,title:r(`hero.costUnavailableTooltip`),children:r(`hero.costUnavailable`)}),x&&(0,X.jsx)(`span`,{"data-testid":`hero-cost-partial`,className:`text-muted-foreground/80 italic`,title:r(`hero.costPartiallyUnavailableTooltip`),children:r(`hero.costPartiallyUnavailable`,{count:v})}),O&&(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground/70 italic`,title:r(`hero.includesEstimatedTooltip`,{amount:Me(g)}),children:r(`hero.includesEstimated`,{amount:Me(g)})})]})]}),d===0&&D&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:r(`hero.trackingStarted`,{date:D.slice(0,10)})})]}),d===0?(0,X.jsxs)(`div`,{className:`rounded-lg border border-dashed border-border/40 p-6 text-center`,children:[(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:r(`hero.emptyState`)}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground/70 mt-1`,children:D?r(`hero.trackingStarted`,{date:D.slice(0,10)}):r(`hero.trackingStartedFallback`)})]}):b?(0,X.jsx)(`div`,{className:`rounded-lg border border-dashed border-border/40 p-4 text-xs text-muted-foreground/80`,children:r(`hero.costUnavailableTooltip`)}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`h-3 w-full rounded-full overflow-hidden bg-background-deep flex`,children:A.map(e=>{let t=u>0?e.costUsd/u*100:0;return t===0?null:(0,X.jsx)(`div`,{className:`h-full ${m[e.surface].dot}`,style:{width:`${t}%`},title:r(`hero.segmentTitle`,{label:f[e.surface],value:Me(e.costUsd)})},e.surface)})}),(0,X.jsx)(`div`,{className:`mt-3 flex flex-wrap items-center gap-x-5 gap-y-1.5 text-xs`,children:A.filter(e=>e.costUsd>0).map(e=>(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 tabular-nums`,children:[(0,X.jsx)(`span`,{className:`w-2 h-2 rounded-full ${m[e.surface].dot}`}),(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:f[e.surface]}),(0,X.jsx)(`span`,{className:`text-foreground font-medium`,children:Me(e.costUsd)}),(0,X.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,X.jsx)(`span`,{className:`text-muted-foreground/80`,children:e.count})]},e.surface))})]})]})}var Le={claude:`Claude`,codex:`Codex`,gemini:`Gemini`,kimi:`Kimi`},Re={claude:`bg-accent-info`,codex:`bg-accent-highlight`,gemini:`bg-accent-success`,kimi:`bg-purple-400`};function ze(e){return e>=100?`$${e.toFixed(0)}`:e>=10?`$${e.toFixed(1)}`:e>=.01?`$${e.toFixed(2)}`:`$${e.toFixed(4)}`}function Be(e){return Le[e]??e}function Ve(e){return Re[e]??`bg-accent-secondary`}function He({data:e,loading:t}){let{t:n}=s(`analytics`);if(t&&!e)return(0,X.jsx)(`div`,{className:`h-32 rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e||e.byProvider.length===0||e.byProvider.length===1)return null;let r=e.byProvider.reduce((e,t)=>e+t.costUsd+t.estimatedCostUsd,0),i=e.byProvider.some(e=>typeof e.unpricedCount==`number`?e.unpricedCount>0:e.count>0&&e.costUsd===0&&e.estimatedCostUsd===0);return(0,X.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,X.jsx)(`div`,{className:`flex items-baseline justify-between mb-3`,children:(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`text-[11px] uppercase tracking-wider text-muted-foreground`,children:n(`providerCard.title`)}),(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground/70 mt-0.5`,children:(0,X.jsx)(o,{ns:`analytics`,i18nKey:`providerCard.description`,components:{tilde:(0,X.jsx)(`span`,{className:`font-medium`})}})})]})}),r===0&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:n(i?`providerCard.costUnavailableTooltip`:`providerCard.noCost`)}),r>0&&(0,X.jsx)(X.Fragment,{children:(0,X.jsx)(`div`,{className:`h-2 w-full rounded-full overflow-hidden bg-background-deep flex mb-3`,children:e.byProvider.map(e=>{let t=e.costUsd+e.estimatedCostUsd,i=r>0?t/r*100:0;if(i===0)return null;let a=`${e.costUsd===0&&e.estimatedCostUsd>0?`~`:``}${ze(t)}`;return(0,X.jsx)(`div`,{className:`h-full ${Ve(e.provider)}`,style:{width:`${i}%`},title:n(`providerCard.segmentTitle`,{label:Be(e.provider),value:a,count:e.count})},e.provider)})})}),(0,X.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2 ${r>0?``:`mt-3`}`,children:e.byProvider.map(e=>(0,X.jsx)(Ue,{entry:e},e.provider))})]})}function Ue({entry:e}){let{t}=s(`analytics`),n=e.costUsd+e.estimatedCostUsd,r=e.costUsd===0&&e.estimatedCostUsd>0,i=e.unpricedCount??(e.count>0&&e.costUsd===0&&e.estimatedCostUsd===0?e.count:0),a=e.pricedCount??Math.max(0,e.count-i),o=e.count>0&&i>0&&a===0,c=a>0&&i>0;return(0,X.jsxs)(`div`,{className:`flex items-center gap-2.5 rounded-md border border-border/30 px-2.5 py-1.5`,children:[(0,X.jsx)(`span`,{className:`w-2 h-2 rounded-full shrink-0 ${Ve(e.provider)}`}),(0,X.jsx)(`span`,{className:`text-xs font-medium`,children:Be(e.provider)}),(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:t(`runs`,{count:e.count})}),o?(0,X.jsx)(`span`,{className:`ml-auto text-xs font-medium text-muted-foreground/80 italic`,title:t(`providerCard.costUnavailableTooltip`),children:t(`providerCard.costUnavailable`)}):(0,X.jsxs)(`span`,{className:`ml-auto text-xs font-medium tabular-nums`,title:c?t(`providerCard.costPartiallyUnavailableTooltip`):void 0,children:[r?`~`:``,ze(n),c&&(0,X.jsx)(`span`,{className:`ml-1 font-normal text-muted-foreground/80 italic`,children:t(`providerCard.costPartiallyUnavailable`,{count:i})})]})]})}var We=[`option`,`isActive`];function Z(){return Z=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},Z.apply(null,arguments)}function Ge(e,t){if(e==null)return{};var n,r,i=Ke(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 Ke(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 qe(e){var{option:t,isActive:n}=e,r=Ge(e,We);return typeof t==`string`?Y.createElement(L,Z({option:Y.createElement(we,Z({type:t},r)),isActive:n,shapeType:`symbols`},r)):Y.createElement(L,Z({option:t,isActive:n,shapeType:`symbols`},r))}var Je=W([(e,t,n,r,i,a,o)=>te(e,void 0,void 0,o),(e,t,n,r,i,a,o)=>N(e,`xAxis`,t,o),(e,t,n,r,i,a,o)=>F(e,`xAxis`,t,o),(e,t,n,r,i,a,o)=>N(e,`yAxis`,n,o),(e,t,n,r,i,a,o)=>F(e,`yAxis`,n,o),(e,t,n,r)=>O(e,`zAxis`,r,!1),W([T,(e,t,n,r,i)=>i],(e,t)=>e.filter(e=>e.type===`scatter`).find(e=>e.id===t)),(e,t,n,r,i,a)=>a],(e,t,n,r,i,a,o,s)=>{var{chartData:c,dataStartIndex:l,dataEndIndex:u}=e;if(o!=null){var d=o?.data!=null&&o.data.length>0?o.data:c?.slice(l,u+1);if(!(d==null||t==null||r==null||n==null||i==null||n?.length===0||i?.length===0))return ut({displayedData:d,xAxis:t,yAxis:r,zAxis:a,scatterSettings:o,xAxisTicks:n,yAxisTicks:i,cells:s})}}),Ye=[`id`],Xe=[`onMouseEnter`,`onClick`,`onMouseLeave`],Ze=[`animationBegin`,`animationDuration`,`animationEasing`,`hide`,`isAnimationActive`,`legendType`,`lineJointType`,`lineType`,`shape`,`xAxisId`,`yAxisId`,`zAxisId`];function Qe(e,t){if(e==null)return{};var n,r,i=$e(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 $e(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 Q(){return Q=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},Q.apply(null,arguments)}function et(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 $(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?et(Object(n),!0).forEach(function(t){tt(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):et(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function tt(e,t,n){return(t=nt(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function nt(e){var t=rt(e,`string`);return typeof t==`symbol`?t:t+``}function rt(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 it=e=>{var{dataKey:t,name:n,fill:r,legendType:i,hide:a}=e;return[{inactive:a,dataKey:t,type:i,color:r,value:V(n,t),payload:e}]},at=Y.memo(e=>{var{dataKey:t,points:n,stroke:r,strokeWidth:i,fill:a,name:o,hide:s,tooltipType:c,id:l}=e,u={dataDefinedOnItem:n?.map(e=>e.tooltipPayload),getPosition:e=>{var t;return n==null||(t=n[Number(e)])==null?void 0:t.tooltipPosition},settings:{stroke:r,strokeWidth:i,fill:a,nameKey:void 0,dataKey:t,name:V(o,t),hide:s,type:c,color:a,unit:``,graphicalItemId:l}};return Y.createElement(De,{tooltipEntrySettings:u})});function ot(e){var{points:t,props:n}=e,{line:r,lineType:i,lineJointType:a}=n;if(!r)return null;var o=ce(n),s=H(r),c,l;if(i===`joint`)c=t.map(e=>({x:e.cx??null,y:e.cy??null}));else if(i===`fitting`){var{xmin:u,xmax:d,a:f,b:p}=oe(t),m=e=>f*e+p;c=[{x:u,y:m(u)},{x:d,y:m(d)}]}var h=$($($({},o),{},{fill:`none`,stroke:o&&o.fill},s),{},{points:c});return l=Y.isValidElement(r)?Y.cloneElement(r,h):typeof r==`function`?r(h):Y.createElement(z,Q({},h,{type:a})),Y.createElement(q,{className:`recharts-scatter-line`,key:`recharts-scatter-line`},l)}function st(e){var{showLabels:t,points:n,children:r}=e,i=E(),a=(0,Y.useMemo)(()=>n?.map(e=>{var t={x:e.x??0,y:e.y??0,width:e.width,height:e.height,lowerWidth:e.width,upperWidth:e.width};return $($({},t),{},{value:void 0,payload:e.payload,viewBox:t,parentViewBox:i,fill:void 0})}),[i,n]);return Y.createElement(R,{value:t?a:void 0},r)}function ct(e){var{points:t,allOtherScatterProps:n}=e,{shape:r,activeShape:i,dataKey:a}=n,{id:o}=n,s=Qe(n,Ye),c=ge(de),{onMouseEnter:l,onClick:u,onMouseLeave:d}=n,f=Qe(n,Xe),p=ie(l,a,o),m=Oe(d),h=ke(u,a,o);if(!ve(t))return null;var g=ce(s);return Y.createElement(Y.Fragment,null,Y.createElement(ot,{points:t,props:s}),t.map((e,t)=>{var n=i!=null&&i!==!1,a=n&&c===String(t),s=n&&a?i:r,l=$($($({},g),e),{},{index:t,[k]:String(o)});return Y.createElement(x,{key:`symbol-${e?.cx}-${e?.cy}-${e?.size}-${t}`,zIndex:a?j.activeDot:void 0},Y.createElement(q,Q({className:`recharts-scatter-symbol`},re(f,e,t),{onMouseEnter:p(e,t),onMouseLeave:m(e,t),onClick:h(e,t)}),Y.createElement(qe,Q({option:s,isActive:a},l))))}))}function lt(e){var{previousPointsRef:t,props:n}=e,{points:r,isAnimationActive:i,animationBegin:a,animationDuration:o,animationEasing:s}=n,c=t.current,l=Ae(n,`recharts-scatter-`),[u,d]=(0,Y.useState)(!1),f=(0,Y.useCallback)(()=>{d(!1)},[]),p=(0,Y.useCallback)(()=>{d(!0)},[]),m=!u;return Y.createElement(st,{showLabels:m,points:r},n.children,Y.createElement(S,{animationId:l,begin:a,duration:o,isActive:i,easing:s,onAnimationEnd:f,onAnimationStart:p,key:l},e=>{var i=e===1?r:r?.map((t,n)=>{var r=c&&c[n];return r?$($({},t),{},{cx:t.cx==null?void 0:K(r.cx,t.cx,e),cy:t.cy==null?void 0:K(r.cy,t.cy,e),size:K(r.size,t.size,e)}):$($({},t),{},{size:K(0,t.size,e)})});return e>0&&(t.current=i),Y.createElement(q,null,Y.createElement(ct,{points:i,allOtherScatterProps:n,showLabels:m}))}),Y.createElement(w,{label:n.label}))}function ut(e){var{displayedData:t,xAxis:n,yAxis:r,zAxis:i,scatterSettings:a,xAxisTicks:o,yAxisTicks:s,cells:c}=e,l=J(n.dataKey)?a.dataKey:n.dataKey,u=J(r.dataKey)?a.dataKey:r.dataKey,d=i&&i.dataKey,f=i?i.range:M.range,p=f&&f[0],m=n.scale.bandwidth?n.scale.bandwidth():0,h=r.scale.bandwidth?r.scale.bandwidth():0;return t.map((e,t)=>{var f=I(e,l),g=I(e,u),_=!J(d)&&I(e,d)||`-`,v=[{name:J(n.dataKey)?a.name:n.name||String(n.dataKey),unit:n.unit||``,value:f,payload:e,dataKey:l,type:a.tooltipType,graphicalItemId:a.id},{name:J(r.dataKey)?a.name:r.name||String(r.dataKey),unit:r.unit||``,value:g,payload:e,dataKey:u,type:a.tooltipType,graphicalItemId:a.id}];_!==`-`&&i!=null&&v.push({name:i.name||i.dataKey,unit:i.unit||``,value:_,payload:e,dataKey:d,type:a.tooltipType,graphicalItemId:a.id});var y=B({axis:n,ticks:o,bandSize:m,entry:e,index:t,dataKey:l}),b=B({axis:r,ticks:s,bandSize:h,entry:e,index:t,dataKey:u}),x=_!==`-`&&i!=null?i.scale.map(_):p,S=x==null?0:Math.sqrt(Math.max(x,0)/Math.PI);return $($({},e),{},{cx:y,cy:b,x:y==null?void 0:y-S,y:b==null?void 0:b-S,width:2*S,height:2*S,size:x,node:{x:f,y:g,z:_},tooltipPayload:v,tooltipPosition:{x:y,y:b},payload:e},c&&c[t]&&c[t].props)})}var dt=(e,t,n)=>({x:e.cx,y:e.cy,value:Number(n===`x`?e.node.x:e.node.y),errorVal:I(e,t)});function ft(e){var{hide:t,points:n,className:r,needClip:i,xAxisId:a,yAxisId:o,id:s}=e,c=(0,Y.useRef)(null);if(t)return null;var l=h(`recharts-scatter`,r),u=s;return Y.createElement(x,{zIndex:e.zIndex},Y.createElement(q,{className:l,clipPath:i?`url(#clipPath-${u})`:void 0,id:s},i&&Y.createElement(`defs`,null,Y.createElement(_e,{clipPathId:u,xAxisId:a,yAxisId:o})),Y.createElement(ae,{xAxisId:a,yAxisId:o,data:n,dataPointFormatter:dt,errorBarOffset:0},Y.createElement(q,{key:`recharts-scatter-symbols`},Y.createElement(lt,{props:e,previousPointsRef:c})))))}var pt={xAxisId:0,yAxisId:0,zAxisId:0,label:!1,line:!1,legendType:`circle`,lineType:`joint`,lineJointType:`linear`,shape:`circle`,hide:!1,isAnimationActive:`auto`,animationBegin:0,animationDuration:400,animationEasing:`linear`,zIndex:j.scatter};function mt(e){var t=Se(e,pt),{animationBegin:n,animationDuration:r,animationEasing:i,hide:a,isAnimationActive:o,legendType:s,lineJointType:c,lineType:l,shape:u,xAxisId:d,yAxisId:f,zAxisId:p}=t,m=Qe(t,Ze),{needClip:h}=Ce(d,f),g=(0,Y.useMemo)(()=>C(e.children,ee),[e.children]),_=be(),v=ge(t=>Je(t,d,f,p,e.id,g,_));return h==null||v==null?null:Y.createElement(Y.Fragment,null,Y.createElement(at,{dataKey:e.dataKey,points:v,stroke:e.stroke,strokeWidth:e.strokeWidth,fill:e.fill,name:e.name,hide:e.hide,tooltipType:e.tooltipType,id:e.id}),Y.createElement(ft,Q({},m,{xAxisId:d,yAxisId:f,zAxisId:p,lineType:l,lineJointType:c,legendType:s,shape:u,hide:a,isAnimationActive:o,animationBegin:n,animationDuration:r,animationEasing:i,points:v,needClip:h})))}function ht(e){var t=Se(e,pt),n=be();return Y.createElement(G,{id:t.id,type:`scatter`},e=>Y.createElement(Y.Fragment,null,Y.createElement(ne,{legendPayload:it(t)}),Y.createElement(le,{type:`scatter`,id:e,data:t.data,xAxisId:t.xAxisId,yAxisId:t.yAxisId,zAxisId:t.zAxisId,dataKey:t.dataKey,hide:t.hide,name:t.name,tooltipType:t.tooltipType,isPanorama:n}),Y.createElement(mt,Q({},t,{id:e}))))}var gt=Y.memo(ht,D);gt.displayName=`Scatter`;function _t(e){var t=Ee(),n=(0,Y.useRef)(null);return(0,Y.useLayoutEffect)(()=>{n.current===null?t(se(e)):n.current!==e&&t(me({prev:n.current,next:e})),n.current=e},[e,t]),(0,Y.useLayoutEffect)(()=>()=>{n.current&&=(t(ye(n.current)),null)},[t]),null}var vt={zAxisId:0,range:M.range,scale:M.scale,type:M.type};function yt(e){var t=Se(e,vt);return Y.createElement(_t,{domain:t.domain,id:t.zAxisId,dataKey:t.dataKey,name:t.name,unit:t.unit,range:t.range,scale:t.scale,type:t.type,allowDuplicatedCategory:M.allowDuplicatedCategory,allowDataOverflow:M.allowDataOverflow,reversed:M.reversed,includeHidden:M.includeHidden})}yt.displayName=`ZAxis`;var bt=[`item`],xt=(0,Y.forwardRef)((e,t)=>Y.createElement(he,{chartName:`ScatterChart`,defaultTooltipEventType:`item`,validateTooltipEventTypes:bt,tooltipPayloadSearcher:fe,categoricalChartProps:e,ref:t}));function St({data:e,loading:t}){let{t:n}=s(`analytics`);if(t&&!e)return(0,X.jsx)(`div`,{className:`h-[220px] rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let r={jobs:n(`surfaces.job`),explore:n(`surfaces.exploreSpec`),quick:n(`surfaces.quickSpec`),refine:n(`surfaces.aiEdit`),fileSummaries:n(`surfaces.fileSummary`),smash:n(`surfaces.smash`),loop:n(`surfaces.loop`)},i=e.dailyTimeline.map(e=>({date:e.date.slice(5),[r.jobs]:e.jobsCostUsd,[r.explore]:e.exploreCostUsd,[r.quick]:e.quickCostUsd,[r.refine]:e.aiEditCostUsd,[r.fileSummaries]:e.fileSummaryCostUsd??0,[r.smash]:e.smashCostUsd??0,[r.loop]:e.loopCostUsd??0})),a=e.dailyTimeline.every(e=>e.jobsCostUsd+e.exploreCostUsd+e.quickCostUsd+e.aiEditCostUsd+(e.fileSummaryCostUsd??0)+(e.smashCostUsd??0)+(e.loopCostUsd??0)===0),o=e.dailyTimeline.reduce((e,t)=>e+(t.unpricedCount??0),0),c=a&&o>0,l=!a&&o>0;return(0,X.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,X.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider`,children:n(`timeline.title`)}),(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground/70`,children:l?n(`timeline.costPartiallyUnavailable`,{count:o}):n(`timeline.subtitle`)})]}),c?(0,X.jsx)(`div`,{"data-testid":`timeline-cost-unavailable`,className:`h-40 flex items-center justify-center text-xs text-muted-foreground/70`,children:n(`timeline.costUnavailable`)}):a?(0,X.jsx)(`div`,{className:`h-40 flex items-center justify-center text-xs text-muted-foreground/70`,children:n(`timeline.empty`)}):(0,X.jsx)(`div`,{className:`h-[220px]`,children:(0,X.jsx)(A,{width:`100%`,height:`100%`,children:(0,X.jsxs)(Te,{data:i,margin:{top:10,right:10,left:-8,bottom:0},children:[(0,X.jsx)(pe,{strokeDasharray:`2 4`,stroke:`currentColor`,className:`text-border/30`,vertical:!1}),(0,X.jsx)(ue,{dataKey:`date`,tick:{fontSize:10},stroke:`currentColor`,className:`text-muted-foreground`}),(0,X.jsx)(xe,{tick:{fontSize:10},stroke:`currentColor`,className:`text-muted-foreground`,tickFormatter:e=>`$${e}`}),(0,X.jsx)(P,{contentStyle:{backgroundColor:`var(--popover)`,border:`1px solid var(--border)`,fontSize:11,borderRadius:6},formatter:(e,t)=>[`$${typeof e==`number`?e.toFixed(2):`—`}`,String(t)]}),(0,X.jsx)(U,{dataKey:r.jobs,stackId:`a`,fill:`var(--accent-info, #5fa8d3)`}),(0,X.jsx)(U,{dataKey:r.explore,stackId:`a`,fill:`var(--accent-highlight, #c084fc)`}),(0,X.jsx)(U,{dataKey:r.quick,stackId:`a`,fill:`var(--accent-secondary, #f7768e)`}),(0,X.jsx)(U,{dataKey:r.refine,stackId:`a`,fill:`var(--accent-success, #50fa7b)`}),(0,X.jsx)(U,{dataKey:r.fileSummaries,stackId:`a`,fill:`var(--accent-warning, #f1fa8c)`}),(0,X.jsx)(U,{dataKey:r.smash,stackId:`a`,fill:`var(--accent-highlight, #c084fc)`}),(0,X.jsx)(U,{dataKey:r.loop,stackId:`a`,fill:`var(--accent-primary, #7aa2f7)`})]})})})]})}function Ct(e){return e==null?`—`:e<.005?`$${e.toFixed(4)}`:e<1?`$${e.toFixed(3)}`:`$${e.toFixed(2)}`}function wt(e){return e==null?`—`:e<1e3?`${e} ms`:e<6e4?`${(e/1e3).toFixed(1)}s`:`${Math.floor(e/6e4)}m ${Math.floor(e%6e4/1e3)}s`}function Tt({values:e}){let t=Math.max(1e-4,...e);return(0,X.jsx)(`div`,{className:`flex items-end gap-[1px] h-5`,children:e.map((e,n)=>(0,X.jsx)(`div`,{className:`w-[3px] rounded-sm bg-foreground/40`,style:{height:`${Math.max(2,e/t*20)}px`}},n))})}function Et({mode:e,label:t,accentClass:n}){let{t:r}=s(`analytics`),i=e.mode===`explore`&&e.totalRuns<5,a=(e.estimatedCostUsd??0)>0,c=e.avgCostPerSpec==null&&(e.unpricedCount??0)>0;return(0,X.jsxs)(`div`,{className:`flex-1 p-4 first:pr-2 last:pl-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,X.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full ${n}`}),(0,X.jsx)(`span`,{className:`text-xs font-medium uppercase tracking-wider text-muted-foreground`,children:t})]}),i?(0,X.jsxs)(`div`,{className:`py-3`,children:[(0,X.jsx)(`p`,{className:`text-sm text-foreground`,children:r(`quickVsExplore.sparseCta`)}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:r(`quickVsExplore.runsSoFar`,{count:e.totalRuns})})]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`text-3xl font-semibold tabular-nums tracking-tight`,"data-estimated":a?`true`:void 0,title:c?r(`quickVsExplore.costUnavailableTooltip`):a?r(`quickVsExplore.estimatedTooltip`):void 0,children:[a&&e.avgCostPerSpec!=null?`~`:``,Ct(e.avgCostPerSpec)]}),(0,X.jsx)(`div`,{className:`text-[11px] text-muted-foreground mt-0.5`,children:r(c?`quickVsExplore.costUnavailable`:`quickVsExplore.perSpec`)}),(0,X.jsx)(`div`,{className:`mt-3`,children:(0,X.jsx)(Tt,{values:e.sparkline.length>0?e.sparkline:[0]})}),(0,X.jsxs)(`div`,{className:`mt-3 space-y-0.5 text-xs tabular-nums text-muted-foreground`,children:[(0,X.jsx)(`div`,{children:(0,X.jsx)(o,{ns:`analytics`,i18nKey:`quickVsExplore.createdRuns`,values:{created:e.ticketsCreated,runs:e.totalRuns},components:{strong:(0,X.jsx)(`span`,{className:`text-foreground font-medium`})}})}),(0,X.jsx)(`div`,{children:r(`quickVsExplore.avgDuration`,{duration:wt(e.avgDurationMs)})}),(0,X.jsx)(`div`,{className:`truncate`,children:e.dominantModel??`—`})]})]})]})}function Dt({data:e,loading:t}){let{t:n}=s(`analytics`);if(t&&!e)return(0,X.jsx)(`div`,{className:`h-[220px] rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let r=e.byMode.find(e=>e.mode===`quick`),i=e.byMode.find(e=>e.mode===`explore`);if(!r||!i)return null;let a=r.avgCostPerSpec&&i.avgCostPerSpec&&r.avgCostPerSpec>0?i.avgCostPerSpec/r.avgCostPerSpec:null,o=a!==null&&r.totalRuns>=1&&i.totalRuns>=5,c=(r.estimatedCostUsd??0)>0||(i.estimatedCostUsd??0)>0;return(0,X.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40`,children:[(0,X.jsx)(`div`,{className:`px-4 pt-3 pb-1`,children:(0,X.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider`,children:n(`quickVsExplore.title`)})}),(0,X.jsxs)(`div`,{className:`flex divide-x divide-border/40`,children:[(0,X.jsx)(Et,{mode:r,label:n(`quickVsExplore.quick`),accentClass:`bg-accent-secondary`}),(0,X.jsx)(Et,{mode:i,label:n(`quickVsExplore.explore`),accentClass:`bg-accent-highlight`})]}),o&&(0,X.jsx)(`div`,{className:`px-4 pb-3 -mt-1`,children:(0,X.jsx)(`div`,{className:`text-center text-[11px] text-muted-foreground tabular-nums`,children:(0,X.jsxs)(`span`,{className:`px-2`,children:[`━━━━━━ `,n(`quickVsExplore.ratio`,{ratio:a.toFixed(1)}),` ━━━━━━`]})})}),c&&(0,X.jsx)(`div`,{className:`px-4 pb-3 -mt-1`,"data-testid":`quick-vs-explore-estimated-footnote`,children:(0,X.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:n(`quickVsExplore.estimatedFootnote`)})})]})}function Ot(e){return e<.005&&e>0?`$${e.toFixed(4)}`:e<1?`$${e.toFixed(3)}`:`$${e.toFixed(2)}`}function kt(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function At({data:e,loading:t}){let{t:n}=s(`analytics`),r=e?.agentMissions;if(t||!r||r.summary.turns===0)return null;let{summary:a,topConversations:o}=r,c=a.estimatedCostUsd>0,l=a.prevTotalCostUsd>0?(a.totalCostUsd-a.prevTotalCostUsd)/a.prevTotalCostUsd*100:null;return(0,X.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card p-4`,"data-testid":`agent-missions-card`,children:[(0,X.jsxs)(`div`,{className:`mb-3 flex items-center gap-2`,children:[(0,X.jsx)(v,{className:`h-4 w-4 text-accent-highlight`}),(0,X.jsx)(`h3`,{className:`text-sm font-medium`,children:n(`agentMissions.title`)}),(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:n(`agentMissions.subtitle`)})]}),(0,X.jsxs)(`div`,{className:`flex items-baseline gap-3`,children:[(0,X.jsxs)(`span`,{className:`text-3xl font-semibold tabular-nums tracking-tight`,"data-estimated":c?`true`:void 0,title:c?n(`agentMissions.estimatedNote`):void 0,children:[c?`~`:``,Ot(a.totalCostUsd)]}),l!==null&&(0,X.jsxs)(`span`,{className:l>0?`text-xs text-accent-warning`:`text-xs text-accent-success`,children:[l>0?`+`:``,l.toFixed(0),`% `,n(`agentMissions.vsPrev`)]})]}),(0,X.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:n(`agentMissions.turnsAndTokens`,{turns:a.turns,tokens:kt(a.tokensIn+a.tokensOut)})}),o.length>0&&(0,X.jsx)(`ul`,{className:`mt-3 space-y-1 border-t border-border/40 pt-2`,children:o.map(e=>(0,X.jsxs)(`li`,{className:`flex items-center gap-2 text-xs`,children:[(0,X.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-foreground/85`,children:e.title?.trim()||n(`agentMissions.untitled`)}),(0,X.jsxs)(`span`,{className:`shrink-0 text-[10px] text-muted-foreground`,children:[e.turns,` · `,e.lastAt?g(new Date(e.lastAt),{addSuffix:!0,locale:i()}):`—`]}),(0,X.jsxs)(`span`,{className:`shrink-0 tabular-nums font-medium`,children:[e.estimatedCostUsd>0?`~`:``,Ot(e.costUsd)]})]},e.conversationId??`unknown`))})]})}function jt({data:e,loading:t,onSelectModel:n,activeModel:r}){let{t:i}=s(`analytics`);if(t&&!e)return(0,X.jsx)(`div`,{className:`h-[220px] rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let a=e.summary.totalCostUsd,o=e.byModel.slice(0,5),c=o.reduce((e,t)=>e+t.costUsd,0),l=Math.max(0,a-c),u=l>=.005;return(0,X.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,X.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider mb-3`,children:i(`models.title`)}),o.length===0?(0,X.jsx)(`div`,{className:`h-32 flex items-center justify-center text-xs text-muted-foreground/70`,children:i(`models.empty`)}):(0,X.jsxs)(`ul`,{className:`space-y-1.5`,children:[o.map(e=>{let t=a>0?e.costUsd/a*100:0,o=r===e.model,s=(e.estimatedCostUsd??0)>0,c=e.unpricedCount??0,l=Math.max(0,e.count-c),u=e.count>0&&c>0&&l===0,d=l>0&&c>0;return(0,X.jsx)(`li`,{children:(0,X.jsxs)(`button`,{type:`button`,onClick:()=>n(e.model,e.provider),className:`w-full text-left group rounded-md px-2 py-1.5 transition-colors ${o?`bg-accent-highlight/10 ring-1 ring-accent-highlight/30`:`hover:bg-accent/30`}`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between text-[12px] mb-1 tabular-nums`,children:[(0,X.jsx)(`span`,{className:`truncate font-medium`,children:e.model}),(0,X.jsx)(`span`,{className:`text-muted-foreground`,"data-testid":u?`model-cost-unavailable`:void 0,title:u?i(`models.costUnavailableTooltip`):d?i(`models.costPartiallyUnavailableTooltip`):s?i(`models.estimatedTooltip`):void 0,children:u?i(`models.costUnavailableWithRuns`,{count:e.count}):(0,X.jsxs)(X.Fragment,{children:[s?`~`:``,`$`,e.costUsd.toFixed(2),` · `,e.count,d&&(0,X.jsx)(`span`,{className:`ml-1 italic`,children:i(`models.costPartiallyUnavailable`,{count:c})})]})})]}),(0,X.jsx)(`div`,{className:`h-1.5 rounded-full bg-background-deep overflow-hidden`,children:(0,X.jsx)(`div`,{className:`h-full ${o?`bg-accent-highlight`:`bg-foreground/40 group-hover:bg-foreground/60`} transition-colors`,style:{width:`${t}%`}})})]})},`${e.provider??`claude`}:${e.model}`)}),u&&(0,X.jsx)(`li`,{"data-testid":`model-others`,children:(0,X.jsxs)(`div`,{className:`w-full rounded-md px-2 py-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between text-[12px] mb-1 tabular-nums`,children:[(0,X.jsx)(`span`,{className:`truncate font-medium text-muted-foreground`,children:i(`models.others`)}),(0,X.jsxs)(`span`,{className:`text-muted-foreground`,children:[`$`,l.toFixed(2)]})]}),(0,X.jsx)(`div`,{className:`h-1.5 rounded-full bg-background-deep overflow-hidden`,children:(0,X.jsx)(`div`,{className:`h-full bg-foreground/25`,style:{width:`${a>0?l/a*100:0}%`}})})]})})]})]})}var Mt={job:`var(--accent-info, #5fa8d3)`,"quick-spec":`var(--accent-secondary, #f7768e)`,"explore-spec":`var(--accent-highlight, #c084fc)`,"ai-edit":`var(--accent-success, #50fa7b)`,smash:`var(--accent-highlight, #c084fc)`,"file-summary":`var(--accent-warning, #f1fa8c)`,loop:`var(--accent-primary, #7aa2f7)`,"chat-sidebar":`var(--accent-info, #5fa8d3)`,"spec-launcher":`var(--accent-secondary, #f7768e)`,proposal:`var(--accent-highlight, #c084fc)`,"agent-studio":`var(--accent-success, #50fa7b)`,setup:`var(--accent-primary, #7aa2f7)`},Nt=Object.keys(f);function Pt({data:e,loading:t,onSelectPoint:n}){let{t:r}=s(`analytics`);if(t&&!e)return(0,X.jsx)(`div`,{className:`h-[260px] rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let i=Nt,a=i.map(t=>({surface:t,points:e.scatter.filter(e=>e.surface===t).map(e=>({id:e.id,x:e.numTurns??Math.round((e.durationMs??0)/1e3),y:e.costUsd,surface:t,ticketId:e.ticketId,startedAt:e.startedAt,raw:e}))})),o=e.scatter.length===0,c=e.summary.unpricedRuns??0,l=o&&c>0,u=!o&&c>0,d=e.scatterTruncated===!0,p=e.scatterTotal??e.scatter.length;return(0,X.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,X.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider`,children:r(`scatter.title`)}),(0,X.jsx)(`div`,{className:`flex flex-wrap items-center gap-2 text-[10px]`,children:i.map(e=>(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,X.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full`,style:{background:Mt[e]}}),(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:f[e]})]},e))})]}),d&&!o&&(0,X.jsx)(`div`,{"data-testid":`scatter-truncation-notice`,className:`mb-2 text-[10px] text-accent-warning`,children:r(`scatter.truncated`,{shown:e.scatter.length,total:p})}),u&&(0,X.jsx)(`div`,{"data-testid":`scatter-cost-partial-notice`,className:`mb-2 text-[10px] text-muted-foreground/80 italic`,children:r(`scatter.costPartiallyUnavailable`,{count:c})}),l?(0,X.jsx)(`div`,{"data-testid":`scatter-cost-unavailable`,className:`h-40 flex items-center justify-center text-xs text-muted-foreground/70`,children:r(`scatter.costUnavailable`)}):o?(0,X.jsx)(`div`,{className:`h-40 flex items-center justify-center text-xs text-muted-foreground/70`,children:r(`scatter.empty`)}):(0,X.jsx)(`div`,{className:`h-[260px]`,children:(0,X.jsx)(A,{width:`100%`,height:`100%`,children:(0,X.jsxs)(xt,{margin:{top:10,right:10,left:-8,bottom:5},children:[(0,X.jsx)(pe,{strokeDasharray:`2 4`,stroke:`currentColor`,className:`text-border/30`}),(0,X.jsx)(ue,{type:`number`,dataKey:`x`,name:`turns`,tick:{fontSize:10},stroke:`currentColor`,className:`text-muted-foreground`,label:{value:r(`scatter.turnsLabel`),position:`insideBottomRight`,offset:-2,fontSize:10,fill:`currentColor`}}),(0,X.jsx)(xe,{type:`number`,dataKey:`y`,name:`cost`,tick:{fontSize:10},stroke:`currentColor`,className:`text-muted-foreground`,tickFormatter:e=>`$${e.toFixed(e<1?2:0)}`}),(0,X.jsx)(yt,{range:[40,80]}),(0,X.jsx)(P,{cursor:{strokeDasharray:`3 3`},contentStyle:{backgroundColor:`var(--popover)`,border:`1px solid var(--border)`,fontSize:11,borderRadius:6},formatter:(e,t)=>{let n=String(t);return n===`cost`&&typeof e==`number`?[`$${e.toFixed(3)}`,r(`scatter.costLabel`)]:[String(e),n===`turns`?r(`scatter.turnsLabel`):n]}}),a.map(e=>(0,X.jsx)(gt,{data:e.points,fill:Mt[e.surface],onClick:e=>{let t=e;t?.raw&&n(t.raw)}},e.surface))]})})})]})}function Ft({data:e,loading:t,onSelectTicket:n}){let{t:r}=s(`analytics`);if(t&&!e)return(0,X.jsx)(`div`,{className:`h-40 rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let i=e.topTickets;return(0,X.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,X.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider mb-3`,children:r(`topTickets.title`)}),i.length===0?(0,X.jsx)(`div`,{className:`h-32 flex items-center justify-center text-xs text-muted-foreground/70`,children:r(`topTickets.empty`)}):(0,X.jsx)(`ul`,{className:`divide-y divide-border/30`,children:i.map((e,t)=>{let i=Object.entries(e.bySurface).filter(([,e])=>e.count>0).map(([e,t])=>r(`topTickets.breakdownItem`,{n:t.count,label:f[e].toLowerCase()})).join(` + `),a=e.isUnattributed,o=a?r(`topTickets.unattributed`):e.ticketTitle?`#${e.ticketId} ${e.ticketTitle}`:r(`topTickets.deletedTicket`,{id:e.ticketId}),s=!e.ticketTitle&&!a?`opacity-50`:``,c=e.unpricedCount??0,l=e.totalRuns>0&&c===e.totalRuns,u=c>0&&!l;return(0,X.jsx)(`li`,{children:(0,X.jsxs)(`button`,{type:`button`,onClick:()=>n(e.ticketId),className:`w-full text-left flex items-center justify-between gap-3 py-2 px-1 hover:bg-accent/30 rounded transition-colors ${s}`,disabled:a,children:[(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`div`,{className:`text-sm truncate`,children:o}),(0,X.jsx)(`div`,{className:`text-[11px] text-muted-foreground truncate`,children:i||`—`})]}),(0,X.jsxs)(`div`,{className:`text-right tabular-nums`,children:[(0,X.jsx)(`div`,{className:`text-sm font-medium`,title:l?r(`topTickets.costUnavailableTooltip`):u?r(`topTickets.costPartiallyUnavailableTooltip`):void 0,children:l?r(`topTickets.costUnavailable`):`$${e.totalCostUsd.toFixed(2)}`}),u&&(0,X.jsx)(`div`,{className:`text-[10px] text-muted-foreground italic`,children:r(`topTickets.costPartiallyUnavailable`,{count:c})}),(0,X.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:r(`runs`,{count:e.totalRuns})})]})]})},`${e.ticketId??`u`}-${t}`)})})]})}var It={claude:`Claude`,codex:`Codex`,gemini:`Gemini`,kimi:`Kimi`};function Lt(e){return It[e]??e}function Rt(e){return e==null?`—`:e<.005?`$${e.toFixed(4)}`:`$${e.toFixed(2)}`}function zt(e){return e==null?`—`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function Bt(e){return e.surface_ref_id?.startsWith(`contract-refine:`)?!0:e.surface===`explore-spec`&&e.ticket_id!=null&&e.conversation_id!=null&&e.surface_ref_id===e.conversation_id&&e.model==null}function Vt(e){let t=new Map;for(let n of e)n.model&&(n.conversation_id&&t.set(`conversation:${n.conversation_id}`,n.model),n.ticket_id!=null&&n.surface===`explore-spec`&&t.set(`ticket:${n.ticket_id}:explore-spec`,n.model),n.ticket_id!=null&&n.surface===`quick-spec`&&t.set(`ticket:${n.ticket_id}:quick-spec`,n.model));return t}function Ht(e,t){if(e.model)return e.model;if(!Bt(e))return null;if(e.conversation_id){let n=t.get(`conversation:${e.conversation_id}`);if(n)return n}return e.ticket_id==null?null:t.get(`ticket:${e.ticket_id}:${e.surface}`)??null}function Ut({rows:e,loading:t,truncated:n,totalAvailable:r,tableFilters:i,onTableFiltersChange:a}){let{t:o}=s(`analytics`),[c,l]=(0,Y.useState)(null),u=Vt(e),d=new Set(e.map(e=>e.provider??`claude`)).size>1,p=n||r>e.length;return(0,X.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 mb-3`,children:[(0,X.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider`,children:o(`table.title`)}),(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-[11px]`,children:[(0,X.jsxs)(`select`,{value:i.status??``,onChange:e=>a({...i,status:e.target.value||void 0}),className:`h-7 px-2 rounded-md bg-background-deep border border-border/60 text-xs`,"aria-label":o(`table.statusFilterAria`),children:[(0,X.jsx)(`option`,{value:``,children:o(`table.allStatus`)}),(0,X.jsx)(`option`,{value:`success`,children:o(`table.success`)}),(0,X.jsx)(`option`,{value:`failed`,children:o(`table.failed`)}),(0,X.jsx)(`option`,{value:`aborted`,children:o(`table.aborted`)})]}),(0,X.jsx)(`input`,{type:`number`,step:`0.01`,min:`0`,placeholder:o(`table.minCostPlaceholder`),value:i.minCostUsd??``,onChange:e=>{let t=e.target.value===``?void 0:parseFloat(e.target.value);a({...i,minCostUsd:Number.isNaN(t)?void 0:t})},className:`h-7 w-24 px-2 rounded-md bg-background-deep border border-border/60 text-xs tabular-nums`,"aria-label":o(`table.minCostFilterAria`)})]})]}),t?(0,X.jsx)(`div`,{className:`h-32 rounded bg-card/30 animate-pulse`}):e.length===0?(0,X.jsx)(`div`,{className:`h-32 flex items-center justify-center text-xs text-muted-foreground/70`,children:o(`table.empty`)}):(0,X.jsx)(`div`,{className:`overflow-x-auto`,children:(0,X.jsxs)(`table`,{className:`w-full text-[12px] tabular-nums`,children:[(0,X.jsx)(`thead`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:(0,X.jsxs)(`tr`,{className:`text-left`,children:[(0,X.jsx)(`th`,{className:`font-medium px-2 py-2`,children:o(`table.colSurface`)}),(0,X.jsx)(`th`,{className:`font-medium px-2 py-2`,children:o(`table.colTicket`)}),(0,X.jsx)(`th`,{className:`font-medium px-2 py-2 text-right`,children:o(`table.colCost`)}),(0,X.jsx)(`th`,{className:`font-medium px-2 py-2 text-right`,children:o(`table.colTurns`)}),(0,X.jsx)(`th`,{className:`font-medium px-2 py-2 text-right`,children:o(`table.colTokens`)}),(0,X.jsx)(`th`,{className:`font-medium px-2 py-2`,children:o(`table.colModel`)}),d&&(0,X.jsx)(`th`,{className:`font-medium px-2 py-2`,children:o(`table.colProvider`)}),(0,X.jsx)(`th`,{className:`font-medium px-2 py-2`,children:o(`table.colStatus`)}),(0,X.jsx)(`th`,{className:`font-medium px-2 py-2`,children:o(`table.colStarted`)})]})}),(0,X.jsx)(`tbody`,{children:e.map(e=>{let t=e.surface,n=m[t],r=(e.tokens_in??0)+(e.tokens_out??0)+(e.tokens_cache_read??0)+(e.tokens_cache_create??0),i=Bt(e),a=i?o(`table.contractLayer`):f[t],s=Ht(e,u);return(0,X.jsxs)(`tr`,{onClick:()=>l(c===e.id?null:e.id),className:`border-t border-border/30 hover:bg-accent/30 cursor-pointer`,children:[(0,X.jsx)(`td`,{className:`px-2 py-2`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 px-2 h-5 rounded-full text-[10px] font-medium ${n.bg} ${n.text}`,children:[(0,X.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full ${n.dot}`}),a]})}),(0,X.jsx)(`td`,{className:`px-2 py-2 max-w-[260px]`,children:e.ticket_id==null?e.ticket_title?(0,X.jsx)(`span`,{className:`truncate block text-muted-foreground/90 italic`,title:o(`table.provisionalTitleTooltip`),children:e.ticket_title}):(0,X.jsx)(`span`,{className:`text-muted-foreground/70`,children:`—`}):(0,X.jsxs)(`span`,{className:`truncate block`,children:[`#`,e.ticket_id,` `,i?(0,X.jsx)(`span`,{className:`text-muted-foreground/90`,children:o(`table.contractLayerRefinement`)}):e.ticket_title??(0,X.jsx)(`span`,{className:`text-muted-foreground/70 italic`,children:o(`table.deleted`)})]})}),(0,X.jsx)(`td`,{className:`px-2 py-2 text-right font-medium`,children:e.total_cost_usd_estimated===1&&e.total_cost_usd!=null?(0,X.jsxs)(`span`,{title:o(`table.estimatedCostTooltip`),className:`text-muted-foreground/90`,children:[`~`,Rt(e.total_cost_usd)]}):Rt(e.total_cost_usd)}),(0,X.jsx)(`td`,{className:`px-2 py-2 text-right`,children:zt(e.num_turns)}),(0,X.jsx)(`td`,{className:`px-2 py-2 text-right`,children:r>0?zt(r):`—`}),(0,X.jsxs)(`td`,{className:`px-2 py-2 max-w-[180px] truncate`,children:[s??`—`,s&&!e.model?(0,X.jsx)(`span`,{className:`ml-1 text-[10px] text-muted-foreground/70`,children:o(`table.inferred`)}):null]}),d&&(0,X.jsx)(`td`,{className:`px-2 py-2 text-muted-foreground`,children:Lt(e.provider??`claude`)}),(0,X.jsxs)(`td`,{className:`px-2 py-2`,children:[e.status===`success`?(0,X.jsx)(`span`,{className:`text-accent-success/90`,children:`●`}):e.status===`failed`?(0,X.jsx)(`span`,{className:`text-accent-warning`,children:`⚠`}):(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`○`}),(0,X.jsx)(`span`,{className:`ml-1 text-muted-foreground`,children:o(`table.statusValue.${e.status}`)})]}),(0,X.jsx)(`td`,{className:`px-2 py-2 text-muted-foreground`,children:e.started_at.slice(0,16).replace(`T`,` `)})]},e.id)})})]})}),p&&e.length>0&&(0,X.jsx)(`div`,{className:`mt-2 text-[11px] text-muted-foreground/80`,children:o(`table.truncated`,{shown:e.length,total:r.toLocaleString()})})]})}var Wt=[{value:`7d`,labelKey:`periods.d7`},{value:`30d`,labelKey:`periods.d30`},{value:`90d`,labelKey:`periods.d90`},{value:`all`,labelKey:`periods.all`}],Gt=[{value:`all`,labelKey:`page.all`},{value:`job`,labelKey:`surfaces.job`},{value:`explore-spec`,labelKey:`surfaces.exploreSpec`},{value:`quick-spec`,labelKey:`surfaces.quickSpec`},{value:`ai-edit`,labelKey:`surfaces.aiEdit`},{value:`smash`,labelKey:`surfaces.smash`},{value:`file-summary`,labelKey:`surfaces.fileSummary`},{value:`loop`,labelKey:`surfaces.loop`}];function Kt(e){let t=new URLSearchParams;return e.period&&t.set(`period`,e.period),e.from&&t.set(`from`,e.from),e.to&&t.set(`to`,e.to),e.surface&&e.surface.length>0&&t.set(`surface`,e.surface.join(`,`)),e.provider&&e.provider.length>0&&t.set(`provider`,e.provider.join(`,`)),e.model&&e.model.length>0&&t.set(`model`,e.model.join(`,`)),e.modelKeys&&e.modelKeys.length>0&&e.model&&e.modelKeys.length===e.model.length&&t.set(`modelProvider`,e.modelKeys.map(e=>e.provider).join(`,`)),e.status&&t.set(`status`,e.status),typeof e.minCostUsd==`number`&&t.set(`minCostUsd`,String(e.minCostUsd)),typeof e.ticketId==`number`&&t.set(`ticketId`,String(e.ticketId)),typeof e.tzOffsetMinutes==`number`&&t.set(`tzOffsetMinutes`,String(e.tzOffsetMinutes)),e.sortBy&&t.set(`sortBy`,e.sortBy),t.toString()}function qt(){let{t:e}=s(`analytics`),{activeProjectId:t,projects:n}=d(),[i,o]=r(),c=n.find(e=>e.id===t),f=c?u(c):[`claude`],p=f.length>1,m=i.get(`period`)??`30d`,h=(i.get(`surface`)??``).split(`,`).filter(Boolean),g=(i.get(`provider`)??``).split(`,`).filter(Boolean),v=i.get(`ticketId`),x=(i.get(`model`)??``).split(`,`).filter(Boolean),S=(i.get(`modelProvider`)??``).split(`,`).filter(Boolean),C=x.length>0&&x.length===S.length?x.map((e,t)=>({provider:S[t],model:e})):void 0,ee=(0,Y.useMemo)(()=>-new Date().getTimezoneOffset(),[]),[w,T]=(0,Y.useState)({period:m,surface:h.length>0?h:void 0,provider:g.length>0?g:void 0,ticketId:v?Number(v):void 0,model:x.length>0?x:void 0,modelKeys:C,tzOffsetMinutes:ee}),[E,D]=(0,Y.useState)(null),[O,k]=(0,Y.useState)(!0),[A,j]=(0,Y.useState)(null),[M,N]=(0,Y.useState)({}),[P,F]=(0,Y.useState)(null),[I,te]=(0,Y.useState)(`recency`),L=(0,Y.useRef)(new Map),R=(0,Y.useRef)(0);(0,Y.useEffect)(()=>{let e=new URLSearchParams;e.set(`period`,w.period),w.surface&&w.surface.length>0&&e.set(`surface`,w.surface.join(`,`)),w.provider&&w.provider.length>0&&e.set(`provider`,w.provider.join(`,`)),w.ticketId&&e.set(`ticketId`,String(w.ticketId)),w.model&&w.model.length>0&&(e.set(`model`,w.model.join(`,`)),w.modelKeys&&w.modelKeys.length===w.model.length&&e.set(`modelProvider`,w.modelKeys.map(e=>e.provider).join(`,`))),o(e,{replace:!0})},[w.period,w.surface,w.provider,w.ticketId,w.model,w.modelKeys,o]);let z=(0,Y.useCallback)(async()=>{if(!t)return;let e=++R.current;j(null);let n=`${t}:${Kt(w)}`,r=L.current.get(n);r?(D(r),k(!1)):k(!0);try{let t=await fetch(`${l()}/spending?${Kt(w)}`);if(!t.ok)throw Error(`HTTP ${t.status}`);if(e!==R.current)return;let r=await t.json();L.current.set(n,r),D(r),k(!1)}catch(t){if(e!==R.current)return;j(t.message),k(!1)}},[t,w]),B=(0,Y.useRef)(0),V=(0,Y.useCallback)(async()=>{if(!t)return;let e=++B.current,n={...w};M.model&&(n.model=[M.model],n.modelKeys=void 0),M.status&&(n.status=M.status),typeof M.minCostUsd==`number`&&(n.minCostUsd=M.minCostUsd),n.sortBy=I;try{let t=await fetch(`${l()}/invocations?${Kt(n)}&limit=100`);if(!t.ok)throw Error(`HTTP ${t.status}`);let r=await t.json();if(e!==B.current)return;F(r)}catch{if(e!==B.current)return;F(null)}},[t,w,M,I]),ne=(0,Y.useRef)(t);(0,Y.useEffect)(()=>{ne.current!==t&&(ne.current=t,D(null),F(null),k(!0))},[t]),(0,Y.useEffect)(()=>{z()},[z]),(0,Y.useEffect)(()=>{V()},[V]);let H=(0,Y.useRef)(null),U=a();(0,Y.useEffect)(()=>{let e=`analytics-spending`;return U.registerHandler(e,e=>{let n=e;n.type===`spending.invalidated`&&n.projectId===t&&(H.current&&clearTimeout(H.current),H.current=setTimeout(()=>{L.current.clear(),z(),V()},500))}),()=>{U.unregisterHandler(e),H.current&&clearTimeout(H.current)}},[U,t,z,V]);function re(e){if(e===`all`){T(e=>({...e,surface:void 0}));return}T(t=>{let n=t.surface??[],r=n.includes(e)?n.filter(t=>t!==e):[...n,e];return{...t,surface:r.length>0?r:void 0}})}let ie=(0,Y.useCallback)((e,t)=>{T(n=>{if(n.model?.length===1&&n.model[0]===e&&(t===void 0||n.modelKeys?.length===1&&n.modelKeys[0].provider===t))return{...n,model:void 0,modelKeys:void 0};let r=(E?.byModel??[]).filter(n=>n.model===e&&(t===void 0||n.provider===t)).map(e=>({provider:e.provider,model:e.model})),i=r.length>0?r.map(e=>e.model):[e];return{...n,model:i,modelKeys:r.length>0?r:void 0}})},[E]);function ae(){T(e=>({...e,model:void 0,modelKeys:void 0}))}function oe(e){if(e===`all`){T(e=>({...e,provider:void 0}));return}T(t=>{let n=t.provider??[],r=n.includes(e)?n.filter(t=>t!==e):[...n,e];return{...t,provider:r.length>0?r:void 0}})}let W=w.surface,se=!W||W.length===0,G=w.provider,ce=!G||G.length===0,le=(0,Y.useMemo)(()=>{let e={period:w.period};return w.surface&&w.surface.length>0&&(e.surface=w.surface.join(`,`)),w.provider&&w.provider.length>0&&(e.provider=w.provider.join(`,`)),w.ticketId&&(e.ticketId=String(w.ticketId)),e},[w]),ue=E?E.summary.totalRuns===0:!1;return(0,X.jsxs)(`div`,{className:`flex flex-col gap-6 p-4 pb-12`,children:[(0,X.jsxs)(`div`,{className:`sticky top-0 z-10 -mx-4 px-4 py-3 bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/80 border-b border-border/40`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,X.jsx)(`h1`,{className:`text-base font-semibold tracking-tight`,children:e(`page.title`)}),w.ticketId&&(0,X.jsx)(`button`,{type:`button`,onClick:()=>T(e=>({...e,ticketId:void 0})),className:`inline-flex items-center gap-1 h-6 px-2 rounded-full text-[11px] font-medium bg-accent-highlight/15 text-accent-highlight ring-1 ring-accent-highlight/30 hover:bg-accent-highlight/25`,children:e(`page.ticketChip`,{id:w.ticketId})}),w.model&&w.model.length>0&&(0,X.jsxs)(`button`,{type:`button`,"data-testid":`analytics-model-chip`,onClick:ae,title:e(`page.clearModelFilter`),className:`inline-flex items-center gap-1 h-6 px-2 rounded-full text-[11px] font-medium bg-accent-highlight/15 text-accent-highlight ring-1 ring-accent-highlight/30 hover:bg-accent-highlight/25`,children:[e(`page.modelChip`,{model:w.model[0]}),(0,X.jsx)(`span`,{"aria-hidden":!0,className:`opacity-70`,children:`×`})]})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`div`,{className:`flex items-center gap-1 rounded-md border border-border/60 bg-card/40 p-0.5`,children:Wt.map(t=>(0,X.jsx)(`button`,{type:`button`,onClick:()=>T(e=>({...e,period:t.value})),className:`px-2.5 h-6 rounded text-[11px] font-medium transition-colors ${w.period===t.value?`bg-accent text-foreground`:`text-muted-foreground hover:text-foreground`}`,children:e(t.labelKey)},t.value))}),(0,X.jsx)(b,{baseUrl:`${l()}/analytics/export`,params:le,disabled:ue}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>{L.current.clear(),z(),V()},className:`h-7 w-7 inline-flex items-center justify-center rounded-md border border-border/60 bg-card/50 text-muted-foreground hover:text-foreground hover:bg-accent/60`,title:e(`common:actions.refresh`),children:(0,X.jsx)(y,{className:`w-3 h-3`})})]})]}),(0,X.jsx)(`div`,{className:`mt-3 flex flex-wrap items-center gap-1.5`,children:Gt.map(t=>(0,X.jsx)(`button`,{type:`button`,onClick:()=>re(t.value),className:`h-7 px-3 rounded-full text-[11px] font-medium transition-all ${(t.value===`all`?se:W?.includes(t.value)??!1)?`bg-foreground/10 text-foreground ring-1 ring-foreground/20`:`text-muted-foreground hover:text-foreground hover:bg-accent/40`}`,children:e(t.labelKey)},t.value))}),p&&(0,X.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-1.5`,"data-testid":`analytics-provider-chips`,children:[(0,X.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-muted-foreground/70 mr-1`,children:e(`page.engine`)}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>oe(`all`),className:`h-7 px-3 rounded-full text-[11px] font-medium transition-all ${ce?`bg-foreground/10 text-foreground ring-1 ring-foreground/20`:`text-muted-foreground hover:text-foreground hover:bg-accent/40`}`,children:e(`page.all`)}),f.map(e=>(0,X.jsx)(`button`,{type:`button`,onClick:()=>oe(e),className:`h-7 px-3 rounded-full text-[11px] font-medium transition-all ${G?.includes(e)??!1?`bg-foreground/10 text-foreground ring-1 ring-foreground/20`:`text-muted-foreground hover:text-foreground hover:bg-accent/40`}`,children:_(e)},e))]})]}),A&&(0,X.jsxs)(`div`,{className:`rounded-lg border border-accent-warning/30 bg-accent-warning/10 p-4 flex items-center justify-between`,children:[(0,X.jsx)(`p`,{className:`text-sm text-accent-warning`,children:e(`page.failedToLoad`,{error:A})}),(0,X.jsxs)(`button`,{onClick:()=>z(),className:`flex items-center gap-1.5 h-7 px-3 rounded-md text-xs text-accent-warning border border-accent-warning/30 hover:bg-accent-warning/10`,children:[(0,X.jsx)(y,{className:`w-3 h-3`}),e(`common:actions.retry`)]})]}),(0,X.jsx)(Ie,{data:E,loading:O,period:w.period}),(0,X.jsx)(He,{data:E,loading:O}),(0,X.jsx)(St,{data:E,loading:O}),(0,X.jsx)(At,{data:E,loading:O}),(0,X.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4`,children:[(0,X.jsx)(Dt,{data:E,loading:O}),(0,X.jsx)(jt,{data:E,loading:O,onSelectModel:ie,activeModel:w.model?.[0]})]}),(0,X.jsx)(Pt,{data:E,loading:O,onSelectPoint:e=>{N(e=>({...e})),T(t=>({...t,ticketId:e.ticketId??void 0}))}}),(0,X.jsx)(Ft,{data:E,loading:O,onSelectTicket:e=>T(t=>({...t,ticketId:e??void 0}))}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-end gap-1.5`,"data-testid":`analytics-table-sort`,children:[(0,X.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-muted-foreground/70 mr-1`,children:e(`table.sortLabel`)}),[`recency`,`cost`].map(t=>(0,X.jsx)(`button`,{type:`button`,"data-testid":`analytics-table-sort-${t}`,"aria-pressed":I===t,onClick:()=>te(t),className:`h-6 px-2.5 rounded-full text-[11px] font-medium transition-all ${I===t?`bg-foreground/10 text-foreground ring-1 ring-foreground/20`:`text-muted-foreground hover:text-foreground hover:bg-accent/40`}`,children:e(t===`recency`?`table.sortRecency`:`table.sortCost`)},t))]}),(0,X.jsx)(Ut,{rows:P?.rows??[],loading:O&&!P,truncated:(P?.truncated??!1)||(P?.totalAvailable??0)>(P?.rows.length??0),totalAvailable:P?.totalAvailable??0,tableFilters:M,onTableFiltersChange:N})]})]})}export{qt as default};
|
|
1
|
+
import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-zu2_FqZY.js";import{f as r}from"./chunk-KS7C4IRE-DEKu087k.js";import{m as i,r as a}from"./useSharedWebSocket-DbGL_YOt.js";import{t as o}from"./Trans-mjFZpHw1.js";import{n as s,t as c}from"./createLucideIcon-Bjbbp_KS.js";import{a as l,n as u,r as d}from"./useDesktop-gVGoWWiY.js";import{n as f,r as p,t as m}from"./spending-DXOcv1tn.js";import{t as h}from"./clsx-CjueKrWZ.js";import{t as g}from"./formatDistanceToNow-BIL-HxGy.js";import{r as _}from"./provider-capabilities-B-wOHfLP.js";import{Ft as v,ft as y}from"./index-UnaJTMIy.js";import{t as b}from"./ExportDropdown-DczgU4at.js";import{A as x,B as S,C,D as ee,E as w,F as T,G as E,H as D,I as O,J as k,K as A,L as j,M,N,O as P,P as F,Q as I,R as te,S as L,T as R,V as z,X as B,Z as V,_ as ne,_t as H,a as U,at as re,b as ie,c as ae,ct as oe,et as W,f as se,g as G,gt as ce,h as le,i as ue,j as de,k as fe,l as pe,lt as K,m as me,n as he,nt as ge,o as _e,ot as ve,p as ye,pt as q,q as be,r as xe,rt as Se,s as Ce,st as we,t as Te,tt as Ee,ut as J,v as De,x as Oe,y as ke,z as Ae}from"./BarChart-nBOMNfiy.js";var je=c(`arrow-down-right`,[[`path`,{d:`m7 7 10 10`,key:`1fmybs`}],[`path`,{d:`M17 7v10H7`,key:`6fjiku`}]]),Y=e(t(),1),X=n();function Me(e){return e>=100?`$${e.toFixed(0)}`:e>=10?`$${e.toFixed(1)}`:`$${e.toFixed(2)}`}function Ne(e){return e>=1e3?`$${(e/1e3).toFixed(1)}k`:`$${e.toFixed(2)}`}function Pe(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:`${e}`}var Fe=[`job`,`explore-spec`,`quick-spec`,`ai-edit`,`chat-sidebar`,`spec-launcher`,`proposal`,`agent-studio`,`setup`,`smash`,`file-summary`,`loop`];function Ie({data:e,loading:t,period:n}){let{t:r}=s(`analytics`),[i,a]=(0,Y.useState)(0),o=(0,Y.useRef)(0),c=(0,Y.useRef)(null),l=(0,Y.useRef)(0);if((0,Y.useEffect)(()=>{if(!e)return;let t=e.summary.totalCostUsd,n=++l.current;if(c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),o.current===0&&t>0){let e=performance.now(),r=i=>{if(n!==l.current)return;let o=Math.min(1,(i-e)/600),s=1-(1-o)**3;a(0+(t-0)*s),o<1?c.current=requestAnimationFrame(r):c.current=null};c.current=requestAnimationFrame(r)}else a(t);return o.current=t,()=>{c.current!==null&&(cancelAnimationFrame(c.current),c.current=null)}},[e]),t&&!e)return(0,X.jsx)(`div`,{className:`h-44 rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let u=e.summary.totalCostUsd,d=e.summary.totalRuns,h=e.summary.totalTokens,g=e.summary.totalEstimatedCostUsd??0,_=typeof e.summary.pricedRuns==`number`||typeof e.summary.unpricedRuns==`number`,v=e.summary.unpricedRuns??0,y=e.summary.pricedRuns??(_?Math.max(0,d-v):d),b=_&&d>0&&y===0&&v>0,x=y>0&&v>0,S=typeof e.summary.usageReportedRuns==`number`||typeof e.summary.usageUnavailableRuns==`number`,C=e.summary.usageUnavailableRuns??0,ee=e.summary.usageReportedRuns??(S?Math.max(0,d-C):d),w=S&&d>0&&ee===0&&C>0,T=ee>0&&C>0,E=v>0?null:e.summary.deltaPct,D=e.trackingStartedAt,O=g>0,k=e.bySurface.map(e=>e.surface).filter(e=>!Fe.includes(e)),A=[...Fe,...k].map(t=>{let n=e.bySurface.find(e=>e.surface===t);return{surface:t,costUsd:n?.costUsd??0,count:n?.count??0}}),j=n?r(`windowLabels.${n}`):null;return(0,X.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-gradient-to-br from-card/80 to-card/40 p-5`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-end justify-between gap-3 mb-4`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`div`,{className:`text-[11px] uppercase tracking-wider text-muted-foreground mb-1 flex items-center gap-1.5`,children:[(0,X.jsx)(`span`,{children:r(`hero.spending`)}),j&&(0,X.jsxs)(`span`,{"data-testid":`hero-window-label`,className:`normal-case tracking-normal text-muted-foreground/70 font-normal`,children:[`· `,j]})]}),(0,X.jsxs)(`div`,{className:`flex items-baseline gap-3`,children:[(0,X.jsx)(`div`,{className:`text-5xl font-semibold tabular-nums tracking-tight`,"data-testid":b?`hero-cost-unavailable`:void 0,title:b?r(`hero.costUnavailableTooltip`):void 0,children:b?`—`:Ne(i)}),E!==null&&(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 text-xs font-medium ${E>=0?`text-accent-warning`:`text-accent-success`}`,children:[E>=0?(0,X.jsx)(p,{className:`w-3 h-3`}):(0,X.jsx)(je,{className:`w-3 h-3`}),r(`hero.vsPrev`,{pct:Math.abs(E).toFixed(0)})]})]}),(0,X.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-1 tabular-nums flex items-center gap-2`,children:[(0,X.jsx)(`span`,{children:r(`hero.invocations`,{count:d})}),w?(0,X.jsx)(`span`,{"data-testid":`hero-usage-unavailable`,className:`text-muted-foreground/80 italic`,title:r(`hero.usageUnavailableTooltip`),children:r(`hero.usageUnavailable`)}):T&&h!=null?(0,X.jsx)(`span`,{className:`text-muted-foreground/80 italic`,title:r(`hero.usagePartiallyUnavailableTooltip`),children:r(`hero.usagePartiallyUnavailable`,{tokens:Pe(h),count:C})}):h!=null&&h>0?(0,X.jsx)(`span`,{className:`text-muted-foreground/80`,title:r(`hero.tokensTooltip`),children:r(`hero.tokens`,{tokens:Pe(h)})}):null,b&&(0,X.jsx)(`span`,{className:`text-muted-foreground/80 italic`,title:r(`hero.costUnavailableTooltip`),children:r(`hero.costUnavailable`)}),x&&(0,X.jsx)(`span`,{"data-testid":`hero-cost-partial`,className:`text-muted-foreground/80 italic`,title:r(`hero.costPartiallyUnavailableTooltip`),children:r(`hero.costPartiallyUnavailable`,{count:v})}),O&&(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground/70 italic`,title:r(`hero.includesEstimatedTooltip`,{amount:Me(g)}),children:r(`hero.includesEstimated`,{amount:Me(g)})})]})]}),d===0&&D&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:r(`hero.trackingStarted`,{date:D.slice(0,10)})})]}),d===0?(0,X.jsxs)(`div`,{className:`rounded-lg border border-dashed border-border/40 p-6 text-center`,children:[(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:r(`hero.emptyState`)}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground/70 mt-1`,children:D?r(`hero.trackingStarted`,{date:D.slice(0,10)}):r(`hero.trackingStartedFallback`)})]}):b?(0,X.jsx)(`div`,{className:`rounded-lg border border-dashed border-border/40 p-4 text-xs text-muted-foreground/80`,children:r(`hero.costUnavailableTooltip`)}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`h-3 w-full rounded-full overflow-hidden bg-background-deep flex`,children:A.map(e=>{let t=u>0?e.costUsd/u*100:0;return t===0?null:(0,X.jsx)(`div`,{className:`h-full ${m[e.surface].dot}`,style:{width:`${t}%`},title:r(`hero.segmentTitle`,{label:f[e.surface],value:Me(e.costUsd)})},e.surface)})}),(0,X.jsx)(`div`,{className:`mt-3 flex flex-wrap items-center gap-x-5 gap-y-1.5 text-xs`,children:A.filter(e=>e.costUsd>0).map(e=>(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 tabular-nums`,children:[(0,X.jsx)(`span`,{className:`w-2 h-2 rounded-full ${m[e.surface].dot}`}),(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:f[e.surface]}),(0,X.jsx)(`span`,{className:`text-foreground font-medium`,children:Me(e.costUsd)}),(0,X.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,X.jsx)(`span`,{className:`text-muted-foreground/80`,children:e.count})]},e.surface))})]})]})}var Le={claude:`Claude`,codex:`Codex`,gemini:`Gemini`,kimi:`Kimi`},Re={claude:`bg-accent-info`,codex:`bg-accent-highlight`,gemini:`bg-accent-success`,kimi:`bg-purple-400`};function ze(e){return e>=100?`$${e.toFixed(0)}`:e>=10?`$${e.toFixed(1)}`:e>=.01?`$${e.toFixed(2)}`:`$${e.toFixed(4)}`}function Be(e){return Le[e]??e}function Ve(e){return Re[e]??`bg-accent-secondary`}function He({data:e,loading:t}){let{t:n}=s(`analytics`);if(t&&!e)return(0,X.jsx)(`div`,{className:`h-32 rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e||e.byProvider.length===0||e.byProvider.length===1)return null;let r=e.byProvider.reduce((e,t)=>e+t.costUsd+t.estimatedCostUsd,0),i=e.byProvider.some(e=>typeof e.unpricedCount==`number`?e.unpricedCount>0:e.count>0&&e.costUsd===0&&e.estimatedCostUsd===0);return(0,X.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,X.jsx)(`div`,{className:`flex items-baseline justify-between mb-3`,children:(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`text-[11px] uppercase tracking-wider text-muted-foreground`,children:n(`providerCard.title`)}),(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground/70 mt-0.5`,children:(0,X.jsx)(o,{ns:`analytics`,i18nKey:`providerCard.description`,components:{tilde:(0,X.jsx)(`span`,{className:`font-medium`})}})})]})}),r===0&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:n(i?`providerCard.costUnavailableTooltip`:`providerCard.noCost`)}),r>0&&(0,X.jsx)(X.Fragment,{children:(0,X.jsx)(`div`,{className:`h-2 w-full rounded-full overflow-hidden bg-background-deep flex mb-3`,children:e.byProvider.map(e=>{let t=e.costUsd+e.estimatedCostUsd,i=r>0?t/r*100:0;if(i===0)return null;let a=`${e.costUsd===0&&e.estimatedCostUsd>0?`~`:``}${ze(t)}`;return(0,X.jsx)(`div`,{className:`h-full ${Ve(e.provider)}`,style:{width:`${i}%`},title:n(`providerCard.segmentTitle`,{label:Be(e.provider),value:a,count:e.count})},e.provider)})})}),(0,X.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2 ${r>0?``:`mt-3`}`,children:e.byProvider.map(e=>(0,X.jsx)(Ue,{entry:e},e.provider))})]})}function Ue({entry:e}){let{t}=s(`analytics`),n=e.costUsd+e.estimatedCostUsd,r=e.costUsd===0&&e.estimatedCostUsd>0,i=e.unpricedCount??(e.count>0&&e.costUsd===0&&e.estimatedCostUsd===0?e.count:0),a=e.pricedCount??Math.max(0,e.count-i),o=e.count>0&&i>0&&a===0,c=a>0&&i>0;return(0,X.jsxs)(`div`,{className:`flex items-center gap-2.5 rounded-md border border-border/30 px-2.5 py-1.5`,children:[(0,X.jsx)(`span`,{className:`w-2 h-2 rounded-full shrink-0 ${Ve(e.provider)}`}),(0,X.jsx)(`span`,{className:`text-xs font-medium`,children:Be(e.provider)}),(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:t(`runs`,{count:e.count})}),o?(0,X.jsx)(`span`,{className:`ml-auto text-xs font-medium text-muted-foreground/80 italic`,title:t(`providerCard.costUnavailableTooltip`),children:t(`providerCard.costUnavailable`)}):(0,X.jsxs)(`span`,{className:`ml-auto text-xs font-medium tabular-nums`,title:c?t(`providerCard.costPartiallyUnavailableTooltip`):void 0,children:[r?`~`:``,ze(n),c&&(0,X.jsx)(`span`,{className:`ml-1 font-normal text-muted-foreground/80 italic`,children:t(`providerCard.costPartiallyUnavailable`,{count:i})})]})]})}var We=[`option`,`isActive`];function Z(){return Z=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},Z.apply(null,arguments)}function Ge(e,t){if(e==null)return{};var n,r,i=Ke(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 Ke(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 qe(e){var{option:t,isActive:n}=e,r=Ge(e,We);return typeof t==`string`?Y.createElement(L,Z({option:Y.createElement(we,Z({type:t},r)),isActive:n,shapeType:`symbols`},r)):Y.createElement(L,Z({option:t,isActive:n,shapeType:`symbols`},r))}var Je=W([(e,t,n,r,i,a,o)=>te(e,void 0,void 0,o),(e,t,n,r,i,a,o)=>N(e,`xAxis`,t,o),(e,t,n,r,i,a,o)=>F(e,`xAxis`,t,o),(e,t,n,r,i,a,o)=>N(e,`yAxis`,n,o),(e,t,n,r,i,a,o)=>F(e,`yAxis`,n,o),(e,t,n,r)=>O(e,`zAxis`,r,!1),W([T,(e,t,n,r,i)=>i],(e,t)=>e.filter(e=>e.type===`scatter`).find(e=>e.id===t)),(e,t,n,r,i,a)=>a],(e,t,n,r,i,a,o,s)=>{var{chartData:c,dataStartIndex:l,dataEndIndex:u}=e;if(o!=null){var d=o?.data!=null&&o.data.length>0?o.data:c?.slice(l,u+1);if(!(d==null||t==null||r==null||n==null||i==null||n?.length===0||i?.length===0))return ut({displayedData:d,xAxis:t,yAxis:r,zAxis:a,scatterSettings:o,xAxisTicks:n,yAxisTicks:i,cells:s})}}),Ye=[`id`],Xe=[`onMouseEnter`,`onClick`,`onMouseLeave`],Ze=[`animationBegin`,`animationDuration`,`animationEasing`,`hide`,`isAnimationActive`,`legendType`,`lineJointType`,`lineType`,`shape`,`xAxisId`,`yAxisId`,`zAxisId`];function Qe(e,t){if(e==null)return{};var n,r,i=$e(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 $e(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 Q(){return Q=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},Q.apply(null,arguments)}function et(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 $(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?et(Object(n),!0).forEach(function(t){tt(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):et(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function tt(e,t,n){return(t=nt(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function nt(e){var t=rt(e,`string`);return typeof t==`symbol`?t:t+``}function rt(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 it=e=>{var{dataKey:t,name:n,fill:r,legendType:i,hide:a}=e;return[{inactive:a,dataKey:t,type:i,color:r,value:V(n,t),payload:e}]},at=Y.memo(e=>{var{dataKey:t,points:n,stroke:r,strokeWidth:i,fill:a,name:o,hide:s,tooltipType:c,id:l}=e,u={dataDefinedOnItem:n?.map(e=>e.tooltipPayload),getPosition:e=>{var t;return n==null||(t=n[Number(e)])==null?void 0:t.tooltipPosition},settings:{stroke:r,strokeWidth:i,fill:a,nameKey:void 0,dataKey:t,name:V(o,t),hide:s,type:c,color:a,unit:``,graphicalItemId:l}};return Y.createElement(De,{tooltipEntrySettings:u})});function ot(e){var{points:t,props:n}=e,{line:r,lineType:i,lineJointType:a}=n;if(!r)return null;var o=ce(n),s=H(r),c,l;if(i===`joint`)c=t.map(e=>({x:e.cx??null,y:e.cy??null}));else if(i===`fitting`){var{xmin:u,xmax:d,a:f,b:p}=oe(t),m=e=>f*e+p;c=[{x:u,y:m(u)},{x:d,y:m(d)}]}var h=$($($({},o),{},{fill:`none`,stroke:o&&o.fill},s),{},{points:c});return l=Y.isValidElement(r)?Y.cloneElement(r,h):typeof r==`function`?r(h):Y.createElement(z,Q({},h,{type:a})),Y.createElement(q,{className:`recharts-scatter-line`,key:`recharts-scatter-line`},l)}function st(e){var{showLabels:t,points:n,children:r}=e,i=E(),a=(0,Y.useMemo)(()=>n?.map(e=>{var t={x:e.x??0,y:e.y??0,width:e.width,height:e.height,lowerWidth:e.width,upperWidth:e.width};return $($({},t),{},{value:void 0,payload:e.payload,viewBox:t,parentViewBox:i,fill:void 0})}),[i,n]);return Y.createElement(R,{value:t?a:void 0},r)}function ct(e){var{points:t,allOtherScatterProps:n}=e,{shape:r,activeShape:i,dataKey:a}=n,{id:o}=n,s=Qe(n,Ye),c=ge(de),{onMouseEnter:l,onClick:u,onMouseLeave:d}=n,f=Qe(n,Xe),p=ie(l,a,o),m=Oe(d),h=ke(u,a,o);if(!ve(t))return null;var g=ce(s);return Y.createElement(Y.Fragment,null,Y.createElement(ot,{points:t,props:s}),t.map((e,t)=>{var n=i!=null&&i!==!1,a=n&&c===String(t),s=n&&a?i:r,l=$($($({},g),e),{},{index:t,[k]:String(o)});return Y.createElement(x,{key:`symbol-${e?.cx}-${e?.cy}-${e?.size}-${t}`,zIndex:a?j.activeDot:void 0},Y.createElement(q,Q({className:`recharts-scatter-symbol`},re(f,e,t),{onMouseEnter:p(e,t),onMouseLeave:m(e,t),onClick:h(e,t)}),Y.createElement(qe,Q({option:s,isActive:a},l))))}))}function lt(e){var{previousPointsRef:t,props:n}=e,{points:r,isAnimationActive:i,animationBegin:a,animationDuration:o,animationEasing:s}=n,c=t.current,l=Ae(n,`recharts-scatter-`),[u,d]=(0,Y.useState)(!1),f=(0,Y.useCallback)(()=>{d(!1)},[]),p=(0,Y.useCallback)(()=>{d(!0)},[]),m=!u;return Y.createElement(st,{showLabels:m,points:r},n.children,Y.createElement(S,{animationId:l,begin:a,duration:o,isActive:i,easing:s,onAnimationEnd:f,onAnimationStart:p,key:l},e=>{var i=e===1?r:r?.map((t,n)=>{var r=c&&c[n];return r?$($({},t),{},{cx:t.cx==null?void 0:K(r.cx,t.cx,e),cy:t.cy==null?void 0:K(r.cy,t.cy,e),size:K(r.size,t.size,e)}):$($({},t),{},{size:K(0,t.size,e)})});return e>0&&(t.current=i),Y.createElement(q,null,Y.createElement(ct,{points:i,allOtherScatterProps:n,showLabels:m}))}),Y.createElement(w,{label:n.label}))}function ut(e){var{displayedData:t,xAxis:n,yAxis:r,zAxis:i,scatterSettings:a,xAxisTicks:o,yAxisTicks:s,cells:c}=e,l=J(n.dataKey)?a.dataKey:n.dataKey,u=J(r.dataKey)?a.dataKey:r.dataKey,d=i&&i.dataKey,f=i?i.range:M.range,p=f&&f[0],m=n.scale.bandwidth?n.scale.bandwidth():0,h=r.scale.bandwidth?r.scale.bandwidth():0;return t.map((e,t)=>{var f=I(e,l),g=I(e,u),_=!J(d)&&I(e,d)||`-`,v=[{name:J(n.dataKey)?a.name:n.name||String(n.dataKey),unit:n.unit||``,value:f,payload:e,dataKey:l,type:a.tooltipType,graphicalItemId:a.id},{name:J(r.dataKey)?a.name:r.name||String(r.dataKey),unit:r.unit||``,value:g,payload:e,dataKey:u,type:a.tooltipType,graphicalItemId:a.id}];_!==`-`&&i!=null&&v.push({name:i.name||i.dataKey,unit:i.unit||``,value:_,payload:e,dataKey:d,type:a.tooltipType,graphicalItemId:a.id});var y=B({axis:n,ticks:o,bandSize:m,entry:e,index:t,dataKey:l}),b=B({axis:r,ticks:s,bandSize:h,entry:e,index:t,dataKey:u}),x=_!==`-`&&i!=null?i.scale.map(_):p,S=x==null?0:Math.sqrt(Math.max(x,0)/Math.PI);return $($({},e),{},{cx:y,cy:b,x:y==null?void 0:y-S,y:b==null?void 0:b-S,width:2*S,height:2*S,size:x,node:{x:f,y:g,z:_},tooltipPayload:v,tooltipPosition:{x:y,y:b},payload:e},c&&c[t]&&c[t].props)})}var dt=(e,t,n)=>({x:e.cx,y:e.cy,value:Number(n===`x`?e.node.x:e.node.y),errorVal:I(e,t)});function ft(e){var{hide:t,points:n,className:r,needClip:i,xAxisId:a,yAxisId:o,id:s}=e,c=(0,Y.useRef)(null);if(t)return null;var l=h(`recharts-scatter`,r),u=s;return Y.createElement(x,{zIndex:e.zIndex},Y.createElement(q,{className:l,clipPath:i?`url(#clipPath-${u})`:void 0,id:s},i&&Y.createElement(`defs`,null,Y.createElement(_e,{clipPathId:u,xAxisId:a,yAxisId:o})),Y.createElement(ae,{xAxisId:a,yAxisId:o,data:n,dataPointFormatter:dt,errorBarOffset:0},Y.createElement(q,{key:`recharts-scatter-symbols`},Y.createElement(lt,{props:e,previousPointsRef:c})))))}var pt={xAxisId:0,yAxisId:0,zAxisId:0,label:!1,line:!1,legendType:`circle`,lineType:`joint`,lineJointType:`linear`,shape:`circle`,hide:!1,isAnimationActive:`auto`,animationBegin:0,animationDuration:400,animationEasing:`linear`,zIndex:j.scatter};function mt(e){var t=Se(e,pt),{animationBegin:n,animationDuration:r,animationEasing:i,hide:a,isAnimationActive:o,legendType:s,lineJointType:c,lineType:l,shape:u,xAxisId:d,yAxisId:f,zAxisId:p}=t,m=Qe(t,Ze),{needClip:h}=Ce(d,f),g=(0,Y.useMemo)(()=>C(e.children,ee),[e.children]),_=be(),v=ge(t=>Je(t,d,f,p,e.id,g,_));return h==null||v==null?null:Y.createElement(Y.Fragment,null,Y.createElement(at,{dataKey:e.dataKey,points:v,stroke:e.stroke,strokeWidth:e.strokeWidth,fill:e.fill,name:e.name,hide:e.hide,tooltipType:e.tooltipType,id:e.id}),Y.createElement(ft,Q({},m,{xAxisId:d,yAxisId:f,zAxisId:p,lineType:l,lineJointType:c,legendType:s,shape:u,hide:a,isAnimationActive:o,animationBegin:n,animationDuration:r,animationEasing:i,points:v,needClip:h})))}function ht(e){var t=Se(e,pt),n=be();return Y.createElement(G,{id:t.id,type:`scatter`},e=>Y.createElement(Y.Fragment,null,Y.createElement(ne,{legendPayload:it(t)}),Y.createElement(le,{type:`scatter`,id:e,data:t.data,xAxisId:t.xAxisId,yAxisId:t.yAxisId,zAxisId:t.zAxisId,dataKey:t.dataKey,hide:t.hide,name:t.name,tooltipType:t.tooltipType,isPanorama:n}),Y.createElement(mt,Q({},t,{id:e}))))}var gt=Y.memo(ht,D);gt.displayName=`Scatter`;function _t(e){var t=Ee(),n=(0,Y.useRef)(null);return(0,Y.useLayoutEffect)(()=>{n.current===null?t(se(e)):n.current!==e&&t(me({prev:n.current,next:e})),n.current=e},[e,t]),(0,Y.useLayoutEffect)(()=>()=>{n.current&&=(t(ye(n.current)),null)},[t]),null}var vt={zAxisId:0,range:M.range,scale:M.scale,type:M.type};function yt(e){var t=Se(e,vt);return Y.createElement(_t,{domain:t.domain,id:t.zAxisId,dataKey:t.dataKey,name:t.name,unit:t.unit,range:t.range,scale:t.scale,type:t.type,allowDuplicatedCategory:M.allowDuplicatedCategory,allowDataOverflow:M.allowDataOverflow,reversed:M.reversed,includeHidden:M.includeHidden})}yt.displayName=`ZAxis`;var bt=[`item`],xt=(0,Y.forwardRef)((e,t)=>Y.createElement(he,{chartName:`ScatterChart`,defaultTooltipEventType:`item`,validateTooltipEventTypes:bt,tooltipPayloadSearcher:fe,categoricalChartProps:e,ref:t}));function St({data:e,loading:t}){let{t:n}=s(`analytics`);if(t&&!e)return(0,X.jsx)(`div`,{className:`h-[220px] rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let r={jobs:n(`surfaces.job`),explore:n(`surfaces.exploreSpec`),quick:n(`surfaces.quickSpec`),refine:n(`surfaces.aiEdit`),fileSummaries:n(`surfaces.fileSummary`),smash:n(`surfaces.smash`),loop:n(`surfaces.loop`)},i=e.dailyTimeline.map(e=>({date:e.date.slice(5),[r.jobs]:e.jobsCostUsd,[r.explore]:e.exploreCostUsd,[r.quick]:e.quickCostUsd,[r.refine]:e.aiEditCostUsd,[r.fileSummaries]:e.fileSummaryCostUsd??0,[r.smash]:e.smashCostUsd??0,[r.loop]:e.loopCostUsd??0})),a=e.dailyTimeline.every(e=>e.jobsCostUsd+e.exploreCostUsd+e.quickCostUsd+e.aiEditCostUsd+(e.fileSummaryCostUsd??0)+(e.smashCostUsd??0)+(e.loopCostUsd??0)===0),o=e.dailyTimeline.reduce((e,t)=>e+(t.unpricedCount??0),0),c=a&&o>0,l=!a&&o>0;return(0,X.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,X.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider`,children:n(`timeline.title`)}),(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground/70`,children:l?n(`timeline.costPartiallyUnavailable`,{count:o}):n(`timeline.subtitle`)})]}),c?(0,X.jsx)(`div`,{"data-testid":`timeline-cost-unavailable`,className:`h-40 flex items-center justify-center text-xs text-muted-foreground/70`,children:n(`timeline.costUnavailable`)}):a?(0,X.jsx)(`div`,{className:`h-40 flex items-center justify-center text-xs text-muted-foreground/70`,children:n(`timeline.empty`)}):(0,X.jsx)(`div`,{className:`h-[220px]`,children:(0,X.jsx)(A,{width:`100%`,height:`100%`,children:(0,X.jsxs)(Te,{data:i,margin:{top:10,right:10,left:-8,bottom:0},children:[(0,X.jsx)(pe,{strokeDasharray:`2 4`,stroke:`currentColor`,className:`text-border/30`,vertical:!1}),(0,X.jsx)(ue,{dataKey:`date`,tick:{fontSize:10},stroke:`currentColor`,className:`text-muted-foreground`}),(0,X.jsx)(xe,{tick:{fontSize:10},stroke:`currentColor`,className:`text-muted-foreground`,tickFormatter:e=>`$${e}`}),(0,X.jsx)(P,{contentStyle:{backgroundColor:`var(--popover)`,border:`1px solid var(--border)`,fontSize:11,borderRadius:6},formatter:(e,t)=>[`$${typeof e==`number`?e.toFixed(2):`—`}`,String(t)]}),(0,X.jsx)(U,{dataKey:r.jobs,stackId:`a`,fill:`var(--accent-info, #5fa8d3)`}),(0,X.jsx)(U,{dataKey:r.explore,stackId:`a`,fill:`var(--accent-highlight, #c084fc)`}),(0,X.jsx)(U,{dataKey:r.quick,stackId:`a`,fill:`var(--accent-secondary, #f7768e)`}),(0,X.jsx)(U,{dataKey:r.refine,stackId:`a`,fill:`var(--accent-success, #50fa7b)`}),(0,X.jsx)(U,{dataKey:r.fileSummaries,stackId:`a`,fill:`var(--accent-warning, #f1fa8c)`}),(0,X.jsx)(U,{dataKey:r.smash,stackId:`a`,fill:`var(--accent-highlight, #c084fc)`}),(0,X.jsx)(U,{dataKey:r.loop,stackId:`a`,fill:`var(--accent-primary, #7aa2f7)`})]})})})]})}function Ct(e){return e==null?`—`:e<.005?`$${e.toFixed(4)}`:e<1?`$${e.toFixed(3)}`:`$${e.toFixed(2)}`}function wt(e){return e==null?`—`:e<1e3?`${e} ms`:e<6e4?`${(e/1e3).toFixed(1)}s`:`${Math.floor(e/6e4)}m ${Math.floor(e%6e4/1e3)}s`}function Tt({values:e}){let t=Math.max(1e-4,...e);return(0,X.jsx)(`div`,{className:`flex items-end gap-[1px] h-5`,children:e.map((e,n)=>(0,X.jsx)(`div`,{className:`w-[3px] rounded-sm bg-foreground/40`,style:{height:`${Math.max(2,e/t*20)}px`}},n))})}function Et({mode:e,label:t,accentClass:n}){let{t:r}=s(`analytics`),i=e.mode===`explore`&&e.totalRuns<5,a=(e.estimatedCostUsd??0)>0,c=e.avgCostPerSpec==null&&(e.unpricedCount??0)>0;return(0,X.jsxs)(`div`,{className:`flex-1 p-4 first:pr-2 last:pl-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,X.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full ${n}`}),(0,X.jsx)(`span`,{className:`text-xs font-medium uppercase tracking-wider text-muted-foreground`,children:t})]}),i?(0,X.jsxs)(`div`,{className:`py-3`,children:[(0,X.jsx)(`p`,{className:`text-sm text-foreground`,children:r(`quickVsExplore.sparseCta`)}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:r(`quickVsExplore.runsSoFar`,{count:e.totalRuns})})]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`text-3xl font-semibold tabular-nums tracking-tight`,"data-estimated":a?`true`:void 0,title:c?r(`quickVsExplore.costUnavailableTooltip`):a?r(`quickVsExplore.estimatedTooltip`):void 0,children:[a&&e.avgCostPerSpec!=null?`~`:``,Ct(e.avgCostPerSpec)]}),(0,X.jsx)(`div`,{className:`text-[11px] text-muted-foreground mt-0.5`,children:r(c?`quickVsExplore.costUnavailable`:`quickVsExplore.perSpec`)}),(0,X.jsx)(`div`,{className:`mt-3`,children:(0,X.jsx)(Tt,{values:e.sparkline.length>0?e.sparkline:[0]})}),(0,X.jsxs)(`div`,{className:`mt-3 space-y-0.5 text-xs tabular-nums text-muted-foreground`,children:[(0,X.jsx)(`div`,{children:(0,X.jsx)(o,{ns:`analytics`,i18nKey:`quickVsExplore.createdRuns`,values:{created:e.ticketsCreated,runs:e.totalRuns},components:{strong:(0,X.jsx)(`span`,{className:`text-foreground font-medium`})}})}),(0,X.jsx)(`div`,{children:r(`quickVsExplore.avgDuration`,{duration:wt(e.avgDurationMs)})}),(0,X.jsx)(`div`,{className:`truncate`,children:e.dominantModel??`—`})]})]})]})}function Dt({data:e,loading:t}){let{t:n}=s(`analytics`);if(t&&!e)return(0,X.jsx)(`div`,{className:`h-[220px] rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let r=e.byMode.find(e=>e.mode===`quick`),i=e.byMode.find(e=>e.mode===`explore`);if(!r||!i)return null;let a=r.avgCostPerSpec&&i.avgCostPerSpec&&r.avgCostPerSpec>0?i.avgCostPerSpec/r.avgCostPerSpec:null,o=a!==null&&r.totalRuns>=1&&i.totalRuns>=5,c=(r.estimatedCostUsd??0)>0||(i.estimatedCostUsd??0)>0;return(0,X.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40`,children:[(0,X.jsx)(`div`,{className:`px-4 pt-3 pb-1`,children:(0,X.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider`,children:n(`quickVsExplore.title`)})}),(0,X.jsxs)(`div`,{className:`flex divide-x divide-border/40`,children:[(0,X.jsx)(Et,{mode:r,label:n(`quickVsExplore.quick`),accentClass:`bg-accent-secondary`}),(0,X.jsx)(Et,{mode:i,label:n(`quickVsExplore.explore`),accentClass:`bg-accent-highlight`})]}),o&&(0,X.jsx)(`div`,{className:`px-4 pb-3 -mt-1`,children:(0,X.jsx)(`div`,{className:`text-center text-[11px] text-muted-foreground tabular-nums`,children:(0,X.jsxs)(`span`,{className:`px-2`,children:[`━━━━━━ `,n(`quickVsExplore.ratio`,{ratio:a.toFixed(1)}),` ━━━━━━`]})})}),c&&(0,X.jsx)(`div`,{className:`px-4 pb-3 -mt-1`,"data-testid":`quick-vs-explore-estimated-footnote`,children:(0,X.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:n(`quickVsExplore.estimatedFootnote`)})})]})}function Ot(e){return e<.005&&e>0?`$${e.toFixed(4)}`:e<1?`$${e.toFixed(3)}`:`$${e.toFixed(2)}`}function kt(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function At({data:e,loading:t}){let{t:n}=s(`analytics`),r=e?.agentMissions;if(t||!r||r.summary.turns===0)return null;let{summary:a,topConversations:o}=r,c=a.estimatedCostUsd>0,l=a.prevTotalCostUsd>0?(a.totalCostUsd-a.prevTotalCostUsd)/a.prevTotalCostUsd*100:null;return(0,X.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card p-4`,"data-testid":`agent-missions-card`,children:[(0,X.jsxs)(`div`,{className:`mb-3 flex items-center gap-2`,children:[(0,X.jsx)(v,{className:`h-4 w-4 text-accent-highlight`}),(0,X.jsx)(`h3`,{className:`text-sm font-medium`,children:n(`agentMissions.title`)}),(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:n(`agentMissions.subtitle`)})]}),(0,X.jsxs)(`div`,{className:`flex items-baseline gap-3`,children:[(0,X.jsxs)(`span`,{className:`text-3xl font-semibold tabular-nums tracking-tight`,"data-estimated":c?`true`:void 0,title:c?n(`agentMissions.estimatedNote`):void 0,children:[c?`~`:``,Ot(a.totalCostUsd)]}),l!==null&&(0,X.jsxs)(`span`,{className:l>0?`text-xs text-accent-warning`:`text-xs text-accent-success`,children:[l>0?`+`:``,l.toFixed(0),`% `,n(`agentMissions.vsPrev`)]})]}),(0,X.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:n(`agentMissions.turnsAndTokens`,{turns:a.turns,tokens:kt(a.tokensIn+a.tokensOut)})}),o.length>0&&(0,X.jsx)(`ul`,{className:`mt-3 space-y-1 border-t border-border/40 pt-2`,children:o.map(e=>(0,X.jsxs)(`li`,{className:`flex items-center gap-2 text-xs`,children:[(0,X.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-foreground/85`,children:e.title?.trim()||n(`agentMissions.untitled`)}),(0,X.jsxs)(`span`,{className:`shrink-0 text-[10px] text-muted-foreground`,children:[e.turns,` · `,e.lastAt?g(new Date(e.lastAt),{addSuffix:!0,locale:i()}):`—`]}),(0,X.jsxs)(`span`,{className:`shrink-0 tabular-nums font-medium`,children:[e.estimatedCostUsd>0?`~`:``,Ot(e.costUsd)]})]},e.conversationId??`unknown`))})]})}function jt({data:e,loading:t,onSelectModel:n,activeModel:r}){let{t:i}=s(`analytics`);if(t&&!e)return(0,X.jsx)(`div`,{className:`h-[220px] rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let a=e.summary.totalCostUsd,o=e.byModel.slice(0,5),c=o.reduce((e,t)=>e+t.costUsd,0),l=Math.max(0,a-c),u=l>=.005;return(0,X.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,X.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider mb-3`,children:i(`models.title`)}),o.length===0?(0,X.jsx)(`div`,{className:`h-32 flex items-center justify-center text-xs text-muted-foreground/70`,children:i(`models.empty`)}):(0,X.jsxs)(`ul`,{className:`space-y-1.5`,children:[o.map(e=>{let t=a>0?e.costUsd/a*100:0,o=r===e.model,s=(e.estimatedCostUsd??0)>0,c=e.unpricedCount??0,l=Math.max(0,e.count-c),u=e.count>0&&c>0&&l===0,d=l>0&&c>0;return(0,X.jsx)(`li`,{children:(0,X.jsxs)(`button`,{type:`button`,onClick:()=>n(e.model,e.provider),className:`w-full text-left group rounded-md px-2 py-1.5 transition-colors ${o?`bg-accent-highlight/10 ring-1 ring-accent-highlight/30`:`hover:bg-accent/30`}`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between text-[12px] mb-1 tabular-nums`,children:[(0,X.jsx)(`span`,{className:`truncate font-medium`,children:e.model}),(0,X.jsx)(`span`,{className:`text-muted-foreground`,"data-testid":u?`model-cost-unavailable`:void 0,title:u?i(`models.costUnavailableTooltip`):d?i(`models.costPartiallyUnavailableTooltip`):s?i(`models.estimatedTooltip`):void 0,children:u?i(`models.costUnavailableWithRuns`,{count:e.count}):(0,X.jsxs)(X.Fragment,{children:[s?`~`:``,`$`,e.costUsd.toFixed(2),` · `,e.count,d&&(0,X.jsx)(`span`,{className:`ml-1 italic`,children:i(`models.costPartiallyUnavailable`,{count:c})})]})})]}),(0,X.jsx)(`div`,{className:`h-1.5 rounded-full bg-background-deep overflow-hidden`,children:(0,X.jsx)(`div`,{className:`h-full ${o?`bg-accent-highlight`:`bg-foreground/40 group-hover:bg-foreground/60`} transition-colors`,style:{width:`${t}%`}})})]})},`${e.provider??`claude`}:${e.model}`)}),u&&(0,X.jsx)(`li`,{"data-testid":`model-others`,children:(0,X.jsxs)(`div`,{className:`w-full rounded-md px-2 py-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between text-[12px] mb-1 tabular-nums`,children:[(0,X.jsx)(`span`,{className:`truncate font-medium text-muted-foreground`,children:i(`models.others`)}),(0,X.jsxs)(`span`,{className:`text-muted-foreground`,children:[`$`,l.toFixed(2)]})]}),(0,X.jsx)(`div`,{className:`h-1.5 rounded-full bg-background-deep overflow-hidden`,children:(0,X.jsx)(`div`,{className:`h-full bg-foreground/25`,style:{width:`${a>0?l/a*100:0}%`}})})]})})]})]})}var Mt={job:`var(--accent-info, #5fa8d3)`,"quick-spec":`var(--accent-secondary, #f7768e)`,"explore-spec":`var(--accent-highlight, #c084fc)`,"ai-edit":`var(--accent-success, #50fa7b)`,smash:`var(--accent-highlight, #c084fc)`,"file-summary":`var(--accent-warning, #f1fa8c)`,loop:`var(--accent-primary, #7aa2f7)`,"chat-sidebar":`var(--accent-info, #5fa8d3)`,"spec-launcher":`var(--accent-secondary, #f7768e)`,proposal:`var(--accent-highlight, #c084fc)`,"agent-studio":`var(--accent-success, #50fa7b)`,setup:`var(--accent-primary, #7aa2f7)`},Nt=Object.keys(f);function Pt({data:e,loading:t,onSelectPoint:n}){let{t:r}=s(`analytics`);if(t&&!e)return(0,X.jsx)(`div`,{className:`h-[260px] rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let i=Nt,a=i.map(t=>({surface:t,points:e.scatter.filter(e=>e.surface===t).map(e=>({id:e.id,x:e.numTurns??Math.round((e.durationMs??0)/1e3),y:e.costUsd,surface:t,ticketId:e.ticketId,startedAt:e.startedAt,raw:e}))})),o=e.scatter.length===0,c=e.summary.unpricedRuns??0,l=o&&c>0,u=!o&&c>0,d=e.scatterTruncated===!0,p=e.scatterTotal??e.scatter.length;return(0,X.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,X.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider`,children:r(`scatter.title`)}),(0,X.jsx)(`div`,{className:`flex flex-wrap items-center gap-2 text-[10px]`,children:i.map(e=>(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,X.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full`,style:{background:Mt[e]}}),(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:f[e]})]},e))})]}),d&&!o&&(0,X.jsx)(`div`,{"data-testid":`scatter-truncation-notice`,className:`mb-2 text-[10px] text-accent-warning`,children:r(`scatter.truncated`,{shown:e.scatter.length,total:p})}),u&&(0,X.jsx)(`div`,{"data-testid":`scatter-cost-partial-notice`,className:`mb-2 text-[10px] text-muted-foreground/80 italic`,children:r(`scatter.costPartiallyUnavailable`,{count:c})}),l?(0,X.jsx)(`div`,{"data-testid":`scatter-cost-unavailable`,className:`h-40 flex items-center justify-center text-xs text-muted-foreground/70`,children:r(`scatter.costUnavailable`)}):o?(0,X.jsx)(`div`,{className:`h-40 flex items-center justify-center text-xs text-muted-foreground/70`,children:r(`scatter.empty`)}):(0,X.jsx)(`div`,{className:`h-[260px]`,children:(0,X.jsx)(A,{width:`100%`,height:`100%`,children:(0,X.jsxs)(xt,{margin:{top:10,right:10,left:-8,bottom:5},children:[(0,X.jsx)(pe,{strokeDasharray:`2 4`,stroke:`currentColor`,className:`text-border/30`}),(0,X.jsx)(ue,{type:`number`,dataKey:`x`,name:`turns`,tick:{fontSize:10},stroke:`currentColor`,className:`text-muted-foreground`,label:{value:r(`scatter.turnsLabel`),position:`insideBottomRight`,offset:-2,fontSize:10,fill:`currentColor`}}),(0,X.jsx)(xe,{type:`number`,dataKey:`y`,name:`cost`,tick:{fontSize:10},stroke:`currentColor`,className:`text-muted-foreground`,tickFormatter:e=>`$${e.toFixed(e<1?2:0)}`}),(0,X.jsx)(yt,{range:[40,80]}),(0,X.jsx)(P,{cursor:{strokeDasharray:`3 3`},contentStyle:{backgroundColor:`var(--popover)`,border:`1px solid var(--border)`,fontSize:11,borderRadius:6},formatter:(e,t)=>{let n=String(t);return n===`cost`&&typeof e==`number`?[`$${e.toFixed(3)}`,r(`scatter.costLabel`)]:[String(e),n===`turns`?r(`scatter.turnsLabel`):n]}}),a.map(e=>(0,X.jsx)(gt,{data:e.points,fill:Mt[e.surface],onClick:e=>{let t=e;t?.raw&&n(t.raw)}},e.surface))]})})})]})}function Ft({data:e,loading:t,onSelectTicket:n}){let{t:r}=s(`analytics`);if(t&&!e)return(0,X.jsx)(`div`,{className:`h-40 rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let i=e.topTickets;return(0,X.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,X.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider mb-3`,children:r(`topTickets.title`)}),i.length===0?(0,X.jsx)(`div`,{className:`h-32 flex items-center justify-center text-xs text-muted-foreground/70`,children:r(`topTickets.empty`)}):(0,X.jsx)(`ul`,{className:`divide-y divide-border/30`,children:i.map((e,t)=>{let i=Object.entries(e.bySurface).filter(([,e])=>e.count>0).map(([e,t])=>r(`topTickets.breakdownItem`,{n:t.count,label:f[e].toLowerCase()})).join(` + `),a=e.isUnattributed,o=a?r(`topTickets.unattributed`):e.ticketTitle?`#${e.ticketId} ${e.ticketTitle}`:r(`topTickets.deletedTicket`,{id:e.ticketId}),s=!e.ticketTitle&&!a?`opacity-50`:``,c=e.unpricedCount??0,l=e.totalRuns>0&&c===e.totalRuns,u=c>0&&!l;return(0,X.jsx)(`li`,{children:(0,X.jsxs)(`button`,{type:`button`,onClick:()=>n(e.ticketId),className:`w-full text-left flex items-center justify-between gap-3 py-2 px-1 hover:bg-accent/30 rounded transition-colors ${s}`,disabled:a,children:[(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`div`,{className:`text-sm truncate`,children:o}),(0,X.jsx)(`div`,{className:`text-[11px] text-muted-foreground truncate`,children:i||`—`})]}),(0,X.jsxs)(`div`,{className:`text-right tabular-nums`,children:[(0,X.jsx)(`div`,{className:`text-sm font-medium`,title:l?r(`topTickets.costUnavailableTooltip`):u?r(`topTickets.costPartiallyUnavailableTooltip`):void 0,children:l?r(`topTickets.costUnavailable`):`$${e.totalCostUsd.toFixed(2)}`}),u&&(0,X.jsx)(`div`,{className:`text-[10px] text-muted-foreground italic`,children:r(`topTickets.costPartiallyUnavailable`,{count:c})}),(0,X.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:r(`runs`,{count:e.totalRuns})})]})]})},`${e.ticketId??`u`}-${t}`)})})]})}var It={claude:`Claude`,codex:`Codex`,gemini:`Gemini`,kimi:`Kimi`};function Lt(e){return It[e]??e}function Rt(e){return e==null?`—`:e<.005?`$${e.toFixed(4)}`:`$${e.toFixed(2)}`}function zt(e){return e==null?`—`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function Bt(e){return e.surface_ref_id?.startsWith(`contract-refine:`)?!0:e.surface===`explore-spec`&&e.ticket_id!=null&&e.conversation_id!=null&&e.surface_ref_id===e.conversation_id&&e.model==null}function Vt(e){let t=new Map;for(let n of e)n.model&&(n.conversation_id&&t.set(`conversation:${n.conversation_id}`,n.model),n.ticket_id!=null&&n.surface===`explore-spec`&&t.set(`ticket:${n.ticket_id}:explore-spec`,n.model),n.ticket_id!=null&&n.surface===`quick-spec`&&t.set(`ticket:${n.ticket_id}:quick-spec`,n.model));return t}function Ht(e,t){if(e.model)return e.model;if(!Bt(e))return null;if(e.conversation_id){let n=t.get(`conversation:${e.conversation_id}`);if(n)return n}return e.ticket_id==null?null:t.get(`ticket:${e.ticket_id}:${e.surface}`)??null}function Ut({rows:e,loading:t,truncated:n,totalAvailable:r,tableFilters:i,onTableFiltersChange:a}){let{t:o}=s(`analytics`),[c,l]=(0,Y.useState)(null),u=Vt(e),d=new Set(e.map(e=>e.provider??`claude`)).size>1,p=n||r>e.length;return(0,X.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 mb-3`,children:[(0,X.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider`,children:o(`table.title`)}),(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-[11px]`,children:[(0,X.jsxs)(`select`,{value:i.status??``,onChange:e=>a({...i,status:e.target.value||void 0}),className:`h-7 px-2 rounded-md bg-background-deep border border-border/60 text-xs`,"aria-label":o(`table.statusFilterAria`),children:[(0,X.jsx)(`option`,{value:``,children:o(`table.allStatus`)}),(0,X.jsx)(`option`,{value:`success`,children:o(`table.success`)}),(0,X.jsx)(`option`,{value:`failed`,children:o(`table.failed`)}),(0,X.jsx)(`option`,{value:`aborted`,children:o(`table.aborted`)})]}),(0,X.jsx)(`input`,{type:`number`,step:`0.01`,min:`0`,placeholder:o(`table.minCostPlaceholder`),value:i.minCostUsd??``,onChange:e=>{let t=e.target.value===``?void 0:parseFloat(e.target.value);a({...i,minCostUsd:Number.isNaN(t)?void 0:t})},className:`h-7 w-24 px-2 rounded-md bg-background-deep border border-border/60 text-xs tabular-nums`,"aria-label":o(`table.minCostFilterAria`)})]})]}),t?(0,X.jsx)(`div`,{className:`h-32 rounded bg-card/30 animate-pulse`}):e.length===0?(0,X.jsx)(`div`,{className:`h-32 flex items-center justify-center text-xs text-muted-foreground/70`,children:o(`table.empty`)}):(0,X.jsx)(`div`,{className:`overflow-x-auto`,children:(0,X.jsxs)(`table`,{className:`w-full text-[12px] tabular-nums`,children:[(0,X.jsx)(`thead`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:(0,X.jsxs)(`tr`,{className:`text-left`,children:[(0,X.jsx)(`th`,{className:`font-medium px-2 py-2`,children:o(`table.colSurface`)}),(0,X.jsx)(`th`,{className:`font-medium px-2 py-2`,children:o(`table.colTicket`)}),(0,X.jsx)(`th`,{className:`font-medium px-2 py-2 text-right`,children:o(`table.colCost`)}),(0,X.jsx)(`th`,{className:`font-medium px-2 py-2 text-right`,children:o(`table.colTurns`)}),(0,X.jsx)(`th`,{className:`font-medium px-2 py-2 text-right`,children:o(`table.colTokens`)}),(0,X.jsx)(`th`,{className:`font-medium px-2 py-2`,children:o(`table.colModel`)}),d&&(0,X.jsx)(`th`,{className:`font-medium px-2 py-2`,children:o(`table.colProvider`)}),(0,X.jsx)(`th`,{className:`font-medium px-2 py-2`,children:o(`table.colStatus`)}),(0,X.jsx)(`th`,{className:`font-medium px-2 py-2`,children:o(`table.colStarted`)})]})}),(0,X.jsx)(`tbody`,{children:e.map(e=>{let t=e.surface,n=m[t],r=(e.tokens_in??0)+(e.tokens_out??0)+(e.tokens_cache_read??0)+(e.tokens_cache_create??0),i=Bt(e),a=i?o(`table.contractLayer`):f[t],s=Ht(e,u);return(0,X.jsxs)(`tr`,{onClick:()=>l(c===e.id?null:e.id),className:`border-t border-border/30 hover:bg-accent/30 cursor-pointer`,children:[(0,X.jsx)(`td`,{className:`px-2 py-2`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 px-2 h-5 rounded-full text-[10px] font-medium ${n.bg} ${n.text}`,children:[(0,X.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full ${n.dot}`}),a]})}),(0,X.jsx)(`td`,{className:`px-2 py-2 max-w-[260px]`,children:e.ticket_id==null?e.ticket_title?(0,X.jsx)(`span`,{className:`truncate block text-muted-foreground/90 italic`,title:o(`table.provisionalTitleTooltip`),children:e.ticket_title}):(0,X.jsx)(`span`,{className:`text-muted-foreground/70`,children:`—`}):(0,X.jsxs)(`span`,{className:`truncate block`,children:[`#`,e.ticket_id,` `,i?(0,X.jsx)(`span`,{className:`text-muted-foreground/90`,children:o(`table.contractLayerRefinement`)}):e.ticket_title??(0,X.jsx)(`span`,{className:`text-muted-foreground/70 italic`,children:o(`table.deleted`)})]})}),(0,X.jsx)(`td`,{className:`px-2 py-2 text-right font-medium`,children:e.total_cost_usd_estimated===1&&e.total_cost_usd!=null?(0,X.jsxs)(`span`,{title:o(`table.estimatedCostTooltip`),className:`text-muted-foreground/90`,children:[`~`,Rt(e.total_cost_usd)]}):Rt(e.total_cost_usd)}),(0,X.jsx)(`td`,{className:`px-2 py-2 text-right`,children:zt(e.num_turns)}),(0,X.jsx)(`td`,{className:`px-2 py-2 text-right`,children:r>0?zt(r):`—`}),(0,X.jsxs)(`td`,{className:`px-2 py-2 max-w-[180px] truncate`,children:[s??`—`,s&&!e.model?(0,X.jsx)(`span`,{className:`ml-1 text-[10px] text-muted-foreground/70`,children:o(`table.inferred`)}):null]}),d&&(0,X.jsx)(`td`,{className:`px-2 py-2 text-muted-foreground`,children:Lt(e.provider??`claude`)}),(0,X.jsxs)(`td`,{className:`px-2 py-2`,children:[e.status===`success`?(0,X.jsx)(`span`,{className:`text-accent-success/90`,children:`●`}):e.status===`failed`?(0,X.jsx)(`span`,{className:`text-accent-warning`,children:`⚠`}):(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`○`}),(0,X.jsx)(`span`,{className:`ml-1 text-muted-foreground`,children:o(`table.statusValue.${e.status}`)})]}),(0,X.jsx)(`td`,{className:`px-2 py-2 text-muted-foreground`,children:e.started_at.slice(0,16).replace(`T`,` `)})]},e.id)})})]})}),p&&e.length>0&&(0,X.jsx)(`div`,{className:`mt-2 text-[11px] text-muted-foreground/80`,children:o(`table.truncated`,{shown:e.length,total:r.toLocaleString()})})]})}var Wt=[{value:`7d`,labelKey:`periods.d7`},{value:`30d`,labelKey:`periods.d30`},{value:`90d`,labelKey:`periods.d90`},{value:`all`,labelKey:`periods.all`}],Gt=[{value:`all`,labelKey:`page.all`},{value:`job`,labelKey:`surfaces.job`},{value:`explore-spec`,labelKey:`surfaces.exploreSpec`},{value:`quick-spec`,labelKey:`surfaces.quickSpec`},{value:`ai-edit`,labelKey:`surfaces.aiEdit`},{value:`smash`,labelKey:`surfaces.smash`},{value:`file-summary`,labelKey:`surfaces.fileSummary`},{value:`loop`,labelKey:`surfaces.loop`}];function Kt(e){let t=new URLSearchParams;return e.period&&t.set(`period`,e.period),e.from&&t.set(`from`,e.from),e.to&&t.set(`to`,e.to),e.surface&&e.surface.length>0&&t.set(`surface`,e.surface.join(`,`)),e.provider&&e.provider.length>0&&t.set(`provider`,e.provider.join(`,`)),e.model&&e.model.length>0&&t.set(`model`,e.model.join(`,`)),e.modelKeys&&e.modelKeys.length>0&&e.model&&e.modelKeys.length===e.model.length&&t.set(`modelProvider`,e.modelKeys.map(e=>e.provider).join(`,`)),e.status&&t.set(`status`,e.status),typeof e.minCostUsd==`number`&&t.set(`minCostUsd`,String(e.minCostUsd)),typeof e.ticketId==`number`&&t.set(`ticketId`,String(e.ticketId)),typeof e.tzOffsetMinutes==`number`&&t.set(`tzOffsetMinutes`,String(e.tzOffsetMinutes)),e.sortBy&&t.set(`sortBy`,e.sortBy),t.toString()}function qt(){let{t:e}=s(`analytics`),{activeProjectId:t,projects:n}=d(),[i,o]=r(),c=n.find(e=>e.id===t),f=c?u(c):[`claude`],p=f.length>1,m=i.get(`period`)??`30d`,h=(i.get(`surface`)??``).split(`,`).filter(Boolean),g=(i.get(`provider`)??``).split(`,`).filter(Boolean),v=i.get(`ticketId`),x=(i.get(`model`)??``).split(`,`).filter(Boolean),S=(i.get(`modelProvider`)??``).split(`,`).filter(Boolean),C=x.length>0&&x.length===S.length?x.map((e,t)=>({provider:S[t],model:e})):void 0,ee=(0,Y.useMemo)(()=>-new Date().getTimezoneOffset(),[]),[w,T]=(0,Y.useState)({period:m,surface:h.length>0?h:void 0,provider:g.length>0?g:void 0,ticketId:v?Number(v):void 0,model:x.length>0?x:void 0,modelKeys:C,tzOffsetMinutes:ee}),[E,D]=(0,Y.useState)(null),[O,k]=(0,Y.useState)(!0),[A,j]=(0,Y.useState)(null),[M,N]=(0,Y.useState)({}),[P,F]=(0,Y.useState)(null),[I,te]=(0,Y.useState)(`recency`),L=(0,Y.useRef)(new Map),R=(0,Y.useRef)(0);(0,Y.useEffect)(()=>{let e=new URLSearchParams;e.set(`period`,w.period),w.surface&&w.surface.length>0&&e.set(`surface`,w.surface.join(`,`)),w.provider&&w.provider.length>0&&e.set(`provider`,w.provider.join(`,`)),w.ticketId&&e.set(`ticketId`,String(w.ticketId)),w.model&&w.model.length>0&&(e.set(`model`,w.model.join(`,`)),w.modelKeys&&w.modelKeys.length===w.model.length&&e.set(`modelProvider`,w.modelKeys.map(e=>e.provider).join(`,`))),o(e,{replace:!0})},[w.period,w.surface,w.provider,w.ticketId,w.model,w.modelKeys,o]);let z=(0,Y.useCallback)(async()=>{if(!t)return;let e=++R.current;j(null);let n=`${t}:${Kt(w)}`,r=L.current.get(n);r?(D(r),k(!1)):k(!0);try{let t=await fetch(`${l()}/spending?${Kt(w)}`);if(!t.ok)throw Error(`HTTP ${t.status}`);if(e!==R.current)return;let r=await t.json();L.current.set(n,r),D(r),k(!1)}catch(t){if(e!==R.current)return;j(t.message),k(!1)}},[t,w]),B=(0,Y.useRef)(0),V=(0,Y.useCallback)(async()=>{if(!t)return;let e=++B.current,n={...w};M.model&&(n.model=[M.model],n.modelKeys=void 0),M.status&&(n.status=M.status),typeof M.minCostUsd==`number`&&(n.minCostUsd=M.minCostUsd),n.sortBy=I;try{let t=await fetch(`${l()}/invocations?${Kt(n)}&limit=100`);if(!t.ok)throw Error(`HTTP ${t.status}`);let r=await t.json();if(e!==B.current)return;F(r)}catch{if(e!==B.current)return;F(null)}},[t,w,M,I]),ne=(0,Y.useRef)(t);(0,Y.useEffect)(()=>{ne.current!==t&&(ne.current=t,D(null),F(null),k(!0))},[t]),(0,Y.useEffect)(()=>{z()},[z]),(0,Y.useEffect)(()=>{V()},[V]);let H=(0,Y.useRef)(null),U=a();(0,Y.useEffect)(()=>{let e=`analytics-spending`;return U.registerHandler(e,e=>{let n=e;n.type===`spending.invalidated`&&n.projectId===t&&(H.current&&clearTimeout(H.current),H.current=setTimeout(()=>{L.current.clear(),z(),V()},500))}),()=>{U.unregisterHandler(e),H.current&&clearTimeout(H.current)}},[U,t,z,V]);function re(e){if(e===`all`){T(e=>({...e,surface:void 0}));return}T(t=>{let n=t.surface??[],r=n.includes(e)?n.filter(t=>t!==e):[...n,e];return{...t,surface:r.length>0?r:void 0}})}let ie=(0,Y.useCallback)((e,t)=>{T(n=>{if(n.model?.length===1&&n.model[0]===e&&(t===void 0||n.modelKeys?.length===1&&n.modelKeys[0].provider===t))return{...n,model:void 0,modelKeys:void 0};let r=(E?.byModel??[]).filter(n=>n.model===e&&(t===void 0||n.provider===t)).map(e=>({provider:e.provider,model:e.model})),i=r.length>0?r.map(e=>e.model):[e];return{...n,model:i,modelKeys:r.length>0?r:void 0}})},[E]);function ae(){T(e=>({...e,model:void 0,modelKeys:void 0}))}function oe(e){if(e===`all`){T(e=>({...e,provider:void 0}));return}T(t=>{let n=t.provider??[],r=n.includes(e)?n.filter(t=>t!==e):[...n,e];return{...t,provider:r.length>0?r:void 0}})}let W=w.surface,se=!W||W.length===0,G=w.provider,ce=!G||G.length===0,le=(0,Y.useMemo)(()=>{let e={period:w.period};return w.surface&&w.surface.length>0&&(e.surface=w.surface.join(`,`)),w.provider&&w.provider.length>0&&(e.provider=w.provider.join(`,`)),w.ticketId&&(e.ticketId=String(w.ticketId)),e},[w]),ue=E?E.summary.totalRuns===0:!1;return(0,X.jsxs)(`div`,{className:`flex flex-col gap-6 p-4 pb-12`,children:[(0,X.jsxs)(`div`,{className:`sticky top-0 z-10 -mx-4 px-4 py-3 bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/80 border-b border-border/40`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,X.jsx)(`h1`,{className:`text-base font-semibold tracking-tight`,children:e(`page.title`)}),w.ticketId&&(0,X.jsx)(`button`,{type:`button`,onClick:()=>T(e=>({...e,ticketId:void 0})),className:`inline-flex items-center gap-1 h-6 px-2 rounded-full text-[11px] font-medium bg-accent-highlight/15 text-accent-highlight ring-1 ring-accent-highlight/30 hover:bg-accent-highlight/25`,children:e(`page.ticketChip`,{id:w.ticketId})}),w.model&&w.model.length>0&&(0,X.jsxs)(`button`,{type:`button`,"data-testid":`analytics-model-chip`,onClick:ae,title:e(`page.clearModelFilter`),className:`inline-flex items-center gap-1 h-6 px-2 rounded-full text-[11px] font-medium bg-accent-highlight/15 text-accent-highlight ring-1 ring-accent-highlight/30 hover:bg-accent-highlight/25`,children:[e(`page.modelChip`,{model:w.model[0]}),(0,X.jsx)(`span`,{"aria-hidden":!0,className:`opacity-70`,children:`×`})]})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`div`,{className:`flex items-center gap-1 rounded-md border border-border/60 bg-card/40 p-0.5`,children:Wt.map(t=>(0,X.jsx)(`button`,{type:`button`,onClick:()=>T(e=>({...e,period:t.value})),className:`px-2.5 h-6 rounded text-[11px] font-medium transition-colors ${w.period===t.value?`bg-accent text-foreground`:`text-muted-foreground hover:text-foreground`}`,children:e(t.labelKey)},t.value))}),(0,X.jsx)(b,{baseUrl:`${l()}/analytics/export`,params:le,disabled:ue}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>{L.current.clear(),z(),V()},className:`h-7 w-7 inline-flex items-center justify-center rounded-md border border-border/60 bg-card/50 text-muted-foreground hover:text-foreground hover:bg-accent/60`,title:e(`common:actions.refresh`),children:(0,X.jsx)(y,{className:`w-3 h-3`})})]})]}),(0,X.jsx)(`div`,{className:`mt-3 flex flex-wrap items-center gap-1.5`,children:Gt.map(t=>(0,X.jsx)(`button`,{type:`button`,onClick:()=>re(t.value),className:`h-7 px-3 rounded-full text-[11px] font-medium transition-all ${(t.value===`all`?se:W?.includes(t.value)??!1)?`bg-foreground/10 text-foreground ring-1 ring-foreground/20`:`text-muted-foreground hover:text-foreground hover:bg-accent/40`}`,children:e(t.labelKey)},t.value))}),p&&(0,X.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-1.5`,"data-testid":`analytics-provider-chips`,children:[(0,X.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-muted-foreground/70 mr-1`,children:e(`page.engine`)}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>oe(`all`),className:`h-7 px-3 rounded-full text-[11px] font-medium transition-all ${ce?`bg-foreground/10 text-foreground ring-1 ring-foreground/20`:`text-muted-foreground hover:text-foreground hover:bg-accent/40`}`,children:e(`page.all`)}),f.map(e=>(0,X.jsx)(`button`,{type:`button`,onClick:()=>oe(e),className:`h-7 px-3 rounded-full text-[11px] font-medium transition-all ${G?.includes(e)??!1?`bg-foreground/10 text-foreground ring-1 ring-foreground/20`:`text-muted-foreground hover:text-foreground hover:bg-accent/40`}`,children:_(e)},e))]})]}),A&&(0,X.jsxs)(`div`,{className:`rounded-lg border border-accent-warning/30 bg-accent-warning/10 p-4 flex items-center justify-between`,children:[(0,X.jsx)(`p`,{className:`text-sm text-accent-warning`,children:e(`page.failedToLoad`,{error:A})}),(0,X.jsxs)(`button`,{onClick:()=>z(),className:`flex items-center gap-1.5 h-7 px-3 rounded-md text-xs text-accent-warning border border-accent-warning/30 hover:bg-accent-warning/10`,children:[(0,X.jsx)(y,{className:`w-3 h-3`}),e(`common:actions.retry`)]})]}),(0,X.jsx)(Ie,{data:E,loading:O,period:w.period}),(0,X.jsx)(He,{data:E,loading:O}),(0,X.jsx)(St,{data:E,loading:O}),(0,X.jsx)(At,{data:E,loading:O}),(0,X.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4`,children:[(0,X.jsx)(Dt,{data:E,loading:O}),(0,X.jsx)(jt,{data:E,loading:O,onSelectModel:ie,activeModel:w.model?.[0]})]}),(0,X.jsx)(Pt,{data:E,loading:O,onSelectPoint:e=>{N(e=>({...e})),T(t=>({...t,ticketId:e.ticketId??void 0}))}}),(0,X.jsx)(Ft,{data:E,loading:O,onSelectTicket:e=>T(t=>({...t,ticketId:e??void 0}))}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-end gap-1.5`,"data-testid":`analytics-table-sort`,children:[(0,X.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-muted-foreground/70 mr-1`,children:e(`table.sortLabel`)}),[`recency`,`cost`].map(t=>(0,X.jsx)(`button`,{type:`button`,"data-testid":`analytics-table-sort-${t}`,"aria-pressed":I===t,onClick:()=>te(t),className:`h-6 px-2.5 rounded-full text-[11px] font-medium transition-all ${I===t?`bg-foreground/10 text-foreground ring-1 ring-foreground/20`:`text-muted-foreground hover:text-foreground hover:bg-accent/40`}`,children:e(t===`recency`?`table.sortRecency`:`table.sortCost`)},t))]}),(0,X.jsx)(Ut,{rows:P?.rows??[],loading:O&&!P,truncated:(P?.truncated??!1)||(P?.totalAvailable??0)>(P?.rows.length??0),totalAvailable:P?.totalAvailable??0,tableFilters:M,onTableFiltersChange:N})]})]})}export{qt as default};
|