specrails-desktop 2.59.3 → 2.61.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/dist/assets/{ActivityFeedPage-BGEayjTY.js → ActivityFeedPage-Wi5XNgoG.js} +1 -1
- package/client/dist/assets/{AgentBrowserCapture-Qvg4y5Tr.js → AgentBrowserCapture-CkNWDZT3.js} +1 -1
- package/client/dist/assets/{AgentModeAnalyticsPane-CR7aFeLJ.js → AgentModeAnalyticsPane-CXz2j-Bt.js} +2 -2
- package/client/dist/assets/{AgentModeCodePane-gAd88Gng.js → AgentModeCodePane-DnsBPtpS.js} +2 -2
- package/client/dist/assets/{AgentModeJobsPane-EjCDuTow.js → AgentModeJobsPane-U1J6PaBo.js} +1 -1
- package/client/dist/assets/{AgentsPage-CRHHcp1V.js → AgentsPage-CXrqu5vo.js} +2 -2
- package/client/dist/assets/{AnalyticsPage-a0b1fNEl.js → AnalyticsPage-Cvtt-LOO.js} +1 -1
- package/client/dist/assets/{CodePage-BmV1m7l3.js → CodePage-D35o-MFO.js} +1 -1
- package/client/dist/assets/{DesktopAnalyticsPage-B87WmXOQ.js → DesktopAnalyticsPage-CsDFy5rp.js} +1 -1
- package/client/dist/assets/{DocsDialog-Co0O672q.js → DocsDialog-CSlMPemn.js} +1 -1
- package/client/dist/assets/{DocsPage-DxGI6A2T.js → DocsPage-BKlYAvWq.js} +1 -1
- package/client/dist/assets/{ExportDropdown-1Ce031vB.js → ExportDropdown-CweP_1GP.js} +1 -1
- package/client/dist/assets/InteractiveJobComposer-CFKvbQeJ.js +19 -0
- package/client/dist/assets/{JobDetailModal-DVLDVgzz.js → JobDetailModal-DYyGq1Vp.js} +1 -1
- package/client/dist/assets/{JobDetailPage-RcP9N-D-.js → JobDetailPage-C6gpdYvj.js} +1 -1
- package/client/dist/assets/{JobsPage-R9M4xQnp.js → JobsPage-CgS0pnKd.js} +1 -1
- package/client/dist/assets/LoopBuilderPage-jUp20DSZ.js +1 -0
- package/client/dist/assets/{LoopPreviewModal-DA2JeKWX.js → LoopPreviewModal-DkLRfsYX.js} +1 -1
- package/client/dist/assets/{LoopWindowSurface-BkkeD0hx.js → LoopWindowSurface-CuACkXFV.js} +1 -1
- package/client/dist/assets/{LoopsPage-BHv--iI7.js → LoopsPage-ClSrWzDd.js} +1 -1
- package/client/dist/assets/{MinimizedChatsContext-Bc9xHByW.js → MinimizedChatsContext-CroAs6Kh.js} +1 -1
- package/client/dist/assets/{PluginsPage-BEy62gxK.js → PluginsPage-nCKQOwRL.js} +1 -1
- package/client/dist/assets/{ProjectSettingsDialog-DDQ_f94T.js → ProjectSettingsDialog-BVDYwllU.js} +1 -1
- package/client/dist/assets/{RepositoryDeliveries-DIWDFLRM.js → RepositoryDeliveries-DJCm1pZr.js} +1 -1
- package/client/dist/assets/{RepositoryScopeSelector-D3PlHIM-.js → RepositoryScopeSelector-CeCr6Jz-.js} +1 -1
- package/client/dist/assets/{ReviewPacketPage-BXdPwmdE.js → ReviewPacketPage-kTErrEjx.js} +1 -1
- package/client/dist/assets/{TemplatePreviewModal-C7-G6lvI.js → TemplatePreviewModal-B8yd1AGU.js} +1 -1
- package/client/dist/assets/{TicketDetailModalContext-gGUv7gsQ.js → TicketDetailModalContext-YBJX3RmP.js} +1 -1
- package/client/dist/assets/{Trans-Br_OIUKP.js → Trans-D5eOjfvG.js} +1 -1
- package/client/dist/assets/agentRuntime-B-myNBUP.js +1 -0
- package/client/dist/assets/agentRuntime-Bjt7Ij6_.js +1 -0
- package/client/dist/assets/agentRuntime-C_yLPKDy.js +1 -0
- package/client/dist/assets/agentRuntime-D2kYQqNO.js +1 -0
- package/client/dist/assets/agentRuntime-DvhEe1um.js +1 -0
- package/client/dist/assets/agentRuntime-DxC6-9rN.js +1 -0
- package/client/dist/assets/agentRuntime-TKQyg137.js +1 -0
- package/client/dist/assets/agentRuntime-WSv8G0pW.js +1 -0
- package/client/dist/assets/agents-B6ZsnARo.js +1 -0
- package/client/dist/assets/agents-BORdhe0K.js +1 -0
- package/client/dist/assets/agents-C6aq9Oqs.js +1 -0
- package/client/dist/assets/agents-Cbsc4bcX.js +1 -0
- package/client/dist/assets/agents-D0uYR6hq.js +1 -0
- package/client/dist/assets/agents-Doe1sHY5.js +1 -0
- package/client/dist/assets/agents-DyNi_I9m.js +1 -0
- package/client/dist/assets/agents-StKxiTg0.js +1 -0
- package/client/dist/assets/agentstudio-7cYCXn-L.js +1 -0
- package/client/dist/assets/{agentstudio-QdAJIDef.js → agentstudio-BHWQh8G3.js} +1 -1
- package/client/dist/assets/agentstudio-BjnWHyRs.js +1 -0
- package/client/dist/assets/{agentstudio-fLXpRGIi.js → agentstudio-BkV8vcK4.js} +1 -1
- package/client/dist/assets/{agentstudio-BWAKeGgB.js → agentstudio-BzugqB_N.js} +1 -1
- package/client/dist/assets/{agentstudio-Cja8Sjcp.js → agentstudio-CWbp7KvH.js} +1 -1
- package/client/dist/assets/agentstudio-DG6plf5o.js +1 -0
- package/client/dist/assets/agentstudio-DkZVF-Cc.js +1 -0
- package/client/dist/assets/{formatDistanceToNow-Q7QPRFV4.js → formatDistanceToNow-DZ3VWsHq.js} +1 -1
- package/client/dist/assets/{getTimezoneOffsetInMilliseconds-Bq0CXBaJ.js → getTimezoneOffsetInMilliseconds-9JiGlFrx.js} +1 -1
- package/client/dist/assets/{index-DVkWHOR3.js → index-lTGJJTuk.js} +8 -8
- package/client/dist/assets/{jira-api-C2Tzc362.js → jira-api-Bp0zXwjg.js} +1 -1
- package/client/dist/assets/{loops-Cm55CXJ4.js → loops-B2PhQLKR.js} +1 -1
- package/client/dist/assets/{loops-3IutojWt.js → loops-BqbF46st.js} +1 -1
- package/client/dist/assets/{loops-BAosWtXE.js → loops-CINnHbfI.js} +1 -1
- package/client/dist/assets/{loops-kIJJkaxf.js → loops-D-3XhH04.js} +1 -1
- package/client/dist/assets/{loops-DHQtnfze.js → loops-DKkEEjZ_.js} +1 -1
- package/client/dist/assets/{loops-D7tL_Saw.js → loops-DzWR5-v6.js} +1 -1
- package/client/dist/assets/{loops--KWr0X-w.js → loops-WyWDkhok.js} +1 -1
- package/client/dist/assets/{loops-BISDssL5.js → loops-scD5fIBf.js} +1 -1
- package/client/dist/assets/{narration-DvLQBW9U.js → narration-BEKMVxGm.js} +1 -1
- package/client/dist/assets/{narration-CHI06czm.js → narration-CjLwGKap.js} +1 -1
- package/client/dist/assets/{narration-DjKB3pQZ.js → narration-DANWuGsW.js} +1 -1
- package/client/dist/assets/{narration-eSx3gR0W.js → narration-DGeEDWiT.js} +1 -1
- package/client/dist/assets/{narration-DtCYvRLM.js → narration-DJgpGwIP.js} +1 -1
- package/client/dist/assets/{narration-n3hOA7LY.js → narration-DbHnz0qV.js} +1 -1
- package/client/dist/assets/{narration-thJOeT2-.js → narration-bZSsTZG8.js} +1 -1
- package/client/dist/assets/{narration--hUhjM5v.js → narration-i6aKJKEc.js} +1 -1
- package/client/dist/assets/{project-repositories-DZKmieH3.js → project-repositories-CadLZOnr.js} +1 -1
- package/client/dist/assets/{spending-EXaboRU0.js → spending-DQDNtM8q.js} +1 -1
- package/client/dist/assets/{useDesktop-ChSmmJfc.js → useDesktop-DKNbOF0u.js} +1 -1
- package/client/dist/assets/{useRuntimeRuns-w9-5OzZl.js → useRuntimeRuns-D3YMw9qx.js} +1 -1
- package/client/dist/assets/{useSharedWebSocket-g0nTHfTT.js → useSharedWebSocket-DaWuiO0S.js} +2 -2
- package/client/dist/index.html +19 -19
- package/docs/getting-started.md +2 -2
- package/docs/guide/de/agents/1-meet-the-agents.md +1 -1
- package/docs/guide/de/agents/2-profiles-and-the-balanced-default.md +1 -1
- package/docs/guide/de/agents/3-customizing-models-per-agent.md +1 -1
- package/docs/guide/de/agents/4-custom-agents-catalog.md +3 -3
- package/docs/guide/en/agents/1-meet-the-agents.md +1 -1
- package/docs/guide/en/agents/2-profiles-and-the-balanced-default.md +1 -1
- package/docs/guide/en/agents/3-customizing-models-per-agent.md +1 -1
- package/docs/guide/en/agents/4-custom-agents-catalog.md +3 -3
- package/docs/guide/es/agents/1-meet-the-agents.md +1 -1
- package/docs/guide/es/agents/2-profiles-and-the-balanced-default.md +1 -1
- package/docs/guide/es/agents/3-customizing-models-per-agent.md +1 -1
- package/docs/guide/es/agents/4-custom-agents-catalog.md +3 -3
- package/docs/guide/fr/agents/1-meet-the-agents.md +1 -1
- package/docs/guide/fr/agents/2-profiles-and-the-balanced-default.md +1 -1
- package/docs/guide/fr/agents/3-customizing-models-per-agent.md +1 -1
- package/docs/guide/fr/agents/4-custom-agents-catalog.md +3 -3
- package/docs/guide/it/agents/1-meet-the-agents.md +1 -1
- package/docs/guide/it/agents/2-profiles-and-the-balanced-default.md +1 -1
- package/docs/guide/it/agents/3-customizing-models-per-agent.md +1 -1
- package/docs/guide/it/agents/4-custom-agents-catalog.md +3 -3
- package/docs/guide/ja/agents/1-meet-the-agents.md +1 -1
- package/docs/guide/ja/agents/2-profiles-and-the-balanced-default.md +1 -1
- package/docs/guide/ja/agents/3-customizing-models-per-agent.md +1 -1
- package/docs/guide/ja/agents/4-custom-agents-catalog.md +3 -3
- package/docs/guide/pt/agents/1-meet-the-agents.md +1 -1
- package/docs/guide/pt/agents/2-profiles-and-the-balanced-default.md +1 -1
- package/docs/guide/pt/agents/3-customizing-models-per-agent.md +1 -1
- package/docs/guide/pt/agents/4-custom-agents-catalog.md +3 -3
- package/docs/guide/zh/agents/1-meet-the-agents.md +1 -1
- package/docs/guide/zh/agents/2-profiles-and-the-balanced-default.md +1 -1
- package/docs/guide/zh/agents/3-customizing-models-per-agent.md +1 -1
- package/docs/guide/zh/agents/4-custom-agents-catalog.md +3 -3
- package/docs/internals/adding-a-provider.md +7 -6
- package/docs/internals/configuration.md +2 -0
- package/docs/internals/core-runtime-updates.md +22 -3
- package/docs/internals/profiles.md +17 -10
- package/docs/internals/programmatic-agent-runtime.md +2 -0
- package/docs/internals/review-packet.md +1 -1
- package/docs/internals/source-map.md +1 -1
- package/docs/running-pipelines.md +2 -2
- package/package.json +1 -1
- package/server/dist/core-compat.js +7 -3
- package/server/dist/mcp/guide.js +4 -3
- package/server/dist/modules/agent-runtime/runtime/agent-runtime-bridge.js +19 -3
- package/server/dist/modules/agent-runtime/runtime/agent-runtime-effective-config.js +2 -0
- package/server/dist/modules/agent-runtime/runtime/agent-runtime-settings-router.js +6 -2
- package/server/dist/modules/agent-runtime/runtime/agent-runtime-settings.js +42 -7
- package/server/dist/modules/agents/runtime/profiles-router.js +74 -36
- package/server/dist/modules/execution/runtime/queue-manager.js +7 -9
- package/server/dist/modules/loops/runtime/loop-agents.js +2 -5
- package/server/dist/modules/loops/runtime/loop-command-catalog.js +5 -5
- package/server/dist/modules/loops/runtime/loop-core-factory.js +2 -2
- package/server/dist/modules/loops/runtime/loop-definition.js +2 -1
- package/server/dist/modules/loops/runtime/loop-executors.js +0 -2
- package/server/dist/modules/loops/runtime/loop-factory.js +1 -1
- package/server/dist/modules/loops/runtime/loop-graph.js +8 -1
- package/server/dist/modules/loops/runtime/loop-implement-recipe.js +33 -13
- package/server/dist/modules/loops/runtime/loop-templates.js +3 -3
- package/server/dist/modules/loops/runtime/loops-router.js +3 -1
- package/server/dist/providers/gemini-agent-ack.js +13 -10
- package/server/dist/schemas/agent-runtime.schema.json +9 -7
- package/server/dist/setup-manager.js +28 -43
- package/server/dist/workspace-manager.js +13 -71
- package/client/dist/assets/InteractiveJobComposer-DkqR77pO.js +0 -19
- package/client/dist/assets/LoopBuilderPage-C4S-rkWp.js +0 -1
- package/client/dist/assets/agentRuntime-15Pkk6we.js +0 -1
- package/client/dist/assets/agentRuntime-Bpx3yWHK.js +0 -1
- package/client/dist/assets/agentRuntime-C78n13To.js +0 -1
- package/client/dist/assets/agentRuntime-CCI7XF4c.js +0 -1
- package/client/dist/assets/agentRuntime-CKDHe2-a.js +0 -1
- package/client/dist/assets/agentRuntime-Ddqvp2bP.js +0 -1
- package/client/dist/assets/agentRuntime-TXPQowKJ.js +0 -1
- package/client/dist/assets/agentRuntime-hqZRy08E.js +0 -1
- package/client/dist/assets/agents-CA5eT1d0.js +0 -1
- package/client/dist/assets/agents-CAgy-5uS.js +0 -1
- package/client/dist/assets/agents-CNm6Qzlv.js +0 -1
- package/client/dist/assets/agents-CTwbx-fb.js +0 -1
- package/client/dist/assets/agents-DEGV1Vao.js +0 -1
- package/client/dist/assets/agents-HsDF1aQU.js +0 -1
- package/client/dist/assets/agents-IQjdA-z9.js +0 -1
- package/client/dist/assets/agents-RkGoteXh.js +0 -1
- package/client/dist/assets/agentstudio-B2CTtQgZ.js +0 -1
- package/client/dist/assets/agentstudio-DtfPcr99.js +0 -1
- package/client/dist/assets/agentstudio-X70BKf6u.js +0 -1
- package/client/dist/assets/agentstudio-qXKqVnWS.js +0 -1
- package/server/dist/modules/loops/runtime/loop-agent-defaults.json +0 -6
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-zu2_FqZY.js";import{d as r,u as i}from"./chunk-KS7C4IRE-DEKu087k.js";import{n as a,t as o}from"./createLucideIcon-Bjbbp_KS.js";import{a as s,r as c,s as l}from"./useDesktop-DKNbOF0u.js";import{r as u}from"./provider-capabilities-lePfeT_Y.js";import{n as d,r as f,t as p}from"./save-OsUqVn99.js";import{t as m}from"./external-link-D6XxC_Cu.js";import{t as h}from"./git-branch-BRM0F5GN.js";import{n as g,t as _}from"./square-Ci-PFcFe.js";import{t as v}from"./plus-CsnjfkmX.js";import{t as ee}from"./rotate-ccw-Wh4id13q.js";import{t as y}from"./trash-2-BOU3WdZZ.js";import{t as te}from"./triangle-alert-H9T4jAmh.js";import{t as ne}from"./upload-DYMjAQ6M.js";import{t as re}from"./x-CBMI9ejn.js";import{a as ie,i as ae,l as oe,o as b,r as x,t as se}from"./dialog-CMgps2MY.js";import{t as S}from"./utils-BC4DHlz2.js";import{t as C}from"./button-D1xExSTF.js";import{n as w,t as T}from"./project-repositories-CadLZOnr.js";import{Ft as ce,J as le,K as ue,Mt as de,U as E,Ut as fe,Vt as pe,Y as me,Yt as he,bt as ge,c as D,d as _e,f as ve,gt as O,in as ye,it as k,l as A,m as j,ot as M,p as be,q as xe,rn as Se,rt as Ce,tn as we,u as N,xt as P,zt as Te}from"./index-lTGJJTuk.js";import{a as Ee,c as De,d as Oe,f as ke,i as F,l as Ae,m as I,n as je,o as Me,p as Ne,r as Pe,s as Fe,t as Ie,u as Le}from"./loop-layout-BF8xMiNv.js";var Re=o(`grid-3x3`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M3 9h18`,key:`1pudct`}],[`path`,{d:`M3 15h18`,key:`5xshup`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}]]),ze=o(`move-horizontal`,[[`path`,{d:`m18 8 4 4-4 4`,key:`1ak13k`}],[`path`,{d:`M2 12h20`,key:`9i4pu4`}],[`path`,{d:`m6 8-4 4 4 4`,key:`15zrgr`}]]),Be=o(`move-vertical`,[[`path`,{d:`M12 2v20`,key:`t6zp3m`}],[`path`,{d:`m8 18 4 4 4-4`,key:`bh5tu3`}],[`path`,{d:`m8 6 4-4 4 4`,key:`ybng9g`}]]),L=e(t(),1),R=n(),z=`h-9 w-full rounded-md border border-input bg-background px-2 text-sm`;function Ve({roles:e={},provider:t,supported:n,onChange:r,renderEngine:i,visibleRoleIds:o,manageRoles:s=!0}){let{t:c}=a(`agentRuntime`),[l,u]=(0,L.useState)(``),[d,f]=(0,L.useState)(!1),p=Object.entries(e).filter(([e])=>!ve.includes(e)&&(!o||o.includes(e)));function m(){if(!D.test(l)||l===`fixer`||ve.includes(l)||Object.prototype.hasOwnProperty.call(e,l)){f(!0);return}r({...e,[l]:{provider:t,access:`read`,artifacts:`none`}}),u(``),f(!1)}return(0,R.jsxs)(`section`,{className:`space-y-3`,"aria-labelledby":`custom-runtime-roles`,children:[s&&(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`h3`,{id:`custom-runtime-roles`,className:`text-sm font-medium`,children:c(`customRoles.title`)}),(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:c(`customRoles.hint`)})]}),!n&&(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:c(`customRoles.unsupported`)}),p.map(([t,a])=>{let o=n=>r({...e,[t]:{...a,...n}});return(0,R.jsxs)(`fieldset`,{className:`space-y-3 rounded-lg border p-3`,"aria-label":t,children:[(0,R.jsx)(`legend`,{className:`px-1 font-mono text-sm`,children:t}),s&&(0,R.jsx)(`div`,{className:`flex justify-end`,children:(0,R.jsx)(C,{size:`sm`,variant:`ghost`,onClick:()=>{let n={...e};delete n[t],r(n)},children:c(`customRoles.remove`,{id:t})})}),(0,R.jsxs)(`fieldset`,{disabled:!n,className:`space-y-3`,children:[i(t),(0,R.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,R.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[c(`customRoles.access`),(0,R.jsxs)(`select`,{className:z,value:a.access,onChange:e=>o({access:e.target.value}),children:[(0,R.jsx)(`option`,{value:`read`,children:c(`customRoles.read`)}),(0,R.jsx)(`option`,{value:`write`,children:c(`customRoles.write`)})]})]}),(0,R.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[c(`customRoles.artifacts`),(0,R.jsxs)(`select`,{className:z,value:a.artifacts,onChange:e=>o({artifacts:e.target.value}),children:[(0,R.jsx)(`option`,{value:`none`,children:c(`customRoles.none`)}),(0,R.jsx)(`option`,{value:`tasks-checkboxes`,children:c(`customRoles.tasks`)}),(0,R.jsx)(`option`,{value:`all`,children:c(`customRoles.all`)})]})]})]}),(0,R.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[c(`customRoles.skill`),(0,R.jsxs)(`select`,{className:z,value:a.openspecSkill??``,onChange:e=>o({openspecSkill:e.target.value||void 0}),children:[(0,R.jsx)(`option`,{value:``,children:c(`customRoles.noSkill`)}),[`openspec-ff-change`,`openspec-apply-change`,`openspec-verify-change`].map(e=>(0,R.jsx)(`option`,{value:e,children:e},e))]})]}),(0,R.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[c(`customRoles.prompt`),(0,R.jsx)(`textarea`,{className:`w-full rounded-md border border-input bg-background px-3 py-2 text-sm`,value:a.prompt??``,rows:5,maxLength:2e4,onChange:e=>o({prompt:e.target.value||void 0})})]})]})]},t)}),s&&(0,R.jsxs)(`fieldset`,{disabled:!n||!t,className:`flex items-end gap-2`,children:[(0,R.jsxs)(`label`,{className:`min-w-0 flex-1 space-y-1 text-xs`,children:[c(`customRoles.id`),(0,R.jsx)(E,{value:l,maxLength:64,placeholder:`security-reviewer`,onChange:e=>{u(e.target.value),f(!1)}})]}),(0,R.jsx)(C,{variant:`secondary`,onClick:m,children:c(`customRoles.add`)})]}),d&&(0,R.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive`,children:c(`customRoles.invalidId`)})]})}var He={architect:fe,developer:ce,host:O};function Ue({projectId:e,catalogUrl:t,guardrails:n,onChange:r}){let{t:i,i18n:o}=a(`agentRuntime`),[s,c]=(0,L.useState)(!0),[l,u]=(0,L.useState)({status:`loading`});(0,L.useEffect)(()=>{let n=!1;return u({status:`loading`}),fetch(t??`${w(e)}/agent-runtime/guardrails`,{cache:`no-store`}).then(async e=>{if(!e.ok)throw Error(`guardrails`);let r=await e.json(),i=t?r.guardrails:r;if(!be(i))throw Error(`guardrails`);n||u({status:`ready`,supported:i.supported,catalog:i.catalog})}).catch(()=>{n||u({status:`unsupported`})}),()=>{n=!0}},[e,t]);let f=l.status===`ready`?l.catalog:[],p=l.status===`ready`&&l.supported,m=f.filter(e=>n?.[e.id]===!1).length,h=f.length,g=e=>o.exists(`agentRuntime:guardrails.items.${e}.title`),_=`pipeline-guardrails-body`;return(0,R.jsxs)(`fieldset`,{id:`pipeline-guardrails`,"data-testid":`phase-card-guardrails`,className:`scroll-mt-4 rounded-lg border border-border transition-shadow`,children:[(0,R.jsx)(`legend`,{className:`sr-only`,children:i(`guardrails.title`)}),(0,R.jsxs)(`button`,{type:`button`,"aria-expanded":s,"aria-controls":_,"aria-label":`${i(s?`pipeline.collapse`:`pipeline.open`)}: ${i(`guardrails.title`)}`,onClick:()=>c(e=>!e),className:`flex w-full flex-wrap items-center gap-2 rounded-t-lg px-3 py-2 text-left hover:bg-muted/40`,children:[(0,R.jsx)(`span`,{className:`flex h-5 w-5 shrink-0 items-center justify-center rounded-full bg-accent-success/15 text-accent-success`,children:(0,R.jsx)(ge,{className:`h-3.5 w-3.5`,"aria-hidden":!0})}),(0,R.jsx)(`span`,{className:`text-xs font-medium`,children:i(`guardrails.title`)}),(0,R.jsxs)(`span`,{className:`ml-auto flex items-center gap-2`,children:[l.status===`ready`&&p&&(0,R.jsx)(`span`,{"data-testid":`guardrails-active`,className:S(`inline-flex items-center rounded-md border px-1.5 py-0.5 text-[11px] leading-4`,m?`border-accent-warning/40 bg-accent-warning/10 text-accent-warning`:`border-accent-success/30 bg-accent-success/10 text-accent-success`),children:i(`guardrails.active`,{on:h-m,total:h})}),(0,R.jsx)(d,{className:`h-3.5 w-3.5 text-muted-foreground transition-transform ${s?``:`-rotate-90`}`,"aria-hidden":!0})]})]}),(0,R.jsxs)(`div`,{id:_,hidden:!s,className:`space-y-3 px-3 pb-3`,children:[(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i(`guardrails.intro`)}),l.status===`loading`&&(0,R.jsx)(`p`,{role:`status`,className:`text-xs text-muted-foreground`,children:i(`loading`)}),(l.status===`unsupported`||l.status===`ready`&&!p)&&(0,R.jsx)(`p`,{role:`status`,className:`rounded-md border border-accent-warning/40 p-3 text-xs text-accent-warning`,children:i(`guardrails.unsupported`)}),l.status===`ready`&&(0,R.jsxs)(`fieldset`,{disabled:!p,className:`space-y-3 disabled:opacity-60`,children:[m>0&&(0,R.jsx)(`div`,{className:`flex justify-end`,children:(0,R.jsx)(`button`,{type:`button`,className:`text-[11px] text-accent-primary underline-offset-2 hover:underline`,onClick:()=>r(void 0),children:i(`guardrails.reset`)})}),A.map(e=>{let t=f.filter(t=>t.phase===e);if(!t.length)return null;let a=He[e];return(0,R.jsxs)(`div`,{className:`space-y-2`,"data-testid":`guardrails-phase-${e}`,children:[(0,R.jsxs)(`p`,{className:`flex items-center gap-1.5 text-[11px] font-medium uppercase tracking-wide text-muted-foreground`,children:[(0,R.jsx)(a,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),i(`guardrails.phases.${e}`)]}),(0,R.jsx)(`ul`,{className:`divide-y divide-border/60 rounded-md border border-border/60`,children:t.map(e=>{let t=n?.[e.id]!==!1,a=g(e.id)?i(`guardrails.items.${e.id}.title`):e.id,o=g(e.id)?i(`guardrails.items.${e.id}.description`):i(`guardrails.unknown`),s=g(e.id)?i(`guardrails.items.${e.id}.why`):null,c=`guardrail-${e.id}-title`;return(0,R.jsxs)(`li`,{className:`flex items-start gap-3 px-3 py-2`,children:[(0,R.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":t,"aria-labelledby":c,"data-testid":`guardrail-${e.id}`,onClick:()=>r(j(n,e.id,!t)),className:S(`relative mt-0.5 inline-flex h-4 w-7 shrink-0 items-center rounded-full transition-colors`,t?`bg-accent-primary/70`:`bg-muted-foreground/30`),children:(0,R.jsx)(`span`,{className:S(`absolute h-3 w-3 rounded-full bg-background shadow transition-transform`,t?`translate-x-3.5`:`translate-x-0.5`)})}),(0,R.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,R.jsx)(`p`,{id:c,className:S(`text-xs font-medium`,!t&&`text-muted-foreground line-through decoration-muted-foreground/50`),children:a}),(0,R.jsx)(`p`,{className:`mt-0.5 text-[11px] leading-4 text-muted-foreground`,children:o}),s&&(0,R.jsx)(`p`,{className:`mt-0.5 text-[10px] italic leading-4 text-muted-foreground/70`,children:s})]})]},e.id)})})]},e)})]})]})]})}var We=`h-9 w-full rounded-md border border-input bg-background px-2 text-sm`;function B({config:e,onChange:t}){let{t:n}=a(`agentRuntime`),r=e.efficiency??{schemaVersion:1};return(0,R.jsxs)(`section`,{className:`space-y-3`,"aria-label":n(`efficiency.title`),children:[(0,R.jsx)(`h3`,{className:`text-sm font-medium`,children:n(`efficiency.title`)}),(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`efficiency.scope`)}),(0,R.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-3`,children:[`contextMode`,`reviewMode`,`planning`].map(i=>(0,R.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[n(`efficiency.${i}`),(0,R.jsxs)(`select`,{className:We,value:r[i]??(i===`planning`?`proportional`:`incremental`),onChange:n=>t({...e,efficiency:{...r,[i]:n.target.value}}),children:[(0,R.jsx)(`option`,{value:i===`planning`?`proportional`:`incremental`,children:n(`efficiency.adaptive`)}),(0,R.jsx)(`option`,{value:`full`,children:n(`efficiency.full`)})]})]},i))}),(0,R.jsxs)(`label`,{className:`flex items-center gap-2 text-xs`,children:[(0,R.jsx)(`input`,{type:`checkbox`,checked:r.acceptDeveloperChecks!==!1,onChange:n=>t({...e,efficiency:{...r,acceptDeveloperChecks:n.target.checked}})}),n(`efficiency.developerChecks`)]}),(0,R.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[n(`efficiency.concurrency`),(0,R.jsx)(E,{type:`number`,min:`1`,max:`4`,step:`1`,value:r.verification?.maxConcurrency??1,onChange:n=>t({...e,efficiency:{...r,verification:{...r.verification,maxConcurrency:Number(n.target.value)}}})})]}),(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`efficiency.concurrencyHint`)})]})}function Ge(e){let t=[],n=0;function r(i,a,o){if(!(o.length>=32||t.length>=1e4))for(let s of i.nodes){if(++n>1e4)return;if(s.type!==`core`)continue;let i=a+s.id,c=s.data?.kind,l=V(s.data?.params);(c===`role-turn`||c===`implementation-step`&&l.phase===`reviewer`)&&t.push(i);let u=c===`component`?l.ref:c===`map`?l.body:void 0;typeof u==`string`&&!o.includes(u)&&e.components?.[u]&&r(e.components[u],i+`/`,[...o,u])}}return r(e,``,[]),t.sort()}var V=e=>typeof e==`object`&&e&&!Array.isArray(e)?e:{};function H(e){return typeof e.type==`string`?e.type:e.properties||e.additionalProperties?`object`:e.items?`array`:`string`}function U(e){if(`default`in e)return structuredClone(e.default);if(`const`in e)return structuredClone(e.const);if(Array.isArray(e.enum))return structuredClone(e.enum[0]);let t=e.oneOf??e.anyOf;if(Array.isArray(t)&&!e.properties)return U(V(t[0]));switch(H(e)){case`boolean`:return!1;case`number`:case`integer`:return typeof e.minimum==`number`?e.minimum:0;case`array`:return[];case`object`:{let t=V(e.properties);return Object.fromEntries((Array.isArray(e.required)?e.required:[]).filter(e=>typeof e==`string`).map(e=>[e,U(V(t[e]))]))}default:return``}}function Ke(e){let t=V(U(e.paramsSchema));return e.kind===`prompt`&&(t.text=``,t.engine={provider:`claude`},t.access=`read`),e.kind===`shell`&&(t.argv=[``]),e.kind===`assign`&&(t.set={}),{kind:`core`,coreKind:e.kind,params:t}}function qe(e,t,n={}){if(!e)return[];let r=e.outcomes;return e.kind===`prompt`&&(r=t.sentinel===`verification`?[`pass`,`fail`,`failed`]:t.sentinel===`blocked`?[`next`,`blocked`,`failed`]:[`next`,`failed`]),e.kind===`role-turn`&&(r=t.structuredOutput?[`next`,`invalid`,`failed`]:[`next`,`failed`]),e.kind===`verify`&&t.hostBlockers!==!0&&(r=r.filter(e=>e!==`blocked`)),e.kind===`component`?n[String(t.ref)]?.outputs??[`next`,`failed`]:r.filter(t=>e.outcomes.includes(t))}var Je=e=>[`prompt`,`role-turn`,`decider`,`implementation`,`implementation-step`].includes(e)?`ai`:[`verify`,`shell`].includes(e)?`verification`:e===`artifact-contract`||e.startsWith(`openspec-`)?`openspec`:`control`;function Ye(e,t,n){return t===`implementation`?[`architect`,`developer`,`reviewer`,`fixer`]:t===`implementation-step`?[`architect`,`developer`,`reviewer`,`fixer`].includes(String(n.phase))?[String(n.phase)]:[]:t===`prompt`?[e===`fix`?`fixer`:e===`prepare`?`architect`:n.access===`read`?`reviewer`:`developer`]:(t===`role-turn`||t===`decider`)&&typeof n.roleId==`string`?[n.roleId]:[]}function Xe(e){let t=new Set,n=new Set;function r(i){for(let a of i.nodes){if(a.type!==`core`)continue;let i=V(a.data?.params),o=a.data?.kind;Ye(a.id,o,i).forEach(e=>t.add(e));let s=o===`component`?i.ref:o===`map`?i.body:void 0;typeof s==`string`&&!n.has(s)&&e.components?.[s]&&(n.add(s),r(e.components[s]))}}return r(e),[...t]}var W=`w-full rounded-md border border-input bg-background px-2 py-1 text-xs`,G=[`architect`,`developer`,`reviewer`,`fixer`];function Ze({value:e,onChange:t,selectedRole:n,graph:r,mode:i=`all`}){let{t:o}=a(`agentRuntime`),{activeProjectId:l}=c(),d=(0,L.useRef)(l);d.current=l;let[f,p]=(0,L.useState)([]),[m,h]=(0,L.useState)({}),[g,_]=(0,L.useState)(),[v,ee]=(0,L.useState)(null),[y,te]=(0,L.useState)(``),[ne,re]=(0,L.useState)(!1),[ie,ae]=(0,L.useState)(!1),oe=r?Xe(r):[...G,...Object.keys(e?.roles??{})],b=i===`step`?[n??``]:ie?void 0:oe,x=i!==`workflow`,se=i!==`step`,S=i===`step`?`loopAgents.stepTitle`:i===`workflow`?`loopAgents.policy`:`loopAgents.title`,w=[...G,...Object.keys(e?.roles??{})].some(e=>!oe.includes(e));(0,L.useEffect)(()=>{let e=new AbortController;return Promise.all([`/api/runtime-providers`,`/api/loop-agent-defaults`].map(t=>fetch(t,{signal:e.signal}).then(async e=>{if(!e.ok)throw Error(o(`loadFailed`));return e.json()}))).then(([t,n])=>{e.signal.aborted||(p(t.providers??[]),_(n.agents),ee(n.rolePromptDefaults??null),h(Object.fromEntries(Object.entries(t.status??{}).map(([e,t])=>[e,t.models??[]]))))}).catch(()=>{e.signal.aborted||te(o(`loadFailed`))}),()=>e.abort()},[o]);async function T(){let e=l;re(!0),te(``);try{let n=s(),[r,i]=await Promise.all([fetch(`${n}/agent-runtime/config`),fetch(`${n}/agent-runtime/loop-roles`)]);if(!r.ok||!i.ok)throw Error(o(`loadFailed`));let a=await r.json(),c=await i.json(),{agents:l,fixer:u,roles:f,rolePrompts:p,limits:m,review:h,architect:_,approvalBeforeArchive:v,efficiency:ee,guardrails:y}=a.config;if(!e||d.current!==e)return;t({schemaVersion:1,agents:l,fixer:u,roles:{...g?.roles,...Object.fromEntries(Object.entries(f??{}).map(([e,t])=>[e,{...t,prompt:p?.[e]??t.prompt}])),...c.roles?.decider?{"loop-decider":{...g.roles[`loop-decider`],...c.roles.decider}}:{}},rolePrompts:Object.fromEntries(Object.entries({...g?.rolePrompts,...p}).filter(([e])=>G.includes(e))),limits:m,review:h,architect:_,approvalBeforeArchive:v,efficiency:ee,guardrails:y})}catch{te(o(`loadFailed`))}finally{re(!1)}}function ce(n){if(!e)return null;let r=G.includes(n),i=n===`fixer`?e.fixer??e.agents.developer:r?e.agents[n]:e.roles?.[n];if(!i)return null;let a=i=>t(n===`fixer`?{...e,fixer:i}:r?{...e,agents:{...e.agents,[n]:i}}:{...e,roles:{...e.roles,[n]:{...e.roles[n],...i}}}),s=f.find(e=>e.id===i.provider),c=s?.kind===`cli`?M(s.cli).map(e=>e.value):m[i.provider]??[];return(0,R.jsxs)(`div`,{className:`space-y-2`,children:[(0,R.jsxs)(`label`,{className:`block text-xs`,children:[o(`agents.provider`),(0,R.jsxs)(`select`,{className:W,value:i.provider,onChange:e=>a({provider:e.target.value,maxTurns:i.maxTurns}),children:[(0,R.jsx)(`option`,{value:`inherit`,children:o(`loopAgents.inheritProvider`)}),!s&&i.provider!==`inherit`&&u(i.provider)&&(0,R.jsx)(`option`,{value:i.provider,children:i.provider}),f.filter(e=>u(e.kind===`cli`?e.cli:e.id)).map(e=>(0,R.jsx)(`option`,{value:e.id,children:e.kind===`openai-compatible`?e.label??e.id:e.id},e.id))]})]}),(0,R.jsxs)(`label`,{className:`block text-xs`,children:[o(`agents.model`),(0,R.jsx)(E,{value:i.model??``,list:`loop-models-${n}`,onChange:e=>a({...i,model:e.target.value||void 0})}),(0,R.jsx)(`datalist`,{id:`loop-models-${n}`,children:c.map(e=>(0,R.jsx)(`option`,{value:e},e))})]}),(0,R.jsxs)(`label`,{className:`block text-xs`,children:[o(`loopAgents.effort`),(0,R.jsx)(E,{value:i.effort??``,onChange:e=>a({...i,effort:e.target.value||void 0})})]}),(0,R.jsxs)(`label`,{className:`block text-xs`,children:[o(`agents.maxTurns`,{turns:100}),(0,R.jsx)(E,{type:`number`,min:1,value:i.maxTurns??``,onChange:e=>a({...i,maxTurns:e.target.value?Number(e.target.value):void 0})})]}),(0,R.jsxs)(`label`,{className:`block text-xs`,children:[o(`agents.thinking`),(0,R.jsxs)(`select`,{className:W,value:i.thinking??``,onChange:e=>a({...i,thinking:e.target.value?e.target.value:void 0}),children:[(0,R.jsx)(`option`,{value:``,children:o(`loopAgents.default`)}),(0,R.jsx)(`option`,{value:`off`,children:o(`agents.thinking_off`)}),(0,R.jsx)(`option`,{value:`on`,children:o(`agents.thinking_on`)})]})]}),(0,R.jsxs)(`label`,{className:`block text-xs`,children:[o(`loopAgents.escalationModel`),(0,R.jsx)(E,{value:i.escalation?.model??``,onChange:e=>a({...i,escalation:e.target.value?{...i.escalation,model:e.target.value}:void 0})})]}),i.escalation&&(0,R.jsxs)(`label`,{className:`block text-xs`,children:[o(`loopAgents.escalationEffort`),(0,R.jsx)(E,{value:i.escalation.effort??``,onChange:e=>a({...i,escalation:{model:i.escalation.model,effort:e.target.value||void 0}})})]})]})}let le=e?{...e,enabled:!0,providers:f,verification:[]}:void 0;return(0,R.jsxs)(`section`,{className:`space-y-3 border-b border-border pb-4`,"aria-label":o(S),children:[(0,R.jsx)(`h3`,{className:`text-sm font-medium`,children:o(S)}),x&&(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o(i===`step`?`loopAgents.stepHint`:`loopAgents.hint`)}),y&&(0,R.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive`,children:y}),!e&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`p`,{className:`text-xs text-accent-warning`,children:o(`loopAgents.legacy`)}),(0,R.jsx)(C,{size:`sm`,disabled:!g,onClick:()=>g&&t(structuredClone(g)),children:o(`loopAgents.enable`)})]}),i!==`step`&&(0,R.jsx)(C,{size:`sm`,variant:`secondary`,disabled:!l||!g||ne,onClick:()=>void T(),children:o(`loopAgents.import`)}),e&&(0,R.jsxs)(R.Fragment,{children:[i===`all`&&w&&(0,R.jsxs)(`label`,{className:`flex gap-2 text-xs`,children:[(0,R.jsx)(`input`,{type:`checkbox`,checked:ie,onChange:e=>ae(e.target.checked)}),o(`loopAgents.showUnused`)]}),x&&G.filter(e=>!b||b.includes(e)).map(r=>(0,R.jsxs)(`details`,{open:n===r,className:`rounded-md border border-border p-2`,children:[(0,R.jsx)(`summary`,{className:`cursor-pointer text-sm font-medium`,children:r}),(0,R.jsxs)(`div`,{className:`mt-3 space-y-3`,children:[ce(r),e.rolePrompts?.[r]===`inherit`?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o(`loopAgents.inheritDefinition`)}),(0,R.jsx)(`textarea`,{readOnly:!0,"aria-label":o(`customRoles.prompt`),className:`${W} opacity-80`,rows:8,value:v?.[r]??o(`loopAgents.coreDefinitionUnavailable`)}),(0,R.jsx)(C,{size:`sm`,variant:`ghost`,disabled:!v?.[r],onClick:()=>t({...e,rolePrompts:{...e.rolePrompts,[r]:v?.[r]??``}}),children:o(`loopAgents.customizeDefinition`)})]}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`label`,{className:`block text-xs`,children:[o(`customRoles.prompt`),(0,R.jsx)(`textarea`,{className:W,rows:10,maxLength:2e4,value:e.rolePrompts?.[r]??``,onChange:n=>t({...e,rolePrompts:{...e.rolePrompts,[r]:n.target.value}})})]}),(0,R.jsx)(C,{size:`sm`,variant:`ghost`,onClick:()=>t({...e,rolePrompts:{...e.rolePrompts,[r]:`inherit`}}),children:o(`loopAgents.restoreDefinition`)})]})]})]},r)),i===`step`&&n&&![...G,`archive`,`verify`].includes(n)&&!e.roles?.[n]&&(0,R.jsx)(C,{size:`sm`,disabled:!f.length,onClick:()=>t({...e,roles:{...e.roles,[n]:{provider:`inherit`,access:`read`,artifacts:`none`}}}),children:o(`customRoles.add`)}),(x||i===`workflow`)&&(0,R.jsx)(Ve,{manageRoles:i!==`step`,visibleRoleIds:i===`workflow`?[]:b,roles:e.roles,provider:`inherit`,supported:!0,onChange:n=>{Object.keys(n).some(t=>!e.roles?.[t])&&ae(!0),t({...e,roles:n,rolePrompts:Object.fromEntries(Object.entries(e.rolePrompts??{}).filter(([e])=>G.includes(e)))})},renderEngine:ce}),(0,R.jsxs)(`div`,{className:`space-y-3`,children:[se&&(0,R.jsxs)(`details`,{className:`rounded-md border border-border p-2`,children:[(0,R.jsx)(`summary`,{className:`cursor-pointer text-sm`,children:o(`loopAgents.policy`)}),(0,R.jsxs)(`div`,{className:`mt-3 space-y-3`,children:[[`maxAttempts`,`maxTokens`,`maxCostUsd`,`timeoutMs`].map(n=>(0,R.jsxs)(`label`,{className:`block text-xs`,children:[o(`loopAgents.${n}`),(0,R.jsx)(E,{type:`number`,min:1,value:e.limits?.[n]??``,onChange:r=>t({...e,limits:{...e.limits,[n]:r.target.value?Number(r.target.value):void 0}})})]},n)),(0,R.jsx)(Ue,{catalogUrl:`/api/loop-agent-defaults`,guardrails:e.guardrails,onChange:n=>t({...e,guardrails:n})}),le&&(0,R.jsx)(B,{config:le,onChange:n=>t({...e,efficiency:n.efficiency})})]})]}),(i===`all`||i===`step`&&n===`reviewer`)&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`label`,{className:`block text-xs`,children:[o(`review.minScore`,{score:70}),(0,R.jsx)(E,{type:`number`,min:70,max:100,value:e.review?.minScore??``,onChange:n=>t({...e,review:{...e.review,minScore:n.target.value?Number(n.target.value):void 0}})})]}),N.map(n=>(0,R.jsxs)(`label`,{className:`block text-xs`,children:[o(`review.aspects.${n}`,{score:_e.aspects[n]}),(0,R.jsx)(E,{type:`number`,min:_e.aspects[n],max:100,value:e.review?.aspects?.[n]??``,onChange:r=>t({...e,review:{...e.review,aspects:{...e.review?.aspects,[n]:r.target.value?Number(r.target.value):void 0}}})})]},n))]}),(i===`all`||i===`step`&&n===`architect`)&&(0,R.jsxs)(`label`,{className:`block text-xs`,children:[o(`architect.onLowConfidence`),(0,R.jsxs)(`select`,{className:W,value:e.architect?.onLowConfidence??`ask`,onChange:n=>t({...e,architect:{onLowConfidence:n.target.value}}),children:[(0,R.jsx)(`option`,{value:`ask`,children:o(`architect.ask`)}),(0,R.jsx)(`option`,{value:`proceed`,children:o(`architect.proceed`)})]})]}),(i===`all`||i===`step`&&n===`archive`)&&(0,R.jsxs)(`label`,{className:`flex gap-2 text-xs`,children:[(0,R.jsx)(`input`,{type:`checkbox`,checked:e.approvalBeforeArchive??!1,onChange:n=>t({...e,approvalBeforeArchive:n.target.checked})}),o(`approvalBeforeArchive`)]})]})]})]})}var K=`w-full min-w-0 rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-primary`;function q({schema:e,value:t,onChange:n,path:r=`params`,choices:i={},depth:o=0}){let{t:s}=a(`loops`),c=(0,L.useId)(),[l,u]=(0,L.useState)(``);if(o>24)return(0,R.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive`,children:s(`builder.core.tooDeep`)});let d=typeof e.title==`string`?e.title:r.split(`.`).slice(-1)[0],f=(e,n,a,s)=>(0,R.jsx)(q,{schema:n,value:a,onChange:s,path:`${r}.${e}`,choices:{...i,selectedProvider:typeof V(t).provider==`string`?String(V(t).provider):i.selectedProvider},depth:o+1},e),p=e.oneOf??e.anyOf;if(Array.isArray(p)&&!e.properties){let e=p.map(V),r=Math.max(0,e.findIndex(e=>`const`in e?t===e.const:Array.isArray(e.enum)?e.enum.includes(t):H(e)===(Array.isArray(t)?`array`:typeof t)));return(0,R.jsxs)(`fieldset`,{className:`space-y-2`,children:[(0,R.jsx)(`legend`,{className:`text-xs font-medium`,children:d}),(0,R.jsx)(`label`,{className:`sr-only`,htmlFor:c,children:s(`builder.core.variant`,{name:d})}),(0,R.jsx)(`select`,{id:c,className:K,value:r,onChange:t=>n(U(e[Number(t.target.value)])),children:e.map((e,t)=>(0,R.jsx)(`option`,{value:t,children:String(e.title??e.const??(Array.isArray(e.enum)?e.enum.join(` / `):H(e)))},t))}),f(`value`,e[r],t,n)]})}if(`const`in e)return(0,R.jsxs)(`p`,{className:`text-xs`,children:[(0,R.jsxs)(`span`,{className:`text-muted-foreground`,children:[d,`: `]}),String(e.const)]});if(Array.isArray(e.enum))return(0,R.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[d,(0,R.jsxs)(`select`,{className:K,value:JSON.stringify(t),onChange:e=>n(JSON.parse(e.target.value)),children:[!e.enum.includes(t)&&(0,R.jsx)(`option`,{value:JSON.stringify(t)??``,children:s(`builder.core.select`)}),e.enum.map((e,t)=>(0,R.jsx)(`option`,{value:JSON.stringify(e),children:String(e)},t))]})]});let m=H(e);if(m===`object`){let r=V(t),i=V(e.properties),a=new Set(Array.isArray(e.required)?e.required:[]),o=[...Object.keys(i),...Object.keys(r).filter(e=>!(e in i))],c=(e,t)=>{let a={...r};e===`provider`&&t!==r.provider&&i.model&&(delete a.model,delete a.effort),t===void 0?delete a[e]:Object.defineProperty(a,e,{value:t,enumerable:!0,configurable:!0,writable:!0}),n(a)},m=Array.isArray(p)?p.map(e=>V(e).required).filter(e=>Array.isArray(e)&&e.every(e=>typeof e==`string`)):[],h=t=>{let a={...r};if(m.some(e=>e.includes(t)))for(let e of m)for(let n of e)n!==t&&delete a[n];Object.defineProperty(a,t,{value:U(V(i[t]??e.additionalProperties)),enumerable:!0,configurable:!0,writable:!0}),n(a)};return(0,R.jsxs)(`fieldset`,{className:`space-y-2 min-w-0`,children:[(0,R.jsx)(`legend`,{className:`text-xs font-semibold text-foreground mb-1`,children:d}),o.map(t=>{let n=Object.prototype.hasOwnProperty.call(r,t),o=a.has(t);return!n&&!o?(0,R.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 text-xs rounded border border-border px-2 py-1 mr-1 hover:bg-muted`,onClick:()=>h(t),"aria-label":s(`builder.core.addField`,{name:t}),children:[(0,R.jsx)(v,{className:`h-3 w-3`}),t]},t):(0,R.jsxs)(`div`,{className:`relative border-l border-border pl-2 space-y-1`,children:[!o&&(0,R.jsx)(`button`,{type:`button`,className:`float-right text-muted-foreground hover:text-destructive`,onClick:()=>c(t,void 0),"aria-label":s(`builder.core.removeField`,{name:t}),children:(0,R.jsx)(re,{className:`h-3.5 w-3.5`})}),f(t,V(i[t]??e.additionalProperties),r[t],e=>c(t,e))]},t)}),e.additionalProperties!==!1&&(0,R.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,R.jsx)(`input`,{className:K,value:l,placeholder:s(`builder.core.fieldName`),"aria-label":s(`builder.core.fieldName`),onChange:e=>u(e.target.value)}),(0,R.jsx)(`button`,{type:`button`,className:`p-1.5 text-accent-primary disabled:opacity-40`,disabled:!l.trim()||Object.prototype.hasOwnProperty.call(r,l.trim())||[`__proto__`,`constructor`,`prototype`].includes(l.trim()),onClick:()=>{h(l.trim()),u(``)},"aria-label":s(`builder.core.addField`,{name:l}),children:(0,R.jsx)(v,{className:`h-4 w-4`})})]})]})}if(m===`array`){let r=Array.isArray(t)?t:[],i=V(e.items);return(0,R.jsxs)(`fieldset`,{className:`space-y-2`,children:[(0,R.jsx)(`legend`,{className:`text-xs font-semibold`,children:d}),r.map((e,t)=>(0,R.jsxs)(`div`,{className:`border-l border-border pl-2`,children:[(0,R.jsx)(`button`,{type:`button`,className:`float-right text-muted-foreground hover:text-destructive`,onClick:()=>n(r.filter((e,n)=>n!==t)),"aria-label":s(`builder.core.removeField`,{name:`${d} ${t+1}`}),children:(0,R.jsx)(re,{className:`h-3.5 w-3.5`})}),f(String(t+1),i,e,e=>n(r.map((n,r)=>r===t?e:n)))]},t)),(0,R.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 text-xs text-accent-primary`,disabled:typeof e.maxItems==`number`&&r.length>=e.maxItems,onClick:()=>n([...r,U(i)]),children:[(0,R.jsx)(v,{className:`h-3 w-3`}),s(`builder.core.addItem`)]})]})}if(!Object.keys(e).length){let e=t===null?`null`:Array.isArray(t)?`array`:typeof t,r=[`object`,`array`,`boolean`,`number`,`null`].includes(e)?e:`string`;return(0,R.jsxs)(`div`,{className:`space-y-1`,children:[(0,R.jsxs)(`label`,{className:`text-xs`,children:[s(`builder.core.valueType`),(0,R.jsx)(`select`,{className:K,value:r,onChange:e=>n(e.target.value===`null`?null:U({type:e.target.value})),children:[`string`,`number`,`boolean`,`object`,`array`,`null`].map(e=>(0,R.jsx)(`option`,{children:e},e))})]}),r===`null`?(0,R.jsx)(`span`,{className:`text-xs`,children:`null`}):f(`value`,{type:r},t,n)]})}if(m===`boolean`)return(0,R.jsxs)(`label`,{className:`flex items-center gap-2 text-xs`,children:[(0,R.jsx)(`input`,{type:`checkbox`,checked:t===!0,onChange:e=>n(e.target.checked),className:`accent-accent-primary`}),d]});if(m===`number`||m===`integer`)return(0,R.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[d,(0,R.jsx)(`input`,{type:`number`,className:K,value:typeof t==`number`?t:``,min:typeof e.minimum==`number`?e.minimum:void 0,max:typeof e.maximum==`number`?e.maximum:void 0,step:m===`integer`?1:`any`,onChange:e=>n(e.target.value===``?void 0:Number(e.target.value))})]});let h=d===`provider`?i.providers:d===`roleId`?i.roles:[`ref`,`body`].includes(d)?i.components:void 0,g=d===`model`?i.models?.[i.selectedProvider??``]:void 0,_=[`text`,`prompt`,`question`,`message`,`goal`,`expr`,`commandLine`,`reason`].includes(d);return(0,R.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[d,h?.length&&d!==`roleId`?(0,R.jsxs)(`select`,{className:K,value:typeof t==`string`?t:``,onChange:e=>n(e.target.value),children:[(0,R.jsx)(`option`,{value:``,children:s(`builder.core.select`)}),t&&!h.includes(String(t))?(0,R.jsx)(`option`,{value:String(t),children:String(t)}):null,h.map(e=>(0,R.jsx)(`option`,{children:e},e))]}):_?(0,R.jsx)(`textarea`,{className:`${K} min-h-24 resize-y font-mono`,value:typeof t==`string`?t:``,maxLength:typeof e.maxLength==`number`?e.maxLength:void 0,onChange:e=>n(e.target.value)}):(0,R.jsx)(`input`,{list:g?.length||d===`roleId`&&h?.length?c:void 0,className:K,value:typeof t==`string`?t:``,maxLength:typeof e.maxLength==`number`?e.maxLength:void 0,onChange:e=>n(e.target.value)}),g?.length||d===`roleId`&&h?.length?(0,R.jsx)(`datalist`,{id:c,children:(g??h??[]).map(e=>(0,R.jsx)(`option`,{value:e},e))}):null,typeof e.description==`string`&&(0,R.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:e.description})]})}var J=`w-full min-w-0 rounded border border-border bg-background px-2 py-1 text-xs`,Qe=[`journal`,`change`,`maxTokens`,`maxTransitions`,`policies`];function $e({graph:e,canvas:t,schema:n,onChange:r,onOpenCanvas:i}){let{t:o}=a(`loops`),[s,c]=(0,L.useState)(``),l=V(n.properties),u={type:`object`,additionalProperties:!1,properties:{...Object.fromEntries(Qe.filter(e=>l[e]).map(e=>[e,l[e]])),...V(V(l.budget).properties).maxTokens?{maxTokens:V(V(l.budget).properties).maxTokens}:{}}},d=Object.fromEntries(Object.entries(e.config).filter(([e])=>Qe.includes(e))),f=t?e.components?.[t]:void 0,p=t?[]:Ge(e);return(0,R.jsxs)(R.Fragment,{children:[!t&&(0,R.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[(0,R.jsx)(`span`,{children:o(`builder.core.reviewerStep`)}),(0,R.jsxs)(`select`,{className:J,value:e.config.reviewerStepId??``,onChange:t=>r({...e,config:{...e.config,reviewerStepId:t.target.value||void 0}}),children:[(0,R.jsx)(`option`,{value:``,children:o(`builder.core.reviewerAutomatic`)}),e.config.reviewerStepId&&!p.includes(e.config.reviewerStepId)&&(0,R.jsx)(`option`,{value:e.config.reviewerStepId,children:e.config.reviewerStepId}),p.map(e=>(0,R.jsx)(`option`,{value:e,children:e},e))]}),(0,R.jsx)(`span`,{className:`block text-muted-foreground`,children:o(`builder.core.reviewerHint`)})]}),(0,R.jsx)(q,{schema:u,value:d,path:o(`builder.core.options`),onChange:t=>{let n=Object.fromEntries(Object.entries(e.config).filter(([e])=>!Qe.includes(e)));r({...e,config:{...n,...t}})}}),(0,R.jsxs)(`section`,{className:`space-y-2`,children:[(0,R.jsx)(`p`,{className:`text-xs font-semibold`,children:o(`builder.core.components`)}),(0,R.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:Object.keys(e.components??{}).map(e=>(0,R.jsx)(`button`,{type:`button`,onClick:()=>i(e),className:`text-xs rounded border border-border px-2 py-1 hover:bg-muted`,children:e},e))}),(0,R.jsxs)(`div`,{className:`flex gap-1`,children:[(0,R.jsx)(`input`,{className:J,value:s,"aria-label":o(`builder.core.componentName`),placeholder:o(`builder.core.componentName`),onChange:e=>c(e.target.value)}),(0,R.jsx)(`button`,{type:`button`,disabled:!/^[a-z][a-z0-9-]{0,63}$/.test(s)||!!e.components?.[s],onClick:()=>{i(s,!0),c(``)},"aria-label":o(`builder.core.addComponent`),className:`text-accent-primary disabled:opacity-40`,children:(0,R.jsx)(v,{className:`w-4 h-4`})})]}),f&&t&&(0,R.jsx)(q,{schema:{type:`object`,additionalProperties:!1,required:[`inputs`,`outputs`],properties:{inputs:{type:`array`,items:{type:`string`}},outputs:{type:`array`,items:{type:`string`}}}},value:{inputs:f.inputs??[],outputs:f.outputs??[`next`,`failed`]},path:t,onChange:n=>{r({...e,components:{...e.components,[t]:{...f,...n}}})}})]})]})}function et({nodeId:e,data:t,piece:n,choices:r,schema:i,onChange:o,onDelete:s,onOpenCanvas:c}){let{t:l}=a(`loops`),u=t.params?.ref??t.params?.body,d=V(V(i.$defs).retry),f=n?.paramsSchema??{},p=t.coreKind===`assign`?{set:l(`builder.core.assignment.set`),increment:l(`builder.core.assignment.increment`)}:t.coreKind===`decider`?{continueWhen:l(`builder.core.requiredContinue`)}:{},m=Object.keys(p).length?{...f,properties:Object.fromEntries(Object.entries(V(f.properties)).map(([e,t])=>[e,p[e]?{...V(t),title:p[e]}:t]))}:f;return(0,R.jsxs)(`div`,{className:`space-y-3`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,R.jsx)(`h3`,{className:`text-sm font-semibold`,children:l(`builder.core.pieces.${t.coreKind}`)}),(0,R.jsx)(`button`,{type:`button`,onClick:s,"aria-label":l(`common:actions.delete`),className:`text-muted-foreground hover:text-destructive`,children:(0,R.jsx)(y,{className:`h-4 w-4`})})]}),(0,R.jsxs)(`label`,{className:`block text-xs`,children:[l(`builder.inspector.label`),(0,R.jsx)(`input`,{className:J,value:String(t.label??``),onChange:e=>o({label:e.target.value})})]}),[`implementation`,`implementation-step`].includes(t.coreKind??``)&&(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:l(`builder.core.legacyImplementation`)}),n?(0,R.jsx)(q,{schema:m,value:t.params??{},onChange:e=>o({params:e}),choices:r},e):(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:l(`builder.core.unavailable`)}),[`component`,`map`].includes(t.coreKind)&&typeof u==`string`&&(0,R.jsx)(`button`,{type:`button`,className:`text-xs text-accent-primary`,onClick:()=>c(u),children:l(`builder.core.openComponent`)}),Object.keys(d).length>0&&(0,R.jsx)(q,{schema:d,value:t.retry??{},path:`retry`,onChange:e=>o({retry:e})})]})}function tt(e){return e===`continue`||e===`stop`?e:void 0}function nt(e){switch(e){case`core`:return{kind:e,coreKind:`prompt`,params:{text:``,access:`write`,sessionContinuity:`run`}};case`ai-step`:return{kind:e,prompt:``,provider:`claude`,model:``,effort:`medium`,maxTurns:0};case`shell`:return{kind:e,command:``};case`decider`:return{kind:e,goal:``};case`condition`:return{kind:e,join:`AND`};case`end`:return{kind:e,outcome:`success`};default:return{kind:e}}}function Y(){return globalThis.crypto?.randomUUID?.()??`n-${Date.now()}-${Math.floor(Math.random()*1e9)}`}function rt(e,t){return{id:Y(),type:`loop`,position:t,data:nt(e)}}function it(e){let t=(e.nodes??[]).map(e=>({id:e.id,type:`loop`,position:e.position??{x:0,y:0},data:{...e.data??{},...e.type===`core`?{coreKind:e.data?.kind}:{},kind:e.type}})),n=new Map((e.nodes??[]).map(e=>[e.id,e.type]));return{nodes:t,edges:(e.edges??[]).map(e=>{let t=e.branch??(n.get(e.source)===`decider`?n.get(e.target)===`end`?`stop`:`continue`:void 0);return{id:e.id,source:e.source,target:e.target,sourceHandle:e.label??t??void 0,type:`smoothstep`,markerEnd:{type:Ne.ArrowClosed,width:16,height:16},label:e.label??e.join,data:{...e.join?{join:e.join}:{},...t?{branch:t}:{},...e.label?{label:e.label}:{}},...t?{style:{stroke:t===`stop`?`var(--color-accent-success)`:`var(--color-accent-highlight)`}}:{}}})}}function at(e,t,n,r){let i={...n};return i.legacyDeciderRole&&!e.some(e=>e.data.coreKind===`decider`&&e.data.params?.roleId===i.legacyDeciderRole)&&delete i.legacyDeciderRole,{nodes:e.map(e=>{let{kind:t,coreKind:n,...r}=e.data,i={id:e.id,type:t,position:e.position};return(Object.keys(r).length>0||n)&&(i.data={...r,...t===`core`?{kind:n}:{}}),i}),edges:t.map(t=>{let n=t.data?.join;if(e.find(e=>e.id===t.source)?.data.kind===`core`){let e=t.sourceHandle??t.data?.label;return{id:t.id,source:t.source,target:t.target,...e?{label:e}:{}}}let r=tt(t.sourceHandle)??tt(t.data?.branch);return{id:t.id,source:t.source,target:t.target,...n?{join:n}:{},...r?{branch:r}:{}}}),config:i,...r?{components:r}:{}}}var ot=`specrailsNodes`;function st(e,t){let n=e.filter(e=>e.selected);if(n.length===0)return null;let r=new Set(n.map(e=>e.id));return{specrailsNodes:1,nodes:n,edges:t.filter(e=>r.has(e.source)&&r.has(e.target))}}function ct(e){if(!e)return null;let t;try{t=JSON.parse(e)}catch{return null}let n=t;return!n||n[ot]==null||!Array.isArray(n.nodes)?null:{nodes:n.nodes,edges:Array.isArray(n.edges)?n.edges:[]}}function lt(e,t){let n=t.offset??{x:40,y:40},r=new Set(t.excludeKinds??[]),i=new Map;return{nodes:e.nodes.filter(e=>!r.has(String(e.data?.kind))).map(e=>{let r=t.mintId();return i.set(e.id,r),{...e,id:r,position:{x:e.position.x+n.x,y:e.position.y+n.y},selected:!0}}),edges:e.edges.filter(e=>i.has(e.source)&&i.has(e.target)).map(e=>({...e,id:t.mintId(),source:i.get(e.source),target:i.get(e.target),selected:!1}))}}function ut(e){return typeof e!=`string`||e.trim().length===0}function dt(e,t){let n=e.find(e=>e.data.kind===`start`),r=new Set;if(!n)return r;let i=new Map;for(let e of t)(i.get(e.source)??i.set(e.source,[]).get(e.source)).push(e.target);let a=[n.id];for(;a.length;){let e=a.shift();if(!r.has(e)){r.add(e);for(let t of i.get(e)??[])r.has(t)||a.push(t)}}return r}function ft(e,t){let n=[],r=e.filter(e=>e.data.kind===`start`);r.length===0&&n.push({severity:`error`,code:`NO_START`});for(let e of r.slice(1))n.push({severity:`error`,code:`MULTIPLE_START`,nodeId:e.id});if(e.some(e=>e.data.kind===`end`||e.data.kind===`core`&&e.data.coreKind===`end`)||n.push({severity:`error`,code:`NO_END`}),e.some(e=>e.data.kind===`core`)&&e.some(e=>![`start`,`core`,`end`].includes(e.data.kind))&&n.push({severity:`error`,code:`MIXED_ENGINES`}),r.length===1){let r=dt(e,t);for(let t of e)r.has(t.id)||n.push({severity:`error`,code:`ORPHAN`,nodeId:t.id})}let i=new Map;for(let e of t)(i.get(e.source)??i.set(e.source,[]).get(e.source)).push(e);for(let t of e){let e=i.get(t.id)??[];switch(t.data.kind){case`core`:{(!t.data.coreKind||!t.data.params||typeof t.data.params!=`object`||Array.isArray(t.data.params))&&n.push({severity:`error`,code:`CORE_PIECE`,nodeId:t.id});let r=e.map(e=>e.sourceHandle??e.data?.label);(t.data.coreKind===`end`?e.length>0:!r.length||r.some(e=>!e||!/^[a-z][a-z0-9-]{0,31}$/.test(e))||new Set(r).size!==r.length)&&n.push({severity:`error`,code:`CORE_OUTCOMES`,nodeId:t.id});break}case`decider`:{let r=new Set(e.map(e=>e.sourceHandle??e.data?.branch));(!r.has(`continue`)||!r.has(`stop`))&&n.push({severity:`error`,code:`DECIDER_BRANCHES`,nodeId:t.id}),ut(t.data.goal)&&n.push({severity:`warning`,code:`EMPTY_GOAL`,nodeId:t.id});break}case`ai-step`:ut(t.data.prompt)&&n.push({severity:`warning`,code:`EMPTY_PROMPT`,nodeId:t.id}),e.length===0&&n.push({severity:`warning`,code:`DEAD_END`,nodeId:t.id});break;case`shell`:ut(t.data.command)&&n.push({severity:`warning`,code:`EMPTY_COMMAND`,nodeId:t.id}),e.length===0&&n.push({severity:`warning`,code:`DEAD_END`,nodeId:t.id});break;case`start`:e.length===0&&n.push({severity:`warning`,code:`DEAD_END`,nodeId:t.id});break;default:break}}return n}function pt(e){let t=new Map;for(let n of e)n.nodeId&&(n.severity===`error`||!t.has(n.nodeId))&&t.set(n.nodeId,n.severity);return t}var mt=(0,L.createContext)(new Map),ht=(0,L.createContext)({pieces:[]}),gt=[`start`,`ai-step`,`shell`,`decider`,`end`],_t={core:he,start:g,"ai-step":he,shell:O,decider:h,condition:h,end:Te},vt={core:`border-accent-primary/60`,start:`border-accent-success/60`,"ai-step":`border-accent-primary/60`,shell:`border-accent-warning/60`,decider:`border-accent-highlight/60`,condition:`border-accent-info/60`,end:`border-accent-secondary/60`};function yt({id:e,data:t,selected:n}){let{t:r}=a(`loops`),i=t.kind,o=_t[i]??_,s=String(t.label??``).trim(),c=(0,L.useContext)(mt).get(e),l=(0,L.useContext)(ht),u=qe(l.pieces.find(e=>e.kind===t.coreKind),t.params??{},l.components),d=i===`core`?String(t.params?.roleId??t.params?.ref??t.params?.body??t.params?.text??t.params?.expr??``):i===`ai-step`?String(t.model||t.provider||``):i===`shell`?String(t.command||``):i===`decider`?String(t.goal||``):i===`condition`?String(t.join||`AND`):i===`end`?String(t.outcome||`success`):``;return(0,R.jsxs)(`div`,{className:S(`rounded-md border-2 bg-card px-3 py-2 min-w-[140px] shadow-sm`,vt[i],c===`error`?`ring-2 ring-destructive`:n?`ring-2 ring-accent-primary`:c===`warning`?`ring-2 ring-accent-warning`:``),children:[i!==`start`&&(0,R.jsx)(F,{type:`target`,position:I.Top}),(0,R.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,R.jsx)(o,{className:`w-3.5 h-3.5 text-foreground flex-shrink-0`}),(0,R.jsx)(`span`,{className:`text-xs font-semibold text-foreground truncate max-w-[150px]`,children:s||r(i===`core`?`builder.core.pieces.${t.coreKind}`:`builder.nodes.${i}`)}),s&&(0,R.jsx)(`span`,{className:`text-[9px] text-muted-foreground/70 flex-shrink-0`,children:r(i===`core`?`builder.core.pieces.${t.coreKind}`:`builder.nodes.${i}`)})]}),d&&(0,R.jsx)(`p`,{className:`text-[10px] text-muted-foreground mt-1 truncate max-w-[160px]`,children:d}),i===`core`?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`div`,{className:`flex justify-around gap-2 mt-2 text-[9px] text-accent-primary`,children:u.map(e=>(0,R.jsx)(`span`,{children:e},e))}),u.map((e,t)=>(0,R.jsx)(F,{id:e,type:`source`,position:I.Bottom,style:{left:`${(t+1)*100/(u.length+1)}%`},"aria-label":e},e))]}):i===`decider`?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`div`,{className:`mt-1.5 flex items-center justify-between gap-2 text-[9px] font-medium`,children:[(0,R.jsx)(`span`,{className:`text-accent-highlight`,children:r(`builder.branch.continue`)}),(0,R.jsx)(`span`,{className:`text-accent-success`,children:r(`builder.branch.stop`)})]}),(0,R.jsx)(F,{id:`continue`,type:`source`,position:I.Bottom,style:{left:`30%`},className:`!bg-accent-highlight`}),(0,R.jsx)(F,{id:`stop`,type:`source`,position:I.Bottom,style:{left:`70%`},className:`!bg-accent-success`})]}):i===`end`?null:(0,R.jsx)(F,{type:`source`,position:I.Bottom})]})}function bt({loopId:e,onExit:t,onWindowOpened:n}){let{t:o}=a(`loops`),u=i(),{id:d}=r(),h=e??d,g=(0,L.useCallback)(()=>{t?t():u(`/loops`)},[t,u]),_=we(),{fitView:y,screenToFlowPosition:re}=ke(),{activeProjectId:w}=c(),[T,ce]=(0,L.useState)([]),[E,fe]=(0,L.useState)({}),[he,ge]=(0,L.useState)(!1),[D,_e]=(0,L.useState)({}),[ve,O]=(0,L.useState)([]),[A,j]=(0,L.useState)(null),[M,be]=(0,L.useState)(null);(0,L.useEffect)(()=>{let e=!1;return k.catalog().then(t=>{e||(ce(t.nodeKinds),fe(t.definitionSchema??{}),ge(!1))}).catch(()=>{e||ge(!0)}),()=>{e=!0}},[]),(0,L.useEffect)(()=>{let e=new AbortController;_e({});let t=t=>fetch(t,{signal:e.signal}).then(e=>e.ok?e.json():null).catch(()=>null);return Promise.all([w&&A&&!A.config.agents?t(`${s()}/agent-runtime/config`):Promise.resolve(null),t(`/api/runtime-providers`)]).then(([t,n])=>{e.signal.aborted||_e({providers:(t?.config?.providers??n?.providers??[]).map(e=>e.id),roles:[...new Set([...Object.keys(t?.config?.agents??{}),...Object.keys(t?.config?.roles??{}),...Object.keys(t?.workflowRoleDefaults??{})])],models:Object.fromEntries(Object.entries(n?.status??{}).map(([e,t])=>[e,t.models??[]]))})}),()=>e.abort()},[w,!!A,!!A?.config.agents]);let[N,P,Te]=Oe([]),[F,I,Fe]=Le([]),[z,Ve]=(0,L.useState)(``),[He,Ue]=(0,L.useState)(!1),[We,B]=(0,L.useState)(!1),[Ge,V]=(0,L.useState)(10),[H,U]=(0,L.useState)(30),[Xe,W]=(0,L.useState)(null),[G,K]=(0,L.useState)(null),[q,J]=(0,L.useState)(!1);(0,L.useEffect)(()=>J(!1),[h]);let[Qe,tt]=(0,L.useState)(!0),[nt,ot]=(0,L.useState)(!1),[ut,dt]=(0,L.useState)(!1),[vt,bt]=(0,L.useState)(null),[xt,St]=(0,L.useState)(!1),X=(0,L.useMemo)(()=>[...ft(N,F),...ve.map(e=>({severity:`error`,code:`CORE_VALIDATION`,nodeId:e.nodeId,message:e.message}))],[N,F,ve]),Ct=(0,L.useMemo)(()=>pt(X),[X]),wt=X.filter(e=>e.severity===`error`).length,[Ot,kt]=(0,L.useState)(`manual`),At=(0,L.useRef)(new Map),[jt,Mt]=(0,L.useState)([]),[Nt,Pt]=(0,L.useState)(!1),Ft=(0,L.useCallback)(async()=>{try{Mt(await k.loopConstants())}catch{}},[]);(0,L.useEffect)(()=>{Ft()},[Ft]);let It=(0,L.useMemo)(()=>({loop:yt}),[]),Lt=(0,L.useCallback)(e=>{j(e.graph),be(null);let{nodes:t,edges:n}=it(e.graph);At.current=new Map(t.map(e=>[e.id,{...e.position}]));let r=e.graph.config?.layout,i=r===`vertical`||r===`horizontal`||r===`grid`?r:`manual`;kt(i),P(i===`manual`?t:Ie(t,n,i)),I(n),Ve(e.name),V(e.graph.config?.maxIterations??10),U(e.graph.config?.timeoutMinutes??30),W(typeof e.graph.config?.maxCostUsd==`number`?e.graph.config.maxCostUsd:null),Ue(!!e.builtinId)},[P,I]);(0,L.useEffect)(()=>{if(!h)return;let e=!1;return k.get(h).then(t=>{e||Lt(t)}).catch(()=>l.error(o(`errors.load`))).finally(()=>{e||tt(!1)}),()=>{e=!0}},[h,Lt,o]);let Rt=(0,L.useCallback)(async()=>{if(h){B(!1);try{Lt(await k.restoreBuiltin(h)),O([]),l.success(o(`builder.builtin.restored`))}catch(e){l.error(e instanceof Error&&e.message?e.message:o(`errors.save`))}}},[h,Lt,o]),zt=(0,L.useCallback)(e=>{if(O([]),N.find(t=>t.id===e.source)?.data.kind===`core`){I(t=>De({...e,label:e.sourceHandle,data:{label:e.sourceHandle}},t));return}let t=e.sourceHandle===`continue`||e.sourceHandle===`stop`?e.sourceHandle:void 0,n=t?{...e,data:{branch:t},style:{stroke:t===`stop`?`var(--color-accent-success)`:`var(--color-accent-highlight)`}}:e;I(e=>De(n,e))},[I,N]),Bt=(0,L.useCallback)(e=>{if(!e.source||!e.target)return!1;let t=N.find(t=>t.id===e.source)?.data.kind,n=N.find(t=>t.id===e.target)?.data.kind;if(!t||!n||e.source===e.target&&t!==`core`||t===`end`)return!1;if(t===`core`){let t=N.find(t=>t.id===e.source),n=qe(T.find(e=>e.kind===t.data.coreKind),t.data.params??{},A?.components);if(!e.sourceHandle||!n.includes(e.sourceHandle)||F.some(t=>t.source===e.source&&t.sourceHandle===e.sourceHandle))return!1}return!(t===`start`&&F.some(t=>t.source===e.source)||n===`start`)},[N,F,T,A]),Vt=(0,L.useCallback)(e=>{kt(e==="default"?`manual`:e),P(t=>e==="default"?t.map(e=>{let t=At.current.get(e.id);return t?{...e,position:{...t}}:e}):Ie(t,F,e)),requestAnimationFrame(()=>y({padding:.25,maxZoom:.85,duration:300}))},[P,F,y]),Ht=(0,L.useCallback)(e=>{e.some(e=>e.type===`position`&&e.dragging===!1)&&kt(`manual`),Te(e)},[Te]),Ut=(0,L.useRef)(N);Ut.current=N;let Wt=(0,L.useRef)(F);Wt.current=F,(0,L.useEffect)(()=>{let e=()=>{let e=window.document.activeElement;return!!e&&(e.tagName===`INPUT`||e.tagName===`TEXTAREA`||e.isContentEditable)},t=t=>{if(e())return;let n=st(Ut.current,Wt.current);!n||!t.clipboardData||(t.clipboardData.setData(`text/plain`,JSON.stringify(n)),t.preventDefault())},n=t=>{if(e())return;let n=ct(t.clipboardData?.getData(`text/plain`)??``);if(!n)return;t.preventDefault();let r=lt(n,{mintId:Y,offset:{x:40,y:40},excludeKinds:Ut.current.some(e=>e.data.kind===`start`)?[`start`]:[]});r.nodes.length!==0&&(P(e=>[...e.map(e=>({...e,selected:!1})),...r.nodes]),I(e=>[...e,...r.edges]),kt(`manual`),l.success(o(`builder.paste.done`,{count:r.nodes.length})))};return window.addEventListener(`copy`,t),window.addEventListener(`paste`,n),()=>{window.removeEventListener(`copy`,t),window.removeEventListener(`paste`,n)}},[P,I,o]);let Gt=(0,L.useCallback)(e=>{let t=rt(e,{x:120+Math.random()*120,y:80+Math.random()*240});P(e=>[...e,t]),J(!1),K(t.id)},[P]),Kt=(0,L.useCallback)(e=>{O([]),P(t=>t.map(t=>t.id===G?{...t,data:{...t.data,...e}}:t))},[G,P]),qt=(0,L.useCallback)(()=>{G&&(P(e=>e.filter(e=>e.id!==G)),I(e=>e.filter(e=>e.source!==G&&e.target!==G)),K(null))},[G,P,I]),Z=!!A&&!N.some(e=>![`start`,`core`,`end`].includes(e.data.kind)),Q=(0,L.useCallback)(()=>{let e={...A?.config,maxIterations:Ge,timeoutMinutes:H,maxCostUsd:Xe??void 0,layout:Ot},t=M?A?.components?.[M]:A,n={...t,...at(N,F,M?t?.config??e:e)};return M?{...A,config:e,components:{...A?.components,[M]:n}}:{...n,components:A?.components}},[A,M,N,F,Ge,H,Xe,Ot]),Jt=(0,L.useCallback)((e,t=!1)=>{let n=Q();e&&t&&!n.components?.[e]&&(n.components={...n.components,[e]:{nodes:[{id:Y(),type:`start`,position:{x:160,y:40}},{id:Y(),type:`core`,position:{x:160,y:220},data:{kind:`end`,params:{outcome:`success`}}}],edges:[],config:{maxIterations:10,timeoutMinutes:0},inputs:[],outputs:[`next`,`failed`]}});let r=e?n.components?.[e]:n;if(!r)return;let i=it(r);j(n),be(e),P(i.nodes),I(i.edges),K(null),O([]),requestAnimationFrame(()=>y({padding:.25}))},[Q,P,I,y]),Yt=(0,L.useCallback)((e,t)=>{let n={id:Y(),type:`loop`,position:t??{x:160+N.length*20,y:100+N.length*30},data:Ke(e)};if(e.kind===`role-turn`&&A){let e=D.providers?.[0]??`claude`,t=(`agent-`+n.id.replace(/[^a-z0-9-]/g,`-`)).slice(0,64),r=A.config.agents??{schemaVersion:1,agents:{architect:{provider:e},developer:{provider:e},reviewer:{provider:e}}};n.data.params={roleId:t,prompt:o(`builder.core.agentTaskDefault`)},j({...A,config:{...A.config,agents:{...r,roles:{...r.roles,[t]:{provider:e,access:`write`,artifacts:`none`,prompt:``}}}}})}e.kind===`prompt`&&D.providers?.length&&(n.data.params.engine={provider:D.providers[0]}),P(e=>[...e,n]),J(!1),K(n.id)},[N.length,P,D.providers,A,o]),Xt=(0,L.useCallback)(async()=>{St(!0);try{let e=Q(),{steps:t}=await k.previewLoop(e);bt(t)}catch{l.error(o(`builder.preview.error`))}finally{St(!1)}},[Q,o]),Zt=(0,L.useCallback)(async()=>{if(!h)return!1;ot(!0);try{let e=Q();return await k.update(h,{name:z,graph:e}),!0}catch(e){return l.error(e instanceof Error&&e.message?e.message:o(`errors.save`)),!1}finally{ot(!1)}},[h,Q,z,o]),Qt=(0,L.useCallback)(async()=>{if(h&&await Zt())try{await k.publish(h),l.success(o(`builder.published`)),g()}catch(e){e instanceof Ce?(O(e.errors),dt(!0),l.error(o(`errors.publishInvalid`))):l.error(e instanceof Error&&e.message?e.message:o(`errors.save`))}},[h,Zt,g,o]),$=N.find(e=>e.id===G)??null;return(0,R.jsx)(mt.Provider,{value:Ct,children:(0,R.jsx)(ht.Provider,{value:{pieces:T,components:A?.components},children:(0,R.jsxs)(`div`,{className:`h-full flex flex-col`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-4 h-12 border-b border-border flex-shrink-0`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,R.jsx)(`button`,{type:`button`,onClick:g,className:`text-muted-foreground hover:text-foreground`,"aria-label":o(`builder.back`),children:(0,R.jsx)(f,{className:`w-4 h-4`})}),(0,R.jsx)(`input`,{value:z,onChange:e=>Ve(e.target.value),className:`text-sm font-semibold bg-transparent text-foreground border-b border-transparent focus:border-border focus:outline-none min-w-0`,"aria-label":`name`})]}),(0,R.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,R.jsxs)(le,{delayDuration:150,children:[(0,R.jsxs)(`label`,{className:`text-[10px] text-muted-foreground flex items-center gap-1`,children:[o(`builder.config.maxIterations`),(0,R.jsxs)(ue,{children:[(0,R.jsx)(me,{asChild:!0,children:(0,R.jsx)(`button`,{type:`button`,onClick:e=>e.preventDefault(),className:`text-muted-foreground/60 hover:text-foreground`,"aria-label":o(`builder.config.maxIterations`),children:(0,R.jsx)(de,{className:`w-3 h-3`})})}),(0,R.jsx)(xe,{className:`max-w-xs leading-relaxed`,children:o(`builder.config.maxIterationsHint`)})]}),(0,R.jsx)(`input`,{type:`number`,min:1,value:Ge,onChange:e=>V(Math.max(1,Number(e.target.value)||1)),className:`w-14 h-6 text-xs rounded border border-border bg-transparent px-1 text-foreground`})]}),(0,R.jsxs)(`label`,{className:`text-[10px] text-muted-foreground flex items-center gap-1`,children:[o(`builder.config.timeout`),(0,R.jsxs)(ue,{children:[(0,R.jsx)(me,{asChild:!0,children:(0,R.jsx)(`button`,{type:`button`,onClick:e=>e.preventDefault(),className:`text-muted-foreground/60 hover:text-foreground`,"aria-label":o(`builder.config.timeout`),children:(0,R.jsx)(de,{className:`w-3 h-3`})})}),(0,R.jsx)(xe,{className:`max-w-xs leading-relaxed`,children:o(`builder.config.timeoutHint`)})]}),(0,R.jsx)(`input`,{type:`number`,min:0,"aria-label":o(`builder.config.timeout`),value:H,onChange:e=>U(Math.max(0,Number(e.target.value)||0)),className:`w-14 h-6 text-xs rounded border border-border bg-transparent px-1 text-foreground`})]}),(0,R.jsxs)(`label`,{className:`text-[10px] text-muted-foreground flex items-center gap-1`,children:[o(`builder.config.maxCost`),(0,R.jsxs)(ue,{children:[(0,R.jsx)(me,{asChild:!0,children:(0,R.jsx)(`button`,{type:`button`,onClick:e=>e.preventDefault(),className:`text-muted-foreground/60 hover:text-foreground`,"aria-label":o(`builder.config.maxCost`),children:(0,R.jsx)(de,{className:`w-3 h-3`})})}),(0,R.jsx)(xe,{className:`max-w-xs leading-relaxed`,children:o(`builder.config.maxCostHint`)})]}),(0,R.jsx)(`input`,{type:`number`,min:0,step:.5,placeholder:`∞`,value:Xe??``,onChange:e=>{let t=Number(e.target.value);W(e.target.value===``||!(t>0)?null:t)},className:`w-16 h-6 text-xs rounded border border-border bg-transparent px-1 text-foreground`})]})]}),Z&&(0,R.jsx)(`button`,{type:`button`,"aria-pressed":q,onClick:()=>J(e=>!e),className:`inline-flex items-center gap-1.5 h-7 px-2.5 rounded-md text-xs border border-border hover:bg-muted text-foreground`,children:o(`builder.loopSettings`)}),He&&(0,R.jsxs)(`button`,{type:`button`,onClick:()=>B(!0),disabled:nt,"data-testid":`builder-restore-builtin`,className:`inline-flex items-center gap-1.5 h-7 px-2.5 rounded-md text-xs border border-border hover:bg-muted text-foreground disabled:opacity-50`,children:[(0,R.jsx)(ee,{className:`w-3 h-3`}),` `,o(`actions.restoreBuiltin`)]}),(0,R.jsxs)(`button`,{type:`button`,onClick:()=>void Xt(),disabled:xt,className:`inline-flex items-center gap-1.5 h-7 px-2.5 rounded-md text-xs border border-border hover:bg-muted text-foreground disabled:opacity-50`,children:[(0,R.jsx)(pe,{className:`w-3 h-3`}),` `,o(`builder.preview.label`)]}),!Se()&&(0,R.jsxs)(`button`,{type:`button`,disabled:nt,onClick:()=>void Zt().then(async e=>{if(!(!e||!h))try{await ye(w,h),n?n():g()}catch(e){l.error(String(e))}}),className:`inline-flex items-center gap-1.5 h-7 px-2.5 rounded-md text-xs border border-border hover:bg-muted disabled:opacity-50`,children:[(0,R.jsx)(m,{className:`w-3 h-3`}),o(`window.open`)]}),(0,R.jsxs)(`button`,{type:`button`,onClick:()=>void Zt().then(e=>e&&l.success(o(`builder.saved`))),disabled:nt,className:`inline-flex items-center gap-1.5 h-7 px-2.5 rounded-md text-xs border border-border hover:bg-muted text-foreground disabled:opacity-50`,children:[(0,R.jsx)(p,{className:`w-3 h-3`}),` `,o(`builder.save`)]}),(0,R.jsxs)(`button`,{type:`button`,onClick:()=>void Qt(),disabled:nt,className:`inline-flex items-center gap-1.5 h-7 px-2.5 rounded-md text-xs bg-accent-primary text-white hover:bg-accent-primary/90 disabled:opacity-50`,children:[(0,R.jsx)(ne,{className:`w-3 h-3`}),` `,o(`builder.publish`)]})]})]}),He&&(0,R.jsx)(`div`,{role:`note`,"data-testid":`builder-builtin-note`,className:`px-4 py-1.5 border-b border-border bg-accent-info/10 text-[11px] text-accent-info flex-shrink-0`,children:o(`builder.builtin.note`)}),(0,R.jsx)(se,{open:We,onOpenChange:e=>{e||B(!1)},children:(0,R.jsxs)(x,{className:`max-w-sm`,children:[(0,R.jsxs)(b,{children:[(0,R.jsx)(oe,{children:o(`builder.builtin.confirmTitle`)}),(0,R.jsx)(ae,{children:o(`builder.builtin.confirmBody`)})]}),(0,R.jsxs)(ie,{children:[(0,R.jsx)(C,{variant:`ghost`,onClick:()=>B(!1),children:o(`common:actions.cancel`)}),(0,R.jsx)(C,{"data-testid":`builder-restore-confirm`,onClick:()=>void Rt(),children:o(`actions.restoreBuiltin`)})]})]})}),(0,R.jsxs)(`div`,{className:`flex-1 flex min-h-0`,children:[(0,R.jsxs)(`div`,{className:`w-44 border-r border-border p-2 space-y-1 flex-shrink-0 overflow-y-auto`,children:[(0,R.jsx)(`p`,{className:`text-[10px] font-semibold uppercase tracking-wide text-muted-foreground px-1 mb-1`,children:o(`builder.addNode`)}),Z&&he&&(0,R.jsx)(`p`,{role:`status`,className:`text-xs text-muted-foreground px-1`,children:o(`builder.core.unavailable`)}),Z&&T.length>0&&[`ai`,`verification`,`openspec`,`control`].map(e=>(0,R.jsxs)(`div`,{className:`pt-2`,children:[(0,R.jsx)(`p`,{className:`text-[10px] uppercase text-muted-foreground px-1`,children:o(`builder.core.groups.${e}`)}),T.filter(t=>![`implementation`,`implementation-step`].includes(t.kind)&&Je(t.kind)===e).map(e=>(0,R.jsxs)(`button`,{type:`button`,draggable:!0,onDragStart:t=>{t.dataTransfer.setData(`application/specrails-core-piece`,e.kind),t.dataTransfer.effectAllowed=`copy`},onClick:()=>Yt(e),className:`flex items-center gap-2 w-full min-h-8 px-2 rounded text-left text-xs hover:bg-muted focus-visible:ring-2 focus-visible:ring-accent-primary`,children:[(0,R.jsx)(v,{className:`h-3 w-3 flex-shrink-0`}),o(`builder.core.pieces.${e.kind}`)]},e.kind))]},e)),(Z?[`start`]:gt).map(e=>{let t=_t[e];return(0,R.jsxs)(`button`,{type:`button`,onClick:()=>Gt(e),disabled:e===`start`&&N.some(e=>e.data.kind===`start`),className:`flex items-center gap-2 w-full h-8 px-2 rounded-md text-xs text-muted-foreground hover:text-foreground hover:bg-muted/50`,children:[(0,R.jsx)(t,{className:`w-3.5 h-3.5 flex-shrink-0`}),(0,R.jsx)(`span`,{className:`truncate`,children:o(`builder.nodes.${e}`)}),(0,R.jsx)(v,{className:`w-3 h-3 ml-auto opacity-50`})]},e)})]}),(0,R.jsx)(`div`,{className:`flex-1 min-w-0 relative`,onDragOver:e=>{e.dataTransfer.types.includes(`application/specrails-core-piece`)&&(e.preventDefault(),e.dataTransfer.dropEffect=`copy`)},onDrop:e=>{let t=T.find(t=>t.kind===e.dataTransfer.getData(`application/specrails-core-piece`));!t||!Z||(e.preventDefault(),Yt(t,re({x:e.clientX,y:e.clientY})))},children:Qe?(0,R.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,R.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`…`})}):(0,R.jsxs)(Ae,{nodes:N,edges:F,onNodesChange:Ht,onEdgesChange:Fe,onConnect:zt,isValidConnection:Bt,onNodeClick:(e,t)=>{J(!1),K(t.id)},onPaneClick:()=>{J(!1),K(null)},nodeTypes:It,colorMode:_.scheme===`dark`?`dark`:`light`,fitView:!0,fitViewOptions:{padding:.25,maxZoom:.85},minZoom:.2,defaultEdgeOptions:{type:`smoothstep`,markerEnd:{type:Ne.ArrowClosed,width:16,height:16}},proOptions:{hideAttribution:!0},children:[Z&&(0,R.jsx)(Me,{position:`top-center`,children:(0,R.jsxs)(`nav`,{className:`flex items-center gap-1 rounded border border-border bg-card/95 p-1 text-xs`,"aria-label":o(`builder.core.breadcrumbs`),children:[(0,R.jsx)(`button`,{type:`button`,onClick:()=>Jt(null),className:`px-2 py-1 hover:bg-muted`,children:z||o(`builder.core.root`)}),M&&(0,R.jsxs)(`span`,{"aria-current":`page`,children:[`/ `,M]})]})}),(0,R.jsx)(je,{}),(0,R.jsx)(Pe,{}),(0,R.jsx)(Ee,{pannable:!0,zoomable:!0}),(0,R.jsx)(Me,{position:`top-left`,children:(0,R.jsx)(`div`,{className:`flex items-center gap-0.5 rounded-md border border-border bg-card/90 backdrop-blur p-0.5`,role:`group`,"aria-label":o(`builder.arrange.label`),children:[[`vertical`,Be],[`horizontal`,ze],[`grid`,Re],[`default`,ee]].map(([e,t])=>{let n=e==="default"?`reset`:e,r=e==="default"?Ot===`manual`:Ot===e;return(0,R.jsx)(`button`,{type:`button`,title:o(`builder.arrange.${n}`),"aria-label":o(`builder.arrange.${n}`),"aria-pressed":r,onClick:()=>Vt(e),className:S(`inline-flex items-center justify-center w-7 h-7 rounded hover:bg-muted`,r?`bg-muted text-accent-primary`:`text-muted-foreground hover:text-foreground`),children:(0,R.jsx)(t,{className:`w-3.5 h-3.5`})},e)})})}),(0,R.jsx)(Me,{position:`top-right`,children:(0,R.jsx)(le,{delayDuration:150,children:(0,R.jsxs)(ue,{children:[(0,R.jsx)(me,{asChild:!0,children:(0,R.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 h-6 px-2 rounded-md text-[10px] border border-border bg-card/90 text-muted-foreground hover:text-foreground backdrop-blur`,children:[(0,R.jsx)(de,{className:`w-3 h-3`}),o(`builder.edgesHelp.label`)]})}),(0,R.jsx)(xe,{className:`max-w-xs leading-relaxed`,children:o(`builder.edgesHelp.body`)})]})})}),X.length>0&&(0,R.jsx)(Me,{position:`bottom-center`,children:(0,R.jsxs)(`div`,{className:`rounded-md border border-border bg-card/95 backdrop-blur text-xs overflow-hidden max-w-md mb-2`,children:[(0,R.jsxs)(`button`,{type:`button`,onClick:()=>dt(e=>!e),className:S(`flex items-center gap-1.5 w-full px-2.5 py-1.5 font-medium`,wt>0?`text-destructive`:`text-accent-warning`),children:[(0,R.jsx)(te,{className:`w-3.5 h-3.5`}),o(`builder.problems.count`,{count:X.length})]}),ut&&(0,R.jsx)(`ul`,{className:`border-t border-border max-h-40 overflow-y-auto py-1`,children:X.map((e,t)=>(0,R.jsx)(`li`,{children:(0,R.jsxs)(`button`,{type:`button`,disabled:!e.nodeId,onClick:()=>{e.nodeId&&(J(!1),K(e.nodeId))},className:`flex items-start gap-1.5 w-full text-left px-2.5 py-1 hover:bg-muted disabled:cursor-default`,children:[(0,R.jsx)(`span`,{className:S(`mt-1 w-1.5 h-1.5 rounded-full flex-shrink-0`,e.severity===`error`?`bg-destructive`:`bg-accent-warning`)}),(0,R.jsx)(`span`,{className:`text-foreground`,children:`message`in e?String(e.message):o(`builder.problems.${e.code}`)})]})},`${e.code}-${e.nodeId??t}`))})]})})]})}),(0,R.jsxs)(`div`,{className:`w-80 border-l border-border p-3 flex-shrink-0 overflow-y-auto space-y-4`,children:[!q&&($?$.data.kind===`core`?(0,R.jsx)(et,{nodeId:$.id,data:$.data,piece:T.find(e=>e.kind===$.data.coreKind),choices:{...D,roles:A?.config.agents?[...Object.keys(A.config.agents.agents),...Object.keys(A.config.agents.roles??{})]:D.roles,components:Object.keys(A?.components??{})},schema:E,onChange:Kt,onDelete:qt,onOpenCanvas:Jt}):(0,R.jsx)(Dt,{data:$.data,onChange:Kt,onDelete:qt,constants:jt,onManageConstants:()=>Pt(!0)}):(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o(`builder.inspector.selectNode`)})),!q&&Z&&A&&$&&(Ye($.id,$.data.coreKind,$.data.params??{}).length>0||$.data.coreKind===`implementation-step`&&$.data.params?.phase===`archive`)&&(0,R.jsx)(Ze,{mode:$.data.coreKind===`implementation`?`all`:`step`,graph:Q(),value:A.config.agents,selectedRole:String($.data.params?.phase??Ye($.id,$.data.coreKind,$.data.params??{})[0]??``),onChange:e=>j({...A,config:{...A.config,agents:e}})},`${h}:${$.id}`),q&&Z&&A&&(0,R.jsx)(Ze,{mode:`workflow`,graph:Q(),value:A.config.agents,selectedRole:$?Ye($.id,$.data.coreKind,$.data.params??{})[0]:void 0,onChange:e=>j({...A,config:{...A.config,agents:e}})},h),q&&Z&&A&&(0,R.jsx)($e,{graph:A,canvas:M,schema:E,onChange:j,onOpenCanvas:Jt})]})]}),(0,R.jsx)(Tt,{open:Nt,onClose:()=>Pt(!1),constants:jt,onChanged:Ft,t:o}),(0,R.jsx)(Et,{steps:vt,onClose:()=>bt(null),t:o})]})})})}var xt=[{labelKey:`builder.inspector.tokensSpec`,tokens:[{token:`{{spec.title}}`,label:`spec.title`},{token:`{{spec.description}}`,label:`spec.description`},{token:`{{spec.id}}`,label:`spec.id`},{token:`{{spec.status}}`,label:`spec.status`},{token:`{{spec.priority}}`,label:`spec.priority`},{token:`{{spec.labels}}`,label:`spec.labels`}]},{labelKey:`builder.inspector.tokensJira`,tokens:[{token:`{{spec.jira_key}}`,label:`spec.jira_key`},{token:`{{spec.jira_url}}`,label:`spec.jira_url`}]}];function St({token:e,label:t,description:n,onInsert:r}){return(0,R.jsx)(`button`,{type:`button`,draggable:!0,onDragStart:t=>t.dataTransfer.setData(`text/plain`,e),onClick:()=>r(e),title:n?`${e} — ${n}`:e,className:`px-1.5 py-0.5 rounded border border-border bg-surface/40 text-[10px] font-mono text-accent-primary hover:bg-accent-primary/10 cursor-grab active:cursor-grabbing`,children:t})}function X({t:e,onInsert:t}){let[n,r]=(0,L.useState)([]);return(0,L.useEffect)(()=>{let e=!1;return k.loopCommands().then(t=>{e||r(t)}).catch(()=>{}),()=>{e=!0}},[]),(0,R.jsxs)(`div`,{className:`mb-2 space-y-1.5`,children:[xt.map(n=>(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`span`,{className:`block text-[9px] uppercase tracking-wide text-muted-foreground/70 mb-0.5`,children:e(n.labelKey)}),(0,R.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:n.tokens.map(e=>(0,R.jsx)(St,{token:e.token,label:e.label,onInsert:t},e.token))})]},n.labelKey)),n.length>0&&(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`span`,{className:`block text-[9px] uppercase tracking-wide text-muted-foreground/70 mb-0.5`,children:e(`builder.inspector.tokensCommands`)}),(0,R.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:n.map(e=>(0,R.jsx)(St,{token:`{{cmd:${e.name}}}`,label:`⚡ ${e.label}`,description:e.description,onInsert:t},e.name))})]})]})}function Ct({t:e,constants:t,onInsert:n,onManage:r}){return(0,R.jsxs)(`div`,{className:`mb-2`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between mb-0.5`,children:[(0,R.jsx)(`span`,{className:`text-[9px] uppercase tracking-wide text-muted-foreground/70`,children:e(`builder.constants.label`)}),(0,R.jsx)(`button`,{type:`button`,onClick:r,title:e(`builder.constants.manage`),"aria-label":e(`builder.constants.manage`),className:`text-muted-foreground hover:text-foreground`,children:(0,R.jsx)(P,{className:`w-3 h-3`})})]}),(0,R.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:t.map(e=>(0,R.jsx)(St,{token:`{{const:${e.name}}}`,label:e.builtin?`🔒 ${e.name}`:e.name,description:e.value,onInsert:n},e.id))})]})}function wt({c:e,onSave:t,onDelete:n}){let[r,i]=(0,L.useState)(e.value);return(0,R.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,R.jsx)(`code`,{className:`text-[10px] font-mono text-accent-primary w-28 truncate`,title:e.name,children:e.name}),(0,R.jsx)(`input`,{className:`flex-1 text-xs rounded border border-border bg-transparent px-2 py-1 text-foreground`,value:r,onChange:e=>i(e.target.value)}),(0,R.jsx)(`button`,{type:`button`,disabled:r===e.value||!r,onClick:()=>t(r),className:`text-muted-foreground hover:text-foreground disabled:opacity-40`,"aria-label":`save`,children:(0,R.jsx)(p,{className:`w-3.5 h-3.5`})}),(0,R.jsx)(`button`,{type:`button`,onClick:n,className:`text-muted-foreground hover:text-destructive`,"aria-label":`delete`,children:(0,R.jsx)(y,{className:`w-3.5 h-3.5`})})]})}function Tt({open:e,onClose:t,constants:n,onChanged:r,t:i}){let[a,o]=(0,L.useState)(``),[s,c]=(0,L.useState)(``),[l,u]=(0,L.useState)(null),[d,f]=(0,L.useState)(!1),p=n.filter(e=>e.builtin),m=n.filter(e=>!e.builtin),h=async()=>{f(!0),u(null);try{await k.createConstant(a.trim(),s),o(``),c(``),await r()}catch(e){u(e instanceof Error?e.message:`error`)}finally{f(!1)}},g=`text-xs rounded border border-border bg-transparent px-2 py-1 text-foreground focus:outline-none focus:ring-1 focus:ring-accent-primary/40`;return(0,R.jsx)(se,{open:e,onOpenChange:e=>{e||t()},children:(0,R.jsxs)(x,{className:`max-w-md`,children:[(0,R.jsx)(b,{children:(0,R.jsx)(oe,{children:i(`builder.constants.title`)})}),(0,R.jsxs)(`div`,{className:`space-y-3`,children:[(0,R.jsxs)(`div`,{className:`space-y-1.5`,children:[m.length===0&&(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i(`builder.constants.empty`)}),m.map(e=>(0,R.jsx)(wt,{c:e,onSave:t=>void k.updateConstant(e.id,t).then(r),onDelete:()=>void k.deleteConstant(e.id).then(r)},e.id))]}),(0,R.jsxs)(`div`,{className:`flex items-center gap-1.5 border-t border-border pt-2`,children:[(0,R.jsx)(`input`,{className:`${g} w-28`,placeholder:i(`builder.constants.name`),value:a,onChange:e=>o(e.target.value)}),(0,R.jsx)(`input`,{className:`${g} flex-1`,placeholder:i(`builder.constants.value`),value:s,onChange:e=>c(e.target.value)}),(0,R.jsx)(C,{size:`sm`,disabled:d||!a.trim()||!s,onClick:()=>void h(),children:i(`builder.constants.add`)})]}),l&&(0,R.jsx)(`p`,{className:`text-[10px] text-destructive`,children:l}),p.length>0&&(0,R.jsxs)(`div`,{className:`border-t border-border pt-2 space-y-1`,children:[(0,R.jsx)(`span`,{className:`text-[9px] uppercase tracking-wide text-muted-foreground/70`,children:i(`builder.constants.builtinBadge`)}),p.map(e=>(0,R.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px]`,children:[(0,R.jsx)(`code`,{className:`font-mono text-accent-primary w-28 truncate`,title:e.name,children:e.name}),(0,R.jsx)(`span`,{className:`text-muted-foreground truncate`,children:e.value})]},e.id))]})]}),(0,R.jsx)(ie,{children:(0,R.jsx)(C,{variant:`ghost`,onClick:t,children:i(`common:actions.close`)})})]})})}function Et({steps:e,onClose:t,t:n}){return(0,R.jsx)(se,{open:e!==null,onOpenChange:e=>{e||t()},children:(0,R.jsxs)(x,{className:`max-w-2xl`,children:[(0,R.jsx)(b,{children:(0,R.jsx)(oe,{children:n(`builder.preview.title`)})}),(0,R.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:n(`builder.preview.sampleNote`)}),(0,R.jsxs)(`div`,{className:`space-y-2 max-h-[60vh] overflow-y-auto`,children:[e&&e.length===0&&(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`builder.preview.empty`)}),e?.map((e,t)=>(0,R.jsxs)(`div`,{className:`rounded-md border border-border`,children:[(0,R.jsxs)(`div`,{className:`px-2.5 py-1 text-[10px] border-b border-border flex items-center gap-1.5`,children:[(0,R.jsx)(`span`,{className:`font-medium text-foreground`,children:e.label||n([`start`,`end`,`ai-step`,`shell`,`decider`,`condition`].includes(e.kind)?`builder.nodes.${e.kind}`:`builder.core.pieces.${e.kind}`)}),(0,R.jsxs)(`span`,{className:`text-muted-foreground`,children:[`· `,n([`start`,`end`,`ai-step`,`shell`,`decider`,`condition`].includes(e.kind)?`builder.nodes.${e.kind}`:`builder.core.pieces.${e.kind}`)]})]}),(0,R.jsx)(`pre`,{className:`px-2.5 py-2 text-[11px] text-foreground whitespace-pre-wrap break-words font-mono`,children:e.text||`—`})]},`${e.nodeId}-${t}`))]}),(0,R.jsx)(ie,{children:(0,R.jsx)(C,{variant:`ghost`,onClick:t,children:n(`common:actions.close`)})})]})})}function Dt({data:e,onChange:t,onDelete:n,constants:r,onManageConstants:i}){let{t:o}=a(`loops`),{activeProjectId:s,projects:l}=c(),u=T(l.find(e=>e.id===s)),d=e.kind,f=`block text-[10px] font-medium text-muted-foreground mb-1`,p=`w-full text-xs rounded border border-border bg-transparent px-2 py-1 text-foreground focus:outline-none focus:ring-1 focus:ring-accent-primary/40`,m=(0,L.useRef)(null),h=(0,L.useRef)(null),g=(n,r,i)=>{let a=n.current,o=String(e[r]??``);if(!a){t({[r]:o+i});return}let s=a.selectionStart??o.length,c=a.selectionEnd??o.length;t({[r]:o.slice(0,s)+i+o.slice(c)}),requestAnimationFrame(()=>{a.focus();let e=s+i.length;a.setSelectionRange(e,e)})},_=e=>g(m,`prompt`,e);return(0,R.jsxs)(`div`,{className:`space-y-3`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,R.jsx)(`span`,{className:`text-xs font-semibold text-foreground`,children:o(`builder.nodes.${d}`)}),(0,R.jsx)(`button`,{type:`button`,onClick:n,"aria-label":o(`builder.deleteNode`),className:`text-muted-foreground hover:text-destructive`,children:(0,R.jsx)(y,{className:`w-3.5 h-3.5`})})]}),(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`label`,{className:f,children:o(`builder.inspector.label`)}),(0,R.jsx)(`input`,{className:p,value:String(e.label??``),onChange:e=>t({label:e.target.value}),placeholder:o(`builder.nodes.${d}`)})]}),d===`ai-step`&&(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`label`,{className:f,children:o(`builder.inspector.prompt`)}),(0,R.jsx)(X,{t:o,onInsert:_}),(0,R.jsx)(Ct,{t:o,constants:r,onInsert:_,onManage:i}),(0,R.jsx)(`textarea`,{ref:m,rows:7,className:p,value:String(e.prompt??``),onChange:e=>t({prompt:e.target.value})}),(0,R.jsx)(`p`,{className:`text-[10px] text-muted-foreground mt-1`,children:o(`builder.inspector.promptHint`)})]}),d===`shell`&&(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`label`,{className:f,children:o(`builder.inspector.command`)}),(0,R.jsx)(`input`,{className:p,value:String(e.command??``),onChange:e=>t({command:e.target.value}),placeholder:`npm test`}),(0,R.jsxs)(`label`,{className:`${f} mt-3`,children:[o(`common:repositories.shellTarget`),(0,R.jsxs)(`select`,{className:p,value:String(e.repositoryId??``),onChange:e=>t({repositoryId:e.target.value||void 0}),children:[(0,R.jsx)(`option`,{value:``,children:o(`common:repositories.shellDefault`)}),u.filter(e=>e.kind===`git`).map(e=>(0,R.jsx)(`option`,{value:e.id,children:e.name},e.id)),!!e.repositoryId&&!u.some(t=>t.id===e.repositoryId)&&(0,R.jsx)(`option`,{value:String(e.repositoryId),children:String(e.repositoryId)})]})]}),(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o(`common:repositories.shellHint`)})]}),d===`decider`&&(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`label`,{className:f,children:o(`builder.inspector.goal`)}),(0,R.jsx)(Ct,{t:o,constants:r,onInsert:e=>g(h,`goal`,e),onManage:i}),(0,R.jsx)(`textarea`,{ref:h,rows:4,className:p,value:String(e.goal??``),onChange:e=>t({goal:e.target.value})})]}),d===`condition`&&(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`label`,{className:f,children:o(`builder.inspector.join`)}),(0,R.jsxs)(`select`,{className:p,value:String(e.join??`AND`),onChange:e=>t({join:e.target.value}),children:[(0,R.jsx)(`option`,{value:`AND`,children:`AND`}),(0,R.jsx)(`option`,{value:`OR`,children:`OR`})]})]}),d===`end`&&(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`label`,{className:f,children:o(`builder.inspector.outcome`)}),(0,R.jsxs)(`select`,{className:p,value:String(e.outcome??`success`),onChange:e=>t({outcome:e.target.value}),children:[(0,R.jsx)(`option`,{value:`success`,children:`success`}),(0,R.jsx)(`option`,{value:`failure`,children:`failure`})]})]}),d===`start`&&(0,R.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:o(`builder.inspector.startNote`)})]})}function Ot({loopId:e,onExit:t,onWindowOpened:n}={}){return(0,R.jsx)(Fe,{children:(0,R.jsx)(bt,{loopId:e,onExit:t,onWindowOpened:n})})}export{Ot as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-zu2_FqZY.js";import{t as r}from"./react-dom-DiWzBDP9.js";import{u as i}from"./chunk-KS7C4IRE-DEKu087k.js";import{n as a}from"./createLucideIcon-Bjbbp_KS.js";import{t as o}from"./pencil-C9RkrIPZ.js";import{t as s}from"./square-Ci-PFcFe.js";import{t as c}from"./utils-BC4DHlz2.js";import{t as l}from"./button-D1xExSTF.js";import{Yt as u}from"./index-
|
|
1
|
+
import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-zu2_FqZY.js";import{t as r}from"./react-dom-DiWzBDP9.js";import{u as i}from"./chunk-KS7C4IRE-DEKu087k.js";import{n as a}from"./createLucideIcon-Bjbbp_KS.js";import{t as o}from"./pencil-C9RkrIPZ.js";import{t as s}from"./square-Ci-PFcFe.js";import{t as c}from"./utils-BC4DHlz2.js";import{t as l}from"./button-D1xExSTF.js";import{Yt as u}from"./index-lTGJJTuk.js";import{r as d,t as f}from"./TemplatePreviewModal-B8yd1AGU.js";var p=e(t(),1),m=e(r(),1),h=n();function g({loop:e,onClose:t}){let{t:n}=a(`loops`),r=i();return(0,p.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]),(0,m.createPortal)((0,h.jsxs)(`div`,{"data-testid":`loop-preview-modal`,className:`fixed inset-0 z-[65] flex items-center justify-center p-4`,children:[(0,h.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:t,"aria-hidden":!0}),(0,h.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-label":e.name,className:`relative flex max-h-[80vh] w-full max-w-lg flex-col gap-4 overflow-hidden rounded-xl border border-border/30 bg-popover p-6 shadow-xl backdrop-blur-md`,children:[(0,h.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-2 pr-6`,children:[(0,h.jsx)(u,{className:`h-4 w-4 shrink-0 text-accent-highlight`}),(0,h.jsx)(`span`,{className:`min-w-0 truncate text-base font-semibold text-foreground`,children:e.name}),(0,h.jsx)(`span`,{className:c(`inline-flex shrink-0 items-center gap-1 rounded-full border px-1.5 py-px text-[10px] font-medium uppercase tracking-wide`,e.builtin?`border-accent-info/40 bg-accent-info/10 text-accent-info`:e.status===`published`?`border-accent-success/40 bg-accent-success/10 text-accent-success`:`border-border/60 bg-surface/60 text-foreground/60`),children:e.builtin?n(`preview.builtin`):n(`status.${e.status??`draft`}`,{defaultValue:e.status??``})})]}),e.description&&(0,h.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e.description})]}),(0,h.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:e.graph.config.timeoutMinutes>0?n(`preview.limits`,{iterations:e.graph.config.maxIterations,timeout:e.graph.config.timeoutMinutes}):n(`preview.limitsNoTimeout`,{iterations:e.graph.config.maxIterations})}),(0,h.jsxs)(`div`,{className:`min-h-0 space-y-1.5 overflow-y-auto pr-1`,children:[(0,h.jsx)(`span`,{className:`block text-[10px] font-medium uppercase tracking-wide text-muted-foreground`,children:n(`preview.steps`)}),e.graph.nodes.map((e,t)=>{let r=f[e.type]??s,i=d(e);return(0,h.jsxs)(`div`,{className:`rounded border border-border bg-surface/30 p-2`,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs font-medium text-foreground`,children:[(0,h.jsxs)(`span`,{className:`text-[10px] tabular-nums text-muted-foreground`,children:[t+1,`.`]}),(0,h.jsx)(r,{className:`h-3.5 w-3.5 text-accent-primary`}),n(`builder.nodes.${e.type}`)]}),i&&(0,h.jsx)(`pre`,{className:`mt-1 whitespace-pre-wrap break-words font-mono text-[11px] text-muted-foreground`,children:i})]},e.id)})]}),(0,h.jsxs)(`div`,{className:`flex shrink-0 items-center justify-end gap-2`,children:[(0,h.jsx)(l,{variant:`ghost`,onClick:t,children:n(`common:actions.close`)}),!e.locked&&(0,h.jsxs)(l,{"data-testid":`loop-preview-open-builder`,onClick:()=>{t(),r(`/loops/${encodeURIComponent(e.id)}/edit`)},children:[(0,h.jsx)(o,{className:`mr-1.5 h-3.5 w-3.5`}),n(`preview.openInBuilder`)]})]})]})]}),document.body)}export{g as LoopPreviewModal};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-zu2_FqZY.js";import{r}from"./useDesktop-
|
|
1
|
+
import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-zu2_FqZY.js";import{r}from"./useDesktop-DKNbOF0u.js";import i from"./LoopsPage-ClSrWzDd.js";import a from"./LoopBuilderPage-jUp20DSZ.js";var o=e(t(),1),s=n();function c(){let{projects:e,isLoading:t,setActiveProjectId:n}=r(),[c,l]=(0,o.useState)(()=>new URLSearchParams(window.location.search).get(`loopId`)),u=(0,o.useRef)(!1),d=new URLSearchParams(window.location.search).get(`projectId`);return(0,o.useEffect)(()=>{!t&&!u.current&&(u.current=!0,n(e.some(e=>e.id===d)?d:null))},[t,d,e,n]),(0,s.jsx)(`div`,{className:`flex-1 min-h-0 bg-background`,children:c?(0,s.jsx)(a,{loopId:c,onExit:()=>l(null)},c):(0,s.jsx)(i,{onOpenBuilder:l})})}export{c as LoopWindowSurface};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-zu2_FqZY.js";import{u as r}from"./chunk-KS7C4IRE-DEKu087k.js";import{n as i,t as a}from"./createLucideIcon-Bjbbp_KS.js";import{n as o,r as s,s as c}from"./useDesktop-
|
|
1
|
+
import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-zu2_FqZY.js";import{u as r}from"./chunk-KS7C4IRE-DEKu087k.js";import{n as i,t as a}from"./createLucideIcon-Bjbbp_KS.js";import{n as o,r as s,s as c}from"./useDesktop-DKNbOF0u.js";import{_ as l,s as u,t as d,u as f}from"./provider-capabilities-lePfeT_Y.js";import{t as p}from"./download-CFHyyHcw.js";import{t as m}from"./external-link-D6XxC_Cu.js";import{t as h}from"./pencil-C9RkrIPZ.js";import{n as g}from"./square-Ci-PFcFe.js";import{t as _}from"./plus-CsnjfkmX.js";import{t as v}from"./rotate-ccw-Wh4id13q.js";import{t as y}from"./sparkles-DrY8hb0X.js";import{t as b}from"./trash-2-BOU3WdZZ.js";import{t as x}from"./upload-DYMjAQ6M.js";import{a as S,i as C,l as w,o as T,r as E,t as D}from"./dialog-CMgps2MY.js";import{t as O}from"./utils-BC4DHlz2.js";import{t as k}from"./button-D1xExSTF.js";import{t as ee}from"./RepositoryScopeSelector-CeCr6Jz-.js";import{Ht as A,Vt as j,X as M,Z as N,at as te,in as P,it as F,nt as I,ot as L,pt as R,rn as ne,rt as z}from"./index-lTGJJTuk.js";import{n as re}from"./TemplatePreviewModal-B8yd1AGU.js";var ie=a(`file-down`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M12 18v-6`,key:`17g6i2`}],[`path`,{d:`m9 15 3 3 3-3`,key:`1npd3o`}]]),ae=a(`file-up`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M12 12v6`,key:`3ahymv`}],[`path`,{d:`m15 15-3-3-3 3`,key:`15xj92`}]]),B=e(t(),1),V=n(),H=[`invalid`,`needs_attention`,`convertible`,`running`,`current`];function oe({onConvert:e}){let{t}=i(`loops`),[n,r]=(0,B.useState)(null),[a,o]=(0,B.useState)(!1),[s,c]=(0,B.useState)(``),l=(0,B.useRef)(!0);(0,B.useEffect)(()=>(l.current=!0,()=>{l.current=!1}),[]);async function u(){o(!0),c(``),r(null);try{let e=await F.migration();l.current&&r(e)}catch(e){l.current&&c(e instanceof Error&&e.message?e.message:t(`migration.failed`))}finally{l.current&&o(!1)}}let d=n?n.loops.filter(e=>e.state!==`current`):[];return(0,V.jsxs)(`section`,{className:`rounded-lg border border-border p-3 space-y-2`,"aria-label":t(`migration.title`),children:[(0,V.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`h2`,{className:`text-sm font-medium text-foreground`,children:t(`migration.title`)}),(0,V.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:t(`migration.description`)})]}),(0,V.jsx)(k,{size:`sm`,variant:`secondary`,disabled:a,onClick:()=>void u(),children:t(a?`migration.checking`:`migration.check`)})]}),s&&(0,V.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive`,children:s}),n&&(0,V.jsxs)(`div`,{role:`status`,className:`space-y-2 text-xs`,children:[(0,V.jsx)(`p`,{children:H.filter(e=>n.summary[e]>0).map(e=>t(`migration.states.${e}`)+`: `+n.summary[e]).join(` · `)||t(`migration.empty`)}),d.length===0&&n.loops.length>0&&(0,V.jsx)(`p`,{className:`text-muted-foreground`,children:t(`migration.allCurrent`)}),(0,V.jsx)(`ul`,{className:`space-y-1`,children:d.map(n=>(0,V.jsxs)(`li`,{className:`flex flex-wrap items-center gap-2`,children:[(0,V.jsx)(`span`,{className:`font-medium`,children:n.name}),(0,V.jsxs)(`span`,{className:`text-muted-foreground`,children:[t(`migration.states.${n.state}`),n.status===`published`?` · ${t(`status.published`)}`:``]}),n.issues.slice(0,3).map((e,t)=>(0,V.jsx)(`span`,{className:`text-destructive`,children:e.message},t)),n.state===`convertible`&&(0,V.jsx)(k,{size:`sm`,variant:`ghost`,onClick:()=>e(n.id),children:t(`actions.convert`)})]},n.id))})]})]})}function se(e){return{specrailsLoops:1,loops:e.map(e=>({name:e.name,description:e.description,graph:e.graph}))}}function U(e){let t=e;return!!t&&typeof t.name==`string`&&!!t.graph&&typeof t.graph==`object`}function ce(e){let t;try{t=JSON.parse(e)}catch{throw Error(`invalid-json`)}let n=(Array.isArray(t)?t:Array.isArray(t?.loops)?t.loops:U(t)?[t]:[]).filter(U);if(n.length===0)throw Error(`no-loops`);return n.map(e=>({name:e.name,description:e.description??null,graph:e.graph}))}function le(e){return e.length===1?`${e[0].name.trim().toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``)||`loop`}.loop.json`:`specrails-loops-${e.length}.json`}var W=[`API`,`Automation`,`CI`,`Database`,`Debugging`,`DevOps`,`Docs`,`Git`,`Maintenance`,`Performance`,`Planning`,`Quality`,`Review`,`Security`,`Testing`];function ue(e,t){let n=t.query.trim().toLowerCase(),r=t.categories;return e.filter(e=>r.length>0&&!(e.category&&r.includes(e.category))?!1:!n||`${e.name} ${e.description} ${e.tags.join(` `)} ${e.category??``} ${e.searchTerms??``}`.toLowerCase().includes(n))}function de(e){let t=new Map;for(let n of e)n.category&&t.set(n.category,(t.get(n.category)??0)+1);let n=[];for(let e of W){let r=t.get(e);r&&(n.push({category:e,count:r}),t.delete(e))}for(let e of[...t.keys()].sort())n.push({category:e,count:t.get(e)});return n}function fe({loop:e,projects:t,onClose:n,onExecute:r}){let{t:a}=i(`loops`),o=e!==null,[s,c]=(0,B.useState)(``),[p,m]=(0,B.useState)(``),[h,_]=(0,B.useState)(``),[v,y]=(0,B.useState)(``),[b,x]=(0,B.useState)(),O=t.find(e=>e.id===(s||t[0]?.id)),A=(0,B.useMemo)(()=>O?.providers??(O?.provider?[O.provider]:[]),[O]),j=p||A[0]||``,P=(0,B.useMemo)(()=>L(j),[j]),F=f(j),I=h&&(P.some(e=>e.value===h)||F&&N(h))?h:te(j),R=l(j,I),ne=R.includes(v)?v:d(j,I)??``,z=R.length>0;return(0,V.jsx)(D,{open:o,onOpenChange:e=>{e||n()},children:(0,V.jsx)(E,{movableResizable:!0,className:`max-w-sm`,children:e&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(T,{children:[(0,V.jsx)(w,{children:a(`run.title`,{name:e.name})}),(0,V.jsx)(C,{children:a(`run.subtitle`)})]}),(0,V.jsx)(`label`,{className:`block text-[11px] font-medium text-muted-foreground`,children:a(`run.project`)}),t.length===0?(0,V.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:a(`run.noProjects`)}):(0,V.jsx)(`select`,{"aria-label":a(`run.project`),"data-testid":`run-project-select`,value:s||t[0]?.id,onChange:e=>{c(e.target.value),m(``),_(``),y(``),x(void 0)},className:`w-full text-xs rounded border border-border bg-transparent px-2 py-1 text-foreground focus:outline-none focus:ring-1 focus:ring-accent-primary/40`,children:t.map(e=>(0,V.jsx)(`option`,{value:e.id,children:e.name},e.id))}),(0,V.jsx)(ee,{repositories:O?.repositories??[],value:b,onChange:x}),A.length>1&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`label`,{className:`block text-[11px] font-medium text-muted-foreground`,children:a(`run.provider`)}),(0,V.jsx)(`select`,{"aria-label":a(`run.provider`),value:j,onChange:e=>{m(e.target.value),_(``),y(``)},className:`w-full text-xs rounded border border-border bg-transparent px-2 py-1 text-foreground focus:outline-none focus:ring-1 focus:ring-accent-primary/40`,children:A.map(e=>(0,V.jsx)(`option`,{value:e,children:u(e)},e))})]}),P.length>0&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`label`,{className:`block text-[11px] font-medium text-muted-foreground`,children:a(`run.model`)}),F?(0,V.jsx)(M,{value:I,options:P,ariaLabel:a(`run.model`),testId:`run-model-select`,className:`w-full px-2 py-1 text-xs`,onCommit:e=>{_(e),y(d(j,e)??``)}}):(0,V.jsx)(`select`,{"aria-label":a(`run.model`),"data-testid":`run-model-select`,value:I,onChange:e=>{let t=e.target.value;_(t),y(d(j,t)??``)},className:`w-full text-xs rounded border border-border bg-transparent px-2 py-1 text-foreground focus:outline-none focus:ring-1 focus:ring-accent-primary/40`,children:P.map(e=>(0,V.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),z&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`label`,{className:`block text-[11px] font-medium text-muted-foreground`,children:a(`run.effort`)}),(0,V.jsx)(`select`,{"aria-label":a(`run.effort`),value:ne,onChange:e=>y(e.target.value),className:`w-full text-xs rounded border border-border bg-transparent px-2 py-1 text-foreground focus:outline-none focus:ring-1 focus:ring-accent-primary/40`,children:R.map(e=>(0,V.jsx)(`option`,{value:e,children:e},e))})]}),(0,V.jsxs)(S,{children:[(0,V.jsx)(k,{variant:`ghost`,onClick:n,children:a(`common:actions.cancel`)}),(0,V.jsxs)(k,{onClick:()=>{let e=s||t[0]?.id;e&&r({projectId:e,...b?{repositoryIds:b}:{},provider:A.length>1?j:void 0,model:P.length>0?I:void 0,effort:z?ne:void 0})},disabled:t.length===0,children:[(0,V.jsx)(g,{className:`w-3.5 h-3.5 mr-1.5`}),a(`run.execute`)]})]})]})})})}function pe({loop:e,projects:t,onClose:n,onConverted:r}){let{t:a}=i(`loops`),[o,s]=(0,B.useState)(``),[c,l]=(0,B.useState)(!1),[u,d]=(0,B.useState)(``),f=e.graph.nodes.some(e=>e.type===`shell`&&!e.data?.repositoryId),p=t.flatMap(e=>(e.repositories??[]).map(t=>({key:JSON.stringify([e.id,t.id]),id:t.id,label:`${e.name} / ${t.name}`}))),m=p.find(e=>e.key===o);async function h(){l(!0),d(``);try{r((await F.convert(e.id,m?.id)).loop)}catch(e){d(e instanceof z?e.errors.map(e=>`${e.nodeId?e.nodeId+`: `:``}${e.message}`).join(`
|
|
2
2
|
`):e instanceof Error&&e.message===`engine_unsupported`?a(`conversion.coreRequired`):e instanceof Error?a(`conversion.error`)+`: `+e.message:a(`conversion.error`))}finally{l(!1)}}return(0,V.jsx)(D,{open:!0,onOpenChange:e=>{!e&&!c&&n()},children:(0,V.jsxs)(E,{children:[(0,V.jsxs)(T,{children:[(0,V.jsx)(w,{children:a(`conversion.title`,{name:e.name})}),(0,V.jsx)(C,{children:a(`conversion.description`)})]}),f&&(0,V.jsxs)(`label`,{className:`flex flex-col gap-2 text-sm`,children:[a(`conversion.repository`),(0,V.jsxs)(`select`,{className:`rounded border border-border bg-background p-2`,value:o,onChange:e=>s(e.target.value),disabled:c,children:[(0,V.jsx)(`option`,{value:``,children:a(`conversion.selectRepository`)}),p.map(e=>(0,V.jsx)(`option`,{value:e.key,children:e.label},e.key))]})]}),u&&(0,V.jsx)(`p`,{role:`alert`,className:`whitespace-pre-wrap text-sm text-destructive`,children:u}),(0,V.jsxs)(S,{children:[(0,V.jsx)(k,{variant:`outline`,disabled:c,onClick:n,children:a(`common:actions.cancel`)}),(0,V.jsx)(k,{disabled:c||f&&!m,onClick:()=>void h(),children:a(c?`conversion.pending`:`conversion.submit`)})]})]})})}var G={draft:`bg-accent-secondary/15 text-accent-secondary ring-accent-secondary/40`,published:`bg-accent-success/15 text-accent-success ring-accent-success/40`};function K({status:e}){let{t}=i(`loops`);return(0,V.jsx)(`span`,{className:O(`inline-flex items-center px-1.5 py-0.5 rounded text-[10px] font-medium ring-1 ring-inset`,G[e]),children:t(`status.${e}`)})}function q({onOpenBuilder:e,onWindowOpened:t}={}){let{t:n}=i(`loops`),a=r(),l=(0,B.useCallback)(e=>e.replace(/:/g,`_`),[]),u=(0,B.useCallback)((e,t)=>n(`catalog.${l(e)}.name`,{defaultValue:t}),[n,l]),d=(0,B.useCallback)((e,t)=>n(`catalog.${l(e)}.description`,{defaultValue:t}),[n,l]),[f,h]=(0,B.useState)([]),[g,x]=(0,B.useState)([]),[ee,A]=(0,B.useState)(!0),[M,N]=(0,B.useState)(null),[te,L]=(0,B.useState)(null),[H,U]=(0,B.useState)(null),[W,G]=(0,B.useState)(null),[K,q]=(0,B.useState)(null),[J,ge]=(0,B.useState)(new Set),_e=`specrails-desktop:loop-template-filter`,ve=(()=>{try{let e=localStorage.getItem(_e),t=e?JSON.parse(e):null;return{query:typeof t?.query==`string`?t.query:``,categories:Array.isArray(t?.categories)?t.categories:[]}}catch{return{query:``,categories:[]}}})(),[Y,ye]=(0,B.useState)(ve.query),[X,be]=(0,B.useState)(ve.categories);(0,B.useEffect)(()=>{try{localStorage.setItem(_e,JSON.stringify({query:Y,categories:X}))}catch{}},[Y,X]);let xe=(0,B.useCallback)(e=>{be(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},[]),Se=(0,B.useCallback)(()=>{ye(``),be([])},[]),Ce=(0,B.useRef)(null),{projects:we,activeProjectId:Te,setActiveProjectId:Ee}=s(),De=(0,B.useCallback)(e=>{ge(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),Z=(0,B.useCallback)(e=>{if(e.length===0)return;let t=new Blob([JSON.stringify(se(e),null,2)],{type:`application/json`}),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=le(e),r.click(),URL.revokeObjectURL(n)},[]),Oe=(0,B.useCallback)(async e=>{try{let t=await F.legacyGraph(e.id);Z([{...e,name:n(`actions.originalCopyName`,{name:e.name}),graph:t.graph}])}catch{c.error(n(`errors.exportLegacy`))}},[Z,n]),Q=(0,B.useCallback)(async()=>{try{let[e,t]=await Promise.all([F.list(),F.templates()]);h(e),x(t)}catch{c.error(n(`errors.load`))}finally{A(!1)}},[n]);(0,B.useEffect)(()=>{Q()},[Q]);let ke=(0,B.useCallback)(async e=>{try{let t=ce(await e.text()),{imported:r,skipped:i}=await F.importLoops(t);await Q(),r.length&&c.success(n(`import.done`,{count:r.length})),i.length&&c.warning(n(`import.skipped`,{count:i.length,names:i.join(`, `)})),!r.length&&!i.length&&c.warning(n(`import.invalid`))}catch(e){let t=e instanceof Error?e.message:``;c.error(n(t===`invalid-json`||t===`no-loops`?`import.invalid`:`errors.save`))}},[Q,n]),$=(0,B.useCallback)(t=>{e?e(t):a(`/loops/${t}/edit`)},[e,a]),Ae=(0,B.useCallback)(async()=>{try{let e=await F.create({name:n(`newLoopName`)});$(e.id)}catch{c.error(n(`errors.save`))}},[n,$]),je=(0,B.useCallback)(async e=>{try{let t=await F.fromTemplate(e);$(t.id)}catch{c.error(n(`errors.save`))}},[n,$]),Me=(0,B.useCallback)(async({projectId:e,provider:t,model:r,effort:i,repositoryIds:o})=>{let s=W;if(s){G(null);try{let{loopRunId:l}=await F.runStandalone(e,s.id,{aiEngine:t,model:r,reasoning_effort:i,...o?{repositoryIds:o}:{}});Ee(e),a(`/jobs/${l}`),c.success(n(`run.launched`,{name:s.name}))}catch{c.error(n(`errors.save`))}}},[W,a,Ee,n]),Ne=(0,B.useCallback)(async e=>{try{await F.publish(e),await Q()}catch(e){e instanceof z?c.error(n(`errors.publishInvalid`)):c.error(n(`errors.save`))}},[n,Q]),Pe=(0,B.useCallback)(async e=>{try{await F.unpublish(e),await Q()}catch{c.error(n(`errors.save`))}},[n,Q]),Fe=(0,B.useCallback)(async e=>{try{await F.duplicate(e),await Q()}catch{c.error(n(`errors.save`))}},[n,Q]),Ie=(0,B.useCallback)(async()=>{let e=H;if(e){U(null);try{await F.restoreBuiltin(e),await Q(),c.success(n(`builder.builtin.restored`))}catch{c.error(n(`errors.save`))}}},[H,n,Q]),Le=(0,B.useCallback)(e=>N(e),[]),Re=(0,B.useCallback)(async()=>{let e=M;if(e){N(null);try{await F.remove(e),await Q()}catch{c.error(n(`errors.save`))}}},[M,n,Q]),ze=f.filter(e=>e.builtinId),Be=f.filter(e=>!e.builtinId),Ve=Be.filter(e=>e.status===`draft`),He=Be.filter(e=>e.status===`published`),Ue=de(g),We=ue(g.map(e=>({...e,searchTerms:`${u(e.id,e.name)} ${d(e.id,e.description)} ${e.category?n(`categories.${e.category}`,{defaultValue:e.category}):``}`})),{query:Y,categories:X}),Ge=Y.trim()!==``||X.length>0;return(0,V.jsxs)(`div`,{className:`h-full overflow-y-auto`,children:[(0,V.jsxs)(`div`,{className:`max-w-5xl mx-auto px-6 py-6`,children:[(0,V.jsxs)(`div`,{className:`flex items-start justify-between mb-6`,children:[(0,V.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,V.jsx)(R,{className:`w-5 h-5 text-accent-primary`}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`h1`,{className:`text-lg font-semibold text-foreground`,children:n(`title`)}),(0,V.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:n(`subtitle`)})]})]}),(0,V.jsxs)(`div`,{className:`flex items-center gap-2`,children:[!ne()&&(0,V.jsxs)(`button`,{type:`button`,onClick:()=>void P(Te).then(()=>t?.()).catch(e=>c.error(String(e))),className:`inline-flex items-center gap-1.5 h-8 px-3 rounded-md text-xs border border-border hover:bg-muted`,children:[(0,V.jsx)(m,{className:`w-3.5 h-3.5`}),n(`window.open`)]}),J.size>0&&(0,V.jsxs)(`button`,{type:`button`,onClick:()=>Z(f.filter(e=>J.has(e.id))),className:`inline-flex items-center gap-1.5 h-8 px-3 rounded-md text-xs font-medium border border-border text-foreground hover:bg-muted`,children:[(0,V.jsx)(ie,{className:`w-3.5 h-3.5`}),n(`actions.export`),` (`,J.size,`)`]}),(0,V.jsxs)(`button`,{type:`button`,onClick:()=>Ce.current?.click(),className:`inline-flex items-center gap-1.5 h-8 px-3 rounded-md text-xs font-medium border border-border text-foreground hover:bg-muted`,children:[(0,V.jsx)(ae,{className:`w-3.5 h-3.5`}),n(`actions.import`)]}),(0,V.jsx)(`input`,{ref:Ce,type:`file`,accept:`application/json,.json`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&ke(t),e.target.value=``}}),(0,V.jsxs)(`button`,{type:`button`,onClick:Ae,className:`inline-flex items-center gap-1.5 h-8 px-3 rounded-md text-xs font-medium bg-accent-primary text-white hover:bg-accent-primary/90`,children:[(0,V.jsx)(_,{className:`w-3.5 h-3.5`}),n(`newLoop`)]})]})]}),ee?(0,V.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`…`}):(0,V.jsxs)(`div`,{className:`space-y-8`,children:[Ve.length===0&&He.length===0&&(0,V.jsxs)(`div`,{className:`rounded-lg border border-dashed border-border p-8 text-center`,children:[(0,V.jsx)(`p`,{className:`text-sm font-medium text-foreground`,children:n(`empty.title`)}),(0,V.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:n(`empty.body`)})]}),f.length>0&&(0,V.jsx)(oe,{onConvert:e=>{let t=f.find(t=>t.id===e);t&&q(t)}}),He.length>0&&(0,V.jsx)(me,{title:n(`sections.published`),children:He.map(e=>(0,V.jsx)(he,{loop:e,selected:J.has(e.id),onToggleSelect:()=>De(e.id),onEdit:()=>$(e.id),onUnpublish:()=>Pe(e.id),onDuplicate:()=>Fe(e.id),onExport:()=>Z([e]),onExportLegacy:e.hasLegacyGraph?()=>void Oe(e):void 0,onConvert:e.graph.nodes.some(e=>e.type===`core`)?void 0:()=>q(e),onDelete:()=>Le(e.id),onRun:I(e.graph)?void 0:()=>G(e)},e.id))}),Ve.length>0&&(0,V.jsx)(me,{title:n(`sections.drafts`),children:Ve.map(e=>(0,V.jsx)(he,{loop:e,selected:J.has(e.id),onToggleSelect:()=>De(e.id),onEdit:()=>$(e.id),onPublish:()=>Ne(e.id),onDuplicate:()=>Fe(e.id),onExport:()=>Z([e]),onExportLegacy:e.hasLegacyGraph?()=>void Oe(e):void 0,onConvert:e.graph.nodes.some(e=>e.type===`core`)?void 0:()=>q(e),onDelete:()=>Le(e.id)},e.id))}),ze.length>0&&(0,V.jsx)(me,{title:n(`sections.builtIn`),children:ze.map(e=>(0,V.jsx)(he,{loop:{...e,name:e.builtinModified?e.name:u(e.id,e.name)},builtIn:!0,selected:J.has(e.id),onToggleSelect:()=>De(e.id),onEdit:()=>$(e.id),onPublish:e.status===`draft`?()=>Ne(e.id):void 0,onDuplicate:()=>Fe(e.id),onExport:()=>Z([e]),onRestore:e.builtinModified?()=>U(e.id):void 0},e.id))}),g.length>0&&(0,V.jsxs)(`section`,{children:[(0,V.jsxs)(`div`,{className:`flex items-center justify-between gap-3 mb-2 flex-wrap`,children:[(0,V.jsx)(`h2`,{className:`text-xs font-semibold uppercase tracking-wide text-muted-foreground`,children:n(`sections.templates`)}),(0,V.jsx)(`input`,{type:`search`,value:Y,onChange:e=>ye(e.target.value),placeholder:n(`gallery.search`),"aria-label":n(`gallery.search`),"data-testid":`template-search`,className:`h-7 w-48 max-w-full rounded-md border border-border bg-surface/40 px-2.5 text-xs text-foreground placeholder:text-muted-foreground/70 focus:outline-none focus:ring-1 focus:ring-accent-primary`})]}),(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 mb-3`,"data-testid":`category-chips`,children:[Ue.map(({category:e,count:t})=>{let r=X.includes(e);return(0,V.jsxs)(`button`,{type:`button`,"aria-pressed":r,onClick:()=>xe(e),className:O(`inline-flex items-center gap-1 h-6 px-2 rounded-full text-[11px] border transition-colors`,r?`border-accent-primary bg-accent-primary/15 text-accent-primary`:`border-border bg-surface/40 text-muted-foreground hover:text-foreground hover:bg-muted`),children:[n(`categories.${e}`,{defaultValue:e}),(0,V.jsx)(`span`,{className:`opacity-60 tabular-nums`,children:t})]},e)}),Ge&&(0,V.jsx)(`button`,{type:`button`,onClick:Se,className:`inline-flex items-center h-6 px-2 rounded-full text-[11px] text-accent-primary hover:underline`,children:n(`gallery.clearFilter`)})]}),We.length===0?(0,V.jsxs)(`div`,{className:`rounded-lg border border-dashed border-border p-6 text-center`,"data-testid":`template-empty`,children:[(0,V.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`gallery.noResults`)}),(0,V.jsx)(`button`,{type:`button`,onClick:Se,className:`mt-2 text-xs text-accent-primary hover:underline`,children:n(`gallery.clearFilter`)})]}):(0,V.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3`,children:We.map(e=>(0,V.jsxs)(`div`,{className:`rounded-lg border border-border bg-card p-3 flex flex-col gap-2`,"data-testid":`template-card`,children:[(0,V.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,V.jsx)(y,{className:`w-3.5 h-3.5 text-accent-highlight flex-shrink-0`}),(0,V.jsx)(`span`,{className:`text-sm font-medium text-foreground truncate`,children:u(e.id,e.name)}),e.category&&(0,V.jsx)(`span`,{className:`ml-auto px-1.5 py-0.5 rounded text-[10px] bg-accent-info/15 text-accent-info flex-shrink-0`,children:n(`categories.${e.category}`,{defaultValue:e.category})})]}),(0,V.jsx)(`p`,{className:`text-xs text-muted-foreground flex-1`,children:d(e.id,e.description)}),(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1`,children:[I(e.graph)?(0,V.jsx)(`span`,{title:n(`gallery.needsSpecHint`),className:`px-1.5 py-0.5 rounded text-[10px] bg-accent-secondary/15 text-accent-secondary`,children:n(`gallery.needsSpec`)}):(0,V.jsx)(`span`,{title:n(`gallery.standaloneHint`),className:`px-1.5 py-0.5 rounded text-[10px] bg-accent-success/15 text-accent-success`,children:n(`gallery.standalone`)}),e.tags.map(e=>(0,V.jsx)(`span`,{className:`px-1.5 py-0.5 rounded text-[10px] bg-muted text-muted-foreground`,children:e},e))]}),(0,V.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,V.jsxs)(`button`,{type:`button`,onClick:()=>L({...e,name:u(e.id,e.name),description:d(e.id,e.description)}),className:`inline-flex items-center gap-1.5 h-7 px-2.5 rounded-md text-xs border border-border hover:bg-muted text-foreground`,children:[(0,V.jsx)(j,{className:`w-3 h-3`}),n(`actions.preview`)]}),(0,V.jsxs)(`button`,{type:`button`,onClick:()=>je(e.id),className:`inline-flex items-center gap-1.5 h-7 px-2.5 rounded-md text-xs border border-border hover:bg-muted text-foreground`,children:[(0,V.jsx)(p,{className:`w-3 h-3`}),n(`actions.use`)]})]})]},e.id))})]})]})]}),(0,V.jsx)(D,{open:M!==null,onOpenChange:e=>{e||N(null)},children:(0,V.jsxs)(E,{className:`max-w-sm`,children:[(0,V.jsxs)(T,{children:[(0,V.jsxs)(w,{className:`flex items-center gap-2`,children:[(0,V.jsx)(b,{className:`w-4 h-4 text-destructive`}),f.find(e=>e.id===M)?.name??n(`actions.delete`)]}),(0,V.jsx)(C,{children:n(`confirmDelete`)})]}),(0,V.jsxs)(S,{children:[(0,V.jsx)(k,{variant:`ghost`,onClick:()=>N(null),children:n(`common:actions.cancel`)}),(0,V.jsx)(k,{variant:`destructive`,onClick:()=>void Re(),children:n(`common:actions.delete`)})]})]})}),(0,V.jsx)(D,{open:H!==null,onOpenChange:e=>{e||U(null)},children:(0,V.jsxs)(E,{className:`max-w-sm`,children:[(0,V.jsxs)(T,{children:[(0,V.jsxs)(w,{className:`flex items-center gap-2`,children:[(0,V.jsx)(v,{className:`w-4 h-4`}),n(`builder.builtin.confirmTitle`)]}),(0,V.jsx)(C,{children:n(`builder.builtin.confirmBody`)})]}),(0,V.jsxs)(S,{children:[(0,V.jsx)(k,{variant:`ghost`,onClick:()=>U(null),children:n(`common:actions.cancel`)}),(0,V.jsx)(k,{"data-testid":`confirm-restore-builtin`,onClick:()=>void Ie(),children:n(`actions.restoreBuiltin`)})]})]})}),(0,V.jsx)(re,{template:te,onClose:()=>L(null),onUse:e=>{L(null),je(e)}}),K&&(0,V.jsx)(pe,{loop:K,projects:we,onClose:()=>q(null),onConverted:e=>{h(t=>t.map(t=>t.id===e.id?e:t)),q(null),$(e.id)}},K.id),(0,V.jsx)(fe,{loop:W?{id:W.id,name:W.name}:null,projects:we.map(e=>({id:e.id,name:e.name,providers:o(e),repositories:e.repositories})),onClose:()=>G(null),onExecute:Me})]})}function me({title:e,children:t}){return(0,V.jsxs)(`section`,{children:[(0,V.jsx)(`h2`,{className:`text-xs font-semibold uppercase tracking-wide text-muted-foreground mb-2`,children:e}),(0,V.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3`,children:t})]})}function he({loop:e,builtIn:t=!1,selected:n,onToggleSelect:r,onEdit:a,onPublish:o,onUnpublish:s,onDuplicate:c,onExport:l,onExportLegacy:u,onConvert:d,onDelete:f,onRun:m,onRestore:_}){let{t:y}=i(`loops`),S=e.graph?.nodes?.length??0;return(0,V.jsxs)(`div`,{className:`rounded-lg border border-border bg-card p-3 flex flex-col gap-2`,"data-testid":t?`builtin-loop-card`:`loop-card`,children:[(0,V.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,V.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,V.jsx)(`input`,{type:`checkbox`,checked:n,onChange:r,"aria-label":y(`actions.select`,{name:e.name}),className:`accent-accent-primary flex-shrink-0`}),(0,V.jsx)(`span`,{className:`text-sm font-medium text-foreground truncate`,children:e.name})]}),(0,V.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[t&&(0,V.jsx)(`span`,{className:`px-1.5 py-0.5 rounded text-[10px] bg-muted text-muted-foreground`,"data-testid":`builtin-badge`,children:y(`builtInBadge`)}),(0,V.jsx)(K,{status:e.status})]})]}),(0,V.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[y(`card.nodes`,{count:S}),t&&e.builtinModified&&(0,V.jsxs)(`span`,{className:`ml-1.5 text-accent-secondary`,children:[`· `,y(`card.builtinModified`)]})]}),(0,V.jsxs)(`div`,{className:`flex items-center gap-1 flex-wrap`,children:[m&&(0,V.jsx)(J,{icon:g,label:y(`actions.run`),onClick:m}),(0,V.jsx)(J,{icon:h,label:y(`actions.edit`),onClick:a}),o&&(0,V.jsx)(J,{icon:x,label:y(`actions.publish`),onClick:o}),s&&(0,V.jsx)(J,{icon:p,label:y(`actions.unpublish`),onClick:s}),(0,V.jsx)(J,{icon:A,label:y(`actions.duplicate`),onClick:c}),(0,V.jsx)(J,{icon:ie,label:y(`actions.export`),onClick:l}),u&&(0,V.jsx)(J,{icon:ie,label:y(`actions.exportLegacy`),onClick:u}),d&&(0,V.jsx)(J,{icon:R,label:y(`actions.convert`),onClick:d}),_&&(0,V.jsx)(J,{icon:v,label:y(`actions.restoreBuiltin`),onClick:_}),f&&(0,V.jsx)(J,{icon:b,label:y(`actions.delete`),onClick:f,danger:!0})]})]})}function J({icon:e,label:t,onClick:n,danger:r}){return(0,V.jsx)(`button`,{type:`button`,onClick:n,title:t,"aria-label":t,className:O(`inline-flex items-center justify-center w-7 h-7 rounded-md transition-colors`,r?`text-muted-foreground hover:text-destructive hover:bg-destructive/10`:`text-muted-foreground hover:text-foreground hover:bg-muted`),children:(0,V.jsx)(e,{className:`w-3.5 h-3.5`})})}export{q as default};
|
package/client/dist/assets/{MinimizedChatsContext-Bc9xHByW.js → MinimizedChatsContext-CroAs6Kh.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-zu2_FqZY.js";import{t as r}from"./react-dom-DiWzBDP9.js";import{u as i}from"./chunk-KS7C4IRE-DEKu087k.js";import{r as a}from"./useSharedWebSocket-
|
|
1
|
+
import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-zu2_FqZY.js";import{t as r}from"./react-dom-DiWzBDP9.js";import{u as i}from"./chunk-KS7C4IRE-DEKu087k.js";import{r as a}from"./useSharedWebSocket-DaWuiO0S.js";import{n as o,t as s}from"./createLucideIcon-Bjbbp_KS.js";import{r as c}from"./useDesktop-DKNbOF0u.js";import{t as l}from"./sparkles-DrY8hb0X.js";import{t as u}from"./x-CBMI9ejn.js";var d=s(`arrow-up`,[[`path`,{d:`m5 12 7-7 7 7`,key:`hav0vg`}],[`path`,{d:`M12 19V5`,key:`x0mq9r`}]]),f=s(`check`,[[`path`,{d:`M20 6 9 17l-5-5`,key:`1gmf2c`}]]),p=s(`chevron-up`,[[`path`,{d:`m18 15-6-6-6 6`,key:`153udz`}]]),m=s(`messages-square`,[[`path`,{d:`M16 10a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 14.286V4a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2z`,key:`1n2ejm`}],[`path`,{d:`M20 9a2 2 0 0 1 2 2v10.286a.71.71 0 0 1-1.212.502l-2.202-2.202A2 2 0 0 0 17.172 19H10a2 2 0 0 1-2-2v-1`,key:`1qfcsi`}]]),h=e(t(),1),g=[`title`,`description`,`labels`,`priority`,`acceptanceCriteria`,`repositoryIds`],_={title:``,description:``,labels:[],priority:`medium`,acceptanceCriteria:[]};function v(e){return!e||typeof e!=`object`?!1:e.type===`spec_draft.update`}var y=e(r(),1),b=n(),x=42;function S(e){let t=e.replace(/\s+/g,` `).trim();return t.length<=x?t:t.slice(0,x-1).trimEnd()+`…`}function C({chat:e,projectName:t,onRestore:n,onClose:r}){let{t:i}=o(`chat`),a=S(e.label);return(0,b.jsxs)(`div`,{"data-testid":`minimized-chat-chip-${e.id}`,className:`grid items-start gap-2 w-full max-w-full`,style:{gridTemplateColumns:`auto minmax(0, 1fr) auto`},children:[(0,b.jsx)(w,{kind:e.kind}),(0,b.jsxs)(`button`,{type:`button`,onClick:n,className:`min-w-0 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-primary/50 rounded overflow-hidden`,"aria-label":i(`chip.restore`,{label:e.label}),title:e.label,children:[(0,b.jsx)(`div`,{className:`text-sm font-medium text-foreground truncate`,children:a}),(0,b.jsx)(`div`,{className:`text-[11px] text-muted-foreground mt-0.5 truncate`,children:i(`chip.continueEditing`,{projectName:t})})]}),(0,b.jsx)(`button`,{type:`button`,onClick:r,className:`flex items-center justify-center w-6 h-6 rounded text-muted-foreground hover:text-foreground hover:bg-accent/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-primary/50`,"aria-label":i(`chip.close`,{label:e.label}),children:(0,b.jsx)(u,{className:`w-3.5 h-3.5`})})]})}function w({kind:e}){let{t}=o(`chat`);return(0,b.jsx)(e===`ai-edit`?l:m,{className:`w-4 h-4 text-accent-primary flex-shrink-0 mt-0.5`,"aria-label":t(e===`ai-edit`?`chip.kindAiEdit`:`chip.kindExploreSpec`)})}function T({chats:e,projects:t,hidden:n,onRestore:r,onClose:i}){let{t:a}=o(`chat`),s=(0,h.useMemo)(()=>{let e=new Map;for(let n of t)e.set(n.id,n.name);return e},[t]),c=(0,h.useMemo)(()=>[...e].sort((e,t)=>t.createdAt-e.createdAt),[e]);return n||c.length===0?null:(0,y.createPortal)((0,b.jsxs)(`div`,{"data-testid":`minimized-chats-dock`,"aria-label":a(`dock.minimizedSessions`,{count:c.length}),className:`fixed bottom-4 right-14 z-[70] flex flex-col-reverse gap-2 w-[320px] max-w-[calc(100vw-15rem)] max-h-[70vh] overflow-y-auto pointer-events-none`,children:[c.map(e=>(0,b.jsx)(`div`,{className:`pointer-events-auto glass-card border border-border/30 rounded-lg p-3 shadow-lg w-full`,children:(0,b.jsx)(C,{chat:e,projectName:s.get(e.projectId)??a(`dock.unknownProject`),onRestore:()=>r(e.id),onClose:()=>i(e.id)})},e.id)),c.length>1&&(0,b.jsxs)(`div`,{className:`pointer-events-auto self-end inline-flex items-center gap-1 rounded-full bg-card/80 border border-border/40 px-2 py-0.5 text-[10px] text-muted-foreground backdrop-blur-sm`,children:[(0,b.jsx)(p,{className:`w-3 h-3`}),a(`dock.minimizedCount`,{count:c.length})]})]}),document.body)}var E=(0,h.createContext)(null),D=`specrails-desktop:minimized-chats`,O=`specrails-desktop:minimized-chats-pending`,k=50,A=8e3;function j(){return F(D)}function M(e){L(D,e)}function N(){return F(O)}function P(e){L(O,e)}function F(e){if(typeof window>`u`)return[];try{let t=window.localStorage.getItem(e);if(!t)return[];let n=JSON.parse(t);return Array.isArray(n)?n.filter(R):[]}catch{return[]}}function I(e){return e.length<=k?e:[...e].sort((e,t)=>e.createdAt-t.createdAt).slice(e.length-k)}function L(e,t){if(!(typeof window>`u`))try{window.localStorage.setItem(e,JSON.stringify(I(t)))}catch{}}function R(e){if(!e||typeof e!=`object`)return!1;let t=e;return!(typeof t.id!=`string`||typeof t.projectId!=`string`||typeof t.label!=`string`||typeof t.restoreRoute!=`string`||typeof t.createdAt!=`number`||t.kind!==`explore-spec`&&t.kind!==`ai-edit`||!t.params||typeof t.params!=`object`)}function z(){return typeof crypto<`u`&&`randomUUID`in crypto?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function B(e){return e.kind===`explore-spec`?e.params.resumeConversationId??`pending:${e.params.pendingSpecId}`:e.params.resumeRefineId??`agent:${e.params.agentId}`}function V(e,t){return e.kind!==t.kind||e.projectId!==t.projectId?!1:B(e)===B(t)}function H({children:e}){let{projects:t,activeProjectId:n,setActiveProjectId:r}=c(),o=i(),{registerHandler:s,unregisterHandler:l}=a(),[u,d]=(0,h.useState)(()=>j()),[f,p]=(0,h.useState)([]),m=(0,h.useRef)(u);m.current=u;let g=(0,h.useRef)(f);g.current=f;let _=(0,h.useRef)(new Map),y=(0,h.useRef)(t);y.current=t;let x=(0,h.useRef)(!1);(0,h.useEffect)(()=>{if(x.current)return;x.current=!0;let e=N();P([]),e.length!==0&&d(t=>{let n=[...t];for(let t of e)n.some(e=>e.id===t.id||V(e,t))||n.push(t);return M(n),m.current=n,n})},[]),(0,h.useEffect)(()=>{let e=_.current;return()=>{for(let t of e.values())clearTimeout(t);e.clear()}},[]),(0,h.useEffect)(()=>{M(u)},[u]),(0,h.useEffect)(()=>{P(f)},[f]);let S=(0,h.useRef)(()=>{}),C=(0,h.useRef)(()=>{});(0,h.useEffect)(()=>{let e=`minimized-chats:spec-draft`;return s(e,e=>{if(!v(e))return;let t=e.conversationId,n=m.current.find(e=>e.kind===`explore-spec`&&e.params.resumeConversationId===t);if(!n)return;let r=e.draft;r.title?.trim()&&S.current(n.id,r.title);let i={};r.title!==void 0&&(i.title=r.title),r.description!==void 0&&(i.description=r.description),r.priority!==void 0&&(i.priority=r.priority),r.labels!==void 0&&(i.labels=r.labels),r.repositoryIds!==void 0&&(i.repositoryIds=r.repositoryIds),r.acceptanceCriteria!==void 0&&(i.acceptanceCriteria=r.acceptanceCriteria),Object.keys(i).length>0&&C.current(n.id,i)}),()=>l(e)},[s,l]),(0,h.useEffect)(()=>{if(t.length===0)return;let e=new Set(t.map(e=>e.id));d(t=>{let n=t.filter(t=>e.has(t.projectId));return n.length===t.length?t:(M(n),m.current=n,n)}),p(t=>{let n=t.filter(t=>e.has(t.projectId));return n.length===t.length?t:(P(n),g.current=n,n)})},[t]);let w=(0,h.useCallback)(e=>{let t=z(),n={...e,id:t,createdAt:Date.now()};if(d(e=>{let t=I([...e.filter(e=>!V(e,n)),n]);return M(t),m.current=t,t}),e.kind===`explore-spec`){let t=e.params.resumeConversationId;t&&fetch(`/api/projects/${e.projectId}/chat/conversations/${t}/minimize`,{method:`POST`}).catch(()=>{})}return t},[]),D=(0,h.useCallback)(e=>{let t=_.current.get(e);t&&(clearTimeout(t),_.current.delete(e))},[]),O=(0,h.useCallback)(e=>{D(e),d(t=>{let n=t.filter(t=>t.id!==e);return M(n),m.current=n,n}),p(t=>{let n=t.filter(t=>t.id!==e);return n.length===t.length?t:(P(n),g.current=n,n)})},[D]),k=(0,h.useCallback)((e,t)=>{let n=t.trim();n&&d(t=>{let r=t.map(t=>t.id===e&&t.label!==n?{...t,label:n}:t);return r===t?t:(m.current=r,r)})},[]),F=(0,h.useCallback)((e,t)=>{d(n=>{let r=n.map(n=>{if(n.id!==e||n.kind!==`explore-spec`)return n;let r={...n.params.draftOverrides??{},...t};return{...n,params:{...n.params,draftOverrides:r}}});return m.current=r,r})},[]),L=(0,h.useCallback)(e=>{let t=m.current.find(t=>t.id===e);if(!t||y.current.length>0&&!y.current.some(e=>e.id===t.projectId))return;if(t.kind===`explore-spec`){let e=t.params.resumeConversationId;e&&fetch(`/api/projects/${t.projectId}/chat/conversations/${e}/restore`,{method:`POST`}).catch(()=>{})}n!==t.projectId&&r(t.projectId),o(t.restoreRoute),p(n=>{let r=[...n.filter(t=>t.id!==e),t];return P(r),g.current=r,r}),d(t=>{let n=t.filter(t=>t.id!==e);return M(n),m.current=n,n}),D(e);let i=setTimeout(()=>{_.current.delete(e),g.current.some(t=>t.id===e)&&(p(t=>{let n=t.filter(t=>t.id!==e);return P(n),g.current=n,n}),d(n=>{if(n.some(n=>n.id===e||V(n,t)))return n;let r=[...n,t];return M(r),m.current=r,r}))},A);_.current.set(e,i)},[n,r,o,D]),R=(0,h.useRef)(L);R.current=L;let B=(0,h.useRef)(O);B.current=O,S.current=k,C.current=F;let H=(0,h.useCallback)((e,t)=>{let n=g.current,r=n.findIndex(n=>n.kind===e&&n.projectId===t);if(r===-1)return null;let i=n[r];return D(i.id),p(e=>{let t=e.filter(e=>e.id!==i.id);return P(t),t}),g.current=n.filter(e=>e.id!==i.id),i},[D]),U=(0,h.useCallback)(e=>{let t=z(),i={...e,id:t,createdAt:Date.now()};n!==e.projectId&&r(e.projectId),o(e.restoreRoute),p(e=>{let t=[...e,i];return P(t),g.current=t,t}),D(t);let a=setTimeout(()=>{_.current.delete(t),g.current.some(e=>e.id===t)&&(p(e=>{let n=e.filter(e=>e.id!==t);return P(n),g.current=n,n}),d(e=>{if(e.some(e=>e.id===t||V(e,i)))return e;let n=[...e,i];return M(n),m.current=n,n}))},A);_.current.set(t,a)},[n,r,o,D]),W=(0,h.useMemo)(()=>({chats:u,pendingRestores:f,minimize:w,updateLabel:k,patchExploreSpecDraft:F,close:O,restore:L,takePendingRestore:H,triggerResume:U}),[u,f,w,k,F,O,L,H,U]);return(0,b.jsxs)(E.Provider,{value:W,children:[e,(0,b.jsx)(T,{chats:u,projects:t,hidden:!1,onRestore:L,onClose:O})]})}function U(){return(0,h.useContext)(E)||{chats:[],pendingRestores:[],minimize:()=>``,updateLabel:()=>{},patchExploreSpecDraft:()=>{},close:()=>{},restore:()=>{},takePendingRestore:()=>null,triggerResume:()=>{}}}function W(e,t,n){let{pendingRestores:r,takePendingRestore:i}=U(),a=(0,h.useRef)(n);a.current=n,(0,h.useEffect)(()=>{if(!t)return;let n=i(e,t);n&&a.current(n)},[r,e,t,i])}export{g as a,p as c,_ as i,f as l,U as n,v as o,W as r,m as s,H as t,d as u};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-zu2_FqZY.js";import{l as r,r as i,t as a}from"./useSharedWebSocket-g0nTHfTT.js";import{n as o,t as s}from"./createLucideIcon-Bjbbp_KS.js";import{n as c,r as l,s as u}from"./useDesktop-ChSmmJfc.js";import{s as d}from"./provider-capabilities-lePfeT_Y.js";import{t as f}from"./download-CFHyyHcw.js";import{t as p}from"./external-link-D6XxC_Cu.js";import{t as m}from"./loader-circle-DcygOQpC.js";import{t as h}from"./search-Cq_gE3Ik.js";import{t as g}from"./trash-2-BOU3WdZZ.js";import{t as _}from"./triangle-alert-H9T4jAmh.js";import{n as v,t as y}from"./jira-api-C2Tzc362.js";import{i as b,l as x,o as S,r as C,t as w}from"./dialog-CMgps2MY.js";import{t as T}from"./utils-BC4DHlz2.js";import{t as E}from"./button-D1xExSTF.js";import{Et as D,Gt as O,Tt as k,U as A,an as ee,bt as te,on as ne,qt as j,vt as re,yt as ie}from"./index-DVkWHOR3.js";var M=s(`earth`,[[`path`,{d:`M21.54 15H17a2 2 0 0 0-2 2v4.54`,key:`1djwo0`}],[`path`,{d:`M7 3.34V5a3 3 0 0 0 3 3a2 2 0 0 1 2 2c0 1.1.9 2 2 2a2 2 0 0 0 2-2c0-1.1.9-2 2-2h3.17`,key:`1tzkfa`}],[`path`,{d:`M11 21.95V18a2 2 0 0 0-2-2a2 2 0 0 1-2-2v-1a2 2 0 0 0-2-2H2.05`,key:`14pb5j`}],[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]),ae=s(`folder-kanban`,[[`path`,{d:`M4 20h16a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.93a2 2 0 0 1-1.66-.9l-.82-1.2A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13c0 1.1.9 2 2 2Z`,key:`1fr9dc`}],[`path`,{d:`M8 10v4`,key:`tgpxqk`}],[`path`,{d:`M12 10v2`,key:`hh53o1`}],[`path`,{d:`M16 10v6`,key:`1d6xys`}]]),N=s(`power`,[[`path`,{d:`M12 2v10`,key:`mnfbl`}],[`path`,{d:`M18.4 6.6a9 9 0 1 1-12.77.04`,key:`obofu9`}]]),P=s(`settings-2`,[[`path`,{d:`M14 17H5`,key:`gfn3mx`}],[`path`,{d:`M19 7h-9`,key:`6i9tg`}],[`circle`,{cx:`17`,cy:`17`,r:`3`,key:`18b49y`}],[`circle`,{cx:`7`,cy:`7`,r:`3`,key:`dfmy0x`}]]),F=e(t(),1),I=n(),oe=[`todo`,`in_progress`,`on_review`,`done`,`cancelled`],se={todo:`todo`,in_progress:`inProgress`,on_review:`onReview`,done:`done`,cancelled:`cancelled`};function L(e){let{activeProjectId:t}=l();return(0,I.jsx)(R,{...e},e.apiBase??t??`legacy`)}function R({onConnected:e,onSkip:t,apiBase:n}){let{t:r}=o(`jira`),[i,a]=(0,F.useState)(1),[s,c]=(0,F.useState)(``),[l,d]=(0,F.useState)(``),[f,p]=(0,F.useState)(``),[m,h]=(0,F.useState)(`idle`),[g,_]=(0,F.useState)(null),[v,b]=(0,F.useState)(`cloud`),[x,S]=(0,F.useState)([]),[C,w]=(0,F.useState)(``),[T,D]=(0,F.useState)(``),[O,k]=(0,F.useState)(``),[ee,te]=(0,F.useState)(!1),[ne,j]=(0,F.useState)([]),[re,ie]=(0,F.useState)({}),[M,ae]=(0,F.useState)(``),[N,P]=(0,F.useState)(!1),[L,R]=(0,F.useState)(!1),H=(0,F.useRef)(0),U=(0,F.useRef)(!0);(0,F.useEffect)(()=>(U.current=!0,()=>{U.current=!1,H.current++}),[]);let[W,ce]=(0,F.useState)(!1),G=()=>({baseUrl:s.trim(),accountEmail:l.trim()||null,token:f});async function le(){h(`testing`);try{let e=await y.test(G(),n);if(!U.current)return;h(`ok`),_(e.displayName),b(e.deployment)}catch(e){if(!U.current)return;h(`error`),u.error(V(e,r))}}async function K(){a(2),te(!0);try{let{projects:e}=await y.discoverProjects({...G(),query:C.trim()||void 0},n);if(!U.current)return;S(e)}catch(e){U.current&&u.error(V(e,r))}finally{U.current&&te(!1)}}async function q(){a(3),await J()}async function J(){if(!T)return;let e=++H.current;P(!0);try{let{statuses:t}=await y.discoverStatuses({...G(),projectKey:T},n);if(!U.current||e!==H.current)return;j(t),R(!1)}catch{U.current&&e===H.current&&R(!0)}finally{U.current&&e===H.current&&P(!1)}}function Y(e,t){e!==T&&(H.current++,j([]),ie({}),ae(``),R(!1),P(!1)),D(e),k(t)}async function ue(){ce(!0);try{let t=Object.fromEntries(Object.entries(re).filter(([,e])=>e));if(await y.connect({...G(),jiraProjectKey:T.trim(),statusMap:Object.keys(t).length?t:null,discardStatus:M.trim()||null},n),!U.current)return;u.success(r(`status.connected`,{key:T.trim()})),e()}catch(e){U.current&&u.error(V(e,r))}finally{U.current&&ce(!1)}}return(0,I.jsxs)(`div`,{className:`space-y-4`,"data-testid":`jira-wizard`,children:[(0,I.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(`wizard.step`,{current:i,total:4})}),t&&(0,I.jsx)(`button`,{type:`button`,onClick:t,className:`text-xs text-muted-foreground hover:text-foreground hover:underline`,"data-testid":`jira-later`,children:r(`wizard.later`)})]}),i===1&&(0,I.jsxs)(`div`,{className:`space-y-3`,children:[(0,I.jsx)(`h3`,{className:`text-sm font-semibold`,children:r(`wizard.step1Title`)}),(0,I.jsx)(z,{label:r(`creds.baseUrlLabel`),help:r(`creds.baseUrlHelp`),children:(0,I.jsx)(A,{value:s,onChange:e=>{c(e.target.value),h(`idle`)},placeholder:r(`creds.baseUrlPlaceholder`)})}),(0,I.jsx)(z,{label:r(`creds.emailLabel`),help:r(`creds.emailHelp`),children:(0,I.jsx)(A,{value:l,onChange:e=>{d(e.target.value),h(`idle`)},placeholder:r(`creds.emailPlaceholder`)})}),(0,I.jsx)(z,{label:r(`creds.tokenLabel`),help:r(`creds.tokenHelp`),children:(0,I.jsx)(A,{type:`password`,value:f,onChange:e=>{p(e.target.value),h(`idle`)}})}),(0,I.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,I.jsx)(E,{size:`sm`,variant:`outline`,onClick:le,disabled:!s.trim()||!f.trim()||m===`testing`,children:r(m===`testing`?`creds.testing`:m===`ok`?`creds.retest`:`creds.test`)}),m===`ok`&&(0,I.jsxs)(`span`,{className:`text-xs text-accent-success`,"data-testid":`jira-test-ok`,children:[`✓ `,r(`creds.testOk`,{name:g??``}),` · `,r(v===`cloud`?`review.cloud`:`review.dc`)]})]}),(0,I.jsx)(`div`,{className:`flex justify-end`,children:(0,I.jsx)(E,{size:`sm`,onClick:K,disabled:m!==`ok`,children:r(`wizard.next`)})})]}),i===2&&(0,I.jsxs)(`div`,{className:`space-y-3`,children:[(0,I.jsx)(`h3`,{className:`text-sm font-semibold`,children:r(`wizard.step2Title`)}),(0,I.jsxs)(`div`,{className:`flex gap-2`,children:[(0,I.jsx)(A,{value:C,onChange:e=>w(e.target.value),placeholder:r(`project.searchPlaceholder`)}),(0,I.jsx)(E,{size:`sm`,variant:`outline`,onClick:K,children:r(`project.searchPlaceholder`)})]}),ee?(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(`project.loading`)}):x.length===0?(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(`project.none`)}):(0,I.jsx)(`div`,{className:`max-h-48 space-y-1 overflow-y-auto`,"data-testid":`jira-project-list`,children:x.map(e=>(0,I.jsxs)(`button`,{type:`button`,onClick:()=>Y(e.key,e.name),className:`flex w-full items-center justify-between rounded px-2 py-1.5 text-left text-sm hover:bg-muted ${T===e.key?`bg-muted`:``}`,children:[(0,I.jsx)(`span`,{className:`font-medium`,children:e.key}),(0,I.jsx)(`span`,{className:`truncate text-xs text-muted-foreground`,children:e.name})]},e.id))}),(0,I.jsx)(z,{label:r(`project.manualLabel`),children:(0,I.jsx)(A,{value:T,onChange:e=>Y(e.target.value.toUpperCase(),``),placeholder:r(`project.manualPlaceholder`)})}),(0,I.jsxs)(`div`,{className:`flex justify-between`,children:[(0,I.jsx)(E,{size:`sm`,variant:`ghost`,onClick:()=>a(1),children:r(`wizard.back`)}),(0,I.jsx)(E,{size:`sm`,onClick:q,disabled:!T.trim(),children:r(`wizard.next`)})]})]}),i===3&&(0,I.jsxs)(`div`,{className:`space-y-3`,children:[(0,I.jsx)(`h3`,{className:`text-sm font-semibold`,children:r(`wizard.step3Title`)}),(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(`mapping.intro`)}),L&&(0,I.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,I.jsx)(`p`,{role:`alert`,className:`text-xs text-accent-warning`,children:r(`mapping.loadFailed`)}),(0,I.jsx)(E,{size:`sm`,variant:`outline`,disabled:N,onClick:()=>void J(),children:r(`mapping.retry`)})]}),N&&(0,I.jsx)(`p`,{role:`status`,className:`text-xs text-muted-foreground`,children:r(`mapping.loading`)}),oe.map(e=>(0,I.jsx)(z,{label:r(`mapping.${se[e]}`),children:(0,I.jsxs)(`select`,{value:re[e]??``,onChange:t=>ie(n=>({...n,[e]:t.target.value||void 0})),className:`w-full rounded-md border border-border bg-background px-2 py-1.5 text-sm`,children:[(0,I.jsx)(`option`,{value:``,children:r(`mapping.auto`)}),ne.map(e=>(0,I.jsx)(`option`,{value:e.name,children:e.name},e.id))]})},e)),(0,I.jsx)(z,{label:r(`discard.configLabel`),help:r(`discard.configHelp`),children:(0,I.jsxs)(`select`,{value:M,onChange:e=>ae(e.target.value),className:`w-full rounded-md border border-border bg-background px-2 py-1.5 text-sm`,"data-testid":`jira-discard-status-select`,children:[(0,I.jsx)(`option`,{value:``,children:r(`discard.configNone`)}),ne.map(e=>(0,I.jsx)(`option`,{value:e.name,children:e.name},e.id))]})}),(0,I.jsxs)(`div`,{className:`flex justify-between`,children:[(0,I.jsx)(E,{size:`sm`,variant:`ghost`,onClick:()=>a(2),children:r(`wizard.back`)}),(0,I.jsx)(E,{size:`sm`,onClick:()=>a(4),children:r(`wizard.next`)})]})]}),i===4&&(0,I.jsxs)(`div`,{className:`space-y-3`,children:[(0,I.jsx)(`h3`,{className:`text-sm font-semibold`,children:r(`wizard.step4Title`)}),(0,I.jsxs)(`dl`,{className:`space-y-1 text-sm`,children:[(0,I.jsx)(B,{label:r(`review.site`),value:s}),(0,I.jsx)(B,{label:r(`review.project`),value:O?`${T} — ${O}`:T}),(0,I.jsx)(B,{label:r(`review.account`),value:g??l}),(0,I.jsx)(B,{label:r(`review.type`),value:r(v===`cloud`?`review.cloud`:`review.dc`)}),(0,I.jsx)(B,{label:r(`discard.reviewLabel`),value:M||r(`discard.configNone`)})]}),(0,I.jsxs)(`div`,{className:`flex justify-between`,children:[(0,I.jsx)(E,{size:`sm`,variant:`ghost`,onClick:()=>a(3),children:r(`wizard.back`)}),(0,I.jsx)(E,{size:`sm`,onClick:ue,disabled:W,children:r(W?`wizard.connecting`:`wizard.connect`)})]})]})]})}function z({label:e,help:t,children:n}){return(0,I.jsxs)(`label`,{className:`block space-y-1`,children:[(0,I.jsx)(`span`,{className:`text-xs font-medium text-foreground`,children:e}),n,t&&(0,I.jsx)(`span`,{className:`block text-[11px] text-muted-foreground`,children:t})]})}function B({label:e,value:t}){return(0,I.jsxs)(`div`,{className:`flex justify-between gap-4`,children:[(0,I.jsx)(`dt`,{className:`text-muted-foreground`,children:e}),(0,I.jsx)(`dd`,{className:`truncate text-right font-medium`,children:t})]})}function V(e,t){return e instanceof Error?e.message:t(`errors.generic`)}var H={pending:0,inflight:0,done:0,dead:0};function U({projectId:e,baseUrl:t,apiBase:n,initialCounts:r,refreshToken:i}){let{t:s}=o(`jira`),[c,l]=(0,F.useState)(null),[d,f]=(0,F.useState)(!1),[p,m]=(0,F.useState)(()=>new Set),h=(0,F.useRef)(!0),g=(0,F.useRef)(0),_=(0,F.useContext)(a),v=(0,F.useId)(),b=(0,F.useCallback)(async()=>{if(!h.current)return;let e=++g.current;try{let t=n?await y.listOutbox(`dead`,n):await y.listOutbox(`dead`);if(!h.current||e!==g.current)return;l({...t,ops:t.ops.filter(e=>e.state===`dead`)}),f(!1)}catch{h.current&&e===g.current&&f(!0)}},[n]);(0,F.useEffect)(()=>(h.current=!0,b(),()=>{h.current=!1,g.current++}),[b,i,r?.dead,r?.pending,r?.inflight,r?.done,r?.superseded]),(0,F.useEffect)(()=>{if(_)return _.registerHandler(v,t=>{if(!t||typeof t!=`object`)return;let n=t;n.type===`jira.outbox_changed`&&n.projectId===e&&b()}),()=>_.unregisterHandler(v)},[_,v,e,b]);async function x(e){if(!p.has(e)){m(t=>new Set(t).add(e));try{n?await y.retryOutbox(e,n):await y.retryOutbox(e),h.current&&await b()}catch(e){h.current&&u.error(e instanceof Error?e.message:s(`errors.generic`))}finally{h.current&&m(t=>{let n=new Set(t);return n.delete(e),n})}}}let S=c?.counts??r??H,C=S.pending+S.inflight;return(0,I.jsxs)(`div`,{className:`rounded-md border border-border p-3`,"data-testid":`jira-outbox`,children:[(0,I.jsx)(`p`,{className:`text-sm font-medium`,children:s(`outbox.title`)}),(0,I.jsx)(`p`,{className:`mt-1 text-xs ${S.dead>0?`text-accent-warning`:`text-muted-foreground`}`,children:S.dead>0?s(`outbox.dead`,{count:S.dead}):C>0?s(`outbox.pending`,{count:C}):s(S.superseded?`outbox.nonePending`:`outbox.allSynced`)}),d&&(0,I.jsxs)(`div`,{className:`mt-2 flex items-center justify-between gap-2`,children:[(0,I.jsx)(`p`,{role:`alert`,className:`text-xs text-accent-warning`,children:s(`outbox.loadFailed`)}),(0,I.jsx)(E,{variant:`outline`,size:`sm`,onClick:()=>void b(),children:s(`outbox.retry`)})]}),!!c?.ops.length&&(0,I.jsxs)(`div`,{className:`mt-2 space-y-2`,children:[(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:s(`outbox.deadHelp`)}),c.ops.map(e=>{let n=e.targetStatus||(e.logicalState?s(`mapping.${W(e.logicalState)}`):null),r=e.deadReason??e.lastError??``;return(0,I.jsxs)(`div`,{className:`flex items-start justify-between gap-2 rounded border border-border/60 px-2 py-2`,children:[(0,I.jsxs)(`div`,{className:`min-w-0 space-y-1 text-xs`,children:[(0,I.jsxs)(`p`,{className:`break-words`,children:[e.jiraKey?(0,I.jsx)(`a`,{href:`${t.replace(/\/$/,``)}/browse/${encodeURIComponent(e.jiraKey)}`,target:`_blank`,rel:`noreferrer`,className:`font-medium text-accent-primary hover:underline`,children:e.jiraKey}):(0,I.jsx)(`span`,{className:`font-medium`,children:s(`outbox.issueFallback`,{id:e.jiraIssueId})}),` · `,s(e.opType===`transition`?`outbox.opTransition`:e.opType===`comment`?`outbox.opComment`:e.opType===`update`?`outbox.opUpdate`:`outbox.opCreate`)]}),n&&(0,I.jsx)(`p`,{className:`break-words text-muted-foreground`,children:s(`outbox.target`,{status:n})}),(0,I.jsx)(`p`,{className:`max-h-32 overflow-y-auto whitespace-pre-wrap break-words text-muted-foreground`,children:r})]}),(0,I.jsx)(E,{className:`shrink-0`,variant:`outline`,size:`sm`,disabled:p.has(e.id),onClick:()=>void x(e.id),children:s(p.has(e.id)?`outbox.retrying`:`outbox.retry`)})]},e.id)})]})]})}function W(e){return e===`in_progress`?`inProgress`:e===`on_review`?`onReview`:e}var ce=[`todo`,`in_progress`,`on_review`,`done`,`cancelled`],G={todo:`todo`,in_progress:`inProgress`,on_review:`onReview`,done:`done`,cancelled:`cancelled`};function le(e){let{activeProjectId:t}=l(),n=`${e.apiBase??t??``}:${e.state.connection.projectId}`;return(0,I.jsx)(K,{...e},n)}function K({state:e,onChanged:t,apiBase:n}){let{t:r}=o(`jira`),i=e.connection,[a,s]=(0,F.useState)(i.enabled),[c,l]=(0,F.useState)(!1),[d,f]=(0,F.useState)(!1),[p,m]=(0,F.useState)(0),[h,g]=(0,F.useState)([]),[_,v]=(0,F.useState)(i.discardStatus??``),[b,x]=(0,F.useState)(i.statusMap??{}),[S,C]=(0,F.useState)(!1),[w,T]=(0,F.useState)(!1),D=(0,F.useRef)(0),O=(0,F.useRef)(!0),k=(0,F.useCallback)(async()=>{let e=++D.current;T(!0);try{let{statuses:t}=await y.listStatuses(n);if(!O.current||e!==D.current)return;g(t),C(!1)}catch{O.current&&e===D.current&&C(!0)}finally{O.current&&e===D.current&&T(!1)}},[n]);(0,F.useEffect)(()=>(O.current=!0,k(),()=>{O.current=!1,D.current++}),[k]);async function A(e){let i=_;v(e);try{if(n?await y.patchConnection({discardStatus:e||null},n):await y.patchConnection({discardStatus:e||null}),!O.current)return;t()}catch(e){if(!O.current)return;v(i),u.error(q(e,r))}}async function ee(e,i){let a=b,o={...b,[e]:i||void 0};x(o);let s=Object.fromEntries(Object.entries(o).filter(([,e])=>e));try{if(n?await y.patchConnection({statusMap:Object.keys(s).length?s:null},n):await y.patchConnection({statusMap:Object.keys(s).length?s:null}),!O.current)return;m(e=>e+1),t()}catch(e){if(!O.current)return;x(a),u.error(q(e,r))}}async function te(){let e=!a;s(e),f(!0);try{n?await y.setEnabled(e,n):await y.setEnabled(e)}catch(t){if(!O.current)return;s(!e),u.error(q(t,r))}finally{O.current&&f(!1)}}async function ne(){l(!0);try{let e=n?await y.syncNow(n):await y.syncNow();if(!O.current)return;u.success(r(`status.syncedToast`,{count:e.upserted})),m(e=>e+1)}catch(e){O.current&&u.error(q(e,r))}finally{O.current&&l(!1)}}async function j(){if(window.confirm(r(`status.disconnectConfirm`))){f(!0);try{if(n?await y.disconnect(n):await y.disconnect(),!O.current)return;u.success(r(`status.disconnectedToast`)),t()}catch(e){O.current&&u.error(q(e,r))}finally{O.current&&f(!1)}}}return(0,I.jsxs)(`div`,{className:`space-y-4`,"data-testid":`jira-connected`,children:[(0,I.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`p`,{className:`text-sm font-medium text-foreground`,children:r(`status.connected`,{key:i.jiraProjectKey})}),(0,I.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[i.baseUrl,` · `,i.deployment===`cloud`?r(`review.cloud`):r(`review.dc`)]})]}),(0,I.jsx)(`a`,{href:`${i.baseUrl}/browse/${i.jiraProjectKey}`,target:`_blank`,rel:`noreferrer`,className:`text-xs text-accent-primary hover:underline`,children:r(`badge.openInJira`)})]}),(0,I.jsxs)(`div`,{className:`flex items-center justify-between rounded-md border border-border p-3`,children:[(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`p`,{className:`text-sm font-medium`,children:r(`status.enabledLabel`)}),(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(a?`status.enabledHelp`:`status.pausedHelp`)})]}),(0,I.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":a,"aria-label":r(`status.enabledLabel`),disabled:d,onClick:te,className:`relative inline-flex h-5 w-9 shrink-0 items-center rounded-full transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 ${a?`bg-accent-success`:`bg-input`}`,children:(0,I.jsx)(`span`,{className:`inline-block h-3.5 w-3.5 rounded-full bg-background shadow-sm transition-transform ${a?`translate-x-4`:`translate-x-0.5`}`})})]}),(0,I.jsxs)(`div`,{className:`rounded-md border border-border p-3`,"data-testid":`jira-status-map`,children:[(0,I.jsx)(`p`,{className:`text-sm font-medium`,children:r(`wizard.step3Title`)}),(0,I.jsx)(`p`,{className:`mt-0.5 mb-2 text-xs text-muted-foreground`,children:r(`mapping.intro`)}),S&&(0,I.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2`,children:[(0,I.jsx)(`p`,{role:`alert`,className:`text-xs text-accent-warning`,children:r(`mapping.loadFailed`)}),(0,I.jsx)(E,{variant:`outline`,size:`sm`,disabled:w,onClick:()=>void k(),children:r(`mapping.retry`)})]}),w&&(0,I.jsx)(`p`,{role:`status`,className:`mb-2 text-xs text-muted-foreground`,children:r(`mapping.loading`)}),(0,I.jsx)(`div`,{className:`space-y-2`,children:ce.map(e=>(0,I.jsxs)(`label`,{className:`flex items-center justify-between gap-3`,children:[(0,I.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:r(`mapping.${G[e]}`)}),(0,I.jsxs)(`select`,{value:b[e]??``,onChange:t=>void ee(e,t.target.value),className:`w-44 rounded-md border border-border bg-background px-2 py-1.5 text-sm`,"data-testid":`jira-statusmap-${e}`,children:[(0,I.jsx)(`option`,{value:``,children:r(`mapping.auto`)}),h.map(e=>(0,I.jsx)(`option`,{value:e.name,children:e.name},e.id)),b[e]&&!h.some(t=>t.name===b[e])&&(0,I.jsx)(`option`,{value:b[e],children:b[e]})]})]},e))})]}),(0,I.jsxs)(`div`,{className:`rounded-md border border-border p-3`,children:[(0,I.jsx)(`p`,{className:`text-sm font-medium`,children:r(`discard.configLabel`)}),(0,I.jsx)(`p`,{className:`mt-0.5 mb-2 text-xs text-muted-foreground`,children:r(`discard.configHelp`)}),(0,I.jsxs)(`select`,{value:_,onChange:e=>void A(e.target.value),className:`w-full rounded-md border border-border bg-background px-2 py-1.5 text-sm`,"data-testid":`jira-discard-status-select`,children:[(0,I.jsx)(`option`,{value:``,children:r(`discard.configNone`)}),h.map(e=>(0,I.jsx)(`option`,{value:e.name,children:e.name},e.id)),_&&!h.some(e=>e.name===_)&&(0,I.jsx)(`option`,{value:_,children:_})]})]}),(0,I.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,I.jsx)(E,{variant:`outline`,size:`sm`,onClick:ne,disabled:c,children:r(c?`status.syncing`:`status.syncNow`)}),(0,I.jsx)(E,{variant:`ghost`,size:`sm`,onClick:j,disabled:d,className:`text-destructive`,children:r(`status.disconnect`)})]}),(0,I.jsx)(U,{projectId:i.projectId,baseUrl:i.baseUrl,apiBase:n,initialCounts:e.outbox,refreshToken:p})]})}function q(e,t){return e instanceof Error?e.message:t(`errors.generic`)}var J=new Set([`claude`,`codex`,`kimi`]);function Y(e){return{provider:e,label:e===`codex`?`Codex`:`Claude`,active:!1,available:!1,detectedRoute:!1,requests:0,inputTokens:0,inputTokensSaved:0,outputTokens:0,outputTokensSaved:0,outputSavingsPercent:0,outputSavingsMethod:`none`,outputSavingsAllocated:!1}}function ue(){return{updatedAt:null,proxyStatsAvailable:!1,durableSavingsAvailable:!1,outputSavingsAvailable:!1,outputSavingsMethod:null,outputConfidence:null,providers:{codex:Y(`codex`),claude:Y(`claude`)},lastIssue:null}}var X={installed:!1,installSource:null,version:null,executablePath:null,uvPath:null,port:8787,phase:`idle`,activeProviders:{codex:!1,claude:!1},availableProviders:{codex:!1,claude:!1},detectedRoutes:{codex:!1,claude:!1},proxyRunning:!1,proxyPid:null,learning:{enabled:!1,baselineReady:!1,baselineSamples:0,updatedAt:null,lastIssue:null},metrics:ue(),lastIssue:null,updatedAt:null};function de(e){let t=e?.metrics??ue();return{...X,...e,activeProviders:{...X.activeProviders,...e?.activeProviders},availableProviders:{...X.availableProviders,...e?.availableProviders},detectedRoutes:{...X.detectedRoutes,...e?.detectedRoutes},learning:{...X.learning,...e?.learning},metrics:{...ue(),...t,providers:{codex:{...Y(`codex`),...t.providers?.codex},claude:{...Y(`claude`),...t.providers?.claude}}}}}async function Z(e){let t=await e.text(),n=t?JSON.parse(t):{};if(!e.ok){let t=n.issue;throw Object.assign(Error(t?.title??n.error??`HTTP ${e.status}`),{payload:n})}return n}function Q(e){return`${r}/api/projects/${e}`}function fe(e,t=`en`){if(!Number.isFinite(e))return`0`;try{return Intl.NumberFormat(t,{notation:`compact`,maximumFractionDigits:1}).format(Math.max(0,e))}catch{return Intl.NumberFormat(`en`,{notation:`compact`,maximumFractionDigits:1}).format(Math.max(0,e))}}function $(e,t,n){return`${fe(e,t)} ${n}`}function pe({onWindowOpened:e}={}){let{t}=o(`integrations`),{projects:n}=l(),{registerHandler:a,unregisterHandler:s}=i(),[c,d]=(0,F.useState)(``),[f,m]=(0,F.useState)(`all`),[g,_]=(0,F.useState)(X),[v,y]=(0,F.useState)(!0),[E,O]=(0,F.useState)(null),[A,j]=(0,F.useState)([]),[M,N]=(0,F.useState)(!1),[P,oe]=(0,F.useState)(!1),[se,L]=(0,F.useState)(null),[R,z]=(0,F.useState)({jira:0,serena:0,projects:0}),B=(0,F.useCallback)(async()=>{try{let e=await fetch(`${r}/api/global-plugins/headroom`).then(e=>Z(e));_(de(e.state))}finally{y(!1)}},[]);(0,F.useEffect)(()=>{B()},[B]),(0,F.useEffect)(()=>(a(`plugins-page`,e=>{let t=e;t.type===`plugin.headroom_progress`&&(t.line&&j(e=>[...e.slice(-80),t.line]),B())}),()=>s(`plugins-page`)),[a,s,B]),(0,F.useEffect)(()=>{let e=!1;async function t(){let t=await Promise.all(n.map(async e=>{let[t,n]=await Promise.all([fetch(`${Q(e.id)}/jira/connection`).then(e=>Z(e)).catch(()=>({connected:!1})),fetch(`${Q(e.id)}/plugins`).then(e=>Z(e)).catch(()=>({plugins:[]}))]),r=n.plugins.find(e=>e.name===`serena`);return{jira:+!!t.connected,serena:r&&r.status!==`not-installed`&&r.status!==`orphan`?1:0}}));e||z({jira:t.reduce((e,t)=>e+t.jira,0),serena:t.reduce((e,t)=>e+t.serena,0),projects:n.length})}return t(),()=>{e=!0}},[n]);async function V(e,t){O(e),j([]);try{let e=(await t()).state;e&&_(de(e))}catch(e){let t=e.payload;t?.state&&_(de(t.state))}finally{O(null),B()}}let H=(0,F.useMemo)(()=>[{id:`headroom-ai`,title:`Headroom AI`,scope:`global`,icon:D,description:t(`plugins.catalog.headroom.description`),installed:g.installed,status:g.lastIssue?`attention`:g.installed?g.activeProviders.codex||g.activeProviders.claude?g.installSource===`system`?`external-active`:`active`:g.installSource===`system`?`external`:`installed`:`available`,statusLabel:g.lastIssue?t(`plugins.status.attention`):g.installed?g.activeProviders.codex||g.activeProviders.claude?g.installSource===`system`?t(`plugins.status.externalActive`):t(`plugins.status.active`):g.installSource===`system`?t(`plugins.status.external`):t(`plugins.status.installed`):t(`plugins.status.available`),actionKind:g.lastIssue?`review`:g.installed?`manage`:`install`,actionLabel:g.lastIssue?t(`plugins.actions.review`):g.installed?t(`plugins.actions.manage`):t(`plugins.actions.install`),busy:E===`install`,action:()=>{if(g.lastIssue||g.installed){N(!0);return}V(`install`,()=>fetch(`${r}/api/global-plugins/headroom/install`,{method:`POST`}).then(e=>Z(e)))}}],[g,E,t]),U=(0,F.useMemo)(()=>[{id:`jira`,title:`Jira`,scope:`project`,icon:ae,description:t(`plugins.catalog.jira.description`),installed:R.jira>0,status:R.jira>0?`configured`:`available`,statusLabel:R.jira>0?t(`plugins.status.configuredCount`,{count:R.jira}):t(`plugins.status.available`),actionKind:R.jira>0?`manage`:`install`,actionLabel:R.jira>0?t(`plugins.actions.manage`):t(`plugins.actions.install`),action:()=>L(`jira`)},{id:`serena`,title:`Serena`,scope:`project`,icon:re,description:t(`plugins.catalog.serena.description`),installed:R.serena>0,status:R.serena>0?`installed`:`available`,statusLabel:R.serena>0?t(`plugins.status.installedCount`,{count:R.serena}):t(`plugins.status.available`),actionKind:R.serena>0?`manage`:`install`,actionLabel:R.serena>0?t(`plugins.actions.manage`):t(`plugins.actions.install`),action:()=>L(`serena`)}],[R,t]),W=c.trim().toLowerCase(),ce=e=>`${e.title} ${e.description} ${e.statusLabel} ${t(`plugins.scope.${e.scope}`)}`.toLowerCase().includes(W),G=[...H,...U].filter(e=>f!==`all`&&e.scope!==f?!1:ce(e)),le=G.filter(e=>e.scope===`global`&&e.installed),K=G.filter(e=>e.scope===`project`&&e.installed),q=G.filter(e=>e.scope===`global`&&!e.installed),J=G.filter(e=>e.scope===`project`&&!e.installed),Y=le.length>0||K.length>0,ue=q.length>0||J.length>0,fe=[g.installed,R.jira>0,R.serena>0].filter(Boolean).length;return(0,I.jsxs)(`div`,{className:`flex h-full flex-col bg-background`,children:[(0,I.jsxs)(`div`,{className:`border-b border-border px-6 py-4`,children:[(0,I.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,I.jsx)(`div`,{className:`grid h-9 w-9 place-items-center rounded-lg border border-accent-primary/25 bg-accent-primary/10 text-accent-primary`,children:(0,I.jsx)(k,{className:`h-4 w-4`})}),(0,I.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,I.jsx)(`h1`,{className:`text-lg font-semibold tracking-normal`,children:t(`plugins.page.title`)}),(0,I.jsx)(`p`,{className:`mt-0.5 text-xs text-muted-foreground`,children:t(`plugins.page.subtitle`)})]}),!ee()&&(0,I.jsxs)(`button`,{type:`button`,onClick:()=>void ne().then(()=>e?.()).catch(e=>u.error(String(e))),className:`inline-flex items-center gap-1.5 rounded-md border border-border px-3 py-2 text-xs hover:bg-muted`,children:[(0,I.jsx)(p,{className:`h-3.5 w-3.5`}),t(`plugins.page.openWindow`)]}),(0,I.jsxs)(`div`,{className:`mr-12 flex items-center gap-2 rounded-lg border border-border bg-card/60 px-3 py-2 text-xs`,children:[(0,I.jsx)(te,{className:`h-3.5 w-3.5 text-accent-success`}),(0,I.jsx)(`span`,{className:`text-muted-foreground`,children:t(`plugins.page.readyCount`,{count:fe})})]})]}),(0,I.jsxs)(`div`,{className:`mt-4 flex flex-col gap-3 md:flex-row md:items-center`,children:[(0,I.jsxs)(`label`,{className:`relative flex-1`,children:[(0,I.jsx)(h,{className:`pointer-events-none absolute left-3 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground`}),(0,I.jsx)(`input`,{value:c,onChange:e=>d(e.target.value),placeholder:t(`plugins.search.placeholder`),className:`h-9 w-full rounded-lg border border-border bg-background pl-9 pr-3 text-sm outline-none transition-colors focus:border-accent-primary/60`})]}),(0,I.jsx)(`div`,{className:`inline-flex h-9 rounded-lg border border-border bg-card p-1`,children:[`all`,`global`,`project`].map(e=>(0,I.jsx)(`button`,{type:`button`,onClick:()=>m(e),className:T(`rounded-md px-3 text-xs capitalize transition-colors`,f===e?`bg-muted text-foreground`:`text-muted-foreground hover:text-foreground`),children:t(`plugins.filters.${e}`)},e))})]})]}),(0,I.jsxs)(`div`,{className:`flex-1 overflow-auto px-6 py-5`,children:[(0,I.jsxs)(`section`,{className:`mb-6`,children:[(0,I.jsxs)(`div`,{className:`mb-3 flex items-center gap-2 text-xs font-medium text-muted-foreground`,children:[(0,I.jsx)(ie,{className:`h-3.5 w-3.5`}),t(`plugins.sections.installed`)]}),Y?(0,I.jsx)(me,{globalPlugins:le,projectPlugins:K}):(0,I.jsx)(he,{text:t(W?`plugins.empty.installedSearch`:`plugins.empty.installed`)})]}),(0,I.jsxs)(`section`,{children:[(0,I.jsxs)(`div`,{className:`mb-3 flex items-center gap-2 text-xs font-medium text-muted-foreground`,children:[(0,I.jsx)(k,{className:`h-3.5 w-3.5`}),t(`plugins.sections.available`)]}),ue?(0,I.jsx)(me,{globalPlugins:q,projectPlugins:J}):(0,I.jsx)(he,{text:t(W?`plugins.empty.availableSearch`:`plugins.empty.allInstalled`)})]})]}),(0,I.jsx)(w,{open:M,onOpenChange:N,children:(0,I.jsxs)(C,{className:`w-[calc(100vw-2rem)] max-w-xl overflow-x-hidden p-4 sm:p-6`,children:[(0,I.jsxs)(S,{children:[(0,I.jsx)(x,{children:t(`plugins.headroom.title`)}),(0,I.jsx)(b,{children:t(`plugins.headroom.dialogDescription`)})]}),(0,I.jsx)(ye,{state:g,loading:v,busy:E,logs:A,onInstall:()=>V(`install`,()=>fetch(`${r}/api/global-plugins/headroom/install`,{method:`POST`}).then(e=>Z(e))),onToggleProvider:(e,t)=>V(`${t?`deactivate`:`activate`}-${e}`,()=>fetch(`${r}/api/global-plugins/headroom/${t?`deactivate`:`activate`}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({provider:e})}).then(e=>Z(e))),onDeactivateAll:()=>V(`deactivate-all`,async()=>{let e={state:g};for(let t of[`codex`,`claude`])g.activeProviders[t]&&(e=await fetch(`${r}/api/global-plugins/headroom/deactivate`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({provider:t})}).then(e=>Z(e)));return e}),onUninstall:()=>V(`uninstall`,()=>fetch(`${r}/api/global-plugins/headroom/uninstall`,{method:`POST`}).then(e=>Z(e))),onSetPort:e=>V(`port`,()=>fetch(`${r}/api/global-plugins/headroom/port`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({port:e})}).then(e=>Z(e))),onOpenDiagnostics:()=>oe(!0)})]})}),(0,I.jsx)(Ee,{plugin:se,projects:n,onClose:()=>L(null)}),(0,I.jsx)(ke,{open:P,onClose:()=>oe(!1)})]})}function me({globalPlugins:e,projectPlugins:t}){let{t:n}=o(`integrations`);return(0,I.jsxs)(`div`,{className:T(`grid grid-cols-1 gap-4`,e.length>0&&t.length>0&&`xl:grid-cols-2`),children:[e.length>0&&(0,I.jsxs)(`section`,{children:[(0,I.jsx)(_e,{title:n(`plugins.groups.global.title`),detail:n(`plugins.groups.global.detail`),scope:`global`}),(0,I.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(260px,320px))] justify-start gap-3`,children:e.map(e=>(0,I.jsx)(ve,{plugin:e},e.id))})]}),t.length>0&&(0,I.jsxs)(`section`,{children:[(0,I.jsx)(_e,{title:n(`plugins.groups.project.title`),detail:n(`plugins.groups.project.detail`),scope:`project`}),(0,I.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(260px,320px))] justify-start gap-3`,children:t.map(e=>(0,I.jsx)(ve,{plugin:e},e.id))})]})]})}function he({text:e}){return(0,I.jsx)(`div`,{className:`flex h-[74px] max-w-[320px] items-center rounded-lg border border-dashed border-border bg-card/35 px-3 text-xs text-muted-foreground`,children:e})}function ge({scope:e}){let{t}=o(`integrations`);return(0,I.jsx)(`span`,{className:T(`rounded px-1.5 py-0.5 text-[10px] uppercase tracking-wide`,e===`global`?`bg-accent-primary/10 text-accent-primary`:`bg-accent-info/10 text-accent-info`),children:t(`plugins.scope.${e}`)})}function _e({title:e,detail:t,scope:n}){return(0,I.jsxs)(`div`,{className:`mb-2 flex items-center gap-2`,children:[(0,I.jsx)(`div`,{className:T(`h-px flex-1`,n===`global`?`bg-accent-primary/30`:`bg-accent-info/30`)}),(0,I.jsxs)(`div`,{className:`flex items-center gap-2 rounded-md border border-border bg-card/70 px-2 py-1`,children:[(0,I.jsx)(ge,{scope:n}),(0,I.jsx)(`span`,{className:`text-xs font-medium`,children:e}),(0,I.jsx)(`span`,{className:`hidden text-[11px] text-muted-foreground sm:inline`,children:t})]}),(0,I.jsx)(`div`,{className:T(`h-px flex-1`,n===`global`?`bg-accent-primary/30`:`bg-accent-info/30`)})]})}function ve({plugin:e}){let{t}=o(`integrations`),n=e.icon,r=e.scope===`global`,i=e.status===`attention`,a=e.busy?m:e.actionKind===`install`?f:e.actionKind===`review`?_:P,s=T(`shrink-0 rounded border px-1.5 py-0.5 text-[10px] leading-none`,i?`border-accent-warning/30 bg-accent-warning/10 text-accent-warning`:e.installed?`border-accent-success/25 bg-accent-success/10 text-accent-success`:`border-border bg-muted text-muted-foreground`);return(0,I.jsxs)(`article`,{className:`grid h-[88px] w-full grid-cols-[38px_minmax(0,1fr)_auto] items-center gap-3 rounded-lg border border-border bg-card/70 px-3 transition-colors hover:border-accent-primary/35 hover:bg-card`,children:[(0,I.jsx)(`div`,{className:T(`grid h-[38px] w-[38px] shrink-0 place-items-center rounded-lg border`,r?`border-accent-primary/25 bg-accent-primary/10 text-accent-primary`:`border-accent-info/25 bg-accent-info/10 text-accent-info`),children:(0,I.jsx)(n,{className:`h-4 w-4`})}),(0,I.jsxs)(`div`,{className:`min-w-0`,children:[(0,I.jsx)(`h2`,{className:`truncate text-sm font-semibold leading-5`,children:e.title}),(0,I.jsx)(`p`,{className:`mt-1 truncate text-[11px] leading-4 text-muted-foreground`,children:e.description}),(0,I.jsxs)(`div`,{className:`mt-1.5 flex items-center gap-1.5`,children:[(0,I.jsx)(ge,{scope:e.scope}),(0,I.jsx)(`span`,{className:s,children:e.statusLabel})]})]}),(0,I.jsxs)(`button`,{type:`button`,disabled:e.busy,onClick:e.action,className:`flex h-7 shrink-0 items-center gap-1.5 rounded-md border border-border bg-background px-2.5 text-xs font-medium transition-colors hover:bg-muted disabled:opacity-50`,children:[(0,I.jsx)(a,{className:T(`h-3.5 w-3.5`,e.busy&&`animate-spin`)}),e.busy?t(`plugins.actions.installing`):e.actionLabel]})]})}function ye({state:e,loading:t,busy:n,logs:r,onInstall:i,onToggleProvider:a,onDeactivateAll:s,onUninstall:c,onSetPort:l,onOpenDiagnostics:u}){let{t:d}=o(`integrations`),[p,h]=(0,F.useState)(String(e.port)),[_,y]=(0,F.useState)(!1);(0,F.useEffect)(()=>h(String(e.port)),[e.port]),(0,F.useEffect)(()=>{e.installed||y(!1)},[e.installed]);let b=e.activeProviders.codex||e.activeProviders.claude,x=e.installSource===`system`;return(0,I.jsxs)(`aside`,{className:`w-full min-w-0 overflow-hidden rounded-lg border border-border bg-card/80 p-4`,children:[(0,I.jsxs)(`div`,{className:`mb-4 flex items-start gap-3`,children:[(0,I.jsx)(`div`,{className:`grid h-10 w-10 place-items-center rounded-lg border border-accent-primary/25 bg-accent-primary/10 text-accent-primary`,children:(0,I.jsx)(D,{className:`h-4 w-4`})}),(0,I.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,I.jsx)(`h2`,{className:`text-sm font-semibold`,children:d(`plugins.headroom.title`)}),(0,I.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-muted-foreground`,children:d(`plugins.headroom.panelDescription`)})]})]}),(0,I.jsxs)(`div`,{className:`mb-4 grid grid-cols-3 gap-2 text-xs`,children:[(0,I.jsx)(be,{label:d(`plugins.headroom.metrics.install`),value:t?d(`plugins.headroom.metrics.checking`):e.installed?d(`plugins.headroom.metrics.ready`):d(`plugins.headroom.metrics.missing`),good:e.installed}),(0,I.jsx)(be,{label:d(`plugins.headroom.metrics.source`),value:e.installSource===`system`?d(`plugins.headroom.metrics.system`):e.installSource===`managed`?d(`plugins.headroom.metrics.specrails`):d(`plugins.headroom.metrics.none`),good:e.installed}),(0,I.jsx)(be,{label:d(`plugins.headroom.metrics.proxy`),value:e.proxyRunning?`:${e.port}`:d(b?`plugins.headroom.metrics.starting`:`plugins.headroom.metrics.off`),good:e.proxyRunning||!b})]}),e.lastIssue&&(0,I.jsx)(xe,{issue:e.lastIssue}),e.installed?(0,I.jsxs)(`div`,{className:`mb-4 space-y-2`,children:[(0,I.jsx)(Te,{provider:`codex`,active:e.activeProviders.codex,available:e.availableProviders.codex,detectedRoute:e.detectedRoutes.codex,busy:n===`activate-codex`||n===`deactivate-codex`,onClick:()=>a(`codex`,e.activeProviders.codex)}),(0,I.jsx)(Te,{provider:`claude`,active:e.activeProviders.claude,available:e.availableProviders.claude,detectedRoute:e.detectedRoutes.claude,busy:n===`activate-claude`||n===`deactivate-claude`,onClick:()=>a(`claude`,e.activeProviders.claude)}),b&&(0,I.jsxs)(`button`,{type:`button`,disabled:!!n,onClick:s,className:`flex h-8 w-full items-center justify-center gap-2 rounded-lg border border-border bg-background/45 text-xs hover:bg-muted/50 disabled:opacity-50`,children:[n===`deactivate-all`?(0,I.jsx)(m,{className:`h-3.5 w-3.5 animate-spin`}):(0,I.jsx)(N,{className:`h-3.5 w-3.5`}),d(`plugins.headroom.actions.disableAllRoutes`)]})]}):(0,I.jsxs)(`button`,{type:`button`,disabled:!!n,onClick:i,className:`mb-3 flex h-9 w-full items-center justify-center gap-2 rounded-lg bg-accent-primary px-3 text-xs font-medium text-white disabled:opacity-50`,children:[n===`install`?(0,I.jsx)(m,{className:`h-3.5 w-3.5 animate-spin`}):(0,I.jsx)(f,{className:`h-3.5 w-3.5`}),d(`plugins.headroom.actions.installWithUv`)]}),e.installed&&(0,I.jsx)(Se,{state:e}),(0,I.jsxs)(`div`,{className:`mb-4 rounded-lg border border-border bg-background/45 p-3`,children:[(0,I.jsx)(`label`,{className:`mb-1 block text-[11px] font-medium text-muted-foreground`,children:d(`plugins.headroom.port.label`)}),(0,I.jsxs)(`div`,{className:`flex gap-2`,children:[(0,I.jsx)(`input`,{value:p,onChange:e=>h(e.target.value),className:`h-8 min-w-0 flex-1 rounded-md border border-border bg-background px-2 text-sm`}),(0,I.jsx)(`button`,{type:`button`,disabled:!!n||Number(p)===e.port,onClick:()=>l(Number(p)),className:`rounded-md border border-border px-2 text-xs hover:bg-muted disabled:opacity-50`,children:d(`plugins.headroom.port.apply`)})]})]}),r.length>0&&(0,I.jsx)(`pre`,{className:`mb-3 max-h-32 overflow-y-auto overflow-x-hidden whitespace-pre-wrap break-words rounded-lg border border-border bg-background/60 p-2 text-[10px] text-muted-foreground`,children:r.join(`
|
|
1
|
+
import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-zu2_FqZY.js";import{l as r,r as i,t as a}from"./useSharedWebSocket-DaWuiO0S.js";import{n as o,t as s}from"./createLucideIcon-Bjbbp_KS.js";import{n as c,r as l,s as u}from"./useDesktop-DKNbOF0u.js";import{s as d}from"./provider-capabilities-lePfeT_Y.js";import{t as f}from"./download-CFHyyHcw.js";import{t as p}from"./external-link-D6XxC_Cu.js";import{t as m}from"./loader-circle-DcygOQpC.js";import{t as h}from"./search-Cq_gE3Ik.js";import{t as g}from"./trash-2-BOU3WdZZ.js";import{t as _}from"./triangle-alert-H9T4jAmh.js";import{n as v,t as y}from"./jira-api-Bp0zXwjg.js";import{i as b,l as x,o as S,r as C,t as w}from"./dialog-CMgps2MY.js";import{t as T}from"./utils-BC4DHlz2.js";import{t as E}from"./button-D1xExSTF.js";import{Et as D,Gt as O,Tt as k,U as A,an as ee,bt as te,on as ne,qt as j,vt as re,yt as ie}from"./index-lTGJJTuk.js";var M=s(`earth`,[[`path`,{d:`M21.54 15H17a2 2 0 0 0-2 2v4.54`,key:`1djwo0`}],[`path`,{d:`M7 3.34V5a3 3 0 0 0 3 3a2 2 0 0 1 2 2c0 1.1.9 2 2 2a2 2 0 0 0 2-2c0-1.1.9-2 2-2h3.17`,key:`1tzkfa`}],[`path`,{d:`M11 21.95V18a2 2 0 0 0-2-2a2 2 0 0 1-2-2v-1a2 2 0 0 0-2-2H2.05`,key:`14pb5j`}],[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]),ae=s(`folder-kanban`,[[`path`,{d:`M4 20h16a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.93a2 2 0 0 1-1.66-.9l-.82-1.2A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13c0 1.1.9 2 2 2Z`,key:`1fr9dc`}],[`path`,{d:`M8 10v4`,key:`tgpxqk`}],[`path`,{d:`M12 10v2`,key:`hh53o1`}],[`path`,{d:`M16 10v6`,key:`1d6xys`}]]),N=s(`power`,[[`path`,{d:`M12 2v10`,key:`mnfbl`}],[`path`,{d:`M18.4 6.6a9 9 0 1 1-12.77.04`,key:`obofu9`}]]),P=s(`settings-2`,[[`path`,{d:`M14 17H5`,key:`gfn3mx`}],[`path`,{d:`M19 7h-9`,key:`6i9tg`}],[`circle`,{cx:`17`,cy:`17`,r:`3`,key:`18b49y`}],[`circle`,{cx:`7`,cy:`7`,r:`3`,key:`dfmy0x`}]]),F=e(t(),1),I=n(),oe=[`todo`,`in_progress`,`on_review`,`done`,`cancelled`],se={todo:`todo`,in_progress:`inProgress`,on_review:`onReview`,done:`done`,cancelled:`cancelled`};function L(e){let{activeProjectId:t}=l();return(0,I.jsx)(R,{...e},e.apiBase??t??`legacy`)}function R({onConnected:e,onSkip:t,apiBase:n}){let{t:r}=o(`jira`),[i,a]=(0,F.useState)(1),[s,c]=(0,F.useState)(``),[l,d]=(0,F.useState)(``),[f,p]=(0,F.useState)(``),[m,h]=(0,F.useState)(`idle`),[g,_]=(0,F.useState)(null),[v,b]=(0,F.useState)(`cloud`),[x,S]=(0,F.useState)([]),[C,w]=(0,F.useState)(``),[T,D]=(0,F.useState)(``),[O,k]=(0,F.useState)(``),[ee,te]=(0,F.useState)(!1),[ne,j]=(0,F.useState)([]),[re,ie]=(0,F.useState)({}),[M,ae]=(0,F.useState)(``),[N,P]=(0,F.useState)(!1),[L,R]=(0,F.useState)(!1),H=(0,F.useRef)(0),U=(0,F.useRef)(!0);(0,F.useEffect)(()=>(U.current=!0,()=>{U.current=!1,H.current++}),[]);let[W,ce]=(0,F.useState)(!1),G=()=>({baseUrl:s.trim(),accountEmail:l.trim()||null,token:f});async function le(){h(`testing`);try{let e=await y.test(G(),n);if(!U.current)return;h(`ok`),_(e.displayName),b(e.deployment)}catch(e){if(!U.current)return;h(`error`),u.error(V(e,r))}}async function K(){a(2),te(!0);try{let{projects:e}=await y.discoverProjects({...G(),query:C.trim()||void 0},n);if(!U.current)return;S(e)}catch(e){U.current&&u.error(V(e,r))}finally{U.current&&te(!1)}}async function q(){a(3),await J()}async function J(){if(!T)return;let e=++H.current;P(!0);try{let{statuses:t}=await y.discoverStatuses({...G(),projectKey:T},n);if(!U.current||e!==H.current)return;j(t),R(!1)}catch{U.current&&e===H.current&&R(!0)}finally{U.current&&e===H.current&&P(!1)}}function Y(e,t){e!==T&&(H.current++,j([]),ie({}),ae(``),R(!1),P(!1)),D(e),k(t)}async function ue(){ce(!0);try{let t=Object.fromEntries(Object.entries(re).filter(([,e])=>e));if(await y.connect({...G(),jiraProjectKey:T.trim(),statusMap:Object.keys(t).length?t:null,discardStatus:M.trim()||null},n),!U.current)return;u.success(r(`status.connected`,{key:T.trim()})),e()}catch(e){U.current&&u.error(V(e,r))}finally{U.current&&ce(!1)}}return(0,I.jsxs)(`div`,{className:`space-y-4`,"data-testid":`jira-wizard`,children:[(0,I.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(`wizard.step`,{current:i,total:4})}),t&&(0,I.jsx)(`button`,{type:`button`,onClick:t,className:`text-xs text-muted-foreground hover:text-foreground hover:underline`,"data-testid":`jira-later`,children:r(`wizard.later`)})]}),i===1&&(0,I.jsxs)(`div`,{className:`space-y-3`,children:[(0,I.jsx)(`h3`,{className:`text-sm font-semibold`,children:r(`wizard.step1Title`)}),(0,I.jsx)(z,{label:r(`creds.baseUrlLabel`),help:r(`creds.baseUrlHelp`),children:(0,I.jsx)(A,{value:s,onChange:e=>{c(e.target.value),h(`idle`)},placeholder:r(`creds.baseUrlPlaceholder`)})}),(0,I.jsx)(z,{label:r(`creds.emailLabel`),help:r(`creds.emailHelp`),children:(0,I.jsx)(A,{value:l,onChange:e=>{d(e.target.value),h(`idle`)},placeholder:r(`creds.emailPlaceholder`)})}),(0,I.jsx)(z,{label:r(`creds.tokenLabel`),help:r(`creds.tokenHelp`),children:(0,I.jsx)(A,{type:`password`,value:f,onChange:e=>{p(e.target.value),h(`idle`)}})}),(0,I.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,I.jsx)(E,{size:`sm`,variant:`outline`,onClick:le,disabled:!s.trim()||!f.trim()||m===`testing`,children:r(m===`testing`?`creds.testing`:m===`ok`?`creds.retest`:`creds.test`)}),m===`ok`&&(0,I.jsxs)(`span`,{className:`text-xs text-accent-success`,"data-testid":`jira-test-ok`,children:[`✓ `,r(`creds.testOk`,{name:g??``}),` · `,r(v===`cloud`?`review.cloud`:`review.dc`)]})]}),(0,I.jsx)(`div`,{className:`flex justify-end`,children:(0,I.jsx)(E,{size:`sm`,onClick:K,disabled:m!==`ok`,children:r(`wizard.next`)})})]}),i===2&&(0,I.jsxs)(`div`,{className:`space-y-3`,children:[(0,I.jsx)(`h3`,{className:`text-sm font-semibold`,children:r(`wizard.step2Title`)}),(0,I.jsxs)(`div`,{className:`flex gap-2`,children:[(0,I.jsx)(A,{value:C,onChange:e=>w(e.target.value),placeholder:r(`project.searchPlaceholder`)}),(0,I.jsx)(E,{size:`sm`,variant:`outline`,onClick:K,children:r(`project.searchPlaceholder`)})]}),ee?(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(`project.loading`)}):x.length===0?(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(`project.none`)}):(0,I.jsx)(`div`,{className:`max-h-48 space-y-1 overflow-y-auto`,"data-testid":`jira-project-list`,children:x.map(e=>(0,I.jsxs)(`button`,{type:`button`,onClick:()=>Y(e.key,e.name),className:`flex w-full items-center justify-between rounded px-2 py-1.5 text-left text-sm hover:bg-muted ${T===e.key?`bg-muted`:``}`,children:[(0,I.jsx)(`span`,{className:`font-medium`,children:e.key}),(0,I.jsx)(`span`,{className:`truncate text-xs text-muted-foreground`,children:e.name})]},e.id))}),(0,I.jsx)(z,{label:r(`project.manualLabel`),children:(0,I.jsx)(A,{value:T,onChange:e=>Y(e.target.value.toUpperCase(),``),placeholder:r(`project.manualPlaceholder`)})}),(0,I.jsxs)(`div`,{className:`flex justify-between`,children:[(0,I.jsx)(E,{size:`sm`,variant:`ghost`,onClick:()=>a(1),children:r(`wizard.back`)}),(0,I.jsx)(E,{size:`sm`,onClick:q,disabled:!T.trim(),children:r(`wizard.next`)})]})]}),i===3&&(0,I.jsxs)(`div`,{className:`space-y-3`,children:[(0,I.jsx)(`h3`,{className:`text-sm font-semibold`,children:r(`wizard.step3Title`)}),(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(`mapping.intro`)}),L&&(0,I.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,I.jsx)(`p`,{role:`alert`,className:`text-xs text-accent-warning`,children:r(`mapping.loadFailed`)}),(0,I.jsx)(E,{size:`sm`,variant:`outline`,disabled:N,onClick:()=>void J(),children:r(`mapping.retry`)})]}),N&&(0,I.jsx)(`p`,{role:`status`,className:`text-xs text-muted-foreground`,children:r(`mapping.loading`)}),oe.map(e=>(0,I.jsx)(z,{label:r(`mapping.${se[e]}`),children:(0,I.jsxs)(`select`,{value:re[e]??``,onChange:t=>ie(n=>({...n,[e]:t.target.value||void 0})),className:`w-full rounded-md border border-border bg-background px-2 py-1.5 text-sm`,children:[(0,I.jsx)(`option`,{value:``,children:r(`mapping.auto`)}),ne.map(e=>(0,I.jsx)(`option`,{value:e.name,children:e.name},e.id))]})},e)),(0,I.jsx)(z,{label:r(`discard.configLabel`),help:r(`discard.configHelp`),children:(0,I.jsxs)(`select`,{value:M,onChange:e=>ae(e.target.value),className:`w-full rounded-md border border-border bg-background px-2 py-1.5 text-sm`,"data-testid":`jira-discard-status-select`,children:[(0,I.jsx)(`option`,{value:``,children:r(`discard.configNone`)}),ne.map(e=>(0,I.jsx)(`option`,{value:e.name,children:e.name},e.id))]})}),(0,I.jsxs)(`div`,{className:`flex justify-between`,children:[(0,I.jsx)(E,{size:`sm`,variant:`ghost`,onClick:()=>a(2),children:r(`wizard.back`)}),(0,I.jsx)(E,{size:`sm`,onClick:()=>a(4),children:r(`wizard.next`)})]})]}),i===4&&(0,I.jsxs)(`div`,{className:`space-y-3`,children:[(0,I.jsx)(`h3`,{className:`text-sm font-semibold`,children:r(`wizard.step4Title`)}),(0,I.jsxs)(`dl`,{className:`space-y-1 text-sm`,children:[(0,I.jsx)(B,{label:r(`review.site`),value:s}),(0,I.jsx)(B,{label:r(`review.project`),value:O?`${T} — ${O}`:T}),(0,I.jsx)(B,{label:r(`review.account`),value:g??l}),(0,I.jsx)(B,{label:r(`review.type`),value:r(v===`cloud`?`review.cloud`:`review.dc`)}),(0,I.jsx)(B,{label:r(`discard.reviewLabel`),value:M||r(`discard.configNone`)})]}),(0,I.jsxs)(`div`,{className:`flex justify-between`,children:[(0,I.jsx)(E,{size:`sm`,variant:`ghost`,onClick:()=>a(3),children:r(`wizard.back`)}),(0,I.jsx)(E,{size:`sm`,onClick:ue,disabled:W,children:r(W?`wizard.connecting`:`wizard.connect`)})]})]})]})}function z({label:e,help:t,children:n}){return(0,I.jsxs)(`label`,{className:`block space-y-1`,children:[(0,I.jsx)(`span`,{className:`text-xs font-medium text-foreground`,children:e}),n,t&&(0,I.jsx)(`span`,{className:`block text-[11px] text-muted-foreground`,children:t})]})}function B({label:e,value:t}){return(0,I.jsxs)(`div`,{className:`flex justify-between gap-4`,children:[(0,I.jsx)(`dt`,{className:`text-muted-foreground`,children:e}),(0,I.jsx)(`dd`,{className:`truncate text-right font-medium`,children:t})]})}function V(e,t){return e instanceof Error?e.message:t(`errors.generic`)}var H={pending:0,inflight:0,done:0,dead:0};function U({projectId:e,baseUrl:t,apiBase:n,initialCounts:r,refreshToken:i}){let{t:s}=o(`jira`),[c,l]=(0,F.useState)(null),[d,f]=(0,F.useState)(!1),[p,m]=(0,F.useState)(()=>new Set),h=(0,F.useRef)(!0),g=(0,F.useRef)(0),_=(0,F.useContext)(a),v=(0,F.useId)(),b=(0,F.useCallback)(async()=>{if(!h.current)return;let e=++g.current;try{let t=n?await y.listOutbox(`dead`,n):await y.listOutbox(`dead`);if(!h.current||e!==g.current)return;l({...t,ops:t.ops.filter(e=>e.state===`dead`)}),f(!1)}catch{h.current&&e===g.current&&f(!0)}},[n]);(0,F.useEffect)(()=>(h.current=!0,b(),()=>{h.current=!1,g.current++}),[b,i,r?.dead,r?.pending,r?.inflight,r?.done,r?.superseded]),(0,F.useEffect)(()=>{if(_)return _.registerHandler(v,t=>{if(!t||typeof t!=`object`)return;let n=t;n.type===`jira.outbox_changed`&&n.projectId===e&&b()}),()=>_.unregisterHandler(v)},[_,v,e,b]);async function x(e){if(!p.has(e)){m(t=>new Set(t).add(e));try{n?await y.retryOutbox(e,n):await y.retryOutbox(e),h.current&&await b()}catch(e){h.current&&u.error(e instanceof Error?e.message:s(`errors.generic`))}finally{h.current&&m(t=>{let n=new Set(t);return n.delete(e),n})}}}let S=c?.counts??r??H,C=S.pending+S.inflight;return(0,I.jsxs)(`div`,{className:`rounded-md border border-border p-3`,"data-testid":`jira-outbox`,children:[(0,I.jsx)(`p`,{className:`text-sm font-medium`,children:s(`outbox.title`)}),(0,I.jsx)(`p`,{className:`mt-1 text-xs ${S.dead>0?`text-accent-warning`:`text-muted-foreground`}`,children:S.dead>0?s(`outbox.dead`,{count:S.dead}):C>0?s(`outbox.pending`,{count:C}):s(S.superseded?`outbox.nonePending`:`outbox.allSynced`)}),d&&(0,I.jsxs)(`div`,{className:`mt-2 flex items-center justify-between gap-2`,children:[(0,I.jsx)(`p`,{role:`alert`,className:`text-xs text-accent-warning`,children:s(`outbox.loadFailed`)}),(0,I.jsx)(E,{variant:`outline`,size:`sm`,onClick:()=>void b(),children:s(`outbox.retry`)})]}),!!c?.ops.length&&(0,I.jsxs)(`div`,{className:`mt-2 space-y-2`,children:[(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:s(`outbox.deadHelp`)}),c.ops.map(e=>{let n=e.targetStatus||(e.logicalState?s(`mapping.${W(e.logicalState)}`):null),r=e.deadReason??e.lastError??``;return(0,I.jsxs)(`div`,{className:`flex items-start justify-between gap-2 rounded border border-border/60 px-2 py-2`,children:[(0,I.jsxs)(`div`,{className:`min-w-0 space-y-1 text-xs`,children:[(0,I.jsxs)(`p`,{className:`break-words`,children:[e.jiraKey?(0,I.jsx)(`a`,{href:`${t.replace(/\/$/,``)}/browse/${encodeURIComponent(e.jiraKey)}`,target:`_blank`,rel:`noreferrer`,className:`font-medium text-accent-primary hover:underline`,children:e.jiraKey}):(0,I.jsx)(`span`,{className:`font-medium`,children:s(`outbox.issueFallback`,{id:e.jiraIssueId})}),` · `,s(e.opType===`transition`?`outbox.opTransition`:e.opType===`comment`?`outbox.opComment`:e.opType===`update`?`outbox.opUpdate`:`outbox.opCreate`)]}),n&&(0,I.jsx)(`p`,{className:`break-words text-muted-foreground`,children:s(`outbox.target`,{status:n})}),(0,I.jsx)(`p`,{className:`max-h-32 overflow-y-auto whitespace-pre-wrap break-words text-muted-foreground`,children:r})]}),(0,I.jsx)(E,{className:`shrink-0`,variant:`outline`,size:`sm`,disabled:p.has(e.id),onClick:()=>void x(e.id),children:s(p.has(e.id)?`outbox.retrying`:`outbox.retry`)})]},e.id)})]})]})}function W(e){return e===`in_progress`?`inProgress`:e===`on_review`?`onReview`:e}var ce=[`todo`,`in_progress`,`on_review`,`done`,`cancelled`],G={todo:`todo`,in_progress:`inProgress`,on_review:`onReview`,done:`done`,cancelled:`cancelled`};function le(e){let{activeProjectId:t}=l(),n=`${e.apiBase??t??``}:${e.state.connection.projectId}`;return(0,I.jsx)(K,{...e},n)}function K({state:e,onChanged:t,apiBase:n}){let{t:r}=o(`jira`),i=e.connection,[a,s]=(0,F.useState)(i.enabled),[c,l]=(0,F.useState)(!1),[d,f]=(0,F.useState)(!1),[p,m]=(0,F.useState)(0),[h,g]=(0,F.useState)([]),[_,v]=(0,F.useState)(i.discardStatus??``),[b,x]=(0,F.useState)(i.statusMap??{}),[S,C]=(0,F.useState)(!1),[w,T]=(0,F.useState)(!1),D=(0,F.useRef)(0),O=(0,F.useRef)(!0),k=(0,F.useCallback)(async()=>{let e=++D.current;T(!0);try{let{statuses:t}=await y.listStatuses(n);if(!O.current||e!==D.current)return;g(t),C(!1)}catch{O.current&&e===D.current&&C(!0)}finally{O.current&&e===D.current&&T(!1)}},[n]);(0,F.useEffect)(()=>(O.current=!0,k(),()=>{O.current=!1,D.current++}),[k]);async function A(e){let i=_;v(e);try{if(n?await y.patchConnection({discardStatus:e||null},n):await y.patchConnection({discardStatus:e||null}),!O.current)return;t()}catch(e){if(!O.current)return;v(i),u.error(q(e,r))}}async function ee(e,i){let a=b,o={...b,[e]:i||void 0};x(o);let s=Object.fromEntries(Object.entries(o).filter(([,e])=>e));try{if(n?await y.patchConnection({statusMap:Object.keys(s).length?s:null},n):await y.patchConnection({statusMap:Object.keys(s).length?s:null}),!O.current)return;m(e=>e+1),t()}catch(e){if(!O.current)return;x(a),u.error(q(e,r))}}async function te(){let e=!a;s(e),f(!0);try{n?await y.setEnabled(e,n):await y.setEnabled(e)}catch(t){if(!O.current)return;s(!e),u.error(q(t,r))}finally{O.current&&f(!1)}}async function ne(){l(!0);try{let e=n?await y.syncNow(n):await y.syncNow();if(!O.current)return;u.success(r(`status.syncedToast`,{count:e.upserted})),m(e=>e+1)}catch(e){O.current&&u.error(q(e,r))}finally{O.current&&l(!1)}}async function j(){if(window.confirm(r(`status.disconnectConfirm`))){f(!0);try{if(n?await y.disconnect(n):await y.disconnect(),!O.current)return;u.success(r(`status.disconnectedToast`)),t()}catch(e){O.current&&u.error(q(e,r))}finally{O.current&&f(!1)}}}return(0,I.jsxs)(`div`,{className:`space-y-4`,"data-testid":`jira-connected`,children:[(0,I.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`p`,{className:`text-sm font-medium text-foreground`,children:r(`status.connected`,{key:i.jiraProjectKey})}),(0,I.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[i.baseUrl,` · `,i.deployment===`cloud`?r(`review.cloud`):r(`review.dc`)]})]}),(0,I.jsx)(`a`,{href:`${i.baseUrl}/browse/${i.jiraProjectKey}`,target:`_blank`,rel:`noreferrer`,className:`text-xs text-accent-primary hover:underline`,children:r(`badge.openInJira`)})]}),(0,I.jsxs)(`div`,{className:`flex items-center justify-between rounded-md border border-border p-3`,children:[(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`p`,{className:`text-sm font-medium`,children:r(`status.enabledLabel`)}),(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(a?`status.enabledHelp`:`status.pausedHelp`)})]}),(0,I.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":a,"aria-label":r(`status.enabledLabel`),disabled:d,onClick:te,className:`relative inline-flex h-5 w-9 shrink-0 items-center rounded-full transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 ${a?`bg-accent-success`:`bg-input`}`,children:(0,I.jsx)(`span`,{className:`inline-block h-3.5 w-3.5 rounded-full bg-background shadow-sm transition-transform ${a?`translate-x-4`:`translate-x-0.5`}`})})]}),(0,I.jsxs)(`div`,{className:`rounded-md border border-border p-3`,"data-testid":`jira-status-map`,children:[(0,I.jsx)(`p`,{className:`text-sm font-medium`,children:r(`wizard.step3Title`)}),(0,I.jsx)(`p`,{className:`mt-0.5 mb-2 text-xs text-muted-foreground`,children:r(`mapping.intro`)}),S&&(0,I.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2`,children:[(0,I.jsx)(`p`,{role:`alert`,className:`text-xs text-accent-warning`,children:r(`mapping.loadFailed`)}),(0,I.jsx)(E,{variant:`outline`,size:`sm`,disabled:w,onClick:()=>void k(),children:r(`mapping.retry`)})]}),w&&(0,I.jsx)(`p`,{role:`status`,className:`mb-2 text-xs text-muted-foreground`,children:r(`mapping.loading`)}),(0,I.jsx)(`div`,{className:`space-y-2`,children:ce.map(e=>(0,I.jsxs)(`label`,{className:`flex items-center justify-between gap-3`,children:[(0,I.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:r(`mapping.${G[e]}`)}),(0,I.jsxs)(`select`,{value:b[e]??``,onChange:t=>void ee(e,t.target.value),className:`w-44 rounded-md border border-border bg-background px-2 py-1.5 text-sm`,"data-testid":`jira-statusmap-${e}`,children:[(0,I.jsx)(`option`,{value:``,children:r(`mapping.auto`)}),h.map(e=>(0,I.jsx)(`option`,{value:e.name,children:e.name},e.id)),b[e]&&!h.some(t=>t.name===b[e])&&(0,I.jsx)(`option`,{value:b[e],children:b[e]})]})]},e))})]}),(0,I.jsxs)(`div`,{className:`rounded-md border border-border p-3`,children:[(0,I.jsx)(`p`,{className:`text-sm font-medium`,children:r(`discard.configLabel`)}),(0,I.jsx)(`p`,{className:`mt-0.5 mb-2 text-xs text-muted-foreground`,children:r(`discard.configHelp`)}),(0,I.jsxs)(`select`,{value:_,onChange:e=>void A(e.target.value),className:`w-full rounded-md border border-border bg-background px-2 py-1.5 text-sm`,"data-testid":`jira-discard-status-select`,children:[(0,I.jsx)(`option`,{value:``,children:r(`discard.configNone`)}),h.map(e=>(0,I.jsx)(`option`,{value:e.name,children:e.name},e.id)),_&&!h.some(e=>e.name===_)&&(0,I.jsx)(`option`,{value:_,children:_})]})]}),(0,I.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,I.jsx)(E,{variant:`outline`,size:`sm`,onClick:ne,disabled:c,children:r(c?`status.syncing`:`status.syncNow`)}),(0,I.jsx)(E,{variant:`ghost`,size:`sm`,onClick:j,disabled:d,className:`text-destructive`,children:r(`status.disconnect`)})]}),(0,I.jsx)(U,{projectId:i.projectId,baseUrl:i.baseUrl,apiBase:n,initialCounts:e.outbox,refreshToken:p})]})}function q(e,t){return e instanceof Error?e.message:t(`errors.generic`)}var J=new Set([`claude`,`codex`,`kimi`]);function Y(e){return{provider:e,label:e===`codex`?`Codex`:`Claude`,active:!1,available:!1,detectedRoute:!1,requests:0,inputTokens:0,inputTokensSaved:0,outputTokens:0,outputTokensSaved:0,outputSavingsPercent:0,outputSavingsMethod:`none`,outputSavingsAllocated:!1}}function ue(){return{updatedAt:null,proxyStatsAvailable:!1,durableSavingsAvailable:!1,outputSavingsAvailable:!1,outputSavingsMethod:null,outputConfidence:null,providers:{codex:Y(`codex`),claude:Y(`claude`)},lastIssue:null}}var X={installed:!1,installSource:null,version:null,executablePath:null,uvPath:null,port:8787,phase:`idle`,activeProviders:{codex:!1,claude:!1},availableProviders:{codex:!1,claude:!1},detectedRoutes:{codex:!1,claude:!1},proxyRunning:!1,proxyPid:null,learning:{enabled:!1,baselineReady:!1,baselineSamples:0,updatedAt:null,lastIssue:null},metrics:ue(),lastIssue:null,updatedAt:null};function de(e){let t=e?.metrics??ue();return{...X,...e,activeProviders:{...X.activeProviders,...e?.activeProviders},availableProviders:{...X.availableProviders,...e?.availableProviders},detectedRoutes:{...X.detectedRoutes,...e?.detectedRoutes},learning:{...X.learning,...e?.learning},metrics:{...ue(),...t,providers:{codex:{...Y(`codex`),...t.providers?.codex},claude:{...Y(`claude`),...t.providers?.claude}}}}}async function Z(e){let t=await e.text(),n=t?JSON.parse(t):{};if(!e.ok){let t=n.issue;throw Object.assign(Error(t?.title??n.error??`HTTP ${e.status}`),{payload:n})}return n}function Q(e){return`${r}/api/projects/${e}`}function fe(e,t=`en`){if(!Number.isFinite(e))return`0`;try{return Intl.NumberFormat(t,{notation:`compact`,maximumFractionDigits:1}).format(Math.max(0,e))}catch{return Intl.NumberFormat(`en`,{notation:`compact`,maximumFractionDigits:1}).format(Math.max(0,e))}}function $(e,t,n){return`${fe(e,t)} ${n}`}function pe({onWindowOpened:e}={}){let{t}=o(`integrations`),{projects:n}=l(),{registerHandler:a,unregisterHandler:s}=i(),[c,d]=(0,F.useState)(``),[f,m]=(0,F.useState)(`all`),[g,_]=(0,F.useState)(X),[v,y]=(0,F.useState)(!0),[E,O]=(0,F.useState)(null),[A,j]=(0,F.useState)([]),[M,N]=(0,F.useState)(!1),[P,oe]=(0,F.useState)(!1),[se,L]=(0,F.useState)(null),[R,z]=(0,F.useState)({jira:0,serena:0,projects:0}),B=(0,F.useCallback)(async()=>{try{let e=await fetch(`${r}/api/global-plugins/headroom`).then(e=>Z(e));_(de(e.state))}finally{y(!1)}},[]);(0,F.useEffect)(()=>{B()},[B]),(0,F.useEffect)(()=>(a(`plugins-page`,e=>{let t=e;t.type===`plugin.headroom_progress`&&(t.line&&j(e=>[...e.slice(-80),t.line]),B())}),()=>s(`plugins-page`)),[a,s,B]),(0,F.useEffect)(()=>{let e=!1;async function t(){let t=await Promise.all(n.map(async e=>{let[t,n]=await Promise.all([fetch(`${Q(e.id)}/jira/connection`).then(e=>Z(e)).catch(()=>({connected:!1})),fetch(`${Q(e.id)}/plugins`).then(e=>Z(e)).catch(()=>({plugins:[]}))]),r=n.plugins.find(e=>e.name===`serena`);return{jira:+!!t.connected,serena:r&&r.status!==`not-installed`&&r.status!==`orphan`?1:0}}));e||z({jira:t.reduce((e,t)=>e+t.jira,0),serena:t.reduce((e,t)=>e+t.serena,0),projects:n.length})}return t(),()=>{e=!0}},[n]);async function V(e,t){O(e),j([]);try{let e=(await t()).state;e&&_(de(e))}catch(e){let t=e.payload;t?.state&&_(de(t.state))}finally{O(null),B()}}let H=(0,F.useMemo)(()=>[{id:`headroom-ai`,title:`Headroom AI`,scope:`global`,icon:D,description:t(`plugins.catalog.headroom.description`),installed:g.installed,status:g.lastIssue?`attention`:g.installed?g.activeProviders.codex||g.activeProviders.claude?g.installSource===`system`?`external-active`:`active`:g.installSource===`system`?`external`:`installed`:`available`,statusLabel:g.lastIssue?t(`plugins.status.attention`):g.installed?g.activeProviders.codex||g.activeProviders.claude?g.installSource===`system`?t(`plugins.status.externalActive`):t(`plugins.status.active`):g.installSource===`system`?t(`plugins.status.external`):t(`plugins.status.installed`):t(`plugins.status.available`),actionKind:g.lastIssue?`review`:g.installed?`manage`:`install`,actionLabel:g.lastIssue?t(`plugins.actions.review`):g.installed?t(`plugins.actions.manage`):t(`plugins.actions.install`),busy:E===`install`,action:()=>{if(g.lastIssue||g.installed){N(!0);return}V(`install`,()=>fetch(`${r}/api/global-plugins/headroom/install`,{method:`POST`}).then(e=>Z(e)))}}],[g,E,t]),U=(0,F.useMemo)(()=>[{id:`jira`,title:`Jira`,scope:`project`,icon:ae,description:t(`plugins.catalog.jira.description`),installed:R.jira>0,status:R.jira>0?`configured`:`available`,statusLabel:R.jira>0?t(`plugins.status.configuredCount`,{count:R.jira}):t(`plugins.status.available`),actionKind:R.jira>0?`manage`:`install`,actionLabel:R.jira>0?t(`plugins.actions.manage`):t(`plugins.actions.install`),action:()=>L(`jira`)},{id:`serena`,title:`Serena`,scope:`project`,icon:re,description:t(`plugins.catalog.serena.description`),installed:R.serena>0,status:R.serena>0?`installed`:`available`,statusLabel:R.serena>0?t(`plugins.status.installedCount`,{count:R.serena}):t(`plugins.status.available`),actionKind:R.serena>0?`manage`:`install`,actionLabel:R.serena>0?t(`plugins.actions.manage`):t(`plugins.actions.install`),action:()=>L(`serena`)}],[R,t]),W=c.trim().toLowerCase(),ce=e=>`${e.title} ${e.description} ${e.statusLabel} ${t(`plugins.scope.${e.scope}`)}`.toLowerCase().includes(W),G=[...H,...U].filter(e=>f!==`all`&&e.scope!==f?!1:ce(e)),le=G.filter(e=>e.scope===`global`&&e.installed),K=G.filter(e=>e.scope===`project`&&e.installed),q=G.filter(e=>e.scope===`global`&&!e.installed),J=G.filter(e=>e.scope===`project`&&!e.installed),Y=le.length>0||K.length>0,ue=q.length>0||J.length>0,fe=[g.installed,R.jira>0,R.serena>0].filter(Boolean).length;return(0,I.jsxs)(`div`,{className:`flex h-full flex-col bg-background`,children:[(0,I.jsxs)(`div`,{className:`border-b border-border px-6 py-4`,children:[(0,I.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,I.jsx)(`div`,{className:`grid h-9 w-9 place-items-center rounded-lg border border-accent-primary/25 bg-accent-primary/10 text-accent-primary`,children:(0,I.jsx)(k,{className:`h-4 w-4`})}),(0,I.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,I.jsx)(`h1`,{className:`text-lg font-semibold tracking-normal`,children:t(`plugins.page.title`)}),(0,I.jsx)(`p`,{className:`mt-0.5 text-xs text-muted-foreground`,children:t(`plugins.page.subtitle`)})]}),!ee()&&(0,I.jsxs)(`button`,{type:`button`,onClick:()=>void ne().then(()=>e?.()).catch(e=>u.error(String(e))),className:`inline-flex items-center gap-1.5 rounded-md border border-border px-3 py-2 text-xs hover:bg-muted`,children:[(0,I.jsx)(p,{className:`h-3.5 w-3.5`}),t(`plugins.page.openWindow`)]}),(0,I.jsxs)(`div`,{className:`mr-12 flex items-center gap-2 rounded-lg border border-border bg-card/60 px-3 py-2 text-xs`,children:[(0,I.jsx)(te,{className:`h-3.5 w-3.5 text-accent-success`}),(0,I.jsx)(`span`,{className:`text-muted-foreground`,children:t(`plugins.page.readyCount`,{count:fe})})]})]}),(0,I.jsxs)(`div`,{className:`mt-4 flex flex-col gap-3 md:flex-row md:items-center`,children:[(0,I.jsxs)(`label`,{className:`relative flex-1`,children:[(0,I.jsx)(h,{className:`pointer-events-none absolute left-3 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground`}),(0,I.jsx)(`input`,{value:c,onChange:e=>d(e.target.value),placeholder:t(`plugins.search.placeholder`),className:`h-9 w-full rounded-lg border border-border bg-background pl-9 pr-3 text-sm outline-none transition-colors focus:border-accent-primary/60`})]}),(0,I.jsx)(`div`,{className:`inline-flex h-9 rounded-lg border border-border bg-card p-1`,children:[`all`,`global`,`project`].map(e=>(0,I.jsx)(`button`,{type:`button`,onClick:()=>m(e),className:T(`rounded-md px-3 text-xs capitalize transition-colors`,f===e?`bg-muted text-foreground`:`text-muted-foreground hover:text-foreground`),children:t(`plugins.filters.${e}`)},e))})]})]}),(0,I.jsxs)(`div`,{className:`flex-1 overflow-auto px-6 py-5`,children:[(0,I.jsxs)(`section`,{className:`mb-6`,children:[(0,I.jsxs)(`div`,{className:`mb-3 flex items-center gap-2 text-xs font-medium text-muted-foreground`,children:[(0,I.jsx)(ie,{className:`h-3.5 w-3.5`}),t(`plugins.sections.installed`)]}),Y?(0,I.jsx)(me,{globalPlugins:le,projectPlugins:K}):(0,I.jsx)(he,{text:t(W?`plugins.empty.installedSearch`:`plugins.empty.installed`)})]}),(0,I.jsxs)(`section`,{children:[(0,I.jsxs)(`div`,{className:`mb-3 flex items-center gap-2 text-xs font-medium text-muted-foreground`,children:[(0,I.jsx)(k,{className:`h-3.5 w-3.5`}),t(`plugins.sections.available`)]}),ue?(0,I.jsx)(me,{globalPlugins:q,projectPlugins:J}):(0,I.jsx)(he,{text:t(W?`plugins.empty.availableSearch`:`plugins.empty.allInstalled`)})]})]}),(0,I.jsx)(w,{open:M,onOpenChange:N,children:(0,I.jsxs)(C,{className:`w-[calc(100vw-2rem)] max-w-xl overflow-x-hidden p-4 sm:p-6`,children:[(0,I.jsxs)(S,{children:[(0,I.jsx)(x,{children:t(`plugins.headroom.title`)}),(0,I.jsx)(b,{children:t(`plugins.headroom.dialogDescription`)})]}),(0,I.jsx)(ye,{state:g,loading:v,busy:E,logs:A,onInstall:()=>V(`install`,()=>fetch(`${r}/api/global-plugins/headroom/install`,{method:`POST`}).then(e=>Z(e))),onToggleProvider:(e,t)=>V(`${t?`deactivate`:`activate`}-${e}`,()=>fetch(`${r}/api/global-plugins/headroom/${t?`deactivate`:`activate`}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({provider:e})}).then(e=>Z(e))),onDeactivateAll:()=>V(`deactivate-all`,async()=>{let e={state:g};for(let t of[`codex`,`claude`])g.activeProviders[t]&&(e=await fetch(`${r}/api/global-plugins/headroom/deactivate`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({provider:t})}).then(e=>Z(e)));return e}),onUninstall:()=>V(`uninstall`,()=>fetch(`${r}/api/global-plugins/headroom/uninstall`,{method:`POST`}).then(e=>Z(e))),onSetPort:e=>V(`port`,()=>fetch(`${r}/api/global-plugins/headroom/port`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({port:e})}).then(e=>Z(e))),onOpenDiagnostics:()=>oe(!0)})]})}),(0,I.jsx)(Ee,{plugin:se,projects:n,onClose:()=>L(null)}),(0,I.jsx)(ke,{open:P,onClose:()=>oe(!1)})]})}function me({globalPlugins:e,projectPlugins:t}){let{t:n}=o(`integrations`);return(0,I.jsxs)(`div`,{className:T(`grid grid-cols-1 gap-4`,e.length>0&&t.length>0&&`xl:grid-cols-2`),children:[e.length>0&&(0,I.jsxs)(`section`,{children:[(0,I.jsx)(_e,{title:n(`plugins.groups.global.title`),detail:n(`plugins.groups.global.detail`),scope:`global`}),(0,I.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(260px,320px))] justify-start gap-3`,children:e.map(e=>(0,I.jsx)(ve,{plugin:e},e.id))})]}),t.length>0&&(0,I.jsxs)(`section`,{children:[(0,I.jsx)(_e,{title:n(`plugins.groups.project.title`),detail:n(`plugins.groups.project.detail`),scope:`project`}),(0,I.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(260px,320px))] justify-start gap-3`,children:t.map(e=>(0,I.jsx)(ve,{plugin:e},e.id))})]})]})}function he({text:e}){return(0,I.jsx)(`div`,{className:`flex h-[74px] max-w-[320px] items-center rounded-lg border border-dashed border-border bg-card/35 px-3 text-xs text-muted-foreground`,children:e})}function ge({scope:e}){let{t}=o(`integrations`);return(0,I.jsx)(`span`,{className:T(`rounded px-1.5 py-0.5 text-[10px] uppercase tracking-wide`,e===`global`?`bg-accent-primary/10 text-accent-primary`:`bg-accent-info/10 text-accent-info`),children:t(`plugins.scope.${e}`)})}function _e({title:e,detail:t,scope:n}){return(0,I.jsxs)(`div`,{className:`mb-2 flex items-center gap-2`,children:[(0,I.jsx)(`div`,{className:T(`h-px flex-1`,n===`global`?`bg-accent-primary/30`:`bg-accent-info/30`)}),(0,I.jsxs)(`div`,{className:`flex items-center gap-2 rounded-md border border-border bg-card/70 px-2 py-1`,children:[(0,I.jsx)(ge,{scope:n}),(0,I.jsx)(`span`,{className:`text-xs font-medium`,children:e}),(0,I.jsx)(`span`,{className:`hidden text-[11px] text-muted-foreground sm:inline`,children:t})]}),(0,I.jsx)(`div`,{className:T(`h-px flex-1`,n===`global`?`bg-accent-primary/30`:`bg-accent-info/30`)})]})}function ve({plugin:e}){let{t}=o(`integrations`),n=e.icon,r=e.scope===`global`,i=e.status===`attention`,a=e.busy?m:e.actionKind===`install`?f:e.actionKind===`review`?_:P,s=T(`shrink-0 rounded border px-1.5 py-0.5 text-[10px] leading-none`,i?`border-accent-warning/30 bg-accent-warning/10 text-accent-warning`:e.installed?`border-accent-success/25 bg-accent-success/10 text-accent-success`:`border-border bg-muted text-muted-foreground`);return(0,I.jsxs)(`article`,{className:`grid h-[88px] w-full grid-cols-[38px_minmax(0,1fr)_auto] items-center gap-3 rounded-lg border border-border bg-card/70 px-3 transition-colors hover:border-accent-primary/35 hover:bg-card`,children:[(0,I.jsx)(`div`,{className:T(`grid h-[38px] w-[38px] shrink-0 place-items-center rounded-lg border`,r?`border-accent-primary/25 bg-accent-primary/10 text-accent-primary`:`border-accent-info/25 bg-accent-info/10 text-accent-info`),children:(0,I.jsx)(n,{className:`h-4 w-4`})}),(0,I.jsxs)(`div`,{className:`min-w-0`,children:[(0,I.jsx)(`h2`,{className:`truncate text-sm font-semibold leading-5`,children:e.title}),(0,I.jsx)(`p`,{className:`mt-1 truncate text-[11px] leading-4 text-muted-foreground`,children:e.description}),(0,I.jsxs)(`div`,{className:`mt-1.5 flex items-center gap-1.5`,children:[(0,I.jsx)(ge,{scope:e.scope}),(0,I.jsx)(`span`,{className:s,children:e.statusLabel})]})]}),(0,I.jsxs)(`button`,{type:`button`,disabled:e.busy,onClick:e.action,className:`flex h-7 shrink-0 items-center gap-1.5 rounded-md border border-border bg-background px-2.5 text-xs font-medium transition-colors hover:bg-muted disabled:opacity-50`,children:[(0,I.jsx)(a,{className:T(`h-3.5 w-3.5`,e.busy&&`animate-spin`)}),e.busy?t(`plugins.actions.installing`):e.actionLabel]})]})}function ye({state:e,loading:t,busy:n,logs:r,onInstall:i,onToggleProvider:a,onDeactivateAll:s,onUninstall:c,onSetPort:l,onOpenDiagnostics:u}){let{t:d}=o(`integrations`),[p,h]=(0,F.useState)(String(e.port)),[_,y]=(0,F.useState)(!1);(0,F.useEffect)(()=>h(String(e.port)),[e.port]),(0,F.useEffect)(()=>{e.installed||y(!1)},[e.installed]);let b=e.activeProviders.codex||e.activeProviders.claude,x=e.installSource===`system`;return(0,I.jsxs)(`aside`,{className:`w-full min-w-0 overflow-hidden rounded-lg border border-border bg-card/80 p-4`,children:[(0,I.jsxs)(`div`,{className:`mb-4 flex items-start gap-3`,children:[(0,I.jsx)(`div`,{className:`grid h-10 w-10 place-items-center rounded-lg border border-accent-primary/25 bg-accent-primary/10 text-accent-primary`,children:(0,I.jsx)(D,{className:`h-4 w-4`})}),(0,I.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,I.jsx)(`h2`,{className:`text-sm font-semibold`,children:d(`plugins.headroom.title`)}),(0,I.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-muted-foreground`,children:d(`plugins.headroom.panelDescription`)})]})]}),(0,I.jsxs)(`div`,{className:`mb-4 grid grid-cols-3 gap-2 text-xs`,children:[(0,I.jsx)(be,{label:d(`plugins.headroom.metrics.install`),value:t?d(`plugins.headroom.metrics.checking`):e.installed?d(`plugins.headroom.metrics.ready`):d(`plugins.headroom.metrics.missing`),good:e.installed}),(0,I.jsx)(be,{label:d(`plugins.headroom.metrics.source`),value:e.installSource===`system`?d(`plugins.headroom.metrics.system`):e.installSource===`managed`?d(`plugins.headroom.metrics.specrails`):d(`plugins.headroom.metrics.none`),good:e.installed}),(0,I.jsx)(be,{label:d(`plugins.headroom.metrics.proxy`),value:e.proxyRunning?`:${e.port}`:d(b?`plugins.headroom.metrics.starting`:`plugins.headroom.metrics.off`),good:e.proxyRunning||!b})]}),e.lastIssue&&(0,I.jsx)(xe,{issue:e.lastIssue}),e.installed?(0,I.jsxs)(`div`,{className:`mb-4 space-y-2`,children:[(0,I.jsx)(Te,{provider:`codex`,active:e.activeProviders.codex,available:e.availableProviders.codex,detectedRoute:e.detectedRoutes.codex,busy:n===`activate-codex`||n===`deactivate-codex`,onClick:()=>a(`codex`,e.activeProviders.codex)}),(0,I.jsx)(Te,{provider:`claude`,active:e.activeProviders.claude,available:e.availableProviders.claude,detectedRoute:e.detectedRoutes.claude,busy:n===`activate-claude`||n===`deactivate-claude`,onClick:()=>a(`claude`,e.activeProviders.claude)}),b&&(0,I.jsxs)(`button`,{type:`button`,disabled:!!n,onClick:s,className:`flex h-8 w-full items-center justify-center gap-2 rounded-lg border border-border bg-background/45 text-xs hover:bg-muted/50 disabled:opacity-50`,children:[n===`deactivate-all`?(0,I.jsx)(m,{className:`h-3.5 w-3.5 animate-spin`}):(0,I.jsx)(N,{className:`h-3.5 w-3.5`}),d(`plugins.headroom.actions.disableAllRoutes`)]})]}):(0,I.jsxs)(`button`,{type:`button`,disabled:!!n,onClick:i,className:`mb-3 flex h-9 w-full items-center justify-center gap-2 rounded-lg bg-accent-primary px-3 text-xs font-medium text-white disabled:opacity-50`,children:[n===`install`?(0,I.jsx)(m,{className:`h-3.5 w-3.5 animate-spin`}):(0,I.jsx)(f,{className:`h-3.5 w-3.5`}),d(`plugins.headroom.actions.installWithUv`)]}),e.installed&&(0,I.jsx)(Se,{state:e}),(0,I.jsxs)(`div`,{className:`mb-4 rounded-lg border border-border bg-background/45 p-3`,children:[(0,I.jsx)(`label`,{className:`mb-1 block text-[11px] font-medium text-muted-foreground`,children:d(`plugins.headroom.port.label`)}),(0,I.jsxs)(`div`,{className:`flex gap-2`,children:[(0,I.jsx)(`input`,{value:p,onChange:e=>h(e.target.value),className:`h-8 min-w-0 flex-1 rounded-md border border-border bg-background px-2 text-sm`}),(0,I.jsx)(`button`,{type:`button`,disabled:!!n||Number(p)===e.port,onClick:()=>l(Number(p)),className:`rounded-md border border-border px-2 text-xs hover:bg-muted disabled:opacity-50`,children:d(`plugins.headroom.port.apply`)})]})]}),r.length>0&&(0,I.jsx)(`pre`,{className:`mb-3 max-h-32 overflow-y-auto overflow-x-hidden whitespace-pre-wrap break-words rounded-lg border border-border bg-background/60 p-2 text-[10px] text-muted-foreground`,children:r.join(`
|
|
2
2
|
`)}),(0,I.jsxs)(`button`,{type:`button`,onClick:u,className:`mb-2 flex h-8 w-full items-center justify-center gap-2 rounded-lg border border-border text-xs hover:bg-muted/50`,children:[(0,I.jsx)(v,{className:`h-3.5 w-3.5`}),d(`plugins.headroom.actions.viewDiagnostics`)]}),e.installed&&(0,I.jsx)(`div`,{className:`rounded-lg border border-destructive/25 bg-destructive/5 p-3`,children:_?(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(`p`,{className:`text-[11px] leading-relaxed text-muted-foreground`,children:d(x?`plugins.headroom.confirmDetach`:`plugins.headroom.confirmUninstall`)}),(0,I.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,I.jsx)(`button`,{type:`button`,disabled:!!n,onClick:()=>y(!1),className:`h-8 rounded-md border border-border text-xs hover:bg-muted/50 disabled:opacity-50`,children:d(`plugins.actions.cancel`)}),(0,I.jsxs)(`button`,{type:`button`,disabled:!!n,onClick:c,className:`flex h-8 items-center justify-center gap-2 rounded-md bg-destructive px-2 text-xs font-medium text-destructive-foreground disabled:opacity-50`,children:[n===`uninstall`?(0,I.jsx)(m,{className:`h-3.5 w-3.5 animate-spin`}):(0,I.jsx)(g,{className:`h-3.5 w-3.5`}),d(x?`plugins.headroom.actions.detach`:`plugins.headroom.actions.uninstall`)]})]})]}):(0,I.jsxs)(`button`,{type:`button`,disabled:!!n,onClick:()=>y(!0),className:`flex h-8 w-full items-center justify-center gap-2 rounded-md text-xs font-medium text-destructive hover:bg-destructive/10 disabled:opacity-50`,children:[(0,I.jsx)(g,{className:`h-3.5 w-3.5`}),d(x?`plugins.headroom.actions.detachHeadroom`:`plugins.headroom.actions.uninstallHeadroom`)]})})]})}function be({label:e,value:t,good:n}){return(0,I.jsxs)(`div`,{className:`rounded-lg border border-border bg-background/45 p-2`,children:[(0,I.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:e}),(0,I.jsx)(`div`,{className:T(`mt-0.5 font-medium`,n?`text-foreground`:`text-accent-warning`),children:t})]})}function xe({issue:e}){let{t}=o(`integrations`),n=`plugins.headroom.issues.${e.code}`,r=t(`${n}.title`,{defaultValue:e.title}),i=t(`${n}.guidance`,{defaultValue:e.guidance});return(0,I.jsx)(`div`,{className:`mb-3 rounded-lg border border-accent-warning/35 bg-accent-warning/10 p-3`,children:(0,I.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,I.jsx)(_,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-accent-warning`}),(0,I.jsxs)(`div`,{className:`min-w-0`,children:[(0,I.jsx)(`div`,{className:`text-xs font-medium`,children:r}),(0,I.jsx)(`p`,{className:`mt-1 text-[11px] leading-relaxed text-muted-foreground`,children:i}),(0,I.jsx)(`div`,{className:`mt-1 text-[10px] text-muted-foreground`,children:t(`plugins.headroom.issueCode`,{code:e.code})})]})]})})}function Se({state:e}){let{t,i18n:n}=o(`integrations`),r=e.metrics,i=r.outputSavingsAvailable,a=[`codex`,`claude`].map(e=>({provider:e,metric:r.providers[e]})),s=t(`plugins.headroom.savings.tokens`),c=a.reduce((e,{metric:t})=>({inputTokens:e.inputTokens+t.inputTokens,inputTokensSaved:e.inputTokensSaved+t.inputTokensSaved,outputTokens:e.outputTokens+t.outputTokens,outputTokensSaved:e.outputTokensSaved+t.outputTokensSaved}),{inputTokens:0,inputTokensSaved:0,outputTokens:0,outputTokensSaved:0}),l=a.some(({metric:e})=>e.inputTokensSaved>0),u=a.some(({metric:e})=>e.active),d=t(i?`plugins.headroom.savings.statusInputOutput`:l?`plugins.headroom.savings.statusInputOnly`:u?`plugins.headroom.savings.statusRouting`:`plugins.headroom.savings.statusInactive`),f=i||l;return(0,I.jsxs)(`div`,{className:`mb-4 rounded-lg border border-border bg-background/45 p-3`,children:[(0,I.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2`,children:[(0,I.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,I.jsx)(j,{className:`h-3.5 w-3.5 text-accent-primary`}),(0,I.jsx)(`div`,{className:`truncate text-xs font-medium`,children:t(`plugins.headroom.savings.title`)})]}),(0,I.jsx)(`span`,{className:T(`shrink-0 rounded border px-1.5 py-0.5 text-[10px]`,f?`border-accent-success/25 bg-accent-success/10 text-accent-success`:u?`border-accent-primary/25 bg-accent-primary/10 text-accent-primary`:`border-border bg-muted text-muted-foreground`),children:d})]}),(0,I.jsxs)(`div`,{className:`mb-2 rounded-md bg-muted/35 px-2.5 py-2`,children:[(0,I.jsx)(`div`,{className:`mb-1.5 text-[10px] font-medium uppercase text-muted-foreground`,children:t(`plugins.headroom.savings.totals`)}),(0,I.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,I.jsx)(Ce,{label:t(`plugins.headroom.savings.input`),processed:c.inputTokens>0?$(c.inputTokens,n.language,s):t(`plugins.headroom.savings.noData`),saved:$(c.inputTokensSaved,n.language,s)}),(0,I.jsx)(Ce,{align:`right`,label:t(`plugins.headroom.savings.output`),processed:c.outputTokens>0?$(c.outputTokens,n.language,s):t(`plugins.headroom.savings.noData`),saved:i?$(c.outputTokensSaved,n.language,s):t(`plugins.headroom.savings.noData`)})]})]}),(0,I.jsx)(`div`,{className:`grid gap-2`,children:a.map(({provider:e,metric:t})=>(0,I.jsx)(we,{metric:t,outputAvailable:r.outputSavingsAvailable},e))}),(0,I.jsx)(`div`,{className:`mt-2 flex items-center justify-end gap-2 text-[10px] text-muted-foreground`,children:r.updatedAt?t(`plugins.headroom.savings.updatedLive`):t(`plugins.headroom.savings.baselineSamples`,{count:e.learning.baselineSamples})})]})}function Ce({label:e,processed:t,saved:n,detail:r,align:i=`left`}){let{t:a}=o(`integrations`);return(0,I.jsxs)(`div`,{className:T(`min-w-0`,i===`right`&&`text-right`),children:[(0,I.jsx)(`div`,{className:`text-[10px] font-medium uppercase text-muted-foreground`,children:e}),(0,I.jsxs)(`div`,{className:`mt-1 space-y-0.5 text-[11px]`,children:[(0,I.jsxs)(`div`,{className:`flex min-w-0 items-baseline justify-between gap-2`,children:[(0,I.jsx)(`span`,{className:`shrink-0 text-muted-foreground`,children:a(`plugins.headroom.savings.processed`)}),(0,I.jsx)(`span`,{className:`truncate font-semibold tabular-nums text-foreground`,children:t})]}),(0,I.jsxs)(`div`,{className:`flex min-w-0 items-baseline justify-between gap-2`,children:[(0,I.jsx)(`span`,{className:`shrink-0 text-muted-foreground`,children:a(`plugins.headroom.savings.saved`)}),(0,I.jsx)(`span`,{className:`truncate font-semibold tabular-nums text-foreground`,children:n})]})]}),r&&(0,I.jsx)(`div`,{className:`mt-1 truncate text-[10px] text-muted-foreground`,children:r})]})}function we({metric:e,outputAvailable:t}){let{t:n,i18n:r}=o(`integrations`),i=!e.available,a=i||!e.active,s=n(`plugins.headroom.savings.tokens`),c=e.inputTokens>0?$(e.inputTokens,r.language,s):n(`plugins.headroom.savings.noData`),l=$(e.inputTokensSaved,r.language,s),u=e.outputTokens>0?$(e.outputTokens,r.language,s):n(`plugins.headroom.savings.noData`),d=t?$(e.outputTokensSaved,r.language,s):e.active?n(`plugins.headroom.savings.noData`):n(`plugins.headroom.savings.off`),f=e.requests>0?n(`plugins.headroom.savings.requestCount`,{count:fe(e.requests,r.language)}):i?n(`plugins.headroom.provider.noProjectUsesProvider`):e.active?n(`plugins.headroom.savings.inputSavingsActive`):n(`plugins.headroom.savings.routeDisabled`);return(0,I.jsxs)(`div`,{className:T(`rounded-md border border-border bg-card/45 px-2.5 py-2`,a&&`opacity-70`),children:[(0,I.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5`,children:[(0,I.jsx)(`span`,{className:`text-xs font-medium`,children:e.label}),e.detectedRoute&&(0,I.jsx)(`span`,{className:`rounded bg-accent-primary/10 px-1.5 py-0.5 text-[9px] uppercase text-accent-primary`,children:n(`plugins.headroom.savings.detected`)})]}),(0,I.jsx)(`div`,{className:`mt-0.5 truncate text-[10px] text-muted-foreground`,children:f}),(0,I.jsxs)(`div`,{className:`mt-2 grid grid-cols-2 gap-3`,children:[(0,I.jsx)(Ce,{label:n(`plugins.headroom.savings.input`),processed:c,saved:l}),(0,I.jsx)(Ce,{align:`right`,label:n(`plugins.headroom.savings.output`),processed:u,saved:d})]})]})}function Te({provider:e,active:t,available:n,detectedRoute:r,busy:i,onClick:a}){let{t:s}=o(`integrations`),c=s(n?t?`plugins.headroom.provider.routedThroughHeadroom`:r?`plugins.headroom.provider.detectedExternalRoute`:`plugins.headroom.provider.notRouted`:`plugins.headroom.provider.noProjectUsesProvider`);return(0,I.jsxs)(`button`,{type:`button`,onClick:a,disabled:i||!n,className:`flex w-full items-center gap-3 rounded-lg border border-border bg-background/45 p-3 text-left hover:bg-muted/35 disabled:opacity-50`,children:[(0,I.jsx)(`div`,{className:T(`grid h-8 w-8 place-items-center rounded-md`,t?`bg-accent-success/15 text-accent-success`:`bg-muted text-muted-foreground`),children:i?(0,I.jsx)(m,{className:`h-3.5 w-3.5 animate-spin`}):(0,I.jsx)(M,{className:`h-3.5 w-3.5`})}),(0,I.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,I.jsx)(`div`,{className:`text-xs font-medium capitalize`,children:e}),(0,I.jsx)(`div`,{className:`text-[11px] text-muted-foreground`,children:c})]}),(0,I.jsx)(`span`,{className:T(`h-5 w-9 rounded-full p-0.5 transition-colors`,t?`bg-accent-success`:`bg-muted`),children:(0,I.jsx)(`span`,{className:T(`block h-4 w-4 rounded-full bg-white shadow transition-transform`,t&&`translate-x-4`)})})]})}function Ee({plugin:e,projects:t,onClose:n}){let{t:r}=o(`integrations`),[i,a]=(0,F.useState)(``);(0,F.useEffect)(()=>a(``),[e]);let s=t.find(e=>e.id===i)??null;return(0,I.jsx)(w,{open:!!e,onOpenChange:e=>{e||n()},children:(0,I.jsxs)(C,{className:`w-[calc(100vw-2rem)] max-w-3xl overflow-x-hidden p-4 sm:p-6`,children:[(0,I.jsxs)(S,{children:[(0,I.jsx)(x,{children:r(e===`jira`?`plugins.projectWizard.configureJira`:`plugins.projectWizard.installSerena`)}),(0,I.jsx)(b,{children:r(`plugins.projectWizard.description`)})]}),(0,I.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-[260px_minmax(0,1fr)]`,children:[(0,I.jsxs)(`div`,{className:`rounded-lg border border-border bg-card/70 p-3`,children:[(0,I.jsx)(`div`,{className:`mb-2 text-xs font-medium text-muted-foreground`,children:r(`plugins.projectWizard.chooseProject`)}),(0,I.jsx)(`div`,{className:`max-h-[52vh] space-y-1 overflow-auto`,children:t.map(t=>{let n=e===`serena`&&!c(t).some(e=>J.has(e));return(0,I.jsxs)(`button`,{type:`button`,disabled:n,onClick:()=>a(t.id),className:T(`w-full rounded-md px-2 py-2 text-left transition-colors`,t.id===i?`bg-muted text-foreground`:`text-muted-foreground hover:bg-muted/45 hover:text-foreground`,n&&`cursor-not-allowed opacity-45`),children:[(0,I.jsx)(`div`,{className:`truncate text-xs font-medium`,children:t.name}),(0,I.jsx)(`div`,{className:`truncate text-[10px]`,children:n?r(`plugins.projectWizard.requiresSupportedProvider`,{defaultValue:`Requires Claude or Codex`}):t.path})]},t.id)})})]}),(0,I.jsx)(`div`,{className:`min-h-[360px] rounded-lg border border-border bg-card/70 p-4`,children:s?e===`jira`?(0,I.jsx)(De,{project:s,onDone:n}):(0,I.jsx)(Oe,{project:s,onDone:n}):(0,I.jsx)(`div`,{className:`flex h-full items-center justify-center text-sm text-muted-foreground`,children:r(`plugins.projectWizard.selectProjectToContinue`)})})]})]})})}function De({project:e,onDone:t}){let{t:n}=o(`integrations`),r=Q(e.id),[i,a]=(0,F.useState)(null),[s,c]=(0,F.useState)(!0),[l,u]=(0,F.useState)(null),d=(0,F.useCallback)(async()=>{c(!0),u(null);try{let e=await fetch(`${r}/jira/connection`).then(e=>Z(e));a(e)}catch(e){a({connected:!1}),u(e.message)}finally{c(!1)}},[r]);return(0,F.useEffect)(()=>{d()},[d]),s?(0,I.jsxs)(`div`,{className:`flex h-full items-center justify-center text-sm text-muted-foreground`,children:[(0,I.jsx)(m,{className:`mr-2 h-4 w-4 animate-spin`}),n(`plugins.jira.loading`,{defaultValue:`Loading Jira...`})]}):i?.connected&&i.connection?(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`h3`,{className:`text-sm font-semibold`,children:n(`plugins.jira.titleForProject`,{name:e.name,defaultValue:`Jira for ${e.name}`})}),(0,I.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:n(`plugins.jira.configuredDescription`,{defaultValue:`Manage the Jira project, status mapping, discard status, sync, and connection state.`})})]}),(0,I.jsx)(le,{state:i,apiBase:r,onChanged:()=>{d()}})]}):(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`h3`,{className:`text-sm font-semibold`,children:n(`plugins.jira.titleForProject`,{name:e.name,defaultValue:`Jira for ${e.name}`})}),(0,I.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:l?n(`plugins.jira.loadFailed`,{message:l,defaultValue:`Could not load the current Jira configuration: ${l}`}):n(`plugins.jira.notConfiguredDescription`,{defaultValue:`Connect this project to Jira.`})})]}),(0,I.jsx)(L,{apiBase:r,onConnected:()=>{d()},onSkip:t})]})}function Oe({project:e,onDone:t}){let{t:n}=o(`integrations`),r=(0,F.useMemo)(()=>c(e).filter(e=>J.has(e)),[e]),i=r.includes(e.provider)?e.provider:r[0]??e.provider,[a,s]=(0,F.useState)(i),[l,u]=(0,F.useState)(null),[p,h]=(0,F.useState)(null),[g,v]=(0,F.useState)(!1),[y,b]=(0,F.useState)(null),x=(0,F.useRef)(0);(0,F.useEffect)(()=>{s(i),u(null),h(null)},[e.id,i]);let S=(0,F.useCallback)(async()=>{let t=++x.current;b(null);try{let n=`?provider=${encodeURIComponent(a)}`,r=await fetch(`${Q(e.id)}/plugins${n}`).then(e=>Z(e));if(t!==x.current)return;let i=r.plugins.find(e=>e.name===`serena`)??null;if(u(i),h(null),i?.status===`not-installed`){let r=await fetch(`${Q(e.id)}/plugins/serena/preview-install${n}`).then(e=>Z(e));t===x.current&&h(r)}}catch(e){t===x.current&&b(e.message)}},[e.id,a]);(0,F.useEffect)(()=>{S()},[S]);async function C(){v(!0),b(null);try{await fetch(`${Q(e.id)}/plugins/serena/install`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({provider:a})}).then(e=>Z(e)),await S(),t()}catch(e){b(e.message)}finally{v(!1)}}let w=(p?.requirements??[]).every(e=>e.installed&&e.executable&&e.meetsMinimum),T=l?n(`plugins.projectStatus.${l.status}`,{defaultValue:l.status}):``,E=l?.name===`serena`?n(`plugins.catalog.serena.description`):l?.description;return!l&&!y?(0,I.jsxs)(`div`,{className:`flex h-full items-center justify-center text-sm text-muted-foreground`,children:[(0,I.jsx)(m,{className:`mr-2 h-4 w-4 animate-spin`}),` `,n(`plugins.serena.loading`)]}):(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`h3`,{className:`text-sm font-semibold`,children:n(`plugins.serena.titleForProject`,{name:e.name})}),(0,I.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:n(`plugins.serena.description`)})]}),(0,I.jsxs)(`label`,{className:`block space-y-1`,children:[(0,I.jsx)(`span`,{className:`text-xs font-medium`,children:n(`plugins.serena.provider`,{defaultValue:`AI provider`})}),(0,I.jsx)(`select`,{"aria-label":n(`plugins.serena.provider`,{defaultValue:`AI provider`}),value:a,disabled:g,onChange:e=>{u(null),h(null),s(e.target.value)},className:`w-full rounded-md border border-border bg-background px-2 py-1.5 text-xs`,children:r.map(e=>(0,I.jsx)(`option`,{value:e,children:d(e)},e))})]}),l&&(0,I.jsxs)(`div`,{className:`rounded-lg border border-border bg-background/45 p-3`,children:[(0,I.jsx)(`div`,{className:`text-xs font-medium`,children:n(`plugins.serena.status`,{status:T})}),E&&(0,I.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:E})]}),p&&(0,I.jsxs)(`div`,{className:`space-y-3`,children:[(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`div`,{className:`mb-1 text-xs font-medium`,children:n(`plugins.serena.files`)}),(0,I.jsx)(`ul`,{className:`space-y-1 text-xs font-mono`,children:p.files.map(e=>(0,I.jsxs)(`li`,{className:e.op===`create`?`text-accent-success`:`text-accent-info`,children:[e.op===`create`?`+ `:`~ `,e.path]},e.path))})]}),(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`div`,{className:`mb-1 text-xs font-medium`,children:n(`plugins.serena.prerequisites`)}),(0,I.jsx)(`ul`,{className:`space-y-1 text-xs`,children:p.requirements.map(e=>(0,I.jsxs)(`li`,{className:`flex items-center gap-2`,children:[e.installed&&e.executable&&e.meetsMinimum?(0,I.jsx)(O,{className:`h-3 w-3 text-accent-success`}):(0,I.jsx)(_,{className:`h-3 w-3 text-accent-warning`}),(0,I.jsxs)(`span`,{children:[e.name,e.minVersion?` >= ${e.minVersion}`:``]}),e.version&&(0,I.jsxs)(`span`,{className:`text-muted-foreground`,children:[`(`,e.version,`)`]})]},e.name))})]})]}),y&&(0,I.jsx)(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/10 p-3 text-xs text-destructive`,children:y}),(0,I.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,I.jsx)(`button`,{type:`button`,onClick:t,className:`rounded-md border border-border px-3 py-1.5 text-xs`,children:n(`plugins.actions.cancel`)}),(0,I.jsxs)(`button`,{type:`button`,disabled:g||l?.status!==`not-installed`||!w,onClick:C,className:`flex items-center gap-2 rounded-md bg-accent-primary px-3 py-1.5 text-xs text-white disabled:opacity-50`,children:[g?(0,I.jsx)(m,{className:`h-3.5 w-3.5 animate-spin`}):(0,I.jsx)(f,{className:`h-3.5 w-3.5`}),n(`plugins.actions.install`)]})]})]})}function ke({open:e,onClose:t}){let{t:n}=o(`integrations`),[i,a]=(0,F.useState)(null);return(0,F.useEffect)(()=>{e&&fetch(`${r}/api/global-plugins/headroom/diagnostics`).then(e=>Z(e)).then(a).catch(e=>a({error:e.message}))},[e]),(0,I.jsx)(w,{open:e,onOpenChange:e=>{e||t()},children:(0,I.jsxs)(C,{className:`max-w-3xl`,children:[(0,I.jsxs)(S,{children:[(0,I.jsxs)(x,{className:`flex items-center gap-2`,children:[(0,I.jsx)(P,{className:`h-4 w-4`}),` `,n(`plugins.diagnostics.title`)]}),(0,I.jsx)(b,{children:n(`plugins.diagnostics.description`)})]}),(0,I.jsx)(`pre`,{className:`max-h-[62vh] overflow-y-auto overflow-x-hidden whitespace-pre-wrap break-words rounded-lg border border-border bg-background p-3 text-xs`,children:JSON.stringify(i,null,2)})]})})}export{pe as default};
|