specrails-desktop 2.20.0 → 2.21.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/README.md +1 -0
- package/client/dist/assets/{ActivityFeedPage-BgLjSsDn.js → ActivityFeedPage-BPkf89Xk.js} +1 -1
- package/client/dist/assets/{AgentBrowserCapture-R87DoreG.js → AgentBrowserCapture-DkA8FLp8.js} +1 -1
- package/client/dist/assets/{AgentModeCodePane-CO8F0ttc.js → AgentModeCodePane-DhVkOSdv.js} +2 -2
- package/client/dist/assets/{AgentModeJobsPane-BecN3lwS.js → AgentModeJobsPane-TLYCqNAw.js} +1 -1
- package/client/dist/assets/{AgentsPage-_-Q9plMs.js → AgentsPage-BKsPH-l1.js} +1 -1
- package/client/dist/assets/AnalyticsPage-Da9pDQrq.js +1 -0
- package/client/dist/assets/{BarChart-DZlxRF5i.js → BarChart-9_p1-qtv.js} +1 -1
- package/client/dist/assets/{CodePage-4eiDoOBX.js → CodePage-DlwvWKCo.js} +1 -1
- package/client/dist/assets/{DesktopAnalyticsPage-DyiCeq0h.js → DesktopAnalyticsPage-DpVVhXKF.js} +1 -1
- package/client/dist/assets/{DocsDialog-CDZv0FMK.js → DocsDialog-BSdgftgR.js} +1 -1
- package/client/dist/assets/{DocsPage-BmwaXyUf.js → DocsPage-9SGL4_zz.js} +1 -1
- package/client/dist/assets/{ExportDropdown-CWafyruY.js → ExportDropdown-Clt8DyCs.js} +1 -1
- package/client/dist/assets/{IntegrationsPage-CY2jfpeW.js → IntegrationsPage-BW5mofSA.js} +1 -1
- package/client/dist/assets/{JobDetailPage-p0lsbXRg.js → JobDetailPage-CqiJ9vwR.js} +1 -1
- package/client/dist/assets/{JobsPage-GeKC3ckC.js → JobsPage-CVinOe6p.js} +1 -1
- package/client/dist/assets/{LogViewer-Cz7jzyU2.js → LogViewer-Cf6s1TDs.js} +1 -1
- package/client/dist/assets/{LoopBuilderPage-C_vv7AW2.js → LoopBuilderPage-CqgUH5Vw.js} +1 -1
- package/client/dist/assets/{LoopsPage-CettzySP.js → LoopsPage-C6h2gjPP.js} +1 -1
- package/client/dist/assets/{ProjectSettingsDialog-Xw30FTul.js → ProjectSettingsDialog-BU-JR7wI.js} +1 -1
- package/client/dist/assets/analytics-B7bPj6u_2.js +1 -0
- package/client/dist/assets/analytics-BakymH7Z2.js +1 -0
- package/client/dist/assets/analytics-CBvaxOId.js +1 -0
- package/client/dist/assets/analytics-Ce-sPORu.js +1 -0
- package/client/dist/assets/analytics-DZ74aQ54.js +1 -0
- package/client/dist/assets/analytics-WF1I49ln.js +1 -0
- package/client/dist/assets/analytics-slx4X1mu2.js +1 -0
- package/client/dist/assets/analytics-uRNP6yAJ.js +1 -0
- package/client/dist/assets/dashboard-B-AiVq5X.js +1 -0
- package/client/dist/assets/dashboard-BpYYrPl8.js +1 -0
- package/client/dist/assets/dashboard-Bunv-uon2.js +1 -0
- package/client/dist/assets/dashboard-CYciEbov.js +1 -0
- package/client/dist/assets/dashboard-CvFg-_JQ.js +1 -0
- package/client/dist/assets/dashboard-DAyPERCJ.js +1 -0
- package/client/dist/assets/dashboard-DJ-6T44N2.js +1 -0
- package/client/dist/assets/dashboard-DnBGqZkZ2.js +1 -0
- package/client/dist/assets/{dist-js-zlcAXgob.js → dist-js-4mmVovCB.js} +1 -1
- package/client/dist/assets/{dist-js-DoZ1SVEs.js → dist-js-wMFtEMAw.js} +1 -1
- package/client/dist/assets/index-BHPbzyg6.css +2 -0
- package/client/dist/assets/index-D4R3rVF5.js +152 -0
- package/client/dist/assets/jobs-BqF79kHz2.js +1 -0
- package/client/dist/assets/jobs-C1XM5urS.js +1 -0
- package/client/dist/assets/jobs-C5UjG0262.js +1 -0
- package/client/dist/assets/jobs-DBfaHTxC.js +1 -0
- package/client/dist/assets/jobs-DM4BDPdg.js +1 -0
- package/client/dist/assets/jobs-Da5OkZmf2.js +1 -0
- package/client/dist/assets/jobs-JJdnuQ03.js +1 -0
- package/client/dist/assets/{jobs---dwa4Nf.js → jobs-SI34ML8I.js} +1 -1
- package/client/dist/assets/{lib-zJbG81CY.js → lib-Cz65p1sn.js} +1 -1
- package/client/dist/assets/{settings-DZj7Uqy32.js → settings-BJ6fj67y2.js} +1 -1
- package/client/dist/assets/{settings-zZr7NzuB.js → settings-BbxrZlv7.js} +1 -1
- package/client/dist/assets/{settings-VgCsjaYf.js → settings-BmA06FIJ.js} +1 -1
- package/client/dist/assets/{settings-BWHGtmU12.js → settings-C2_QJA8f2.js} +1 -1
- package/client/dist/assets/{settings-C-m3yEZ2.js → settings-CgjmTpR8.js} +1 -1
- package/client/dist/assets/{settings-BPq9nCJm.js → settings-D3rfdI1i.js} +1 -1
- package/client/dist/assets/{settings-r8Qq2Gzp2.js → settings-DoUJb93K2.js} +1 -1
- package/client/dist/assets/settings-Mr7MnJbf.js +1 -0
- package/client/dist/assets/{upload-Cm4KWhcE.js → upload-DPRq2dC-.js} +1 -1
- package/client/dist/assets/{value-m3Q84dDF.js → value-DJMRojPA.js} +1 -1
- package/client/dist/index.html +6 -6
- package/docs/guide/de/pipeline/3-batch-implement-and-multi-feature.md +8 -5
- package/docs/guide/en/pipeline/3-batch-implement-and-multi-feature.md +9 -4
- package/docs/guide/es/pipeline/3-batch-implement-and-multi-feature.md +8 -5
- package/docs/guide/fr/pipeline/3-batch-implement-and-multi-feature.md +8 -5
- package/docs/guide/it/pipeline/3-batch-implement-and-multi-feature.md +9 -6
- package/docs/guide/ja/pipeline/3-batch-implement-and-multi-feature.md +8 -5
- package/docs/guide/pt/pipeline/3-batch-implement-and-multi-feature.md +8 -5
- package/docs/guide/zh/pipeline/3-batch-implement-and-multi-feature.md +9 -6
- package/docs/running-pipelines.md +2 -0
- package/package.json +1 -1
- package/server/dist/agent-chat-manager.js +57 -4
- package/server/dist/agent-generator.js +110 -14
- package/server/dist/agent-refine-manager.js +51 -28
- package/server/dist/ai-invocations.js +14 -0
- package/server/dist/chat-manager.js +179 -38
- package/server/dist/db.js +40 -22
- package/server/dist/desktop-analytics.js +83 -31
- package/server/dist/desktop-db.js +62 -0
- package/server/dist/file-summary-generator.js +7 -2
- package/server/dist/git-guardrails.js +62 -0
- package/server/dist/integration-branch.js +63 -0
- package/server/dist/interactive-job-session.js +126 -4
- package/server/dist/loop-effect.js +12 -0
- package/server/dist/loop-executors.js +13 -1
- package/server/dist/loop-run-manager.js +7 -0
- package/server/dist/pr-publisher.js +68 -0
- package/server/dist/pricing.js +77 -17
- package/server/dist/profiles-router.js +12 -4
- package/server/dist/project-registry.js +7 -3
- package/server/dist/project-router-settings.js +33 -0
- package/server/dist/project-router-spending.js +46 -1
- package/server/dist/project-router-tickets.js +51 -5
- package/server/dist/proposal-manager.js +70 -3
- package/server/dist/providers/claude-adapter.js +67 -6
- package/server/dist/queue-manager.js +495 -81
- package/server/dist/rail-isolated-launch.js +54 -3
- package/server/dist/rail-isolation.js +14 -0
- package/server/dist/rail-merge-orchestrator.js +53 -2
- package/server/dist/rail-pr-delivery.js +72 -0
- package/server/dist/rails-router.js +38 -1
- package/server/dist/result-event.js +20 -7
- package/server/dist/setup-manager.js +63 -3
- package/server/dist/smash-runner.js +73 -25
- package/server/dist/spec-launcher-manager.js +85 -2
- package/server/dist/spending.js +61 -16
- package/client/dist/assets/AnalyticsPage-Cqh5IGaF.js +0 -1
- package/client/dist/assets/analytics-B4FJ_pry.js +0 -1
- package/client/dist/assets/analytics-BBAfeB1o.js +0 -1
- package/client/dist/assets/analytics-BM1R5CEp2.js +0 -1
- package/client/dist/assets/analytics-BjLruoYS.js +0 -1
- package/client/dist/assets/analytics-CKwh2zUr.js +0 -1
- package/client/dist/assets/analytics-CpcjUkV72.js +0 -1
- package/client/dist/assets/analytics-DbXHdSlk2.js +0 -1
- package/client/dist/assets/analytics-Djzr1xUQ.js +0 -1
- package/client/dist/assets/dashboard-B8032psZ.js +0 -1
- package/client/dist/assets/dashboard-BHGKtxty2.js +0 -1
- package/client/dist/assets/dashboard-CXnoUgN22.js +0 -1
- package/client/dist/assets/dashboard-Ccyxqy7d.js +0 -1
- package/client/dist/assets/dashboard-CoED_41r.js +0 -1
- package/client/dist/assets/dashboard-Dc5ZAgMN.js +0 -1
- package/client/dist/assets/dashboard-JMY8ueD3.js +0 -1
- package/client/dist/assets/dashboard-tkWr1aHD2.js +0 -1
- package/client/dist/assets/index-5mbwBNQ-.css +0 -2
- package/client/dist/assets/index-CG4z4_Mq.js +0 -152
- package/client/dist/assets/jobs-Bvh_HiRo2.js +0 -1
- package/client/dist/assets/jobs-BzYX5VLd.js +0 -1
- package/client/dist/assets/jobs-DTfaTfzQ2.js +0 -1
- package/client/dist/assets/jobs-DrPyq5J2.js +0 -1
- package/client/dist/assets/jobs-Dty7cCdI2.js +0 -1
- package/client/dist/assets/jobs-Dv8MP-eE.js +0 -1
- package/client/dist/assets/jobs-DvkAoA8D.js +0 -1
- package/client/dist/assets/settings-CY8udi0e.js +0 -1
package/README.md
CHANGED
|
@@ -54,6 +54,7 @@
|
|
|
54
54
|
| 🛤️ **Execution rails** | Each rail is an independent lane. Drag specs in, **pick a Loop**, and press Play. Within a project, jobs run **one at a time** (rails let you queue and organise the work); true parallelism is **across projects**. Each rail carries its own **agent profile** and provider. |
|
|
55
55
|
| 🔁 **Loops** | A global, visual **Loop Builder** (n8n-style). The built-in loops — **Implement**, **Batch**, **Freestyle** — are what a rail runs by default, or build your own: chain AI steps, shell commands and a **Loop Decider** that repeats until a goal is met (e.g. *verify → fix → verify until green*). Publish a loop and pick it on any rail. See [Running pipelines](docs/running-pipelines.md). |
|
|
56
56
|
| 🧩 **Agent profiles** | A per-project, declarative catalog that tells the implement pipeline which agents to run and at what model — snapshotted per job so concurrent rails stay isolated. |
|
|
57
|
+
| 🔀 **Safe PR delivery** | Each rail runs in an isolated **git worktree** off your designated integration branch (set it in *Settings → Integration branch*) and, when it finishes, hands you **one draft pull request** — combined across all the specs on the rail. specrails **never merges and never touches your working tree**: you review and **Approve**, and your engineers merge it in GitHub the way they already do. Set `SPECRAILS_RAIL_DELIVER_PR=0` to fall back to local integration. |
|
|
57
58
|
| 📡 **Live job detail** | A premium ticket-identity header, live duration ticker, incremental turns/tokens, and authoritative cost on exit. |
|
|
58
59
|
| 🔌 **Plugins** | A per-project marketplace of MCP-based integrations (**Serena** semantic code-nav bundled today). Additive by design — installing plugin N+1 never disturbs plugin N. |
|
|
59
60
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as e}from"./chunk-BNv3lrIs.js";import{Cn as t,Dt as n,Jt as r,Kn as i,Rn as a,Sn as o,Yt as s,cn as c,et as l,pn as u,sn as d,un as f,wn as p}from"./index-
|
|
1
|
+
import{a as e}from"./chunk-BNv3lrIs.js";import{Cn as t,Dt as n,Jt as r,Kn as i,Rn as a,Sn as o,Yt as s,cn as c,et as l,pn as u,sn as d,un as f,wn as p}from"./index-D4R3rVF5.js";var m=c(`ban`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M4.929 4.929 19.07 19.071`,key:`196cmz`}]]),h=e(i(),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,a]=(0,h.useState)(!1),[s,c]=(0,h.useState)(!0),l=(0,h.useRef)(e);(0,h.useEffect)(()=>{l.current=e},[e]);let{registerHandler:d,unregisterHandler:f}=o();(0,h.useEffect)(()=>{if(!e){r([]),c(!0);return}let n=!1;a(!0),r([]),c(!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),c(a.length===t)}catch{}finally{n||a(!1)}}return i(),()=>{n=!0}},[e,t]);let m=(0,h.useCallback)(async()=>{if(i||!s)return;a(!0);let e=p(),n=l.current;try{r(i=>{let o=i[i.length-1];if(!o)return i;let s=encodeURIComponent(o.timestamp);return fetch(`${e}/activity?limit=${t}&before=${s}`).then(e=>e.json()).then(e=>{if(l.current!==n){a(!1);return}r(t=>g([...t,...e])),c(e.length===t),a(!1)}).catch(()=>a(!1)),i})}catch{a(!1)}},[i,s,t]),_=(0,h.useCallback)(e=>{let t=e,n=l.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:u.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:s,loadMore:m}}var v=t();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)(s,{className:`w-4 h-4 text-green-500 aurora-light:text-accent-success flex-shrink-0`});case`job_failed`:return(0,v.jsx)(r,{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)(l,{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}=a(`activity`),{activeProjectId:t}=f(),{items:r,loading:i,hasMore:o,loadMore:s}=_({activeProjectId:t}),c=(0,h.useRef)(null);return(0,h.useEffect)(()=>{let e=c.current;if(!e)return;let t=new IntersectionObserver(e=>{e[0].isIntersecting&&o&&!i&&s()},{threshold:.1});return t.observe(e),()=>t.disconnect()},[o,i,s]),(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)(d,{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:[i&&r.length===0?(0,v.jsx)(`div`,{className:`flex items-center justify-center h-32`,children:(0,v.jsx)(n,{className:`w-4 h-4 animate-spin text-muted-foreground`})}):r.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)(d,{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:r.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:c,className:`h-1`}),i&&r.length>0&&(0,v.jsx)(`div`,{className:`flex justify-center py-3`,children:(0,v.jsx)(n,{className:`w-4 h-4 animate-spin text-muted-foreground`})}),!o&&r.length>0&&(0,v.jsx)(`p`,{className:`text-center text-xs text-muted-foreground py-3`,children:e(`feed.allLoaded`)})]})]})}export{C as default};
|
package/client/dist/assets/{AgentBrowserCapture-R87DoreG.js → AgentBrowserCapture-DkA8FLp8.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as e}from"./chunk-BNv3lrIs.js";import{Cn as t,Kn as n,Ln as r,Rn as i,j as a,n as o,r as s}from"./index-
|
|
1
|
+
import{a as e}from"./chunk-BNv3lrIs.js";import{Cn as t,Kn as n,Ln as r,Rn as i,j as a,n as o,r as s}from"./index-D4R3rVF5.js";var c=e(n(),1),l=t();function u({projectId:e,conversationId:t}){let{t:n}=i(`agent`),{closeBrowser:u,queueCapture:d}=o(),f=(0,c.useMemo)(()=>`agent-${t??`home`}-${Math.round(performance.now())}`,[t]),p=async e=>{try{if(!t)throw Error(n(`workspace.requiresConversation`));let i=await(await fetch(e.screenshotDataUrl)).blob();d(await s(t,new File([i],`capture-${Date.now()}.png`,{type:`image/png`}))),r.success(n(`workspace.browserCaptured`)),u()}catch(e){r.error(e instanceof Error?e.message:n(`workspace.uploadFailed`))}};return(0,l.jsx)(a,{open:!0,onClose:u,projectId:e,pendingSpecId:f,confirmLabel:n(`workspace.browserConfirm`),onCaptured:e=>{p(e)}})}export{u as AgentBrowserCapture};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/CodePage-
|
|
2
|
-
import{a as e}from"./chunk-BNv3lrIs.js";import{t}from"./preload-helper-DSXbuxSR.js";import{Cn as n,Et as r,Kn as i,Rn as a,Tt as o,n as s,tt as c}from"./index-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/CodePage-DlwvWKCo.js","assets/chunk-BNv3lrIs.js","assets/index-D4R3rVF5.js","assets/preload-helper-DSXbuxSR.js","assets/clsx-1dnHRn8W.js","assets/auth-Cvsb7-Ek.js","assets/activity-D8vQJrpW.js","assets/addspec-DxW6oPsk.js","assets/agent-C32FOi9v.js","assets/agents-Cev2oFfX.js","assets/agentstudio-CZm2rOzt.js","assets/aiedit-DYtnZU9H.js","assets/analytics-Ce-sPORu.js","assets/attachments-Ci6_42Kh.js","assets/browser-ZB1afzjZ.js","assets/chat-VMflhzxn.js","assets/code-wtcs0ivb.js","assets/commands-CckaBWdV.js","assets/common-BPQQkgJZ.js","assets/dashboard-B-AiVq5X.js","assets/explore-BKVV5JSu.js","assets/integrations-CuWnMR5L.js","assets/jira-DXMoAKWD.js","assets/jobs-SI34ML8I.js","assets/loops-CQuuMlyZ.js","assets/mcp-CIH0pH1K.js","assets/nav-CzKzuwH8.js","assets/settings-Mr7MnJbf.js","assets/setup-G4ZvDKxX.js","assets/specs-BYeAbIEy.js","assets/terminal-DFPNRLKp.js","assets/tickets-CkfbISuK.js","assets/index-BHPbzyg6.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{a as e}from"./chunk-BNv3lrIs.js";import{t}from"./preload-helper-DSXbuxSR.js";import{Cn as n,Et as r,Kn as i,Rn as a,Tt as o,n as s,tt as c}from"./index-D4R3rVF5.js";var l=e(i(),1),u=n(),d=(0,l.lazy)(()=>t(()=>import(`./CodePage-DlwvWKCo.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32]))),f=new Map,p=420,m=560;function h({projectId:e,conversationId:t}){let{t:n}=a(`agent`),{closeCodePane:i}=s(),[h,g]=(0,l.useState)(m),[_,v]=(0,l.useState)(!1),y=(0,l.useRef)(null),b=`${e}:${t}`,x=(0,l.useCallback)(e=>{f.set(b,e)},[b]),S=(0,l.useCallback)(e=>{let t=e.clientX,n=h,r=window.innerWidth-p;try{e.currentTarget.setPointerCapture(e.pointerId)}catch{}let i=e=>{g(Math.min(Math.max(n+(t-e.clientX),p),r))},a=()=>{window.removeEventListener(`pointermove`,i),window.removeEventListener(`pointerup`,a),window.removeEventListener(`pointercancel`,a)};window.addEventListener(`pointermove`,i),window.addEventListener(`pointerup`,a),window.addEventListener(`pointercancel`,a)},[h]);return(0,u.jsxs)(`div`,{ref:y,className:`flex h-full flex-col overflow-hidden border-l border-border bg-background${_?` absolute inset-0 z-30 border-l-0`:``}`,style:_?void 0:{width:h,flexShrink:0},children:[(0,u.jsx)(`div`,{className:`relative flex items-center`,children:!_&&(0,u.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,onPointerDown:S,className:`absolute left-0 top-0 h-full w-1.5 -translate-x-full cursor-col-resize select-none touch-none hover:bg-accent-primary/20`,title:n(`workspace.resizeCode`)})}),(0,u.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-border/60 bg-surface/40 px-3 py-1.5`,children:[(0,u.jsx)(`span`,{className:`text-xs font-medium text-foreground/70`,children:n(`workspace.files`)}),(0,u.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[(0,u.jsx)(`button`,{type:`button`,onClick:()=>v(e=>!e),"aria-label":n(_?`restore`:`maximize`),title:n(_?`restore`:`maximize`),className:`rounded-md p-1 text-foreground/60 hover:bg-surface hover:text-foreground`,children:_?(0,u.jsx)(o,{className:`h-4 w-4`}):(0,u.jsx)(r,{className:`h-4 w-4`})}),(0,u.jsx)(`button`,{type:`button`,onClick:i,"aria-label":n(`workspace.closeFiles`),title:n(`workspace.closeFiles`),className:`rounded-md p-1 text-foreground/60 hover:bg-surface hover:text-foreground`,children:(0,u.jsx)(c,{className:`h-4 w-4`})})]})]}),(0,u.jsx)(`div`,{className:`min-h-0 flex-1 overflow-hidden`,children:(0,u.jsx)(l.Suspense,{fallback:(0,u.jsx)(`div`,{className:`flex h-full items-center justify-center text-sm text-muted-foreground`,children:`…`}),children:(0,u.jsx)(d,{embedded:!0,initialPath:f.get(b)??null,onSelectedPathChange:x})})})]},b)}export{h as AgentModeCodePane};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as e}from"./chunk-BNv3lrIs.js";import{n as t}from"./auth-Cvsb7-Ek.js";import{$ as n,Cn as r,Dt as i,Et as a,F as o,G as s,H as c,Ht as l,I as u,J as d,K as f,Kn as p,L as m,Ln as h,M as g,Q as _,R as v,Rn as y,Sn as b,Tt as x,U as S,V as C,W as w,Z as T,dn as E,fn as D,g as O,n as k,q as A,tn as j,tt as M,un as N,wn as P}from"./index-CG4z4_Mq.js";import{t as F}from"./format-command-BHymDa4r.js";import{n as I,t as L}from"./LogViewer-Cz7jzyU2.js";var R=e(p(),1),z=[1e3,2e3,4e3,8e3,16e3];function B(e,n){let[r,i]=(0,R.useState)(`connecting`),a=(0,R.useRef)(null),o=(0,R.useRef)(0),s=(0,R.useRef)(null),c=(0,R.useRef)(n);c.current=n;let l=(0,R.useCallback)(()=>{let n=t(),r=n?new WebSocket(e,[`specrails-desktop`,n]):new WebSocket(e);a.current=r,i(`connecting`),r.onopen=()=>{o.current=0,i(`connected`)},r.onmessage=e=>{try{let t=JSON.parse(e.data);c.current(t)}catch{}},r.onclose=()=>{a.current=null;let e=o.current;if(e>=z.length){i(`disconnected`);return}let t=z[e];o.current+=1,s.current=setTimeout(l,t)}},[e]);return(0,R.useEffect)(()=>(l(),()=>{s.current&&clearTimeout(s.current);let e=a.current;e&&(e.onopen=null,e.onmessage=null,e.onclose=null,e.onerror=null,e.close()),a.current=null}),[l]),{connectionStatus:r}}var V=r();function H(e,t){let n=new Date(t).getTime()-new Date(e).getTime();if(n<0)return`—`;let r=Math.round(n/1e3);if(r<60)return`${r}s`;let i=Math.floor(r/60),a=r%60;return i<60?`${i}m ${a}s`:`${Math.floor(i/60)}h ${i%60}m`}var U={running:{variant:`running`,labelKey:`statusLabel.running`,tooltipKey:`statusTooltip.running`},completed:{variant:`success`,labelKey:`statusLabel.completed`,tooltipKey:`statusTooltip.completed`},failed:{variant:`failed`,labelKey:`statusLabel.failed`,tooltipKey:`statusTooltip.failed`},canceled:{variant:`canceled`,labelKey:`statusLabel.canceled`,tooltipKey:`statusTooltip.canceled`},queued:{variant:`queued`,labelKey:`statusLabel.queued`,tooltipKey:`statusTooltip.queued`},zombie_terminated:{variant:`failed`,labelKey:`statusLabel.zombie`,tooltipKey:`statusTooltip.zombie`}};function W({jobId:e,onClose:t}){let{t:n}=y(`jobs`),[r,i]=(0,R.useState)(null),[a,p]=(0,R.useState)([]),[b,x]=(0,R.useState)([]),[E,k]=(0,R.useState)({}),[j,N]=(0,R.useState)(!0),[F,z]=(0,R.useState)(!1),[W,G]=(0,R.useState)(!1);(0,R.useEffect)(()=>{async function t(){try{let t=await fetch(`${P()}/jobs/${e}`);if(t.status===404){z(!0);return}if(!t.ok)throw Error(`Failed to fetch job`);let n=await t.json();if(i(n.job),p(n.events),n.phaseDefinitions){x(n.phaseDefinitions);let e={};for(let t of n.phaseDefinitions)e[t.key]=`idle`;k(e)}}catch{z(!0)}finally{N(!1)}}t()},[e]);let K=(0,R.useRef)([]),q=(0,R.useRef)(null),J=(0,R.useCallback)(()=>{q.current=null;let e=K.current;e.length!==0&&(K.current=[],p(t=>{let n=[...t,...e];return n.length>1e4?n.slice(n.length-8e3):n}))},[]);(0,R.useEffect)(()=>()=>{q.current&&cancelAnimationFrame(q.current)},[]),B(g,(0,R.useCallback)(t=>{let n=t;if(n.type===`event`&&n.jobId===e){let t={id:Date.now(),job_id:e,seq:0,event_type:n.event_type,source:n.source,payload:n.payload,timestamp:n.timestamp};K.current.push(t),q.current||=requestAnimationFrame(J)}else if(n.type===`log`&&n.processId===e&&n.source===`stderr`){let t={id:Date.now(),job_id:e,seq:0,event_type:`log`,source:`stderr`,payload:JSON.stringify({line:n.line}),timestamp:n.timestamp};K.current.push(t),q.current||=requestAnimationFrame(J)}else if(n.type===`phase`){let e=n.phase,t=n.state;k(n=>({...n,[e]:t}))}else if(n.type===`queue`){let t=n.jobs?.find(t=>t.id===e);t&&r&&i(e=>e&&{...e,status:t.status})}},[e,r,J])),(0,R.useEffect)(()=>{function e(e){e.key===`Escape`&&t()}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);async function Y(){try{let t=await fetch(`${P()}/jobs/${e}`,{method:`DELETE`});if(t.ok)h.success(n(`modal.toast.cancelSignalSent`),{description:n(`modal.toast.cancelSignalSentDescription`)});else{let e=await t.json();h.error(n(`modal.toast.cancelFailed`),{description:e.error})}}catch{h.error(n(`modal.toast.networkError`))}}let X=r?U[r.status]??U.queued:U.queued,Z=r?.status===`running`,{panelRef:Q,panelStyle:$,headerHandleProps:ee,resizeHandles:te,isFloating:ne,guardBackdrop:re}=d();return(0,V.jsx)(m,{delayDuration:400,children:(0,V.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-stretch justify-center`,children:[(0,V.jsx)(`div`,{className:`absolute inset-0 bg-black/50 backdrop-blur-sm`,onClick:re(t)}),(0,V.jsxs)(`div`,{ref:Q,className:`relative w-full m-3 rounded-xl glass-card border border-border/30 flex flex-col animate-in fade-in zoom-in-95 duration-200 overflow-hidden`,style:$,children:[(0,V.jsxs)(`div`,{...ee,className:`flex items-center justify-between px-4 py-3 border-b border-border/30${ne?` cursor-grab active:cursor-grabbing`:``}`,children:[(0,V.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[r&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(o,{children:[(0,V.jsx)(v,{asChild:!0,children:(0,V.jsx)(`div`,{children:(0,V.jsx)(T,{variant:X.variant,children:n(X.labelKey)})})}),(0,V.jsx)(u,{children:n(X.tooltipKey)})]}),(0,V.jsx)(`code`,{className:`text-xs font-mono text-foreground/80 truncate`,children:r.command}),(0,V.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:O(new Date(r.started_at),{addSuffix:!0,locale:D()})}),r.total_cost_usd!=null&&r.total_cost_usd>0&&(0,V.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[`$`,r.total_cost_usd.toFixed(4)]}),r.finished_at&&(0,V.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:H(r.started_at,r.finished_at)})]}),j&&(0,V.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:n(`common:states.loading`)})]}),(0,V.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[b.length>0&&(0,V.jsx)(`div`,{className:`mr-3`,children:(0,V.jsx)(I,{phases:E,phaseDefinitions:b})}),Z&&(0,V.jsx)(_,{variant:`ghost`,size:`sm`,onClick:()=>G(!0),className:`h-7 text-destructive hover:text-destructive hover:bg-destructive/10`,children:n(`common:actions.cancel`)}),(0,V.jsxs)(o,{children:[(0,V.jsx)(v,{asChild:!0,children:(0,V.jsx)(`a`,{href:`/jobs/${e}`,target:`_blank`,rel:`noopener noreferrer`,className:`h-7 w-7 flex items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-surface/50 transition-colors`,children:(0,V.jsx)(l,{className:`w-3.5 h-3.5`})})}),(0,V.jsx)(u,{children:n(`modal.openInNewTab`)})]}),(0,V.jsx)(`button`,{onClick:t,className:`h-7 w-7 flex items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-surface/50 transition-colors cursor-pointer`,children:(0,V.jsx)(M,{className:`w-4 h-4`})})]})]}),(0,V.jsx)(`div`,{className:`flex-1 overflow-hidden relative`,children:F?(0,V.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,V.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:n(`modal.notFound`)})}):(0,V.jsx)(L,{events:a,isLoading:j})})]}),(0,V.jsx)(A,{handles:te}),(0,V.jsx)(C,{open:W,onOpenChange:G,children:(0,V.jsxs)(c,{className:`max-w-sm`,children:[(0,V.jsxs)(s,{children:[(0,V.jsx)(f,{children:n(`modal.cancelConfirmTitle`)}),(0,V.jsx)(S,{children:n(`modal.cancelConfirmDescription`)})]}),(0,V.jsxs)(w,{children:[(0,V.jsx)(_,{variant:`ghost`,size:`sm`,onClick:()=>G(!1),children:n(`modal.keepRunning`)}),(0,V.jsx)(_,{variant:`destructive`,size:`sm`,onClick:()=>{G(!1),Y()},children:n(`modal.cancelJob`)})]})]})})]})})}var G=360,K=480,q={running:`running`,completed:`success`,failed:`failed`,canceled:`canceled`,queued:`queued`};function J({projectId:e}){let{t}=y(`agent`),{t:r}=y(`jobs`),{closeJobsPane:o}=k(),{projects:s}=N(),c=s.find(t=>t.id===e)?.provider,[l,u]=(0,R.useState)(K),[d,f]=(0,R.useState)(!1),[p,m]=(0,R.useState)(null),{data:h,isFirstLoad:g,refresh:_}=E({namespace:`agent-jobs`,projectId:e,initialValue:[],fetcher:async()=>{let e=await fetch(`${P()}/jobs?limit=50`);return e.ok?(await e.json()).jobs:[]},pollInterval:5e3}),{registerHandler:v,unregisterHandler:S}=b(),C=(0,R.useRef)(e);C.current=e;let w=(0,R.useRef)(_);w.current=_,(0,R.useEffect)(()=>(v(`agent-jobs-pane`,e=>{let t=e;t.type===`queue`&&(t.projectId&&t.projectId!==C.current||w.current())}),()=>S(`agent-jobs-pane`)),[v,S]);let A=(0,R.useCallback)(e=>{let t=e.clientX,n=l,r=window.innerWidth-G;try{e.currentTarget.setPointerCapture(e.pointerId)}catch{}let i=e=>{u(Math.min(Math.max(n+(t-e.clientX),G),r))},a=()=>{window.removeEventListener(`pointermove`,i),window.removeEventListener(`pointerup`,a),window.removeEventListener(`pointercancel`,a)};window.addEventListener(`pointermove`,i),window.addEventListener(`pointerup`,a),window.addEventListener(`pointercancel`,a)},[l]);return(0,V.jsxs)(`div`,{className:n(`flex h-full flex-col overflow-hidden border-l border-border bg-background`,d&&`absolute inset-0 z-30 border-l-0`),style:d?void 0:{width:l,flexShrink:0},children:[(0,V.jsx)(`div`,{className:`relative flex items-center`,children:!d&&(0,V.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,onPointerDown:A,className:`absolute left-0 top-0 h-full w-1.5 -translate-x-full cursor-col-resize select-none touch-none hover:bg-accent-primary/20`,title:t(`workspace.resizeJobs`)})}),(0,V.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-border/60 bg-surface/40 px-3 py-1.5`,children:[(0,V.jsx)(`span`,{className:`text-xs font-medium text-foreground/70`,children:t(`workspace.jobs`)}),(0,V.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[(0,V.jsx)(`button`,{type:`button`,onClick:()=>f(e=>!e),"aria-label":t(d?`restore`:`maximize`),title:t(d?`restore`:`maximize`),className:`rounded-md p-1 text-foreground/60 hover:bg-surface hover:text-foreground`,children:d?(0,V.jsx)(x,{className:`h-4 w-4`}):(0,V.jsx)(a,{className:`h-4 w-4`})}),(0,V.jsx)(`button`,{type:`button`,onClick:o,"aria-label":t(`workspace.closeJobs`),title:t(`workspace.closeJobs`),className:`rounded-md p-1 text-foreground/60 hover:bg-surface hover:text-foreground`,children:(0,V.jsx)(M,{className:`h-4 w-4`})})]})]}),(0,V.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-2`,children:g?(0,V.jsx)(`div`,{className:`flex h-24 items-center justify-center text-muted-foreground`,children:(0,V.jsx)(i,{className:`h-4 w-4 animate-spin`})}):h.length===0?(0,V.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-2 text-center text-muted-foreground`,children:[(0,V.jsx)(j,{className:`h-6 w-6 opacity-40`}),(0,V.jsx)(`p`,{className:`text-xs`,children:t(`workspace.noJobs`)})]}):(0,V.jsx)(`ul`,{className:`space-y-1`,children:h.map(e=>(0,V.jsx)(`li`,{children:(0,V.jsxs)(`button`,{type:`button`,onClick:()=>m(e.id),className:n(`flex w-full flex-col gap-1 rounded-lg border border-border/50 bg-surface/30 px-2.5 py-2 text-left transition-colors`,`hover:border-accent-primary/40 hover:bg-surface/60`),children:[(0,V.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,V.jsx)(T,{variant:q[e.status]??`queued`,children:r(`statusLabel.${e.status in q?e.status:`queued`}`)}),e.status===`running`&&(0,V.jsx)(i,{className:`h-3 w-3 animate-spin text-accent-primary`}),(0,V.jsx)(`span`,{className:`ml-auto text-[10px] text-muted-foreground`,children:O(new Date(e.started_at),{addSuffix:!0,locale:D()})})]}),(0,V.jsx)(`code`,{className:`truncate font-mono text-xs text-foreground/85`,children:F(e.command,c)})]})},e.id))})}),p&&(0,V.jsx)(W,{jobId:p,onClose:()=>m(null)})]})}export{J as AgentModeJobsPane};
|
|
1
|
+
import{a as e}from"./chunk-BNv3lrIs.js";import{n as t}from"./auth-Cvsb7-Ek.js";import{$ as n,Cn as r,Dt as i,Et as a,F as o,G as s,H as c,Ht as l,I as u,J as d,K as f,Kn as p,L as m,Ln as h,M as g,Q as _,R as v,Rn as y,Sn as b,Tt as x,U as S,V as C,W as w,Z as T,dn as E,fn as D,g as O,n as k,q as A,tn as j,tt as M,un as N,wn as P}from"./index-D4R3rVF5.js";import{t as F}from"./format-command-BHymDa4r.js";import{n as I,t as L}from"./LogViewer-Cf6s1TDs.js";var R=e(p(),1),z=[1e3,2e3,4e3,8e3,16e3];function B(e,n){let[r,i]=(0,R.useState)(`connecting`),a=(0,R.useRef)(null),o=(0,R.useRef)(0),s=(0,R.useRef)(null),c=(0,R.useRef)(n);c.current=n;let l=(0,R.useCallback)(()=>{let n=t(),r=n?new WebSocket(e,[`specrails-desktop`,n]):new WebSocket(e);a.current=r,i(`connecting`),r.onopen=()=>{o.current=0,i(`connected`)},r.onmessage=e=>{try{let t=JSON.parse(e.data);c.current(t)}catch{}},r.onclose=()=>{a.current=null;let e=o.current;if(e>=z.length){i(`disconnected`);return}let t=z[e];o.current+=1,s.current=setTimeout(l,t)}},[e]);return(0,R.useEffect)(()=>(l(),()=>{s.current&&clearTimeout(s.current);let e=a.current;e&&(e.onopen=null,e.onmessage=null,e.onclose=null,e.onerror=null,e.close()),a.current=null}),[l]),{connectionStatus:r}}var V=r();function H(e,t){let n=new Date(t).getTime()-new Date(e).getTime();if(n<0)return`—`;let r=Math.round(n/1e3);if(r<60)return`${r}s`;let i=Math.floor(r/60),a=r%60;return i<60?`${i}m ${a}s`:`${Math.floor(i/60)}h ${i%60}m`}var U={running:{variant:`running`,labelKey:`statusLabel.running`,tooltipKey:`statusTooltip.running`},completed:{variant:`success`,labelKey:`statusLabel.completed`,tooltipKey:`statusTooltip.completed`},failed:{variant:`failed`,labelKey:`statusLabel.failed`,tooltipKey:`statusTooltip.failed`},canceled:{variant:`canceled`,labelKey:`statusLabel.canceled`,tooltipKey:`statusTooltip.canceled`},queued:{variant:`queued`,labelKey:`statusLabel.queued`,tooltipKey:`statusTooltip.queued`},zombie_terminated:{variant:`failed`,labelKey:`statusLabel.zombie`,tooltipKey:`statusTooltip.zombie`}};function W({jobId:e,onClose:t}){let{t:n}=y(`jobs`),[r,i]=(0,R.useState)(null),[a,p]=(0,R.useState)([]),[b,x]=(0,R.useState)([]),[E,k]=(0,R.useState)({}),[j,N]=(0,R.useState)(!0),[F,z]=(0,R.useState)(!1),[W,G]=(0,R.useState)(!1);(0,R.useEffect)(()=>{async function t(){try{let t=await fetch(`${P()}/jobs/${e}`);if(t.status===404){z(!0);return}if(!t.ok)throw Error(`Failed to fetch job`);let n=await t.json();if(i(n.job),p(n.events),n.phaseDefinitions){x(n.phaseDefinitions);let e={};for(let t of n.phaseDefinitions)e[t.key]=`idle`;k(e)}}catch{z(!0)}finally{N(!1)}}t()},[e]);let K=(0,R.useRef)([]),q=(0,R.useRef)(null),J=(0,R.useCallback)(()=>{q.current=null;let e=K.current;e.length!==0&&(K.current=[],p(t=>{let n=[...t,...e];return n.length>1e4?n.slice(n.length-8e3):n}))},[]);(0,R.useEffect)(()=>()=>{q.current&&cancelAnimationFrame(q.current)},[]),B(g,(0,R.useCallback)(t=>{let n=t;if(n.type===`event`&&n.jobId===e){let t={id:Date.now(),job_id:e,seq:0,event_type:n.event_type,source:n.source,payload:n.payload,timestamp:n.timestamp};K.current.push(t),q.current||=requestAnimationFrame(J)}else if(n.type===`log`&&n.processId===e&&n.source===`stderr`){let t={id:Date.now(),job_id:e,seq:0,event_type:`log`,source:`stderr`,payload:JSON.stringify({line:n.line}),timestamp:n.timestamp};K.current.push(t),q.current||=requestAnimationFrame(J)}else if(n.type===`phase`){let e=n.phase,t=n.state;k(n=>({...n,[e]:t}))}else if(n.type===`queue`){let t=n.jobs?.find(t=>t.id===e);t&&r&&i(e=>e&&{...e,status:t.status})}},[e,r,J])),(0,R.useEffect)(()=>{function e(e){e.key===`Escape`&&t()}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);async function Y(){try{let t=await fetch(`${P()}/jobs/${e}`,{method:`DELETE`});if(t.ok)h.success(n(`modal.toast.cancelSignalSent`),{description:n(`modal.toast.cancelSignalSentDescription`)});else{let e=await t.json();h.error(n(`modal.toast.cancelFailed`),{description:e.error})}}catch{h.error(n(`modal.toast.networkError`))}}let X=r?U[r.status]??U.queued:U.queued,Z=r?.status===`running`,{panelRef:Q,panelStyle:$,headerHandleProps:ee,resizeHandles:te,isFloating:ne,guardBackdrop:re}=d();return(0,V.jsx)(m,{delayDuration:400,children:(0,V.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-stretch justify-center`,children:[(0,V.jsx)(`div`,{className:`absolute inset-0 bg-black/50 backdrop-blur-sm`,onClick:re(t)}),(0,V.jsxs)(`div`,{ref:Q,className:`relative w-full m-3 rounded-xl glass-card border border-border/30 flex flex-col animate-in fade-in zoom-in-95 duration-200 overflow-hidden`,style:$,children:[(0,V.jsxs)(`div`,{...ee,className:`flex items-center justify-between px-4 py-3 border-b border-border/30${ne?` cursor-grab active:cursor-grabbing`:``}`,children:[(0,V.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[r&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(o,{children:[(0,V.jsx)(v,{asChild:!0,children:(0,V.jsx)(`div`,{children:(0,V.jsx)(T,{variant:X.variant,children:n(X.labelKey)})})}),(0,V.jsx)(u,{children:n(X.tooltipKey)})]}),(0,V.jsx)(`code`,{className:`text-xs font-mono text-foreground/80 truncate`,children:r.command}),(0,V.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:O(new Date(r.started_at),{addSuffix:!0,locale:D()})}),r.total_cost_usd!=null&&r.total_cost_usd>0&&(0,V.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[`$`,r.total_cost_usd.toFixed(4)]}),r.finished_at&&(0,V.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:H(r.started_at,r.finished_at)})]}),j&&(0,V.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:n(`common:states.loading`)})]}),(0,V.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[b.length>0&&(0,V.jsx)(`div`,{className:`mr-3`,children:(0,V.jsx)(I,{phases:E,phaseDefinitions:b})}),Z&&(0,V.jsx)(_,{variant:`ghost`,size:`sm`,onClick:()=>G(!0),className:`h-7 text-destructive hover:text-destructive hover:bg-destructive/10`,children:n(`common:actions.cancel`)}),(0,V.jsxs)(o,{children:[(0,V.jsx)(v,{asChild:!0,children:(0,V.jsx)(`a`,{href:`/jobs/${e}`,target:`_blank`,rel:`noopener noreferrer`,className:`h-7 w-7 flex items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-surface/50 transition-colors`,children:(0,V.jsx)(l,{className:`w-3.5 h-3.5`})})}),(0,V.jsx)(u,{children:n(`modal.openInNewTab`)})]}),(0,V.jsx)(`button`,{onClick:t,className:`h-7 w-7 flex items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-surface/50 transition-colors cursor-pointer`,children:(0,V.jsx)(M,{className:`w-4 h-4`})})]})]}),(0,V.jsx)(`div`,{className:`flex-1 overflow-hidden relative`,children:F?(0,V.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,V.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:n(`modal.notFound`)})}):(0,V.jsx)(L,{events:a,isLoading:j})})]}),(0,V.jsx)(A,{handles:te}),(0,V.jsx)(C,{open:W,onOpenChange:G,children:(0,V.jsxs)(c,{className:`max-w-sm`,children:[(0,V.jsxs)(s,{children:[(0,V.jsx)(f,{children:n(`modal.cancelConfirmTitle`)}),(0,V.jsx)(S,{children:n(`modal.cancelConfirmDescription`)})]}),(0,V.jsxs)(w,{children:[(0,V.jsx)(_,{variant:`ghost`,size:`sm`,onClick:()=>G(!1),children:n(`modal.keepRunning`)}),(0,V.jsx)(_,{variant:`destructive`,size:`sm`,onClick:()=>{G(!1),Y()},children:n(`modal.cancelJob`)})]})]})})]})})}var G=360,K=480,q={running:`running`,completed:`success`,failed:`failed`,canceled:`canceled`,queued:`queued`};function J({projectId:e}){let{t}=y(`agent`),{t:r}=y(`jobs`),{closeJobsPane:o}=k(),{projects:s}=N(),c=s.find(t=>t.id===e)?.provider,[l,u]=(0,R.useState)(K),[d,f]=(0,R.useState)(!1),[p,m]=(0,R.useState)(null),{data:h,isFirstLoad:g,refresh:_}=E({namespace:`agent-jobs`,projectId:e,initialValue:[],fetcher:async()=>{let e=await fetch(`${P()}/jobs?limit=50`);return e.ok?(await e.json()).jobs:[]},pollInterval:5e3}),{registerHandler:v,unregisterHandler:S}=b(),C=(0,R.useRef)(e);C.current=e;let w=(0,R.useRef)(_);w.current=_,(0,R.useEffect)(()=>(v(`agent-jobs-pane`,e=>{let t=e;t.type===`queue`&&(t.projectId&&t.projectId!==C.current||w.current())}),()=>S(`agent-jobs-pane`)),[v,S]);let A=(0,R.useCallback)(e=>{let t=e.clientX,n=l,r=window.innerWidth-G;try{e.currentTarget.setPointerCapture(e.pointerId)}catch{}let i=e=>{u(Math.min(Math.max(n+(t-e.clientX),G),r))},a=()=>{window.removeEventListener(`pointermove`,i),window.removeEventListener(`pointerup`,a),window.removeEventListener(`pointercancel`,a)};window.addEventListener(`pointermove`,i),window.addEventListener(`pointerup`,a),window.addEventListener(`pointercancel`,a)},[l]);return(0,V.jsxs)(`div`,{className:n(`flex h-full flex-col overflow-hidden border-l border-border bg-background`,d&&`absolute inset-0 z-30 border-l-0`),style:d?void 0:{width:l,flexShrink:0},children:[(0,V.jsx)(`div`,{className:`relative flex items-center`,children:!d&&(0,V.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,onPointerDown:A,className:`absolute left-0 top-0 h-full w-1.5 -translate-x-full cursor-col-resize select-none touch-none hover:bg-accent-primary/20`,title:t(`workspace.resizeJobs`)})}),(0,V.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-border/60 bg-surface/40 px-3 py-1.5`,children:[(0,V.jsx)(`span`,{className:`text-xs font-medium text-foreground/70`,children:t(`workspace.jobs`)}),(0,V.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[(0,V.jsx)(`button`,{type:`button`,onClick:()=>f(e=>!e),"aria-label":t(d?`restore`:`maximize`),title:t(d?`restore`:`maximize`),className:`rounded-md p-1 text-foreground/60 hover:bg-surface hover:text-foreground`,children:d?(0,V.jsx)(x,{className:`h-4 w-4`}):(0,V.jsx)(a,{className:`h-4 w-4`})}),(0,V.jsx)(`button`,{type:`button`,onClick:o,"aria-label":t(`workspace.closeJobs`),title:t(`workspace.closeJobs`),className:`rounded-md p-1 text-foreground/60 hover:bg-surface hover:text-foreground`,children:(0,V.jsx)(M,{className:`h-4 w-4`})})]})]}),(0,V.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-2`,children:g?(0,V.jsx)(`div`,{className:`flex h-24 items-center justify-center text-muted-foreground`,children:(0,V.jsx)(i,{className:`h-4 w-4 animate-spin`})}):h.length===0?(0,V.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-2 text-center text-muted-foreground`,children:[(0,V.jsx)(j,{className:`h-6 w-6 opacity-40`}),(0,V.jsx)(`p`,{className:`text-xs`,children:t(`workspace.noJobs`)})]}):(0,V.jsx)(`ul`,{className:`space-y-1`,children:h.map(e=>(0,V.jsx)(`li`,{children:(0,V.jsxs)(`button`,{type:`button`,onClick:()=>m(e.id),className:n(`flex w-full flex-col gap-1 rounded-lg border border-border/50 bg-surface/30 px-2.5 py-2 text-left transition-colors`,`hover:border-accent-primary/40 hover:bg-surface/60`),children:[(0,V.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,V.jsx)(T,{variant:q[e.status]??`queued`,children:r(`statusLabel.${e.status in q?e.status:`queued`}`)}),e.status===`running`&&(0,V.jsx)(i,{className:`h-3 w-3 animate-spin text-accent-primary`}),(0,V.jsx)(`span`,{className:`ml-auto text-[10px] text-muted-foreground`,children:O(new Date(e.started_at),{addSuffix:!0,locale:D()})})]}),(0,V.jsx)(`code`,{className:`truncate font-mono text-xs text-foreground/85`,children:F(e.command,c)})]})},e.id))})}),p&&(0,V.jsx)(W,{jobId:p,onClose:()=>m(null)})]})}export{J as AgentModeJobsPane};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as e}from"./chunk-BNv3lrIs.js";import{$t as t,An as n,Bn as r,Cn as i,Ct as a,Dn as o,Dt as s,En as c,Fn as l,G as u,H as d,Ht as f,In as p,J as m,K as h,Kn as g,Ln as _,Mn as v,Mt as y,Nn as b,On as x,Pn as S,Q as C,Qt as w,Rn as T,Rt as E,Sn as D,T as O,Tn as k,U as A,V as j,W as M,Wt as ee,X as N,Xt as P,Y as F,an as I,at as L,bt as R,cn as z,en as B,f as te,ht as V,it as H,jn as ne,jt as U,kn as re,mt as ie,on as W,pn as ae,q as oe,rn as se,st as ce,tt as G,un as le,ut as K,vt as q,wn as J,wt as ue}from"./index-CG4z4_Mq.js";var Y=z(`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`}]]),de=z(`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=z(`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`}]]),X=e(g(),1),Z=i(),pe=/^[a-z0-9][a-z0-9-]*$/;function me({open:e,mode:t=`add`,initial:n,chainAgents:i,onConfirm:a,onCancel:o}){let{t:s}=T(`agents`),[c,l]=(0,X.useState)(``),[f,p]=(0,X.useState)(i[0]??``);(0,X.useEffect)(()=>{e&&(t===`edit`&&n?(l(n.tags.join(`, `)),p(i.includes(n.agent)?n.agent:i[0]??``)):(l(``),p(i[0]??``)))},[e,t,n,i]);let m=c.split(`,`).map(e=>e.trim()).filter(Boolean),g=m.filter(e=>!pe.test(e)),_=m.length>0&&g.length===0&&i.includes(f);return(0,Z.jsx)(j,{open:e,onOpenChange:e=>{e||o()},children:(0,Z.jsxs)(d,{movableResizable:!0,className:`max-w-md`,children:[(0,Z.jsxs)(u,{children:[(0,Z.jsx)(h,{children:s(t===`edit`?`routingRule.editTitle`:`routingRule.addTitle`)}),(0,Z.jsx)(A,{children:s(t===`edit`?`routingRule.editDescription`:`routingRule.addDescription`)})]}),(0,Z.jsxs)(`div`,{className:`py-2 space-y-3`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:s(`routingRule.tagsLabel`)}),(0,Z.jsx)(te,{autoFocus:!0,value:c,onChange:e=>l(e.target.value),placeholder:`frontend, ui`,"aria-label":s(`routingRule.tagsLabel`),className:`text-sm font-mono`}),(0,Z.jsx)(`p`,{className:`text-[11px] text-muted-foreground mt-1`,children:(0,Z.jsx)(r,{t:s,i18nKey:`routingRule.tagsHint`,components:{code:(0,Z.jsx)(`code`,{})}})}),g.length>0&&(0,Z.jsx)(`p`,{className:`text-[11px] text-red-400 aurora-light:text-destructive mt-1`,children:s(`routingRule.invalidTags`,{count:g.length,tags:g.join(`, `)})})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:s(`routingRule.routeToLabel`)}),(0,Z.jsx)(`select`,{value:f,onChange:e=>p(e.target.value),"aria-label":s(`routingRule.routeToLabel`),className:`w-full h-9 px-2 text-sm rounded-md border border-border bg-background`,children:i.map(e=>(0,Z.jsx)(`option`,{value:e,children:e},e))}),(0,Z.jsx)(`p`,{className:`text-[11px] text-muted-foreground mt-1`,children:s(`routingRule.routeToHint`)})]})]}),(0,Z.jsxs)(M,{children:[(0,Z.jsx)(C,{variant:`ghost`,size:`sm`,onClick:o,children:s(`common:actions.cancel`)}),(0,Z.jsx)(C,{size:`sm`,onClick:()=>a(m,f),disabled:!_,children:s(t===`edit`?`routingRule.saveChanges`:`routingRule.addRule`)})]})]})})}var Q=new Set([`sr-architect`,`sr-developer`,`sr-reviewer`,`sr-merge-resolver`]),he=[`sonnet`,`fable`,`opus`,`haiku`],ge=/^[a-z0-9][a-z0-9-]*$/;function _e({profile:e,onChange:t,footer:i,onValidityChange:a,onSoftWarningsChange:s}){let{t:u}=T(`agentstudio`),[d,f]=(0,X.useState)([]),[p,m]=(0,X.useState)(!1),[h,g]=(0,X.useState)(!1),[_,y]=(0,X.useState)(null);(0,X.useEffect)(()=>{let e=!1;return fetch(`${J()}/profiles/catalog`).then(e=>e.ok?e.json():{agents:[]}).then(t=>{e||f(t.agents)}).catch(()=>{e||f([])}),()=>{e=!0}},[]);let x=n=>{let r=JSON.parse(JSON.stringify(e));n(r),t(r)},w=new Set(e.agents.map(e=>e.id)),E=d.filter(e=>!w.has(e.id)),D=(0,X.useMemo)(()=>{let t=[];for(let n of Q)e.agents.some(e=>e.id===n)||t.push(u(`profileEditor.validation.missingBaseline`,{agent:n}));let n=e.routing.filter(e=>`default`in e&&e.default===!0);if(n.length>1&&t.push(u(`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(u(`profileEditor.validation.defaultRuleNotLast`))}for(let n of e.routing)if(e.agents.some(e=>e.id===n.agent)||t.push(u(`profileEditor.validation.unknownRoutingAgent`,{agent:n.agent})),`tags`in n){let e=n.tags.filter(e=>!ge.test(e));e.length>0&&t.push(u(`profileEditor.validation.invalidTags`,{agent:n.agent,tags:e.join(`, `)}))}return t},[e,u]),O=(0,X.useMemo)(()=>{if(e.routing.length===0)return[];let t=new Set(e.routing.map(e=>e.agent));return e.agents.filter(e=>!Q.has(e.id)&&!t.has(e.id)).map(e=>e.id)},[e]),A=(0,X.useMemo)(()=>e.routing.some(e=>`default`in e&&e.default===!0),[e.routing]);(0,X.useEffect)(()=>{a&&a(D)},[D,a]),(0,X.useEffect)(()=>{s&&s({agentsMissingRouting:O})},[O,s]);let j=e=>{x(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)}),m(!1)},M=t=>{let n=e.agents[t];Q.has(n.id)||x(e=>{e.agents.splice(t,1),e.routing=e.routing.filter(e=>e.agent!==n.id)})},ee=(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=c(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)}x(e=>{e.agents=a})},N=l(S(v,{activationConstraint:{distance:4}}),S(ne,{coordinateGetter:o})),P=e=>{let{active:t,over:n}=e;n&&ee(String(t.id),String(n.id))},F=(e,t)=>{x(n=>{n.agents[e].model=t})},I=(e,t)=>{x(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)}),g(!1)},L=()=>{x(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,B=(e,t)=>{x(n=>{let r=n.routing[e];r&&(z(r)||(r.agent=t))})},V=(e,t,n)=>{x(r=>{let i=r.routing[e];i&&(z(i)||(i.tags=t,i.agent=n))})},H=e=>{x(t=>{let n=t.routing[e];n&&(z(n)||t.routing.splice(e,1))})},U=(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)||x(e=>{let[n]=e.routing.splice(t,1);e.routing.splice(r,0,n)})};return(0,Z.jsxs)(`div`,{className:`p-6 space-y-6 max-w-3xl`,children:[(0,Z.jsx)(me,{open:h,mode:`add`,chainAgents:e.agents.map(e=>e.id),onConfirm:I,onCancel:()=>g(!1)}),(0,Z.jsx)(me,{open:_!==null,mode:`edit`,initial:_!==null&&e.routing[_]&&!(`default`in e.routing[_])?{tags:e.routing[_].tags,agent:e.routing[_].agent}:void 0,chainAgents:e.agents.map(e=>e.id),onConfirm:(e,t)=>{_!==null&&(V(_,e,t),y(null))},onCancel:()=>y(null)}),D.length>0&&(0,Z.jsxs)(`div`,{className:`px-3 py-2 text-xs rounded-md border border-yellow-500/30 aurora-light:border-accent-warning/30 bg-yellow-500/10 aurora-light:bg-accent-warning/10 text-yellow-500 aurora-light:text-accent-warning`,children:[(0,Z.jsx)(`div`,{className:`font-medium mb-1`,children:u(`profileEditor.validationSummary`,{count:D.length})}),(0,Z.jsx)(`ul`,{className:`list-disc list-inside space-y-0.5`,children:D.map((e,t)=>(0,Z.jsx)(`li`,{children:e},t))})]}),(0,Z.jsxs)(`section`,{className:`space-y-3`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:u(`profileEditor.nameLabel`)}),(0,Z.jsx)(te,{value:e.name,disabled:!0,className:`text-sm`})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:u(`profileEditor.descriptionLabel`)}),(0,Z.jsx)(te,{value:e.description??``,onChange:e=>x(t=>{t.description=e.target.value}),className:`text-sm`,placeholder:u(`profileEditor.descriptionPlaceholder`)})]})]}),(0,Z.jsxs)(`section`,{children:[(0,Z.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide mb-2`,children:u(`profileEditor.orchestrator.heading`)}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 p-3 rounded-md border border-border`,children:[(0,Z.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Z.jsx)(`div`,{className:`text-sm font-mono text-foreground truncate`,children:`/specrails:implement · /specrails:batch-implement`}),(0,Z.jsx)(`div`,{className:`text-[11px] text-muted-foreground mt-0.5`,children:u(`profileEditor.orchestrator.description`)})]}),(0,Z.jsx)(be,{value:e.orchestrator.model,onChange:e=>x(t=>{t.orchestrator.model=e})})]})]}),(0,Z.jsxs)(`section`,{children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,Z.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:u(`profileEditor.agentChain.heading`,{n:e.agents.length})}),(0,Z.jsxs)(C,{size:`sm`,variant:`ghost`,onClick:()=>m(e=>!e),disabled:E.length===0,title:E.length===0?u(`profileEditor.agentChain.addDisabledTitle`):u(`profileEditor.agentChain.addTitle`),children:[(0,Z.jsx)(R,{className:`w-3.5 h-3.5 mr-1`}),` `,u(`common:actions.add`)]})]}),p&&(0,Z.jsxs)(`div`,{className:`mb-2 p-2 rounded-md border border-border bg-muted/30`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between mb-1.5 px-1`,children:[(0,Z.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:u(`profileEditor.agentChain.pickFromCatalog`,{n:E.length})}),(0,Z.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:()=>m(!1),title:u(`common:actions.close`),children:(0,Z.jsx)(G,{className:`w-3 h-3`})})]}),E.length===0?(0,Z.jsx)(`div`,{className:`px-2 py-3 text-xs text-muted-foreground text-center`,children:u(`profileEditor.agentChain.emptyCatalog`)}):(0,Z.jsx)(`div`,{className:`space-y-0.5 max-h-64 overflow-auto`,children:E.map(e=>(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>j(e.id),className:`w-full flex items-center justify-between gap-2 px-2 py-1.5 text-left rounded hover:bg-accent transition-colors`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-mono`,children:e.id}),(0,Z.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded `+(e.kind===`custom`?`bg-purple-500/15 aurora-light:bg-accent-secondary/15 text-purple-400 aurora-light:text-accent-secondary`:`bg-muted text-muted-foreground`),children:u(`profileEditor.agentChain.kind.${e.kind}`)})]},e.id))})]}),(0,Z.jsx)(n,{sensors:N,collisionDetection:b,onDragEnd:P,children:(0,Z.jsx)(k,{items:e.agents.map(e=>e.id),strategy:re,children:(0,Z.jsx)(`div`,{className:`space-y-1.5`,children:e.agents.map((e,t)=>(0,Z.jsx)(ve,{agent:e,canRemove:!Q.has(e.id),onModel:e=>F(t,e),onRemove:()=>M(t)},e.id))})})})]}),(0,Z.jsxs)(`section`,{children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,Z.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:u(`profileEditor.routing.heading`,{n:e.routing.length})}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[!A&&(0,Z.jsxs)(C,{size:`sm`,variant:`ghost`,onClick:L,disabled:e.agents.length===0,title:e.agents.length===0?u(`profileEditor.routing.needAgentsTitle`):void 0,children:[(0,Z.jsx)(R,{className:`w-3.5 h-3.5 mr-1`}),` `,u(`profileEditor.routing.addDefault`)]}),(0,Z.jsxs)(C,{size:`sm`,variant:`ghost`,onClick:()=>g(!0),disabled:e.agents.length===0,title:e.agents.length===0?u(`profileEditor.routing.needAgentsTitle`):void 0,children:[(0,Z.jsx)(R,{className:`w-3.5 h-3.5 mr-1`}),` `,u(`profileEditor.routing.addRule`)]})]})]}),(0,Z.jsx)(`p`,{className:`text-[11px] text-muted-foreground mb-2`,children:u(`profileEditor.routing.explainer`)}),O.length>0&&(0,Z.jsxs)(`div`,{className:`mb-2 px-3 py-2 text-xs rounded-md border border-yellow-500/30 aurora-light:border-accent-warning/30 bg-yellow-500/10 aurora-light:bg-accent-warning/10 text-yellow-500 aurora-light:text-accent-warning`,children:[(0,Z.jsx)(`div`,{className:`font-medium mb-1`,children:u(`profileEditor.routing.untargetedTitle`)}),(0,Z.jsx)(`div`,{children:(0,Z.jsx)(r,{t:u,i18nKey:`profileEditor.routing.untargetedDetail`,values:{agents:O.join(`, `)},components:{mono:(0,Z.jsx)(`span`,{className:`font-mono`})}})})]}),(0,Z.jsx)(`div`,{className:`space-y-1.5`,children:e.routing.map((t,n)=>{let r=`default`in t&&t.default===!0;return(0,Z.jsx)(ye,{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=>B(n,e),onEdit:()=>y(n),onUp:()=>U(n,-1),onDown:()=>U(n,1),onRemove:()=>H(n)},n)})})]}),i&&(0,Z.jsx)(`div`,{className:`pt-3 border-t border-border`,children:i})]})}function ve({agent:e,canRemove:t,onModel:n,onRemove:r}){let{t:i}=T(`agentstudio`),a=Q.has(e.id),o=e.id===`sr-architect`,s=e.id===`sr-merge-resolver`,{attributes:c,listeners:l,setNodeRef:u,transform:d,transition:f,isDragging:m}=x({id:e.id});return(0,Z.jsxs)(`div`,{ref:u,style:{transform:p.Transform.toString(d),transition:f,opacity:m?.5:void 0,zIndex:m?10:void 0},className:`flex items-center gap-2 px-2 py-1.5 rounded-md border border-border group hover:bg-accent/30 transition-colors bg-background`,children:[(0,Z.jsx)(`button`,{type:`button`,className:`flex-shrink-0 p-0.5 rounded text-muted-foreground cursor-grab active:cursor-grabbing hover:text-foreground`,title:i(`profileEditor.agentRow.dragTitle`),"aria-label":i(`profileEditor.agentRow.dragHandleAria`),...c,...l,children:(0,Z.jsx)(y,{className:`w-3.5 h-3.5`})}),(0,Z.jsx)(`span`,{className:`text-sm font-mono flex-1 truncate`,children:e.id}),o&&(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded bg-accent-primary/15 text-accent-primary`,title:i(`profileEditor.agentRow.pinnedFirstTitle`),children:[(0,Z.jsx)(de,{className:`w-2.5 h-2.5 rotate-[135deg]`}),` `,i(`profileEditor.agentRow.pinnedFirst`)]}),s&&(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded bg-accent-primary/15 text-accent-primary`,title:i(`profileEditor.agentRow.pinnedLastTitle`),children:[(0,Z.jsx)(de,{className:`w-2.5 h-2.5 rotate-45`}),` `,i(`profileEditor.agentRow.pinnedLast`)]}),a&&!o&&!s&&(0,Z.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:i(`profileEditor.agentRow.required`)}),(0,Z.jsx)(be,{value:e.model??`sonnet`,onChange:n}),(0,Z.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-red-500/20 aurora-light:hover:bg-destructive/15 text-red-400 aurora-light:text-destructive rounded disabled:opacity-30 disabled:cursor-not-allowed opacity-0 group-hover:opacity-100 transition-opacity`,onClick:r,disabled:!t,title:i(t?`common:actions.remove`:`profileEditor.agentRow.requiredRemoveTitle`),children:(0,Z.jsx)(G,{className:`w-3 h-3`})})]})}function ye({rule:e,ordinal:t,isLast:n,canMove:r,canRemove:i,canEdit:o,chainAgents:s,onAgentChange:c,onEdit:l,onUp:u,onDown:d,onRemove:f}){let{t:p}=T(`agentstudio`),m=`default`in e&&e.default===!0;return(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 rounded-md border border-border group hover:bg-accent/30 transition-colors`,children:[(0,Z.jsxs)(`span`,{className:`text-[10px] font-mono text-muted-foreground w-5 text-center flex-shrink-0`,children:[t,`.`]}),m?(0,Z.jsx)(`span`,{className:`text-xs text-muted-foreground flex-1`,children:p(`profileEditor.routingRow.everythingElse`)}):(0,Z.jsx)(`span`,{className:`text-xs flex-1 flex gap-1 flex-wrap items-center`,children:e.tags.map(e=>(0,Z.jsx)(`span`,{className:`px-1.5 py-0.5 rounded bg-muted font-mono text-[11px]`,children:e},e))}),(0,Z.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`→`}),m?(0,Z.jsx)(`span`,{className:`h-7 max-w-[15rem] px-2 text-xs font-mono rounded border border-border bg-muted/40 text-muted-foreground inline-flex items-center`,"aria-label":p(`profileEditor.routingRow.defaultTargetAria`),title:p(`profileEditor.routingRow.defaultTargetTitle`),children:e.agent}):(0,Z.jsx)(`select`,{value:e.agent,onChange:e=>c(e.target.value),"aria-label":p(`profileEditor.routingRow.targetAria`,{ordinal:t}),className:`h-7 max-w-[15rem] px-2 text-xs font-mono rounded border border-border bg-background`,children:s.map(e=>(0,Z.jsx)(`option`,{value:e,children:e},e))}),(0,Z.jsxs)(`div`,{className:`flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity`,children:[o&&(0,Z.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:l,title:p(`profileEditor.routingRow.editTitle`),"aria-label":p(`profileEditor.routingRow.editAria`,{ordinal:t}),children:(0,Z.jsx)(a,{className:`w-3 h-3`})}),r&&!n&&(0,Z.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:d,title:p(`profileEditor.routingRow.moveDown`),children:(0,Z.jsx)(W,{className:`w-3 h-3`})}),r&&t>1&&(0,Z.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:u,title:p(`profileEditor.routingRow.moveUp`),children:(0,Z.jsx)(se,{className:`w-3 h-3`})}),i&&(0,Z.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-red-500/20 aurora-light:hover:bg-destructive/15 text-red-400 aurora-light:text-destructive rounded`,onClick:f,title:p(`common:actions.remove`),children:(0,Z.jsx)(G,{className:`w-3 h-3`})})]}),m&&(0,Z.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,title:p(`profileEditor.routingRow.coreDefaultTitle`),children:p(`profileEditor.routingRow.coreDefaultBadge`)})]})}function be({value:e,onChange:t}){return(0,Z.jsx)(`select`,{value:e,onChange:e=>t(e.target.value),className:`h-7 px-2 text-xs rounded border border-border bg-background`,children:he.map(e=>(0,Z.jsx)(`option`,{value:e,children:e},e))})}function xe({open:e,title:t,description:n,placeholder:r,initialValue:i=``,confirmLabel:a,inputPattern:o,inputInvalidHint:s,onConfirm:c,onCancel:l}){let{t:f}=T(),[p,m]=(0,X.useState)(i);(0,X.useEffect)(()=>{e&&m(i)},[e,i]);let g=p.trim(),_=!o||o.test(g),v=g.length>0&&_;return(0,Z.jsx)(j,{open:e,onOpenChange:e=>{e||l()},children:(0,Z.jsxs)(d,{movableResizable:!0,className:`max-w-md`,children:[(0,Z.jsx)(u,{children:(0,Z.jsx)(h,{children:t})}),(0,Z.jsxs)(`div`,{className:`py-2 space-y-2`,children:[n&&(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n}),(0,Z.jsx)(te,{autoFocus:!0,value:p,placeholder:r,onChange:e=>m(e.target.value),onKeyDown:e=>{e.key===`Enter`&&v&&c(g)},className:`text-sm font-mono`}),g.length>0&&!_&&s&&(0,Z.jsx)(`p`,{className:`text-[11px] text-yellow-500 aurora-light:text-accent-warning`,children:s})]}),(0,Z.jsxs)(M,{children:[(0,Z.jsx)(C,{variant:`ghost`,size:`sm`,onClick:l,children:f(`actions.cancel`)}),(0,Z.jsx)(C,{size:`sm`,onClick:()=>c(g),disabled:!v,children:a??f(`actions.confirm`)})]})]})})}function Se({open:e,title:t,description:n,confirmLabel:r,destructive:i=!1,onConfirm:a,onCancel:o}){let{t:s}=T();return(0,Z.jsx)(j,{open:e,onOpenChange:e=>{e||o()},children:(0,Z.jsxs)(d,{movableResizable:!0,className:`max-w-md`,children:[(0,Z.jsx)(u,{children:(0,Z.jsx)(h,{children:t})}),n&&(0,Z.jsx)(`div`,{className:`py-2`,children:(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n})}),(0,Z.jsxs)(M,{children:[(0,Z.jsx)(C,{variant:`ghost`,size:`sm`,onClick:o,children:s(`actions.cancel`)}),(0,Z.jsx)(C,{size:`sm`,onClick:a,className:i?`bg-red-500 hover:bg-red-600 text-white`:void 0,children:r??s(`actions.confirm`)})]})]})})}function Ce(){let{t:e}=T(`agents`),[t,n]=(0,X.useState)([]),[i,a]=(0,X.useState)(null),[o,s]=(0,X.useState)(null),[c,l]=(0,X.useState)(!0),[u,d]=(0,X.useState)(null),[f,p]=(0,X.useState)(!1),[m,h]=(0,X.useState)([]),[g,v]=(0,X.useState)([]),[y,b]=(0,X.useState)(!1),[x,S]=(0,X.useState)(null),[w,E]=(0,X.useState)(null),D=(0,X.useCallback)(async()=>{l(!0),d(null);try{let t=await fetch(`${J()}/profiles`);if(!t.ok)throw Error(e(`profiles.errors.listFailed`,{status:t.status}));let r=await t.json();n(r.profiles),r.profiles.length>0&&!i&&a(r.profiles[0].name)}catch(e){d(e.message)}finally{l(!1)}},[i]);(0,X.useEffect)(()=>{D()},[D]),(0,X.useEffect)(()=>{if(!i){s(null);return}let t=!1;return fetch(`${J()}/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 O=(0,X.useCallback)(async()=>{p(!0),d(null);try{let t=await fetch(`${J()}/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 D(),a(`default`),_.success(e(`profiles.toasts.migrated`),{description:e(`profiles.toasts.migratedDescription`)})}catch(t){let n=t.message;d(n),_.error(e(`profiles.toasts.migrationFailed`),{description:n})}finally{p(!1)}},[D]),k=(0,X.useCallback)(async t=>{b(!1),p(!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(`${J()}/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 D(),a(t),_.success(e(`profiles.toasts.created`),{description:t})}catch(t){let n=t.message;d(n),_.error(e(`profiles.toasts.createFailed`),{description:n})}finally{p(!1)}},[D]),A=(0,X.useCallback)(async(t,n)=>{S(null),p(!0),d(null);try{let r=await fetch(`${J()}/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 D(),a(n),_.success(e(`profiles.toasts.duplicated`),{description:e(`profiles.toasts.duplicatedDescription`,{from:t,to:n})})}catch(t){let n=t.message;d(n),_.error(e(`profiles.toasts.duplicateFailed`),{description:n})}finally{p(!1)}},[D]),j=(0,X.useCallback)(async t=>{E(null),p(!0),d(null);try{let n=await fetch(`${J()}/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 D(),_.success(e(`profiles.toasts.deleted`),{description:t})}catch(t){let n=t.message;d(n),_.error(e(`profiles.toasts.deleteFailed`),{description:n})}finally{p(!1)}},[D]),M=(0,X.useCallback)(()=>b(!0),[]),N=(0,X.useCallback)(e=>S({from:e}),[]),P=(0,X.useCallback)(e=>E({name:e}),[]),F=(0,X.useCallback)(async(t,n)=>{p(!0),d(null);try{let r=await fetch(`${J()}/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?_.warning(e(`profiles.toasts.savedWithUntargeted`),{description:e(`profiles.toasts.savedWithUntargetedDescription`,{agents:n.join(`, `)}),duration:6e3}):_.success(e(`profiles.toasts.saved`),{description:t.name})}catch(t){let n=t.message;d(n),_.error(e(`profiles.toasts.saveFailed`),{description:n})}finally{p(!1)}},[e]),I=(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(xe,{open:y,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 k(e),onCancel:()=>b(!1)}),x&&(0,Z.jsx)(xe,{open:!0,title:e(`profiles.duplicateDialog.title`,{name:x.from}),description:e(`profiles.duplicateDialog.description`),placeholder:`${x.from}-copy`,initialValue:`${x.from}-copy`,confirmLabel:e(`common:actions.duplicate`),inputPattern:/^[a-z0-9][a-z0-9-]*$/,inputInvalidHint:e(`profiles.duplicateDialog.invalidHint`),onConfirm:e=>void A(x.from,e),onCancel:()=>S(null)}),w&&(0,Z.jsx)(Se,{open:!0,title:e(`profiles.deleteDialog.title`,{name:w.name}),description:e(`profiles.deleteDialog.description`),confirmLabel:e(`common:actions.delete`),destructive:!0,onConfirm:()=>void j(w.name),onCancel:()=>E(null)})]});return c?(0,Z.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`profiles.loading`)})}):t.length===0?(0,Z.jsxs)(Z.Fragment,{children:[I,(0,Z.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,Z.jsxs)(`div`,{className:`text-center max-w-md`,children:[(0,Z.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:e(`profiles.empty.title`)}),(0,Z.jsx)(`div`,{className:`text-xs text-muted-foreground mt-1 mb-4`,children:e(`profiles.empty.body`)}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 justify-center`,children:[(0,Z.jsxs)(C,{size:`sm`,onClick:O,disabled:f,children:[(0,Z.jsx)(fe,{className:`w-3.5 h-3.5 mr-1.5`}),` `,e(`profiles.empty.migrateButton`)]}),(0,Z.jsxs)(C,{size:`sm`,variant:`ghost`,onClick:M,disabled:f,children:[(0,Z.jsx)(R,{className:`w-3.5 h-3.5 mr-1.5`}),` `,e(`profiles.empty.blankButton`)]})]}),(0,Z.jsx)(`div`,{className:`text-[11px] text-muted-foreground/70 mt-3`,children:(0,Z.jsx)(r,{t:e,i18nKey:`profiles.empty.migrateExplainer`,components:{code:(0,Z.jsx)(`code`,{className:`text-foreground`})}})}),u&&(0,Z.jsx)(`div`,{className:`mt-3 text-xs text-red-400 aurora-light:text-destructive`,children:u})]})})]}):(0,Z.jsxs)(`div`,{className:`flex flex-col h-full`,children:[I,(0,Z.jsxs)(`div`,{className:`flex flex-1 min-h-0`,children:[(0,Z.jsxs)(`aside`,{className:`w-64 flex-shrink-0 border-r border-border flex flex-col`,children:[(0,Z.jsxs)(`div`,{className:`p-3 flex items-center justify-between`,children:[(0,Z.jsx)(`div`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:e(`profiles.sidebar.title`)}),(0,Z.jsx)(C,{size:`sm`,variant:`ghost`,onClick:M,disabled:f,children:(0,Z.jsx)(R,{className:`w-3.5 h-3.5`})})]}),(0,Z.jsx)(`div`,{className:`flex-1 overflow-auto px-2 pb-3`,children:t.map(t=>(0,Z.jsxs)(`div`,{className:`group mb-1 rounded-md px-2 py-1.5 text-xs cursor-pointer transition-colors flex items-center justify-between `+(t.name===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,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,Z.jsx)(`span`,{className:`truncate font-medium`,children:t.name}),t.isDefault&&(0,Z.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:e(`profiles.sidebar.teamDefault`)})]}),(0,Z.jsxs)(`div`,{className:`flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity`,children:[(0,Z.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,title:e(`common:actions.duplicate`),onClick:e=>{e.stopPropagation(),N(t.name)},children:(0,Z.jsx)(ee,{className:`w-3 h-3`})}),!t.isDefault&&(0,Z.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-red-500/20 text-red-400 aurora-light:text-destructive rounded`,title:e(`common:actions.delete`),onClick:e=>{e.stopPropagation(),P(t.name)},children:(0,Z.jsx)(L,{className:`w-3 h-3`})})]})]},t.name))})]}),(0,Z.jsxs)(`main`,{className:`flex-1 overflow-auto`,children:[u&&(0,Z.jsx)(`div`,{className:`mx-4 mt-4 px-3 py-2 text-xs rounded border border-red-500/30 aurora-light:border-destructive/30 bg-red-500/10 aurora-light:bg-destructive/10 text-red-400 aurora-light:text-destructive`,children:u}),o?(0,Z.jsx)(_e,{profile:o,onChange:s,onValidityChange:h,onSoftWarningsChange:e=>v(e.agentsMissingRouting),footer:(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsxs)(C,{size:`sm`,onClick:()=>void F(o,g),disabled:f||m.length>0,title:m.length>0?e(`profiles.editorFooter.fixValidationIssues`):void 0,children:[(0,Z.jsx)(V,{className:`w-3.5 h-3.5 mr-1.5`}),e(`common:actions.save`)]}),f&&(0,Z.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e(`common:states.saving`)}),m.length>0&&(0,Z.jsx)(`span`,{className:`text-xs text-yellow-500 aurora-light:text-accent-warning`,children:e(`profiles.editorFooter.issuesToResolve`,{count:m.length})})]})},o.name):(0,Z.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`profiles.selectPrompt`)})})]})]})]})}function $(e){let t=e.workflow.map((e,t)=>`${t+1}. ${e}`).join(`
|
|
1
|
+
import{a as e}from"./chunk-BNv3lrIs.js";import{$t as t,An as n,Bn as r,Cn as i,Ct as a,Dn as o,Dt as s,En as c,Fn as l,G as u,H as d,Ht as f,In as p,J as m,K as h,Kn as g,Ln as _,Mn as v,Mt as y,Nn as b,On as x,Pn as S,Q as C,Qt as w,Rn as T,Rt as E,Sn as D,T as O,Tn as k,U as A,V as j,W as M,Wt as ee,X as N,Xt as P,Y as F,an as I,at as L,bt as R,cn as z,en as B,f as te,ht as V,it as H,jn as ne,jt as U,kn as re,mt as ie,on as W,pn as ae,q as oe,rn as se,st as ce,tt as G,un as le,ut as K,vt as q,wn as J,wt as ue}from"./index-D4R3rVF5.js";var Y=z(`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`}]]),de=z(`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=z(`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`}]]),X=e(g(),1),Z=i(),pe=/^[a-z0-9][a-z0-9-]*$/;function me({open:e,mode:t=`add`,initial:n,chainAgents:i,onConfirm:a,onCancel:o}){let{t:s}=T(`agents`),[c,l]=(0,X.useState)(``),[f,p]=(0,X.useState)(i[0]??``);(0,X.useEffect)(()=>{e&&(t===`edit`&&n?(l(n.tags.join(`, `)),p(i.includes(n.agent)?n.agent:i[0]??``)):(l(``),p(i[0]??``)))},[e,t,n,i]);let m=c.split(`,`).map(e=>e.trim()).filter(Boolean),g=m.filter(e=>!pe.test(e)),_=m.length>0&&g.length===0&&i.includes(f);return(0,Z.jsx)(j,{open:e,onOpenChange:e=>{e||o()},children:(0,Z.jsxs)(d,{movableResizable:!0,className:`max-w-md`,children:[(0,Z.jsxs)(u,{children:[(0,Z.jsx)(h,{children:s(t===`edit`?`routingRule.editTitle`:`routingRule.addTitle`)}),(0,Z.jsx)(A,{children:s(t===`edit`?`routingRule.editDescription`:`routingRule.addDescription`)})]}),(0,Z.jsxs)(`div`,{className:`py-2 space-y-3`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:s(`routingRule.tagsLabel`)}),(0,Z.jsx)(te,{autoFocus:!0,value:c,onChange:e=>l(e.target.value),placeholder:`frontend, ui`,"aria-label":s(`routingRule.tagsLabel`),className:`text-sm font-mono`}),(0,Z.jsx)(`p`,{className:`text-[11px] text-muted-foreground mt-1`,children:(0,Z.jsx)(r,{t:s,i18nKey:`routingRule.tagsHint`,components:{code:(0,Z.jsx)(`code`,{})}})}),g.length>0&&(0,Z.jsx)(`p`,{className:`text-[11px] text-red-400 aurora-light:text-destructive mt-1`,children:s(`routingRule.invalidTags`,{count:g.length,tags:g.join(`, `)})})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:s(`routingRule.routeToLabel`)}),(0,Z.jsx)(`select`,{value:f,onChange:e=>p(e.target.value),"aria-label":s(`routingRule.routeToLabel`),className:`w-full h-9 px-2 text-sm rounded-md border border-border bg-background`,children:i.map(e=>(0,Z.jsx)(`option`,{value:e,children:e},e))}),(0,Z.jsx)(`p`,{className:`text-[11px] text-muted-foreground mt-1`,children:s(`routingRule.routeToHint`)})]})]}),(0,Z.jsxs)(M,{children:[(0,Z.jsx)(C,{variant:`ghost`,size:`sm`,onClick:o,children:s(`common:actions.cancel`)}),(0,Z.jsx)(C,{size:`sm`,onClick:()=>a(m,f),disabled:!_,children:s(t===`edit`?`routingRule.saveChanges`:`routingRule.addRule`)})]})]})})}var Q=new Set([`sr-architect`,`sr-developer`,`sr-reviewer`,`sr-merge-resolver`]),he=[`sonnet`,`fable`,`opus`,`haiku`],ge=/^[a-z0-9][a-z0-9-]*$/;function _e({profile:e,onChange:t,footer:i,onValidityChange:a,onSoftWarningsChange:s}){let{t:u}=T(`agentstudio`),[d,f]=(0,X.useState)([]),[p,m]=(0,X.useState)(!1),[h,g]=(0,X.useState)(!1),[_,y]=(0,X.useState)(null);(0,X.useEffect)(()=>{let e=!1;return fetch(`${J()}/profiles/catalog`).then(e=>e.ok?e.json():{agents:[]}).then(t=>{e||f(t.agents)}).catch(()=>{e||f([])}),()=>{e=!0}},[]);let x=n=>{let r=JSON.parse(JSON.stringify(e));n(r),t(r)},w=new Set(e.agents.map(e=>e.id)),E=d.filter(e=>!w.has(e.id)),D=(0,X.useMemo)(()=>{let t=[];for(let n of Q)e.agents.some(e=>e.id===n)||t.push(u(`profileEditor.validation.missingBaseline`,{agent:n}));let n=e.routing.filter(e=>`default`in e&&e.default===!0);if(n.length>1&&t.push(u(`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(u(`profileEditor.validation.defaultRuleNotLast`))}for(let n of e.routing)if(e.agents.some(e=>e.id===n.agent)||t.push(u(`profileEditor.validation.unknownRoutingAgent`,{agent:n.agent})),`tags`in n){let e=n.tags.filter(e=>!ge.test(e));e.length>0&&t.push(u(`profileEditor.validation.invalidTags`,{agent:n.agent,tags:e.join(`, `)}))}return t},[e,u]),O=(0,X.useMemo)(()=>{if(e.routing.length===0)return[];let t=new Set(e.routing.map(e=>e.agent));return e.agents.filter(e=>!Q.has(e.id)&&!t.has(e.id)).map(e=>e.id)},[e]),A=(0,X.useMemo)(()=>e.routing.some(e=>`default`in e&&e.default===!0),[e.routing]);(0,X.useEffect)(()=>{a&&a(D)},[D,a]),(0,X.useEffect)(()=>{s&&s({agentsMissingRouting:O})},[O,s]);let j=e=>{x(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)}),m(!1)},M=t=>{let n=e.agents[t];Q.has(n.id)||x(e=>{e.agents.splice(t,1),e.routing=e.routing.filter(e=>e.agent!==n.id)})},ee=(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=c(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)}x(e=>{e.agents=a})},N=l(S(v,{activationConstraint:{distance:4}}),S(ne,{coordinateGetter:o})),P=e=>{let{active:t,over:n}=e;n&&ee(String(t.id),String(n.id))},F=(e,t)=>{x(n=>{n.agents[e].model=t})},I=(e,t)=>{x(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)}),g(!1)},L=()=>{x(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,B=(e,t)=>{x(n=>{let r=n.routing[e];r&&(z(r)||(r.agent=t))})},V=(e,t,n)=>{x(r=>{let i=r.routing[e];i&&(z(i)||(i.tags=t,i.agent=n))})},H=e=>{x(t=>{let n=t.routing[e];n&&(z(n)||t.routing.splice(e,1))})},U=(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)||x(e=>{let[n]=e.routing.splice(t,1);e.routing.splice(r,0,n)})};return(0,Z.jsxs)(`div`,{className:`p-6 space-y-6 max-w-3xl`,children:[(0,Z.jsx)(me,{open:h,mode:`add`,chainAgents:e.agents.map(e=>e.id),onConfirm:I,onCancel:()=>g(!1)}),(0,Z.jsx)(me,{open:_!==null,mode:`edit`,initial:_!==null&&e.routing[_]&&!(`default`in e.routing[_])?{tags:e.routing[_].tags,agent:e.routing[_].agent}:void 0,chainAgents:e.agents.map(e=>e.id),onConfirm:(e,t)=>{_!==null&&(V(_,e,t),y(null))},onCancel:()=>y(null)}),D.length>0&&(0,Z.jsxs)(`div`,{className:`px-3 py-2 text-xs rounded-md border border-yellow-500/30 aurora-light:border-accent-warning/30 bg-yellow-500/10 aurora-light:bg-accent-warning/10 text-yellow-500 aurora-light:text-accent-warning`,children:[(0,Z.jsx)(`div`,{className:`font-medium mb-1`,children:u(`profileEditor.validationSummary`,{count:D.length})}),(0,Z.jsx)(`ul`,{className:`list-disc list-inside space-y-0.5`,children:D.map((e,t)=>(0,Z.jsx)(`li`,{children:e},t))})]}),(0,Z.jsxs)(`section`,{className:`space-y-3`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:u(`profileEditor.nameLabel`)}),(0,Z.jsx)(te,{value:e.name,disabled:!0,className:`text-sm`})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:u(`profileEditor.descriptionLabel`)}),(0,Z.jsx)(te,{value:e.description??``,onChange:e=>x(t=>{t.description=e.target.value}),className:`text-sm`,placeholder:u(`profileEditor.descriptionPlaceholder`)})]})]}),(0,Z.jsxs)(`section`,{children:[(0,Z.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide mb-2`,children:u(`profileEditor.orchestrator.heading`)}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 p-3 rounded-md border border-border`,children:[(0,Z.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Z.jsx)(`div`,{className:`text-sm font-mono text-foreground truncate`,children:`/specrails:implement · /specrails:batch-implement`}),(0,Z.jsx)(`div`,{className:`text-[11px] text-muted-foreground mt-0.5`,children:u(`profileEditor.orchestrator.description`)})]}),(0,Z.jsx)(be,{value:e.orchestrator.model,onChange:e=>x(t=>{t.orchestrator.model=e})})]})]}),(0,Z.jsxs)(`section`,{children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,Z.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:u(`profileEditor.agentChain.heading`,{n:e.agents.length})}),(0,Z.jsxs)(C,{size:`sm`,variant:`ghost`,onClick:()=>m(e=>!e),disabled:E.length===0,title:E.length===0?u(`profileEditor.agentChain.addDisabledTitle`):u(`profileEditor.agentChain.addTitle`),children:[(0,Z.jsx)(R,{className:`w-3.5 h-3.5 mr-1`}),` `,u(`common:actions.add`)]})]}),p&&(0,Z.jsxs)(`div`,{className:`mb-2 p-2 rounded-md border border-border bg-muted/30`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between mb-1.5 px-1`,children:[(0,Z.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:u(`profileEditor.agentChain.pickFromCatalog`,{n:E.length})}),(0,Z.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:()=>m(!1),title:u(`common:actions.close`),children:(0,Z.jsx)(G,{className:`w-3 h-3`})})]}),E.length===0?(0,Z.jsx)(`div`,{className:`px-2 py-3 text-xs text-muted-foreground text-center`,children:u(`profileEditor.agentChain.emptyCatalog`)}):(0,Z.jsx)(`div`,{className:`space-y-0.5 max-h-64 overflow-auto`,children:E.map(e=>(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>j(e.id),className:`w-full flex items-center justify-between gap-2 px-2 py-1.5 text-left rounded hover:bg-accent transition-colors`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-mono`,children:e.id}),(0,Z.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded `+(e.kind===`custom`?`bg-purple-500/15 aurora-light:bg-accent-secondary/15 text-purple-400 aurora-light:text-accent-secondary`:`bg-muted text-muted-foreground`),children:u(`profileEditor.agentChain.kind.${e.kind}`)})]},e.id))})]}),(0,Z.jsx)(n,{sensors:N,collisionDetection:b,onDragEnd:P,children:(0,Z.jsx)(k,{items:e.agents.map(e=>e.id),strategy:re,children:(0,Z.jsx)(`div`,{className:`space-y-1.5`,children:e.agents.map((e,t)=>(0,Z.jsx)(ve,{agent:e,canRemove:!Q.has(e.id),onModel:e=>F(t,e),onRemove:()=>M(t)},e.id))})})})]}),(0,Z.jsxs)(`section`,{children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,Z.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:u(`profileEditor.routing.heading`,{n:e.routing.length})}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[!A&&(0,Z.jsxs)(C,{size:`sm`,variant:`ghost`,onClick:L,disabled:e.agents.length===0,title:e.agents.length===0?u(`profileEditor.routing.needAgentsTitle`):void 0,children:[(0,Z.jsx)(R,{className:`w-3.5 h-3.5 mr-1`}),` `,u(`profileEditor.routing.addDefault`)]}),(0,Z.jsxs)(C,{size:`sm`,variant:`ghost`,onClick:()=>g(!0),disabled:e.agents.length===0,title:e.agents.length===0?u(`profileEditor.routing.needAgentsTitle`):void 0,children:[(0,Z.jsx)(R,{className:`w-3.5 h-3.5 mr-1`}),` `,u(`profileEditor.routing.addRule`)]})]})]}),(0,Z.jsx)(`p`,{className:`text-[11px] text-muted-foreground mb-2`,children:u(`profileEditor.routing.explainer`)}),O.length>0&&(0,Z.jsxs)(`div`,{className:`mb-2 px-3 py-2 text-xs rounded-md border border-yellow-500/30 aurora-light:border-accent-warning/30 bg-yellow-500/10 aurora-light:bg-accent-warning/10 text-yellow-500 aurora-light:text-accent-warning`,children:[(0,Z.jsx)(`div`,{className:`font-medium mb-1`,children:u(`profileEditor.routing.untargetedTitle`)}),(0,Z.jsx)(`div`,{children:(0,Z.jsx)(r,{t:u,i18nKey:`profileEditor.routing.untargetedDetail`,values:{agents:O.join(`, `)},components:{mono:(0,Z.jsx)(`span`,{className:`font-mono`})}})})]}),(0,Z.jsx)(`div`,{className:`space-y-1.5`,children:e.routing.map((t,n)=>{let r=`default`in t&&t.default===!0;return(0,Z.jsx)(ye,{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=>B(n,e),onEdit:()=>y(n),onUp:()=>U(n,-1),onDown:()=>U(n,1),onRemove:()=>H(n)},n)})})]}),i&&(0,Z.jsx)(`div`,{className:`pt-3 border-t border-border`,children:i})]})}function ve({agent:e,canRemove:t,onModel:n,onRemove:r}){let{t:i}=T(`agentstudio`),a=Q.has(e.id),o=e.id===`sr-architect`,s=e.id===`sr-merge-resolver`,{attributes:c,listeners:l,setNodeRef:u,transform:d,transition:f,isDragging:m}=x({id:e.id});return(0,Z.jsxs)(`div`,{ref:u,style:{transform:p.Transform.toString(d),transition:f,opacity:m?.5:void 0,zIndex:m?10:void 0},className:`flex items-center gap-2 px-2 py-1.5 rounded-md border border-border group hover:bg-accent/30 transition-colors bg-background`,children:[(0,Z.jsx)(`button`,{type:`button`,className:`flex-shrink-0 p-0.5 rounded text-muted-foreground cursor-grab active:cursor-grabbing hover:text-foreground`,title:i(`profileEditor.agentRow.dragTitle`),"aria-label":i(`profileEditor.agentRow.dragHandleAria`),...c,...l,children:(0,Z.jsx)(y,{className:`w-3.5 h-3.5`})}),(0,Z.jsx)(`span`,{className:`text-sm font-mono flex-1 truncate`,children:e.id}),o&&(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded bg-accent-primary/15 text-accent-primary`,title:i(`profileEditor.agentRow.pinnedFirstTitle`),children:[(0,Z.jsx)(de,{className:`w-2.5 h-2.5 rotate-[135deg]`}),` `,i(`profileEditor.agentRow.pinnedFirst`)]}),s&&(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded bg-accent-primary/15 text-accent-primary`,title:i(`profileEditor.agentRow.pinnedLastTitle`),children:[(0,Z.jsx)(de,{className:`w-2.5 h-2.5 rotate-45`}),` `,i(`profileEditor.agentRow.pinnedLast`)]}),a&&!o&&!s&&(0,Z.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:i(`profileEditor.agentRow.required`)}),(0,Z.jsx)(be,{value:e.model??`sonnet`,onChange:n}),(0,Z.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-red-500/20 aurora-light:hover:bg-destructive/15 text-red-400 aurora-light:text-destructive rounded disabled:opacity-30 disabled:cursor-not-allowed opacity-0 group-hover:opacity-100 transition-opacity`,onClick:r,disabled:!t,title:i(t?`common:actions.remove`:`profileEditor.agentRow.requiredRemoveTitle`),children:(0,Z.jsx)(G,{className:`w-3 h-3`})})]})}function ye({rule:e,ordinal:t,isLast:n,canMove:r,canRemove:i,canEdit:o,chainAgents:s,onAgentChange:c,onEdit:l,onUp:u,onDown:d,onRemove:f}){let{t:p}=T(`agentstudio`),m=`default`in e&&e.default===!0;return(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 rounded-md border border-border group hover:bg-accent/30 transition-colors`,children:[(0,Z.jsxs)(`span`,{className:`text-[10px] font-mono text-muted-foreground w-5 text-center flex-shrink-0`,children:[t,`.`]}),m?(0,Z.jsx)(`span`,{className:`text-xs text-muted-foreground flex-1`,children:p(`profileEditor.routingRow.everythingElse`)}):(0,Z.jsx)(`span`,{className:`text-xs flex-1 flex gap-1 flex-wrap items-center`,children:e.tags.map(e=>(0,Z.jsx)(`span`,{className:`px-1.5 py-0.5 rounded bg-muted font-mono text-[11px]`,children:e},e))}),(0,Z.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`→`}),m?(0,Z.jsx)(`span`,{className:`h-7 max-w-[15rem] px-2 text-xs font-mono rounded border border-border bg-muted/40 text-muted-foreground inline-flex items-center`,"aria-label":p(`profileEditor.routingRow.defaultTargetAria`),title:p(`profileEditor.routingRow.defaultTargetTitle`),children:e.agent}):(0,Z.jsx)(`select`,{value:e.agent,onChange:e=>c(e.target.value),"aria-label":p(`profileEditor.routingRow.targetAria`,{ordinal:t}),className:`h-7 max-w-[15rem] px-2 text-xs font-mono rounded border border-border bg-background`,children:s.map(e=>(0,Z.jsx)(`option`,{value:e,children:e},e))}),(0,Z.jsxs)(`div`,{className:`flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity`,children:[o&&(0,Z.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:l,title:p(`profileEditor.routingRow.editTitle`),"aria-label":p(`profileEditor.routingRow.editAria`,{ordinal:t}),children:(0,Z.jsx)(a,{className:`w-3 h-3`})}),r&&!n&&(0,Z.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:d,title:p(`profileEditor.routingRow.moveDown`),children:(0,Z.jsx)(W,{className:`w-3 h-3`})}),r&&t>1&&(0,Z.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:u,title:p(`profileEditor.routingRow.moveUp`),children:(0,Z.jsx)(se,{className:`w-3 h-3`})}),i&&(0,Z.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-red-500/20 aurora-light:hover:bg-destructive/15 text-red-400 aurora-light:text-destructive rounded`,onClick:f,title:p(`common:actions.remove`),children:(0,Z.jsx)(G,{className:`w-3 h-3`})})]}),m&&(0,Z.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,title:p(`profileEditor.routingRow.coreDefaultTitle`),children:p(`profileEditor.routingRow.coreDefaultBadge`)})]})}function be({value:e,onChange:t}){return(0,Z.jsx)(`select`,{value:e,onChange:e=>t(e.target.value),className:`h-7 px-2 text-xs rounded border border-border bg-background`,children:he.map(e=>(0,Z.jsx)(`option`,{value:e,children:e},e))})}function xe({open:e,title:t,description:n,placeholder:r,initialValue:i=``,confirmLabel:a,inputPattern:o,inputInvalidHint:s,onConfirm:c,onCancel:l}){let{t:f}=T(),[p,m]=(0,X.useState)(i);(0,X.useEffect)(()=>{e&&m(i)},[e,i]);let g=p.trim(),_=!o||o.test(g),v=g.length>0&&_;return(0,Z.jsx)(j,{open:e,onOpenChange:e=>{e||l()},children:(0,Z.jsxs)(d,{movableResizable:!0,className:`max-w-md`,children:[(0,Z.jsx)(u,{children:(0,Z.jsx)(h,{children:t})}),(0,Z.jsxs)(`div`,{className:`py-2 space-y-2`,children:[n&&(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n}),(0,Z.jsx)(te,{autoFocus:!0,value:p,placeholder:r,onChange:e=>m(e.target.value),onKeyDown:e=>{e.key===`Enter`&&v&&c(g)},className:`text-sm font-mono`}),g.length>0&&!_&&s&&(0,Z.jsx)(`p`,{className:`text-[11px] text-yellow-500 aurora-light:text-accent-warning`,children:s})]}),(0,Z.jsxs)(M,{children:[(0,Z.jsx)(C,{variant:`ghost`,size:`sm`,onClick:l,children:f(`actions.cancel`)}),(0,Z.jsx)(C,{size:`sm`,onClick:()=>c(g),disabled:!v,children:a??f(`actions.confirm`)})]})]})})}function Se({open:e,title:t,description:n,confirmLabel:r,destructive:i=!1,onConfirm:a,onCancel:o}){let{t:s}=T();return(0,Z.jsx)(j,{open:e,onOpenChange:e=>{e||o()},children:(0,Z.jsxs)(d,{movableResizable:!0,className:`max-w-md`,children:[(0,Z.jsx)(u,{children:(0,Z.jsx)(h,{children:t})}),n&&(0,Z.jsx)(`div`,{className:`py-2`,children:(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n})}),(0,Z.jsxs)(M,{children:[(0,Z.jsx)(C,{variant:`ghost`,size:`sm`,onClick:o,children:s(`actions.cancel`)}),(0,Z.jsx)(C,{size:`sm`,onClick:a,className:i?`bg-red-500 hover:bg-red-600 text-white`:void 0,children:r??s(`actions.confirm`)})]})]})})}function Ce(){let{t:e}=T(`agents`),[t,n]=(0,X.useState)([]),[i,a]=(0,X.useState)(null),[o,s]=(0,X.useState)(null),[c,l]=(0,X.useState)(!0),[u,d]=(0,X.useState)(null),[f,p]=(0,X.useState)(!1),[m,h]=(0,X.useState)([]),[g,v]=(0,X.useState)([]),[y,b]=(0,X.useState)(!1),[x,S]=(0,X.useState)(null),[w,E]=(0,X.useState)(null),D=(0,X.useCallback)(async()=>{l(!0),d(null);try{let t=await fetch(`${J()}/profiles`);if(!t.ok)throw Error(e(`profiles.errors.listFailed`,{status:t.status}));let r=await t.json();n(r.profiles),r.profiles.length>0&&!i&&a(r.profiles[0].name)}catch(e){d(e.message)}finally{l(!1)}},[i]);(0,X.useEffect)(()=>{D()},[D]),(0,X.useEffect)(()=>{if(!i){s(null);return}let t=!1;return fetch(`${J()}/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 O=(0,X.useCallback)(async()=>{p(!0),d(null);try{let t=await fetch(`${J()}/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 D(),a(`default`),_.success(e(`profiles.toasts.migrated`),{description:e(`profiles.toasts.migratedDescription`)})}catch(t){let n=t.message;d(n),_.error(e(`profiles.toasts.migrationFailed`),{description:n})}finally{p(!1)}},[D]),k=(0,X.useCallback)(async t=>{b(!1),p(!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(`${J()}/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 D(),a(t),_.success(e(`profiles.toasts.created`),{description:t})}catch(t){let n=t.message;d(n),_.error(e(`profiles.toasts.createFailed`),{description:n})}finally{p(!1)}},[D]),A=(0,X.useCallback)(async(t,n)=>{S(null),p(!0),d(null);try{let r=await fetch(`${J()}/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 D(),a(n),_.success(e(`profiles.toasts.duplicated`),{description:e(`profiles.toasts.duplicatedDescription`,{from:t,to:n})})}catch(t){let n=t.message;d(n),_.error(e(`profiles.toasts.duplicateFailed`),{description:n})}finally{p(!1)}},[D]),j=(0,X.useCallback)(async t=>{E(null),p(!0),d(null);try{let n=await fetch(`${J()}/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 D(),_.success(e(`profiles.toasts.deleted`),{description:t})}catch(t){let n=t.message;d(n),_.error(e(`profiles.toasts.deleteFailed`),{description:n})}finally{p(!1)}},[D]),M=(0,X.useCallback)(()=>b(!0),[]),N=(0,X.useCallback)(e=>S({from:e}),[]),P=(0,X.useCallback)(e=>E({name:e}),[]),F=(0,X.useCallback)(async(t,n)=>{p(!0),d(null);try{let r=await fetch(`${J()}/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?_.warning(e(`profiles.toasts.savedWithUntargeted`),{description:e(`profiles.toasts.savedWithUntargetedDescription`,{agents:n.join(`, `)}),duration:6e3}):_.success(e(`profiles.toasts.saved`),{description:t.name})}catch(t){let n=t.message;d(n),_.error(e(`profiles.toasts.saveFailed`),{description:n})}finally{p(!1)}},[e]),I=(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(xe,{open:y,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 k(e),onCancel:()=>b(!1)}),x&&(0,Z.jsx)(xe,{open:!0,title:e(`profiles.duplicateDialog.title`,{name:x.from}),description:e(`profiles.duplicateDialog.description`),placeholder:`${x.from}-copy`,initialValue:`${x.from}-copy`,confirmLabel:e(`common:actions.duplicate`),inputPattern:/^[a-z0-9][a-z0-9-]*$/,inputInvalidHint:e(`profiles.duplicateDialog.invalidHint`),onConfirm:e=>void A(x.from,e),onCancel:()=>S(null)}),w&&(0,Z.jsx)(Se,{open:!0,title:e(`profiles.deleteDialog.title`,{name:w.name}),description:e(`profiles.deleteDialog.description`),confirmLabel:e(`common:actions.delete`),destructive:!0,onConfirm:()=>void j(w.name),onCancel:()=>E(null)})]});return c?(0,Z.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`profiles.loading`)})}):t.length===0?(0,Z.jsxs)(Z.Fragment,{children:[I,(0,Z.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,Z.jsxs)(`div`,{className:`text-center max-w-md`,children:[(0,Z.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:e(`profiles.empty.title`)}),(0,Z.jsx)(`div`,{className:`text-xs text-muted-foreground mt-1 mb-4`,children:e(`profiles.empty.body`)}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 justify-center`,children:[(0,Z.jsxs)(C,{size:`sm`,onClick:O,disabled:f,children:[(0,Z.jsx)(fe,{className:`w-3.5 h-3.5 mr-1.5`}),` `,e(`profiles.empty.migrateButton`)]}),(0,Z.jsxs)(C,{size:`sm`,variant:`ghost`,onClick:M,disabled:f,children:[(0,Z.jsx)(R,{className:`w-3.5 h-3.5 mr-1.5`}),` `,e(`profiles.empty.blankButton`)]})]}),(0,Z.jsx)(`div`,{className:`text-[11px] text-muted-foreground/70 mt-3`,children:(0,Z.jsx)(r,{t:e,i18nKey:`profiles.empty.migrateExplainer`,components:{code:(0,Z.jsx)(`code`,{className:`text-foreground`})}})}),u&&(0,Z.jsx)(`div`,{className:`mt-3 text-xs text-red-400 aurora-light:text-destructive`,children:u})]})})]}):(0,Z.jsxs)(`div`,{className:`flex flex-col h-full`,children:[I,(0,Z.jsxs)(`div`,{className:`flex flex-1 min-h-0`,children:[(0,Z.jsxs)(`aside`,{className:`w-64 flex-shrink-0 border-r border-border flex flex-col`,children:[(0,Z.jsxs)(`div`,{className:`p-3 flex items-center justify-between`,children:[(0,Z.jsx)(`div`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:e(`profiles.sidebar.title`)}),(0,Z.jsx)(C,{size:`sm`,variant:`ghost`,onClick:M,disabled:f,children:(0,Z.jsx)(R,{className:`w-3.5 h-3.5`})})]}),(0,Z.jsx)(`div`,{className:`flex-1 overflow-auto px-2 pb-3`,children:t.map(t=>(0,Z.jsxs)(`div`,{className:`group mb-1 rounded-md px-2 py-1.5 text-xs cursor-pointer transition-colors flex items-center justify-between `+(t.name===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,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,Z.jsx)(`span`,{className:`truncate font-medium`,children:t.name}),t.isDefault&&(0,Z.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:e(`profiles.sidebar.teamDefault`)})]}),(0,Z.jsxs)(`div`,{className:`flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity`,children:[(0,Z.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,title:e(`common:actions.duplicate`),onClick:e=>{e.stopPropagation(),N(t.name)},children:(0,Z.jsx)(ee,{className:`w-3 h-3`})}),!t.isDefault&&(0,Z.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-red-500/20 text-red-400 aurora-light:text-destructive rounded`,title:e(`common:actions.delete`),onClick:e=>{e.stopPropagation(),P(t.name)},children:(0,Z.jsx)(L,{className:`w-3 h-3`})})]})]},t.name))})]}),(0,Z.jsxs)(`main`,{className:`flex-1 overflow-auto`,children:[u&&(0,Z.jsx)(`div`,{className:`mx-4 mt-4 px-3 py-2 text-xs rounded border border-red-500/30 aurora-light:border-destructive/30 bg-red-500/10 aurora-light:bg-destructive/10 text-red-400 aurora-light:text-destructive`,children:u}),o?(0,Z.jsx)(_e,{profile:o,onChange:s,onValidityChange:h,onSoftWarningsChange:e=>v(e.agentsMissingRouting),footer:(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsxs)(C,{size:`sm`,onClick:()=>void F(o,g),disabled:f||m.length>0,title:m.length>0?e(`profiles.editorFooter.fixValidationIssues`):void 0,children:[(0,Z.jsx)(V,{className:`w-3.5 h-3.5 mr-1.5`}),e(`common:actions.save`)]}),f&&(0,Z.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e(`common:states.saving`)}),m.length>0&&(0,Z.jsx)(`span`,{className:`text-xs text-yellow-500 aurora-light:text-accent-warning`,children:e(`profiles.editorFooter.issuesToResolve`,{count:m.length})})]})},o.name):(0,Z.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`profiles.selectPrompt`)})})]})]})]})}function $(e){let t=e.workflow.map((e,t)=>`${t+1}. ${e}`).join(`
|
|
2
2
|
`);return`---
|
|
3
3
|
name: ${e.id}
|
|
4
4
|
description: "${e.descriptionOneLine}"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as e}from"./chunk-BNv3lrIs.js";import{t}from"./clsx-1dnHRn8W.js";import{Bn as n,Cn as r,Kn as i,N as a,Rn as o,Sn as s,Wn as c,cn as l,in as u,ln as d,m as f,p,un as m,vt as h,wn as g}from"./index-D4R3rVF5.js";import{t as _}from"./ExportDropdown-Clt8DyCs.js";import{A as v,B as y,C as b,D as x,E as S,F as ee,G as te,H as C,I as w,J as T,K as E,L as D,M as O,N as k,O as A,P as j,Q as M,R as N,S as P,T as F,V as ne,X as I,Z as L,_ as R,_t as z,a as B,at as re,b as V,c as H,ct as ie,et as ae,f as oe,g as se,gt as U,h as ce,i as W,j as le,k as ue,l as de,lt as G,m as fe,n as pe,nt as me,o as he,ot as ge,p as _e,pt as K,q as ve,r as ye,rt as be,s as xe,st as Se,t as Ce,tt as we,ut as q,v as Te,x as Ee,y as De,z as Oe}from"./BarChart-9_p1-qtv.js";var ke=l(`arrow-down-right`,[[`path`,{d:`m7 7 10 10`,key:`1fmybs`}],[`path`,{d:`M17 7v10H7`,key:`6fjiku`}]]),J=e(i(),1),Y=r();function X(e){return e>=100?`$${e.toFixed(0)}`:e>=10?`$${e.toFixed(1)}`:`$${e.toFixed(2)}`}function Ae(e){return e>=1e3?`$${(e/1e3).toFixed(1)}k`:`$${e.toFixed(2)}`}function je(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:`${e}`}var Me=[`job`,`explore-spec`,`quick-spec`,`ai-edit`,`chat-sidebar`,`spec-launcher`,`proposal`,`agent-studio`,`setup`,`smash`,`file-summary`,`loop`];function Ne({data:e,loading:t,period:n}){let{t:r}=o(`analytics`),[i,a]=(0,J.useState)(0),s=(0,J.useRef)(0),c=(0,J.useRef)(null),l=(0,J.useRef)(0);if((0,J.useEffect)(()=>{if(!e)return;let t=e.summary.totalCostUsd,n=++l.current;if(c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),s.current===0&&t>0){let e=performance.now(),r=i=>{if(n!==l.current)return;let o=Math.min(1,(i-e)/600),s=1-(1-o)**3;a(0+(t-0)*s),o<1?c.current=requestAnimationFrame(r):c.current=null};c.current=requestAnimationFrame(r)}else a(t);return s.current=t,()=>{c.current!==null&&(cancelAnimationFrame(c.current),c.current=null)}},[e]),t&&!e)return(0,Y.jsx)(`div`,{className:`h-44 rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let d=e.summary.totalCostUsd,m=e.summary.totalRuns,h=e.summary.totalTokens??0,g=e.summary.totalEstimatedCostUsd??0,_=e.summary.deltaPct,v=e.trackingStartedAt,y=g>0,b=e.bySurface.map(e=>e.surface).filter(e=>!Me.includes(e)),x=[...Me,...b].map(t=>{let n=e.bySurface.find(e=>e.surface===t);return{surface:t,costUsd:n?.costUsd??0,count:n?.count??0}}),S=n?r(`windowLabels.${n}`):null;return(0,Y.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-gradient-to-br from-card/80 to-card/40 p-5`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-end justify-between gap-3 mb-4`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`div`,{className:`text-[11px] uppercase tracking-wider text-muted-foreground mb-1 flex items-center gap-1.5`,children:[(0,Y.jsx)(`span`,{children:r(`hero.spending`)}),S&&(0,Y.jsxs)(`span`,{"data-testid":`hero-window-label`,className:`normal-case tracking-normal text-muted-foreground/70 font-normal`,children:[`· `,S]})]}),(0,Y.jsxs)(`div`,{className:`flex items-baseline gap-3`,children:[(0,Y.jsx)(`div`,{className:`text-5xl font-semibold tabular-nums tracking-tight`,children:Ae(i)}),_!==null&&(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 text-xs font-medium ${_>=0?`text-accent-warning`:`text-accent-success`}`,children:[_>=0?(0,Y.jsx)(u,{className:`w-3 h-3`}):(0,Y.jsx)(ke,{className:`w-3 h-3`}),r(`hero.vsPrev`,{pct:Math.abs(_).toFixed(0)})]})]}),(0,Y.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-1 tabular-nums flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{children:r(`hero.invocations`,{count:m})}),h>0&&(0,Y.jsx)(`span`,{className:`text-muted-foreground/80`,title:r(`hero.tokensTooltip`),children:r(`hero.tokens`,{tokens:je(h)})}),y&&(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground/70 italic`,title:r(`hero.includesEstimatedTooltip`,{amount:X(g)}),children:r(`hero.includesEstimated`,{amount:X(g)})})]})]}),m===0&&v&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:r(`hero.trackingStarted`,{date:v.slice(0,10)})})]}),m===0?(0,Y.jsxs)(`div`,{className:`rounded-lg border border-dashed border-border/40 p-6 text-center`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:r(`hero.emptyState`)}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground/70 mt-1`,children:v?r(`hero.trackingStarted`,{date:v.slice(0,10)}):r(`hero.trackingStartedFallback`)})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`div`,{className:`h-3 w-full rounded-full overflow-hidden bg-background-deep flex`,children:x.map(e=>{let t=d>0?e.costUsd/d*100:0;return t===0?null:(0,Y.jsx)(`div`,{className:`h-full ${p[e.surface].dot}`,style:{width:`${t}%`},title:r(`hero.segmentTitle`,{label:f[e.surface],value:X(e.costUsd)})},e.surface)})}),(0,Y.jsx)(`div`,{className:`mt-3 flex flex-wrap items-center gap-x-5 gap-y-1.5 text-xs`,children:x.filter(e=>e.costUsd>0).map(e=>(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 tabular-nums`,children:[(0,Y.jsx)(`span`,{className:`w-2 h-2 rounded-full ${p[e.surface].dot}`}),(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:f[e.surface]}),(0,Y.jsx)(`span`,{className:`text-foreground font-medium`,children:X(e.costUsd)}),(0,Y.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,Y.jsx)(`span`,{className:`text-muted-foreground/80`,children:e.count})]},e.surface))})]})]})}var Pe={claude:`Claude`,codex:`Codex`,gemini:`Gemini`},Fe={claude:`bg-accent-info`,codex:`bg-accent-highlight`,gemini:`bg-accent-success`};function Ie(e){return e>=100?`$${e.toFixed(0)}`:e>=10?`$${e.toFixed(1)}`:e>=.01?`$${e.toFixed(2)}`:`$${e.toFixed(4)}`}function Le(e){return Pe[e]??e}function Re(e){return Fe[e]??`bg-accent-secondary`}function ze({data:e,loading:t}){let{t:r}=o(`analytics`);if(t&&!e)return(0,Y.jsx)(`div`,{className:`h-32 rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e||e.byProvider.length===0||e.byProvider.length===1)return null;let i=e.byProvider.reduce((e,t)=>e+t.costUsd+t.estimatedCostUsd,0);return(0,Y.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,Y.jsx)(`div`,{className:`flex items-baseline justify-between mb-3`,children:(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-[11px] uppercase tracking-wider text-muted-foreground`,children:r(`providerCard.title`)}),(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground/70 mt-0.5`,children:(0,Y.jsx)(n,{ns:`analytics`,i18nKey:`providerCard.description`,components:{tilde:(0,Y.jsx)(`span`,{className:`font-medium`})}})})]})}),i===0?(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:r(`providerCard.noCost`)}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`div`,{className:`h-2 w-full rounded-full overflow-hidden bg-background-deep flex mb-3`,children:e.byProvider.map(e=>{let t=e.costUsd+e.estimatedCostUsd,n=i>0?t/i*100:0;if(n===0)return null;let a=`${e.costUsd===0&&e.estimatedCostUsd>0?`~`:``}${Ie(t)}`;return(0,Y.jsx)(`div`,{className:`h-full ${Re(e.provider)}`,style:{width:`${n}%`},title:r(`providerCard.segmentTitle`,{label:Le(e.provider),value:a,count:e.count})},e.provider)})}),(0,Y.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2`,children:e.byProvider.map(e=>(0,Y.jsx)(Be,{entry:e},e.provider))})]})]})}function Be({entry:e}){let{t}=o(`analytics`),n=e.costUsd+e.estimatedCostUsd,r=e.costUsd===0&&e.estimatedCostUsd>0,i=e.count>0&&e.costUsd===0&&e.estimatedCostUsd===0;return(0,Y.jsxs)(`div`,{className:`flex items-center gap-2.5 rounded-md border border-border/30 px-2.5 py-1.5`,children:[(0,Y.jsx)(`span`,{className:`w-2 h-2 rounded-full shrink-0 ${Re(e.provider)}`}),(0,Y.jsx)(`span`,{className:`text-xs font-medium`,children:Le(e.provider)}),(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:t(`runs`,{count:e.count})}),i?(0,Y.jsx)(`span`,{className:`ml-auto text-xs font-medium text-muted-foreground/80 italic`,title:t(`providerCard.costUnavailableTooltip`),children:t(`providerCard.costUnavailable`)}):(0,Y.jsxs)(`span`,{className:`ml-auto text-xs font-medium tabular-nums`,children:[r?`~`:``,Ie(n)]})]})}var Ve=[`option`,`isActive`];function Z(){return Z=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},Z.apply(null,arguments)}function He(e,t){if(e==null)return{};var n,r,i=Ue(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 Ue(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 We(e){var{option:t,isActive:n}=e,r=He(e,Ve);return typeof t==`string`?J.createElement(P,Z({option:J.createElement(Se,Z({type:t},r)),isActive:n,shapeType:`symbols`},r)):J.createElement(P,Z({option:t,isActive:n,shapeType:`symbols`},r))}var Ge=ae([(e,t,n,r,i,a,o)=>N(e,void 0,void 0,o),(e,t,n,r,i,a,o)=>k(e,`xAxis`,t,o),(e,t,n,r,i,a,o)=>j(e,`xAxis`,t,o),(e,t,n,r,i,a,o)=>k(e,`yAxis`,n,o),(e,t,n,r,i,a,o)=>j(e,`yAxis`,n,o),(e,t,n,r)=>w(e,`zAxis`,r,!1),ae([ee,(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})}}),Ke=[`id`],qe=[`onMouseEnter`,`onClick`,`onMouseLeave`],Je=[`animationBegin`,`animationDuration`,`animationEasing`,`hide`,`isAnimationActive`,`legendType`,`lineJointType`,`lineType`,`shape`,`xAxisId`,`yAxisId`,`zAxisId`];function Ye(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:L(n,t),payload:e}]},nt=J.memo(e=>{var{dataKey:t,points:n,stroke:r,strokeWidth:i,fill:a,name:o,hide:s,tooltipType:c,id:l}=e,u={dataDefinedOnItem:n?.map(e=>e.tooltipPayload),getPosition:e=>{var t;return n==null||(t=n[Number(e)])==null?void 0:t.tooltipPosition},settings:{stroke:r,strokeWidth:i,fill:a,nameKey:void 0,dataKey:t,name:L(o,t),hide:s,type:c,color:a,unit:``,graphicalItemId:l}};return J.createElement(Te,{tooltipEntrySettings:u})});function rt(e){var{points:t,props:n}=e,{line:r,lineType:i,lineJointType:a}=n;if(!r)return null;var o=U(n),s=z(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=J.isValidElement(r)?J.cloneElement(r,h):typeof r==`function`?r(h):J.createElement(ne,Q({},h,{type:a})),J.createElement(K,{className:`recharts-scatter-line`,key:`recharts-scatter-line`},l)}function it(e){var{showLabels:t,points:n,children:r}=e,i=te(),a=(0,J.useMemo)(()=>n?.map(e=>{var t={x:e.x??0,y:e.y??0,width:e.width,height:e.height,lowerWidth:e.width,upperWidth:e.width};return $($({},t),{},{value:void 0,payload:e.payload,viewBox:t,parentViewBox:i,fill:void 0})}),[i,n]);return J.createElement(F,{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=Ye(n,Ke),c=me(le),{onMouseEnter:l,onClick:u,onMouseLeave:d}=n,f=Ye(n,qe),p=V(l,a,o),m=Ee(d),h=De(u,a,o);if(!ge(t))return null;var g=U(s);return J.createElement(J.Fragment,null,J.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,[T]:String(o)});return J.createElement(v,{key:`symbol-${e?.cx}-${e?.cy}-${e?.size}-${t}`,zIndex:a?D.activeDot:void 0},J.createElement(K,Q({className:`recharts-scatter-symbol`},re(f,e,t),{onMouseEnter:p(e,t),onMouseLeave:m(e,t),onClick:h(e,t)}),J.createElement(We,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=Oe(n,`recharts-scatter-`),[u,d]=(0,J.useState)(!1),f=(0,J.useCallback)(()=>{d(!1)},[]),p=(0,J.useCallback)(()=>{d(!0)},[]),m=!u;return J.createElement(it,{showLabels:m,points:r},n.children,J.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:G(r.cx,t.cx,e),cy:t.cy==null?void 0:G(r.cy,t.cy,e),size:G(r.size,t.size,e)}):$($({},t),{},{size:G(0,t.size,e)})});return e>0&&(t.current=i),J.createElement(K,null,J.createElement(at,{points:i,allOtherScatterProps:n,showLabels:m}))}),J.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=q(n.dataKey)?a.dataKey:n.dataKey,u=q(r.dataKey)?a.dataKey:r.dataKey,d=i&&i.dataKey,f=i?i.range:O.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=M(e,l),g=M(e,u),_=!q(d)&&M(e,d)||`-`,v=[{name:q(n.dataKey)?a.name:n.name||String(n.dataKey),unit:n.unit||``,value:f,payload:e,dataKey:l,type:a.tooltipType,graphicalItemId:a.id},{name:q(r.dataKey)?a.name:r.name||String(r.dataKey),unit:r.unit||``,value:g,payload:e,dataKey:u,type:a.tooltipType,graphicalItemId:a.id}];_!==`-`&&i!=null&&v.push({name:i.name||i.dataKey,unit:i.unit||``,value:_,payload:e,dataKey:d,type:a.tooltipType,graphicalItemId:a.id});var y=I({axis:n,ticks:o,bandSize:m,entry:e,index:t,dataKey:l}),b=I({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:M(e,t)});function lt(e){var{hide:n,points:r,className:i,needClip:a,xAxisId:o,yAxisId:s,id:c}=e,l=(0,J.useRef)(null);if(n)return null;var u=t(`recharts-scatter`,i),d=c;return J.createElement(v,{zIndex:e.zIndex},J.createElement(K,{className:u,clipPath:a?`url(#clipPath-${d})`:void 0,id:c},a&&J.createElement(`defs`,null,J.createElement(he,{clipPathId:d,xAxisId:o,yAxisId:s})),J.createElement(H,{xAxisId:o,yAxisId:s,data:r,dataPointFormatter:ct,errorBarOffset:0},J.createElement(K,{key:`recharts-scatter-symbols`},J.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:D.scatter};function dt(e){var t=be(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=Ye(t,Je),{needClip:h}=xe(d,f),g=(0,J.useMemo)(()=>b(e.children,x),[e.children]),_=ve(),v=me(t=>Ge(t,d,f,p,e.id,g,_));return h==null||v==null?null:J.createElement(J.Fragment,null,J.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}),J.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=be(e,ut),n=ve();return J.createElement(se,{id:t.id,type:`scatter`},e=>J.createElement(J.Fragment,null,J.createElement(R,{legendPayload:tt(t)}),J.createElement(ce,{type:`scatter`,id:e,data:t.data,xAxisId:t.xAxisId,yAxisId:t.yAxisId,zAxisId:t.zAxisId,dataKey:t.dataKey,hide:t.hide,name:t.name,tooltipType:t.tooltipType,isPanorama:n}),J.createElement(dt,Q({},t,{id:e}))))}var pt=J.memo(ft,C);pt.displayName=`Scatter`;function mt(e){var t=we(),n=(0,J.useRef)(null);return(0,J.useLayoutEffect)(()=>{n.current===null?t(oe(e)):n.current!==e&&t(fe({prev:n.current,next:e})),n.current=e},[e,t]),(0,J.useLayoutEffect)(()=>()=>{n.current&&=(t(_e(n.current)),null)},[t]),null}var ht={zAxisId:0,range:O.range,scale:O.scale,type:O.type};function gt(e){var t=be(e,ht);return J.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:O.allowDuplicatedCategory,allowDataOverflow:O.allowDataOverflow,reversed:O.reversed,includeHidden:O.includeHidden})}gt.displayName=`ZAxis`;var _t=[`item`],vt=(0,J.forwardRef)((e,t)=>J.createElement(pe,{chartName:`ScatterChart`,defaultTooltipEventType:`item`,validateTooltipEventTypes:_t,tooltipPayloadSearcher:ue,categoricalChartProps:e,ref:t}));function yt({data:e,loading:t}){let{t:n}=o(`analytics`);if(t&&!e)return(0,Y.jsx)(`div`,{className:`h-[220px] rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let r={jobs:n(`surfaces.job`),explore:n(`surfaces.exploreSpec`),quick:n(`surfaces.quickSpec`),refine:n(`surfaces.aiEdit`),fileSummaries:n(`surfaces.fileSummary`),smash:n(`surfaces.smash`),loop:n(`surfaces.loop`)},i=e.dailyTimeline.map(e=>({date:e.date.slice(5),[r.jobs]:e.jobsCostUsd,[r.explore]:e.exploreCostUsd,[r.quick]:e.quickCostUsd,[r.refine]:e.aiEditCostUsd,[r.fileSummaries]:e.fileSummaryCostUsd??0,[r.smash]:e.smashCostUsd??0,[r.loop]:e.loopCostUsd??0})),a=e.dailyTimeline.every(e=>e.jobsCostUsd+e.exploreCostUsd+e.quickCostUsd+e.aiEditCostUsd+(e.fileSummaryCostUsd??0)+(e.smashCostUsd??0)+(e.loopCostUsd??0)===0);return(0,Y.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,Y.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider`,children:n(`timeline.title`)}),(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground/70`,children:n(`timeline.subtitle`)})]}),a?(0,Y.jsx)(`div`,{className:`h-40 flex items-center justify-center text-xs text-muted-foreground/70`,children:n(`timeline.empty`)}):(0,Y.jsx)(`div`,{className:`h-[220px]`,children:(0,Y.jsx)(E,{width:`100%`,height:`100%`,children:(0,Y.jsxs)(Ce,{data:i,margin:{top:10,right:10,left:-8,bottom:0},children:[(0,Y.jsx)(de,{strokeDasharray:`2 4`,stroke:`currentColor`,className:`text-border/30`,vertical:!1}),(0,Y.jsx)(W,{dataKey:`date`,tick:{fontSize:10},stroke:`currentColor`,className:`text-muted-foreground`}),(0,Y.jsx)(ye,{tick:{fontSize:10},stroke:`currentColor`,className:`text-muted-foreground`,tickFormatter:e=>`$${e}`}),(0,Y.jsx)(A,{contentStyle:{backgroundColor:`var(--popover)`,border:`1px solid var(--border)`,fontSize:11,borderRadius:6},formatter:(e,t)=>[`$${typeof e==`number`?e.toFixed(2):`—`}`,String(t)]}),(0,Y.jsx)(B,{dataKey:r.jobs,stackId:`a`,fill:`var(--accent-info, #5fa8d3)`}),(0,Y.jsx)(B,{dataKey:r.explore,stackId:`a`,fill:`var(--accent-highlight, #c084fc)`}),(0,Y.jsx)(B,{dataKey:r.quick,stackId:`a`,fill:`var(--accent-secondary, #f7768e)`}),(0,Y.jsx)(B,{dataKey:r.refine,stackId:`a`,fill:`var(--accent-success, #50fa7b)`}),(0,Y.jsx)(B,{dataKey:r.fileSummaries,stackId:`a`,fill:`var(--accent-warning, #f1fa8c)`}),(0,Y.jsx)(B,{dataKey:r.smash,stackId:`a`,fill:`var(--accent-highlight, #c084fc)`}),(0,Y.jsx)(B,{dataKey:r.loop,stackId:`a`,fill:`var(--accent-primary, #7aa2f7)`})]})})})]})}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,Y.jsx)(`div`,{className:`flex items-end gap-[1px] h-5`,children:e.map((e,n)=>(0,Y.jsx)(`div`,{className:`w-[3px] rounded-sm bg-foreground/40`,style:{height:`${Math.max(2,e/t*20)}px`}},n))})}function Ct({mode:e,label:t,accentClass:r}){let{t:i}=o(`analytics`),a=e.mode===`explore`&&e.totalRuns<5,s=(e.estimatedCostUsd??0)>0;return(0,Y.jsxs)(`div`,{className:`flex-1 p-4 first:pr-2 last:pl-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,Y.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full ${r}`}),(0,Y.jsx)(`span`,{className:`text-xs font-medium uppercase tracking-wider text-muted-foreground`,children:t})]}),a?(0,Y.jsxs)(`div`,{className:`py-3`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-foreground`,children:i(`quickVsExplore.sparseCta`)}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:i(`quickVsExplore.runsSoFar`,{count:e.totalRuns})})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`text-3xl font-semibold tabular-nums tracking-tight`,"data-estimated":s?`true`:void 0,title:s?i(`quickVsExplore.estimatedTooltip`):void 0,children:[s&&e.avgCostPerSpec!=null?`~`:``,bt(e.avgCostPerSpec)]}),(0,Y.jsx)(`div`,{className:`text-[11px] text-muted-foreground mt-0.5`,children:i(`quickVsExplore.perSpec`)}),(0,Y.jsx)(`div`,{className:`mt-3`,children:(0,Y.jsx)(St,{values:e.sparkline.length>0?e.sparkline:[0]})}),(0,Y.jsxs)(`div`,{className:`mt-3 space-y-0.5 text-xs tabular-nums text-muted-foreground`,children:[(0,Y.jsx)(`div`,{children:(0,Y.jsx)(n,{ns:`analytics`,i18nKey:`quickVsExplore.createdRuns`,values:{created:e.ticketsCreated,runs:e.totalRuns},components:{strong:(0,Y.jsx)(`span`,{className:`text-foreground font-medium`})}})}),(0,Y.jsx)(`div`,{children:i(`quickVsExplore.avgDuration`,{duration:xt(e.avgDurationMs)})}),(0,Y.jsx)(`div`,{className:`truncate`,children:e.dominantModel??`—`})]})]})]})}function wt({data:e,loading:t}){let{t:n}=o(`analytics`);if(t&&!e)return(0,Y.jsx)(`div`,{className:`h-[220px] rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let r=e.byMode.find(e=>e.mode===`quick`),i=e.byMode.find(e=>e.mode===`explore`);if(!r||!i)return null;let a=r.avgCostPerSpec&&i.avgCostPerSpec&&r.avgCostPerSpec>0?i.avgCostPerSpec/r.avgCostPerSpec:null,s=a!==null&&r.totalRuns>=1&&i.totalRuns>=5,c=(r.estimatedCostUsd??0)>0||(i.estimatedCostUsd??0)>0;return(0,Y.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40`,children:[(0,Y.jsx)(`div`,{className:`px-4 pt-3 pb-1`,children:(0,Y.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider`,children:n(`quickVsExplore.title`)})}),(0,Y.jsxs)(`div`,{className:`flex divide-x divide-border/40`,children:[(0,Y.jsx)(Ct,{mode:r,label:n(`quickVsExplore.quick`),accentClass:`bg-accent-secondary`}),(0,Y.jsx)(Ct,{mode:i,label:n(`quickVsExplore.explore`),accentClass:`bg-accent-highlight`})]}),s&&(0,Y.jsx)(`div`,{className:`px-4 pb-3 -mt-1`,children:(0,Y.jsx)(`div`,{className:`text-center text-[11px] text-muted-foreground tabular-nums`,children:(0,Y.jsxs)(`span`,{className:`px-2`,children:[`━━━━━━ `,n(`quickVsExplore.ratio`,{ratio:a.toFixed(1)}),` ━━━━━━`]})})}),c&&(0,Y.jsx)(`div`,{className:`px-4 pb-3 -mt-1`,"data-testid":`quick-vs-explore-estimated-footnote`,children:(0,Y.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:n(`quickVsExplore.estimatedFootnote`)})})]})}function Tt({data:e,loading:t,onSelectModel:n,activeModel:r}){let{t:i}=o(`analytics`);if(t&&!e)return(0,Y.jsx)(`div`,{className:`h-[220px] rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let a=e.summary.totalCostUsd,s=e.byModel.slice(0,5),c=s.reduce((e,t)=>e+t.costUsd,0),l=Math.max(0,a-c),u=l>=.005;return(0,Y.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,Y.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider mb-3`,children:i(`models.title`)}),s.length===0?(0,Y.jsx)(`div`,{className:`h-32 flex items-center justify-center text-xs text-muted-foreground/70`,children:i(`models.empty`)}):(0,Y.jsxs)(`ul`,{className:`space-y-1.5`,children:[s.map(e=>{let t=a>0?e.costUsd/a*100:0,o=r===e.model,s=(e.estimatedCostUsd??0)>0;return(0,Y.jsx)(`li`,{children:(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>n(e.model,e.provider),className:`w-full text-left group rounded-md px-2 py-1.5 transition-colors ${o?`bg-accent-highlight/10 ring-1 ring-accent-highlight/30`:`hover:bg-accent/30`}`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between text-[12px] mb-1 tabular-nums`,children:[(0,Y.jsx)(`span`,{className:`truncate font-medium`,children:e.model}),(0,Y.jsxs)(`span`,{className:`text-muted-foreground`,title:s?i(`models.estimatedTooltip`):void 0,children:[s?`~`:``,`$`,e.costUsd.toFixed(2),` · `,e.count]})]}),(0,Y.jsx)(`div`,{className:`h-1.5 rounded-full bg-background-deep overflow-hidden`,children:(0,Y.jsx)(`div`,{className:`h-full ${o?`bg-accent-highlight`:`bg-foreground/40 group-hover:bg-foreground/60`} transition-colors`,style:{width:`${t}%`}})})]})},`${e.provider??`claude`}:${e.model}`)}),u&&(0,Y.jsx)(`li`,{"data-testid":`model-others`,children:(0,Y.jsxs)(`div`,{className:`w-full rounded-md px-2 py-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between text-[12px] mb-1 tabular-nums`,children:[(0,Y.jsx)(`span`,{className:`truncate font-medium text-muted-foreground`,children:i(`models.others`)}),(0,Y.jsxs)(`span`,{className:`text-muted-foreground`,children:[`$`,l.toFixed(2)]})]}),(0,Y.jsx)(`div`,{className:`h-1.5 rounded-full bg-background-deep overflow-hidden`,children:(0,Y.jsx)(`div`,{className:`h-full bg-foreground/25`,style:{width:`${a>0?l/a*100:0}%`}})})]})})]})]})}var 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)`,"file-summary":`var(--accent-warning, #f1fa8c)`,loop:`var(--accent-primary, #7aa2f7)`,"chat-sidebar":`var(--accent-info, #5fa8d3)`,"spec-launcher":`var(--accent-secondary, #f7768e)`,proposal:`var(--accent-highlight, #c084fc)`,"agent-studio":`var(--accent-success, #50fa7b)`,setup:`var(--accent-primary, #7aa2f7)`},Dt=Object.keys(f);function Ot({data:e,loading:t,onSelectPoint:n}){let{t:r}=o(`analytics`);if(t&&!e)return(0,Y.jsx)(`div`,{className:`h-[260px] rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let i=Dt,a=i.map(t=>({surface:t,points:e.scatter.filter(e=>e.surface===t).map(e=>({id:e.id,x:e.numTurns??Math.round((e.durationMs??0)/1e3),y:e.costUsd,surface:t,ticketId:e.ticketId,startedAt:e.startedAt,raw:e}))})),s=e.scatter.length===0,c=e.scatterTruncated===!0,l=e.scatterTotal??e.scatter.length;return(0,Y.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,Y.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider`,children:r(`scatter.title`)}),(0,Y.jsx)(`div`,{className:`flex flex-wrap items-center gap-2 text-[10px]`,children:i.map(e=>(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,Y.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full`,style:{background:Et[e]}}),(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:f[e]})]},e))})]}),c&&!s&&(0,Y.jsx)(`div`,{"data-testid":`scatter-truncation-notice`,className:`mb-2 text-[10px] text-accent-warning`,children:r(`scatter.truncated`,{shown:e.scatter.length,total:l})}),s?(0,Y.jsx)(`div`,{className:`h-40 flex items-center justify-center text-xs text-muted-foreground/70`,children:r(`scatter.empty`)}):(0,Y.jsx)(`div`,{className:`h-[260px]`,children:(0,Y.jsx)(E,{width:`100%`,height:`100%`,children:(0,Y.jsxs)(vt,{margin:{top:10,right:10,left:-8,bottom:5},children:[(0,Y.jsx)(de,{strokeDasharray:`2 4`,stroke:`currentColor`,className:`text-border/30`}),(0,Y.jsx)(W,{type:`number`,dataKey:`x`,name:`turns`,tick:{fontSize:10},stroke:`currentColor`,className:`text-muted-foreground`,label:{value:r(`scatter.turnsLabel`),position:`insideBottomRight`,offset:-2,fontSize:10,fill:`currentColor`}}),(0,Y.jsx)(ye,{type:`number`,dataKey:`y`,name:`cost`,tick:{fontSize:10},stroke:`currentColor`,className:`text-muted-foreground`,tickFormatter:e=>`$${e.toFixed(e<1?2:0)}`}),(0,Y.jsx)(gt,{range:[40,80]}),(0,Y.jsx)(A,{cursor:{strokeDasharray:`3 3`},contentStyle:{backgroundColor:`var(--popover)`,border:`1px solid var(--border)`,fontSize:11,borderRadius:6},formatter:(e,t)=>{let n=String(t);return n===`cost`&&typeof e==`number`?[`$${e.toFixed(3)}`,r(`scatter.costLabel`)]:[String(e),n===`turns`?r(`scatter.turnsLabel`):n]}}),a.map(e=>(0,Y.jsx)(pt,{data:e.points,fill:Et[e.surface],onClick:e=>{let t=e;t?.raw&&n(t.raw)}},e.surface))]})})})]})}function kt({data:e,loading:t,onSelectTicket:n}){let{t:r}=o(`analytics`);if(t&&!e)return(0,Y.jsx)(`div`,{className:`h-40 rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let i=e.topTickets;return(0,Y.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,Y.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider mb-3`,children:r(`topTickets.title`)}),i.length===0?(0,Y.jsx)(`div`,{className:`h-32 flex items-center justify-center text-xs text-muted-foreground/70`,children:r(`topTickets.empty`)}):(0,Y.jsx)(`ul`,{className:`divide-y divide-border/30`,children:i.map((e,t)=>{let i=Object.entries(e.bySurface).filter(([,e])=>e.count>0).map(([e,t])=>r(`topTickets.breakdownItem`,{n:t.count,label:f[e].toLowerCase()})).join(` + `),a=e.isUnattributed,o=a?r(`topTickets.unattributed`):e.ticketTitle?`#${e.ticketId} ${e.ticketTitle}`:r(`topTickets.deletedTicket`,{id:e.ticketId});return(0,Y.jsx)(`li`,{children:(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>n(e.ticketId),className:`w-full text-left flex items-center justify-between gap-3 py-2 px-1 hover:bg-accent/30 rounded transition-colors ${!e.ticketTitle&&!a?`opacity-50`:``}`,disabled:a,children:[(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`div`,{className:`text-sm truncate`,children:o}),(0,Y.jsx)(`div`,{className:`text-[11px] text-muted-foreground truncate`,children:i||`—`})]}),(0,Y.jsxs)(`div`,{className:`text-right tabular-nums`,children:[(0,Y.jsxs)(`div`,{className:`text-sm font-medium`,children:[`$`,e.totalCostUsd.toFixed(2)]}),(0,Y.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:r(`runs`,{count:e.totalRuns})})]})]})},`${e.ticketId??`u`}-${t}`)})})]})}var At={claude:`Claude`,codex:`Codex`,gemini:`Gemini`};function jt(e){return At[e]??e}function Mt(e){return e==null?`—`:e<.005?`$${e.toFixed(4)}`:`$${e.toFixed(2)}`}function Nt(e){return e==null?`—`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function Pt(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 Ft(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 It(e,t){if(e.model)return e.model;if(!Pt(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 Lt({rows:e,loading:t,truncated:n,totalAvailable:r,tableFilters:i,onTableFiltersChange:a}){let{t:s}=o(`analytics`),[c,l]=(0,J.useState)(null),u=Ft(e),d=new Set(e.map(e=>e.provider??`claude`)).size>1,m=n||r>e.length;return(0,Y.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 mb-3`,children:[(0,Y.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider`,children:s(`table.title`)}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-[11px]`,children:[(0,Y.jsxs)(`select`,{value:i.status??``,onChange:e=>a({...i,status:e.target.value||void 0}),className:`h-7 px-2 rounded-md bg-background-deep border border-border/60 text-xs`,"aria-label":s(`table.statusFilterAria`),children:[(0,Y.jsx)(`option`,{value:``,children:s(`table.allStatus`)}),(0,Y.jsx)(`option`,{value:`success`,children:s(`table.success`)}),(0,Y.jsx)(`option`,{value:`failed`,children:s(`table.failed`)}),(0,Y.jsx)(`option`,{value:`aborted`,children:s(`table.aborted`)})]}),(0,Y.jsx)(`input`,{type:`number`,step:`0.01`,min:`0`,placeholder:s(`table.minCostPlaceholder`),value:i.minCostUsd??``,onChange:e=>{let t=e.target.value===``?void 0:parseFloat(e.target.value);a({...i,minCostUsd:Number.isNaN(t)?void 0:t})},className:`h-7 w-24 px-2 rounded-md bg-background-deep border border-border/60 text-xs tabular-nums`,"aria-label":s(`table.minCostFilterAria`)})]})]}),t?(0,Y.jsx)(`div`,{className:`h-32 rounded bg-card/30 animate-pulse`}):e.length===0?(0,Y.jsx)(`div`,{className:`h-32 flex items-center justify-center text-xs text-muted-foreground/70`,children:s(`table.empty`)}):(0,Y.jsx)(`div`,{className:`overflow-x-auto`,children:(0,Y.jsxs)(`table`,{className:`w-full text-[12px] tabular-nums`,children:[(0,Y.jsx)(`thead`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:(0,Y.jsxs)(`tr`,{className:`text-left`,children:[(0,Y.jsx)(`th`,{className:`font-medium px-2 py-2`,children:s(`table.colSurface`)}),(0,Y.jsx)(`th`,{className:`font-medium px-2 py-2`,children:s(`table.colTicket`)}),(0,Y.jsx)(`th`,{className:`font-medium px-2 py-2 text-right`,children:s(`table.colCost`)}),(0,Y.jsx)(`th`,{className:`font-medium px-2 py-2 text-right`,children:s(`table.colTurns`)}),(0,Y.jsx)(`th`,{className:`font-medium px-2 py-2 text-right`,children:s(`table.colTokens`)}),(0,Y.jsx)(`th`,{className:`font-medium px-2 py-2`,children:s(`table.colModel`)}),d&&(0,Y.jsx)(`th`,{className:`font-medium px-2 py-2`,children:s(`table.colProvider`)}),(0,Y.jsx)(`th`,{className:`font-medium px-2 py-2`,children:s(`table.colStatus`)}),(0,Y.jsx)(`th`,{className:`font-medium px-2 py-2`,children:s(`table.colStarted`)})]})}),(0,Y.jsx)(`tbody`,{children:e.map(e=>{let t=e.surface,n=p[t],r=(e.tokens_in??0)+(e.tokens_out??0)+(e.tokens_cache_read??0)+(e.tokens_cache_create??0),i=Pt(e),a=i?s(`table.contractLayer`):f[t],o=It(e,u);return(0,Y.jsxs)(`tr`,{onClick:()=>l(c===e.id?null:e.id),className:`border-t border-border/30 hover:bg-accent/30 cursor-pointer`,children:[(0,Y.jsx)(`td`,{className:`px-2 py-2`,children:(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 px-2 h-5 rounded-full text-[10px] font-medium ${n.bg} ${n.text}`,children:[(0,Y.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full ${n.dot}`}),a]})}),(0,Y.jsx)(`td`,{className:`px-2 py-2 max-w-[260px]`,children:e.ticket_id==null?e.ticket_title?(0,Y.jsx)(`span`,{className:`truncate block text-muted-foreground/90 italic`,title:s(`table.provisionalTitleTooltip`),children:e.ticket_title}):(0,Y.jsx)(`span`,{className:`text-muted-foreground/70`,children:`—`}):(0,Y.jsxs)(`span`,{className:`truncate block`,children:[`#`,e.ticket_id,` `,i?(0,Y.jsx)(`span`,{className:`text-muted-foreground/90`,children:s(`table.contractLayerRefinement`)}):e.ticket_title??(0,Y.jsx)(`span`,{className:`text-muted-foreground/70 italic`,children:s(`table.deleted`)})]})}),(0,Y.jsx)(`td`,{className:`px-2 py-2 text-right font-medium`,children:e.total_cost_usd_estimated===1&&e.total_cost_usd!=null?(0,Y.jsxs)(`span`,{title:s(`table.estimatedCostTooltip`),className:`text-muted-foreground/90`,children:[`~`,Mt(e.total_cost_usd)]}):Mt(e.total_cost_usd)}),(0,Y.jsx)(`td`,{className:`px-2 py-2 text-right`,children:Nt(e.num_turns)}),(0,Y.jsx)(`td`,{className:`px-2 py-2 text-right`,children:r>0?Nt(r):`—`}),(0,Y.jsxs)(`td`,{className:`px-2 py-2 max-w-[180px] truncate`,children:[o??`—`,o&&!e.model?(0,Y.jsx)(`span`,{className:`ml-1 text-[10px] text-muted-foreground/70`,children:s(`table.inferred`)}):null]}),d&&(0,Y.jsx)(`td`,{className:`px-2 py-2 text-muted-foreground`,children:jt(e.provider??`claude`)}),(0,Y.jsxs)(`td`,{className:`px-2 py-2`,children:[e.status===`success`?(0,Y.jsx)(`span`,{className:`text-accent-success/90`,children:`●`}):e.status===`failed`?(0,Y.jsx)(`span`,{className:`text-accent-warning`,children:`⚠`}):(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`○`}),(0,Y.jsx)(`span`,{className:`ml-1 text-muted-foreground`,children:s(`table.statusValue.${e.status}`)})]}),(0,Y.jsx)(`td`,{className:`px-2 py-2 text-muted-foreground`,children:e.started_at.slice(0,16).replace(`T`,` `)})]},e.id)})})]})}),m&&e.length>0&&(0,Y.jsx)(`div`,{className:`mt-2 text-[11px] text-muted-foreground/80`,children:s(`table.truncated`,{shown:e.length,total:r.toLocaleString()})})]})}var Rt=[{value:`7d`,labelKey:`periods.d7`},{value:`30d`,labelKey:`periods.d30`},{value:`90d`,labelKey:`periods.d90`},{value:`all`,labelKey:`periods.all`}],zt=[{value:`all`,labelKey:`page.all`},{value:`job`,labelKey:`surfaces.job`},{value:`explore-spec`,labelKey:`surfaces.exploreSpec`},{value:`quick-spec`,labelKey:`surfaces.quickSpec`},{value:`ai-edit`,labelKey:`surfaces.aiEdit`},{value:`smash`,labelKey:`surfaces.smash`},{value:`file-summary`,labelKey:`surfaces.fileSummary`},{value:`loop`,labelKey:`surfaces.loop`}];function Bt(e){let t=new URLSearchParams;return e.period&&t.set(`period`,e.period),e.from&&t.set(`from`,e.from),e.to&&t.set(`to`,e.to),e.surface&&e.surface.length>0&&t.set(`surface`,e.surface.join(`,`)),e.provider&&e.provider.length>0&&t.set(`provider`,e.provider.join(`,`)),e.model&&e.model.length>0&&t.set(`model`,e.model.join(`,`)),e.modelKeys&&e.modelKeys.length>0&&e.model&&e.modelKeys.length===e.model.length&&t.set(`modelProvider`,e.modelKeys.map(e=>e.provider).join(`,`)),e.status&&t.set(`status`,e.status),typeof e.minCostUsd==`number`&&t.set(`minCostUsd`,String(e.minCostUsd)),typeof e.ticketId==`number`&&t.set(`ticketId`,String(e.ticketId)),typeof e.tzOffsetMinutes==`number`&&t.set(`tzOffsetMinutes`,String(e.tzOffsetMinutes)),e.sortBy&&t.set(`sortBy`,e.sortBy),t.toString()}function Vt(){let{t:e}=o(`analytics`),{activeProjectId:t,projects:n}=m(),[r,i]=c(),l=n.find(e=>e.id===t),u=l?d(l):[`claude`],f=u.length>1,p=r.get(`period`)??`30d`,v=(r.get(`surface`)??``).split(`,`).filter(Boolean),y=(r.get(`provider`)??``).split(`,`).filter(Boolean),b=r.get(`ticketId`),x=(r.get(`model`)??``).split(`,`).filter(Boolean),S=(r.get(`modelProvider`)??``).split(`,`).filter(Boolean),ee=x.length>0&&x.length===S.length?x.map((e,t)=>({provider:S[t],model:e})):void 0,te=(0,J.useMemo)(()=>-new Date().getTimezoneOffset(),[]),[C,w]=(0,J.useState)({period:p,surface:v.length>0?v:void 0,provider:y.length>0?y:void 0,ticketId:b?Number(b):void 0,model:x.length>0?x:void 0,modelKeys:ee,tzOffsetMinutes:te}),[T,E]=(0,J.useState)(null),[D,O]=(0,J.useState)(!0),[k,A]=(0,J.useState)(null),[j,M]=(0,J.useState)({}),[N,P]=(0,J.useState)(null),[F,ne]=(0,J.useState)(`recency`),I=(0,J.useRef)(new Map),L=(0,J.useRef)(0);(0,J.useEffect)(()=>{let e=new URLSearchParams;e.set(`period`,C.period),C.surface&&C.surface.length>0&&e.set(`surface`,C.surface.join(`,`)),C.provider&&C.provider.length>0&&e.set(`provider`,C.provider.join(`,`)),C.ticketId&&e.set(`ticketId`,String(C.ticketId)),C.model&&C.model.length>0&&(e.set(`model`,C.model.join(`,`)),C.modelKeys&&C.modelKeys.length===C.model.length&&e.set(`modelProvider`,C.modelKeys.map(e=>e.provider).join(`,`))),i(e,{replace:!0})},[C.period,C.surface,C.provider,C.ticketId,C.model,C.modelKeys,i]);let R=(0,J.useCallback)(async()=>{if(!t)return;let e=++L.current;A(null);let n=`${t}:${Bt(C)}`,r=I.current.get(n);r?(E(r),O(!1)):O(!0);try{let t=await fetch(`${g()}/spending?${Bt(C)}`);if(!t.ok)throw Error(`HTTP ${t.status}`);if(e!==L.current)return;let r=await t.json();I.current.set(n,r),E(r),O(!1)}catch(t){if(e!==L.current)return;A(t.message),O(!1)}},[t,C]),z=(0,J.useRef)(0),B=(0,J.useCallback)(async()=>{if(!t)return;let e=++z.current,n={...C};j.model&&(n.model=[j.model],n.modelKeys=void 0),j.status&&(n.status=j.status),typeof j.minCostUsd==`number`&&(n.minCostUsd=j.minCostUsd),n.sortBy=F;try{let t=await fetch(`${g()}/invocations?${Bt(n)}&limit=100`);if(!t.ok)throw Error(`HTTP ${t.status}`);let r=await t.json();if(e!==z.current)return;P(r)}catch{if(e!==z.current)return;P(null)}},[t,C,j,F]),re=(0,J.useRef)(t);(0,J.useEffect)(()=>{re.current!==t&&(re.current=t,E(null),P(null),O(!0))},[t]),(0,J.useEffect)(()=>{R()},[R]),(0,J.useEffect)(()=>{B()},[B]);let V=(0,J.useRef)(null),H=s();(0,J.useEffect)(()=>{let e=`analytics-spending`;return H.registerHandler(e,e=>{let n=e;n.type===`spending.invalidated`&&n.projectId===t&&(V.current&&clearTimeout(V.current),V.current=setTimeout(()=>{I.current.clear(),R(),B()},500))}),()=>{H.unregisterHandler(e),V.current&&clearTimeout(V.current)}},[H,t,R,B]);function ie(e){if(e===`all`){w(e=>({...e,surface:void 0}));return}w(t=>{let n=t.surface??[],r=n.includes(e)?n.filter(t=>t!==e):[...n,e];return{...t,surface:r.length>0?r:void 0}})}let ae=(0,J.useCallback)((e,t)=>{w(n=>{if(n.model?.length===1&&n.model[0]===e&&(t===void 0||n.modelKeys?.length===1&&n.modelKeys[0].provider===t))return{...n,model:void 0,modelKeys:void 0};let r=(T?.byModel??[]).filter(n=>n.model===e&&(t===void 0||n.provider===t)).map(e=>({provider:e.provider,model:e.model})),i=r.length>0?r.map(e=>e.model):[e];return{...n,model:i,modelKeys:r.length>0?r:void 0}})},[T]);function oe(){w(e=>({...e,model:void 0,modelKeys:void 0}))}function se(e){if(e===`all`){w(e=>({...e,provider:void 0}));return}w(t=>{let n=t.provider??[],r=n.includes(e)?n.filter(t=>t!==e):[...n,e];return{...t,provider:r.length>0?r:void 0}})}let U=C.surface,ce=!U||U.length===0,W=C.provider,le=!W||W.length===0,ue=(0,J.useMemo)(()=>{let e={period:C.period};return C.surface&&C.surface.length>0&&(e.surface=C.surface.join(`,`)),C.provider&&C.provider.length>0&&(e.provider=C.provider.join(`,`)),C.ticketId&&(e.ticketId=String(C.ticketId)),e},[C]),de=T?T.summary.totalRuns===0:!1;return(0,Y.jsxs)(`div`,{className:`flex flex-col gap-6 p-4 pb-12`,children:[(0,Y.jsxs)(`div`,{className:`sticky top-0 z-10 -mx-4 px-4 py-3 bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/80 border-b border-border/40`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(`h1`,{className:`text-base font-semibold tracking-tight`,children:e(`page.title`)}),C.ticketId&&(0,Y.jsx)(`button`,{type:`button`,onClick:()=>w(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:C.ticketId})}),C.model&&C.model.length>0&&(0,Y.jsxs)(`button`,{type:`button`,"data-testid":`analytics-model-chip`,onClick:oe,title:e(`page.clearModelFilter`),className:`inline-flex items-center gap-1 h-6 px-2 rounded-full text-[11px] font-medium bg-accent-highlight/15 text-accent-highlight ring-1 ring-accent-highlight/30 hover:bg-accent-highlight/25`,children:[e(`page.modelChip`,{model:C.model[0]}),(0,Y.jsx)(`span`,{"aria-hidden":!0,className:`opacity-70`,children:`×`})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`div`,{className:`flex items-center gap-1 rounded-md border border-border/60 bg-card/40 p-0.5`,children:Rt.map(t=>(0,Y.jsx)(`button`,{type:`button`,onClick:()=>w(e=>({...e,period:t.value})),className:`px-2.5 h-6 rounded text-[11px] font-medium transition-colors ${C.period===t.value?`bg-accent text-foreground`:`text-muted-foreground hover:text-foreground`}`,children:e(t.labelKey)},t.value))}),(0,Y.jsx)(_,{baseUrl:`${g()}/analytics/export`,params:ue,disabled:de}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>{I.current.clear(),R(),B()},className:`h-7 w-7 inline-flex items-center justify-center rounded-md border border-border/60 bg-card/50 text-muted-foreground hover:text-foreground hover:bg-accent/60`,title:e(`common:actions.refresh`),children:(0,Y.jsx)(h,{className:`w-3 h-3`})})]})]}),(0,Y.jsx)(`div`,{className:`mt-3 flex flex-wrap items-center gap-1.5`,children:zt.map(t=>(0,Y.jsx)(`button`,{type:`button`,onClick:()=>ie(t.value),className:`h-7 px-3 rounded-full text-[11px] font-medium transition-all ${(t.value===`all`?ce:U?.includes(t.value)??!1)?`bg-foreground/10 text-foreground ring-1 ring-foreground/20`:`text-muted-foreground hover:text-foreground hover:bg-accent/40`}`,children:e(t.labelKey)},t.value))}),f&&(0,Y.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-1.5`,"data-testid":`analytics-provider-chips`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-muted-foreground/70 mr-1`,children:e(`page.engine`)}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>se(`all`),className:`h-7 px-3 rounded-full text-[11px] font-medium transition-all ${le?`bg-foreground/10 text-foreground ring-1 ring-foreground/20`:`text-muted-foreground hover:text-foreground hover:bg-accent/40`}`,children:e(`page.all`)}),u.map(e=>(0,Y.jsx)(`button`,{type:`button`,onClick:()=>se(e),className:`h-7 px-3 rounded-full text-[11px] font-medium transition-all ${W?.includes(e)??!1?`bg-foreground/10 text-foreground ring-1 ring-foreground/20`:`text-muted-foreground hover:text-foreground hover:bg-accent/40`}`,children:a(e)},e))]})]}),k&&(0,Y.jsxs)(`div`,{className:`rounded-lg border border-accent-warning/30 bg-accent-warning/10 p-4 flex items-center justify-between`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-accent-warning`,children:e(`page.failedToLoad`,{error:k})}),(0,Y.jsxs)(`button`,{onClick:()=>R(),className:`flex items-center gap-1.5 h-7 px-3 rounded-md text-xs text-accent-warning border border-accent-warning/30 hover:bg-accent-warning/10`,children:[(0,Y.jsx)(h,{className:`w-3 h-3`}),e(`common:actions.retry`)]})]}),(0,Y.jsx)(Ne,{data:T,loading:D,period:C.period}),(0,Y.jsx)(ze,{data:T,loading:D}),(0,Y.jsx)(yt,{data:T,loading:D}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4`,children:[(0,Y.jsx)(wt,{data:T,loading:D}),(0,Y.jsx)(Tt,{data:T,loading:D,onSelectModel:ae,activeModel:C.model?.[0]})]}),(0,Y.jsx)(Ot,{data:T,loading:D,onSelectPoint:e=>{M(e=>({...e})),w(t=>({...t,ticketId:e.ticketId??void 0}))}}),(0,Y.jsx)(kt,{data:T,loading:D,onSelectTicket:e=>w(t=>({...t,ticketId:e??void 0}))}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-end gap-1.5`,"data-testid":`analytics-table-sort`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-muted-foreground/70 mr-1`,children:e(`table.sortLabel`)}),[`recency`,`cost`].map(t=>(0,Y.jsx)(`button`,{type:`button`,"data-testid":`analytics-table-sort-${t}`,"aria-pressed":F===t,onClick:()=>ne(t),className:`h-6 px-2.5 rounded-full text-[11px] font-medium transition-all ${F===t?`bg-foreground/10 text-foreground ring-1 ring-foreground/20`:`text-muted-foreground hover:text-foreground hover:bg-accent/40`}`,children:e(t===`recency`?`table.sortRecency`:`table.sortCost`)},t))]}),(0,Y.jsx)(Lt,{rows:N?.rows??[],loading:D&&!N,truncated:(N?.truncated??!1)||(N?.totalAvailable??0)>(N?.rows.length??0),totalAvailable:N?.totalAvailable??0,tableFilters:j,onTableFiltersChange:M})]})]})}export{Vt as default};
|