@worca/ui 0.3.1-rc.3 → 0.3.1-rc.4
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/app/main.bundle.js +1 -1
- package/app/main.bundle.js.map +2 -2
- package/package.json +1 -1
- package/server/process-manager.js +147 -83
- package/server/project-routes.js +3 -3
- package/server/ws-message-router.js +2 -1
package/app/main.bundle.js
CHANGED
|
@@ -5844,7 +5844,7 @@ ${bc}${"\u2500".repeat(40)} Iteration ${e} ${"\u2500".repeat(40)}${jn}
|
|
|
5844
5844
|
<slot name="help-text">${this.helpText}</slot>
|
|
5845
5845
|
</div>
|
|
5846
5846
|
</div>
|
|
5847
|
-
`}};ae.styles=[te,ii,Cg];g([Q(".textarea__control")],ae.prototype,"input",2);g([Q(".textarea__size-adjuster")],ae.prototype,"sizeAdjuster",2);g([he()],ae.prototype,"hasFocus",2);g([b()],ae.prototype,"title",2);g([b()],ae.prototype,"name",2);g([b()],ae.prototype,"value",2);g([b({reflect:!0})],ae.prototype,"size",2);g([b({type:Boolean,reflect:!0})],ae.prototype,"filled",2);g([b()],ae.prototype,"label",2);g([b({attribute:"help-text"})],ae.prototype,"helpText",2);g([b()],ae.prototype,"placeholder",2);g([b({type:Number})],ae.prototype,"rows",2);g([b()],ae.prototype,"resize",2);g([b({type:Boolean,reflect:!0})],ae.prototype,"disabled",2);g([b({type:Boolean,reflect:!0})],ae.prototype,"readonly",2);g([b({reflect:!0})],ae.prototype,"form",2);g([b({type:Boolean,reflect:!0})],ae.prototype,"required",2);g([b({type:Number})],ae.prototype,"minlength",2);g([b({type:Number})],ae.prototype,"maxlength",2);g([b()],ae.prototype,"autocapitalize",2);g([b()],ae.prototype,"autocorrect",2);g([b()],ae.prototype,"autocomplete",2);g([b({type:Boolean})],ae.prototype,"autofocus",2);g([b()],ae.prototype,"enterkeyhint",2);g([b({type:Boolean,converter:{fromAttribute:e=>!(!e||e==="false"),toAttribute:e=>e?"true":"false"}})],ae.prototype,"spellcheck",2);g([b()],ae.prototype,"inputmode",2);g([Cr()],ae.prototype,"defaultValue",2);g([Y("disabled",{waitUntilFirstUpdate:!0})],ae.prototype,"handleDisabledChange",1);g([Y("rows",{waitUntilFirstUpdate:!0})],ae.prototype,"handleRowsChange",1);g([Y("value",{waitUntilFirstUpdate:!0})],ae.prototype,"handleValueChange",1);ae.define("sl-textarea");var I=ed();function Zt(e){let t=I.getState().currentProjectId;return t?`/api/projects/${t}${e}`:`/api${e}`}var W=zf(),Ko=Qh({store:I,ws:W,getSettings:()=>Jt}),O=Na(location.hash),Rg=W.getState(),xh=!0,Jt={},Ge=null,Vo=null,oi=null,Uo=null,bt="*",$a="",ri=null,Ps={},Ho=new Set,kh="all",$h="all",Wo=null,qo=null,Eh=new Map,Th={},Ah=[],jo=!1,Aa=new Map,Rh={},Ea=null,Ra=!1,Fi=null,Lh="all",Dh=null,Ph="",xa="all";function TS(){Jt={},Ge=null,Vo=null,oi=null,Uo=null,bt="*",$a="",ri=null;for(let e of Object.keys(Ps))delete Ps[e];Ho.clear(),kh="all",$h="all",Wo=null,qo=null,Eh.clear(),Th={},Ah=[],jo=!1,Aa.clear(),Rh={},Ea=null,Ra=!1,Fi=null,Lh="all",Dh=null,Ph="",xa="all"}function AS(e,t){Aa.set(e,t)}function Mh(e){e&&W.send("list-beads-by-run",{runId:e}).then(t=>{Eh.set(e,t.issues||[]),j()}).catch(()=>{})}function RS(e,t){if(!(!e||!t)){Ps[e]||(Ps[e]={});for(let[s,i]of Object.entries(t)){if(i.status==="pending")continue;let r=`${e}:${s}`;Ps[e][s]||Ho.has(r)||(Ho.add(r),W.send("get-agent-prompt",{runId:e,stage:s}).then(o=>{Ps[e][s]=o,Ho.delete(r),j()}).catch(()=>{Ho.delete(r)}))}}}function xg(e){if(!e||!e.stages)return null;for(let[t,s]of Object.entries(e.stages))if(s.status==="in_progress")return t;return null}function Lg(e,t){let s=xg(e),i=xg(t);i&&s!==i&&(bt="*",ri=null,ar(),I.clearLog(),W.send("unsubscribe-log").catch(()=>{}),W.send("subscribe-log",{stage:null,runId:t.id}).catch(()=>{}))}W.on("runs-list",(e,t)=>{if((I.getState().projects||[]).length>1){let i={...I.getState().runs},r=new Set((e.runs||[]).map(c=>c.id)),o=t?.project||null;if(o)for(let[c,l]of Object.entries(i))l._project===o&&!r.has(c)&&delete i[c];let n={...I.getState().archivedRuns};if(o)for(let[c,l]of Object.entries(n))l._project===o&&!r.has(c)&&delete n[c];let a=Date.now();for(let c of e.runs||[])if(o&&(c._project=o),c.archived){if(rn(c,a))continue;n[c.id]=c,delete i[c.id]}else i[c.id]=c,delete n[c.id];e.settings&&(Jt=e.settings),I.setState({runs:i,archivedRuns:n});return}e.settings&&(Jt=e.settings),I.setRunsBulk(e.runs||[])});W.on("run-snapshot",e=>{if(e?.id){let t=I.getRunById(e.id)??null;if(e.archived===!0||I.getState().archivedRuns[e.id]||Ko.handleRunUpdate(e.id,e,t),t&&Ps[e.id])for(let[i,r]of Object.entries(e.stages||{})){let o=t.stages?.[i]?.iterations?.length||0;(r.iterations?.length||0)>o&&delete Ps[e.id][i]}I.setRun(e.id,e),O.runId===e.id&&(Lg(t,e),Vn(e)),Ge&&(Ge=null,j())}});W.on("run-update",e=>{if(e?.id){let t=I.getRunById(e.id)??null;e.archived===!0||I.getState().archivedRuns[e.id]||Ko.handleRunUpdate(e.id,e,t),I.setRun(e.id,e),O.runId===e.id&&(Lg(t,e),Vn(e)),Ge&&(Ge=null,j())}});W.on("log-line",e=>{e&&(I.appendLog(e),e.iteration&&e.iteration>1&&e._iterStart&&bp(e.iteration),yc(e))});W.on("log-bulk",e=>{if(e&&Array.isArray(e.lines))for(let t of e.lines){let s={stage:e.stage,iteration:e.iteration,line:t,timestamp:new Date().toISOString()};I.appendLog(s),bt!=="*"&&Jp(s),yc(s)}});W.on("preferences",e=>{e&&(I.setState({preferences:e}),jr(e.theme||"light"))});W.on("beads-update",(e,t)=>{let s=I.getState().currentProjectId;t?.project&&s&&t.project!==s||e&&(I.setState({beads:{issues:e.issues||[],dbExists:e.dbExists??!1,dbPath:e.dbPath||null,loading:!1}}),O.runId&&O.section!=="beads"&&Mh(O.runId),Bh(),O.section==="beads"&&O.runId&&Oh(O.runId))});function Ta(){return W.send("list-runs").then(e=>{e.settings&&(Jt=e.settings),I.setRunsBulk(e.runs||[])})}W.on("run-started",()=>{Ta().catch(()=>{}),setTimeout(()=>Ta().catch(()=>{}),2e3)});W.on("run-archived",e=>{if(e?.runId){let t=I.getState().runs[e.runId]??I.getState().archivedRuns[e.runId];t?I.setRun(e.runId,{...t,archived:!0,archived_at:e.archived_at||new Date().toISOString()}):Ta().catch(()=>{})}});W.on("run-unarchived",e=>{if(e?.runId){let t=I.getState().runs[e.runId]??I.getState().archivedRuns[e.runId];if(t){let{archived:s,archived_at:i,...r}=t;I.setRun(e.runId,r)}else Ta().catch(()=>{})}});W.on("run-stopped",()=>{Ge=null,W.send("list-runs").then(e=>{e.settings&&(Jt=e.settings),I.setRunsBulk(e.runs||[])}).catch(()=>{})});W.on("stage-restarted",()=>{W.send("list-runs").then(e=>{e.settings&&(Jt=e.settings),I.setRunsBulk(e.runs||[])}).catch(()=>{})});W.on("learn-started",e=>{e?.runId&&e.runId===O.runId&&W.send("subscribe-run",{runId:e.runId}).catch(()=>{})});W.on("webhook-inbox-event",e=>{if(e){let t=I.getState().currentProjectId;if(!e.projectId||!t||e.projectId===t){let s=I.getState().webhookInbox;I.setState({webhookInbox:{...s,events:[...s.events,e]}})}}});W.on("webhook-control-changed",e=>{if(e){let t=I.getState().webhookInbox;I.setState({webhookInbox:{...t,controlAction:e.action}})}});W.on("webhook-inbox-cleared",()=>{let e=I.getState().webhookInbox;I.setState({webhookInbox:{...e,events:[]}}),Fi=null});W.on("pipeline-status-changed",e=>{let t=I.getState().currentProjectId;if(e.project&&t&&e.project!==t)return;let s={...I.getState().pipelines};e.status==="removed"?delete s[e.runId]:s[e.runId]={run_id:e.runId,status:e.status,stage:e.stage,title:e.title,worktree_path:e.worktree_path,started_at:e.started_at,pid:e.pid},I.setState({pipelines:s})});function LS(e){if(!(e?.capabilities||[]).includes("multi-project")){W.sendRaw({type:"hello-ack",payload:{protocol:2,projectId:null}}),kg();return}fetch("/api/projects").then(i=>i.json()).then(i=>{let r=i.projects||[];I.setState({projects:r});let o=O.projectId||(r.length===1?r[0].name:null);I.setState({currentProjectId:o}),W.sendRaw({type:"hello-ack",payload:{protocol:2,projectId:o}}),kg()}).catch(()=>{})}function Dg(){let e=I.getState().projects||[];Promise.all(e.map(t=>fetch(`/api/projects/${t.name}/runs`).then(s=>s.json()).then(s=>({runs:(s.runs||[]).map(i=>({...i,project:i.project||t.name})),settings:s.settings||null,projectName:t.name})).catch(()=>({runs:[],settings:null,projectName:t.name})))).then(t=>{let s={},i={},r=Date.now();for(let{runs:o,settings:n}of t){n&&(Jt=n);for(let a of o)if(a.archived){if(rn(a,r))continue;i[a.id]=a}else s[a.id]=a}I.setState({runs:s,archivedRuns:i,runsLoaded:!0}),j()})}function kg(){(I.getState().projects||[]).length>1?Dg():W.send("list-runs").then(e=>{e.settings&&(Jt=e.settings),I.setRunsBulk(e.runs||[])}).catch(()=>{}),W.send("list-beads-issues").then(e=>{I.setState({beads:{issues:e.issues||[],dbExists:e.dbExists??!1,dbPath:e.dbPath||null,loading:!1}})}).catch(()=>{}),W.send("get-webhook-inbox").then(e=>{I.setState({webhookInbox:{events:e.events||[],controlAction:e.controlAction||"continue"}})}).catch(()=>{}),W.send("list-pipelines").then(e=>{let t={};for(let s of e.pipelines||[])t[s.run_id]=s;I.setState({pipelines:t})}).catch(()=>{}),Bh(),Ih(),O.runId&&(O.section!=="beads"&&(W.send("subscribe-run",{runId:O.runId}).catch(()=>{}),W.send("subscribe-log",{stage:bt==="*"?null:bt,runId:O.runId}).catch(()=>{})),Mh(O.runId),O.section==="beads"&&Oh(O.runId))}W.on("hello",LS);W.on("projects-updated",e=>{e?.projects&&I.setState({projects:e.projects})});function DS(e){W.send("unsubscribe-run").catch(()=>{}),W.send("unsubscribe-log").catch(()=>{}),W.send("unsubscribe-events").catch(()=>{}),W.send("unsubscribe-pipeline").catch(()=>{}),I.clearLog(),I.setState({currentProjectId:e,runs:{},archivedRuns:{},logLines:[],activeRunId:null,pipelines:{}}),TS(),W.sendRaw({type:"hello-ack",payload:{protocol:2,projectId:e}}),(I.getState().projects||[]).length>1?Dg():W.send("list-runs").then(t=>{t.settings&&(Jt=t.settings),I.setRunsBulk(t.runs||[])}).catch(()=>{}),W.send("list-beads-issues").then(t=>{I.setState({beads:{issues:t.issues||[],dbExists:t.dbExists??!1,dbPath:t.dbPath||null,loading:!1}})}).catch(()=>{}),I.setState({webhookInbox:{events:[],controlAction:I.getState().webhookInbox?.controlAction||"continue"}}),W.send("get-webhook-inbox").then(t=>{I.setState({webhookInbox:{events:t.events||[],controlAction:t.controlAction||"continue"}})}).catch(()=>{}),Bh(),Ih()}W.onConnection(e=>{Rg=e,e==="open"&&W.send("get-preferences").then(t=>{I.setState({preferences:t}),jr(t.theme||"light")}).catch(()=>{}),j()});Zh(e=>{let t=O.runId,s=O.projectId;O=e,e.projectId!==s&&DS(e.projectId),t&&t!==O.runId&&(Aa.clear(),W.send("unsubscribe-run").catch(()=>{}),W.send("unsubscribe-log").catch(()=>{}),I.clearLog(),ar(),wc()),O.runId&&O.runId!==t&&(O.section==="beads"?Oh(O.runId):(bt="*",ri=null,W.send("subscribe-run",{runId:O.runId}).catch(()=>{}),W.send("subscribe-log",{stage:null,runId:O.runId}).catch(()=>{}),Mh(O.runId))),O.section==="settings"&&Js(null).then(()=>j()),O.section==="project-settings"&&Js(I.getState().currentProjectId||null).then(()=>j()),O.section==="costs"&&(Ra=!1,Pg()),!O.runId&&t&&(Zp(),yp()),j()});function PS(e){Oe(e,null,O.projectId)}function ka(e){Oe(O.section,e,O.projectId)}function MS(e){e?Oe(O.section,null,e):Oe("dashboard",null,null)}function BS(){let t=I.getState().preferences.theme==="dark"?"light":"dark";W.send("set-preferences",{theme:t}).catch(()=>{}),I.setState({preferences:{theme:t}}),jr(t)}function OS(e){W.send("set-preferences",{notifications:e}).catch(()=>{}),I.setState({preferences:{notifications:e}})}function IS(e){W.send("set-preferences",{source_repo:e}).catch(()=>{}),I.setState({preferences:{source_repo:e}})}function zS(e){if(bt=e,e!=="*"){let i=I.getRunById(O.runId)?.stages?.[e]?.iterations?.length||0;ri=i>0?i:null}else ri=null;ar(),I.clearLog(),W.send("unsubscribe-log").catch(()=>{}),W.send("subscribe-log",{stage:e==="*"?null:e,runId:O.runId,iteration:ri}).catch(()=>{}),j()}function NS(e){ri=e,ar(),I.clearLog(),W.send("unsubscribe-log").catch(()=>{}),W.send("subscribe-log",{stage:bt==="*"?null:bt,runId:O.runId,iteration:e}).catch(()=>{}),j()}function FS(e){$a=e,Qp(e)}function HS(){xh=!xh,j()}function Ee(e){oi=e,j(),requestAnimationFrame(()=>{let t=document.getElementById("action-error-dialog");t&&t.show()})}function WS(){oi=null,j()}function $g(){Ht({label:"Stop Pipeline?",message:"Are you sure? The current stage will be interrupted and marked as error.",confirmLabel:"Stop",confirmVariant:"danger",onConfirm:jS},j)}async function jS(){Ge="stopping",oi=null,j();try{let t=Object.values(I.getState().runs).find(r=>r.active)?.id||"current",i=await(await fetch(Zt(`/runs/${t}`),{method:"DELETE"})).json();i.ok||(Ge=null,Ee(i.error||"Failed to stop pipeline"))}catch(e){Ge=null,Ee(e?.message||"Failed to stop pipeline")}}async function VS(e){try{let s=await(await fetch(Zt(`/runs/${e}/cancel`),{method:"POST"})).json();s.ok||Ee(s.error||"Failed to cancel run")}catch(t){Ee(t?.message||"Failed to cancel run")}}function US(){Ge="resuming",oi=null,j(),W.send("resume-run",{runId:O.runId}).then(()=>{Ge=null,j()}).catch(e=>{Ge=null,Ee(e?.message||"Failed to resume pipeline")})}async function qS(){let t=Object.values(I.getState().runs).find(s=>s.active)?.id||"current";Ge="pausing",oi=null,j();try{let i=await(await fetch(Zt(`/runs/${t}/pause`),{method:"POST"})).json();i.ok||(Ge=null,Ee(i.error||"Failed to pause pipeline"))}catch(s){Ge=null,Ee(s?.message||"Failed to pause pipeline")}}async function Eg(e){Vo={action:"pause",runId:e},j();try{let s=await(await fetch(Zt(`/runs/${e}/pause`),{method:"POST"})).json();s.ok||Ee(s.error||"Failed to pause run")}catch(t){Ee(t?.message||"Failed to pause run")}finally{Vo=null,j()}}async function Sh(e){Vo={action:"resume",runId:e},j();try{let s=await(await fetch(Zt(`/runs/${e}/resume`),{method:"POST"})).json();s.ok||Ee(s.error||"Failed to resume run")}catch(t){Ee(t?.message||"Failed to resume run")}finally{Vo=null,j()}}var{archiveRun:Ch,unarchiveRun:KS}=td({showConfirm:Ht,showActionError:Ee,projectUrl:Zt,store:I,rerender:j});async function GS(e){try{let s=await(await fetch(Zt(`/pipelines/${e}/pause`),{method:"POST"})).json();s.ok||Ee(s.error||"Failed to pause pipeline")}catch(t){Ee(t?.message||"Failed to pause pipeline")}}async function YS(e){try{let s=await(await fetch(Zt(`/pipelines/${e}/stop`),{method:"POST"})).json();s.ok||Ee(s.error||"Failed to stop pipeline")}catch(t){Ee(t?.message||"Failed to stop pipeline")}}async function XS(e){try{await W.send("resume-run",{runId:e})}catch(t){Ee(t?.message||"Failed to resume pipeline")}}function JS(e){Uo=e,Ht({label:"Restart Stage?",message:`Restart the "${e}" stage? The pipeline will resume from this point.`,confirmLabel:"Restart",confirmVariant:"warning",onConfirm:ZS,onCancel:()=>{Uo=null}},j)}async function ZS(){let e=Uo;Uo=null,j();try{let s=Object.values(I.getState().runs).find(o=>!o.active)?.id||"current",r=await(await fetch(Zt(`/runs/${s}/stages/${e}/restart`),{method:"POST"})).json();r.ok?Oe("active",null,O.projectId):Ee(r.error||"Failed to restart stage")}catch(t){Ee(t?.message||"Failed to restart stage")}}function QS(){O.runId?Oe(O.section,null,O.projectId):O.section&&O.section!=="dashboard"&&Oe("dashboard",null,O.projectId)}function eC(e){kh=e,j()}function tC(e){$h=e,j()}async function sC(e){Wo=e,qo=null,j();try{await W.send("start-beads-issue",{issueId:e}),Wo=null,Oe("active",null,O.projectId)}catch(t){Wo=null,qo=t?.message||"Failed to start pipeline",j()}}function iC(){qo=null,j()}function Bh(){W.send("list-beads-counts").then(e=>{Th=e.counts||{},j()}).catch(()=>{})}function Oh(e){jo=!0,j(),W.send("list-beads-by-run",{runId:e}).then(t=>{Ah=t.issues||[],jo=!1,j()}).catch(()=>{jo=!1,j()})}function Pg(){fetch(Zt("/costs")).then(e=>e.json()).then(e=>{e.ok&&(Rh=e.tokenData||{},Ra=!0,j())}).catch(()=>{})}function Ih(){let e=I.getState().currentProjectId,t=e?`/api/projects/${e}/info`:"/api/project-info";fetch(t).then(s=>s.json()).then(s=>{let i=s.project?.name??s.name;i!==void 0&&(I.setState({projectName:i}),document.title=sd(i))}).catch(()=>{})}function rC(e){Ea=Ea===e?null:e,j()}function oC(e){Fi=Fi===e?null:e,j()}function nC(e){Lh=e,j()}function aC(e){Dh=e,j()}function lC(e){Ph=e,j()}function cC(e){W.send("set-webhook-control",{action:e}).catch(()=>{})}function Mg(){W.send("clear-webhook-inbox").catch(()=>{}),Fi=null}function hC(e){try{navigator.clipboard.writeText(JSON.stringify(e.envelope,null,2))}catch{}}function dC(){Fi=null,j()}function uC(){let t=I.getRunById(O.runId)?.stages?.learn?.status;if(t==="completed"||t==="error"){Ht({label:"Re-run Learning Analysis?",message:"This will replace existing learnings. Continue?",confirmLabel:"Re-run",confirmVariant:"warning",onConfirm:Tg},j);return}Tg()}async function Tg(){j();try{let e=O.runId,s=await(await fetch(Zt(`/runs/${e}/learn`),{method:"POST"})).json();if(!s.ok)Ee(s.error||"Failed to run learning analysis");else{let i=I.getRunById(e);if(i){let r=new Date().toISOString();I.setRun(e,{...i,stages:{...i.stages||{},learn:{status:"in_progress",pid:s.pid,started_at:r,iterations:[{number:1,status:"in_progress",started_at:r,trigger:"manual"}]}}})}}}catch(e){Ee(e?.message||"Failed to run learning analysis")}}function pC(){let e=I.getState(),t="Dashboard",s=!1,i=null,r=null;if(O.section==="beads"&&O.runId){let a=(I.getRunById(O.runId)?.work_request?.title||O.runId).split(`
|
|
5847
|
+
`}};ae.styles=[te,ii,Cg];g([Q(".textarea__control")],ae.prototype,"input",2);g([Q(".textarea__size-adjuster")],ae.prototype,"sizeAdjuster",2);g([he()],ae.prototype,"hasFocus",2);g([b()],ae.prototype,"title",2);g([b()],ae.prototype,"name",2);g([b()],ae.prototype,"value",2);g([b({reflect:!0})],ae.prototype,"size",2);g([b({type:Boolean,reflect:!0})],ae.prototype,"filled",2);g([b()],ae.prototype,"label",2);g([b({attribute:"help-text"})],ae.prototype,"helpText",2);g([b()],ae.prototype,"placeholder",2);g([b({type:Number})],ae.prototype,"rows",2);g([b()],ae.prototype,"resize",2);g([b({type:Boolean,reflect:!0})],ae.prototype,"disabled",2);g([b({type:Boolean,reflect:!0})],ae.prototype,"readonly",2);g([b({reflect:!0})],ae.prototype,"form",2);g([b({type:Boolean,reflect:!0})],ae.prototype,"required",2);g([b({type:Number})],ae.prototype,"minlength",2);g([b({type:Number})],ae.prototype,"maxlength",2);g([b()],ae.prototype,"autocapitalize",2);g([b()],ae.prototype,"autocorrect",2);g([b()],ae.prototype,"autocomplete",2);g([b({type:Boolean})],ae.prototype,"autofocus",2);g([b()],ae.prototype,"enterkeyhint",2);g([b({type:Boolean,converter:{fromAttribute:e=>!(!e||e==="false"),toAttribute:e=>e?"true":"false"}})],ae.prototype,"spellcheck",2);g([b()],ae.prototype,"inputmode",2);g([Cr()],ae.prototype,"defaultValue",2);g([Y("disabled",{waitUntilFirstUpdate:!0})],ae.prototype,"handleDisabledChange",1);g([Y("rows",{waitUntilFirstUpdate:!0})],ae.prototype,"handleRowsChange",1);g([Y("value",{waitUntilFirstUpdate:!0})],ae.prototype,"handleValueChange",1);ae.define("sl-textarea");var I=ed();function Zt(e){let t=I.getState().currentProjectId;return t?`/api/projects/${t}${e}`:`/api${e}`}var W=zf(),Ko=Qh({store:I,ws:W,getSettings:()=>Jt}),O=Na(location.hash),Rg=W.getState(),xh=!0,Jt={},Ge=null,Vo=null,oi=null,Uo=null,bt="*",$a="",ri=null,Ps={},Ho=new Set,kh="all",$h="all",Wo=null,qo=null,Eh=new Map,Th={},Ah=[],jo=!1,Aa=new Map,Rh={},Ea=null,Ra=!1,Fi=null,Lh="all",Dh=null,Ph="",xa="all";function TS(){Jt={},Ge=null,Vo=null,oi=null,Uo=null,bt="*",$a="",ri=null;for(let e of Object.keys(Ps))delete Ps[e];Ho.clear(),kh="all",$h="all",Wo=null,qo=null,Eh.clear(),Th={},Ah=[],jo=!1,Aa.clear(),Rh={},Ea=null,Ra=!1,Fi=null,Lh="all",Dh=null,Ph="",xa="all"}function AS(e,t){Aa.set(e,t)}function Mh(e){e&&W.send("list-beads-by-run",{runId:e}).then(t=>{Eh.set(e,t.issues||[]),j()}).catch(()=>{})}function RS(e,t){if(!(!e||!t)){Ps[e]||(Ps[e]={});for(let[s,i]of Object.entries(t)){if(i.status==="pending")continue;let r=`${e}:${s}`;Ps[e][s]||Ho.has(r)||(Ho.add(r),W.send("get-agent-prompt",{runId:e,stage:s}).then(o=>{Ps[e][s]=o,Ho.delete(r),j()}).catch(()=>{Ho.delete(r)}))}}}function xg(e){if(!e||!e.stages)return null;for(let[t,s]of Object.entries(e.stages))if(s.status==="in_progress")return t;return null}function Lg(e,t){let s=xg(e),i=xg(t);i&&s!==i&&(bt="*",ri=null,ar(),I.clearLog(),W.send("unsubscribe-log").catch(()=>{}),W.send("subscribe-log",{stage:null,runId:t.id}).catch(()=>{}))}W.on("runs-list",(e,t)=>{if((I.getState().projects||[]).length>1){let i={...I.getState().runs},r=new Set((e.runs||[]).map(c=>c.id)),o=t?.project||null;if(o)for(let[c,l]of Object.entries(i))l._project===o&&!r.has(c)&&delete i[c];let n={...I.getState().archivedRuns};if(o)for(let[c,l]of Object.entries(n))l._project===o&&!r.has(c)&&delete n[c];let a=Date.now();for(let c of e.runs||[])if(o&&(c._project=o),c.archived){if(rn(c,a))continue;n[c.id]=c,delete i[c.id]}else i[c.id]=c,delete n[c.id];e.settings&&(Jt=e.settings),I.setState({runs:i,archivedRuns:n});return}e.settings&&(Jt=e.settings),I.setRunsBulk(e.runs||[])});W.on("run-snapshot",e=>{if(e?.id){let t=I.getRunById(e.id)??null;if(e.archived===!0||I.getState().archivedRuns[e.id]||Ko.handleRunUpdate(e.id,e,t),t&&Ps[e.id])for(let[i,r]of Object.entries(e.stages||{})){let o=t.stages?.[i]?.iterations?.length||0;(r.iterations?.length||0)>o&&delete Ps[e.id][i]}I.setRun(e.id,e),O.runId===e.id&&(Lg(t,e),Vn(e)),Ge&&(Ge=null,j())}});W.on("run-update",e=>{if(e?.id){let t=I.getRunById(e.id)??null;e.archived===!0||I.getState().archivedRuns[e.id]||Ko.handleRunUpdate(e.id,e,t),I.setRun(e.id,e),O.runId===e.id&&(Lg(t,e),Vn(e)),Ge&&(Ge=null,j())}});W.on("log-line",e=>{e&&(I.appendLog(e),e.iteration&&e.iteration>1&&e._iterStart&&bp(e.iteration),yc(e))});W.on("log-bulk",e=>{if(e&&Array.isArray(e.lines))for(let t of e.lines){let s={stage:e.stage,iteration:e.iteration,line:t,timestamp:new Date().toISOString()};I.appendLog(s),bt!=="*"&&Jp(s),yc(s)}});W.on("preferences",e=>{e&&(I.setState({preferences:e}),jr(e.theme||"light"))});W.on("beads-update",(e,t)=>{let s=I.getState().currentProjectId;t?.project&&s&&t.project!==s||e&&(I.setState({beads:{issues:e.issues||[],dbExists:e.dbExists??!1,dbPath:e.dbPath||null,loading:!1}}),O.runId&&O.section!=="beads"&&Mh(O.runId),Bh(),O.section==="beads"&&O.runId&&Oh(O.runId))});function Ta(){return W.send("list-runs").then(e=>{e.settings&&(Jt=e.settings),I.setRunsBulk(e.runs||[])})}W.on("run-started",()=>{Ta().catch(()=>{}),setTimeout(()=>Ta().catch(()=>{}),2e3)});W.on("run-archived",e=>{if(e?.runId){let t=I.getState().runs[e.runId]??I.getState().archivedRuns[e.runId];t?I.setRun(e.runId,{...t,archived:!0,archived_at:e.archived_at||new Date().toISOString()}):Ta().catch(()=>{})}});W.on("run-unarchived",e=>{if(e?.runId){let t=I.getState().runs[e.runId]??I.getState().archivedRuns[e.runId];if(t){let{archived:s,archived_at:i,...r}=t;I.setRun(e.runId,r)}else Ta().catch(()=>{})}});W.on("run-stopped",()=>{Ge=null,W.send("list-runs").then(e=>{e.settings&&(Jt=e.settings),I.setRunsBulk(e.runs||[])}).catch(()=>{})});W.on("stage-restarted",()=>{W.send("list-runs").then(e=>{e.settings&&(Jt=e.settings),I.setRunsBulk(e.runs||[])}).catch(()=>{})});W.on("learn-started",e=>{e?.runId&&e.runId===O.runId&&W.send("subscribe-run",{runId:e.runId}).catch(()=>{})});W.on("webhook-inbox-event",e=>{if(e){let t=I.getState().currentProjectId;if(!e.projectId||!t||e.projectId===t){let s=I.getState().webhookInbox;I.setState({webhookInbox:{...s,events:[...s.events,e]}})}}});W.on("webhook-control-changed",e=>{if(e){let t=I.getState().webhookInbox;I.setState({webhookInbox:{...t,controlAction:e.action}})}});W.on("webhook-inbox-cleared",()=>{let e=I.getState().webhookInbox;I.setState({webhookInbox:{...e,events:[]}}),Fi=null});W.on("pipeline-status-changed",e=>{let t=I.getState().currentProjectId;if(e.project&&t&&e.project!==t)return;let s={...I.getState().pipelines};e.status==="removed"?delete s[e.runId]:s[e.runId]={run_id:e.runId,status:e.status,stage:e.stage,title:e.title,worktree_path:e.worktree_path,started_at:e.started_at,pid:e.pid},I.setState({pipelines:s})});function LS(e){if(!(e?.capabilities||[]).includes("multi-project")){W.sendRaw({type:"hello-ack",payload:{protocol:2,projectId:null}}),kg();return}fetch("/api/projects").then(i=>i.json()).then(i=>{let r=i.projects||[];I.setState({projects:r});let o=O.projectId||(r.length===1?r[0].name:null);I.setState({currentProjectId:o}),W.sendRaw({type:"hello-ack",payload:{protocol:2,projectId:o}}),kg()}).catch(()=>{})}function Dg(){let e=I.getState().projects||[];Promise.all(e.map(t=>fetch(`/api/projects/${t.name}/runs`).then(s=>s.json()).then(s=>({runs:(s.runs||[]).map(i=>({...i,project:i.project||t.name})),settings:s.settings||null,projectName:t.name})).catch(()=>({runs:[],settings:null,projectName:t.name})))).then(t=>{let s={},i={},r=Date.now();for(let{runs:o,settings:n}of t){n&&(Jt=n);for(let a of o)if(a.archived){if(rn(a,r))continue;i[a.id]=a}else s[a.id]=a}I.setState({runs:s,archivedRuns:i,runsLoaded:!0}),j()})}function kg(){(I.getState().projects||[]).length>1?Dg():W.send("list-runs").then(e=>{e.settings&&(Jt=e.settings),I.setRunsBulk(e.runs||[])}).catch(()=>{}),W.send("list-beads-issues").then(e=>{I.setState({beads:{issues:e.issues||[],dbExists:e.dbExists??!1,dbPath:e.dbPath||null,loading:!1}})}).catch(()=>{}),W.send("get-webhook-inbox").then(e=>{I.setState({webhookInbox:{events:e.events||[],controlAction:e.controlAction||"continue"}})}).catch(()=>{}),W.send("list-pipelines").then(e=>{let t={};for(let s of e.pipelines||[])t[s.run_id]=s;I.setState({pipelines:t})}).catch(()=>{}),Bh(),Ih(),O.runId&&(O.section!=="beads"&&(W.send("subscribe-run",{runId:O.runId}).catch(()=>{}),W.send("subscribe-log",{stage:bt==="*"?null:bt,runId:O.runId}).catch(()=>{})),Mh(O.runId),O.section==="beads"&&Oh(O.runId))}W.on("hello",LS);W.on("projects-updated",e=>{e?.projects&&I.setState({projects:e.projects})});function DS(e){W.send("unsubscribe-run").catch(()=>{}),W.send("unsubscribe-log").catch(()=>{}),W.send("unsubscribe-events").catch(()=>{}),W.send("unsubscribe-pipeline").catch(()=>{}),I.clearLog(),I.setState({currentProjectId:e,runs:{},archivedRuns:{},logLines:[],activeRunId:null,pipelines:{}}),TS(),W.sendRaw({type:"hello-ack",payload:{protocol:2,projectId:e}}),(I.getState().projects||[]).length>1?Dg():W.send("list-runs").then(t=>{t.settings&&(Jt=t.settings),I.setRunsBulk(t.runs||[])}).catch(()=>{}),W.send("list-beads-issues").then(t=>{I.setState({beads:{issues:t.issues||[],dbExists:t.dbExists??!1,dbPath:t.dbPath||null,loading:!1}})}).catch(()=>{}),I.setState({webhookInbox:{events:[],controlAction:I.getState().webhookInbox?.controlAction||"continue"}}),W.send("get-webhook-inbox").then(t=>{I.setState({webhookInbox:{events:t.events||[],controlAction:t.controlAction||"continue"}})}).catch(()=>{}),Bh(),Ih()}W.onConnection(e=>{Rg=e,e==="open"&&W.send("get-preferences").then(t=>{I.setState({preferences:t}),jr(t.theme||"light")}).catch(()=>{}),j()});Zh(e=>{let t=O.runId,s=O.projectId;O=e,e.projectId!==s&&DS(e.projectId),t&&t!==O.runId&&(Aa.clear(),W.send("unsubscribe-run").catch(()=>{}),W.send("unsubscribe-log").catch(()=>{}),I.clearLog(),ar(),wc()),O.runId&&O.runId!==t&&(O.section==="beads"?Oh(O.runId):(bt="*",ri=null,W.send("subscribe-run",{runId:O.runId}).catch(()=>{}),W.send("subscribe-log",{stage:null,runId:O.runId}).catch(()=>{}),Mh(O.runId))),O.section==="settings"&&Js(null).then(()=>j()),O.section==="project-settings"&&Js(I.getState().currentProjectId||null).then(()=>j()),O.section==="costs"&&(Ra=!1,Pg()),!O.runId&&t&&(Zp(),yp()),j()});function PS(e){Oe(e,null,O.projectId)}function ka(e){Oe(O.section,e,O.projectId)}function MS(e){e?Oe(O.section,null,e):Oe("dashboard",null,null)}function BS(){let t=I.getState().preferences.theme==="dark"?"light":"dark";W.send("set-preferences",{theme:t}).catch(()=>{}),I.setState({preferences:{theme:t}}),jr(t)}function OS(e){W.send("set-preferences",{notifications:e}).catch(()=>{}),I.setState({preferences:{notifications:e}})}function IS(e){W.send("set-preferences",{source_repo:e}).catch(()=>{}),I.setState({preferences:{source_repo:e}})}function zS(e){if(bt=e,e!=="*"){let i=I.getRunById(O.runId)?.stages?.[e]?.iterations?.length||0;ri=i>0?i:null}else ri=null;ar(),I.clearLog(),W.send("unsubscribe-log").catch(()=>{}),W.send("subscribe-log",{stage:e==="*"?null:e,runId:O.runId,iteration:ri}).catch(()=>{}),j()}function NS(e){ri=e,ar(),I.clearLog(),W.send("unsubscribe-log").catch(()=>{}),W.send("subscribe-log",{stage:bt==="*"?null:bt,runId:O.runId,iteration:e}).catch(()=>{}),j()}function FS(e){$a=e,Qp(e)}function HS(){xh=!xh,j()}function Ee(e){oi=e,j(),requestAnimationFrame(()=>{let t=document.getElementById("action-error-dialog");t&&t.show()})}function WS(){oi=null,j()}function $g(){Ht({label:"Stop Pipeline?",message:"Are you sure? The current stage will be interrupted and marked as error.",confirmLabel:"Stop",confirmVariant:"danger",onConfirm:jS},j)}async function jS(){Ge="stopping",oi=null,j();try{let t=Object.values(I.getState().runs).find(r=>r.active)?.id||"current",i=await(await fetch(Zt(`/runs/${t}/stop`),{method:"POST"})).json();i.ok||(Ge=null,Ee(i.error||"Failed to stop pipeline"))}catch(e){Ge=null,Ee(e?.message||"Failed to stop pipeline")}}async function VS(e){try{let s=await(await fetch(Zt(`/runs/${e}/cancel`),{method:"POST"})).json();s.ok||Ee(s.error||"Failed to cancel run")}catch(t){Ee(t?.message||"Failed to cancel run")}}function US(){Ge="resuming",oi=null,j(),W.send("resume-run",{runId:O.runId}).then(()=>{Ge=null,j()}).catch(e=>{Ge=null,Ee(e?.message||"Failed to resume pipeline")})}async function qS(){let t=Object.values(I.getState().runs).find(s=>s.active)?.id||"current";Ge="pausing",oi=null,j();try{let i=await(await fetch(Zt(`/runs/${t}/pause`),{method:"POST"})).json();i.ok||(Ge=null,Ee(i.error||"Failed to pause pipeline"))}catch(s){Ge=null,Ee(s?.message||"Failed to pause pipeline")}}async function Eg(e){Vo={action:"pause",runId:e},j();try{let s=await(await fetch(Zt(`/runs/${e}/pause`),{method:"POST"})).json();s.ok||Ee(s.error||"Failed to pause run")}catch(t){Ee(t?.message||"Failed to pause run")}finally{Vo=null,j()}}async function Sh(e){Vo={action:"resume",runId:e},j();try{let s=await(await fetch(Zt(`/runs/${e}/resume`),{method:"POST"})).json();s.ok||Ee(s.error||"Failed to resume run")}catch(t){Ee(t?.message||"Failed to resume run")}finally{Vo=null,j()}}var{archiveRun:Ch,unarchiveRun:KS}=td({showConfirm:Ht,showActionError:Ee,projectUrl:Zt,store:I,rerender:j});async function GS(e){try{let s=await(await fetch(Zt(`/pipelines/${e}/pause`),{method:"POST"})).json();s.ok||Ee(s.error||"Failed to pause pipeline")}catch(t){Ee(t?.message||"Failed to pause pipeline")}}async function YS(e){try{let s=await(await fetch(Zt(`/pipelines/${e}/stop`),{method:"POST"})).json();s.ok||Ee(s.error||"Failed to stop pipeline")}catch(t){Ee(t?.message||"Failed to stop pipeline")}}async function XS(e){try{await W.send("resume-run",{runId:e})}catch(t){Ee(t?.message||"Failed to resume pipeline")}}function JS(e){Uo=e,Ht({label:"Restart Stage?",message:`Restart the "${e}" stage? The pipeline will resume from this point.`,confirmLabel:"Restart",confirmVariant:"warning",onConfirm:ZS,onCancel:()=>{Uo=null}},j)}async function ZS(){let e=Uo;Uo=null,j();try{let s=Object.values(I.getState().runs).find(o=>!o.active)?.id||"current",r=await(await fetch(Zt(`/runs/${s}/stages/${e}/restart`),{method:"POST"})).json();r.ok?Oe("active",null,O.projectId):Ee(r.error||"Failed to restart stage")}catch(t){Ee(t?.message||"Failed to restart stage")}}function QS(){O.runId?Oe(O.section,null,O.projectId):O.section&&O.section!=="dashboard"&&Oe("dashboard",null,O.projectId)}function eC(e){kh=e,j()}function tC(e){$h=e,j()}async function sC(e){Wo=e,qo=null,j();try{await W.send("start-beads-issue",{issueId:e}),Wo=null,Oe("active",null,O.projectId)}catch(t){Wo=null,qo=t?.message||"Failed to start pipeline",j()}}function iC(){qo=null,j()}function Bh(){W.send("list-beads-counts").then(e=>{Th=e.counts||{},j()}).catch(()=>{})}function Oh(e){jo=!0,j(),W.send("list-beads-by-run",{runId:e}).then(t=>{Ah=t.issues||[],jo=!1,j()}).catch(()=>{jo=!1,j()})}function Pg(){fetch(Zt("/costs")).then(e=>e.json()).then(e=>{e.ok&&(Rh=e.tokenData||{},Ra=!0,j())}).catch(()=>{})}function Ih(){let e=I.getState().currentProjectId,t=e?`/api/projects/${e}/info`:"/api/project-info";fetch(t).then(s=>s.json()).then(s=>{let i=s.project?.name??s.name;i!==void 0&&(I.setState({projectName:i}),document.title=sd(i))}).catch(()=>{})}function rC(e){Ea=Ea===e?null:e,j()}function oC(e){Fi=Fi===e?null:e,j()}function nC(e){Lh=e,j()}function aC(e){Dh=e,j()}function lC(e){Ph=e,j()}function cC(e){W.send("set-webhook-control",{action:e}).catch(()=>{})}function Mg(){W.send("clear-webhook-inbox").catch(()=>{}),Fi=null}function hC(e){try{navigator.clipboard.writeText(JSON.stringify(e.envelope,null,2))}catch{}}function dC(){Fi=null,j()}function uC(){let t=I.getRunById(O.runId)?.stages?.learn?.status;if(t==="completed"||t==="error"){Ht({label:"Re-run Learning Analysis?",message:"This will replace existing learnings. Continue?",confirmLabel:"Re-run",confirmVariant:"warning",onConfirm:Tg},j);return}Tg()}async function Tg(){j();try{let e=O.runId,s=await(await fetch(Zt(`/runs/${e}/learn`),{method:"POST"})).json();if(!s.ok)Ee(s.error||"Failed to run learning analysis");else{let i=I.getRunById(e);if(i){let r=new Date().toISOString();I.setRun(e,{...i,stages:{...i.stages||{},learn:{status:"in_progress",pid:s.pid,started_at:r,iterations:[{number:1,status:"in_progress",started_at:r,trigger:"manual"}]}}})}}}catch(e){Ee(e?.message||"Failed to run learning analysis")}}function pC(){let e=I.getState(),t="Dashboard",s=!1,i=null,r=null;if(O.section==="beads"&&O.runId){let a=(I.getRunById(O.runId)?.work_request?.title||O.runId).split(`
|
|
5848
5848
|
`)[0];t=a.length>80?`${a.slice(0,80)}\u2026`:a,s=!0}else if(O.section==="beads"&&!O.runId){t="Beads Issues",s=!0;let o=e.beads?.dbPath;o&&(r=u`<span class="beads-db-path">${A(L(qa,12))} Beads DB<br><code>${o}</code></span>`)}else if(O.runId){let o=I.getRunById(O.runId),a=(o?.work_request?.title||"Pipeline Details").split(`
|
|
5849
5849
|
`)[0];if(t=a.length>80?`${a.slice(0,80)}\u2026`:a,s=!0,o){let c=o.pipeline_status||(o.active?"running":"completed"),h={running:"warning",resuming:"warning",paused:"warning",completed:"success",failed:"danger"}[c]||"neutral",d=c.charAt(0).toUpperCase()+c.slice(1);i=u`<sl-badge variant="${h}" pill>
|
|
5850
5850
|
${A(jt(c,12))}
|