specrails-desktop 2.48.1 → 2.49.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/client/dist/assets/{ActivityFeedPage-CGq6QhP5.js → ActivityFeedPage-FdZBSmTU.js} +1 -1
- package/client/dist/assets/{AgentBrowserCapture-C4GZ-kdf.js → AgentBrowserCapture-Dr8kZotA.js} +1 -1
- package/client/dist/assets/{AgentModeAnalyticsPane-_IPmL0ZS.js → AgentModeAnalyticsPane-DXQSjYe-.js} +2 -2
- package/client/dist/assets/{AgentModeCodePane-B5WG5DOP.js → AgentModeCodePane-DcVV6EBy.js} +2 -2
- package/client/dist/assets/AgentModeJobsPane-a9f-g56c.js +1 -0
- package/client/dist/assets/AgentsPage-CTv4UVdp.js +87 -0
- package/client/dist/assets/{AnalyticsPage-BUMsKtsJ.js → AnalyticsPage-BbXPcz3a.js} +1 -1
- package/client/dist/assets/CodePage-CIigb_O0.js +3 -0
- package/client/dist/assets/DesktopAnalyticsPage-DZhN5jVh.js +1 -0
- package/client/dist/assets/{DocsDialog-ccQETHKB.js → DocsDialog-DzrqPxuj.js} +2 -2
- package/client/dist/assets/{DocsPage-DzEgplB3.js → DocsPage-B1AUuk0U.js} +1 -1
- package/client/dist/assets/{ExportDropdown-B8bBGopr.js → ExportDropdown-IPutNYvD.js} +1 -1
- package/client/dist/assets/InteractiveJobComposer-jg3xE_GX.js +19 -0
- package/client/dist/assets/{JobDetailModal-BYXmuTDe.js → JobDetailModal-BS-htwqZ.js} +1 -1
- package/client/dist/assets/JobDetailPage-CKYtQV5a.js +1 -0
- package/client/dist/assets/JobsPage-DFJm0bw0.js +1 -0
- package/client/dist/assets/{LoopBuilderPage-DQE-7Vby.js → LoopBuilderPage-ujkA2U0T.js} +2 -2
- package/client/dist/assets/LoopPreviewModal-BYOrnmcp.js +1 -0
- package/client/dist/assets/LoopsPage-DRcT1ikP.js +1 -0
- package/client/dist/assets/{MinimizedChatsContext-UpnqccPx.js → MinimizedChatsContext-CX1i2kQ8.js} +1 -1
- package/client/dist/assets/{PluginsPage-CjgVvmpW.js → PluginsPage-BR9ZTqxR.js} +2 -2
- package/client/dist/assets/{ProjectSettingsDialog-D6vBCoay.js → ProjectSettingsDialog-SAfCqXzC.js} +1 -1
- package/client/dist/assets/RepositoryDeliveries-DqmlG0Zs.js +5 -0
- package/client/dist/assets/{RepositoryScopeSelector-0Gz_fR1E.js → RepositoryScopeSelector-DG8KKPrm.js} +1 -1
- package/client/dist/assets/ReviewPacketPage-BoqahYNC.js +4 -0
- package/client/dist/assets/TemplatePreviewModal-CK5OoImj.js +1 -0
- package/client/dist/assets/TicketDetailModalContext-D2MEhRwJ.js +14 -0
- package/client/dist/assets/{Trans-9pHTy2fH.js → Trans-BLljsfHR.js} +1 -1
- package/client/dist/assets/agent-B76BhAyE.js +1 -0
- package/client/dist/assets/agent-BII69Nc0.js +1 -0
- package/client/dist/assets/agent-BIO4q6b0.js +1 -0
- package/client/dist/assets/agent-ButS6kwl.js +1 -0
- package/client/dist/assets/agent-CVeMLIu4.js +1 -0
- package/client/dist/assets/agent-CYFBDwFD.js +1 -0
- package/client/dist/assets/agent-D3jkMipn.js +1 -0
- package/client/dist/assets/agent-DSrflYFL.js +1 -0
- package/client/dist/assets/{formatDistanceToNow-w_2U5pm0.js → formatDistanceToNow-CbQZkD8M.js} +1 -1
- package/client/dist/assets/{getTimezoneOffsetInMilliseconds-BRymg1Kk.js → getTimezoneOffsetInMilliseconds-pBVK3rJC.js} +1 -1
- package/client/dist/assets/index-CjAPu3wb.js +80 -0
- package/client/dist/assets/index-UDzndadF.css +2 -0
- package/client/dist/assets/{jira-api-BqHbSdxK.js → jira-api-f-sYCIuX.js} +1 -1
- package/client/dist/assets/packet-BTRySHoQ.js +1 -0
- package/client/dist/assets/packet-BsRimSfZ.js +1 -0
- package/client/dist/assets/packet-C0pcMd6x.js +1 -0
- package/client/dist/assets/packet-C8qzvgrZ.js +1 -0
- package/client/dist/assets/packet-DF-iwqqY.js +1 -0
- package/client/dist/assets/packet-DQ_GnT2b.js +1 -0
- package/client/dist/assets/packet-Nb8BLI5h.js +1 -0
- package/client/dist/assets/packet-r7J14m89.js +1 -0
- package/client/dist/assets/{project-repositories-BsCs1PPA.js → project-repositories-DAjJbFhm.js} +1 -1
- package/client/dist/assets/{spending-hcgxHP4O.js → spending-DJBbdJyD.js} +1 -1
- package/client/dist/assets/{useDesktop-CAisjKWC.js → useDesktop-BJ8IRBRt.js} +1 -1
- package/client/dist/assets/useRuntimeRuns-Ch1KUc7k.js +1 -0
- package/client/dist/assets/{useSharedWebSocket-BHIfW4QT.js → useSharedWebSocket-BN3Lmehi.js} +2 -2
- package/client/dist/index.html +17 -17
- package/docs/guide/de/integrations/6-agent-chat.md +8 -0
- package/docs/guide/en/integrations/6-agent-chat.md +8 -0
- package/docs/guide/es/integrations/6-agent-chat.md +8 -0
- package/docs/guide/fr/integrations/6-agent-chat.md +8 -0
- package/docs/guide/it/integrations/6-agent-chat.md +8 -0
- package/docs/guide/ja/integrations/6-agent-chat.md +8 -0
- package/docs/guide/pt/integrations/6-agent-chat.md +8 -0
- package/docs/guide/zh/integrations/6-agent-chat.md +8 -0
- package/docs/internals/mission-rail-cards.md +130 -0
- package/docs/internals/review-packet.md +16 -3
- package/docs/local-providers.md +6 -0
- package/docs/mcp.md +24 -1
- package/package.json +1 -1
- package/server/dist/agent-chat-manager.js +97 -2
- package/server/dist/agent-chat-router.js +57 -1
- package/server/dist/agent-context-resolver.js +15 -0
- package/server/dist/agent-cwd-manager.js +1 -1
- package/server/dist/agent-failure-briefing.js +90 -0
- package/server/dist/agent-fence-promotion.js +8 -1
- package/server/dist/agent-operator-prompt.js +69 -1
- package/server/dist/agent-runtime-controls-router.js +17 -0
- package/server/dist/agent-store.js +40 -0
- package/server/dist/delivery-evidence.js +159 -0
- package/server/dist/desktop-db.js +11 -0
- package/server/dist/feature-flags.js +20 -0
- package/server/dist/mcp/guide.js +7 -0
- package/server/dist/mcp/tools/jobs.js +91 -4
- package/server/dist/mcp/tools/rails.js +2 -2
- package/server/dist/mission-run-notify.js +170 -0
- package/server/dist/providers/local-adapter.js +17 -0
- package/server/dist/rail-isolated-launch.js +47 -0
- package/server/dist/rail-launch-parser.js +182 -0
- package/server/dist/rail-pr-store.js +20 -0
- package/server/dist/rails-router.js +98 -5
- package/server/dist/review-packet.js +35 -2
- package/client/dist/assets/AgentModeJobsPane-w1N_HIXh.js +0 -1
- package/client/dist/assets/AgentsPage-CmwnnT46.js +0 -87
- package/client/dist/assets/CodePage-PjgywJPS.js +0 -3
- package/client/dist/assets/DesktopAnalyticsPage-BXY1pH4y.js +0 -1
- package/client/dist/assets/InteractiveJobComposer-CEwGkJ8F.js +0 -19
- package/client/dist/assets/JobDetailPage-CWp6MwJj.js +0 -1
- package/client/dist/assets/JobsPage-D1O1uyG8.js +0 -1
- package/client/dist/assets/LoopPreviewModal-Bk7zIXD5.js +0 -1
- package/client/dist/assets/LoopsPage-CqG7mx56.js +0 -1
- package/client/dist/assets/RepositoryDeliveries-C36ipKp_.js +0 -5
- package/client/dist/assets/ReviewPacketPage-Dr9RYs7q.js +0 -1
- package/client/dist/assets/TemplatePreviewModal-sCMHYFJo.js +0 -1
- package/client/dist/assets/TicketDetailModalContext-C5GgJlEt.js +0 -14
- package/client/dist/assets/agent-BdT0SB1D.js +0 -1
- package/client/dist/assets/agent-Bh9K7iEt.js +0 -1
- package/client/dist/assets/agent-C4ibdFk9.js +0 -1
- package/client/dist/assets/agent-CSFY22Zo.js +0 -1
- package/client/dist/assets/agent-DAnqxUn8.js +0 -1
- package/client/dist/assets/agent-DTQiu0Mi.js +0 -1
- package/client/dist/assets/agent-T54WuR_Y.js +0 -1
- package/client/dist/assets/agent-i75WDZOA.js +0 -1
- package/client/dist/assets/brain-DI9lHkKY.js +0 -1
- package/client/dist/assets/format-duration-NJVPOPBG.js +0 -1
- package/client/dist/assets/index-D0ScFZvR.css +0 -2
- package/client/dist/assets/index-DORCrgbI.js +0 -77
- package/client/dist/assets/packet-BNW8ODQw.js +0 -1
- package/client/dist/assets/packet-CXYvfdjy.js +0 -1
- package/client/dist/assets/packet-CtIlB8YE.js +0 -1
- package/client/dist/assets/packet-DA1SJkMH.js +0 -1
- package/client/dist/assets/packet-DYcWfBip.js +0 -1
- package/client/dist/assets/packet-DseX9yKC.js +0 -1
- package/client/dist/assets/packet-_m5aOy_d.js +0 -1
- package/client/dist/assets/packet-qOemUAm3.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-BHIfW4QT.js";import{t as o}from"./Trans-9pHTy2fH.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-CAisjKWC.js";import{r as f,s as p}from"./provider-capabilities-Vi1ZGvAK.js";import{n as m,r as h,t as g}from"./spending-hcgxHP4O.js";import{t as _}from"./clsx-CjueKrWZ.js";import{t as v}from"./formatDistanceToNow-w_2U5pm0.js";import{Ut as y,_t as b}from"./index-DORCrgbI.js";import{t as x}from"./ExportDropdown-B8bBGopr.js";import{A as S,B as C,C as w,D as ee,E as T,F as E,G as D,H as O,I as k,J as A,K as j,L as te,M,N as ne,O as N,P,Q as F,R as re,S as I,T as L,V as R,X as z,Z as B,_ as ie,_t as V,a as H,at as ae,b as oe,c as se,ct as ce,et as U,f as le,g as W,gt as ue,h as de,i as fe,j as pe,k as me,l as he,lt as G,m as ge,n as _e,nt as ve,o as ye,ot as be,p as xe,pt as K,q as Se,r as Ce,rt as we,s as Te,st as Ee,t as De,tt as Oe,ut as q,v as ke,x as Ae,y as je,z as Me}from"./BarChart-nBOMNfiy.js";var Ne=c(`arrow-down-right`,[[`path`,{d:`m7 7 10 10`,key:`1fmybs`}],[`path`,{d:`M17 7v10H7`,key:`6fjiku`}]]),J=e(t(),1),Y=n();function X(e){return e>=100?`$${e.toFixed(0)}`:e>=10?`$${e.toFixed(1)}`:`$${e.toFixed(2)}`}function Pe(e){return e>=1e3?`$${(e/1e3).toFixed(1)}k`:`$${e.toFixed(2)}`}function Fe(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:`${e}`}var Ie=[`job`,`explore-spec`,`quick-spec`,`ai-edit`,`chat-sidebar`,`spec-launcher`,`proposal`,`agent-studio`,`setup`,`smash`,`file-summary`,`loop`];function Le({data:e,loading:t,period:n}){let{t:r}=s(`analytics`),[i,a]=(0,J.useState)(0),o=(0,J.useRef)(0),c=(0,J.useRef)(null),l=(0,J.useRef)(0);if((0,J.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,Y.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,f=e.summary.totalTokens,p=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,w=e.summary.usageReportedRuns??(S?Math.max(0,d-C):d),ee=S&&d>0&&w===0&&C>0,T=w>0&&C>0,E=v>0?null:e.summary.deltaPct,D=e.trackingStartedAt,O=p>0,k=e.bySurface.map(e=>e.surface).filter(e=>!Ie.includes(e)),A=[...Ie,...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,Y.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-gradient-to-br from-card/80 to-card/40 p-5`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-end justify-between gap-3 mb-4`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`div`,{className:`text-[11px] uppercase tracking-wider text-muted-foreground mb-1 flex items-center gap-1.5`,children:[(0,Y.jsx)(`span`,{children:r(`hero.spending`)}),j&&(0,Y.jsxs)(`span`,{"data-testid":`hero-window-label`,className:`normal-case tracking-normal text-muted-foreground/70 font-normal`,children:[`· `,j]})]}),(0,Y.jsxs)(`div`,{className:`flex items-baseline gap-3`,children:[(0,Y.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?`—`:Pe(i)}),E!==null&&(0,Y.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,Y.jsx)(h,{className:`w-3 h-3`}):(0,Y.jsx)(Ne,{className:`w-3 h-3`}),r(`hero.vsPrev`,{pct:Math.abs(E).toFixed(0)})]})]}),(0,Y.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-1 tabular-nums flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{children:r(`hero.invocations`,{count:d})}),ee?(0,Y.jsx)(`span`,{"data-testid":`hero-usage-unavailable`,className:`text-muted-foreground/80 italic`,title:r(`hero.usageUnavailableTooltip`),children:r(`hero.usageUnavailable`)}):T&&f!=null?(0,Y.jsx)(`span`,{className:`text-muted-foreground/80 italic`,title:r(`hero.usagePartiallyUnavailableTooltip`),children:r(`hero.usagePartiallyUnavailable`,{tokens:Fe(f),count:C})}):f!=null&&f>0?(0,Y.jsx)(`span`,{className:`text-muted-foreground/80`,title:r(`hero.tokensTooltip`),children:r(`hero.tokens`,{tokens:Fe(f)})}):null,b&&(0,Y.jsx)(`span`,{className:`text-muted-foreground/80 italic`,title:r(`hero.costUnavailableTooltip`),children:r(`hero.costUnavailable`)}),x&&(0,Y.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,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground/70 italic`,title:r(`hero.includesEstimatedTooltip`,{amount:X(p)}),children:r(`hero.includesEstimated`,{amount:X(p)})})]})]}),d===0&&D&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:r(`hero.trackingStarted`,{date:D.slice(0,10)})})]}),d===0?(0,Y.jsxs)(`div`,{className:`rounded-lg border border-dashed border-border/40 p-6 text-center`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:r(`hero.emptyState`)}),(0,Y.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,Y.jsx)(`div`,{className:`rounded-lg border border-dashed border-border/40 p-4 text-xs text-muted-foreground/80`,children:r(`hero.costUnavailableTooltip`)}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.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,Y.jsx)(`div`,{className:`h-full ${g[e.surface].dot}`,style:{width:`${t}%`},title:r(`hero.segmentTitle`,{label:m[e.surface],value:X(e.costUsd)})},e.surface)})}),(0,Y.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,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 tabular-nums`,children:[(0,Y.jsx)(`span`,{className:`w-2 h-2 rounded-full ${g[e.surface].dot}`}),(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:m[e.surface]}),(0,Y.jsx)(`span`,{className:`text-foreground font-medium`,children:X(e.costUsd)}),(0,Y.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,Y.jsx)(`span`,{className:`text-muted-foreground/80`,children:e.count})]},e.surface))})]})]})}var Re={claude:`Claude`,codex:`Codex`,gemini:`Gemini`,kimi:`Kimi`},ze={claude:`bg-accent-info`,codex:`bg-accent-highlight`,gemini:`bg-accent-success`,kimi:`bg-purple-400`};function Be(e){return e>=100?`$${e.toFixed(0)}`:e>=10?`$${e.toFixed(1)}`:e>=.01?`$${e.toFixed(2)}`:`$${e.toFixed(4)}`}function Ve(e){return Re[e]??e}function He(e){return ze[e]??`bg-accent-secondary`}function Ue({data:e,loading:t}){let{t:n}=s(`analytics`);if(t&&!e)return(0,Y.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,Y.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,Y.jsx)(`div`,{className:`flex items-baseline justify-between mb-3`,children:(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-[11px] uppercase tracking-wider text-muted-foreground`,children:n(`providerCard.title`)}),(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground/70 mt-0.5`,children:(0,Y.jsx)(o,{ns:`analytics`,i18nKey:`providerCard.description`,components:{tilde:(0,Y.jsx)(`span`,{className:`font-medium`})}})})]})}),r===0&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:n(i?`providerCard.costUnavailableTooltip`:`providerCard.noCost`)}),r>0&&(0,Y.jsx)(Y.Fragment,{children:(0,Y.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?`~`:``}${Be(t)}`;return(0,Y.jsx)(`div`,{className:`h-full ${He(e.provider)}`,style:{width:`${i}%`},title:n(`providerCard.segmentTitle`,{label:Ve(e.provider),value:a,count:e.count})},e.provider)})})}),(0,Y.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2 ${r>0?``:`mt-3`}`,children:e.byProvider.map(e=>(0,Y.jsx)(We,{entry:e},e.provider))})]})}function We({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,Y.jsxs)(`div`,{className:`flex items-center gap-2.5 rounded-md border border-border/30 px-2.5 py-1.5`,children:[(0,Y.jsx)(`span`,{className:`w-2 h-2 rounded-full shrink-0 ${He(e.provider)}`}),(0,Y.jsx)(`span`,{className:`text-xs font-medium`,children:Ve(e.provider)}),(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:t(`runs`,{count:e.count})}),o?(0,Y.jsx)(`span`,{className:`ml-auto text-xs font-medium text-muted-foreground/80 italic`,title:t(`providerCard.costUnavailableTooltip`),children:t(`providerCard.costUnavailable`)}):(0,Y.jsxs)(`span`,{className:`ml-auto text-xs font-medium tabular-nums`,title:c?t(`providerCard.costPartiallyUnavailableTooltip`):void 0,children:[r?`~`:``,Be(n),c&&(0,Y.jsx)(`span`,{className:`ml-1 font-normal text-muted-foreground/80 italic`,children:t(`providerCard.costPartiallyUnavailable`,{count:i})})]})]})}var Ge=[`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 Ke(e,t){if(e==null)return{};var n,r,i=qe(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 qe(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 Je(e){var{option:t,isActive:n}=e,r=Ke(e,Ge);return typeof t==`string`?J.createElement(I,Z({option:J.createElement(Ee,Z({type:t},r)),isActive:n,shapeType:`symbols`},r)):J.createElement(I,Z({option:t,isActive:n,shapeType:`symbols`},r))}var Ye=U([(e,t,n,r,i,a,o)=>re(e,void 0,void 0,o),(e,t,n,r,i,a,o)=>ne(e,`xAxis`,t,o),(e,t,n,r,i,a,o)=>P(e,`xAxis`,t,o),(e,t,n,r,i,a,o)=>ne(e,`yAxis`,n,o),(e,t,n,r,i,a,o)=>P(e,`yAxis`,n,o),(e,t,n,r)=>k(e,`zAxis`,r,!1),U([E,(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 dt({displayedData:d,xAxis:t,yAxis:r,zAxis:a,scatterSettings:o,xAxisTicks:n,yAxisTicks:i,cells:s})}}),Xe=[`id`],Ze=[`onMouseEnter`,`onClick`,`onMouseLeave`],Qe=[`animationBegin`,`animationDuration`,`animationEasing`,`hide`,`isAnimationActive`,`legendType`,`lineJointType`,`lineType`,`shape`,`xAxisId`,`yAxisId`,`zAxisId`];function $e(e,t){if(e==null)return{};var n,r,i=et(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 et(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 tt(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?tt(Object(n),!0).forEach(function(t){nt(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):tt(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function nt(e,t,n){return(t=rt(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function rt(e){var t=it(e,`string`);return typeof t==`symbol`?t:t+``}function it(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 at=e=>{var{dataKey:t,name:n,fill:r,legendType:i,hide:a}=e;return[{inactive:a,dataKey:t,type:i,color:r,value:B(n,t),payload:e}]},ot=J.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:B(o,t),hide:s,type:c,color:a,unit:``,graphicalItemId:l}};return J.createElement(ke,{tooltipEntrySettings:u})});function st(e){var{points:t,props:n}=e,{line:r,lineType:i,lineJointType:a}=n;if(!r)return null;var o=ue(n),s=V(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}=ce(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=J.isValidElement(r)?J.cloneElement(r,h):typeof r==`function`?r(h):J.createElement(R,Q({},h,{type:a})),J.createElement(K,{className:`recharts-scatter-line`,key:`recharts-scatter-line`},l)}function ct(e){var{showLabels:t,points:n,children:r}=e,i=D(),a=(0,J.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 J.createElement(L,{value:t?a:void 0},r)}function lt(e){var{points:t,allOtherScatterProps:n}=e,{shape:r,activeShape:i,dataKey:a}=n,{id:o}=n,s=$e(n,Xe),c=ve(pe),{onMouseEnter:l,onClick:u,onMouseLeave:d}=n,f=$e(n,Ze),p=oe(l,a,o),m=Ae(d),h=je(u,a,o);if(!be(t))return null;var g=ue(s);return J.createElement(J.Fragment,null,J.createElement(st,{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,[A]:String(o)});return J.createElement(S,{key:`symbol-${e?.cx}-${e?.cy}-${e?.size}-${t}`,zIndex:a?te.activeDot:void 0},J.createElement(K,Q({className:`recharts-scatter-symbol`},ae(f,e,t),{onMouseEnter:p(e,t),onMouseLeave:m(e,t),onClick:h(e,t)}),J.createElement(Je,Q({option:s,isActive:a},l))))}))}function ut(e){var{previousPointsRef:t,props:n}=e,{points:r,isAnimationActive:i,animationBegin:a,animationDuration:o,animationEasing:s}=n,c=t.current,l=Me(n,`recharts-scatter-`),[u,d]=(0,J.useState)(!1),f=(0,J.useCallback)(()=>{d(!1)},[]),p=(0,J.useCallback)(()=>{d(!0)},[]),m=!u;return J.createElement(ct,{showLabels:m,points:r},n.children,J.createElement(C,{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:G(r.cx,t.cx,e),cy:t.cy==null?void 0:G(r.cy,t.cy,e),size:G(r.size,t.size,e)}):$($({},t),{},{size:G(0,t.size,e)})});return e>0&&(t.current=i),J.createElement(K,null,J.createElement(lt,{points:i,allOtherScatterProps:n,showLabels:m}))}),J.createElement(T,{label:n.label}))}function dt(e){var{displayedData:t,xAxis:n,yAxis:r,zAxis:i,scatterSettings:a,xAxisTicks:o,yAxisTicks:s,cells:c}=e,l=q(n.dataKey)?a.dataKey:n.dataKey,u=q(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=F(e,l),g=F(e,u),_=!q(d)&&F(e,d)||`-`,v=[{name:q(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:q(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=z({axis:n,ticks:o,bandSize:m,entry:e,index:t,dataKey:l}),b=z({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 ft=(e,t,n)=>({x:e.cx,y:e.cy,value:Number(n===`x`?e.node.x:e.node.y),errorVal:F(e,t)});function pt(e){var{hide:t,points:n,className:r,needClip:i,xAxisId:a,yAxisId:o,id:s}=e,c=(0,J.useRef)(null);if(t)return null;var l=_(`recharts-scatter`,r),u=s;return J.createElement(S,{zIndex:e.zIndex},J.createElement(K,{className:l,clipPath:i?`url(#clipPath-${u})`:void 0,id:s},i&&J.createElement(`defs`,null,J.createElement(ye,{clipPathId:u,xAxisId:a,yAxisId:o})),J.createElement(se,{xAxisId:a,yAxisId:o,data:n,dataPointFormatter:ft,errorBarOffset:0},J.createElement(K,{key:`recharts-scatter-symbols`},J.createElement(ut,{props:e,previousPointsRef:c})))))}var mt={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:te.scatter};function ht(e){var t=we(e,mt),{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=$e(t,Qe),{needClip:h}=Te(d,f),g=(0,J.useMemo)(()=>w(e.children,ee),[e.children]),_=Se(),v=ve(t=>Ye(t,d,f,p,e.id,g,_));return h==null||v==null?null:J.createElement(J.Fragment,null,J.createElement(ot,{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}),J.createElement(pt,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 gt(e){var t=we(e,mt),n=Se();return J.createElement(W,{id:t.id,type:`scatter`},e=>J.createElement(J.Fragment,null,J.createElement(ie,{legendPayload:at(t)}),J.createElement(de,{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}),J.createElement(ht,Q({},t,{id:e}))))}var _t=J.memo(gt,O);_t.displayName=`Scatter`;function vt(e){var t=Oe(),n=(0,J.useRef)(null);return(0,J.useLayoutEffect)(()=>{n.current===null?t(le(e)):n.current!==e&&t(ge({prev:n.current,next:e})),n.current=e},[e,t]),(0,J.useLayoutEffect)(()=>()=>{n.current&&=(t(xe(n.current)),null)},[t]),null}var yt={zAxisId:0,range:M.range,scale:M.scale,type:M.type};function bt(e){var t=we(e,yt);return J.createElement(vt,{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})}bt.displayName=`ZAxis`;var xt=[`item`],St=(0,J.forwardRef)((e,t)=>J.createElement(_e,{chartName:`ScatterChart`,defaultTooltipEventType:`item`,validateTooltipEventTypes:xt,tooltipPayloadSearcher:me,categoricalChartProps:e,ref:t}));function Ct({data:e,loading:t}){let{t:n}=s(`analytics`);if(t&&!e)return(0,Y.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,Y.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,Y.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider`,children:n(`timeline.title`)}),(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground/70`,children:l?n(`timeline.costPartiallyUnavailable`,{count:o}):n(`timeline.subtitle`)})]}),c?(0,Y.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,Y.jsx)(`div`,{className:`h-40 flex items-center justify-center text-xs text-muted-foreground/70`,children:n(`timeline.empty`)}):(0,Y.jsx)(`div`,{className:`h-[220px]`,children:(0,Y.jsx)(j,{width:`100%`,height:`100%`,children:(0,Y.jsxs)(De,{data:i,margin:{top:10,right:10,left:-8,bottom:0},children:[(0,Y.jsx)(he,{strokeDasharray:`2 4`,stroke:`currentColor`,className:`text-border/30`,vertical:!1}),(0,Y.jsx)(fe,{dataKey:`date`,tick:{fontSize:10},stroke:`currentColor`,className:`text-muted-foreground`}),(0,Y.jsx)(Ce,{tick:{fontSize:10},stroke:`currentColor`,className:`text-muted-foreground`,tickFormatter:e=>`$${e}`}),(0,Y.jsx)(N,{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,Y.jsx)(H,{dataKey:r.jobs,stackId:`a`,fill:`var(--accent-info, #5fa8d3)`}),(0,Y.jsx)(H,{dataKey:r.explore,stackId:`a`,fill:`var(--accent-highlight, #c084fc)`}),(0,Y.jsx)(H,{dataKey:r.quick,stackId:`a`,fill:`var(--accent-secondary, #f7768e)`}),(0,Y.jsx)(H,{dataKey:r.refine,stackId:`a`,fill:`var(--accent-success, #50fa7b)`}),(0,Y.jsx)(H,{dataKey:r.fileSummaries,stackId:`a`,fill:`var(--accent-warning, #f1fa8c)`}),(0,Y.jsx)(H,{dataKey:r.smash,stackId:`a`,fill:`var(--accent-highlight, #c084fc)`}),(0,Y.jsx)(H,{dataKey:r.loop,stackId:`a`,fill:`var(--accent-primary, #7aa2f7)`})]})})})]})}function wt(e){return e==null?`—`:e<.005?`$${e.toFixed(4)}`:e<1?`$${e.toFixed(3)}`:`$${e.toFixed(2)}`}function Tt(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 Et({values:e}){let t=Math.max(1e-4,...e);return(0,Y.jsx)(`div`,{className:`flex items-end gap-[1px] h-5`,children:e.map((e,n)=>(0,Y.jsx)(`div`,{className:`w-[3px] rounded-sm bg-foreground/40`,style:{height:`${Math.max(2,e/t*20)}px`}},n))})}function Dt({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,Y.jsxs)(`div`,{className:`flex-1 p-4 first:pr-2 last:pl-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,Y.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full ${n}`}),(0,Y.jsx)(`span`,{className:`text-xs font-medium uppercase tracking-wider text-muted-foreground`,children:t})]}),i?(0,Y.jsxs)(`div`,{className:`py-3`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-foreground`,children:r(`quickVsExplore.sparseCta`)}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:r(`quickVsExplore.runsSoFar`,{count:e.totalRuns})})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.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?`~`:``,wt(e.avgCostPerSpec)]}),(0,Y.jsx)(`div`,{className:`text-[11px] text-muted-foreground mt-0.5`,children:r(c?`quickVsExplore.costUnavailable`:`quickVsExplore.perSpec`)}),(0,Y.jsx)(`div`,{className:`mt-3`,children:(0,Y.jsx)(Et,{values:e.sparkline.length>0?e.sparkline:[0]})}),(0,Y.jsxs)(`div`,{className:`mt-3 space-y-0.5 text-xs tabular-nums text-muted-foreground`,children:[(0,Y.jsx)(`div`,{children:(0,Y.jsx)(o,{ns:`analytics`,i18nKey:`quickVsExplore.createdRuns`,values:{created:e.ticketsCreated,runs:e.totalRuns},components:{strong:(0,Y.jsx)(`span`,{className:`text-foreground font-medium`})}})}),(0,Y.jsx)(`div`,{children:r(`quickVsExplore.avgDuration`,{duration:Tt(e.avgDurationMs)})}),(0,Y.jsx)(`div`,{className:`truncate`,children:e.dominantModel??`—`})]})]})]})}function Ot({data:e,loading:t}){let{t:n}=s(`analytics`);if(t&&!e)return(0,Y.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,Y.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40`,children:[(0,Y.jsx)(`div`,{className:`px-4 pt-3 pb-1`,children:(0,Y.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider`,children:n(`quickVsExplore.title`)})}),(0,Y.jsxs)(`div`,{className:`flex divide-x divide-border/40`,children:[(0,Y.jsx)(Dt,{mode:r,label:n(`quickVsExplore.quick`),accentClass:`bg-accent-secondary`}),(0,Y.jsx)(Dt,{mode:i,label:n(`quickVsExplore.explore`),accentClass:`bg-accent-highlight`})]}),o&&(0,Y.jsx)(`div`,{className:`px-4 pb-3 -mt-1`,children:(0,Y.jsx)(`div`,{className:`text-center text-[11px] text-muted-foreground tabular-nums`,children:(0,Y.jsxs)(`span`,{className:`px-2`,children:[`━━━━━━ `,n(`quickVsExplore.ratio`,{ratio:a.toFixed(1)}),` ━━━━━━`]})})}),c&&(0,Y.jsx)(`div`,{className:`px-4 pb-3 -mt-1`,"data-testid":`quick-vs-explore-estimated-footnote`,children:(0,Y.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:n(`quickVsExplore.estimatedFootnote`)})})]})}function kt(e){return e<.005&&e>0?`$${e.toFixed(4)}`:e<1?`$${e.toFixed(3)}`:`$${e.toFixed(2)}`}function At(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function jt({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,Y.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card p-4`,"data-testid":`agent-missions-card`,children:[(0,Y.jsxs)(`div`,{className:`mb-3 flex items-center gap-2`,children:[(0,Y.jsx)(y,{className:`h-4 w-4 text-accent-highlight`}),(0,Y.jsx)(`h3`,{className:`text-sm font-medium`,children:n(`agentMissions.title`)}),(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:n(`agentMissions.subtitle`)})]}),(0,Y.jsxs)(`div`,{className:`flex items-baseline gap-3`,children:[(0,Y.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?`~`:``,kt(a.totalCostUsd)]}),l!==null&&(0,Y.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,Y.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:n(`agentMissions.turnsAndTokens`,{turns:a.turns,tokens:At(a.tokensIn+a.tokensOut)})}),o.length>0&&(0,Y.jsx)(`ul`,{className:`mt-3 space-y-1 border-t border-border/40 pt-2`,children:o.map(e=>(0,Y.jsxs)(`li`,{className:`flex items-center gap-2 text-xs`,children:[(0,Y.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-foreground/85`,children:e.title?.trim()||n(`agentMissions.untitled`)}),(0,Y.jsxs)(`span`,{className:`shrink-0 text-[10px] text-muted-foreground`,children:[e.turns,` · `,e.lastAt?v(new Date(e.lastAt),{addSuffix:!0,locale:i()}):`—`]}),(0,Y.jsxs)(`span`,{className:`shrink-0 tabular-nums font-medium`,children:[e.estimatedCostUsd>0?`~`:``,kt(e.costUsd)]})]},e.conversationId??`unknown`))})]})}function Mt({data:e,loading:t,onSelectModel:n,activeModel:r}){let{t:i}=s(`analytics`);if(t&&!e)return(0,Y.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,Y.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,Y.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider mb-3`,children:i(`models.title`)}),o.length===0?(0,Y.jsx)(`div`,{className:`h-32 flex items-center justify-center text-xs text-muted-foreground/70`,children:i(`models.empty`)}):(0,Y.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,Y.jsx)(`li`,{children:(0,Y.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,Y.jsxs)(`div`,{className:`flex items-center justify-between text-[12px] mb-1 tabular-nums`,children:[(0,Y.jsx)(`span`,{className:`truncate font-medium`,children:e.model}),(0,Y.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,Y.jsxs)(Y.Fragment,{children:[s?`~`:``,`$`,e.costUsd.toFixed(2),` · `,e.count,d&&(0,Y.jsx)(`span`,{className:`ml-1 italic`,children:i(`models.costPartiallyUnavailable`,{count:c})})]})})]}),(0,Y.jsx)(`div`,{className:`h-1.5 rounded-full bg-background-deep overflow-hidden`,children:(0,Y.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,Y.jsx)(`li`,{"data-testid":`model-others`,children:(0,Y.jsxs)(`div`,{className:`w-full rounded-md px-2 py-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between text-[12px] mb-1 tabular-nums`,children:[(0,Y.jsx)(`span`,{className:`truncate font-medium text-muted-foreground`,children:i(`models.others`)}),(0,Y.jsxs)(`span`,{className:`text-muted-foreground`,children:[`$`,l.toFixed(2)]})]}),(0,Y.jsx)(`div`,{className:`h-1.5 rounded-full bg-background-deep overflow-hidden`,children:(0,Y.jsx)(`div`,{className:`h-full bg-foreground/25`,style:{width:`${a>0?l/a*100:0}%`}})})]})})]})]})}var Nt={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)`},Pt=Object.keys(m);function Ft({data:e,loading:t,onSelectPoint:n}){let{t:r}=s(`analytics`);if(t&&!e)return(0,Y.jsx)(`div`,{className:`h-[260px] rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let i=Pt,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,f=e.scatterTotal??e.scatter.length;return(0,Y.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,Y.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider`,children:r(`scatter.title`)}),(0,Y.jsx)(`div`,{className:`flex flex-wrap items-center gap-2 text-[10px]`,children:i.map(e=>(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,Y.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full`,style:{background:Nt[e]}}),(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:m[e]})]},e))})]}),d&&!o&&(0,Y.jsx)(`div`,{"data-testid":`scatter-truncation-notice`,className:`mb-2 text-[10px] text-accent-warning`,children:r(`scatter.truncated`,{shown:e.scatter.length,total:f})}),u&&(0,Y.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,Y.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,Y.jsx)(`div`,{className:`h-40 flex items-center justify-center text-xs text-muted-foreground/70`,children:r(`scatter.empty`)}):(0,Y.jsx)(`div`,{className:`h-[260px]`,children:(0,Y.jsx)(j,{width:`100%`,height:`100%`,children:(0,Y.jsxs)(St,{margin:{top:10,right:10,left:-8,bottom:5},children:[(0,Y.jsx)(he,{strokeDasharray:`2 4`,stroke:`currentColor`,className:`text-border/30`}),(0,Y.jsx)(fe,{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,Y.jsx)(Ce,{type:`number`,dataKey:`y`,name:`cost`,tick:{fontSize:10},stroke:`currentColor`,className:`text-muted-foreground`,tickFormatter:e=>`$${e.toFixed(e<1?2:0)}`}),(0,Y.jsx)(bt,{range:[40,80]}),(0,Y.jsx)(N,{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,Y.jsx)(_t,{data:e.points,fill:Nt[e.surface],onClick:e=>{let t=e;t?.raw&&n(t.raw)}},e.surface))]})})})]})}function It({data:e,loading:t,onSelectTicket:n}){let{t:r}=s(`analytics`);if(t&&!e)return(0,Y.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,Y.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,Y.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider mb-3`,children:r(`topTickets.title`)}),i.length===0?(0,Y.jsx)(`div`,{className:`h-32 flex items-center justify-center text-xs text-muted-foreground/70`,children:r(`topTickets.empty`)}):(0,Y.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:m[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,Y.jsx)(`li`,{children:(0,Y.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,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`div`,{className:`text-sm truncate`,children:o}),(0,Y.jsx)(`div`,{className:`text-[11px] text-muted-foreground truncate`,children:i||`—`})]}),(0,Y.jsxs)(`div`,{className:`text-right tabular-nums`,children:[(0,Y.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,Y.jsx)(`div`,{className:`text-[10px] text-muted-foreground italic`,children:r(`topTickets.costPartiallyUnavailable`,{count:c})}),(0,Y.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:r(`runs`,{count:e.totalRuns})})]})]})},`${e.ticketId??`u`}-${t}`)})})]})}var Lt={claude:`Claude`,codex:`Codex`,gemini:`Gemini`,kimi:`Kimi`};function Rt(e){return Lt[e]??e}function zt(e){return!!e&&!(e in Lt)}function Bt(e){return e==null?`—`:e<.005?`$${e.toFixed(4)}`:`$${e.toFixed(2)}`}function Vt(e){return e==null?`—`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function Ht(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 Ut(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 Wt(e,t){if(e.model)return e.model;if(!Ht(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 Gt({rows:e,loading:t,truncated:n,totalAvailable:r,tableFilters:i,onTableFiltersChange:a}){let{t:o}=s(`analytics`),[c,l]=(0,J.useState)(null),u=Ut(e),d=new Set(e.map(e=>e.provider??`claude`)).size>1,f=n||r>e.length;return(0,Y.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 mb-3`,children:[(0,Y.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider`,children:o(`table.title`)}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-[11px]`,children:[(0,Y.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,Y.jsx)(`option`,{value:``,children:o(`table.allStatus`)}),(0,Y.jsx)(`option`,{value:`success`,children:o(`table.success`)}),(0,Y.jsx)(`option`,{value:`failed`,children:o(`table.failed`)}),(0,Y.jsx)(`option`,{value:`aborted`,children:o(`table.aborted`)})]}),(0,Y.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,Y.jsx)(`div`,{className:`h-32 rounded bg-card/30 animate-pulse`}):e.length===0?(0,Y.jsx)(`div`,{className:`h-32 flex items-center justify-center text-xs text-muted-foreground/70`,children:o(`table.empty`)}):(0,Y.jsx)(`div`,{className:`overflow-x-auto`,children:(0,Y.jsxs)(`table`,{className:`w-full text-[12px] tabular-nums`,children:[(0,Y.jsx)(`thead`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:(0,Y.jsxs)(`tr`,{className:`text-left`,children:[(0,Y.jsx)(`th`,{className:`font-medium px-2 py-2`,children:o(`table.colSurface`)}),(0,Y.jsx)(`th`,{className:`font-medium px-2 py-2`,children:o(`table.colTicket`)}),(0,Y.jsx)(`th`,{className:`font-medium px-2 py-2 text-right`,children:o(`table.colCost`)}),(0,Y.jsx)(`th`,{className:`font-medium px-2 py-2 text-right`,children:o(`table.colTurns`)}),(0,Y.jsx)(`th`,{className:`font-medium px-2 py-2 text-right`,children:o(`table.colTokens`)}),(0,Y.jsx)(`th`,{className:`font-medium px-2 py-2`,children:o(`table.colModel`)}),d&&(0,Y.jsx)(`th`,{className:`font-medium px-2 py-2`,children:o(`table.colProvider`)}),(0,Y.jsx)(`th`,{className:`font-medium px-2 py-2`,children:o(`table.colStatus`)}),(0,Y.jsx)(`th`,{className:`font-medium px-2 py-2`,children:o(`table.colStarted`)})]})}),(0,Y.jsx)(`tbody`,{children:e.map(e=>{let t=e.surface,n=g[t],r=(e.tokens_in??0)+(e.tokens_out??0)+(e.tokens_cache_read??0)+(e.tokens_cache_create??0),i=Ht(e),a=i?o(`table.contractLayer`):m[t],s=Wt(e,u);return(0,Y.jsxs)(`tr`,{onClick:()=>l(c===e.id?null:e.id),className:`border-t border-border/30 hover:bg-accent/30 cursor-pointer`,children:[(0,Y.jsx)(`td`,{className:`px-2 py-2`,children:(0,Y.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,Y.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full ${n.dot}`}),a]})}),(0,Y.jsx)(`td`,{className:`px-2 py-2 max-w-[260px]`,children:e.ticket_id==null?e.ticket_title?(0,Y.jsx)(`span`,{className:`truncate block text-muted-foreground/90 italic`,title:o(`table.provisionalTitleTooltip`),children:e.ticket_title}):(0,Y.jsx)(`span`,{className:`text-muted-foreground/70`,children:`—`}):(0,Y.jsxs)(`span`,{className:`truncate block`,children:[`#`,e.ticket_id,` `,i?(0,Y.jsx)(`span`,{className:`text-muted-foreground/90`,children:o(`table.contractLayerRefinement`)}):e.ticket_title??(0,Y.jsx)(`span`,{className:`text-muted-foreground/70 italic`,children:o(`table.deleted`)})]})}),(0,Y.jsx)(`td`,{className:`px-2 py-2 text-right font-medium`,children:e.total_cost_usd_estimated===1&&e.total_cost_usd!=null?(0,Y.jsxs)(`span`,{title:o(`table.estimatedCostTooltip`),className:`text-muted-foreground/90`,children:[`~`,Bt(e.total_cost_usd)]}):e.total_cost_usd==null&&zt(e.provider)?(0,Y.jsx)(`span`,{title:o(`table.costUnknownLocalTooltip`),"data-testid":`cost-unknown-local`,className:`text-muted-foreground/70`,children:`—`}):Bt(e.total_cost_usd)}),(0,Y.jsx)(`td`,{className:`px-2 py-2 text-right`,children:Vt(e.num_turns)}),(0,Y.jsx)(`td`,{className:`px-2 py-2 text-right`,children:r>0?Vt(r):`—`}),(0,Y.jsxs)(`td`,{className:`px-2 py-2 max-w-[180px] truncate`,children:[s??`—`,s&&!e.model?(0,Y.jsx)(`span`,{className:`ml-1 text-[10px] text-muted-foreground/70`,children:o(`table.inferred`)}):null]}),d&&(0,Y.jsx)(`td`,{className:`px-2 py-2 text-muted-foreground`,children:Rt(e.provider??`claude`)}),(0,Y.jsxs)(`td`,{className:`px-2 py-2`,children:[e.status===`success`?(0,Y.jsx)(`span`,{className:`text-accent-success/90`,children:`●`}):e.status===`failed`?(0,Y.jsx)(`span`,{className:`text-accent-warning`,children:`⚠`}):(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`○`}),(0,Y.jsx)(`span`,{className:`ml-1 text-muted-foreground`,children:o(`table.statusValue.${e.status}`)})]}),(0,Y.jsx)(`td`,{className:`px-2 py-2 text-muted-foreground`,children:e.started_at.slice(0,16).replace(`T`,` `)})]},e.id)})})]})}),f&&e.length>0&&(0,Y.jsx)(`div`,{className:`mt-2 text-[11px] text-muted-foreground/80`,children:o(`table.truncated`,{shown:e.length,total:r.toLocaleString()})})]})}var Kt=[{value:`7d`,labelKey:`periods.d7`},{value:`30d`,labelKey:`periods.d30`},{value:`90d`,labelKey:`periods.d90`},{value:`all`,labelKey:`periods.all`}],qt=[{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 Jt(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 Yt(){let{t:e}=s(`analytics`),{activeProjectId:t,projects:n}=d(),[i,o]=r(),c=n.find(e=>e.id===t),m=c?u(c):[`claude`],h=m.length>1,g=i.get(`period`)??`30d`,_=(i.get(`surface`)??``).split(`,`).filter(Boolean),v=(i.get(`provider`)??``).split(`,`).filter(Boolean),y=i.get(`ticketId`),S=(i.get(`model`)??``).split(`,`).filter(Boolean),C=(i.get(`modelProvider`)??``).split(`,`).filter(Boolean),w=S.length>0&&S.length===C.length?S.map((e,t)=>({provider:C[t],model:e})):void 0,ee=(0,J.useMemo)(()=>-new Date().getTimezoneOffset(),[]),[T,E]=(0,J.useState)({period:g,surface:_.length>0?_:void 0,provider:v.length>0?v:void 0,ticketId:y?Number(y):void 0,model:S.length>0?S:void 0,modelKeys:w,tzOffsetMinutes:ee}),[D,O]=(0,J.useState)(null),[k,A]=(0,J.useState)(!0),[j,te]=(0,J.useState)(null),[M,ne]=(0,J.useState)({}),[N,P]=(0,J.useState)(null),[F,re]=(0,J.useState)(`recency`),I=(0,J.useRef)(new Map),L=(0,J.useRef)(0);(0,J.useEffect)(()=>{let e=new URLSearchParams;e.set(`period`,T.period),T.surface&&T.surface.length>0&&e.set(`surface`,T.surface.join(`,`)),T.provider&&T.provider.length>0&&e.set(`provider`,T.provider.join(`,`)),T.ticketId&&e.set(`ticketId`,String(T.ticketId)),T.model&&T.model.length>0&&(e.set(`model`,T.model.join(`,`)),T.modelKeys&&T.modelKeys.length===T.model.length&&e.set(`modelProvider`,T.modelKeys.map(e=>e.provider).join(`,`))),o(e,{replace:!0})},[T.period,T.surface,T.provider,T.ticketId,T.model,T.modelKeys,o]);let R=(0,J.useCallback)(async()=>{if(!t)return;let e=++L.current;te(null);let n=`${t}:${Jt(T)}`,r=I.current.get(n);r?(O(r),A(!1)):A(!0);try{let t=await fetch(`${l()}/spending?${Jt(T)}`);if(!t.ok)throw Error(`HTTP ${t.status}`);if(e!==L.current)return;let r=await t.json();I.current.set(n,r),O(r),A(!1)}catch(t){if(e!==L.current)return;te(t.message),A(!1)}},[t,T]),z=(0,J.useRef)(0),B=(0,J.useCallback)(async()=>{if(!t)return;let e=++z.current,n={...T};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=F;try{let t=await fetch(`${l()}/invocations?${Jt(n)}&limit=100`);if(!t.ok)throw Error(`HTTP ${t.status}`);let r=await t.json();if(e!==z.current)return;P(r)}catch{if(e!==z.current)return;P(null)}},[t,T,M,F]),ie=(0,J.useRef)(t);(0,J.useEffect)(()=>{ie.current!==t&&(ie.current=t,O(null),P(null),A(!0))},[t]),(0,J.useEffect)(()=>{R()},[R]),(0,J.useEffect)(()=>{B()},[B]);let V=(0,J.useRef)(null),H=a();(0,J.useEffect)(()=>{let e=`analytics-spending`;return H.registerHandler(e,e=>{let n=e;n.type===`spending.invalidated`&&n.projectId===t&&(V.current&&clearTimeout(V.current),V.current=setTimeout(()=>{I.current.clear(),R(),B()},500))}),()=>{H.unregisterHandler(e),V.current&&clearTimeout(V.current)}},[H,t,R,B]);function ae(e){if(e===`all`){E(e=>({...e,surface:void 0}));return}E(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 oe=(0,J.useCallback)((e,t)=>{E(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=(D?.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}})},[D]);function se(){E(e=>({...e,model:void 0,modelKeys:void 0}))}function ce(e){if(e===`all`){E(e=>({...e,provider:void 0}));return}E(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 U=T.surface,le=!U||U.length===0,W=T.provider,ue=!W||W.length===0,de=(0,J.useMemo)(()=>{let e={period:T.period};return T.surface&&T.surface.length>0&&(e.surface=T.surface.join(`,`)),T.provider&&T.provider.length>0&&(e.provider=T.provider.join(`,`)),T.ticketId&&(e.ticketId=String(T.ticketId)),e},[T]),fe=D?D.summary.totalRuns===0:!1;return(0,Y.jsxs)(`div`,{className:`flex flex-col gap-6 p-4 pb-12`,children:[(0,Y.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,Y.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(`h1`,{className:`text-base font-semibold tracking-tight`,children:e(`page.title`)}),T.ticketId&&(0,Y.jsx)(`button`,{type:`button`,onClick:()=>E(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:T.ticketId})}),T.model&&T.model.length>0&&(0,Y.jsxs)(`button`,{type:`button`,"data-testid":`analytics-model-chip`,onClick:se,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:T.model[0]}),(0,Y.jsx)(`span`,{"aria-hidden":!0,className:`opacity-70`,children:`×`})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`div`,{className:`flex items-center gap-1 rounded-md border border-border/60 bg-card/40 p-0.5`,children:Kt.map(t=>(0,Y.jsx)(`button`,{type:`button`,onClick:()=>E(e=>({...e,period:t.value})),className:`px-2.5 h-6 rounded text-[11px] font-medium transition-colors ${T.period===t.value?`bg-accent text-foreground`:`text-muted-foreground hover:text-foreground`}`,children:e(t.labelKey)},t.value))}),(0,Y.jsx)(x,{baseUrl:`${l()}/analytics/export`,params:de,disabled:fe}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>{I.current.clear(),R(),B()},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,Y.jsx)(b,{className:`w-3 h-3`})})]})]}),(0,Y.jsx)(`div`,{className:`mt-3 flex flex-wrap items-center gap-1.5`,children:qt.map(t=>(0,Y.jsx)(`button`,{type:`button`,onClick:()=>ae(t.value),className:`h-7 px-3 rounded-full text-[11px] font-medium transition-all ${(t.value===`all`?le:U?.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))}),h&&(0,Y.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-1.5`,"data-testid":`analytics-provider-chips`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-muted-foreground/70 mr-1`,children:e(`page.engine`)}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>ce(`all`),className:`h-7 px-3 rounded-full text-[11px] font-medium transition-all ${ue?`bg-foreground/10 text-foreground ring-1 ring-foreground/20`:`text-muted-foreground hover:text-foreground hover:bg-accent/40`}`,children:e(`page.all`)}),m.map(t=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>ce(t),className:`h-7 px-3 rounded-full text-[11px] font-medium transition-all ${W?.includes(t)??!1?`bg-foreground/10 text-foreground ring-1 ring-foreground/20`:`text-muted-foreground hover:text-foreground hover:bg-accent/40`}`,children:[p(t),f(t)&&(0,Y.jsx)(`span`,{className:`ml-1 rounded-full bg-accent-secondary/15 px-1.5 text-[9px] uppercase tracking-wide text-accent-secondary`,children:e(`page.localEngine`)})]},t))]})]}),j&&(0,Y.jsxs)(`div`,{className:`rounded-lg border border-accent-warning/30 bg-accent-warning/10 p-4 flex items-center justify-between`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-accent-warning`,children:e(`page.failedToLoad`,{error:j})}),(0,Y.jsxs)(`button`,{onClick:()=>R(),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,Y.jsx)(b,{className:`w-3 h-3`}),e(`common:actions.retry`)]})]}),(0,Y.jsx)(Le,{data:D,loading:k,period:T.period}),(0,Y.jsx)(Ue,{data:D,loading:k}),(0,Y.jsx)(Ct,{data:D,loading:k}),(0,Y.jsx)(jt,{data:D,loading:k}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4`,children:[(0,Y.jsx)(Ot,{data:D,loading:k}),(0,Y.jsx)(Mt,{data:D,loading:k,onSelectModel:oe,activeModel:T.model?.[0]})]}),(0,Y.jsx)(Ft,{data:D,loading:k,onSelectPoint:e=>{ne(e=>({...e})),E(t=>({...t,ticketId:e.ticketId??void 0}))}}),(0,Y.jsx)(It,{data:D,loading:k,onSelectTicket:e=>E(t=>({...t,ticketId:e??void 0}))}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-end gap-1.5`,"data-testid":`analytics-table-sort`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-muted-foreground/70 mr-1`,children:e(`table.sortLabel`)}),[`recency`,`cost`].map(t=>(0,Y.jsx)(`button`,{type:`button`,"data-testid":`analytics-table-sort-${t}`,"aria-pressed":F===t,onClick:()=>re(t),className:`h-6 px-2.5 rounded-full text-[11px] font-medium transition-all ${F===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,Y.jsx)(Gt,{rows:N?.rows??[],loading:k&&!N,truncated:(N?.truncated??!1)||(N?.totalAvailable??0)>(N?.rows.length??0),totalAvailable:N?.totalAvailable??0,tableFilters:M,onTableFiltersChange:ne})]})]})}export{Yt 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-BN3Lmehi.js";import{t as o}from"./Trans-BLljsfHR.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-BJ8IRBRt.js";import{r as f,s as p}from"./provider-capabilities-Vi1ZGvAK.js";import{n as m,r as h,t as g}from"./spending-DJBbdJyD.js";import{t as _}from"./clsx-CjueKrWZ.js";import{t as v}from"./formatDistanceToNow-CbQZkD8M.js";import{Ut as y,gt as b}from"./index-CjAPu3wb.js";import{t as x}from"./ExportDropdown-IPutNYvD.js";import{A as S,B as C,C as w,D as ee,E as T,F as E,G as D,H as O,I as k,J as A,K as j,L as te,M,N as ne,O as N,P,Q as F,R as re,S as I,T as L,V as R,X as z,Z as B,_ as ie,_t as V,a as H,at as ae,b as oe,c as se,ct as ce,et as U,f as le,g as W,gt as ue,h as de,i as fe,j as pe,k as me,l as he,lt as G,m as ge,n as _e,nt as ve,o as ye,ot as be,p as xe,pt as K,q as Se,r as Ce,rt as we,s as Te,st as Ee,t as De,tt as Oe,ut as q,v as ke,x as Ae,y as je,z as Me}from"./BarChart-nBOMNfiy.js";var Ne=c(`arrow-down-right`,[[`path`,{d:`m7 7 10 10`,key:`1fmybs`}],[`path`,{d:`M17 7v10H7`,key:`6fjiku`}]]),J=e(t(),1),Y=n();function X(e){return e>=100?`$${e.toFixed(0)}`:e>=10?`$${e.toFixed(1)}`:`$${e.toFixed(2)}`}function Pe(e){return e>=1e3?`$${(e/1e3).toFixed(1)}k`:`$${e.toFixed(2)}`}function Fe(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:`${e}`}var Ie=[`job`,`explore-spec`,`quick-spec`,`ai-edit`,`chat-sidebar`,`spec-launcher`,`proposal`,`agent-studio`,`setup`,`smash`,`file-summary`,`loop`];function Le({data:e,loading:t,period:n}){let{t:r}=s(`analytics`),[i,a]=(0,J.useState)(0),o=(0,J.useRef)(0),c=(0,J.useRef)(null),l=(0,J.useRef)(0);if((0,J.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,Y.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,f=e.summary.totalTokens,p=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,w=e.summary.usageReportedRuns??(S?Math.max(0,d-C):d),ee=S&&d>0&&w===0&&C>0,T=w>0&&C>0,E=v>0?null:e.summary.deltaPct,D=e.trackingStartedAt,O=p>0,k=e.bySurface.map(e=>e.surface).filter(e=>!Ie.includes(e)),A=[...Ie,...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,Y.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-gradient-to-br from-card/80 to-card/40 p-5`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-end justify-between gap-3 mb-4`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`div`,{className:`text-[11px] uppercase tracking-wider text-muted-foreground mb-1 flex items-center gap-1.5`,children:[(0,Y.jsx)(`span`,{children:r(`hero.spending`)}),j&&(0,Y.jsxs)(`span`,{"data-testid":`hero-window-label`,className:`normal-case tracking-normal text-muted-foreground/70 font-normal`,children:[`· `,j]})]}),(0,Y.jsxs)(`div`,{className:`flex items-baseline gap-3`,children:[(0,Y.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?`—`:Pe(i)}),E!==null&&(0,Y.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,Y.jsx)(h,{className:`w-3 h-3`}):(0,Y.jsx)(Ne,{className:`w-3 h-3`}),r(`hero.vsPrev`,{pct:Math.abs(E).toFixed(0)})]})]}),(0,Y.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-1 tabular-nums flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{children:r(`hero.invocations`,{count:d})}),ee?(0,Y.jsx)(`span`,{"data-testid":`hero-usage-unavailable`,className:`text-muted-foreground/80 italic`,title:r(`hero.usageUnavailableTooltip`),children:r(`hero.usageUnavailable`)}):T&&f!=null?(0,Y.jsx)(`span`,{className:`text-muted-foreground/80 italic`,title:r(`hero.usagePartiallyUnavailableTooltip`),children:r(`hero.usagePartiallyUnavailable`,{tokens:Fe(f),count:C})}):f!=null&&f>0?(0,Y.jsx)(`span`,{className:`text-muted-foreground/80`,title:r(`hero.tokensTooltip`),children:r(`hero.tokens`,{tokens:Fe(f)})}):null,b&&(0,Y.jsx)(`span`,{className:`text-muted-foreground/80 italic`,title:r(`hero.costUnavailableTooltip`),children:r(`hero.costUnavailable`)}),x&&(0,Y.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,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground/70 italic`,title:r(`hero.includesEstimatedTooltip`,{amount:X(p)}),children:r(`hero.includesEstimated`,{amount:X(p)})})]})]}),d===0&&D&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:r(`hero.trackingStarted`,{date:D.slice(0,10)})})]}),d===0?(0,Y.jsxs)(`div`,{className:`rounded-lg border border-dashed border-border/40 p-6 text-center`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:r(`hero.emptyState`)}),(0,Y.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,Y.jsx)(`div`,{className:`rounded-lg border border-dashed border-border/40 p-4 text-xs text-muted-foreground/80`,children:r(`hero.costUnavailableTooltip`)}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.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,Y.jsx)(`div`,{className:`h-full ${g[e.surface].dot}`,style:{width:`${t}%`},title:r(`hero.segmentTitle`,{label:m[e.surface],value:X(e.costUsd)})},e.surface)})}),(0,Y.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,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 tabular-nums`,children:[(0,Y.jsx)(`span`,{className:`w-2 h-2 rounded-full ${g[e.surface].dot}`}),(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:m[e.surface]}),(0,Y.jsx)(`span`,{className:`text-foreground font-medium`,children:X(e.costUsd)}),(0,Y.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,Y.jsx)(`span`,{className:`text-muted-foreground/80`,children:e.count})]},e.surface))})]})]})}var Re={claude:`Claude`,codex:`Codex`,gemini:`Gemini`,kimi:`Kimi`},ze={claude:`bg-accent-info`,codex:`bg-accent-highlight`,gemini:`bg-accent-success`,kimi:`bg-purple-400`};function Be(e){return e>=100?`$${e.toFixed(0)}`:e>=10?`$${e.toFixed(1)}`:e>=.01?`$${e.toFixed(2)}`:`$${e.toFixed(4)}`}function Ve(e){return Re[e]??e}function He(e){return ze[e]??`bg-accent-secondary`}function Ue({data:e,loading:t}){let{t:n}=s(`analytics`);if(t&&!e)return(0,Y.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,Y.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,Y.jsx)(`div`,{className:`flex items-baseline justify-between mb-3`,children:(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-[11px] uppercase tracking-wider text-muted-foreground`,children:n(`providerCard.title`)}),(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground/70 mt-0.5`,children:(0,Y.jsx)(o,{ns:`analytics`,i18nKey:`providerCard.description`,components:{tilde:(0,Y.jsx)(`span`,{className:`font-medium`})}})})]})}),r===0&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:n(i?`providerCard.costUnavailableTooltip`:`providerCard.noCost`)}),r>0&&(0,Y.jsx)(Y.Fragment,{children:(0,Y.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?`~`:``}${Be(t)}`;return(0,Y.jsx)(`div`,{className:`h-full ${He(e.provider)}`,style:{width:`${i}%`},title:n(`providerCard.segmentTitle`,{label:Ve(e.provider),value:a,count:e.count})},e.provider)})})}),(0,Y.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2 ${r>0?``:`mt-3`}`,children:e.byProvider.map(e=>(0,Y.jsx)(We,{entry:e},e.provider))})]})}function We({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,Y.jsxs)(`div`,{className:`flex items-center gap-2.5 rounded-md border border-border/30 px-2.5 py-1.5`,children:[(0,Y.jsx)(`span`,{className:`w-2 h-2 rounded-full shrink-0 ${He(e.provider)}`}),(0,Y.jsx)(`span`,{className:`text-xs font-medium`,children:Ve(e.provider)}),(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:t(`runs`,{count:e.count})}),o?(0,Y.jsx)(`span`,{className:`ml-auto text-xs font-medium text-muted-foreground/80 italic`,title:t(`providerCard.costUnavailableTooltip`),children:t(`providerCard.costUnavailable`)}):(0,Y.jsxs)(`span`,{className:`ml-auto text-xs font-medium tabular-nums`,title:c?t(`providerCard.costPartiallyUnavailableTooltip`):void 0,children:[r?`~`:``,Be(n),c&&(0,Y.jsx)(`span`,{className:`ml-1 font-normal text-muted-foreground/80 italic`,children:t(`providerCard.costPartiallyUnavailable`,{count:i})})]})]})}var Ge=[`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 Ke(e,t){if(e==null)return{};var n,r,i=qe(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 qe(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 Je(e){var{option:t,isActive:n}=e,r=Ke(e,Ge);return typeof t==`string`?J.createElement(I,Z({option:J.createElement(Ee,Z({type:t},r)),isActive:n,shapeType:`symbols`},r)):J.createElement(I,Z({option:t,isActive:n,shapeType:`symbols`},r))}var Ye=U([(e,t,n,r,i,a,o)=>re(e,void 0,void 0,o),(e,t,n,r,i,a,o)=>ne(e,`xAxis`,t,o),(e,t,n,r,i,a,o)=>P(e,`xAxis`,t,o),(e,t,n,r,i,a,o)=>ne(e,`yAxis`,n,o),(e,t,n,r,i,a,o)=>P(e,`yAxis`,n,o),(e,t,n,r)=>k(e,`zAxis`,r,!1),U([E,(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 dt({displayedData:d,xAxis:t,yAxis:r,zAxis:a,scatterSettings:o,xAxisTicks:n,yAxisTicks:i,cells:s})}}),Xe=[`id`],Ze=[`onMouseEnter`,`onClick`,`onMouseLeave`],Qe=[`animationBegin`,`animationDuration`,`animationEasing`,`hide`,`isAnimationActive`,`legendType`,`lineJointType`,`lineType`,`shape`,`xAxisId`,`yAxisId`,`zAxisId`];function $e(e,t){if(e==null)return{};var n,r,i=et(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 et(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 tt(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?tt(Object(n),!0).forEach(function(t){nt(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):tt(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function nt(e,t,n){return(t=rt(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function rt(e){var t=it(e,`string`);return typeof t==`symbol`?t:t+``}function it(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 at=e=>{var{dataKey:t,name:n,fill:r,legendType:i,hide:a}=e;return[{inactive:a,dataKey:t,type:i,color:r,value:B(n,t),payload:e}]},ot=J.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:B(o,t),hide:s,type:c,color:a,unit:``,graphicalItemId:l}};return J.createElement(ke,{tooltipEntrySettings:u})});function st(e){var{points:t,props:n}=e,{line:r,lineType:i,lineJointType:a}=n;if(!r)return null;var o=ue(n),s=V(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}=ce(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=J.isValidElement(r)?J.cloneElement(r,h):typeof r==`function`?r(h):J.createElement(R,Q({},h,{type:a})),J.createElement(K,{className:`recharts-scatter-line`,key:`recharts-scatter-line`},l)}function ct(e){var{showLabels:t,points:n,children:r}=e,i=D(),a=(0,J.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 J.createElement(L,{value:t?a:void 0},r)}function lt(e){var{points:t,allOtherScatterProps:n}=e,{shape:r,activeShape:i,dataKey:a}=n,{id:o}=n,s=$e(n,Xe),c=ve(pe),{onMouseEnter:l,onClick:u,onMouseLeave:d}=n,f=$e(n,Ze),p=oe(l,a,o),m=Ae(d),h=je(u,a,o);if(!be(t))return null;var g=ue(s);return J.createElement(J.Fragment,null,J.createElement(st,{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,[A]:String(o)});return J.createElement(S,{key:`symbol-${e?.cx}-${e?.cy}-${e?.size}-${t}`,zIndex:a?te.activeDot:void 0},J.createElement(K,Q({className:`recharts-scatter-symbol`},ae(f,e,t),{onMouseEnter:p(e,t),onMouseLeave:m(e,t),onClick:h(e,t)}),J.createElement(Je,Q({option:s,isActive:a},l))))}))}function ut(e){var{previousPointsRef:t,props:n}=e,{points:r,isAnimationActive:i,animationBegin:a,animationDuration:o,animationEasing:s}=n,c=t.current,l=Me(n,`recharts-scatter-`),[u,d]=(0,J.useState)(!1),f=(0,J.useCallback)(()=>{d(!1)},[]),p=(0,J.useCallback)(()=>{d(!0)},[]),m=!u;return J.createElement(ct,{showLabels:m,points:r},n.children,J.createElement(C,{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:G(r.cx,t.cx,e),cy:t.cy==null?void 0:G(r.cy,t.cy,e),size:G(r.size,t.size,e)}):$($({},t),{},{size:G(0,t.size,e)})});return e>0&&(t.current=i),J.createElement(K,null,J.createElement(lt,{points:i,allOtherScatterProps:n,showLabels:m}))}),J.createElement(T,{label:n.label}))}function dt(e){var{displayedData:t,xAxis:n,yAxis:r,zAxis:i,scatterSettings:a,xAxisTicks:o,yAxisTicks:s,cells:c}=e,l=q(n.dataKey)?a.dataKey:n.dataKey,u=q(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=F(e,l),g=F(e,u),_=!q(d)&&F(e,d)||`-`,v=[{name:q(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:q(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=z({axis:n,ticks:o,bandSize:m,entry:e,index:t,dataKey:l}),b=z({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 ft=(e,t,n)=>({x:e.cx,y:e.cy,value:Number(n===`x`?e.node.x:e.node.y),errorVal:F(e,t)});function pt(e){var{hide:t,points:n,className:r,needClip:i,xAxisId:a,yAxisId:o,id:s}=e,c=(0,J.useRef)(null);if(t)return null;var l=_(`recharts-scatter`,r),u=s;return J.createElement(S,{zIndex:e.zIndex},J.createElement(K,{className:l,clipPath:i?`url(#clipPath-${u})`:void 0,id:s},i&&J.createElement(`defs`,null,J.createElement(ye,{clipPathId:u,xAxisId:a,yAxisId:o})),J.createElement(se,{xAxisId:a,yAxisId:o,data:n,dataPointFormatter:ft,errorBarOffset:0},J.createElement(K,{key:`recharts-scatter-symbols`},J.createElement(ut,{props:e,previousPointsRef:c})))))}var mt={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:te.scatter};function ht(e){var t=we(e,mt),{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=$e(t,Qe),{needClip:h}=Te(d,f),g=(0,J.useMemo)(()=>w(e.children,ee),[e.children]),_=Se(),v=ve(t=>Ye(t,d,f,p,e.id,g,_));return h==null||v==null?null:J.createElement(J.Fragment,null,J.createElement(ot,{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}),J.createElement(pt,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 gt(e){var t=we(e,mt),n=Se();return J.createElement(W,{id:t.id,type:`scatter`},e=>J.createElement(J.Fragment,null,J.createElement(ie,{legendPayload:at(t)}),J.createElement(de,{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}),J.createElement(ht,Q({},t,{id:e}))))}var _t=J.memo(gt,O);_t.displayName=`Scatter`;function vt(e){var t=Oe(),n=(0,J.useRef)(null);return(0,J.useLayoutEffect)(()=>{n.current===null?t(le(e)):n.current!==e&&t(ge({prev:n.current,next:e})),n.current=e},[e,t]),(0,J.useLayoutEffect)(()=>()=>{n.current&&=(t(xe(n.current)),null)},[t]),null}var yt={zAxisId:0,range:M.range,scale:M.scale,type:M.type};function bt(e){var t=we(e,yt);return J.createElement(vt,{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})}bt.displayName=`ZAxis`;var xt=[`item`],St=(0,J.forwardRef)((e,t)=>J.createElement(_e,{chartName:`ScatterChart`,defaultTooltipEventType:`item`,validateTooltipEventTypes:xt,tooltipPayloadSearcher:me,categoricalChartProps:e,ref:t}));function Ct({data:e,loading:t}){let{t:n}=s(`analytics`);if(t&&!e)return(0,Y.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,Y.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,Y.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider`,children:n(`timeline.title`)}),(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground/70`,children:l?n(`timeline.costPartiallyUnavailable`,{count:o}):n(`timeline.subtitle`)})]}),c?(0,Y.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,Y.jsx)(`div`,{className:`h-40 flex items-center justify-center text-xs text-muted-foreground/70`,children:n(`timeline.empty`)}):(0,Y.jsx)(`div`,{className:`h-[220px]`,children:(0,Y.jsx)(j,{width:`100%`,height:`100%`,children:(0,Y.jsxs)(De,{data:i,margin:{top:10,right:10,left:-8,bottom:0},children:[(0,Y.jsx)(he,{strokeDasharray:`2 4`,stroke:`currentColor`,className:`text-border/30`,vertical:!1}),(0,Y.jsx)(fe,{dataKey:`date`,tick:{fontSize:10},stroke:`currentColor`,className:`text-muted-foreground`}),(0,Y.jsx)(Ce,{tick:{fontSize:10},stroke:`currentColor`,className:`text-muted-foreground`,tickFormatter:e=>`$${e}`}),(0,Y.jsx)(N,{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,Y.jsx)(H,{dataKey:r.jobs,stackId:`a`,fill:`var(--accent-info, #5fa8d3)`}),(0,Y.jsx)(H,{dataKey:r.explore,stackId:`a`,fill:`var(--accent-highlight, #c084fc)`}),(0,Y.jsx)(H,{dataKey:r.quick,stackId:`a`,fill:`var(--accent-secondary, #f7768e)`}),(0,Y.jsx)(H,{dataKey:r.refine,stackId:`a`,fill:`var(--accent-success, #50fa7b)`}),(0,Y.jsx)(H,{dataKey:r.fileSummaries,stackId:`a`,fill:`var(--accent-warning, #f1fa8c)`}),(0,Y.jsx)(H,{dataKey:r.smash,stackId:`a`,fill:`var(--accent-highlight, #c084fc)`}),(0,Y.jsx)(H,{dataKey:r.loop,stackId:`a`,fill:`var(--accent-primary, #7aa2f7)`})]})})})]})}function wt(e){return e==null?`—`:e<.005?`$${e.toFixed(4)}`:e<1?`$${e.toFixed(3)}`:`$${e.toFixed(2)}`}function Tt(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 Et({values:e}){let t=Math.max(1e-4,...e);return(0,Y.jsx)(`div`,{className:`flex items-end gap-[1px] h-5`,children:e.map((e,n)=>(0,Y.jsx)(`div`,{className:`w-[3px] rounded-sm bg-foreground/40`,style:{height:`${Math.max(2,e/t*20)}px`}},n))})}function Dt({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,Y.jsxs)(`div`,{className:`flex-1 p-4 first:pr-2 last:pl-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,Y.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full ${n}`}),(0,Y.jsx)(`span`,{className:`text-xs font-medium uppercase tracking-wider text-muted-foreground`,children:t})]}),i?(0,Y.jsxs)(`div`,{className:`py-3`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-foreground`,children:r(`quickVsExplore.sparseCta`)}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:r(`quickVsExplore.runsSoFar`,{count:e.totalRuns})})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.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?`~`:``,wt(e.avgCostPerSpec)]}),(0,Y.jsx)(`div`,{className:`text-[11px] text-muted-foreground mt-0.5`,children:r(c?`quickVsExplore.costUnavailable`:`quickVsExplore.perSpec`)}),(0,Y.jsx)(`div`,{className:`mt-3`,children:(0,Y.jsx)(Et,{values:e.sparkline.length>0?e.sparkline:[0]})}),(0,Y.jsxs)(`div`,{className:`mt-3 space-y-0.5 text-xs tabular-nums text-muted-foreground`,children:[(0,Y.jsx)(`div`,{children:(0,Y.jsx)(o,{ns:`analytics`,i18nKey:`quickVsExplore.createdRuns`,values:{created:e.ticketsCreated,runs:e.totalRuns},components:{strong:(0,Y.jsx)(`span`,{className:`text-foreground font-medium`})}})}),(0,Y.jsx)(`div`,{children:r(`quickVsExplore.avgDuration`,{duration:Tt(e.avgDurationMs)})}),(0,Y.jsx)(`div`,{className:`truncate`,children:e.dominantModel??`—`})]})]})]})}function Ot({data:e,loading:t}){let{t:n}=s(`analytics`);if(t&&!e)return(0,Y.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,Y.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40`,children:[(0,Y.jsx)(`div`,{className:`px-4 pt-3 pb-1`,children:(0,Y.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider`,children:n(`quickVsExplore.title`)})}),(0,Y.jsxs)(`div`,{className:`flex divide-x divide-border/40`,children:[(0,Y.jsx)(Dt,{mode:r,label:n(`quickVsExplore.quick`),accentClass:`bg-accent-secondary`}),(0,Y.jsx)(Dt,{mode:i,label:n(`quickVsExplore.explore`),accentClass:`bg-accent-highlight`})]}),o&&(0,Y.jsx)(`div`,{className:`px-4 pb-3 -mt-1`,children:(0,Y.jsx)(`div`,{className:`text-center text-[11px] text-muted-foreground tabular-nums`,children:(0,Y.jsxs)(`span`,{className:`px-2`,children:[`━━━━━━ `,n(`quickVsExplore.ratio`,{ratio:a.toFixed(1)}),` ━━━━━━`]})})}),c&&(0,Y.jsx)(`div`,{className:`px-4 pb-3 -mt-1`,"data-testid":`quick-vs-explore-estimated-footnote`,children:(0,Y.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:n(`quickVsExplore.estimatedFootnote`)})})]})}function kt(e){return e<.005&&e>0?`$${e.toFixed(4)}`:e<1?`$${e.toFixed(3)}`:`$${e.toFixed(2)}`}function At(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function jt({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,Y.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card p-4`,"data-testid":`agent-missions-card`,children:[(0,Y.jsxs)(`div`,{className:`mb-3 flex items-center gap-2`,children:[(0,Y.jsx)(y,{className:`h-4 w-4 text-accent-highlight`}),(0,Y.jsx)(`h3`,{className:`text-sm font-medium`,children:n(`agentMissions.title`)}),(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:n(`agentMissions.subtitle`)})]}),(0,Y.jsxs)(`div`,{className:`flex items-baseline gap-3`,children:[(0,Y.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?`~`:``,kt(a.totalCostUsd)]}),l!==null&&(0,Y.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,Y.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:n(`agentMissions.turnsAndTokens`,{turns:a.turns,tokens:At(a.tokensIn+a.tokensOut)})}),o.length>0&&(0,Y.jsx)(`ul`,{className:`mt-3 space-y-1 border-t border-border/40 pt-2`,children:o.map(e=>(0,Y.jsxs)(`li`,{className:`flex items-center gap-2 text-xs`,children:[(0,Y.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-foreground/85`,children:e.title?.trim()||n(`agentMissions.untitled`)}),(0,Y.jsxs)(`span`,{className:`shrink-0 text-[10px] text-muted-foreground`,children:[e.turns,` · `,e.lastAt?v(new Date(e.lastAt),{addSuffix:!0,locale:i()}):`—`]}),(0,Y.jsxs)(`span`,{className:`shrink-0 tabular-nums font-medium`,children:[e.estimatedCostUsd>0?`~`:``,kt(e.costUsd)]})]},e.conversationId??`unknown`))})]})}function Mt({data:e,loading:t,onSelectModel:n,activeModel:r}){let{t:i}=s(`analytics`);if(t&&!e)return(0,Y.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,Y.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,Y.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider mb-3`,children:i(`models.title`)}),o.length===0?(0,Y.jsx)(`div`,{className:`h-32 flex items-center justify-center text-xs text-muted-foreground/70`,children:i(`models.empty`)}):(0,Y.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,Y.jsx)(`li`,{children:(0,Y.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,Y.jsxs)(`div`,{className:`flex items-center justify-between text-[12px] mb-1 tabular-nums`,children:[(0,Y.jsx)(`span`,{className:`truncate font-medium`,children:e.model}),(0,Y.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,Y.jsxs)(Y.Fragment,{children:[s?`~`:``,`$`,e.costUsd.toFixed(2),` · `,e.count,d&&(0,Y.jsx)(`span`,{className:`ml-1 italic`,children:i(`models.costPartiallyUnavailable`,{count:c})})]})})]}),(0,Y.jsx)(`div`,{className:`h-1.5 rounded-full bg-background-deep overflow-hidden`,children:(0,Y.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,Y.jsx)(`li`,{"data-testid":`model-others`,children:(0,Y.jsxs)(`div`,{className:`w-full rounded-md px-2 py-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between text-[12px] mb-1 tabular-nums`,children:[(0,Y.jsx)(`span`,{className:`truncate font-medium text-muted-foreground`,children:i(`models.others`)}),(0,Y.jsxs)(`span`,{className:`text-muted-foreground`,children:[`$`,l.toFixed(2)]})]}),(0,Y.jsx)(`div`,{className:`h-1.5 rounded-full bg-background-deep overflow-hidden`,children:(0,Y.jsx)(`div`,{className:`h-full bg-foreground/25`,style:{width:`${a>0?l/a*100:0}%`}})})]})})]})]})}var Nt={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)`},Pt=Object.keys(m);function Ft({data:e,loading:t,onSelectPoint:n}){let{t:r}=s(`analytics`);if(t&&!e)return(0,Y.jsx)(`div`,{className:`h-[260px] rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let i=Pt,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,f=e.scatterTotal??e.scatter.length;return(0,Y.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,Y.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider`,children:r(`scatter.title`)}),(0,Y.jsx)(`div`,{className:`flex flex-wrap items-center gap-2 text-[10px]`,children:i.map(e=>(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,Y.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full`,style:{background:Nt[e]}}),(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:m[e]})]},e))})]}),d&&!o&&(0,Y.jsx)(`div`,{"data-testid":`scatter-truncation-notice`,className:`mb-2 text-[10px] text-accent-warning`,children:r(`scatter.truncated`,{shown:e.scatter.length,total:f})}),u&&(0,Y.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,Y.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,Y.jsx)(`div`,{className:`h-40 flex items-center justify-center text-xs text-muted-foreground/70`,children:r(`scatter.empty`)}):(0,Y.jsx)(`div`,{className:`h-[260px]`,children:(0,Y.jsx)(j,{width:`100%`,height:`100%`,children:(0,Y.jsxs)(St,{margin:{top:10,right:10,left:-8,bottom:5},children:[(0,Y.jsx)(he,{strokeDasharray:`2 4`,stroke:`currentColor`,className:`text-border/30`}),(0,Y.jsx)(fe,{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,Y.jsx)(Ce,{type:`number`,dataKey:`y`,name:`cost`,tick:{fontSize:10},stroke:`currentColor`,className:`text-muted-foreground`,tickFormatter:e=>`$${e.toFixed(e<1?2:0)}`}),(0,Y.jsx)(bt,{range:[40,80]}),(0,Y.jsx)(N,{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,Y.jsx)(_t,{data:e.points,fill:Nt[e.surface],onClick:e=>{let t=e;t?.raw&&n(t.raw)}},e.surface))]})})})]})}function It({data:e,loading:t,onSelectTicket:n}){let{t:r}=s(`analytics`);if(t&&!e)return(0,Y.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,Y.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,Y.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider mb-3`,children:r(`topTickets.title`)}),i.length===0?(0,Y.jsx)(`div`,{className:`h-32 flex items-center justify-center text-xs text-muted-foreground/70`,children:r(`topTickets.empty`)}):(0,Y.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:m[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,Y.jsx)(`li`,{children:(0,Y.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,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`div`,{className:`text-sm truncate`,children:o}),(0,Y.jsx)(`div`,{className:`text-[11px] text-muted-foreground truncate`,children:i||`—`})]}),(0,Y.jsxs)(`div`,{className:`text-right tabular-nums`,children:[(0,Y.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,Y.jsx)(`div`,{className:`text-[10px] text-muted-foreground italic`,children:r(`topTickets.costPartiallyUnavailable`,{count:c})}),(0,Y.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:r(`runs`,{count:e.totalRuns})})]})]})},`${e.ticketId??`u`}-${t}`)})})]})}var Lt={claude:`Claude`,codex:`Codex`,gemini:`Gemini`,kimi:`Kimi`};function Rt(e){return Lt[e]??e}function zt(e){return!!e&&!(e in Lt)}function Bt(e){return e==null?`—`:e<.005?`$${e.toFixed(4)}`:`$${e.toFixed(2)}`}function Vt(e){return e==null?`—`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function Ht(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 Ut(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 Wt(e,t){if(e.model)return e.model;if(!Ht(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 Gt({rows:e,loading:t,truncated:n,totalAvailable:r,tableFilters:i,onTableFiltersChange:a}){let{t:o}=s(`analytics`),[c,l]=(0,J.useState)(null),u=Ut(e),d=new Set(e.map(e=>e.provider??`claude`)).size>1,f=n||r>e.length;return(0,Y.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 mb-3`,children:[(0,Y.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider`,children:o(`table.title`)}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-[11px]`,children:[(0,Y.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,Y.jsx)(`option`,{value:``,children:o(`table.allStatus`)}),(0,Y.jsx)(`option`,{value:`success`,children:o(`table.success`)}),(0,Y.jsx)(`option`,{value:`failed`,children:o(`table.failed`)}),(0,Y.jsx)(`option`,{value:`aborted`,children:o(`table.aborted`)})]}),(0,Y.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,Y.jsx)(`div`,{className:`h-32 rounded bg-card/30 animate-pulse`}):e.length===0?(0,Y.jsx)(`div`,{className:`h-32 flex items-center justify-center text-xs text-muted-foreground/70`,children:o(`table.empty`)}):(0,Y.jsx)(`div`,{className:`overflow-x-auto`,children:(0,Y.jsxs)(`table`,{className:`w-full text-[12px] tabular-nums`,children:[(0,Y.jsx)(`thead`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:(0,Y.jsxs)(`tr`,{className:`text-left`,children:[(0,Y.jsx)(`th`,{className:`font-medium px-2 py-2`,children:o(`table.colSurface`)}),(0,Y.jsx)(`th`,{className:`font-medium px-2 py-2`,children:o(`table.colTicket`)}),(0,Y.jsx)(`th`,{className:`font-medium px-2 py-2 text-right`,children:o(`table.colCost`)}),(0,Y.jsx)(`th`,{className:`font-medium px-2 py-2 text-right`,children:o(`table.colTurns`)}),(0,Y.jsx)(`th`,{className:`font-medium px-2 py-2 text-right`,children:o(`table.colTokens`)}),(0,Y.jsx)(`th`,{className:`font-medium px-2 py-2`,children:o(`table.colModel`)}),d&&(0,Y.jsx)(`th`,{className:`font-medium px-2 py-2`,children:o(`table.colProvider`)}),(0,Y.jsx)(`th`,{className:`font-medium px-2 py-2`,children:o(`table.colStatus`)}),(0,Y.jsx)(`th`,{className:`font-medium px-2 py-2`,children:o(`table.colStarted`)})]})}),(0,Y.jsx)(`tbody`,{children:e.map(e=>{let t=e.surface,n=g[t],r=(e.tokens_in??0)+(e.tokens_out??0)+(e.tokens_cache_read??0)+(e.tokens_cache_create??0),i=Ht(e),a=i?o(`table.contractLayer`):m[t],s=Wt(e,u);return(0,Y.jsxs)(`tr`,{onClick:()=>l(c===e.id?null:e.id),className:`border-t border-border/30 hover:bg-accent/30 cursor-pointer`,children:[(0,Y.jsx)(`td`,{className:`px-2 py-2`,children:(0,Y.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,Y.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full ${n.dot}`}),a]})}),(0,Y.jsx)(`td`,{className:`px-2 py-2 max-w-[260px]`,children:e.ticket_id==null?e.ticket_title?(0,Y.jsx)(`span`,{className:`truncate block text-muted-foreground/90 italic`,title:o(`table.provisionalTitleTooltip`),children:e.ticket_title}):(0,Y.jsx)(`span`,{className:`text-muted-foreground/70`,children:`—`}):(0,Y.jsxs)(`span`,{className:`truncate block`,children:[`#`,e.ticket_id,` `,i?(0,Y.jsx)(`span`,{className:`text-muted-foreground/90`,children:o(`table.contractLayerRefinement`)}):e.ticket_title??(0,Y.jsx)(`span`,{className:`text-muted-foreground/70 italic`,children:o(`table.deleted`)})]})}),(0,Y.jsx)(`td`,{className:`px-2 py-2 text-right font-medium`,children:e.total_cost_usd_estimated===1&&e.total_cost_usd!=null?(0,Y.jsxs)(`span`,{title:o(`table.estimatedCostTooltip`),className:`text-muted-foreground/90`,children:[`~`,Bt(e.total_cost_usd)]}):e.total_cost_usd==null&&zt(e.provider)?(0,Y.jsx)(`span`,{title:o(`table.costUnknownLocalTooltip`),"data-testid":`cost-unknown-local`,className:`text-muted-foreground/70`,children:`—`}):Bt(e.total_cost_usd)}),(0,Y.jsx)(`td`,{className:`px-2 py-2 text-right`,children:Vt(e.num_turns)}),(0,Y.jsx)(`td`,{className:`px-2 py-2 text-right`,children:r>0?Vt(r):`—`}),(0,Y.jsxs)(`td`,{className:`px-2 py-2 max-w-[180px] truncate`,children:[s??`—`,s&&!e.model?(0,Y.jsx)(`span`,{className:`ml-1 text-[10px] text-muted-foreground/70`,children:o(`table.inferred`)}):null]}),d&&(0,Y.jsx)(`td`,{className:`px-2 py-2 text-muted-foreground`,children:Rt(e.provider??`claude`)}),(0,Y.jsxs)(`td`,{className:`px-2 py-2`,children:[e.status===`success`?(0,Y.jsx)(`span`,{className:`text-accent-success/90`,children:`●`}):e.status===`failed`?(0,Y.jsx)(`span`,{className:`text-accent-warning`,children:`⚠`}):(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`○`}),(0,Y.jsx)(`span`,{className:`ml-1 text-muted-foreground`,children:o(`table.statusValue.${e.status}`)})]}),(0,Y.jsx)(`td`,{className:`px-2 py-2 text-muted-foreground`,children:e.started_at.slice(0,16).replace(`T`,` `)})]},e.id)})})]})}),f&&e.length>0&&(0,Y.jsx)(`div`,{className:`mt-2 text-[11px] text-muted-foreground/80`,children:o(`table.truncated`,{shown:e.length,total:r.toLocaleString()})})]})}var Kt=[{value:`7d`,labelKey:`periods.d7`},{value:`30d`,labelKey:`periods.d30`},{value:`90d`,labelKey:`periods.d90`},{value:`all`,labelKey:`periods.all`}],qt=[{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 Jt(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 Yt(){let{t:e}=s(`analytics`),{activeProjectId:t,projects:n}=d(),[i,o]=r(),c=n.find(e=>e.id===t),m=c?u(c):[`claude`],h=m.length>1,g=i.get(`period`)??`30d`,_=(i.get(`surface`)??``).split(`,`).filter(Boolean),v=(i.get(`provider`)??``).split(`,`).filter(Boolean),y=i.get(`ticketId`),S=(i.get(`model`)??``).split(`,`).filter(Boolean),C=(i.get(`modelProvider`)??``).split(`,`).filter(Boolean),w=S.length>0&&S.length===C.length?S.map((e,t)=>({provider:C[t],model:e})):void 0,ee=(0,J.useMemo)(()=>-new Date().getTimezoneOffset(),[]),[T,E]=(0,J.useState)({period:g,surface:_.length>0?_:void 0,provider:v.length>0?v:void 0,ticketId:y?Number(y):void 0,model:S.length>0?S:void 0,modelKeys:w,tzOffsetMinutes:ee}),[D,O]=(0,J.useState)(null),[k,A]=(0,J.useState)(!0),[j,te]=(0,J.useState)(null),[M,ne]=(0,J.useState)({}),[N,P]=(0,J.useState)(null),[F,re]=(0,J.useState)(`recency`),I=(0,J.useRef)(new Map),L=(0,J.useRef)(0);(0,J.useEffect)(()=>{let e=new URLSearchParams;e.set(`period`,T.period),T.surface&&T.surface.length>0&&e.set(`surface`,T.surface.join(`,`)),T.provider&&T.provider.length>0&&e.set(`provider`,T.provider.join(`,`)),T.ticketId&&e.set(`ticketId`,String(T.ticketId)),T.model&&T.model.length>0&&(e.set(`model`,T.model.join(`,`)),T.modelKeys&&T.modelKeys.length===T.model.length&&e.set(`modelProvider`,T.modelKeys.map(e=>e.provider).join(`,`))),o(e,{replace:!0})},[T.period,T.surface,T.provider,T.ticketId,T.model,T.modelKeys,o]);let R=(0,J.useCallback)(async()=>{if(!t)return;let e=++L.current;te(null);let n=`${t}:${Jt(T)}`,r=I.current.get(n);r?(O(r),A(!1)):A(!0);try{let t=await fetch(`${l()}/spending?${Jt(T)}`);if(!t.ok)throw Error(`HTTP ${t.status}`);if(e!==L.current)return;let r=await t.json();I.current.set(n,r),O(r),A(!1)}catch(t){if(e!==L.current)return;te(t.message),A(!1)}},[t,T]),z=(0,J.useRef)(0),B=(0,J.useCallback)(async()=>{if(!t)return;let e=++z.current,n={...T};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=F;try{let t=await fetch(`${l()}/invocations?${Jt(n)}&limit=100`);if(!t.ok)throw Error(`HTTP ${t.status}`);let r=await t.json();if(e!==z.current)return;P(r)}catch{if(e!==z.current)return;P(null)}},[t,T,M,F]),ie=(0,J.useRef)(t);(0,J.useEffect)(()=>{ie.current!==t&&(ie.current=t,O(null),P(null),A(!0))},[t]),(0,J.useEffect)(()=>{R()},[R]),(0,J.useEffect)(()=>{B()},[B]);let V=(0,J.useRef)(null),H=a();(0,J.useEffect)(()=>{let e=`analytics-spending`;return H.registerHandler(e,e=>{let n=e;n.type===`spending.invalidated`&&n.projectId===t&&(V.current&&clearTimeout(V.current),V.current=setTimeout(()=>{I.current.clear(),R(),B()},500))}),()=>{H.unregisterHandler(e),V.current&&clearTimeout(V.current)}},[H,t,R,B]);function ae(e){if(e===`all`){E(e=>({...e,surface:void 0}));return}E(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 oe=(0,J.useCallback)((e,t)=>{E(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=(D?.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}})},[D]);function se(){E(e=>({...e,model:void 0,modelKeys:void 0}))}function ce(e){if(e===`all`){E(e=>({...e,provider:void 0}));return}E(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 U=T.surface,le=!U||U.length===0,W=T.provider,ue=!W||W.length===0,de=(0,J.useMemo)(()=>{let e={period:T.period};return T.surface&&T.surface.length>0&&(e.surface=T.surface.join(`,`)),T.provider&&T.provider.length>0&&(e.provider=T.provider.join(`,`)),T.ticketId&&(e.ticketId=String(T.ticketId)),e},[T]),fe=D?D.summary.totalRuns===0:!1;return(0,Y.jsxs)(`div`,{className:`flex flex-col gap-6 p-4 pb-12`,children:[(0,Y.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,Y.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(`h1`,{className:`text-base font-semibold tracking-tight`,children:e(`page.title`)}),T.ticketId&&(0,Y.jsx)(`button`,{type:`button`,onClick:()=>E(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:T.ticketId})}),T.model&&T.model.length>0&&(0,Y.jsxs)(`button`,{type:`button`,"data-testid":`analytics-model-chip`,onClick:se,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:T.model[0]}),(0,Y.jsx)(`span`,{"aria-hidden":!0,className:`opacity-70`,children:`×`})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`div`,{className:`flex items-center gap-1 rounded-md border border-border/60 bg-card/40 p-0.5`,children:Kt.map(t=>(0,Y.jsx)(`button`,{type:`button`,onClick:()=>E(e=>({...e,period:t.value})),className:`px-2.5 h-6 rounded text-[11px] font-medium transition-colors ${T.period===t.value?`bg-accent text-foreground`:`text-muted-foreground hover:text-foreground`}`,children:e(t.labelKey)},t.value))}),(0,Y.jsx)(x,{baseUrl:`${l()}/analytics/export`,params:de,disabled:fe}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>{I.current.clear(),R(),B()},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,Y.jsx)(b,{className:`w-3 h-3`})})]})]}),(0,Y.jsx)(`div`,{className:`mt-3 flex flex-wrap items-center gap-1.5`,children:qt.map(t=>(0,Y.jsx)(`button`,{type:`button`,onClick:()=>ae(t.value),className:`h-7 px-3 rounded-full text-[11px] font-medium transition-all ${(t.value===`all`?le:U?.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))}),h&&(0,Y.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-1.5`,"data-testid":`analytics-provider-chips`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-muted-foreground/70 mr-1`,children:e(`page.engine`)}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>ce(`all`),className:`h-7 px-3 rounded-full text-[11px] font-medium transition-all ${ue?`bg-foreground/10 text-foreground ring-1 ring-foreground/20`:`text-muted-foreground hover:text-foreground hover:bg-accent/40`}`,children:e(`page.all`)}),m.map(t=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>ce(t),className:`h-7 px-3 rounded-full text-[11px] font-medium transition-all ${W?.includes(t)??!1?`bg-foreground/10 text-foreground ring-1 ring-foreground/20`:`text-muted-foreground hover:text-foreground hover:bg-accent/40`}`,children:[p(t),f(t)&&(0,Y.jsx)(`span`,{className:`ml-1 rounded-full bg-accent-secondary/15 px-1.5 text-[9px] uppercase tracking-wide text-accent-secondary`,children:e(`page.localEngine`)})]},t))]})]}),j&&(0,Y.jsxs)(`div`,{className:`rounded-lg border border-accent-warning/30 bg-accent-warning/10 p-4 flex items-center justify-between`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-accent-warning`,children:e(`page.failedToLoad`,{error:j})}),(0,Y.jsxs)(`button`,{onClick:()=>R(),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,Y.jsx)(b,{className:`w-3 h-3`}),e(`common:actions.retry`)]})]}),(0,Y.jsx)(Le,{data:D,loading:k,period:T.period}),(0,Y.jsx)(Ue,{data:D,loading:k}),(0,Y.jsx)(Ct,{data:D,loading:k}),(0,Y.jsx)(jt,{data:D,loading:k}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4`,children:[(0,Y.jsx)(Ot,{data:D,loading:k}),(0,Y.jsx)(Mt,{data:D,loading:k,onSelectModel:oe,activeModel:T.model?.[0]})]}),(0,Y.jsx)(Ft,{data:D,loading:k,onSelectPoint:e=>{ne(e=>({...e})),E(t=>({...t,ticketId:e.ticketId??void 0}))}}),(0,Y.jsx)(It,{data:D,loading:k,onSelectTicket:e=>E(t=>({...t,ticketId:e??void 0}))}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-end gap-1.5`,"data-testid":`analytics-table-sort`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-muted-foreground/70 mr-1`,children:e(`table.sortLabel`)}),[`recency`,`cost`].map(t=>(0,Y.jsx)(`button`,{type:`button`,"data-testid":`analytics-table-sort-${t}`,"aria-pressed":F===t,onClick:()=>re(t),className:`h-6 px-2.5 rounded-full text-[11px] font-medium transition-all ${F===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,Y.jsx)(Gt,{rows:N?.rows??[],loading:k&&!N,truncated:(N?.truncated??!1)||(N?.totalAvailable??0)>(N?.rows.length??0),totalAvailable:N?.totalAvailable??0,tableFilters:M,onTableFiltersChange:ne})]})]})}export{Yt as default};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/editor.main-DxrmGfoq.js","assets/rolldown-runtime-CNC7AqOf.js","assets/preload-helper-Czpn1I53.js","assets/editor.api2-4ndOupAA.js","assets/editor-Br_kD0ds.css","assets/monaco.contribution-Bt92R3Vw.js","assets/workers-uOo7WLaa.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-zu2_FqZY.js";import{t as r}from"./react-dom-DiWzBDP9.js";import{t as i}from"./preload-helper-Czpn1I53.js";import{f as a,u as o}from"./chunk-KS7C4IRE-DEKu087k.js";import{G as s,K as c,W as l,X as u,n as d,z as f}from"./TicketDetailModalContext-D2MEhRwJ.js";import{r as p}from"./useSharedWebSocket-BN3Lmehi.js";import{n as m,t as h}from"./createLucideIcon-Bjbbp_KS.js";import{a as g,i as _,r as v,s as y}from"./useDesktop-BJ8IRBRt.js";import{p as b}from"./provider-capabilities-Vi1ZGvAK.js";import{n as x}from"./save-B6wGWwBR.js";import{c as S,l as C}from"./MinimizedChatsContext-CX1i2kQ8.js";import{t as w}from"./file-text-CFT-xXKN.js";import{t as T}from"./loader-circle-DcygOQpC.js";import{t as E}from"./search-Cq_gE3Ik.js";import{t as D}from"./sparkles-DrY8hb0X.js";import{t as O}from"./x-CBMI9ejn.js";import{M as k,j as A}from"./dialog-xXB2q5HJ.js";import{t as j}from"./utils-BC4DHlz2.js";import{n as M,t as N}from"./lib-CGdyxIWg.js";import{n as P,t as ee}from"./project-repositories-DAjJbFhm.js";import{At as F,Dt as I,Mt as te,Rt as L,Yt as R,gt as ne,kt as z,zt as re}from"./index-CjAPu3wb.js";var B=h(`file-search`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`circle`,{cx:`11.5`,cy:`14.5`,r:`2.5`,key:`1bq0ko`}],[`path`,{d:`M13.3 16.3 15 18`,key:`2quom7`}]]),ie=h(`files`,[[`path`,{d:`M15 2h-4a2 2 0 0 0-2 2v11a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2V8`,key:`14sh0y`}],[`path`,{d:`M16.706 2.706A2.4 2.4 0 0 0 15 2v5a1 1 0 0 0 1 1h5a2.4 2.4 0 0 0-.706-1.706z`,key:`1970lx`}],[`path`,{d:`M5 7a2 2 0 0 0-2 2v11a2 2 0 0 0 2 2h8a2 2 0 0 0 1.732-1`,key:`l4dndm`}]]),V=h(`folder-search`,[[`path`,{d:`M10.7 20H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H20a2 2 0 0 1 2 2v4.1`,key:`1bw5m7`}],[`path`,{d:`m21 21-1.9-1.9`,key:`1g2n9r`}],[`circle`,{cx:`17`,cy:`17`,r:`3`,key:`18b49y`}]]),ae=h(`funnel`,[[`path`,{d:`M10 20a1 1 0 0 0 .553.895l2 1A1 1 0 0 0 14 21v-7a2 2 0 0 1 .517-1.341L21.74 4.67A1 1 0 0 0 21 3H3a1 1 0 0 0-.742 1.67l7.225 7.989A2 2 0 0 1 10 14z`,key:`sc7q7i`}]]),oe=h(`panel-left-close`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}],[`path`,{d:`m16 15-3-3 3-3`,key:`14y99z`}]]),se=h(`panel-left-open`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}],[`path`,{d:`m14 9 3 3-3 3`,key:`8010ee`}]]),H=e(t(),1),ce=e(r(),1);function U(e,t,n){let r=Array(e);return new Proxy(r,{get(r,i,a){if(typeof i==`string`){let a=i.charCodeAt(0);if(a>=48&&a<=57){let a=+i;if(Number.isInteger(a)&&a>=0&&a<e){let e=r[a];if(!e){let i=t[a*2];e=r[a]={index:a,key:n(a),start:i,size:t[a*2+1],end:i+t[a*2+1],lane:0}}return e}}if(i===`length`)return e}return Reflect.get(r,i,a)}})}function W(e,t,n){let r=n.initialDeps??[],i,a=!0;function o(){let o=e();return o.length!==r.length||o.some((e,t)=>r[t]!==e)?(r=o,i=t(...o),n?.onChange&&!(a&&n.skipInitialOnChange)&&n.onChange(i),a=!1,i):i}return o.updateDeps=e=>{r=e},o}function G(e,t){if(e===void 0)throw Error(`Unexpected undefined${t?`: ${t}`:``}`);return e}var K=(e,t)=>Math.abs(e-t)<1.01,le=(e,t,n)=>{let r;return function(...i){e.clearTimeout(r),r=e.setTimeout(()=>t.apply(this,i),n)}},q,ue=()=>{if(q!==void 0)return q;if(typeof navigator>`u`)return q=!1;if(/iP(hone|od|ad)/.test(navigator.userAgent))return q=!0;let e=navigator.maxTouchPoints;return q=navigator.platform===`MacIntel`&&e!==void 0&&e>0},J=e=>{let{offsetWidth:t,offsetHeight:n}=e;return{width:t,height:n}},de=e=>e,fe=e=>{let t=Math.max(e.startIndex-e.overscan,0),n=Math.min(e.endIndex+e.overscan,e.count-1)-t+1,r=Array(n);for(let e=0;e<n;e++)r[e]=t+e;return r},pe=(e,t)=>{let n=e.scrollElement;if(!n)return;let r=e.targetWindow;if(!r)return;let i=e=>{let{width:n,height:r}=e;t({width:Math.round(n),height:Math.round(r)})};if(i(J(n)),!r.ResizeObserver)return()=>{};let a=new r.ResizeObserver(t=>{let r=()=>{let e=t[0];if(e?.borderBoxSize){let t=e.borderBoxSize[0];if(t){i({width:t.inlineSize,height:t.blockSize});return}}i(J(n))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(r):r()});return a.observe(n,{box:`border-box`}),()=>{a.unobserve(n)}},me={passive:!0},Y=typeof window>`u`||`onscrollend`in window,he=(e,t,n)=>{let r=e.scrollElement;if(!r)return;let i=e.targetWindow;if(!i)return;let a=e.options.useScrollendEvent&&Y,o=0,s=a?null:le(i,()=>t(o,!1),e.options.isScrollingResetDelay),c=e=>()=>{o=n(r),s?.(),t(o,e)},l=c(!0),u=c(!1);return r.addEventListener(`scroll`,l,me),a&&r.addEventListener(`scrollend`,u,me),()=>{r.removeEventListener(`scroll`,l),a&&r.removeEventListener(`scrollend`,u)}},ge=(e,t)=>he(e,t,t=>{let{horizontal:n,isRtl:r}=e.options;return n?t.scrollLeft*(r&&-1||1):t.scrollTop}),X=(e,t,n)=>{if(t?.borderBoxSize){let e=t.borderBoxSize[0];if(e)return Math.round(e[n.options.horizontal?`inlineSize`:`blockSize`])}return e[n.options.horizontal?`offsetWidth`:`offsetHeight`]},_e=(e,{adjustments:t=0,behavior:n},r)=>{var i,a;(a=(i=r.scrollElement)?.scrollTo)==null||a.call(i,{[r.options.horizontal?`left`:`top`]:e+t,behavior:n})},ve=class{constructor(e){this.unsubs=[],this.scrollElement=null,this.targetWindow=null,this.isScrolling=!1,this.scrollState=null,this.measurementsCache=[],this._flatMeasurements=null,this.itemSizeCache=new Map,this.itemSizeCacheVersion=0,this.laneAssignments=new Map,this.pendingMin=null,this.prevLanes=void 0,this.lanesChangedFlag=!1,this.lanesSettling=!1,this.scrollRect=null,this.scrollOffset=null,this.scrollDirection=null,this.scrollAdjustments=0,this._iosDeferredAdjustment=0,this._iosTouching=!1,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._intendedScrollOffset=null,this.elementsCache=new Map,this.now=()=>{var e;return((e=this.targetWindow?.performance)?.now)?.call(e)??Date.now()},this.observer=(()=>{let e=null,t=()=>e||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:e=new this.targetWindow.ResizeObserver(e=>{e.forEach(e=>{let t=()=>{let t=e.target,n=this.indexFromElement(t);if(!t.isConnected){this.observer.unobserve(t);for(let[e,n]of this.elementsCache)if(n===t){this.elementsCache.delete(e);break}return}this.shouldMeasureDuringScroll(n)&&this.resizeItem(n,this.options.measureElement(t,e,this))};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(t):t()})}));return{disconnect:()=>{var n;(n=t())==null||n.disconnect(),e=null},observe:e=>t()?.observe(e,{box:`border-box`}),unobserve:e=>t()?.unobserve(e)}})(),this.range=null,this.setOptions=e=>{let t={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:de,rangeExtractor:fe,onChange:()=>{},measureElement:X,initialRect:{width:0,height:0},scrollMargin:0,gap:0,indexAttribute:`data-index`,initialMeasurementsCache:[],lanes:1,isScrollingResetDelay:150,enabled:!0,isRtl:!1,useScrollendEvent:!1,useAnimationFrameWithResizeObserver:!1,laneAssignmentMode:`estimate`};for(let n in e){let r=e[n];r!==void 0&&(t[n]=r)}this.options=t},this.notify=e=>{var t,n;(n=(t=this.options).onChange)==null||n.call(t,this,e)},this.maybeNotify=W(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),e=>{this.notify(e)},{key:!1,debug:()=>this.options.debug,initialDeps:[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]}),this.cleanup=()=>{this.unsubs.filter(Boolean).forEach(e=>e()),this.unsubs=[],this.observer.disconnect(),this.rafId!=null&&this.targetWindow&&(this.targetWindow.cancelAnimationFrame(this.rafId),this.rafId=null),this.scrollState=null,this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{let e=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==e){if(this.cleanup(),!e){this.maybeNotify();return}if(this.scrollElement=e,this.scrollElement&&`ownerDocument`in this.scrollElement?this.targetWindow=this.scrollElement.ownerDocument.defaultView:this.targetWindow=this.scrollElement?.window??null,this.elementsCache.forEach(e=>{this.observer.observe(e)}),this.unsubs.push(this.options.observeElementRect(this,e=>{this.scrollRect=e,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(e,t)=>{this._intendedScrollOffset!==null&&Math.abs(e-this._intendedScrollOffset)<1.5&&(e=this._intendedScrollOffset),this._intendedScrollOffset=null,this.scrollAdjustments=0,this.scrollDirection=t?this.getScrollOffset()<e?`forward`:`backward`:null,this.scrollOffset=e,this.isScrolling=t,this._flushIosDeferredIfReady(),this.scrollState&&this.scheduleScrollReconcile(),this.maybeNotify()})),`addEventListener`in this.scrollElement){let e=this.scrollElement,t=()=>{this._iosTouching=!0,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)},n=()=>{this._iosTouching=!1,!(!ue()||this.targetWindow==null)&&(this._iosJustTouchEnded=!0,this._iosTouchEndTimerId=this.targetWindow.setTimeout(()=>{this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._flushIosDeferredIfReady()},150))};e.addEventListener(`touchstart`,t,me),e.addEventListener(`touchend`,n,me),this.unsubs.push(()=>{e.removeEventListener(`touchstart`,t),e.removeEventListener(`touchend`,n),this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)})}this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})}},this._flushIosDeferredIfReady=()=>{if(this._iosDeferredAdjustment===0||this.isScrolling||this._iosTouching||this._iosJustTouchEnded)return;let e=this.getScrollOffset(),t=this.getMaxScrollOffset();if(e<0||e>t)return;let n=this._iosDeferredAdjustment;this._iosDeferredAdjustment=0,this._scrollToOffset(e,{adjustments:this.scrollAdjustments+=n,behavior:void 0})},this.rafId=null,this.getSize=()=>this.options.enabled?(this.scrollRect=this.scrollRect??this.options.initialRect,this.scrollRect[this.options.horizontal?`width`:`height`]):(this.scrollRect=null,0),this.getScrollOffset=()=>this.options.enabled?(this.scrollOffset=this.scrollOffset??(typeof this.options.initialOffset==`function`?this.options.initialOffset():this.options.initialOffset),this.scrollOffset):(this.scrollOffset=null,0),this.getFurthestMeasurement=(e,t)=>{let n=new Map,r=new Map;for(let i=t-1;i>=0;i--){let t=e[i];if(n.has(t.lane))continue;let a=r.get(t.lane);if(a==null||t.end>a.end?r.set(t.lane,t):t.end<a.end&&n.set(t.lane,!0),n.size===this.options.lanes)break}return r.size===this.options.lanes?Array.from(r.values()).sort((e,t)=>e.end===t.end?e.index-t.index:e.end-t.end)[0]:void 0},this.getMeasurementOptions=W(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled,this.options.lanes,this.options.laneAssignmentMode],(e,t,n,r,i,a,o)=>(this.prevLanes!==void 0&&this.prevLanes!==a&&(this.lanesChangedFlag=!0),this.prevLanes=a,this.pendingMin=null,{count:e,paddingStart:t,scrollMargin:n,getItemKey:r,enabled:i,lanes:a,laneAssignmentMode:o}),{key:!1}),this.getMeasurements=W(()=>[this.getMeasurementOptions(),this.itemSizeCacheVersion],({count:e,paddingStart:t,scrollMargin:n,getItemKey:r,enabled:i,lanes:a,laneAssignmentMode:o},s)=>{let c=this.itemSizeCache;if(!i)return this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>e)for(let t of this.laneAssignments.keys())t>=e&&this.laneAssignments.delete(t);this.lanesChangedFlag&&(this.lanesChangedFlag=!1,this.lanesSettling=!0,this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),this.pendingMin=null),this.measurementsCache.length===0&&!this.lanesSettling&&(this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach(e=>{this.itemSizeCache.set(e.key,e.size)}));let l=this.lanesSettling?0:this.pendingMin??0;if(this.pendingMin=null,this.lanesSettling&&this.measurementsCache.length===e&&(this.lanesSettling=!1),a===1){let i=this.options.gap,a=e*2,o=this._flatMeasurements;if(!o||o.length<a){let e=new Float64Array(a);o&&l>0&&e.set(o.subarray(0,l*2)),o=e,this._flatMeasurements=o}let s;if(l===0)s=t+n;else{let e=l-1;s=o[e*2]+o[e*2+1]+i}for(let t=l;t<e;t++){let e=r(t),n=c.get(e),a=typeof n==`number`?n:this.options.estimateSize(t);o[t*2]=s,o[t*2+1]=a,s+=a+i}let u=U(e,o,r);return this.measurementsCache=u,u}let u=this.measurementsCache.slice(0,l),d=Array(a).fill(void 0);for(let e=0;e<l;e++){let t=u[e];t&&(d[t.lane]=e)}for(let i=l;i<e;i++){let e=r(i),a=this.laneAssignments.get(i),s,l,f=o===`estimate`||c.has(e);if(a!==void 0&&this.options.lanes>1){s=a;let e=d[s],r=e===void 0?void 0:u[e];l=r?r.end+this.options.gap:t+n}else{let e=this.options.lanes===1?u[i-1]:this.getFurthestMeasurement(u,i);l=e?e.end+this.options.gap:t+n,s=e?e.lane:i%this.options.lanes,this.options.lanes>1&&f&&this.laneAssignments.set(i,s)}let p=c.get(e),m=typeof p==`number`?p:this.options.estimateSize(i),h=l+m;u[i]={index:i,start:l,size:m,end:h,key:e,lane:s},d[s]=i}return this.measurementsCache=u,u},{key:!1,debug:()=>this.options.debug}),this.calculateRange=W(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(e,t,n,r)=>this.range=e.length>0&&t>0?be({measurements:e,outerSize:t,scrollOffset:n,lanes:r,flat:r===1&&this._flatMeasurements!=null?this._flatMeasurements:null}):null,{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=W(()=>{let e=null,t=null,n=this.calculateRange();return n&&(e=n.startIndex,t=n.endIndex),this.maybeNotify.updateDeps([this.isScrolling,e,t]),[this.options.rangeExtractor,this.options.overscan,this.options.count,e,t]},(e,t,n,r,i)=>r===null||i===null?[]:e({startIndex:r,endIndex:i,overscan:t,count:n}),{key:!1,debug:()=>this.options.debug}),this.indexFromElement=e=>{let t=this.options.indexAttribute,n=e.getAttribute(t);return n?parseInt(n,10):(console.warn(`Missing attribute name '${t}={index}' on measured element.`),-1)},this.shouldMeasureDuringScroll=e=>{if(!this.scrollState||this.scrollState.behavior!==`smooth`)return!0;let t=this.scrollState.index??this.getVirtualItemForOffset(this.scrollState.lastTargetOffset)?.index;if(t!==void 0&&this.range){let n=Math.max(this.options.overscan,Math.ceil((this.range.endIndex-this.range.startIndex)/2)),r=Math.max(0,t-n),i=Math.min(this.options.count-1,t+n);return e>=r&&e<=i}return!0},this.measureElement=e=>{if(!e){this.elementsCache.forEach((e,t)=>{e.isConnected||(this.observer.unobserve(e),this.elementsCache.delete(t))});return}let t=this.indexFromElement(e),n=this.options.getItemKey(t),r=this.elementsCache.get(n);r!==e&&(r&&this.observer.unobserve(r),this.observer.observe(e),this.elementsCache.set(n,e)),(!this.isScrolling||this.scrollState)&&this.shouldMeasureDuringScroll(t)&&this.resizeItem(t,this.options.measureElement(e,void 0,this))},this.resizeItem=(e,t)=>{if(e<0||e>=this.options.count)return;let n,r,i,a=this._flatMeasurements;if(this.options.lanes===1&&a!==null)i=this.options.getItemKey(e),r=a[e*2],n=a[e*2+1];else{let t=this.measurementsCache[e];if(!t)return;i=t.key,r=t.start,n=t.size}let o=t-(this.itemSizeCache.get(i)??n);o!==0&&(this.scrollState?.behavior!==`smooth`&&(this.shouldAdjustScrollPositionOnItemSizeChange===void 0?r<this.getScrollOffset()+this.scrollAdjustments&&this.scrollDirection!==`backward`:this.shouldAdjustScrollPositionOnItemSizeChange(this.measurementsCache[e]??{index:e,key:i,start:r,size:n,end:r+n,lane:0},o,this))&&(ue()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded)?this._iosDeferredAdjustment+=o:this._scrollToOffset(this.getScrollOffset(),{adjustments:this.scrollAdjustments+=o,behavior:void 0})),(this.pendingMin===null||e<this.pendingMin)&&(this.pendingMin=e),this.itemSizeCache.set(i,t),this.itemSizeCacheVersion++,this.notify(!1))},this.getVirtualItems=W(()=>[this.getVirtualIndexes(),this.getMeasurements()],(e,t)=>{let n=[];for(let r=0,i=e.length;r<i;r++){let i=t[e[r]];n.push(i)}return n},{key:!1,debug:()=>this.options.debug}),this.getVirtualItemForOffset=e=>{let t=this.getMeasurements();if(t.length===0)return;let n=this._flatMeasurements,r=this.options.lanes===1&&n!=null;return G(t[ye(0,t.length-1,r?e=>n[e*2]:e=>G(t[e]).start,e)])},this.getMaxScrollOffset=()=>{if(!this.scrollElement)return 0;if(`scrollHeight`in this.scrollElement)return this.options.horizontal?this.scrollElement.scrollWidth-this.scrollElement.clientWidth:this.scrollElement.scrollHeight-this.scrollElement.clientHeight;{let e=this.scrollElement.document.documentElement;return this.options.horizontal?e.scrollWidth-this.scrollElement.innerWidth:e.scrollHeight-this.scrollElement.innerHeight}},this.getOffsetForAlignment=(e,t,n=0)=>{if(!this.scrollElement)return 0;let r=this.getSize(),i=this.getScrollOffset();t===`auto`&&(t=e>=i+r?`end`:`start`),t===`center`?e+=(n-r)/2:t===`end`&&(e-=r);let a=this.getMaxScrollOffset();return Math.max(Math.min(a,e),0)},this.getOffsetForIndex=(e,t=`auto`)=>{e=Math.max(0,Math.min(e,this.options.count-1));let n=this.getSize(),r=this.getScrollOffset(),i=this.measurementsCache[e];if(!i)return;if(t===`auto`)if(i.end>=r+n-this.options.scrollPaddingEnd)t=`end`;else if(i.start<=r+this.options.scrollPaddingStart)t=`start`;else return[r,t];if(t===`end`&&e===this.options.count-1)return[this.getMaxScrollOffset(),t];let a=t===`end`?i.end+this.options.scrollPaddingEnd:i.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(a,t,i.size),t]},this.scrollToOffset=(e,{align:t=`start`,behavior:n=`auto`}={})=>{let r=this.getOffsetForAlignment(e,t),i=this.now();this.scrollState={index:null,align:t,behavior:n,startedAt:i,lastTargetOffset:r,stableFrames:0},this._scrollToOffset(r,{adjustments:void 0,behavior:n}),this.scheduleScrollReconcile()},this.scrollToIndex=(e,{align:t=`auto`,behavior:n=`auto`}={})=>{e=Math.max(0,Math.min(e,this.options.count-1));let r=this.getOffsetForIndex(e,t);if(!r)return;let[i,a]=r,o=this.now();this.scrollState={index:e,align:a,behavior:n,startedAt:o,lastTargetOffset:i,stableFrames:0},this._scrollToOffset(i,{adjustments:void 0,behavior:n}),this.scheduleScrollReconcile()},this.scrollBy=(e,{behavior:t=`auto`}={})=>{let n=this.getScrollOffset()+e,r=this.now();this.scrollState={index:null,align:`start`,behavior:t,startedAt:r,lastTargetOffset:n,stableFrames:0},this._scrollToOffset(n,{adjustments:void 0,behavior:t}),this.scheduleScrollReconcile()},this.getTotalSize=()=>{let e=this.getMeasurements(),t;if(e.length===0)t=this.options.paddingStart;else if(this.options.lanes===1){let n=e.length-1,r=this._flatMeasurements;t=r==null?e[n]?.end??0:r[n*2]+r[n*2+1]}else{let n=Array(this.options.lanes).fill(null),r=e.length-1;for(;r>=0&&n.some(e=>e===null);){let t=e[r];n[t.lane]===null&&(n[t.lane]=t.end),r--}t=Math.max(...n.filter(e=>e!==null))}return Math.max(t-this.options.scrollMargin+this.options.paddingEnd,0)},this.takeSnapshot=()=>{let e=[];if(this.itemSizeCache.size===0)return e;let t=this.getMeasurements();for(let n of t)n&&this.itemSizeCache.has(n.key)&&e.push({index:n.index,key:n.key,start:n.start,size:n.size,end:n.end,lane:n.lane});return e},this._scrollToOffset=(e,{adjustments:t,behavior:n})=>{this._intendedScrollOffset=e+(t??0),this.options.scrollToFn(e,{behavior:n,adjustments:t},this)},this.measure=()=>{this.pendingMin=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),this.itemSizeCacheVersion++,this.notify(!1)},this.setOptions(e)}scheduleScrollReconcile(){if(!this.targetWindow){this.scrollState=null;return}this.rafId??=this.targetWindow.requestAnimationFrame(()=>{this.rafId=null,this.reconcileScroll()})}reconcileScroll(){if(!this.scrollState||!this.scrollElement)return;if(this.now()-this.scrollState.startedAt>5e3){this.scrollState=null;return}let e=this.scrollState.index==null?void 0:this.getOffsetForIndex(this.scrollState.index,this.scrollState.align),t=e?e[0]:this.scrollState.lastTargetOffset,n=t!==this.scrollState.lastTargetOffset;if(!n&&K(t,this.getScrollOffset())){if(this.scrollState.stableFrames++,this.scrollState.stableFrames>=1){this.getScrollOffset()!==t&&this._scrollToOffset(t,{adjustments:void 0,behavior:`auto`}),this.scrollState=null;return}}else if(this.scrollState.stableFrames=0,n){let e=this.getSize()||600,n=Math.abs(t-this.getScrollOffset()),r=this.scrollState.behavior===`smooth`&&n>e;this.scrollState.lastTargetOffset=t,r||(this.scrollState.behavior=`auto`),this._scrollToOffset(t,{adjustments:void 0,behavior:r?`smooth`:`auto`})}this.scheduleScrollReconcile()}},ye=(e,t,n,r)=>{for(;e<=t;){let i=(e+t)/2|0,a=n(i);if(a<r)e=i+1;else if(a>r)t=i-1;else return i}return e>0?e-1:0};function be({measurements:e,outerSize:t,scrollOffset:n,lanes:r,flat:i}){let a=e.length-1,o=i?e=>i[e*2]:t=>e[t].start,s=i?e=>i[e*2]+i[e*2+1]:t=>e[t].end;if(e.length<=r)return{startIndex:0,endIndex:a};let c=ye(0,a,o,n),l=c;if(r===1)for(;l<a&&s(l)<n+t;)l++;else if(r>1){let i=Array(r).fill(0);for(;l<a&&i.some(e=>e<n+t);){let t=e[l];i[t.lane]=t.end,l++}let o=Array(r).fill(n+t);for(;c>=0&&o.some(e=>e>=n);){let t=e[c];o[t.lane]=t.start,c--}c=Math.max(0,c-c%r),l=Math.min(a,l+(r-1-l%r))}return{startIndex:c,endIndex:l}}var xe=typeof document<`u`?H.useLayoutEffect:H.useEffect;function Se({useFlushSync:e=!0,...t}){let n=H.useReducer(e=>e+1,0)[1],r={...t,onChange:(r,i)=>{var a;e&&i?(0,ce.flushSync)(n):n(),(a=t.onChange)==null||a.call(t,r,i)}},[i]=H.useState(()=>new ve(r));return i.setOptions(r),xe(()=>i._didMount(),[]),xe(()=>i._willUpdate()),i}function Ce(e){return Se({observeElementRect:pe,observeElementOffset:ge,scrollToFn:_e,...e})}var we=(0,H.createContext)(null);function Z(){return(0,H.useContext)(we)??{apiBase:g()}}function Te(e,t){return e?e===t.repositoryId:!t.repositoryId||t.isPrimary===!0}var Q=n(),Ee=e=>`specrails-desktop:code-tree-filter:${e}`,De=e=>`specrails-desktop:code-tree-collapsed:${e}`;function Oe(e){return e.split(`/`).length-1}function ke(e){let t=e.lastIndexOf(`/`);return t>=0?e.slice(t+1):e}function Ae(e){return e?e.length>10?e.slice(0,10):e:null}function je(e){return e===`created`?`added`:e===`modified`?`changed`:e===`deleted`?`deleted`:null}function Me(e,t){if(t.size===0)return!1;let n=e.split(`/`);for(let e=1;e<n.length;e++)if(t.has(n.slice(0,e).join(`/`)))return!0;return!1}function Ne({onOpenFile:e,selectedPath:t,filterJobId:n,filterTicketId:r}){let{t:i}=m(`code`),a=(0,H.useId)(),o=Z(),{apiBase:s,repositoryId:c,repositoryPath:u}=o,{activeProjectId:f}=v(),{openTicketDetail:h}=d(),{registerHandler:g,unregisterHandler:y}=p(),[b,x]=(0,H.useState)(()=>{if(!f)return`all`;try{let e=localStorage.getItem(Ee(`${f}:${c??`primary`}`));if(e===`all`||e===`touched-by-ai`)return e}catch{}return`all`});(0,H.useEffect)(()=>{if(f)try{localStorage.setItem(Ee(`${f}:${c??`primary`}`),b)}catch{}},[b,f,c]),(0,H.useEffect)(()=>{(n||r)&&x(`touched-by-ai`)},[n,r]);let[S,C]=(0,H.useState)(()=>{if(!f)return new Set;try{let e=localStorage.getItem(De(`${f}:${c??`primary`}`));if(!e)return new Set;let t=JSON.parse(e);if(Array.isArray(t))return new Set(t.filter(e=>typeof e==`string`))}catch{}return new Set});(0,H.useEffect)(()=>{if(f)try{localStorage.setItem(De(`${f}:${c??`primary`}`),JSON.stringify([...S]))}catch{}},[S,f,c]);let w=(0,H.useCallback)(e=>{C(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),T=(0,H.useCallback)(()=>{C(new Set)},[]),E=b===`touched-by-ai`?`${n??`all-jobs`}:${r??`all-specs`}`:`all`,{data:D,refresh:O,isFirstLoad:k,isLoading:A,error:M}=_({namespace:`code-tree-v2:${JSON.stringify([c,u,b,E])}`,projectId:f,initialValue:{entries:[],partial:!1},fetcher:(0,H.useCallback)(async({signal:e})=>{let t=new Map,i=new Set,a=null,o=!1;for(let c=0;c<20;c+=1){e.throwIfAborted();let c=new URLSearchParams({withProvenance:`1`,filter:b});b===`touched-by-ai`&&n&&c.set(`jobId`,n),b===`touched-by-ai`&&typeof r==`number`&&c.set(`ticketId`,String(r)),a&&c.set(`cursor`,a);let l=await fetch(`${s}/code/tree?${c}`,{signal:e});if(!l.ok)throw Error(`tree_request_failed`);let u=await l.json();if(e.throwIfAborted(),!Array.isArray(u.entries))throw Error(`invalid_tree_response`);for(let e of u.entries)t.set(e.path,e);if(o||=u.truncated===!0,a=u.nextCursor??null,!a)break;if(i.has(a)||t.size>=2e4){o=!0;break}i.add(a)}return{entries:[...t.values()].slice(0,2e4),partial:o||!!a}},[b,n,r,s])}),N=D.entries,P=(0,H.useRef)(f);(0,H.useEffect)(()=>{P.current=f},[f]),(0,H.useEffect)(()=>{if(!f)return;let e=`code-tree-${a}-${f}-${c??`primary`}`,t;return g(e,e=>{let n=e;n.projectId!==P.current||!Te(n.repositoryId,o)||n.type===`file.provenance_updated`&&(clearTimeout(t),t=setTimeout(()=>{O()},150))}),()=>{clearTimeout(t),y(e)}},[s,c,f,g,y,O,a]);let ee=(0,H.useRef)(null),I=(0,H.useMemo)(()=>(N??[]).filter(e=>!Me(e.path,S)),[N,S]),R=(0,H.useCallback)(()=>{C(new Set((N??[]).filter(e=>e.kind===`dir`).map(e=>e.path)))},[N]),B=Ce({count:I.length,getScrollElement:()=>ee.current,estimateSize:()=>28,overscan:12,initialRect:{width:320,height:600},observeElementRect:(e,t)=>{let n=e.scrollElement;if(!n)return()=>{};let r=()=>{let e=n.getBoundingClientRect(),r=e.height||n.clientHeight||600;t({width:e.width||n.clientWidth||320,height:r})};if(r(),typeof ResizeObserver<`u`){let e=new ResizeObserver(r);return e.observe(n),()=>e.disconnect()}return()=>{}}}),ie=(0,H.useId)(),[V,ae]=(0,H.useState)(t),oe=Math.max(0,I.findIndex(e=>e.path===V));(0,H.useEffect)(()=>{t&&(ae(t),C(e=>{let n=new Set(e),r=t.split(`/`);for(let e=1;e<r.length;e++)n.delete(r.slice(0,e).join(`/`));return n}))},[t]);let se=(0,H.useRef)(null);(0,H.useEffect)(()=>{if(!t||se.current===t)return;let e=I.findIndex(e=>e.path===t);e>=0&&(B.scrollToIndex(e,{align:`auto`}),se.current=t)},[t,I,B]);let ce=(t,n)=>{let r=I[n];if(!r)return;let i=n;switch(t.key){case`ArrowDown`:i=Math.min(I.length-1,n+1);break;case`ArrowUp`:i=Math.max(0,n-1);break;case`Home`:i=0;break;case`End`:i=I.length-1;break;case`ArrowRight`:r.kind===`dir`&&S.has(r.path)?w(r.path):r.kind===`dir`&&(i=Math.min(I.length-1,n+1));break;case`ArrowLeft`:if(r.kind===`dir`&&!S.has(r.path))w(r.path);else{let e=r.path.split(`/`).slice(0,-1).join(`/`),t=I.findIndex(t=>t.path===e);t>=0&&(i=t)}break;case`Enter`:case` `:r.kind===`dir`?w(r.path):e(r.path);break;default:return}t.preventDefault(),t.stopPropagation(),ae(I[i].path),i!==n&&B.scrollToIndex(i,{align:`auto`})},U=I.length===0,W=(0,H.useMemo)(()=>(N??[]).filter(e=>e.kind===`file`).length,[N]);return(0,Q.jsxs)(`div`,{className:`flex flex-col h-full`,"data-testid":`file-tree`,children:[(0,Q.jsxs)(`div`,{className:`px-2 py-2 border-b border-border text-xs space-y-2`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>x(`touched-by-ai`),className:j(`px-2 py-1 rounded-md transition-colors`,b===`touched-by-ai`?`bg-accent-primary/20 text-accent-primary`:`text-muted-foreground hover:text-foreground hover:bg-muted/50`),"aria-pressed":b===`touched-by-ai`,children:i(n?`tree.jobFiles`:r?`tree.specFiles`:`tree.touchedByAi`)}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>x(`all`),className:j(`px-2 py-1 rounded-md transition-colors`,b===`all`?`bg-accent-primary/20 text-accent-primary`:`text-muted-foreground hover:text-foreground hover:bg-muted/50`),"aria-pressed":b===`all`,children:i(`tree.allFiles`)}),(0,Q.jsx)(`div`,{className:`flex-1`}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{O()},disabled:A,"aria-label":i(`explore.refresh`),title:i(`explore.refresh`),className:`rounded p-1 text-muted-foreground hover:bg-muted disabled:opacity-40`,children:(0,Q.jsx)(ne,{className:`h-3.5 w-3.5 ${A?`animate-spin`:``}`})}),(0,Q.jsx)(`button`,{type:`button`,onClick:R,title:i(`tree.collapseAll`),className:`px-1.5 py-1 rounded-md text-muted-foreground hover:text-foreground hover:bg-muted/50`,"aria-label":i(`tree.collapseAll`),children:(0,Q.jsx)(L,{className:`w-3.5 h-3.5`})}),(0,Q.jsx)(`button`,{type:`button`,onClick:T,title:i(`tree.expandAll`),className:`px-1.5 py-1 rounded-md text-muted-foreground hover:text-foreground hover:bg-muted/50`,"aria-label":i(`tree.expandAll`),children:(0,Q.jsx)(re,{className:`w-3.5 h-3.5`})})]}),b===`touched-by-ai`&&W>0&&(0,Q.jsx)(`div`,{className:`flex items-center justify-between gap-2 text-[11px] text-muted-foreground`,children:(0,Q.jsx)(`span`,{children:i(`tree.touchedCount`,{count:W})})})]}),M&&(0,Q.jsxs)(`div`,{role:`alert`,className:`space-y-1 border-b border-border p-3 text-xs`,children:[(0,Q.jsx)(`p`,{children:i(`tree.loadFailed`)}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{O()},className:`text-accent-primary underline`,children:i(`explore.retry`)})]}),D.partial&&(0,Q.jsx)(`p`,{role:`status`,className:`border-b border-border p-3 text-xs text-amber-600 dark:text-amber-400`,children:i(`tree.partial`)}),U&&M?null:U&&k?(0,Q.jsx)(`div`,{className:`flex-1 flex items-center justify-center px-4 text-center`,"data-testid":`file-tree-loading`,children:(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground animate-pulse`,children:i(`tree.loadingFiles`)})}):U&&b===`touched-by-ai`?(0,Q.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center px-4 text-center gap-3`,children:[(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i(`tree.emptyTouched`)}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>x(`all`),className:`text-xs px-3 py-1.5 rounded-md bg-accent-primary/20 text-accent-primary hover:bg-accent-primary/30`,children:i(`tree.showAllFiles`)})]}):U?(0,Q.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-xs text-muted-foreground px-4 text-center`,children:i(`tree.noFiles`)}):(0,Q.jsx)(`div`,{ref:ee,className:`min-h-0 flex-1 overflow-auto outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-accent-primary/50`,"data-testid":`file-tree-scroller`,role:`tree`,tabIndex:0,"aria-label":i(`explore.files`),"aria-activedescendant":I[oe]?`${ie}-${oe}`:void 0,onKeyDown:e=>{e.target===e.currentTarget&&ce(e,oe)},children:(0,Q.jsx)(`div`,{style:{height:B.getTotalSize(),position:`relative`,width:`100%`},children:B.getVirtualItems().map(n=>{let r=I[n.index],a=Oe(r.path)*12,o=r.kind===`file`&&r.path===t,s=r.provenance?.createdByTicketId,c=r.provenance?.modifiedByTicketIds??[],u=r.provenance?.latest??null,d=Ae(u?.jobId),f=je(u?.kind),p=r.kind===`dir`,m=p&&S.has(r.path),g=r.provenance?.touchedFileCount??0;return(0,Q.jsxs)(`div`,{style:{position:`absolute`,top:0,left:0,transform:`translateY(${n.start}px)`,height:n.size,width:`100%`},className:j(`flex items-center gap-2 px-2 text-xs cursor-pointer hover:bg-muted/50`,o&&`bg-accent-primary/10 text-foreground`,r.path===V&&`ring-1 ring-inset ring-accent-primary/30`),onClick:()=>{ae(r.path),ee.current?.focus({preventScroll:!0}),p?w(r.path):e(r.path)},onKeyDown:e=>{e.target===e.currentTarget&&ce(e,n.index)},role:`treeitem`,id:`${ie}-${n.index}`,tabIndex:-1,"aria-level":Oe(r.path)+1,"aria-selected":o,title:r.path,"aria-expanded":p?!m:void 0,"data-testid":`file-tree-row-${r.path}`,children:[(0,Q.jsxs)(`span`,{style:{paddingLeft:a},className:`flex items-center gap-1 min-w-0 flex-1`,children:[p?(0,Q.jsxs)(Q.Fragment,{children:[m?(0,Q.jsx)(L,{className:`w-3 h-3 text-muted-foreground flex-shrink-0`}):(0,Q.jsx)(re,{className:`w-3 h-3 text-muted-foreground flex-shrink-0`}),m?(0,Q.jsx)(z,{className:`w-3.5 h-3.5 text-accent-info flex-shrink-0`}):(0,Q.jsx)(F,{className:`w-3.5 h-3.5 text-accent-info flex-shrink-0`})]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{className:`w-3 flex-shrink-0`}),(0,Q.jsx)(te,{className:`w-3.5 h-3.5 text-muted-foreground flex-shrink-0`})]}),(0,Q.jsx)(`span`,{className:`truncate ml-0.5`,children:ke(r.path)})]}),(0,Q.jsxs)(`span`,{className:`flex items-center gap-1 flex-shrink-0`,children:[p&&g>0&&(0,Q.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted/60 text-muted-foreground`,title:i(`tree.folderTouched`,{count:g}),children:g}),!p&&f&&(0,Q.jsx)(`span`,{className:j(`h-1.5 w-1.5 rounded-full`,u?.kind===`created`&&`bg-accent-success`,u?.kind===`modified`&&`bg-accent-info`,u?.kind===`deleted`&&`bg-destructive`),title:u?.kind===`created`?i(`tree.latestTitleCreated`):u?.kind===`deleted`?i(`tree.latestTitleDeleted`):i(`tree.latestTitleModified`),children:(0,Q.jsx)(`span`,{className:`sr-only`,children:i(`action.${f}`)})}),!p&&d&&(0,Q.jsxs)(`span`,{className:`inline-flex items-center px-0.5 text-muted-foreground`,title:i(`tree.jobTitle`,{jobId:u?.jobId??``}),children:[(0,Q.jsx)(l,{className:`h-3 w-3`}),(0,Q.jsx)(`span`,{className:`sr-only`,children:d})]}),!p&&typeof s==`number`&&(0,Q.jsxs)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),h(s)},className:`text-[10px] px-1.5 py-0.5 rounded bg-accent-success/20 text-accent-success`,"data-testid":`provenance-chip-created-${s}`,title:i(`tree.createdBySpec`,{id:s}),children:[`#`,s]}),!p&&c.slice(0,2).map(e=>(0,Q.jsxs)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),h(e)},className:`text-[10px] px-1.5 py-0.5 rounded bg-accent-info/15 text-accent-info`,"data-testid":`provenance-chip-modified-${e}`,title:i(`tree.modifiedBySpec`,{id:e}),children:[`#`,e]},e))]})]},r.path)})})})]})}function Pe(e){return new Worker(`/assets/editor.worker-tytyn86m.js`,{name:e?.name})}function Fe(e){return new Worker(`/assets/json.worker-Oa9UrkKE.js`,{name:e?.name})}function Ie(e){return new Worker(`/assets/css.worker-yKcq13f2.js`,{name:e?.name})}function Le(e){return new Worker(`/assets/html.worker-DSJ9zmd7.js`,{name:e?.name})}function Re(e){return new Worker(`/assets/ts.worker-BtjBFNHX.js`,{name:e?.name})}var ze=!1;function Be(e){let t=e.trim().match(/^hsl\(\s*([-\d.]+)[\s,]+([\d.]+)%[\s,]+([\d.]+)%\s*\)$/i);return t?[parseFloat(t[1]),parseFloat(t[2]),parseFloat(t[3])]:null}function $(e,t=`#1e1e1e`){if(e.startsWith(`#`))return e;let n=Be(e);if(!n)return t;let[r,i,a]=n,o=i/100,s=a/100,c=(1-Math.abs(2*s-1))*o,l=(r%360+360)%360/60,u=c*(1-Math.abs(l%2-1)),d=0,f=0,p=0;l<1?(d=c,f=u):l<2?(d=u,f=c):l<3?(f=c,p=u):l<4?(f=u,p=c):l<5?(d=u,p=c):(d=c,p=u);let m=s-c/2,h=e=>Math.round((e+m)*255).toString(16).padStart(2,`0`);return`#${h(d)}${h(f)}${h(p)}`}function Ve(e){return`specrails-${e}`}function He(e,t){let n=Ve(t.id),r=t.xterm,i=$(r.background),a=$(r.foreground),o=$(r.brightBlack),s=$(r.magenta),c=$(r.yellow),l=$(r.cyan),u=$(r.blue),d=$(r.green),f=$(r.brightBlack),p=$(r.brightCyan),m=$(r.red),h=$(r.selectionBackground);return e.editor.defineTheme(n,{base:t.scheme===`light`?`vs`:`vs-dark`,inherit:!0,rules:[{token:``,foreground:a.slice(1)},{token:`comment`,foreground:f.slice(1),fontStyle:`italic`},{token:`keyword`,foreground:s.slice(1)},{token:`string`,foreground:c.slice(1)},{token:`number`,foreground:l.slice(1)},{token:`constant`,foreground:p.slice(1)},{token:`constant.numeric`,foreground:l.slice(1)},{token:`type`,foreground:d.slice(1)},{token:`type.identifier`,foreground:d.slice(1)},{token:`identifier`,foreground:a.slice(1)},{token:`function`,foreground:u.slice(1)},{token:`tag`,foreground:m.slice(1)},{token:`attribute.name`,foreground:p.slice(1)},{token:`attribute.value`,foreground:c.slice(1)},{token:`delimiter`,foreground:o.slice(1)},{token:`operator`,foreground:o.slice(1)}],colors:{"editor.background":i,"editor.foreground":a,"editorLineNumber.foreground":o,"editorLineNumber.activeForeground":a,"editorCursor.foreground":$(r.cursor),"editor.selectionBackground":h,"editor.inactiveSelectionBackground":h,"editor.lineHighlightBackground":$(r.black),"editor.lineHighlightBorder":$(r.black),"editorGutter.background":i,"editorWhitespace.foreground":o,"editorIndentGuide.background1":$(r.black),"editorIndentGuide.activeBackground1":o,"scrollbarSlider.background":`${o}55`,"scrollbarSlider.hoverBackground":`${o}88`,"scrollbarSlider.activeBackground":`${o}bb`,"minimap.background":i}}),n}function Ue(){ze||=(self.MonacoEnvironment={getWorker(e,t){switch(t){case`json`:return new Fe;case`css`:case`scss`:case`less`:return new Ie;case`html`:case`handlebars`:case`razor`:return new Le;case`typescript`:case`javascript`:return new Re;default:return new Pe}}},!0)}function We({content:e,language:t,initialLine:n}){let{t:r}=m(`code`),a=R(),o=(0,H.useRef)(null),s=(0,H.useRef)(null),c=(0,H.useRef)(null),[l,u]=(0,H.useState)(!1),[d,f]=(0,H.useState)(!1),[p,h]=(0,H.useState)(0),[g,_]=(0,H.useState)(!1),[v,y]=(0,H.useState)(``),b=(0,H.useRef)({content:e,language:t,theme:a,initialLine:n,wrap:g});b.current={content:e,language:t,theme:a,initialLine:n,wrap:g};let x=(e,t=!1)=>{let n=s.current,r=n?.getModel();if(!n||!r||!Number.isFinite(e)||e<1)return;let i=Math.min(r.getLineCount(),Math.max(1,Math.floor(e)));n.setSelection({startLineNumber:i,startColumn:1,endLineNumber:i,endColumn:r.getLineMaxColumn(i)}),n.revealLineInCenter(i),t&&n.focus()};return(0,H.useEffect)(()=>{let e=!1;return u(!1),f(!1),Ue(),i(()=>import(`./editor.main-DxrmGfoq.js`).then(t=>{if(e||!o.current)return;c.current=t;let n=b.current,r=t.editor.create(o.current,{value:n.content,language:n.language,readOnly:!0,domReadOnly:!0,theme:He(t,n.theme),minimap:{enabled:!1},lineNumbers:`on`,scrollBeyondLastLine:!1,automaticLayout:!0,renderValidationDecorations:`off`,wordWrap:n.wrap?`on`:`off`,fontSize:13});s.current=r,x(n.initialLine),u(!0)}),__vite__mapDeps([0,1,2,3,4,5,6])).catch(()=>{e||f(!0)}),()=>{e=!0;let t=s.current?.getModel();s.current?.dispose(),t?.dispose(),s.current=null,c.current=null}},[p]),(0,H.useEffect)(()=>{let t=s.current;t&&t.getValue()!==e&&t.setValue(e)},[e]),(0,H.useEffect)(()=>{let e=s.current?.getModel();e&&c.current&&c.current.editor.setModelLanguage(e,t)},[t]),(0,H.useEffect)(()=>{let e=c.current;e&&e.editor.setTheme(He(e,a))},[a]),(0,H.useEffect)(()=>{x(n)},[n,l]),(0,H.useEffect)(()=>{s.current?.updateOptions({wordWrap:g?`on`:`off`})},[g]),(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[(0,Q.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-2 border-b border-border bg-muted/20 px-3 py-1 text-xs`,children:[(0,Q.jsx)(`button`,{type:`button`,disabled:!l,className:`rounded px-2 py-1 hover:bg-muted disabled:opacity-50`,onClick:()=>{s.current?.getAction(`actions.find`)?.run()},children:r(`reader.find`,{defaultValue:`Find in file`})}),(0,Q.jsx)(`button`,{type:`button`,disabled:!l,"aria-pressed":g,className:`rounded px-2 py-1 hover:bg-muted disabled:opacity-50`,onClick:()=>_(e=>!e),children:r(`reader.wrap`,{defaultValue:`Wrap lines`})}),(0,Q.jsxs)(`form`,{className:`ml-auto flex items-center gap-1`,onSubmit:e=>{e.preventDefault(),x(Number(v),!0)},children:[(0,Q.jsx)(`input`,{type:`number`,min:1,step:1,"aria-label":r(`reader.line`,{defaultValue:`Line number`}),placeholder:`#`,title:r(`reader.line`,{defaultValue:`Line number`}),value:v,onChange:e=>y(e.target.value),className:`w-28 rounded border border-border bg-background px-2 py-1`}),(0,Q.jsx)(`button`,{type:`submit`,disabled:!l||!Number.isInteger(Number(v))||Number(v)<1,className:`rounded px-2 py-1 hover:bg-muted disabled:opacity-50`,children:r(`reader.go`,{defaultValue:`Go`})})]})]}),d?(0,Q.jsxs)(`div`,{className:`flex flex-1 flex-col items-center justify-center gap-2 text-sm text-muted-foreground`,"data-testid":`monaco-load-error`,children:[(0,Q.jsx)(`span`,{children:r(`monaco.loadFailed`)}),(0,Q.jsx)(`button`,{onClick:()=>h(e=>e+1),className:`rounded border px-3 py-1`,children:r(`reader.retry`,{defaultValue:`Retry`})})]}):(0,Q.jsxs)(`div`,{className:`relative min-h-0 flex-1`,children:[!l&&(0,Q.jsx)(`div`,{role:`status`,className:`absolute inset-0 flex items-center justify-center text-sm text-muted-foreground`,children:r(`reader.loading`,{defaultValue:`Loading source viewer…`})}),(0,Q.jsx)(`div`,{ref:o,className:`h-full w-full`,"data-testid":`monaco-host`})]})]})}function Ge(e,t){if(!e)return null;let n=Date.parse(e);if(Number.isNaN(n))return null;let r=Math.round((n-Date.now())/1e3),i=new Intl.RelativeTimeFormat(t,{numeric:`auto`}),a=Math.abs(r);return a<60?i.format(r,`second`):a<3600?i.format(Math.round(r/60),`minute`):a<86400?i.format(Math.round(r/3600),`hour`):i.format(Math.round(r/86400),`day`)}function Ke({path:e,summary:t,stale:n,regenerating:r,generateDisabledReason:i,onCollapse:a}){let{t:o,i18n:s}=m(`code`),{openTicketDetail:c}=d();if(!t)return(0,Q.jsx)(`div`,{className:`border-b border-border px-4 py-3 bg-surface`,"data-testid":`summary-header-empty`,children:(0,Q.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-col gap-0.5 min-w-0`,children:[(0,Q.jsx)(`span`,{className:`text-xs text-muted-foreground truncate`,children:e}),(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:i?o(`summary.unavailable`,{reason:i}):o(`summary.empty`)})]}),a&&(0,Q.jsxs)(`button`,{type:`button`,onClick:a,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[11px] text-muted-foreground hover:bg-muted/50 hover:text-foreground`,children:[(0,Q.jsx)(C,{className:`h-3.5 w-3.5`}),o(`summary.hide`)]})]})});let l=Ge(t.generatedAt,s.language),u=t.generatedBy?.model??t.model,f=t.generatedAt&&Number.isFinite(Date.parse(t.generatedAt))?new Date(t.generatedAt).toLocaleString(s.language):void 0,p=t.triggeredBy?.ticketId,h=t.triggeredBy?.modifiedTicketIds??[];return(0,Q.jsx)(`div`,{className:`border-b border-border px-4 py-3 bg-surface`,"data-testid":`summary-header`,children:(0,Q.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,Q.jsx)(`span`,{className:`text-xs text-muted-foreground truncate`,children:e}),n&&(0,Q.jsx)(`span`,{className:j(`text-[10px] px-1.5 py-0.5 rounded bg-accent-warning/20 text-accent-warning font-medium`),"data-testid":`summary-stale-badge`,children:o(`summary.stale`)}),r&&(0,Q.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-accent-primary animate-pulse`,"aria-hidden":!0})]}),(0,Q.jsx)(`p`,{className:`text-sm text-foreground mt-1 whitespace-pre-wrap break-words`,children:t.summary}),t.generatedBy?.truncated&&(0,Q.jsx)(`p`,{className:`mt-2 text-xs text-accent-warning`,children:o(`reader.summaryPartial`,{defaultValue:`Generated from a partial source snapshot. This summary may not cover the entire file.`})}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 mt-2 flex-wrap`,children:[u&&(0,Q.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:o(`story.explainedBy`,{model:u})}),typeof p==`number`&&(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>c(p),className:`text-[10px] px-1.5 py-0.5 rounded bg-accent-success/20 text-accent-success`,children:[`#`,p]}),h.map(e=>(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>c(e),className:`text-[10px] px-1.5 py-0.5 rounded bg-accent-info/15 text-accent-info`,children:[`#`,e]},e)),l&&(0,Q.jsx)(`time`,{className:`text-[10px] text-muted-foreground`,dateTime:t.generatedAt,title:f,children:l})]})]}),a&&(0,Q.jsxs)(`button`,{type:`button`,onClick:a,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[11px] text-muted-foreground hover:bg-muted/50 hover:text-foreground`,children:[(0,Q.jsx)(C,{className:`h-3.5 w-3.5`}),o(`summary.hide`)]})]})})}function qe({content:e}){return(0,Q.jsx)(M,{remarkPlugins:[N],children:e})}var Je=2e3,Ye=256e3;function Xe({path:e,jobId:t}){let{activeProjectId:n}=v(),r=Z(),i=JSON.stringify([n,r.apiBase,r.repositoryPath,e,t]);return(0,Q.jsx)(Ze,{path:e,jobId:t},i)}function Ze({path:e,jobId:t}){let{t:n}=m(`code`),{apiBase:r}=Z(),[i,a]=(0,H.useState)(null),[o,s]=(0,H.useState)(`loading`),[c,l]=(0,H.useState)(0);(0,H.useEffect)(()=>{let n=new AbortController;s(`loading`);let i=new URLSearchParams({path:e,jobId:t});return fetch(`${r}/code/diff?${i}`,{signal:n.signal}).then(async e=>{if(e.status===404){n.signal.aborted||s(`missing`);return}if(!e.ok)throw Error(`Diff request failed`);let t=await e.json();if(typeof t.patch!=`string`)throw Error(`Invalid patch response`);n.signal.aborted||(a({patch:t.patch,truncated:t.truncated===!0}),s(t.patch?`ready`:`missing`))}).catch(()=>{n.signal.aborted||s(`failed`)}),()=>n.abort()},[r,e,t,c]);let u=(i?.patch??``).slice(0,Ye).split(`
|
|
3
|
+
`),d=u.length>Je||(i?.patch.length??0)>Ye,f=null,p=null;return(0,Q.jsxs)(`section`,{className:`flex min-h-0 flex-col gap-2 text-xs`,"data-testid":`recorded-diff`,children:[(0,Q.jsxs)(`div`,{className:`rounded-md border border-border bg-muted/30 px-3 py-2`,children:[(0,Q.jsxs)(`p`,{className:`font-medium`,children:[n(`reader.recordedChange`,{defaultValue:`Recorded change`}),` · `,(0,Q.jsx)(`span`,{className:`font-mono`,title:t,children:t.slice(0,12)})]}),(0,Q.jsx)(`p`,{className:`mt-1 text-muted-foreground`,children:n(`reader.recordedNotice`,{defaultValue:`This patch records a past run. It may differ from the current registered checkout.`})})]}),o===`loading`&&(0,Q.jsx)(`p`,{role:`status`,children:n(`history.loadingDiff`)}),o===`missing`&&(0,Q.jsx)(`p`,{children:n(`history.diffUnavailable`)}),o===`failed`&&(0,Q.jsxs)(`div`,{role:`alert`,children:[(0,Q.jsx)(`p`,{children:n(`reader.diffFailed`,{defaultValue:`Could not load the recorded change.`})}),(0,Q.jsx)(`button`,{className:`mt-2 rounded border px-2 py-1`,onClick:()=>l(e=>e+1),children:n(`reader.retry`,{defaultValue:`Retry`})})]}),o===`ready`&&i&&(0,Q.jsxs)(Q.Fragment,{children:[i.truncated&&(0,Q.jsx)(`p`,{className:`text-accent-warning`,children:n(`reader.patchIncomplete`,{defaultValue:`The stored patch is incomplete. Missing content cannot be reconstructed from this record.`})}),d&&(0,Q.jsx)(`p`,{className:`text-accent-warning`,children:n(`reader.displayLimited`,{defaultValue:`Preview limited to {{count}} lines or {{chars}} characters. The remaining patch is not shown.`,count:Je,chars:Ye})}),(0,Q.jsx)(`div`,{className:`max-h-[32rem] overflow-auto rounded-md border border-border bg-background font-mono text-[11px] leading-5`,tabIndex:0,"aria-label":n(`reader.patch`,{defaultValue:`Recorded patch`}),children:u.slice(0,Je).map((e,t)=>{let n=/^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/.exec(e),r=null,i=null,a=`meta`;return n?(f=Number(n[1]),p=Number(n[2])):f!==null&&p!==null&&(e.startsWith(`+`)?(a=`added`,i=p++):e.startsWith(`-`)?(a=`removed`,r=f++):e.startsWith(` `)&&(a=`context`,r=f++,i=p++)),(0,Q.jsxs)(`div`,{"data-kind":a,className:`flex min-w-max ${a===`added`?`bg-accent-success/10`:a===`removed`?`bg-destructive/10`:a===`meta`?`text-muted-foreground`:``}`,children:[(0,Q.jsx)(`span`,{"aria-hidden":!0,className:`w-12 shrink-0 select-none border-r border-border/40 px-2 text-right text-muted-foreground`,children:r}),(0,Q.jsx)(`span`,{"aria-hidden":!0,className:`w-12 shrink-0 select-none border-r border-border/40 px-2 text-right text-muted-foreground`,children:i}),(0,Q.jsx)(`code`,{className:`whitespace-pre px-3`,children:e||` `})]},t)})})]})]})}var Qe={done:`bg-accent-success/15 text-accent-success`,in_progress:`bg-accent-info/15 text-accent-info`,on_review:`bg-accent-warning/15 text-accent-warning`,todo:`bg-muted/60 text-muted-foreground`,draft:`bg-accent-secondary/15 text-accent-secondary`};function $e(e){return e===`created`?s:e===`deleted`?c:w}function et(e){let t=Z(),{activeProjectId:n}=v(),r=JSON.stringify([n,t.apiBase,t.repositoryPath,e.relPath]);return(0,Q.jsx)(tt,{...e},r)}function tt({relPath:e,height:t,onOpenTicket:n,onFilterJob:r,onViewDiff:i}){let{t:a}=m(`code`),o=Z(),{apiBase:s,repositoryId:c}=o,{activeProjectId:l,projects:u}=v(),d=u.find(e=>e.id===l)?.provider,f=b(d),{registerHandler:h,unregisterHandler:g}=p(),_=(0,H.useId)(),[x,S]=(0,H.useState)(null),[C,w]=(0,H.useState)(!1),T=(0,H.useRef)(!0),E=(0,H.useRef)(null),D=(0,H.useRef)(new Map);(0,H.useEffect)(()=>(T.current=!0,()=>{T.current=!1,E.current?.abort();for(let e of D.current.values())e.abort();D.current.clear()}),[]);let[O,k]=(0,H.useState)({}),A=(0,H.useRef)(l);(0,H.useEffect)(()=>{A.current=l},[l]);let j=(0,H.useRef)(e);(0,H.useEffect)(()=>{j.current=e},[e]);let M=(0,H.useRef)(0),N=(0,H.useCallback)(async()=>{if(!T.current)return;let t=++M.current;E.current?.abort();let n=new AbortController;E.current=n;try{let r=await fetch(`${s}/code/file/story?path=${encodeURIComponent(e)}`,{signal:n.signal});if(!T.current||n.signal.aborted||t!==M.current)return;if(!r.ok){S([]),w(!0);return}let i=await r.json();if(!T.current||n.signal.aborted||t!==M.current)return;S(Array.isArray(i.story)?i.story:[]),w(!1)}catch{T.current&&!n.signal.aborted&&t===M.current&&(S([]),w(!0))}},[e,l,s]);(0,H.useEffect)(()=>{S(null),k({}),N()},[N]),(0,H.useEffect)(()=>{if(!l)return;let e=`code-story-${l}-${c??`primary`}-${_}`;return h(e,e=>{let t=e;t.projectId!==A.current||!Te(t.repositoryId,o)||t.path===j.current&&(t.type===`file.story_updated`||t.type===`file.provenance_updated`)&&N()}),()=>g(e)},[_,s,c,l,h,g,N]);let P=(0,H.useCallback)(async(t,n)=>{if(!f||!T.current||!t.hasPatch||t.evidence?.kind===`missing`||D.current.has(t.provenanceId))return;let r=new AbortController;D.current.set(t.provenanceId,r),k(e=>({...e,[t.provenanceId]:`busy`}));try{let i=await fetch(`${s}/code/file/story/explain?path=${encodeURIComponent(e)}`,{method:`POST`,signal:r.signal,headers:{"content-type":`application/json`},body:JSON.stringify({provenanceId:t.provenanceId,overrideBudget:n,...t.summaryStale?{force:!0}:{}})}),o=await i.json().catch(()=>({}));if(!T.current||r.signal.aborted)return;if(o.skipped===`budget`){k(e=>({...e,[t.provenanceId]:`budget`}));return}if(!i.ok||!o.ok){y.error(a(`story.explainFailed`)),k(e=>{let n={...e};return delete n[t.provenanceId],n});return}if(await N(),!T.current||r.signal.aborted)return;k(e=>{let n={...e};return delete n[t.provenanceId],n})}catch{if(!T.current||r.signal.aborted)return;y.error(a(`story.explainFailed`)),k(e=>{let n={...e};return delete n[t.provenanceId],n})}finally{D.current.delete(t.provenanceId)}},[f,N,e,a]);return(0,Q.jsx)(`div`,{className:`shrink-0 border-t border-border bg-card/40 px-4 py-3 overflow-hidden`,style:{height:t},"data-testid":`construction-story`,children:(0,Q.jsx)(`div`,{className:`h-full overflow-auto`,children:x===null?(0,Q.jsx)(`div`,{className:`text-[11px] text-muted-foreground animate-pulse py-2`,children:a(`story.loading`)}):C?(0,Q.jsxs)(`div`,{className:`text-[11px] text-muted-foreground py-2`,"data-testid":`story-failed`,role:`alert`,children:[a(`story.loadFailed`),` `,(0,Q.jsx)(`button`,{className:`ml-2 underline`,onClick:()=>{N()},children:a(`reader.retry`,{defaultValue:`Retry`})})]}):x.length===0?(0,Q.jsx)(`div`,{className:`text-[11px] text-muted-foreground py-2`,"data-testid":`story-empty`,children:a(`story.empty`)}):(0,Q.jsx)(`ol`,{className:`relative ml-1.5 border-l border-border/60 space-y-3 py-1`,children:x.map(t=>(0,Q.jsx)(nt,{entry:t,state:O[t.provenanceId],canExplain:f&&t.hasPatch&&t.evidence?.kind!==`missing`,path:e,onViewDiff:i,onOpenTicket:n,onFilterJob:r,onExplain:e=>{P(t,e)}},t.provenanceId))})})})}function nt({entry:e,state:t,canExplain:n,path:r,onViewDiff:i,onOpenTicket:a,onFilterJob:o,onExplain:s}){let{t:c}=m(`code`),[l,u]=(0,H.useState)(!1),d=$e(e.kind),f=e.ticket?.status??null,p=e.ticket?.title?`#${e.ticket.id} · ${e.ticket.title}`:e.ticketId==null?null:c(`story.spec`,{ticketId:e.ticketId}),h=e.ticketId==null?`${e.kind}NoSpec`:e.kind;return(0,Q.jsxs)(`li`,{className:`relative pl-4`,"data-testid":`story-card`,children:[(0,Q.jsx)(`span`,{"aria-hidden":!0,className:`absolute -left-[5px] top-2 h-2.5 w-2.5 rounded-full border-2 border-background ${e.kind===`created`?`bg-accent-success`:e.kind===`deleted`?`bg-destructive`:`bg-accent-info`}`}),(0,Q.jsxs)(`article`,{className:`rounded-lg border border-border/60 bg-card/60 px-3 py-2.5 backdrop-blur-sm transition-colors hover:border-border`,children:[(0,Q.jsxs)(`header`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,Q.jsx)(d,{className:`h-3.5 w-3.5 shrink-0`}),c(`story.kindLabel.${e.kind}`)]}),p!=null&&e.ticketId!=null&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>a(e.ticketId),className:`min-w-0 max-w-full truncate rounded bg-accent-primary/15 px-1.5 py-0.5 text-left text-[11px] font-medium text-accent-primary hover:bg-accent-primary/25`,title:c(`story.openSpec`,{ticketId:e.ticketId}),children:p}),p==null&&(0,Q.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:c(`story.unknownSpec`)}),f&&(0,Q.jsx)(`span`,{className:`rounded px-1.5 py-0.5 text-[10px] ${Qe[f]??`bg-muted/60 text-muted-foreground`}`,"data-testid":`story-status-pill`,children:f}),(0,Q.jsxs)(`span`,{className:`ml-auto inline-flex items-center gap-2`,children:[e.addedLines!=null&&e.addedLines>0&&(0,Q.jsxs)(`span`,{className:`font-mono text-[10px] text-accent-success`,title:c(`story.linesAdded`),children:[`+`,e.addedLines]}),e.removedLines!=null&&e.removedLines>0&&(0,Q.jsxs)(`span`,{className:`font-mono text-[10px] text-destructive`,title:c(`story.linesRemoved`),children:[`−`,e.removedLines]}),(0,Q.jsx)(`time`,{className:`text-[10px] text-muted-foreground`,dateTime:new Date(e.at).toISOString(),children:new Date(e.at).toLocaleString()})]})]}),(0,Q.jsx)(`div`,{className:`mt-1.5`,children:e.summary?(0,Q.jsxs)(Q.Fragment,{children:[e.summaryStale&&(0,Q.jsx)(`span`,{className:`text-[10px] text-accent-warning`,children:c(`summary.stale`)}),(0,Q.jsx)(`p`,{className:`text-sm leading-relaxed text-foreground/90`,"data-testid":`story-contribution`,children:e.summary}),e.summaryGeneratedAt&&(0,Q.jsx)(`time`,{className:`mt-1 block text-[10px] text-muted-foreground`,dateTime:e.summaryGeneratedAt,children:new Date(e.summaryGeneratedAt).toLocaleString()}),e.summaryStale&&n&&(t===`budget`?(0,Q.jsxs)(`span`,{className:`mt-1 inline-flex items-center gap-2 text-[11px] text-accent-warning`,children:[(0,Q.jsx)(`span`,{children:c(`story.budgetReached`)}),(0,Q.jsx)(`button`,{className:`rounded border px-2 py-1`,onClick:()=>s(!0),children:c(`story.generateAnyway`)})]}):(0,Q.jsx)(`button`,{disabled:t===`busy`,className:`mt-1 rounded border px-2 py-1 text-[11px]`,onClick:()=>s(!1),children:t===`busy`?c(`story.explaining`):c(`reader.regenerateExplanation`,{defaultValue:`Refresh explanation`})})),e.summaryModel&&(0,Q.jsx)(`p`,{className:`mt-1 text-[10px] text-muted-foreground/80`,children:c(`story.explainedBy`,{model:e.summaryModel})})]}):(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,"data-testid":`story-fallback`,children:c(`story.fallback.${h}`)}),n?t===`budget`?(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,Q.jsx)(`span`,{className:`text-[10px] text-accent-warning`,children:c(`story.budgetReached`)}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>s(!0),className:`rounded bg-accent-warning/15 px-1.5 py-0.5 text-[10px] text-accent-warning hover:bg-accent-warning/25`,children:c(`story.generateAnyway`)})]}):(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>s(!1),disabled:t===`busy`,className:`inline-flex items-center gap-1 rounded bg-accent-primary/10 px-1.5 py-0.5 text-[10px] text-accent-primary hover:bg-accent-primary/20 disabled:opacity-60`,"data-testid":`story-explain`,children:[(0,Q.jsx)(D,{className:t===`busy`?`h-3 w-3 animate-pulse`:`h-3 w-3`}),c(t===`busy`?`story.explaining`:`story.explain`)]}):(0,Q.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,"data-testid":`story-explain-unavailable`,children:!e.hasPatch||e.evidence?.kind===`missing`?c(`reader.noEvidence`,{defaultValue:`No patch evidence was stored for this change.`}):c(`story.explainUnavailable`)})]})}),e.summary&&(!e.hasPatch||e.evidence?.kind===`missing`)&&(0,Q.jsx)(`p`,{className:`mt-2 text-[10px] text-accent-warning`,children:c(`reader.noEvidence`,{defaultValue:`No patch evidence was stored for this change.`})}),(e.summaryEvidence?.truncated??e.evidence?.truncated)&&(0,Q.jsx)(`p`,{className:`mt-2 text-[10px] text-accent-warning`,children:c(`reader.excerptEvidence`,{defaultValue:`This explanation uses incomplete patch evidence.`})}),e.jobId&&(0,Q.jsxs)(`div`,{className:`mt-2`,children:[(0,Q.jsx)(`button`,{className:`rounded border px-2 py-1 text-[11px]`,onClick:()=>{i?i(e.jobId):u(e=>!e)},children:c(`reader.viewPatch`,{defaultValue:`View recorded change`})}),l&&(0,Q.jsx)(`div`,{className:`mt-2`,children:(0,Q.jsx)(Xe,{path:r,jobId:e.jobId})})]}),e.jobId&&o&&(0,Q.jsx)(`footer`,{className:`mt-1.5`,children:(0,Q.jsx)(`button`,{type:`button`,onClick:()=>o(e.jobId),className:`font-mono text-[10px] text-muted-foreground hover:text-foreground`,title:c(`history.filterByJob`,{jobId:e.jobId}),children:e.jobId.length>12?e.jobId.slice(0,12):e.jobId})})]})]})}function rt(e,t){return t===`markdown`||t===`md`||/\.(md|mdx|markdown)$/i.test(e)}var it=180,at=120,ot=240;function st(e){return e?`specrails-desktop:code-summary-collapsed:${e}`:null}function ct(e){return e?`specrails-desktop:code-history-height:${e}`:null}function lt(e){return e?`specrails-desktop:code-history-collapsed:${e}`:null}function ut(e){return e?`specrails-desktop:code-history-mode:${e}`:null}function dt(e){let t=ut(e);if(!t)return`story`;try{return localStorage.getItem(t)===`log`?`log`:`story`}catch{return`story`}}function ft(e,t){let n=ut(e);if(n)try{localStorage.setItem(n,t)}catch{}}function pt(e){let t=ct(e);if(!t)return it;try{let e=localStorage.getItem(t),n=e?Number(e):NaN;return Number.isFinite(n)&&n>0?n:it}catch{return it}}function mt(e,t){let n=ct(e);if(n)try{localStorage.setItem(n,String(Math.round(t)))}catch{}}function ht(e){let t=st(e);if(!t)return!1;try{return localStorage.getItem(t)===`true`}catch{return!1}}function gt(e,t){let n=st(e);if(n)try{localStorage.setItem(n,t?`true`:`false`)}catch{}}function _t(e,t=!1){let n=lt(e);if(!n)return t;let r=t?n+`:compact`:n;try{let e=localStorage.getItem(r);return e===null?t:e===`true`}catch{return t}}function vt(e,t,n=!1){let r=lt(e),i=r&&n?r+`:compact`:r;if(i)try{localStorage.setItem(i,t?`true`:`false`)}catch{}}function yt(e,t){let n=Math.max(at,t-ot);return Math.min(Math.max(e,at),n)}function bt(e){let{activeProjectId:t}=v(),n=Z(),r=JSON.stringify([t,n.apiBase,n.repositoryId,n.repositoryPath,e.relPath,e.initialJobId]);return(0,Q.jsx)(xt,{...e},r)}function xt({relPath:e,initialLine:t,initialJobId:n,compact:r=!1,onFilterJob:i,onSummaryActionChange:a,onCopyPathActionChange:o}){let{t:s}=m(`code`),c=Z(),{apiBase:l,repositoryId:u}=c,{activeProjectId:f,projects:h}=v(),g=h.find(e=>e.id===f)?.provider,_=b(g),{openTicketDetail:x}=d(),{registerHandler:S,unregisterHandler:w}=p(),T=(0,H.useId)(),E=k({allowMove:!1}),D=(0,H.useRef)(null),[O,j]=(0,H.useState)(null),[M,N]=(0,H.useState)(!1),P=(0,H.useRef)(!0),ee=(0,H.useRef)(null),F=(0,H.useRef)(new Set);(0,H.useEffect)(()=>(P.current=!0,()=>{P.current=!1,ee.current?.abort();for(let e of F.current)e.abort();F.current.clear()}),[]);let[I,te]=(0,H.useState)(n??null),[L,R]=(0,H.useState)(n?`recorded`:`source`);(0,H.useEffect)(()=>{te(n??null),R(n?`recorded`:`source`)},[n]),(0,H.useEffect)(()=>{t&&!n&&R(`source`)},[t,n]);let ne=(0,H.useCallback)(e=>{te(e),R(`recorded`)},[]),[z,B]=(0,H.useState)(!0),[ie,V]=(0,H.useState)(!1),[ae,oe]=(0,H.useState)(!1),[se,U]=(0,H.useState)(()=>ht(f)),[W,G]=(0,H.useState)(()=>pt(f)),[K,le]=(0,H.useState)(()=>_t(f,r)),[q,ue]=(0,H.useState)(()=>dt(f)),J=(0,H.useRef)(f);(0,H.useEffect)(()=>{J.current=f},[f]);let de=(0,H.useRef)(e);(0,H.useEffect)(()=>{de.current=e},[e]),(0,H.useEffect)(()=>{let e=D.current?.clientHeight||window.innerHeight;U(ht(f)),G(yt(pt(f),e)),le(_t(f,r)),ue(dt(f))},[f,r]);let fe=(0,H.useCallback)(e=>{let t=e.clientY,n=W,r=D.current?.clientHeight||window.innerHeight,i=e.currentTarget;try{i.setPointerCapture(e.pointerId)}catch{}function a(e){G(yt(n+(t-e.clientY),r))}function o(){window.removeEventListener(`pointermove`,a),window.removeEventListener(`pointerup`,o),window.removeEventListener(`pointercancel`,o),G(e=>{let t=yt(e,r);return mt(f,t),t})}window.addEventListener(`pointermove`,a),window.addEventListener(`pointerup`,o),window.addEventListener(`pointercancel`,o)},[f,W]),pe=(0,H.useCallback)(()=>{let e=yt(it,D.current?.clientHeight||window.innerHeight);G(e),mt(f,e)},[f]),me=(0,H.useCallback)(()=>{U(e=>{let t=!e;return gt(f,t),t})},[f]),Y=(0,H.useCallback)(()=>{le(e=>{let t=!e;return vt(f,t,r),t})},[f,r]),he=(0,H.useCallback)(e=>{ue(e),ft(f,e)},[f]);(0,H.useEffect)(()=>{xe(t?`raw`:`preview`)},[e,t]);let ge=(0,H.useRef)(0),X=(0,H.useCallback)(async()=>{if(!P.current)return;let t=++ge.current;ee.current?.abort();let n=new AbortController;ee.current=n,B(!0),N(!1);try{let r=await fetch(`${l}/code/file?path=${encodeURIComponent(e)}`,{signal:n.signal});if(!P.current||n.signal.aborted||t!==ge.current)return;if(!r.ok){N(!0);return}let i=await r.json();if(!P.current||n.signal.aborted||t!==ge.current)return;j(i)}catch{P.current&&!n.signal.aborted&&t===ge.current&&N(!0)}finally{P.current&&!n.signal.aborted&&t===ge.current&&B(!1)}},[e,f,l]);(0,H.useEffect)(()=>{X()},[X]),(0,H.useEffect)(()=>{let e=()=>{X()};return window.addEventListener(`focus`,e),()=>window.removeEventListener(`focus`,e)},[X]),(0,H.useEffect)(()=>{if(!f)return;let e=`code-file-${f}-${u??`primary`}-${T}`;return S(e,e=>{let t=e;t.projectId!==J.current||!Te(t.repositoryId,c)||((t.type===`file.summary_updated`||t.type===`file.provenance_updated`||t.type===`file.content_updated`)&&t.path===de.current?(t.type===`file.summary_updated`&&V(!1),X()):t.type===`file.summary_failed`&&t.path===de.current?(y.error(t.reason??s(`summary.generationFailed`)),V(!1)):t.type===`file.summary_skipped`&&t.path===de.current&&(t.reason&&y(s(`summary.skipped`,{reason:t.reason})),V(!1)))}),()=>w(e)},[T,l,u,f,S,w,X,s]);let _e=(0,H.useCallback)(async t=>{if(!_||!P.current||F.current.size>0)return;let n=new AbortController;F.current.add(n),V(!0);try{let r=await fetch(`${l}/code/file/regenerate-summary?path=${encodeURIComponent(e)}`,{method:`POST`,signal:n.signal,headers:{"content-type":`application/json`},body:JSON.stringify({overrideBudget:t})}),i=await r.json().catch(()=>({}));if(!P.current||n.signal.aborted)return;if(!r.ok){V(!1);let e=typeof i.skipped==`string`?i.skipped:null;y.error(e?s(`summary.skipped`,{reason:e}):s(`summary.generationFailed`));return}if(i.skipped===`budget`){V(!1),oe(!0);return}if(i.skipped){V(!1),y(s(`summary.skipped`,{reason:i.skipped}));return}await X(),P.current&&!n.signal.aborted&&V(!1)}catch{P.current&&!n.signal.aborted&&(V(!1),y.error(s(`summary.generationFailed`)))}finally{F.current.delete(n)}},[_,X,e,s]),ve=(0,H.useCallback)(async()=>{let t=O?.absolutePath??e;try{if(!navigator.clipboard?.writeText)throw Error(`Clipboard unavailable`);await navigator.clipboard.writeText(t),y.success(s(`viewer.pathCopied`))}catch{y.error(s(`viewer.copyPathFailed`))}},[O,e,s]),ye=(0,H.useMemo)(()=>rt(e,O?.language),[e,O?.language]),[be,xe]=(0,H.useState)(t?`raw`:`preview`),Se=O?.summary??null,Ce=!!O?.summaryStale,we=O?.provenance??[],Ee=O?.reason===`not-found`,De=O?_?Ee?s(`summary.reason.missing`):O?.binary?s(`summary.reason.binary`):O?.tooLarge?s(`summary.reason.tooLarge`):null:s(`summary.reason.providerNoPureOutput`):s(`reader.sourceUnavailable`,{defaultValue:`source unavailable`});return(0,H.useEffect)(()=>{if(a){if(L===`recorded`||z&&!O){a(null);return}return a({hasSummary:!!Se,regenerating:ie,disabledReason:De,onClick:()=>_e(!1)}),()=>a(null)}},[O,_e,z,a,ie,Se,De,L]),(0,H.useEffect)(()=>{if(o){if(z&&!O){o(null);return}return o({onClick:ve}),()=>o(null)}},[ve,O,z,o]),L===`source`&&z&&!O?(0,Q.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-sm text-muted-foreground animate-pulse`,children:s(`viewer.loadingFile`)}):(0,Q.jsxs)(`div`,{ref:D,className:`flex flex-col h-full`,"data-testid":`file-viewer`,children:[L===`source`&&(se?(0,Q.jsxs)(`div`,{className:`flex h-8 shrink-0 items-center justify-between border-b border-border bg-surface px-4`,"data-testid":`summary-header-collapsed`,children:[(0,Q.jsx)(`span`,{className:`truncate text-xs text-muted-foreground`,children:e}),(0,Q.jsxs)(`button`,{type:`button`,onClick:me,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[11px] text-muted-foreground hover:bg-muted/50 hover:text-foreground`,children:[(0,Q.jsx)(re,{className:`h-3.5 w-3.5`}),s(`viewer.showSummary`)]})]}):(0,Q.jsx)(Ke,{path:e,summary:Se,stale:Ce,regenerating:ie,generateDisabledReason:De,onCollapse:me})),(0,Q.jsxs)(`div`,{className:`px-4 py-1 border-b border-border flex flex-wrap items-center justify-between gap-2`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 min-w-0`,children:[(0,Q.jsx)(`button`,{"aria-pressed":L===`source`,onClick:()=>R(`source`),className:`rounded px-2 py-1 text-xs hover:bg-muted`,children:s(`reader.currentFile`,{defaultValue:`Current file`})}),I&&(0,Q.jsx)(`button`,{"aria-pressed":L===`recorded`,onClick:()=>R(`recorded`),className:`rounded px-2 py-1 text-xs hover:bg-muted`,children:s(`reader.recordedChange`,{defaultValue:`Recorded change`})}),L===`source`&&ye&&O?.content!==void 0&&!O.binary&&!O.tooLarge&&(0,Q.jsxs)(`div`,{className:`flex items-center gap-1 text-[11px]`,role:`group`,"aria-label":s(`viewer.markdownViewMode`),children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>xe(`preview`),"aria-pressed":be===`preview`,className:be===`preview`?`px-2 py-1 rounded-md bg-accent-primary/20 text-accent-primary`:`px-2 py-1 rounded-md text-muted-foreground hover:text-foreground hover:bg-muted/50`,children:s(`viewer.preview`)}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>xe(`raw`),"aria-pressed":be===`raw`,className:be===`raw`?`px-2 py-1 rounded-md bg-accent-primary/20 text-accent-primary`:`px-2 py-1 rounded-md text-muted-foreground hover:text-foreground hover:bg-muted/50`,children:s(`viewer.raw`)})]})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] text-muted-foreground`,children:[O?.language&&(0,Q.jsx)(`span`,{children:O.language}),typeof O?.sizeBytes==`number`&&(0,Q.jsxs)(`span`,{children:[(O.sizeBytes/1024).toFixed(1),` KB`]}),(0,Q.jsx)(`button`,{disabled:z,onClick:()=>{X()},className:`rounded px-2 py-1 hover:bg-muted disabled:opacity-50`,children:s(`reader.refresh`,{defaultValue:`Refresh source`})})]})]}),M&&(0,Q.jsxs)(`div`,{role:`alert`,className:`border-b border-border px-4 py-2 text-xs`,children:[s(`reader.sourceFailed`,{defaultValue:`Could not refresh the current file. Any displayed source is the last successful read.`}),(0,Q.jsx)(`button`,{className:`ml-2 underline`,onClick:()=>{X()},children:s(`reader.retry`,{defaultValue:`Retry`})})]}),(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-hidden`,children:L===`recorded`&&I?(0,Q.jsx)(`div`,{className:`h-full overflow-auto p-3`,children:(0,Q.jsx)(Xe,{path:e,jobId:I})}):Ee?(0,Q.jsx)(`div`,{className:`h-full flex items-center justify-center text-sm text-muted-foreground`,"data-testid":`file-missing`,children:s(`viewer.missingFile`)}):O?.binary?(0,Q.jsx)(`div`,{className:`h-full flex items-center justify-center text-sm text-muted-foreground`,"data-testid":`file-binary`,children:s(`viewer.binaryFile`)}):O?.tooLarge?(0,Q.jsx)(`div`,{className:`h-full flex items-center justify-center text-sm text-muted-foreground`,"data-testid":`file-too-large`,children:s(`viewer.tooLarge`,{size:Math.round((O.sizeBytes??0)/1024/1024)})}):O?.content===void 0?(0,Q.jsx)(`div`,{className:`h-full flex items-center justify-center text-sm text-muted-foreground`,children:s(`viewer.noContent`)}):ye&&be===`preview`?(0,Q.jsx)(`div`,{className:`h-full overflow-auto px-6 py-4 prose prose-invert prose-sm max-w-none prose-p:my-2 prose-headings:mt-4 prose-headings:mb-2 prose-pre:bg-muted/40 prose-pre:rounded-md prose-code:before:content-none prose-code:after:content-none`,"data-testid":`markdown-preview`,children:(0,Q.jsx)(qe,{content:O.content})}):(0,Q.jsx)(We,{content:O.content,language:O.language??`plaintext`,initialLine:t})}),we.length>0&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{role:`separator`,"aria-orientation":`horizontal`,"aria-label":s(`history.resize`),onPointerDown:K?void 0:fe,onDoubleClick:K?void 0:pe,className:K?`flex h-8 shrink-0 items-center justify-between border-t border-border bg-card/35 px-4`:`flex h-8 shrink-0 cursor-row-resize items-center justify-between border-y border-border/40 bg-card/35 px-4 hover:bg-accent-primary/10`,title:K?void 0:s(`resizer.hint`),"data-testid":`code-history-resizer`,children:[(0,Q.jsx)(`span`,{className:`text-[11px] font-medium uppercase tracking-wider text-muted-foreground`,children:s(q===`story`?`story.title`:`history.title`,{count:we.length})}),(0,Q.jsxs)(`span`,{className:`flex items-center gap-1`,children:[!K&&(0,Q.jsxs)(`span`,{className:`flex items-center gap-0.5 rounded-md bg-muted/40 p-0.5`,role:`group`,"aria-label":s(`story.viewMode`),onPointerDown:e=>e.stopPropagation(),children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>he(`story`),"aria-pressed":q===`story`,className:q===`story`?`rounded px-2 py-0.5 text-[10px] bg-accent-primary/20 text-accent-primary`:`rounded px-2 py-0.5 text-[10px] text-muted-foreground hover:text-foreground`,children:s(`story.modeStory`)}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>he(`log`),"aria-pressed":q===`log`,className:q===`log`?`rounded px-2 py-0.5 text-[10px] bg-accent-primary/20 text-accent-primary`:`rounded px-2 py-0.5 text-[10px] text-muted-foreground hover:text-foreground`,children:s(`story.modeLog`)})]}),(0,Q.jsxs)(`button`,{type:`button`,onPointerDown:e=>e.stopPropagation(),onClick:Y,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[11px] text-muted-foreground hover:bg-muted/50 hover:text-foreground`,children:[K?(0,Q.jsx)(C,{className:`h-3.5 w-3.5`}):(0,Q.jsx)(re,{className:`h-3.5 w-3.5`}),s(K?`history.show`:`history.hide`)]})]})]}),!K&&(q===`story`?(0,Q.jsx)(et,{relPath:e,height:W,onOpenTicket:x,onFilterJob:i,onViewDiff:ne}):(0,Q.jsx)(St,{rows:we,onOpenTicket:x,onFilterJob:i,height:W}))]}),ae&&(0,ce.createPortal)((0,Q.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50`,role:`dialog`,"aria-modal":`true`,"data-testid":`budget-prompt`,onClick:E.guardBackdrop(()=>oe(!1)),children:[(0,Q.jsxs)(`div`,{ref:E.panelRef,onClick:e=>e.stopPropagation(),className:`bg-card border border-border rounded-lg p-4 w-80 flex flex-col gap-3`,style:E.panelStyle,children:[(0,Q.jsx)(`p`,{className:`text-sm text-foreground`,children:s(`viewer.budgetPrompt`)}),(0,Q.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>oe(!1),className:`text-xs px-3 py-1.5 rounded-md text-muted-foreground hover:text-foreground`,children:s(`common:actions.cancel`)}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{oe(!1),_e(!0)},className:`text-xs px-3 py-1.5 rounded-md bg-accent-primary text-white`,children:s(`common:actions.confirm`)})]})]}),(0,Q.jsx)(A,{handles:E.resizeHandles})]}),document.body)]})}function St({rows:e,onOpenTicket:t,onFilterJob:n,height:r}){let{t:i}=m(`code`),[a,o]=(0,H.useState)(null);if(e.length===0)return null;function u(e,t){o(e=>e===t?null:t)}return(0,Q.jsx)(`div`,{className:`shrink-0 border-t border-border bg-card/40 px-4 py-3 overflow-hidden`,style:{height:r},"data-testid":`file-provenance-timeline`,children:(0,Q.jsx)(`div`,{className:`h-full overflow-auto space-y-1`,children:e.map((e,r)=>{let o=e.kind===`created`?s:e.kind===`deleted`?c:w,d=e.jobId?e.jobId.length>12?e.jobId.slice(0,12):e.jobId:i(`history.unknownJob`),f=`${e.jobId??`job`}:${e.path}:${e.at}:${r}`;return(0,Q.jsxs)(`div`,{className:`rounded-md hover:bg-muted/40`,children:[(0,Q.jsxs)(`div`,{className:`grid grid-cols-[minmax(72px,auto)_minmax(0,1fr)_auto] items-center gap-2 text-xs px-2 py-1.5`,children:[(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 min-w-0`,children:[(0,Q.jsx)(o,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}),(0,Q.jsx)(`span`,{className:`capitalize`,children:i(`kind.${e.kind}`)})]}),(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 min-w-0 text-muted-foreground`,children:[(0,Q.jsx)(l,{className:`h-3.5 w-3.5 shrink-0`}),e.jobId&&n?(0,Q.jsx)(`button`,{type:`button`,onClick:()=>n(e.jobId),className:`font-mono truncate hover:text-foreground`,title:i(`history.filterByJob`,{jobId:e.jobId}),children:d}):(0,Q.jsx)(`span`,{className:`font-mono truncate`,title:e.jobId??void 0,children:d}),e.jobId&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>u(e,f),className:`shrink-0 rounded bg-muted/60 px-1.5 py-0.5 text-[10px] text-muted-foreground hover:bg-muted hover:text-foreground`,children:i(`history.diff`)}),typeof e.ticketId==`number`&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>t(e.ticketId),className:`shrink-0 rounded bg-accent-primary/15 px-1.5 py-0.5 text-[10px] text-accent-primary hover:bg-accent-primary/25`,title:i(`history.openSpec`,{ticketId:e.ticketId}),children:i(`history.specChip`,{ticketId:e.ticketId})})]}),(0,Q.jsx)(`time`,{className:`text-[11px] text-muted-foreground`,dateTime:new Date(e.at).toISOString(),children:new Date(e.at).toLocaleString()})]}),a===f&&(0,Q.jsx)(`div`,{className:`px-2 pb-2`,children:e.jobId&&(0,Q.jsx)(Xe,{path:e.path,jobId:e.jobId})})]},f)})})})}function Ct({projectId:e,repositoryName:t,multipleRepositories:n,active:r=!0,onOpen:i}){let{t:a}=m(`code`),{apiBase:o,repositoryId:s,repositoryPath:c}=Z(),[l,u]=(0,H.useState)(``),[d,f]=(0,H.useState)(`find`),[p,h]=(0,H.useState)(n),[g,_]=(0,H.useState)(!1),[v,y]=(0,H.useState)(``),[b,x]=(0,H.useState)(null),[S,C]=(0,H.useState)(!1),[w,D]=(0,H.useState)(!1),[O,k]=(0,H.useState)(0),A=n&&p,j=A?P(e):o,M=A?void 0:s,N=A?void 0:t,ee=A?void 0:c,F=(0,H.useRef)(0),I=(0,H.useRef)(null);return(0,H.useEffect)(()=>{r&&I.current?.focus()},[r]),(0,H.useEffect)(()=>{let e=++F.current,t=new AbortController;x(null),D(!1);let n=l.trim();if(!n)return C(!1),()=>t.abort();C(!0);let r=setTimeout(async()=>{try{let r=new URLSearchParams({q:n,limit:d===`find`?`50`:`100`});d===`search`&&r.set(`caseSensitive`,String(g)),d===`search`&&v.trim()&&r.set(`path`,v.trim()),A&&r.set(`kind`,d);let i=await fetch(`${j}/code/${A?`discover`:d}?${r}`,{signal:t.signal});if(!i.ok)throw Error(`search_failed`);let a=await i.json();if(!Array.isArray(a.matches))throw Error(`invalid_search_response`);!t.signal.aborted&&e===F.current&&x({...a,matches:a.matches.map(e=>({...e,repositoryId:e.repositoryId??M,repositoryName:e.repositoryName??N}))})}catch{!t.signal.aborted&&e===F.current&&D(!0)}finally{!t.signal.aborted&&e===F.current&&C(!1)}},250);return()=>{clearTimeout(r),t.abort()}},[l,d,g,v,O,A,j,M,N,ee]),(0,Q.jsxs)(`section`,{className:`flex min-h-0 flex-1 flex-col`,"aria-label":a(`explore.search`),children:[(0,Q.jsxs)(`div`,{className:`space-y-2 border-b border-border p-3`,children:[(0,Q.jsx)(`div`,{className:`flex gap-1 rounded-lg bg-muted/40 p-1`,children:[`find`,`search`].map(e=>(0,Q.jsx)(`button`,{type:`button`,"aria-pressed":d===e,onClick:()=>f(e),className:`flex-1 rounded-md px-2 py-1.5 text-xs ${d===e?`bg-background text-foreground shadow-sm`:`text-muted-foreground hover:text-foreground`}`,children:a(`search.${e}`)},e))}),(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsx)(E,{className:`pointer-events-none absolute left-2.5 top-2.5 h-3.5 w-3.5 text-muted-foreground`}),(0,Q.jsx)(`input`,{ref:I,value:l,onChange:e=>u(e.target.value),maxLength:256,"aria-label":a(`search.query`),placeholder:a(d===`find`?`search.filePlaceholder`:`search.contentPlaceholder`),className:`h-9 w-full rounded-md border border-border bg-background pl-8 pr-2 text-xs outline-none focus:border-accent-primary`})]}),n&&(0,Q.jsxs)(`select`,{"aria-label":a(`search.scope`),value:p?`all`:`current`,onChange:e=>h(e.target.value===`all`),className:`w-full rounded-md border border-border bg-background px-2 py-1.5 text-xs`,children:[(0,Q.jsx)(`option`,{value:`all`,children:a(`search.allRepositories`)}),(0,Q.jsx)(`option`,{value:`current`,children:t??a(`search.currentRepository`)})]}),d===`search`&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`input`,{value:v,onChange:e=>y(e.target.value),placeholder:a(`search.pathPlaceholder`),"aria-label":a(`search.withinPath`),className:`w-full rounded-md border border-border bg-background px-2 py-1.5 text-xs outline-none focus:border-accent-primary`}),(0,Q.jsxs)(`label`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:g,onChange:e=>_(e.target.checked)}),a(`search.caseSensitive`)]})]})]}),(0,Q.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-auto`,"aria-busy":S,children:[!l.trim()&&(0,Q.jsxs)(`div`,{className:`space-y-2 px-5 py-8 text-center text-xs text-muted-foreground`,children:[(0,Q.jsx)(B,{className:`mx-auto h-7 w-7 opacity-50`}),(0,Q.jsx)(`p`,{children:a(`search.hint`)})]}),S&&(0,Q.jsxs)(`p`,{role:`status`,className:`flex items-center gap-2 p-4 text-xs text-muted-foreground`,children:[(0,Q.jsx)(T,{className:`h-3.5 w-3.5 animate-spin`}),a(`search.loading`)]}),w&&(0,Q.jsxs)(`div`,{role:`alert`,className:`space-y-2 p-4 text-xs`,children:[(0,Q.jsx)(`p`,{children:a(`search.failed`)}),(0,Q.jsx)(`button`,{type:`button`,className:`text-accent-primary underline`,onClick:()=>k(e=>e+1),children:a(`explore.retry`)})]}),b&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{role:`status`,className:`space-y-1 border-b border-border/50 px-3 py-2 text-[11px] text-muted-foreground`,children:[(0,Q.jsx)(`p`,{children:a(`search.results`,{count:b.matches.length})}),b.truncated&&(0,Q.jsx)(`p`,{className:`text-amber-600 dark:text-amber-400`,children:a(`search.partial`)}),b.repositories?.filter(e=>![`ok`,`partial`].includes(e.status)).map(e=>(0,Q.jsx)(`p`,{children:a(`search.repositoryIncomplete`,{name:e.repositoryName})},e.repositoryId))]}),b.matches.length===0&&(0,Q.jsx)(`p`,{className:`p-4 text-xs text-muted-foreground`,children:a(b.truncated?`search.noMatchesPartial`:`search.noMatches`)}),(0,Q.jsx)(`ul`,{className:`divide-y divide-border/40`,children:b.matches.map((e,t)=>(0,Q.jsx)(`li`,{children:(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>i({repositoryId:e.repositoryId,path:e.path,line:e.lineNumber}),className:`w-full space-y-1 px-3 py-3 text-left hover:bg-muted/50 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-accent-primary`,title:`${e.repositoryName??``} / ${e.path}`,children:[n&&(0,Q.jsx)(`span`,{className:`block text-[10px] font-medium text-accent-primary`,children:e.repositoryName}),(0,Q.jsxs)(`span`,{className:`block break-all font-mono text-xs text-foreground`,children:[e.path,e.lineNumber?(0,Q.jsxs)(`span`,{className:`text-accent-primary`,children:[`:`,e.lineNumber]}):null]}),e.snippet!==void 0&&(0,Q.jsxs)(`span`,{className:`block overflow-hidden text-ellipsis whitespace-pre font-mono text-[11px] text-muted-foreground`,children:[e.snippetTruncated?`… `:``,e.snippet]})]})},`${e.repositoryId}:${e.path}:${e.lineNumber??0}:${t}`))})]})]})]})}function wt({projectId:e,repositoryName:t,multipleRepositories:n,jobId:r,ticketId:i,onOpen:a}){let{t:o,i18n:u}=m(`code`),{repositoryId:d,repositoryPath:f}=Z(),{registerHandler:h,unregisterHandler:g}=p(),[_,v]=(0,H.useState)(n),[y,b]=(0,H.useState)(null),[x,S]=(0,H.useState)(!1),[C,E]=(0,H.useState)(!1),D=(0,H.useRef)(0),O=(0,H.useRef)(null),k=(0,H.useId)(),A=JSON.stringify([e,d,f,_,r,i]),j=(0,H.useRef)(A);j.current=A;let M=y?.scope===A?y:null,N=(0,H.useCallback)(async t=>{let n=++D.current;O.current?.abort();let a=new AbortController;O.current=a,S(!0),E(!1),t||b(null);try{let o=new URLSearchParams({limit:`50`});!_&&d&&o.set(`repositoryId`,d),r&&o.set(`jobId`,r),i&&o.set(`ticketId`,String(i)),t&&o.set(`cursor`,t);let s=await fetch(`${P(e)}/code/activity?${o}`,{signal:a.signal});if(!s.ok)throw Error(`activity_failed`);let c=await s.json();if(!Array.isArray(c.entries)||t&&c.nextCursor===t)throw Error(`invalid_activity_page`);if(a.signal.aborted||n!==D.current||j.current!==A)return;b(e=>{let n=t&&e?.scope===A?[...e.entries,...c.entries]:c.entries,r=[...new Map(n.map(e=>[e.id,e])).values()],i=r.length>1e3||r.length===1e3&&c.nextCursor!==null;return{...c,scope:A,entries:r.slice(0,1e3),nextCursor:i?null:c.nextCursor,truncated:c.truncated||i||!!t&&e?.scope===A&&e.truncated}})}catch{!a.signal.aborted&&n===D.current&&j.current===A&&E(!0)}finally{!a.signal.aborted&&n===D.current&&j.current===A&&S(!1)}},[e,d,f,_,r,i,A]);return(0,H.useEffect)(()=>(N(),()=>{D.current++,O.current?.abort()}),[N]),(0,H.useEffect)(()=>{let t=`code-activity-${e}-${k}`,n;return h(t,t=>{let r=t;r.type!==`file.provenance_updated`||r.projectId!==e||(clearTimeout(n),n=setTimeout(()=>{N()},250))}),()=>{clearTimeout(n),g(t)}},[N,e,k,h,g]),(0,Q.jsxs)(`section`,{className:`flex min-h-0 flex-1 flex-col`,"aria-label":o(`explore.activity`),children:[(0,Q.jsxs)(`div`,{className:`space-y-2 border-b border-border p-3`,children:[(0,Q.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,Q.jsx)(`p`,{className:`text-xs leading-relaxed text-muted-foreground`,children:o(`activity.description`)}),(0,Q.jsx)(`button`,{type:`button`,disabled:x,onClick:()=>{N()},"aria-label":o(`explore.refresh`),title:o(`explore.refresh`),className:`rounded p-1 text-muted-foreground hover:bg-muted disabled:opacity-40`,children:(0,Q.jsx)(ne,{className:`h-3.5 w-3.5 ${x?`animate-spin`:``}`})})]}),n&&(0,Q.jsxs)(`select`,{"aria-label":o(`activity.scope`),value:_?`all`:`current`,onChange:e=>v(e.target.value===`all`),className:`w-full rounded-md border border-border bg-background px-2 py-1.5 text-xs`,children:[(0,Q.jsx)(`option`,{value:`all`,children:o(`search.allRepositories`)}),(0,Q.jsx)(`option`,{value:`current`,children:t??o(`search.currentRepository`)})]}),(i||r)&&(0,Q.jsx)(`p`,{className:`break-all text-[11px] text-accent-primary`,children:i?o(`provenancePanel.specTitle`,{ticketId:i}):o(`provenancePanel.jobTitle`,{jobId:r})})]}),(0,Q.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-auto`,"aria-busy":x,children:[C&&(0,Q.jsxs)(`div`,{role:`alert`,className:`space-y-2 p-3 text-xs`,children:[(0,Q.jsx)(`p`,{children:o(`activity.failed`)}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{N(M?.nextCursor??void 0)},className:`text-accent-primary underline`,children:o(`explore.retry`)})]}),M?.truncated&&(0,Q.jsx)(`p`,{role:`status`,className:`border-b border-border p-3 text-xs text-amber-600 dark:text-amber-400`,children:o(`activity.partial`)}),M&&M.entries.length===0&&!M.truncated&&!M.nextCursor&&!x&&(0,Q.jsxs)(`div`,{className:`space-y-2 p-6 text-center text-xs text-muted-foreground`,children:[(0,Q.jsx)(I,{className:`mx-auto h-6 w-6 opacity-50`}),(0,Q.jsx)(`p`,{children:o(`activity.empty`)})]}),(0,Q.jsx)(`ol`,{children:M?.entries.map((e,t)=>{let n=M.entries[t-1],r=!n||n.repositoryId!==e.repositoryId||n.jobId!==e.jobId||n.ticketId!==e.ticketId,i=e.kind===`created`?s:e.kind===`deleted`?c:w;return(0,Q.jsxs)(`li`,{children:[r&&(0,Q.jsxs)(`div`,{className:`sticky top-0 z-[1] space-y-1 border-y border-border bg-background/95 px-3 py-2 backdrop-blur`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px]`,children:[(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-medium`,children:e.repositoryName}),e.ticketId!=null&&(0,Q.jsx)(`span`,{className:`rounded bg-accent-primary/10 px-1.5 py-0.5 text-accent-primary`,children:o(`story.spec`,{ticketId:e.ticketId})})]}),(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-2 text-[10px] text-muted-foreground`,children:[(0,Q.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-1`,title:e.jobId??void 0,children:[(0,Q.jsx)(l,{className:`h-3 w-3`}),e.jobId?.slice(0,10)??o(`history.unknownJob`)]}),(0,Q.jsx)(`time`,{dateTime:new Date(e.at).toISOString(),title:new Date(e.at).toLocaleString(u.language),children:new Date(e.at).toLocaleDateString(u.language,{month:`short`,day:`numeric`})})]})]}),(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>a({repositoryId:e.repositoryId,path:e.path,changeJobId:e.jobId}),className:`flex w-full items-start gap-2 border-b border-border/30 px-3 py-3 text-left hover:bg-muted/50`,title:e.path,children:[(0,Q.jsx)(i,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 ${e.kind===`created`?`text-accent-success`:e.kind===`deleted`?`text-destructive`:`text-accent-info`}`}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1 space-y-1`,children:[(0,Q.jsx)(`span`,{className:`block break-all font-mono text-xs`,children:e.path}),(0,Q.jsxs)(`span`,{className:`block text-[10px] text-muted-foreground`,children:[o(`story.kindLabel.${e.kind}`),` · `,o(e.hasPatch?e.patchTruncated?`activity.partialPatch`:`activity.patch`:`activity.noPatch`)]})]})]})]},e.id)})}),x&&(0,Q.jsxs)(`p`,{role:`status`,className:`flex items-center gap-2 p-4 text-xs text-muted-foreground`,children:[(0,Q.jsx)(T,{className:`h-3.5 w-3.5 animate-spin`}),o(`activity.loading`)]}),M?.nextCursor&&!x&&!C&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{N(M.nextCursor)},className:`m-3 rounded-md border border-border px-3 py-1.5 text-xs hover:bg-muted/50`,children:o(`activity.loadMore`)})]})]})}function Tt(e){if(!e||!/^\d+$/.test(e))return;let t=Number(e);return Number.isSafeInteger(t)&&t>0?t:void 0}var Et=320,Dt=240,Ot=420,kt=760,At=e=>`specrails-desktop:code-tree-width:${e}`;function jt(e){try{let t=Number(localStorage.getItem(At(e)));return t>0&&Number.isFinite(t)?t:Et}catch{return Et}}function Mt(e,t){if(e)try{localStorage.setItem(At(e),String(Math.round(t)))}catch{}}function Nt(e,t){return Math.min(Math.max(e,Dt),Math.max(Dt,t-Ot))}function Pt(e={}){let{activeProjectId:t}=v();return(0,Q.jsx)(Ft,{...e},t??`no-project`)}function Ft({embedded:e=!1,initialPath:t=null,initialRepositoryId:n,onRepositoryChange:r,onSelectedPathChange:i}){let{t:s}=m(`code`),{t:c}=m(`common`),{activeProjectId:l,projects:d}=v(),[f,p]=a(),h=o(),_=d?.find(e=>e.id===l),y=(0,H.useMemo)(()=>ee(_),[_]),[b,S]=(0,H.useState)(()=>({entries:[{repositoryId:n??void 0,path:t}],index:0})),C=e?b.entries[b.index]:{repositoryId:f.get(`repositoryId`)??void 0,path:f.get(`path`),line:Tt(f.get(`line`)),changeJobId:f.get(`changeJobId`)},T=C.repositoryId?y.find(e=>e.id===C.repositoryId):y.find(e=>e.isPrimary),D=!!C.repositoryId&&!!_&&!T,O=(0,H.useMemo)(()=>({apiBase:l?P(l,T?.id):g(),repositoryId:T?.id,repositoryPath:T?.path,isPrimary:T?.isPrimary}),[l,T?.id,T?.path,T?.isPrimary]),k=JSON.stringify([l,T?.id,T?.path]),[A,j]=(0,H.useState)(`files`),[M,N]=(0,H.useState)(!0),[F,te]=(0,H.useState)(e),[R,ne]=(0,H.useState)(()=>jt(l)),[z,re]=(0,H.useState)(null),[B,ae]=(0,H.useState)(null),[ce,U]=(0,H.useState)({}),W=e?ce.jobId??null:f.get(`jobId`),G=e?ce.ticketId??null:Tt(f.get(`ticketId`))??null,[K,le]=(0,H.useState)(G?String(G):``),q=(0,H.useRef)(null),ue=(0,H.useRef)(null);(0,H.useEffect)(()=>{le(G?String(G):``)},[G]),(0,H.useEffect)(()=>{let e=q.current;if(!e)return;let t=e=>{e&&(te(e<kt),ne(t=>Nt(t,e)))};if(t(e.clientWidth),typeof ResizeObserver>`u`)return;let n=new ResizeObserver(e=>t(e[0]?.contentRect.width??0));return n.observe(e),()=>n.disconnect()},[]),(0,H.useEffect)(()=>()=>ue.current?.(),[]),(0,H.useEffect)(()=>{F&&C.path&&N(!1)},[F,C.path]);let J=(0,H.useCallback)(t=>{let n={...t,repositoryId:t.repositoryId??T?.id},a=n.repositoryId!==T?.id;if(e)S(e=>({entries:[...e.entries.slice(0,e.index+1),n],index:e.index+1})),a&&U({});else{let e=new URLSearchParams(f);for(let t of[`path`,`line`,`changeJobId`])e.delete(t);n.repositoryId&&e.set(`repositoryId`,n.repositoryId),n.path&&e.set(`path`,n.path),n.line&&e.set(`line`,String(n.line)),n.changeJobId&&e.set(`changeJobId`,n.changeJobId),a&&(e.delete(`jobId`),e.delete(`ticketId`)),p(e)}i?.(n.path),n.repositoryId&&r?.(n.repositoryId),F&&n.path&&N(!1)},[e,T?.id,f,p,i,r,F]),de=t=>{if(!e){h(t);return}let n=b.index+t,a=b.entries[n];if(!a)return;let o=a.repositoryId??y.find(e=>e.isPrimary)?.id;o!==T?.id&&U({}),S({...b,index:n}),i?.(a.path),o&&r?.(o)},fe=(0,H.useCallback)(t=>{if(e)U(t);else{let e=new URLSearchParams(f);e.delete(`jobId`),e.delete(`ticketId`),t.jobId&&e.set(`jobId`,t.jobId),t.ticketId&&e.set(`ticketId`,String(t.ticketId)),p(e)}},[e,f,p]),pe=(0,H.useCallback)(e=>{fe({jobId:e}),j(`activity`),N(!0)},[fe]),me=e=>{ue.current?.();let t=e.clientX,n=R,r=R,i=e=>{r=Nt(n+e.clientX-t,q.current?.clientWidth||window.innerWidth),ne(r)},a=()=>{window.removeEventListener(`pointermove`,i),window.removeEventListener(`pointerup`,a),window.removeEventListener(`pointercancel`,a),Mt(l,r),ue.current=null};ue.current=a,window.addEventListener(`pointermove`,i),window.addEventListener(`pointerup`,a),window.addEventListener(`pointercancel`,a)},Y=M||!C.path,he=!F||!Y,ge=C.path?.split(`/`)??[];return(0,Q.jsx)(we.Provider,{value:O,children:(0,Q.jsxs)(`div`,{ref:q,className:`flex h-full min-h-0 w-full min-w-0 flex-col overflow-hidden`,"data-testid":`code-page`,"data-compact":F,children:[(0,Q.jsxs)(`header`,{className:`flex shrink-0 flex-wrap items-center gap-2 border-b border-border bg-card/30 px-3 py-2`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,Q.jsx)(`button`,{type:`button`,"aria-label":s(`explore.back`),title:s(`explore.back`),onClick:()=>de(-1),disabled:e&&b.index===0,className:`rounded p-1.5 text-muted-foreground hover:bg-muted disabled:opacity-30`,children:(0,Q.jsx)(x,{className:`h-3.5 w-3.5`})}),(0,Q.jsx)(`button`,{type:`button`,"aria-label":s(`explore.forward`),title:s(`explore.forward`),onClick:()=>de(1),disabled:e&&b.index===b.entries.length-1,className:`rounded p-1.5 text-muted-foreground hover:bg-muted disabled:opacity-30`,children:(0,Q.jsx)(u,{className:`h-3.5 w-3.5`})}),C.path&&(0,Q.jsx)(`button`,{type:`button`,"aria-label":s(Y?`explore.hideNavigation`:`explore.showNavigation`),title:s(Y?`explore.hideNavigation`:`explore.showNavigation`),onClick:()=>N(!Y),className:`rounded p-1.5 text-muted-foreground hover:bg-muted`,children:Y?(0,Q.jsx)(oe,{className:`h-4 w-4`}):(0,Q.jsx)(se,{className:`h-4 w-4`})})]}),y.length>0&&(0,Q.jsxs)(`select`,{"aria-label":c(`repositories.select`),className:`max-w-full min-w-0 rounded-md border border-border bg-background px-2 py-1 text-xs`,value:T?.id??C.repositoryId??``,onChange:e=>J({repositoryId:e.target.value,path:null}),children:[D&&(0,Q.jsx)(`option`,{value:C.repositoryId,children:c(`repositories.unavailable`)}),y.map(e=>(0,Q.jsxs)(`option`,{value:e.id,children:[e.name,e.isPrimary?` · ${c(`repositories.primary`)}`:``]},e.id))]}),(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[11px] text-muted-foreground`,title:T?.path,children:T?.path})]}),D?(0,Q.jsx)(`p`,{role:`alert`,className:`p-4 text-sm text-destructive`,children:c(`repositories.invalidSelection`)}):(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1 overflow-hidden`,children:[(0,Q.jsxs)(`aside`,{hidden:!Y,className:`${Y?`flex`:`hidden`} min-h-0 min-w-0 shrink-0 flex-col overflow-hidden bg-card/15`,style:{width:F?`100%`:R},"aria-label":s(`explore.navigation`),children:[(0,Q.jsx)(`nav`,{className:`flex shrink-0 gap-0.5 border-b border-border px-2 pt-2`,"aria-label":s(`explore.views`),children:[{mode:`files`,Icon:ie},{mode:`search`,Icon:E},{mode:`activity`,Icon:I}].map(({mode:e,Icon:t})=>(0,Q.jsxs)(`button`,{type:`button`,"aria-pressed":A===e,onClick:()=>j(e),className:`flex min-w-0 flex-1 items-center justify-center gap-1.5 border-b-2 px-1 py-2 text-xs ${A===e?`border-accent-primary text-accent-primary`:`border-transparent text-muted-foreground hover:text-foreground`}`,children:[(0,Q.jsx)(t,{className:`h-3.5 w-3.5 shrink-0`}),s(`explore.${e}`)]},e))}),(0,Q.jsx)(`div`,{className:A===`files`?`min-h-0 flex-1`:`hidden`,children:(0,Q.jsx)(Ne,{selectedPath:C.path,onOpenFile:e=>J({path:e}),filterJobId:W,filterTicketId:G},k)}),l&&(0,Q.jsx)(`div`,{className:A===`search`?`flex min-h-0 flex-1 flex-col`:`hidden`,children:(0,Q.jsx)(Ct,{active:A===`search`&&Y,projectId:l,repositoryName:T?.name,multipleRepositories:y.length>1,onOpen:J})}),A===`activity`&&l&&(0,Q.jsx)(wt,{projectId:l,repositoryName:T?.name,multipleRepositories:y.length>1,jobId:W,ticketId:G,onOpen:J})]}),Y&&!F&&(0,Q.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-label":s(`page.resizeFileTree`),onPointerDown:me,onDoubleClick:()=>{let e=Nt(Et,q.current?.clientWidth||window.innerWidth);ne(e),Mt(l,e)},className:`w-1.5 shrink-0 cursor-col-resize touch-none select-none border-x border-border/40 hover:bg-accent-primary/20`,title:s(`resizer.hint`),"data-testid":`code-tree-resizer`}),(0,Q.jsxs)(`main`,{hidden:!he,className:`${he?`flex`:`hidden`} min-h-0 min-w-0 flex-1 flex-col overflow-hidden`,children:[C.path&&(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1 overflow-x-auto border-b border-border/60 px-3 py-2 text-[11px]`,"aria-label":s(`explore.breadcrumb`),children:[(0,Q.jsx)(w,{className:`mr-1 h-3.5 w-3.5 shrink-0 text-muted-foreground`}),ge.map((e,t)=>(0,Q.jsxs)(`span`,{className:`flex shrink-0 items-center gap-1 ${t===ge.length-1?`font-medium text-foreground`:`text-muted-foreground`}`,children:[t>0&&(0,Q.jsx)(L,{className:`h-3 w-3`}),e]},t)),C.line&&(0,Q.jsxs)(`span`,{className:`ml-1 shrink-0 text-accent-primary`,children:[`:`,C.line]})]}),(0,Q.jsx)(It,{jobId:W,ticketId:G,ticketInput:K,onTicketInputChange:le,onApplyTicket:e=>fe({ticketId:Tt(e.trim())}),onClear:()=>fe({}),summaryAction:C.path?z:null,copyPathAction:C.path?B:null}),(W||G)&&(0,Q.jsx)(Lt,{jobId:W,ticketId:G,onOpenFile:e=>J({path:e,changeJobId:W})},`${k}:${W}:${G}`),C.path?(0,Q.jsx)(bt,{compact:F,relPath:C.path,initialLine:C.line,initialJobId:C.changeJobId,onFilterJob:pe,onSummaryActionChange:re,onCopyPathActionChange:ae},`${k}:${C.path}`):(0,Q.jsx)(`div`,{className:`flex min-h-0 flex-1 items-center justify-center overflow-auto p-6`,children:(0,Q.jsxs)(`div`,{className:`max-w-sm space-y-4 text-center`,children:[(0,Q.jsx)(`div`,{className:`mx-auto flex h-14 w-14 items-center justify-center rounded-2xl border border-accent-primary/20 bg-accent-primary/10 text-accent-primary`,children:(0,Q.jsx)(V,{className:`h-7 w-7`})}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h1`,{className:`text-lg font-semibold`,children:s(`explore.welcome`)}),(0,Q.jsx)(`p`,{className:`mt-2 text-sm leading-relaxed text-muted-foreground`,children:s(`explore.description`)})]}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap justify-center gap-2`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{j(`search`),N(!0)},className:`rounded-lg bg-accent-primary/15 px-3 py-2 text-xs text-accent-primary`,children:s(`explore.findCode`)}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{j(`activity`),N(!0)},className:`rounded-lg border border-border px-3 py-2 text-xs text-muted-foreground hover:text-foreground`,children:s(`explore.viewActivity`)})]}),(0,Q.jsx)(`p`,{className:`text-[11px] leading-relaxed text-muted-foreground/80`,children:s(`explore.sourceHint`)})]})})]})]})]})})}function It({jobId:e,ticketId:t,ticketInput:n,onTicketInputChange:r,onApplyTicket:i,onClear:a,summaryAction:o,copyPathAction:s}){let{t:c}=m(`code`),l=t?`spec`:e?`job-context`:`all`;return(0,Q.jsx)(`div`,{className:`border-b border-border bg-background/80 px-4 py-2`,"data-testid":`code-provenance-toolbar`,children:(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-xs font-medium text-muted-foreground`,children:[(0,Q.jsx)(ae,{className:`h-3.5 w-3.5`}),c(`toolbar.scope`)]}),(0,Q.jsx)(`button`,{type:`button`,onClick:a,"aria-pressed":l===`all`,className:l===`all`?`rounded-md bg-accent-primary/20 px-2 py-1 text-xs text-accent-primary`:`rounded-md px-2 py-1 text-xs text-muted-foreground hover:bg-muted/50 hover:text-foreground`,children:c(`toolbar.allAi`)}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-1 rounded-md border border-border/70 bg-card/40 px-1 py-1`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>i(n),"aria-pressed":l===`spec`,className:l===`spec`?`rounded bg-accent-success/20 px-2 py-0.5 text-xs text-accent-success`:`rounded px-2 py-0.5 text-xs text-muted-foreground hover:bg-muted/50 hover:text-foreground`,children:c(`toolbar.spec`)}),(0,Q.jsx)(`input`,{value:n,onChange:e=>r(e.target.value),onKeyDown:e=>{e.key===`Enter`&&i(n)},placeholder:c(`toolbar.ticketIdPlaceholder`),inputMode:`numeric`,className:`h-6 w-20 bg-transparent px-1 font-mono text-xs outline-none placeholder:text-muted-foreground/60`})]}),(0,Q.jsx)(`div`,{className:`flex-1`}),s&&(0,Q.jsx)(`button`,{type:`button`,onClick:s.onClick,className:`inline-flex items-center gap-1.5 rounded-md px-2.5 py-1 text-xs text-muted-foreground hover:bg-muted/50 hover:text-foreground`,children:c(`toolbar.copyFilePath`)}),o&&(0,Q.jsxs)(`button`,{type:`button`,onClick:o.onClick,disabled:o.regenerating||!!o.disabledReason,"aria-label":o.hasSummary?c(`toolbar.regenerateSummary`):c(`toolbar.generateSummary`),className:`inline-flex items-center gap-1.5 rounded-md bg-accent-primary/15 px-2.5 py-1 text-xs text-accent-primary hover:bg-accent-primary/25 disabled:opacity-50`,title:o.disabledReason?c(`toolbar.summaryUnavailable`,{reason:o.disabledReason}):void 0,children:[(0,Q.jsx)(f,{className:o.regenerating?`h-3.5 w-3.5 animate-spin`:`h-3.5 w-3.5`}),o.hasSummary?o.regenerating?c(`toolbar.regenerating`):c(`toolbar.regenerateSummary`):o.regenerating?c(`toolbar.generating`):c(`toolbar.generateSummary`)]}),l===`job-context`&&(0,Q.jsx)(`span`,{className:`rounded-md bg-accent-info/15 px-2 py-1 text-xs text-accent-info`,children:c(`toolbar.jobContext`)}),(e||t)&&(0,Q.jsxs)(`button`,{type:`button`,onClick:a,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-xs text-muted-foreground hover:bg-muted/50 hover:text-foreground`,children:[(0,Q.jsx)(O,{className:`h-3.5 w-3.5`}),c(`toolbar.clear`)]})]})})}function Lt({jobId:e,ticketId:t,onOpenFile:n}){let{t:r}=m(`code`),{apiBase:i}=Z(),[a,o]=(0,H.useState)(null),[s,c]=(0,H.useState)(!1),[l,u]=(0,H.useState)(!1),[d,f]=(0,H.useState)(0);(0,H.useEffect)(()=>{let n=new AbortController;o(null),c(!1),u(!1);let r=new URLSearchParams({limit:`100`});return e&&r.set(`jobId`,e),t&&r.set(`ticketId`,String(t)),fetch(`${i}/code/activity?${r}`,{signal:n.signal}).then(async e=>{if(!e.ok)throw Error(`activity_failed`);return e.json()}).then(e=>{if(n.signal.aborted)return;if(!Array.isArray(e.entries))throw Error(`invalid_activity_response`);let t=new Map;for(let n of e.entries)t.has(n.path)||t.set(n.path,n);o([...t.values()]),u(!!e.nextCursor||e.truncated===!0)}).catch(()=>{n.signal.aborted||c(!0)}),()=>n.abort()},[e,t,i,d]);let p=(0,H.useMemo)(()=>{let e=a??[];return{created:e.filter(e=>e.kind===`created`),modified:e.filter(e=>e.kind===`modified`),deleted:e.filter(e=>e.kind===`deleted`)}},[a]),h=a?.length??0,g=e?r(`provenancePanel.jobTitle`,{jobId:e}):r(`provenancePanel.specTitle`,{ticketId:t});return(0,Q.jsxs)(`section`,{className:`max-h-52 shrink-0 overflow-auto border-b border-border bg-card/35 px-4 py-3`,"data-testid":`provenance-result-panel`,children:[s&&(0,Q.jsxs)(`p`,{role:`alert`,className:`mb-2 text-xs`,children:[r(`activity.failed`),` `,(0,Q.jsx)(`button`,{type:`button`,className:`text-accent-primary underline`,onClick:()=>f(e=>e+1),children:r(`explore.retry`)})]}),!a&&!s&&(0,Q.jsx)(`p`,{role:`status`,className:`mb-2 text-xs text-muted-foreground`,children:r(`activity.loading`)}),l&&(0,Q.jsx)(`p`,{role:`status`,className:`mb-2 text-xs text-amber-600 dark:text-amber-400`,children:r(`activity.partial`)}),(0,Q.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`h2`,{className:`text-sm font-semibold truncate`,children:g}),(0,Q.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:a?r(`provenancePanel.touchedFiles`,{count:h}):`—`})]}),(0,Q.jsxs)(`div`,{className:`mt-2 flex flex-wrap gap-2`,children:[(0,Q.jsx)(Rt,{label:r(`action.added`),rows:p.created,icon:`created`,onOpenFile:n}),(0,Q.jsx)(Rt,{label:r(`action.changed`),rows:p.modified,icon:`modified`,onOpenFile:n}),(0,Q.jsx)(Rt,{label:r(`action.deleted`),rows:p.deleted,icon:`deleted`,onOpenFile:n})]})]}),(0,Q.jsx)(`div`,{className:`flex items-center gap-1 shrink-0`,children:e&&(0,Q.jsxs)(`a`,{href:`/jobs/${encodeURIComponent(e)}`,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-xs text-muted-foreground hover:bg-muted/50 hover:text-foreground`,children:[(0,Q.jsx)(S,{className:`h-3.5 w-3.5`}),r(`provenancePanel.log`)]})})]})]})}function Rt({label:e,rows:t,icon:n,onOpenFile:r}){return(0,Q.jsxs)(`details`,{className:`group min-w-[180px] max-w-[320px]`,children:[(0,Q.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center gap-1.5 rounded-md bg-muted/35 px-2 py-1 text-xs hover:bg-muted/55`,children:[(0,Q.jsx)(n===`created`?s:n===`deleted`?c:w,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,Q.jsx)(`span`,{children:e}),(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:t.length})]}),t.length>0&&(0,Q.jsx)(`div`,{className:`mt-1 max-h-28 overflow-auto rounded-md border border-border/60 bg-background/60 p-1`,children:t.map((e,t)=>(0,Q.jsx)(`button`,{type:`button`,onClick:()=>r(e.path),className:`block w-full truncate rounded px-1.5 py-1 text-left font-mono text-[11px] text-muted-foreground hover:bg-muted/50 hover:text-foreground`,title:e.path,children:e.path},`${e.path}-${e.jobId??`job`}-${e.at}-${t}`))})]})}export{Pt as default};
|
|
@@ -0,0 +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{m as r,r as i}from"./useSharedWebSocket-BN3Lmehi.js";import{n as a,t as o}from"./createLucideIcon-Bjbbp_KS.js";import{t as s}from"./clsx-CjueKrWZ.js";import{t as c}from"./utils-BC4DHlz2.js";import{$ as l,Yt as u,gt as d}from"./index-CjAPu3wb.js";import{$ as f,A as p,B as m,E as h,F as g,H as _,K as v,L as y,N as b,O as x,P as S,Q as C,R as w,S as T,T as ee,U as E,W as D,X as O,Y as te,Z as k,_ as ne,_t as A,a as re,c as ie,d as ae,dt as j,et as M,ft as oe,g as se,gt as ce,h as le,ht as ue,i as de,it as N,j as fe,k as pe,l as P,lt as F,mt as me,n as he,nt as I,o as ge,pt as L,q as R,r as z,rt as B,s as _e,t as ve,u as ye,ut as V,v as be,w as H,z as xe}from"./BarChart-nBOMNfiy.js";var Se=o(`trending-up`,[[`path`,{d:`M16 7h6v6`,key:`box55l`}],[`path`,{d:`m22 7-8.5 8.5-5-5L2 17`,key:`1t1m79`}]]),U=e(t());function W(){return W=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},W.apply(null,arguments)}var G=e=>{var{cx:t,cy:n,r,className:i}=e,a=s(`recharts-dot`,i);return j(t)&&j(n)&&j(r)?U.createElement(`circle`,W({},ce(e),N(e),{className:a,cx:t,cy:n,r})):null},Ce=[`points`];function K(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 q(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?K(Object(n),!0).forEach(function(t){we(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):K(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function we(e,t,n){return(t=Te(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Te(e){var t=Ee(e,`string`);return typeof t==`symbol`?t:t+``}function Ee(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function J(){return J=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},J.apply(null,arguments)}function De(e,t){if(e==null)return{};var n,r,i=Oe(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 Oe(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 ke(e){var{option:t,dotProps:n,className:r}=e;if((0,U.isValidElement)(t))return(0,U.cloneElement)(t,n);if(typeof t==`function`)return t(n);var i=s(r,typeof t==`boolean`?``:t.className),a=n??{},{points:o}=a,c=De(a,Ce);return U.createElement(G,J({},c,{className:i}))}function Ae(e,t){return e==null?!1:t?!0:e.length===1}function je(e){var{points:t,dot:n,className:r,dotClassName:i,dataKey:a,baseProps:o,needClip:s,clipPathId:c,zIndex:l=y.scatter}=e;if(!Ae(t,n))return null;var u=H(n),d=ue(n),f=t.map((e,r)=>{var s=q(q(q({r:3},o),d),{},{index:r,cx:e.x??void 0,cy:e.y??void 0,dataKey:a,value:e.value,payload:e.payload,points:t});return U.createElement(ke,{key:`dot-${r}`,option:n,dotProps:s,className:i})}),m={};return s&&c!=null&&(m.clipPath=`url(#clipPath-${u?``:`dots-`}${c})`),U.createElement(p,{zIndex:l},U.createElement(L,J({className:r},m),f))}function Me(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 Y(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?Me(Object(n),!0).forEach(function(t){Ne(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Me(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function Ne(e,t,n){return(t=Pe(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Pe(e){var t=Fe(e,`string`);return typeof t==`symbol`?t:t+``}function Fe(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 Ie=e=>{var{point:t,childIndex:n,mainColor:r,activeDot:i,dataKey:a,clipPath:o}=e;if(i===!1||t.x==null||t.y==null)return null;var s=Y(Y(Y({},{index:n,dataKey:a,cx:t.x,cy:t.y,r:4,fill:r??`none`,strokeWidth:2,stroke:`#fff`,payload:t.payload,value:t.value}),A(i)),N(i)),c=(0,U.isValidElement)(i)?(0,U.cloneElement)(i,s):typeof i==`function`?i(s):U.createElement(G,s);return U.createElement(L,{className:`recharts-active-dot`,clipPath:o},c)};function Le(e){var{points:t,mainColor:n,activeDot:r,itemDataKey:i,clipPath:a,zIndex:o=y.activeDot}=e,s=I(fe),c=ye();if(t==null||c==null)return null;var l=t.find(e=>c.includes(e.payload));return V(l)?null:U.createElement(p,{zIndex:o},U.createElement(Ie,{point:l,childIndex:Number(s),mainColor:n,dataKey:i,activeDot:r,clipPath:a}))}var Re=(e,t,n,r)=>b(e,`xAxis`,t,r),ze=(e,t,n,r)=>S(e,`xAxis`,t,r),Be=(e,t,n,r)=>b(e,`yAxis`,n,r),Ve=(e,t,n,r)=>S(e,`yAxis`,n,r),He=M([E,Re,Be,ze,Ve],(e,t,n,r,i)=>f(e,`xAxis`)?te(t,r,!1):te(n,i,!1)),Ue=(e,t,n,r,i)=>i;function We(e){return e.type===`line`}var Ge=M([E,Re,Be,ze,Ve,M([g,Ue],(e,t)=>e.filter(We).find(e=>e.id===t)),He,w],(e,t,n,r,i,a,o,s)=>{var{chartData:c,dataStartIndex:l,dataEndIndex:u}=s;if(!(a==null||t==null||n==null||r==null||i==null||r.length===0||i.length===0||o==null||e!==`horizontal`&&e!==`vertical`)){var{dataKey:d,data:f}=a,p=f!=null&&f.length>0?f:c?.slice(l,u+1);if(p!=null)return gt({layout:e,xAxis:t,yAxis:n,xAxisTicks:r,yAxisTicks:i,dataKey:d,bandSize:o,displayedData:p})}});function Ke(e){var t=A(e),n=3,r=2;if(t!=null){var{r:i,strokeWidth:a}=t,o=Number(i),s=Number(a);return(Number.isNaN(o)||o<0)&&(o=n),(Number.isNaN(s)||s<0)&&(s=r),{r:o,strokeWidth:s}}return{r:n,strokeWidth:r}}var qe=[`id`],Je=[`type`,`layout`,`connectNulls`,`needClip`,`shape`],Ye=[`activeDot`,`animateNewValues`,`animationBegin`,`animationDuration`,`animationEasing`,`connectNulls`,`dot`,`hide`,`isAnimationActive`,`label`,`legendType`,`xAxisId`,`yAxisId`,`id`];function X(){return X=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},X.apply(null,arguments)}function Xe(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 Z(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?Xe(Object(n),!0).forEach(function(t){Ze(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Xe(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function Ze(e,t,n){return(t=Qe(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Qe(e){var t=$e(e,`string`);return typeof t==`symbol`?t:t+``}function $e(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Q(e,t){if(e==null)return{};var n,r,i=et(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 et(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}var tt=e=>{var{dataKey:t,name:n,stroke:r,legendType:i,hide:a}=e;return[{inactive:a,dataKey:t,type:i,color:r,value:k(n,t),payload:e}]},nt=U.memo(e=>{var{dataKey:t,data:n,stroke:r,strokeWidth:i,fill:a,name:o,hide:s,unit:c,tooltipType:l,id:u}=e,d={dataDefinedOnItem:n,getPosition:oe,settings:{stroke:r,strokeWidth:i,fill:a,dataKey:t,nameKey:void 0,name:k(o,t),hide:s,type:l,color:r,unit:c,graphicalItemId:u}};return U.createElement(be,{tooltipEntrySettings:d})}),rt=(e,t)=>`${t}px ${e}px`;function it(e,t){for(var n=e.length%2==0?e:[...e,0],r=[],i=0;i<t;++i)r.push(...n);return r}var at=(e,t,n)=>{var r=n.reduce((e,t)=>e+t,0);if(!r)return rt(t,e);for(var i=Math.floor(e/r),a=e%r,o=[],s=0,c=0;s<n.length;c+=(l=n[s])??0,++s){var l,u=n[s];if(u!=null&&c+u>a){o=[...n.slice(0,s),a-c];break}}var d=o.length%2==0?[0,t]:[t];return[...it(n,i),...o,...d].map(e=>`${e}px`).join(`, `)};function ot(e){var{clipPathId:t,points:n,props:r}=e,{dot:i,dataKey:a,needClip:o}=r,{id:s}=r,c=ce(Q(r,qe));return U.createElement(je,{points:n,dot:i,className:`recharts-line-dots`,dotClassName:`recharts-line-dot`,dataKey:a,baseProps:c,needClip:o,clipPathId:t})}function st(e){var{showLabels:t,children:n,points:r}=e,i=(0,U.useMemo)(()=>r?.map(e=>{var t={x:e.x??0,y:e.y??0,width:0,lowerWidth:0,upperWidth:0,height:0};return Z(Z({},t),{},{value:e.value,payload:e.payload,viewBox:t,parentViewBox:void 0,fill:void 0})}),[r]);return U.createElement(ee,{value:t?i:void 0},n)}function ct(e){var{clipPathId:t,pathRef:n,points:r,strokeDasharray:i,props:a}=e,{type:o,layout:s,connectNulls:c,needClip:l,shape:u}=a,d=Z(Z({},me(Q(a,Je))),{},{fill:`none`,className:`recharts-line-curve`,clipPath:l?`url(#clipPath-${t})`:void 0,points:r,type:o,layout:s,connectNulls:c,strokeDasharray:i??a.strokeDasharray});return U.createElement(U.Fragment,null,r?.length>1&&U.createElement(T,X({shapeType:`curve`,option:u},d,{pathRef:n})),U.createElement(ot,{points:r,clipPathId:t,props:a}))}function lt(e){try{return e&&e.getTotalLength&&e.getTotalLength()||0}catch{return 0}}function ut(e){var{clipPathId:t,props:n,pathRef:r,previousPointsRef:i,longestAnimatedLengthRef:a}=e,{points:o,strokeDasharray:s,isAnimationActive:c,animationBegin:l,animationDuration:u,animationEasing:d,animateNewValues:f,width:p,height:g,onAnimationEnd:_,onAnimationStart:v}=n,y=i.current,b=xe(o,`recharts-line-`),x=(0,U.useRef)(b),[S,C]=(0,U.useState)(!1),w=!S,T=(0,U.useCallback)(()=>{typeof _==`function`&&_(),C(!1)},[_]),ee=(0,U.useCallback)(()=>{typeof v==`function`&&v(),C(!0)},[v]),E=lt(r.current),D=(0,U.useRef)(0);x.current!==b&&(D.current=a.current,x.current=b);var O=D.current;return U.createElement(st,{points:o,showLabels:w},n.children,U.createElement(m,{animationId:b,begin:l,duration:u,isActive:c,easing:d,onAnimationEnd:T,onAnimationStart:ee,key:b},e=>{var l=F(O,E+O,e),u=Math.min(l,E),d=c?s?at(u,E,`${s}`.split(/[,\s]+/gim).map(e=>parseFloat(e))):rt(E,u):s==null?void 0:String(s);if(e>0&&E>0&&(i.current=o,a.current=Math.max(a.current,u)),y){var m=y.length/o.length,h=e===1?o:o.map((t,n)=>{var r=Math.floor(n*m);if(y[r]){var i=y[r];return Z(Z({},t),{},{x:F(i.x,t.x,e),y:F(i.y,t.y,e)})}return f?Z(Z({},t),{},{x:F(p*2,t.x,e),y:F(g/2,t.y,e)}):Z(Z({},t),{},{x:t.x,y:t.y})});return i.current=h,U.createElement(ct,{props:n,points:h,clipPathId:t,pathRef:r,strokeDasharray:d})}return U.createElement(ct,{props:n,points:o,clipPathId:t,pathRef:r,strokeDasharray:d})}),U.createElement(h,{label:n.label}))}function dt(e){var{clipPathId:t,props:n}=e,r=(0,U.useRef)(null),i=(0,U.useRef)(0),a=(0,U.useRef)(null);return U.createElement(ut,{props:n,clipPathId:t,previousPointsRef:r,longestAnimatedLengthRef:i,pathRef:a})}var ft=(e,t)=>({x:e.x??void 0,y:e.y??void 0,value:e.value,errorVal:C(e.payload,t)}),pt=class extends U.Component{render(){var{hide:e,dot:t,points:n,className:r,xAxisId:i,yAxisId:a,top:o,left:c,width:l,height:u,id:d,needClip:f,zIndex:m}=this.props;if(e)return null;var h=s(`recharts-line`,r),g=d,{r:_,strokeWidth:v}=Ke(t),y=H(t),b=_*2+v,x=f?`url(#clipPath-${y?``:`dots-`}${g})`:void 0;return U.createElement(p,{zIndex:m},U.createElement(L,{className:h},f&&U.createElement(`defs`,null,U.createElement(ge,{clipPathId:g,xAxisId:i,yAxisId:a}),!y&&U.createElement(`clipPath`,{id:`clipPath-dots-${g}`},U.createElement(`rect`,{x:c-b/2,y:o-b/2,width:l+b,height:u+b}))),U.createElement(ie,{xAxisId:i,yAxisId:a,data:n,dataPointFormatter:ft,errorBarOffset:0},U.createElement(dt,{props:this.props,clipPathId:g}))),U.createElement(Le,{activeDot:this.props.activeDot,points:n,mainColor:this.props.stroke,itemDataKey:this.props.dataKey,clipPath:x}))}},mt={activeDot:!0,animateNewValues:!0,animationBegin:0,animationDuration:1500,animationEasing:`ease`,connectNulls:!1,dot:!0,fill:`#fff`,hide:!1,isAnimationActive:`auto`,label:!1,legendType:`line`,stroke:`#3182bd`,strokeWidth:1,xAxisId:0,yAxisId:0,zIndex:y.line,type:`linear`};function ht(e){var t=B(e,mt),{activeDot:n,animateNewValues:r,animationBegin:i,animationDuration:a,animationEasing:o,connectNulls:s,dot:c,hide:l,isAnimationActive:u,label:d,legendType:f,xAxisId:p,yAxisId:m,id:h}=t,g=Q(t,Ye),{needClip:_}=_e(p,m),v=ae(),y=D(),b=R(),x=I(e=>Ge(e,p,m,b,h));if(y!==`horizontal`&&y!==`vertical`||x==null||v==null)return null;var{height:S,width:C,x:w,y:T}=v;return U.createElement(pt,X({},g,{id:h,connectNulls:s,dot:c,activeDot:n,animateNewValues:r,animationBegin:i,animationDuration:a,animationEasing:o,isAnimationActive:u,hide:l,label:d,legendType:f,xAxisId:p,yAxisId:m,points:x,layout:y,height:S,width:C,left:w,top:T,needClip:_}))}function gt(e){var{layout:t,xAxis:n,yAxis:r,xAxisTicks:i,yAxisTicks:a,dataKey:o,bandSize:s,displayedData:c}=e;return c.map((e,c)=>{var l=C(e,o);if(t===`horizontal`)return{x:O({axis:n,ticks:i,bandSize:s,entry:e,index:c}),y:(V(l)?null:r.scale.map(l))??null,value:l,payload:e};var u=V(l)?null:n.scale.map(l),d=O({axis:r,ticks:a,bandSize:s,entry:e,index:c});return u==null||d==null?null:{x:u,y:d,value:l,payload:e}}).filter(Boolean)}function _t(e){var t=B(e,mt),n=R();return U.createElement(se,{id:t.id,type:`line`},e=>U.createElement(U.Fragment,null,U.createElement(ne,{legendPayload:tt(t)}),U.createElement(nt,{dataKey:t.dataKey,data:t.data,stroke:t.stroke,strokeWidth:t.strokeWidth,fill:t.fill,name:t.name,hide:t.hide,unit:t.unit,tooltipType:t.tooltipType,id:e}),U.createElement(le,{type:`line`,id:e,data:t.data,xAxisId:t.xAxisId,yAxisId:t.yAxisId,zAxisId:0,dataKey:t.dataKey,hide:t.hide,isPanorama:n}),U.createElement(ht,X({},t,{id:e}))))}var vt=U.memo(_t,_);vt.displayName=`Line`;var yt=[`axis`],bt=(0,U.forwardRef)((e,t)=>U.createElement(he,{chartName:`LineChart`,defaultTooltipEventType:`axis`,validateTooltipEventTypes:yt,tooltipPayloadSearcher:pe,categoricalChartProps:e,ref:t})),$=n(),xt=[{value:`7d`,labelKey:`periods.d7`},{value:`30d`,labelKey:`periods.d30`},{value:`90d`,labelKey:`periods.d90`},{value:`all`,labelKey:`periods.all`},{value:`custom`,labelKey:`periods.custom`}];function St({period:e,from:t,to:n,onChange:r}){let{t:i}=a(`analytics`);function o(e){e===`custom`?r(`custom`,t,n):r(e)}function s(e){r(`custom`,e,n)}function l(e){r(`custom`,t,e)}return(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(`div`,{className:`flex items-center gap-1`,children:xt.map(t=>(0,$.jsx)(`button`,{onClick:()=>o(t.value),className:c(`h-7 px-3 rounded-md text-xs font-medium transition-colors`,e===t.value?`bg-primary text-primary-foreground`:`text-muted-foreground hover:text-foreground hover:bg-accent`),children:i(t.labelKey)},t.value))}),e===`custom`&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`input`,{type:`date`,value:t,onChange:e=>s(e.target.value),"aria-label":i(`periods.startDate`),className:`h-7 px-2 rounded-md text-xs bg-card border border-border text-foreground focus:outline-none focus:ring-1 focus:ring-primary`}),(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:i(`periods.to`)}),(0,$.jsx)(`input`,{type:`date`,value:n,onChange:e=>l(e.target.value),"aria-label":i(`periods.endDate`),className:`h-7 px-2 rounded-md text-xs bg-card border border-border text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})]})]})}function Ct({kpi:e,windowLabel:t}){let{t:n}=a(`analytics`),r=e.estimatedCostUsd??0,i=e.estimatedCostToday??0,o=e.includesEstimated??r>0,s=r>0,c=i>0,l=typeof e.pricedRuns==`number`||typeof e.unpricedRuns==`number`,u=e.unpricedRuns??0,d=e.pricedRuns??(l?Math.max(0,e.totalJobs-u):e.totalJobs),f=l&&e.totalCostUsd===0&&u>0&&d===0,p=u>0&&(d>0||e.totalCostUsd>0),m=e.unpricedTodayRuns??0,h=e.pricedTodayRuns??(l?Math.max(0,e.jobsToday-m):e.jobsToday),g=l&&e.costToday===0&&m>0&&h===0;return(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`div`,{className:`grid grid-cols-2 lg:grid-cols-4 gap-3`,children:[{key:`totalCost`,label:n(`desktop.totalCost`),value:f?`—`:`${s?`~`:``}$${e.totalCostUsd.toFixed(4)}`,sub:g?n(`desktop.costTodayUnavailable`):n(`desktop.costToday`,{value:`${c?`~`:``}$${e.costToday.toFixed(4)}`}),estimated:s,window:t},{key:`totalJobs`,label:n(`desktop.totalJobs`),value:e.totalJobs.toLocaleString(),sub:n(`desktop.jobsToday`,{n:e.jobsToday}),estimated:!1},{key:`successRate`,label:n(`desktop.successRate`),value:`${(e.successRate*100).toFixed(1)}%`,sub:n(`desktop.acrossAllProjects`),estimated:!1},{key:`avgCostPerJob`,label:n(`desktop.avgCostPerJob`),value:e.totalJobs>0&&u===0?`${s?`~`:``}$${(e.totalCostUsd/e.totalJobs).toFixed(5)}`:`—`,sub:n(u>0?`desktop.averageUnavailable`:`desktop.periodAverage`),estimated:s&&e.totalJobs>0}].map(e=>(0,$.jsxs)(`div`,{className:`rounded-lg border border-border/40 bg-card/50 p-4`,"data-estimated":e.estimated?`true`:void 0,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-1 mb-1`,children:[(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.label}),`window`in e&&e.window&&(0,$.jsx)(`span`,{"data-testid":`kpi-window-label`,className:`text-[10px] text-muted-foreground/70 whitespace-nowrap`,children:e.window})]}),(0,$.jsx)(`p`,{className:`text-xl font-semibold font-mono`,children:e.value}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:e.sub})]},e.key))}),o&&(0,$.jsx)(`p`,{"data-testid":`kpi-estimated-footnote`,className:`text-[10px] text-muted-foreground/70 italic`,title:n(`desktop.includesEstimatedTooltip`,{amount:`$${r.toFixed(4)}`}),children:n(`desktop.includesEstimated`,{amount:`$${r.toFixed(4)}`})}),(f||p)&&(0,$.jsx)(`p`,{"data-testid":`kpi-cost-coverage-note`,className:`text-[10px] text-muted-foreground/70 italic`,children:f?n(`desktop.costUnavailable`):n(`desktop.costPartiallyUnavailable`,{count:u})})]})}function wt({data:e}){let{t}=a(`analytics`),n=u(),i=e.length>0&&e.some(e=>e.costUsd>0),o=e.reduce((e,t)=>e+(t.unpricedCount??0),0),s=!i&&o>0,c=i&&o>0,d=Math.max(1,Math.floor(e.length/7)),f=e.filter((e,t)=>t%d===0).map(e=>e.date),p=new Map(e.map(e=>[e.date,e.estimatedCostUsd??0])),m=e.some(e=>(e.estimatedCostUsd??0)>0);return(0,$.jsxs)(`div`,{className:`rounded-lg border border-border/40 bg-card/50 p-4`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,$.jsx)(`h3`,{className:`text-sm font-medium`,children:t(`desktop.costOverTime`)}),m&&(0,$.jsx)(`span`,{"data-testid":`timeline-estimated-note`,className:`text-[10px] text-muted-foreground/70 italic`,title:t(`desktop.timelineEstimatedTooltip`),children:t(`desktop.includesEstimatedShort`)}),c&&(0,$.jsx)(`span`,{className:`text-[10px] text-muted-foreground/70 italic`,children:t(`desktop.costPartiallyUnavailable`,{count:o})})]}),s?(0,$.jsx)(`div`,{"data-testid":`desktop-timeline-cost-unavailable`,className:`h-[200px] flex items-center justify-center text-xs text-muted-foreground`,children:t(`desktop.costUnavailable`)}):i?(0,$.jsx)(v,{width:`100%`,height:200,children:(0,$.jsxs)(bt,{data:e,margin:{top:4,right:8,left:0,bottom:0},children:[(0,$.jsx)(P,{strokeDasharray:`3 3`,stroke:`var(--color-border)`}),(0,$.jsx)(de,{dataKey:`date`,ticks:f,tickFormatter:e=>{try{return l(new Date(e),`MMM d`,{locale:r()})}catch{return e}},tick:{fontSize:10,fill:`var(--color-muted-foreground)`},axisLine:!1,tickLine:!1}),(0,$.jsx)(z,{tickFormatter:e=>`$${e.toFixed(2)}`,tick:{fontSize:10,fill:`var(--color-muted-foreground)`},axisLine:!1,tickLine:!1,width:55}),(0,$.jsx)(x,{content:({active:e,payload:t,label:n})=>{if(!e||!t?.length)return null;let r=(p.get(n)??0)>0;return(0,$.jsxs)(`div`,{className:`bg-popover border border-border/30 rounded-lg p-2 text-xs shadow-lg`,children:[(0,$.jsx)(`p`,{className:`text-muted-foreground mb-1`,children:n}),(0,$.jsxs)(`p`,{className:`font-medium`,children:[r?`~`:``,`$`,t[0].value.toFixed(4)]})]})}}),(0,$.jsx)(vt,{type:`monotone`,dataKey:`costUsd`,stroke:n.chart[0],strokeWidth:2,dot:!1,activeDot:{r:3,fill:n.chart[0]}})]})}):(0,$.jsx)(`div`,{className:`h-[200px] flex items-center justify-center text-xs text-muted-foreground`,children:t(`desktop.noCostData`)})]})}function Tt({projects:e}){let{t}=a(`analytics`),n=u();if(e.length===0)return(0,$.jsxs)(`div`,{className:`rounded-lg border border-border/40 bg-card/50 p-4`,children:[(0,$.jsx)(`h3`,{className:`text-sm font-medium mb-3`,children:t(`desktop.projectComparison`)}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:t(`desktop.noProjects`)})]});let r=Math.max(...e.map(e=>e.totalCostUsd),1e-4);return(0,$.jsxs)(`div`,{className:`rounded-lg border border-border/40 bg-card/50 p-4`,children:[(0,$.jsx)(`h3`,{className:`text-sm font-medium mb-4`,children:t(`desktop.projectComparison`)}),(0,$.jsx)(`div`,{className:`space-y-3`,children:e.map((e,i)=>{let a=e.estimatedCostUsd??0,o=a>0,s=e.unpricedRuns??0,c=e.pricedRuns??Math.max(0,e.totalJobs-s),l=s>0&&c===0,u=s>0&&c>0;return(0,$.jsxs)(`div`,{className:`space-y-1`,"data-estimated":o?`true`:void 0,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,$.jsxs)(`span`,{className:`font-medium truncate max-w-[160px] flex items-center gap-1`,title:e.projectName,children:[e.projectName,o&&(0,$.jsx)(`span`,{"data-testid":`project-estimated-badge`,className:`text-[9px] uppercase tracking-wide text-muted-foreground/70 not-italic border border-border/40 rounded px-1`,title:t(`desktop.projectEstimatedTooltip`,{amount:`$${a.toFixed(4)}`}),children:t(`desktop.estimatedBadge`)})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-4 text-muted-foreground`,children:[(0,$.jsx)(`span`,{children:t(`desktop.jobsCount`,{count:e.totalJobs})}),(0,$.jsx)(`span`,{children:t(`desktop.successPct`,{pct:(e.successRate*100).toFixed(0)})}),(0,$.jsx)(`span`,{className:`font-mono text-foreground`,title:u?t(`desktop.costPartiallyUnavailable`,{count:s}):void 0,children:l?t(`desktop.costUnavailableShort`):`${o?`~`:``}$${e.totalCostUsd.toFixed(4)}`})]})]}),(0,$.jsx)(`div`,{className:`h-1.5 rounded-full bg-border/30 overflow-hidden`,children:(0,$.jsx)(`div`,{className:`h-full rounded-full transition-all duration-500`,style:{width:`${e.totalCostUsd/r*100}%`,backgroundColor:n.chart[i%n.chart.length]}})})]},e.projectId)})})]})}function Et({projects:e}){let{t}=a(`analytics`),n=u();if(e.length===0)return null;let r=e.map(e=>({name:e.projectName.slice(0,12),costUsd:e.totalCostUsd})),i=e.some(e=>e.totalCostUsd>0),o=e.some(e=>(e.unpricedRuns??0)>0);return(0,$.jsxs)(`div`,{className:`rounded-lg border border-border/40 bg-card/50 p-4`,children:[(0,$.jsx)(`h3`,{className:`text-sm font-medium mb-3`,children:t(`desktop.costByProject`)}),!i&&o?(0,$.jsx)(`div`,{"data-testid":`desktop-project-cost-unavailable`,className:`h-[180px] flex items-center justify-center text-xs text-muted-foreground`,children:t(`desktop.costUnavailable`)}):(0,$.jsx)(v,{width:`100%`,height:180,children:(0,$.jsxs)(ve,{data:r,margin:{top:4,right:8,left:0,bottom:0},children:[(0,$.jsx)(P,{strokeDasharray:`3 3`,stroke:`var(--color-border)`}),(0,$.jsx)(de,{dataKey:`name`,tick:{fontSize:10,fill:`var(--color-muted-foreground)`},axisLine:!1,tickLine:!1}),(0,$.jsx)(z,{tickFormatter:e=>`$${e.toFixed(2)}`,tick:{fontSize:10,fill:`var(--color-muted-foreground)`},axisLine:!1,tickLine:!1,width:55}),(0,$.jsx)(x,{content:({active:e,payload:t,label:n})=>e&&t?.length?(0,$.jsxs)(`div`,{className:`bg-popover border border-border/30 rounded-lg p-2 text-xs shadow-lg`,children:[(0,$.jsx)(`p`,{className:`text-muted-foreground mb-1`,children:n}),(0,$.jsxs)(`p`,{className:`font-medium`,children:[`$`,t[0].value.toFixed(4)]})]}):null}),(0,$.jsx)(re,{dataKey:`costUsd`,fill:n.chart[1],radius:[3,3,0,0]})]})})]})}function Dt(){let{t:e}=a(`analytics`),[t,n]=(0,U.useState)(`7d`),[r,o]=(0,U.useState)(``),[s,c]=(0,U.useState)(``),[l,u]=(0,U.useState)(null),[f,p]=(0,U.useState)(!0),[m,h]=(0,U.useState)(null),{registerHandler:g,unregisterHandler:_}=i(),v=(0,U.useCallback)(e=>{let n=e;(n.type===`spending.invalidated`||n.type===`rail.job_completed`)&&y(t,r,s)},[t,r,s]);(0,U.useEffect)(()=>(g(`desktop-analytics`,v),()=>_(`desktop-analytics`)),[v,g,_]);async function y(e,t,n){p(!0),h(null);try{let r=new URLSearchParams({period:e});e===`custom`&&t&&n&&(r.set(`from`,t),r.set(`to`,n));let i=await fetch(`/api/analytics?${r}`);if(!i.ok)throw Error(`HTTP ${i.status}`);let a=await i.json();u(a)}catch(e){h(e.message)}finally{p(!1)}}(0,U.useEffect)(()=>{y(t,r,s)},[t,r,s]);function b(e,t,r){n(e),t!==void 0&&o(t),r!==void 0&&c(r)}return(0,$.jsx)(`div`,{className:`flex flex-col h-full overflow-auto bg-background`,children:(0,$.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(Se,{className:`w-4 h-4 text-muted-foreground`}),(0,$.jsx)(`h1`,{className:`text-sm font-semibold`,children:e(`desktop.title`)}),l&&(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:l.period.label})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-3 mr-8`,children:[(0,$.jsx)(St,{period:t,from:r,to:s,onChange:b}),(0,$.jsx)(`button`,{onClick:()=>y(t,r,s),disabled:f,className:`flex items-center gap-1.5 h-7 px-2 rounded-md text-xs text-muted-foreground hover:text-foreground hover:bg-accent transition-colors disabled:opacity-50`,"aria-label":e(`desktop.refreshAria`),children:(0,$.jsx)(d,{className:`w-3 h-3 ${f?`animate-spin`:``}`})})]})]}),m&&(0,$.jsx)(`div`,{className:`rounded-lg border border-red-400/30 aurora-light:border-destructive/30 bg-red-400/10 aurora-light:bg-destructive/10 p-3 text-xs text-red-400 aurora-light:text-destructive`,children:e(`desktop.failedToLoad`,{error:m})}),f&&!l&&(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsx)(`div`,{className:`grid grid-cols-2 lg:grid-cols-4 gap-3`,children:Array.from({length:4}).map((e,t)=>(0,$.jsx)(`div`,{className:`h-20 rounded-lg border border-border/40 bg-card/50 animate-pulse`},t))}),(0,$.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:Array.from({length:2}).map((e,t)=>(0,$.jsx)(`div`,{className:`h-[220px] rounded-lg border border-border/40 bg-card/50 animate-pulse`},t))})]}),l&&(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsx)(Ct,{kpi:l.kpi,windowLabel:t===`custom`?l.period.label:e(`windowLabels.${t}`)}),(0,$.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:[(0,$.jsx)(wt,{data:l.costTimeline}),(0,$.jsx)(Et,{projects:l.projectBreakdown})]}),(0,$.jsx)(Tt,{projects:l.projectBreakdown})]})]})})}export{Dt as default};
|