specrails-desktop 2.43.0 → 2.43.2

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.
Files changed (43) hide show
  1. package/client/dist/assets/{ActivityFeedPage-DoEMumQS.js → ActivityFeedPage-C7XJ5-bJ.js} +1 -1
  2. package/client/dist/assets/{AgentBrowserCapture-DIh4K0gh.js → AgentBrowserCapture-C_WpXceT.js} +1 -1
  3. package/client/dist/assets/{AgentModeAnalyticsPane-mbq4WEoO.js → AgentModeAnalyticsPane-PEZKjyZS.js} +2 -2
  4. package/client/dist/assets/{AgentModeCodePane-CKh7zuA4.js → AgentModeCodePane-D_Xcq5t5.js} +2 -2
  5. package/client/dist/assets/{AgentModeJobsPane-BDokPiLJ.js → AgentModeJobsPane-CDSkOuNP.js} +1 -1
  6. package/client/dist/assets/{AgentsPage-BFVAZbBj.js → AgentsPage-D577NzIM.js} +1 -1
  7. package/client/dist/assets/{AnalyticsPage-3Y9LuWwz.js → AnalyticsPage-C6ZZI_zg.js} +1 -1
  8. package/client/dist/assets/{CodePage-C9KyuV_C.js → CodePage-B5z5oLnP.js} +1 -1
  9. package/client/dist/assets/{DesktopAnalyticsPage-Bhi54bXQ.js → DesktopAnalyticsPage-D_V9RuGg.js} +1 -1
  10. package/client/dist/assets/{DocsDialog-Dj6mt4ga.js → DocsDialog-Beg82MEe.js} +1 -1
  11. package/client/dist/assets/{DocsPage-24yWglNI.js → DocsPage-BkE4m4wp.js} +1 -1
  12. package/client/dist/assets/{InteractiveJobComposer-C1ucmxQh.js → InteractiveJobComposer-wBBBNaJn.js} +1 -1
  13. package/client/dist/assets/JobDetailModal-BCxue_Do.js +1 -0
  14. package/client/dist/assets/{JobDetailPage-BcajZyuu.js → JobDetailPage-_rIDpNfo.js} +1 -1
  15. package/client/dist/assets/{JobsPage-B9nTZw6e.js → JobsPage-C6xcijbs.js} +1 -1
  16. package/client/dist/assets/{LoopBuilderPage-Oc48iOFW.js → LoopBuilderPage-A-Mt6EjT.js} +1 -1
  17. package/client/dist/assets/{LoopPreviewModal-ae0Fr6SU.js → LoopPreviewModal-DqHiG4Dt.js} +1 -1
  18. package/client/dist/assets/{LoopsPage-CUEqzUBI.js → LoopsPage-B-ketPET.js} +1 -1
  19. package/client/dist/assets/{PluginsPage-C1xtARIx.js → PluginsPage-Dn2jPvJL.js} +1 -1
  20. package/client/dist/assets/{ProjectSettingsDialog-JZzrXFBN.js → ProjectSettingsDialog-CVTj4VLt.js} +1 -1
  21. package/client/dist/assets/{RepositoryDeliveries-CSDsiVUz.js → RepositoryDeliveries-IiQCcndQ.js} +1 -1
  22. package/client/dist/assets/{ReviewPacketPage-x5EfGTiL.js → ReviewPacketPage-BBd617OM.js} +1 -1
  23. package/client/dist/assets/{TemplatePreviewModal-BSyuZxGq.js → TemplatePreviewModal-COHFkUS4.js} +1 -1
  24. package/client/dist/assets/{TicketDetailModalContext-DqyF0so-.js → TicketDetailModalContext-BNa1mdXq.js} +3 -3
  25. package/client/dist/assets/{button-DCBqEaZl.js → button-Ccc9Dc-D.js} +1 -1
  26. package/client/dist/assets/dialog-xXB2q5HJ.js +45 -0
  27. package/client/dist/assets/index-D5n_jg_I.css +2 -0
  28. package/client/dist/assets/index-m5pKr1T6.js +76 -0
  29. package/client/dist/index.html +6 -6
  30. package/docs/guide/en/pipeline/3-batch-implement-and-multi-feature.md +11 -0
  31. package/docs/internals/core-runtime-updates.md +7 -0
  32. package/docs/internals/interactive-jobs.md +53 -0
  33. package/package.json +1 -1
  34. package/server/dist/loop-executors.js +14 -1
  35. package/server/dist/loop-factory.js +24 -5
  36. package/server/dist/loop-run-manager.js +12 -0
  37. package/server/dist/loop-templates.js +14 -33
  38. package/server/dist/rails-router.js +2 -2
  39. package/server/dist/workspace-manager.js +54 -3
  40. package/client/dist/assets/JobDetailModal-DNWmgVHD.js +0 -1
  41. package/client/dist/assets/dialog-SRw01_QU.js +0 -45
  42. package/client/dist/assets/index-DwAmL7m5.css +0 -2
  43. package/client/dist/assets/index-EzrkUb8B.js +0 -76
