specrails-desktop 2.34.0 → 2.35.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/dist/assets/ActivityFeedPage-LCBJ5WiD.js +1 -0
- package/client/dist/assets/AgentBrowserCapture-B-xQpyZr.js +1 -0
- package/client/dist/assets/AgentModeAnalyticsPane-BI1Vcf3T.js +2 -0
- package/client/dist/assets/AgentModeCodePane-BTRwCl9h.js +2 -0
- package/client/dist/assets/AgentModeJobsPane-VzeBJLqP.js +1 -0
- package/client/dist/assets/AgentsPage-CJj1K24O.js +87 -0
- package/client/dist/assets/AnalyticsPage-CQpV5_fX.js +1 -0
- package/client/dist/assets/CodePage-9-tFh0jB.js +2 -0
- package/client/dist/assets/DesktopAnalyticsPage-BcZ0_O_C.js +1 -0
- package/client/dist/assets/DocsDialog-BPAzDICW.js +11 -0
- package/client/dist/assets/DocsPage-Dqo4Hn6G.js +11 -0
- package/client/dist/assets/IntegrationsPage-Bhy58lnQ.js +1 -0
- package/client/dist/assets/InteractiveJobComposer-D36fZWai.js +19 -0
- package/client/dist/assets/JobDetailModal-BxsktbkQ.js +1 -0
- package/client/dist/assets/JobDetailPage-WWyCy6Sp.js +1 -0
- package/client/dist/assets/JobsPage-CEbM7uxU.js +1 -0
- package/client/dist/assets/{LoopBuilderPage-WeiofeL6.js → LoopBuilderPage-CYsSN8io.js} +2 -2
- package/client/dist/assets/LoopPreviewModal-BJhgX5wY.js +1 -0
- package/client/dist/assets/LoopsPage-DB4OqMot.js +1 -0
- package/client/dist/assets/MinimizedChatsContext-CcjBHMHd.js +1 -0
- package/client/dist/assets/PluginsPage-CR8K4nM_.js +2 -0
- package/client/dist/assets/{ProjectSettingsDialog-BkCXBQWk.js → ProjectSettingsDialog-C45-qhF4.js} +1 -1
- package/client/dist/assets/ReviewPacketPage-Cz_QQeC3.js +1 -0
- package/client/dist/assets/TemplatePreviewModal-wFBd2vQP.js +1 -0
- package/client/dist/assets/TicketDetailModal-BvZoyDAL.js +14 -0
- package/client/dist/assets/{Trans-CTqw6rr9.js → Trans-DXZ-BLXb.js} +1 -1
- package/client/dist/assets/agent-BQgKv_2F.js +1 -0
- package/client/dist/assets/agent-C1NRDJqL.js +1 -0
- package/client/dist/assets/agent-CLNleiy6.js +1 -0
- package/client/dist/assets/agent-CmceArkQ.js +1 -0
- package/client/dist/assets/agent-D3UxQ3SR.js +1 -0
- package/client/dist/assets/agent-DB1JeE64.js +1 -0
- package/client/dist/assets/agent-DXkHcQ-D.js +1 -0
- package/client/dist/assets/agent-DjJJJ2M8.js +1 -0
- package/client/dist/assets/ban-E4EaZe3a.js +1 -0
- package/client/dist/assets/bot-DzuuuC5R.js +1 -0
- package/client/dist/assets/{browser-DxP-alBK.js → browser-BgqHDMXP.js} +1 -1
- package/client/dist/assets/{browser-CyR1Kp3m.js → browser-CsKJtrpv.js} +1 -1
- package/client/dist/assets/browser-Cu58EpZU.js +1 -0
- package/client/dist/assets/{browser-rRCwi7Y7.js → browser-CvXOJm-j.js} +1 -1
- package/client/dist/assets/{browser-CvgDySd9.js → browser-DOrFh1c7.js} +1 -1
- package/client/dist/assets/{browser-DwZljcRh.js → browser-DQv_Jo7x.js} +1 -1
- package/client/dist/assets/{browser-C25DkQiO.js → browser-LPgxvJu2.js} +1 -1
- package/client/dist/assets/{browser-CiJ7-L32.js → browser-eL-3MIEI.js} +1 -1
- package/client/dist/assets/button-CJqFnUOL.js +1 -0
- package/client/dist/assets/{chunk-KS7C4IRE-Cx5sqopX.js → chunk-KS7C4IRE-DEKu087k.js} +1 -1
- package/client/dist/assets/{commands-DyUZQ1FI.js → commands-6tYQih5m.js} +1 -1
- package/client/dist/assets/{commands-B9RZO4qS.js → commands-BK2QinXN.js} +1 -1
- package/client/dist/assets/{commands-Bbxu8kLU.js → commands-C2Nca76h.js} +1 -1
- package/client/dist/assets/{commands-CDU3qv68.js → commands-CKdLihNX.js} +1 -1
- package/client/dist/assets/{commands-DTQBF_q5.js → commands-CYIBTAlc.js} +1 -1
- package/client/dist/assets/{commands-hOtKuOXc.js → commands-CjUtYJIM.js} +1 -1
- package/client/dist/assets/{commands-BEwbAjtD.js → commands-Cq_u_8y9.js} +1 -1
- package/client/dist/assets/{commands-CzezgtQj.js → commands-D_ZHYQug.js} +1 -1
- package/client/dist/assets/core-B3mKBIh5.js +1 -0
- package/client/dist/assets/dashboard-B9GhC5ku.js +1 -0
- package/client/dist/assets/dashboard-C8WOEiPu.js +1 -0
- package/client/dist/assets/dashboard-CBnv6zOI.js +1 -0
- package/client/dist/assets/dashboard-CaP0fU87.js +1 -0
- package/client/dist/assets/dashboard-D4ZZ4x84.js +1 -0
- package/client/dist/assets/dashboard-DmuTQBX8.js +1 -0
- package/client/dist/assets/dashboard-DynLYj3d.js +1 -0
- package/client/dist/assets/dashboard-zj4gGFJ1.js +1 -0
- package/client/dist/assets/dialog-CdWCb02j.js +45 -0
- package/client/dist/assets/dist-js-CWeUdf5Z.js +1 -0
- package/client/dist/assets/dist-js-Rlh4FLH5.js +1 -0
- package/client/dist/assets/event-Bt7f3wXe.js +1 -0
- package/client/dist/assets/file-text-BcLCfcWZ.js +1 -0
- package/client/dist/assets/{formatDistanceToNow-BOuXgebD.js → formatDistanceToNow-C0ImhVKp.js} +1 -1
- package/client/dist/assets/{getTimezoneOffsetInMilliseconds-EjGOpn4b.js → getTimezoneOffsetInMilliseconds-owhDdTXs.js} +1 -1
- package/client/dist/assets/git-refresh-wTW0rO0Z.js +1 -0
- package/client/dist/assets/i18n-DwgvwTnx.js +2 -0
- package/client/dist/assets/index-DhjjFyU5.js +66 -0
- package/client/dist/assets/index-xBFsOEiJ.css +2 -0
- package/client/dist/assets/jira-api-CcZMcEN5.js +1 -0
- package/client/dist/assets/loops-B7YpGizO.js +1 -0
- package/client/dist/assets/{loops-CMMQOw2P.js → loops-BomD2J-h.js} +1 -1
- package/client/dist/assets/{loops-B2_97D26.js → loops-BrQHSQw3.js} +1 -1
- package/client/dist/assets/{loops-BwxCndZk.js → loops-BvBwvTPA.js} +1 -1
- package/client/dist/assets/{loops-BISOkuCu.js → loops-CODk6Slz.js} +1 -1
- package/client/dist/assets/{loops-CD19kEzq.js → loops-DC6k-Ym-.js} +1 -1
- package/client/dist/assets/{loops-aEb4RxN2.js → loops-DSEg8-uY.js} +1 -1
- package/client/dist/assets/{loops-Bo6w_peZ.js → loops-DhCoXD_v.js} +1 -1
- package/client/dist/assets/narration-4Z2VUhZw.js +1 -0
- package/client/dist/assets/narration-BGuiEDj3.js +1 -0
- package/client/dist/assets/narration-BuSoqRmv.js +1 -0
- package/client/dist/assets/narration-CB9t29fy.js +1 -0
- package/client/dist/assets/narration-CU3x8FHD.js +1 -0
- package/client/dist/assets/narration-CWeXhfP5.js +1 -0
- package/client/dist/assets/narration-DRaDnhT5.js +1 -0
- package/client/dist/assets/narration-DtEbQgCw.js +1 -0
- package/client/dist/assets/packet-B1IxaL5f.js +1 -0
- package/client/dist/assets/packet-Bh5kkbiB.js +1 -0
- package/client/dist/assets/packet-By8fqYxW.js +1 -0
- package/client/dist/assets/packet-CZdvA44E.js +1 -0
- package/client/dist/assets/packet-CrjHRQCP.js +1 -0
- package/client/dist/assets/packet-Dwi2pTtx.js +1 -0
- package/client/dist/assets/packet-_-ZIa0IR.js +1 -0
- package/client/dist/assets/packet-n0W6E1Hn.js +1 -0
- package/client/dist/assets/save-B6wGWwBR.js +1 -0
- package/client/dist/assets/settings-Bd0x4TBa.js +1 -0
- package/client/dist/assets/settings-C1-7cXzC.js +1 -0
- package/client/dist/assets/settings-CAFaT38b.js +1 -0
- package/client/dist/assets/settings-Ct3v1nW2.js +1 -0
- package/client/dist/assets/settings-DHh7_IF5.js +1 -0
- package/client/dist/assets/settings-DQXAmdcv.js +1 -0
- package/client/dist/assets/settings-guzlhpup.js +1 -0
- package/client/dist/assets/settings-sZfTPMEH.js +1 -0
- package/client/dist/assets/{spending-BpYPsevQ.js → spending-BQX3P7Cq.js} +1 -1
- package/client/dist/assets/useDesktop-BzX769yH.js +1 -0
- package/client/dist/index.html +29 -31
- package/docs/internals/embedded-browser-native-webview-evaluation.md +161 -0
- package/docs/internals/review-packet.md +212 -0
- package/package.json +1 -1
- package/server/dist/accept-ladder.js +61 -0
- package/server/dist/agent-chat-manager.js +22 -1
- package/server/dist/agent-defaults.js +359 -0
- package/server/dist/agent-operator-prompt.js +13 -5
- package/server/dist/browser-playwright.js +39 -2
- package/server/dist/db.js +38 -0
- package/server/dist/delivery-evidence.js +242 -0
- package/server/dist/desktop-router.js +23 -0
- package/server/dist/feature-flags.js +23 -0
- package/server/dist/loop-command-catalog.js +33 -0
- package/server/dist/loop-executors.js +12 -2
- package/server/dist/loop-factory.js +16 -1
- package/server/dist/loops-router.js +2 -0
- package/server/dist/mcp/tools/rails.js +16 -0
- package/server/dist/project-registry.js +33 -1
- package/server/dist/project-router-loop-runs.js +27 -2
- package/server/dist/providers/claude-adapter.js +60 -3
- package/server/dist/queue-manager.js +47 -4
- package/server/dist/rail-isolated-launch.js +119 -5
- package/server/dist/rail-pr-store.js +40 -3
- package/server/dist/rail-worktree-release.js +17 -1
- package/server/dist/rails-router.js +124 -3
- package/server/dist/review-packet.js +327 -0
- package/server/dist/revision-seed.js +73 -0
- package/server/dist/run-duration-stats.js +71 -0
- package/server/dist/stuck-run-detector.js +153 -0
- package/server/dist/telemetry-receiver.js +22 -0
- package/server/dist/worktree-node-modules.js +138 -16
- package/client/dist/assets/ActivityFeedPage-DIDxNsDj.js +0 -1
- package/client/dist/assets/AgentBrowserCapture-7pJ2G5VY.js +0 -1
- package/client/dist/assets/AgentModeAnalyticsPane-BSSyTnTM.js +0 -2
- package/client/dist/assets/AgentModeCodePane-DzW6gvDw.js +0 -2
- package/client/dist/assets/AgentModeJobsPane-9wJff15f.js +0 -1
- package/client/dist/assets/AgentsPage-CIA67psb.js +0 -87
- package/client/dist/assets/AnalyticsPage-C0LwYELz.js +0 -1
- package/client/dist/assets/CodePage-RtKvHmAO.js +0 -2
- package/client/dist/assets/DesktopAnalyticsPage-BU8Y_Ts1.js +0 -1
- package/client/dist/assets/DocsDialog-DIpoaGlQ.js +0 -11
- package/client/dist/assets/DocsPage-ME47KZpK.js +0 -11
- package/client/dist/assets/IntegrationsPage-Bs00_tl4.js +0 -1
- package/client/dist/assets/InteractiveJobComposer-BGjIe9R6.js +0 -19
- package/client/dist/assets/JobDetailModal-1UZkqH4I.js +0 -1
- package/client/dist/assets/JobDetailPage-CN65sAf1.js +0 -1
- package/client/dist/assets/JobsPage-f-4dqys7.js +0 -1
- package/client/dist/assets/LoopPreviewModal-DDTnTyH0.js +0 -1
- package/client/dist/assets/LoopsPage-BVNchIex.js +0 -1
- package/client/dist/assets/MinimizedChatsContext-CHsu3NCX.js +0 -1
- package/client/dist/assets/PluginsPage-CdFzGEfQ.js +0 -2
- package/client/dist/assets/TemplatePreviewModal-RDi0khFG.js +0 -1
- package/client/dist/assets/TicketDetailModal-MhJzrqbi.js +0 -14
- package/client/dist/assets/agent-Bd-q3Wqp.js +0 -1
- package/client/dist/assets/agent-BlvdW4Hv.js +0 -1
- package/client/dist/assets/agent-C-KQhxeM.js +0 -1
- package/client/dist/assets/agent-Ca15w5eu.js +0 -1
- package/client/dist/assets/agent-D6fKaoMd.js +0 -1
- package/client/dist/assets/agent-HFMYMTbB.js +0 -1
- package/client/dist/assets/agent-QIEbkBjg.js +0 -1
- package/client/dist/assets/agent-mTCsAbCl.js +0 -1
- package/client/dist/assets/api-B2M7CtDw.js +0 -1
- package/client/dist/assets/arrow-left-CpIR4j7G.js +0 -1
- package/client/dist/assets/arrow-up-right-9DoMn7fD.js +0 -1
- package/client/dist/assets/browser-CXUcnTMI.js +0 -1
- package/client/dist/assets/button-BUIIBQPT.js +0 -1
- package/client/dist/assets/chevron-right-CViMxucY.js +0 -1
- package/client/dist/assets/dashboard-BHRqsGCV.js +0 -1
- package/client/dist/assets/dashboard-Bfr90vOl.js +0 -1
- package/client/dist/assets/dashboard-CTsM8x3m.js +0 -1
- package/client/dist/assets/dashboard-CqC6wX0h.js +0 -1
- package/client/dist/assets/dashboard-CuZtAszc.js +0 -1
- package/client/dist/assets/dashboard-DAcqIc-n.js +0 -1
- package/client/dist/assets/dashboard-DekiV-86.js +0 -1
- package/client/dist/assets/dashboard-DoDczc5S.js +0 -1
- package/client/dist/assets/dialog-CzIekCw0.js +0 -45
- package/client/dist/assets/dist-Cez5CRkX.js +0 -1
- package/client/dist/assets/dist-js-BmsFWRly.js +0 -1
- package/client/dist/assets/dist-js-J5W_N5ng.js +0 -1
- package/client/dist/assets/external-link-BcU5EWZp.js +0 -1
- package/client/dist/assets/file-text-CFT-xXKN.js +0 -1
- package/client/dist/assets/i18n-nJQvD5zJ.js +0 -2
- package/client/dist/assets/index-C_sdsSZt.js +0 -63
- package/client/dist/assets/index-DCN5QbDm.css +0 -2
- package/client/dist/assets/jira-api-Bhixwn-d.js +0 -1
- package/client/dist/assets/loops-CnxqL8IL.js +0 -1
- package/client/dist/assets/save-28sIlCdr.js +0 -1
- package/client/dist/assets/settings-BveOJoaI.js +0 -1
- package/client/dist/assets/settings-Cj1C6F5k.js +0 -1
- package/client/dist/assets/settings-CuVwOpe0.js +0 -1
- package/client/dist/assets/settings-D5X4DfRc.js +0 -1
- package/client/dist/assets/settings-DXwxe-BW.js +0 -1
- package/client/dist/assets/settings-Di81Ba_V.js +0 -1
- package/client/dist/assets/settings-jbLjCYC_.js +0 -1
- package/client/dist/assets/settings-wIZNPFnn.js +0 -1
- package/client/dist/assets/useBrowserCaptureSession-BBXBN0Na.js +0 -1
- package/client/dist/assets/useDesktop-B6Du2N83.js +0 -1
- package/client/dist/assets/useSharedWebSocket-DK96ctb7.js +0 -1
|
@@ -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{f as r}from"./chunk-KS7C4IRE-DEKu087k.js";import{a as i,w as a}from"./i18n-DwgvwTnx.js";import{t as o}from"./Trans-DXZ-BLXb.js";import{n as s,t as c}from"./createLucideIcon-Bjbbp_KS.js";import{n as l,t as u}from"./bot-DzuuuC5R.js";import{a as d,n as f,r as p}from"./useDesktop-BzX769yH.js";import{t as m}from"./clsx-CjueKrWZ.js";import{r as h}from"./provider-capabilities-Doej9lfa.js";import{t as g}from"./formatDistanceToNow-C0ImhVKp.js";import{n as _,t as v}from"./spending-BQX3P7Cq.js";import{ct as y}from"./index-DhjjFyU5.js";import{t as b}from"./ExportDropdown-BrtfWzEG.js";import{A as x,B as S,C,D as ee,E as w,F as T,G as E,H as D,I as O,J as k,K as A,L as j,M,N,O as P,P as F,Q as I,R as te,S as L,T as R,V as z,X as B,Z as V,_ as ne,_t as H,a as U,at as re,b as ie,c as ae,ct as oe,et as W,f as se,g as G,gt as ce,h as le,i as ue,j as de,k as fe,l as pe,lt as K,m as me,n as he,nt as ge,o as _e,ot as ve,p as ye,pt as q,q as be,r as xe,rt as Se,s as Ce,st as we,t as Te,tt as Ee,ut as J,v as De,x as Oe,y as ke,z as Ae}from"./BarChart-nBOMNfiy.js";var je=c(`arrow-down-right`,[[`path`,{d:`m7 7 10 10`,key:`1fmybs`}],[`path`,{d:`M17 7v10H7`,key:`6fjiku`}]]),Y=e(t(),1),X=n();function Me(e){return e>=100?`$${e.toFixed(0)}`:e>=10?`$${e.toFixed(1)}`:`$${e.toFixed(2)}`}function Ne(e){return e>=1e3?`$${(e/1e3).toFixed(1)}k`:`$${e.toFixed(2)}`}function Pe(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:`${e}`}var Fe=[`job`,`explore-spec`,`quick-spec`,`ai-edit`,`chat-sidebar`,`spec-launcher`,`proposal`,`agent-studio`,`setup`,`smash`,`file-summary`,`loop`];function Ie({data:e,loading:t,period:n}){let{t:r}=s(`analytics`),[i,a]=(0,Y.useState)(0),o=(0,Y.useRef)(0),c=(0,Y.useRef)(null),u=(0,Y.useRef)(0);if((0,Y.useEffect)(()=>{if(!e)return;let t=e.summary.totalCostUsd,n=++u.current;if(c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),o.current===0&&t>0){let e=performance.now(),r=i=>{if(n!==u.current)return;let o=Math.min(1,(i-e)/600),s=1-(1-o)**3;a(0+(t-0)*s),o<1?c.current=requestAnimationFrame(r):c.current=null};c.current=requestAnimationFrame(r)}else a(t);return o.current=t,()=>{c.current!==null&&(cancelAnimationFrame(c.current),c.current=null)}},[e]),t&&!e)return(0,X.jsx)(`div`,{className:`h-44 rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let d=e.summary.totalCostUsd,f=e.summary.totalRuns,p=e.summary.totalTokens,m=e.summary.totalEstimatedCostUsd??0,h=typeof e.summary.pricedRuns==`number`||typeof e.summary.unpricedRuns==`number`,g=e.summary.unpricedRuns??0,y=e.summary.pricedRuns??(h?Math.max(0,f-g):f),b=h&&f>0&&y===0&&g>0,x=y>0&&g>0,S=typeof e.summary.usageReportedRuns==`number`||typeof e.summary.usageUnavailableRuns==`number`,C=e.summary.usageUnavailableRuns??0,ee=e.summary.usageReportedRuns??(S?Math.max(0,f-C):f),w=S&&f>0&&ee===0&&C>0,T=ee>0&&C>0,E=g>0?null:e.summary.deltaPct,D=e.trackingStartedAt,O=m>0,k=e.bySurface.map(e=>e.surface).filter(e=>!Fe.includes(e)),A=[...Fe,...k].map(t=>{let n=e.bySurface.find(e=>e.surface===t);return{surface:t,costUsd:n?.costUsd??0,count:n?.count??0}}),j=n?r(`windowLabels.${n}`):null;return(0,X.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-gradient-to-br from-card/80 to-card/40 p-5`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-end justify-between gap-3 mb-4`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`div`,{className:`text-[11px] uppercase tracking-wider text-muted-foreground mb-1 flex items-center gap-1.5`,children:[(0,X.jsx)(`span`,{children:r(`hero.spending`)}),j&&(0,X.jsxs)(`span`,{"data-testid":`hero-window-label`,className:`normal-case tracking-normal text-muted-foreground/70 font-normal`,children:[`· `,j]})]}),(0,X.jsxs)(`div`,{className:`flex items-baseline gap-3`,children:[(0,X.jsx)(`div`,{className:`text-5xl font-semibold tabular-nums tracking-tight`,"data-testid":b?`hero-cost-unavailable`:void 0,title:b?r(`hero.costUnavailableTooltip`):void 0,children:b?`—`:Ne(i)}),E!==null&&(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 text-xs font-medium ${E>=0?`text-accent-warning`:`text-accent-success`}`,children:[E>=0?(0,X.jsx)(l,{className:`w-3 h-3`}):(0,X.jsx)(je,{className:`w-3 h-3`}),r(`hero.vsPrev`,{pct:Math.abs(E).toFixed(0)})]})]}),(0,X.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-1 tabular-nums flex items-center gap-2`,children:[(0,X.jsx)(`span`,{children:r(`hero.invocations`,{count:f})}),w?(0,X.jsx)(`span`,{"data-testid":`hero-usage-unavailable`,className:`text-muted-foreground/80 italic`,title:r(`hero.usageUnavailableTooltip`),children:r(`hero.usageUnavailable`)}):T&&p!=null?(0,X.jsx)(`span`,{className:`text-muted-foreground/80 italic`,title:r(`hero.usagePartiallyUnavailableTooltip`),children:r(`hero.usagePartiallyUnavailable`,{tokens:Pe(p),count:C})}):p!=null&&p>0?(0,X.jsx)(`span`,{className:`text-muted-foreground/80`,title:r(`hero.tokensTooltip`),children:r(`hero.tokens`,{tokens:Pe(p)})}):null,b&&(0,X.jsx)(`span`,{className:`text-muted-foreground/80 italic`,title:r(`hero.costUnavailableTooltip`),children:r(`hero.costUnavailable`)}),x&&(0,X.jsx)(`span`,{"data-testid":`hero-cost-partial`,className:`text-muted-foreground/80 italic`,title:r(`hero.costPartiallyUnavailableTooltip`),children:r(`hero.costPartiallyUnavailable`,{count:g})}),O&&(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground/70 italic`,title:r(`hero.includesEstimatedTooltip`,{amount:Me(m)}),children:r(`hero.includesEstimated`,{amount:Me(m)})})]})]}),f===0&&D&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:r(`hero.trackingStarted`,{date:D.slice(0,10)})})]}),f===0?(0,X.jsxs)(`div`,{className:`rounded-lg border border-dashed border-border/40 p-6 text-center`,children:[(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:r(`hero.emptyState`)}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground/70 mt-1`,children:D?r(`hero.trackingStarted`,{date:D.slice(0,10)}):r(`hero.trackingStartedFallback`)})]}):b?(0,X.jsx)(`div`,{className:`rounded-lg border border-dashed border-border/40 p-4 text-xs text-muted-foreground/80`,children:r(`hero.costUnavailableTooltip`)}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`h-3 w-full rounded-full overflow-hidden bg-background-deep flex`,children:A.map(e=>{let t=d>0?e.costUsd/d*100:0;return t===0?null:(0,X.jsx)(`div`,{className:`h-full ${v[e.surface].dot}`,style:{width:`${t}%`},title:r(`hero.segmentTitle`,{label:_[e.surface],value:Me(e.costUsd)})},e.surface)})}),(0,X.jsx)(`div`,{className:`mt-3 flex flex-wrap items-center gap-x-5 gap-y-1.5 text-xs`,children:A.filter(e=>e.costUsd>0).map(e=>(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 tabular-nums`,children:[(0,X.jsx)(`span`,{className:`w-2 h-2 rounded-full ${v[e.surface].dot}`}),(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:_[e.surface]}),(0,X.jsx)(`span`,{className:`text-foreground font-medium`,children:Me(e.costUsd)}),(0,X.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,X.jsx)(`span`,{className:`text-muted-foreground/80`,children:e.count})]},e.surface))})]})]})}var Le={claude:`Claude`,codex:`Codex`,gemini:`Gemini`,kimi:`Kimi`},Re={claude:`bg-accent-info`,codex:`bg-accent-highlight`,gemini:`bg-accent-success`,kimi:`bg-purple-400`};function ze(e){return e>=100?`$${e.toFixed(0)}`:e>=10?`$${e.toFixed(1)}`:e>=.01?`$${e.toFixed(2)}`:`$${e.toFixed(4)}`}function Be(e){return Le[e]??e}function Ve(e){return Re[e]??`bg-accent-secondary`}function He({data:e,loading:t}){let{t:n}=s(`analytics`);if(t&&!e)return(0,X.jsx)(`div`,{className:`h-32 rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e||e.byProvider.length===0||e.byProvider.length===1)return null;let r=e.byProvider.reduce((e,t)=>e+t.costUsd+t.estimatedCostUsd,0),i=e.byProvider.some(e=>typeof e.unpricedCount==`number`?e.unpricedCount>0:e.count>0&&e.costUsd===0&&e.estimatedCostUsd===0);return(0,X.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,X.jsx)(`div`,{className:`flex items-baseline justify-between mb-3`,children:(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`text-[11px] uppercase tracking-wider text-muted-foreground`,children:n(`providerCard.title`)}),(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground/70 mt-0.5`,children:(0,X.jsx)(o,{ns:`analytics`,i18nKey:`providerCard.description`,components:{tilde:(0,X.jsx)(`span`,{className:`font-medium`})}})})]})}),r===0&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:n(i?`providerCard.costUnavailableTooltip`:`providerCard.noCost`)}),r>0&&(0,X.jsx)(X.Fragment,{children:(0,X.jsx)(`div`,{className:`h-2 w-full rounded-full overflow-hidden bg-background-deep flex mb-3`,children:e.byProvider.map(e=>{let t=e.costUsd+e.estimatedCostUsd,i=r>0?t/r*100:0;if(i===0)return null;let a=`${e.costUsd===0&&e.estimatedCostUsd>0?`~`:``}${ze(t)}`;return(0,X.jsx)(`div`,{className:`h-full ${Ve(e.provider)}`,style:{width:`${i}%`},title:n(`providerCard.segmentTitle`,{label:Be(e.provider),value:a,count:e.count})},e.provider)})})}),(0,X.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2 ${r>0?``:`mt-3`}`,children:e.byProvider.map(e=>(0,X.jsx)(Ue,{entry:e},e.provider))})]})}function Ue({entry:e}){let{t}=s(`analytics`),n=e.costUsd+e.estimatedCostUsd,r=e.costUsd===0&&e.estimatedCostUsd>0,i=e.unpricedCount??(e.count>0&&e.costUsd===0&&e.estimatedCostUsd===0?e.count:0),a=e.pricedCount??Math.max(0,e.count-i),o=e.count>0&&i>0&&a===0,c=a>0&&i>0;return(0,X.jsxs)(`div`,{className:`flex items-center gap-2.5 rounded-md border border-border/30 px-2.5 py-1.5`,children:[(0,X.jsx)(`span`,{className:`w-2 h-2 rounded-full shrink-0 ${Ve(e.provider)}`}),(0,X.jsx)(`span`,{className:`text-xs font-medium`,children:Be(e.provider)}),(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:t(`runs`,{count:e.count})}),o?(0,X.jsx)(`span`,{className:`ml-auto text-xs font-medium text-muted-foreground/80 italic`,title:t(`providerCard.costUnavailableTooltip`),children:t(`providerCard.costUnavailable`)}):(0,X.jsxs)(`span`,{className:`ml-auto text-xs font-medium tabular-nums`,title:c?t(`providerCard.costPartiallyUnavailableTooltip`):void 0,children:[r?`~`:``,ze(n),c&&(0,X.jsx)(`span`,{className:`ml-1 font-normal text-muted-foreground/80 italic`,children:t(`providerCard.costPartiallyUnavailable`,{count:i})})]})]})}var We=[`option`,`isActive`];function Z(){return Z=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},Z.apply(null,arguments)}function Ge(e,t){if(e==null)return{};var n,r,i=Ke(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function Ke(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}function qe(e){var{option:t,isActive:n}=e,r=Ge(e,We);return typeof t==`string`?Y.createElement(L,Z({option:Y.createElement(we,Z({type:t},r)),isActive:n,shapeType:`symbols`},r)):Y.createElement(L,Z({option:t,isActive:n,shapeType:`symbols`},r))}var Je=W([(e,t,n,r,i,a,o)=>te(e,void 0,void 0,o),(e,t,n,r,i,a,o)=>N(e,`xAxis`,t,o),(e,t,n,r,i,a,o)=>F(e,`xAxis`,t,o),(e,t,n,r,i,a,o)=>N(e,`yAxis`,n,o),(e,t,n,r,i,a,o)=>F(e,`yAxis`,n,o),(e,t,n,r)=>O(e,`zAxis`,r,!1),W([T,(e,t,n,r,i)=>i],(e,t)=>e.filter(e=>e.type===`scatter`).find(e=>e.id===t)),(e,t,n,r,i,a)=>a],(e,t,n,r,i,a,o,s)=>{var{chartData:c,dataStartIndex:l,dataEndIndex:u}=e;if(o!=null){var d=o?.data!=null&&o.data.length>0?o.data:c?.slice(l,u+1);if(!(d==null||t==null||r==null||n==null||i==null||n?.length===0||i?.length===0))return ut({displayedData:d,xAxis:t,yAxis:r,zAxis:a,scatterSettings:o,xAxisTicks:n,yAxisTicks:i,cells:s})}}),Ye=[`id`],Xe=[`onMouseEnter`,`onClick`,`onMouseLeave`],Ze=[`animationBegin`,`animationDuration`,`animationEasing`,`hide`,`isAnimationActive`,`legendType`,`lineJointType`,`lineType`,`shape`,`xAxisId`,`yAxisId`,`zAxisId`];function Qe(e,t){if(e==null)return{};var n,r,i=$e(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function $e(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}function Q(){return Q=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},Q.apply(null,arguments)}function et(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function $(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?et(Object(n),!0).forEach(function(t){tt(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):et(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function tt(e,t,n){return(t=nt(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function nt(e){var t=rt(e,`string`);return typeof t==`symbol`?t:t+``}function rt(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}var it=e=>{var{dataKey:t,name:n,fill:r,legendType:i,hide:a}=e;return[{inactive:a,dataKey:t,type:i,color:r,value:V(n,t),payload:e}]},at=Y.memo(e=>{var{dataKey:t,points:n,stroke:r,strokeWidth:i,fill:a,name:o,hide:s,tooltipType:c,id:l}=e,u={dataDefinedOnItem:n?.map(e=>e.tooltipPayload),getPosition:e=>{var t;return n==null||(t=n[Number(e)])==null?void 0:t.tooltipPosition},settings:{stroke:r,strokeWidth:i,fill:a,nameKey:void 0,dataKey:t,name:V(o,t),hide:s,type:c,color:a,unit:``,graphicalItemId:l}};return Y.createElement(De,{tooltipEntrySettings:u})});function ot(e){var{points:t,props:n}=e,{line:r,lineType:i,lineJointType:a}=n;if(!r)return null;var o=ce(n),s=H(r),c,l;if(i===`joint`)c=t.map(e=>({x:e.cx??null,y:e.cy??null}));else if(i===`fitting`){var{xmin:u,xmax:d,a:f,b:p}=oe(t),m=e=>f*e+p;c=[{x:u,y:m(u)},{x:d,y:m(d)}]}var h=$($($({},o),{},{fill:`none`,stroke:o&&o.fill},s),{},{points:c});return l=Y.isValidElement(r)?Y.cloneElement(r,h):typeof r==`function`?r(h):Y.createElement(z,Q({},h,{type:a})),Y.createElement(q,{className:`recharts-scatter-line`,key:`recharts-scatter-line`},l)}function st(e){var{showLabels:t,points:n,children:r}=e,i=E(),a=(0,Y.useMemo)(()=>n?.map(e=>{var t={x:e.x??0,y:e.y??0,width:e.width,height:e.height,lowerWidth:e.width,upperWidth:e.width};return $($({},t),{},{value:void 0,payload:e.payload,viewBox:t,parentViewBox:i,fill:void 0})}),[i,n]);return Y.createElement(R,{value:t?a:void 0},r)}function ct(e){var{points:t,allOtherScatterProps:n}=e,{shape:r,activeShape:i,dataKey:a}=n,{id:o}=n,s=Qe(n,Ye),c=ge(de),{onMouseEnter:l,onClick:u,onMouseLeave:d}=n,f=Qe(n,Xe),p=ie(l,a,o),m=Oe(d),h=ke(u,a,o);if(!ve(t))return null;var g=ce(s);return Y.createElement(Y.Fragment,null,Y.createElement(ot,{points:t,props:s}),t.map((e,t)=>{var n=i!=null&&i!==!1,a=n&&c===String(t),s=n&&a?i:r,l=$($($({},g),e),{},{index:t,[k]:String(o)});return Y.createElement(x,{key:`symbol-${e?.cx}-${e?.cy}-${e?.size}-${t}`,zIndex:a?j.activeDot:void 0},Y.createElement(q,Q({className:`recharts-scatter-symbol`},re(f,e,t),{onMouseEnter:p(e,t),onMouseLeave:m(e,t),onClick:h(e,t)}),Y.createElement(qe,Q({option:s,isActive:a},l))))}))}function lt(e){var{previousPointsRef:t,props:n}=e,{points:r,isAnimationActive:i,animationBegin:a,animationDuration:o,animationEasing:s}=n,c=t.current,l=Ae(n,`recharts-scatter-`),[u,d]=(0,Y.useState)(!1),f=(0,Y.useCallback)(()=>{d(!1)},[]),p=(0,Y.useCallback)(()=>{d(!0)},[]),m=!u;return Y.createElement(st,{showLabels:m,points:r},n.children,Y.createElement(S,{animationId:l,begin:a,duration:o,isActive:i,easing:s,onAnimationEnd:f,onAnimationStart:p,key:l},e=>{var i=e===1?r:r?.map((t,n)=>{var r=c&&c[n];return r?$($({},t),{},{cx:t.cx==null?void 0:K(r.cx,t.cx,e),cy:t.cy==null?void 0:K(r.cy,t.cy,e),size:K(r.size,t.size,e)}):$($({},t),{},{size:K(0,t.size,e)})});return e>0&&(t.current=i),Y.createElement(q,null,Y.createElement(ct,{points:i,allOtherScatterProps:n,showLabels:m}))}),Y.createElement(w,{label:n.label}))}function ut(e){var{displayedData:t,xAxis:n,yAxis:r,zAxis:i,scatterSettings:a,xAxisTicks:o,yAxisTicks:s,cells:c}=e,l=J(n.dataKey)?a.dataKey:n.dataKey,u=J(r.dataKey)?a.dataKey:r.dataKey,d=i&&i.dataKey,f=i?i.range:M.range,p=f&&f[0],m=n.scale.bandwidth?n.scale.bandwidth():0,h=r.scale.bandwidth?r.scale.bandwidth():0;return t.map((e,t)=>{var f=I(e,l),g=I(e,u),_=!J(d)&&I(e,d)||`-`,v=[{name:J(n.dataKey)?a.name:n.name||String(n.dataKey),unit:n.unit||``,value:f,payload:e,dataKey:l,type:a.tooltipType,graphicalItemId:a.id},{name:J(r.dataKey)?a.name:r.name||String(r.dataKey),unit:r.unit||``,value:g,payload:e,dataKey:u,type:a.tooltipType,graphicalItemId:a.id}];_!==`-`&&i!=null&&v.push({name:i.name||i.dataKey,unit:i.unit||``,value:_,payload:e,dataKey:d,type:a.tooltipType,graphicalItemId:a.id});var y=B({axis:n,ticks:o,bandSize:m,entry:e,index:t,dataKey:l}),b=B({axis:r,ticks:s,bandSize:h,entry:e,index:t,dataKey:u}),x=_!==`-`&&i!=null?i.scale.map(_):p,S=x==null?0:Math.sqrt(Math.max(x,0)/Math.PI);return $($({},e),{},{cx:y,cy:b,x:y==null?void 0:y-S,y:b==null?void 0:b-S,width:2*S,height:2*S,size:x,node:{x:f,y:g,z:_},tooltipPayload:v,tooltipPosition:{x:y,y:b},payload:e},c&&c[t]&&c[t].props)})}var dt=(e,t,n)=>({x:e.cx,y:e.cy,value:Number(n===`x`?e.node.x:e.node.y),errorVal:I(e,t)});function ft(e){var{hide:t,points:n,className:r,needClip:i,xAxisId:a,yAxisId:o,id:s}=e,c=(0,Y.useRef)(null);if(t)return null;var l=m(`recharts-scatter`,r),u=s;return Y.createElement(x,{zIndex:e.zIndex},Y.createElement(q,{className:l,clipPath:i?`url(#clipPath-${u})`:void 0,id:s},i&&Y.createElement(`defs`,null,Y.createElement(_e,{clipPathId:u,xAxisId:a,yAxisId:o})),Y.createElement(ae,{xAxisId:a,yAxisId:o,data:n,dataPointFormatter:dt,errorBarOffset:0},Y.createElement(q,{key:`recharts-scatter-symbols`},Y.createElement(lt,{props:e,previousPointsRef:c})))))}var pt={xAxisId:0,yAxisId:0,zAxisId:0,label:!1,line:!1,legendType:`circle`,lineType:`joint`,lineJointType:`linear`,shape:`circle`,hide:!1,isAnimationActive:`auto`,animationBegin:0,animationDuration:400,animationEasing:`linear`,zIndex:j.scatter};function mt(e){var t=Se(e,pt),{animationBegin:n,animationDuration:r,animationEasing:i,hide:a,isAnimationActive:o,legendType:s,lineJointType:c,lineType:l,shape:u,xAxisId:d,yAxisId:f,zAxisId:p}=t,m=Qe(t,Ze),{needClip:h}=Ce(d,f),g=(0,Y.useMemo)(()=>C(e.children,ee),[e.children]),_=be(),v=ge(t=>Je(t,d,f,p,e.id,g,_));return h==null||v==null?null:Y.createElement(Y.Fragment,null,Y.createElement(at,{dataKey:e.dataKey,points:v,stroke:e.stroke,strokeWidth:e.strokeWidth,fill:e.fill,name:e.name,hide:e.hide,tooltipType:e.tooltipType,id:e.id}),Y.createElement(ft,Q({},m,{xAxisId:d,yAxisId:f,zAxisId:p,lineType:l,lineJointType:c,legendType:s,shape:u,hide:a,isAnimationActive:o,animationBegin:n,animationDuration:r,animationEasing:i,points:v,needClip:h})))}function ht(e){var t=Se(e,pt),n=be();return Y.createElement(G,{id:t.id,type:`scatter`},e=>Y.createElement(Y.Fragment,null,Y.createElement(ne,{legendPayload:it(t)}),Y.createElement(le,{type:`scatter`,id:e,data:t.data,xAxisId:t.xAxisId,yAxisId:t.yAxisId,zAxisId:t.zAxisId,dataKey:t.dataKey,hide:t.hide,name:t.name,tooltipType:t.tooltipType,isPanorama:n}),Y.createElement(mt,Q({},t,{id:e}))))}var gt=Y.memo(ht,D);gt.displayName=`Scatter`;function _t(e){var t=Ee(),n=(0,Y.useRef)(null);return(0,Y.useLayoutEffect)(()=>{n.current===null?t(se(e)):n.current!==e&&t(me({prev:n.current,next:e})),n.current=e},[e,t]),(0,Y.useLayoutEffect)(()=>()=>{n.current&&=(t(ye(n.current)),null)},[t]),null}var vt={zAxisId:0,range:M.range,scale:M.scale,type:M.type};function yt(e){var t=Se(e,vt);return Y.createElement(_t,{domain:t.domain,id:t.zAxisId,dataKey:t.dataKey,name:t.name,unit:t.unit,range:t.range,scale:t.scale,type:t.type,allowDuplicatedCategory:M.allowDuplicatedCategory,allowDataOverflow:M.allowDataOverflow,reversed:M.reversed,includeHidden:M.includeHidden})}yt.displayName=`ZAxis`;var bt=[`item`],xt=(0,Y.forwardRef)((e,t)=>Y.createElement(he,{chartName:`ScatterChart`,defaultTooltipEventType:`item`,validateTooltipEventTypes:bt,tooltipPayloadSearcher:fe,categoricalChartProps:e,ref:t}));function St({data:e,loading:t}){let{t:n}=s(`analytics`);if(t&&!e)return(0,X.jsx)(`div`,{className:`h-[220px] rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let r={jobs:n(`surfaces.job`),explore:n(`surfaces.exploreSpec`),quick:n(`surfaces.quickSpec`),refine:n(`surfaces.aiEdit`),fileSummaries:n(`surfaces.fileSummary`),smash:n(`surfaces.smash`),loop:n(`surfaces.loop`)},i=e.dailyTimeline.map(e=>({date:e.date.slice(5),[r.jobs]:e.jobsCostUsd,[r.explore]:e.exploreCostUsd,[r.quick]:e.quickCostUsd,[r.refine]:e.aiEditCostUsd,[r.fileSummaries]:e.fileSummaryCostUsd??0,[r.smash]:e.smashCostUsd??0,[r.loop]:e.loopCostUsd??0})),a=e.dailyTimeline.every(e=>e.jobsCostUsd+e.exploreCostUsd+e.quickCostUsd+e.aiEditCostUsd+(e.fileSummaryCostUsd??0)+(e.smashCostUsd??0)+(e.loopCostUsd??0)===0),o=e.dailyTimeline.reduce((e,t)=>e+(t.unpricedCount??0),0),c=a&&o>0,l=!a&&o>0;return(0,X.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,X.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider`,children:n(`timeline.title`)}),(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground/70`,children:l?n(`timeline.costPartiallyUnavailable`,{count:o}):n(`timeline.subtitle`)})]}),c?(0,X.jsx)(`div`,{"data-testid":`timeline-cost-unavailable`,className:`h-40 flex items-center justify-center text-xs text-muted-foreground/70`,children:n(`timeline.costUnavailable`)}):a?(0,X.jsx)(`div`,{className:`h-40 flex items-center justify-center text-xs text-muted-foreground/70`,children:n(`timeline.empty`)}):(0,X.jsx)(`div`,{className:`h-[220px]`,children:(0,X.jsx)(A,{width:`100%`,height:`100%`,children:(0,X.jsxs)(Te,{data:i,margin:{top:10,right:10,left:-8,bottom:0},children:[(0,X.jsx)(pe,{strokeDasharray:`2 4`,stroke:`currentColor`,className:`text-border/30`,vertical:!1}),(0,X.jsx)(ue,{dataKey:`date`,tick:{fontSize:10},stroke:`currentColor`,className:`text-muted-foreground`}),(0,X.jsx)(xe,{tick:{fontSize:10},stroke:`currentColor`,className:`text-muted-foreground`,tickFormatter:e=>`$${e}`}),(0,X.jsx)(P,{contentStyle:{backgroundColor:`var(--popover)`,border:`1px solid var(--border)`,fontSize:11,borderRadius:6},formatter:(e,t)=>[`$${typeof e==`number`?e.toFixed(2):`—`}`,String(t)]}),(0,X.jsx)(U,{dataKey:r.jobs,stackId:`a`,fill:`var(--accent-info, #5fa8d3)`}),(0,X.jsx)(U,{dataKey:r.explore,stackId:`a`,fill:`var(--accent-highlight, #c084fc)`}),(0,X.jsx)(U,{dataKey:r.quick,stackId:`a`,fill:`var(--accent-secondary, #f7768e)`}),(0,X.jsx)(U,{dataKey:r.refine,stackId:`a`,fill:`var(--accent-success, #50fa7b)`}),(0,X.jsx)(U,{dataKey:r.fileSummaries,stackId:`a`,fill:`var(--accent-warning, #f1fa8c)`}),(0,X.jsx)(U,{dataKey:r.smash,stackId:`a`,fill:`var(--accent-highlight, #c084fc)`}),(0,X.jsx)(U,{dataKey:r.loop,stackId:`a`,fill:`var(--accent-primary, #7aa2f7)`})]})})})]})}function Ct(e){return e==null?`—`:e<.005?`$${e.toFixed(4)}`:e<1?`$${e.toFixed(3)}`:`$${e.toFixed(2)}`}function wt(e){return e==null?`—`:e<1e3?`${e} ms`:e<6e4?`${(e/1e3).toFixed(1)}s`:`${Math.floor(e/6e4)}m ${Math.floor(e%6e4/1e3)}s`}function Tt({values:e}){let t=Math.max(1e-4,...e);return(0,X.jsx)(`div`,{className:`flex items-end gap-[1px] h-5`,children:e.map((e,n)=>(0,X.jsx)(`div`,{className:`w-[3px] rounded-sm bg-foreground/40`,style:{height:`${Math.max(2,e/t*20)}px`}},n))})}function Et({mode:e,label:t,accentClass:n}){let{t:r}=s(`analytics`),i=e.mode===`explore`&&e.totalRuns<5,a=(e.estimatedCostUsd??0)>0,c=e.avgCostPerSpec==null&&(e.unpricedCount??0)>0;return(0,X.jsxs)(`div`,{className:`flex-1 p-4 first:pr-2 last:pl-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,X.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full ${n}`}),(0,X.jsx)(`span`,{className:`text-xs font-medium uppercase tracking-wider text-muted-foreground`,children:t})]}),i?(0,X.jsxs)(`div`,{className:`py-3`,children:[(0,X.jsx)(`p`,{className:`text-sm text-foreground`,children:r(`quickVsExplore.sparseCta`)}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:r(`quickVsExplore.runsSoFar`,{count:e.totalRuns})})]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`text-3xl font-semibold tabular-nums tracking-tight`,"data-estimated":a?`true`:void 0,title:c?r(`quickVsExplore.costUnavailableTooltip`):a?r(`quickVsExplore.estimatedTooltip`):void 0,children:[a&&e.avgCostPerSpec!=null?`~`:``,Ct(e.avgCostPerSpec)]}),(0,X.jsx)(`div`,{className:`text-[11px] text-muted-foreground mt-0.5`,children:r(c?`quickVsExplore.costUnavailable`:`quickVsExplore.perSpec`)}),(0,X.jsx)(`div`,{className:`mt-3`,children:(0,X.jsx)(Tt,{values:e.sparkline.length>0?e.sparkline:[0]})}),(0,X.jsxs)(`div`,{className:`mt-3 space-y-0.5 text-xs tabular-nums text-muted-foreground`,children:[(0,X.jsx)(`div`,{children:(0,X.jsx)(o,{ns:`analytics`,i18nKey:`quickVsExplore.createdRuns`,values:{created:e.ticketsCreated,runs:e.totalRuns},components:{strong:(0,X.jsx)(`span`,{className:`text-foreground font-medium`})}})}),(0,X.jsx)(`div`,{children:r(`quickVsExplore.avgDuration`,{duration:wt(e.avgDurationMs)})}),(0,X.jsx)(`div`,{className:`truncate`,children:e.dominantModel??`—`})]})]})]})}function Dt({data:e,loading:t}){let{t:n}=s(`analytics`);if(t&&!e)return(0,X.jsx)(`div`,{className:`h-[220px] rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let r=e.byMode.find(e=>e.mode===`quick`),i=e.byMode.find(e=>e.mode===`explore`);if(!r||!i)return null;let a=r.avgCostPerSpec&&i.avgCostPerSpec&&r.avgCostPerSpec>0?i.avgCostPerSpec/r.avgCostPerSpec:null,o=a!==null&&r.totalRuns>=1&&i.totalRuns>=5,c=(r.estimatedCostUsd??0)>0||(i.estimatedCostUsd??0)>0;return(0,X.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40`,children:[(0,X.jsx)(`div`,{className:`px-4 pt-3 pb-1`,children:(0,X.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider`,children:n(`quickVsExplore.title`)})}),(0,X.jsxs)(`div`,{className:`flex divide-x divide-border/40`,children:[(0,X.jsx)(Et,{mode:r,label:n(`quickVsExplore.quick`),accentClass:`bg-accent-secondary`}),(0,X.jsx)(Et,{mode:i,label:n(`quickVsExplore.explore`),accentClass:`bg-accent-highlight`})]}),o&&(0,X.jsx)(`div`,{className:`px-4 pb-3 -mt-1`,children:(0,X.jsx)(`div`,{className:`text-center text-[11px] text-muted-foreground tabular-nums`,children:(0,X.jsxs)(`span`,{className:`px-2`,children:[`━━━━━━ `,n(`quickVsExplore.ratio`,{ratio:a.toFixed(1)}),` ━━━━━━`]})})}),c&&(0,X.jsx)(`div`,{className:`px-4 pb-3 -mt-1`,"data-testid":`quick-vs-explore-estimated-footnote`,children:(0,X.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:n(`quickVsExplore.estimatedFootnote`)})})]})}function Ot(e){return e<.005&&e>0?`$${e.toFixed(4)}`:e<1?`$${e.toFixed(3)}`:`$${e.toFixed(2)}`}function kt(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function At({data:e,loading:t}){let{t:n}=s(`analytics`),r=e?.agentMissions;if(t||!r||r.summary.turns===0)return null;let{summary:a,topConversations:o}=r,c=a.estimatedCostUsd>0,l=a.prevTotalCostUsd>0?(a.totalCostUsd-a.prevTotalCostUsd)/a.prevTotalCostUsd*100:null;return(0,X.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card p-4`,"data-testid":`agent-missions-card`,children:[(0,X.jsxs)(`div`,{className:`mb-3 flex items-center gap-2`,children:[(0,X.jsx)(u,{className:`h-4 w-4 text-accent-highlight`}),(0,X.jsx)(`h3`,{className:`text-sm font-medium`,children:n(`agentMissions.title`)}),(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:n(`agentMissions.subtitle`)})]}),(0,X.jsxs)(`div`,{className:`flex items-baseline gap-3`,children:[(0,X.jsxs)(`span`,{className:`text-3xl font-semibold tabular-nums tracking-tight`,"data-estimated":c?`true`:void 0,title:c?n(`agentMissions.estimatedNote`):void 0,children:[c?`~`:``,Ot(a.totalCostUsd)]}),l!==null&&(0,X.jsxs)(`span`,{className:l>0?`text-xs text-accent-warning`:`text-xs text-accent-success`,children:[l>0?`+`:``,l.toFixed(0),`% `,n(`agentMissions.vsPrev`)]})]}),(0,X.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:n(`agentMissions.turnsAndTokens`,{turns:a.turns,tokens:kt(a.tokensIn+a.tokensOut)})}),o.length>0&&(0,X.jsx)(`ul`,{className:`mt-3 space-y-1 border-t border-border/40 pt-2`,children:o.map(e=>(0,X.jsxs)(`li`,{className:`flex items-center gap-2 text-xs`,children:[(0,X.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-foreground/85`,children:e.title?.trim()||n(`agentMissions.untitled`)}),(0,X.jsxs)(`span`,{className:`shrink-0 text-[10px] text-muted-foreground`,children:[e.turns,` · `,e.lastAt?g(new Date(e.lastAt),{addSuffix:!0,locale:i()}):`—`]}),(0,X.jsxs)(`span`,{className:`shrink-0 tabular-nums font-medium`,children:[e.estimatedCostUsd>0?`~`:``,Ot(e.costUsd)]})]},e.conversationId??`unknown`))})]})}function jt({data:e,loading:t,onSelectModel:n,activeModel:r}){let{t:i}=s(`analytics`);if(t&&!e)return(0,X.jsx)(`div`,{className:`h-[220px] rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let a=e.summary.totalCostUsd,o=e.byModel.slice(0,5),c=o.reduce((e,t)=>e+t.costUsd,0),l=Math.max(0,a-c),u=l>=.005;return(0,X.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,X.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider mb-3`,children:i(`models.title`)}),o.length===0?(0,X.jsx)(`div`,{className:`h-32 flex items-center justify-center text-xs text-muted-foreground/70`,children:i(`models.empty`)}):(0,X.jsxs)(`ul`,{className:`space-y-1.5`,children:[o.map(e=>{let t=a>0?e.costUsd/a*100:0,o=r===e.model,s=(e.estimatedCostUsd??0)>0,c=e.unpricedCount??0,l=Math.max(0,e.count-c),u=e.count>0&&c>0&&l===0,d=l>0&&c>0;return(0,X.jsx)(`li`,{children:(0,X.jsxs)(`button`,{type:`button`,onClick:()=>n(e.model,e.provider),className:`w-full text-left group rounded-md px-2 py-1.5 transition-colors ${o?`bg-accent-highlight/10 ring-1 ring-accent-highlight/30`:`hover:bg-accent/30`}`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between text-[12px] mb-1 tabular-nums`,children:[(0,X.jsx)(`span`,{className:`truncate font-medium`,children:e.model}),(0,X.jsx)(`span`,{className:`text-muted-foreground`,"data-testid":u?`model-cost-unavailable`:void 0,title:u?i(`models.costUnavailableTooltip`):d?i(`models.costPartiallyUnavailableTooltip`):s?i(`models.estimatedTooltip`):void 0,children:u?i(`models.costUnavailableWithRuns`,{count:e.count}):(0,X.jsxs)(X.Fragment,{children:[s?`~`:``,`$`,e.costUsd.toFixed(2),` · `,e.count,d&&(0,X.jsx)(`span`,{className:`ml-1 italic`,children:i(`models.costPartiallyUnavailable`,{count:c})})]})})]}),(0,X.jsx)(`div`,{className:`h-1.5 rounded-full bg-background-deep overflow-hidden`,children:(0,X.jsx)(`div`,{className:`h-full ${o?`bg-accent-highlight`:`bg-foreground/40 group-hover:bg-foreground/60`} transition-colors`,style:{width:`${t}%`}})})]})},`${e.provider??`claude`}:${e.model}`)}),u&&(0,X.jsx)(`li`,{"data-testid":`model-others`,children:(0,X.jsxs)(`div`,{className:`w-full rounded-md px-2 py-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between text-[12px] mb-1 tabular-nums`,children:[(0,X.jsx)(`span`,{className:`truncate font-medium text-muted-foreground`,children:i(`models.others`)}),(0,X.jsxs)(`span`,{className:`text-muted-foreground`,children:[`$`,l.toFixed(2)]})]}),(0,X.jsx)(`div`,{className:`h-1.5 rounded-full bg-background-deep overflow-hidden`,children:(0,X.jsx)(`div`,{className:`h-full bg-foreground/25`,style:{width:`${a>0?l/a*100:0}%`}})})]})})]})]})}var Mt={job:`var(--accent-info, #5fa8d3)`,"quick-spec":`var(--accent-secondary, #f7768e)`,"explore-spec":`var(--accent-highlight, #c084fc)`,"ai-edit":`var(--accent-success, #50fa7b)`,smash:`var(--accent-highlight, #c084fc)`,"file-summary":`var(--accent-warning, #f1fa8c)`,loop:`var(--accent-primary, #7aa2f7)`,"chat-sidebar":`var(--accent-info, #5fa8d3)`,"spec-launcher":`var(--accent-secondary, #f7768e)`,proposal:`var(--accent-highlight, #c084fc)`,"agent-studio":`var(--accent-success, #50fa7b)`,setup:`var(--accent-primary, #7aa2f7)`},Nt=Object.keys(_);function Pt({data:e,loading:t,onSelectPoint:n}){let{t:r}=s(`analytics`);if(t&&!e)return(0,X.jsx)(`div`,{className:`h-[260px] rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let i=Nt,a=i.map(t=>({surface:t,points:e.scatter.filter(e=>e.surface===t).map(e=>({id:e.id,x:e.numTurns??Math.round((e.durationMs??0)/1e3),y:e.costUsd,surface:t,ticketId:e.ticketId,startedAt:e.startedAt,raw:e}))})),o=e.scatter.length===0,c=e.summary.unpricedRuns??0,l=o&&c>0,u=!o&&c>0,d=e.scatterTruncated===!0,f=e.scatterTotal??e.scatter.length;return(0,X.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,X.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider`,children:r(`scatter.title`)}),(0,X.jsx)(`div`,{className:`flex flex-wrap items-center gap-2 text-[10px]`,children:i.map(e=>(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,X.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full`,style:{background:Mt[e]}}),(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:_[e]})]},e))})]}),d&&!o&&(0,X.jsx)(`div`,{"data-testid":`scatter-truncation-notice`,className:`mb-2 text-[10px] text-accent-warning`,children:r(`scatter.truncated`,{shown:e.scatter.length,total:f})}),u&&(0,X.jsx)(`div`,{"data-testid":`scatter-cost-partial-notice`,className:`mb-2 text-[10px] text-muted-foreground/80 italic`,children:r(`scatter.costPartiallyUnavailable`,{count:c})}),l?(0,X.jsx)(`div`,{"data-testid":`scatter-cost-unavailable`,className:`h-40 flex items-center justify-center text-xs text-muted-foreground/70`,children:r(`scatter.costUnavailable`)}):o?(0,X.jsx)(`div`,{className:`h-40 flex items-center justify-center text-xs text-muted-foreground/70`,children:r(`scatter.empty`)}):(0,X.jsx)(`div`,{className:`h-[260px]`,children:(0,X.jsx)(A,{width:`100%`,height:`100%`,children:(0,X.jsxs)(xt,{margin:{top:10,right:10,left:-8,bottom:5},children:[(0,X.jsx)(pe,{strokeDasharray:`2 4`,stroke:`currentColor`,className:`text-border/30`}),(0,X.jsx)(ue,{type:`number`,dataKey:`x`,name:`turns`,tick:{fontSize:10},stroke:`currentColor`,className:`text-muted-foreground`,label:{value:r(`scatter.turnsLabel`),position:`insideBottomRight`,offset:-2,fontSize:10,fill:`currentColor`}}),(0,X.jsx)(xe,{type:`number`,dataKey:`y`,name:`cost`,tick:{fontSize:10},stroke:`currentColor`,className:`text-muted-foreground`,tickFormatter:e=>`$${e.toFixed(e<1?2:0)}`}),(0,X.jsx)(yt,{range:[40,80]}),(0,X.jsx)(P,{cursor:{strokeDasharray:`3 3`},contentStyle:{backgroundColor:`var(--popover)`,border:`1px solid var(--border)`,fontSize:11,borderRadius:6},formatter:(e,t)=>{let n=String(t);return n===`cost`&&typeof e==`number`?[`$${e.toFixed(3)}`,r(`scatter.costLabel`)]:[String(e),n===`turns`?r(`scatter.turnsLabel`):n]}}),a.map(e=>(0,X.jsx)(gt,{data:e.points,fill:Mt[e.surface],onClick:e=>{let t=e;t?.raw&&n(t.raw)}},e.surface))]})})})]})}function Ft({data:e,loading:t,onSelectTicket:n}){let{t:r}=s(`analytics`);if(t&&!e)return(0,X.jsx)(`div`,{className:`h-40 rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let i=e.topTickets;return(0,X.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,X.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider mb-3`,children:r(`topTickets.title`)}),i.length===0?(0,X.jsx)(`div`,{className:`h-32 flex items-center justify-center text-xs text-muted-foreground/70`,children:r(`topTickets.empty`)}):(0,X.jsx)(`ul`,{className:`divide-y divide-border/30`,children:i.map((e,t)=>{let i=Object.entries(e.bySurface).filter(([,e])=>e.count>0).map(([e,t])=>r(`topTickets.breakdownItem`,{n:t.count,label:_[e].toLowerCase()})).join(` + `),a=e.isUnattributed,o=a?r(`topTickets.unattributed`):e.ticketTitle?`#${e.ticketId} ${e.ticketTitle}`:r(`topTickets.deletedTicket`,{id:e.ticketId}),s=!e.ticketTitle&&!a?`opacity-50`:``,c=e.unpricedCount??0,l=e.totalRuns>0&&c===e.totalRuns,u=c>0&&!l;return(0,X.jsx)(`li`,{children:(0,X.jsxs)(`button`,{type:`button`,onClick:()=>n(e.ticketId),className:`w-full text-left flex items-center justify-between gap-3 py-2 px-1 hover:bg-accent/30 rounded transition-colors ${s}`,disabled:a,children:[(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`div`,{className:`text-sm truncate`,children:o}),(0,X.jsx)(`div`,{className:`text-[11px] text-muted-foreground truncate`,children:i||`—`})]}),(0,X.jsxs)(`div`,{className:`text-right tabular-nums`,children:[(0,X.jsx)(`div`,{className:`text-sm font-medium`,title:l?r(`topTickets.costUnavailableTooltip`):u?r(`topTickets.costPartiallyUnavailableTooltip`):void 0,children:l?r(`topTickets.costUnavailable`):`$${e.totalCostUsd.toFixed(2)}`}),u&&(0,X.jsx)(`div`,{className:`text-[10px] text-muted-foreground italic`,children:r(`topTickets.costPartiallyUnavailable`,{count:c})}),(0,X.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:r(`runs`,{count:e.totalRuns})})]})]})},`${e.ticketId??`u`}-${t}`)})})]})}var It={claude:`Claude`,codex:`Codex`,gemini:`Gemini`,kimi:`Kimi`};function Lt(e){return It[e]??e}function Rt(e){return e==null?`—`:e<.005?`$${e.toFixed(4)}`:`$${e.toFixed(2)}`}function zt(e){return e==null?`—`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function Bt(e){return e.surface_ref_id?.startsWith(`contract-refine:`)?!0:e.surface===`explore-spec`&&e.ticket_id!=null&&e.conversation_id!=null&&e.surface_ref_id===e.conversation_id&&e.model==null}function Vt(e){let t=new Map;for(let n of e)n.model&&(n.conversation_id&&t.set(`conversation:${n.conversation_id}`,n.model),n.ticket_id!=null&&n.surface===`explore-spec`&&t.set(`ticket:${n.ticket_id}:explore-spec`,n.model),n.ticket_id!=null&&n.surface===`quick-spec`&&t.set(`ticket:${n.ticket_id}:quick-spec`,n.model));return t}function Ht(e,t){if(e.model)return e.model;if(!Bt(e))return null;if(e.conversation_id){let n=t.get(`conversation:${e.conversation_id}`);if(n)return n}return e.ticket_id==null?null:t.get(`ticket:${e.ticket_id}:${e.surface}`)??null}function Ut({rows:e,loading:t,truncated:n,totalAvailable:r,tableFilters:i,onTableFiltersChange:a}){let{t:o}=s(`analytics`),[c,l]=(0,Y.useState)(null),u=Vt(e),d=new Set(e.map(e=>e.provider??`claude`)).size>1,f=n||r>e.length;return(0,X.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 mb-3`,children:[(0,X.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider`,children:o(`table.title`)}),(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-[11px]`,children:[(0,X.jsxs)(`select`,{value:i.status??``,onChange:e=>a({...i,status:e.target.value||void 0}),className:`h-7 px-2 rounded-md bg-background-deep border border-border/60 text-xs`,"aria-label":o(`table.statusFilterAria`),children:[(0,X.jsx)(`option`,{value:``,children:o(`table.allStatus`)}),(0,X.jsx)(`option`,{value:`success`,children:o(`table.success`)}),(0,X.jsx)(`option`,{value:`failed`,children:o(`table.failed`)}),(0,X.jsx)(`option`,{value:`aborted`,children:o(`table.aborted`)})]}),(0,X.jsx)(`input`,{type:`number`,step:`0.01`,min:`0`,placeholder:o(`table.minCostPlaceholder`),value:i.minCostUsd??``,onChange:e=>{let t=e.target.value===``?void 0:parseFloat(e.target.value);a({...i,minCostUsd:Number.isNaN(t)?void 0:t})},className:`h-7 w-24 px-2 rounded-md bg-background-deep border border-border/60 text-xs tabular-nums`,"aria-label":o(`table.minCostFilterAria`)})]})]}),t?(0,X.jsx)(`div`,{className:`h-32 rounded bg-card/30 animate-pulse`}):e.length===0?(0,X.jsx)(`div`,{className:`h-32 flex items-center justify-center text-xs text-muted-foreground/70`,children:o(`table.empty`)}):(0,X.jsx)(`div`,{className:`overflow-x-auto`,children:(0,X.jsxs)(`table`,{className:`w-full text-[12px] tabular-nums`,children:[(0,X.jsx)(`thead`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:(0,X.jsxs)(`tr`,{className:`text-left`,children:[(0,X.jsx)(`th`,{className:`font-medium px-2 py-2`,children:o(`table.colSurface`)}),(0,X.jsx)(`th`,{className:`font-medium px-2 py-2`,children:o(`table.colTicket`)}),(0,X.jsx)(`th`,{className:`font-medium px-2 py-2 text-right`,children:o(`table.colCost`)}),(0,X.jsx)(`th`,{className:`font-medium px-2 py-2 text-right`,children:o(`table.colTurns`)}),(0,X.jsx)(`th`,{className:`font-medium px-2 py-2 text-right`,children:o(`table.colTokens`)}),(0,X.jsx)(`th`,{className:`font-medium px-2 py-2`,children:o(`table.colModel`)}),d&&(0,X.jsx)(`th`,{className:`font-medium px-2 py-2`,children:o(`table.colProvider`)}),(0,X.jsx)(`th`,{className:`font-medium px-2 py-2`,children:o(`table.colStatus`)}),(0,X.jsx)(`th`,{className:`font-medium px-2 py-2`,children:o(`table.colStarted`)})]})}),(0,X.jsx)(`tbody`,{children:e.map(e=>{let t=e.surface,n=v[t],r=(e.tokens_in??0)+(e.tokens_out??0)+(e.tokens_cache_read??0)+(e.tokens_cache_create??0),i=Bt(e),a=i?o(`table.contractLayer`):_[t],s=Ht(e,u);return(0,X.jsxs)(`tr`,{onClick:()=>l(c===e.id?null:e.id),className:`border-t border-border/30 hover:bg-accent/30 cursor-pointer`,children:[(0,X.jsx)(`td`,{className:`px-2 py-2`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 px-2 h-5 rounded-full text-[10px] font-medium ${n.bg} ${n.text}`,children:[(0,X.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full ${n.dot}`}),a]})}),(0,X.jsx)(`td`,{className:`px-2 py-2 max-w-[260px]`,children:e.ticket_id==null?e.ticket_title?(0,X.jsx)(`span`,{className:`truncate block text-muted-foreground/90 italic`,title:o(`table.provisionalTitleTooltip`),children:e.ticket_title}):(0,X.jsx)(`span`,{className:`text-muted-foreground/70`,children:`—`}):(0,X.jsxs)(`span`,{className:`truncate block`,children:[`#`,e.ticket_id,` `,i?(0,X.jsx)(`span`,{className:`text-muted-foreground/90`,children:o(`table.contractLayerRefinement`)}):e.ticket_title??(0,X.jsx)(`span`,{className:`text-muted-foreground/70 italic`,children:o(`table.deleted`)})]})}),(0,X.jsx)(`td`,{className:`px-2 py-2 text-right font-medium`,children:e.total_cost_usd_estimated===1&&e.total_cost_usd!=null?(0,X.jsxs)(`span`,{title:o(`table.estimatedCostTooltip`),className:`text-muted-foreground/90`,children:[`~`,Rt(e.total_cost_usd)]}):Rt(e.total_cost_usd)}),(0,X.jsx)(`td`,{className:`px-2 py-2 text-right`,children:zt(e.num_turns)}),(0,X.jsx)(`td`,{className:`px-2 py-2 text-right`,children:r>0?zt(r):`—`}),(0,X.jsxs)(`td`,{className:`px-2 py-2 max-w-[180px] truncate`,children:[s??`—`,s&&!e.model?(0,X.jsx)(`span`,{className:`ml-1 text-[10px] text-muted-foreground/70`,children:o(`table.inferred`)}):null]}),d&&(0,X.jsx)(`td`,{className:`px-2 py-2 text-muted-foreground`,children:Lt(e.provider??`claude`)}),(0,X.jsxs)(`td`,{className:`px-2 py-2`,children:[e.status===`success`?(0,X.jsx)(`span`,{className:`text-accent-success/90`,children:`●`}):e.status===`failed`?(0,X.jsx)(`span`,{className:`text-accent-warning`,children:`⚠`}):(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`○`}),(0,X.jsx)(`span`,{className:`ml-1 text-muted-foreground`,children:o(`table.statusValue.${e.status}`)})]}),(0,X.jsx)(`td`,{className:`px-2 py-2 text-muted-foreground`,children:e.started_at.slice(0,16).replace(`T`,` `)})]},e.id)})})]})}),f&&e.length>0&&(0,X.jsx)(`div`,{className:`mt-2 text-[11px] text-muted-foreground/80`,children:o(`table.truncated`,{shown:e.length,total:r.toLocaleString()})})]})}var Wt=[{value:`7d`,labelKey:`periods.d7`},{value:`30d`,labelKey:`periods.d30`},{value:`90d`,labelKey:`periods.d90`},{value:`all`,labelKey:`periods.all`}],Gt=[{value:`all`,labelKey:`page.all`},{value:`job`,labelKey:`surfaces.job`},{value:`explore-spec`,labelKey:`surfaces.exploreSpec`},{value:`quick-spec`,labelKey:`surfaces.quickSpec`},{value:`ai-edit`,labelKey:`surfaces.aiEdit`},{value:`smash`,labelKey:`surfaces.smash`},{value:`file-summary`,labelKey:`surfaces.fileSummary`},{value:`loop`,labelKey:`surfaces.loop`}];function Kt(e){let t=new URLSearchParams;return e.period&&t.set(`period`,e.period),e.from&&t.set(`from`,e.from),e.to&&t.set(`to`,e.to),e.surface&&e.surface.length>0&&t.set(`surface`,e.surface.join(`,`)),e.provider&&e.provider.length>0&&t.set(`provider`,e.provider.join(`,`)),e.model&&e.model.length>0&&t.set(`model`,e.model.join(`,`)),e.modelKeys&&e.modelKeys.length>0&&e.model&&e.modelKeys.length===e.model.length&&t.set(`modelProvider`,e.modelKeys.map(e=>e.provider).join(`,`)),e.status&&t.set(`status`,e.status),typeof e.minCostUsd==`number`&&t.set(`minCostUsd`,String(e.minCostUsd)),typeof e.ticketId==`number`&&t.set(`ticketId`,String(e.ticketId)),typeof e.tzOffsetMinutes==`number`&&t.set(`tzOffsetMinutes`,String(e.tzOffsetMinutes)),e.sortBy&&t.set(`sortBy`,e.sortBy),t.toString()}function qt(){let{t:e}=s(`analytics`),{activeProjectId:t,projects:n}=p(),[i,o]=r(),c=n.find(e=>e.id===t),l=c?f(c):[`claude`],u=l.length>1,m=i.get(`period`)??`30d`,g=(i.get(`surface`)??``).split(`,`).filter(Boolean),_=(i.get(`provider`)??``).split(`,`).filter(Boolean),v=i.get(`ticketId`),x=(i.get(`model`)??``).split(`,`).filter(Boolean),S=(i.get(`modelProvider`)??``).split(`,`).filter(Boolean),C=x.length>0&&x.length===S.length?x.map((e,t)=>({provider:S[t],model:e})):void 0,ee=(0,Y.useMemo)(()=>-new Date().getTimezoneOffset(),[]),[w,T]=(0,Y.useState)({period:m,surface:g.length>0?g:void 0,provider:_.length>0?_:void 0,ticketId:v?Number(v):void 0,model:x.length>0?x:void 0,modelKeys:C,tzOffsetMinutes:ee}),[E,D]=(0,Y.useState)(null),[O,k]=(0,Y.useState)(!0),[A,j]=(0,Y.useState)(null),[M,N]=(0,Y.useState)({}),[P,F]=(0,Y.useState)(null),[I,te]=(0,Y.useState)(`recency`),L=(0,Y.useRef)(new Map),R=(0,Y.useRef)(0);(0,Y.useEffect)(()=>{let e=new URLSearchParams;e.set(`period`,w.period),w.surface&&w.surface.length>0&&e.set(`surface`,w.surface.join(`,`)),w.provider&&w.provider.length>0&&e.set(`provider`,w.provider.join(`,`)),w.ticketId&&e.set(`ticketId`,String(w.ticketId)),w.model&&w.model.length>0&&(e.set(`model`,w.model.join(`,`)),w.modelKeys&&w.modelKeys.length===w.model.length&&e.set(`modelProvider`,w.modelKeys.map(e=>e.provider).join(`,`))),o(e,{replace:!0})},[w.period,w.surface,w.provider,w.ticketId,w.model,w.modelKeys,o]);let z=(0,Y.useCallback)(async()=>{if(!t)return;let e=++R.current;j(null);let n=`${t}:${Kt(w)}`,r=L.current.get(n);r?(D(r),k(!1)):k(!0);try{let t=await fetch(`${d()}/spending?${Kt(w)}`);if(!t.ok)throw Error(`HTTP ${t.status}`);if(e!==R.current)return;let r=await t.json();L.current.set(n,r),D(r),k(!1)}catch(t){if(e!==R.current)return;j(t.message),k(!1)}},[t,w]),B=(0,Y.useRef)(0),V=(0,Y.useCallback)(async()=>{if(!t)return;let e=++B.current,n={...w};M.model&&(n.model=[M.model],n.modelKeys=void 0),M.status&&(n.status=M.status),typeof M.minCostUsd==`number`&&(n.minCostUsd=M.minCostUsd),n.sortBy=I;try{let t=await fetch(`${d()}/invocations?${Kt(n)}&limit=100`);if(!t.ok)throw Error(`HTTP ${t.status}`);let r=await t.json();if(e!==B.current)return;F(r)}catch{if(e!==B.current)return;F(null)}},[t,w,M,I]),ne=(0,Y.useRef)(t);(0,Y.useEffect)(()=>{ne.current!==t&&(ne.current=t,D(null),F(null),k(!0))},[t]),(0,Y.useEffect)(()=>{z()},[z]),(0,Y.useEffect)(()=>{V()},[V]);let H=(0,Y.useRef)(null),U=a();(0,Y.useEffect)(()=>{let e=`analytics-spending`;return U.registerHandler(e,e=>{let n=e;n.type===`spending.invalidated`&&n.projectId===t&&(H.current&&clearTimeout(H.current),H.current=setTimeout(()=>{L.current.clear(),z(),V()},500))}),()=>{U.unregisterHandler(e),H.current&&clearTimeout(H.current)}},[U,t,z,V]);function re(e){if(e===`all`){T(e=>({...e,surface:void 0}));return}T(t=>{let n=t.surface??[],r=n.includes(e)?n.filter(t=>t!==e):[...n,e];return{...t,surface:r.length>0?r:void 0}})}let ie=(0,Y.useCallback)((e,t)=>{T(n=>{if(n.model?.length===1&&n.model[0]===e&&(t===void 0||n.modelKeys?.length===1&&n.modelKeys[0].provider===t))return{...n,model:void 0,modelKeys:void 0};let r=(E?.byModel??[]).filter(n=>n.model===e&&(t===void 0||n.provider===t)).map(e=>({provider:e.provider,model:e.model})),i=r.length>0?r.map(e=>e.model):[e];return{...n,model:i,modelKeys:r.length>0?r:void 0}})},[E]);function ae(){T(e=>({...e,model:void 0,modelKeys:void 0}))}function oe(e){if(e===`all`){T(e=>({...e,provider:void 0}));return}T(t=>{let n=t.provider??[],r=n.includes(e)?n.filter(t=>t!==e):[...n,e];return{...t,provider:r.length>0?r:void 0}})}let W=w.surface,se=!W||W.length===0,G=w.provider,ce=!G||G.length===0,le=(0,Y.useMemo)(()=>{let e={period:w.period};return w.surface&&w.surface.length>0&&(e.surface=w.surface.join(`,`)),w.provider&&w.provider.length>0&&(e.provider=w.provider.join(`,`)),w.ticketId&&(e.ticketId=String(w.ticketId)),e},[w]),ue=E?E.summary.totalRuns===0:!1;return(0,X.jsxs)(`div`,{className:`flex flex-col gap-6 p-4 pb-12`,children:[(0,X.jsxs)(`div`,{className:`sticky top-0 z-10 -mx-4 px-4 py-3 bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/80 border-b border-border/40`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,X.jsx)(`h1`,{className:`text-base font-semibold tracking-tight`,children:e(`page.title`)}),w.ticketId&&(0,X.jsx)(`button`,{type:`button`,onClick:()=>T(e=>({...e,ticketId:void 0})),className:`inline-flex items-center gap-1 h-6 px-2 rounded-full text-[11px] font-medium bg-accent-highlight/15 text-accent-highlight ring-1 ring-accent-highlight/30 hover:bg-accent-highlight/25`,children:e(`page.ticketChip`,{id:w.ticketId})}),w.model&&w.model.length>0&&(0,X.jsxs)(`button`,{type:`button`,"data-testid":`analytics-model-chip`,onClick:ae,title:e(`page.clearModelFilter`),className:`inline-flex items-center gap-1 h-6 px-2 rounded-full text-[11px] font-medium bg-accent-highlight/15 text-accent-highlight ring-1 ring-accent-highlight/30 hover:bg-accent-highlight/25`,children:[e(`page.modelChip`,{model:w.model[0]}),(0,X.jsx)(`span`,{"aria-hidden":!0,className:`opacity-70`,children:`×`})]})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`div`,{className:`flex items-center gap-1 rounded-md border border-border/60 bg-card/40 p-0.5`,children:Wt.map(t=>(0,X.jsx)(`button`,{type:`button`,onClick:()=>T(e=>({...e,period:t.value})),className:`px-2.5 h-6 rounded text-[11px] font-medium transition-colors ${w.period===t.value?`bg-accent text-foreground`:`text-muted-foreground hover:text-foreground`}`,children:e(t.labelKey)},t.value))}),(0,X.jsx)(b,{baseUrl:`${d()}/analytics/export`,params:le,disabled:ue}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>{L.current.clear(),z(),V()},className:`h-7 w-7 inline-flex items-center justify-center rounded-md border border-border/60 bg-card/50 text-muted-foreground hover:text-foreground hover:bg-accent/60`,title:e(`common:actions.refresh`),children:(0,X.jsx)(y,{className:`w-3 h-3`})})]})]}),(0,X.jsx)(`div`,{className:`mt-3 flex flex-wrap items-center gap-1.5`,children:Gt.map(t=>(0,X.jsx)(`button`,{type:`button`,onClick:()=>re(t.value),className:`h-7 px-3 rounded-full text-[11px] font-medium transition-all ${(t.value===`all`?se:W?.includes(t.value)??!1)?`bg-foreground/10 text-foreground ring-1 ring-foreground/20`:`text-muted-foreground hover:text-foreground hover:bg-accent/40`}`,children:e(t.labelKey)},t.value))}),u&&(0,X.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-1.5`,"data-testid":`analytics-provider-chips`,children:[(0,X.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-muted-foreground/70 mr-1`,children:e(`page.engine`)}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>oe(`all`),className:`h-7 px-3 rounded-full text-[11px] font-medium transition-all ${ce?`bg-foreground/10 text-foreground ring-1 ring-foreground/20`:`text-muted-foreground hover:text-foreground hover:bg-accent/40`}`,children:e(`page.all`)}),l.map(e=>(0,X.jsx)(`button`,{type:`button`,onClick:()=>oe(e),className:`h-7 px-3 rounded-full text-[11px] font-medium transition-all ${G?.includes(e)??!1?`bg-foreground/10 text-foreground ring-1 ring-foreground/20`:`text-muted-foreground hover:text-foreground hover:bg-accent/40`}`,children:h(e)},e))]})]}),A&&(0,X.jsxs)(`div`,{className:`rounded-lg border border-accent-warning/30 bg-accent-warning/10 p-4 flex items-center justify-between`,children:[(0,X.jsx)(`p`,{className:`text-sm text-accent-warning`,children:e(`page.failedToLoad`,{error:A})}),(0,X.jsxs)(`button`,{onClick:()=>z(),className:`flex items-center gap-1.5 h-7 px-3 rounded-md text-xs text-accent-warning border border-accent-warning/30 hover:bg-accent-warning/10`,children:[(0,X.jsx)(y,{className:`w-3 h-3`}),e(`common:actions.retry`)]})]}),(0,X.jsx)(Ie,{data:E,loading:O,period:w.period}),(0,X.jsx)(He,{data:E,loading:O}),(0,X.jsx)(St,{data:E,loading:O}),(0,X.jsx)(At,{data:E,loading:O}),(0,X.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4`,children:[(0,X.jsx)(Dt,{data:E,loading:O}),(0,X.jsx)(jt,{data:E,loading:O,onSelectModel:ie,activeModel:w.model?.[0]})]}),(0,X.jsx)(Pt,{data:E,loading:O,onSelectPoint:e=>{N(e=>({...e})),T(t=>({...t,ticketId:e.ticketId??void 0}))}}),(0,X.jsx)(Ft,{data:E,loading:O,onSelectTicket:e=>T(t=>({...t,ticketId:e??void 0}))}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-end gap-1.5`,"data-testid":`analytics-table-sort`,children:[(0,X.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-muted-foreground/70 mr-1`,children:e(`table.sortLabel`)}),[`recency`,`cost`].map(t=>(0,X.jsx)(`button`,{type:`button`,"data-testid":`analytics-table-sort-${t}`,"aria-pressed":I===t,onClick:()=>te(t),className:`h-6 px-2.5 rounded-full text-[11px] font-medium transition-all ${I===t?`bg-foreground/10 text-foreground ring-1 ring-foreground/20`:`text-muted-foreground hover:text-foreground hover:bg-accent/40`}`,children:e(t===`recency`?`table.sortRecency`:`table.sortCost`)},t))]}),(0,X.jsx)(Ut,{rows:P?.rows??[],loading:O&&!P,truncated:(P?.truncated??!1)||(P?.totalAvailable??0)>(P?.rows.length??0),totalAvailable:P?.totalAvailable??0,tableFilters:M,onTableFiltersChange:N})]})]})}export{qt as default};
|
|
@@ -0,0 +1,2 @@
|
|
|
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{w as s}from"./i18n-DwgvwTnx.js";import{n as c,t as l}from"./createLucideIcon-Bjbbp_KS.js";import{n as u}from"./dist-bVqfYmby.js";import{X as d,et as f,nt as p,o as m,tt as h}from"./TicketDetailModal-BvZoyDAL.js";import{c as g,l as _,u as v}from"./MinimizedChatsContext-CcjBHMHd.js";import{n as y,t as b}from"./file-text-BcLCfcWZ.js";import{t as x}from"./sparkles-DrY8hb0X.js";import{t as S}from"./x-CBMI9ejn.js";import{a as C,i as w,r as T}from"./useDesktop-BzX769yH.js";import{c as E,s as D}from"./dialog-CdWCb02j.js";import{t as O}from"./utils-BC4DHlz2.js";import{c as k}from"./provider-capabilities-Doej9lfa.js";import{n as A,t as j}from"./lib-CGdyxIWg.js";import{Ct as M,bt as N,v as P,xt as F}from"./index-DhjjFyU5.js";var I=l(`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`}]]),L=e(t(),1),R=e(r(),1);function z(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 B(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 V(e,t){if(e===void 0)throw Error(`Unexpected undefined${t?`: ${t}`:``}`);return e}var ee=(e,t)=>Math.abs(e-t)<1.01,te=(e,t,n)=>{let r;return function(...i){e.clearTimeout(r),r=e.setTimeout(()=>t.apply(this,i),n)}},H,ne=()=>{if(H!==void 0)return H;if(typeof navigator>`u`)return H=!1;if(/iP(hone|od|ad)/.test(navigator.userAgent))return H=!0;let e=navigator.maxTouchPoints;return H=navigator.platform===`MacIntel`&&e!==void 0&&e>0},re=e=>{let{offsetWidth:t,offsetHeight:n}=e;return{width:t,height:n}},ie=e=>e,ae=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},oe=(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(re(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(re(n))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(r):r()});return a.observe(n,{box:`border-box`}),()=>{a.unobserve(n)}},U={passive:!0},W=typeof window>`u`||`onscrollend`in window,G=(e,t,n)=>{let r=e.scrollElement;if(!r)return;let i=e.targetWindow;if(!i)return;let a=e.options.useScrollendEvent&&W,o=0,s=a?null:te(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,U),a&&r.addEventListener(`scrollend`,u,U),()=>{r.removeEventListener(`scroll`,l),a&&r.removeEventListener(`scrollend`,u)}},se=(e,t)=>G(e,t,t=>{let{horizontal:n,isRtl:r}=e.options;return n?t.scrollLeft*(r&&-1||1):t.scrollTop}),ce=(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`]},K=(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})},q=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:ie,rangeExtractor:ae,onChange:()=>{},measureElement:ce,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=B(()=>(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,!(!ne()||this.targetWindow==null)&&(this._iosJustTouchEnded=!0,this._iosTouchEndTimerId=this.targetWindow.setTimeout(()=>{this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._flushIosDeferredIfReady()},150))};e.addEventListener(`touchstart`,t,U),e.addEventListener(`touchend`,n,U),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=B(()=>[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=B(()=>[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=z(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=B(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(e,t,n,r)=>this.range=e.length>0&&t>0?Y({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=B(()=>{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))&&(ne()&&(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=B(()=>[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 V(t[J(0,t.length-1,r?e=>n[e*2]:e=>V(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&&ee(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()}},J=(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 Y({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=J(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 X=typeof document<`u`?L.useLayoutEffect:L.useEffect;function le({useFlushSync:e=!0,...t}){let n=L.useReducer(e=>e+1,0)[1],r={...t,onChange:(r,i)=>{var a;e&&i?(0,R.flushSync)(n):n(),(a=t.onChange)==null||a.call(t,r,i)}},[i]=L.useState(()=>new q(r));return i.setOptions(r),X(()=>i._didMount(),[]),X(()=>i._willUpdate()),i}function ue(e){return le({observeElementRect:oe,observeElementOffset:se,scrollToFn:K,...e})}var Z=n(),de=e=>`specrails-desktop:code-tree-filter:${e}`,fe=e=>`specrails-desktop:code-tree-collapsed:${e}`;function pe(e){return e.split(`/`).length-1}function me(e){let t=e.lastIndexOf(`/`);return t>=0?e.slice(t+1):e}function he(e){return e?e.length>10?e.slice(0,10):e:null}function ge(e){return e===`created`?`added`:e===`modified`?`changed`:e===`deleted`?`deleted`:null}function _e(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 ve({onOpenFile:e,selectedPath:t,filterJobId:n,filterTicketId:r}){let{t:i}=c(`code`),{activeProjectId:a}=T(),{openTicketDetail:o}=m(),{registerHandler:l,unregisterHandler:u}=s(),[d,p]=(0,L.useState)(()=>{if(!a)return`touched-by-ai`;try{let e=localStorage.getItem(de(a));if(e===`all`||e===`touched-by-ai`)return e}catch{}return`touched-by-ai`});(0,L.useEffect)(()=>{if(a)try{localStorage.setItem(de(a),d)}catch{}},[d,a]);let[h,g]=(0,L.useState)(()=>{if(!a)return new Set;try{let e=localStorage.getItem(fe(a));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,L.useEffect)(()=>{if(a)try{localStorage.setItem(fe(a),JSON.stringify([...h]))}catch{}},[h,a]);let _=(0,L.useCallback)(e=>{g(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),b=(0,L.useCallback)(()=>{g(new Set)},[]),{data:x,refresh:S,isFirstLoad:E}=w({namespace:`code-tree:${d}:${d===`touched-by-ai`?`${n??`all-jobs`}:${r??`all-specs`}`:`all`}`,projectId:a,initialValue:[],fetcher:(0,L.useCallback)(async()=>{let e=[],t=null;for(let i=0;i<100;i+=1){let i=new URLSearchParams({withProvenance:`1`,filter:d});d===`touched-by-ai`&&n&&i.set(`jobId`,n),d===`touched-by-ai`&&typeof r==`number`&&i.set(`ticketId`,String(r)),t&&i.set(`cursor`,t);let a=await fetch(`${C()}/code/tree?${i.toString()}`);if(!a.ok)break;let o=await a.json().catch(()=>({}));if(Array.isArray(o.entries)&&e.push(...o.entries),!o.nextCursor)break;t=o.nextCursor}return e},[d,n,r])}),D=(0,L.useRef)(a);(0,L.useEffect)(()=>{D.current=a},[a]),(0,L.useEffect)(()=>{if(!a)return;let e=`code-tree-${a}`;return l(e,e=>{let t=e;t.projectId===D.current&&t.type===`file.provenance_updated`&&S()}),()=>u(e)},[a,l,u,S]);let k=(0,L.useRef)(null),A=(0,L.useMemo)(()=>(x??[]).filter(e=>!_e(e.path,h)),[x,h]),j=(0,L.useCallback)(()=>{g(new Set((x??[]).filter(e=>e.kind===`dir`).map(e=>e.path)))},[x]),P=ue({count:A.length,getScrollElement:()=>k.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()=>{}}}),I=A.length===0,R=(0,L.useMemo)(()=>(x??[]).filter(e=>e.kind===`file`).length,[x]);return(0,Z.jsxs)(`div`,{className:`flex flex-col h-full`,"data-testid":`file-tree`,children:[(0,Z.jsxs)(`div`,{className:`px-2 py-2 border-b border-border text-xs space-y-2`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:()=>p(`touched-by-ai`),className:O(`px-2 py-1 rounded-md transition-colors`,d===`touched-by-ai`?`bg-accent-primary/20 text-accent-primary`:`text-muted-foreground hover:text-foreground hover:bg-muted/50`),"aria-pressed":d===`touched-by-ai`,children:i(n?`tree.jobFiles`:r?`tree.specFiles`:`tree.touchedByAi`)}),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>p(`all`),className:O(`px-2 py-1 rounded-md transition-colors`,d===`all`?`bg-accent-primary/20 text-accent-primary`:`text-muted-foreground hover:text-foreground hover:bg-muted/50`),"aria-pressed":d===`all`,children:i(`tree.allFiles`)}),(0,Z.jsx)(`div`,{className:`flex-1`}),(0,Z.jsx)(`button`,{type:`button`,onClick:j,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,Z.jsx)(y,{className:`w-3.5 h-3.5`})}),(0,Z.jsx)(`button`,{type:`button`,onClick:b,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,Z.jsx)(v,{className:`w-3.5 h-3.5`})})]}),d===`touched-by-ai`&&R>0&&(0,Z.jsx)(`div`,{className:`flex items-center justify-between gap-2 text-[11px] text-muted-foreground`,children:(0,Z.jsx)(`span`,{children:i(`tree.touchedCount`,{count:R})})})]}),I&&E?(0,Z.jsx)(`div`,{className:`flex-1 flex items-center justify-center px-4 text-center`,"data-testid":`file-tree-loading`,children:(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground animate-pulse`,children:i(`tree.loadingFiles`)})}):I&&d===`touched-by-ai`?(0,Z.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center px-4 text-center gap-3`,children:[(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i(`tree.emptyTouched`)}),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>p(`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`)})]}):I?(0,Z.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-xs text-muted-foreground px-4 text-center`,children:i(`tree.noFiles`)}):(0,Z.jsx)(`div`,{ref:k,className:`flex-1 overflow-auto`,"data-testid":`file-tree-scroller`,children:(0,Z.jsx)(`div`,{style:{height:P.getTotalSize(),position:`relative`,width:`100%`},children:P.getVirtualItems().map(n=>{let r=A[n.index],a=pe(r.path)*12,s=r.kind===`file`&&r.path===t,c=r.provenance?.createdByTicketId,l=r.provenance?.modifiedByTicketIds??[],u=r.provenance?.latest??null,d=he(u?.jobId),p=ge(u?.kind),m=r.kind===`dir`,g=m&&h.has(r.path),b=r.provenance?.touchedFileCount??0;return(0,Z.jsxs)(`div`,{style:{position:`absolute`,top:0,left:0,transform:`translateY(${n.start}px)`,height:n.size,width:`100%`},className:O(`flex items-center gap-2 px-2 text-xs cursor-pointer hover:bg-muted/50`,s&&`bg-muted text-foreground`),onClick:()=>{m?_(r.path):e(r.path)},onKeyDown:t=>{t.target===t.currentTarget&&(t.key!==`Enter`&&t.key!==` `||(t.preventDefault(),m?_(r.path):e(r.path)))},role:`button`,tabIndex:0,"aria-expanded":m?!g:void 0,"data-testid":`file-tree-row-${r.path}`,children:[(0,Z.jsxs)(`span`,{style:{paddingLeft:a},className:`flex items-center gap-1 min-w-0 flex-1`,children:[m?(0,Z.jsxs)(Z.Fragment,{children:[g?(0,Z.jsx)(y,{className:`w-3 h-3 text-muted-foreground flex-shrink-0`}):(0,Z.jsx)(v,{className:`w-3 h-3 text-muted-foreground flex-shrink-0`}),g?(0,Z.jsx)(N,{className:`w-3.5 h-3.5 text-accent-info flex-shrink-0`}):(0,Z.jsx)(F,{className:`w-3.5 h-3.5 text-accent-info flex-shrink-0`})]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`span`,{className:`w-3 flex-shrink-0`}),(0,Z.jsx)(M,{className:`w-3.5 h-3.5 text-muted-foreground flex-shrink-0`})]}),(0,Z.jsx)(`span`,{className:`truncate ml-0.5`,children:me(r.path)})]}),(0,Z.jsxs)(`span`,{className:`flex items-center gap-1 flex-shrink-0`,children:[m&&b>0&&(0,Z.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted/60 text-muted-foreground`,title:i(`tree.folderTouched`,{count:b}),children:b}),!m&&p&&(0,Z.jsx)(`span`,{className:O(`text-[10px] px-1.5 py-0.5 rounded`,u?.kind===`created`&&`bg-accent-success/15 text-accent-success`,u?.kind===`modified`&&`bg-accent-info/15 text-accent-info`,u?.kind===`deleted`&&`bg-destructive/15 text-destructive`),title:u?.kind===`created`?i(`tree.latestTitleCreated`):u?.kind===`deleted`?i(`tree.latestTitleDeleted`):i(`tree.latestTitleModified`),children:i(`action.${p}`)}),!m&&d&&(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded bg-muted/60 text-muted-foreground font-mono`,title:i(`tree.jobTitle`,{jobId:u?.jobId??``}),children:[(0,Z.jsx)(f,{className:`h-3 w-3`}),d]}),!m&&typeof c==`number`&&(0,Z.jsxs)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),o(c)},className:`text-[10px] px-1.5 py-0.5 rounded bg-accent-success/20 text-accent-success`,"data-testid":`provenance-chip-created-${c}`,title:i(`tree.createdBySpec`,{id:c}),children:[`#`,c]}),!m&&l.slice(0,2).map(e=>(0,Z.jsxs)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),o(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 ye(e){return new Worker(`/assets/editor.worker-tytyn86m.js`,{name:e?.name})}function be(e){return new Worker(`/assets/json.worker-Oa9UrkKE.js`,{name:e?.name})}function xe(e){return new Worker(`/assets/css.worker-yKcq13f2.js`,{name:e?.name})}function Se(e){return new Worker(`/assets/html.worker-DSJ9zmd7.js`,{name:e?.name})}function Ce(e){return new Worker(`/assets/ts.worker-BtjBFNHX.js`,{name:e?.name})}var we=!1;function Te(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 Q(e,t=`#1e1e1e`){if(e.startsWith(`#`))return e;let n=Te(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 Ee(e){return`specrails-${e}`}function De(e,t){let n=Ee(t.id),r=t.xterm,i=Q(r.background),a=Q(r.foreground),o=Q(r.brightBlack),s=Q(r.magenta),c=Q(r.yellow),l=Q(r.cyan),u=Q(r.blue),d=Q(r.green),f=Q(r.brightBlack),p=Q(r.brightCyan),m=Q(r.red),h=Q(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":Q(r.cursor),"editor.selectionBackground":h,"editor.inactiveSelectionBackground":h,"editor.lineHighlightBackground":Q(r.black),"editor.lineHighlightBorder":Q(r.black),"editorGutter.background":i,"editorWhitespace.foreground":o,"editorIndentGuide.background1":Q(r.black),"editorIndentGuide.activeBackground1":o,"scrollbarSlider.background":`${o}55`,"scrollbarSlider.hoverBackground":`${o}88`,"scrollbarSlider.activeBackground":`${o}bb`,"minimap.background":i}}),n}function Oe(){we||=(self.MonacoEnvironment={getWorker(e,t){switch(t){case`json`:return new be;case`css`:case`scss`:case`less`:return new xe;case`html`:case`handlebars`:case`razor`:return new Se;case`typescript`:case`javascript`:return new Ce;default:return new ye}}},!0)}function ke({content:e,language:t,readOnly:n,onChange:r}){let{t:a}=c(`code`),o=P(),s=(0,L.useRef)(null),l=(0,L.useRef)(null),u=(0,L.useRef)(null),[d,f]=(0,L.useState)(!1),p=(0,L.useRef)(e),m=(0,L.useRef)(t),h=(0,L.useRef)(o),g=(0,L.useRef)(n),_=(0,L.useRef)(r);return(0,L.useEffect)(()=>{p.current=e},[e]),(0,L.useEffect)(()=>{m.current=t},[t]),(0,L.useEffect)(()=>{h.current=o},[o]),(0,L.useEffect)(()=>{g.current=n},[n]),(0,L.useEffect)(()=>{_.current=r},[r]),(0,L.useEffect)(()=>{let e=!1;return Oe(),i(()=>import(`./editor.main-DxrmGfoq.js`).then(t=>{if(e||!s.current)return;u.current=t;let n=De(t,h.current),r=t.editor.create(s.current,{value:p.current,language:m.current,readOnly:g.current,theme:n,minimap:{enabled:!1},lineNumbers:`on`,scrollBeyondLastLine:!1,automaticLayout:!0,fontSize:13});r.onDidChangeModelContent(()=>{_.current?.(r.getValue())}),l.current=r}),__vite__mapDeps([0,1,2,3,4,5,6])).catch(()=>{e||f(!0)}),()=>{e=!0,l.current?.dispose?.(),l.current=null}},[]),(0,L.useEffect)(()=>{let t=l.current;t&&t.getValue?.()!==e&&t.setValue?.(e)},[e]),(0,L.useEffect)(()=>{l.current?.updateOptions?.({readOnly:n})},[n]),(0,L.useEffect)(()=>{let e=u.current,n=l.current;if(!e||!n)return;let r=n.getModel?.();r&&e.editor.setModelLanguage(r,t)},[t]),(0,L.useEffect)(()=>{let e=u.current;if(!e)return;let t=De(e,o);e.editor.setTheme(t)},[o]),d?(0,Z.jsxs)(`div`,{className:`w-full h-full flex flex-col items-center justify-center gap-2 text-sm text-muted-foreground`,"data-testid":`monaco-load-error`,children:[(0,Z.jsx)(`span`,{children:a(`monaco.loadFailed`)}),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>window.location.reload(),className:`rounded-md bg-accent-primary/15 px-3 py-1 text-xs text-accent-primary hover:bg-accent-primary/25`,children:a(`monaco.reload`)})]}):(0,Z.jsx)(`div`,{ref:s,className:`w-full h-full`,"data-testid":`monaco-host`})}var Ae=(0,L.lazy)(async()=>({default:ke}));function je({content:e,language:t,readOnly:n=!0,onChange:r}){let{t:i}=c(`code`);return(0,Z.jsx)(L.Suspense,{fallback:(0,Z.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-sm text-muted-foreground animate-pulse`,children:i(`monaco.loadingEditor`)}),children:(0,Z.jsx)(Ae,{content:e,language:t,readOnly:n,onChange:r})})}function Me(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 Ne({path:e,summary:t,stale:n,regenerating:r,generateDisabledReason:i,onCollapse:a}){let{t:o,i18n:s}=c(`code`),{openTicketDetail:l}=m();if(!t)return(0,Z.jsx)(`div`,{className:`border-b border-border px-4 py-3 bg-surface`,"data-testid":`summary-header-empty`,children:(0,Z.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-col gap-0.5 min-w-0`,children:[(0,Z.jsx)(`span`,{className:`text-xs text-muted-foreground truncate`,children:e}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:i?o(`summary.unavailable`,{reason:i}):o(`summary.empty`)})]}),a&&(0,Z.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,Z.jsx)(_,{className:`h-3.5 w-3.5`}),o(`summary.hide`)]})]})});let u=Me(t.generatedAt,s.language),d=t.triggeredBy?.ticketId,f=t.triggeredBy?.modifiedTicketIds??[];return(0,Z.jsx)(`div`,{className:`border-b border-border px-4 py-3 bg-surface`,"data-testid":`summary-header`,children:(0,Z.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,Z.jsx)(`span`,{className:`text-xs text-muted-foreground truncate`,children:e}),n&&(0,Z.jsx)(`span`,{className:O(`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,Z.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-accent-primary animate-pulse`,"aria-hidden":!0})]}),(0,Z.jsx)(`p`,{className:`text-sm text-foreground mt-1`,children:t.summary}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 mt-2 flex-wrap`,children:[typeof d==`number`&&(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>l(d),className:`text-[10px] px-1.5 py-0.5 rounded bg-accent-success/20 text-accent-success`,children:[`#`,d]}),f.map(e=>(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>l(e),className:`text-[10px] px-1.5 py-0.5 rounded bg-accent-info/15 text-accent-info`,children:[`#`,e]},e)),u&&(0,Z.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:u})]})]}),a&&(0,Z.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,Z.jsx)(_,{className:`h-3.5 w-3.5`}),o(`summary.hide`)]})]})})}function Pe({content:e}){return(0,Z.jsx)(A,{remarkPlugins:[j],children:e})}var Fe={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 Ie(e){return e===`created`?h:e===`deleted`?p:b}function Le({relPath:e,height:t,onOpenTicket:n,onFilterJob:r}){let{t:i}=c(`code`),{activeProjectId:a,projects:o}=T(),l=o.find(e=>e.id===a)?.provider,d=k(l),{registerHandler:f,unregisterHandler:p}=s(),[m,h]=(0,L.useState)(null),[g,_]=(0,L.useState)(!1),[v,y]=(0,L.useState)({}),b=(0,L.useRef)(a);(0,L.useEffect)(()=>{b.current=a},[a]);let x=(0,L.useRef)(e);(0,L.useEffect)(()=>{x.current=e},[e]);let S=(0,L.useRef)(0),w=(0,L.useCallback)(async()=>{let t=++S.current;try{let n=await fetch(`${C()}/code/file/story?path=${encodeURIComponent(e)}`);if(t!==S.current)return;if(!n.ok){h([]),_(!0);return}let r=await n.json();if(t!==S.current)return;h(Array.isArray(r.story)?r.story:[]),_(!1)}catch{t===S.current&&(h([]),_(!0))}},[e,a]);(0,L.useEffect)(()=>{h(null),y({}),w()},[w]),(0,L.useEffect)(()=>{if(!a)return;let e=`code-story-${a}`;return f(e,e=>{let t=e;t.projectId===b.current&&t.path===x.current&&(t.type===`file.story_updated`||t.type===`file.provenance_updated`)&&w()}),()=>p(e)},[a,f,p,w]);let E=(0,L.useCallback)(async(t,n)=>{if(d){y(e=>({...e,[t.provenanceId]:`busy`}));try{let r=await fetch(`${C()}/code/file/story/explain?path=${encodeURIComponent(e)}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({provenanceId:t.provenanceId,overrideBudget:n})}),a=await r.json().catch(()=>({}));if(a.skipped===`budget`){y(e=>({...e,[t.provenanceId]:`budget`}));return}if(!r.ok||!a.ok){u.error(i(`story.explainFailed`)),y(e=>{let n={...e};return delete n[t.provenanceId],n});return}await w(),y(e=>{let n={...e};return delete n[t.provenanceId],n})}catch{u.error(i(`story.explainFailed`)),y(e=>{let n={...e};return delete n[t.provenanceId],n})}}},[d,w,e,i]);return(0,Z.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,Z.jsx)(`div`,{className:`h-full overflow-auto`,children:m===null?(0,Z.jsx)(`div`,{className:`text-[11px] text-muted-foreground animate-pulse py-2`,children:i(`story.loading`)}):g?(0,Z.jsx)(`div`,{className:`text-[11px] text-muted-foreground py-2`,"data-testid":`story-failed`,children:i(`story.loadFailed`)}):m.length===0?(0,Z.jsx)(`div`,{className:`text-[11px] text-muted-foreground py-2`,"data-testid":`story-empty`,children:i(`story.empty`)}):(0,Z.jsx)(`ol`,{className:`relative ml-1.5 border-l border-border/60 space-y-3 py-1`,children:m.map(e=>(0,Z.jsx)(Re,{entry:e,state:v[e.provenanceId],canExplain:d,onOpenTicket:n,onFilterJob:r,onExplain:t=>{E(e,t)}},e.provenanceId))})})})}function Re({entry:e,state:t,canExplain:n,onOpenTicket:r,onFilterJob:i,onExplain:a}){let{t:o}=c(`code`),s=Ie(e.kind),l=e.ticket?.status??null,u=e.ticket?.title?`#${e.ticket.id} · ${e.ticket.title}`:e.ticketId==null?null:o(`story.spec`,{ticketId:e.ticketId}),d=e.ticketId==null?`${e.kind}NoSpec`:e.kind;return(0,Z.jsxs)(`li`,{className:`relative pl-4`,"data-testid":`story-card`,children:[(0,Z.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,Z.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,Z.jsxs)(`header`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,Z.jsx)(s,{className:`h-3.5 w-3.5 shrink-0`}),o(`story.kindLabel.${e.kind}`)]}),u!=null&&e.ticketId!=null&&(0,Z.jsx)(`button`,{type:`button`,onClick:()=>r(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:o(`story.openSpec`,{ticketId:e.ticketId}),children:u}),u==null&&(0,Z.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:o(`story.unknownSpec`)}),l&&(0,Z.jsx)(`span`,{className:`rounded px-1.5 py-0.5 text-[10px] ${Fe[l]??`bg-muted/60 text-muted-foreground`}`,"data-testid":`story-status-pill`,children:l}),(0,Z.jsxs)(`span`,{className:`ml-auto inline-flex items-center gap-2`,children:[e.addedLines!=null&&e.addedLines>0&&(0,Z.jsxs)(`span`,{className:`font-mono text-[10px] text-accent-success`,title:o(`story.linesAdded`),children:[`+`,e.addedLines]}),e.removedLines!=null&&e.removedLines>0&&(0,Z.jsxs)(`span`,{className:`font-mono text-[10px] text-destructive`,title:o(`story.linesRemoved`),children:[`−`,e.removedLines]}),(0,Z.jsx)(`time`,{className:`text-[10px] text-muted-foreground`,dateTime:new Date(e.at).toISOString(),children:new Date(e.at).toLocaleString()})]})]}),(0,Z.jsx)(`div`,{className:`mt-1.5`,children:e.summary?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`p`,{className:`text-sm leading-relaxed text-foreground/90`,"data-testid":`story-contribution`,children:e.summary}),e.summaryModel&&(0,Z.jsx)(`p`,{className:`mt-1 text-[10px] text-muted-foreground/80`,children:o(`story.explainedBy`,{model:e.summaryModel})})]}):(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,"data-testid":`story-fallback`,children:o(`story.fallback.${d}`)}),n?t===`budget`?(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,Z.jsx)(`span`,{className:`text-[10px] text-accent-warning`,children:o(`story.budgetReached`)}),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>a(!0),className:`rounded bg-accent-warning/15 px-1.5 py-0.5 text-[10px] text-accent-warning hover:bg-accent-warning/25`,children:o(`story.generateAnyway`)})]}):(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>a(!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,Z.jsx)(x,{className:t===`busy`?`h-3 w-3 animate-pulse`:`h-3 w-3`}),o(t===`busy`?`story.explaining`:`story.explain`)]}):(0,Z.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,"data-testid":`story-explain-unavailable`,children:o(`story.explainUnavailable`)})]})}),e.jobId&&i&&(0,Z.jsx)(`footer`,{className:`mt-1.5`,children:(0,Z.jsx)(`button`,{type:`button`,onClick:()=>i(e.jobId),className:`font-mono text-[10px] text-muted-foreground hover:text-foreground`,title:o(`history.filterByJob`,{jobId:e.jobId}),children:e.jobId.length>12?e.jobId.slice(0,12):e.jobId})})]})]})}function ze(e,t){return t===`markdown`||t===`md`||/\.(md|mdx|markdown)$/i.test(e)}var Be=180,Ve=120,He=240;function Ue(e){return e?`specrails-desktop:code-summary-collapsed:${e}`:null}function We(e){return e?`specrails-desktop:code-history-height:${e}`:null}function Ge(e){return e?`specrails-desktop:code-history-collapsed:${e}`:null}function Ke(e){return e?`specrails-desktop:code-history-mode:${e}`:null}function qe(e){let t=Ke(e);if(!t)return`story`;try{return localStorage.getItem(t)===`log`?`log`:`story`}catch{return`story`}}function Je(e,t){let n=Ke(e);if(n)try{localStorage.setItem(n,t)}catch{}}function Ye(e){let t=We(e);if(!t)return Be;try{let e=localStorage.getItem(t),n=e?Number(e):NaN;return Number.isFinite(n)&&n>0?n:Be}catch{return Be}}function Xe(e,t){let n=We(e);if(n)try{localStorage.setItem(n,String(Math.round(t)))}catch{}}function Ze(e){let t=Ue(e);if(!t)return!1;try{return localStorage.getItem(t)===`true`}catch{return!1}}function Qe(e,t){let n=Ue(e);if(n)try{localStorage.setItem(n,t?`true`:`false`)}catch{}}function $e(e){let t=Ge(e);if(!t)return!1;try{return localStorage.getItem(t)===`true`}catch{return!1}}function et(e,t){let n=Ge(e);if(n)try{localStorage.setItem(n,t?`true`:`false`)}catch{}}function tt(e,t){let n=Math.max(Ve,t-He);return Math.min(Math.max(e,Ve),n)}function nt({relPath:e,onFilterJob:t,onSummaryActionChange:n,onCopyPathActionChange:r}){let{t:i}=c(`code`),{activeProjectId:a,projects:o}=T(),l=o.find(e=>e.id===a)?.provider,d=k(l),{openTicketDetail:f}=m(),{registerHandler:p,unregisterHandler:h}=s(),g=E({allowMove:!1}),y=(0,L.useRef)(null),[b,x]=(0,L.useState)(null),[S,w]=(0,L.useState)(!0),[O,A]=(0,L.useState)(!1),[j,M]=(0,L.useState)(!1),[N,P]=(0,L.useState)(()=>Ze(a)),[F,I]=(0,L.useState)(()=>Ye(a)),[z,B]=(0,L.useState)(()=>$e(a)),[V,ee]=(0,L.useState)(()=>qe(a)),te=(0,L.useRef)(a);(0,L.useEffect)(()=>{te.current=a},[a]);let H=(0,L.useRef)(e);(0,L.useEffect)(()=>{H.current=e},[e]),(0,L.useEffect)(()=>{let e=y.current?.clientHeight||window.innerHeight;P(Ze(a)),I(tt(Ye(a),e)),B($e(a)),ee(qe(a))},[a]);let ne=(0,L.useCallback)(e=>{let t=e.clientY,n=F,r=y.current?.clientHeight||window.innerHeight,i=e.currentTarget;try{i.setPointerCapture(e.pointerId)}catch{}function o(e){I(tt(n+(t-e.clientY),r))}function s(){window.removeEventListener(`pointermove`,o),window.removeEventListener(`pointerup`,s),window.removeEventListener(`pointercancel`,s),I(e=>{let t=tt(e,r);return Xe(a,t),t})}window.addEventListener(`pointermove`,o),window.addEventListener(`pointerup`,s),window.addEventListener(`pointercancel`,s)},[a,F]),re=(0,L.useCallback)(()=>{let e=tt(Be,y.current?.clientHeight||window.innerHeight);I(e),Xe(a,e)},[a]),ie=(0,L.useCallback)(()=>{P(e=>{let t=!e;return Qe(a,t),t})},[a]),ae=(0,L.useCallback)(()=>{B(e=>{let t=!e;return et(a,t),t})},[a]),oe=(0,L.useCallback)(e=>{ee(e),Je(a,e)},[a]);(0,L.useEffect)(()=>{A(!1),M(!1),q(`preview`),Y(!1)},[e]);let U=(0,L.useRef)(0),W=(0,L.useCallback)(async()=>{let t=++U.current;w(!0);try{let n=await fetch(`${C()}/code/file?path=${encodeURIComponent(e)}`);if(t!==U.current)return;if(!n.ok){x(null);return}let r=await n.json();if(t!==U.current)return;x(r)}catch{t===U.current&&x(null)}finally{t===U.current&&w(!1)}},[e,a]);(0,L.useEffect)(()=>{W()},[W]),(0,L.useEffect)(()=>{if(!a)return;let e=`code-file-${a}`;return p(e,e=>{let t=e;t.projectId===te.current&&(t.type===`file.summary_updated`&&t.path===H.current?(A(!1),W()):t.type===`file.summary_failed`&&t.path===H.current?(u.error(t.reason??i(`summary.generationFailed`)),A(!1)):t.type===`file.summary_skipped`&&t.path===H.current&&(t.reason&&u(i(`summary.skipped`,{reason:t.reason})),A(!1)))}),()=>h(e)},[a,p,h,W,i]);let G=(0,L.useCallback)(async t=>{if(d){A(!0);try{let n=await fetch(`${C()}/code/file/regenerate-summary?path=${encodeURIComponent(e)}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({overrideBudget:t})}),r=await n.json().catch(()=>({}));if(!n.ok){A(!1);let e=typeof r.skipped==`string`?r.skipped:null;u.error(e?i(`summary.skipped`,{reason:e}):i(`summary.generationFailed`));return}if(r.skipped===`budget`){A(!1),M(!0);return}if(r.skipped){A(!1),u(i(`summary.skipped`,{reason:r.skipped}));return}await W(),A(!1)}catch{A(!1),u.error(i(`summary.generationFailed`))}}},[d,W,e,i]),se=(0,L.useCallback)(async()=>{let t=b?.absolutePath??e;try{await navigator.clipboard?.writeText(t),u.success(i(`viewer.pathCopied`))}catch{u.error(i(`viewer.copyPathFailed`))}},[b,e,i]),ce=(0,L.useMemo)(()=>ze(e,b?.language),[e,b?.language]),[K,q]=(0,L.useState)(`preview`),[J,Y]=(0,L.useState)(!1),[X,le]=(0,L.useState)(``),[ue,de]=(0,L.useState)(!1),fe=b?.content!==void 0&&!b.binary&&!b.tooLarge&&b.reason!==`not-found`,pe=(0,L.useCallback)(()=>{le(b?.content??``),q(`raw`),Y(!0)},[b]),me=(0,L.useCallback)(async()=>{de(!0);try{let t=await fetch(`${C()}/code/file`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({path:e,content:X})});if(!t.ok){let e=await t.json().catch(()=>({}));u.error(e.error??i(`viewer.saveFailed`));return}u.success(i(`viewer.saved`)),Y(!1),W()}catch{u.error(i(`viewer.saveFailed`))}finally{de(!1)}},[e,X,i,W]),he=b?.summary??null,ge=!!b?.summaryStale,_e=b?.provenance??[],ve=b?.reason===`not-found`,ye=d?ve?i(`summary.reason.missing`):b?.binary?i(`summary.reason.binary`):b?.tooLarge?i(`summary.reason.tooLarge`):null:i(`summary.reason.providerNoPureOutput`);return(0,L.useEffect)(()=>{if(n){if(S&&!b){n(null);return}return n({hasSummary:!!he,regenerating:O,disabledReason:ye,onClick:()=>G(!1)}),()=>n(null)}},[b,G,S,n,O,he,ye]),(0,L.useEffect)(()=>{if(r){if(S&&!b){r(null);return}return r({onClick:se}),()=>r(null)}},[se,b,S,r]),S&&!b?(0,Z.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-sm text-muted-foreground animate-pulse`,children:i(`viewer.loadingFile`)}):(0,Z.jsxs)(`div`,{ref:y,className:`flex flex-col h-full`,"data-testid":`file-viewer`,children:[N?(0,Z.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,Z.jsx)(`span`,{className:`truncate text-xs text-muted-foreground`,children:e}),(0,Z.jsxs)(`button`,{type:`button`,onClick:ie,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,Z.jsx)(v,{className:`h-3.5 w-3.5`}),i(`viewer.showSummary`)]})]}):(0,Z.jsx)(Ne,{path:e,summary:he,stale:ge,regenerating:O,generateDisabledReason:ye,onCollapse:ie}),(0,Z.jsxs)(`div`,{className:`px-4 py-1 border-b border-border flex items-center justify-between gap-3`,children:[(0,Z.jsx)(`div`,{className:`flex items-center gap-2 min-w-0`,children:ce&&b?.content!==void 0&&!b.binary&&!b.tooLarge&&(0,Z.jsxs)(`div`,{className:`flex items-center gap-1 text-[11px]`,role:`group`,"aria-label":i(`viewer.markdownViewMode`),children:[(0,Z.jsx)(`button`,{type:`button`,onClick:()=>q(`preview`),"aria-pressed":K===`preview`,className:K===`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:i(`viewer.preview`)}),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>q(`raw`),"aria-pressed":K===`raw`,className:K===`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:i(`viewer.raw`)})]})}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1 text-[11px] shrink-0`,children:[fe&&!J&&(0,Z.jsx)(`button`,{type:`button`,onClick:pe,className:`px-2 py-1 rounded-md text-muted-foreground hover:text-foreground hover:bg-muted/50`,children:i(`viewer.edit`)}),J&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`button`,{type:`button`,onClick:()=>Y(!1),disabled:ue,className:`px-2 py-1 rounded-md text-muted-foreground hover:text-foreground hover:bg-muted/50 disabled:opacity-50`,children:i(`actions.cancel`,{ns:`common`})}),(0,Z.jsx)(`button`,{type:`button`,onClick:me,disabled:ue,className:`px-2 py-1 rounded-md bg-accent-primary/20 text-accent-primary hover:bg-accent-primary/30 disabled:opacity-50`,children:i(ue?`viewer.saving`:`viewer.save`)})]})]})]}),(0,Z.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:ve?(0,Z.jsx)(`div`,{className:`h-full flex items-center justify-center text-sm text-muted-foreground`,"data-testid":`file-missing`,children:i(`viewer.missingFile`)}):b?.binary?(0,Z.jsx)(`div`,{className:`h-full flex items-center justify-center text-sm text-muted-foreground`,"data-testid":`file-binary`,children:i(`viewer.binaryFile`)}):b?.tooLarge?(0,Z.jsx)(`div`,{className:`h-full flex items-center justify-center text-sm text-muted-foreground`,"data-testid":`file-too-large`,children:i(`viewer.tooLarge`,{size:Math.round((b.sizeBytes??0)/1024/1024)})}):b?.content===void 0?(0,Z.jsx)(`div`,{className:`h-full flex items-center justify-center text-sm text-muted-foreground`,children:i(`viewer.noContent`)}):J?(0,Z.jsx)(je,{content:X,language:b.language??`plaintext`,readOnly:!1,onChange:le}):ce&&K===`preview`?(0,Z.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,Z.jsx)(Pe,{content:b.content})}):(0,Z.jsx)(je,{content:b.content,language:b.language??`plaintext`})}),_e.length>0&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{role:`separator`,"aria-orientation":`horizontal`,"aria-label":i(`history.resize`),onPointerDown:z?void 0:ne,onDoubleClick:z?void 0:re,className:z?`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:z?void 0:i(`resizer.hint`),"data-testid":`code-history-resizer`,children:[(0,Z.jsx)(`span`,{className:`text-[11px] font-medium uppercase tracking-wider text-muted-foreground`,children:i(V===`story`?`story.title`:`history.title`,{count:_e.length})}),(0,Z.jsxs)(`span`,{className:`flex items-center gap-1`,children:[!z&&(0,Z.jsxs)(`span`,{className:`flex items-center gap-0.5 rounded-md bg-muted/40 p-0.5`,role:`group`,"aria-label":i(`story.viewMode`),onPointerDown:e=>e.stopPropagation(),children:[(0,Z.jsx)(`button`,{type:`button`,onClick:()=>oe(`story`),"aria-pressed":V===`story`,className:V===`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:i(`story.modeStory`)}),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>oe(`log`),"aria-pressed":V===`log`,className:V===`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:i(`story.modeLog`)})]}),(0,Z.jsxs)(`button`,{type:`button`,onPointerDown:e=>e.stopPropagation(),onClick:ae,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:[z?(0,Z.jsx)(_,{className:`h-3.5 w-3.5`}):(0,Z.jsx)(v,{className:`h-3.5 w-3.5`}),i(z?`history.show`:`history.hide`)]})]})]}),!z&&(V===`story`?(0,Z.jsx)(Le,{relPath:e,height:F,onOpenTicket:f,onFilterJob:t}):(0,Z.jsx)(rt,{rows:_e,onOpenTicket:f,onFilterJob:t,height:F}))]}),j&&(0,R.createPortal)((0,Z.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:g.guardBackdrop(()=>M(!1)),children:[(0,Z.jsxs)(`div`,{ref:g.panelRef,onClick:e=>e.stopPropagation(),className:`bg-card border border-border rounded-lg p-4 w-80 flex flex-col gap-3`,style:g.panelStyle,children:[(0,Z.jsx)(`p`,{className:`text-sm text-foreground`,children:i(`viewer.budgetPrompt`)}),(0,Z.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:()=>M(!1),className:`text-xs px-3 py-1.5 rounded-md text-muted-foreground hover:text-foreground`,children:i(`common:actions.cancel`)}),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>{M(!1),G(!0)},className:`text-xs px-3 py-1.5 rounded-md bg-accent-primary text-white`,children:i(`common:actions.confirm`)})]})]}),(0,Z.jsx)(D,{handles:g.resizeHandles})]}),document.body)]})}function rt({rows:e,onOpenTicket:t,onFilterJob:n,height:r}){let{t:i}=c(`code`),[a,o]=(0,L.useState)(null),[s,l]=(0,L.useState)({});if(e.length===0)return null;async function u(e,t){if(a===t){o(null);return}if(o(t),!(!e.jobId||s[t])){l(e=>({...e,[t]:`loading`}));try{let n=new URLSearchParams({jobId:e.jobId,path:e.path}),r=await fetch(`${C()}/code/diff?${n.toString()}`);if(r.status===404){l(e=>({...e,[t]:`missing`}));return}if(!r.ok)throw Error(`diff failed`);let i=await r.json();l(e=>({...e,[t]:{patch:i.patch??``,truncated:i.truncated===!0}}))}catch{l(e=>({...e,[t]:`missing`}))}}}return(0,Z.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,Z.jsx)(`div`,{className:`h-full overflow-auto space-y-1`,children:e.map((e,r)=>{let o=e.kind===`created`?h:e.kind===`deleted`?p:b,c=e.jobId?e.jobId.length>12?e.jobId.slice(0,12):e.jobId:i(`history.unknownJob`),l=`${e.jobId??`job`}:${e.path}:${e.at}:${r}`,d=s[l];return(0,Z.jsxs)(`div`,{className:`rounded-md hover:bg-muted/40`,children:[(0,Z.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,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 min-w-0`,children:[(0,Z.jsx)(o,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}),(0,Z.jsx)(`span`,{className:`capitalize`,children:i(`kind.${e.kind}`)})]}),(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 min-w-0 text-muted-foreground`,children:[(0,Z.jsx)(f,{className:`h-3.5 w-3.5 shrink-0`}),e.jobId&&n?(0,Z.jsx)(`button`,{type:`button`,onClick:()=>n(e.jobId),className:`font-mono truncate hover:text-foreground`,title:i(`history.filterByJob`,{jobId:e.jobId}),children:c}):(0,Z.jsx)(`span`,{className:`font-mono truncate`,title:e.jobId??void 0,children:c}),e.jobId&&(0,Z.jsx)(`button`,{type:`button`,onClick:()=>u(e,l),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,Z.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,Z.jsx)(`time`,{className:`text-[11px] text-muted-foreground`,dateTime:new Date(e.at).toISOString(),children:new Date(e.at).toLocaleString()})]}),a===l&&(0,Z.jsx)(`div`,{className:`px-2 pb-2`,children:d===`loading`?(0,Z.jsx)(`div`,{className:`rounded-md bg-muted/35 px-2 py-2 text-[11px] text-muted-foreground`,children:i(`history.loadingDiff`)}):d===`missing`||!d?(0,Z.jsx)(`div`,{className:`rounded-md bg-muted/35 px-2 py-2 text-[11px] text-muted-foreground`,children:i(`history.diffUnavailable`)}):(0,Z.jsxs)(`pre`,{className:`max-h-72 overflow-auto rounded-md bg-muted/50 px-2 py-2 font-mono text-[11px] leading-relaxed text-foreground/85`,children:[d.patch,d.truncated?`\n${i(`history.diffTruncated`)}`:``]})})]},l)})})})}var it=320,at=240,ot=520;function st(e){return e?`specrails-desktop:code-tree-width:${e}`:null}function ct(e){let t=st(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 lt(e,t){let n=st(e);if(n)try{localStorage.setItem(n,String(Math.round(t)))}catch{}}function $(e,t){let n=Math.max(at,t-ot);return Math.min(Math.max(e,at),n)}function ut({embedded:e=!1,initialPath:t=null,onSelectedPathChange:n}={}){let{t:r}=c(`code`),{activeProjectId:i}=T(),[s]=a(),l=o(),u=(0,L.useRef)(null),[d,f]=(0,L.useState)(e?t:s.get(`path`)),p=(0,L.useCallback)(e=>{f(e),n?.(e)},[n]),[m,h]=(0,L.useState)(null),[g,_]=(0,L.useState)(null),[v,y]=(0,L.useState)(()=>ct(i)),[b,x]=(0,L.useState)(null),[S,C]=(0,L.useState)(null),w=e?b:s.get(`jobId`),E=(0,L.useMemo)(()=>{if(e)return S;let t=s.get(`ticketId`);if(!t)return null;let n=Number(t);return Number.isInteger(n)&&n>0?n:null},[e,S,s]),[D,O]=(0,L.useState)(E==null?``:String(E));(0,L.useEffect)(()=>{if(e)return;let t=s.get(`path`);t!==d&&f(t)},[s,e]),(0,L.useEffect)(()=>{O(E==null?``:String(E))},[E]),(0,L.useEffect)(()=>{let e=u.current?.clientWidth||window.innerWidth;y($(ct(i),e))},[i]),(0,L.useEffect)(()=>{let e=u.current;if(!e||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(e=>{let t=e[0]?.contentRect.width;typeof t==`number`&&y(e=>$(e,t))});return t.observe(e),()=>t.disconnect()},[]);let k=(0,L.useCallback)(e=>{let t=e.clientX,n=v,r=u.current?.clientWidth||window.innerWidth,a=e.currentTarget;try{a.setPointerCapture(e.pointerId)}catch{}function o(e){y($(n+(e.clientX-t),r))}function s(){window.removeEventListener(`pointermove`,o),window.removeEventListener(`pointerup`,s),window.removeEventListener(`pointercancel`,s),y(e=>{let t=$(e,r);return lt(i,t),t})}window.addEventListener(`pointermove`,o),window.addEventListener(`pointerup`,s),window.addEventListener(`pointercancel`,s)},[i,v]),A=(0,L.useCallback)(()=>{let e=$(it,u.current?.clientWidth||window.innerWidth);y(e),lt(i,e)},[i]),j=(0,L.useCallback)(t=>{if(p(t),e)return;let n=new URLSearchParams(s);n.set(`path`,t),l({pathname:`/code`,search:`?${n.toString()}`},{replace:!0})},[e,l,s,p]),M=(0,L.useCallback)(t=>{if(e){x(t),C(null);return}let n=new URLSearchParams(s);n.set(`jobId`,t),n.delete(`ticketId`),l({pathname:`/code`,search:`?${n.toString()}`},{replace:!0})},[e,l,s]),N=(0,L.useCallback)(()=>{if(e){x(null),C(null);return}let t=new URLSearchParams(s);t.delete(`jobId`),t.delete(`ticketId`),l({pathname:`/code`,search:t.toString()?`?${t.toString()}`:``},{replace:!0})},[e,l,s]),P=(0,L.useCallback)(t=>{let n=Number(t.trim());if(!Number.isInteger(n)||n<=0){N();return}if(e){C(n),x(null);return}let r=new URLSearchParams(s);r.set(`ticketId`,String(n)),r.delete(`jobId`),l({pathname:`/code`,search:`?${r.toString()}`},{replace:!0})},[N,e,l,s]);return(0,Z.jsxs)(`div`,{ref:u,className:`flex h-full w-full`,"data-testid":`code-page`,children:[(0,Z.jsx)(`aside`,{className:`overflow-hidden flex flex-col shrink-0`,style:{width:v},children:(0,Z.jsx)(ve,{onOpenFile:j,selectedPath:d,filterJobId:w,filterTicketId:E},i??`no-project`)}),(0,Z.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-label":r(`page.resizeFileTree`),onPointerDown:k,onDoubleClick:A,className:`relative w-1.5 shrink-0 cursor-col-resize select-none touch-none border-x border-border/40 hover:bg-accent-primary/20 focus-visible:outline-none focus-visible:bg-accent-primary/30`,title:r(`resizer.hint`),"data-testid":`code-tree-resizer`}),(0,Z.jsxs)(`main`,{className:`flex-1 overflow-hidden flex flex-col`,children:[(0,Z.jsx)(dt,{jobId:w,ticketId:E,ticketInput:D,onTicketInputChange:O,onApplyTicket:P,onClear:N,summaryAction:m,copyPathAction:g}),(w||E)&&(0,Z.jsx)(ft,{jobId:w,ticketId:E,onOpenFile:j}),d?(0,Z.jsx)(nt,{relPath:d,onFilterJob:M,onSummaryActionChange:h,onCopyPathActionChange:_}):(0,Z.jsx)(`div`,{className:`h-full flex items-center justify-center text-sm text-muted-foreground`,children:r(`page.selectFile`)})]})]})}function dt({jobId:e,ticketId:t,ticketInput:n,onTicketInputChange:r,onApplyTicket:i,onClear:a,summaryAction:o,copyPathAction:s}){let{t:l}=c(`code`),u=t?`spec`:e?`job-context`:`all`;return(0,Z.jsx)(`div`,{className:`border-b border-border bg-background/80 px-4 py-2`,"data-testid":`code-provenance-toolbar`,children:(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-xs font-medium text-muted-foreground`,children:[(0,Z.jsx)(I,{className:`h-3.5 w-3.5`}),l(`toolbar.scope`)]}),(0,Z.jsx)(`button`,{type:`button`,onClick:a,"aria-pressed":u===`all`,className:u===`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:l(`toolbar.allAi`)}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1 rounded-md border border-border/70 bg-card/40 px-1 py-1`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:()=>i(n),"aria-pressed":u===`spec`,className:u===`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:l(`toolbar.spec`)}),(0,Z.jsx)(`input`,{value:n,onChange:e=>r(e.target.value),onKeyDown:e=>{e.key===`Enter`&&i(n)},placeholder:l(`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,Z.jsx)(`div`,{className:`flex-1`}),s&&(0,Z.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:l(`toolbar.copyFilePath`)}),o&&(0,Z.jsxs)(`button`,{type:`button`,onClick:o.onClick,disabled:o.regenerating||!!o.disabledReason,"aria-label":o.hasSummary?l(`toolbar.regenerateSummary`):l(`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?l(`toolbar.summaryUnavailable`,{reason:o.disabledReason}):void 0,children:[(0,Z.jsx)(d,{className:o.regenerating?`h-3.5 w-3.5 animate-spin`:`h-3.5 w-3.5`}),o.hasSummary?o.regenerating?l(`toolbar.regenerating`):l(`toolbar.regenerateSummary`):o.regenerating?l(`toolbar.generating`):l(`toolbar.generateSummary`)]}),u===`job-context`&&(0,Z.jsx)(`span`,{className:`rounded-md bg-accent-info/15 px-2 py-1 text-xs text-accent-info`,children:l(`toolbar.jobContext`)}),(e||t)&&(0,Z.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,Z.jsx)(S,{className:`h-3.5 w-3.5`}),l(`toolbar.clear`)]})]})})}function ft({jobId:e,ticketId:t,onOpenFile:n}){let{t:r}=c(`code`),[i,a]=(0,L.useState)(null);(0,L.useEffect)(()=>{let n=!1,r=new URLSearchParams;return e&&r.set(`jobId`,e),t&&r.set(`ticketId`,String(t)),fetch(`${C()}/code/provenance?${r.toString()}`).then(e=>e.ok?e.json():[]).then(e=>{n||a(Array.isArray(e)?e:[])}).catch(()=>{n||a([])}),()=>{n=!0}},[e,t]);let o=(0,L.useMemo)(()=>{let e=i??[];return{created:e.filter(e=>e.kind===`created`),modified:e.filter(e=>e.kind===`modified`),deleted:e.filter(e=>e.kind===`deleted`)}},[i]),s=i?.length??0;return(0,Z.jsx)(`section`,{className:`border-b border-border bg-card/35 px-4 py-3`,"data-testid":`provenance-result-panel`,children:(0,Z.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`h2`,{className:`text-sm font-semibold truncate`,children:e?r(`provenancePanel.jobTitle`,{jobId:e}):r(`provenancePanel.specTitle`,{ticketId:t})}),(0,Z.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:r(`provenancePanel.touchedFiles`,{count:s})})]}),(0,Z.jsxs)(`div`,{className:`mt-2 flex flex-wrap gap-2`,children:[(0,Z.jsx)(pt,{label:r(`action.added`),rows:o.created,icon:`created`,onOpenFile:n}),(0,Z.jsx)(pt,{label:r(`action.changed`),rows:o.modified,icon:`modified`,onOpenFile:n}),(0,Z.jsx)(pt,{label:r(`action.deleted`),rows:o.deleted,icon:`deleted`,onOpenFile:n})]})]}),(0,Z.jsx)(`div`,{className:`flex items-center gap-1 shrink-0`,children:e&&(0,Z.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,Z.jsx)(g,{className:`h-3.5 w-3.5`}),r(`provenancePanel.log`)]})})]})})}function pt({label:e,rows:t,icon:n,onOpenFile:r}){return(0,Z.jsxs)(`details`,{className:`group min-w-[180px] max-w-[320px]`,children:[(0,Z.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,Z.jsx)(n===`created`?h:n===`deleted`?p:b,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,Z.jsx)(`span`,{children:e}),(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:t.length})]}),t.length>0&&(0,Z.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,Z.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{ut 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{a as r,w as i}from"./i18n-DwgvwTnx.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{ct as l,v as u,y as d}from"./index-DhjjFyU5.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,l=Math.max(1,Math.floor(e.length/7)),f=e.filter((e,t)=>t%l===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 d(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)(``),[u,d]=(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();d(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`)}),u&&(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:u.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)(l,{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&&!u&&(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))})]}),u&&(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsx)(Ct,{kpi:u.kpi,windowLabel:t===`custom`?u.period.label:e(`windowLabels.${t}`)}),(0,$.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:[(0,$.jsx)(wt,{data:u.costTimeline}),(0,$.jsx)(Et,{projects:u.projectBreakdown})]}),(0,$.jsx)(Tt,{projects:u.projectBreakdown})]})]})})}export{Dt as default};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-zu2_FqZY.js";import{n as r}from"./createLucideIcon-Bjbbp_KS.js";import{n as i,t as a}from"./file-text-BcLCfcWZ.js";import{t as o}from"./loader-circle-DcygOQpC.js";import{a as s,n as c,o as l,r as u,t as d}from"./dialog-CdWCb02j.js";import{t as f}from"./utils-BC4DHlz2.js";import{n as p,t as m}from"./lib-CGdyxIWg.js";import{Mt as h}from"./index-DhjjFyU5.js";import{t as g}from"./lib-C7Mhm-gT.js";import{t as _}from"./atom-one-dark-qiGhVQxg.js";var v=e(t(),1),y=n();function b({categories:e,activeCategory:t,activeSlug:n,onSelect:i,onHome:o}){let{t:s}=r(`integrations`);return(0,y.jsxs)(`nav`,{className:`w-48 shrink-0 space-y-4 overflow-y-auto border-r border-border pr-2`,children:[(0,y.jsxs)(`button`,{onClick:o,className:f(`flex w-full items-center gap-2 rounded-lg px-2.5 py-1.5 text-left text-xs transition-colors`,!t&&!n?`bg-accent-primary/15 font-medium text-foreground`:`text-muted-foreground hover:bg-muted/40 hover:text-foreground`),children:[(0,y.jsx)(h,{className:`w-3.5 h-3.5 shrink-0`}),(0,y.jsx)(`span`,{className:`truncate`,children:s(`docs.title`)})]}),e.map(e=>(0,y.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,y.jsxs)(`div`,{className:`px-2.5 mb-1 flex items-center justify-between`,children:[(0,y.jsx)(`span`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:e.name}),e.docs.length>0&&(0,y.jsx)(`span`,{className:`text-[9px] font-medium text-muted-foreground/60 bg-muted/40 rounded px-1 py-0.5 leading-none`,children:e.docs.length})]}),e.docs.length===0?(0,y.jsx)(`p`,{className:`px-2.5 text-xs text-muted-foreground italic`,children:s(`docs.sidebarEmpty`)}):(0,y.jsx)(`ul`,{className:`space-y-0.5`,children:e.docs.map(r=>{let o=t===e.slug&&n===r.slug;return(0,y.jsx)(`li`,{children:(0,y.jsxs)(`button`,{onClick:()=>i(e.slug,r.slug),title:r.title,className:f(`flex w-full items-center gap-2 rounded-lg px-2.5 py-1.5 text-left text-xs transition-colors`,o?`bg-accent-primary/15 font-medium text-foreground`:`text-muted-foreground hover:bg-muted/40 hover:text-foreground`),children:[(0,y.jsx)(a,{className:`w-3.5 h-3.5 shrink-0`}),(0,y.jsx)(`span`,{className:`truncate`,children:r.title})]})},r.slug)})})]},e.slug))]})}function x({categories:e,onSelect:t}){let{t:n}=r(`integrations`),o=e.reduce((e,t)=>e+t.docs.length,0),s=e.filter(e=>e.docs.length>0).length;return(0,y.jsxs)(`div`,{className:`max-w-2xl mx-auto py-2 px-1 space-y-5`,children:[(0,y.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:o===0?n(`docs.indexEmpty`):n(`docs.summary`,{documents:n(`docs.documentCount`,{count:o}),categories:n(`docs.categoryCount`,{count:s})})}),e.map(e=>(0,y.jsxs)(`div`,{className:`space-y-2`,children:[(0,y.jsx)(`h2`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:e.name}),e.docs.length===0?(0,y.jsx)(`p`,{className:`text-xs text-muted-foreground italic pl-2`,children:n(`docs.categoryEmpty`)}):(0,y.jsx)(`ul`,{className:`space-y-2`,children:e.docs.map(n=>(0,y.jsx)(`li`,{children:(0,y.jsxs)(`button`,{onClick:()=>t(e.slug,n.slug),className:`w-full flex items-center gap-3 p-2.5 rounded-md border border-border text-left transition-colors hover:bg-muted/40 group`,children:[(0,y.jsx)(a,{className:`w-3.5 h-3.5 text-muted-foreground flex-shrink-0`}),(0,y.jsx)(`span`,{className:`text-xs font-medium text-foreground truncate`,children:n.title}),(0,y.jsx)(i,{className:`w-3 h-3 text-muted-foreground ml-auto md:opacity-0 md:group-hover:opacity-100 transition-opacity`})]})},n.slug))})]},e.slug))]})}var S=(0,v.memo)(function({content:e,currentCategory:t,onNavigateDoc:n}){return(0,y.jsx)(p,{remarkPlugins:[m],rehypePlugins:[g],components:{a({href:e,children:r,...i}){return(0,y.jsx)(`a`,{href:e,onClick:r=>{if(!e)return;if(/^[a-z][a-z0-9+.-]*:/i.test(e)){r.preventDefault(),window.open(e,`_blank`,`noopener,noreferrer`);return}if(e.startsWith(`#`))return;r.preventDefault();let i=_(e,t);i&&n(i.category,i.slug)},...i,children:r})}},children:e})});function C({category:e,slug:t,lang:n,onNotFound:i,onNavigate:a,scrollContainerRef:s}){let{t:c}=r(`integrations`),[l,u]=(0,v.useState)(null),[d,f]=(0,v.useState)(null),p=(0,v.useRef)(0);return(0,v.useEffect)(()=>{let r=++p.current;f(null),fetch(`/api/docs/${e}/${t}?lang=${encodeURIComponent(n)}`).then(async e=>{if(e.status===404){i();return}if(!e.ok)throw Error(`HTTP ${e.status}`);return e.json()}).then(e=>{r===p.current&&e&&(u(e),s.current&&(s.current.scrollTop=0))}).catch(e=>{r===p.current&&f(e instanceof Error?e.message:c(`docs.loadError`))})},[e,t,n,i,s]),!l&&!d?(0,y.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,y.jsx)(o,{className:`w-4 h-4 animate-spin text-muted-foreground`})}):d&&!l?(0,y.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,y.jsx)(`p`,{className:`text-sm text-destructive`,children:d})}):l?(0,y.jsx)(`article`,{className:`max-w-2xl mx-auto py-2 px-1`,children:(0,y.jsx)(`div`,{className:`prose prose-sm max-w-none
|
|
2
|
+
prose-headings:text-foreground prose-headings:font-bold
|
|
3
|
+
prose-p:text-foreground/90
|
|
4
|
+
prose-a:text-accent-primary prose-a:no-underline hover:prose-a:underline
|
|
5
|
+
prose-strong:text-foreground
|
|
6
|
+
prose-code:text-accent-info prose-code:bg-card prose-code:px-1 prose-code:py-0.5 prose-code:rounded prose-code:text-xs
|
|
7
|
+
prose-pre:bg-card prose-pre:border prose-pre:border-border prose-pre:rounded-md prose-pre:p-0 prose-pre:overflow-x-auto
|
|
8
|
+
prose-blockquote:border-l-accent-primary prose-blockquote:text-muted-foreground
|
|
9
|
+
prose-hr:border-border
|
|
10
|
+
prose-th:text-foreground prose-td:text-foreground/90
|
|
11
|
+
prose-li:text-foreground/90`,children:(0,y.jsx)(S,{content:l.content,currentCategory:l.category,onNavigateDoc:a})})}):null}function w({open:e,onClose:t}){let{t:n,i18n:i}=r(`integrations`),a=i.language||`en`,[f,p]=(0,v.useState)(null),[m,g]=(0,v.useState)(!0),[_,S]=(0,v.useState)(),[w,T]=(0,v.useState)(),E=(0,v.useRef)(null);(0,v.useEffect)(()=>{e&&(g(!0),fetch(`/api/docs?lang=${encodeURIComponent(a)}`).then(e=>e.json()).then(e=>p(e)).catch(()=>p({categories:[]})).finally(()=>g(!1)))},[e,a]);let D=(0,v.useCallback)((e,t)=>{S(e),T(t)},[]),O=(0,v.useCallback)(()=>{S(void 0),T(void 0)},[]),k=!!(_&&w);return(0,y.jsx)(d,{open:e,onOpenChange:e=>{e||t()},children:(0,y.jsxs)(c,{movableResizable:!0,className:`flex max-w-5xl w-[92vw] h-[82vh] flex-col overflow-hidden`,children:[(0,y.jsxs)(s,{children:[(0,y.jsxs)(l,{className:`flex items-center gap-2`,children:[(0,y.jsx)(h,{className:`w-4 h-4`}),n(`docs.title`)]}),(0,y.jsx)(u,{children:n(`docs.dialogDescription`)})]}),(0,y.jsxs)(`div`,{className:`flex min-h-0 flex-1 gap-5 py-2`,children:[m?(0,y.jsx)(`div`,{className:`w-48 shrink-0 border-r border-border flex items-center justify-center`,children:(0,y.jsx)(o,{className:`w-3.5 h-3.5 animate-spin text-muted-foreground`})}):(0,y.jsx)(b,{categories:f?.categories??[],activeCategory:_,activeSlug:w,onSelect:D,onHome:O}),(0,y.jsx)(`main`,{ref:E,className:`min-w-0 flex-1 overflow-y-auto pr-1`,children:k&&_&&w?(0,y.jsx)(C,{category:_,slug:w,lang:a,onNotFound:O,onNavigate:D,scrollContainerRef:E}):f&&(0,y.jsx)(x,{categories:f.categories,onSelect:D})})]})]})})}var T=(0,v.memo)(w);export{T as default};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-zu2_FqZY.js";import{d as r,n as i,u as a}from"./chunk-KS7C4IRE-DEKu087k.js";import{n as o}from"./createLucideIcon-Bjbbp_KS.js";import{n as s,t as c}from"./file-text-BcLCfcWZ.js";import{t as l}from"./loader-circle-DcygOQpC.js";import{t as u}from"./utils-BC4DHlz2.js";import{n as d,t as f}from"./lib-CGdyxIWg.js";import{Mt as p}from"./index-DhjjFyU5.js";import{t as m}from"./lib-C7Mhm-gT.js";import{t as h}from"./atom-one-dark-qiGhVQxg.js";var g=e(t(),1),_=n();function v({categories:e,activeCategory:t,activeSlug:n}){let{t:r}=o(`integrations`);return(0,_.jsxs)(`nav`,{className:`w-56 flex-shrink-0 border-r border-border overflow-y-auto py-4 px-3 space-y-4`,children:[(0,_.jsxs)(i,{to:`/docs`,className:u(`flex w-full items-center gap-2 rounded-lg px-2.5 py-1.5 text-left text-xs transition-colors`,!t&&!n?`bg-accent-primary/15 font-medium text-foreground`:`text-muted-foreground hover:bg-muted/40 hover:text-foreground`),children:[(0,_.jsx)(p,{className:`w-3.5 h-3.5 shrink-0`}),(0,_.jsx)(`span`,{className:`truncate`,children:r(`docs.title`)})]}),e.map(e=>(0,_.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,_.jsxs)(`div`,{className:`px-2.5 mb-1 flex items-center justify-between`,children:[(0,_.jsx)(`span`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:e.name}),e.docs.length>0&&(0,_.jsx)(`span`,{className:`text-[9px] font-medium text-muted-foreground/60 bg-muted/40 rounded px-1 py-0.5 leading-none`,children:e.docs.length})]}),e.docs.length===0?(0,_.jsx)(`p`,{className:`px-2.5 text-xs text-muted-foreground italic`,children:r(`docs.sidebarEmpty`)}):(0,_.jsx)(`ul`,{className:`space-y-0.5`,children:e.docs.map(r=>{let a=t===e.slug&&n===r.slug;return(0,_.jsx)(`li`,{children:(0,_.jsxs)(i,{to:`/docs/${e.slug}/${r.slug}`,title:r.title,className:u(`flex w-full items-center gap-2 rounded-lg px-2.5 py-1.5 text-left text-xs transition-colors`,a?`bg-accent-primary/15 font-medium text-foreground`:`text-muted-foreground hover:bg-muted/40 hover:text-foreground`),children:[(0,_.jsx)(c,{className:`w-3.5 h-3.5 shrink-0`}),(0,_.jsx)(`span`,{className:`truncate`,children:r.title})]})},r.slug)})})]},e.slug))]})}function y({categories:e}){let{t}=o(`integrations`),n=e.reduce((e,t)=>e+t.docs.length,0),r=e.filter(e=>e.docs.length>0).length;return(0,_.jsxs)(`div`,{className:`max-w-2xl mx-auto py-8 px-6 space-y-5`,children:[(0,_.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,_.jsxs)(`h1`,{className:`flex items-center gap-2 text-lg font-semibold`,children:[(0,_.jsx)(p,{className:`w-4 h-4`}),t(`docs.title`)]}),(0,_.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:n===0?t(`docs.indexEmpty`):t(`docs.summary`,{documents:t(`docs.documentCount`,{count:n}),categories:t(`docs.categoryCount`,{count:r})})})]}),e.map(e=>(0,_.jsxs)(`div`,{className:`space-y-2`,children:[(0,_.jsx)(`h2`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:e.name}),e.docs.length===0?(0,_.jsx)(`p`,{className:`text-xs text-muted-foreground italic pl-2`,children:t(`docs.categoryEmpty`)}):(0,_.jsx)(`ul`,{className:`space-y-2`,children:e.docs.map(t=>(0,_.jsx)(`li`,{children:(0,_.jsxs)(i,{to:`/docs/${e.slug}/${t.slug}`,className:`flex items-center gap-3 p-2.5 rounded-md border border-border transition-colors hover:bg-muted/40 group`,children:[(0,_.jsx)(c,{className:`w-3.5 h-3.5 text-muted-foreground flex-shrink-0`}),(0,_.jsx)(`span`,{className:`text-xs font-medium text-foreground truncate`,children:t.title}),(0,_.jsx)(s,{className:`w-3 h-3 text-muted-foreground ml-auto md:opacity-0 md:group-hover:opacity-100 transition-opacity`})]})},t.slug))})]},e.slug))]})}var b=(0,g.memo)(function({content:e,currentCategory:t,onNavigateDoc:n}){return(0,_.jsx)(d,{remarkPlugins:[f],rehypePlugins:[m],components:{a({href:e,children:r,...i}){return(0,_.jsx)(`a`,{href:e,onClick:r=>{if(!e)return;if(/^[a-z][a-z0-9+.-]*:/i.test(e)){r.preventDefault(),window.open(e,`_blank`,`noopener,noreferrer`);return}if(e.startsWith(`#`))return;r.preventDefault();let i=h(e,t);i&&n(i.category,i.slug)},...i,children:r})}},children:e})});function x({category:e,slug:t,lang:n,scrollContainerRef:r}){let{t:i}=o(`integrations`),[s,c]=(0,g.useState)(null),[u,d]=(0,g.useState)(null),f=(0,g.useRef)(0),p=a();return(0,g.useEffect)(()=>{let a=++f.current;d(null),fetch(`/api/docs/${e}/${t}?lang=${encodeURIComponent(n)}`).then(async e=>{if(e.status===404){p(`/docs`,{replace:!0});return}if(!e.ok)throw Error(`HTTP ${e.status}`);return e.json()}).then(e=>{a===f.current&&e&&(c(e),r.current&&(r.current.scrollTop=0))}).catch(e=>{a===f.current&&d(e instanceof Error?e.message:i(`docs.loadError`))})},[e,t,n,p,r]),!s&&!u?(0,_.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,_.jsx)(l,{className:`w-4 h-4 animate-spin text-muted-foreground`})}):u&&!s?(0,_.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,_.jsx)(`p`,{className:`text-sm text-destructive`,children:u})}):s?(0,_.jsx)(`article`,{className:`max-w-2xl mx-auto py-8 px-6`,children:(0,_.jsx)(`div`,{className:`prose prose-sm max-w-none
|
|
2
|
+
prose-headings:text-foreground prose-headings:font-bold
|
|
3
|
+
prose-p:text-foreground/90
|
|
4
|
+
prose-a:text-accent-primary prose-a:no-underline hover:prose-a:underline
|
|
5
|
+
prose-strong:text-foreground
|
|
6
|
+
prose-code:text-accent-info prose-code:bg-card prose-code:px-1 prose-code:py-0.5 prose-code:rounded prose-code:text-xs
|
|
7
|
+
prose-pre:bg-card prose-pre:border prose-pre:border-border prose-pre:rounded-md prose-pre:p-0 prose-pre:overflow-x-auto
|
|
8
|
+
prose-blockquote:border-l-accent-primary prose-blockquote:text-muted-foreground
|
|
9
|
+
prose-hr:border-border
|
|
10
|
+
prose-th:text-foreground prose-td:text-foreground/90
|
|
11
|
+
prose-li:text-foreground/90`,children:(0,_.jsx)(b,{content:s.content,currentCategory:s.category,onNavigateDoc:(e,t)=>p(`/docs/${e}/${t}`)})})}):null}function S(){let{category:e,slug:t}=r(),{i18n:n}=o(`integrations`),i=n.language||`en`,[a,s]=(0,g.useState)(null),[c,u]=(0,g.useState)(!0),d=(0,g.useRef)(null);(0,g.useEffect)(()=>{fetch(`/api/docs?lang=${encodeURIComponent(i)}`).then(e=>e.json()).then(e=>s(e)).catch(()=>s({categories:[]})).finally(()=>u(!1))},[i]);let f=!!(e&&t);return(0,_.jsxs)(`div`,{className:`flex h-full overflow-hidden`,children:[c?(0,_.jsx)(`div`,{className:`w-56 flex-shrink-0 border-r border-border flex items-center justify-center`,children:(0,_.jsx)(l,{className:`w-3.5 h-3.5 animate-spin text-muted-foreground`})}):(0,_.jsx)(v,{categories:a?.categories??[],activeCategory:e,activeSlug:t}),(0,_.jsx)(`main`,{ref:d,className:`flex-1 overflow-y-auto`,children:f&&e&&t?(0,_.jsx)(x,{category:e,slug:t,lang:i,scrollContainerRef:d}):a&&(0,_.jsx)(y,{categories:a.categories})})]})}export{S as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e}from"./jsx-runtime-zu2_FqZY.js";import{i as t}from"./chunk-KS7C4IRE-DEKu087k.js";var n=e();function r(){return(0,n.jsx)(t,{to:`/plugins`,replace:!0})}export{r as default};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-zu2_FqZY.js";import{o as r,w as i}from"./i18n-DwgvwTnx.js";import{n as a,t as o}from"./createLucideIcon-Bjbbp_KS.js";import{n as s}from"./dist-bVqfYmby.js";import{X as c,at as l,it as u}from"./TicketDetailModal-BvZoyDAL.js";import{d,u as f}from"./MinimizedChatsContext-CcjBHMHd.js";import{t as p}from"./brain-DI9lHkKY.js";import{n as m}from"./file-text-BcLCfcWZ.js";import{t as h}from"./circle-x-CMYsN4ZH.js";import{t as g}from"./git-branch-BRM0F5GN.js";import{t as _}from"./loader-circle-DcygOQpC.js";import{t as v}from"./play-DNlrawbS.js";import{t as y}from"./search-Cq_gE3Ik.js";import{t as b}from"./triangle-alert-H9T4jAmh.js";import{t as x}from"./x-CBMI9ejn.js";import{a as S}from"./auth-D_5bQv5W.js";import{a as C,r as w}from"./useDesktop-BzX769yH.js";import{t as T}from"./button-CJqFnUOL.js";import{t as E}from"./utils-BC4DHlz2.js";import{n as D,t as O}from"./lib-CGdyxIWg.js";import{C as k,Et as A,I as j,N as M,Ot as N,P,Q as F,S as ee,St as te,Tt as I,_ as L,at as R,c as z,et as ne,gt as re,l as ie,o as ae,ot as oe,s as se,st as ce}from"./index-DhjjFyU5.js";import{t as le}from"./lib-C7Mhm-gT.js";var ue=o(`chevrons-down-up`,[[`path`,{d:`m7 20 5-5 5 5`,key:`13a0gw`}],[`path`,{d:`m7 4 5 5 5-5`,key:`1kwcof`}]]),de=o(`chevrons-up-down`,[[`path`,{d:`m7 15 5 5 5-5`,key:`1hf1tw`}],[`path`,{d:`m7 9 5-5 5 5`,key:`sgt6xg`}]]),fe=o(`circle-dot`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}]]),pe=o(`hourglass`,[[`path`,{d:`M5 22h14`,key:`ehvnwv`}],[`path`,{d:`M5 2h14`,key:`pdyrp9`}],[`path`,{d:`M17 22v-4.172a2 2 0 0 0-.586-1.414L12 12l-4.414 4.414A2 2 0 0 0 7 17.828V22`,key:`1d314k`}],[`path`,{d:`M7 2v4.172a2 2 0 0 0 .586 1.414L12 12l4.414-4.414A2 2 0 0 0 17 6.172V2`,key:`1vvvr6`}]]),B=n();function me({phases:e,phaseDefinitions:t}){return t.length===0?null:(0,B.jsx)(`div`,{className:`flex items-center`,children:t.map((n,r)=>{let i=e[n.key]??`idle`,a=r<t.length-1?e[t[r+1].key]??`idle`:null;return(0,B.jsxs)(`div`,{className:`flex items-center`,children:[(0,B.jsxs)(M,{children:[(0,B.jsx)(j,{asChild:!0,children:(0,B.jsxs)(`div`,{className:`flex flex-col items-center gap-1.5 cursor-default px-4`,children:[(0,B.jsx)(he,{state:i}),(0,B.jsx)(`span`,{className:E(`text-xs font-medium transition-colors`,i===`running`?`text-blue-400 aurora-light:text-accent-info`:i===`done`?`text-emerald-400 aurora-light:text-accent-success`:i===`error`?`text-red-400 aurora-light:text-destructive`:`text-muted-foreground/40`),children:n.label})]})}),(0,B.jsxs)(P,{side:`bottom`,className:`max-w-[200px]`,children:[(0,B.jsx)(`p`,{className:`font-medium`,children:n.label}),(0,B.jsx)(`p`,{className:`text-muted-foreground mt-0.5`,children:n.description})]})]}),a!==null&&(0,B.jsx)(`div`,{className:E(`h-px w-12 -mt-5 shrink-0 transition-all duration-300`,a===`done`||i===`done`?`bg-emerald-500/30 aurora-light:bg-accent-success/40`:a===`running`?`bg-blue-400/40 aurora-light:bg-accent-info/40`:`bg-border/30`)})]},n.key)})})}function he({state:e}){return(0,B.jsxs)(`div`,{className:E(`flex items-center justify-center w-10 h-10 rounded-full transition-all duration-300`,e===`running`?`bg-blue-500/10 aurora-light:bg-accent-info/10 ring-1 ring-blue-400/30 aurora-light:ring-accent-info/30 animate-pulse`:e===`done`?`bg-emerald-500/10 aurora-light:bg-accent-success/10`:e===`error`?`bg-red-500/10 aurora-light:bg-destructive/10`:`bg-muted/20`),children:[e===`running`&&(0,B.jsx)(_,{className:`w-6 h-6 text-blue-400 aurora-light:text-accent-info animate-spin`}),e===`done`&&(0,B.jsx)(N,{className:`w-6 h-6 text-emerald-400 aurora-light:text-accent-success`}),e===`error`&&(0,B.jsx)(h,{className:`w-6 h-6 text-red-400 aurora-light:text-destructive`}),e===`idle`&&(0,B.jsx)(u,{className:`w-6 h-6 text-muted-foreground/20`})]})}var V=e(t(),1);function ge(e){let t=e.trimStart();return!!(/^#{1,6}\s/.test(t)||/^[-*+]\s/.test(t)||/^\d+\.\s/.test(t)||/^\|.+\|/.test(t)||t.startsWith("```")||t.startsWith(`> `)||/\*\*[^*]+\*\*/.test(e)||/`[^`]+`/.test(e)||/\[.+\]\(.+\)/.test(e)||/^(-{3,}|_{3,}|\*{3,})$/.test(t)||/^- \[[ x]\]\s/.test(t))}var _e=new Set;function ve({ticketId:e,onOpen:t,children:n}){let{t:r}=a(`agent`),i=r(`refs.openTicket`,{id:e});return(0,B.jsx)(`button`,{type:`button`,"data-testid":`log-ticket-ref`,onClick:n=>{n.stopPropagation(),t(e)},title:i,"aria-label":i,className:`inline cursor-pointer p-0 align-baseline text-accent-primary/90 underline decoration-accent-primary/50 decoration-dotted underline-offset-2 transition-colors hover:text-accent-primary hover:decoration-solid`,children:n})}function ye(e){if(!e.includes(`#`))return null;let t=z(e,_e);return t.some(e=>e.kind===`ticket`)?t:null}function be(e,t){let n=ye(e);return n?n.map((e,n)=>e.kind===`ticket`?(0,B.jsx)(ve,{ticketId:e.ticketId,onOpen:t,children:e.label},n):(0,B.jsx)(V.Fragment,{children:e.kind===`text`?e.text:e.label},n)):e}var xe=new Set([`code`,`inlineCode`,`link`,`linkReference`,`image`,`imageReference`,`definition`,`html`]);function Se(e){return e.kind===`ticket`?{type:`link`,url:ae({kind:`ticket`,ticketId:e.ticketId}),children:[{type:`text`,value:e.label}]}:{type:`text`,value:e.kind===`text`?e.text:e.label}}function Ce(e){let t=e.children;if(t)for(let e=t.length-1;e>=0;e--){let n=t[e];if(!xe.has(n.type))if(n.type===`text`&&typeof n.value==`string`){let r=z(n.value,_e);r.some(e=>e.kind===`ticket`)&&t.splice(e,1,...r.map(Se))}else Ce(n)}}function we(){return e=>Ce(e)}function Te(e){let{activeProjectId:t}=w(),{openRef:n}=ie(),r=e??t??void 0;return(0,V.useMemo)(()=>r?e=>{n(r,{kind:`ticket`,ticketId:e})}:void 0,[r,n])}function H(e,t){let n=`${e.id??t}`,i=e.timestamp;if(e.event_type===`log`)try{let t=JSON.parse(e.payload).line??``;return t.trim()?t.startsWith(`▸`)||t.match(/^(architect|developer|reviewer|ship|analyst)\s*:/i)?{id:n,content:t,type:`phase`,timestamp:i}:e.source===`stderr`?{id:n,content:t,type:`stderr`,timestamp:i}:ge(t)?{id:n,content:t,type:`assistant`,timestamp:i}:{id:n,content:t,type:`plain`,timestamp:i}:null}catch{return null}if(e.event_type!==`log`&&e.event_type!==`result`)return null;if(e.event_type===`result`)try{let t=JSON.parse(e.payload),a=[];return t.duration_ms&&a.push(`${(t.duration_ms/1e3).toFixed(1)}s`),t.total_cost_usd&&a.push(`$${t.total_cost_usd.toFixed(4)}`),t.num_turns&&a.push(r.t(`jobs:logViewer.turns`,{count:t.num_turns})),{id:n,content:`▸ ${r.t(`jobs:logViewer.completed`)}${a.length?` — ${a.join(` · `)}`:``}`,type:`result`,timestamp:i}}catch{return null}return null}function Ee(e){let t=`none`,n=[];for(let r of e){let e=r.type;if(e!==`plain`&&e!==`log`){t=`none`,n.push(r);continue}let i=r.content;i.startsWith(`--- `)?(t=`saw_minus`,n.push({...r,type:`diff-meta`})):t===`saw_minus`&&i.startsWith(`+++ `)?(t=`active`,n.push({...r,type:`diff-meta`})):t===`active`&&i.startsWith(`@@ `)?n.push({...r,type:`diff-hunk`}):t===`active`&&i.startsWith(`+`)&&!i.startsWith(`+++`)?n.push({...r,type:`diff-add`}):t===`active`&&i.startsWith(`-`)&&!i.startsWith(`---`)?n.push({...r,type:`diff-remove`}):(t===`active`&&(i.startsWith(` `)||i===``)||(t=`none`),n.push(r))}return n}function De(e){let t=[];for(let n of e){let e=t.length>0?t[t.length-1]:null;n.type===`assistant`&&e?.type===`assistant`?e.content+=`
|
|
2
|
+
`+n.content:t.push({...n})}return t}function Oe(e){let t=[{key:`__preamble__`,header:null,lines:[]}];for(let n of e)n.type===`phase`?t.push({key:n.id,header:n,lines:[]}):t[t.length-1].lines.push(n);return t.filter(e=>e.header!==null||e.lines.length>0)}function ke({events:e,isLoading:t,projectId:n}){let{t:r,i18n:i}=a(`jobs`),[o,c]=(0,V.useState)(``),[l,u]=(0,V.useState)(!0),[d,p]=(0,V.useState)(new Set),m=(0,V.useRef)(null),h=(0,V.useRef)(null),g=Te(n),{processedLines:_,groups:v,totalLines:b}=(0,V.useMemo)(()=>{let t=Ee(De(e.map((e,t)=>H(e,t)).filter(e=>e!==null)));return{processedLines:t,groups:Oe(t),totalLines:t.length}},[e,i.language]),x=(0,V.useMemo)(()=>{if(!o)return b;let e=o.toLowerCase();return _.filter(t=>t.content.toLowerCase().includes(e)).length},[o,_,b]),S=(0,V.useCallback)(()=>{let e=h.current;e&&(e.scrollTop=e.scrollHeight)},[]);(0,V.useEffect)(()=>{l&&S()},[e.length,l,S]);function C(){let e=h.current;if(!e)return;let t=e.scrollHeight-e.scrollTop-e.clientHeight<50;u(t)}function w(e){p(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}return t?(0,B.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(`logViewer.loading`)})}):b===0?(0,B.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(`logViewer.empty`)})}):(0,B.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,B.jsxs)(`div`,{className:`px-4 py-2 border-b border-border flex items-center gap-2`,children:[(0,B.jsxs)(`div`,{className:`relative flex-1 max-w-xs`,children:[(0,B.jsx)(y,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 w-3 h-3 text-muted-foreground`}),(0,B.jsx)(L,{placeholder:r(`logViewer.filterPlaceholder`),value:o,onChange:e=>c(e.target.value),className:`pl-7 h-7`})]}),(0,B.jsx)(T,{variant:`ghost`,size:`sm`,className:`h-7 px-2 text-muted-foreground/50 hover:text-foreground`,onClick:()=>{let e=_.map(e=>e.content).join(`
|
|
3
|
+
`);navigator.clipboard.writeText(e).then(()=>{s.success(r(`logViewer.copySuccess`))}).catch(()=>{s.error(r(`logViewer.copyFailed`))})},children:(0,B.jsx)(I,{className:`w-3.5 h-3.5`})}),(0,B.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:r(`logViewer.lineCount`,{filtered:x,total:b})})]}),(0,B.jsxs)(`div`,{ref:h,className:`flex-1 overflow-y-auto p-2 text-xs relative`,onScroll:C,children:[v.map(e=>(0,B.jsx)(Ae,{group:e,filter:o,collapsed:d.has(e.key),onToggle:()=>w(e.key),onOpenTicket:g},e.key)),(0,B.jsx)(`div`,{ref:m})]}),!l&&(0,B.jsxs)(T,{size:`sm`,variant:`secondary`,onClick:()=>{u(!0),S()},className:`absolute bottom-16 right-6 h-7 gap-1 shadow-lg`,children:[(0,B.jsx)(f,{className:`w-3 h-3`}),r(`logViewer.jumpToBottom`)]})]})}var Ae=(0,V.memo)(function({group:e,filter:t,collapsed:n,onToggle:r,onOpenTicket:i}){let{t:o}=a(`jobs`),s=t?e.lines.filter(e=>e.content.toLowerCase().includes(t.toLowerCase())):e.lines;if(e.header===null)return s.length===0?null:(0,B.jsx)(`div`,{children:s.map((e,t)=>(0,B.jsx)(U,{line:e,even:t%2==0,onOpenTicket:i},e.id))});let c=e.header.content;return(0,B.jsxs)(`div`,{className:`mt-3 rounded-md overflow-hidden border border-border/20`,children:[(0,B.jsxs)(`button`,{type:`button`,onClick:r,className:E(`flex items-center gap-2 w-full text-left px-3 py-2`,`bg-primary/5 border-b border-primary/20`,`hover:bg-primary/10 transition-colors duration-150 cursor-pointer`),children:[(0,B.jsx)(m,{className:E(`w-3 h-3 text-primary/60 shrink-0 transition-transform duration-150`,!n&&`rotate-90`)}),(0,B.jsx)(`span`,{className:`flex-1 text-[12px] font-semibold text-foreground leading-none`,children:c}),e.header.timestamp&&(0,B.jsx)(`span`,{className:`text-[10px] text-muted-foreground/40 font-mono tabular-nums shrink-0`,children:new Date(e.header.timestamp).toLocaleTimeString(`en`,{hour:`2-digit`,minute:`2-digit`,second:`2-digit`,hour12:!1})}),(0,B.jsx)(`span`,{className:`text-[10px] text-muted-foreground/40 shrink-0`,children:o(`logViewer.phaseLines`,{count:e.lines.length})})]}),!n&&(0,B.jsx)(`div`,{className:`bg-muted/5`,children:s.length===0?(0,B.jsx)(`p`,{className:`px-4 py-2 text-[10px] text-muted-foreground/40 italic`,children:o(t?`logViewer.noMatchingLines`:`logViewer.noOutput`)}):s.map((e,t)=>(0,B.jsx)(U,{line:e,even:t%2==0,onOpenTicket:i},e.id))})]})}),je=[le],Me=[O],Ne=[O,we],U=(0,V.memo)(function({line:e,even:t,onOpenTicket:n}){let r=e.type===`assistant`,i=e.type===`diff-add`,a=e.type===`diff-remove`,o=e.type===`diff-meta`,s=e.type===`diff-hunk`,c=i||a||o||s,l=n!=null&&(e.type===`plain`||e.type===`log`),u=(0,V.useMemo)(()=>l&&n?be(e.content,n):e.content,[l,n,e.content]),d=r&&n?Ne:Me,f=(0,V.useMemo)(()=>n?{a:({href:e,children:t})=>{let r=se(e);return r?.kind===`ticket`?(0,B.jsx)(ve,{ticketId:r.ticketId,onOpen:n,children:t}):(0,B.jsx)(`a`,{href:e,children:t})}}:void 0,[n]);return(0,B.jsxs)(`div`,{className:E(`flex items-start gap-2 group px-2 py-0.5 rounded-sm`,!c&&(t?`bg-muted/20`:`bg-transparent`),e.type===`result`&&`bg-emerald-500/5 aurora-light:bg-accent-success/10 border-l-2 border-emerald-500/40 aurora-light:border-accent-success/40 mt-2 py-2`,i&&`bg-emerald-500/8 aurora-light:bg-accent-success/10 border-l-2 border-emerald-500/50 aurora-light:border-accent-success/50`,a&&`bg-red-500/8 aurora-light:bg-destructive/10 border-l-2 border-red-500/50 aurora-light:border-destructive/50`,o&&`bg-accent-primary/5 border-l-2 border-accent-primary/30`,s&&`bg-accent-info/5 border-l-2 border-accent-info/30`),children:[e.timestamp&&(0,B.jsx)(`span`,{className:`text-[10px] text-muted-foreground/40 shrink-0 mt-0.5 w-[52px] font-mono tabular-nums`,children:new Date(e.timestamp).toLocaleTimeString(`en`,{hour:`2-digit`,minute:`2-digit`,second:`2-digit`,hour12:!1})}),r?(0,B.jsx)(`div`,{className:`flex-1 min-w-0 prose prose-invert prose-xs max-w-none
|
|
4
|
+
prose-p:my-1 prose-p:leading-relaxed
|
|
5
|
+
prose-headings:mt-2 prose-headings:mb-1 prose-headings:text-sm prose-headings:font-semibold
|
|
6
|
+
prose-ul:my-1 prose-ol:my-1 prose-li:my-0
|
|
7
|
+
prose-code:text-cyan-300 prose-code:text-[11px] prose-code:bg-muted/40 prose-code:px-1 prose-code:py-0.5 prose-code:rounded
|
|
8
|
+
prose-pre:my-1 prose-pre:bg-muted/30 prose-pre:rounded-md prose-pre:p-2 prose-pre:text-[11px]
|
|
9
|
+
prose-strong:text-foreground prose-em:text-foreground/70
|
|
10
|
+
prose-a:text-blue-400 prose-a:no-underline hover:prose-a:underline
|
|
11
|
+
prose-table:my-2 prose-table:text-[11px]
|
|
12
|
+
prose-thead:border-border prose-thead:bg-muted/30
|
|
13
|
+
prose-th:px-3 prose-th:py-1.5 prose-th:text-left prose-th:font-semibold prose-th:text-foreground/90
|
|
14
|
+
prose-td:px-3 prose-td:py-1.5 prose-td:border-border
|
|
15
|
+
prose-tr:border-border
|
|
16
|
+
text-foreground/80`,children:(0,B.jsx)(D,{remarkPlugins:d,rehypePlugins:je,components:f,children:e.content})}):(0,B.jsx)(`span`,{className:E(`flex-1 break-all leading-relaxed whitespace-pre-wrap font-mono`,e.type===`tool-use`&&`text-cyan-400/80 aurora-light:text-accent-info text-[11px]`,e.type===`stderr`&&`text-orange-400 aurora-light:text-accent-warning`,e.type===`result`&&`text-emerald-400 aurora-light:text-accent-success font-medium`,e.type===`log`&&`text-foreground/60`,e.type===`plain`&&`text-foreground/70`,e.type===`tool-result`&&`text-muted-foreground/50`,i&&`text-emerald-400 aurora-light:text-accent-success`,a&&`text-red-400 aurora-light:text-destructive`,o&&`text-accent-primary/80`,s&&`text-accent-info/80`),children:u})]})});function W(e){try{let t=JSON.parse(e);if(t&&typeof t==`object`&&!Array.isArray(t))return t}catch{}return null}var Pe=/^\s*━+\s*Step\s+\d+\s*·/,Fe=/\s*\(iteration\s+\d+\)\s*$/i;function G(e){return e.replace(/^[\s\uFE0F\p{Extended_Pictographic}]+/u,``).trim()||e.trim()}function K(e){let t=G(e.title);return e.iteration==null?t:t.replace(Fe,``)}function Ie(e){return e.meta.nodeId??`${e.meta.kind}::${G(e.meta.title).replace(Fe,``)}`}function Le(e){let t=null,n=0,r=[[]],i=[];for(let a=0;a<e.length;a++){let o=e[a];if(o.event_type===`loop_graph`){let e=W(o.payload);e&&e.graph&&typeof e.graph==`object`&&!Array.isArray(e.graph)&&(t={graph:e.graph,loopId:typeof e.loopId==`string`?e.loopId:void 0,loopName:typeof e.loopName==`string`?e.loopName:void 0,provider:typeof e.provider==`string`?e.provider:void 0,model:typeof e.model==`string`?e.model:void 0,iterationLimit:typeof e.iterationLimit==`number`?e.iterationLimit:void 0});continue}if(o.event_type===`loop_step`){let e=W(o.payload);if(!e||typeof e.index!=`number`)continue;let t=typeof e.iteration==`number`?e.iteration:null;t!=null&&t>n&&(n=t),i.push({meta:{index:e.index,kind:typeof e.kind==`string`?e.kind:`ai-step`,title:typeof e.title==`string`?e.title:``,nodeId:typeof e.nodeId==`string`?e.nodeId:null,iteration:t,template:typeof e.template==`string`&&e.template?e.template:void 0,command:typeof e.command==`string`&&e.command?e.command:void 0},end:null,lastActivity:null}),r.push([]);continue}if(o.event_type===`loop_step_end`){let e=W(o.payload);if(!e||typeof e.index!=`number`)continue;for(let t=i.length-1;t>=0;t--)if(i[t].meta.index===e.index){i[t].end={index:e.index,nodeId:typeof e.nodeId==`string`?e.nodeId:null,status:e.status===`failed`?`failed`:`ok`,exitCode:typeof e.exitCode==`number`?e.exitCode:null,durationMs:typeof e.durationMs==`number`?e.durationMs:null,decision:e.decision===`continue`||e.decision===`stop`?e.decision:void 0};break}continue}let s=i.length>0,c=H(o,a);if(c&&!(s&&Pe.test(c.content))&&r[r.length-1].push(c),s){let e=k(o);e.step&&e.actionKey&&(i[i.length-1].lastActivity={actionKey:e.actionKey,actionArg:e.actionArg})}}let a=e=>Ee(De(e)),o=a(r[0]),s=i.map((e,t)=>({key:`step-${t}-${e.meta.index}`,meta:e.meta,lines:a(r[t+1]),end:e.end,lastActivity:e.lastActivity})),c=o.length+s.reduce((e,t)=>e+t.lines.length,0);return{graphMeta:t,setup:o,segments:s,maxIteration:n,totalLines:c}}function Re(e,t){return e.end?e.end.status:t.isLast?t.jobSettled?`interrupted`:`running`:`unknown`}function ze(e){return e===`continue`?0:e===`stop`?2:1}function Be(e){let t=new Map(e.nodes.map(e=>[e.id,e])),n=new Set,r=[],i=a=>{if(n.has(a))return;let o=t.get(a);if(!o)return;n.add(a),r.push(o);let s=e.edges.filter(e=>e.source===a).slice().sort((e,t)=>ze(e.branch)-ze(t.branch));for(let e of s)i(e.target)},a=e.nodes.find(e=>e.type===`start`);a&&i(a.id);for(let t of e.nodes)i(t.id);return r}function q(e){let t=e.data?.label;return typeof t==`string`&&t.trim()?t.trim():null}function Ve(e,t){let n=e.segments.length-1,r=new Map,i=new Map;e.segments.forEach((e,t)=>{let n=Ie(e);r.set(n,{seg:e,idx:t}),e.meta.kind===`decider`&&e.end?.decision&&i.set(n,e.end.decision)});let a=e=>{let r=Re(e.seg,{isLast:e.idx===n,jobSettled:t.jobSettled});return r===`unknown`?`ok`:r};if(e.graphMeta)return Be(e.graphMeta.graph).map(e=>{if(e.type===`start`)return{key:e.id,kind:`start`,label:q(e),state:`ok`,latestSegmentKey:null};if(e.type===`end`)return{key:e.id,kind:`end`,label:q(e),state:t.jobSettled?t.jobFailed?`failed`:`ok`:`pending`,latestSegmentKey:null};let n=r.get(e.id);return n?{key:e.id,kind:e.type,label:q(e)??K(n.seg.meta),state:a(n),decision:e.type===`decider`?i.get(e.id):void 0,latestSegmentKey:n.seg.key}:{key:e.id,kind:e.type,label:q(e),state:`pending`,latestSegmentKey:null}});let o=[],s=new Map;return e.segments.forEach((e,t)=>{let n=Ie(e),r={seg:e,idx:t},c=s.get(n),l=e.meta.kind===`decider`?i.get(n):void 0;if(c!=null){let t=o[c];t.state=a(r),t.decision=l,t.latestSegmentKey=e.key}else s.set(n,o.length),o.push({key:n,kind:e.meta.kind,label:K(e.meta)||null,state:a(r),decision:l,latestSegmentKey:e.key})}),o}function He(e){if(!Number.isFinite(e)||e<0)return`—`;if(e<1e3)return`${Math.round(e)}ms`;let t=e/1e3;if(t<60)return`${t.toFixed(1)}s`;let n=Math.floor(t/60),r=Math.round(t%60);return n<60?`${n}m ${r}s`:`${Math.floor(n/60)}h ${n%60}m`}var Ue={start:v,"ai-step":p,shell:F,decider:g,condition:g,end:te},We=ne,Ge={start:`text-accent-success`,"ai-step":`text-accent-primary`,shell:`text-accent-warning`,decider:`text-accent-highlight`,condition:`text-accent-info`,end:`text-accent-secondary`},Ke={start:`border-accent-success/60`,"ai-step":`border-accent-primary/60`,shell:`border-accent-warning/60`,decider:`border-accent-highlight/60`,condition:`border-accent-info/60`,end:`border-accent-secondary/60`};function qe(e){return Ue[e]??We}function Je({chips:e,iteration:t,onChipClick:n,variant:r}){let{t:i}=a(`jobs`);return e.length===0&&!t?null:(0,B.jsxs)(`div`,{"data-testid":`loop-overview-strip`,role:`list`,"aria-label":i(`loopExplorer.stepMapAria`),className:E(`flex items-center gap-1 overflow-x-auto border-b border-border/30 bg-surface/20`,r===`glass`?`px-3 py-1.5`:`px-4 py-2`),children:[e.map((e,t)=>{let r=qe(e.kind),a=Ge[e.kind]??`text-foreground`,o=Ke[e.kind]??`border-border/40`,s=e.label??i(`loops:builder.nodes.${e.kind}`,{defaultValue:e.kind}),u=e.latestSegmentKey!=null;return(0,B.jsxs)(V.Fragment,{children:[t>0&&(0,B.jsx)(m,{className:`w-3 h-3 text-muted-foreground/30 shrink-0`}),(0,B.jsxs)(`button`,{type:`button`,role:`listitem`,"data-testid":`loop-node-chip`,"data-state":e.state,"data-kind":e.kind,"data-decision":e.decision,"aria-label":`${s} — ${e.state}`,disabled:!u,onClick:()=>e.latestSegmentKey&&n(e.latestSegmentKey),className:E(`relative flex items-center gap-1.5 shrink-0 rounded-full border bg-surface/40 px-2.5 py-1 text-[11px] transition-colors`,o,e.state===`pending`&&`opacity-45 border-border/40`,e.state===`interrupted`&&`border-dashed border-accent-warning/50`,u?`cursor-pointer hover:bg-surface/70`:`cursor-default`),children:[e.state===`running`&&(0,B.jsx)(`span`,{"aria-hidden":!0,className:`absolute -inset-px rounded-full ring-2 ring-accent-primary/50 motion-safe:animate-pulse pointer-events-none`}),(0,B.jsx)(r,{className:E(`w-3 h-3 shrink-0`,a)}),(0,B.jsx)(`span`,{className:E(`max-w-[120px] truncate font-medium text-foreground/90`,e.state===`running`&&`title-shimmer`),children:s}),e.state===`ok`&&(0,B.jsx)(d,{className:`w-3 h-3 text-accent-success shrink-0`}),e.state===`failed`&&(0,B.jsx)(x,{className:`w-3 h-3 text-destructive shrink-0`}),e.decision===`continue`&&(0,B.jsx)(c,{className:`w-3 h-3 text-accent-highlight shrink-0`}),e.decision===`stop`&&(0,B.jsx)(l,{className:`w-3 h-3 text-accent-success shrink-0`})]})]},e.key)}),t&&(0,B.jsxs)(`span`,{"data-testid":`loop-iteration-chip`,className:`ml-auto flex items-center gap-1.5 shrink-0 rounded-full border border-accent-highlight/40 bg-accent-highlight/10 px-2.5 py-1 text-[10px] font-medium text-accent-highlight tabular-nums`,children:[(0,B.jsx)(ce,{className:`w-3 h-3`}),t.limit==null?i(`loopExplorer.iterationBadge`,{count:t.current}):i(`loopExplorer.iteration`,{current:t.current,limit:t.limit})]})]})}var Ye=(0,V.memo)(Je);function Xe({className:e}){return(0,B.jsxs)(`span`,{className:E(`relative flex h-2 w-2 shrink-0`,e),children:[(0,B.jsx)(`span`,{className:`motion-safe:animate-ping absolute inline-flex h-full w-full rounded-full bg-accent-primary opacity-60`}),(0,B.jsx)(`span`,{className:`relative inline-flex rounded-full h-2 w-2 bg-accent-primary`})]})}function Ze(e,t){if(!t)return e;let n=t.toLowerCase();return e.filter(e=>e.content.toLowerCase().includes(n))}function Qe(e,t,n,r){return e.length===0?(0,B.jsx)(`p`,{className:`px-4 py-2 text-[10px] text-muted-foreground/40 italic`,children:n(t?`logViewer.noMatchingLines`:`logViewer.noOutput`)}):e.map((e,t)=>(0,B.jsx)(U,{line:e,even:t%2==0,onOpenTicket:r},e.id))}function $e({label:e,value:t,copyLabel:n}){let[r,i]=(0,V.useState)(!1),a=async()=>{try{await navigator.clipboard.writeText(t),i(!0),window.setTimeout(()=>i(!1),1500)}catch{}};return(0,B.jsxs)(`div`,{className:`min-w-0`,children:[(0,B.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,B.jsx)(`span`,{className:`text-[9px] font-semibold uppercase tracking-wider text-muted-foreground/50`,children:e}),(0,B.jsx)(`button`,{type:`button`,onClick:()=>void a(),"aria-label":`${n} — ${e}`,title:n,className:`p-0.5 text-muted-foreground/40 hover:text-foreground transition-colors cursor-pointer`,children:r?(0,B.jsx)(d,{className:`w-2.5 h-2.5 text-accent-success`}):(0,B.jsx)(I,{className:`w-2.5 h-2.5`})})]}),(0,B.jsx)(`pre`,{className:`mt-0.5 text-[10px] font-mono leading-relaxed text-foreground/75 whitespace-pre-wrap break-words`,children:t})]})}function et({segment:e,status:t,collapsed:n,filter:r,onToggle:i,onCopy:o,setRef:s,onOpenTicket:c}){let{t:l}=a(`jobs`),{meta:u,lines:f,end:p,lastActivity:h}=e,g=qe(u.kind),_=Ge[u.kind]??`text-foreground`,v=Ze(f,r),y=t===`running`,b=!!(u.template||u.command),[S,C]=(0,V.useState)(!1);return(0,B.jsxs)(`div`,{ref:t=>s(e.key,t),"data-testid":`loop-step-section`,"data-status":t,"data-step-index":u.index,className:E(`mt-3 rounded-md overflow-hidden border animate-in fade-in duration-200`,t===`running`&&`border-accent-primary/40`,t===`failed`&&`border-destructive/30`,t===`interrupted`&&`border-dashed border-accent-warning/40`,(t===`ok`||t===`unknown`)&&`border-border/20`),children:[(0,B.jsxs)(`div`,{className:E(`flex items-stretch bg-primary/5 border-b`,t===`failed`?`border-destructive/20`:`border-primary/20`),children:[(0,B.jsxs)(`button`,{type:`button`,onClick:()=>i(e.key),className:`flex items-center gap-2 flex-1 min-w-0 text-left px-3 py-2 hover:bg-primary/10 transition-colors duration-150 cursor-pointer`,children:[(0,B.jsx)(m,{className:E(`w-3 h-3 text-primary/60 shrink-0 transition-transform duration-150`,!n&&`rotate-90`)}),(0,B.jsx)(`span`,{className:`text-[10px] font-mono tabular-nums text-muted-foreground/60 shrink-0 w-5 text-right`,children:u.index}),(0,B.jsx)(g,{className:E(`w-3.5 h-3.5 shrink-0`,_)}),(0,B.jsx)(`span`,{className:`text-[12px] font-semibold text-foreground leading-none truncate`,children:K(u)}),u.iteration!=null&&u.iteration>=1&&(0,B.jsx)(`span`,{className:`shrink-0 rounded-full bg-muted/60 px-1.5 py-0.5 text-[9px] font-medium text-muted-foreground tabular-nums`,children:l(`loopExplorer.iterationBadge`,{count:u.iteration})}),y&&(0,B.jsxs)(`span`,{className:`flex items-center gap-1.5 min-w-0 shrink-0 max-w-[40%]`,children:[(0,B.jsx)(Xe,{}),h&&(0,B.jsx)(`span`,{className:`title-shimmer text-[10px] truncate`,children:l(`statusPanel.activity.${h.actionKey}`,{arg:h.actionArg??``})})]}),t===`ok`&&(0,B.jsx)(d,{className:`w-3.5 h-3.5 text-accent-success shrink-0`}),t===`failed`&&(0,B.jsx)(x,{className:`w-3.5 h-3.5 text-destructive shrink-0`}),t===`interrupted`&&(0,B.jsx)(`span`,{className:`shrink-0 rounded border border-dashed border-accent-warning/50 px-1.5 py-0.5 text-[9px] font-medium uppercase tracking-wide text-accent-warning`,children:l(`loopExplorer.interrupted`)}),(0,B.jsx)(`span`,{className:`flex-1`}),p?.durationMs!=null&&(0,B.jsx)(`span`,{className:`text-[10px] text-muted-foreground/50 font-mono tabular-nums shrink-0`,children:He(p.durationMs)}),t===`failed`&&p?.exitCode!=null&&p.exitCode!==0&&(0,B.jsx)(`span`,{className:`text-[10px] text-destructive/70 font-mono shrink-0`,children:l(`activeJob.exitCode`,{code:p.exitCode})}),(0,B.jsx)(`span`,{className:`text-[10px] text-muted-foreground/40 shrink-0`,children:l(`logViewer.phaseLines`,{count:f.length})})]}),b&&(0,B.jsx)(`button`,{type:`button`,onClick:()=>C(e=>!e),"aria-label":l(`loopExplorer.stepDetail`),"aria-expanded":S,title:l(`loopExplorer.stepDetail`),className:E(`px-2 flex items-center transition-colors cursor-pointer`,S?`text-foreground bg-primary/10`:`text-muted-foreground/40 hover:text-foreground hover:bg-primary/10`),children:(0,B.jsx)(re,{className:`w-3 h-3`})}),(0,B.jsx)(`button`,{type:`button`,onClick:()=>o(e.key),"aria-label":l(`loopExplorer.copyStep`),title:l(`loopExplorer.copyStep`),className:`px-2.5 flex items-center text-muted-foreground/40 hover:text-foreground hover:bg-primary/10 transition-colors cursor-pointer`,children:(0,B.jsx)(I,{className:`w-3 h-3`})})]}),S&&b&&(0,B.jsxs)(`div`,{"data-testid":`loop-step-detail`,className:E(`px-4 py-2.5 space-y-2.5 bg-muted/10 border-b animate-in fade-in duration-150`,t===`failed`?`border-destructive/20`:`border-primary/10`),children:[u.template&&(0,B.jsx)($e,{label:l(`loopExplorer.stepDetailTemplate`),value:u.template,copyLabel:l(`loopExplorer.copyCommand`)}),u.command&&(0,B.jsx)($e,{label:l(`loopExplorer.stepDetailCommand`),value:u.command,copyLabel:l(`loopExplorer.copyCommand`)})]}),!n&&(0,B.jsx)(`div`,{className:`bg-muted/5`,children:Qe(v,r,l,c)})]})}var tt=(0,V.memo)(et,(e,t)=>e.segment.key===t.segment.key&&e.segment.lines.length===t.segment.lines.length&&e.segment.lines[e.segment.lines.length-1]?.content===t.segment.lines[t.segment.lines.length-1]?.content&&e.segment.meta.template===t.segment.meta.template&&e.segment.meta.command===t.segment.meta.command&&e.segment.end?.status===t.segment.end?.status&&e.segment.end?.durationMs===t.segment.end?.durationMs&&e.segment.end?.decision===t.segment.end?.decision&&e.segment.end?.exitCode===t.segment.end?.exitCode&&e.segment.lastActivity?.actionKey===t.segment.lastActivity?.actionKey&&e.segment.lastActivity?.actionArg===t.segment.lastActivity?.actionArg&&e.status===t.status&&e.collapsed===t.collapsed&&e.filter===t.filter&&e.onOpenTicket===t.onOpenTicket),J=`__setup__`;function nt({lines:e,collapsed:t,filter:n,onToggle:r,setRef:i,onOpenTicket:o}){let{t:s}=a(`jobs`),c=Ze(e,n);return(0,B.jsxs)(`div`,{ref:e=>i(J,e),"data-testid":`loop-setup-section`,className:`rounded-md overflow-hidden border border-border/20`,children:[(0,B.jsxs)(`button`,{type:`button`,onClick:()=>r(J),className:`flex items-center gap-2 w-full text-left px-3 py-2 bg-muted/10 border-b border-border/20 hover:bg-muted/20 transition-colors duration-150 cursor-pointer`,children:[(0,B.jsx)(m,{className:E(`w-3 h-3 text-muted-foreground/60 shrink-0 transition-transform duration-150`,!t&&`rotate-90`)}),(0,B.jsx)(v,{className:`w-3.5 h-3.5 text-accent-success/70 shrink-0`}),(0,B.jsx)(`span`,{className:`text-[11px] font-semibold text-muted-foreground leading-none uppercase tracking-wide`,children:s(`loopExplorer.setup`)}),(0,B.jsx)(`span`,{className:`flex-1`}),(0,B.jsx)(`span`,{className:`text-[10px] text-muted-foreground/40 shrink-0`,children:s(`logViewer.phaseLines`,{count:e.length})})]}),!t&&(0,B.jsx)(`div`,{className:`bg-muted/5`,children:Qe(c,n,s,o)})]})}var rt=(0,V.memo)(nt,(e,t)=>e.lines.length===t.lines.length&&e.lines[e.lines.length-1]?.content===t.lines[t.lines.length-1]?.content&&e.collapsed===t.collapsed&&e.filter===t.filter&&e.onOpenTicket===t.onOpenTicket);function Y(){return(0,B.jsxs)(`span`,{className:`relative flex h-1.5 w-1.5 shrink-0`,children:[(0,B.jsx)(`span`,{className:`motion-safe:animate-ping absolute inline-flex h-full w-full rounded-full bg-accent-primary opacity-60`}),(0,B.jsx)(`span`,{className:`relative inline-flex rounded-full h-1.5 w-1.5 bg-accent-primary`})]})}function it({events:e,jobStatus:t,isLoading:n,variant:r=`page`,projectId:i}){let{t:o,i18n:c}=a(`jobs`),[l,u]=(0,V.useState)(``),[d,f]=(0,V.useState)(`follow`),[p,m]=(0,V.useState)(new Set),h=(0,V.useRef)(null),g=(0,V.useRef)(new Map),_=Te(i),v=(0,V.useMemo)(()=>Le(e),[e,c.language]),b=t!=null&&t!==`running`&&t!==`queued`,x=t===`running`,S=(0,V.useMemo)(()=>v.segments.map((e,t)=>Re(e,{isLast:t===v.segments.length-1,jobSettled:b})),[v,b]),C=(0,V.useMemo)(()=>{let e=v.segments.map(e=>e.key);return v.setup.length>0&&e.push(J),e},[v]),w=v.segments.length>0?v.segments[v.segments.length-1].key:J,D=(0,V.useMemo)(()=>l?new Set(C):d===`follow`?new Set([w]):p,[l,d,w,p,C]),O=(0,V.useRef)(D);O.current=D;let k=(0,V.useRef)(v);k.current=v;let A=(0,V.useCallback)(e=>{let t=new Set(O.current);e?.(t),m(t),f(`manual`)},[]),j=(0,V.useCallback)(e=>{A(t=>{t.has(e)?t.delete(e):t.add(e)})},[A]),M=(0,V.useCallback)(e=>{A(t=>t.add(e)),requestAnimationFrame(()=>{g.current.get(e)?.scrollIntoView?.({behavior:`smooth`,block:`start`})})},[A]),N=(0,V.useCallback)(()=>{let e=h.current;e&&(e.scrollTop=e.scrollHeight)},[]),P=(0,V.useCallback)(()=>{f(`follow`),requestAnimationFrame(N)},[N]),F=(0,V.useCallback)(()=>{m(new Set(C)),f(`manual`)},[C]),ee=(0,V.useCallback)(()=>{m(new Set),f(`manual`)},[]);(0,V.useEffect)(()=>{d===`follow`&&!l&&N()},[v.totalLines,v.segments.length,d,l,N]);let te=(0,V.useCallback)(()=>{let e=h.current;!e||d!==`follow`||e.scrollHeight-e.scrollTop-e.clientHeight>80&&A()},[d,A]),R=(0,V.useCallback)((e,t)=>{t?g.current.set(e,t):g.current.delete(e)},[]),z=(0,V.useCallback)(e=>{let t=k.current.segments.find(t=>t.key===e),n=e===`__setup__`?k.current.setup.map(e=>e.content).join(`
|
|
17
|
+
`):(t?.lines??[]).map(e=>e.content).join(`
|
|
18
|
+
`);navigator.clipboard.writeText(n).then(()=>s.success(o(`loopExplorer.copied`))).catch(()=>s.error(o(`logViewer.copyFailed`)))},[o]),ne=(0,V.useCallback)(()=>{let e=k.current,t=e.setup.map(e=>e.content);for(let n of e.segments){t.push(`── Step ${n.meta.index} · ${G(n.meta.title)} ──`);for(let e of n.lines)t.push(e.content)}navigator.clipboard.writeText(t.join(`
|
|
19
|
+
`)).then(()=>s.success(o(`logViewer.copySuccess`))).catch(()=>s.error(o(`logViewer.copyFailed`)))},[o]),re=(0,V.useMemo)(()=>Ve(v,{jobSettled:b,jobFailed:t===`failed`}),[v,b,t]),ie=v.graphMeta?.iterationLimit??v.graphMeta?.graph.config.maxIterations??null,ae=v.maxIteration>0?{current:v.maxIteration,limit:ie}:null,oe=(0,V.useMemo)(()=>{if(!l)return v.totalLines;let e=l.toLowerCase(),t=v.setup.filter(t=>t.content.toLowerCase().includes(e)).length;for(let n of v.segments)t+=n.lines.filter(t=>t.content.toLowerCase().includes(e)).length;return t},[l,v]),se=v.segments[v.segments.length-1],ce=x&&(v.segments.length===0||se?.end!=null);return n?(0,B.jsx)(`div`,{className:`flex-1 flex items-center justify-center h-full`,children:(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o(`logViewer.loading`)})}):v.totalLines===0&&v.segments.length===0?(0,B.jsx)(`div`,{"data-testid":`loop-step-explorer`,className:`flex-1 flex items-center justify-center h-full`,children:(0,B.jsxs)(`p`,{className:`text-xs text-muted-foreground flex items-center gap-2`,children:[x&&(0,B.jsx)(Y,{}),o(x?`loopExplorer.waiting`:`logViewer.empty`)]})}):(0,B.jsxs)(`div`,{"data-testid":`loop-step-explorer`,className:`relative flex flex-col h-full`,children:[(0,B.jsxs)(`div`,{className:E(`border-b border-border flex items-center gap-2`,r===`glass`?`px-3 py-1.5`:`px-4 py-2`),children:[(0,B.jsxs)(`div`,{className:`relative flex-1 max-w-xs`,children:[(0,B.jsx)(y,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 w-3 h-3 text-muted-foreground`}),(0,B.jsx)(L,{placeholder:o(`logViewer.filterPlaceholder`),value:l,onChange:e=>u(e.target.value),className:`pl-7 h-7`})]}),(0,B.jsx)(T,{variant:`ghost`,size:`sm`,className:`h-7 px-2 text-muted-foreground/50 hover:text-foreground`,onClick:F,"aria-label":o(`loopExplorer.expandAll`),title:o(`loopExplorer.expandAll`),children:(0,B.jsx)(de,{className:`w-3.5 h-3.5`})}),(0,B.jsx)(T,{variant:`ghost`,size:`sm`,className:`h-7 px-2 text-muted-foreground/50 hover:text-foreground`,onClick:ee,"aria-label":o(`loopExplorer.collapseAll`),title:o(`loopExplorer.collapseAll`),children:(0,B.jsx)(ue,{className:`w-3.5 h-3.5`})}),d===`follow`&&x&&(0,B.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[10px] text-accent-primary shrink-0`,children:[(0,B.jsx)(Y,{}),o(`loopExplorer.follow`)]}),(0,B.jsx)(`span`,{className:`flex-1`}),(0,B.jsx)(T,{variant:`ghost`,size:`sm`,className:`h-7 px-2 text-muted-foreground/50 hover:text-foreground`,onClick:ne,"aria-label":o(`logViewer.copySuccess`),children:(0,B.jsx)(I,{className:`w-3.5 h-3.5`})}),(0,B.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:o(`logViewer.lineCount`,{filtered:oe,total:v.totalLines})})]}),(0,B.jsx)(Ye,{chips:re,iteration:ae,onChipClick:M,variant:r}),(0,B.jsxs)(`div`,{ref:h,onScroll:te,className:`flex-1 overflow-y-auto p-2 text-xs`,children:[v.setup.length>0&&(0,B.jsx)(rt,{lines:v.setup,collapsed:!D.has(`__setup__`),filter:l,onToggle:j,setRef:R,onOpenTicket:_}),v.segments.map((e,t)=>(0,B.jsx)(tt,{segment:e,status:S[t],collapsed:!D.has(e.key),filter:l,onToggle:j,onCopy:z,setRef:R,onOpenTicket:_},e.key)),ce&&(0,B.jsxs)(`div`,{"data-testid":`loop-waiting-row`,className:`mt-3 flex items-center gap-2 px-3 py-2 text-[11px] text-muted-foreground/70 italic`,children:[(0,B.jsx)(Y,{}),o(`loopExplorer.waiting`)]})]}),d===`manual`&&x&&!l&&(0,B.jsxs)(`button`,{type:`button`,"data-testid":`resume-follow-pill`,onClick:P,className:`absolute bottom-4 left-1/2 -translate-x-1/2 z-10 flex items-center gap-1.5 rounded-full glass-card border border-accent-primary/30 px-3 py-1.5 text-[11px] font-medium text-foreground shadow-lg hover:border-accent-primary/60 transition-colors cursor-pointer animate-in fade-in slide-in-from-bottom-2 duration-200`,children:[(0,B.jsx)(Y,{}),o(`loopExplorer.resumeFollow`)]})]})}var at=new Set(`grep.rg.ag.ack.find.fd.ls.cat.head.tail.sed.awk.cut.sort.uniq.wc.jq.yq.tr.xargs.tee.column.less.more.cd.pwd.echo.printf.which.type.test.true.false.env.export.set.source.date.basename.dirname.realpath.readlink.stat.file.tree.diff.sleep.seq.hostname.whoami.uname.mkdir.rmdir.cp.mv.rm.touch.ln.chmod.chown.install.[[.[.]].].for.while.until.if.then.else.elif.fi.do.done.case.esac.exec.eval.trap.read.shift.wait`.split(`.`)),ot=new Set([`status`,`diff`,`log`,`show`,`branch`,`rev-parse`,`ls-files`,`blame`,`describe`]),st=new Set([...ot,`commit`,`add`,`stage`,`push`,`pull`,`fetch`,`checkout`,`switch`,`merge`,`rebase`,`reset`,`stash`,`tag`,`clone`,`worktree`,`cherry-pick`,`restore`,`apply`,`init`,`remote`,`config`,`update-ref`,`for-each-ref`]),ct=new Set([`run`,`run-script`,`test`,`install`,`ci`,`i`,`add`,`exec`,`start`,`dlx`]),lt=[[/^(test|tests|test:.*|vitest|jest|spec)$/,`activity.testing`],[/^(build|compile|bundle|dist)$/,`activity.building`],[/^(typecheck|tsc|types?)$/,`activity.typechecking`],[/^(lint|lint:.*|eslint|format|fmt|prettier)$/,`activity.linting`]],ut=new Set([`vitest`,`jest`,`pytest`,`mocha`,`ava`,`rspec`,`phpunit`]);function dt(e){for(let[t,n]of lt)if(t.test(e))return n;return null}function ft(e){return e.split(/\s+/).map(e=>e.replace(/^['"`]+/,``).replace(/['"`]+$/,``)).filter(e=>e.length>0&&!e.startsWith(`-`))}function pt(e){let t=ft(e);if(t.length===0)return{kind:`plumbing`};let n=t[0].split(`/`).pop()??t[0],r=t.slice(1);if(at.has(n))return{kind:`plumbing`};if(ut.has(n))return{kind:`intent`,code:`activity.testing`};if((n===`npx`||n===`pnpm`||n===`yarn`||n===`bunx`)&&r.length>0){let e=r[0]===`dlx`||r[0]===`exec`?r[1]??``:r[0];if(ut.has(e))return{kind:`intent`,code:`activity.testing`};let t=dt(e===`run`?r[r.indexOf(`run`)+1]??``:e);if(t)return{kind:`intent`,code:t};if(e===`tsc`)return{kind:`intent`,code:`activity.typechecking`}}if(n===`npm`||n===`yarn`||n===`pnpm`||n===`bun`){let e=r.findIndex(e=>ct.has(e)),t=e===-1?``:r[e];if(t===`install`||t===`ci`||t===`i`||t===`add`)return{kind:`intent`,code:`activity.installing`};let i=dt(t===`run`||t===`run-script`?r[e+1]??``:t);return i?{kind:`intent`,code:i}:{kind:`named`,tool:n}}if(n===`git`){let e=r.find(e=>st.has(e))??``;return ot.has(e)?{kind:`plumbing`}:e===`commit`||e===`add`||e===`stage`?{kind:`intent`,code:`activity.savingWork`}:{kind:`named`,tool:n}}if(n===`cargo`||n===`go`||n===`dotnet`||n===`mvn`||n===`gradle`){let e=r.find(e=>e===`test`||e===`build`||e===`compile`)??``;return e===`test`?{kind:`intent`,code:`activity.testing`}:e===`build`||e===`compile`?{kind:`intent`,code:`activity.building`}:{kind:`named`,tool:n}}return n===`tsc`?{kind:`intent`,code:`activity.typechecking`}:n===`openspec`?{kind:`intent`,code:`activity.checkingSpec`}:{kind:`named`,tool:n}}function mt(e){try{let t=JSON.parse(e);return t&&typeof t==`object`&&!Array.isArray(t)?t:{}}catch{return{}}}function ht(e,t){return e&&/^main-\d+$/.test(e)?`step.role.work`:e===`verify`?`step.role.verify`:e===`decide`||t===`decider`?`step.role.decide`:e===`fix`?`step.role.fix`:null}function gt(e){return e.replace(/^[^\p{L}\p{N}(]+/u,``).trim()}var X=e=>typeof e==`number`&&Number.isFinite(e)?e:null,Z=e=>typeof e==`string`&&e.length>0?e:null,_t=new Set([`thinking`,`reasoning`]),vt=/^(MEMORY\.md|confidence-score\.json|design-confidence\.json|\d{4}-\d{2}-\d{2}-.+|feedback_.+)$/,yt=/^(proposal|design|tasks|spec|context-bundle)\.md$/,bt=new Set([`reading`,`writing`,`editing`]);function Q(e,t,n,r,i){for(let t=e.length-1;t>=0;t--){let a=e[t];if(a.kind!==`activity`){if(a.stepIndex!==n)break;continue}if(a.stepIndex!==n)break;if(a.values.action===r&&a.values.target===i){a.values.repeats=Number(a.values.repeats??1)+1;return}}e.push({seq:t,kind:`activity`,code:r===`intent`?i:i?`activity.${r}`:`activity.${r}Bare`,values:{action:r,target:i,repeats:1},stepIndex:n,tone:`neutral`})}var xt=3;function St(e,t,n,r,i){for(let t=e.length-1;t>=0;t--){let a=e[t];if(a.stepIndex!==n)break;if(a.kind!==`activity`||a.values.action!==r||a.values.fileGroup!==1)continue;let o=String(a.values.allNames??``).split(`\0`).filter(Boolean),s=!!i&&!o.includes(i);s&&o.push(i),a.values.allNames=o.join(`\0`),a.values.files=o.length;let c=String(a.values.names??``).split(`, `).filter(Boolean);s&&c.length<xt&&(c.push(i),a.values.names=c.join(`, `)),a.code=o.length>1?`activity.${r}Files`:i?`activity.${r}`:`activity.${r}Bare`,a.values.repeats=o.length>1?1:Number(a.values.repeats??1)+1;return}e.push({seq:t,kind:`activity`,code:i?`activity.${r}`:`activity.${r}Bare`,values:{action:r,target:i,names:i,allNames:i,files:+!!i,fileGroup:1,repeats:1},stepIndex:n,tone:`neutral`})}function Ct({events:e,settled:t}){let n=[],r=new Map,i=null,a=!1;for(let t of e){if(t.event_type===`loop_graph`){a=!0;continue}if(t.event_type===`loop_step`){let e=mt(t.payload),o=X(e.index);if(o===null)continue;a=!0;let s=Z(e.kind)??`ai-step`,c={index:o,title:gt(Z(e.title)??``),roleCode:ht(Z(e.nodeId),s),kind:s,iteration:X(e.iteration),ended:!1};r.set(o,c),i=o,n.push({seq:t.seq,kind:`step-start`,code:c.iteration&&c.iteration>1?`step.startRetry`:`step.start`,values:{step:o,title:c.title,iteration:c.iteration??1,...c.roleCode?{roleCode:c.roleCode}:{}},stepIndex:o,tone:`neutral`});continue}if(t.event_type===`loop_step_end`){let e=mt(t.payload),i=X(e.index);if(i===null)continue;let a=i===null?void 0:r.get(i);a&&(a.ended=!0);let o=Z(e.status),s=X(e.durationMs),c=X(e.exitCode),l=o===`failed`;n.push({seq:t.seq,kind:`step-end`,code:l?`step.failed`:s===null?`step.done`:s>=9e4?`step.doneTimedMin`:`step.doneTimed`,values:{step:i,title:a?.title??``,seconds:s===null?0:Math.max(1,Math.round(s/1e3)),minutes:s===null?0:Math.max(1,Math.round(s/6e4)),...a?.roleCode?{roleCode:a.roleCode}:{},...c===null?{}:{exitCode:c}},stepIndex:i,tone:l?`bad`:`good`});let u=Z(e.decision);(u===`continue`||u===`stop`)&&n.push({seq:t.seq,kind:`decision`,code:u===`continue`?`decision.another`:`decision.satisfied`,values:{step:i},stepIndex:i,tone:u===`continue`?`neutral`:`good`});continue}let e=k(t);if(!(!e.step||!e.actionKey)&&!_t.has(e.actionKey)){if(e.actionKey===`running`){let r=ee(t),a=r?pt(r):{kind:`named`,tool:e.actionArg??``};if(a.kind===`plumbing`){Q(n,t.seq,i,`exploring`,``);continue}if(a.kind===`intent`){Q(n,t.seq,i,`intent`,a.code);continue}Q(n,t.seq,i,`running`,a.tool);continue}if(bt.has(e.actionKey)){let r=e.actionArg??``;if(vt.test(r)){Q(n,t.seq,i,`intent`,`activity.bookkeeping`);continue}if(yt.test(r)){Q(n,t.seq,i,`intent`,`activity.writingSpec`);continue}St(n,t.seq,i,e.actionKey,r);continue}Q(n,t.seq,i,e.actionKey,e.actionArg??``)}}if(t)for(let e of r.values())e.ended||n.push({seq:2**53-1-(1e3-e.index),kind:`step-interrupted`,code:`step.interrupted`,values:{step:e.index,title:e.title},stepIndex:e.index,tone:`bad`});return{milestones:n,stepCount:r.size,plainJob:!a}}var wt={"step-start":fe,"step-end":d,"step-interrupted":b,decision:oe,activity:fe},Tt={neutral:`text-muted-foreground`,good:`text-accent-success`,bad:`text-accent-warning`};function Et({events:e,settled:t,durationRange:n,elapsedMs:r,variant:i=`page`}){let{t:o}=a(`narration`),s=(0,V.useMemo)(()=>Ct({events:e,settled:t}),[e,t]),c=(0,V.useMemo)(()=>[...s.milestones].sort((e,t)=>e.seq-t.seq),[s.milestones]);return(0,B.jsxs)(`div`,{className:i===`glass`?`flex h-full flex-col overflow-hidden`:`flex flex-col`,children:[(0,B.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 border-b border-border/50 px-3 py-2 text-[11px] text-muted-foreground`,children:[typeof r==`number`&&r>0?(0,B.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,B.jsx)(A,{className:`size-3`,"aria-hidden":!0}),o(`waiting.elapsed`,{minutes:Math.max(1,Math.round(r/6e4))})]}):null,n?(0,B.jsx)(`span`,{"data-testid":`narration-range`,children:o(`waiting.range`,{low:Math.max(1,Math.round(n.p25Ms/6e4)),high:Math.max(1,Math.round(n.p75Ms/6e4)),count:n.sampleCount})}):null,(0,B.jsx)(`span`,{className:`ml-auto italic opacity-70`,children:o(`aiNote`)})]}),(0,B.jsx)(`ol`,{className:`flex-1 space-y-1 px-3 py-2 ${i===`glass`?`overflow-y-auto`:``}`,"data-testid":`narration-list`,children:c.length===0?(0,B.jsx)(`li`,{className:`py-6 text-center text-xs text-muted-foreground`,children:o(t?`emptySettled`:`emptyLive`)}):c.map((e,t)=>{let n=wt[e.kind],r=e.kind===`step-start`||e.kind===`step-end`||e.kind===`step-interrupted`,i=Number(e.values.files??0)>1?1:Number(e.values.repeats??1);return(0,B.jsxs)(`li`,{className:`flex items-start gap-2 text-sm ${r?`font-medium text-foreground`:`text-muted-foreground`} ${e.kind===`step-start`&&t>0?`pt-2`:``}`,children:[(0,B.jsx)(n,{className:`mt-0.5 size-3.5 shrink-0 ${Tt[e.tone]}`,"aria-hidden":!0}),(0,B.jsxs)(`span`,{children:[e.kind===`step-start`&&typeof e.values.roleCode==`string`?o(e.code,{...e.values,title:o(e.values.roleCode),defaultValue:e.code}):o(e.code,{...e.values,defaultValue:e.code}),i>1?(0,B.jsx)(`span`,{className:`ml-1.5 text-[11px] opacity-70`,children:o(`repeats`,{count:i})}):null]})]},`${e.seq}-${e.code}-${t}`)})})]})}var $=`specrails-desktop:job-log-mode`;function Dt(){try{let e=localStorage.getItem($);return e===`log`||e===`narrated`?e:`narrated`}catch{return`narrated`}}function Ot(e){try{localStorage.setItem($,e)}catch{}}function kt(e,t){switch(t.type){case`turn-user`:return{...e,streaming:!0,accepting:!0,queued:t.queued?e.queued+1:e.queued};case`turn-done`:{let n=Math.max(0,e.queued-1);return{...e,totals:t.totals,queued:n,streaming:e.queued>0}}case`finalized`:return{...e,streaming:!1,finalizing:!1,accepting:!1,queued:0,totals:t.totals??e.totals};case`accepting`:return t.accepting?{...e,accepting:!0}:{...e,accepting:!1,streaming:!1,queued:0};case`finalize-request`:return{...e,finalizing:!0};case`finalize-reject`:return{...e,finalizing:!1};case`blocked`:return{...e,accepting:!1,streaming:!1};default:return e}}function At(){try{return i()}catch{return null}}function jt({jobId:e,projectId:t,settleMode:n,initialAcceptingTurns:r,kind:i=`job`,variant:o=`page`,onFinalized:c}){let{t:l}=a(`jobs`),u=n??`finalize`,d=()=>t?`${S}/api/projects/${t}`:C(),[f,p]=(0,V.useReducer)(kt,{streaming:!1,queued:0,totals:null,accepting:r??!0,finalizing:!1}),[m,h]=(0,V.useState)(``),[g,v]=(0,V.useState)(!1),y=(0,V.useRef)(null);(0,V.useEffect)(()=>{r!==void 0&&p({type:`accepting`,accepting:r})},[r]);let b=(0,V.useRef)(c);b.current=c;let x=At(),w=(0,V.useId)();(0,V.useEffect)(()=>{if(!x)return;let t=`interactive-composer-${e}-${w}`;return x.registerHandler(t,t=>{let n=t;n.jobId===e&&(n.type===`job.turn_user`?p({type:`turn-user`,queued:!!n.queued}):n.type===`job.turn_done`?p({type:`turn-done`,totals:n.totals}):n.type===`job.finalized`?(p({type:`finalized`,totals:n.totals??null}),b.current?.()):n.type===`job.interactive`&&p({type:`accepting`,accepting:!!n.acceptingTurns}))}),()=>x.unregisterHandler(t)},[x,e,w]);let D=i===`loop-step`&&!f.accepting;async function O(){let t=m.trim();if(!(!t||g||D)){v(!0);try{let n=await fetch(`${d()}/jobs/${e}/messages`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({text:t})});if(n.ok)h(``),requestAnimationFrame(()=>y.current?.focus());else if(n.status===409&&i===`loop-step`)p({type:`blocked`});else{let e=await n.json().catch(()=>({}));s.error(l(`detail.toast.sendFailed`),{description:e.error})}}catch{s.error(l(`detail.toast.networkError`))}finally{v(!1)}}}async function k(){if(!f.finalizing){p({type:`finalize-request`});try{let t=await fetch(`${d()}/jobs/${e}/finalize`,{method:`POST`});if(t.ok)s.success(l(u===`finalize`?`detail.toast.finalizeScheduled`:i===`loop-step`?`detail.toast.wrapUpStepScheduled`:`detail.toast.wrapUpScheduled`));else if(t.status===409&&i===`loop-step`)p({type:`blocked`}),p({type:`finalize-reject`});else{let e=await t.json().catch(()=>({}));s.error(l(`detail.toast.finalizeFailed`),{description:e.error}),p({type:`finalize-reject`})}}catch{s.error(l(`detail.toast.networkError`)),p({type:`finalize-reject`})}}}let A=g||D||!m.trim(),F=l(`detail.interactive.working`);return(0,B.jsxs)(`div`,{"data-testid":`interactive-job-composer`,className:E(`shrink-0 border-t px-3 py-2 space-y-1.5`,`motion-safe:animate-in motion-safe:fade-in motion-safe:slide-in-from-bottom-2 motion-safe:duration-300`,o===`glass`?`border-border/30 bg-surface/30`:`border-border/40 bg-surface/40`),children:[(0,B.jsxs)(`div`,{className:`flex items-center justify-between gap-3 text-[11px] text-muted-foreground`,children:[(0,B.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[D?(0,B.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,B.jsx)(pe,{className:`h-3 w-3 motion-safe:animate-pulse`}),l(`detail.interactive.waitingForStepShort`)]}):f.streaming?(0,B.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,B.jsx)(_,{className:`h-3 w-3 animate-spin text-accent-primary`}),(0,B.jsxs)(`span`,{className:`relative`,children:[F,(0,B.jsx)(`span`,{"aria-hidden":!0,className:`title-shimmer pointer-events-none absolute inset-0`,children:F})]})]}):(0,B.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,B.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-accent-success motion-safe:animate-pulse`}),l(`detail.interactive.ready`)]}),f.queued>0&&(0,B.jsx)(`span`,{className:`rounded-full border border-accent-info/30 bg-accent-info/10 px-1.5 py-px text-[10px] tabular-nums text-accent-info motion-safe:animate-in motion-safe:fade-in`,children:l(`detail.interactive.queued`,{count:f.queued})})]}),(0,B.jsxs)(`span`,{className:`flex shrink-0 items-center gap-3`,children:[f.totals&&(0,B.jsx)(`span`,{className:`tabular-nums`,children:l(`detail.interactive.liveTotals`,{turns:f.totals.num_turns,cost:f.totals.total_cost_usd.toFixed(4)})}),u===`finalize`?(0,B.jsxs)(M,{children:[(0,B.jsx)(j,{asChild:!0,children:(0,B.jsxs)(T,{variant:`outline`,size:`sm`,onClick:()=>void k(),disabled:f.finalizing,className:`h-7 border-accent-success/40 text-accent-success hover:bg-accent-success/10`,children:[(0,B.jsx)(N,{className:`mr-1.5 h-3.5 w-3.5`}),f.finalizing?l(`detail.finalizing`):l(`detail.finalizeJob`)]})}),(0,B.jsx)(P,{children:l(`detail.finalizeJobTooltip`)})]}):(0,B.jsxs)(M,{children:[(0,B.jsx)(j,{asChild:!0,children:(0,B.jsx)(`button`,{type:`button`,onClick:()=>void k(),disabled:f.finalizing||D,className:E(`text-[11px] underline-offset-2 transition-colors`,D?`cursor-not-allowed text-muted-foreground/40`:`text-muted-foreground hover:text-accent-success hover:underline`),children:f.finalizing?l(`detail.interactive.wrappingUp`):l(i===`loop-step`?`detail.interactive.wrapUpStep`:`detail.interactive.wrapUp`)})}),(0,B.jsx)(P,{children:l(i===`loop-step`?`detail.interactive.wrapUpStepTooltip`:`detail.interactive.wrapUpTooltip`)})]})]})]}),u===`auto`&&(0,B.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground/60`,children:l(D?`detail.interactive.waitingForStep`:`detail.interactive.autoHint`)}),(0,B.jsxs)(`div`,{className:`flex items-end gap-2`,children:[(0,B.jsx)(`textarea`,{ref:y,value:m,onChange:e=>h(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(!e.shiftKey||e.metaKey||e.ctrlKey)&&(e.preventDefault(),O())},rows:2,placeholder:l(D?`detail.interactive.waitingForStepShort`:`detail.interactive.placeholder`),"aria-label":l(`detail.interactive.placeholder`),disabled:D,className:E(`flex-1 resize-none rounded-md border border-border/50 bg-background px-2.5 py-1.5 text-sm transition-opacity focus:outline-none focus:ring-2 focus:ring-ring`,D&&`opacity-60`)}),(0,B.jsxs)(M,{children:[(0,B.jsx)(j,{asChild:!0,children:(0,B.jsx)(`span`,{className:`shrink-0`,children:(0,B.jsxs)(T,{size:`sm`,onClick:()=>void O(),disabled:A,className:`h-9`,children:[(0,B.jsx)(R,{className:`mr-1.5 h-3.5 w-3.5`}),l(`detail.interactive.send`)]})})}),A&&!g&&(0,B.jsx)(P,{children:l(D?`detail.interactive.sendDisabledWaiting`:`detail.interactive.sendDisabledEmpty`)})]})]})]})}export{it as a,Et as i,Dt as n,ke as o,Ot as r,me as s,jt as t};
|