specrails-desktop 2.24.1 → 2.24.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/README.md +5 -4
  2. package/client/dist/assets/{ActivityFeedPage-D0HbUDeS.js → ActivityFeedPage-CxnjeMnO.js} +1 -1
  3. package/client/dist/assets/{AgentBrowserCapture-Brth-3zu.js → AgentBrowserCapture-c-Cr7q94.js} +1 -1
  4. package/client/dist/assets/{AgentModeCodePane-UuKgXzPX.js → AgentModeCodePane-CoZZ2_sJ.js} +2 -2
  5. package/client/dist/assets/{AgentModeJobsPane-_P5Xm6ij.js → AgentModeJobsPane-Dua5r_jk.js} +1 -1
  6. package/client/dist/assets/{AgentsPage-BHpan6kZ.js → AgentsPage-L-pmBTbc.js} +1 -1
  7. package/client/dist/assets/{AnalyticsPage-kryIHuZy.js → AnalyticsPage-B82qtTYV.js} +1 -1
  8. package/client/dist/assets/{BarChart-C5W41oN4.js → BarChart-JoGhQq6b.js} +1 -1
  9. package/client/dist/assets/{CodePage-B0WhKBeS.js → CodePage-CIBbOHTk.js} +1 -1
  10. package/client/dist/assets/{DesktopAnalyticsPage-u9a30yar.js → DesktopAnalyticsPage-D94CWcV4.js} +1 -1
  11. package/client/dist/assets/{DocsDialog-GSzYhxfg.js → DocsDialog-DIubUwd_.js} +1 -1
  12. package/client/dist/assets/{DocsPage-Bm0J873n.js → DocsPage-A9PpvdW3.js} +1 -1
  13. package/client/dist/assets/{ExportDropdown-CXc3MBkq.js → ExportDropdown-CWelhih_.js} +1 -1
  14. package/client/dist/assets/{IntegrationsPage-Z5Qy3n6G.js → IntegrationsPage-DtcigyHI.js} +1 -1
  15. package/client/dist/assets/{InteractiveJobComposer-BbBSAQm1.js → InteractiveJobComposer-CtkXJ1gD.js} +1 -1
  16. package/client/dist/assets/{JobDetailModal-CdPgkHdb.js → JobDetailModal-C-AewB0N.js} +1 -1
  17. package/client/dist/assets/{JobDetailPage-CprNUYlt.js → JobDetailPage-C2nAjNRu.js} +1 -1
  18. package/client/dist/assets/{JobsPage-ClIaG5ow.js → JobsPage-CtDu1BqI.js} +1 -1
  19. package/client/dist/assets/{LoopBuilderPage-rWwSzVr_.js → LoopBuilderPage-CLikTQXx.js} +1 -1
  20. package/client/dist/assets/{LoopPreviewModal-B0VUdegW.js → LoopPreviewModal-SEb8gedX.js} +1 -1
  21. package/client/dist/assets/{LoopsPage-Brrl03uv.js → LoopsPage-Pf_0o0Yf.js} +1 -1
  22. package/client/dist/assets/{ProjectSettingsDialog-i1aAs49_.js → ProjectSettingsDialog-C6_NZLxv.js} +1 -1
  23. package/client/dist/assets/{TemplatePreviewModal-C92-Ygm2.js → TemplatePreviewModal-CcTeX1GA.js} +1 -1
  24. package/client/dist/assets/agent-CXGbWkpN2.js +1 -0
  25. package/client/dist/assets/{agent-CbHTqhBt.js → agent-Cjiy_5TS.js} +1 -1
  26. package/client/dist/assets/agent-DBo9_-zx.js +1 -0
  27. package/client/dist/assets/agent-DUmd88ng.js +1 -0
  28. package/client/dist/assets/{agent-i5VEzNfj2.js → agent-N5jFquC82.js} +1 -1
  29. package/client/dist/assets/{agent-Bq74VvOq.js → agent-ay1iYN3L.js} +1 -1
  30. package/client/dist/assets/agent-dMyoDKGk.js +1 -0
  31. package/client/dist/assets/agent-opeyUUUG2.js +1 -0
  32. package/client/dist/assets/{brain-CJ92kxwM.js → brain-BVlxI-OH.js} +1 -1
  33. package/client/dist/assets/{dist-js-CAU8gTUN.js → dist-js-DOGUoTVT.js} +1 -1
  34. package/client/dist/assets/{dist-js-BVonQLiD.js → dist-js-DtG-ECSR.js} +1 -1
  35. package/client/dist/assets/{index-CfHBmcjb.js → index-B0fq5d1Z.js} +21 -21
  36. package/client/dist/assets/index-DZ2Beygz.css +2 -0
  37. package/client/dist/assets/{lib-DJy6HBRz.js → lib-B-CmfZ34.js} +1 -1
  38. package/client/dist/assets/{upload-D_1UxNS_.js → upload-B22mO1uT.js} +1 -1
  39. package/client/dist/assets/{value-BH0Vlt96.js → value-DltGn-Ab.js} +1 -1
  40. package/client/dist/index.html +3 -3
  41. package/docs/guide/de/integrations/3-jira-integration.md +3 -2
  42. package/docs/guide/de/pipeline/1-rails-and-jobs.md +5 -5
  43. package/docs/guide/de/pipeline/3-batch-implement-and-multi-feature.md +6 -4
  44. package/docs/guide/en/integrations/3-jira-integration.md +4 -3
  45. package/docs/guide/en/pipeline/1-rails-and-jobs.md +5 -5
  46. package/docs/guide/en/pipeline/3-batch-implement-and-multi-feature.md +6 -4
  47. package/docs/guide/es/integrations/3-jira-integration.md +3 -2
  48. package/docs/guide/es/pipeline/1-rails-and-jobs.md +5 -5
  49. package/docs/guide/es/pipeline/3-batch-implement-and-multi-feature.md +6 -4
  50. package/docs/guide/fr/integrations/3-jira-integration.md +3 -2
  51. package/docs/guide/fr/pipeline/1-rails-and-jobs.md +5 -5
  52. package/docs/guide/fr/pipeline/3-batch-implement-and-multi-feature.md +6 -4
  53. package/docs/guide/it/integrations/3-jira-integration.md +3 -2
  54. package/docs/guide/it/pipeline/1-rails-and-jobs.md +5 -5
  55. package/docs/guide/it/pipeline/3-batch-implement-and-multi-feature.md +6 -4
  56. package/docs/guide/ja/integrations/3-jira-integration.md +3 -2
  57. package/docs/guide/ja/pipeline/1-rails-and-jobs.md +5 -5
  58. package/docs/guide/ja/pipeline/3-batch-implement-and-multi-feature.md +6 -4
  59. package/docs/guide/pt/integrations/3-jira-integration.md +3 -2
  60. package/docs/guide/pt/pipeline/1-rails-and-jobs.md +5 -5
  61. package/docs/guide/pt/pipeline/3-batch-implement-and-multi-feature.md +6 -4
  62. package/docs/guide/zh/integrations/3-jira-integration.md +3 -2
  63. package/docs/guide/zh/pipeline/1-rails-and-jobs.md +5 -5
  64. package/docs/guide/zh/pipeline/3-batch-implement-and-multi-feature.md +6 -4
  65. package/package.json +1 -1
  66. package/server/dist/active-pr-continuation.js +242 -0
  67. package/server/dist/agent-operator-prompt.js +9 -0
  68. package/server/dist/docs-router.js +75 -10
  69. package/server/dist/jira/jira-adf.js +325 -36
  70. package/server/dist/jira/jira-sync-manager.js +50 -11
  71. package/server/dist/loop-factory.js +1 -1
  72. package/server/dist/loop-run-manager.js +49 -6
  73. package/server/dist/mcp/guide.js +9 -0
  74. package/server/dist/mcp/tools/rails.js +2 -1
  75. package/server/dist/project-router-git.js +26 -0
  76. package/server/dist/rail-isolated-launch.js +91 -7
  77. package/server/dist/rail-pr-store.js +1 -0
  78. package/server/dist/worktree-manager.js +24 -1
  79. package/client/dist/assets/agent-2gmrdgKk.js +0 -1
  80. package/client/dist/assets/agent-BrhvIxZF.js +0 -1
  81. package/client/dist/assets/agent-Ch_OIjXA2.js +0 -1
  82. package/client/dist/assets/agent-E-X9b1uz2.js +0 -1
  83. package/client/dist/assets/agent-zI95bSiF.js +0 -1
  84. package/client/dist/assets/index-B9483NYu.css +0 -2
package/README.md CHANGED
@@ -25,7 +25,7 @@
25
25
  **Specrails Desktop** (`specrails-desktop`) turns *"I'll just let the AI do it"* into a workflow you can **see, steer, and trust**. It's the desktop app for specrails — a local-first dashboard and CLI that sits on top of [**specrails-core**](https://github.com/fjpulidop/specrails-core) and gives you **one window for all your projects**:
26
26
 
27
27
  - 💬 Shape a spec in conversation with an AI, or generate one in a single shot.
28
- - 🛤️ Drag specs onto **execution rails**, pick a **Loop** to run (built-in or your own), and ship — one job at a time per project, in parallel across projects.
28
+ - 🛤️ Drag specs onto **execution rails**, pick a **Loop** to run (built-in or your own), and ship — rails run in parallel inside a git-backed project, each isolated in its own worktree.
29
29
  - 🤖 Watch the **Architect → Developer → Reviewer → Ship** pipeline stream live — and **talk to the running job**: ask questions or steer it mid-run from the built-in composer.
30
30
  - 💰 See exactly **what each agent cost you** this week, per provider, per ticket.
31
31
 
@@ -51,10 +51,10 @@
51
51
 
52
52
  | | |
