specrails-desktop 2.10.0 → 2.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/dist/assets/{ActivityFeedPage-qPnIozX9.js → ActivityFeedPage-CbOQSZ4L.js} +1 -1
- package/client/dist/assets/{AgentsPage-B_8WZUUI.js → AgentsPage-5UiKCp_t.js} +1 -1
- package/client/dist/assets/{AnalyticsPage-DCnFtl8E.js → AnalyticsPage-BwxD58MO.js} +1 -1
- package/client/dist/assets/{BarChart-Cr7__BAU.js → BarChart-BaJJVLw4.js} +1 -1
- package/client/dist/assets/{CodePage-C7uJgpF8.js → CodePage-3tgS4fU2.js} +1 -1
- package/client/dist/assets/{DesktopAnalyticsPage-DqCEHy0T.js → DesktopAnalyticsPage-BWJxqa4T.js} +1 -1
- package/client/dist/assets/{DocsDialog-C_jIYef_.js → DocsDialog-DF5TF81L.js} +1 -1
- package/client/dist/assets/{DocsPage-CTifuwaa.js → DocsPage-DZDZPRLe.js} +1 -1
- package/client/dist/assets/{ExportDropdown-BcmU6I16.js → ExportDropdown-DFEuLgiK.js} +1 -1
- package/client/dist/assets/{IntegrationsPage-DZntBwnd.js → IntegrationsPage-CuAShwlJ.js} +1 -1
- package/client/dist/assets/{JobDetailPage-4ncqbKxF.js → JobDetailPage-Bx0wRTry.js} +1 -1
- package/client/dist/assets/{JobsPage-CapLnvIs.js → JobsPage-COcbVVcd.js} +1 -1
- package/client/dist/assets/{dist-js-DKGy2gD-.js → dist-js-Cbm7C856.js} +1 -1
- package/client/dist/assets/{dist-js-DvPNad3t.js → dist-js-CgFhhWyd.js} +1 -1
- package/client/dist/assets/{index-IgMtikGD.js → index-Wgxn2zBM.js} +6 -6
- package/client/dist/assets/{lib-BouqFmKc.js → lib-BhY8Pq4z.js} +1 -1
- package/client/dist/assets/{useProjectCache-vvFIixVa.js → useProjectCache-CDaO4kHu.js} +1 -1
- package/client/dist/index.html +1 -1
- package/package.json +1 -1
- package/server/dist/install-config-path.js +27 -0
- package/server/dist/project-router-setup.js +20 -2
- package/server/dist/setup-manager.js +31 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./chunk-CilyBKbf.js";import{$t as t,Ct as n,Et as r,F as i,Lt as a,Ot as o,Q as s,Rt as c,dt as l,ft as u,sn as d,wt as f,zt as p}from"./index-
|
|
1
|
+
import{r as e}from"./chunk-CilyBKbf.js";import{$t as t,Ct as n,Et as r,F as i,Lt as a,Ot as o,Q as s,Rt as c,dt as l,ft as u,sn as d,wt as f,zt as p}from"./index-Wgxn2zBM.js";var m=f(`ban`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M4.929 4.929 19.07 19.071`,key:`196cmz`}]]),h=e(d(),1);function g(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 _({activeProjectId:e,limit:t=50}){let[n,r]=(0,h.useState)([]),[i,s]=(0,h.useState)(!1),[c,l]=(0,h.useState)(!0),u=(0,h.useRef)(e);(0,h.useEffect)(()=>{u.current=e},[e]);let{registerHandler:d,unregisterHandler:f}=a();(0,h.useEffect)(()=>{if(!e){r([]),l(!0);return}let n=!1;s(!0),r([]),l(!0);async function i(){let e=p();try{let i=await fetch(`${e}/activity?limit=${t}`);if(!i.ok||n)return;let a=await i.json();if(n)return;r(a),l(a.length===t)}catch{}finally{n||s(!1)}}return i(),()=>{n=!0}},[e,t]);let m=(0,h.useCallback)(async()=>{if(i||!c)return;s(!0);let e=p();try{r(n=>{let i=n[n.length-1];if(!i)return n;let a=encodeURIComponent(i.timestamp);return fetch(`${e}/activity?limit=${t}&before=${a}`).then(e=>e.json()).then(e=>{r(t=>g([...t,...e])),l(e.length===t),s(!1)}).catch(()=>s(!1)),n})}catch{s(!1)}},[i,c,t]),_=(0,h.useCallback)(e=>{let t=e,n=u.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&&r(t=>g([...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:o.t(`activity:feed.phaseCommand`,{phase:t.phase,state:t.state}),timestamp:t.timestamp,summary:`Phase ${t.phase} is ${t.state}`,costUsd:null};r(t=>g([e,...t]))}}},[]);return(0,h.useLayoutEffect)(()=>(d(`activity`,_),()=>f(`activity`)),[_,d,f]),{items:n,loading:i,hasMore:c,loadMore:m}}var v=c();function y(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 b({type:e}){switch(e){case`job_completed`:return(0,v.jsx)(u,{className:`w-4 h-4 text-green-500 aurora-light:text-accent-success flex-shrink-0`});case`job_failed`:return(0,v.jsx)(l,{className:`w-4 h-4 text-red-500 aurora-light:text-destructive flex-shrink-0`});case`job_canceled`:return(0,v.jsx)(m,{className:`w-4 h-4 text-muted-foreground flex-shrink-0`});default:return(0,v.jsx)(i,{className:`w-4 h-4 text-blue-500 aurora-light:text-accent-info flex-shrink-0`})}}function x(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 S(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 C(){let{t:e}=t(`activity`),{activeProjectId:i}=r(),{items:a,loading:o,hasMore:c,loadMore:l}=_({activeProjectId:i}),u=(0,h.useRef)(null);return(0,h.useEffect)(()=>{let e=u.current;if(!e)return;let t=new IntersectionObserver(e=>{e[0].isIntersecting&&c&&!o&&l()},{threshold:.1});return t.observe(e),()=>t.disconnect()},[c,o,l]),(0,v.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,v.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-3 border-b border-border bg-background/50`,children:[(0,v.jsx)(n,{className:`w-4 h-4 text-muted-foreground`}),(0,v.jsx)(`h1`,{className:`text-sm font-medium`,children:e(`feed.title`)})]}),(0,v.jsxs)(`div`,{className:`flex-1 overflow-y-auto`,children:[o&&a.length===0?(0,v.jsx)(`div`,{className:`flex items-center justify-center h-32`,children:(0,v.jsx)(s,{className:`w-4 h-4 animate-spin text-muted-foreground`})}):a.length===0?(0,v.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-48 gap-2 text-muted-foreground`,children:[(0,v.jsx)(n,{className:`w-8 h-8 opacity-40`}),(0,v.jsx)(`p`,{className:`text-sm`,children:e(`feed.emptyTitle`)}),(0,v.jsx)(`p`,{className:`text-xs opacity-70`,children:e(`feed.emptyHint`)})]}):(0,v.jsx)(`ul`,{className:`divide-y divide-border/50`,children:a.map(t=>(0,v.jsxs)(`li`,{className:`flex items-center gap-3 px-4 py-2.5 hover:bg-accent/30 transition-colors`,children:[(0,v.jsx)(b,{type:t.type}),(0,v.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,v.jsx)(`p`,{className:`text-xs text-foreground truncate`,title:t.jobCommand,children:t.jobCommand}),(0,v.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5`,children:[(0,v.jsx)(`span`,{className:`text-xs font-medium ${S(t.type)}`,children:x(t.type,e)}),t.costUsd!=null&&(0,v.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`$`,t.costUsd.toFixed(4)]})]})]}),(0,v.jsx)(`span`,{className:`text-xs text-muted-foreground flex-shrink-0 tabular-nums`,children:y(t.timestamp,e)})]},`${t.type}:${t.jobId}`))}),(0,v.jsx)(`div`,{ref:u,className:`h-1`}),o&&a.length>0&&(0,v.jsx)(`div`,{className:`flex justify-center py-3`,children:(0,v.jsx)(s,{className:`w-4 h-4 animate-spin text-muted-foreground`})}),!c&&a.length>0&&(0,v.jsx)(`p`,{className:`text-center text-xs text-muted-foreground py-3`,children:e(`feed.allLoaded`)})]})]})}export{C as default};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{r as e}from"./chunk-CilyBKbf.js";import{$t as t,A as n,B as r,Bt as i,D as a,E as o,Et as s,Gt as c,H as l,Ht as u,I as d,J as f,Jt as p,K as m,Kt as h,L as g,Lt as _,N as v,O as y,Ot as b,Q as x,Qt as S,R as C,Rt as w,St as T,T as E,U as D,Ut as O,Vt as k,Wt as A,X as ee,Xt as j,Yt as M,Z as N,Zt as P,_t as F,ct as I,et as L,f as R,gt as te,ht as z,j as ne,k as B,o as re,ot as V,pt as ie,qt as ae,rt as oe,sn as se,tn as H,w as U,wt as W,xt as ce,yt as le,z as ue,zt as G}from"./index-IgMtikGD.js";var K=W(`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`}]]),q=W(`history`,[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}],[`path`,{d:`M12 7v5l4 2`,key:`1fdv2h`}]]),de=W(`pin`,[[`path`,{d:`M12 17v5`,key:`bb1du9`}],[`path`,{d:`M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z`,key:`1nkz8b`}]]),fe=W(`wand-sparkles`,[[`path`,{d:`m21.64 3.64-1.28-1.28a1.21 1.21 0 0 0-1.72 0L2.36 18.64a1.21 1.21 0 0 0 0 1.72l1.28 1.28a1.2 1.2 0 0 0 1.72 0L21.64 5.36a1.2 1.2 0 0 0 0-1.72`,key:`ul74o6`}],[`path`,{d:`m14 7 3 3`,key:`1r5n42`}],[`path`,{d:`M5 6v4`,key:`ilb8ba`}],[`path`,{d:`M19 14v4`,key:`blhpug`}],[`path`,{d:`M10 2v2`,key:`7u0qdc`}],[`path`,{d:`M7 8H3`,key:`zfb6yr`}],[`path`,{d:`M21 16h-4`,key:`1cnmox`}],[`path`,{d:`M11 3H9`,key:`1obp7u`}]]),J=e(se(),1),Y=w(),X=/^[a-z0-9][a-z0-9-]*$/;function pe({open:e,mode:n=`add`,initial:r,chainAgents:i,onConfirm:s,onCancel:c}){let{t:l}=t(`agents`),[u,d]=(0,J.useState)(``),[f,p]=(0,J.useState)(i[0]??``);(0,J.useEffect)(()=>{e&&(n===`edit`&&r?(d(r.tags.join(`, `)),p(i.includes(r.agent)?r.agent:i[0]??``)):(d(``),p(i[0]??``)))},[e,n,r,i]);let m=u.split(`,`).map(e=>e.trim()).filter(Boolean),h=m.filter(e=>!X.test(e)),g=m.length>0&&h.length===0&&i.includes(f);return(0,Y.jsx)(U,{open:e,onOpenChange:e=>{e||c()},children:(0,Y.jsxs)(E,{className:`max-w-md`,children:[(0,Y.jsxs)(y,{children:[(0,Y.jsx)(B,{children:l(n===`edit`?`routingRule.editTitle`:`routingRule.addTitle`)}),(0,Y.jsx)(o,{children:l(n===`edit`?`routingRule.editDescription`:`routingRule.addDescription`)})]}),(0,Y.jsxs)(`div`,{className:`py-2 space-y-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:l(`routingRule.tagsLabel`)}),(0,Y.jsx)(re,{autoFocus:!0,value:u,onChange:e=>d(e.target.value),placeholder:`frontend, ui`,"aria-label":l(`routingRule.tagsLabel`),className:`text-sm font-mono`}),(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground mt-1`,children:(0,Y.jsx)(H,{t:l,i18nKey:`routingRule.tagsHint`,components:{code:(0,Y.jsx)(`code`,{})}})}),h.length>0&&(0,Y.jsx)(`p`,{className:`text-[11px] text-red-400 aurora-light:text-destructive mt-1`,children:l(`routingRule.invalidTags`,{count:h.length,tags:h.join(`, `)})})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:l(`routingRule.routeToLabel`)}),(0,Y.jsx)(`select`,{value:f,onChange:e=>p(e.target.value),"aria-label":l(`routingRule.routeToLabel`),className:`w-full h-9 px-2 text-sm rounded-md border border-border bg-background`,children:i.map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e))}),(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground mt-1`,children:l(`routingRule.routeToHint`)})]})]}),(0,Y.jsxs)(a,{children:[(0,Y.jsx)(v,{variant:`ghost`,size:`sm`,onClick:c,children:l(`common:actions.cancel`)}),(0,Y.jsx)(v,{size:`sm`,onClick:()=>s(m,f),disabled:!g,children:l(n===`edit`?`routingRule.saveChanges`:`routingRule.addRule`)})]})]})})}var Z=new Set([`sr-architect`,`sr-developer`,`sr-reviewer`,`sr-merge-resolver`]),me=[`sonnet`,`opus`,`haiku`],he=/^[a-z0-9][a-z0-9-]*$/;function ge({profile:e,onChange:n,footer:r,onValidityChange:a,onSoftWarningsChange:o}){let{t:s}=t(`agentstudio`),[l,m]=(0,J.useState)([]),[g,_]=(0,J.useState)(!1),[y,b]=(0,J.useState)(!1),[x,S]=(0,J.useState)(null);(0,J.useEffect)(()=>{let e=!1;return fetch(`${G()}/profiles/catalog`).then(e=>e.ok?e.json():{agents:[]}).then(t=>{e||m(t.agents)}).catch(()=>{e||m([])}),()=>{e=!0}},[]);let C=t=>{let r=JSON.parse(JSON.stringify(e));t(r),n(r)},w=new Set(e.agents.map(e=>e.id)),T=l.filter(e=>!w.has(e.id)),E=(0,J.useMemo)(()=>{let t=[];for(let n of Z)e.agents.some(e=>e.id===n)||t.push(s(`profileEditor.validation.missingBaseline`,{agent:n}));let n=e.routing.filter(e=>`default`in e&&e.default===!0);if(n.length>1&&t.push(s(`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(s(`profileEditor.validation.defaultRuleNotLast`))}for(let n of e.routing)if(e.agents.some(e=>e.id===n.agent)||t.push(s(`profileEditor.validation.unknownRoutingAgent`,{agent:n.agent})),`tags`in n){let e=n.tags.filter(e=>!he.test(e));e.length>0&&t.push(s(`profileEditor.validation.invalidTags`,{agent:n.agent,tags:e.join(`, `)}))}return t},[e,s]),D=(0,J.useMemo)(()=>{if(e.routing.length===0)return[];let t=new Set(e.routing.map(e=>e.agent));return e.agents.filter(e=>!Z.has(e.id)&&!t.has(e.id)).map(e=>e.id)},[e]),O=(0,J.useMemo)(()=>e.routing.some(e=>`default`in e&&e.default===!0),[e.routing]);(0,J.useEffect)(()=>{a&&a(E)},[E,a]),(0,J.useEffect)(()=>{o&&o({agentsMissingRouting:D})},[D,o]);let ee=e=>{C(t=>{let n={id:e,model:`sonnet`},r=t.agents.findIndex(e=>e.id===`sr-merge-resolver`);r>=0?t.agents.splice(r,0,n):t.agents.push(n)}),_(!1)},N=t=>{let n=e.agents[t];Z.has(n.id)||C(e=>{e.agents.splice(t,1),e.routing=e.routing.filter(e=>e.agent!==n.id)})},P=(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=k(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})},F=j(M(ae,{activationConstraint:{distance:4}}),M(h,{coordinateGetter:u})),I=e=>{let{active:t,over:n}=e;n&&P(String(t.id),String(n.id))},L=(e,t)=>{C(n=>{n.agents[e].model=t})},R=(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)}),b(!1)},te=()=>{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,ne=(e,t)=>{C(n=>{let r=n.routing[e];r&&(z(r)||(r.agent=t))})},B=(e,t,n)=>{C(r=>{let i=r.routing[e];i&&(z(i)||(i.tags=t,i.agent=n))})},V=e=>{C(t=>{let n=t.routing[e];n&&(z(n)||t.routing.splice(e,1))})},ie=(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,Y.jsxs)(`div`,{className:`p-6 space-y-6 max-w-3xl`,children:[(0,Y.jsx)(pe,{open:y,mode:`add`,chainAgents:e.agents.map(e=>e.id),onConfirm:R,onCancel:()=>b(!1)}),(0,Y.jsx)(pe,{open:x!==null,mode:`edit`,initial:x!==null&&e.routing[x]&&!(`default`in e.routing[x])?{tags:e.routing[x].tags,agent:e.routing[x].agent}:void 0,chainAgents:e.agents.map(e=>e.id),onConfirm:(e,t)=>{x!==null&&(B(x,e,t),S(null))},onCancel:()=>S(null)}),E.length>0&&(0,Y.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,Y.jsx)(`div`,{className:`font-medium mb-1`,children:s(`profileEditor.validationSummary`,{count:E.length})}),(0,Y.jsx)(`ul`,{className:`list-disc list-inside space-y-0.5`,children:E.map((e,t)=>(0,Y.jsx)(`li`,{children:e},t))})]}),(0,Y.jsxs)(`section`,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:s(`profileEditor.nameLabel`)}),(0,Y.jsx)(re,{value:e.name,disabled:!0,className:`text-sm`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:s(`profileEditor.descriptionLabel`)}),(0,Y.jsx)(re,{value:e.description??``,onChange:e=>C(t=>{t.description=e.target.value}),className:`text-sm`,placeholder:s(`profileEditor.descriptionPlaceholder`)})]})]}),(0,Y.jsxs)(`section`,{children:[(0,Y.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide mb-2`,children:s(`profileEditor.orchestrator.heading`)}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 p-3 rounded-md border border-border`,children:[(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-mono text-foreground truncate`,children:`/specrails:implement · /specrails:batch-implement`}),(0,Y.jsx)(`div`,{className:`text-[11px] text-muted-foreground mt-0.5`,children:s(`profileEditor.orchestrator.description`)})]}),(0,Y.jsx)(ye,{value:e.orchestrator.model,onChange:e=>C(t=>{t.orchestrator.model=e})})]})]}),(0,Y.jsxs)(`section`,{children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,Y.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:s(`profileEditor.agentChain.heading`,{n:e.agents.length})}),(0,Y.jsxs)(v,{size:`sm`,variant:`ghost`,onClick:()=>_(e=>!e),disabled:T.length===0,title:T.length===0?s(`profileEditor.agentChain.addDisabledTitle`):s(`profileEditor.agentChain.addTitle`),children:[(0,Y.jsx)(f,{className:`w-3.5 h-3.5 mr-1`}),` `,s(`common:actions.add`)]})]}),g&&(0,Y.jsxs)(`div`,{className:`mb-2 p-2 rounded-md border border-border bg-muted/30`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mb-1.5 px-1`,children:[(0,Y.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:s(`profileEditor.agentChain.pickFromCatalog`,{n:T.length})}),(0,Y.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:()=>_(!1),title:s(`common:actions.close`),children:(0,Y.jsx)(d,{className:`w-3 h-3`})})]}),T.length===0?(0,Y.jsx)(`div`,{className:`px-2 py-3 text-xs text-muted-foreground text-center`,children:s(`profileEditor.agentChain.emptyCatalog`)}):(0,Y.jsx)(`div`,{className:`space-y-0.5 max-h-64 overflow-auto`,children:T.map(e=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>ee(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,Y.jsx)(`span`,{className:`text-sm font-mono`,children:e.id}),(0,Y.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:s(`profileEditor.agentChain.kind.${e.kind}`)})]},e.id))})]}),(0,Y.jsx)(c,{sensors:F,collisionDetection:p,onDragEnd:I,children:(0,Y.jsx)(i,{items:e.agents.map(e=>e.id),strategy:A,children:(0,Y.jsx)(`div`,{className:`space-y-1.5`,children:e.agents.map((e,t)=>(0,Y.jsx)(_e,{agent:e,canRemove:!Z.has(e.id),onModel:e=>L(t,e),onRemove:()=>N(t)},e.id))})})})]}),(0,Y.jsxs)(`section`,{children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,Y.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:s(`profileEditor.routing.heading`,{n:e.routing.length})}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[!O&&(0,Y.jsxs)(v,{size:`sm`,variant:`ghost`,onClick:te,disabled:e.agents.length===0,title:e.agents.length===0?s(`profileEditor.routing.needAgentsTitle`):void 0,children:[(0,Y.jsx)(f,{className:`w-3.5 h-3.5 mr-1`}),` `,s(`profileEditor.routing.addDefault`)]}),(0,Y.jsxs)(v,{size:`sm`,variant:`ghost`,onClick:()=>b(!0),disabled:e.agents.length===0,title:e.agents.length===0?s(`profileEditor.routing.needAgentsTitle`):void 0,children:[(0,Y.jsx)(f,{className:`w-3.5 h-3.5 mr-1`}),` `,s(`profileEditor.routing.addRule`)]})]})]}),(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground mb-2`,children:s(`profileEditor.routing.explainer`)}),D.length>0&&(0,Y.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,Y.jsx)(`div`,{className:`font-medium mb-1`,children:s(`profileEditor.routing.untargetedTitle`)}),(0,Y.jsx)(`div`,{children:(0,Y.jsx)(H,{t:s,i18nKey:`profileEditor.routing.untargetedDetail`,values:{agents:D.join(`, `)},components:{mono:(0,Y.jsx)(`span`,{className:`font-mono`})}})})]}),(0,Y.jsx)(`div`,{className:`space-y-1.5`,children:e.routing.map((t,n)=>{let r=`default`in t&&t.default===!0;return(0,Y.jsx)(ve,{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=>ne(n,e),onEdit:()=>S(n),onUp:()=>ie(n,-1),onDown:()=>ie(n,1),onRemove:()=>V(n)},n)})})]}),r&&(0,Y.jsx)(`div`,{className:`pt-3 border-t border-border`,children:r})]})}function _e({agent:e,canRemove:n,onModel:r,onRemove:i}){let{t:a}=t(`agentstudio`),o=Z.has(e.id),s=e.id===`sr-architect`,c=e.id===`sr-merge-resolver`,{attributes:l,listeners:u,setNodeRef:f,transform:p,transition:m,isDragging:h}=O({id:e.id});return(0,Y.jsxs)(`div`,{ref:f,style:{transform:P.Transform.toString(p),transition:m,opacity:h?.5:void 0,zIndex:h?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,Y.jsx)(`button`,{type:`button`,className:`flex-shrink-0 p-0.5 rounded text-muted-foreground cursor-grab active:cursor-grabbing hover:text-foreground`,title:a(`profileEditor.agentRow.dragTitle`),"aria-label":a(`profileEditor.agentRow.dragHandleAria`),...l,...u,children:(0,Y.jsx)(L,{className:`w-3.5 h-3.5`})}),(0,Y.jsx)(`span`,{className:`text-sm font-mono flex-1 truncate`,children:e.id}),s&&(0,Y.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:a(`profileEditor.agentRow.pinnedFirstTitle`),children:[(0,Y.jsx)(de,{className:`w-2.5 h-2.5 rotate-[135deg]`}),` `,a(`profileEditor.agentRow.pinnedFirst`)]}),c&&(0,Y.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:a(`profileEditor.agentRow.pinnedLastTitle`),children:[(0,Y.jsx)(de,{className:`w-2.5 h-2.5 rotate-45`}),` `,a(`profileEditor.agentRow.pinnedLast`)]}),o&&!s&&!c&&(0,Y.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:a(`profileEditor.agentRow.required`)}),(0,Y.jsx)(ye,{value:e.model??`sonnet`,onChange:r}),(0,Y.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:i,disabled:!n,title:a(n?`common:actions.remove`:`profileEditor.agentRow.requiredRemoveTitle`),children:(0,Y.jsx)(d,{className:`w-3 h-3`})})]})}function ve({rule:e,ordinal:n,isLast:r,canMove:i,canRemove:a,canEdit:o,chainAgents:s,onAgentChange:c,onEdit:l,onUp:u,onDown:f,onRemove:p}){let{t:m}=t(`agentstudio`),h=`default`in e&&e.default===!0;return(0,Y.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,Y.jsxs)(`span`,{className:`text-[10px] font-mono text-muted-foreground w-5 text-center flex-shrink-0`,children:[n,`.`]}),h?(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground flex-1`,children:m(`profileEditor.routingRow.everythingElse`)}):(0,Y.jsx)(`span`,{className:`text-xs flex-1 flex gap-1 flex-wrap items-center`,children:e.tags.map(e=>(0,Y.jsx)(`span`,{className:`px-1.5 py-0.5 rounded bg-muted font-mono text-[11px]`,children:e},e))}),(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`→`}),h?(0,Y.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":m(`profileEditor.routingRow.defaultTargetAria`),title:m(`profileEditor.routingRow.defaultTargetTitle`),children:e.agent}):(0,Y.jsx)(`select`,{value:e.agent,onChange:e=>c(e.target.value),"aria-label":m(`profileEditor.routingRow.targetAria`,{ordinal:n}),className:`h-7 max-w-[15rem] px-2 text-xs font-mono rounded border border-border bg-background`,children:s.map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e))}),(0,Y.jsxs)(`div`,{className:`flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity`,children:[o&&(0,Y.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:l,title:m(`profileEditor.routingRow.editTitle`),"aria-label":m(`profileEditor.routingRow.editAria`,{ordinal:n}),children:(0,Y.jsx)(ee,{className:`w-3 h-3`})}),i&&!r&&(0,Y.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:f,title:m(`profileEditor.routingRow.moveDown`),children:(0,Y.jsx)(T,{className:`w-3 h-3`})}),i&&n>1&&(0,Y.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:u,title:m(`profileEditor.routingRow.moveUp`),children:(0,Y.jsx)(le,{className:`w-3 h-3`})}),a&&(0,Y.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:p,title:m(`common:actions.remove`),children:(0,Y.jsx)(d,{className:`w-3 h-3`})})]}),h&&(0,Y.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,title:m(`profileEditor.routingRow.coreDefaultTitle`),children:m(`profileEditor.routingRow.coreDefaultBadge`)})]})}function ye({value:e,onChange:t}){return(0,Y.jsx)(`select`,{value:e,onChange:e=>t(e.target.value),className:`h-7 px-2 text-xs rounded border border-border bg-background`,children:me.map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e))})}function be({open:e,title:n,description:r,placeholder:i,initialValue:o=``,confirmLabel:s,inputPattern:c,inputInvalidHint:l,onConfirm:u,onCancel:d}){let{t:f}=t(),[p,m]=(0,J.useState)(o);(0,J.useEffect)(()=>{e&&m(o)},[e,o]);let h=p.trim(),g=!c||c.test(h),_=h.length>0&&g;return(0,Y.jsx)(U,{open:e,onOpenChange:e=>{e||d()},children:(0,Y.jsxs)(E,{className:`max-w-md`,children:[(0,Y.jsx)(y,{children:(0,Y.jsx)(B,{children:n})}),(0,Y.jsxs)(`div`,{className:`py-2 space-y-2`,children:[r&&(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r}),(0,Y.jsx)(re,{autoFocus:!0,value:p,placeholder:i,onChange:e=>m(e.target.value),onKeyDown:e=>{e.key===`Enter`&&_&&u(h)},className:`text-sm font-mono`}),h.length>0&&!g&&l&&(0,Y.jsx)(`p`,{className:`text-[11px] text-yellow-500 aurora-light:text-accent-warning`,children:l})]}),(0,Y.jsxs)(a,{children:[(0,Y.jsx)(v,{variant:`ghost`,size:`sm`,onClick:d,children:f(`actions.cancel`)}),(0,Y.jsx)(v,{size:`sm`,onClick:()=>u(h),disabled:!_,children:s??f(`actions.confirm`)})]})]})})}function xe({open:e,title:n,description:r,confirmLabel:i,destructive:o=!1,onConfirm:s,onCancel:c}){let{t:l}=t();return(0,Y.jsx)(U,{open:e,onOpenChange:e=>{e||c()},children:(0,Y.jsxs)(E,{className:`max-w-md`,children:[(0,Y.jsx)(y,{children:(0,Y.jsx)(B,{children:n})}),r&&(0,Y.jsx)(`div`,{className:`py-2`,children:(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r})}),(0,Y.jsxs)(a,{children:[(0,Y.jsx)(v,{variant:`ghost`,size:`sm`,onClick:c,children:l(`actions.cancel`)}),(0,Y.jsx)(v,{size:`sm`,onClick:s,className:o?`bg-red-500 hover:bg-red-600 text-white`:void 0,children:i??l(`actions.confirm`)})]})]})})}function Se(){let{t:e}=t(`agents`),[n,r]=(0,J.useState)([]),[i,a]=(0,J.useState)(null),[o,s]=(0,J.useState)(null),[c,l]=(0,J.useState)(!0),[u,d]=(0,J.useState)(null),[p,m]=(0,J.useState)(!1),[h,g]=(0,J.useState)([]),[_,y]=(0,J.useState)([]),[b,x]=(0,J.useState)(!1),[w,T]=(0,J.useState)(null),[E,O]=(0,J.useState)(null),k=(0,J.useCallback)(async()=>{l(!0),d(null);try{let t=await fetch(`${G()}/profiles`);if(!t.ok)throw Error(e(`profiles.errors.listFailed`,{status:t.status}));let n=await t.json();r(n.profiles),n.profiles.length>0&&!i&&a(n.profiles[0].name)}catch(e){d(e.message)}finally{l(!1)}},[i]);(0,J.useEffect)(()=>{k()},[k]),(0,J.useEffect)(()=>{if(!i){s(null);return}let t=!1;return fetch(`${G()}/profiles/${encodeURIComponent(i)}`).then(t=>{if(!t.ok)throw Error(e(`profiles.errors.loadFailed`,{status:t.status}));return t.json()}).then(e=>{t||s(e.profile)}).catch(e=>{t||d(e.message)}),()=>{t=!0}},[i]);let A=(0,J.useCallback)(async()=>{m(!0),d(null);try{let t=await fetch(`${G()}/profiles/migrate-from-settings`,{method:`POST`});if(!t.ok){let n=await t.json().catch(()=>({}));throw Error(n.error??e(`profiles.errors.migrationFailed`,{status:t.status}))}await k(),a(`default`),S.success(e(`profiles.toasts.migrated`),{description:e(`profiles.toasts.migratedDescription`)})}catch(t){let n=t.message;d(n),S.error(e(`profiles.toasts.migrationFailed`),{description:n})}finally{m(!1)}},[k]),ee=(0,J.useCallback)(async t=>{x(!1),m(!0),d(null);try{let n={schemaVersion:1,name:t,description:``,orchestrator:{model:`sonnet`},agents:[{id:`sr-architect`,model:`sonnet`,required:!0},{id:`sr-developer`,model:`sonnet`,required:!0},{id:`sr-reviewer`,model:`sonnet`,required:!0},{id:`sr-merge-resolver`,model:`sonnet`,required:!0}],routing:[{default:!0,agent:`sr-developer`}]},r=await fetch(`${G()}/profiles`,{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 k(),a(t),S.success(e(`profiles.toasts.created`),{description:t})}catch(t){let n=t.message;d(n),S.error(e(`profiles.toasts.createFailed`),{description:n})}finally{m(!1)}},[k]),j=(0,J.useCallback)(async(t,n)=>{T(null),m(!0),d(null);try{let r=await fetch(`${G()}/profiles/${encodeURIComponent(t)}/duplicate`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:n})});if(!r.ok){let t=await r.json().catch(()=>({}));throw Error(t.error??e(`profiles.errors.duplicateFailed`,{status:r.status}))}await k(),a(n),S.success(e(`profiles.toasts.duplicated`),{description:e(`profiles.toasts.duplicatedDescription`,{from:t,to:n})})}catch(t){let n=t.message;d(n),S.error(e(`profiles.toasts.duplicateFailed`),{description:n})}finally{m(!1)}},[k]),M=(0,J.useCallback)(async t=>{O(null),m(!0),d(null);try{let n=await fetch(`${G()}/profiles/${encodeURIComponent(t)}`,{method:`DELETE`});if(!n.ok){let t=await n.json().catch(()=>({}));throw Error(t.error??e(`profiles.errors.deleteFailed`,{status:n.status}))}a(e=>e===t?null:e),await k(),S.success(e(`profiles.toasts.deleted`),{description:t})}catch(t){let n=t.message;d(n),S.error(e(`profiles.toasts.deleteFailed`),{description:n})}finally{m(!1)}},[k]),N=(0,J.useCallback)(()=>x(!0),[]),P=(0,J.useCallback)(e=>T({from:e}),[]),F=(0,J.useCallback)(e=>O({name:e}),[]),L=(0,J.useCallback)(async(t,n)=>{m(!0),d(null);try{let r=await fetch(`${G()}/profiles/${encodeURIComponent(t.name)}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)});if(!r.ok){let t=await r.json().catch(()=>({}));throw Error(t.error??e(`profiles.errors.saveFailed`,{status:r.status}))}s(t),n.length>0?S.warning(e(`profiles.toasts.savedWithUntargeted`),{description:e(`profiles.toasts.savedWithUntargetedDescription`,{agents:n.join(`, `)}),duration:6e3}):S.success(e(`profiles.toasts.saved`),{description:t.name})}catch(t){let n=t.message;d(n),S.error(e(`profiles.toasts.saveFailed`),{description:n})}finally{m(!1)}},[e]),R=(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(be,{open:b,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 ee(e),onCancel:()=>x(!1)}),w&&(0,Y.jsx)(be,{open:!0,title:e(`profiles.duplicateDialog.title`,{name:w.from}),description:e(`profiles.duplicateDialog.description`),placeholder:`${w.from}-copy`,initialValue:`${w.from}-copy`,confirmLabel:e(`common:actions.duplicate`),inputPattern:/^[a-z0-9][a-z0-9-]*$/,inputInvalidHint:e(`profiles.duplicateDialog.invalidHint`),onConfirm:e=>void j(w.from,e),onCancel:()=>T(null)}),E&&(0,Y.jsx)(xe,{open:!0,title:e(`profiles.deleteDialog.title`,{name:E.name}),description:e(`profiles.deleteDialog.description`),confirmLabel:e(`common:actions.delete`),destructive:!0,onConfirm:()=>void M(E.name),onCancel:()=>O(null)})]});return c?(0,Y.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`profiles.loading`)})}):n.length===0?(0,Y.jsxs)(Y.Fragment,{children:[R,(0,Y.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,Y.jsxs)(`div`,{className:`text-center max-w-md`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:e(`profiles.empty.title`)}),(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground mt-1 mb-4`,children:e(`profiles.empty.body`)}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 justify-center`,children:[(0,Y.jsxs)(v,{size:`sm`,onClick:A,disabled:p,children:[(0,Y.jsx)(fe,{className:`w-3.5 h-3.5 mr-1.5`}),` `,e(`profiles.empty.migrateButton`)]}),(0,Y.jsxs)(v,{size:`sm`,variant:`ghost`,onClick:N,disabled:p,children:[(0,Y.jsx)(f,{className:`w-3.5 h-3.5 mr-1.5`}),` `,e(`profiles.empty.blankButton`)]})]}),(0,Y.jsx)(`div`,{className:`text-[11px] text-muted-foreground/70 mt-3`,children:(0,Y.jsx)(H,{t:e,i18nKey:`profiles.empty.migrateExplainer`,components:{code:(0,Y.jsx)(`code`,{className:`text-foreground`})}})}),u&&(0,Y.jsx)(`div`,{className:`mt-3 text-xs text-red-400 aurora-light:text-destructive`,children:u})]})})]}):(0,Y.jsxs)(`div`,{className:`flex flex-col h-full`,children:[R,(0,Y.jsxs)(`div`,{className:`flex flex-1 min-h-0`,children:[(0,Y.jsxs)(`aside`,{className:`w-64 flex-shrink-0 border-r border-border flex flex-col`,children:[(0,Y.jsxs)(`div`,{className:`p-3 flex items-center justify-between`,children:[(0,Y.jsx)(`div`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:e(`profiles.sidebar.title`)}),(0,Y.jsx)(v,{size:`sm`,variant:`ghost`,onClick:N,disabled:p,children:(0,Y.jsx)(f,{className:`w-3.5 h-3.5`})})]}),(0,Y.jsx)(`div`,{className:`flex-1 overflow-auto px-2 pb-3`,children:n.map(t=>(0,Y.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===i?`bg-accent text-foreground`:`text-muted-foreground hover:bg-accent/50 hover:text-foreground`),onClick:()=>a(t.name),role:`button`,tabIndex:0,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&a(t.name)},children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,Y.jsx)(`span`,{className:`truncate font-medium`,children:t.name}),t.isDefault&&(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:e(`profiles.sidebar.teamDefault`)})]}),(0,Y.jsxs)(`div`,{className:`flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity`,children:[(0,Y.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,title:e(`common:actions.duplicate`),onClick:e=>{e.stopPropagation(),P(t.name)},children:(0,Y.jsx)(I,{className:`w-3 h-3`})}),!t.isDefault&&(0,Y.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(),F(t.name)},children:(0,Y.jsx)(C,{className:`w-3 h-3`})})]})]},t.name))})]}),(0,Y.jsxs)(`main`,{className:`flex-1 overflow-auto`,children:[u&&(0,Y.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:u}),o?(0,Y.jsx)(ge,{profile:o,onChange:s,onValidityChange:g,onSoftWarningsChange:e=>y(e.agentsMissingRouting),footer:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)(v,{size:`sm`,onClick:()=>void L(o,_),disabled:p||h.length>0,title:h.length>0?e(`profiles.editorFooter.fixValidationIssues`):void 0,children:[(0,Y.jsx)(D,{className:`w-3.5 h-3.5 mr-1.5`}),e(`common:actions.save`)]}),p&&(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e(`common:states.saving`)}),h.length>0&&(0,Y.jsx)(`span`,{className:`text-xs text-yellow-500 aurora-light:text-accent-warning`,children:e(`profiles.editorFooter.issuesToResolve`,{count:h.length})})]})},o.name):(0,Y.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`profiles.selectPrompt`)})})]})]})]})}function Q(e){let t=e.workflow.map((e,t)=>`${t+1}. ${e}`).join(`
|
|
1
|
+
import{r as e}from"./chunk-CilyBKbf.js";import{$t as t,A as n,B as r,Bt as i,D as a,E as o,Et as s,Gt as c,H as l,Ht as u,I as d,J as f,Jt as p,K as m,Kt as h,L as g,Lt as _,N as v,O as y,Ot as b,Q as x,Qt as S,R as C,Rt as w,St as T,T as E,U as D,Ut as O,Vt as k,Wt as A,X as ee,Xt as j,Yt as M,Z as N,Zt as P,_t as F,ct as I,et as L,f as R,gt as te,ht as z,j as ne,k as B,o as re,ot as V,pt as ie,qt as ae,rt as oe,sn as se,tn as H,w as U,wt as W,xt as ce,yt as le,z as ue,zt as G}from"./index-Wgxn2zBM.js";var K=W(`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`}]]),q=W(`history`,[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}],[`path`,{d:`M12 7v5l4 2`,key:`1fdv2h`}]]),de=W(`pin`,[[`path`,{d:`M12 17v5`,key:`bb1du9`}],[`path`,{d:`M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z`,key:`1nkz8b`}]]),fe=W(`wand-sparkles`,[[`path`,{d:`m21.64 3.64-1.28-1.28a1.21 1.21 0 0 0-1.72 0L2.36 18.64a1.21 1.21 0 0 0 0 1.72l1.28 1.28a1.2 1.2 0 0 0 1.72 0L21.64 5.36a1.2 1.2 0 0 0 0-1.72`,key:`ul74o6`}],[`path`,{d:`m14 7 3 3`,key:`1r5n42`}],[`path`,{d:`M5 6v4`,key:`ilb8ba`}],[`path`,{d:`M19 14v4`,key:`blhpug`}],[`path`,{d:`M10 2v2`,key:`7u0qdc`}],[`path`,{d:`M7 8H3`,key:`zfb6yr`}],[`path`,{d:`M21 16h-4`,key:`1cnmox`}],[`path`,{d:`M11 3H9`,key:`1obp7u`}]]),J=e(se(),1),Y=w(),X=/^[a-z0-9][a-z0-9-]*$/;function pe({open:e,mode:n=`add`,initial:r,chainAgents:i,onConfirm:s,onCancel:c}){let{t:l}=t(`agents`),[u,d]=(0,J.useState)(``),[f,p]=(0,J.useState)(i[0]??``);(0,J.useEffect)(()=>{e&&(n===`edit`&&r?(d(r.tags.join(`, `)),p(i.includes(r.agent)?r.agent:i[0]??``)):(d(``),p(i[0]??``)))},[e,n,r,i]);let m=u.split(`,`).map(e=>e.trim()).filter(Boolean),h=m.filter(e=>!X.test(e)),g=m.length>0&&h.length===0&&i.includes(f);return(0,Y.jsx)(U,{open:e,onOpenChange:e=>{e||c()},children:(0,Y.jsxs)(E,{className:`max-w-md`,children:[(0,Y.jsxs)(y,{children:[(0,Y.jsx)(B,{children:l(n===`edit`?`routingRule.editTitle`:`routingRule.addTitle`)}),(0,Y.jsx)(o,{children:l(n===`edit`?`routingRule.editDescription`:`routingRule.addDescription`)})]}),(0,Y.jsxs)(`div`,{className:`py-2 space-y-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:l(`routingRule.tagsLabel`)}),(0,Y.jsx)(re,{autoFocus:!0,value:u,onChange:e=>d(e.target.value),placeholder:`frontend, ui`,"aria-label":l(`routingRule.tagsLabel`),className:`text-sm font-mono`}),(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground mt-1`,children:(0,Y.jsx)(H,{t:l,i18nKey:`routingRule.tagsHint`,components:{code:(0,Y.jsx)(`code`,{})}})}),h.length>0&&(0,Y.jsx)(`p`,{className:`text-[11px] text-red-400 aurora-light:text-destructive mt-1`,children:l(`routingRule.invalidTags`,{count:h.length,tags:h.join(`, `)})})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:l(`routingRule.routeToLabel`)}),(0,Y.jsx)(`select`,{value:f,onChange:e=>p(e.target.value),"aria-label":l(`routingRule.routeToLabel`),className:`w-full h-9 px-2 text-sm rounded-md border border-border bg-background`,children:i.map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e))}),(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground mt-1`,children:l(`routingRule.routeToHint`)})]})]}),(0,Y.jsxs)(a,{children:[(0,Y.jsx)(v,{variant:`ghost`,size:`sm`,onClick:c,children:l(`common:actions.cancel`)}),(0,Y.jsx)(v,{size:`sm`,onClick:()=>s(m,f),disabled:!g,children:l(n===`edit`?`routingRule.saveChanges`:`routingRule.addRule`)})]})]})})}var Z=new Set([`sr-architect`,`sr-developer`,`sr-reviewer`,`sr-merge-resolver`]),me=[`sonnet`,`opus`,`haiku`],he=/^[a-z0-9][a-z0-9-]*$/;function ge({profile:e,onChange:n,footer:r,onValidityChange:a,onSoftWarningsChange:o}){let{t:s}=t(`agentstudio`),[l,m]=(0,J.useState)([]),[g,_]=(0,J.useState)(!1),[y,b]=(0,J.useState)(!1),[x,S]=(0,J.useState)(null);(0,J.useEffect)(()=>{let e=!1;return fetch(`${G()}/profiles/catalog`).then(e=>e.ok?e.json():{agents:[]}).then(t=>{e||m(t.agents)}).catch(()=>{e||m([])}),()=>{e=!0}},[]);let C=t=>{let r=JSON.parse(JSON.stringify(e));t(r),n(r)},w=new Set(e.agents.map(e=>e.id)),T=l.filter(e=>!w.has(e.id)),E=(0,J.useMemo)(()=>{let t=[];for(let n of Z)e.agents.some(e=>e.id===n)||t.push(s(`profileEditor.validation.missingBaseline`,{agent:n}));let n=e.routing.filter(e=>`default`in e&&e.default===!0);if(n.length>1&&t.push(s(`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(s(`profileEditor.validation.defaultRuleNotLast`))}for(let n of e.routing)if(e.agents.some(e=>e.id===n.agent)||t.push(s(`profileEditor.validation.unknownRoutingAgent`,{agent:n.agent})),`tags`in n){let e=n.tags.filter(e=>!he.test(e));e.length>0&&t.push(s(`profileEditor.validation.invalidTags`,{agent:n.agent,tags:e.join(`, `)}))}return t},[e,s]),D=(0,J.useMemo)(()=>{if(e.routing.length===0)return[];let t=new Set(e.routing.map(e=>e.agent));return e.agents.filter(e=>!Z.has(e.id)&&!t.has(e.id)).map(e=>e.id)},[e]),O=(0,J.useMemo)(()=>e.routing.some(e=>`default`in e&&e.default===!0),[e.routing]);(0,J.useEffect)(()=>{a&&a(E)},[E,a]),(0,J.useEffect)(()=>{o&&o({agentsMissingRouting:D})},[D,o]);let ee=e=>{C(t=>{let n={id:e,model:`sonnet`},r=t.agents.findIndex(e=>e.id===`sr-merge-resolver`);r>=0?t.agents.splice(r,0,n):t.agents.push(n)}),_(!1)},N=t=>{let n=e.agents[t];Z.has(n.id)||C(e=>{e.agents.splice(t,1),e.routing=e.routing.filter(e=>e.agent!==n.id)})},P=(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=k(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})},F=j(M(ae,{activationConstraint:{distance:4}}),M(h,{coordinateGetter:u})),I=e=>{let{active:t,over:n}=e;n&&P(String(t.id),String(n.id))},L=(e,t)=>{C(n=>{n.agents[e].model=t})},R=(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)}),b(!1)},te=()=>{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,ne=(e,t)=>{C(n=>{let r=n.routing[e];r&&(z(r)||(r.agent=t))})},B=(e,t,n)=>{C(r=>{let i=r.routing[e];i&&(z(i)||(i.tags=t,i.agent=n))})},V=e=>{C(t=>{let n=t.routing[e];n&&(z(n)||t.routing.splice(e,1))})},ie=(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,Y.jsxs)(`div`,{className:`p-6 space-y-6 max-w-3xl`,children:[(0,Y.jsx)(pe,{open:y,mode:`add`,chainAgents:e.agents.map(e=>e.id),onConfirm:R,onCancel:()=>b(!1)}),(0,Y.jsx)(pe,{open:x!==null,mode:`edit`,initial:x!==null&&e.routing[x]&&!(`default`in e.routing[x])?{tags:e.routing[x].tags,agent:e.routing[x].agent}:void 0,chainAgents:e.agents.map(e=>e.id),onConfirm:(e,t)=>{x!==null&&(B(x,e,t),S(null))},onCancel:()=>S(null)}),E.length>0&&(0,Y.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,Y.jsx)(`div`,{className:`font-medium mb-1`,children:s(`profileEditor.validationSummary`,{count:E.length})}),(0,Y.jsx)(`ul`,{className:`list-disc list-inside space-y-0.5`,children:E.map((e,t)=>(0,Y.jsx)(`li`,{children:e},t))})]}),(0,Y.jsxs)(`section`,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:s(`profileEditor.nameLabel`)}),(0,Y.jsx)(re,{value:e.name,disabled:!0,className:`text-sm`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:s(`profileEditor.descriptionLabel`)}),(0,Y.jsx)(re,{value:e.description??``,onChange:e=>C(t=>{t.description=e.target.value}),className:`text-sm`,placeholder:s(`profileEditor.descriptionPlaceholder`)})]})]}),(0,Y.jsxs)(`section`,{children:[(0,Y.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide mb-2`,children:s(`profileEditor.orchestrator.heading`)}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 p-3 rounded-md border border-border`,children:[(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-mono text-foreground truncate`,children:`/specrails:implement · /specrails:batch-implement`}),(0,Y.jsx)(`div`,{className:`text-[11px] text-muted-foreground mt-0.5`,children:s(`profileEditor.orchestrator.description`)})]}),(0,Y.jsx)(ye,{value:e.orchestrator.model,onChange:e=>C(t=>{t.orchestrator.model=e})})]})]}),(0,Y.jsxs)(`section`,{children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,Y.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:s(`profileEditor.agentChain.heading`,{n:e.agents.length})}),(0,Y.jsxs)(v,{size:`sm`,variant:`ghost`,onClick:()=>_(e=>!e),disabled:T.length===0,title:T.length===0?s(`profileEditor.agentChain.addDisabledTitle`):s(`profileEditor.agentChain.addTitle`),children:[(0,Y.jsx)(f,{className:`w-3.5 h-3.5 mr-1`}),` `,s(`common:actions.add`)]})]}),g&&(0,Y.jsxs)(`div`,{className:`mb-2 p-2 rounded-md border border-border bg-muted/30`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mb-1.5 px-1`,children:[(0,Y.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:s(`profileEditor.agentChain.pickFromCatalog`,{n:T.length})}),(0,Y.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:()=>_(!1),title:s(`common:actions.close`),children:(0,Y.jsx)(d,{className:`w-3 h-3`})})]}),T.length===0?(0,Y.jsx)(`div`,{className:`px-2 py-3 text-xs text-muted-foreground text-center`,children:s(`profileEditor.agentChain.emptyCatalog`)}):(0,Y.jsx)(`div`,{className:`space-y-0.5 max-h-64 overflow-auto`,children:T.map(e=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>ee(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,Y.jsx)(`span`,{className:`text-sm font-mono`,children:e.id}),(0,Y.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:s(`profileEditor.agentChain.kind.${e.kind}`)})]},e.id))})]}),(0,Y.jsx)(c,{sensors:F,collisionDetection:p,onDragEnd:I,children:(0,Y.jsx)(i,{items:e.agents.map(e=>e.id),strategy:A,children:(0,Y.jsx)(`div`,{className:`space-y-1.5`,children:e.agents.map((e,t)=>(0,Y.jsx)(_e,{agent:e,canRemove:!Z.has(e.id),onModel:e=>L(t,e),onRemove:()=>N(t)},e.id))})})})]}),(0,Y.jsxs)(`section`,{children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,Y.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:s(`profileEditor.routing.heading`,{n:e.routing.length})}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[!O&&(0,Y.jsxs)(v,{size:`sm`,variant:`ghost`,onClick:te,disabled:e.agents.length===0,title:e.agents.length===0?s(`profileEditor.routing.needAgentsTitle`):void 0,children:[(0,Y.jsx)(f,{className:`w-3.5 h-3.5 mr-1`}),` `,s(`profileEditor.routing.addDefault`)]}),(0,Y.jsxs)(v,{size:`sm`,variant:`ghost`,onClick:()=>b(!0),disabled:e.agents.length===0,title:e.agents.length===0?s(`profileEditor.routing.needAgentsTitle`):void 0,children:[(0,Y.jsx)(f,{className:`w-3.5 h-3.5 mr-1`}),` `,s(`profileEditor.routing.addRule`)]})]})]}),(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground mb-2`,children:s(`profileEditor.routing.explainer`)}),D.length>0&&(0,Y.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,Y.jsx)(`div`,{className:`font-medium mb-1`,children:s(`profileEditor.routing.untargetedTitle`)}),(0,Y.jsx)(`div`,{children:(0,Y.jsx)(H,{t:s,i18nKey:`profileEditor.routing.untargetedDetail`,values:{agents:D.join(`, `)},components:{mono:(0,Y.jsx)(`span`,{className:`font-mono`})}})})]}),(0,Y.jsx)(`div`,{className:`space-y-1.5`,children:e.routing.map((t,n)=>{let r=`default`in t&&t.default===!0;return(0,Y.jsx)(ve,{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=>ne(n,e),onEdit:()=>S(n),onUp:()=>ie(n,-1),onDown:()=>ie(n,1),onRemove:()=>V(n)},n)})})]}),r&&(0,Y.jsx)(`div`,{className:`pt-3 border-t border-border`,children:r})]})}function _e({agent:e,canRemove:n,onModel:r,onRemove:i}){let{t:a}=t(`agentstudio`),o=Z.has(e.id),s=e.id===`sr-architect`,c=e.id===`sr-merge-resolver`,{attributes:l,listeners:u,setNodeRef:f,transform:p,transition:m,isDragging:h}=O({id:e.id});return(0,Y.jsxs)(`div`,{ref:f,style:{transform:P.Transform.toString(p),transition:m,opacity:h?.5:void 0,zIndex:h?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,Y.jsx)(`button`,{type:`button`,className:`flex-shrink-0 p-0.5 rounded text-muted-foreground cursor-grab active:cursor-grabbing hover:text-foreground`,title:a(`profileEditor.agentRow.dragTitle`),"aria-label":a(`profileEditor.agentRow.dragHandleAria`),...l,...u,children:(0,Y.jsx)(L,{className:`w-3.5 h-3.5`})}),(0,Y.jsx)(`span`,{className:`text-sm font-mono flex-1 truncate`,children:e.id}),s&&(0,Y.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:a(`profileEditor.agentRow.pinnedFirstTitle`),children:[(0,Y.jsx)(de,{className:`w-2.5 h-2.5 rotate-[135deg]`}),` `,a(`profileEditor.agentRow.pinnedFirst`)]}),c&&(0,Y.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:a(`profileEditor.agentRow.pinnedLastTitle`),children:[(0,Y.jsx)(de,{className:`w-2.5 h-2.5 rotate-45`}),` `,a(`profileEditor.agentRow.pinnedLast`)]}),o&&!s&&!c&&(0,Y.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:a(`profileEditor.agentRow.required`)}),(0,Y.jsx)(ye,{value:e.model??`sonnet`,onChange:r}),(0,Y.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:i,disabled:!n,title:a(n?`common:actions.remove`:`profileEditor.agentRow.requiredRemoveTitle`),children:(0,Y.jsx)(d,{className:`w-3 h-3`})})]})}function ve({rule:e,ordinal:n,isLast:r,canMove:i,canRemove:a,canEdit:o,chainAgents:s,onAgentChange:c,onEdit:l,onUp:u,onDown:f,onRemove:p}){let{t:m}=t(`agentstudio`),h=`default`in e&&e.default===!0;return(0,Y.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,Y.jsxs)(`span`,{className:`text-[10px] font-mono text-muted-foreground w-5 text-center flex-shrink-0`,children:[n,`.`]}),h?(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground flex-1`,children:m(`profileEditor.routingRow.everythingElse`)}):(0,Y.jsx)(`span`,{className:`text-xs flex-1 flex gap-1 flex-wrap items-center`,children:e.tags.map(e=>(0,Y.jsx)(`span`,{className:`px-1.5 py-0.5 rounded bg-muted font-mono text-[11px]`,children:e},e))}),(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`→`}),h?(0,Y.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":m(`profileEditor.routingRow.defaultTargetAria`),title:m(`profileEditor.routingRow.defaultTargetTitle`),children:e.agent}):(0,Y.jsx)(`select`,{value:e.agent,onChange:e=>c(e.target.value),"aria-label":m(`profileEditor.routingRow.targetAria`,{ordinal:n}),className:`h-7 max-w-[15rem] px-2 text-xs font-mono rounded border border-border bg-background`,children:s.map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e))}),(0,Y.jsxs)(`div`,{className:`flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity`,children:[o&&(0,Y.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:l,title:m(`profileEditor.routingRow.editTitle`),"aria-label":m(`profileEditor.routingRow.editAria`,{ordinal:n}),children:(0,Y.jsx)(ee,{className:`w-3 h-3`})}),i&&!r&&(0,Y.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:f,title:m(`profileEditor.routingRow.moveDown`),children:(0,Y.jsx)(T,{className:`w-3 h-3`})}),i&&n>1&&(0,Y.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:u,title:m(`profileEditor.routingRow.moveUp`),children:(0,Y.jsx)(le,{className:`w-3 h-3`})}),a&&(0,Y.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:p,title:m(`common:actions.remove`),children:(0,Y.jsx)(d,{className:`w-3 h-3`})})]}),h&&(0,Y.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,title:m(`profileEditor.routingRow.coreDefaultTitle`),children:m(`profileEditor.routingRow.coreDefaultBadge`)})]})}function ye({value:e,onChange:t}){return(0,Y.jsx)(`select`,{value:e,onChange:e=>t(e.target.value),className:`h-7 px-2 text-xs rounded border border-border bg-background`,children:me.map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e))})}function be({open:e,title:n,description:r,placeholder:i,initialValue:o=``,confirmLabel:s,inputPattern:c,inputInvalidHint:l,onConfirm:u,onCancel:d}){let{t:f}=t(),[p,m]=(0,J.useState)(o);(0,J.useEffect)(()=>{e&&m(o)},[e,o]);let h=p.trim(),g=!c||c.test(h),_=h.length>0&&g;return(0,Y.jsx)(U,{open:e,onOpenChange:e=>{e||d()},children:(0,Y.jsxs)(E,{className:`max-w-md`,children:[(0,Y.jsx)(y,{children:(0,Y.jsx)(B,{children:n})}),(0,Y.jsxs)(`div`,{className:`py-2 space-y-2`,children:[r&&(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r}),(0,Y.jsx)(re,{autoFocus:!0,value:p,placeholder:i,onChange:e=>m(e.target.value),onKeyDown:e=>{e.key===`Enter`&&_&&u(h)},className:`text-sm font-mono`}),h.length>0&&!g&&l&&(0,Y.jsx)(`p`,{className:`text-[11px] text-yellow-500 aurora-light:text-accent-warning`,children:l})]}),(0,Y.jsxs)(a,{children:[(0,Y.jsx)(v,{variant:`ghost`,size:`sm`,onClick:d,children:f(`actions.cancel`)}),(0,Y.jsx)(v,{size:`sm`,onClick:()=>u(h),disabled:!_,children:s??f(`actions.confirm`)})]})]})})}function xe({open:e,title:n,description:r,confirmLabel:i,destructive:o=!1,onConfirm:s,onCancel:c}){let{t:l}=t();return(0,Y.jsx)(U,{open:e,onOpenChange:e=>{e||c()},children:(0,Y.jsxs)(E,{className:`max-w-md`,children:[(0,Y.jsx)(y,{children:(0,Y.jsx)(B,{children:n})}),r&&(0,Y.jsx)(`div`,{className:`py-2`,children:(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r})}),(0,Y.jsxs)(a,{children:[(0,Y.jsx)(v,{variant:`ghost`,size:`sm`,onClick:c,children:l(`actions.cancel`)}),(0,Y.jsx)(v,{size:`sm`,onClick:s,className:o?`bg-red-500 hover:bg-red-600 text-white`:void 0,children:i??l(`actions.confirm`)})]})]})})}function Se(){let{t:e}=t(`agents`),[n,r]=(0,J.useState)([]),[i,a]=(0,J.useState)(null),[o,s]=(0,J.useState)(null),[c,l]=(0,J.useState)(!0),[u,d]=(0,J.useState)(null),[p,m]=(0,J.useState)(!1),[h,g]=(0,J.useState)([]),[_,y]=(0,J.useState)([]),[b,x]=(0,J.useState)(!1),[w,T]=(0,J.useState)(null),[E,O]=(0,J.useState)(null),k=(0,J.useCallback)(async()=>{l(!0),d(null);try{let t=await fetch(`${G()}/profiles`);if(!t.ok)throw Error(e(`profiles.errors.listFailed`,{status:t.status}));let n=await t.json();r(n.profiles),n.profiles.length>0&&!i&&a(n.profiles[0].name)}catch(e){d(e.message)}finally{l(!1)}},[i]);(0,J.useEffect)(()=>{k()},[k]),(0,J.useEffect)(()=>{if(!i){s(null);return}let t=!1;return fetch(`${G()}/profiles/${encodeURIComponent(i)}`).then(t=>{if(!t.ok)throw Error(e(`profiles.errors.loadFailed`,{status:t.status}));return t.json()}).then(e=>{t||s(e.profile)}).catch(e=>{t||d(e.message)}),()=>{t=!0}},[i]);let A=(0,J.useCallback)(async()=>{m(!0),d(null);try{let t=await fetch(`${G()}/profiles/migrate-from-settings`,{method:`POST`});if(!t.ok){let n=await t.json().catch(()=>({}));throw Error(n.error??e(`profiles.errors.migrationFailed`,{status:t.status}))}await k(),a(`default`),S.success(e(`profiles.toasts.migrated`),{description:e(`profiles.toasts.migratedDescription`)})}catch(t){let n=t.message;d(n),S.error(e(`profiles.toasts.migrationFailed`),{description:n})}finally{m(!1)}},[k]),ee=(0,J.useCallback)(async t=>{x(!1),m(!0),d(null);try{let n={schemaVersion:1,name:t,description:``,orchestrator:{model:`sonnet`},agents:[{id:`sr-architect`,model:`sonnet`,required:!0},{id:`sr-developer`,model:`sonnet`,required:!0},{id:`sr-reviewer`,model:`sonnet`,required:!0},{id:`sr-merge-resolver`,model:`sonnet`,required:!0}],routing:[{default:!0,agent:`sr-developer`}]},r=await fetch(`${G()}/profiles`,{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 k(),a(t),S.success(e(`profiles.toasts.created`),{description:t})}catch(t){let n=t.message;d(n),S.error(e(`profiles.toasts.createFailed`),{description:n})}finally{m(!1)}},[k]),j=(0,J.useCallback)(async(t,n)=>{T(null),m(!0),d(null);try{let r=await fetch(`${G()}/profiles/${encodeURIComponent(t)}/duplicate`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:n})});if(!r.ok){let t=await r.json().catch(()=>({}));throw Error(t.error??e(`profiles.errors.duplicateFailed`,{status:r.status}))}await k(),a(n),S.success(e(`profiles.toasts.duplicated`),{description:e(`profiles.toasts.duplicatedDescription`,{from:t,to:n})})}catch(t){let n=t.message;d(n),S.error(e(`profiles.toasts.duplicateFailed`),{description:n})}finally{m(!1)}},[k]),M=(0,J.useCallback)(async t=>{O(null),m(!0),d(null);try{let n=await fetch(`${G()}/profiles/${encodeURIComponent(t)}`,{method:`DELETE`});if(!n.ok){let t=await n.json().catch(()=>({}));throw Error(t.error??e(`profiles.errors.deleteFailed`,{status:n.status}))}a(e=>e===t?null:e),await k(),S.success(e(`profiles.toasts.deleted`),{description:t})}catch(t){let n=t.message;d(n),S.error(e(`profiles.toasts.deleteFailed`),{description:n})}finally{m(!1)}},[k]),N=(0,J.useCallback)(()=>x(!0),[]),P=(0,J.useCallback)(e=>T({from:e}),[]),F=(0,J.useCallback)(e=>O({name:e}),[]),L=(0,J.useCallback)(async(t,n)=>{m(!0),d(null);try{let r=await fetch(`${G()}/profiles/${encodeURIComponent(t.name)}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)});if(!r.ok){let t=await r.json().catch(()=>({}));throw Error(t.error??e(`profiles.errors.saveFailed`,{status:r.status}))}s(t),n.length>0?S.warning(e(`profiles.toasts.savedWithUntargeted`),{description:e(`profiles.toasts.savedWithUntargetedDescription`,{agents:n.join(`, `)}),duration:6e3}):S.success(e(`profiles.toasts.saved`),{description:t.name})}catch(t){let n=t.message;d(n),S.error(e(`profiles.toasts.saveFailed`),{description:n})}finally{m(!1)}},[e]),R=(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(be,{open:b,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 ee(e),onCancel:()=>x(!1)}),w&&(0,Y.jsx)(be,{open:!0,title:e(`profiles.duplicateDialog.title`,{name:w.from}),description:e(`profiles.duplicateDialog.description`),placeholder:`${w.from}-copy`,initialValue:`${w.from}-copy`,confirmLabel:e(`common:actions.duplicate`),inputPattern:/^[a-z0-9][a-z0-9-]*$/,inputInvalidHint:e(`profiles.duplicateDialog.invalidHint`),onConfirm:e=>void j(w.from,e),onCancel:()=>T(null)}),E&&(0,Y.jsx)(xe,{open:!0,title:e(`profiles.deleteDialog.title`,{name:E.name}),description:e(`profiles.deleteDialog.description`),confirmLabel:e(`common:actions.delete`),destructive:!0,onConfirm:()=>void M(E.name),onCancel:()=>O(null)})]});return c?(0,Y.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`profiles.loading`)})}):n.length===0?(0,Y.jsxs)(Y.Fragment,{children:[R,(0,Y.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,Y.jsxs)(`div`,{className:`text-center max-w-md`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:e(`profiles.empty.title`)}),(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground mt-1 mb-4`,children:e(`profiles.empty.body`)}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 justify-center`,children:[(0,Y.jsxs)(v,{size:`sm`,onClick:A,disabled:p,children:[(0,Y.jsx)(fe,{className:`w-3.5 h-3.5 mr-1.5`}),` `,e(`profiles.empty.migrateButton`)]}),(0,Y.jsxs)(v,{size:`sm`,variant:`ghost`,onClick:N,disabled:p,children:[(0,Y.jsx)(f,{className:`w-3.5 h-3.5 mr-1.5`}),` `,e(`profiles.empty.blankButton`)]})]}),(0,Y.jsx)(`div`,{className:`text-[11px] text-muted-foreground/70 mt-3`,children:(0,Y.jsx)(H,{t:e,i18nKey:`profiles.empty.migrateExplainer`,components:{code:(0,Y.jsx)(`code`,{className:`text-foreground`})}})}),u&&(0,Y.jsx)(`div`,{className:`mt-3 text-xs text-red-400 aurora-light:text-destructive`,children:u})]})})]}):(0,Y.jsxs)(`div`,{className:`flex flex-col h-full`,children:[R,(0,Y.jsxs)(`div`,{className:`flex flex-1 min-h-0`,children:[(0,Y.jsxs)(`aside`,{className:`w-64 flex-shrink-0 border-r border-border flex flex-col`,children:[(0,Y.jsxs)(`div`,{className:`p-3 flex items-center justify-between`,children:[(0,Y.jsx)(`div`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:e(`profiles.sidebar.title`)}),(0,Y.jsx)(v,{size:`sm`,variant:`ghost`,onClick:N,disabled:p,children:(0,Y.jsx)(f,{className:`w-3.5 h-3.5`})})]}),(0,Y.jsx)(`div`,{className:`flex-1 overflow-auto px-2 pb-3`,children:n.map(t=>(0,Y.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===i?`bg-accent text-foreground`:`text-muted-foreground hover:bg-accent/50 hover:text-foreground`),onClick:()=>a(t.name),role:`button`,tabIndex:0,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&a(t.name)},children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,Y.jsx)(`span`,{className:`truncate font-medium`,children:t.name}),t.isDefault&&(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:e(`profiles.sidebar.teamDefault`)})]}),(0,Y.jsxs)(`div`,{className:`flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity`,children:[(0,Y.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,title:e(`common:actions.duplicate`),onClick:e=>{e.stopPropagation(),P(t.name)},children:(0,Y.jsx)(I,{className:`w-3 h-3`})}),!t.isDefault&&(0,Y.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(),F(t.name)},children:(0,Y.jsx)(C,{className:`w-3 h-3`})})]})]},t.name))})]}),(0,Y.jsxs)(`main`,{className:`flex-1 overflow-auto`,children:[u&&(0,Y.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:u}),o?(0,Y.jsx)(ge,{profile:o,onChange:s,onValidityChange:g,onSoftWarningsChange:e=>y(e.agentsMissingRouting),footer:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)(v,{size:`sm`,onClick:()=>void L(o,_),disabled:p||h.length>0,title:h.length>0?e(`profiles.editorFooter.fixValidationIssues`):void 0,children:[(0,Y.jsx)(D,{className:`w-3.5 h-3.5 mr-1.5`}),e(`common:actions.save`)]}),p&&(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e(`common:states.saving`)}),h.length>0&&(0,Y.jsx)(`span`,{className:`text-xs text-yellow-500 aurora-light:text-accent-warning`,children:e(`profiles.editorFooter.issuesToResolve`,{count:h.length})})]})},o.name):(0,Y.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`profiles.selectPrompt`)})})]})]})]})}function Q(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{r as e}from"./chunk-CilyBKbf.js";import{t}from"./clsx-CnH-HMk3.js";import{$t as n,Et as r,K as i,Lt as a,Rt as o,Tt as s,an as c,bt as l,c as u,s as d,sn as f,tn as p,v as m,wt as h,zt as g}from"./index-IgMtikGD.js";import{t as _}from"./ExportDropdown-BcmU6I16.js";import{A as v,B as y,C as b,D as x,E as S,F as C,G as w,H as T,I as E,J as D,K as O,L as k,M as A,N as j,O as M,P as N,Q as P,R as F,S as I,T as L,V as R,X as z,Z as B,_ as V,_t as ee,a as H,at as te,b as ne,c as re,ct as ie,et as ae,f as oe,g as se,gt as ce,h as le,i as ue,j as de,k as fe,l as pe,lt as U,m as me,n as he,nt as ge,o as _e,ot as ve,p as ye,pt as W,q as be,r as xe,rt as G,s as Se,st as Ce,t as we,tt as Te,ut as K,v as Ee,x as De,y as Oe,z as ke}from"./BarChart-Cr7__BAU.js";var Ae=h(`arrow-down-right`,[[`path`,{d:`m7 7 10 10`,key:`1fmybs`}],[`path`,{d:`M17 7v10H7`,key:`6fjiku`}]]),q=e(f(),1),J=o();function Y(e){return e>=100?`$${e.toFixed(0)}`:e>=10?`$${e.toFixed(1)}`:`$${e.toFixed(2)}`}function je(e){return e>=1e3?`$${(e/1e3).toFixed(1)}k`:`$${e.toFixed(2)}`}function Me(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:`${e}`}var Ne=[`job`,`explore-spec`,`quick-spec`,`ai-edit`,`smash`];function Pe({data:e,loading:t}){let{t:r}=n(`analytics`),[i,a]=(0,q.useState)(0),o=(0,q.useRef)(0);if((0,q.useEffect)(()=>{if(!e)return;let t=e.summary.totalCostUsd;if(o.current===0&&t>0){let e=performance.now(),n=r=>{let i=Math.min(1,(r-e)/600),o=1-(1-i)**3;a(0+(t-0)*o),i<1&&requestAnimationFrame(n)};requestAnimationFrame(n)}else a(t);o.current=t},[e]),t&&!e)return(0,J.jsx)(`div`,{className:`h-44 rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let s=e.summary.totalCostUsd,c=e.summary.totalRuns,f=e.summary.totalTokens??0,p=e.summary.totalEstimatedCostUsd??0,m=e.summary.deltaPct,h=e.trackingStartedAt,g=p>0,_=Ne.map(t=>{let n=e.bySurface.find(e=>e.surface===t);return{surface:t,costUsd:n?.costUsd??0,count:n?.count??0}});return(0,J.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-gradient-to-br from-card/80 to-card/40 p-5`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-end justify-between gap-3 mb-4`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`div`,{className:`text-[11px] uppercase tracking-wider text-muted-foreground mb-1`,children:r(`hero.spending`)}),(0,J.jsxs)(`div`,{className:`flex items-baseline gap-3`,children:[(0,J.jsx)(`div`,{className:`text-5xl font-semibold tabular-nums tracking-tight`,children:je(i)}),m!==null&&(0,J.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 text-xs font-medium ${m>=0?`text-accent-warning`:`text-accent-success`}`,children:[m>=0?(0,J.jsx)(l,{className:`w-3 h-3`}):(0,J.jsx)(Ae,{className:`w-3 h-3`}),r(`hero.vsPrev`,{pct:Math.abs(m).toFixed(0)})]})]}),(0,J.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-1 tabular-nums flex items-center gap-2`,children:[(0,J.jsx)(`span`,{children:r(`hero.invocations`,{count:c})}),f>0&&(0,J.jsx)(`span`,{className:`text-muted-foreground/80`,title:r(`hero.tokensTooltip`),children:r(`hero.tokens`,{tokens:Me(f)})}),g&&(0,J.jsx)(`span`,{className:`text-[10px] text-muted-foreground/70 italic`,title:r(`hero.includesEstimatedTooltip`,{amount:Y(p)}),children:r(`hero.includesEstimated`,{amount:Y(p)})})]})]}),c===0&&h&&(0,J.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:r(`hero.trackingStarted`,{date:h.slice(0,10)})})]}),c===0?(0,J.jsxs)(`div`,{className:`rounded-lg border border-dashed border-border/40 p-6 text-center`,children:[(0,J.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:r(`hero.emptyState`)}),(0,J.jsx)(`p`,{className:`text-xs text-muted-foreground/70 mt-1`,children:h?r(`hero.trackingStarted`,{date:h.slice(0,10)}):r(`hero.trackingStartedFallback`)})]}):(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`h-3 w-full rounded-full overflow-hidden bg-background-deep flex`,children:_.map(e=>{let t=s>0?e.costUsd/s*100:0;return t===0?null:(0,J.jsx)(`div`,{className:`h-full ${d[e.surface].dot}`,style:{width:`${t}%`},title:r(`hero.segmentTitle`,{label:u[e.surface],value:Y(e.costUsd)})},e.surface)})}),(0,J.jsx)(`div`,{className:`mt-3 flex flex-wrap items-center gap-x-5 gap-y-1.5 text-xs`,children:_.filter(e=>e.costUsd>0).map(e=>(0,J.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 tabular-nums`,children:[(0,J.jsx)(`span`,{className:`w-2 h-2 rounded-full ${d[e.surface].dot}`}),(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:u[e.surface]}),(0,J.jsx)(`span`,{className:`text-foreground font-medium`,children:Y(e.costUsd)}),(0,J.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,J.jsx)(`span`,{className:`text-muted-foreground/80`,children:e.count})]},e.surface))})]})]})}var Fe={claude:`Claude`,codex:`Codex`,gemini:`Gemini`},Ie={claude:`bg-accent-info`,codex:`bg-accent-highlight`,gemini:`bg-accent-success`};function Le(e){return e>=100?`$${e.toFixed(0)}`:e>=10?`$${e.toFixed(1)}`:e>=.01?`$${e.toFixed(2)}`:`$${e.toFixed(4)}`}function Re(e){return Fe[e]??e}function ze(e){return Ie[e]??`bg-accent-secondary`}function Be({data:e,loading:t}){let{t:r}=n(`analytics`);if(t&&!e)return(0,J.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 i=e.byProvider.reduce((e,t)=>e+t.costUsd+t.estimatedCostUsd,0);return(0,J.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,J.jsx)(`div`,{className:`flex items-baseline justify-between mb-3`,children:(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`div`,{className:`text-[11px] uppercase tracking-wider text-muted-foreground`,children:r(`providerCard.title`)}),(0,J.jsx)(`div`,{className:`text-xs text-muted-foreground/70 mt-0.5`,children:(0,J.jsx)(p,{ns:`analytics`,i18nKey:`providerCard.description`,components:{tilde:(0,J.jsx)(`span`,{className:`font-medium`})}})})]})}),i===0?(0,J.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:r(`providerCard.noCost`)}):(0,J.jsxs)(J.Fragment,{children:[(0,J.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,n=i>0?t/i*100:0;return n===0?null:(0,J.jsx)(`div`,{className:`h-full ${ze(e.provider)}`,style:{width:`${n}%`},title:r(`providerCard.segmentTitle`,{label:Re(e.provider),value:Le(t),count:e.count})},e.provider)})}),(0,J.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2`,children:e.byProvider.map(e=>(0,J.jsx)(Ve,{entry:e},e.provider))})]})]})}function Ve({entry:e}){let{t}=n(`analytics`),r=e.costUsd+e.estimatedCostUsd,i=e.costUsd===0&&e.estimatedCostUsd>0;return(0,J.jsxs)(`div`,{className:`flex items-center gap-2.5 rounded-md border border-border/30 px-2.5 py-1.5`,children:[(0,J.jsx)(`span`,{className:`w-2 h-2 rounded-full shrink-0 ${ze(e.provider)}`}),(0,J.jsx)(`span`,{className:`text-xs font-medium`,children:Re(e.provider)}),(0,J.jsx)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:t(`runs`,{count:e.count})}),(0,J.jsxs)(`span`,{className:`ml-auto text-xs font-medium tabular-nums`,children:[i?`~`:``,Le(r)]})]})}var He=[`option`,`isActive`];function X(){return X=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},X.apply(null,arguments)}function Ue(e,t){if(e==null)return{};var n,r,i=We(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 We(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 Ge(e){var{option:t,isActive:n}=e,r=Ue(e,He);return typeof t==`string`?q.createElement(I,X({option:q.createElement(Ce,X({type:t},r)),isActive:n,shapeType:`symbols`},r)):q.createElement(I,X({option:t,isActive:n,shapeType:`symbols`},r))}var Ke=ae([(e,t,n,r,i,a,o)=>F(e,void 0,void 0,o),(e,t,n,r,i,a,o)=>j(e,`xAxis`,t,o),(e,t,n,r,i,a,o)=>N(e,`xAxis`,t,o),(e,t,n,r,i,a,o)=>j(e,`yAxis`,n,o),(e,t,n,r,i,a,o)=>N(e,`yAxis`,n,o),(e,t,n,r)=>E(e,`zAxis`,r,!1),ae([C,(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 st({displayedData:d,xAxis:t,yAxis:r,zAxis:a,scatterSettings:o,xAxisTicks:n,yAxisTicks:i,cells:s})}}),qe=[`id`],Je=[`onMouseEnter`,`onClick`,`onMouseLeave`],Ye=[`animationBegin`,`animationDuration`,`animationEasing`,`hide`,`isAnimationActive`,`legendType`,`lineJointType`,`lineType`,`shape`,`xAxisId`,`yAxisId`,`zAxisId`];function Z(e,t){if(e==null)return{};var n,r,i=Xe(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 Xe(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 Ze(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?Ze(Object(n),!0).forEach(function(t){Qe(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Ze(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function Qe(e,t,n){return(t=$e(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function $e(e){var t=et(e,`string`);return typeof t==`symbol`?t:t+``}function et(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 tt=e=>{var{dataKey:t,name:n,fill:r,legendType:i,hide:a}=e;return[{inactive:a,dataKey:t,type:i,color:r,value:B(n,t),payload:e}]},nt=q.memo(e=>{var{dataKey:t,points:n,stroke:r,strokeWidth:i,fill:a,name:o,hide:s,tooltipType:c,id:l}=e,u={dataDefinedOnItem:n?.map(e=>e.tooltipPayload),getPosition:e=>{var t;return n==null||(t=n[Number(e)])==null?void 0:t.tooltipPosition},settings:{stroke:r,strokeWidth:i,fill:a,nameKey:void 0,dataKey:t,name:B(o,t),hide:s,type:c,color:a,unit:``,graphicalItemId:l}};return q.createElement(Ee,{tooltipEntrySettings:u})});function rt(e){var{points:t,props:n}=e,{line:r,lineType:i,lineJointType:a}=n;if(!r)return null;var o=ce(n),s=ee(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}=ie(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=q.isValidElement(r)?q.cloneElement(r,h):typeof r==`function`?r(h):q.createElement(R,Q({},h,{type:a})),q.createElement(W,{className:`recharts-scatter-line`,key:`recharts-scatter-line`},l)}function it(e){var{showLabels:t,points:n,children:r}=e,i=w(),a=(0,q.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 q.createElement(L,{value:t?a:void 0},r)}function at(e){var{points:t,allOtherScatterProps:n}=e,{shape:r,activeShape:i,dataKey:a}=n,{id:o}=n,s=Z(n,qe),c=ge(de),{onMouseEnter:l,onClick:u,onMouseLeave:d}=n,f=Z(n,Je),p=ne(l,a,o),m=De(d),h=Oe(u,a,o);if(!ve(t))return null;var g=ce(s);return q.createElement(q.Fragment,null,q.createElement(rt,{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,[D]:String(o)});return q.createElement(v,{key:`symbol-${e?.cx}-${e?.cy}-${e?.size}-${t}`,zIndex:a?k.activeDot:void 0},q.createElement(W,Q({className:`recharts-scatter-symbol`},te(f,e,t),{onMouseEnter:p(e,t),onMouseLeave:m(e,t),onClick:h(e,t)}),q.createElement(Ge,Q({option:s,isActive:a},l))))}))}function ot(e){var{previousPointsRef:t,props:n}=e,{points:r,isAnimationActive:i,animationBegin:a,animationDuration:o,animationEasing:s}=n,c=t.current,l=ke(n,`recharts-scatter-`),[u,d]=(0,q.useState)(!1),f=(0,q.useCallback)(()=>{d(!1)},[]),p=(0,q.useCallback)(()=>{d(!0)},[]),m=!u;return q.createElement(it,{showLabels:m,points:r},n.children,q.createElement(y,{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:U(r.cx,t.cx,e),cy:t.cy==null?void 0:U(r.cy,t.cy,e),size:U(r.size,t.size,e)}):$($({},t),{},{size:U(0,t.size,e)})});return e>0&&(t.current=i),q.createElement(W,null,q.createElement(at,{points:i,allOtherScatterProps:n,showLabels:m}))}),q.createElement(S,{label:n.label}))}function st(e){var{displayedData:t,xAxis:n,yAxis:r,zAxis:i,scatterSettings:a,xAxisTicks:o,yAxisTicks:s,cells:c}=e,l=K(n.dataKey)?a.dataKey:n.dataKey,u=K(r.dataKey)?a.dataKey:r.dataKey,d=i&&i.dataKey,f=i?i.range:A.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=P(e,l),g=P(e,u),_=!K(d)&&P(e,d)||`-`,v=[{name:K(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:K(r.dataKey)?a.name:r.name||String(r.dataKey),unit:r.unit||``,value:g,payload:e,dataKey:u,type:a.tooltipType,graphicalItemId:a.id}];_!==`-`&&i!=null&&v.push({name:i.name||i.dataKey,unit:i.unit||``,value:_,payload:e,dataKey:d,type:a.tooltipType,graphicalItemId:a.id});var y=z({axis:n,ticks:o,bandSize:m,entry:e,index:t,dataKey:l}),b=z({axis:r,ticks:s,bandSize:h,entry:e,index:t,dataKey:u}),x=_!==`-`&&i!=null?i.scale.map(_):p,S=x==null?0:Math.sqrt(Math.max(x,0)/Math.PI);return $($({},e),{},{cx:y,cy:b,x:y==null?void 0:y-S,y:b==null?void 0:b-S,width:2*S,height:2*S,size:x,node:{x:f,y:g,z:_},tooltipPayload:v,tooltipPosition:{x:y,y:b},payload:e},c&&c[t]&&c[t].props)})}var ct=(e,t,n)=>({x:e.cx,y:e.cy,value:Number(n===`x`?e.node.x:e.node.y),errorVal:P(e,t)});function lt(e){var{hide:n,points:r,className:i,needClip:a,xAxisId:o,yAxisId:s,id:c}=e,l=(0,q.useRef)(null);if(n)return null;var u=t(`recharts-scatter`,i),d=c;return q.createElement(v,{zIndex:e.zIndex},q.createElement(W,{className:u,clipPath:a?`url(#clipPath-${d})`:void 0,id:c},a&&q.createElement(`defs`,null,q.createElement(_e,{clipPathId:d,xAxisId:o,yAxisId:s})),q.createElement(re,{xAxisId:o,yAxisId:s,data:r,dataPointFormatter:ct,errorBarOffset:0},q.createElement(W,{key:`recharts-scatter-symbols`},q.createElement(ot,{props:e,previousPointsRef:l})))))}var ut={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:k.scatter};function dt(e){var t=G(e,ut),{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=Z(t,Ye),{needClip:h}=Se(d,f),g=(0,q.useMemo)(()=>b(e.children,x),[e.children]),_=be(),v=ge(t=>Ke(t,d,f,p,e.id,g,_));return h==null||v==null?null:q.createElement(q.Fragment,null,q.createElement(nt,{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}),q.createElement(lt,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 ft(e){var t=G(e,ut),n=be();return q.createElement(se,{id:t.id,type:`scatter`},e=>q.createElement(q.Fragment,null,q.createElement(V,{legendPayload:tt(t)}),q.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}),q.createElement(dt,Q({},t,{id:e}))))}var pt=q.memo(ft,T);pt.displayName=`Scatter`;function mt(e){var t=Te(),n=(0,q.useRef)(null);return(0,q.useLayoutEffect)(()=>{n.current===null?t(oe(e)):n.current!==e&&t(me({prev:n.current,next:e})),n.current=e},[e,t]),(0,q.useLayoutEffect)(()=>()=>{n.current&&=(t(ye(n.current)),null)},[t]),null}var ht={zAxisId:0,range:A.range,scale:A.scale,type:A.type};function gt(e){var t=G(e,ht);return q.createElement(mt,{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:A.allowDuplicatedCategory,allowDataOverflow:A.allowDataOverflow,reversed:A.reversed,includeHidden:A.includeHidden})}gt.displayName=`ZAxis`;var _t=[`item`],vt=(0,q.forwardRef)((e,t)=>q.createElement(he,{chartName:`ScatterChart`,defaultTooltipEventType:`item`,validateTooltipEventTypes:_t,tooltipPayloadSearcher:fe,categoricalChartProps:e,ref:t}));function yt({data:e,loading:t}){let{t:r}=n(`analytics`);if(t&&!e)return(0,J.jsx)(`div`,{className:`h-[220px] rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let i={jobs:r(`surfaces.job`),explore:r(`surfaces.exploreSpec`),quick:r(`surfaces.quickSpec`),refine:r(`surfaces.aiEdit`),fileSummaries:r(`surfaces.fileSummary`)},a=e.dailyTimeline.map(e=>({date:e.date.slice(5),[i.jobs]:e.jobsCostUsd,[i.explore]:e.exploreCostUsd,[i.quick]:e.quickCostUsd,[i.refine]:e.aiEditCostUsd,[i.fileSummaries]:e.fileSummaryCostUsd??0})),o=e.dailyTimeline.every(e=>e.jobsCostUsd+e.exploreCostUsd+e.quickCostUsd+e.aiEditCostUsd+(e.fileSummaryCostUsd??0)===0);return(0,J.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,J.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider`,children:r(`timeline.title`)}),(0,J.jsx)(`span`,{className:`text-[10px] text-muted-foreground/70`,children:r(`timeline.subtitle`)})]}),o?(0,J.jsx)(`div`,{className:`h-40 flex items-center justify-center text-xs text-muted-foreground/70`,children:r(`timeline.empty`)}):(0,J.jsx)(`div`,{className:`h-[220px]`,children:(0,J.jsx)(O,{width:`100%`,height:`100%`,children:(0,J.jsxs)(we,{data:a,margin:{top:10,right:10,left:-8,bottom:0},children:[(0,J.jsx)(pe,{strokeDasharray:`2 4`,stroke:`currentColor`,className:`text-border/30`,vertical:!1}),(0,J.jsx)(ue,{dataKey:`date`,tick:{fontSize:10},stroke:`currentColor`,className:`text-muted-foreground`}),(0,J.jsx)(xe,{tick:{fontSize:10},stroke:`currentColor`,className:`text-muted-foreground`,tickFormatter:e=>`$${e}`}),(0,J.jsx)(M,{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,J.jsx)(H,{dataKey:i.jobs,stackId:`a`,fill:`var(--accent-info, #5fa8d3)`}),(0,J.jsx)(H,{dataKey:i.explore,stackId:`a`,fill:`var(--accent-highlight, #c084fc)`}),(0,J.jsx)(H,{dataKey:i.quick,stackId:`a`,fill:`var(--accent-secondary, #f7768e)`}),(0,J.jsx)(H,{dataKey:i.refine,stackId:`a`,fill:`var(--accent-success, #50fa7b)`}),(0,J.jsx)(H,{dataKey:i.fileSummaries,stackId:`a`,fill:`var(--accent-warning, #f1fa8c)`})]})})})]})}function bt(e){return e==null?`—`:e<.005?`$${e.toFixed(4)}`:e<1?`$${e.toFixed(3)}`:`$${e.toFixed(2)}`}function xt(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 St({values:e}){let t=Math.max(1e-4,...e);return(0,J.jsx)(`div`,{className:`flex items-end gap-[1px] h-5`,children:e.map((e,n)=>(0,J.jsx)(`div`,{className:`w-[3px] rounded-sm bg-foreground/40`,style:{height:`${Math.max(2,e/t*20)}px`}},n))})}function Ct({mode:e,label:t,accentClass:r}){let{t:i}=n(`analytics`),a=e.mode===`explore`&&e.totalRuns<5;return(0,J.jsxs)(`div`,{className:`flex-1 p-4 first:pr-2 last:pl-2`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,J.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full ${r}`}),(0,J.jsx)(`span`,{className:`text-xs font-medium uppercase tracking-wider text-muted-foreground`,children:t})]}),a?(0,J.jsxs)(`div`,{className:`py-3`,children:[(0,J.jsx)(`p`,{className:`text-sm text-foreground`,children:i(`quickVsExplore.sparseCta`)}),(0,J.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:i(`quickVsExplore.runsSoFar`,{count:e.totalRuns})})]}):(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`text-3xl font-semibold tabular-nums tracking-tight`,children:bt(e.avgCostPerSpec)}),(0,J.jsx)(`div`,{className:`text-[11px] text-muted-foreground mt-0.5`,children:i(`quickVsExplore.perSpec`)}),(0,J.jsx)(`div`,{className:`mt-3`,children:(0,J.jsx)(St,{values:e.sparkline.length>0?e.sparkline:[0]})}),(0,J.jsxs)(`div`,{className:`mt-3 space-y-0.5 text-xs tabular-nums text-muted-foreground`,children:[(0,J.jsx)(`div`,{children:(0,J.jsx)(p,{ns:`analytics`,i18nKey:`quickVsExplore.createdRuns`,values:{created:e.ticketsCreated,runs:e.totalRuns},components:{strong:(0,J.jsx)(`span`,{className:`text-foreground font-medium`})}})}),(0,J.jsx)(`div`,{children:i(`quickVsExplore.avgDuration`,{duration:xt(e.avgDurationMs)})}),(0,J.jsx)(`div`,{className:`truncate`,children:e.dominantModel??`—`})]})]})]})}function wt({data:e,loading:t}){let{t:r}=n(`analytics`);if(t&&!e)return(0,J.jsx)(`div`,{className:`h-[220px] rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let i=e.byMode.find(e=>e.mode===`quick`),a=e.byMode.find(e=>e.mode===`explore`);if(!i||!a)return null;let o=i.avgCostPerSpec&&a.avgCostPerSpec&&i.avgCostPerSpec>0?a.avgCostPerSpec/i.avgCostPerSpec:null,s=o!==null&&i.totalRuns>=1&&a.totalRuns>=5;return(0,J.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40`,children:[(0,J.jsx)(`div`,{className:`px-4 pt-3 pb-1`,children:(0,J.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider`,children:r(`quickVsExplore.title`)})}),(0,J.jsxs)(`div`,{className:`flex divide-x divide-border/40`,children:[(0,J.jsx)(Ct,{mode:i,label:r(`quickVsExplore.quick`),accentClass:`bg-accent-secondary`}),(0,J.jsx)(Ct,{mode:a,label:r(`quickVsExplore.explore`),accentClass:`bg-accent-highlight`})]}),s&&(0,J.jsx)(`div`,{className:`px-4 pb-3 -mt-1`,children:(0,J.jsx)(`div`,{className:`text-center text-[11px] text-muted-foreground tabular-nums`,children:(0,J.jsxs)(`span`,{className:`px-2`,children:[`━━━━━━ `,r(`quickVsExplore.ratio`,{ratio:o.toFixed(1)}),` ━━━━━━`]})})})]})}function Tt({data:e,loading:t,onSelectModel:r,activeModel:i}){let{t:a}=n(`analytics`);if(t&&!e)return(0,J.jsx)(`div`,{className:`h-[220px] rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let o=e.byModel.reduce((e,t)=>e+t.costUsd,0),s=e.byModel.slice(0,5);return(0,J.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,J.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider mb-3`,children:a(`models.title`)}),s.length===0?(0,J.jsx)(`div`,{className:`h-32 flex items-center justify-center text-xs text-muted-foreground/70`,children:a(`models.empty`)}):(0,J.jsx)(`ul`,{className:`space-y-1.5`,children:s.map(e=>{let t=o>0?e.costUsd/o*100:0,n=i===e.model;return(0,J.jsx)(`li`,{children:(0,J.jsxs)(`button`,{type:`button`,onClick:()=>r(e.model),className:`w-full text-left group rounded-md px-2 py-1.5 transition-colors ${n?`bg-accent-highlight/10 ring-1 ring-accent-highlight/30`:`hover:bg-accent/30`}`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between text-[12px] mb-1 tabular-nums`,children:[(0,J.jsx)(`span`,{className:`truncate font-medium`,children:e.model}),(0,J.jsxs)(`span`,{className:`text-muted-foreground`,children:[`$`,e.costUsd.toFixed(2),` · `,e.count]})]}),(0,J.jsx)(`div`,{className:`h-1.5 rounded-full bg-background-deep overflow-hidden`,children:(0,J.jsx)(`div`,{className:`h-full ${n?`bg-accent-highlight`:`bg-foreground/40 group-hover:bg-foreground/60`} transition-colors`,style:{width:`${t}%`}})})]})},e.model)})})]})}var Et={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)`};function Dt({data:e,loading:t,onSelectPoint:r}){let{t:i}=n(`analytics`);if(t&&!e)return(0,J.jsx)(`div`,{className:`h-[260px] rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let a=[`job`,`quick-spec`,`explore-spec`,`ai-edit`,`smash`],o=a.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}))})),s=e.scatter.length===0;return(0,J.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,J.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider`,children:i(`scatter.title`)}),(0,J.jsx)(`div`,{className:`flex flex-wrap items-center gap-2 text-[10px]`,children:a.map(e=>(0,J.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,J.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full`,style:{background:Et[e]}}),(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:u[e]})]},e))})]}),s?(0,J.jsx)(`div`,{className:`h-40 flex items-center justify-center text-xs text-muted-foreground/70`,children:i(`scatter.empty`)}):(0,J.jsx)(`div`,{className:`h-[260px]`,children:(0,J.jsx)(O,{width:`100%`,height:`100%`,children:(0,J.jsxs)(vt,{margin:{top:10,right:10,left:-8,bottom:5},children:[(0,J.jsx)(pe,{strokeDasharray:`2 4`,stroke:`currentColor`,className:`text-border/30`}),(0,J.jsx)(ue,{type:`number`,dataKey:`x`,name:`turns`,tick:{fontSize:10},stroke:`currentColor`,className:`text-muted-foreground`,label:{value:i(`scatter.turnsLabel`),position:`insideBottomRight`,offset:-2,fontSize:10,fill:`currentColor`}}),(0,J.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,J.jsx)(gt,{range:[40,80]}),(0,J.jsx)(M,{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)}`,i(`scatter.costLabel`)]:[String(e),n===`turns`?i(`scatter.turnsLabel`):n]}}),o.map(e=>(0,J.jsx)(pt,{data:e.points,fill:Et[e.surface],onClick:e=>{let t=e;t?.raw&&r(t.raw)}},e.surface))]})})})]})}function Ot({data:e,loading:t,onSelectTicket:r}){let{t:i}=n(`analytics`);if(t&&!e)return(0,J.jsx)(`div`,{className:`h-40 rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let a=e.topTickets;return(0,J.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,J.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider mb-3`,children:i(`topTickets.title`)}),a.length===0?(0,J.jsx)(`div`,{className:`h-32 flex items-center justify-center text-xs text-muted-foreground/70`,children:i(`topTickets.empty`)}):(0,J.jsx)(`ul`,{className:`divide-y divide-border/30`,children:a.map((e,t)=>{let n=Object.entries(e.bySurface).filter(([,e])=>e.count>0).map(([e,t])=>i(`topTickets.breakdownItem`,{n:t.count,label:u[e].toLowerCase()})).join(` + `),a=e.isUnattributed,o=a?i(`topTickets.unattributed`):e.ticketTitle?`#${e.ticketId} ${e.ticketTitle}`:i(`topTickets.deletedTicket`,{id:e.ticketId});return(0,J.jsx)(`li`,{children:(0,J.jsxs)(`button`,{type:`button`,onClick:()=>r(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 ${!e.ticketTitle&&!a?`opacity-50`:``}`,disabled:a,children:[(0,J.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,J.jsx)(`div`,{className:`text-sm truncate`,children:o}),(0,J.jsx)(`div`,{className:`text-[11px] text-muted-foreground truncate`,children:n||`—`})]}),(0,J.jsxs)(`div`,{className:`text-right tabular-nums`,children:[(0,J.jsxs)(`div`,{className:`text-sm font-medium`,children:[`$`,e.totalCostUsd.toFixed(2)]}),(0,J.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:i(`runs`,{count:e.totalRuns})})]})]})},`${e.ticketId??`u`}-${t}`)})})]})}function kt(e){return e==null?`—`:e<.005?`$${e.toFixed(4)}`:`$${e.toFixed(2)}`}function At(e){return e==null?`—`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function jt(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 Mt(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 Nt(e,t){if(e.model)return e.model;if(!jt(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 Pt({rows:e,loading:t,truncated:r,totalAvailable:i,tableFilters:a,onTableFiltersChange:o}){let{t:s}=n(`analytics`),[c,l]=(0,q.useState)(null),f=Mt(e);return(0,J.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 mb-3`,children:[(0,J.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider`,children:s(`table.title`)}),(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-[11px]`,children:[(0,J.jsxs)(`select`,{value:a.status??``,onChange:e=>o({...a,status:e.target.value||void 0}),className:`h-7 px-2 rounded-md bg-background-deep border border-border/60 text-xs`,"aria-label":s(`table.statusFilterAria`),children:[(0,J.jsx)(`option`,{value:``,children:s(`table.allStatus`)}),(0,J.jsx)(`option`,{value:`success`,children:s(`table.success`)}),(0,J.jsx)(`option`,{value:`failed`,children:s(`table.failed`)}),(0,J.jsx)(`option`,{value:`aborted`,children:s(`table.aborted`)})]}),(0,J.jsx)(`input`,{type:`number`,step:`0.01`,min:`0`,placeholder:s(`table.minCostPlaceholder`),value:a.minCostUsd??``,onChange:e=>{let t=e.target.value===``?void 0:parseFloat(e.target.value);o({...a,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":s(`table.minCostFilterAria`)})]})]}),t?(0,J.jsx)(`div`,{className:`h-32 rounded bg-card/30 animate-pulse`}):e.length===0?(0,J.jsx)(`div`,{className:`h-32 flex items-center justify-center text-xs text-muted-foreground/70`,children:s(`table.empty`)}):(0,J.jsx)(`div`,{className:`overflow-x-auto`,children:(0,J.jsxs)(`table`,{className:`w-full text-[12px] tabular-nums`,children:[(0,J.jsx)(`thead`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:(0,J.jsxs)(`tr`,{className:`text-left`,children:[(0,J.jsx)(`th`,{className:`font-medium px-2 py-2`,children:s(`table.colSurface`)}),(0,J.jsx)(`th`,{className:`font-medium px-2 py-2`,children:s(`table.colTicket`)}),(0,J.jsx)(`th`,{className:`font-medium px-2 py-2 text-right`,children:s(`table.colCost`)}),(0,J.jsx)(`th`,{className:`font-medium px-2 py-2 text-right`,children:s(`table.colTurns`)}),(0,J.jsx)(`th`,{className:`font-medium px-2 py-2 text-right`,children:s(`table.colTokens`)}),(0,J.jsx)(`th`,{className:`font-medium px-2 py-2`,children:s(`table.colModel`)}),(0,J.jsx)(`th`,{className:`font-medium px-2 py-2`,children:s(`table.colStatus`)}),(0,J.jsx)(`th`,{className:`font-medium px-2 py-2`,children:s(`table.colStarted`)})]})}),(0,J.jsx)(`tbody`,{children:e.map(e=>{let t=e.surface,n=d[t],r=(e.tokens_in??0)+(e.tokens_out??0)+(e.tokens_cache_read??0)+(e.tokens_cache_create??0),i=jt(e),a=i?s(`table.contractLayer`):u[t],o=Nt(e,f);return(0,J.jsxs)(`tr`,{onClick:()=>l(c===e.id?null:e.id),className:`border-t border-border/30 hover:bg-accent/30 cursor-pointer`,children:[(0,J.jsx)(`td`,{className:`px-2 py-2`,children:(0,J.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,J.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full ${n.dot}`}),a]})}),(0,J.jsx)(`td`,{className:`px-2 py-2 max-w-[260px]`,children:e.ticket_id==null?e.ticket_title?(0,J.jsx)(`span`,{className:`truncate block text-muted-foreground/90 italic`,title:s(`table.provisionalTitleTooltip`),children:e.ticket_title}):(0,J.jsx)(`span`,{className:`text-muted-foreground/70`,children:`—`}):(0,J.jsxs)(`span`,{className:`truncate block`,children:[`#`,e.ticket_id,` `,i?(0,J.jsx)(`span`,{className:`text-muted-foreground/90`,children:s(`table.contractLayerRefinement`)}):e.ticket_title??(0,J.jsx)(`span`,{className:`text-muted-foreground/70 italic`,children:s(`table.deleted`)})]})}),(0,J.jsx)(`td`,{className:`px-2 py-2 text-right font-medium`,children:e.total_cost_usd_estimated===1&&e.total_cost_usd!=null?(0,J.jsxs)(`span`,{title:s(`table.estimatedCostTooltip`),className:`text-muted-foreground/90`,children:[`~`,kt(e.total_cost_usd)]}):kt(e.total_cost_usd)}),(0,J.jsx)(`td`,{className:`px-2 py-2 text-right`,children:At(e.num_turns)}),(0,J.jsx)(`td`,{className:`px-2 py-2 text-right`,children:r>0?At(r):`—`}),(0,J.jsxs)(`td`,{className:`px-2 py-2 max-w-[180px] truncate`,children:[o??`—`,o&&!e.model?(0,J.jsx)(`span`,{className:`ml-1 text-[10px] text-muted-foreground/70`,children:s(`table.inferred`)}):null]}),(0,J.jsxs)(`td`,{className:`px-2 py-2`,children:[e.status===`success`?(0,J.jsx)(`span`,{className:`text-accent-success/90`,children:`●`}):e.status===`failed`?(0,J.jsx)(`span`,{className:`text-accent-warning`,children:`⚠`}):(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:`○`}),(0,J.jsx)(`span`,{className:`ml-1 text-muted-foreground`,children:s(`table.statusValue.${e.status}`)})]}),(0,J.jsx)(`td`,{className:`px-2 py-2 text-muted-foreground`,children:e.started_at.slice(0,16).replace(`T`,` `)})]},e.id)})})]})}),r&&(0,J.jsx)(`div`,{className:`mt-2 text-[11px] text-muted-foreground/80`,children:s(`table.truncated`,{shown:e.length,total:i.toLocaleString()})})]})}var Ft=[{value:`7d`,labelKey:`periods.d7`},{value:`30d`,labelKey:`periods.d30`},{value:`90d`,labelKey:`periods.d90`},{value:`all`,labelKey:`periods.all`}],It=[{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`}];function Lt(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.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)),t.toString()}function Rt(){let{t:e}=n(`analytics`),{activeProjectId:t,projects:o}=r(),[l,u]=c(),d=o.find(e=>e.id===t),f=d?s(d):[`claude`],p=f.length>1,h=l.get(`period`)??`30d`,v=(l.get(`surface`)??``).split(`,`).filter(Boolean),y=(l.get(`provider`)??``).split(`,`).filter(Boolean),b=l.get(`ticketId`),[x,S]=(0,q.useState)({period:h,surface:v.length>0?v:void 0,provider:y.length>0?y:void 0,ticketId:b?Number(b):void 0}),[C,w]=(0,q.useState)(null),[T,E]=(0,q.useState)(!0),[D,O]=(0,q.useState)(null),[k,A]=(0,q.useState)({}),[j,M]=(0,q.useState)(null),N=(0,q.useRef)(new Map),P=(0,q.useRef)(0);(0,q.useEffect)(()=>{let e=new URLSearchParams;e.set(`period`,x.period),x.surface&&x.surface.length>0&&e.set(`surface`,x.surface.join(`,`)),x.provider&&x.provider.length>0&&e.set(`provider`,x.provider.join(`,`)),x.ticketId&&e.set(`ticketId`,String(x.ticketId)),u(e,{replace:!0})},[x.period,x.surface,x.provider,x.ticketId,u]);let F=(0,q.useCallback)(async()=>{if(!t)return;let e=++P.current;O(null);let n=`${t}:${Lt(x)}`,r=N.current.get(n);r?(w(r),E(!1)):E(!0);try{let t=await fetch(`${g()}/spending?${Lt(x)}`);if(!t.ok)throw Error(`HTTP ${t.status}`);if(e!==P.current)return;let r=await t.json();N.current.set(n,r),w(r),E(!1)}catch(t){if(e!==P.current)return;O(t.message),E(!1)}},[t,x]),I=(0,q.useCallback)(async()=>{if(!t)return;let e={...x};k.model&&(e.model=[k.model]),k.status&&(e.status=k.status),typeof k.minCostUsd==`number`&&(e.minCostUsd=k.minCostUsd);try{let t=await fetch(`${g()}/invocations?${Lt(e)}&limit=100`);if(!t.ok)throw Error(`HTTP ${t.status}`);M(await t.json())}catch{M(null)}},[t,x,k]);(0,q.useEffect)(()=>{F()},[F]),(0,q.useEffect)(()=>{I()},[I]);let L=(0,q.useRef)(null),R=a();(0,q.useEffect)(()=>{let e=`analytics-spending`;return R.registerHandler(e,e=>{let n=e;n.type===`spending.invalidated`&&n.projectId===t&&(L.current&&clearTimeout(L.current),L.current=setTimeout(()=>{N.current.clear(),F(),I()},500))}),()=>{R.unregisterHandler(e)}},[R,t,F,I]);function z(e){if(e===`all`){S(e=>({...e,surface:void 0}));return}S(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}})}function B(e){if(e===`all`){S(e=>({...e,provider:void 0}));return}S(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 V=x.surface,ee=!V||V.length===0,H=x.provider,te=!H||H.length===0,ne=(0,q.useMemo)(()=>{let e={period:x.period};return x.surface&&x.surface.length>0&&(e.surface=x.surface.join(`,`)),x.provider&&x.provider.length>0&&(e.provider=x.provider.join(`,`)),x.ticketId&&(e.ticketId=String(x.ticketId)),e},[x]),re=C?C.summary.totalRuns===0:!1;return(0,J.jsxs)(`div`,{className:`flex flex-col gap-6 p-4 pb-12`,children:[(0,J.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,J.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,J.jsx)(`h1`,{className:`text-base font-semibold tracking-tight`,children:e(`page.title`)}),x.ticketId&&(0,J.jsx)(`button`,{type:`button`,onClick:()=>S(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:x.ticketId})})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(`div`,{className:`flex items-center gap-1 rounded-md border border-border/60 bg-card/40 p-0.5`,children:Ft.map(t=>(0,J.jsx)(`button`,{type:`button`,onClick:()=>S(e=>({...e,period:t.value})),className:`px-2.5 h-6 rounded text-[11px] font-medium transition-colors ${x.period===t.value?`bg-accent text-foreground`:`text-muted-foreground hover:text-foreground`}`,children:e(t.labelKey)},t.value))}),(0,J.jsx)(_,{baseUrl:`${g()}/analytics/export`,params:ne,disabled:re}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>{N.current.clear(),F(),I()},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,J.jsx)(i,{className:`w-3 h-3`})})]})]}),(0,J.jsx)(`div`,{className:`mt-3 flex flex-wrap items-center gap-1.5`,children:It.map(t=>(0,J.jsx)(`button`,{type:`button`,onClick:()=>z(t.value),className:`h-7 px-3 rounded-full text-[11px] font-medium transition-all ${(t.value===`all`?ee:V?.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,J.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-1.5`,"data-testid":`analytics-provider-chips`,children:[(0,J.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-muted-foreground/70 mr-1`,children:e(`page.engine`)}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>B(`all`),className:`h-7 px-3 rounded-full text-[11px] font-medium transition-all ${te?`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,J.jsx)(`button`,{type:`button`,onClick:()=>B(e),className:`h-7 px-3 rounded-full text-[11px] font-medium transition-all ${H?.includes(e)??!1?`bg-foreground/10 text-foreground ring-1 ring-foreground/20`:`text-muted-foreground hover:text-foreground hover:bg-accent/40`}`,children:m(e)},e))]})]}),D&&(0,J.jsxs)(`div`,{className:`rounded-lg border border-accent-warning/30 bg-accent-warning/10 p-4 flex items-center justify-between`,children:[(0,J.jsx)(`p`,{className:`text-sm text-accent-warning`,children:e(`page.failedToLoad`,{error:D})}),(0,J.jsxs)(`button`,{onClick:()=>F(),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,J.jsx)(i,{className:`w-3 h-3`}),e(`common:actions.retry`)]})]}),(0,J.jsx)(Pe,{data:C,loading:T}),(0,J.jsx)(Be,{data:C,loading:T}),(0,J.jsx)(yt,{data:C,loading:T}),(0,J.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4`,children:[(0,J.jsx)(wt,{data:C,loading:T}),(0,J.jsx)(Tt,{data:C,loading:T,onSelectModel:e=>S(t=>({...t,model:[e]})),activeModel:x.model?.[0]})]}),(0,J.jsx)(Dt,{data:C,loading:T,onSelectPoint:e=>{A(e=>({...e})),S(t=>({...t,ticketId:e.ticketId??void 0}))}}),(0,J.jsx)(Ot,{data:C,loading:T,onSelectTicket:e=>S(t=>({...t,ticketId:e??void 0}))}),(0,J.jsx)(Pt,{rows:j?.rows??[],loading:T&&!j,truncated:j?.truncated??!1,totalAvailable:j?.totalAvailable??0,tableFilters:k,onTableFiltersChange:A})]})}export{Rt as default};
|
|
1
|
+
import{r as e}from"./chunk-CilyBKbf.js";import{t}from"./clsx-CnH-HMk3.js";import{$t as n,Et as r,K as i,Lt as a,Rt as o,Tt as s,an as c,bt as l,c as u,s as d,sn as f,tn as p,v as m,wt as h,zt as g}from"./index-Wgxn2zBM.js";import{t as _}from"./ExportDropdown-DFEuLgiK.js";import{A as v,B as y,C as b,D as x,E as S,F as C,G as w,H as T,I as E,J as D,K as O,L as k,M as A,N as j,O as M,P as N,Q as P,R as F,S as I,T as L,V as R,X as z,Z as B,_ as V,_t as ee,a as H,at as te,b as ne,c as re,ct as ie,et as ae,f as oe,g as se,gt as ce,h as le,i as ue,j as de,k as fe,l as pe,lt as U,m as me,n as he,nt as ge,o as _e,ot as ve,p as ye,pt as W,q as be,r as xe,rt as G,s as Se,st as Ce,t as we,tt as Te,ut as K,v as Ee,x as De,y as Oe,z as ke}from"./BarChart-BaJJVLw4.js";var Ae=h(`arrow-down-right`,[[`path`,{d:`m7 7 10 10`,key:`1fmybs`}],[`path`,{d:`M17 7v10H7`,key:`6fjiku`}]]),q=e(f(),1),J=o();function Y(e){return e>=100?`$${e.toFixed(0)}`:e>=10?`$${e.toFixed(1)}`:`$${e.toFixed(2)}`}function je(e){return e>=1e3?`$${(e/1e3).toFixed(1)}k`:`$${e.toFixed(2)}`}function Me(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:`${e}`}var Ne=[`job`,`explore-spec`,`quick-spec`,`ai-edit`,`smash`];function Pe({data:e,loading:t}){let{t:r}=n(`analytics`),[i,a]=(0,q.useState)(0),o=(0,q.useRef)(0);if((0,q.useEffect)(()=>{if(!e)return;let t=e.summary.totalCostUsd;if(o.current===0&&t>0){let e=performance.now(),n=r=>{let i=Math.min(1,(r-e)/600),o=1-(1-i)**3;a(0+(t-0)*o),i<1&&requestAnimationFrame(n)};requestAnimationFrame(n)}else a(t);o.current=t},[e]),t&&!e)return(0,J.jsx)(`div`,{className:`h-44 rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let s=e.summary.totalCostUsd,c=e.summary.totalRuns,f=e.summary.totalTokens??0,p=e.summary.totalEstimatedCostUsd??0,m=e.summary.deltaPct,h=e.trackingStartedAt,g=p>0,_=Ne.map(t=>{let n=e.bySurface.find(e=>e.surface===t);return{surface:t,costUsd:n?.costUsd??0,count:n?.count??0}});return(0,J.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-gradient-to-br from-card/80 to-card/40 p-5`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-end justify-between gap-3 mb-4`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`div`,{className:`text-[11px] uppercase tracking-wider text-muted-foreground mb-1`,children:r(`hero.spending`)}),(0,J.jsxs)(`div`,{className:`flex items-baseline gap-3`,children:[(0,J.jsx)(`div`,{className:`text-5xl font-semibold tabular-nums tracking-tight`,children:je(i)}),m!==null&&(0,J.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 text-xs font-medium ${m>=0?`text-accent-warning`:`text-accent-success`}`,children:[m>=0?(0,J.jsx)(l,{className:`w-3 h-3`}):(0,J.jsx)(Ae,{className:`w-3 h-3`}),r(`hero.vsPrev`,{pct:Math.abs(m).toFixed(0)})]})]}),(0,J.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-1 tabular-nums flex items-center gap-2`,children:[(0,J.jsx)(`span`,{children:r(`hero.invocations`,{count:c})}),f>0&&(0,J.jsx)(`span`,{className:`text-muted-foreground/80`,title:r(`hero.tokensTooltip`),children:r(`hero.tokens`,{tokens:Me(f)})}),g&&(0,J.jsx)(`span`,{className:`text-[10px] text-muted-foreground/70 italic`,title:r(`hero.includesEstimatedTooltip`,{amount:Y(p)}),children:r(`hero.includesEstimated`,{amount:Y(p)})})]})]}),c===0&&h&&(0,J.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:r(`hero.trackingStarted`,{date:h.slice(0,10)})})]}),c===0?(0,J.jsxs)(`div`,{className:`rounded-lg border border-dashed border-border/40 p-6 text-center`,children:[(0,J.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:r(`hero.emptyState`)}),(0,J.jsx)(`p`,{className:`text-xs text-muted-foreground/70 mt-1`,children:h?r(`hero.trackingStarted`,{date:h.slice(0,10)}):r(`hero.trackingStartedFallback`)})]}):(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`h-3 w-full rounded-full overflow-hidden bg-background-deep flex`,children:_.map(e=>{let t=s>0?e.costUsd/s*100:0;return t===0?null:(0,J.jsx)(`div`,{className:`h-full ${d[e.surface].dot}`,style:{width:`${t}%`},title:r(`hero.segmentTitle`,{label:u[e.surface],value:Y(e.costUsd)})},e.surface)})}),(0,J.jsx)(`div`,{className:`mt-3 flex flex-wrap items-center gap-x-5 gap-y-1.5 text-xs`,children:_.filter(e=>e.costUsd>0).map(e=>(0,J.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 tabular-nums`,children:[(0,J.jsx)(`span`,{className:`w-2 h-2 rounded-full ${d[e.surface].dot}`}),(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:u[e.surface]}),(0,J.jsx)(`span`,{className:`text-foreground font-medium`,children:Y(e.costUsd)}),(0,J.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,J.jsx)(`span`,{className:`text-muted-foreground/80`,children:e.count})]},e.surface))})]})]})}var Fe={claude:`Claude`,codex:`Codex`,gemini:`Gemini`},Ie={claude:`bg-accent-info`,codex:`bg-accent-highlight`,gemini:`bg-accent-success`};function Le(e){return e>=100?`$${e.toFixed(0)}`:e>=10?`$${e.toFixed(1)}`:e>=.01?`$${e.toFixed(2)}`:`$${e.toFixed(4)}`}function Re(e){return Fe[e]??e}function ze(e){return Ie[e]??`bg-accent-secondary`}function Be({data:e,loading:t}){let{t:r}=n(`analytics`);if(t&&!e)return(0,J.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 i=e.byProvider.reduce((e,t)=>e+t.costUsd+t.estimatedCostUsd,0);return(0,J.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,J.jsx)(`div`,{className:`flex items-baseline justify-between mb-3`,children:(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`div`,{className:`text-[11px] uppercase tracking-wider text-muted-foreground`,children:r(`providerCard.title`)}),(0,J.jsx)(`div`,{className:`text-xs text-muted-foreground/70 mt-0.5`,children:(0,J.jsx)(p,{ns:`analytics`,i18nKey:`providerCard.description`,components:{tilde:(0,J.jsx)(`span`,{className:`font-medium`})}})})]})}),i===0?(0,J.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:r(`providerCard.noCost`)}):(0,J.jsxs)(J.Fragment,{children:[(0,J.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,n=i>0?t/i*100:0;return n===0?null:(0,J.jsx)(`div`,{className:`h-full ${ze(e.provider)}`,style:{width:`${n}%`},title:r(`providerCard.segmentTitle`,{label:Re(e.provider),value:Le(t),count:e.count})},e.provider)})}),(0,J.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2`,children:e.byProvider.map(e=>(0,J.jsx)(Ve,{entry:e},e.provider))})]})]})}function Ve({entry:e}){let{t}=n(`analytics`),r=e.costUsd+e.estimatedCostUsd,i=e.costUsd===0&&e.estimatedCostUsd>0;return(0,J.jsxs)(`div`,{className:`flex items-center gap-2.5 rounded-md border border-border/30 px-2.5 py-1.5`,children:[(0,J.jsx)(`span`,{className:`w-2 h-2 rounded-full shrink-0 ${ze(e.provider)}`}),(0,J.jsx)(`span`,{className:`text-xs font-medium`,children:Re(e.provider)}),(0,J.jsx)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:t(`runs`,{count:e.count})}),(0,J.jsxs)(`span`,{className:`ml-auto text-xs font-medium tabular-nums`,children:[i?`~`:``,Le(r)]})]})}var He=[`option`,`isActive`];function X(){return X=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},X.apply(null,arguments)}function Ue(e,t){if(e==null)return{};var n,r,i=We(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 We(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 Ge(e){var{option:t,isActive:n}=e,r=Ue(e,He);return typeof t==`string`?q.createElement(I,X({option:q.createElement(Ce,X({type:t},r)),isActive:n,shapeType:`symbols`},r)):q.createElement(I,X({option:t,isActive:n,shapeType:`symbols`},r))}var Ke=ae([(e,t,n,r,i,a,o)=>F(e,void 0,void 0,o),(e,t,n,r,i,a,o)=>j(e,`xAxis`,t,o),(e,t,n,r,i,a,o)=>N(e,`xAxis`,t,o),(e,t,n,r,i,a,o)=>j(e,`yAxis`,n,o),(e,t,n,r,i,a,o)=>N(e,`yAxis`,n,o),(e,t,n,r)=>E(e,`zAxis`,r,!1),ae([C,(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 st({displayedData:d,xAxis:t,yAxis:r,zAxis:a,scatterSettings:o,xAxisTicks:n,yAxisTicks:i,cells:s})}}),qe=[`id`],Je=[`onMouseEnter`,`onClick`,`onMouseLeave`],Ye=[`animationBegin`,`animationDuration`,`animationEasing`,`hide`,`isAnimationActive`,`legendType`,`lineJointType`,`lineType`,`shape`,`xAxisId`,`yAxisId`,`zAxisId`];function Z(e,t){if(e==null)return{};var n,r,i=Xe(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 Xe(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 Ze(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?Ze(Object(n),!0).forEach(function(t){Qe(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Ze(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function Qe(e,t,n){return(t=$e(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function $e(e){var t=et(e,`string`);return typeof t==`symbol`?t:t+``}function et(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 tt=e=>{var{dataKey:t,name:n,fill:r,legendType:i,hide:a}=e;return[{inactive:a,dataKey:t,type:i,color:r,value:B(n,t),payload:e}]},nt=q.memo(e=>{var{dataKey:t,points:n,stroke:r,strokeWidth:i,fill:a,name:o,hide:s,tooltipType:c,id:l}=e,u={dataDefinedOnItem:n?.map(e=>e.tooltipPayload),getPosition:e=>{var t;return n==null||(t=n[Number(e)])==null?void 0:t.tooltipPosition},settings:{stroke:r,strokeWidth:i,fill:a,nameKey:void 0,dataKey:t,name:B(o,t),hide:s,type:c,color:a,unit:``,graphicalItemId:l}};return q.createElement(Ee,{tooltipEntrySettings:u})});function rt(e){var{points:t,props:n}=e,{line:r,lineType:i,lineJointType:a}=n;if(!r)return null;var o=ce(n),s=ee(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}=ie(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=q.isValidElement(r)?q.cloneElement(r,h):typeof r==`function`?r(h):q.createElement(R,Q({},h,{type:a})),q.createElement(W,{className:`recharts-scatter-line`,key:`recharts-scatter-line`},l)}function it(e){var{showLabels:t,points:n,children:r}=e,i=w(),a=(0,q.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 q.createElement(L,{value:t?a:void 0},r)}function at(e){var{points:t,allOtherScatterProps:n}=e,{shape:r,activeShape:i,dataKey:a}=n,{id:o}=n,s=Z(n,qe),c=ge(de),{onMouseEnter:l,onClick:u,onMouseLeave:d}=n,f=Z(n,Je),p=ne(l,a,o),m=De(d),h=Oe(u,a,o);if(!ve(t))return null;var g=ce(s);return q.createElement(q.Fragment,null,q.createElement(rt,{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,[D]:String(o)});return q.createElement(v,{key:`symbol-${e?.cx}-${e?.cy}-${e?.size}-${t}`,zIndex:a?k.activeDot:void 0},q.createElement(W,Q({className:`recharts-scatter-symbol`},te(f,e,t),{onMouseEnter:p(e,t),onMouseLeave:m(e,t),onClick:h(e,t)}),q.createElement(Ge,Q({option:s,isActive:a},l))))}))}function ot(e){var{previousPointsRef:t,props:n}=e,{points:r,isAnimationActive:i,animationBegin:a,animationDuration:o,animationEasing:s}=n,c=t.current,l=ke(n,`recharts-scatter-`),[u,d]=(0,q.useState)(!1),f=(0,q.useCallback)(()=>{d(!1)},[]),p=(0,q.useCallback)(()=>{d(!0)},[]),m=!u;return q.createElement(it,{showLabels:m,points:r},n.children,q.createElement(y,{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:U(r.cx,t.cx,e),cy:t.cy==null?void 0:U(r.cy,t.cy,e),size:U(r.size,t.size,e)}):$($({},t),{},{size:U(0,t.size,e)})});return e>0&&(t.current=i),q.createElement(W,null,q.createElement(at,{points:i,allOtherScatterProps:n,showLabels:m}))}),q.createElement(S,{label:n.label}))}function st(e){var{displayedData:t,xAxis:n,yAxis:r,zAxis:i,scatterSettings:a,xAxisTicks:o,yAxisTicks:s,cells:c}=e,l=K(n.dataKey)?a.dataKey:n.dataKey,u=K(r.dataKey)?a.dataKey:r.dataKey,d=i&&i.dataKey,f=i?i.range:A.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=P(e,l),g=P(e,u),_=!K(d)&&P(e,d)||`-`,v=[{name:K(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:K(r.dataKey)?a.name:r.name||String(r.dataKey),unit:r.unit||``,value:g,payload:e,dataKey:u,type:a.tooltipType,graphicalItemId:a.id}];_!==`-`&&i!=null&&v.push({name:i.name||i.dataKey,unit:i.unit||``,value:_,payload:e,dataKey:d,type:a.tooltipType,graphicalItemId:a.id});var y=z({axis:n,ticks:o,bandSize:m,entry:e,index:t,dataKey:l}),b=z({axis:r,ticks:s,bandSize:h,entry:e,index:t,dataKey:u}),x=_!==`-`&&i!=null?i.scale.map(_):p,S=x==null?0:Math.sqrt(Math.max(x,0)/Math.PI);return $($({},e),{},{cx:y,cy:b,x:y==null?void 0:y-S,y:b==null?void 0:b-S,width:2*S,height:2*S,size:x,node:{x:f,y:g,z:_},tooltipPayload:v,tooltipPosition:{x:y,y:b},payload:e},c&&c[t]&&c[t].props)})}var ct=(e,t,n)=>({x:e.cx,y:e.cy,value:Number(n===`x`?e.node.x:e.node.y),errorVal:P(e,t)});function lt(e){var{hide:n,points:r,className:i,needClip:a,xAxisId:o,yAxisId:s,id:c}=e,l=(0,q.useRef)(null);if(n)return null;var u=t(`recharts-scatter`,i),d=c;return q.createElement(v,{zIndex:e.zIndex},q.createElement(W,{className:u,clipPath:a?`url(#clipPath-${d})`:void 0,id:c},a&&q.createElement(`defs`,null,q.createElement(_e,{clipPathId:d,xAxisId:o,yAxisId:s})),q.createElement(re,{xAxisId:o,yAxisId:s,data:r,dataPointFormatter:ct,errorBarOffset:0},q.createElement(W,{key:`recharts-scatter-symbols`},q.createElement(ot,{props:e,previousPointsRef:l})))))}var ut={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:k.scatter};function dt(e){var t=G(e,ut),{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=Z(t,Ye),{needClip:h}=Se(d,f),g=(0,q.useMemo)(()=>b(e.children,x),[e.children]),_=be(),v=ge(t=>Ke(t,d,f,p,e.id,g,_));return h==null||v==null?null:q.createElement(q.Fragment,null,q.createElement(nt,{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}),q.createElement(lt,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 ft(e){var t=G(e,ut),n=be();return q.createElement(se,{id:t.id,type:`scatter`},e=>q.createElement(q.Fragment,null,q.createElement(V,{legendPayload:tt(t)}),q.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}),q.createElement(dt,Q({},t,{id:e}))))}var pt=q.memo(ft,T);pt.displayName=`Scatter`;function mt(e){var t=Te(),n=(0,q.useRef)(null);return(0,q.useLayoutEffect)(()=>{n.current===null?t(oe(e)):n.current!==e&&t(me({prev:n.current,next:e})),n.current=e},[e,t]),(0,q.useLayoutEffect)(()=>()=>{n.current&&=(t(ye(n.current)),null)},[t]),null}var ht={zAxisId:0,range:A.range,scale:A.scale,type:A.type};function gt(e){var t=G(e,ht);return q.createElement(mt,{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:A.allowDuplicatedCategory,allowDataOverflow:A.allowDataOverflow,reversed:A.reversed,includeHidden:A.includeHidden})}gt.displayName=`ZAxis`;var _t=[`item`],vt=(0,q.forwardRef)((e,t)=>q.createElement(he,{chartName:`ScatterChart`,defaultTooltipEventType:`item`,validateTooltipEventTypes:_t,tooltipPayloadSearcher:fe,categoricalChartProps:e,ref:t}));function yt({data:e,loading:t}){let{t:r}=n(`analytics`);if(t&&!e)return(0,J.jsx)(`div`,{className:`h-[220px] rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let i={jobs:r(`surfaces.job`),explore:r(`surfaces.exploreSpec`),quick:r(`surfaces.quickSpec`),refine:r(`surfaces.aiEdit`),fileSummaries:r(`surfaces.fileSummary`)},a=e.dailyTimeline.map(e=>({date:e.date.slice(5),[i.jobs]:e.jobsCostUsd,[i.explore]:e.exploreCostUsd,[i.quick]:e.quickCostUsd,[i.refine]:e.aiEditCostUsd,[i.fileSummaries]:e.fileSummaryCostUsd??0})),o=e.dailyTimeline.every(e=>e.jobsCostUsd+e.exploreCostUsd+e.quickCostUsd+e.aiEditCostUsd+(e.fileSummaryCostUsd??0)===0);return(0,J.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,J.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider`,children:r(`timeline.title`)}),(0,J.jsx)(`span`,{className:`text-[10px] text-muted-foreground/70`,children:r(`timeline.subtitle`)})]}),o?(0,J.jsx)(`div`,{className:`h-40 flex items-center justify-center text-xs text-muted-foreground/70`,children:r(`timeline.empty`)}):(0,J.jsx)(`div`,{className:`h-[220px]`,children:(0,J.jsx)(O,{width:`100%`,height:`100%`,children:(0,J.jsxs)(we,{data:a,margin:{top:10,right:10,left:-8,bottom:0},children:[(0,J.jsx)(pe,{strokeDasharray:`2 4`,stroke:`currentColor`,className:`text-border/30`,vertical:!1}),(0,J.jsx)(ue,{dataKey:`date`,tick:{fontSize:10},stroke:`currentColor`,className:`text-muted-foreground`}),(0,J.jsx)(xe,{tick:{fontSize:10},stroke:`currentColor`,className:`text-muted-foreground`,tickFormatter:e=>`$${e}`}),(0,J.jsx)(M,{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,J.jsx)(H,{dataKey:i.jobs,stackId:`a`,fill:`var(--accent-info, #5fa8d3)`}),(0,J.jsx)(H,{dataKey:i.explore,stackId:`a`,fill:`var(--accent-highlight, #c084fc)`}),(0,J.jsx)(H,{dataKey:i.quick,stackId:`a`,fill:`var(--accent-secondary, #f7768e)`}),(0,J.jsx)(H,{dataKey:i.refine,stackId:`a`,fill:`var(--accent-success, #50fa7b)`}),(0,J.jsx)(H,{dataKey:i.fileSummaries,stackId:`a`,fill:`var(--accent-warning, #f1fa8c)`})]})})})]})}function bt(e){return e==null?`—`:e<.005?`$${e.toFixed(4)}`:e<1?`$${e.toFixed(3)}`:`$${e.toFixed(2)}`}function xt(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 St({values:e}){let t=Math.max(1e-4,...e);return(0,J.jsx)(`div`,{className:`flex items-end gap-[1px] h-5`,children:e.map((e,n)=>(0,J.jsx)(`div`,{className:`w-[3px] rounded-sm bg-foreground/40`,style:{height:`${Math.max(2,e/t*20)}px`}},n))})}function Ct({mode:e,label:t,accentClass:r}){let{t:i}=n(`analytics`),a=e.mode===`explore`&&e.totalRuns<5;return(0,J.jsxs)(`div`,{className:`flex-1 p-4 first:pr-2 last:pl-2`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,J.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full ${r}`}),(0,J.jsx)(`span`,{className:`text-xs font-medium uppercase tracking-wider text-muted-foreground`,children:t})]}),a?(0,J.jsxs)(`div`,{className:`py-3`,children:[(0,J.jsx)(`p`,{className:`text-sm text-foreground`,children:i(`quickVsExplore.sparseCta`)}),(0,J.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:i(`quickVsExplore.runsSoFar`,{count:e.totalRuns})})]}):(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`text-3xl font-semibold tabular-nums tracking-tight`,children:bt(e.avgCostPerSpec)}),(0,J.jsx)(`div`,{className:`text-[11px] text-muted-foreground mt-0.5`,children:i(`quickVsExplore.perSpec`)}),(0,J.jsx)(`div`,{className:`mt-3`,children:(0,J.jsx)(St,{values:e.sparkline.length>0?e.sparkline:[0]})}),(0,J.jsxs)(`div`,{className:`mt-3 space-y-0.5 text-xs tabular-nums text-muted-foreground`,children:[(0,J.jsx)(`div`,{children:(0,J.jsx)(p,{ns:`analytics`,i18nKey:`quickVsExplore.createdRuns`,values:{created:e.ticketsCreated,runs:e.totalRuns},components:{strong:(0,J.jsx)(`span`,{className:`text-foreground font-medium`})}})}),(0,J.jsx)(`div`,{children:i(`quickVsExplore.avgDuration`,{duration:xt(e.avgDurationMs)})}),(0,J.jsx)(`div`,{className:`truncate`,children:e.dominantModel??`—`})]})]})]})}function wt({data:e,loading:t}){let{t:r}=n(`analytics`);if(t&&!e)return(0,J.jsx)(`div`,{className:`h-[220px] rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let i=e.byMode.find(e=>e.mode===`quick`),a=e.byMode.find(e=>e.mode===`explore`);if(!i||!a)return null;let o=i.avgCostPerSpec&&a.avgCostPerSpec&&i.avgCostPerSpec>0?a.avgCostPerSpec/i.avgCostPerSpec:null,s=o!==null&&i.totalRuns>=1&&a.totalRuns>=5;return(0,J.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40`,children:[(0,J.jsx)(`div`,{className:`px-4 pt-3 pb-1`,children:(0,J.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider`,children:r(`quickVsExplore.title`)})}),(0,J.jsxs)(`div`,{className:`flex divide-x divide-border/40`,children:[(0,J.jsx)(Ct,{mode:i,label:r(`quickVsExplore.quick`),accentClass:`bg-accent-secondary`}),(0,J.jsx)(Ct,{mode:a,label:r(`quickVsExplore.explore`),accentClass:`bg-accent-highlight`})]}),s&&(0,J.jsx)(`div`,{className:`px-4 pb-3 -mt-1`,children:(0,J.jsx)(`div`,{className:`text-center text-[11px] text-muted-foreground tabular-nums`,children:(0,J.jsxs)(`span`,{className:`px-2`,children:[`━━━━━━ `,r(`quickVsExplore.ratio`,{ratio:o.toFixed(1)}),` ━━━━━━`]})})})]})}function Tt({data:e,loading:t,onSelectModel:r,activeModel:i}){let{t:a}=n(`analytics`);if(t&&!e)return(0,J.jsx)(`div`,{className:`h-[220px] rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let o=e.byModel.reduce((e,t)=>e+t.costUsd,0),s=e.byModel.slice(0,5);return(0,J.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,J.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider mb-3`,children:a(`models.title`)}),s.length===0?(0,J.jsx)(`div`,{className:`h-32 flex items-center justify-center text-xs text-muted-foreground/70`,children:a(`models.empty`)}):(0,J.jsx)(`ul`,{className:`space-y-1.5`,children:s.map(e=>{let t=o>0?e.costUsd/o*100:0,n=i===e.model;return(0,J.jsx)(`li`,{children:(0,J.jsxs)(`button`,{type:`button`,onClick:()=>r(e.model),className:`w-full text-left group rounded-md px-2 py-1.5 transition-colors ${n?`bg-accent-highlight/10 ring-1 ring-accent-highlight/30`:`hover:bg-accent/30`}`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between text-[12px] mb-1 tabular-nums`,children:[(0,J.jsx)(`span`,{className:`truncate font-medium`,children:e.model}),(0,J.jsxs)(`span`,{className:`text-muted-foreground`,children:[`$`,e.costUsd.toFixed(2),` · `,e.count]})]}),(0,J.jsx)(`div`,{className:`h-1.5 rounded-full bg-background-deep overflow-hidden`,children:(0,J.jsx)(`div`,{className:`h-full ${n?`bg-accent-highlight`:`bg-foreground/40 group-hover:bg-foreground/60`} transition-colors`,style:{width:`${t}%`}})})]})},e.model)})})]})}var Et={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)`};function Dt({data:e,loading:t,onSelectPoint:r}){let{t:i}=n(`analytics`);if(t&&!e)return(0,J.jsx)(`div`,{className:`h-[260px] rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let a=[`job`,`quick-spec`,`explore-spec`,`ai-edit`,`smash`],o=a.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}))})),s=e.scatter.length===0;return(0,J.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,J.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider`,children:i(`scatter.title`)}),(0,J.jsx)(`div`,{className:`flex flex-wrap items-center gap-2 text-[10px]`,children:a.map(e=>(0,J.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,J.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full`,style:{background:Et[e]}}),(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:u[e]})]},e))})]}),s?(0,J.jsx)(`div`,{className:`h-40 flex items-center justify-center text-xs text-muted-foreground/70`,children:i(`scatter.empty`)}):(0,J.jsx)(`div`,{className:`h-[260px]`,children:(0,J.jsx)(O,{width:`100%`,height:`100%`,children:(0,J.jsxs)(vt,{margin:{top:10,right:10,left:-8,bottom:5},children:[(0,J.jsx)(pe,{strokeDasharray:`2 4`,stroke:`currentColor`,className:`text-border/30`}),(0,J.jsx)(ue,{type:`number`,dataKey:`x`,name:`turns`,tick:{fontSize:10},stroke:`currentColor`,className:`text-muted-foreground`,label:{value:i(`scatter.turnsLabel`),position:`insideBottomRight`,offset:-2,fontSize:10,fill:`currentColor`}}),(0,J.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,J.jsx)(gt,{range:[40,80]}),(0,J.jsx)(M,{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)}`,i(`scatter.costLabel`)]:[String(e),n===`turns`?i(`scatter.turnsLabel`):n]}}),o.map(e=>(0,J.jsx)(pt,{data:e.points,fill:Et[e.surface],onClick:e=>{let t=e;t?.raw&&r(t.raw)}},e.surface))]})})})]})}function Ot({data:e,loading:t,onSelectTicket:r}){let{t:i}=n(`analytics`);if(t&&!e)return(0,J.jsx)(`div`,{className:`h-40 rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let a=e.topTickets;return(0,J.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,J.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider mb-3`,children:i(`topTickets.title`)}),a.length===0?(0,J.jsx)(`div`,{className:`h-32 flex items-center justify-center text-xs text-muted-foreground/70`,children:i(`topTickets.empty`)}):(0,J.jsx)(`ul`,{className:`divide-y divide-border/30`,children:a.map((e,t)=>{let n=Object.entries(e.bySurface).filter(([,e])=>e.count>0).map(([e,t])=>i(`topTickets.breakdownItem`,{n:t.count,label:u[e].toLowerCase()})).join(` + `),a=e.isUnattributed,o=a?i(`topTickets.unattributed`):e.ticketTitle?`#${e.ticketId} ${e.ticketTitle}`:i(`topTickets.deletedTicket`,{id:e.ticketId});return(0,J.jsx)(`li`,{children:(0,J.jsxs)(`button`,{type:`button`,onClick:()=>r(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 ${!e.ticketTitle&&!a?`opacity-50`:``}`,disabled:a,children:[(0,J.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,J.jsx)(`div`,{className:`text-sm truncate`,children:o}),(0,J.jsx)(`div`,{className:`text-[11px] text-muted-foreground truncate`,children:n||`—`})]}),(0,J.jsxs)(`div`,{className:`text-right tabular-nums`,children:[(0,J.jsxs)(`div`,{className:`text-sm font-medium`,children:[`$`,e.totalCostUsd.toFixed(2)]}),(0,J.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:i(`runs`,{count:e.totalRuns})})]})]})},`${e.ticketId??`u`}-${t}`)})})]})}function kt(e){return e==null?`—`:e<.005?`$${e.toFixed(4)}`:`$${e.toFixed(2)}`}function At(e){return e==null?`—`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function jt(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 Mt(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 Nt(e,t){if(e.model)return e.model;if(!jt(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 Pt({rows:e,loading:t,truncated:r,totalAvailable:i,tableFilters:a,onTableFiltersChange:o}){let{t:s}=n(`analytics`),[c,l]=(0,q.useState)(null),f=Mt(e);return(0,J.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 mb-3`,children:[(0,J.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider`,children:s(`table.title`)}),(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-[11px]`,children:[(0,J.jsxs)(`select`,{value:a.status??``,onChange:e=>o({...a,status:e.target.value||void 0}),className:`h-7 px-2 rounded-md bg-background-deep border border-border/60 text-xs`,"aria-label":s(`table.statusFilterAria`),children:[(0,J.jsx)(`option`,{value:``,children:s(`table.allStatus`)}),(0,J.jsx)(`option`,{value:`success`,children:s(`table.success`)}),(0,J.jsx)(`option`,{value:`failed`,children:s(`table.failed`)}),(0,J.jsx)(`option`,{value:`aborted`,children:s(`table.aborted`)})]}),(0,J.jsx)(`input`,{type:`number`,step:`0.01`,min:`0`,placeholder:s(`table.minCostPlaceholder`),value:a.minCostUsd??``,onChange:e=>{let t=e.target.value===``?void 0:parseFloat(e.target.value);o({...a,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":s(`table.minCostFilterAria`)})]})]}),t?(0,J.jsx)(`div`,{className:`h-32 rounded bg-card/30 animate-pulse`}):e.length===0?(0,J.jsx)(`div`,{className:`h-32 flex items-center justify-center text-xs text-muted-foreground/70`,children:s(`table.empty`)}):(0,J.jsx)(`div`,{className:`overflow-x-auto`,children:(0,J.jsxs)(`table`,{className:`w-full text-[12px] tabular-nums`,children:[(0,J.jsx)(`thead`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:(0,J.jsxs)(`tr`,{className:`text-left`,children:[(0,J.jsx)(`th`,{className:`font-medium px-2 py-2`,children:s(`table.colSurface`)}),(0,J.jsx)(`th`,{className:`font-medium px-2 py-2`,children:s(`table.colTicket`)}),(0,J.jsx)(`th`,{className:`font-medium px-2 py-2 text-right`,children:s(`table.colCost`)}),(0,J.jsx)(`th`,{className:`font-medium px-2 py-2 text-right`,children:s(`table.colTurns`)}),(0,J.jsx)(`th`,{className:`font-medium px-2 py-2 text-right`,children:s(`table.colTokens`)}),(0,J.jsx)(`th`,{className:`font-medium px-2 py-2`,children:s(`table.colModel`)}),(0,J.jsx)(`th`,{className:`font-medium px-2 py-2`,children:s(`table.colStatus`)}),(0,J.jsx)(`th`,{className:`font-medium px-2 py-2`,children:s(`table.colStarted`)})]})}),(0,J.jsx)(`tbody`,{children:e.map(e=>{let t=e.surface,n=d[t],r=(e.tokens_in??0)+(e.tokens_out??0)+(e.tokens_cache_read??0)+(e.tokens_cache_create??0),i=jt(e),a=i?s(`table.contractLayer`):u[t],o=Nt(e,f);return(0,J.jsxs)(`tr`,{onClick:()=>l(c===e.id?null:e.id),className:`border-t border-border/30 hover:bg-accent/30 cursor-pointer`,children:[(0,J.jsx)(`td`,{className:`px-2 py-2`,children:(0,J.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,J.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full ${n.dot}`}),a]})}),(0,J.jsx)(`td`,{className:`px-2 py-2 max-w-[260px]`,children:e.ticket_id==null?e.ticket_title?(0,J.jsx)(`span`,{className:`truncate block text-muted-foreground/90 italic`,title:s(`table.provisionalTitleTooltip`),children:e.ticket_title}):(0,J.jsx)(`span`,{className:`text-muted-foreground/70`,children:`—`}):(0,J.jsxs)(`span`,{className:`truncate block`,children:[`#`,e.ticket_id,` `,i?(0,J.jsx)(`span`,{className:`text-muted-foreground/90`,children:s(`table.contractLayerRefinement`)}):e.ticket_title??(0,J.jsx)(`span`,{className:`text-muted-foreground/70 italic`,children:s(`table.deleted`)})]})}),(0,J.jsx)(`td`,{className:`px-2 py-2 text-right font-medium`,children:e.total_cost_usd_estimated===1&&e.total_cost_usd!=null?(0,J.jsxs)(`span`,{title:s(`table.estimatedCostTooltip`),className:`text-muted-foreground/90`,children:[`~`,kt(e.total_cost_usd)]}):kt(e.total_cost_usd)}),(0,J.jsx)(`td`,{className:`px-2 py-2 text-right`,children:At(e.num_turns)}),(0,J.jsx)(`td`,{className:`px-2 py-2 text-right`,children:r>0?At(r):`—`}),(0,J.jsxs)(`td`,{className:`px-2 py-2 max-w-[180px] truncate`,children:[o??`—`,o&&!e.model?(0,J.jsx)(`span`,{className:`ml-1 text-[10px] text-muted-foreground/70`,children:s(`table.inferred`)}):null]}),(0,J.jsxs)(`td`,{className:`px-2 py-2`,children:[e.status===`success`?(0,J.jsx)(`span`,{className:`text-accent-success/90`,children:`●`}):e.status===`failed`?(0,J.jsx)(`span`,{className:`text-accent-warning`,children:`⚠`}):(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:`○`}),(0,J.jsx)(`span`,{className:`ml-1 text-muted-foreground`,children:s(`table.statusValue.${e.status}`)})]}),(0,J.jsx)(`td`,{className:`px-2 py-2 text-muted-foreground`,children:e.started_at.slice(0,16).replace(`T`,` `)})]},e.id)})})]})}),r&&(0,J.jsx)(`div`,{className:`mt-2 text-[11px] text-muted-foreground/80`,children:s(`table.truncated`,{shown:e.length,total:i.toLocaleString()})})]})}var Ft=[{value:`7d`,labelKey:`periods.d7`},{value:`30d`,labelKey:`periods.d30`},{value:`90d`,labelKey:`periods.d90`},{value:`all`,labelKey:`periods.all`}],It=[{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`}];function Lt(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.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)),t.toString()}function Rt(){let{t:e}=n(`analytics`),{activeProjectId:t,projects:o}=r(),[l,u]=c(),d=o.find(e=>e.id===t),f=d?s(d):[`claude`],p=f.length>1,h=l.get(`period`)??`30d`,v=(l.get(`surface`)??``).split(`,`).filter(Boolean),y=(l.get(`provider`)??``).split(`,`).filter(Boolean),b=l.get(`ticketId`),[x,S]=(0,q.useState)({period:h,surface:v.length>0?v:void 0,provider:y.length>0?y:void 0,ticketId:b?Number(b):void 0}),[C,w]=(0,q.useState)(null),[T,E]=(0,q.useState)(!0),[D,O]=(0,q.useState)(null),[k,A]=(0,q.useState)({}),[j,M]=(0,q.useState)(null),N=(0,q.useRef)(new Map),P=(0,q.useRef)(0);(0,q.useEffect)(()=>{let e=new URLSearchParams;e.set(`period`,x.period),x.surface&&x.surface.length>0&&e.set(`surface`,x.surface.join(`,`)),x.provider&&x.provider.length>0&&e.set(`provider`,x.provider.join(`,`)),x.ticketId&&e.set(`ticketId`,String(x.ticketId)),u(e,{replace:!0})},[x.period,x.surface,x.provider,x.ticketId,u]);let F=(0,q.useCallback)(async()=>{if(!t)return;let e=++P.current;O(null);let n=`${t}:${Lt(x)}`,r=N.current.get(n);r?(w(r),E(!1)):E(!0);try{let t=await fetch(`${g()}/spending?${Lt(x)}`);if(!t.ok)throw Error(`HTTP ${t.status}`);if(e!==P.current)return;let r=await t.json();N.current.set(n,r),w(r),E(!1)}catch(t){if(e!==P.current)return;O(t.message),E(!1)}},[t,x]),I=(0,q.useCallback)(async()=>{if(!t)return;let e={...x};k.model&&(e.model=[k.model]),k.status&&(e.status=k.status),typeof k.minCostUsd==`number`&&(e.minCostUsd=k.minCostUsd);try{let t=await fetch(`${g()}/invocations?${Lt(e)}&limit=100`);if(!t.ok)throw Error(`HTTP ${t.status}`);M(await t.json())}catch{M(null)}},[t,x,k]);(0,q.useEffect)(()=>{F()},[F]),(0,q.useEffect)(()=>{I()},[I]);let L=(0,q.useRef)(null),R=a();(0,q.useEffect)(()=>{let e=`analytics-spending`;return R.registerHandler(e,e=>{let n=e;n.type===`spending.invalidated`&&n.projectId===t&&(L.current&&clearTimeout(L.current),L.current=setTimeout(()=>{N.current.clear(),F(),I()},500))}),()=>{R.unregisterHandler(e)}},[R,t,F,I]);function z(e){if(e===`all`){S(e=>({...e,surface:void 0}));return}S(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}})}function B(e){if(e===`all`){S(e=>({...e,provider:void 0}));return}S(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 V=x.surface,ee=!V||V.length===0,H=x.provider,te=!H||H.length===0,ne=(0,q.useMemo)(()=>{let e={period:x.period};return x.surface&&x.surface.length>0&&(e.surface=x.surface.join(`,`)),x.provider&&x.provider.length>0&&(e.provider=x.provider.join(`,`)),x.ticketId&&(e.ticketId=String(x.ticketId)),e},[x]),re=C?C.summary.totalRuns===0:!1;return(0,J.jsxs)(`div`,{className:`flex flex-col gap-6 p-4 pb-12`,children:[(0,J.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,J.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,J.jsx)(`h1`,{className:`text-base font-semibold tracking-tight`,children:e(`page.title`)}),x.ticketId&&(0,J.jsx)(`button`,{type:`button`,onClick:()=>S(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:x.ticketId})})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(`div`,{className:`flex items-center gap-1 rounded-md border border-border/60 bg-card/40 p-0.5`,children:Ft.map(t=>(0,J.jsx)(`button`,{type:`button`,onClick:()=>S(e=>({...e,period:t.value})),className:`px-2.5 h-6 rounded text-[11px] font-medium transition-colors ${x.period===t.value?`bg-accent text-foreground`:`text-muted-foreground hover:text-foreground`}`,children:e(t.labelKey)},t.value))}),(0,J.jsx)(_,{baseUrl:`${g()}/analytics/export`,params:ne,disabled:re}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>{N.current.clear(),F(),I()},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,J.jsx)(i,{className:`w-3 h-3`})})]})]}),(0,J.jsx)(`div`,{className:`mt-3 flex flex-wrap items-center gap-1.5`,children:It.map(t=>(0,J.jsx)(`button`,{type:`button`,onClick:()=>z(t.value),className:`h-7 px-3 rounded-full text-[11px] font-medium transition-all ${(t.value===`all`?ee:V?.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,J.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-1.5`,"data-testid":`analytics-provider-chips`,children:[(0,J.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-muted-foreground/70 mr-1`,children:e(`page.engine`)}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>B(`all`),className:`h-7 px-3 rounded-full text-[11px] font-medium transition-all ${te?`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,J.jsx)(`button`,{type:`button`,onClick:()=>B(e),className:`h-7 px-3 rounded-full text-[11px] font-medium transition-all ${H?.includes(e)??!1?`bg-foreground/10 text-foreground ring-1 ring-foreground/20`:`text-muted-foreground hover:text-foreground hover:bg-accent/40`}`,children:m(e)},e))]})]}),D&&(0,J.jsxs)(`div`,{className:`rounded-lg border border-accent-warning/30 bg-accent-warning/10 p-4 flex items-center justify-between`,children:[(0,J.jsx)(`p`,{className:`text-sm text-accent-warning`,children:e(`page.failedToLoad`,{error:D})}),(0,J.jsxs)(`button`,{onClick:()=>F(),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,J.jsx)(i,{className:`w-3 h-3`}),e(`common:actions.retry`)]})]}),(0,J.jsx)(Pe,{data:C,loading:T}),(0,J.jsx)(Be,{data:C,loading:T}),(0,J.jsx)(yt,{data:C,loading:T}),(0,J.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4`,children:[(0,J.jsx)(wt,{data:C,loading:T}),(0,J.jsx)(Tt,{data:C,loading:T,onSelectModel:e=>S(t=>({...t,model:[e]})),activeModel:x.model?.[0]})]}),(0,J.jsx)(Dt,{data:C,loading:T,onSelectPoint:e=>{A(e=>({...e})),S(t=>({...t,ticketId:e.ticketId??void 0}))}}),(0,J.jsx)(Ot,{data:C,loading:T,onSelectTicket:e=>S(t=>({...t,ticketId:e??void 0}))}),(0,J.jsx)(Pt,{rows:j?.rows??[],loading:T&&!j,truncated:j?.truncated??!1,totalAvailable:j?.totalAvailable??0,tableFilters:k,onTableFiltersChange:A})]})}export{Rt as default};
|