stageflow 0.19.0 → 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/agent/activity.d.ts +5 -0
- package/dist/agent/activityObserver.d.ts +3 -0
- package/dist/agent/activityObserver.js +6 -1
- package/dist/agent/piAdapter.js +7 -3
- package/dist/agent/port.d.ts +2 -0
- package/dist/agent/providerInspect.d.ts +19 -0
- package/dist/agent/providerInspect.js +35 -0
- package/dist/agent/streamLogRedact.d.ts +2 -0
- package/dist/agent/streamLogRedact.js +13 -0
- package/dist/cli/artifactCommand.js +2 -2
- package/dist/cli/envelopeCommand.js +2 -2
- package/dist/cli/exportRunCommand.js +2 -2
- package/dist/cli/hostClient.d.ts +43 -0
- package/dist/cli/hostClient.js +182 -0
- package/dist/cli/providersCommand.js +5 -3
- package/dist/cli/runCommand.d.ts +6 -5
- package/dist/cli/runCommand.js +23 -31
- package/dist/cli/runOutput.d.ts +1 -1
- package/dist/cli/runsCommand.d.ts +3 -7
- package/dist/cli/runsCommand.js +33 -94
- package/dist/cli.js +1 -5
- package/dist/config/describePipeline.d.ts +26 -0
- package/dist/config/describePipeline.js +37 -0
- package/dist/config/loadPipeline.d.ts +13 -1
- package/dist/config/loadPipeline.js +34 -4
- package/dist/config/mergePipelineIncludes.d.ts +11 -0
- package/dist/config/mergePipelineIncludes.js +75 -0
- package/dist/config/validateCatalog.d.ts +2 -2
- package/dist/config/validateCatalog.js +24 -17
- package/dist/mcp/catalogTools.js +146 -52
- package/dist/mcp/controlTools.js +77 -19
- package/dist/mcp/deps.d.ts +3 -0
- package/dist/mcp/projectMcpTools.d.ts +3 -0
- package/dist/mcp/projectMcpTools.js +25 -0
- package/dist/mcp/providerTools.d.ts +3 -0
- package/dist/mcp/providerTools.js +17 -0
- package/dist/mcp/readArtifact.d.ts +9 -0
- package/dist/mcp/readArtifact.js +11 -0
- package/dist/mcp/server.js +9 -1
- package/dist/mcp/tailStreamLog.d.ts +8 -0
- package/dist/mcp/tailStreamLog.js +28 -0
- package/dist/mcp/toolResults.d.ts +17 -0
- package/dist/mcp/toolResults.js +15 -0
- package/dist/mcp/tools.js +4 -0
- package/dist/mcp/waitRun.js +4 -4
- package/dist/mcp/waitingGates.d.ts +1 -0
- package/dist/mcp/waitingGates.js +3 -2
- package/dist/package-meta.d.ts +1 -1
- package/dist/package-meta.js +1 -1
- package/dist/projection/projectRun.d.ts +3 -0
- package/dist/projection/projectRun.js +7 -0
- package/dist/runstore/port.d.ts +3 -1
- package/dist/runstore/sqlite/SqliteRunStore.d.ts +2 -1
- package/dist/runstore/sqlite/SqliteRunStore.js +15 -1
- package/dist/runstore/workspaceLayout.d.ts +1 -0
- package/dist/runstore/workspaceLayout.js +3 -0
- package/dist/runtime/feedbackLoopCoordinator.d.ts +9 -1
- package/dist/runtime/feedbackLoopCoordinator.js +50 -20
- package/dist/runtime/feedbackLoopDecision.js +33 -1
- package/dist/runtime/pipelineRunner.d.ts +3 -3
- package/dist/runtime/pipelineRunner.js +3 -1
- package/dist/runtime/resumeReconstruct.js +2 -2
- package/dist/runtime/runManager.d.ts +2 -1
- package/dist/runtime/runManager.js +36 -16
- package/dist/runtime/settingsFile.d.ts +2 -0
- package/dist/runtime/settingsFile.js +19 -0
- package/dist/runtime/stageAttemptBootstrap.d.ts +3 -0
- package/dist/runtime/stageAttemptBootstrap.js +8 -2
- package/dist/runtime/stageStreamLog.d.ts +17 -0
- package/dist/runtime/stageStreamLog.js +89 -0
- package/dist/runtime/stageWorker.js +2 -1
- package/dist/server/bootstrap.js +9 -2
- package/dist/server/ensureGlobalService.d.ts +35 -0
- package/dist/server/ensureGlobalService.js +138 -0
- package/dist/server/http.d.ts +20 -1
- package/dist/server/http.js +450 -402
- package/dist/server/mcpHost.js +7 -8
- package/dist/server/operatorResults.d.ts +10 -0
- package/dist/server/operatorResults.js +24 -0
- package/dist/server/providerRoutes.d.ts +0 -6
- package/dist/server/providerRoutes.js +10 -18
- package/dist/types/pipeline.d.ts +8 -0
- package/dist/ui/assets/{index-DMVdl1qB.js → index-Da5EHU6M.js} +5 -5
- package/dist/ui/index.html +1 -1
- package/package.json +1 -1
- package/skills/stageflow/references/control-surface.md +2 -2
- package/skills/stageflow-run/SKILL.md +27 -9
- package/skills/stageflow-run/references/mcp-call.md +1 -1
- package/skills/stageflow-run/scripts/mcp-call.mjs +9 -0
|
@@ -112,8 +112,8 @@ ${`:root {\n${Object.entries(ue).map(([e,t])=>` ${e}: ${t};`).join(`
|
|
|
112
112
|
`)}function op(e,t){if(e.length===0||t.length===0)return[...e,...t];let n=e[e.length-1],r=t[0];if(n.type===`list`&&r.type===`list`&&n.ordered===r.ordered&&n.delimiter===r.delimiter){let i={type:`list`,ordered:n.ordered,start:n.start,delimiter:n.delimiter,loose:!0,items:[...n.items,...r.items]};return[...e.slice(0,-1),i,...t.slice(1)]}return[...e,...t]}function sp(e,t,n){let r=df(n);if(t.autolink!==r.autolink&&(t.prevInput=``,t.settledText=``,t.settledBlocks=[],t.settledUpTo=0,t.autolink=r.autolink),e===``)return t.prevInput=``,t.settledText=``,t.settledBlocks=[],t.settledUpTo=0,t.linkDefsKey=void 0,[];let{defs:i}=gf(e),a=_f(i);t.linkDefsKey!==a&&(t.prevInput=``,t.settledText=``,t.settledBlocks=[],t.settledUpTo=0,t.linkDefsKey=a);let o=i.size>0?{...r,linkDefs:i}:r,s=e.split(`
|
|
113
113
|
`),c=rp(s);if(c<0)return t.prevInput=e,tp(e,o);let l=s.slice(0,c).join(`
|
|
114
114
|
`),u=ap(s.slice(c).join(`
|
|
115
|
-
`).trim()),d;if(l===t.settledText)d=t.settledBlocks;else if(t.settledText.length>0&&l.startsWith(t.settledText)){let e=tp(l.slice(t.settledText.length),o);d=op(t.settledBlocks,e)}else d=tp(l,o);let f=u?tp(u,o):[];return t.settledText=l,t.settledBlocks=d,t.settledUpTo=c,t.prevInput=e,op(d,f)}var cp={start:`0`,center:`auto`},lp={start:null,center:`auto`},up={k7Eaqz:`xkj4a21`,$$css:!0},dp={proseWidth:e=>[{ks0D6T:e==null?e:`xf68679`,$$css:!0},{"--x-maxWidth":(e=>typeof e==`number`?e+`px`:e??void 0)(e)}],proseAlign:e=>[{kUOVxO:e==null?e:`xvlecxo`,$$css:!0},{"--x-marginInline":(e=>typeof e==`number`?e+`px`:e??void 0)(e)}],blockWidth:e=>[up,{"--x-minWidth":(e=>typeof e==`number`?e+`px`:e??void 0)(`min(${e}, 100%)`)}],blockAlign:e=>[{kUOVxO:e==null?e:`xvlecxo`,$$css:!0},{"--x-marginInline":(e=>typeof e==`number`?e+`px`:e??void 0)(e)}],cellMinWidth:e=>[{k7Eaqz:e==null?e:`xkj4a21`,$$css:!0},{"--x-minWidth":(e=>typeof e==`number`?e+`px`:e??void 0)(e)}]},fp={center:{k9WMMc:`x2b8uid`,$$css:!0},end:{k9WMMc:`xp4054r`,$$css:!0}},$={root:{kMv6JI:`x9ynric`,kMwMTN:`x1tgivj0`,kLWn49:`xw6l6zx`,kGuDYH:`xjm74w1`,kzqmXN:`xh8yej3`,ks0D6T:`x193iq5w`,k7Eaqz:`xeuugli`,kHjlTd:`x1mzt3pk`,$$css:!0},inlineRoot:{k1xSpc:`xt0psk2`,kzqmXN:`x14atkfc`,ks0D6T:`x1x1rfll`,kMv6JI:`xjb2p0i`,kMwMTN:`x1heor9g`,kLWn49:`x15bjb6t`,kGuDYH:`x1qlqyl8`,$$css:!0},headingBase:{kMv6JI:`x1g81bgm`,kMwMTN:`x1tgivj0`,$$css:!0},h1:{kGuDYH:`xcg7oai`,k63SB2:`x1v68xuy`,kLWn49:`xfmsba7`,$$css:!0},h2:{kGuDYH:`x1xvnhcw`,k63SB2:`x12yy4cs`,kLWn49:`x1cpk1wn`,$$css:!0},h3:{kGuDYH:`xii13ha`,k63SB2:`x1jcxfy8`,kLWn49:`xwjzt0u`,$$css:!0},h4:{kGuDYH:`x8tkxat`,k63SB2:`x2hcmsi`,kLWn49:`xqerer`,$$css:!0},h5:{kGuDYH:`xsgqta0`,k63SB2:`xno150v`,kLWn49:`xo3gurs`,$$css:!0},h6:{kGuDYH:`xw5ohdf`,k63SB2:`x1pw4frv`,kLWn49:`xeixjfn`,$$css:!0},spacingHeadingMajorDefault:{keoZOQ:`x13rv44w`,k1K539:`xep27e5`,$$css:!0},spacingHeadingMinorDefault:{keoZOQ:`x1s1qpeq`,k1K539:`x1p37lm5`,$$css:!0},spacingParagraphDefault:{keoZOQ:`xj6sv8s`,k1K539:`xep27e5`,$$css:!0},spacingCodeblockDefault:{keoZOQ:`x1s1qpeq`,k1K539:`xwh1t77`,$$css:!0},spacingBlockquoteDefault:{keoZOQ:`x1s1qpeq`,k1K539:`xwh1t77`,$$css:!0},spacingListDefault:{keoZOQ:`xj6sv8s`,k1K539:`xep27e5`,$$css:!0},spacingTableDefault:{keoZOQ:`x1s1qpeq`,k1K539:`xwh1t77`,$$css:!0},spacingHrDefault:{keoZOQ:`x13rv44w`,k1K539:`x4d5cxa`,$$css:!0},spacingImageDefault:{keoZOQ:`xj6sv8s`,k1K539:`xep27e5`,$$css:!0},spacingHeadingMajorCompact:{keoZOQ:`x1s1qpeq`,k1K539:`x1p37lm5`,$$css:!0},spacingHeadingMinorCompact:{keoZOQ:`xj6sv8s`,k1K539:`x14cgwvg`,$$css:!0},spacingParagraphCompact:{keoZOQ:`xcsaf9d`,k1K539:`x14cgwvg`,$$css:!0},spacingCodeblockCompact:{keoZOQ:`xtbrsbv`,k1K539:`x1p37lm5`,$$css:!0},spacingBlockquoteCompact:{keoZOQ:`xtbrsbv`,k1K539:`x1p37lm5`,$$css:!0},spacingListCompact:{keoZOQ:`xcsaf9d`,k1K539:`x14cgwvg`,$$css:!0},spacingTableCompact:{keoZOQ:`xtbrsbv`,k1K539:`x1p37lm5`,$$css:!0},spacingHrCompact:{keoZOQ:`xj6sv8s`,k1K539:`xep27e5`,$$css:!0},spacingImageCompact:{keoZOQ:`xtbrsbv`,k1K539:`x1p37lm5`,$$css:!0},noMarginBlockStart:{keoZOQ:`xdj266r`,$$css:!0},noMarginBlockEnd:{k1K539:`xat24cr`,$$css:!0},codeBlockWrapper:{ks0D6T:`x193iq5w`,$$css:!0},tableWrapper:{kXHlph:`xw2csxc`,ks0D6T:`x193iq5w`,"--container-padding-inline-start":`xrhngw9`,"--container-padding-inline-end":`xjsfl84`,"--container-padding-block-start":`x1047aw6`,"--container-padding-block-end":`xax9j7h`,$$css:!0},blockIndent:{kUOVxO:`x1ho7dyk`,$$css:!0},hr:{kMzoRj:`xc342km`,kEafiO:`x11xkdxz`,kPef9Z:`x13fuv20`,kLZC3w:`x1pc3f07`,$$css:!0}};function pp(e){let t=e.match(/^([\d.]+)ms$/);if(t)return parseFloat(t[1]);let n=e.match(/^([\d.]+)s$/);return n?parseFloat(n[1])*1e3:null}function mp(e){let t=0;for(let n of e)switch(n.type){case`text`:t+=n.content.length;break;case`code`:t+=n.content.length;break;case`image`:t+=n.alt.length;break;case`bold`:case`italic`:case`strikethrough`:case`link`:t+=mp(n.children);break;case`break`:t+=1;break;case`citation`:t+=1}return t}function hp(e){let t=0;for(let n of e)switch(n.type){case`heading`:case`paragraph`:t+=mp(n.children);break;case`codeblock`:t+=n.content.length;break;case`blockquote`:t+=hp(n.children);break;case`list`:for(let e of n.items)t+=hp(e.children);break;case`table`:for(let e of n.headers)t+=mp(e.children);for(let e of n.rows)for(let n of e)t+=mp(n.children);break;case`hr`:break;case`image`:t+=n.alt.length}return t}var gp={1:$.h1,2:$.h2,3:$.h3,4:$.h4,5:$.h5,6:$.h6},_p=/^(javascript|data|vbscript):/i;function vp(e){let t=e.trim();return t.length===0||_p.test(t)?null:t}function yp(e,t){let n=[];for(let r of t){r.pattern.lastIndex=0;let t;for(;(t=r.pattern.exec(e))!==null;){let i;if(r.getEndIndex){let n=r.getEndIndex(e,t);if(n===!1)continue;i=n}else i=t.index+t[0].length;n.push({start:t.index,end:i,match:t,plugin:r})}}n.sort((e,t)=>e.start-t.start);let r=[],i=0;for(let e of n)e.start>=i&&(r.push(e),i=e.end);if(r.length===0)return[{type:`text`,content:e}];let a=[],o=0;for(let t=0;t<r.length;t++){let n=r[t];n.start>o&&a.push({type:`text`,content:e.slice(o,n.start)}),a.push({type:`plugin`,element:n.plugin.render(n.match,`plugin-${t}`),matchLength:n.end-n.start}),o=n.end}return o<e.length&&a.push({type:`text`,content:e.slice(o)}),a}function bp(e,t,n){let r=t.offset;if(t.offset+=e.length,!t.active)return e;let i=sf(e,r,t.boundaries,n);if(i==null)return e;let a=i.map(e=>e.fading?(0,B.jsx)(`span`,{className:`x1hc1fzr x19991ni x80gvsz x12w9bfk xlr8y92 x4itv7f`,children:e.text},e.key):(0,B.jsx)(`span`,{children:e.text},e.key));return(0,B.jsx)(`span`,{children:a},`wrap-${n}`)}function xp(e,t){let n=e.numberMap.get(t);return n??(n=e.nextNumber++,e.numberMap.set(t,n)),n}function Sp(e,t,n,r,i,a=`a`,o,s){switch(e.type){case`text`:if(o&&o.length>0){let n=yp(e.content,o);if(n.length!==1||n[0].type!==`text`){let e=[];for(let i=0;i<n.length;i++){let a=n[i];a.type===`text`?e.push(bp(a.content,r,`${t}-seg-${i}`)):(r.offset+=a.matchLength,e.push((0,B.jsx)(v.Fragment,{children:a.element},`plugin-${t}-${i}`)))}return(0,B.jsx)(v.Fragment,{children:e},t)}}return bp(e.content,r,t);case`bold`:return(0,B.jsx)(`strong`,{className:`x2mo6ok`,children:e.children.map((e,t)=>Sp(e,t,n,r,i,a,o,s))},t);case`italic`:return(0,B.jsx)(`em`,{children:e.children.map((e,t)=>Sp(e,t,n,r,i,a,o,s))},t);case`strikethrough`:return(0,B.jsx)(`del`,{className:`xv1l7n4`,children:e.children.map((e,t)=>Sp(e,t,n,r,i,a,o,s))},t);case`code`:{r.offset+=e.content.length;let n=s?.inlineCode;return n?(0,B.jsx)(n,{children:e.content},t):(0,B.jsx)(pc,{children:e.content},t)}case`link`:{let c=vp(e.href);if(c==null)return(0,B.jsx)(`span`,{children:e.children.map((e,t)=>Sp(e,t,n,r,i,a,o,s))},t);let l=s?.link;if(l)return(0,B.jsx)(l,{href:c,children:e.children.map((e,t)=>Sp(e,t,n,r,i,a,o,s))},t);let u=c.startsWith(`https://`)||c.startsWith(`http://`);return(0,B.jsx)(u?`a`:a,{href:c,onClick:n?e=>{n(c,e)===!1&&e.preventDefault()}:void 0,...u?{target:`_blank`,rel:`noopener noreferrer`}:{},className:`xjse4m1 x1bvjpef`,children:e.children.map((e,t)=>Sp(e,t,n,r,i,a,o,s))},t)}case`image`:{let n=vp(e.src);if(n==null)return(0,B.jsxs)(`span`,{children:[`[`,e.alt,`]`]},t);let r=s?.image;return r?(0,B.jsx)(r,{src:n,alt:e.alt},t):(0,B.jsx)(`img`,{src:n,alt:e.alt,className:`x193iq5w xh6dtrn`},t)}case`break`:return r.offset+=1,(0,B.jsx)(`br`,{},t);case`citation`:{if(r.offset+=1,!i)return(0,B.jsxs)(`span`,{children:[`[`,e.sourceId,`]`]},t);let n=xp(i,e.sourceId),a=i.sources[e.sourceId]??{title:e.sourceId},o=i.style===`number`?`number`:`label`,c=s?.citation;return c?(0,B.jsx)(c,{source:a,number:n,variant:o},t):(0,B.jsx)(lf,{source:a,number:n,variant:o},t)}}}function Cp(e,t){let n=t===`compact`;switch(e.type){case`heading`:return e.level<=3?n?$.spacingHeadingMajorCompact:$.spacingHeadingMajorDefault:n?$.spacingHeadingMinorCompact:$.spacingHeadingMinorDefault;case`paragraph`:return n?$.spacingParagraphCompact:$.spacingParagraphDefault;case`codeblock`:return n?$.spacingCodeblockCompact:$.spacingCodeblockDefault;case`blockquote`:return n?$.spacingBlockquoteCompact:$.spacingBlockquoteDefault;case`list`:return n?$.spacingListCompact:$.spacingListDefault;case`table`:return n?$.spacingTableCompact:$.spacingTableDefault;case`hr`:return n?$.spacingHrCompact:$.spacingHrDefault;case`image`:return n?$.spacingImageCompact:$.spacingImageDefault}}function wp(e){return e.headers.map((t,n)=>{let r=mp(t.children);for(let t of e.rows)if(t[n]){let e=mp(t[n].children);e>r&&(r=e)}return r<=6?60:r<=15?80:120})}function Tp(e,t,n,r,i,a,o,s,c,l,u=`a`,d,f,p){let m=lp[l],h=m==null?null:dp.blockAlign(m),g=Cp(e,r),_=t===0,v=t===n-1;switch(e.type){case`heading`:{let n=Math.min(e.level+i-1,6),p=e.children.map((e,t)=>Sp(e,t,a,o,s,u,d,f)),m=f?.heading;if(m)return(0,B.jsx)(m,{level:n,children:p},t);let h=`h${n}`;return(0,B.jsx)(h,{...H(U(`markdown-heading`,{density:r,level:n}),w($.headingBase,gp[n],g,c==null?null:dp.proseWidth(c),l===`start`?null:dp.proseAlign(cp[l]),_&&$.noMarginBlockStart,v&&$.noMarginBlockEnd)),children:p},t)}case`paragraph`:{let n=e.children.map((e,t)=>Sp(e,t,a,o,s,u,d,f)),i=f?.paragraph;return i?(0,B.jsx)(i,{children:n},t):(0,B.jsx)(`div`,{role:`paragraph`,...H(U(`markdown-paragraph`,{density:r}),w(g,c==null?null:dp.proseWidth(c),l===`start`?null:dp.proseAlign(cp[l]),_&&$.noMarginBlockStart,v&&$.noMarginBlockEnd)),children:n},t)}case`codeblock`:{o.offset+=e.content.length;let n=f?.code;return n?(0,B.jsx)(n,{code:e.content,language:e.language},t):(0,B.jsx)(`div`,{...H(U(`markdown-codeblock`,{density:r}),w(g,$.codeBlockWrapper,_&&$.noMarginBlockStart,v&&$.noMarginBlockEnd)),children:(0,B.jsx)(lc,{code:e.content,language:e.language,isCollapsible:!0,xstyle:[c==null?void 0:dp.blockWidth(c),h]})},t)}case`blockquote`:{let n=f?.blockquote;if(n){let m=e.children.map((t,n)=>Tp(t,n,e.children.length,r,i,a,o,s,c,l,u,d,f,p));return(0,B.jsx)(n,{children:m},t)}return(0,B.jsx)(Su,{...U(`markdown-blockquote`,{density:r}),xstyle:[g,c==null?void 0:dp.proseWidth(c),l===`start`?void 0:dp.proseAlign(cp[l]),_&&$.noMarginBlockStart,v&&$.noMarginBlockEnd],children:e.children.map((t,n)=>Tp(t,n,e.children.length,r,i,a,o,s,c,l,u,d,f,p))},t)}case`list`:if(e.items.length>0&&e.items.every(e=>e.checked!=null)){let n=e.items.map((e,t)=>({item:e,key:`task-${t}`})).filter(({item:e})=>e.checked).map(({key:e})=>e);return(0,B.jsx)(`div`,{...H(U(`markdown-list`,{density:r}),w(g,_&&$.noMarginBlockStart,v&&$.noMarginBlockEnd)),children:(0,B.jsx)(Bl,{label:p(`@astryx.markdown.taskList`),isLabelHidden:!0,value:n,xstyle:$.blockIndent,isReadOnly:!0,density:`compact`,children:e.items.map((e,t)=>{let n=e.children[0],m=e.children.length===1&&n?.type===`paragraph`?(0,B.jsx)(B.Fragment,{children:n.children.map((e,t)=>Sp(e,t,a,o,s,u,d,f))}):(0,B.jsx)(B.Fragment,{children:e.children.map((t,n)=>Tp(t,n,e.children.length,r,i,a,o,s,c,l,u,d,f,p))});return(0,B.jsx)(bu,{value:`task-${t}`,label:m},t)})})},t)}return(0,B.jsx)(`div`,{...H(U(`markdown-list`,{density:r}),w(g,c==null?null:dp.proseWidth(c),l===`start`?null:dp.proseAlign(cp[l]),_&&$.noMarginBlockStart,v&&$.noMarginBlockEnd)),children:(0,B.jsx)(Y,{listStyle:e.ordered?`decimal`:`disc`,density:`compact`,start:e.ordered?e.start:void 0,xstyle:$.blockIndent,children:e.items.map((e,t)=>{let n=e.children[0],m=e.children.length===1&&n?.type===`paragraph`?(0,B.jsx)(B.Fragment,{children:n.children.map((e,t)=>Sp(e,t,a,o,s,u,d,f))}):(0,B.jsx)(B.Fragment,{children:e.children.map((t,n)=>Tp(t,n,e.children.length,r,i,a,o,s,c,l,u,d,f,p))});return(0,B.jsx)(vu,{label:m},t)})})},t);case`table`:{let n=wp(e);return(0,B.jsx)(`div`,{tabIndex:0,role:`group`,"aria-label":p(`@astryx.markdown.table`),...H(U(`markdown-table`,{density:r}),w($.tableWrapper,g,c==null?null:dp.blockWidth(c),lp[l]==null?null:dp.blockAlign(lp[l]),_&&$.noMarginBlockStart,v&&$.noMarginBlockEnd)),children:(0,B.jsxs)(af,{dividers:`rows`,textOverflow:`wrap`,children:[(0,B.jsx)(Nd,{children:(0,B.jsx)(Bu,{children:e.headers.map((t,r)=>(0,B.jsx)(Md,{xstyle:[dp.cellMinWidth(`${n[r]}px`),e.alignments[r]===`center`&&fp.center,e.alignments[r]===`right`&&fp.end],children:t.children.map((e,t)=>Sp(e,t,a,o,s,u,d,f))},r))})}),(0,B.jsx)(Pd,{children:e.rows.map((t,n)=>{let r=t.map((t,n)=>(0,B.jsx)(Dd,{xstyle:[e.alignments[n]===`center`&&fp.center,e.alignments[n]===`right`&&fp.end],children:t.children.map((e,t)=>Sp(e,t,a,o,s,u,d,f))},n));return(0,B.jsx)(Bu,{children:r},n)})})]})},t)}case`hr`:{let e=f?.hr;return e?(0,B.jsx)(e,{},t):(0,B.jsx)(`hr`,{...H(U(`markdown-hr`,{density:r}),w($.hr,g,_&&$.noMarginBlockStart,v&&$.noMarginBlockEnd))},t)}case`image`:{let n=vp(e.src);if(n==null)return(0,B.jsxs)(`div`,{...H(U(`markdown-image`,{density:r}),w(g,_&&$.noMarginBlockStart,v&&$.noMarginBlockEnd)),children:[`[`,e.alt,`]`]},t);let i=f?.image;return i?(0,B.jsx)(i,{src:n,alt:e.alt},t):(0,B.jsx)(`div`,{...H(U(`markdown-image`,{density:r}),w(g,_&&$.noMarginBlockStart,v&&$.noMarginBlockEnd)),children:(0,B.jsx)(`img`,{src:n,alt:e.alt,className:`x193iq5w xh6dtrn`})},t)}}}function Ep({ref:e,children:t,display:n=`block`,density:r=`default`,headingLevelStart:i=1,isStreaming:a=!1,onLinkClick:o,sources:s,citationStyle:c=`label`,contentWidth:l=680,contentAlign:u=`start`,components:d,inlinePlugins:f,autolink:p,xstyle:m,className:h,style:g,"data-testid":_}){let y=ds(),b=Pa(),x=(0,v.useMemo)(()=>s?new Set(Object.keys(s)):void 0,[s]),S=(0,v.useMemo)(()=>({sourceIds:x,autolink:p}),[x,p]),C=pl(t,a),T=(0,v.useRef)(np()),E=(0,v.useRef)(p);E.current!==p&&(T.current=np(),E.current=p);let D=(0,v.useMemo)(()=>n===`inline`?[]:a?C===``?(T.current=np(),[]):sp(ip(C),T.current,S):ep(t,S),[n,C,t,a,S]),O=(0,v.useMemo)(()=>n===`inline`?wf(a?ip(C):t,S):[],[n,C,t,a,S]),{token:k}=xt(),A=(0,v.useMemo)(()=>{let e=pp(k(`--duration-fast-max`))??230,t=pp(k(`--duration-fast-min`)),n=t==null?50:Math.max(4,Math.round(t/10));return Math.min(Math.ceil(e/n),12)},[k]),j=(0,v.useRef)([]),M=(0,v.useRef)([]),N=(0,v.useRef)([]),ee=C.length,P={offset:0,boundaries:(0,v.useMemo)(()=>{let e=n===`inline`?mp(M.current):hp(j.current),t=of(N.current,e,A);return N.current=t,t},[n,ee,A]),active:a},F=s?{sources:s,numberMap:new Map,nextNumber:1,style:c}:null;if(n===`inline`){let t=(0,B.jsx)(`span`,{ref:e,"data-testid":_,...H(U(`markdown`,{density:r}),w($.root,$.inlineRoot,m),h,g),children:O.map((e,t)=>Sp(e,t,o,P,F,b,f,d))});return M.current=O,j.current=[],t}let I=(0,B.jsx)(`div`,{role:`document`,ref:e,"data-testid":_,...H(U(`markdown`,{density:r}),w($.root,m),h,g),children:D.map((e,t)=>Tp(e,t,D.length,r,i,o,P,F,l?typeof l==`number`?`${l}px`:l:null,u,b,f,d,y))});return j.current=D,M.current=[],I}Ep.displayName=`Markdown`;function Dp(e){return e.split(`/`).pop()??e}function Op(e){let t=e.split(`/`);return t.length<=1?``:t.slice(0,-1).join(`/`)}function kp(e){let t=e.toLowerCase();return t.endsWith(`.md`)||t.endsWith(`.markdown`)}function Ap(e){let t=e.split(`/`).pop()??e;return/\.(png|jpe?g|gif|webp)$/i.test(t)}function jp(e){let t=e.toLowerCase();return t.endsWith(`.md`)||t.endsWith(`.markdown`)?`markdown`:t.endsWith(`.json`)?`json`:t.endsWith(`.yaml`)||t.endsWith(`.yml`)?`yaml`:t.endsWith(`.ts`)||t.endsWith(`.tsx`)?`typescript`:t.endsWith(`.js`)||t.endsWith(`.jsx`)?`javascript`:t.endsWith(`.py`)?`python`:t.endsWith(`.sh`)?`bash`:t.endsWith(`.html`)?`html`:t.endsWith(`.css`)?`css`:(t.endsWith(`.txt`),`plaintext`)}function Mp({runId:e,path:t,readOnly:n,onBackToTranscript:r,onHide:i}){let a=kp(t),o=Ap(t),[s,c]=(0,v.useState)(a||o?`rendered`:`raw`),[l,u]=(0,v.useState)({status:`loading`});return(0,v.useEffect)(()=>{c(kp(t)||Ap(t)?`rendered`:`raw`)},[t]),(0,v.useEffect)(()=>{if(Ap(t)){u({status:`ready`,content:``});return}let n=!1;return u({status:`loading`}),ar(e,t).then(e=>{n||u({status:`ready`,content:e})}).catch(e=>{n||u({status:`error`,message:e instanceof Error?e.message:String(e)})}),()=>{n=!0}},[e,t]),(0,B.jsxs)(`div`,{className:`reader`,style:{height:`100%`},children:[(0,B.jsxs)(`div`,{className:`reader__bar`,children:[(0,B.jsx)(`span`,{className:`reader__name`,children:Dp(t)}),Op(t)?(0,B.jsx)(`span`,{className:`reader__path`,children:Op(t)}):null,n?(0,B.jsx)(`span`,{className:`chip`,children:`read only`}):null,(0,B.jsx)(`span`,{className:`topbar__spacer`}),(0,B.jsxs)(`div`,{className:`stream__head-trail`,children:[(0,B.jsx)(`button`,{className:`btn btn--ghost btn--sm`,onClick:r,children:`← Transcript`}),i?(0,B.jsx)(`button`,{type:`button`,className:`btn btn--sm`,onClick:i,children:`Hide workspace`}):null,(0,B.jsxs)(`div`,{className:`seg`,children:[(0,B.jsx)(`button`,{"data-active":s===`rendered`?`true`:void 0,disabled:!a&&!o,onClick:()=>{(a||o)&&c(`rendered`)},children:`Rendered`}),(0,B.jsx)(`button`,{"data-active":s===`raw`?`true`:void 0,disabled:o,onClick:()=>{o||c(`raw`)},children:`Raw`}),(0,B.jsx)(`button`,{disabled:!0,children:`Diff`})]})]})]}),(0,B.jsxs)(`div`,{className:`reader__body`,children:[l.status===`loading`?(0,B.jsx)(`p`,{className:`muted`,style:{padding:`var(--spacing-6)`},children:`Loading…`}):null,l.status===`error`?(0,B.jsx)(`div`,{style:{padding:`var(--spacing-6)`},children:(0,B.jsxs)(`div`,{className:`gate`,style:{padding:`var(--spacing-4)`,borderColor:`var(--color-border-red)`,borderLeftColor:`var(--color-error)`,background:`var(--color-background-red)`,color:`var(--color-text-red)`},children:[(0,B.jsx)(`div`,{className:`gate__label`,style:{color:`var(--color-text-red)`},children:`Could not load artifact`}),(0,B.jsx)(`p`,{className:`gate__question`,style:{color:`var(--color-text-primary)`},children:l.message})]})}):null,l.status===`ready`?(0,B.jsx)(`div`,{className:`page`,children:o?(0,B.jsx)(`img`,{src:`/api/runs/${encodeURIComponent(e)}/artifact?path=${encodeURIComponent(t)}`,alt:Dp(t),style:{maxWidth:`100%`,height:`auto`,display:`block`}}):s===`rendered`&&a?l.content.trim().length===0?(0,B.jsx)(`p`,{className:`muted`,children:`Empty file.`}):(0,B.jsx)(Ep,{headingLevelStart:2,contentWidth:`76ch`,children:l.content}):(0,B.jsx)(lc,{code:l.content,language:jp(t),title:Dp(t),container:`section`,width:`100%`})}):null]})]})}function Np({question:e,note:t,onNoteChange:n,onAccept:r,onReject:i,isSubmitting:a,error:o,refs:s,children:c}){let l=!!a;return(0,B.jsxs)(`div`,{className:`decide`,style:{height:`100%`},children:[(0,B.jsxs)(`div`,{className:`decide__gate`,children:[(0,B.jsxs)(`div`,{className:`decide__label`,children:[(0,B.jsx)(`span`,{className:`dot dot--waiting`}),Ur(),` · artifact_backed`]}),(0,B.jsx)(`p`,{className:`decide__q`,children:e}),s?(0,B.jsx)(`div`,{className:`decide__refs`,children:s}):null,o?(0,B.jsx)(`div`,{className:`gate`,style:{padding:`var(--spacing-3)`,marginBottom:`var(--spacing-3)`,borderColor:`var(--color-border-red)`,borderLeftColor:`var(--color-error)`,background:`var(--color-background-red)`,color:`var(--color-text-red)`},children:(0,B.jsxs)(`p`,{style:{margin:0,fontSize:`var(--font-size-sm)`},children:[`Could not submit answer: `,o]})}):null,(0,B.jsx)(`textarea`,{value:t,onChange:e=>n(e.target.value),disabled:l,placeholder:`Optional review notes`,rows:3}),(0,B.jsxs)(`div`,{className:`decide__buttons`,children:[(0,B.jsx)(`button`,{className:`btn btn--accept`,disabled:l,onClick:r,children:a?`Submitting…`:`Accept`}),(0,B.jsx)(`button`,{className:`btn btn--reject`,disabled:l,onClick:i,children:`Reject`})]})]}),c?(0,B.jsx)(`div`,{className:`decide__body`,children:c}):null]})}function Pp(e){if(!e||typeof e!=`object`)return null;let t=e.kind;return t===`free_text`||t===`confirm`||t===`multi_question`||t===`artifact_backed`?e:null}function Fp(e){if(!e||typeof e!=`object`)return null;let t=e.kind;return t===`free_text`||t===`confirm`||t===`multi_question`||t===`artifact_backed`?e:null}function Ip(e){let t=0;for(let n of e)n.event===`operator_prompt`&&Pp(n.prompt)?.kind===`artifact_backed`&&(t+=1);return Math.max(t,1)}function Lp(e){let t=[];return e.forEach((e,n)=>{if(e.event===`operator_prompt`){t.push({key:`ask-${e.at??n}`,label:`Asked you`,at:e.at});return}if(e.event!==`operator_answer`)return;let r=Fp(e.answer),i=`Answered`,a;r?.kind===`artifact_backed`||r?.kind===`confirm`?(i=r.decision===`reject`?`Rejected`:`Accepted`,a=r.text):r?.kind===`free_text`&&(a=r.text),t.push({key:`ans-${e.at??n}`,label:i,at:e.at,note:a})}),t}function Rp(e){if(!e)return``;try{let t=new Date(e),n=Math.round((Date.now()-t.getTime())/1e3);return n<60?`just now`:n<3600?`${Math.floor(n/60)}m ago`:n<86400?`${Math.floor(n/3600)}h ago`:t.toLocaleDateString()}catch{return``}}function zp({runId:e,stageId:t,prompt:n,events:r,inboundEnvelope:i,inboundFromStageId:a,inboundToStageId:o,selectedPath:s,onSelectArtifact:c,onOpenInboundEnvelope:l}){let[u,d]=(0,v.useState)(``),{submitting:f,error:p,locked:m,submitIntent:h}=zc(e,t,{promptId:n.id,kind:n.kind}),g=Ip(r),_=Lp(r);async function y(e){await h({type:`decision`,decision:e,note:u})}let b=a&&o?`${a} → ${o}`:a??`previous stage`;return(0,B.jsxs)(Np,{question:n.message,note:u,onNoteChange:d,onAccept:()=>void y(`accept`),onReject:()=>void y(`reject`),isSubmitting:f||m,error:p,refs:n.artifacts.length>0?(0,B.jsx)(B.Fragment,{children:n.artifacts.map(e=>(0,B.jsx)(`button`,{className:`chip${e===s?` chip--active`:``}`,onClick:()=>c(e),style:e===s?{borderColor:`var(--color-warning)`,background:`var(--color-background-yellow)`}:void 0,children:e.split(`/`).pop()??e},e))}):void 0,children:[(0,B.jsxs)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`},children:[`Iteration `,g,`. A rejection returns to the same live session, which revises this file and asks again — the stage is not restarted.`]}),_.length>0?(0,B.jsxs)(`div`,{style:{marginTop:`var(--spacing-3)`},children:[(0,B.jsx)(`strong`,{style:{fontSize:`var(--font-size-sm)`},children:`Review history`}),_.map(e=>(0,B.jsxs)(`div`,{style:{marginTop:`var(--spacing-2)`},children:[(0,B.jsx)(`span`,{style:{fontSize:`var(--font-size-sm)`,fontWeight:500},children:e.label}),e.at?(0,B.jsx)(`span`,{className:`muted`,style:{fontSize:`var(--font-size-xs)`,marginLeft:`var(--spacing-2)`,fontFamily:`var(--font-family-code)`},children:Rp(e.at)}):null,e.note?(0,B.jsx)(`p`,{className:`muted`,style:{margin:`2px 0 0`,fontSize:`var(--font-size-sm)`},children:e.note}):null]},e.key))]}):null,i?(0,B.jsxs)(`div`,{style:{marginTop:`var(--spacing-3)`},children:[(0,B.jsx)(`strong`,{style:{fontSize:`var(--font-size-sm)`},children:`Inbound context`}),(0,B.jsx)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`,margin:`2px 0 var(--spacing-2)`},children:i.summary}),l?(0,B.jsx)(`button`,{className:`btn btn--ghost btn--sm`,onClick:l,children:b}):(0,B.jsx)(`span`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`},children:b})]}):null]})}function Bp({envelope:e,onArtifactClick:t,payloadMaxHeight:n=280}){return(0,B.jsxs)(`div`,{className:`drawer__grid`,children:[(0,B.jsxs)(`dl`,{className:`kv`,children:[(0,B.jsx)(`dt`,{children:`Summary`}),(0,B.jsx)(`dd`,{children:e.summary}),(0,B.jsx)(`dt`,{children:`Artifacts`}),(0,B.jsx)(`dd`,{children:e.artifacts.length===0?(0,B.jsx)(`span`,{className:`muted`,children:`none`}):e.artifacts.map(e=>{let n=e.split(`/`).pop()??e;return t?(0,B.jsxs)(`button`,{type:`button`,className:`chip chip--file`,onClick:()=>t(e),children:[`◆ `,n]},e):(0,B.jsxs)(`span`,{className:`chip chip--file`,children:[`◆ `,n]},e)})}),e.notes?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`dt`,{children:`Notes`}),(0,B.jsx)(`dd`,{className:`muted`,children:e.notes})]}):null]}),e.payload?(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`div`,{className:`eyebrow`,style:{marginBottom:`var(--spacing-2)`},children:`payload`}),(0,B.jsx)(lc,{code:JSON.stringify(e.payload,null,2),language:`json`,container:`section`,maxHeight:n,width:`100%`})]}):(0,B.jsx)(`p`,{className:`muted`,children:`No payload.`})]})}function Vp(e,t,n){let r=e=>n?.(e)??e;return t?`${r(e)} → ${r(t)}`:r(e)}function Hp({fromStageId:e,toStageId:t,envelope:n,onBackToTranscript:r,onHide:i,onArtifactClick:a,stageLabel:o}){let s=Vp(e,t,o);return(0,B.jsxs)(`div`,{className:`stream`,style:{height:`100%`},children:[(0,B.jsxs)(`header`,{className:`stream__head`,children:[(0,B.jsx)(`h3`,{className:`stream__name`,children:`Handoff envelope`}),(0,B.jsx)(`span`,{className:`mono muted`,children:s}),(0,B.jsx)(`span`,{className:`topbar__spacer`}),(0,B.jsxs)(`div`,{className:`stream__head-trail`,children:[(0,B.jsx)(`button`,{type:`button`,className:`btn btn--sm`,onClick:r,children:`← Transcript`}),i?(0,B.jsx)(`button`,{type:`button`,className:`btn btn--sm`,onClick:i,children:`Hide workspace`}):null]})]}),(0,B.jsx)(`div`,{className:`stream__body`,children:(0,B.jsx)(Bp,{envelope:n,onArtifactClick:a,payloadMaxHeight:480})})]})}function Up(e){return e===`success`?`status status--succeeded`:e===`failure`?`status status--failed`:`status`}function Wp(e){return e===`success`?`dot dot--succeeded`:e===`failure`?`dot dot--failed`:`dot`}function Gp({isOpen:e,onClose:t,fromStageId:n,toStageId:r,envelope:i,onOpenFullRecord:a,onArtifactClick:o}){let s=r?`${n} → ${r}`:n;return(0,v.useEffect)(()=>{if(!e)return;function n(e){e.key===`Escape`&&t()}return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,t]),(0,B.jsxs)(`aside`,{className:`drawer`,hidden:!e,children:[(0,B.jsxs)(`div`,{className:`drawer__head`,children:[(0,B.jsx)(`span`,{className:`eyebrow`,children:`Handoff envelope`}),(0,B.jsx)(`span`,{className:`mono muted`,children:s}),(0,B.jsxs)(`span`,{className:Up(i.status),children:[(0,B.jsx)(`span`,{className:Wp(i.status)}),` `,i.status]}),(0,B.jsx)(`span`,{style:{marginLeft:`auto`}}),a?(0,B.jsx)(`button`,{type:`button`,className:`btn btn--sm`,onClick:a,children:`Open full record`}):null,(0,B.jsx)(`button`,{type:`button`,className:`btn btn--sm`,onClick:t,children:`Close`})]}),(0,B.jsx)(Bp,{envelope:i,onArtifactClick:o})]})}function Kp(e){let t={submitting:!1,error:null},n=new Set,r=()=>t,i=()=>{for(let e of n)e()};return{getState:r,decide:async(n,r)=>{if(!t.submitting){t={submitting:!0,error:null},i();try{await e.submit(n,r),await e.onSuccess()}catch(e){t={...t,error:e instanceof Error?e.message:String(e)}}finally{t={...t,submitting:!1},i()}}},clearError:()=>{t.error!==null&&(t={...t,error:null},i())},subscribe:e=>(n.add(e),()=>{n.delete(e)})}}function qp(e,t){let n=(0,v.useRef)(e);n.current=e;let r=(0,v.useRef)(t);r.current=t;let i=(0,v.useRef)(null);i.current===null&&(i.current=Kp({submit:async(e,t)=>{await nr(n.current,e,t)},onSuccess:()=>r.current()}));let a=i.current,[o,s]=(0,v.useState)(()=>a.getState());(0,v.useEffect)(()=>a.subscribe(()=>s(a.getState())),[a]);let c=(0,v.useCallback)((e,t)=>void a.decide(e,t),[a]),l=(0,v.useCallback)(()=>a.clearError(),[a]);return{submitting:o.submitting,error:o.error,decide:c,clearError:l}}function Jp({runId:e,decide:t,onSuccess:n}){let[r,i]=(0,v.useState)(``),{submitting:a,error:o,decide:s}=qp(e,n),c=a,l=t.replayNumber!==void 0&&t.maxReplays!==void 0?`Replay ${t.replayNumber} of ${t.maxReplays}`:t.maxReplays===void 0?null:`Max ${t.maxReplays} replays`;function u(e){let n=r.trim();s(t.sourceStageId,{decision:e,loopId:t.loopId,...n?{reason:n}:{}})}return(0,B.jsx)(`div`,{className:`decide feedback-decide`,style:{height:`100%`},children:(0,B.jsxs)(`div`,{className:`decide__gate`,children:[(0,B.jsxs)(`div`,{className:`decide__label`,children:[(0,B.jsx)(`span`,{className:`dot dot--waiting`}),Ur(),` · feedback_loop_decision`]}),(0,B.jsx)(`p`,{className:`decide__q`,children:t.summary??`Feedback loop limit reached — extend, continue, or abandon`}),(0,B.jsxs)(`div`,{className:`decide__refs`,children:[(0,B.jsxs)(`span`,{children:[`Source `,(0,B.jsx)(`strong`,{children:t.sourceStageId})]}),t.deferredTarget?(0,B.jsxs)(`span`,{children:[`Target `,(0,B.jsx)(`strong`,{children:t.deferredTarget})]}):null,l?(0,B.jsx)(`span`,{children:l}):null]}),o?(0,B.jsx)(`div`,{className:`gate`,style:{padding:`var(--spacing-3)`,marginBottom:`var(--spacing-3)`,borderColor:`var(--color-border-red)`,borderLeftColor:`var(--color-error)`,background:`var(--color-background-red)`,color:`var(--color-text-red)`},children:(0,B.jsxs)(`p`,{style:{margin:0,fontSize:`var(--font-size-sm)`},children:[`Could not submit decision: `,o]})}):null,(0,B.jsx)(`textarea`,{value:r,onChange:e=>i(e.target.value),disabled:c,placeholder:`Optional reason`,rows:3}),(0,B.jsxs)(`div`,{className:`decide__buttons`,children:[(0,B.jsx)(`button`,{className:`btn btn--accept`,disabled:c,onClick:()=>u(`extend`),children:a?`Submitting…`:`Extend`}),(0,B.jsx)(`button`,{className:`btn btn--primary`,disabled:c,onClick:()=>u(`continue`),children:`Continue`}),(0,B.jsx)(`button`,{className:`btn btn--reject`,disabled:c,onClick:()=>u(`abandon`),children:`Abandon`})]}),(0,B.jsx)(`p`,{className:`decide__hint`,children:`Extend raises the replay budget and continues the deferred send-back. Continue accepts the limit and advances. Abandon stops the loop.`})]})})}function Yp(e){return`Replay ${e.current_replay_number??0} of ${e.policy.max_replays}`}function Xp(e){for(let t=e.length-1;t>=0;t--){let n=e[t]?.replays;if(!n||n.length===0)continue;let r=n[n.length-1]?.replay;if(r?.target_stage_id)return r.target_stage_id}return null}function Zp(e,t){let n=e.deferred_send_back?.target??Xp(t)??e.policy.target??null;return n?`${e.source_stage_id} → ${n}`:null}function Qp(e){switch(e){case`waiting_for_human`:return`status status--waiting`;case`completed`:case`continued`:return`status status--succeeded`;case`abandoned`:return`status status--failed`;default:return`status`}}function $p({active:e,history:t}){if(!e&&t.length===0)return null;let n=e??t[t.length-1]?.loop,r=n?Zp(n,t):null,i=n?r??Yp(n):null,a=n?.state===`waiting_for_human`,o=t.flatMap(e=>e.replays),s=t.reduce((e,t)=>{let n=t.fork_generations.filter(e=>e.status===`superseded`).length;for(let e of t.replays)n+=e.fork_generations.filter(e=>e.status===`superseded`).length;return e+n},0);return(0,B.jsx)(`section`,{className:`feedback-loop-panel block`,children:(0,B.jsx)(xc,{trigger:(0,B.jsxs)(`span`,{className:`feedback-loop-panel__trigger`,children:[(0,B.jsx)(`span`,{className:`block__pipeline`,children:`Feedback loop`}),n?(0,B.jsx)(`span`,{className:Qp(n.state),children:n.state.replaceAll(`_`,` `)}):null,i?(0,B.jsx)(`span`,{className:`feedback-loop-panel__summary`,children:i}):null]}),defaultIsOpen:a,children:(0,B.jsxs)(`div`,{className:`feedback-loop-panel__body`,children:[n?(0,B.jsxs)(`dl`,{className:`kv`,children:[(0,B.jsx)(`dt`,{children:`Budget`}),(0,B.jsx)(`dd`,{children:Yp(n)}),r?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`dt`,{children:`Route`}),(0,B.jsx)(`dd`,{children:r})]}):null,(0,B.jsx)(`dt`,{children:`Session`}),(0,B.jsx)(`dd`,{children:n.policy.replay_session})]}):null,o.length>0?(0,B.jsxs)(`div`,{className:`feedback-loop-panel__timeline`,children:[(0,B.jsx)(`div`,{className:`decide__label`,children:`Replay timeline`}),(0,B.jsx)(`ol`,{className:`feedback-loop-panel__list`,children:o.map(({replay:e,stage_passes:t})=>(0,B.jsxs)(`li`,{children:[(0,B.jsxs)(`span`,{children:[`#`,e.replay_number,` `,e.source_stage_id,` →`,` `,e.target_stage_id]}),(0,B.jsxs)(`span`,{className:`feedback-loop-panel__status`,children:[e.status.replaceAll(`_`,` `),t.length>0?` · ${t.length} stage pass${t.length===1?``:`es`}`:``]})]},e.replay_id))})]}):null,s>0?(0,B.jsxs)(`p`,{className:`block__sub`,children:[s,` superseded fork generation`,s===1?``:`s`,` hidden from the map.`]}):null]})},a?`waiting`:`idle`)})}var em=160;function tm(e,t=em){let n=e.trim();return n.length<=t?n:`${n.slice(0,t)}…`}function nm(e){let t=e.prompt;if(!t||typeof t!=`object`)return;let n=t;if(n.kind===`multi_question`){let e=n.questions?.length??0;return e===1?`1 question`:`${e} questions`}if(typeof n.message==`string`&&n.message.trim())return tm(n.message)}function rm(e){let t=e.answer;if(!t||typeof t!=`object`)return;let n=t;if(n.kind===`free_text`)return typeof n.text==`string`?tm(n.text):void 0;if(n.kind===`confirm`||n.kind===`artifact_backed`){let e=n.decision,t=typeof n.text==`string`&&n.text.trim()?tm(n.text):void 0;return e&&t?`${e} — ${t}`:e||t}if(n.kind===`multi_question`){let e=Object.keys(n.answers??{}).length;return e===1?`1 answer`:`${e} answers`}}function im(e){switch(e.event){case`started`:return`Stage started`;case`succeeded`:return`Stage succeeded`;case`failed`:return`Stage failed`;case`agent_start`:return`Agent started`;case`agent_end`:return`Agent settled`;case`turn_start`:return`Turn`;case`tool_start`:return`→ ${e.toolName??`tool`}`;case`tool_end`:return e.isError?`✕ ${e.toolName??`tool`}`:`✓ ${e.toolName??`tool`}`;case`tool_progress`:return`│ ${e.toolName??`tool`}`;case`message`:{let t=e.role??`message`;return e.text?`${t}: ${e.text}`:t}case`operator_prompt`:return`Operator prompt`;case`operator_answer`:return`Operator answer`;case`waiting_for_input`:return Ur();case`resumed`:return`Stage resumed`;default:return e.event}}function am(e){if(e.event===`tool_start`&&e.argsPreview)return e.argsPreview;if(e.event===`tool_end`&&e.resultPreview)return e.resultPreview;if(e.event===`tool_progress`&&e.textPreview)return e.textPreview;if(e.event===`failed`&&e.reason||e.event===`turn_start`&&e.reason)return e.reason;if(e.event===`operator_prompt`)return nm(e);if(e.event===`operator_answer`)return rm(e)}var om=4;function sm(e,t){return`${e.event}-${e.at??`na`}-${t}`}function cm(e){if(!e||typeof e!=`object`)return null;let t=e.kind;return t===`free_text`||t===`confirm`||t===`multi_question`||t===`artifact_backed`?e:null}function lm(e){if(!e||typeof e!=`object`)return null;let t=e.kind;return t===`free_text`||t===`confirm`||t===`multi_question`||t===`artifact_backed`?e:null}function um(e){return e===`tool_start`||e===`tool_end`||e===`tool_progress`}function dm(e){let t=[],n=[];for(let r=0;r<e.length;r++){let i=e[r];if(i.event===`tool_start`){t.push({name:i.toolName??`tool`,args:i.argsPreview,at:i.at,id:i.toolCallId??`start-${r}`});continue}if(i.event===`tool_progress`){let e=-1;if(i.toolCallId&&(e=t.findIndex(e=>e.id===i.toolCallId)),e<0&&(e=t.length>0?t.length-1:-1),e<0)continue;let n=typeof i.textPreview==`string`?i.textPreview:void 0;n!==void 0&&(t[e].progressPreview=n);continue}if(i.event===`tool_end`){let e=i.toolCallId?t.findIndex(e=>e.id===i.toolCallId):t.findIndex(e=>e.name===(i.toolName??`tool`)),r=e>=0?t.splice(e,1)[0]:void 0;n.push({name:i.toolName??r?.name??`tool`,status:i.isError?`error`:`complete`,args:r?.args,result:i.resultPreview,at:i.at??r?.at,startedAt:r?.at})}}for(let e of t)n.push({name:e.name,status:`running`,args:e.args,progressPreview:e.progressPreview,at:e.at,startedAt:e.at});return n}function fm({at:e}){return e?(0,B.jsx)(`time`,{children:Pr(e)}):null}function pm({envelope:e}){return(0,B.jsxs)(`div`,{className:`turn`,children:[(0,B.jsx)(`div`,{className:`turn__who`,children:`Envelope`}),(0,B.jsxs)(`div`,{className:`bubble`,style:{borderColor:`var(--color-border-green)`},children:[(0,B.jsx)(`p`,{children:e.summary}),e.artifacts.length>0?(0,B.jsx)(`p`,{className:`muted`,children:e.artifacts.map(e=>e.split(`/`).pop()??e).join(` · `)}):null]})]})}function mm({calls:e}){let[t,n]=(0,v.useState)(!1),r=!t&&e.length>om?e.length-om:0,i=r>0?e.slice(0,om):e;return(0,B.jsxs)(`div`,{className:`tools`,children:[i.map((e,t)=>{let n=e.status===`running`?e.progressPreview:e.result;return(0,B.jsxs)(`div`,{className:e.status===`error`?`tool tool--error`:`tool`,children:[(0,B.jsxs)(`span`,{children:[e.status===`error`?`✕`:e.status===`running`?`▸`:`⚙`,` `,e.name,e.args?` ${e.args}`:``,n?` · ${n}`:``]}),(0,B.jsx)(fm,{at:e.at})]},`${e.name}-${e.at??t}`)}),r>0?(0,B.jsxs)(`button`,{type:`button`,className:`tools__more`,onClick:()=>n(!0),children:[`Show `,r,` more`]}):null]})}function hm({event:e}){let t=e.role??`message`,n=e.text?.trim();return n?(0,B.jsxs)(`div`,{className:`turn`,children:[(0,B.jsxs)(`div`,{className:`turn__who`,children:[t,(0,B.jsx)(fm,{at:e.at})]}),(0,B.jsx)(`div`,{className:`bubble`,children:(0,B.jsx)(`p`,{children:n})})]}):null}function gm({event:e}){let t=cm(e.prompt);return(0,B.jsxs)(`div`,{className:`ask`,children:[(0,B.jsxs)(`div`,{className:`ask__label`,children:[t?.kind??`ask`,(0,B.jsx)(`span`,{style:{marginLeft:`auto`},children:(0,B.jsx)(fm,{at:e.at})})]}),t?.kind===`multi_question`?(0,B.jsx)(`ol`,{className:`qlist`,children:t.questions.map(e=>(0,B.jsxs)(`li`,{children:[e.message,(0,B.jsx)(`small`,{children:e.kind})]},e.id))}):(0,B.jsx)(`p`,{className:`ask__q`,children:t&&`message`in t?t.message:am(e)})]})}function _m({event:e}){let t=lm(e.answer),n,r;if(t?.kind===`free_text`)n=`answered`,r=t.text;else if(t?.kind===`confirm`||t?.kind===`artifact_backed`)n=t.decision,r=t.text;else if(t?.kind===`multi_question`){let e=Object.keys(t.answers??{}).length;n=e===1?`1 answer`:`${e} answers`}else r=am(e);let i=n===`accept`||n===`answered`||n===`reject`?n:void 0;return(0,B.jsxs)(`div`,{className:`answer`,children:[(0,B.jsxs)(`div`,{className:`turn__who`,children:[n?(0,B.jsx)(`span`,{className:`answer__verdict`,...i?{"data-v":i}:{},children:n}):(0,B.jsx)(`span`,{children:`Operator`}),(0,B.jsx)(fm,{at:e.at})]}),r?(0,B.jsx)(`p`,{children:r}):null]})}function vm({event:e}){let t=am(e),n=im(e);return(0,B.jsx)(`div`,{className:`divider-iter`,children:t?`${n} · ${t}`:n})}function ym(e){let t=[],n=0;for(;n<e.length;){let r=e[n];if(um(r.event)){let r=[];for(;n<e.length&&um(e[n].event);)r.push(e[n]),n+=1;let i=dm(r);i.length>0&&t.push({kind:`tools`,calls:i});continue}r.event===`message`?r.text?.trim()&&t.push({kind:`message`,event:r}):r.event===`operator_prompt`?t.push({kind:`operator_prompt`,event:r}):r.event===`operator_answer`?t.push({kind:`operator_answer`,event:r}):r.event===`turn_start`&&!am(r)||t.push({kind:`system`,event:r}),n+=1}return t}function bm({events:e,inboundEnvelope:t}){let n=[];t&&n.push((0,B.jsx)(pm,{envelope:t},`inbound-envelope`));let r=ym(e);for(let e=0;e<r.length;e++){let t=r[e];if(t.kind===`tools`){n.push((0,B.jsx)(mm,{calls:t.calls},`tools-${e}`));continue}if(t.kind===`message`){n.push((0,B.jsx)(hm,{event:t.event},sm(t.event,e)));continue}if(t.kind===`operator_prompt`){n.push((0,B.jsx)(gm,{event:t.event},sm(t.event,e)));continue}if(t.kind===`operator_answer`){n.push((0,B.jsx)(_m,{event:t.event},sm(t.event,e)));continue}n.push((0,B.jsx)(vm,{event:t.event},sm(t.event,e)))}return n.length===0?(0,B.jsx)(`p`,{className:`muted`,children:`No activity yet.`}):(0,B.jsx)(B.Fragment,{children:n})}function xm(e){for(let t=e.length-1;t>=0;t--)if(e[t].kind===`system`&&e[t].status===`failed`)return e[t].id;if(!e.some(e=>e.kind===`system`&&e.sourceEvent===`succeeded`)){for(let t=e.length-1;t>=0;t--)if(e[t].kind===`tool`&&e[t].status===`failed`)return e[t].id}}function Sm(e,t){let n=e.find(e=>e.id===t);if(!(!n||n.kind!==`system`))return n.detail??n.label}var Cm=160;function wm(e,t){let n=e.slice(0,t),r=n.lastIndexOf(` `);return r>0?{shown:n.slice(0,r),cutIndex:r+1}:{shown:n,cutIndex:t}}function Tm(e){let t=e.indexOf(`
|
|
116
|
-
`),n=t===-1?e:e.slice(0,t);if(n.length<=Cm){let r=(t===-1?``:e.slice(t+1)).replace(/^\n+/,``);return{preview:n,hasMore:r.trim().length>0,rest:r}}let{shown:r,cutIndex:i}=wm(n,Cm);return{preview:`${r}…`,hasMore:!0,rest:e.slice(i).replace(/^\n+/,``)}}function Em(e){if(e<1e3)return`<1s`;let t=Math.round(e/1e3);return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`}function Dm(e,t){if(e.kind!==`tool`||!e.startedAt)return;let n=Date.parse(e.startedAt);if(Number.isNaN(n))return;if(e.status===`running`)return Math.max(0,t-n);if(!e.finishedAt)return;let r=Date.parse(e.finishedAt);if(!Number.isNaN(r))return Math.max(0,r-n)}function Om(e){return e.status===`error`?`failed`:e.status===`running`?`running`:`succeeded`}var km={read:{key:`file_path`,isPath:!0},write:{key:`file_path`,isPath:!0},edit:{key:`file_path`,isPath:!0},notebookedit:{key:`notebook_path`,isPath:!0},bash:{key:`command`,isPath:!1},grep:{key:`pattern`,isPath:!1},glob:{key:`pattern`,isPath:!1},webfetch:{key:`url`,isPath:!1},websearch:{key:`query`,isPath:!1}},Am=new Set([`read`]);function jm(e){if(e)try{let t=JSON.parse(e);return t&&typeof t==`object`?t:void 0}catch{return}}function Mm(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function Nm(e,t){let n=jm(e)?.[t];if(typeof n==`string`)return n;if(!e)return;let r=e.match(RegExp(`"${Mm(t)}"\\s*:\\s*"((?:[^"\\\\]|\\\\.)*)"`));return r?r[1]:void 0}function Pm(e){return e.split(`/`).pop()||e}function Fm(e){let t=km[e.name.toLowerCase()];if(!t)return e.name;let n=Nm(e.args,t.key);return typeof n!=`string`||!n.trim()?e.name:`${e.name} ${t.isPath?Pm(n):n}`}function Im(e){if(e.status===`running`)return e.progressPreview;if(!(e.status===`complete`&&Am.has(e.name.toLowerCase())))return e.result}function Lm(e,t){return{id:t,kind:`tool`,label:Fm(e),status:Om(e),detail:Im(e),at:e.at,startedAt:e.startedAt,finishedAt:e.status===`running`?void 0:e.at,defaultExpanded:!1}}function Rm(e,t){return{id:t,kind:`message`,label:e.role??`message`,status:`succeeded`,detail:e.text?.trim(),at:e.at,defaultExpanded:!1}}function zm(e,t,n){return{id:n,kind:e,label:im(t),status:e===`system`&&t.event===`failed`?`failed`:`succeeded`,detail:am(t),at:t.at,defaultExpanded:!1,sourceEvent:e===`system`?t.event:void 0}}function Bm(e){let t=ym(e),n=[],r=0;for(let e of t){if(e.kind===`tools`){for(let t of e.calls)n.push(Lm(t,`step-${r}`)),r+=1;continue}let t=`step-${r}`;r+=1,e.kind===`message`?n.push(Rm(e.event,t)):e.kind===`operator_prompt`?n.push(zm(`operator_prompt`,e.event,t)):e.kind===`operator_answer`?n.push(zm(`operator_answer`,e.event,t)):n.push(zm(`system`,e.event,t))}let i=xm(n);for(let e of n)e.defaultExpanded=e.status===`running`||e.id===i;return n}function Vm({step:e,now:t,isOpen:n,onToggle:r}){let i=Dm(e,t),{preview:a,hasMore:o,rest:s}=e.detail?Tm(e.detail):{preview:``,hasMore:!1,rest:``};return(0,B.jsxs)(`div`,{id:`logstep-${e.id}`,className:`logstep logstep--${e.status}`,children:[(0,B.jsxs)(`button`,{type:`button`,className:`logstep__row${o?``:` logstep__row--static`}`,disabled:!o,"aria-expanded":o?n:void 0,onClick:o?()=>r(!n):void 0,children:[(0,B.jsx)(Pi,{icon:`chevronDown`,size:`sm`,className:`logstep__chevron${o?n?` logstep__chevron--open`:``:` logstep__chevron--hidden`}`}),(0,B.jsx)(`span`,{className:`dot dot--${e.status} logstep__dot`}),(0,B.jsxs)(`span`,{className:`logstep__text`,children:[(0,B.jsxs)(`span`,{className:`logstep__label-row`,children:[(0,B.jsx)(`span`,{className:`logstep__label`,children:e.label}),i===void 0?null:(0,B.jsx)(`span`,{className:`logstep__duration`,children:Em(i)})]}),a?(0,B.jsx)(`span`,{className:`logstep__preview`,children:a}):null]})]}),o&&n?(0,B.jsx)(`pre`,{className:`logstep__detail`,children:s}):null]})}function Hm(e){let t=document.getElementById(`logstep-${e}`);t&&(t.scrollIntoView({behavior:`smooth`,block:`center`}),t.classList.add(`logstep--highlight`),window.setTimeout(()=>t.classList.remove(`logstep--highlight`),1500))}function Um({events:e,headerAction:t}){let n=Bm(e),r=Date.now(),i=xm(n),a=Sm(n,i),[o,s]=(0,v.useState)({});return(0,B.jsxs)(`div`,{className:`stream`,style:{height:`100%`},children:[(0,B.jsxs)(`header`,{className:`stream__head`,children:[(0,B.jsx)(`h3`,{className:`stream__name`,children:`Logs`}),t?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`span`,{className:`topbar__spacer`}),(0,B.jsx)(`div`,{className:`stream__head-trail`,children:t})]}):null]}),(0,B.jsx)(`div`,{className:`stream__body`,children:n.length===0?(0,B.jsx)(`p`,{className:`muted`,children:`No activity yet.`}):(0,B.jsx)(`div`,{className:`logpanel`,children:n.map(e=>(0,B.jsx)(Vm,{step:e,now:r,isOpen:o[e.id]??e.defaultExpanded,onToggle:t=>s(n=>({...n,[e.id]:t}))},e.id))})}),a&&i?(0,B.jsxs)(`div`,{className:`logpanel__banner`,children:[(0,B.jsx)(`span`,{className:`logpanel__banner-text`,children:a}),(0,B.jsx)(`button`,{type:`button`,className:`btn btn--sm`,onClick:()=>{s(e=>{if(!(i in e))return e;let t={...e};return delete t[i],t}),Hm(i)},children:`Jump to failing step`})]}):null]})}function Wm(e){let t=new Map;for(let n of e){let e=t.get(n.layer)??[];e.push(n),t.set(n.layer,e)}return[...t.keys()].sort((e,t)=>e-t).map(e=>(t.get(e)??[]).sort((e,t)=>e.layer_order-t.layer_order))}function Gm(e){return Wm(e).flat()}function Km(e,t,n,r=0){return{stageId:e,x:t*520,y:r+n*340,width:400,height:128,layerIndex:t,indexInLayer:n}}function qm(e,t){return t<=1||e>=t?0:(t-e)/2*340}function Jm(e){let t=e?.plannedStageIds??[],n=e?.liveStageIds??[];if(t.length===0)return n;let r=new Set,i=[];for(let e of t)r.add(e),i.push(e);for(let e of n)r.has(e)||i.push(e);return i}function Ym(e,t){if(!e.nodes.length){let e=Jm(t);return{nodes:e.map((e,t)=>Km(e,t,0)),edges:e.slice(1).map((t,n)=>({from:e[n],to:t}))}}let n=Wm(e.nodes),r=n.reduce((e,t)=>Math.max(e,t.length),0);return{nodes:n.flatMap((e,t)=>{let n=qm(e.length,r);return e.map((e,r)=>Km(e.stage_id,t,r,n))}),edges:e.edges.map(e=>({from:e.from,to:e.to}))}}function Xm(e){return e===`failed`}function Zm(e){return e===`running`}function Qm(e){if(e.status!==`failed`)return!1;let t;for(let n of e.events)n.event===`failed`&&(t=n.reason);return typeof t==`string`&&t.startsWith(`stage timed out after `)}function $m(e,t){return e.retryingStageIds.has(t)||e.abandoningStageId===t||(e.resumingStageIds?.has(t)??!1)}function eh(e){let t={retryingStageIds:new Set,error:null},n=new Set,r=()=>t,i=()=>{for(let e of n)e()};return{getState:r,retry:async n=>{if(t.retryingStageIds.has(n))return;let r=new Set(t.retryingStageIds);r.add(n),t={retryingStageIds:r,error:null},i();try{await e.retry(n),await e.onSuccess()}catch(e){t={...t,error:e instanceof Error?e.message:String(e)}}finally{let e=new Set(t.retryingStageIds);e.delete(n),t={...t,retryingStageIds:e},i()}},clearError:()=>{t.error!==null&&(t={...t,error:null},i())},subscribe:e=>(n.add(e),()=>{n.delete(e)})}}function th(e,t){let n=(0,v.useRef)(e);n.current=e;let r=(0,v.useRef)(t);r.current=t;let i=(0,v.useRef)(null);i.current===null&&(i.current=eh({retry:async e=>{await Xn(n.current,e)},onSuccess:()=>r.current()}));let a=i.current,[o,s]=(0,v.useState)(()=>a.getState());(0,v.useEffect)(()=>a.subscribe(()=>s(a.getState())),[a]);let c=(0,v.useCallback)(e=>void a.retry(e),[a]),l=(0,v.useCallback)(()=>a.clearError(),[a]);return{retryingStageIds:o.retryingStageIds,error:o.error,retry:c,clearError:l}}function nh(e){let t={resumingStageIds:new Set,error:null},n=new Set,r=()=>t,i=()=>{for(let e of n)e()};return{getState:r,resume:async n=>{if(t.resumingStageIds.has(n))return;let r=new Set(t.resumingStageIds);r.add(n),t={resumingStageIds:r,error:null},i();try{await e.resume(n),await e.onSuccess()}catch(e){t={...t,error:e instanceof Error?e.message:String(e)}}finally{let e=new Set(t.resumingStageIds);e.delete(n),t={...t,resumingStageIds:e},i()}},clearError:()=>{t.error!==null&&(t={...t,error:null},i())},subscribe:e=>(n.add(e),()=>{n.delete(e)})}}function rh(e,t){let n=(0,v.useRef)(e);n.current=e;let r=(0,v.useRef)(t);r.current=t;let i=(0,v.useRef)(null);i.current===null&&(i.current=nh({resume:async e=>{await Zn(n.current,e)},onSuccess:()=>r.current()}));let a=i.current,[o,s]=(0,v.useState)(a.getState);(0,v.useEffect)(()=>a.subscribe(()=>s(a.getState())),[a]);let c=(0,v.useCallback)(e=>{a.resume(e)},[a]);return{resumingStageIds:o.resumingStageIds,error:o.error,resume:c,clearError:a.clearError}}function ih(e){let t={abandoningStageId:null,error:null},n=!1,r=new Set,i=()=>t,a=()=>{for(let e of r)e()};return{getState:i,abandon:async r=>{if(!n&&(e.confirm?.(r)??window.confirm(`This stage will be marked failed. Retry stage will become available.`))){n=!0,t={abandoningStageId:r,error:null},a();try{await e.abandon(r),await e.onSuccess()}catch(e){t={...t,error:e instanceof Error?e.message:String(e)}}finally{n=!1,t={...t,abandoningStageId:null},a()}}},clearError:()=>{t.error!==null&&(t={...t,error:null},a())},subscribe:e=>(r.add(e),()=>{r.delete(e)})}}function ah(e,t){let n=(0,v.useRef)(e);n.current=e;let r=(0,v.useRef)(t);r.current=t;let i=(0,v.useRef)(null);i.current===null&&(i.current=ih({abandon:async e=>{await er(n.current,e)},onSuccess:()=>r.current()}));let a=i.current,[o,s]=(0,v.useState)(()=>a.getState());(0,v.useEffect)(()=>a.subscribe(()=>s(a.getState())),[a]);let c=(0,v.useCallback)(e=>void a.abandon(e),[a]),l=(0,v.useCallback)(()=>a.clearError(),[a]);return{abandoningStageId:o.abandoningStageId,error:o.error,abandon:c,clearError:l}}var oh=.25,sh=1.8;function ch(e,t){return Math.abs(e.y+e.height/2-(t.y+t.height/2))<e.height*.75}function lh(e,t){let n=e.x+e.width/2,r=t.x+t.width/2;return Math.max(0,Math.round(Math.abs(r-n)/520)-1)*12}function uh(e,t,n,r,i){return`M${e} ${t} V${i} H${n} V${r}`}function dh(e,t){let n=e.y+e.height/2,r=t.y+t.height/2,i=lh(e,t);if(ch(e,t)){let n=e.x+e.width/2,r=e.y+e.height,a=t.x+t.width/2,o=t.y+t.height;return uh(n,r,a,o,Math.max(r,o)+48+i)}if(r>=n){let n=e.x+e.width/2,r=e.y+e.height,a=t.x+t.width/2,o=t.y,s=o-r;return uh(n,r,a,o,s>=48?r+s/2:Math.max(r,o)+48+i)}let a=e.x+e.width/2,o=e.y,s=t.x+t.width/2,c=t.y;return uh(a,o,s,c,Math.min(o,c)-48-i)}function fh(e){let t=e.match(/[MLHVmlhv]|-?\d*\.?\d+/g);if(!t)return[];let n=[],r=0,i=0,a=0;for(;a<t.length;){let e=t[a++].toUpperCase();e===`M`||e===`L`?(r=Number(t[a++]),i=Number(t[a++]),n.push({x:r,y:i})):e===`H`?(r=Number(t[a++]),n.push({x:r,y:i})):e===`V`&&(i=Number(t[a++]),n.push({x:r,y:i}))}return n}function ph(e,t){let n=fh(dh(e,t));if(n.length===0)return{x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),width:Math.abs(t.x-e.x)+Math.max(e.width,t.width),height:Math.abs(t.y-e.y)+Math.max(e.height,t.height)};let r=n.map(e=>e.x),i=n.map(e=>e.y),a=Math.min(...r),o=Math.max(...r),s=Math.min(...i),c=Math.max(...i);return{x:a,y:s,width:o-a,height:c-s}}function mh(e,t,n=4){return Math.hypot(e,t)>n}function hh(e,t=24){if(e.length===0)return{x:0,y:0,width:0,height:0};let n=1/0,r=1/0,i=-1/0,a=-1/0;for(let t of e)n=Math.min(n,t.x),r=Math.min(r,t.y),i=Math.max(i,t.x+t.width),a=Math.max(a,t.y+t.height);return{x:n-t,y:r-t,width:i-n+t*2,height:a-r+t*2}}function gh(e,t){if(e.width<=0||e.height<=0||t.width<=0||t.height<=0)return{panX:0,panY:0,zoom:1};let n=t.width-56,r=t.height-56;if(n<=0||r<=0)return{panX:0,panY:0,zoom:1};let i=Math.max(oh,Math.min(1.1,sh,n/e.width,r/e.height));return{zoom:i,panX:56+(n-e.width*i)/2-e.x*i,panY:56+(r-e.height*i)/2-e.y*i}}function _h(e,t){return e&&!t}function vh(e,t){return e===t?null:e}function yh(e,t){return!!e.find(e=>e.stage_id===t)?.envelope}function bh(e,t){return e===`waiting_for_input`||e===`pending`||e===`skipped`?null:e===`running`?`abandon`:e===`failed`||t?`retry`:null}function xh(e){switch(e){case`free_text`:return`free text`;case`confirm`:return`confirm`;case`multi_question`:return`multi-question`;case`artifact_backed`:return`artifact`}}function Sh(e,t,n,r){let i=Math.max(48,(n-e)/2);return`M${e} ${t} C${e+i} ${t} ${n-i} ${r} ${n} ${r}`}function Ch(e,t){return t?`abandoned`:e}function wh({layout:e,stages:t,nodeChrome:n,selectedStageId:r,onSelectStage:i,onDeselect:a,retryingStageIds:o,onRetryStage:s,resumingStageIds:c,onResumeStage:l,abandoningStageId:u=null,onAbandonStage:d,runId:f,showHint:p,feedbackOverlays:m=[]}){let h=(0,v.useRef)(null),g=(0,v.useRef)(!1),_=(0,v.useRef)(!1),y=(0,v.useRef)({width:0,height:0}),b=(0,v.useRef)(null),[x,S]=(0,v.useState)({width:0,height:0}),[C,w]=(0,v.useState)({x:0,y:0}),[T,E]=(0,v.useState)(1),[D,O]=(0,v.useState)(!1),k=new Map(t.map(e=>[e.stage_id,e])),A=new Map(n.map(e=>[e.stageId,e])),j=o??new Set,M=c??new Set;(0,v.useLayoutEffect)(()=>{let e=h.current;if(!e)return;let t=()=>{let t=e.getBoundingClientRect();S({width:t.width,height:t.height})};t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[]),(0,v.useLayoutEffect)(()=>{g.current=!1,_.current=!1,y.current={width:0,height:0}},[f]);let N=()=>{let t=[...e.nodes];for(let n of m){let r=e.nodes.find(e=>e.stageId===n.from),i=e.nodes.find(e=>e.stageId===n.to);!r||!i||t.push(ph(r,i))}return hh(t)};(0,v.useLayoutEffect)(()=>{if(e.nodes.length===0||x.width===0||x.height===0)return;if(!g.current){let e=gh(N(),x);w({x:e.panX,y:e.panY}),E(e.zoom),g.current=!0,y.current={width:x.width,height:x.height};return}if(y.current.width===x.width&&y.current.height===x.height||(y.current={width:x.width,height:x.height},!_h(!0,_.current)))return;let t=gh(N(),x);w({x:t.panX,y:t.panY}),E(t.zoom)},[m,e.nodes,x.height,x.width]);let ee=(e,t)=>{let n=t??{x:x.width/2,y:x.height/2},r=Math.max(oh,Math.min(sh,T*e)),i=(n.x-C.x)/T,a=(n.y-C.y)/T;_.current=!0,w({x:n.x-i*r,y:n.y-a*r}),E(r)},P=()=>{let t=h.current;if(!t||e.nodes.length===0)return;let n=t.getBoundingClientRect(),r=gh(N(),{width:n.width,height:n.height});w({x:r.panX,y:r.panY}),E(r.zoom),_.current=!1,g.current=!0,y.current={width:n.width,height:n.height}},F=e=>{e.target.closest(`.gnode`)||(e.currentTarget.setPointerCapture(e.pointerId),O(!0),b.current={id:e.pointerId,x:e.clientX,y:e.clientY,panX:C.x,panY:C.y})},I=e=>{let t=b.current;if(!t||t.id!==e.pointerId)return;let n=e.clientX-t.x,r=e.clientY-t.y;mh(n,r)&&(_.current=!0),w({x:t.panX+n,y:t.panY+r})},te=e=>{let t=b.current;if(!t||t.id!==e.pointerId)return;let n=e.clientX-t.x,r=e.clientY-t.y;b.current=null,O(!1),mh(n,r)||a()};return(0,B.jsxs)(`div`,{className:`graph-view`,children:[(0,B.jsxs)(`svg`,{className:`graph-grid`,"aria-hidden":`true`,width:`100%`,height:`100%`,children:[(0,B.jsx)(`defs`,{children:(0,B.jsx)(`pattern`,{id:`spatial-dots`,width:`24`,height:`24`,patternUnits:`userSpaceOnUse`,children:(0,B.jsx)(`circle`,{cx:`1`,cy:`1`,r:`1`,fill:`var(--color-border)`})})}),(0,B.jsx)(`rect`,{width:`100%`,height:`100%`,fill:`url(#spatial-dots)`})]}),(0,B.jsx)(`div`,{ref:h,className:D?`graph-stage dragging`:`graph-stage`,onPointerDown:F,onPointerMove:I,onPointerUp:te,onPointerCancel:te,onWheel:e=>{e.preventDefault();let t=e.currentTarget.getBoundingClientRect();if(e.metaKey||e.ctrlKey){ee(e.deltaY<0?1.08:.92,{x:e.clientX-t.left,y:e.clientY-t.top});return}_.current=!0,w(t=>({x:t.x-e.deltaX,y:t.y-e.deltaY}))},children:(0,B.jsxs)(`svg`,{className:`graph-svg`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,B.jsxs)(`defs`,{children:[(0,B.jsx)(`marker`,{id:`spatial-arrow`,markerWidth:`8`,markerHeight:`8`,refX:`7`,refY:`3`,orient:`auto`,children:(0,B.jsx)(`path`,{d:`M0,0 L7,3 L0,6 Z`,fill:`var(--color-text-disabled)`})}),(0,B.jsx)(`marker`,{id:`spatial-arrow-active`,markerWidth:`8`,markerHeight:`8`,refX:`7`,refY:`3`,orient:`auto`,children:(0,B.jsx)(`path`,{d:`M0,0 L7,3 L0,6 Z`,fill:`var(--color-accent)`})}),(0,B.jsx)(`marker`,{id:`spatial-arrow-feedback`,markerWidth:`8`,markerHeight:`8`,refX:`7`,refY:`3`,orient:`auto`,children:(0,B.jsx)(`path`,{d:`M0,0 L7,3 L0,6 Z`,fill:`var(--color-warning)`})})]}),(0,B.jsxs)(`g`,{className:`world`,transform:`translate(${C.x} ${C.y}) scale(${T})`,children:[e.edges.map(n=>{let r=e.nodes.find(e=>e.stageId===n.from),i=e.nodes.find(e=>e.stageId===n.to);if(!r||!i)return null;let a=r.height,o=i.height,s=r.x+r.width,c=r.y+a/2,l=i.x,u=i.y+o/2,d=yh(t,n.from);return(0,B.jsx)(`g`,{children:(0,B.jsx)(`path`,{className:d?`edge handoff`:`edge`,d:Sh(s,c,l,u),markerEnd:d?`url(#spatial-arrow-active)`:`url(#spatial-arrow)`})},`${n.from}->${n.to}`)}),m.map(t=>{let n=e.nodes.find(e=>e.stageId===t.from),r=e.nodes.find(e=>e.stageId===t.to);return!n||!r?null:(0,B.jsx)(`path`,{className:t.kind===`deferred`?`edge feedback feedback--deferred`:t.kind===`policy`?`edge feedback feedback--policy`:`edge feedback`,d:dh(n,r),markerEnd:`url(#spatial-arrow-feedback)`},`feedback:${t.kind}:${t.from}->${t.to}`)}),e.nodes.map(e=>{let t=k.get(e.stageId),n=A.get(e.stageId),a=t?.status??n?.status??`pending`,o=t?Rr(t.events):!1;return(0,B.jsx)(Th,{node:e,status:a,abandoned:o,chrome:n,selected:r===e.stageId,busy:$m({retryingStageIds:j,abandoningStageId:u,resumingStageIds:M},e.stageId),retrying:j.has(e.stageId),resuming:M.has(e.stageId),abandoning:u===e.stageId,snapshot:t,onSelectStage:i,onRetryStage:s,onResumeStage:l,onAbandonStage:d},e.stageId)})]})]})}),(0,B.jsxs)(`div`,{className:`canvas-tools`,children:[(0,B.jsx)(`button`,{type:`button`,className:`icon`,title:`Zoom out`,"aria-label":`Zoom out`,onClick:()=>ee(.87),children:`−`}),(0,B.jsxs)(`span`,{className:`zoom`,"aria-live":`polite`,children:[Math.round(T*100),`%`]}),(0,B.jsx)(`button`,{type:`button`,className:`icon`,title:`Zoom in`,"aria-label":`Zoom in`,onClick:()=>ee(1.15),children:`+`}),(0,B.jsx)(`span`,{className:`divider`}),(0,B.jsx)(`button`,{type:`button`,className:`icon fit-btn`,onClick:P,children:`Fit run`})]}),p?(0,B.jsx)(`div`,{className:`canvas-hint`,children:`Stages become selectable when they start.`}):null]})}function Th({node:e,status:t,abandoned:n,chrome:r,selected:i,busy:a,retrying:o,resuming:s,abandoning:c,snapshot:l,onSelectStage:u,onRetryStage:d,onResumeStage:f,onAbandonStage:p}){let m=t!==`pending`,h=bh(t,n),g=l!==void 0&&Qm(l)&&f!==void 0,_=h===`retry`&&Xm(t)&&d,v=h===`abandon`&&Zm(t)&&p,y=Ch(t,n),b=[r?.isFeedbackSource?`feedback-source`:``,r?.isFeedbackTarget?`feedback-target`:``,r?.isSuperseded?`superseded`:``].filter(Boolean).join(` `),x=n?zr():Hr(t),S=r?.title??e.stageId,C=r?vh(r.kicker,r.title):null,w=[x];r?.isSuperseded&&w.push(`superseded`),r?.readinessLine&&t===`pending`&&w.push(r.readinessLine),t===`waiting_for_input`?(r?.gateKinds?.length&&w.push(r.gateKinds.map(xh).join(` · `)),r?.promptSummary&&w.push(r.promptSummary)):r?.meta&&w.push(r.meta);let T=()=>{m&&u(e.stageId)};return(0,B.jsxs)(`g`,{className:`gnode ${y}${i?` selected`:``}${b?` ${b}`:``}`,"data-id":e.stageId,"data-waiting":r?.isWaitingAttention?`true`:void 0,"data-feedback-source":r?.isFeedbackSource?`true`:void 0,"data-feedback-target":r?.isFeedbackTarget?`true`:void 0,"data-superseded":r?.isSuperseded?`true`:void 0,transform:`translate(${e.x},${e.y})`,children:[(0,B.jsx)(`rect`,{className:`node-box`,x:0,y:0,width:e.width,height:128,rx:12,ry:12}),(0,B.jsx)(`circle`,{className:`port`,cx:-4,cy:64,r:4}),(0,B.jsx)(`circle`,{className:`port`,cx:e.width+4,cy:64,r:4}),m?(0,B.jsx)(`foreignObject`,{x:0,y:0,width:e.width,height:128,children:(0,B.jsxs)(`button`,{type:`button`,className:`gnode__hit`,onClick:T,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),T())},children:[C?(0,B.jsx)(`span`,{className:`gnode__kicker`,children:C}):null,(0,B.jsxs)(`span`,{className:`gnode__title`,children:[S,(0,B.jsx)(Hc,{count:r?.attemptCount})]}),(0,B.jsx)(`span`,{className:`gnode__meta`,children:w.join(` · `)})]})}):(0,B.jsxs)(`g`,{className:`gnode__static`,children:[C?(0,B.jsx)(`text`,{className:`kicker`,x:16,y:22,children:C}):null,(0,B.jsx)(`text`,{className:`node-title`,x:16,y:C?44:32,children:S}),(0,B.jsx)(`text`,{className:`node-meta`,x:16,y:66,children:w.join(` · `)})]}),(0,B.jsx)(Dh,{status:t,abandoned:n,cx:e.width-26,cy:26,showResume:!!g,showRetry:!!_,showAbandon:!!v,busy:a,resumeLabel:s?`Resuming…`:`Resume session`,retryLabel:o?`Retrying…`:`Retry stage`,abandonLabel:c?`Abandoning…`:`Abandon stage`,onResume:g?()=>{f?.(e.stageId)}:void 0,onRetry:_?()=>{d?.(e.stageId)}:void 0,onAbandon:v?()=>{p?.(e.stageId)}:void 0})]})}function Eh({kind:e,cx:t,cy:n,busy:r,label:i,onActivate:a}){return(0,B.jsxs)(`g`,{className:`node-action-btn node-${e}${r?` is-busy`:``}`,role:`button`,tabIndex:r?-1:0,"aria-label":i,"aria-disabled":r||void 0,onClick:e=>{r||(e.stopPropagation(),a?.())},onKeyDown:e=>{r||(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),e.stopPropagation(),a?.())},children:[(0,B.jsx)(`title`,{children:i}),(0,B.jsx)(`circle`,{className:`action-bg`,cx:t,cy:n,r:11}),e===`retry`?(0,B.jsx)(`path`,{className:`action-icon`,d:[`M${t-3.2} ${n-2.2}`,`A4.2 4.2 0 1 0 ${t+.2} ${n-4}`,`M${t+.2} ${n-7.2}`,`L${t+.2} ${n-3.6}`,`L${t-3.4} ${n-3.6}`].join(` `)}):e===`resume`?(0,B.jsx)(`path`,{className:`action-icon`,d:`M${t-2.2} ${n-3.6} L${t-2.2} ${n+3.6} L${t+4.2} ${n} Z`}):(0,B.jsx)(`rect`,{className:`action-icon`,x:t-3.5,y:n-3.5,width:7,height:7,rx:1.25})]})}function Dh({status:e,abandoned:t,cx:n,cy:r,showResume:i,showRetry:a,showAbandon:o,busy:s,resumeLabel:c,retryLabel:l,abandonLabel:u,onResume:d,onRetry:f,onAbandon:p}){let m=r+28,h=i?m+26:m;return(0,B.jsxs)(`g`,{className:`node-status`,children:[e===`succeeded`?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`circle`,{cx:n,cy:r,r:11,fill:`var(--color-success)`}),(0,B.jsx)(`path`,{d:`M${n-4} ${r} l3 3 l6-7`,fill:`none`,stroke:`var(--color-background-surface)`,strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`})]}):null,e===`running`?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`circle`,{className:`node-spin`,cx:n,cy:r,r:11,fill:`none`,stroke:`var(--color-border)`,strokeWidth:2}),(0,B.jsx)(`circle`,{className:`node-spin`,cx:n,cy:r,r:11,fill:`none`,stroke:`var(--color-accent)`,strokeWidth:2.25,strokeLinecap:`round`,strokeDasharray:`18 52`})]}):null,e===`waiting_for_input`?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`circle`,{cx:n,cy:r,r:10,fill:`none`,stroke:`var(--color-warning)`,strokeWidth:2,strokeDasharray:`4 3`}),(0,B.jsx)(`text`,{x:n,y:r+4,textAnchor:`middle`,fill:`var(--color-warning)`,fontSize:11,fontWeight:700,children:`!`})]}):null,e===`failed`&&!t?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`circle`,{cx:n,cy:r,r:11,fill:`var(--color-error)`}),(0,B.jsx)(`text`,{x:n,y:r+4,textAnchor:`middle`,fill:`var(--color-background-surface)`,fontSize:12,fontWeight:700,children:`!`})]}):null,t?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`circle`,{cx:n,cy:r,r:11,fill:`var(--color-error)`}),(0,B.jsx)(`rect`,{x:n-5,y:r-1.5,width:10,height:3,rx:1,fill:`var(--color-background-surface)`})]}):null,e===`pending`||e===`skipped`?(0,B.jsx)(`circle`,{cx:n,cy:r,r:10,fill:`none`,stroke:`var(--color-text-disabled)`,strokeWidth:1.5}):null,i?(0,B.jsx)(Eh,{kind:`resume`,cx:n,cy:m,busy:s,label:c,onActivate:d}):null,a?(0,B.jsx)(Eh,{kind:`retry`,cx:n,cy:h,busy:s,label:l,onActivate:f}):null,o?(0,B.jsx)(Eh,{kind:`abandon`,cx:n,cy:m,busy:s,label:u,onActivate:p}):null]})}var Oh=64;function kh(e){return e.scrollHeight-e.scrollTop-e.clientHeight<Oh}function Ah({stageName:e,status:t,trailing:n,children:r,composer:i,autoScroll:a,scrollKey:o}){let s=(0,v.useRef)(null),c=(0,v.useRef)(!0);(0,v.useEffect)(()=>{a&&(c.current=!0)},[a]),(0,v.useEffect)(()=>{if(!a||!c.current)return;let e=s.current;e&&(e.scrollTop=e.scrollHeight)},[a,o]);function l(e){c.current=kh(e.currentTarget)}return(0,B.jsxs)(`div`,{className:`stream`,style:{height:`100%`},children:[(0,B.jsxs)(`header`,{className:`stream__head`,children:[(0,B.jsx)(`h3`,{className:`stream__name`,children:e}),t,n?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`span`,{className:`topbar__spacer`}),(0,B.jsx)(`div`,{className:`stream__head-trail`,children:n})]}):null]}),(0,B.jsx)(`div`,{ref:s,className:`stream__body`,onScroll:l,children:(0,B.jsx)(`div`,{className:`thread`,children:r})}),i]})}function jh(e){switch(e){case`passed`:return`passed`;case`failed`:return`failed`;case`running`:return`running`;case`skipped`:return`skipped`;default:return`pending`}}function Mh(e){let t=e.checks.length===1?`check`:`checks`;return`Attempt ${e.attempt} · ${e.status} · verification ${e.verification_outcome.replace(`_`,` `)} · ${e.checks.length} ${t}`}function Nh({check:e}){let t=e.evidence===void 0?void 0:JSON.stringify(e.evidence,null,2);return(0,B.jsxs)(`div`,{className:`verification-check`,children:[(0,B.jsxs)(`div`,{className:`verification-check__summary`,children:[(0,B.jsxs)(`span`,{className:`status status--${e.status===`passed`?`succeeded`:e.status===`failed`?`failed`:`running`}`,children:[(0,B.jsx)(`span`,{className:`dot dot--${e.status===`passed`?`succeeded`:e.status===`failed`?`failed`:`running`}`}),` `,jh(e.status)]}),(0,B.jsx)(`code`,{children:e.check_id}),(0,B.jsx)(`span`,{className:`muted`,children:e.check_type})]}),t===void 0?null:(0,B.jsx)(lc,{code:t,language:`json`,title:`Evidence`,size:`sm`,width:`100%`,maxHeight:260,container:`section`,isCollapsible:!0})]})}function Ph({history:e,error:t,recovering:n=!1,onRecover:r,onStop:i}){let[a,o]=(0,v.useState)(``);return t?(0,B.jsxs)(`div`,{className:`banner banner--warning`,children:[`Verification evidence unavailable: `,t]}):e===null||e.attempts.every(e=>e.checks.length===0)?null:(0,B.jsxs)(`section`,{className:`verification-history`,"aria-label":`Verification history`,children:[(0,B.jsxs)(`div`,{className:`verification-history__head`,children:[(0,B.jsx)(`strong`,{children:`Verification`}),(0,B.jsxs)(`span`,{className:`muted`,children:[e.attempts.length,` attempts`]})]}),e.attempts.map(t=>(0,B.jsx)(xc,{trigger:(0,B.jsx)(`span`,{className:`verification-history__attempt`,children:Mh(t)}),defaultIsOpen:t.attempt===e.attempts.length,children:(0,B.jsx)(`div`,{className:`verification-history__checks`,children:t.checks.length>0?t.checks.map(e=>(0,B.jsx)(Nh,{check:e},e.check_id)):(0,B.jsx)(`p`,{className:`muted`,children:`No completion checks ran in this attempt.`})})},t.attempt)),e.manual_recovery?.status===`available`?(0,B.jsxs)(`section`,{className:`manual-recovery`,"aria-label":`Manual recovery`,children:[(0,B.jsx)(`strong`,{children:`Manual recovery required`}),(0,B.jsx)(`p`,{className:`muted`,children:`This stage remains failed until an operator explicitly retries it or stops recovery.`}),(0,B.jsx)(`label`,{className:`manual-recovery__label`,htmlFor:`manual-recovery-guidance`,children:`Guidance for the retry (optional)`}),(0,B.jsx)(`textarea`,{id:`manual-recovery-guidance`,className:`manual-recovery__guidance`,value:a,maxLength:4e3,onChange:e=>o(e.target.value),placeholder:`Tell the agent what to address before it retries.`,disabled:n}),(0,B.jsxs)(`div`,{className:`manual-recovery__actions`,children:[(0,B.jsx)(`button`,{type:`button`,className:`btn btn--primary`,disabled:n||r===void 0,onClick:()=>r?.(a),children:n?`Starting recovery…`:`Retry with guidance`}),(0,B.jsx)(`button`,{type:`button`,className:`btn btn--sm btn--reject`,disabled:n||i===void 0,onClick:()=>i?.(),children:`Stop recovery`})]})]}):null,e.manual_recovery?.status===`stopped`?(0,B.jsx)(`p`,{className:`muted`,children:`Manual recovery was stopped by an operator.`}):null]})}function Fh(e){let{readiness:t,blocked_by:n,status:r}=e;if(t===`blocked`)return n?.length?`Blocked on ${n.join(`, `)}`:`Blocked`;if(t===`skipped`)return`Skipped`;if(t===`ready`)return`Ready`;if(t!==`waiting`||r!==`waiting_for_input`){if(t===`succeeded`)return Hr(`succeeded`);if(t===`failed`)return Hr(`failed`);if(t===`running`)return Hr(`running`)}}var Ih=`stageflow:envelope:`;function Lh(e){return`${Ih}${e}`}function Rh(e){if(!e.startsWith(Ih))return null;let t=e.slice(19);return t.length>0?t:null}function zh(e,t){return`${e}->${t}`}var Bh={deferred:3,replay:2,policy:1},Vh=new Set([`scheduled`,`active`,`waiting_for_human`]);function Hh(e,t,n){let r=new Map,i=e=>{let t=zh(e.from,e.to),n=r.get(t);(!n||Bh[e.kind]>Bh[n.kind])&&r.set(t,e)};for(let e of n?.nodes??[]){let t=e.feedback_loop?.target;t&&i({from:e.stage_id,to:t,kind:`policy`})}e?.deferred_send_back?.target&&i({from:e.source_stage_id,to:e.deferred_send_back.target,kind:`deferred`});let a=!!e?.deferred_send_back?.target,o=e=>{for(let n of t??[])for(let{replay:t}of n.replays)t.status!==`superseded`&&t.status!==`failed`&&e(t.status)&&i({from:t.source_stage_id,to:t.target_stage_id,kind:`replay`})};return o(e=>Vh.has(e)),![...r.values()].some(e=>e.kind===`replay`)&&!a&&o(e=>e===`completed`),e&&i({from:e.source_stage_id,to:e.policy.target,kind:`policy`}),[...r.values()]}function Uh(e){let t=new Set;for(let n of e??[]){for(let e of n.fork_generations)if(e.status===`superseded`)for(let n of e.clone_stage_ids)t.add(n);for(let{stage_passes:e,fork_generations:r}of n.replays){for(let n of e)n.status===`superseded`&&t.add(n.stage_id);for(let e of r)if(e.status===`superseded`)for(let n of e.clone_stage_ids)t.add(n)}}return t}function Wh(e,t){for(let n of t)if(n.status===`superseded`)for(let t of n.clone_stage_ids)e.add(t)}function Gh(e){let t=new Set;for(let n of e??[]){Wh(t,n.fork_generations);for(let e of n.replays)Wh(t,e.fork_generations)}return t}function Kh(e,t){return e.filter(e=>!t.has(e))}function qh(e,t){return t.size===0?e:{nodes:e.nodes.filter(e=>!t.has(e.stage_id)),edges:e.edges.filter(e=>!t.has(e.from)&&!t.has(e.to))}}function Jh(e){let t=e.active_feedback_loop;if(!(e.waiting_kind!==`feedback_loop_decision`||!t||t.state!==`waiting_for_human`))return{loopId:t.loop_id,sourceStageId:t.source_stage_id,deferredTarget:t.deferred_send_back?.target,replayNumber:t.current_replay_number,maxReplays:t.policy.max_replays,summary:e.waiting_summary}}function Yh(e,t){return e.stages.some(e=>e.stage_id===t)}function Xh(e,t,n){return Yh(e,t)||e.pipeline_track?.nodes?.some(e=>e.stage_id===t)?!0:!!n?.includes(t)}function Zh(e){return new Map(e.stages.map(e=>[e.stage_id,e]))}function Qh(e){let t=e.pipeline_track;return t?.nodes?.length?Gm(t.nodes).map(e=>e.stage_id):e.stages.map(e=>e.stage_id)}function $h(e){let t=e.waiting_stage_id;if(!t)return null;let n=e.stages.find(e=>e.stage_id===t)?.pending_prompt?.id;return n?`${t}:${n}`:e.waiting_prompt_id?e.waiting_prompt_id:Yh(e,t)?`${t}:`:null}function eg(e,t){if(t.userPicked&&t.previousStageId&&Yh(e,t.previousStageId))return t.previousStageId;let n=$h(e);return n&&n!==t.dismissedWaitKey&&e.waiting_stage_id&&Yh(e,e.waiting_stage_id)?e.waiting_stage_id:null}function tg(e,t){return e.artifacts.includes(t)?!0:!!e.envelope?.artifacts.includes(t)}function ng(e,t){let n=Zh(e);for(let r of Qh(e)){let e=n.get(r);if(e&&tg(e,t))return r}return null}function rg(e,t,n){return t===void 0||t===``?e:e===t?t:n===void 0?e:`${t} · ${n}`}function ig(e,t,n){if(n===void 0)return;let r=Gm(e).filter(e=>(e.definition_id??e.stage_id)===n).findIndex(e=>e.stage_id===t);if(!(r<0))return r+1}function ag(e,t){return rg(t.stage_id,t.definition_id,ig(e,t.stage_id,t.definition_id))}function og(e,t){let n=e.pipeline_track?.nodes??[],r=n.find(e=>e.stage_id===t);return r?ag(n,r):rg(t)}function sg(e,t,n){let r=Wr(e.status);return{id:e.stage_id,label:n??e.stage_id,status:r,selected:e.stage_id===t,meta:r===`waiting`?Hr(e.status):e.last_at,envelope:e.envelope?{summary:e.envelope.summary,artifactCount:e.envelope.artifacts.length}:null}}function cg(e,t,n){return{id:e,label:n??e,status:`pending`,selected:e===t,meta:`pending`,envelope:null}}function lg(e,t,n,r){let i=ag(r,e);return t?sg(t,n,i):cg(e.stage_id,n,i)}function ug(e,t,n){if(!n||n.length===0)return e.map(e=>sg(e,t));let r=new Map(e.map(e=>[e.stage_id,e])),i=new Set,a=[];for(let e of n){i.add(e);let n=r.get(e);a.push(n?sg(n,t):cg(e,t))}for(let n of e)i.has(n.stage_id)||a.push(sg(n,t));return a}function dg(e,t,n){return e.waiting_stage_ids?.includes(t)?!0:n===`waiting_for_input`}function fg(e){if(e)switch(e.kind){case`free_text`:case`confirm`:return e.message;case`artifact_backed`:return e.message||e.artifacts[0];case`multi_question`:return e.questions.length===1?`1 question`:`${e.questions.length} questions`}}function pg(e,t,n,r,i,a){return Gm(t).map(o=>{let s=n.get(o.stage_id),c=s?.status??o.status;return{stageId:o.stage_id,title:ag(t,o),kicker:o.definition_id??o.stage_id,status:c,attemptCount:s?.attempt_count??o.attempt_count??1,readinessLine:Fh({readiness:o.readiness,blocked_by:o.blocked_by,status:c}),gateKinds:o.gate_kinds,meta:c===`running`?s?.last_at:void 0,promptSummary:c===`waiting_for_input`?fg(s?.pending_prompt):void 0,isWaitingAttention:dg(e,o.stage_id,c),isFeedbackSource:r.has(o.stage_id)||void 0,isFeedbackTarget:i.has(o.stage_id)||void 0,isSuperseded:a.has(o.stage_id)||void 0}})}function mg(e,t,n,r,i,a){return t.map(t=>{let o=n.get(t.id),s=o?.status??`pending`;return{stageId:t.id,title:t.label,kicker:t.id,status:s,attemptCount:o?.attempt_count??1,meta:s===`running`?o?.last_at:void 0,promptSummary:s===`waiting_for_input`?fg(o?.pending_prompt):void 0,isWaitingAttention:dg(e,t.id,s),isFeedbackSource:r.has(t.id)||void 0,isFeedbackTarget:i.has(t.id)||void 0,isSuperseded:a.has(t.id)||void 0}})}function hg(e,t,n,r,i,a){let o=Zh(e),s=qh(e.pipeline_track,a),c=n&&Kh(n,a),l=Ym(s,{liveStageIds:Kh(e.stages.map(e=>e.stage_id),a),plannedStageIds:c}),u=new Set(r.map(e=>e.from)),d=new Set(r.map(e=>e.to));if(!s.nodes.length){let n=ug(e.stages.filter(e=>!a.has(e.stage_id)),t,c);return{spatialLayout:l,nodeChrome:mg(e,n,o,u,d,i),trackStages:n}}let f=s.nodes,p=Gm(f).map(e=>lg(e,o.get(e.stage_id),t,f));return{spatialLayout:l,nodeChrome:pg(e,f,o,u,d,i),trackStages:p}}function gg(e,t,n){return e===`stream`?t===`waiting_for_input`&&n?{kind:`reply`,prompt:n}:!t||t===`succeeded`||t===`failed`||t===`pending`||t===`skipped`?{kind:`idle`,label:`Session closed`}:{kind:`none`}:{kind:`none`}}function _g(e){return e===`waiting_for_input`?`alive`:e===`succeeded`||e===`failed`||e===`pending`||e===`skipped`?`closed`:null}function vg(e){let t=[];for(let n of e.stages)for(let r of n.artifacts)t.push({path:r,meta:og(e,n.stage_id)});return t}function yg(e,t){let n=vg(e);return t?.envelope?[{path:Lh(t.stage_id),label:`Handoff envelope`,meta:og(e,t.stage_id)},...n]:n}function bg(e,t,n){let r=e.pipeline_track;if(r?.nodes?.length)return r.edges.find(e=>e.to===t)?.from;if(n&&n.length>0){let e=n.indexOf(t);if(e>0)return n[e-1]}let i=e.stages.findIndex(e=>e.stage_id===t);if(i>0)return e.stages[i-1]?.stage_id}function xg(e,t,n){let r=e.pipeline_track;if(r?.nodes?.length){let e=r.edges.filter(e=>e.from===t);return e.length===1?e[0]?.to:void 0}if(n&&n.length>0){let e=n.indexOf(t);if(e>=0)return n[e+1]}let i=e.stages.findIndex(e=>e.stage_id===t);if(!(i<0))return e.stages[i+1]?.stage_id}function Sg(e){return e?.kind===`artifact_backed`?e:void 0}function Cg(e){return e?.status===`waiting_for_input`&&e.pending_prompt?.kind===`artifact_backed`}function wg(e,t){return t.retrying||t.abandoning?!0:e?e.status===`created`||e.status===`running`||e.waiting_stage_id?!0:e.stages.some(e=>e.status===`running`||e.status===`waiting_for_input`):!1}function Tg(e,t,n,r){let i=eg(t,n),a=e.kind===`stream`&&e.stageId&&Xh(t,e.stageId,r)?e.stageId:i,o=e.kind===`envelope`?e.stageId:e.kind===`artifact`?ng(t,e.path):a,s=t.stages.find(e=>e.stage_id===o)??null,c=t.pipeline_track?.nodes?.length?void 0:r,l=o?bg(t,o,c):void 0,u=l?t.stages.find(e=>e.stage_id===l):void 0,d=Cg(s),f=e.kind===`artifact`&&!!n.wasWaitingArtifact&&!d,p;p=e.kind===`envelope`?`envelope`:e.kind===`artifact`&&!f?`artifact`:o?`stream`:`empty`;let m=p===`artifact`&&d,h=m?Sg(s?.pending_prompt):void 0,g=Jh(t),_=!!g,v=Hh(t.active_feedback_loop,t.feedback_loops,t.pipeline_track),y=Gh(t.feedback_loops),b=Uh(t.feedback_loops),x=e.kind===`envelope`?e.stageId:null,S=x?t.stages.find(e=>e.stage_id===x)??null:null,C=e.kind===`envelope`?{fromStageId:e.stageId,toStageId:xg(t,e.stageId,c),envelope:S?.envelope??null}:null,w=(n.drawerStageId?t.stages.find(e=>e.stage_id===n.drawerStageId)??null:null)?.envelope??null,T=p!==`envelope`&&n.drawerStageId&&w?{fromStageId:n.drawerStageId,toStageId:xg(t,n.drawerStageId,c),envelope:w}:null,{spatialLayout:E,nodeChrome:D,trackStages:O}=hg(t,o,r,v,b,y);return{selectedStageId:o,selectedStage:s,kind:p,composer:gg(p,s?.status,s?.pending_prompt),showDecide:m,decidePrompt:h,showFeedbackDecide:_,feedbackDecide:g,feedbackOverlays:v,artifactReadOnly:!m,selectedPath:p===`artifact`&&e.kind===`artifact`?e.path:p===`envelope`&&e.kind===`envelope`?Lh(e.stageId):void 0,trackStages:O,spatialLayout:E,nodeChrome:D,artifactFiles:yg(t,s),sessionChip:_g(s?.status),inboundEnvelope:u?.envelope??null,inboundFromStageId:u?.stage_id,inboundToStageId:s?.stage_id,drawer:T,envelope:C,liveStream:s?.status===`running`||s?.status===`waiting_for_input`,activeEnvelopeId:e.kind===`envelope`?e.stageId:n.drawerStageId,waitingArtifact:d,syncStreamRoute:f}}function Eg(e){return e.syncStreamRoute?{action:`openStream`,stageId:e.selectedStageId??void 0}:e.view.kind!==`stream`||!e.run?{action:`none`}:e.streamViewStageId&&!Xh(e.run,e.streamViewStageId,e.plannedStageIds)?{action:`openStream`}:e.userPickedStageId||e.dismissedWaitKey||!e.selectedStageId||e.streamViewStageId===e.selectedStageId?{action:`none`}:{action:`openStream`,stageId:e.selectedStageId}}var Dg=300,Og=200,kg=140,Ag=24;function jg(e,t){let n=t-kg;return t<340?Math.max(0,n):Math.max(Og,Math.min(e,n))}function Mg(e){return e===`alive`?(0,B.jsx)(`span`,{className:`chip`,children:`session alive`}):e===`closed`?(0,B.jsx)(`span`,{className:`chip`,children:`session closed`}):null}function Ng(e,t,n){let r=t.selectedStage;if(t.composer.kind===`reply`&&r)return(0,B.jsx)(`div`,{className:`composer`,children:(0,B.jsx)(`div`,{className:`composer__inner`,children:(0,B.jsx)(Bc,{runId:e,stageId:r.stage_id,prompt:t.composer.prompt,onReviewSideBySide:n})})});if(t.composer.kind===`idle`)return(0,B.jsx)(`div`,{className:`composer composer--idle`,children:(0,B.jsx)(`div`,{className:`composer__inner`,children:(0,B.jsx)(`p`,{className:`muted`,children:t.composer.label})})})}function Pg({runId:e,view:t,onBack:n,onReran:r,onOpenStream:i,onOpenArtifact:a,onOpenEnvelope:o}){let[s,c]=(0,v.useState)(null),[l,u]=(0,v.useState)(null),[d,f]=(0,v.useState)(null),[p,m]=(0,v.useState)(null),[h,g]=(0,v.useState)(null),[_,y]=(0,v.useState)(!1),[b,x]=(0,v.useState)(null),[S,C]=(0,v.useState)(()=>t.kind===`stream`&&t.stageId?t.stageId:null),w=(0,v.useRef)(null),[T,E]=(0,v.useState)(null),[D,O]=(0,v.useState)(null),[k,A]=(0,v.useState)(Dg),[j,M]=(0,v.useState)(null),[N,ee]=(0,v.useState)(0),[P,F]=(0,v.useState)(!1),I=(0,v.useRef)(null),te=(0,v.useRef)(null),[ne,re]=(0,v.useState)(!1),ie=(0,v.useRef)(!1),ae=(0,v.useRef)(i);ae.current=i;let L=mr(),oe=t.kind===`stream`?t.stageId:void 0,se=(0,v.useCallback)(async()=>{try{let t=await Dn(e);c(t),f(null)}catch(e){f(e instanceof Error?e.message:String(e))}},[e]),ce=(0,v.useCallback)(async()=>{await se(),L.refresh()},[se,L]),le=(0,v.useCallback)(async(t,n)=>{y(!0),x(null);try{await Qn(e,t,n),await ce()}catch(e){x(e instanceof Error?e.message:String(e))}finally{y(!1)}},[ce,e]),ue=(0,v.useCallback)(async t=>{if(window.confirm(`Stop manual recovery? This stage will remain failed in this run.`)){y(!0),x(null);try{await $n(e,t),await ce()}catch(e){x(e instanceof Error?e.message:String(e))}finally{y(!1)}}},[ce,e]),{retryingStageIds:de,error:fe,retry:pe,clearError:me}=th(e,ce),he=(0,v.useCallback)(e=>{C(e),i(e),pe(e)},[i,pe]),{resumingStageIds:ge,error:_e,resume:ve,clearError:ye}=rh(e,ce),be=(0,v.useCallback)(e=>{C(e),i(e),ve(e)},[i,ve]),{abandoningStageId:xe,error:Se,abandon:Ce,clearError:we}=ah(e,ce),Te={retryingStageIds:de,abandoningStageId:xe,resumingStageIds:ge};(0,v.useEffect)(()=>{C(oe??null),w.current=null,E(null),O(null),A(Dg),M(null),c(null),f(null),m(null),g(null),y(!1),x(null),ie.current=!1},[e]),(0,v.useEffect)(()=>{se()},[se]),(0,v.useEffect)(()=>{t.kind===`stream`&&C(oe??null)},[t.kind,oe]),(0,v.useEffect)(()=>{let e=!1;return An().then(t=>{e||u(t.pipelines)}).catch(()=>{e||u([])}),()=>{e=!0}},[]);let Ee=wg(s,{retrying:de.size>0,abandoning:xe!==null});(0,v.useEffect)(()=>{if(!Ee)return;let e=window.setInterval(()=>void se(),1e3);return()=>window.clearInterval(e)},[se,Ee]);let De=l?.find(e=>e.id===s?.pipeline_id)?.stages.map(e=>e.id)??[],R=s?Tg(t,s,{previousStageId:S??w.current,userPicked:S!==null,drawerStageId:T,dismissedWaitKey:D,wasWaitingArtifact:ie.current},De):null,Oe=R?.selectedStageId,ke=R?.selectedStage?.attempt_count;(0,v.useEffect)(()=>{if(!Oe){m(null),g(null);return}let t=!1;return m(null),g(null),On(e,Oe).then(e=>{t||m(e)}).catch(e=>{t||g(e instanceof Error?e.message:String(e))}),()=>{t=!0}},[e,Oe,ke]),R&&(w.current=R.selectedStageId),R?.waitingArtifact?ie.current=!0:t.kind!==`artifact`&&(ie.current=!1),(0,v.useEffect)(()=>{let e=Eg({view:t,streamViewStageId:oe,run:s,plannedStageIds:De,selectedStageId:R?.selectedStageId??null,syncStreamRoute:R?.syncStreamRoute??!1,userPickedStageId:S,dismissedWaitKey:D});e.action===`openStream`&&ae.current(e.stageId)},[t,oe,s,De,R?.selectedStageId,R?.syncStreamRoute,S,D]),(0,v.useEffect)(()=>{let e=I.current;if(!e)return;let t=()=>ee(e.getBoundingClientRect().height);t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[]);let Ae=(0,v.useCallback)(e=>{let t=I.current?.getBoundingClientRect().height??N;A(jg(e,t))},[N]),je=(0,v.useCallback)(()=>{s&&O($h(s)),C(null),w.current=null,E(null),i()},[i,s]),Me=(0,v.useCallback)(()=>{let e=R?.selectedStageId??(t.kind===`envelope`?t.stageId:void 0)??S;if(e){C(e),i(e);return}i()},[i,S,t,R?.selectedStageId]);async function Ne(){re(!0),f(null),me(),we(),ye();try{r((await Yn(e)).runId)}catch(e){f(e instanceof Error?e.message:String(e))}finally{re(!1)}}let z=R?.selectedStage??null,Pe=p!==null&&p.stage_id===z?.stage_id?p.manual_recovery:void 0,Fe=R?.selectedPath,Ie=s?Vr(s.status):void 0,Le=R?Ng(e,R,a):void 0,Re=!!(R&&R.spatialLayout.nodes.length>0),ze=!!(R&&(R.selectedStageId||R.kind===`artifact`||R.kind===`envelope`)),Be=z?Rr(z.events):!1,Ve=(0,B.jsx)(`button`,{type:`button`,className:`btn btn--sm`,onClick:je,children:`Hide workspace`}),He;if(d)He=(0,B.jsx)(`div`,{style:{padding:`var(--spacing-4)`},children:(0,B.jsx)(`div`,{className:`banner banner--error`,children:d})});else if(!s||!R)He=(0,B.jsx)(`div`,{style:{padding:`var(--spacing-4)`},children:(0,B.jsx)(`p`,{children:`Loading…`})});else if(R.kind===`artifact`&&Fe)He=(0,B.jsx)(Mp,{runId:e,path:Fe,readOnly:R.artifactReadOnly,onBackToTranscript:Me,onHide:je});else if(R.kind===`envelope`&&R.envelope)He=R.envelope.envelope?(0,B.jsx)(Hp,{fromStageId:R.envelope.fromStageId,toStageId:R.envelope.toStageId,envelope:R.envelope.envelope,onBackToTranscript:Me,onHide:je,onArtifactClick:a,stageLabel:e=>og(s,e)}):(0,B.jsxs)(`div`,{className:`stream`,style:{height:`100%`},children:[(0,B.jsxs)(`header`,{className:`stream__head`,children:[(0,B.jsx)(`h3`,{className:`stream__name`,children:`Handoff envelope`}),(0,B.jsx)(`span`,{className:`topbar__spacer`}),(0,B.jsxs)(`div`,{className:`stream__head-trail`,children:[(0,B.jsx)(`button`,{type:`button`,className:`btn btn--sm`,onClick:Me,children:`← Transcript`}),Ve]})]}),(0,B.jsx)(`div`,{style:{padding:`var(--spacing-4)`},children:(0,B.jsxs)(`div`,{className:`banner banner--warning`,children:[R.envelope.fromStageId,` has not emitted a handoff envelope.`]})})]});else if(R.selectedStageId){let e=R.selectedStageId,t=z?Vr(z.status):void 0,n=j!==`transcript`,r=j!==`logs`,i=(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`button`,{type:`button`,className:`btn btn--sm`,onClick:()=>M(r?`logs`:null),children:r?`Hide logs`:`Show logs`}),Ve]}),a=(0,B.jsxs)(B.Fragment,{children:[z?(0,B.jsx)(Yr,{costUsd:z.cost_usd}):null,(0,B.jsx)(`button`,{type:`button`,className:`btn btn--sm`,onClick:()=>M(n?`transcript`:null),children:n?`Hide transcript`:`Show transcript`}),Ve]});He=(0,B.jsxs)(`div`,{className:`center-split`,children:[(0,B.jsx)(`div`,{className:`center-split__transcript`,hidden:!n,children:(0,B.jsxs)(Ah,{stageName:R.trackStages.find(t=>t.id===e)?.label??e,status:(0,B.jsxs)(B.Fragment,{children:[Be?(0,B.jsxs)(`span`,{className:`status status--failed`,children:[(0,B.jsx)(`span`,{className:`dot dot--failed`}),` `,zr()]}):(0,B.jsxs)(`span`,{className:`status${t&&t!==`running`?` status--${t}`:``}`,children:[(0,B.jsx)(`span`,{className:`dot${t?` dot--${t}`:``}`}),` `,z?Hr(z.status):`pending`]}),z?(0,B.jsx)(Hc,{count:z.attempt_count}):null,z?(0,B.jsx)(Yr,{costUsd:z.cost_usd}):null,Mg(R.sessionChip),z&&Qm(z)&&Pe===void 0?(0,B.jsx)(`button`,{type:`button`,className:`btn btn--sm`,disabled:$m(Te,z.stage_id),onClick:()=>be(z.stage_id),children:ge.has(z.stage_id)?`Resuming…`:`Resume session`}):null,z&&Xm(z.status)&&Pe===void 0?(0,B.jsx)(`button`,{type:`button`,className:`btn btn--sm`,disabled:$m(Te,z.stage_id),onClick:()=>he(z.stage_id),children:de.has(z.stage_id)?`Retrying…`:`Retry stage`}):null,z&&Zm(z.status)?(0,B.jsx)(`button`,{type:`button`,className:`btn btn--sm btn--reject`,disabled:$m(Te,z.stage_id),onClick:()=>Ce(z.stage_id),children:xe===z.stage_id?`Abandoning…`:`Abandon`}):null]}),trailing:i,autoScroll:R.liveStream,scrollKey:z?.events.length,composer:Le,children:[(0,B.jsx)(bm,{events:z?.events??[],inboundEnvelope:R.inboundEnvelope}),(0,B.jsx)(Ph,{history:p,error:h,recovering:_,onRecover:z?e=>void le(z.stage_id,e):void 0,onStop:z?()=>void ue(z.stage_id):void 0})]})}),(0,B.jsx)(`div`,{className:`center-split__logs`,hidden:!r,children:(0,B.jsx)(Um,{events:z?.events??[],headerAction:a})})]})}let Ue=Math.max(0,N-kg),We=N<340?Ue:Og;return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(`div`,{ref:I,className:`pane run-detail${ze?` has-stage`:``}${P?` is-resizing`:``}`,style:{height:`100%`,"--work-h":`${k}px`},children:[(0,B.jsxs)(`div`,{children:[(0,B.jsxs)(`div`,{className:`topbar`,children:[(0,B.jsx)(`a`,{className:`topbar__back`,href:`#/runs`,onClick:e=>{e.preventDefault(),n()},children:`← Runs`}),(0,B.jsx)(`h2`,{className:`topbar__title`,children:s?yr(s):`Loading…`}),s?(0,B.jsx)(`span`,{className:`topbar__sub`,title:vr(s),children:vr(s)}):null,s?(0,B.jsxs)(`span`,{className:`status${Ie&&Ie!==`running`?` status--${Ie}`:``}`,children:[(0,B.jsx)(`span`,{className:`dot${Ie?` dot--${Ie}`:``}`}),` `,Hr(s.status)]}):null,s&&Jr(s.total_cost_usd)?(0,B.jsx)(`span`,{className:`topbar__sub`,title:`Total cost across every stage in this run`,children:Jr(s.total_cost_usd)}):null,(0,B.jsx)(`span`,{className:`topbar__spacer`}),(0,B.jsx)(`button`,{className:`btn btn--primary`,disabled:ne,onClick:()=>void Ne(),children:ne?s?.status===`created`?`Starting…`:`Starting fresh…`:s?.status===`created`?`Start run`:`Start fresh`})]}),fe?(0,B.jsx)(`div`,{className:`banner banner--error`,style:{padding:`var(--spacing-3) var(--spacing-5)`},children:fe}):null,_e?(0,B.jsx)(`div`,{className:`banner banner--error`,style:{padding:`var(--spacing-3) var(--spacing-5)`},children:_e}):null,Se?(0,B.jsx)(`div`,{className:`banner banner--error`,style:{padding:`var(--spacing-3) var(--spacing-5)`},children:Se}):null,b?(0,B.jsx)(`div`,{className:`banner banner--error`,style:{padding:`var(--spacing-3) var(--spacing-5)`},children:b}):null]}),d&&!s?(0,B.jsx)(`div`,{style:{padding:`var(--spacing-4)`},children:(0,B.jsx)(`div`,{className:`banner banner--error`,children:d})}):!s||!R?(0,B.jsx)(`div`,{style:{padding:`var(--spacing-4)`},children:(0,B.jsx)(`p`,{children:`Loading…`})}):Re?(0,B.jsxs)(`div`,{className:`workspace`,children:[s.active_feedback_loop||(s.feedback_loops?.length??0)>0?(0,B.jsx)($p,{active:s.active_feedback_loop,history:s.feedback_loops??[]}):null,(0,B.jsx)(wh,{layout:R.spatialLayout,stages:s.stages,nodeChrome:R.nodeChrome,selectedStageId:R.selectedStageId,onSelectStage:e=>{C(e),i(e)},onDeselect:je,retryingStageIds:de,onRetryStage:he,resumingStageIds:ge,onResumeStage:be,abandoningStageId:xe,onAbandonStage:Ce,runId:e,showHint:!ze,feedbackOverlays:R.feedbackOverlays})]}):(0,B.jsx)(`div`,{style:{padding:`var(--spacing-4)`},children:(0,B.jsx)(`p`,{children:`No stages have started yet.`})}),ze&&s&&R?(0,B.jsxs)(`div`,{className:`work`,children:[(0,B.jsx)(`div`,{className:`work-split${P?` is-dragging`:``}`,role:`separator`,"aria-orientation":`horizontal`,"aria-label":`Resize workspace`,"aria-valuemin":We,"aria-valuemax":Ue,"aria-valuenow":Math.round(k),tabIndex:0,onPointerDown:e=>{(e.button==null||e.button===0)&&(e.preventDefault(),e.currentTarget.setPointerCapture(e.pointerId),F(!0),te.current={id:e.pointerId,y:e.clientY,h:k})},onPointerMove:e=>{let t=te.current;!t||t.id!==e.pointerId||Ae(t.h+(t.y-e.clientY))},onPointerUp:e=>{te.current?.id===e.pointerId&&(te.current=null,F(!1))},onPointerCancel:e=>{te.current?.id===e.pointerId&&(te.current=null,F(!1))},onKeyDown:e=>{e.key===`ArrowUp`&&(e.preventDefault(),Ae(k+Ag)),e.key===`ArrowDown`&&(e.preventDefault(),Ae(k-Ag)),e.key===`Home`&&(e.preventDefault(),Ae(Ue)),e.key===`End`&&(e.preventDefault(),Ae(We))},children:(0,B.jsx)(`span`,{className:`work-split__grip`,"aria-hidden":`true`})}),(0,B.jsxs)(`div`,{className:`work-row`,children:[(0,B.jsx)(`div`,{className:`aside`,style:{width:240,flexShrink:0,overflow:`auto`},children:(0,B.jsx)(Wc,{files:R.artifactFiles,selectedPath:Fe,onSelect:e=>{let t=Rh(e);if(t){C(t),o(t);return}a(e)},footer:(0,B.jsx)(xc,{trigger:(0,B.jsx)(`span`,{style:{fontSize:`var(--font-size-sm)`,fontWeight:500},children:`Input`}),defaultIsOpen:!1,children:(0,B.jsx)(lc,{code:s.task_yaml,language:`yaml`,container:`section`,maxHeight:200,width:`100%`})})})}),(0,B.jsx)(`div`,{style:{flex:1,minWidth:0,minHeight:0,display:`flex`,flexDirection:`column`},children:He}),R.showFeedbackDecide&&R.feedbackDecide?(0,B.jsx)(`div`,{className:`decide`,style:{width:320,flexShrink:0},children:(0,B.jsx)(Jp,{runId:e,decide:R.feedbackDecide,onSuccess:ce})}):R.showDecide&&R.decidePrompt&&z?(0,B.jsx)(`div`,{className:`decide`,style:{width:320,flexShrink:0},children:(0,B.jsx)(zp,{runId:e,stageId:z.stage_id,prompt:R.decidePrompt,events:z.events,inboundEnvelope:R.inboundEnvelope,inboundFromStageId:R.inboundFromStageId,inboundToStageId:R.inboundToStageId,selectedPath:Fe,onSelectArtifact:a,onOpenInboundEnvelope:R.inboundFromStageId?()=>{let e=R.inboundFromStageId;e&&E(e)}:void 0})}):null]})]}):null]}),R?.drawer?(0,B.jsx)(Gp,{isOpen:!0,onClose:()=>E(null),fromStageId:R.drawer.fromStageId,toStageId:R.drawer.toStageId,envelope:R.drawer.envelope,onOpenFullRecord:()=>{let e=R.drawer?.fromStageId;E(null),e&&o(e)},onArtifactClick:e=>{E(null),a(e)}}):null]})}function Fg({label:e,status:t,index:n,meta:r,selected:i,onClick:a}){let o=Gr(t)||(n==null?``:String(n+1));return(0,B.jsxs)(`button`,{type:`button`,className:`node`,"data-s":t,"data-selected":i?`true`:void 0,onClick:a,"aria-disabled":!a,style:{cursor:a?`pointer`:`default`},children:[(0,B.jsx)(`span`,{className:`node__ring`,"aria-hidden":`true`,children:o}),(0,B.jsx)(`span`,{className:`node__name`,children:e}),r?(0,B.jsx)(`span`,{className:`node__meta`,children:r}):null]})}function Ig(e){return e===1?`1 file`:`${e} files`}function Lg({mode:e,flowed:t,envelope:n,fromStageId:r,selected:i,onEnvelopeClick:a}){let o=n==null,s=o?`no envelope yet`:`envelope · ${Ig(n.artifactCount)}`;return(0,B.jsxs)(`span`,{className:`wire`,"data-flowed":t?`true`:void 0,children:[(0,B.jsx)(`span`,{className:`wire__line`}),e===`definition`?null:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`button`,{className:`wire__env`,disabled:o||!a,"data-selected":i?`true`:void 0,onClick:o||!a?void 0:()=>a(r),children:s}),n?.summary?(0,B.jsx)(`span`,{className:`wire__summary`,children:n.summary}):null]})]})}function Rg({stages:e,mode:t=`run`,onSelect:n,onEnvelopeClick:r,activeEnvelopeId:i}){return(0,B.jsx)(`nav`,{className:`track`,"aria-label":`Pipeline track`,children:(0,B.jsx)(`div`,{className:`track__rail`,children:e.map((a,o)=>(0,B.jsxs)(v.Fragment,{children:[(0,B.jsx)(Fg,{id:a.id,label:a.label,status:a.status,index:o,meta:a.meta,selected:a.selected,onClick:n&&a.status!==`pending`?()=>n(a.id):void 0}),o<e.length-1?(0,B.jsx)(Lg,{mode:t,flowed:a.envelope!=null,envelope:a.envelope,fromStageId:a.id,selected:i===a.id,onEnvelopeClick:r}):null]},a.id))})})}var zg=`Providers are connected through Pi. Stageflow binds the credential store you choose; it is not a standalone non-Pi LLM client.`;function Bg(e){return e.credentialSource===void 0}function Vg(e){return e?`pi_home`:`sf_owned`}function Hg(e){return e.supportsApiKey}function Ug(e){return e.supportsOauth&&!e.supportsApiKey}function Wg(e){return e?e.configured?e.authKind===`oauth`?`Connected (OAuth)`:e.authKind===`api_key`?`Connected (API key)`:`Connected`:`Not connected`:`Unknown`}function Gg(e){return e.credentialSource===void 0?!1:e.credentialSource===`pi_home`||e.configuredCount>0}function Kg(e){return e.filter(e=>e?.configured===!0).length}async function qg(){let e=await zn();if(Bg(e))return{ready:!1,message:`Connect providers before starting a run. Choose an existing Pi login or add API keys in Stageflow.`};let t=e.credentialSource;if(t===`pi_home`)return{ready:!0,credentialSource:t};let n=await Rn();return Gg({credentialSource:t,configuredCount:Kg(await Promise.all(n.providers.map(async e=>{try{let{provider:t}=await Bn(e.id);return t}catch{return}})))})?{ready:!0,credentialSource:t}:{ready:!1,credentialSource:t,message:`Connect at least one provider API key in Settings → Providers (or #/connect) before starting a run.`}}function Jg(e){return e===void 0?`all kinds`:e.length===0?`no gate`:`will ask you`}function Yg({onStarted:e,initialPipelinePath:t,initialTaskPath:n}){let[r,i]=(0,v.useState)([]),[a,o]=(0,v.useState)([]),[s,c]=(0,v.useState)(``),[l,u]=(0,v.useState)(``),[d,f]=(0,v.useState)(null),[p,m]=(0,v.useState)(!1),[h,g]=(0,v.useState)(null),[_,y]=(0,v.useState)(null),{snapshot:b,error:x}=pr(),S=b.health;(0,v.useEffect)(()=>{(async()=>{try{let[e,r]=await Promise.all([kn(),An()]);i(e.tasks),o(r.pipelines);let a=n&&e.tasks.some(e=>e.path===n)?n:e.tasks[0]?.path??``,s=t&&r.pipelines.some(e=>e.path===t)?t:r.pipelines[0]?.path??``;c(a),u(s)}catch(e){f(e instanceof Error?e.message:String(e))}})()},[t,n]);let C=a.find(e=>e.path===l)??null,w=(0,v.useMemo)(()=>C?C.stages.map(e=>({id:e.id,label:e.id,status:Mr(e.gate_kinds)?`waiting`:`pending`,meta:Jg(e.gate_kinds)})):[],[C]),T=S!=null&&S.slotsAvailable===0,E=S==null?0:Or(b,S.activeRunIds).length,D=d??(S==null&&x?x:null);async function O(){if(!s||!l){f(`Pick a task and a pipeline.`);return}m(!0),f(null),g(null),y(null);try{let e=await qg();if(!e.ready){y(e.message??`Connect providers before starting a run.`),m(!1);return}}catch(e){y(e instanceof Error?e.message:String(e)),m(!1);return}let t=await Jn(s,l);if(m(!1),t.ok){e(t.runId);return}g(t)}return(0,B.jsxs)(`div`,{className:`main__inner`,children:[(0,B.jsxs)(`p`,{className:`crumbs`,children:[(0,B.jsx)(`a`,{href:`#/today`,children:`Today`}),` / start a run`]}),(0,B.jsx)(`div`,{className:`page-head`,children:(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`h1`,{children:`Start a run`}),(0,B.jsx)(`p`,{children:`A run is a task path plus a pipeline path. Nothing else is decided here.`})]})}),T&&S?(0,B.jsxs)(`div`,{className:`gate`,style:{padding:`var(--spacing-4)`,marginBottom:`var(--spacing-5)`},children:[(0,B.jsxs)(`div`,{className:`gate__label`,children:[(0,B.jsx)(`span`,{className:`dot dot--waiting`}),` No free session slots`]}),(0,B.jsxs)(`p`,{className:`gate__question`,children:[`All `,S.maxConcurrent,` slots are in use`,E>0?` — ${E===1?`one is`:`${E} are`} held by stages waiting on you`:``]}),S.activeRunIds.length>0?(0,B.jsxs)(`p`,{style:{margin:`var(--spacing-2) 0 0`,color:`var(--color-text-yellow)`,fontSize:`var(--font-size-sm)`},children:[`Blocking runs: `,S.activeRunIds.map((e,t)=>(0,B.jsxs)(v.Fragment,{children:[t>0?`, `:``,(0,B.jsx)(`a`,{href:`#/runs/${e}`,children:e.slice(0,8)})]},e))]}):null]}):null,_?(0,B.jsxs)(`div`,{className:`gate`,style:{padding:`var(--spacing-4)`,marginBottom:`var(--spacing-5)`},children:[(0,B.jsxs)(`div`,{className:`gate__label`,children:[(0,B.jsx)(`span`,{className:`dot dot--waiting`}),` Providers not ready`]}),(0,B.jsx)(`p`,{className:`gate__question`,children:_}),(0,B.jsxs)(`p`,{style:{margin:`var(--spacing-2) 0 0`,fontSize:`var(--font-size-sm)`},children:[(0,B.jsx)(`a`,{href:`#/connect`,children:`Connect providers`}),` · `,(0,B.jsx)(`a`,{href:`#/settings`,children:`Open Settings`})]})]}):null,h?(0,B.jsxs)(`div`,{className:`gate`,style:{padding:`var(--spacing-4)`,marginBottom:`var(--spacing-5)`,borderColor:`var(--color-border-red)`,borderLeftColor:`var(--color-error)`,background:`var(--color-background-red)`,color:`var(--color-text-red)`},children:[(0,B.jsx)(`div`,{className:`gate__label`,style:{color:`var(--color-text-red)`},children:`Could not start run`}),(0,B.jsx)(`p`,{className:`gate__question`,style:{color:`var(--color-text-primary)`},children:h.error})]}):null,D?(0,B.jsxs)(`p`,{style:{color:`var(--color-text-red)`,marginBottom:`var(--spacing-4)`},children:[`Could not start run: `,D]}):null,(0,B.jsxs)(`div`,{className:`grid-2`,children:[(0,B.jsx)(`div`,{children:(0,B.jsxs)(`section`,{className:`card`,children:[(0,B.jsx)(`div`,{className:`card__head`,children:(0,B.jsx)(`h2`,{children:`Task`})}),(0,B.jsx)(`div`,{className:`pick`,children:r.map(e=>(0,B.jsxs)(`label`,{className:`pick__opt`,children:[(0,B.jsx)(`input`,{type:`radio`,name:`task`,checked:s===e.path,onChange:()=>c(e.path)}),(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`strong`,{children:e.id}),(0,B.jsx)(`span`,{children:e.goal}),(0,B.jsx)(`span`,{className:`mono muted`,style:{display:`block`,fontSize:`var(--font-size-xs)`},children:e.path})]})]},e.path))})]})}),(0,B.jsx)(`div`,{children:(0,B.jsxs)(`section`,{className:`card`,children:[(0,B.jsx)(`div`,{className:`card__head`,children:(0,B.jsx)(`h2`,{children:`Pipeline`})}),(0,B.jsx)(`div`,{className:`pick`,children:a.map(e=>(0,B.jsxs)(`label`,{className:`pick__opt`,children:[(0,B.jsx)(`input`,{type:`radio`,name:`pipeline`,checked:l===e.path,onChange:()=>u(e.path)}),(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`strong`,{children:e.id}),(0,B.jsxs)(`span`,{children:[e.stages.length,` stages`]}),(0,B.jsx)(`span`,{className:`mono muted`,style:{display:`block`,fontSize:`var(--font-size-xs)`},children:e.path})]})]},e.path))}),w.length>0?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`div`,{className:`eyebrow`,style:{marginTop:`var(--spacing-4)`,marginBottom:`var(--spacing-3)`},children:`What will run`}),(0,B.jsx)(`div`,{className:`track track--inline`,children:(0,B.jsx)(Rg,{stages:w,mode:`definition`})}),(0,B.jsx)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`,marginTop:`var(--spacing-3)`},children:w.filter(e=>e.status===`waiting`).length===0?`No stage in this pipeline is declared to stop for a human.`:`${w.filter(e=>e.status===`waiting`).length} ${w.filter(e=>e.status===`waiting`).length===1?`stage`:`stages`} will hold and wait for you.`})]}):null]})})]}),(0,B.jsxs)(`div`,{className:`form-actions`,style:{paddingBottom:`var(--spacing-8)`},children:[(0,B.jsx)(`button`,{className:`btn btn--primary`,disabled:!s||!l||T||p,onClick:()=>void O(),children:p?`Starting…`:`Start run`}),(0,B.jsx)(`a`,{className:`btn btn--ghost`,href:`#/today`,children:`Cancel`})]})]})}var Xg={waiting:`dot dot--waiting`,running:`dot dot--running`,failed:`dot dot--failed`,succeeded:`dot dot--succeeded`};function Zg({label:e,count:t,status:n,children:r}){return(0,B.jsxs)(`section`,{className:`zone`,children:[(0,B.jsxs)(`div`,{className:`zone__head`,children:[(0,B.jsx)(`span`,{className:Xg[n]}),(0,B.jsx)(`span`,{className:`eyebrow`,children:e}),(0,B.jsx)(`span`,{className:`zone__rule`}),(0,B.jsx)(`span`,{className:`zone__count`,children:t})]}),r]})}function Qg({waiting:e,inFlight:t,broken:n,finished:r}){return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(Zg,{label:e.label,count:e.count,status:e.status,children:e.children}),(0,B.jsx)(Zg,{label:t.label,count:t.count,status:t.status,children:t.children}),(0,B.jsx)(Zg,{label:n.label,count:n.count,status:n.status,children:n.children}),(0,B.jsx)(Zg,{label:r.label,count:r.count,status:r.status,children:r.children})]})}function $g(e){return e===0?`Nothing needs you`:e===1?`One thing needs you`:`${e} things need you`}function e_(e){let t=e.waiting_stage_id??`this stage`;switch(e.waiting_kind){case`confirm`:return`Stage ${t} paused its session to ask. Rejecting sends your note back to the same session.`;case`artifact_backed`:return`Stage ${t} asked an artifact_backed prompt. Reject revises in the same session.`;case`multi_question`:return`Stage ${t} asked a multi_question prompt. All answers go back in one reply.`;case`free_text`:return`Stage ${t} asked a free_text prompt.`;case`feedback_loop_decision`:return`Feedback loop limit — decide extend, continue, or abandon`;default:return`Stage ${t} is waiting for input.`}}function t_(e){let t=e.waiting_artifacts?.[0];return t?{icon:`◆`,name:t.split(`/`).pop()??t}:{icon:`?`,name:e.waiting_kind??`waiting`}}function n_(e){let t=e.waiting_summary??`Waiting for input`;return t.length<=180?t:`${t.slice(0,180)}…`}var r_=400,i_=12;function a_(e){let t=e.split(`
|
|
117
|
-
`).slice(0,
|
|
118
|
-
`);return t.length>
|
|
119
|
-
`),r,i=[];for(let e of n){let t=e.match(/^#+\s+(.+)/);if(!r&&t?.[1]){r=t[1];continue}e.trim()&&i.push(e.replace(/^#+\s+/,``))}return(0,B.jsxs)(B.Fragment,{children:[r?(0,B.jsx)(`strong`,{children:r}):null,i.length>0?i.map((e,t)=>(0,B.jsx)(`p`,{children:e},t)):r?null:(0,B.jsx)(`p`,{children:t})]})}function s_({run:e}){let t=e.waiting_artifacts?.[0],[n,r]=(0,v.useState)(null);return(0,v.useEffect)(()=>{if(e.waiting_kind!==`artifact_backed`||!t){r(null);return}let n=!1;return ar(e.run_id,t).then(e=>{n||r(o_(e))}).catch(()=>{n||r(null)}),()=>{n=!0}},[e.run_id,e.waiting_kind,t]),e.waiting_kind===`multi_question`&&e.waiting_questions?.length?(0,B.jsx)(`span`,{className:`peek-doc`,children:e.waiting_questions.map((e,t)=>(0,B.jsx)(`p`,{children:e},t))}):(0,B.jsx)(`span`,{className:`peek-doc`,children:n??(0,B.jsx)(`p`,{children:n_(e)})})}function c_(e){let t=Pr(e.updated_at??e.created_at),n=Fr(e.stages,e.waiting_stage_id);return n?`held ${t} at ${n}`:`held ${t}`}function l_(e){let t=e.stages?.find(e=>e.status===`running`);return t?t.id:e.waiting_stage_id?e.waiting_stage_id:``}function u_({run:e,onOpen:t,onOpenArtifact:n}){let r=e.waiting_kind,i=r===`feedback_loop_decision`,a=!i&&e.waiting_prompt_id&&r?{promptId:e.waiting_prompt_id,kind:r}:null,{locked:o,error:s,submitIntent:c}=zc(e.run_id,e.waiting_stage_id,a),l=!i&&Tc({promptId:e.waiting_prompt_id,kind:i?null:r}),u=e.waiting_artifacts?.[0],d=t_(e),f=e.waiting_questions?.length??0;function p(){u?n(e.run_id,u):t(e.run_id)}return(0,B.jsxs)(`article`,{className:`block`,children:[(0,B.jsxs)(`div`,{className:`block__body`,children:[(0,B.jsxs)(`div`,{className:`block__meta`,children:[(0,B.jsx)(`a`,{className:`block__pipeline`,href:`#/pipelines/${e.pipeline_id}`,children:vr(e)}),(0,B.jsx)(`span`,{className:`status status--waiting`,children:c_(e)})]}),(0,B.jsx)(`p`,{className:`block__q`,children:e.waiting_summary??`Waiting for input`}),(0,B.jsx)(`p`,{className:`block__sub`,children:e_(e)}),s?(0,B.jsxs)(`p`,{style:{color:`var(--color-text-red)`,fontSize:`var(--font-size-sm)`},children:[`Could not accept: `,s]}):null,(0,B.jsxs)(`div`,{className:`block__actions`,children:[i?(0,B.jsx)(`button`,{className:`btn btn--primary`,onClick:()=>t(e.run_id),children:`Decide on run`}):null,l?(0,B.jsx)(`button`,{className:`btn btn--accept`,disabled:o,onClick:()=>void c({type:`decision`,decision:`accept`}),children:`Accept`}):null,r===`confirm`||r===`artifact_backed`?(0,B.jsx)(`button`,{className:`btn btn--reject`,onClick:()=>t(e.run_id),children:`Reject with note`}):null,r===`multi_question`?(0,B.jsx)(`button`,{className:`btn btn--primary`,onClick:()=>t(e.run_id),children:f>0?`Answer ${f} questions`:`Answer questions`}):null,r===`free_text`?(0,B.jsx)(`button`,{className:`btn btn--primary`,onClick:()=>t(e.run_id),children:`Answer`}):null,r===`artifact_backed`&&u?(0,B.jsxs)(`button`,{className:`btn`,onClick:()=>n(e.run_id,u),children:[`Read `,d.name]}):null,(0,B.jsx)(`button`,{className:`btn btn--ghost`,onClick:()=>t(e.run_id),children:`Open run`})]})]}),(0,B.jsxs)(`button`,{className:`block__peek`,onClick:p,"aria-label":u?`Open ${d.name}`:`Open run`,children:[(0,B.jsxs)(`span`,{className:`block__peek-name`,children:[(0,B.jsx)(`span`,{"aria-hidden":`true`,children:d.icon}),` `,d.name]}),(0,B.jsx)(s_,{run:e})]})]})}function d_({onOpen:e,onOpenArtifact:t,onNew:n,onSeeRuns:r}){let{snapshot:i,error:a,loading:o}=pr(),[s,c]=(0,v.useState)(null),[l,u]=(0,v.useState)(null),d=br(i),f=Cr(i),p=s??a;async function m(t){u(t);try{e((await Yn(t)).runId)}catch(e){c(e instanceof Error?e.message:String(e))}finally{u(null)}}let h=!o&&d.waiting.length===0&&d.inFlight.length===0&&d.broken.length===0&&d.finished.length===0,g=d.finished.slice(0,3);return(0,B.jsxs)(`div`,{className:`main__inner`,children:[(0,B.jsxs)(`div`,{className:`page-head`,children:[(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`h1`,{children:$g(d.waiting.length)}),(0,B.jsx)(`p`,{children:f.line})]}),(0,B.jsx)(`a`,{className:`btn btn--primary`,href:`#/new`,onClick:e=>{e.preventDefault(),n()},children:`Start a run`})]}),p?(0,B.jsxs)(`p`,{style:{color:`var(--color-text-red)`},children:[`Could not load runs: `,p]}):null,o?(0,B.jsx)(`p`,{className:`muted`,children:`Loading…`}):null,h?(0,B.jsx)(`div`,{className:`empty-hint`,children:`No runs yet. Start a pipeline to see triage zones fill in.`}):null,!o&&!h?(0,B.jsx)(Qg,{waiting:{label:Ur(),count:d.waiting.length,status:`waiting`,children:d.waiting.length===0?(0,B.jsx)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`},children:`Nothing waiting.`}):d.waiting.map(n=>(0,B.jsx)(u_,{run:n,onOpen:e,onOpenArtifact:t},n.run_id))},inFlight:{label:`In flight`,count:d.inFlight.length,status:`running`,children:d.inFlight.length===0?(0,B.jsx)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`},children:`No runs in flight.`}):(0,B.jsx)(`div`,{className:`runs`,children:d.inFlight.map(t=>(0,B.jsxs)(`a`,{className:`run-row`,href:`#/runs/${t.run_id}`,onClick:n=>{n.preventDefault(),e(t.run_id)},children:[(0,B.jsxs)(`span`,{className:`run-row__id`,children:[(0,B.jsx)(`span`,{className:`dot dot--running`}),(0,B.jsxs)(`span`,{className:`run-row__name`,children:[yr(t),` `,(0,B.jsxs)(`span`,{children:[`· `,l_(t)]})]})]}),(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`span`,{className:`track-mini`,"aria-hidden":`true`,children:t.stages.map(e=>{let t=Kr(e.status);return(0,B.jsx)(`i`,{className:`track-mini__seg`,...t?{"data-s":t}:{}},e.id)})}),(0,B.jsx)(`span`,{className:`track-mini__label`,children:Ir(t)})]}),(0,B.jsx)(`span`,{className:`run-row__right`,children:Pr(t.updated_at??t.created_at)})]},t.run_id))})},broken:{label:`Broken`,count:d.broken.length,status:`failed`,children:d.broken.length===0?(0,B.jsx)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`},children:`No failed runs.`}):d.broken.map(t=>(0,B.jsxs)(`div`,{className:`fail-row`,children:[(0,B.jsx)(`span`,{className:`dot dot--failed`}),(0,B.jsxs)(`span`,{className:`fail-row__why`,children:[(0,B.jsx)(`b`,{children:yr(t)}),` · `,vr(t),t.failed_reason?(0,B.jsx)(`span`,{children:t.failed_reason}):null]}),(0,B.jsx)(`button`,{className:`btn btn--sm`,onClick:n=>{n.stopPropagation(),e(t.run_id)},children:`Open stage`}),(0,B.jsx)(`button`,{className:`btn btn--sm`,disabled:l===t.run_id,onClick:e=>{e.stopPropagation(),m(t.run_id)},children:l===t.run_id?`Starting fresh…`:`Start fresh`})]},t.run_id))},finished:{label:`Finished`,count:d.finished.length,status:`succeeded`,children:d.finished.length===0?(0,B.jsx)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`},children:`No finished runs yet.`}):(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`div`,{className:`runs`,children:g.map(t=>(0,B.jsxs)(`a`,{className:`run-row`,href:`#/runs/${t.run_id}`,onClick:n=>{n.preventDefault(),e(t.run_id)},children:[(0,B.jsxs)(`span`,{className:`run-row__id`,children:[(0,B.jsx)(`span`,{className:`dot dot--succeeded`}),(0,B.jsxs)(`span`,{className:`run-row__name`,children:[yr(t),` `,(0,B.jsxs)(`span`,{children:[`· `,vr(t)]})]})]}),(0,B.jsxs)(`span`,{className:`mono muted`,children:[t.stages.length,` stages`]}),(0,B.jsx)(`span`,{className:`run-row__right`,children:Pr(t.updated_at??t.created_at)})]},t.run_id))}),(0,B.jsx)(`p`,{style:{margin:`var(--spacing-3) 0 0`},children:(0,B.jsx)(`button`,{className:`btn btn--sm btn--ghost`,onClick:r,children:`See every run →`})})]})}}):null]})}var f_=/^[a-z][a-z0-9]*(-[a-z0-9]+)*$/,p_=/^[a-z][a-z0-9]*(-[a-z0-9]+)*$/;function m_(e){let t={};e.directory.trim()||(t.directory=`Directory is required.`);let n=e.id.trim();if(n?(n.length>64||!f_.test(n))&&(t.id=`Id must be lowercase kebab-case.`):t.id=`Id is required.`,e.selectedStageIds.length===0)t.stages=`Add at least one stage id.`;else if(new Set(e.selectedStageIds).size!==e.selectedStageIds.length)t.stages=`A pipeline cannot repeat the same stage id.`;else{for(let n of e.selectedStageIds)if(!p_.test(n)){t.stages=`Stage id "${n}" must be lowercase kebab-case.`;break}if(!t.stages&&e.compositionMode===`dependencies`){let n=new Set(e.selectedStageIds);for(let r of e.selectedStageIds){let i=e.stageNeeds[r];if(i&&(!n.has(i)||i===r)){t.stages=`Stage "${r}" needs a stage that is in this pipeline.`;break}}}}return t}function h_(e,t){let n=t?.trim(),r;if(e===409)r=`Could not create pipeline: this id already exists.`;else if(e===422){let e=n?.toLowerCase()??``;r=e.includes(`cycle`)?`Could not create pipeline: dependency cycle detected.`:e.includes(`unknown needs`)?`Could not create pipeline: a stage needs another stage that is not in this pipeline.`:e.includes(`duplicate`)?`Could not create pipeline: the same stage was listed more than once.`:e.includes(`missing stage file`)?`Could not create pipeline: create stage files beside the pipeline directory first.`:`Could not create pipeline. Try again.`}else r=`Could not create pipeline. Try again.`;return n?`${r} ${n}`:r}function g_(e){let t={};for(let n=1;n<e.length;n++)t[e[n]]=e[n-1];return t}function __(e){let t=new Set;for(let n of e){let e=n.path.replace(/\\/g,`/`),r=e.lastIndexOf(`/`);t.add(r>=0?e.slice(0,r):`pipelines`)}return t.size===0&&t.add(`pipelines`),[...t].sort()}function v_({isOpen:e,onClose:t,onCreated:n,pipelines:r}){let i=__(r),[a,o]=(0,v.useState)(i[0]??`pipelines`),[s,c]=(0,v.useState)(``),[l,u]=(0,v.useState)([]),[d,f]=(0,v.useState)(``),[p,m]=(0,v.useState)(`linear`),[h,g]=(0,v.useState)({}),[_,y]=(0,v.useState)({}),[b,x]=(0,v.useState)(null),[S,C]=(0,v.useState)(!1),w=(0,v.useRef)(!1);(0,v.useEffect)(()=>{e&&!w.current&&(o(__(r)[0]??`pipelines`),c(``),u([]),f(``),m(`linear`),g({}),y({}),x(null)),w.current=e},[e,r]),(0,v.useEffect)(()=>{if(!e)return;function t(e){e.key===`Escape`&&j()}return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e]);function T(e){e!==p&&(g(e===`dependencies`?g_(l):{}),m(e))}function E(){let e=d.trim();!e||l.includes(e)||(u(t=>[...t,e]),f(``))}function D(e,t){u(n=>{let r=e+t;if(r<0||r>=n.length)return n;let i=[...n],[a]=i.splice(e,1);return i.splice(r,0,a),p===`dependencies`&&g(g_(i)),i})}function O(e){let t=l[e];u(t=>t.filter((t,n)=>n!==e)),g(e=>{let n={...e};delete n[t];for(let[e,r]of Object.entries(n))r===t&&delete n[e];return n})}function k(e,t){g(n=>{let r={...n};return t?r[e]=t:delete r[e],r})}async function A(){let e=s.trim(),t=a.trim(),r=m_({directory:t,id:e,selectedStageIds:l,compositionMode:p,stageNeeds:h});if(y(r),x(null),Object.keys(r).length>0)return;C(!0);let i=await Mn({directory:t,id:e,stages:l.map(e=>{if(p===`dependencies`){let t=h[e];return t?{id:e,uses:`./${e}.yaml`,needs:t}:{id:e,uses:`./${e}.yaml`}}return{id:e,uses:`./${e}.yaml`}})});if(C(!1),i.ok){n(i.pipeline);return}x(h_(i.status,i.error))}function j(){c(``),u([]),f(``),m(`linear`),g({}),y({}),x(null),t()}return e?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`button`,{type:`button`,className:`drawer-scrim`,"aria-label":`Close panel`,onClick:j}),(0,B.jsxs)(`aside`,{className:`drawer drawer--right`,"aria-labelledby":`new-pipeline-title`,children:[(0,B.jsxs)(`div`,{className:`drawer__head`,children:[(0,B.jsx)(`h2`,{id:`new-pipeline-title`,style:{margin:0,fontSize:`var(--font-size-lg)`},children:`New pipeline`}),(0,B.jsx)(`span`,{style:{marginLeft:`auto`}}),(0,B.jsx)(`button`,{type:`button`,className:`btn btn--sm`,onClick:j,children:`Close`})]}),(0,B.jsxs)(`div`,{className:`drawer__body`,children:[b?(0,B.jsx)(`div`,{className:`gate`,style:{padding:`var(--spacing-4)`,marginBottom:`var(--spacing-5)`,borderColor:`var(--color-border-red)`,borderLeftColor:`var(--color-error)`,background:`var(--color-background-red)`,color:`var(--color-text-red)`},children:(0,B.jsx)(`p`,{className:`gate__question`,style:{color:`var(--color-text-primary)`,margin:0},children:b})}):null,(0,B.jsxs)(`div`,{className:`form-field`,children:[(0,B.jsx)(`label`,{htmlFor:`new-pipeline-directory`,children:`Directory`}),(0,B.jsx)(`input`,{id:`new-pipeline-directory`,className:`input`,list:`pipeline-directory-options`,value:a,onChange:e=>o(e.target.value),autoComplete:`off`,spellCheck:!1}),(0,B.jsx)(`datalist`,{id:`pipeline-directory-options`,children:i.map(e=>(0,B.jsx)(`option`,{value:e},e))}),_.directory?(0,B.jsx)(`p`,{className:`field-error`,children:_.directory}):(0,B.jsxs)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`,marginTop:`var(--spacing-1)`},children:[`Repo-relative folder for `,(0,B.jsxs)(`span`,{className:`mono`,children:[s.trim()||`id`,`.pipeline.yaml`]}),` and stage files.`]})]}),(0,B.jsxs)(`div`,{className:`form-field`,children:[(0,B.jsx)(`label`,{htmlFor:`new-pipeline-id`,children:`Id`}),(0,B.jsx)(`input`,{id:`new-pipeline-id`,className:`input`,value:s,onChange:e=>c(e.target.value),autoComplete:`off`,spellCheck:!1}),_.id?(0,B.jsx)(`p`,{className:`field-error`,children:_.id}):null]}),(0,B.jsxs)(`div`,{className:`filters`,style:{marginTop:`var(--spacing-2)`},children:[(0,B.jsx)(`button`,{type:`button`,className:`tab`,"data-active":p===`linear`?`true`:void 0,onClick:()=>T(`linear`),children:`Linear`}),(0,B.jsx)(`button`,{type:`button`,className:`tab`,"data-active":p===`dependencies`?`true`:void 0,onClick:()=>T(`dependencies`),children:`Dependencies`})]}),(0,B.jsxs)(`div`,{className:`form-field`,children:[(0,B.jsx)(`span`,{className:`eyebrow`,children:`Stage ids`}),(0,B.jsxs)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`,margin:`var(--spacing-1) 0 var(--spacing-3)`},children:[`Each id maps to `,(0,B.jsx)(`span`,{className:`mono`,children:`./<id>.yaml`}),` beside the pipeline file. Create stage files first.`]}),(0,B.jsxs)(`div`,{style:{display:`flex`,gap:`var(--spacing-2)`,marginBottom:`var(--spacing-3)`},children:[(0,B.jsx)(`input`,{className:`input`,value:d,onChange:e=>f(e.target.value),placeholder:`stage-id`,autoComplete:`off`,spellCheck:!1,onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),E())}}),(0,B.jsx)(`button`,{type:`button`,className:`btn btn--sm`,onClick:E,children:`Add`})]}),l.length===0?(0,B.jsx)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`},children:`No stages added yet.`}):(0,B.jsx)(`ul`,{style:{listStyle:`none`,margin:0,padding:0},children:l.map((e,t)=>(0,B.jsxs)(`li`,{style:{display:`flex`,alignItems:`center`,gap:`var(--spacing-2)`,padding:`var(--spacing-2) 0`,borderBottom:`1px solid var(--color-border)`},children:[(0,B.jsxs)(`span`,{className:`mono`,style:{flex:p===`dependencies`?void 0:1},children:[t+1,`. `,e]}),p===`dependencies`?(0,B.jsxs)(`label`,{style:{display:`flex`,alignItems:`center`,gap:`var(--spacing-2)`,flex:1,fontSize:`var(--font-size-sm)`},children:[(0,B.jsx)(`span`,{className:`muted`,children:`Needs`}),(0,B.jsxs)(`select`,{className:`input`,value:h[e]??``,onChange:t=>k(e,t.target.value),style:{flex:1,minWidth:0},children:[(0,B.jsx)(`option`,{value:``,children:`(none — root)`}),l.filter(t=>t!==e).map(e=>(0,B.jsx)(`option`,{value:e,children:e},e))]})]}):null,(0,B.jsx)(`button`,{type:`button`,className:`btn btn--sm btn--ghost`,disabled:t===0,onClick:()=>D(t,-1),children:`Up`}),(0,B.jsx)(`button`,{type:`button`,className:`btn btn--sm btn--ghost`,disabled:t===l.length-1,onClick:()=>D(t,1),children:`Down`}),(0,B.jsx)(`button`,{type:`button`,className:`btn btn--sm btn--ghost`,onClick:()=>O(t),children:`Remove`})]},`${e}-${t}`))}),_.stages?(0,B.jsx)(`p`,{className:`field-error`,children:_.stages}):null]}),(0,B.jsxs)(`div`,{className:`form-actions`,children:[(0,B.jsx)(`button`,{type:`button`,className:`btn btn--primary`,disabled:S,onClick:()=>void A(),children:S?`Creating…`:`Create pipeline`}),(0,B.jsx)(`button`,{type:`button`,className:`btn btn--ghost`,onClick:j,children:`Cancel`})]})]})]})]}):null}function y_(e,t){return e===`all`?{}:e===`none`?{gate_kinds:[]}:{gate_kinds:t}}var b_=/^[a-z][a-z0-9]*(-[a-z0-9]+)*$/,x_=`__inherit__`,S_=`__other__`,C_=[`free_text`,`confirm`,`multi_question`,`artifact_backed`];function w_(e){let t={},n=e.id.trim();return n?(n.length>64||!b_.test(n))&&(t.id=`Id must be lowercase kebab-case.`):t.id=`Id is required.`,e.useDropdown&&e.modelSelect===`__other__`&&!e.model.trim()&&(t.model=`Model is required when Other is selected.`),e.system_prompt.trim()||(t.system_prompt=`System prompt is required.`),t}function T_(e){return e.useDropdown?e.modelSelect===`__inherit__`?``:e.modelSelect===`__other__`?e.customModel.trim():e.modelSelect.trim():e.plainModel.trim()}function E_(e,t){let n=e===409?`Could not create Stage: this id already exists.`:`Could not create Stage. Try again.`,r=t?.trim();return r?`${n} ${r}`:n}var D_=()=>({id:``,system_prompt:``,gateMode:`all`,gateKinds:[],modelSelect:x_,customModel:``,plainModel:``});function O_({isOpen:e,onClose:t,onCreated:n,pipelineDirectory:r}){let[i,a]=(0,v.useState)(D_),[o,s]=(0,v.useState)(null),[c,l]=(0,v.useState)(!1),[u,d]=(0,v.useState)({}),[f,p]=(0,v.useState)(null),[m,h]=(0,v.useState)(!1);(0,v.useEffect)(()=>{if(!e)return;let t=!1;return(async()=>{try{let{models:e}=await jn();if(t)return;e.length>0?(s(e),l(!0)):(s([]),l(!1))}catch{if(t)return;s(null),l(!1)}})(),()=>{t=!0}},[e]),(0,v.useEffect)(()=>{if(!e)return;function n(e){e.key===`Escape`&&t()}return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,t]);function g(){return T_({useDropdown:c,modelSelect:i.modelSelect,customModel:i.customModel,plainModel:i.plainModel})}function _(e){a(t=>({...t,gateKinds:t.gateKinds.includes(e)?t.gateKinds.filter(t=>t!==e):[...t.gateKinds,e]}))}async function y(){let e=g(),t={id:i.id.trim(),system_prompt:i.system_prompt,model:e},o=w_({...t,useDropdown:c,modelSelect:i.modelSelect});if(d(o),p(null),Object.keys(o).length>0)return;h(!0);let s=await Nn({pipeline_directory:r,filename:`${i.id.trim()}.yaml`,id:t.id,system_prompt:t.system_prompt,...e.length>0?{model:e}:{},...y_(i.gateMode,i.gateKinds)});if(h(!1),s.ok){a(D_()),d({}),p(null),n(s.stage);return}p(E_(s.status,s.error))}function b(){a(D_()),d({}),p(null),t()}return e?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`button`,{type:`button`,className:`drawer-scrim`,"aria-label":`Close panel`,onClick:b}),(0,B.jsxs)(`aside`,{className:`drawer drawer--right`,"aria-labelledby":`new-stage-title`,children:[(0,B.jsxs)(`div`,{className:`drawer__head`,children:[(0,B.jsx)(`h2`,{id:`new-stage-title`,style:{margin:0,fontSize:`var(--font-size-lg)`},children:`New stage`}),(0,B.jsx)(`span`,{style:{marginLeft:`auto`}}),(0,B.jsx)(`button`,{type:`button`,className:`btn btn--sm`,onClick:b,children:`Close`})]}),(0,B.jsxs)(`div`,{className:`drawer__body`,children:[f?(0,B.jsx)(`div`,{className:`gate`,style:{padding:`var(--spacing-4)`,marginBottom:`var(--spacing-5)`,borderColor:`var(--color-border-red)`,borderLeftColor:`var(--color-error)`,background:`var(--color-background-red)`,color:`var(--color-text-red)`},children:(0,B.jsx)(`p`,{className:`gate__question`,style:{color:`var(--color-text-primary)`,margin:0},children:f})}):null,(0,B.jsxs)(`div`,{className:`form-field`,children:[(0,B.jsx)(`label`,{htmlFor:`new-stage-id`,children:`Id`}),(0,B.jsx)(`input`,{id:`new-stage-id`,className:`input`,value:i.id,onChange:e=>a(t=>({...t,id:e.target.value})),autoComplete:`off`,spellCheck:!1}),u.id?(0,B.jsx)(`p`,{className:`field-error`,children:u.id}):(0,B.jsxs)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`,marginTop:`var(--spacing-1)`},children:[`Writes `,(0,B.jsxs)(`span`,{className:`mono`,children:[r,`/<id>.yaml`]}),`.`]})]}),(0,B.jsxs)(`div`,{className:`form-field`,children:[(0,B.jsx)(`label`,{htmlFor:`new-stage-model`,children:`Model`}),c&&o?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(`select`,{id:`new-stage-model`,className:`select`,value:i.modelSelect,onChange:e=>a(t=>({...t,modelSelect:e.target.value})),children:[(0,B.jsx)(`option`,{value:x_,children:`Inherit default`}),o.map(e=>(0,B.jsx)(`option`,{value:e,children:e},e)),(0,B.jsx)(`option`,{value:S_,children:`Other...`})]}),i.modelSelect===`__other__`?(0,B.jsx)(`input`,{className:`input`,style:{marginTop:`var(--spacing-2)`},value:i.customModel,onChange:e=>a(t=>({...t,customModel:e.target.value})),placeholder:`Model id`,autoComplete:`off`,spellCheck:!1}):null]}):(0,B.jsx)(`input`,{id:`new-stage-model`,className:`input`,value:i.plainModel,onChange:e=>a(t=>({...t,plainModel:e.target.value})),autoComplete:`off`,spellCheck:!1}),u.model?(0,B.jsx)(`p`,{className:`field-error`,children:u.model}):(0,B.jsx)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`,marginTop:`var(--spacing-1)`},children:`Optional. Inherits pipeline then global default when omitted.`})]}),(0,B.jsxs)(`div`,{className:`form-field`,children:[(0,B.jsx)(`label`,{htmlFor:`new-stage-prompt`,children:`System prompt`}),(0,B.jsx)(`textarea`,{id:`new-stage-prompt`,className:`textarea`,rows:6,value:i.system_prompt,onChange:e=>a(t=>({...t,system_prompt:e.target.value}))}),u.system_prompt?(0,B.jsx)(`p`,{className:`field-error`,children:u.system_prompt}):null]}),(0,B.jsxs)(`div`,{className:`form-field`,children:[(0,B.jsx)(`span`,{className:`eyebrow`,children:`HITL`}),(0,B.jsx)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`,margin:`var(--spacing-1) 0 var(--spacing-3)`},children:`All kinds keeps every ask kind available. No HITL unregisters ask_operator. Allowlist restricts kinds.`}),(0,B.jsxs)(`div`,{className:`pick`,children:[(0,B.jsxs)(`label`,{className:`pick__opt`,children:[(0,B.jsx)(`input`,{type:`radio`,name:`new-stage-hitl`,checked:i.gateMode===`all`,onChange:()=>a(e=>({...e,gateMode:`all`}))}),(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`strong`,{children:`All kinds`}),(0,B.jsx)(`span`,{className:`muted`,children:` Compatible default. Every ask kind is available.`})]})]}),(0,B.jsxs)(`label`,{className:`pick__opt`,children:[(0,B.jsx)(`input`,{type:`radio`,name:`new-stage-hitl`,checked:i.gateMode===`none`,onChange:()=>a(e=>({...e,gateMode:`none`}))}),(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`strong`,{children:`No HITL`}),(0,B.jsx)(`span`,{className:`muted`,children:` Writes gate_kinds: []. The stage cannot ask the operator.`})]})]}),(0,B.jsxs)(`label`,{className:`pick__opt`,children:[(0,B.jsx)(`input`,{type:`radio`,name:`new-stage-hitl`,checked:i.gateMode===`allowlist`,onChange:()=>a(e=>({...e,gateMode:`allowlist`}))}),(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`strong`,{children:`Allowlist`}),(0,B.jsx)(`span`,{className:`muted`,children:` Only the kinds you select.`})]})]})]}),i.gateMode===`allowlist`?(0,B.jsx)(`div`,{className:`pick`,style:{marginTop:`var(--spacing-3)`},children:C_.map(e=>(0,B.jsxs)(`label`,{className:`pick__opt`,children:[(0,B.jsx)(`input`,{type:`checkbox`,checked:i.gateKinds.includes(e),onChange:()=>_(e)}),(0,B.jsx)(`span`,{children:(0,B.jsx)(`strong`,{className:`mono`,children:e})})]},e))}):null]}),(0,B.jsxs)(`div`,{className:`form-actions`,children:[(0,B.jsx)(`button`,{type:`button`,className:`btn btn--primary`,disabled:m,onClick:()=>void y(),children:m?`Creating…`:`Create stage`}),(0,B.jsx)(`button`,{type:`button`,className:`btn btn--ghost`,onClick:b,children:`Cancel`})]})]})]})]}):null}function k_(e){window.location.hash=e.startsWith(`#`)?e:`#${e}`}function A_(e){return`/runs/${encodeURIComponent(e)}`}function j_(e,t){return`/runs/${encodeURIComponent(e)}/stages/${encodeURIComponent(t)}`}function M_(e,t){return`/runs/${encodeURIComponent(e)}/artifacts?path=${encodeURIComponent(t)}`}function N_(e,t){return`/runs/${encodeURIComponent(e)}/stages/${encodeURIComponent(t)}/envelope`}function P_(e){return`/pipelines/${encodeURIComponent(e)}`}function F_(e){return`/tasks/${encodeURIComponent(e)}`}function I_(e){return`/skills/${encodeURIComponent(e)}`}function L_(e,t){return`/extensions/packages/${encodeURIComponent(e)}/${encodeURIComponent(t)}`}function R_(e){return`/extensions/files/${encodeURIComponent(e)}`}function z_(e){let t=new URLSearchParams;e?.pipeline&&t.set(`pipeline`,e.pipeline),e?.task&&t.set(`task`,e.task);let n=t.toString();return n?`/new?${n}`:`/new`}function B_(e){let t=e.replace(/^#\/?/,``),n=t.indexOf(`?`);return n<0?{path:t,params:new URLSearchParams}:{path:t.slice(0,n),params:new URLSearchParams(t.slice(n+1))}}function V_(e){let t=e.indexOf(`/`),n=t<0?e:e.slice(0,t);return n?decodeURIComponent(n):``}function H_(e=window.location.hash){let{path:t,params:n}=B_(e);if(!t||t===`today`)return{name:`today`};if(t===`runs`)return{name:`runs`};if(t===`new`){let e=n.get(`pipeline`)??void 0,t=n.get(`task`)??void 0;return{name:`new`,...e?{pipelineId:e}:{},...t?{taskPath:t}:{}}}if(t===`pipelines`)return{name:`pipelines`};if(t.startsWith(`pipelines/`)){let e=V_(t.slice(10));if(e)return{name:`pipeline`,pipelineId:e}}if(t===`tasks`)return{name:`tasks`};if(t.startsWith(`tasks/`)){let e=V_(t.slice(6));if(e)return{name:`task`,taskId:e}}if(t===`skills`)return{name:`skills`};if(t.startsWith(`skills/`)){let e=V_(t.slice(7));if(e)return{name:`skill`,skillName:e}}if(t===`extensions`)return{name:`extensions`};if(t.startsWith(`extensions/packages/`)){let e=t.slice(20),n=e.indexOf(`/`);if(n>0){let t=decodeURIComponent(e.slice(0,n)),r=decodeURIComponent(e.slice(n+1));if((t===`user`||t===`project`)&&r)return{name:`extensionPackage`,scope:t,source:r}}}if(t.startsWith(`extensions/files/`)){let e=decodeURIComponent(t.slice(17));if(e)return{name:`extensionFile`,path:e}}if(t===`settings`)return{name:`settings`};if(t===`connect`)return{name:`connect`};if(t.startsWith(`runs/`)){let e=t.slice(5).split(`/`),r=decodeURIComponent(e[0]??``);if(!r)return{name:`today`};if(e[1]===`stages`&&e[3]===`envelope`&&e[2]&&e.length===4)return{name:`detail`,runId:r,view:{kind:`envelope`,stageId:decodeURIComponent(e[2])}};if(e[1]===`stages`&&e[2]&&e.length===3)return{name:`detail`,runId:r,view:{kind:`stream`,stageId:decodeURIComponent(e[2])}};if(e[1]===`artifacts`&&e.length===2){let e=n.get(`path`);if(e)return{name:`detail`,runId:r,view:{kind:`artifact`,path:e}}}return e.length,{name:`detail`,runId:r,view:{kind:`stream`}}}return{name:`today`}}function U_({status:e}){let t=Vr(e),n=t&&t!==`running`?`status status--${t}`:`status`,r=t?`dot dot--${t}`:`dot`;return(0,B.jsxs)(`span`,{className:n,children:[(0,B.jsx)(`span`,{className:r}),` `,Hr(e)]})}var W_=null,G_=null;function K_(e,t=4e3){W_||(W_=document.createElement(`div`),W_.className=`toast`,W_.setAttribute(`role`,`status`),document.body.appendChild(W_)),W_.textContent=e,W_.setAttribute(`data-show`,`true`),G_&&clearTimeout(G_),G_=setTimeout(()=>{W_?.setAttribute(`data-show`,`false`)},t)}function q_(e){return e.map(e=>{let t=e.gate_kinds;return{id:e.id,label:e.id,status:Mr(t)?`waiting`:`pending`,meta:J_(t)}})}function J_(e){return e===void 0?`all kinds`:e.length===0?`none`:e.join(` · `)}function Y_(e){return e.inline?`inline`:e.uses_path?e.uses_path:`—`}function X_(e){let t=e.replace(/\\/g,`/`),n=t.lastIndexOf(`/`);return n>=0?t.slice(0,n):`.`}function Z_(e,t){let n=X_(e.path);return t.filter(e=>n===`.`?!e.path.includes(`/`):e.path.startsWith(`${n}/`))[0]?.path??t[0]?.path}function Q_({stages:e}){return(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`span`,{className:`mini`,"aria-hidden":`true`,children:e.map((e,t)=>(0,B.jsxs)(v.Fragment,{children:[t>0?(0,B.jsx)(`i`,{className:`mini__w`}):null,(0,B.jsx)(`i`,{className:`mini__n`,"data-s":Mr(e.gate_kinds)?`waiting`:void 0,children:Mr(e.gate_kinds)?`?`:String(t+1)})]},e.id))}),(0,B.jsx)(`span`,{className:`mini__label`,style:{display:`block`},children:e.map(e=>e.id).join(` · `)})]})}function $_({pipelineId:e,onNew:t}){let{snapshot:n,error:r,loading:i}=pr(),[a,o]=(0,v.useState)([]),[s,c]=(0,v.useState)([]),[l,u]=(0,v.useState)(null),[d,f]=(0,v.useState)(!0),[p,m]=(0,v.useState)(!1),[h,g]=(0,v.useState)(!1),_=(0,v.useCallback)(async()=>{try{let[e,t]=await Promise.all([An(),kn()]);o(e.pipelines),c(t.tasks),u(null)}catch(e){u(e instanceof Error?e.message:String(e))}finally{f(!1)}},[]);(0,v.useEffect)(()=>{_()},[_]);let y=d||i,b=l??r,x=e?a.find(t=>t.id===e)??null:null,S=x?Er(n,x):[];async function C(e){g(!1);try{let e=await An();o(e.pipelines),u(null)}catch(e){u(e instanceof Error?e.message:String(e))}K_(`Pipeline created · ${e.id}`),t(P_(e.id))}return e?(0,B.jsx)(ev,{pipelineId:e,pipeline:x,tasks:s,runs:S,loading:y,error:b,onNew:t,onStageCreated:()=>void _(),stagePanelOpen:p,onOpenStagePanel:()=>m(!0),onCloseStagePanel:()=>m(!1)}):(0,B.jsxs)(`div`,{className:`main__inner main__inner--wide`,children:[(0,B.jsxs)(`div`,{className:`page-head`,children:[(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`h1`,{children:`Pipelines`}),(0,B.jsx)(`p`,{children:`Manifest-declared pipeline files and their embedded stages. Each row shows its chain and which stages will stop for a human.`})]}),(0,B.jsx)(`button`,{type:`button`,className:`btn btn--primary`,onClick:()=>g(!0),children:`New pipeline`})]}),b?(0,B.jsx)(`p`,{style:{color:`var(--color-text-red)`},children:b}):null,y?(0,B.jsx)(`p`,{className:`muted`,children:`Loading pipelines…`}):null,!y&&a.length===0?(0,B.jsxs)(`div`,{className:`empty-hint`,children:[(0,B.jsxs)(`p`,{style:{margin:`0 0 var(--spacing-3)`},children:[`No pipelines in the manifest yet. Add a `,(0,B.jsx)(`span`,{className:`mono`,children:`stageflow.yaml`}),` catalog entry or run`,` `,(0,B.jsx)(`span`,{className:`mono`,children:`sf init`}),`.`]}),(0,B.jsx)(`button`,{type:`button`,className:`btn btn--primary`,onClick:()=>g(!0),children:`New pipeline`})]}):null,!y&&a.length>0?(0,B.jsx)(B.Fragment,{children:a.map(e=>{let t=Er(n,e),r=Nr(e.stages);return(0,B.jsxs)(`a`,{className:`rrow`,href:`#${P_(e.id)}`,children:[(0,B.jsxs)(`span`,{className:`rrow__id`,children:[(0,B.jsx)(`span`,{className:`rrow__task`,children:e.id}),(0,B.jsx)(`span`,{className:`rrow__pipe`,children:e.path})]}),(0,B.jsxs)(`span`,{className:`rrow__right`,children:[r===1?`1 gate`:`${r} gates`,(0,B.jsx)(`br`,{}),(0,B.jsxs)(`span`,{className:`mono`,style:{fontSize:`var(--font-size-xs)`},children:[t.length,` `,t.length===1?`run`:`runs`]})]}),(0,B.jsx)(`span`,{className:`rrow__track`,children:(0,B.jsx)(Q_,{stages:e.stages})})]},`${e.path}:${e.id}`)})}):null,(0,B.jsx)(v_,{isOpen:h,onClose:()=>g(!1),onCreated:e=>void C(e),pipelines:a})]})}function ev({pipelineId:e,pipeline:t,tasks:n,runs:r,loading:i,error:a,onNew:o,onStageCreated:s,stagePanelOpen:c,onOpenStagePanel:l,onCloseStagePanel:u}){let d=(0,v.useMemo)(()=>t?q_(t.stages):[],[t]),f=t?Nr(t.stages):0,p=t?`${t.path} · ${t.stages.length} stages · ${f===1?`1 gate`:`${f} gates`} · ${r.length} ${r.length===1?`run`:`runs`}`:e,m=t?Z_(t,n):void 0;return(0,B.jsxs)(`div`,{className:`main__inner`,children:[(0,B.jsxs)(`p`,{className:`crumbs`,children:[(0,B.jsx)(`a`,{href:`#/pipelines`,children:`Pipelines`}),` / `,e]}),(0,B.jsxs)(`div`,{className:`page-head`,children:[(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`h1`,{children:e}),(0,B.jsx)(`p`,{className:`mono`,children:p})]}),t?(0,B.jsx)(`button`,{className:`btn btn--primary`,onClick:()=>o(z_({pipeline:t.path,...m?{task:m}:{}})),children:`Start a run with this`}):null]}),a?(0,B.jsx)(`p`,{style:{color:`var(--color-text-red)`},children:a}):null,i?(0,B.jsx)(`p`,{className:`muted`,children:`Loading…`}):null,!i&&!t?(0,B.jsxs)(`p`,{className:`muted`,children:[e,` is not in the current manifest catalog.`]}):null,t?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(Rg,{stages:d,mode:`definition`}),(0,B.jsxs)(`div`,{className:`page-head`,style:{marginTop:`var(--spacing-6)`},children:[(0,B.jsx)(`h3`,{style:{margin:0},children:`Stages`}),(0,B.jsx)(`button`,{type:`button`,className:`btn btn--sm`,onClick:l,children:`Add stage file`})]}),(0,B.jsxs)(`table`,{className:`table`,children:[(0,B.jsx)(`thead`,{children:(0,B.jsxs)(`tr`,{children:[(0,B.jsx)(`th`,{children:`Stage`}),(0,B.jsx)(`th`,{children:`Gate`}),(0,B.jsx)(`th`,{children:`Source`})]})}),(0,B.jsx)(`tbody`,{children:t.stages.map(e=>(0,B.jsxs)(`tr`,{children:[(0,B.jsx)(`td`,{className:`mono`,children:e.id}),(0,B.jsx)(`td`,{className:`muted`,children:J_(e.gate_kinds)}),(0,B.jsx)(`td`,{className:`mono muted`,children:Y_(e)})]},e.id))})]}),(0,B.jsx)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`,marginTop:`var(--spacing-3)`},children:f===1?`Only one stage stops for a human. That is worth knowing before you start a run, not after.`:f===0?`No stage in this pipeline is declared to stop for a human.`:`${f} stages stop for a human.`}),(0,B.jsx)(`h3`,{style:{marginTop:`var(--spacing-6)`},children:`Recent runs`}),r.length===0?(0,B.jsx)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`},children:`No runs of this pipeline yet.`}):(0,B.jsxs)(`table`,{className:`table`,children:[(0,B.jsx)(`thead`,{children:(0,B.jsxs)(`tr`,{children:[(0,B.jsx)(`th`,{children:`Task`}),(0,B.jsx)(`th`,{children:`Status`}),(0,B.jsx)(`th`,{children:`When`})]})}),(0,B.jsx)(`tbody`,{children:r.map(e=>(0,B.jsxs)(`tr`,{children:[(0,B.jsxs)(`td`,{children:[(0,B.jsx)(`a`,{href:`#${A_(e.run_id)}`,children:yr(e)}),e.task_path?(0,B.jsx)(`span`,{className:`muted mono`,style:{display:`block`,fontSize:`var(--font-size-xs)`},children:hr(e.task_path,e.project_root)}):null]}),(0,B.jsx)(`td`,{children:(0,B.jsx)(U_,{status:Br(e)})}),(0,B.jsx)(`td`,{className:`muted`,children:Pr(e.created_at)})]},e.run_id))})]})]}):null,(0,B.jsx)(O_,{isOpen:c,onClose:u,pipelineDirectory:t?X_(t.path):`pipelines`,onCreated:e=>{u(),s()}})]})}function tv({taskId:e,onNew:t}){let{snapshot:n,error:r,loading:i}=pr(),[a,o]=(0,v.useState)([]),[s,c]=(0,v.useState)(null),[l,u]=(0,v.useState)(!0),d=(0,v.useCallback)(async()=>{try{let e=await kn();o(e.tasks),c(null)}catch(e){c(e instanceof Error?e.message:String(e))}finally{u(!1)}},[]);(0,v.useEffect)(()=>{d()},[d]);let f=l||i,p=s??r,m=e?a.find(t=>t.id===e)??null:null,h=m?Tr(n,m.id):[];return e?(0,B.jsx)(nv,{taskId:e,task:m,runs:h,loading:f,error:p,onNew:t}):(0,B.jsxs)(`div`,{className:`main__inner main__inner--wide`,children:[(0,B.jsx)(`div`,{className:`page-head`,children:(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`h1`,{children:`Tasks`}),(0,B.jsx)(`p`,{children:`A task is a brief plus the pipeline it should run through. Tasks are reusable; runs are not.`})]})}),p?(0,B.jsx)(`p`,{style:{color:`var(--color-text-red)`},children:p}):null,f?(0,B.jsx)(`p`,{className:`muted`,children:`Loading tasks…`}):null,!f&&a.length===0?(0,B.jsx)(`p`,{className:`muted`,children:`No tasks yet. Add a YAML file under tasks/ in this project.`}):null,!f&&a.length>0?(0,B.jsxs)(`table`,{className:`table`,children:[(0,B.jsx)(`thead`,{children:(0,B.jsxs)(`tr`,{children:[(0,B.jsx)(`th`,{children:`Task`}),(0,B.jsx)(`th`,{children:`Pipeline`}),(0,B.jsx)(`th`,{children:`Runs`}),(0,B.jsx)(`th`,{children:`Last result`}),(0,B.jsx)(`th`,{})]})}),(0,B.jsx)(`tbody`,{children:a.map(e=>{let r=Tr(n,e.id),i=r[0],a=i?Br(i):void 0,o=i?.pipeline_id;return(0,B.jsxs)(`tr`,{children:[(0,B.jsxs)(`td`,{children:[(0,B.jsx)(`a`,{href:`#${F_(e.id)}`,children:e.id}),(0,B.jsx)(`div`,{className:`muted`,style:{fontSize:`var(--font-size-xs)`},children:e.goal})]}),(0,B.jsx)(`td`,{className:`mono`,children:o??`—`}),(0,B.jsx)(`td`,{className:`mono`,children:r.length}),(0,B.jsx)(`td`,{children:a?(0,B.jsx)(U_,{status:a}):(0,B.jsx)(`span`,{className:`muted`,children:`no runs`})}),(0,B.jsx)(`td`,{style:{textAlign:`right`},children:i?(0,B.jsx)(`a`,{className:`btn btn--sm`,href:`#${A_(i.run_id)}`,children:`Open run`}):(0,B.jsx)(`button`,{className:`btn btn--sm`,onClick:()=>t(z_({task:e.path})),children:`Run it`})})]},e.id)})})]}):null]})}function nv({taskId:e,task:t,runs:n,loading:r,error:i,onNew:a}){let o=n[0],s=br({runs:n,health:null}),c=s.waiting.length+s.inFlight.length,l=t?`${t.path} · ${n.length} ${n.length===1?`run`:`runs`}${c>0?` · ${c} in flight`:``}`:e;return(0,B.jsxs)(`div`,{className:`main__inner`,children:[(0,B.jsxs)(`p`,{className:`crumbs`,children:[(0,B.jsx)(`a`,{href:`#/tasks`,children:`Tasks`}),` / `,e]}),(0,B.jsxs)(`div`,{className:`page-head`,children:[(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`h1`,{children:e}),(0,B.jsx)(`p`,{className:`mono`,children:l})]}),t?(0,B.jsx)(`button`,{className:`btn btn--primary`,onClick:()=>a(z_({task:t.path,pipeline:o?.pipeline_id})),children:`Run it again`}):null]}),i?(0,B.jsx)(`p`,{style:{color:`var(--color-text-red)`},children:i}):null,r?(0,B.jsx)(`p`,{className:`muted`,children:`Loading…`}):null,!r&&!t?(0,B.jsxs)(`p`,{className:`muted`,children:[e,` is not in this project's tasks/ catalog.`]}):null,t?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`h3`,{children:`Brief`}),(0,B.jsx)(`p`,{children:t.goal}),(0,B.jsx)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`},children:`Pipeline`}),o?(0,B.jsx)(`a`,{href:`#${P_(o.pipeline_id)}`,style:{fontWeight:500},children:o.pipeline_id}):(0,B.jsx)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`},children:`No runs yet — pick a pipeline when you start one.`}),(0,B.jsx)(`h3`,{style:{marginTop:`var(--spacing-6)`},children:`Run history`}),n.length===0?(0,B.jsx)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`},children:`No runs of this task yet.`}):(0,B.jsxs)(`table`,{className:`table`,children:[(0,B.jsx)(`thead`,{children:(0,B.jsxs)(`tr`,{children:[(0,B.jsx)(`th`,{children:`Run`}),(0,B.jsx)(`th`,{children:`Status`}),(0,B.jsx)(`th`,{children:`Pipeline`}),(0,B.jsx)(`th`,{children:`When`})]})}),(0,B.jsx)(`tbody`,{children:n.map(e=>(0,B.jsxs)(`tr`,{children:[(0,B.jsx)(`td`,{children:(0,B.jsx)(`a`,{href:`#${A_(e.run_id)}`,children:e.run_id})}),(0,B.jsx)(`td`,{children:(0,B.jsx)(U_,{status:Br(e)})}),(0,B.jsx)(`td`,{children:(0,B.jsx)(`a`,{href:`#${P_(e.pipeline_id)}`,children:e.pipeline_id})}),(0,B.jsx)(`td`,{className:`muted`,children:Pr(e.created_at)})]},e.run_id))})]})]}):null]})}function rv({skillName:e}){let[t,n]=(0,v.useState)([]),[r,i]=(0,v.useState)(null),[a,o]=(0,v.useState)(!0),s=(0,v.useCallback)(async()=>{try{let e=await Pn();n(e.skills),i(null)}catch(e){i(e instanceof Error?e.message:String(e))}finally{o(!1)}},[]);(0,v.useEffect)(()=>{s()},[s]);let c=e?t.find(t=>t.name===e)??null:null;return e?(0,B.jsx)(iv,{skillName:e,skill:c,loading:a,error:r}):(0,B.jsxs)(`div`,{className:`main__inner main__inner--wide`,children:[(0,B.jsx)(`div`,{className:`page-head`,children:(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`h1`,{children:`Skills`}),(0,B.jsx)(`p`,{children:`Skills the Pi SDK can discover on this machine. Factory stages do not load them.`})]})}),r?(0,B.jsx)(`p`,{style:{color:`var(--color-text-red)`},children:r}):null,a?(0,B.jsx)(`p`,{className:`muted`,children:`Loading skills…`}):null,!a&&t.length===0?(0,B.jsx)(`p`,{className:`muted`,children:`No skills found under ~/.pi/agent/skills, ~/.agents/skills, or this project's .pi/skills / .agents/skills.`}):null,!a&&t.length>0?(0,B.jsxs)(`table`,{className:`table`,children:[(0,B.jsx)(`thead`,{children:(0,B.jsxs)(`tr`,{children:[(0,B.jsx)(`th`,{children:`Skill`}),(0,B.jsx)(`th`,{children:`Scope`}),(0,B.jsx)(`th`,{children:`Source`}),(0,B.jsx)(`th`,{children:`Invocation`})]})}),(0,B.jsx)(`tbody`,{children:t.map(e=>(0,B.jsxs)(`tr`,{children:[(0,B.jsxs)(`td`,{children:[(0,B.jsx)(`a`,{href:`#${I_(e.name)}`,children:e.name}),(0,B.jsx)(`div`,{className:`muted`,style:{fontSize:`var(--font-size-xs)`},children:e.description})]}),(0,B.jsx)(`td`,{className:`mono`,children:e.scope}),(0,B.jsx)(`td`,{className:`mono`,children:e.source}),(0,B.jsx)(`td`,{className:`mono`,children:e.disableModelInvocation?`command-only`:`model`})]},`${e.scope}:${e.filePath}`))})]}):null]})}function iv({skillName:e,skill:t,loading:n,error:r}){return(0,B.jsxs)(`div`,{className:`main__inner`,children:[(0,B.jsxs)(`p`,{className:`crumbs`,children:[(0,B.jsx)(`a`,{href:`#/skills`,children:`Skills`}),` / `,e]}),(0,B.jsx)(`div`,{className:`page-head`,children:(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`h1`,{children:e}),(0,B.jsx)(`p`,{className:`mono`,children:t?`${t.scope} · ${t.source}`:e})]})}),r?(0,B.jsx)(`p`,{style:{color:`var(--color-text-red)`},children:r}):null,n?(0,B.jsx)(`p`,{className:`muted`,children:`Loading…`}):null,!n&&!t?(0,B.jsxs)(`p`,{className:`muted`,children:[e,` is not in the Pi skill catalog on this machine.`]}):null,t?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`h3`,{children:`Description`}),(0,B.jsx)(`p`,{children:t.description}),(0,B.jsx)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`},children:`Invocation`}),(0,B.jsx)(`p`,{className:`mono`,children:t.disableModelInvocation?`command-only`:`model`}),(0,B.jsx)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`},children:`File path`}),(0,B.jsx)(`p`,{className:`mono`,children:t.filePath}),(0,B.jsx)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`},children:`Base dir`}),(0,B.jsx)(`p`,{className:`mono`,children:t.baseDir})]}):null]})}function av({packageScope:e,packageSource:t,filePath:n}){let[r,i]=(0,v.useState)([]),[a,o]=(0,v.useState)([]),[s,c]=(0,v.useState)(null),[l,u]=(0,v.useState)(!0),d=(0,v.useCallback)(async()=>{try{let e=await Fn();i(e.packages),o(e.extensions),c(null)}catch(e){c(e instanceof Error?e.message:String(e))}finally{u(!1)}},[]);if((0,v.useEffect)(()=>{d()},[d]),e&&t){let n=r.find(n=>n.scope===e&&n.source===t)??null;return(0,B.jsx)(ov,{scope:e,source:t,pkg:n,loading:l,error:s})}if(n){let e=a.find(e=>e.path===n)??null;return(0,B.jsx)(sv,{filePath:n,file:e,loading:l,error:s})}let f=!l&&r.length===0&&a.length===0;return(0,B.jsxs)(`div`,{className:`main__inner main__inner--wide`,children:[(0,B.jsx)(`div`,{className:`page-head`,children:(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`h1`,{children:`Extensions`}),(0,B.jsx)(`p`,{children:`Extensions the Pi SDK can discover on this machine. Factory stages do not load them.`})]})}),s?(0,B.jsx)(`p`,{style:{color:`var(--color-text-red)`},children:s}):null,l?(0,B.jsx)(`p`,{className:`muted`,children:`Loading extensions…`}):null,f?(0,B.jsx)(`p`,{className:`muted`,children:`No extensions found under ~/.pi/agent/extensions, this project's .pi/extensions, or packages in Pi settings.`}):null,!l&&r.length>0?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`h3`,{children:`Packages`}),(0,B.jsxs)(`table`,{className:`table`,children:[(0,B.jsx)(`thead`,{children:(0,B.jsxs)(`tr`,{children:[(0,B.jsx)(`th`,{children:`Source`}),(0,B.jsx)(`th`,{children:`Scope`}),(0,B.jsx)(`th`,{children:`Installed`})]})}),(0,B.jsx)(`tbody`,{children:r.map(e=>(0,B.jsxs)(`tr`,{children:[(0,B.jsx)(`td`,{children:(0,B.jsx)(`a`,{href:`#${L_(e.scope,e.source)}`,children:e.source})}),(0,B.jsx)(`td`,{className:`mono`,children:e.scope}),(0,B.jsx)(`td`,{className:`mono`,children:e.installedPath??`not installed`})]},`${e.scope}:${e.source}`))})]})]}):null,!l&&a.length>0?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`h3`,{children:`Files`}),(0,B.jsxs)(`table`,{className:`table`,children:[(0,B.jsx)(`thead`,{children:(0,B.jsxs)(`tr`,{children:[(0,B.jsx)(`th`,{children:`Name`}),(0,B.jsx)(`th`,{children:`Scope`}),(0,B.jsx)(`th`,{children:`Source`}),(0,B.jsx)(`th`,{children:`Origin`})]})}),(0,B.jsx)(`tbody`,{children:a.map(e=>(0,B.jsxs)(`tr`,{children:[(0,B.jsx)(`td`,{children:(0,B.jsx)(`a`,{href:`#${R_(e.path)}`,children:e.name})}),(0,B.jsx)(`td`,{className:`mono`,children:e.scope}),(0,B.jsx)(`td`,{className:`mono`,children:e.source}),(0,B.jsx)(`td`,{className:`mono`,children:e.origin})]},`${e.scope}:${e.path}`))})]})]}):null]})}function ov({scope:e,source:t,pkg:n,loading:r,error:i}){return(0,B.jsxs)(`div`,{className:`main__inner`,children:[(0,B.jsxs)(`p`,{className:`crumbs`,children:[(0,B.jsx)(`a`,{href:`#/extensions`,children:`Extensions`}),` / `,t]}),(0,B.jsx)(`div`,{className:`page-head`,children:(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`h1`,{children:t}),(0,B.jsx)(`p`,{className:`mono`,children:n?`${n.scope} · package`:`${e} · package`})]})}),i?(0,B.jsx)(`p`,{style:{color:`var(--color-text-red)`},children:i}):null,r?(0,B.jsx)(`p`,{className:`muted`,children:`Loading…`}):null,!r&&!n?(0,B.jsxs)(`p`,{className:`muted`,children:[t,` is not in the Pi package catalog on this machine.`]}):null,n?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`},children:`Scope`}),(0,B.jsx)(`p`,{className:`mono`,children:n.scope}),(0,B.jsx)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`},children:`Source`}),(0,B.jsx)(`p`,{className:`mono`,children:n.source}),(0,B.jsx)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`},children:`Filtered`}),(0,B.jsx)(`p`,{className:`mono`,children:n.filtered?`yes`:`no`}),(0,B.jsx)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`},children:`Installed path`}),(0,B.jsx)(`p`,{className:`mono`,children:n.installedPath??`not installed`})]}):null]})}function sv({filePath:e,file:t,loading:n,error:r}){let i=t?.name??e;return(0,B.jsxs)(`div`,{className:`main__inner`,children:[(0,B.jsxs)(`p`,{className:`crumbs`,children:[(0,B.jsx)(`a`,{href:`#/extensions`,children:`Extensions`}),` / `,i]}),(0,B.jsx)(`div`,{className:`page-head`,children:(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`h1`,{children:i}),(0,B.jsx)(`p`,{className:`mono`,children:t?`${t.scope} · ${t.source}`:e})]})}),r?(0,B.jsx)(`p`,{style:{color:`var(--color-text-red)`},children:r}):null,n?(0,B.jsx)(`p`,{className:`muted`,children:`Loading…`}):null,!n&&!t?(0,B.jsx)(`p`,{className:`muted`,children:`This path is not in the Pi extension catalog on this machine.`}):null,t?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`},children:`Scope`}),(0,B.jsx)(`p`,{className:`mono`,children:t.scope}),(0,B.jsx)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`},children:`Source`}),(0,B.jsx)(`p`,{className:`mono`,children:t.source}),(0,B.jsx)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`},children:`Origin`}),(0,B.jsx)(`p`,{className:`mono`,children:t.origin}),(0,B.jsx)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`},children:`File path`}),(0,B.jsx)(`p`,{className:`mono`,children:t.path}),t.baseDir?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`},children:`Base dir`}),(0,B.jsx)(`p`,{className:`mono`,children:t.baseDir})]}):null]}):null]})}var cv=`sf-theme`;function lv(){try{let e=localStorage.getItem(cv);if(e===`light`||e===`dark`||e===`system`)return e}catch{}return`system`}function uv(e){try{localStorage.setItem(cv,e)}catch{}}function dv({value:e,onChange:t}){return(0,B.jsxs)(`section`,{className:`card`,children:[(0,B.jsx)(`div`,{className:`card__head`,children:(0,B.jsx)(`h2`,{children:`Appearance`})}),(0,B.jsx)(`p`,{style:{margin:0,color:`var(--color-text-secondary)`,fontSize:`var(--font-size-sm)`},children:`Applies immediately, on every screen.`}),(0,B.jsx)(`div`,{className:`theme-picks`,role:`radiogroup`,"aria-label":`Color theme`,children:[`system`,`light`,`dark`].map(n=>(0,B.jsxs)(`button`,{type:`button`,className:`theme-pick`,"data-theme":n,"aria-pressed":e===n?`true`:`false`,onClick:()=>{uv(n),t(n)},children:[(0,B.jsx)(`span`,{className:`theme-pick__swatch`,"data-preview":n}),(0,B.jsx)(`strong`,{children:n===`system`?`System`:n===`light`?`Light`:`Dark`}),(0,B.jsx)(`span`,{children:n===`system`?`Follows this machine`:`Astryx neutral`})]},n))})]})}var fv=`http://127.0.0.1:3847/mcp`;function pv(e,t={}){if(t.viteDev||e.hostname!==`127.0.0.1`&&e.hostname!==`localhost`&&e.hostname!==`[::1]`)return fv;let n=e.hostname===`localhost`||e.hostname===`[::1]`?`127.0.0.1`:e.hostname;return`${`${e.protocol}//${n}${e.port?`:${e.port}`:``}`}/mcp`}function mv(e){return`${JSON.stringify({mcpServers:{stageflow:{url:e}}},null,2)}\n`}function hv(){let e=pv(window.location,{viteDev:!1}),t=mv(e);return(0,B.jsxs)(`section`,{className:`card`,children:[(0,B.jsx)(`div`,{className:`card__head`,children:(0,B.jsx)(`h2`,{children:`Operator-host MCP`})}),(0,B.jsx)(`p`,{style:{margin:0,color:`var(--color-text-secondary)`,fontSize:`var(--font-size-sm)`},children:`This console process also serves Streamable HTTP MCP on localhost. Cursor connects with a URL. There is no stdio command, and the endpoint dies when this process stops.`}),(0,B.jsxs)(`div`,{className:`setting`,children:[(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`strong`,{children:`Endpoint`}),(0,B.jsxs)(`p`,{children:[`Same host as this console, path`,` `,(0,B.jsx)(`span`,{className:`mono`,children:`/mcp`}),`. Loopback only. No API key.`]})]}),(0,B.jsx)(`span`,{className:`mono`,style:{wordBreak:`break-all`},children:e})]}),(0,B.jsxs)(`ol`,{className:`steps`,children:[(0,B.jsx)(`li`,{children:(0,B.jsx)(`span`,{children:`Keep this operator console running. MCP is not a second server.`})}),(0,B.jsx)(`li`,{children:(0,B.jsxs)(`span`,{children:[`Open Cursor Settings → MCP, or add`,` `,(0,B.jsx)(`span`,{className:`mono`,children:`.cursor/mcp.json`}),` in this project.`]})}),(0,B.jsx)(`li`,{children:(0,B.jsxs)(`span`,{children:[`Paste the snippet below. Use `,(0,B.jsx)(`span`,{className:`mono`,children:`url`}),`, not`,` `,(0,B.jsx)(`span`,{className:`mono`,children:`command`}),`.`]})}),(0,B.jsx)(`li`,{children:(0,B.jsxs)(`span`,{children:[`Reload MCP in Cursor. Tools that should appear:`,` `,(0,B.jsx)(`span`,{className:`mono`,children:`list_pipelines`}),`,`,` `,(0,B.jsx)(`span`,{className:`mono`,children:`start_run`}),`,`,` `,(0,B.jsx)(`span`,{className:`mono`,children:`get_run`}),`,`,` `,(0,B.jsx)(`span`,{className:`mono`,children:`get_health`}),`,`,` `,(0,B.jsx)(`span`,{className:`mono`,children:`list_runs`}),`,`,` `,(0,B.jsx)(`span`,{className:`mono`,children:`read_artifact`}),`.`]})})]}),(0,B.jsx)(lc,{code:t,language:`json`,title:`.cursor/mcp.json`,container:`section`,hasLanguageLabel:!1,width:`100%`}),(0,B.jsx)(`p`,{className:`muted`,style:{margin:`var(--spacing-4) 0 0`,fontSize:`var(--font-size-sm)`},children:`This URL is this console's origin plus /mcp. It must match the MCP endpoint line printed on boot.`}),(0,B.jsx)(`p`,{className:`muted`,style:{margin:`var(--spacing-2) 0 0`,fontSize:`var(--font-size-sm)`},children:`Held-stage answers stay in this console. MCP can start and inspect runs; it cannot submit an answer.`})]})}var gv=`Servers from this project's git-root .mcp.json. Check tests whether a server can connect. It does not start a run and does not attach tools to stages. YAML mcp: still allowlists what a stage receives.`;function _v(e){switch(e){case`not-yet-probed`:return`Not yet probed`;case`probing`:return`Probing…`;case`connected`:return`Connected`;case`needs_auth`:return`Needs auth`;case`connect_failed`:return`Connect failed`;case`unresolved_var`:return`Unresolved variable`;case`invalid_config`:return`Invalid config`;case`missing_catalog`:return`Missing catalog`;case`cancelled`:return`Cancelled`}}function vv(e){switch(e){case`probing`:return`running`;case`connected`:return`succeeded`;case`needs_auth`:return`waiting`;case`connect_failed`:case`unresolved_var`:case`invalid_config`:case`missing_catalog`:return`failed`;case`not-yet-probed`:case`cancelled`:return}}function yv(e){return e===`missing_catalog`?`No git-root .mcp.json in this project.`:e===`invalid_config`?`Project .mcp.json is invalid.`:null}function bv(e){let t={loading:!0,catalogStatus:null,servers:[],error:null},n=!1,r=new Map,i=new Set,a=()=>t,o=()=>{for(let e of i)e()},s=(e,n)=>{t={...t,servers:t.servers.map(t=>t.name===e?{...t,...n}:t)},o()};return{getState:a,load:async()=>{if(!n){t={loading:!0,catalogStatus:null,servers:[],error:null},o();try{let r=await e.list();if(n)return;if(r.status!==`ok`){t={loading:!1,catalogStatus:r.status,servers:[],error:null},o();return}t={loading:!1,catalogStatus:`ok`,servers:r.servers.map(e=>({name:e.name,transport:e.transport,status:`not-yet-probed`})),error:null},o()}catch(e){if(n)return;t={loading:!1,catalogStatus:null,servers:[],error:e instanceof Error?e.message:String(e)},o()}}},check:async t=>{if(n||r.has(t))return;let i=new AbortController;r.set(t,i),s(t,{status:`probing`,error:void 0});try{let r=await e.probe(t,{signal:i.signal});if(n)return;s(t,{status:r.status,error:r.error})}catch(e){if(n||i.signal.aborted)return;s(t,{status:`connect_failed`,error:e instanceof Error?e.message:String(e)})}finally{r.delete(t)}},dispose:()=>{n=!0;for(let e of r.values())e.abort();r.clear()},subscribe:e=>(i.add(e),()=>{i.delete(e)})}}function xv(){let e=(0,v.useRef)(null),[t,n]=(0,v.useState)({loading:!0,catalogStatus:null,servers:[],error:null});(0,v.useEffect)(()=>{let t=bv({list:rr,probe:ir});e.current=t,n(t.getState());let r=t.subscribe(()=>n(t.getState()));return t.load(),()=>{r(),t.dispose(),e.current===t&&(e.current=null)}},[]);let r=t.catalogStatus?yv(t.catalogStatus):null;return(0,B.jsxs)(`section`,{className:`card`,children:[(0,B.jsx)(`div`,{className:`card__head`,children:(0,B.jsx)(`h2`,{children:`Project MCP servers`})}),(0,B.jsx)(`p`,{style:{margin:0,color:`var(--color-text-secondary)`,fontSize:`var(--font-size-sm)`},children:gv}),t.error?(0,B.jsx)(`p`,{style:{color:`var(--color-text-red)`,fontSize:`var(--font-size-sm)`,marginBottom:`var(--spacing-3)`},children:t.error}):null,r?(0,B.jsx)(`p`,{style:{color:`var(--color-text-red)`,fontSize:`var(--font-size-sm)`,marginBottom:`var(--spacing-3)`},children:r}):null,t.loading?(0,B.jsx)(`p`,{className:`muted`,children:`Loading project catalog…`}):t.catalogStatus===`ok`&&t.servers.length===0?(0,B.jsx)(`p`,{className:`muted`,children:`No servers in .mcp.json.`}):t.servers.map(t=>{let n=vv(t.status),r=t.status===`probing`;return(0,B.jsxs)(`div`,{className:`setting`,children:[(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`strong`,{children:t.name}),(0,B.jsx)(`p`,{children:t.transport}),t.error?(0,B.jsx)(`p`,{children:t.error}):null]}),(0,B.jsxs)(`span`,{style:{display:`flex`,gap:`var(--spacing-2)`,alignItems:`center`},children:[(0,B.jsxs)(`span`,{className:`status`,children:[(0,B.jsx)(`span`,{className:`dot${n?` dot--${n}`:``}`}),` `,_v(t.status)]}),(0,B.jsx)(`button`,{type:`button`,className:`btn btn--ghost`,disabled:r,onClick:()=>void e.current?.check(t.name),children:r?`Probing…`:`Check`})]})]},t.name)})]})}var Sv=`Pi may complete login via a local callback in the Stageflow process. If the browser cannot reach this machine, paste the redirect URL or code when prompted.`,Cv=`If automatic completion does not finish, paste the redirect URL or manual code below.`;function wv(e){for(let t=e.length-1;t>=0;t--){let n=e[t];if(n?.type===`auth_url`)return n}}function Tv(e){for(let t=e.length-1;t>=0;t--){let n=e[t];if(n?.type===`device_code`)return n}}function Ev(e){for(let t=e.length-1;t>=0;t--){let n=e[t];if(n?.type===`progress`||n?.type===`info`)return n.message}}function Dv(e){for(let t=e.length-1;t>=0;t--){let n=e[t];if(n?.type===`info`&&n.links&&n.links.length>0)return n.links}}function Ov(e){return e.status===`completed`||e.status===`failed`||e.status===`cancelled`}function kv(e){return e.type===`select`?`select`:e.type===`secret`?`password`:`text`}function Av(e){return e.supportsOauth}var jv=500;function Mv({providerId:e,providerName:t,onComplete:n,onDismiss:r}){let[i,a]=(0,v.useState)(null),[o,s]=(0,v.useState)(null),[c,l]=(0,v.useState)(``),[u,d]=(0,v.useState)(!1),[f,p]=(0,v.useState)(null),m=(0,v.useRef)(!1),h=(0,v.useRef)(!1);(0,v.useEffect)(()=>{m.current||(m.current=!0,(async()=>{d(!0);let t=await Un(e);if(d(!1),!t.ok){s(t.error);return}a(t.session)})())},[e]),(0,v.useEffect)(()=>{if(!i||Ov(i))return;let t=window.setInterval(()=>{(async()=>{try{let{session:t}=await Wn(e,i.id);a(t)}catch(e){s(e instanceof Error?e.message:String(e))}})()},jv);return()=>window.clearInterval(t)},[e,i?.id,i?.status]),(0,v.useEffect)(()=>{if(!(!i||!Ov(i)||h.current)){if(h.current=!0,i.status===`completed`){n(i.provider,i.warning?.message);return}if(i.status===`failed`){s(i.error?.message??`OAuth login failed`);return}r()}},[i,n,r]);let g=i?.pendingPrompt;(0,v.useEffect)(()=>{g||(l(``),s(e=>e===`Enter a value to continue.`?null:e))},[g]);async function _(e,t){try{await navigator.clipboard.writeText(t),p(e),window.setTimeout(()=>p(null),1500)}catch{s(`Could not copy to clipboard`)}}async function y(){if(!i)return;let t=c.trim();if(!t){s(`Enter a value to continue.`);return}d(!0),s(null);let n=await Gn(e,i.id,t);if(d(!1),!n.ok){s(n.error);return}l(``),a(n.session)}async function b(t){if(!i)return;d(!0),s(null);let n=await Gn(e,i.id,t);if(d(!1),!n.ok){s(n.error);return}a(n.session)}async function x(){if(!i){r();return}d(!0),await Kn(e,i.id),d(!1),h.current=!0,r()}let S=i?wv(i.events):void 0,C=i?Tv(i.events):void 0,w=i?Ev(i.events):void 0,T=i?Dv(i.events):void 0,E=g?kv(g):null;return(0,B.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:`var(--spacing-2)`,marginTop:`var(--spacing-2)`},children:[(0,B.jsxs)(`p`,{style:{margin:0,color:`var(--color-text-secondary)`,fontSize:`var(--font-size-sm)`},children:[`Connecting `,t,` with Pi OAuth / subscription login.`]}),w?(0,B.jsx)(`p`,{className:`muted`,style:{margin:0},children:w}):null,T&&T.length>0?(0,B.jsx)(`div`,{style:{display:`flex`,gap:`var(--spacing-2)`,flexWrap:`wrap`},children:T.map(e=>(0,B.jsx)(`a`,{className:`btn btn--ghost`,href:e.url,target:`_blank`,rel:`noreferrer`,children:e.label??`Open link`},e.url))}):null,S?(0,B.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:`var(--spacing-2)`},children:[S.instructions?(0,B.jsx)(`p`,{style:{margin:0,fontSize:`var(--font-size-sm)`},children:S.instructions}):null,(0,B.jsxs)(`div`,{style:{display:`flex`,gap:`var(--spacing-2)`,flexWrap:`wrap`},children:[(0,B.jsx)(`a`,{className:`btn btn--primary`,href:S.url,target:`_blank`,rel:`noreferrer`,children:`Open browser`}),(0,B.jsx)(`button`,{type:`button`,className:`btn btn--ghost`,onClick:()=>void _(`url`,S.url),children:f===`url`?`Copied`:`Copy link`})]}),(0,B.jsxs)(`p`,{style:{margin:0,color:`var(--color-text-secondary)`,fontSize:`var(--font-size-sm)`},children:[Sv,` `,Cv]})]}):null,C?(0,B.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:`var(--spacing-2)`},children:[(0,B.jsxs)(`p`,{style:{margin:0},children:[`Device code: `,(0,B.jsx)(`strong`,{children:C.userCode})]}),typeof C.expiresInSeconds==`number`?(0,B.jsxs)(`p`,{className:`muted`,style:{margin:0,fontSize:`var(--font-size-sm)`},children:[`Code expires in about `,C.expiresInSeconds,`s.`]}):null,(0,B.jsxs)(`div`,{style:{display:`flex`,gap:`var(--spacing-2)`,flexWrap:`wrap`},children:[(0,B.jsx)(`a`,{className:`btn btn--primary`,href:C.verificationUri,target:`_blank`,rel:`noreferrer`,children:`Open verification page`}),(0,B.jsx)(`button`,{type:`button`,className:`btn btn--ghost`,onClick:()=>void _(`code`,C.userCode),children:f===`code`?`Copied`:`Copy code`}),(0,B.jsx)(`button`,{type:`button`,className:`btn btn--ghost`,onClick:()=>void _(`uri`,C.verificationUri),children:f===`uri`?`Copied`:`Copy URI`})]})]}):null,g&&E===`select`?(0,B.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:`var(--spacing-2)`},children:[(0,B.jsx)(`p`,{style:{margin:0},children:g.message}),(g.options??[]).map(e=>(0,B.jsxs)(`button`,{type:`button`,className:`btn btn--ghost`,disabled:u,onClick:()=>void b(e.id),children:[e.label,e.description?` — ${e.description}`:``]},e.id))]}):null,g&&E!==`select`?(0,B.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:`var(--spacing-2)`},children:[(0,B.jsx)(`p`,{style:{margin:0},children:g.message}),g.type===`manual_code`?(0,B.jsx)(`p`,{style:{margin:0,color:`var(--color-text-secondary)`,fontSize:`var(--font-size-sm)`},children:Cv}):null,(0,B.jsx)(`input`,{className:`input`,type:E===`password`?`password`:`text`,autoComplete:`off`,placeholder:g.placeholder??``,value:c,onChange:e=>l(e.target.value)}),(0,B.jsx)(`button`,{type:`button`,className:`btn btn--primary`,disabled:u,onClick:()=>void y(),children:u?`Sending…`:`Continue`})]}):null,o?(0,B.jsx)(`p`,{style:{margin:0,color:`var(--color-text-red)`,fontSize:`var(--font-size-sm)`},children:o}):null,(0,B.jsx)(`div`,{style:{display:`flex`,gap:`var(--spacing-2)`},children:(0,B.jsx)(`button`,{type:`button`,className:`btn btn--ghost`,disabled:u,onClick:()=>void x(),children:`Cancel`})})]})}function Nv({provider:e,status:t,connecting:n,oauthing:r,apiKeyDraft:i,rowBusy:a,showDisconnect:o,onSetConnecting:s,onSetOauthing:c,onApiKeyChange:l,onConnectSubmit:u,onDisconnect:d,onOauthComplete:f,onOauthDismiss:p}){let m=t?.configured===!0,h=Hg(e),g=Av(e),_=Ug(e);return(0,B.jsxs)(`div`,{className:`setting`,children:[(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`strong`,{children:e.name}),(0,B.jsx)(`p`,{children:Wg(t)}),n?(0,B.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:`var(--spacing-2)`,marginTop:`var(--spacing-2)`},children:[(0,B.jsx)(`input`,{className:`input`,type:`password`,autoComplete:`off`,placeholder:`API key`,value:i,onChange:e=>l(e.target.value)}),(0,B.jsxs)(`div`,{style:{display:`flex`,gap:`var(--spacing-2)`},children:[(0,B.jsx)(`button`,{type:`button`,className:`btn btn--primary`,disabled:a,onClick:()=>u(e.id),children:a?`Saving…`:`Save key`}),(0,B.jsx)(`button`,{type:`button`,className:`btn btn--ghost`,disabled:a,onClick:()=>{s(null),l(``)},children:`Cancel`})]})]}):null,r?(0,B.jsx)(Mv,{providerId:e.id,providerName:e.name,onComplete:f,onDismiss:p}):null]}),(0,B.jsxs)(`span`,{style:{display:`flex`,gap:`var(--spacing-2)`},children:[m&&o?(0,B.jsx)(`button`,{type:`button`,className:`btn btn--ghost`,disabled:a||r,onClick:()=>d(e.id),children:`Disconnect`}):null,m&&!o?(0,B.jsx)(`span`,{className:`muted`,children:`Connected`}):null,h&&!m&&!r?(0,B.jsx)(`button`,{type:`button`,className:`btn btn--primary`,disabled:a,onClick:()=>{s(e.id),c(null),l(``)},children:`Connect`}):null,g&&!m&&!n&&!r?(0,B.jsx)(`button`,{type:`button`,className:_?`btn btn--primary`:`btn btn--ghost`,disabled:a,onClick:()=>{c(e.id),s(null),l(``)},children:`Connect with OAuth`}):null]})]},e.id)}function Pv(){let[e,t]=(0,v.useState)([]),[n,r]=(0,v.useState)({}),[i,a]=(0,v.useState)(void 0),[o,s]=(0,v.useState)(!0),[c,l]=(0,v.useState)(null),[u,d]=(0,v.useState)(!1),[f,p]=(0,v.useState)(null),[m,h]=(0,v.useState)(null),[g,_]=(0,v.useState)(``),[y,b]=(0,v.useState)(null),[x,S]=(0,v.useState)(null),[C,w]=(0,v.useState)(null),T=(0,v.useCallback)(async()=>{l(null);let[e,n]=await Promise.all([Rn(),zn()]);t(e.providers),a(n.credentialSource);let i={};await Promise.all(e.providers.map(async e=>{try{let{provider:t}=await Bn(e.id);i[e.id]=t}catch{i[e.id]=void 0}})),r(i)},[]);(0,v.useEffect)(()=>{(async()=>{s(!0);try{await T()}catch(e){l(e instanceof Error?e.message:String(e))}finally{s(!1)}})()},[T]);async function E(e){if(e===`pi_home`||e===`sf_owned`){d(!0),l(null);try{let t=await qn(e);a(t.credentialSource),await T()}catch(e){l(e instanceof Error?e.message:String(e))}finally{d(!1)}}}async function D(e){let t=g.trim();if(!t){S(`Paste an API key to connect.`);return}b(e),S(null);let n=await Vn(e,t);if(b(null),!n.ok){S(n.error);return}_(``),p(null),r(t=>({...t,[e]:n.provider}))}async function O(e){b(e),S(null);let t=await Hn(e);if(b(null),!t.ok){S(t.error);return}r(n=>({...n,[e]:t.provider}))}return(0,B.jsxs)(`section`,{className:`card`,children:[(0,B.jsx)(`div`,{className:`card__head`,children:(0,B.jsx)(`h2`,{children:`Providers`})}),(0,B.jsx)(`p`,{style:{margin:0,color:`var(--color-text-secondary)`,fontSize:`var(--font-size-sm)`},children:zg}),(0,B.jsxs)(`div`,{className:`setting`,children:[(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`strong`,{children:`Credential source`}),(0,B.jsx)(`p`,{children:`Use credentials already stored by Pi, or keep a Stageflow-owned store for keys you paste here.`})]}),o?(0,B.jsx)(`span`,{className:`muted`,children:`—`}):(0,B.jsxs)(`select`,{className:`select`,value:i??``,disabled:u,onChange:e=>void E(e.target.value),children:[(0,B.jsx)(`option`,{value:``,disabled:!0,children:`Not set`}),(0,B.jsx)(`option`,{value:`pi_home`,children:`Existing Pi login (~/.pi)`}),(0,B.jsx)(`option`,{value:`sf_owned`,children:`Stageflow-owned store`})]})]}),c?(0,B.jsx)(`p`,{style:{color:`var(--color-text-red)`,fontSize:`var(--font-size-sm)`,marginBottom:`var(--spacing-3)`},children:c}):null,x?(0,B.jsx)(`p`,{style:{color:`var(--color-text-red)`,fontSize:`var(--font-size-sm)`,marginBottom:`var(--spacing-3)`},children:x}):null,C?(0,B.jsx)(`p`,{style:{color:`var(--color-text-secondary)`,fontSize:`var(--font-size-sm)`,marginBottom:`var(--spacing-3)`},children:C}):null,o?(0,B.jsx)(`p`,{className:`muted`,children:`Loading providers…`}):e.length===0?(0,B.jsx)(`p`,{className:`muted`,children:`No providers reported by Pi.`}):e.map(e=>(0,B.jsx)(Nv,{provider:e,status:n[e.id],connecting:f===e.id,oauthing:m===e.id,apiKeyDraft:g,rowBusy:y===e.id,showDisconnect:!0,onSetConnecting:e=>{p(e),S(null)},onSetOauthing:e=>{h(e),S(null),w(null)},onApiKeyChange:_,onConnectSubmit:e=>void D(e),onDisconnect:e=>void O(e),onOauthComplete:(t,n)=>{h(null),w(n??null),t?r(n=>({...n,[e.id]:t})):T()},onOauthDismiss:()=>{h(null),S(null)}},e.id))]})}var Fv=`sf-notify-waiting`;function Iv(){try{let e=localStorage.getItem(Fv);if(e===`system`||e===`off`)return e}catch{}return`off`}function Lv(e){try{localStorage.setItem(Fv,e)}catch{}}function Rv(){return typeof Notification>`u`?`unsupported`:Notification.permission}async function zv(){return typeof Notification>`u`?`unsupported`:Notification.permission==="default"?Notification.requestPermission():Notification.permission}function Bv(e,t){let n=new Set(e.map(e=>e.run_id));if(t===null)return{emit:[],nextSeen:n};let r=[],i=new Set(t);for(let t of e)i.has(t.run_id)||(r.push(t),i.add(t.run_id));for(let e of[...i])n.has(e)||i.delete(e);return{emit:r,nextSeen:i}}function Vv(e){let{snapshot:t,loading:n}=pr(),r=(0,v.useRef)(null);(0,v.useEffect)(()=>{if(n)return;let{emit:i,nextSeen:a}=Bv(xr(t),r.current);if(r.current=a,e){for(let e of i)if(typeof Notification<`u`&&Notification.permission===`granted`){let t=[e.pipeline_id,e.waiting_summary].filter(e=>!!e);new Notification(`Stage waiting on you`,{body:t.join(` — `)})}}},[t,n,e])}function Hv({themeMode:e,onThemeChange:t,notifyPreference:n,onNotifyChange:r}){let{snapshot:i,loading:a}=pr(),o=mr(),s=i.health,c=a&&s==null,l=!c&&s==null?`unavailable`:null,[u,d]=(0,v.useState)(null),[f,p]=(0,v.useState)(!1),[m,h]=(0,v.useState)(Rv);async function g(e){let t=e===`system`?`system`:`off`;if(Lv(t),r(t),t===`system`&&Rv()==="default"){let e=await zv();h(e)}}async function _(e){let t=Number(e);p(!0),d(null);try{await Ln(t),await o.refresh()}catch(e){d(e instanceof Error?e.message:String(e))}finally{p(!1)}}let y=[1,2,3,4,6],b=s?.maxConcurrent,x=b!=null&&!y.includes(b)?[b,...y]:y;return(0,B.jsxs)(`div`,{className:`main__inner`,children:[(0,B.jsx)(`div`,{className:`page-head`,children:(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`h1`,{children:`Settings`}),(0,B.jsx)(`p`,{children:`Local to this machine. Nothing here is shared, because Stageflow runs as one operator's CLI.`})]})}),(0,B.jsx)(dv,{value:e,onChange:t}),(0,B.jsx)(Pv,{}),(0,B.jsx)(xv,{}),(0,B.jsx)(hv,{}),(0,B.jsxs)(`section`,{className:`card`,children:[(0,B.jsx)(`div`,{className:`card__head`,children:(0,B.jsx)(`h2`,{children:`Concurrency`})}),l?(0,B.jsxs)(`p`,{style:{color:`var(--color-text-red)`,fontSize:`var(--font-size-sm)`,marginBottom:`var(--spacing-3)`},children:[`Could not load capacity: `,l]}):null,(0,B.jsxs)(`div`,{className:`setting`,children:[(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`strong`,{children:`Session slots`}),(0,B.jsx)(`p`,{children:`How many stage sessions may be alive at once. A stage waiting on you still holds its slot. Lowering the cap does not stop runs that are already in flight.`})]}),c?(0,B.jsx)(`span`,{className:`muted`,children:`—`}):s?(0,B.jsx)(`select`,{className:`select`,value:s.maxConcurrent,disabled:f,onChange:e=>void _(e.target.value),children:x.map(e=>(0,B.jsxs)(`option`,{value:e,children:[e,e===s.maxConcurrent?` · current`:``]},e))}):(0,B.jsx)(`span`,{className:`muted`,children:`—`})]}),u?(0,B.jsxs)(`p`,{style:{color:`var(--color-text-red)`,fontSize:`var(--font-size-sm)`,marginBottom:`var(--spacing-3)`},children:[`Could not update slots: `,u]}):null,(0,B.jsxs)(`div`,{className:`setting`,children:[(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`strong`,{children:`Slots available`}),(0,B.jsx)(`p`,{children:`Free slots that can accept a new run right now.`})]}),(0,B.jsx)(`span`,{className:`muted`,children:c?`—`:s?String(s.slotsAvailable):`—`})]}),(0,B.jsxs)(`div`,{className:`setting`,children:[(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`strong`,{children:`When slots are full`}),(0,B.jsx)(`p`,{children:`Reject with busy_capacity. There is no queue.`})]}),(0,B.jsx)(`span`,{className:`muted`,children:`Reject with busy_capacity`})]})]}),(0,B.jsxs)(`section`,{className:`card`,children:[(0,B.jsx)(`div`,{className:`card__head`,children:(0,B.jsx)(`h2`,{children:`Held stages`})}),(0,B.jsxs)(`div`,{className:`setting`,children:[(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`strong`,{children:`Hold timeout`}),(0,B.jsx)(`p`,{children:`A held stage waits until you answer. There is no timeout yet.`})]}),(0,B.jsx)(`span`,{className:`muted`,children:`—`})]}),(0,B.jsxs)(`div`,{className:`setting`,children:[(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`strong`,{children:`Notify me when a stage asks`}),(0,B.jsx)(`p`,{children:`A held stage is invisible if this window is closed. A system notification is the only thing that reaches you.`})]}),(0,B.jsxs)(`select`,{className:`select`,value:n,onChange:e=>void g(e.target.value),children:[(0,B.jsx)(`option`,{value:`system`,children:`System notification`}),(0,B.jsx)(`option`,{value:`off`,children:`Nothing`})]})]}),n===`system`&&m===`denied`?(0,B.jsx)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-xs)`,padding:`var(--spacing-2) 0`},children:`Notifications blocked — enable in browser settings`}):null]})]})}function Uv({onComplete:e}){let[t,n]=(0,v.useState)(!0),[r,i]=(0,v.useState)(null),[a,o]=(0,v.useState)(null),[s,c]=(0,v.useState)(!1),[l,u]=(0,v.useState)(`sf_owned`),[d,f]=(0,v.useState)(`offer`),[p,m]=(0,v.useState)(!1),[h,g]=(0,v.useState)([]),[_,y]=(0,v.useState)({}),[b,x]=(0,v.useState)(null),[S,C]=(0,v.useState)(null),[w,T]=(0,v.useState)(``),[E,D]=(0,v.useState)(null);(0,v.useEffect)(()=>{(async()=>{n(!0),i(null);try{let e=await zn();c(e.piHomeUsable);let t=Vg(e.piHomeUsable);u(t),e.piHomeUsable?f(`offer`):(f(`keys`),await O())}catch(e){i(e instanceof Error?e.message:String(e))}finally{n(!1)}})()},[]);async function O(){let e=(await Rn()).providers.filter(e=>Hg(e)||Av(e));g(e);let t={};await Promise.all(e.map(async e=>{try{let{provider:n}=await Bn(e.id);t[e.id]=n}catch{t[e.id]=void 0}})),y(t)}async function k(){m(!0),i(null);try{if(await qn(l),l===`pi_home`){e();return}await O(),f(`keys`)}catch(e){i(e instanceof Error?e.message:String(e))}finally{m(!1)}}async function A(e){let t=w.trim();if(!t){i(`Paste an API key to connect.`);return}D(e),i(null);try{await qn(`sf_owned`)}catch(e){D(null),i(e instanceof Error?e.message:String(e));return}let n=await Vn(e,t);if(D(null),!n.ok){i(n.error);return}T(``),x(null),y(t=>({...t,[e]:n.provider}))}let j=Object.values(_).some(e=>e?.configured);return(0,B.jsxs)(`div`,{className:`main__inner`,children:[(0,B.jsx)(`div`,{className:`page-head`,children:(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`h1`,{children:`Connect providers`}),(0,B.jsx)(`p`,{children:zg})]})}),t?(0,B.jsx)(`p`,{className:`muted`,children:`Checking for an existing Pi login…`}):null,r?(0,B.jsx)(`p`,{style:{color:`var(--color-text-red)`,marginBottom:`var(--spacing-4)`},children:r}):null,a?(0,B.jsx)(`p`,{style:{color:`var(--color-text-secondary)`,marginBottom:`var(--spacing-4)`},children:a}):null,!t&&d===`offer`?(0,B.jsxs)(`section`,{className:`card`,children:[(0,B.jsx)(`div`,{className:`card__head`,children:(0,B.jsx)(`h2`,{children:`Credential source`})}),(0,B.jsx)(`p`,{style:{margin:0,color:`var(--color-text-secondary)`,fontSize:`var(--font-size-sm)`},children:s?`Usable Pi credentials were found on this machine. Reuse them, or set up keys inside Stageflow.`:`No usable Pi login was detected. Set up credentials in Stageflow.`}),(0,B.jsxs)(`div`,{className:`theme-picks`,role:`radiogroup`,"aria-label":`Credential source`,children:[(0,B.jsxs)(`button`,{type:`button`,className:`theme-pick`,"aria-pressed":l===`pi_home`?`true`:`false`,disabled:!s,onClick:()=>u(`pi_home`),children:[(0,B.jsx)(`strong`,{children:`Use existing Pi login`}),(0,B.jsx)(`span`,{children:`Reuse ~/.pi credentials without re-entering keys`})]}),(0,B.jsxs)(`button`,{type:`button`,className:`theme-pick`,"aria-pressed":l===`sf_owned`?`true`:`false`,onClick:()=>u(`sf_owned`),children:[(0,B.jsx)(`strong`,{children:`Set up in Stageflow`}),(0,B.jsx)(`span`,{children:`Paste API keys or complete Pi OAuth in an SF-owned store`})]})]}),(0,B.jsx)(`div`,{className:`form-actions`,style:{marginTop:`var(--spacing-4)`},children:(0,B.jsx)(`button`,{type:`button`,className:`btn btn--primary`,disabled:p||!s&&l===`pi_home`,onClick:()=>void k(),children:p?`Saving…`:`Continue`})})]}):null,!t&&d===`keys`?(0,B.jsxs)(`section`,{className:`card`,children:[(0,B.jsx)(`div`,{className:`card__head`,children:(0,B.jsx)(`h2`,{children:`Providers`})}),(0,B.jsx)(`p`,{style:{margin:0,color:`var(--color-text-secondary)`,fontSize:`var(--font-size-sm)`},children:`Connect at least one provider with an API key or Pi OAuth / subscription login.`}),h.length===0?(0,B.jsx)(`p`,{className:`muted`,children:`No connectable providers are available from Pi right now.`}):h.map(e=>(0,B.jsx)(Nv,{provider:e,status:_[e.id],connecting:b===e.id,oauthing:S===e.id,apiKeyDraft:w,rowBusy:E===e.id,showDisconnect:!1,onSetConnecting:x,onSetOauthing:C,onApiKeyChange:T,onConnectSubmit:e=>void A(e),onDisconnect:()=>void 0,onOauthComplete:(t,n)=>{C(null),o(n??null),t?y(n=>({...n,[e.id]:t})):O()},onOauthDismiss:()=>C(null)},e.id)),(0,B.jsxs)(`div`,{className:`form-actions`,style:{marginTop:`var(--spacing-4)`},children:[(0,B.jsx)(`button`,{type:`button`,className:`btn btn--primary`,disabled:!j,onClick:e,children:`Continue to console`}),(0,B.jsx)(`button`,{type:`button`,className:`btn btn--ghost`,onClick:e,children:`Skip for now`})]})]}):null]})}function Wv(e){return e.name===`connect`?`settings`:e.name===`detail`?`runs`:e.name===`new`?`today`:e.name===`pipeline`?`pipelines`:e.name===`task`?`tasks`:e.name===`skill`?`skills`:e.name===`extensionPackage`||e.name===`extensionFile`?`extensions`:e.name}function Gv(){let[e,t]=(0,v.useState)(()=>H_()),[n,r]=(0,v.useState)(lv),[i,a]=(0,v.useState)(Iv),[o,s]=(0,v.useState)(`loading`),{snapshot:c}=pr();(0,v.useEffect)(()=>{let e=()=>t(H_());return window.addEventListener(`hashchange`,e),window.location.hash||(window.location.hash=`#/today`),()=>window.removeEventListener(`hashchange`,e)},[]),Vv(i===`system`),(0,v.useEffect)(()=>{let e=!1;return zn().then(t=>{e||s(Bg(t)?`needs_connect`:`ready`)}).catch(()=>{e||s(`ready`)}),()=>{e=!0}},[]);let l=xr(c).length,u=c.health,d=(0,v.useCallback)(e=>{k_(e)},[]),f=(0,v.useCallback)(e=>{d(`/${e}`)},[d]),p;return p=e.name===`new`?(0,B.jsx)(Yg,{onStarted:e=>d(A_(e)),initialPipelinePath:e.pipelineId,initialTaskPath:e.taskPath}):e.name===`detail`?(0,B.jsx)(Pg,{runId:e.runId,view:e.view,onBack:()=>d(`/runs`),onReran:e=>d(A_(e)),onOpenStream:t=>d(t?j_(e.runId,t):A_(e.runId)),onOpenArtifact:t=>d(M_(e.runId,t)),onOpenEnvelope:t=>d(N_(e.runId,t))}):e.name===`runs`?(0,B.jsx)(Zr,{onOpen:e=>d(A_(e)),onNew:()=>d(`/new`)}):e.name===`pipelines`?(0,B.jsx)($_,{onNew:d}):e.name===`pipeline`?(0,B.jsx)($_,{pipelineId:e.pipelineId,onNew:d}):e.name===`tasks`?(0,B.jsx)(tv,{onNew:d}):e.name===`task`?(0,B.jsx)(tv,{taskId:e.taskId,onNew:d}):e.name===`skills`?(0,B.jsx)(rv,{}):e.name===`skill`?(0,B.jsx)(rv,{skillName:e.skillName}):e.name===`extensions`?(0,B.jsx)(av,{}):e.name===`extensionPackage`?(0,B.jsx)(av,{packageScope:e.scope,packageSource:e.source}):e.name===`extensionFile`?(0,B.jsx)(av,{filePath:e.path}):e.name===`settings`?(0,B.jsx)(Hv,{themeMode:n,onThemeChange:r,notifyPreference:i,onNotifyChange:a}):e.name===`connect`?(0,B.jsx)(Uv,{onComplete:()=>{s(`ready`),d(`/today`)}}):(0,B.jsx)(d_,{onOpen:e=>d(A_(e)),onOpenArtifact:(e,t)=>d(M_(e,t)),onNew:()=>d(`/new`),onSeeRuns:()=>d(`/runs`)}),o===`needs_connect`&&e.name!==`settings`&&e.name!==`connect`&&(p=(0,B.jsx)(Uv,{onComplete:()=>{s(`ready`),d(`/today`)}})),(0,B.jsx)(At,{theme:wn,mode:n,children:(0,B.jsxs)(`div`,{className:`app`,children:[(0,B.jsx)(jr,{activeId:Wv(e),onNavigate:f,waitingCount:l,health:u}),(0,B.jsx)(`main`,{className:`main`,children:p})]})})}function Kv(){let[e]=(0,v.useState)(()=>lr({source:or()}));return(0,B.jsx)(fr,{catalog:e,children:(0,B.jsx)(Gv,{})})}(0,Cn.createRoot)(document.getElementById(`root`)).render((0,B.jsx)(v.StrictMode,{children:(0,B.jsx)(Kv,{})}));
|
|
115
|
+
`).trim()),d;if(l===t.settledText)d=t.settledBlocks;else if(t.settledText.length>0&&l.startsWith(t.settledText)){let e=tp(l.slice(t.settledText.length),o);d=op(t.settledBlocks,e)}else d=tp(l,o);let f=u?tp(u,o):[];return t.settledText=l,t.settledBlocks=d,t.settledUpTo=c,t.prevInput=e,op(d,f)}var cp={start:`0`,center:`auto`},lp={start:null,center:`auto`},up={k7Eaqz:`xkj4a21`,$$css:!0},dp={proseWidth:e=>[{ks0D6T:e==null?e:`xf68679`,$$css:!0},{"--x-maxWidth":(e=>typeof e==`number`?e+`px`:e??void 0)(e)}],proseAlign:e=>[{kUOVxO:e==null?e:`xvlecxo`,$$css:!0},{"--x-marginInline":(e=>typeof e==`number`?e+`px`:e??void 0)(e)}],blockWidth:e=>[up,{"--x-minWidth":(e=>typeof e==`number`?e+`px`:e??void 0)(`min(${e}, 100%)`)}],blockAlign:e=>[{kUOVxO:e==null?e:`xvlecxo`,$$css:!0},{"--x-marginInline":(e=>typeof e==`number`?e+`px`:e??void 0)(e)}],cellMinWidth:e=>[{k7Eaqz:e==null?e:`xkj4a21`,$$css:!0},{"--x-minWidth":(e=>typeof e==`number`?e+`px`:e??void 0)(e)}]},fp={center:{k9WMMc:`x2b8uid`,$$css:!0},end:{k9WMMc:`xp4054r`,$$css:!0}},$={root:{kMv6JI:`x9ynric`,kMwMTN:`x1tgivj0`,kLWn49:`xw6l6zx`,kGuDYH:`xjm74w1`,kzqmXN:`xh8yej3`,ks0D6T:`x193iq5w`,k7Eaqz:`xeuugli`,kHjlTd:`x1mzt3pk`,$$css:!0},inlineRoot:{k1xSpc:`xt0psk2`,kzqmXN:`x14atkfc`,ks0D6T:`x1x1rfll`,kMv6JI:`xjb2p0i`,kMwMTN:`x1heor9g`,kLWn49:`x15bjb6t`,kGuDYH:`x1qlqyl8`,$$css:!0},headingBase:{kMv6JI:`x1g81bgm`,kMwMTN:`x1tgivj0`,$$css:!0},h1:{kGuDYH:`xcg7oai`,k63SB2:`x1v68xuy`,kLWn49:`xfmsba7`,$$css:!0},h2:{kGuDYH:`x1xvnhcw`,k63SB2:`x12yy4cs`,kLWn49:`x1cpk1wn`,$$css:!0},h3:{kGuDYH:`xii13ha`,k63SB2:`x1jcxfy8`,kLWn49:`xwjzt0u`,$$css:!0},h4:{kGuDYH:`x8tkxat`,k63SB2:`x2hcmsi`,kLWn49:`xqerer`,$$css:!0},h5:{kGuDYH:`xsgqta0`,k63SB2:`xno150v`,kLWn49:`xo3gurs`,$$css:!0},h6:{kGuDYH:`xw5ohdf`,k63SB2:`x1pw4frv`,kLWn49:`xeixjfn`,$$css:!0},spacingHeadingMajorDefault:{keoZOQ:`x13rv44w`,k1K539:`xep27e5`,$$css:!0},spacingHeadingMinorDefault:{keoZOQ:`x1s1qpeq`,k1K539:`x1p37lm5`,$$css:!0},spacingParagraphDefault:{keoZOQ:`xj6sv8s`,k1K539:`xep27e5`,$$css:!0},spacingCodeblockDefault:{keoZOQ:`x1s1qpeq`,k1K539:`xwh1t77`,$$css:!0},spacingBlockquoteDefault:{keoZOQ:`x1s1qpeq`,k1K539:`xwh1t77`,$$css:!0},spacingListDefault:{keoZOQ:`xj6sv8s`,k1K539:`xep27e5`,$$css:!0},spacingTableDefault:{keoZOQ:`x1s1qpeq`,k1K539:`xwh1t77`,$$css:!0},spacingHrDefault:{keoZOQ:`x13rv44w`,k1K539:`x4d5cxa`,$$css:!0},spacingImageDefault:{keoZOQ:`xj6sv8s`,k1K539:`xep27e5`,$$css:!0},spacingHeadingMajorCompact:{keoZOQ:`x1s1qpeq`,k1K539:`x1p37lm5`,$$css:!0},spacingHeadingMinorCompact:{keoZOQ:`xj6sv8s`,k1K539:`x14cgwvg`,$$css:!0},spacingParagraphCompact:{keoZOQ:`xcsaf9d`,k1K539:`x14cgwvg`,$$css:!0},spacingCodeblockCompact:{keoZOQ:`xtbrsbv`,k1K539:`x1p37lm5`,$$css:!0},spacingBlockquoteCompact:{keoZOQ:`xtbrsbv`,k1K539:`x1p37lm5`,$$css:!0},spacingListCompact:{keoZOQ:`xcsaf9d`,k1K539:`x14cgwvg`,$$css:!0},spacingTableCompact:{keoZOQ:`xtbrsbv`,k1K539:`x1p37lm5`,$$css:!0},spacingHrCompact:{keoZOQ:`xj6sv8s`,k1K539:`xep27e5`,$$css:!0},spacingImageCompact:{keoZOQ:`xtbrsbv`,k1K539:`x1p37lm5`,$$css:!0},noMarginBlockStart:{keoZOQ:`xdj266r`,$$css:!0},noMarginBlockEnd:{k1K539:`xat24cr`,$$css:!0},codeBlockWrapper:{ks0D6T:`x193iq5w`,$$css:!0},tableWrapper:{kXHlph:`xw2csxc`,ks0D6T:`x193iq5w`,"--container-padding-inline-start":`xrhngw9`,"--container-padding-inline-end":`xjsfl84`,"--container-padding-block-start":`x1047aw6`,"--container-padding-block-end":`xax9j7h`,$$css:!0},blockIndent:{kUOVxO:`x1ho7dyk`,$$css:!0},hr:{kMzoRj:`xc342km`,kEafiO:`x11xkdxz`,kPef9Z:`x13fuv20`,kLZC3w:`x1pc3f07`,$$css:!0}};function pp(e){let t=e.match(/^([\d.]+)ms$/);if(t)return parseFloat(t[1]);let n=e.match(/^([\d.]+)s$/);return n?parseFloat(n[1])*1e3:null}function mp(e){let t=0;for(let n of e)switch(n.type){case`text`:t+=n.content.length;break;case`code`:t+=n.content.length;break;case`image`:t+=n.alt.length;break;case`bold`:case`italic`:case`strikethrough`:case`link`:t+=mp(n.children);break;case`break`:t+=1;break;case`citation`:t+=1}return t}function hp(e){let t=0;for(let n of e)switch(n.type){case`heading`:case`paragraph`:t+=mp(n.children);break;case`codeblock`:t+=n.content.length;break;case`blockquote`:t+=hp(n.children);break;case`list`:for(let e of n.items)t+=hp(e.children);break;case`table`:for(let e of n.headers)t+=mp(e.children);for(let e of n.rows)for(let n of e)t+=mp(n.children);break;case`hr`:break;case`image`:t+=n.alt.length}return t}var gp={1:$.h1,2:$.h2,3:$.h3,4:$.h4,5:$.h5,6:$.h6},_p=/^(javascript|data|vbscript):/i;function vp(e){let t=e.trim();return t.length===0||_p.test(t)?null:t}function yp(e,t){let n=[];for(let r of t){r.pattern.lastIndex=0;let t;for(;(t=r.pattern.exec(e))!==null;){let i;if(r.getEndIndex){let n=r.getEndIndex(e,t);if(n===!1)continue;i=n}else i=t.index+t[0].length;n.push({start:t.index,end:i,match:t,plugin:r})}}n.sort((e,t)=>e.start-t.start);let r=[],i=0;for(let e of n)e.start>=i&&(r.push(e),i=e.end);if(r.length===0)return[{type:`text`,content:e}];let a=[],o=0;for(let t=0;t<r.length;t++){let n=r[t];n.start>o&&a.push({type:`text`,content:e.slice(o,n.start)}),a.push({type:`plugin`,element:n.plugin.render(n.match,`plugin-${t}`),matchLength:n.end-n.start}),o=n.end}return o<e.length&&a.push({type:`text`,content:e.slice(o)}),a}function bp(e,t,n){let r=t.offset;if(t.offset+=e.length,!t.active)return e;let i=sf(e,r,t.boundaries,n);if(i==null)return e;let a=i.map(e=>e.fading?(0,B.jsx)(`span`,{className:`x1hc1fzr x19991ni x80gvsz x12w9bfk xlr8y92 x4itv7f`,children:e.text},e.key):(0,B.jsx)(`span`,{children:e.text},e.key));return(0,B.jsx)(`span`,{children:a},`wrap-${n}`)}function xp(e,t){let n=e.numberMap.get(t);return n??(n=e.nextNumber++,e.numberMap.set(t,n)),n}function Sp(e,t,n,r,i,a=`a`,o,s){switch(e.type){case`text`:if(o&&o.length>0){let n=yp(e.content,o);if(n.length!==1||n[0].type!==`text`){let e=[];for(let i=0;i<n.length;i++){let a=n[i];a.type===`text`?e.push(bp(a.content,r,`${t}-seg-${i}`)):(r.offset+=a.matchLength,e.push((0,B.jsx)(v.Fragment,{children:a.element},`plugin-${t}-${i}`)))}return(0,B.jsx)(v.Fragment,{children:e},t)}}return bp(e.content,r,t);case`bold`:return(0,B.jsx)(`strong`,{className:`x2mo6ok`,children:e.children.map((e,t)=>Sp(e,t,n,r,i,a,o,s))},t);case`italic`:return(0,B.jsx)(`em`,{children:e.children.map((e,t)=>Sp(e,t,n,r,i,a,o,s))},t);case`strikethrough`:return(0,B.jsx)(`del`,{className:`xv1l7n4`,children:e.children.map((e,t)=>Sp(e,t,n,r,i,a,o,s))},t);case`code`:{r.offset+=e.content.length;let n=s?.inlineCode;return n?(0,B.jsx)(n,{children:e.content},t):(0,B.jsx)(pc,{children:e.content},t)}case`link`:{let c=vp(e.href);if(c==null)return(0,B.jsx)(`span`,{children:e.children.map((e,t)=>Sp(e,t,n,r,i,a,o,s))},t);let l=s?.link;if(l)return(0,B.jsx)(l,{href:c,children:e.children.map((e,t)=>Sp(e,t,n,r,i,a,o,s))},t);let u=c.startsWith(`https://`)||c.startsWith(`http://`);return(0,B.jsx)(u?`a`:a,{href:c,onClick:n?e=>{n(c,e)===!1&&e.preventDefault()}:void 0,...u?{target:`_blank`,rel:`noopener noreferrer`}:{},className:`xjse4m1 x1bvjpef`,children:e.children.map((e,t)=>Sp(e,t,n,r,i,a,o,s))},t)}case`image`:{let n=vp(e.src);if(n==null)return(0,B.jsxs)(`span`,{children:[`[`,e.alt,`]`]},t);let r=s?.image;return r?(0,B.jsx)(r,{src:n,alt:e.alt},t):(0,B.jsx)(`img`,{src:n,alt:e.alt,className:`x193iq5w xh6dtrn`},t)}case`break`:return r.offset+=1,(0,B.jsx)(`br`,{},t);case`citation`:{if(r.offset+=1,!i)return(0,B.jsxs)(`span`,{children:[`[`,e.sourceId,`]`]},t);let n=xp(i,e.sourceId),a=i.sources[e.sourceId]??{title:e.sourceId},o=i.style===`number`?`number`:`label`,c=s?.citation;return c?(0,B.jsx)(c,{source:a,number:n,variant:o},t):(0,B.jsx)(lf,{source:a,number:n,variant:o},t)}}}function Cp(e,t){let n=t===`compact`;switch(e.type){case`heading`:return e.level<=3?n?$.spacingHeadingMajorCompact:$.spacingHeadingMajorDefault:n?$.spacingHeadingMinorCompact:$.spacingHeadingMinorDefault;case`paragraph`:return n?$.spacingParagraphCompact:$.spacingParagraphDefault;case`codeblock`:return n?$.spacingCodeblockCompact:$.spacingCodeblockDefault;case`blockquote`:return n?$.spacingBlockquoteCompact:$.spacingBlockquoteDefault;case`list`:return n?$.spacingListCompact:$.spacingListDefault;case`table`:return n?$.spacingTableCompact:$.spacingTableDefault;case`hr`:return n?$.spacingHrCompact:$.spacingHrDefault;case`image`:return n?$.spacingImageCompact:$.spacingImageDefault}}function wp(e){return e.headers.map((t,n)=>{let r=mp(t.children);for(let t of e.rows)if(t[n]){let e=mp(t[n].children);e>r&&(r=e)}return r<=6?60:r<=15?80:120})}function Tp(e,t,n,r,i,a,o,s,c,l,u=`a`,d,f,p){let m=lp[l],h=m==null?null:dp.blockAlign(m),g=Cp(e,r),_=t===0,v=t===n-1;switch(e.type){case`heading`:{let n=Math.min(e.level+i-1,6),p=e.children.map((e,t)=>Sp(e,t,a,o,s,u,d,f)),m=f?.heading;if(m)return(0,B.jsx)(m,{level:n,children:p},t);let h=`h${n}`;return(0,B.jsx)(h,{...H(U(`markdown-heading`,{density:r,level:n}),w($.headingBase,gp[n],g,c==null?null:dp.proseWidth(c),l===`start`?null:dp.proseAlign(cp[l]),_&&$.noMarginBlockStart,v&&$.noMarginBlockEnd)),children:p},t)}case`paragraph`:{let n=e.children.map((e,t)=>Sp(e,t,a,o,s,u,d,f)),i=f?.paragraph;return i?(0,B.jsx)(i,{children:n},t):(0,B.jsx)(`div`,{role:`paragraph`,...H(U(`markdown-paragraph`,{density:r}),w(g,c==null?null:dp.proseWidth(c),l===`start`?null:dp.proseAlign(cp[l]),_&&$.noMarginBlockStart,v&&$.noMarginBlockEnd)),children:n},t)}case`codeblock`:{o.offset+=e.content.length;let n=f?.code;return n?(0,B.jsx)(n,{code:e.content,language:e.language},t):(0,B.jsx)(`div`,{...H(U(`markdown-codeblock`,{density:r}),w(g,$.codeBlockWrapper,_&&$.noMarginBlockStart,v&&$.noMarginBlockEnd)),children:(0,B.jsx)(lc,{code:e.content,language:e.language,isCollapsible:!0,xstyle:[c==null?void 0:dp.blockWidth(c),h]})},t)}case`blockquote`:{let n=f?.blockquote;if(n){let m=e.children.map((t,n)=>Tp(t,n,e.children.length,r,i,a,o,s,c,l,u,d,f,p));return(0,B.jsx)(n,{children:m},t)}return(0,B.jsx)(Su,{...U(`markdown-blockquote`,{density:r}),xstyle:[g,c==null?void 0:dp.proseWidth(c),l===`start`?void 0:dp.proseAlign(cp[l]),_&&$.noMarginBlockStart,v&&$.noMarginBlockEnd],children:e.children.map((t,n)=>Tp(t,n,e.children.length,r,i,a,o,s,c,l,u,d,f,p))},t)}case`list`:if(e.items.length>0&&e.items.every(e=>e.checked!=null)){let n=e.items.map((e,t)=>({item:e,key:`task-${t}`})).filter(({item:e})=>e.checked).map(({key:e})=>e);return(0,B.jsx)(`div`,{...H(U(`markdown-list`,{density:r}),w(g,_&&$.noMarginBlockStart,v&&$.noMarginBlockEnd)),children:(0,B.jsx)(Bl,{label:p(`@astryx.markdown.taskList`),isLabelHidden:!0,value:n,xstyle:$.blockIndent,isReadOnly:!0,density:`compact`,children:e.items.map((e,t)=>{let n=e.children[0],m=e.children.length===1&&n?.type===`paragraph`?(0,B.jsx)(B.Fragment,{children:n.children.map((e,t)=>Sp(e,t,a,o,s,u,d,f))}):(0,B.jsx)(B.Fragment,{children:e.children.map((t,n)=>Tp(t,n,e.children.length,r,i,a,o,s,c,l,u,d,f,p))});return(0,B.jsx)(bu,{value:`task-${t}`,label:m},t)})})},t)}return(0,B.jsx)(`div`,{...H(U(`markdown-list`,{density:r}),w(g,c==null?null:dp.proseWidth(c),l===`start`?null:dp.proseAlign(cp[l]),_&&$.noMarginBlockStart,v&&$.noMarginBlockEnd)),children:(0,B.jsx)(Y,{listStyle:e.ordered?`decimal`:`disc`,density:`compact`,start:e.ordered?e.start:void 0,xstyle:$.blockIndent,children:e.items.map((e,t)=>{let n=e.children[0],m=e.children.length===1&&n?.type===`paragraph`?(0,B.jsx)(B.Fragment,{children:n.children.map((e,t)=>Sp(e,t,a,o,s,u,d,f))}):(0,B.jsx)(B.Fragment,{children:e.children.map((t,n)=>Tp(t,n,e.children.length,r,i,a,o,s,c,l,u,d,f,p))});return(0,B.jsx)(vu,{label:m},t)})})},t);case`table`:{let n=wp(e);return(0,B.jsx)(`div`,{tabIndex:0,role:`group`,"aria-label":p(`@astryx.markdown.table`),...H(U(`markdown-table`,{density:r}),w($.tableWrapper,g,c==null?null:dp.blockWidth(c),lp[l]==null?null:dp.blockAlign(lp[l]),_&&$.noMarginBlockStart,v&&$.noMarginBlockEnd)),children:(0,B.jsxs)(af,{dividers:`rows`,textOverflow:`wrap`,children:[(0,B.jsx)(Nd,{children:(0,B.jsx)(Bu,{children:e.headers.map((t,r)=>(0,B.jsx)(Md,{xstyle:[dp.cellMinWidth(`${n[r]}px`),e.alignments[r]===`center`&&fp.center,e.alignments[r]===`right`&&fp.end],children:t.children.map((e,t)=>Sp(e,t,a,o,s,u,d,f))},r))})}),(0,B.jsx)(Pd,{children:e.rows.map((t,n)=>{let r=t.map((t,n)=>(0,B.jsx)(Dd,{xstyle:[e.alignments[n]===`center`&&fp.center,e.alignments[n]===`right`&&fp.end],children:t.children.map((e,t)=>Sp(e,t,a,o,s,u,d,f))},n));return(0,B.jsx)(Bu,{children:r},n)})})]})},t)}case`hr`:{let e=f?.hr;return e?(0,B.jsx)(e,{},t):(0,B.jsx)(`hr`,{...H(U(`markdown-hr`,{density:r}),w($.hr,g,_&&$.noMarginBlockStart,v&&$.noMarginBlockEnd))},t)}case`image`:{let n=vp(e.src);if(n==null)return(0,B.jsxs)(`div`,{...H(U(`markdown-image`,{density:r}),w(g,_&&$.noMarginBlockStart,v&&$.noMarginBlockEnd)),children:[`[`,e.alt,`]`]},t);let i=f?.image;return i?(0,B.jsx)(i,{src:n,alt:e.alt},t):(0,B.jsx)(`div`,{...H(U(`markdown-image`,{density:r}),w(g,_&&$.noMarginBlockStart,v&&$.noMarginBlockEnd)),children:(0,B.jsx)(`img`,{src:n,alt:e.alt,className:`x193iq5w xh6dtrn`})},t)}}}function Ep({ref:e,children:t,display:n=`block`,density:r=`default`,headingLevelStart:i=1,isStreaming:a=!1,onLinkClick:o,sources:s,citationStyle:c=`label`,contentWidth:l=680,contentAlign:u=`start`,components:d,inlinePlugins:f,autolink:p,xstyle:m,className:h,style:g,"data-testid":_}){let y=ds(),b=Pa(),x=(0,v.useMemo)(()=>s?new Set(Object.keys(s)):void 0,[s]),S=(0,v.useMemo)(()=>({sourceIds:x,autolink:p}),[x,p]),C=pl(t,a),T=(0,v.useRef)(np()),E=(0,v.useRef)(p);E.current!==p&&(T.current=np(),E.current=p);let D=(0,v.useMemo)(()=>n===`inline`?[]:a?C===``?(T.current=np(),[]):sp(ip(C),T.current,S):ep(t,S),[n,C,t,a,S]),O=(0,v.useMemo)(()=>n===`inline`?wf(a?ip(C):t,S):[],[n,C,t,a,S]),{token:k}=xt(),A=(0,v.useMemo)(()=>{let e=pp(k(`--duration-fast-max`))??230,t=pp(k(`--duration-fast-min`)),n=t==null?50:Math.max(4,Math.round(t/10));return Math.min(Math.ceil(e/n),12)},[k]),j=(0,v.useRef)([]),M=(0,v.useRef)([]),N=(0,v.useRef)([]),ee=C.length,P={offset:0,boundaries:(0,v.useMemo)(()=>{let e=n===`inline`?mp(M.current):hp(j.current),t=of(N.current,e,A);return N.current=t,t},[n,ee,A]),active:a},F=s?{sources:s,numberMap:new Map,nextNumber:1,style:c}:null;if(n===`inline`){let t=(0,B.jsx)(`span`,{ref:e,"data-testid":_,...H(U(`markdown`,{density:r}),w($.root,$.inlineRoot,m),h,g),children:O.map((e,t)=>Sp(e,t,o,P,F,b,f,d))});return M.current=O,j.current=[],t}let I=(0,B.jsx)(`div`,{role:`document`,ref:e,"data-testid":_,...H(U(`markdown`,{density:r}),w($.root,m),h,g),children:D.map((e,t)=>Tp(e,t,D.length,r,i,o,P,F,l?typeof l==`number`?`${l}px`:l:null,u,b,f,d,y))});return j.current=D,M.current=[],I}Ep.displayName=`Markdown`;function Dp(e){return e.split(`/`).pop()??e}function Op(e){let t=e.split(`/`);return t.length<=1?``:t.slice(0,-1).join(`/`)}function kp(e){let t=e.toLowerCase();return t.endsWith(`.md`)||t.endsWith(`.markdown`)}function Ap(e){let t=e.split(`/`).pop()??e;return/\.(png|jpe?g|gif|webp)$/i.test(t)}function jp(e){let t=e.toLowerCase();return t.endsWith(`.md`)||t.endsWith(`.markdown`)?`markdown`:t.endsWith(`.json`)?`json`:t.endsWith(`.yaml`)||t.endsWith(`.yml`)?`yaml`:t.endsWith(`.ts`)||t.endsWith(`.tsx`)?`typescript`:t.endsWith(`.js`)||t.endsWith(`.jsx`)?`javascript`:t.endsWith(`.py`)?`python`:t.endsWith(`.sh`)?`bash`:t.endsWith(`.html`)?`html`:t.endsWith(`.css`)?`css`:(t.endsWith(`.txt`),`plaintext`)}function Mp({runId:e,path:t,readOnly:n,onBackToTranscript:r,onHide:i}){let a=kp(t),o=Ap(t),[s,c]=(0,v.useState)(a||o?`rendered`:`raw`),[l,u]=(0,v.useState)({status:`loading`});return(0,v.useEffect)(()=>{c(kp(t)||Ap(t)?`rendered`:`raw`)},[t]),(0,v.useEffect)(()=>{if(Ap(t)){u({status:`ready`,content:``});return}let n=!1;return u({status:`loading`}),ar(e,t).then(e=>{n||u({status:`ready`,content:e})}).catch(e=>{n||u({status:`error`,message:e instanceof Error?e.message:String(e)})}),()=>{n=!0}},[e,t]),(0,B.jsxs)(`div`,{className:`reader`,style:{height:`100%`},children:[(0,B.jsxs)(`div`,{className:`reader__bar`,children:[(0,B.jsx)(`span`,{className:`reader__name`,children:Dp(t)}),Op(t)?(0,B.jsx)(`span`,{className:`reader__path`,children:Op(t)}):null,n?(0,B.jsx)(`span`,{className:`chip`,children:`read only`}):null,(0,B.jsx)(`span`,{className:`topbar__spacer`}),(0,B.jsxs)(`div`,{className:`stream__head-trail`,children:[(0,B.jsx)(`button`,{className:`btn btn--ghost btn--sm`,onClick:r,children:`← Transcript`}),i?(0,B.jsx)(`button`,{type:`button`,className:`btn btn--sm`,onClick:i,children:`Hide workspace`}):null,(0,B.jsxs)(`div`,{className:`seg`,children:[(0,B.jsx)(`button`,{"data-active":s===`rendered`?`true`:void 0,disabled:!a&&!o,onClick:()=>{(a||o)&&c(`rendered`)},children:`Rendered`}),(0,B.jsx)(`button`,{"data-active":s===`raw`?`true`:void 0,disabled:o,onClick:()=>{o||c(`raw`)},children:`Raw`}),(0,B.jsx)(`button`,{disabled:!0,children:`Diff`})]})]})]}),(0,B.jsxs)(`div`,{className:`reader__body`,children:[l.status===`loading`?(0,B.jsx)(`p`,{className:`muted`,style:{padding:`var(--spacing-6)`},children:`Loading…`}):null,l.status===`error`?(0,B.jsx)(`div`,{style:{padding:`var(--spacing-6)`},children:(0,B.jsxs)(`div`,{className:`gate`,style:{padding:`var(--spacing-4)`,borderColor:`var(--color-border-red)`,borderLeftColor:`var(--color-error)`,background:`var(--color-background-red)`,color:`var(--color-text-red)`},children:[(0,B.jsx)(`div`,{className:`gate__label`,style:{color:`var(--color-text-red)`},children:`Could not load artifact`}),(0,B.jsx)(`p`,{className:`gate__question`,style:{color:`var(--color-text-primary)`},children:l.message})]})}):null,l.status===`ready`?(0,B.jsx)(`div`,{className:`page`,children:o?(0,B.jsx)(`img`,{src:`/api/runs/${encodeURIComponent(e)}/artifact?path=${encodeURIComponent(t)}`,alt:Dp(t),style:{maxWidth:`100%`,height:`auto`,display:`block`}}):s===`rendered`&&a?l.content.trim().length===0?(0,B.jsx)(`p`,{className:`muted`,children:`Empty file.`}):(0,B.jsx)(Ep,{headingLevelStart:2,contentWidth:`76ch`,children:l.content}):(0,B.jsx)(lc,{code:l.content,language:jp(t),title:Dp(t),container:`section`,width:`100%`})}):null]})]})}function Np({question:e,note:t,onNoteChange:n,onAccept:r,onReject:i,isSubmitting:a,error:o,refs:s,children:c}){let l=!!a;return(0,B.jsxs)(`div`,{className:`decide`,style:{height:`100%`},children:[(0,B.jsxs)(`div`,{className:`decide__gate`,children:[(0,B.jsxs)(`div`,{className:`decide__label`,children:[(0,B.jsx)(`span`,{className:`dot dot--waiting`}),Ur(),` · artifact_backed`]}),(0,B.jsx)(`p`,{className:`decide__q`,children:e}),s?(0,B.jsx)(`div`,{className:`decide__refs`,children:s}):null,o?(0,B.jsx)(`div`,{className:`gate`,style:{padding:`var(--spacing-3)`,marginBottom:`var(--spacing-3)`,borderColor:`var(--color-border-red)`,borderLeftColor:`var(--color-error)`,background:`var(--color-background-red)`,color:`var(--color-text-red)`},children:(0,B.jsxs)(`p`,{style:{margin:0,fontSize:`var(--font-size-sm)`},children:[`Could not submit answer: `,o]})}):null,(0,B.jsx)(`textarea`,{value:t,onChange:e=>n(e.target.value),disabled:l,placeholder:`Optional review notes`,rows:3}),(0,B.jsxs)(`div`,{className:`decide__buttons`,children:[(0,B.jsx)(`button`,{className:`btn btn--accept`,disabled:l,onClick:r,children:a?`Submitting…`:`Accept`}),(0,B.jsx)(`button`,{className:`btn btn--reject`,disabled:l,onClick:i,children:`Reject`})]})]}),c?(0,B.jsx)(`div`,{className:`decide__body`,children:c}):null]})}function Pp(e){if(!e||typeof e!=`object`)return null;let t=e.kind;return t===`free_text`||t===`confirm`||t===`multi_question`||t===`artifact_backed`?e:null}function Fp(e){if(!e||typeof e!=`object`)return null;let t=e.kind;return t===`free_text`||t===`confirm`||t===`multi_question`||t===`artifact_backed`?e:null}function Ip(e){let t=0;for(let n of e)n.event===`operator_prompt`&&Pp(n.prompt)?.kind===`artifact_backed`&&(t+=1);return Math.max(t,1)}function Lp(e){let t=[];return e.forEach((e,n)=>{if(e.event===`operator_prompt`){t.push({key:`ask-${e.at??n}`,label:`Asked you`,at:e.at});return}if(e.event!==`operator_answer`)return;let r=Fp(e.answer),i=`Answered`,a;r?.kind===`artifact_backed`||r?.kind===`confirm`?(i=r.decision===`reject`?`Rejected`:`Accepted`,a=r.text):r?.kind===`free_text`&&(a=r.text),t.push({key:`ans-${e.at??n}`,label:i,at:e.at,note:a})}),t}function Rp(e){if(!e)return``;try{let t=new Date(e),n=Math.round((Date.now()-t.getTime())/1e3);return n<60?`just now`:n<3600?`${Math.floor(n/60)}m ago`:n<86400?`${Math.floor(n/3600)}h ago`:t.toLocaleDateString()}catch{return``}}function zp({runId:e,stageId:t,prompt:n,events:r,inboundEnvelope:i,inboundFromStageId:a,inboundToStageId:o,selectedPath:s,onSelectArtifact:c,onOpenInboundEnvelope:l}){let[u,d]=(0,v.useState)(``),{submitting:f,error:p,locked:m,submitIntent:h}=zc(e,t,{promptId:n.id,kind:n.kind}),g=Ip(r),_=Lp(r);async function y(e){await h({type:`decision`,decision:e,note:u})}let b=a&&o?`${a} → ${o}`:a??`previous stage`;return(0,B.jsxs)(Np,{question:n.message,note:u,onNoteChange:d,onAccept:()=>void y(`accept`),onReject:()=>void y(`reject`),isSubmitting:f||m,error:p,refs:n.artifacts.length>0?(0,B.jsx)(B.Fragment,{children:n.artifacts.map(e=>(0,B.jsx)(`button`,{className:`chip${e===s?` chip--active`:``}`,onClick:()=>c(e),style:e===s?{borderColor:`var(--color-warning)`,background:`var(--color-background-yellow)`}:void 0,children:e.split(`/`).pop()??e},e))}):void 0,children:[(0,B.jsxs)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`},children:[`Iteration `,g,`. A rejection returns to the same live session, which revises this file and asks again — the stage is not restarted.`]}),_.length>0?(0,B.jsxs)(`div`,{style:{marginTop:`var(--spacing-3)`},children:[(0,B.jsx)(`strong`,{style:{fontSize:`var(--font-size-sm)`},children:`Review history`}),_.map(e=>(0,B.jsxs)(`div`,{style:{marginTop:`var(--spacing-2)`},children:[(0,B.jsx)(`span`,{style:{fontSize:`var(--font-size-sm)`,fontWeight:500},children:e.label}),e.at?(0,B.jsx)(`span`,{className:`muted`,style:{fontSize:`var(--font-size-xs)`,marginLeft:`var(--spacing-2)`,fontFamily:`var(--font-family-code)`},children:Rp(e.at)}):null,e.note?(0,B.jsx)(`p`,{className:`muted`,style:{margin:`2px 0 0`,fontSize:`var(--font-size-sm)`},children:e.note}):null]},e.key))]}):null,i?(0,B.jsxs)(`div`,{style:{marginTop:`var(--spacing-3)`},children:[(0,B.jsx)(`strong`,{style:{fontSize:`var(--font-size-sm)`},children:`Inbound context`}),(0,B.jsx)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`,margin:`2px 0 var(--spacing-2)`},children:i.summary}),l?(0,B.jsx)(`button`,{className:`btn btn--ghost btn--sm`,onClick:l,children:b}):(0,B.jsx)(`span`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`},children:b})]}):null]})}function Bp({envelope:e,onArtifactClick:t,payloadMaxHeight:n=280}){return(0,B.jsxs)(`div`,{className:`drawer__grid`,children:[(0,B.jsxs)(`dl`,{className:`kv`,children:[(0,B.jsx)(`dt`,{children:`Summary`}),(0,B.jsx)(`dd`,{children:e.summary}),(0,B.jsx)(`dt`,{children:`Artifacts`}),(0,B.jsx)(`dd`,{children:e.artifacts.length===0?(0,B.jsx)(`span`,{className:`muted`,children:`none`}):e.artifacts.map(e=>{let n=e.split(`/`).pop()??e;return t?(0,B.jsxs)(`button`,{type:`button`,className:`chip chip--file`,onClick:()=>t(e),children:[`◆ `,n]},e):(0,B.jsxs)(`span`,{className:`chip chip--file`,children:[`◆ `,n]},e)})}),e.notes?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`dt`,{children:`Notes`}),(0,B.jsx)(`dd`,{className:`muted`,children:e.notes})]}):null]}),e.payload?(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`div`,{className:`eyebrow`,style:{marginBottom:`var(--spacing-2)`},children:`payload`}),(0,B.jsx)(lc,{code:JSON.stringify(e.payload,null,2),language:`json`,container:`section`,maxHeight:n,width:`100%`})]}):(0,B.jsx)(`p`,{className:`muted`,children:`No payload.`})]})}function Vp(e,t,n){let r=e=>n?.(e)??e;return t?`${r(e)} → ${r(t)}`:r(e)}function Hp({fromStageId:e,toStageId:t,envelope:n,onBackToTranscript:r,onHide:i,onArtifactClick:a,stageLabel:o}){let s=Vp(e,t,o);return(0,B.jsxs)(`div`,{className:`stream`,style:{height:`100%`},children:[(0,B.jsxs)(`header`,{className:`stream__head`,children:[(0,B.jsx)(`h3`,{className:`stream__name`,children:`Handoff envelope`}),(0,B.jsx)(`span`,{className:`mono muted`,children:s}),(0,B.jsx)(`span`,{className:`topbar__spacer`}),(0,B.jsxs)(`div`,{className:`stream__head-trail`,children:[(0,B.jsx)(`button`,{type:`button`,className:`btn btn--sm`,onClick:r,children:`← Transcript`}),i?(0,B.jsx)(`button`,{type:`button`,className:`btn btn--sm`,onClick:i,children:`Hide workspace`}):null]})]}),(0,B.jsx)(`div`,{className:`stream__body`,children:(0,B.jsx)(Bp,{envelope:n,onArtifactClick:a,payloadMaxHeight:480})})]})}function Up(e){return e===`success`?`status status--succeeded`:e===`failure`?`status status--failed`:`status`}function Wp(e){return e===`success`?`dot dot--succeeded`:e===`failure`?`dot dot--failed`:`dot`}function Gp({isOpen:e,onClose:t,fromStageId:n,toStageId:r,envelope:i,onOpenFullRecord:a,onArtifactClick:o}){let s=r?`${n} → ${r}`:n;return(0,v.useEffect)(()=>{if(!e)return;function n(e){e.key===`Escape`&&t()}return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,t]),(0,B.jsxs)(`aside`,{className:`drawer`,hidden:!e,children:[(0,B.jsxs)(`div`,{className:`drawer__head`,children:[(0,B.jsx)(`span`,{className:`eyebrow`,children:`Handoff envelope`}),(0,B.jsx)(`span`,{className:`mono muted`,children:s}),(0,B.jsxs)(`span`,{className:Up(i.status),children:[(0,B.jsx)(`span`,{className:Wp(i.status)}),` `,i.status]}),(0,B.jsx)(`span`,{style:{marginLeft:`auto`}}),a?(0,B.jsx)(`button`,{type:`button`,className:`btn btn--sm`,onClick:a,children:`Open full record`}):null,(0,B.jsx)(`button`,{type:`button`,className:`btn btn--sm`,onClick:t,children:`Close`})]}),(0,B.jsx)(Bp,{envelope:i,onArtifactClick:o})]})}function Kp(e){let t={submitting:!1,error:null},n=new Set,r=()=>t,i=()=>{for(let e of n)e()};return{getState:r,decide:async(n,r)=>{if(!t.submitting){t={submitting:!0,error:null},i();try{await e.submit(n,r),await e.onSuccess()}catch(e){t={...t,error:e instanceof Error?e.message:String(e)}}finally{t={...t,submitting:!1},i()}}},clearError:()=>{t.error!==null&&(t={...t,error:null},i())},subscribe:e=>(n.add(e),()=>{n.delete(e)})}}function qp(e,t){let n=(0,v.useRef)(e);n.current=e;let r=(0,v.useRef)(t);r.current=t;let i=(0,v.useRef)(null);i.current===null&&(i.current=Kp({submit:async(e,t)=>{await nr(n.current,e,t)},onSuccess:()=>r.current()}));let a=i.current,[o,s]=(0,v.useState)(()=>a.getState());(0,v.useEffect)(()=>a.subscribe(()=>s(a.getState())),[a]);let c=(0,v.useCallback)((e,t)=>void a.decide(e,t),[a]),l=(0,v.useCallback)(()=>a.clearError(),[a]);return{submitting:o.submitting,error:o.error,decide:c,clearError:l}}function Jp({runId:e,decide:t,onSuccess:n}){let[r,i]=(0,v.useState)(``),{submitting:a,error:o,decide:s}=qp(e,n),c=a,l=t.replayNumber!==void 0&&t.maxReplays!==void 0?`Replay ${t.replayNumber} of ${t.maxReplays}`:t.maxReplays===void 0?null:`Max ${t.maxReplays} replays`;function u(e){let n=r.trim();s(t.sourceStageId,{decision:e,loopId:t.loopId,...n?{reason:n}:{}})}return(0,B.jsx)(`div`,{className:`decide feedback-decide`,style:{height:`100%`},children:(0,B.jsxs)(`div`,{className:`decide__gate`,children:[(0,B.jsxs)(`div`,{className:`decide__label`,children:[(0,B.jsx)(`span`,{className:`dot dot--waiting`}),Ur(),` · feedback_loop_decision`]}),(0,B.jsx)(`p`,{className:`decide__q`,children:t.summary??`Feedback loop limit reached — extend, continue, or abandon`}),(0,B.jsxs)(`div`,{className:`decide__refs`,children:[(0,B.jsxs)(`span`,{children:[`Source `,(0,B.jsx)(`strong`,{children:t.sourceStageId})]}),t.deferredTarget?(0,B.jsxs)(`span`,{children:[`Target `,(0,B.jsx)(`strong`,{children:t.deferredTarget})]}):null,l?(0,B.jsx)(`span`,{children:l}):null]}),o?(0,B.jsx)(`div`,{className:`gate`,style:{padding:`var(--spacing-3)`,marginBottom:`var(--spacing-3)`,borderColor:`var(--color-border-red)`,borderLeftColor:`var(--color-error)`,background:`var(--color-background-red)`,color:`var(--color-text-red)`},children:(0,B.jsxs)(`p`,{style:{margin:0,fontSize:`var(--font-size-sm)`},children:[`Could not submit decision: `,o]})}):null,(0,B.jsx)(`textarea`,{value:r,onChange:e=>i(e.target.value),disabled:c,placeholder:`Optional reason`,rows:3}),(0,B.jsxs)(`div`,{className:`decide__buttons`,children:[(0,B.jsx)(`button`,{className:`btn btn--accept`,disabled:c,onClick:()=>u(`extend`),children:a?`Submitting…`:`Extend`}),(0,B.jsx)(`button`,{className:`btn btn--primary`,disabled:c,onClick:()=>u(`continue`),children:`Continue`}),(0,B.jsx)(`button`,{className:`btn btn--reject`,disabled:c,onClick:()=>u(`abandon`),children:`Abandon`})]}),(0,B.jsx)(`p`,{className:`decide__hint`,children:`Extend raises the replay budget and continues the deferred send-back. Continue accepts the limit and advances. Abandon stops the loop.`})]})})}function Yp(e){return`Replay ${e.current_replay_number??0} of ${e.policy.max_replays}`}function Xp(e){for(let t=e.length-1;t>=0;t--){let n=e[t]?.replays;if(!n||n.length===0)continue;let r=n[n.length-1]?.replay;if(r?.target_stage_id)return r.target_stage_id}return null}function Zp(e,t){let n=e.deferred_send_back?.target??Xp(t)??e.policy.target??null;return n?`${e.source_stage_id} → ${n}`:null}function Qp(e){switch(e){case`waiting_for_human`:return`status status--waiting`;case`completed`:case`continued`:return`status status--succeeded`;case`abandoned`:return`status status--failed`;default:return`status`}}function $p({active:e,history:t}){if(!e&&t.length===0)return null;let n=e??t[t.length-1]?.loop,r=n?Zp(n,t):null,i=n?r??Yp(n):null,a=n?.state===`waiting_for_human`,o=t.flatMap(e=>e.replays),s=t.reduce((e,t)=>{let n=t.fork_generations.filter(e=>e.status===`superseded`).length;for(let e of t.replays)n+=e.fork_generations.filter(e=>e.status===`superseded`).length;return e+n},0);return(0,B.jsx)(`section`,{className:`feedback-loop-panel block`,children:(0,B.jsx)(xc,{trigger:(0,B.jsxs)(`span`,{className:`feedback-loop-panel__trigger`,children:[(0,B.jsx)(`span`,{className:`block__pipeline`,children:`Feedback loop`}),n?(0,B.jsx)(`span`,{className:Qp(n.state),children:n.state.replaceAll(`_`,` `)}):null,i?(0,B.jsx)(`span`,{className:`feedback-loop-panel__summary`,children:i}):null]}),defaultIsOpen:a,children:(0,B.jsxs)(`div`,{className:`feedback-loop-panel__body`,children:[n?(0,B.jsxs)(`dl`,{className:`kv`,children:[(0,B.jsx)(`dt`,{children:`Budget`}),(0,B.jsx)(`dd`,{children:Yp(n)}),r?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`dt`,{children:`Route`}),(0,B.jsx)(`dd`,{children:r})]}):null,(0,B.jsx)(`dt`,{children:`Session`}),(0,B.jsx)(`dd`,{children:n.policy.replay_session})]}):null,o.length>0?(0,B.jsxs)(`div`,{className:`feedback-loop-panel__timeline`,children:[(0,B.jsx)(`div`,{className:`decide__label`,children:`Replay timeline`}),(0,B.jsx)(`ol`,{className:`feedback-loop-panel__list`,children:o.map(({replay:e,stage_passes:t})=>(0,B.jsxs)(`li`,{children:[(0,B.jsxs)(`span`,{children:[`#`,e.replay_number,` `,e.source_stage_id,` →`,` `,e.target_stage_id]}),(0,B.jsxs)(`span`,{className:`feedback-loop-panel__status`,children:[e.status.replaceAll(`_`,` `),t.length>0?` · ${t.length} stage pass${t.length===1?``:`es`}`:``]})]},e.replay_id))})]}):null,s>0?(0,B.jsxs)(`p`,{className:`block__sub`,children:[s,` superseded fork generation`,s===1?``:`s`,` hidden from the map.`]}):null]})},a?`waiting`:`idle`)})}var em=160;function tm(e,t=em){let n=e.trim();return n.length<=t?n:`${n.slice(0,t)}…`}function nm(e){let t=e.prompt;if(!t||typeof t!=`object`)return;let n=t;if(n.kind===`multi_question`){let e=n.questions?.length??0;return e===1?`1 question`:`${e} questions`}if(typeof n.message==`string`&&n.message.trim())return tm(n.message)}function rm(e){let t=e.answer;if(!t||typeof t!=`object`)return;let n=t;if(n.kind===`free_text`)return typeof n.text==`string`?tm(n.text):void 0;if(n.kind===`confirm`||n.kind===`artifact_backed`){let e=n.decision,t=typeof n.text==`string`&&n.text.trim()?tm(n.text):void 0;return e&&t?`${e} — ${t}`:e||t}if(n.kind===`multi_question`){let e=Object.keys(n.answers??{}).length;return e===1?`1 answer`:`${e} answers`}}function im(e){switch(e.event){case`started`:return`Stage started`;case`succeeded`:return`Stage succeeded`;case`failed`:return`Stage failed`;case`agent_start`:return`Agent started`;case`agent_end`:return`Agent settled`;case`turn_start`:return`Turn`;case`tool_start`:return`→ ${e.toolName??`tool`}`;case`tool_end`:return e.isError?`✕ ${e.toolName??`tool`}`:`✓ ${e.toolName??`tool`}`;case`tool_progress`:return`│ ${e.toolName??`tool`}`;case`message`:{let t=e.role??`message`;return e.text?`${t}: ${e.text}`:t}case`operator_prompt`:return`Operator prompt`;case`operator_answer`:return`Operator answer`;case`waiting_for_input`:return Ur();case`resumed`:return`Stage resumed`;case`feedback_loop_decided`:return`Feedback loop decided`;default:return e.event}}function am(e){let t=e.decision;if(t!==`extend`&&t!==`continue`&&t!==`abandon`)return;let n=typeof e.reason==`string`&&e.reason.trim()?tm(e.reason):void 0;return n?`${t} — ${n}`:t}function om(e){if(e.event===`tool_start`&&e.argsPreview)return e.argsPreview;if(e.event===`tool_end`&&e.resultPreview)return e.resultPreview;if(e.event===`tool_progress`&&e.textPreview)return e.textPreview;if(e.event===`failed`&&e.reason||e.event===`turn_start`&&e.reason)return e.reason;if(e.event===`operator_prompt`)return nm(e);if(e.event===`operator_answer`)return rm(e);if(e.event===`feedback_loop_decided`)return am(e)}var sm=4;function cm(e,t){return`${e.event}-${e.at??`na`}-${t}`}function lm(e){if(!e||typeof e!=`object`)return null;let t=e.kind;return t===`free_text`||t===`confirm`||t===`multi_question`||t===`artifact_backed`?e:null}function um(e){if(!e||typeof e!=`object`)return null;let t=e.kind;return t===`free_text`||t===`confirm`||t===`multi_question`||t===`artifact_backed`?e:null}function dm(e){return e===`tool_start`||e===`tool_end`||e===`tool_progress`}function fm(e){let t=[],n=[];for(let r=0;r<e.length;r++){let i=e[r];if(i.event===`tool_start`){t.push({name:i.toolName??`tool`,args:i.argsPreview,at:i.at,id:i.toolCallId??`start-${r}`});continue}if(i.event===`tool_progress`){let e=-1;if(i.toolCallId&&(e=t.findIndex(e=>e.id===i.toolCallId)),e<0&&(e=t.length>0?t.length-1:-1),e<0)continue;let n=typeof i.textPreview==`string`?i.textPreview:void 0;n!==void 0&&(t[e].progressPreview=n);continue}if(i.event===`tool_end`){let e=i.toolCallId?t.findIndex(e=>e.id===i.toolCallId):t.findIndex(e=>e.name===(i.toolName??`tool`)),r=e>=0?t.splice(e,1)[0]:void 0;n.push({name:i.toolName??r?.name??`tool`,status:i.isError?`error`:`complete`,args:r?.args,result:i.resultPreview,at:i.at??r?.at,startedAt:r?.at})}}for(let e of t)n.push({name:e.name,status:`running`,args:e.args,progressPreview:e.progressPreview,at:e.at,startedAt:e.at});return n}function pm({at:e}){return e?(0,B.jsx)(`time`,{children:Pr(e)}):null}function mm({envelope:e}){return(0,B.jsxs)(`div`,{className:`turn`,children:[(0,B.jsx)(`div`,{className:`turn__who`,children:`Envelope`}),(0,B.jsxs)(`div`,{className:`bubble`,style:{borderColor:`var(--color-border-green)`},children:[(0,B.jsx)(`p`,{children:e.summary}),e.artifacts.length>0?(0,B.jsx)(`p`,{className:`muted`,children:e.artifacts.map(e=>e.split(`/`).pop()??e).join(` · `)}):null]})]})}function hm({calls:e}){let[t,n]=(0,v.useState)(!1),r=!t&&e.length>sm?e.length-sm:0,i=r>0?e.slice(0,sm):e;return(0,B.jsxs)(`div`,{className:`tools`,children:[i.map((e,t)=>{let n=e.status===`running`?e.progressPreview:e.result;return(0,B.jsxs)(`div`,{className:e.status===`error`?`tool tool--error`:`tool`,children:[(0,B.jsxs)(`span`,{children:[e.status===`error`?`✕`:e.status===`running`?`▸`:`⚙`,` `,e.name,e.args?` ${e.args}`:``,n?` · ${n}`:``]}),(0,B.jsx)(pm,{at:e.at})]},`${e.name}-${e.at??t}`)}),r>0?(0,B.jsxs)(`button`,{type:`button`,className:`tools__more`,onClick:()=>n(!0),children:[`Show `,r,` more`]}):null]})}function gm({event:e}){let t=e.role??`message`,n=e.text?.trim();return n?(0,B.jsxs)(`div`,{className:`turn`,children:[(0,B.jsxs)(`div`,{className:`turn__who`,children:[t,(0,B.jsx)(pm,{at:e.at})]}),(0,B.jsx)(`div`,{className:`bubble`,children:(0,B.jsx)(`p`,{children:n})})]}):null}function _m({event:e}){let t=lm(e.prompt);return(0,B.jsxs)(`div`,{className:`ask`,children:[(0,B.jsxs)(`div`,{className:`ask__label`,children:[t?.kind??`ask`,(0,B.jsx)(`span`,{style:{marginLeft:`auto`},children:(0,B.jsx)(pm,{at:e.at})})]}),t?.kind===`multi_question`?(0,B.jsx)(`ol`,{className:`qlist`,children:t.questions.map(e=>(0,B.jsxs)(`li`,{children:[e.message,(0,B.jsx)(`small`,{children:e.kind})]},e.id))}):(0,B.jsx)(`p`,{className:`ask__q`,children:t&&`message`in t?t.message:om(e)})]})}function vm({event:e}){let t=um(e.answer),n,r;if(t?.kind===`free_text`)n=`answered`,r=t.text;else if(t?.kind===`confirm`||t?.kind===`artifact_backed`)n=t.decision,r=t.text;else if(t?.kind===`multi_question`){let e=Object.keys(t.answers??{}).length;n=e===1?`1 answer`:`${e} answers`}else r=om(e);let i=n===`accept`||n===`answered`||n===`reject`?n:void 0;return(0,B.jsxs)(`div`,{className:`answer`,children:[(0,B.jsxs)(`div`,{className:`turn__who`,children:[n?(0,B.jsx)(`span`,{className:`answer__verdict`,...i?{"data-v":i}:{},children:n}):(0,B.jsx)(`span`,{children:`Operator`}),(0,B.jsx)(pm,{at:e.at})]}),r?(0,B.jsx)(`p`,{children:r}):null]})}function ym({event:e}){let t=om(e),n=im(e);return(0,B.jsx)(`div`,{className:`divider-iter`,children:t?`${n} · ${t}`:n})}function bm(e){let t=[],n=0;for(;n<e.length;){let r=e[n];if(dm(r.event)){let r=[];for(;n<e.length&&dm(e[n].event);)r.push(e[n]),n+=1;let i=fm(r);i.length>0&&t.push({kind:`tools`,calls:i});continue}r.event===`message`?r.text?.trim()&&t.push({kind:`message`,event:r}):r.event===`operator_prompt`?t.push({kind:`operator_prompt`,event:r}):r.event===`operator_answer`?t.push({kind:`operator_answer`,event:r}):r.event===`turn_start`&&!om(r)||t.push({kind:`system`,event:r}),n+=1}return t}function xm({events:e,inboundEnvelope:t}){let n=[];t&&n.push((0,B.jsx)(mm,{envelope:t},`inbound-envelope`));let r=bm(e);for(let e=0;e<r.length;e++){let t=r[e];if(t.kind===`tools`){n.push((0,B.jsx)(hm,{calls:t.calls},`tools-${e}`));continue}if(t.kind===`message`){n.push((0,B.jsx)(gm,{event:t.event},cm(t.event,e)));continue}if(t.kind===`operator_prompt`){n.push((0,B.jsx)(_m,{event:t.event},cm(t.event,e)));continue}if(t.kind===`operator_answer`){n.push((0,B.jsx)(vm,{event:t.event},cm(t.event,e)));continue}n.push((0,B.jsx)(ym,{event:t.event},cm(t.event,e)))}return n.length===0?(0,B.jsx)(`p`,{className:`muted`,children:`No activity yet.`}):(0,B.jsx)(B.Fragment,{children:n})}function Sm(e){for(let t=e.length-1;t>=0;t--)if(e[t].kind===`system`&&e[t].status===`failed`)return e[t].id;if(!e.some(e=>e.kind===`system`&&e.sourceEvent===`succeeded`)){for(let t=e.length-1;t>=0;t--)if(e[t].kind===`tool`&&e[t].status===`failed`)return e[t].id}}function Cm(e,t){let n=e.find(e=>e.id===t);if(!(!n||n.kind!==`system`))return n.detail??n.label}var wm=160;function Tm(e,t){let n=e.slice(0,t),r=n.lastIndexOf(` `);return r>0?{shown:n.slice(0,r),cutIndex:r+1}:{shown:n,cutIndex:t}}function Em(e){let t=e.indexOf(`
|
|
116
|
+
`),n=t===-1?e:e.slice(0,t);if(n.length<=wm){let r=(t===-1?``:e.slice(t+1)).replace(/^\n+/,``);return{preview:n,hasMore:r.trim().length>0,rest:r}}let{shown:r,cutIndex:i}=Tm(n,wm);return{preview:`${r}…`,hasMore:!0,rest:e.slice(i).replace(/^\n+/,``)}}function Dm(e){if(e<1e3)return`<1s`;let t=Math.round(e/1e3);return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`}function Om(e,t){if(e.kind!==`tool`||!e.startedAt)return;let n=Date.parse(e.startedAt);if(Number.isNaN(n))return;if(e.status===`running`)return Math.max(0,t-n);if(!e.finishedAt)return;let r=Date.parse(e.finishedAt);if(!Number.isNaN(r))return Math.max(0,r-n)}function km(e){return e.status===`error`?`failed`:e.status===`running`?`running`:`succeeded`}var Am={read:{key:`file_path`,isPath:!0},write:{key:`file_path`,isPath:!0},edit:{key:`file_path`,isPath:!0},notebookedit:{key:`notebook_path`,isPath:!0},bash:{key:`command`,isPath:!1},grep:{key:`pattern`,isPath:!1},glob:{key:`pattern`,isPath:!1},webfetch:{key:`url`,isPath:!1},websearch:{key:`query`,isPath:!1}},jm=new Set([`read`]);function Mm(e){if(e)try{let t=JSON.parse(e);return t&&typeof t==`object`?t:void 0}catch{return}}function Nm(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function Pm(e,t){let n=Mm(e)?.[t];if(typeof n==`string`)return n;if(!e)return;let r=e.match(RegExp(`"${Nm(t)}"\\s*:\\s*"((?:[^"\\\\]|\\\\.)*)"`));return r?r[1]:void 0}function Fm(e){return e.split(`/`).pop()||e}function Im(e){let t=Am[e.name.toLowerCase()];if(!t)return e.name;let n=Pm(e.args,t.key);return typeof n!=`string`||!n.trim()?e.name:`${e.name} ${t.isPath?Fm(n):n}`}function Lm(e){if(e.status===`running`)return e.progressPreview;if(!(e.status===`complete`&&jm.has(e.name.toLowerCase())))return e.result}function Rm(e,t){return{id:t,kind:`tool`,label:Im(e),status:km(e),detail:Lm(e),at:e.at,startedAt:e.startedAt,finishedAt:e.status===`running`?void 0:e.at,defaultExpanded:!1}}function zm(e,t){return{id:t,kind:`message`,label:e.role??`message`,status:`succeeded`,detail:e.text?.trim(),at:e.at,defaultExpanded:!1}}function Bm(e,t,n){return{id:n,kind:e,label:im(t),status:e===`system`&&t.event===`failed`?`failed`:`succeeded`,detail:om(t),at:t.at,defaultExpanded:!1,sourceEvent:e===`system`?t.event:void 0}}function Vm(e){let t=bm(e),n=[],r=0;for(let e of t){if(e.kind===`tools`){for(let t of e.calls)n.push(Rm(t,`step-${r}`)),r+=1;continue}let t=`step-${r}`;r+=1,e.kind===`message`?n.push(zm(e.event,t)):e.kind===`operator_prompt`?n.push(Bm(`operator_prompt`,e.event,t)):e.kind===`operator_answer`?n.push(Bm(`operator_answer`,e.event,t)):n.push(Bm(`system`,e.event,t))}let i=Sm(n);for(let e of n)e.defaultExpanded=e.status===`running`||e.id===i;return n}function Hm({step:e,now:t,isOpen:n,onToggle:r}){let i=Om(e,t),{preview:a,hasMore:o,rest:s}=e.detail?Em(e.detail):{preview:``,hasMore:!1,rest:``};return(0,B.jsxs)(`div`,{id:`logstep-${e.id}`,className:`logstep logstep--${e.status}`,children:[(0,B.jsxs)(`button`,{type:`button`,className:`logstep__row${o?``:` logstep__row--static`}`,disabled:!o,"aria-expanded":o?n:void 0,onClick:o?()=>r(!n):void 0,children:[(0,B.jsx)(Pi,{icon:`chevronDown`,size:`sm`,className:`logstep__chevron${o?n?` logstep__chevron--open`:``:` logstep__chevron--hidden`}`}),(0,B.jsx)(`span`,{className:`dot dot--${e.status} logstep__dot`}),(0,B.jsxs)(`span`,{className:`logstep__text`,children:[(0,B.jsxs)(`span`,{className:`logstep__label-row`,children:[(0,B.jsx)(`span`,{className:`logstep__label`,children:e.label}),i===void 0?null:(0,B.jsx)(`span`,{className:`logstep__duration`,children:Dm(i)})]}),a?(0,B.jsx)(`span`,{className:`logstep__preview`,children:a}):null]})]}),o&&n?(0,B.jsx)(`pre`,{className:`logstep__detail`,children:s}):null]})}function Um(e){let t=document.getElementById(`logstep-${e}`);t&&(t.scrollIntoView({behavior:`smooth`,block:`center`}),t.classList.add(`logstep--highlight`),window.setTimeout(()=>t.classList.remove(`logstep--highlight`),1500))}function Wm({events:e,headerAction:t}){let n=Vm(e),r=Date.now(),i=Sm(n),a=Cm(n,i),[o,s]=(0,v.useState)({});return(0,B.jsxs)(`div`,{className:`stream`,style:{height:`100%`},children:[(0,B.jsxs)(`header`,{className:`stream__head`,children:[(0,B.jsx)(`h3`,{className:`stream__name`,children:`Logs`}),t?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`span`,{className:`topbar__spacer`}),(0,B.jsx)(`div`,{className:`stream__head-trail`,children:t})]}):null]}),(0,B.jsx)(`div`,{className:`stream__body`,children:n.length===0?(0,B.jsx)(`p`,{className:`muted`,children:`No activity yet.`}):(0,B.jsx)(`div`,{className:`logpanel`,children:n.map(e=>(0,B.jsx)(Hm,{step:e,now:r,isOpen:o[e.id]??e.defaultExpanded,onToggle:t=>s(n=>({...n,[e.id]:t}))},e.id))})}),a&&i?(0,B.jsxs)(`div`,{className:`logpanel__banner`,children:[(0,B.jsx)(`span`,{className:`logpanel__banner-text`,children:a}),(0,B.jsx)(`button`,{type:`button`,className:`btn btn--sm`,onClick:()=>{s(e=>{if(!(i in e))return e;let t={...e};return delete t[i],t}),Um(i)},children:`Jump to failing step`})]}):null]})}function Gm(e){let t=new Map;for(let n of e){let e=t.get(n.layer)??[];e.push(n),t.set(n.layer,e)}return[...t.keys()].sort((e,t)=>e-t).map(e=>(t.get(e)??[]).sort((e,t)=>e.layer_order-t.layer_order))}function Km(e){return Gm(e).flat()}function qm(e,t,n,r=0){return{stageId:e,x:t*520,y:r+n*340,width:400,height:128,layerIndex:t,indexInLayer:n}}function Jm(e,t){return t<=1||e>=t?0:(t-e)/2*340}function Ym(e){let t=e?.plannedStageIds??[],n=e?.liveStageIds??[];if(t.length===0)return n;let r=new Set,i=[];for(let e of t)r.add(e),i.push(e);for(let e of n)r.has(e)||i.push(e);return i}function Xm(e,t){if(!e.nodes.length){let e=Ym(t);return{nodes:e.map((e,t)=>qm(e,t,0)),edges:e.slice(1).map((t,n)=>({from:e[n],to:t}))}}let n=Gm(e.nodes),r=n.reduce((e,t)=>Math.max(e,t.length),0);return{nodes:n.flatMap((e,t)=>{let n=Jm(e.length,r);return e.map((e,r)=>qm(e.stage_id,t,r,n))}),edges:e.edges.map(e=>({from:e.from,to:e.to}))}}function Zm(e){return e===`failed`}function Qm(e){return e===`running`}function $m(e){if(e.status!==`failed`)return!1;let t;for(let n of e.events)n.event===`failed`&&(t=n.reason);return typeof t==`string`&&t.startsWith(`stage timed out after `)}function eh(e,t){return e.retryingStageIds.has(t)||e.abandoningStageId===t||(e.resumingStageIds?.has(t)??!1)}function th(e){let t={retryingStageIds:new Set,error:null},n=new Set,r=()=>t,i=()=>{for(let e of n)e()};return{getState:r,retry:async n=>{if(t.retryingStageIds.has(n))return;let r=new Set(t.retryingStageIds);r.add(n),t={retryingStageIds:r,error:null},i();try{await e.retry(n),await e.onSuccess()}catch(e){t={...t,error:e instanceof Error?e.message:String(e)}}finally{let e=new Set(t.retryingStageIds);e.delete(n),t={...t,retryingStageIds:e},i()}},clearError:()=>{t.error!==null&&(t={...t,error:null},i())},subscribe:e=>(n.add(e),()=>{n.delete(e)})}}function nh(e,t){let n=(0,v.useRef)(e);n.current=e;let r=(0,v.useRef)(t);r.current=t;let i=(0,v.useRef)(null);i.current===null&&(i.current=th({retry:async e=>{await Xn(n.current,e)},onSuccess:()=>r.current()}));let a=i.current,[o,s]=(0,v.useState)(()=>a.getState());(0,v.useEffect)(()=>a.subscribe(()=>s(a.getState())),[a]);let c=(0,v.useCallback)(e=>void a.retry(e),[a]),l=(0,v.useCallback)(()=>a.clearError(),[a]);return{retryingStageIds:o.retryingStageIds,error:o.error,retry:c,clearError:l}}function rh(e){let t={resumingStageIds:new Set,error:null},n=new Set,r=()=>t,i=()=>{for(let e of n)e()};return{getState:r,resume:async n=>{if(t.resumingStageIds.has(n))return;let r=new Set(t.resumingStageIds);r.add(n),t={resumingStageIds:r,error:null},i();try{await e.resume(n),await e.onSuccess()}catch(e){t={...t,error:e instanceof Error?e.message:String(e)}}finally{let e=new Set(t.resumingStageIds);e.delete(n),t={...t,resumingStageIds:e},i()}},clearError:()=>{t.error!==null&&(t={...t,error:null},i())},subscribe:e=>(n.add(e),()=>{n.delete(e)})}}function ih(e,t){let n=(0,v.useRef)(e);n.current=e;let r=(0,v.useRef)(t);r.current=t;let i=(0,v.useRef)(null);i.current===null&&(i.current=rh({resume:async e=>{await Zn(n.current,e)},onSuccess:()=>r.current()}));let a=i.current,[o,s]=(0,v.useState)(a.getState);(0,v.useEffect)(()=>a.subscribe(()=>s(a.getState())),[a]);let c=(0,v.useCallback)(e=>{a.resume(e)},[a]);return{resumingStageIds:o.resumingStageIds,error:o.error,resume:c,clearError:a.clearError}}function ah(e){let t={abandoningStageId:null,error:null},n=!1,r=new Set,i=()=>t,a=()=>{for(let e of r)e()};return{getState:i,abandon:async r=>{if(!n&&(e.confirm?.(r)??window.confirm(`This stage will be marked failed. Retry stage will become available.`))){n=!0,t={abandoningStageId:r,error:null},a();try{await e.abandon(r),await e.onSuccess()}catch(e){t={...t,error:e instanceof Error?e.message:String(e)}}finally{n=!1,t={...t,abandoningStageId:null},a()}}},clearError:()=>{t.error!==null&&(t={...t,error:null},a())},subscribe:e=>(r.add(e),()=>{r.delete(e)})}}function oh(e,t){let n=(0,v.useRef)(e);n.current=e;let r=(0,v.useRef)(t);r.current=t;let i=(0,v.useRef)(null);i.current===null&&(i.current=ah({abandon:async e=>{await er(n.current,e)},onSuccess:()=>r.current()}));let a=i.current,[o,s]=(0,v.useState)(()=>a.getState());(0,v.useEffect)(()=>a.subscribe(()=>s(a.getState())),[a]);let c=(0,v.useCallback)(e=>void a.abandon(e),[a]),l=(0,v.useCallback)(()=>a.clearError(),[a]);return{abandoningStageId:o.abandoningStageId,error:o.error,abandon:c,clearError:l}}var sh=.25,ch=1.8;function lh(e,t){return Math.abs(e.y+e.height/2-(t.y+t.height/2))<e.height*.75}function uh(e,t){let n=e.x+e.width/2,r=t.x+t.width/2;return Math.max(0,Math.round(Math.abs(r-n)/520)-1)*12}function dh(e,t,n,r,i){return`M${e} ${t} V${i} H${n} V${r}`}function fh(e,t){let n=e.y+e.height/2,r=t.y+t.height/2,i=uh(e,t);if(lh(e,t)){let n=e.x+e.width/2,r=e.y+e.height,a=t.x+t.width/2,o=t.y+t.height;return dh(n,r,a,o,Math.max(r,o)+48+i)}if(r>=n){let n=e.x+e.width/2,r=e.y+e.height,a=t.x+t.width/2,o=t.y,s=o-r;return dh(n,r,a,o,s>=48?r+s/2:Math.max(r,o)+48+i)}let a=e.x+e.width/2,o=e.y,s=t.x+t.width/2,c=t.y;return dh(a,o,s,c,Math.min(o,c)-48-i)}function ph(e){let t=e.match(/[MLHVmlhv]|-?\d*\.?\d+/g);if(!t)return[];let n=[],r=0,i=0,a=0;for(;a<t.length;){let e=t[a++].toUpperCase();e===`M`||e===`L`?(r=Number(t[a++]),i=Number(t[a++]),n.push({x:r,y:i})):e===`H`?(r=Number(t[a++]),n.push({x:r,y:i})):e===`V`&&(i=Number(t[a++]),n.push({x:r,y:i}))}return n}function mh(e,t){let n=ph(fh(e,t));if(n.length===0)return{x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),width:Math.abs(t.x-e.x)+Math.max(e.width,t.width),height:Math.abs(t.y-e.y)+Math.max(e.height,t.height)};let r=n.map(e=>e.x),i=n.map(e=>e.y),a=Math.min(...r),o=Math.max(...r),s=Math.min(...i),c=Math.max(...i);return{x:a,y:s,width:o-a,height:c-s}}function hh(e,t,n=4){return Math.hypot(e,t)>n}function gh(e,t=24){if(e.length===0)return{x:0,y:0,width:0,height:0};let n=1/0,r=1/0,i=-1/0,a=-1/0;for(let t of e)n=Math.min(n,t.x),r=Math.min(r,t.y),i=Math.max(i,t.x+t.width),a=Math.max(a,t.y+t.height);return{x:n-t,y:r-t,width:i-n+t*2,height:a-r+t*2}}function _h(e,t){if(e.width<=0||e.height<=0||t.width<=0||t.height<=0)return{panX:0,panY:0,zoom:1};let n=t.width-56,r=t.height-56;if(n<=0||r<=0)return{panX:0,panY:0,zoom:1};let i=Math.max(sh,Math.min(1.1,ch,n/e.width,r/e.height));return{zoom:i,panX:56+(n-e.width*i)/2-e.x*i,panY:56+(r-e.height*i)/2-e.y*i}}function vh(e,t){return e&&!t}function yh(e,t){return e===t?null:e}function bh(e,t){return!!e.find(e=>e.stage_id===t)?.envelope}function xh(e,t){return e===`waiting_for_input`||e===`pending`||e===`skipped`?null:e===`running`?`abandon`:e===`failed`||t?`retry`:null}function Sh(e){switch(e){case`free_text`:return`free text`;case`confirm`:return`confirm`;case`multi_question`:return`multi-question`;case`artifact_backed`:return`artifact`}}function Ch(e,t,n,r){let i=Math.max(48,(n-e)/2);return`M${e} ${t} C${e+i} ${t} ${n-i} ${r} ${n} ${r}`}function wh(e,t){return t?`abandoned`:e}function Th({layout:e,stages:t,nodeChrome:n,selectedStageId:r,onSelectStage:i,onDeselect:a,retryingStageIds:o,onRetryStage:s,resumingStageIds:c,onResumeStage:l,abandoningStageId:u=null,onAbandonStage:d,runId:f,showHint:p,feedbackOverlays:m=[]}){let h=(0,v.useRef)(null),g=(0,v.useRef)(!1),_=(0,v.useRef)(!1),y=(0,v.useRef)({width:0,height:0}),b=(0,v.useRef)(null),[x,S]=(0,v.useState)({width:0,height:0}),[C,w]=(0,v.useState)({x:0,y:0}),[T,E]=(0,v.useState)(1),[D,O]=(0,v.useState)(!1),k=new Map(t.map(e=>[e.stage_id,e])),A=new Map(n.map(e=>[e.stageId,e])),j=o??new Set,M=c??new Set;(0,v.useLayoutEffect)(()=>{let e=h.current;if(!e)return;let t=()=>{let t=e.getBoundingClientRect();S({width:t.width,height:t.height})};t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[]),(0,v.useLayoutEffect)(()=>{g.current=!1,_.current=!1,y.current={width:0,height:0}},[f]);let N=()=>{let t=[...e.nodes];for(let n of m){let r=e.nodes.find(e=>e.stageId===n.from),i=e.nodes.find(e=>e.stageId===n.to);!r||!i||t.push(mh(r,i))}return gh(t)};(0,v.useLayoutEffect)(()=>{if(e.nodes.length===0||x.width===0||x.height===0)return;if(!g.current){let e=_h(N(),x);w({x:e.panX,y:e.panY}),E(e.zoom),g.current=!0,y.current={width:x.width,height:x.height};return}if(y.current.width===x.width&&y.current.height===x.height||(y.current={width:x.width,height:x.height},!vh(!0,_.current)))return;let t=_h(N(),x);w({x:t.panX,y:t.panY}),E(t.zoom)},[m,e.nodes,x.height,x.width]);let ee=(e,t)=>{let n=t??{x:x.width/2,y:x.height/2},r=Math.max(sh,Math.min(ch,T*e)),i=(n.x-C.x)/T,a=(n.y-C.y)/T;_.current=!0,w({x:n.x-i*r,y:n.y-a*r}),E(r)},P=()=>{let t=h.current;if(!t||e.nodes.length===0)return;let n=t.getBoundingClientRect(),r=_h(N(),{width:n.width,height:n.height});w({x:r.panX,y:r.panY}),E(r.zoom),_.current=!1,g.current=!0,y.current={width:n.width,height:n.height}},F=e=>{e.target.closest(`.gnode`)||(e.currentTarget.setPointerCapture(e.pointerId),O(!0),b.current={id:e.pointerId,x:e.clientX,y:e.clientY,panX:C.x,panY:C.y})},I=e=>{let t=b.current;if(!t||t.id!==e.pointerId)return;let n=e.clientX-t.x,r=e.clientY-t.y;hh(n,r)&&(_.current=!0),w({x:t.panX+n,y:t.panY+r})},te=e=>{let t=b.current;if(!t||t.id!==e.pointerId)return;let n=e.clientX-t.x,r=e.clientY-t.y;b.current=null,O(!1),hh(n,r)||a()};return(0,B.jsxs)(`div`,{className:`graph-view`,children:[(0,B.jsxs)(`svg`,{className:`graph-grid`,"aria-hidden":`true`,width:`100%`,height:`100%`,children:[(0,B.jsx)(`defs`,{children:(0,B.jsx)(`pattern`,{id:`spatial-dots`,width:`24`,height:`24`,patternUnits:`userSpaceOnUse`,children:(0,B.jsx)(`circle`,{cx:`1`,cy:`1`,r:`1`,fill:`var(--color-border)`})})}),(0,B.jsx)(`rect`,{width:`100%`,height:`100%`,fill:`url(#spatial-dots)`})]}),(0,B.jsx)(`div`,{ref:h,className:D?`graph-stage dragging`:`graph-stage`,onPointerDown:F,onPointerMove:I,onPointerUp:te,onPointerCancel:te,onWheel:e=>{e.preventDefault();let t=e.currentTarget.getBoundingClientRect();if(e.metaKey||e.ctrlKey){ee(e.deltaY<0?1.08:.92,{x:e.clientX-t.left,y:e.clientY-t.top});return}_.current=!0,w(t=>({x:t.x-e.deltaX,y:t.y-e.deltaY}))},children:(0,B.jsxs)(`svg`,{className:`graph-svg`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,B.jsxs)(`defs`,{children:[(0,B.jsx)(`marker`,{id:`spatial-arrow`,markerWidth:`8`,markerHeight:`8`,refX:`7`,refY:`3`,orient:`auto`,children:(0,B.jsx)(`path`,{d:`M0,0 L7,3 L0,6 Z`,fill:`var(--color-text-disabled)`})}),(0,B.jsx)(`marker`,{id:`spatial-arrow-active`,markerWidth:`8`,markerHeight:`8`,refX:`7`,refY:`3`,orient:`auto`,children:(0,B.jsx)(`path`,{d:`M0,0 L7,3 L0,6 Z`,fill:`var(--color-accent)`})}),(0,B.jsx)(`marker`,{id:`spatial-arrow-feedback`,markerWidth:`8`,markerHeight:`8`,refX:`7`,refY:`3`,orient:`auto`,children:(0,B.jsx)(`path`,{d:`M0,0 L7,3 L0,6 Z`,fill:`var(--color-warning)`})})]}),(0,B.jsxs)(`g`,{className:`world`,transform:`translate(${C.x} ${C.y}) scale(${T})`,children:[e.edges.map(n=>{let r=e.nodes.find(e=>e.stageId===n.from),i=e.nodes.find(e=>e.stageId===n.to);if(!r||!i)return null;let a=r.height,o=i.height,s=r.x+r.width,c=r.y+a/2,l=i.x,u=i.y+o/2,d=bh(t,n.from);return(0,B.jsx)(`g`,{children:(0,B.jsx)(`path`,{className:d?`edge handoff`:`edge`,d:Ch(s,c,l,u),markerEnd:d?`url(#spatial-arrow-active)`:`url(#spatial-arrow)`})},`${n.from}->${n.to}`)}),m.map(t=>{let n=e.nodes.find(e=>e.stageId===t.from),r=e.nodes.find(e=>e.stageId===t.to);return!n||!r?null:(0,B.jsx)(`path`,{className:t.kind===`deferred`?`edge feedback feedback--deferred`:t.kind===`policy`?`edge feedback feedback--policy`:`edge feedback`,d:fh(n,r),markerEnd:`url(#spatial-arrow-feedback)`},`feedback:${t.kind}:${t.from}->${t.to}`)}),e.nodes.map(e=>{let t=k.get(e.stageId),n=A.get(e.stageId),a=t?.status??n?.status??`pending`,o=t?Rr(t.events):!1;return(0,B.jsx)(Eh,{node:e,status:a,abandoned:o,chrome:n,selected:r===e.stageId,busy:eh({retryingStageIds:j,abandoningStageId:u,resumingStageIds:M},e.stageId),retrying:j.has(e.stageId),resuming:M.has(e.stageId),abandoning:u===e.stageId,snapshot:t,onSelectStage:i,onRetryStage:s,onResumeStage:l,onAbandonStage:d},e.stageId)})]})]})}),(0,B.jsxs)(`div`,{className:`canvas-tools`,children:[(0,B.jsx)(`button`,{type:`button`,className:`icon`,title:`Zoom out`,"aria-label":`Zoom out`,onClick:()=>ee(.87),children:`−`}),(0,B.jsxs)(`span`,{className:`zoom`,"aria-live":`polite`,children:[Math.round(T*100),`%`]}),(0,B.jsx)(`button`,{type:`button`,className:`icon`,title:`Zoom in`,"aria-label":`Zoom in`,onClick:()=>ee(1.15),children:`+`}),(0,B.jsx)(`span`,{className:`divider`}),(0,B.jsx)(`button`,{type:`button`,className:`icon fit-btn`,onClick:P,children:`Fit run`})]}),p?(0,B.jsx)(`div`,{className:`canvas-hint`,children:`Stages become selectable when they start.`}):null]})}function Eh({node:e,status:t,abandoned:n,chrome:r,selected:i,busy:a,retrying:o,resuming:s,abandoning:c,snapshot:l,onSelectStage:u,onRetryStage:d,onResumeStage:f,onAbandonStage:p}){let m=t!==`pending`,h=xh(t,n),g=l!==void 0&&$m(l)&&f!==void 0,_=h===`retry`&&Zm(t)&&d,v=h===`abandon`&&Qm(t)&&p,y=wh(t,n),b=[r?.isFeedbackSource?`feedback-source`:``,r?.isFeedbackTarget?`feedback-target`:``,r?.isSuperseded?`superseded`:``].filter(Boolean).join(` `),x=n?zr():Hr(t),S=r?.title??e.stageId,C=r?yh(r.kicker,r.title):null,w=[x];r?.isSuperseded&&w.push(`superseded`),r?.readinessLine&&t===`pending`&&w.push(r.readinessLine),t===`waiting_for_input`?(r?.gateKinds?.length&&w.push(r.gateKinds.map(Sh).join(` · `)),r?.promptSummary&&w.push(r.promptSummary)):r?.meta&&w.push(r.meta);let T=()=>{m&&u(e.stageId)};return(0,B.jsxs)(`g`,{className:`gnode ${y}${i?` selected`:``}${b?` ${b}`:``}`,"data-id":e.stageId,"data-waiting":r?.isWaitingAttention?`true`:void 0,"data-feedback-source":r?.isFeedbackSource?`true`:void 0,"data-feedback-target":r?.isFeedbackTarget?`true`:void 0,"data-superseded":r?.isSuperseded?`true`:void 0,transform:`translate(${e.x},${e.y})`,children:[(0,B.jsx)(`rect`,{className:`node-box`,x:0,y:0,width:e.width,height:128,rx:12,ry:12}),(0,B.jsx)(`circle`,{className:`port`,cx:-4,cy:64,r:4}),(0,B.jsx)(`circle`,{className:`port`,cx:e.width+4,cy:64,r:4}),m?(0,B.jsx)(`foreignObject`,{x:0,y:0,width:e.width,height:128,children:(0,B.jsxs)(`button`,{type:`button`,className:`gnode__hit`,onClick:T,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),T())},children:[C?(0,B.jsx)(`span`,{className:`gnode__kicker`,children:C}):null,(0,B.jsxs)(`span`,{className:`gnode__title`,children:[S,(0,B.jsx)(Hc,{count:r?.attemptCount})]}),(0,B.jsx)(`span`,{className:`gnode__meta`,children:w.join(` · `)})]})}):(0,B.jsxs)(`g`,{className:`gnode__static`,children:[C?(0,B.jsx)(`text`,{className:`kicker`,x:16,y:22,children:C}):null,(0,B.jsx)(`text`,{className:`node-title`,x:16,y:C?44:32,children:S}),(0,B.jsx)(`text`,{className:`node-meta`,x:16,y:66,children:w.join(` · `)})]}),(0,B.jsx)(Oh,{status:t,abandoned:n,cx:e.width-26,cy:26,showResume:!!g,showRetry:!!_,showAbandon:!!v,busy:a,resumeLabel:s?`Resuming…`:`Resume session`,retryLabel:o?`Retrying…`:`Retry stage`,abandonLabel:c?`Abandoning…`:`Abandon stage`,onResume:g?()=>{f?.(e.stageId)}:void 0,onRetry:_?()=>{d?.(e.stageId)}:void 0,onAbandon:v?()=>{p?.(e.stageId)}:void 0})]})}function Dh({kind:e,cx:t,cy:n,busy:r,label:i,onActivate:a}){return(0,B.jsxs)(`g`,{className:`node-action-btn node-${e}${r?` is-busy`:``}`,role:`button`,tabIndex:r?-1:0,"aria-label":i,"aria-disabled":r||void 0,onClick:e=>{r||(e.stopPropagation(),a?.())},onKeyDown:e=>{r||(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),e.stopPropagation(),a?.())},children:[(0,B.jsx)(`title`,{children:i}),(0,B.jsx)(`circle`,{className:`action-bg`,cx:t,cy:n,r:11}),e===`retry`?(0,B.jsx)(`path`,{className:`action-icon`,d:[`M${t-3.2} ${n-2.2}`,`A4.2 4.2 0 1 0 ${t+.2} ${n-4}`,`M${t+.2} ${n-7.2}`,`L${t+.2} ${n-3.6}`,`L${t-3.4} ${n-3.6}`].join(` `)}):e===`resume`?(0,B.jsx)(`path`,{className:`action-icon`,d:`M${t-2.2} ${n-3.6} L${t-2.2} ${n+3.6} L${t+4.2} ${n} Z`}):(0,B.jsx)(`rect`,{className:`action-icon`,x:t-3.5,y:n-3.5,width:7,height:7,rx:1.25})]})}function Oh({status:e,abandoned:t,cx:n,cy:r,showResume:i,showRetry:a,showAbandon:o,busy:s,resumeLabel:c,retryLabel:l,abandonLabel:u,onResume:d,onRetry:f,onAbandon:p}){let m=r+28,h=i?m+26:m;return(0,B.jsxs)(`g`,{className:`node-status`,children:[e===`succeeded`?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`circle`,{cx:n,cy:r,r:11,fill:`var(--color-success)`}),(0,B.jsx)(`path`,{d:`M${n-4} ${r} l3 3 l6-7`,fill:`none`,stroke:`var(--color-background-surface)`,strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`})]}):null,e===`running`?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`circle`,{className:`node-spin`,cx:n,cy:r,r:11,fill:`none`,stroke:`var(--color-border)`,strokeWidth:2}),(0,B.jsx)(`circle`,{className:`node-spin`,cx:n,cy:r,r:11,fill:`none`,stroke:`var(--color-accent)`,strokeWidth:2.25,strokeLinecap:`round`,strokeDasharray:`18 52`})]}):null,e===`waiting_for_input`?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`circle`,{cx:n,cy:r,r:10,fill:`none`,stroke:`var(--color-warning)`,strokeWidth:2,strokeDasharray:`4 3`}),(0,B.jsx)(`text`,{x:n,y:r+4,textAnchor:`middle`,fill:`var(--color-warning)`,fontSize:11,fontWeight:700,children:`!`})]}):null,e===`failed`&&!t?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`circle`,{cx:n,cy:r,r:11,fill:`var(--color-error)`}),(0,B.jsx)(`text`,{x:n,y:r+4,textAnchor:`middle`,fill:`var(--color-background-surface)`,fontSize:12,fontWeight:700,children:`!`})]}):null,t?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`circle`,{cx:n,cy:r,r:11,fill:`var(--color-error)`}),(0,B.jsx)(`rect`,{x:n-5,y:r-1.5,width:10,height:3,rx:1,fill:`var(--color-background-surface)`})]}):null,e===`pending`||e===`skipped`?(0,B.jsx)(`circle`,{cx:n,cy:r,r:10,fill:`none`,stroke:`var(--color-text-disabled)`,strokeWidth:1.5}):null,i?(0,B.jsx)(Dh,{kind:`resume`,cx:n,cy:m,busy:s,label:c,onActivate:d}):null,a?(0,B.jsx)(Dh,{kind:`retry`,cx:n,cy:h,busy:s,label:l,onActivate:f}):null,o?(0,B.jsx)(Dh,{kind:`abandon`,cx:n,cy:m,busy:s,label:u,onActivate:p}):null]})}var kh=64;function Ah(e){return e.scrollHeight-e.scrollTop-e.clientHeight<kh}function jh({stageName:e,status:t,trailing:n,children:r,composer:i,autoScroll:a,scrollKey:o}){let s=(0,v.useRef)(null),c=(0,v.useRef)(!0);(0,v.useEffect)(()=>{a&&(c.current=!0)},[a]),(0,v.useEffect)(()=>{if(!a||!c.current)return;let e=s.current;e&&(e.scrollTop=e.scrollHeight)},[a,o]);function l(e){c.current=Ah(e.currentTarget)}return(0,B.jsxs)(`div`,{className:`stream`,style:{height:`100%`},children:[(0,B.jsxs)(`header`,{className:`stream__head`,children:[(0,B.jsx)(`h3`,{className:`stream__name`,children:e}),t,n?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`span`,{className:`topbar__spacer`}),(0,B.jsx)(`div`,{className:`stream__head-trail`,children:n})]}):null]}),(0,B.jsx)(`div`,{ref:s,className:`stream__body`,onScroll:l,children:(0,B.jsx)(`div`,{className:`thread`,children:r})}),i]})}function Mh(e){switch(e){case`passed`:return`passed`;case`failed`:return`failed`;case`running`:return`running`;case`skipped`:return`skipped`;default:return`pending`}}function Nh(e){let t=e.checks.length===1?`check`:`checks`;return`Attempt ${e.attempt} · ${e.status} · verification ${e.verification_outcome.replace(`_`,` `)} · ${e.checks.length} ${t}`}function Ph({check:e}){let t=e.evidence===void 0?void 0:JSON.stringify(e.evidence,null,2);return(0,B.jsxs)(`div`,{className:`verification-check`,children:[(0,B.jsxs)(`div`,{className:`verification-check__summary`,children:[(0,B.jsxs)(`span`,{className:`status status--${e.status===`passed`?`succeeded`:e.status===`failed`?`failed`:`running`}`,children:[(0,B.jsx)(`span`,{className:`dot dot--${e.status===`passed`?`succeeded`:e.status===`failed`?`failed`:`running`}`}),` `,Mh(e.status)]}),(0,B.jsx)(`code`,{children:e.check_id}),(0,B.jsx)(`span`,{className:`muted`,children:e.check_type})]}),t===void 0?null:(0,B.jsx)(lc,{code:t,language:`json`,title:`Evidence`,size:`sm`,width:`100%`,maxHeight:260,container:`section`,isCollapsible:!0})]})}function Fh({history:e,error:t,recovering:n=!1,onRecover:r,onStop:i}){let[a,o]=(0,v.useState)(``);return t?(0,B.jsxs)(`div`,{className:`banner banner--warning`,children:[`Verification evidence unavailable: `,t]}):e===null||e.attempts.every(e=>e.checks.length===0)?null:(0,B.jsxs)(`section`,{className:`verification-history`,"aria-label":`Verification history`,children:[(0,B.jsxs)(`div`,{className:`verification-history__head`,children:[(0,B.jsx)(`strong`,{children:`Verification`}),(0,B.jsxs)(`span`,{className:`muted`,children:[e.attempts.length,` attempts`]})]}),e.attempts.map(t=>(0,B.jsx)(xc,{trigger:(0,B.jsx)(`span`,{className:`verification-history__attempt`,children:Nh(t)}),defaultIsOpen:t.attempt===e.attempts.length,children:(0,B.jsx)(`div`,{className:`verification-history__checks`,children:t.checks.length>0?t.checks.map(e=>(0,B.jsx)(Ph,{check:e},e.check_id)):(0,B.jsx)(`p`,{className:`muted`,children:`No completion checks ran in this attempt.`})})},t.attempt)),e.manual_recovery?.status===`available`?(0,B.jsxs)(`section`,{className:`manual-recovery`,"aria-label":`Manual recovery`,children:[(0,B.jsx)(`strong`,{children:`Manual recovery required`}),(0,B.jsx)(`p`,{className:`muted`,children:`This stage remains failed until an operator explicitly retries it or stops recovery.`}),(0,B.jsx)(`label`,{className:`manual-recovery__label`,htmlFor:`manual-recovery-guidance`,children:`Guidance for the retry (optional)`}),(0,B.jsx)(`textarea`,{id:`manual-recovery-guidance`,className:`manual-recovery__guidance`,value:a,maxLength:4e3,onChange:e=>o(e.target.value),placeholder:`Tell the agent what to address before it retries.`,disabled:n}),(0,B.jsxs)(`div`,{className:`manual-recovery__actions`,children:[(0,B.jsx)(`button`,{type:`button`,className:`btn btn--primary`,disabled:n||r===void 0,onClick:()=>r?.(a),children:n?`Starting recovery…`:`Retry with guidance`}),(0,B.jsx)(`button`,{type:`button`,className:`btn btn--sm btn--reject`,disabled:n||i===void 0,onClick:()=>i?.(),children:`Stop recovery`})]})]}):null,e.manual_recovery?.status===`stopped`?(0,B.jsx)(`p`,{className:`muted`,children:`Manual recovery was stopped by an operator.`}):null]})}function Ih(e){let{readiness:t,blocked_by:n,status:r}=e;if(t===`blocked`)return n?.length?`Blocked on ${n.join(`, `)}`:`Blocked`;if(t===`skipped`)return`Skipped`;if(t===`ready`)return`Ready`;if(t!==`waiting`||r!==`waiting_for_input`){if(t===`succeeded`)return Hr(`succeeded`);if(t===`failed`)return Hr(`failed`);if(t===`running`)return Hr(`running`)}}var Lh=`stageflow:envelope:`;function Rh(e){return`${Lh}${e}`}function zh(e){if(!e.startsWith(Lh))return null;let t=e.slice(19);return t.length>0?t:null}function Bh(e,t){return`${e}->${t}`}var Vh={deferred:3,replay:2,policy:1},Hh=new Set([`scheduled`,`active`,`waiting_for_human`]);function Uh(e,t,n){let r=new Map,i=e=>{let t=Bh(e.from,e.to),n=r.get(t);(!n||Vh[e.kind]>Vh[n.kind])&&r.set(t,e)};for(let e of n?.nodes??[]){let t=e.feedback_loop?.target;t&&i({from:e.stage_id,to:t,kind:`policy`})}e?.deferred_send_back?.target&&i({from:e.source_stage_id,to:e.deferred_send_back.target,kind:`deferred`});let a=!!e?.deferred_send_back?.target,o=e=>{for(let n of t??[])for(let{replay:t}of n.replays)t.status!==`superseded`&&t.status!==`failed`&&e(t.status)&&i({from:t.source_stage_id,to:t.target_stage_id,kind:`replay`})};return o(e=>Hh.has(e)),![...r.values()].some(e=>e.kind===`replay`)&&!a&&o(e=>e===`completed`),e&&i({from:e.source_stage_id,to:e.policy.target,kind:`policy`}),[...r.values()]}function Wh(e){let t=new Set;for(let n of e??[]){for(let e of n.fork_generations)if(e.status===`superseded`)for(let n of e.clone_stage_ids)t.add(n);for(let{stage_passes:e,fork_generations:r}of n.replays){for(let n of e)n.status===`superseded`&&t.add(n.stage_id);for(let e of r)if(e.status===`superseded`)for(let n of e.clone_stage_ids)t.add(n)}}return t}function Gh(e,t){for(let n of t)if(n.status===`superseded`)for(let t of n.clone_stage_ids)e.add(t)}function Kh(e){let t=new Set;for(let n of e??[]){Gh(t,n.fork_generations);for(let e of n.replays)Gh(t,e.fork_generations)}return t}function qh(e,t){return e.filter(e=>!t.has(e))}function Jh(e,t){return t.size===0?e:{nodes:e.nodes.filter(e=>!t.has(e.stage_id)),edges:e.edges.filter(e=>!t.has(e.from)&&!t.has(e.to))}}function Yh(e){let t=e.active_feedback_loop;if(!(e.waiting_kind!==`feedback_loop_decision`||!t||t.state!==`waiting_for_human`))return{loopId:t.loop_id,sourceStageId:t.source_stage_id,deferredTarget:t.deferred_send_back?.target,replayNumber:t.current_replay_number,maxReplays:t.policy.max_replays,summary:e.waiting_summary}}function Xh(e,t){return e.stages.some(e=>e.stage_id===t)}function Zh(e,t,n){return Xh(e,t)||e.pipeline_track?.nodes?.some(e=>e.stage_id===t)?!0:!!n?.includes(t)}function Qh(e){return new Map(e.stages.map(e=>[e.stage_id,e]))}function $h(e){let t=e.pipeline_track;return t?.nodes?.length?Km(t.nodes).map(e=>e.stage_id):e.stages.map(e=>e.stage_id)}function eg(e){let t=e.waiting_stage_id;if(!t)return null;let n=e.stages.find(e=>e.stage_id===t)?.pending_prompt?.id;return n?`${t}:${n}`:e.waiting_prompt_id?e.waiting_prompt_id:Xh(e,t)?`${t}:`:null}function tg(e,t){if(t.userPicked&&t.previousStageId&&Xh(e,t.previousStageId))return t.previousStageId;let n=eg(e);return n&&n!==t.dismissedWaitKey&&e.waiting_stage_id&&Xh(e,e.waiting_stage_id)?e.waiting_stage_id:null}function ng(e,t){return e.artifacts.includes(t)?!0:!!e.envelope?.artifacts.includes(t)}function rg(e,t){let n=Qh(e);for(let r of $h(e)){let e=n.get(r);if(e&&ng(e,t))return r}return null}function ig(e,t,n){return t===void 0||t===``?e:e===t?t:n===void 0?e:`${t} · ${n}`}function ag(e,t,n){if(n===void 0)return;let r=Km(e).filter(e=>(e.definition_id??e.stage_id)===n).findIndex(e=>e.stage_id===t);if(!(r<0))return r+1}function og(e,t){return ig(t.stage_id,t.definition_id,ag(e,t.stage_id,t.definition_id))}function sg(e,t){let n=e.pipeline_track?.nodes??[],r=n.find(e=>e.stage_id===t);return r?og(n,r):ig(t)}function cg(e,t,n){let r=Wr(e.status);return{id:e.stage_id,label:n??e.stage_id,status:r,selected:e.stage_id===t,meta:r===`waiting`?Hr(e.status):e.last_at,envelope:e.envelope?{summary:e.envelope.summary,artifactCount:e.envelope.artifacts.length}:null}}function lg(e,t,n){return{id:e,label:n??e,status:`pending`,selected:e===t,meta:`pending`,envelope:null}}function ug(e,t,n,r){let i=og(r,e);return t?cg(t,n,i):lg(e.stage_id,n,i)}function dg(e,t,n){if(!n||n.length===0)return e.map(e=>cg(e,t));let r=new Map(e.map(e=>[e.stage_id,e])),i=new Set,a=[];for(let e of n){i.add(e);let n=r.get(e);a.push(n?cg(n,t):lg(e,t))}for(let n of e)i.has(n.stage_id)||a.push(cg(n,t));return a}function fg(e,t,n){return e.waiting_stage_ids?.includes(t)?!0:n===`waiting_for_input`}function pg(e){if(e)switch(e.kind){case`free_text`:case`confirm`:return e.message;case`artifact_backed`:return e.message||e.artifacts[0];case`multi_question`:return e.questions.length===1?`1 question`:`${e.questions.length} questions`}}function mg(e,t,n,r,i,a){return Km(t).map(o=>{let s=n.get(o.stage_id),c=s?.status??o.status;return{stageId:o.stage_id,title:og(t,o),kicker:o.definition_id??o.stage_id,status:c,attemptCount:s?.attempt_count??o.attempt_count??1,readinessLine:Ih({readiness:o.readiness,blocked_by:o.blocked_by,status:c}),gateKinds:o.gate_kinds,meta:c===`running`?s?.last_at:void 0,promptSummary:c===`waiting_for_input`?pg(s?.pending_prompt):void 0,isWaitingAttention:fg(e,o.stage_id,c),isFeedbackSource:r.has(o.stage_id)||void 0,isFeedbackTarget:i.has(o.stage_id)||void 0,isSuperseded:a.has(o.stage_id)||void 0}})}function hg(e,t,n,r,i,a){return t.map(t=>{let o=n.get(t.id),s=o?.status??`pending`;return{stageId:t.id,title:t.label,kicker:t.id,status:s,attemptCount:o?.attempt_count??1,meta:s===`running`?o?.last_at:void 0,promptSummary:s===`waiting_for_input`?pg(o?.pending_prompt):void 0,isWaitingAttention:fg(e,t.id,s),isFeedbackSource:r.has(t.id)||void 0,isFeedbackTarget:i.has(t.id)||void 0,isSuperseded:a.has(t.id)||void 0}})}function gg(e,t,n,r,i,a){let o=Qh(e),s=Jh(e.pipeline_track,a),c=n&&qh(n,a),l=Xm(s,{liveStageIds:qh(e.stages.map(e=>e.stage_id),a),plannedStageIds:c}),u=new Set(r.map(e=>e.from)),d=new Set(r.map(e=>e.to));if(!s.nodes.length){let n=dg(e.stages.filter(e=>!a.has(e.stage_id)),t,c);return{spatialLayout:l,nodeChrome:hg(e,n,o,u,d,i),trackStages:n}}let f=s.nodes,p=Km(f).map(e=>ug(e,o.get(e.stage_id),t,f));return{spatialLayout:l,nodeChrome:mg(e,f,o,u,d,i),trackStages:p}}function _g(e,t,n){return e===`stream`?t===`waiting_for_input`&&n?{kind:`reply`,prompt:n}:!t||t===`succeeded`||t===`failed`||t===`pending`||t===`skipped`?{kind:`idle`,label:`Session closed`}:{kind:`none`}:{kind:`none`}}function vg(e){return e===`waiting_for_input`?`alive`:e===`succeeded`||e===`failed`||e===`pending`||e===`skipped`?`closed`:null}function yg(e){let t=[];for(let n of e.stages)for(let r of n.artifacts)t.push({path:r,meta:sg(e,n.stage_id)});return t}function bg(e,t){let n=yg(e);return t?.envelope?[{path:Rh(t.stage_id),label:`Handoff envelope`,meta:sg(e,t.stage_id)},...n]:n}function xg(e,t,n){let r=e.pipeline_track;if(r?.nodes?.length)return r.edges.find(e=>e.to===t)?.from;if(n&&n.length>0){let e=n.indexOf(t);if(e>0)return n[e-1]}let i=e.stages.findIndex(e=>e.stage_id===t);if(i>0)return e.stages[i-1]?.stage_id}function Sg(e,t,n){let r=e.pipeline_track;if(r?.nodes?.length){let e=r.edges.filter(e=>e.from===t);return e.length===1?e[0]?.to:void 0}if(n&&n.length>0){let e=n.indexOf(t);if(e>=0)return n[e+1]}let i=e.stages.findIndex(e=>e.stage_id===t);if(!(i<0))return e.stages[i+1]?.stage_id}function Cg(e){return e?.kind===`artifact_backed`?e:void 0}function wg(e){return e?.status===`waiting_for_input`&&e.pending_prompt?.kind===`artifact_backed`}function Tg(e,t){return t.retrying||t.abandoning?!0:e?e.status===`created`||e.status===`running`||e.waiting_stage_id?!0:e.stages.some(e=>e.status===`running`||e.status===`waiting_for_input`):!1}function Eg(e,t,n,r){let i=tg(t,n),a=e.kind===`stream`&&e.stageId&&Zh(t,e.stageId,r)?e.stageId:i,o=e.kind===`envelope`?e.stageId:e.kind===`artifact`?rg(t,e.path):a,s=t.stages.find(e=>e.stage_id===o)??null,c=t.pipeline_track?.nodes?.length?void 0:r,l=o?xg(t,o,c):void 0,u=l?t.stages.find(e=>e.stage_id===l):void 0,d=wg(s),f=e.kind===`artifact`&&!!n.wasWaitingArtifact&&!d,p;p=e.kind===`envelope`?`envelope`:e.kind===`artifact`&&!f?`artifact`:o?`stream`:`empty`;let m=p===`artifact`&&d,h=m?Cg(s?.pending_prompt):void 0,g=Yh(t),_=!!g,v=Uh(t.active_feedback_loop,t.feedback_loops,t.pipeline_track),y=Kh(t.feedback_loops),b=Wh(t.feedback_loops),x=e.kind===`envelope`?e.stageId:null,S=x?t.stages.find(e=>e.stage_id===x)??null:null,C=e.kind===`envelope`?{fromStageId:e.stageId,toStageId:Sg(t,e.stageId,c),envelope:S?.envelope??null}:null,w=(n.drawerStageId?t.stages.find(e=>e.stage_id===n.drawerStageId)??null:null)?.envelope??null,T=p!==`envelope`&&n.drawerStageId&&w?{fromStageId:n.drawerStageId,toStageId:Sg(t,n.drawerStageId,c),envelope:w}:null,{spatialLayout:E,nodeChrome:D,trackStages:O}=gg(t,o,r,v,b,y);return{selectedStageId:o,selectedStage:s,kind:p,composer:_g(p,s?.status,s?.pending_prompt),showDecide:m,decidePrompt:h,showFeedbackDecide:_,feedbackDecide:g,feedbackOverlays:v,artifactReadOnly:!m,selectedPath:p===`artifact`&&e.kind===`artifact`?e.path:p===`envelope`&&e.kind===`envelope`?Rh(e.stageId):void 0,trackStages:O,spatialLayout:E,nodeChrome:D,artifactFiles:bg(t,s),sessionChip:vg(s?.status),inboundEnvelope:u?.envelope??null,inboundFromStageId:u?.stage_id,inboundToStageId:s?.stage_id,drawer:T,envelope:C,liveStream:s?.status===`running`||s?.status===`waiting_for_input`,activeEnvelopeId:e.kind===`envelope`?e.stageId:n.drawerStageId,waitingArtifact:d,syncStreamRoute:f}}function Dg(e){return e.syncStreamRoute?{action:`openStream`,stageId:e.selectedStageId??void 0}:e.view.kind!==`stream`||!e.run?{action:`none`}:e.streamViewStageId&&!Zh(e.run,e.streamViewStageId,e.plannedStageIds)?{action:`openStream`}:e.userPickedStageId||e.dismissedWaitKey||!e.selectedStageId||e.streamViewStageId===e.selectedStageId?{action:`none`}:{action:`openStream`,stageId:e.selectedStageId}}var Og=300,kg=200,Ag=140,jg=24;function Mg(e,t){let n=t-Ag;return t<340?Math.max(0,n):Math.max(kg,Math.min(e,n))}function Ng(e){return e===`alive`?(0,B.jsx)(`span`,{className:`chip`,children:`session alive`}):e===`closed`?(0,B.jsx)(`span`,{className:`chip`,children:`session closed`}):null}function Pg(e,t,n){let r=t.selectedStage;if(t.composer.kind===`reply`&&r)return(0,B.jsx)(`div`,{className:`composer`,children:(0,B.jsx)(`div`,{className:`composer__inner`,children:(0,B.jsx)(Bc,{runId:e,stageId:r.stage_id,prompt:t.composer.prompt,onReviewSideBySide:n})})});if(t.composer.kind===`idle`)return(0,B.jsx)(`div`,{className:`composer composer--idle`,children:(0,B.jsx)(`div`,{className:`composer__inner`,children:(0,B.jsx)(`p`,{className:`muted`,children:t.composer.label})})})}function Fg({runId:e,view:t,onBack:n,onReran:r,onOpenStream:i,onOpenArtifact:a,onOpenEnvelope:o}){let[s,c]=(0,v.useState)(null),[l,u]=(0,v.useState)(null),[d,f]=(0,v.useState)(null),[p,m]=(0,v.useState)(null),[h,g]=(0,v.useState)(null),[_,y]=(0,v.useState)(!1),[b,x]=(0,v.useState)(null),[S,C]=(0,v.useState)(()=>t.kind===`stream`&&t.stageId?t.stageId:null),w=(0,v.useRef)(null),[T,E]=(0,v.useState)(null),[D,O]=(0,v.useState)(null),[k,A]=(0,v.useState)(Og),[j,M]=(0,v.useState)(null),[N,ee]=(0,v.useState)(0),[P,F]=(0,v.useState)(!1),I=(0,v.useRef)(null),te=(0,v.useRef)(null),[ne,re]=(0,v.useState)(!1),ie=(0,v.useRef)(!1),ae=(0,v.useRef)(i);ae.current=i;let L=mr(),oe=t.kind===`stream`?t.stageId:void 0,se=(0,v.useCallback)(async()=>{try{let t=await Dn(e);c(t),f(null)}catch(e){f(e instanceof Error?e.message:String(e))}},[e]),ce=(0,v.useCallback)(async()=>{await se(),L.refresh()},[se,L]),le=(0,v.useCallback)(async(t,n)=>{y(!0),x(null);try{await Qn(e,t,n),await ce()}catch(e){x(e instanceof Error?e.message:String(e))}finally{y(!1)}},[ce,e]),ue=(0,v.useCallback)(async t=>{if(window.confirm(`Stop manual recovery? This stage will remain failed in this run.`)){y(!0),x(null);try{await $n(e,t),await ce()}catch(e){x(e instanceof Error?e.message:String(e))}finally{y(!1)}}},[ce,e]),{retryingStageIds:de,error:fe,retry:pe,clearError:me}=nh(e,ce),he=(0,v.useCallback)(e=>{C(e),i(e),pe(e)},[i,pe]),{resumingStageIds:ge,error:_e,resume:ve,clearError:ye}=ih(e,ce),be=(0,v.useCallback)(e=>{C(e),i(e),ve(e)},[i,ve]),{abandoningStageId:xe,error:Se,abandon:Ce,clearError:we}=oh(e,ce),Te={retryingStageIds:de,abandoningStageId:xe,resumingStageIds:ge};(0,v.useEffect)(()=>{C(oe??null),w.current=null,E(null),O(null),A(Og),M(null),c(null),f(null),m(null),g(null),y(!1),x(null),ie.current=!1},[e]),(0,v.useEffect)(()=>{se()},[se]),(0,v.useEffect)(()=>{t.kind===`stream`&&C(oe??null)},[t.kind,oe]),(0,v.useEffect)(()=>{let e=!1;return An().then(t=>{e||u(t.pipelines)}).catch(()=>{e||u([])}),()=>{e=!0}},[]);let Ee=Tg(s,{retrying:de.size>0,abandoning:xe!==null});(0,v.useEffect)(()=>{if(!Ee)return;let e=window.setInterval(()=>void se(),1e3);return()=>window.clearInterval(e)},[se,Ee]);let De=l?.find(e=>e.id===s?.pipeline_id)?.stages.map(e=>e.id)??[],R=s?Eg(t,s,{previousStageId:S??w.current,userPicked:S!==null,drawerStageId:T,dismissedWaitKey:D,wasWaitingArtifact:ie.current},De):null,Oe=R?.selectedStageId,ke=R?.selectedStage?.attempt_count;(0,v.useEffect)(()=>{if(!Oe){m(null),g(null);return}let t=!1;return m(null),g(null),On(e,Oe).then(e=>{t||m(e)}).catch(e=>{t||g(e instanceof Error?e.message:String(e))}),()=>{t=!0}},[e,Oe,ke]),R&&(w.current=R.selectedStageId),R?.waitingArtifact?ie.current=!0:t.kind!==`artifact`&&(ie.current=!1),(0,v.useEffect)(()=>{let e=Dg({view:t,streamViewStageId:oe,run:s,plannedStageIds:De,selectedStageId:R?.selectedStageId??null,syncStreamRoute:R?.syncStreamRoute??!1,userPickedStageId:S,dismissedWaitKey:D});e.action===`openStream`&&ae.current(e.stageId)},[t,oe,s,De,R?.selectedStageId,R?.syncStreamRoute,S,D]),(0,v.useEffect)(()=>{let e=I.current;if(!e)return;let t=()=>ee(e.getBoundingClientRect().height);t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[]);let Ae=(0,v.useCallback)(e=>{let t=I.current?.getBoundingClientRect().height??N;A(Mg(e,t))},[N]),je=(0,v.useCallback)(()=>{s&&O(eg(s)),C(null),w.current=null,E(null),i()},[i,s]),Me=(0,v.useCallback)(()=>{let e=R?.selectedStageId??(t.kind===`envelope`?t.stageId:void 0)??S;if(e){C(e),i(e);return}i()},[i,S,t,R?.selectedStageId]);async function Ne(){re(!0),f(null),me(),we(),ye();try{r((await Yn(e)).runId)}catch(e){f(e instanceof Error?e.message:String(e))}finally{re(!1)}}let z=R?.selectedStage??null,Pe=p!==null&&p.stage_id===z?.stage_id?p.manual_recovery:void 0,Fe=R?.selectedPath,Ie=s?Vr(s.status):void 0,Le=R?Pg(e,R,a):void 0,Re=!!(R&&R.spatialLayout.nodes.length>0),ze=!!(R&&(R.selectedStageId||R.kind===`artifact`||R.kind===`envelope`)),Be=z?Rr(z.events):!1,Ve=(0,B.jsx)(`button`,{type:`button`,className:`btn btn--sm`,onClick:je,children:`Hide workspace`}),He;if(d)He=(0,B.jsx)(`div`,{style:{padding:`var(--spacing-4)`},children:(0,B.jsx)(`div`,{className:`banner banner--error`,children:d})});else if(!s||!R)He=(0,B.jsx)(`div`,{style:{padding:`var(--spacing-4)`},children:(0,B.jsx)(`p`,{children:`Loading…`})});else if(R.kind===`artifact`&&Fe)He=(0,B.jsx)(Mp,{runId:e,path:Fe,readOnly:R.artifactReadOnly,onBackToTranscript:Me,onHide:je});else if(R.kind===`envelope`&&R.envelope)He=R.envelope.envelope?(0,B.jsx)(Hp,{fromStageId:R.envelope.fromStageId,toStageId:R.envelope.toStageId,envelope:R.envelope.envelope,onBackToTranscript:Me,onHide:je,onArtifactClick:a,stageLabel:e=>sg(s,e)}):(0,B.jsxs)(`div`,{className:`stream`,style:{height:`100%`},children:[(0,B.jsxs)(`header`,{className:`stream__head`,children:[(0,B.jsx)(`h3`,{className:`stream__name`,children:`Handoff envelope`}),(0,B.jsx)(`span`,{className:`topbar__spacer`}),(0,B.jsxs)(`div`,{className:`stream__head-trail`,children:[(0,B.jsx)(`button`,{type:`button`,className:`btn btn--sm`,onClick:Me,children:`← Transcript`}),Ve]})]}),(0,B.jsx)(`div`,{style:{padding:`var(--spacing-4)`},children:(0,B.jsxs)(`div`,{className:`banner banner--warning`,children:[R.envelope.fromStageId,` has not emitted a handoff envelope.`]})})]});else if(R.selectedStageId){let e=R.selectedStageId,t=z?Vr(z.status):void 0,n=j!==`transcript`,r=j!==`logs`,i=(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`button`,{type:`button`,className:`btn btn--sm`,onClick:()=>M(r?`logs`:null),children:r?`Hide logs`:`Show logs`}),Ve]}),a=(0,B.jsxs)(B.Fragment,{children:[z?(0,B.jsx)(Yr,{costUsd:z.cost_usd}):null,(0,B.jsx)(`button`,{type:`button`,className:`btn btn--sm`,onClick:()=>M(n?`transcript`:null),children:n?`Hide transcript`:`Show transcript`}),Ve]});He=(0,B.jsxs)(`div`,{className:`center-split`,children:[(0,B.jsx)(`div`,{className:`center-split__transcript`,hidden:!n,children:(0,B.jsxs)(jh,{stageName:R.trackStages.find(t=>t.id===e)?.label??e,status:(0,B.jsxs)(B.Fragment,{children:[Be?(0,B.jsxs)(`span`,{className:`status status--failed`,children:[(0,B.jsx)(`span`,{className:`dot dot--failed`}),` `,zr()]}):(0,B.jsxs)(`span`,{className:`status${t&&t!==`running`?` status--${t}`:``}`,children:[(0,B.jsx)(`span`,{className:`dot${t?` dot--${t}`:``}`}),` `,z?Hr(z.status):`pending`]}),z?(0,B.jsx)(Hc,{count:z.attempt_count}):null,z?(0,B.jsx)(Yr,{costUsd:z.cost_usd}):null,Ng(R.sessionChip),z&&$m(z)&&Pe===void 0?(0,B.jsx)(`button`,{type:`button`,className:`btn btn--sm`,disabled:eh(Te,z.stage_id),onClick:()=>be(z.stage_id),children:ge.has(z.stage_id)?`Resuming…`:`Resume session`}):null,z&&Zm(z.status)&&Pe===void 0?(0,B.jsx)(`button`,{type:`button`,className:`btn btn--sm`,disabled:eh(Te,z.stage_id),onClick:()=>he(z.stage_id),children:de.has(z.stage_id)?`Retrying…`:`Retry stage`}):null,z&&Qm(z.status)?(0,B.jsx)(`button`,{type:`button`,className:`btn btn--sm btn--reject`,disabled:eh(Te,z.stage_id),onClick:()=>Ce(z.stage_id),children:xe===z.stage_id?`Abandoning…`:`Abandon`}):null]}),trailing:i,autoScroll:R.liveStream,scrollKey:z?.events.length,composer:Le,children:[(0,B.jsx)(xm,{events:z?.events??[],inboundEnvelope:R.inboundEnvelope}),(0,B.jsx)(Fh,{history:p,error:h,recovering:_,onRecover:z?e=>void le(z.stage_id,e):void 0,onStop:z?()=>void ue(z.stage_id):void 0})]})}),(0,B.jsx)(`div`,{className:`center-split__logs`,hidden:!r,children:(0,B.jsx)(Wm,{events:z?.events??[],headerAction:a})})]})}let Ue=Math.max(0,N-Ag),We=N<340?Ue:kg;return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(`div`,{ref:I,className:`pane run-detail${ze?` has-stage`:``}${P?` is-resizing`:``}`,style:{height:`100%`,"--work-h":`${k}px`},children:[(0,B.jsxs)(`div`,{children:[(0,B.jsxs)(`div`,{className:`topbar`,children:[(0,B.jsx)(`a`,{className:`topbar__back`,href:`#/runs`,onClick:e=>{e.preventDefault(),n()},children:`← Runs`}),(0,B.jsx)(`h2`,{className:`topbar__title`,children:s?yr(s):`Loading…`}),s?(0,B.jsx)(`span`,{className:`topbar__sub`,title:vr(s),children:vr(s)}):null,s?(0,B.jsxs)(`span`,{className:`status${Ie&&Ie!==`running`?` status--${Ie}`:``}`,children:[(0,B.jsx)(`span`,{className:`dot${Ie?` dot--${Ie}`:``}`}),` `,Hr(s.status)]}):null,s&&Jr(s.total_cost_usd)?(0,B.jsx)(`span`,{className:`topbar__sub`,title:`Total cost across every stage in this run`,children:Jr(s.total_cost_usd)}):null,(0,B.jsx)(`span`,{className:`topbar__spacer`}),(0,B.jsx)(`button`,{className:`btn btn--primary`,disabled:ne,onClick:()=>void Ne(),children:ne?s?.status===`created`?`Starting…`:`Starting fresh…`:s?.status===`created`?`Start run`:`Start fresh`})]}),fe?(0,B.jsx)(`div`,{className:`banner banner--error`,style:{padding:`var(--spacing-3) var(--spacing-5)`},children:fe}):null,_e?(0,B.jsx)(`div`,{className:`banner banner--error`,style:{padding:`var(--spacing-3) var(--spacing-5)`},children:_e}):null,Se?(0,B.jsx)(`div`,{className:`banner banner--error`,style:{padding:`var(--spacing-3) var(--spacing-5)`},children:Se}):null,b?(0,B.jsx)(`div`,{className:`banner banner--error`,style:{padding:`var(--spacing-3) var(--spacing-5)`},children:b}):null]}),d&&!s?(0,B.jsx)(`div`,{style:{padding:`var(--spacing-4)`},children:(0,B.jsx)(`div`,{className:`banner banner--error`,children:d})}):!s||!R?(0,B.jsx)(`div`,{style:{padding:`var(--spacing-4)`},children:(0,B.jsx)(`p`,{children:`Loading…`})}):Re?(0,B.jsxs)(`div`,{className:`workspace`,children:[s.active_feedback_loop||(s.feedback_loops?.length??0)>0?(0,B.jsx)($p,{active:s.active_feedback_loop,history:s.feedback_loops??[]}):null,(0,B.jsx)(Th,{layout:R.spatialLayout,stages:s.stages,nodeChrome:R.nodeChrome,selectedStageId:R.selectedStageId,onSelectStage:e=>{C(e),i(e)},onDeselect:je,retryingStageIds:de,onRetryStage:he,resumingStageIds:ge,onResumeStage:be,abandoningStageId:xe,onAbandonStage:Ce,runId:e,showHint:!ze,feedbackOverlays:R.feedbackOverlays})]}):(0,B.jsx)(`div`,{style:{padding:`var(--spacing-4)`},children:(0,B.jsx)(`p`,{children:`No stages have started yet.`})}),ze&&s&&R?(0,B.jsxs)(`div`,{className:`work`,children:[(0,B.jsx)(`div`,{className:`work-split${P?` is-dragging`:``}`,role:`separator`,"aria-orientation":`horizontal`,"aria-label":`Resize workspace`,"aria-valuemin":We,"aria-valuemax":Ue,"aria-valuenow":Math.round(k),tabIndex:0,onPointerDown:e=>{(e.button==null||e.button===0)&&(e.preventDefault(),e.currentTarget.setPointerCapture(e.pointerId),F(!0),te.current={id:e.pointerId,y:e.clientY,h:k})},onPointerMove:e=>{let t=te.current;!t||t.id!==e.pointerId||Ae(t.h+(t.y-e.clientY))},onPointerUp:e=>{te.current?.id===e.pointerId&&(te.current=null,F(!1))},onPointerCancel:e=>{te.current?.id===e.pointerId&&(te.current=null,F(!1))},onKeyDown:e=>{e.key===`ArrowUp`&&(e.preventDefault(),Ae(k+jg)),e.key===`ArrowDown`&&(e.preventDefault(),Ae(k-jg)),e.key===`Home`&&(e.preventDefault(),Ae(Ue)),e.key===`End`&&(e.preventDefault(),Ae(We))},children:(0,B.jsx)(`span`,{className:`work-split__grip`,"aria-hidden":`true`})}),(0,B.jsxs)(`div`,{className:`work-row`,children:[(0,B.jsx)(`div`,{className:`aside`,style:{width:240,flexShrink:0,overflow:`auto`},children:(0,B.jsx)(Wc,{files:R.artifactFiles,selectedPath:Fe,onSelect:e=>{let t=zh(e);if(t){C(t),o(t);return}a(e)},footer:(0,B.jsx)(xc,{trigger:(0,B.jsx)(`span`,{style:{fontSize:`var(--font-size-sm)`,fontWeight:500},children:`Input`}),defaultIsOpen:!1,children:(0,B.jsx)(lc,{code:s.task_yaml,language:`yaml`,container:`section`,maxHeight:200,width:`100%`})})})}),(0,B.jsx)(`div`,{style:{flex:1,minWidth:0,minHeight:0,display:`flex`,flexDirection:`column`},children:He}),R.showFeedbackDecide&&R.feedbackDecide?(0,B.jsx)(`div`,{className:`decide`,style:{width:320,flexShrink:0},children:(0,B.jsx)(Jp,{runId:e,decide:R.feedbackDecide,onSuccess:ce})}):R.showDecide&&R.decidePrompt&&z?(0,B.jsx)(`div`,{className:`decide`,style:{width:320,flexShrink:0},children:(0,B.jsx)(zp,{runId:e,stageId:z.stage_id,prompt:R.decidePrompt,events:z.events,inboundEnvelope:R.inboundEnvelope,inboundFromStageId:R.inboundFromStageId,inboundToStageId:R.inboundToStageId,selectedPath:Fe,onSelectArtifact:a,onOpenInboundEnvelope:R.inboundFromStageId?()=>{let e=R.inboundFromStageId;e&&E(e)}:void 0})}):null]})]}):null]}),R?.drawer?(0,B.jsx)(Gp,{isOpen:!0,onClose:()=>E(null),fromStageId:R.drawer.fromStageId,toStageId:R.drawer.toStageId,envelope:R.drawer.envelope,onOpenFullRecord:()=>{let e=R.drawer?.fromStageId;E(null),e&&o(e)},onArtifactClick:e=>{E(null),a(e)}}):null]})}function Ig({label:e,status:t,index:n,meta:r,selected:i,onClick:a}){let o=Gr(t)||(n==null?``:String(n+1));return(0,B.jsxs)(`button`,{type:`button`,className:`node`,"data-s":t,"data-selected":i?`true`:void 0,onClick:a,"aria-disabled":!a,style:{cursor:a?`pointer`:`default`},children:[(0,B.jsx)(`span`,{className:`node__ring`,"aria-hidden":`true`,children:o}),(0,B.jsx)(`span`,{className:`node__name`,children:e}),r?(0,B.jsx)(`span`,{className:`node__meta`,children:r}):null]})}function Lg(e){return e===1?`1 file`:`${e} files`}function Rg({mode:e,flowed:t,envelope:n,fromStageId:r,selected:i,onEnvelopeClick:a}){let o=n==null,s=o?`no envelope yet`:`envelope · ${Lg(n.artifactCount)}`;return(0,B.jsxs)(`span`,{className:`wire`,"data-flowed":t?`true`:void 0,children:[(0,B.jsx)(`span`,{className:`wire__line`}),e===`definition`?null:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`button`,{className:`wire__env`,disabled:o||!a,"data-selected":i?`true`:void 0,onClick:o||!a?void 0:()=>a(r),children:s}),n?.summary?(0,B.jsx)(`span`,{className:`wire__summary`,children:n.summary}):null]})]})}function zg({stages:e,mode:t=`run`,onSelect:n,onEnvelopeClick:r,activeEnvelopeId:i}){return(0,B.jsx)(`nav`,{className:`track`,"aria-label":`Pipeline track`,children:(0,B.jsx)(`div`,{className:`track__rail`,children:e.map((a,o)=>(0,B.jsxs)(v.Fragment,{children:[(0,B.jsx)(Ig,{id:a.id,label:a.label,status:a.status,index:o,meta:a.meta,selected:a.selected,onClick:n&&a.status!==`pending`?()=>n(a.id):void 0}),o<e.length-1?(0,B.jsx)(Rg,{mode:t,flowed:a.envelope!=null,envelope:a.envelope,fromStageId:a.id,selected:i===a.id,onEnvelopeClick:r}):null]},a.id))})})}var Bg=`Providers are connected through Pi. Stageflow binds the credential store you choose; it is not a standalone non-Pi LLM client.`;function Vg(e){return e.credentialSource===void 0}function Hg(e){return e?`pi_home`:`sf_owned`}function Ug(e){return e.supportsApiKey}function Wg(e){return e.supportsOauth&&!e.supportsApiKey}function Gg(e){return e?e.configured?e.authKind===`oauth`?`Connected (OAuth)`:e.authKind===`api_key`?`Connected (API key)`:`Connected`:`Not connected`:`Unknown`}function Kg(e){return e.credentialSource===void 0?!1:e.credentialSource===`pi_home`||e.configuredCount>0}function qg(e){return e.filter(e=>e?.configured===!0).length}async function Jg(){let e=await zn();if(Vg(e))return{ready:!1,message:`Connect providers before starting a run. Choose an existing Pi login or add API keys in Stageflow.`};let t=e.credentialSource;if(t===`pi_home`)return{ready:!0,credentialSource:t};let n=await Rn();return Kg({credentialSource:t,configuredCount:qg(await Promise.all(n.providers.map(async e=>{try{let{provider:t}=await Bn(e.id);return t}catch{return}})))})?{ready:!0,credentialSource:t}:{ready:!1,credentialSource:t,message:`Connect at least one provider API key in Settings → Providers (or #/connect) before starting a run.`}}function Yg(e){return e===void 0?`all kinds`:e.length===0?`no gate`:`will ask you`}function Xg({onStarted:e,initialPipelinePath:t,initialTaskPath:n}){let[r,i]=(0,v.useState)([]),[a,o]=(0,v.useState)([]),[s,c]=(0,v.useState)(``),[l,u]=(0,v.useState)(``),[d,f]=(0,v.useState)(null),[p,m]=(0,v.useState)(!1),[h,g]=(0,v.useState)(null),[_,y]=(0,v.useState)(null),{snapshot:b,error:x}=pr(),S=b.health;(0,v.useEffect)(()=>{(async()=>{try{let[e,r]=await Promise.all([kn(),An()]);i(e.tasks),o(r.pipelines);let a=n&&e.tasks.some(e=>e.path===n)?n:e.tasks[0]?.path??``,s=t&&r.pipelines.some(e=>e.path===t)?t:r.pipelines[0]?.path??``;c(a),u(s)}catch(e){f(e instanceof Error?e.message:String(e))}})()},[t,n]);let C=a.find(e=>e.path===l)??null,w=(0,v.useMemo)(()=>C?C.stages.map(e=>({id:e.id,label:e.id,status:Mr(e.gate_kinds)?`waiting`:`pending`,meta:Yg(e.gate_kinds)})):[],[C]),T=S!=null&&S.slotsAvailable===0,E=S==null?0:Or(b,S.activeRunIds).length,D=d??(S==null&&x?x:null);async function O(){if(!s||!l){f(`Pick a task and a pipeline.`);return}m(!0),f(null),g(null),y(null);try{let e=await Jg();if(!e.ready){y(e.message??`Connect providers before starting a run.`),m(!1);return}}catch(e){y(e instanceof Error?e.message:String(e)),m(!1);return}let t=await Jn(s,l);if(m(!1),t.ok){e(t.runId);return}g(t)}return(0,B.jsxs)(`div`,{className:`main__inner`,children:[(0,B.jsxs)(`p`,{className:`crumbs`,children:[(0,B.jsx)(`a`,{href:`#/today`,children:`Today`}),` / start a run`]}),(0,B.jsx)(`div`,{className:`page-head`,children:(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`h1`,{children:`Start a run`}),(0,B.jsx)(`p`,{children:`A run is a task path plus a pipeline path. Nothing else is decided here.`})]})}),T&&S?(0,B.jsxs)(`div`,{className:`gate`,style:{padding:`var(--spacing-4)`,marginBottom:`var(--spacing-5)`},children:[(0,B.jsxs)(`div`,{className:`gate__label`,children:[(0,B.jsx)(`span`,{className:`dot dot--waiting`}),` No free session slots`]}),(0,B.jsxs)(`p`,{className:`gate__question`,children:[`All `,S.maxConcurrent,` slots are in use`,E>0?` — ${E===1?`one is`:`${E} are`} held by stages waiting on you`:``]}),S.activeRunIds.length>0?(0,B.jsxs)(`p`,{style:{margin:`var(--spacing-2) 0 0`,color:`var(--color-text-yellow)`,fontSize:`var(--font-size-sm)`},children:[`Blocking runs: `,S.activeRunIds.map((e,t)=>(0,B.jsxs)(v.Fragment,{children:[t>0?`, `:``,(0,B.jsx)(`a`,{href:`#/runs/${e}`,children:e.slice(0,8)})]},e))]}):null]}):null,_?(0,B.jsxs)(`div`,{className:`gate`,style:{padding:`var(--spacing-4)`,marginBottom:`var(--spacing-5)`},children:[(0,B.jsxs)(`div`,{className:`gate__label`,children:[(0,B.jsx)(`span`,{className:`dot dot--waiting`}),` Providers not ready`]}),(0,B.jsx)(`p`,{className:`gate__question`,children:_}),(0,B.jsxs)(`p`,{style:{margin:`var(--spacing-2) 0 0`,fontSize:`var(--font-size-sm)`},children:[(0,B.jsx)(`a`,{href:`#/connect`,children:`Connect providers`}),` · `,(0,B.jsx)(`a`,{href:`#/settings`,children:`Open Settings`})]})]}):null,h?(0,B.jsxs)(`div`,{className:`gate`,style:{padding:`var(--spacing-4)`,marginBottom:`var(--spacing-5)`,borderColor:`var(--color-border-red)`,borderLeftColor:`var(--color-error)`,background:`var(--color-background-red)`,color:`var(--color-text-red)`},children:[(0,B.jsx)(`div`,{className:`gate__label`,style:{color:`var(--color-text-red)`},children:`Could not start run`}),(0,B.jsx)(`p`,{className:`gate__question`,style:{color:`var(--color-text-primary)`},children:h.error})]}):null,D?(0,B.jsxs)(`p`,{style:{color:`var(--color-text-red)`,marginBottom:`var(--spacing-4)`},children:[`Could not start run: `,D]}):null,(0,B.jsxs)(`div`,{className:`grid-2`,children:[(0,B.jsx)(`div`,{children:(0,B.jsxs)(`section`,{className:`card`,children:[(0,B.jsx)(`div`,{className:`card__head`,children:(0,B.jsx)(`h2`,{children:`Task`})}),(0,B.jsx)(`div`,{className:`pick`,children:r.map(e=>(0,B.jsxs)(`label`,{className:`pick__opt`,children:[(0,B.jsx)(`input`,{type:`radio`,name:`task`,checked:s===e.path,onChange:()=>c(e.path)}),(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`strong`,{children:e.id}),(0,B.jsx)(`span`,{children:e.goal}),(0,B.jsx)(`span`,{className:`mono muted`,style:{display:`block`,fontSize:`var(--font-size-xs)`},children:e.path})]})]},e.path))})]})}),(0,B.jsx)(`div`,{children:(0,B.jsxs)(`section`,{className:`card`,children:[(0,B.jsx)(`div`,{className:`card__head`,children:(0,B.jsx)(`h2`,{children:`Pipeline`})}),(0,B.jsx)(`div`,{className:`pick`,children:a.map(e=>(0,B.jsxs)(`label`,{className:`pick__opt`,children:[(0,B.jsx)(`input`,{type:`radio`,name:`pipeline`,checked:l===e.path,onChange:()=>u(e.path)}),(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`strong`,{children:e.id}),(0,B.jsxs)(`span`,{children:[e.stages.length,` stages`]}),(0,B.jsx)(`span`,{className:`mono muted`,style:{display:`block`,fontSize:`var(--font-size-xs)`},children:e.path})]})]},e.path))}),w.length>0?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`div`,{className:`eyebrow`,style:{marginTop:`var(--spacing-4)`,marginBottom:`var(--spacing-3)`},children:`What will run`}),(0,B.jsx)(`div`,{className:`track track--inline`,children:(0,B.jsx)(zg,{stages:w,mode:`definition`})}),(0,B.jsx)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`,marginTop:`var(--spacing-3)`},children:w.filter(e=>e.status===`waiting`).length===0?`No stage in this pipeline is declared to stop for a human.`:`${w.filter(e=>e.status===`waiting`).length} ${w.filter(e=>e.status===`waiting`).length===1?`stage`:`stages`} will hold and wait for you.`})]}):null]})})]}),(0,B.jsxs)(`div`,{className:`form-actions`,style:{paddingBottom:`var(--spacing-8)`},children:[(0,B.jsx)(`button`,{className:`btn btn--primary`,disabled:!s||!l||T||p,onClick:()=>void O(),children:p?`Starting…`:`Start run`}),(0,B.jsx)(`a`,{className:`btn btn--ghost`,href:`#/today`,children:`Cancel`})]})]})}var Zg={waiting:`dot dot--waiting`,running:`dot dot--running`,failed:`dot dot--failed`,succeeded:`dot dot--succeeded`};function Qg({label:e,count:t,status:n,children:r}){return(0,B.jsxs)(`section`,{className:`zone`,children:[(0,B.jsxs)(`div`,{className:`zone__head`,children:[(0,B.jsx)(`span`,{className:Zg[n]}),(0,B.jsx)(`span`,{className:`eyebrow`,children:e}),(0,B.jsx)(`span`,{className:`zone__rule`}),(0,B.jsx)(`span`,{className:`zone__count`,children:t})]}),r]})}function $g({waiting:e,inFlight:t,broken:n,finished:r}){return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(Qg,{label:e.label,count:e.count,status:e.status,children:e.children}),(0,B.jsx)(Qg,{label:t.label,count:t.count,status:t.status,children:t.children}),(0,B.jsx)(Qg,{label:n.label,count:n.count,status:n.status,children:n.children}),(0,B.jsx)(Qg,{label:r.label,count:r.count,status:r.status,children:r.children})]})}function e_(e){return e===0?`Nothing needs you`:e===1?`One thing needs you`:`${e} things need you`}function t_(e){let t=e.waiting_stage_id??`this stage`;switch(e.waiting_kind){case`confirm`:return`Stage ${t} paused its session to ask. Rejecting sends your note back to the same session.`;case`artifact_backed`:return`Stage ${t} asked an artifact_backed prompt. Reject revises in the same session.`;case`multi_question`:return`Stage ${t} asked a multi_question prompt. All answers go back in one reply.`;case`free_text`:return`Stage ${t} asked a free_text prompt.`;case`feedback_loop_decision`:return`Feedback loop limit — decide extend, continue, or abandon`;default:return`Stage ${t} is waiting for input.`}}function n_(e){let t=e.waiting_artifacts?.[0];return t?{icon:`◆`,name:t.split(`/`).pop()??t}:{icon:`?`,name:e.waiting_kind??`waiting`}}function r_(e){let t=e.waiting_summary??`Waiting for input`;return t.length<=180?t:`${t.slice(0,180)}…`}var i_=400,a_=12;function o_(e){let t=e.split(`
|
|
117
|
+
`).slice(0,a_).join(`
|
|
118
|
+
`);return t.length>i_&&(t=`${t.slice(0,i_).trimEnd()}…`),t}function s_(e){let t=o_(e),n=t.split(`
|
|
119
|
+
`),r,i=[];for(let e of n){let t=e.match(/^#+\s+(.+)/);if(!r&&t?.[1]){r=t[1];continue}e.trim()&&i.push(e.replace(/^#+\s+/,``))}return(0,B.jsxs)(B.Fragment,{children:[r?(0,B.jsx)(`strong`,{children:r}):null,i.length>0?i.map((e,t)=>(0,B.jsx)(`p`,{children:e},t)):r?null:(0,B.jsx)(`p`,{children:t})]})}function c_({run:e}){let t=e.waiting_artifacts?.[0],[n,r]=(0,v.useState)(null);return(0,v.useEffect)(()=>{if(e.waiting_kind!==`artifact_backed`||!t){r(null);return}let n=!1;return ar(e.run_id,t).then(e=>{n||r(s_(e))}).catch(()=>{n||r(null)}),()=>{n=!0}},[e.run_id,e.waiting_kind,t]),e.waiting_kind===`multi_question`&&e.waiting_questions?.length?(0,B.jsx)(`span`,{className:`peek-doc`,children:e.waiting_questions.map((e,t)=>(0,B.jsx)(`p`,{children:e},t))}):(0,B.jsx)(`span`,{className:`peek-doc`,children:n??(0,B.jsx)(`p`,{children:r_(e)})})}function l_(e){let t=Pr(e.updated_at??e.created_at),n=Fr(e.stages,e.waiting_stage_id);return n?`held ${t} at ${n}`:`held ${t}`}function u_(e){let t=e.stages?.find(e=>e.status===`running`);return t?t.id:e.waiting_stage_id?e.waiting_stage_id:``}function d_({run:e,onOpen:t,onOpenArtifact:n}){let r=e.waiting_kind,i=r===`feedback_loop_decision`,a=!i&&e.waiting_prompt_id&&r?{promptId:e.waiting_prompt_id,kind:r}:null,{locked:o,error:s,submitIntent:c}=zc(e.run_id,e.waiting_stage_id,a),l=!i&&Tc({promptId:e.waiting_prompt_id,kind:i?null:r}),u=e.waiting_artifacts?.[0],d=n_(e),f=e.waiting_questions?.length??0;function p(){u?n(e.run_id,u):t(e.run_id)}return(0,B.jsxs)(`article`,{className:`block`,children:[(0,B.jsxs)(`div`,{className:`block__body`,children:[(0,B.jsxs)(`div`,{className:`block__meta`,children:[(0,B.jsx)(`a`,{className:`block__pipeline`,href:`#/pipelines/${e.pipeline_id}`,children:vr(e)}),(0,B.jsx)(`span`,{className:`status status--waiting`,children:l_(e)})]}),(0,B.jsx)(`p`,{className:`block__q`,children:e.waiting_summary??`Waiting for input`}),(0,B.jsx)(`p`,{className:`block__sub`,children:t_(e)}),s?(0,B.jsxs)(`p`,{style:{color:`var(--color-text-red)`,fontSize:`var(--font-size-sm)`},children:[`Could not accept: `,s]}):null,(0,B.jsxs)(`div`,{className:`block__actions`,children:[i?(0,B.jsx)(`button`,{className:`btn btn--primary`,onClick:()=>t(e.run_id),children:`Decide on run`}):null,l?(0,B.jsx)(`button`,{className:`btn btn--accept`,disabled:o,onClick:()=>void c({type:`decision`,decision:`accept`}),children:`Accept`}):null,r===`confirm`||r===`artifact_backed`?(0,B.jsx)(`button`,{className:`btn btn--reject`,onClick:()=>t(e.run_id),children:`Reject with note`}):null,r===`multi_question`?(0,B.jsx)(`button`,{className:`btn btn--primary`,onClick:()=>t(e.run_id),children:f>0?`Answer ${f} questions`:`Answer questions`}):null,r===`free_text`?(0,B.jsx)(`button`,{className:`btn btn--primary`,onClick:()=>t(e.run_id),children:`Answer`}):null,r===`artifact_backed`&&u?(0,B.jsxs)(`button`,{className:`btn`,onClick:()=>n(e.run_id,u),children:[`Read `,d.name]}):null,(0,B.jsx)(`button`,{className:`btn btn--ghost`,onClick:()=>t(e.run_id),children:`Open run`})]})]}),(0,B.jsxs)(`button`,{className:`block__peek`,onClick:p,"aria-label":u?`Open ${d.name}`:`Open run`,children:[(0,B.jsxs)(`span`,{className:`block__peek-name`,children:[(0,B.jsx)(`span`,{"aria-hidden":`true`,children:d.icon}),` `,d.name]}),(0,B.jsx)(c_,{run:e})]})]})}function f_({onOpen:e,onOpenArtifact:t,onNew:n,onSeeRuns:r}){let{snapshot:i,error:a,loading:o}=pr(),[s,c]=(0,v.useState)(null),[l,u]=(0,v.useState)(null),d=br(i),f=Cr(i),p=s??a;async function m(t){u(t);try{e((await Yn(t)).runId)}catch(e){c(e instanceof Error?e.message:String(e))}finally{u(null)}}let h=!o&&d.waiting.length===0&&d.inFlight.length===0&&d.broken.length===0&&d.finished.length===0,g=d.finished.slice(0,3);return(0,B.jsxs)(`div`,{className:`main__inner`,children:[(0,B.jsxs)(`div`,{className:`page-head`,children:[(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`h1`,{children:e_(d.waiting.length)}),(0,B.jsx)(`p`,{children:f.line})]}),(0,B.jsx)(`a`,{className:`btn btn--primary`,href:`#/new`,onClick:e=>{e.preventDefault(),n()},children:`Start a run`})]}),p?(0,B.jsxs)(`p`,{style:{color:`var(--color-text-red)`},children:[`Could not load runs: `,p]}):null,o?(0,B.jsx)(`p`,{className:`muted`,children:`Loading…`}):null,h?(0,B.jsx)(`div`,{className:`empty-hint`,children:`No runs yet. Start a pipeline to see triage zones fill in.`}):null,!o&&!h?(0,B.jsx)($g,{waiting:{label:Ur(),count:d.waiting.length,status:`waiting`,children:d.waiting.length===0?(0,B.jsx)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`},children:`Nothing waiting.`}):d.waiting.map(n=>(0,B.jsx)(d_,{run:n,onOpen:e,onOpenArtifact:t},n.run_id))},inFlight:{label:`In flight`,count:d.inFlight.length,status:`running`,children:d.inFlight.length===0?(0,B.jsx)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`},children:`No runs in flight.`}):(0,B.jsx)(`div`,{className:`runs`,children:d.inFlight.map(t=>(0,B.jsxs)(`a`,{className:`run-row`,href:`#/runs/${t.run_id}`,onClick:n=>{n.preventDefault(),e(t.run_id)},children:[(0,B.jsxs)(`span`,{className:`run-row__id`,children:[(0,B.jsx)(`span`,{className:`dot dot--running`}),(0,B.jsxs)(`span`,{className:`run-row__name`,children:[yr(t),` `,(0,B.jsxs)(`span`,{children:[`· `,u_(t)]})]})]}),(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`span`,{className:`track-mini`,"aria-hidden":`true`,children:t.stages.map(e=>{let t=Kr(e.status);return(0,B.jsx)(`i`,{className:`track-mini__seg`,...t?{"data-s":t}:{}},e.id)})}),(0,B.jsx)(`span`,{className:`track-mini__label`,children:Ir(t)})]}),(0,B.jsx)(`span`,{className:`run-row__right`,children:Pr(t.updated_at??t.created_at)})]},t.run_id))})},broken:{label:`Broken`,count:d.broken.length,status:`failed`,children:d.broken.length===0?(0,B.jsx)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`},children:`No failed runs.`}):d.broken.map(t=>(0,B.jsxs)(`div`,{className:`fail-row`,children:[(0,B.jsx)(`span`,{className:`dot dot--failed`}),(0,B.jsxs)(`span`,{className:`fail-row__why`,children:[(0,B.jsx)(`b`,{children:yr(t)}),` · `,vr(t),t.failed_reason?(0,B.jsx)(`span`,{children:t.failed_reason}):null]}),(0,B.jsx)(`button`,{className:`btn btn--sm`,onClick:n=>{n.stopPropagation(),e(t.run_id)},children:`Open stage`}),(0,B.jsx)(`button`,{className:`btn btn--sm`,disabled:l===t.run_id,onClick:e=>{e.stopPropagation(),m(t.run_id)},children:l===t.run_id?`Starting fresh…`:`Start fresh`})]},t.run_id))},finished:{label:`Finished`,count:d.finished.length,status:`succeeded`,children:d.finished.length===0?(0,B.jsx)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`},children:`No finished runs yet.`}):(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`div`,{className:`runs`,children:g.map(t=>(0,B.jsxs)(`a`,{className:`run-row`,href:`#/runs/${t.run_id}`,onClick:n=>{n.preventDefault(),e(t.run_id)},children:[(0,B.jsxs)(`span`,{className:`run-row__id`,children:[(0,B.jsx)(`span`,{className:`dot dot--succeeded`}),(0,B.jsxs)(`span`,{className:`run-row__name`,children:[yr(t),` `,(0,B.jsxs)(`span`,{children:[`· `,vr(t)]})]})]}),(0,B.jsxs)(`span`,{className:`mono muted`,children:[t.stages.length,` stages`]}),(0,B.jsx)(`span`,{className:`run-row__right`,children:Pr(t.updated_at??t.created_at)})]},t.run_id))}),(0,B.jsx)(`p`,{style:{margin:`var(--spacing-3) 0 0`},children:(0,B.jsx)(`button`,{className:`btn btn--sm btn--ghost`,onClick:r,children:`See every run →`})})]})}}):null]})}var p_=/^[a-z][a-z0-9]*(-[a-z0-9]+)*$/,m_=/^[a-z][a-z0-9]*(-[a-z0-9]+)*$/;function h_(e){let t={};e.directory.trim()||(t.directory=`Directory is required.`);let n=e.id.trim();if(n?(n.length>64||!p_.test(n))&&(t.id=`Id must be lowercase kebab-case.`):t.id=`Id is required.`,e.selectedStageIds.length===0)t.stages=`Add at least one stage id.`;else if(new Set(e.selectedStageIds).size!==e.selectedStageIds.length)t.stages=`A pipeline cannot repeat the same stage id.`;else{for(let n of e.selectedStageIds)if(!m_.test(n)){t.stages=`Stage id "${n}" must be lowercase kebab-case.`;break}if(!t.stages&&e.compositionMode===`dependencies`){let n=new Set(e.selectedStageIds);for(let r of e.selectedStageIds){let i=e.stageNeeds[r];if(i&&(!n.has(i)||i===r)){t.stages=`Stage "${r}" needs a stage that is in this pipeline.`;break}}}}return t}function g_(e,t){let n=t?.trim(),r;if(e===409)r=`Could not create pipeline: this id already exists.`;else if(e===422){let e=n?.toLowerCase()??``;r=e.includes(`cycle`)?`Could not create pipeline: dependency cycle detected.`:e.includes(`unknown needs`)?`Could not create pipeline: a stage needs another stage that is not in this pipeline.`:e.includes(`duplicate`)?`Could not create pipeline: the same stage was listed more than once.`:e.includes(`missing stage file`)?`Could not create pipeline: create stage files beside the pipeline directory first.`:`Could not create pipeline. Try again.`}else r=`Could not create pipeline. Try again.`;return n?`${r} ${n}`:r}function __(e){let t={};for(let n=1;n<e.length;n++)t[e[n]]=e[n-1];return t}function v_(e){let t=new Set;for(let n of e){let e=n.path.replace(/\\/g,`/`),r=e.lastIndexOf(`/`);t.add(r>=0?e.slice(0,r):`pipelines`)}return t.size===0&&t.add(`pipelines`),[...t].sort()}function y_({isOpen:e,onClose:t,onCreated:n,pipelines:r}){let i=v_(r),[a,o]=(0,v.useState)(i[0]??`pipelines`),[s,c]=(0,v.useState)(``),[l,u]=(0,v.useState)([]),[d,f]=(0,v.useState)(``),[p,m]=(0,v.useState)(`linear`),[h,g]=(0,v.useState)({}),[_,y]=(0,v.useState)({}),[b,x]=(0,v.useState)(null),[S,C]=(0,v.useState)(!1),w=(0,v.useRef)(!1);(0,v.useEffect)(()=>{e&&!w.current&&(o(v_(r)[0]??`pipelines`),c(``),u([]),f(``),m(`linear`),g({}),y({}),x(null)),w.current=e},[e,r]),(0,v.useEffect)(()=>{if(!e)return;function t(e){e.key===`Escape`&&j()}return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e]);function T(e){e!==p&&(g(e===`dependencies`?__(l):{}),m(e))}function E(){let e=d.trim();!e||l.includes(e)||(u(t=>[...t,e]),f(``))}function D(e,t){u(n=>{let r=e+t;if(r<0||r>=n.length)return n;let i=[...n],[a]=i.splice(e,1);return i.splice(r,0,a),p===`dependencies`&&g(__(i)),i})}function O(e){let t=l[e];u(t=>t.filter((t,n)=>n!==e)),g(e=>{let n={...e};delete n[t];for(let[e,r]of Object.entries(n))r===t&&delete n[e];return n})}function k(e,t){g(n=>{let r={...n};return t?r[e]=t:delete r[e],r})}async function A(){let e=s.trim(),t=a.trim(),r=h_({directory:t,id:e,selectedStageIds:l,compositionMode:p,stageNeeds:h});if(y(r),x(null),Object.keys(r).length>0)return;C(!0);let i=await Mn({directory:t,id:e,stages:l.map(e=>{if(p===`dependencies`){let t=h[e];return t?{id:e,uses:`./${e}.yaml`,needs:t}:{id:e,uses:`./${e}.yaml`}}return{id:e,uses:`./${e}.yaml`}})});if(C(!1),i.ok){n(i.pipeline);return}x(g_(i.status,i.error))}function j(){c(``),u([]),f(``),m(`linear`),g({}),y({}),x(null),t()}return e?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`button`,{type:`button`,className:`drawer-scrim`,"aria-label":`Close panel`,onClick:j}),(0,B.jsxs)(`aside`,{className:`drawer drawer--right`,"aria-labelledby":`new-pipeline-title`,children:[(0,B.jsxs)(`div`,{className:`drawer__head`,children:[(0,B.jsx)(`h2`,{id:`new-pipeline-title`,style:{margin:0,fontSize:`var(--font-size-lg)`},children:`New pipeline`}),(0,B.jsx)(`span`,{style:{marginLeft:`auto`}}),(0,B.jsx)(`button`,{type:`button`,className:`btn btn--sm`,onClick:j,children:`Close`})]}),(0,B.jsxs)(`div`,{className:`drawer__body`,children:[b?(0,B.jsx)(`div`,{className:`gate`,style:{padding:`var(--spacing-4)`,marginBottom:`var(--spacing-5)`,borderColor:`var(--color-border-red)`,borderLeftColor:`var(--color-error)`,background:`var(--color-background-red)`,color:`var(--color-text-red)`},children:(0,B.jsx)(`p`,{className:`gate__question`,style:{color:`var(--color-text-primary)`,margin:0},children:b})}):null,(0,B.jsxs)(`div`,{className:`form-field`,children:[(0,B.jsx)(`label`,{htmlFor:`new-pipeline-directory`,children:`Directory`}),(0,B.jsx)(`input`,{id:`new-pipeline-directory`,className:`input`,list:`pipeline-directory-options`,value:a,onChange:e=>o(e.target.value),autoComplete:`off`,spellCheck:!1}),(0,B.jsx)(`datalist`,{id:`pipeline-directory-options`,children:i.map(e=>(0,B.jsx)(`option`,{value:e},e))}),_.directory?(0,B.jsx)(`p`,{className:`field-error`,children:_.directory}):(0,B.jsxs)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`,marginTop:`var(--spacing-1)`},children:[`Repo-relative folder for `,(0,B.jsxs)(`span`,{className:`mono`,children:[s.trim()||`id`,`.pipeline.yaml`]}),` and stage files.`]})]}),(0,B.jsxs)(`div`,{className:`form-field`,children:[(0,B.jsx)(`label`,{htmlFor:`new-pipeline-id`,children:`Id`}),(0,B.jsx)(`input`,{id:`new-pipeline-id`,className:`input`,value:s,onChange:e=>c(e.target.value),autoComplete:`off`,spellCheck:!1}),_.id?(0,B.jsx)(`p`,{className:`field-error`,children:_.id}):null]}),(0,B.jsxs)(`div`,{className:`filters`,style:{marginTop:`var(--spacing-2)`},children:[(0,B.jsx)(`button`,{type:`button`,className:`tab`,"data-active":p===`linear`?`true`:void 0,onClick:()=>T(`linear`),children:`Linear`}),(0,B.jsx)(`button`,{type:`button`,className:`tab`,"data-active":p===`dependencies`?`true`:void 0,onClick:()=>T(`dependencies`),children:`Dependencies`})]}),(0,B.jsxs)(`div`,{className:`form-field`,children:[(0,B.jsx)(`span`,{className:`eyebrow`,children:`Stage ids`}),(0,B.jsxs)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`,margin:`var(--spacing-1) 0 var(--spacing-3)`},children:[`Each id maps to `,(0,B.jsx)(`span`,{className:`mono`,children:`./<id>.yaml`}),` beside the pipeline file. Create stage files first.`]}),(0,B.jsxs)(`div`,{style:{display:`flex`,gap:`var(--spacing-2)`,marginBottom:`var(--spacing-3)`},children:[(0,B.jsx)(`input`,{className:`input`,value:d,onChange:e=>f(e.target.value),placeholder:`stage-id`,autoComplete:`off`,spellCheck:!1,onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),E())}}),(0,B.jsx)(`button`,{type:`button`,className:`btn btn--sm`,onClick:E,children:`Add`})]}),l.length===0?(0,B.jsx)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`},children:`No stages added yet.`}):(0,B.jsx)(`ul`,{style:{listStyle:`none`,margin:0,padding:0},children:l.map((e,t)=>(0,B.jsxs)(`li`,{style:{display:`flex`,alignItems:`center`,gap:`var(--spacing-2)`,padding:`var(--spacing-2) 0`,borderBottom:`1px solid var(--color-border)`},children:[(0,B.jsxs)(`span`,{className:`mono`,style:{flex:p===`dependencies`?void 0:1},children:[t+1,`. `,e]}),p===`dependencies`?(0,B.jsxs)(`label`,{style:{display:`flex`,alignItems:`center`,gap:`var(--spacing-2)`,flex:1,fontSize:`var(--font-size-sm)`},children:[(0,B.jsx)(`span`,{className:`muted`,children:`Needs`}),(0,B.jsxs)(`select`,{className:`input`,value:h[e]??``,onChange:t=>k(e,t.target.value),style:{flex:1,minWidth:0},children:[(0,B.jsx)(`option`,{value:``,children:`(none — root)`}),l.filter(t=>t!==e).map(e=>(0,B.jsx)(`option`,{value:e,children:e},e))]})]}):null,(0,B.jsx)(`button`,{type:`button`,className:`btn btn--sm btn--ghost`,disabled:t===0,onClick:()=>D(t,-1),children:`Up`}),(0,B.jsx)(`button`,{type:`button`,className:`btn btn--sm btn--ghost`,disabled:t===l.length-1,onClick:()=>D(t,1),children:`Down`}),(0,B.jsx)(`button`,{type:`button`,className:`btn btn--sm btn--ghost`,onClick:()=>O(t),children:`Remove`})]},`${e}-${t}`))}),_.stages?(0,B.jsx)(`p`,{className:`field-error`,children:_.stages}):null]}),(0,B.jsxs)(`div`,{className:`form-actions`,children:[(0,B.jsx)(`button`,{type:`button`,className:`btn btn--primary`,disabled:S,onClick:()=>void A(),children:S?`Creating…`:`Create pipeline`}),(0,B.jsx)(`button`,{type:`button`,className:`btn btn--ghost`,onClick:j,children:`Cancel`})]})]})]})]}):null}function b_(e,t){return e===`all`?{}:e===`none`?{gate_kinds:[]}:{gate_kinds:t}}var x_=/^[a-z][a-z0-9]*(-[a-z0-9]+)*$/,S_=`__inherit__`,C_=`__other__`,w_=[`free_text`,`confirm`,`multi_question`,`artifact_backed`];function T_(e){let t={},n=e.id.trim();return n?(n.length>64||!x_.test(n))&&(t.id=`Id must be lowercase kebab-case.`):t.id=`Id is required.`,e.useDropdown&&e.modelSelect===`__other__`&&!e.model.trim()&&(t.model=`Model is required when Other is selected.`),e.system_prompt.trim()||(t.system_prompt=`System prompt is required.`),t}function E_(e){return e.useDropdown?e.modelSelect===`__inherit__`?``:e.modelSelect===`__other__`?e.customModel.trim():e.modelSelect.trim():e.plainModel.trim()}function D_(e,t){let n=e===409?`Could not create Stage: this id already exists.`:`Could not create Stage. Try again.`,r=t?.trim();return r?`${n} ${r}`:n}var O_=()=>({id:``,system_prompt:``,gateMode:`all`,gateKinds:[],modelSelect:S_,customModel:``,plainModel:``});function k_({isOpen:e,onClose:t,onCreated:n,pipelineDirectory:r}){let[i,a]=(0,v.useState)(O_),[o,s]=(0,v.useState)(null),[c,l]=(0,v.useState)(!1),[u,d]=(0,v.useState)({}),[f,p]=(0,v.useState)(null),[m,h]=(0,v.useState)(!1);(0,v.useEffect)(()=>{if(!e)return;let t=!1;return(async()=>{try{let{models:e}=await jn();if(t)return;e.length>0?(s(e),l(!0)):(s([]),l(!1))}catch{if(t)return;s(null),l(!1)}})(),()=>{t=!0}},[e]),(0,v.useEffect)(()=>{if(!e)return;function n(e){e.key===`Escape`&&t()}return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,t]);function g(){return E_({useDropdown:c,modelSelect:i.modelSelect,customModel:i.customModel,plainModel:i.plainModel})}function _(e){a(t=>({...t,gateKinds:t.gateKinds.includes(e)?t.gateKinds.filter(t=>t!==e):[...t.gateKinds,e]}))}async function y(){let e=g(),t={id:i.id.trim(),system_prompt:i.system_prompt,model:e},o=T_({...t,useDropdown:c,modelSelect:i.modelSelect});if(d(o),p(null),Object.keys(o).length>0)return;h(!0);let s=await Nn({pipeline_directory:r,filename:`${i.id.trim()}.yaml`,id:t.id,system_prompt:t.system_prompt,...e.length>0?{model:e}:{},...b_(i.gateMode,i.gateKinds)});if(h(!1),s.ok){a(O_()),d({}),p(null),n(s.stage);return}p(D_(s.status,s.error))}function b(){a(O_()),d({}),p(null),t()}return e?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`button`,{type:`button`,className:`drawer-scrim`,"aria-label":`Close panel`,onClick:b}),(0,B.jsxs)(`aside`,{className:`drawer drawer--right`,"aria-labelledby":`new-stage-title`,children:[(0,B.jsxs)(`div`,{className:`drawer__head`,children:[(0,B.jsx)(`h2`,{id:`new-stage-title`,style:{margin:0,fontSize:`var(--font-size-lg)`},children:`New stage`}),(0,B.jsx)(`span`,{style:{marginLeft:`auto`}}),(0,B.jsx)(`button`,{type:`button`,className:`btn btn--sm`,onClick:b,children:`Close`})]}),(0,B.jsxs)(`div`,{className:`drawer__body`,children:[f?(0,B.jsx)(`div`,{className:`gate`,style:{padding:`var(--spacing-4)`,marginBottom:`var(--spacing-5)`,borderColor:`var(--color-border-red)`,borderLeftColor:`var(--color-error)`,background:`var(--color-background-red)`,color:`var(--color-text-red)`},children:(0,B.jsx)(`p`,{className:`gate__question`,style:{color:`var(--color-text-primary)`,margin:0},children:f})}):null,(0,B.jsxs)(`div`,{className:`form-field`,children:[(0,B.jsx)(`label`,{htmlFor:`new-stage-id`,children:`Id`}),(0,B.jsx)(`input`,{id:`new-stage-id`,className:`input`,value:i.id,onChange:e=>a(t=>({...t,id:e.target.value})),autoComplete:`off`,spellCheck:!1}),u.id?(0,B.jsx)(`p`,{className:`field-error`,children:u.id}):(0,B.jsxs)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`,marginTop:`var(--spacing-1)`},children:[`Writes `,(0,B.jsxs)(`span`,{className:`mono`,children:[r,`/<id>.yaml`]}),`.`]})]}),(0,B.jsxs)(`div`,{className:`form-field`,children:[(0,B.jsx)(`label`,{htmlFor:`new-stage-model`,children:`Model`}),c&&o?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(`select`,{id:`new-stage-model`,className:`select`,value:i.modelSelect,onChange:e=>a(t=>({...t,modelSelect:e.target.value})),children:[(0,B.jsx)(`option`,{value:S_,children:`Inherit default`}),o.map(e=>(0,B.jsx)(`option`,{value:e,children:e},e)),(0,B.jsx)(`option`,{value:C_,children:`Other...`})]}),i.modelSelect===`__other__`?(0,B.jsx)(`input`,{className:`input`,style:{marginTop:`var(--spacing-2)`},value:i.customModel,onChange:e=>a(t=>({...t,customModel:e.target.value})),placeholder:`Model id`,autoComplete:`off`,spellCheck:!1}):null]}):(0,B.jsx)(`input`,{id:`new-stage-model`,className:`input`,value:i.plainModel,onChange:e=>a(t=>({...t,plainModel:e.target.value})),autoComplete:`off`,spellCheck:!1}),u.model?(0,B.jsx)(`p`,{className:`field-error`,children:u.model}):(0,B.jsx)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`,marginTop:`var(--spacing-1)`},children:`Optional. Inherits pipeline then global default when omitted.`})]}),(0,B.jsxs)(`div`,{className:`form-field`,children:[(0,B.jsx)(`label`,{htmlFor:`new-stage-prompt`,children:`System prompt`}),(0,B.jsx)(`textarea`,{id:`new-stage-prompt`,className:`textarea`,rows:6,value:i.system_prompt,onChange:e=>a(t=>({...t,system_prompt:e.target.value}))}),u.system_prompt?(0,B.jsx)(`p`,{className:`field-error`,children:u.system_prompt}):null]}),(0,B.jsxs)(`div`,{className:`form-field`,children:[(0,B.jsx)(`span`,{className:`eyebrow`,children:`HITL`}),(0,B.jsx)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`,margin:`var(--spacing-1) 0 var(--spacing-3)`},children:`All kinds keeps every ask kind available. No HITL unregisters ask_operator. Allowlist restricts kinds.`}),(0,B.jsxs)(`div`,{className:`pick`,children:[(0,B.jsxs)(`label`,{className:`pick__opt`,children:[(0,B.jsx)(`input`,{type:`radio`,name:`new-stage-hitl`,checked:i.gateMode===`all`,onChange:()=>a(e=>({...e,gateMode:`all`}))}),(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`strong`,{children:`All kinds`}),(0,B.jsx)(`span`,{className:`muted`,children:` Compatible default. Every ask kind is available.`})]})]}),(0,B.jsxs)(`label`,{className:`pick__opt`,children:[(0,B.jsx)(`input`,{type:`radio`,name:`new-stage-hitl`,checked:i.gateMode===`none`,onChange:()=>a(e=>({...e,gateMode:`none`}))}),(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`strong`,{children:`No HITL`}),(0,B.jsx)(`span`,{className:`muted`,children:` Writes gate_kinds: []. The stage cannot ask the operator.`})]})]}),(0,B.jsxs)(`label`,{className:`pick__opt`,children:[(0,B.jsx)(`input`,{type:`radio`,name:`new-stage-hitl`,checked:i.gateMode===`allowlist`,onChange:()=>a(e=>({...e,gateMode:`allowlist`}))}),(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`strong`,{children:`Allowlist`}),(0,B.jsx)(`span`,{className:`muted`,children:` Only the kinds you select.`})]})]})]}),i.gateMode===`allowlist`?(0,B.jsx)(`div`,{className:`pick`,style:{marginTop:`var(--spacing-3)`},children:w_.map(e=>(0,B.jsxs)(`label`,{className:`pick__opt`,children:[(0,B.jsx)(`input`,{type:`checkbox`,checked:i.gateKinds.includes(e),onChange:()=>_(e)}),(0,B.jsx)(`span`,{children:(0,B.jsx)(`strong`,{className:`mono`,children:e})})]},e))}):null]}),(0,B.jsxs)(`div`,{className:`form-actions`,children:[(0,B.jsx)(`button`,{type:`button`,className:`btn btn--primary`,disabled:m,onClick:()=>void y(),children:m?`Creating…`:`Create stage`}),(0,B.jsx)(`button`,{type:`button`,className:`btn btn--ghost`,onClick:b,children:`Cancel`})]})]})]})]}):null}function A_(e){window.location.hash=e.startsWith(`#`)?e:`#${e}`}function j_(e){return`/runs/${encodeURIComponent(e)}`}function M_(e,t){return`/runs/${encodeURIComponent(e)}/stages/${encodeURIComponent(t)}`}function N_(e,t){return`/runs/${encodeURIComponent(e)}/artifacts?path=${encodeURIComponent(t)}`}function P_(e,t){return`/runs/${encodeURIComponent(e)}/stages/${encodeURIComponent(t)}/envelope`}function F_(e){return`/pipelines/${encodeURIComponent(e)}`}function I_(e){return`/tasks/${encodeURIComponent(e)}`}function L_(e){return`/skills/${encodeURIComponent(e)}`}function R_(e,t){return`/extensions/packages/${encodeURIComponent(e)}/${encodeURIComponent(t)}`}function z_(e){return`/extensions/files/${encodeURIComponent(e)}`}function B_(e){let t=new URLSearchParams;e?.pipeline&&t.set(`pipeline`,e.pipeline),e?.task&&t.set(`task`,e.task);let n=t.toString();return n?`/new?${n}`:`/new`}function V_(e){let t=e.replace(/^#\/?/,``),n=t.indexOf(`?`);return n<0?{path:t,params:new URLSearchParams}:{path:t.slice(0,n),params:new URLSearchParams(t.slice(n+1))}}function H_(e){let t=e.indexOf(`/`),n=t<0?e:e.slice(0,t);return n?decodeURIComponent(n):``}function U_(e=window.location.hash){let{path:t,params:n}=V_(e);if(!t||t===`today`)return{name:`today`};if(t===`runs`)return{name:`runs`};if(t===`new`){let e=n.get(`pipeline`)??void 0,t=n.get(`task`)??void 0;return{name:`new`,...e?{pipelineId:e}:{},...t?{taskPath:t}:{}}}if(t===`pipelines`)return{name:`pipelines`};if(t.startsWith(`pipelines/`)){let e=H_(t.slice(10));if(e)return{name:`pipeline`,pipelineId:e}}if(t===`tasks`)return{name:`tasks`};if(t.startsWith(`tasks/`)){let e=H_(t.slice(6));if(e)return{name:`task`,taskId:e}}if(t===`skills`)return{name:`skills`};if(t.startsWith(`skills/`)){let e=H_(t.slice(7));if(e)return{name:`skill`,skillName:e}}if(t===`extensions`)return{name:`extensions`};if(t.startsWith(`extensions/packages/`)){let e=t.slice(20),n=e.indexOf(`/`);if(n>0){let t=decodeURIComponent(e.slice(0,n)),r=decodeURIComponent(e.slice(n+1));if((t===`user`||t===`project`)&&r)return{name:`extensionPackage`,scope:t,source:r}}}if(t.startsWith(`extensions/files/`)){let e=decodeURIComponent(t.slice(17));if(e)return{name:`extensionFile`,path:e}}if(t===`settings`)return{name:`settings`};if(t===`connect`)return{name:`connect`};if(t.startsWith(`runs/`)){let e=t.slice(5).split(`/`),r=decodeURIComponent(e[0]??``);if(!r)return{name:`today`};if(e[1]===`stages`&&e[3]===`envelope`&&e[2]&&e.length===4)return{name:`detail`,runId:r,view:{kind:`envelope`,stageId:decodeURIComponent(e[2])}};if(e[1]===`stages`&&e[2]&&e.length===3)return{name:`detail`,runId:r,view:{kind:`stream`,stageId:decodeURIComponent(e[2])}};if(e[1]===`artifacts`&&e.length===2){let e=n.get(`path`);if(e)return{name:`detail`,runId:r,view:{kind:`artifact`,path:e}}}return e.length,{name:`detail`,runId:r,view:{kind:`stream`}}}return{name:`today`}}function W_({status:e}){let t=Vr(e),n=t&&t!==`running`?`status status--${t}`:`status`,r=t?`dot dot--${t}`:`dot`;return(0,B.jsxs)(`span`,{className:n,children:[(0,B.jsx)(`span`,{className:r}),` `,Hr(e)]})}var G_=null,K_=null;function q_(e,t=4e3){G_||(G_=document.createElement(`div`),G_.className=`toast`,G_.setAttribute(`role`,`status`),document.body.appendChild(G_)),G_.textContent=e,G_.setAttribute(`data-show`,`true`),K_&&clearTimeout(K_),K_=setTimeout(()=>{G_?.setAttribute(`data-show`,`false`)},t)}function J_(e){return e.map(e=>{let t=e.gate_kinds;return{id:e.id,label:e.id,status:Mr(t)?`waiting`:`pending`,meta:Y_(t)}})}function Y_(e){return e===void 0?`all kinds`:e.length===0?`none`:e.join(` · `)}function X_(e){return e.inline?`inline`:e.uses_path?e.uses_path:`—`}function Z_(e){let t=e.replace(/\\/g,`/`),n=t.lastIndexOf(`/`);return n>=0?t.slice(0,n):`.`}function Q_(e,t){let n=Z_(e.path);return t.filter(e=>n===`.`?!e.path.includes(`/`):e.path.startsWith(`${n}/`))[0]?.path??t[0]?.path}function $_({stages:e}){return(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`span`,{className:`mini`,"aria-hidden":`true`,children:e.map((e,t)=>(0,B.jsxs)(v.Fragment,{children:[t>0?(0,B.jsx)(`i`,{className:`mini__w`}):null,(0,B.jsx)(`i`,{className:`mini__n`,"data-s":Mr(e.gate_kinds)?`waiting`:void 0,children:Mr(e.gate_kinds)?`?`:String(t+1)})]},e.id))}),(0,B.jsx)(`span`,{className:`mini__label`,style:{display:`block`},children:e.map(e=>e.id).join(` · `)})]})}function ev({pipelineId:e,onNew:t}){let{snapshot:n,error:r,loading:i}=pr(),[a,o]=(0,v.useState)([]),[s,c]=(0,v.useState)([]),[l,u]=(0,v.useState)(null),[d,f]=(0,v.useState)(!0),[p,m]=(0,v.useState)(!1),[h,g]=(0,v.useState)(!1),_=(0,v.useCallback)(async()=>{try{let[e,t]=await Promise.all([An(),kn()]);o(e.pipelines),c(t.tasks),u(null)}catch(e){u(e instanceof Error?e.message:String(e))}finally{f(!1)}},[]);(0,v.useEffect)(()=>{_()},[_]);let y=d||i,b=l??r,x=e?a.find(t=>t.id===e)??null:null,S=x?Er(n,x):[];async function C(e){g(!1);try{let e=await An();o(e.pipelines),u(null)}catch(e){u(e instanceof Error?e.message:String(e))}q_(`Pipeline created · ${e.id}`),t(F_(e.id))}return e?(0,B.jsx)(tv,{pipelineId:e,pipeline:x,tasks:s,runs:S,loading:y,error:b,onNew:t,onStageCreated:()=>void _(),stagePanelOpen:p,onOpenStagePanel:()=>m(!0),onCloseStagePanel:()=>m(!1)}):(0,B.jsxs)(`div`,{className:`main__inner main__inner--wide`,children:[(0,B.jsxs)(`div`,{className:`page-head`,children:[(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`h1`,{children:`Pipelines`}),(0,B.jsx)(`p`,{children:`Manifest-declared pipeline files and their embedded stages. Each row shows its chain and which stages will stop for a human.`})]}),(0,B.jsx)(`button`,{type:`button`,className:`btn btn--primary`,onClick:()=>g(!0),children:`New pipeline`})]}),b?(0,B.jsx)(`p`,{style:{color:`var(--color-text-red)`},children:b}):null,y?(0,B.jsx)(`p`,{className:`muted`,children:`Loading pipelines…`}):null,!y&&a.length===0?(0,B.jsxs)(`div`,{className:`empty-hint`,children:[(0,B.jsxs)(`p`,{style:{margin:`0 0 var(--spacing-3)`},children:[`No pipelines in the manifest yet. Add a `,(0,B.jsx)(`span`,{className:`mono`,children:`stageflow.yaml`}),` catalog entry or run`,` `,(0,B.jsx)(`span`,{className:`mono`,children:`sf init`}),`.`]}),(0,B.jsx)(`button`,{type:`button`,className:`btn btn--primary`,onClick:()=>g(!0),children:`New pipeline`})]}):null,!y&&a.length>0?(0,B.jsx)(B.Fragment,{children:a.map(e=>{let t=Er(n,e),r=Nr(e.stages);return(0,B.jsxs)(`a`,{className:`rrow`,href:`#${F_(e.id)}`,children:[(0,B.jsxs)(`span`,{className:`rrow__id`,children:[(0,B.jsx)(`span`,{className:`rrow__task`,children:e.id}),(0,B.jsx)(`span`,{className:`rrow__pipe`,children:e.path})]}),(0,B.jsxs)(`span`,{className:`rrow__right`,children:[r===1?`1 gate`:`${r} gates`,(0,B.jsx)(`br`,{}),(0,B.jsxs)(`span`,{className:`mono`,style:{fontSize:`var(--font-size-xs)`},children:[t.length,` `,t.length===1?`run`:`runs`]})]}),(0,B.jsx)(`span`,{className:`rrow__track`,children:(0,B.jsx)($_,{stages:e.stages})})]},`${e.path}:${e.id}`)})}):null,(0,B.jsx)(y_,{isOpen:h,onClose:()=>g(!1),onCreated:e=>void C(e),pipelines:a})]})}function tv({pipelineId:e,pipeline:t,tasks:n,runs:r,loading:i,error:a,onNew:o,onStageCreated:s,stagePanelOpen:c,onOpenStagePanel:l,onCloseStagePanel:u}){let d=(0,v.useMemo)(()=>t?J_(t.stages):[],[t]),f=t?Nr(t.stages):0,p=t?`${t.path} · ${t.stages.length} stages · ${f===1?`1 gate`:`${f} gates`} · ${r.length} ${r.length===1?`run`:`runs`}`:e,m=t?Q_(t,n):void 0;return(0,B.jsxs)(`div`,{className:`main__inner`,children:[(0,B.jsxs)(`p`,{className:`crumbs`,children:[(0,B.jsx)(`a`,{href:`#/pipelines`,children:`Pipelines`}),` / `,e]}),(0,B.jsxs)(`div`,{className:`page-head`,children:[(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`h1`,{children:e}),(0,B.jsx)(`p`,{className:`mono`,children:p})]}),t?(0,B.jsx)(`button`,{className:`btn btn--primary`,onClick:()=>o(B_({pipeline:t.path,...m?{task:m}:{}})),children:`Start a run with this`}):null]}),a?(0,B.jsx)(`p`,{style:{color:`var(--color-text-red)`},children:a}):null,i?(0,B.jsx)(`p`,{className:`muted`,children:`Loading…`}):null,!i&&!t?(0,B.jsxs)(`p`,{className:`muted`,children:[e,` is not in the current manifest catalog.`]}):null,t?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(zg,{stages:d,mode:`definition`}),(0,B.jsxs)(`div`,{className:`page-head`,style:{marginTop:`var(--spacing-6)`},children:[(0,B.jsx)(`h3`,{style:{margin:0},children:`Stages`}),(0,B.jsx)(`button`,{type:`button`,className:`btn btn--sm`,onClick:l,children:`Add stage file`})]}),(0,B.jsxs)(`table`,{className:`table`,children:[(0,B.jsx)(`thead`,{children:(0,B.jsxs)(`tr`,{children:[(0,B.jsx)(`th`,{children:`Stage`}),(0,B.jsx)(`th`,{children:`Gate`}),(0,B.jsx)(`th`,{children:`Source`})]})}),(0,B.jsx)(`tbody`,{children:t.stages.map(e=>(0,B.jsxs)(`tr`,{children:[(0,B.jsx)(`td`,{className:`mono`,children:e.id}),(0,B.jsx)(`td`,{className:`muted`,children:Y_(e.gate_kinds)}),(0,B.jsx)(`td`,{className:`mono muted`,children:X_(e)})]},e.id))})]}),(0,B.jsx)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`,marginTop:`var(--spacing-3)`},children:f===1?`Only one stage stops for a human. That is worth knowing before you start a run, not after.`:f===0?`No stage in this pipeline is declared to stop for a human.`:`${f} stages stop for a human.`}),(0,B.jsx)(`h3`,{style:{marginTop:`var(--spacing-6)`},children:`Recent runs`}),r.length===0?(0,B.jsx)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`},children:`No runs of this pipeline yet.`}):(0,B.jsxs)(`table`,{className:`table`,children:[(0,B.jsx)(`thead`,{children:(0,B.jsxs)(`tr`,{children:[(0,B.jsx)(`th`,{children:`Task`}),(0,B.jsx)(`th`,{children:`Status`}),(0,B.jsx)(`th`,{children:`When`})]})}),(0,B.jsx)(`tbody`,{children:r.map(e=>(0,B.jsxs)(`tr`,{children:[(0,B.jsxs)(`td`,{children:[(0,B.jsx)(`a`,{href:`#${j_(e.run_id)}`,children:yr(e)}),e.task_path?(0,B.jsx)(`span`,{className:`muted mono`,style:{display:`block`,fontSize:`var(--font-size-xs)`},children:hr(e.task_path,e.project_root)}):null]}),(0,B.jsx)(`td`,{children:(0,B.jsx)(W_,{status:Br(e)})}),(0,B.jsx)(`td`,{className:`muted`,children:Pr(e.created_at)})]},e.run_id))})]})]}):null,(0,B.jsx)(k_,{isOpen:c,onClose:u,pipelineDirectory:t?Z_(t.path):`pipelines`,onCreated:e=>{u(),s()}})]})}function nv({taskId:e,onNew:t}){let{snapshot:n,error:r,loading:i}=pr(),[a,o]=(0,v.useState)([]),[s,c]=(0,v.useState)(null),[l,u]=(0,v.useState)(!0),d=(0,v.useCallback)(async()=>{try{let e=await kn();o(e.tasks),c(null)}catch(e){c(e instanceof Error?e.message:String(e))}finally{u(!1)}},[]);(0,v.useEffect)(()=>{d()},[d]);let f=l||i,p=s??r,m=e?a.find(t=>t.id===e)??null:null,h=m?Tr(n,m.id):[];return e?(0,B.jsx)(rv,{taskId:e,task:m,runs:h,loading:f,error:p,onNew:t}):(0,B.jsxs)(`div`,{className:`main__inner main__inner--wide`,children:[(0,B.jsx)(`div`,{className:`page-head`,children:(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`h1`,{children:`Tasks`}),(0,B.jsx)(`p`,{children:`A task is a brief plus the pipeline it should run through. Tasks are reusable; runs are not.`})]})}),p?(0,B.jsx)(`p`,{style:{color:`var(--color-text-red)`},children:p}):null,f?(0,B.jsx)(`p`,{className:`muted`,children:`Loading tasks…`}):null,!f&&a.length===0?(0,B.jsx)(`p`,{className:`muted`,children:`No tasks yet. Add a YAML file under tasks/ in this project.`}):null,!f&&a.length>0?(0,B.jsxs)(`table`,{className:`table`,children:[(0,B.jsx)(`thead`,{children:(0,B.jsxs)(`tr`,{children:[(0,B.jsx)(`th`,{children:`Task`}),(0,B.jsx)(`th`,{children:`Pipeline`}),(0,B.jsx)(`th`,{children:`Runs`}),(0,B.jsx)(`th`,{children:`Last result`}),(0,B.jsx)(`th`,{})]})}),(0,B.jsx)(`tbody`,{children:a.map(e=>{let r=Tr(n,e.id),i=r[0],a=i?Br(i):void 0,o=i?.pipeline_id;return(0,B.jsxs)(`tr`,{children:[(0,B.jsxs)(`td`,{children:[(0,B.jsx)(`a`,{href:`#${I_(e.id)}`,children:e.id}),(0,B.jsx)(`div`,{className:`muted`,style:{fontSize:`var(--font-size-xs)`},children:e.goal})]}),(0,B.jsx)(`td`,{className:`mono`,children:o??`—`}),(0,B.jsx)(`td`,{className:`mono`,children:r.length}),(0,B.jsx)(`td`,{children:a?(0,B.jsx)(W_,{status:a}):(0,B.jsx)(`span`,{className:`muted`,children:`no runs`})}),(0,B.jsx)(`td`,{style:{textAlign:`right`},children:i?(0,B.jsx)(`a`,{className:`btn btn--sm`,href:`#${j_(i.run_id)}`,children:`Open run`}):(0,B.jsx)(`button`,{className:`btn btn--sm`,onClick:()=>t(B_({task:e.path})),children:`Run it`})})]},e.id)})})]}):null]})}function rv({taskId:e,task:t,runs:n,loading:r,error:i,onNew:a}){let o=n[0],s=br({runs:n,health:null}),c=s.waiting.length+s.inFlight.length,l=t?`${t.path} · ${n.length} ${n.length===1?`run`:`runs`}${c>0?` · ${c} in flight`:``}`:e;return(0,B.jsxs)(`div`,{className:`main__inner`,children:[(0,B.jsxs)(`p`,{className:`crumbs`,children:[(0,B.jsx)(`a`,{href:`#/tasks`,children:`Tasks`}),` / `,e]}),(0,B.jsxs)(`div`,{className:`page-head`,children:[(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`h1`,{children:e}),(0,B.jsx)(`p`,{className:`mono`,children:l})]}),t?(0,B.jsx)(`button`,{className:`btn btn--primary`,onClick:()=>a(B_({task:t.path,pipeline:o?.pipeline_id})),children:`Run it again`}):null]}),i?(0,B.jsx)(`p`,{style:{color:`var(--color-text-red)`},children:i}):null,r?(0,B.jsx)(`p`,{className:`muted`,children:`Loading…`}):null,!r&&!t?(0,B.jsxs)(`p`,{className:`muted`,children:[e,` is not in this project's tasks/ catalog.`]}):null,t?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`h3`,{children:`Brief`}),(0,B.jsx)(`p`,{children:t.goal}),(0,B.jsx)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`},children:`Pipeline`}),o?(0,B.jsx)(`a`,{href:`#${F_(o.pipeline_id)}`,style:{fontWeight:500},children:o.pipeline_id}):(0,B.jsx)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`},children:`No runs yet — pick a pipeline when you start one.`}),(0,B.jsx)(`h3`,{style:{marginTop:`var(--spacing-6)`},children:`Run history`}),n.length===0?(0,B.jsx)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`},children:`No runs of this task yet.`}):(0,B.jsxs)(`table`,{className:`table`,children:[(0,B.jsx)(`thead`,{children:(0,B.jsxs)(`tr`,{children:[(0,B.jsx)(`th`,{children:`Run`}),(0,B.jsx)(`th`,{children:`Status`}),(0,B.jsx)(`th`,{children:`Pipeline`}),(0,B.jsx)(`th`,{children:`When`})]})}),(0,B.jsx)(`tbody`,{children:n.map(e=>(0,B.jsxs)(`tr`,{children:[(0,B.jsx)(`td`,{children:(0,B.jsx)(`a`,{href:`#${j_(e.run_id)}`,children:e.run_id})}),(0,B.jsx)(`td`,{children:(0,B.jsx)(W_,{status:Br(e)})}),(0,B.jsx)(`td`,{children:(0,B.jsx)(`a`,{href:`#${F_(e.pipeline_id)}`,children:e.pipeline_id})}),(0,B.jsx)(`td`,{className:`muted`,children:Pr(e.created_at)})]},e.run_id))})]})]}):null]})}function iv({skillName:e}){let[t,n]=(0,v.useState)([]),[r,i]=(0,v.useState)(null),[a,o]=(0,v.useState)(!0),s=(0,v.useCallback)(async()=>{try{let e=await Pn();n(e.skills),i(null)}catch(e){i(e instanceof Error?e.message:String(e))}finally{o(!1)}},[]);(0,v.useEffect)(()=>{s()},[s]);let c=e?t.find(t=>t.name===e)??null:null;return e?(0,B.jsx)(av,{skillName:e,skill:c,loading:a,error:r}):(0,B.jsxs)(`div`,{className:`main__inner main__inner--wide`,children:[(0,B.jsx)(`div`,{className:`page-head`,children:(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`h1`,{children:`Skills`}),(0,B.jsx)(`p`,{children:`Skills the Pi SDK can discover on this machine. Factory stages do not load them.`})]})}),r?(0,B.jsx)(`p`,{style:{color:`var(--color-text-red)`},children:r}):null,a?(0,B.jsx)(`p`,{className:`muted`,children:`Loading skills…`}):null,!a&&t.length===0?(0,B.jsx)(`p`,{className:`muted`,children:`No skills found under ~/.pi/agent/skills, ~/.agents/skills, or this project's .pi/skills / .agents/skills.`}):null,!a&&t.length>0?(0,B.jsxs)(`table`,{className:`table`,children:[(0,B.jsx)(`thead`,{children:(0,B.jsxs)(`tr`,{children:[(0,B.jsx)(`th`,{children:`Skill`}),(0,B.jsx)(`th`,{children:`Scope`}),(0,B.jsx)(`th`,{children:`Source`}),(0,B.jsx)(`th`,{children:`Invocation`})]})}),(0,B.jsx)(`tbody`,{children:t.map(e=>(0,B.jsxs)(`tr`,{children:[(0,B.jsxs)(`td`,{children:[(0,B.jsx)(`a`,{href:`#${L_(e.name)}`,children:e.name}),(0,B.jsx)(`div`,{className:`muted`,style:{fontSize:`var(--font-size-xs)`},children:e.description})]}),(0,B.jsx)(`td`,{className:`mono`,children:e.scope}),(0,B.jsx)(`td`,{className:`mono`,children:e.source}),(0,B.jsx)(`td`,{className:`mono`,children:e.disableModelInvocation?`command-only`:`model`})]},`${e.scope}:${e.filePath}`))})]}):null]})}function av({skillName:e,skill:t,loading:n,error:r}){return(0,B.jsxs)(`div`,{className:`main__inner`,children:[(0,B.jsxs)(`p`,{className:`crumbs`,children:[(0,B.jsx)(`a`,{href:`#/skills`,children:`Skills`}),` / `,e]}),(0,B.jsx)(`div`,{className:`page-head`,children:(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`h1`,{children:e}),(0,B.jsx)(`p`,{className:`mono`,children:t?`${t.scope} · ${t.source}`:e})]})}),r?(0,B.jsx)(`p`,{style:{color:`var(--color-text-red)`},children:r}):null,n?(0,B.jsx)(`p`,{className:`muted`,children:`Loading…`}):null,!n&&!t?(0,B.jsxs)(`p`,{className:`muted`,children:[e,` is not in the Pi skill catalog on this machine.`]}):null,t?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`h3`,{children:`Description`}),(0,B.jsx)(`p`,{children:t.description}),(0,B.jsx)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`},children:`Invocation`}),(0,B.jsx)(`p`,{className:`mono`,children:t.disableModelInvocation?`command-only`:`model`}),(0,B.jsx)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`},children:`File path`}),(0,B.jsx)(`p`,{className:`mono`,children:t.filePath}),(0,B.jsx)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`},children:`Base dir`}),(0,B.jsx)(`p`,{className:`mono`,children:t.baseDir})]}):null]})}function ov({packageScope:e,packageSource:t,filePath:n}){let[r,i]=(0,v.useState)([]),[a,o]=(0,v.useState)([]),[s,c]=(0,v.useState)(null),[l,u]=(0,v.useState)(!0),d=(0,v.useCallback)(async()=>{try{let e=await Fn();i(e.packages),o(e.extensions),c(null)}catch(e){c(e instanceof Error?e.message:String(e))}finally{u(!1)}},[]);if((0,v.useEffect)(()=>{d()},[d]),e&&t){let n=r.find(n=>n.scope===e&&n.source===t)??null;return(0,B.jsx)(sv,{scope:e,source:t,pkg:n,loading:l,error:s})}if(n){let e=a.find(e=>e.path===n)??null;return(0,B.jsx)(cv,{filePath:n,file:e,loading:l,error:s})}let f=!l&&r.length===0&&a.length===0;return(0,B.jsxs)(`div`,{className:`main__inner main__inner--wide`,children:[(0,B.jsx)(`div`,{className:`page-head`,children:(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`h1`,{children:`Extensions`}),(0,B.jsx)(`p`,{children:`Extensions the Pi SDK can discover on this machine. Factory stages do not load them.`})]})}),s?(0,B.jsx)(`p`,{style:{color:`var(--color-text-red)`},children:s}):null,l?(0,B.jsx)(`p`,{className:`muted`,children:`Loading extensions…`}):null,f?(0,B.jsx)(`p`,{className:`muted`,children:`No extensions found under ~/.pi/agent/extensions, this project's .pi/extensions, or packages in Pi settings.`}):null,!l&&r.length>0?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`h3`,{children:`Packages`}),(0,B.jsxs)(`table`,{className:`table`,children:[(0,B.jsx)(`thead`,{children:(0,B.jsxs)(`tr`,{children:[(0,B.jsx)(`th`,{children:`Source`}),(0,B.jsx)(`th`,{children:`Scope`}),(0,B.jsx)(`th`,{children:`Installed`})]})}),(0,B.jsx)(`tbody`,{children:r.map(e=>(0,B.jsxs)(`tr`,{children:[(0,B.jsx)(`td`,{children:(0,B.jsx)(`a`,{href:`#${R_(e.scope,e.source)}`,children:e.source})}),(0,B.jsx)(`td`,{className:`mono`,children:e.scope}),(0,B.jsx)(`td`,{className:`mono`,children:e.installedPath??`not installed`})]},`${e.scope}:${e.source}`))})]})]}):null,!l&&a.length>0?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`h3`,{children:`Files`}),(0,B.jsxs)(`table`,{className:`table`,children:[(0,B.jsx)(`thead`,{children:(0,B.jsxs)(`tr`,{children:[(0,B.jsx)(`th`,{children:`Name`}),(0,B.jsx)(`th`,{children:`Scope`}),(0,B.jsx)(`th`,{children:`Source`}),(0,B.jsx)(`th`,{children:`Origin`})]})}),(0,B.jsx)(`tbody`,{children:a.map(e=>(0,B.jsxs)(`tr`,{children:[(0,B.jsx)(`td`,{children:(0,B.jsx)(`a`,{href:`#${z_(e.path)}`,children:e.name})}),(0,B.jsx)(`td`,{className:`mono`,children:e.scope}),(0,B.jsx)(`td`,{className:`mono`,children:e.source}),(0,B.jsx)(`td`,{className:`mono`,children:e.origin})]},`${e.scope}:${e.path}`))})]})]}):null]})}function sv({scope:e,source:t,pkg:n,loading:r,error:i}){return(0,B.jsxs)(`div`,{className:`main__inner`,children:[(0,B.jsxs)(`p`,{className:`crumbs`,children:[(0,B.jsx)(`a`,{href:`#/extensions`,children:`Extensions`}),` / `,t]}),(0,B.jsx)(`div`,{className:`page-head`,children:(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`h1`,{children:t}),(0,B.jsx)(`p`,{className:`mono`,children:n?`${n.scope} · package`:`${e} · package`})]})}),i?(0,B.jsx)(`p`,{style:{color:`var(--color-text-red)`},children:i}):null,r?(0,B.jsx)(`p`,{className:`muted`,children:`Loading…`}):null,!r&&!n?(0,B.jsxs)(`p`,{className:`muted`,children:[t,` is not in the Pi package catalog on this machine.`]}):null,n?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`},children:`Scope`}),(0,B.jsx)(`p`,{className:`mono`,children:n.scope}),(0,B.jsx)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`},children:`Source`}),(0,B.jsx)(`p`,{className:`mono`,children:n.source}),(0,B.jsx)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`},children:`Filtered`}),(0,B.jsx)(`p`,{className:`mono`,children:n.filtered?`yes`:`no`}),(0,B.jsx)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`},children:`Installed path`}),(0,B.jsx)(`p`,{className:`mono`,children:n.installedPath??`not installed`})]}):null]})}function cv({filePath:e,file:t,loading:n,error:r}){let i=t?.name??e;return(0,B.jsxs)(`div`,{className:`main__inner`,children:[(0,B.jsxs)(`p`,{className:`crumbs`,children:[(0,B.jsx)(`a`,{href:`#/extensions`,children:`Extensions`}),` / `,i]}),(0,B.jsx)(`div`,{className:`page-head`,children:(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`h1`,{children:i}),(0,B.jsx)(`p`,{className:`mono`,children:t?`${t.scope} · ${t.source}`:e})]})}),r?(0,B.jsx)(`p`,{style:{color:`var(--color-text-red)`},children:r}):null,n?(0,B.jsx)(`p`,{className:`muted`,children:`Loading…`}):null,!n&&!t?(0,B.jsx)(`p`,{className:`muted`,children:`This path is not in the Pi extension catalog on this machine.`}):null,t?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`},children:`Scope`}),(0,B.jsx)(`p`,{className:`mono`,children:t.scope}),(0,B.jsx)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`},children:`Source`}),(0,B.jsx)(`p`,{className:`mono`,children:t.source}),(0,B.jsx)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`},children:`Origin`}),(0,B.jsx)(`p`,{className:`mono`,children:t.origin}),(0,B.jsx)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`},children:`File path`}),(0,B.jsx)(`p`,{className:`mono`,children:t.path}),t.baseDir?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-sm)`},children:`Base dir`}),(0,B.jsx)(`p`,{className:`mono`,children:t.baseDir})]}):null]}):null]})}var lv=`sf-theme`;function uv(){try{let e=localStorage.getItem(lv);if(e===`light`||e===`dark`||e===`system`)return e}catch{}return`system`}function dv(e){try{localStorage.setItem(lv,e)}catch{}}function fv({value:e,onChange:t}){return(0,B.jsxs)(`section`,{className:`card`,children:[(0,B.jsx)(`div`,{className:`card__head`,children:(0,B.jsx)(`h2`,{children:`Appearance`})}),(0,B.jsx)(`p`,{style:{margin:0,color:`var(--color-text-secondary)`,fontSize:`var(--font-size-sm)`},children:`Applies immediately, on every screen.`}),(0,B.jsx)(`div`,{className:`theme-picks`,role:`radiogroup`,"aria-label":`Color theme`,children:[`system`,`light`,`dark`].map(n=>(0,B.jsxs)(`button`,{type:`button`,className:`theme-pick`,"data-theme":n,"aria-pressed":e===n?`true`:`false`,onClick:()=>{dv(n),t(n)},children:[(0,B.jsx)(`span`,{className:`theme-pick__swatch`,"data-preview":n}),(0,B.jsx)(`strong`,{children:n===`system`?`System`:n===`light`?`Light`:`Dark`}),(0,B.jsx)(`span`,{children:n===`system`?`Follows this machine`:`Astryx neutral`})]},n))})]})}var pv=`http://127.0.0.1:3847/mcp`;function mv(e,t={}){if(t.viteDev||e.hostname!==`127.0.0.1`&&e.hostname!==`localhost`&&e.hostname!==`[::1]`)return pv;let n=e.hostname===`localhost`||e.hostname===`[::1]`?`127.0.0.1`:e.hostname;return`${`${e.protocol}//${n}${e.port?`:${e.port}`:``}`}/mcp`}function hv(e){return`${JSON.stringify({mcpServers:{stageflow:{url:e}}},null,2)}\n`}function gv(){let e=mv(window.location,{viteDev:!1}),t=hv(e);return(0,B.jsxs)(`section`,{className:`card`,children:[(0,B.jsx)(`div`,{className:`card__head`,children:(0,B.jsx)(`h2`,{children:`Operator-host MCP`})}),(0,B.jsx)(`p`,{style:{margin:0,color:`var(--color-text-secondary)`,fontSize:`var(--font-size-sm)`},children:`This console process also serves Streamable HTTP MCP on localhost. Cursor connects with a URL. There is no stdio command, and the endpoint dies when this process stops.`}),(0,B.jsxs)(`div`,{className:`setting`,children:[(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`strong`,{children:`Endpoint`}),(0,B.jsxs)(`p`,{children:[`Same host as this console, path`,` `,(0,B.jsx)(`span`,{className:`mono`,children:`/mcp`}),`. Loopback only. No API key.`]})]}),(0,B.jsx)(`span`,{className:`mono`,style:{wordBreak:`break-all`},children:e})]}),(0,B.jsxs)(`ol`,{className:`steps`,children:[(0,B.jsx)(`li`,{children:(0,B.jsx)(`span`,{children:`Keep this operator console running. MCP is not a second server.`})}),(0,B.jsx)(`li`,{children:(0,B.jsxs)(`span`,{children:[`Open Cursor Settings → MCP, or add`,` `,(0,B.jsx)(`span`,{className:`mono`,children:`.cursor/mcp.json`}),` in this project.`]})}),(0,B.jsx)(`li`,{children:(0,B.jsxs)(`span`,{children:[`Paste the snippet below. Use `,(0,B.jsx)(`span`,{className:`mono`,children:`url`}),`, not`,` `,(0,B.jsx)(`span`,{className:`mono`,children:`command`}),`.`]})}),(0,B.jsx)(`li`,{children:(0,B.jsxs)(`span`,{children:[`Reload MCP in Cursor. Tools that should appear:`,` `,(0,B.jsx)(`span`,{className:`mono`,children:`list_pipelines`}),`,`,` `,(0,B.jsx)(`span`,{className:`mono`,children:`start_run`}),`,`,` `,(0,B.jsx)(`span`,{className:`mono`,children:`get_run`}),`,`,` `,(0,B.jsx)(`span`,{className:`mono`,children:`get_health`}),`,`,` `,(0,B.jsx)(`span`,{className:`mono`,children:`list_runs`}),`,`,` `,(0,B.jsx)(`span`,{className:`mono`,children:`read_artifact`}),`,`,` `,(0,B.jsx)(`span`,{className:`mono`,children:`wait_run`}),`,`,` `,(0,B.jsx)(`span`,{className:`mono`,children:`answer_gate`}),`,`,` `,(0,B.jsx)(`span`,{className:`mono`,children:`decide_feedback_loop`}),`,`,` `,(0,B.jsx)(`span`,{className:`mono`,children:`describe_pipeline`}),`,`,` `,(0,B.jsx)(`span`,{className:`mono`,children:`validate`}),`,`,` `,(0,B.jsx)(`span`,{className:`mono`,children:`list_providers`}),`,`,` `,(0,B.jsx)(`span`,{className:`mono`,children:`list_models`}),`,`,` `,(0,B.jsx)(`span`,{className:`mono`,children:`list_project_mcp`}),`,`,` `,(0,B.jsx)(`span`,{className:`mono`,children:`probe_project_mcp`}),`.`]})})]}),(0,B.jsx)(lc,{code:t,language:`json`,title:`.cursor/mcp.json`,container:`section`,hasLanguageLabel:!1,width:`100%`}),(0,B.jsx)(`p`,{className:`muted`,style:{margin:`var(--spacing-4) 0 0`,fontSize:`var(--font-size-sm)`},children:`This URL is this console's origin plus /mcp. It must match the MCP endpoint line printed on boot.`}),(0,B.jsxs)(`p`,{className:`muted`,style:{margin:`var(--spacing-2) 0 0`,fontSize:`var(--font-size-sm)`},children:[`MCP can submit a waiting-stage answer (`,(0,B.jsx)(`span`,{className:`mono`,children:`answer_gate`}),`) and a feedback-loop decision (`,(0,B.jsx)(`span`,{className:`mono`,children:`decide_feedback_loop`}),`).`]})]})}var _v=`Servers from this project's git-root .mcp.json. Check tests whether a server can connect. It does not start a run and does not attach tools to stages. YAML mcp: still allowlists what a stage receives.`;function vv(e){switch(e){case`not-yet-probed`:return`Not yet probed`;case`probing`:return`Probing…`;case`connected`:return`Connected`;case`needs_auth`:return`Needs auth`;case`connect_failed`:return`Connect failed`;case`unresolved_var`:return`Unresolved variable`;case`invalid_config`:return`Invalid config`;case`missing_catalog`:return`Missing catalog`;case`cancelled`:return`Cancelled`}}function yv(e){switch(e){case`probing`:return`running`;case`connected`:return`succeeded`;case`needs_auth`:return`waiting`;case`connect_failed`:case`unresolved_var`:case`invalid_config`:case`missing_catalog`:return`failed`;case`not-yet-probed`:case`cancelled`:return}}function bv(e){return e===`missing_catalog`?`No git-root .mcp.json in this project.`:e===`invalid_config`?`Project .mcp.json is invalid.`:null}function xv(e){let t={loading:!0,catalogStatus:null,servers:[],error:null},n=!1,r=new Map,i=new Set,a=()=>t,o=()=>{for(let e of i)e()},s=(e,n)=>{t={...t,servers:t.servers.map(t=>t.name===e?{...t,...n}:t)},o()};return{getState:a,load:async()=>{if(!n){t={loading:!0,catalogStatus:null,servers:[],error:null},o();try{let r=await e.list();if(n)return;if(r.status!==`ok`){t={loading:!1,catalogStatus:r.status,servers:[],error:null},o();return}t={loading:!1,catalogStatus:`ok`,servers:r.servers.map(e=>({name:e.name,transport:e.transport,status:`not-yet-probed`})),error:null},o()}catch(e){if(n)return;t={loading:!1,catalogStatus:null,servers:[],error:e instanceof Error?e.message:String(e)},o()}}},check:async t=>{if(n||r.has(t))return;let i=new AbortController;r.set(t,i),s(t,{status:`probing`,error:void 0});try{let r=await e.probe(t,{signal:i.signal});if(n)return;s(t,{status:r.status,error:r.error})}catch(e){if(n||i.signal.aborted)return;s(t,{status:`connect_failed`,error:e instanceof Error?e.message:String(e)})}finally{r.delete(t)}},dispose:()=>{n=!0;for(let e of r.values())e.abort();r.clear()},subscribe:e=>(i.add(e),()=>{i.delete(e)})}}function Sv(){let e=(0,v.useRef)(null),[t,n]=(0,v.useState)({loading:!0,catalogStatus:null,servers:[],error:null});(0,v.useEffect)(()=>{let t=xv({list:rr,probe:ir});e.current=t,n(t.getState());let r=t.subscribe(()=>n(t.getState()));return t.load(),()=>{r(),t.dispose(),e.current===t&&(e.current=null)}},[]);let r=t.catalogStatus?bv(t.catalogStatus):null;return(0,B.jsxs)(`section`,{className:`card`,children:[(0,B.jsx)(`div`,{className:`card__head`,children:(0,B.jsx)(`h2`,{children:`Project MCP servers`})}),(0,B.jsx)(`p`,{style:{margin:0,color:`var(--color-text-secondary)`,fontSize:`var(--font-size-sm)`},children:_v}),t.error?(0,B.jsx)(`p`,{style:{color:`var(--color-text-red)`,fontSize:`var(--font-size-sm)`,marginBottom:`var(--spacing-3)`},children:t.error}):null,r?(0,B.jsx)(`p`,{style:{color:`var(--color-text-red)`,fontSize:`var(--font-size-sm)`,marginBottom:`var(--spacing-3)`},children:r}):null,t.loading?(0,B.jsx)(`p`,{className:`muted`,children:`Loading project catalog…`}):t.catalogStatus===`ok`&&t.servers.length===0?(0,B.jsx)(`p`,{className:`muted`,children:`No servers in .mcp.json.`}):t.servers.map(t=>{let n=yv(t.status),r=t.status===`probing`;return(0,B.jsxs)(`div`,{className:`setting`,children:[(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`strong`,{children:t.name}),(0,B.jsx)(`p`,{children:t.transport}),t.error?(0,B.jsx)(`p`,{children:t.error}):null]}),(0,B.jsxs)(`span`,{style:{display:`flex`,gap:`var(--spacing-2)`,alignItems:`center`},children:[(0,B.jsxs)(`span`,{className:`status`,children:[(0,B.jsx)(`span`,{className:`dot${n?` dot--${n}`:``}`}),` `,vv(t.status)]}),(0,B.jsx)(`button`,{type:`button`,className:`btn btn--ghost`,disabled:r,onClick:()=>void e.current?.check(t.name),children:r?`Probing…`:`Check`})]})]},t.name)})]})}var Cv=`Pi may complete login via a local callback in the Stageflow process. If the browser cannot reach this machine, paste the redirect URL or code when prompted.`,wv=`If automatic completion does not finish, paste the redirect URL or manual code below.`;function Tv(e){for(let t=e.length-1;t>=0;t--){let n=e[t];if(n?.type===`auth_url`)return n}}function Ev(e){for(let t=e.length-1;t>=0;t--){let n=e[t];if(n?.type===`device_code`)return n}}function Dv(e){for(let t=e.length-1;t>=0;t--){let n=e[t];if(n?.type===`progress`||n?.type===`info`)return n.message}}function Ov(e){for(let t=e.length-1;t>=0;t--){let n=e[t];if(n?.type===`info`&&n.links&&n.links.length>0)return n.links}}function kv(e){return e.status===`completed`||e.status===`failed`||e.status===`cancelled`}function Av(e){return e.type===`select`?`select`:e.type===`secret`?`password`:`text`}function jv(e){return e.supportsOauth}var Mv=500;function Nv({providerId:e,providerName:t,onComplete:n,onDismiss:r}){let[i,a]=(0,v.useState)(null),[o,s]=(0,v.useState)(null),[c,l]=(0,v.useState)(``),[u,d]=(0,v.useState)(!1),[f,p]=(0,v.useState)(null),m=(0,v.useRef)(!1),h=(0,v.useRef)(!1);(0,v.useEffect)(()=>{m.current||(m.current=!0,(async()=>{d(!0);let t=await Un(e);if(d(!1),!t.ok){s(t.error);return}a(t.session)})())},[e]),(0,v.useEffect)(()=>{if(!i||kv(i))return;let t=window.setInterval(()=>{(async()=>{try{let{session:t}=await Wn(e,i.id);a(t)}catch(e){s(e instanceof Error?e.message:String(e))}})()},Mv);return()=>window.clearInterval(t)},[e,i?.id,i?.status]),(0,v.useEffect)(()=>{if(!(!i||!kv(i)||h.current)){if(h.current=!0,i.status===`completed`){n(i.provider,i.warning?.message);return}if(i.status===`failed`){s(i.error?.message??`OAuth login failed`);return}r()}},[i,n,r]);let g=i?.pendingPrompt;(0,v.useEffect)(()=>{g||(l(``),s(e=>e===`Enter a value to continue.`?null:e))},[g]);async function _(e,t){try{await navigator.clipboard.writeText(t),p(e),window.setTimeout(()=>p(null),1500)}catch{s(`Could not copy to clipboard`)}}async function y(){if(!i)return;let t=c.trim();if(!t){s(`Enter a value to continue.`);return}d(!0),s(null);let n=await Gn(e,i.id,t);if(d(!1),!n.ok){s(n.error);return}l(``),a(n.session)}async function b(t){if(!i)return;d(!0),s(null);let n=await Gn(e,i.id,t);if(d(!1),!n.ok){s(n.error);return}a(n.session)}async function x(){if(!i){r();return}d(!0),await Kn(e,i.id),d(!1),h.current=!0,r()}let S=i?Tv(i.events):void 0,C=i?Ev(i.events):void 0,w=i?Dv(i.events):void 0,T=i?Ov(i.events):void 0,E=g?Av(g):null;return(0,B.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:`var(--spacing-2)`,marginTop:`var(--spacing-2)`},children:[(0,B.jsxs)(`p`,{style:{margin:0,color:`var(--color-text-secondary)`,fontSize:`var(--font-size-sm)`},children:[`Connecting `,t,` with Pi OAuth / subscription login.`]}),w?(0,B.jsx)(`p`,{className:`muted`,style:{margin:0},children:w}):null,T&&T.length>0?(0,B.jsx)(`div`,{style:{display:`flex`,gap:`var(--spacing-2)`,flexWrap:`wrap`},children:T.map(e=>(0,B.jsx)(`a`,{className:`btn btn--ghost`,href:e.url,target:`_blank`,rel:`noreferrer`,children:e.label??`Open link`},e.url))}):null,S?(0,B.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:`var(--spacing-2)`},children:[S.instructions?(0,B.jsx)(`p`,{style:{margin:0,fontSize:`var(--font-size-sm)`},children:S.instructions}):null,(0,B.jsxs)(`div`,{style:{display:`flex`,gap:`var(--spacing-2)`,flexWrap:`wrap`},children:[(0,B.jsx)(`a`,{className:`btn btn--primary`,href:S.url,target:`_blank`,rel:`noreferrer`,children:`Open browser`}),(0,B.jsx)(`button`,{type:`button`,className:`btn btn--ghost`,onClick:()=>void _(`url`,S.url),children:f===`url`?`Copied`:`Copy link`})]}),(0,B.jsxs)(`p`,{style:{margin:0,color:`var(--color-text-secondary)`,fontSize:`var(--font-size-sm)`},children:[Cv,` `,wv]})]}):null,C?(0,B.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:`var(--spacing-2)`},children:[(0,B.jsxs)(`p`,{style:{margin:0},children:[`Device code: `,(0,B.jsx)(`strong`,{children:C.userCode})]}),typeof C.expiresInSeconds==`number`?(0,B.jsxs)(`p`,{className:`muted`,style:{margin:0,fontSize:`var(--font-size-sm)`},children:[`Code expires in about `,C.expiresInSeconds,`s.`]}):null,(0,B.jsxs)(`div`,{style:{display:`flex`,gap:`var(--spacing-2)`,flexWrap:`wrap`},children:[(0,B.jsx)(`a`,{className:`btn btn--primary`,href:C.verificationUri,target:`_blank`,rel:`noreferrer`,children:`Open verification page`}),(0,B.jsx)(`button`,{type:`button`,className:`btn btn--ghost`,onClick:()=>void _(`code`,C.userCode),children:f===`code`?`Copied`:`Copy code`}),(0,B.jsx)(`button`,{type:`button`,className:`btn btn--ghost`,onClick:()=>void _(`uri`,C.verificationUri),children:f===`uri`?`Copied`:`Copy URI`})]})]}):null,g&&E===`select`?(0,B.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:`var(--spacing-2)`},children:[(0,B.jsx)(`p`,{style:{margin:0},children:g.message}),(g.options??[]).map(e=>(0,B.jsxs)(`button`,{type:`button`,className:`btn btn--ghost`,disabled:u,onClick:()=>void b(e.id),children:[e.label,e.description?` — ${e.description}`:``]},e.id))]}):null,g&&E!==`select`?(0,B.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:`var(--spacing-2)`},children:[(0,B.jsx)(`p`,{style:{margin:0},children:g.message}),g.type===`manual_code`?(0,B.jsx)(`p`,{style:{margin:0,color:`var(--color-text-secondary)`,fontSize:`var(--font-size-sm)`},children:wv}):null,(0,B.jsx)(`input`,{className:`input`,type:E===`password`?`password`:`text`,autoComplete:`off`,placeholder:g.placeholder??``,value:c,onChange:e=>l(e.target.value)}),(0,B.jsx)(`button`,{type:`button`,className:`btn btn--primary`,disabled:u,onClick:()=>void y(),children:u?`Sending…`:`Continue`})]}):null,o?(0,B.jsx)(`p`,{style:{margin:0,color:`var(--color-text-red)`,fontSize:`var(--font-size-sm)`},children:o}):null,(0,B.jsx)(`div`,{style:{display:`flex`,gap:`var(--spacing-2)`},children:(0,B.jsx)(`button`,{type:`button`,className:`btn btn--ghost`,disabled:u,onClick:()=>void x(),children:`Cancel`})})]})}function Pv({provider:e,status:t,connecting:n,oauthing:r,apiKeyDraft:i,rowBusy:a,showDisconnect:o,onSetConnecting:s,onSetOauthing:c,onApiKeyChange:l,onConnectSubmit:u,onDisconnect:d,onOauthComplete:f,onOauthDismiss:p}){let m=t?.configured===!0,h=Ug(e),g=jv(e),_=Wg(e);return(0,B.jsxs)(`div`,{className:`setting`,children:[(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`strong`,{children:e.name}),(0,B.jsx)(`p`,{children:Gg(t)}),n?(0,B.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:`var(--spacing-2)`,marginTop:`var(--spacing-2)`},children:[(0,B.jsx)(`input`,{className:`input`,type:`password`,autoComplete:`off`,placeholder:`API key`,value:i,onChange:e=>l(e.target.value)}),(0,B.jsxs)(`div`,{style:{display:`flex`,gap:`var(--spacing-2)`},children:[(0,B.jsx)(`button`,{type:`button`,className:`btn btn--primary`,disabled:a,onClick:()=>u(e.id),children:a?`Saving…`:`Save key`}),(0,B.jsx)(`button`,{type:`button`,className:`btn btn--ghost`,disabled:a,onClick:()=>{s(null),l(``)},children:`Cancel`})]})]}):null,r?(0,B.jsx)(Nv,{providerId:e.id,providerName:e.name,onComplete:f,onDismiss:p}):null]}),(0,B.jsxs)(`span`,{style:{display:`flex`,gap:`var(--spacing-2)`},children:[m&&o?(0,B.jsx)(`button`,{type:`button`,className:`btn btn--ghost`,disabled:a||r,onClick:()=>d(e.id),children:`Disconnect`}):null,m&&!o?(0,B.jsx)(`span`,{className:`muted`,children:`Connected`}):null,h&&!m&&!r?(0,B.jsx)(`button`,{type:`button`,className:`btn btn--primary`,disabled:a,onClick:()=>{s(e.id),c(null),l(``)},children:`Connect`}):null,g&&!m&&!n&&!r?(0,B.jsx)(`button`,{type:`button`,className:_?`btn btn--primary`:`btn btn--ghost`,disabled:a,onClick:()=>{c(e.id),s(null),l(``)},children:`Connect with OAuth`}):null]})]},e.id)}function Fv(){let[e,t]=(0,v.useState)([]),[n,r]=(0,v.useState)({}),[i,a]=(0,v.useState)(void 0),[o,s]=(0,v.useState)(!0),[c,l]=(0,v.useState)(null),[u,d]=(0,v.useState)(!1),[f,p]=(0,v.useState)(null),[m,h]=(0,v.useState)(null),[g,_]=(0,v.useState)(``),[y,b]=(0,v.useState)(null),[x,S]=(0,v.useState)(null),[C,w]=(0,v.useState)(null),T=(0,v.useCallback)(async()=>{l(null);let[e,n]=await Promise.all([Rn(),zn()]);t(e.providers),a(n.credentialSource);let i={};await Promise.all(e.providers.map(async e=>{try{let{provider:t}=await Bn(e.id);i[e.id]=t}catch{i[e.id]=void 0}})),r(i)},[]);(0,v.useEffect)(()=>{(async()=>{s(!0);try{await T()}catch(e){l(e instanceof Error?e.message:String(e))}finally{s(!1)}})()},[T]);async function E(e){if(e===`pi_home`||e===`sf_owned`){d(!0),l(null);try{let t=await qn(e);a(t.credentialSource),await T()}catch(e){l(e instanceof Error?e.message:String(e))}finally{d(!1)}}}async function D(e){let t=g.trim();if(!t){S(`Paste an API key to connect.`);return}b(e),S(null);let n=await Vn(e,t);if(b(null),!n.ok){S(n.error);return}_(``),p(null),r(t=>({...t,[e]:n.provider}))}async function O(e){b(e),S(null);let t=await Hn(e);if(b(null),!t.ok){S(t.error);return}r(n=>({...n,[e]:t.provider}))}return(0,B.jsxs)(`section`,{className:`card`,children:[(0,B.jsx)(`div`,{className:`card__head`,children:(0,B.jsx)(`h2`,{children:`Providers`})}),(0,B.jsx)(`p`,{style:{margin:0,color:`var(--color-text-secondary)`,fontSize:`var(--font-size-sm)`},children:Bg}),(0,B.jsxs)(`div`,{className:`setting`,children:[(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`strong`,{children:`Credential source`}),(0,B.jsx)(`p`,{children:`Use credentials already stored by Pi, or keep a Stageflow-owned store for keys you paste here.`})]}),o?(0,B.jsx)(`span`,{className:`muted`,children:`—`}):(0,B.jsxs)(`select`,{className:`select`,value:i??``,disabled:u,onChange:e=>void E(e.target.value),children:[(0,B.jsx)(`option`,{value:``,disabled:!0,children:`Not set`}),(0,B.jsx)(`option`,{value:`pi_home`,children:`Existing Pi login (~/.pi)`}),(0,B.jsx)(`option`,{value:`sf_owned`,children:`Stageflow-owned store`})]})]}),c?(0,B.jsx)(`p`,{style:{color:`var(--color-text-red)`,fontSize:`var(--font-size-sm)`,marginBottom:`var(--spacing-3)`},children:c}):null,x?(0,B.jsx)(`p`,{style:{color:`var(--color-text-red)`,fontSize:`var(--font-size-sm)`,marginBottom:`var(--spacing-3)`},children:x}):null,C?(0,B.jsx)(`p`,{style:{color:`var(--color-text-secondary)`,fontSize:`var(--font-size-sm)`,marginBottom:`var(--spacing-3)`},children:C}):null,o?(0,B.jsx)(`p`,{className:`muted`,children:`Loading providers…`}):e.length===0?(0,B.jsx)(`p`,{className:`muted`,children:`No providers reported by Pi.`}):e.map(e=>(0,B.jsx)(Pv,{provider:e,status:n[e.id],connecting:f===e.id,oauthing:m===e.id,apiKeyDraft:g,rowBusy:y===e.id,showDisconnect:!0,onSetConnecting:e=>{p(e),S(null)},onSetOauthing:e=>{h(e),S(null),w(null)},onApiKeyChange:_,onConnectSubmit:e=>void D(e),onDisconnect:e=>void O(e),onOauthComplete:(t,n)=>{h(null),w(n??null),t?r(n=>({...n,[e.id]:t})):T()},onOauthDismiss:()=>{h(null),S(null)}},e.id))]})}var Iv=`sf-notify-waiting`;function Lv(){try{let e=localStorage.getItem(Iv);if(e===`system`||e===`off`)return e}catch{}return`off`}function Rv(e){try{localStorage.setItem(Iv,e)}catch{}}function zv(){return typeof Notification>`u`?`unsupported`:Notification.permission}async function Bv(){return typeof Notification>`u`?`unsupported`:Notification.permission==="default"?Notification.requestPermission():Notification.permission}function Vv(e,t){let n=new Set(e.map(e=>e.run_id));if(t===null)return{emit:[],nextSeen:n};let r=[],i=new Set(t);for(let t of e)i.has(t.run_id)||(r.push(t),i.add(t.run_id));for(let e of[...i])n.has(e)||i.delete(e);return{emit:r,nextSeen:i}}function Hv(e){let{snapshot:t,loading:n}=pr(),r=(0,v.useRef)(null);(0,v.useEffect)(()=>{if(n)return;let{emit:i,nextSeen:a}=Vv(xr(t),r.current);if(r.current=a,e){for(let e of i)if(typeof Notification<`u`&&Notification.permission===`granted`){let t=[e.pipeline_id,e.waiting_summary].filter(e=>!!e);new Notification(`Stage waiting on you`,{body:t.join(` — `)})}}},[t,n,e])}function Uv({themeMode:e,onThemeChange:t,notifyPreference:n,onNotifyChange:r}){let{snapshot:i,loading:a}=pr(),o=mr(),s=i.health,c=a&&s==null,l=!c&&s==null?`unavailable`:null,[u,d]=(0,v.useState)(null),[f,p]=(0,v.useState)(!1),[m,h]=(0,v.useState)(zv);async function g(e){let t=e===`system`?`system`:`off`;if(Rv(t),r(t),t===`system`&&zv()==="default"){let e=await Bv();h(e)}}async function _(e){let t=Number(e);p(!0),d(null);try{await Ln(t),await o.refresh()}catch(e){d(e instanceof Error?e.message:String(e))}finally{p(!1)}}let y=[1,2,3,4,6],b=s?.maxConcurrent,x=b!=null&&!y.includes(b)?[b,...y]:y;return(0,B.jsxs)(`div`,{className:`main__inner`,children:[(0,B.jsx)(`div`,{className:`page-head`,children:(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`h1`,{children:`Settings`}),(0,B.jsx)(`p`,{children:`Local to this machine. Nothing here is shared, because Stageflow runs as one operator's CLI.`})]})}),(0,B.jsx)(fv,{value:e,onChange:t}),(0,B.jsx)(Fv,{}),(0,B.jsx)(Sv,{}),(0,B.jsx)(gv,{}),(0,B.jsxs)(`section`,{className:`card`,children:[(0,B.jsx)(`div`,{className:`card__head`,children:(0,B.jsx)(`h2`,{children:`Concurrency`})}),l?(0,B.jsxs)(`p`,{style:{color:`var(--color-text-red)`,fontSize:`var(--font-size-sm)`,marginBottom:`var(--spacing-3)`},children:[`Could not load capacity: `,l]}):null,(0,B.jsxs)(`div`,{className:`setting`,children:[(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`strong`,{children:`Session slots`}),(0,B.jsx)(`p`,{children:`How many stage sessions may be alive at once. A stage waiting on you still holds its slot. Lowering the cap does not stop runs that are already in flight.`})]}),c?(0,B.jsx)(`span`,{className:`muted`,children:`—`}):s?(0,B.jsx)(`select`,{className:`select`,value:s.maxConcurrent,disabled:f,onChange:e=>void _(e.target.value),children:x.map(e=>(0,B.jsxs)(`option`,{value:e,children:[e,e===s.maxConcurrent?` · current`:``]},e))}):(0,B.jsx)(`span`,{className:`muted`,children:`—`})]}),u?(0,B.jsxs)(`p`,{style:{color:`var(--color-text-red)`,fontSize:`var(--font-size-sm)`,marginBottom:`var(--spacing-3)`},children:[`Could not update slots: `,u]}):null,(0,B.jsxs)(`div`,{className:`setting`,children:[(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`strong`,{children:`Slots available`}),(0,B.jsx)(`p`,{children:`Free slots that can accept a new run right now.`})]}),(0,B.jsx)(`span`,{className:`muted`,children:c?`—`:s?String(s.slotsAvailable):`—`})]}),(0,B.jsxs)(`div`,{className:`setting`,children:[(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`strong`,{children:`When slots are full`}),(0,B.jsx)(`p`,{children:`Reject with busy_capacity. There is no queue.`})]}),(0,B.jsx)(`span`,{className:`muted`,children:`Reject with busy_capacity`})]})]}),(0,B.jsxs)(`section`,{className:`card`,children:[(0,B.jsx)(`div`,{className:`card__head`,children:(0,B.jsx)(`h2`,{children:`Held stages`})}),(0,B.jsxs)(`div`,{className:`setting`,children:[(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`strong`,{children:`Hold timeout`}),(0,B.jsx)(`p`,{children:`A held stage waits until you answer. There is no timeout yet.`})]}),(0,B.jsx)(`span`,{className:`muted`,children:`—`})]}),(0,B.jsxs)(`div`,{className:`setting`,children:[(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`strong`,{children:`Notify me when a stage asks`}),(0,B.jsx)(`p`,{children:`A held stage is invisible if this window is closed. A system notification is the only thing that reaches you.`})]}),(0,B.jsxs)(`select`,{className:`select`,value:n,onChange:e=>void g(e.target.value),children:[(0,B.jsx)(`option`,{value:`system`,children:`System notification`}),(0,B.jsx)(`option`,{value:`off`,children:`Nothing`})]})]}),n===`system`&&m===`denied`?(0,B.jsx)(`p`,{className:`muted`,style:{fontSize:`var(--font-size-xs)`,padding:`var(--spacing-2) 0`},children:`Notifications blocked — enable in browser settings`}):null]})]})}function Wv({onComplete:e}){let[t,n]=(0,v.useState)(!0),[r,i]=(0,v.useState)(null),[a,o]=(0,v.useState)(null),[s,c]=(0,v.useState)(!1),[l,u]=(0,v.useState)(`sf_owned`),[d,f]=(0,v.useState)(`offer`),[p,m]=(0,v.useState)(!1),[h,g]=(0,v.useState)([]),[_,y]=(0,v.useState)({}),[b,x]=(0,v.useState)(null),[S,C]=(0,v.useState)(null),[w,T]=(0,v.useState)(``),[E,D]=(0,v.useState)(null);(0,v.useEffect)(()=>{(async()=>{n(!0),i(null);try{let e=await zn();c(e.piHomeUsable);let t=Hg(e.piHomeUsable);u(t),e.piHomeUsable?f(`offer`):(f(`keys`),await O())}catch(e){i(e instanceof Error?e.message:String(e))}finally{n(!1)}})()},[]);async function O(){let e=(await Rn()).providers.filter(e=>Ug(e)||jv(e));g(e);let t={};await Promise.all(e.map(async e=>{try{let{provider:n}=await Bn(e.id);t[e.id]=n}catch{t[e.id]=void 0}})),y(t)}async function k(){m(!0),i(null);try{if(await qn(l),l===`pi_home`){e();return}await O(),f(`keys`)}catch(e){i(e instanceof Error?e.message:String(e))}finally{m(!1)}}async function A(e){let t=w.trim();if(!t){i(`Paste an API key to connect.`);return}D(e),i(null);try{await qn(`sf_owned`)}catch(e){D(null),i(e instanceof Error?e.message:String(e));return}let n=await Vn(e,t);if(D(null),!n.ok){i(n.error);return}T(``),x(null),y(t=>({...t,[e]:n.provider}))}let j=Object.values(_).some(e=>e?.configured);return(0,B.jsxs)(`div`,{className:`main__inner`,children:[(0,B.jsx)(`div`,{className:`page-head`,children:(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`h1`,{children:`Connect providers`}),(0,B.jsx)(`p`,{children:Bg})]})}),t?(0,B.jsx)(`p`,{className:`muted`,children:`Checking for an existing Pi login…`}):null,r?(0,B.jsx)(`p`,{style:{color:`var(--color-text-red)`,marginBottom:`var(--spacing-4)`},children:r}):null,a?(0,B.jsx)(`p`,{style:{color:`var(--color-text-secondary)`,marginBottom:`var(--spacing-4)`},children:a}):null,!t&&d===`offer`?(0,B.jsxs)(`section`,{className:`card`,children:[(0,B.jsx)(`div`,{className:`card__head`,children:(0,B.jsx)(`h2`,{children:`Credential source`})}),(0,B.jsx)(`p`,{style:{margin:0,color:`var(--color-text-secondary)`,fontSize:`var(--font-size-sm)`},children:s?`Usable Pi credentials were found on this machine. Reuse them, or set up keys inside Stageflow.`:`No usable Pi login was detected. Set up credentials in Stageflow.`}),(0,B.jsxs)(`div`,{className:`theme-picks`,role:`radiogroup`,"aria-label":`Credential source`,children:[(0,B.jsxs)(`button`,{type:`button`,className:`theme-pick`,"aria-pressed":l===`pi_home`?`true`:`false`,disabled:!s,onClick:()=>u(`pi_home`),children:[(0,B.jsx)(`strong`,{children:`Use existing Pi login`}),(0,B.jsx)(`span`,{children:`Reuse ~/.pi credentials without re-entering keys`})]}),(0,B.jsxs)(`button`,{type:`button`,className:`theme-pick`,"aria-pressed":l===`sf_owned`?`true`:`false`,onClick:()=>u(`sf_owned`),children:[(0,B.jsx)(`strong`,{children:`Set up in Stageflow`}),(0,B.jsx)(`span`,{children:`Paste API keys or complete Pi OAuth in an SF-owned store`})]})]}),(0,B.jsx)(`div`,{className:`form-actions`,style:{marginTop:`var(--spacing-4)`},children:(0,B.jsx)(`button`,{type:`button`,className:`btn btn--primary`,disabled:p||!s&&l===`pi_home`,onClick:()=>void k(),children:p?`Saving…`:`Continue`})})]}):null,!t&&d===`keys`?(0,B.jsxs)(`section`,{className:`card`,children:[(0,B.jsx)(`div`,{className:`card__head`,children:(0,B.jsx)(`h2`,{children:`Providers`})}),(0,B.jsx)(`p`,{style:{margin:0,color:`var(--color-text-secondary)`,fontSize:`var(--font-size-sm)`},children:`Connect at least one provider with an API key or Pi OAuth / subscription login.`}),h.length===0?(0,B.jsx)(`p`,{className:`muted`,children:`No connectable providers are available from Pi right now.`}):h.map(e=>(0,B.jsx)(Pv,{provider:e,status:_[e.id],connecting:b===e.id,oauthing:S===e.id,apiKeyDraft:w,rowBusy:E===e.id,showDisconnect:!1,onSetConnecting:x,onSetOauthing:C,onApiKeyChange:T,onConnectSubmit:e=>void A(e),onDisconnect:()=>void 0,onOauthComplete:(t,n)=>{C(null),o(n??null),t?y(n=>({...n,[e.id]:t})):O()},onOauthDismiss:()=>C(null)},e.id)),(0,B.jsxs)(`div`,{className:`form-actions`,style:{marginTop:`var(--spacing-4)`},children:[(0,B.jsx)(`button`,{type:`button`,className:`btn btn--primary`,disabled:!j,onClick:e,children:`Continue to console`}),(0,B.jsx)(`button`,{type:`button`,className:`btn btn--ghost`,onClick:e,children:`Skip for now`})]})]}):null]})}function Gv(e){return e.name===`connect`?`settings`:e.name===`detail`?`runs`:e.name===`new`?`today`:e.name===`pipeline`?`pipelines`:e.name===`task`?`tasks`:e.name===`skill`?`skills`:e.name===`extensionPackage`||e.name===`extensionFile`?`extensions`:e.name}function Kv(){let[e,t]=(0,v.useState)(()=>U_()),[n,r]=(0,v.useState)(uv),[i,a]=(0,v.useState)(Lv),[o,s]=(0,v.useState)(`loading`),{snapshot:c}=pr();(0,v.useEffect)(()=>{let e=()=>t(U_());return window.addEventListener(`hashchange`,e),window.location.hash||(window.location.hash=`#/today`),()=>window.removeEventListener(`hashchange`,e)},[]),Hv(i===`system`),(0,v.useEffect)(()=>{let e=!1;return zn().then(t=>{e||s(Vg(t)?`needs_connect`:`ready`)}).catch(()=>{e||s(`ready`)}),()=>{e=!0}},[]);let l=xr(c).length,u=c.health,d=(0,v.useCallback)(e=>{A_(e)},[]),f=(0,v.useCallback)(e=>{d(`/${e}`)},[d]),p;return p=e.name===`new`?(0,B.jsx)(Xg,{onStarted:e=>d(j_(e)),initialPipelinePath:e.pipelineId,initialTaskPath:e.taskPath}):e.name===`detail`?(0,B.jsx)(Fg,{runId:e.runId,view:e.view,onBack:()=>d(`/runs`),onReran:e=>d(j_(e)),onOpenStream:t=>d(t?M_(e.runId,t):j_(e.runId)),onOpenArtifact:t=>d(N_(e.runId,t)),onOpenEnvelope:t=>d(P_(e.runId,t))}):e.name===`runs`?(0,B.jsx)(Zr,{onOpen:e=>d(j_(e)),onNew:()=>d(`/new`)}):e.name===`pipelines`?(0,B.jsx)(ev,{onNew:d}):e.name===`pipeline`?(0,B.jsx)(ev,{pipelineId:e.pipelineId,onNew:d}):e.name===`tasks`?(0,B.jsx)(nv,{onNew:d}):e.name===`task`?(0,B.jsx)(nv,{taskId:e.taskId,onNew:d}):e.name===`skills`?(0,B.jsx)(iv,{}):e.name===`skill`?(0,B.jsx)(iv,{skillName:e.skillName}):e.name===`extensions`?(0,B.jsx)(ov,{}):e.name===`extensionPackage`?(0,B.jsx)(ov,{packageScope:e.scope,packageSource:e.source}):e.name===`extensionFile`?(0,B.jsx)(ov,{filePath:e.path}):e.name===`settings`?(0,B.jsx)(Uv,{themeMode:n,onThemeChange:r,notifyPreference:i,onNotifyChange:a}):e.name===`connect`?(0,B.jsx)(Wv,{onComplete:()=>{s(`ready`),d(`/today`)}}):(0,B.jsx)(f_,{onOpen:e=>d(j_(e)),onOpenArtifact:(e,t)=>d(N_(e,t)),onNew:()=>d(`/new`),onSeeRuns:()=>d(`/runs`)}),o===`needs_connect`&&e.name!==`settings`&&e.name!==`connect`&&(p=(0,B.jsx)(Wv,{onComplete:()=>{s(`ready`),d(`/today`)}})),(0,B.jsx)(At,{theme:wn,mode:n,children:(0,B.jsxs)(`div`,{className:`app`,children:[(0,B.jsx)(jr,{activeId:Gv(e),onNavigate:f,waitingCount:l,health:u}),(0,B.jsx)(`main`,{className:`main`,children:p})]})})}function qv(){let[e]=(0,v.useState)(()=>lr({source:or()}));return(0,B.jsx)(fr,{catalog:e,children:(0,B.jsx)(Kv,{})})}(0,Cn.createRoot)(document.getElementById(`root`)).render((0,B.jsx)(v.StrictMode,{children:(0,B.jsx)(qv,{})}));
|