cogpit 3.0.0 → 3.1.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.
Files changed (40) hide show
  1. package/README.md +1 -1
  2. package/dist/cli-runtime.js +57254 -0
  3. package/dist/cli.js +5 -44811
  4. package/dist/instance-worker.js +19943 -0
  5. package/dist/web/assets/CogpitBlock-DngXfAds.js +35 -0
  6. package/dist/web/assets/CommandPaletteHost-qBLfTYUI.js +1 -0
  7. package/dist/web/assets/{ConfigBrowser-CXvr5BFb.js → ConfigBrowser-CX8VxPCF.js} +1 -1
  8. package/dist/web/assets/CrewPanel-BQinfJ8Y.js +1 -0
  9. package/dist/web/assets/{HighlightedEditor-DWc-xoSc.js → HighlightedEditor-Cz0PCIaA.js} +1 -1
  10. package/dist/web/assets/{KeyboardShortcutsDialog-C1of2PBc.js → KeyboardShortcutsDialog-B7cVkxlZ.js} +1 -1
  11. package/dist/web/assets/MissionHome-CCYLRIPz.js +1 -0
  12. package/dist/web/assets/{MobileFileChanges-BAEIKapA.js → MobileFileChanges-FHYv1Fc1.js} +1 -1
  13. package/dist/web/assets/{PluginsDialog-BgnTB0-z.js → PluginsDialog-Bwf8bQH-.js} +1 -1
  14. package/dist/web/assets/{PreviewPanel-DgbgRibz.js → PreviewPanel-DC6gaBWX.js} +1 -1
  15. package/dist/web/assets/{ProjectFilesPanel-BGpyS_aw.js → ProjectFilesPanel-BEVS1EcM.js} +3 -3
  16. package/dist/web/assets/{ProjectSwitcherModal-CEypvUNm.js → ProjectSwitcherModal-ByUN7aFG.js} +1 -1
  17. package/dist/web/assets/{TerminalOutput-Dq6QP83Y.js → TerminalOutput-DcUf6lUO.js} +1 -1
  18. package/dist/web/assets/{ThemeSelectorModal-DeYABHF9.js → ThemeSelectorModal-rD4ZYmvZ.js} +1 -1
  19. package/dist/web/assets/WorkflowsPanel-BbzofKqG.js +1 -0
  20. package/dist/web/assets/WorktreePanel-CAVc-e2v.js +1 -0
  21. package/dist/web/assets/edition-ui-D3yHMSJq.js +2 -0
  22. package/dist/web/assets/index-CYJLZdyZ.js +482 -0
  23. package/dist/web/assets/{index-DYugSKH5.js → index-Ca9i-hcz.js} +4 -4
  24. package/dist/web/assets/index-D6mWk1bF.css +1 -0
  25. package/dist/web/assets/index-DO4zq6Qr.js +1 -0
  26. package/dist/web/assets/{index-Bm91RnFy.js → index-DRHHijwL.js} +1 -1
  27. package/dist/web/assets/session-parser.worker-D3SBmcaP.js +30 -0
  28. package/dist/web/assets/vendor-ui-Dxtv9P3W.js +987 -0
  29. package/dist/web/index.html +3 -3
  30. package/package.json +5 -3
  31. package/dist/web/assets/CommandPaletteHost-fa5vgo7-.js +0 -1
  32. package/dist/web/assets/WorkflowsPanel-CNxUSC9Q.js +0 -1
  33. package/dist/web/assets/WorktreePanel-DJYEUobs.js +0 -1
  34. package/dist/web/assets/edition-ui-CFlDe2_U.js +0 -2
  35. package/dist/web/assets/index-Ch-IpPaH.js +0 -1
  36. package/dist/web/assets/index-DVp2Xjmx.js +0 -1
  37. package/dist/web/assets/index-DsnL-sXV.js +0 -472
  38. package/dist/web/assets/index-TCQKag8a.css +0 -1
  39. package/dist/web/assets/session-parser.worker-CXlsiJzz.js +0 -29
  40. package/dist/web/assets/vendor-ui-Br3ZTAXZ.js +0 -957
