specrails-desktop 2.63.0 → 2.63.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/dist/assets/{ActivityFeedPage-Bn2MpG5M.js → ActivityFeedPage-B1bpTy7O.js} +1 -1
- package/client/dist/assets/{AgentBrowserCapture-CHlXWdXq.js → AgentBrowserCapture-BussBbN3.js} +1 -1
- package/client/dist/assets/{AgentModeAnalyticsPane-yj-YCgrK.js → AgentModeAnalyticsPane-BiT1n3BU.js} +2 -2
- package/client/dist/assets/{AgentModeCodePane-Xczcyghb.js → AgentModeCodePane-CUjNfeKa.js} +2 -2
- package/client/dist/assets/{AgentModeJobsPane-DtOW01ln.js → AgentModeJobsPane-RVEwyS59.js} +1 -1
- package/client/dist/assets/{AgentsPage-BMfJ4mzU.js → AgentsPage-DKE-eMC5.js} +1 -1
- package/client/dist/assets/{AnalyticsPage-CGn5cgtc.js → AnalyticsPage-Bser2Ly3.js} +1 -1
- package/client/dist/assets/{CodePage-C8NIginr.js → CodePage-BK0grm6e.js} +1 -1
- package/client/dist/assets/{DesktopAnalyticsPage-C87r4y26.js → DesktopAnalyticsPage-DEBidZbs.js} +1 -1
- package/client/dist/assets/{DocsDialog-Z50a_KPv.js → DocsDialog-Dhyo57n9.js} +1 -1
- package/client/dist/assets/{DocsPage-DIArbEPl.js → DocsPage-BcEkPXd6.js} +1 -1
- package/client/dist/assets/{ExportDropdown-CJdCqYd7.js → ExportDropdown-mRmqdkjr.js} +1 -1
- package/client/dist/assets/{InteractiveJobComposer-BxLh4me-.js → InteractiveJobComposer-BlCe3vrU.js} +1 -1
- package/client/dist/assets/{JobDetailModal-C7dWoRu6.js → JobDetailModal-CkAejD1F.js} +1 -1
- package/client/dist/assets/{JobDetailPage-Ilu294WS.js → JobDetailPage-P-FS_lKz.js} +1 -1
- package/client/dist/assets/{JobsPage-fPq1hefb.js → JobsPage-CoUXgYse.js} +1 -1
- package/client/dist/assets/LoopBuilderPage-iFylNk68.js +1 -0
- package/client/dist/assets/{LoopPreviewModal-ChI3NQC7.js → LoopPreviewModal-4obS_Ptg.js} +1 -1
- package/client/dist/assets/{LoopWindowSurface-D1WB9i-9.js → LoopWindowSurface-CLr5OPqj.js} +1 -1
- package/client/dist/assets/{LoopsPage-CCwc0Biu.js → LoopsPage-eKpWFtCp.js} +1 -1
- package/client/dist/assets/{MinimizedChatsContext-eH_KaAZ1.js → MinimizedChatsContext-BHIUPVmC.js} +1 -1
- package/client/dist/assets/{PluginsPage-DfDfEfbW.js → PluginsPage-BgTC2CQx.js} +1 -1
- package/client/dist/assets/{ProjectSettingsDialog-9NHnG8JQ.js → ProjectSettingsDialog-B4chTfU8.js} +1 -1
- package/client/dist/assets/{RepositoryDeliveries-DgzNnJmn.js → RepositoryDeliveries-DAIxIYsl.js} +1 -1
- package/client/dist/assets/{RepositoryScopeSelector-BSgUqk_u.js → RepositoryScopeSelector-DeCoUsRN.js} +1 -1
- package/client/dist/assets/{ReviewPacketPage-D34bGpSA.js → ReviewPacketPage-Cktv0-9b.js} +1 -1
- package/client/dist/assets/{TemplatePreviewModal-CcfSxWQ7.js → TemplatePreviewModal-BZTV1TM1.js} +1 -1
- package/client/dist/assets/{TicketDetailModalContext-BoafEcm4.js → TicketDetailModalContext-DiPngt2g.js} +1 -1
- package/client/dist/assets/{Trans-CVSryAL1.js → Trans-ZiXIfj50.js} +1 -1
- package/client/dist/assets/{agentRuntime-TKQyg137.js → agentRuntime-BDvbJMmS.js} +1 -1
- package/client/dist/assets/{agentRuntime-DvhEe1um.js → agentRuntime-BKJfv5YD.js} +1 -1
- package/client/dist/assets/{agentRuntime-DxC6-9rN.js → agentRuntime-BxF81z52.js} +1 -1
- package/client/dist/assets/{agentRuntime-C_yLPKDy.js → agentRuntime-BxYS5V7u.js} +1 -1
- package/client/dist/assets/{agentRuntime-WSv8G0pW.js → agentRuntime-BzuwQQgn.js} +1 -1
- package/client/dist/assets/{agentRuntime-D2kYQqNO.js → agentRuntime-Dc9HG3BA.js} +1 -1
- package/client/dist/assets/{agentRuntime-Bjt7Ij6_.js → agentRuntime-DiCldqGG.js} +1 -1
- package/client/dist/assets/{agentRuntime-B-myNBUP.js → agentRuntime-es2ymSl-.js} +1 -1
- package/client/dist/assets/{formatDistanceToNow-NVM6rK3i.js → formatDistanceToNow-CdN5lTyD.js} +1 -1
- package/client/dist/assets/{getTimezoneOffsetInMilliseconds-ZHg7WpdH.js → getTimezoneOffsetInMilliseconds-62h40I4t.js} +1 -1
- package/client/dist/assets/index-BgbCbIua.css +2 -0
- package/client/dist/assets/{index-Culan6y7.js → index-CECj3joE.js} +7 -7
- package/client/dist/assets/{jira-api-Bl8xEIpk.js → jira-api-C_D_RDhl.js} +1 -1
- package/client/dist/assets/{project-repositories-CvJf1a6H.js → project-repositories-Be0CWklo.js} +1 -1
- package/client/dist/assets/{spending-BfjSJjBd.js → spending-eWiZGhC_.js} +1 -1
- package/client/dist/assets/{useDesktop-C5JVBeur.js → useDesktop-C0mRIlHT.js} +1 -1
- package/client/dist/assets/{useRuntimeRuns-DohBmeg8.js → useRuntimeRuns-B1a6GChu.js} +1 -1
- package/client/dist/assets/{useSharedWebSocket-CNOvmgTr.js → useSharedWebSocket-CcsE5986.js} +2 -2
- package/client/dist/index.html +16 -16
- package/docs/internals/core-runtime-updates.md +3 -3
- package/docs/internals/desktop-owned-workflows.md +10 -0
- package/docs/internals/programmatic-agent-runtime.md +16 -0
- package/docs/internals/source-map.md +4 -1
- package/package.json +1 -1
- package/server/dist/mcp/tools/loops.js +1 -1
- package/server/dist/modules/agent-runtime/runtime/agent-runtime-bridge.js +13 -3
- package/server/dist/modules/delivery/runtime/rail-isolated-launch.js +1 -1
- package/server/dist/modules/loops/runtime/loop-implement-recipe.js +13 -6
- package/server/dist/modules/loops/runtime/loop-turn-limits.js +64 -0
- package/server/dist/modules/loops/runtime/loops-router.js +3 -1
- package/server/dist/modules/missions/runtime/agent-operator-prompt.js +8 -0
- package/server/dist/schemas/agent-runtime.schema.json +1 -1
- package/client/dist/assets/LoopBuilderPage-5M7IypEP.js +0 -1
- package/client/dist/assets/index-D1v33giW.css +0 -2
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-BbYvbtY8.js";import{d as r,u as i}from"./chunk-OB3PAWPO-B1EMk45A.js";import{n as a,t as o}from"./createLucideIcon-DtODIU64.js";import{a as s,r as c,s as l}from"./useDesktop-C5JVBeur.js";import{r as u}from"./provider-capabilities-lePfeT_Y.js";import{n as d,t as f}from"./save-LmPSfsvZ.js";import{t as p}from"./external-link-CZ6Q-v1-.js";import{t as m}from"./git-branch-yf6LE1Bw.js";import{n as h,t as g}from"./square-D0JTbRSR.js";import{t as _}from"./plus-fHDdjBk1.js";import{t as v}from"./rotate-ccw-DalJAQQX.js";import{t as y}from"./trash-D8zYUmTg.js";import{t as ee}from"./triangle-alert-Cxpn8bqr.js";import{t as te}from"./upload-CCHvUkRs.js";import{t as b}from"./x-Bu7X_eR2.js";import{a as ne,i as re,l as ie,o as ae,r as x,t as S}from"./dialog-DtdR05v1.js";import{t as C}from"./utils-BC4DHlz2.js";import{t as w}from"./button-4FS1ZDTp.js";import{n as oe,t as se}from"./project-repositories-CvJf1a6H.js";import{$t as T,Ht as ce,It as E,J as le,Kt as ue,Rt as de,St as fe,W as D,Wt as pe,X as me,Xt as O,Y as he,_t as ge,an as _e,at as k,c as ve,cn as ye,d as A,f as j,it as be,l as M,m as N,p as xe,q as Se,sn as Ce,st as P,u as F,xt as we}from"./index-Culan6y7.js";import{a as Te,c as Ee,d as De,f as Oe,i as I,l as ke,m as L,n as Ae,o as je,p as Me,r as Ne,s as Pe,t as Fe,u as Ie}from"./loop-layout-CyXj9223.js";var R={name:`grid-3x3`,size:24,node:[[`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`}]],aliases:[`grid`,`grid-3-x-3`]};R.node;var Le=o(R),Re={name:`move-horizontal`,size:24,node:[[`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`}]]};Re.node;var ze=o(Re),Be={name:`move-vertical`,size:24,node:[[`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`}]]};Be.node;var Ve=o(Be),z=e(t(),1),B=n(),He=`h-9 w-full rounded-md border border-input bg-background px-2 text-sm`;function Ue({roles:e={},provider:t,supported:n,onChange:r,renderEngine:i,visibleRoleIds:o,manageRoles:s=!0}){let{t:c}=a(`agentRuntime`),[l,u]=(0,z.useState)(``),[d,f]=(0,z.useState)(!1),p=Object.entries(e).filter(([e])=>!j.includes(e)&&(!o||o.includes(e)));function m(){if(!ve.test(l)||l===`fixer`||j.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,B.jsxs)(`section`,{className:`space-y-3`,"aria-labelledby":`custom-runtime-roles`,children:[s&&(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`h3`,{id:`custom-runtime-roles`,className:`text-sm font-medium`,children:c(`customRoles.title`)}),(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:c(`customRoles.hint`)})]}),!n&&(0,B.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,B.jsxs)(`fieldset`,{className:`space-y-3 rounded-lg border p-3`,"aria-label":t,children:[(0,B.jsx)(`legend`,{className:`px-1 font-mono text-sm`,children:t}),s&&(0,B.jsx)(`div`,{className:`flex justify-end`,children:(0,B.jsx)(w,{size:`sm`,variant:`ghost`,onClick:()=>{let n={...e};delete n[t],r(n)},children:c(`customRoles.remove`,{id:t})})}),(0,B.jsxs)(`fieldset`,{disabled:!n,className:`space-y-3`,children:[i(t),(0,B.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,B.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[c(`customRoles.access`),(0,B.jsxs)(`select`,{className:He,value:a.access,onChange:e=>o({access:e.target.value}),children:[(0,B.jsx)(`option`,{value:`read`,children:c(`customRoles.read`)}),(0,B.jsx)(`option`,{value:`write`,children:c(`customRoles.write`)})]})]}),(0,B.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[c(`customRoles.artifacts`),(0,B.jsxs)(`select`,{className:He,value:a.artifacts,onChange:e=>o({artifacts:e.target.value}),children:[(0,B.jsx)(`option`,{value:`none`,children:c(`customRoles.none`)}),(0,B.jsx)(`option`,{value:`tasks-checkboxes`,children:c(`customRoles.tasks`)}),(0,B.jsx)(`option`,{value:`all`,children:c(`customRoles.all`)})]})]})]}),(0,B.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[c(`customRoles.skill`),(0,B.jsxs)(`select`,{className:He,value:a.openspecSkill??``,onChange:e=>o({openspecSkill:e.target.value||void 0}),children:[(0,B.jsx)(`option`,{value:``,children:c(`customRoles.noSkill`)}),[`openspec-ff-change`,`openspec-apply-change`,`openspec-verify-change`].map(e=>(0,B.jsx)(`option`,{value:e,children:e},e))]})]}),(0,B.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[c(`customRoles.prompt`),(0,B.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,B.jsxs)(`fieldset`,{disabled:!n||!t,className:`flex items-end gap-2`,children:[(0,B.jsxs)(`label`,{className:`min-w-0 flex-1 space-y-1 text-xs`,children:[c(`customRoles.id`),(0,B.jsx)(D,{value:l,maxLength:64,placeholder:`security-reviewer`,onChange:e=>{u(e.target.value),f(!1)}})]}),(0,B.jsx)(w,{variant:`secondary`,onClick:m,children:c(`customRoles.add`)})]}),d&&(0,B.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive`,children:c(`customRoles.invalidId`)})]})}var We={architect:ue,developer:de,host:ge};function Ge({projectId:e,catalogUrl:t,guardrails:n,onChange:r}){let{t:i,i18n:o}=a(`agentRuntime`),[s,c]=(0,z.useState)(!0),[l,u]=(0,z.useState)({status:`loading`});(0,z.useEffect)(()=>{let n=!1;return u({status:`loading`}),fetch(t??`${oe(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(!xe(i))throw Error(`guardrails`);n||u({status:`ready`,supported:i.supported,catalog:i.catalog})}).catch(()=>{n||u({status:`unsupported`})}),()=>{n=!0}},[e,t]);let d=l.status===`ready`?l.catalog:[],f=l.status===`ready`&&l.supported,p=d.filter(e=>n?.[e.id]===!1).length,m=d.length,h=e=>o.exists(`agentRuntime:guardrails.items.${e}.title`),g=`pipeline-guardrails-body`;return(0,B.jsxs)(`fieldset`,{id:`pipeline-guardrails`,"data-testid":`phase-card-guardrails`,className:`scroll-mt-4 rounded-lg border border-border transition-shadow`,children:[(0,B.jsx)(`legend`,{className:`sr-only`,children:i(`guardrails.title`)}),(0,B.jsxs)(`button`,{type:`button`,"aria-expanded":s,"aria-controls":g,"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,B.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,B.jsx)(we,{className:`h-3.5 w-3.5`,"aria-hidden":!0})}),(0,B.jsx)(`span`,{className:`text-xs font-medium`,children:i(`guardrails.title`)}),(0,B.jsxs)(`span`,{className:`ml-auto flex items-center gap-2`,children:[l.status===`ready`&&f&&(0,B.jsx)(`span`,{"data-testid":`guardrails-active`,className:C(`inline-flex items-center rounded-md border px-1.5 py-0.5 text-[11px] leading-4`,p?`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:m-p,total:m})}),(0,B.jsx)(O,{className:`h-3.5 w-3.5 text-muted-foreground transition-transform ${s?``:`-rotate-90`}`,"aria-hidden":!0})]})]}),(0,B.jsxs)(`div`,{id:g,hidden:!s,className:`space-y-3 px-3 pb-3`,children:[(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i(`guardrails.intro`)}),l.status===`loading`&&(0,B.jsx)(`p`,{role:`status`,className:`text-xs text-muted-foreground`,children:i(`loading`)}),(l.status===`unsupported`||l.status===`ready`&&!f)&&(0,B.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,B.jsxs)(`fieldset`,{disabled:!f,className:`space-y-3 disabled:opacity-60`,children:[p>0&&(0,B.jsx)(`div`,{className:`flex justify-end`,children:(0,B.jsx)(`button`,{type:`button`,className:`text-[11px] text-accent-primary underline-offset-2 hover:underline`,onClick:()=>r(void 0),children:i(`guardrails.reset`)})}),M.map(e=>{let t=d.filter(t=>t.phase===e);if(!t.length)return null;let a=We[e];return(0,B.jsxs)(`div`,{className:`space-y-2`,"data-testid":`guardrails-phase-${e}`,children:[(0,B.jsxs)(`p`,{className:`flex items-center gap-1.5 text-[11px] font-medium uppercase tracking-wide text-muted-foreground`,children:[(0,B.jsx)(a,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),i(`guardrails.phases.${e}`)]}),(0,B.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=h(e.id)?i(`guardrails.items.${e.id}.title`):e.id,o=h(e.id)?i(`guardrails.items.${e.id}.description`):i(`guardrails.unknown`),s=h(e.id)?i(`guardrails.items.${e.id}.why`):null,c=`guardrail-${e.id}-title`;return(0,B.jsxs)(`li`,{className:`flex items-start gap-3 px-3 py-2`,children:[(0,B.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":t,"aria-labelledby":c,"data-testid":`guardrail-${e.id}`,onClick:()=>r(N(n,e.id,!t)),className:C(`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,B.jsx)(`span`,{className:C(`absolute h-3 w-3 rounded-full bg-background shadow transition-transform`,t?`translate-x-3.5`:`translate-x-0.5`)})}),(0,B.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,B.jsx)(`p`,{id:c,className:C(`text-xs font-medium`,!t&&`text-muted-foreground line-through decoration-muted-foreground/50`),children:a}),(0,B.jsx)(`p`,{className:`mt-0.5 text-[11px] leading-4 text-muted-foreground`,children:o}),s&&(0,B.jsx)(`p`,{className:`mt-0.5 text-[10px] italic leading-4 text-muted-foreground/70`,children:s})]})]},e.id)})})]},e)})]})]})]})}var Ke=`h-9 w-full rounded-md border border-input bg-background px-2 text-sm`;function qe({config:e,onChange:t}){let{t:n}=a(`agentRuntime`),r=e.efficiency??{schemaVersion:1};return(0,B.jsxs)(`section`,{className:`space-y-3`,"aria-label":n(`efficiency.title`),children:[(0,B.jsx)(`h3`,{className:`text-sm font-medium`,children:n(`efficiency.title`)}),(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`efficiency.scope`)}),(0,B.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-3`,children:[`contextMode`,`reviewMode`,`planning`].map(i=>(0,B.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[n(`efficiency.${i}`),(0,B.jsxs)(`select`,{className:Ke,value:r[i]??(i===`planning`?`proportional`:`incremental`),onChange:n=>t({...e,efficiency:{...r,[i]:n.target.value}}),children:[(0,B.jsx)(`option`,{value:i===`planning`?`proportional`:`incremental`,children:n(`efficiency.adaptive`)}),(0,B.jsx)(`option`,{value:`full`,children:n(`efficiency.full`)})]})]},i))}),(0,B.jsxs)(`label`,{className:`flex items-center gap-2 text-xs`,children:[(0,B.jsx)(`input`,{type:`checkbox`,checked:r.acceptDeveloperChecks!==!1,onChange:n=>t({...e,efficiency:{...r,acceptDeveloperChecks:n.target.checked}})}),n(`efficiency.developerChecks`)]}),(0,B.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[n(`efficiency.concurrency`),(0,B.jsx)(D,{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,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`efficiency.concurrencyHint`)})]})}function Je(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 Ye(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 Xe(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 Ze=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 Qe(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 W(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;Qe(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 G=`w-full rounded-md border border-input bg-background px-2 py-1 text-xs`,K=[`architect`,`developer`,`reviewer`,`fixer`];function $e({value:e,onChange:t,selectedRole:n,graph:r,mode:i=`all`}){let{t:o}=a(`agentRuntime`),{activeProjectId:l}=c(),d=(0,z.useRef)(l);d.current=l;let[f,p]=(0,z.useState)([]),[m,h]=(0,z.useState)({}),[g,_]=(0,z.useState)(),[v,y]=(0,z.useState)(null),[ee,te]=(0,z.useState)(``),[b,ne]=(0,z.useState)(!1),[re,ie]=(0,z.useState)(!1),ae=r?W(r):[...K,...Object.keys(e?.roles??{})],x=i===`step`?[n??``]:re?void 0:ae,S=i!==`workflow`,C=i!==`step`,oe=i===`step`?`loopAgents.stepTitle`:i===`workflow`?`loopAgents.policy`:`loopAgents.title`,se=[...K,...Object.keys(e?.roles??{})].some(e=>!ae.includes(e));(0,z.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),y(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;ne(!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:y,guardrails:ee}=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])=>K.includes(e))),limits:m,review:h,architect:_,approvalBeforeArchive:v,efficiency:y,guardrails:ee})}catch{te(o(`loadFailed`))}finally{ne(!1)}}function ce(n){if(!e)return null;let r=K.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`?P(s.cli).map(e=>e.value):m[i.provider]??[];return(0,B.jsxs)(`div`,{className:`space-y-2`,children:[(0,B.jsxs)(`label`,{className:`block text-xs`,children:[o(`agents.provider`),(0,B.jsxs)(`select`,{className:G,value:i.provider,onChange:e=>a({provider:e.target.value,maxTurns:i.maxTurns}),children:[(0,B.jsx)(`option`,{value:`inherit`,children:o(`loopAgents.inheritProvider`)}),!s&&i.provider!==`inherit`&&u(i.provider)&&(0,B.jsx)(`option`,{value:i.provider,children:i.provider}),f.filter(e=>u(e.kind===`cli`?e.cli:e.id)).map(e=>(0,B.jsx)(`option`,{value:e.id,children:e.kind===`openai-compatible`?e.label??e.id:e.id},e.id))]})]}),(0,B.jsxs)(`label`,{className:`block text-xs`,children:[o(`agents.model`),(0,B.jsx)(D,{value:i.model??``,list:`loop-models-${n}`,onChange:e=>a({...i,model:e.target.value||void 0})}),(0,B.jsx)(`datalist`,{id:`loop-models-${n}`,children:c.map(e=>(0,B.jsx)(`option`,{value:e},e))})]}),(0,B.jsxs)(`label`,{className:`block text-xs`,children:[o(`loopAgents.effort`),(0,B.jsx)(D,{value:i.effort??``,onChange:e=>a({...i,effort:e.target.value||void 0})})]}),(0,B.jsxs)(`label`,{className:`block text-xs`,children:[o(`agents.maxTurns`,{turns:100}),(0,B.jsx)(D,{type:`number`,min:1,value:i.maxTurns??``,onChange:e=>a({...i,maxTurns:e.target.value?Number(e.target.value):void 0})})]}),(0,B.jsxs)(`label`,{className:`block text-xs`,children:[o(`agents.thinking`),(0,B.jsxs)(`select`,{className:G,value:i.thinking??``,onChange:e=>a({...i,thinking:e.target.value?e.target.value:void 0}),children:[(0,B.jsx)(`option`,{value:``,children:o(`loopAgents.default`)}),(0,B.jsx)(`option`,{value:`off`,children:o(`agents.thinking_off`)}),(0,B.jsx)(`option`,{value:`on`,children:o(`agents.thinking_on`)})]})]}),(0,B.jsxs)(`label`,{className:`block text-xs`,children:[o(`loopAgents.escalationModel`),(0,B.jsx)(D,{value:i.escalation?.model??``,onChange:e=>a({...i,escalation:e.target.value?{...i.escalation,model:e.target.value}:void 0})})]}),i.escalation&&(0,B.jsxs)(`label`,{className:`block text-xs`,children:[o(`loopAgents.escalationEffort`),(0,B.jsx)(D,{value:i.escalation.effort??``,onChange:e=>a({...i,escalation:{model:i.escalation.model,effort:e.target.value||void 0}})})]})]})}let E=e?{...e,enabled:!0,providers:f,verification:[]}:void 0;return(0,B.jsxs)(`section`,{className:`space-y-3 border-b border-border pb-4`,"aria-label":o(oe),children:[(0,B.jsx)(`h3`,{className:`text-sm font-medium`,children:o(oe)}),S&&(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o(i===`step`?`loopAgents.stepHint`:`loopAgents.hint`)}),ee&&(0,B.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive`,children:ee}),!e&&(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`p`,{className:`text-xs text-accent-warning`,children:o(`loopAgents.legacy`)}),(0,B.jsx)(w,{size:`sm`,disabled:!g,onClick:()=>g&&t(structuredClone(g)),children:o(`loopAgents.enable`)})]}),i!==`step`&&(0,B.jsx)(w,{size:`sm`,variant:`secondary`,disabled:!l||!g||b,onClick:()=>void T(),children:o(`loopAgents.import`)}),e&&(0,B.jsxs)(B.Fragment,{children:[i===`all`&&se&&(0,B.jsxs)(`label`,{className:`flex gap-2 text-xs`,children:[(0,B.jsx)(`input`,{type:`checkbox`,checked:re,onChange:e=>ie(e.target.checked)}),o(`loopAgents.showUnused`)]}),S&&K.filter(e=>!x||x.includes(e)).map(r=>(0,B.jsxs)(`details`,{open:n===r,className:`rounded-md border border-border p-2`,children:[(0,B.jsx)(`summary`,{className:`cursor-pointer text-sm font-medium`,children:r}),(0,B.jsxs)(`div`,{className:`mt-3 space-y-3`,children:[ce(r),e.rolePrompts?.[r]===`inherit`?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o(`loopAgents.inheritDefinition`)}),(0,B.jsx)(`textarea`,{readOnly:!0,"aria-label":o(`customRoles.prompt`),className:`${G} opacity-80`,rows:8,value:v?.[r]??o(`loopAgents.coreDefinitionUnavailable`)}),(0,B.jsx)(w,{size:`sm`,variant:`ghost`,disabled:!v?.[r],onClick:()=>t({...e,rolePrompts:{...e.rolePrompts,[r]:v?.[r]??``}}),children:o(`loopAgents.customizeDefinition`)})]}):(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(`label`,{className:`block text-xs`,children:[o(`customRoles.prompt`),(0,B.jsx)(`textarea`,{className:G,rows:10,maxLength:2e4,value:e.rolePrompts?.[r]??``,onChange:n=>t({...e,rolePrompts:{...e.rolePrompts,[r]:n.target.value}})})]}),(0,B.jsx)(w,{size:`sm`,variant:`ghost`,onClick:()=>t({...e,rolePrompts:{...e.rolePrompts,[r]:`inherit`}}),children:o(`loopAgents.restoreDefinition`)})]})]})]},r)),i===`step`&&n&&![...K,`archive`,`verify`].includes(n)&&!e.roles?.[n]&&(0,B.jsx)(w,{size:`sm`,disabled:!f.length,onClick:()=>t({...e,roles:{...e.roles,[n]:{provider:`inherit`,access:`read`,artifacts:`none`}}}),children:o(`customRoles.add`)}),(S||i===`workflow`)&&(0,B.jsx)(Ue,{manageRoles:i!==`step`,visibleRoleIds:i===`workflow`?[]:x,roles:e.roles,provider:`inherit`,supported:!0,onChange:n=>{Object.keys(n).some(t=>!e.roles?.[t])&&ie(!0),t({...e,roles:n,rolePrompts:Object.fromEntries(Object.entries(e.rolePrompts??{}).filter(([e])=>K.includes(e)))})},renderEngine:ce}),(0,B.jsxs)(`div`,{className:`space-y-3`,children:[C&&(0,B.jsxs)(`details`,{className:`rounded-md border border-border p-2`,children:[(0,B.jsx)(`summary`,{className:`cursor-pointer text-sm`,children:o(`loopAgents.policy`)}),(0,B.jsxs)(`div`,{className:`mt-3 space-y-3`,children:[[`maxAttempts`,`maxTokens`,`maxCostUsd`,`timeoutMs`].map(n=>(0,B.jsxs)(`label`,{className:`block text-xs`,children:[o(`loopAgents.${n}`),(0,B.jsx)(D,{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,B.jsx)(Ge,{catalogUrl:`/api/loop-agent-defaults`,guardrails:e.guardrails,onChange:n=>t({...e,guardrails:n})}),E&&(0,B.jsx)(qe,{config:E,onChange:n=>t({...e,efficiency:n.efficiency})})]})]}),(i===`all`||i===`step`&&n===`reviewer`)&&(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(`label`,{className:`block text-xs`,children:[o(`review.minScore`,{score:70}),(0,B.jsx)(D,{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}})})]}),F.map(n=>(0,B.jsxs)(`label`,{className:`block text-xs`,children:[o(`review.aspects.${n}`,{score:A.aspects[n]}),(0,B.jsx)(D,{type:`number`,min:A.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,B.jsxs)(`label`,{className:`block text-xs`,children:[o(`architect.onLowConfidence`),(0,B.jsxs)(`select`,{className:G,value:e.architect?.onLowConfidence??`ask`,onChange:n=>t({...e,architect:{onLowConfidence:n.target.value}}),children:[(0,B.jsx)(`option`,{value:`ask`,children:o(`architect.ask`)}),(0,B.jsx)(`option`,{value:`proceed`,children:o(`architect.proceed`)})]})]}),(i===`all`||i===`step`&&n===`archive`)&&(0,B.jsxs)(`label`,{className:`flex gap-2 text-xs`,children:[(0,B.jsx)(`input`,{type:`checkbox`,checked:e.approvalBeforeArchive??!1,onChange:n=>t({...e,approvalBeforeArchive:n.target.checked})}),o(`approvalBeforeArchive`)]})]})]})]})}var q=`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 J({schema:e,value:t,onChange:n,path:r=`params`,choices:i={},depth:o=0}){let{t:s}=a(`loops`),c=(0,z.useId)(),[l,u]=(0,z.useState)(``);if(o>24)return(0,B.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,B.jsx)(J,{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,B.jsxs)(`fieldset`,{className:`space-y-2`,children:[(0,B.jsx)(`legend`,{className:`text-xs font-medium`,children:d}),(0,B.jsx)(`label`,{className:`sr-only`,htmlFor:c,children:s(`builder.core.variant`,{name:d})}),(0,B.jsx)(`select`,{id:c,className:q,value:r,onChange:t=>n(U(e[Number(t.target.value)])),children:e.map((e,t)=>(0,B.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,B.jsxs)(`p`,{className:`text-xs`,children:[(0,B.jsxs)(`span`,{className:`text-muted-foreground`,children:[d,`: `]}),String(e.const)]});if(Array.isArray(e.enum))return(0,B.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[d,(0,B.jsxs)(`select`,{className:q,value:JSON.stringify(t),onChange:e=>n(JSON.parse(e.target.value)),children:[!e.enum.includes(t)&&(0,B.jsx)(`option`,{value:JSON.stringify(t)??``,children:s(`builder.core.select`)}),e.enum.map((e,t)=>(0,B.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,B.jsxs)(`fieldset`,{className:`space-y-2 min-w-0`,children:[(0,B.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,B.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,B.jsx)(_,{className:`h-3 w-3`}),t]},t):(0,B.jsxs)(`div`,{className:`relative border-l border-border pl-2 space-y-1`,children:[!o&&(0,B.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,B.jsx)(b,{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,B.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,B.jsx)(`input`,{className:q,value:l,placeholder:s(`builder.core.fieldName`),"aria-label":s(`builder.core.fieldName`),onChange:e=>u(e.target.value)}),(0,B.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,B.jsx)(_,{className:`h-4 w-4`})})]})]})}if(m===`array`){let r=Array.isArray(t)?t:[],i=V(e.items);return(0,B.jsxs)(`fieldset`,{className:`space-y-2`,children:[(0,B.jsx)(`legend`,{className:`text-xs font-semibold`,children:d}),r.map((e,t)=>(0,B.jsxs)(`div`,{className:`border-l border-border pl-2`,children:[(0,B.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,B.jsx)(b,{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,B.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,B.jsx)(_,{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,B.jsxs)(`div`,{className:`space-y-1`,children:[(0,B.jsxs)(`label`,{className:`text-xs`,children:[s(`builder.core.valueType`),(0,B.jsx)(`select`,{className:q,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,B.jsx)(`option`,{children:e},e))})]}),r===`null`?(0,B.jsx)(`span`,{className:`text-xs`,children:`null`}):f(`value`,{type:r},t,n)]})}if(m===`boolean`)return(0,B.jsxs)(`label`,{className:`flex items-center gap-2 text-xs`,children:[(0,B.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,B.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[d,(0,B.jsx)(`input`,{type:`number`,className:q,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,v=[`text`,`prompt`,`question`,`message`,`goal`,`expr`,`commandLine`,`reason`].includes(d);return(0,B.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[d,h?.length&&d!==`roleId`?(0,B.jsxs)(`select`,{className:q,value:typeof t==`string`?t:``,onChange:e=>n(e.target.value),children:[(0,B.jsx)(`option`,{value:``,children:s(`builder.core.select`)}),t&&!h.includes(String(t))?(0,B.jsx)(`option`,{value:String(t),children:String(t)}):null,h.map(e=>(0,B.jsx)(`option`,{children:e},e))]}):v?(0,B.jsx)(`textarea`,{className:`${q} 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,B.jsx)(`input`,{list:g?.length||d===`roleId`&&h?.length?c:void 0,className:q,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,B.jsx)(`datalist`,{id:c,children:(g??h??[]).map(e=>(0,B.jsx)(`option`,{value:e},e))}):null,typeof e.description==`string`&&(0,B.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:e.description})]})}var Y=`w-full min-w-0 rounded border border-border bg-background px-2 py-1 text-xs`,et=[`journal`,`change`,`maxTokens`,`maxTransitions`,`policies`];function tt({graph:e,canvas:t,schema:n,onChange:r,onOpenCanvas:i}){let{t:o}=a(`loops`),[s,c]=(0,z.useState)(``),l=V(n.properties),u={type:`object`,additionalProperties:!1,properties:{...Object.fromEntries(et.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])=>et.includes(e))),f=t?e.components?.[t]:void 0,p=t?[]:Je(e);return(0,B.jsxs)(B.Fragment,{children:[!t&&(0,B.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[(0,B.jsx)(`span`,{children:o(`builder.core.reviewerStep`)}),(0,B.jsxs)(`select`,{className:Y,value:e.config.reviewerStepId??``,onChange:t=>r({...e,config:{...e.config,reviewerStepId:t.target.value||void 0}}),children:[(0,B.jsx)(`option`,{value:``,children:o(`builder.core.reviewerAutomatic`)}),e.config.reviewerStepId&&!p.includes(e.config.reviewerStepId)&&(0,B.jsx)(`option`,{value:e.config.reviewerStepId,children:e.config.reviewerStepId}),p.map(e=>(0,B.jsx)(`option`,{value:e,children:e},e))]}),(0,B.jsx)(`span`,{className:`block text-muted-foreground`,children:o(`builder.core.reviewerHint`)})]}),(0,B.jsx)(J,{schema:u,value:d,path:o(`builder.core.options`),onChange:t=>{let n=Object.fromEntries(Object.entries(e.config).filter(([e])=>!et.includes(e)));r({...e,config:{...n,...t}})}}),(0,B.jsxs)(`section`,{className:`space-y-2`,children:[(0,B.jsx)(`p`,{className:`text-xs font-semibold`,children:o(`builder.core.components`)}),(0,B.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:Object.keys(e.components??{}).map(e=>(0,B.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,B.jsxs)(`div`,{className:`flex gap-1`,children:[(0,B.jsx)(`input`,{className:Y,value:s,"aria-label":o(`builder.core.componentName`),placeholder:o(`builder.core.componentName`),onChange:e=>c(e.target.value)}),(0,B.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,B.jsx)(_,{className:`w-4 h-4`})})]}),f&&t&&(0,B.jsx)(J,{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 nt({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,B.jsxs)(`div`,{className:`space-y-3`,children:[(0,B.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,B.jsx)(`h3`,{className:`text-sm font-semibold`,children:l(`builder.core.pieces.${t.coreKind}`)}),(0,B.jsx)(`button`,{type:`button`,onClick:s,"aria-label":l(`common:actions.delete`),className:`text-muted-foreground hover:text-destructive`,children:(0,B.jsx)(y,{className:`h-4 w-4`})})]}),(0,B.jsxs)(`label`,{className:`block text-xs`,children:[l(`builder.inspector.label`),(0,B.jsx)(`input`,{className:Y,value:String(t.label??``),onChange:e=>o({label:e.target.value})})]}),[`implementation`,`implementation-step`].includes(t.coreKind??``)&&(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:l(`builder.core.legacyImplementation`)}),n?(0,B.jsx)(J,{schema:m,value:t.params??{},onChange:e=>o({params:e}),choices:r},e):(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:l(`builder.core.unavailable`)}),[`component`,`map`].includes(t.coreKind)&&typeof u==`string`&&(0,B.jsx)(`button`,{type:`button`,className:`text-xs text-accent-primary`,onClick:()=>c(u),children:l(`builder.core.openComponent`)}),Object.keys(d).length>0&&(0,B.jsx)(J,{schema:d,value:t.retry??{},path:`retry`,onChange:e=>o({retry:e})})]})}function rt(e){return e===`continue`||e===`stop`?e:void 0}function it(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 at(){return globalThis.crypto?.randomUUID?.()??`n-${Date.now()}-${Math.floor(Math.random()*1e9)}`}function ot(e,t){return{id:at(),type:`loop`,position:t,data:it(e)}}function st(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:Me.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 ct(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=rt(t.sourceHandle)??rt(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 lt=`specrailsNodes`;function ut(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 dt(e){if(!e)return null;let t;try{t=JSON.parse(e)}catch{return null}let n=t;return!n||n[lt]==null||!Array.isArray(n.nodes)?null:{nodes:n.nodes,edges:Array.isArray(n.edges)?n.edges:[]}}function ft(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 pt(e){return typeof e!=`string`||e.trim().length===0}function mt(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 ht(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=mt(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}),pt(t.data.goal)&&n.push({severity:`warning`,code:`EMPTY_GOAL`,nodeId:t.id});break}case`ai-step`:pt(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`:pt(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 gt(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 _t=(0,z.createContext)(new Map),vt=(0,z.createContext)({pieces:[]}),yt=[`start`,`ai-step`,`shell`,`decider`,`end`],bt={core:T,start:h,"ai-step":T,shell:ge,decider:m,condition:m,end:ce},xt={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 St({id:e,data:t,selected:n}){let{t:r}=a(`loops`),i=t.kind,o=bt[i]??g,s=String(t.label??``).trim(),c=(0,z.useContext)(_t).get(e),l=(0,z.useContext)(vt),u=Xe(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,B.jsxs)(`div`,{className:C(`rounded-md border-2 bg-card px-3 py-2 min-w-[140px] shadow-sm`,xt[i],c===`error`?`ring-2 ring-destructive`:n?`ring-2 ring-accent-primary`:c===`warning`?`ring-2 ring-accent-warning`:``),children:[i!==`start`&&(0,B.jsx)(I,{type:`target`,position:L.Top}),(0,B.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,B.jsx)(o,{className:`w-3.5 h-3.5 text-foreground flex-shrink-0`}),(0,B.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,B.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,B.jsx)(`p`,{className:`text-[10px] text-muted-foreground mt-1 truncate max-w-[160px]`,children:d}),i===`core`?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`div`,{className:`flex justify-around gap-2 mt-2 text-[9px] text-accent-primary`,children:u.map(e=>(0,B.jsx)(`span`,{children:e},e))}),u.map((e,t)=>(0,B.jsx)(I,{id:e,type:`source`,position:L.Bottom,style:{left:`${(t+1)*100/(u.length+1)}%`},"aria-label":e},e))]}):i===`decider`?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(`div`,{className:`mt-1.5 flex items-center justify-between gap-2 text-[9px] font-medium`,children:[(0,B.jsx)(`span`,{className:`text-accent-highlight`,children:r(`builder.branch.continue`)}),(0,B.jsx)(`span`,{className:`text-accent-success`,children:r(`builder.branch.stop`)})]}),(0,B.jsx)(I,{id:`continue`,type:`source`,position:L.Bottom,style:{left:`30%`},className:`!bg-accent-highlight`}),(0,B.jsx)(I,{id:`stop`,type:`source`,position:L.Bottom,style:{left:`70%`},className:`!bg-accent-success`})]}):i===`end`?null:(0,B.jsx)(I,{type:`source`,position:L.Bottom})]})}function X({loopId:e,onExit:t,onWindowOpened:n}){let{t:o}=a(`loops`),u=i(),{id:m}=r(),h=e??m,g=(0,z.useCallback)(()=>{t?t():u(`/loops`)},[t,u]),y=_e(),{fitView:b,screenToFlowPosition:oe}=Oe(),{activeProjectId:se}=c(),[T,ce]=(0,z.useState)([]),[ue,de]=(0,z.useState)({}),[fe,D]=(0,z.useState)(!1),[O,ge]=(0,z.useState)({}),[ve,A]=(0,z.useState)([]),[j,M]=(0,z.useState)(null),[N,xe]=(0,z.useState)(null);(0,z.useEffect)(()=>{let e=!1;return k.catalog().then(t=>{e||(ce(t.nodeKinds),de(t.definitionSchema??{}),D(!1))}).catch(()=>{e||D(!0)}),()=>{e=!0}},[]),(0,z.useEffect)(()=>{let e=new AbortController;ge({});let t=t=>fetch(t,{signal:e.signal}).then(e=>e.ok?e.json():null).catch(()=>null);return Promise.all([se&&j&&!j.config.agents?t(`${s()}/agent-runtime/config`):Promise.resolve(null),t(`/api/runtime-providers`)]).then(([t,n])=>{e.signal.aborted||ge({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()},[se,!!j,!!j?.config.agents]);let[P,F,we]=De([]),[I,L,Pe]=Ie([]),[R,Re]=(0,z.useState)(``),[Be,He]=(0,z.useState)(!1),[Ue,We]=(0,z.useState)(!1),[Ge,Ke]=(0,z.useState)(10),[qe,Je]=(0,z.useState)(30),[V,H]=(0,z.useState)(null),[U,W]=(0,z.useState)(null),[G,K]=(0,z.useState)(!1);(0,z.useEffect)(()=>K(!1),[h]);let[q,J]=(0,z.useState)(!0),[Y,et]=(0,z.useState)(!1),[rt,it]=(0,z.useState)(!1),[lt,pt]=(0,z.useState)(null),[mt,xt]=(0,z.useState)(!1),X=(0,z.useMemo)(()=>[...ht(P,I),...ve.map(e=>({severity:`error`,code:`CORE_VALIDATION`,nodeId:e.nodeId,message:e.message}))],[P,I,ve]),Ct=(0,z.useMemo)(()=>gt(X),[X]),wt=X.filter(e=>e.severity===`error`).length,[Tt,Et]=(0,z.useState)(`manual`),Dt=(0,z.useRef)(new Map),[jt,Mt]=(0,z.useState)([]),[Nt,Pt]=(0,z.useState)(!1),Ft=(0,z.useCallback)(async()=>{try{Mt(await k.loopConstants())}catch{}},[]);(0,z.useEffect)(()=>{Ft()},[Ft]);let It=(0,z.useMemo)(()=>({loop:St}),[]),Lt=(0,z.useCallback)(e=>{M(e.graph),xe(null);let{nodes:t,edges:n}=st(e.graph);Dt.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`;Et(i),F(i===`manual`?t:Fe(t,n,i)),L(n),Re(e.name),Ke(e.graph.config?.maxIterations??10),Je(e.graph.config?.timeoutMinutes??30),H(typeof e.graph.config?.maxCostUsd==`number`?e.graph.config.maxCostUsd:null),He(!!e.builtinId)},[F,L]);(0,z.useEffect)(()=>{if(!h)return;let e=!1;return k.get(h).then(t=>{e||Lt(t)}).catch(()=>l.error(o(`errors.load`))).finally(()=>{e||J(!1)}),()=>{e=!0}},[h,Lt,o]);let Rt=(0,z.useCallback)(async()=>{if(h){We(!1);try{Lt(await k.restoreBuiltin(h)),A([]),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,z.useCallback)(e=>{if(A([]),P.find(t=>t.id===e.source)?.data.kind===`core`){L(t=>Ee({...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;L(e=>Ee(n,e))},[L,P]),Bt=(0,z.useCallback)(e=>{if(!e.source||!e.target)return!1;let t=P.find(t=>t.id===e.source)?.data.kind,n=P.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=P.find(t=>t.id===e.source),n=Xe(T.find(e=>e.kind===t.data.coreKind),t.data.params??{},j?.components);if(!e.sourceHandle||!n.includes(e.sourceHandle)||I.some(t=>t.source===e.source&&t.sourceHandle===e.sourceHandle))return!1}return!(t===`start`&&I.some(t=>t.source===e.source)||n===`start`)},[P,I,T,j]),Vt=(0,z.useCallback)(e=>{Et(e==="default"?`manual`:e),F(t=>e==="default"?t.map(e=>{let t=Dt.current.get(e.id);return t?{...e,position:{...t}}:e}):Fe(t,I,e)),requestAnimationFrame(()=>b({padding:.25,maxZoom:.85,duration:300}))},[F,I,b]),Ht=(0,z.useCallback)(e=>{e.some(e=>e.type===`position`&&e.dragging===!1)&&Et(`manual`),we(e)},[we]),Ut=(0,z.useRef)(P);Ut.current=P;let Wt=(0,z.useRef)(I);Wt.current=I,(0,z.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=ut(Ut.current,Wt.current);!n||!t.clipboardData||(t.clipboardData.setData(`text/plain`,JSON.stringify(n)),t.preventDefault())},n=t=>{if(e())return;let n=dt(t.clipboardData?.getData(`text/plain`)??``);if(!n)return;t.preventDefault();let r=ft(n,{mintId:at,offset:{x:40,y:40},excludeKinds:Ut.current.some(e=>e.data.kind===`start`)?[`start`]:[]});r.nodes.length!==0&&(F(e=>[...e.map(e=>({...e,selected:!1})),...r.nodes]),L(e=>[...e,...r.edges]),Et(`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)}},[F,L,o]);let Gt=(0,z.useCallback)(e=>{let t=ot(e,{x:120+Math.random()*120,y:80+Math.random()*240});F(e=>[...e,t]),K(!1),W(t.id)},[F]),Kt=(0,z.useCallback)(e=>{A([]),F(t=>t.map(t=>t.id===U?{...t,data:{...t.data,...e}}:t))},[U,F]),qt=(0,z.useCallback)(()=>{U&&(F(e=>e.filter(e=>e.id!==U)),L(e=>e.filter(e=>e.source!==U&&e.target!==U)),W(null))},[U,F,L]),Z=!!j&&!P.some(e=>![`start`,`core`,`end`].includes(e.data.kind)),Q=(0,z.useCallback)(()=>{let e={...j?.config,maxIterations:Ge,timeoutMinutes:qe,maxCostUsd:V??void 0,layout:Tt},t=N?j?.components?.[N]:j,n={...t,...ct(P,I,N?t?.config??e:e)};return N?{...j,config:e,components:{...j?.components,[N]:n}}:{...n,components:j?.components}},[j,N,P,I,Ge,qe,V,Tt]),Jt=(0,z.useCallback)((e,t=!1)=>{let n=Q();e&&t&&!n.components?.[e]&&(n.components={...n.components,[e]:{nodes:[{id:at(),type:`start`,position:{x:160,y:40}},{id:at(),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=st(r);M(n),xe(e),F(i.nodes),L(i.edges),W(null),A([]),requestAnimationFrame(()=>b({padding:.25}))},[Q,F,L,b]),Yt=(0,z.useCallback)((e,t)=>{let n={id:at(),type:`loop`,position:t??{x:160+P.length*20,y:100+P.length*30},data:Ye(e)};if(e.kind===`role-turn`&&j){let e=O.providers?.[0]??`claude`,t=(`agent-`+n.id.replace(/[^a-z0-9-]/g,`-`)).slice(0,64),r=j.config.agents??{schemaVersion:1,agents:{architect:{provider:e},developer:{provider:e},reviewer:{provider:e}}};n.data.params={roleId:t,prompt:o(`builder.core.agentTaskDefault`)},M({...j,config:{...j.config,agents:{...r,roles:{...r.roles,[t]:{provider:e,access:`write`,artifacts:`none`,prompt:``}}}}})}e.kind===`prompt`&&O.providers?.length&&(n.data.params.engine={provider:O.providers[0]}),F(e=>[...e,n]),K(!1),W(n.id)},[P.length,F,O.providers,j,o]),Xt=(0,z.useCallback)(async()=>{xt(!0);try{let e=Q(),{steps:t}=await k.previewLoop(e);pt(t)}catch{l.error(o(`builder.preview.error`))}finally{xt(!1)}},[Q,o]),Zt=(0,z.useCallback)(async()=>{if(!h)return!1;et(!0);try{let e=Q();return await k.update(h,{name:R,graph:e}),!0}catch(e){return l.error(e instanceof Error&&e.message?e.message:o(`errors.save`)),!1}finally{et(!1)}},[h,Q,R,o]),Qt=(0,z.useCallback)(async()=>{if(h&&await Zt())try{await k.publish(h),l.success(o(`builder.published`)),g()}catch(e){e instanceof be?(A(e.errors),it(!0),l.error(o(`errors.publishInvalid`))):l.error(e instanceof Error&&e.message?e.message:o(`errors.save`))}},[h,Zt,g,o]),$=P.find(e=>e.id===U)??null;return(0,B.jsx)(_t.Provider,{value:Ct,children:(0,B.jsx)(vt.Provider,{value:{pieces:T,components:j?.components},children:(0,B.jsxs)(`div`,{className:`h-full flex flex-col`,children:[(0,B.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-4 h-12 border-b border-border flex-shrink-0`,children:[(0,B.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,B.jsx)(`button`,{type:`button`,onClick:g,className:`text-muted-foreground hover:text-foreground`,"aria-label":o(`builder.back`),children:(0,B.jsx)(d,{className:`w-4 h-4`})}),(0,B.jsx)(`input`,{value:R,onChange:e=>Re(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,B.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,B.jsxs)(he,{delayDuration:150,children:[(0,B.jsxs)(`label`,{className:`text-[10px] text-muted-foreground flex items-center gap-1`,children:[o(`builder.config.maxIterations`),(0,B.jsxs)(Se,{children:[(0,B.jsx)(me,{asChild:!0,children:(0,B.jsx)(`button`,{type:`button`,onClick:e=>e.preventDefault(),className:`text-muted-foreground/60 hover:text-foreground`,"aria-label":o(`builder.config.maxIterations`),children:(0,B.jsx)(E,{className:`w-3 h-3`})})}),(0,B.jsx)(le,{className:`max-w-xs leading-relaxed`,children:o(`builder.config.maxIterationsHint`)})]}),(0,B.jsx)(`input`,{type:`number`,min:1,value:Ge,onChange:e=>Ke(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,B.jsxs)(`label`,{className:`text-[10px] text-muted-foreground flex items-center gap-1`,children:[o(`builder.config.timeout`),(0,B.jsxs)(Se,{children:[(0,B.jsx)(me,{asChild:!0,children:(0,B.jsx)(`button`,{type:`button`,onClick:e=>e.preventDefault(),className:`text-muted-foreground/60 hover:text-foreground`,"aria-label":o(`builder.config.timeout`),children:(0,B.jsx)(E,{className:`w-3 h-3`})})}),(0,B.jsx)(le,{className:`max-w-xs leading-relaxed`,children:o(`builder.config.timeoutHint`)})]}),(0,B.jsx)(`input`,{type:`number`,min:0,"aria-label":o(`builder.config.timeout`),value:qe,onChange:e=>Je(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,B.jsxs)(`label`,{className:`text-[10px] text-muted-foreground flex items-center gap-1`,children:[o(`builder.config.maxCost`),(0,B.jsxs)(Se,{children:[(0,B.jsx)(me,{asChild:!0,children:(0,B.jsx)(`button`,{type:`button`,onClick:e=>e.preventDefault(),className:`text-muted-foreground/60 hover:text-foreground`,"aria-label":o(`builder.config.maxCost`),children:(0,B.jsx)(E,{className:`w-3 h-3`})})}),(0,B.jsx)(le,{className:`max-w-xs leading-relaxed`,children:o(`builder.config.maxCostHint`)})]}),(0,B.jsx)(`input`,{type:`number`,min:0,step:.5,placeholder:`∞`,value:V??``,onChange:e=>{let t=Number(e.target.value);H(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,B.jsx)(`button`,{type:`button`,"aria-pressed":G,onClick:()=>K(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`)}),Be&&(0,B.jsxs)(`button`,{type:`button`,onClick:()=>We(!0),disabled:Y,"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,B.jsx)(v,{className:`w-3 h-3`}),` `,o(`actions.restoreBuiltin`)]}),(0,B.jsxs)(`button`,{type:`button`,onClick:()=>void Xt(),disabled:mt,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,B.jsx)(pe,{className:`w-3 h-3`}),` `,o(`builder.preview.label`)]}),!Ce()&&(0,B.jsxs)(`button`,{type:`button`,disabled:Y,onClick:()=>void Zt().then(async e=>{if(!(!e||!h))try{await ye(se,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,B.jsx)(p,{className:`w-3 h-3`}),o(`window.open`)]}),(0,B.jsxs)(`button`,{type:`button`,onClick:()=>void Zt().then(e=>e&&l.success(o(`builder.saved`))),disabled:Y,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,B.jsx)(f,{className:`w-3 h-3`}),` `,o(`builder.save`)]}),(0,B.jsxs)(`button`,{type:`button`,onClick:()=>void Qt(),disabled:Y,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,B.jsx)(te,{className:`w-3 h-3`}),` `,o(`builder.publish`)]})]})]}),Be&&(0,B.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,B.jsx)(S,{open:Ue,onOpenChange:e=>{e||We(!1)},children:(0,B.jsxs)(x,{className:`max-w-sm`,children:[(0,B.jsxs)(ae,{children:[(0,B.jsx)(ie,{children:o(`builder.builtin.confirmTitle`)}),(0,B.jsx)(re,{children:o(`builder.builtin.confirmBody`)})]}),(0,B.jsxs)(ne,{children:[(0,B.jsx)(w,{variant:`ghost`,onClick:()=>We(!1),children:o(`common:actions.cancel`)}),(0,B.jsx)(w,{"data-testid":`builder-restore-confirm`,onClick:()=>void Rt(),children:o(`actions.restoreBuiltin`)})]})]})}),(0,B.jsxs)(`div`,{className:`flex-1 flex min-h-0`,children:[(0,B.jsxs)(`div`,{className:`w-44 border-r border-border p-2 space-y-1 flex-shrink-0 overflow-y-auto`,children:[(0,B.jsx)(`p`,{className:`text-[10px] font-semibold uppercase tracking-wide text-muted-foreground px-1 mb-1`,children:o(`builder.addNode`)}),Z&&fe&&(0,B.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,B.jsxs)(`div`,{className:`pt-2`,children:[(0,B.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)&&Ze(t.kind)===e).map(e=>(0,B.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,B.jsx)(_,{className:`h-3 w-3 flex-shrink-0`}),o(`builder.core.pieces.${e.kind}`)]},e.kind))]},e)),(Z?[`start`]:yt).map(e=>{let t=bt[e];return(0,B.jsxs)(`button`,{type:`button`,onClick:()=>Gt(e),disabled:e===`start`&&P.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,B.jsx)(t,{className:`w-3.5 h-3.5 flex-shrink-0`}),(0,B.jsx)(`span`,{className:`truncate`,children:o(`builder.nodes.${e}`)}),(0,B.jsx)(_,{className:`w-3 h-3 ml-auto opacity-50`})]},e)})]}),(0,B.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,oe({x:e.clientX,y:e.clientY})))},children:q?(0,B.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,B.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`…`})}):(0,B.jsxs)(ke,{nodes:P,edges:I,onNodesChange:Ht,onEdgesChange:Pe,onConnect:zt,isValidConnection:Bt,onNodeClick:(e,t)=>{K(!1),W(t.id)},onPaneClick:()=>{K(!1),W(null)},nodeTypes:It,colorMode:y.scheme===`dark`?`dark`:`light`,fitView:!0,fitViewOptions:{padding:.25,maxZoom:.85},minZoom:.2,defaultEdgeOptions:{type:`smoothstep`,markerEnd:{type:Me.ArrowClosed,width:16,height:16}},proOptions:{hideAttribution:!0},children:[Z&&(0,B.jsx)(je,{position:`top-center`,children:(0,B.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,B.jsx)(`button`,{type:`button`,onClick:()=>Jt(null),className:`px-2 py-1 hover:bg-muted`,children:R||o(`builder.core.root`)}),N&&(0,B.jsxs)(`span`,{"aria-current":`page`,children:[`/ `,N]})]})}),(0,B.jsx)(Ae,{}),(0,B.jsx)(Ne,{}),(0,B.jsx)(Te,{pannable:!0,zoomable:!0}),(0,B.jsx)(je,{position:`top-left`,children:(0,B.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`,Ve],[`horizontal`,ze],[`grid`,Le],[`default`,v]].map(([e,t])=>{let n=e==="default"?`reset`:e,r=e==="default"?Tt===`manual`:Tt===e;return(0,B.jsx)(`button`,{type:`button`,title:o(`builder.arrange.${n}`),"aria-label":o(`builder.arrange.${n}`),"aria-pressed":r,onClick:()=>Vt(e),className:C(`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,B.jsx)(t,{className:`w-3.5 h-3.5`})},e)})})}),(0,B.jsx)(je,{position:`top-right`,children:(0,B.jsx)(he,{delayDuration:150,children:(0,B.jsxs)(Se,{children:[(0,B.jsx)(me,{asChild:!0,children:(0,B.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,B.jsx)(E,{className:`w-3 h-3`}),o(`builder.edgesHelp.label`)]})}),(0,B.jsx)(le,{className:`max-w-xs leading-relaxed`,children:o(`builder.edgesHelp.body`)})]})})}),X.length>0&&(0,B.jsx)(je,{position:`bottom-center`,children:(0,B.jsxs)(`div`,{className:`rounded-md border border-border bg-card/95 backdrop-blur text-xs overflow-hidden max-w-md mb-2`,children:[(0,B.jsxs)(`button`,{type:`button`,onClick:()=>it(e=>!e),className:C(`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,B.jsx)(ee,{className:`w-3.5 h-3.5`}),o(`builder.problems.count`,{count:X.length})]}),rt&&(0,B.jsx)(`ul`,{className:`border-t border-border max-h-40 overflow-y-auto py-1`,children:X.map((e,t)=>(0,B.jsx)(`li`,{children:(0,B.jsxs)(`button`,{type:`button`,disabled:!e.nodeId,onClick:()=>{e.nodeId&&(K(!1),W(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,B.jsx)(`span`,{className:C(`mt-1 w-1.5 h-1.5 rounded-full flex-shrink-0`,e.severity===`error`?`bg-destructive`:`bg-accent-warning`)}),(0,B.jsx)(`span`,{className:`text-foreground`,children:`message`in e?String(e.message):o(`builder.problems.${e.code}`)})]})},`${e.code}-${e.nodeId??t}`))})]})})]})}),(0,B.jsxs)(`div`,{className:`w-80 border-l border-border p-3 flex-shrink-0 overflow-y-auto space-y-4`,children:[!G&&($?$.data.kind===`core`?(0,B.jsx)(nt,{nodeId:$.id,data:$.data,piece:T.find(e=>e.kind===$.data.coreKind),choices:{...O,roles:j?.config.agents?[...Object.keys(j.config.agents.agents),...Object.keys(j.config.agents.roles??{})]:O.roles,components:Object.keys(j?.components??{})},schema:ue,onChange:Kt,onDelete:qt,onOpenCanvas:Jt}):(0,B.jsx)(At,{data:$.data,onChange:Kt,onDelete:qt,constants:jt,onManageConstants:()=>Pt(!0)}):(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o(`builder.inspector.selectNode`)})),!G&&Z&&j&&$&&(Qe($.id,$.data.coreKind,$.data.params??{}).length>0||$.data.coreKind===`implementation-step`&&$.data.params?.phase===`archive`)&&(0,B.jsx)($e,{mode:$.data.coreKind===`implementation`?`all`:`step`,graph:Q(),value:j.config.agents,selectedRole:String($.data.params?.phase??Qe($.id,$.data.coreKind,$.data.params??{})[0]??``),onChange:e=>M({...j,config:{...j.config,agents:e}})},`${h}:${$.id}`),G&&Z&&j&&(0,B.jsx)($e,{mode:`workflow`,graph:Q(),value:j.config.agents,selectedRole:$?Qe($.id,$.data.coreKind,$.data.params??{})[0]:void 0,onChange:e=>M({...j,config:{...j.config,agents:e}})},h),G&&Z&&j&&(0,B.jsx)(tt,{graph:j,canvas:N,schema:ue,onChange:M,onOpenCanvas:Jt})]})]}),(0,B.jsx)(Ot,{open:Nt,onClose:()=>Pt(!1),constants:jt,onChanged:Ft,t:o}),(0,B.jsx)(kt,{steps:lt,onClose:()=>pt(null),t:o})]})})})}var Ct=[{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 wt({token:e,label:t,description:n,onInsert:r}){return(0,B.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 Tt({t:e,onInsert:t}){let[n,r]=(0,z.useState)([]);return(0,z.useEffect)(()=>{let e=!1;return k.loopCommands().then(t=>{e||r(t)}).catch(()=>{}),()=>{e=!0}},[]),(0,B.jsxs)(`div`,{className:`mb-2 space-y-1.5`,children:[Ct.map(n=>(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`span`,{className:`block text-[9px] uppercase tracking-wide text-muted-foreground/70 mb-0.5`,children:e(n.labelKey)}),(0,B.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:n.tokens.map(e=>(0,B.jsx)(wt,{token:e.token,label:e.label,onInsert:t},e.token))})]},n.labelKey)),n.length>0&&(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`span`,{className:`block text-[9px] uppercase tracking-wide text-muted-foreground/70 mb-0.5`,children:e(`builder.inspector.tokensCommands`)}),(0,B.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:n.map(e=>(0,B.jsx)(wt,{token:`{{cmd:${e.name}}}`,label:`⚡ ${e.label}`,description:e.description,onInsert:t},e.name))})]})]})}function Et({t:e,constants:t,onInsert:n,onManage:r}){return(0,B.jsxs)(`div`,{className:`mb-2`,children:[(0,B.jsxs)(`div`,{className:`flex items-center justify-between mb-0.5`,children:[(0,B.jsx)(`span`,{className:`text-[9px] uppercase tracking-wide text-muted-foreground/70`,children:e(`builder.constants.label`)}),(0,B.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,B.jsx)(fe,{className:`w-3 h-3`})})]}),(0,B.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:t.map(e=>(0,B.jsx)(wt,{token:`{{const:${e.name}}}`,label:e.builtin?`🔒 ${e.name}`:e.name,description:e.value,onInsert:n},e.id))})]})}function Dt({c:e,onSave:t,onDelete:n}){let[r,i]=(0,z.useState)(e.value);return(0,B.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,B.jsx)(`code`,{className:`text-[10px] font-mono text-accent-primary w-28 truncate`,title:e.name,children:e.name}),(0,B.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,B.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,B.jsx)(f,{className:`w-3.5 h-3.5`})}),(0,B.jsx)(`button`,{type:`button`,onClick:n,className:`text-muted-foreground hover:text-destructive`,"aria-label":`delete`,children:(0,B.jsx)(y,{className:`w-3.5 h-3.5`})})]})}function Ot({open:e,onClose:t,constants:n,onChanged:r,t:i}){let[a,o]=(0,z.useState)(``),[s,c]=(0,z.useState)(``),[l,u]=(0,z.useState)(null),[d,f]=(0,z.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,B.jsx)(S,{open:e,onOpenChange:e=>{e||t()},children:(0,B.jsxs)(x,{className:`max-w-md`,children:[(0,B.jsx)(ae,{children:(0,B.jsx)(ie,{children:i(`builder.constants.title`)})}),(0,B.jsxs)(`div`,{className:`space-y-3`,children:[(0,B.jsxs)(`div`,{className:`space-y-1.5`,children:[m.length===0&&(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i(`builder.constants.empty`)}),m.map(e=>(0,B.jsx)(Dt,{c:e,onSave:t=>void k.updateConstant(e.id,t).then(r),onDelete:()=>void k.deleteConstant(e.id).then(r)},e.id))]}),(0,B.jsxs)(`div`,{className:`flex items-center gap-1.5 border-t border-border pt-2`,children:[(0,B.jsx)(`input`,{className:`${g} w-28`,placeholder:i(`builder.constants.name`),value:a,onChange:e=>o(e.target.value)}),(0,B.jsx)(`input`,{className:`${g} flex-1`,placeholder:i(`builder.constants.value`),value:s,onChange:e=>c(e.target.value)}),(0,B.jsx)(w,{size:`sm`,disabled:d||!a.trim()||!s,onClick:()=>void h(),children:i(`builder.constants.add`)})]}),l&&(0,B.jsx)(`p`,{className:`text-[10px] text-destructive`,children:l}),p.length>0&&(0,B.jsxs)(`div`,{className:`border-t border-border pt-2 space-y-1`,children:[(0,B.jsx)(`span`,{className:`text-[9px] uppercase tracking-wide text-muted-foreground/70`,children:i(`builder.constants.builtinBadge`)}),p.map(e=>(0,B.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px]`,children:[(0,B.jsx)(`code`,{className:`font-mono text-accent-primary w-28 truncate`,title:e.name,children:e.name}),(0,B.jsx)(`span`,{className:`text-muted-foreground truncate`,children:e.value})]},e.id))]})]}),(0,B.jsx)(ne,{children:(0,B.jsx)(w,{variant:`ghost`,onClick:t,children:i(`common:actions.close`)})})]})})}function kt({steps:e,onClose:t,t:n}){return(0,B.jsx)(S,{open:e!==null,onOpenChange:e=>{e||t()},children:(0,B.jsxs)(x,{className:`max-w-2xl`,children:[(0,B.jsx)(ae,{children:(0,B.jsx)(ie,{children:n(`builder.preview.title`)})}),(0,B.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:n(`builder.preview.sampleNote`)}),(0,B.jsxs)(`div`,{className:`space-y-2 max-h-[60vh] overflow-y-auto`,children:[e&&e.length===0&&(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`builder.preview.empty`)}),e?.map((e,t)=>(0,B.jsxs)(`div`,{className:`rounded-md border border-border`,children:[(0,B.jsxs)(`div`,{className:`px-2.5 py-1 text-[10px] border-b border-border flex items-center gap-1.5`,children:[(0,B.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,B.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,B.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,B.jsx)(ne,{children:(0,B.jsx)(w,{variant:`ghost`,onClick:t,children:n(`common:actions.close`)})})]})})}function At({data:e,onChange:t,onDelete:n,constants:r,onManageConstants:i}){let{t:o}=a(`loops`),{activeProjectId:s,projects:l}=c(),u=se(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,z.useRef)(null),h=(0,z.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,B.jsxs)(`div`,{className:`space-y-3`,children:[(0,B.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,B.jsx)(`span`,{className:`text-xs font-semibold text-foreground`,children:o(`builder.nodes.${d}`)}),(0,B.jsx)(`button`,{type:`button`,onClick:n,"aria-label":o(`builder.deleteNode`),className:`text-muted-foreground hover:text-destructive`,children:(0,B.jsx)(y,{className:`w-3.5 h-3.5`})})]}),(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`label`,{className:f,children:o(`builder.inspector.label`)}),(0,B.jsx)(`input`,{className:p,value:String(e.label??``),onChange:e=>t({label:e.target.value}),placeholder:o(`builder.nodes.${d}`)})]}),d===`ai-step`&&(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`label`,{className:f,children:o(`builder.inspector.prompt`)}),(0,B.jsx)(Tt,{t:o,onInsert:_}),(0,B.jsx)(Et,{t:o,constants:r,onInsert:_,onManage:i}),(0,B.jsx)(`textarea`,{ref:m,rows:7,className:p,value:String(e.prompt??``),onChange:e=>t({prompt:e.target.value})}),(0,B.jsx)(`p`,{className:`text-[10px] text-muted-foreground mt-1`,children:o(`builder.inspector.promptHint`)})]}),d===`shell`&&(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`label`,{className:f,children:o(`builder.inspector.command`)}),(0,B.jsx)(`input`,{className:p,value:String(e.command??``),onChange:e=>t({command:e.target.value}),placeholder:`npm test`}),(0,B.jsxs)(`label`,{className:`${f} mt-3`,children:[o(`common:repositories.shellTarget`),(0,B.jsxs)(`select`,{className:p,value:String(e.repositoryId??``),onChange:e=>t({repositoryId:e.target.value||void 0}),children:[(0,B.jsx)(`option`,{value:``,children:o(`common:repositories.shellDefault`)}),u.filter(e=>e.kind===`git`).map(e=>(0,B.jsx)(`option`,{value:e.id,children:e.name},e.id)),!!e.repositoryId&&!u.some(t=>t.id===e.repositoryId)&&(0,B.jsx)(`option`,{value:String(e.repositoryId),children:String(e.repositoryId)})]})]}),(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o(`common:repositories.shellHint`)})]}),d===`decider`&&(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`label`,{className:f,children:o(`builder.inspector.goal`)}),(0,B.jsx)(Et,{t:o,constants:r,onInsert:e=>g(h,`goal`,e),onManage:i}),(0,B.jsx)(`textarea`,{ref:h,rows:4,className:p,value:String(e.goal??``),onChange:e=>t({goal:e.target.value})})]}),d===`condition`&&(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`label`,{className:f,children:o(`builder.inspector.join`)}),(0,B.jsxs)(`select`,{className:p,value:String(e.join??`AND`),onChange:e=>t({join:e.target.value}),children:[(0,B.jsx)(`option`,{value:`AND`,children:`AND`}),(0,B.jsx)(`option`,{value:`OR`,children:`OR`})]})]}),d===`end`&&(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`label`,{className:f,children:o(`builder.inspector.outcome`)}),(0,B.jsxs)(`select`,{className:p,value:String(e.outcome??`success`),onChange:e=>t({outcome:e.target.value}),children:[(0,B.jsx)(`option`,{value:`success`,children:`success`}),(0,B.jsx)(`option`,{value:`failure`,children:`failure`})]})]}),d===`start`&&(0,B.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:o(`builder.inspector.startNote`)})]})}function jt({loopId:e,onExit:t,onWindowOpened:n}={}){return(0,B.jsx)(Pe,{children:(0,B.jsx)(X,{loopId:e,onExit:t,onWindowOpened:n})})}export{jt as default};
|