53
53
  |---|---|
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. |
54
+ | 🛤️ **Execution rails** | Each rail is an independent lane. Drag specs in, **pick a Loop**, and press Play. In git-backed projects, rails run in parallel inside isolated per-spec worktrees, so several lanes can build at once without touching your active working tree. 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 (ask-first)** | Each rail runs in an isolated **git worktree** off your designated integration branch (set it in *Settings → Integration branch*). When it finishes, nothing is pushed and no PR exists yet — the specs move to **On Review** and the app **asks you first**: **Create PR** (one combined draft PR across all the specs on the rail) or **Discard** (clean up, specs back to the backlog). After creating it you can **Publish** (open the draft for your team's review) and **Check merge** — once your team merges it in GitHub, the specs flip to Done. specrails **never merges and never touches your working tree**. Set `SPECRAILS_RAIL_DELIVER_PR=0` to fall back to local integration. |
57
+ | 🔀 **Safe PR delivery (ask-first)** | Fresh work runs in an isolated **git worktree** off your designated integration branch (set it in *Settings → Integration branch*). When it finishes, nothing is pushed and no PR exists yet — the specs move to **On Review** and the app **asks you first**: **Create PR** (one combined draft PR across all the specs on the rail) or **Discard** (clean up, specs back to the backlog). If you relaunch a spec that is already in review with an open PR, specrails detects that active PR and continues its head branch instead of starting from the integration branch again. After a PR exists you can **Publish** (open the draft for your team's review) and **Check merge** — once your team merges it in GitHub, the specs flip to Done. specrails **never merges and never touches your working tree**. Projects without git degrade to shared-folder execution with no branch or PR card. Set `SPECRAILS_RAIL_DELIVER_PR=0` to fall back to local integration. |
58
58
  | 📡 **Live job detail** | A premium ticket-identity header, live duration ticker, incremental turns/tokens, and authoritative cost on exit. Every Claude job is a **live session**: a chat composer on the job view lets you ask the running agent questions or steer it mid-run — messages queue while it streams, and the job still finishes its plan (Freestyle waits for your explicit **Finalize**; everything else wraps up on its own). |
59
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. |
60
60
 
@@ -159,7 +159,8 @@ When the app is running, the CLI talks to it over HTTP + WebSocket; when it isn'
159
159
  - **[Claude Code](https://claude.com/claude-code)** — the `claude` binary, signed in (via Claude subscription login or an `ANTHROPIC_API_KEY`). No minimum version pinned.
160
160
  - **[Codex CLI](https://developers.openai.com/codex)** ≥ 0.128.0 — the `codex` binary. Run `codex login` or set `OPENAI_API_KEY`.
161
161
  - **[Gemini CLI](https://github.com/google-gemini/gemini-cli)** ≥ 0.11.0 — the `gemini` binary, authenticated (set `GEMINI_API_KEY`).
162
- - 🌿 **git**
162
+ - 🌿 **git** — required for isolated worktrees, branch-based resume, and PR delivery. Non-git projects still run in shared-folder mode, but no branch or PR card is created.
163
+ - 🔀 *(optional but recommended)* **GitHub CLI (`gh`)** authenticated — required when you want Specrails to create, publish, check, or continue GitHub pull requests for rail deliveries.
163
164
  - 🧪 *(optional)* **`uv`** — only if you want the Serena plugin
164
165
  - 📦 **specrails-core** ≥ 4.8.0 in the project *(the wizard installs it)* — a single shared floor for all providers; 4.8.0 is the release that ships the Gemini target. Agent profiles need core ≥ 4.1.0 in the project.
165
166
 
@@ -1 +1 @@
1
- import{a as e}from"./chunk-BNv3lrIs.js";import{Cn as t,Kn as n,Pt as r,Rn as i,Sn as a,gn as o,hn as s,it as c,nn as l,tn as u,vn as d,wn as f,xn as p}from"./index-CfHBmcjb.js";var m=o(`ban`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M4.929 4.929 19.07 19.071`,key:`196cmz`}]]),h=e(n(),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,o]=(0,h.useState)(!1),[s,c]=(0,h.useState)(!0),l=(0,h.useRef)(e);(0,h.useEffect)(()=>{l.current=e},[e]);let{registerHandler:u,unregisterHandler:d}=a();(0,h.useEffect)(()=>{if(!e){r([]),c(!0);return}let n=!1;o(!0),r([]),c(!0);async function i(){let e=f();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||o(!1)}}return i(),()=>{n=!0}},[e,t]);let m=(0,h.useCallback)(async()=>{if(i||!s)return;o(!0);let e=f(),n=l.current;try{r(i=>{let a=i[i.length-1];if(!a)return i;let s=encodeURIComponent(a.timestamp);return fetch(`${e}/activity?limit=${t}&before=${s}`).then(e=>e.json()).then(e=>{if(l.current!==n){o(!1);return}r(t=>g([...t,...e])),c(e.length===t),o(!1)}).catch(()=>o(!1)),i})}catch{o(!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:p.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)(()=>(u(`activity`,_),()=>d(`activity`)),[_,u,d]),{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)(l,{className:`w-4 h-4 text-green-500 aurora-light:text-accent-success flex-shrink-0`});case`job_failed`:return(0,v.jsx)(u,{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)(c,{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}=i(`activity`),{activeProjectId:t}=d(),{items:n,loading:a,hasMore:o,loadMore:c}=_({activeProjectId:t}),l=(0,h.useRef)(null);return(0,h.useEffect)(()=>{let e=l.current;if(!e)return;let t=new IntersectionObserver(e=>{e[0].isIntersecting&&o&&!a&&c()},{threshold:.1});return t.observe(e),()=>t.disconnect()},[o,a,c]),(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)(s,{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:[a&&n.length===0?(0,v.jsx)(`div`,{className:`flex items-center justify-center h-32`,children:(0,v.jsx)(r,{className:`w-4 h-4 animate-spin text-muted-foreground`})}):n.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)(s,{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:n.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:l,className:`h-1`}),a&&n.length>0&&(0,v.jsx)(`div`,{className:`flex justify-center py-3`,children:(0,v.jsx)(r,{className:`w-4 h-4 animate-spin text-muted-foreground`})}),!o&&n.length>0&&(0,v.jsx)(`p`,{className:`text-center text-xs text-muted-foreground py-3`,children:e(`feed.allLoaded`)})]})]})}export{C as default};
1
+ import{a as e}from"./chunk-BNv3lrIs.js";import{Cn as t,Kn as n,Pt as r,Rn as i,Sn as a,gn as o,hn as s,it as c,nn as l,tn as u,vn as d,wn as f,xn as p}from"./index-B0fq5d1Z.js";var m=o(`ban`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M4.929 4.929 19.07 19.071`,key:`196cmz`}]]),h=e(n(),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,o]=(0,h.useState)(!1),[s,c]=(0,h.useState)(!0),l=(0,h.useRef)(e);(0,h.useEffect)(()=>{l.current=e},[e]);let{registerHandler:u,unregisterHandler:d}=a();(0,h.useEffect)(()=>{if(!e){r([]),c(!0);return}let n=!1;o(!0),r([]),c(!0);async function i(){let e=f();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||o(!1)}}return i(),()=>{n=!0}},[e,t]);let m=(0,h.useCallback)(async()=>{if(i||!s)return;o(!0);let e=f(),n=l.current;try{r(i=>{let a=i[i.length-1];if(!a)return i;let s=encodeURIComponent(a.timestamp);return fetch(`${e}/activity?limit=${t}&before=${s}`).then(e=>e.json()).then(e=>{if(l.current!==n){o(!1);return}r(t=>g([...t,...e])),c(e.length===t),o(!1)}).catch(()=>o(!1)),i})}catch{o(!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:p.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)(()=>(u(`activity`,_),()=>d(`activity`)),[_,u,d]),{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)(l,{className:`w-4 h-4 text-green-500 aurora-light:text-accent-success flex-shrink-0`});case`job_failed`:return(0,v.jsx)(u,{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)(c,{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}=i(`activity`),{activeProjectId:t}=d(),{items:n,loading:a,hasMore:o,loadMore:c}=_({activeProjectId:t}),l=(0,h.useRef)(null);return(0,h.useEffect)(()=>{let e=l.current;if(!e)return;let t=new IntersectionObserver(e=>{e[0].isIntersecting&&o&&!a&&c()},{threshold:.1});return t.observe(e),()=>t.disconnect()},[o,a,c]),(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)(s,{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:[a&&n.length===0?(0,v.jsx)(`div`,{className:`flex items-center justify-center h-32`,children:(0,v.jsx)(r,{className:`w-4 h-4 animate-spin text-muted-foreground`})}):n.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)(s,{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:n.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:l,className:`h-1`}),a&&n.length>0&&(0,v.jsx)(`div`,{className:`flex justify-center py-3`,children:(0,v.jsx)(r,{className:`w-4 h-4 animate-spin text-muted-foreground`})}),!o&&n.length>0&&(0,v.jsx)(`p`,{className:`text-center text-xs text-muted-foreground py-3`,children:e(`feed.allLoaded`)})]})]})}export{C as default};
@@ -1 +1 @@
1
- import{a as e}from"./chunk-BNv3lrIs.js";import{Cn as t,F as n,Kn as r,Ln as i,Rn as a,n as o,s}from"./index-CfHBmcjb.js";var c=e(r(),1);function l(e,t){let n=e.indexOf(`,`);if(!e.startsWith(`data:`)||n===-1)throw Error(`dataUrlToFile: not a data URL`);let r=e.slice(0,n),i=/^data:([^;,]+)/.exec(r)?.[1]||`application/octet-stream`,a=e.slice(n+1);if(/;base64$/i.test(r)){let e=atob(a),n=new Uint8Array(e.length);for(let t=0;t<e.length;t++)n[t]=e.charCodeAt(t);return new File([n],t,{type:i})}return new File([decodeURIComponent(a)],t,{type:i})}var u=t();function d({projectId:e,conversationId:t}){let{t:r}=a(`agent`),{closeBrowser:d,queueCapture:f}=o(),p=(0,c.useMemo)(()=>`agent-${t??`home`}-${Math.round(performance.now())}`,[t]),m=async e=>{if(!t){i.error(r(`workspace.requiresConversation`));return}try{f(await s(t,l(e.screenshotDataUrl,`capture-${Date.now()}.png`))),i.success(r(`workspace.browserCaptured`)),d()}catch(e){i.error(r(`workspace.uploadFailed`),{description:e instanceof Error?e.message:void 0})}};return(0,u.jsx)(n,{open:!0,onClose:d,projectId:e,pendingSpecId:p,confirmLabel:r(`workspace.browserConfirm`),onCaptured:e=>{m(e)}})}export{d as AgentBrowserCapture};
1
+ import{a as e}from"./chunk-BNv3lrIs.js";import{Cn as t,F as n,Kn as r,Ln as i,Rn as a,n as o,s}from"./index-B0fq5d1Z.js";var c=e(r(),1);function l(e,t){let n=e.indexOf(`,`);if(!e.startsWith(`data:`)||n===-1)throw Error(`dataUrlToFile: not a data URL`);let r=e.slice(0,n),i=/^data:([^;,]+)/.exec(r)?.[1]||`application/octet-stream`,a=e.slice(n+1);if(/;base64$/i.test(r)){let e=atob(a),n=new Uint8Array(e.length);for(let t=0;t<e.length;t++)n[t]=e.charCodeAt(t);return new File([n],t,{type:i})}return new File([decodeURIComponent(a)],t,{type:i})}var u=t();function d({projectId:e,conversationId:t}){let{t:r}=a(`agent`),{closeBrowser:d,queueCapture:f}=o(),p=(0,c.useMemo)(()=>`agent-${t??`home`}-${Math.round(performance.now())}`,[t]),m=async e=>{if(!t){i.error(r(`workspace.requiresConversation`));return}try{f(await s(t,l(e.screenshotDataUrl,`capture-${Date.now()}.png`))),i.success(r(`workspace.browserCaptured`)),d()}catch(e){i.error(r(`workspace.uploadFailed`),{description:e instanceof Error?e.message:void 0})}};return(0,u.jsx)(n,{open:!0,onClose:d,projectId:e,pendingSpecId:p,confirmLabel:r(`workspace.browserConfirm`),onCaptured:e=>{m(e)}})}export{d as AgentBrowserCapture};
@@ -1,2 +1,2 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/CodePage-B0WhKBeS.js","assets/chunk-BNv3lrIs.js","assets/index-CfHBmcjb.js","assets/preload-helper-DSXbuxSR.js","assets/clsx-CNmW0Nip.js","assets/auth-Cvsb7-Ek.js","assets/activity-D8vQJrpW.js","assets/addspec-DxW6oPsk.js","assets/agent-CbHTqhBt.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-CdS6O1Qb.js","assets/chat-VMflhzxn.js","assets/code-thSEptMx.js","assets/commands-CckaBWdV.js","assets/common-CYaT2yHp.js","assets/dashboard-oqS7VRrK.js","assets/explore-BKVV5JSu.js","assets/integrations-CuWnMR5L.js","assets/jira-B3613-gj.js","assets/jobs-D5sZzgLs.js","assets/loops-YYV2bwjd.js","assets/mcp-CIH0pH1K.js","assets/nav-CzKzuwH8.js","assets/settings-Mr7MnJbf.js","assets/setup-VNqXyB6Y.js","assets/specs-CmEZY57v.js","assets/terminal-DFPNRLKp.js","assets/tickets-CkfbISuK.js","assets/index-B9483NYu.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,Kn as r,Mt as i,Rn as a,at as o,jt as s,n as c}from"./index-CfHBmcjb.js";var l=e(r(),1),u=n(),d=(0,l.lazy)(()=>t(()=>import(`./CodePage-B0WhKBeS.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:r}=c(),[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)(s,{className:`h-4 w-4`}):(0,u.jsx)(i,{className:`h-4 w-4`})}),(0,u.jsx)(`button`,{type:`button`,onClick:r,"aria-label":n(`workspace.closeFiles`),title:n(`workspace.closeFiles`),className:`rounded-md p-1 text-foreground/60 hover:bg-surface hover:text-foreground`,children:(0,u.jsx)(o,{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
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/CodePage-CIBbOHTk.js","assets/chunk-BNv3lrIs.js","assets/index-B0fq5d1Z.js","assets/preload-helper-DSXbuxSR.js","assets/clsx-CNmW0Nip.js","assets/auth-Cvsb7-Ek.js","assets/activity-D8vQJrpW.js","assets/addspec-DxW6oPsk.js","assets/agent-Cjiy_5TS.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-CdS6O1Qb.js","assets/chat-VMflhzxn.js","assets/code-thSEptMx.js","assets/commands-CckaBWdV.js","assets/common-CYaT2yHp.js","assets/dashboard-oqS7VRrK.js","assets/explore-BKVV5JSu.js","assets/integrations-CuWnMR5L.js","assets/jira-B3613-gj.js","assets/jobs-D5sZzgLs.js","assets/loops-YYV2bwjd.js","assets/mcp-CIH0pH1K.js","assets/nav-CzKzuwH8.js","assets/settings-Mr7MnJbf.js","assets/setup-VNqXyB6Y.js","assets/specs-CmEZY57v.js","assets/terminal-DFPNRLKp.js","assets/tickets-CkfbISuK.js","assets/index-DZ2Beygz.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,Kn as r,Mt as i,Rn as a,at as o,jt as s,n as c}from"./index-B0fq5d1Z.js";var l=e(r(),1),u=n(),d=(0,l.lazy)(()=>t(()=>import(`./CodePage-CIBbOHTk.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:r}=c(),[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)(s,{className:`h-4 w-4`}):(0,u.jsx)(i,{className:`h-4 w-4`})}),(0,u.jsx)(`button`,{type:`button`,onClick:r,"aria-label":n(`workspace.closeFiles`),title:n(`workspace.closeFiles`),className:`rounded-md p-1 text-foreground/60 hover:bg-surface hover:text-foreground`,children:(0,u.jsx)(o,{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{Cn as t,Kn as n,Mt as r,Pt as i,Rn as a,Sn as o,at as s,b as c,bn as l,cn as u,jt as d,n as f,rt as p,tt as m,vn as h,wn as g,yn as _}from"./index-CfHBmcjb.js";import{JobDetailModal as v}from"./JobDetailModal-CdPgkHdb.js";import{t as y}from"./format-command-CuWuRvka.js";var b=e(n(),1),x=t(),S=360,C=480,w={running:`running`,completed:`success`,failed:`failed`,canceled:`canceled`,queued:`queued`};function T({projectId:e}){let{t}=a(`agent`),{t:n}=a(`jobs`),{closeJobsPane:T}=f(),{projects:E}=h(),D=E.find(t=>t.id===e)?.provider,[O,k]=(0,b.useState)(C),[A,j]=(0,b.useState)(!1),[M,N]=(0,b.useState)(null),{data:P,isFirstLoad:F,refresh:I}=_({namespace:`agent-jobs`,projectId:e,initialValue:[],fetcher:async()=>{let e=await fetch(`${g()}/jobs?limit=50`);return e.ok?(await e.json()).jobs:[]},pollInterval:5e3}),{registerHandler:L,unregisterHandler:R}=o(),z=(0,b.useRef)(e);z.current=e;let B=(0,b.useRef)(I);B.current=I,(0,b.useEffect)(()=>(L(`agent-jobs-pane`,e=>{let t=e;t.type===`queue`&&(t.projectId&&t.projectId!==z.current||B.current())}),()=>R(`agent-jobs-pane`)),[L,R]);let V=(0,b.useCallback)(e=>{let t=e.clientX,n=O,r=window.innerWidth-S;try{e.currentTarget.setPointerCapture(e.pointerId)}catch{}let i=e=>{k(Math.min(Math.max(n+(t-e.clientX),S),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)},[O]);return(0,x.jsxs)(`div`,{className:p(`flex h-full flex-col overflow-hidden border-l border-border bg-background`,A&&`absolute inset-0 z-30 border-l-0`),style:A?void 0:{width:O,flexShrink:0},children:[(0,x.jsx)(`div`,{className:`relative flex items-center`,children:!A&&(0,x.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,onPointerDown:V,className:`absolute left-0 top-0 h-full w-1.5 -translate-x-full cursor-col-resize select-none touch-none hover:bg-accent-primary/20`,title:t(`workspace.resizeJobs`)})}),(0,x.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-border/60 bg-surface/40 px-3 py-1.5`,children:[(0,x.jsx)(`span`,{className:`text-xs font-medium text-foreground/70`,children:t(`workspace.jobs`)}),(0,x.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[(0,x.jsx)(`button`,{type:`button`,onClick:()=>j(e=>!e),"aria-label":t(A?`restore`:`maximize`),title:t(A?`restore`:`maximize`),className:`rounded-md p-1 text-foreground/60 hover:bg-surface hover:text-foreground`,children:A?(0,x.jsx)(d,{className:`h-4 w-4`}):(0,x.jsx)(r,{className:`h-4 w-4`})}),(0,x.jsx)(`button`,{type:`button`,onClick:T,"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,x.jsx)(s,{className:`h-4 w-4`})})]})]}),(0,x.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-2`,children:F?(0,x.jsx)(`div`,{className:`flex h-24 items-center justify-center text-muted-foreground`,children:(0,x.jsx)(i,{className:`h-4 w-4 animate-spin`})}):P.length===0?(0,x.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-2 text-center text-muted-foreground`,children:[(0,x.jsx)(u,{className:`h-6 w-6 opacity-40`}),(0,x.jsx)(`p`,{className:`text-xs`,children:t(`workspace.noJobs`)})]}):(0,x.jsx)(`ul`,{className:`space-y-1`,children:P.map(e=>(0,x.jsx)(`li`,{children:(0,x.jsxs)(`button`,{type:`button`,onClick:()=>N(e.id),className:p(`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,x.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,x.jsx)(m,{variant:w[e.status]??`queued`,children:n(`statusLabel.${e.status in w?e.status:`queued`}`)}),e.status===`running`&&(0,x.jsx)(i,{className:`h-3 w-3 animate-spin text-accent-primary`}),(0,x.jsx)(`span`,{className:`ml-auto text-[10px] text-muted-foreground`,children:c(new Date(e.started_at),{addSuffix:!0,locale:l()})})]}),(0,x.jsx)(`code`,{className:`truncate font-mono text-xs text-foreground/85`,children:y(e.command,D)})]})},e.id))})}),M&&(0,x.jsx)(v,{jobId:M,onClose:()=>N(null)})]})}export{T as AgentModeJobsPane};
1
+ import{a as e}from"./chunk-BNv3lrIs.js";import{Cn as t,Kn as n,Mt as r,Pt as i,Rn as a,Sn as o,at as s,b as c,bn as l,cn as u,jt as d,n as f,rt as p,tt as m,vn as h,wn as g,yn as _}from"./index-B0fq5d1Z.js";import{JobDetailModal as v}from"./JobDetailModal-C-AewB0N.js";import{t as y}from"./format-command-CuWuRvka.js";var b=e(n(),1),x=t(),S=360,C=480,w={running:`running`,completed:`success`,failed:`failed`,canceled:`canceled`,queued:`queued`};function T({projectId:e}){let{t}=a(`agent`),{t:n}=a(`jobs`),{closeJobsPane:T}=f(),{projects:E}=h(),D=E.find(t=>t.id===e)?.provider,[O,k]=(0,b.useState)(C),[A,j]=(0,b.useState)(!1),[M,N]=(0,b.useState)(null),{data:P,isFirstLoad:F,refresh:I}=_({namespace:`agent-jobs`,projectId:e,initialValue:[],fetcher:async()=>{let e=await fetch(`${g()}/jobs?limit=50`);return e.ok?(await e.json()).jobs:[]},pollInterval:5e3}),{registerHandler:L,unregisterHandler:R}=o(),z=(0,b.useRef)(e);z.current=e;let B=(0,b.useRef)(I);B.current=I,(0,b.useEffect)(()=>(L(`agent-jobs-pane`,e=>{let t=e;t.type===`queue`&&(t.projectId&&t.projectId!==z.current||B.current())}),()=>R(`agent-jobs-pane`)),[L,R]);let V=(0,b.useCallback)(e=>{let t=e.clientX,n=O,r=window.innerWidth-S;try{e.currentTarget.setPointerCapture(e.pointerId)}catch{}let i=e=>{k(Math.min(Math.max(n+(t-e.clientX),S),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)},[O]);return(0,x.jsxs)(`div`,{className:p(`flex h-full flex-col overflow-hidden border-l border-border bg-background`,A&&`absolute inset-0 z-30 border-l-0`),style:A?void 0:{width:O,flexShrink:0},children:[(0,x.jsx)(`div`,{className:`relative flex items-center`,children:!A&&(0,x.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,onPointerDown:V,className:`absolute left-0 top-0 h-full w-1.5 -translate-x-full cursor-col-resize select-none touch-none hover:bg-accent-primary/20`,title:t(`workspace.resizeJobs`)})}),(0,x.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-border/60 bg-surface/40 px-3 py-1.5`,children:[(0,x.jsx)(`span`,{className:`text-xs font-medium text-foreground/70`,children:t(`workspace.jobs`)}),(0,x.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[(0,x.jsx)(`button`,{type:`button`,onClick:()=>j(e=>!e),"aria-label":t(A?`restore`:`maximize`),title:t(A?`restore`:`maximize`),className:`rounded-md p-1 text-foreground/60 hover:bg-surface hover:text-foreground`,children:A?(0,x.jsx)(d,{className:`h-4 w-4`}):(0,x.jsx)(r,{className:`h-4 w-4`})}),(0,x.jsx)(`button`,{type:`button`,onClick:T,"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,x.jsx)(s,{className:`h-4 w-4`})})]})]}),(0,x.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-2`,children:F?(0,x.jsx)(`div`,{className:`flex h-24 items-center justify-center text-muted-foreground`,children:(0,x.jsx)(i,{className:`h-4 w-4 animate-spin`})}):P.length===0?(0,x.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-2 text-center text-muted-foreground`,children:[(0,x.jsx)(u,{className:`h-6 w-6 opacity-40`}),(0,x.jsx)(`p`,{className:`text-xs`,children:t(`workspace.noJobs`)})]}):(0,x.jsx)(`ul`,{className:`space-y-1`,children:P.map(e=>(0,x.jsx)(`li`,{children:(0,x.jsxs)(`button`,{type:`button`,onClick:()=>N(e.id),className:p(`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,x.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,x.jsx)(m,{variant:w[e.status]??`queued`,children:n(`statusLabel.${e.status in w?e.status:`queued`}`)}),e.status===`running`&&(0,x.jsx)(i,{className:`h-3 w-3 animate-spin text-accent-primary`}),(0,x.jsx)(`span`,{className:`ml-auto text-[10px] text-muted-foreground`,children:c(new Date(e.started_at),{addSuffix:!0,locale:l()})})]}),(0,x.jsx)(`code`,{className:`truncate font-mono text-xs text-foreground/85`,children:y(e.command,D)})]})},e.id))})}),M&&(0,x.jsx)(v,{jobId:M,onClose:()=>N(null)})]})}export{T as AgentModeJobsPane};
@@ -1,4 +1,4 @@
1
- import{a as e}from"./chunk-BNv3lrIs.js";import{$ as t,An as n,At as r,Bn as i,Cn as a,Ct as o,Dn as s,En as c,Fn as l,G as u,Gt as d,In as f,J as p,K as m,Kn as h,Ln as g,Mn as _,Nn as v,On as y,Ot as b,Pn as x,Pt as S,Q as C,Rn as w,Rt as T,Sn as E,Tn as D,Tt as O,X as k,Y as A,Yt as j,Z as M,Zt as ee,an as N,at as P,ct as F,dt as I,et as L,g as te,gn as R,jn as ne,k as z,kn as B,kt as V,lt as H,mn as re,mt as U,nt as W,on as ie,pn as ae,q as G,rn as oe,sn as se,un as ce,vn as le,vt as ue,wn as K,xn as q,yt as de,zt as J}from"./index-CfHBmcjb.js";var fe=R(`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`}]]),pe=R(`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`}]]),Y=e(h(),1),X=a(),me=/^[a-z0-9][a-z0-9-]*$/;function Z({open:e,mode:t=`add`,initial:n,chainAgents:r,onConfirm:a,onCancel:o}){let{t:s}=w(`agents`),[c,l]=(0,Y.useState)(``),[d,f]=(0,Y.useState)(r[0]??``);(0,Y.useEffect)(()=>{e&&(t===`edit`&&n?(l(n.tags.join(`, `)),f(r.includes(n.agent)?n.agent:r[0]??``)):(l(``),f(r[0]??``)))},[e,t,n,r]);let h=c.split(`,`).map(e=>e.trim()).filter(Boolean),g=h.filter(e=>!me.test(e)),_=h.length>0&&g.length===0&&r.includes(d);return(0,X.jsx)(u,{open:e,onOpenChange:e=>{e||o()},children:(0,X.jsxs)(m,{movableResizable:!0,className:`max-w-md`,children:[(0,X.jsxs)(A,{children:[(0,X.jsx)(k,{children:s(t===`edit`?`routingRule.editTitle`:`routingRule.addTitle`)}),(0,X.jsx)(G,{children:s(t===`edit`?`routingRule.editDescription`:`routingRule.addDescription`)})]}),(0,X.jsxs)(`div`,{className:`py-2 space-y-3`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:s(`routingRule.tagsLabel`)}),(0,X.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,X.jsx)(`p`,{className:`text-[11px] text-muted-foreground mt-1`,children:(0,X.jsx)(i,{t:s,i18nKey:`routingRule.tagsHint`,components:{code:(0,X.jsx)(`code`,{})}})}),g.length>0&&(0,X.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,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:s(`routingRule.routeToLabel`)}),(0,X.jsx)(`select`,{value:d,onChange:e=>f(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:r.map(e=>(0,X.jsx)(`option`,{value:e,children:e},e))}),(0,X.jsx)(`p`,{className:`text-[11px] text-muted-foreground mt-1`,children:s(`routingRule.routeToHint`)})]})]}),(0,X.jsxs)(p,{children:[(0,X.jsx)(W,{variant:`ghost`,size:`sm`,onClick:o,children:s(`common:actions.cancel`)}),(0,X.jsx)(W,{size:`sm`,onClick:()=>a(h,d),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:r,onValidityChange:a,onSoftWarningsChange:o}){let{t:u}=w(`agentstudio`),[d,f]=(0,Y.useState)([]),[p,m]=(0,Y.useState)(!1),[h,g]=(0,Y.useState)(!1),[y,b]=(0,Y.useState)(null);(0,Y.useEffect)(()=>{let e=!1;return fetch(`${K()}/profiles/catalog`).then(e=>e.ok?e.json():{agents:[]}).then(t=>{e||f(t.agents)}).catch(()=>{e||f([])}),()=>{e=!0}},[]);let S=n=>{let r=JSON.parse(JSON.stringify(e));n(r),t(r)},C=new Set(e.agents.map(e=>e.id)),T=d.filter(e=>!C.has(e.id)),E=(0,Y.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]),k=(0,Y.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,Y.useMemo)(()=>e.routing.some(e=>`default`in e&&e.default===!0),[e.routing]);(0,Y.useEffect)(()=>{a&&a(E)},[E,a]),(0,Y.useEffect)(()=>{o&&o({agentsMissingRouting:k})},[k,o]);let j=e=>{S(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)||S(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)}S(e=>{e.agents=a})},N=l(x(_,{activationConstraint:{distance:4}}),x(ne,{coordinateGetter:s})),F=e=>{let{active:t,over:n}=e;n&&ee(String(t.id),String(n.id))},I=(e,t)=>{S(n=>{n.agents[e].model=t})},L=(e,t)=>{S(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)},R=()=>{S(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,V=(e,t)=>{S(n=>{let r=n.routing[e];r&&(z(r)||(r.agent=t))})},H=(e,t,n)=>{S(r=>{let i=r.routing[e];i&&(z(i)||(i.tags=t,i.agent=n))})},re=e=>{S(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)||S(e=>{let[n]=e.routing.splice(t,1);e.routing.splice(r,0,n)})};return(0,X.jsxs)(`div`,{className:`p-6 space-y-6 max-w-3xl`,children:[(0,X.jsx)(Z,{open:h,mode:`add`,chainAgents:e.agents.map(e=>e.id),onConfirm:L,onCancel:()=>g(!1)}),(0,X.jsx)(Z,{open:y!==null,mode:`edit`,initial:y!==null&&e.routing[y]&&!(`default`in e.routing[y])?{tags:e.routing[y].tags,agent:e.routing[y].agent}:void 0,chainAgents:e.agents.map(e=>e.id),onConfirm:(e,t)=>{y!==null&&(H(y,e,t),b(null))},onCancel:()=>b(null)}),E.length>0&&(0,X.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,X.jsx)(`div`,{className:`font-medium mb-1`,children:u(`profileEditor.validationSummary`,{count:E.length})}),(0,X.jsx)(`ul`,{className:`list-disc list-inside space-y-0.5`,children:E.map((e,t)=>(0,X.jsx)(`li`,{children:e},t))})]}),(0,X.jsxs)(`section`,{className:`space-y-3`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:u(`profileEditor.nameLabel`)}),(0,X.jsx)(te,{value:e.name,disabled:!0,className:`text-sm`})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:u(`profileEditor.descriptionLabel`)}),(0,X.jsx)(te,{value:e.description??``,onChange:e=>S(t=>{t.description=e.target.value}),className:`text-sm`,placeholder:u(`profileEditor.descriptionPlaceholder`)})]})]}),(0,X.jsxs)(`section`,{children:[(0,X.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide mb-2`,children:u(`profileEditor.orchestrator.heading`)}),(0,X.jsxs)(`div`,{className:`flex items-center gap-3 p-3 rounded-md border border-border`,children:[(0,X.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,X.jsx)(`div`,{className:`text-sm font-mono text-foreground truncate`,children:`/specrails:implement · /specrails:batch-implement`}),(0,X.jsx)(`div`,{className:`text-[11px] text-muted-foreground mt-0.5`,children:u(`profileEditor.orchestrator.description`)})]}),(0,X.jsx)(be,{value:e.orchestrator.model,onChange:e=>S(t=>{t.orchestrator.model=e})})]})]}),(0,X.jsxs)(`section`,{children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,X.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:u(`profileEditor.agentChain.heading`,{n:e.agents.length})}),(0,X.jsxs)(W,{size:`sm`,variant:`ghost`,onClick:()=>m(e=>!e),disabled:T.length===0,title:T.length===0?u(`profileEditor.agentChain.addDisabledTitle`):u(`profileEditor.agentChain.addTitle`),children:[(0,X.jsx)(O,{className:`w-3.5 h-3.5 mr-1`}),` `,u(`common:actions.add`)]})]}),p&&(0,X.jsxs)(`div`,{className:`mb-2 p-2 rounded-md border border-border bg-muted/30`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between mb-1.5 px-1`,children:[(0,X.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:u(`profileEditor.agentChain.pickFromCatalog`,{n:T.length})}),(0,X.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:()=>m(!1),title:u(`common:actions.close`),children:(0,X.jsx)(P,{className:`w-3 h-3`})})]}),T.length===0?(0,X.jsx)(`div`,{className:`px-2 py-3 text-xs text-muted-foreground text-center`,children:u(`profileEditor.agentChain.emptyCatalog`)}):(0,X.jsx)(`div`,{className:`space-y-0.5 max-h-64 overflow-auto`,children:T.map(e=>(0,X.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,X.jsx)(`span`,{className:`text-sm font-mono`,children:e.id}),(0,X.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,X.jsx)(n,{sensors:N,collisionDetection:v,onDragEnd:F,children:(0,X.jsx)(D,{items:e.agents.map(e=>e.id),strategy:B,children:(0,X.jsx)(`div`,{className:`space-y-1.5`,children:e.agents.map((e,t)=>(0,X.jsx)(ve,{agent:e,canRemove:!Q.has(e.id),onModel:e=>I(t,e),onRemove:()=>M(t)},e.id))})})})]}),(0,X.jsxs)(`section`,{children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,X.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:u(`profileEditor.routing.heading`,{n:e.routing.length})}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,children:[!A&&(0,X.jsxs)(W,{size:`sm`,variant:`ghost`,onClick:R,disabled:e.agents.length===0,title:e.agents.length===0?u(`profileEditor.routing.needAgentsTitle`):void 0,children:[(0,X.jsx)(O,{className:`w-3.5 h-3.5 mr-1`}),` `,u(`profileEditor.routing.addDefault`)]}),(0,X.jsxs)(W,{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,X.jsx)(O,{className:`w-3.5 h-3.5 mr-1`}),` `,u(`profileEditor.routing.addRule`)]})]})]}),(0,X.jsx)(`p`,{className:`text-[11px] text-muted-foreground mb-2`,children:u(`profileEditor.routing.explainer`)}),k.length>0&&(0,X.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,X.jsx)(`div`,{className:`font-medium mb-1`,children:u(`profileEditor.routing.untargetedTitle`)}),(0,X.jsx)(`div`,{children:(0,X.jsx)(i,{t:u,i18nKey:`profileEditor.routing.untargetedDetail`,values:{agents:k.join(`, `)},components:{mono:(0,X.jsx)(`span`,{className:`font-mono`})}})})]}),(0,X.jsx)(`div`,{className:`space-y-1.5`,children:e.routing.map((t,n)=>{let r=`default`in t&&t.default===!0;return(0,X.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=>V(n,e),onEdit:()=>b(n),onUp:()=>U(n,-1),onDown:()=>U(n,1),onRemove:()=>re(n)},n)})})]}),r&&(0,X.jsx)(`div`,{className:`pt-3 border-t border-border`,children:r})]})}function ve({agent:e,canRemove:t,onModel:n,onRemove:r}){let{t:i}=w(`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:p,isDragging:m}=y({id:e.id});return(0,X.jsxs)(`div`,{ref:u,style:{transform:f.Transform.toString(d),transition:p,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,X.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,X.jsx)(J,{className:`w-3.5 h-3.5`})}),(0,X.jsx)(`span`,{className:`text-sm font-mono flex-1 truncate`,children:e.id}),o&&(0,X.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,X.jsx)(b,{className:`w-2.5 h-2.5 rotate-[135deg]`}),` `,i(`profileEditor.agentRow.pinnedFirst`)]}),s&&(0,X.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,X.jsx)(b,{className:`w-2.5 h-2.5 rotate-45`}),` `,i(`profileEditor.agentRow.pinnedLast`)]}),a&&!o&&!s&&(0,X.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:i(`profileEditor.agentRow.required`)}),(0,X.jsx)(be,{value:e.model??`sonnet`,onChange:n}),(0,X.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,X.jsx)(P,{className:`w-3 h-3`})})]})}function ye({rule:e,ordinal:t,isLast:n,canMove:r,canRemove:i,canEdit:a,chainAgents:o,onAgentChange:s,onEdit:c,onUp:l,onDown:u,onRemove:d}){let{t:f}=w(`agentstudio`),p=`default`in e&&e.default===!0;return(0,X.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,X.jsxs)(`span`,{className:`text-[10px] font-mono text-muted-foreground w-5 text-center flex-shrink-0`,children:[t,`.`]}),p?(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground flex-1`,children:f(`profileEditor.routingRow.everythingElse`)}):(0,X.jsx)(`span`,{className:`text-xs flex-1 flex gap-1 flex-wrap items-center`,children:e.tags.map(e=>(0,X.jsx)(`span`,{className:`px-1.5 py-0.5 rounded bg-muted font-mono text-[11px]`,children:e},e))}),(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`→`}),p?(0,X.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":f(`profileEditor.routingRow.defaultTargetAria`),title:f(`profileEditor.routingRow.defaultTargetTitle`),children:e.agent}):(0,X.jsx)(`select`,{value:e.agent,onChange:e=>s(e.target.value),"aria-label":f(`profileEditor.routingRow.targetAria`,{ordinal:t}),className:`h-7 max-w-[15rem] px-2 text-xs font-mono rounded border border-border bg-background`,children:o.map(e=>(0,X.jsx)(`option`,{value:e,children:e},e))}),(0,X.jsxs)(`div`,{className:`flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity`,children:[a&&(0,X.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:c,title:f(`profileEditor.routingRow.editTitle`),"aria-label":f(`profileEditor.routingRow.editAria`,{ordinal:t}),children:(0,X.jsx)(V,{className:`w-3 h-3`})}),r&&!n&&(0,X.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:u,title:f(`profileEditor.routingRow.moveDown`),children:(0,X.jsx)(re,{className:`w-3 h-3`})}),r&&t>1&&(0,X.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:l,title:f(`profileEditor.routingRow.moveUp`),children:(0,X.jsx)(ce,{className:`w-3 h-3`})}),i&&(0,X.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:d,title:f(`common:actions.remove`),children:(0,X.jsx)(P,{className:`w-3 h-3`})})]}),p&&(0,X.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,title:f(`profileEditor.routingRow.coreDefaultTitle`),children:f(`profileEditor.routingRow.coreDefaultBadge`)})]})}function be({value:e,onChange:t}){return(0,X.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,X.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:d}=w(),[f,h]=(0,Y.useState)(i);(0,Y.useEffect)(()=>{e&&h(i)},[e,i]);let g=f.trim(),_=!o||o.test(g),v=g.length>0&&_;return(0,X.jsx)(u,{open:e,onOpenChange:e=>{e||l()},children:(0,X.jsxs)(m,{movableResizable:!0,className:`max-w-md`,children:[(0,X.jsx)(A,{children:(0,X.jsx)(k,{children:t})}),(0,X.jsxs)(`div`,{className:`py-2 space-y-2`,children:[n&&(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n}),(0,X.jsx)(te,{autoFocus:!0,value:f,placeholder:r,onChange:e=>h(e.target.value),onKeyDown:e=>{e.key===`Enter`&&v&&c(g)},className:`text-sm font-mono`}),g.length>0&&!_&&s&&(0,X.jsx)(`p`,{className:`text-[11px] text-yellow-500 aurora-light:text-accent-warning`,children:s})]}),(0,X.jsxs)(p,{children:[(0,X.jsx)(W,{variant:`ghost`,size:`sm`,onClick:l,children:d(`actions.cancel`)}),(0,X.jsx)(W,{size:`sm`,onClick:()=>c(g),disabled:!v,children:a??d(`actions.confirm`)})]})]})})}function Se({open:e,title:t,description:n,confirmLabel:r,destructive:i=!1,onConfirm:a,onCancel:o}){let{t:s}=w();return(0,X.jsx)(u,{open:e,onOpenChange:e=>{e||o()},children:(0,X.jsxs)(m,{movableResizable:!0,className:`max-w-md`,children:[(0,X.jsx)(A,{children:(0,X.jsx)(k,{children:t})}),n&&(0,X.jsx)(`div`,{className:`py-2`,children:(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n})}),(0,X.jsxs)(p,{children:[(0,X.jsx)(W,{variant:`ghost`,size:`sm`,onClick:o,children:s(`actions.cancel`)}),(0,X.jsx)(W,{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}=w(`agents`),[t,n]=(0,Y.useState)([]),[r,a]=(0,Y.useState)(null),[o,s]=(0,Y.useState)(null),[c,l]=(0,Y.useState)(!0),[u,d]=(0,Y.useState)(null),[f,p]=(0,Y.useState)(!1),[m,h]=(0,Y.useState)([]),[_,v]=(0,Y.useState)([]),[y,b]=(0,Y.useState)(!1),[x,S]=(0,Y.useState)(null),[C,T]=(0,Y.useState)(null),E=(0,Y.useCallback)(async()=>{l(!0),d(null);try{let t=await fetch(`${K()}/profiles`);if(!t.ok)throw Error(e(`profiles.errors.listFailed`,{status:t.status}));let i=await t.json();n(i.profiles),i.profiles.length>0&&!r&&a(i.profiles[0].name)}catch(e){d(e.message)}finally{l(!1)}},[r]);(0,Y.useEffect)(()=>{E()},[E]),(0,Y.useEffect)(()=>{if(!r){s(null);return}let t=!1;return fetch(`${K()}/profiles/${encodeURIComponent(r)}`).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}},[r]);let D=(0,Y.useCallback)(async()=>{p(!0),d(null);try{let t=await fetch(`${K()}/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 E(),a(`default`),g.success(e(`profiles.toasts.migrated`),{description:e(`profiles.toasts.migratedDescription`)})}catch(t){let n=t.message;d(n),g.error(e(`profiles.toasts.migrationFailed`),{description:n})}finally{p(!1)}},[E]),k=(0,Y.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(`${K()}/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 E(),a(t),g.success(e(`profiles.toasts.created`),{description:t})}catch(t){let n=t.message;d(n),g.error(e(`profiles.toasts.createFailed`),{description:n})}finally{p(!1)}},[E]),A=(0,Y.useCallback)(async(t,n)=>{S(null),p(!0),d(null);try{let r=await fetch(`${K()}/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 E(),a(n),g.success(e(`profiles.toasts.duplicated`),{description:e(`profiles.toasts.duplicatedDescription`,{from:t,to:n})})}catch(t){let n=t.message;d(n),g.error(e(`profiles.toasts.duplicateFailed`),{description:n})}finally{p(!1)}},[E]),j=(0,Y.useCallback)(async t=>{T(null),p(!0),d(null);try{let n=await fetch(`${K()}/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 E(),g.success(e(`profiles.toasts.deleted`),{description:t})}catch(t){let n=t.message;d(n),g.error(e(`profiles.toasts.deleteFailed`),{description:n})}finally{p(!1)}},[E]),M=(0,Y.useCallback)(()=>b(!0),[]),N=(0,Y.useCallback)(e=>S({from:e}),[]),P=(0,Y.useCallback)(e=>T({name:e}),[]),F=(0,Y.useCallback)(async(t,n)=>{p(!0),d(null);try{let r=await fetch(`${K()}/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?g.warning(e(`profiles.toasts.savedWithUntargeted`),{description:e(`profiles.toasts.savedWithUntargetedDescription`,{agents:n.join(`, `)}),duration:6e3}):g.success(e(`profiles.toasts.saved`),{description:t.name})}catch(t){let n=t.message;d(n),g.error(e(`profiles.toasts.saveFailed`),{description:n})}finally{p(!1)}},[e]),I=(0,X.jsxs)(X.Fragment,{children:[(0,X.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,X.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)}),C&&(0,X.jsx)(Se,{open:!0,title:e(`profiles.deleteDialog.title`,{name:C.name}),description:e(`profiles.deleteDialog.description`),confirmLabel:e(`common:actions.delete`),destructive:!0,onConfirm:()=>void j(C.name),onCancel:()=>T(null)})]});return c?(0,X.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`profiles.loading`)})}):t.length===0?(0,X.jsxs)(X.Fragment,{children:[I,(0,X.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,X.jsxs)(`div`,{className:`text-center max-w-md`,children:[(0,X.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:e(`profiles.empty.title`)}),(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground mt-1 mb-4`,children:e(`profiles.empty.body`)}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2 justify-center`,children:[(0,X.jsxs)(W,{size:`sm`,onClick:D,disabled:f,children:[(0,X.jsx)(pe,{className:`w-3.5 h-3.5 mr-1.5`}),` `,e(`profiles.empty.migrateButton`)]}),(0,X.jsxs)(W,{size:`sm`,variant:`ghost`,onClick:M,disabled:f,children:[(0,X.jsx)(O,{className:`w-3.5 h-3.5 mr-1.5`}),` `,e(`profiles.empty.blankButton`)]})]}),(0,X.jsx)(`div`,{className:`text-[11px] text-muted-foreground/70 mt-3`,children:(0,X.jsx)(i,{t:e,i18nKey:`profiles.empty.migrateExplainer`,components:{code:(0,X.jsx)(`code`,{className:`text-foreground`})}})}),u&&(0,X.jsx)(`div`,{className:`mt-3 text-xs text-red-400 aurora-light:text-destructive`,children:u})]})})]}):(0,X.jsxs)(`div`,{className:`flex flex-col h-full`,children:[I,(0,X.jsxs)(`div`,{className:`flex flex-1 min-h-0`,children:[(0,X.jsxs)(`aside`,{className:`w-64 flex-shrink-0 border-r border-border flex flex-col`,children:[(0,X.jsxs)(`div`,{className:`p-3 flex items-center justify-between`,children:[(0,X.jsx)(`div`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:e(`profiles.sidebar.title`)}),(0,X.jsx)(W,{size:`sm`,variant:`ghost`,onClick:M,disabled:f,children:(0,X.jsx)(O,{className:`w-3.5 h-3.5`})})]}),(0,X.jsx)(`div`,{className:`flex-1 overflow-auto px-2 pb-3`,children:t.map(t=>(0,X.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===r?`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,X.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,X.jsx)(`span`,{className:`truncate font-medium`,children:t.name}),t.isDefault&&(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:e(`profiles.sidebar.teamDefault`)})]}),(0,X.jsxs)(`div`,{className:`flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity`,children:[(0,X.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,X.jsx)(ee,{className:`w-3 h-3`})}),!t.isDefault&&(0,X.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,X.jsx)(H,{className:`w-3 h-3`})})]})]},t.name))})]}),(0,X.jsxs)(`main`,{className:`flex-1 overflow-auto`,children:[u&&(0,X.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,X.jsx)(_e,{profile:o,onChange:s,onValidityChange:h,onSoftWarningsChange:e=>v(e.agentsMissingRouting),footer:(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsxs)(W,{size:`sm`,onClick:()=>void F(o,_),disabled:f||m.length>0,title:m.length>0?e(`profiles.editorFooter.fixValidationIssues`):void 0,children:[(0,X.jsx)(de,{className:`w-3.5 h-3.5 mr-1.5`}),e(`common:actions.save`)]}),f&&(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e(`common:states.saving`)}),m.length>0&&(0,X.jsx)(`span`,{className:`text-xs text-yellow-500 aurora-light:text-accent-warning`,children:e(`profiles.editorFooter.issuesToResolve`,{count:m.length})})]})},o.name):(0,X.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,X.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{$ as t,An as n,At as r,Bn as i,Cn as a,Ct as o,Dn as s,En as c,Fn as l,G as u,Gt as d,In as f,J as p,K as m,Kn as h,Ln as g,Mn as _,Nn as v,On as y,Ot as b,Pn as x,Pt as S,Q as C,Rn as w,Rt as T,Sn as E,Tn as D,Tt as O,X as k,Y as A,Yt as j,Z as M,Zt as ee,an as N,at as P,ct as F,dt as I,et as L,g as te,gn as R,jn as ne,k as z,kn as B,kt as V,lt as H,mn as re,mt as U,nt as W,on as ie,pn as ae,q as G,rn as oe,sn as se,un as ce,vn as le,vt as ue,wn as K,xn as q,yt as de,zt as J}from"./index-B0fq5d1Z.js";var fe=R(`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`}]]),pe=R(`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`}]]),Y=e(h(),1),X=a(),me=/^[a-z0-9][a-z0-9-]*$/;function Z({open:e,mode:t=`add`,initial:n,chainAgents:r,onConfirm:a,onCancel:o}){let{t:s}=w(`agents`),[c,l]=(0,Y.useState)(``),[d,f]=(0,Y.useState)(r[0]??``);(0,Y.useEffect)(()=>{e&&(t===`edit`&&n?(l(n.tags.join(`, `)),f(r.includes(n.agent)?n.agent:r[0]??``)):(l(``),f(r[0]??``)))},[e,t,n,r]);let h=c.split(`,`).map(e=>e.trim()).filter(Boolean),g=h.filter(e=>!me.test(e)),_=h.length>0&&g.length===0&&r.includes(d);return(0,X.jsx)(u,{open:e,onOpenChange:e=>{e||o()},children:(0,X.jsxs)(m,{movableResizable:!0,className:`max-w-md`,children:[(0,X.jsxs)(A,{children:[(0,X.jsx)(k,{children:s(t===`edit`?`routingRule.editTitle`:`routingRule.addTitle`)}),(0,X.jsx)(G,{children:s(t===`edit`?`routingRule.editDescription`:`routingRule.addDescription`)})]}),(0,X.jsxs)(`div`,{className:`py-2 space-y-3`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:s(`routingRule.tagsLabel`)}),(0,X.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,X.jsx)(`p`,{className:`text-[11px] text-muted-foreground mt-1`,children:(0,X.jsx)(i,{t:s,i18nKey:`routingRule.tagsHint`,components:{code:(0,X.jsx)(`code`,{})}})}),g.length>0&&(0,X.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,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:s(`routingRule.routeToLabel`)}),(0,X.jsx)(`select`,{value:d,onChange:e=>f(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:r.map(e=>(0,X.jsx)(`option`,{value:e,children:e},e))}),(0,X.jsx)(`p`,{className:`text-[11px] text-muted-foreground mt-1`,children:s(`routingRule.routeToHint`)})]})]}),(0,X.jsxs)(p,{children:[(0,X.jsx)(W,{variant:`ghost`,size:`sm`,onClick:o,children:s(`common:actions.cancel`)}),(0,X.jsx)(W,{size:`sm`,onClick:()=>a(h,d),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:r,onValidityChange:a,onSoftWarningsChange:o}){let{t:u}=w(`agentstudio`),[d,f]=(0,Y.useState)([]),[p,m]=(0,Y.useState)(!1),[h,g]=(0,Y.useState)(!1),[y,b]=(0,Y.useState)(null);(0,Y.useEffect)(()=>{let e=!1;return fetch(`${K()}/profiles/catalog`).then(e=>e.ok?e.json():{agents:[]}).then(t=>{e||f(t.agents)}).catch(()=>{e||f([])}),()=>{e=!0}},[]);let S=n=>{let r=JSON.parse(JSON.stringify(e));n(r),t(r)},C=new Set(e.agents.map(e=>e.id)),T=d.filter(e=>!C.has(e.id)),E=(0,Y.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]),k=(0,Y.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,Y.useMemo)(()=>e.routing.some(e=>`default`in e&&e.default===!0),[e.routing]);(0,Y.useEffect)(()=>{a&&a(E)},[E,a]),(0,Y.useEffect)(()=>{o&&o({agentsMissingRouting:k})},[k,o]);let j=e=>{S(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)||S(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)}S(e=>{e.agents=a})},N=l(x(_,{activationConstraint:{distance:4}}),x(ne,{coordinateGetter:s})),F=e=>{let{active:t,over:n}=e;n&&ee(String(t.id),String(n.id))},I=(e,t)=>{S(n=>{n.agents[e].model=t})},L=(e,t)=>{S(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)},R=()=>{S(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,V=(e,t)=>{S(n=>{let r=n.routing[e];r&&(z(r)||(r.agent=t))})},H=(e,t,n)=>{S(r=>{let i=r.routing[e];i&&(z(i)||(i.tags=t,i.agent=n))})},re=e=>{S(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)||S(e=>{let[n]=e.routing.splice(t,1);e.routing.splice(r,0,n)})};return(0,X.jsxs)(`div`,{className:`p-6 space-y-6 max-w-3xl`,children:[(0,X.jsx)(Z,{open:h,mode:`add`,chainAgents:e.agents.map(e=>e.id),onConfirm:L,onCancel:()=>g(!1)}),(0,X.jsx)(Z,{open:y!==null,mode:`edit`,initial:y!==null&&e.routing[y]&&!(`default`in e.routing[y])?{tags:e.routing[y].tags,agent:e.routing[y].agent}:void 0,chainAgents:e.agents.map(e=>e.id),onConfirm:(e,t)=>{y!==null&&(H(y,e,t),b(null))},onCancel:()=>b(null)}),E.length>0&&(0,X.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,X.jsx)(`div`,{className:`font-medium mb-1`,children:u(`profileEditor.validationSummary`,{count:E.length})}),(0,X.jsx)(`ul`,{className:`list-disc list-inside space-y-0.5`,children:E.map((e,t)=>(0,X.jsx)(`li`,{children:e},t))})]}),(0,X.jsxs)(`section`,{className:`space-y-3`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:u(`profileEditor.nameLabel`)}),(0,X.jsx)(te,{value:e.name,disabled:!0,className:`text-sm`})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:u(`profileEditor.descriptionLabel`)}),(0,X.jsx)(te,{value:e.description??``,onChange:e=>S(t=>{t.description=e.target.value}),className:`text-sm`,placeholder:u(`profileEditor.descriptionPlaceholder`)})]})]}),(0,X.jsxs)(`section`,{children:[(0,X.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide mb-2`,children:u(`profileEditor.orchestrator.heading`)}),(0,X.jsxs)(`div`,{className:`flex items-center gap-3 p-3 rounded-md border border-border`,children:[(0,X.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,X.jsx)(`div`,{className:`text-sm font-mono text-foreground truncate`,children:`/specrails:implement · /specrails:batch-implement`}),(0,X.jsx)(`div`,{className:`text-[11px] text-muted-foreground mt-0.5`,children:u(`profileEditor.orchestrator.description`)})]}),(0,X.jsx)(be,{value:e.orchestrator.model,onChange:e=>S(t=>{t.orchestrator.model=e})})]})]}),(0,X.jsxs)(`section`,{children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,X.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:u(`profileEditor.agentChain.heading`,{n:e.agents.length})}),(0,X.jsxs)(W,{size:`sm`,variant:`ghost`,onClick:()=>m(e=>!e),disabled:T.length===0,title:T.length===0?u(`profileEditor.agentChain.addDisabledTitle`):u(`profileEditor.agentChain.addTitle`),children:[(0,X.jsx)(O,{className:`w-3.5 h-3.5 mr-1`}),` `,u(`common:actions.add`)]})]}),p&&(0,X.jsxs)(`div`,{className:`mb-2 p-2 rounded-md border border-border bg-muted/30`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between mb-1.5 px-1`,children:[(0,X.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:u(`profileEditor.agentChain.pickFromCatalog`,{n:T.length})}),(0,X.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:()=>m(!1),title:u(`common:actions.close`),children:(0,X.jsx)(P,{className:`w-3 h-3`})})]}),T.length===0?(0,X.jsx)(`div`,{className:`px-2 py-3 text-xs text-muted-foreground text-center`,children:u(`profileEditor.agentChain.emptyCatalog`)}):(0,X.jsx)(`div`,{className:`space-y-0.5 max-h-64 overflow-auto`,children:T.map(e=>(0,X.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,X.jsx)(`span`,{className:`text-sm font-mono`,children:e.id}),(0,X.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,X.jsx)(n,{sensors:N,collisionDetection:v,onDragEnd:F,children:(0,X.jsx)(D,{items:e.agents.map(e=>e.id),strategy:B,children:(0,X.jsx)(`div`,{className:`space-y-1.5`,children:e.agents.map((e,t)=>(0,X.jsx)(ve,{agent:e,canRemove:!Q.has(e.id),onModel:e=>I(t,e),onRemove:()=>M(t)},e.id))})})})]}),(0,X.jsxs)(`section`,{children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,X.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:u(`profileEditor.routing.heading`,{n:e.routing.length})}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,children:[!A&&(0,X.jsxs)(W,{size:`sm`,variant:`ghost`,onClick:R,disabled:e.agents.length===0,title:e.agents.length===0?u(`profileEditor.routing.needAgentsTitle`):void 0,children:[(0,X.jsx)(O,{className:`w-3.5 h-3.5 mr-1`}),` `,u(`profileEditor.routing.addDefault`)]}),(0,X.jsxs)(W,{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,X.jsx)(O,{className:`w-3.5 h-3.5 mr-1`}),` `,u(`profileEditor.routing.addRule`)]})]})]}),(0,X.jsx)(`p`,{className:`text-[11px] text-muted-foreground mb-2`,children:u(`profileEditor.routing.explainer`)}),k.length>0&&(0,X.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,X.jsx)(`div`,{className:`font-medium mb-1`,children:u(`profileEditor.routing.untargetedTitle`)}),(0,X.jsx)(`div`,{children:(0,X.jsx)(i,{t:u,i18nKey:`profileEditor.routing.untargetedDetail`,values:{agents:k.join(`, `)},components:{mono:(0,X.jsx)(`span`,{className:`font-mono`})}})})]}),(0,X.jsx)(`div`,{className:`space-y-1.5`,children:e.routing.map((t,n)=>{let r=`default`in t&&t.default===!0;return(0,X.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=>V(n,e),onEdit:()=>b(n),onUp:()=>U(n,-1),onDown:()=>U(n,1),onRemove:()=>re(n)},n)})})]}),r&&(0,X.jsx)(`div`,{className:`pt-3 border-t border-border`,children:r})]})}function ve({agent:e,canRemove:t,onModel:n,onRemove:r}){let{t:i}=w(`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:p,isDragging:m}=y({id:e.id});return(0,X.jsxs)(`div`,{ref:u,style:{transform:f.Transform.toString(d),transition:p,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,X.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,X.jsx)(J,{className:`w-3.5 h-3.5`})}),(0,X.jsx)(`span`,{className:`text-sm font-mono flex-1 truncate`,children:e.id}),o&&(0,X.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,X.jsx)(b,{className:`w-2.5 h-2.5 rotate-[135deg]`}),` `,i(`profileEditor.agentRow.pinnedFirst`)]}),s&&(0,X.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,X.jsx)(b,{className:`w-2.5 h-2.5 rotate-45`}),` `,i(`profileEditor.agentRow.pinnedLast`)]}),a&&!o&&!s&&(0,X.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:i(`profileEditor.agentRow.required`)}),(0,X.jsx)(be,{value:e.model??`sonnet`,onChange:n}),(0,X.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,X.jsx)(P,{className:`w-3 h-3`})})]})}function ye({rule:e,ordinal:t,isLast:n,canMove:r,canRemove:i,canEdit:a,chainAgents:o,onAgentChange:s,onEdit:c,onUp:l,onDown:u,onRemove:d}){let{t:f}=w(`agentstudio`),p=`default`in e&&e.default===!0;return(0,X.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,X.jsxs)(`span`,{className:`text-[10px] font-mono text-muted-foreground w-5 text-center flex-shrink-0`,children:[t,`.`]}),p?(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground flex-1`,children:f(`profileEditor.routingRow.everythingElse`)}):(0,X.jsx)(`span`,{className:`text-xs flex-1 flex gap-1 flex-wrap items-center`,children:e.tags.map(e=>(0,X.jsx)(`span`,{className:`px-1.5 py-0.5 rounded bg-muted font-mono text-[11px]`,children:e},e))}),(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`→`}),p?(0,X.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":f(`profileEditor.routingRow.defaultTargetAria`),title:f(`profileEditor.routingRow.defaultTargetTitle`),children:e.agent}):(0,X.jsx)(`select`,{value:e.agent,onChange:e=>s(e.target.value),"aria-label":f(`profileEditor.routingRow.targetAria`,{ordinal:t}),className:`h-7 max-w-[15rem] px-2 text-xs font-mono rounded border border-border bg-background`,children:o.map(e=>(0,X.jsx)(`option`,{value:e,children:e},e))}),(0,X.jsxs)(`div`,{className:`flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity`,children:[a&&(0,X.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:c,title:f(`profileEditor.routingRow.editTitle`),"aria-label":f(`profileEditor.routingRow.editAria`,{ordinal:t}),children:(0,X.jsx)(V,{className:`w-3 h-3`})}),r&&!n&&(0,X.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:u,title:f(`profileEditor.routingRow.moveDown`),children:(0,X.jsx)(re,{className:`w-3 h-3`})}),r&&t>1&&(0,X.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:l,title:f(`profileEditor.routingRow.moveUp`),children:(0,X.jsx)(ce,{className:`w-3 h-3`})}),i&&(0,X.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:d,title:f(`common:actions.remove`),children:(0,X.jsx)(P,{className:`w-3 h-3`})})]}),p&&(0,X.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,title:f(`profileEditor.routingRow.coreDefaultTitle`),children:f(`profileEditor.routingRow.coreDefaultBadge`)})]})}function be({value:e,onChange:t}){return(0,X.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,X.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:d}=w(),[f,h]=(0,Y.useState)(i);(0,Y.useEffect)(()=>{e&&h(i)},[e,i]);let g=f.trim(),_=!o||o.test(g),v=g.length>0&&_;return(0,X.jsx)(u,{open:e,onOpenChange:e=>{e||l()},children:(0,X.jsxs)(m,{movableResizable:!0,className:`max-w-md`,children:[(0,X.jsx)(A,{children:(0,X.jsx)(k,{children:t})}),(0,X.jsxs)(`div`,{className:`py-2 space-y-2`,children:[n&&(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n}),(0,X.jsx)(te,{autoFocus:!0,value:f,placeholder:r,onChange:e=>h(e.target.value),onKeyDown:e=>{e.key===`Enter`&&v&&c(g)},className:`text-sm font-mono`}),g.length>0&&!_&&s&&(0,X.jsx)(`p`,{className:`text-[11px] text-yellow-500 aurora-light:text-accent-warning`,children:s})]}),(0,X.jsxs)(p,{children:[(0,X.jsx)(W,{variant:`ghost`,size:`sm`,onClick:l,children:d(`actions.cancel`)}),(0,X.jsx)(W,{size:`sm`,onClick:()=>c(g),disabled:!v,children:a??d(`actions.confirm`)})]})]})})}function Se({open:e,title:t,description:n,confirmLabel:r,destructive:i=!1,onConfirm:a,onCancel:o}){let{t:s}=w();return(0,X.jsx)(u,{open:e,onOpenChange:e=>{e||o()},children:(0,X.jsxs)(m,{movableResizable:!0,className:`max-w-md`,children:[(0,X.jsx)(A,{children:(0,X.jsx)(k,{children:t})}),n&&(0,X.jsx)(`div`,{className:`py-2`,children:(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n})}),(0,X.jsxs)(p,{children:[(0,X.jsx)(W,{variant:`ghost`,size:`sm`,onClick:o,children:s(`actions.cancel`)}),(0,X.jsx)(W,{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}=w(`agents`),[t,n]=(0,Y.useState)([]),[r,a]=(0,Y.useState)(null),[o,s]=(0,Y.useState)(null),[c,l]=(0,Y.useState)(!0),[u,d]=(0,Y.useState)(null),[f,p]=(0,Y.useState)(!1),[m,h]=(0,Y.useState)([]),[_,v]=(0,Y.useState)([]),[y,b]=(0,Y.useState)(!1),[x,S]=(0,Y.useState)(null),[C,T]=(0,Y.useState)(null),E=(0,Y.useCallback)(async()=>{l(!0),d(null);try{let t=await fetch(`${K()}/profiles`);if(!t.ok)throw Error(e(`profiles.errors.listFailed`,{status:t.status}));let i=await t.json();n(i.profiles),i.profiles.length>0&&!r&&a(i.profiles[0].name)}catch(e){d(e.message)}finally{l(!1)}},[r]);(0,Y.useEffect)(()=>{E()},[E]),(0,Y.useEffect)(()=>{if(!r){s(null);return}let t=!1;return fetch(`${K()}/profiles/${encodeURIComponent(r)}`).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}},[r]);let D=(0,Y.useCallback)(async()=>{p(!0),d(null);try{let t=await fetch(`${K()}/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 E(),a(`default`),g.success(e(`profiles.toasts.migrated`),{description:e(`profiles.toasts.migratedDescription`)})}catch(t){let n=t.message;d(n),g.error(e(`profiles.toasts.migrationFailed`),{description:n})}finally{p(!1)}},[E]),k=(0,Y.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(`${K()}/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 E(),a(t),g.success(e(`profiles.toasts.created`),{description:t})}catch(t){let n=t.message;d(n),g.error(e(`profiles.toasts.createFailed`),{description:n})}finally{p(!1)}},[E]),A=(0,Y.useCallback)(async(t,n)=>{S(null),p(!0),d(null);try{let r=await fetch(`${K()}/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 E(),a(n),g.success(e(`profiles.toasts.duplicated`),{description:e(`profiles.toasts.duplicatedDescription`,{from:t,to:n})})}catch(t){let n=t.message;d(n),g.error(e(`profiles.toasts.duplicateFailed`),{description:n})}finally{p(!1)}},[E]),j=(0,Y.useCallback)(async t=>{T(null),p(!0),d(null);try{let n=await fetch(`${K()}/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 E(),g.success(e(`profiles.toasts.deleted`),{description:t})}catch(t){let n=t.message;d(n),g.error(e(`profiles.toasts.deleteFailed`),{description:n})}finally{p(!1)}},[E]),M=(0,Y.useCallback)(()=>b(!0),[]),N=(0,Y.useCallback)(e=>S({from:e}),[]),P=(0,Y.useCallback)(e=>T({name:e}),[]),F=(0,Y.useCallback)(async(t,n)=>{p(!0),d(null);try{let r=await fetch(`${K()}/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?g.warning(e(`profiles.toasts.savedWithUntargeted`),{description:e(`profiles.toasts.savedWithUntargetedDescription`,{agents:n.join(`, `)}),duration:6e3}):g.success(e(`profiles.toasts.saved`),{description:t.name})}catch(t){let n=t.message;d(n),g.error(e(`profiles.toasts.saveFailed`),{description:n})}finally{p(!1)}},[e]),I=(0,X.jsxs)(X.Fragment,{children:[(0,X.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,X.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)}),C&&(0,X.jsx)(Se,{open:!0,title:e(`profiles.deleteDialog.title`,{name:C.name}),description:e(`profiles.deleteDialog.description`),confirmLabel:e(`common:actions.delete`),destructive:!0,onConfirm:()=>void j(C.name),onCancel:()=>T(null)})]});return c?(0,X.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`profiles.loading`)})}):t.length===0?(0,X.jsxs)(X.Fragment,{children:[I,(0,X.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,X.jsxs)(`div`,{className:`text-center max-w-md`,children:[(0,X.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:e(`profiles.empty.title`)}),(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground mt-1 mb-4`,children:e(`profiles.empty.body`)}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2 justify-center`,children:[(0,X.jsxs)(W,{size:`sm`,onClick:D,disabled:f,children:[(0,X.jsx)(pe,{className:`w-3.5 h-3.5 mr-1.5`}),` `,e(`profiles.empty.migrateButton`)]}),(0,X.jsxs)(W,{size:`sm`,variant:`ghost`,onClick:M,disabled:f,children:[(0,X.jsx)(O,{className:`w-3.5 h-3.5 mr-1.5`}),` `,e(`profiles.empty.blankButton`)]})]}),(0,X.jsx)(`div`,{className:`text-[11px] text-muted-foreground/70 mt-3`,children:(0,X.jsx)(i,{t:e,i18nKey:`profiles.empty.migrateExplainer`,components:{code:(0,X.jsx)(`code`,{className:`text-foreground`})}})}),u&&(0,X.jsx)(`div`,{className:`mt-3 text-xs text-red-400 aurora-light:text-destructive`,children:u})]})})]}):(0,X.jsxs)(`div`,{className:`flex flex-col h-full`,children:[I,(0,X.jsxs)(`div`,{className:`flex flex-1 min-h-0`,children:[(0,X.jsxs)(`aside`,{className:`w-64 flex-shrink-0 border-r border-border flex flex-col`,children:[(0,X.jsxs)(`div`,{className:`p-3 flex items-center justify-between`,children:[(0,X.jsx)(`div`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:e(`profiles.sidebar.title`)}),(0,X.jsx)(W,{size:`sm`,variant:`ghost`,onClick:M,disabled:f,children:(0,X.jsx)(O,{className:`w-3.5 h-3.5`})})]}),(0,X.jsx)(`div`,{className:`flex-1 overflow-auto px-2 pb-3`,children:t.map(t=>(0,X.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===r?`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,X.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,X.jsx)(`span`,{className:`truncate font-medium`,children:t.name}),t.isDefault&&(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:e(`profiles.sidebar.teamDefault`)})]}),(0,X.jsxs)(`div`,{className:`flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity`,children:[(0,X.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,X.jsx)(ee,{className:`w-3 h-3`})}),!t.isDefault&&(0,X.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,X.jsx)(H,{className:`w-3 h-3`})})]})]},t.name))})]}),(0,X.jsxs)(`main`,{className:`flex-1 overflow-auto`,children:[u&&(0,X.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,X.jsx)(_e,{profile:o,onChange:s,onValidityChange:h,onSoftWarningsChange:e=>v(e.agentsMissingRouting),footer:(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsxs)(W,{size:`sm`,onClick:()=>void F(o,_),disabled:f||m.length>0,title:m.length>0?e(`profiles.editorFooter.fixValidationIssues`):void 0,children:[(0,X.jsx)(de,{className:`w-3.5 h-3.5 mr-1.5`}),e(`common:actions.save`)]}),f&&(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e(`common:states.saving`)}),m.length>0&&(0,X.jsx)(`span`,{className:`text-xs text-yellow-500 aurora-light:text-accent-warning`,children:e(`profiles.editorFooter.issuesToResolve`,{count:m.length})})]})},o.name):(0,X.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`profiles.selectPrompt`)})})]})]})]})}function $(e){let t=e.workflow.map((e,t)=>`${t+1}. ${e}`).join(`
2
2
  `);return`---
3
3
  name: ${e.id}
4
4
  description: "${e.descriptionOneLine}"
@@ -1 +1 @@
1
- import{a as e}from"./chunk-BNv3lrIs.js";import{t}from"./clsx-CNmW0Nip.js";import{Bn as n,Cn as r,Ct as i,Kn as a,L as o,Rn as s,Sn as c,Wn as l,_ as u,_n as d,dn as f,gn as p,v as m,vn as h,wn as g}from"./index-CfHBmcjb.js";import{t as _}from"./ExportDropdown-CXc3MBkq.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-C5W41oN4.js";var ke=p(`arrow-down-right`,[[`path`,{d:`m7 7 10 10`,key:`1fmybs`}],[`path`,{d:`M17 7v10H7`,key:`6fjiku`}]]),J=e(a(),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}=s(`analytics`),[i,a]=(0,J.useState)(0),o=(0,J.useRef)(0),c=(0,J.useRef)(null),l=(0,J.useRef)(0);if((0,J.useEffect)(()=>{if(!e)return;let t=e.summary.totalCostUsd,n=++l.current;if(c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),o.current===0&&t>0){let e=performance.now(),r=i=>{if(n!==l.current)return;let o=Math.min(1,(i-e)/600),s=1-(1-o)**3;a(0+(t-0)*s),o<1?c.current=requestAnimationFrame(r):c.current=null};c.current=requestAnimationFrame(r)}else a(t);return o.current=t,()=>{c.current!==null&&(cancelAnimationFrame(c.current),c.current=null)}},[e]),t&&!e)return(0,Y.jsx)(`div`,{className:`h-44 rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let d=e.summary.totalCostUsd,p=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)(f,{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:p})}),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)})})]})]}),p===0&&v&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:r(`hero.trackingStarted`,{date:v.slice(0,10)})})]}),p===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 ${u[e.surface].dot}`,style:{width:`${t}%`},title:r(`hero.segmentTitle`,{label:m[e.surface],value:X(e.costUsd)})},e.surface)})}),(0,Y.jsx)(`div`,{className:`mt-3 flex flex-wrap items-center gap-x-5 gap-y-1.5 text-xs`,children: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 ${u[e.surface].dot}`}),(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:m[e.surface]}),(0,Y.jsx)(`span`,{className:`text-foreground font-medium`,children:X(e.costUsd)}),(0,Y.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,Y.jsx)(`span`,{className:`text-muted-foreground/80`,children:e.count})]},e.surface))})]})]})}var 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}=s(`analytics`);if(t&&!e)return(0,Y.jsx)(`div`,{className:`h-32 rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e||e.byProvider.length===0||e.byProvider.length===1)return null;let 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}=s(`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}=s(`analytics`);if(t&&!e)return(0,Y.jsx)(`div`,{className:`h-[220px] rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let r={jobs:n(`surfaces.job`),explore:n(`surfaces.exploreSpec`),quick:n(`surfaces.quickSpec`),refine:n(`surfaces.aiEdit`),fileSummaries:n(`surfaces.fileSummary`),smash:n(`surfaces.smash`),loop:n(`surfaces.loop`)},i=e.dailyTimeline.map(e=>({date:e.date.slice(5),[r.jobs]:e.jobsCostUsd,[r.explore]:e.exploreCostUsd,[r.quick]:e.quickCostUsd,[r.refine]:e.aiEditCostUsd,[r.fileSummaries]:e.fileSummaryCostUsd??0,[r.smash]:e.smashCostUsd??0,[r.loop]:e.loopCostUsd??0})),a=e.dailyTimeline.every(e=>e.jobsCostUsd+e.exploreCostUsd+e.quickCostUsd+e.aiEditCostUsd+(e.fileSummaryCostUsd??0)+(e.smashCostUsd??0)+(e.loopCostUsd??0)===0);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}=s(`analytics`),a=e.mode===`explore`&&e.totalRuns<5,o=(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":o?`true`:void 0,title:o?i(`quickVsExplore.estimatedTooltip`):void 0,children:[o&&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}=s(`analytics`);if(t&&!e)return(0,Y.jsx)(`div`,{className:`h-[220px] rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let r=e.byMode.find(e=>e.mode===`quick`),i=e.byMode.find(e=>e.mode===`explore`);if(!r||!i)return null;let a=r.avgCostPerSpec&&i.avgCostPerSpec&&r.avgCostPerSpec>0?i.avgCostPerSpec/r.avgCostPerSpec:null,o=a!==null&&r.totalRuns>=1&&i.totalRuns>=5,c=(r.estimatedCostUsd??0)>0||(i.estimatedCostUsd??0)>0;return(0,Y.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40`,children:[(0,Y.jsx)(`div`,{className:`px-4 pt-3 pb-1`,children:(0,Y.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider`,children:n(`quickVsExplore.title`)})}),(0,Y.jsxs)(`div`,{className:`flex divide-x divide-border/40`,children:[(0,Y.jsx)(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`})]}),o&&(0,Y.jsx)(`div`,{className:`px-4 pb-3 -mt-1`,children:(0,Y.jsx)(`div`,{className:`text-center text-[11px] text-muted-foreground tabular-nums`,children:(0,Y.jsxs)(`span`,{className:`px-2`,children:[`━━━━━━ `,n(`quickVsExplore.ratio`,{ratio:a.toFixed(1)}),` ━━━━━━`]})})}),c&&(0,Y.jsx)(`div`,{className:`px-4 pb-3 -mt-1`,"data-testid":`quick-vs-explore-estimated-footnote`,children:(0,Y.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:n(`quickVsExplore.estimatedFootnote`)})})]})}function Tt({data:e,loading:t,onSelectModel:n,activeModel:r}){let{t:i}=s(`analytics`);if(t&&!e)return(0,Y.jsx)(`div`,{className:`h-[220px] rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let a=e.summary.totalCostUsd,o=e.byModel.slice(0,5),c=o.reduce((e,t)=>e+t.costUsd,0),l=Math.max(0,a-c),u=l>=.005;return(0,Y.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,Y.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider mb-3`,children:i(`models.title`)}),o.length===0?(0,Y.jsx)(`div`,{className:`h-32 flex items-center justify-center text-xs text-muted-foreground/70`,children:i(`models.empty`)}):(0,Y.jsxs)(`ul`,{className:`space-y-1.5`,children:[o.map(e=>{let t=a>0?e.costUsd/a*100:0,o=r===e.model,s=(e.estimatedCostUsd??0)>0;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(m);function Ot({data:e,loading:t,onSelectPoint:n}){let{t:r}=s(`analytics`);if(t&&!e)return(0,Y.jsx)(`div`,{className:`h-[260px] rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let i=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}))})),o=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:m[e]})]},e))})]}),c&&!o&&(0,Y.jsx)(`div`,{"data-testid":`scatter-truncation-notice`,className:`mb-2 text-[10px] text-accent-warning`,children:r(`scatter.truncated`,{shown:e.scatter.length,total:l})}),o?(0,Y.jsx)(`div`,{className:`h-40 flex items-center justify-center text-xs text-muted-foreground/70`,children:r(`scatter.empty`)}):(0,Y.jsx)(`div`,{className:`h-[260px]`,children:(0,Y.jsx)(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}=s(`analytics`);if(t&&!e)return(0,Y.jsx)(`div`,{className:`h-40 rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let i=e.topTickets;return(0,Y.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,Y.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider mb-3`,children:r(`topTickets.title`)}),i.length===0?(0,Y.jsx)(`div`,{className:`h-32 flex items-center justify-center text-xs text-muted-foreground/70`,children:r(`topTickets.empty`)}):(0,Y.jsx)(`ul`,{className:`divide-y divide-border/30`,children:i.map((e,t)=>{let i=Object.entries(e.bySurface).filter(([,e])=>e.count>0).map(([e,t])=>r(`topTickets.breakdownItem`,{n:t.count,label:m[e].toLowerCase()})).join(` + `),a=e.isUnattributed,o=a?r(`topTickets.unattributed`):e.ticketTitle?`#${e.ticketId} ${e.ticketTitle}`:r(`topTickets.deletedTicket`,{id:e.ticketId});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:o}=s(`analytics`),[c,l]=(0,J.useState)(null),d=Ft(e),f=new Set(e.map(e=>e.provider??`claude`)).size>1,p=n||r>e.length;return(0,Y.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 mb-3`,children:[(0,Y.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider`,children:o(`table.title`)}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-[11px]`,children:[(0,Y.jsxs)(`select`,{value:i.status??``,onChange:e=>a({...i,status:e.target.value||void 0}),className:`h-7 px-2 rounded-md bg-background-deep border border-border/60 text-xs`,"aria-label":o(`table.statusFilterAria`),children:[(0,Y.jsx)(`option`,{value:``,children:o(`table.allStatus`)}),(0,Y.jsx)(`option`,{value:`success`,children:o(`table.success`)}),(0,Y.jsx)(`option`,{value:`failed`,children:o(`table.failed`)}),(0,Y.jsx)(`option`,{value:`aborted`,children:o(`table.aborted`)})]}),(0,Y.jsx)(`input`,{type:`number`,step:`0.01`,min:`0`,placeholder:o(`table.minCostPlaceholder`),value:i.minCostUsd??``,onChange:e=>{let t=e.target.value===``?void 0:parseFloat(e.target.value);a({...i,minCostUsd:Number.isNaN(t)?void 0:t})},className:`h-7 w-24 px-2 rounded-md bg-background-deep border border-border/60 text-xs tabular-nums`,"aria-label":o(`table.minCostFilterAria`)})]})]}),t?(0,Y.jsx)(`div`,{className:`h-32 rounded bg-card/30 animate-pulse`}):e.length===0?(0,Y.jsx)(`div`,{className:`h-32 flex items-center justify-center text-xs text-muted-foreground/70`,children:o(`table.empty`)}):(0,Y.jsx)(`div`,{className:`overflow-x-auto`,children:(0,Y.jsxs)(`table`,{className:`w-full text-[12px] tabular-nums`,children:[(0,Y.jsx)(`thead`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:(0,Y.jsxs)(`tr`,{className:`text-left`,children:[(0,Y.jsx)(`th`,{className:`font-medium px-2 py-2`,children:o(`table.colSurface`)}),(0,Y.jsx)(`th`,{className:`font-medium px-2 py-2`,children:o(`table.colTicket`)}),(0,Y.jsx)(`th`,{className:`font-medium px-2 py-2 text-right`,children:o(`table.colCost`)}),(0,Y.jsx)(`th`,{className:`font-medium px-2 py-2 text-right`,children:o(`table.colTurns`)}),(0,Y.jsx)(`th`,{className:`font-medium px-2 py-2 text-right`,children:o(`table.colTokens`)}),(0,Y.jsx)(`th`,{className:`font-medium px-2 py-2`,children:o(`table.colModel`)}),f&&(0,Y.jsx)(`th`,{className:`font-medium px-2 py-2`,children:o(`table.colProvider`)}),(0,Y.jsx)(`th`,{className:`font-medium px-2 py-2`,children:o(`table.colStatus`)}),(0,Y.jsx)(`th`,{className:`font-medium px-2 py-2`,children:o(`table.colStarted`)})]})}),(0,Y.jsx)(`tbody`,{children:e.map(e=>{let t=e.surface,n=u[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?o(`table.contractLayer`):m[t],s=It(e,d);return(0,Y.jsxs)(`tr`,{onClick:()=>l(c===e.id?null:e.id),className:`border-t border-border/30 hover:bg-accent/30 cursor-pointer`,children:[(0,Y.jsx)(`td`,{className:`px-2 py-2`,children:(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 px-2 h-5 rounded-full text-[10px] font-medium ${n.bg} ${n.text}`,children:[(0,Y.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full ${n.dot}`}),a]})}),(0,Y.jsx)(`td`,{className:`px-2 py-2 max-w-[260px]`,children:e.ticket_id==null?e.ticket_title?(0,Y.jsx)(`span`,{className:`truncate block text-muted-foreground/90 italic`,title:o(`table.provisionalTitleTooltip`),children:e.ticket_title}):(0,Y.jsx)(`span`,{className:`text-muted-foreground/70`,children:`—`}):(0,Y.jsxs)(`span`,{className:`truncate block`,children:[`#`,e.ticket_id,` `,i?(0,Y.jsx)(`span`,{className:`text-muted-foreground/90`,children:o(`table.contractLayerRefinement`)}):e.ticket_title??(0,Y.jsx)(`span`,{className:`text-muted-foreground/70 italic`,children:o(`table.deleted`)})]})}),(0,Y.jsx)(`td`,{className:`px-2 py-2 text-right font-medium`,children:e.total_cost_usd_estimated===1&&e.total_cost_usd!=null?(0,Y.jsxs)(`span`,{title:o(`table.estimatedCostTooltip`),className:`text-muted-foreground/90`,children:[`~`,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:[s??`—`,s&&!e.model?(0,Y.jsx)(`span`,{className:`ml-1 text-[10px] text-muted-foreground/70`,children:o(`table.inferred`)}):null]}),f&&(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:o(`table.statusValue.${e.status}`)})]}),(0,Y.jsx)(`td`,{className:`px-2 py-2 text-muted-foreground`,children:e.started_at.slice(0,16).replace(`T`,` `)})]},e.id)})})]})}),p&&e.length>0&&(0,Y.jsx)(`div`,{className:`mt-2 text-[11px] text-muted-foreground/80`,children:o(`table.truncated`,{shown:e.length,total:r.toLocaleString()})})]})}var 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}=s(`analytics`),{activeProjectId:t,projects:n}=h(),[r,a]=l(),u=n.find(e=>e.id===t),f=u?d(u):[`claude`],p=f.length>1,m=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:m,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(`,`))),a(e,{replace:!0})},[C.period,C.surface,C.provider,C.ticketId,C.model,C.modelKeys,a]);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=c();(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)(i,{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))}),p&&(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`)}),f.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:o(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)(i,{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};
1
+ import{a as e}from"./chunk-BNv3lrIs.js";import{t}from"./clsx-CNmW0Nip.js";import{Bn as n,Cn as r,Ct as i,Kn as a,L as o,Rn as s,Sn as c,Wn as l,_ as u,_n as d,dn as f,gn as p,v as m,vn as h,wn as g}from"./index-B0fq5d1Z.js";import{t as _}from"./ExportDropdown-CWelhih_.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-JoGhQq6b.js";var ke=p(`arrow-down-right`,[[`path`,{d:`m7 7 10 10`,key:`1fmybs`}],[`path`,{d:`M17 7v10H7`,key:`6fjiku`}]]),J=e(a(),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}=s(`analytics`),[i,a]=(0,J.useState)(0),o=(0,J.useRef)(0),c=(0,J.useRef)(null),l=(0,J.useRef)(0);if((0,J.useEffect)(()=>{if(!e)return;let t=e.summary.totalCostUsd,n=++l.current;if(c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),o.current===0&&t>0){let e=performance.now(),r=i=>{if(n!==l.current)return;let o=Math.min(1,(i-e)/600),s=1-(1-o)**3;a(0+(t-0)*s),o<1?c.current=requestAnimationFrame(r):c.current=null};c.current=requestAnimationFrame(r)}else a(t);return o.current=t,()=>{c.current!==null&&(cancelAnimationFrame(c.current),c.current=null)}},[e]),t&&!e)return(0,Y.jsx)(`div`,{className:`h-44 rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let d=e.summary.totalCostUsd,p=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)(f,{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:p})}),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)})})]})]}),p===0&&v&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:r(`hero.trackingStarted`,{date:v.slice(0,10)})})]}),p===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 ${u[e.surface].dot}`,style:{width:`${t}%`},title:r(`hero.segmentTitle`,{label:m[e.surface],value:X(e.costUsd)})},e.surface)})}),(0,Y.jsx)(`div`,{className:`mt-3 flex flex-wrap items-center gap-x-5 gap-y-1.5 text-xs`,children: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 ${u[e.surface].dot}`}),(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:m[e.surface]}),(0,Y.jsx)(`span`,{className:`text-foreground font-medium`,children:X(e.costUsd)}),(0,Y.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,Y.jsx)(`span`,{className:`text-muted-foreground/80`,children:e.count})]},e.surface))})]})]})}var 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}=s(`analytics`);if(t&&!e)return(0,Y.jsx)(`div`,{className:`h-32 rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e||e.byProvider.length===0||e.byProvider.length===1)return null;let 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}=s(`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}=s(`analytics`);if(t&&!e)return(0,Y.jsx)(`div`,{className:`h-[220px] rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let r={jobs:n(`surfaces.job`),explore:n(`surfaces.exploreSpec`),quick:n(`surfaces.quickSpec`),refine:n(`surfaces.aiEdit`),fileSummaries:n(`surfaces.fileSummary`),smash:n(`surfaces.smash`),loop:n(`surfaces.loop`)},i=e.dailyTimeline.map(e=>({date:e.date.slice(5),[r.jobs]:e.jobsCostUsd,[r.explore]:e.exploreCostUsd,[r.quick]:e.quickCostUsd,[r.refine]:e.aiEditCostUsd,[r.fileSummaries]:e.fileSummaryCostUsd??0,[r.smash]:e.smashCostUsd??0,[r.loop]:e.loopCostUsd??0})),a=e.dailyTimeline.every(e=>e.jobsCostUsd+e.exploreCostUsd+e.quickCostUsd+e.aiEditCostUsd+(e.fileSummaryCostUsd??0)+(e.smashCostUsd??0)+(e.loopCostUsd??0)===0);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}=s(`analytics`),a=e.mode===`explore`&&e.totalRuns<5,o=(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":o?`true`:void 0,title:o?i(`quickVsExplore.estimatedTooltip`):void 0,children:[o&&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}=s(`analytics`);if(t&&!e)return(0,Y.jsx)(`div`,{className:`h-[220px] rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let r=e.byMode.find(e=>e.mode===`quick`),i=e.byMode.find(e=>e.mode===`explore`);if(!r||!i)return null;let a=r.avgCostPerSpec&&i.avgCostPerSpec&&r.avgCostPerSpec>0?i.avgCostPerSpec/r.avgCostPerSpec:null,o=a!==null&&r.totalRuns>=1&&i.totalRuns>=5,c=(r.estimatedCostUsd??0)>0||(i.estimatedCostUsd??0)>0;return(0,Y.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40`,children:[(0,Y.jsx)(`div`,{className:`px-4 pt-3 pb-1`,children:(0,Y.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider`,children:n(`quickVsExplore.title`)})}),(0,Y.jsxs)(`div`,{className:`flex divide-x divide-border/40`,children:[(0,Y.jsx)(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`})]}),o&&(0,Y.jsx)(`div`,{className:`px-4 pb-3 -mt-1`,children:(0,Y.jsx)(`div`,{className:`text-center text-[11px] text-muted-foreground tabular-nums`,children:(0,Y.jsxs)(`span`,{className:`px-2`,children:[`━━━━━━ `,n(`quickVsExplore.ratio`,{ratio:a.toFixed(1)}),` ━━━━━━`]})})}),c&&(0,Y.jsx)(`div`,{className:`px-4 pb-3 -mt-1`,"data-testid":`quick-vs-explore-estimated-footnote`,children:(0,Y.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:n(`quickVsExplore.estimatedFootnote`)})})]})}function Tt({data:e,loading:t,onSelectModel:n,activeModel:r}){let{t:i}=s(`analytics`);if(t&&!e)return(0,Y.jsx)(`div`,{className:`h-[220px] rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let a=e.summary.totalCostUsd,o=e.byModel.slice(0,5),c=o.reduce((e,t)=>e+t.costUsd,0),l=Math.max(0,a-c),u=l>=.005;return(0,Y.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,Y.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider mb-3`,children:i(`models.title`)}),o.length===0?(0,Y.jsx)(`div`,{className:`h-32 flex items-center justify-center text-xs text-muted-foreground/70`,children:i(`models.empty`)}):(0,Y.jsxs)(`ul`,{className:`space-y-1.5`,children:[o.map(e=>{let t=a>0?e.costUsd/a*100:0,o=r===e.model,s=(e.estimatedCostUsd??0)>0;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(m);function Ot({data:e,loading:t,onSelectPoint:n}){let{t:r}=s(`analytics`);if(t&&!e)return(0,Y.jsx)(`div`,{className:`h-[260px] rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let i=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}))})),o=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:m[e]})]},e))})]}),c&&!o&&(0,Y.jsx)(`div`,{"data-testid":`scatter-truncation-notice`,className:`mb-2 text-[10px] text-accent-warning`,children:r(`scatter.truncated`,{shown:e.scatter.length,total:l})}),o?(0,Y.jsx)(`div`,{className:`h-40 flex items-center justify-center text-xs text-muted-foreground/70`,children:r(`scatter.empty`)}):(0,Y.jsx)(`div`,{className:`h-[260px]`,children:(0,Y.jsx)(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}=s(`analytics`);if(t&&!e)return(0,Y.jsx)(`div`,{className:`h-40 rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let i=e.topTickets;return(0,Y.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,Y.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider mb-3`,children:r(`topTickets.title`)}),i.length===0?(0,Y.jsx)(`div`,{className:`h-32 flex items-center justify-center text-xs text-muted-foreground/70`,children:r(`topTickets.empty`)}):(0,Y.jsx)(`ul`,{className:`divide-y divide-border/30`,children:i.map((e,t)=>{let i=Object.entries(e.bySurface).filter(([,e])=>e.count>0).map(([e,t])=>r(`topTickets.breakdownItem`,{n:t.count,label:m[e].toLowerCase()})).join(` + `),a=e.isUnattributed,o=a?r(`topTickets.unattributed`):e.ticketTitle?`#${e.ticketId} ${e.ticketTitle}`:r(`topTickets.deletedTicket`,{id:e.ticketId});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:o}=s(`analytics`),[c,l]=(0,J.useState)(null),d=Ft(e),f=new Set(e.map(e=>e.provider??`claude`)).size>1,p=n||r>e.length;return(0,Y.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 mb-3`,children:[(0,Y.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider`,children:o(`table.title`)}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-[11px]`,children:[(0,Y.jsxs)(`select`,{value:i.status??``,onChange:e=>a({...i,status:e.target.value||void 0}),className:`h-7 px-2 rounded-md bg-background-deep border border-border/60 text-xs`,"aria-label":o(`table.statusFilterAria`),children:[(0,Y.jsx)(`option`,{value:``,children:o(`table.allStatus`)}),(0,Y.jsx)(`option`,{value:`success`,children:o(`table.success`)}),(0,Y.jsx)(`option`,{value:`failed`,children:o(`table.failed`)}),(0,Y.jsx)(`option`,{value:`aborted`,children:o(`table.aborted`)})]}),(0,Y.jsx)(`input`,{type:`number`,step:`0.01`,min:`0`,placeholder:o(`table.minCostPlaceholder`),value:i.minCostUsd??``,onChange:e=>{let t=e.target.value===``?void 0:parseFloat(e.target.value);a({...i,minCostUsd:Number.isNaN(t)?void 0:t})},className:`h-7 w-24 px-2 rounded-md bg-background-deep border border-border/60 text-xs tabular-nums`,"aria-label":o(`table.minCostFilterAria`)})]})]}),t?(0,Y.jsx)(`div`,{className:`h-32 rounded bg-card/30 animate-pulse`}):e.length===0?(0,Y.jsx)(`div`,{className:`h-32 flex items-center justify-center text-xs text-muted-foreground/70`,children:o(`table.empty`)}):(0,Y.jsx)(`div`,{className:`overflow-x-auto`,children:(0,Y.jsxs)(`table`,{className:`w-full text-[12px] tabular-nums`,children:[(0,Y.jsx)(`thead`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:(0,Y.jsxs)(`tr`,{className:`text-left`,children:[(0,Y.jsx)(`th`,{className:`font-medium px-2 py-2`,children:o(`table.colSurface`)}),(0,Y.jsx)(`th`,{className:`font-medium px-2 py-2`,children:o(`table.colTicket`)}),(0,Y.jsx)(`th`,{className:`font-medium px-2 py-2 text-right`,children:o(`table.colCost`)}),(0,Y.jsx)(`th`,{className:`font-medium px-2 py-2 text-right`,children:o(`table.colTurns`)}),(0,Y.jsx)(`th`,{className:`font-medium px-2 py-2 text-right`,children:o(`table.colTokens`)}),(0,Y.jsx)(`th`,{className:`font-medium px-2 py-2`,children:o(`table.colModel`)}),f&&(0,Y.jsx)(`th`,{className:`font-medium px-2 py-2`,children:o(`table.colProvider`)}),(0,Y.jsx)(`th`,{className:`font-medium px-2 py-2`,children:o(`table.colStatus`)}),(0,Y.jsx)(`th`,{className:`font-medium px-2 py-2`,children:o(`table.colStarted`)})]})}),(0,Y.jsx)(`tbody`,{children:e.map(e=>{let t=e.surface,n=u[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?o(`table.contractLayer`):m[t],s=It(e,d);return(0,Y.jsxs)(`tr`,{onClick:()=>l(c===e.id?null:e.id),className:`border-t border-border/30 hover:bg-accent/30 cursor-pointer`,children:[(0,Y.jsx)(`td`,{className:`px-2 py-2`,children:(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 px-2 h-5 rounded-full text-[10px] font-medium ${n.bg} ${n.text}`,children:[(0,Y.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full ${n.dot}`}),a]})}),(0,Y.jsx)(`td`,{className:`px-2 py-2 max-w-[260px]`,children:e.ticket_id==null?e.ticket_title?(0,Y.jsx)(`span`,{className:`truncate block text-muted-foreground/90 italic`,title:o(`table.provisionalTitleTooltip`),children:e.ticket_title}):(0,Y.jsx)(`span`,{className:`text-muted-foreground/70`,children:`—`}):(0,Y.jsxs)(`span`,{className:`truncate block`,children:[`#`,e.ticket_id,` `,i?(0,Y.jsx)(`span`,{className:`text-muted-foreground/90`,children:o(`table.contractLayerRefinement`)}):e.ticket_title??(0,Y.jsx)(`span`,{className:`text-muted-foreground/70 italic`,children:o(`table.deleted`)})]})}),(0,Y.jsx)(`td`,{className:`px-2 py-2 text-right font-medium`,children:e.total_cost_usd_estimated===1&&e.total_cost_usd!=null?(0,Y.jsxs)(`span`,{title:o(`table.estimatedCostTooltip`),className:`text-muted-foreground/90`,children:[`~`,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:[s??`—`,s&&!e.model?(0,Y.jsx)(`span`,{className:`ml-1 text-[10px] text-muted-foreground/70`,children:o(`table.inferred`)}):null]}),f&&(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:o(`table.statusValue.${e.status}`)})]}),(0,Y.jsx)(`td`,{className:`px-2 py-2 text-muted-foreground`,children:e.started_at.slice(0,16).replace(`T`,` `)})]},e.id)})})]})}),p&&e.length>0&&(0,Y.jsx)(`div`,{className:`mt-2 text-[11px] text-muted-foreground/80`,children:o(`table.truncated`,{shown:e.length,total:r.toLocaleString()})})]})}var 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}=s(`analytics`),{activeProjectId:t,projects:n}=h(),[r,a]=l(),u=n.find(e=>e.id===t),f=u?d(u):[`claude`],p=f.length>1,m=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:m,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(`,`))),a(e,{replace:!0})},[C.period,C.surface,C.provider,C.ticketId,C.model,C.modelKeys,a]);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=c();(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)(i,{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))}),p&&(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`)}),f.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:o(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)(i,{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};