@@ -1 +1 @@
1
- import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-zu2_FqZY.js";import{h as r,r as i}from"./useSharedWebSocket-BOdS5_Iz.js";import{n as a}from"./createLucideIcon-Bjbbp_KS.js";import{a as o,r as s}from"./useDesktop-RSMTyy7V.js";import{t as c}from"./circle-x-CMYsN4ZH.js";import{t as l}from"./loader-circle-DcygOQpC.js";import{t as u}from"./zap-CHo3aCD1.js";import{Lt as d,jt as f,zt as p}from"./index-EzrkUb8B.js";var m=e(t(),1);function h(e){let t=new Set;return e.filter(e=>{let n=`${e.type}:${e.jobId}`;return t.has(n)?!1:(t.add(n),!0)})}function g({activeProjectId:e,limit:t=50}){let[n,a]=(0,m.useState)([]),[s,c]=(0,m.useState)(!1),[l,u]=(0,m.useState)(!0),d=(0,m.useRef)(e);(0,m.useEffect)(()=>{d.current=e},[e]);let{registerHandler:f,unregisterHandler:p}=i();(0,m.useEffect)(()=>{if(!e){a([]),u(!0);return}let n=!1;c(!0),a([]),u(!0);async function r(){let e=o();try{let r=await fetch(`${e}/activity?limit=${t}`);if(!r.ok||n)return;let i=await r.json();if(n)return;a(i),u(i.length===t)}catch{}finally{n||c(!1)}}return r(),()=>{n=!0}},[e,t]);let g=(0,m.useCallback)(async()=>{if(s||!l)return;c(!0);let e=o(),n=d.current;try{a(r=>{let i=r[r.length-1];if(!i)return r;let o=encodeURIComponent(i.timestamp);return fetch(`${e}/activity?limit=${t}&before=${o}`).then(e=>e.json()).then(e=>{if(d.current!==n){c(!1);return}a(t=>h([...t,...e])),u(e.length===t),c(!1)}).catch(()=>c(!1)),r})}catch{c(!1)}},[s,l,t]),_=(0,m.useCallback)(e=>{let t=e,n=d.current;if(!(!t||typeof t.type!=`string`)&&!(t.projectId&&t.projectId!==n)){if(t.type===`queue`&&Array.isArray(t.jobs)){let e=[];for(let n of t.jobs){let t=n.status===`completed`?`job_completed`:n.status===`failed`?`job_failed`:n.status===`canceled`?`job_canceled`:`job_started`;e.push({id:`${t}:${n.id}`,type:t,jobId:n.id,jobCommand:n.command??``,timestamp:n.startedAt??new Date().toISOString(),summary:`${t.replace(`_`,` `)}: ${n.command??``}`,costUsd:null})}e.length>0&&a(t=>h([...e,...t]))}if(t.type===`phase`&&t.phase&&t.state&&t.timestamp){let e={id:`phase:${t.phase}:${t.state}:${t.timestamp}`,type:`job_started`,jobId:`phase-${t.phase}`,jobCommand:r.t(`activity:feed.phaseCommand`,{phase:t.phase,state:t.state}),timestamp:t.timestamp,summary:`Phase ${t.phase} is ${t.state}`,costUsd:null};a(t=>h([e,...t]))}}},[]);return(0,m.useLayoutEffect)(()=>(f(`activity`,_),()=>p(`activity`)),[_,f,p]),{items:n,loading:s,hasMore:l,loadMore:g}}var _=n();function v(e,t){let n=Date.now()-new Date(e).getTime(),r=Math.floor(n/1e3);if(r<60)return t(`feed.relativeTime.seconds`,{value:r});let i=Math.floor(r/60);if(i<60)return t(`feed.relativeTime.minutes`,{value:i});let a=Math.floor(i/60);return a<24?t(`feed.relativeTime.hours`,{value:a}):t(`feed.relativeTime.days`,{value:Math.floor(a/24)})}function y({type:e}){switch(e){case`job_completed`:return(0,_.jsx)(f,{className:`w-4 h-4 text-green-500 aurora-light:text-accent-success flex-shrink-0`});case`job_failed`:return(0,_.jsx)(c,{className:`w-4 h-4 text-red-500 aurora-light:text-destructive flex-shrink-0`});case`job_canceled`:return(0,_.jsx)(d,{className:`w-4 h-4 text-muted-foreground flex-shrink-0`});default:return(0,_.jsx)(u,{className:`w-4 h-4 text-blue-500 aurora-light:text-accent-info flex-shrink-0`})}}function b(e,t){switch(e){case`job_completed`:return t(`common:status.completed`);case`job_failed`:return t(`common:status.failed`);case`job_canceled`:return t(`common:status.canceled`);default:return t(`feed.typeStarted`)}}function x(e){switch(e){case`job_completed`:return`text-green-500 aurora-light:text-accent-success`;case`job_failed`:return`text-red-500 aurora-light:text-destructive`;case`job_canceled`:return`text-muted-foreground`;default:return`text-blue-500 aurora-light:text-accent-info`}}function S(){let{t:e}=a(`activity`),{activeProjectId:t}=s(),{items:n,loading:r,hasMore:i,loadMore:o}=g({activeProjectId:t}),c=(0,m.useRef)(null);return(0,m.useEffect)(()=>{let e=c.current;if(!e)return;let t=new IntersectionObserver(e=>{e[0].isIntersecting&&i&&!r&&o()},{threshold:.1});return t.observe(e),()=>t.disconnect()},[i,r,o]),(0,_.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,_.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-3 border-b border-border bg-background/50`,children:[(0,_.jsx)(p,{className:`w-4 h-4 text-muted-foreground`}),(0,_.jsx)(`h1`,{className:`text-sm font-medium`,children:e(`feed.title`)})]}),(0,_.jsxs)(`div`,{className:`flex-1 overflow-y-auto`,children:[r&&n.length===0?(0,_.jsx)(`div`,{className:`flex items-center justify-center h-32`,children:(0,_.jsx)(l,{className:`w-4 h-4 animate-spin text-muted-foreground`})}):n.length===0?(0,_.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-48 gap-2 text-muted-foreground`,children:[(0,_.jsx)(p,{className:`w-8 h-8 opacity-40`}),(0,_.jsx)(`p`,{className:`text-sm`,children:e(`feed.emptyTitle`)}),(0,_.jsx)(`p`,{className:`text-xs opacity-70`,children:e(`feed.emptyHint`)})]}):(0,_.jsx)(`ul`,{className:`divide-y divide-border/50`,children:n.map(t=>(0,_.jsxs)(`li`,{className:`flex items-center gap-3 px-4 py-2.5 hover:bg-accent/30 transition-colors`,children:[(0,_.jsx)(y,{type:t.type}),(0,_.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,_.jsx)(`p`,{className:`text-xs text-foreground truncate`,title:t.jobCommand,children:t.jobCommand}),(0,_.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5`,children:[(0,_.jsx)(`span`,{className:`text-xs font-medium ${x(t.type)}`,children:b(t.type,e)}),t.costUsd!=null&&(0,_.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`$`,t.costUsd.toFixed(4)]})]})]}),(0,_.jsx)(`span`,{className:`text-xs text-muted-foreground flex-shrink-0 tabular-nums`,children:v(t.timestamp,e)})]},`${t.type}:${t.jobId}`))}),(0,_.jsx)(`div`,{ref:c,className:`h-1`}),r&&n.length>0&&(0,_.jsx)(`div`,{className:`flex justify-center py-3`,children:(0,_.jsx)(l,{className:`w-4 h-4 animate-spin text-muted-foreground`})}),!i&&n.length>0&&(0,_.jsx)(`p`,{className:`text-center text-xs text-muted-foreground py-3`,children:e(`feed.allLoaded`)})]})]})}export{S as default};
1
+ import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-zu2_FqZY.js";import{h as r,r as i}from"./useSharedWebSocket-BOdS5_Iz.js";import{n as a}from"./createLucideIcon-Bjbbp_KS.js";import{a as o,r as s}from"./useDesktop-RSMTyy7V.js";import{t as c}from"./circle-x-CMYsN4ZH.js";import{t as l}from"./loader-circle-DcygOQpC.js";import{t as u}from"./zap-CHo3aCD1.js";import{Lt as d,jt as f,zt as p}from"./index-m5pKr1T6.js";var m=e(t(),1);function h(e){let t=new Set;return e.filter(e=>{let n=`${e.type}:${e.jobId}`;return t.has(n)?!1:(t.add(n),!0)})}function g({activeProjectId:e,limit:t=50}){let[n,a]=(0,m.useState)([]),[s,c]=(0,m.useState)(!1),[l,u]=(0,m.useState)(!0),d=(0,m.useRef)(e);(0,m.useEffect)(()=>{d.current=e},[e]);let{registerHandler:f,unregisterHandler:p}=i();(0,m.useEffect)(()=>{if(!e){a([]),u(!0);return}let n=!1;c(!0),a([]),u(!0);async function r(){let e=o();try{let r=await fetch(`${e}/activity?limit=${t}`);if(!r.ok||n)return;let i=await r.json();if(n)return;a(i),u(i.length===t)}catch{}finally{n||c(!1)}}return r(),()=>{n=!0}},[e,t]);let g=(0,m.useCallback)(async()=>{if(s||!l)return;c(!0);let e=o(),n=d.current;try{a(r=>{let i=r[r.length-1];if(!i)return r;let o=encodeURIComponent(i.timestamp);return fetch(`${e}/activity?limit=${t}&before=${o}`).then(e=>e.json()).then(e=>{if(d.current!==n){c(!1);return}a(t=>h([...t,...e])),u(e.length===t),c(!1)}).catch(()=>c(!1)),r})}catch{c(!1)}},[s,l,t]),_=(0,m.useCallback)(e=>{let t=e,n=d.current;if(!(!t||typeof t.type!=`string`)&&!(t.projectId&&t.projectId!==n)){if(t.type===`queue`&&Array.isArray(t.jobs)){let e=[];for(let n of t.jobs){let t=n.status===`completed`?`job_completed`:n.status===`failed`?`job_failed`:n.status===`canceled`?`job_canceled`:`job_started`;e.push({id:`${t}:${n.id}`,type:t,jobId:n.id,jobCommand:n.command??``,timestamp:n.startedAt??new Date().toISOString(),summary:`${t.replace(`_`,` `)}: ${n.command??``}`,costUsd:null})}e.length>0&&a(t=>h([...e,...t]))}if(t.type===`phase`&&t.phase&&t.state&&t.timestamp){let e={id:`phase:${t.phase}:${t.state}:${t.timestamp}`,type:`job_started`,jobId:`phase-${t.phase}`,jobCommand:r.t(`activity:feed.phaseCommand`,{phase:t.phase,state:t.state}),timestamp:t.timestamp,summary:`Phase ${t.phase} is ${t.state}`,costUsd:null};a(t=>h([e,...t]))}}},[]);return(0,m.useLayoutEffect)(()=>(f(`activity`,_),()=>p(`activity`)),[_,f,p]),{items:n,loading:s,hasMore:l,loadMore:g}}var _=n();function v(e,t){let n=Date.now()-new Date(e).getTime(),r=Math.floor(n/1e3);if(r<60)return t(`feed.relativeTime.seconds`,{value:r});let i=Math.floor(r/60);if(i<60)return t(`feed.relativeTime.minutes`,{value:i});let a=Math.floor(i/60);return a<24?t(`feed.relativeTime.hours`,{value:a}):t(`feed.relativeTime.days`,{value:Math.floor(a/24)})}function y({type:e}){switch(e){case`job_completed`:return(0,_.jsx)(f,{className:`w-4 h-4 text-green-500 aurora-light:text-accent-success flex-shrink-0`});case`job_failed`:return(0,_.jsx)(c,{className:`w-4 h-4 text-red-500 aurora-light:text-destructive flex-shrink-0`});case`job_canceled`:return(0,_.jsx)(d,{className:`w-4 h-4 text-muted-foreground flex-shrink-0`});default:return(0,_.jsx)(u,{className:`w-4 h-4 text-blue-500 aurora-light:text-accent-info flex-shrink-0`})}}function b(e,t){switch(e){case`job_completed`:return t(`common:status.completed`);case`job_failed`:return t(`common:status.failed`);case`job_canceled`:return t(`common:status.canceled`);default:return t(`feed.typeStarted`)}}function x(e){switch(e){case`job_completed`:return`text-green-500 aurora-light:text-accent-success`;case`job_failed`:return`text-red-500 aurora-light:text-destructive`;case`job_canceled`:return`text-muted-foreground`;default:return`text-blue-500 aurora-light:text-accent-info`}}function S(){let{t:e}=a(`activity`),{activeProjectId:t}=s(),{items:n,loading:r,hasMore:i,loadMore:o}=g({activeProjectId:t}),c=(0,m.useRef)(null);return(0,m.useEffect)(()=>{let e=c.current;if(!e)return;let t=new IntersectionObserver(e=>{e[0].isIntersecting&&i&&!r&&o()},{threshold:.1});return t.observe(e),()=>t.disconnect()},[i,r,o]),(0,_.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,_.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-3 border-b border-border bg-background/50`,children:[(0,_.jsx)(p,{className:`w-4 h-4 text-muted-foreground`}),(0,_.jsx)(`h1`,{className:`text-sm font-medium`,children:e(`feed.title`)})]}),(0,_.jsxs)(`div`,{className:`flex-1 overflow-y-auto`,children:[r&&n.length===0?(0,_.jsx)(`div`,{className:`flex items-center justify-center h-32`,children:(0,_.jsx)(l,{className:`w-4 h-4 animate-spin text-muted-foreground`})}):n.length===0?(0,_.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-48 gap-2 text-muted-foreground`,children:[(0,_.jsx)(p,{className:`w-8 h-8 opacity-40`}),(0,_.jsx)(`p`,{className:`text-sm`,children:e(`feed.emptyTitle`)}),(0,_.jsx)(`p`,{className:`text-xs opacity-70`,children:e(`feed.emptyHint`)})]}):(0,_.jsx)(`ul`,{className:`divide-y divide-border/50`,children:n.map(t=>(0,_.jsxs)(`li`,{className:`flex items-center gap-3 px-4 py-2.5 hover:bg-accent/30 transition-colors`,children:[(0,_.jsx)(y,{type:t.type}),(0,_.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,_.jsx)(`p`,{className:`text-xs text-foreground truncate`,title:t.jobCommand,children:t.jobCommand}),(0,_.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5`,children:[(0,_.jsx)(`span`,{className:`text-xs font-medium ${x(t.type)}`,children:b(t.type,e)}),t.costUsd!=null&&(0,_.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`$`,t.costUsd.toFixed(4)]})]})]}),(0,_.jsx)(`span`,{className:`text-xs text-muted-foreground flex-shrink-0 tabular-nums`,children:v(t.timestamp,e)})]},`${t.type}:${t.jobId}`))}),(0,_.jsx)(`div`,{ref:c,className:`h-1`}),r&&n.length>0&&(0,_.jsx)(`div`,{className:`flex justify-center py-3`,children:(0,_.jsx)(l,{className:`w-4 h-4 animate-spin text-muted-foreground`})}),!i&&n.length>0&&(0,_.jsx)(`p`,{className:`text-center text-xs text-muted-foreground py-3`,children:e(`feed.allLoaded`)})]})]})}export{S as default};
@@ -1 +1 @@
1
- import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-zu2_FqZY.js";import{d as r,f as i,m as a,u as o}from"./TicketDetailModalContext-DqyF0so-.js";import{n as s}from"./createLucideIcon-Bjbbp_KS.js";import{s as c}from"./useDesktop-RSMTyy7V.js";import{$ as l,Bt as u,Ht as d,P as f,W as p,X as m,v as h}from"./index-EzrkUb8B.js";var g=e(t(),1),_=n();function v({projectId:e,conversationId:t}){let{t:n}=s(`agent`),{error:v}=d(),y=l(t??`__new-mission__`),{closeBrowser:b,queueCapture:x,browserOwnerId:S,browserUrl:C,setBrowserUrl:w}=p(),{materializeDraftConversation:T}=f(),[E,D]=(0,g.useState)(!1),[O,k]=(0,g.useState)(!1),[A,j]=(0,g.useState)(`probing`);(0,g.useEffect)(()=>{if(t&&(E||O||A===`screencast`))return m(t)},[t,E,O,A]);let M=(0,g.useMemo)(()=>{if(C)return C;try{return i(localStorage.getItem(`specrails-desktop:agent-browser-url:${e}`)??``)??`about:blank`}catch{return`about:blank`}},[e]);(0,g.useEffect)(()=>{let e=!0;return r().then(t=>{e&&j(t?`native`:`screencast`)}),()=>{e=!1}},[]);let N=(0,g.useMemo)(()=>`agent-${t??`home`}-${Math.round(performance.now())}`,[t]),P=async e=>{k(!0);try{let r=await u(t??(await T()).id,a(e.screenshotDataUrl,`capture-${Date.now()}.png`));x(r),c.success(n(`workspace.browserCaptured`)),b()}catch(e){throw c.error(n(`workspace.uploadFailed`),{description:e instanceof Error?e.message:void 0}),e}finally{k(!1)}};return A===`probing`?null:A===`native`?(0,_.jsx)(o,{ownerId:S??void 0,leaseRevision:y,onBusyChange:D,transferError:v,url:M,onClose:b,onFallback:()=>j(`screencast`),onUrlChange:t=>{if(w(t),i(t)&&t!==`about:blank`)try{localStorage.setItem(`specrails-desktop:agent-browser-url:${e}`,t)}catch{}},confirmLabel:n(`workspace.browserConfirm`),selectLabel:n(`workspace.browserSelectStart`),onCaptured:P}):(0,_.jsx)(h,{open:!0,onClose:b,projectId:e,pendingSpecId:N,confirmLabel:n(`workspace.browserConfirm`),selectLabel:n(`workspace.browserSelectStart`),onCaptured:P})}export{v as AgentBrowserCapture};
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,f as i,m as a,u as o}from"./TicketDetailModalContext-BNa1mdXq.js";import{n as s}from"./createLucideIcon-Bjbbp_KS.js";import{s as c}from"./useDesktop-RSMTyy7V.js";import{$ as l,Bt as u,Ht as d,P as f,W as p,X as m,v as h}from"./index-m5pKr1T6.js";var g=e(t(),1),_=n();function v({projectId:e,conversationId:t}){let{t:n}=s(`agent`),{error:v}=d(),y=l(t??`__new-mission__`),{closeBrowser:b,queueCapture:x,browserOwnerId:S,browserUrl:C,setBrowserUrl:w}=p(),{materializeDraftConversation:T}=f(),[E,D]=(0,g.useState)(!1),[O,k]=(0,g.useState)(!1),[A,j]=(0,g.useState)(`probing`);(0,g.useEffect)(()=>{if(t&&(E||O||A===`screencast`))return m(t)},[t,E,O,A]);let M=(0,g.useMemo)(()=>{if(C)return C;try{return i(localStorage.getItem(`specrails-desktop:agent-browser-url:${e}`)??``)??`about:blank`}catch{return`about:blank`}},[e]);(0,g.useEffect)(()=>{let e=!0;return r().then(t=>{e&&j(t?`native`:`screencast`)}),()=>{e=!1}},[]);let N=(0,g.useMemo)(()=>`agent-${t??`home`}-${Math.round(performance.now())}`,[t]),P=async e=>{k(!0);try{let r=await u(t??(await T()).id,a(e.screenshotDataUrl,`capture-${Date.now()}.png`));x(r),c.success(n(`workspace.browserCaptured`)),b()}catch(e){throw c.error(n(`workspace.uploadFailed`),{description:e instanceof Error?e.message:void 0}),e}finally{k(!1)}};return A===`probing`?null:A===`native`?(0,_.jsx)(o,{ownerId:S??void 0,leaseRevision:y,onBusyChange:D,transferError:v,url:M,onClose:b,onFallback:()=>j(`screencast`),onUrlChange:t=>{if(w(t),i(t)&&t!==`about:blank`)try{localStorage.setItem(`specrails-desktop:agent-browser-url:${e}`,t)}catch{}},confirmLabel:n(`workspace.browserConfirm`),selectLabel:n(`workspace.browserSelectStart`),onCaptured:P}):(0,_.jsx)(h,{open:!0,onClose:b,projectId:e,pendingSpecId:N,confirmLabel:n(`workspace.browserConfirm`),selectLabel:n(`workspace.browserSelectStart`),onCaptured:P})}export{v as AgentBrowserCapture};
@@ -1,2 +1,2 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/AnalyticsPage-3Y9LuWwz.js","assets/rolldown-runtime-CNC7AqOf.js","assets/jsx-runtime-zu2_FqZY.js","assets/chunk-KS7C4IRE-DEKu087k.js","assets/preload-helper-Czpn1I53.js","assets/useSharedWebSocket-BOdS5_Iz.js","assets/activity-DiyjsgQV.js","assets/addspec-D2YIQ0GU.js","assets/agent-Bh9K7iEt.js","assets/agents-ms7TwG16.js","assets/agentstudio-CN2pokQu.js","assets/aiedit-iIjz2_Qk.js","assets/analytics-BMzCvrCU.js","assets/attachments-B53PG733.js","assets/browser-CG0PE1j_.js","assets/builder-BTiGnPT0.js","assets/chat-BGD7MXAy.js","assets/code-DaZ-ZwCT.js","assets/commands-BAWSYHjQ.js","assets/common-BrlwEnL7.js","assets/dashboard-BfBir_6o.js","assets/explore-DgBACn39.js","assets/integrations-mB-7zoyT.js","assets/jira-CKJg3HZd.js","assets/jobs-DzMjUcaN.js","assets/loops-B7YpGizO.js","assets/mcp-CUAN6ORK.js","assets/narration-B-ynWTpn.js","assets/nav-Ch-zHBG5.js","assets/packet-Cx-zRuWn.js","assets/settings-BJB9RKJj.js","assets/setup-Ba11l2JA.js","assets/specs-DII0C8gw.js","assets/terminal-BAzpHtpY.js","assets/tickets-W6pBmbrX.js","assets/createLucideIcon-Bjbbp_KS.js","assets/Trans-SnMX4MhW.js","assets/useDesktop-RSMTyy7V.js","assets/react-dom-DiWzBDP9.js","assets/spending-BqbdPm_4.js","assets/clsx-CjueKrWZ.js","assets/formatDistanceToNow-DSj5DprF.js","assets/getTimezoneOffsetInMilliseconds-YhD8rIEs.js","assets/provider-capabilities-B-wOHfLP.js","assets/index-EzrkUb8B.js","assets/TicketDetailModalContext-DqyF0so-.js","assets/save-B6wGWwBR.js","assets/MinimizedChatsContext-Deg39peL.js","assets/sparkles-DrY8hb0X.js","assets/x-CBMI9ejn.js","assets/file-text-BcLCfcWZ.js","assets/circle-x-CMYsN4ZH.js","assets/download-CFHyyHcw.js","assets/git-branch-BRM0F5GN.js","assets/loader-circle-DcygOQpC.js","assets/pencil-C9RkrIPZ.js","assets/square-Ci-PFcFe.js","assets/plus-CsnjfkmX.js","assets/search-Cq_gE3Ik.js","assets/trash-2-BOU3WdZZ.js","assets/triangle-alert-H9T4jAmh.js","assets/jira-api-CSCqGr-Q.js","assets/zap-CHo3aCD1.js","assets/dialog-SRw01_QU.js","assets/utils-BC4DHlz2.js","assets/lib-CGdyxIWg.js","assets/button-DCBqEaZl.js","assets/RepositoryScopeSelector-D-RCaknl.js","assets/project-repositories-DYhTvwQ1.js","assets/core-B3mKBIh5.js","assets/RepositoryDeliveries-CSDsiVUz.js","assets/event-Bt7f3wXe.js","assets/index-DwAmL7m5.css","assets/ExportDropdown-ophapHrT.js","assets/BarChart-nBOMNfiy.js","assets/value-s-gzBeyF.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"./preload-helper-Czpn1I53.js";import{n as i}from"./createLucideIcon-Bjbbp_KS.js";import{t as a}from"./loader-circle-DcygOQpC.js";import{t as o}from"./x-CBMI9ejn.js";import{t as s}from"./utils-BC4DHlz2.js";import{W as c,_t as l,gt as u}from"./index-EzrkUb8B.js";var d=e(t(),1),f=n(),p=(0,d.lazy)(()=>r(()=>import(`./AnalyticsPage-3Y9LuWwz.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75]))),m=420,h=560;function g(){let{t:e}=i(`agent`),{closeAnalyticsPane:t}=c(),[n,r]=(0,d.useState)(h),[g,_]=(0,d.useState)(!1),v=(0,d.useCallback)(e=>{let t=e.clientX,i=n,a=window.innerWidth-m;try{e.currentTarget.setPointerCapture(e.pointerId)}catch{}let o=e=>{let n=Math.min(Math.max(i+(t-e.clientX),m),a);r(n)},s=()=>{window.removeEventListener(`pointermove`,o),window.removeEventListener(`pointerup`,s),window.removeEventListener(`pointercancel`,s)};window.addEventListener(`pointermove`,o),window.addEventListener(`pointerup`,s),window.addEventListener(`pointercancel`,s)},[n]);return(0,f.jsxs)(`div`,{className:s(`flex h-full flex-col overflow-hidden border-l border-border bg-background`,g&&`absolute inset-0 z-30 border-l-0`),style:g?void 0:{width:n,flexShrink:0},"data-testid":`agent-analytics-pane`,children:[(0,f.jsx)(`div`,{className:`relative flex items-center`,children:!g&&(0,f.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,onPointerDown:v,className:`absolute left-0 top-0 h-full w-1.5 -translate-x-full cursor-col-resize select-none touch-none hover:bg-accent-primary/20`,title:e(`workspace.resizeAnalytics`)})}),(0,f.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-border/60 bg-surface/40 px-3 py-1.5`,children:[(0,f.jsx)(`span`,{className:`text-xs font-medium text-foreground/70`,children:e(`workspace.analytics`)}),(0,f.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[(0,f.jsx)(`button`,{type:`button`,onClick:()=>_(e=>!e),"aria-label":e(g?`restore`:`maximize`),title:e(g?`restore`:`maximize`),className:`rounded-md p-1 text-foreground/60 hover:bg-surface hover:text-foreground`,children:g?(0,f.jsx)(u,{className:`h-4 w-4`}):(0,f.jsx)(l,{className:`h-4 w-4`})}),(0,f.jsx)(`button`,{type:`button`,onClick:t,"aria-label":e(`workspace.closeAnalytics`),title:e(`workspace.closeAnalytics`),className:`rounded-md p-1 text-foreground/60 hover:bg-surface hover:text-foreground`,children:(0,f.jsx)(o,{className:`h-4 w-4`})})]})]}),(0,f.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:(0,f.jsx)(d.Suspense,{fallback:(0,f.jsx)(`div`,{className:`flex h-24 items-center justify-center text-muted-foreground`,children:(0,f.jsx)(a,{className:`h-4 w-4 animate-spin`})}),children:(0,f.jsx)(p,{})})})]})}export{g as AgentModeAnalyticsPane};
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/AnalyticsPage-C6ZZI_zg.js","assets/rolldown-runtime-CNC7AqOf.js","assets/jsx-runtime-zu2_FqZY.js","assets/chunk-KS7C4IRE-DEKu087k.js","assets/preload-helper-Czpn1I53.js","assets/useSharedWebSocket-BOdS5_Iz.js","assets/activity-DiyjsgQV.js","assets/addspec-D2YIQ0GU.js","assets/agent-Bh9K7iEt.js","assets/agents-ms7TwG16.js","assets/agentstudio-CN2pokQu.js","assets/aiedit-iIjz2_Qk.js","assets/analytics-BMzCvrCU.js","assets/attachments-B53PG733.js","assets/browser-CG0PE1j_.js","assets/builder-BTiGnPT0.js","assets/chat-BGD7MXAy.js","assets/code-DaZ-ZwCT.js","assets/commands-BAWSYHjQ.js","assets/common-BrlwEnL7.js","assets/dashboard-BfBir_6o.js","assets/explore-DgBACn39.js","assets/integrations-mB-7zoyT.js","assets/jira-CKJg3HZd.js","assets/jobs-DzMjUcaN.js","assets/loops-B7YpGizO.js","assets/mcp-CUAN6ORK.js","assets/narration-B-ynWTpn.js","assets/nav-Ch-zHBG5.js","assets/packet-Cx-zRuWn.js","assets/settings-BJB9RKJj.js","assets/setup-Ba11l2JA.js","assets/specs-DII0C8gw.js","assets/terminal-BAzpHtpY.js","assets/tickets-W6pBmbrX.js","assets/createLucideIcon-Bjbbp_KS.js","assets/Trans-SnMX4MhW.js","assets/useDesktop-RSMTyy7V.js","assets/react-dom-DiWzBDP9.js","assets/spending-BqbdPm_4.js","assets/clsx-CjueKrWZ.js","assets/formatDistanceToNow-DSj5DprF.js","assets/getTimezoneOffsetInMilliseconds-YhD8rIEs.js","assets/provider-capabilities-B-wOHfLP.js","assets/index-m5pKr1T6.js","assets/TicketDetailModalContext-BNa1mdXq.js","assets/save-B6wGWwBR.js","assets/MinimizedChatsContext-Deg39peL.js","assets/sparkles-DrY8hb0X.js","assets/x-CBMI9ejn.js","assets/file-text-BcLCfcWZ.js","assets/circle-x-CMYsN4ZH.js","assets/download-CFHyyHcw.js","assets/git-branch-BRM0F5GN.js","assets/loader-circle-DcygOQpC.js","assets/pencil-C9RkrIPZ.js","assets/square-Ci-PFcFe.js","assets/plus-CsnjfkmX.js","assets/search-Cq_gE3Ik.js","assets/trash-2-BOU3WdZZ.js","assets/triangle-alert-H9T4jAmh.js","assets/jira-api-CSCqGr-Q.js","assets/zap-CHo3aCD1.js","assets/dialog-xXB2q5HJ.js","assets/utils-BC4DHlz2.js","assets/lib-CGdyxIWg.js","assets/button-Ccc9Dc-D.js","assets/RepositoryScopeSelector-D-RCaknl.js","assets/project-repositories-DYhTvwQ1.js","assets/core-B3mKBIh5.js","assets/RepositoryDeliveries-IiQCcndQ.js","assets/event-Bt7f3wXe.js","assets/index-D5n_jg_I.css","assets/ExportDropdown-ophapHrT.js","assets/BarChart-nBOMNfiy.js","assets/value-s-gzBeyF.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"./preload-helper-Czpn1I53.js";import{n as i}from"./createLucideIcon-Bjbbp_KS.js";import{t as a}from"./loader-circle-DcygOQpC.js";import{t as o}from"./x-CBMI9ejn.js";import{t as s}from"./utils-BC4DHlz2.js";import{W as c,_t as l,gt as u}from"./index-m5pKr1T6.js";var d=e(t(),1),f=n(),p=(0,d.lazy)(()=>r(()=>import(`./AnalyticsPage-C6ZZI_zg.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75]))),m=420,h=560;function g(){let{t:e}=i(`agent`),{closeAnalyticsPane:t}=c(),[n,r]=(0,d.useState)(h),[g,_]=(0,d.useState)(!1),v=(0,d.useCallback)(e=>{let t=e.clientX,i=n,a=window.innerWidth-m;try{e.currentTarget.setPointerCapture(e.pointerId)}catch{}let o=e=>{let n=Math.min(Math.max(i+(t-e.clientX),m),a);r(n)},s=()=>{window.removeEventListener(`pointermove`,o),window.removeEventListener(`pointerup`,s),window.removeEventListener(`pointercancel`,s)};window.addEventListener(`pointermove`,o),window.addEventListener(`pointerup`,s),window.addEventListener(`pointercancel`,s)},[n]);return(0,f.jsxs)(`div`,{className:s(`flex h-full flex-col overflow-hidden border-l border-border bg-background`,g&&`absolute inset-0 z-30 border-l-0`),style:g?void 0:{width:n,flexShrink:0},"data-testid":`agent-analytics-pane`,children:[(0,f.jsx)(`div`,{className:`relative flex items-center`,children:!g&&(0,f.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,onPointerDown:v,className:`absolute left-0 top-0 h-full w-1.5 -translate-x-full cursor-col-resize select-none touch-none hover:bg-accent-primary/20`,title:e(`workspace.resizeAnalytics`)})}),(0,f.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-border/60 bg-surface/40 px-3 py-1.5`,children:[(0,f.jsx)(`span`,{className:`text-xs font-medium text-foreground/70`,children:e(`workspace.analytics`)}),(0,f.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[(0,f.jsx)(`button`,{type:`button`,onClick:()=>_(e=>!e),"aria-label":e(g?`restore`:`maximize`),title:e(g?`restore`:`maximize`),className:`rounded-md p-1 text-foreground/60 hover:bg-surface hover:text-foreground`,children:g?(0,f.jsx)(u,{className:`h-4 w-4`}):(0,f.jsx)(l,{className:`h-4 w-4`})}),(0,f.jsx)(`button`,{type:`button`,onClick:t,"aria-label":e(`workspace.closeAnalytics`),title:e(`workspace.closeAnalytics`),className:`rounded-md p-1 text-foreground/60 hover:bg-surface hover:text-foreground`,children:(0,f.jsx)(o,{className:`h-4 w-4`})})]})]}),(0,f.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:(0,f.jsx)(d.Suspense,{fallback:(0,f.jsx)(`div`,{className:`flex h-24 items-center justify-center text-muted-foreground`,children:(0,f.jsx)(a,{className:`h-4 w-4 animate-spin`})}),children:(0,f.jsx)(p,{})})})]})}export{g as AgentModeAnalyticsPane};
@@ -1,2 +1,2 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/CodePage-C9KyuV_C.js","assets/rolldown-runtime-CNC7AqOf.js","assets/jsx-runtime-zu2_FqZY.js","assets/react-dom-DiWzBDP9.js","assets/preload-helper-Czpn1I53.js","assets/chunk-KS7C4IRE-DEKu087k.js","assets/TicketDetailModalContext-DqyF0so-.js","assets/useSharedWebSocket-BOdS5_Iz.js","assets/activity-DiyjsgQV.js","assets/addspec-D2YIQ0GU.js","assets/agent-Bh9K7iEt.js","assets/agents-ms7TwG16.js","assets/agentstudio-CN2pokQu.js","assets/aiedit-iIjz2_Qk.js","assets/analytics-BMzCvrCU.js","assets/attachments-B53PG733.js","assets/browser-CG0PE1j_.js","assets/builder-BTiGnPT0.js","assets/chat-BGD7MXAy.js","assets/code-DaZ-ZwCT.js","assets/commands-BAWSYHjQ.js","assets/common-BrlwEnL7.js","assets/dashboard-BfBir_6o.js","assets/explore-DgBACn39.js","assets/integrations-mB-7zoyT.js","assets/jira-CKJg3HZd.js","assets/jobs-DzMjUcaN.js","assets/loops-B7YpGizO.js","assets/mcp-CUAN6ORK.js","assets/narration-B-ynWTpn.js","assets/nav-Ch-zHBG5.js","assets/packet-Cx-zRuWn.js","assets/settings-BJB9RKJj.js","assets/setup-Ba11l2JA.js","assets/specs-DII0C8gw.js","assets/terminal-BAzpHtpY.js","assets/tickets-W6pBmbrX.js","assets/createLucideIcon-Bjbbp_KS.js","assets/Trans-SnMX4MhW.js","assets/useDesktop-RSMTyy7V.js","assets/save-B6wGWwBR.js","assets/spending-BqbdPm_4.js","assets/MinimizedChatsContext-Deg39peL.js","assets/sparkles-DrY8hb0X.js","assets/x-CBMI9ejn.js","assets/file-text-BcLCfcWZ.js","assets/circle-x-CMYsN4ZH.js","assets/download-CFHyyHcw.js","assets/git-branch-BRM0F5GN.js","assets/loader-circle-DcygOQpC.js","assets/pencil-C9RkrIPZ.js","assets/square-Ci-PFcFe.js","assets/plus-CsnjfkmX.js","assets/search-Cq_gE3Ik.js","assets/trash-2-BOU3WdZZ.js","assets/triangle-alert-H9T4jAmh.js","assets/jira-api-CSCqGr-Q.js","assets/zap-CHo3aCD1.js","assets/dialog-SRw01_QU.js","assets/utils-BC4DHlz2.js","assets/clsx-CjueKrWZ.js","assets/lib-CGdyxIWg.js","assets/formatDistanceToNow-DSj5DprF.js","assets/getTimezoneOffsetInMilliseconds-YhD8rIEs.js","assets/button-DCBqEaZl.js","assets/RepositoryScopeSelector-D-RCaknl.js","assets/project-repositories-DYhTvwQ1.js","assets/provider-capabilities-B-wOHfLP.js","assets/index-EzrkUb8B.js","assets/core-B3mKBIh5.js","assets/RepositoryDeliveries-CSDsiVUz.js","assets/event-Bt7f3wXe.js","assets/index-DwAmL7m5.css"])))=>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"./preload-helper-Czpn1I53.js";import{n as i}from"./createLucideIcon-Bjbbp_KS.js";import{t as a}from"./x-CBMI9ejn.js";import{Q as o,W as s,Z as c,_t as l,gt as u}from"./index-EzrkUb8B.js";var d=e(t(),1),f=n(),p=(0,d.lazy)(()=>r(()=>import(`./CodePage-C9KyuV_C.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72]))),m=420,h=560;function g({projectId:e,conversationId:t}){let{t:n}=i(`agent`),{closeCodePane:r}=s(),[g,_]=(0,d.useState)(h),[v,y]=(0,d.useState)(()=>window.innerWidth),[b,x]=(0,d.useState)(!1),S=(0,d.useRef)(null),C=(0,d.useRef)(null),w=Math.max(0,v-Math.min(m,v/2)),T=Math.min(m,w),E=Math.min(w,Math.max(T,g)),D=(0,d.useCallback)(e=>Math.min(w,Math.max(T,e)),[w,T]),O=`${e}:${t}`,k=(0,d.useCallback)(n=>{o(e,t,{path:n})},[e,t]);(0,d.useLayoutEffect)(()=>{let e=S.current,t=e?.parentElement;if(!e||!t)return;let n=()=>{let n=t.getBoundingClientRect().width||t.clientWidth||window.innerWidth,r=0;for(let n of t.children){if(n===e||!(n instanceof HTMLElement))continue;let t=getComputedStyle(n);t.display===`none`||t.position===`absolute`||t.position===`fixed`||Number(t.flexGrow)>0||(r+=n.getBoundingClientRect().width)}y(Math.max(0,n-r))},r=new ResizeObserver(n),i=()=>{r.disconnect(),r.observe(t);for(let n of t.children)n!==e&&r.observe(n);n()},a=new MutationObserver(i);return a.observe(t,{childList:!0}),i(),window.addEventListener(`resize`,n),()=>{r.disconnect(),a.disconnect(),window.removeEventListener(`resize`,n)}},[O]),(0,d.useEffect)(()=>()=>{C.current?.()},[O,b,w]);let A=(0,d.useCallback)(e=>{if(e.button!==0)return;e.preventDefault(),C.current?.();let t=e.clientX,n=E,r=e.pointerId,i=e.currentTarget;try{i.setPointerCapture(r)}catch{}let a=e=>{e.pointerId===r&&_(D(n+t-e.clientX))},o=()=>{window.removeEventListener(`pointermove`,a),window.removeEventListener(`pointerup`,s),window.removeEventListener(`pointercancel`,s),window.removeEventListener(`blur`,o),i.removeEventListener(`lostpointercapture`,o);try{i.hasPointerCapture(r)&&i.releasePointerCapture(r)}catch{}C.current=null},s=e=>{e.pointerId===r&&o()};C.current=o,window.addEventListener(`pointermove`,a),window.addEventListener(`pointerup`,s),window.addEventListener(`pointercancel`,s),window.addEventListener(`blur`,o),i.addEventListener(`lostpointercapture`,o)},[E,D]);return(0,f.jsxs)(`div`,{ref:S,className:`flex h-full min-w-0 flex-col overflow-hidden border-l border-border bg-background${b?` absolute inset-0 z-30 border-l-0`:` relative`}`,style:b?void 0:{width:E,maxWidth:`100%`,flexShrink:0},"data-testid":`agent-code-pane`,children:[!b&&(0,f.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,onPointerDown:A,tabIndex:0,"aria-label":n(`workspace.resizeCode`),"aria-valuemin":Math.round(T),"aria-valuemax":Math.round(w),"aria-valuenow":Math.round(E),onKeyDown:e=>{let t=e.key===`ArrowLeft`?E+32:e.key===`ArrowRight`?E-32:e.key===`Home`?T:e.key===`End`?w:null;t!==null&&(e.preventDefault(),_(D(t)))},className:`absolute inset-y-0 left-0 z-20 w-1.5 cursor-col-resize select-none touch-none hover:bg-accent-primary/20 focus-visible:bg-accent-primary/30 focus-visible:outline-none`,title:n(`workspace.resizeCode`)}),(0,f.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-border/60 bg-surface/40 px-3 py-1.5`,children:[(0,f.jsx)(`span`,{className:`text-xs font-medium text-foreground/70`,children:n(`workspace.files`)}),(0,f.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[(0,f.jsx)(`button`,{type:`button`,onClick:()=>{C.current?.(),x(e=>!e)},"aria-label":n(b?`restore`:`maximize`),title:n(b?`restore`:`maximize`),className:`rounded-md p-1 text-foreground/60 hover:bg-surface hover:text-foreground`,children:b?(0,f.jsx)(u,{className:`h-4 w-4`}):(0,f.jsx)(l,{className:`h-4 w-4`})}),(0,f.jsx)(`button`,{type:`button`,onClick:()=>{C.current?.(),r()},"aria-label":n(`workspace.closeFiles`),title:n(`workspace.closeFiles`),className:`rounded-md p-1 text-foreground/60 hover:bg-surface hover:text-foreground`,children:(0,f.jsx)(a,{className:`h-4 w-4`})})]})]}),(0,f.jsx)(`div`,{className:`min-h-0 flex-1 overflow-hidden`,children:(0,f.jsx)(d.Suspense,{fallback:(0,f.jsx)(`div`,{className:`flex h-full items-center justify-center text-sm text-muted-foreground`,children:`…`}),children:(0,f.jsx)(p,{embedded:!0,initialRepositoryId:c(e,t).repositoryId,onRepositoryChange:n=>o(e,t,{repositoryId:n}),initialPath:c(e,t).path,onSelectedPathChange:k},O)})})]},O)}export{g as AgentModeCodePane};
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/CodePage-B5z5oLnP.js","assets/rolldown-runtime-CNC7AqOf.js","assets/jsx-runtime-zu2_FqZY.js","assets/react-dom-DiWzBDP9.js","assets/preload-helper-Czpn1I53.js","assets/chunk-KS7C4IRE-DEKu087k.js","assets/TicketDetailModalContext-BNa1mdXq.js","assets/useSharedWebSocket-BOdS5_Iz.js","assets/activity-DiyjsgQV.js","assets/addspec-D2YIQ0GU.js","assets/agent-Bh9K7iEt.js","assets/agents-ms7TwG16.js","assets/agentstudio-CN2pokQu.js","assets/aiedit-iIjz2_Qk.js","assets/analytics-BMzCvrCU.js","assets/attachments-B53PG733.js","assets/browser-CG0PE1j_.js","assets/builder-BTiGnPT0.js","assets/chat-BGD7MXAy.js","assets/code-DaZ-ZwCT.js","assets/commands-BAWSYHjQ.js","assets/common-BrlwEnL7.js","assets/dashboard-BfBir_6o.js","assets/explore-DgBACn39.js","assets/integrations-mB-7zoyT.js","assets/jira-CKJg3HZd.js","assets/jobs-DzMjUcaN.js","assets/loops-B7YpGizO.js","assets/mcp-CUAN6ORK.js","assets/narration-B-ynWTpn.js","assets/nav-Ch-zHBG5.js","assets/packet-Cx-zRuWn.js","assets/settings-BJB9RKJj.js","assets/setup-Ba11l2JA.js","assets/specs-DII0C8gw.js","assets/terminal-BAzpHtpY.js","assets/tickets-W6pBmbrX.js","assets/createLucideIcon-Bjbbp_KS.js","assets/Trans-SnMX4MhW.js","assets/useDesktop-RSMTyy7V.js","assets/save-B6wGWwBR.js","assets/spending-BqbdPm_4.js","assets/MinimizedChatsContext-Deg39peL.js","assets/sparkles-DrY8hb0X.js","assets/x-CBMI9ejn.js","assets/file-text-BcLCfcWZ.js","assets/circle-x-CMYsN4ZH.js","assets/download-CFHyyHcw.js","assets/git-branch-BRM0F5GN.js","assets/loader-circle-DcygOQpC.js","assets/pencil-C9RkrIPZ.js","assets/square-Ci-PFcFe.js","assets/plus-CsnjfkmX.js","assets/search-Cq_gE3Ik.js","assets/trash-2-BOU3WdZZ.js","assets/triangle-alert-H9T4jAmh.js","assets/jira-api-CSCqGr-Q.js","assets/zap-CHo3aCD1.js","assets/dialog-xXB2q5HJ.js","assets/utils-BC4DHlz2.js","assets/clsx-CjueKrWZ.js","assets/lib-CGdyxIWg.js","assets/formatDistanceToNow-DSj5DprF.js","assets/getTimezoneOffsetInMilliseconds-YhD8rIEs.js","assets/button-Ccc9Dc-D.js","assets/RepositoryScopeSelector-D-RCaknl.js","assets/project-repositories-DYhTvwQ1.js","assets/provider-capabilities-B-wOHfLP.js","assets/index-m5pKr1T6.js","assets/core-B3mKBIh5.js","assets/RepositoryDeliveries-IiQCcndQ.js","assets/event-Bt7f3wXe.js","assets/index-D5n_jg_I.css"])))=>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"./preload-helper-Czpn1I53.js";import{n as i}from"./createLucideIcon-Bjbbp_KS.js";import{t as a}from"./x-CBMI9ejn.js";import{Q as o,W as s,Z as c,_t as l,gt as u}from"./index-m5pKr1T6.js";var d=e(t(),1),f=n(),p=(0,d.lazy)(()=>r(()=>import(`./CodePage-B5z5oLnP.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72]))),m=420,h=560;function g({projectId:e,conversationId:t}){let{t:n}=i(`agent`),{closeCodePane:r}=s(),[g,_]=(0,d.useState)(h),[v,y]=(0,d.useState)(()=>window.innerWidth),[b,x]=(0,d.useState)(!1),S=(0,d.useRef)(null),C=(0,d.useRef)(null),w=Math.max(0,v-Math.min(m,v/2)),T=Math.min(m,w),E=Math.min(w,Math.max(T,g)),D=(0,d.useCallback)(e=>Math.min(w,Math.max(T,e)),[w,T]),O=`${e}:${t}`,k=(0,d.useCallback)(n=>{o(e,t,{path:n})},[e,t]);(0,d.useLayoutEffect)(()=>{let e=S.current,t=e?.parentElement;if(!e||!t)return;let n=()=>{let n=t.getBoundingClientRect().width||t.clientWidth||window.innerWidth,r=0;for(let n of t.children){if(n===e||!(n instanceof HTMLElement))continue;let t=getComputedStyle(n);t.display===`none`||t.position===`absolute`||t.position===`fixed`||Number(t.flexGrow)>0||(r+=n.getBoundingClientRect().width)}y(Math.max(0,n-r))},r=new ResizeObserver(n),i=()=>{r.disconnect(),r.observe(t);for(let n of t.children)n!==e&&r.observe(n);n()},a=new MutationObserver(i);return a.observe(t,{childList:!0}),i(),window.addEventListener(`resize`,n),()=>{r.disconnect(),a.disconnect(),window.removeEventListener(`resize`,n)}},[O]),(0,d.useEffect)(()=>()=>{C.current?.()},[O,b,w]);let A=(0,d.useCallback)(e=>{if(e.button!==0)return;e.preventDefault(),C.current?.();let t=e.clientX,n=E,r=e.pointerId,i=e.currentTarget;try{i.setPointerCapture(r)}catch{}let a=e=>{e.pointerId===r&&_(D(n+t-e.clientX))},o=()=>{window.removeEventListener(`pointermove`,a),window.removeEventListener(`pointerup`,s),window.removeEventListener(`pointercancel`,s),window.removeEventListener(`blur`,o),i.removeEventListener(`lostpointercapture`,o);try{i.hasPointerCapture(r)&&i.releasePointerCapture(r)}catch{}C.current=null},s=e=>{e.pointerId===r&&o()};C.current=o,window.addEventListener(`pointermove`,a),window.addEventListener(`pointerup`,s),window.addEventListener(`pointercancel`,s),window.addEventListener(`blur`,o),i.addEventListener(`lostpointercapture`,o)},[E,D]);return(0,f.jsxs)(`div`,{ref:S,className:`flex h-full min-w-0 flex-col overflow-hidden border-l border-border bg-background${b?` absolute inset-0 z-30 border-l-0`:` relative`}`,style:b?void 0:{width:E,maxWidth:`100%`,flexShrink:0},"data-testid":`agent-code-pane`,children:[!b&&(0,f.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,onPointerDown:A,tabIndex:0,"aria-label":n(`workspace.resizeCode`),"aria-valuemin":Math.round(T),"aria-valuemax":Math.round(w),"aria-valuenow":Math.round(E),onKeyDown:e=>{let t=e.key===`ArrowLeft`?E+32:e.key===`ArrowRight`?E-32:e.key===`Home`?T:e.key===`End`?w:null;t!==null&&(e.preventDefault(),_(D(t)))},className:`absolute inset-y-0 left-0 z-20 w-1.5 cursor-col-resize select-none touch-none hover:bg-accent-primary/20 focus-visible:bg-accent-primary/30 focus-visible:outline-none`,title:n(`workspace.resizeCode`)}),(0,f.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-border/60 bg-surface/40 px-3 py-1.5`,children:[(0,f.jsx)(`span`,{className:`text-xs font-medium text-foreground/70`,children:n(`workspace.files`)}),(0,f.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[(0,f.jsx)(`button`,{type:`button`,onClick:()=>{C.current?.(),x(e=>!e)},"aria-label":n(b?`restore`:`maximize`),title:n(b?`restore`:`maximize`),className:`rounded-md p-1 text-foreground/60 hover:bg-surface hover:text-foreground`,children:b?(0,f.jsx)(u,{className:`h-4 w-4`}):(0,f.jsx)(l,{className:`h-4 w-4`})}),(0,f.jsx)(`button`,{type:`button`,onClick:()=>{C.current?.(),r()},"aria-label":n(`workspace.closeFiles`),title:n(`workspace.closeFiles`),className:`rounded-md p-1 text-foreground/60 hover:bg-surface hover:text-foreground`,children:(0,f.jsx)(a,{className:`h-4 w-4`})})]})]}),(0,f.jsx)(`div`,{className:`min-h-0 flex-1 overflow-hidden`,children:(0,f.jsx)(d.Suspense,{fallback:(0,f.jsx)(`div`,{className:`flex h-full items-center justify-center text-sm text-muted-foreground`,children:`…`}),children:(0,f.jsx)(p,{embedded:!0,initialRepositoryId:c(e,t).repositoryId,onRepositoryChange:n=>o(e,t,{repositoryId:n}),initialPath:c(e,t).path,onSelectedPathChange:k},O)})})]},O)}export{g as AgentModeCodePane};
@@ -1 +1 @@
1
- import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-zu2_FqZY.js";import{m as r,r as i}from"./useSharedWebSocket-BOdS5_Iz.js";import{n as a}from"./createLucideIcon-Bjbbp_KS.js";import{a as o,i as s,r as c}from"./useDesktop-RSMTyy7V.js";import{t as l}from"./loader-circle-DcygOQpC.js";import{t as u}from"./x-CBMI9ejn.js";import{t as d}from"./utils-BC4DHlz2.js";import{t as f}from"./formatDistanceToNow-DSj5DprF.js";import{Pt as p,W as m,_t as h,gt as g,x as _}from"./index-EzrkUb8B.js";import{n as v,t as y}from"./job-time-BCL7wee9.js";import{JobDetailModal as b}from"./JobDetailModal-DNWmgVHD.js";import{t as x}from"./format-command-C0D9IPmV.js";var S=e(t(),1),C=n(),w=360,T=480,E={running:`running`,completed:`success`,failed:`failed`,canceled:`canceled`,queued:`queued`};function D({projectId:e}){let{t}=a(`agent`),{t:n}=a(`jobs`),{closeJobsPane:D}=m(),{projects:O}=c(),k=O.find(t=>t.id===e)?.provider,[A,j]=(0,S.useState)(T),[M,N]=(0,S.useState)(!1),[P,F]=(0,S.useState)(null),{data:I,isFirstLoad:L,refresh:R}=s({namespace:`agent-jobs`,projectId:e,initialValue:[],fetcher:async()=>{let e=await fetch(`${o()}/jobs?limit=50`);return e.ok?(await e.json()).jobs:[]},pollInterval:5e3}),{registerHandler:z,unregisterHandler:B}=i(),V=(0,S.useRef)(e);V.current=e;let H=(0,S.useRef)(R);H.current=R,(0,S.useEffect)(()=>(z(`agent-jobs-pane`,e=>{let t=e;t.type===`queue`&&(t.projectId&&t.projectId!==V.current||H.current())}),()=>B(`agent-jobs-pane`)),[z,B]);let U=(0,S.useCallback)(e=>{let t=e.clientX,n=A,r=window.innerWidth-w;try{e.currentTarget.setPointerCapture(e.pointerId)}catch{}let i=e=>{let i=Math.min(Math.max(n+(t-e.clientX),w),r);j(i)},a=()=>{window.removeEventListener(`pointermove`,i),window.removeEventListener(`pointerup`,a),window.removeEventListener(`pointercancel`,a)};window.addEventListener(`pointermove`,i),window.addEventListener(`pointerup`,a),window.addEventListener(`pointercancel`,a)},[A]);return(0,C.jsxs)(`div`,{className:d(`flex h-full flex-col overflow-hidden border-l border-border bg-background`,M&&`absolute inset-0 z-30 border-l-0`),style:M?void 0:{width:A,flexShrink:0},children:[(0,C.jsx)(`div`,{className:`relative flex items-center`,children:!M&&(0,C.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,onPointerDown:U,className:`absolute left-0 top-0 h-full w-1.5 -translate-x-full cursor-col-resize select-none touch-none hover:bg-accent-primary/20`,title:t(`workspace.resizeJobs`)})}),(0,C.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-border/60 bg-surface/40 px-3 py-1.5`,children:[(0,C.jsx)(`span`,{className:`text-xs font-medium text-foreground/70`,children:t(`workspace.jobs`)}),(0,C.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[(0,C.jsx)(`button`,{type:`button`,onClick:()=>N(e=>!e),"aria-label":t(M?`restore`:`maximize`),title:t(M?`restore`:`maximize`),className:`rounded-md p-1 text-foreground/60 hover:bg-surface hover:text-foreground`,children:M?(0,C.jsx)(g,{className:`h-4 w-4`}):(0,C.jsx)(h,{className:`h-4 w-4`})}),(0,C.jsx)(`button`,{type:`button`,onClick:D,"aria-label":t(`workspace.closeJobs`),title:t(`workspace.closeJobs`),className:`rounded-md p-1 text-foreground/60 hover:bg-surface hover:text-foreground`,children:(0,C.jsx)(u,{className:`h-4 w-4`})})]})]}),(0,C.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-2`,children:L?(0,C.jsx)(`div`,{className:`flex h-24 items-center justify-center text-muted-foreground`,children:(0,C.jsx)(l,{className:`h-4 w-4 animate-spin`})}):I.length===0?(0,C.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-2 text-center text-muted-foreground`,children:[(0,C.jsx)(p,{className:`h-6 w-6 opacity-40`}),(0,C.jsx)(`p`,{className:`text-xs`,children:t(`workspace.noJobs`)})]}):(0,C.jsx)(`ul`,{className:`space-y-1`,children:I.map(e=>(0,C.jsx)(`li`,{children:(0,C.jsxs)(`button`,{type:`button`,onClick:()=>F(e.id),className:d(`flex w-full flex-col gap-1 rounded-lg border border-border/50 bg-surface/30 px-2.5 py-2 text-left transition-colors`,`hover:border-accent-primary/40 hover:bg-surface/60`),children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,C.jsx)(_,{variant:E[e.status]??`queued`,children:n(`statusLabel.${e.status in E?e.status:`queued`}`)}),e.status===`running`&&(0,C.jsx)(l,{className:`h-3 w-3 animate-spin text-accent-primary`}),(0,C.jsx)(`span`,{className:`ml-auto text-[10px] text-muted-foreground`,children:(()=>{let t=v(y(e));return t?f(t,{addSuffix:!0,locale:r()}):`—`})()})]}),(0,C.jsx)(`code`,{className:`truncate font-mono text-xs text-foreground/85`,children:x(e.command,k)})]})},e.id))})}),P&&(0,C.jsx)(b,{jobId:P,onClose:()=>F(null)})]})}export{D as AgentModeJobsPane};
1
+ import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-zu2_FqZY.js";import{m as r,r as i}from"./useSharedWebSocket-BOdS5_Iz.js";import{n as a}from"./createLucideIcon-Bjbbp_KS.js";import{a as o,i as s,r as c}from"./useDesktop-RSMTyy7V.js";import{t as l}from"./loader-circle-DcygOQpC.js";import{t as u}from"./x-CBMI9ejn.js";import{t as d}from"./utils-BC4DHlz2.js";import{t as f}from"./formatDistanceToNow-DSj5DprF.js";import{Pt as p,W as m,_t as h,gt as g,x as _}from"./index-m5pKr1T6.js";import{n as v,t as y}from"./job-time-BCL7wee9.js";import{JobDetailModal as b}from"./JobDetailModal-BCxue_Do.js";import{t as x}from"./format-command-C0D9IPmV.js";var S=e(t(),1),C=n(),w=360,T=480,E={running:`running`,completed:`success`,failed:`failed`,canceled:`canceled`,queued:`queued`};function D({projectId:e}){let{t}=a(`agent`),{t:n}=a(`jobs`),{closeJobsPane:D}=m(),{projects:O}=c(),k=O.find(t=>t.id===e)?.provider,[A,j]=(0,S.useState)(T),[M,N]=(0,S.useState)(!1),[P,F]=(0,S.useState)(null),{data:I,isFirstLoad:L,refresh:R}=s({namespace:`agent-jobs`,projectId:e,initialValue:[],fetcher:async()=>{let e=await fetch(`${o()}/jobs?limit=50`);return e.ok?(await e.json()).jobs:[]},pollInterval:5e3}),{registerHandler:z,unregisterHandler:B}=i(),V=(0,S.useRef)(e);V.current=e;let H=(0,S.useRef)(R);H.current=R,(0,S.useEffect)(()=>(z(`agent-jobs-pane`,e=>{let t=e;t.type===`queue`&&(t.projectId&&t.projectId!==V.current||H.current())}),()=>B(`agent-jobs-pane`)),[z,B]);let U=(0,S.useCallback)(e=>{let t=e.clientX,n=A,r=window.innerWidth-w;try{e.currentTarget.setPointerCapture(e.pointerId)}catch{}let i=e=>{let i=Math.min(Math.max(n+(t-e.clientX),w),r);j(i)},a=()=>{window.removeEventListener(`pointermove`,i),window.removeEventListener(`pointerup`,a),window.removeEventListener(`pointercancel`,a)};window.addEventListener(`pointermove`,i),window.addEventListener(`pointerup`,a),window.addEventListener(`pointercancel`,a)},[A]);return(0,C.jsxs)(`div`,{className:d(`flex h-full flex-col overflow-hidden border-l border-border bg-background`,M&&`absolute inset-0 z-30 border-l-0`),style:M?void 0:{width:A,flexShrink:0},children:[(0,C.jsx)(`div`,{className:`relative flex items-center`,children:!M&&(0,C.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,onPointerDown:U,className:`absolute left-0 top-0 h-full w-1.5 -translate-x-full cursor-col-resize select-none touch-none hover:bg-accent-primary/20`,title:t(`workspace.resizeJobs`)})}),(0,C.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-border/60 bg-surface/40 px-3 py-1.5`,children:[(0,C.jsx)(`span`,{className:`text-xs font-medium text-foreground/70`,children:t(`workspace.jobs`)}),(0,C.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[(0,C.jsx)(`button`,{type:`button`,onClick:()=>N(e=>!e),"aria-label":t(M?`restore`:`maximize`),title:t(M?`restore`:`maximize`),className:`rounded-md p-1 text-foreground/60 hover:bg-surface hover:text-foreground`,children:M?(0,C.jsx)(g,{className:`h-4 w-4`}):(0,C.jsx)(h,{className:`h-4 w-4`})}),(0,C.jsx)(`button`,{type:`button`,onClick:D,"aria-label":t(`workspace.closeJobs`),title:t(`workspace.closeJobs`),className:`rounded-md p-1 text-foreground/60 hover:bg-surface hover:text-foreground`,children:(0,C.jsx)(u,{className:`h-4 w-4`})})]})]}),(0,C.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-2`,children:L?(0,C.jsx)(`div`,{className:`flex h-24 items-center justify-center text-muted-foreground`,children:(0,C.jsx)(l,{className:`h-4 w-4 animate-spin`})}):I.length===0?(0,C.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-2 text-center text-muted-foreground`,children:[(0,C.jsx)(p,{className:`h-6 w-6 opacity-40`}),(0,C.jsx)(`p`,{className:`text-xs`,children:t(`workspace.noJobs`)})]}):(0,C.jsx)(`ul`,{className:`space-y-1`,children:I.map(e=>(0,C.jsx)(`li`,{children:(0,C.jsxs)(`button`,{type:`button`,onClick:()=>F(e.id),className:d(`flex w-full flex-col gap-1 rounded-lg border border-border/50 bg-surface/30 px-2.5 py-2 text-left transition-colors`,`hover:border-accent-primary/40 hover:bg-surface/60`),children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,C.jsx)(_,{variant:E[e.status]??`queued`,children:n(`statusLabel.${e.status in E?e.status:`queued`}`)}),e.status===`running`&&(0,C.jsx)(l,{className:`h-3 w-3 animate-spin text-accent-primary`}),(0,C.jsx)(`span`,{className:`ml-auto text-[10px] text-muted-foreground`,children:(()=>{let t=v(y(e));return t?f(t,{addSuffix:!0,locale:r()}):`—`})()})]}),(0,C.jsx)(`code`,{className:`truncate font-mono text-xs text-foreground/85`,children:x(e.command,k)})]})},e.id))})}),P&&(0,C.jsx)(b,{jobId:P,onClose:()=>F(null)})]})}export{D as AgentModeJobsPane};
@@ -1,4 +1,4 @@
1
- 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{h as i,r as a}from"./useSharedWebSocket-BOdS5_Iz.js";import{t as o}from"./Trans-SnMX4MhW.js";import{n as s,t as c}from"./createLucideIcon-Bjbbp_KS.js";import{a as l,r as u,s as d}from"./useDesktop-RSMTyy7V.js";import{n as f,t as p}from"./save-B6wGWwBR.js";import{c as m,d as h,f as g,n as _,r as v,u as y}from"./MinimizedChatsContext-Deg39peL.js";import{n as b,t as x}from"./file-text-BcLCfcWZ.js";import{t as S}from"./loader-circle-DcygOQpC.js";import{t as C}from"./pencil-C9RkrIPZ.js";import{t as w}from"./plus-CsnjfkmX.js";import{t as ee}from"./search-Cq_gE3Ik.js";import{t as T}from"./sparkles-DrY8hb0X.js";import{t as E}from"./trash-2-BOU3WdZZ.js";import{t as D}from"./triangle-alert-H9T4jAmh.js";import{t as O}from"./x-CBMI9ejn.js";import{M as k,a as A,i as j,j as M,l as N,o as P,r as F,t as I}from"./dialog-SRw01_QU.js";import{t as L}from"./button-DCBqEaZl.js";import{i as R,r as z}from"./provider-capabilities-B-wOHfLP.js";import{A as B,C as V,Ct as H,D as U,E as te,F as ne,H as W,M as re,Mt as ie,N as G,O as ae,Rt as K,S as oe,St as se,T as ce,_ as le,ft as q,ht as ue,it as de,j as J,k as Y,kt as fe,l as pe,mt as me,tt as he,w as ge,y as _e}from"./index-EzrkUb8B.js";import{t as ve}from"./format-command-C0D9IPmV.js";var ye=c(`flask-conical`,[[`path`,{d:`M14 2v6a2 2 0 0 0 .245.96l5.51 10.08A2 2 0 0 1 18 22H6a2 2 0 0 1-1.755-2.96l5.51-10.08A2 2 0 0 0 10 8V2`,key:`18mbvz`}],[`path`,{d:`M6.453 15h11.094`,key:`3shlmq`}],[`path`,{d:`M8.5 2h7`,key:`csnxdl`}]]),X=e(t(),1),Z=n(),be=/^[a-z0-9][a-z0-9-]*$/;function xe({open:e,mode:t=`add`,initial:n,chainAgents:r,onConfirm:i,onCancel:a}){let{t:c}=s(`agents`),[l,u]=(0,X.useState)(``),[d,f]=(0,X.useState)(r[0]??``);(0,X.useEffect)(()=>{e&&(t===`edit`&&n?(u(n.tags.join(`, `)),f(r.includes(n.agent)?n.agent:r[0]??``)):(u(``),f(r[0]??``)))},[e,t,n,r]);let p=l.split(`,`).map(e=>e.trim()).filter(Boolean),m=p.filter(e=>!be.test(e)),h=p.length>0&&m.length===0&&r.includes(d);return(0,Z.jsx)(I,{open:e,onOpenChange:e=>{e||a()},children:(0,Z.jsxs)(F,{movableResizable:!0,className:`max-w-md`,children:[(0,Z.jsxs)(P,{children:[(0,Z.jsx)(N,{children:c(t===`edit`?`routingRule.editTitle`:`routingRule.addTitle`)}),(0,Z.jsx)(j,{children:c(t===`edit`?`routingRule.editDescription`:`routingRule.addDescription`)})]}),(0,Z.jsxs)(`div`,{className:`py-2 space-y-3`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:c(`routingRule.tagsLabel`)}),(0,Z.jsx)(ne,{autoFocus:!0,value:l,onChange:e=>u(e.target.value),placeholder:`frontend, ui`,"aria-label":c(`routingRule.tagsLabel`),className:`text-sm font-mono`}),(0,Z.jsx)(`p`,{className:`text-[11px] text-muted-foreground mt-1`,children:(0,Z.jsx)(o,{t:c,i18nKey:`routingRule.tagsHint`,components:{code:(0,Z.jsx)(`code`,{})}})}),m.length>0&&(0,Z.jsx)(`p`,{className:`text-[11px] text-red-400 aurora-light:text-destructive mt-1`,children:c(`routingRule.invalidTags`,{count:m.length,tags:m.join(`, `)})})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:c(`routingRule.routeToLabel`)}),(0,Z.jsx)(`select`,{value:d,onChange:e=>f(e.target.value),"aria-label":c(`routingRule.routeToLabel`),className:`w-full h-9 px-2 text-sm rounded-md border border-border bg-background`,children:r.map(e=>(0,Z.jsx)(`option`,{value:e,children:e},e))}),(0,Z.jsx)(`p`,{className:`text-[11px] text-muted-foreground mt-1`,children:c(`routingRule.routeToHint`)})]})]}),(0,Z.jsxs)(A,{children:[(0,Z.jsx)(L,{variant:`ghost`,size:`sm`,onClick:a,children:c(`common:actions.cancel`)}),(0,Z.jsx)(L,{size:`sm`,onClick:()=>i(p,d),disabled:!h,children:c(t===`edit`?`routingRule.saveChanges`:`routingRule.addRule`)})]})]})})}var Se=new Set([`sr-architect`,`sr-developer`,`sr-reviewer`,`sr-merge-resolver`]),Ce=[`sonnet`,`fable`,`opus`,`haiku`],we=/^[a-z0-9][a-z0-9-]*$/,Te=Ce.map(e=>({value:e,label:e})),Ee=[...Se];function De({profile:e,onChange:t,footer:n,provider:r=e.provider??`claude`,modelCatalog:i=Te,defaultModel:a=i[0]?.value??``,customModelAliases:c=!1,baselineAgents:u=Ee,onValidityChange:d,onSoftWarningsChange:f}){let{t:p}=s(`agentstudio`),[m,h]=(0,X.useState)([]),[g,_]=(0,X.useState)(!1),[v,y]=(0,X.useState)(!1),[b,x]=(0,X.useState)(null),S=(0,X.useMemo)(()=>new Set(u),[u]);(0,X.useEffect)(()=>{let e=!1;return fetch(`${l()}/profiles/catalog?provider=${encodeURIComponent(r)}`).then(e=>e.ok?e.json():{agents:[]}).then(t=>{e||h(t.agents)}).catch(()=>{e||h([])}),()=>{e=!0}},[r]);let C=n=>{let r=JSON.parse(JSON.stringify(e));n(r),t(r)},ee=new Set(e.agents.map(e=>e.id)),T=m.filter(e=>!ee.has(e.id)),E=(0,X.useMemo)(()=>{let t=[];for(let n of S)e.agents.some(e=>e.id===n)||t.push(p(`profileEditor.validation.missingBaseline`,{agent:n}));let n=e.routing.filter(e=>`default`in e&&e.default===!0);if(n.length>1&&t.push(p(`profileEditor.validation.multipleDefaultRules`,{found:n.length})),n.length===1){let n=e.routing[e.routing.length-1];`default`in n&&n.default===!0||t.push(p(`profileEditor.validation.defaultRuleNotLast`))}for(let n of e.routing)if(e.agents.some(e=>e.id===n.agent)||t.push(p(`profileEditor.validation.unknownRoutingAgent`,{agent:n.agent})),`tags`in n){let e=n.tags.filter(e=>!we.test(e));e.length>0&&t.push(p(`profileEditor.validation.invalidTags`,{agent:n.agent,tags:e.join(`, `)}))}return t},[e,S,p]),D=(0,X.useMemo)(()=>{if(e.routing.length===0)return[];let t=new Set(e.routing.map(e=>e.agent));return e.agents.filter(e=>!S.has(e.id)&&!t.has(e.id)).map(e=>e.id)},[e,S]),k=(0,X.useMemo)(()=>e.routing.some(e=>`default`in e&&e.default===!0),[e.routing]);(0,X.useEffect)(()=>{d&&d(E)},[E,d]),(0,X.useEffect)(()=>{f&&f({agentsMissingRouting:D})},[D,f]);let A=e=>{C(t=>{let n={id:e,model:a},r=t.agents.findIndex(e=>e.id===`sr-merge-resolver`);r>=0?t.agents.splice(r,0,n):t.agents.push(n)}),_(!1)},j=t=>{let n=e.agents[t];S.has(n.id)||C(e=>{e.agents.splice(t,1),e.routing=e.routing.filter(e=>e.agent!==n.id)})},M=(t,n)=>{if(t===n)return;let r=e.agents.findIndex(e=>e.id===t),i=e.agents.findIndex(e=>e.id===n);if(r<0||i<0)return;let a=V(e.agents,r,i),o=a.findIndex(e=>e.id===`sr-architect`);if(o>0){let[e]=a.splice(o,1);a.unshift(e)}let s=a.findIndex(e=>e.id===`sr-merge-resolver`);if(s>=0&&s!==a.length-1){let[e]=a.splice(s,1);a.push(e)}C(e=>{e.agents=a})},N=re(J(Y,{activationConstraint:{distance:4}}),J(ae,{coordinateGetter:ge})),P=e=>{let{active:t,over:n}=e;n&&M(String(t.id),String(n.id))},F=(e,t)=>{C(n=>{n.agents[e].model=t})},I=(e,t)=>{C(n=>{let r={tags:e,agent:t},i=n.routing.findIndex(e=>`default`in e&&e.default===!0);i>=0?n.routing.splice(i,0,r):n.routing.push(r)}),y(!1)},R=()=>{C(e=>{e.routing.some(e=>`default`in e&&e.default===!0)||e.agents.some(e=>e.id===`sr-developer`)&&e.routing.push({default:!0,agent:`sr-developer`})})},z=e=>`default`in e&&e.default===!0,H=(e,t)=>{C(n=>{let r=n.routing[e];r&&(z(r)||(r.agent=t))})},W=(e,t,n)=>{C(r=>{let i=r.routing[e];i&&(z(i)||(i.tags=t,i.agent=n))})},ie=e=>{C(t=>{let n=t.routing[e];n&&(z(n)||t.routing.splice(e,1))})},G=(t,n)=>{let r=t+n;if(r<0||r>=e.routing.length)return;let i=e.routing[t],a=e.routing[r];z(i)||z(a)||C(e=>{let[n]=e.routing.splice(t,1);e.routing.splice(r,0,n)})};return(0,Z.jsxs)(`div`,{className:`p-6 space-y-6 max-w-3xl`,children:[(0,Z.jsx)(xe,{open:v,mode:`add`,chainAgents:e.agents.map(e=>e.id),onConfirm:I,onCancel:()=>y(!1)}),(0,Z.jsx)(xe,{open:b!==null,mode:`edit`,initial:b!==null&&e.routing[b]&&!(`default`in e.routing[b])?{tags:e.routing[b].tags,agent:e.routing[b].agent}:void 0,chainAgents:e.agents.map(e=>e.id),onConfirm:(e,t)=>{b!==null&&(W(b,e,t),x(null))},onCancel:()=>x(null)}),E.length>0&&(0,Z.jsxs)(`div`,{className:`px-3 py-2 text-xs rounded-md border border-yellow-500/30 aurora-light:border-accent-warning/30 bg-yellow-500/10 aurora-light:bg-accent-warning/10 text-yellow-500 aurora-light:text-accent-warning`,children:[(0,Z.jsx)(`div`,{className:`font-medium mb-1`,children:p(`profileEditor.validationSummary`,{count:E.length})}),(0,Z.jsx)(`ul`,{className:`list-disc list-inside space-y-0.5`,children:E.map((e,t)=>(0,Z.jsx)(`li`,{children:e},t))})]}),(0,Z.jsxs)(`section`,{className:`space-y-3`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:p(`profileEditor.nameLabel`)}),(0,Z.jsx)(ne,{value:e.name,disabled:!0,className:`text-sm`})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:p(`profileEditor.descriptionLabel`)}),(0,Z.jsx)(ne,{value:e.description??``,onChange:e=>C(t=>{t.description=e.target.value}),className:`text-sm`,placeholder:p(`profileEditor.descriptionPlaceholder`)})]})]}),(0,Z.jsxs)(`section`,{children:[(0,Z.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide mb-2`,children:p(`profileEditor.orchestrator.heading`)}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 p-3 rounded-md border border-border`,children:[(0,Z.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`text-sm font-mono text-foreground truncate`,children:[ve(`/specrails:implement`,r),` ·`,` `,ve(`/specrails:batch-implement`,r)]}),(0,Z.jsx)(`div`,{className:`text-[11px] text-muted-foreground mt-0.5`,children:p(`profileEditor.orchestrator.description`)})]}),(0,Z.jsx)(Q,{value:e.orchestrator.model,models:i,customModelAliases:c,testId:`profile-orchestrator-model`,onChange:e=>C(t=>{t.orchestrator.model=e})})]})]}),(0,Z.jsxs)(`section`,{children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,Z.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:p(`profileEditor.agentChain.heading`,{n:e.agents.length})}),(0,Z.jsxs)(L,{size:`sm`,variant:`ghost`,onClick:()=>_(e=>!e),disabled:T.length===0,title:T.length===0?p(`profileEditor.agentChain.addDisabledTitle`):p(`profileEditor.agentChain.addTitle`),children:[(0,Z.jsx)(w,{className:`w-3.5 h-3.5 mr-1`}),` `,p(`common:actions.add`)]})]}),g&&(0,Z.jsxs)(`div`,{className:`mb-2 p-2 rounded-md border border-border bg-muted/30`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between mb-1.5 px-1`,children:[(0,Z.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:p(`profileEditor.agentChain.pickFromCatalog`,{n:T.length})}),(0,Z.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:()=>_(!1),title:p(`common:actions.close`),children:(0,Z.jsx)(O,{className:`w-3 h-3`})})]}),T.length===0?(0,Z.jsx)(`div`,{className:`px-2 py-3 text-xs text-muted-foreground text-center`,children:p(`profileEditor.agentChain.emptyCatalog`)}):(0,Z.jsx)(`div`,{className:`space-y-0.5 max-h-64 overflow-auto`,children:T.map(e=>(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>A(e.id),className:`w-full flex items-center justify-between gap-2 px-2 py-1.5 text-left rounded hover:bg-accent transition-colors`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-mono`,children:e.id}),(0,Z.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded `+(e.kind===`custom`?`bg-purple-500/15 aurora-light:bg-accent-secondary/15 text-purple-400 aurora-light:text-accent-secondary`:`bg-muted text-muted-foreground`),children:p(`profileEditor.agentChain.kind.${e.kind}`)})]},e.id))})]}),(0,Z.jsx)(U,{sensors:N,collisionDetection:B,onDragEnd:P,children:(0,Z.jsx)(oe,{items:e.agents.map(e=>e.id),strategy:te,children:(0,Z.jsx)(`div`,{className:`space-y-1.5`,children:e.agents.map((e,t)=>(0,Z.jsx)(Oe,{agent:e,required:S.has(e.id),canRemove:!S.has(e.id),models:i,defaultModel:a,customModelAliases:c,onModel:e=>F(t,e),onRemove:()=>j(t)},e.id))})})})]}),(0,Z.jsxs)(`section`,{children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,Z.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:p(`profileEditor.routing.heading`,{n:e.routing.length})}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[!k&&(0,Z.jsxs)(L,{size:`sm`,variant:`ghost`,onClick:R,disabled:e.agents.length===0,title:e.agents.length===0?p(`profileEditor.routing.needAgentsTitle`):void 0,children:[(0,Z.jsx)(w,{className:`w-3.5 h-3.5 mr-1`}),` `,p(`profileEditor.routing.addDefault`)]}),(0,Z.jsxs)(L,{size:`sm`,variant:`ghost`,onClick:()=>y(!0),disabled:e.agents.length===0,title:e.agents.length===0?p(`profileEditor.routing.needAgentsTitle`):void 0,children:[(0,Z.jsx)(w,{className:`w-3.5 h-3.5 mr-1`}),` `,p(`profileEditor.routing.addRule`)]})]})]}),(0,Z.jsx)(`p`,{className:`text-[11px] text-muted-foreground mb-2`,children:p(`profileEditor.routing.explainer`)}),D.length>0&&(0,Z.jsxs)(`div`,{className:`mb-2 px-3 py-2 text-xs rounded-md border border-yellow-500/30 aurora-light:border-accent-warning/30 bg-yellow-500/10 aurora-light:bg-accent-warning/10 text-yellow-500 aurora-light:text-accent-warning`,children:[(0,Z.jsx)(`div`,{className:`font-medium mb-1`,children:p(`profileEditor.routing.untargetedTitle`)}),(0,Z.jsx)(`div`,{children:(0,Z.jsx)(o,{t:p,i18nKey:`profileEditor.routing.untargetedDetail`,values:{agents:D.join(`, `)},components:{mono:(0,Z.jsx)(`span`,{className:`font-mono`})}})})]}),(0,Z.jsx)(`div`,{className:`space-y-1.5`,children:e.routing.map((t,n)=>{let r=`default`in t&&t.default===!0;return(0,Z.jsx)(ke,{rule:t,ordinal:n+1,isLast:n===e.routing.length-1,canMove:!r,canRemove:!r,canEdit:!r,chainAgents:e.agents.map(e=>e.id),onAgentChange:e=>H(n,e),onEdit:()=>x(n),onUp:()=>G(n,-1),onDown:()=>G(n,1),onRemove:()=>ie(n)},n)})})]}),n&&(0,Z.jsx)(`div`,{className:`pt-3 border-t border-border`,children:n})]})}function Oe({agent:e,required:t,canRemove:n,models:r,defaultModel:i,customModelAliases:a,onModel:o,onRemove:c}){let{t:l}=s(`agentstudio`),u=t,d=e.id===`sr-architect`,f=e.id===`sr-merge-resolver`,{attributes:p,listeners:m,setNodeRef:h,transform:g,transition:_,isDragging:v}=ce({id:e.id});return(0,Z.jsxs)(`div`,{ref:h,style:{transform:G.Transform.toString(g),transition:_,opacity:v?.5:void 0,zIndex:v?10:void 0},className:`flex items-center gap-2 px-2 py-1.5 rounded-md border border-border group hover:bg-accent/30 transition-colors bg-background`,children:[(0,Z.jsx)(`button`,{type:`button`,className:`flex-shrink-0 p-0.5 rounded text-muted-foreground cursor-grab active:cursor-grabbing hover:text-foreground`,title:l(`profileEditor.agentRow.dragTitle`),"aria-label":l(`profileEditor.agentRow.dragHandleAria`),...p,...m,children:(0,Z.jsx)(H,{className:`w-3.5 h-3.5`})}),(0,Z.jsx)(`span`,{className:`text-sm font-mono flex-1 truncate`,children:e.id}),d&&(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded bg-accent-primary/15 text-accent-primary`,title:l(`profileEditor.agentRow.pinnedFirstTitle`),children:[(0,Z.jsx)(me,{className:`w-2.5 h-2.5 rotate-[135deg]`}),` `,l(`profileEditor.agentRow.pinnedFirst`)]}),f&&(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded bg-accent-primary/15 text-accent-primary`,title:l(`profileEditor.agentRow.pinnedLastTitle`),children:[(0,Z.jsx)(me,{className:`w-2.5 h-2.5 rotate-45`}),` `,l(`profileEditor.agentRow.pinnedLast`)]}),u&&!d&&!f&&(0,Z.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:l(`profileEditor.agentRow.required`)}),(0,Z.jsx)(Q,{value:e.model??i,models:r,customModelAliases:a,testId:`profile-agent-model-${e.id}`,onChange:o}),(0,Z.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-red-500/20 aurora-light:hover:bg-destructive/15 text-red-400 aurora-light:text-destructive rounded disabled:opacity-30 disabled:cursor-not-allowed opacity-0 group-hover:opacity-100 transition-opacity`,onClick:c,disabled:!n,title:l(n?`common:actions.remove`:`profileEditor.agentRow.requiredRemoveTitle`),children:(0,Z.jsx)(O,{className:`w-3 h-3`})})]})}function ke({rule:e,ordinal:t,isLast:n,canMove:r,canRemove:i,canEdit:a,chainAgents:o,onAgentChange:c,onEdit:l,onUp:u,onDown:d,onRemove:f}){let{t:p}=s(`agentstudio`),m=`default`in e&&e.default===!0;return(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 rounded-md border border-border group hover:bg-accent/30 transition-colors`,children:[(0,Z.jsxs)(`span`,{className:`text-[10px] font-mono text-muted-foreground w-5 text-center flex-shrink-0`,children:[t,`.`]}),m?(0,Z.jsx)(`span`,{className:`text-xs text-muted-foreground flex-1`,children:p(`profileEditor.routingRow.everythingElse`)}):(0,Z.jsx)(`span`,{className:`text-xs flex-1 flex gap-1 flex-wrap items-center`,children:e.tags.map(e=>(0,Z.jsx)(`span`,{className:`px-1.5 py-0.5 rounded bg-muted font-mono text-[11px]`,children:e},e))}),(0,Z.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`→`}),m?(0,Z.jsx)(`span`,{className:`h-7 max-w-[15rem] px-2 text-xs font-mono rounded border border-border bg-muted/40 text-muted-foreground inline-flex items-center`,"aria-label":p(`profileEditor.routingRow.defaultTargetAria`),title:p(`profileEditor.routingRow.defaultTargetTitle`),children:e.agent}):(0,Z.jsx)(`select`,{value:e.agent,onChange:e=>c(e.target.value),"aria-label":p(`profileEditor.routingRow.targetAria`,{ordinal:t}),className:`h-7 max-w-[15rem] px-2 text-xs font-mono rounded border border-border bg-background`,children:o.map(e=>(0,Z.jsx)(`option`,{value:e,children:e},e))}),(0,Z.jsxs)(`div`,{className:`flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity`,children:[a&&(0,Z.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:l,title:p(`profileEditor.routingRow.editTitle`),"aria-label":p(`profileEditor.routingRow.editAria`,{ordinal:t}),children:(0,Z.jsx)(C,{className:`w-3 h-3`})}),r&&!n&&(0,Z.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:d,title:p(`profileEditor.routingRow.moveDown`),children:(0,Z.jsx)(K,{className:`w-3 h-3`})}),r&&t>1&&(0,Z.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:u,title:p(`profileEditor.routingRow.moveUp`),children:(0,Z.jsx)(g,{className:`w-3 h-3`})}),i&&(0,Z.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-red-500/20 aurora-light:hover:bg-destructive/15 text-red-400 aurora-light:text-destructive rounded`,onClick:f,title:p(`common:actions.remove`),children:(0,Z.jsx)(O,{className:`w-3 h-3`})})]}),m&&(0,Z.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,title:p(`profileEditor.routingRow.coreDefaultTitle`),children:p(`profileEditor.routingRow.coreDefaultBadge`)})]})}function Q({value:e,models:t,customModelAliases:n,testId:r,onChange:i}){return n?(0,Z.jsx)(W,{value:e,options:t,ariaLabel:`Model alias`,testId:r,className:`h-7 w-52 bg-background px-2 text-xs`,onCommit:i}):(0,Z.jsx)(`select`,{value:e,onChange:e=>i(e.target.value),className:`h-7 px-2 text-xs rounded border border-border bg-background`,children:(t.some(t=>t.value===e)?t:[...t,{value:e,label:e}]).map(e=>(0,Z.jsx)(`option`,{value:e.value,children:e.label},e.value))})}function Ae({open:e,title:t,description:n,placeholder:r,initialValue:i=``,confirmLabel:a,inputPattern:o,inputInvalidHint:c,onConfirm:l,onCancel:u}){let{t:d}=s(),[f,p]=(0,X.useState)(i);(0,X.useEffect)(()=>{e&&p(i)},[e,i]);let m=f.trim(),h=!o||o.test(m),g=m.length>0&&h;return(0,Z.jsx)(I,{open:e,onOpenChange:e=>{e||u()},children:(0,Z.jsxs)(F,{movableResizable:!0,className:`max-w-md`,children:[(0,Z.jsx)(P,{children:(0,Z.jsx)(N,{children:t})}),(0,Z.jsxs)(`div`,{className:`py-2 space-y-2`,children:[n&&(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n}),(0,Z.jsx)(ne,{autoFocus:!0,value:f,placeholder:r,onChange:e=>p(e.target.value),onKeyDown:e=>{e.key===`Enter`&&g&&l(m)},className:`text-sm font-mono`}),m.length>0&&!h&&c&&(0,Z.jsx)(`p`,{className:`text-[11px] text-yellow-500 aurora-light:text-accent-warning`,children:c})]}),(0,Z.jsxs)(A,{children:[(0,Z.jsx)(L,{variant:`ghost`,size:`sm`,onClick:u,children:d(`actions.cancel`)}),(0,Z.jsx)(L,{size:`sm`,onClick:()=>l(m),disabled:!g,children:a??d(`actions.confirm`)})]})]})})}function je({open:e,title:t,description:n,confirmLabel:r,destructive:i=!1,onConfirm:a,onCancel:o}){let{t:c}=s();return(0,Z.jsx)(I,{open:e,onOpenChange:e=>{e||o()},children:(0,Z.jsxs)(F,{movableResizable:!0,className:`max-w-md`,children:[(0,Z.jsx)(P,{children:(0,Z.jsx)(N,{children:t})}),n&&(0,Z.jsx)(`div`,{className:`py-2`,children:(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n})}),(0,Z.jsxs)(A,{children:[(0,Z.jsx)(L,{variant:`ghost`,size:`sm`,onClick:o,children:c(`actions.cancel`)}),(0,Z.jsx)(L,{size:`sm`,onClick:a,className:i?`bg-red-500 hover:bg-red-600 text-white`:void 0,children:r??c(`actions.confirm`)})]})]})})}var Me={models:Ce.map(e=>({value:e,label:e})),defaultModel:`sonnet`,baselineAgents:[...Se],customModelAliases:!1},Ne={primaryProvider:`claude`,providers:[`claude`],catalogs:{claude:Me}};function Pe(e,t,n){return{schemaVersion:1,name:e,description:``,provider:t,orchestrator:{model:n.defaultModel},agents:n.baselineAgents.map(e=>({id:e,model:n.defaultModel,required:!0})),routing:[{default:!0,agent:`sr-developer`}]}}function Fe(){let{t:e}=s(`agents`),[t,n]=(0,X.useState)([]),[r,i]=(0,X.useState)(Ne),[a,c]=(0,X.useState)(``),[u,f]=(0,X.useState)(null),[m,h]=(0,X.useState)(null),[g,_]=(0,X.useState)(!0),[v,y]=(0,X.useState)(null),[b,x]=(0,X.useState)(!1),[S,C]=(0,X.useState)([]),[ee,T]=(0,X.useState)([]),[D,O]=(0,X.useState)(!1),[k,A]=(0,X.useState)(null),[j,M]=(0,X.useState)(null),N=a,P=r.catalogs[N]??Me;(0,X.useEffect)(()=>{let e=!1;return fetch(`${l()}/profiles/context`).then(e=>{if(!e.ok)throw Error(`profile context unavailable`);return e.json()}).then(t=>{if(e)return;let n=Array.isArray(t.providers)&&t.providers.length>0?t.providers:[t.primaryProvider||`claude`],r=n.includes(t.primaryProvider)?t.primaryProvider:n[0];i({...t,providers:n,primaryProvider:r}),c(r)}).catch(()=>{e||(i(Ne),c(Ne.primaryProvider))}),()=>{e=!0}},[]);let F=(0,X.useCallback)(async()=>{if(N){_(!0),y(null);try{let t=await fetch(`${l()}/profiles?provider=${encodeURIComponent(N)}`);if(!t.ok)throw Error(e(`profiles.errors.listFailed`,{status:t.status}));let r=await t.json();n(r.profiles),f(e=>e&&r.profiles.some(t=>t.name===e)?e:r.profiles[0]?.name??null)}catch(e){y(e.message)}finally{_(!1)}}},[N,e]);(0,X.useEffect)(()=>{N&&F()},[N,F]),(0,X.useEffect)(()=>{if(!u){h(null);return}let t=!1;return fetch(`${l()}/profiles/${encodeURIComponent(u)}?provider=${encodeURIComponent(N)}`).then(t=>{if(!t.ok)throw Error(e(`profiles.errors.loadFailed`,{status:t.status}));return t.json()}).then(e=>{t||h(e.profile)}).catch(e=>{t||y(e.message)}),()=>{t=!0}},[N,u,e]);let I=(0,X.useCallback)(async()=>{x(!0),y(null);try{let t=await fetch(`${l()}/profiles/migrate-from-settings?provider=${encodeURIComponent(N)}`,{method:`POST`});if(!t.ok){let n=await t.json().catch(()=>({}));throw Error(n.error??e(`profiles.errors.migrationFailed`,{status:t.status}))}await F(),f(`default`),d.success(e(`profiles.toasts.migrated`),{description:e(`profiles.toasts.migratedDescription`)})}catch(t){let n=t.message;y(n),d.error(e(`profiles.toasts.migrationFailed`),{description:n})}finally{x(!1)}},[N,F,e]),R=(0,X.useCallback)(async t=>{O(!1),x(!0),y(null);try{let n=Pe(t,N,P),r=await fetch(`${l()}/profiles?provider=${encodeURIComponent(N)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(n)});if(!r.ok){let t=await r.json().catch(()=>({}));throw Error(t.error??e(`profiles.errors.createFailed`,{status:r.status}))}await F(),f(t),d.success(e(`profiles.toasts.created`),{description:t})}catch(t){let n=t.message;y(n),d.error(e(`profiles.toasts.createFailed`),{description:n})}finally{x(!1)}},[P,N,F,e]),B=(0,X.useCallback)(async(t,n)=>{A(null),x(!0),y(null);try{let r=await fetch(`${l()}/profiles/${encodeURIComponent(t)}/duplicate?provider=${encodeURIComponent(N)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:n,provider:N})});if(!r.ok){let t=await r.json().catch(()=>({}));throw Error(t.error??e(`profiles.errors.duplicateFailed`,{status:r.status}))}await F(),f(n),d.success(e(`profiles.toasts.duplicated`),{description:e(`profiles.toasts.duplicatedDescription`,{from:t,to:n})})}catch(t){let n=t.message;y(n),d.error(e(`profiles.toasts.duplicateFailed`),{description:n})}finally{x(!1)}},[N,F,e]),V=(0,X.useCallback)(async t=>{M(null),x(!0),y(null);try{let n=await fetch(`${l()}/profiles/${encodeURIComponent(t)}?provider=${encodeURIComponent(N)}`,{method:`DELETE`});if(!n.ok){let t=await n.json().catch(()=>({}));throw Error(t.error??e(`profiles.errors.deleteFailed`,{status:n.status}))}f(e=>e===t?null:e),await F(),d.success(e(`profiles.toasts.deleted`),{description:t})}catch(t){let n=t.message;y(n),d.error(e(`profiles.toasts.deleteFailed`),{description:n})}finally{x(!1)}},[N,F,e]),H=(0,X.useCallback)(()=>O(!0),[]),U=(0,X.useCallback)(e=>A({from:e}),[]),te=(0,X.useCallback)(e=>M({name:e}),[]),ne=(0,X.useCallback)(async(t,n)=>{x(!0),y(null);try{let r=await fetch(`${l()}/profiles/${encodeURIComponent(t.name)}?provider=${encodeURIComponent(N)}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({...t,provider:N})});if(!r.ok){let t=await r.json().catch(()=>({}));throw Error(t.error??e(`profiles.errors.saveFailed`,{status:r.status}))}h(t),n.length>0?d.warning(e(`profiles.toasts.savedWithUntargeted`),{description:e(`profiles.toasts.savedWithUntargetedDescription`,{agents:n.join(`, `)}),duration:6e3}):d.success(e(`profiles.toasts.saved`),{description:t.name})}catch(t){let n=t.message;y(n),d.error(e(`profiles.toasts.saveFailed`),{description:n})}finally{x(!1)}},[N,e]),W=(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Ae,{open:D,title:e(`profiles.createDialog.title`),description:e(`profiles.createDialog.description`),placeholder:`my-profile`,confirmLabel:e(`profiles.createDialog.confirmLabel`),inputPattern:/^[a-z0-9][a-z0-9-]*$/,inputInvalidHint:e(`profiles.createDialog.invalidHint`),onConfirm:e=>void R(e),onCancel:()=>O(!1)}),k&&(0,Z.jsx)(Ae,{open:!0,title:e(`profiles.duplicateDialog.title`,{name:k.from}),description:e(`profiles.duplicateDialog.description`),placeholder:`${k.from}-copy`,initialValue:`${k.from}-copy`,confirmLabel:e(`common:actions.duplicate`),inputPattern:/^[a-z0-9][a-z0-9-]*$/,inputInvalidHint:e(`profiles.duplicateDialog.invalidHint`),onConfirm:e=>void B(k.from,e),onCancel:()=>A(null)}),j&&(0,Z.jsx)(je,{open:!0,title:e(`profiles.deleteDialog.title`,{name:j.name}),description:e(`profiles.deleteDialog.description`),confirmLabel:e(`common:actions.delete`),destructive:!0,onConfirm:()=>void V(j.name),onCancel:()=>M(null)})]});return g?(0,Z.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`profiles.loading`)})}):t.length===0?(0,Z.jsxs)(Z.Fragment,{children:[W,(0,Z.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,Z.jsxs)(`div`,{className:`text-center max-w-md`,children:[(0,Z.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:e(`profiles.empty.title`)}),(0,Z.jsx)(`div`,{className:`text-xs text-muted-foreground mt-1 mb-4`,children:e(`profiles.empty.body`)}),r.providers.length>1&&(0,Z.jsx)(`select`,{value:N,"aria-label":e(`profiles.providerLabel`),onChange:e=>{f(null),h(null),c(e.target.value)},className:`mb-4 h-8 w-full rounded border border-border bg-background px-2 text-xs`,children:r.providers.map(e=>(0,Z.jsx)(`option`,{value:e,children:z(e)},e))}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 justify-center`,children:[(0,Z.jsxs)(L,{size:`sm`,onClick:I,disabled:b,children:[(0,Z.jsx)(he,{className:`w-3.5 h-3.5 mr-1.5`}),` `,e(`profiles.empty.migrateButton`)]}),(0,Z.jsxs)(L,{size:`sm`,variant:`ghost`,onClick:H,disabled:b,children:[(0,Z.jsx)(w,{className:`w-3.5 h-3.5 mr-1.5`}),` `,e(`profiles.empty.blankButton`)]})]}),(0,Z.jsx)(`div`,{className:`text-[11px] text-muted-foreground/70 mt-3`,children:(0,Z.jsx)(o,{t:e,i18nKey:`profiles.empty.migrateExplainer`,components:{code:(0,Z.jsx)(`code`,{className:`text-foreground`})}})}),v&&(0,Z.jsx)(`div`,{className:`mt-3 text-xs text-red-400 aurora-light:text-destructive`,children:v})]})})]}):(0,Z.jsxs)(`div`,{className:`flex flex-col h-full`,children:[W,(0,Z.jsxs)(`div`,{className:`flex flex-1 min-h-0`,children:[(0,Z.jsxs)(`aside`,{className:`w-64 flex-shrink-0 border-r border-border flex flex-col`,children:[(0,Z.jsxs)(`div`,{className:`p-3 space-y-2`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsx)(`div`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:e(`profiles.sidebar.title`)}),(0,Z.jsx)(L,{size:`sm`,variant:`ghost`,onClick:H,disabled:b,children:(0,Z.jsx)(w,{className:`w-3.5 h-3.5`})})]}),r.providers.length>1&&(0,Z.jsx)(`select`,{value:N,"aria-label":e(`profiles.providerLabel`),onChange:e=>{f(null),h(null),c(e.target.value)},className:`h-7 w-full rounded border border-border bg-background px-2 text-xs`,children:r.providers.map(e=>(0,Z.jsx)(`option`,{value:e,children:z(e)},e))})]}),(0,Z.jsx)(`div`,{className:`flex-1 overflow-auto px-2 pb-3`,children:t.map(t=>(0,Z.jsxs)(`div`,{className:`group mb-1 rounded-md px-2 py-1.5 text-xs cursor-pointer transition-colors flex items-center justify-between `+(t.name===u?`bg-accent text-foreground`:`text-muted-foreground hover:bg-accent/50 hover:text-foreground`),onClick:()=>f(t.name),role:`button`,tabIndex:0,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&f(t.name)},children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,Z.jsx)(`span`,{className:`truncate font-medium`,children:t.name}),t.isDefault&&(0,Z.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:e(`profiles.sidebar.teamDefault`)})]}),(0,Z.jsxs)(`div`,{className:`flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity`,children:[(0,Z.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,title:e(`common:actions.duplicate`),onClick:e=>{e.stopPropagation(),U(t.name)},children:(0,Z.jsx)(fe,{className:`w-3 h-3`})}),!t.isDefault&&(0,Z.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-red-500/20 text-red-400 aurora-light:text-destructive rounded`,title:e(`common:actions.delete`),onClick:e=>{e.stopPropagation(),te(t.name)},children:(0,Z.jsx)(E,{className:`w-3 h-3`})})]})]},t.name))})]}),(0,Z.jsxs)(`main`,{className:`flex-1 overflow-auto`,children:[v&&(0,Z.jsx)(`div`,{className:`mx-4 mt-4 px-3 py-2 text-xs rounded border border-red-500/30 aurora-light:border-destructive/30 bg-red-500/10 aurora-light:bg-destructive/10 text-red-400 aurora-light:text-destructive`,children:v}),m?(0,Z.jsx)(De,{profile:m,provider:N,modelCatalog:P.models,defaultModel:P.defaultModel,customModelAliases:P.customModelAliases===!0,baselineAgents:P.baselineAgents,onChange:h,onValidityChange:C,onSoftWarningsChange:e=>T(e.agentsMissingRouting),footer:(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsxs)(L,{size:`sm`,onClick:()=>void ne(m,ee),disabled:b||S.length>0,title:S.length>0?e(`profiles.editorFooter.fixValidationIssues`):void 0,children:[(0,Z.jsx)(p,{className:`w-3.5 h-3.5 mr-1.5`}),e(`common:actions.save`)]}),b&&(0,Z.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e(`common:states.saving`)}),S.length>0&&(0,Z.jsx)(`span`,{className:`text-xs text-yellow-500 aurora-light:text-accent-warning`,children:e(`profiles.editorFooter.issuesToResolve`,{count:S.length})})]})},`${N}:${m.name}`):(0,Z.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`profiles.selectPrompt`)})})]})]})]})}function $(e){let t=e.workflow.map((e,t)=>`${t+1}. ${e}`).join(`
1
+ 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{h as i,r as a}from"./useSharedWebSocket-BOdS5_Iz.js";import{t as o}from"./Trans-SnMX4MhW.js";import{n as s,t as c}from"./createLucideIcon-Bjbbp_KS.js";import{a as l,r as u,s as d}from"./useDesktop-RSMTyy7V.js";import{n as f,t as p}from"./save-B6wGWwBR.js";import{c as m,d as h,f as g,n as _,r as v,u as y}from"./MinimizedChatsContext-Deg39peL.js";import{n as b,t as x}from"./file-text-BcLCfcWZ.js";import{t as S}from"./loader-circle-DcygOQpC.js";import{t as C}from"./pencil-C9RkrIPZ.js";import{t as w}from"./plus-CsnjfkmX.js";import{t as ee}from"./search-Cq_gE3Ik.js";import{t as T}from"./sparkles-DrY8hb0X.js";import{t as E}from"./trash-2-BOU3WdZZ.js";import{t as D}from"./triangle-alert-H9T4jAmh.js";import{t as O}from"./x-CBMI9ejn.js";import{M as k,a as A,i as j,j as M,l as N,o as P,r as F,t as I}from"./dialog-xXB2q5HJ.js";import{t as L}from"./button-Ccc9Dc-D.js";import{i as R,r as z}from"./provider-capabilities-B-wOHfLP.js";import{A as B,C as V,Ct as H,D as U,E as te,F as ne,H as W,M as re,Mt as ie,N as G,O as ae,Rt as K,S as oe,St as se,T as ce,_ as le,ft as q,ht as ue,it as de,j as J,k as Y,kt as fe,l as pe,mt as me,tt as he,w as ge,y as _e}from"./index-m5pKr1T6.js";import{t as ve}from"./format-command-C0D9IPmV.js";var ye=c(`flask-conical`,[[`path`,{d:`M14 2v6a2 2 0 0 0 .245.96l5.51 10.08A2 2 0 0 1 18 22H6a2 2 0 0 1-1.755-2.96l5.51-10.08A2 2 0 0 0 10 8V2`,key:`18mbvz`}],[`path`,{d:`M6.453 15h11.094`,key:`3shlmq`}],[`path`,{d:`M8.5 2h7`,key:`csnxdl`}]]),X=e(t(),1),Z=n(),be=/^[a-z0-9][a-z0-9-]*$/;function xe({open:e,mode:t=`add`,initial:n,chainAgents:r,onConfirm:i,onCancel:a}){let{t:c}=s(`agents`),[l,u]=(0,X.useState)(``),[d,f]=(0,X.useState)(r[0]??``);(0,X.useEffect)(()=>{e&&(t===`edit`&&n?(u(n.tags.join(`, `)),f(r.includes(n.agent)?n.agent:r[0]??``)):(u(``),f(r[0]??``)))},[e,t,n,r]);let p=l.split(`,`).map(e=>e.trim()).filter(Boolean),m=p.filter(e=>!be.test(e)),h=p.length>0&&m.length===0&&r.includes(d);return(0,Z.jsx)(I,{open:e,onOpenChange:e=>{e||a()},children:(0,Z.jsxs)(F,{movableResizable:!0,className:`max-w-md`,children:[(0,Z.jsxs)(P,{children:[(0,Z.jsx)(N,{children:c(t===`edit`?`routingRule.editTitle`:`routingRule.addTitle`)}),(0,Z.jsx)(j,{children:c(t===`edit`?`routingRule.editDescription`:`routingRule.addDescription`)})]}),(0,Z.jsxs)(`div`,{className:`py-2 space-y-3`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:c(`routingRule.tagsLabel`)}),(0,Z.jsx)(ne,{autoFocus:!0,value:l,onChange:e=>u(e.target.value),placeholder:`frontend, ui`,"aria-label":c(`routingRule.tagsLabel`),className:`text-sm font-mono`}),(0,Z.jsx)(`p`,{className:`text-[11px] text-muted-foreground mt-1`,children:(0,Z.jsx)(o,{t:c,i18nKey:`routingRule.tagsHint`,components:{code:(0,Z.jsx)(`code`,{})}})}),m.length>0&&(0,Z.jsx)(`p`,{className:`text-[11px] text-red-400 aurora-light:text-destructive mt-1`,children:c(`routingRule.invalidTags`,{count:m.length,tags:m.join(`, `)})})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:c(`routingRule.routeToLabel`)}),(0,Z.jsx)(`select`,{value:d,onChange:e=>f(e.target.value),"aria-label":c(`routingRule.routeToLabel`),className:`w-full h-9 px-2 text-sm rounded-md border border-border bg-background`,children:r.map(e=>(0,Z.jsx)(`option`,{value:e,children:e},e))}),(0,Z.jsx)(`p`,{className:`text-[11px] text-muted-foreground mt-1`,children:c(`routingRule.routeToHint`)})]})]}),(0,Z.jsxs)(A,{children:[(0,Z.jsx)(L,{variant:`ghost`,size:`sm`,onClick:a,children:c(`common:actions.cancel`)}),(0,Z.jsx)(L,{size:`sm`,onClick:()=>i(p,d),disabled:!h,children:c(t===`edit`?`routingRule.saveChanges`:`routingRule.addRule`)})]})]})})}var Se=new Set([`sr-architect`,`sr-developer`,`sr-reviewer`,`sr-merge-resolver`]),Ce=[`sonnet`,`fable`,`opus`,`haiku`],we=/^[a-z0-9][a-z0-9-]*$/,Te=Ce.map(e=>({value:e,label:e})),Ee=[...Se];function De({profile:e,onChange:t,footer:n,provider:r=e.provider??`claude`,modelCatalog:i=Te,defaultModel:a=i[0]?.value??``,customModelAliases:c=!1,baselineAgents:u=Ee,onValidityChange:d,onSoftWarningsChange:f}){let{t:p}=s(`agentstudio`),[m,h]=(0,X.useState)([]),[g,_]=(0,X.useState)(!1),[v,y]=(0,X.useState)(!1),[b,x]=(0,X.useState)(null),S=(0,X.useMemo)(()=>new Set(u),[u]);(0,X.useEffect)(()=>{let e=!1;return fetch(`${l()}/profiles/catalog?provider=${encodeURIComponent(r)}`).then(e=>e.ok?e.json():{agents:[]}).then(t=>{e||h(t.agents)}).catch(()=>{e||h([])}),()=>{e=!0}},[r]);let C=n=>{let r=JSON.parse(JSON.stringify(e));n(r),t(r)},ee=new Set(e.agents.map(e=>e.id)),T=m.filter(e=>!ee.has(e.id)),E=(0,X.useMemo)(()=>{let t=[];for(let n of S)e.agents.some(e=>e.id===n)||t.push(p(`profileEditor.validation.missingBaseline`,{agent:n}));let n=e.routing.filter(e=>`default`in e&&e.default===!0);if(n.length>1&&t.push(p(`profileEditor.validation.multipleDefaultRules`,{found:n.length})),n.length===1){let n=e.routing[e.routing.length-1];`default`in n&&n.default===!0||t.push(p(`profileEditor.validation.defaultRuleNotLast`))}for(let n of e.routing)if(e.agents.some(e=>e.id===n.agent)||t.push(p(`profileEditor.validation.unknownRoutingAgent`,{agent:n.agent})),`tags`in n){let e=n.tags.filter(e=>!we.test(e));e.length>0&&t.push(p(`profileEditor.validation.invalidTags`,{agent:n.agent,tags:e.join(`, `)}))}return t},[e,S,p]),D=(0,X.useMemo)(()=>{if(e.routing.length===0)return[];let t=new Set(e.routing.map(e=>e.agent));return e.agents.filter(e=>!S.has(e.id)&&!t.has(e.id)).map(e=>e.id)},[e,S]),k=(0,X.useMemo)(()=>e.routing.some(e=>`default`in e&&e.default===!0),[e.routing]);(0,X.useEffect)(()=>{d&&d(E)},[E,d]),(0,X.useEffect)(()=>{f&&f({agentsMissingRouting:D})},[D,f]);let A=e=>{C(t=>{let n={id:e,model:a},r=t.agents.findIndex(e=>e.id===`sr-merge-resolver`);r>=0?t.agents.splice(r,0,n):t.agents.push(n)}),_(!1)},j=t=>{let n=e.agents[t];S.has(n.id)||C(e=>{e.agents.splice(t,1),e.routing=e.routing.filter(e=>e.agent!==n.id)})},M=(t,n)=>{if(t===n)return;let r=e.agents.findIndex(e=>e.id===t),i=e.agents.findIndex(e=>e.id===n);if(r<0||i<0)return;let a=V(e.agents,r,i),o=a.findIndex(e=>e.id===`sr-architect`);if(o>0){let[e]=a.splice(o,1);a.unshift(e)}let s=a.findIndex(e=>e.id===`sr-merge-resolver`);if(s>=0&&s!==a.length-1){let[e]=a.splice(s,1);a.push(e)}C(e=>{e.agents=a})},N=re(J(Y,{activationConstraint:{distance:4}}),J(ae,{coordinateGetter:ge})),P=e=>{let{active:t,over:n}=e;n&&M(String(t.id),String(n.id))},F=(e,t)=>{C(n=>{n.agents[e].model=t})},I=(e,t)=>{C(n=>{let r={tags:e,agent:t},i=n.routing.findIndex(e=>`default`in e&&e.default===!0);i>=0?n.routing.splice(i,0,r):n.routing.push(r)}),y(!1)},R=()=>{C(e=>{e.routing.some(e=>`default`in e&&e.default===!0)||e.agents.some(e=>e.id===`sr-developer`)&&e.routing.push({default:!0,agent:`sr-developer`})})},z=e=>`default`in e&&e.default===!0,H=(e,t)=>{C(n=>{let r=n.routing[e];r&&(z(r)||(r.agent=t))})},W=(e,t,n)=>{C(r=>{let i=r.routing[e];i&&(z(i)||(i.tags=t,i.agent=n))})},ie=e=>{C(t=>{let n=t.routing[e];n&&(z(n)||t.routing.splice(e,1))})},G=(t,n)=>{let r=t+n;if(r<0||r>=e.routing.length)return;let i=e.routing[t],a=e.routing[r];z(i)||z(a)||C(e=>{let[n]=e.routing.splice(t,1);e.routing.splice(r,0,n)})};return(0,Z.jsxs)(`div`,{className:`p-6 space-y-6 max-w-3xl`,children:[(0,Z.jsx)(xe,{open:v,mode:`add`,chainAgents:e.agents.map(e=>e.id),onConfirm:I,onCancel:()=>y(!1)}),(0,Z.jsx)(xe,{open:b!==null,mode:`edit`,initial:b!==null&&e.routing[b]&&!(`default`in e.routing[b])?{tags:e.routing[b].tags,agent:e.routing[b].agent}:void 0,chainAgents:e.agents.map(e=>e.id),onConfirm:(e,t)=>{b!==null&&(W(b,e,t),x(null))},onCancel:()=>x(null)}),E.length>0&&(0,Z.jsxs)(`div`,{className:`px-3 py-2 text-xs rounded-md border border-yellow-500/30 aurora-light:border-accent-warning/30 bg-yellow-500/10 aurora-light:bg-accent-warning/10 text-yellow-500 aurora-light:text-accent-warning`,children:[(0,Z.jsx)(`div`,{className:`font-medium mb-1`,children:p(`profileEditor.validationSummary`,{count:E.length})}),(0,Z.jsx)(`ul`,{className:`list-disc list-inside space-y-0.5`,children:E.map((e,t)=>(0,Z.jsx)(`li`,{children:e},t))})]}),(0,Z.jsxs)(`section`,{className:`space-y-3`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:p(`profileEditor.nameLabel`)}),(0,Z.jsx)(ne,{value:e.name,disabled:!0,className:`text-sm`})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:p(`profileEditor.descriptionLabel`)}),(0,Z.jsx)(ne,{value:e.description??``,onChange:e=>C(t=>{t.description=e.target.value}),className:`text-sm`,placeholder:p(`profileEditor.descriptionPlaceholder`)})]})]}),(0,Z.jsxs)(`section`,{children:[(0,Z.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide mb-2`,children:p(`profileEditor.orchestrator.heading`)}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 p-3 rounded-md border border-border`,children:[(0,Z.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`text-sm font-mono text-foreground truncate`,children:[ve(`/specrails:implement`,r),` ·`,` `,ve(`/specrails:batch-implement`,r)]}),(0,Z.jsx)(`div`,{className:`text-[11px] text-muted-foreground mt-0.5`,children:p(`profileEditor.orchestrator.description`)})]}),(0,Z.jsx)(Q,{value:e.orchestrator.model,models:i,customModelAliases:c,testId:`profile-orchestrator-model`,onChange:e=>C(t=>{t.orchestrator.model=e})})]})]}),(0,Z.jsxs)(`section`,{children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,Z.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:p(`profileEditor.agentChain.heading`,{n:e.agents.length})}),(0,Z.jsxs)(L,{size:`sm`,variant:`ghost`,onClick:()=>_(e=>!e),disabled:T.length===0,title:T.length===0?p(`profileEditor.agentChain.addDisabledTitle`):p(`profileEditor.agentChain.addTitle`),children:[(0,Z.jsx)(w,{className:`w-3.5 h-3.5 mr-1`}),` `,p(`common:actions.add`)]})]}),g&&(0,Z.jsxs)(`div`,{className:`mb-2 p-2 rounded-md border border-border bg-muted/30`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between mb-1.5 px-1`,children:[(0,Z.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:p(`profileEditor.agentChain.pickFromCatalog`,{n:T.length})}),(0,Z.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:()=>_(!1),title:p(`common:actions.close`),children:(0,Z.jsx)(O,{className:`w-3 h-3`})})]}),T.length===0?(0,Z.jsx)(`div`,{className:`px-2 py-3 text-xs text-muted-foreground text-center`,children:p(`profileEditor.agentChain.emptyCatalog`)}):(0,Z.jsx)(`div`,{className:`space-y-0.5 max-h-64 overflow-auto`,children:T.map(e=>(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>A(e.id),className:`w-full flex items-center justify-between gap-2 px-2 py-1.5 text-left rounded hover:bg-accent transition-colors`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-mono`,children:e.id}),(0,Z.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded `+(e.kind===`custom`?`bg-purple-500/15 aurora-light:bg-accent-secondary/15 text-purple-400 aurora-light:text-accent-secondary`:`bg-muted text-muted-foreground`),children:p(`profileEditor.agentChain.kind.${e.kind}`)})]},e.id))})]}),(0,Z.jsx)(U,{sensors:N,collisionDetection:B,onDragEnd:P,children:(0,Z.jsx)(oe,{items:e.agents.map(e=>e.id),strategy:te,children:(0,Z.jsx)(`div`,{className:`space-y-1.5`,children:e.agents.map((e,t)=>(0,Z.jsx)(Oe,{agent:e,required:S.has(e.id),canRemove:!S.has(e.id),models:i,defaultModel:a,customModelAliases:c,onModel:e=>F(t,e),onRemove:()=>j(t)},e.id))})})})]}),(0,Z.jsxs)(`section`,{children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,Z.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:p(`profileEditor.routing.heading`,{n:e.routing.length})}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[!k&&(0,Z.jsxs)(L,{size:`sm`,variant:`ghost`,onClick:R,disabled:e.agents.length===0,title:e.agents.length===0?p(`profileEditor.routing.needAgentsTitle`):void 0,children:[(0,Z.jsx)(w,{className:`w-3.5 h-3.5 mr-1`}),` `,p(`profileEditor.routing.addDefault`)]}),(0,Z.jsxs)(L,{size:`sm`,variant:`ghost`,onClick:()=>y(!0),disabled:e.agents.length===0,title:e.agents.length===0?p(`profileEditor.routing.needAgentsTitle`):void 0,children:[(0,Z.jsx)(w,{className:`w-3.5 h-3.5 mr-1`}),` `,p(`profileEditor.routing.addRule`)]})]})]}),(0,Z.jsx)(`p`,{className:`text-[11px] text-muted-foreground mb-2`,children:p(`profileEditor.routing.explainer`)}),D.length>0&&(0,Z.jsxs)(`div`,{className:`mb-2 px-3 py-2 text-xs rounded-md border border-yellow-500/30 aurora-light:border-accent-warning/30 bg-yellow-500/10 aurora-light:bg-accent-warning/10 text-yellow-500 aurora-light:text-accent-warning`,children:[(0,Z.jsx)(`div`,{className:`font-medium mb-1`,children:p(`profileEditor.routing.untargetedTitle`)}),(0,Z.jsx)(`div`,{children:(0,Z.jsx)(o,{t:p,i18nKey:`profileEditor.routing.untargetedDetail`,values:{agents:D.join(`, `)},components:{mono:(0,Z.jsx)(`span`,{className:`font-mono`})}})})]}),(0,Z.jsx)(`div`,{className:`space-y-1.5`,children:e.routing.map((t,n)=>{let r=`default`in t&&t.default===!0;return(0,Z.jsx)(ke,{rule:t,ordinal:n+1,isLast:n===e.routing.length-1,canMove:!r,canRemove:!r,canEdit:!r,chainAgents:e.agents.map(e=>e.id),onAgentChange:e=>H(n,e),onEdit:()=>x(n),onUp:()=>G(n,-1),onDown:()=>G(n,1),onRemove:()=>ie(n)},n)})})]}),n&&(0,Z.jsx)(`div`,{className:`pt-3 border-t border-border`,children:n})]})}function Oe({agent:e,required:t,canRemove:n,models:r,defaultModel:i,customModelAliases:a,onModel:o,onRemove:c}){let{t:l}=s(`agentstudio`),u=t,d=e.id===`sr-architect`,f=e.id===`sr-merge-resolver`,{attributes:p,listeners:m,setNodeRef:h,transform:g,transition:_,isDragging:v}=ce({id:e.id});return(0,Z.jsxs)(`div`,{ref:h,style:{transform:G.Transform.toString(g),transition:_,opacity:v?.5:void 0,zIndex:v?10:void 0},className:`flex items-center gap-2 px-2 py-1.5 rounded-md border border-border group hover:bg-accent/30 transition-colors bg-background`,children:[(0,Z.jsx)(`button`,{type:`button`,className:`flex-shrink-0 p-0.5 rounded text-muted-foreground cursor-grab active:cursor-grabbing hover:text-foreground`,title:l(`profileEditor.agentRow.dragTitle`),"aria-label":l(`profileEditor.agentRow.dragHandleAria`),...p,...m,children:(0,Z.jsx)(H,{className:`w-3.5 h-3.5`})}),(0,Z.jsx)(`span`,{className:`text-sm font-mono flex-1 truncate`,children:e.id}),d&&(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded bg-accent-primary/15 text-accent-primary`,title:l(`profileEditor.agentRow.pinnedFirstTitle`),children:[(0,Z.jsx)(me,{className:`w-2.5 h-2.5 rotate-[135deg]`}),` `,l(`profileEditor.agentRow.pinnedFirst`)]}),f&&(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded bg-accent-primary/15 text-accent-primary`,title:l(`profileEditor.agentRow.pinnedLastTitle`),children:[(0,Z.jsx)(me,{className:`w-2.5 h-2.5 rotate-45`}),` `,l(`profileEditor.agentRow.pinnedLast`)]}),u&&!d&&!f&&(0,Z.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:l(`profileEditor.agentRow.required`)}),(0,Z.jsx)(Q,{value:e.model??i,models:r,customModelAliases:a,testId:`profile-agent-model-${e.id}`,onChange:o}),(0,Z.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-red-500/20 aurora-light:hover:bg-destructive/15 text-red-400 aurora-light:text-destructive rounded disabled:opacity-30 disabled:cursor-not-allowed opacity-0 group-hover:opacity-100 transition-opacity`,onClick:c,disabled:!n,title:l(n?`common:actions.remove`:`profileEditor.agentRow.requiredRemoveTitle`),children:(0,Z.jsx)(O,{className:`w-3 h-3`})})]})}function ke({rule:e,ordinal:t,isLast:n,canMove:r,canRemove:i,canEdit:a,chainAgents:o,onAgentChange:c,onEdit:l,onUp:u,onDown:d,onRemove:f}){let{t:p}=s(`agentstudio`),m=`default`in e&&e.default===!0;return(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 rounded-md border border-border group hover:bg-accent/30 transition-colors`,children:[(0,Z.jsxs)(`span`,{className:`text-[10px] font-mono text-muted-foreground w-5 text-center flex-shrink-0`,children:[t,`.`]}),m?(0,Z.jsx)(`span`,{className:`text-xs text-muted-foreground flex-1`,children:p(`profileEditor.routingRow.everythingElse`)}):(0,Z.jsx)(`span`,{className:`text-xs flex-1 flex gap-1 flex-wrap items-center`,children:e.tags.map(e=>(0,Z.jsx)(`span`,{className:`px-1.5 py-0.5 rounded bg-muted font-mono text-[11px]`,children:e},e))}),(0,Z.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`→`}),m?(0,Z.jsx)(`span`,{className:`h-7 max-w-[15rem] px-2 text-xs font-mono rounded border border-border bg-muted/40 text-muted-foreground inline-flex items-center`,"aria-label":p(`profileEditor.routingRow.defaultTargetAria`),title:p(`profileEditor.routingRow.defaultTargetTitle`),children:e.agent}):(0,Z.jsx)(`select`,{value:e.agent,onChange:e=>c(e.target.value),"aria-label":p(`profileEditor.routingRow.targetAria`,{ordinal:t}),className:`h-7 max-w-[15rem] px-2 text-xs font-mono rounded border border-border bg-background`,children:o.map(e=>(0,Z.jsx)(`option`,{value:e,children:e},e))}),(0,Z.jsxs)(`div`,{className:`flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity`,children:[a&&(0,Z.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:l,title:p(`profileEditor.routingRow.editTitle`),"aria-label":p(`profileEditor.routingRow.editAria`,{ordinal:t}),children:(0,Z.jsx)(C,{className:`w-3 h-3`})}),r&&!n&&(0,Z.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:d,title:p(`profileEditor.routingRow.moveDown`),children:(0,Z.jsx)(K,{className:`w-3 h-3`})}),r&&t>1&&(0,Z.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:u,title:p(`profileEditor.routingRow.moveUp`),children:(0,Z.jsx)(g,{className:`w-3 h-3`})}),i&&(0,Z.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-red-500/20 aurora-light:hover:bg-destructive/15 text-red-400 aurora-light:text-destructive rounded`,onClick:f,title:p(`common:actions.remove`),children:(0,Z.jsx)(O,{className:`w-3 h-3`})})]}),m&&(0,Z.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,title:p(`profileEditor.routingRow.coreDefaultTitle`),children:p(`profileEditor.routingRow.coreDefaultBadge`)})]})}function Q({value:e,models:t,customModelAliases:n,testId:r,onChange:i}){return n?(0,Z.jsx)(W,{value:e,options:t,ariaLabel:`Model alias`,testId:r,className:`h-7 w-52 bg-background px-2 text-xs`,onCommit:i}):(0,Z.jsx)(`select`,{value:e,onChange:e=>i(e.target.value),className:`h-7 px-2 text-xs rounded border border-border bg-background`,children:(t.some(t=>t.value===e)?t:[...t,{value:e,label:e}]).map(e=>(0,Z.jsx)(`option`,{value:e.value,children:e.label},e.value))})}function Ae({open:e,title:t,description:n,placeholder:r,initialValue:i=``,confirmLabel:a,inputPattern:o,inputInvalidHint:c,onConfirm:l,onCancel:u}){let{t:d}=s(),[f,p]=(0,X.useState)(i);(0,X.useEffect)(()=>{e&&p(i)},[e,i]);let m=f.trim(),h=!o||o.test(m),g=m.length>0&&h;return(0,Z.jsx)(I,{open:e,onOpenChange:e=>{e||u()},children:(0,Z.jsxs)(F,{movableResizable:!0,className:`max-w-md`,children:[(0,Z.jsx)(P,{children:(0,Z.jsx)(N,{children:t})}),(0,Z.jsxs)(`div`,{className:`py-2 space-y-2`,children:[n&&(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n}),(0,Z.jsx)(ne,{autoFocus:!0,value:f,placeholder:r,onChange:e=>p(e.target.value),onKeyDown:e=>{e.key===`Enter`&&g&&l(m)},className:`text-sm font-mono`}),m.length>0&&!h&&c&&(0,Z.jsx)(`p`,{className:`text-[11px] text-yellow-500 aurora-light:text-accent-warning`,children:c})]}),(0,Z.jsxs)(A,{children:[(0,Z.jsx)(L,{variant:`ghost`,size:`sm`,onClick:u,children:d(`actions.cancel`)}),(0,Z.jsx)(L,{size:`sm`,onClick:()=>l(m),disabled:!g,children:a??d(`actions.confirm`)})]})]})})}function je({open:e,title:t,description:n,confirmLabel:r,destructive:i=!1,onConfirm:a,onCancel:o}){let{t:c}=s();return(0,Z.jsx)(I,{open:e,onOpenChange:e=>{e||o()},children:(0,Z.jsxs)(F,{movableResizable:!0,className:`max-w-md`,children:[(0,Z.jsx)(P,{children:(0,Z.jsx)(N,{children:t})}),n&&(0,Z.jsx)(`div`,{className:`py-2`,children:(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n})}),(0,Z.jsxs)(A,{children:[(0,Z.jsx)(L,{variant:`ghost`,size:`sm`,onClick:o,children:c(`actions.cancel`)}),(0,Z.jsx)(L,{size:`sm`,onClick:a,className:i?`bg-red-500 hover:bg-red-600 text-white`:void 0,children:r??c(`actions.confirm`)})]})]})})}var Me={models:Ce.map(e=>({value:e,label:e})),defaultModel:`sonnet`,baselineAgents:[...Se],customModelAliases:!1},Ne={primaryProvider:`claude`,providers:[`claude`],catalogs:{claude:Me}};function Pe(e,t,n){return{schemaVersion:1,name:e,description:``,provider:t,orchestrator:{model:n.defaultModel},agents:n.baselineAgents.map(e=>({id:e,model:n.defaultModel,required:!0})),routing:[{default:!0,agent:`sr-developer`}]}}function Fe(){let{t:e}=s(`agents`),[t,n]=(0,X.useState)([]),[r,i]=(0,X.useState)(Ne),[a,c]=(0,X.useState)(``),[u,f]=(0,X.useState)(null),[m,h]=(0,X.useState)(null),[g,_]=(0,X.useState)(!0),[v,y]=(0,X.useState)(null),[b,x]=(0,X.useState)(!1),[S,C]=(0,X.useState)([]),[ee,T]=(0,X.useState)([]),[D,O]=(0,X.useState)(!1),[k,A]=(0,X.useState)(null),[j,M]=(0,X.useState)(null),N=a,P=r.catalogs[N]??Me;(0,X.useEffect)(()=>{let e=!1;return fetch(`${l()}/profiles/context`).then(e=>{if(!e.ok)throw Error(`profile context unavailable`);return e.json()}).then(t=>{if(e)return;let n=Array.isArray(t.providers)&&t.providers.length>0?t.providers:[t.primaryProvider||`claude`],r=n.includes(t.primaryProvider)?t.primaryProvider:n[0];i({...t,providers:n,primaryProvider:r}),c(r)}).catch(()=>{e||(i(Ne),c(Ne.primaryProvider))}),()=>{e=!0}},[]);let F=(0,X.useCallback)(async()=>{if(N){_(!0),y(null);try{let t=await fetch(`${l()}/profiles?provider=${encodeURIComponent(N)}`);if(!t.ok)throw Error(e(`profiles.errors.listFailed`,{status:t.status}));let r=await t.json();n(r.profiles),f(e=>e&&r.profiles.some(t=>t.name===e)?e:r.profiles[0]?.name??null)}catch(e){y(e.message)}finally{_(!1)}}},[N,e]);(0,X.useEffect)(()=>{N&&F()},[N,F]),(0,X.useEffect)(()=>{if(!u){h(null);return}let t=!1;return fetch(`${l()}/profiles/${encodeURIComponent(u)}?provider=${encodeURIComponent(N)}`).then(t=>{if(!t.ok)throw Error(e(`profiles.errors.loadFailed`,{status:t.status}));return t.json()}).then(e=>{t||h(e.profile)}).catch(e=>{t||y(e.message)}),()=>{t=!0}},[N,u,e]);let I=(0,X.useCallback)(async()=>{x(!0),y(null);try{let t=await fetch(`${l()}/profiles/migrate-from-settings?provider=${encodeURIComponent(N)}`,{method:`POST`});if(!t.ok){let n=await t.json().catch(()=>({}));throw Error(n.error??e(`profiles.errors.migrationFailed`,{status:t.status}))}await F(),f(`default`),d.success(e(`profiles.toasts.migrated`),{description:e(`profiles.toasts.migratedDescription`)})}catch(t){let n=t.message;y(n),d.error(e(`profiles.toasts.migrationFailed`),{description:n})}finally{x(!1)}},[N,F,e]),R=(0,X.useCallback)(async t=>{O(!1),x(!0),y(null);try{let n=Pe(t,N,P),r=await fetch(`${l()}/profiles?provider=${encodeURIComponent(N)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(n)});if(!r.ok){let t=await r.json().catch(()=>({}));throw Error(t.error??e(`profiles.errors.createFailed`,{status:r.status}))}await F(),f(t),d.success(e(`profiles.toasts.created`),{description:t})}catch(t){let n=t.message;y(n),d.error(e(`profiles.toasts.createFailed`),{description:n})}finally{x(!1)}},[P,N,F,e]),B=(0,X.useCallback)(async(t,n)=>{A(null),x(!0),y(null);try{let r=await fetch(`${l()}/profiles/${encodeURIComponent(t)}/duplicate?provider=${encodeURIComponent(N)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:n,provider:N})});if(!r.ok){let t=await r.json().catch(()=>({}));throw Error(t.error??e(`profiles.errors.duplicateFailed`,{status:r.status}))}await F(),f(n),d.success(e(`profiles.toasts.duplicated`),{description:e(`profiles.toasts.duplicatedDescription`,{from:t,to:n})})}catch(t){let n=t.message;y(n),d.error(e(`profiles.toasts.duplicateFailed`),{description:n})}finally{x(!1)}},[N,F,e]),V=(0,X.useCallback)(async t=>{M(null),x(!0),y(null);try{let n=await fetch(`${l()}/profiles/${encodeURIComponent(t)}?provider=${encodeURIComponent(N)}`,{method:`DELETE`});if(!n.ok){let t=await n.json().catch(()=>({}));throw Error(t.error??e(`profiles.errors.deleteFailed`,{status:n.status}))}f(e=>e===t?null:e),await F(),d.success(e(`profiles.toasts.deleted`),{description:t})}catch(t){let n=t.message;y(n),d.error(e(`profiles.toasts.deleteFailed`),{description:n})}finally{x(!1)}},[N,F,e]),H=(0,X.useCallback)(()=>O(!0),[]),U=(0,X.useCallback)(e=>A({from:e}),[]),te=(0,X.useCallback)(e=>M({name:e}),[]),ne=(0,X.useCallback)(async(t,n)=>{x(!0),y(null);try{let r=await fetch(`${l()}/profiles/${encodeURIComponent(t.name)}?provider=${encodeURIComponent(N)}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({...t,provider:N})});if(!r.ok){let t=await r.json().catch(()=>({}));throw Error(t.error??e(`profiles.errors.saveFailed`,{status:r.status}))}h(t),n.length>0?d.warning(e(`profiles.toasts.savedWithUntargeted`),{description:e(`profiles.toasts.savedWithUntargetedDescription`,{agents:n.join(`, `)}),duration:6e3}):d.success(e(`profiles.toasts.saved`),{description:t.name})}catch(t){let n=t.message;y(n),d.error(e(`profiles.toasts.saveFailed`),{description:n})}finally{x(!1)}},[N,e]),W=(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Ae,{open:D,title:e(`profiles.createDialog.title`),description:e(`profiles.createDialog.description`),placeholder:`my-profile`,confirmLabel:e(`profiles.createDialog.confirmLabel`),inputPattern:/^[a-z0-9][a-z0-9-]*$/,inputInvalidHint:e(`profiles.createDialog.invalidHint`),onConfirm:e=>void R(e),onCancel:()=>O(!1)}),k&&(0,Z.jsx)(Ae,{open:!0,title:e(`profiles.duplicateDialog.title`,{name:k.from}),description:e(`profiles.duplicateDialog.description`),placeholder:`${k.from}-copy`,initialValue:`${k.from}-copy`,confirmLabel:e(`common:actions.duplicate`),inputPattern:/^[a-z0-9][a-z0-9-]*$/,inputInvalidHint:e(`profiles.duplicateDialog.invalidHint`),onConfirm:e=>void B(k.from,e),onCancel:()=>A(null)}),j&&(0,Z.jsx)(je,{open:!0,title:e(`profiles.deleteDialog.title`,{name:j.name}),description:e(`profiles.deleteDialog.description`),confirmLabel:e(`common:actions.delete`),destructive:!0,onConfirm:()=>void V(j.name),onCancel:()=>M(null)})]});return g?(0,Z.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`profiles.loading`)})}):t.length===0?(0,Z.jsxs)(Z.Fragment,{children:[W,(0,Z.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,Z.jsxs)(`div`,{className:`text-center max-w-md`,children:[(0,Z.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:e(`profiles.empty.title`)}),(0,Z.jsx)(`div`,{className:`text-xs text-muted-foreground mt-1 mb-4`,children:e(`profiles.empty.body`)}),r.providers.length>1&&(0,Z.jsx)(`select`,{value:N,"aria-label":e(`profiles.providerLabel`),onChange:e=>{f(null),h(null),c(e.target.value)},className:`mb-4 h-8 w-full rounded border border-border bg-background px-2 text-xs`,children:r.providers.map(e=>(0,Z.jsx)(`option`,{value:e,children:z(e)},e))}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 justify-center`,children:[(0,Z.jsxs)(L,{size:`sm`,onClick:I,disabled:b,children:[(0,Z.jsx)(he,{className:`w-3.5 h-3.5 mr-1.5`}),` `,e(`profiles.empty.migrateButton`)]}),(0,Z.jsxs)(L,{size:`sm`,variant:`ghost`,onClick:H,disabled:b,children:[(0,Z.jsx)(w,{className:`w-3.5 h-3.5 mr-1.5`}),` `,e(`profiles.empty.blankButton`)]})]}),(0,Z.jsx)(`div`,{className:`text-[11px] text-muted-foreground/70 mt-3`,children:(0,Z.jsx)(o,{t:e,i18nKey:`profiles.empty.migrateExplainer`,components:{code:(0,Z.jsx)(`code`,{className:`text-foreground`})}})}),v&&(0,Z.jsx)(`div`,{className:`mt-3 text-xs text-red-400 aurora-light:text-destructive`,children:v})]})})]}):(0,Z.jsxs)(`div`,{className:`flex flex-col h-full`,children:[W,(0,Z.jsxs)(`div`,{className:`flex flex-1 min-h-0`,children:[(0,Z.jsxs)(`aside`,{className:`w-64 flex-shrink-0 border-r border-border flex flex-col`,children:[(0,Z.jsxs)(`div`,{className:`p-3 space-y-2`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsx)(`div`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:e(`profiles.sidebar.title`)}),(0,Z.jsx)(L,{size:`sm`,variant:`ghost`,onClick:H,disabled:b,children:(0,Z.jsx)(w,{className:`w-3.5 h-3.5`})})]}),r.providers.length>1&&(0,Z.jsx)(`select`,{value:N,"aria-label":e(`profiles.providerLabel`),onChange:e=>{f(null),h(null),c(e.target.value)},className:`h-7 w-full rounded border border-border bg-background px-2 text-xs`,children:r.providers.map(e=>(0,Z.jsx)(`option`,{value:e,children:z(e)},e))})]}),(0,Z.jsx)(`div`,{className:`flex-1 overflow-auto px-2 pb-3`,children:t.map(t=>(0,Z.jsxs)(`div`,{className:`group mb-1 rounded-md px-2 py-1.5 text-xs cursor-pointer transition-colors flex items-center justify-between `+(t.name===u?`bg-accent text-foreground`:`text-muted-foreground hover:bg-accent/50 hover:text-foreground`),onClick:()=>f(t.name),role:`button`,tabIndex:0,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&f(t.name)},children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,Z.jsx)(`span`,{className:`truncate font-medium`,children:t.name}),t.isDefault&&(0,Z.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:e(`profiles.sidebar.teamDefault`)})]}),(0,Z.jsxs)(`div`,{className:`flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity`,children:[(0,Z.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,title:e(`common:actions.duplicate`),onClick:e=>{e.stopPropagation(),U(t.name)},children:(0,Z.jsx)(fe,{className:`w-3 h-3`})}),!t.isDefault&&(0,Z.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-red-500/20 text-red-400 aurora-light:text-destructive rounded`,title:e(`common:actions.delete`),onClick:e=>{e.stopPropagation(),te(t.name)},children:(0,Z.jsx)(E,{className:`w-3 h-3`})})]})]},t.name))})]}),(0,Z.jsxs)(`main`,{className:`flex-1 overflow-auto`,children:[v&&(0,Z.jsx)(`div`,{className:`mx-4 mt-4 px-3 py-2 text-xs rounded border border-red-500/30 aurora-light:border-destructive/30 bg-red-500/10 aurora-light:bg-destructive/10 text-red-400 aurora-light:text-destructive`,children:v}),m?(0,Z.jsx)(De,{profile:m,provider:N,modelCatalog:P.models,defaultModel:P.defaultModel,customModelAliases:P.customModelAliases===!0,baselineAgents:P.baselineAgents,onChange:h,onValidityChange:C,onSoftWarningsChange:e=>T(e.agentsMissingRouting),footer:(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsxs)(L,{size:`sm`,onClick:()=>void ne(m,ee),disabled:b||S.length>0,title:S.length>0?e(`profiles.editorFooter.fixValidationIssues`):void 0,children:[(0,Z.jsx)(p,{className:`w-3.5 h-3.5 mr-1.5`}),e(`common:actions.save`)]}),b&&(0,Z.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e(`common:states.saving`)}),S.length>0&&(0,Z.jsx)(`span`,{className:`text-xs text-yellow-500 aurora-light:text-accent-warning`,children:e(`profiles.editorFooter.issuesToResolve`,{count:S.length})})]})},`${N}:${m.name}`):(0,Z.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`profiles.selectPrompt`)})})]})]})]})}function $(e){let t=e.workflow.map((e,t)=>`${t+1}. ${e}`).join(`
2
2
  `);return`---
3
3
  name: ${e.id}
4
4
  description: "${e.descriptionOneLine}"
@@ -1 +1 @@
1
- import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-zu2_FqZY.js";import{f as r}from"./chunk-KS7C4IRE-DEKu087k.js";import{m as i,r as a}from"./useSharedWebSocket-BOdS5_Iz.js";import{t as o}from"./Trans-SnMX4MhW.js";import{n as s,t as c}from"./createLucideIcon-Bjbbp_KS.js";import{a as l,n as u,r as d}from"./useDesktop-RSMTyy7V.js";import{n as f,r as p,t as m}from"./spending-BqbdPm_4.js";import{t as h}from"./clsx-CjueKrWZ.js";import{t as g}from"./formatDistanceToNow-DSj5DprF.js";import{r as _}from"./provider-capabilities-B-wOHfLP.js";import{Ft as v,ft as y}from"./index-EzrkUb8B.js";import{t as b}from"./ExportDropdown-ophapHrT.js";import{A as x,B as S,C,D as ee,E as w,F as T,G as E,H as D,I as O,J as k,K as A,L as j,M,N,O as P,P as F,Q as I,R as te,S as L,T as R,V as z,X as B,Z as V,_ as ne,_t as H,a as U,at as re,b as ie,c as ae,ct as oe,et as W,f as se,g as G,gt as ce,h as le,i as ue,j as de,k as fe,l as pe,lt as K,m as me,n as he,nt as ge,o as _e,ot as ve,p as ye,pt as q,q as be,r as xe,rt as Se,s as Ce,st as we,t as Te,tt as Ee,ut as J,v as De,x as Oe,y as ke,z as Ae}from"./BarChart-nBOMNfiy.js";var je=c(`arrow-down-right`,[[`path`,{d:`m7 7 10 10`,key:`1fmybs`}],[`path`,{d:`M17 7v10H7`,key:`6fjiku`}]]),Y=e(t(),1),X=n();function Me(e){return e>=100?`$${e.toFixed(0)}`:e>=10?`$${e.toFixed(1)}`:`$${e.toFixed(2)}`}function Ne(e){return e>=1e3?`$${(e/1e3).toFixed(1)}k`:`$${e.toFixed(2)}`}function Pe(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:`${e}`}var Fe=[`job`,`explore-spec`,`quick-spec`,`ai-edit`,`chat-sidebar`,`spec-launcher`,`proposal`,`agent-studio`,`setup`,`smash`,`file-summary`,`loop`];function Ie({data:e,loading:t,period:n}){let{t:r}=s(`analytics`),[i,a]=(0,Y.useState)(0),o=(0,Y.useRef)(0),c=(0,Y.useRef)(null),l=(0,Y.useRef)(0);if((0,Y.useEffect)(()=>{if(!e)return;let t=e.summary.totalCostUsd,n=++l.current;if(c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),o.current===0&&t>0){let e=performance.now(),r=i=>{if(n!==l.current)return;let o=Math.min(1,(i-e)/600),s=1-(1-o)**3;a(0+(t-0)*s),o<1?c.current=requestAnimationFrame(r):c.current=null};c.current=requestAnimationFrame(r)}else a(t);return o.current=t,()=>{c.current!==null&&(cancelAnimationFrame(c.current),c.current=null)}},[e]),t&&!e)return(0,X.jsx)(`div`,{className:`h-44 rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let u=e.summary.totalCostUsd,d=e.summary.totalRuns,h=e.summary.totalTokens,g=e.summary.totalEstimatedCostUsd??0,_=typeof e.summary.pricedRuns==`number`||typeof e.summary.unpricedRuns==`number`,v=e.summary.unpricedRuns??0,y=e.summary.pricedRuns??(_?Math.max(0,d-v):d),b=_&&d>0&&y===0&&v>0,x=y>0&&v>0,S=typeof e.summary.usageReportedRuns==`number`||typeof e.summary.usageUnavailableRuns==`number`,C=e.summary.usageUnavailableRuns??0,ee=e.summary.usageReportedRuns??(S?Math.max(0,d-C):d),w=S&&d>0&&ee===0&&C>0,T=ee>0&&C>0,E=v>0?null:e.summary.deltaPct,D=e.trackingStartedAt,O=g>0,k=e.bySurface.map(e=>e.surface).filter(e=>!Fe.includes(e)),A=[...Fe,...k].map(t=>{let n=e.bySurface.find(e=>e.surface===t);return{surface:t,costUsd:n?.costUsd??0,count:n?.count??0}}),j=n?r(`windowLabels.${n}`):null;return(0,X.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-gradient-to-br from-card/80 to-card/40 p-5`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-end justify-between gap-3 mb-4`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`div`,{className:`text-[11px] uppercase tracking-wider text-muted-foreground mb-1 flex items-center gap-1.5`,children:[(0,X.jsx)(`span`,{children:r(`hero.spending`)}),j&&(0,X.jsxs)(`span`,{"data-testid":`hero-window-label`,className:`normal-case tracking-normal text-muted-foreground/70 font-normal`,children:[`· `,j]})]}),(0,X.jsxs)(`div`,{className:`flex items-baseline gap-3`,children:[(0,X.jsx)(`div`,{className:`text-5xl font-semibold tabular-nums tracking-tight`,"data-testid":b?`hero-cost-unavailable`:void 0,title:b?r(`hero.costUnavailableTooltip`):void 0,children:b?`—`:Ne(i)}),E!==null&&(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 text-xs font-medium ${E>=0?`text-accent-warning`:`text-accent-success`}`,children:[E>=0?(0,X.jsx)(p,{className:`w-3 h-3`}):(0,X.jsx)(je,{className:`w-3 h-3`}),r(`hero.vsPrev`,{pct:Math.abs(E).toFixed(0)})]})]}),(0,X.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-1 tabular-nums flex items-center gap-2`,children:[(0,X.jsx)(`span`,{children:r(`hero.invocations`,{count:d})}),w?(0,X.jsx)(`span`,{"data-testid":`hero-usage-unavailable`,className:`text-muted-foreground/80 italic`,title:r(`hero.usageUnavailableTooltip`),children:r(`hero.usageUnavailable`)}):T&&h!=null?(0,X.jsx)(`span`,{className:`text-muted-foreground/80 italic`,title:r(`hero.usagePartiallyUnavailableTooltip`),children:r(`hero.usagePartiallyUnavailable`,{tokens:Pe(h),count:C})}):h!=null&&h>0?(0,X.jsx)(`span`,{className:`text-muted-foreground/80`,title:r(`hero.tokensTooltip`),children:r(`hero.tokens`,{tokens:Pe(h)})}):null,b&&(0,X.jsx)(`span`,{className:`text-muted-foreground/80 italic`,title:r(`hero.costUnavailableTooltip`),children:r(`hero.costUnavailable`)}),x&&(0,X.jsx)(`span`,{"data-testid":`hero-cost-partial`,className:`text-muted-foreground/80 italic`,title:r(`hero.costPartiallyUnavailableTooltip`),children:r(`hero.costPartiallyUnavailable`,{count:v})}),O&&(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground/70 italic`,title:r(`hero.includesEstimatedTooltip`,{amount:Me(g)}),children:r(`hero.includesEstimated`,{amount:Me(g)})})]})]}),d===0&&D&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:r(`hero.trackingStarted`,{date:D.slice(0,10)})})]}),d===0?(0,X.jsxs)(`div`,{className:`rounded-lg border border-dashed border-border/40 p-6 text-center`,children:[(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:r(`hero.emptyState`)}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground/70 mt-1`,children:D?r(`hero.trackingStarted`,{date:D.slice(0,10)}):r(`hero.trackingStartedFallback`)})]}):b?(0,X.jsx)(`div`,{className:`rounded-lg border border-dashed border-border/40 p-4 text-xs text-muted-foreground/80`,children:r(`hero.costUnavailableTooltip`)}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`h-3 w-full rounded-full overflow-hidden bg-background-deep flex`,children:A.map(e=>{let t=u>0?e.costUsd/u*100:0;return t===0?null:(0,X.jsx)(`div`,{className:`h-full ${m[e.surface].dot}`,style:{width:`${t}%`},title:r(`hero.segmentTitle`,{label:f[e.surface],value:Me(e.costUsd)})},e.surface)})}),(0,X.jsx)(`div`,{className:`mt-3 flex flex-wrap items-center gap-x-5 gap-y-1.5 text-xs`,children:A.filter(e=>e.costUsd>0).map(e=>(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 tabular-nums`,children:[(0,X.jsx)(`span`,{className:`w-2 h-2 rounded-full ${m[e.surface].dot}`}),(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:f[e.surface]}),(0,X.jsx)(`span`,{className:`text-foreground font-medium`,children:Me(e.costUsd)}),(0,X.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,X.jsx)(`span`,{className:`text-muted-foreground/80`,children:e.count})]},e.surface))})]})]})}var Le={claude:`Claude`,codex:`Codex`,gemini:`Gemini`,kimi:`Kimi`},Re={claude:`bg-accent-info`,codex:`bg-accent-highlight`,gemini:`bg-accent-success`,kimi:`bg-purple-400`};function ze(e){return e>=100?`$${e.toFixed(0)}`:e>=10?`$${e.toFixed(1)}`:e>=.01?`$${e.toFixed(2)}`:`$${e.toFixed(4)}`}function Be(e){return Le[e]??e}function Ve(e){return Re[e]??`bg-accent-secondary`}function He({data:e,loading:t}){let{t:n}=s(`analytics`);if(t&&!e)return(0,X.jsx)(`div`,{className:`h-32 rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e||e.byProvider.length===0||e.byProvider.length===1)return null;let r=e.byProvider.reduce((e,t)=>e+t.costUsd+t.estimatedCostUsd,0),i=e.byProvider.some(e=>typeof e.unpricedCount==`number`?e.unpricedCount>0:e.count>0&&e.costUsd===0&&e.estimatedCostUsd===0);return(0,X.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,X.jsx)(`div`,{className:`flex items-baseline justify-between mb-3`,children:(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`text-[11px] uppercase tracking-wider text-muted-foreground`,children:n(`providerCard.title`)}),(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground/70 mt-0.5`,children:(0,X.jsx)(o,{ns:`analytics`,i18nKey:`providerCard.description`,components:{tilde:(0,X.jsx)(`span`,{className:`font-medium`})}})})]})}),r===0&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:n(i?`providerCard.costUnavailableTooltip`:`providerCard.noCost`)}),r>0&&(0,X.jsx)(X.Fragment,{children:(0,X.jsx)(`div`,{className:`h-2 w-full rounded-full overflow-hidden bg-background-deep flex mb-3`,children:e.byProvider.map(e=>{let t=e.costUsd+e.estimatedCostUsd,i=r>0?t/r*100:0;if(i===0)return null;let a=`${e.costUsd===0&&e.estimatedCostUsd>0?`~`:``}${ze(t)}`;return(0,X.jsx)(`div`,{className:`h-full ${Ve(e.provider)}`,style:{width:`${i}%`},title:n(`providerCard.segmentTitle`,{label:Be(e.provider),value:a,count:e.count})},e.provider)})})}),(0,X.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2 ${r>0?``:`mt-3`}`,children:e.byProvider.map(e=>(0,X.jsx)(Ue,{entry:e},e.provider))})]})}function Ue({entry:e}){let{t}=s(`analytics`),n=e.costUsd+e.estimatedCostUsd,r=e.costUsd===0&&e.estimatedCostUsd>0,i=e.unpricedCount??(e.count>0&&e.costUsd===0&&e.estimatedCostUsd===0?e.count:0),a=e.pricedCount??Math.max(0,e.count-i),o=e.count>0&&i>0&&a===0,c=a>0&&i>0;return(0,X.jsxs)(`div`,{className:`flex items-center gap-2.5 rounded-md border border-border/30 px-2.5 py-1.5`,children:[(0,X.jsx)(`span`,{className:`w-2 h-2 rounded-full shrink-0 ${Ve(e.provider)}`}),(0,X.jsx)(`span`,{className:`text-xs font-medium`,children:Be(e.provider)}),(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:t(`runs`,{count:e.count})}),o?(0,X.jsx)(`span`,{className:`ml-auto text-xs font-medium text-muted-foreground/80 italic`,title:t(`providerCard.costUnavailableTooltip`),children:t(`providerCard.costUnavailable`)}):(0,X.jsxs)(`span`,{className:`ml-auto text-xs font-medium tabular-nums`,title:c?t(`providerCard.costPartiallyUnavailableTooltip`):void 0,children:[r?`~`:``,ze(n),c&&(0,X.jsx)(`span`,{className:`ml-1 font-normal text-muted-foreground/80 italic`,children:t(`providerCard.costPartiallyUnavailable`,{count:i})})]})]})}var We=[`option`,`isActive`];function Z(){return Z=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},Z.apply(null,arguments)}function Ge(e,t){if(e==null)return{};var n,r,i=Ke(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function Ke(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}function qe(e){var{option:t,isActive:n}=e,r=Ge(e,We);return typeof t==`string`?Y.createElement(L,Z({option:Y.createElement(we,Z({type:t},r)),isActive:n,shapeType:`symbols`},r)):Y.createElement(L,Z({option:t,isActive:n,shapeType:`symbols`},r))}var Je=W([(e,t,n,r,i,a,o)=>te(e,void 0,void 0,o),(e,t,n,r,i,a,o)=>N(e,`xAxis`,t,o),(e,t,n,r,i,a,o)=>F(e,`xAxis`,t,o),(e,t,n,r,i,a,o)=>N(e,`yAxis`,n,o),(e,t,n,r,i,a,o)=>F(e,`yAxis`,n,o),(e,t,n,r)=>O(e,`zAxis`,r,!1),W([T,(e,t,n,r,i)=>i],(e,t)=>e.filter(e=>e.type===`scatter`).find(e=>e.id===t)),(e,t,n,r,i,a)=>a],(e,t,n,r,i,a,o,s)=>{var{chartData:c,dataStartIndex:l,dataEndIndex:u}=e;if(o!=null){var d=o?.data!=null&&o.data.length>0?o.data:c?.slice(l,u+1);if(!(d==null||t==null||r==null||n==null||i==null||n?.length===0||i?.length===0))return ut({displayedData:d,xAxis:t,yAxis:r,zAxis:a,scatterSettings:o,xAxisTicks:n,yAxisTicks:i,cells:s})}}),Ye=[`id`],Xe=[`onMouseEnter`,`onClick`,`onMouseLeave`],Ze=[`animationBegin`,`animationDuration`,`animationEasing`,`hide`,`isAnimationActive`,`legendType`,`lineJointType`,`lineType`,`shape`,`xAxisId`,`yAxisId`,`zAxisId`];function Qe(e,t){if(e==null)return{};var n,r,i=$e(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function $e(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}function Q(){return Q=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},Q.apply(null,arguments)}function et(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function $(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?et(Object(n),!0).forEach(function(t){tt(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):et(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function tt(e,t,n){return(t=nt(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function nt(e){var t=rt(e,`string`);return typeof t==`symbol`?t:t+``}function rt(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}var it=e=>{var{dataKey:t,name:n,fill:r,legendType:i,hide:a}=e;return[{inactive:a,dataKey:t,type:i,color:r,value:V(n,t),payload:e}]},at=Y.memo(e=>{var{dataKey:t,points:n,stroke:r,strokeWidth:i,fill:a,name:o,hide:s,tooltipType:c,id:l}=e,u={dataDefinedOnItem:n?.map(e=>e.tooltipPayload),getPosition:e=>{var t;return n==null||(t=n[Number(e)])==null?void 0:t.tooltipPosition},settings:{stroke:r,strokeWidth:i,fill:a,nameKey:void 0,dataKey:t,name:V(o,t),hide:s,type:c,color:a,unit:``,graphicalItemId:l}};return Y.createElement(De,{tooltipEntrySettings:u})});function ot(e){var{points:t,props:n}=e,{line:r,lineType:i,lineJointType:a}=n;if(!r)return null;var o=ce(n),s=H(r),c,l;if(i===`joint`)c=t.map(e=>({x:e.cx??null,y:e.cy??null}));else if(i===`fitting`){var{xmin:u,xmax:d,a:f,b:p}=oe(t),m=e=>f*e+p;c=[{x:u,y:m(u)},{x:d,y:m(d)}]}var h=$($($({},o),{},{fill:`none`,stroke:o&&o.fill},s),{},{points:c});return l=Y.isValidElement(r)?Y.cloneElement(r,h):typeof r==`function`?r(h):Y.createElement(z,Q({},h,{type:a})),Y.createElement(q,{className:`recharts-scatter-line`,key:`recharts-scatter-line`},l)}function st(e){var{showLabels:t,points:n,children:r}=e,i=E(),a=(0,Y.useMemo)(()=>n?.map(e=>{var t={x:e.x??0,y:e.y??0,width:e.width,height:e.height,lowerWidth:e.width,upperWidth:e.width};return $($({},t),{},{value:void 0,payload:e.payload,viewBox:t,parentViewBox:i,fill:void 0})}),[i,n]);return Y.createElement(R,{value:t?a:void 0},r)}function ct(e){var{points:t,allOtherScatterProps:n}=e,{shape:r,activeShape:i,dataKey:a}=n,{id:o}=n,s=Qe(n,Ye),c=ge(de),{onMouseEnter:l,onClick:u,onMouseLeave:d}=n,f=Qe(n,Xe),p=ie(l,a,o),m=Oe(d),h=ke(u,a,o);if(!ve(t))return null;var g=ce(s);return Y.createElement(Y.Fragment,null,Y.createElement(ot,{points:t,props:s}),t.map((e,t)=>{var n=i!=null&&i!==!1,a=n&&c===String(t),s=n&&a?i:r,l=$($($({},g),e),{},{index:t,[k]:String(o)});return Y.createElement(x,{key:`symbol-${e?.cx}-${e?.cy}-${e?.size}-${t}`,zIndex:a?j.activeDot:void 0},Y.createElement(q,Q({className:`recharts-scatter-symbol`},re(f,e,t),{onMouseEnter:p(e,t),onMouseLeave:m(e,t),onClick:h(e,t)}),Y.createElement(qe,Q({option:s,isActive:a},l))))}))}function lt(e){var{previousPointsRef:t,props:n}=e,{points:r,isAnimationActive:i,animationBegin:a,animationDuration:o,animationEasing:s}=n,c=t.current,l=Ae(n,`recharts-scatter-`),[u,d]=(0,Y.useState)(!1),f=(0,Y.useCallback)(()=>{d(!1)},[]),p=(0,Y.useCallback)(()=>{d(!0)},[]),m=!u;return Y.createElement(st,{showLabels:m,points:r},n.children,Y.createElement(S,{animationId:l,begin:a,duration:o,isActive:i,easing:s,onAnimationEnd:f,onAnimationStart:p,key:l},e=>{var i=e===1?r:r?.map((t,n)=>{var r=c&&c[n];return r?$($({},t),{},{cx:t.cx==null?void 0:K(r.cx,t.cx,e),cy:t.cy==null?void 0:K(r.cy,t.cy,e),size:K(r.size,t.size,e)}):$($({},t),{},{size:K(0,t.size,e)})});return e>0&&(t.current=i),Y.createElement(q,null,Y.createElement(ct,{points:i,allOtherScatterProps:n,showLabels:m}))}),Y.createElement(w,{label:n.label}))}function ut(e){var{displayedData:t,xAxis:n,yAxis:r,zAxis:i,scatterSettings:a,xAxisTicks:o,yAxisTicks:s,cells:c}=e,l=J(n.dataKey)?a.dataKey:n.dataKey,u=J(r.dataKey)?a.dataKey:r.dataKey,d=i&&i.dataKey,f=i?i.range:M.range,p=f&&f[0],m=n.scale.bandwidth?n.scale.bandwidth():0,h=r.scale.bandwidth?r.scale.bandwidth():0;return t.map((e,t)=>{var f=I(e,l),g=I(e,u),_=!J(d)&&I(e,d)||`-`,v=[{name:J(n.dataKey)?a.name:n.name||String(n.dataKey),unit:n.unit||``,value:f,payload:e,dataKey:l,type:a.tooltipType,graphicalItemId:a.id},{name:J(r.dataKey)?a.name:r.name||String(r.dataKey),unit:r.unit||``,value:g,payload:e,dataKey:u,type:a.tooltipType,graphicalItemId:a.id}];_!==`-`&&i!=null&&v.push({name:i.name||i.dataKey,unit:i.unit||``,value:_,payload:e,dataKey:d,type:a.tooltipType,graphicalItemId:a.id});var y=B({axis:n,ticks:o,bandSize:m,entry:e,index:t,dataKey:l}),b=B({axis:r,ticks:s,bandSize:h,entry:e,index:t,dataKey:u}),x=_!==`-`&&i!=null?i.scale.map(_):p,S=x==null?0:Math.sqrt(Math.max(x,0)/Math.PI);return $($({},e),{},{cx:y,cy:b,x:y==null?void 0:y-S,y:b==null?void 0:b-S,width:2*S,height:2*S,size:x,node:{x:f,y:g,z:_},tooltipPayload:v,tooltipPosition:{x:y,y:b},payload:e},c&&c[t]&&c[t].props)})}var dt=(e,t,n)=>({x:e.cx,y:e.cy,value:Number(n===`x`?e.node.x:e.node.y),errorVal:I(e,t)});function ft(e){var{hide:t,points:n,className:r,needClip:i,xAxisId:a,yAxisId:o,id:s}=e,c=(0,Y.useRef)(null);if(t)return null;var l=h(`recharts-scatter`,r),u=s;return Y.createElement(x,{zIndex:e.zIndex},Y.createElement(q,{className:l,clipPath:i?`url(#clipPath-${u})`:void 0,id:s},i&&Y.createElement(`defs`,null,Y.createElement(_e,{clipPathId:u,xAxisId:a,yAxisId:o})),Y.createElement(ae,{xAxisId:a,yAxisId:o,data:n,dataPointFormatter:dt,errorBarOffset:0},Y.createElement(q,{key:`recharts-scatter-symbols`},Y.createElement(lt,{props:e,previousPointsRef:c})))))}var pt={xAxisId:0,yAxisId:0,zAxisId:0,label:!1,line:!1,legendType:`circle`,lineType:`joint`,lineJointType:`linear`,shape:`circle`,hide:!1,isAnimationActive:`auto`,animationBegin:0,animationDuration:400,animationEasing:`linear`,zIndex:j.scatter};function mt(e){var t=Se(e,pt),{animationBegin:n,animationDuration:r,animationEasing:i,hide:a,isAnimationActive:o,legendType:s,lineJointType:c,lineType:l,shape:u,xAxisId:d,yAxisId:f,zAxisId:p}=t,m=Qe(t,Ze),{needClip:h}=Ce(d,f),g=(0,Y.useMemo)(()=>C(e.children,ee),[e.children]),_=be(),v=ge(t=>Je(t,d,f,p,e.id,g,_));return h==null||v==null?null:Y.createElement(Y.Fragment,null,Y.createElement(at,{dataKey:e.dataKey,points:v,stroke:e.stroke,strokeWidth:e.strokeWidth,fill:e.fill,name:e.name,hide:e.hide,tooltipType:e.tooltipType,id:e.id}),Y.createElement(ft,Q({},m,{xAxisId:d,yAxisId:f,zAxisId:p,lineType:l,lineJointType:c,legendType:s,shape:u,hide:a,isAnimationActive:o,animationBegin:n,animationDuration:r,animationEasing:i,points:v,needClip:h})))}function ht(e){var t=Se(e,pt),n=be();return Y.createElement(G,{id:t.id,type:`scatter`},e=>Y.createElement(Y.Fragment,null,Y.createElement(ne,{legendPayload:it(t)}),Y.createElement(le,{type:`scatter`,id:e,data:t.data,xAxisId:t.xAxisId,yAxisId:t.yAxisId,zAxisId:t.zAxisId,dataKey:t.dataKey,hide:t.hide,name:t.name,tooltipType:t.tooltipType,isPanorama:n}),Y.createElement(mt,Q({},t,{id:e}))))}var gt=Y.memo(ht,D);gt.displayName=`Scatter`;function _t(e){var t=Ee(),n=(0,Y.useRef)(null);return(0,Y.useLayoutEffect)(()=>{n.current===null?t(se(e)):n.current!==e&&t(me({prev:n.current,next:e})),n.current=e},[e,t]),(0,Y.useLayoutEffect)(()=>()=>{n.current&&=(t(ye(n.current)),null)},[t]),null}var vt={zAxisId:0,range:M.range,scale:M.scale,type:M.type};function yt(e){var t=Se(e,vt);return Y.createElement(_t,{domain:t.domain,id:t.zAxisId,dataKey:t.dataKey,name:t.name,unit:t.unit,range:t.range,scale:t.scale,type:t.type,allowDuplicatedCategory:M.allowDuplicatedCategory,allowDataOverflow:M.allowDataOverflow,reversed:M.reversed,includeHidden:M.includeHidden})}yt.displayName=`ZAxis`;var bt=[`item`],xt=(0,Y.forwardRef)((e,t)=>Y.createElement(he,{chartName:`ScatterChart`,defaultTooltipEventType:`item`,validateTooltipEventTypes:bt,tooltipPayloadSearcher:fe,categoricalChartProps:e,ref:t}));function St({data:e,loading:t}){let{t:n}=s(`analytics`);if(t&&!e)return(0,X.jsx)(`div`,{className:`h-[220px] rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let r={jobs:n(`surfaces.job`),explore:n(`surfaces.exploreSpec`),quick:n(`surfaces.quickSpec`),refine:n(`surfaces.aiEdit`),fileSummaries:n(`surfaces.fileSummary`),smash:n(`surfaces.smash`),loop:n(`surfaces.loop`)},i=e.dailyTimeline.map(e=>({date:e.date.slice(5),[r.jobs]:e.jobsCostUsd,[r.explore]:e.exploreCostUsd,[r.quick]:e.quickCostUsd,[r.refine]:e.aiEditCostUsd,[r.fileSummaries]:e.fileSummaryCostUsd??0,[r.smash]:e.smashCostUsd??0,[r.loop]:e.loopCostUsd??0})),a=e.dailyTimeline.every(e=>e.jobsCostUsd+e.exploreCostUsd+e.quickCostUsd+e.aiEditCostUsd+(e.fileSummaryCostUsd??0)+(e.smashCostUsd??0)+(e.loopCostUsd??0)===0),o=e.dailyTimeline.reduce((e,t)=>e+(t.unpricedCount??0),0),c=a&&o>0,l=!a&&o>0;return(0,X.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,X.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider`,children:n(`timeline.title`)}),(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground/70`,children:l?n(`timeline.costPartiallyUnavailable`,{count:o}):n(`timeline.subtitle`)})]}),c?(0,X.jsx)(`div`,{"data-testid":`timeline-cost-unavailable`,className:`h-40 flex items-center justify-center text-xs text-muted-foreground/70`,children:n(`timeline.costUnavailable`)}):a?(0,X.jsx)(`div`,{className:`h-40 flex items-center justify-center text-xs text-muted-foreground/70`,children:n(`timeline.empty`)}):(0,X.jsx)(`div`,{className:`h-[220px]`,children:(0,X.jsx)(A,{width:`100%`,height:`100%`,children:(0,X.jsxs)(Te,{data:i,margin:{top:10,right:10,left:-8,bottom:0},children:[(0,X.jsx)(pe,{strokeDasharray:`2 4`,stroke:`currentColor`,className:`text-border/30`,vertical:!1}),(0,X.jsx)(ue,{dataKey:`date`,tick:{fontSize:10},stroke:`currentColor`,className:`text-muted-foreground`}),(0,X.jsx)(xe,{tick:{fontSize:10},stroke:`currentColor`,className:`text-muted-foreground`,tickFormatter:e=>`$${e}`}),(0,X.jsx)(P,{contentStyle:{backgroundColor:`var(--popover)`,border:`1px solid var(--border)`,fontSize:11,borderRadius:6},formatter:(e,t)=>[`$${typeof e==`number`?e.toFixed(2):`—`}`,String(t)]}),(0,X.jsx)(U,{dataKey:r.jobs,stackId:`a`,fill:`var(--accent-info, #5fa8d3)`}),(0,X.jsx)(U,{dataKey:r.explore,stackId:`a`,fill:`var(--accent-highlight, #c084fc)`}),(0,X.jsx)(U,{dataKey:r.quick,stackId:`a`,fill:`var(--accent-secondary, #f7768e)`}),(0,X.jsx)(U,{dataKey:r.refine,stackId:`a`,fill:`var(--accent-success, #50fa7b)`}),(0,X.jsx)(U,{dataKey:r.fileSummaries,stackId:`a`,fill:`var(--accent-warning, #f1fa8c)`}),(0,X.jsx)(U,{dataKey:r.smash,stackId:`a`,fill:`var(--accent-highlight, #c084fc)`}),(0,X.jsx)(U,{dataKey:r.loop,stackId:`a`,fill:`var(--accent-primary, #7aa2f7)`})]})})})]})}function Ct(e){return e==null?`—`:e<.005?`$${e.toFixed(4)}`:e<1?`$${e.toFixed(3)}`:`$${e.toFixed(2)}`}function wt(e){return e==null?`—`:e<1e3?`${e} ms`:e<6e4?`${(e/1e3).toFixed(1)}s`:`${Math.floor(e/6e4)}m ${Math.floor(e%6e4/1e3)}s`}function Tt({values:e}){let t=Math.max(1e-4,...e);return(0,X.jsx)(`div`,{className:`flex items-end gap-[1px] h-5`,children:e.map((e,n)=>(0,X.jsx)(`div`,{className:`w-[3px] rounded-sm bg-foreground/40`,style:{height:`${Math.max(2,e/t*20)}px`}},n))})}function Et({mode:e,label:t,accentClass:n}){let{t:r}=s(`analytics`),i=e.mode===`explore`&&e.totalRuns<5,a=(e.estimatedCostUsd??0)>0,c=e.avgCostPerSpec==null&&(e.unpricedCount??0)>0;return(0,X.jsxs)(`div`,{className:`flex-1 p-4 first:pr-2 last:pl-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,X.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full ${n}`}),(0,X.jsx)(`span`,{className:`text-xs font-medium uppercase tracking-wider text-muted-foreground`,children:t})]}),i?(0,X.jsxs)(`div`,{className:`py-3`,children:[(0,X.jsx)(`p`,{className:`text-sm text-foreground`,children:r(`quickVsExplore.sparseCta`)}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:r(`quickVsExplore.runsSoFar`,{count:e.totalRuns})})]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`text-3xl font-semibold tabular-nums tracking-tight`,"data-estimated":a?`true`:void 0,title:c?r(`quickVsExplore.costUnavailableTooltip`):a?r(`quickVsExplore.estimatedTooltip`):void 0,children:[a&&e.avgCostPerSpec!=null?`~`:``,Ct(e.avgCostPerSpec)]}),(0,X.jsx)(`div`,{className:`text-[11px] text-muted-foreground mt-0.5`,children:r(c?`quickVsExplore.costUnavailable`:`quickVsExplore.perSpec`)}),(0,X.jsx)(`div`,{className:`mt-3`,children:(0,X.jsx)(Tt,{values:e.sparkline.length>0?e.sparkline:[0]})}),(0,X.jsxs)(`div`,{className:`mt-3 space-y-0.5 text-xs tabular-nums text-muted-foreground`,children:[(0,X.jsx)(`div`,{children:(0,X.jsx)(o,{ns:`analytics`,i18nKey:`quickVsExplore.createdRuns`,values:{created:e.ticketsCreated,runs:e.totalRuns},components:{strong:(0,X.jsx)(`span`,{className:`text-foreground font-medium`})}})}),(0,X.jsx)(`div`,{children:r(`quickVsExplore.avgDuration`,{duration:wt(e.avgDurationMs)})}),(0,X.jsx)(`div`,{className:`truncate`,children:e.dominantModel??`—`})]})]})]})}function Dt({data:e,loading:t}){let{t:n}=s(`analytics`);if(t&&!e)return(0,X.jsx)(`div`,{className:`h-[220px] rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let r=e.byMode.find(e=>e.mode===`quick`),i=e.byMode.find(e=>e.mode===`explore`);if(!r||!i)return null;let a=r.avgCostPerSpec&&i.avgCostPerSpec&&r.avgCostPerSpec>0?i.avgCostPerSpec/r.avgCostPerSpec:null,o=a!==null&&r.totalRuns>=1&&i.totalRuns>=5,c=(r.estimatedCostUsd??0)>0||(i.estimatedCostUsd??0)>0;return(0,X.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40`,children:[(0,X.jsx)(`div`,{className:`px-4 pt-3 pb-1`,children:(0,X.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider`,children:n(`quickVsExplore.title`)})}),(0,X.jsxs)(`div`,{className:`flex divide-x divide-border/40`,children:[(0,X.jsx)(Et,{mode:r,label:n(`quickVsExplore.quick`),accentClass:`bg-accent-secondary`}),(0,X.jsx)(Et,{mode:i,label:n(`quickVsExplore.explore`),accentClass:`bg-accent-highlight`})]}),o&&(0,X.jsx)(`div`,{className:`px-4 pb-3 -mt-1`,children:(0,X.jsx)(`div`,{className:`text-center text-[11px] text-muted-foreground tabular-nums`,children:(0,X.jsxs)(`span`,{className:`px-2`,children:[`━━━━━━ `,n(`quickVsExplore.ratio`,{ratio:a.toFixed(1)}),` ━━━━━━`]})})}),c&&(0,X.jsx)(`div`,{className:`px-4 pb-3 -mt-1`,"data-testid":`quick-vs-explore-estimated-footnote`,children:(0,X.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:n(`quickVsExplore.estimatedFootnote`)})})]})}function Ot(e){return e<.005&&e>0?`$${e.toFixed(4)}`:e<1?`$${e.toFixed(3)}`:`$${e.toFixed(2)}`}function kt(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function At({data:e,loading:t}){let{t:n}=s(`analytics`),r=e?.agentMissions;if(t||!r||r.summary.turns===0)return null;let{summary:a,topConversations:o}=r,c=a.estimatedCostUsd>0,l=a.prevTotalCostUsd>0?(a.totalCostUsd-a.prevTotalCostUsd)/a.prevTotalCostUsd*100:null;return(0,X.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card p-4`,"data-testid":`agent-missions-card`,children:[(0,X.jsxs)(`div`,{className:`mb-3 flex items-center gap-2`,children:[(0,X.jsx)(v,{className:`h-4 w-4 text-accent-highlight`}),(0,X.jsx)(`h3`,{className:`text-sm font-medium`,children:n(`agentMissions.title`)}),(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:n(`agentMissions.subtitle`)})]}),(0,X.jsxs)(`div`,{className:`flex items-baseline gap-3`,children:[(0,X.jsxs)(`span`,{className:`text-3xl font-semibold tabular-nums tracking-tight`,"data-estimated":c?`true`:void 0,title:c?n(`agentMissions.estimatedNote`):void 0,children:[c?`~`:``,Ot(a.totalCostUsd)]}),l!==null&&(0,X.jsxs)(`span`,{className:l>0?`text-xs text-accent-warning`:`text-xs text-accent-success`,children:[l>0?`+`:``,l.toFixed(0),`% `,n(`agentMissions.vsPrev`)]})]}),(0,X.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:n(`agentMissions.turnsAndTokens`,{turns:a.turns,tokens:kt(a.tokensIn+a.tokensOut)})}),o.length>0&&(0,X.jsx)(`ul`,{className:`mt-3 space-y-1 border-t border-border/40 pt-2`,children:o.map(e=>(0,X.jsxs)(`li`,{className:`flex items-center gap-2 text-xs`,children:[(0,X.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-foreground/85`,children:e.title?.trim()||n(`agentMissions.untitled`)}),(0,X.jsxs)(`span`,{className:`shrink-0 text-[10px] text-muted-foreground`,children:[e.turns,` · `,e.lastAt?g(new Date(e.lastAt),{addSuffix:!0,locale:i()}):`—`]}),(0,X.jsxs)(`span`,{className:`shrink-0 tabular-nums font-medium`,children:[e.estimatedCostUsd>0?`~`:``,Ot(e.costUsd)]})]},e.conversationId??`unknown`))})]})}function jt({data:e,loading:t,onSelectModel:n,activeModel:r}){let{t:i}=s(`analytics`);if(t&&!e)return(0,X.jsx)(`div`,{className:`h-[220px] rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let a=e.summary.totalCostUsd,o=e.byModel.slice(0,5),c=o.reduce((e,t)=>e+t.costUsd,0),l=Math.max(0,a-c),u=l>=.005;return(0,X.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,X.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider mb-3`,children:i(`models.title`)}),o.length===0?(0,X.jsx)(`div`,{className:`h-32 flex items-center justify-center text-xs text-muted-foreground/70`,children:i(`models.empty`)}):(0,X.jsxs)(`ul`,{className:`space-y-1.5`,children:[o.map(e=>{let t=a>0?e.costUsd/a*100:0,o=r===e.model,s=(e.estimatedCostUsd??0)>0,c=e.unpricedCount??0,l=Math.max(0,e.count-c),u=e.count>0&&c>0&&l===0,d=l>0&&c>0;return(0,X.jsx)(`li`,{children:(0,X.jsxs)(`button`,{type:`button`,onClick:()=>n(e.model,e.provider),className:`w-full text-left group rounded-md px-2 py-1.5 transition-colors ${o?`bg-accent-highlight/10 ring-1 ring-accent-highlight/30`:`hover:bg-accent/30`}`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between text-[12px] mb-1 tabular-nums`,children:[(0,X.jsx)(`span`,{className:`truncate font-medium`,children:e.model}),(0,X.jsx)(`span`,{className:`text-muted-foreground`,"data-testid":u?`model-cost-unavailable`:void 0,title:u?i(`models.costUnavailableTooltip`):d?i(`models.costPartiallyUnavailableTooltip`):s?i(`models.estimatedTooltip`):void 0,children:u?i(`models.costUnavailableWithRuns`,{count:e.count}):(0,X.jsxs)(X.Fragment,{children:[s?`~`:``,`$`,e.costUsd.toFixed(2),` · `,e.count,d&&(0,X.jsx)(`span`,{className:`ml-1 italic`,children:i(`models.costPartiallyUnavailable`,{count:c})})]})})]}),(0,X.jsx)(`div`,{className:`h-1.5 rounded-full bg-background-deep overflow-hidden`,children:(0,X.jsx)(`div`,{className:`h-full ${o?`bg-accent-highlight`:`bg-foreground/40 group-hover:bg-foreground/60`} transition-colors`,style:{width:`${t}%`}})})]})},`${e.provider??`claude`}:${e.model}`)}),u&&(0,X.jsx)(`li`,{"data-testid":`model-others`,children:(0,X.jsxs)(`div`,{className:`w-full rounded-md px-2 py-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between text-[12px] mb-1 tabular-nums`,children:[(0,X.jsx)(`span`,{className:`truncate font-medium text-muted-foreground`,children:i(`models.others`)}),(0,X.jsxs)(`span`,{className:`text-muted-foreground`,children:[`$`,l.toFixed(2)]})]}),(0,X.jsx)(`div`,{className:`h-1.5 rounded-full bg-background-deep overflow-hidden`,children:(0,X.jsx)(`div`,{className:`h-full bg-foreground/25`,style:{width:`${a>0?l/a*100:0}%`}})})]})})]})]})}var Mt={job:`var(--accent-info, #5fa8d3)`,"quick-spec":`var(--accent-secondary, #f7768e)`,"explore-spec":`var(--accent-highlight, #c084fc)`,"ai-edit":`var(--accent-success, #50fa7b)`,smash:`var(--accent-highlight, #c084fc)`,"file-summary":`var(--accent-warning, #f1fa8c)`,loop:`var(--accent-primary, #7aa2f7)`,"chat-sidebar":`var(--accent-info, #5fa8d3)`,"spec-launcher":`var(--accent-secondary, #f7768e)`,proposal:`var(--accent-highlight, #c084fc)`,"agent-studio":`var(--accent-success, #50fa7b)`,setup:`var(--accent-primary, #7aa2f7)`},Nt=Object.keys(f);function Pt({data:e,loading:t,onSelectPoint:n}){let{t:r}=s(`analytics`);if(t&&!e)return(0,X.jsx)(`div`,{className:`h-[260px] rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let i=Nt,a=i.map(t=>({surface:t,points:e.scatter.filter(e=>e.surface===t).map(e=>({id:e.id,x:e.numTurns??Math.round((e.durationMs??0)/1e3),y:e.costUsd,surface:t,ticketId:e.ticketId,startedAt:e.startedAt,raw:e}))})),o=e.scatter.length===0,c=e.summary.unpricedRuns??0,l=o&&c>0,u=!o&&c>0,d=e.scatterTruncated===!0,p=e.scatterTotal??e.scatter.length;return(0,X.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,X.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider`,children:r(`scatter.title`)}),(0,X.jsx)(`div`,{className:`flex flex-wrap items-center gap-2 text-[10px]`,children:i.map(e=>(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,X.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full`,style:{background:Mt[e]}}),(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:f[e]})]},e))})]}),d&&!o&&(0,X.jsx)(`div`,{"data-testid":`scatter-truncation-notice`,className:`mb-2 text-[10px] text-accent-warning`,children:r(`scatter.truncated`,{shown:e.scatter.length,total:p})}),u&&(0,X.jsx)(`div`,{"data-testid":`scatter-cost-partial-notice`,className:`mb-2 text-[10px] text-muted-foreground/80 italic`,children:r(`scatter.costPartiallyUnavailable`,{count:c})}),l?(0,X.jsx)(`div`,{"data-testid":`scatter-cost-unavailable`,className:`h-40 flex items-center justify-center text-xs text-muted-foreground/70`,children:r(`scatter.costUnavailable`)}):o?(0,X.jsx)(`div`,{className:`h-40 flex items-center justify-center text-xs text-muted-foreground/70`,children:r(`scatter.empty`)}):(0,X.jsx)(`div`,{className:`h-[260px]`,children:(0,X.jsx)(A,{width:`100%`,height:`100%`,children:(0,X.jsxs)(xt,{margin:{top:10,right:10,left:-8,bottom:5},children:[(0,X.jsx)(pe,{strokeDasharray:`2 4`,stroke:`currentColor`,className:`text-border/30`}),(0,X.jsx)(ue,{type:`number`,dataKey:`x`,name:`turns`,tick:{fontSize:10},stroke:`currentColor`,className:`text-muted-foreground`,label:{value:r(`scatter.turnsLabel`),position:`insideBottomRight`,offset:-2,fontSize:10,fill:`currentColor`}}),(0,X.jsx)(xe,{type:`number`,dataKey:`y`,name:`cost`,tick:{fontSize:10},stroke:`currentColor`,className:`text-muted-foreground`,tickFormatter:e=>`$${e.toFixed(e<1?2:0)}`}),(0,X.jsx)(yt,{range:[40,80]}),(0,X.jsx)(P,{cursor:{strokeDasharray:`3 3`},contentStyle:{backgroundColor:`var(--popover)`,border:`1px solid var(--border)`,fontSize:11,borderRadius:6},formatter:(e,t)=>{let n=String(t);return n===`cost`&&typeof e==`number`?[`$${e.toFixed(3)}`,r(`scatter.costLabel`)]:[String(e),n===`turns`?r(`scatter.turnsLabel`):n]}}),a.map(e=>(0,X.jsx)(gt,{data:e.points,fill:Mt[e.surface],onClick:e=>{let t=e;t?.raw&&n(t.raw)}},e.surface))]})})})]})}function Ft({data:e,loading:t,onSelectTicket:n}){let{t:r}=s(`analytics`);if(t&&!e)return(0,X.jsx)(`div`,{className:`h-40 rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let i=e.topTickets;return(0,X.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,X.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider mb-3`,children:r(`topTickets.title`)}),i.length===0?(0,X.jsx)(`div`,{className:`h-32 flex items-center justify-center text-xs text-muted-foreground/70`,children:r(`topTickets.empty`)}):(0,X.jsx)(`ul`,{className:`divide-y divide-border/30`,children:i.map((e,t)=>{let i=Object.entries(e.bySurface).filter(([,e])=>e.count>0).map(([e,t])=>r(`topTickets.breakdownItem`,{n:t.count,label:f[e].toLowerCase()})).join(` + `),a=e.isUnattributed,o=a?r(`topTickets.unattributed`):e.ticketTitle?`#${e.ticketId} ${e.ticketTitle}`:r(`topTickets.deletedTicket`,{id:e.ticketId}),s=!e.ticketTitle&&!a?`opacity-50`:``,c=e.unpricedCount??0,l=e.totalRuns>0&&c===e.totalRuns,u=c>0&&!l;return(0,X.jsx)(`li`,{children:(0,X.jsxs)(`button`,{type:`button`,onClick:()=>n(e.ticketId),className:`w-full text-left flex items-center justify-between gap-3 py-2 px-1 hover:bg-accent/30 rounded transition-colors ${s}`,disabled:a,children:[(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`div`,{className:`text-sm truncate`,children:o}),(0,X.jsx)(`div`,{className:`text-[11px] text-muted-foreground truncate`,children:i||`—`})]}),(0,X.jsxs)(`div`,{className:`text-right tabular-nums`,children:[(0,X.jsx)(`div`,{className:`text-sm font-medium`,title:l?r(`topTickets.costUnavailableTooltip`):u?r(`topTickets.costPartiallyUnavailableTooltip`):void 0,children:l?r(`topTickets.costUnavailable`):`$${e.totalCostUsd.toFixed(2)}`}),u&&(0,X.jsx)(`div`,{className:`text-[10px] text-muted-foreground italic`,children:r(`topTickets.costPartiallyUnavailable`,{count:c})}),(0,X.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:r(`runs`,{count:e.totalRuns})})]})]})},`${e.ticketId??`u`}-${t}`)})})]})}var It={claude:`Claude`,codex:`Codex`,gemini:`Gemini`,kimi:`Kimi`};function Lt(e){return It[e]??e}function Rt(e){return e==null?`—`:e<.005?`$${e.toFixed(4)}`:`$${e.toFixed(2)}`}function zt(e){return e==null?`—`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function Bt(e){return e.surface_ref_id?.startsWith(`contract-refine:`)?!0:e.surface===`explore-spec`&&e.ticket_id!=null&&e.conversation_id!=null&&e.surface_ref_id===e.conversation_id&&e.model==null}function Vt(e){let t=new Map;for(let n of e)n.model&&(n.conversation_id&&t.set(`conversation:${n.conversation_id}`,n.model),n.ticket_id!=null&&n.surface===`explore-spec`&&t.set(`ticket:${n.ticket_id}:explore-spec`,n.model),n.ticket_id!=null&&n.surface===`quick-spec`&&t.set(`ticket:${n.ticket_id}:quick-spec`,n.model));return t}function Ht(e,t){if(e.model)return e.model;if(!Bt(e))return null;if(e.conversation_id){let n=t.get(`conversation:${e.conversation_id}`);if(n)return n}return e.ticket_id==null?null:t.get(`ticket:${e.ticket_id}:${e.surface}`)??null}function Ut({rows:e,loading:t,truncated:n,totalAvailable:r,tableFilters:i,onTableFiltersChange:a}){let{t:o}=s(`analytics`),[c,l]=(0,Y.useState)(null),u=Vt(e),d=new Set(e.map(e=>e.provider??`claude`)).size>1,p=n||r>e.length;return(0,X.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 mb-3`,children:[(0,X.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider`,children:o(`table.title`)}),(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-[11px]`,children:[(0,X.jsxs)(`select`,{value:i.status??``,onChange:e=>a({...i,status:e.target.value||void 0}),className:`h-7 px-2 rounded-md bg-background-deep border border-border/60 text-xs`,"aria-label":o(`table.statusFilterAria`),children:[(0,X.jsx)(`option`,{value:``,children:o(`table.allStatus`)}),(0,X.jsx)(`option`,{value:`success`,children:o(`table.success`)}),(0,X.jsx)(`option`,{value:`failed`,children:o(`table.failed`)}),(0,X.jsx)(`option`,{value:`aborted`,children:o(`table.aborted`)})]}),(0,X.jsx)(`input`,{type:`number`,step:`0.01`,min:`0`,placeholder:o(`table.minCostPlaceholder`),value:i.minCostUsd??``,onChange:e=>{let t=e.target.value===``?void 0:parseFloat(e.target.value);a({...i,minCostUsd:Number.isNaN(t)?void 0:t})},className:`h-7 w-24 px-2 rounded-md bg-background-deep border border-border/60 text-xs tabular-nums`,"aria-label":o(`table.minCostFilterAria`)})]})]}),t?(0,X.jsx)(`div`,{className:`h-32 rounded bg-card/30 animate-pulse`}):e.length===0?(0,X.jsx)(`div`,{className:`h-32 flex items-center justify-center text-xs text-muted-foreground/70`,children:o(`table.empty`)}):(0,X.jsx)(`div`,{className:`overflow-x-auto`,children:(0,X.jsxs)(`table`,{className:`w-full text-[12px] tabular-nums`,children:[(0,X.jsx)(`thead`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:(0,X.jsxs)(`tr`,{className:`text-left`,children:[(0,X.jsx)(`th`,{className:`font-medium px-2 py-2`,children:o(`table.colSurface`)}),(0,X.jsx)(`th`,{className:`font-medium px-2 py-2`,children:o(`table.colTicket`)}),(0,X.jsx)(`th`,{className:`font-medium px-2 py-2 text-right`,children:o(`table.colCost`)}),(0,X.jsx)(`th`,{className:`font-medium px-2 py-2 text-right`,children:o(`table.colTurns`)}),(0,X.jsx)(`th`,{className:`font-medium px-2 py-2 text-right`,children:o(`table.colTokens`)}),(0,X.jsx)(`th`,{className:`font-medium px-2 py-2`,children:o(`table.colModel`)}),d&&(0,X.jsx)(`th`,{className:`font-medium px-2 py-2`,children:o(`table.colProvider`)}),(0,X.jsx)(`th`,{className:`font-medium px-2 py-2`,children:o(`table.colStatus`)}),(0,X.jsx)(`th`,{className:`font-medium px-2 py-2`,children:o(`table.colStarted`)})]})}),(0,X.jsx)(`tbody`,{children:e.map(e=>{let t=e.surface,n=m[t],r=(e.tokens_in??0)+(e.tokens_out??0)+(e.tokens_cache_read??0)+(e.tokens_cache_create??0),i=Bt(e),a=i?o(`table.contractLayer`):f[t],s=Ht(e,u);return(0,X.jsxs)(`tr`,{onClick:()=>l(c===e.id?null:e.id),className:`border-t border-border/30 hover:bg-accent/30 cursor-pointer`,children:[(0,X.jsx)(`td`,{className:`px-2 py-2`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 px-2 h-5 rounded-full text-[10px] font-medium ${n.bg} ${n.text}`,children:[(0,X.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full ${n.dot}`}),a]})}),(0,X.jsx)(`td`,{className:`px-2 py-2 max-w-[260px]`,children:e.ticket_id==null?e.ticket_title?(0,X.jsx)(`span`,{className:`truncate block text-muted-foreground/90 italic`,title:o(`table.provisionalTitleTooltip`),children:e.ticket_title}):(0,X.jsx)(`span`,{className:`text-muted-foreground/70`,children:`—`}):(0,X.jsxs)(`span`,{className:`truncate block`,children:[`#`,e.ticket_id,` `,i?(0,X.jsx)(`span`,{className:`text-muted-foreground/90`,children:o(`table.contractLayerRefinement`)}):e.ticket_title??(0,X.jsx)(`span`,{className:`text-muted-foreground/70 italic`,children:o(`table.deleted`)})]})}),(0,X.jsx)(`td`,{className:`px-2 py-2 text-right font-medium`,children:e.total_cost_usd_estimated===1&&e.total_cost_usd!=null?(0,X.jsxs)(`span`,{title:o(`table.estimatedCostTooltip`),className:`text-muted-foreground/90`,children:[`~`,Rt(e.total_cost_usd)]}):Rt(e.total_cost_usd)}),(0,X.jsx)(`td`,{className:`px-2 py-2 text-right`,children:zt(e.num_turns)}),(0,X.jsx)(`td`,{className:`px-2 py-2 text-right`,children:r>0?zt(r):`—`}),(0,X.jsxs)(`td`,{className:`px-2 py-2 max-w-[180px] truncate`,children:[s??`—`,s&&!e.model?(0,X.jsx)(`span`,{className:`ml-1 text-[10px] text-muted-foreground/70`,children:o(`table.inferred`)}):null]}),d&&(0,X.jsx)(`td`,{className:`px-2 py-2 text-muted-foreground`,children:Lt(e.provider??`claude`)}),(0,X.jsxs)(`td`,{className:`px-2 py-2`,children:[e.status===`success`?(0,X.jsx)(`span`,{className:`text-accent-success/90`,children:`●`}):e.status===`failed`?(0,X.jsx)(`span`,{className:`text-accent-warning`,children:`⚠`}):(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`○`}),(0,X.jsx)(`span`,{className:`ml-1 text-muted-foreground`,children:o(`table.statusValue.${e.status}`)})]}),(0,X.jsx)(`td`,{className:`px-2 py-2 text-muted-foreground`,children:e.started_at.slice(0,16).replace(`T`,` `)})]},e.id)})})]})}),p&&e.length>0&&(0,X.jsx)(`div`,{className:`mt-2 text-[11px] text-muted-foreground/80`,children:o(`table.truncated`,{shown:e.length,total:r.toLocaleString()})})]})}var Wt=[{value:`7d`,labelKey:`periods.d7`},{value:`30d`,labelKey:`periods.d30`},{value:`90d`,labelKey:`periods.d90`},{value:`all`,labelKey:`periods.all`}],Gt=[{value:`all`,labelKey:`page.all`},{value:`job`,labelKey:`surfaces.job`},{value:`explore-spec`,labelKey:`surfaces.exploreSpec`},{value:`quick-spec`,labelKey:`surfaces.quickSpec`},{value:`ai-edit`,labelKey:`surfaces.aiEdit`},{value:`smash`,labelKey:`surfaces.smash`},{value:`file-summary`,labelKey:`surfaces.fileSummary`},{value:`loop`,labelKey:`surfaces.loop`}];function Kt(e){let t=new URLSearchParams;return e.period&&t.set(`period`,e.period),e.from&&t.set(`from`,e.from),e.to&&t.set(`to`,e.to),e.surface&&e.surface.length>0&&t.set(`surface`,e.surface.join(`,`)),e.provider&&e.provider.length>0&&t.set(`provider`,e.provider.join(`,`)),e.model&&e.model.length>0&&t.set(`model`,e.model.join(`,`)),e.modelKeys&&e.modelKeys.length>0&&e.model&&e.modelKeys.length===e.model.length&&t.set(`modelProvider`,e.modelKeys.map(e=>e.provider).join(`,`)),e.status&&t.set(`status`,e.status),typeof e.minCostUsd==`number`&&t.set(`minCostUsd`,String(e.minCostUsd)),typeof e.ticketId==`number`&&t.set(`ticketId`,String(e.ticketId)),typeof e.tzOffsetMinutes==`number`&&t.set(`tzOffsetMinutes`,String(e.tzOffsetMinutes)),e.sortBy&&t.set(`sortBy`,e.sortBy),t.toString()}function qt(){let{t:e}=s(`analytics`),{activeProjectId:t,projects:n}=d(),[i,o]=r(),c=n.find(e=>e.id===t),f=c?u(c):[`claude`],p=f.length>1,m=i.get(`period`)??`30d`,h=(i.get(`surface`)??``).split(`,`).filter(Boolean),g=(i.get(`provider`)??``).split(`,`).filter(Boolean),v=i.get(`ticketId`),x=(i.get(`model`)??``).split(`,`).filter(Boolean),S=(i.get(`modelProvider`)??``).split(`,`).filter(Boolean),C=x.length>0&&x.length===S.length?x.map((e,t)=>({provider:S[t],model:e})):void 0,ee=(0,Y.useMemo)(()=>-new Date().getTimezoneOffset(),[]),[w,T]=(0,Y.useState)({period:m,surface:h.length>0?h:void 0,provider:g.length>0?g:void 0,ticketId:v?Number(v):void 0,model:x.length>0?x:void 0,modelKeys:C,tzOffsetMinutes:ee}),[E,D]=(0,Y.useState)(null),[O,k]=(0,Y.useState)(!0),[A,j]=(0,Y.useState)(null),[M,N]=(0,Y.useState)({}),[P,F]=(0,Y.useState)(null),[I,te]=(0,Y.useState)(`recency`),L=(0,Y.useRef)(new Map),R=(0,Y.useRef)(0);(0,Y.useEffect)(()=>{let e=new URLSearchParams;e.set(`period`,w.period),w.surface&&w.surface.length>0&&e.set(`surface`,w.surface.join(`,`)),w.provider&&w.provider.length>0&&e.set(`provider`,w.provider.join(`,`)),w.ticketId&&e.set(`ticketId`,String(w.ticketId)),w.model&&w.model.length>0&&(e.set(`model`,w.model.join(`,`)),w.modelKeys&&w.modelKeys.length===w.model.length&&e.set(`modelProvider`,w.modelKeys.map(e=>e.provider).join(`,`))),o(e,{replace:!0})},[w.period,w.surface,w.provider,w.ticketId,w.model,w.modelKeys,o]);let z=(0,Y.useCallback)(async()=>{if(!t)return;let e=++R.current;j(null);let n=`${t}:${Kt(w)}`,r=L.current.get(n);r?(D(r),k(!1)):k(!0);try{let t=await fetch(`${l()}/spending?${Kt(w)}`);if(!t.ok)throw Error(`HTTP ${t.status}`);if(e!==R.current)return;let r=await t.json();L.current.set(n,r),D(r),k(!1)}catch(t){if(e!==R.current)return;j(t.message),k(!1)}},[t,w]),B=(0,Y.useRef)(0),V=(0,Y.useCallback)(async()=>{if(!t)return;let e=++B.current,n={...w};M.model&&(n.model=[M.model],n.modelKeys=void 0),M.status&&(n.status=M.status),typeof M.minCostUsd==`number`&&(n.minCostUsd=M.minCostUsd),n.sortBy=I;try{let t=await fetch(`${l()}/invocations?${Kt(n)}&limit=100`);if(!t.ok)throw Error(`HTTP ${t.status}`);let r=await t.json();if(e!==B.current)return;F(r)}catch{if(e!==B.current)return;F(null)}},[t,w,M,I]),ne=(0,Y.useRef)(t);(0,Y.useEffect)(()=>{ne.current!==t&&(ne.current=t,D(null),F(null),k(!0))},[t]),(0,Y.useEffect)(()=>{z()},[z]),(0,Y.useEffect)(()=>{V()},[V]);let H=(0,Y.useRef)(null),U=a();(0,Y.useEffect)(()=>{let e=`analytics-spending`;return U.registerHandler(e,e=>{let n=e;n.type===`spending.invalidated`&&n.projectId===t&&(H.current&&clearTimeout(H.current),H.current=setTimeout(()=>{L.current.clear(),z(),V()},500))}),()=>{U.unregisterHandler(e),H.current&&clearTimeout(H.current)}},[U,t,z,V]);function re(e){if(e===`all`){T(e=>({...e,surface:void 0}));return}T(t=>{let n=t.surface??[],r=n.includes(e)?n.filter(t=>t!==e):[...n,e];return{...t,surface:r.length>0?r:void 0}})}let ie=(0,Y.useCallback)((e,t)=>{T(n=>{if(n.model?.length===1&&n.model[0]===e&&(t===void 0||n.modelKeys?.length===1&&n.modelKeys[0].provider===t))return{...n,model:void 0,modelKeys:void 0};let r=(E?.byModel??[]).filter(n=>n.model===e&&(t===void 0||n.provider===t)).map(e=>({provider:e.provider,model:e.model})),i=r.length>0?r.map(e=>e.model):[e];return{...n,model:i,modelKeys:r.length>0?r:void 0}})},[E]);function ae(){T(e=>({...e,model:void 0,modelKeys:void 0}))}function oe(e){if(e===`all`){T(e=>({...e,provider:void 0}));return}T(t=>{let n=t.provider??[],r=n.includes(e)?n.filter(t=>t!==e):[...n,e];return{...t,provider:r.length>0?r:void 0}})}let W=w.surface,se=!W||W.length===0,G=w.provider,ce=!G||G.length===0,le=(0,Y.useMemo)(()=>{let e={period:w.period};return w.surface&&w.surface.length>0&&(e.surface=w.surface.join(`,`)),w.provider&&w.provider.length>0&&(e.provider=w.provider.join(`,`)),w.ticketId&&(e.ticketId=String(w.ticketId)),e},[w]),ue=E?E.summary.totalRuns===0:!1;return(0,X.jsxs)(`div`,{className:`flex flex-col gap-6 p-4 pb-12`,children:[(0,X.jsxs)(`div`,{className:`sticky top-0 z-10 -mx-4 px-4 py-3 bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/80 border-b border-border/40`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,X.jsx)(`h1`,{className:`text-base font-semibold tracking-tight`,children:e(`page.title`)}),w.ticketId&&(0,X.jsx)(`button`,{type:`button`,onClick:()=>T(e=>({...e,ticketId:void 0})),className:`inline-flex items-center gap-1 h-6 px-2 rounded-full text-[11px] font-medium bg-accent-highlight/15 text-accent-highlight ring-1 ring-accent-highlight/30 hover:bg-accent-highlight/25`,children:e(`page.ticketChip`,{id:w.ticketId})}),w.model&&w.model.length>0&&(0,X.jsxs)(`button`,{type:`button`,"data-testid":`analytics-model-chip`,onClick:ae,title:e(`page.clearModelFilter`),className:`inline-flex items-center gap-1 h-6 px-2 rounded-full text-[11px] font-medium bg-accent-highlight/15 text-accent-highlight ring-1 ring-accent-highlight/30 hover:bg-accent-highlight/25`,children:[e(`page.modelChip`,{model:w.model[0]}),(0,X.jsx)(`span`,{"aria-hidden":!0,className:`opacity-70`,children:`×`})]})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`div`,{className:`flex items-center gap-1 rounded-md border border-border/60 bg-card/40 p-0.5`,children:Wt.map(t=>(0,X.jsx)(`button`,{type:`button`,onClick:()=>T(e=>({...e,period:t.value})),className:`px-2.5 h-6 rounded text-[11px] font-medium transition-colors ${w.period===t.value?`bg-accent text-foreground`:`text-muted-foreground hover:text-foreground`}`,children:e(t.labelKey)},t.value))}),(0,X.jsx)(b,{baseUrl:`${l()}/analytics/export`,params:le,disabled:ue}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>{L.current.clear(),z(),V()},className:`h-7 w-7 inline-flex items-center justify-center rounded-md border border-border/60 bg-card/50 text-muted-foreground hover:text-foreground hover:bg-accent/60`,title:e(`common:actions.refresh`),children:(0,X.jsx)(y,{className:`w-3 h-3`})})]})]}),(0,X.jsx)(`div`,{className:`mt-3 flex flex-wrap items-center gap-1.5`,children:Gt.map(t=>(0,X.jsx)(`button`,{type:`button`,onClick:()=>re(t.value),className:`h-7 px-3 rounded-full text-[11px] font-medium transition-all ${(t.value===`all`?se:W?.includes(t.value)??!1)?`bg-foreground/10 text-foreground ring-1 ring-foreground/20`:`text-muted-foreground hover:text-foreground hover:bg-accent/40`}`,children:e(t.labelKey)},t.value))}),p&&(0,X.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-1.5`,"data-testid":`analytics-provider-chips`,children:[(0,X.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-muted-foreground/70 mr-1`,children:e(`page.engine`)}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>oe(`all`),className:`h-7 px-3 rounded-full text-[11px] font-medium transition-all ${ce?`bg-foreground/10 text-foreground ring-1 ring-foreground/20`:`text-muted-foreground hover:text-foreground hover:bg-accent/40`}`,children:e(`page.all`)}),f.map(e=>(0,X.jsx)(`button`,{type:`button`,onClick:()=>oe(e),className:`h-7 px-3 rounded-full text-[11px] font-medium transition-all ${G?.includes(e)??!1?`bg-foreground/10 text-foreground ring-1 ring-foreground/20`:`text-muted-foreground hover:text-foreground hover:bg-accent/40`}`,children:_(e)},e))]})]}),A&&(0,X.jsxs)(`div`,{className:`rounded-lg border border-accent-warning/30 bg-accent-warning/10 p-4 flex items-center justify-between`,children:[(0,X.jsx)(`p`,{className:`text-sm text-accent-warning`,children:e(`page.failedToLoad`,{error:A})}),(0,X.jsxs)(`button`,{onClick:()=>z(),className:`flex items-center gap-1.5 h-7 px-3 rounded-md text-xs text-accent-warning border border-accent-warning/30 hover:bg-accent-warning/10`,children:[(0,X.jsx)(y,{className:`w-3 h-3`}),e(`common:actions.retry`)]})]}),(0,X.jsx)(Ie,{data:E,loading:O,period:w.period}),(0,X.jsx)(He,{data:E,loading:O}),(0,X.jsx)(St,{data:E,loading:O}),(0,X.jsx)(At,{data:E,loading:O}),(0,X.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4`,children:[(0,X.jsx)(Dt,{data:E,loading:O}),(0,X.jsx)(jt,{data:E,loading:O,onSelectModel:ie,activeModel:w.model?.[0]})]}),(0,X.jsx)(Pt,{data:E,loading:O,onSelectPoint:e=>{N(e=>({...e})),T(t=>({...t,ticketId:e.ticketId??void 0}))}}),(0,X.jsx)(Ft,{data:E,loading:O,onSelectTicket:e=>T(t=>({...t,ticketId:e??void 0}))}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-end gap-1.5`,"data-testid":`analytics-table-sort`,children:[(0,X.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-muted-foreground/70 mr-1`,children:e(`table.sortLabel`)}),[`recency`,`cost`].map(t=>(0,X.jsx)(`button`,{type:`button`,"data-testid":`analytics-table-sort-${t}`,"aria-pressed":I===t,onClick:()=>te(t),className:`h-6 px-2.5 rounded-full text-[11px] font-medium transition-all ${I===t?`bg-foreground/10 text-foreground ring-1 ring-foreground/20`:`text-muted-foreground hover:text-foreground hover:bg-accent/40`}`,children:e(t===`recency`?`table.sortRecency`:`table.sortCost`)},t))]}),(0,X.jsx)(Ut,{rows:P?.rows??[],loading:O&&!P,truncated:(P?.truncated??!1)||(P?.totalAvailable??0)>(P?.rows.length??0),totalAvailable:P?.totalAvailable??0,tableFilters:M,onTableFiltersChange:N})]})]})}export{qt as default};
1
+ import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-zu2_FqZY.js";import{f as r}from"./chunk-KS7C4IRE-DEKu087k.js";import{m as i,r as a}from"./useSharedWebSocket-BOdS5_Iz.js";import{t as o}from"./Trans-SnMX4MhW.js";import{n as s,t as c}from"./createLucideIcon-Bjbbp_KS.js";import{a as l,n as u,r as d}from"./useDesktop-RSMTyy7V.js";import{n as f,r as p,t as m}from"./spending-BqbdPm_4.js";import{t as h}from"./clsx-CjueKrWZ.js";import{t as g}from"./formatDistanceToNow-DSj5DprF.js";import{r as _}from"./provider-capabilities-B-wOHfLP.js";import{Ft as v,ft as y}from"./index-m5pKr1T6.js";import{t as b}from"./ExportDropdown-ophapHrT.js";import{A as x,B as S,C,D as ee,E as w,F as T,G as E,H as D,I as O,J as k,K as A,L as j,M,N,O as P,P as F,Q as I,R as te,S as L,T as R,V as z,X as B,Z as V,_ as ne,_t as H,a as U,at as re,b as ie,c as ae,ct as oe,et as W,f as se,g as G,gt as ce,h as le,i as ue,j as de,k as fe,l as pe,lt as K,m as me,n as he,nt as ge,o as _e,ot as ve,p as ye,pt as q,q as be,r as xe,rt as Se,s as Ce,st as we,t as Te,tt as Ee,ut as J,v as De,x as Oe,y as ke,z as Ae}from"./BarChart-nBOMNfiy.js";var je=c(`arrow-down-right`,[[`path`,{d:`m7 7 10 10`,key:`1fmybs`}],[`path`,{d:`M17 7v10H7`,key:`6fjiku`}]]),Y=e(t(),1),X=n();function Me(e){return e>=100?`$${e.toFixed(0)}`:e>=10?`$${e.toFixed(1)}`:`$${e.toFixed(2)}`}function Ne(e){return e>=1e3?`$${(e/1e3).toFixed(1)}k`:`$${e.toFixed(2)}`}function Pe(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:`${e}`}var Fe=[`job`,`explore-spec`,`quick-spec`,`ai-edit`,`chat-sidebar`,`spec-launcher`,`proposal`,`agent-studio`,`setup`,`smash`,`file-summary`,`loop`];function Ie({data:e,loading:t,period:n}){let{t:r}=s(`analytics`),[i,a]=(0,Y.useState)(0),o=(0,Y.useRef)(0),c=(0,Y.useRef)(null),l=(0,Y.useRef)(0);if((0,Y.useEffect)(()=>{if(!e)return;let t=e.summary.totalCostUsd,n=++l.current;if(c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),o.current===0&&t>0){let e=performance.now(),r=i=>{if(n!==l.current)return;let o=Math.min(1,(i-e)/600),s=1-(1-o)**3;a(0+(t-0)*s),o<1?c.current=requestAnimationFrame(r):c.current=null};c.current=requestAnimationFrame(r)}else a(t);return o.current=t,()=>{c.current!==null&&(cancelAnimationFrame(c.current),c.current=null)}},[e]),t&&!e)return(0,X.jsx)(`div`,{className:`h-44 rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let u=e.summary.totalCostUsd,d=e.summary.totalRuns,h=e.summary.totalTokens,g=e.summary.totalEstimatedCostUsd??0,_=typeof e.summary.pricedRuns==`number`||typeof e.summary.unpricedRuns==`number`,v=e.summary.unpricedRuns??0,y=e.summary.pricedRuns??(_?Math.max(0,d-v):d),b=_&&d>0&&y===0&&v>0,x=y>0&&v>0,S=typeof e.summary.usageReportedRuns==`number`||typeof e.summary.usageUnavailableRuns==`number`,C=e.summary.usageUnavailableRuns??0,ee=e.summary.usageReportedRuns??(S?Math.max(0,d-C):d),w=S&&d>0&&ee===0&&C>0,T=ee>0&&C>0,E=v>0?null:e.summary.deltaPct,D=e.trackingStartedAt,O=g>0,k=e.bySurface.map(e=>e.surface).filter(e=>!Fe.includes(e)),A=[...Fe,...k].map(t=>{let n=e.bySurface.find(e=>e.surface===t);return{surface:t,costUsd:n?.costUsd??0,count:n?.count??0}}),j=n?r(`windowLabels.${n}`):null;return(0,X.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-gradient-to-br from-card/80 to-card/40 p-5`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-end justify-between gap-3 mb-4`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`div`,{className:`text-[11px] uppercase tracking-wider text-muted-foreground mb-1 flex items-center gap-1.5`,children:[(0,X.jsx)(`span`,{children:r(`hero.spending`)}),j&&(0,X.jsxs)(`span`,{"data-testid":`hero-window-label`,className:`normal-case tracking-normal text-muted-foreground/70 font-normal`,children:[`· `,j]})]}),(0,X.jsxs)(`div`,{className:`flex items-baseline gap-3`,children:[(0,X.jsx)(`div`,{className:`text-5xl font-semibold tabular-nums tracking-tight`,"data-testid":b?`hero-cost-unavailable`:void 0,title:b?r(`hero.costUnavailableTooltip`):void 0,children:b?`—`:Ne(i)}),E!==null&&(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 text-xs font-medium ${E>=0?`text-accent-warning`:`text-accent-success`}`,children:[E>=0?(0,X.jsx)(p,{className:`w-3 h-3`}):(0,X.jsx)(je,{className:`w-3 h-3`}),r(`hero.vsPrev`,{pct:Math.abs(E).toFixed(0)})]})]}),(0,X.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-1 tabular-nums flex items-center gap-2`,children:[(0,X.jsx)(`span`,{children:r(`hero.invocations`,{count:d})}),w?(0,X.jsx)(`span`,{"data-testid":`hero-usage-unavailable`,className:`text-muted-foreground/80 italic`,title:r(`hero.usageUnavailableTooltip`),children:r(`hero.usageUnavailable`)}):T&&h!=null?(0,X.jsx)(`span`,{className:`text-muted-foreground/80 italic`,title:r(`hero.usagePartiallyUnavailableTooltip`),children:r(`hero.usagePartiallyUnavailable`,{tokens:Pe(h),count:C})}):h!=null&&h>0?(0,X.jsx)(`span`,{className:`text-muted-foreground/80`,title:r(`hero.tokensTooltip`),children:r(`hero.tokens`,{tokens:Pe(h)})}):null,b&&(0,X.jsx)(`span`,{className:`text-muted-foreground/80 italic`,title:r(`hero.costUnavailableTooltip`),children:r(`hero.costUnavailable`)}),x&&(0,X.jsx)(`span`,{"data-testid":`hero-cost-partial`,className:`text-muted-foreground/80 italic`,title:r(`hero.costPartiallyUnavailableTooltip`),children:r(`hero.costPartiallyUnavailable`,{count:v})}),O&&(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground/70 italic`,title:r(`hero.includesEstimatedTooltip`,{amount:Me(g)}),children:r(`hero.includesEstimated`,{amount:Me(g)})})]})]}),d===0&&D&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:r(`hero.trackingStarted`,{date:D.slice(0,10)})})]}),d===0?(0,X.jsxs)(`div`,{className:`rounded-lg border border-dashed border-border/40 p-6 text-center`,children:[(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:r(`hero.emptyState`)}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground/70 mt-1`,children:D?r(`hero.trackingStarted`,{date:D.slice(0,10)}):r(`hero.trackingStartedFallback`)})]}):b?(0,X.jsx)(`div`,{className:`rounded-lg border border-dashed border-border/40 p-4 text-xs text-muted-foreground/80`,children:r(`hero.costUnavailableTooltip`)}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`h-3 w-full rounded-full overflow-hidden bg-background-deep flex`,children:A.map(e=>{let t=u>0?e.costUsd/u*100:0;return t===0?null:(0,X.jsx)(`div`,{className:`h-full ${m[e.surface].dot}`,style:{width:`${t}%`},title:r(`hero.segmentTitle`,{label:f[e.surface],value:Me(e.costUsd)})},e.surface)})}),(0,X.jsx)(`div`,{className:`mt-3 flex flex-wrap items-center gap-x-5 gap-y-1.5 text-xs`,children:A.filter(e=>e.costUsd>0).map(e=>(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 tabular-nums`,children:[(0,X.jsx)(`span`,{className:`w-2 h-2 rounded-full ${m[e.surface].dot}`}),(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:f[e.surface]}),(0,X.jsx)(`span`,{className:`text-foreground font-medium`,children:Me(e.costUsd)}),(0,X.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,X.jsx)(`span`,{className:`text-muted-foreground/80`,children:e.count})]},e.surface))})]})]})}var Le={claude:`Claude`,codex:`Codex`,gemini:`Gemini`,kimi:`Kimi`},Re={claude:`bg-accent-info`,codex:`bg-accent-highlight`,gemini:`bg-accent-success`,kimi:`bg-purple-400`};function ze(e){return e>=100?`$${e.toFixed(0)}`:e>=10?`$${e.toFixed(1)}`:e>=.01?`$${e.toFixed(2)}`:`$${e.toFixed(4)}`}function Be(e){return Le[e]??e}function Ve(e){return Re[e]??`bg-accent-secondary`}function He({data:e,loading:t}){let{t:n}=s(`analytics`);if(t&&!e)return(0,X.jsx)(`div`,{className:`h-32 rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e||e.byProvider.length===0||e.byProvider.length===1)return null;let r=e.byProvider.reduce((e,t)=>e+t.costUsd+t.estimatedCostUsd,0),i=e.byProvider.some(e=>typeof e.unpricedCount==`number`?e.unpricedCount>0:e.count>0&&e.costUsd===0&&e.estimatedCostUsd===0);return(0,X.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,X.jsx)(`div`,{className:`flex items-baseline justify-between mb-3`,children:(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`text-[11px] uppercase tracking-wider text-muted-foreground`,children:n(`providerCard.title`)}),(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground/70 mt-0.5`,children:(0,X.jsx)(o,{ns:`analytics`,i18nKey:`providerCard.description`,components:{tilde:(0,X.jsx)(`span`,{className:`font-medium`})}})})]})}),r===0&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:n(i?`providerCard.costUnavailableTooltip`:`providerCard.noCost`)}),r>0&&(0,X.jsx)(X.Fragment,{children:(0,X.jsx)(`div`,{className:`h-2 w-full rounded-full overflow-hidden bg-background-deep flex mb-3`,children:e.byProvider.map(e=>{let t=e.costUsd+e.estimatedCostUsd,i=r>0?t/r*100:0;if(i===0)return null;let a=`${e.costUsd===0&&e.estimatedCostUsd>0?`~`:``}${ze(t)}`;return(0,X.jsx)(`div`,{className:`h-full ${Ve(e.provider)}`,style:{width:`${i}%`},title:n(`providerCard.segmentTitle`,{label:Be(e.provider),value:a,count:e.count})},e.provider)})})}),(0,X.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2 ${r>0?``:`mt-3`}`,children:e.byProvider.map(e=>(0,X.jsx)(Ue,{entry:e},e.provider))})]})}function Ue({entry:e}){let{t}=s(`analytics`),n=e.costUsd+e.estimatedCostUsd,r=e.costUsd===0&&e.estimatedCostUsd>0,i=e.unpricedCount??(e.count>0&&e.costUsd===0&&e.estimatedCostUsd===0?e.count:0),a=e.pricedCount??Math.max(0,e.count-i),o=e.count>0&&i>0&&a===0,c=a>0&&i>0;return(0,X.jsxs)(`div`,{className:`flex items-center gap-2.5 rounded-md border border-border/30 px-2.5 py-1.5`,children:[(0,X.jsx)(`span`,{className:`w-2 h-2 rounded-full shrink-0 ${Ve(e.provider)}`}),(0,X.jsx)(`span`,{className:`text-xs font-medium`,children:Be(e.provider)}),(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:t(`runs`,{count:e.count})}),o?(0,X.jsx)(`span`,{className:`ml-auto text-xs font-medium text-muted-foreground/80 italic`,title:t(`providerCard.costUnavailableTooltip`),children:t(`providerCard.costUnavailable`)}):(0,X.jsxs)(`span`,{className:`ml-auto text-xs font-medium tabular-nums`,title:c?t(`providerCard.costPartiallyUnavailableTooltip`):void 0,children:[r?`~`:``,ze(n),c&&(0,X.jsx)(`span`,{className:`ml-1 font-normal text-muted-foreground/80 italic`,children:t(`providerCard.costPartiallyUnavailable`,{count:i})})]})]})}var We=[`option`,`isActive`];function Z(){return Z=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},Z.apply(null,arguments)}function Ge(e,t){if(e==null)return{};var n,r,i=Ke(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function Ke(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}function qe(e){var{option:t,isActive:n}=e,r=Ge(e,We);return typeof t==`string`?Y.createElement(L,Z({option:Y.createElement(we,Z({type:t},r)),isActive:n,shapeType:`symbols`},r)):Y.createElement(L,Z({option:t,isActive:n,shapeType:`symbols`},r))}var Je=W([(e,t,n,r,i,a,o)=>te(e,void 0,void 0,o),(e,t,n,r,i,a,o)=>N(e,`xAxis`,t,o),(e,t,n,r,i,a,o)=>F(e,`xAxis`,t,o),(e,t,n,r,i,a,o)=>N(e,`yAxis`,n,o),(e,t,n,r,i,a,o)=>F(e,`yAxis`,n,o),(e,t,n,r)=>O(e,`zAxis`,r,!1),W([T,(e,t,n,r,i)=>i],(e,t)=>e.filter(e=>e.type===`scatter`).find(e=>e.id===t)),(e,t,n,r,i,a)=>a],(e,t,n,r,i,a,o,s)=>{var{chartData:c,dataStartIndex:l,dataEndIndex:u}=e;if(o!=null){var d=o?.data!=null&&o.data.length>0?o.data:c?.slice(l,u+1);if(!(d==null||t==null||r==null||n==null||i==null||n?.length===0||i?.length===0))return ut({displayedData:d,xAxis:t,yAxis:r,zAxis:a,scatterSettings:o,xAxisTicks:n,yAxisTicks:i,cells:s})}}),Ye=[`id`],Xe=[`onMouseEnter`,`onClick`,`onMouseLeave`],Ze=[`animationBegin`,`animationDuration`,`animationEasing`,`hide`,`isAnimationActive`,`legendType`,`lineJointType`,`lineType`,`shape`,`xAxisId`,`yAxisId`,`zAxisId`];function Qe(e,t){if(e==null)return{};var n,r,i=$e(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function $e(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}function Q(){return Q=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},Q.apply(null,arguments)}function et(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function $(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?et(Object(n),!0).forEach(function(t){tt(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):et(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function tt(e,t,n){return(t=nt(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function nt(e){var t=rt(e,`string`);return typeof t==`symbol`?t:t+``}function rt(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}var it=e=>{var{dataKey:t,name:n,fill:r,legendType:i,hide:a}=e;return[{inactive:a,dataKey:t,type:i,color:r,value:V(n,t),payload:e}]},at=Y.memo(e=>{var{dataKey:t,points:n,stroke:r,strokeWidth:i,fill:a,name:o,hide:s,tooltipType:c,id:l}=e,u={dataDefinedOnItem:n?.map(e=>e.tooltipPayload),getPosition:e=>{var t;return n==null||(t=n[Number(e)])==null?void 0:t.tooltipPosition},settings:{stroke:r,strokeWidth:i,fill:a,nameKey:void 0,dataKey:t,name:V(o,t),hide:s,type:c,color:a,unit:``,graphicalItemId:l}};return Y.createElement(De,{tooltipEntrySettings:u})});function ot(e){var{points:t,props:n}=e,{line:r,lineType:i,lineJointType:a}=n;if(!r)return null;var o=ce(n),s=H(r),c,l;if(i===`joint`)c=t.map(e=>({x:e.cx??null,y:e.cy??null}));else if(i===`fitting`){var{xmin:u,xmax:d,a:f,b:p}=oe(t),m=e=>f*e+p;c=[{x:u,y:m(u)},{x:d,y:m(d)}]}var h=$($($({},o),{},{fill:`none`,stroke:o&&o.fill},s),{},{points:c});return l=Y.isValidElement(r)?Y.cloneElement(r,h):typeof r==`function`?r(h):Y.createElement(z,Q({},h,{type:a})),Y.createElement(q,{className:`recharts-scatter-line`,key:`recharts-scatter-line`},l)}function st(e){var{showLabels:t,points:n,children:r}=e,i=E(),a=(0,Y.useMemo)(()=>n?.map(e=>{var t={x:e.x??0,y:e.y??0,width:e.width,height:e.height,lowerWidth:e.width,upperWidth:e.width};return $($({},t),{},{value:void 0,payload:e.payload,viewBox:t,parentViewBox:i,fill:void 0})}),[i,n]);return Y.createElement(R,{value:t?a:void 0},r)}function ct(e){var{points:t,allOtherScatterProps:n}=e,{shape:r,activeShape:i,dataKey:a}=n,{id:o}=n,s=Qe(n,Ye),c=ge(de),{onMouseEnter:l,onClick:u,onMouseLeave:d}=n,f=Qe(n,Xe),p=ie(l,a,o),m=Oe(d),h=ke(u,a,o);if(!ve(t))return null;var g=ce(s);return Y.createElement(Y.Fragment,null,Y.createElement(ot,{points:t,props:s}),t.map((e,t)=>{var n=i!=null&&i!==!1,a=n&&c===String(t),s=n&&a?i:r,l=$($($({},g),e),{},{index:t,[k]:String(o)});return Y.createElement(x,{key:`symbol-${e?.cx}-${e?.cy}-${e?.size}-${t}`,zIndex:a?j.activeDot:void 0},Y.createElement(q,Q({className:`recharts-scatter-symbol`},re(f,e,t),{onMouseEnter:p(e,t),onMouseLeave:m(e,t),onClick:h(e,t)}),Y.createElement(qe,Q({option:s,isActive:a},l))))}))}function lt(e){var{previousPointsRef:t,props:n}=e,{points:r,isAnimationActive:i,animationBegin:a,animationDuration:o,animationEasing:s}=n,c=t.current,l=Ae(n,`recharts-scatter-`),[u,d]=(0,Y.useState)(!1),f=(0,Y.useCallback)(()=>{d(!1)},[]),p=(0,Y.useCallback)(()=>{d(!0)},[]),m=!u;return Y.createElement(st,{showLabels:m,points:r},n.children,Y.createElement(S,{animationId:l,begin:a,duration:o,isActive:i,easing:s,onAnimationEnd:f,onAnimationStart:p,key:l},e=>{var i=e===1?r:r?.map((t,n)=>{var r=c&&c[n];return r?$($({},t),{},{cx:t.cx==null?void 0:K(r.cx,t.cx,e),cy:t.cy==null?void 0:K(r.cy,t.cy,e),size:K(r.size,t.size,e)}):$($({},t),{},{size:K(0,t.size,e)})});return e>0&&(t.current=i),Y.createElement(q,null,Y.createElement(ct,{points:i,allOtherScatterProps:n,showLabels:m}))}),Y.createElement(w,{label:n.label}))}function ut(e){var{displayedData:t,xAxis:n,yAxis:r,zAxis:i,scatterSettings:a,xAxisTicks:o,yAxisTicks:s,cells:c}=e,l=J(n.dataKey)?a.dataKey:n.dataKey,u=J(r.dataKey)?a.dataKey:r.dataKey,d=i&&i.dataKey,f=i?i.range:M.range,p=f&&f[0],m=n.scale.bandwidth?n.scale.bandwidth():0,h=r.scale.bandwidth?r.scale.bandwidth():0;return t.map((e,t)=>{var f=I(e,l),g=I(e,u),_=!J(d)&&I(e,d)||`-`,v=[{name:J(n.dataKey)?a.name:n.name||String(n.dataKey),unit:n.unit||``,value:f,payload:e,dataKey:l,type:a.tooltipType,graphicalItemId:a.id},{name:J(r.dataKey)?a.name:r.name||String(r.dataKey),unit:r.unit||``,value:g,payload:e,dataKey:u,type:a.tooltipType,graphicalItemId:a.id}];_!==`-`&&i!=null&&v.push({name:i.name||i.dataKey,unit:i.unit||``,value:_,payload:e,dataKey:d,type:a.tooltipType,graphicalItemId:a.id});var y=B({axis:n,ticks:o,bandSize:m,entry:e,index:t,dataKey:l}),b=B({axis:r,ticks:s,bandSize:h,entry:e,index:t,dataKey:u}),x=_!==`-`&&i!=null?i.scale.map(_):p,S=x==null?0:Math.sqrt(Math.max(x,0)/Math.PI);return $($({},e),{},{cx:y,cy:b,x:y==null?void 0:y-S,y:b==null?void 0:b-S,width:2*S,height:2*S,size:x,node:{x:f,y:g,z:_},tooltipPayload:v,tooltipPosition:{x:y,y:b},payload:e},c&&c[t]&&c[t].props)})}var dt=(e,t,n)=>({x:e.cx,y:e.cy,value:Number(n===`x`?e.node.x:e.node.y),errorVal:I(e,t)});function ft(e){var{hide:t,points:n,className:r,needClip:i,xAxisId:a,yAxisId:o,id:s}=e,c=(0,Y.useRef)(null);if(t)return null;var l=h(`recharts-scatter`,r),u=s;return Y.createElement(x,{zIndex:e.zIndex},Y.createElement(q,{className:l,clipPath:i?`url(#clipPath-${u})`:void 0,id:s},i&&Y.createElement(`defs`,null,Y.createElement(_e,{clipPathId:u,xAxisId:a,yAxisId:o})),Y.createElement(ae,{xAxisId:a,yAxisId:o,data:n,dataPointFormatter:dt,errorBarOffset:0},Y.createElement(q,{key:`recharts-scatter-symbols`},Y.createElement(lt,{props:e,previousPointsRef:c})))))}var pt={xAxisId:0,yAxisId:0,zAxisId:0,label:!1,line:!1,legendType:`circle`,lineType:`joint`,lineJointType:`linear`,shape:`circle`,hide:!1,isAnimationActive:`auto`,animationBegin:0,animationDuration:400,animationEasing:`linear`,zIndex:j.scatter};function mt(e){var t=Se(e,pt),{animationBegin:n,animationDuration:r,animationEasing:i,hide:a,isAnimationActive:o,legendType:s,lineJointType:c,lineType:l,shape:u,xAxisId:d,yAxisId:f,zAxisId:p}=t,m=Qe(t,Ze),{needClip:h}=Ce(d,f),g=(0,Y.useMemo)(()=>C(e.children,ee),[e.children]),_=be(),v=ge(t=>Je(t,d,f,p,e.id,g,_));return h==null||v==null?null:Y.createElement(Y.Fragment,null,Y.createElement(at,{dataKey:e.dataKey,points:v,stroke:e.stroke,strokeWidth:e.strokeWidth,fill:e.fill,name:e.name,hide:e.hide,tooltipType:e.tooltipType,id:e.id}),Y.createElement(ft,Q({},m,{xAxisId:d,yAxisId:f,zAxisId:p,lineType:l,lineJointType:c,legendType:s,shape:u,hide:a,isAnimationActive:o,animationBegin:n,animationDuration:r,animationEasing:i,points:v,needClip:h})))}function ht(e){var t=Se(e,pt),n=be();return Y.createElement(G,{id:t.id,type:`scatter`},e=>Y.createElement(Y.Fragment,null,Y.createElement(ne,{legendPayload:it(t)}),Y.createElement(le,{type:`scatter`,id:e,data:t.data,xAxisId:t.xAxisId,yAxisId:t.yAxisId,zAxisId:t.zAxisId,dataKey:t.dataKey,hide:t.hide,name:t.name,tooltipType:t.tooltipType,isPanorama:n}),Y.createElement(mt,Q({},t,{id:e}))))}var gt=Y.memo(ht,D);gt.displayName=`Scatter`;function _t(e){var t=Ee(),n=(0,Y.useRef)(null);return(0,Y.useLayoutEffect)(()=>{n.current===null?t(se(e)):n.current!==e&&t(me({prev:n.current,next:e})),n.current=e},[e,t]),(0,Y.useLayoutEffect)(()=>()=>{n.current&&=(t(ye(n.current)),null)},[t]),null}var vt={zAxisId:0,range:M.range,scale:M.scale,type:M.type};function yt(e){var t=Se(e,vt);return Y.createElement(_t,{domain:t.domain,id:t.zAxisId,dataKey:t.dataKey,name:t.name,unit:t.unit,range:t.range,scale:t.scale,type:t.type,allowDuplicatedCategory:M.allowDuplicatedCategory,allowDataOverflow:M.allowDataOverflow,reversed:M.reversed,includeHidden:M.includeHidden})}yt.displayName=`ZAxis`;var bt=[`item`],xt=(0,Y.forwardRef)((e,t)=>Y.createElement(he,{chartName:`ScatterChart`,defaultTooltipEventType:`item`,validateTooltipEventTypes:bt,tooltipPayloadSearcher:fe,categoricalChartProps:e,ref:t}));function St({data:e,loading:t}){let{t:n}=s(`analytics`);if(t&&!e)return(0,X.jsx)(`div`,{className:`h-[220px] rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let r={jobs:n(`surfaces.job`),explore:n(`surfaces.exploreSpec`),quick:n(`surfaces.quickSpec`),refine:n(`surfaces.aiEdit`),fileSummaries:n(`surfaces.fileSummary`),smash:n(`surfaces.smash`),loop:n(`surfaces.loop`)},i=e.dailyTimeline.map(e=>({date:e.date.slice(5),[r.jobs]:e.jobsCostUsd,[r.explore]:e.exploreCostUsd,[r.quick]:e.quickCostUsd,[r.refine]:e.aiEditCostUsd,[r.fileSummaries]:e.fileSummaryCostUsd??0,[r.smash]:e.smashCostUsd??0,[r.loop]:e.loopCostUsd??0})),a=e.dailyTimeline.every(e=>e.jobsCostUsd+e.exploreCostUsd+e.quickCostUsd+e.aiEditCostUsd+(e.fileSummaryCostUsd??0)+(e.smashCostUsd??0)+(e.loopCostUsd??0)===0),o=e.dailyTimeline.reduce((e,t)=>e+(t.unpricedCount??0),0),c=a&&o>0,l=!a&&o>0;return(0,X.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,X.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider`,children:n(`timeline.title`)}),(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground/70`,children:l?n(`timeline.costPartiallyUnavailable`,{count:o}):n(`timeline.subtitle`)})]}),c?(0,X.jsx)(`div`,{"data-testid":`timeline-cost-unavailable`,className:`h-40 flex items-center justify-center text-xs text-muted-foreground/70`,children:n(`timeline.costUnavailable`)}):a?(0,X.jsx)(`div`,{className:`h-40 flex items-center justify-center text-xs text-muted-foreground/70`,children:n(`timeline.empty`)}):(0,X.jsx)(`div`,{className:`h-[220px]`,children:(0,X.jsx)(A,{width:`100%`,height:`100%`,children:(0,X.jsxs)(Te,{data:i,margin:{top:10,right:10,left:-8,bottom:0},children:[(0,X.jsx)(pe,{strokeDasharray:`2 4`,stroke:`currentColor`,className:`text-border/30`,vertical:!1}),(0,X.jsx)(ue,{dataKey:`date`,tick:{fontSize:10},stroke:`currentColor`,className:`text-muted-foreground`}),(0,X.jsx)(xe,{tick:{fontSize:10},stroke:`currentColor`,className:`text-muted-foreground`,tickFormatter:e=>`$${e}`}),(0,X.jsx)(P,{contentStyle:{backgroundColor:`var(--popover)`,border:`1px solid var(--border)`,fontSize:11,borderRadius:6},formatter:(e,t)=>[`$${typeof e==`number`?e.toFixed(2):`—`}`,String(t)]}),(0,X.jsx)(U,{dataKey:r.jobs,stackId:`a`,fill:`var(--accent-info, #5fa8d3)`}),(0,X.jsx)(U,{dataKey:r.explore,stackId:`a`,fill:`var(--accent-highlight, #c084fc)`}),(0,X.jsx)(U,{dataKey:r.quick,stackId:`a`,fill:`var(--accent-secondary, #f7768e)`}),(0,X.jsx)(U,{dataKey:r.refine,stackId:`a`,fill:`var(--accent-success, #50fa7b)`}),(0,X.jsx)(U,{dataKey:r.fileSummaries,stackId:`a`,fill:`var(--accent-warning, #f1fa8c)`}),(0,X.jsx)(U,{dataKey:r.smash,stackId:`a`,fill:`var(--accent-highlight, #c084fc)`}),(0,X.jsx)(U,{dataKey:r.loop,stackId:`a`,fill:`var(--accent-primary, #7aa2f7)`})]})})})]})}function Ct(e){return e==null?`—`:e<.005?`$${e.toFixed(4)}`:e<1?`$${e.toFixed(3)}`:`$${e.toFixed(2)}`}function wt(e){return e==null?`—`:e<1e3?`${e} ms`:e<6e4?`${(e/1e3).toFixed(1)}s`:`${Math.floor(e/6e4)}m ${Math.floor(e%6e4/1e3)}s`}function Tt({values:e}){let t=Math.max(1e-4,...e);return(0,X.jsx)(`div`,{className:`flex items-end gap-[1px] h-5`,children:e.map((e,n)=>(0,X.jsx)(`div`,{className:`w-[3px] rounded-sm bg-foreground/40`,style:{height:`${Math.max(2,e/t*20)}px`}},n))})}function Et({mode:e,label:t,accentClass:n}){let{t:r}=s(`analytics`),i=e.mode===`explore`&&e.totalRuns<5,a=(e.estimatedCostUsd??0)>0,c=e.avgCostPerSpec==null&&(e.unpricedCount??0)>0;return(0,X.jsxs)(`div`,{className:`flex-1 p-4 first:pr-2 last:pl-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,X.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full ${n}`}),(0,X.jsx)(`span`,{className:`text-xs font-medium uppercase tracking-wider text-muted-foreground`,children:t})]}),i?(0,X.jsxs)(`div`,{className:`py-3`,children:[(0,X.jsx)(`p`,{className:`text-sm text-foreground`,children:r(`quickVsExplore.sparseCta`)}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:r(`quickVsExplore.runsSoFar`,{count:e.totalRuns})})]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`text-3xl font-semibold tabular-nums tracking-tight`,"data-estimated":a?`true`:void 0,title:c?r(`quickVsExplore.costUnavailableTooltip`):a?r(`quickVsExplore.estimatedTooltip`):void 0,children:[a&&e.avgCostPerSpec!=null?`~`:``,Ct(e.avgCostPerSpec)]}),(0,X.jsx)(`div`,{className:`text-[11px] text-muted-foreground mt-0.5`,children:r(c?`quickVsExplore.costUnavailable`:`quickVsExplore.perSpec`)}),(0,X.jsx)(`div`,{className:`mt-3`,children:(0,X.jsx)(Tt,{values:e.sparkline.length>0?e.sparkline:[0]})}),(0,X.jsxs)(`div`,{className:`mt-3 space-y-0.5 text-xs tabular-nums text-muted-foreground`,children:[(0,X.jsx)(`div`,{children:(0,X.jsx)(o,{ns:`analytics`,i18nKey:`quickVsExplore.createdRuns`,values:{created:e.ticketsCreated,runs:e.totalRuns},components:{strong:(0,X.jsx)(`span`,{className:`text-foreground font-medium`})}})}),(0,X.jsx)(`div`,{children:r(`quickVsExplore.avgDuration`,{duration:wt(e.avgDurationMs)})}),(0,X.jsx)(`div`,{className:`truncate`,children:e.dominantModel??`—`})]})]})]})}function Dt({data:e,loading:t}){let{t:n}=s(`analytics`);if(t&&!e)return(0,X.jsx)(`div`,{className:`h-[220px] rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let r=e.byMode.find(e=>e.mode===`quick`),i=e.byMode.find(e=>e.mode===`explore`);if(!r||!i)return null;let a=r.avgCostPerSpec&&i.avgCostPerSpec&&r.avgCostPerSpec>0?i.avgCostPerSpec/r.avgCostPerSpec:null,o=a!==null&&r.totalRuns>=1&&i.totalRuns>=5,c=(r.estimatedCostUsd??0)>0||(i.estimatedCostUsd??0)>0;return(0,X.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40`,children:[(0,X.jsx)(`div`,{className:`px-4 pt-3 pb-1`,children:(0,X.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider`,children:n(`quickVsExplore.title`)})}),(0,X.jsxs)(`div`,{className:`flex divide-x divide-border/40`,children:[(0,X.jsx)(Et,{mode:r,label:n(`quickVsExplore.quick`),accentClass:`bg-accent-secondary`}),(0,X.jsx)(Et,{mode:i,label:n(`quickVsExplore.explore`),accentClass:`bg-accent-highlight`})]}),o&&(0,X.jsx)(`div`,{className:`px-4 pb-3 -mt-1`,children:(0,X.jsx)(`div`,{className:`text-center text-[11px] text-muted-foreground tabular-nums`,children:(0,X.jsxs)(`span`,{className:`px-2`,children:[`━━━━━━ `,n(`quickVsExplore.ratio`,{ratio:a.toFixed(1)}),` ━━━━━━`]})})}),c&&(0,X.jsx)(`div`,{className:`px-4 pb-3 -mt-1`,"data-testid":`quick-vs-explore-estimated-footnote`,children:(0,X.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:n(`quickVsExplore.estimatedFootnote`)})})]})}function Ot(e){return e<.005&&e>0?`$${e.toFixed(4)}`:e<1?`$${e.toFixed(3)}`:`$${e.toFixed(2)}`}function kt(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function At({data:e,loading:t}){let{t:n}=s(`analytics`),r=e?.agentMissions;if(t||!r||r.summary.turns===0)return null;let{summary:a,topConversations:o}=r,c=a.estimatedCostUsd>0,l=a.prevTotalCostUsd>0?(a.totalCostUsd-a.prevTotalCostUsd)/a.prevTotalCostUsd*100:null;return(0,X.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card p-4`,"data-testid":`agent-missions-card`,children:[(0,X.jsxs)(`div`,{className:`mb-3 flex items-center gap-2`,children:[(0,X.jsx)(v,{className:`h-4 w-4 text-accent-highlight`}),(0,X.jsx)(`h3`,{className:`text-sm font-medium`,children:n(`agentMissions.title`)}),(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:n(`agentMissions.subtitle`)})]}),(0,X.jsxs)(`div`,{className:`flex items-baseline gap-3`,children:[(0,X.jsxs)(`span`,{className:`text-3xl font-semibold tabular-nums tracking-tight`,"data-estimated":c?`true`:void 0,title:c?n(`agentMissions.estimatedNote`):void 0,children:[c?`~`:``,Ot(a.totalCostUsd)]}),l!==null&&(0,X.jsxs)(`span`,{className:l>0?`text-xs text-accent-warning`:`text-xs text-accent-success`,children:[l>0?`+`:``,l.toFixed(0),`% `,n(`agentMissions.vsPrev`)]})]}),(0,X.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:n(`agentMissions.turnsAndTokens`,{turns:a.turns,tokens:kt(a.tokensIn+a.tokensOut)})}),o.length>0&&(0,X.jsx)(`ul`,{className:`mt-3 space-y-1 border-t border-border/40 pt-2`,children:o.map(e=>(0,X.jsxs)(`li`,{className:`flex items-center gap-2 text-xs`,children:[(0,X.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-foreground/85`,children:e.title?.trim()||n(`agentMissions.untitled`)}),(0,X.jsxs)(`span`,{className:`shrink-0 text-[10px] text-muted-foreground`,children:[e.turns,` · `,e.lastAt?g(new Date(e.lastAt),{addSuffix:!0,locale:i()}):`—`]}),(0,X.jsxs)(`span`,{className:`shrink-0 tabular-nums font-medium`,children:[e.estimatedCostUsd>0?`~`:``,Ot(e.costUsd)]})]},e.conversationId??`unknown`))})]})}function jt({data:e,loading:t,onSelectModel:n,activeModel:r}){let{t:i}=s(`analytics`);if(t&&!e)return(0,X.jsx)(`div`,{className:`h-[220px] rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let a=e.summary.totalCostUsd,o=e.byModel.slice(0,5),c=o.reduce((e,t)=>e+t.costUsd,0),l=Math.max(0,a-c),u=l>=.005;return(0,X.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,X.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider mb-3`,children:i(`models.title`)}),o.length===0?(0,X.jsx)(`div`,{className:`h-32 flex items-center justify-center text-xs text-muted-foreground/70`,children:i(`models.empty`)}):(0,X.jsxs)(`ul`,{className:`space-y-1.5`,children:[o.map(e=>{let t=a>0?e.costUsd/a*100:0,o=r===e.model,s=(e.estimatedCostUsd??0)>0,c=e.unpricedCount??0,l=Math.max(0,e.count-c),u=e.count>0&&c>0&&l===0,d=l>0&&c>0;return(0,X.jsx)(`li`,{children:(0,X.jsxs)(`button`,{type:`button`,onClick:()=>n(e.model,e.provider),className:`w-full text-left group rounded-md px-2 py-1.5 transition-colors ${o?`bg-accent-highlight/10 ring-1 ring-accent-highlight/30`:`hover:bg-accent/30`}`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between text-[12px] mb-1 tabular-nums`,children:[(0,X.jsx)(`span`,{className:`truncate font-medium`,children:e.model}),(0,X.jsx)(`span`,{className:`text-muted-foreground`,"data-testid":u?`model-cost-unavailable`:void 0,title:u?i(`models.costUnavailableTooltip`):d?i(`models.costPartiallyUnavailableTooltip`):s?i(`models.estimatedTooltip`):void 0,children:u?i(`models.costUnavailableWithRuns`,{count:e.count}):(0,X.jsxs)(X.Fragment,{children:[s?`~`:``,`$`,e.costUsd.toFixed(2),` · `,e.count,d&&(0,X.jsx)(`span`,{className:`ml-1 italic`,children:i(`models.costPartiallyUnavailable`,{count:c})})]})})]}),(0,X.jsx)(`div`,{className:`h-1.5 rounded-full bg-background-deep overflow-hidden`,children:(0,X.jsx)(`div`,{className:`h-full ${o?`bg-accent-highlight`:`bg-foreground/40 group-hover:bg-foreground/60`} transition-colors`,style:{width:`${t}%`}})})]})},`${e.provider??`claude`}:${e.model}`)}),u&&(0,X.jsx)(`li`,{"data-testid":`model-others`,children:(0,X.jsxs)(`div`,{className:`w-full rounded-md px-2 py-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between text-[12px] mb-1 tabular-nums`,children:[(0,X.jsx)(`span`,{className:`truncate font-medium text-muted-foreground`,children:i(`models.others`)}),(0,X.jsxs)(`span`,{className:`text-muted-foreground`,children:[`$`,l.toFixed(2)]})]}),(0,X.jsx)(`div`,{className:`h-1.5 rounded-full bg-background-deep overflow-hidden`,children:(0,X.jsx)(`div`,{className:`h-full bg-foreground/25`,style:{width:`${a>0?l/a*100:0}%`}})})]})})]})]})}var Mt={job:`var(--accent-info, #5fa8d3)`,"quick-spec":`var(--accent-secondary, #f7768e)`,"explore-spec":`var(--accent-highlight, #c084fc)`,"ai-edit":`var(--accent-success, #50fa7b)`,smash:`var(--accent-highlight, #c084fc)`,"file-summary":`var(--accent-warning, #f1fa8c)`,loop:`var(--accent-primary, #7aa2f7)`,"chat-sidebar":`var(--accent-info, #5fa8d3)`,"spec-launcher":`var(--accent-secondary, #f7768e)`,proposal:`var(--accent-highlight, #c084fc)`,"agent-studio":`var(--accent-success, #50fa7b)`,setup:`var(--accent-primary, #7aa2f7)`},Nt=Object.keys(f);function Pt({data:e,loading:t,onSelectPoint:n}){let{t:r}=s(`analytics`);if(t&&!e)return(0,X.jsx)(`div`,{className:`h-[260px] rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let i=Nt,a=i.map(t=>({surface:t,points:e.scatter.filter(e=>e.surface===t).map(e=>({id:e.id,x:e.numTurns??Math.round((e.durationMs??0)/1e3),y:e.costUsd,surface:t,ticketId:e.ticketId,startedAt:e.startedAt,raw:e}))})),o=e.scatter.length===0,c=e.summary.unpricedRuns??0,l=o&&c>0,u=!o&&c>0,d=e.scatterTruncated===!0,p=e.scatterTotal??e.scatter.length;return(0,X.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,X.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider`,children:r(`scatter.title`)}),(0,X.jsx)(`div`,{className:`flex flex-wrap items-center gap-2 text-[10px]`,children:i.map(e=>(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,X.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full`,style:{background:Mt[e]}}),(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:f[e]})]},e))})]}),d&&!o&&(0,X.jsx)(`div`,{"data-testid":`scatter-truncation-notice`,className:`mb-2 text-[10px] text-accent-warning`,children:r(`scatter.truncated`,{shown:e.scatter.length,total:p})}),u&&(0,X.jsx)(`div`,{"data-testid":`scatter-cost-partial-notice`,className:`mb-2 text-[10px] text-muted-foreground/80 italic`,children:r(`scatter.costPartiallyUnavailable`,{count:c})}),l?(0,X.jsx)(`div`,{"data-testid":`scatter-cost-unavailable`,className:`h-40 flex items-center justify-center text-xs text-muted-foreground/70`,children:r(`scatter.costUnavailable`)}):o?(0,X.jsx)(`div`,{className:`h-40 flex items-center justify-center text-xs text-muted-foreground/70`,children:r(`scatter.empty`)}):(0,X.jsx)(`div`,{className:`h-[260px]`,children:(0,X.jsx)(A,{width:`100%`,height:`100%`,children:(0,X.jsxs)(xt,{margin:{top:10,right:10,left:-8,bottom:5},children:[(0,X.jsx)(pe,{strokeDasharray:`2 4`,stroke:`currentColor`,className:`text-border/30`}),(0,X.jsx)(ue,{type:`number`,dataKey:`x`,name:`turns`,tick:{fontSize:10},stroke:`currentColor`,className:`text-muted-foreground`,label:{value:r(`scatter.turnsLabel`),position:`insideBottomRight`,offset:-2,fontSize:10,fill:`currentColor`}}),(0,X.jsx)(xe,{type:`number`,dataKey:`y`,name:`cost`,tick:{fontSize:10},stroke:`currentColor`,className:`text-muted-foreground`,tickFormatter:e=>`$${e.toFixed(e<1?2:0)}`}),(0,X.jsx)(yt,{range:[40,80]}),(0,X.jsx)(P,{cursor:{strokeDasharray:`3 3`},contentStyle:{backgroundColor:`var(--popover)`,border:`1px solid var(--border)`,fontSize:11,borderRadius:6},formatter:(e,t)=>{let n=String(t);return n===`cost`&&typeof e==`number`?[`$${e.toFixed(3)}`,r(`scatter.costLabel`)]:[String(e),n===`turns`?r(`scatter.turnsLabel`):n]}}),a.map(e=>(0,X.jsx)(gt,{data:e.points,fill:Mt[e.surface],onClick:e=>{let t=e;t?.raw&&n(t.raw)}},e.surface))]})})})]})}function Ft({data:e,loading:t,onSelectTicket:n}){let{t:r}=s(`analytics`);if(t&&!e)return(0,X.jsx)(`div`,{className:`h-40 rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let i=e.topTickets;return(0,X.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,X.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider mb-3`,children:r(`topTickets.title`)}),i.length===0?(0,X.jsx)(`div`,{className:`h-32 flex items-center justify-center text-xs text-muted-foreground/70`,children:r(`topTickets.empty`)}):(0,X.jsx)(`ul`,{className:`divide-y divide-border/30`,children:i.map((e,t)=>{let i=Object.entries(e.bySurface).filter(([,e])=>e.count>0).map(([e,t])=>r(`topTickets.breakdownItem`,{n:t.count,label:f[e].toLowerCase()})).join(` + `),a=e.isUnattributed,o=a?r(`topTickets.unattributed`):e.ticketTitle?`#${e.ticketId} ${e.ticketTitle}`:r(`topTickets.deletedTicket`,{id:e.ticketId}),s=!e.ticketTitle&&!a?`opacity-50`:``,c=e.unpricedCount??0,l=e.totalRuns>0&&c===e.totalRuns,u=c>0&&!l;return(0,X.jsx)(`li`,{children:(0,X.jsxs)(`button`,{type:`button`,onClick:()=>n(e.ticketId),className:`w-full text-left flex items-center justify-between gap-3 py-2 px-1 hover:bg-accent/30 rounded transition-colors ${s}`,disabled:a,children:[(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`div`,{className:`text-sm truncate`,children:o}),(0,X.jsx)(`div`,{className:`text-[11px] text-muted-foreground truncate`,children:i||`—`})]}),(0,X.jsxs)(`div`,{className:`text-right tabular-nums`,children:[(0,X.jsx)(`div`,{className:`text-sm font-medium`,title:l?r(`topTickets.costUnavailableTooltip`):u?r(`topTickets.costPartiallyUnavailableTooltip`):void 0,children:l?r(`topTickets.costUnavailable`):`$${e.totalCostUsd.toFixed(2)}`}),u&&(0,X.jsx)(`div`,{className:`text-[10px] text-muted-foreground italic`,children:r(`topTickets.costPartiallyUnavailable`,{count:c})}),(0,X.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:r(`runs`,{count:e.totalRuns})})]})]})},`${e.ticketId??`u`}-${t}`)})})]})}var It={claude:`Claude`,codex:`Codex`,gemini:`Gemini`,kimi:`Kimi`};function Lt(e){return It[e]??e}function Rt(e){return e==null?`—`:e<.005?`$${e.toFixed(4)}`:`$${e.toFixed(2)}`}function zt(e){return e==null?`—`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function Bt(e){return e.surface_ref_id?.startsWith(`contract-refine:`)?!0:e.surface===`explore-spec`&&e.ticket_id!=null&&e.conversation_id!=null&&e.surface_ref_id===e.conversation_id&&e.model==null}function Vt(e){let t=new Map;for(let n of e)n.model&&(n.conversation_id&&t.set(`conversation:${n.conversation_id}`,n.model),n.ticket_id!=null&&n.surface===`explore-spec`&&t.set(`ticket:${n.ticket_id}:explore-spec`,n.model),n.ticket_id!=null&&n.surface===`quick-spec`&&t.set(`ticket:${n.ticket_id}:quick-spec`,n.model));return t}function Ht(e,t){if(e.model)return e.model;if(!Bt(e))return null;if(e.conversation_id){let n=t.get(`conversation:${e.conversation_id}`);if(n)return n}return e.ticket_id==null?null:t.get(`ticket:${e.ticket_id}:${e.surface}`)??null}function Ut({rows:e,loading:t,truncated:n,totalAvailable:r,tableFilters:i,onTableFiltersChange:a}){let{t:o}=s(`analytics`),[c,l]=(0,Y.useState)(null),u=Vt(e),d=new Set(e.map(e=>e.provider??`claude`)).size>1,p=n||r>e.length;return(0,X.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 mb-3`,children:[(0,X.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider`,children:o(`table.title`)}),(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-[11px]`,children:[(0,X.jsxs)(`select`,{value:i.status??``,onChange:e=>a({...i,status:e.target.value||void 0}),className:`h-7 px-2 rounded-md bg-background-deep border border-border/60 text-xs`,"aria-label":o(`table.statusFilterAria`),children:[(0,X.jsx)(`option`,{value:``,children:o(`table.allStatus`)}),(0,X.jsx)(`option`,{value:`success`,children:o(`table.success`)}),(0,X.jsx)(`option`,{value:`failed`,children:o(`table.failed`)}),(0,X.jsx)(`option`,{value:`aborted`,children:o(`table.aborted`)})]}),(0,X.jsx)(`input`,{type:`number`,step:`0.01`,min:`0`,placeholder:o(`table.minCostPlaceholder`),value:i.minCostUsd??``,onChange:e=>{let t=e.target.value===``?void 0:parseFloat(e.target.value);a({...i,minCostUsd:Number.isNaN(t)?void 0:t})},className:`h-7 w-24 px-2 rounded-md bg-background-deep border border-border/60 text-xs tabular-nums`,"aria-label":o(`table.minCostFilterAria`)})]})]}),t?(0,X.jsx)(`div`,{className:`h-32 rounded bg-card/30 animate-pulse`}):e.length===0?(0,X.jsx)(`div`,{className:`h-32 flex items-center justify-center text-xs text-muted-foreground/70`,children:o(`table.empty`)}):(0,X.jsx)(`div`,{className:`overflow-x-auto`,children:(0,X.jsxs)(`table`,{className:`w-full text-[12px] tabular-nums`,children:[(0,X.jsx)(`thead`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:(0,X.jsxs)(`tr`,{className:`text-left`,children:[(0,X.jsx)(`th`,{className:`font-medium px-2 py-2`,children:o(`table.colSurface`)}),(0,X.jsx)(`th`,{className:`font-medium px-2 py-2`,children:o(`table.colTicket`)}),(0,X.jsx)(`th`,{className:`font-medium px-2 py-2 text-right`,children:o(`table.colCost`)}),(0,X.jsx)(`th`,{className:`font-medium px-2 py-2 text-right`,children:o(`table.colTurns`)}),(0,X.jsx)(`th`,{className:`font-medium px-2 py-2 text-right`,children:o(`table.colTokens`)}),(0,X.jsx)(`th`,{className:`font-medium px-2 py-2`,children:o(`table.colModel`)}),d&&(0,X.jsx)(`th`,{className:`font-medium px-2 py-2`,children:o(`table.colProvider`)}),(0,X.jsx)(`th`,{className:`font-medium px-2 py-2`,children:o(`table.colStatus`)}),(0,X.jsx)(`th`,{className:`font-medium px-2 py-2`,children:o(`table.colStarted`)})]})}),(0,X.jsx)(`tbody`,{children:e.map(e=>{let t=e.surface,n=m[t],r=(e.tokens_in??0)+(e.tokens_out??0)+(e.tokens_cache_read??0)+(e.tokens_cache_create??0),i=Bt(e),a=i?o(`table.contractLayer`):f[t],s=Ht(e,u);return(0,X.jsxs)(`tr`,{onClick:()=>l(c===e.id?null:e.id),className:`border-t border-border/30 hover:bg-accent/30 cursor-pointer`,children:[(0,X.jsx)(`td`,{className:`px-2 py-2`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 px-2 h-5 rounded-full text-[10px] font-medium ${n.bg} ${n.text}`,children:[(0,X.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full ${n.dot}`}),a]})}),(0,X.jsx)(`td`,{className:`px-2 py-2 max-w-[260px]`,children:e.ticket_id==null?e.ticket_title?(0,X.jsx)(`span`,{className:`truncate block text-muted-foreground/90 italic`,title:o(`table.provisionalTitleTooltip`),children:e.ticket_title}):(0,X.jsx)(`span`,{className:`text-muted-foreground/70`,children:`—`}):(0,X.jsxs)(`span`,{className:`truncate block`,children:[`#`,e.ticket_id,` `,i?(0,X.jsx)(`span`,{className:`text-muted-foreground/90`,children:o(`table.contractLayerRefinement`)}):e.ticket_title??(0,X.jsx)(`span`,{className:`text-muted-foreground/70 italic`,children:o(`table.deleted`)})]})}),(0,X.jsx)(`td`,{className:`px-2 py-2 text-right font-medium`,children:e.total_cost_usd_estimated===1&&e.total_cost_usd!=null?(0,X.jsxs)(`span`,{title:o(`table.estimatedCostTooltip`),className:`text-muted-foreground/90`,children:[`~`,Rt(e.total_cost_usd)]}):Rt(e.total_cost_usd)}),(0,X.jsx)(`td`,{className:`px-2 py-2 text-right`,children:zt(e.num_turns)}),(0,X.jsx)(`td`,{className:`px-2 py-2 text-right`,children:r>0?zt(r):`—`}),(0,X.jsxs)(`td`,{className:`px-2 py-2 max-w-[180px] truncate`,children:[s??`—`,s&&!e.model?(0,X.jsx)(`span`,{className:`ml-1 text-[10px] text-muted-foreground/70`,children:o(`table.inferred`)}):null]}),d&&(0,X.jsx)(`td`,{className:`px-2 py-2 text-muted-foreground`,children:Lt(e.provider??`claude`)}),(0,X.jsxs)(`td`,{className:`px-2 py-2`,children:[e.status===`success`?(0,X.jsx)(`span`,{className:`text-accent-success/90`,children:`●`}):e.status===`failed`?(0,X.jsx)(`span`,{className:`text-accent-warning`,children:`⚠`}):(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`○`}),(0,X.jsx)(`span`,{className:`ml-1 text-muted-foreground`,children:o(`table.statusValue.${e.status}`)})]}),(0,X.jsx)(`td`,{className:`px-2 py-2 text-muted-foreground`,children:e.started_at.slice(0,16).replace(`T`,` `)})]},e.id)})})]})}),p&&e.length>0&&(0,X.jsx)(`div`,{className:`mt-2 text-[11px] text-muted-foreground/80`,children:o(`table.truncated`,{shown:e.length,total:r.toLocaleString()})})]})}var Wt=[{value:`7d`,labelKey:`periods.d7`},{value:`30d`,labelKey:`periods.d30`},{value:`90d`,labelKey:`periods.d90`},{value:`all`,labelKey:`periods.all`}],Gt=[{value:`all`,labelKey:`page.all`},{value:`job`,labelKey:`surfaces.job`},{value:`explore-spec`,labelKey:`surfaces.exploreSpec`},{value:`quick-spec`,labelKey:`surfaces.quickSpec`},{value:`ai-edit`,labelKey:`surfaces.aiEdit`},{value:`smash`,labelKey:`surfaces.smash`},{value:`file-summary`,labelKey:`surfaces.fileSummary`},{value:`loop`,labelKey:`surfaces.loop`}];function Kt(e){let t=new URLSearchParams;return e.period&&t.set(`period`,e.period),e.from&&t.set(`from`,e.from),e.to&&t.set(`to`,e.to),e.surface&&e.surface.length>0&&t.set(`surface`,e.surface.join(`,`)),e.provider&&e.provider.length>0&&t.set(`provider`,e.provider.join(`,`)),e.model&&e.model.length>0&&t.set(`model`,e.model.join(`,`)),e.modelKeys&&e.modelKeys.length>0&&e.model&&e.modelKeys.length===e.model.length&&t.set(`modelProvider`,e.modelKeys.map(e=>e.provider).join(`,`)),e.status&&t.set(`status`,e.status),typeof e.minCostUsd==`number`&&t.set(`minCostUsd`,String(e.minCostUsd)),typeof e.ticketId==`number`&&t.set(`ticketId`,String(e.ticketId)),typeof e.tzOffsetMinutes==`number`&&t.set(`tzOffsetMinutes`,String(e.tzOffsetMinutes)),e.sortBy&&t.set(`sortBy`,e.sortBy),t.toString()}function qt(){let{t:e}=s(`analytics`),{activeProjectId:t,projects:n}=d(),[i,o]=r(),c=n.find(e=>e.id===t),f=c?u(c):[`claude`],p=f.length>1,m=i.get(`period`)??`30d`,h=(i.get(`surface`)??``).split(`,`).filter(Boolean),g=(i.get(`provider`)??``).split(`,`).filter(Boolean),v=i.get(`ticketId`),x=(i.get(`model`)??``).split(`,`).filter(Boolean),S=(i.get(`modelProvider`)??``).split(`,`).filter(Boolean),C=x.length>0&&x.length===S.length?x.map((e,t)=>({provider:S[t],model:e})):void 0,ee=(0,Y.useMemo)(()=>-new Date().getTimezoneOffset(),[]),[w,T]=(0,Y.useState)({period:m,surface:h.length>0?h:void 0,provider:g.length>0?g:void 0,ticketId:v?Number(v):void 0,model:x.length>0?x:void 0,modelKeys:C,tzOffsetMinutes:ee}),[E,D]=(0,Y.useState)(null),[O,k]=(0,Y.useState)(!0),[A,j]=(0,Y.useState)(null),[M,N]=(0,Y.useState)({}),[P,F]=(0,Y.useState)(null),[I,te]=(0,Y.useState)(`recency`),L=(0,Y.useRef)(new Map),R=(0,Y.useRef)(0);(0,Y.useEffect)(()=>{let e=new URLSearchParams;e.set(`period`,w.period),w.surface&&w.surface.length>0&&e.set(`surface`,w.surface.join(`,`)),w.provider&&w.provider.length>0&&e.set(`provider`,w.provider.join(`,`)),w.ticketId&&e.set(`ticketId`,String(w.ticketId)),w.model&&w.model.length>0&&(e.set(`model`,w.model.join(`,`)),w.modelKeys&&w.modelKeys.length===w.model.length&&e.set(`modelProvider`,w.modelKeys.map(e=>e.provider).join(`,`))),o(e,{replace:!0})},[w.period,w.surface,w.provider,w.ticketId,w.model,w.modelKeys,o]);let z=(0,Y.useCallback)(async()=>{if(!t)return;let e=++R.current;j(null);let n=`${t}:${Kt(w)}`,r=L.current.get(n);r?(D(r),k(!1)):k(!0);try{let t=await fetch(`${l()}/spending?${Kt(w)}`);if(!t.ok)throw Error(`HTTP ${t.status}`);if(e!==R.current)return;let r=await t.json();L.current.set(n,r),D(r),k(!1)}catch(t){if(e!==R.current)return;j(t.message),k(!1)}},[t,w]),B=(0,Y.useRef)(0),V=(0,Y.useCallback)(async()=>{if(!t)return;let e=++B.current,n={...w};M.model&&(n.model=[M.model],n.modelKeys=void 0),M.status&&(n.status=M.status),typeof M.minCostUsd==`number`&&(n.minCostUsd=M.minCostUsd),n.sortBy=I;try{let t=await fetch(`${l()}/invocations?${Kt(n)}&limit=100`);if(!t.ok)throw Error(`HTTP ${t.status}`);let r=await t.json();if(e!==B.current)return;F(r)}catch{if(e!==B.current)return;F(null)}},[t,w,M,I]),ne=(0,Y.useRef)(t);(0,Y.useEffect)(()=>{ne.current!==t&&(ne.current=t,D(null),F(null),k(!0))},[t]),(0,Y.useEffect)(()=>{z()},[z]),(0,Y.useEffect)(()=>{V()},[V]);let H=(0,Y.useRef)(null),U=a();(0,Y.useEffect)(()=>{let e=`analytics-spending`;return U.registerHandler(e,e=>{let n=e;n.type===`spending.invalidated`&&n.projectId===t&&(H.current&&clearTimeout(H.current),H.current=setTimeout(()=>{L.current.clear(),z(),V()},500))}),()=>{U.unregisterHandler(e),H.current&&clearTimeout(H.current)}},[U,t,z,V]);function re(e){if(e===`all`){T(e=>({...e,surface:void 0}));return}T(t=>{let n=t.surface??[],r=n.includes(e)?n.filter(t=>t!==e):[...n,e];return{...t,surface:r.length>0?r:void 0}})}let ie=(0,Y.useCallback)((e,t)=>{T(n=>{if(n.model?.length===1&&n.model[0]===e&&(t===void 0||n.modelKeys?.length===1&&n.modelKeys[0].provider===t))return{...n,model:void 0,modelKeys:void 0};let r=(E?.byModel??[]).filter(n=>n.model===e&&(t===void 0||n.provider===t)).map(e=>({provider:e.provider,model:e.model})),i=r.length>0?r.map(e=>e.model):[e];return{...n,model:i,modelKeys:r.length>0?r:void 0}})},[E]);function ae(){T(e=>({...e,model:void 0,modelKeys:void 0}))}function oe(e){if(e===`all`){T(e=>({...e,provider:void 0}));return}T(t=>{let n=t.provider??[],r=n.includes(e)?n.filter(t=>t!==e):[...n,e];return{...t,provider:r.length>0?r:void 0}})}let W=w.surface,se=!W||W.length===0,G=w.provider,ce=!G||G.length===0,le=(0,Y.useMemo)(()=>{let e={period:w.period};return w.surface&&w.surface.length>0&&(e.surface=w.surface.join(`,`)),w.provider&&w.provider.length>0&&(e.provider=w.provider.join(`,`)),w.ticketId&&(e.ticketId=String(w.ticketId)),e},[w]),ue=E?E.summary.totalRuns===0:!1;return(0,X.jsxs)(`div`,{className:`flex flex-col gap-6 p-4 pb-12`,children:[(0,X.jsxs)(`div`,{className:`sticky top-0 z-10 -mx-4 px-4 py-3 bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/80 border-b border-border/40`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,X.jsx)(`h1`,{className:`text-base font-semibold tracking-tight`,children:e(`page.title`)}),w.ticketId&&(0,X.jsx)(`button`,{type:`button`,onClick:()=>T(e=>({...e,ticketId:void 0})),className:`inline-flex items-center gap-1 h-6 px-2 rounded-full text-[11px] font-medium bg-accent-highlight/15 text-accent-highlight ring-1 ring-accent-highlight/30 hover:bg-accent-highlight/25`,children:e(`page.ticketChip`,{id:w.ticketId})}),w.model&&w.model.length>0&&(0,X.jsxs)(`button`,{type:`button`,"data-testid":`analytics-model-chip`,onClick:ae,title:e(`page.clearModelFilter`),className:`inline-flex items-center gap-1 h-6 px-2 rounded-full text-[11px] font-medium bg-accent-highlight/15 text-accent-highlight ring-1 ring-accent-highlight/30 hover:bg-accent-highlight/25`,children:[e(`page.modelChip`,{model:w.model[0]}),(0,X.jsx)(`span`,{"aria-hidden":!0,className:`opacity-70`,children:`×`})]})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`div`,{className:`flex items-center gap-1 rounded-md border border-border/60 bg-card/40 p-0.5`,children:Wt.map(t=>(0,X.jsx)(`button`,{type:`button`,onClick:()=>T(e=>({...e,period:t.value})),className:`px-2.5 h-6 rounded text-[11px] font-medium transition-colors ${w.period===t.value?`bg-accent text-foreground`:`text-muted-foreground hover:text-foreground`}`,children:e(t.labelKey)},t.value))}),(0,X.jsx)(b,{baseUrl:`${l()}/analytics/export`,params:le,disabled:ue}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>{L.current.clear(),z(),V()},className:`h-7 w-7 inline-flex items-center justify-center rounded-md border border-border/60 bg-card/50 text-muted-foreground hover:text-foreground hover:bg-accent/60`,title:e(`common:actions.refresh`),children:(0,X.jsx)(y,{className:`w-3 h-3`})})]})]}),(0,X.jsx)(`div`,{className:`mt-3 flex flex-wrap items-center gap-1.5`,children:Gt.map(t=>(0,X.jsx)(`button`,{type:`button`,onClick:()=>re(t.value),className:`h-7 px-3 rounded-full text-[11px] font-medium transition-all ${(t.value===`all`?se:W?.includes(t.value)??!1)?`bg-foreground/10 text-foreground ring-1 ring-foreground/20`:`text-muted-foreground hover:text-foreground hover:bg-accent/40`}`,children:e(t.labelKey)},t.value))}),p&&(0,X.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-1.5`,"data-testid":`analytics-provider-chips`,children:[(0,X.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-muted-foreground/70 mr-1`,children:e(`page.engine`)}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>oe(`all`),className:`h-7 px-3 rounded-full text-[11px] font-medium transition-all ${ce?`bg-foreground/10 text-foreground ring-1 ring-foreground/20`:`text-muted-foreground hover:text-foreground hover:bg-accent/40`}`,children:e(`page.all`)}),f.map(e=>(0,X.jsx)(`button`,{type:`button`,onClick:()=>oe(e),className:`h-7 px-3 rounded-full text-[11px] font-medium transition-all ${G?.includes(e)??!1?`bg-foreground/10 text-foreground ring-1 ring-foreground/20`:`text-muted-foreground hover:text-foreground hover:bg-accent/40`}`,children:_(e)},e))]})]}),A&&(0,X.jsxs)(`div`,{className:`rounded-lg border border-accent-warning/30 bg-accent-warning/10 p-4 flex items-center justify-between`,children:[(0,X.jsx)(`p`,{className:`text-sm text-accent-warning`,children:e(`page.failedToLoad`,{error:A})}),(0,X.jsxs)(`button`,{onClick:()=>z(),className:`flex items-center gap-1.5 h-7 px-3 rounded-md text-xs text-accent-warning border border-accent-warning/30 hover:bg-accent-warning/10`,children:[(0,X.jsx)(y,{className:`w-3 h-3`}),e(`common:actions.retry`)]})]}),(0,X.jsx)(Ie,{data:E,loading:O,period:w.period}),(0,X.jsx)(He,{data:E,loading:O}),(0,X.jsx)(St,{data:E,loading:O}),(0,X.jsx)(At,{data:E,loading:O}),(0,X.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4`,children:[(0,X.jsx)(Dt,{data:E,loading:O}),(0,X.jsx)(jt,{data:E,loading:O,onSelectModel:ie,activeModel:w.model?.[0]})]}),(0,X.jsx)(Pt,{data:E,loading:O,onSelectPoint:e=>{N(e=>({...e})),T(t=>({...t,ticketId:e.ticketId??void 0}))}}),(0,X.jsx)(Ft,{data:E,loading:O,onSelectTicket:e=>T(t=>({...t,ticketId:e??void 0}))}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-end gap-1.5`,"data-testid":`analytics-table-sort`,children:[(0,X.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-muted-foreground/70 mr-1`,children:e(`table.sortLabel`)}),[`recency`,`cost`].map(t=>(0,X.jsx)(`button`,{type:`button`,"data-testid":`analytics-table-sort-${t}`,"aria-pressed":I===t,onClick:()=>te(t),className:`h-6 px-2.5 rounded-full text-[11px] font-medium transition-all ${I===t?`bg-foreground/10 text-foreground ring-1 ring-foreground/20`:`text-muted-foreground hover:text-foreground hover:bg-accent/40`}`,children:e(t===`recency`?`table.sortRecency`:`table.sortCost`)},t))]}),(0,X.jsx)(Ut,{rows:P?.rows??[],loading:O&&!P,truncated:(P?.truncated??!1)||(P?.totalAvailable??0)>(P?.rows.length??0),totalAvailable:P?.totalAvailable??0,tableFilters:M,onTableFiltersChange:N})]})]})}export{qt as default};