specrails-hub 1.54.3 → 1.55.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -5
- package/client/dist/assets/{ActivityFeedPage-Bst7JQBD.js → ActivityFeedPage-BDXiLxvY.js} +1 -1
- package/client/dist/assets/{AgentsPage-CQSsFPUf.js → AgentsPage-DE3qXlQo.js} +2 -2
- package/client/dist/assets/AnalyticsPage-xejLx2IR.js +1 -0
- package/client/dist/assets/{BarChart-D0Js4qm-.js → BarChart-DX0CY_mx.js} +1 -1
- package/client/dist/assets/{DocsDialog-Dx-XFezQ.js → DocsDialog-yqbYur_U.js} +1 -1
- package/client/dist/assets/{DocsPage-DBe0KLC6.js → DocsPage-Bs4zmSgP.js} +1 -1
- package/client/dist/assets/{ExportDropdown-CHJbkux7.js → ExportDropdown-Bndfxa-s.js} +1 -1
- package/client/dist/assets/{HubAnalyticsPage-CExwOxYs.js → HubAnalyticsPage-gg956SNq.js} +1 -1
- package/client/dist/assets/IntegrationsPage-AXITR_fK.js +3 -0
- package/client/dist/assets/JobDetailPage-8PF2PEUV.js +16 -0
- package/client/dist/assets/JobsPage-C_cTJ2-l.js +1 -0
- package/client/dist/assets/{dist-js-BNqVf1xQ.js → dist-js-DTXcnjXE.js} +1 -1
- package/client/dist/assets/{dist-js-CEpsPzWv.js → dist-js-DwmgoHUT.js} +1 -1
- package/client/dist/assets/format-command-BEuLCUdd.js +1 -0
- package/client/dist/assets/index-DtoMOtcd.css +2 -0
- package/client/dist/assets/index-P2hinGr2.js +139 -0
- package/client/dist/assets/{lib-CKFRx_1H.js → lib-BSpHCAvi.js} +1 -1
- package/client/dist/assets/{useProjectCache-bmnxPDIP.js → useProjectCache-CTroRmR4.js} +1 -1
- package/client/dist/index.html +10 -3
- package/docs/adding-a-provider.md +159 -0
- package/docs/codex.md +148 -0
- package/package.json +1 -1
- package/server/dist/agent-refine-manager.js +65 -62
- package/server/dist/ai-invocations.js +40 -4
- package/server/dist/chat-manager.js +142 -216
- package/server/dist/codex-otel-bridge.js +235 -0
- package/server/dist/command-resolver.js +38 -0
- package/server/dist/contract-refine-runner.js +28 -1
- package/server/dist/core-compat.js +34 -27
- package/server/dist/db.js +76 -1
- package/server/dist/explore-cwd-manager.js +45 -18
- package/server/dist/hub-router.js +24 -9
- package/server/dist/index.js +5 -0
- package/server/dist/plugin-manager.js +70 -26
- package/server/dist/plugins/claude-md-mutation.js +35 -17
- package/server/dist/plugins/codex-mcp.js +108 -0
- package/server/dist/plugins/contributors.js +31 -15
- package/server/dist/plugins/serena/install.js +63 -9
- package/server/dist/plugins/serena/manifest.js +39 -0
- package/server/dist/plugins-router.js +6 -6
- package/server/dist/pricing.js +81 -0
- package/server/dist/profile-manager.js +38 -6
- package/server/dist/project-registry.js +1 -1
- package/server/dist/project-router.js +124 -59
- package/server/dist/providers/claude-adapter.js +273 -0
- package/server/dist/providers/codex-adapter.js +259 -0
- package/server/dist/providers/index.js +23 -0
- package/server/dist/providers/registry.js +37 -0
- package/server/dist/providers/types.js +22 -0
- package/server/dist/queue-manager.js +180 -103
- package/server/dist/result-event.js +69 -7
- package/server/dist/schemas/profile.v1.json +9 -3
- package/server/dist/setup-manager.js +255 -190
- package/server/dist/setup-prerequisites.js +57 -0
- package/server/dist/smash-runner.js +2 -0
- package/server/dist/spending.js +23 -0
- package/server/dist/util/cli-prompt.js +13 -6
- package/client/dist/assets/AnalyticsPage-BXSGt62I.js +0 -1
- package/client/dist/assets/IntegrationsPage-Cq0TXYaZ.js +0 -3
- package/client/dist/assets/JobDetailPage-C00ccK2a.js +0 -16
- package/client/dist/assets/JobsPage-BgrKbNeS.js +0 -1
- package/client/dist/assets/index-KaHNgvWR.css +0 -2
- package/client/dist/assets/index-NFgJciDY.js +0 -140
package/README.md
CHANGED
|
@@ -10,13 +10,13 @@ It's a local-first companion to [specrails-core](https://github.com/fjpulidop/sp
|
|
|
10
10
|
|
|
11
11
|
## What you can do with it
|
|
12
12
|
|
|
13
|
-
- **Draft a spec by talking to Claude** — open Explore, describe what you want; the live draft updates each turn. Save it as a draft and come back later, or commit when it looks right.
|
|
13
|
+
- **Draft a spec by talking to Claude or Codex** — open Explore, describe what you want; the live draft updates each turn. Save it as a draft and come back later, or commit when it looks right.
|
|
14
14
|
- **Generate a spec in one shot** — Quick mode for when you already know what you want. Optionally enrich it with a "Contract Layer" of names, shapes, invariants, and a file touch list.
|
|
15
15
|
- **Drag specs onto execution rails** — each rail is an independent lane. Run multiple specs in parallel, with different agent profiles per rail.
|
|
16
16
|
- **Compare two specs side by side** — drag any spec modal to the edge of the screen; a picker of your todo specs appears on the other side. Pick one and they live next to each other. Tablet-style.
|
|
17
17
|
- **Split a big epic** — SMASH a parent spec into a family of sub-specs in one click; the children carry short summaries on their cards.
|
|
18
18
|
- **Refine a spec in place** — *Continue Editing* reopens any draft / todo / backlog spec in Explore, with the original conversation resumed if there was one.
|
|
19
|
-
- **Track every AI cost** — every
|
|
19
|
+
- **Track every AI cost** — every AI CLI invocation across rails, Quick spec, Explore turns, and AI edits is recorded — across **both** Claude and Codex. Codex cost is estimated from a local rate-card since the CLI doesn't report it natively. The Analytics page shows your burn rate, top tickets, breaks down spend per provider, and lets you export CSV.
|
|
20
20
|
- **Customise everything** — three themes, font sizes, terminal preferences, agent profiles, plugin integrations (Serena bundled today).
|
|
21
21
|
|
|
22
22
|
## How specrails-hub looks
|
|
@@ -61,12 +61,20 @@ If the project doesn't have specrails-core yet, the setup wizard walks you throu
|
|
|
61
61
|
|
|
62
62
|
## Prerequisites
|
|
63
63
|
|
|
64
|
-
- **Node.js 20+**
|
|
65
|
-
-
|
|
64
|
+
- **Node.js 20+** (specrails-core ≥ 4.6.0 for codex projects; ≥ 4.2.0 for claude-only)
|
|
65
|
+
- **At least one AI CLI** on your PATH:
|
|
66
|
+
- **[Claude Code](https://claude.com/claude-code)** — `claude` binary. Set `ANTHROPIC_API_KEY` to authenticate.
|
|
67
|
+
- **[Codex CLI](https://developers.openai.com/codex)** ≥ 0.128.0 — `codex` binary. Run `codex login` or set `OPENAI_API_KEY`.
|
|
66
68
|
- **`git`**
|
|
67
69
|
- (Optional) **`uv`** if you want to use the Serena plugin
|
|
68
70
|
|
|
69
|
-
|
|
71
|
+
The provider is chosen per-project at install time and is immutable after
|
|
72
|
+
creation. On macOS, the desktop app handles Homebrew/Volta/nvm paths
|
|
73
|
+
automatically — see [docs/platforms/macos.md](docs/platforms/macos.md).
|
|
74
|
+
**Windows users:** see [docs/windows.md](docs/windows.md) for Windows
|
|
75
|
+
10/11 specifics. For Codex-specific topics — auth, sandbox config,
|
|
76
|
+
estimated cost caveats, plugin support, and emergency rollback — see
|
|
77
|
+
[docs/codex.md](docs/codex.md).
|
|
70
78
|
|
|
71
79
|
## Documentation
|
|
72
80
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./chunk-CilyBKbf.js";import{L as t,St as n,Vt as r,Z as i,_t as a,bt as o,ot as s,st as c,vt as l,xt as u,yt as d}from"./index-
|
|
1
|
+
import{r as e}from"./chunk-CilyBKbf.js";import{L as t,St as n,Vt as r,Z as i,_t as a,bt as o,ot as s,st as c,vt as l,xt as u,yt as d}from"./index-P2hinGr2.js";var f=l(`ban`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M4.929 4.929 19.07 19.071`,key:`196cmz`}]]),p=e(r(),1);function m(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 h({activeProjectId:e,limit:t=50}){let[r,i]=(0,p.useState)([]),[a,s]=(0,p.useState)(!1),[c,l]=(0,p.useState)(!0),u=(0,p.useRef)(e);(0,p.useEffect)(()=>{u.current=e},[e]);let{registerHandler:d,unregisterHandler:f}=o();(0,p.useEffect)(()=>{if(!e){i([]),l(!0);return}let r=!1;s(!0),i([]),l(!0);async function a(){let e=n();try{let n=await fetch(`${e}/activity?limit=${t}`);if(!n.ok||r)return;let a=await n.json();if(r)return;i(a),l(a.length===t)}catch{}finally{r||s(!1)}}return a(),()=>{r=!0}},[e,t]);let h=(0,p.useCallback)(async()=>{if(a||!c)return;s(!0);let e=n();try{i(n=>{let r=n[n.length-1];if(!r)return n;let a=encodeURIComponent(r.timestamp);return fetch(`${e}/activity?limit=${t}&before=${a}`).then(e=>e.json()).then(e=>{i(t=>m([...t,...e])),l(e.length===t),s(!1)}).catch(()=>s(!1)),n})}catch{s(!1)}},[a,c,t]),g=(0,p.useCallback)(e=>{let t=e,n=u.current;if(!(!t||typeof t.type!=`string`)&&!(t.projectId&&t.projectId!==n)){if(t.type===`queue`&&Array.isArray(t.jobs)){let e=[];for(let n of t.jobs){let t=n.status===`completed`?`job_completed`:n.status===`failed`?`job_failed`:n.status===`canceled`?`job_canceled`:`job_started`;e.push({id:`${t}:${n.id}`,type:t,jobId:n.id,jobCommand:n.command??``,timestamp:n.startedAt??new Date().toISOString(),summary:`${t.replace(`_`,` `)}: ${n.command??``}`,costUsd:null})}e.length>0&&i(t=>m([...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:`Phase: ${t.phase} → ${t.state}`,timestamp:t.timestamp,summary:`Phase ${t.phase} is ${t.state}`,costUsd:null};i(t=>m([e,...t]))}}},[]);return(0,p.useLayoutEffect)(()=>(d(`activity`,g),()=>f(`activity`)),[g,d,f]),{items:r,loading:a,hasMore:c,loadMore:h}}var g=u();function _(e){let t=Date.now()-new Date(e).getTime(),n=Math.floor(t/1e3);if(n<60)return`${n}s ago`;let r=Math.floor(n/60);if(r<60)return`${r}m ago`;let i=Math.floor(r/60);return i<24?`${i}h ago`:`${Math.floor(i/24)}d ago`}function v({type:e}){switch(e){case`job_completed`:return(0,g.jsx)(c,{className:`w-4 h-4 text-green-500 flex-shrink-0`});case`job_failed`:return(0,g.jsx)(s,{className:`w-4 h-4 text-red-500 flex-shrink-0`});case`job_canceled`:return(0,g.jsx)(f,{className:`w-4 h-4 text-muted-foreground flex-shrink-0`});default:return(0,g.jsx)(t,{className:`w-4 h-4 text-blue-500 flex-shrink-0`})}}function y(e){switch(e){case`job_completed`:return`Completed`;case`job_failed`:return`Failed`;case`job_canceled`:return`Canceled`;default:return`Started`}}function b(e){switch(e){case`job_completed`:return`text-green-500`;case`job_failed`:return`text-red-500`;case`job_canceled`:return`text-muted-foreground`;default:return`text-blue-500`}}function x(){let{activeProjectId:e}=d(),{items:t,loading:n,hasMore:r,loadMore:o}=h({activeProjectId:e}),s=(0,p.useRef)(null);return(0,p.useEffect)(()=>{let e=s.current;if(!e)return;let t=new IntersectionObserver(e=>{e[0].isIntersecting&&r&&!n&&o()},{threshold:.1});return t.observe(e),()=>t.disconnect()},[r,n,o]),(0,g.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,g.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-3 border-b border-border bg-background/50`,children:[(0,g.jsx)(a,{className:`w-4 h-4 text-muted-foreground`}),(0,g.jsx)(`h1`,{className:`text-sm font-medium`,children:`Activity`})]}),(0,g.jsxs)(`div`,{className:`flex-1 overflow-y-auto`,children:[n&&t.length===0?(0,g.jsx)(`div`,{className:`flex items-center justify-center h-32`,children:(0,g.jsx)(i,{className:`w-4 h-4 animate-spin text-muted-foreground`})}):t.length===0?(0,g.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-48 gap-2 text-muted-foreground`,children:[(0,g.jsx)(a,{className:`w-8 h-8 opacity-40`}),(0,g.jsx)(`p`,{className:`text-sm`,children:`No activity yet`}),(0,g.jsx)(`p`,{className:`text-xs opacity-70`,children:`Job events will appear here when jobs run`})]}):(0,g.jsx)(`ul`,{className:`divide-y divide-border/50`,children:t.map(e=>(0,g.jsxs)(`li`,{className:`flex items-center gap-3 px-4 py-2.5 hover:bg-accent/30 transition-colors`,children:[(0,g.jsx)(v,{type:e.type}),(0,g.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,g.jsx)(`p`,{className:`text-xs text-foreground truncate`,title:e.jobCommand,children:e.jobCommand}),(0,g.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5`,children:[(0,g.jsx)(`span`,{className:`text-xs font-medium ${b(e.type)}`,children:y(e.type)}),e.costUsd!=null&&(0,g.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`$`,e.costUsd.toFixed(4)]})]})]}),(0,g.jsx)(`span`,{className:`text-xs text-muted-foreground flex-shrink-0 tabular-nums`,children:_(e.timestamp)})]},`${e.type}:${e.jobId}`))}),(0,g.jsx)(`div`,{ref:s,className:`h-1`}),n&&t.length>0&&(0,g.jsx)(`div`,{className:`flex justify-center py-3`,children:(0,g.jsx)(i,{className:`w-4 h-4 animate-spin text-muted-foreground`})}),!r&&t.length>0&&(0,g.jsx)(`p`,{className:`text-center text-xs text-muted-foreground py-3`,children:`All activity loaded`})]})]})}export{x as default};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{r as e}from"./chunk-CilyBKbf.js";import{$ as t,A as n,At as r,B as i,Ct as a,D as o,Dt as s,E as c,Et as l,F as u,Ft as d,H as f,J as p,K as m,M as h,Mt as g,N as _,Nt as v,O as y,Ot as b,Pt as x,R as S,St as C,Tt as w,U as T,V as E,Vt as D,W as O,X as k,Y as A,Z as j,a as M,bt as N,ct as ee,dt as P,et as F,ft as I,gt as L,ht as R,j as z,jt as B,k as V,kt as H,mt as U,rt as te,tt as ne,ut as re,vt as W,wt as G,xt as ie,yt as ae,z as K}from"./index-NFgJciDY.js";var oe=W(`flask-conical`,[[`path`,{d:`M14 2v6a2 2 0 0 0 .245.96l5.51 10.08A2 2 0 0 1 18 22H6a2 2 0 0 1-1.755-2.96l5.51-10.08A2 2 0 0 0 10 8V2`,key:`18mbvz`}],[`path`,{d:`M6.453 15h11.094`,key:`3shlmq`}],[`path`,{d:`M8.5 2h7`,key:`csnxdl`}]]),q=W(`history`,[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}],[`path`,{d:`M12 7v5l4 2`,key:`1fdv2h`}]]),se=W(`pin`,[[`path`,{d:`M12 17v5`,key:`bb1du9`}],[`path`,{d:`M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z`,key:`1nkz8b`}]]),ce=W(`wand-sparkles`,[[`path`,{d:`m21.64 3.64-1.28-1.28a1.21 1.21 0 0 0-1.72 0L2.36 18.64a1.21 1.21 0 0 0 0 1.72l1.28 1.28a1.2 1.2 0 0 0 1.72 0L21.64 5.36a1.2 1.2 0 0 0 0-1.72`,key:`ul74o6`}],[`path`,{d:`m14 7 3 3`,key:`1r5n42`}],[`path`,{d:`M5 6v4`,key:`ilb8ba`}],[`path`,{d:`M19 14v4`,key:`blhpug`}],[`path`,{d:`M10 2v2`,key:`7u0qdc`}],[`path`,{d:`M7 8H3`,key:`zfb6yr`}],[`path`,{d:`M21 16h-4`,key:`1cnmox`}],[`path`,{d:`M11 3H9`,key:`1obp7u`}]]),J=e(D(),1),Y=ie(),X=/^[a-z0-9][a-z0-9-]*$/;function le({open:e,mode:t=`add`,initial:r,chainAgents:i,onConfirm:a,onCancel:s}){let[l,d]=(0,J.useState)(``),[f,p]=(0,J.useState)(i[0]??``);(0,J.useEffect)(()=>{e&&(t===`edit`&&r?(d(r.tags.join(`, `)),p(i.includes(r.agent)?r.agent:i[0]??``)):(d(``),p(i[0]??``)))},[e,t,r,i]);let m=l.split(`,`).map(e=>e.trim()).filter(Boolean),h=m.filter(e=>!X.test(e)),g=m.length>0&&h.length===0&&i.includes(f);return(0,Y.jsx)(c,{open:e,onOpenChange:e=>{e||s()},children:(0,Y.jsxs)(o,{className:`max-w-md`,children:[(0,Y.jsxs)(n,{children:[(0,Y.jsx)(z,{children:t===`edit`?`Edit routing rule`:`Add routing rule`}),(0,Y.jsx)(y,{children:t===`edit`?`Update the tags or target agent for this rule.`:`Add a tag-matched routing rule using lowercase kebab-case tags.`})]}),(0,Y.jsxs)(`div`,{className:`py-2 space-y-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Tags`}),(0,Y.jsx)(M,{autoFocus:!0,value:l,onChange:e=>d(e.target.value),placeholder:`frontend, ui`,"aria-label":`Tags`,className:`text-sm font-mono`}),(0,Y.jsxs)(`p`,{className:`text-[11px] text-muted-foreground mt-1`,children:[`Comma-separated. Use lowercase kebab-case like `,(0,Y.jsx)(`code`,{children:`frontend`}),` or `,(0,Y.jsx)(`code`,{children:`api-design`}),`.`]}),h.length>0&&(0,Y.jsxs)(`p`,{className:`text-[11px] text-red-400 mt-1`,children:[`Invalid tag`,h.length===1?``:`s`,`: `,h.join(`, `),`. Tags must use lowercase letters, digits, and hyphens only.`]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Route to`}),(0,Y.jsx)(`select`,{value:f,onChange:e=>p(e.target.value),"aria-label":`Route to`,className:`w-full h-9 px-2 text-sm rounded-md border border-border bg-background`,children:i.map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e))}),(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground mt-1`,children:`Only agents in this profile's chain can be routing targets.`})]})]}),(0,Y.jsxs)(V,{children:[(0,Y.jsx)(u,{variant:`ghost`,size:`sm`,onClick:s,children:`Cancel`}),(0,Y.jsx)(u,{size:`sm`,onClick:()=>a(m,f),disabled:!g,children:t===`edit`?`Save changes`:`Add rule`})]})]})})}var Z=new Set([`sr-architect`,`sr-developer`,`sr-reviewer`,`sr-merge-resolver`]),ue=[`sonnet`,`opus`,`haiku`],de=/^[a-z0-9][a-z0-9-]*$/;function fe({profile:e,onChange:t,footer:n,onValidityChange:i,onSoftWarningsChange:o}){let[c,l]=(0,J.useState)([]),[d,f]=(0,J.useState)(!1),[m,h]=(0,J.useState)(!1),[_,y]=(0,J.useState)(null);(0,J.useEffect)(()=>{let e=!1;return fetch(`${C()}/profiles/catalog`).then(e=>e.ok?e.json():{agents:[]}).then(t=>{e||l(t.agents)}).catch(()=>{e||l([])}),()=>{e=!0}},[]);let x=n=>{let r=JSON.parse(JSON.stringify(e));n(r),t(r)},T=new Set(e.agents.map(e=>e.id)),E=c.filter(e=>!T.has(e.id)),D=(0,J.useMemo)(()=>{let t=[];for(let n of Z)e.agents.some(e=>e.id===n)||t.push(`Missing required baseline agent: ${n}`);let n=e.routing.filter(e=>`default`in e&&e.default===!0);if(n.length>1&&t.push(`Routing may have at most one default rule (found ${n.length})`),n.length===1){let n=e.routing[e.routing.length-1];`default`in n&&n.default===!0||t.push(`The default routing rule must be the last entry`)}for(let n of e.routing)if(e.agents.some(e=>e.id===n.agent)||t.push(`Routing references agent not in the chain: ${n.agent}`),`tags`in n){let e=n.tags.filter(e=>!de.test(e));e.length>0&&t.push(`Routing rule ${n.agent} has invalid tags: ${e.join(`, `)} (use lowercase kebab-case)`)}return t},[e]),O=(0,J.useMemo)(()=>{if(e.routing.length===0)return[];let t=new Set(e.routing.map(e=>e.agent));return e.agents.filter(e=>!Z.has(e.id)&&!t.has(e.id)).map(e=>e.id)},[e]),k=(0,J.useMemo)(()=>e.routing.some(e=>`default`in e&&e.default===!0),[e.routing]);(0,J.useEffect)(()=>{i&&i(D)},[D,i]),(0,J.useEffect)(()=>{o&&o({agentsMissingRouting:O})},[O,o]);let A=e=>{x(t=>{let n={id:e,model:`sonnet`},r=t.agents.findIndex(e=>e.id===`sr-merge-resolver`);r>=0?t.agents.splice(r,0,n):t.agents.push(n)}),f(!1)},j=t=>{let n=e.agents[t];Z.has(n.id)||x(e=>{e.agents.splice(t,1),e.routing=e.routing.filter(e=>e.agent!==n.id)})},N=(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=G(e.agents,r,i),o=a.findIndex(e=>e.id===`sr-architect`);if(o>0){let[e]=a.splice(o,1);a.unshift(e)}let s=a.findIndex(e=>e.id===`sr-merge-resolver`);if(s>=0&&s!==a.length-1){let[e]=a.splice(s,1);a.push(e)}x(e=>{e.agents=a})},ee=v(g(r,{activationConstraint:{distance:4}}),g(H,{coordinateGetter:w})),P=e=>{let{active:t,over:n}=e;n&&N(String(t.id),String(n.id))},F=(e,t)=>{x(n=>{n.agents[e].model=t})},I=(e,t)=>{x(n=>{let r={tags:e,agent:t},i=n.routing.findIndex(e=>`default`in e&&e.default===!0);i>=0?n.routing.splice(i,0,r):n.routing.push(r)}),h(!1)},L=()=>{x(e=>{e.routing.some(e=>`default`in e&&e.default===!0)||e.agents.some(e=>e.id===`sr-developer`)&&e.routing.push({default:!0,agent:`sr-developer`})})},R=e=>`default`in e&&e.default===!0,z=(e,t)=>{x(n=>{let r=n.routing[e];r&&(R(r)||(r.agent=t))})},V=(e,t,n)=>{x(r=>{let i=r.routing[e];i&&(R(i)||(i.tags=t,i.agent=n))})},U=e=>{x(t=>{let n=t.routing[e];n&&(R(n)||t.routing.splice(e,1))})},te=(t,n)=>{let r=t+n;if(r<0||r>=e.routing.length)return;let i=e.routing[t],a=e.routing[r];R(i)||R(a)||x(e=>{let[n]=e.routing.splice(t,1);e.routing.splice(r,0,n)})};return(0,Y.jsxs)(`div`,{className:`p-6 space-y-6 max-w-3xl`,children:[(0,Y.jsx)(le,{open:m,mode:`add`,chainAgents:e.agents.map(e=>e.id),onConfirm:I,onCancel:()=>h(!1)}),(0,Y.jsx)(le,{open:_!==null,mode:`edit`,initial:_!==null&&e.routing[_]&&!(`default`in e.routing[_])?{tags:e.routing[_].tags,agent:e.routing[_].agent}:void 0,chainAgents:e.agents.map(e=>e.id),onConfirm:(e,t)=>{_!==null&&(V(_,e,t),y(null))},onCancel:()=>y(null)}),D.length>0&&(0,Y.jsxs)(`div`,{className:`px-3 py-2 text-xs rounded-md border border-yellow-500/30 bg-yellow-500/10 text-yellow-500`,children:[(0,Y.jsxs)(`div`,{className:`font-medium mb-1`,children:[D.length,` validation `,D.length===1?`issue`:`issues`]}),(0,Y.jsx)(`ul`,{className:`list-disc list-inside space-y-0.5`,children:D.map((e,t)=>(0,Y.jsx)(`li`,{children:e},t))})]}),(0,Y.jsxs)(`section`,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Name`}),(0,Y.jsx)(M,{value:e.name,disabled:!0,className:`text-sm`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Description`}),(0,Y.jsx)(M,{value:e.description??``,onChange:e=>x(t=>{t.description=e.target.value}),className:`text-sm`,placeholder:`What is this profile for?`})]})]}),(0,Y.jsxs)(`section`,{children:[(0,Y.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide mb-2`,children:`Orchestrator`}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 p-3 rounded-md border border-border`,children:[(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-mono text-foreground truncate`,children:`/specrails:implement · /specrails:batch-implement`}),(0,Y.jsx)(`div`,{className:`text-[11px] text-muted-foreground mt-0.5`,children:`Top-level model for both commands. batch-implement delegates to implement per feature, so every rail it spawns inherits this profile's agent chain.`})]}),(0,Y.jsx)(he,{value:e.orchestrator.model,onChange:e=>x(t=>{t.orchestrator.model=e})})]})]}),(0,Y.jsxs)(`section`,{children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,Y.jsxs)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:[`Agent chain (`,e.agents.length,`)`]}),(0,Y.jsxs)(u,{size:`sm`,variant:`ghost`,onClick:()=>f(e=>!e),disabled:E.length===0,title:E.length===0?`All catalog agents are already in the chain`:`Add an agent from the catalog`,children:[(0,Y.jsx)(p,{className:`w-3.5 h-3.5 mr-1`}),` Add`]})]}),d&&(0,Y.jsxs)(`div`,{className:`mb-2 p-2 rounded-md border border-border bg-muted/30`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mb-1.5 px-1`,children:[(0,Y.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,children:[`Pick from catalog (`,E.length,` available)`]}),(0,Y.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:()=>f(!1),title:`Close`,children:(0,Y.jsx)(S,{className:`w-3 h-3`})})]}),E.length===0?(0,Y.jsx)(`div`,{className:`px-2 py-3 text-xs text-muted-foreground text-center`,children:`No more agents in the catalog. Add custom agents from the Agents Catalog tab.`}):(0,Y.jsx)(`div`,{className:`space-y-0.5 max-h-64 overflow-auto`,children:E.map(e=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>A(e.id),className:`w-full flex items-center justify-between gap-2 px-2 py-1.5 text-left rounded hover:bg-accent transition-colors`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-mono`,children:e.id}),(0,Y.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded `+(e.kind===`custom`?`bg-purple-500/15 text-purple-400`:`bg-muted text-muted-foreground`),children:e.kind})]},e.id))})]}),(0,Y.jsx)(b,{sensors:ee,collisionDetection:B,onDragEnd:P,children:(0,Y.jsx)(a,{items:e.agents.map(e=>e.id),strategy:s,children:(0,Y.jsx)(`div`,{className:`space-y-1.5`,children:e.agents.map((e,t)=>(0,Y.jsx)(pe,{agent:e,canRemove:!Z.has(e.id),onModel:e=>F(t,e),onRemove:()=>j(t)},e.id))})})})]}),(0,Y.jsxs)(`section`,{children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,Y.jsxs)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:[`Routing (`,e.routing.length,`)`]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[!k&&(0,Y.jsxs)(u,{size:`sm`,variant:`ghost`,onClick:L,disabled:e.agents.length===0,title:e.agents.length===0?`Add at least one agent before creating routing rules`:void 0,children:[(0,Y.jsx)(p,{className:`w-3.5 h-3.5 mr-1`}),` Add default`]}),(0,Y.jsxs)(u,{size:`sm`,variant:`ghost`,onClick:()=>h(!0),disabled:e.agents.length===0,title:e.agents.length===0?`Add at least one agent before creating routing rules`:void 0,children:[(0,Y.jsx)(p,{className:`w-3.5 h-3.5 mr-1`}),` Add rule`]})]})]}),(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground mb-2`,children:`First matching rule wins. Rules are editable and removable, and the default catch-all stays last when present. If you leave routing empty, the pipeline falls back to the first developer-shaped agent in the chain.`}),O.length>0&&(0,Y.jsxs)(`div`,{className:`mb-2 px-3 py-2 text-xs rounded-md border border-yellow-500/30 bg-yellow-500/10 text-yellow-500`,children:[(0,Y.jsx)(`div`,{className:`font-medium mb-1`,children:`Untargeted agents in the chain`}),(0,Y.jsxs)(`div`,{children:[`No routing rule points to: `,(0,Y.jsx)(`span`,{className:`font-mono`,children:O.join(`, `)}),`. Add a tag rule or retarget the default rule if you want them to run.`]})]}),(0,Y.jsx)(`div`,{className:`space-y-1.5`,children:e.routing.map((t,n)=>{let r=`default`in t&&t.default===!0;return(0,Y.jsx)(me,{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=>z(n,e),onEdit:()=>y(n),onUp:()=>te(n,-1),onDown:()=>te(n,1),onRemove:()=>U(n)},n)})})]}),n&&(0,Y.jsx)(`div`,{className:`pt-3 border-t border-border`,children:n})]})}function pe({agent:e,canRemove:n,onModel:r,onRemove:i}){let a=Z.has(e.id),o=e.id===`sr-architect`,s=e.id===`sr-merge-resolver`,{attributes:c,listeners:u,setNodeRef:d,transform:f,transition:p,isDragging:m}=l({id:e.id});return(0,Y.jsxs)(`div`,{ref:d,style:{transform:x.Transform.toString(f),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,Y.jsx)(`button`,{type:`button`,className:`flex-shrink-0 p-0.5 rounded text-muted-foreground cursor-grab active:cursor-grabbing hover:text-foreground`,title:`Drag to reorder`,"aria-label":`Drag handle`,...c,...u,children:(0,Y.jsx)(t,{className:`w-3.5 h-3.5`})}),(0,Y.jsx)(`span`,{className:`text-sm font-mono flex-1 truncate`,children:e.id}),o&&(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded bg-accent-primary/15 text-accent-primary`,title:`Pinned to first position — pipeline always starts with sr-architect`,children:[(0,Y.jsx)(se,{className:`w-2.5 h-2.5 rotate-[135deg]`}),` first`]}),s&&(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded bg-accent-primary/15 text-accent-primary`,title:`Pinned to last position — merge phase always runs last`,children:[(0,Y.jsx)(se,{className:`w-2.5 h-2.5 rotate-45`}),` last`]}),a&&!o&&!s&&(0,Y.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:`required`}),(0,Y.jsx)(he,{value:e.model??`sonnet`,onChange:r}),(0,Y.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-red-500/20 text-red-400 rounded disabled:opacity-30 disabled:cursor-not-allowed opacity-0 group-hover:opacity-100 transition-opacity`,onClick:i,disabled:!n,title:n?`Remove`:`Required baseline agent — the pipeline depends on this row`,children:(0,Y.jsx)(S,{className:`w-3 h-3`})})]})}function me({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 f=`default`in e&&e.default===!0;return(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 rounded-md border border-border group hover:bg-accent/30 transition-colors`,children:[(0,Y.jsxs)(`span`,{className:`text-[10px] font-mono text-muted-foreground w-5 text-center flex-shrink-0`,children:[t,`.`]}),f?(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground flex-1`,children:`everything else`}):(0,Y.jsx)(`span`,{className:`text-xs flex-1 flex gap-1 flex-wrap items-center`,children:e.tags.map(e=>(0,Y.jsx)(`span`,{className:`px-1.5 py-0.5 rounded bg-muted font-mono text-[11px]`,children:e},e))}),(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`→`}),f?(0,Y.jsx)(`span`,{className:`h-7 max-w-[15rem] px-2 text-xs font-mono rounded border border-border bg-muted/40 text-muted-foreground inline-flex items-center`,"aria-label":`Default routing target (core, read-only)`,title:`Core fallback — not editable`,children:e.agent}):(0,Y.jsx)(`select`,{value:e.agent,onChange:e=>s(e.target.value),"aria-label":`Routing target for rule ${t}`,className:`h-7 max-w-[15rem] px-2 text-xs font-mono rounded border border-border bg-background`,children:o.map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e))}),(0,Y.jsxs)(`div`,{className:`flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity`,children:[a&&(0,Y.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:c,title:`Edit rule`,"aria-label":`Edit rule ${t}`,children:(0,Y.jsx)(A,{className:`w-3 h-3`})}),r&&!n&&(0,Y.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:u,title:`Move down`,children:(0,Y.jsx)(L,{className:`w-3 h-3`})}),r&&t>1&&(0,Y.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:l,title:`Move up`,children:(0,Y.jsx)(U,{className:`w-3 h-3`})}),i&&(0,Y.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-red-500/20 text-red-400 rounded`,onClick:d,title:`Remove`,children:(0,Y.jsx)(S,{className:`w-3 h-3`})})]}),f&&(0,Y.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,title:`Core fallback — the pipeline's last-resort rule, pinned to sr-developer`,children:`core · default`})]})}function he({value:e,onChange:t}){return(0,Y.jsx)(`select`,{value:e,onChange:e=>t(e.target.value),className:`h-7 px-2 text-xs rounded border border-border bg-background`,children:ue.map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e))})}function ge({open:e,title:t,description:r,placeholder:i,initialValue:a=``,confirmLabel:s=`Confirm`,inputPattern:l,inputInvalidHint:d,onConfirm:f,onCancel:p}){let[m,h]=(0,J.useState)(a);(0,J.useEffect)(()=>{e&&h(a)},[e,a]);let g=m.trim(),_=!l||l.test(g),v=g.length>0&&_;return(0,Y.jsx)(c,{open:e,onOpenChange:e=>{e||p()},children:(0,Y.jsxs)(o,{className:`max-w-md`,children:[(0,Y.jsx)(n,{children:(0,Y.jsx)(z,{children:t})}),(0,Y.jsxs)(`div`,{className:`py-2 space-y-2`,children:[r&&(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r}),(0,Y.jsx)(M,{autoFocus:!0,value:m,placeholder:i,onChange:e=>h(e.target.value),onKeyDown:e=>{e.key===`Enter`&&v&&f(g)},className:`text-sm font-mono`}),g.length>0&&!_&&d&&(0,Y.jsx)(`p`,{className:`text-[11px] text-yellow-500`,children:d})]}),(0,Y.jsxs)(V,{children:[(0,Y.jsx)(u,{variant:`ghost`,size:`sm`,onClick:p,children:`Cancel`}),(0,Y.jsx)(u,{size:`sm`,onClick:()=>f(g),disabled:!v,children:s})]})]})})}function _e({open:e,title:t,description:r,confirmLabel:i=`Confirm`,destructive:a=!1,onConfirm:s,onCancel:l}){return(0,Y.jsx)(c,{open:e,onOpenChange:e=>{e||l()},children:(0,Y.jsxs)(o,{className:`max-w-md`,children:[(0,Y.jsx)(n,{children:(0,Y.jsx)(z,{children:t})}),r&&(0,Y.jsx)(`div`,{className:`py-2`,children:(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r})}),(0,Y.jsxs)(V,{children:[(0,Y.jsx)(u,{variant:`ghost`,size:`sm`,onClick:l,children:`Cancel`}),(0,Y.jsx)(u,{size:`sm`,onClick:s,className:a?`bg-red-500 hover:bg-red-600 text-white`:void 0,children:i})]})]})})}function ve(){let[e,t]=(0,J.useState)([]),[n,r]=(0,J.useState)(null),[a,o]=(0,J.useState)(null),[s,c]=(0,J.useState)(!0),[l,f]=(0,J.useState)(null),[m,h]=(0,J.useState)(!1),[g,_]=(0,J.useState)([]),[v,y]=(0,J.useState)([]),[b,x]=(0,J.useState)(!1),[S,w]=(0,J.useState)(null),[T,E]=(0,J.useState)(null),D=(0,J.useCallback)(async()=>{c(!0),f(null);try{let e=await fetch(`${C()}/profiles`);if(!e.ok)throw Error(`List failed: ${e.status}`);let i=await e.json();t(i.profiles),i.profiles.length>0&&!n&&r(i.profiles[0].name)}catch(e){f(e.message)}finally{c(!1)}},[n]);(0,J.useEffect)(()=>{D()},[D]),(0,J.useEffect)(()=>{if(!n){o(null);return}let e=!1;return fetch(`${C()}/profiles/${encodeURIComponent(n)}`).then(e=>{if(!e.ok)throw Error(`Load failed: ${e.status}`);return e.json()}).then(t=>{e||o(t.profile)}).catch(t=>{e||f(t.message)}),()=>{e=!0}},[n]);let k=(0,J.useCallback)(async()=>{h(!0),f(null);try{let e=await fetch(`${C()}/profiles/migrate-from-settings`,{method:`POST`});if(!e.ok){let t=await e.json().catch(()=>({}));throw Error(t.error??`Migration failed: ${e.status}`)}await D(),r(`default`),d.success(`Profile migrated`,{description:`default profile created from your current agents`})}catch(e){let t=e.message;f(t),d.error(`Migration failed`,{description:t})}finally{h(!1)}},[D]),A=(0,J.useCallback)(async e=>{x(!1),h(!0),f(null);try{let t={schemaVersion:1,name:e,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`}]},n=await fetch(`${C()}/profiles`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)});if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(e.error??`Create failed: ${n.status}`)}await D(),r(e),d.success(`Profile created`,{description:e})}catch(e){let t=e.message;f(t),d.error(`Failed to create profile`,{description:t})}finally{h(!1)}},[D]),j=(0,J.useCallback)(async(e,t)=>{w(null),h(!0),f(null);try{let n=await fetch(`${C()}/profiles/${encodeURIComponent(e)}/duplicate`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:t})});if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(e.error??`Duplicate failed: ${n.status}`)}await D(),r(t),d.success(`Profile duplicated`,{description:`${e} → ${t}`})}catch(e){let t=e.message;f(t),d.error(`Failed to duplicate profile`,{description:t})}finally{h(!1)}},[D]),M=(0,J.useCallback)(async e=>{E(null),h(!0),f(null);try{let t=await fetch(`${C()}/profiles/${encodeURIComponent(e)}`,{method:`DELETE`});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error??`Delete failed: ${t.status}`)}r(t=>t===e?null:t),await D(),d.success(`Profile deleted`,{description:e})}catch(e){let t=e.message;f(t),d.error(`Failed to delete profile`,{description:t})}finally{h(!1)}},[D]),N=(0,J.useCallback)(()=>x(!0),[]),ee=(0,J.useCallback)(e=>w({from:e}),[]),P=(0,J.useCallback)(e=>E({name:e}),[]),F=(0,J.useCallback)(async(e,t)=>{h(!0),f(null);try{let n=await fetch(`${C()}/profiles/${encodeURIComponent(e.name)}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)});if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(e.error??`Save failed: ${n.status}`)}o(e),t.length>0?d.warning(`Profile saved with untargeted agents`,{description:`No routing rule points to: ${t.join(`, `)}. Add a tag rule or retarget the default rule if you want them to run.`,duration:6e3}):d.success(`Profile saved`,{description:e.name})}catch(e){let t=e.message;f(t),d.error(`Failed to save profile`,{description:t})}finally{h(!1)}},[]),I=(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(ge,{open:b,title:`New profile`,description:`Pick a lowercase kebab-case name (letters, digits, and hyphens).`,placeholder:`my-profile`,confirmLabel:`Create`,inputPattern:/^[a-z0-9][a-z0-9-]*$/,inputInvalidHint:`Must start with a letter or digit and contain only lowercase letters, digits, and hyphens.`,onConfirm:e=>void A(e),onCancel:()=>x(!1)}),S&&(0,Y.jsx)(ge,{open:!0,title:`Duplicate "${S.from}"`,description:`Name for the new profile.`,placeholder:`${S.from}-copy`,initialValue:`${S.from}-copy`,confirmLabel:`Duplicate`,inputPattern:/^[a-z0-9][a-z0-9-]*$/,inputInvalidHint:`Lowercase kebab-case only.`,onConfirm:e=>void j(S.from,e),onCancel:()=>w(null)}),T&&(0,Y.jsx)(_e,{open:!0,title:`Delete profile "${T.name}"?`,description:`This cannot be undone. Jobs already launched with this profile keep their snapshot; future launches will fall back to the resolution order.`,confirmLabel:`Delete`,destructive:!0,onConfirm:()=>void M(T.name),onCancel:()=>E(null)})]});return s?(0,Y.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading profiles…`})}):e.length===0?(0,Y.jsxs)(Y.Fragment,{children:[I,(0,Y.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,Y.jsxs)(`div`,{className:`text-center max-w-md`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:`No profiles yet`}),(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground mt-1 mb-4`,children:`Profiles let you save orchestrator + agent + routing combinations and pick one per rail.`}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 justify-center`,children:[(0,Y.jsxs)(u,{size:`sm`,onClick:k,disabled:m,children:[(0,Y.jsx)(ce,{className:`w-3.5 h-3.5 mr-1.5`}),` Migrate from current agents`]}),(0,Y.jsxs)(u,{size:`sm`,variant:`ghost`,onClick:N,disabled:m,children:[(0,Y.jsx)(p,{className:`w-3.5 h-3.5 mr-1.5`}),` Blank profile`]})]}),(0,Y.jsxs)(`div`,{className:`text-[11px] text-muted-foreground/70 mt-3`,children:[`"Migrate" reads your existing `,(0,Y.jsx)(`code`,{className:`text-foreground`,children:`.claude/agents/`}),` `,`frontmatter models and creates a `,(0,Y.jsx)(`code`,{className:`text-foreground`,children:`default`}),` profile mirroring today's behavior — zero-loss.`]}),l&&(0,Y.jsx)(`div`,{className:`mt-3 text-xs text-red-400`,children:l})]})})]}):(0,Y.jsxs)(`div`,{className:`flex flex-col h-full`,children:[I,(0,Y.jsxs)(`div`,{className:`flex flex-1 min-h-0`,children:[(0,Y.jsxs)(`aside`,{className:`w-64 flex-shrink-0 border-r border-border flex flex-col`,children:[(0,Y.jsxs)(`div`,{className:`p-3 flex items-center justify-between`,children:[(0,Y.jsx)(`div`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:`Profiles`}),(0,Y.jsx)(u,{size:`sm`,variant:`ghost`,onClick:N,disabled:m,children:(0,Y.jsx)(p,{className:`w-3.5 h-3.5`})})]}),(0,Y.jsx)(`div`,{className:`flex-1 overflow-auto px-2 pb-3`,children:e.map(e=>(0,Y.jsxs)(`div`,{className:`group mb-1 rounded-md px-2 py-1.5 text-xs cursor-pointer transition-colors flex items-center justify-between `+(e.name===n?`bg-accent text-foreground`:`text-muted-foreground hover:bg-accent/50 hover:text-foreground`),onClick:()=>r(e.name),role:`button`,tabIndex:0,onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&r(e.name)},children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,Y.jsx)(`span`,{className:`truncate font-medium`,children:e.name}),e.isDefault&&(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`(team default)`})]}),(0,Y.jsxs)(`div`,{className:`flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity`,children:[(0,Y.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,title:`Duplicate`,onClick:t=>{t.stopPropagation(),ee(e.name)},children:(0,Y.jsx)(te,{className:`w-3 h-3`})}),!e.isDefault&&(0,Y.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-red-500/20 text-red-400 rounded`,title:`Delete`,onClick:t=>{t.stopPropagation(),P(e.name)},children:(0,Y.jsx)(i,{className:`w-3 h-3`})})]})]},e.name))})]}),(0,Y.jsxs)(`main`,{className:`flex-1 overflow-auto`,children:[l&&(0,Y.jsx)(`div`,{className:`mx-4 mt-4 px-3 py-2 text-xs rounded border border-red-500/30 bg-red-500/10 text-red-400`,children:l}),a?(0,Y.jsx)(fe,{profile:a,onChange:o,onValidityChange:_,onSoftWarningsChange:e=>y(e.agentsMissingRouting),footer:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)(u,{size:`sm`,onClick:()=>void F(a,v),disabled:m||g.length>0,title:g.length>0?`Fix validation issues before saving`:void 0,children:[(0,Y.jsx)(O,{className:`w-3.5 h-3.5 mr-1.5`}),`Save`]}),m&&(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Saving…`}),g.length>0&&(0,Y.jsxs)(`span`,{className:`text-xs text-yellow-500`,children:[g.length,` `,g.length===1?`issue`:`issues`,` to resolve`]})]})},a.name):(0,Y.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Select a profile to edit`})})]})]})]})}function Q(e){let t=e.workflow.map((e,t)=>`${t+1}. ${e}`).join(`
|
|
1
|
+
import{r as e}from"./chunk-CilyBKbf.js";import{$ as t,A as n,At as r,B as i,Ct as a,D as o,Dt as s,E as c,Et as l,F as u,Ft as d,H as f,J as p,K as m,M as h,Mt as g,N as _,Nt as v,O as y,Ot as b,Pt as x,R as S,St as C,Tt as w,U as T,V as E,Vt as D,W as O,X as k,Y as A,Z as j,a as M,bt as N,ct as ee,dt as P,et as F,ft as I,gt as L,ht as R,j as z,jt as B,k as V,kt as H,mt as U,rt as te,tt as ne,ut as re,vt as W,wt as G,xt as ie,yt as ae,z as K}from"./index-P2hinGr2.js";var oe=W(`flask-conical`,[[`path`,{d:`M14 2v6a2 2 0 0 0 .245.96l5.51 10.08A2 2 0 0 1 18 22H6a2 2 0 0 1-1.755-2.96l5.51-10.08A2 2 0 0 0 10 8V2`,key:`18mbvz`}],[`path`,{d:`M6.453 15h11.094`,key:`3shlmq`}],[`path`,{d:`M8.5 2h7`,key:`csnxdl`}]]),q=W(`history`,[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}],[`path`,{d:`M12 7v5l4 2`,key:`1fdv2h`}]]),se=W(`pin`,[[`path`,{d:`M12 17v5`,key:`bb1du9`}],[`path`,{d:`M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z`,key:`1nkz8b`}]]),ce=W(`wand-sparkles`,[[`path`,{d:`m21.64 3.64-1.28-1.28a1.21 1.21 0 0 0-1.72 0L2.36 18.64a1.21 1.21 0 0 0 0 1.72l1.28 1.28a1.2 1.2 0 0 0 1.72 0L21.64 5.36a1.2 1.2 0 0 0 0-1.72`,key:`ul74o6`}],[`path`,{d:`m14 7 3 3`,key:`1r5n42`}],[`path`,{d:`M5 6v4`,key:`ilb8ba`}],[`path`,{d:`M19 14v4`,key:`blhpug`}],[`path`,{d:`M10 2v2`,key:`7u0qdc`}],[`path`,{d:`M7 8H3`,key:`zfb6yr`}],[`path`,{d:`M21 16h-4`,key:`1cnmox`}],[`path`,{d:`M11 3H9`,key:`1obp7u`}]]),J=e(D(),1),Y=ie(),X=/^[a-z0-9][a-z0-9-]*$/;function le({open:e,mode:t=`add`,initial:r,chainAgents:i,onConfirm:a,onCancel:s}){let[l,d]=(0,J.useState)(``),[f,p]=(0,J.useState)(i[0]??``);(0,J.useEffect)(()=>{e&&(t===`edit`&&r?(d(r.tags.join(`, `)),p(i.includes(r.agent)?r.agent:i[0]??``)):(d(``),p(i[0]??``)))},[e,t,r,i]);let m=l.split(`,`).map(e=>e.trim()).filter(Boolean),h=m.filter(e=>!X.test(e)),g=m.length>0&&h.length===0&&i.includes(f);return(0,Y.jsx)(c,{open:e,onOpenChange:e=>{e||s()},children:(0,Y.jsxs)(o,{className:`max-w-md`,children:[(0,Y.jsxs)(n,{children:[(0,Y.jsx)(z,{children:t===`edit`?`Edit routing rule`:`Add routing rule`}),(0,Y.jsx)(y,{children:t===`edit`?`Update the tags or target agent for this rule.`:`Add a tag-matched routing rule using lowercase kebab-case tags.`})]}),(0,Y.jsxs)(`div`,{className:`py-2 space-y-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Tags`}),(0,Y.jsx)(M,{autoFocus:!0,value:l,onChange:e=>d(e.target.value),placeholder:`frontend, ui`,"aria-label":`Tags`,className:`text-sm font-mono`}),(0,Y.jsxs)(`p`,{className:`text-[11px] text-muted-foreground mt-1`,children:[`Comma-separated. Use lowercase kebab-case like `,(0,Y.jsx)(`code`,{children:`frontend`}),` or `,(0,Y.jsx)(`code`,{children:`api-design`}),`.`]}),h.length>0&&(0,Y.jsxs)(`p`,{className:`text-[11px] text-red-400 mt-1`,children:[`Invalid tag`,h.length===1?``:`s`,`: `,h.join(`, `),`. Tags must use lowercase letters, digits, and hyphens only.`]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Route to`}),(0,Y.jsx)(`select`,{value:f,onChange:e=>p(e.target.value),"aria-label":`Route to`,className:`w-full h-9 px-2 text-sm rounded-md border border-border bg-background`,children:i.map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e))}),(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground mt-1`,children:`Only agents in this profile's chain can be routing targets.`})]})]}),(0,Y.jsxs)(V,{children:[(0,Y.jsx)(u,{variant:`ghost`,size:`sm`,onClick:s,children:`Cancel`}),(0,Y.jsx)(u,{size:`sm`,onClick:()=>a(m,f),disabled:!g,children:t===`edit`?`Save changes`:`Add rule`})]})]})})}var Z=new Set([`sr-architect`,`sr-developer`,`sr-reviewer`,`sr-merge-resolver`]),ue=[`sonnet`,`opus`,`haiku`],de=/^[a-z0-9][a-z0-9-]*$/;function fe({profile:e,onChange:t,footer:n,onValidityChange:i,onSoftWarningsChange:o}){let[c,l]=(0,J.useState)([]),[d,f]=(0,J.useState)(!1),[m,h]=(0,J.useState)(!1),[_,y]=(0,J.useState)(null);(0,J.useEffect)(()=>{let e=!1;return fetch(`${C()}/profiles/catalog`).then(e=>e.ok?e.json():{agents:[]}).then(t=>{e||l(t.agents)}).catch(()=>{e||l([])}),()=>{e=!0}},[]);let x=n=>{let r=JSON.parse(JSON.stringify(e));n(r),t(r)},T=new Set(e.agents.map(e=>e.id)),E=c.filter(e=>!T.has(e.id)),D=(0,J.useMemo)(()=>{let t=[];for(let n of Z)e.agents.some(e=>e.id===n)||t.push(`Missing required baseline agent: ${n}`);let n=e.routing.filter(e=>`default`in e&&e.default===!0);if(n.length>1&&t.push(`Routing may have at most one default rule (found ${n.length})`),n.length===1){let n=e.routing[e.routing.length-1];`default`in n&&n.default===!0||t.push(`The default routing rule must be the last entry`)}for(let n of e.routing)if(e.agents.some(e=>e.id===n.agent)||t.push(`Routing references agent not in the chain: ${n.agent}`),`tags`in n){let e=n.tags.filter(e=>!de.test(e));e.length>0&&t.push(`Routing rule ${n.agent} has invalid tags: ${e.join(`, `)} (use lowercase kebab-case)`)}return t},[e]),O=(0,J.useMemo)(()=>{if(e.routing.length===0)return[];let t=new Set(e.routing.map(e=>e.agent));return e.agents.filter(e=>!Z.has(e.id)&&!t.has(e.id)).map(e=>e.id)},[e]),k=(0,J.useMemo)(()=>e.routing.some(e=>`default`in e&&e.default===!0),[e.routing]);(0,J.useEffect)(()=>{i&&i(D)},[D,i]),(0,J.useEffect)(()=>{o&&o({agentsMissingRouting:O})},[O,o]);let A=e=>{x(t=>{let n={id:e,model:`sonnet`},r=t.agents.findIndex(e=>e.id===`sr-merge-resolver`);r>=0?t.agents.splice(r,0,n):t.agents.push(n)}),f(!1)},j=t=>{let n=e.agents[t];Z.has(n.id)||x(e=>{e.agents.splice(t,1),e.routing=e.routing.filter(e=>e.agent!==n.id)})},N=(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=G(e.agents,r,i),o=a.findIndex(e=>e.id===`sr-architect`);if(o>0){let[e]=a.splice(o,1);a.unshift(e)}let s=a.findIndex(e=>e.id===`sr-merge-resolver`);if(s>=0&&s!==a.length-1){let[e]=a.splice(s,1);a.push(e)}x(e=>{e.agents=a})},ee=v(g(r,{activationConstraint:{distance:4}}),g(H,{coordinateGetter:w})),P=e=>{let{active:t,over:n}=e;n&&N(String(t.id),String(n.id))},F=(e,t)=>{x(n=>{n.agents[e].model=t})},I=(e,t)=>{x(n=>{let r={tags:e,agent:t},i=n.routing.findIndex(e=>`default`in e&&e.default===!0);i>=0?n.routing.splice(i,0,r):n.routing.push(r)}),h(!1)},L=()=>{x(e=>{e.routing.some(e=>`default`in e&&e.default===!0)||e.agents.some(e=>e.id===`sr-developer`)&&e.routing.push({default:!0,agent:`sr-developer`})})},R=e=>`default`in e&&e.default===!0,z=(e,t)=>{x(n=>{let r=n.routing[e];r&&(R(r)||(r.agent=t))})},V=(e,t,n)=>{x(r=>{let i=r.routing[e];i&&(R(i)||(i.tags=t,i.agent=n))})},U=e=>{x(t=>{let n=t.routing[e];n&&(R(n)||t.routing.splice(e,1))})},te=(t,n)=>{let r=t+n;if(r<0||r>=e.routing.length)return;let i=e.routing[t],a=e.routing[r];R(i)||R(a)||x(e=>{let[n]=e.routing.splice(t,1);e.routing.splice(r,0,n)})};return(0,Y.jsxs)(`div`,{className:`p-6 space-y-6 max-w-3xl`,children:[(0,Y.jsx)(le,{open:m,mode:`add`,chainAgents:e.agents.map(e=>e.id),onConfirm:I,onCancel:()=>h(!1)}),(0,Y.jsx)(le,{open:_!==null,mode:`edit`,initial:_!==null&&e.routing[_]&&!(`default`in e.routing[_])?{tags:e.routing[_].tags,agent:e.routing[_].agent}:void 0,chainAgents:e.agents.map(e=>e.id),onConfirm:(e,t)=>{_!==null&&(V(_,e,t),y(null))},onCancel:()=>y(null)}),D.length>0&&(0,Y.jsxs)(`div`,{className:`px-3 py-2 text-xs rounded-md border border-yellow-500/30 bg-yellow-500/10 text-yellow-500`,children:[(0,Y.jsxs)(`div`,{className:`font-medium mb-1`,children:[D.length,` validation `,D.length===1?`issue`:`issues`]}),(0,Y.jsx)(`ul`,{className:`list-disc list-inside space-y-0.5`,children:D.map((e,t)=>(0,Y.jsx)(`li`,{children:e},t))})]}),(0,Y.jsxs)(`section`,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Name`}),(0,Y.jsx)(M,{value:e.name,disabled:!0,className:`text-sm`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Description`}),(0,Y.jsx)(M,{value:e.description??``,onChange:e=>x(t=>{t.description=e.target.value}),className:`text-sm`,placeholder:`What is this profile for?`})]})]}),(0,Y.jsxs)(`section`,{children:[(0,Y.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide mb-2`,children:`Orchestrator`}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 p-3 rounded-md border border-border`,children:[(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-mono text-foreground truncate`,children:`/specrails:implement · /specrails:batch-implement`}),(0,Y.jsx)(`div`,{className:`text-[11px] text-muted-foreground mt-0.5`,children:`Top-level model for both commands. batch-implement delegates to implement per feature, so every rail it spawns inherits this profile's agent chain.`})]}),(0,Y.jsx)(he,{value:e.orchestrator.model,onChange:e=>x(t=>{t.orchestrator.model=e})})]})]}),(0,Y.jsxs)(`section`,{children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,Y.jsxs)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:[`Agent chain (`,e.agents.length,`)`]}),(0,Y.jsxs)(u,{size:`sm`,variant:`ghost`,onClick:()=>f(e=>!e),disabled:E.length===0,title:E.length===0?`All catalog agents are already in the chain`:`Add an agent from the catalog`,children:[(0,Y.jsx)(p,{className:`w-3.5 h-3.5 mr-1`}),` Add`]})]}),d&&(0,Y.jsxs)(`div`,{className:`mb-2 p-2 rounded-md border border-border bg-muted/30`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mb-1.5 px-1`,children:[(0,Y.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,children:[`Pick from catalog (`,E.length,` available)`]}),(0,Y.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:()=>f(!1),title:`Close`,children:(0,Y.jsx)(S,{className:`w-3 h-3`})})]}),E.length===0?(0,Y.jsx)(`div`,{className:`px-2 py-3 text-xs text-muted-foreground text-center`,children:`No more agents in the catalog. Add custom agents from the Agents Catalog tab.`}):(0,Y.jsx)(`div`,{className:`space-y-0.5 max-h-64 overflow-auto`,children:E.map(e=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>A(e.id),className:`w-full flex items-center justify-between gap-2 px-2 py-1.5 text-left rounded hover:bg-accent transition-colors`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-mono`,children:e.id}),(0,Y.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded `+(e.kind===`custom`?`bg-purple-500/15 text-purple-400`:`bg-muted text-muted-foreground`),children:e.kind})]},e.id))})]}),(0,Y.jsx)(b,{sensors:ee,collisionDetection:B,onDragEnd:P,children:(0,Y.jsx)(a,{items:e.agents.map(e=>e.id),strategy:s,children:(0,Y.jsx)(`div`,{className:`space-y-1.5`,children:e.agents.map((e,t)=>(0,Y.jsx)(pe,{agent:e,canRemove:!Z.has(e.id),onModel:e=>F(t,e),onRemove:()=>j(t)},e.id))})})})]}),(0,Y.jsxs)(`section`,{children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,Y.jsxs)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:[`Routing (`,e.routing.length,`)`]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[!k&&(0,Y.jsxs)(u,{size:`sm`,variant:`ghost`,onClick:L,disabled:e.agents.length===0,title:e.agents.length===0?`Add at least one agent before creating routing rules`:void 0,children:[(0,Y.jsx)(p,{className:`w-3.5 h-3.5 mr-1`}),` Add default`]}),(0,Y.jsxs)(u,{size:`sm`,variant:`ghost`,onClick:()=>h(!0),disabled:e.agents.length===0,title:e.agents.length===0?`Add at least one agent before creating routing rules`:void 0,children:[(0,Y.jsx)(p,{className:`w-3.5 h-3.5 mr-1`}),` Add rule`]})]})]}),(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground mb-2`,children:`First matching rule wins. Rules are editable and removable, and the default catch-all stays last when present. If you leave routing empty, the pipeline falls back to the first developer-shaped agent in the chain.`}),O.length>0&&(0,Y.jsxs)(`div`,{className:`mb-2 px-3 py-2 text-xs rounded-md border border-yellow-500/30 bg-yellow-500/10 text-yellow-500`,children:[(0,Y.jsx)(`div`,{className:`font-medium mb-1`,children:`Untargeted agents in the chain`}),(0,Y.jsxs)(`div`,{children:[`No routing rule points to: `,(0,Y.jsx)(`span`,{className:`font-mono`,children:O.join(`, `)}),`. Add a tag rule or retarget the default rule if you want them to run.`]})]}),(0,Y.jsx)(`div`,{className:`space-y-1.5`,children:e.routing.map((t,n)=>{let r=`default`in t&&t.default===!0;return(0,Y.jsx)(me,{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=>z(n,e),onEdit:()=>y(n),onUp:()=>te(n,-1),onDown:()=>te(n,1),onRemove:()=>U(n)},n)})})]}),n&&(0,Y.jsx)(`div`,{className:`pt-3 border-t border-border`,children:n})]})}function pe({agent:e,canRemove:n,onModel:r,onRemove:i}){let a=Z.has(e.id),o=e.id===`sr-architect`,s=e.id===`sr-merge-resolver`,{attributes:c,listeners:u,setNodeRef:d,transform:f,transition:p,isDragging:m}=l({id:e.id});return(0,Y.jsxs)(`div`,{ref:d,style:{transform:x.Transform.toString(f),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,Y.jsx)(`button`,{type:`button`,className:`flex-shrink-0 p-0.5 rounded text-muted-foreground cursor-grab active:cursor-grabbing hover:text-foreground`,title:`Drag to reorder`,"aria-label":`Drag handle`,...c,...u,children:(0,Y.jsx)(t,{className:`w-3.5 h-3.5`})}),(0,Y.jsx)(`span`,{className:`text-sm font-mono flex-1 truncate`,children:e.id}),o&&(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded bg-accent-primary/15 text-accent-primary`,title:`Pinned to first position — pipeline always starts with sr-architect`,children:[(0,Y.jsx)(se,{className:`w-2.5 h-2.5 rotate-[135deg]`}),` first`]}),s&&(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded bg-accent-primary/15 text-accent-primary`,title:`Pinned to last position — merge phase always runs last`,children:[(0,Y.jsx)(se,{className:`w-2.5 h-2.5 rotate-45`}),` last`]}),a&&!o&&!s&&(0,Y.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:`required`}),(0,Y.jsx)(he,{value:e.model??`sonnet`,onChange:r}),(0,Y.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-red-500/20 text-red-400 rounded disabled:opacity-30 disabled:cursor-not-allowed opacity-0 group-hover:opacity-100 transition-opacity`,onClick:i,disabled:!n,title:n?`Remove`:`Required baseline agent — the pipeline depends on this row`,children:(0,Y.jsx)(S,{className:`w-3 h-3`})})]})}function me({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 f=`default`in e&&e.default===!0;return(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 rounded-md border border-border group hover:bg-accent/30 transition-colors`,children:[(0,Y.jsxs)(`span`,{className:`text-[10px] font-mono text-muted-foreground w-5 text-center flex-shrink-0`,children:[t,`.`]}),f?(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground flex-1`,children:`everything else`}):(0,Y.jsx)(`span`,{className:`text-xs flex-1 flex gap-1 flex-wrap items-center`,children:e.tags.map(e=>(0,Y.jsx)(`span`,{className:`px-1.5 py-0.5 rounded bg-muted font-mono text-[11px]`,children:e},e))}),(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`→`}),f?(0,Y.jsx)(`span`,{className:`h-7 max-w-[15rem] px-2 text-xs font-mono rounded border border-border bg-muted/40 text-muted-foreground inline-flex items-center`,"aria-label":`Default routing target (core, read-only)`,title:`Core fallback — not editable`,children:e.agent}):(0,Y.jsx)(`select`,{value:e.agent,onChange:e=>s(e.target.value),"aria-label":`Routing target for rule ${t}`,className:`h-7 max-w-[15rem] px-2 text-xs font-mono rounded border border-border bg-background`,children:o.map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e))}),(0,Y.jsxs)(`div`,{className:`flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity`,children:[a&&(0,Y.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:c,title:`Edit rule`,"aria-label":`Edit rule ${t}`,children:(0,Y.jsx)(A,{className:`w-3 h-3`})}),r&&!n&&(0,Y.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:u,title:`Move down`,children:(0,Y.jsx)(L,{className:`w-3 h-3`})}),r&&t>1&&(0,Y.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:l,title:`Move up`,children:(0,Y.jsx)(U,{className:`w-3 h-3`})}),i&&(0,Y.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-red-500/20 text-red-400 rounded`,onClick:d,title:`Remove`,children:(0,Y.jsx)(S,{className:`w-3 h-3`})})]}),f&&(0,Y.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,title:`Core fallback — the pipeline's last-resort rule, pinned to sr-developer`,children:`core · default`})]})}function he({value:e,onChange:t}){return(0,Y.jsx)(`select`,{value:e,onChange:e=>t(e.target.value),className:`h-7 px-2 text-xs rounded border border-border bg-background`,children:ue.map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e))})}function ge({open:e,title:t,description:r,placeholder:i,initialValue:a=``,confirmLabel:s=`Confirm`,inputPattern:l,inputInvalidHint:d,onConfirm:f,onCancel:p}){let[m,h]=(0,J.useState)(a);(0,J.useEffect)(()=>{e&&h(a)},[e,a]);let g=m.trim(),_=!l||l.test(g),v=g.length>0&&_;return(0,Y.jsx)(c,{open:e,onOpenChange:e=>{e||p()},children:(0,Y.jsxs)(o,{className:`max-w-md`,children:[(0,Y.jsx)(n,{children:(0,Y.jsx)(z,{children:t})}),(0,Y.jsxs)(`div`,{className:`py-2 space-y-2`,children:[r&&(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r}),(0,Y.jsx)(M,{autoFocus:!0,value:m,placeholder:i,onChange:e=>h(e.target.value),onKeyDown:e=>{e.key===`Enter`&&v&&f(g)},className:`text-sm font-mono`}),g.length>0&&!_&&d&&(0,Y.jsx)(`p`,{className:`text-[11px] text-yellow-500`,children:d})]}),(0,Y.jsxs)(V,{children:[(0,Y.jsx)(u,{variant:`ghost`,size:`sm`,onClick:p,children:`Cancel`}),(0,Y.jsx)(u,{size:`sm`,onClick:()=>f(g),disabled:!v,children:s})]})]})})}function _e({open:e,title:t,description:r,confirmLabel:i=`Confirm`,destructive:a=!1,onConfirm:s,onCancel:l}){return(0,Y.jsx)(c,{open:e,onOpenChange:e=>{e||l()},children:(0,Y.jsxs)(o,{className:`max-w-md`,children:[(0,Y.jsx)(n,{children:(0,Y.jsx)(z,{children:t})}),r&&(0,Y.jsx)(`div`,{className:`py-2`,children:(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r})}),(0,Y.jsxs)(V,{children:[(0,Y.jsx)(u,{variant:`ghost`,size:`sm`,onClick:l,children:`Cancel`}),(0,Y.jsx)(u,{size:`sm`,onClick:s,className:a?`bg-red-500 hover:bg-red-600 text-white`:void 0,children:i})]})]})})}function ve(){let[e,t]=(0,J.useState)([]),[n,r]=(0,J.useState)(null),[a,o]=(0,J.useState)(null),[s,c]=(0,J.useState)(!0),[l,f]=(0,J.useState)(null),[m,h]=(0,J.useState)(!1),[g,_]=(0,J.useState)([]),[v,y]=(0,J.useState)([]),[b,x]=(0,J.useState)(!1),[S,w]=(0,J.useState)(null),[T,E]=(0,J.useState)(null),D=(0,J.useCallback)(async()=>{c(!0),f(null);try{let e=await fetch(`${C()}/profiles`);if(!e.ok)throw Error(`List failed: ${e.status}`);let i=await e.json();t(i.profiles),i.profiles.length>0&&!n&&r(i.profiles[0].name)}catch(e){f(e.message)}finally{c(!1)}},[n]);(0,J.useEffect)(()=>{D()},[D]),(0,J.useEffect)(()=>{if(!n){o(null);return}let e=!1;return fetch(`${C()}/profiles/${encodeURIComponent(n)}`).then(e=>{if(!e.ok)throw Error(`Load failed: ${e.status}`);return e.json()}).then(t=>{e||o(t.profile)}).catch(t=>{e||f(t.message)}),()=>{e=!0}},[n]);let k=(0,J.useCallback)(async()=>{h(!0),f(null);try{let e=await fetch(`${C()}/profiles/migrate-from-settings`,{method:`POST`});if(!e.ok){let t=await e.json().catch(()=>({}));throw Error(t.error??`Migration failed: ${e.status}`)}await D(),r(`default`),d.success(`Profile migrated`,{description:`default profile created from your current agents`})}catch(e){let t=e.message;f(t),d.error(`Migration failed`,{description:t})}finally{h(!1)}},[D]),A=(0,J.useCallback)(async e=>{x(!1),h(!0),f(null);try{let t={schemaVersion:1,name:e,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`}]},n=await fetch(`${C()}/profiles`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)});if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(e.error??`Create failed: ${n.status}`)}await D(),r(e),d.success(`Profile created`,{description:e})}catch(e){let t=e.message;f(t),d.error(`Failed to create profile`,{description:t})}finally{h(!1)}},[D]),j=(0,J.useCallback)(async(e,t)=>{w(null),h(!0),f(null);try{let n=await fetch(`${C()}/profiles/${encodeURIComponent(e)}/duplicate`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:t})});if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(e.error??`Duplicate failed: ${n.status}`)}await D(),r(t),d.success(`Profile duplicated`,{description:`${e} → ${t}`})}catch(e){let t=e.message;f(t),d.error(`Failed to duplicate profile`,{description:t})}finally{h(!1)}},[D]),M=(0,J.useCallback)(async e=>{E(null),h(!0),f(null);try{let t=await fetch(`${C()}/profiles/${encodeURIComponent(e)}`,{method:`DELETE`});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error??`Delete failed: ${t.status}`)}r(t=>t===e?null:t),await D(),d.success(`Profile deleted`,{description:e})}catch(e){let t=e.message;f(t),d.error(`Failed to delete profile`,{description:t})}finally{h(!1)}},[D]),N=(0,J.useCallback)(()=>x(!0),[]),ee=(0,J.useCallback)(e=>w({from:e}),[]),P=(0,J.useCallback)(e=>E({name:e}),[]),F=(0,J.useCallback)(async(e,t)=>{h(!0),f(null);try{let n=await fetch(`${C()}/profiles/${encodeURIComponent(e.name)}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)});if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(e.error??`Save failed: ${n.status}`)}o(e),t.length>0?d.warning(`Profile saved with untargeted agents`,{description:`No routing rule points to: ${t.join(`, `)}. Add a tag rule or retarget the default rule if you want them to run.`,duration:6e3}):d.success(`Profile saved`,{description:e.name})}catch(e){let t=e.message;f(t),d.error(`Failed to save profile`,{description:t})}finally{h(!1)}},[]),I=(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(ge,{open:b,title:`New profile`,description:`Pick a lowercase kebab-case name (letters, digits, and hyphens).`,placeholder:`my-profile`,confirmLabel:`Create`,inputPattern:/^[a-z0-9][a-z0-9-]*$/,inputInvalidHint:`Must start with a letter or digit and contain only lowercase letters, digits, and hyphens.`,onConfirm:e=>void A(e),onCancel:()=>x(!1)}),S&&(0,Y.jsx)(ge,{open:!0,title:`Duplicate "${S.from}"`,description:`Name for the new profile.`,placeholder:`${S.from}-copy`,initialValue:`${S.from}-copy`,confirmLabel:`Duplicate`,inputPattern:/^[a-z0-9][a-z0-9-]*$/,inputInvalidHint:`Lowercase kebab-case only.`,onConfirm:e=>void j(S.from,e),onCancel:()=>w(null)}),T&&(0,Y.jsx)(_e,{open:!0,title:`Delete profile "${T.name}"?`,description:`This cannot be undone. Jobs already launched with this profile keep their snapshot; future launches will fall back to the resolution order.`,confirmLabel:`Delete`,destructive:!0,onConfirm:()=>void M(T.name),onCancel:()=>E(null)})]});return s?(0,Y.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading profiles…`})}):e.length===0?(0,Y.jsxs)(Y.Fragment,{children:[I,(0,Y.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,Y.jsxs)(`div`,{className:`text-center max-w-md`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:`No profiles yet`}),(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground mt-1 mb-4`,children:`Profiles let you save orchestrator + agent + routing combinations and pick one per rail.`}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 justify-center`,children:[(0,Y.jsxs)(u,{size:`sm`,onClick:k,disabled:m,children:[(0,Y.jsx)(ce,{className:`w-3.5 h-3.5 mr-1.5`}),` Migrate from current agents`]}),(0,Y.jsxs)(u,{size:`sm`,variant:`ghost`,onClick:N,disabled:m,children:[(0,Y.jsx)(p,{className:`w-3.5 h-3.5 mr-1.5`}),` Blank profile`]})]}),(0,Y.jsxs)(`div`,{className:`text-[11px] text-muted-foreground/70 mt-3`,children:[`"Migrate" reads your existing `,(0,Y.jsx)(`code`,{className:`text-foreground`,children:`.claude/agents/`}),` `,`frontmatter models and creates a `,(0,Y.jsx)(`code`,{className:`text-foreground`,children:`default`}),` profile mirroring today's behavior — zero-loss.`]}),l&&(0,Y.jsx)(`div`,{className:`mt-3 text-xs text-red-400`,children:l})]})})]}):(0,Y.jsxs)(`div`,{className:`flex flex-col h-full`,children:[I,(0,Y.jsxs)(`div`,{className:`flex flex-1 min-h-0`,children:[(0,Y.jsxs)(`aside`,{className:`w-64 flex-shrink-0 border-r border-border flex flex-col`,children:[(0,Y.jsxs)(`div`,{className:`p-3 flex items-center justify-between`,children:[(0,Y.jsx)(`div`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:`Profiles`}),(0,Y.jsx)(u,{size:`sm`,variant:`ghost`,onClick:N,disabled:m,children:(0,Y.jsx)(p,{className:`w-3.5 h-3.5`})})]}),(0,Y.jsx)(`div`,{className:`flex-1 overflow-auto px-2 pb-3`,children:e.map(e=>(0,Y.jsxs)(`div`,{className:`group mb-1 rounded-md px-2 py-1.5 text-xs cursor-pointer transition-colors flex items-center justify-between `+(e.name===n?`bg-accent text-foreground`:`text-muted-foreground hover:bg-accent/50 hover:text-foreground`),onClick:()=>r(e.name),role:`button`,tabIndex:0,onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&r(e.name)},children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,Y.jsx)(`span`,{className:`truncate font-medium`,children:e.name}),e.isDefault&&(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`(team default)`})]}),(0,Y.jsxs)(`div`,{className:`flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity`,children:[(0,Y.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,title:`Duplicate`,onClick:t=>{t.stopPropagation(),ee(e.name)},children:(0,Y.jsx)(te,{className:`w-3 h-3`})}),!e.isDefault&&(0,Y.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-red-500/20 text-red-400 rounded`,title:`Delete`,onClick:t=>{t.stopPropagation(),P(e.name)},children:(0,Y.jsx)(i,{className:`w-3 h-3`})})]})]},e.name))})]}),(0,Y.jsxs)(`main`,{className:`flex-1 overflow-auto`,children:[l&&(0,Y.jsx)(`div`,{className:`mx-4 mt-4 px-3 py-2 text-xs rounded border border-red-500/30 bg-red-500/10 text-red-400`,children:l}),a?(0,Y.jsx)(fe,{profile:a,onChange:o,onValidityChange:_,onSoftWarningsChange:e=>y(e.agentsMissingRouting),footer:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)(u,{size:`sm`,onClick:()=>void F(a,v),disabled:m||g.length>0,title:g.length>0?`Fix validation issues before saving`:void 0,children:[(0,Y.jsx)(O,{className:`w-3.5 h-3.5 mr-1.5`}),`Save`]}),m&&(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Saving…`}),g.length>0&&(0,Y.jsxs)(`span`,{className:`text-xs text-yellow-500`,children:[g.length,` `,g.length===1?`issue`:`issues`,` to resolve`]})]})},a.name):(0,Y.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Select a profile to edit`})})]})]})]})}function Q(e){let t=e.workflow.map((e,t)=>`${t+1}. ${e}`).join(`
|
|
2
2
|
`);return`---
|
|
3
3
|
name: ${e.id}
|
|
4
4
|
description: "${e.descriptionOneLine}"
|
|
@@ -83,4 +83,4 @@ You are ...
|
|
|
83
83
|
`}),o++):(i.push({type:`del`,text:n[a]+`
|
|
84
84
|
`}),a++)}for(;a<n.length;)i.push({type:`del`,text:n[a++]+`
|
|
85
85
|
`});for(;o<r.length;)i.push({type:`add`,text:r[o++]+`
|
|
86
|
-
`});return i}function qe({value:e,onChange:t,onSubmit:n,disabled:r,placeholder:i,autoFocus:a,inputRef:o}){return(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsxs)(`div`,{className:`relative rounded-xl border border-border bg-card/40 focus-within:border-accent-primary/40 focus-within:ring-2 focus-within:ring-accent-primary/20 transition-all`,children:[(0,Y.jsx)(`textarea`,{ref:o,value:e,onChange:e=>t(e.target.value),placeholder:i,rows:3,disabled:r,autoFocus:a,className:`w-full text-sm p-3 pr-14 bg-transparent resize-none focus:outline-none disabled:opacity-50 placeholder:text-muted-foreground/60`,onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),n())}}),(0,Y.jsx)(`button`,{type:`button`,onClick:n,disabled:!e.trim()||r,"aria-label":`Send (⌘⏎)`,className:`absolute bottom-2.5 right-2.5 p-2 rounded-md bg-accent-primary text-white hover:bg-accent-primary/90 disabled:opacity-30 disabled:cursor-not-allowed focus-visible:ring-2 focus-visible:ring-primary/40 focus-visible:outline-none transition-opacity`,children:r?(0,Y.jsx)(j,{className:`w-3.5 h-3.5 animate-spin`}):(0,Y.jsx)(Je,{})})]}),(0,Y.jsx)(`div`,{className:`flex items-center justify-end text-[11px] text-muted-foreground/70`,children:(0,Y.jsxs)(`span`,{children:[(0,Y.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted/60 text-[10px] font-mono`,children:`⌘⏎`}),` submit`,(0,Y.jsx)(`span`,{className:`mx-1.5`,children:`·`}),(0,Y.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted/60 text-[10px] font-mono`,children:`Esc`}),` cancel`]})})]})}function Je(){return(0,Y.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,className:`w-3.5 h-3.5`,children:[(0,Y.jsx)(`path`,{d:`M22 2 11 13`}),(0,Y.jsx)(`path`,{d:`M22 2 15 22l-4-9-9-4Z`})]})}var Ye=[`Tighten the tool list`,`Make the personality stricter`,`Add a Workflow protocol section`,`Shorten and sharpen the description`,`Match the sr-developer style`];function Xe({agentId:e,baseBody:t,resumeRefineId:n,onClose:r,onMinimize:i,onStateChange:a,onOpenInStudio:o,onApplied:s}){let{activeProjectId:c}=ae(),l=De(c),[u,d]=(0,J.useState)(``),f=(0,J.useRef)(null),p=(0,J.useRef)(!1);(0,J.useEffect)(()=>{p.current||(p.current=!0,n?l.rehydrate(n,e):l.open(e,t))},[e,t,n,l]),(0,J.useEffect)(()=>{let e=setTimeout(()=>f.current?.focus(),50);return()=>clearTimeout(e)},[]);let m=(0,J.useRef)(a);m.current=a,(0,J.useEffect)(()=>{m.current?.({refineId:l.state.refineId??null})},[l.state.refineId]);let h=(0,J.useRef)(null);(0,J.useEffect)(()=>{l.state.uiState===`applied`&&l.state.appliedVersion!==null&&l.state.appliedVersion!==h.current&&(h.current=l.state.appliedVersion,s&&l.state.agentId&&s(l.state.agentId,l.state.appliedVersion))},[l.state.uiState,l.state.appliedVersion,l.state.agentId,s]);let g=(0,J.useCallback)(async e=>{let t=e.trim();t&&(d(``),l.state.refineId?await l.sendTurn(t):await l.start(t))},[l]),_=(0,J.useCallback)(()=>{g(u)},[u,g]),v=(0,J.useCallback)(async()=>{l.state.refineId&&(l.state.uiState===`streaming`||l.state.uiState===`reviewing`)&&await l.cancel(),r()},[l,r]),y=Ze(l.state),b=(0,J.useMemo)(()=>!l.state.draftBody||!l.state.baseBody?null:(0,Y.jsx)(Ue,{hunks:Ge(l.state.baseBody,l.state.draftBody)}),[l.state.baseBody,l.state.draftBody]);return(0,Y.jsx)(ke,{uiPhase:y,errorMessage:l.state.errorMessage,applyConflict:l.state.applyConflict,eyebrow:`AI Edit`,targetLabel:e,targetLabelMono:!0,headline:`Refine your agent`,streamingHeadline:`Refining your agent…`,description:Qe(t),chips:Ye,onChipSubmit:e=>void g(e),composer:(0,Y.jsx)(qe,{value:u,onChange:d,onSubmit:_,disabled:y===`streaming`||y===`applied`,placeholder:l.state.refineId?`Send a follow-up refinement…`:`Describe how to refine this agent…`,inputRef:f}),streamingText:l.state.streamingText,history:l.state.history,diff:b,diffHeaderLabel:`.claude/agents/${e}.md`,baseBody:t,baseBodyDisclosureLabel:`View current agent body`,appliedNotice:l.state.appliedVersion===null?void 0:(0,Y.jsxs)(`div`,{className:`rounded-md border border-green-500/40 bg-green-500/10 p-3 text-xs text-green-300`,children:[`Applied as version `,l.state.appliedVersion,`.`]}),canApply:l.state.uiState===`reviewing`&&!!l.state.draftBody&&!l.state.applyConflict,onApply:()=>void l.apply(),onForceApply:()=>void l.apply(!0),onDiscard:()=>void v(),onClose:()=>void v(),onMinimize:i?()=>i(l.state.refineId??null):void 0,secondaryAction:o&&l.state.draftBody&&l.state.refineId?{label:`Open draft in Studio for manual editing`,icon:(0,Y.jsx)(ne,{className:`w-3 h-3`}),onClick:()=>{l.state.refineId&&l.state.draftBody&&o&&o(l.state.refineId,l.state.draftBody)}}:void 0})}function Ze(e){switch(e.uiState){case`streaming`:return`streaming`;case`reviewing`:return`reviewing`;case`applied`:return`applied`;case`error`:return`error`;default:return`composing`}}function Qe(e){let t=e.match(/^---\r?\n([\s\S]*?)\r?\n---/);if(!t)return null;let n=t[1].match(/^description:\s*([\s\S]*?)(?=^[a-z_]+:\s|\Z)/m);if(!n)return null;let r=n[1].trim();return(r.startsWith(`"`)&&r.endsWith(`"`)||r.startsWith(`'`)&&r.endsWith(`'`))&&(r=r.slice(1,-1)),r=r.replace(/\\n/g,` `).replace(/\\t/g,` `).replace(/\\"/g,`"`).replace(/\\'/g,`'`).replace(/\\\\/g,`\\`).replace(/\s+/g,` `).trim(),r.length>240&&(r=r.slice(0,237)+`…`),r||null}function $e(){let[e,t]=(0,J.useState)([]),[r,i]=(0,J.useState)(null),[a,s]=(0,J.useState)(null),[l,d]=(0,J.useState)(!0),[m,g]=(0,J.useState)(!1),[v,y]=(0,J.useState)(null),[b,x]=(0,J.useState)({kind:`closed`}),[w,D]=(0,J.useState)({kind:`closed`}),[O,k]=(0,J.useState)(!1),[N,ee]=(0,J.useState)(``),[P,I]=(0,J.useState)(`all`),[L,R]=(0,J.useState)(null),[B,H]=(0,J.useState)(!1),[U,ne]=(0,J.useState)(``),[re,W]=(0,J.useState)(``),[G,ie]=(0,J.useState)(!1),[K,oe]=(0,J.useState)(null),{activeProjectId:q}=ae(),{minimize:se}=h(),X=(0,J.useRef)({refineId:null}),le=(0,J.useRef)(w);le.current=w;let Z=(0,J.useCallback)(()=>{let e=le.current;e.kind!==`open`||!q||se({kind:`ai-edit`,projectId:q,label:`AI Edit · ${e.agentId}`,restoreRoute:`/agents`,params:{agentId:e.agentId,baseBody:e.baseBody,resumeRefineId:X.current.refineId??e.resumeRefineId}})},[q,se]);_(`ai-edit`,q,e=>{e.kind===`ai-edit`&&(Z(),X.current={refineId:e.params.resumeRefineId??null},D({kind:`open`,agentId:e.params.agentId,baseBody:e.params.baseBody,resumeRefineId:e.params.resumeRefineId}))});let ue=(0,J.useCallback)(()=>{let e=!1;return d(!0),fetch(`${C()}/profiles/catalog`).then(e=>{if(!e.ok)throw Error(`Catalog load failed: ${e.status}`);return e.json()}).then(n=>{e||(t(n.agents),n.agents.length>0&&!r&&i(n.agents[0].id))}).catch(t=>{e||y(t.message)}).finally(()=>{e||d(!1)}),()=>{e=!0}},[r]);(0,J.useEffect)(()=>ue(),[ue]);let de=(0,J.useCallback)(e=>{let t=!1;return g(!0),s(null),fetch(`${C()}/profiles/catalog/${encodeURIComponent(e)}`).then(e=>{if(!e.ok)throw Error(`Agent body load failed: ${e.status}`);return e.json()}).then(e=>{t||s(e.body)}).catch(e=>{t||y(e.message)}).finally(()=>{t||g(!1)}),()=>{t=!0}},[]);if((0,J.useEffect)(()=>{if(r)return de(r)},[r,de]),l)return(0,Y.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading catalog…`})});if(b.kind!==`closed`)return(0,Y.jsx)(Se,{agentId:b.kind===`edit`?b.agentId:void 0,initialBody:b.kind===`duplicate`||b.kind===`create`?b.initialBody:void 0,initialName:b.kind===`create`?b.initialName:void 0,draftFromRefine:b.kind===`edit`?b.draftFromRefine:void 0,onClose:()=>x({kind:`closed`}),onSaved:e=>{i(e),x({kind:`closed`}),ue()},onResumeRefine:(e,t,n)=>{x({kind:`closed`}),Z(),X.current={refineId:e},D({kind:`open`,agentId:t,baseBody:n,resumeRefineId:e})}});if(w.kind===`open`)return(0,Y.jsx)(Xe,{agentId:w.agentId,baseBody:w.baseBody,resumeRefineId:w.resumeRefineId,onStateChange:e=>{X.current=e},onClose:()=>D({kind:`closed`}),onMinimize:e=>{if(!q){D({kind:`closed`});return}let t=w.kind===`open`?w.agentId:``,n=w.kind===`open`?w.baseBody:``;se({kind:`ai-edit`,projectId:q,label:`AI Edit · ${t}`,restoreRoute:`/agents`,params:{agentId:t,baseBody:n,resumeRefineId:e??void 0}}),D({kind:`closed`})},onApplied:e=>{D({kind:`closed`}),i(e),ue()},onOpenInStudio:(e,t)=>{D({kind:`closed`}),x({kind:`edit`,agentId:w.agentId,draftFromRefine:e})}},`${w.agentId}:${w.resumeRefineId??`fresh`}`);let fe=(()=>{let e=N.trim().toLowerCase();return ye.filter(t=>!(P!==`all`&&t.category!==P||L&&!t.tags.includes(L)||e&&!(t.label+` `+t.blurb+` `+t.tags.join(` `)+` `+t.category).toLowerCase().includes(e)))})(),pe=(()=>{let e=new Map;for(let t of ye)e.set(t.category,(e.get(t.category)??0)+1);return e})(),me=()=>{k(!1),ee(``),I(`all`),R(null)},he=()=>(0,Y.jsx)(c,{open:O,onOpenChange:e=>{e||me()},children:(0,Y.jsxs)(o,{className:`max-w-4xl p-0 h-[85vh] flex flex-col overflow-hidden`,children:[(0,Y.jsxs)(`div`,{className:`flex-shrink-0 px-6 pt-5 pb-3 border-b border-border`,children:[(0,Y.jsxs)(n,{children:[(0,Y.jsxs)(z,{className:`flex items-center gap-2 text-base`,children:[(0,Y.jsx)(F,{className:`w-4 h-4 text-accent-primary`}),` Agent template library`,(0,Y.jsxs)(`span`,{className:`text-[11px] font-normal text-muted-foreground ml-1`,children:[fe.length,` of `,ye.length]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:`Start from a curated template across engineering, product, science, health, legal, and more. Pick one and open it in the Studio for review and editing before saving.`})]}),(0,Y.jsxs)(`div`,{className:`mt-3 relative`,children:[(0,Y.jsx)(T,{className:`w-3.5 h-3.5 absolute left-2.5 top-1/2 -translate-y-1/2 text-muted-foreground pointer-events-none`}),(0,Y.jsx)(`input`,{value:N,onChange:e=>ee(e.target.value),placeholder:`Search by name, description, tag, or category…`,className:`w-full h-9 pl-8 pr-8 text-sm rounded-md border border-border bg-background focus:outline-none focus:ring-1 focus:ring-primary/40`,autoFocus:!0}),N&&(0,Y.jsx)(`button`,{type:`button`,onClick:()=>ee(``),className:`absolute right-2 top-1/2 -translate-y-1/2 p-0.5 rounded hover:bg-accent text-muted-foreground`,children:(0,Y.jsx)(S,{className:`w-3.5 h-3.5`})})]}),(0,Y.jsxs)(`div`,{className:`flex gap-1.5 overflow-x-auto mt-3 pb-1 scrollbar-thin`,children:[(0,Y.jsx)(et,{label:`All`,count:ye.length,active:P===`all`,onClick:()=>I(`all`)}),be.map(e=>(0,Y.jsx)(et,{label:e,count:pe.get(e)??0,active:P===e,onClick:()=>I(e)},e))]}),L&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mt-2`,children:[(0,Y.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:`Tag filter:`}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>R(null),className:`inline-flex items-center gap-1 text-[11px] px-2 py-0.5 rounded-full bg-accent-primary/20 text-accent-primary hover:bg-accent-primary/30`,children:[(0,Y.jsx)(E,{className:`w-3 h-3`}),` `,L,(0,Y.jsx)(S,{className:`w-3 h-3`})]})]})]}),(0,Y.jsx)(`div`,{className:`flex-1 overflow-y-auto px-6 py-4`,children:fe.length===0?(0,Y.jsx)(`div`,{className:`h-full flex items-center justify-center text-center`,children:(0,Y.jsxs)(`div`,{className:`max-w-sm`,children:[(0,Y.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:`No templates match your filters.`}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>{ee(``),I(`all`),R(null)},className:`text-xs text-accent-primary hover:underline mt-2`,children:`Clear filters`})]})}):(0,Y.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:fe.map(e=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{me(),x({kind:`create`,initialBody:e.body,initialName:e.nameHint})},className:`group text-left p-4 rounded-lg border border-border bg-card/40 hover:border-accent-primary/50 hover:bg-accent/40 hover:shadow-sm transition-all`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start gap-3 mb-2`,children:[(0,Y.jsx)(`span`,{className:`text-2xl leading-none mt-0.5`,children:e.emoji}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-semibold text-foreground group-hover:text-accent-primary truncate`,children:e.label}),(0,Y.jsx)(`div`,{className:`text-[10px] text-muted-foreground mt-0.5`,children:e.category})]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground leading-relaxed line-clamp-2 min-h-[2lh]`,children:e.blurb}),(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-1 mt-3`,children:e.tags.slice(0,5).map(e=>(0,Y.jsx)(`span`,{role:`button`,tabIndex:0,onClick:t=>{t.stopPropagation(),R(e)},onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),t.stopPropagation(),R(e))},className:`text-[10px] px-1.5 py-0.5 rounded bg-muted/50 text-muted-foreground hover:bg-accent-primary/20 hover:text-accent-primary cursor-pointer transition-colors `+(L===e?`bg-accent-primary/20 text-accent-primary`:``),children:e},e))}),(0,Y.jsxs)(`div`,{className:`mt-3 pt-2 border-t border-border/40 flex items-center justify-between`,children:[(0,Y.jsx)(`code`,{className:`text-[10px] font-mono text-muted-foreground/70 truncate`,children:e.nameHint}),(0,Y.jsx)(`span`,{className:`text-[10px] text-accent-primary opacity-0 group-hover:opacity-100 transition-opacity`,children:`Open in Studio →`})]})]},e.id))})}),(0,Y.jsxs)(`div`,{className:`flex-shrink-0 px-6 py-3 border-t border-border flex items-center justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:`Tip: click a tag pill on any card to filter by that tag.`}),(0,Y.jsx)(u,{variant:`ghost`,size:`sm`,onClick:me,children:`Cancel`})]})]})}),ge=()=>(0,Y.jsx)(c,{open:B,onOpenChange:e=>{!e&&!G&&(H(!1),oe(null))},children:(0,Y.jsxs)(o,{className:`max-w-lg`,children:[(0,Y.jsx)(n,{children:(0,Y.jsxs)(z,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(f,{className:`w-4 h-4 text-accent-primary`}),` Generate a custom agent`]})}),(0,Y.jsxs)(`div`,{className:`space-y-3 py-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Agent id`}),(0,Y.jsx)(M,{value:U,onChange:e=>ne(e.target.value),placeholder:`custom-my-agent`,className:`text-sm font-mono`,disabled:G}),(0,Y.jsxs)(`p`,{className:`text-[11px] text-muted-foreground mt-1`,children:[`Must start with `,(0,Y.jsx)(`code`,{children:`custom-`}),`.`]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Describe what this agent should do`}),(0,Y.jsx)(`textarea`,{value:re,onChange:e=>W(e.target.value),placeholder:`e.g. Review Terraform/IaC changes and flag security misconfigurations, excessive IAM permissions, and public S3 buckets before merging. Conservative and terse.`,className:`w-full text-sm p-2 rounded border border-border bg-background min-h-[120px] resize-y`,disabled:G})]}),K&&(0,Y.jsx)(`div`,{className:`px-3 py-2 text-xs rounded border border-red-500/30 bg-red-500/10 text-red-400`,children:K}),(0,Y.jsxs)(`p`,{className:`text-[11px] text-muted-foreground`,children:[`Claude will draft a full `,(0,Y.jsx)(`code`,{children:`.md`}),` body. You'll review it in the Studio and can edit before saving. This spawns a one-shot claude invocation and can take up to 90 seconds.`]})]}),(0,Y.jsxs)(V,{children:[(0,Y.jsx)(u,{variant:`ghost`,size:`sm`,onClick:()=>H(!1),disabled:G,children:`Cancel`}),(0,Y.jsx)(u,{size:`sm`,onClick:_e,disabled:G||!U.trim()||!re.trim(),children:G?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(j,{className:`w-3.5 h-3.5 mr-1.5 animate-spin`}),` Generating…`]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(f,{className:`w-3.5 h-3.5 mr-1.5`}),` Generate`]})})]})]})}),_e=async()=>{ie(!0),oe(null);try{let e=await fetch(`${C()}/profiles/catalog/generate`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:U.trim(),description:re.trim()})});if(!e.ok){let t=await e.json().catch(()=>({}));throw Error(t.error??`Generate failed: ${e.status}`)}let t=await e.json();H(!1),x({kind:`create`,initialBody:t.draft,initialName:U.trim()})}catch(e){oe(e.message)}finally{ie(!1)}},ve=async e=>{try{let t=await fetch(`${C()}/profiles/catalog/${encodeURIComponent(e)}`);if(!t.ok)throw Error(`Load failed: ${t.status}`);x({kind:`duplicate`,from:e,initialBody:(await t.json()).body})}catch(e){y(e.message)}};if(e.length===0)return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,Y.jsxs)(`div`,{className:`text-center max-w-sm`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:`No agents installed`}),(0,Y.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-1 mb-4`,children:[`Run `,(0,Y.jsx)(`code`,{className:`text-foreground`,children:`npx specrails-core@latest update`}),` in this project to install the upstream agents, or create a custom agent now.`]}),(0,Y.jsxs)(`div`,{className:`flex gap-2 justify-center flex-wrap`,children:[(0,Y.jsxs)(u,{size:`sm`,onClick:()=>H(!0),children:[(0,Y.jsx)(f,{className:`w-3.5 h-3.5 mr-1.5`}),` Generate with Claude`]}),(0,Y.jsxs)(u,{size:`sm`,variant:`ghost`,onClick:()=>k(!0),children:[(0,Y.jsx)(F,{className:`w-3.5 h-3.5 mr-1.5`}),` Template`]}),(0,Y.jsxs)(u,{size:`sm`,variant:`ghost`,onClick:()=>x({kind:`create`}),children:[(0,Y.jsx)(p,{className:`w-3.5 h-3.5 mr-1.5`}),` Blank`]})]})]})}),he(),ge()]});let Q=e.filter(e=>e.kind===`upstream`),xe=e.filter(e=>e.kind===`custom`),$=e.find(e=>e.id===r);return(0,Y.jsxs)(Y.Fragment,{children:[he(),ge(),(0,Y.jsxs)(`div`,{className:`flex h-full`,children:[(0,Y.jsxs)(`aside`,{className:`w-72 flex-shrink-0 border-r border-border flex flex-col`,children:[(0,Y.jsxs)(`div`,{className:`px-3 py-2 border-b border-border`,children:[(0,Y.jsx)(`div`,{className:`text-[11px] text-muted-foreground uppercase tracking-wide mb-1.5`,children:`Catalog`}),(0,Y.jsx)(`div`,{className:`text-[10px] text-muted-foreground/70 mb-2`,children:`Create a custom agent:`}),(0,Y.jsxs)(`div`,{className:`flex gap-1`,children:[(0,Y.jsxs)(u,{size:`sm`,variant:`ghost`,className:`flex-1 h-7 text-[11px] px-2`,onClick:()=>k(!0),title:`Start from a template`,children:[(0,Y.jsx)(F,{className:`w-3 h-3 mr-1`}),` Template`]}),(0,Y.jsxs)(u,{size:`sm`,variant:`ghost`,className:`flex-1 h-7 text-[11px] px-2`,onClick:()=>H(!0),title:`Generate with Claude`,children:[(0,Y.jsx)(f,{className:`w-3 h-3 mr-1`}),` Generate`]}),(0,Y.jsxs)(u,{size:`sm`,variant:`ghost`,className:`flex-1 h-7 text-[11px] px-2`,onClick:()=>x({kind:`create`}),title:`Start from a blank template`,children:[(0,Y.jsx)(p,{className:`w-3 h-3 mr-1`}),` Blank`]})]})]}),(0,Y.jsxs)(`div`,{className:`flex-1 overflow-auto p-2`,children:[(0,Y.jsx)(tt,{title:`Upstream (${Q.length})`,description:`Shipped by specrails-core; read-only.`,children:Q.map(e=>(0,Y.jsx)(nt,{agent:e,selected:e.id===r,onSelect:()=>i(e.id)},e.id))}),(0,Y.jsx)(tt,{title:`Custom (${xe.length})`,description:`Your project's custom-*.md files. Use Template / Generate / Blank above to create one.`,children:xe.length===0?(0,Y.jsx)(`div`,{className:`text-[11px] text-muted-foreground px-2 py-2 italic`,children:`No custom agents yet.`}):xe.map(e=>(0,Y.jsx)(nt,{agent:e,selected:e.id===r,onSelect:()=>i(e.id)},e.id))})]})]}),(0,Y.jsxs)(`main`,{className:`flex-1 min-w-0 overflow-auto`,children:[v&&(0,Y.jsx)(`div`,{className:`m-4 px-3 py-2 text-xs rounded border border-red-500/30 bg-red-500/10 text-red-400`,children:v}),$&&(0,Y.jsxs)(`div`,{className:`p-6 min-w-0`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start justify-between gap-4 mb-1`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,Y.jsx)(`h2`,{className:`text-base font-mono font-semibold`,children:$.id}),(0,Y.jsx)(rt,{kind:$.kind}),$.model&&(0,Y.jsxs)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:[`default model: `,$.model]})]}),$.description&&(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1 break-words`,children:$.description})]}),(0,Y.jsxs)(`div`,{className:`flex gap-2 flex-shrink-0`,children:[(0,Y.jsxs)(u,{size:`sm`,variant:`ghost`,onClick:()=>void ve($.id),children:[(0,Y.jsx)(te,{className:`w-3.5 h-3.5 mr-1`}),` Duplicate`]}),$.kind===`custom`&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(u,{size:`sm`,variant:`ghost`,onClick:()=>x({kind:`edit`,agentId:$.id}),children:[(0,Y.jsx)(A,{className:`w-3.5 h-3.5 mr-1`}),` Edit`]}),(0,Y.jsxs)(u,{size:`sm`,onClick:async()=>{try{let e=await fetch(`${C()}/profiles/catalog/${encodeURIComponent($.id)}`);if(!e.ok)throw Error(`Load failed: ${e.status}`);let t=await e.json();Z(),X.current={refineId:null},D({kind:`open`,agentId:$.id,baseBody:t.body})}catch(e){y(e.message)}},title:`Iteratively refine this agent with AI`,children:[(0,Y.jsx)(ce,{className:`w-3.5 h-3.5 mr-1`}),` AI Edit`]})]})]})]}),(0,Y.jsxs)(`div`,{className:`rounded-md border border-border bg-muted/30 mt-4 min-w-0 overflow-hidden`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-1.5 border-b border-border`,children:[(0,Y.jsxs)(`span`,{className:`text-[11px] font-mono text-muted-foreground truncate`,children:[`.claude/agents/`,$.id,`.md`]}),(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground flex-shrink-0 ml-2`,children:$.kind===`upstream`?`read-only`:`editable — use Edit above`})]}),(0,Y.jsx)(`pre`,{className:`p-4 text-xs font-mono overflow-auto max-h-[60vh] whitespace-pre-wrap break-all`,children:m?`Loading…`:a??``})]})]})]})]})]})}function et({label:e,count:t,active:n,onClick:r}){return(0,Y.jsxs)(`button`,{type:`button`,onClick:r,className:`flex-shrink-0 inline-flex items-center gap-1 h-7 px-2.5 text-[11px] rounded-full border transition-colors whitespace-nowrap `+(n?`bg-accent-primary/20 border-accent-primary/50 text-accent-primary`:`bg-transparent border-border text-muted-foreground hover:bg-accent/50 hover:text-foreground`),children:[e,(0,Y.jsx)(`span`,{className:`text-[9px] px-1 rounded `+(n?`bg-accent-primary/30`:`bg-muted/60`),children:t})]})}function tt({title:e,description:t,children:n}){return(0,Y.jsxs)(`div`,{className:`mb-4`,children:[(0,Y.jsxs)(`div`,{className:`px-2 pb-1`,children:[(0,Y.jsx)(`div`,{className:`text-[11px] font-medium text-muted-foreground uppercase tracking-wide`,children:e}),t&&(0,Y.jsx)(`div`,{className:`text-[11px] text-muted-foreground/70 mt-0.5`,children:t})]}),(0,Y.jsx)(`div`,{className:`space-y-0.5`,children:n})]})}function nt({agent:e,selected:t,onSelect:n}){return(0,Y.jsxs)(`button`,{type:`button`,onClick:n,className:`w-full flex items-center justify-between gap-2 px-2 py-1.5 text-left rounded transition-colors `+(t?`bg-accent text-foreground`:`text-muted-foreground hover:bg-accent/50 hover:text-foreground`),children:[(0,Y.jsx)(`span`,{className:`text-sm font-mono truncate`,children:e.id}),(0,Y.jsx)(rt,{kind:e.kind})]})}function rt({kind:e}){return(0,Y.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded flex-shrink-0 `+(e===`custom`?`bg-purple-500/15 text-purple-400`:`bg-muted text-muted-foreground`),children:e})}var it=[{label:`7d`,days:7},{label:`30d`,days:30},{label:`90d`,days:90}];function at(){let[e,t]=(0,J.useState)(null),[n,r]=(0,J.useState)(30),[i,a]=(0,J.useState)(!0);if((0,J.useEffect)(()=>{let e=!1;return a(!0),fetch(`${C()}/profiles/analytics?windowDays=${n}`).then(e=>e.ok?e.json():null).then(n=>{!e&&n&&t(n)}).catch(()=>{}).finally(()=>{e||a(!1)}),()=>{e=!0}},[n]),i&&!e)return null;if(!e||e.rows.length===0)return(0,Y.jsxs)(`div`,{className:`mx-6 my-4 rounded-md border border-border bg-muted/20`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b border-border`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-xs font-medium text-foreground`,children:`Profile usage`}),(0,Y.jsx)(`div`,{className:`text-[11px] text-muted-foreground`,children:`Jobs launched per profile in the selected window.`})]}),(0,Y.jsx)(`div`,{className:`flex gap-0.5`,children:it.map(e=>(0,Y.jsx)(`button`,{type:`button`,onClick:()=>r(e.days),className:`text-[10px] px-2 py-1 rounded transition-colors `+(n===e.days?`bg-accent text-foreground`:`text-muted-foreground hover:bg-accent/50 hover:text-foreground`),children:e.label},e.days))})]}),(0,Y.jsx)(`div`,{className:`px-4 py-8 text-xs text-muted-foreground`,children:`No profile-scoped jobs yet.`})]});let o=Math.max(...e.rows.map(e=>e.jobs),1);return(0,Y.jsxs)(`div`,{className:`mx-6 my-4 rounded-md border border-border bg-muted/20`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b border-border`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-xs font-medium text-foreground`,children:`Profile usage`}),(0,Y.jsxs)(`div`,{className:`text-[11px] text-muted-foreground`,children:[`Jobs launched per profile in the last `,e.windowDays,` days.`]})]}),(0,Y.jsx)(`div`,{className:`flex gap-0.5`,children:it.map(e=>(0,Y.jsx)(`button`,{type:`button`,onClick:()=>r(e.days),className:`text-[10px] px-2 py-1 rounded transition-colors `+(n===e.days?`bg-accent text-foreground`:`text-muted-foreground hover:bg-accent/50 hover:text-foreground`),children:e.label},e.days))})]}),(0,Y.jsx)(`div`,{className:`p-4 space-y-2`,children:e.rows.map(e=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(`div`,{className:`w-32 text-xs font-mono truncate`,children:e.profileName}),(0,Y.jsx)(`div`,{className:`flex-1 h-4 bg-muted/50 rounded overflow-hidden`,children:(0,Y.jsx)(`div`,{className:`h-full bg-accent-primary/70`,style:{width:`${Math.max(6,Math.round(e.jobs/o*100))}%`}})}),(0,Y.jsxs)(`div`,{className:`flex gap-4 text-[11px] text-muted-foreground min-w-0 flex-shrink-0`,children:[(0,Y.jsxs)(`span`,{title:`jobs`,children:[(0,Y.jsx)(`span`,{className:`text-foreground font-mono`,children:e.jobs}),` jobs`]}),(0,Y.jsxs)(`span`,{title:`success rate`,children:[(0,Y.jsxs)(`span`,{className:`text-foreground font-mono`,children:[Math.round(e.successRate*100),`%`]}),` `,`ok`]}),e.avgDurationMs!=null&&(0,Y.jsx)(`span`,{title:`avg duration`,children:(0,Y.jsx)(`span`,{className:`text-foreground font-mono`,children:ot(e.avgDurationMs)})}),e.avgTokens!=null&&(0,Y.jsxs)(`span`,{title:`avg tokens`,children:[(0,Y.jsx)(`span`,{className:`text-foreground font-mono`,children:st(e.avgTokens)}),` `,`tok`]})]})]},e.profileName))})]})}function ot(e){let t=Math.round(e/1e3);if(t<60)return`${t}s`;let n=Math.floor(t/60);return n<60?`${n}m`:`${Math.floor(n/60)}h${n%60}m`}function st(e){return e<1e3?Math.round(e).toString():e<1e6?`${(e/1e3).toFixed(1)}k`:`${(e/1e6).toFixed(1)}M`}var ct=`specrails-hub:agents-tab`;function lt(){try{let e=localStorage.getItem(ct);if(e===`profiles`||e===`usage`||e===`catalog`)return e}catch{}return`profiles`}function ut(){let[e,t]=(0,J.useState)(()=>lt()),n=e=>{t(e);try{localStorage.setItem(ct,e)}catch{}},[r,i]=(0,J.useState)(null);return(0,J.useEffect)(()=>{let e=!1;return fetch(`${C()}/profiles/core-version`).then(e=>e.ok?e.json():null).then(t=>{!e&&t&&i(t)}).catch(()=>{}),()=>{e=!0}},[]),(0,Y.jsxs)(`div`,{className:`flex flex-col h-full bg-background`,children:[r!==null&&!r.profileAware&&(0,Y.jsxs)(`div`,{className:`flex-shrink-0 flex items-start gap-3 px-6 py-3 border-b border-yellow-500/30 bg-yellow-500/10`,children:[(0,Y.jsx)(K,{className:`w-4 h-4 text-yellow-500 mt-0.5 flex-shrink-0`}),(0,Y.jsxs)(`div`,{className:`text-xs`,children:[(0,Y.jsxs)(`div`,{className:`font-medium text-yellow-500`,children:[`Profile-aware pipeline requires specrails-core `,r.required,`+`]}),(0,Y.jsxs)(`div`,{className:`text-yellow-500/80 mt-0.5`,children:[`This project has`,` `,(0,Y.jsx)(`code`,{className:`px-1 rounded bg-yellow-500/20`,children:r.version??`unknown`}),`. Run`,` `,(0,Y.jsx)(`code`,{className:`px-1 rounded bg-yellow-500/20`,children:`npx specrails-core@latest update`}),` `,`inside the project to unlock profile mode. Profiles you create here will still save; they just won't affect the pipeline until core is updated.`]})]})]}),(0,Y.jsxs)(`div`,{className:`flex-shrink-0 border-b border-border`,children:[(0,Y.jsxs)(`div`,{className:`px-6 pt-4`,children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Agents`}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:`Manage agent profiles and the catalog (upstream + custom) for this project.`})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 px-4 pt-3`,children:[(0,Y.jsx)(ft,{active:e===`profiles`,onClick:()=>n(`profiles`),children:`Profiles`}),(0,Y.jsx)(ft,{active:e===`usage`,onClick:()=>n(`usage`),children:`Usage`}),(0,Y.jsx)(ft,{active:e===`catalog`,onClick:()=>n(`catalog`),children:`Catalog`})]})]}),(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0 overflow-auto`,children:[e===`profiles`&&(0,Y.jsx)(ve,{}),e===`usage`&&(0,Y.jsx)(dt,{}),e===`catalog`&&(0,Y.jsx)($e,{})]})]})}function dt(){return(0,Y.jsx)(`div`,{className:`min-h-full`,children:(0,Y.jsx)(at,{})})}function ft({active:e,children:t,onClick:n}){return(0,Y.jsx)(`button`,{type:`button`,onClick:n,className:`h-8 px-3 text-xs font-medium rounded-t-md border-b-2 transition-colors `+(e?`text-foreground border-foreground`:`text-muted-foreground border-transparent hover:text-foreground hover:border-border`),children:t})}export{ut as default};
|
|
86
|
+
`});return i}function qe({value:e,onChange:t,onSubmit:n,disabled:r,placeholder:i,autoFocus:a,inputRef:o}){return(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsxs)(`div`,{className:`relative rounded-xl border border-border bg-card/40 focus-within:border-accent-primary/40 focus-within:ring-2 focus-within:ring-accent-primary/20 transition-all`,children:[(0,Y.jsx)(`textarea`,{ref:o,value:e,onChange:e=>t(e.target.value),placeholder:i,rows:3,disabled:r,autoFocus:a,className:`w-full text-sm p-3 pr-14 bg-transparent resize-none focus:outline-none disabled:opacity-50 placeholder:text-muted-foreground/60`,onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),n())}}),(0,Y.jsx)(`button`,{type:`button`,onClick:n,disabled:!e.trim()||r,"aria-label":`Send (⌘⏎)`,className:`absolute bottom-2.5 right-2.5 p-2 rounded-md bg-accent-primary text-white hover:bg-accent-primary/90 disabled:opacity-30 disabled:cursor-not-allowed focus-visible:ring-2 focus-visible:ring-primary/40 focus-visible:outline-none transition-opacity`,children:r?(0,Y.jsx)(j,{className:`w-3.5 h-3.5 animate-spin`}):(0,Y.jsx)(Je,{})})]}),(0,Y.jsx)(`div`,{className:`flex items-center justify-end text-[11px] text-muted-foreground/70`,children:(0,Y.jsxs)(`span`,{children:[(0,Y.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted/60 text-[10px] font-mono`,children:`⌘⏎`}),` submit`,(0,Y.jsx)(`span`,{className:`mx-1.5`,children:`·`}),(0,Y.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted/60 text-[10px] font-mono`,children:`Esc`}),` cancel`]})})]})}function Je(){return(0,Y.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,className:`w-3.5 h-3.5`,children:[(0,Y.jsx)(`path`,{d:`M22 2 11 13`}),(0,Y.jsx)(`path`,{d:`M22 2 15 22l-4-9-9-4Z`})]})}var Ye=[`Tighten the tool list`,`Make the personality stricter`,`Add a Workflow protocol section`,`Shorten and sharpen the description`,`Match the sr-developer style`];function Xe({agentId:e,baseBody:t,resumeRefineId:n,onClose:r,onMinimize:i,onStateChange:a,onOpenInStudio:o,onApplied:s}){let{activeProjectId:c}=ae(),l=De(c),[u,d]=(0,J.useState)(``),f=(0,J.useRef)(null),p=(0,J.useRef)(!1);(0,J.useEffect)(()=>{p.current||(p.current=!0,n?l.rehydrate(n,e):l.open(e,t))},[e,t,n,l]),(0,J.useEffect)(()=>{let e=setTimeout(()=>f.current?.focus(),50);return()=>clearTimeout(e)},[]);let m=(0,J.useRef)(a);m.current=a,(0,J.useEffect)(()=>{m.current?.({refineId:l.state.refineId??null})},[l.state.refineId]);let h=(0,J.useRef)(null);(0,J.useEffect)(()=>{l.state.uiState===`applied`&&l.state.appliedVersion!==null&&l.state.appliedVersion!==h.current&&(h.current=l.state.appliedVersion,s&&l.state.agentId&&s(l.state.agentId,l.state.appliedVersion))},[l.state.uiState,l.state.appliedVersion,l.state.agentId,s]);let g=(0,J.useCallback)(async e=>{let t=e.trim();t&&(d(``),l.state.refineId?await l.sendTurn(t):await l.start(t))},[l]),_=(0,J.useCallback)(()=>{g(u)},[u,g]),v=(0,J.useCallback)(async()=>{l.state.refineId&&(l.state.uiState===`streaming`||l.state.uiState===`reviewing`)&&await l.cancel(),r()},[l,r]),y=Ze(l.state),b=(0,J.useMemo)(()=>!l.state.draftBody||!l.state.baseBody?null:(0,Y.jsx)(Ue,{hunks:Ge(l.state.baseBody,l.state.draftBody)}),[l.state.baseBody,l.state.draftBody]);return(0,Y.jsx)(ke,{uiPhase:y,errorMessage:l.state.errorMessage,applyConflict:l.state.applyConflict,eyebrow:`AI Edit`,targetLabel:e,targetLabelMono:!0,headline:`Refine your agent`,streamingHeadline:`Refining your agent…`,description:Qe(t),chips:Ye,onChipSubmit:e=>void g(e),composer:(0,Y.jsx)(qe,{value:u,onChange:d,onSubmit:_,disabled:y===`streaming`||y===`applied`,placeholder:l.state.refineId?`Send a follow-up refinement…`:`Describe how to refine this agent…`,inputRef:f}),streamingText:l.state.streamingText,history:l.state.history,diff:b,diffHeaderLabel:`.claude/agents/${e}.md`,baseBody:t,baseBodyDisclosureLabel:`View current agent body`,appliedNotice:l.state.appliedVersion===null?void 0:(0,Y.jsxs)(`div`,{className:`rounded-md border border-green-500/40 bg-green-500/10 p-3 text-xs text-green-300`,children:[`Applied as version `,l.state.appliedVersion,`.`]}),canApply:l.state.uiState===`reviewing`&&!!l.state.draftBody&&!l.state.applyConflict,onApply:()=>void l.apply(),onForceApply:()=>void l.apply(!0),onDiscard:()=>void v(),onClose:()=>void v(),onMinimize:i?()=>i(l.state.refineId??null):void 0,secondaryAction:o&&l.state.draftBody&&l.state.refineId?{label:`Open draft in Studio for manual editing`,icon:(0,Y.jsx)(ne,{className:`w-3 h-3`}),onClick:()=>{l.state.refineId&&l.state.draftBody&&o&&o(l.state.refineId,l.state.draftBody)}}:void 0})}function Ze(e){switch(e.uiState){case`streaming`:return`streaming`;case`reviewing`:return`reviewing`;case`applied`:return`applied`;case`error`:return`error`;default:return`composing`}}function Qe(e){let t=e.match(/^---\r?\n([\s\S]*?)\r?\n---/);if(!t)return null;let n=t[1].match(/^description:\s*([\s\S]*?)(?=^[a-z_]+:\s|\Z)/m);if(!n)return null;let r=n[1].trim();return(r.startsWith(`"`)&&r.endsWith(`"`)||r.startsWith(`'`)&&r.endsWith(`'`))&&(r=r.slice(1,-1)),r=r.replace(/\\n/g,` `).replace(/\\t/g,` `).replace(/\\"/g,`"`).replace(/\\'/g,`'`).replace(/\\\\/g,`\\`).replace(/\s+/g,` `).trim(),r.length>240&&(r=r.slice(0,237)+`…`),r||null}function $e(){let[e,t]=(0,J.useState)([]),[r,i]=(0,J.useState)(null),[a,s]=(0,J.useState)(null),[l,d]=(0,J.useState)(!0),[m,g]=(0,J.useState)(!1),[v,y]=(0,J.useState)(null),[b,x]=(0,J.useState)({kind:`closed`}),[w,D]=(0,J.useState)({kind:`closed`}),[O,k]=(0,J.useState)(!1),[N,ee]=(0,J.useState)(``),[P,I]=(0,J.useState)(`all`),[L,R]=(0,J.useState)(null),[B,H]=(0,J.useState)(!1),[U,ne]=(0,J.useState)(``),[re,W]=(0,J.useState)(``),[G,ie]=(0,J.useState)(!1),[K,oe]=(0,J.useState)(null),{activeProjectId:q}=ae(),{minimize:se}=h(),X=(0,J.useRef)({refineId:null}),le=(0,J.useRef)(w);le.current=w;let Z=(0,J.useCallback)(()=>{let e=le.current;e.kind!==`open`||!q||se({kind:`ai-edit`,projectId:q,label:`AI Edit · ${e.agentId}`,restoreRoute:`/agents`,params:{agentId:e.agentId,baseBody:e.baseBody,resumeRefineId:X.current.refineId??e.resumeRefineId}})},[q,se]);_(`ai-edit`,q,e=>{e.kind===`ai-edit`&&(Z(),X.current={refineId:e.params.resumeRefineId??null},D({kind:`open`,agentId:e.params.agentId,baseBody:e.params.baseBody,resumeRefineId:e.params.resumeRefineId}))});let ue=(0,J.useCallback)(()=>{let e=!1;return d(!0),fetch(`${C()}/profiles/catalog`).then(e=>{if(!e.ok)throw Error(`Catalog load failed: ${e.status}`);return e.json()}).then(n=>{e||(t(n.agents),n.agents.length>0&&!r&&i(n.agents[0].id))}).catch(t=>{e||y(t.message)}).finally(()=>{e||d(!1)}),()=>{e=!0}},[r]);(0,J.useEffect)(()=>ue(),[ue]);let de=(0,J.useCallback)(e=>{let t=!1;return g(!0),s(null),fetch(`${C()}/profiles/catalog/${encodeURIComponent(e)}`).then(e=>{if(!e.ok)throw Error(`Agent body load failed: ${e.status}`);return e.json()}).then(e=>{t||s(e.body)}).catch(e=>{t||y(e.message)}).finally(()=>{t||g(!1)}),()=>{t=!0}},[]);if((0,J.useEffect)(()=>{if(r)return de(r)},[r,de]),l)return(0,Y.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading catalog…`})});if(b.kind!==`closed`)return(0,Y.jsx)(Se,{agentId:b.kind===`edit`?b.agentId:void 0,initialBody:b.kind===`duplicate`||b.kind===`create`?b.initialBody:void 0,initialName:b.kind===`create`?b.initialName:void 0,draftFromRefine:b.kind===`edit`?b.draftFromRefine:void 0,onClose:()=>x({kind:`closed`}),onSaved:e=>{i(e),x({kind:`closed`}),ue()},onResumeRefine:(e,t,n)=>{x({kind:`closed`}),Z(),X.current={refineId:e},D({kind:`open`,agentId:t,baseBody:n,resumeRefineId:e})}});if(w.kind===`open`)return(0,Y.jsx)(Xe,{agentId:w.agentId,baseBody:w.baseBody,resumeRefineId:w.resumeRefineId,onStateChange:e=>{X.current=e},onClose:()=>D({kind:`closed`}),onMinimize:e=>{if(!q){D({kind:`closed`});return}let t=w.kind===`open`?w.agentId:``,n=w.kind===`open`?w.baseBody:``;se({kind:`ai-edit`,projectId:q,label:`AI Edit · ${t}`,restoreRoute:`/agents`,params:{agentId:t,baseBody:n,resumeRefineId:e??void 0}}),D({kind:`closed`})},onApplied:e=>{D({kind:`closed`}),i(e),ue()},onOpenInStudio:(e,t)=>{D({kind:`closed`}),x({kind:`edit`,agentId:w.agentId,draftFromRefine:e})}},`${w.agentId}:${w.resumeRefineId??`fresh`}`);let fe=(()=>{let e=N.trim().toLowerCase();return ye.filter(t=>!(P!==`all`&&t.category!==P||L&&!t.tags.includes(L)||e&&!(t.label+` `+t.blurb+` `+t.tags.join(` `)+` `+t.category).toLowerCase().includes(e)))})(),pe=(()=>{let e=new Map;for(let t of ye)e.set(t.category,(e.get(t.category)??0)+1);return e})(),me=()=>{k(!1),ee(``),I(`all`),R(null)},he=()=>(0,Y.jsx)(c,{open:O,onOpenChange:e=>{e||me()},children:(0,Y.jsxs)(o,{className:`max-w-4xl p-0 h-[85vh] flex flex-col overflow-hidden`,children:[(0,Y.jsxs)(`div`,{className:`flex-shrink-0 px-6 pt-5 pb-3 border-b border-border`,children:[(0,Y.jsxs)(n,{children:[(0,Y.jsxs)(z,{className:`flex items-center gap-2 text-base`,children:[(0,Y.jsx)(F,{className:`w-4 h-4 text-accent-primary`}),` Agent template library`,(0,Y.jsxs)(`span`,{className:`text-[11px] font-normal text-muted-foreground ml-1`,children:[fe.length,` of `,ye.length]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:`Start from a curated template across engineering, product, science, health, legal, and more. Pick one and open it in the Studio for review and editing before saving.`})]}),(0,Y.jsxs)(`div`,{className:`mt-3 relative`,children:[(0,Y.jsx)(T,{className:`w-3.5 h-3.5 absolute left-2.5 top-1/2 -translate-y-1/2 text-muted-foreground pointer-events-none`}),(0,Y.jsx)(`input`,{value:N,onChange:e=>ee(e.target.value),placeholder:`Search by name, description, tag, or category…`,className:`w-full h-9 pl-8 pr-8 text-sm rounded-md border border-border bg-background focus:outline-none focus:ring-1 focus:ring-primary/40`,autoFocus:!0}),N&&(0,Y.jsx)(`button`,{type:`button`,onClick:()=>ee(``),className:`absolute right-2 top-1/2 -translate-y-1/2 p-0.5 rounded hover:bg-accent text-muted-foreground`,children:(0,Y.jsx)(S,{className:`w-3.5 h-3.5`})})]}),(0,Y.jsxs)(`div`,{className:`flex gap-1.5 overflow-x-auto mt-3 pb-1 scrollbar-thin`,children:[(0,Y.jsx)(et,{label:`All`,count:ye.length,active:P===`all`,onClick:()=>I(`all`)}),be.map(e=>(0,Y.jsx)(et,{label:e,count:pe.get(e)??0,active:P===e,onClick:()=>I(e)},e))]}),L&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mt-2`,children:[(0,Y.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:`Tag filter:`}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>R(null),className:`inline-flex items-center gap-1 text-[11px] px-2 py-0.5 rounded-full bg-accent-primary/20 text-accent-primary hover:bg-accent-primary/30`,children:[(0,Y.jsx)(E,{className:`w-3 h-3`}),` `,L,(0,Y.jsx)(S,{className:`w-3 h-3`})]})]})]}),(0,Y.jsx)(`div`,{className:`flex-1 overflow-y-auto px-6 py-4`,children:fe.length===0?(0,Y.jsx)(`div`,{className:`h-full flex items-center justify-center text-center`,children:(0,Y.jsxs)(`div`,{className:`max-w-sm`,children:[(0,Y.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:`No templates match your filters.`}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>{ee(``),I(`all`),R(null)},className:`text-xs text-accent-primary hover:underline mt-2`,children:`Clear filters`})]})}):(0,Y.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:fe.map(e=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{me(),x({kind:`create`,initialBody:e.body,initialName:e.nameHint})},className:`group text-left p-4 rounded-lg border border-border bg-card/40 hover:border-accent-primary/50 hover:bg-accent/40 hover:shadow-sm transition-all`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start gap-3 mb-2`,children:[(0,Y.jsx)(`span`,{className:`text-2xl leading-none mt-0.5`,children:e.emoji}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-semibold text-foreground group-hover:text-accent-primary truncate`,children:e.label}),(0,Y.jsx)(`div`,{className:`text-[10px] text-muted-foreground mt-0.5`,children:e.category})]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground leading-relaxed line-clamp-2 min-h-[2lh]`,children:e.blurb}),(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-1 mt-3`,children:e.tags.slice(0,5).map(e=>(0,Y.jsx)(`span`,{role:`button`,tabIndex:0,onClick:t=>{t.stopPropagation(),R(e)},onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),t.stopPropagation(),R(e))},className:`text-[10px] px-1.5 py-0.5 rounded bg-muted/50 text-muted-foreground hover:bg-accent-primary/20 hover:text-accent-primary cursor-pointer transition-colors `+(L===e?`bg-accent-primary/20 text-accent-primary`:``),children:e},e))}),(0,Y.jsxs)(`div`,{className:`mt-3 pt-2 border-t border-border/40 flex items-center justify-between`,children:[(0,Y.jsx)(`code`,{className:`text-[10px] font-mono text-muted-foreground/70 truncate`,children:e.nameHint}),(0,Y.jsx)(`span`,{className:`text-[10px] text-accent-primary opacity-0 group-hover:opacity-100 transition-opacity`,children:`Open in Studio →`})]})]},e.id))})}),(0,Y.jsxs)(`div`,{className:`flex-shrink-0 px-6 py-3 border-t border-border flex items-center justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:`Tip: click a tag pill on any card to filter by that tag.`}),(0,Y.jsx)(u,{variant:`ghost`,size:`sm`,onClick:me,children:`Cancel`})]})]})}),ge=()=>(0,Y.jsx)(c,{open:B,onOpenChange:e=>{!e&&!G&&(H(!1),oe(null))},children:(0,Y.jsxs)(o,{className:`max-w-lg`,children:[(0,Y.jsx)(n,{children:(0,Y.jsxs)(z,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(f,{className:`w-4 h-4 text-accent-primary`}),` Generate a custom agent`]})}),(0,Y.jsxs)(`div`,{className:`space-y-3 py-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Agent id`}),(0,Y.jsx)(M,{value:U,onChange:e=>ne(e.target.value),placeholder:`custom-my-agent`,className:`text-sm font-mono`,disabled:G}),(0,Y.jsxs)(`p`,{className:`text-[11px] text-muted-foreground mt-1`,children:[`Must start with `,(0,Y.jsx)(`code`,{children:`custom-`}),`.`]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Describe what this agent should do`}),(0,Y.jsx)(`textarea`,{value:re,onChange:e=>W(e.target.value),placeholder:`e.g. Review Terraform/IaC changes and flag security misconfigurations, excessive IAM permissions, and public S3 buckets before merging. Conservative and terse.`,className:`w-full text-sm p-2 rounded border border-border bg-background min-h-[120px] resize-y`,disabled:G})]}),K&&(0,Y.jsx)(`div`,{className:`px-3 py-2 text-xs rounded border border-red-500/30 bg-red-500/10 text-red-400`,children:K}),(0,Y.jsxs)(`p`,{className:`text-[11px] text-muted-foreground`,children:[`Claude will draft a full `,(0,Y.jsx)(`code`,{children:`.md`}),` body. You'll review it in the Studio and can edit before saving. This spawns a one-shot claude invocation and can take up to 90 seconds.`]})]}),(0,Y.jsxs)(V,{children:[(0,Y.jsx)(u,{variant:`ghost`,size:`sm`,onClick:()=>H(!1),disabled:G,children:`Cancel`}),(0,Y.jsx)(u,{size:`sm`,onClick:_e,disabled:G||!U.trim()||!re.trim(),children:G?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(j,{className:`w-3.5 h-3.5 mr-1.5 animate-spin`}),` Generating…`]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(f,{className:`w-3.5 h-3.5 mr-1.5`}),` Generate`]})})]})]})}),_e=async()=>{ie(!0),oe(null);try{let e=await fetch(`${C()}/profiles/catalog/generate`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:U.trim(),description:re.trim()})});if(!e.ok){let t=await e.json().catch(()=>({}));throw Error(t.error??`Generate failed: ${e.status}`)}let t=await e.json();H(!1),x({kind:`create`,initialBody:t.draft,initialName:U.trim()})}catch(e){oe(e.message)}finally{ie(!1)}},ve=async e=>{try{let t=await fetch(`${C()}/profiles/catalog/${encodeURIComponent(e)}`);if(!t.ok)throw Error(`Load failed: ${t.status}`);x({kind:`duplicate`,from:e,initialBody:(await t.json()).body})}catch(e){y(e.message)}};if(e.length===0)return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,Y.jsxs)(`div`,{className:`text-center max-w-sm`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:`No agents installed`}),(0,Y.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-1 mb-4`,children:[`Run `,(0,Y.jsx)(`code`,{className:`text-foreground`,children:`npx specrails-core@latest update`}),` in this project to install the upstream agents, or create a custom agent now.`]}),(0,Y.jsxs)(`div`,{className:`flex gap-2 justify-center flex-wrap`,children:[(0,Y.jsxs)(u,{size:`sm`,onClick:()=>H(!0),children:[(0,Y.jsx)(f,{className:`w-3.5 h-3.5 mr-1.5`}),` Generate with Claude`]}),(0,Y.jsxs)(u,{size:`sm`,variant:`ghost`,onClick:()=>k(!0),children:[(0,Y.jsx)(F,{className:`w-3.5 h-3.5 mr-1.5`}),` Template`]}),(0,Y.jsxs)(u,{size:`sm`,variant:`ghost`,onClick:()=>x({kind:`create`}),children:[(0,Y.jsx)(p,{className:`w-3.5 h-3.5 mr-1.5`}),` Blank`]})]})]})}),he(),ge()]});let Q=e.filter(e=>e.kind===`upstream`),xe=e.filter(e=>e.kind===`custom`),$=e.find(e=>e.id===r);return(0,Y.jsxs)(Y.Fragment,{children:[he(),ge(),(0,Y.jsxs)(`div`,{className:`flex h-full`,children:[(0,Y.jsxs)(`aside`,{className:`w-72 flex-shrink-0 border-r border-border flex flex-col`,children:[(0,Y.jsxs)(`div`,{className:`px-3 py-2 border-b border-border`,children:[(0,Y.jsx)(`div`,{className:`text-[11px] text-muted-foreground uppercase tracking-wide mb-1.5`,children:`Catalog`}),(0,Y.jsx)(`div`,{className:`text-[10px] text-muted-foreground/70 mb-2`,children:`Create a custom agent:`}),(0,Y.jsxs)(`div`,{className:`flex gap-1`,children:[(0,Y.jsxs)(u,{size:`sm`,variant:`ghost`,className:`flex-1 h-7 text-[11px] px-2`,onClick:()=>k(!0),title:`Start from a template`,children:[(0,Y.jsx)(F,{className:`w-3 h-3 mr-1`}),` Template`]}),(0,Y.jsxs)(u,{size:`sm`,variant:`ghost`,className:`flex-1 h-7 text-[11px] px-2`,onClick:()=>H(!0),title:`Generate with Claude`,children:[(0,Y.jsx)(f,{className:`w-3 h-3 mr-1`}),` Generate`]}),(0,Y.jsxs)(u,{size:`sm`,variant:`ghost`,className:`flex-1 h-7 text-[11px] px-2`,onClick:()=>x({kind:`create`}),title:`Start from a blank template`,children:[(0,Y.jsx)(p,{className:`w-3 h-3 mr-1`}),` Blank`]})]})]}),(0,Y.jsxs)(`div`,{className:`flex-1 overflow-auto p-2`,children:[(0,Y.jsx)(tt,{title:`Upstream (${Q.length})`,description:`Shipped by specrails-core; read-only.`,children:Q.map(e=>(0,Y.jsx)(nt,{agent:e,selected:e.id===r,onSelect:()=>i(e.id)},e.id))}),(0,Y.jsx)(tt,{title:`Custom (${xe.length})`,description:`Your project's custom-*.md files. Use Template / Generate / Blank above to create one.`,children:xe.length===0?(0,Y.jsx)(`div`,{className:`text-[11px] text-muted-foreground px-2 py-2 italic`,children:`No custom agents yet.`}):xe.map(e=>(0,Y.jsx)(nt,{agent:e,selected:e.id===r,onSelect:()=>i(e.id)},e.id))})]})]}),(0,Y.jsxs)(`main`,{className:`flex-1 min-w-0 overflow-auto`,children:[v&&(0,Y.jsx)(`div`,{className:`m-4 px-3 py-2 text-xs rounded border border-red-500/30 bg-red-500/10 text-red-400`,children:v}),$&&(0,Y.jsxs)(`div`,{className:`p-6 min-w-0`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start justify-between gap-4 mb-1`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,Y.jsx)(`h2`,{className:`text-base font-mono font-semibold`,children:$.id}),(0,Y.jsx)(rt,{kind:$.kind}),$.model&&(0,Y.jsxs)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:[`default model: `,$.model]})]}),$.description&&(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1 break-words`,children:$.description})]}),(0,Y.jsxs)(`div`,{className:`flex gap-2 flex-shrink-0`,children:[(0,Y.jsxs)(u,{size:`sm`,variant:`ghost`,onClick:()=>void ve($.id),children:[(0,Y.jsx)(te,{className:`w-3.5 h-3.5 mr-1`}),` Duplicate`]}),$.kind===`custom`&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(u,{size:`sm`,variant:`ghost`,onClick:()=>x({kind:`edit`,agentId:$.id}),children:[(0,Y.jsx)(A,{className:`w-3.5 h-3.5 mr-1`}),` Edit`]}),(0,Y.jsxs)(u,{size:`sm`,onClick:async()=>{try{let e=await fetch(`${C()}/profiles/catalog/${encodeURIComponent($.id)}`);if(!e.ok)throw Error(`Load failed: ${e.status}`);let t=await e.json();Z(),X.current={refineId:null},D({kind:`open`,agentId:$.id,baseBody:t.body})}catch(e){y(e.message)}},title:`Iteratively refine this agent with AI`,children:[(0,Y.jsx)(ce,{className:`w-3.5 h-3.5 mr-1`}),` AI Edit`]})]})]})]}),(0,Y.jsxs)(`div`,{className:`rounded-md border border-border bg-muted/30 mt-4 min-w-0 overflow-hidden`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-1.5 border-b border-border`,children:[(0,Y.jsxs)(`span`,{className:`text-[11px] font-mono text-muted-foreground truncate`,children:[`.claude/agents/`,$.id,`.md`]}),(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground flex-shrink-0 ml-2`,children:$.kind===`upstream`?`read-only`:`editable — use Edit above`})]}),(0,Y.jsx)(`pre`,{className:`p-4 text-xs font-mono overflow-auto max-h-[60vh] whitespace-pre-wrap break-all`,children:m?`Loading…`:a??``})]})]})]})]})]})}function et({label:e,count:t,active:n,onClick:r}){return(0,Y.jsxs)(`button`,{type:`button`,onClick:r,className:`flex-shrink-0 inline-flex items-center gap-1 h-7 px-2.5 text-[11px] rounded-full border transition-colors whitespace-nowrap `+(n?`bg-accent-primary/20 border-accent-primary/50 text-accent-primary`:`bg-transparent border-border text-muted-foreground hover:bg-accent/50 hover:text-foreground`),children:[e,(0,Y.jsx)(`span`,{className:`text-[9px] px-1 rounded `+(n?`bg-accent-primary/30`:`bg-muted/60`),children:t})]})}function tt({title:e,description:t,children:n}){return(0,Y.jsxs)(`div`,{className:`mb-4`,children:[(0,Y.jsxs)(`div`,{className:`px-2 pb-1`,children:[(0,Y.jsx)(`div`,{className:`text-[11px] font-medium text-muted-foreground uppercase tracking-wide`,children:e}),t&&(0,Y.jsx)(`div`,{className:`text-[11px] text-muted-foreground/70 mt-0.5`,children:t})]}),(0,Y.jsx)(`div`,{className:`space-y-0.5`,children:n})]})}function nt({agent:e,selected:t,onSelect:n}){return(0,Y.jsxs)(`button`,{type:`button`,onClick:n,className:`w-full flex items-center justify-between gap-2 px-2 py-1.5 text-left rounded transition-colors `+(t?`bg-accent text-foreground`:`text-muted-foreground hover:bg-accent/50 hover:text-foreground`),children:[(0,Y.jsx)(`span`,{className:`text-sm font-mono truncate`,children:e.id}),(0,Y.jsx)(rt,{kind:e.kind})]})}function rt({kind:e}){return(0,Y.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded flex-shrink-0 `+(e===`custom`?`bg-purple-500/15 text-purple-400`:`bg-muted text-muted-foreground`),children:e})}var it=[{label:`7d`,days:7},{label:`30d`,days:30},{label:`90d`,days:90}];function at(){let[e,t]=(0,J.useState)(null),[n,r]=(0,J.useState)(30),[i,a]=(0,J.useState)(!0);if((0,J.useEffect)(()=>{let e=!1;return a(!0),fetch(`${C()}/profiles/analytics?windowDays=${n}`).then(e=>e.ok?e.json():null).then(n=>{!e&&n&&t(n)}).catch(()=>{}).finally(()=>{e||a(!1)}),()=>{e=!0}},[n]),i&&!e)return null;if(!e||e.rows.length===0)return(0,Y.jsxs)(`div`,{className:`mx-6 my-4 rounded-md border border-border bg-muted/20`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b border-border`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-xs font-medium text-foreground`,children:`Profile usage`}),(0,Y.jsx)(`div`,{className:`text-[11px] text-muted-foreground`,children:`Jobs launched per profile in the selected window.`})]}),(0,Y.jsx)(`div`,{className:`flex gap-0.5`,children:it.map(e=>(0,Y.jsx)(`button`,{type:`button`,onClick:()=>r(e.days),className:`text-[10px] px-2 py-1 rounded transition-colors `+(n===e.days?`bg-accent text-foreground`:`text-muted-foreground hover:bg-accent/50 hover:text-foreground`),children:e.label},e.days))})]}),(0,Y.jsx)(`div`,{className:`px-4 py-8 text-xs text-muted-foreground`,children:`No profile-scoped jobs yet.`})]});let o=Math.max(...e.rows.map(e=>e.jobs),1);return(0,Y.jsxs)(`div`,{className:`mx-6 my-4 rounded-md border border-border bg-muted/20`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b border-border`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-xs font-medium text-foreground`,children:`Profile usage`}),(0,Y.jsxs)(`div`,{className:`text-[11px] text-muted-foreground`,children:[`Jobs launched per profile in the last `,e.windowDays,` days.`]})]}),(0,Y.jsx)(`div`,{className:`flex gap-0.5`,children:it.map(e=>(0,Y.jsx)(`button`,{type:`button`,onClick:()=>r(e.days),className:`text-[10px] px-2 py-1 rounded transition-colors `+(n===e.days?`bg-accent text-foreground`:`text-muted-foreground hover:bg-accent/50 hover:text-foreground`),children:e.label},e.days))})]}),(0,Y.jsx)(`div`,{className:`p-4 space-y-2`,children:e.rows.map(e=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(`div`,{className:`w-32 text-xs font-mono truncate`,children:e.profileName}),(0,Y.jsx)(`div`,{className:`flex-1 h-4 bg-muted/50 rounded overflow-hidden`,children:(0,Y.jsx)(`div`,{className:`h-full bg-accent-primary/70`,style:{width:`${Math.max(6,Math.round(e.jobs/o*100))}%`}})}),(0,Y.jsxs)(`div`,{className:`flex gap-4 text-[11px] text-muted-foreground min-w-0 flex-shrink-0`,children:[(0,Y.jsxs)(`span`,{title:`jobs`,children:[(0,Y.jsx)(`span`,{className:`text-foreground font-mono`,children:e.jobs}),` jobs`]}),(0,Y.jsxs)(`span`,{title:`success rate`,children:[(0,Y.jsxs)(`span`,{className:`text-foreground font-mono`,children:[Math.round(e.successRate*100),`%`]}),` `,`ok`]}),e.avgDurationMs!=null&&(0,Y.jsx)(`span`,{title:`avg duration`,children:(0,Y.jsx)(`span`,{className:`text-foreground font-mono`,children:ot(e.avgDurationMs)})}),e.avgTokens!=null&&(0,Y.jsxs)(`span`,{title:`avg tokens`,children:[(0,Y.jsx)(`span`,{className:`text-foreground font-mono`,children:st(e.avgTokens)}),` `,`tok`]})]})]},e.profileName))})]})}function ot(e){let t=Math.round(e/1e3);if(t<60)return`${t}s`;let n=Math.floor(t/60);return n<60?`${n}m`:`${Math.floor(n/60)}h${n%60}m`}function st(e){return e<1e3?Math.round(e).toString():e<1e6?`${(e/1e3).toFixed(1)}k`:`${(e/1e6).toFixed(1)}M`}var ct=`specrails-hub:agents-tab`;function lt(){try{let e=localStorage.getItem(ct);if(e===`profiles`||e===`usage`||e===`catalog`)return e}catch{}return`profiles`}function ut(){let[e,t]=(0,J.useState)(()=>lt()),n=e=>{t(e);try{localStorage.setItem(ct,e)}catch{}},[r,i]=(0,J.useState)(null);return(0,J.useEffect)(()=>{let e=!1;return fetch(`${C()}/profiles/core-version`).then(e=>e.ok?e.json():null).then(t=>{!e&&t&&i(t)}).catch(()=>{}),()=>{e=!0}},[]),(0,Y.jsxs)(`div`,{className:`flex flex-col h-full`,children:[r!==null&&!r.profileAware&&(0,Y.jsxs)(`div`,{className:`flex-shrink-0 flex items-start gap-3 px-6 py-3 border-b border-yellow-500/30 bg-yellow-500/10`,children:[(0,Y.jsx)(K,{className:`w-4 h-4 text-yellow-500 mt-0.5 flex-shrink-0`}),(0,Y.jsxs)(`div`,{className:`text-xs`,children:[(0,Y.jsxs)(`div`,{className:`font-medium text-yellow-500`,children:[`Profile-aware pipeline requires specrails-core `,r.required,`+`]}),(0,Y.jsxs)(`div`,{className:`text-yellow-500/80 mt-0.5`,children:[`This project has`,` `,(0,Y.jsx)(`code`,{className:`px-1 rounded bg-yellow-500/20`,children:r.version??`unknown`}),`. Run`,` `,(0,Y.jsx)(`code`,{className:`px-1 rounded bg-yellow-500/20`,children:`npx specrails-core@latest update`}),` `,`inside the project to unlock profile mode. Profiles you create here will still save; they just won't affect the pipeline until core is updated.`]})]})]}),(0,Y.jsxs)(`div`,{className:`flex-shrink-0 border-b border-border`,children:[(0,Y.jsxs)(`div`,{className:`px-6 pt-4`,children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Agents`}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:`Manage agent profiles and the catalog (upstream + custom) for this project.`})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 px-4 pt-3`,children:[(0,Y.jsx)(ft,{active:e===`profiles`,onClick:()=>n(`profiles`),children:`Profiles`}),(0,Y.jsx)(ft,{active:e===`usage`,onClick:()=>n(`usage`),children:`Usage`}),(0,Y.jsx)(ft,{active:e===`catalog`,onClick:()=>n(`catalog`),children:`Catalog`})]})]}),(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0 overflow-auto`,children:[e===`profiles`&&(0,Y.jsx)(ve,{}),e===`usage`&&(0,Y.jsx)(dt,{}),e===`catalog`&&(0,Y.jsx)($e,{})]})]})}function dt(){return(0,Y.jsx)(`div`,{className:`min-h-full`,children:(0,Y.jsx)(at,{})})}function ft({active:e,children:t,onClick:n}){return(0,Y.jsx)(`button`,{type:`button`,onClick:n,className:`h-8 px-3 text-xs font-medium rounded-t-md border-b-2 transition-colors `+(e?`text-foreground border-foreground`:`text-muted-foreground border-transparent hover:text-foreground hover:border-border`),children:t})}export{ut as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as e}from"./chunk-CilyBKbf.js";import{t}from"./clsx-fiJc2n10.js";import{K as n,St as r,Vt as i,bt as a,o,s,vt as c,xt as l,yt as u,zt as d}from"./index-P2hinGr2.js";import{t as f}from"./ExportDropdown-Bndfxa-s.js";import{A as p,B as m,C as h,D as g,E as _,F as v,G as y,H as b,I as x,J as S,K as C,L as w,M as T,N as E,O as D,P as O,Q as k,R as A,S as j,T as ee,V as M,X as N,Z as te,_ as ne,_t as re,a as P,at as ie,b as ae,c as oe,ct as se,et as ce,f as le,g as ue,gt as de,h as fe,i as F,j as pe,k as me,l as I,lt as L,m as he,n as ge,nt as R,o as _e,ot as ve,p as ye,pt as z,q as B,r as V,rt as H,s as be,st as xe,t as Se,tt as Ce,ut as U,v as we,x as Te,y as Ee,z as De}from"./BarChart-DX0CY_mx.js";var Oe=c(`arrow-down-right`,[[`path`,{d:`m7 7 10 10`,key:`1fmybs`}],[`path`,{d:`M17 7v10H7`,key:`6fjiku`}]]),ke=c(`arrow-up-right`,[[`path`,{d:`M7 7h10v10`,key:`1tivn9`}],[`path`,{d:`M7 17 17 7`,key:`1vkiza`}]]),W=e(i(),1),G=l();function K(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)}`}var je=[`job`,`explore-spec`,`quick-spec`,`ai-edit`,`smash`];function Me({data:e,loading:t}){let[n,r]=(0,W.useState)(0),i=(0,W.useRef)(0);if((0,W.useEffect)(()=>{if(!e)return;let t=e.summary.totalCostUsd;if(i.current===0&&t>0){let e=performance.now(),n=i=>{let a=Math.min(1,(i-e)/600),o=1-(1-a)**3;r(0+(t-0)*o),a<1&&requestAnimationFrame(n)};requestAnimationFrame(n)}else r(t);i.current=t},[e]),t&&!e)return(0,G.jsx)(`div`,{className:`h-44 rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let a=e.summary.totalCostUsd,c=e.summary.totalRuns,l=e.summary.totalEstimatedCostUsd??0,u=e.summary.deltaPct,d=e.trackingStartedAt,f=l>0,p=je.map(t=>{let n=e.bySurface.find(e=>e.surface===t);return{surface:t,costUsd:n?.costUsd??0,count:n?.count??0}});return(0,G.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-gradient-to-br from-card/80 to-card/40 p-5`,children:[(0,G.jsxs)(`div`,{className:`flex flex-wrap items-end justify-between gap-3 mb-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-[11px] uppercase tracking-wider text-muted-foreground mb-1`,children:`Spending`}),(0,G.jsxs)(`div`,{className:`flex items-baseline gap-3`,children:[(0,G.jsx)(`div`,{className:`text-5xl font-semibold tabular-nums tracking-tight`,children:Ae(n)}),u!==null&&(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 text-xs font-medium ${u>=0?`text-accent-warning`:`text-accent-success`}`,children:[u>=0?(0,G.jsx)(ke,{className:`w-3 h-3`}):(0,G.jsx)(Oe,{className:`w-3 h-3`}),Math.abs(u).toFixed(0),`% vs prev`]})]}),(0,G.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-1 tabular-nums flex items-center gap-2`,children:[(0,G.jsxs)(`span`,{children:[c,` invocation`,c===1?``:`s`]}),f&&(0,G.jsxs)(`span`,{className:`text-[10px] text-muted-foreground/70 italic`,title:`Includes ${K(l)} of estimated cost from providers without a native cost field (e.g. codex via the local pricing table).`,children:[`· includes ~`,K(l),` estimated`]})]})]}),c===0&&d&&(0,G.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[`Tracking started `,d.slice(0,10)]})]}),c===0?(0,G.jsxs)(`div`,{className:`rounded-lg border border-dashed border-border/40 p-6 text-center`,children:[(0,G.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No invocations yet for this filter window.`}),(0,G.jsxs)(`p`,{className:`text-xs text-muted-foreground/70 mt-1`,children:[`Tracking started `,d?d.slice(0,10):`on first invocation`]})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`h-3 w-full rounded-full overflow-hidden bg-background-deep flex`,children:p.map(e=>{let t=a>0?e.costUsd/a*100:0;return t===0?null:(0,G.jsx)(`div`,{className:`h-full ${o[e.surface].dot}`,style:{width:`${t}%`},title:`${s[e.surface]}: ${K(e.costUsd)}`},e.surface)})}),(0,G.jsx)(`div`,{className:`mt-3 flex flex-wrap items-center gap-x-5 gap-y-1.5 text-xs`,children:p.filter(e=>e.costUsd>0).map(e=>(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 tabular-nums`,children:[(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full ${o[e.surface].dot}`}),(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:s[e.surface]}),(0,G.jsx)(`span`,{className:`text-foreground font-medium`,children:K(e.costUsd)}),(0,G.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,G.jsx)(`span`,{className:`text-muted-foreground/80`,children:e.count})]},e.surface))})]})]})}var Ne={claude:`Claude`,codex:`Codex`},Pe={claude:`bg-accent-info`,codex:`bg-accent-highlight`};function Fe(e){return e>=100?`$${e.toFixed(0)}`:e>=10?`$${e.toFixed(1)}`:e>=.01?`$${e.toFixed(2)}`:`$${e.toFixed(4)}`}function Ie(e){return Ne[e]??e}function Le(e){return Pe[e]??`bg-accent-secondary`}function Re({data:e,loading:t}){if(t&&!e)return(0,G.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 n=e.byProvider.reduce((e,t)=>e+t.costUsd+t.estimatedCostUsd,0);return(0,G.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,G.jsx)(`div`,{className:`flex items-baseline justify-between mb-3`,children:(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-[11px] uppercase tracking-wider text-muted-foreground`,children:`By provider`}),(0,G.jsxs)(`div`,{className:`text-xs text-muted-foreground/70 mt-0.5`,children:[`How cost splits across the AI CLIs in this project. The`,` `,(0,G.jsx)(`span`,{className:`font-medium`,children:`~`}),` prefix marks rows where cost is estimated from the local pricing table (the provider does not report it natively).`]})]})}),n===0?(0,G.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:`No cost recorded yet in this window.`}):(0,G.jsxs)(G.Fragment,{children:[(0,G.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,r=n>0?t/n*100:0;return r===0?null:(0,G.jsx)(`div`,{className:`h-full ${Le(e.provider)}`,style:{width:`${r}%`},title:`${Ie(e.provider)}: ${Fe(t)} (${e.count})`},e.provider)})}),(0,G.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2`,children:e.byProvider.map(e=>(0,G.jsx)(ze,{entry:e},e.provider))})]})]})}function ze({entry:e}){let t=e.costUsd+e.estimatedCostUsd,n=e.costUsd===0&&e.estimatedCostUsd>0;return(0,G.jsxs)(`div`,{className:`flex items-center gap-2.5 rounded-md border border-border/30 px-2.5 py-1.5`,children:[(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full shrink-0 ${Le(e.provider)}`}),(0,G.jsx)(`span`,{className:`text-xs font-medium`,children:Ie(e.provider)}),(0,G.jsxs)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[e.count,` run`,e.count===1?``:`s`]}),(0,G.jsxs)(`span`,{className:`ml-auto text-xs font-medium tabular-nums`,children:[n?`~`:``,Fe(t)]})]})}var Be=[`option`,`isActive`];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 Ve(e,t){if(e==null)return{};var n,r,i=He(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 He(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 Ue(e){var{option:t,isActive:n}=e,r=Ve(e,Be);return typeof t==`string`?W.createElement(j,q({option:W.createElement(xe,q({type:t},r)),isActive:n,shapeType:`symbols`},r)):W.createElement(j,q({option:t,isActive:n,shapeType:`symbols`},r))}var We=ce([(e,t,n,r,i,a,o)=>A(e,void 0,void 0,o),(e,t,n,r,i,a,o)=>E(e,`xAxis`,t,o),(e,t,n,r,i,a,o)=>O(e,`xAxis`,t,o),(e,t,n,r,i,a,o)=>E(e,`yAxis`,n,o),(e,t,n,r,i,a,o)=>O(e,`yAxis`,n,o),(e,t,n,r)=>x(e,`zAxis`,r,!1),ce([v,(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 at({displayedData:d,xAxis:t,yAxis:r,zAxis:a,scatterSettings:o,xAxisTicks:n,yAxisTicks:i,cells:s})}}),Ge=[`id`],Ke=[`onMouseEnter`,`onClick`,`onMouseLeave`],qe=[`animationBegin`,`animationDuration`,`animationEasing`,`hide`,`isAnimationActive`,`legendType`,`lineJointType`,`lineType`,`shape`,`xAxisId`,`yAxisId`,`zAxisId`];function J(e,t){if(e==null)return{};var n,r,i=Je(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 Je(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 Y(){return Y=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},Y.apply(null,arguments)}function Ye(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 X(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?Ye(Object(n),!0).forEach(function(t){Xe(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Ye(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function Xe(e,t,n){return(t=Ze(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Ze(e){var t=Qe(e,`string`);return typeof t==`symbol`?t:t+``}function Qe(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 $e=e=>{var{dataKey:t,name:n,fill:r,legendType:i,hide:a}=e;return[{inactive:a,dataKey:t,type:i,color:r,value:te(n,t),payload:e}]},et=W.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:te(o,t),hide:s,type:c,color:a,unit:``,graphicalItemId:l}};return W.createElement(we,{tooltipEntrySettings:u})});function tt(e){var{points:t,props:n}=e,{line:r,lineType:i,lineJointType:a}=n;if(!r)return null;var o=de(n),s=re(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}=se(t),m=e=>f*e+p;c=[{x:u,y:m(u)},{x:d,y:m(d)}]}var h=X(X(X({},o),{},{fill:`none`,stroke:o&&o.fill},s),{},{points:c});return l=W.isValidElement(r)?W.cloneElement(r,h):typeof r==`function`?r(h):W.createElement(M,Y({},h,{type:a})),W.createElement(z,{className:`recharts-scatter-line`,key:`recharts-scatter-line`},l)}function nt(e){var{showLabels:t,points:n,children:r}=e,i=y(),a=(0,W.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 X(X({},t),{},{value:void 0,payload:e.payload,viewBox:t,parentViewBox:i,fill:void 0})}),[i,n]);return W.createElement(ee,{value:t?a:void 0},r)}function rt(e){var{points:t,allOtherScatterProps:n}=e,{shape:r,activeShape:i,dataKey:a}=n,{id:o}=n,s=J(n,Ge),c=R(pe),{onMouseEnter:l,onClick:u,onMouseLeave:d}=n,f=J(n,Ke),m=ae(l,a,o),h=Te(d),g=Ee(u,a,o);if(!ve(t))return null;var _=de(s);return W.createElement(W.Fragment,null,W.createElement(tt,{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=X(X(X({},_),e),{},{index:t,[S]:String(o)});return W.createElement(p,{key:`symbol-${e?.cx}-${e?.cy}-${e?.size}-${t}`,zIndex:a?w.activeDot:void 0},W.createElement(z,Y({className:`recharts-scatter-symbol`},ie(f,e,t),{onMouseEnter:m(e,t),onMouseLeave:h(e,t),onClick:g(e,t)}),W.createElement(Ue,Y({option:s,isActive:a},l))))}))}function it(e){var{previousPointsRef:t,props:n}=e,{points:r,isAnimationActive:i,animationBegin:a,animationDuration:o,animationEasing:s}=n,c=t.current,l=De(n,`recharts-scatter-`),[u,d]=(0,W.useState)(!1),f=(0,W.useCallback)(()=>{d(!1)},[]),p=(0,W.useCallback)(()=>{d(!0)},[]),h=!u;return W.createElement(nt,{showLabels:h,points:r},n.children,W.createElement(m,{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?X(X({},t),{},{cx:t.cx==null?void 0:L(r.cx,t.cx,e),cy:t.cy==null?void 0:L(r.cy,t.cy,e),size:L(r.size,t.size,e)}):X(X({},t),{},{size:L(0,t.size,e)})});return e>0&&(t.current=i),W.createElement(z,null,W.createElement(rt,{points:i,allOtherScatterProps:n,showLabels:h}))}),W.createElement(_,{label:n.label}))}function at(e){var{displayedData:t,xAxis:n,yAxis:r,zAxis:i,scatterSettings:a,xAxisTicks:o,yAxisTicks:s,cells:c}=e,l=U(n.dataKey)?a.dataKey:n.dataKey,u=U(r.dataKey)?a.dataKey:r.dataKey,d=i&&i.dataKey,f=i?i.range:T.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=k(e,l),g=k(e,u),_=!U(d)&&k(e,d)||`-`,v=[{name:U(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:U(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=N({axis:n,ticks:o,bandSize:m,entry:e,index:t,dataKey:l}),b=N({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 X(X({},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 ot=(e,t,n)=>({x:e.cx,y:e.cy,value:Number(n===`x`?e.node.x:e.node.y),errorVal:k(e,t)});function st(e){var{hide:n,points:r,className:i,needClip:a,xAxisId:o,yAxisId:s,id:c}=e,l=(0,W.useRef)(null);if(n)return null;var u=t(`recharts-scatter`,i),d=c;return W.createElement(p,{zIndex:e.zIndex},W.createElement(z,{className:u,clipPath:a?`url(#clipPath-${d})`:void 0,id:c},a&&W.createElement(`defs`,null,W.createElement(_e,{clipPathId:d,xAxisId:o,yAxisId:s})),W.createElement(oe,{xAxisId:o,yAxisId:s,data:r,dataPointFormatter:ot,errorBarOffset:0},W.createElement(z,{key:`recharts-scatter-symbols`},W.createElement(it,{props:e,previousPointsRef:l})))))}var ct={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:w.scatter};function lt(e){var t=H(e,ct),{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=J(t,qe),{needClip:_}=be(d,f),v=(0,W.useMemo)(()=>h(e.children,g),[e.children]),y=B(),b=R(t=>We(t,d,f,p,e.id,v,y));return _==null||b==null?null:W.createElement(W.Fragment,null,W.createElement(et,{dataKey:e.dataKey,points:b,stroke:e.stroke,strokeWidth:e.strokeWidth,fill:e.fill,name:e.name,hide:e.hide,tooltipType:e.tooltipType,id:e.id}),W.createElement(st,Y({},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:b,needClip:_})))}function ut(e){var t=H(e,ct),n=B();return W.createElement(ue,{id:t.id,type:`scatter`},e=>W.createElement(W.Fragment,null,W.createElement(ne,{legendPayload:$e(t)}),W.createElement(fe,{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}),W.createElement(lt,Y({},t,{id:e}))))}var dt=W.memo(ut,b);dt.displayName=`Scatter`;function ft(e){var t=Ce(),n=(0,W.useRef)(null);return(0,W.useLayoutEffect)(()=>{n.current===null?t(le(e)):n.current!==e&&t(he({prev:n.current,next:e})),n.current=e},[e,t]),(0,W.useLayoutEffect)(()=>()=>{n.current&&=(t(ye(n.current)),null)},[t]),null}var pt={zAxisId:0,range:T.range,scale:T.scale,type:T.type};function Z(e){var t=H(e,pt);return W.createElement(ft,{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:T.allowDuplicatedCategory,allowDataOverflow:T.allowDataOverflow,reversed:T.reversed,includeHidden:T.includeHidden})}Z.displayName=`ZAxis`;var mt=[`item`],ht=(0,W.forwardRef)((e,t)=>W.createElement(ge,{chartName:`ScatterChart`,defaultTooltipEventType:`item`,validateTooltipEventTypes:mt,tooltipPayloadSearcher:me,categoricalChartProps:e,ref:t}));function gt({data:e,loading:t}){if(t&&!e)return(0,G.jsx)(`div`,{className:`h-[220px] rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let n=e.dailyTimeline.map(e=>({date:e.date.slice(5),Jobs:e.jobsCostUsd,Explore:e.exploreCostUsd,Quick:e.quickCostUsd,Refine:e.aiEditCostUsd})),r=n.every(e=>e.Jobs+e.Explore+e.Quick+e.Refine===0);return(0,G.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,G.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider`,children:`Daily timeline`}),(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground/70`,children:`stacked by surface`})]}),r?(0,G.jsx)(`div`,{className:`h-40 flex items-center justify-center text-xs text-muted-foreground/70`,children:`No spend in this period.`}):(0,G.jsx)(`div`,{className:`h-[220px]`,children:(0,G.jsx)(C,{width:`100%`,height:`100%`,children:(0,G.jsxs)(Se,{data:n,margin:{top:10,right:10,left:-8,bottom:0},children:[(0,G.jsx)(I,{strokeDasharray:`2 4`,stroke:`currentColor`,className:`text-border/30`,vertical:!1}),(0,G.jsx)(F,{dataKey:`date`,tick:{fontSize:10},stroke:`currentColor`,className:`text-muted-foreground`}),(0,G.jsx)(V,{tick:{fontSize:10},stroke:`currentColor`,className:`text-muted-foreground`,tickFormatter:e=>`$${e}`}),(0,G.jsx)(D,{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,G.jsx)(P,{dataKey:`Jobs`,stackId:`a`,fill:`var(--accent-info, #5fa8d3)`}),(0,G.jsx)(P,{dataKey:`Explore`,stackId:`a`,fill:`var(--accent-highlight, #c084fc)`}),(0,G.jsx)(P,{dataKey:`Quick`,stackId:`a`,fill:`var(--accent-secondary, #f7768e)`}),(0,G.jsx)(P,{dataKey:`Refine`,stackId:`a`,fill:`var(--accent-success, #50fa7b)`})]})})})]})}function _t(e){return e==null?`—`:e<.005?`$${e.toFixed(4)}`:e<1?`$${e.toFixed(3)}`:`$${e.toFixed(2)}`}function vt(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 yt({values:e}){let t=Math.max(1e-4,...e);return(0,G.jsx)(`div`,{className:`flex items-end gap-[1px] h-5`,children:e.map((e,n)=>(0,G.jsx)(`div`,{className:`w-[3px] rounded-sm bg-foreground/40`,style:{height:`${Math.max(2,e/t*20)}px`}},n))})}function bt({mode:e,label:t,accentClass:n}){let r=e.mode===`explore`&&e.totalRuns<5;return(0,G.jsxs)(`div`,{className:`flex-1 p-4 first:pr-2 last:pl-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,G.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full ${n}`}),(0,G.jsx)(`span`,{className:`text-xs font-medium uppercase tracking-wider text-muted-foreground`,children:t})]}),r?(0,G.jsxs)(`div`,{className:`py-3`,children:[(0,G.jsx)(`p`,{className:`text-sm text-foreground`,children:`Try Explore for richer specs`}),(0,G.jsxs)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:[e.totalRuns,` run`,e.totalRuns===1?``:`s`,` so far`]})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`text-3xl font-semibold tabular-nums tracking-tight`,children:_t(e.avgCostPerSpec)}),(0,G.jsx)(`div`,{className:`text-[11px] text-muted-foreground mt-0.5`,children:`per spec`}),(0,G.jsx)(`div`,{className:`mt-3`,children:(0,G.jsx)(yt,{values:e.sparkline.length>0?e.sparkline:[0]})}),(0,G.jsxs)(`div`,{className:`mt-3 space-y-0.5 text-xs tabular-nums text-muted-foreground`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-foreground font-medium`,children:e.ticketsCreated}),` created · `,e.totalRuns,` runs`]}),(0,G.jsxs)(`div`,{children:[vt(e.avgDurationMs),` avg`]}),(0,G.jsx)(`div`,{className:`truncate`,children:e.dominantModel??`—`})]})]})]})}function xt({data:e,loading:t}){if(t&&!e)return(0,G.jsx)(`div`,{className:`h-[220px] rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let n=e.byMode.find(e=>e.mode===`quick`),r=e.byMode.find(e=>e.mode===`explore`);if(!n||!r)return null;let i=n.avgCostPerSpec&&r.avgCostPerSpec&&n.avgCostPerSpec>0?r.avgCostPerSpec/n.avgCostPerSpec:null,a=i!==null&&n.totalRuns>=1&&r.totalRuns>=5;return(0,G.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40`,children:[(0,G.jsx)(`div`,{className:`px-4 pt-3 pb-1`,children:(0,G.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider`,children:`Quick vs Explore`})}),(0,G.jsxs)(`div`,{className:`flex divide-x divide-border/40`,children:[(0,G.jsx)(bt,{mode:n,label:`Quick`,accentClass:`bg-accent-secondary`}),(0,G.jsx)(bt,{mode:r,label:`Explore`,accentClass:`bg-accent-highlight`})]}),a&&(0,G.jsx)(`div`,{className:`px-4 pb-3 -mt-1`,children:(0,G.jsx)(`div`,{className:`text-center text-[11px] text-muted-foreground tabular-nums`,children:(0,G.jsxs)(`span`,{className:`px-2`,children:[`━━━━━━ `,i.toFixed(1),`× more per spec ━━━━━━`]})})})]})}function St({data:e,loading:t,onSelectModel:n,activeModel:r}){if(t&&!e)return(0,G.jsx)(`div`,{className:`h-[220px] rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let i=e.byModel.reduce((e,t)=>e+t.costUsd,0),a=e.byModel.slice(0,5);return(0,G.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,G.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider mb-3`,children:`Models`}),a.length===0?(0,G.jsx)(`div`,{className:`h-32 flex items-center justify-center text-xs text-muted-foreground/70`,children:`No models recorded.`}):(0,G.jsx)(`ul`,{className:`space-y-1.5`,children:a.map(e=>{let t=i>0?e.costUsd/i*100:0,a=r===e.model;return(0,G.jsx)(`li`,{children:(0,G.jsxs)(`button`,{type:`button`,onClick:()=>n(e.model),className:`w-full text-left group rounded-md px-2 py-1.5 transition-colors ${a?`bg-accent-highlight/10 ring-1 ring-accent-highlight/30`:`hover:bg-accent/30`}`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-[12px] mb-1 tabular-nums`,children:[(0,G.jsx)(`span`,{className:`truncate font-medium`,children:e.model}),(0,G.jsxs)(`span`,{className:`text-muted-foreground`,children:[`$`,e.costUsd.toFixed(2),` · `,e.count]})]}),(0,G.jsx)(`div`,{className:`h-1.5 rounded-full bg-background-deep overflow-hidden`,children:(0,G.jsx)(`div`,{className:`h-full ${a?`bg-accent-highlight`:`bg-foreground/40 group-hover:bg-foreground/60`} transition-colors`,style:{width:`${t}%`}})})]})},e.model)})})]})}var Ct={job:`var(--accent-info, #5fa8d3)`,"quick-spec":`var(--accent-secondary, #f7768e)`,"explore-spec":`var(--accent-highlight, #c084fc)`,"ai-edit":`var(--accent-success, #50fa7b)`,smash:`var(--accent-highlight, #c084fc)`};function wt({data:e,loading:t,onSelectPoint:n}){if(t&&!e)return(0,G.jsx)(`div`,{className:`h-[260px] rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let r=[`job`,`quick-spec`,`explore-spec`,`ai-edit`,`smash`],i=r.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}))})),a=e.scatter.length===0;return(0,G.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,G.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider`,children:`Cost vs Turns`}),(0,G.jsx)(`div`,{className:`flex flex-wrap items-center gap-2 text-[10px]`,children:r.map(e=>(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,G.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full`,style:{background:Ct[e]}}),(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:s[e]})]},e))})]}),a?(0,G.jsx)(`div`,{className:`h-40 flex items-center justify-center text-xs text-muted-foreground/70`,children:`No invocations to plot.`}):(0,G.jsx)(`div`,{className:`h-[260px]`,children:(0,G.jsx)(C,{width:`100%`,height:`100%`,children:(0,G.jsxs)(ht,{margin:{top:10,right:10,left:-8,bottom:5},children:[(0,G.jsx)(I,{strokeDasharray:`2 4`,stroke:`currentColor`,className:`text-border/30`}),(0,G.jsx)(F,{type:`number`,dataKey:`x`,name:`turns`,tick:{fontSize:10},stroke:`currentColor`,className:`text-muted-foreground`,label:{value:`turns`,position:`insideBottomRight`,offset:-2,fontSize:10,fill:`currentColor`}}),(0,G.jsx)(V,{type:`number`,dataKey:`y`,name:`cost`,tick:{fontSize:10},stroke:`currentColor`,className:`text-muted-foreground`,tickFormatter:e=>`$${e.toFixed(e<1?2:0)}`}),(0,G.jsx)(Z,{range:[40,80]}),(0,G.jsx)(D,{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)}`,`cost`]:[String(e),n]}}),i.map(e=>(0,G.jsx)(dt,{data:e.points,fill:Ct[e.surface],onClick:e=>{let t=e;t?.raw&&n(t.raw)}},e.surface))]})})})]})}function Tt({data:e,loading:t,onSelectTicket:n}){if(t&&!e)return(0,G.jsx)(`div`,{className:`h-40 rounded-xl border border-border/40 bg-card/40 animate-pulse`});if(!e)return null;let r=e.topTickets;return(0,G.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,G.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider mb-3`,children:`Top tickets`}),r.length===0?(0,G.jsx)(`div`,{className:`h-32 flex items-center justify-center text-xs text-muted-foreground/70`,children:`No ticket activity in this period.`}):(0,G.jsx)(`ul`,{className:`divide-y divide-border/30`,children:r.map((e,t)=>{let r=Object.entries(e.bySurface).filter(([,e])=>e.count>0).map(([e,t])=>`${t.count} ${s[e].toLowerCase()}`).join(` + `),i=e.isUnattributed,a=i?`Unattributed`:e.ticketTitle?`#${e.ticketId} ${e.ticketTitle}`:`deleted ticket #${e.ticketId}`;return(0,G.jsx)(`li`,{children:(0,G.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&&!i?`opacity-50`:``}`,disabled:i,children:[(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`div`,{className:`text-sm truncate`,children:a}),(0,G.jsx)(`div`,{className:`text-[11px] text-muted-foreground truncate`,children:r||`—`})]}),(0,G.jsxs)(`div`,{className:`text-right tabular-nums`,children:[(0,G.jsxs)(`div`,{className:`text-sm font-medium`,children:[`$`,e.totalCostUsd.toFixed(2)]}),(0,G.jsxs)(`div`,{className:`text-[10px] text-muted-foreground`,children:[e.totalRuns,` run`,e.totalRuns===1?``:`s`]})]})]})},`${e.ticketId??`u`}-${t}`)})})]})}function Et(e){return e==null?`—`:e<.005?`$${e.toFixed(4)}`:`$${e.toFixed(2)}`}function Dt(e){return e==null?`—`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function Q(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 Ot(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 kt(e,t){if(e.model)return e.model;if(!Q(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 At({rows:e,loading:t,truncated:n,totalAvailable:r,tableFilters:i,onTableFiltersChange:a}){let[c,l]=(0,W.useState)(null),u=Ot(e);return(0,G.jsxs)(`div`,{className:`rounded-xl border border-border/50 bg-card/40 p-4`,children:[(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 mb-3`,children:[(0,G.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider`,children:`All invocations`}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-[11px]`,children:[(0,G.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":`Status filter`,children:[(0,G.jsx)(`option`,{value:``,children:`All status`}),(0,G.jsx)(`option`,{value:`success`,children:`Success`}),(0,G.jsx)(`option`,{value:`failed`,children:`Failed`}),(0,G.jsx)(`option`,{value:`aborted`,children:`Aborted`})]}),(0,G.jsx)(`input`,{type:`number`,step:`0.01`,min:`0`,placeholder:`≥ $0.00`,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":`Minimum cost filter`})]})]}),t?(0,G.jsx)(`div`,{className:`h-32 rounded bg-card/30 animate-pulse`}):e.length===0?(0,G.jsx)(`div`,{className:`h-32 flex items-center justify-center text-xs text-muted-foreground/70`,children:`No invocations match the current filters.`}):(0,G.jsx)(`div`,{className:`overflow-x-auto`,children:(0,G.jsxs)(`table`,{className:`w-full text-[12px] tabular-nums`,children:[(0,G.jsx)(`thead`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:(0,G.jsxs)(`tr`,{className:`text-left`,children:[(0,G.jsx)(`th`,{className:`font-medium px-2 py-2`,children:`Surface`}),(0,G.jsx)(`th`,{className:`font-medium px-2 py-2`,children:`Ticket`}),(0,G.jsx)(`th`,{className:`font-medium px-2 py-2 text-right`,children:`Cost`}),(0,G.jsx)(`th`,{className:`font-medium px-2 py-2 text-right`,children:`Turns`}),(0,G.jsx)(`th`,{className:`font-medium px-2 py-2 text-right`,children:`Tokens`}),(0,G.jsx)(`th`,{className:`font-medium px-2 py-2`,children:`Model`}),(0,G.jsx)(`th`,{className:`font-medium px-2 py-2`,children:`Status`}),(0,G.jsx)(`th`,{className:`font-medium px-2 py-2`,children:`Started`})]})}),(0,G.jsx)(`tbody`,{children:e.map(e=>{let t=e.surface,n=o[t],r=(e.tokens_in??0)+(e.tokens_out??0),i=Q(e),a=i?`Contract Layer`:s[t],d=kt(e,u);return(0,G.jsxs)(`tr`,{onClick:()=>l(c===e.id?null:e.id),className:`border-t border-border/30 hover:bg-accent/30 cursor-pointer`,children:[(0,G.jsx)(`td`,{className:`px-2 py-2`,children:(0,G.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,G.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full ${n.dot}`}),a]})}),(0,G.jsx)(`td`,{className:`px-2 py-2 max-w-[260px]`,children:e.ticket_id==null?e.ticket_title?(0,G.jsx)(`span`,{className:`truncate block text-muted-foreground/90 italic`,title:`Provisional Explore title — not yet committed`,children:e.ticket_title}):(0,G.jsx)(`span`,{className:`text-muted-foreground/70`,children:`—`}):(0,G.jsxs)(`span`,{className:`truncate block`,children:[`#`,e.ticket_id,` `,i?(0,G.jsx)(`span`,{className:`text-muted-foreground/90`,children:`Contract Layer refinement`}):e.ticket_title??(0,G.jsx)(`span`,{className:`text-muted-foreground/70 italic`,children:`(deleted)`})]})}),(0,G.jsx)(`td`,{className:`px-2 py-2 text-right font-medium`,children:e.total_cost_usd_estimated===1&&e.total_cost_usd!=null?(0,G.jsxs)(`span`,{title:`Estimated from local pricing table — this provider does not report cost natively.`,className:`text-muted-foreground/90`,children:[`~`,Et(e.total_cost_usd)]}):Et(e.total_cost_usd)}),(0,G.jsx)(`td`,{className:`px-2 py-2 text-right`,children:Dt(e.num_turns)}),(0,G.jsx)(`td`,{className:`px-2 py-2 text-right`,children:r>0?Dt(r):`—`}),(0,G.jsxs)(`td`,{className:`px-2 py-2 max-w-[180px] truncate`,children:[d??`—`,d&&!e.model?(0,G.jsx)(`span`,{className:`ml-1 text-[10px] text-muted-foreground/70`,children:`inferred`}):null]}),(0,G.jsxs)(`td`,{className:`px-2 py-2`,children:[e.status===`success`?(0,G.jsx)(`span`,{className:`text-accent-success/90`,children:`●`}):e.status===`failed`?(0,G.jsx)(`span`,{className:`text-accent-warning`,children:`⚠`}):(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:`○`}),(0,G.jsx)(`span`,{className:`ml-1 text-muted-foreground`,children:e.status})]}),(0,G.jsx)(`td`,{className:`px-2 py-2 text-muted-foreground`,children:e.started_at.slice(0,16).replace(`T`,` `)})]},e.id)})})]})}),n&&(0,G.jsxs)(`div`,{className:`mt-2 text-[11px] text-muted-foreground/80`,children:[`Showing first `,e.length,` of `,r.toLocaleString(),` matching rows.`]})]})}var jt=[{value:`7d`,label:`7d`},{value:`30d`,label:`30d`},{value:`90d`,label:`90d`},{value:`all`,label:`All`}],Mt=[{value:`all`,label:`All`},{value:`job`,label:`Jobs`},{value:`explore-spec`,label:`Explore`},{value:`quick-spec`,label:`Quick`},{value:`ai-edit`,label:`Refine`},{value:`smash`,label:`SMASH`}];function $(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.model&&e.model.length>0&&t.set(`model`,e.model.join(`,`)),e.status&&t.set(`status`,e.status),typeof e.minCostUsd==`number`&&t.set(`minCostUsd`,String(e.minCostUsd)),typeof e.ticketId==`number`&&t.set(`ticketId`,String(e.ticketId)),t.toString()}function Nt(){let{activeProjectId:e}=u(),[t,i]=d(),o=t.get(`period`)??`30d`,s=(t.get(`surface`)??``).split(`,`).filter(Boolean),c=t.get(`ticketId`),[l,p]=(0,W.useState)({period:o,surface:s.length>0?s:void 0,ticketId:c?Number(c):void 0}),[m,h]=(0,W.useState)(null),[g,_]=(0,W.useState)(!0),[v,y]=(0,W.useState)(null),[b,x]=(0,W.useState)({}),[S,C]=(0,W.useState)(null),w=(0,W.useRef)(new Map),T=(0,W.useRef)(0);(0,W.useEffect)(()=>{let e=new URLSearchParams;e.set(`period`,l.period),l.surface&&l.surface.length>0&&e.set(`surface`,l.surface.join(`,`)),l.ticketId&&e.set(`ticketId`,String(l.ticketId)),i(e,{replace:!0})},[l.period,l.surface,l.ticketId,i]);let E=(0,W.useCallback)(async()=>{if(!e)return;let t=++T.current;y(null);let n=`${e}:${$(l)}`,i=w.current.get(n);i?(h(i),_(!1)):_(!0);try{let e=await fetch(`${r()}/spending?${$(l)}`);if(!e.ok)throw Error(`HTTP ${e.status}`);if(t!==T.current)return;let i=await e.json();w.current.set(n,i),h(i),_(!1)}catch(e){if(t!==T.current)return;y(e.message),_(!1)}},[e,l]),D=(0,W.useCallback)(async()=>{if(!e)return;let t={...l};b.model&&(t.model=[b.model]),b.status&&(t.status=b.status),typeof b.minCostUsd==`number`&&(t.minCostUsd=b.minCostUsd);try{let e=await fetch(`${r()}/invocations?${$(t)}&limit=100`);if(!e.ok)throw Error(`HTTP ${e.status}`);C(await e.json())}catch{C(null)}},[e,l,b]);(0,W.useEffect)(()=>{E()},[E]),(0,W.useEffect)(()=>{D()},[D]);let O=(0,W.useRef)(null),k=a();(0,W.useEffect)(()=>{let t=`analytics-spending`;return k.registerHandler(t,t=>{let n=t;n.type===`spending.invalidated`&&n.projectId===e&&(O.current&&clearTimeout(O.current),O.current=setTimeout(()=>{w.current.clear(),E(),D()},500))}),()=>{k.unregisterHandler(t)}},[k,e,E,D]);function A(e){if(e===`all`){p(e=>({...e,surface:void 0}));return}p(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 j=l.surface,ee=!j||j.length===0,M=(0,W.useMemo)(()=>{let e={period:l.period};return l.surface&&l.surface.length>0&&(e.surface=l.surface.join(`,`)),l.ticketId&&(e.ticketId=String(l.ticketId)),e},[l]),N=m?m.summary.totalRuns===0:!1;return(0,G.jsxs)(`div`,{className:`flex flex-col gap-6 p-4 pb-12`,children:[(0,G.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,G.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`h1`,{className:`text-base font-semibold tracking-tight`,children:`Analytics`}),l.ticketId&&(0,G.jsxs)(`button`,{type:`button`,onClick:()=>p(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:[`ticket #`,l.ticketId,` · ✕`]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`div`,{className:`flex items-center gap-1 rounded-md border border-border/60 bg-card/40 p-0.5`,children:jt.map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>p(t=>({...t,period:e.value})),className:`px-2.5 h-6 rounded text-[11px] font-medium transition-colors ${l.period===e.value?`bg-accent text-foreground`:`text-muted-foreground hover:text-foreground`}`,children:e.label},e.value))}),(0,G.jsx)(f,{baseUrl:`${r()}/analytics/export`,params:M,disabled:N}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>{w.current.clear(),E(),D()},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:`Refresh`,children:(0,G.jsx)(n,{className:`w-3 h-3`})})]})]}),(0,G.jsx)(`div`,{className:`mt-3 flex flex-wrap items-center gap-1.5`,children:Mt.map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>A(e.value),className:`h-7 px-3 rounded-full text-[11px] font-medium transition-all ${(e.value===`all`?ee:j?.includes(e.value)??!1)?`bg-foreground/10 text-foreground ring-1 ring-foreground/20`:`text-muted-foreground hover:text-foreground hover:bg-accent/40`}`,children:e.label},e.value))})]}),v&&(0,G.jsxs)(`div`,{className:`rounded-lg border border-accent-warning/30 bg-accent-warning/10 p-4 flex items-center justify-between`,children:[(0,G.jsxs)(`p`,{className:`text-sm text-accent-warning`,children:[`Failed to load: `,v]}),(0,G.jsxs)(`button`,{onClick:()=>E(),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,G.jsx)(n,{className:`w-3 h-3`}),`Retry`]})]}),(0,G.jsx)(Me,{data:m,loading:g}),(0,G.jsx)(Re,{data:m,loading:g}),(0,G.jsx)(gt,{data:m,loading:g}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4`,children:[(0,G.jsx)(xt,{data:m,loading:g}),(0,G.jsx)(St,{data:m,loading:g,onSelectModel:e=>p(t=>({...t,model:[e]})),activeModel:l.model?.[0]})]}),(0,G.jsx)(wt,{data:m,loading:g,onSelectPoint:e=>{x(e=>({...e})),p(t=>({...t,ticketId:e.ticketId??void 0}))}}),(0,G.jsx)(Tt,{data:m,loading:g,onSelectTicket:e=>p(t=>({...t,ticketId:e??void 0}))}),(0,G.jsx)(At,{rows:S?.rows??[],loading:g&&!S,truncated:S?.truncated??!1,totalAvailable:S?.totalAvailable??0,tableFilters:b,onTableFiltersChange:x})]})}export{Nt as default};
|