@@ -1 +1 @@
1
- import{c as ue,r as C,j as t}from"./vendor-react-gGw_S5I_.js";import{C as Q,b8 as Ie,a$ as X,b9 as Qe,b0 as Re,ba as Xe,b4 as de,B as E,z as Fe,bb as et,bc as Ge,bd as Ke,be as Je,bf as We,bg as Ye,bh as Ze,A as se,p as ne,bi as tt,Z as $e,bj as st,bk as Me,a7 as nt,a8 as it,ab as lt,a5 as at,aa as ot,a9 as rt,a4 as ct,a3 as dt,aV as De,bl as ut,bm as ft,D as ht,h as mt,i as pt,j as xt,k as gt,bn as jt,bo as bt,bp as vt,bq as Ae,br as Oe,L as yt,M as Ct,N as wt,O as Nt,Q as St}from"./index-DsnL-sXV.js";import{a as kt,aj as $t}from"./vendor-ui-Br3ZTAXZ.js";import"./vendor-shiki-DOn6sF-i.js";import"./vendor-markdown-BE1gYnO9.js";function Be(l){const e=l.trim().replace(/^v/i,"").match(/^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?/);return e?{parts:[Number(e[1]),Number(e[2]),Number(e[3])],prerelease:e[4]?e[4].split("."):[]}:null}function Dt(l,e){if(l.length===0&&e.length===0)return 0;if(l.length===0)return 1;if(e.length===0)return-1;for(let s=0;s<Math.max(l.length,e.length);s+=1){const i=l[s],r=e[s];if(i===void 0)return-1;if(r===void 0)return 1;const a=/^\d+$/.test(i),n=/^\d+$/.test(r);if(a&&n){if(Number(i)!==Number(r))return Number(i)<Number(r)?-1:1;continue}if(a!==n)return a?-1:1;if(i!==r)return i<r?-1:1}return 0}function It(l,e){const s=Be(l),i=Be(e);if(!s||!i)return null;for(let r=0;r<3;r+=1)if(s.parts[r]!==i.parts[r])return s.parts[r]<i.parts[r]?-1:1;return Dt(s.prerelease,i.prerelease)}function Ue(l){const e=ue.c(33),{value:s,onChange:i,projects:r,disabled:a}=l,n=a===void 0?!1:a,d=C.useId();let o;e[0]!==s.projectIds||e[1]!==s.type?(o=s.type==="projects"?s.projectIds:[],e[0]=s.projectIds,e[1]=s.type,e[2]=o):o=e[2];let v;e[3]!==o?(v=new Set(o),e[3]=o,e[4]=v):v=e[4];const y=v;let h;e[5]===Symbol.for("react.memo_cache_sentinel")?(h=t.jsx(Qe,{children:"Available in"}),e[5]=h):h=e[5];const w=`${d}-all`,j=s.type==="all";let c;e[6]!==i?(c=N=>i(N?{type:"all"}:{type:"projects",projectIds:[]}),e[6]=i,e[7]=c):c=e[7];let p;e[8]!==n||e[9]!==w||e[10]!==j||e[11]!==c?(p=t.jsx(Ie,{id:w,checked:j,disabled:n,onCheckedChange:c}),e[8]=n,e[9]=w,e[10]=j,e[11]=c,e[12]=p):p=e[12];const m=`${d}-all`;let x;e[13]!==m?(x=t.jsx(X,{htmlFor:m,children:"All projects on this host, including new projects"}),e[13]=m,e[14]=x):x=e[14];let g;e[15]!==x||e[16]!==p?(g=t.jsxs(Q,{orientation:"horizontal",children:[p,x]}),e[15]=x,e[16]=p,e[17]=g):g=e[17];let b;e[18]!==n||e[19]!==d||e[20]!==i||e[21]!==r||e[22]!==y||e[23]!==s.projectIds||e[24]!==s.type?(b=s.type==="projects"&&t.jsx("div",{className:"flex max-h-40 flex-col gap-3 overflow-y-auto",children:r.map(N=>t.jsxs(Q,{orientation:"horizontal",children:[t.jsx(Ie,{id:`${d}-${N.id}`,checked:y.has(N.id),disabled:n,onCheckedChange:D=>i({type:"projects",projectIds:D?[...s.projectIds,N.id]:s.projectIds.filter(R=>R!==N.id)})}),t.jsx(X,{htmlFor:`${d}-${N.id}`,children:N.name})]},N.id))}),e[18]=n,e[19]=d,e[20]=i,e[21]=r,e[22]=y,e[23]=s.projectIds,e[24]=s.type,e[25]=b):b=e[25];const k=s.type==="projects"&&s.projectIds.length===0?"Installed but hidden until you choose a project.":"This setting is shared by every client connected to this host.";let S;e[26]!==k?(S=t.jsx(Re,{children:k}),e[26]=k,e[27]=S):S=e[27];let u;return e[28]!==n||e[29]!==g||e[30]!==b||e[31]!==S?(u=t.jsxs(Xe,{disabled:n,children:[h,g,b,S]}),e[28]=n,e[29]=g,e[30]=b,e[31]=S,e[32]=u):u=e[32],u}function Rt(l){const e=ue.c(69),{client:s,run:i,busy:r}=l,a=C.useId(),[n,d]=C.useState(""),[o,v]=C.useState(""),[y,h]=C.useState(null),[w,j]=C.useState(""),[c,p]=C.useState(!1);let m;e[0]!==s||e[1]!==w||e[2]!==o||e[3]!==n||e[4]!==y||e[5]!==i?(m=Y=>{Y.preventDefault(),i(async()=>{var ce;if(!y||y.size>262144)throw new Error("Choose a root metadata file smaller than 256 KiB");if(!((ce=globalThis.crypto)!=null&&ce.subtle))throw new Error("Publisher enrollment requires HTTPS or localhost");const B=await y.arrayBuffer(),re=Array.from(new Uint8Array(await crypto.subtle.digest("SHA-256",B)),Et).join("");if(re!==w.trim().toLowerCase())throw new Error("The root file does not match the fingerprint you entered");await s.enrollDeveloper({publisher:n,label:o,root:new TextDecoder("utf-8",{fatal:!0}).decode(B),fingerprint:re}),p(!1),d(""),v(""),j("")})},e[0]=s,e[1]=w,e[2]=o,e[3]=n,e[4]=y,e[5]=i,e[6]=m):m=e[6];const x=`${a}-name`;let g;e[7]!==x?(g=t.jsx(X,{htmlFor:x,children:"Development publisher"}),e[7]=x,e[8]=g):g=e[8];const b=`${a}-name`;let k;e[9]===Symbol.for("react.memo_cache_sentinel")?(k=Y=>d(Y.target.value),e[9]=k):k=e[9];let S;e[10]!==r||e[11]!==n||e[12]!==b?(S=t.jsx(de,{id:b,value:n,onChange:k,placeholder:"dev-your-name",pattern:"dev-[a-z0-9-]+",maxLength:64,required:!0,disabled:r}),e[10]=r,e[11]=n,e[12]=b,e[13]=S):S=e[13];let u;e[14]===Symbol.for("react.memo_cache_sentinel")?(u=t.jsx(Re,{children:"Development publishers have a separate namespace from official plugins."}),e[14]=u):u=e[14];let N;e[15]!==g||e[16]!==S?(N=t.jsxs(Q,{children:[g,S,u]}),e[15]=g,e[16]=S,e[17]=N):N=e[17];const D=`${a}-label`;let R;e[18]!==D?(R=t.jsx(X,{htmlFor:D,children:"Display name"}),e[18]=D,e[19]=R):R=e[19];const A=`${a}-label`;let O;e[20]===Symbol.for("react.memo_cache_sentinel")?(O=Y=>v(Y.target.value),e[20]=O):O=e[20];let I;e[21]!==r||e[22]!==o||e[23]!==A?(I=t.jsx(de,{id:A,value:o,onChange:O,maxLength:100,required:!0,disabled:r}),e[21]=r,e[22]=o,e[23]=A,e[24]=I):I=e[24];let q;e[25]!==R||e[26]!==I?(q=t.jsxs(Q,{children:[R,I]}),e[25]=R,e[26]=I,e[27]=q):q=e[27];const H=`${a}-root`;let z;e[28]!==H?(z=t.jsx(X,{htmlFor:H,children:"Publisher root file"}),e[28]=H,e[29]=z):z=e[29];const ee=`${a}-root`;let G;e[30]===Symbol.for("react.memo_cache_sentinel")?(G=Y=>{var B;h(((B=Y.target.files)==null?void 0:B[0])??null),p(!1)},e[30]=G):G=e[30];let F;e[31]!==r||e[32]!==ee?(F=t.jsx(de,{id:ee,type:"file",accept:".json,application/json",onChange:G,required:!0,disabled:r}),e[31]=r,e[32]=ee,e[33]=F):F=e[33];let K;e[34]!==z||e[35]!==F?(K=t.jsxs(Q,{children:[z,F]}),e[34]=z,e[35]=F,e[36]=K):K=e[36];const te=`${a}-fingerprint`;let _;e[37]!==te?(_=t.jsx(X,{htmlFor:te,children:"Verified SHA-256 fingerprint"}),e[37]=te,e[38]=_):_=e[38];const J=`${a}-fingerprint`;let L;e[39]===Symbol.for("react.memo_cache_sentinel")?(L=Y=>{j(Y.target.value),p(!1)},e[39]=L):L=e[39];let U;e[40]!==r||e[41]!==w||e[42]!==J?(U=t.jsx(de,{id:J,value:w,onChange:L,placeholder:"64 hexadecimal characters",pattern:"[a-fA-F0-9]{64}",required:!0,disabled:r}),e[40]=r,e[41]=w,e[42]=J,e[43]=U):U=e[43];let T;e[44]===Symbol.for("react.memo_cache_sentinel")?(T=t.jsx(Re,{children:"Get this fingerprint from the publisher through a source you trust."}),e[44]=T):T=e[44];let V;e[45]!==_||e[46]!==U?(V=t.jsxs(Q,{children:[_,U,T]}),e[45]=_,e[46]=U,e[47]=V):V=e[47];const f=`${a}-trust`;let $;e[48]!==r||e[49]!==f||e[50]!==c?($=t.jsx(Ie,{id:f,checked:c,onCheckedChange:p,disabled:r}),e[48]=r,e[49]=f,e[50]=c,e[51]=$):$=e[51];const W=`${a}-trust`;let M;e[52]!==W?(M=t.jsx(X,{htmlFor:W,children:"I verified the publisher and trust packages signed by this root."}),e[52]=W,e[53]=M):M=e[53];let Z;e[54]!==$||e[55]!==M?(Z=t.jsxs(Q,{orientation:"horizontal",children:[$,M]}),e[54]=$,e[55]=M,e[56]=Z):Z=e[56];const ae=r||!c||!y;let ie;e[57]!==ae?(ie=t.jsx(E,{type:"submit",disabled:ae,children:"Trust development publisher"}),e[57]=ae,e[58]=ie):ie=e[58];let le;e[59]!==q||e[60]!==K||e[61]!==V||e[62]!==Z||e[63]!==ie||e[64]!==N?(le=t.jsxs(Fe,{children:[N,q,K,V,Z,ie]}),e[59]=q,e[60]=K,e[61]=V,e[62]=Z,e[63]=ie,e[64]=N,e[65]=le):le=e[65];let oe;return e[66]!==m||e[67]!==le?(oe=t.jsx("form",{onSubmit:m,children:le}),e[66]=m,e[67]=le,e[68]=oe):oe=e[68],oe}function Et(l){return l.toString(16).padStart(2,"0")}const Pt={project:null,theme:{mode:"light",tokens:{}},locale:"en",reducedMotion:!0,visible:!1};function Tt({client:l,preview:e,activation:s,key:i,onFrame:r,onComplete:a,onError:n}){const d=new AbortController;let o="loading",v,y=0;const h=()=>new Error("The installation check expired. Review the package again to retry.");function w(m){o==="canceled"||o==="finished"||(o="canceled",clearTimeout(v),d.abort(),r(null),n(m))}function j(){o==="canceled"||o==="finished"||(o="finished",clearTimeout(v),a())}async function c(m){if(o==="committing"){o="recovering",clearTimeout(v);try{const x=await l.transactionOutcome(e);if(o!=="recovering")return;x.status==="committed"?(await l.refresh(),o==="recovering"&&j()):w(m)}catch{o==="recovering"&&w(new Error("The host did not confirm the installation result. Check Installed after reconnecting before trying again."))}}}async function p(){if(o==="trial"){if(Date.now()>y){w(h());return}o="committing";try{await l.commit(e,d.signal),o==="committing"&&j()}catch(m){await c(m instanceof Error?m:new Error("Plugin installation failed"))}}}return s&&(async()=>{try{const m=await l.payload(e.transactionId,d.signal);if(d.signal.aborted||(y=await l.beginTrial(e,d.signal),d.signal.aborted))return;const x=y-Date.now();if(x<=0){w(h());return}o="trial",v=setTimeout(()=>{o==="committing"?(d.abort(),c(h())):o==="trial"&&w(h())},x),r({key:i,client:l,props:{payload:m,digest:e.digest,activationKey:i,context:Pt,active:!1,title:"Plugin installation check",execute:async(g,b)=>{if(d.signal.throwIfAborted(),b.throwIfAborted(),g.method!=="lifecycle.ready")throw new Error("This action is unavailable during installation");return null},onReady:()=>{p()},onError:w}})}catch(m){w(m instanceof Error?m:new Error("Plugin trial failed"))}})(),()=>{o="canceled",clearTimeout(v),d.abort()}}function At(l){const e=ue.c(22),{client:s,preview:i,activation:r,onComplete:a,onError:n}=l,d=`${r}:trial:${i.transactionId}:${i.digest}:${i.registryRevision}`,[o,v]=C.useState(null);let y;e[0]!==a||e[1]!==n?(y={onComplete:a,onError:n},e[0]=a,e[1]=n,e[2]=y):y=e[2];const h=C.useRef(y);let w;e[3]!==a||e[4]!==n?(w=()=>{h.current={onComplete:a,onError:n}},e[3]=a,e[4]=n,e[5]=w):w=e[5],C.useLayoutEffect(w);let j,c;e[6]!==r||e[7]!==s||e[8]!==d||e[9]!==i?(j=()=>Tt({client:s,preview:i,activation:r,key:d,onFrame:v,onComplete:()=>h.current.onComplete(),onError:g=>h.current.onError(g)}),c=[s,i,r,d],e[6]=r,e[7]=s,e[8]=d,e[9]=i,e[10]=j,e[11]=c):(j=e[10],c=e[11]),C.useLayoutEffect(j,c);let p;e[12]!==i.manifest.name?(p=t.jsxs("p",{children:["Checking that ",i.manifest.name," starts correctly…"]}),e[12]=i.manifest.name,e[13]=p):p=e[13];let m;e[14]!==r||e[15]!==s||e[16]!==o||e[17]!==d?(m=r&&(o==null?void 0:o.key)===d&&o.client===s&&t.jsx(et,{...o.props}),e[14]=r,e[15]=s,e[16]=o,e[17]=d,e[18]=m):m=e[18];let x;return e[19]!==p||e[20]!==m?(x=t.jsxs("div",{role:"status",className:"flex flex-col gap-2",children:[p,m]}),e[19]=p,e[20]=m,e[21]=x):x=e[21],x}function Ot({connection:l,resourceId:e,target:s,client:i,disabled:r,save:a}){const n=C.useId(),d=l.definition.resources[e],o=l.selected[e],[v,y]=C.useState(""),[h,w]=C.useState(null),[j,c]=C.useState(!1),[p,m]=C.useState(null),x=C.useRef(null);C.useEffect(()=>()=>{var u;return(u=x.current)==null?void 0:u.abort()},[]);const g=tt(l.definition,e).find(u=>!l.selected[u]),b=r||!!g||d.scope==="project"&&!s.projectId;async function k(){var N;(N=x.current)==null||N.abort();const u=new AbortController;x.current=u,c(!0),m(null);try{const D=await i.connectionOptions(s,l.id,e,u.signal);u.signal.aborted||w(D)}catch(D){u.signal.aborted||m(D instanceof Error?D.message:"Unable to load choices")}finally{u.signal.aborted||c(!1)}}const S=o&&!(h!=null&&h.some(u=>u.id===o.id))?[o,...h??[]]:h??[];return t.jsxs(Q,{"data-disabled":b,"data-invalid":!!p,children:[t.jsx(X,{htmlFor:`${n}-resource`,children:d.label}),t.jsx(Re,{children:d.scope==="project"?"Applies to the selected project.":"Applies to all projects using this connection."}),o&&t.jsxs("p",{className:"text-sm",children:["Selected: ",o.label]}),g&&t.jsxs("p",{className:"text-sm text-muted-foreground",children:["Choose ",l.definition.resources[g].label," first."]}),d.scope==="project"&&!s.projectId&&t.jsx("p",{className:"text-sm text-muted-foreground",children:"Choose a Cogpit project above."}),d.options&&t.jsxs("div",{className:"flex flex-wrap gap-2",children:[t.jsx(E,{type:"button",variant:"outline",size:"sm",disabled:b||j,onClick:()=>{k()},children:j?"Loading choices…":h?"Refresh choices":"Browse choices"}),h&&t.jsxs(Ze,{items:S.map(u=>({value:u.id,label:u.label})),value:(o==null?void 0:o.id)??null,disabled:b||j,onValueChange:u=>{u&&u!==(o==null?void 0:o.id)&&a(l.id,"select",{resourceId:e,value:u})},children:[t.jsx(Ye,{id:`${n}-resource`,"aria-invalid":!!p,children:t.jsx(We,{placeholder:`Choose ${d.label}`})}),t.jsx(Ge,{children:t.jsx(Ke,{children:S.map(u=>t.jsx(Je,{value:u.id,children:u.label},u.id))})})]}),(h==null?void 0:h.length)===0&&t.jsx("p",{className:"text-sm text-muted-foreground",children:"No choices were returned."})]}),d.input&&t.jsxs("form",{className:"flex flex-wrap gap-2",onSubmit:u=>{u.preventDefault(),a(l.id,"select",{resourceId:e,value:v.trim()})},children:[t.jsx(de,{id:d.options?`${n}-input`:`${n}-resource`,"aria-label":`${d.label} ${d.input.urls?"URL or ID":"ID"}`,value:v,onChange:u=>y(u.target.value),maxLength:2048,disabled:b,autoComplete:"off",spellCheck:!1,placeholder:d.input.urls?"Paste a URL or ID":"Enter an ID"}),t.jsx(E,{type:"submit",size:"sm",variant:"outline",disabled:b||!v.trim(),children:"Validate and select"})]}),o&&t.jsxs(E,{type:"button",size:"sm",variant:"ghost",disabled:b,onClick:()=>{a(l.id,"select",{resourceId:e,value:null})},children:["Clear ",d.label]}),p&&t.jsx("p",{role:"alert",className:"text-sm text-destructive",children:p})]})}function Ft(l){const e=ue.c(45),{connection:s,target:i,client:r,disabled:a,save:n}=l,d=C.useId(),[o,v]=C.useState(""),[y,h]=C.useState(!1),w=s.label;let j;e[0]!==s.label?(j=t.jsx("h3",{className:"font-medium",children:s.label}),e[0]=s.label,e[1]=j):j=e[1];const c=s.status==="disconnected"?"Needs connection":s.readOnly?"Configured by host":"Connected";let p;e[2]!==c?(p=t.jsx($e,{variant:"outline",children:c}),e[2]=c,e[3]=p):p=e[3];let m;e[4]!==j||e[5]!==p?(m=t.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[j,p]}),e[4]=j,e[5]=p,e[6]=m):m=e[6];let x;e[7]===Symbol.for("react.memo_cache_sentinel")?(x=t.jsx("p",{className:"text-sm text-muted-foreground",children:"Cogpit keeps this credential on the selected host. Plugin code cannot read it."}),e[7]=x):x=e[7];let g;e[8]!==s.definition.operations?(g=new Set(Object.values(s.definition.operations).map(_t)),e[8]=s.definition.operations,e[9]=g):g=e[9];let b;e[10]!==g?(b=[...g],e[10]=g,e[11]=b):b=e[11];const k=b.join(", ");let S;e[12]!==k?(S=t.jsxs("p",{className:"break-all text-xs text-muted-foreground",children:["Credential destinations: ",k]}),e[12]=k,e[13]=S):S=e[13];let u;e[14]!==s.id||e[15]!==s.legacyImportAvailable||e[16]!==s.readOnly||e[17]!==s.status||e[18]!==a||e[19]!==d||e[20]!==y||e[21]!==n?(u=s.legacyImportAvailable&&t.jsxs("div",{className:"flex flex-col gap-3 rounded-md bg-muted p-3",children:[t.jsx("p",{className:"text-sm",children:"An existing host connection has saved settings available to import."}),s.status==="connected"&&!s.readOnly&&t.jsxs(Q,{orientation:"horizontal",children:[t.jsx(Ie,{id:`${d}-replace`,checked:y,onCheckedChange:h,disabled:a}),t.jsx(X,{htmlFor:`${d}-replace`,children:"Allow replacing my current connection with these saved settings"})]}),t.jsx(E,{type:"button",size:"sm",variant:"outline",disabled:a,onClick:()=>{n(s.id,"import-legacy",{replaceExisting:y})},children:"Import saved host settings"})]}),e[14]=s.id,e[15]=s.legacyImportAvailable,e[16]=s.readOnly,e[17]=s.status,e[18]=a,e[19]=d,e[20]=y,e[21]=n,e[22]=u):u=e[22];let N;e[23]!==s.definition.secret||e[24]!==s.id||e[25]!==s.readOnly||e[26]!==s.status||e[27]!==a||e[28]!==d||e[29]!==n||e[30]!==o?(N=s.readOnly?t.jsx("p",{className:"text-sm",children:"The host environment supplies this credential. Change it on the host."}):t.jsx("form",{onSubmit:A=>{A.preventDefault();const O=o.trim();v(""),n(s.id,"credential",{secret:O})},children:t.jsxs(Fe,{children:[t.jsxs(Q,{"data-disabled":a,children:[t.jsx(X,{htmlFor:`${d}-secret`,children:s.definition.secret.label}),t.jsx(de,{id:`${d}-secret`,type:"password",autoComplete:"off",spellCheck:!1,maxLength:4096,disabled:a,value:o,onChange:A=>v(A.target.value)})]}),t.jsxs("div",{className:"flex flex-wrap gap-2",children:[t.jsx(E,{type:"submit",size:"sm",disabled:a||!o.trim(),children:s.status==="disconnected"?"Validate and connect":"Replace credential"}),s.status!=="disconnected"&&t.jsx(E,{type:"button",size:"sm",variant:"outline",disabled:a,onClick:()=>{n(s.id,"disconnect",{})},children:"Disconnect"})]})]})}),e[23]=s.definition.secret,e[24]=s.id,e[25]=s.readOnly,e[26]=s.status,e[27]=a,e[28]=d,e[29]=n,e[30]=o,e[31]=N):N=e[31];let D;e[32]!==r||e[33]!==s||e[34]!==a||e[35]!==n||e[36]!==i?(D=s.status!=="disconnected"&&t.jsx(Fe,{children:Object.keys(s.definition.resources).map(A=>t.jsx(Ot,{connection:s,resourceId:A,target:i,client:r,disabled:a,save:n},A))}),e[32]=r,e[33]=s,e[34]=a,e[35]=n,e[36]=i,e[37]=D):D=e[37];let R;return e[38]!==s.label||e[39]!==S||e[40]!==u||e[41]!==N||e[42]!==D||e[43]!==m?(R=t.jsxs("section",{className:"flex flex-col gap-4 rounded-lg border p-4","aria-label":w,children:[m,x,S,u,N,D]}),e[38]=s.label,e[39]=S,e[40]=u,e[41]=N,e[42]=D,e[43]=m,e[44]=R):R=e[44],R}function _t(l){return l.origin}function zt({client:l,target:e}){const[s,i]=C.useState(null),[r,a]=C.useState(null),[n,d]=C.useState(!1),o=C.useRef(null),v=C.useRef(!1),y=e.pluginId,h=e.projectId;C.useEffect(()=>{const j=new AbortController;return o.current=j,l.connections({pluginId:y,projectId:h},j.signal).then(c=>{j.signal.aborted||i(c)}).catch(c=>{j.signal.aborted||a(c instanceof Error?c.message:"Unable to load connections")}),()=>{j.abort(),o.current=null}},[l,y,h]);async function w(j,c,p){if(!s||v.current||!o.current||o.current.signal.aborted)return;v.current=!0;const m=o.current.signal;d(!0),a(null);try{const x=await l.changeConnection(e,j,c,p,s.revision,m);m.aborted||i(x)}catch(x){m.aborted||a(x instanceof Error?x.message:"Connection change failed")}finally{v.current=!1,m.aborted||d(!1)}}return t.jsxs("div",{className:"flex flex-col gap-4",children:[r&&t.jsx(se,{variant:"destructive",children:t.jsx(ne,{children:r})}),!s&&!r&&t.jsx("p",{role:"status",className:"text-sm text-muted-foreground",children:"Loading connections…"}),s==null?void 0:s.connections.map(j=>t.jsx(Ft,{connection:j,target:e,client:l,disabled:n,save:w},`${j.id}:${s.revision}`)),(s==null?void 0:s.connections.length)===0&&t.jsx("p",{className:"text-sm text-muted-foreground",children:"This plugin does not use provider connections."})]})}function Lt(l){const e=ue.c(32),{client:s,status:i,pluginId:r,initialProjectId:a}=l,[n,d]=C.useState(a),o=C.useId();let v;e[0]===Symbol.for("react.memo_cache_sentinel")?(v={value:"",label:"Host connections only"},e[0]=v):v=e[0];let y;e[1]!==i.projects?(y=[v,...i.projects.map(qt)],e[1]=i.projects,e[2]=y):y=e[2];const h=y;let w;e[3]!==o?(w=t.jsx(X,{htmlFor:o,children:"Project settings"}),e[3]=o,e[4]=w):w=e[4];const j=n??"";let c;e[5]===Symbol.for("react.memo_cache_sentinel")?(c=R=>d(R||null),e[5]=c):c=e[5];let p;e[6]===Symbol.for("react.memo_cache_sentinel")?(p=t.jsx(We,{}),e[6]=p):p=e[6];let m;e[7]!==o?(m=t.jsx(Ye,{id:o,children:p}),e[7]=o,e[8]=m):m=e[8];let x;e[9]!==h?(x=t.jsx(Ge,{children:t.jsx(Ke,{children:h.map(Vt)})}),e[9]=h,e[10]=x):x=e[10];let g;e[11]!==h||e[12]!==j||e[13]!==m||e[14]!==x?(g=t.jsxs(Ze,{items:h,value:j,onValueChange:c,children:[m,x]}),e[11]=h,e[12]=j,e[13]=m,e[14]=x,e[15]=g):g=e[15];let b;e[16]!==i.host.name?(b=t.jsxs(Re,{children:["Connection credentials belong to ",i.host.name,". Project resources stay within the project you choose."]}),e[16]=i.host.name,e[17]=b):b=e[17];let k;e[18]!==b||e[19]!==w||e[20]!==g?(k=t.jsxs(Q,{children:[w,g,b]}),e[18]=b,e[19]=w,e[20]=g,e[21]=k):k=e[21];const S=`${r}:${n??"host"}:${i.connectionRevision??0}`;let u;e[22]!==r||e[23]!==n?(u={pluginId:r,projectId:n},e[22]=r,e[23]=n,e[24]=u):u=e[24];let N;e[25]!==s||e[26]!==S||e[27]!==u?(N=t.jsx(zt,{client:s,target:u},S),e[25]=s,e[26]=S,e[27]=u,e[28]=N):N=e[28];let D;return e[29]!==k||e[30]!==N?(D=t.jsxs("div",{className:"flex flex-col gap-4",children:[k,N]}),e[29]=k,e[30]=N,e[31]=D):D=e[31],D}function Vt(l){return t.jsx(Je,{value:l.value,children:l.label},l.value)}function qt(l){return{value:l.id,label:l.name}}function Ut(l){var ie;const e=ue.c(174),{plugin:s,status:i,client:r,busy:a,run:n,onPreview:d,onConnections:o,onUpdate:v}=l,y=C.useId(),[h,w]=C.useState(s.scope),[j,c]=C.useState(!1),[p,m]=C.useState(!1);let x,g,b,k,S,u,N,D,R,A,O,I;if(e[0]!==a||e[1]!==r||e[2]!==o||e[3]!==d||e[4]!==v||e[5]!==s||e[6]!==n||e[7]!==h||e[8]!==i.host.name||e[9]!==i.projects||e[10]!==i.runtime||e[11]!==i.store){const le=st(),oe=Me(s.manifest,le,i.runtime,{allowPrerelease:s.manifest.publisher.startsWith("dev-")});let Y;e[24]!==r||e[25]!==s.id||e[26]!==n||e[27]!==i.store?(Y=(P,Te)=>n(()=>r.changeInstalled(s.id,P,Te,i.store.revision)),e[24]=r,e[25]=s.id,e[26]=n,e[27]=i.store,e[28]=Y):Y=e[28];const B=Y,re=s.lastError?"Needs recovery":oe.compatible?s.enabled?"Enabled":"Disabled":"Incompatible";let ce;e[29]!==s.id||e[30]!==s.lastError||e[31]!==s.selectedDigest||e[32]!==i.store?(ce=s.lastError&&((ie=i.store.availableSeeds)==null?void 0:ie.find(P=>P.manifest.id===s.id&&P.digest===s.selectedDigest)),e[29]=s.id,e[30]=s.lastError,e[31]=s.selectedDigest,e[32]=i.store,e[33]=ce):ce=e[33];const _e=ce;A="flex flex-col gap-3 rounded-lg border p-4";let fe;e[34]!==s.manifest.name?(fe=t.jsx("h3",{className:"font-medium",children:s.manifest.name}),e[34]=s.manifest.name,e[35]=fe):fe=e[35];let he;e[36]!==s.id||e[37]!==s.manifest.version?(he=t.jsxs("p",{className:"break-all text-xs text-muted-foreground",children:[s.id," · ",s.manifest.version]}),e[36]=s.id,e[37]=s.manifest.version,e[38]=he):he=e[38];let me;e[39]!==fe||e[40]!==he?(me=t.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[fe,he]}),e[39]=fe,e[40]=he,e[41]=me):me=e[41];const ze=re==="Enabled"?"secondary":"outline";let pe;e[42]!==re||e[43]!==ze?(pe=t.jsx($e,{variant:ze,children:re}),e[42]=re,e[43]=ze,e[44]=pe):pe=e[44],e[45]!==me||e[46]!==pe?(O=t.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-2",children:[me,pe]}),e[45]=me,e[46]=pe,e[47]=O):O=e[47],e[48]!==s.lastError?(I=s.lastError&&t.jsx(se,{variant:"destructive",children:t.jsx(ne,{children:s.lastError})}),e[48]=s.lastError,e[49]=I):I=e[49],g=!oe.compatible&&t.jsx(se,{variant:"destructive",children:t.jsxs(ne,{children:[oe.issues.map(P=>t.jsxs("p",{children:[P.side==="client"?"This client":P.side==="host"?i.host.name:"This package",": ",P.name," requires ",P.required,"; available ",P.actual??"none","."]},`${P.side}:${P.code}:${P.name}`)),t.jsx("p",{children:"Keep the saved data and update the affected app, or choose a compatible retained version below."})]})});let xe;e[50]!==B||e[51]!==s.enabled?(xe=()=>B("enabled",{enabled:!s.enabled}),e[50]=B,e[51]=s.enabled,e[52]=xe):xe=e[52];const Le=s.enabled?"Disable":"Enable";let ge;e[53]!==a||e[54]!==xe||e[55]!==Le?(ge=t.jsx(E,{size:"sm",variant:"outline",disabled:a,onClick:xe,children:Le}),e[53]=a,e[54]=xe,e[55]=Le,e[56]=ge):ge=e[56];let je;e[57]!==a||e[58]!==o||e[59]!==s.id||e[60]!==s.manifest.permissions.connections.length?(je=s.manifest.permissions.connections.length>0&&t.jsx(E,{size:"sm",variant:"outline",disabled:a,onClick:()=>o(s.id),children:"Connections"}),e[57]=a,e[58]=o,e[59]=s.id,e[60]=s.manifest.permissions.connections.length,e[61]=je):je=e[61];const Ve=a||s.pinned;let be;e[62]!==v||e[63]!==s?(be=()=>v(s),e[62]=v,e[63]=s,e[64]=be):be=e[64];let ve;e[65]!==Ve||e[66]!==be?(ve=t.jsx(E,{size:"sm",variant:"outline",disabled:Ve,onClick:be,children:"Update from file"}),e[65]=Ve,e[66]=be,e[67]=ve):ve=e[67];let ye;e[68]!==a||e[69]!==r||e[70]!==d||e[71]!==s.id||e[72]!==s.scope||e[73]!==_e||e[74]!==n?(ye=_e&&t.jsx(E,{size:"sm",variant:"outline",disabled:a,onClick:()=>n(async()=>d(await r.stageSeed(s.id,s.scope))),children:"Review bundled repair"}),e[68]=a,e[69]=r,e[70]=d,e[71]=s.id,e[72]=s.scope,e[73]=_e,e[74]=n,e[75]=ye):ye=e[75];let Ce;e[76]!==B||e[77]!==s.pinned?(Ce=()=>B("pin",{pinned:!s.pinned}),e[76]=B,e[77]=s.pinned,e[78]=Ce):Ce=e[78];const qe=s.pinned?"Unpin version":"Pin version";let we;e[79]!==a||e[80]!==Ce||e[81]!==qe?(we=t.jsx(E,{size:"sm",variant:"outline",disabled:a,onClick:Ce,children:qe}),e[79]=a,e[80]=Ce,e[81]=qe,e[82]=we):we=e[82];let Ee;e[83]===Symbol.for("react.memo_cache_sentinel")?(Ee=()=>{m(!1),c(!0)},e[83]=Ee):Ee=e[83];let Ne;e[84]!==a?(Ne=t.jsx(E,{size:"sm",variant:"ghost",disabled:a,onClick:Ee,children:"Uninstall"}),e[84]=a,e[85]=Ne):Ne=e[85],e[86]!==ge||e[87]!==je||e[88]!==ve||e[89]!==ye||e[90]!==we||e[91]!==Ne?(b=t.jsxs("div",{className:"flex flex-wrap gap-2",children:[ge,je,ve,ye,we,Ne]}),e[86]=ge,e[87]=je,e[88]=ve,e[89]=ye,e[90]=we,e[91]=Ne,e[92]=b):b=e[92],e[93]!==s.pinned?(k=s.pinned&&t.jsx("p",{className:"text-xs text-muted-foreground",children:"Unpin this version before updating or rolling back. Revoked packages remain blocked."}),e[93]=s.pinned,e[94]=k):k=e[94],D="text-sm",e[95]===Symbol.for("react.memo_cache_sentinel")?(R=t.jsx("summary",{className:"cursor-pointer",children:"Projects and previous versions"}),e[95]=R):R=e[95],x="flex flex-col gap-4 pt-4",e[96]!==a||e[97]!==h||e[98]!==i.projects?(S=t.jsx(Ue,{value:h,onChange:w,projects:i.projects,disabled:a}),e[96]=a,e[97]=h,e[98]=i.projects,e[99]=S):S=e[99];let Se;e[100]!==a||e[101]!==s.scope||e[102]!==h?(Se=a||JSON.stringify(h)===JSON.stringify(s.scope),e[100]=a,e[101]=s.scope,e[102]=h,e[103]=Se):Se=e[103];let ke;e[104]!==B||e[105]!==h?(ke=()=>B("scope",{scope:h}),e[104]=B,e[105]=h,e[106]=ke):ke=e[106],e[107]!==i.host.name||e[108]!==Se||e[109]!==ke?(u=t.jsxs(E,{size:"sm",variant:"outline",disabled:Se,onClick:ke,children:["Save projects on ",i.host.name]}),e[107]=i.host.name,e[108]=Se,e[109]=ke,e[110]=u):u=e[110];let Pe;e[111]!==s.selectedDigest?(Pe=P=>P.digest!==s.selectedDigest,e[111]=s.selectedDigest,e[112]=Pe):Pe=e[112],N=s.versions.filter(Pe).map(P=>{const Te=!P.unavailableReason&&Me(P.manifest,le,i.runtime,{allowPrerelease:P.manifest.publisher.startsWith("dev-")}).compatible;return t.jsxs("div",{className:"flex flex-col gap-1",children:[t.jsxs(E,{size:"sm",variant:"outline",disabled:a||s.pinned||!Te,onClick:()=>n(async()=>d({...await r.rollback(s.id,P.digest,s.scope),operation:"rollback"})),children:["Review rollback to ",P.manifest.version]}),!Te&&t.jsx("p",{className:"text-xs text-muted-foreground",children:P.unavailableReason??"This version is incompatible with the connected host or client."})]},P.digest)}),e[0]=a,e[1]=r,e[2]=o,e[3]=d,e[4]=v,e[5]=s,e[6]=n,e[7]=h,e[8]=i.host.name,e[9]=i.projects,e[10]=i.runtime,e[11]=i.store,e[12]=x,e[13]=g,e[14]=b,e[15]=k,e[16]=S,e[17]=u,e[18]=N,e[19]=D,e[20]=R,e[21]=A,e[22]=O,e[23]=I}else x=e[12],g=e[13],b=e[14],k=e[15],S=e[16],u=e[17],N=e[18],D=e[19],R=e[20],A=e[21],O=e[22],I=e[23];let q;e[113]===Symbol.for("react.memo_cache_sentinel")?(q=t.jsx("p",{className:"text-xs text-muted-foreground",children:"Rollback keeps current settings. Disabling keeps the installation and its saved data."}),e[113]=q):q=e[113];let H;e[114]!==x||e[115]!==S||e[116]!==u||e[117]!==N?(H=t.jsxs("div",{className:x,children:[S,u,N,q]}),e[114]=x,e[115]=S,e[116]=u,e[117]=N,e[118]=H):H=e[118];let z;e[119]!==H||e[120]!==D||e[121]!==R?(z=t.jsxs("details",{className:D,children:[R,H]}),e[119]=H,e[120]=D,e[121]=R,e[122]=z):z=e[122];let ee;e[123]!==s.manifest.name?(ee=t.jsxs(nt,{children:["Uninstall ",s.manifest.name,"?"]}),e[123]=s.manifest.name,e[124]=ee):ee=e[124];let G;e[125]!==i.host.name?(G=t.jsxs(it,{children:["This removes the plugin from ",i.host.name," for every connected client and project. Saved data is retained unless you choose deletion."]}),e[125]=i.host.name,e[126]=G):G=e[126];let F;e[127]!==ee||e[128]!==G?(F=t.jsxs(at,{children:[ee,G]}),e[127]=ee,e[128]=G,e[129]=F):F=e[129];const K=`${y}-delete`,te=a||i.connectionRevision===void 0;let _;e[130]!==p||e[131]!==K||e[132]!==te?(_=t.jsx(Ie,{id:K,checked:p,onCheckedChange:m,disabled:te}),e[130]=p,e[131]=K,e[132]=te,e[133]=_):_=e[133];const J=`${y}-delete`;let L;e[134]!==J?(L=t.jsx(X,{htmlFor:J,children:"Delete my saved settings and connections on this host"}),e[134]=J,e[135]=L):L=e[135];let U;e[136]!==_||e[137]!==L?(U=t.jsxs(Q,{orientation:"horizontal",children:[_,L]}),e[136]=_,e[137]=L,e[138]=U):U=e[138];let T;e[139]!==p?(T=p&&t.jsx("p",{className:"text-sm text-muted-foreground",children:"This cannot be undone. Other administrators' saved data is retained. Provider tokens and legacy backup files are not removed."}),e[139]=p,e[140]=T):T=e[140];let V;e[141]!==a?(V=t.jsx(ot,{disabled:a,children:"Cancel"}),e[141]=a,e[142]=V):V=e[142];let f;e[143]!==r||e[144]!==p||e[145]!==s.id||e[146]!==n||e[147]!==i.connectionRevision||e[148]!==i.store?(f=()=>{c(!1),n(()=>r.changeInstalled(s.id,"uninstall",p?{deleteData:!0,expectedConnectionRevision:i.connectionRevision}:{deleteData:!1},i.store.revision))},e[143]=r,e[144]=p,e[145]=s.id,e[146]=n,e[147]=i.connectionRevision,e[148]=i.store,e[149]=f):f=e[149];let $;e[150]!==a||e[151]!==i.host.name||e[152]!==f?($=t.jsxs(lt,{variant:"destructive",disabled:a,onClick:f,children:["Uninstall from ",i.host.name]}),e[150]=a,e[151]=i.host.name,e[152]=f,e[153]=$):$=e[153];let W;e[154]!==V||e[155]!==$?(W=t.jsxs(rt,{children:[V,$]}),e[154]=V,e[155]=$,e[156]=W):W=e[156];let M;e[157]!==F||e[158]!==U||e[159]!==T||e[160]!==W?(M=t.jsxs(ct,{children:[F,U,T,W]}),e[157]=F,e[158]=U,e[159]=T,e[160]=W,e[161]=M):M=e[161];let Z;e[162]!==j||e[163]!==M?(Z=t.jsx(dt,{open:j,onOpenChange:c,children:M}),e[162]=j,e[163]=M,e[164]=Z):Z=e[164];let ae;return e[165]!==g||e[166]!==b||e[167]!==k||e[168]!==z||e[169]!==Z||e[170]!==A||e[171]!==O||e[172]!==I?(ae=t.jsxs("article",{className:A,children:[O,I,g,b,k,z,Z]}),e[165]=g,e[166]=b,e[167]=k,e[168]=z,e[169]=Z,e[170]=A,e[171]=O,e[172]=I,e[173]=ae):ae=e[173],ae}const Mt={github:"GitHub",vercel:"Vercel",cloudflare:"Cloudflare"},Bt={actions:"workflow runs",actionJobs:"workflow jobs and steps",pulls:"pull requests",pullFiles:"pull request files",issues:"issues",deployments:"deployments",buildLogs:"build logs",workspace:"Worker configuration and account",version:"version details"};function Ht(l,e){return e==="pullSessions"?"Read related Cogpit sessions for the selected GitHub repository":e==="mergePull"?"Merge pull requests in the selected GitHub repository when you confirm, using this host's signed-in CLI":`Read ${Mt[l]} ${Bt[e]} using this host's signed-in CLI`}function He(l){const e=l.permissions;return[...e.context.map(s=>s==="session.identity"?"Recognise the open session among related sessions, by handle only":"Read the selected project's name and plugin identifier"),...e.composer.map(()=>"Append text to your draft message"),...e.navigation.map(s=>s==="external"?"Ask Cogpit to open HTTPS links":"Open permitted sessions"),...e.storage?[`Store up to ${e.storage.quotaKiB} KiB of ${e.storage.scope} settings`]:[],...e.connections.flatMap(s=>s.operations.map(i=>`Use connection ${s.id}: ${i}`)),...e.integrations.flatMap(s=>s.operations.map(i=>Ht(s.id,i)))]}function Gt(l){var j;const e=ue.c(32),{preview:s}=l;let i,r,a,n,d,o;if(e[0]!==s.connectionDefinitions||e[1]!==s.manifest||e[2]!==s.oldVersion||e[3]!==s.operation||e[4]!==s.previousConnectionDefinitions||e[5]!==s.previousManifest){const c=He(s.manifest),p=s.previousManifest?He(s.previousManifest):null,m=p?c.filter(b=>!p.includes(b)):[],x=p?p.filter(b=>!c.includes(b)):[],g=s.previousConnectionDefinitions?s.connectionDefinitions.filter(b=>{var S;const k=(S=s.previousConnectionDefinitions)==null?void 0:S.find(u=>u.id===b.id);return!k||JSON.stringify(k)!==JSON.stringify(b)}):[];i="flex flex-col gap-3 text-sm",e[12]!==s.oldVersion||e[13]!==s.operation?(r=s.oldVersion&&t.jsxs(se,{children:[t.jsx(De,{children:s.operation==="rollback"?"Rollback keeps current settings":"Update on this host"}),t.jsxs(ne,{children:["Saved settings and connections are retained. This version replaces ",s.oldVersion," in every enabled project and connected client. A failed trial leaves the current version selected."]})]}),e[12]=s.oldVersion,e[13]=s.operation,e[14]=r):r=e[14],a=p&&t.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsx("h3",{className:"font-medium",children:"Access changes"}),m.length===0&&x.length===0&&g.length===0&&t.jsx("p",{children:"No changes to requested access or connection definitions."}),m.map(Xt),x.map(Qt),g.map(Zt)]}),n=s.oldVersion&&!p&&t.jsx(se,{children:t.jsx(ne,{children:"This host does not report previous permissions. Review all requested access before continuing."})}),e[15]===Symbol.for("react.memo_cache_sentinel")?(d=t.jsx("h3",{className:"font-medium",children:"Requested access"}),e[15]=d):d=e[15],o=c.length?t.jsx("ul",{className:"ml-4 flex list-disc flex-col gap-1",children:c.map(Yt)}):t.jsx("p",{className:"text-muted-foreground",children:"No project, connection, storage, or composer access requested."}),e[0]=s.connectionDefinitions,e[1]=s.manifest,e[2]=s.oldVersion,e[3]=s.operation,e[4]=s.previousConnectionDefinitions,e[5]=s.previousManifest,e[6]=i,e[7]=r,e[8]=a,e[9]=n,e[10]=d,e[11]=o}else i=e[6],r=e[7],a=e[8],n=e[9],d=e[10],o=e[11];let v;e[16]!==s.connectionDefinitions?(v=s.connectionDefinitions.map(Kt),e[16]=s.connectionDefinitions,e[17]=v):v=e[17];let y;e[18]!==s.incompatibleClients?(y=!!((j=s.incompatibleClients)!=null&&j.length)&&t.jsxs(se,{children:[t.jsx(De,{children:"Some connected clients cannot run this version"}),t.jsxs(ne,{children:[s.incompatibleClients.join(", "),". Their plugin panels will be unavailable until those clients are updated. Offline clients are checked when they reconnect."]})]}),e[18]=s.incompatibleClients,e[19]=y):y=e[19];let h;e[20]!==s.digest?(h=t.jsxs("p",{className:"break-all text-xs text-muted-foreground",children:["SHA-256: ",s.digest]}),e[20]=s.digest,e[21]=h):h=e[21];let w;return e[22]!==i||e[23]!==r||e[24]!==a||e[25]!==n||e[26]!==d||e[27]!==o||e[28]!==v||e[29]!==y||e[30]!==h?(w=t.jsxs("div",{className:i,children:[r,a,n,d,o,v,y,h]}),e[22]=i,e[23]=r,e[24]=a,e[25]=n,e[26]=d,e[27]=o,e[28]=v,e[29]=y,e[30]=h,e[31]=w):w=e[31],w}function Kt(l){return t.jsxs("div",{className:"flex flex-col gap-1",children:[t.jsx("p",{className:"font-medium",children:l.label}),t.jsxs("p",{children:["Access to ",Object.values(l.resources).map(Wt).join(", ")||"the connected account","."]}),t.jsxs("p",{className:"break-all text-muted-foreground",children:["Credential destinations: ",[...new Set(Object.values(l.operations).map(Jt))].join(", ")]})]},l.id)}function Jt(l){return l.origin}function Wt(l){return l.label}function Yt(l){return t.jsx("li",{children:l},l)}function Zt(l){return t.jsxs("p",{children:["Changed connection: ",l.label,". Review its destinations and access below."]},l.id)}function Qt(l){return t.jsxs("p",{children:["Removed: ",l]},`remove:${l}`)}function Xt(l){return t.jsxs("p",{children:["Added: ",l]},`add:${l}`)}function ls({client:l,state:e,currentPath:s,onClose:i,initialPluginId:r}){var V;const a=C.useId(),n=e.status,d=ut(),o=(n==null?void 0:n.safeMode)||d,{project:v,resolving:y}=ft({client:l,status:n,activation:e.activation,projectPath:s}),[h,w]=C.useState(null),j=h??{type:"projects",projectIds:v?[v.id]:[]},[c,p]=C.useState(null),[m,x]=C.useState({activation:"",hostName:""}),[g,b]=C.useState(!1),[k,S]=C.useState(!1),[u,N]=C.useState(null),[D,R]=C.useState(null),[A,O]=C.useState("installed"),[I,q]=C.useState(null),[H,z]=C.useState(null),[ee,G]=C.useState(r),F=n==null?void 0:n.store.plugins.find(f=>f.id===ee),K=C.useRef(!1),te=!!(n!=null&&n.store.available)&&m.activation===e.activation;function _(f){x({activation:e.activation,hostName:(n==null?void 0:n.host.name)??"the selected host"}),p(f)}C.useEffect(()=>{!c||te&&!(o&&g)||(b(!1),p(null),N("The host connection or plugin execution state changed. Review the package again before installing."),l.cancel(c).catch(()=>{}))},[l,c,te,o,g]),C.useEffect(()=>()=>{c&&l.cancel(c).catch(()=>{})},[l,c]);async function J(f){if(!K.current){K.current=!0,S(!0),N(null),R(null);try{await f()}catch($){N($ instanceof Error?$.message:"Plugin action failed")}finally{K.current=!1,S(!1)}}}function L(){const f=c;b(!1),p(null),f&&l.cancel(f).catch(()=>{})}async function U(){if(!H||!I&&!h&&y)return;const f=await l.stage(H,(I==null?void 0:I.scope)??j);if(I&&f.manifest.id!==I.id)throw await l.cancel(f),new Error(`Choose a package for ${I.manifest.name} (${I.id}).`);_(f)}const T=k||g||!(n!=null&&n.store.available);return t.jsx(ht,{open:!0,onOpenChange:f=>{!f&&!k&&!g&&(L(),i())},children:t.jsxs(mt,{className:"flex max-h-[85dvh] flex-col sm:max-w-2xl",showCloseButton:!k&&!g,children:[t.jsxs(pt,{children:[t.jsx(xt,{children:"Plugins"}),t.jsx(gt,{children:n?`Installed on ${n.host.name}. Changes apply to every client connected to this host.`:"Connecting to the selected host…"})]}),t.jsxs("div",{className:"flex min-h-0 flex-col gap-4 overflow-y-auto",children:[(e.error||u||(n==null?void 0:n.store.error))&&t.jsxs(se,{variant:"destructive",children:[t.jsx(De,{children:n!=null&&n.store.available&&!u&&!e.error?"Plugin setup needs attention":"Plugin action unavailable"}),t.jsx(ne,{children:u??e.error??(n==null?void 0:n.store.error)})]}),D&&t.jsx(se,{children:t.jsx(ne,{children:D})}),o&&t.jsxs(se,{children:[t.jsx(De,{children:"Plugin safe mode"}),t.jsxs(ne,{children:["Plugin panels are stopped. You can disable or uninstall plugins here.",(n==null?void 0:n.safeMode)&&" The host owner must restart Cogpit without COGPIT_DISABLE_PLUGINS=1 to resume plugins on this host."]})]}),t.jsx(E,{size:"sm",variant:"outline",disabled:k||g||(n==null?void 0:n.safeMode),onClick:()=>jt(!d),children:d?"Resume plugins in this browser":"Pause plugins in this browser"}),(n==null?void 0:n.store.recoveryCode)&&t.jsx("p",{className:"text-sm text-muted-foreground",children:n.store.recoveryCode==="STORE_LOCKED"?"Close the other Cogpit process using this data directory, then restart this host.":n.store.recoveryCode==="STORE_VERSION"?"Open this host with the Cogpit version that last used its plugin store, or a newer compatible version.":"Keep the plugin data directory intact. Restart with plugin safe mode enabled and check the host log before restoring a verified backup."}),!n&&t.jsxs(E,{variant:"outline",disabled:k,onClick:()=>{J(()=>l.refresh())},children:[t.jsx(kt,{"data-icon":"inline-start"}),"Retry connection"]}),n&&F&&!c&&t.jsxs("div",{className:"flex flex-col gap-4",children:[t.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[t.jsxs("h2",{className:"font-medium",children:[F.manifest.name," connections"]}),t.jsx(E,{variant:"outline",size:"sm",onClick:()=>G(void 0),children:"Back to installed"})]}),t.jsx(Lt,{client:l,status:n,pluginId:F.id,initialProjectId:(v==null?void 0:v.id)??null},`${F.id}:${n.store.revision}`)]}),n&&!F&&!c&&t.jsxs(bt,{value:A,onValueChange:f=>{O(String(f)),q(null),z(null)},children:[t.jsxs(vt,{className:"h-auto flex-wrap",children:[t.jsx(Ae,{value:"installed",children:"Installed"}),t.jsx(Ae,{value:"browse",children:"Browse"}),t.jsx(Ae,{value:"install",children:"Install from file"}),t.jsx(Ae,{value:"publishers",children:"Publishers"})]}),t.jsx(Oe,{value:"installed",children:t.jsx("div",{className:"flex flex-col gap-3 pt-4",children:n.store.plugins.length?n.store.plugins.map(f=>t.jsx(Ut,{plugin:f,status:n,client:l,busy:T,run:$=>{J($)},onPreview:_,onConnections:G,onUpdate:$=>{q($),z(null),O("install")}},`${f.id}:${n.store.revision}`)):t.jsx(yt,{children:t.jsxs(Ct,{children:[t.jsx(wt,{variant:"icon",children:t.jsx($t,{})}),t.jsx(Nt,{children:"No installed plugins"}),t.jsx(St,{children:"Browse available plugins or install a signed package to add panels to this host."})]})})})}),t.jsx(Oe,{value:"browse",children:t.jsxs("div",{className:"flex flex-col gap-4 pt-4",children:[t.jsxs("p",{className:"text-sm text-muted-foreground",children:["These optional plugins are available with this Cogpit release. Choose which ones to install on ",n.host.name,"."]}),t.jsx(Ue,{value:j,onChange:w,projects:n.projects,disabled:T}),(n.store.availableSeeds??[]).map(f=>{const $=n.store.plugins.find(M=>M.id===f.manifest.id),W=$&&It(f.manifest.version,$.manifest.version)===1;return t.jsxs("article",{className:"flex flex-wrap items-center justify-between gap-3 rounded-lg border p-4",children:[t.jsxs("div",{children:[t.jsx("h3",{className:"font-medium",children:f.manifest.name}),t.jsxs("p",{className:"text-xs text-muted-foreground",children:[f.manifest.version," · ",f.manifest.publisher]})]}),W?t.jsx(E,{size:"sm",disabled:T||$.pinned,onClick:()=>{J(async()=>_(await l.stageSeed(f.manifest.id,$.scope)))},children:$.pinned?"Pinned to installed version":"Review update"}):$?t.jsx($e,{variant:"outline",children:"Installed"}):t.jsx(E,{size:"sm",disabled:T||!h&&y,onClick:()=>{J(async()=>_(await l.stageSeed(f.manifest.id,j)))},children:"Review installation"})]},f.manifest.id)}),!((V=n.store.availableSeeds)!=null&&V.length)&&t.jsx("p",{className:"text-sm text-muted-foreground",children:"This host has no bundled plugin packages. You can install a signed package from a file."})]})}),t.jsx(Oe,{value:"install",children:t.jsx("form",{className:"pt-4",onSubmit:f=>{f.preventDefault(),J(U)},children:t.jsxs(Fe,{children:[I&&t.jsxs("p",{className:"text-sm",children:["Update ",I.manifest.name," from ",I.manifest.version,". Existing project access is retained."]}),t.jsxs(Q,{children:[t.jsx(X,{htmlFor:`${a}-package`,children:"Signed plugin package"}),t.jsx(de,{id:`${a}-package`,type:"file",accept:".cogpit-plugin",disabled:T,required:!0,onChange:f=>{var $;return z((($=f.target.files)==null?void 0:$[0])??null)}})]}),!I&&t.jsx(Ue,{value:j,onChange:w,projects:n.projects,disabled:T}),t.jsxs(E,{type:"submit",disabled:T||!H||!I&&!h&&y,children:["Review ",I?"update":"installation"," on ",n.host.name]})]})})}),t.jsx(Oe,{value:"publishers",children:t.jsxs("div",{className:"flex flex-col gap-4 pt-4",children:[n.store.publishers.map(f=>t.jsxs("div",{className:"flex flex-col gap-1",children:[t.jsxs("p",{className:"text-sm font-medium",children:[f.label," ",t.jsx($e,{variant:"outline",children:f.kind})]}),t.jsxs("p",{className:"break-all text-xs text-muted-foreground",children:[f.id," · ",f.fingerprint]})]},f.id)),t.jsxs("details",{children:[t.jsx("summary",{className:"cursor-pointer text-sm",children:"Trust a development publisher"}),t.jsx("div",{className:"pt-4",children:t.jsx(Rt,{client:l,busy:T,run:f=>{J(f)}})})]})]})})]}),c&&t.jsxs("div",{className:"flex flex-col gap-4",children:[t.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsxs("h2",{className:"text-lg font-medium",children:[c.manifest.name," ",c.manifest.version]}),t.jsxs("p",{className:"text-sm text-muted-foreground",children:[c.oldVersion?`Replaces ${c.oldVersion}`:"New installation"," on ",m.hostName]}),t.jsx($e,{variant:"outline",children:c.publisherKind==="development"?"Development publisher":"Official publisher"})]}),t.jsx(Gt,{preview:c}),t.jsxs("p",{className:"text-sm",children:["Available in: ",c.scope.type==="all"?"all projects on this host, including new projects":c.scope.projectIds.length?c.scope.projectIds.map(f=>{var $;return(($=n==null?void 0:n.projects.find(W=>W.id===f))==null?void 0:$.name)??"unavailable project"}).join(", "):"no projects until you choose one","."]}),!c.compatibility.compatible&&t.jsxs(se,{variant:"destructive",children:[t.jsx(De,{children:"Incompatible version"}),t.jsx(ne,{children:t.jsx("ul",{className:"flex flex-col gap-1",children:c.compatibility.issues.map(f=>t.jsxs("li",{children:[f.side,": ",f.name," requires ",f.required,"; available ",f.actual??"none","."]},`${f.side}:${f.code}:${f.name}`))})})]}),c.compatibility.unavailableOptional.length>0&&t.jsx(se,{children:t.jsxs(ne,{children:["Some optional features are unavailable: ",c.compatibility.unavailableOptional.map(f=>f.name).join(", "),"."]})}),g&&te&&!o?t.jsxs(t.Fragment,{children:[t.jsx(At,{client:l,preview:c,activation:e.activation,onComplete:()=>{b(!1),p(null),R(`${c.manifest.name} ${c.manifest.version} is ${c.operation==="rollback"?"restored":c.oldVersion?"updated":"installed"} on ${m.hostName}.`),O("installed"),q(null)},onError:f=>{N(f.message),L()}}),t.jsxs(E,{variant:"outline",onClick:L,children:["Cancel ",c.operation==="rollback"?"rollback":c.oldVersion?"update":"installation"]})]}):t.jsxs("div",{className:"flex flex-wrap justify-end gap-2",children:[t.jsx(E,{variant:"outline",disabled:k,onClick:L,children:"Cancel"}),t.jsxs(E,{disabled:T||!te||!c.compatibility.compatible||o,onClick:()=>{N(null),b(!0)},children:[c.operation==="rollback"?"Roll back":c.oldVersion?"Update":"Install"," on ",m.hostName]})]})]})]})]})})}export{ls as PluginsDialog};
1
+ import{c as ue,r as C,j as t}from"./vendor-react-gGw_S5I_.js";import{C as Z,b7 as Ie,bw as X,bE as Ze,bx as Re,bF as Xe,b5 as de,B as E,z as Fe,bG as et,bH as Ge,bI as Ke,bJ as Je,bK as We,bL as Qe,bM as Ye,A as se,p as ne,bN as tt,Z as $e,bO as st,bP as qe,a8 as nt,a9 as it,ac as lt,a6 as at,ab as ot,aa as rt,a5 as ct,a4 as dt,b6 as De,bQ as ut,bR as ft,D as ht,h as mt,i as pt,j as xt,k as gt,bS as jt,bT as bt,bU as vt,bV as Ae,bW as Oe,L as yt,M as Ct,N as wt,O as Nt,Q as St}from"./index-CYJLZdyZ.js";import{a as kt,ar as $t}from"./vendor-ui-Dxtv9P3W.js";import"./vendor-shiki-DOn6sF-i.js";import"./vendor-markdown-BE1gYnO9.js";function Be(l){const e=l.trim().replace(/^v/i,"").match(/^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?/);return e?{parts:[Number(e[1]),Number(e[2]),Number(e[3])],prerelease:e[4]?e[4].split("."):[]}:null}function Dt(l,e){if(l.length===0&&e.length===0)return 0;if(l.length===0)return 1;if(e.length===0)return-1;for(let s=0;s<Math.max(l.length,e.length);s+=1){const i=l[s],r=e[s];if(i===void 0)return-1;if(r===void 0)return 1;const a=/^\d+$/.test(i),n=/^\d+$/.test(r);if(a&&n){if(Number(i)!==Number(r))return Number(i)<Number(r)?-1:1;continue}if(a!==n)return a?-1:1;if(i!==r)return i<r?-1:1}return 0}function It(l,e){const s=Be(l),i=Be(e);if(!s||!i)return null;for(let r=0;r<3;r+=1)if(s.parts[r]!==i.parts[r])return s.parts[r]<i.parts[r]?-1:1;return Dt(s.prerelease,i.prerelease)}function Me(l){const e=ue.c(33),{value:s,onChange:i,projects:r,disabled:a}=l,n=a===void 0?!1:a,d=C.useId();let o;e[0]!==s.projectIds||e[1]!==s.type?(o=s.type==="projects"?s.projectIds:[],e[0]=s.projectIds,e[1]=s.type,e[2]=o):o=e[2];let v;e[3]!==o?(v=new Set(o),e[3]=o,e[4]=v):v=e[4];const y=v;let h;e[5]===Symbol.for("react.memo_cache_sentinel")?(h=t.jsx(Ze,{children:"Available in"}),e[5]=h):h=e[5];const w=`${d}-all`,j=s.type==="all";let c;e[6]!==i?(c=N=>i(N?{type:"all"}:{type:"projects",projectIds:[]}),e[6]=i,e[7]=c):c=e[7];let p;e[8]!==n||e[9]!==w||e[10]!==j||e[11]!==c?(p=t.jsx(Ie,{id:w,checked:j,disabled:n,onCheckedChange:c}),e[8]=n,e[9]=w,e[10]=j,e[11]=c,e[12]=p):p=e[12];const m=`${d}-all`;let x;e[13]!==m?(x=t.jsx(X,{htmlFor:m,children:"All projects on this host, including new projects"}),e[13]=m,e[14]=x):x=e[14];let g;e[15]!==x||e[16]!==p?(g=t.jsxs(Z,{orientation:"horizontal",children:[p,x]}),e[15]=x,e[16]=p,e[17]=g):g=e[17];let b;e[18]!==n||e[19]!==d||e[20]!==i||e[21]!==r||e[22]!==y||e[23]!==s.projectIds||e[24]!==s.type?(b=s.type==="projects"&&t.jsx("div",{className:"flex max-h-40 flex-col gap-3 overflow-y-auto",children:r.map(N=>t.jsxs(Z,{orientation:"horizontal",children:[t.jsx(Ie,{id:`${d}-${N.id}`,checked:y.has(N.id),disabled:n,onCheckedChange:D=>i({type:"projects",projectIds:D?[...s.projectIds,N.id]:s.projectIds.filter(R=>R!==N.id)})}),t.jsx(X,{htmlFor:`${d}-${N.id}`,children:N.name})]},N.id))}),e[18]=n,e[19]=d,e[20]=i,e[21]=r,e[22]=y,e[23]=s.projectIds,e[24]=s.type,e[25]=b):b=e[25];const k=s.type==="projects"&&s.projectIds.length===0?"Installed but hidden until you choose a project.":"This setting is shared by every client connected to this host.";let S;e[26]!==k?(S=t.jsx(Re,{children:k}),e[26]=k,e[27]=S):S=e[27];let u;return e[28]!==n||e[29]!==g||e[30]!==b||e[31]!==S?(u=t.jsxs(Xe,{disabled:n,children:[h,g,b,S]}),e[28]=n,e[29]=g,e[30]=b,e[31]=S,e[32]=u):u=e[32],u}function Rt(l){const e=ue.c(69),{client:s,run:i,busy:r}=l,a=C.useId(),[n,d]=C.useState(""),[o,v]=C.useState(""),[y,h]=C.useState(null),[w,j]=C.useState(""),[c,p]=C.useState(!1);let m;e[0]!==s||e[1]!==w||e[2]!==o||e[3]!==n||e[4]!==y||e[5]!==i?(m=Q=>{Q.preventDefault(),i(async()=>{var ce;if(!y||y.size>262144)throw new Error("Choose a root metadata file smaller than 256 KiB");if(!((ce=globalThis.crypto)!=null&&ce.subtle))throw new Error("Publisher enrollment requires HTTPS or localhost");const B=await y.arrayBuffer(),re=Array.from(new Uint8Array(await crypto.subtle.digest("SHA-256",B)),Et).join("");if(re!==w.trim().toLowerCase())throw new Error("The root file does not match the fingerprint you entered");await s.enrollDeveloper({publisher:n,label:o,root:new TextDecoder("utf-8",{fatal:!0}).decode(B),fingerprint:re}),p(!1),d(""),v(""),j("")})},e[0]=s,e[1]=w,e[2]=o,e[3]=n,e[4]=y,e[5]=i,e[6]=m):m=e[6];const x=`${a}-name`;let g;e[7]!==x?(g=t.jsx(X,{htmlFor:x,children:"Development publisher"}),e[7]=x,e[8]=g):g=e[8];const b=`${a}-name`;let k;e[9]===Symbol.for("react.memo_cache_sentinel")?(k=Q=>d(Q.target.value),e[9]=k):k=e[9];let S;e[10]!==r||e[11]!==n||e[12]!==b?(S=t.jsx(de,{id:b,value:n,onChange:k,placeholder:"dev-your-name",pattern:"dev-[a-z0-9-]+",maxLength:64,required:!0,disabled:r}),e[10]=r,e[11]=n,e[12]=b,e[13]=S):S=e[13];let u;e[14]===Symbol.for("react.memo_cache_sentinel")?(u=t.jsx(Re,{children:"Development publishers have a separate namespace from official plugins."}),e[14]=u):u=e[14];let N;e[15]!==g||e[16]!==S?(N=t.jsxs(Z,{children:[g,S,u]}),e[15]=g,e[16]=S,e[17]=N):N=e[17];const D=`${a}-label`;let R;e[18]!==D?(R=t.jsx(X,{htmlFor:D,children:"Display name"}),e[18]=D,e[19]=R):R=e[19];const A=`${a}-label`;let O;e[20]===Symbol.for("react.memo_cache_sentinel")?(O=Q=>v(Q.target.value),e[20]=O):O=e[20];let I;e[21]!==r||e[22]!==o||e[23]!==A?(I=t.jsx(de,{id:A,value:o,onChange:O,maxLength:100,required:!0,disabled:r}),e[21]=r,e[22]=o,e[23]=A,e[24]=I):I=e[24];let U;e[25]!==R||e[26]!==I?(U=t.jsxs(Z,{children:[R,I]}),e[25]=R,e[26]=I,e[27]=U):U=e[27];const H=`${a}-root`;let z;e[28]!==H?(z=t.jsx(X,{htmlFor:H,children:"Publisher root file"}),e[28]=H,e[29]=z):z=e[29];const ee=`${a}-root`;let G;e[30]===Symbol.for("react.memo_cache_sentinel")?(G=Q=>{var B;h(((B=Q.target.files)==null?void 0:B[0])??null),p(!1)},e[30]=G):G=e[30];let F;e[31]!==r||e[32]!==ee?(F=t.jsx(de,{id:ee,type:"file",accept:".json,application/json",onChange:G,required:!0,disabled:r}),e[31]=r,e[32]=ee,e[33]=F):F=e[33];let K;e[34]!==z||e[35]!==F?(K=t.jsxs(Z,{children:[z,F]}),e[34]=z,e[35]=F,e[36]=K):K=e[36];const te=`${a}-fingerprint`;let _;e[37]!==te?(_=t.jsx(X,{htmlFor:te,children:"Verified SHA-256 fingerprint"}),e[37]=te,e[38]=_):_=e[38];const J=`${a}-fingerprint`;let L;e[39]===Symbol.for("react.memo_cache_sentinel")?(L=Q=>{j(Q.target.value),p(!1)},e[39]=L):L=e[39];let M;e[40]!==r||e[41]!==w||e[42]!==J?(M=t.jsx(de,{id:J,value:w,onChange:L,placeholder:"64 hexadecimal characters",pattern:"[a-fA-F0-9]{64}",required:!0,disabled:r}),e[40]=r,e[41]=w,e[42]=J,e[43]=M):M=e[43];let T;e[44]===Symbol.for("react.memo_cache_sentinel")?(T=t.jsx(Re,{children:"Get this fingerprint from the publisher through a source you trust."}),e[44]=T):T=e[44];let V;e[45]!==_||e[46]!==M?(V=t.jsxs(Z,{children:[_,M,T]}),e[45]=_,e[46]=M,e[47]=V):V=e[47];const f=`${a}-trust`;let $;e[48]!==r||e[49]!==f||e[50]!==c?($=t.jsx(Ie,{id:f,checked:c,onCheckedChange:p,disabled:r}),e[48]=r,e[49]=f,e[50]=c,e[51]=$):$=e[51];const W=`${a}-trust`;let q;e[52]!==W?(q=t.jsx(X,{htmlFor:W,children:"I verified the publisher and trust packages signed by this root."}),e[52]=W,e[53]=q):q=e[53];let Y;e[54]!==$||e[55]!==q?(Y=t.jsxs(Z,{orientation:"horizontal",children:[$,q]}),e[54]=$,e[55]=q,e[56]=Y):Y=e[56];const ae=r||!c||!y;let ie;e[57]!==ae?(ie=t.jsx(E,{type:"submit",disabled:ae,children:"Trust development publisher"}),e[57]=ae,e[58]=ie):ie=e[58];let le;e[59]!==U||e[60]!==K||e[61]!==V||e[62]!==Y||e[63]!==ie||e[64]!==N?(le=t.jsxs(Fe,{children:[N,U,K,V,Y,ie]}),e[59]=U,e[60]=K,e[61]=V,e[62]=Y,e[63]=ie,e[64]=N,e[65]=le):le=e[65];let oe;return e[66]!==m||e[67]!==le?(oe=t.jsx("form",{onSubmit:m,children:le}),e[66]=m,e[67]=le,e[68]=oe):oe=e[68],oe}function Et(l){return l.toString(16).padStart(2,"0")}const Pt={project:null,theme:{mode:"light",tokens:{}},locale:"en",reducedMotion:!0,visible:!1};function Tt({client:l,preview:e,activation:s,key:i,onFrame:r,onComplete:a,onError:n}){const d=new AbortController;let o="loading",v,y=0;const h=()=>new Error("The installation check expired. Review the package again to retry.");function w(m){o==="canceled"||o==="finished"||(o="canceled",clearTimeout(v),d.abort(),r(null),n(m))}function j(){o==="canceled"||o==="finished"||(o="finished",clearTimeout(v),a())}async function c(m){if(o==="committing"){o="recovering",clearTimeout(v);try{const x=await l.transactionOutcome(e);if(o!=="recovering")return;x.status==="committed"?(await l.refresh(),o==="recovering"&&j()):w(m)}catch{o==="recovering"&&w(new Error("The host did not confirm the installation result. Check Installed after reconnecting before trying again."))}}}async function p(){if(o==="trial"){if(Date.now()>y){w(h());return}o="committing";try{await l.commit(e,d.signal),o==="committing"&&j()}catch(m){await c(m instanceof Error?m:new Error("Plugin installation failed"))}}}return s&&(async()=>{try{const m=await l.payload(e.transactionId,d.signal);if(d.signal.aborted||(y=await l.beginTrial(e,d.signal),d.signal.aborted))return;const x=y-Date.now();if(x<=0){w(h());return}o="trial",v=setTimeout(()=>{o==="committing"?(d.abort(),c(h())):o==="trial"&&w(h())},x),r({key:i,client:l,props:{payload:m,digest:e.digest,activationKey:i,context:Pt,active:!1,title:"Plugin installation check",execute:async(g,b)=>{if(d.signal.throwIfAborted(),b.throwIfAborted(),g.method!=="lifecycle.ready")throw new Error("This action is unavailable during installation");return null},onReady:()=>{p()},onError:w}})}catch(m){w(m instanceof Error?m:new Error("Plugin trial failed"))}})(),()=>{o="canceled",clearTimeout(v),d.abort()}}function At(l){const e=ue.c(22),{client:s,preview:i,activation:r,onComplete:a,onError:n}=l,d=`${r}:trial:${i.transactionId}:${i.digest}:${i.registryRevision}`,[o,v]=C.useState(null);let y;e[0]!==a||e[1]!==n?(y={onComplete:a,onError:n},e[0]=a,e[1]=n,e[2]=y):y=e[2];const h=C.useRef(y);let w;e[3]!==a||e[4]!==n?(w=()=>{h.current={onComplete:a,onError:n}},e[3]=a,e[4]=n,e[5]=w):w=e[5],C.useLayoutEffect(w);let j,c;e[6]!==r||e[7]!==s||e[8]!==d||e[9]!==i?(j=()=>Tt({client:s,preview:i,activation:r,key:d,onFrame:v,onComplete:()=>h.current.onComplete(),onError:g=>h.current.onError(g)}),c=[s,i,r,d],e[6]=r,e[7]=s,e[8]=d,e[9]=i,e[10]=j,e[11]=c):(j=e[10],c=e[11]),C.useLayoutEffect(j,c);let p;e[12]!==i.manifest.name?(p=t.jsxs("p",{children:["Checking that ",i.manifest.name," starts correctly…"]}),e[12]=i.manifest.name,e[13]=p):p=e[13];let m;e[14]!==r||e[15]!==s||e[16]!==o||e[17]!==d?(m=r&&(o==null?void 0:o.key)===d&&o.client===s&&t.jsx(et,{...o.props}),e[14]=r,e[15]=s,e[16]=o,e[17]=d,e[18]=m):m=e[18];let x;return e[19]!==p||e[20]!==m?(x=t.jsxs("div",{role:"status",className:"flex flex-col gap-2",children:[p,m]}),e[19]=p,e[20]=m,e[21]=x):x=e[21],x}function Ot({connection:l,resourceId:e,target:s,client:i,disabled:r,save:a}){const n=C.useId(),d=l.definition.resources[e],o=l.selected[e],[v,y]=C.useState(""),[h,w]=C.useState(null),[j,c]=C.useState(!1),[p,m]=C.useState(null),x=C.useRef(null);C.useEffect(()=>()=>{var u;return(u=x.current)==null?void 0:u.abort()},[]);const g=tt(l.definition,e).find(u=>!l.selected[u]),b=r||!!g||d.scope==="project"&&!s.projectId;async function k(){var N;(N=x.current)==null||N.abort();const u=new AbortController;x.current=u,c(!0),m(null);try{const D=await i.connectionOptions(s,l.id,e,u.signal);u.signal.aborted||w(D)}catch(D){u.signal.aborted||m(D instanceof Error?D.message:"Unable to load choices")}finally{u.signal.aborted||c(!1)}}const S=o&&!(h!=null&&h.some(u=>u.id===o.id))?[o,...h??[]]:h??[];return t.jsxs(Z,{"data-disabled":b,"data-invalid":!!p,children:[t.jsx(X,{htmlFor:`${n}-resource`,children:d.label}),t.jsx(Re,{children:d.scope==="project"?"Applies to the selected project.":"Applies to all projects using this connection."}),o&&t.jsxs("p",{className:"text-sm",children:["Selected: ",o.label]}),g&&t.jsxs("p",{className:"text-sm text-muted-foreground",children:["Choose ",l.definition.resources[g].label," first."]}),d.scope==="project"&&!s.projectId&&t.jsx("p",{className:"text-sm text-muted-foreground",children:"Choose a Cogpit project above."}),d.options&&t.jsxs("div",{className:"flex flex-wrap gap-2",children:[t.jsx(E,{type:"button",variant:"outline",size:"sm",disabled:b||j,onClick:()=>{k()},children:j?"Loading choices…":h?"Refresh choices":"Browse choices"}),h&&t.jsxs(Ye,{items:S.map(u=>({value:u.id,label:u.label})),value:(o==null?void 0:o.id)??null,disabled:b||j,onValueChange:u=>{u&&u!==(o==null?void 0:o.id)&&a(l.id,"select",{resourceId:e,value:u})},children:[t.jsx(Qe,{id:`${n}-resource`,"aria-invalid":!!p,children:t.jsx(We,{placeholder:`Choose ${d.label}`})}),t.jsx(Ge,{children:t.jsx(Ke,{children:S.map(u=>t.jsx(Je,{value:u.id,children:u.label},u.id))})})]}),(h==null?void 0:h.length)===0&&t.jsx("p",{className:"text-sm text-muted-foreground",children:"No choices were returned."})]}),d.input&&t.jsxs("form",{className:"flex flex-wrap gap-2",onSubmit:u=>{u.preventDefault(),a(l.id,"select",{resourceId:e,value:v.trim()})},children:[t.jsx(de,{id:d.options?`${n}-input`:`${n}-resource`,"aria-label":`${d.label} ${d.input.urls?"URL or ID":"ID"}`,value:v,onChange:u=>y(u.target.value),maxLength:2048,disabled:b,autoComplete:"off",spellCheck:!1,placeholder:d.input.urls?"Paste a URL or ID":"Enter an ID"}),t.jsx(E,{type:"submit",size:"sm",variant:"outline",disabled:b||!v.trim(),children:"Validate and select"})]}),o&&t.jsxs(E,{type:"button",size:"sm",variant:"ghost",disabled:b,onClick:()=>{a(l.id,"select",{resourceId:e,value:null})},children:["Clear ",d.label]}),p&&t.jsx("p",{role:"alert",className:"text-sm text-destructive",children:p})]})}function Ft(l){const e=ue.c(45),{connection:s,target:i,client:r,disabled:a,save:n}=l,d=C.useId(),[o,v]=C.useState(""),[y,h]=C.useState(!1),w=s.label;let j;e[0]!==s.label?(j=t.jsx("h3",{className:"font-medium",children:s.label}),e[0]=s.label,e[1]=j):j=e[1];const c=s.status==="disconnected"?"Needs connection":s.readOnly?"Configured by host":"Connected";let p;e[2]!==c?(p=t.jsx($e,{variant:"outline",children:c}),e[2]=c,e[3]=p):p=e[3];let m;e[4]!==j||e[5]!==p?(m=t.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[j,p]}),e[4]=j,e[5]=p,e[6]=m):m=e[6];let x;e[7]===Symbol.for("react.memo_cache_sentinel")?(x=t.jsx("p",{className:"text-sm text-muted-foreground",children:"Cogpit keeps this credential on the selected host. Plugin code cannot read it."}),e[7]=x):x=e[7];let g;e[8]!==s.definition.operations?(g=new Set(Object.values(s.definition.operations).map(_t)),e[8]=s.definition.operations,e[9]=g):g=e[9];let b;e[10]!==g?(b=[...g],e[10]=g,e[11]=b):b=e[11];const k=b.join(", ");let S;e[12]!==k?(S=t.jsxs("p",{className:"break-all text-xs text-muted-foreground",children:["Credential destinations: ",k]}),e[12]=k,e[13]=S):S=e[13];let u;e[14]!==s.id||e[15]!==s.legacyImportAvailable||e[16]!==s.readOnly||e[17]!==s.status||e[18]!==a||e[19]!==d||e[20]!==y||e[21]!==n?(u=s.legacyImportAvailable&&t.jsxs("div",{className:"flex flex-col gap-3 rounded-md bg-muted p-3",children:[t.jsx("p",{className:"text-sm",children:"An existing host connection has saved settings available to import."}),s.status==="connected"&&!s.readOnly&&t.jsxs(Z,{orientation:"horizontal",children:[t.jsx(Ie,{id:`${d}-replace`,checked:y,onCheckedChange:h,disabled:a}),t.jsx(X,{htmlFor:`${d}-replace`,children:"Allow replacing my current connection with these saved settings"})]}),t.jsx(E,{type:"button",size:"sm",variant:"outline",disabled:a,onClick:()=>{n(s.id,"import-legacy",{replaceExisting:y})},children:"Import saved host settings"})]}),e[14]=s.id,e[15]=s.legacyImportAvailable,e[16]=s.readOnly,e[17]=s.status,e[18]=a,e[19]=d,e[20]=y,e[21]=n,e[22]=u):u=e[22];let N;e[23]!==s.definition.secret||e[24]!==s.id||e[25]!==s.readOnly||e[26]!==s.status||e[27]!==a||e[28]!==d||e[29]!==n||e[30]!==o?(N=s.readOnly?t.jsx("p",{className:"text-sm",children:"The host environment supplies this credential. Change it on the host."}):t.jsx("form",{onSubmit:A=>{A.preventDefault();const O=o.trim();v(""),n(s.id,"credential",{secret:O})},children:t.jsxs(Fe,{children:[t.jsxs(Z,{"data-disabled":a,children:[t.jsx(X,{htmlFor:`${d}-secret`,children:s.definition.secret.label}),t.jsx(de,{id:`${d}-secret`,type:"password",autoComplete:"off",spellCheck:!1,maxLength:4096,disabled:a,value:o,onChange:A=>v(A.target.value)})]}),t.jsxs("div",{className:"flex flex-wrap gap-2",children:[t.jsx(E,{type:"submit",size:"sm",disabled:a||!o.trim(),children:s.status==="disconnected"?"Validate and connect":"Replace credential"}),s.status!=="disconnected"&&t.jsx(E,{type:"button",size:"sm",variant:"outline",disabled:a,onClick:()=>{n(s.id,"disconnect",{})},children:"Disconnect"})]})]})}),e[23]=s.definition.secret,e[24]=s.id,e[25]=s.readOnly,e[26]=s.status,e[27]=a,e[28]=d,e[29]=n,e[30]=o,e[31]=N):N=e[31];let D;e[32]!==r||e[33]!==s||e[34]!==a||e[35]!==n||e[36]!==i?(D=s.status!=="disconnected"&&t.jsx(Fe,{children:Object.keys(s.definition.resources).map(A=>t.jsx(Ot,{connection:s,resourceId:A,target:i,client:r,disabled:a,save:n},A))}),e[32]=r,e[33]=s,e[34]=a,e[35]=n,e[36]=i,e[37]=D):D=e[37];let R;return e[38]!==s.label||e[39]!==S||e[40]!==u||e[41]!==N||e[42]!==D||e[43]!==m?(R=t.jsxs("section",{className:"flex flex-col gap-4 rounded-lg border p-4","aria-label":w,children:[m,x,S,u,N,D]}),e[38]=s.label,e[39]=S,e[40]=u,e[41]=N,e[42]=D,e[43]=m,e[44]=R):R=e[44],R}function _t(l){return l.origin}function zt({client:l,target:e}){const[s,i]=C.useState(null),[r,a]=C.useState(null),[n,d]=C.useState(!1),o=C.useRef(null),v=C.useRef(!1),y=e.pluginId,h=e.projectId;C.useEffect(()=>{const j=new AbortController;return o.current=j,l.connections({pluginId:y,projectId:h},j.signal).then(c=>{j.signal.aborted||i(c)}).catch(c=>{j.signal.aborted||a(c instanceof Error?c.message:"Unable to load connections")}),()=>{j.abort(),o.current=null}},[l,y,h]);async function w(j,c,p){if(!s||v.current||!o.current||o.current.signal.aborted)return;v.current=!0;const m=o.current.signal;d(!0),a(null);try{const x=await l.changeConnection(e,j,c,p,s.revision,m);m.aborted||i(x)}catch(x){m.aborted||a(x instanceof Error?x.message:"Connection change failed")}finally{v.current=!1,m.aborted||d(!1)}}return t.jsxs("div",{className:"flex flex-col gap-4",children:[r&&t.jsx(se,{variant:"destructive",children:t.jsx(ne,{children:r})}),!s&&!r&&t.jsx("p",{role:"status",className:"text-sm text-muted-foreground",children:"Loading connections…"}),s==null?void 0:s.connections.map(j=>t.jsx(Ft,{connection:j,target:e,client:l,disabled:n,save:w},`${j.id}:${s.revision}`)),(s==null?void 0:s.connections.length)===0&&t.jsx("p",{className:"text-sm text-muted-foreground",children:"This plugin does not use provider connections."})]})}function Lt(l){const e=ue.c(32),{client:s,status:i,pluginId:r,initialProjectId:a}=l,[n,d]=C.useState(a),o=C.useId();let v;e[0]===Symbol.for("react.memo_cache_sentinel")?(v={value:"",label:"Host connections only"},e[0]=v):v=e[0];let y;e[1]!==i.projects?(y=[v,...i.projects.map(Ut)],e[1]=i.projects,e[2]=y):y=e[2];const h=y;let w;e[3]!==o?(w=t.jsx(X,{htmlFor:o,children:"Project settings"}),e[3]=o,e[4]=w):w=e[4];const j=n??"";let c;e[5]===Symbol.for("react.memo_cache_sentinel")?(c=R=>d(R||null),e[5]=c):c=e[5];let p;e[6]===Symbol.for("react.memo_cache_sentinel")?(p=t.jsx(We,{}),e[6]=p):p=e[6];let m;e[7]!==o?(m=t.jsx(Qe,{id:o,children:p}),e[7]=o,e[8]=m):m=e[8];let x;e[9]!==h?(x=t.jsx(Ge,{children:t.jsx(Ke,{children:h.map(Vt)})}),e[9]=h,e[10]=x):x=e[10];let g;e[11]!==h||e[12]!==j||e[13]!==m||e[14]!==x?(g=t.jsxs(Ye,{items:h,value:j,onValueChange:c,children:[m,x]}),e[11]=h,e[12]=j,e[13]=m,e[14]=x,e[15]=g):g=e[15];let b;e[16]!==i.host.name?(b=t.jsxs(Re,{children:["Connection credentials belong to ",i.host.name,". Project resources stay within the project you choose."]}),e[16]=i.host.name,e[17]=b):b=e[17];let k;e[18]!==b||e[19]!==w||e[20]!==g?(k=t.jsxs(Z,{children:[w,g,b]}),e[18]=b,e[19]=w,e[20]=g,e[21]=k):k=e[21];const S=`${r}:${n??"host"}:${i.connectionRevision??0}`;let u;e[22]!==r||e[23]!==n?(u={pluginId:r,projectId:n},e[22]=r,e[23]=n,e[24]=u):u=e[24];let N;e[25]!==s||e[26]!==S||e[27]!==u?(N=t.jsx(zt,{client:s,target:u},S),e[25]=s,e[26]=S,e[27]=u,e[28]=N):N=e[28];let D;return e[29]!==k||e[30]!==N?(D=t.jsxs("div",{className:"flex flex-col gap-4",children:[k,N]}),e[29]=k,e[30]=N,e[31]=D):D=e[31],D}function Vt(l){return t.jsx(Je,{value:l.value,children:l.label},l.value)}function Ut(l){return{value:l.id,label:l.name}}function Mt(l){var ie;const e=ue.c(174),{plugin:s,status:i,client:r,busy:a,run:n,onPreview:d,onConnections:o,onUpdate:v}=l,y=C.useId(),[h,w]=C.useState(s.scope),[j,c]=C.useState(!1),[p,m]=C.useState(!1);let x,g,b,k,S,u,N,D,R,A,O,I;if(e[0]!==a||e[1]!==r||e[2]!==o||e[3]!==d||e[4]!==v||e[5]!==s||e[6]!==n||e[7]!==h||e[8]!==i.host.name||e[9]!==i.projects||e[10]!==i.runtime||e[11]!==i.store){const le=st(),oe=qe(s.manifest,le,i.runtime,{allowPrerelease:s.manifest.publisher.startsWith("dev-")});let Q;e[24]!==r||e[25]!==s.id||e[26]!==n||e[27]!==i.store?(Q=(P,Te)=>n(()=>r.changeInstalled(s.id,P,Te,i.store.revision)),e[24]=r,e[25]=s.id,e[26]=n,e[27]=i.store,e[28]=Q):Q=e[28];const B=Q,re=s.lastError?"Needs recovery":oe.compatible?s.enabled?"Enabled":"Disabled":"Incompatible";let ce;e[29]!==s.id||e[30]!==s.lastError||e[31]!==s.selectedDigest||e[32]!==i.store?(ce=s.lastError&&((ie=i.store.availableSeeds)==null?void 0:ie.find(P=>P.manifest.id===s.id&&P.digest===s.selectedDigest)),e[29]=s.id,e[30]=s.lastError,e[31]=s.selectedDigest,e[32]=i.store,e[33]=ce):ce=e[33];const _e=ce;A="flex flex-col gap-3 rounded-lg border p-4";let fe;e[34]!==s.manifest.name?(fe=t.jsx("h3",{className:"font-medium",children:s.manifest.name}),e[34]=s.manifest.name,e[35]=fe):fe=e[35];let he;e[36]!==s.id||e[37]!==s.manifest.version?(he=t.jsxs("p",{className:"break-all text-xs text-muted-foreground",children:[s.id," · ",s.manifest.version]}),e[36]=s.id,e[37]=s.manifest.version,e[38]=he):he=e[38];let me;e[39]!==fe||e[40]!==he?(me=t.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[fe,he]}),e[39]=fe,e[40]=he,e[41]=me):me=e[41];const ze=re==="Enabled"?"secondary":"outline";let pe;e[42]!==re||e[43]!==ze?(pe=t.jsx($e,{variant:ze,children:re}),e[42]=re,e[43]=ze,e[44]=pe):pe=e[44],e[45]!==me||e[46]!==pe?(O=t.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-2",children:[me,pe]}),e[45]=me,e[46]=pe,e[47]=O):O=e[47],e[48]!==s.lastError?(I=s.lastError&&t.jsx(se,{variant:"destructive",children:t.jsx(ne,{children:s.lastError})}),e[48]=s.lastError,e[49]=I):I=e[49],g=!oe.compatible&&t.jsx(se,{variant:"destructive",children:t.jsxs(ne,{children:[oe.issues.map(P=>t.jsxs("p",{children:[P.side==="client"?"This client":P.side==="host"?i.host.name:"This package",": ",P.name," requires ",P.required,"; available ",P.actual??"none","."]},`${P.side}:${P.code}:${P.name}`)),t.jsx("p",{children:"Keep the saved data and update the affected app, or choose a compatible retained version below."})]})});let xe;e[50]!==B||e[51]!==s.enabled?(xe=()=>B("enabled",{enabled:!s.enabled}),e[50]=B,e[51]=s.enabled,e[52]=xe):xe=e[52];const Le=s.enabled?"Disable":"Enable";let ge;e[53]!==a||e[54]!==xe||e[55]!==Le?(ge=t.jsx(E,{size:"sm",variant:"outline",disabled:a,onClick:xe,children:Le}),e[53]=a,e[54]=xe,e[55]=Le,e[56]=ge):ge=e[56];let je;e[57]!==a||e[58]!==o||e[59]!==s.id||e[60]!==s.manifest.permissions.connections.length?(je=s.manifest.permissions.connections.length>0&&t.jsx(E,{size:"sm",variant:"outline",disabled:a,onClick:()=>o(s.id),children:"Connections"}),e[57]=a,e[58]=o,e[59]=s.id,e[60]=s.manifest.permissions.connections.length,e[61]=je):je=e[61];const Ve=a||s.pinned;let be;e[62]!==v||e[63]!==s?(be=()=>v(s),e[62]=v,e[63]=s,e[64]=be):be=e[64];let ve;e[65]!==Ve||e[66]!==be?(ve=t.jsx(E,{size:"sm",variant:"outline",disabled:Ve,onClick:be,children:"Update from file"}),e[65]=Ve,e[66]=be,e[67]=ve):ve=e[67];let ye;e[68]!==a||e[69]!==r||e[70]!==d||e[71]!==s.id||e[72]!==s.scope||e[73]!==_e||e[74]!==n?(ye=_e&&t.jsx(E,{size:"sm",variant:"outline",disabled:a,onClick:()=>n(async()=>d(await r.stageSeed(s.id,s.scope))),children:"Review bundled repair"}),e[68]=a,e[69]=r,e[70]=d,e[71]=s.id,e[72]=s.scope,e[73]=_e,e[74]=n,e[75]=ye):ye=e[75];let Ce;e[76]!==B||e[77]!==s.pinned?(Ce=()=>B("pin",{pinned:!s.pinned}),e[76]=B,e[77]=s.pinned,e[78]=Ce):Ce=e[78];const Ue=s.pinned?"Unpin version":"Pin version";let we;e[79]!==a||e[80]!==Ce||e[81]!==Ue?(we=t.jsx(E,{size:"sm",variant:"outline",disabled:a,onClick:Ce,children:Ue}),e[79]=a,e[80]=Ce,e[81]=Ue,e[82]=we):we=e[82];let Ee;e[83]===Symbol.for("react.memo_cache_sentinel")?(Ee=()=>{m(!1),c(!0)},e[83]=Ee):Ee=e[83];let Ne;e[84]!==a?(Ne=t.jsx(E,{size:"sm",variant:"ghost",disabled:a,onClick:Ee,children:"Uninstall"}),e[84]=a,e[85]=Ne):Ne=e[85],e[86]!==ge||e[87]!==je||e[88]!==ve||e[89]!==ye||e[90]!==we||e[91]!==Ne?(b=t.jsxs("div",{className:"flex flex-wrap gap-2",children:[ge,je,ve,ye,we,Ne]}),e[86]=ge,e[87]=je,e[88]=ve,e[89]=ye,e[90]=we,e[91]=Ne,e[92]=b):b=e[92],e[93]!==s.pinned?(k=s.pinned&&t.jsx("p",{className:"text-xs text-muted-foreground",children:"Unpin this version before updating or rolling back. Revoked packages remain blocked."}),e[93]=s.pinned,e[94]=k):k=e[94],D="text-sm",e[95]===Symbol.for("react.memo_cache_sentinel")?(R=t.jsx("summary",{className:"cursor-pointer",children:"Projects and previous versions"}),e[95]=R):R=e[95],x="flex flex-col gap-4 pt-4",e[96]!==a||e[97]!==h||e[98]!==i.projects?(S=t.jsx(Me,{value:h,onChange:w,projects:i.projects,disabled:a}),e[96]=a,e[97]=h,e[98]=i.projects,e[99]=S):S=e[99];let Se;e[100]!==a||e[101]!==s.scope||e[102]!==h?(Se=a||JSON.stringify(h)===JSON.stringify(s.scope),e[100]=a,e[101]=s.scope,e[102]=h,e[103]=Se):Se=e[103];let ke;e[104]!==B||e[105]!==h?(ke=()=>B("scope",{scope:h}),e[104]=B,e[105]=h,e[106]=ke):ke=e[106],e[107]!==i.host.name||e[108]!==Se||e[109]!==ke?(u=t.jsxs(E,{size:"sm",variant:"outline",disabled:Se,onClick:ke,children:["Save projects on ",i.host.name]}),e[107]=i.host.name,e[108]=Se,e[109]=ke,e[110]=u):u=e[110];let Pe;e[111]!==s.selectedDigest?(Pe=P=>P.digest!==s.selectedDigest,e[111]=s.selectedDigest,e[112]=Pe):Pe=e[112],N=s.versions.filter(Pe).map(P=>{const Te=!P.unavailableReason&&qe(P.manifest,le,i.runtime,{allowPrerelease:P.manifest.publisher.startsWith("dev-")}).compatible;return t.jsxs("div",{className:"flex flex-col gap-1",children:[t.jsxs(E,{size:"sm",variant:"outline",disabled:a||s.pinned||!Te,onClick:()=>n(async()=>d({...await r.rollback(s.id,P.digest,s.scope),operation:"rollback"})),children:["Review rollback to ",P.manifest.version]}),!Te&&t.jsx("p",{className:"text-xs text-muted-foreground",children:P.unavailableReason??"This version is incompatible with the connected host or client."})]},P.digest)}),e[0]=a,e[1]=r,e[2]=o,e[3]=d,e[4]=v,e[5]=s,e[6]=n,e[7]=h,e[8]=i.host.name,e[9]=i.projects,e[10]=i.runtime,e[11]=i.store,e[12]=x,e[13]=g,e[14]=b,e[15]=k,e[16]=S,e[17]=u,e[18]=N,e[19]=D,e[20]=R,e[21]=A,e[22]=O,e[23]=I}else x=e[12],g=e[13],b=e[14],k=e[15],S=e[16],u=e[17],N=e[18],D=e[19],R=e[20],A=e[21],O=e[22],I=e[23];let U;e[113]===Symbol.for("react.memo_cache_sentinel")?(U=t.jsx("p",{className:"text-xs text-muted-foreground",children:"Rollback keeps current settings. Disabling keeps the installation and its saved data."}),e[113]=U):U=e[113];let H;e[114]!==x||e[115]!==S||e[116]!==u||e[117]!==N?(H=t.jsxs("div",{className:x,children:[S,u,N,U]}),e[114]=x,e[115]=S,e[116]=u,e[117]=N,e[118]=H):H=e[118];let z;e[119]!==H||e[120]!==D||e[121]!==R?(z=t.jsxs("details",{className:D,children:[R,H]}),e[119]=H,e[120]=D,e[121]=R,e[122]=z):z=e[122];let ee;e[123]!==s.manifest.name?(ee=t.jsxs(nt,{children:["Uninstall ",s.manifest.name,"?"]}),e[123]=s.manifest.name,e[124]=ee):ee=e[124];let G;e[125]!==i.host.name?(G=t.jsxs(it,{children:["This removes the plugin from ",i.host.name," for every connected client and project. Saved data is retained unless you choose deletion."]}),e[125]=i.host.name,e[126]=G):G=e[126];let F;e[127]!==ee||e[128]!==G?(F=t.jsxs(at,{children:[ee,G]}),e[127]=ee,e[128]=G,e[129]=F):F=e[129];const K=`${y}-delete`,te=a||i.connectionRevision===void 0;let _;e[130]!==p||e[131]!==K||e[132]!==te?(_=t.jsx(Ie,{id:K,checked:p,onCheckedChange:m,disabled:te}),e[130]=p,e[131]=K,e[132]=te,e[133]=_):_=e[133];const J=`${y}-delete`;let L;e[134]!==J?(L=t.jsx(X,{htmlFor:J,children:"Delete my saved settings and connections on this host"}),e[134]=J,e[135]=L):L=e[135];let M;e[136]!==_||e[137]!==L?(M=t.jsxs(Z,{orientation:"horizontal",children:[_,L]}),e[136]=_,e[137]=L,e[138]=M):M=e[138];let T;e[139]!==p?(T=p&&t.jsx("p",{className:"text-sm text-muted-foreground",children:"This cannot be undone. Other administrators' saved data is retained. Provider tokens and legacy backup files are not removed."}),e[139]=p,e[140]=T):T=e[140];let V;e[141]!==a?(V=t.jsx(ot,{disabled:a,children:"Cancel"}),e[141]=a,e[142]=V):V=e[142];let f;e[143]!==r||e[144]!==p||e[145]!==s.id||e[146]!==n||e[147]!==i.connectionRevision||e[148]!==i.store?(f=()=>{c(!1),n(()=>r.changeInstalled(s.id,"uninstall",p?{deleteData:!0,expectedConnectionRevision:i.connectionRevision}:{deleteData:!1},i.store.revision))},e[143]=r,e[144]=p,e[145]=s.id,e[146]=n,e[147]=i.connectionRevision,e[148]=i.store,e[149]=f):f=e[149];let $;e[150]!==a||e[151]!==i.host.name||e[152]!==f?($=t.jsxs(lt,{variant:"destructive",disabled:a,onClick:f,children:["Uninstall from ",i.host.name]}),e[150]=a,e[151]=i.host.name,e[152]=f,e[153]=$):$=e[153];let W;e[154]!==V||e[155]!==$?(W=t.jsxs(rt,{children:[V,$]}),e[154]=V,e[155]=$,e[156]=W):W=e[156];let q;e[157]!==F||e[158]!==M||e[159]!==T||e[160]!==W?(q=t.jsxs(ct,{children:[F,M,T,W]}),e[157]=F,e[158]=M,e[159]=T,e[160]=W,e[161]=q):q=e[161];let Y;e[162]!==j||e[163]!==q?(Y=t.jsx(dt,{open:j,onOpenChange:c,children:q}),e[162]=j,e[163]=q,e[164]=Y):Y=e[164];let ae;return e[165]!==g||e[166]!==b||e[167]!==k||e[168]!==z||e[169]!==Y||e[170]!==A||e[171]!==O||e[172]!==I?(ae=t.jsxs("article",{className:A,children:[O,I,g,b,k,z,Y]}),e[165]=g,e[166]=b,e[167]=k,e[168]=z,e[169]=Y,e[170]=A,e[171]=O,e[172]=I,e[173]=ae):ae=e[173],ae}const qt={github:"GitHub",vercel:"Vercel",cloudflare:"Cloudflare"},Bt={actions:"workflow runs",actionJobs:"workflow jobs and steps",pulls:"pull requests",pullFiles:"pull request files",issues:"issues",deployments:"deployments",buildLogs:"build logs",workspace:"Worker configuration and account",version:"version details"};function Ht(l,e){return e==="pullSessions"?"Read related Cogpit sessions for the selected GitHub repository":e==="mergePull"?"Merge pull requests in the selected GitHub repository when you confirm, using this host's signed-in CLI":`Read ${qt[l]} ${Bt[e]} using this host's signed-in CLI`}function He(l){const e=l.permissions;return[...e.context.map(s=>s==="session.identity"?"Recognise the open session among related sessions, by handle only":"Read the selected project's name and plugin identifier"),...e.composer.map(()=>"Append text to your draft message"),...e.navigation.map(s=>s==="external"?"Ask Cogpit to open HTTPS links":"Open permitted sessions"),...e.storage?[`Store up to ${e.storage.quotaKiB} KiB of ${e.storage.scope} settings`]:[],...e.connections.flatMap(s=>s.operations.map(i=>`Use connection ${s.id}: ${i}`)),...e.integrations.flatMap(s=>s.operations.map(i=>Ht(s.id,i)))]}function Gt(l){var j;const e=ue.c(32),{preview:s}=l;let i,r,a,n,d,o;if(e[0]!==s.connectionDefinitions||e[1]!==s.manifest||e[2]!==s.oldVersion||e[3]!==s.operation||e[4]!==s.previousConnectionDefinitions||e[5]!==s.previousManifest){const c=He(s.manifest),p=s.previousManifest?He(s.previousManifest):null,m=p?c.filter(b=>!p.includes(b)):[],x=p?p.filter(b=>!c.includes(b)):[],g=s.previousConnectionDefinitions?s.connectionDefinitions.filter(b=>{var S;const k=(S=s.previousConnectionDefinitions)==null?void 0:S.find(u=>u.id===b.id);return!k||JSON.stringify(k)!==JSON.stringify(b)}):[];i="flex flex-col gap-3 text-sm",e[12]!==s.oldVersion||e[13]!==s.operation?(r=s.oldVersion&&t.jsxs(se,{children:[t.jsx(De,{children:s.operation==="rollback"?"Rollback keeps current settings":"Update on this host"}),t.jsxs(ne,{children:["Saved settings and connections are retained. This version replaces ",s.oldVersion," in every enabled project and connected client. A failed trial leaves the current version selected."]})]}),e[12]=s.oldVersion,e[13]=s.operation,e[14]=r):r=e[14],a=p&&t.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsx("h3",{className:"font-medium",children:"Access changes"}),m.length===0&&x.length===0&&g.length===0&&t.jsx("p",{children:"No changes to requested access or connection definitions."}),m.map(Xt),x.map(Zt),g.map(Yt)]}),n=s.oldVersion&&!p&&t.jsx(se,{children:t.jsx(ne,{children:"This host does not report previous permissions. Review all requested access before continuing."})}),e[15]===Symbol.for("react.memo_cache_sentinel")?(d=t.jsx("h3",{className:"font-medium",children:"Requested access"}),e[15]=d):d=e[15],o=c.length?t.jsx("ul",{className:"ml-4 flex list-disc flex-col gap-1",children:c.map(Qt)}):t.jsx("p",{className:"text-muted-foreground",children:"No project, connection, storage, or composer access requested."}),e[0]=s.connectionDefinitions,e[1]=s.manifest,e[2]=s.oldVersion,e[3]=s.operation,e[4]=s.previousConnectionDefinitions,e[5]=s.previousManifest,e[6]=i,e[7]=r,e[8]=a,e[9]=n,e[10]=d,e[11]=o}else i=e[6],r=e[7],a=e[8],n=e[9],d=e[10],o=e[11];let v;e[16]!==s.connectionDefinitions?(v=s.connectionDefinitions.map(Kt),e[16]=s.connectionDefinitions,e[17]=v):v=e[17];let y;e[18]!==s.incompatibleClients?(y=!!((j=s.incompatibleClients)!=null&&j.length)&&t.jsxs(se,{children:[t.jsx(De,{children:"Some connected clients cannot run this version"}),t.jsxs(ne,{children:[s.incompatibleClients.join(", "),". Their plugin panels will be unavailable until those clients are updated. Offline clients are checked when they reconnect."]})]}),e[18]=s.incompatibleClients,e[19]=y):y=e[19];let h;e[20]!==s.digest?(h=t.jsxs("p",{className:"break-all text-xs text-muted-foreground",children:["SHA-256: ",s.digest]}),e[20]=s.digest,e[21]=h):h=e[21];let w;return e[22]!==i||e[23]!==r||e[24]!==a||e[25]!==n||e[26]!==d||e[27]!==o||e[28]!==v||e[29]!==y||e[30]!==h?(w=t.jsxs("div",{className:i,children:[r,a,n,d,o,v,y,h]}),e[22]=i,e[23]=r,e[24]=a,e[25]=n,e[26]=d,e[27]=o,e[28]=v,e[29]=y,e[30]=h,e[31]=w):w=e[31],w}function Kt(l){return t.jsxs("div",{className:"flex flex-col gap-1",children:[t.jsx("p",{className:"font-medium",children:l.label}),t.jsxs("p",{children:["Access to ",Object.values(l.resources).map(Wt).join(", ")||"the connected account","."]}),t.jsxs("p",{className:"break-all text-muted-foreground",children:["Credential destinations: ",[...new Set(Object.values(l.operations).map(Jt))].join(", ")]})]},l.id)}function Jt(l){return l.origin}function Wt(l){return l.label}function Qt(l){return t.jsx("li",{children:l},l)}function Yt(l){return t.jsxs("p",{children:["Changed connection: ",l.label,". Review its destinations and access below."]},l.id)}function Zt(l){return t.jsxs("p",{children:["Removed: ",l]},`remove:${l}`)}function Xt(l){return t.jsxs("p",{children:["Added: ",l]},`add:${l}`)}function ls({client:l,state:e,currentPath:s,onClose:i,initialPluginId:r}){var V;const a=C.useId(),n=e.status,d=ut(),o=(n==null?void 0:n.safeMode)||d,{project:v,resolving:y}=ft({client:l,status:n,activation:e.activation,projectPath:s}),[h,w]=C.useState(null),j=h??{type:"projects",projectIds:v?[v.id]:[]},[c,p]=C.useState(null),[m,x]=C.useState({activation:"",hostName:""}),[g,b]=C.useState(!1),[k,S]=C.useState(!1),[u,N]=C.useState(null),[D,R]=C.useState(null),[A,O]=C.useState("installed"),[I,U]=C.useState(null),[H,z]=C.useState(null),[ee,G]=C.useState(r),F=n==null?void 0:n.store.plugins.find(f=>f.id===ee),K=C.useRef(!1),te=!!(n!=null&&n.store.available)&&m.activation===e.activation;function _(f){x({activation:e.activation,hostName:(n==null?void 0:n.host.name)??"the selected host"}),p(f)}C.useEffect(()=>{!c||te&&!(o&&g)||(b(!1),p(null),N("The host connection or plugin execution state changed. Review the package again before installing."),l.cancel(c).catch(()=>{}))},[l,c,te,o,g]),C.useEffect(()=>()=>{c&&l.cancel(c).catch(()=>{})},[l,c]);async function J(f){if(!K.current){K.current=!0,S(!0),N(null),R(null);try{await f()}catch($){N($ instanceof Error?$.message:"Plugin action failed")}finally{K.current=!1,S(!1)}}}function L(){const f=c;b(!1),p(null),f&&l.cancel(f).catch(()=>{})}async function M(){if(!H||!I&&!h&&y)return;const f=await l.stage(H,(I==null?void 0:I.scope)??j);if(I&&f.manifest.id!==I.id)throw await l.cancel(f),new Error(`Choose a package for ${I.manifest.name} (${I.id}).`);_(f)}const T=k||g||!(n!=null&&n.store.available);return t.jsx(ht,{open:!0,onOpenChange:f=>{!f&&!k&&!g&&(L(),i())},children:t.jsxs(mt,{className:"flex max-h-[85dvh] flex-col sm:max-w-2xl",showCloseButton:!k&&!g,children:[t.jsxs(pt,{children:[t.jsx(xt,{children:"Plugins"}),t.jsx(gt,{children:n?`Installed on ${n.host.name}. Changes apply to every client connected to this host.`:"Connecting to the selected host…"})]}),t.jsxs("div",{className:"flex min-h-0 flex-col gap-4 overflow-y-auto",children:[(e.error||u||(n==null?void 0:n.store.error))&&t.jsxs(se,{variant:"destructive",children:[t.jsx(De,{children:n!=null&&n.store.available&&!u&&!e.error?"Plugin setup needs attention":"Plugin action unavailable"}),t.jsx(ne,{children:u??e.error??(n==null?void 0:n.store.error)})]}),D&&t.jsx(se,{children:t.jsx(ne,{children:D})}),o&&t.jsxs(se,{children:[t.jsx(De,{children:"Plugin safe mode"}),t.jsxs(ne,{children:["Plugin panels are stopped. You can disable or uninstall plugins here.",(n==null?void 0:n.safeMode)&&" The host owner must restart Cogpit without COGPIT_DISABLE_PLUGINS=1 to resume plugins on this host."]})]}),t.jsx(E,{size:"sm",variant:"outline",disabled:k||g||(n==null?void 0:n.safeMode),onClick:()=>jt(!d),children:d?"Resume plugins in this browser":"Pause plugins in this browser"}),(n==null?void 0:n.store.recoveryCode)&&t.jsx("p",{className:"text-sm text-muted-foreground",children:n.store.recoveryCode==="STORE_LOCKED"?"Close the other Cogpit process using this data directory, then restart this host.":n.store.recoveryCode==="STORE_VERSION"?"Open this host with the Cogpit version that last used its plugin store, or a newer compatible version.":"Keep the plugin data directory intact. Restart with plugin safe mode enabled and check the host log before restoring a verified backup."}),!n&&t.jsxs(E,{variant:"outline",disabled:k,onClick:()=>{J(()=>l.refresh())},children:[t.jsx(kt,{"data-icon":"inline-start"}),"Retry connection"]}),n&&F&&!c&&t.jsxs("div",{className:"flex flex-col gap-4",children:[t.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[t.jsxs("h2",{className:"font-medium",children:[F.manifest.name," connections"]}),t.jsx(E,{variant:"outline",size:"sm",onClick:()=>G(void 0),children:"Back to installed"})]}),t.jsx(Lt,{client:l,status:n,pluginId:F.id,initialProjectId:(v==null?void 0:v.id)??null},`${F.id}:${n.store.revision}`)]}),n&&!F&&!c&&t.jsxs(bt,{value:A,onValueChange:f=>{O(String(f)),U(null),z(null)},children:[t.jsxs(vt,{className:"h-auto flex-wrap",children:[t.jsx(Ae,{value:"installed",children:"Installed"}),t.jsx(Ae,{value:"browse",children:"Browse"}),t.jsx(Ae,{value:"install",children:"Install from file"}),t.jsx(Ae,{value:"publishers",children:"Publishers"})]}),t.jsx(Oe,{value:"installed",children:t.jsx("div",{className:"flex flex-col gap-3 pt-4",children:n.store.plugins.length?n.store.plugins.map(f=>t.jsx(Mt,{plugin:f,status:n,client:l,busy:T,run:$=>{J($)},onPreview:_,onConnections:G,onUpdate:$=>{U($),z(null),O("install")}},`${f.id}:${n.store.revision}`)):t.jsx(yt,{children:t.jsxs(Ct,{children:[t.jsx(wt,{variant:"icon",children:t.jsx($t,{})}),t.jsx(Nt,{children:"No installed plugins"}),t.jsx(St,{children:"Browse available plugins or install a signed package to add panels to this host."})]})})})}),t.jsx(Oe,{value:"browse",children:t.jsxs("div",{className:"flex flex-col gap-4 pt-4",children:[t.jsxs("p",{className:"text-sm text-muted-foreground",children:["These optional plugins are available with this Cogpit release. Choose which ones to install on ",n.host.name,"."]}),t.jsx(Me,{value:j,onChange:w,projects:n.projects,disabled:T}),(n.store.availableSeeds??[]).map(f=>{const $=n.store.plugins.find(q=>q.id===f.manifest.id),W=$&&It(f.manifest.version,$.manifest.version)===1;return t.jsxs("article",{className:"flex flex-wrap items-center justify-between gap-3 rounded-lg border p-4",children:[t.jsxs("div",{children:[t.jsx("h3",{className:"font-medium",children:f.manifest.name}),t.jsxs("p",{className:"text-xs text-muted-foreground",children:[f.manifest.version," · ",f.manifest.publisher]})]}),W?t.jsx(E,{size:"sm",disabled:T||$.pinned,onClick:()=>{J(async()=>_(await l.stageSeed(f.manifest.id,$.scope)))},children:$.pinned?"Pinned to installed version":"Review update"}):$?t.jsx($e,{variant:"outline",children:"Installed"}):t.jsx(E,{size:"sm",disabled:T||!h&&y,onClick:()=>{J(async()=>_(await l.stageSeed(f.manifest.id,j)))},children:"Review installation"})]},f.manifest.id)}),!((V=n.store.availableSeeds)!=null&&V.length)&&t.jsx("p",{className:"text-sm text-muted-foreground",children:"This host has no bundled plugin packages. You can install a signed package from a file."})]})}),t.jsx(Oe,{value:"install",children:t.jsx("form",{className:"pt-4",onSubmit:f=>{f.preventDefault(),J(M)},children:t.jsxs(Fe,{children:[I&&t.jsxs("p",{className:"text-sm",children:["Update ",I.manifest.name," from ",I.manifest.version,". Existing project access is retained."]}),t.jsxs(Z,{children:[t.jsx(X,{htmlFor:`${a}-package`,children:"Signed plugin package"}),t.jsx(de,{id:`${a}-package`,type:"file",accept:".cogpit-plugin",disabled:T,required:!0,onChange:f=>{var $;return z((($=f.target.files)==null?void 0:$[0])??null)}})]}),!I&&t.jsx(Me,{value:j,onChange:w,projects:n.projects,disabled:T}),t.jsxs(E,{type:"submit",disabled:T||!H||!I&&!h&&y,children:["Review ",I?"update":"installation"," on ",n.host.name]})]})})}),t.jsx(Oe,{value:"publishers",children:t.jsxs("div",{className:"flex flex-col gap-4 pt-4",children:[n.store.publishers.map(f=>t.jsxs("div",{className:"flex flex-col gap-1",children:[t.jsxs("p",{className:"text-sm font-medium",children:[f.label," ",t.jsx($e,{variant:"outline",children:f.kind})]}),t.jsxs("p",{className:"break-all text-xs text-muted-foreground",children:[f.id," · ",f.fingerprint]})]},f.id)),t.jsxs("details",{children:[t.jsx("summary",{className:"cursor-pointer text-sm",children:"Trust a development publisher"}),t.jsx("div",{className:"pt-4",children:t.jsx(Rt,{client:l,busy:T,run:f=>{J(f)}})})]})]})})]}),c&&t.jsxs("div",{className:"flex flex-col gap-4",children:[t.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsxs("h2",{className:"text-lg font-medium",children:[c.manifest.name," ",c.manifest.version]}),t.jsxs("p",{className:"text-sm text-muted-foreground",children:[c.oldVersion?`Replaces ${c.oldVersion}`:"New installation"," on ",m.hostName]}),t.jsx($e,{variant:"outline",children:c.publisherKind==="development"?"Development publisher":"Official publisher"})]}),t.jsx(Gt,{preview:c}),t.jsxs("p",{className:"text-sm",children:["Available in: ",c.scope.type==="all"?"all projects on this host, including new projects":c.scope.projectIds.length?c.scope.projectIds.map(f=>{var $;return(($=n==null?void 0:n.projects.find(W=>W.id===f))==null?void 0:$.name)??"unavailable project"}).join(", "):"no projects until you choose one","."]}),!c.compatibility.compatible&&t.jsxs(se,{variant:"destructive",children:[t.jsx(De,{children:"Incompatible version"}),t.jsx(ne,{children:t.jsx("ul",{className:"flex flex-col gap-1",children:c.compatibility.issues.map(f=>t.jsxs("li",{children:[f.side,": ",f.name," requires ",f.required,"; available ",f.actual??"none","."]},`${f.side}:${f.code}:${f.name}`))})})]}),c.compatibility.unavailableOptional.length>0&&t.jsx(se,{children:t.jsxs(ne,{children:["Some optional features are unavailable: ",c.compatibility.unavailableOptional.map(f=>f.name).join(", "),"."]})}),g&&te&&!o?t.jsxs(t.Fragment,{children:[t.jsx(At,{client:l,preview:c,activation:e.activation,onComplete:()=>{b(!1),p(null),R(`${c.manifest.name} ${c.manifest.version} is ${c.operation==="rollback"?"restored":c.oldVersion?"updated":"installed"} on ${m.hostName}.`),O("installed"),U(null)},onError:f=>{N(f.message),L()}}),t.jsxs(E,{variant:"outline",onClick:L,children:["Cancel ",c.operation==="rollback"?"rollback":c.oldVersion?"update":"installation"]})]}):t.jsxs("div",{className:"flex flex-wrap justify-end gap-2",children:[t.jsx(E,{variant:"outline",disabled:k,onClick:L,children:"Cancel"}),t.jsxs(E,{disabled:T||!te||!c.compatibility.compatible||o,onClick:()=>{N(null),b(!0)},children:[c.operation==="rollback"?"Roll back":c.oldVersion?"Update":"Install"," on ",m.hostName]})]})]})]})]})})}export{ls as PluginsDialog};
@@ -1 +1 @@
1
- import{r as a,j as t}from"./vendor-react-gGw_S5I_.js";import{y as ne,B as g,l as K,z as ie,C as oe,m as le,n as ce,I as de,E as G,G as ue,T as he,H as pe,J as me,L as fe,M as xe,N as we,O as ve,Q as ge,R as be,U as je,w as b}from"./index-DsnL-sXV.js";import{E as H,X as ye,a as Se,b as Ne,c as Ie,M as Ee,T as ke,d as Me,e as Pe,Z as ze,f as Re}from"./vendor-ui-Br3ZTAXZ.js";import"./vendor-shiki-DOn6sF-i.js";import"./vendor-markdown-BE1gYnO9.js";const O=360,Ce=560,V="cogpit-preview-width",Y="cogpit-preview-viewport",_="cogpit-preview-zoom",E=.5,k=1.5,I=.1,h={responsive:{label:"Responsive",width:null,height:null,icon:Pe},phone:{label:"Phone",width:390,height:844,icon:Me},tablet:{label:"Tablet",width:768,height:1024,icon:ke},desktop:{label:"Desktop",width:1280,height:800,icon:Ee}};function Te(){try{const s=Number(localStorage.getItem(V));if(Number.isFinite(s)&&s>=O)return s}catch{}return Ce}function De(){try{const s=localStorage.getItem(Y);if(s&&s in h)return s}catch{}return"responsive"}function Oe(){try{const s=localStorage.getItem(_);if(s===null)return 1;const i=Number(s);if(Number.isFinite(i))return Math.min(k,Math.max(E,i))}catch{}return 1}function X(s){return be(`cogpit-preview-url:${s}`)}function A(s){const i=s.trim();if(!i||/^[a-z][a-z\d+.-]*:/i.test(i)&&!/^https?:\/\//i.test(i)&&!/^[^/]+:\d+(?:\/|$)/.test(i))return null;const j=/^https?:\/\//i.test(i)?i:`http://${i}`;try{const n=new URL(j);return n.protocol!=="http:"&&n.protocol!=="https:"?null:n.href}catch{return null}}function B(s,i){return`http://${i||"localhost"}:${s}/`}function Le({cwd:s,onClose:i}){const[M,j]=a.useState([]),[n,P]=a.useState(""),[W,y]=a.useState(""),[z,R]=a.useState(null),[J,Q]=a.useState(0),[q,C]=a.useState(!1),[S,ee]=a.useState(Te),[l,te]=a.useState(De),[o,p]=a.useState(Oe),c=a.useRef(null),$=a.useRef(null),T=a.useRef(null),{activeDevice:m}=ne(),N=(m==null?void 0:m.host)??(window.location.hostname||"localhost"),re=m==null?void 0:m.id;a.useEffect(()=>{let e="";try{e=localStorage.getItem(X(s))??""}catch{}const r=e?A(e)??"":"";P(r),y(r),R(null)},[s,re]),a.useEffect(()=>{let e=!1;async function r(){try{const u=await je(`/api/background-tasks?cwd=${encodeURIComponent(s)}`);if(e||!u.ok)return;const x=await u.json(),f=Array.isArray(x)?x:[];j(f);const L=f.flatMap(w=>w.ports.filter(v=>w.portStatus[v])).at(0);if(L){const w=B(L,N);P(v=>v||w),y(v=>v||w)}}catch{e||j([])}}r();const d=window.setInterval(r,1e4);return()=>{e=!0,window.clearInterval(d)}},[s,N]),a.useEffect(()=>{if(n)try{localStorage.setItem(X(s),n)}catch{}},[s,n]),a.useEffect(()=>{try{localStorage.setItem(Y,l),localStorage.setItem(_,String(o))}catch{}},[l,o]);const Z=a.useMemo(()=>[...new Set(M.flatMap(e=>e.ports.filter(r=>e.portStatus[r])))].sort((e,r)=>e-r),[M]),U=a.useCallback(e=>{const r=A(e);if(!r){R("Enter a valid HTTP or HTTPS URL.");return}R(null),P(r),y(r),C(!0)},[]),D=a.useCallback(()=>{n&&(C(!0),Q(e=>e+1))},[n]);a.useEffect(()=>{function e(r){var d,u,x;if((d=$.current)!=null&&d.contains(document.activeElement)){if(b("previewRefresh",r)){r.preventDefault(),D();return}if(b("previewFocusUrl",r)){r.preventDefault(),(u=T.current)==null||u.focus(),(x=T.current)==null||x.select();return}if(b("previewZoomIn",r)){r.preventDefault(),p(f=>Math.min(k,Number((f+I).toFixed(1))));return}if(b("previewZoomOut",r)){r.preventDefault(),p(f=>Math.max(E,Number((f-I).toFixed(1))));return}b("previewResetZoom",r)&&(r.preventDefault(),p(1))}}return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[D]);const se=a.useCallback(e=>{e.preventDefault(),c.current={startX:e.clientX,startWidth:S,currentWidth:S},e.currentTarget.setPointerCapture(e.pointerId)},[S]),ae=a.useCallback(e=>{if(!c.current)return;const r=Math.max(O,window.innerWidth*.7),d=c.current.startWidth+(c.current.startX-e.clientX),u=Math.min(r,Math.max(O,d));c.current.currentWidth=u,ee(u)},[]),F=a.useCallback(()=>{if(!c.current)return;const e=c.current.currentWidth;c.current=null;try{localStorage.setItem(V,String(e))}catch{}},[]);return t.jsxs("aside",{ref:$,"aria-label":"Development preview",className:"view-transition-right-panel panel-enter-right relative flex min-h-0 shrink-0 flex-col border-l bg-canvas",style:{width:S},children:[t.jsx("div",{"aria-hidden":"true",className:"absolute inset-y-0 left-0 w-1 cursor-col-resize hover:bg-primary/30",onPointerDown:se,onPointerMove:ae,onPointerUp:F,onPointerCancel:F}),t.jsxs("div",{className:"flex h-10 shrink-0 items-center gap-2 px-3",children:[t.jsx(H,{"aria-hidden":"true",className:"size-4 text-muted-foreground"}),t.jsx("h2",{className:"text-sm font-medium",children:"Preview"}),t.jsx("span",{className:"flex-1"}),t.jsx(g,{variant:"ghost",size:"icon-sm",onClick:i,"aria-label":"Close preview",children:t.jsx(ye,{"data-icon":"inline-start"})})]}),t.jsx(K,{}),t.jsx("form",{className:"p-2",onSubmit:e=>{e.preventDefault(),U(W)},children:t.jsx(ie,{className:"gap-2",children:t.jsxs(oe,{"data-invalid":!!z,children:[t.jsxs(le,{children:[t.jsx(ce,{ref:T,"aria-label":"Preview URL","aria-invalid":!!z,value:W,onChange:e=>y(e.target.value),placeholder:"localhost:3000",spellCheck:!1}),t.jsxs(de,{align:"inline-end",children:[t.jsx(G,{size:"icon-xs",disabled:!n,onClick:D,"aria-label":"Refresh preview",children:t.jsx(Se,{"data-icon":"inline-start",className:q?"animate-spin":void 0})}),t.jsx(G,{size:"icon-xs",disabled:!n,onClick:()=>window.open(n,"_blank","noopener,noreferrer"),"aria-label":"Open preview in browser",children:t.jsx(Ne,{"data-icon":"inline-start"})})]})]}),t.jsx(ue,{children:z})]})})}),Z.length>0&&t.jsxs("div",{className:"flex shrink-0 items-center gap-1 overflow-x-auto px-2 pb-2",children:[t.jsx(Ie,{"aria-hidden":"true",className:"size-3.5 shrink-0 text-muted-foreground"}),Z.map(e=>t.jsxs(g,{variant:"outline",size:"xs",className:"font-mono text-xs",onClick:()=>U(B(e,N)),"aria-label":`Open ${N}:${e} preview`,children:[":",e]},e))]}),t.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-2 px-2 pb-2",children:[t.jsx(he,{"aria-label":"Preview viewport",value:[l],onValueChange:e=>{const r=e[0];r&&r in h&&te(r)},variant:"outline",size:"sm",spacing:0,children:Object.entries(h).map(([e,r])=>{const d=r.icon;return t.jsx(pe,{value:e,"aria-label":`${r.label} viewport`,title:r.width?`${r.label} · ${r.width}×${r.height}`:r.label,children:t.jsx(d,{})},e)})}),t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx(g,{variant:"ghost",size:"icon-sm",disabled:o<=E,onClick:()=>p(e=>Math.max(E,Number((e-I).toFixed(1)))),"aria-label":"Zoom preview out",title:"Zoom out",children:t.jsx(ze,{"data-icon":"inline-start"})}),t.jsxs(g,{variant:"ghost",size:"sm",onClick:()=>p(1),"aria-label":"Reset preview zoom",children:[Math.round(o*100),"%"]}),t.jsx(g,{variant:"ghost",size:"icon-sm",disabled:o>=k,onClick:()=>p(e=>Math.min(k,Number((e+I).toFixed(1)))),"aria-label":"Zoom preview in",title:"Zoom in",children:t.jsx(Re,{"data-icon":"inline-start"})})]})]}),t.jsx(K,{}),t.jsx("div",{className:"min-h-0 flex-1 overflow-auto bg-muted/30 p-3",children:n?t.jsx("div",{className:me("relative mx-auto overflow-hidden bg-white ring-1 ring-border",l==="responsive"&&"size-full"),style:l==="responsive"?void 0:{width:h[l].width*o,height:h[l].height*o},children:t.jsx("iframe",{title:"Development preview",src:n,className:"block border-0 bg-white",style:l==="responsive"?{width:`${100/o}%`,height:`${100/o}%`,transform:`scale(${o})`,transformOrigin:"top left"}:{width:h[l].width,height:h[l].height,transform:`scale(${o})`,transformOrigin:"top left"},sandbox:"allow-downloads allow-forms allow-modals allow-popups allow-same-origin allow-scripts",referrerPolicy:"no-referrer",onLoad:()=>C(!1)},`${n}-${J}`)}):t.jsx(fe,{className:"size-full",children:t.jsxs(xe,{children:[t.jsx(we,{variant:"icon",children:t.jsx(H,{})}),t.jsx(ve,{children:"No preview selected"}),t.jsx(ge,{children:"Start a local development server or enter its URL above. Detected ports appear automatically."})]})})})]})}export{Le as PreviewPanel,A as normalizePreviewUrl};
1
+ import{r as a,j as t}from"./vendor-react-gGw_S5I_.js";import{y as ne,B as g,l as K,z as ie,C as oe,m as le,n as ce,I as de,E as G,G as ue,T as he,H as pe,J as me,L as fe,M as xe,N as we,O as ve,Q as ge,R as be,U as je,w as b}from"./index-CYJLZdyZ.js";import{E as H,X as ye,a as Se,b as Ne,c as Ie,M as Ee,T as ke,d as Me,e as Pe,Z as ze,f as Re}from"./vendor-ui-Dxtv9P3W.js";import"./vendor-shiki-DOn6sF-i.js";import"./vendor-markdown-BE1gYnO9.js";const O=360,Ce=560,V="cogpit-preview-width",Y="cogpit-preview-viewport",_="cogpit-preview-zoom",E=.5,k=1.5,I=.1,h={responsive:{label:"Responsive",width:null,height:null,icon:Pe},phone:{label:"Phone",width:390,height:844,icon:Me},tablet:{label:"Tablet",width:768,height:1024,icon:ke},desktop:{label:"Desktop",width:1280,height:800,icon:Ee}};function Te(){try{const s=Number(localStorage.getItem(V));if(Number.isFinite(s)&&s>=O)return s}catch{}return Ce}function De(){try{const s=localStorage.getItem(Y);if(s&&s in h)return s}catch{}return"responsive"}function Oe(){try{const s=localStorage.getItem(_);if(s===null)return 1;const i=Number(s);if(Number.isFinite(i))return Math.min(k,Math.max(E,i))}catch{}return 1}function X(s){return be(`cogpit-preview-url:${s}`)}function A(s){const i=s.trim();if(!i||/^[a-z][a-z\d+.-]*:/i.test(i)&&!/^https?:\/\//i.test(i)&&!/^[^/]+:\d+(?:\/|$)/.test(i))return null;const j=/^https?:\/\//i.test(i)?i:`http://${i}`;try{const n=new URL(j);return n.protocol!=="http:"&&n.protocol!=="https:"?null:n.href}catch{return null}}function B(s,i){return`http://${i||"localhost"}:${s}/`}function Le({cwd:s,onClose:i}){const[M,j]=a.useState([]),[n,P]=a.useState(""),[W,y]=a.useState(""),[z,R]=a.useState(null),[J,Q]=a.useState(0),[q,C]=a.useState(!1),[S,ee]=a.useState(Te),[l,te]=a.useState(De),[o,p]=a.useState(Oe),c=a.useRef(null),$=a.useRef(null),T=a.useRef(null),{activeDevice:m}=ne(),N=(m==null?void 0:m.host)??(window.location.hostname||"localhost"),re=m==null?void 0:m.id;a.useEffect(()=>{let e="";try{e=localStorage.getItem(X(s))??""}catch{}const r=e?A(e)??"":"";P(r),y(r),R(null)},[s,re]),a.useEffect(()=>{let e=!1;async function r(){try{const u=await je(`/api/background-tasks?cwd=${encodeURIComponent(s)}`);if(e||!u.ok)return;const x=await u.json(),f=Array.isArray(x)?x:[];j(f);const L=f.flatMap(w=>w.ports.filter(v=>w.portStatus[v])).at(0);if(L){const w=B(L,N);P(v=>v||w),y(v=>v||w)}}catch{e||j([])}}r();const d=window.setInterval(r,1e4);return()=>{e=!0,window.clearInterval(d)}},[s,N]),a.useEffect(()=>{if(n)try{localStorage.setItem(X(s),n)}catch{}},[s,n]),a.useEffect(()=>{try{localStorage.setItem(Y,l),localStorage.setItem(_,String(o))}catch{}},[l,o]);const Z=a.useMemo(()=>[...new Set(M.flatMap(e=>e.ports.filter(r=>e.portStatus[r])))].sort((e,r)=>e-r),[M]),U=a.useCallback(e=>{const r=A(e);if(!r){R("Enter a valid HTTP or HTTPS URL.");return}R(null),P(r),y(r),C(!0)},[]),D=a.useCallback(()=>{n&&(C(!0),Q(e=>e+1))},[n]);a.useEffect(()=>{function e(r){var d,u,x;if((d=$.current)!=null&&d.contains(document.activeElement)){if(b("previewRefresh",r)){r.preventDefault(),D();return}if(b("previewFocusUrl",r)){r.preventDefault(),(u=T.current)==null||u.focus(),(x=T.current)==null||x.select();return}if(b("previewZoomIn",r)){r.preventDefault(),p(f=>Math.min(k,Number((f+I).toFixed(1))));return}if(b("previewZoomOut",r)){r.preventDefault(),p(f=>Math.max(E,Number((f-I).toFixed(1))));return}b("previewResetZoom",r)&&(r.preventDefault(),p(1))}}return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[D]);const se=a.useCallback(e=>{e.preventDefault(),c.current={startX:e.clientX,startWidth:S,currentWidth:S},e.currentTarget.setPointerCapture(e.pointerId)},[S]),ae=a.useCallback(e=>{if(!c.current)return;const r=Math.max(O,window.innerWidth*.7),d=c.current.startWidth+(c.current.startX-e.clientX),u=Math.min(r,Math.max(O,d));c.current.currentWidth=u,ee(u)},[]),F=a.useCallback(()=>{if(!c.current)return;const e=c.current.currentWidth;c.current=null;try{localStorage.setItem(V,String(e))}catch{}},[]);return t.jsxs("aside",{ref:$,"aria-label":"Development preview",className:"view-transition-right-panel panel-enter-right relative flex min-h-0 shrink-0 flex-col border-l bg-canvas",style:{width:S},children:[t.jsx("div",{"aria-hidden":"true",className:"absolute inset-y-0 left-0 w-1 cursor-col-resize hover:bg-primary/30",onPointerDown:se,onPointerMove:ae,onPointerUp:F,onPointerCancel:F}),t.jsxs("div",{className:"flex h-10 shrink-0 items-center gap-2 px-3",children:[t.jsx(H,{"aria-hidden":"true",className:"size-4 text-muted-foreground"}),t.jsx("h2",{className:"text-sm font-medium",children:"Preview"}),t.jsx("span",{className:"flex-1"}),t.jsx(g,{variant:"ghost",size:"icon-sm",onClick:i,"aria-label":"Close preview",children:t.jsx(ye,{"data-icon":"inline-start"})})]}),t.jsx(K,{}),t.jsx("form",{className:"p-2",onSubmit:e=>{e.preventDefault(),U(W)},children:t.jsx(ie,{className:"gap-2",children:t.jsxs(oe,{"data-invalid":!!z,children:[t.jsxs(le,{children:[t.jsx(ce,{ref:T,"aria-label":"Preview URL","aria-invalid":!!z,value:W,onChange:e=>y(e.target.value),placeholder:"localhost:3000",spellCheck:!1}),t.jsxs(de,{align:"inline-end",children:[t.jsx(G,{size:"icon-xs",disabled:!n,onClick:D,"aria-label":"Refresh preview",children:t.jsx(Se,{"data-icon":"inline-start",className:q?"animate-spin":void 0})}),t.jsx(G,{size:"icon-xs",disabled:!n,onClick:()=>window.open(n,"_blank","noopener,noreferrer"),"aria-label":"Open preview in browser",children:t.jsx(Ne,{"data-icon":"inline-start"})})]})]}),t.jsx(ue,{children:z})]})})}),Z.length>0&&t.jsxs("div",{className:"flex shrink-0 items-center gap-1 overflow-x-auto px-2 pb-2",children:[t.jsx(Ie,{"aria-hidden":"true",className:"size-3.5 shrink-0 text-muted-foreground"}),Z.map(e=>t.jsxs(g,{variant:"outline",size:"xs",className:"font-mono text-xs",onClick:()=>U(B(e,N)),"aria-label":`Open ${N}:${e} preview`,children:[":",e]},e))]}),t.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-2 px-2 pb-2",children:[t.jsx(he,{"aria-label":"Preview viewport",value:[l],onValueChange:e=>{const r=e[0];r&&r in h&&te(r)},variant:"outline",size:"sm",spacing:0,children:Object.entries(h).map(([e,r])=>{const d=r.icon;return t.jsx(pe,{value:e,"aria-label":`${r.label} viewport`,title:r.width?`${r.label} · ${r.width}×${r.height}`:r.label,children:t.jsx(d,{})},e)})}),t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx(g,{variant:"ghost",size:"icon-sm",disabled:o<=E,onClick:()=>p(e=>Math.max(E,Number((e-I).toFixed(1)))),"aria-label":"Zoom preview out",title:"Zoom out",children:t.jsx(ze,{"data-icon":"inline-start"})}),t.jsxs(g,{variant:"ghost",size:"sm",onClick:()=>p(1),"aria-label":"Reset preview zoom",children:[Math.round(o*100),"%"]}),t.jsx(g,{variant:"ghost",size:"icon-sm",disabled:o>=k,onClick:()=>p(e=>Math.min(k,Number((e+I).toFixed(1)))),"aria-label":"Zoom preview in",title:"Zoom in",children:t.jsx(Re,{"data-icon":"inline-start"})})]})]}),t.jsx(K,{}),t.jsx("div",{className:"min-h-0 flex-1 overflow-auto bg-muted/30 p-3",children:n?t.jsx("div",{className:me("relative mx-auto overflow-hidden bg-white ring-1 ring-border",l==="responsive"&&"size-full"),style:l==="responsive"?void 0:{width:h[l].width*o,height:h[l].height*o},children:t.jsx("iframe",{title:"Development preview",src:n,className:"block border-0 bg-white",style:l==="responsive"?{width:`${100/o}%`,height:`${100/o}%`,transform:`scale(${o})`,transformOrigin:"top left"}:{width:h[l].width,height:h[l].height,transform:`scale(${o})`,transformOrigin:"top left"},sandbox:"allow-downloads allow-forms allow-modals allow-popups allow-same-origin allow-scripts",referrerPolicy:"no-referrer",onLoad:()=>C(!1)},`${n}-${J}`)}):t.jsx(fe,{className:"size-full",children:t.jsxs(xe,{children:[t.jsx(we,{variant:"icon",children:t.jsx(H,{})}),t.jsx(ve,{children:"No preview selected"}),t.jsx(ge,{children:"Start a local development server or enter its URL above. Detected ports appear automatically."})]})})})]})}export{Le as PreviewPanel,A as normalizePreviewUrl};
@@ -1,4 +1,4 @@
1
- import{r as l,j as t,c as Ae}from"./vendor-react-gGw_S5I_.js";import{L as Q,M as J,N as X,O as Y,Q as q,U as ae,J as ie,aA as ot,af as je,B as A,aB as Ct,aC as kt,aD as Et,aE as Rt,l as xe,Z as le,m as Dt,I as Ft,n as Lt,T as nt,H as he,q as Tt,a1 as Mt,aF as It,aG as $t,D as zt,h as At,i as Ut,j as Ot,k as Pt,aH as Gt,aI as Bt,a3 as Ht,a4 as Kt,a5 as Vt,a7 as Qt,a8 as Jt,a9 as Xt,aa as Yt,ab as qt,w as Wt}from"./index-DsnL-sXV.js";import{H as Zt}from"./HighlightedEditor-DWc-xoSc.js";import{J as ge,o as ze,l as _t,N as es,C as ts,X as ss,G as ns,S as ls,a as lt,O as as,Q as at,U as is,F as Ie}from"./vendor-ui-Br3ZTAXZ.js";import{M as rs}from"./vendor-markdown-BE1gYnO9.js";import"./vendor-shiki-DOn6sF-i.js";const os=12,ct="h-6 w-full justify-start gap-1 rounded-none px-2 text-left font-normal";function Se(n,e){return{paddingLeft:8+n*os+(e?0:16)}}function cs(n){const e=n;return typeof e=="object"&&e!==null&&typeof e.name=="string"&&(e.type==="file"||e.type==="directory")}function ds(n){const e=n==null?void 0:n.entries;return Array.isArray(e)?e.filter(cs):[]}async function it(n,e,r){try{const o=await ae(`/api/project-files/tree?cwd=${encodeURIComponent(n)}&dir=${encodeURIComponent(e)}${r?"&refresh=1":""}`);if(!o.ok){const u=await o.json().catch(()=>null),f=u==null?void 0:u.error;throw new Error(typeof f=="string"?f:"Unable to list directory")}const c=await o.json();return{status:"ready",entries:ds(c),scanLimited:c.scanLimited===!0}}catch(o){return{status:"error",message:o instanceof Error?o.message:"Unable to list directory"}}}function fs(n){const e=n.split("/");return e.slice(0,-1).map((r,o)=>e.slice(0,o+1).join("/"))}function us({cwd:n,selectedPath:e,onSelect:r,fileStatus:o,reloadToken:c}){const[u,f]=l.useState(()=>new Map),[g,S]=l.useState(()=>new Set),b=l.useRef(new Set),R=l.useRef(n);R.current=n;const m=l.useCallback(async x=>{if(b.current.has(x))return;b.current.add(x),f(y=>new Map(y).set(x,{status:"loading"}));const w=await it(n,x,!1);b.current.delete(x),R.current===n&&f(y=>new Map(y).set(x,w))},[n]),h=l.useRef(null);l.useEffect(()=>{const x=h.current===n;h.current=n,x||S(new Set),f(new Map([["",{status:"loading"}]]));let w=!1;return it(n,"",x).then(y=>{w||f(new Map([["",y]]))}),()=>{w=!0}},[n,c]),l.useEffect(()=>{if(!e)return;const x=fs(e);x.length!==0&&S(w=>{if(x.every(D=>w.has(D)))return w;const y=new Set(w);for(const D of x)y.add(D);return y})},[e]);const N=l.useCallback(x=>{S(w=>{const y=new Set(w);return y.has(x)?y.delete(x):y.add(x),y})},[]),j=u.get(""),k=ms(j);return t.jsxs("div",{"aria-label":"Project file tree",className:"flex flex-col py-1",children:[k?t.jsx(Q,{className:"min-h-48 rounded-none p-4",children:t.jsxs(J,{children:[t.jsx(X,{variant:"icon",children:t.jsx(k.Icon,{})}),t.jsx(Y,{children:k.title}),t.jsx(q,{children:k.description})]})}):t.jsx(dt,{directory:"",depth:0,state:j,directories:u,expanded:g,selectedPath:e,onSelect:r,onToggle:N,onLoad:m,fileStatus:o}),(j==null?void 0:j.status)==="ready"&&j.scanLimited&&t.jsx("p",{className:"px-3 py-2 text-xs text-muted-foreground",children:"This project is too large to scan completely."})]})}function ms(n){return(n==null?void 0:n.status)==="error"?{Icon:ge,title:"Could not load files",description:n.message}:(n==null?void 0:n.status)==="ready"&&n.entries.length===0?{Icon:ze,title:"No files",description:"This project has no files to show."}:null}function dt(n){const e=Ae.c(22),{directory:r,depth:o,state:c,onLoad:u,...f}=n;let g,S;if(e[0]!==r||e[1]!==u||e[2]!==c?(g=()=>{c===void 0&&r!==""&&u(r)},S=[r,u,c],e[0]=r,e[1]=u,e[2]=c,e[3]=g,e[4]=S):(g=e[3],S=e[4]),l.useEffect(g,S),!c||c.status==="loading"){let m;e[5]!==o?(m=Se(o,!1),e[5]=o,e[6]=m):m=e[6];let h;e[7]===Symbol.for("react.memo_cache_sentinel")?(h=t.jsx(je,{className:"size-3"}),e[7]=h):h=e[7];const N=r===""&&"Loading files…";let j;return e[8]!==m||e[9]!==N?(j=t.jsxs("div",{role:"status",className:"flex h-6 items-center gap-2 text-xs text-muted-foreground",style:m,children:[h,N]}),e[8]=m,e[9]=N,e[10]=j):j=e[10],j}if(c.status==="error"){let m;e[11]!==o?(m=Se(o,!1),e[11]=o,e[12]=m):m=e[12];let h;e[13]===Symbol.for("react.memo_cache_sentinel")?(h=t.jsx(ge,{"aria-hidden":"true",className:"size-3 shrink-0"}),e[13]=h):h=e[13];let N;e[14]!==c.message?(N=t.jsx("span",{className:"truncate",children:c.message}),e[14]=c.message,e[15]=N):N=e[15];let j;return e[16]!==c.message||e[17]!==m||e[18]!==N?(j=t.jsxs("div",{role:"alert",className:"flex h-6 items-center gap-1.5 truncate text-xs text-destructive",style:m,title:c.message,children:[h,N]}),e[16]=c.message,e[17]=m,e[18]=N,e[19]=j):j=e[19],j}const b=c.entries.map(m=>{const h=r?`${r}/${m.name}`:m.name;return m.type==="directory"?t.jsx(xs,{path:h,name:m.name,depth:o,onLoad:u,...f},h):t.jsx(hs,{path:h,name:m.name,depth:o,selected:f.selectedPath===h,status:f.fileStatus(h),onSelect:f.onSelect},h)});let R;return e[20]!==b?(R=t.jsx(t.Fragment,{children:b}),e[20]=b,e[21]=R):R=e[21],R}function xs(n){const e=Ae.c(48);let r,o,c,u,f,g,S,b,R,m,h,N,j,k,x,w,y;e[0]!==n?({path:S,name:f,depth:u,...b}=n,g=b.expanded.has(S),r=g?_t:es,c=A,h="ghost",N="sm",j=g,k=ct,e[18]!==u?(x=Se(u,!0),e[18]=u,e[19]=x):x=e[19],w=()=>b.onToggle(S),y=S,o=ts,R="true",m=ie("size-3 shrink-0 text-muted-foreground transition-transform",g&&"rotate-90"),e[0]=n,e[1]=r,e[2]=o,e[3]=c,e[4]=u,e[5]=f,e[6]=g,e[7]=S,e[8]=b,e[9]=R,e[10]=m,e[11]=h,e[12]=N,e[13]=j,e[14]=k,e[15]=x,e[16]=w,e[17]=y):(r=e[1],o=e[2],c=e[3],u=e[4],f=e[5],g=e[6],S=e[7],b=e[8],R=e[9],m=e[10],h=e[11],N=e[12],j=e[13],k=e[14],x=e[15],w=e[16],y=e[17]);let D;e[20]!==o||e[21]!==R||e[22]!==m?(D=t.jsx(o,{"aria-hidden":R,className:m}),e[20]=o,e[21]=R,e[22]=m,e[23]=D):D=e[23];let L;e[24]!==r?(L=t.jsx(r,{"aria-hidden":"true",className:"size-3.5 shrink-0 text-muted-foreground"}),e[24]=r,e[25]=L):L=e[25];let F;e[26]!==f?(F=t.jsx("span",{className:"min-w-0 flex-1 truncate text-xs",children:f}),e[26]=f,e[27]=F):F=e[27];let i;e[28]!==c||e[29]!==D||e[30]!==L||e[31]!==F||e[32]!==h||e[33]!==N||e[34]!==j||e[35]!==k||e[36]!==x||e[37]!==w||e[38]!==y?(i=t.jsxs(c,{variant:h,size:N,"aria-expanded":j,className:k,style:x,onClick:w,title:y,children:[D,L,F]}),e[28]=c,e[29]=D,e[30]=L,e[31]=F,e[32]=h,e[33]=N,e[34]=j,e[35]=k,e[36]=x,e[37]=w,e[38]=y,e[39]=i):i=e[39];let T;e[40]!==u||e[41]!==g||e[42]!==S||e[43]!==b?(T=g&&t.jsx("div",{children:t.jsx(dt,{directory:S,depth:u+1,state:b.directories.get(S),...b})}),e[40]=u,e[41]=g,e[42]=S,e[43]=b,e[44]=T):T=e[44];let U;return e[45]!==i||e[46]!==T?(U=t.jsxs("div",{children:[i,T]}),e[45]=i,e[46]=T,e[47]=U):U=e[47],U}function hs(n){const e=Ae.c(28),{path:r,name:o,depth:c,selected:u,status:f,onSelect:g}=n,S=l.useRef(null);let b;e[0]!==r?(b=ot(r),e[0]=r,e[1]=b):b=e[1];const R=b;let m,h;e[2]!==u?(m=()=>{var T,U;u&&((U=(T=S.current)==null?void 0:T.scrollIntoView)==null||U.call(T,{block:"nearest"}))},h=[u],e[2]=u,e[3]=m,e[4]=h):(m=e[3],h=e[4]),l.useEffect(m,h);const N=u||void 0,j=u?"secondary":"ghost";let k;e[5]!==c?(k=Se(c,!1),e[5]=c,e[6]=k):k=e[6];let x;e[7]!==g||e[8]!==r?(x=()=>g(r),e[7]=g,e[8]=r,e[9]=x):x=e[9];let w;e[10]!==R?(w=t.jsx(R,{"aria-hidden":"true",className:"size-3.5 shrink-0 text-muted-foreground"}),e[10]=R,e[11]=w):w=e[11];const y=f&&f.className;let D;e[12]!==y?(D=ie("min-w-0 flex-1 truncate text-xs",y),e[12]=y,e[13]=D):D=e[13];let L;e[14]!==o||e[15]!==D?(L=t.jsx("span",{className:D,children:o}),e[14]=o,e[15]=D,e[16]=L):L=e[16];let F;e[17]!==f?(F=f&&t.jsx("span",{className:ie("shrink-0 font-mono text-[10px]",f.className),title:f.label,children:f.code}),e[17]=f,e[18]=F):F=e[18];let i;return e[19]!==r||e[20]!==L||e[21]!==F||e[22]!==N||e[23]!==j||e[24]!==k||e[25]!==x||e[26]!==w?(i=t.jsxs(A,{ref:S,"aria-current":N,variant:j,size:"sm",className:ct,style:k,onClick:x,title:r,children:[w,L,F]}),e[19]=r,e[20]=L,e[21]=F,e[22]=N,e[23]=j,e[24]=k,e[25]=x,e[26]=w,e[27]=i):i=e[27],i}const ps={"?":{label:"Untracked",className:"text-info"},A:{label:"Added",className:"text-success"},M:{label:"Modified",className:"text-warning"},D:{label:"Deleted",className:"text-destructive"},R:{label:"Renamed",className:"text-info"},C:{label:"Copied",className:"text-info"},U:{label:"Conflicted",className:"text-destructive"}};function $e(n){const e=n.workTreeStatus.trim()||n.indexStatus.trim();return ps[e]??{label:"Changed",className:"text-muted-foreground"}}function js(n){return`${n.indexStatus}${n.workTreeStatus}`.trim()||"?"}const gs=new Set([".md",".mdx",".markdown"]);function rt(n){const e=n.lastIndexOf(".");return e!==-1&&gs.has(n.slice(e).toLowerCase())}function ws(n,e,r){if(!n||/^(?:[a-z]+:|\/|#)/i.test(n))return n;const o=r.includes("/")?r.slice(0,r.lastIndexOf("/")):"",c=[];for(const f of[...o.split("/"),...n.split("/")])f===".."?c.pop():f&&f!=="."&&c.push(f);const u=e.includes("\\")?"\\":"/";return[e.replace(/[\\/]+$/,""),...c].join(u)}async function pe(n,e){try{const r=await n.json();if(r&&typeof r=="object"&&typeof r.error=="string")return r.error}catch{}return e}function vs(n){return n<1024?`${n} B`:`${(n/1024).toFixed(n<10*1024?1:0)} KB`}function ys(n,e){let r=0;for(let o=1;o<e;o+=1){const c=n.indexOf(`
2
- `,r);if(c<0)return r;r=c+1}return r}function Rs({cwd:n,onClose:e,onAddToPrompt:r,openRequest:o}){const c=l.useRef(null),u=l.useRef(null),f=l.useRef(null),[g,S]=l.useState(""),[b,R]=l.useState([]),[m,h]=l.useState(!0),[N,j]=l.useState(null),[k,x]=l.useState(0),[w,y]=l.useState(!1),[D,L]=l.useState(0),F=l.useRef(!1),[i,T]=l.useState(null),[U,Ce]=l.useState(!0),[M,W]=l.useState(""),[ft,re]=l.useState(""),[O,oe]=l.useState(null),[ut,Ue]=l.useState(0),[H,Oe]=l.useState(!1),[Z,Pe]=l.useState(!1),[Ge,_]=l.useState(null),[mt,ee]=l.useState(!1),[I,ke]=l.useState("all"),[v,Be]=l.useState(null),[He,Ke]=l.useState(!1),[xt,Ve]=l.useState(null),[C,ce]=l.useState("edit"),[E,we]=l.useState(null),[de,Qe]=l.useState(!1),[Je,Ee]=l.useState(null),[fe,K]=l.useState(null),[P,ve]=l.useState(null),[ye,Re]=l.useState(""),[B,ue]=l.useState(null),$=i!==null&&M!==ft,z=l.useMemo(()=>new Map(((v==null?void 0:v.files)??[]).flatMap(s=>[[s.path,s],...s.originalPath?[[s.originalPath,s]]:[]])),[v==null?void 0:v.files]),te=l.useCallback(async()=>{Ke(!0),Ve(null);try{const s=await ae(`/api/git-status?cwd=${encodeURIComponent(n)}`);if(!s.ok)throw new Error(await pe(s,"Unable to read git status"));const a=await s.json();Be(a),a.isRepository||ke("all")}catch(s){Be(null),ke("all"),Ve(s instanceof Error?s.message:"Unable to read git status")}finally{Ke(!1)}},[n]);l.useEffect(()=>{te()},[te]);const De=I==="all"&&g.trim()==="";l.useEffect(()=>{if(De)return;const s=new AbortController,a=window.setTimeout(async()=>{h(!0),j(null);const d=F.current;F.current=!1;try{const p=await ae(`/api/project-files?cwd=${encodeURIComponent(n)}&q=${encodeURIComponent(g)}&limit=100${d?"&refresh=1":""}`,{signal:s.signal});if(!p.ok)throw new Error(await pe(p,"Unable to list project files"));const G=await p.json();if(s.signal.aborted)return;const tt=Ct(G),st=G.totalMatches;R(tt),x(typeof st=="number"?st:tt.length),y(G.scanLimited===!0)}catch(p){s.signal.aborted||(R([]),j(p instanceof Error?p.message:"Unable to list project files"))}finally{s.signal.aborted||h(!1)}},120);return()=>{window.clearTimeout(a),s.abort()}},[n,g,D,De]),l.useEffect(()=>{T(null),W(""),re(""),oe(null),_(null),K(null),ce("edit"),we(null),Ee(null),ue(null)},[n]),l.useEffect(()=>{if(!$)return;const s=a=>a.preventDefault();return window.addEventListener("beforeunload",s),()=>window.removeEventListener("beforeunload",s)},[$]);const ht=l.useCallback((s,a)=>{const d=u.current;if(!d)return;if(!a||a<1){d.focus();return}const p=ys(s,a);d.blur(),d.setSelectionRange(p,p),d.focus()},[]);l.useEffect(()=>{const s=f.current;!s||!u.current||(f.current=null,ht(s.text,s.line))});const se=l.useCallback(async(s,a)=>{Oe(!0),_(null),ee(!1),K(null);try{const d=await ae(`/api/project-file?cwd=${encodeURIComponent(n)}&path=${encodeURIComponent(s)}`);if(!d.ok)throw new Error(await pe(d,"Unable to open file"));const p=await d.json();W(p.content),re(p.content),oe(p.mtimeMs),Ue(p.size),f.current={text:p.content,line:a}}catch(d){W(""),re(""),oe(null),_(d instanceof Error?d.message:"Unable to open file")}finally{Oe(!1)}},[n]),ne=l.useCallback(async(s,a)=>{Qe(!0),Ee(null),we(null);try{const d=a?`&originalPath=${encodeURIComponent(a)}`:"",p=await ae(`/api/git-diff?cwd=${encodeURIComponent(n)}&path=${encodeURIComponent(s)}${d}`);if(!p.ok)throw new Error(await pe(p,"Unable to diff file"));we(await p.json())}catch(d){Ee(d instanceof Error?d.message:"Unable to diff file")}finally{Qe(!1)}},[n]),be=l.useCallback(({path:s,mode:a,line:d})=>{var p;if(T(s),Ce(!1),a==="edit"){ce(rt(s)&&!d?"preview":"edit"),se(s,d);return}ce(a),W(""),re(""),oe(null),_(null),ee(!1),K(null),ne(s,(p=z.get(s))==null?void 0:p.originalPath)},[z,ne,se]),Ne=l.useCallback(s=>{if($){ue({type:"file",target:s});return}be(s)},[$,be]),Xe=l.useCallback(s=>{if(s===i){Ce(!1);return}const a=I==="changes"&&z.has(s)?"diff":"edit";Ne({path:s,mode:a})},[z,I,Ne,i]),Ye=l.useRef(0);l.useEffect(()=>{!o||o.token===Ye.current||(Ye.current=o.token,Ne({path:o.file,mode:o.mode,line:o.line}))},[o,Ne]);const pt=l.useCallback(()=>{var s;!i||C==="diff"||(ce("diff"),(E==null?void 0:E.path)!==i&&!de&&ne(i,(s=z.get(i))==null?void 0:s.originalPath))},[z,E==null?void 0:E.path,de,ne,i,C]),jt=l.useCallback(s=>{!i||C===s||(ce(s),O===null&&!H&&se(i))},[H,se,O,i,C]),Fe=l.useCallback(()=>{var s;if(i){if(C==="diff"){ne(i,(s=z.get(i))==null?void 0:s.originalPath);return}se(i)}},[z,ne,se,i,C]),gt=l.useCallback(()=>{F.current=!0,L(s=>s+1),te(),C==="diff"&&Fe()},[te,Fe,C]),Le=l.useCallback(async()=>{if(!(!i||O===null||!$||Z)){Pe(!0),_(null),ee(!1);try{const s=await ae("/api/project-file",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:n,path:i,content:M,expectedMtimeMs:O})});if(!s.ok)throw new Error(await pe(s,"Unable to save file"));const a=await s.json();re(M),oe(a.mtimeMs),Ue(a.size),ee(!0),we(null),te()}catch(s){_(s instanceof Error?s.message:"Unable to save file")}finally{Pe(!1)}}},[M,n,$,te,O,Z,i]);l.useEffect(()=>{function s(a){var d;(d=c.current)!=null&&d.contains(document.activeElement)&&Wt("projectFileSave",a)&&(a.preventDefault(),Le())}return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[Le]);const wt=l.useCallback(()=>{if($){ue({type:"close"});return}e()},[$,e]),vt=l.useCallback(()=>{if(!B)return;const s=B;if(ue(null),s.type==="file"){be(s.target);return}e()},[e,be,B]),yt=l.useCallback(s=>{if(s.key!=="Tab")return;s.preventDefault();const a=s.currentTarget,d=a.selectionStart,p=a.selectionEnd,G=`${M.slice(0,d)} ${M.slice(p)}`;W(G),ee(!1),K(null),requestAnimationFrame(()=>{a.selectionStart=d+2,a.selectionEnd=d+2})},[M]),bt=l.useCallback(s=>{const a=s.currentTarget;if(a.selectionStart===a.selectionEnd){K(null);return}const d=M.slice(a.selectionStart,a.selectionEnd),p=M.slice(0,a.selectionStart).split(`
1
+ import{r as l,j as t,c as Ae}from"./vendor-react-gGw_S5I_.js";import{L as J,M as Q,N as X,O as Y,Q as q,U as ae,J as ie,aC as ot,ag as je,B as A,aD as Ct,aE as kt,aF as Et,aG as Rt,l as xe,Z as le,m as Dt,I as Ft,n as Lt,T as nt,H as he,q as Tt,a2 as Mt,aH as It,aI as $t,D as zt,h as At,i as Ut,j as Ot,k as Pt,aJ as Gt,aK as Bt,a4 as Kt,a5 as Ht,a6 as Vt,a8 as Jt,a9 as Qt,aa as Xt,ab as Yt,ac as qt,w as Wt}from"./index-CYJLZdyZ.js";import{H as Zt}from"./HighlightedEditor-Cz0PCIaA.js";import{J as ge,o as ze,l as _t,N as es,C as ts,X as ss,G as ns,S as ls,a as lt,O as as,Q as at,U as is,F as Ie}from"./vendor-ui-Dxtv9P3W.js";import{M as rs}from"./vendor-markdown-BE1gYnO9.js";import"./vendor-shiki-DOn6sF-i.js";const os=12,ct="h-6 w-full justify-start gap-1 rounded-none px-2 text-left font-normal";function Se(n,e){return{paddingLeft:8+n*os+(e?0:16)}}function cs(n){const e=n;return typeof e=="object"&&e!==null&&typeof e.name=="string"&&(e.type==="file"||e.type==="directory")}function ds(n){const e=n==null?void 0:n.entries;return Array.isArray(e)?e.filter(cs):[]}async function it(n,e,r){try{const o=await ae(`/api/project-files/tree?cwd=${encodeURIComponent(n)}&dir=${encodeURIComponent(e)}${r?"&refresh=1":""}`);if(!o.ok){const u=await o.json().catch(()=>null),f=u==null?void 0:u.error;throw new Error(typeof f=="string"?f:"Unable to list directory")}const c=await o.json();return{status:"ready",entries:ds(c),scanLimited:c.scanLimited===!0}}catch(o){return{status:"error",message:o instanceof Error?o.message:"Unable to list directory"}}}function fs(n){const e=n.split("/");return e.slice(0,-1).map((r,o)=>e.slice(0,o+1).join("/"))}function us({cwd:n,selectedPath:e,onSelect:r,fileStatus:o,reloadToken:c}){const[u,f]=l.useState(()=>new Map),[g,S]=l.useState(()=>new Set),b=l.useRef(new Set),R=l.useRef(n);R.current=n;const m=l.useCallback(async x=>{if(b.current.has(x))return;b.current.add(x),f(y=>new Map(y).set(x,{status:"loading"}));const w=await it(n,x,!1);b.current.delete(x),R.current===n&&f(y=>new Map(y).set(x,w))},[n]),h=l.useRef(null);l.useEffect(()=>{const x=h.current===n;h.current=n,x||S(new Set),f(new Map([["",{status:"loading"}]]));let w=!1;return it(n,"",x).then(y=>{w||f(new Map([["",y]]))}),()=>{w=!0}},[n,c]),l.useEffect(()=>{if(!e)return;const x=fs(e);x.length!==0&&S(w=>{if(x.every(D=>w.has(D)))return w;const y=new Set(w);for(const D of x)y.add(D);return y})},[e]);const N=l.useCallback(x=>{S(w=>{const y=new Set(w);return y.has(x)?y.delete(x):y.add(x),y})},[]),j=u.get(""),k=ms(j);return t.jsxs("div",{"aria-label":"Project file tree",className:"flex flex-col py-1",children:[k?t.jsx(J,{className:"min-h-48 rounded-none p-4",children:t.jsxs(Q,{children:[t.jsx(X,{variant:"icon",children:t.jsx(k.Icon,{})}),t.jsx(Y,{children:k.title}),t.jsx(q,{children:k.description})]})}):t.jsx(dt,{directory:"",depth:0,state:j,directories:u,expanded:g,selectedPath:e,onSelect:r,onToggle:N,onLoad:m,fileStatus:o}),(j==null?void 0:j.status)==="ready"&&j.scanLimited&&t.jsx("p",{className:"px-3 py-2 text-xs text-muted-foreground",children:"This project is too large to scan completely."})]})}function ms(n){return(n==null?void 0:n.status)==="error"?{Icon:ge,title:"Could not load files",description:n.message}:(n==null?void 0:n.status)==="ready"&&n.entries.length===0?{Icon:ze,title:"No files",description:"This project has no files to show."}:null}function dt(n){const e=Ae.c(22),{directory:r,depth:o,state:c,onLoad:u,...f}=n;let g,S;if(e[0]!==r||e[1]!==u||e[2]!==c?(g=()=>{c===void 0&&r!==""&&u(r)},S=[r,u,c],e[0]=r,e[1]=u,e[2]=c,e[3]=g,e[4]=S):(g=e[3],S=e[4]),l.useEffect(g,S),!c||c.status==="loading"){let m;e[5]!==o?(m=Se(o,!1),e[5]=o,e[6]=m):m=e[6];let h;e[7]===Symbol.for("react.memo_cache_sentinel")?(h=t.jsx(je,{className:"size-3"}),e[7]=h):h=e[7];const N=r===""&&"Loading files…";let j;return e[8]!==m||e[9]!==N?(j=t.jsxs("div",{role:"status",className:"flex h-6 items-center gap-2 text-xs text-muted-foreground",style:m,children:[h,N]}),e[8]=m,e[9]=N,e[10]=j):j=e[10],j}if(c.status==="error"){let m;e[11]!==o?(m=Se(o,!1),e[11]=o,e[12]=m):m=e[12];let h;e[13]===Symbol.for("react.memo_cache_sentinel")?(h=t.jsx(ge,{"aria-hidden":"true",className:"size-3 shrink-0"}),e[13]=h):h=e[13];let N;e[14]!==c.message?(N=t.jsx("span",{className:"truncate",children:c.message}),e[14]=c.message,e[15]=N):N=e[15];let j;return e[16]!==c.message||e[17]!==m||e[18]!==N?(j=t.jsxs("div",{role:"alert",className:"flex h-6 items-center gap-1.5 truncate text-xs text-destructive",style:m,title:c.message,children:[h,N]}),e[16]=c.message,e[17]=m,e[18]=N,e[19]=j):j=e[19],j}const b=c.entries.map(m=>{const h=r?`${r}/${m.name}`:m.name;return m.type==="directory"?t.jsx(xs,{path:h,name:m.name,depth:o,onLoad:u,...f},h):t.jsx(hs,{path:h,name:m.name,depth:o,selected:f.selectedPath===h,status:f.fileStatus(h),onSelect:f.onSelect},h)});let R;return e[20]!==b?(R=t.jsx(t.Fragment,{children:b}),e[20]=b,e[21]=R):R=e[21],R}function xs(n){const e=Ae.c(48);let r,o,c,u,f,g,S,b,R,m,h,N,j,k,x,w,y;e[0]!==n?({path:S,name:f,depth:u,...b}=n,g=b.expanded.has(S),r=g?_t:es,c=A,h="ghost",N="sm",j=g,k=ct,e[18]!==u?(x=Se(u,!0),e[18]=u,e[19]=x):x=e[19],w=()=>b.onToggle(S),y=S,o=ts,R="true",m=ie("size-3 shrink-0 text-muted-foreground transition-transform",g&&"rotate-90"),e[0]=n,e[1]=r,e[2]=o,e[3]=c,e[4]=u,e[5]=f,e[6]=g,e[7]=S,e[8]=b,e[9]=R,e[10]=m,e[11]=h,e[12]=N,e[13]=j,e[14]=k,e[15]=x,e[16]=w,e[17]=y):(r=e[1],o=e[2],c=e[3],u=e[4],f=e[5],g=e[6],S=e[7],b=e[8],R=e[9],m=e[10],h=e[11],N=e[12],j=e[13],k=e[14],x=e[15],w=e[16],y=e[17]);let D;e[20]!==o||e[21]!==R||e[22]!==m?(D=t.jsx(o,{"aria-hidden":R,className:m}),e[20]=o,e[21]=R,e[22]=m,e[23]=D):D=e[23];let L;e[24]!==r?(L=t.jsx(r,{"aria-hidden":"true",className:"size-3.5 shrink-0 text-muted-foreground"}),e[24]=r,e[25]=L):L=e[25];let F;e[26]!==f?(F=t.jsx("span",{className:"min-w-0 flex-1 truncate text-xs",children:f}),e[26]=f,e[27]=F):F=e[27];let i;e[28]!==c||e[29]!==D||e[30]!==L||e[31]!==F||e[32]!==h||e[33]!==N||e[34]!==j||e[35]!==k||e[36]!==x||e[37]!==w||e[38]!==y?(i=t.jsxs(c,{variant:h,size:N,"aria-expanded":j,className:k,style:x,onClick:w,title:y,children:[D,L,F]}),e[28]=c,e[29]=D,e[30]=L,e[31]=F,e[32]=h,e[33]=N,e[34]=j,e[35]=k,e[36]=x,e[37]=w,e[38]=y,e[39]=i):i=e[39];let T;e[40]!==u||e[41]!==g||e[42]!==S||e[43]!==b?(T=g&&t.jsx("div",{children:t.jsx(dt,{directory:S,depth:u+1,state:b.directories.get(S),...b})}),e[40]=u,e[41]=g,e[42]=S,e[43]=b,e[44]=T):T=e[44];let U;return e[45]!==i||e[46]!==T?(U=t.jsxs("div",{children:[i,T]}),e[45]=i,e[46]=T,e[47]=U):U=e[47],U}function hs(n){const e=Ae.c(28),{path:r,name:o,depth:c,selected:u,status:f,onSelect:g}=n,S=l.useRef(null);let b;e[0]!==r?(b=ot(r),e[0]=r,e[1]=b):b=e[1];const R=b;let m,h;e[2]!==u?(m=()=>{var T,U;u&&((U=(T=S.current)==null?void 0:T.scrollIntoView)==null||U.call(T,{block:"nearest"}))},h=[u],e[2]=u,e[3]=m,e[4]=h):(m=e[3],h=e[4]),l.useEffect(m,h);const N=u||void 0,j=u?"secondary":"ghost";let k;e[5]!==c?(k=Se(c,!1),e[5]=c,e[6]=k):k=e[6];let x;e[7]!==g||e[8]!==r?(x=()=>g(r),e[7]=g,e[8]=r,e[9]=x):x=e[9];let w;e[10]!==R?(w=t.jsx(R,{"aria-hidden":"true",className:"size-3.5 shrink-0 text-muted-foreground"}),e[10]=R,e[11]=w):w=e[11];const y=f&&f.className;let D;e[12]!==y?(D=ie("min-w-0 flex-1 truncate text-xs",y),e[12]=y,e[13]=D):D=e[13];let L;e[14]!==o||e[15]!==D?(L=t.jsx("span",{className:D,children:o}),e[14]=o,e[15]=D,e[16]=L):L=e[16];let F;e[17]!==f?(F=f&&t.jsx("span",{className:ie("shrink-0 font-mono text-[10px]",f.className),title:f.label,children:f.code}),e[17]=f,e[18]=F):F=e[18];let i;return e[19]!==r||e[20]!==L||e[21]!==F||e[22]!==N||e[23]!==j||e[24]!==k||e[25]!==x||e[26]!==w?(i=t.jsxs(A,{ref:S,"aria-current":N,variant:j,size:"sm",className:ct,style:k,onClick:x,title:r,children:[w,L,F]}),e[19]=r,e[20]=L,e[21]=F,e[22]=N,e[23]=j,e[24]=k,e[25]=x,e[26]=w,e[27]=i):i=e[27],i}const ps={"?":{label:"Untracked",className:"text-info"},A:{label:"Added",className:"text-success"},M:{label:"Modified",className:"text-warning"},D:{label:"Deleted",className:"text-destructive"},R:{label:"Renamed",className:"text-info"},C:{label:"Copied",className:"text-info"},U:{label:"Conflicted",className:"text-destructive"}};function $e(n){const e=n.workTreeStatus.trim()||n.indexStatus.trim();return ps[e]??{label:"Changed",className:"text-muted-foreground"}}function js(n){return`${n.indexStatus}${n.workTreeStatus}`.trim()||"?"}const gs=new Set([".md",".mdx",".markdown"]);function rt(n){const e=n.lastIndexOf(".");return e!==-1&&gs.has(n.slice(e).toLowerCase())}function ws(n,e,r){if(!n||/^(?:[a-z]+:|\/|#)/i.test(n))return n;const o=r.includes("/")?r.slice(0,r.lastIndexOf("/")):"",c=[];for(const f of[...o.split("/"),...n.split("/")])f===".."?c.pop():f&&f!=="."&&c.push(f);const u=e.includes("\\")?"\\":"/";return[e.replace(/[\\/]+$/,""),...c].join(u)}async function pe(n,e){try{const r=await n.json();if(r&&typeof r=="object"&&typeof r.error=="string")return r.error}catch{}return e}function vs(n){return n<1024?`${n} B`:`${(n/1024).toFixed(n<10*1024?1:0)} KB`}function ys(n,e){let r=0;for(let o=1;o<e;o+=1){const c=n.indexOf(`
2
+ `,r);if(c<0)return r;r=c+1}return r}function Rs({cwd:n,onClose:e,onAddToPrompt:r,openRequest:o}){const c=l.useRef(null),u=l.useRef(null),f=l.useRef(null),[g,S]=l.useState(""),[b,R]=l.useState([]),[m,h]=l.useState(!0),[N,j]=l.useState(null),[k,x]=l.useState(0),[w,y]=l.useState(!1),[D,L]=l.useState(0),F=l.useRef(!1),[i,T]=l.useState(null),[U,Ce]=l.useState(!0),[M,W]=l.useState(""),[ft,re]=l.useState(""),[O,oe]=l.useState(null),[ut,Ue]=l.useState(0),[K,Oe]=l.useState(!1),[Z,Pe]=l.useState(!1),[Ge,_]=l.useState(null),[mt,ee]=l.useState(!1),[I,ke]=l.useState("all"),[v,Be]=l.useState(null),[Ke,He]=l.useState(!1),[xt,Ve]=l.useState(null),[C,ce]=l.useState("edit"),[E,we]=l.useState(null),[de,Je]=l.useState(!1),[Qe,Ee]=l.useState(null),[fe,H]=l.useState(null),[P,ve]=l.useState(null),[ye,Re]=l.useState(""),[B,ue]=l.useState(null),$=i!==null&&M!==ft,z=l.useMemo(()=>new Map(((v==null?void 0:v.files)??[]).flatMap(s=>[[s.path,s],...s.originalPath?[[s.originalPath,s]]:[]])),[v==null?void 0:v.files]),te=l.useCallback(async()=>{He(!0),Ve(null);try{const s=await ae(`/api/git-status?cwd=${encodeURIComponent(n)}`);if(!s.ok)throw new Error(await pe(s,"Unable to read git status"));const a=await s.json();Be(a),a.isRepository||ke("all")}catch(s){Be(null),ke("all"),Ve(s instanceof Error?s.message:"Unable to read git status")}finally{He(!1)}},[n]);l.useEffect(()=>{te()},[te]);const De=I==="all"&&g.trim()==="";l.useEffect(()=>{if(De)return;const s=new AbortController,a=window.setTimeout(async()=>{h(!0),j(null);const d=F.current;F.current=!1;try{const p=await ae(`/api/project-files?cwd=${encodeURIComponent(n)}&q=${encodeURIComponent(g)}&limit=100${d?"&refresh=1":""}`,{signal:s.signal});if(!p.ok)throw new Error(await pe(p,"Unable to list project files"));const G=await p.json();if(s.signal.aborted)return;const tt=Ct(G),st=G.totalMatches;R(tt),x(typeof st=="number"?st:tt.length),y(G.scanLimited===!0)}catch(p){s.signal.aborted||(R([]),j(p instanceof Error?p.message:"Unable to list project files"))}finally{s.signal.aborted||h(!1)}},120);return()=>{window.clearTimeout(a),s.abort()}},[n,g,D,De]),l.useEffect(()=>{T(null),W(""),re(""),oe(null),_(null),H(null),ce("edit"),we(null),Ee(null),ue(null)},[n]),l.useEffect(()=>{if(!$)return;const s=a=>a.preventDefault();return window.addEventListener("beforeunload",s),()=>window.removeEventListener("beforeunload",s)},[$]);const ht=l.useCallback((s,a)=>{const d=u.current;if(!d)return;if(!a||a<1){d.focus();return}const p=ys(s,a);d.blur(),d.setSelectionRange(p,p),d.focus()},[]);l.useEffect(()=>{const s=f.current;!s||!u.current||(f.current=null,ht(s.text,s.line))});const se=l.useCallback(async(s,a)=>{Oe(!0),_(null),ee(!1),H(null);try{const d=await ae(`/api/project-file?cwd=${encodeURIComponent(n)}&path=${encodeURIComponent(s)}`);if(!d.ok)throw new Error(await pe(d,"Unable to open file"));const p=await d.json();W(p.content),re(p.content),oe(p.mtimeMs),Ue(p.size),f.current={text:p.content,line:a}}catch(d){W(""),re(""),oe(null),_(d instanceof Error?d.message:"Unable to open file")}finally{Oe(!1)}},[n]),ne=l.useCallback(async(s,a)=>{Je(!0),Ee(null),we(null);try{const d=a?`&originalPath=${encodeURIComponent(a)}`:"",p=await ae(`/api/git-diff?cwd=${encodeURIComponent(n)}&path=${encodeURIComponent(s)}${d}`);if(!p.ok)throw new Error(await pe(p,"Unable to diff file"));we(await p.json())}catch(d){Ee(d instanceof Error?d.message:"Unable to diff file")}finally{Je(!1)}},[n]),be=l.useCallback(({path:s,mode:a,line:d})=>{var p;if(T(s),Ce(!1),a==="edit"){ce(rt(s)&&!d?"preview":"edit"),se(s,d);return}ce(a),W(""),re(""),oe(null),_(null),ee(!1),H(null),ne(s,(p=z.get(s))==null?void 0:p.originalPath)},[z,ne,se]),Ne=l.useCallback(s=>{if($){ue({type:"file",target:s});return}be(s)},[$,be]),Xe=l.useCallback(s=>{if(s===i){Ce(!1);return}const a=I==="changes"&&z.has(s)?"diff":"edit";Ne({path:s,mode:a})},[z,I,Ne,i]),Ye=l.useRef(0);l.useEffect(()=>{!o||o.token===Ye.current||(Ye.current=o.token,Ne({path:o.file,mode:o.mode,line:o.line}))},[o,Ne]);const pt=l.useCallback(()=>{var s;!i||C==="diff"||(ce("diff"),(E==null?void 0:E.path)!==i&&!de&&ne(i,(s=z.get(i))==null?void 0:s.originalPath))},[z,E==null?void 0:E.path,de,ne,i,C]),jt=l.useCallback(s=>{!i||C===s||(ce(s),O===null&&!K&&se(i))},[K,se,O,i,C]),Fe=l.useCallback(()=>{var s;if(i){if(C==="diff"){ne(i,(s=z.get(i))==null?void 0:s.originalPath);return}se(i)}},[z,ne,se,i,C]),gt=l.useCallback(()=>{F.current=!0,L(s=>s+1),te(),C==="diff"&&Fe()},[te,Fe,C]),Le=l.useCallback(async()=>{if(!(!i||O===null||!$||Z)){Pe(!0),_(null),ee(!1);try{const s=await ae("/api/project-file",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:n,path:i,content:M,expectedMtimeMs:O})});if(!s.ok)throw new Error(await pe(s,"Unable to save file"));const a=await s.json();re(M),oe(a.mtimeMs),Ue(a.size),ee(!0),we(null),te()}catch(s){_(s instanceof Error?s.message:"Unable to save file")}finally{Pe(!1)}}},[M,n,$,te,O,Z,i]);l.useEffect(()=>{function s(a){var d;(d=c.current)!=null&&d.contains(document.activeElement)&&Wt("projectFileSave",a)&&(a.preventDefault(),Le())}return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[Le]);const wt=l.useCallback(()=>{if($){ue({type:"close"});return}e()},[$,e]),vt=l.useCallback(()=>{if(!B)return;const s=B;if(ue(null),s.type==="file"){be(s.target);return}e()},[e,be,B]),yt=l.useCallback(s=>{if(s.key!=="Tab")return;s.preventDefault();const a=s.currentTarget,d=a.selectionStart,p=a.selectionEnd,G=`${M.slice(0,d)} ${M.slice(p)}`;W(G),ee(!1),H(null),requestAnimationFrame(()=>{a.selectionStart=d+2,a.selectionEnd=d+2})},[M]),bt=l.useCallback(s=>{const a=s.currentTarget;if(a.selectionStart===a.selectionEnd){H(null);return}const d=M.slice(a.selectionStart,a.selectionEnd),p=M.slice(0,a.selectionStart).split(`
3
3
  `).length,G=p+d.split(`
4
- `).length-1;K({text:d,startLine:p,endLine:G})},[M]),Te=l.useMemo(()=>(i==null?void 0:i.split("/").at(-1))??null,[i]),me=i?z.get(i):void 0,qe=i!==null&&rt(i),We=l.useCallback(s=>{const a=z.get(s);return a?{code:js(a),...$e(a)}:null},[z]),Nt=l.useMemo(()=>({...kt,img:s=>t.jsx(Et,{src:ws(s.src,n,i??""),alt:s.alt})}),[n,i]),Me=l.useMemo(()=>E&&!E.binary&&!E.tooLarge?Rt(E.original??"",E.current??""):null,[E]),V=l.useMemo(()=>{if(I==="all")return b;const s=g.trim().toLowerCase();return((v==null?void 0:v.files)??[]).map(a=>a.path).filter((a,d,p)=>p.indexOf(a)===d).filter(a=>!s||a.toLowerCase().includes(s)).sort((a,d)=>a.localeCompare(d))},[I,b,v==null?void 0:v.files,g]),Ze=l.useMemo(()=>i&&!V.includes(i)?[i,...V]:V,[V,i]),St=I==="changes"?He:m,_e=I==="changes"?xt:N,et=He;return t.jsxs("aside",{ref:c,"aria-label":"Project files",className:"relative flex size-full min-h-0 flex-col bg-canvas",children:[t.jsxs("div",{className:"flex h-10 shrink-0 items-center gap-2 px-3",children:[t.jsx(ze,{"data-icon":"inline-start","aria-hidden":"true",className:"size-4 text-muted-foreground"}),t.jsx("h2",{className:"text-sm font-medium",children:"Project files"}),t.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-xs text-muted-foreground",title:n,children:n}),t.jsx(A,{variant:"ghost",size:"icon-sm",onClick:wt,"aria-label":"Close project files",children:t.jsx(ss,{"data-icon":"inline-start"})})]}),t.jsx(xe,{}),(v==null?void 0:v.isRepository)&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex h-8 shrink-0 items-center gap-2 px-3 text-xs text-muted-foreground",children:[t.jsx(ns,{"data-icon":"inline-start","aria-hidden":"true",className:"size-3.5"}),t.jsx("span",{className:"max-w-40 truncate font-mono text-foreground",title:v.branch??"Detached HEAD",children:v.branch??"detached HEAD"}),v.upstream&&t.jsxs("span",{className:"truncate",children:["tracks ",v.upstream]}),(v.ahead??0)>0&&t.jsxs(le,{variant:"outline",children:["↑ ",v.ahead]}),(v.behind??0)>0&&t.jsxs(le,{variant:"outline",children:["↓ ",v.behind]}),t.jsx("span",{className:"flex-1"}),t.jsxs("span",{children:[v.files.length," changed"]})]}),t.jsx(xe,{})]}),t.jsxs("div",{className:"flex min-h-0 flex-1",children:[t.jsxs("section",{"aria-label":"File browser",className:ie("min-h-0 shrink-0 flex-col md:flex md:w-56",i&&!U?"hidden":"flex w-full"),children:[t.jsxs("div",{className:"flex flex-col gap-2 p-2",children:[t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsxs(Dt,{className:"min-w-0 flex-1",children:[t.jsx(Ft,{children:t.jsx(ls,{"data-icon":"inline-start"})}),t.jsx(Lt,{"aria-label":"Search project files",value:g,onChange:s=>S(s.target.value),placeholder:"Filter files…",spellCheck:!1})]}),t.jsx(A,{variant:"ghost",size:"icon-sm",disabled:et,onClick:gt,"aria-label":"Refresh files and git status",title:"Refresh files and git status",children:t.jsx(lt,{"data-icon":"inline-start",className:et?"animate-spin":void 0})})]}),(v==null?void 0:v.isRepository)&&t.jsxs(nt,{"aria-label":"File scope",value:[I],onValueChange:s=>{const a=s[0];(a==="all"||a==="changes")&&ke(a)},variant:"outline",size:"sm",spacing:0,className:"w-full",children:[t.jsx(he,{value:"all",className:"flex-1",children:"All files"}),t.jsx(he,{value:"changes",className:"flex-1",children:"Changes"})]})]}),t.jsx(xe,{}),t.jsx(Tt,{className:"min-h-0 flex-1",children:De?t.jsx(us,{cwd:n,selectedPath:i,onSelect:Xe,fileStatus:We,reloadToken:D}):St?t.jsxs("div",{className:"flex items-center justify-center gap-2 p-6 text-xs text-muted-foreground",role:"status",children:[t.jsx(je,{}),"Loading files…"]}):_e?t.jsx(Q,{className:"min-h-48 rounded-none p-4",children:t.jsxs(J,{children:[t.jsx(X,{variant:"icon",children:t.jsx(ge,{})}),t.jsx(Y,{children:"Could not load files"}),t.jsx(q,{children:_e})]})}):Ze.length===0?t.jsx(Q,{className:"min-h-48 rounded-none p-4",children:t.jsxs(J,{children:[t.jsx(X,{variant:"icon",children:t.jsx(ze,{})}),t.jsx(Y,{children:I==="changes"?"No working-tree changes":"No matching files"}),t.jsx(q,{children:I==="changes"?"This project has no changed files matching the filter.":"Try a different path or filename."})]})}):t.jsxs("div",{className:"flex flex-col py-1",children:[Ze.map(s=>{const a=s.split("/").at(-1)??s,d=s.includes("/")?s.slice(0,s.lastIndexOf("/")):"",p=We(s),G=ot(s);return t.jsxs(A,{variant:i===s?"secondary":"ghost",size:"sm",className:"h-auto w-full justify-start rounded-none px-2 py-1.5 text-left",onClick:()=>Xe(s),title:s,children:[t.jsx(G,{"data-icon":"inline-start",className:"text-muted-foreground"}),t.jsxs("span",{className:"min-w-0 flex-1",children:[t.jsx("span",{className:"block truncate text-xs",children:a}),d&&t.jsx("span",{className:"block truncate font-mono text-xs text-muted-foreground",children:d})]}),p&&t.jsx(le,{variant:"outline",className:ie("font-mono",p.className),title:p.label,children:p.code})]},s)}),I==="all"&&(k>V.length||w)&&t.jsxs("p",{className:"px-3 py-2 text-xs text-muted-foreground",children:[k>V.length&&`Showing ${V.length} of ${k} matches. Type to narrow the list. `,w&&"This project is too large to scan completely."]})]})})]}),t.jsx(xe,{orientation:"vertical",className:"hidden md:block"}),t.jsx("section",{"aria-label":"File editor",className:ie("min-h-0 min-w-0 flex-1 flex-col md:flex",i&&!U?"flex":"hidden"),children:i?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex min-h-10 shrink-0 flex-wrap items-center gap-2 px-3 py-1 md:flex-nowrap",children:[t.jsx(A,{variant:"ghost",size:"icon-lg",className:"md:hidden",onClick:()=>Ce(!0),"aria-label":"Back to file browser",children:t.jsx(as,{"data-icon":"inline-start"})}),t.jsxs("div",{className:"min-w-0 flex-1 basis-[calc(100%-3.25rem)] md:basis-auto",children:[t.jsx("p",{className:"truncate text-xs font-medium",title:i,children:Te}),t.jsx("p",{className:"truncate font-mono text-xs text-muted-foreground",children:i})]}),(me||C==="diff"||qe)&&t.jsxs(nt,{"aria-label":"File view",value:[C],onValueChange:s=>{s[0]==="diff"?pt():(s[0]==="edit"||s[0]==="preview")&&jt(s[0])},variant:"outline",size:"sm",spacing:0,children:[(me||C==="diff")&&t.jsx(he,{value:"diff",children:"Diff"}),qe&&t.jsx(he,{value:"preview",children:"Preview"}),t.jsx(he,{value:"edit",children:"Edit"})]}),C==="diff"&&me&&t.jsx(le,{variant:"outline",className:$e(me).className,children:$e(me).label}),C==="diff"&&Me&&t.jsx(Mt,{add:Me.add,del:Me.del}),C!=="diff"&&$&&t.jsx(le,{variant:"outline",children:"Unsaved"}),C!=="diff"&&!$&&mt&&t.jsx(le,{variant:"secondary",children:"Saved"}),C!=="diff"&&O!==null&&t.jsx("span",{className:"hidden text-xs text-muted-foreground md:inline",children:vs(ut)}),r&&t.jsxs(A,{variant:"outline",size:"sm",disabled:C==="diff"?de||E===null:H||O===null,onClick:()=>{fe?(Re(""),ve(fe)):r({path:i})},"aria-label":fe?"Add selected lines to prompt":"Reference file in prompt",title:fe?"Add selected lines to prompt":"Reference file in prompt",children:[t.jsx(at,{"data-icon":"inline-start"}),fe?"Add selection":"Reference"]}),t.jsx(A,{variant:"ghost",size:"icon-sm",disabled:C==="diff"?de:H||Z,onClick:Fe,"aria-label":C==="diff"?"Reload diff":"Reload file",title:C==="diff"?"Reload diff":"Reload file",children:t.jsx(lt,{"data-icon":"inline-start"})}),C!=="diff"&&t.jsxs(A,{size:"sm",disabled:!$||H||Z||O===null,onClick:()=>void Le(),children:[Z?t.jsx(je,{"data-icon":"inline-start"}):t.jsx(is,{"data-icon":"inline-start"}),Z?"Saving…":"Save"]})]}),t.jsx(xe,{}),C!=="diff"&&Ge&&t.jsxs("div",{role:"alert",className:"flex items-center gap-2 px-3 py-2 text-xs text-destructive",children:[t.jsx(ge,{"data-icon":"inline-start","aria-hidden":"true",className:"size-4 shrink-0"}),t.jsx("span",{children:Ge})]}),C==="diff"?t.jsx("div",{className:"flex min-h-0 flex-1 flex-col",children:de?t.jsxs("div",{className:"flex size-full items-center justify-center gap-2 text-xs text-muted-foreground",role:"status",children:[t.jsx(je,{}),"Loading diff…"]}):Je?t.jsx(Q,{className:"rounded-none",children:t.jsxs(J,{children:[t.jsx(X,{variant:"icon",children:t.jsx(ge,{})}),t.jsx(Y,{children:"Could not diff this file"}),t.jsx(q,{children:Je})]})}):E===null?null:E.binary||E.tooLarge?t.jsx(Q,{className:"rounded-none",children:t.jsxs(J,{children:[t.jsx(X,{variant:"icon",children:t.jsx(Ie,{})}),t.jsx(Y,{children:E.binary?"Binary file":"File is too large to diff"}),t.jsx(q,{children:E.binary?"Git tracks this change, but there is no text diff to show.":"Review this change in your editor instead."})]})}):E.original===E.current?t.jsx(Q,{className:"rounded-none",children:t.jsxs(J,{children:[t.jsx(X,{variant:"icon",children:t.jsx(Ie,{})}),t.jsx(Y,{children:"No content changes"}),t.jsx(q,{children:"This file matches the last commit — only its mode or index entry differs."})]})}):t.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:t.jsx(It,{oldString:E.original??"",newString:E.current??"",filePath:i,compact:!1,hideHeader:!0})})}):t.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[H&&t.jsxs("div",{className:"flex size-full items-center justify-center gap-2 text-xs text-muted-foreground",role:"status",children:[t.jsx(je,{}),"Opening file…"]}),!H&&O!==null&&(C==="preview"?t.jsx("div",{"aria-label":`Preview of ${i}`,className:"min-h-0 flex-1 overflow-auto break-words px-6 py-4 text-sm",children:t.jsx(rs,{components:Nt,remarkPlugins:$t,children:M})}):t.jsx(Zt,{textareaRef:u,ariaLabel:`Editing ${i}`,filePath:i,value:M,readOnly:!1,onChange:s=>{W(s),ee(!1),K(null)},onKeyDown:yt,onSelect:bt}))]})]}):t.jsx(Q,{className:"rounded-none",children:t.jsxs(J,{children:[t.jsx(X,{variant:"icon",children:t.jsx(Ie,{})}),t.jsx(Y,{children:"Select a file"}),t.jsx(q,{children:"Browse or filter project files, then open one to inspect and edit it."})]})})})]}),t.jsx(zt,{open:P!==null,onOpenChange:s=>{s||ve(null)},children:t.jsxs(At,{children:[t.jsxs(Ut,{children:[t.jsx(Ot,{children:"Comment on selected lines"}),t.jsxs(Pt,{children:["Add a review instruction for ",i," lines ",P==null?void 0:P.startLine,"-",P==null?void 0:P.endLine,"."]})]}),t.jsxs("form",{className:"flex flex-col gap-4",onSubmit:s=>{s.preventDefault();const a=ye.trim();!i||!P||!a||!r||(r({path:i,...P,comment:a}),ve(null),Re(""))},children:[t.jsx(Gt,{autoFocus:!0,"aria-label":"Review comment",value:ye,onChange:s=>Re(s.target.value),placeholder:"Describe the change you want…",onKeyDown:s=>{var a;(s.metaKey||s.ctrlKey)&&s.key==="Enter"&&ye.trim()&&(s.preventDefault(),(a=s.currentTarget.form)==null||a.requestSubmit())}}),t.jsxs(Bt,{children:[t.jsx(A,{type:"button",variant:"outline",onClick:()=>ve(null),children:"Cancel"}),t.jsxs(A,{type:"submit",disabled:!ye.trim(),children:[t.jsx(at,{"data-icon":"inline-start"}),"Add to prompt"]})]})]})]})}),t.jsx(Ht,{open:B!==null,onOpenChange:s=>{s||ue(null)},children:t.jsxs(Kt,{size:"sm",children:[t.jsxs(Vt,{children:[t.jsx(Qt,{children:"Discard unsaved changes?"}),t.jsx(Jt,{children:(B==null?void 0:B.type)==="file"?`Your edits to ${Te??"this file"} will be lost when you open ${B.target.path}.`:`Your edits to ${Te??"this file"} will be lost when you close the file workspace.`})]}),t.jsxs(Xt,{children:[t.jsx(Yt,{size:"sm",children:"Keep editing"}),t.jsx(qt,{variant:"destructive",size:"sm",onClick:vt,children:"Discard changes"})]})]})})]})}export{Rs as ProjectFilesPanel};
4
+ `).length-1;H({text:d,startLine:p,endLine:G})},[M]),Te=l.useMemo(()=>(i==null?void 0:i.split("/").at(-1))??null,[i]),me=i?z.get(i):void 0,qe=i!==null&&rt(i),We=l.useCallback(s=>{const a=z.get(s);return a?{code:js(a),...$e(a)}:null},[z]),Nt=l.useMemo(()=>({...kt,img:s=>t.jsx(Et,{src:ws(s.src,n,i??""),alt:s.alt})}),[n,i]),Me=l.useMemo(()=>E&&!E.binary&&!E.tooLarge?Rt(E.original??"",E.current??""):null,[E]),V=l.useMemo(()=>{if(I==="all")return b;const s=g.trim().toLowerCase();return((v==null?void 0:v.files)??[]).map(a=>a.path).filter((a,d,p)=>p.indexOf(a)===d).filter(a=>!s||a.toLowerCase().includes(s)).sort((a,d)=>a.localeCompare(d))},[I,b,v==null?void 0:v.files,g]),Ze=l.useMemo(()=>i&&!V.includes(i)?[i,...V]:V,[V,i]),St=I==="changes"?Ke:m,_e=I==="changes"?xt:N,et=Ke;return t.jsxs("aside",{ref:c,"aria-label":"Project files",className:"relative flex size-full min-h-0 flex-col bg-canvas",children:[t.jsxs("div",{className:"flex h-10 shrink-0 items-center gap-2 px-3",children:[t.jsx(ze,{"data-icon":"inline-start","aria-hidden":"true",className:"size-4 text-muted-foreground"}),t.jsx("h2",{className:"text-sm font-medium",children:"Project files"}),t.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-xs text-muted-foreground",title:n,children:n}),t.jsx(A,{variant:"ghost",size:"icon-sm",onClick:wt,"aria-label":"Close project files",children:t.jsx(ss,{"data-icon":"inline-start"})})]}),t.jsx(xe,{}),(v==null?void 0:v.isRepository)&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex h-8 shrink-0 items-center gap-2 px-3 text-xs text-muted-foreground",children:[t.jsx(ns,{"data-icon":"inline-start","aria-hidden":"true",className:"size-3.5"}),t.jsx("span",{className:"max-w-40 truncate font-mono text-foreground",title:v.branch??"Detached HEAD",children:v.branch??"detached HEAD"}),v.upstream&&t.jsxs("span",{className:"truncate",children:["tracks ",v.upstream]}),(v.ahead??0)>0&&t.jsxs(le,{variant:"outline",children:["↑ ",v.ahead]}),(v.behind??0)>0&&t.jsxs(le,{variant:"outline",children:["↓ ",v.behind]}),t.jsx("span",{className:"flex-1"}),t.jsxs("span",{children:[v.files.length," changed"]})]}),t.jsx(xe,{})]}),t.jsxs("div",{className:"flex min-h-0 flex-1",children:[t.jsxs("section",{"aria-label":"File browser",className:ie("min-h-0 shrink-0 flex-col md:flex md:w-56",i&&!U?"hidden":"flex w-full"),children:[t.jsxs("div",{className:"flex flex-col gap-2 p-2",children:[t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsxs(Dt,{className:"min-w-0 flex-1",children:[t.jsx(Ft,{children:t.jsx(ls,{"data-icon":"inline-start"})}),t.jsx(Lt,{"aria-label":"Search project files",value:g,onChange:s=>S(s.target.value),placeholder:"Filter files…",spellCheck:!1})]}),t.jsx(A,{variant:"ghost",size:"icon-sm",disabled:et,onClick:gt,"aria-label":"Refresh files and git status",title:"Refresh files and git status",children:t.jsx(lt,{"data-icon":"inline-start",className:et?"animate-spin":void 0})})]}),(v==null?void 0:v.isRepository)&&t.jsxs(nt,{"aria-label":"File scope",value:[I],onValueChange:s=>{const a=s[0];(a==="all"||a==="changes")&&ke(a)},variant:"outline",size:"sm",spacing:0,className:"w-full",children:[t.jsx(he,{value:"all",className:"flex-1",children:"All files"}),t.jsx(he,{value:"changes",className:"flex-1",children:"Changes"})]})]}),t.jsx(xe,{}),t.jsx(Tt,{className:"min-h-0 flex-1",children:De?t.jsx(us,{cwd:n,selectedPath:i,onSelect:Xe,fileStatus:We,reloadToken:D}):St?t.jsxs("div",{className:"flex items-center justify-center gap-2 p-6 text-xs text-muted-foreground",role:"status",children:[t.jsx(je,{}),"Loading files…"]}):_e?t.jsx(J,{className:"min-h-48 rounded-none p-4",children:t.jsxs(Q,{children:[t.jsx(X,{variant:"icon",children:t.jsx(ge,{})}),t.jsx(Y,{children:"Could not load files"}),t.jsx(q,{children:_e})]})}):Ze.length===0?t.jsx(J,{className:"min-h-48 rounded-none p-4",children:t.jsxs(Q,{children:[t.jsx(X,{variant:"icon",children:t.jsx(ze,{})}),t.jsx(Y,{children:I==="changes"?"No working-tree changes":"No matching files"}),t.jsx(q,{children:I==="changes"?"This project has no changed files matching the filter.":"Try a different path or filename."})]})}):t.jsxs("div",{className:"flex flex-col py-1",children:[Ze.map(s=>{const a=s.split("/").at(-1)??s,d=s.includes("/")?s.slice(0,s.lastIndexOf("/")):"",p=We(s),G=ot(s);return t.jsxs(A,{variant:i===s?"secondary":"ghost",size:"sm",className:"h-auto w-full justify-start rounded-none px-2 py-1.5 text-left",onClick:()=>Xe(s),title:s,children:[t.jsx(G,{"data-icon":"inline-start",className:"text-muted-foreground"}),t.jsxs("span",{className:"min-w-0 flex-1",children:[t.jsx("span",{className:"block truncate text-xs",children:a}),d&&t.jsx("span",{className:"block truncate font-mono text-xs text-muted-foreground",children:d})]}),p&&t.jsx(le,{variant:"outline",className:ie("font-mono",p.className),title:p.label,children:p.code})]},s)}),I==="all"&&(k>V.length||w)&&t.jsxs("p",{className:"px-3 py-2 text-xs text-muted-foreground",children:[k>V.length&&`Showing ${V.length} of ${k} matches. Type to narrow the list. `,w&&"This project is too large to scan completely."]})]})})]}),t.jsx(xe,{orientation:"vertical",className:"hidden md:block"}),t.jsx("section",{"aria-label":"File editor",className:ie("min-h-0 min-w-0 flex-1 flex-col md:flex",i&&!U?"flex":"hidden"),children:i?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex min-h-10 shrink-0 flex-wrap items-center gap-2 px-3 py-1 md:flex-nowrap",children:[t.jsx(A,{variant:"ghost",size:"icon-lg",className:"md:hidden",onClick:()=>Ce(!0),"aria-label":"Back to file browser",children:t.jsx(as,{"data-icon":"inline-start"})}),t.jsxs("div",{className:"min-w-0 flex-1 basis-[calc(100%-3.25rem)] md:basis-auto",children:[t.jsx("p",{className:"truncate text-xs font-medium",title:i,children:Te}),t.jsx("p",{className:"truncate font-mono text-xs text-muted-foreground",children:i})]}),(me||C==="diff"||qe)&&t.jsxs(nt,{"aria-label":"File view",value:[C],onValueChange:s=>{s[0]==="diff"?pt():(s[0]==="edit"||s[0]==="preview")&&jt(s[0])},variant:"outline",size:"sm",spacing:0,children:[(me||C==="diff")&&t.jsx(he,{value:"diff",children:"Diff"}),qe&&t.jsx(he,{value:"preview",children:"Preview"}),t.jsx(he,{value:"edit",children:"Edit"})]}),C==="diff"&&me&&t.jsx(le,{variant:"outline",className:$e(me).className,children:$e(me).label}),C==="diff"&&Me&&t.jsx(Mt,{add:Me.add,del:Me.del}),C!=="diff"&&$&&t.jsx(le,{variant:"outline",children:"Unsaved"}),C!=="diff"&&!$&&mt&&t.jsx(le,{variant:"secondary",children:"Saved"}),C!=="diff"&&O!==null&&t.jsx("span",{className:"hidden text-xs text-muted-foreground md:inline",children:vs(ut)}),r&&t.jsxs(A,{variant:"outline",size:"sm",disabled:C==="diff"?de||E===null:K||O===null,onClick:()=>{fe?(Re(""),ve(fe)):r({path:i})},"aria-label":fe?"Add selected lines to prompt":"Reference file in prompt",title:fe?"Add selected lines to prompt":"Reference file in prompt",children:[t.jsx(at,{"data-icon":"inline-start"}),fe?"Add selection":"Reference"]}),t.jsx(A,{variant:"ghost",size:"icon-sm",disabled:C==="diff"?de:K||Z,onClick:Fe,"aria-label":C==="diff"?"Reload diff":"Reload file",title:C==="diff"?"Reload diff":"Reload file",children:t.jsx(lt,{"data-icon":"inline-start"})}),C!=="diff"&&t.jsxs(A,{size:"sm",disabled:!$||K||Z||O===null,onClick:()=>void Le(),children:[Z?t.jsx(je,{"data-icon":"inline-start"}):t.jsx(is,{"data-icon":"inline-start"}),Z?"Saving…":"Save"]})]}),t.jsx(xe,{}),C!=="diff"&&Ge&&t.jsxs("div",{role:"alert",className:"flex items-center gap-2 px-3 py-2 text-xs text-destructive",children:[t.jsx(ge,{"data-icon":"inline-start","aria-hidden":"true",className:"size-4 shrink-0"}),t.jsx("span",{children:Ge})]}),C==="diff"?t.jsx("div",{className:"flex min-h-0 flex-1 flex-col",children:de?t.jsxs("div",{className:"flex size-full items-center justify-center gap-2 text-xs text-muted-foreground",role:"status",children:[t.jsx(je,{}),"Loading diff…"]}):Qe?t.jsx(J,{className:"rounded-none",children:t.jsxs(Q,{children:[t.jsx(X,{variant:"icon",children:t.jsx(ge,{})}),t.jsx(Y,{children:"Could not diff this file"}),t.jsx(q,{children:Qe})]})}):E===null?null:E.binary||E.tooLarge?t.jsx(J,{className:"rounded-none",children:t.jsxs(Q,{children:[t.jsx(X,{variant:"icon",children:t.jsx(Ie,{})}),t.jsx(Y,{children:E.binary?"Binary file":"File is too large to diff"}),t.jsx(q,{children:E.binary?"Git tracks this change, but there is no text diff to show.":"Review this change in your editor instead."})]})}):E.original===E.current?t.jsx(J,{className:"rounded-none",children:t.jsxs(Q,{children:[t.jsx(X,{variant:"icon",children:t.jsx(Ie,{})}),t.jsx(Y,{children:"No content changes"}),t.jsx(q,{children:"This file matches the last commit — only its mode or index entry differs."})]})}):t.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:t.jsx(It,{oldString:E.original??"",newString:E.current??"",filePath:i,compact:!1,hideHeader:!0})})}):t.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[K&&t.jsxs("div",{className:"flex size-full items-center justify-center gap-2 text-xs text-muted-foreground",role:"status",children:[t.jsx(je,{}),"Opening file…"]}),!K&&O!==null&&(C==="preview"?t.jsx("div",{"aria-label":`Preview of ${i}`,className:"min-h-0 flex-1 overflow-auto break-words px-6 py-4 text-sm",children:t.jsx(rs,{components:Nt,remarkPlugins:$t,children:M})}):t.jsx(Zt,{textareaRef:u,ariaLabel:`Editing ${i}`,filePath:i,value:M,readOnly:!1,onChange:s=>{W(s),ee(!1),H(null)},onKeyDown:yt,onSelect:bt}))]})]}):t.jsx(J,{className:"rounded-none",children:t.jsxs(Q,{children:[t.jsx(X,{variant:"icon",children:t.jsx(Ie,{})}),t.jsx(Y,{children:"Select a file"}),t.jsx(q,{children:"Browse or filter project files, then open one to inspect and edit it."})]})})})]}),t.jsx(zt,{open:P!==null,onOpenChange:s=>{s||ve(null)},children:t.jsxs(At,{children:[t.jsxs(Ut,{children:[t.jsx(Ot,{children:"Comment on selected lines"}),t.jsxs(Pt,{children:["Add a review instruction for ",i," lines ",P==null?void 0:P.startLine,"-",P==null?void 0:P.endLine,"."]})]}),t.jsxs("form",{className:"flex flex-col gap-4",onSubmit:s=>{s.preventDefault();const a=ye.trim();!i||!P||!a||!r||(r({path:i,...P,comment:a}),ve(null),Re(""))},children:[t.jsx(Gt,{autoFocus:!0,"aria-label":"Review comment",value:ye,onChange:s=>Re(s.target.value),placeholder:"Describe the change you want…",onKeyDown:s=>{var a;(s.metaKey||s.ctrlKey)&&s.key==="Enter"&&ye.trim()&&(s.preventDefault(),(a=s.currentTarget.form)==null||a.requestSubmit())}}),t.jsxs(Bt,{children:[t.jsx(A,{type:"button",variant:"outline",onClick:()=>ve(null),children:"Cancel"}),t.jsxs(A,{type:"submit",disabled:!ye.trim(),children:[t.jsx(at,{"data-icon":"inline-start"}),"Add to prompt"]})]})]})]})}),t.jsx(Kt,{open:B!==null,onOpenChange:s=>{s||ue(null)},children:t.jsxs(Ht,{size:"sm",children:[t.jsxs(Vt,{children:[t.jsx(Jt,{children:"Discard unsaved changes?"}),t.jsx(Qt,{children:(B==null?void 0:B.type)==="file"?`Your edits to ${Te??"this file"} will be lost when you open ${B.target.path}.`:`Your edits to ${Te??"this file"} will be lost when you close the file workspace.`})]}),t.jsxs(Xt,{children:[t.jsx(Yt,{size:"sm",children:"Keep editing"}),t.jsx(qt,{variant:"destructive",size:"sm",onClick:vt,children:"Discard changes"})]})]})})]})}export{Rs as ProjectFilesPanel};
@@ -1 +1 @@
1
- import{c as E,r as y,j as m}from"./vendor-react-gGw_S5I_.js";import{v as b,i as L,j as k,k as F,h as K,P as R,D as _,w as A,x as H}from"./index-DsnL-sXV.js";import"./vendor-ui-Br3ZTAXZ.js";import"./vendor-shiki-DOn6sF-i.js";import"./vendor-markdown-BE1gYnO9.js";function q(v){const e=E.c(28),{open:r,onClose:t,onNewSession:i,onNewFolder:j,defaultAgentKind:x,currentProjectDirName:a,currentProjectCwd:o,initialView:D}=v,s=b(r);let h,p;e[0]!==o||e[1]!==a||e[2]!==t||e[3]!==i||e[4]!==r||e[5]!==s?(h=()=>{if(!r)return;const n=function(g){var S;if(A("newSession",g)&&a){g.preventDefault();const P=o?H(s,o,"claude")??((S=s.find(C=>C.path===o))==null?void 0:S.dirName)??a:a;i(P,o??void 0),t()}};return window.addEventListener("keydown",n),()=>window.removeEventListener("keydown",n)},p=[r,s,a,o,i,t],e[0]=o,e[1]=a,e[2]=t,e[3]=i,e[4]=r,e[5]=s,e[6]=h,e[7]=p):(h=e[6],p=e[7]),y.useEffect(h,p);let l;e[8]!==t?(l=n=>{n||t()},e[8]=t,e[9]=l):l=e[9];let w;e[10]===Symbol.for("react.memo_cache_sentinel")?(w=m.jsxs(L,{className:"sr-only",children:[m.jsx(k,{children:"Start a session"}),m.jsx(F,{children:"Choose a project, enter an absolute folder path, or browse the folders."})]}),e[10]=w):w=e[10];let c;e[11]!==t||e[12]!==i?(c=(n,N)=>{i(n,N),t()},e[11]=t,e[12]=i,e[13]=c):c=e[13];let d;e[14]!==t||e[15]!==j?(d=n=>{j(n),t()},e[14]=t,e[15]=j,e[16]=d):d=e[16];let f;e[17]!==o||e[18]!==x||e[19]!==D||e[20]!==s||e[21]!==c||e[22]!==d?(f=m.jsxs(K,{className:"max-w-md gap-0 overflow-hidden p-0",children:[w,m.jsx(R,{projects:s,currentPath:o,onNewSession:c,onNewFolder:d,defaultAgentKind:x,initialView:D})]}),e[17]=o,e[18]=x,e[19]=D,e[20]=s,e[21]=c,e[22]=d,e[23]=f):f=e[23];let u;return e[24]!==r||e[25]!==l||e[26]!==f?(u=m.jsx(_,{open:r,onOpenChange:l,children:f}),e[24]=r,e[25]=l,e[26]=f,e[27]=u):u=e[27],u}export{q as ProjectSwitcherModal};
1
+ import{c as E,r as y,j as m}from"./vendor-react-gGw_S5I_.js";import{v as b,i as L,j as k,k as F,h as K,P as R,D as _,w as A,x as H}from"./index-CYJLZdyZ.js";import"./vendor-ui-Dxtv9P3W.js";import"./vendor-shiki-DOn6sF-i.js";import"./vendor-markdown-BE1gYnO9.js";function q(v){const e=E.c(28),{open:r,onClose:t,onNewSession:i,onNewFolder:j,defaultAgentKind:x,currentProjectDirName:a,currentProjectCwd:o,initialView:D}=v,s=b(r);let h,p;e[0]!==o||e[1]!==a||e[2]!==t||e[3]!==i||e[4]!==r||e[5]!==s?(h=()=>{if(!r)return;const n=function(g){var S;if(A("newSession",g)&&a){g.preventDefault();const P=o?H(s,o,"claude")??((S=s.find(C=>C.path===o))==null?void 0:S.dirName)??a:a;i(P,o??void 0),t()}};return window.addEventListener("keydown",n),()=>window.removeEventListener("keydown",n)},p=[r,s,a,o,i,t],e[0]=o,e[1]=a,e[2]=t,e[3]=i,e[4]=r,e[5]=s,e[6]=h,e[7]=p):(h=e[6],p=e[7]),y.useEffect(h,p);let l;e[8]!==t?(l=n=>{n||t()},e[8]=t,e[9]=l):l=e[9];let w;e[10]===Symbol.for("react.memo_cache_sentinel")?(w=m.jsxs(L,{className:"sr-only",children:[m.jsx(k,{children:"Start a session"}),m.jsx(F,{children:"Choose a project, enter an absolute folder path, or browse the folders."})]}),e[10]=w):w=e[10];let c;e[11]!==t||e[12]!==i?(c=(n,N)=>{i(n,N),t()},e[11]=t,e[12]=i,e[13]=c):c=e[13];let d;e[14]!==t||e[15]!==j?(d=n=>{j(n),t()},e[14]=t,e[15]=j,e[16]=d):d=e[16];let f;e[17]!==o||e[18]!==x||e[19]!==D||e[20]!==s||e[21]!==c||e[22]!==d?(f=m.jsxs(K,{className:"max-w-md gap-0 overflow-hidden p-0",children:[w,m.jsx(R,{projects:s,currentPath:o,onNewSession:c,onNewFolder:d,defaultAgentKind:x,initialView:D})]}),e[17]=o,e[18]=x,e[19]=D,e[20]=s,e[21]=c,e[22]=d,e[23]=f):f=e[23];let u;return e[24]!==r||e[25]!==l||e[26]!==f?(u=m.jsx(_,{open:r,onOpenChange:l,children:f}),e[24]=r,e[25]=l,e[26]=f,e[27]=u):u=e[27],u}export{q as ProjectSwitcherModal};
@@ -1,4 +1,4 @@
1
- import{r as Ce,j as Rt}from"./vendor-react-gGw_S5I_.js";import{ao as Gr,w as as,B as Jr}from"./index-DsnL-sXV.js";import{Y as Zr}from"./vendor-ui-Br3ZTAXZ.js";import"./vendor-shiki-DOn6sF-i.js";import"./vendor-markdown-BE1gYnO9.js";/**
1
+ import{r as Ce,j as Rt}from"./vendor-react-gGw_S5I_.js";import{ap as Gr,w as as,B as Jr}from"./index-CYJLZdyZ.js";import{a1 as Zr}from"./vendor-ui-Dxtv9P3W.js";import"./vendor-shiki-DOn6sF-i.js";import"./vendor-markdown-BE1gYnO9.js";/**
2
2
  * Copyright (c) 2014-2024 The xterm.js authors. All rights reserved.
3
3
  * @license MIT
4
4
  *
@@ -1 +1 @@
1
- import{c as O,r as g,j as n}from"./vendor-react-gGw_S5I_.js";import{az as I,H as _,i as U,j as Y,k as q,T as $,h as B,D as J}from"./index-DsnL-sXV.js";import{I as Q,u as V}from"./vendor-ui-Br3ZTAXZ.js";import"./vendor-shiki-DOn6sF-i.js";import"./vendor-markdown-BE1gYnO9.js";const W=[{id:"narrow",name:"Narrow",css:"44rem"},{id:"medium",name:"Medium",css:"56rem"},{id:"wide",name:"Wide",css:"64rem"},{id:"full",name:"Full",css:"100%"}],K="cogpit-chat-width",M="medium";function X(){try{const s=localStorage.getItem(K);if(W.some(e=>e.id===s))return s}catch{}return M}let R=typeof window>"u"?M:X();const H=new Set;function L(s){if(typeof document>"u")return;const e=W.find(t=>t.id===s)??W[1];document.documentElement.style.setProperty("--chat-width",e.css)}L(R);function Z(){return R}function ee(s){R=s;try{localStorage.setItem(K,s)}catch{}L(s),H.forEach(e=>e())}function te(s){return H.add(s),()=>H.delete(s)}function se(){const s=O.c(2),e=g.useSyncExternalStore(te,Z,ae);let t;return s[0]!==e?(t=[e,ee],s[0]=e,s[1]=t):t=s[1],t}function ae(){return M}function de(s){const e=O.c(42),{open:t,onClose:r,currentTheme:l,onSelectTheme:k,onPreviewTheme:i}=s,[x,z]=g.useState(0),[P,A]=se();let j,w;e[0]!==l||e[1]!==t?(j=()=>{if(t){const a=I.findIndex(D=>D.id===l);z(a>=0?a:0)}},w=[t,l],e[0]=l,e[1]=t,e[2]=j,e[3]=w):(j=e[2],w=e[3]),g.useEffect(j,w);let N,b;e[4]!==i||e[5]!==t||e[6]!==x?(N=()=>{t&&i(I[x].id)},b=[x,t,i],e[4]=i,e[5]=t,e[6]=x,e[7]=N,e[8]=b):(N=e[7],b=e[8]),g.useEffect(N,b);let S,y;e[9]!==i||e[10]!==t?(S=()=>{t||i(null)},y=[t,i],e[9]=i,e[10]=t,e[11]=S,e[12]=y):(S=e[11],y=e[12]),g.useEffect(S,y);let C;e[13]!==r||e[14]!==k?(C=a=>{k(a.id),r()},e[13]=r,e[14]=k,e[15]=C):C=e[15];const F=C;let o;e[16]!==r?(o=a=>{a||r()},e[16]=r,e[17]=o):o=e[17];let E;e[18]===Symbol.for("react.memo_cache_sentinel")?(E=n.jsxs(U,{className:"border-b p-4 pr-12",children:[n.jsxs(Y,{className:"flex items-center gap-2 text-sm",children:[n.jsx(V,{"data-icon":"inline-start",className:"size-4 text-muted-foreground"}),"Appearance"]}),n.jsx(q,{children:"Preview a color theme and set the chat width."})]}),e[18]=E):E=e[18];const G=I[x];let c;e[19]!==G.id?(c=[G.id],e[19]=G.id,e[20]=c):c=e[20];let d;e[21]!==l||e[22]!==F?(d=I.map((a,D)=>n.jsxs(_,{value:a.id,className:"h-auto w-full justify-start gap-3 px-3 py-2.5 text-left text-muted-foreground data-pressed:bg-accent data-pressed:text-accent-foreground",onClick:()=>F(a),onMouseEnter:()=>z(D),onFocus:()=>z(D),children:[n.jsx("div",{className:"flex gap-1",children:a.swatches.map(ne)}),n.jsx("span",{className:"flex-1 text-sm font-medium",children:a.name}),l===a.id&&n.jsx(Q,{"data-icon":"inline-end",className:"size-4 shrink-0 text-foreground"})]},a.id)),e[21]=l,e[22]=F,e[23]=d):d=e[23];let m;e[24]!==c||e[25]!==d?(m=n.jsx($,{"aria-label":"Theme",orientation:"vertical",value:c,className:"w-full items-stretch p-1",children:d}),e[24]=c,e[25]=d,e[26]=m):m=e[26];let v;e[27]===Symbol.for("react.memo_cache_sentinel")?(v=n.jsx("div",{className:"px-1 pb-2 text-xs font-medium text-muted-foreground",children:"Chat width"}),e[27]=v):v=e[27];let f;e[28]!==P?(f=[P],e[28]=P,e[29]=f):f=e[29];let u;e[30]!==A?(u=W.map(a=>n.jsx(_,{value:a.id,className:"flex-1 text-xs text-muted-foreground data-pressed:bg-accent data-pressed:text-accent-foreground",onClick:()=>A(a.id),children:a.name},a.id)),e[30]=A,e[31]=u):u=e[31];let h;e[32]!==f||e[33]!==u?(h=n.jsxs("div",{className:"border-t p-3",children:[v,n.jsx($,{"aria-label":"Chat width",value:f,className:"w-full items-stretch gap-1",children:u})]}),e[32]=f,e[33]=u,e[34]=h):h=e[34];let p;e[35]!==m||e[36]!==h?(p=n.jsxs(B,{className:"max-w-sm gap-0 overflow-hidden p-0",children:[E,m,h]}),e[35]=m,e[36]=h,e[37]=p):p=e[37];let T;return e[38]!==t||e[39]!==p||e[40]!==o?(T=n.jsx(J,{open:t,onOpenChange:o,children:p}),e[38]=t,e[39]=p,e[40]=o,e[41]=T):T=e[41],T}function ne(s,e){return n.jsx("div",{className:"size-4 rounded-full border",style:{backgroundColor:s}},e)}export{de as ThemeSelectorModal};
1
+ import{c as O,r as g,j as n}from"./vendor-react-gGw_S5I_.js";import{aB as I,H as _,i as L,j as U,k as Y,T as $,h as q,D as J}from"./index-CYJLZdyZ.js";import{I as Q,u as V}from"./vendor-ui-Dxtv9P3W.js";import"./vendor-shiki-DOn6sF-i.js";import"./vendor-markdown-BE1gYnO9.js";const W=[{id:"narrow",name:"Narrow",css:"44rem"},{id:"medium",name:"Medium",css:"56rem"},{id:"wide",name:"Wide",css:"64rem"},{id:"full",name:"Full",css:"100%"}],B="cogpit-chat-width",M="medium";function X(){try{const s=localStorage.getItem(B);if(W.some(e=>e.id===s))return s}catch{}return M}let R=typeof window>"u"?M:X();const H=new Set;function K(s){if(typeof document>"u")return;const e=W.find(t=>t.id===s)??W[1];document.documentElement.style.setProperty("--chat-width",e.css)}K(R);function Z(){return R}function ee(s){R=s;try{localStorage.setItem(B,s)}catch{}K(s),H.forEach(e=>e())}function te(s){return H.add(s),()=>H.delete(s)}function se(){const s=O.c(2),e=g.useSyncExternalStore(te,Z,ae);let t;return s[0]!==e?(t=[e,ee],s[0]=e,s[1]=t):t=s[1],t}function ae(){return M}function de(s){const e=O.c(42),{open:t,onClose:r,currentTheme:l,onSelectTheme:k,onPreviewTheme:i}=s,[x,P]=g.useState(0),[z,A]=se();let j,w;e[0]!==l||e[1]!==t?(j=()=>{if(t){const a=I.findIndex(D=>D.id===l);P(a>=0?a:0)}},w=[t,l],e[0]=l,e[1]=t,e[2]=j,e[3]=w):(j=e[2],w=e[3]),g.useEffect(j,w);let N,b;e[4]!==i||e[5]!==t||e[6]!==x?(N=()=>{t&&i(I[x].id)},b=[x,t,i],e[4]=i,e[5]=t,e[6]=x,e[7]=N,e[8]=b):(N=e[7],b=e[8]),g.useEffect(N,b);let S,y;e[9]!==i||e[10]!==t?(S=()=>{t||i(null)},y=[t,i],e[9]=i,e[10]=t,e[11]=S,e[12]=y):(S=e[11],y=e[12]),g.useEffect(S,y);let C;e[13]!==r||e[14]!==k?(C=a=>{k(a.id),r()},e[13]=r,e[14]=k,e[15]=C):C=e[15];const F=C;let o;e[16]!==r?(o=a=>{a||r()},e[16]=r,e[17]=o):o=e[17];let E;e[18]===Symbol.for("react.memo_cache_sentinel")?(E=n.jsxs(L,{className:"border-b p-4 pr-12",children:[n.jsxs(U,{className:"flex items-center gap-2 text-sm",children:[n.jsx(V,{"data-icon":"inline-start",className:"size-4 text-muted-foreground"}),"Appearance"]}),n.jsx(Y,{children:"Preview a color theme and set the chat width."})]}),e[18]=E):E=e[18];const G=I[x];let c;e[19]!==G.id?(c=[G.id],e[19]=G.id,e[20]=c):c=e[20];let d;e[21]!==l||e[22]!==F?(d=I.map((a,D)=>n.jsxs(_,{value:a.id,className:"h-auto w-full justify-start gap-3 px-3 py-2.5 text-left text-muted-foreground data-pressed:bg-accent data-pressed:text-accent-foreground",onClick:()=>F(a),onMouseEnter:()=>P(D),onFocus:()=>P(D),children:[n.jsx("div",{className:"flex gap-1",children:a.swatches.map(ne)}),n.jsx("span",{className:"flex-1 text-sm font-medium",children:a.name}),l===a.id&&n.jsx(Q,{"data-icon":"inline-end",className:"size-4 shrink-0 text-foreground"})]},a.id)),e[21]=l,e[22]=F,e[23]=d):d=e[23];let m;e[24]!==c||e[25]!==d?(m=n.jsx($,{"aria-label":"Theme",orientation:"vertical",value:c,className:"w-full items-stretch p-1",children:d}),e[24]=c,e[25]=d,e[26]=m):m=e[26];let v;e[27]===Symbol.for("react.memo_cache_sentinel")?(v=n.jsx("div",{className:"px-1 pb-2 text-xs font-medium text-muted-foreground",children:"Chat width"}),e[27]=v):v=e[27];let f;e[28]!==z?(f=[z],e[28]=z,e[29]=f):f=e[29];let u;e[30]!==A?(u=W.map(a=>n.jsx(_,{value:a.id,className:"flex-1 text-xs text-muted-foreground data-pressed:bg-accent data-pressed:text-accent-foreground",onClick:()=>A(a.id),children:a.name},a.id)),e[30]=A,e[31]=u):u=e[31];let h;e[32]!==f||e[33]!==u?(h=n.jsxs("div",{className:"border-t p-3",children:[v,n.jsx($,{"aria-label":"Chat width",value:f,className:"w-full items-stretch gap-1",children:u})]}),e[32]=f,e[33]=u,e[34]=h):h=e[34];let p;e[35]!==m||e[36]!==h?(p=n.jsxs(q,{className:"max-w-sm gap-0 overflow-hidden p-0",children:[E,m,h]}),e[35]=m,e[36]=h,e[37]=p):p=e[37];let T;return e[38]!==t||e[39]!==p||e[40]!==o?(T=n.jsx(J,{open:t,onOpenChange:o,children:p}),e[38]=t,e[39]=p,e[40]=o,e[41]=T):T=e[41],T}function ne(s,e){return n.jsx("div",{className:"size-4 rounded-full border",style:{backgroundColor:s}},e)}export{de as ThemeSelectorModal};
@@ -0,0 +1 @@
1
+ import{c as G,j as s,r as T}from"./vendor-react-gGw_S5I_.js";import{J as le,bm as Ee,bn as mt,aI as ft,aE as xt,bo as Ke,Z as pe,bp as Ve,bq as Qe,ag as je,a0 as Se,a1 as Ce,B as ne,a3 as Te,U as Ie,b3 as Le,a$ as Fe,b0 as De,l as Ue,b1 as Be,A as Ze,b6 as pt,p as Ge,br as ht,bs as gt,bt as jt,L as ze,M as Ae,O as We,Q as Oe,bu as bt,d as Nt,c as wt,S as yt,a as vt,bv as kt,b as St,q as Ct,N as Tt,$ as It}from"./index-CYJLZdyZ.js";import{M as Rt}from"./vendor-markdown-BE1gYnO9.js";import{a6 as Xe,a7 as et,a8 as tt,a9 as $t,aa as Re,R as _t,I as st,z as lt,ab as qe,g as zt,ac as At,ad as Wt,B as Ot,ae as Ye,a as Pt,Y as Mt}from"./vendor-ui-Dxtv9P3W.js";import"./vendor-shiki-DOn6sF-i.js";const Et=new Set(["done","error","skipped"]);function He(l){return Et.has(l)}function Lt(l){return l!=="completed"&&l!=="failed"&&l!=="killed"}function nt(l){switch(l){case"completed":return{label:"Completed",badge:"border-success/30 bg-success/10 text-success",dot:"bg-success"};case"failed":return{label:"Failed",badge:"border-destructive/30 bg-destructive/10 text-destructive",dot:"bg-destructive"};case"killed":return{label:"Stopped",badge:"border-warning/30 bg-warning/10 text-warning",dot:"bg-warning"};default:return{label:"Running",badge:"border-info/30 bg-info/10 text-info",dot:"bg-info"}}}function Ft(l){switch(l){case"done":return{label:"Done",badge:"border-success/30 bg-success/10 text-success",dot:"bg-success"};case"skipped":return{label:"Skipped",badge:"border-border bg-muted/30 text-muted-foreground",dot:"bg-muted-foreground"};case"error":return{label:"Error",badge:"border-destructive/30 bg-destructive/10 text-destructive",dot:"bg-destructive"};case"queued":return{label:"Queued",badge:"border-border bg-muted/30 text-muted-foreground",dot:"bg-muted-foreground"};default:return{label:"Running",badge:"border-info/30 bg-info/10 text-info",dot:"bg-info"}}}function Dt(l){const e=new Map;l.phases.forEach((a,n)=>{const o=n+1;e.set(o,{index:o,title:a.title,detail:a.detail,agents:[]})});const t=[];for(const a of l.agents){const n=e.get(a.phaseIndex);n?n.agents.push(a):t.push(a)}const r=[...e.values()];t.length>0&&r.push({index:r.length+1,title:t[0].phaseTitle||"Other",agents:t});for(const a of r)a.agents.sort((n,o)=>n.index-o.index);return r}function Ut(l){return l.total===0?0:(l.done+l.error)/l.total}const at=["headline","oneLineSell","verdict","summary","name","lens"],Bt=new Set(["title","name"]),Jt=new Set(["headline","oneLineSell","verdict"]);function rt(l){const e=l.trim();if(!e.startsWith("{")&&!e.startsWith("["))return l;try{return JSON.parse(e)}catch{return l}}function qt(l){try{return JSON.parse(`"${l}"`)}catch{return l.replace(/\\n/g," ").replace(/\\"/g,'"')}}function Yt(l){const e=rt(l);if(e!==l)return $e(e);for(const t of at){const r=l.match(new RegExp(`"${t}"\\s*:\\s*"((?:\\\\.|[^"\\\\])*)"`));if(r!=null&&r[1])return qt(r[1])}return l.replace(/^[#>*\s-]+/,"").replace(/[`*_#]/g,"").split(/\n\s*\n|\n/)[0].trim()}function $e(l){if(typeof l=="string")return Yt(l);if(typeof l=="number"||typeof l=="boolean")return String(l);if(Array.isArray(l))return l.length>0?$e(l[0]):"";if(Ee(l))for(const e of at){const t=l[e];if(typeof t=="string"&&t.trim())return t.trim()}return""}function Je(l){if(typeof l=="string")return l;try{return JSON.stringify(l,null,2)}catch{return String(l)}}function Ht(l){const e={oneLineSell:"In one line",quickWins:"Quick wins",whatIsLost:"What is lost",whyItHurts:"Why it hurts",restingState:"Resting state",fatalFlaws:"Fatal flaws",bestIdeasRegardlessOfConcept:"Best ideas across concepts"};return e[l]?e[l]:l.replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/[_-]+/g," ").replace(/^./,t=>t.toUpperCase())}function it(l){const e=G.c(4),{children:t}=l;let r;e[0]!==t?(r=mt(t),e[0]=t,e[1]=r):r=e[1];const a=r;let n;return e[2]!==a?(n=s.jsx(Rt,{components:xt,remarkPlugins:ft,children:a}),e[2]=a,e[3]=n):n=e[3],n}function ot(l){const e=G.c(7),{value:t}=l;if(typeof t=="string"){let n;return e[0]!==t?(n=s.jsx(it,{children:t}),e[0]=t,e[1]=n):n=e[1],n}if(t===null){let n;return e[2]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx("span",{className:"text-muted-foreground",children:"None"}),e[2]=n):n=e[2],n}if(typeof t=="boolean"){const n=t?"Yes":"No";let o;return e[3]!==n?(o=s.jsx("span",{children:n}),e[3]=n,e[4]=o):o=e[4],o}const r=String(t);let a;return e[5]!==r?(a=s.jsx("span",{children:r}),e[5]=r,e[6]=a):a=e[6],a}function Pe(l){const e=G.c(21),{value:t,depth:r}=l,a=r===void 0?0:r;if(!Ee(t)&&!Array.isArray(t)){let o;return e[0]!==t?(o=s.jsx(ot,{value:t}),e[0]=t,e[1]=o):o=e[1],o}if(a>5){let o;e[2]!==t?(o=Je(t),e[2]=t,e[3]=o):o=e[3];let i;return e[4]!==o?(i=s.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap break-words rounded-lg bg-muted p-3 text-xs text-muted-foreground",children:o}),e[4]=o,e[5]=i):i=e[5],i}if(Array.isArray(t)){if(t.length===0){let d;return e[6]===Symbol.for("react.memo_cache_sentinel")?(d=s.jsx("p",{className:"text-sm text-muted-foreground",children:"No items"}),e[6]=d):d=e[6],d}if(t.every(Qt)){let d;e[7]!==t?(d=t.map(Vt),e[7]=t,e[8]=d):d=e[8];let m;return e[9]!==d?(m=s.jsx("ul",{className:"flex list-disc flex-col gap-2 pl-5 marker:text-muted-foreground",children:d}),e[9]=d,e[10]=m):m=e[10],m}let i;if(e[11]!==a||e[12]!==t){let d;e[14]!==a?(d=(m,c)=>s.jsx("article",{className:"border-l pl-4",children:s.jsx(Pe,{value:m,depth:a+1})},c),e[14]=a,e[15]=d):d=e[15],i=t.map(d),e[11]=a,e[12]=t,e[13]=i}else i=e[13];let u;return e[16]!==i?(u=s.jsx("div",{className:"flex flex-col gap-3",children:i}),e[16]=i,e[17]=u):u=e[17],u}let n;if(e[18]!==a||e[19]!==t){const o=Object.entries(t),i=o.find(Kt),u=o.filter(d=>{const[m]=d;return m!==(i==null?void 0:i[0])});n=s.jsxs("div",{className:"flex flex-col gap-4",children:[i&&s.jsx("h3",{className:le("font-semibold text-foreground",a===0?"text-lg":"text-base"),children:i[1]}),u.map(d=>{const[m,c]=d;return c===void 0?null:Jt.has(m)&&typeof c=="string"?s.jsx("div",{className:"border-l-2 border-foreground/30 pl-4 text-sm font-medium leading-relaxed",children:s.jsx(it,{children:c})},m):s.jsxs("section",{className:"flex min-w-0 flex-col gap-2",children:[s.jsx("h4",{className:"text-xs font-medium text-muted-foreground",children:Ht(m)}),s.jsx("div",{className:"min-w-0 text-sm leading-relaxed",children:s.jsx(Pe,{value:c,depth:a+1})})]},m)})]}),e[18]=a,e[19]=t,e[20]=n}else n=e[20];return n}function Kt(l){const[e,t]=l;return Bt.has(e)&&typeof t=="string"&&t.trim().length>0}function Vt(l,e){return s.jsx("li",{className:"pl-1 text-sm leading-relaxed",children:s.jsx(ot,{value:l})},e)}function Qt(l){return!Ee(l)&&!Array.isArray(l)}function Me(l){const e=G.c(19),{value:t,className:r}=l;let a;e[0]!==t?(a=typeof t=="string"?rt(t):t,e[0]=t,e[1]=a):a=e[1];const n=a;if(typeof n=="string"&&(n.trim().startsWith("{")||n.trim().startsWith("["))){let m;e[2]!==n?(m=$e(n),e[2]=n,e[3]=m):m=e[3];const c=m;let x;e[4]!==r?(x=le("flex flex-col gap-2",r),e[4]=r,e[5]=x):x=e[5];let f;e[6]!==c?(f=c&&s.jsx("p",{className:"text-sm leading-relaxed text-foreground",children:c}),e[6]=c,e[7]=f):f=e[7];let h;e[8]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx("p",{className:"text-xs text-muted-foreground",children:"Only a shortened preview was saved for this response."}),e[8]=h):h=e[8];let p;return e[9]!==x||e[10]!==f?(p=s.jsxs("div",{className:x,children:[f,h]}),e[9]=x,e[10]=f,e[11]=p):p=e[11],p}let i;e[12]!==r?(i=le("min-w-0 text-sm",r),e[12]=r,e[13]=i):i=e[13];let u;e[14]!==n?(u=s.jsx(Pe,{value:n}),e[14]=n,e[15]=u):u=e[15];let d;return e[16]!==i||e[17]!==u?(d=s.jsx("div",{className:i,children:u}),e[16]=i,e[17]=u,e[18]=d):d=e[18],d}function Zt(l){return l.replace(/\[[0-9;]*m\]/g,"")}function Gt(l){return(l.includes(":")?l.slice(l.indexOf(":")+1):l).replace(/[-_]+/g," ")}function Xt(l){const e=G.c(135),{agent:t,dirName:r,sessionId:a,runId:n}=l,[o,i]=T.useState(!1),[u,d]=T.useState(!1);let m;e[0]===Symbol.for("react.memo_cache_sentinel")?(m={status:"idle"},e[0]=m):m=e[0];const[c,x]=T.useState(m),[f,h]=Ke();let p,g,j,b,S,C,y,N,v,I,W,Y,R,A,w,k,$,_,O,P,z;if(e[1]!==t||e[2]!==r||e[3]!==o||e[4]!==c.status||e[5]!==c.value||e[6]!==n||e[7]!==a){v=Ft(t.state);let Ne;e[29]!==t.state?(Ne=!He(t.state)&&t.state!=="queued",e[29]=t.state,e[30]=Ne):Ne=e[30],N=Ne;let we;e[31]!==t.resultPreview?(we=t.resultPreview?$e(t.resultPreview):"",e[31]=t.resultPreview,e[32]=we):we=e[32];const ye=we;let ve;e[33]!==t.agentId||e[34]!==r||e[35]!==n||e[36]!==a?(ve=async()=>{x({status:"loading"});try{const he=await Ie(`/api/workflow-agent-result/${encodeURIComponent(r)}/${encodeURIComponent(a)}/${encodeURIComponent(n)}/${encodeURIComponent(t.agentId)}`);if(!he.ok){x({status:"unavailable"});return}const ut=await he.json();x({status:"loaded",value:ut.result})}catch{x({status:"unavailable"})}},e[33]=t.agentId,e[34]=r,e[35]=n,e[36]=a,e[37]=ve):ve=e[37],y=ve;let ke;e[38]!==t.state||e[39]!==y||e[40]!==c.status?(ke=he=>{i(he),he&&c.status==="idle"&&He(t.state)&&y()},e[38]=t.state,e[39]=y,e[40]=c.status,e[41]=ke):ke=e[41];const ct=ke;z=c.status==="loaded"?c.value:t.resultPreview,C=c.status==="unavailable",S=Se,W=o,Y=ct,b=Le,P="sm",I="motion-card motion-list-item gap-0 py-0",j=Fe,O="px-0 py-0",g=Ce,k="group flex w-full items-start gap-3 rounded-lg px-3.5 py-3 text-left outline-none transition-colors hover:bg-muted/40 focus-visible:ring-2 focus-visible:ring-ring/50",$=s.jsx("span",{className:le("mt-1.5 size-2 shrink-0 rounded-full",v.dot)});const dt=t.label;let ae;e[42]!==t.label?(ae=Gt(t.label),e[42]=t.label,e[43]=ae):ae=e[43];let re;e[44]!==t.label||e[45]!==ae?(re=s.jsx(De,{className:"truncate capitalize",title:dt,children:ae}),e[44]=t.label,e[45]=ae,e[46]=re):re=e[46];let ie;e[47]!==t.attempt?(ie=t.attempt&&t.attempt>1&&s.jsxs(pe,{variant:"outline",className:"text-muted-foreground",children:["Attempt ",t.attempt]}),e[47]=t.attempt,e[48]=ie):ie=e[48];let oe;e[49]!==re||e[50]!==ie?(oe=s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[re,ie]}),e[49]=re,e[50]=ie,e[51]=oe):oe=e[51];let ce;e[52]!==t.lastToolName||e[53]!==t.lastToolSummary||e[54]!==N||e[55]!==ye?(ce=ye?s.jsx("p",{className:"mt-1 line-clamp-2 max-w-3xl text-xs leading-relaxed text-muted-foreground",children:ye}):N&&t.lastToolName?s.jsxs("p",{className:"mt-1 truncate text-xs text-muted-foreground",children:["Working in ",t.lastToolName,t.lastToolSummary?`: ${t.lastToolSummary}`:""]}):null,e[52]=t.lastToolName,e[53]=t.lastToolSummary,e[54]=N,e[55]=ye,e[56]=ce):ce=e[56];let de;e[57]!==t.model?(de=t.model&&s.jsx("span",{children:Zt(t.model)}),e[57]=t.model,e[58]=de):de=e[58];let ue;e[59]!==t.tokens?(ue=typeof t.tokens=="number"&&t.tokens>0&&s.jsxs(_e,{icon:Xe,children:[Ve(t.tokens)," tokens"]}),e[59]=t.tokens,e[60]=ue):ue=e[60];let me;e[61]!==t.toolCalls?(me=typeof t.toolCalls=="number"&&t.toolCalls>0&&s.jsxs(_e,{icon:et,children:[t.toolCalls," tools"]}),e[61]=t.toolCalls,e[62]=me):me=e[62];let fe;e[63]!==t.durationMs?(fe=typeof t.durationMs=="number"&&s.jsx(_e,{icon:tt,children:Qe(t.durationMs)}),e[63]=t.durationMs,e[64]=fe):fe=e[64];let xe;e[65]!==de||e[66]!==ue||e[67]!==me||e[68]!==fe?(xe=s.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-muted-foreground",children:[de,ue,me,fe]}),e[65]=de,e[66]=ue,e[67]=me,e[68]=fe,e[69]=xe):xe=e[69],e[70]!==oe||e[71]!==ce||e[72]!==xe?(_=s.jsxs("div",{className:"min-w-0 flex-1",children:[oe,ce,xe]}),e[70]=oe,e[71]=ce,e[72]=xe,e[73]=_):_=e[73],w="flex shrink-0 items-center gap-2",p=pe,R="outline",A=le("hidden sm:inline-flex",v.badge),e[1]=t,e[2]=r,e[3]=o,e[4]=c.status,e[5]=c.value,e[6]=n,e[7]=a,e[8]=p,e[9]=g,e[10]=j,e[11]=b,e[12]=S,e[13]=C,e[14]=y,e[15]=N,e[16]=v,e[17]=I,e[18]=W,e[19]=Y,e[20]=R,e[21]=A,e[22]=w,e[23]=k,e[24]=$,e[25]=_,e[26]=O,e[27]=P,e[28]=z}else p=e[8],g=e[9],j=e[10],b=e[11],S=e[12],C=e[13],y=e[14],N=e[15],v=e[16],I=e[17],W=e[18],Y=e[19],R=e[20],A=e[21],w=e[22],k=e[23],$=e[24],_=e[25],O=e[26],P=e[27],z=e[28];let M;e[74]!==N?(M=N&&s.jsx(je,{"data-icon":"inline-start"}),e[74]=N,e[75]=M):M=e[75];let X;e[76]!==p||e[77]!==v.label||e[78]!==M||e[79]!==R||e[80]!==A?(X=s.jsxs(p,{variant:R,className:A,children:[M,v.label]}),e[76]=p,e[77]=v.label,e[78]=M,e[79]=R,e[80]=A,e[81]=X):X=e[81];let H;e[82]===Symbol.for("react.memo_cache_sentinel")?(H=s.jsx(Re,{className:"mt-0.5 size-4 text-muted-foreground transition-transform group-data-panel-open:rotate-180 motion-reduce:transition-none"}),e[82]=H):H=e[82];let E;e[83]!==X||e[84]!==w?(E=s.jsxs("div",{className:w,children:[X,H]}),e[83]=X,e[84]=w,e[85]=E):E=e[85];let L;e[86]!==g||e[87]!==E||e[88]!==k||e[89]!==$||e[90]!==_?(L=s.jsxs(g,{className:k,children:[$,_,E]}),e[86]=g,e[87]=E,e[88]=k,e[89]=$,e[90]=_,e[91]=L):L=e[91];let ee;e[92]!==j||e[93]!==L||e[94]!==O?(ee=s.jsx(j,{className:O,children:L}),e[92]=j,e[93]=L,e[94]=O,e[95]=ee):ee=e[95];let K;e[96]===Symbol.for("react.memo_cache_sentinel")?(K=s.jsx(Ue,{}),e[96]=K):K=e[96];let V;e[97]===Symbol.for("react.memo_cache_sentinel")?(V=s.jsx("h5",{className:"text-sm font-semibold text-foreground",children:"Response"}),e[97]=V):V=e[97];const te=c.status==="loaded"?"Complete agent response":"Saved response preview";let F;e[98]!==te?(F=s.jsxs("div",{children:[V,s.jsx("p",{className:"text-xs text-muted-foreground",children:te})]}),e[98]=te,e[99]=F):F=e[99];let D;e[100]!==C||e[101]!==y?(D=C&&s.jsxs(ne,{variant:"ghost",size:"sm",onClick:()=>void y(),children:[s.jsx(_t,{"data-icon":"inline-start"}),"Retry"]}),e[100]=C,e[101]=y,e[102]=D):D=e[102];let U;e[103]!==f||e[104]!==h||e[105]!==z?(U=z!==void 0&&s.jsx(ne,{variant:"ghost",size:"icon-sm",onClick:()=>h(Je(z)),"aria-label":f?"Response copied":"Copy response",title:f?"Copied":"Copy response",children:f?s.jsx(st,{"data-icon":"inline-start"}):s.jsx(lt,{"data-icon":"inline-start"})}),e[103]=f,e[104]=h,e[105]=z,e[106]=U):U=e[106];let B;e[107]!==D||e[108]!==U?(B=s.jsxs("div",{className:"flex items-center gap-1",children:[D,U]}),e[107]=D,e[108]=U,e[109]=B):B=e[109];let J;e[110]!==F||e[111]!==B?(J=s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[F,B]}),e[110]=F,e[111]=B,e[112]=J):J=e[112];let q;e[113]!==c.status||e[114]!==N||e[115]!==z?(q=c.status==="loading"?s.jsxs("div",{className:"flex items-center gap-2 py-5 text-sm text-muted-foreground",children:[s.jsx(je,{}),"Loading the complete response…"]}):z!==void 0?s.jsx(Me,{value:z}):s.jsx("p",{className:"text-sm text-muted-foreground",children:N?"This agent has not returned a response yet.":"No response was saved for this agent."}),e[113]=c.status,e[114]=N,e[115]=z,e[116]=q):q=e[116];let Q;e[117]!==t.promptPreview||e[118]!==u?(Q=t.promptPreview&&s.jsxs(Se,{open:u,onOpenChange:d,children:[s.jsxs(Ce,{render:s.jsx(ne,{variant:"ghost",size:"sm",className:"w-full justify-start"}),children:[s.jsx($t,{"data-icon":"inline-start"}),"Agent prompt",s.jsx(Re,{"data-icon":"inline-end",className:le("ml-auto transition-transform",u&&"rotate-180")})]}),s.jsx(Te,{className:"pt-2",children:s.jsx("div",{className:"rounded-md border bg-muted/30 p-3 text-xs leading-relaxed text-muted-foreground",children:s.jsx(Me,{value:t.promptPreview})})})]}),e[117]=t.promptPreview,e[118]=u,e[119]=Q):Q=e[119];let Z;e[120]!==J||e[121]!==q||e[122]!==Q?(Z=s.jsxs(Te,{children:[K,s.jsxs(Be,{className:"flex flex-col gap-4 px-4 py-4",children:[J,q,Q]})]}),e[120]=J,e[121]=q,e[122]=Q,e[123]=Z):Z=e[123];let se;e[124]!==b||e[125]!==I||e[126]!==ee||e[127]!==Z||e[128]!==P?(se=s.jsxs(b,{size:P,className:I,children:[ee,Z]}),e[124]=b,e[125]=I,e[126]=ee,e[127]=Z,e[128]=P,e[129]=se):se=e[129];let be;return e[130]!==S||e[131]!==W||e[132]!==Y||e[133]!==se?(be=s.jsx(S,{open:W,onOpenChange:Y,children:se}),e[130]=S,e[131]=W,e[132]=Y,e[133]=se,e[134]=be):be=e[134],be}function _e(l){const e=G.c(5),{icon:t,children:r}=l;let a;e[0]!==t?(a=s.jsx(t,{className:"size-3"}),e[0]=t,e[1]=a):a=e[1];let n;return e[2]!==r||e[3]!==a?(n=s.jsxs("span",{className:"inline-flex items-center gap-1",children:[a,r]}),e[2]=r,e[3]=a,e[4]=n):n=e[4],n}function es(l){const e=G.c(102),{detail:t,dirName:r,sessionId:a,stopping:n,confirming:o,onForceStop:i}=l;let u,d,m,c,x,f,h,p;if(e[0]!==o||e[1]!==t||e[2]!==r||e[3]!==i||e[4]!==a||e[5]!==n){const C=nt(t.status);let y;e[14]!==t.status?(y=Lt(t.status),e[14]=t.status,e[15]=y):y=e[15];const N=y,v=Dt(t),I=Ut(t.agentCounts),W=N&&t.controllable!==!1;x="flex flex-col gap-6 pb-6";const Y=N&&s.jsx("span",{className:le("size-1.5 rounded-full",C.dot)});let R;e[16]!==C||e[17]!==Y?(R=s.jsxs(pe,{variant:"outline",className:C.badge,children:[Y,C.label]}),e[16]=C,e[17]=Y,e[18]=R):R=e[18];let A;e[19]===Symbol.for("react.memo_cache_sentinel")?(A=s.jsx("span",{className:"text-xs text-muted-foreground",children:"Workflow run"}),e[19]=A):A=e[19];let w;e[20]!==R?(w=s.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[R,A]}),e[20]=R,e[21]=w):w=e[21];let k;e[22]!==t.workflowName?(k=s.jsx("h2",{className:"text-xl font-semibold tracking-tight text-foreground",title:t.workflowName,children:t.workflowName}),e[22]=t.workflowName,e[23]=k):k=e[23];let $;e[24]!==t.summary?($=t.summary&&s.jsx("p",{className:"mt-1.5 max-w-3xl text-sm leading-relaxed text-muted-foreground",children:t.summary}),e[24]=t.summary,e[25]=$):$=e[25];let _;e[26]!==w||e[27]!==k||e[28]!==$?(_=s.jsxs("div",{className:"min-w-0",children:[w,k,$]}),e[26]=w,e[27]=k,e[28]=$,e[29]=_):_=e[29];let O;e[30]!==N||e[31]!==W||e[32]!==o||e[33]!==i||e[34]!==n?(O=N&&i&&s.jsxs("div",{className:"flex shrink-0 flex-col items-start gap-1 sm:items-end",children:[s.jsxs(ne,{variant:o?"destructive":"outline",size:"sm",disabled:!W||n,onClick:i,children:[n?s.jsx(je,{"data-icon":"inline-start"}):s.jsx(qe,{"data-icon":"inline-start"}),o?"Confirm stop":"Stop workflow"]}),!W&&s.jsx("span",{className:"text-xs text-muted-foreground",children:"This run is not controlled by Cogpit"})]}),e[30]=N,e[31]=W,e[32]=o,e[33]=i,e[34]=n,e[35]=O):O=e[35];let P;e[36]!==_||e[37]!==O?(P=s.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between",children:[_,O]}),e[36]=_,e[37]=O,e[38]=P):P=e[38];const z=`${t.agentCounts.done+t.agentCounts.error}/${t.agentCount}`;let M;e[39]!==z?(M=s.jsx(ge,{icon:At,value:z,label:"Agents finished"}),e[39]=z,e[40]=M):M=e[40];const X=String(t.phaseCount);let H;e[41]!==X?(H=s.jsx(ge,{icon:Wt,value:X,label:"Phases"}),e[41]=X,e[42]=H):H=e[42];let E;e[43]!==t.totalTokens?(E=Ve(t.totalTokens),e[43]=t.totalTokens,e[44]=E):E=e[44];let L;e[45]!==E?(L=s.jsx(ge,{icon:Xe,value:E,label:"Tokens"}),e[45]=E,e[46]=L):L=e[46];const ee=String(t.totalToolCalls);let K;e[47]!==ee?(K=s.jsx(ge,{icon:et,value:ee,label:"Tool calls"}),e[47]=ee,e[48]=K):K=e[48];let V;e[49]!==t.durationMs?(V=typeof t.durationMs=="number"?Qe(t.durationMs):"In progress",e[49]=t.durationMs,e[50]=V):V=e[50];let te;e[51]!==V?(te=s.jsx(ge,{icon:tt,value:V,label:"Duration",className:"col-span-2 sm:col-span-1"}),e[51]=V,e[52]=te):te=e[52];let F;e[53]!==M||e[54]!==H||e[55]!==L||e[56]!==K||e[57]!==te?(F=s.jsxs("div",{className:"grid grid-cols-2 gap-px overflow-hidden rounded-lg border bg-border sm:grid-cols-5",children:[M,H,L,K,te]}),e[53]=M,e[54]=H,e[55]=L,e[56]=K,e[57]=te,e[58]=F):F=e[58];let D;e[59]!==I?(D=Math.round(I*100),e[59]=I,e[60]=D):D=e[60];let U;e[61]!==D?(U=s.jsx(jt,{value:D,"aria-label":"Workflow progress",className:"flex-1"}),e[61]=D,e[62]=U):U=e[62];let B;e[63]!==I?(B=Math.round(I*100),e[63]=I,e[64]=B):B=e[64];let J;e[65]!==B?(J=s.jsxs("span",{className:"w-9 text-right text-xs tabular-nums text-muted-foreground",children:[B,"%"]}),e[65]=B,e[66]=J):J=e[66];let q;e[67]!==U||e[68]!==J?(q=s.jsxs("div",{className:"flex items-center gap-3",children:[U,J]}),e[67]=U,e[68]=J,e[69]=q):q=e[69],e[70]!==P||e[71]!==F||e[72]!==q?(f=s.jsxs("section",{className:"flex flex-col gap-4",children:[P,F,q]}),e[70]=P,e[71]=F,e[72]=q,e[73]=f):f=e[73],e[74]!==t.error?(h=t.error&&s.jsxs(Ze,{variant:"destructive",children:[s.jsx(qe,{}),s.jsx(pt,{children:"Workflow error"}),s.jsx(Ge,{children:s.jsx("pre",{className:"max-h-40 overflow-auto whitespace-pre-wrap break-words font-mono text-xs",children:t.error})})]}),e[74]=t.error,e[75]=h):h=e[75],e[76]!==t.resultPreview||e[77]!==t.runId||e[78]!==r||e[79]!==a?(p=t.resultPreview&&s.jsx(ns,{preview:t.resultPreview,dirName:r,sessionId:a,runId:t.runId}),e[76]=t.resultPreview,e[77]=t.runId,e[78]=r,e[79]=a,e[80]=p):p=e[80],m="grid items-start gap-6 md:grid-cols-[180px_minmax(0,1fr)]";let Q;e[81]===Symbol.for("react.memo_cache_sentinel")?(Q=s.jsx("p",{className:"px-2 pb-2 pt-1 text-xs font-medium text-muted-foreground",children:"Run outline"}),e[81]=Q):Q=e[81],c=s.jsxs("nav",{className:"sticky top-0 hidden rounded-lg border bg-popover p-2 md:block","aria-label":"Workflow phases",children:[Q,s.jsx("div",{className:"flex flex-col gap-1",children:v.map(ts)})]}),u="flex min-w-0 flex-col gap-8";let Z;e[82]!==t.runId||e[83]!==r||e[84]!==a?(Z=se=>s.jsx(ss,{group:se,dirName:r,sessionId:a,runId:t.runId},`${se.index}-${se.title}`),e[82]=t.runId,e[83]=r,e[84]=a,e[85]=Z):Z=e[85],d=v.map(Z),e[0]=o,e[1]=t,e[2]=r,e[3]=i,e[4]=a,e[5]=n,e[6]=u,e[7]=d,e[8]=m,e[9]=c,e[10]=x,e[11]=f,e[12]=h,e[13]=p}else u=e[6],d=e[7],m=e[8],c=e[9],x=e[10],f=e[11],h=e[12],p=e[13];let g;e[86]!==u||e[87]!==d?(g=s.jsx("div",{className:u,children:d}),e[86]=u,e[87]=d,e[88]=g):g=e[88];let j;e[89]!==m||e[90]!==c||e[91]!==g?(j=s.jsxs("div",{className:m,children:[c,g]}),e[89]=m,e[90]=c,e[91]=g,e[92]=j):j=e[92];let b;e[93]!==t.script?(b=t.script&&s.jsx(as,{script:t.script}),e[93]=t.script,e[94]=b):b=e[94];let S;return e[95]!==j||e[96]!==b||e[97]!==x||e[98]!==f||e[99]!==h||e[100]!==p?(S=s.jsxs("div",{className:x,children:[f,h,p,j,b]}),e[95]=j,e[96]=b,e[97]=x,e[98]=f,e[99]=h,e[100]=p,e[101]=S):S=e[101],S}function ts(l){return s.jsxs(ne,{variant:"ghost",size:"sm",type:"button",onClick:()=>{var e;return(e=document.getElementById(`workflow-phase-${l.index}`))==null?void 0:e.scrollIntoView({behavior:"smooth",block:"start"})},className:"h-auto w-full justify-start gap-2 px-2 py-2 text-left text-xs text-muted-foreground",children:[s.jsx("span",{className:"flex size-5 shrink-0 items-center justify-center rounded-md bg-muted text-xs font-medium text-foreground",children:l.index}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:l.title}),s.jsx("span",{className:"tabular-nums",children:l.agents.length})]},`${l.index}-${l.title}`)}function ge(l){const e=G.c(15),{icon:t,value:r,label:a,className:n}=l;let o;e[0]!==n?(o=le("flex items-center gap-2.5 bg-card px-3 py-3",n),e[0]=n,e[1]=o):o=e[1];let i;e[2]!==t?(i=s.jsx(t,{className:"size-4 shrink-0 text-muted-foreground"}),e[2]=t,e[3]=i):i=e[3];let u;e[4]!==r?(u=s.jsx("p",{className:"truncate text-sm font-semibold tabular-nums text-foreground",children:r}),e[4]=r,e[5]=u):u=e[5];let d;e[6]!==a?(d=s.jsx("p",{className:"truncate text-xs text-muted-foreground",children:a}),e[6]=a,e[7]=d):d=e[7];let m;e[8]!==u||e[9]!==d?(m=s.jsxs("div",{className:"min-w-0",children:[u,d]}),e[8]=u,e[9]=d,e[10]=m):m=e[10];let c;return e[11]!==o||e[12]!==i||e[13]!==m?(c=s.jsxs("div",{className:o,children:[i,m]}),e[11]=o,e[12]=i,e[13]=m,e[14]=c):c=e[14],c}function ss(l){const e=G.c(29),{group:t,dirName:r,sessionId:a,runId:n}=l;let o;e[0]!==t.agents?(o=t.agents.filter(ls),e[0]=t.agents,e[1]=o):o=e[1];const i=o.length,u=`workflow-phase-${t.index}`;let d;e[2]!==t.index?(d=s.jsx("span",{className:"flex size-7 shrink-0 items-center justify-center rounded-lg bg-primary text-xs font-semibold text-primary-foreground",children:t.index}),e[2]=t.index,e[3]=d):d=e[3];let m;e[4]!==t.title?(m=s.jsx("h3",{className:"text-base font-semibold text-foreground",children:t.title}),e[4]=t.title,e[5]=m):m=e[5];let c;e[6]!==i||e[7]!==t.agents.length?(c=s.jsxs("span",{className:"text-xs text-muted-foreground",children:[i,"/",t.agents.length," complete"]}),e[6]=i,e[7]=t.agents.length,e[8]=c):c=e[8];let x;e[9]!==m||e[10]!==c?(x=s.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[m,c]}),e[9]=m,e[10]=c,e[11]=x):x=e[11];let f;e[12]!==t.detail?(f=t.detail&&s.jsx("p",{className:"mt-0.5 text-xs leading-relaxed text-muted-foreground",children:t.detail}),e[12]=t.detail,e[13]=f):f=e[13];let h;e[14]!==x||e[15]!==f?(h=s.jsxs("div",{className:"min-w-0 flex-1",children:[x,f]}),e[14]=x,e[15]=f,e[16]=h):h=e[16];let p;e[17]!==d||e[18]!==h?(p=s.jsxs("div",{className:"mb-3 flex items-start gap-3",children:[d,h]}),e[17]=d,e[18]=h,e[19]=p):p=e[19];let g;e[20]!==r||e[21]!==t.agents||e[22]!==n||e[23]!==a?(g=t.agents.length===0?s.jsx(ze,{className:"border py-6",children:s.jsxs(Ae,{children:[s.jsx(We,{children:"No agents yet"}),s.jsx(Oe,{children:"No agents have started this phase."})]})}):s.jsx("div",{className:"flex flex-col gap-2",children:t.agents.map(b=>s.jsx(Xt,{agent:b,dirName:r,sessionId:a,runId:n},`${n}:${b.agentId||b.index}`))}),e[20]=r,e[21]=t.agents,e[22]=n,e[23]=a,e[24]=g):g=e[24];let j;return e[25]!==g||e[26]!==u||e[27]!==p?(j=s.jsxs("section",{id:u,className:"scroll-mt-4",children:[p,g]}),e[25]=g,e[26]=u,e[27]=p,e[28]=j):j=e[28],j}function ls(l){return l.state==="done"||l.state==="skipped"}function ns({preview:l,dirName:e,sessionId:t,runId:r}){const[a,n]=T.useState(!0),[o,i]=T.useState(),[u,d]=T.useState(!1),[m,c]=T.useState(!1),[x,f]=Ke(),h=l.endsWith("…"),p=o??l,g=T.useCallback(async()=>{d(!0),c(!1);try{const j=await Ie(`/api/workflow-result/${encodeURIComponent(e)}/${encodeURIComponent(t)}/${encodeURIComponent(r)}`);if(!j.ok){c(!0);return}const b=await j.json();i(b.result)}catch{c(!0)}finally{d(!1)}},[e,r,t]);return s.jsx(Se,{open:a,onOpenChange:n,children:s.jsxs(Le,{className:"motion-enter gap-0 py-0",children:[s.jsxs(Fe,{className:"py-4",children:[s.jsxs(Ce,{className:"group flex min-w-0 items-center gap-3 text-left outline-none",children:[s.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-lg bg-muted text-muted-foreground",children:s.jsx(zt,{className:"size-4"})}),s.jsxs("span",{className:"min-w-0",children:[s.jsx(De,{children:"Workflow outcome"}),s.jsx(ht,{children:"The synthesized answer from this run"})]}),s.jsx(Re,{className:"size-4 shrink-0 text-muted-foreground transition-transform group-data-panel-open:rotate-180 motion-reduce:transition-none"})]}),s.jsxs(gt,{className:"flex items-center gap-1",children:[h&&o===void 0&&s.jsxs(ne,{variant:"outline",size:"sm",disabled:u,onClick:()=>void g(),children:[u&&s.jsx(je,{"data-icon":"inline-start"}),m?"Retry full result":"Load full result"]}),s.jsx(ne,{variant:"ghost",size:"icon-sm",onClick:()=>f(Je(p)),"aria-label":x?"Outcome copied":"Copy outcome",title:x?"Copied":"Copy outcome",children:x?s.jsx(st,{"data-icon":"inline-start"}):s.jsx(lt,{"data-icon":"inline-start"})})]})]}),s.jsxs(Te,{children:[s.jsx(Ue,{}),s.jsx(Be,{className:"py-5",children:s.jsx(Me,{value:p})})]})]})})}function as(l){const e=G.c(7),{script:t}=l,[r,a]=T.useState(!1);let n;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx(Fe,{className:"px-0 py-0",children:s.jsxs(Ce,{className:"group flex w-full items-center gap-2 px-3 py-3 text-left text-sm font-medium text-muted-foreground outline-none transition-colors hover:bg-muted/40 hover:text-foreground",children:[s.jsx(Ot,{className:"size-4"}),s.jsx(De,{children:"Orchestration script"}),s.jsx(Re,{className:"ml-auto size-4 transition-transform group-data-panel-open:rotate-180"})]})}),e[0]=n):n=e[0];let o;e[1]===Symbol.for("react.memo_cache_sentinel")?(o=s.jsx(Ue,{}),e[1]=o):o=e[1];let i;e[2]!==t?(i=s.jsxs(Le,{size:"sm",className:"gap-0 py-0",children:[n,s.jsxs(Te,{children:[o,s.jsx(Be,{className:"py-3",children:s.jsx("pre",{className:"max-h-96 overflow-auto whitespace-pre-wrap break-words rounded-lg bg-muted p-3 text-xs leading-relaxed text-muted-foreground",children:t})})]})]}),e[2]=t,e[3]=i):i=e[3];let u;return e[4]!==r||e[5]!==i?(u=s.jsx(Se,{open:r,onOpenChange:a,children:i}),e[4]=r,e[5]=i,e[6]=u):u=e[6],u}function ms({open:l,onOpenChange:e,dirName:t,sessionId:r,workflows:a,isLive:n,canStop:o,onRefetchList:i}){var A;const[u,d]=T.useState(null),[m,c]=T.useState(!1),[x,f]=T.useState(null),[h,p]=T.useState(!1),[g,j]=T.useState(!1),[b,S]=T.useState(!1),[C,y]=T.useState(null),N=T.useRef(0),v=m?null:u&&a.some(w=>w.runId===u)?u:((A=a[0])==null?void 0:A.runId)??null,I=T.useCallback(async()=>{const w=++N.current;if(!t||!r||!v){f(null);return}try{const k=await Ie(`/api/workflow-detail/${encodeURIComponent(t)}/${encodeURIComponent(r)}/${encodeURIComponent(v)}`);if(!k.ok){w===N.current&&f(null);return}const $=await k.json();w===N.current&&f($)}catch{w===N.current&&f(null)}finally{w===N.current&&p(!1)}},[t,r,v]);T.useEffect(()=>{if(!v){f(null);return}f(null),p(!0),S(!1),y(null),I()},[v,I]),bt(l?t:null,l?r:null,l?v:null,()=>{I(),i()});const W=T.useCallback(async()=>{if(!b){S(!0);return}if(!(!r||!v)){j(!0),y(null);try{const k=await(await Ie("/api/workflow-stop",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:r,runId:v})})).json().catch(()=>({}));k!=null&&k.success?y("Stop signal sent."):(k==null?void 0:k.controllable)===!1?y("This workflow runs in a session Cogpit doesn't control."):y("Couldn't stop. The session may have already exited."),I(),i()}catch{y("Stop request failed.")}finally{j(!1),S(!1)}}},[b,r,v,I,i]),Y=a.length>1,R=a.find(w=>w.runId===v);return s.jsx(Nt,{open:l,onOpenChange:e,children:s.jsxs(wt,{side:"right",className:"w-full data-[side=right]:max-w-[1120px]",children:[s.jsx(yt,{className:"min-h-14 justify-center border-b py-3",children:s.jsxs("div",{className:"flex items-center justify-between gap-3 pr-9",children:[s.jsxs(vt,{className:"flex items-center gap-2",children:[s.jsx(Ye,{className:"size-4"}),"Workflows",a.length>0&&s.jsx(pe,{variant:"secondary",children:a.length}),n&&s.jsxs(pe,{variant:"outline",className:"border-info/30 text-info",children:[s.jsx(kt,{className:"size-1.5"}),"Live"]})]}),s.jsx(St,{className:"sr-only",children:"Inspect workflow runs, agent progress, and run controls for this session."}),s.jsx(ne,{variant:"ghost",size:"icon-sm",onClick:i,"aria-label":"Refresh workflows",title:"Refresh workflows",children:s.jsx(Pt,{"data-icon":"inline-start"})})]})}),s.jsx(Ct,{className:"h-[calc(100dvh-3.5rem)]",children:s.jsx("div",{className:"px-5 py-6 sm:px-6",children:a.length===0?s.jsx(ze,{className:"min-h-[60dvh]",children:s.jsxs(Ae,{children:[s.jsx(Tt,{variant:"icon",children:s.jsx(Ye,{})}),s.jsx(We,{children:"No workflows in this session"}),s.jsx(Oe,{children:"Phases, agents, and their responses will appear here when this session starts a workflow."})]})}):s.jsxs(s.Fragment,{children:[Y&&s.jsxs("div",{className:"mb-6 flex flex-col gap-2",children:[v&&x&&s.jsxs(ne,{variant:"ghost",size:"sm",onClick:()=>c(!0),className:"w-fit px-2 text-muted-foreground",children:[s.jsx(Mt,{"data-icon":"inline-start"}),"All runs"]}),(!v||!x)&&a.map(w=>s.jsx(rs,{workflow:w,active:w.runId===v,onClick:()=>{d(w.runId),c(!1)}},w.runId))]}),h&&!x?s.jsxs("div",{className:"flex min-h-[50dvh] items-center justify-center gap-2 text-sm text-muted-foreground",children:[s.jsx(je,{}),"Loading workflow…"]}):x?s.jsxs(s.Fragment,{children:[C&&s.jsx(Ze,{className:"mb-4",children:s.jsx(Ge,{children:C})}),s.jsx(es,{detail:x,dirName:t??"",sessionId:r??"",stopping:g,confirming:b,onForceStop:o?W:void 0})]}):R?s.jsx(ze,{className:"min-h-[50dvh]",children:s.jsxs(Ae,{children:[s.jsx(We,{children:"Could not load this workflow"}),s.jsx(Oe,{children:"The journal may have moved or the run may no longer be available."})]})}):null]})})})]})})}function rs(l){const e=G.c(45),{workflow:t,active:r,onClick:a}=l;let n,o,i,u,d,m,c;if(e[0]!==r||e[1]!==a||e[2]!==t.agentCounts.done||e[3]!==t.agentCounts.error||e[4]!==t.status){i=nt(t.status),o=t.agentCounts.done+t.agentCounts.error,n=ne,d="ghost",m=a;const N=r?"border-foreground/20 bg-accent":"bg-background hover:bg-muted/50";e[12]!==N?(c=le("h-auto w-full justify-start gap-3 whitespace-normal border px-3 py-3 text-left",N),e[12]=N,e[13]=c):c=e[13],u=le("size-2 shrink-0 rounded-full",i.dot),e[0]=r,e[1]=a,e[2]=t.agentCounts.done,e[3]=t.agentCounts.error,e[4]=t.status,e[5]=n,e[6]=o,e[7]=i,e[8]=u,e[9]=d,e[10]=m,e[11]=c}else n=e[5],o=e[6],i=e[7],u=e[8],d=e[9],m=e[10],c=e[11];let x;e[14]!==u?(x=s.jsx("span",{className:u}),e[14]=u,e[15]=x):x=e[15];let f;e[16]!==t.workflowName?(f=s.jsx("span",{className:"truncate text-sm font-medium text-foreground",children:t.workflowName}),e[16]=t.workflowName,e[17]=f):f=e[17];let h;e[18]!==i.badge||e[19]!==i.label?(h=s.jsx(pe,{variant:"outline",className:i.badge,children:i.label}),e[18]=i.badge,e[19]=i.label,e[20]=h):h=e[20];let p;e[21]!==f||e[22]!==h?(p=s.jsxs("div",{className:"flex items-center gap-2",children:[f,h]}),e[21]=f,e[22]=h,e[23]=p):p=e[23];let g;e[24]!==t.summary?(g=t.summary&&s.jsx("p",{className:"mt-1 line-clamp-1 text-xs text-muted-foreground",children:t.summary}),e[24]=t.summary,e[25]=g):g=e[25];let j;e[26]!==o||e[27]!==t.agentCount?(j=s.jsxs("span",{children:[o,"/",t.agentCount," agents"]}),e[26]=o,e[27]=t.agentCount,e[28]=j):j=e[28];let b;e[29]!==t.startTime?(b=t.startTime>0&&s.jsx("span",{children:It(new Date(t.startTime).toISOString())}),e[29]=t.startTime,e[30]=b):b=e[30];let S;e[31]!==j||e[32]!==b?(S=s.jsxs("div",{className:"mt-1.5 flex items-center gap-2 text-xs text-muted-foreground",children:[j,b]}),e[31]=j,e[32]=b,e[33]=S):S=e[33];let C;e[34]!==S||e[35]!==p||e[36]!==g?(C=s.jsxs("div",{className:"min-w-0 flex-1",children:[p,g,S]}),e[34]=S,e[35]=p,e[36]=g,e[37]=C):C=e[37];let y;return e[38]!==n||e[39]!==C||e[40]!==d||e[41]!==m||e[42]!==c||e[43]!==x?(y=s.jsxs(n,{variant:d,onClick:m,className:c,children:[x,C]}),e[38]=n,e[39]=C,e[40]=d,e[41]=m,e[42]=c,e[43]=x,e[44]=y):y=e[44],y}export{ms as WorkflowsPanel};