@wrongstack/webui 0.257.0 → 0.257.2

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.
@@ -83,28 +83,24 @@ ${o.join(``)}
83
83
  `),[e]),o=a.length>$a,[s,c]=(0,B.useState)(!o),l=s?e:a.slice(0,eo).join(`
84
84
  `),u=!!i&&o&&s;return(0,X.jsxs)(`div`,{className:Y(`rounded-md border bg-background/40 overflow-hidden`,n),children:[u?(0,X.jsxs)(`div`,{className:`flex max-h-96 overflow-auto`,children:[(0,X.jsx)(`pre`,{"aria-hidden":!0,className:`text-xs font-mono leading-[1.4] py-2 pl-2 pr-2 text-muted-foreground/50 select-none border-r border-border/40 bg-muted/20 tabular-nums text-right whitespace-pre shrink-0`,children:a.map((e,t)=>`${t+1}`).join(`
85
85
  `)}),(0,X.jsx)(`pre`,{className:Y(`text-xs font-mono leading-[1.4] py-2 px-2 flex-1 whitespace-pre`,t?`text-destructive`:`text-foreground`),children:l})]}):(0,X.jsx)(`pre`,{className:Y(`text-xs font-mono p-2 max-h-96 overflow-auto`,r,t?`text-destructive`:`text-foreground`),children:l}),o&&(0,X.jsx)(`button`,{type:`button`,onClick:()=>c(e=>!e),className:`w-full flex items-center justify-center gap-1 px-2 py-1 border-t bg-muted/30 text-[11px] text-muted-foreground hover:text-foreground transition-colors`,children:s?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Le,{className:`h-3 w-3`}),`Collapse to first `,eo,` lines`]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Ue,{className:`h-3 w-3`}),`Show all `,a.length,` lines (`,a.length-eo,` more)`]})})]})}var no=(0,B.memo)(function({toolName:e,result:t,isError:n,className:r}){let i=(0,B.useMemo)(()=>ro(e,t),[e,t]);return i.kind===`json`?(0,X.jsx)(io,{value:i.value,isError:n,className:r}):i.kind===`numbered`?(0,X.jsx)(to,{text:t,isError:n,className:r,wrapClass:`whitespace-pre`}):i.kind===`bash`?(0,X.jsxs)(`div`,{className:Y(`rounded-md border bg-background/40 overflow-hidden`,r),children:[i.stdout&&(0,X.jsx)(to,{text:i.stdout,isError:n,className:`border-0 rounded-none bg-transparent`,wrapClass:`whitespace-pre-wrap break-all`,showLineNumbers:!0}),(i.exitCode!==void 0||i.duration)&&(0,X.jsxs)(`div`,{className:Y(`flex items-center gap-3 text-[11px] px-2 py-1 border-t bg-muted/30 tabular-nums`,i.exitCode&&i.exitCode!==0?`text-destructive`:`text-muted-foreground`),children:[i.exitCode!==void 0&&(0,X.jsxs)(`span`,{children:[`exit code: `,(0,X.jsx)(`span`,{className:`font-mono`,children:i.exitCode})]}),i.duration&&(0,X.jsx)(`span`,{children:i.duration})]})]}):(0,X.jsx)(to,{text:t,isError:n,className:r,wrapClass:`whitespace-pre-wrap break-all`,showLineNumbers:!0})});function ro(e,t){let n=t.trim();if(/^\s*\d+→/m.test(t.slice(0,200)))return{kind:`numbered`};if(n.startsWith(`{`)&&n.endsWith(`}`)||n.startsWith(`[`)&&n.endsWith(`]`))try{let e=JSON.parse(n);if(typeof e==`object`&&e)return{kind:`json`,value:e}}catch{}let r=!!e&&/^(bash|shell|exec|run)/i.test(e),i=t.match(/(?:^|\n)\s*(?:\[?exit(?:\s*code)?\]?\s*[:=]?\s*)(\d+)\s*$/i),a=t.match(/(?:^|\s)(\d+\s*ms|\d+\.\d+s)\s*$/i);if(r||i){let e=t;return i&&(e=t.slice(0,i.index).trimEnd()),{kind:`bash`,stdout:e,exitCode:i?Number(i[1]):void 0,duration:a?.[1]}}return{kind:`plain`}}function io({value:e,isError:t,className:r}){let i=(0,B.useMemo)(()=>{try{return JSON.stringify(e,null,2)}catch{return String(e)}},[e]),a=i.split(`
86
- `).length,[o,s]=(0,B.useState)(a<30);return(0,X.jsxs)(`div`,{className:Y(`rounded-md border bg-background/40 overflow-hidden`,t&&`border-destructive/40`,r),children:[(0,X.jsxs)(`button`,{type:`button`,onClick:()=>s(e=>!e),className:`w-full flex items-center justify-between px-2 py-1 border-b bg-muted/30 text-[11px] text-muted-foreground hover:text-foreground`,children:[(0,X.jsxs)(`span`,{className:`flex items-center gap-1`,children:[o?(0,X.jsx)(ut,{className:`h-3 w-3`}):(0,X.jsx)(n,{className:`h-3 w-3`}),(0,X.jsxs)(`span`,{className:`font-mono`,children:[`JSON · `,a,` lines`]})]}),(0,X.jsx)(`span`,{children:o?`collapse`:`expand`})]}),o&&(0,X.jsx)(`pre`,{className:Y(`text-xs font-mono whitespace-pre p-2 max-h-96 overflow-auto`,t?`text-destructive`:`text-foreground`),children:i})]})}var ao=/💡\s*Next steps?\s*\n+((?:\d+\.\s+.+(?:\s+auto="true")?\n?)+)/i,oo=/^(\d+)\.\s+(.+?)(?:\s+auto="true")?$/;function so(e){let t=ao.exec(e);if(!t?.[1])return[];let n=t[1].split(`
87
- `).filter(Boolean),r=[];for(let e of n){let t=oo.exec(e.trim());if(t){let n=t[2].trim(),i=e.trim().endsWith(`auto="true"`);r.push({index:Number.parseInt(t[1],10),text:n,auto:i})}}return r.slice(0,6)}function co(e){let t=document.querySelector(`textarea`);t&&((Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype,`value`)?.set)?.call(t,e),t.dispatchEvent(new Event(`input`,{bubbles:!0})),t.focus())}function lo({delayMs:e,onComplete:t}){let[n,r]=(0,B.useState)(Math.ceil(e/1e3));return(0,B.useEffect)(()=>{if(n<=0){t();return}let e=setTimeout(()=>r(e=>e-1),1e3);return()=>clearTimeout(e)},[n,t]),(0,X.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-primary font-medium`,children:[(0,X.jsx)(It,{className:`h-3 w-3`}),n,`s`]})}function uo({steps:e,yoloMode:t=!1,autoMode:n=!1,autoDelayMs:r=3e4,onAutoSubmit:i}){if(e.length===0)return null;let a=t&&n,o=a?e.find(e=>e.auto):void 0;return(0,X.jsxs)(`div`,{className:`mt-4 rounded-xl border border-primary/20 bg-primary/[0.03] overflow-hidden animate-message`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 px-3.5 py-2 border-b border-primary/10 bg-primary/[0.04]`,children:[(0,X.jsx)(`span`,{className:`flex items-center justify-center w-5 h-5 rounded-md bg-primary/15 text-primary`,children:(0,X.jsx)(Ht,{className:`h-3 w-3`})}),(0,X.jsx)(`span`,{className:`text-xs font-semibold text-foreground/90`,children:`Next steps`}),a&&o?(0,X.jsxs)(`span`,{className:`ml-auto flex items-center gap-1 text-xs text-primary`,children:[(0,X.jsx)(It,{className:`h-3 w-3`}),`auto-submitting in `,(0,X.jsx)(lo,{delayMs:r,onComplete:()=>i?.(o.text)})]}):(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground ml-auto`,children:`click to fill input`})]}),(0,X.jsx)(`div`,{className:`flex flex-col p-2 gap-1`,children:e.map(e=>{let t=a&&e.auto;return(0,X.jsxs)(`button`,{type:`button`,onClick:()=>co(e.text),className:`group flex items-center gap-2.5 w-full text-left px-3 py-2 rounded-lg transition-all border ${t?`bg-primary/10 border-primary/30 ring-1 ring-primary/20`:`border-transparent hover:bg-primary/[0.08] hover:shadow-sm hover:border-primary/20`}`,title:`Click to fill: ${e.text}`,children:[(0,X.jsx)(`span`,{className:`flex items-center justify-center w-5 h-5 rounded-md text-[11px] font-mono font-semibold tabular-nums shrink-0 transition-colors ${t?`bg-primary/30 text-primary`:`bg-muted/80 group-hover:bg-primary/20 text-muted-foreground group-hover:text-primary`}`,children:e.index}),(0,X.jsx)(ln,{className:`h-3.5 w-3.5 shrink-0 transition-all ${t?`text-primary`:`text-muted-foreground/60 group-hover:text-primary group-hover:translate-x-0.5`}`}),(0,X.jsx)(`span`,{className:`text-sm leading-snug flex-1 min-w-0 transition-colors ${t?`text-foreground font-medium`:`text-foreground/80 group-hover:text-foreground`}`,children:e.text}),e.auto&&(0,X.jsxs)(`span`,{className:`flex items-center gap-1 text-[10px] text-primary/70`,children:[(0,X.jsx)(It,{className:`h-3 w-3`}),`auto`]}),(0,X.jsx)(D,{className:`h-3.5 w-3.5 shrink-0 transition-all ${t?`opacity-100 text-primary/60`:`opacity-0 group-hover:opacity-100 text-primary/60`}`})]},e.index)})})]})}async function fo(e){try{if(typeof navigator<`u`&&navigator.clipboard?.writeText)return await navigator.clipboard.writeText(e),!0}catch{}try{let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t),t.select();let n=document.execCommand(`copy`);return document.body.removeChild(t),n}catch{return!1}}function po(e,t){if(typeof document>`u`)return;let n=new Blob([t],{type:`text/plain;charset=utf-8`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=e,document.body.appendChild(i),i.click(),document.body.removeChild(i),setTimeout(()=>URL.revokeObjectURL(r),1e3)}function mo(e){let t=(e??``).toLowerCase();return/bash|shell|exec|run/.test(t)?`log`:(/grep|search|find/.test(t),`txt`)}function ho(e){return e<1e3?`${e} ms`:e<6e4?`${(e/1e3).toFixed(e<1e4?2:1)}s`:`${Math.floor(e/6e4)}m ${Math.floor(e%6e4/1e3)}s`}var go=[T];function _o({text:e}){let[t,n]=(0,B.useState)(!1);return(0,X.jsxs)(`button`,{type:`button`,onClick:(0,B.useCallback)(async()=>{await fo(e)&&(n(!0),setTimeout(()=>n(!1),1500))},[e]),className:Y(`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] transition-colors`,`hover:bg-muted-foreground/10`,t?`text-emerald-500`:`text-muted-foreground hover:text-foreground`),title:t?`Copied!`:`Copy code`,children:[t?(0,X.jsx)(pn,{className:`h-3 w-3`}):(0,X.jsx)(E,{className:`h-3 w-3`}),(0,X.jsx)(`span`,{children:t?`Copied`:`Copy`})]})}var vo={next_steps({children:e}){let t=so(typeof e==`string`?e:``);return t.length===0?null:(0,X.jsxs)(`div`,{className:`mt-4 rounded-xl border border-primary/20 bg-primary/[0.03] overflow-hidden animate-message`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 px-3.5 py-2 border-b border-primary/10 bg-primary/[0.04]`,children:[(0,X.jsx)(`span`,{className:`flex items-center justify-center w-5 h-5 rounded-md bg-primary/15 text-primary text-xs`,children:`💡`}),(0,X.jsx)(`span`,{className:`text-xs font-semibold text-foreground/90`,children:`Next steps`}),(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground ml-auto`,children:`click to fill input`})]}),(0,X.jsx)(`div`,{className:`flex flex-col p-2 gap-1`,children:t.map(e=>(0,X.jsxs)(`button`,{type:`button`,onClick:()=>co(e.text),className:`group flex items-center gap-2.5 w-full text-left px-3 py-2 rounded-lg transition-all
88
- hover:bg-primary/[0.08] hover:shadow-sm
89
- border border-transparent hover:border-primary/20 cursor-pointer`,title:`Click to fill: ${e.text}`,children:[(0,X.jsx)(`span`,{className:`flex items-center justify-center w-5 h-5 rounded-md bg-muted/80 group-hover:bg-primary/20
90
- text-[11px] font-mono font-semibold tabular-nums shrink-0
91
- text-muted-foreground group-hover:text-primary transition-colors`,children:e.index}),(0,X.jsx)(`span`,{className:`h-3.5 w-3.5 text-muted-foreground/60 group-hover:text-primary group-hover:translate-x-0.5 transition-all shrink-0 text-xs`,children:`→`}),(0,X.jsx)(`span`,{className:`text-sm leading-snug text-foreground/80 group-hover:text-foreground transition-colors flex-1 min-w-0`,children:e.text}),(0,X.jsx)(`span`,{className:`opacity-0 group-hover:opacity-100 text-primary/60 transition-all shrink-0 text-xs`,children:`↗`})]},e.index))})]})},code({inline:e,className:t,children:n,...r}){let i=/language-(\w+)/.exec(t??``),a=String(n??``).replace(/\n$/,``);if(e||!i)return(0,X.jsx)(`code`,{className:Y(`rounded border border-border/60 px-1.5 py-0.5 text-[0.85em] font-mono`,t),...r,children:n});let o=(0,B.useMemo)(()=>a.split(`
92
- `),[a]),s=o.length>1;return(0,X.jsxs)(`div`,{className:`not-prose relative my-3 rounded-lg border border-border overflow-hidden group/codeblock`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-1 border-b border-border text-xs`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(jt,{className:`h-3 w-3 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`font-mono text-muted-foreground font-medium`,children:i[1]}),o.length>0&&(0,X.jsxs)(`span`,{className:`text-[10px] text-muted-foreground/60 tabular-nums`,children:[o.length,` line`,o.length===1?``:`s`]})]}),(0,X.jsx)(_o,{text:a})]}),s?(0,X.jsxs)(`div`,{className:`flex max-h-[40rem] overflow-auto`,children:[(0,X.jsx)(`pre`,{"aria-hidden":!0,className:`text-xs font-mono leading-[1.55] py-3 pl-3 pr-2 text-muted-foreground/40 select-none border-r border-border/30 tabular-nums text-right shrink-0`,children:o.map((e,t)=>(0,X.jsx)(`div`,{children:t+1},t))}),(0,X.jsx)(`pre`,{className:`overflow-x-auto py-3 px-3 text-xs leading-[1.55] font-mono flex-1`,children:(0,X.jsx)(`code`,{className:Y(`hljs`,t),...r,children:n})})]}):(0,X.jsx)(`pre`,{className:`overflow-x-auto p-3 text-xs leading-relaxed font-mono max-h-[40rem]`,children:(0,X.jsx)(`code`,{className:Y(`hljs`,t),...r,children:n})}),(0,X.jsx)(`div`,{className:`pointer-events-none absolute bottom-8 left-0 right-0 h-8 bg-gradient-to-t from-black/10 to-transparent opacity-0 group-hover/codeblock:opacity-100 transition-opacity`})]})}};function yo({text:e,className:t,label:n=`Copy`}){let[r,i]=(0,B.useState)(!1);return(0,X.jsx)(`button`,{type:`button`,onClick:async t=>{t.stopPropagation(),await fo(e)&&(i(!0),setTimeout(()=>i(!1),1400))},className:Y(`inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors`,t),title:n,children:r?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(pn,{className:`h-3 w-3 text-green-500`}),(0,X.jsx)(`span`,{children:`Copied`})]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(E,{className:`h-3 w-3`}),(0,X.jsx)(`span`,{children:n})]})})}function bo(e){let t=e.split(`
93
- `);for(let e=0;e<t.length;e++){let n=z(t[e]);if(/^\s*at\s+\S+.*\(.*:\d+:\d+\)\s*$/.test(n)||/^\s*at\s+\S+\.\S+\(\S+\.java:\d+\)\s*$/.test(n)||/^\s+File "[^"]+", line \d+/.test(n))return e}return-1}function xo({text:e}){let t=bo(e),[n,r]=(0,B.useState)(!1);if(t===-1)return(0,X.jsx)(`pre`,{className:`whitespace-pre-wrap break-words font-mono text-xs leading-relaxed`,children:e});let i=e.split(`
86
+ `).length,[o,s]=(0,B.useState)(a<30);return(0,X.jsxs)(`div`,{className:Y(`rounded-md border bg-background/40 overflow-hidden`,t&&`border-destructive/40`,r),children:[(0,X.jsxs)(`button`,{type:`button`,onClick:()=>s(e=>!e),className:`w-full flex items-center justify-between px-2 py-1 border-b bg-muted/30 text-[11px] text-muted-foreground hover:text-foreground`,children:[(0,X.jsxs)(`span`,{className:`flex items-center gap-1`,children:[o?(0,X.jsx)(ut,{className:`h-3 w-3`}):(0,X.jsx)(n,{className:`h-3 w-3`}),(0,X.jsxs)(`span`,{className:`font-mono`,children:[`JSON · `,a,` lines`]})]}),(0,X.jsx)(`span`,{children:o?`collapse`:`expand`})]}),o&&(0,X.jsx)(`pre`,{className:Y(`text-xs font-mono whitespace-pre p-2 max-h-96 overflow-auto`,t?`text-destructive`:`text-foreground`),children:i})]})}var ao=/💡\s*Next steps?\s*\n+((?:\d+\.\s+.+(?:\s+auto="true")?\n?)+)/i,oo=/^(\d+)\.\s+(.+?)(?:\s+auto="true")?$/;function so(e){let t=ao.exec(e);if(t?.[1]){let e=t[1];return co(e)}return co(e)}function co(e){let t=e.split(`
87
+ `).filter(Boolean),n=[];for(let e of t){let t=oo.exec(e.trim());if(t){let r=t[2].trim(),i=e.trim().endsWith(`auto="true"`);n.push({index:Number.parseInt(t[1],10),text:r,auto:i})}}return n.slice(0,6)}function lo(e){let t=document.querySelector(`textarea`);t&&((Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype,`value`)?.set)?.call(t,e),t.dispatchEvent(new Event(`input`,{bubbles:!0})),t.focus())}function uo({delayMs:e,onComplete:t}){let[n,r]=(0,B.useState)(Math.ceil(e/1e3));return(0,B.useEffect)(()=>{if(n<=0){t();return}let e=setTimeout(()=>r(e=>e-1),1e3);return()=>clearTimeout(e)},[n,t]),(0,X.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-primary font-medium`,children:[(0,X.jsx)(It,{className:`h-3 w-3`}),n,`s`]})}function fo({steps:e,yoloMode:t=!1,autoMode:n=!1,autoDelayMs:r=3e4,onAutoSubmit:i}){if(e.length===0)return null;let a=t&&n,o=a?e.find(e=>e.auto):void 0;return(0,X.jsxs)(`div`,{className:`mt-4 rounded-xl border border-primary/20 bg-primary/[0.03] overflow-hidden animate-message`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 px-3.5 py-2 border-b border-primary/10 bg-primary/[0.04]`,children:[(0,X.jsx)(`span`,{className:`flex items-center justify-center w-5 h-5 rounded-md bg-primary/15 text-primary`,children:(0,X.jsx)(Ht,{className:`h-3 w-3`})}),(0,X.jsx)(`span`,{className:`text-xs font-semibold text-foreground/90`,children:`Next steps`}),a&&o?(0,X.jsxs)(`span`,{className:`ml-auto flex items-center gap-1 text-xs text-primary`,children:[(0,X.jsx)(It,{className:`h-3 w-3`}),`auto-submitting in `,(0,X.jsx)(uo,{delayMs:r,onComplete:()=>i?.(o.text)})]}):(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground ml-auto`,children:`click to fill input`})]}),(0,X.jsx)(`div`,{className:`flex flex-col p-2 gap-1`,children:e.map(e=>{let t=a&&e.auto;return(0,X.jsxs)(`button`,{type:`button`,onClick:()=>lo(e.text),className:`group flex items-center gap-2.5 w-full text-left px-3 py-2 rounded-lg transition-all border ${t?`bg-primary/10 border-primary/30 ring-1 ring-primary/20`:`border-transparent hover:bg-primary/[0.08] hover:shadow-sm hover:border-primary/20`}`,title:`Click to fill: ${e.text}`,children:[(0,X.jsx)(`span`,{className:`flex items-center justify-center w-5 h-5 rounded-md text-[11px] font-mono font-semibold tabular-nums shrink-0 transition-colors ${t?`bg-primary/30 text-primary`:`bg-muted/80 group-hover:bg-primary/20 text-muted-foreground group-hover:text-primary`}`,children:e.index}),(0,X.jsx)(ln,{className:`h-3.5 w-3.5 shrink-0 transition-all ${t?`text-primary`:`text-muted-foreground/60 group-hover:text-primary group-hover:translate-x-0.5`}`}),(0,X.jsx)(`span`,{className:`text-sm leading-snug flex-1 min-w-0 transition-colors ${t?`text-foreground font-medium`:`text-foreground/80 group-hover:text-foreground`}`,children:e.text}),e.auto&&(0,X.jsxs)(`span`,{className:`flex items-center gap-1 text-[10px] text-primary/70`,children:[(0,X.jsx)(It,{className:`h-3 w-3`}),`auto`]}),(0,X.jsx)(D,{className:`h-3.5 w-3.5 shrink-0 transition-all ${t?`opacity-100 text-primary/60`:`opacity-0 group-hover:opacity-100 text-primary/60`}`})]},e.index)})})]})}async function po(e){try{if(typeof navigator<`u`&&navigator.clipboard?.writeText)return await navigator.clipboard.writeText(e),!0}catch{}try{let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t),t.select();let n=document.execCommand(`copy`);return document.body.removeChild(t),n}catch{return!1}}function mo(e,t){if(typeof document>`u`)return;let n=new Blob([t],{type:`text/plain;charset=utf-8`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=e,document.body.appendChild(i),i.click(),document.body.removeChild(i),setTimeout(()=>URL.revokeObjectURL(r),1e3)}function ho(e){let t=(e??``).toLowerCase();return/bash|shell|exec|run/.test(t)?`log`:(/grep|search|find/.test(t),`txt`)}function go(e){return e<1e3?`${e} ms`:e<6e4?`${(e/1e3).toFixed(e<1e4?2:1)}s`:`${Math.floor(e/6e4)}m ${Math.floor(e%6e4/1e3)}s`}var _o=[T];function vo({text:e}){let[t,n]=(0,B.useState)(!1);return(0,X.jsxs)(`button`,{type:`button`,onClick:(0,B.useCallback)(async()=>{await po(e)&&(n(!0),setTimeout(()=>n(!1),1500))},[e]),className:Y(`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] transition-colors`,`hover:bg-muted-foreground/10`,t?`text-emerald-500`:`text-muted-foreground hover:text-foreground`),title:t?`Copied!`:`Copy code`,children:[t?(0,X.jsx)(pn,{className:`h-3 w-3`}):(0,X.jsx)(E,{className:`h-3 w-3`}),(0,X.jsx)(`span`,{children:t?`Copied`:`Copy`})]})}var yo={next_steps({children:e}){let t=typeof e==`string`?e.trim():``;if(!t)return null;let n=so(t);return n.length===0?null:(0,X.jsx)(fo,{steps:n,onAutoSubmit:e=>{lo(e);let t=document.querySelector(`form[class*="flex items-end gap-2"]`);t&&t.dispatchEvent(new Event(`submit`,{bubbles:!0,cancelable:!0}))}})},code({inline:e,className:t,children:n,...r}){let i=/language-(\w+)/.exec(t??``),a=String(n??``).replace(/\n$/,``);if(e||!i)return(0,X.jsx)(`code`,{className:Y(`rounded border border-border/60 px-1.5 py-0.5 text-[0.85em] font-mono`,t),...r,children:n});let o=(0,B.useMemo)(()=>a.split(`
88
+ `),[a]),s=o.length>1;return(0,X.jsxs)(`div`,{className:`not-prose relative my-3 rounded-lg border border-border overflow-hidden group/codeblock`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-1 border-b border-border text-xs`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(jt,{className:`h-3 w-3 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`font-mono text-muted-foreground font-medium`,children:i[1]}),o.length>0&&(0,X.jsxs)(`span`,{className:`text-[10px] text-muted-foreground/60 tabular-nums`,children:[o.length,` line`,o.length===1?``:`s`]})]}),(0,X.jsx)(vo,{text:a})]}),s?(0,X.jsxs)(`div`,{className:`flex max-h-[40rem] overflow-auto`,children:[(0,X.jsx)(`pre`,{"aria-hidden":!0,className:`text-xs font-mono leading-[1.55] py-3 pl-3 pr-2 text-muted-foreground/40 select-none border-r border-border/30 tabular-nums text-right shrink-0`,children:o.map((e,t)=>(0,X.jsx)(`div`,{children:t+1},t))}),(0,X.jsx)(`pre`,{className:`overflow-x-auto py-3 px-3 text-xs leading-[1.55] font-mono flex-1`,children:(0,X.jsx)(`code`,{className:Y(`hljs`,t),...r,children:n})})]}):(0,X.jsx)(`pre`,{className:`overflow-x-auto p-3 text-xs leading-relaxed font-mono max-h-[40rem]`,children:(0,X.jsx)(`code`,{className:Y(`hljs`,t),...r,children:n})}),(0,X.jsx)(`div`,{className:`pointer-events-none absolute bottom-8 left-0 right-0 h-8 bg-gradient-to-t from-black/10 to-transparent opacity-0 group-hover/codeblock:opacity-100 transition-opacity`})]})}};function bo({text:e,className:t,label:n=`Copy`}){let[r,i]=(0,B.useState)(!1);return(0,X.jsx)(`button`,{type:`button`,onClick:async t=>{t.stopPropagation(),await po(e)&&(i(!0),setTimeout(()=>i(!1),1400))},className:Y(`inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors`,t),title:n,children:r?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(pn,{className:`h-3 w-3 text-green-500`}),(0,X.jsx)(`span`,{children:`Copied`})]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(E,{className:`h-3 w-3`}),(0,X.jsx)(`span`,{children:n})]})})}function xo(e){let t=e.split(`
89
+ `);for(let e=0;e<t.length;e++){let n=z(t[e]);if(/^\s*at\s+\S+.*\(.*:\d+:\d+\)\s*$/.test(n)||/^\s*at\s+\S+\.\S+\(\S+\.java:\d+\)\s*$/.test(n)||/^\s+File "[^"]+", line \d+/.test(n))return e}return-1}function So({text:e}){let t=xo(e),[n,r]=(0,B.useState)(!1);if(t===-1)return(0,X.jsx)(`pre`,{className:`whitespace-pre-wrap break-words font-mono text-xs leading-relaxed`,children:e});let i=e.split(`
94
90
  `),a=i.slice(0,t).join(`
95
91
  `).trim(),o=i.slice(t).join(`
96
92
  `),s=o.split(`
97
- `).filter(e=>e.trim().length>0).length;return(0,X.jsxs)(`div`,{className:`space-y-2`,children:[a&&(0,X.jsx)(`pre`,{className:`whitespace-pre-wrap break-words font-mono text-xs leading-relaxed`,children:a}),(0,X.jsxs)(`button`,{type:`button`,onClick:()=>r(e=>!e),className:`inline-flex items-center gap-1 text-xs text-destructive hover:text-destructive/80 font-medium`,children:[n?`▾`:`▸`,` `,n?`Hide`:`Show`,` stack trace (`,s,` frame`,s===1?``:`s`,`)`]}),n&&(0,X.jsx)(`pre`,{className:`whitespace-pre-wrap break-words font-mono text-[11px] leading-snug bg-destructive/5 border border-destructive/20 rounded p-2 max-h-80 overflow-auto`,children:o})]})}function So({input:e}){let[t,n]=(0,B.useState)({});if(typeof e!=`object`||!e||Array.isArray(e))return(0,X.jsx)(`pre`,{className:`whitespace-pre-wrap break-all text-xs font-mono`,children:JSON.stringify(e,null,2)});let r=Object.entries(e);return r.length===0?(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground italic`,children:`(no params)`}):(0,X.jsx)(`div`,{className:`text-xs font-mono`,children:r.map(([e,r])=>{if(r==null||typeof r==`string`||typeof r==`number`||typeof r==`boolean`){let t=r===null?`null`:r===void 0?`undefined`:typeof r==`string`?r:String(r),n=typeof r==`string`&&(t.length>80||t.includes(`
98
- `));return(0,X.jsxs)(`div`,{className:Y(`py-0.5`,n?`flex flex-col gap-0.5`:`flex items-baseline gap-2`),children:[(0,X.jsxs)(`span`,{className:`text-muted-foreground shrink-0`,children:[e,`:`]}),(0,X.jsx)(`span`,{className:Y(`text-foreground`,n?`whitespace-pre-wrap break-all bg-muted/40 rounded px-1.5 py-1`:`truncate`,typeof r==`string`?``:`text-amber-600 dark:text-amber-400`),title:typeof r==`string`&&!n?t:void 0,children:t})]},e)}let i=!!t[e],a=Array.isArray(r)?`[${r.length} item${r.length===1?``:`s`}]`:`{${Object.keys(r).length} key${Object.keys(r).length===1?``:`s`}}`;return(0,X.jsxs)(`div`,{className:`py-0.5`,children:[(0,X.jsxs)(`button`,{type:`button`,onClick:()=>n(t=>({...t,[e]:!t[e]})),className:`flex items-baseline gap-2 hover:bg-muted/30 rounded px-1 -mx-1`,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground/60 text-[10px]`,children:i?`▾`:`▸`}),(0,X.jsxs)(`span`,{className:`text-muted-foreground`,children:[e,`:`]}),(0,X.jsx)(`span`,{className:`text-violet-600 dark:text-violet-400`,children:a})]}),i&&(0,X.jsx)(`pre`,{className:`ml-3 mt-1 whitespace-pre-wrap break-all text-[11px] bg-muted/40 rounded px-2 py-1.5`,children:JSON.stringify(r,null,2)})]},e)})})}var Co=(0,B.memo)(function({message:e,isFirst:t=!1,isContinuation:r=!1}){let[i,a]=(0,B.useState)({}),[o,s]=(0,B.useState)(!1),[c,l]=(0,B.useState)(``),[u,d]=(0,B.useState)(!1),f=e.role===`user`,p=e.role===`tool`;e.role;let m=H(e=>e.truncateAfter),h=H(e=>e.addMessage),g=H(e=>e.setLoading),_=H(e=>e.isLoading),y=U(e=>e.wsUrl),S=G(e=>e.pinnedIds),C=G(e=>e.togglePin),w=G(e=>e.compactMode),T=S.includes(e.id),E=W(e=>e.inputCost),D=W(e=>e.outputCost),O=W(e=>e.cacheReadCost),k=hr(),{autonomy:A,yolo:j}=k,ee=e=>{h({role:`user`,content:e}),g(!0),V(y).sendMessage(e)},M=(()=>{if(e.role!==`assistant`||_)return!1;let t=H.getState().messages;for(let n=t.length-1;n>=0;n--){let r=z(t[n]);if(r.role===`assistant`)return r.id===e.id}return!1})(),te=()=>{let t=H.getState().messages,n=t.findIndex(t=>t.id===e.id);if(n===-1)return;let r=-1;for(let e=n-1;e>=0;e--)if(t[e]?.role===`user`){r=e;break}if(r===-1)return;let i=z(t[r]);m(i.id),h({role:`user`,content:i.content}),g(!0),V(y).sendMessage(i.content)},ne=e=>{a(t=>({...t,[e]:!t[e]}))},re=()=>{l(e.content),s(!0)},ie=()=>{s(!1),l(``)},ae=()=>{let t=c.trim();if(!t){ie();return}m(e.id),h({role:`user`,content:t}),g(!0),V(y).sendMessage(t),s(!1),l(``)};return(0,X.jsxs)(`div`,{"data-message-id":e.id,"data-pinned":T?`1`:void 0,className:Y(`group flex msg-bubble animate-message rounded-lg transition-shadow`,w?`gap-2`:`gap-3`,f?`flex-row-reverse`:`flex-row`,T&&`ring-1 ring-amber-500/30 bg-amber-500/[0.02] px-1 -mx-1`),children:[r?(0,X.jsx)(`div`,{className:`flex-shrink-0 w-8 h-8`,"aria-hidden":!0}):(0,X.jsx)(`div`,{className:Y(`flex-shrink-0 w-8 h-8 rounded-full flex items-center justify-center`,`ring-2 ring-offset-2 ring-offset-background`,f?`bg-primary text-primary-foreground ring-primary/20`:p?`bg-secondary text-secondary-foreground ring-secondary/20`:`bg-accent text-accent-foreground ring-accent/20`),children:f?(0,X.jsx)(on,{className:`h-4 w-4`}):p?(0,X.jsx)(vn,{className:`h-4 w-4`}):(0,X.jsx)(R,{className:`h-4 w-4`})}),(0,X.jsxs)(`div`,{className:Y(`flex flex-col gap-1.5 max-w-[85%]`,f&&`items-end`),children:[t&&!r&&(0,X.jsx)(`span`,{className:Y(`text-xs font-medium px-1`,f?`text-primary`:p?`text-secondary`:`text-muted-foreground`),children:f?`You`:p?`Tool`:`Assistant`}),p&&e.toolName&&(0,X.jsxs)(`button`,{type:`button`,onClick:()=>ne(e.id),className:Y(`flex items-center gap-2 text-sm font-medium cursor-pointer select-none`,`hover:bg-muted/50 rounded-lg px-2 py-1 -mx-2 transition-colors`,e.isError?`text-destructive`:`text-foreground`),children:[(0,X.jsx)(`span`,{className:`text-muted-foreground/50`,children:i[e.id]?(0,X.jsx)(ut,{className:`h-3 w-3`}):(0,X.jsx)(n,{className:`h-3 w-3`})}),(0,X.jsx)(vn,{className:`h-3 w-3`}),(0,X.jsx)(`span`,{className:`font-mono`,children:e.toolName}),e.toolResult===void 0?(0,X.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-amber-500 animate-pulse`,"aria-hidden":!0}):e.isError?(0,X.jsx)(N,{className:`h-3 w-3 text-destructive`}):(0,X.jsx)(Be,{className:`h-3 w-3 text-green-500`}),typeof e.toolDurationMs==`number`&&(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums font-normal`,children:ho(e.toolDurationMs)})]}),(0,X.jsx)(`div`,{className:Y(`rounded-2xl`,w?`px-3 py-1.5`:`px-4 py-3`,f?`bg-primary text-primary-foreground rounded-br-md`:p?e.isError?`bg-destructive/5 border border-destructive/20 text-destructive`:`bg-muted/80 text-foreground`:`bg-card border text-foreground`,e.isError&&!p&&`border-destructive/20`),children:p?(()=>{let t=!!i[e.id],n=e.toolInput===void 0?``:Ga(e.toolName,e.toolInput),r=e.toolResult?e.toolResult.split(`
99
- `).length:0;return(0,X.jsxs)(`div`,{className:`space-y-1 tool-details`,children:[n&&!t&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground font-mono truncate`,children:n}),e.toolResult===void 0&&e.progressLines&&e.progressLines.length>0&&(0,X.jsx)(`div`,{className:`mt-1 rounded-md border border-amber-500/20 bg-amber-500/5 p-1.5 text-[11px] font-mono leading-snug max-h-32 overflow-auto`,children:(()=>{let t=new Map;return e.progressLines.slice(-6).map(e=>{let n=t.get(e)??0;return t.set(e,n+1),(0,X.jsx)(`div`,{className:`truncate text-muted-foreground`,children:e},`${e}-${n}`)})})()}),t&&e.toolInput!==void 0&&(()=>{let t=Qa(e.toolName,e.toolInput);return t?(0,X.jsx)(Ya,{oldText:t.oldText,newText:t.newText,caption:t.caption}):(0,X.jsxs)(`div`,{className:`p-3 bg-muted/50 rounded-lg overflow-x-auto`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1 text-muted-foreground mb-2 text-xs`,children:[(0,X.jsx)(Pe,{className:`h-3 w-3`}),(0,X.jsx)(`span`,{children:`Input`})]}),(0,X.jsx)(So,{input:e.toolInput})]})})(),t&&e.toolResult!==void 0&&e.toolResult.length>0&&(0,X.jsxs)(`div`,{className:`relative group/tool`,children:[(0,X.jsx)(no,{toolName:e.toolName,result:e.toolResult,isError:e.isError}),(0,X.jsxs)(`div`,{className:`absolute top-1.5 right-1.5 flex items-center gap-1 opacity-0 group-hover/tool:opacity-100 transition-opacity`,children:[(0,X.jsx)(yo,{text:e.toolResult,label:``,className:`bg-background/80 border rounded px-1.5 py-0.5`}),e.toolResult.split(`
100
- `).length>5&&(0,X.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation();let n=mo(e.toolName);po(`${(e.toolName??`output`).replace(/[^a-z0-9_-]+/gi,`-`).toLowerCase()}-${new Date().toISOString().replace(/[:.]/g,`-`)}.${n}`,e.toolResult??``)},className:`inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground bg-background/80 border rounded px-1.5 py-0.5`,title:`Download as file`,children:(0,X.jsx)(b,{className:`h-3 w-3`})})]})]}),t&&e.toolResult!==void 0&&e.toolResult.length===0&&(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground italic`,children:`(empty)`}),!t&&e.isError&&e.toolResult&&(0,X.jsx)(`div`,{className:`text-xs font-mono text-destructive truncate`,children:e.toolResult.split(`
93
+ `).filter(e=>e.trim().length>0).length;return(0,X.jsxs)(`div`,{className:`space-y-2`,children:[a&&(0,X.jsx)(`pre`,{className:`whitespace-pre-wrap break-words font-mono text-xs leading-relaxed`,children:a}),(0,X.jsxs)(`button`,{type:`button`,onClick:()=>r(e=>!e),className:`inline-flex items-center gap-1 text-xs text-destructive hover:text-destructive/80 font-medium`,children:[n?`▾`:`▸`,` `,n?`Hide`:`Show`,` stack trace (`,s,` frame`,s===1?``:`s`,`)`]}),n&&(0,X.jsx)(`pre`,{className:`whitespace-pre-wrap break-words font-mono text-[11px] leading-snug bg-destructive/5 border border-destructive/20 rounded p-2 max-h-80 overflow-auto`,children:o})]})}function Co({input:e}){let[t,n]=(0,B.useState)({});if(typeof e!=`object`||!e||Array.isArray(e))return(0,X.jsx)(`pre`,{className:`whitespace-pre-wrap break-all text-xs font-mono`,children:JSON.stringify(e,null,2)});let r=Object.entries(e);return r.length===0?(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground italic`,children:`(no params)`}):(0,X.jsx)(`div`,{className:`text-xs font-mono`,children:r.map(([e,r])=>{if(r==null||typeof r==`string`||typeof r==`number`||typeof r==`boolean`){let t=r===null?`null`:r===void 0?`undefined`:typeof r==`string`?r:String(r),n=typeof r==`string`&&(t.length>80||t.includes(`
94
+ `));return(0,X.jsxs)(`div`,{className:Y(`py-0.5`,n?`flex flex-col gap-0.5`:`flex items-baseline gap-2`),children:[(0,X.jsxs)(`span`,{className:`text-muted-foreground shrink-0`,children:[e,`:`]}),(0,X.jsx)(`span`,{className:Y(`text-foreground`,n?`whitespace-pre-wrap break-all bg-muted/40 rounded px-1.5 py-1`:`truncate`,typeof r==`string`?``:`text-amber-600 dark:text-amber-400`),title:typeof r==`string`&&!n?t:void 0,children:t})]},e)}let i=!!t[e],a=Array.isArray(r)?`[${r.length} item${r.length===1?``:`s`}]`:`{${Object.keys(r).length} key${Object.keys(r).length===1?``:`s`}}`;return(0,X.jsxs)(`div`,{className:`py-0.5`,children:[(0,X.jsxs)(`button`,{type:`button`,onClick:()=>n(t=>({...t,[e]:!t[e]})),className:`flex items-baseline gap-2 hover:bg-muted/30 rounded px-1 -mx-1`,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground/60 text-[10px]`,children:i?`▾`:`▸`}),(0,X.jsxs)(`span`,{className:`text-muted-foreground`,children:[e,`:`]}),(0,X.jsx)(`span`,{className:`text-violet-600 dark:text-violet-400`,children:a})]}),i&&(0,X.jsx)(`pre`,{className:`ml-3 mt-1 whitespace-pre-wrap break-all text-[11px] bg-muted/40 rounded px-2 py-1.5`,children:JSON.stringify(r,null,2)})]},e)})})}var wo=(0,B.memo)(function({message:e,isFirst:t=!1,isContinuation:r=!1}){let[i,a]=(0,B.useState)({}),[o,s]=(0,B.useState)(!1),[c,l]=(0,B.useState)(``),[u,d]=(0,B.useState)(!1),f=e.role===`user`,p=e.role===`tool`;e.role;let m=H(e=>e.truncateAfter),h=H(e=>e.addMessage),g=H(e=>e.setLoading),_=H(e=>e.isLoading),y=U(e=>e.wsUrl),S=G(e=>e.pinnedIds),C=G(e=>e.togglePin),w=G(e=>e.compactMode),T=S.includes(e.id),E=W(e=>e.inputCost),D=W(e=>e.outputCost),O=W(e=>e.cacheReadCost),k=hr(),{autonomy:A,yolo:j}=k,ee=e=>{h({role:`user`,content:e}),g(!0),V(y).sendMessage(e),lo(``)},M=(()=>{if(e.role!==`assistant`||_)return!1;let t=H.getState().messages;for(let n=t.length-1;n>=0;n--){let r=z(t[n]);if(r.role===`assistant`)return r.id===e.id}return!1})(),te=()=>{let t=H.getState().messages,n=t.findIndex(t=>t.id===e.id);if(n===-1)return;let r=-1;for(let e=n-1;e>=0;e--)if(t[e]?.role===`user`){r=e;break}if(r===-1)return;let i=z(t[r]);m(i.id),h({role:`user`,content:i.content}),g(!0),V(y).sendMessage(i.content)},ne=e=>{a(t=>({...t,[e]:!t[e]}))},re=()=>{l(e.content),s(!0)},ie=()=>{s(!1),l(``)},ae=()=>{let t=c.trim();if(!t){ie();return}m(e.id),h({role:`user`,content:t}),g(!0),V(y).sendMessage(t),s(!1),l(``)};return(0,X.jsxs)(`div`,{"data-message-id":e.id,"data-pinned":T?`1`:void 0,className:Y(`group flex msg-bubble animate-message rounded-lg transition-shadow`,w?`gap-2`:`gap-3`,f?`flex-row-reverse`:`flex-row`,T&&`ring-1 ring-amber-500/30 bg-amber-500/[0.02] px-1 -mx-1`),children:[r?(0,X.jsx)(`div`,{className:`flex-shrink-0 w-8 h-8`,"aria-hidden":!0}):(0,X.jsx)(`div`,{className:Y(`flex-shrink-0 w-8 h-8 rounded-full flex items-center justify-center`,`ring-2 ring-offset-2 ring-offset-background`,f?`bg-primary text-primary-foreground ring-primary/20`:p?`bg-secondary text-secondary-foreground ring-secondary/20`:`bg-accent text-accent-foreground ring-accent/20`),children:f?(0,X.jsx)(on,{className:`h-4 w-4`}):p?(0,X.jsx)(vn,{className:`h-4 w-4`}):(0,X.jsx)(R,{className:`h-4 w-4`})}),(0,X.jsxs)(`div`,{className:Y(`flex flex-col gap-1.5 max-w-[85%]`,f&&`items-end`),children:[t&&!r&&(0,X.jsx)(`span`,{className:Y(`text-xs font-medium px-1`,f?`text-primary`:p?`text-secondary`:`text-muted-foreground`),children:f?`You`:p?`Tool`:`Assistant`}),p&&e.toolName&&(0,X.jsxs)(`button`,{type:`button`,onClick:()=>ne(e.id),className:Y(`flex items-center gap-2 text-sm font-medium cursor-pointer select-none`,`hover:bg-muted/50 rounded-lg px-2 py-1 -mx-2 transition-colors`,e.isError?`text-destructive`:`text-foreground`),children:[(0,X.jsx)(`span`,{className:`text-muted-foreground/50`,children:i[e.id]?(0,X.jsx)(ut,{className:`h-3 w-3`}):(0,X.jsx)(n,{className:`h-3 w-3`})}),(0,X.jsx)(vn,{className:`h-3 w-3`}),(0,X.jsx)(`span`,{className:`font-mono`,children:e.toolName}),e.toolResult===void 0?(0,X.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-amber-500 animate-pulse`,"aria-hidden":!0}):e.isError?(0,X.jsx)(N,{className:`h-3 w-3 text-destructive`}):(0,X.jsx)(Be,{className:`h-3 w-3 text-green-500`}),typeof e.toolDurationMs==`number`&&(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums font-normal`,children:go(e.toolDurationMs)})]}),(0,X.jsx)(`div`,{className:Y(`rounded-2xl`,w?`px-3 py-1.5`:`px-4 py-3`,f?`bg-primary text-primary-foreground rounded-br-md`:p?e.isError?`bg-destructive/5 border border-destructive/20 text-destructive`:`bg-muted/80 text-foreground`:`bg-card border text-foreground`,e.isError&&!p&&`border-destructive/20`),children:p?(()=>{let t=!!i[e.id],n=e.toolInput===void 0?``:Ga(e.toolName,e.toolInput),r=e.toolResult?e.toolResult.split(`
95
+ `).length:0;return(0,X.jsxs)(`div`,{className:`space-y-1 tool-details`,children:[n&&!t&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground font-mono truncate`,children:n}),e.toolResult===void 0&&e.progressLines&&e.progressLines.length>0&&(0,X.jsx)(`div`,{className:`mt-1 rounded-md border border-amber-500/20 bg-amber-500/5 p-1.5 text-[11px] font-mono leading-snug max-h-32 overflow-auto`,children:(()=>{let t=new Map;return e.progressLines.slice(-6).map(e=>{let n=t.get(e)??0;return t.set(e,n+1),(0,X.jsx)(`div`,{className:`truncate text-muted-foreground`,children:e},`${e}-${n}`)})})()}),t&&e.toolInput!==void 0&&(()=>{let t=Qa(e.toolName,e.toolInput);return t?(0,X.jsx)(Ya,{oldText:t.oldText,newText:t.newText,caption:t.caption}):(0,X.jsxs)(`div`,{className:`p-3 bg-muted/50 rounded-lg overflow-x-auto`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1 text-muted-foreground mb-2 text-xs`,children:[(0,X.jsx)(Pe,{className:`h-3 w-3`}),(0,X.jsx)(`span`,{children:`Input`})]}),(0,X.jsx)(Co,{input:e.toolInput})]})})(),t&&e.toolResult!==void 0&&e.toolResult.length>0&&(0,X.jsxs)(`div`,{className:`relative group/tool`,children:[(0,X.jsx)(no,{toolName:e.toolName,result:e.toolResult,isError:e.isError}),(0,X.jsxs)(`div`,{className:`absolute top-1.5 right-1.5 flex items-center gap-1 opacity-0 group-hover/tool:opacity-100 transition-opacity`,children:[(0,X.jsx)(bo,{text:e.toolResult,label:``,className:`bg-background/80 border rounded px-1.5 py-0.5`}),e.toolResult.split(`
96
+ `).length>5&&(0,X.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation();let n=ho(e.toolName);mo(`${(e.toolName??`output`).replace(/[^a-z0-9_-]+/gi,`-`).toLowerCase()}-${new Date().toISOString().replace(/[:.]/g,`-`)}.${n}`,e.toolResult??``)},className:`inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground bg-background/80 border rounded px-1.5 py-0.5`,title:`Download as file`,children:(0,X.jsx)(b,{className:`h-3 w-3`})})]})]}),t&&e.toolResult!==void 0&&e.toolResult.length===0&&(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground italic`,children:`(empty)`}),!t&&e.isError&&e.toolResult&&(0,X.jsx)(`div`,{className:`text-xs font-mono text-destructive truncate`,children:e.toolResult.split(`
101
97
  `)[0]}),(e.toolResult!==void 0&&e.toolResult.length>0||e.toolInput!==void 0&&Object.keys(e.toolInput??{}).length>0)&&(0,X.jsx)(`button`,{type:`button`,onClick:()=>ne(e.id),className:`text-xs text-muted-foreground hover:text-foreground transition-colors`,children:t?`Hide details`:`Show details${r>0?` (${r} line${r===1?``:`s`})`:``}`})]})})():o&&f?(0,X.jsxs)(`div`,{className:`flex flex-col gap-2 min-w-[280px]`,children:[(0,X.jsx)(`textarea`,{value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Escape`?(e.preventDefault(),ie()):e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),ae())},rows:Math.min(8,Math.max(2,c.split(`
102
- `).length)),className:`w-full resize-none rounded-md border bg-background text-foreground px-2 py-1.5 text-sm font-mono focus:outline-none focus:ring-2 focus:ring-ring`}),(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,X.jsx)(`span`,{className:`text-[10px] text-primary-foreground/60`,children:`⌘/Ctrl+Enter to save · Esc to cancel`}),(0,X.jsxs)(`div`,{className:`flex gap-1`,children:[(0,X.jsx)(`button`,{type:`button`,onClick:ie,className:`text-xs px-2 py-0.5 rounded border border-primary-foreground/30 hover:bg-primary-foreground/10`,children:`Cancel`}),(0,X.jsx)(`button`,{type:`button`,onClick:ae,disabled:!c.trim(),className:`text-xs px-2 py-0.5 rounded bg-primary-foreground text-primary disabled:opacity-50`,children:`Save & resend`})]})]})]}):(0,X.jsx)(`div`,{className:Y(`text-sm leading-relaxed markdown-content`,e.streaming&&`streaming-cursor`),children:e.content?u&&e.role===`assistant`?(0,X.jsx)(`pre`,{className:`whitespace-pre-wrap break-words font-mono text-xs leading-relaxed text-foreground/90 max-h-[40rem] overflow-auto`,children:e.content}):e.role===`assistant`&&e.isError?(0,X.jsx)(xo,{text:e.content}):(0,X.jsx)(Ne,{remarkPlugins:[De],rehypePlugins:go,components:vo,children:e.content}):e.streaming?(0,X.jsx)(`span`,{className:`inline-block animate-pulse text-muted-foreground`,children:`Typing...`}):(0,X.jsx)(`span`,{className:`text-muted-foreground italic`,children:`No content`})})}),M&&e.content&&(()=>{let t=so(e.content);return t.length===0?null:(0,X.jsx)(uo,{steps:t,yoloMode:j,autoMode:A===`auto`,autoDelayMs:k.autonomyDelayMs,onAutoSubmit:ee})})(),(0,X.jsxs)(`div`,{className:Y(`flex items-center gap-2 px-1`,f?`flex-row-reverse`:`flex-row`),children:[(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground/50`,children:new Date(e.timestamp).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})}),(0,X.jsx)(`span`,{className:`w-px h-3 bg-border/60 shrink-0`,"aria-hidden":!0}),e.runSummary&&(0,X.jsxs)(`span`,{className:`text-[10px] text-muted-foreground/60 font-mono tabular-nums`,title:[`Iterations: ${e.runSummary.iterations}`,`Tool calls: ${e.runSummary.tools}`,`Elapsed: ${(e.runSummary.durationMs/1e3).toFixed(2)}s`,e.runSummary.costDelta>0?`Cost: ${e.runSummary.costDelta.toFixed(4)}`:``].filter(Boolean).join(` · `),children:[e.runSummary.iterations,` iter`,e.runSummary.tools>0?` · ${e.runSummary.tools} tool${e.runSummary.tools===1?``:`s`}`:``,` · `,e.runSummary.durationMs<6e4?`${(e.runSummary.durationMs/1e3).toFixed(1)}s`:`${Math.floor(e.runSummary.durationMs/6e4)}m ${Math.floor(e.runSummary.durationMs%6e4/1e3)}s`,e.runSummary.costDelta>0?` · ${e.runSummary.costDelta>=.01?e.runSummary.costDelta.toFixed(4):e.runSummary.costDelta.toFixed(6).replace(/0+$/,``).replace(/\.$/,``)}`:``]}),e.usage&&(e.usage.input>0||e.usage.output>0)&&(()=>{let t=e.usage,n=(t.input*E+t.output*D+(t.cacheRead??0)*O)/1e6,r=E>0||D>0,i=n>=.01?`${n.toFixed(4)}`:n>0?`${n.toFixed(6).replace(/0+$/,``).replace(/\.$/,``)}`:``;return(0,X.jsxs)(`span`,{className:`text-[10px] text-muted-foreground/60 font-mono tabular-nums`,title:[`Input: ${t.input.toLocaleString()}`,`Output: ${t.output.toLocaleString()}`,t.cacheRead?`Cache read: ${t.cacheRead.toLocaleString()}`:``,r?`Cost: ${i}`:``].filter(Boolean).join(` · `),children:[t.input.toLocaleString(),`→`,t.output.toLocaleString(),t.cacheRead?` · ${t.cacheRead.toLocaleString()} ↺`:``,r&&i?` · ${i}`:``]})})(),!p&&e.content&&!e.streaming&&(0,X.jsx)(yo,{text:e.content,label:`Copy`,className:`opacity-50 hover:opacity-100 transition-opacity`}),e.role===`assistant`&&e.content&&!e.streaming&&(0,X.jsxs)(`button`,{type:`button`,onClick:()=>d(e=>!e),title:u?`Show rendered markdown`:`Show raw markdown source`,className:Y(`text-xs inline-flex items-center gap-1 transition-opacity`,u?`text-primary hover:text-primary/80 opacity-100`:`opacity-50 hover:opacity-100 text-muted-foreground hover:text-foreground`),children:[(0,X.jsx)(jt,{className:`h-3 w-3`}),(0,X.jsx)(`span`,{children:u?`Rendered`:`Raw`})]}),f&&!o&&!_&&e.content&&(0,X.jsxs)(`button`,{type:`button`,onClick:re,title:`Edit & resend this prompt`,className:`opacity-50 hover:opacity-100 transition-opacity text-xs text-muted-foreground hover:text-foreground inline-flex items-center gap-1`,children:[(0,X.jsx)(x,{className:`h-3 w-3`}),(0,X.jsx)(`span`,{children:`Edit`})]}),e.role===`assistant`&&e.content&&!e.streaming&&(0,X.jsxs)(`button`,{type:`button`,onClick:()=>C(e.id),title:T?`Unpin`:`Pin this answer`,className:Y(`text-xs inline-flex items-center gap-1 transition-opacity`,T?`text-amber-500 hover:text-amber-600 opacity-100`:`opacity-50 hover:opacity-100 text-muted-foreground hover:text-foreground`),children:[T?(0,X.jsx)(he,{className:`h-3 w-3`}):(0,X.jsx)(P,{className:`h-3 w-3`}),(0,X.jsx)(`span`,{children:T?`Pinned`:`Pin`})]}),M&&e.content&&!e.streaming&&(0,X.jsxs)(`button`,{type:`button`,onClick:te,title:`Regenerate this response`,className:`opacity-50 hover:opacity-100 transition-opacity text-xs text-muted-foreground hover:text-foreground inline-flex items-center gap-1`,children:[(0,X.jsx)(v,{className:`h-3 w-3`}),(0,X.jsx)(`span`,{children:`Retry`})]})]})]})]})});function wo(){let e=W(e=>e.mode),t=W(e=>e.modes),{listModes:n,switchMode:r}=Z(),[i,a]=(0,B.useState)(!1),o=(0,B.useRef)(null);(0,B.useEffect)(()=>{i&&n()},[i,n]),(0,B.useEffect)(()=>{if(!i)return;let e=e=>{o.current?.contains(e.target)||a(!1)},t=e=>{e.key===`Escape`&&a(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[i]);let s=t.length>0?t:[{id:`default`,name:`Default`,description:`Standard agent behaviour`}];return(0,X.jsxs)(`div`,{ref:o,className:`relative shrink-0`,children:[(0,X.jsxs)(`button`,{type:`button`,onClick:()=>a(e=>!e),className:Y(`flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium`,`bg-accent/40 text-foreground hover:bg-accent transition-colors border border-transparent hover:border-primary/30`),title:`Active mode`,children:[`mode: `,(0,X.jsx)(`span`,{className:`font-mono`,children:e||`default`}),(0,X.jsx)(ut,{className:`h-3 w-3 opacity-60`})]}),i&&(0,X.jsxs)(`div`,{className:`absolute top-full left-0 mt-1 w-64 rounded-md border bg-popover shadow-lg z-30 py-1`,children:[(0,X.jsx)(`div`,{className:`px-3 py-1.5 text-[10px] uppercase tracking-wider text-muted-foreground border-b`,children:`Mode`}),s.map(t=>(0,X.jsxs)(`button`,{type:`button`,onClick:()=>{r(t.id),a(!1)},className:Y(`w-full text-left px-3 py-2 hover:bg-accent/40 flex items-start gap-2`,t.id===e&&`bg-accent/30`),children:[(0,X.jsx)(pn,{className:Y(`h-3.5 w-3.5 mt-0.5 shrink-0`,t.id===e?`opacity-100 text-primary`:`opacity-0`)}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`div`,{className:`text-xs font-mono`,children:t.id}),t.description&&(0,X.jsx)(`div`,{className:`text-[11px] text-muted-foreground leading-snug`,children:t.description})]})]},t.id))]})]})}function To({open:e,onClose:t,className:n}){let[r,i]=(0,B.useState)([]),a=Z(),o=(0,B.useRef)(null),s=(0,B.useRef)(null);(0,B.useEffect)(()=>{if(!(!e||!a.client?.isConnected))return a.client.send?.({type:`process.list`}),o.current=a.client.on?.(`process.list`,e=>{let t=e?.payload;t?.processes&&i(t.processes)})??null,s.current=setInterval(()=>{a.client.send?.({type:`process.list`})},3e3),()=>{o.current?.(),s.current&&clearInterval(s.current)}},[e,a.client]);let c=(0,B.useCallback)(e=>{a.client.send?.({type:`process.kill`,payload:{pid:e}})},[a.client]),l=(0,B.useCallback)(()=>{a.client.send?.({type:`process.killAll`})},[a.client]),u=r.filter(e=>e.status===`running`);return e?(0,X.jsx)(`div`,{className:Y(`fixed inset-0 z-50 flex items-start justify-center pt-[10vh] bg-black/40 backdrop-blur-sm`,n),onClick:e=>{e.target===e.currentTarget&&t()},children:(0,X.jsxs)(`div`,{className:`w-full max-w-lg rounded-xl border bg-card shadow-2xl max-h-[75vh] flex flex-col animate-in fade-in zoom-in-95`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b shrink-0`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,X.jsx)(`span`,{className:`flex items-center justify-center w-8 h-8 rounded-lg bg-amber-500/10 text-amber-600 dark:text-amber-400`,children:(0,X.jsx)(vn,{className:`h-4 w-4`})}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Running Processes`}),(0,X.jsxs)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[u.length,` active · `,r.length,` total`]})]})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,children:[u.length>0&&(0,X.jsxs)(`button`,{type:`button`,onClick:l,className:`flex items-center gap-1.5 px-2.5 py-1.5 rounded-md text-xs text-destructive hover:bg-destructive/10 transition-colors font-medium`,children:[(0,X.jsx)(Ct,{className:`h-3 w-3 fill-current`}),`Kill All`]}),(0,X.jsx)(`button`,{type:`button`,onClick:t,className:`p-1.5 rounded-md hover:bg-muted transition-colors`,children:(0,X.jsx)(Ie,{className:`h-4 w-4`})})]})]}),(0,X.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:r.length===0?(0,X.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 gap-3 text-muted-foreground`,children:[(0,X.jsx)(vn,{className:`h-10 w-10 opacity-15`}),(0,X.jsx)(`p`,{className:`text-sm font-medium`,children:`No processes tracked`}),(0,X.jsx)(`p`,{className:`text-xs text-center max-w-xs`,children:`Processes appear here when the agent runs bash or exec tools. Active processes show a pulsing LED.`})]}):(0,X.jsx)(`div`,{className:`divide-y`,children:r.map(e=>{let t=e.status===`running`?Math.floor((Date.now()-e.startedAt)/1e3):null,n=t?t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`:null,r=e.protected===!0;return(0,X.jsxs)(`div`,{className:Y(`flex items-center justify-between px-4 py-3 text-xs transition-colors`,e.status===`running`?`bg-background hover:bg-muted/30`:`bg-muted/20 text-muted-foreground`),children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[(0,X.jsx)(`span`,{className:Y(`led shrink-0`,e.status===`running`?r?`text-blue-400`:`text-[hsl(var(--success))] led-pulse`:`text-muted-foreground`)}),(0,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsxs)(`span`,{className:`font-mono text-[10px] text-muted-foreground shrink-0`,children:[`PID `,e.pid]}),(0,X.jsx)(`span`,{className:`font-medium truncate`,children:e.tool}),r&&(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 px-1 py-0.5 rounded text-[9px] bg-blue-500/10 text-blue-600 dark:text-blue-400 font-medium shrink-0`,title:`Protected — survives kill/killAll`,children:[(0,X.jsx)(tt,{className:`h-2.5 w-2.5`}),`protected`]})]}),(0,X.jsx)(`code`,{className:`text-[10px] text-muted-foreground/70 truncate block mt-0.5 font-mono`,children:e.command})]})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-3 shrink-0 ml-3`,children:[n&&(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:n}),e.status===`running`&&!r&&(0,X.jsx)(`button`,{type:`button`,onClick:()=>c(e.pid),className:`p-1.5 rounded-md hover:bg-destructive/10 hover:text-destructive transition-colors`,title:`Kill PID ${e.pid}`,children:(0,X.jsx)(Ct,{className:`h-3.5 w-3.5 fill-current`})})]})]},e.pid)})})})]})}):null}var Eo=`
98
+ `).length)),className:`w-full resize-none rounded-md border bg-background text-foreground px-2 py-1.5 text-sm font-mono focus:outline-none focus:ring-2 focus:ring-ring`}),(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,X.jsx)(`span`,{className:`text-[10px] text-primary-foreground/60`,children:`⌘/Ctrl+Enter to save · Esc to cancel`}),(0,X.jsxs)(`div`,{className:`flex gap-1`,children:[(0,X.jsx)(`button`,{type:`button`,onClick:ie,className:`text-xs px-2 py-0.5 rounded border border-primary-foreground/30 hover:bg-primary-foreground/10`,children:`Cancel`}),(0,X.jsx)(`button`,{type:`button`,onClick:ae,disabled:!c.trim(),className:`text-xs px-2 py-0.5 rounded bg-primary-foreground text-primary disabled:opacity-50`,children:`Save & resend`})]})]})]}):(0,X.jsx)(`div`,{className:Y(`text-sm leading-relaxed markdown-content`,e.streaming&&`streaming-cursor`),children:e.content?u&&e.role===`assistant`?(0,X.jsx)(`pre`,{className:`whitespace-pre-wrap break-words font-mono text-xs leading-relaxed text-foreground/90 max-h-[40rem] overflow-auto`,children:e.content}):e.role===`assistant`&&e.isError?(0,X.jsx)(So,{text:e.content}):(0,X.jsx)(Ne,{remarkPlugins:[De],rehypePlugins:_o,components:yo,children:e.content}):e.streaming?(0,X.jsx)(`span`,{className:`inline-block animate-pulse text-muted-foreground`,children:`Typing...`}):(0,X.jsx)(`span`,{className:`text-muted-foreground italic`,children:`No content`})})}),M&&e.content&&(()=>{let t=so(e.content);return t.length===0?null:(0,X.jsx)(fo,{steps:t,yoloMode:j,autoMode:A===`auto`,autoDelayMs:k.autonomyDelayMs,onAutoSubmit:ee})})(),(0,X.jsxs)(`div`,{className:Y(`flex items-center gap-2 px-1`,f?`flex-row-reverse`:`flex-row`),children:[(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground/50`,children:new Date(e.timestamp).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})}),(0,X.jsx)(`span`,{className:`w-px h-3 bg-border/60 shrink-0`,"aria-hidden":!0}),e.runSummary&&(0,X.jsxs)(`span`,{className:`text-[10px] text-muted-foreground/60 font-mono tabular-nums`,title:[`Iterations: ${e.runSummary.iterations}`,`Tool calls: ${e.runSummary.tools}`,`Elapsed: ${(e.runSummary.durationMs/1e3).toFixed(2)}s`,e.runSummary.costDelta>0?`Cost: ${e.runSummary.costDelta.toFixed(4)}`:``].filter(Boolean).join(` · `),children:[e.runSummary.iterations,` iter`,e.runSummary.tools>0?` · ${e.runSummary.tools} tool${e.runSummary.tools===1?``:`s`}`:``,` · `,e.runSummary.durationMs<6e4?`${(e.runSummary.durationMs/1e3).toFixed(1)}s`:`${Math.floor(e.runSummary.durationMs/6e4)}m ${Math.floor(e.runSummary.durationMs%6e4/1e3)}s`,e.runSummary.costDelta>0?` · ${e.runSummary.costDelta>=.01?e.runSummary.costDelta.toFixed(4):e.runSummary.costDelta.toFixed(6).replace(/0+$/,``).replace(/\.$/,``)}`:``]}),e.usage&&(e.usage.input>0||e.usage.output>0)&&(()=>{let t=e.usage,n=(t.input*E+t.output*D+(t.cacheRead??0)*O)/1e6,r=E>0||D>0,i=n>=.01?`${n.toFixed(4)}`:n>0?`${n.toFixed(6).replace(/0+$/,``).replace(/\.$/,``)}`:``;return(0,X.jsxs)(`span`,{className:`text-[10px] text-muted-foreground/60 font-mono tabular-nums`,title:[`Input: ${t.input.toLocaleString()}`,`Output: ${t.output.toLocaleString()}`,t.cacheRead?`Cache read: ${t.cacheRead.toLocaleString()}`:``,r?`Cost: ${i}`:``].filter(Boolean).join(` · `),children:[t.input.toLocaleString(),`→`,t.output.toLocaleString(),t.cacheRead?` · ${t.cacheRead.toLocaleString()} ↺`:``,r&&i?` · ${i}`:``]})})(),!p&&e.content&&!e.streaming&&(0,X.jsx)(bo,{text:e.content,label:`Copy`,className:`opacity-50 hover:opacity-100 transition-opacity`}),e.role===`assistant`&&e.content&&!e.streaming&&(0,X.jsxs)(`button`,{type:`button`,onClick:()=>d(e=>!e),title:u?`Show rendered markdown`:`Show raw markdown source`,className:Y(`text-xs inline-flex items-center gap-1 transition-opacity`,u?`text-primary hover:text-primary/80 opacity-100`:`opacity-50 hover:opacity-100 text-muted-foreground hover:text-foreground`),children:[(0,X.jsx)(jt,{className:`h-3 w-3`}),(0,X.jsx)(`span`,{children:u?`Rendered`:`Raw`})]}),f&&!o&&!_&&e.content&&(0,X.jsxs)(`button`,{type:`button`,onClick:re,title:`Edit & resend this prompt`,className:`opacity-50 hover:opacity-100 transition-opacity text-xs text-muted-foreground hover:text-foreground inline-flex items-center gap-1`,children:[(0,X.jsx)(x,{className:`h-3 w-3`}),(0,X.jsx)(`span`,{children:`Edit`})]}),e.role===`assistant`&&e.content&&!e.streaming&&(0,X.jsxs)(`button`,{type:`button`,onClick:()=>C(e.id),title:T?`Unpin`:`Pin this answer`,className:Y(`text-xs inline-flex items-center gap-1 transition-opacity`,T?`text-amber-500 hover:text-amber-600 opacity-100`:`opacity-50 hover:opacity-100 text-muted-foreground hover:text-foreground`),children:[T?(0,X.jsx)(he,{className:`h-3 w-3`}):(0,X.jsx)(P,{className:`h-3 w-3`}),(0,X.jsx)(`span`,{children:T?`Pinned`:`Pin`})]}),M&&e.content&&!e.streaming&&(0,X.jsxs)(`button`,{type:`button`,onClick:te,title:`Regenerate this response`,className:`opacity-50 hover:opacity-100 transition-opacity text-xs text-muted-foreground hover:text-foreground inline-flex items-center gap-1`,children:[(0,X.jsx)(v,{className:`h-3 w-3`}),(0,X.jsx)(`span`,{children:`Retry`})]})]})]})]})});function To(){let e=W(e=>e.mode),t=W(e=>e.modes),{listModes:n,switchMode:r}=Z(),[i,a]=(0,B.useState)(!1),o=(0,B.useRef)(null);(0,B.useEffect)(()=>{i&&n()},[i,n]),(0,B.useEffect)(()=>{if(!i)return;let e=e=>{o.current?.contains(e.target)||a(!1)},t=e=>{e.key===`Escape`&&a(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[i]);let s=t.length>0?t:[{id:`default`,name:`Default`,description:`Standard agent behaviour`}];return(0,X.jsxs)(`div`,{ref:o,className:`relative shrink-0`,children:[(0,X.jsxs)(`button`,{type:`button`,onClick:()=>a(e=>!e),className:Y(`flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium`,`bg-accent/40 text-foreground hover:bg-accent transition-colors border border-transparent hover:border-primary/30`),title:`Active mode`,children:[`mode: `,(0,X.jsx)(`span`,{className:`font-mono`,children:e||`default`}),(0,X.jsx)(ut,{className:`h-3 w-3 opacity-60`})]}),i&&(0,X.jsxs)(`div`,{className:`absolute top-full left-0 mt-1 w-64 rounded-md border bg-popover shadow-lg z-30 py-1`,children:[(0,X.jsx)(`div`,{className:`px-3 py-1.5 text-[10px] uppercase tracking-wider text-muted-foreground border-b`,children:`Mode`}),s.map(t=>(0,X.jsxs)(`button`,{type:`button`,onClick:()=>{r(t.id),a(!1)},className:Y(`w-full text-left px-3 py-2 hover:bg-accent/40 flex items-start gap-2`,t.id===e&&`bg-accent/30`),children:[(0,X.jsx)(pn,{className:Y(`h-3.5 w-3.5 mt-0.5 shrink-0`,t.id===e?`opacity-100 text-primary`:`opacity-0`)}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`div`,{className:`text-xs font-mono`,children:t.id}),t.description&&(0,X.jsx)(`div`,{className:`text-[11px] text-muted-foreground leading-snug`,children:t.description})]})]},t.id))]})]})}function Eo({open:e,onClose:t,className:n}){let[r,i]=(0,B.useState)([]),a=Z(),o=(0,B.useRef)(null),s=(0,B.useRef)(null);(0,B.useEffect)(()=>{if(!(!e||!a.client?.isConnected))return a.client.send?.({type:`process.list`}),o.current=a.client.on?.(`process.list`,e=>{let t=e?.payload;t?.processes&&i(t.processes)})??null,s.current=setInterval(()=>{a.client.send?.({type:`process.list`})},3e3),()=>{o.current?.(),s.current&&clearInterval(s.current)}},[e,a.client]);let c=(0,B.useCallback)(e=>{a.client.send?.({type:`process.kill`,payload:{pid:e}})},[a.client]),l=(0,B.useCallback)(()=>{a.client.send?.({type:`process.killAll`})},[a.client]),u=r.filter(e=>e.status===`running`);return e?(0,X.jsx)(`div`,{className:Y(`fixed inset-0 z-50 flex items-start justify-center pt-[10vh] bg-black/40 backdrop-blur-sm`,n),onClick:e=>{e.target===e.currentTarget&&t()},children:(0,X.jsxs)(`div`,{className:`w-full max-w-lg rounded-xl border bg-card shadow-2xl max-h-[75vh] flex flex-col animate-in fade-in zoom-in-95`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b shrink-0`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,X.jsx)(`span`,{className:`flex items-center justify-center w-8 h-8 rounded-lg bg-amber-500/10 text-amber-600 dark:text-amber-400`,children:(0,X.jsx)(vn,{className:`h-4 w-4`})}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Running Processes`}),(0,X.jsxs)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[u.length,` active · `,r.length,` total`]})]})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,children:[u.length>0&&(0,X.jsxs)(`button`,{type:`button`,onClick:l,className:`flex items-center gap-1.5 px-2.5 py-1.5 rounded-md text-xs text-destructive hover:bg-destructive/10 transition-colors font-medium`,children:[(0,X.jsx)(Ct,{className:`h-3 w-3 fill-current`}),`Kill All`]}),(0,X.jsx)(`button`,{type:`button`,onClick:t,className:`p-1.5 rounded-md hover:bg-muted transition-colors`,children:(0,X.jsx)(Ie,{className:`h-4 w-4`})})]})]}),(0,X.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:r.length===0?(0,X.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 gap-3 text-muted-foreground`,children:[(0,X.jsx)(vn,{className:`h-10 w-10 opacity-15`}),(0,X.jsx)(`p`,{className:`text-sm font-medium`,children:`No processes tracked`}),(0,X.jsx)(`p`,{className:`text-xs text-center max-w-xs`,children:`Processes appear here when the agent runs bash or exec tools. Active processes show a pulsing LED.`})]}):(0,X.jsx)(`div`,{className:`divide-y`,children:r.map(e=>{let t=e.status===`running`?Math.floor((Date.now()-e.startedAt)/1e3):null,n=t?t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`:null,r=e.protected===!0;return(0,X.jsxs)(`div`,{className:Y(`flex items-center justify-between px-4 py-3 text-xs transition-colors`,e.status===`running`?`bg-background hover:bg-muted/30`:`bg-muted/20 text-muted-foreground`),children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[(0,X.jsx)(`span`,{className:Y(`led shrink-0`,e.status===`running`?r?`text-blue-400`:`text-[hsl(var(--success))] led-pulse`:`text-muted-foreground`)}),(0,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsxs)(`span`,{className:`font-mono text-[10px] text-muted-foreground shrink-0`,children:[`PID `,e.pid]}),(0,X.jsx)(`span`,{className:`font-medium truncate`,children:e.tool}),r&&(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 px-1 py-0.5 rounded text-[9px] bg-blue-500/10 text-blue-600 dark:text-blue-400 font-medium shrink-0`,title:`Protected — survives kill/killAll`,children:[(0,X.jsx)(tt,{className:`h-2.5 w-2.5`}),`protected`]})]}),(0,X.jsx)(`code`,{className:`text-[10px] text-muted-foreground/70 truncate block mt-0.5 font-mono`,children:e.command})]})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-3 shrink-0 ml-3`,children:[n&&(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:n}),e.status===`running`&&!r&&(0,X.jsx)(`button`,{type:`button`,onClick:()=>c(e.pid),className:`p-1.5 rounded-md hover:bg-destructive/10 hover:text-destructive transition-colors`,title:`Kill PID ${e.pid}`,children:(0,X.jsx)(Ct,{className:`h-3.5 w-3.5 fill-current`})})]})]},e.pid)})})})]})}):null}var Do=`
103
99
  ::highlight(chat-search) { background-color: hsl(var(--primary) / 0.3); color: inherit; }
104
100
  ::highlight(chat-search-active) { background-color: hsl(var(--primary) / 0.85); color: hsl(var(--primary-foreground)); }
105
- `;function Do(){let e=G(e=>e.searchOpen),t=G(e=>e.setSearchOpen),n=G(e=>e.searchQuery),r=G(e=>e.setSearchQuery),i=H(e=>e.messages),a=G(e=>e.requestScrollToMessage),o=(0,B.useRef)(null),[s,c]=(0,B.useState)(0),[l,u]=(0,B.useState)(0);(0,B.useEffect)(()=>{e&&requestAnimationFrame(()=>o.current?.focus())},[e]),(0,B.useEffect)(()=>{let e=document.createElement(`style`);return e.textContent=Eo,document.head.appendChild(e),()=>{document.head.removeChild(e)}},[]);let d=(0,B.useMemo)(()=>{let e=n.trim().toLowerCase();return e?i.filter(t=>t.role===`tool`?(t.toolName??``).toLowerCase().includes(e)||(t.toolResult??``).toLowerCase().includes(e)||JSON.stringify(t.toolInput??``).toLowerCase().includes(e):t.content.toLowerCase().includes(e)).map(e=>e.id):[]},[i,n]);if((0,B.useEffect)(()=>{s>=d.length&&c(0)},[d,s]),(0,B.useEffect)(()=>{let t=window,r=t.CSS?.highlights,i=t.Highlight;if(!r||!i)return;let a=()=>{r.delete(`chat-search`),r.delete(`chat-search-active`)},o=n.trim();if(!o||!e){a();return}let c=o.toLowerCase(),l=[],u=[],f=d[s];for(let e of document.querySelectorAll(`[data-message-id]`)){let t=e.dataset.messageId===f,n=document.createTreeWalker(e,NodeFilter.SHOW_TEXT),r=n.nextNode();for(;r;){let e=r.nodeValue??``;if(e.length>0){let n=e.toLowerCase(),i=0;for(;i<=n.length-c.length;){let e=n.indexOf(c,i);if(e===-1)break;let a=document.createRange();a.setStart(r,e),a.setEnd(r,e+c.length),l.push(a),t&&u.push(a),i=e+c.length}}r=n.nextNode()}}return l.length>0?r.set(`chat-search`,new i(...l)):r.delete(`chat-search`),u.length>0?r.set(`chat-search-active`,new i(...u)):r.delete(`chat-search-active`),a},[n,d,s,e,l]),(0,B.useEffect)(()=>{let e=d[s];if(!e)return;a(e);let t=0,n=requestAnimationFrame(function e(){u(e=>e+1),++t<3&&(n=requestAnimationFrame(e))});return()=>cancelAnimationFrame(n)},[d,s,a]),!e)return null;let f=e=>{d.length!==0&&c(t=>(t+e+d.length)%d.length)};return(0,X.jsx)(`div`,{className:`absolute top-2 right-4 z-30 w-[28rem] max-w-[calc(100%-2rem)] rounded-lg border bg-popover shadow-xl`,children:(0,X.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[(0,X.jsx)(wn,{className:`h-4 w-4 text-muted-foreground shrink-0`}),(0,X.jsx)(`input`,{ref:o,value:n,onChange:e=>r(e.target.value),onKeyDown:e=>{e.key===`Escape`?(e.preventDefault(),t(!1)):e.key===`Enter`?(e.preventDefault(),f(e.shiftKey?-1:1)):e.key===`ArrowDown`?(e.preventDefault(),f(1)):e.key===`ArrowUp`&&(e.preventDefault(),f(-1))},placeholder:`Search in chat…`,className:`flex-1 bg-transparent outline-none text-sm placeholder:text-muted-foreground`}),(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums shrink-0`,children:d.length===0?n?`0`:``:`${s+1} / ${d.length}`}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>f(-1),disabled:d.length===0,className:Y(`p-1 rounded hover:bg-muted disabled:opacity-30 disabled:cursor-not-allowed`),title:`Previous hit`,children:(0,X.jsx)(qt,{className:`h-3.5 w-3.5`})}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>f(1),disabled:d.length===0,className:Y(`p-1 rounded hover:bg-muted disabled:opacity-30 disabled:cursor-not-allowed`),title:`Next hit`,children:(0,X.jsx)(Ft,{className:`h-3.5 w-3.5`})}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>t(!1),className:`p-1 rounded hover:bg-muted text-muted-foreground`,title:`Close (Esc)`,children:(0,X.jsx)(Ie,{className:`h-3.5 w-3.5`})})]})})}function Oo(e){return e<1e3?`${e}ms`:e<6e4?`${(e/1e3).toFixed(e<1e4?2:1)}s`:`${Math.floor(e/6e4)}m${Math.floor(e%6e4/1e3)}s`}var ko=(0,B.memo)(function({tools:e,defaultOpen:t=!1,isContinuation:r=!1}){let[i,a]=(0,B.useState)(t);if(e.length===1)return(0,X.jsx)(Co,{message:z(e[0]),isFirst:!0,isContinuation:r});let o=e.filter(e=>e.toolResult===void 0).length,s=e.filter(e=>e.isError).length,c=e.reduce((e,t)=>e+(t.toolDurationMs??0),0),l=Array.from(new Set(e.map(e=>e.toolName).filter(Boolean))),u=l.slice(0,3).join(`, `),d=l.length>3?` +${l.length-3}`:``;return(0,X.jsxs)(`div`,{className:`flex gap-3 animate-message`,children:[r?(0,X.jsx)(`div`,{className:`flex-shrink-0 w-8 h-8`,"aria-hidden":!0}):(0,X.jsx)(`div`,{className:`flex-shrink-0 w-8 h-8 rounded-full flex items-center justify-center bg-secondary text-secondary-foreground ring-2 ring-offset-2 ring-offset-background ring-secondary/20`,children:(0,X.jsx)(vn,{className:`h-4 w-4`})}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5 max-w-[85%] flex-1 min-w-0`,children:[(0,X.jsxs)(`button`,{type:`button`,onClick:()=>a(e=>!e),className:Y(`flex items-center gap-2 text-sm font-medium cursor-pointer select-none`,`hover:bg-muted/50 rounded-lg px-2 py-1.5 -mx-2 transition-colors`,`border border-border/40 bg-muted/30`),children:[i?(0,X.jsx)(ut,{className:`h-3.5 w-3.5 text-muted-foreground`}):(0,X.jsx)(n,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,X.jsx)(vn,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,X.jsxs)(`span`,{className:`font-mono text-xs`,children:[e.length,` tool call`,e.length===1?``:`s`]}),o>0?(0,X.jsx)(L,{className:`h-3 w-3 animate-spin text-amber-500`}):s>0?(0,X.jsx)(N,{className:`h-3 w-3 text-destructive`}):(0,X.jsx)(Be,{className:`h-3 w-3 text-green-500`}),c>0&&(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums font-normal`,children:Oo(c)}),u&&(0,X.jsxs)(`span`,{className:`text-xs text-muted-foreground/80 font-mono truncate`,children:[`· `,u,d]})]}),i&&(0,X.jsx)(`div`,{className:`space-y-2 pl-3 border-l-2 border-border/40 ml-2 tool-details`,children:e.map(e=>(0,X.jsx)(Co,{message:e,isFirst:!1},e.id))})]})]})}),Ao=[{icon:wn,title:`Understand`,hint:`Explore and analyze the codebase`,tone:`text-blue-600 dark:text-blue-400 bg-blue-500/10 border-blue-500/20`,prompts:[`Map out the structure of this codebase: what are the main modules or components, how do they depend on each other, and what are the key patterns used throughout?`,`Find and document the public API surface — all exported interfaces, functions, and types that other parts of the system depend on.`,`Trace the flow of data through the system for a typical operation. Where does input validation happen? Where are side effects triggered?`]},{icon:Ht,title:`Create`,hint:`Build new features and functionality`,tone:`text-emerald-600 dark:text-emerald-400 bg-emerald-500/10 border-emerald-500/20`,prompts:[`Add a new feature that covers the full stack: data model, business logic, and any UI or API layers. Follow existing patterns in this codebase.`,`Write comprehensive tests for a module with low coverage. Include happy paths, edge cases, and error scenarios.`,`Add observability to a critical path — structured logging, error tracking, or metrics that help diagnose issues in production.`]},{icon:Mn,title:`Investigate`,hint:`Debug issues and find root causes`,tone:`text-amber-600 dark:text-amber-400 bg-amber-500/10 border-amber-500/20`,prompts:[`Something isn't working as expected — help me trace from the symptom to the root cause. Follow the code path and identify where behavior diverges from intent.`,`There's a difference between how this works locally versus in production or CI. Check for environment differences, configuration issues, or hidden assumptions.`,`Performance is degrading. Identify the bottlenecks — whether N+1 queries, blocking I/O, unnecessary allocations, or something else — and propose targeted fixes.`]},{icon:yt,title:`Improve`,hint:`Refactor and optimize existing code`,tone:`text-violet-600 dark:text-violet-400 bg-violet-500/10 border-violet-500/20`,prompts:[`Find duplicated or similar logic that could be consolidated into shared utilities. Extract the common parts and update the call sites.`,`Identify modules that have grown too large or handle too many responsibilities. Propose a cleaner separation that can be done incrementally.`,`Review error handling across the codebase: are errors consistent, well-contextualized, and properly propagated? Suggest improvements to the worst cases.`]}],jo=[{name:`/help`,hint:`list every slash command`},{name:`/diag`,hint:`runtime diagnostics`},{name:`/stats`,hint:`tokens · cache · cost · elapsed`},{name:`/tools`,hint:`show registered tools`},{name:`/memory`,hint:`show remembered notes`},{name:`/compact`,hint:`shrink context`},{name:`/clear`,hint:`wipe current context`},{name:`/new`,hint:`fresh session`}];function Mo(e){let t=document.querySelector(`textarea`);t&&((Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype,`value`)?.set)?.call(t,e),t.dispatchEvent(new Event(`input`,{bubbles:!0})),t.focus())}function No(){let{projectName:e,cwd:t}=W(),{provider:n,model:r}=U(),i=U(e=>e.wsConnected),a=U(e=>e.wsUrl),o=G(e=>e.setCurrentView),[s,c]=(0,B.useState)(void 0);(0,B.useEffect)(()=>{if(!i)return;let e=V(a),t=e.on(`providers.saved`,e=>{let t=e.payload;c(t.providers?.length??0)});return e.listSavedProviders(),()=>{t()}},[i,a]);let l=G(e=>e.promptHistory).slice(0,6),{listSessions:u,resumeSession:d}=Z(),f=nr(e=>e.entries);(0,B.useEffect)(()=>{i&&f.length===0&&u(10)},[i]);let p=G(e=>e.sessionNicknames),m=f.filter(e=>!e.isCurrent).slice(0,4);return(0,X.jsxs)(`div`,{className:`flex flex-col gap-8 py-8 px-2 max-w-5xl mx-auto w-full`,children:[(0,X.jsxs)(`div`,{className:`flex flex-col items-center text-center gap-3`,children:[(0,X.jsxs)(`div`,{className:`relative`,children:[(0,X.jsx)(`div`,{className:`w-14 h-14 rounded-2xl bg-gradient-to-br from-primary via-primary to-primary/60 flex items-center justify-center shadow-lg shadow-primary/20`,children:(0,X.jsx)(ze,{className:`h-7 w-7 text-primary-foreground`})}),(0,X.jsx)(`div`,{className:`absolute -inset-3 bg-gradient-to-r from-transparent via-primary/10 to-transparent animate-pulse rounded-full -z-10`})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`h2`,{className:`text-2xl font-semibold tracking-tight`,children:[`Where do you want to start`,e?(0,X.jsxs)(X.Fragment,{children:[` in `,(0,X.jsx)(`span`,{className:`text-primary`,children:e})]}):``,`?`]}),(0,X.jsxs)(`p`,{className:`text-sm text-muted-foreground mt-2 max-w-2xl mx-auto leading-relaxed`,children:[`The agent is connected to your project and ready to read, edit, run commands, search the codebase, track todos, and remember context across sessions. Pick a starting prompt below, write your own, or type`,` `,(0,X.jsx)(`span`,{className:`font-mono text-foreground/80`,children:`/`}),` for the full command palette.`]}),n&&r&&(0,X.jsxs)(`p`,{className:`text-xs text-muted-foreground/70 mt-2 font-mono`,children:[n,` / `,r]}),t&&(0,X.jsxs)(`p`,{className:`text-[11px] text-muted-foreground/50 mt-1 font-mono`,title:t,children:[`Working directory: `,t]})]})]}),i&&s===0&&(0,X.jsxs)(`button`,{type:`button`,onClick:()=>o(`settings`),className:Y(`group rounded-xl border bg-gradient-to-br from-amber-500/10 via-amber-500/5 to-transparent`,`border-amber-500/30 hover:border-amber-500/50 transition-colors`,`p-4 flex items-center gap-4 text-left`),children:[(0,X.jsx)(`span`,{className:`flex items-center justify-center w-12 h-12 rounded-lg bg-amber-500/15 text-amber-600 dark:text-amber-400 shrink-0`,children:(0,X.jsx)(cn,{className:`h-6 w-6`})}),(0,X.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,X.jsx)(`h3`,{className:`text-base font-semibold mb-1`,children:`No API key configured yet`}),(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground leading-relaxed`,children:`Register a provider in Settings before sending a message — otherwise the agent has nothing to talk to. Anthropic, OpenAI, Google, and any OpenAI-compatible endpoint all work.`})]}),(0,X.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-amber-600 dark:text-amber-400 font-medium shrink-0 group-hover:translate-x-0.5 transition-transform`,children:[`Open Settings `,(0,X.jsx)(ln,{className:`h-3.5 w-3.5`})]})]}),(0,X.jsx)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4`,children:Ao.map((e,t)=>{let n=e.icon;return(0,X.jsxs)(`div`,{className:`rounded-xl border bg-card/40 backdrop-blur-sm p-4 flex flex-col gap-3 animate-message hover:border-primary/20 hover:shadow-sm transition-all`,style:{animationDelay:`${t*80}ms`},children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`span`,{className:Y(`flex items-center justify-center w-8 h-8 rounded-lg border`,e.tone),children:(0,X.jsx)(n,{className:`h-4 w-4`})}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h3`,{className:`text-sm font-semibold`,children:e.title}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.hint})]})]}),(0,X.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:e.prompts.map((e,t)=>(0,X.jsx)(`button`,{type:`button`,onClick:()=>Mo(e),className:`text-left text-xs leading-relaxed text-foreground/80 hover:text-foreground border border-transparent hover:border-border/60 rounded-lg px-3 py-2 hover:bg-muted/40 transition-colors line-clamp-3`,title:e,children:e},t))})]},e.title)})}),m.length>0&&(0,X.jsxs)(`div`,{className:`rounded-xl border bg-muted/20 p-4`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,X.jsx)(_n,{className:`h-4 w-4 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`text-xs uppercase tracking-wider text-muted-foreground font-medium`,children:`Pick back up`})]}),(0,X.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2`,children:m.map(e=>(0,X.jsxs)(`button`,{type:`button`,onClick:()=>d(e.id),className:`text-left rounded-lg border border-border/40 bg-background/60 hover:border-primary/40 hover:bg-accent/30 px-3 py-2 transition-colors group/sess`,title:e.title,children:[(0,X.jsx)(`div`,{className:`text-sm font-medium truncate text-foreground group-hover/sess:text-primary`,children:p[e.id]||e.title||`(empty)`}),(0,X.jsxs)(`div`,{className:`text-[10px] text-muted-foreground font-mono truncate mt-0.5`,children:[e.provider,`/`,e.model,e.tokenTotal>0&&(0,X.jsxs)(`span`,{className:`ml-2`,children:[`· `,e.tokenTotal.toLocaleString(),` tok`]})]})]},e.id))})]}),l.length>0&&(0,X.jsxs)(`div`,{className:`rounded-xl border bg-muted/20 p-4`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,X.jsx)(Pe,{className:`h-4 w-4 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`text-xs uppercase tracking-wider text-muted-foreground font-medium`,children:`Recent prompts`})]}),(0,X.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:l.filter(e=>!e.startsWith(`/`)).slice(0,5).map((e,t)=>(0,X.jsx)(`button`,{type:`button`,onClick:()=>Mo(e),className:`text-left text-xs leading-relaxed text-muted-foreground hover:text-foreground border border-transparent hover:border-border/60 rounded-lg px-3 py-2 hover:bg-background/60 transition-colors line-clamp-2`,title:e,children:e},t))})]}),(0,X.jsxs)(`div`,{className:`rounded-xl border bg-muted/20 p-4`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,X.jsx)(Xe,{className:`h-4 w-4 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`text-xs uppercase tracking-wider text-muted-foreground font-medium`,children:`Quick commands`})]}),(0,X.jsx)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-2`,children:jo.map(e=>(0,X.jsxs)(`button`,{type:`button`,onClick:()=>Mo(e.name),className:`text-left flex flex-col gap-0.5 rounded-md border border-border/40 bg-background/60 px-3 py-2 hover:border-primary/40 hover:bg-accent/40 transition-colors`,children:[(0,X.jsx)(`span`,{className:`font-mono text-xs text-foreground`,children:e.name}),(0,X.jsx)(`span`,{className:`text-[11px] text-muted-foreground truncate`,children:e.hint})]},e.name))})]})]})}function Po(){let e=H(e=>e.thinkingBuffer);if(!e)return null;let t=e.split(`
101
+ `;function Oo(){let e=G(e=>e.searchOpen),t=G(e=>e.setSearchOpen),n=G(e=>e.searchQuery),r=G(e=>e.setSearchQuery),i=H(e=>e.messages),a=G(e=>e.requestScrollToMessage),o=(0,B.useRef)(null),[s,c]=(0,B.useState)(0),[l,u]=(0,B.useState)(0);(0,B.useEffect)(()=>{e&&requestAnimationFrame(()=>o.current?.focus())},[e]),(0,B.useEffect)(()=>{let e=document.createElement(`style`);return e.textContent=Do,document.head.appendChild(e),()=>{document.head.removeChild(e)}},[]);let d=(0,B.useMemo)(()=>{let e=n.trim().toLowerCase();return e?i.filter(t=>t.role===`tool`?(t.toolName??``).toLowerCase().includes(e)||(t.toolResult??``).toLowerCase().includes(e)||JSON.stringify(t.toolInput??``).toLowerCase().includes(e):t.content.toLowerCase().includes(e)).map(e=>e.id):[]},[i,n]);if((0,B.useEffect)(()=>{s>=d.length&&c(0)},[d,s]),(0,B.useEffect)(()=>{let t=window,r=t.CSS?.highlights,i=t.Highlight;if(!r||!i)return;let a=()=>{r.delete(`chat-search`),r.delete(`chat-search-active`)},o=n.trim();if(!o||!e){a();return}let c=o.toLowerCase(),l=[],u=[],f=d[s];for(let e of document.querySelectorAll(`[data-message-id]`)){let t=e.dataset.messageId===f,n=document.createTreeWalker(e,NodeFilter.SHOW_TEXT),r=n.nextNode();for(;r;){let e=r.nodeValue??``;if(e.length>0){let n=e.toLowerCase(),i=0;for(;i<=n.length-c.length;){let e=n.indexOf(c,i);if(e===-1)break;let a=document.createRange();a.setStart(r,e),a.setEnd(r,e+c.length),l.push(a),t&&u.push(a),i=e+c.length}}r=n.nextNode()}}return l.length>0?r.set(`chat-search`,new i(...l)):r.delete(`chat-search`),u.length>0?r.set(`chat-search-active`,new i(...u)):r.delete(`chat-search-active`),a},[n,d,s,e,l]),(0,B.useEffect)(()=>{let e=d[s];if(!e)return;a(e);let t=0,n=requestAnimationFrame(function e(){u(e=>e+1),++t<3&&(n=requestAnimationFrame(e))});return()=>cancelAnimationFrame(n)},[d,s,a]),!e)return null;let f=e=>{d.length!==0&&c(t=>(t+e+d.length)%d.length)};return(0,X.jsx)(`div`,{className:`absolute top-2 right-4 z-30 w-[28rem] max-w-[calc(100%-2rem)] rounded-lg border bg-popover shadow-xl`,children:(0,X.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[(0,X.jsx)(wn,{className:`h-4 w-4 text-muted-foreground shrink-0`}),(0,X.jsx)(`input`,{ref:o,value:n,onChange:e=>r(e.target.value),onKeyDown:e=>{e.key===`Escape`?(e.preventDefault(),t(!1)):e.key===`Enter`?(e.preventDefault(),f(e.shiftKey?-1:1)):e.key===`ArrowDown`?(e.preventDefault(),f(1)):e.key===`ArrowUp`&&(e.preventDefault(),f(-1))},placeholder:`Search in chat…`,className:`flex-1 bg-transparent outline-none text-sm placeholder:text-muted-foreground`}),(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums shrink-0`,children:d.length===0?n?`0`:``:`${s+1} / ${d.length}`}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>f(-1),disabled:d.length===0,className:Y(`p-1 rounded hover:bg-muted disabled:opacity-30 disabled:cursor-not-allowed`),title:`Previous hit`,children:(0,X.jsx)(qt,{className:`h-3.5 w-3.5`})}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>f(1),disabled:d.length===0,className:Y(`p-1 rounded hover:bg-muted disabled:opacity-30 disabled:cursor-not-allowed`),title:`Next hit`,children:(0,X.jsx)(Ft,{className:`h-3.5 w-3.5`})}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>t(!1),className:`p-1 rounded hover:bg-muted text-muted-foreground`,title:`Close (Esc)`,children:(0,X.jsx)(Ie,{className:`h-3.5 w-3.5`})})]})})}function ko(e){return e<1e3?`${e}ms`:e<6e4?`${(e/1e3).toFixed(e<1e4?2:1)}s`:`${Math.floor(e/6e4)}m${Math.floor(e%6e4/1e3)}s`}var Ao=(0,B.memo)(function({tools:e,defaultOpen:t=!1,isContinuation:r=!1}){let[i,a]=(0,B.useState)(t);if(e.length===1)return(0,X.jsx)(wo,{message:z(e[0]),isFirst:!0,isContinuation:r});let o=e.filter(e=>e.toolResult===void 0).length,s=e.filter(e=>e.isError).length,c=e.reduce((e,t)=>e+(t.toolDurationMs??0),0),l=Array.from(new Set(e.map(e=>e.toolName).filter(Boolean))),u=l.slice(0,3).join(`, `),d=l.length>3?` +${l.length-3}`:``;return(0,X.jsxs)(`div`,{className:`flex gap-3 animate-message`,children:[r?(0,X.jsx)(`div`,{className:`flex-shrink-0 w-8 h-8`,"aria-hidden":!0}):(0,X.jsx)(`div`,{className:`flex-shrink-0 w-8 h-8 rounded-full flex items-center justify-center bg-secondary text-secondary-foreground ring-2 ring-offset-2 ring-offset-background ring-secondary/20`,children:(0,X.jsx)(vn,{className:`h-4 w-4`})}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5 max-w-[85%] flex-1 min-w-0`,children:[(0,X.jsxs)(`button`,{type:`button`,onClick:()=>a(e=>!e),className:Y(`flex items-center gap-2 text-sm font-medium cursor-pointer select-none`,`hover:bg-muted/50 rounded-lg px-2 py-1.5 -mx-2 transition-colors`,`border border-border/40 bg-muted/30`),children:[i?(0,X.jsx)(ut,{className:`h-3.5 w-3.5 text-muted-foreground`}):(0,X.jsx)(n,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,X.jsx)(vn,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,X.jsxs)(`span`,{className:`font-mono text-xs`,children:[e.length,` tool call`,e.length===1?``:`s`]}),o>0?(0,X.jsx)(L,{className:`h-3 w-3 animate-spin text-amber-500`}):s>0?(0,X.jsx)(N,{className:`h-3 w-3 text-destructive`}):(0,X.jsx)(Be,{className:`h-3 w-3 text-green-500`}),c>0&&(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums font-normal`,children:ko(c)}),u&&(0,X.jsxs)(`span`,{className:`text-xs text-muted-foreground/80 font-mono truncate`,children:[`· `,u,d]})]}),i&&(0,X.jsx)(`div`,{className:`space-y-2 pl-3 border-l-2 border-border/40 ml-2 tool-details`,children:e.map(e=>(0,X.jsx)(wo,{message:e,isFirst:!1},e.id))})]})]})}),jo=[{icon:wn,title:`Understand`,hint:`Explore and analyze the codebase`,tone:`text-blue-600 dark:text-blue-400 bg-blue-500/10 border-blue-500/20`,prompts:[`Map out the structure of this codebase: what are the main modules or components, how do they depend on each other, and what are the key patterns used throughout?`,`Find and document the public API surface — all exported interfaces, functions, and types that other parts of the system depend on.`,`Trace the flow of data through the system for a typical operation. Where does input validation happen? Where are side effects triggered?`]},{icon:Ht,title:`Create`,hint:`Build new features and functionality`,tone:`text-emerald-600 dark:text-emerald-400 bg-emerald-500/10 border-emerald-500/20`,prompts:[`Add a new feature that covers the full stack: data model, business logic, and any UI or API layers. Follow existing patterns in this codebase.`,`Write comprehensive tests for a module with low coverage. Include happy paths, edge cases, and error scenarios.`,`Add observability to a critical path — structured logging, error tracking, or metrics that help diagnose issues in production.`]},{icon:Mn,title:`Investigate`,hint:`Debug issues and find root causes`,tone:`text-amber-600 dark:text-amber-400 bg-amber-500/10 border-amber-500/20`,prompts:[`Something isn't working as expected — help me trace from the symptom to the root cause. Follow the code path and identify where behavior diverges from intent.`,`There's a difference between how this works locally versus in production or CI. Check for environment differences, configuration issues, or hidden assumptions.`,`Performance is degrading. Identify the bottlenecks — whether N+1 queries, blocking I/O, unnecessary allocations, or something else — and propose targeted fixes.`]},{icon:yt,title:`Improve`,hint:`Refactor and optimize existing code`,tone:`text-violet-600 dark:text-violet-400 bg-violet-500/10 border-violet-500/20`,prompts:[`Find duplicated or similar logic that could be consolidated into shared utilities. Extract the common parts and update the call sites.`,`Identify modules that have grown too large or handle too many responsibilities. Propose a cleaner separation that can be done incrementally.`,`Review error handling across the codebase: are errors consistent, well-contextualized, and properly propagated? Suggest improvements to the worst cases.`]}],Mo=[{name:`/help`,hint:`list every slash command`},{name:`/diag`,hint:`runtime diagnostics`},{name:`/stats`,hint:`tokens · cache · cost · elapsed`},{name:`/tools`,hint:`show registered tools`},{name:`/memory`,hint:`show remembered notes`},{name:`/compact`,hint:`shrink context`},{name:`/clear`,hint:`wipe current context`},{name:`/new`,hint:`fresh session`}];function No(e){let t=document.querySelector(`textarea`);t&&((Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype,`value`)?.set)?.call(t,e),t.dispatchEvent(new Event(`input`,{bubbles:!0})),t.focus())}function Po(){let{projectName:e,cwd:t}=W(),{provider:n,model:r}=U(),i=U(e=>e.wsConnected),a=U(e=>e.wsUrl),o=G(e=>e.setCurrentView),[s,c]=(0,B.useState)(void 0);(0,B.useEffect)(()=>{if(!i)return;let e=V(a),t=e.on(`providers.saved`,e=>{let t=e.payload;c(t.providers?.length??0)});return e.listSavedProviders(),()=>{t()}},[i,a]);let l=G(e=>e.promptHistory).slice(0,6),{listSessions:u,resumeSession:d}=Z(),f=nr(e=>e.entries);(0,B.useEffect)(()=>{i&&f.length===0&&u(10)},[i]);let p=G(e=>e.sessionNicknames),m=f.filter(e=>!e.isCurrent).slice(0,4);return(0,X.jsxs)(`div`,{className:`flex flex-col gap-8 py-8 px-2 max-w-5xl mx-auto w-full`,children:[(0,X.jsxs)(`div`,{className:`flex flex-col items-center text-center gap-3`,children:[(0,X.jsxs)(`div`,{className:`relative`,children:[(0,X.jsx)(`div`,{className:`w-14 h-14 rounded-2xl bg-gradient-to-br from-primary via-primary to-primary/60 flex items-center justify-center shadow-lg shadow-primary/20`,children:(0,X.jsx)(ze,{className:`h-7 w-7 text-primary-foreground`})}),(0,X.jsx)(`div`,{className:`absolute -inset-3 bg-gradient-to-r from-transparent via-primary/10 to-transparent animate-pulse rounded-full -z-10`})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`h2`,{className:`text-2xl font-semibold tracking-tight`,children:[`Where do you want to start`,e?(0,X.jsxs)(X.Fragment,{children:[` in `,(0,X.jsx)(`span`,{className:`text-primary`,children:e})]}):``,`?`]}),(0,X.jsxs)(`p`,{className:`text-sm text-muted-foreground mt-2 max-w-2xl mx-auto leading-relaxed`,children:[`The agent is connected to your project and ready to read, edit, run commands, search the codebase, track todos, and remember context across sessions. Pick a starting prompt below, write your own, or type`,` `,(0,X.jsx)(`span`,{className:`font-mono text-foreground/80`,children:`/`}),` for the full command palette.`]}),n&&r&&(0,X.jsxs)(`p`,{className:`text-xs text-muted-foreground/70 mt-2 font-mono`,children:[n,` / `,r]}),t&&(0,X.jsxs)(`p`,{className:`text-[11px] text-muted-foreground/50 mt-1 font-mono`,title:t,children:[`Working directory: `,t]})]})]}),i&&s===0&&(0,X.jsxs)(`button`,{type:`button`,onClick:()=>o(`settings`),className:Y(`group rounded-xl border bg-gradient-to-br from-amber-500/10 via-amber-500/5 to-transparent`,`border-amber-500/30 hover:border-amber-500/50 transition-colors`,`p-4 flex items-center gap-4 text-left`),children:[(0,X.jsx)(`span`,{className:`flex items-center justify-center w-12 h-12 rounded-lg bg-amber-500/15 text-amber-600 dark:text-amber-400 shrink-0`,children:(0,X.jsx)(cn,{className:`h-6 w-6`})}),(0,X.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,X.jsx)(`h3`,{className:`text-base font-semibold mb-1`,children:`No API key configured yet`}),(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground leading-relaxed`,children:`Register a provider in Settings before sending a message — otherwise the agent has nothing to talk to. Anthropic, OpenAI, Google, and any OpenAI-compatible endpoint all work.`})]}),(0,X.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-amber-600 dark:text-amber-400 font-medium shrink-0 group-hover:translate-x-0.5 transition-transform`,children:[`Open Settings `,(0,X.jsx)(ln,{className:`h-3.5 w-3.5`})]})]}),(0,X.jsx)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4`,children:jo.map((e,t)=>{let n=e.icon;return(0,X.jsxs)(`div`,{className:`rounded-xl border bg-card/40 backdrop-blur-sm p-4 flex flex-col gap-3 animate-message hover:border-primary/20 hover:shadow-sm transition-all`,style:{animationDelay:`${t*80}ms`},children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`span`,{className:Y(`flex items-center justify-center w-8 h-8 rounded-lg border`,e.tone),children:(0,X.jsx)(n,{className:`h-4 w-4`})}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h3`,{className:`text-sm font-semibold`,children:e.title}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.hint})]})]}),(0,X.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:e.prompts.map((e,t)=>(0,X.jsx)(`button`,{type:`button`,onClick:()=>No(e),className:`text-left text-xs leading-relaxed text-foreground/80 hover:text-foreground border border-transparent hover:border-border/60 rounded-lg px-3 py-2 hover:bg-muted/40 transition-colors line-clamp-3`,title:e,children:e},t))})]},e.title)})}),m.length>0&&(0,X.jsxs)(`div`,{className:`rounded-xl border bg-muted/20 p-4`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,X.jsx)(_n,{className:`h-4 w-4 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`text-xs uppercase tracking-wider text-muted-foreground font-medium`,children:`Pick back up`})]}),(0,X.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2`,children:m.map(e=>(0,X.jsxs)(`button`,{type:`button`,onClick:()=>d(e.id),className:`text-left rounded-lg border border-border/40 bg-background/60 hover:border-primary/40 hover:bg-accent/30 px-3 py-2 transition-colors group/sess`,title:e.title,children:[(0,X.jsx)(`div`,{className:`text-sm font-medium truncate text-foreground group-hover/sess:text-primary`,children:p[e.id]||e.title||`(empty)`}),(0,X.jsxs)(`div`,{className:`text-[10px] text-muted-foreground font-mono truncate mt-0.5`,children:[e.provider,`/`,e.model,e.tokenTotal>0&&(0,X.jsxs)(`span`,{className:`ml-2`,children:[`· `,e.tokenTotal.toLocaleString(),` tok`]})]})]},e.id))})]}),l.length>0&&(0,X.jsxs)(`div`,{className:`rounded-xl border bg-muted/20 p-4`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,X.jsx)(Pe,{className:`h-4 w-4 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`text-xs uppercase tracking-wider text-muted-foreground font-medium`,children:`Recent prompts`})]}),(0,X.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:l.filter(e=>!e.startsWith(`/`)).slice(0,5).map((e,t)=>(0,X.jsx)(`button`,{type:`button`,onClick:()=>No(e),className:`text-left text-xs leading-relaxed text-muted-foreground hover:text-foreground border border-transparent hover:border-border/60 rounded-lg px-3 py-2 hover:bg-background/60 transition-colors line-clamp-2`,title:e,children:e},t))})]}),(0,X.jsxs)(`div`,{className:`rounded-xl border bg-muted/20 p-4`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,X.jsx)(Xe,{className:`h-4 w-4 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`text-xs uppercase tracking-wider text-muted-foreground font-medium`,children:`Quick commands`})]}),(0,X.jsx)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-2`,children:Mo.map(e=>(0,X.jsxs)(`button`,{type:`button`,onClick:()=>No(e.name),className:`text-left flex flex-col gap-0.5 rounded-md border border-border/40 bg-background/60 px-3 py-2 hover:border-primary/40 hover:bg-accent/40 transition-colors`,children:[(0,X.jsx)(`span`,{className:`font-mono text-xs text-foreground`,children:e.name}),(0,X.jsx)(`span`,{className:`text-[11px] text-muted-foreground truncate`,children:e.hint})]},e.name))})]})]})}function Fo(){let e=H(e=>e.thinkingBuffer);if(!e)return null;let t=e.split(`
106
102
  `).slice(-6).join(`
107
- `).trim();return(0,X.jsxs)(`div`,{className:`flex gap-3 animate-message`,children:[(0,X.jsx)(`div`,{className:`flex-shrink-0 w-8 h-8 rounded-full flex items-center justify-center bg-violet-500/10 text-violet-600 dark:text-violet-400 ring-2 ring-offset-2 ring-offset-background ring-violet-500/20`,children:(0,X.jsx)(an,{className:`h-4 w-4 animate-pulse`})}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-1 max-w-[85%] min-w-0`,children:[(0,X.jsx)(`span`,{className:`text-xs font-medium text-violet-600 dark:text-violet-400 px-1`,children:`Thinking…`}),(0,X.jsx)(`div`,{className:`rounded-2xl rounded-bl-md px-3 py-2 bg-violet-500/[0.04] border border-violet-500/20 text-foreground/80`,children:(0,X.jsx)(`pre`,{className:`whitespace-pre-wrap break-words font-sans text-xs leading-relaxed italic max-h-32 overflow-hidden`,children:t||`…`})})]})]})}var Fo=(0,B.memo)(function({row:e,isLoading:t,compactMode:n,isFirstRow:r}){let i=Y(`mx-auto max-w-5xl w-full px-4`,r&&`pt-4`,n?`pb-3`:`pb-6`);return e.kind===`day`?(0,X.jsx)(`div`,{className:i,children:(0,X.jsxs)(`div`,{className:`flex items-center gap-3 py-1 text-[11px] text-muted-foreground/70 uppercase tracking-wider font-medium`,children:[(0,X.jsx)(`div`,{className:`flex-1 h-px bg-border/50`}),(0,X.jsx)(`span`,{children:e.label}),(0,X.jsx)(`div`,{className:`flex-1 h-px bg-border/50`})]})}):e.kind===`user`?(0,X.jsx)(`div`,{className:i,children:(0,X.jsx)(Co,{message:e.message,isFirst:!0})}):(0,X.jsx)(`div`,{className:i,children:(0,X.jsx)(`div`,{className:Y(`chat-turn`,n?`space-y-1`:`space-y-1.5`),children:e.items.map(n=>{if(n.kind===`msg`)return(0,X.jsx)(Co,{message:n.message,isFirst:n.isFirst,isContinuation:n.isContinuation},n.key);let r=e.isLastTurn&&n.isLastGroup&&t&&n.hasRunningTool;return(0,X.jsx)(ko,{tools:n.tools,defaultOpen:r,isContinuation:n.isContinuation},n.key)})})})});function Io(){let e=H(e=>e.messages),t=H(e=>e.isLoading),n=G(e=>e.sidebarOpen),r=G(e=>e.toggleSidebar),i=G(e=>e.compactMode),{totalTokens:a,startTime:o,lastInputTokens:s,maxContext:l,iteration:u}=W(),d=W(e=>e.session),f=d?.id,p=G(e=>f?e.sessionNicknames[f]:void 0),m=G(e=>e.setSessionNickname),h=d?.title,[g,_]=(0,B.useState)(!1),[v,y]=(0,B.useState)(``),b=nr(e=>e.entries),[C,w]=(0,B.useState)(!1),T=(0,B.useRef)(null);(0,B.useEffect)(()=>{if(!C)return;let e=e=>{T.current?.contains(e.target)||w(!1)},t=e=>{e.key===`Escape`&&w(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[C]);let{provider:E,model:D}=U(),O=(0,B.useRef)(null),k=(0,B.useMemo)(()=>Fi(e),[e]),A=(0,B.useRef)(0);A.current=k.length+1;let j=(0,B.useMemo)(()=>{let e=new Map;return k.forEach((t,n)=>{if(t.kind===`user`)e.set(t.message.id,n);else if(t.kind===`agent`)for(let r of t.items)if(r.kind===`msg`)e.set(r.message.id,n);else for(let t of r.tools)e.set(t.id,n)}),e},[k]),ee=G(e=>e.scrollTarget),M=hr(e=>e.autonomy),te=(0,B.useCallback)(e=>{hr.getState().set({autonomy:e}),V()?.send?.({type:`autonomy.switch`,payload:{mode:e}})},[]),[N,ne]=(0,B.useState)(!1),[re,ie]=(0,B.useState)(!1),[ae,oe]=(0,B.useState)(!1);(0,B.useEffect)(()=>{let e=()=>oe(!0);return document.addEventListener(`open:context-breakdown`,e),()=>document.removeEventListener(`open:context-breakdown`,e)},[]);let se=l>0&&s>0?Math.round(s/l*100):0,[ce,le]=(0,B.useState)(!0),[ue,P]=(0,B.useState)(0),[de,F]=(0,B.useState)(!1),fe=(0,B.useRef)(e.length),pe=(0,B.useCallback)(()=>{let e=O.current;if(!e)return;let t=e.scrollSize-e.scrollOffset-e.viewportSize<120;le(t),t&&(P(0),fe.current=H.getState().messages.length),F(e.scrollOffset>e.viewportSize&&e.scrollSize>e.viewportSize*2.5)},[]);(0,B.useEffect)(()=>{let t=O.current;if(t)if(ce)t.scrollToIndex(A.current-1,{align:`end`}),fe.current=e.length;else{let t=e.length-fe.current;t>0&&P(t)}},[e,ce]),(0,B.useEffect)(()=>{le(!0),P(0),fe.current=H.getState().messages.length,requestAnimationFrame(()=>{O.current?.scrollToIndex(A.current-1,{align:`end`})})},[f]),(0,B.useEffect)(()=>{if(!ee)return;let e=j.get(ee.id);e!==void 0&&O.current?.scrollToIndex(e,{align:`center`,smooth:!0})},[ee,j]);let me=(0,B.useCallback)(()=>{O.current?.scrollToIndex(A.current-1,{align:`end`,smooth:!0}),le(!0),P(0),fe.current=H.getState().messages.length},[]),he=(0,B.useCallback)(()=>{O.current?.scrollToIndex(0,{align:`start`,smooth:!0})},[]),[ge,_e]=(0,B.useState)(null),[ve,ye]=(0,B.useState)(()=>Date.now()),be=(0,B.useRef)(null);(0,B.useEffect)(()=>{t&&ge===null&&_e(Date.now()),!t&&ge!==null&&_e(null)},[t,ge]),(0,B.useEffect)(()=>{if(!t)return;let e=setInterval(()=>ye(Date.now()),500);return()=>clearInterval(e)},[t]);let Se=e=>{if(!e)return`--`;let t=Math.floor((Date.now()-e)/1e3);return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`},I=(()=>{if(!t)return`idle`;let n=e[e.length-1];return n?.role===`assistant`&&n.content&&n.streaming?`streaming`:`thinking`})(),Ce=I===`idle`?`bg-muted text-muted-foreground`:I===`streaming`?`bg-blue-500/10 text-blue-600 dark:text-blue-400`:`bg-amber-500/10 text-amber-600 dark:text-amber-400`,we=l>0&&s>0||a.input>0||!!o;return(0,X.jsxs)(`div`,{className:`flex flex-col flex-1 min-h-0`,children:[(0,X.jsxs)(`header`,{className:`flex flex-col border-b bg-card/95 backdrop-blur-sm supports-[backdrop-filter]:bg-card/80 shrink-0 sticky top-0 z-20`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-3 py-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0 flex-1 overflow-hidden`,children:[!n&&(0,X.jsx)($,{variant:`ghost`,size:`icon`,className:`h-7 w-7 shrink-0`,onClick:r,title:`Open sidebar (Ctrl+\\\\)`,children:(0,X.jsx)(xe,{className:`h-4 w-4`})}),!n&&(0,X.jsx)(`div`,{className:`flex items-center gap-1.5 shrink-0 mr-1`,children:(0,X.jsx)(`div`,{className:`w-5 h-5 rounded bg-primary flex items-center justify-center`,children:(0,X.jsx)(ze,{className:`h-3 w-3 text-primary-foreground`})})}),(0,X.jsxs)(`span`,{className:Y(`flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[11px] font-medium shrink-0 tabular-nums`,Ce),title:`Agent state: ${I}`,children:[I!==`idle`&&(0,X.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-current animate-pulse`}),(0,X.jsx)(`span`,{children:I})]}),f&&(g?(0,X.jsx)(`input`,{value:v,onChange:e=>y(e.target.value),onBlur:()=>{v.trim()&&m(f,v),_(!1)},onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),v.trim()&&m(f,v),_(!1)):e.key===`Escape`&&(e.preventDefault(),_(!1))},placeholder:`Session name…`,className:`h-5 px-1.5 text-[11px] bg-background border border-primary/40 rounded focus:outline-none focus:ring-1 focus:ring-ring shrink-0 w-32`,autoFocus:!0}):(0,X.jsxs)(`button`,{type:`button`,onClick:()=>{y(p||h||``),_(!0)},className:`flex items-center gap-1 text-[11px] font-medium text-foreground/80 hover:text-foreground truncate max-w-[12rem] shrink-0 px-1 -mx-1 rounded hover:bg-muted/50 transition-colors`,title:`Click to rename session`,children:[(0,X.jsx)(x,{className:`h-2.5 w-2.5 text-muted-foreground shrink-0`}),(0,X.jsx)(`span`,{className:`truncate`,children:p||h||`Untitled`})]}))]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 shrink-0`,children:[b.length>1&&(0,X.jsxs)(`div`,{ref:T,className:`relative shrink-0`,children:[(0,X.jsxs)(`button`,{type:`button`,onClick:()=>w(e=>!e),className:`flex items-center gap-0.5 px-1 py-0.5 rounded text-[10px] text-muted-foreground hover:text-foreground hover:bg-muted/50 transition-colors`,title:`Switch session`,children:[(0,X.jsx)(Pt,{className:`h-3 w-3`}),(0,X.jsx)(ut,{className:`h-2.5 w-2.5`})]}),C&&(0,X.jsx)(`div`,{className:`absolute left-0 top-full mt-1 z-40 w-64 rounded-md border bg-popover shadow-lg p-1 max-h-60 overflow-y-auto`,children:b.slice(0,15).map(e=>(0,X.jsxs)(`button`,{type:`button`,onClick:()=>{V()?.resumeSession?.(e.id),w(!1)},className:Y(`w-full text-left px-2 py-1.5 rounded text-xs hover:bg-accent transition-colors`,e.isCurrent&&`bg-primary/10`),children:[(0,X.jsx)(`div`,{className:`font-medium truncate`,children:e.title||`(empty)`}),(0,X.jsxs)(`div`,{className:`text-[10px] text-muted-foreground font-mono truncate`,children:[e.provider,`/`,e.model,` · `,e.tokenTotal.toLocaleString(),` tok`]})]},e.id))})]}),(0,X.jsxs)(`button`,{type:`button`,onClick:()=>G.getState().setModelSwitcherOpen(!0),className:`group hidden sm:flex items-center gap-1 px-2 py-0.5 rounded-md border bg-background/50 hover:bg-accent hover:border-primary/40 transition-colors text-[11px] min-w-0 shrink-0`,title:`Change provider / model (Ctrl+M)`,children:[(0,X.jsx)(c,{className:`h-3 w-3 text-muted-foreground group-hover:text-foreground shrink-0`}),(0,X.jsxs)(`span`,{className:`font-mono truncate max-w-[9rem] xl:max-w-[16rem]`,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:E||`no-provider`}),(0,X.jsx)(`span`,{className:`text-muted-foreground/40 mx-0.5`,children:`/`}),(0,X.jsx)(`span`,{className:`font-medium`,children:D||`no-model`})]})]}),(0,X.jsxs)(`div`,{className:`hidden md:flex items-center gap-1.5 shrink-0`,children:[(0,X.jsx)(wo,{}),(0,X.jsx)(Ha,{})]}),u&&(0,X.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[11px] font-medium bg-primary/10 text-primary shrink-0 hover:bg-primary/20 transition-colors cursor-pointer`,title:`Agent iteration — click to jump to live activity`,onClick:()=>document.getElementById(`chat-activity`)?.scrollIntoView({behavior:`smooth`,block:`center`}),children:[(0,X.jsx)(ct,{className:`h-3 w-3 animate-pulse`}),`iter `,u.index,u.max>0?`/${u.max}`:``]}),(0,X.jsx)(ba,{value:M,onChange:te,compact:!0})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-0.5 shrink-0`,children:[(0,X.jsxs)($,{variant:N?`secondary`:`ghost`,size:`icon`,className:Y(`h-7 w-7 relative`,N&&`bg-amber-500/10 text-amber-600 dark:text-amber-400`),onClick:()=>ne(e=>!e),title:`Running processes`,children:[(0,X.jsx)(vn,{className:`h-4 w-4`}),N&&(0,X.jsx)(`span`,{className:`absolute -bottom-0.5 left-1/2 -translate-x-1/2 w-1 h-1 rounded-full bg-amber-500`})]}),(0,X.jsxs)($,{variant:re?`secondary`:`ghost`,size:`icon`,className:Y(`h-7 w-7 relative`,re&&`bg-violet-500/10 text-violet-600 dark:text-violet-400`),onClick:()=>ie(e=>!e),title:`Session checkpoints — rewind`,children:[(0,X.jsx)(Pt,{className:`h-4 w-4`}),re&&(0,X.jsx)(`span`,{className:`absolute -bottom-0.5 left-1/2 -translate-x-1/2 w-1 h-1 rounded-full bg-violet-500`})]})]})]}),we&&(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-3 py-1 border-t bg-muted/20 text-[11px] text-muted-foreground`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1 tabular-nums`,children:[s>0&&(0,X.jsx)(Bi,{pct:se,tokens:s,maxTokens:l>0?l:void 0,onClick:()=>oe(!0)}),a.input>0&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,X.jsx)(`span`,{className:`font-medium text-foreground`,children:Q(a.input)}),(0,X.jsx)(`span`,{children:`in`})]}),(0,X.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,X.jsx)(`span`,{className:`font-medium text-foreground`,children:Q(a.output)}),(0,X.jsx)(`span`,{children:`out`})]}),a.cacheRead&&a.cacheRead>0&&(()=>{let e=(a.cacheRead??0)+a.input,t=e>0?Math.round((a.cacheRead??0)/e*100):0;return(0,X.jsxs)(`span`,{className:`flex items-center gap-1`,title:`Cache hit ratio: ${t}%`,children:[(0,X.jsx)(`span`,{className:`font-medium text-foreground`,children:Q(a.cacheRead)}),(0,X.jsxs)(`span`,{children:[`cache (`,t,`%)`]})]})})(),(0,X.jsx)(Ua,{})]})]}),o&&(0,X.jsx)(`span`,{className:`text-muted-foreground/70 tabular-nums shrink-0`,children:Se(o)})]})]}),(0,X.jsxs)(`div`,{className:`flex-1 relative overflow-hidden`,children:[(0,X.jsx)(Do,{}),!ce&&(0,X.jsxs)(`button`,{type:`button`,onClick:me,className:Y(`absolute bottom-4 left-1/2 -translate-x-1/2 z-10 jump-bottom`,`flex items-center gap-2 px-4 py-2 rounded-full shadow-lg`,`bg-primary text-primary-foreground text-xs font-medium`,`hover:bg-primary/90 transition-colors animate-message`),children:[(0,X.jsx)(Ft,{className:`h-3.5 w-3.5`}),ue>0?`${ue} new message${ue===1?``:`s`}`:`Jump to latest`]}),de&&(0,X.jsxs)(`button`,{type:`button`,onClick:he,title:`Scroll to top (oldest)`,className:Y(`absolute top-3 right-3 z-10`,`flex items-center gap-1 px-2.5 py-1 rounded-full shadow-md border`,`bg-background/90 backdrop-blur-sm text-[11px] text-muted-foreground`,`hover:text-foreground hover:bg-background transition-colors animate-message`),children:[(0,X.jsx)(qt,{className:`h-3 w-3`}),(0,X.jsx)(`span`,{children:`Top`})]}),k.length===0&&!t?(0,X.jsx)(`div`,{className:`mx-auto max-w-5xl w-full px-4 pt-4`,children:(0,X.jsx)(No,{})}):(0,X.jsxs)(S,{ref:O,className:`h-full`,onScroll:pe,children:[k.map((e,n)=>(0,X.jsx)(Fo,{row:e,isLoading:t,compactMode:i,isFirstRow:n===0},e.key)),(0,X.jsxs)(`div`,{id:`chat-activity`,className:Y(`mx-auto max-w-5xl w-full px-4`,i?`pb-3`:`pb-8`),children:[(0,X.jsx)(Po,{}),t&&(()=>{let t=e[e.length-1],n=e.filter(e=>e.role===`tool`&&e.toolResult===void 0),r=`Thinking…`;if(n.length>0){let e=Array.from(new Set(n.map(e=>e.toolName).filter(Boolean))),t=e.slice(0,2).join(`, `),i=e.length>2?` +${e.length-2}`:``;r=n.length===1?`Running ${t||`tool`}…`:`Running ${n.length} tools (${t}${i})…`}else t?.role===`assistant`&&t.content?r=`Writing reply…`:t?.role===`tool`&&t.toolResult!==void 0&&(r=`Thinking about the next step…`);let i=ge?Math.max(0,Math.floor((ve-ge)/1e3)):0,a=i<60?`${i}s`:`${Math.floor(i/60)}m ${i%60}s`,o=``,s=t?.role===`assistant`&&t.streaming&&t.content?t:null;if(s){let e=be.current;if(!e||e.id!==s.id)be.current={id:s.id,at:Date.now(),len:s.content.length};else{let t=Math.max(1,ve-e.at),n=Math.max(0,s.content.length-e.len);if(t>500&&n>0){let e=n*1e3/t;o=e>=1e3?`${(e/1e3).toFixed(1)}k ch/s`:`${Math.round(e)} ch/s`}}}else be.current&&=null;return(0,X.jsxs)(`div`,{className:`flex gap-3 animate-message`,children:[(0,X.jsx)(`div`,{className:`flex-shrink-0 w-8 h-8 rounded-full flex items-center justify-center bg-accent text-accent-foreground ring-2 ring-offset-2 ring-offset-background ring-accent/20`,children:(0,X.jsx)(R,{className:`h-4 w-4`})}),(0,X.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:(0,X.jsx)(`div`,{className:`rounded-2xl px-4 py-3 bg-card border text-foreground`,children:(0,X.jsxs)(`div`,{className:`flex items-center gap-3 text-sm`,children:[(0,X.jsxs)(`span`,{className:`flex gap-1`,children:[(0,X.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-primary/70 animate-bounce [animation-delay:-0.3s]`}),(0,X.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-primary/70 animate-bounce [animation-delay:-0.15s]`}),(0,X.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-primary/70 animate-bounce`})]}),(0,X.jsx)(`span`,{className:`text-foreground/90`,children:r}),(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums`,children:a}),u&&(0,X.jsxs)(`span`,{className:`text-xs text-muted-foreground tabular-nums`,children:[`· iter `,u.index,u.max>0?`/${u.max}`:``]}),o&&(0,X.jsxs)(`span`,{className:`text-xs text-muted-foreground/80 tabular-nums`,children:[`· `,o]})]})})})]})})()]},`__live`)]})]}),(0,X.jsxs)(`div`,{className:`border-t bg-card/50 backdrop-blur supports-[backdrop-filter]:bg-card/50 shrink-0`,children:[(0,X.jsxs)(`div`,{className:`max-w-5xl mx-auto px-4 pt-1.5 flex items-center gap-3 text-[10px] text-muted-foreground/50 select-none overflow-x-auto`,children:[(0,X.jsxs)(`span`,{title:`Enter`,className:`inline-flex items-center gap-1`,children:[(0,X.jsx)(`kbd`,{children:`Enter`}),` send`]}),(0,X.jsx)(`span`,{className:`opacity-50`,children:`·`}),(0,X.jsxs)(`span`,{title:`Shift+Enter`,className:`inline-flex items-center gap-1`,children:[(0,X.jsx)(`kbd`,{children:`Shift`}),`+`,(0,X.jsx)(`kbd`,{children:`↵`}),` newline`]}),(0,X.jsx)(`span`,{className:`opacity-50`,children:`·`}),(0,X.jsxs)(`span`,{title:`Ctrl+\\\\`,className:`inline-flex items-center gap-1`,children:[(0,X.jsx)(`kbd`,{children:`Ctrl+\\`}),` sidebar`]}),(0,X.jsx)(`span`,{className:`opacity-50`,children:`·`}),(0,X.jsxs)(`span`,{title:`Ctrl+F`,className:`inline-flex items-center gap-1`,children:[(0,X.jsx)(`kbd`,{children:`Ctrl+F`}),` search`]}),(0,X.jsx)(`span`,{className:`opacity-50`,children:`·`}),(0,X.jsxs)(`span`,{title:`Ctrl+K`,className:`inline-flex items-center gap-1`,children:[(0,X.jsx)(`kbd`,{children:`Ctrl+K`}),` palette`]}),(0,X.jsx)(`span`,{className:`opacity-50`,children:`·`}),(0,X.jsxs)(`span`,{title:`Ctrl+L / Ctrl+N`,className:`inline-flex items-center gap-1`,children:[(0,X.jsx)(`kbd`,{children:`Ctrl+L`}),` clear`]}),(0,X.jsx)(`span`,{className:`opacity-50`,children:`·`}),(0,X.jsxs)(`span`,{title:`j/k to navigate`,className:`inline-flex items-center gap-1`,children:[(0,X.jsx)(`kbd`,{children:`j`}),(0,X.jsx)(`kbd`,{children:`k`}),` navigate`]}),(0,X.jsx)(`span`,{className:`opacity-50`,children:`·`}),(0,X.jsxs)(`span`,{title:`Ctrl+M`,className:`inline-flex items-center gap-1`,children:[(0,X.jsx)(`kbd`,{children:`Ctrl+M`}),` model`]}),(0,X.jsx)(`span`,{className:`opacity-50`,children:`·`}),(0,X.jsxs)(`span`,{title:`Ctrl+Shift+D`,className:`inline-flex items-center gap-1`,children:[(0,X.jsx)(`kbd`,{children:`Ctrl+⇧D`}),` density`]})]}),(0,X.jsx)(`div`,{className:`p-4`,children:(0,X.jsx)(`div`,{className:`max-w-5xl mx-auto`,children:(0,X.jsx)(za,{onOpenBreakdown:()=>oe(!0)})})})]}),(0,X.jsx)(To,{open:N,onClose:()=>ne(!1)}),(0,X.jsx)(Ba,{open:re,onClose:()=>ie(!1)}),(0,X.jsx)(Vi,{open:ae,onClose:()=>oe(!1)})]})}jn.defineTheme(`wrongstack-dark`,{base:`vs-dark`,inherit:!0,rules:[{token:`comment`,foreground:`6e717a`,fontStyle:`italic`},{token:`comment.line`,foreground:`6e717a`,fontStyle:`italic`},{token:`comment.block`,foreground:`6e717a`,fontStyle:`italic`},{token:`comment.documentation`,foreground:`6e717a`,fontStyle:`italic`},{token:`string`,foreground:`64d488`},{token:`string.escape`,foreground:`49d3c5`},{token:`string.template`,foreground:`64d488`},{token:`number`,foreground:`f2a23a`},{token:`number.hex`,foreground:`f2a23a`},{token:`number.float`,foreground:`f2a23a`},{token:`keyword`,foreground:`f28dbc`},{token:`keyword.control`,foreground:`f28dbc`},{token:`keyword.operator`,foreground:`9ea0a8`},{token:`type`,foreground:`6cb6ff`},{token:`type.identifier`,foreground:`6cb6ff`},{token:`type.parameter`,foreground:`eeede7`},{token:`function`,foreground:`6cb6ff`},{token:`predefined`,foreground:`6cb6ff`},{token:`variable`,foreground:`eeede7`},{token:`variable.parameter`,foreground:`f2a23a`},{token:`variable.readonly`,foreground:`f2a23a`},{token:`variable.language`,foreground:`f28dbc`},{token:`tag`,foreground:`f47a95`},{token:`metatag`,foreground:`f47a95`},{token:`tag.html`,foreground:`f47a95`},{token:`tag.jsx`,foreground:`f47a95`},{token:`tag.tsx`,foreground:`f47a95`},{token:`attribute.name`,foreground:`ffb055`},{token:`attribute.value`,foreground:`64d488`},{token:`attribute.name.html`,foreground:`ffb055`},{token:`attribute.name.jsx`,foreground:`ffb055`},{token:`regexp`,foreground:`49d3c5`},{token:`delimiter`,foreground:`9ea0a8`},{token:`delimiter.bracket`,foreground:`9ea0a8`},{token:`delimiter.parenthesis`,foreground:`9ea0a8`},{token:`delimiter.curly`,foreground:`9ea0a8`},{token:`delimiter.square`,foreground:`9ea0a8`},{token:`delimiter.array`,foreground:`9ea0a8`},{token:`operator`,foreground:`9ea0a8`},{token:`constant`,foreground:`f2a23a`},{token:`constant.language`,foreground:`f28dbc`},{token:`support`,foreground:`6cb6ff`},{token:`support.function`,foreground:`6cb6ff`},{token:`support.type`,foreground:`6cb6ff`},{token:`support.constant`,foreground:`f2a23a`},{token:`support.variable`,foreground:`eeede7`},{token:`storage`,foreground:`f28dbc`},{token:`storage.modifier`,foreground:`f28dbc`},{token:`storage.type`,foreground:`6cb6ff`},{token:`entity.name.type`,foreground:`6cb6ff`},{token:`entity.name.function`,foreground:`6cb6ff`},{token:`entity.other.inherited-class`,foreground:`6cb6ff`},{token:`entity.name.tag`,foreground:`f47a95`},{token:`entity.other.attribute-name`,foreground:`ffb055`},{token:`invalid`,foreground:`d63c3c`},{token:`invalid.deprecated`,foreground:`d63c3c`},{token:`emphasis`,fontStyle:`italic`},{token:`strong`,fontStyle:`bold`},{token:`header`,foreground:`6cb6ff`,fontStyle:`bold`},{token:`link`,foreground:`49d3c5`,fontStyle:`underline`},{token:`class`,foreground:`6cb6ff`},{token:`interface`,foreground:`49d3c5`},{token:`enum`,foreground:`f2a23a`},{token:`enumMember`,foreground:`f2a23a`},{token:`typeParameter`,foreground:`f2a23a`},{token:`namespace`,foreground:`6cb6ff`},{token:`method`,foreground:`6cb6ff`},{token:`property`,foreground:`eeede7`},{token:`property.readonly`,foreground:`f2a23a`},{token:`property.static`,foreground:`eeede7`},{token:`parameter`,foreground:`f2a23a`},{token:`variable.defaultLibrary`,foreground:`6cb6ff`},{token:`function.defaultLibrary`,foreground:`6cb6ff`},{token:`macro`,foreground:`c4a0ff`},{token:`decorator`,foreground:`c4a0ff`},{token:`label`,foreground:`f2a23a`},{token:`comment.deprecated`,foreground:`6e717a`,fontStyle:`italic strikethrough`},{token:`variable.deprecated`,foreground:`6e717a`,fontStyle:`strikethrough`}],colors:{"editor.background":`#121318`,"editor.foreground":`#eeede7`,"editorCursor.foreground":`#f2a23a`,"editor.selectionBackground":`#f2a23a25`,"editor.selectionHighlightBackground":`#f2a23a15`,"editor.inactiveSelectionBackground":`#f2a23a10`,"editor.lineHighlightBackground":`#1a1c23`,"editorLineNumber.foreground":`#4a4d55`,"editorLineNumber.activeForeground":`#9ea0a8`,"editorRuler.foreground":`#1e2028`,"editorBracketMatch.background":`#f2a23a15`,"editorBracketMatch.border":`#f2a23a30`,"editor.findMatchBackground":`#f2a23a30`,"editor.findMatchHighlightBackground":`#f2a23a15`,"editorWidget.background":`#1a1c23`,"editorWidget.border":`#262830`,"editorSuggestWidget.background":`#1a1c23`,"editorSuggestWidget.border":`#262830`,"editorSuggestWidget.selectedBackground":`#262830`,"editorHoverWidget.background":`#1a1c23`,"editorHoverWidget.border":`#262830`,"scrollbar.shadow":`#00000000`,"scrollbarSlider.background":`#4a4d5530`,"scrollbarSlider.hoverBackground":`#f2a23a50`,"scrollbarSlider.activeBackground":`#f2a23a70`,"minimap.background":`#121318`,"diffEditor.insertedTextBackground":`#64d48815`,"diffEditor.removedTextBackground":`#d63c3c15`,"sideBar.background":`#121318`,"sideBar.border":`#1e2028`,"input.background":`#1a1c23`,"input.border":`#262830`,"input.foreground":`#eeede7`,"input.placeholderForeground":`#6e717a`,focusBorder:`#f2a23a40`,"list.activeSelectionBackground":`#262830`,"list.hoverBackground":`#1e2028`,"dropdown.background":`#1a1c23`,"dropdown.border":`#262830`,"badge.background":`#f2a23a`,"badge.foreground":`#1a1208`,"editorBracketHighlighting.foreground1":`#f2a23a`,"editorBracketHighlighting.foreground2":`#6cb6ff`,"editorBracketHighlighting.foreground3":`#f28dbc`,"editorBracketHighlighting.foreground4":`#64d488`,"editorBracketHighlighting.foreground5":`#49d3c5`,"editorBracketHighlighting.foreground6":`#c4a0ff`,"editorBracketPairGuide.background1":`#f2a23a18`,"editorBracketPairGuide.background2":`#6cb6ff18`,"editorBracketPairGuide.background3":`#f28dbc18`,"editorBracketPairGuide.background4":`#64d48818`,"editorBracketPairGuide.background5":`#49d3c518`,"editorBracketPairGuide.background6":`#c4a0ff18`,"editorBracketPairGuide.activeBackground1":`#f2a23a30`,"editorBracketPairGuide.activeBackground2":`#6cb6ff30`,"editorBracketPairGuide.activeBackground3":`#f28dbc30`,"editorBracketPairGuide.activeBackground4":`#64d48830`,"editorBracketPairGuide.activeBackground5":`#49d3c530`,"editorBracketPairGuide.activeBackground6":`#c4a0ff30`}}),jn.defineTheme(`wrongstack-light`,{base:`vs`,inherit:!0,rules:[{token:`comment`,foreground:`9a9d99`,fontStyle:`italic`},{token:`comment.line`,foreground:`9a9d99`,fontStyle:`italic`},{token:`comment.block`,foreground:`9a9d99`,fontStyle:`italic`},{token:`comment.documentation`,foreground:`9a9d99`,fontStyle:`italic`},{token:`string`,foreground:`3b8c5a`},{token:`string.escape`,foreground:`17998e`},{token:`string.template`,foreground:`3b8c5a`},{token:`number`,foreground:`d97a12`},{token:`number.hex`,foreground:`d97a12`},{token:`number.float`,foreground:`d97a12`},{token:`keyword`,foreground:`d65a9a`},{token:`keyword.control`,foreground:`d65a9a`},{token:`keyword.operator`,foreground:`6b6d72`},{token:`type`,foreground:`3178c6`},{token:`type.identifier`,foreground:`3178c6`},{token:`type.parameter`,foreground:`1a1c23`},{token:`function`,foreground:`3178c6`},{token:`predefined`,foreground:`3178c6`},{token:`variable`,foreground:`1a1c23`},{token:`variable.parameter`,foreground:`d97a12`},{token:`variable.readonly`,foreground:`d97a12`},{token:`variable.language`,foreground:`d65a9a`},{token:`tag`,foreground:`c93a5e`},{token:`metatag`,foreground:`c93a5e`},{token:`tag.html`,foreground:`c93a5e`},{token:`tag.jsx`,foreground:`c93a5e`},{token:`tag.tsx`,foreground:`c93a5e`},{token:`attribute.name`,foreground:`d4893a`},{token:`attribute.value`,foreground:`3b8c5a`},{token:`attribute.name.html`,foreground:`d4893a`},{token:`attribute.name.jsx`,foreground:`d4893a`},{token:`regexp`,foreground:`17998e`},{token:`delimiter`,foreground:`6b6d72`},{token:`delimiter.bracket`,foreground:`6b6d72`},{token:`delimiter.parenthesis`,foreground:`6b6d72`},{token:`delimiter.curly`,foreground:`6b6d72`},{token:`delimiter.square`,foreground:`6b6d72`},{token:`delimiter.array`,foreground:`6b6d72`},{token:`operator`,foreground:`6b6d72`},{token:`constant`,foreground:`d97a12`},{token:`constant.language`,foreground:`d65a9a`},{token:`support`,foreground:`3178c6`},{token:`support.function`,foreground:`3178c6`},{token:`support.type`,foreground:`3178c6`},{token:`support.constant`,foreground:`d97a12`},{token:`support.variable`,foreground:`1a1c23`},{token:`storage`,foreground:`d65a9a`},{token:`storage.modifier`,foreground:`d65a9a`},{token:`storage.type`,foreground:`3178c6`},{token:`entity.name.type`,foreground:`3178c6`},{token:`entity.name.function`,foreground:`3178c6`},{token:`entity.other.inherited-class`,foreground:`3178c6`},{token:`entity.name.tag`,foreground:`c93a5e`},{token:`entity.other.attribute-name`,foreground:`d4893a`},{token:`invalid`,foreground:`d63c3c`},{token:`invalid.deprecated`,foreground:`d63c3c`},{token:`emphasis`,fontStyle:`italic`},{token:`strong`,fontStyle:`bold`},{token:`header`,foreground:`3178c6`,fontStyle:`bold`},{token:`link`,foreground:`17998e`,fontStyle:`underline`},{token:`class`,foreground:`3178c6`},{token:`interface`,foreground:`17998e`},{token:`enum`,foreground:`d97a12`},{token:`enumMember`,foreground:`d97a12`},{token:`typeParameter`,foreground:`d97a12`},{token:`namespace`,foreground:`3178c6`},{token:`method`,foreground:`3178c6`},{token:`property`,foreground:`1a1c23`},{token:`property.readonly`,foreground:`d97a12`},{token:`property.static`,foreground:`1a1c23`},{token:`parameter`,foreground:`d97a12`},{token:`variable.defaultLibrary`,foreground:`3178c6`},{token:`function.defaultLibrary`,foreground:`3178c6`},{token:`macro`,foreground:`8b5cf6`},{token:`decorator`,foreground:`8b5cf6`},{token:`label`,foreground:`d97a12`},{token:`comment.deprecated`,foreground:`9a9d99`,fontStyle:`italic strikethrough`},{token:`variable.deprecated`,foreground:`9a9d99`,fontStyle:`strikethrough`}],colors:{"editor.background":`#f7f7f5`,"editor.foreground":`#1a1c23`,"editorCursor.foreground":`#e07b0e`,"editor.selectionBackground":`#e07b0e18`,"editor.selectionHighlightBackground":`#e07b0e10`,"editor.inactiveSelectionBackground":`#e07b0e08`,"editor.lineHighlightBackground":`#f0efe9`,"editorLineNumber.foreground":`#bab8b0`,"editorLineNumber.activeForeground":`#6b6d72`,"editorRuler.foreground":`#e8e6de`,"editorBracketMatch.background":`#e07b0e12`,"editorBracketMatch.border":`#e07b0e25`,"editor.findMatchBackground":`#e07b0e25`,"editor.findMatchHighlightBackground":`#e07b0e12`,"editorWidget.background":`#f7f7f5`,"editorWidget.border":`#ddd9d0`,"editorSuggestWidget.background":`#f7f7f5`,"editorSuggestWidget.border":`#ddd9d0`,"editorSuggestWidget.selectedBackground":`#eeece2`,"editorHoverWidget.background":`#f7f7f5`,"editorHoverWidget.border":`#ddd9d0`,"scrollbar.shadow":`#00000000`,"scrollbarSlider.background":`#bab8b040`,"scrollbarSlider.hoverBackground":`#e07b0e50`,"scrollbarSlider.activeBackground":`#e07b0e70`,"minimap.background":`#f7f7f5`,"diffEditor.insertedTextBackground":`#3b8c5a12`,"diffEditor.removedTextBackground":`#d63c3c12`,"sideBar.background":`#f7f7f5`,"sideBar.border":`#e8e6de`,"input.background":`#ffffff`,"input.border":`#ddd9d0`,"input.foreground":`#1a1c23`,"input.placeholderForeground":`#9a9d99`,focusBorder:`#e07b0e35`,"list.activeSelectionBackground":`#eeece2`,"list.hoverBackground":`#f0efe9`,"dropdown.background":`#ffffff`,"dropdown.border":`#ddd9d0`,"badge.background":`#e07b0e`,"badge.foreground":`#ffffff`,"editorBracketHighlighting.foreground1":`#d97a12`,"editorBracketHighlighting.foreground2":`#3178c6`,"editorBracketHighlighting.foreground3":`#d65a9a`,"editorBracketHighlighting.foreground4":`#3b8c5a`,"editorBracketHighlighting.foreground5":`#17998e`,"editorBracketHighlighting.foreground6":`#8b5cf6`,"editorBracketPairGuide.background1":`#d97a1215`,"editorBracketPairGuide.background2":`#3178c615`,"editorBracketPairGuide.background3":`#d65a9a15`,"editorBracketPairGuide.background4":`#3b8c5a15`,"editorBracketPairGuide.background5":`#17998e15`,"editorBracketPairGuide.background6":`#8b5cf615`,"editorBracketPairGuide.activeBackground1":`#d97a1228`,"editorBracketPairGuide.activeBackground2":`#3178c628`,"editorBracketPairGuide.activeBackground3":`#d65a9a28`,"editorBracketPairGuide.activeBackground4":`#3b8c5a28`,"editorBracketPairGuide.activeBackground5":`#17998e28`,"editorBracketPairGuide.activeBackground6":`#8b5cf628`}});function Lo(){return typeof document>`u`||document.documentElement.classList.contains(`dark`)?`wrongstack-dark`:`wrongstack-light`}Ae.config({monaco:ye});var Ro={ts:`typescript`,tsx:`typescript`,js:`javascript`,jsx:`javascript`,json:`json`,css:`css`,html:`html`,svg:`xml`,md:`markdown`,yml:`yaml`,yaml:`yaml`,toml:`toml`,sh:`shell`,bash:`shell`,ps1:`powershell`,py:`python`,rs:`rust`,go:`go`,rb:`ruby`,java:`java`,c:`c`,cpp:`cpp`,h:`c`,hpp:`cpp`,sql:`sql`,xml:`xml`};function zo(e){return Ro[e.split(`.`).pop()?.toLowerCase()??``]??`plaintext`}function Bo(){let e=q(e=>e.openFiles),t=q(e=>e.activeFilePath),n=q(e=>e.setActiveFile),r=q(e=>e.closeFile);return e.length===0?null:(0,X.jsx)(`div`,{className:`flex items-center border-b bg-muted/40 overflow-x-auto shrink-0`,children:e.map(e=>{let i=e.path===t,a=e.path.split(`/`).pop()??e.path;return(0,X.jsxs)(`button`,{type:`button`,onClick:()=>n(e.path),onMouseDown:t=>{t.button===1&&(t.preventDefault(),r(e.path))},className:Y(`group flex items-center gap-1.5 px-3 py-1.5 text-[11px] border-r whitespace-nowrap min-w-0 max-w-[180px] transition-colors`,i?`bg-background border-t-2 border-t-primary text-foreground -mb-px`:`text-muted-foreground hover:bg-muted/60 hover:text-foreground`),title:e.path,children:[e.dirty&&(0,X.jsx)(C,{className:`h-2 w-2 fill-current text-primary shrink-0`}),(0,X.jsx)(`span`,{className:`truncate`,children:a}),(0,X.jsx)(Ie,{className:Y(`h-3 w-3 shrink-0 rounded-sm hover:bg-muted-foreground/20 opacity-0 group-hover:opacity-100 transition-opacity`,i&&`opacity-100`),onClick:t=>{t.stopPropagation(),r(e.path)}})]},e.path)})})}function Vo(){let e=q(e=>e.openFiles),t=q(e=>e.activeFilePath),n=q(e=>e.updateContent),{theme:r}=Ti(),i=(0,B.useRef)(null),a=(0,B.useMemo)(()=>e.find(e=>e.path===t)??null,[e,t]),o=t?zo(t):`plaintext`,c=Lo();(0,B.useEffect)(()=>{let e=Lo();jn.setTheme(e)},[r]);let l=(0,B.useCallback)(e=>{i.current=e,jn.setTheme(Lo())},[]),u=(0,B.useCallback)(e=>{t&&e!==void 0&&n(t,e)},[t,n]);return(0,B.useEffect)(()=>{let e=e=>{let n=e.ctrlKey||e.metaKey,r=e.target?.tagName?.toLowerCase()===`textarea`||e.target?.closest(`.monaco-editor`)!==null;!n||!r||(e.key.toLowerCase()===`s`&&(e.preventDefault(),window.dispatchEvent(new CustomEvent(`wrongstack:save-file`,{detail:{filePath:t}}))),e.key.toLowerCase()===`w`&&(e.preventDefault(),t&&q.getState().closeFile(t)))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]),e.length===0?(0,X.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,X.jsxs)(`div`,{className:`text-center space-y-2`,children:[(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No files open`}),(0,X.jsx)(`p`,{className:`text-[11px] text-muted-foreground/60`,children:`Select a file from the explorer to start editing`})]})}):(0,X.jsxs)(`div`,{className:`flex-1 flex flex-col overflow-hidden`,children:[(0,X.jsx)(Bo,{}),(0,X.jsx)(`div`,{className:`flex-1 relative`,children:a?(0,X.jsx)(s,{language:o,value:a.content,onChange:u,theme:c,onMount:l,loading:(0,X.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,X.jsx)(`span`,{className:`text-[11px] text-muted-foreground animate-pulse`,children:`Loading editor…`})}),options:{minimap:{enabled:!1},fontSize:13,fontFamily:`'IBM Plex Mono', 'Cascadia Code', 'Fira Code', 'JetBrains Mono', monospace`,lineNumbers:`on`,renderWhitespace:`selection`,scrollBeyondLastLine:!1,wordWrap:`off`,tabSize:2,smoothScrolling:!0,cursorBlinking:`smooth`,cursorSmoothCaretAnimation:`on`,bracketPairColorization:{enabled:!0},"semanticHighlighting.enabled":!0,automaticLayout:!0,padding:{top:8}}},a.path):(0,X.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,X.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`Select a tab to view its content`})})})]})}var Ho=y,Uo=re,Wo=pe,Go=B.forwardRef(({className:e,...t},n)=>(0,X.jsx)(le,{ref:n,className:Y(`fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0`,e),...t}));Go.displayName=le.displayName;var Ko=B.forwardRef(({className:e,children:t,...n},r)=>(0,X.jsxs)(Wo,{children:[(0,X.jsx)(Go,{}),(0,X.jsxs)(Dt,{ref:r,className:Y(`fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg`,e),...n,children:[t,(0,X.jsxs)(i,{className:`absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground`,children:[(0,X.jsx)(Ie,{className:`h-4 w-4`}),(0,X.jsx)(`span`,{className:`sr-only`,children:`Close`})]})]})]}));Ko.displayName=Dt.displayName;var qo=({className:e,...t})=>(0,X.jsx)(`div`,{className:Y(`flex flex-col space-y-1.5 text-center sm:text-left`,e),...t});qo.displayName=`DialogHeader`;var Jo=({className:e,...t})=>(0,X.jsx)(`div`,{className:Y(`flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2`,e),...t});Jo.displayName=`DialogFooter`;var Yo=B.forwardRef(({className:e,...t},n)=>(0,X.jsx)(O,{ref:n,className:Y(`text-lg font-semibold leading-none tracking-tight`,e),...t}));Yo.displayName=O.displayName;var Xo=B.forwardRef(({className:e,...t},n)=>(0,X.jsx)(oe,{ref:n,className:Y(`text-sm text-muted-foreground`,e),...t}));Xo.displayName=oe.displayName;function Zo(e){return/edit|write|create|patch/i.test(e)?Cn:/bash|shell|exec|run|command/i.test(e)?vn:/fetch|http|web|curl|request/i.test(e)?st:He}function Qo({toolName:e,input:t}){let n=Qa(e,t);if(n)return(0,X.jsx)(`div`,{className:`rounded-lg overflow-hidden border`,children:(0,X.jsx)(Ya,{oldText:n.oldText,newText:n.newText,caption:n.caption})});if(typeof t==`object`&&t){let e=t,n=e.command??e.cmd??e.script;if(typeof n==`string`&&n.trim().length>0)return(0,X.jsxs)(`div`,{className:`rounded-lg border bg-background/40 overflow-hidden`,children:[(0,X.jsxs)(`div`,{className:`px-3 py-1.5 text-[10px] uppercase tracking-wider text-muted-foreground border-b bg-muted/40 flex items-center gap-1.5`,children:[(0,X.jsx)(vn,{className:`h-3 w-3`}),(0,X.jsx)(`span`,{children:`Command`})]}),(0,X.jsxs)(`pre`,{className:`px-3 py-2 text-xs font-mono whitespace-pre-wrap break-all max-h-40 overflow-auto`,children:[`$`,n]})]});let r=e.url;if(typeof r==`string`)return(0,X.jsxs)(`div`,{className:`rounded-lg border bg-background/40 px-3 py-2 text-xs font-mono`,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:(e.method??`GET`).toUpperCase()}),` `,(0,X.jsx)(`span`,{className:`break-all`,children:r})]})}return(0,X.jsxs)(`div`,{className:`p-3 rounded-lg bg-muted/50 border text-xs font-mono`,children:[(0,X.jsx)(`div`,{className:`text-muted-foreground mb-2`,children:`Input:`}),(0,X.jsx)(`pre`,{className:`whitespace-pre-wrap break-all max-h-60 overflow-auto`,children:JSON.stringify(t,null,2)})]})}function $o(){let{showConfirmDialog:e,confirmInfo:t,hideConfirm:n}=G(),{sendConfirm:r}=Z(),i=(0,B.useRef)(null),a=e=>{t&&r(t.id,e),n()};if((0,B.useEffect)(()=>{if(!e)return;let t=e=>{let t=e.target?.tagName?.toLowerCase();t===`input`||t===`textarea`||(e.key===`y`||e.key===`Y`?(e.preventDefault(),a(`yes`)):e.key===`n`||e.key===`N`||e.key===`Escape`?(e.preventDefault(),a(`no`)):e.key===`a`||e.key===`A`?(e.preventDefault(),a(`always`)):(e.key===`d`||e.key===`D`)&&(e.preventDefault(),a(`deny`)))};return window.addEventListener(`keydown`,t),i.current?.focus(),()=>window.removeEventListener(`keydown`,t)},[e,t?.id]),!t)return(0,X.jsx)(Ho,{open:e,onOpenChange:()=>n(),children:(0,X.jsx)(Ko,{})});let o=Zo(t.toolName),s=/edit|write/i.test(t.toolName);return(0,X.jsx)(Ho,{open:e,onOpenChange:()=>n(),children:(0,X.jsxs)(Ko,{className:`sm:max-w-2xl border-yellow-500/50`,ref:i,tabIndex:-1,children:[(0,X.jsxs)(qo,{children:[(0,X.jsxs)(Yo,{className:`flex items-center gap-2`,children:[(0,X.jsx)(Dn,{className:`h-5 w-5 text-yellow-500 animate-pulse`}),`Approval required: `,t.toolName]}),(0,X.jsxs)(Xo,{children:[`The agent wants to `,s?`modify a file`:`run this tool`,`. Review the request below and decide whether to proceed.`]})]}),(0,X.jsxs)(`div`,{className:`py-2 space-y-3`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-3 p-3 rounded-lg bg-muted`,children:[(0,X.jsx)(o,{className:`h-5 w-5 text-muted-foreground`}),(0,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsx)(`div`,{className:`font-medium font-mono truncate`,children:t.toolName}),(0,X.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[s?`File modification`:`Tool execution`,` — preview below`]})]})]}),t.input!==void 0&&(0,X.jsx)(Qo,{toolName:t.toolName,input:t.input}),t.suggestedPattern&&(0,X.jsxs)(`div`,{className:`flex items-start gap-2 p-3 rounded-lg bg-yellow-500/10 border border-yellow-500/20`,children:[(0,X.jsx)(Qe,{className:`h-4 w-4 text-yellow-600 mt-0.5 shrink-0`}),(0,X.jsxs)(`div`,{className:`text-sm min-w-0`,children:[(0,X.jsx)(`div`,{className:`font-medium text-yellow-800 dark:text-yellow-200`,children:`Trust pattern suggestion`}),(0,X.jsx)(`div`,{className:`font-mono text-xs mt-1 break-all`,children:t.suggestedPattern}),(0,X.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-1`,children:[`Picking `,(0,X.jsx)(`span`,{className:`font-medium`,children:`Always`}),` will whitelist matching calls for this project.`]})]})]})]}),(0,X.jsxs)(Jo,{className:`gap-2 sm:gap-2 flex-wrap`,children:[(0,X.jsxs)($,{variant:`outline`,size:`sm`,onClick:()=>a(`deny`),title:`Reject this and all future calls matching the pattern (d)`,children:[`Deny always `,(0,X.jsx)(`kbd`,{className:`ml-1 text-[10px] border rounded px-1 bg-background`,children:`d`})]}),(0,X.jsxs)($,{variant:`outline`,size:`sm`,onClick:()=>a(`no`),title:`Reject this single call (Esc / n)`,children:[`No `,(0,X.jsx)(`kbd`,{className:`ml-1 text-[10px] border rounded px-1 bg-background`,children:`n`})]}),(0,X.jsxs)($,{variant:`outline`,size:`sm`,onClick:()=>a(`always`),title:`Approve and remember the pattern for the project (a)`,children:[`Always `,(0,X.jsx)(`kbd`,{className:`ml-1 text-[10px] border rounded px-1 bg-background`,children:`a`})]}),(0,X.jsxs)($,{size:`sm`,onClick:()=>a(`yes`),title:`Approve this single call (y)`,children:[`Yes `,(0,X.jsx)(`kbd`,{className:`ml-1 text-[10px] border rounded px-1 bg-background/80`,children:`y`})]})]})]})})}var es=St()((e,t)=>({request:null,open:n=>{t().request?.resolve(!1),e({request:n})},settle:n=>{t().request?.resolve(n),e({request:null})}}));function ts(e){return new Promise(t=>{es.getState().open({...e,resolve:t})})}function ns(){let e=es(e=>e.request),t=es(e=>e.settle);return(0,B.useEffect)(()=>{if(!e)return;let t=e=>{e.key===`Enter`&&(e.preventDefault(),es.getState().settle(!0))};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e]),(0,X.jsx)(Ho,{open:e!==null,onOpenChange:e=>{e||t(!1)},children:(0,X.jsxs)(Ko,{className:`max-w-md`,children:[(0,X.jsxs)(qo,{children:[(0,X.jsx)(Yo,{children:e?.title}),e?.message&&(0,X.jsx)(Xo,{children:e.message})]}),(0,X.jsxs)(Jo,{className:`gap-2`,children:[(0,X.jsx)($,{variant:`outline`,size:`sm`,onClick:()=>t(!1),children:e?.cancelLabel??`Cancel`}),(0,X.jsx)($,{variant:e?.danger?`destructive`:`default`,size:`sm`,autoFocus:!0,onClick:()=>t(!0),children:e?.confirmLabel??`Confirm`})]})]})})}function rs(){let e=U(e=>e.wsStatus),n=U(e=>e.wsUrl),[r,i]=(0,B.useState)(!1),[a,o]=(0,B.useState)(Date.now());if((0,B.useEffect)(()=>{if(e.state!==`reconnecting`)return;let t=setInterval(()=>o(Date.now()),500);return()=>clearInterval(t)},[e.state]),(0,B.useEffect)(()=>{e.state===`open`&&i(!1)},[e.state]),e.state===`open`||e.state===`connecting`||r)return null;let s=()=>V(n).retryNow(),c=e.state===`reconnecting`,l=e.state===`closed`?e.error:e.state===`reconnecting`?e.lastError:void 0,u=c?Math.max(0,Math.ceil((e.nextRetryAt-a)/1e3)):0;return(0,X.jsxs)(`div`,{className:Y(`flex items-center gap-3 px-4 py-2 border-b text-sm`,c?`bg-orange-500/10 text-orange-700 dark:text-orange-300 border-orange-500/30`:`bg-red-500/10 text-red-700 dark:text-red-300 border-red-500/30`),children:[c?(0,X.jsx)(L,{className:`h-4 w-4 animate-spin shrink-0`}):(0,X.jsx)(t,{className:`h-4 w-4 shrink-0`}),(0,X.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,X.jsx)(`div`,{className:`font-medium`,children:c?`Reconnecting to backend (attempt ${e.attempt}) — retrying in ${u}s`:`Disconnected from backend`}),l&&(0,X.jsx)(`div`,{className:`text-xs opacity-80 truncate`,children:l})]}),(0,X.jsxs)(`button`,{type:`button`,onClick:s,className:Y(`inline-flex items-center gap-1 px-2.5 py-1 rounded-md border text-xs font-medium`,`hover:bg-background/30 transition-colors shrink-0`,c?`border-orange-500/40`:`border-red-500/40`),title:`Retry connection now`,children:[(0,X.jsx)(v,{className:`h-3 w-3`}),`Retry now`]}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>i(!0),className:`text-current/60 hover:text-current shrink-0`,title:`Dismiss (chip in topbar still shows status)`,children:(0,X.jsx)(Ie,{className:`h-4 w-4`})})]})}var is=class extends B.Component{state={error:null};static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e,t){console.error(`[ErrorBoundary]`,e,t.componentStack),this.props.onError?.(e,t)}handleReset=()=>{this.setState({error:null})};render(){return this.state.error?(0,X.jsx)(`div`,{className:`flex items-center justify-center h-screen bg-background`,children:(0,X.jsxs)(`div`,{className:`flex flex-col items-center gap-4 p-8 max-w-md text-center`,children:[(0,X.jsx)(Qe,{className:`h-12 w-12 text-destructive`}),(0,X.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Something went wrong`}),(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`A rendering error occurred. Your session is still active on the server — reloading will pick up where you left off.`}),(0,X.jsx)(`pre`,{className:`text-xs font-mono text-muted-foreground bg-muted/50 rounded p-3 max-h-32 overflow-auto w-full text-left`,children:this.state.error.message}),(0,X.jsxs)(`div`,{className:`flex gap-2`,children:[(0,X.jsxs)($,{size:`sm`,variant:`outline`,onClick:()=>window.location.reload(),children:[(0,X.jsx)(Mt,{className:`h-4 w-4 mr-1`}),`Reload page`]}),(0,X.jsx)($,{size:`sm`,onClick:this.handleReset,children:`Try again`})]})]})}):this.props.children}};function as(e,t,n,r,i){let a=[];for(let n of e){let e=t[n.id]??[];for(let t of e)a.push({provider:n.id,model:t.id,modelName:t.name||t.id,contextWindow:t.contextWindow,isCurrent:n.id===r&&t.id===i})}let o=n.toLowerCase().trim();return(o?a.filter(e=>e.provider.toLowerCase().includes(o)||e.model.toLowerCase().includes(o)||e.modelName.toLowerCase().includes(o)):a).sort((e,t)=>e.isCurrent===t.isCurrent?e.provider.localeCompare(t.provider)||e.model.localeCompare(t.model):e.isCurrent?-1:1)}function os(){let e=G(e=>e.modelSwitcherOpen),t=G(e=>e.setModelSwitcherOpen),[n,r]=(0,B.useState)(``),[i,a]=(0,B.useState)(0),[o,s]=(0,B.useState)([]),[l,u]=(0,B.useState)({}),d=(0,B.useRef)(null),f=U(e=>e.wsUrl),p=U(e=>e.provider),m=U(e=>e.model),h=G(e=>e.paletteOpen),{listSavedProviders:g,listProviderModels:_,switchModel:v}=Z();(0,B.useEffect)(()=>{let n=n=>{if((n.ctrlKey||n.metaKey)&&n.key.toLowerCase()===`m`&&!n.shiftKey&&!n.altKey){if(h)return;n.preventDefault(),t(!e);return}n.key===`Escape`&&e&&(n.preventDefault(),t(!1))};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,h]),(0,B.useEffect)(()=>{let e=V(f),t=e.on(`providers.saved`,e=>{let t=e.payload;s(t.providers??[])}),n=e.on(`provider.models`,e=>{let t=e.payload;u(e=>({...e,[t.provider]:t.models}))});return()=>{t(),n()}},[f]),(0,B.useEffect)(()=>{e&&(r(``),a(0),g(),requestAnimationFrame(()=>d.current?.focus()))},[e,g]),(0,B.useEffect)(()=>{if(e)for(let e of o)l[e.id]||_(e.id)},[e,o,l,_]);let y=(0,B.useMemo)(()=>as(o,l,n,p,m),[o,l,n,p,m]);(0,B.useEffect)(()=>{i>=y.length&&a(0)},[y.length,i]);let b=e=>{let n=y[e];n&&(v(n.provider,n.model),t(!1))};return e?(0,X.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-start justify-center bg-background/60 backdrop-blur-sm pt-[15vh]`,onClick:e=>{e.target===e.currentTarget&&t(!1)},onKeyDown:e=>{e.key===`Escape`&&t(!1)},children:(0,X.jsxs)(`div`,{className:`w-full max-w-xl rounded-xl border bg-popover shadow-2xl overflow-hidden`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 border-b px-3 py-2`,children:[(0,X.jsx)(wn,{className:`h-4 w-4 text-muted-foreground`}),(0,X.jsx)(`input`,{ref:d,value:n,onChange:e=>{r(e.target.value),a(0)},onKeyDown:e=>{e.key===`ArrowDown`?(e.preventDefault(),a(e=>Math.min(y.length-1,e+1))):e.key===`ArrowUp`?(e.preventDefault(),a(e=>Math.max(0,e-1))):e.key===`Enter`?(e.preventDefault(),b(i)):e.key===`Escape`&&(e.preventDefault(),t(!1))},placeholder:`Filter providers and models…`,className:`flex-1 bg-transparent outline-none text-sm placeholder:text-muted-foreground`}),(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground font-mono`,children:`↑↓ · Enter · Esc`})]}),(0,X.jsx)(`div`,{className:`max-h-[50vh] overflow-y-auto py-1`,children:y.length===0?(0,X.jsx)(`div`,{className:`px-4 py-8 text-center text-sm text-muted-foreground`,children:o.length===0?`No saved providers — register a key in Settings first.`:`Loading models…`}):y.map((e,t)=>(0,X.jsxs)(`button`,{type:`button`,onClick:()=>b(t),onMouseEnter:()=>a(t),className:Y(`w-full flex items-center gap-3 px-3 py-2 text-left text-sm transition-colors`,t===i?`bg-accent text-accent-foreground`:`hover:bg-accent/40`,e.isCurrent&&`font-medium`),children:[(0,X.jsx)(c,{className:Y(`h-4 w-4 shrink-0`,e.isCurrent?`text-primary`:`text-muted-foreground`)}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`truncate`,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:e.provider}),(0,X.jsx)(`span`,{className:`mx-1 text-muted-foreground/40`,children:`·`}),(0,X.jsx)(`span`,{children:e.modelName})]}),e.contextWindow&&(0,X.jsxs)(`div`,{className:`text-[10px] text-muted-foreground font-mono`,children:[e.model,` · ctx `,e.contextWindow.toLocaleString()]})]}),e.isCurrent?(0,X.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-primary font-semibold`,children:`active`}):(0,X.jsx)(ln,{className:`h-3.5 w-3.5 text-muted-foreground opacity-0 group-hover:opacity-100`})]},`${e.provider}:${e.model}`))})]})}):null}var ss=B.forwardRef(({className:e,type:t,...n},r)=>(0,X.jsx)(`input`,{type:t,className:Y(`flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,e),ref:r,...n}));ss.displayName=`Input`;var cs=B.forwardRef(({className:e,children:t,...n},r)=>(0,X.jsxs)(g,{ref:r,className:Y(`relative overflow-hidden`,e),...n,children:[(0,X.jsx)(At,{className:`h-full w-full rounded-[inherit]`,children:t}),(0,X.jsx)(ls,{}),(0,X.jsx)(we,{})]}));cs.displayName=g.displayName;var ls=B.forwardRef(({className:e,orientation:t=`vertical`,...n},r)=>(0,X.jsx)(p,{ref:r,orientation:t,className:Y(`flex touch-none select-none transition-colors`,t===`vertical`&&`h-full w-2.5 border-l border-l-transparent p-[1px]`,t===`horizontal`&&`h-2.5 flex-col border-t border-t-transparent p-[1px]`,e),...n,children:(0,X.jsx)(de,{className:`relative flex-1 rounded-full bg-border`})}));ls.displayName=p.displayName;var us=u,ds=B.forwardRef(({className:e,...t},n)=>(0,X.jsx)(Se,{ref:n,className:Y(`inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground`,e),...t}));ds.displayName=Se.displayName;var fs=B.forwardRef(({className:e,...t},n)=>(0,X.jsx)(Sn,{ref:n,className:Y(`inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow-sm`,e),...t}));fs.displayName=Sn.displayName;var ps=B.forwardRef(({className:e,...t},n)=>(0,X.jsx)(Tn,{ref:n,className:Y(`mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2`,e),...t}));ps.displayName=Tn.displayName;function ms({label:e,hint:t,selector:n,onChange:r,configKey:i,value:a}){let o=typeof a==`boolean`,s=G(e=>n?n(e):!1),c=U(e=>i?e[i]:!1),l=o?a:n?s:c;return(0,X.jsxs)(`div`,{className:`flex items-start justify-between gap-3 py-2`,children:[(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`div`,{className:`text-sm font-medium`,children:e}),t&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:t})]}),(0,X.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":l,onClick:()=>{if(o)r?.();else if(n)r?.();else if(i===`soundOnComplete`){let e=!U.getState().soundOnComplete;U.getState().setSoundOnComplete(e),e&&kr()}},className:Y(`shrink-0 relative inline-flex h-5 w-9 rounded-full border transition-colors`,l?`bg-primary border-primary`:`bg-muted border-input hover:bg-muted/80`),children:(0,X.jsx)(`span`,{className:Y(`absolute top-0.5 left-0.5 h-3.5 w-3.5 rounded-full bg-background shadow transition-transform`,l&&`translate-x-4`)})})]})}function hs({label:e,hint:t,value:n,min:r,max:i,step:a=1,onChange:o,unit:s}){return(0,X.jsxs)(`div`,{className:`flex items-start justify-between gap-3 py-2`,children:[(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`div`,{className:`text-sm font-medium`,children:e}),t&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:t})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,X.jsx)(`input`,{type:`range`,min:r,max:i,step:a,value:n,onChange:e=>o(Number(e.target.value)),className:`w-24 h-1.5 accent-primary`}),(0,X.jsxs)(`span`,{className:`text-xs tabular-nums w-10 text-right text-muted-foreground`,children:[n,s??``]})]})]})}function gs({label:e,hint:t,value:n,options:r,onChange:i}){return(0,X.jsxs)(`div`,{className:`flex items-start justify-between gap-3 py-2`,children:[(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`div`,{className:`text-sm font-medium`,children:e}),t&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:t})]}),(0,X.jsx)(`select`,{value:n,onChange:e=>i(e.target.value),className:`shrink-0 h-8 rounded-md border bg-background px-2 text-xs`,children:r.map(e=>(0,X.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})}var _s=[`anthropic`,`openai`,`google`,`openai-compatible`];function vs({activeProvider:e,catalogProviders:t,isLoadingCatalog:n,savedProviders:r,isLoadingSaved:i,providerTab:a,setProviderTab:o,onSelectProvider:s,onAddKey:c,onDeleteKey:l,onSetActiveKey:u,onAddProvider:d,onRemoveProvider:f,catalogQuery:p,setCatalogQuery:m}){let[h,g]=(0,B.useState)(null),[_,v]=(0,B.useState)(``),[y,b]=(0,B.useState)(``),[x,S]=(0,B.useState)(!1),[C,w]=(0,B.useState)(!1),[T,E]=(0,B.useState)(``),[D,O]=(0,B.useState)(`openai-compatible`),[k,A]=(0,B.useState)(``),[j,ee]=(0,B.useState)(``),M=(0,B.useCallback)(e=>{!_.trim()||!y.trim()||(c(e,_.trim(),y.trim()),v(``),b(``),g(null))},[c,_,y]),te=(0,B.useCallback)(()=>{T.trim()&&(d(T.trim(),D,k||void 0,j||void 0),E(``),O(`openai-compatible`),A(``),ee(``),w(!1))},[d,T,D,k,j]),N=p.trim()?t.filter(e=>{let t=p.trim().toLowerCase();return e.id.toLowerCase().includes(t)||e.name.toLowerCase().includes(t)||e.family.toLowerCase().includes(t)}):t,ne=N.reduce((e,t)=>(e[t.family]||(e[t.family]=[]),e[t.family]?.push(t),e),{});return(0,X.jsxs)(`div`,{className:`space-y-4`,children:[(0,X.jsxs)(`div`,{className:`flex gap-2 mb-4`,children:[(0,X.jsxs)($,{variant:a===`catalog`?`default`:`outline`,size:`sm`,onClick:()=>o(`catalog`),children:[(0,X.jsx)(st,{className:`h-4 w-4 mr-1`}),`Catalog`]}),(0,X.jsxs)($,{variant:a===`saved`?`default`:`outline`,size:`sm`,onClick:()=>o(`saved`),children:[(0,X.jsx)(Kt,{className:`h-4 w-4 mr-1`}),`Saved (`,r.length,`)`]})]}),a===`catalog`&&(0,X.jsxs)(`div`,{className:`space-y-4`,children:[(0,X.jsx)(ss,{placeholder:`Search ${t.length} providers (name / id / family)…`,value:p,onChange:e=>m(e.target.value),className:`text-sm`}),n&&t.length===0?(0,X.jsxs)(`div`,{className:`flex items-center justify-center py-8`,children:[(0,X.jsx)(L,{className:`h-6 w-6 animate-spin text-muted-foreground`}),(0,X.jsx)(`span`,{className:`ml-2 text-muted-foreground`,children:`Loading catalog...`})]}):N.length===0&&p?(0,X.jsxs)(`div`,{className:`text-center py-8 text-muted-foreground text-sm`,children:[`No providers match "`,(0,X.jsx)(`span`,{className:`font-mono`,children:p}),`".`]}):(0,X.jsx)(X.Fragment,{children:_s.map(t=>{let n=ne[t];return n?.length?(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(`h3`,{className:`text-sm font-semibold text-muted-foreground uppercase tracking-wider`,children:t}),(0,X.jsx)(`div`,{className:`grid grid-cols-1 gap-2`,children:n.map(t=>(0,X.jsxs)(`button`,{type:`button`,onClick:()=>s(t.id),className:Y(`flex flex-col items-start p-3 rounded-lg border text-left transition-all`,e===t.id?`border-primary bg-primary/5 ring-2 ring-primary/20`:`border-border hover:bg-muted`),children:[(0,X.jsxs)(`div`,{className:`flex w-full justify-between items-start`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`span`,{className:`font-medium`,children:t.name}),(0,X.jsxs)(`span`,{className:`ml-2 text-xs text-muted-foreground`,children:[`(`,t.id,`)`]})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[t.hasApiKey&&(0,X.jsxs)(`span`,{className:`text-xs bg-green-500/10 text-green-600 px-2 py-0.5 rounded`,children:[(0,X.jsx)(Kt,{className:`h-3 w-3 inline mr-1`}),`Configured`]}),t.envVars[0]&&(0,X.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`ENV: `,t.envVars[0]]}),e===t.id&&(0,X.jsx)(Be,{className:`h-4 w-4 text-primary`})]})]}),(0,X.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-1`,children:[t.modelCount,` models`,t.apiBase&&` · ${t.apiBase}`]})]},t.id))})]},t):null})})]}),a===`saved`&&(0,X.jsxs)(`div`,{className:`space-y-4`,children:[(0,X.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Manage your API keys and provider configurations`}),(0,X.jsxs)($,{size:`sm`,variant:`outline`,onClick:()=>w(!C),children:[(0,X.jsx)(kt,{className:`h-4 w-4 mr-1`}),`Add Provider`]})]}),C&&(0,X.jsxs)(`div`,{className:`p-4 border rounded-lg space-y-3 bg-muted/50`,children:[(0,X.jsx)(`h4`,{className:`font-medium`,children:`Add Custom Provider`}),(0,X.jsx)(ss,{placeholder:`Provider ID (e.g. my-llm-server)`,value:T,onChange:e=>E(e.target.value)}),(0,X.jsxs)(`select`,{className:`flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm`,value:D,onChange:e=>O(e.target.value),children:[(0,X.jsx)(`option`,{value:`anthropic`,children:`Anthropic`}),(0,X.jsx)(`option`,{value:`openai`,children:`OpenAI`}),(0,X.jsx)(`option`,{value:`openai-compatible`,children:`OpenAI Compatible`}),(0,X.jsx)(`option`,{value:`google`,children:`Google`})]}),(0,X.jsx)(ss,{placeholder:`Base URL (optional, e.g. http://localhost:11434/v1)`,value:k,onChange:e=>A(e.target.value)}),(0,X.jsx)(ss,{type:`password`,placeholder:`API Key (optional)`,value:j,onChange:e=>ee(e.target.value)}),(0,X.jsxs)(`div`,{className:`flex gap-2`,children:[(0,X.jsx)($,{size:`sm`,onClick:te,disabled:!T.trim(),children:`Add`}),(0,X.jsx)($,{size:`sm`,variant:`ghost`,onClick:()=>w(!1),children:`Cancel`})]})]}),i?(0,X.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,X.jsx)(L,{className:`h-6 w-6 animate-spin text-muted-foreground`})}):r.length===0?(0,X.jsxs)(`div`,{className:`text-center py-8 text-muted-foreground`,children:[(0,X.jsx)(Kt,{className:`h-8 w-8 mx-auto mb-2 opacity-50`}),(0,X.jsx)(`p`,{children:`No saved providers yet`}),(0,X.jsx)(`p`,{className:`text-sm`,children:`Add a provider to get started`})]}):r.map(e=>(0,X.jsxs)(`div`,{className:`border rounded-lg p-4 space-y-3`,children:[(0,X.jsxs)(`div`,{className:`flex justify-between items-start`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h4`,{className:`font-medium`,children:e.id}),e.family&&(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e.family})]}),(0,X.jsx)(`div`,{className:`flex gap-2`,children:(0,X.jsx)($,{size:`icon`,variant:`ghost`,onClick:()=>f(e.id),children:(0,X.jsx)(at,{className:`h-4 w-4 text-destructive`})})})]}),e.baseUrl&&(0,X.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[(0,X.jsx)(st,{className:`h-3 w-3 inline mr-1`}),e.baseUrl]}),(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,X.jsx)(`span`,{className:`text-sm font-medium`,children:`API Keys`}),(0,X.jsxs)($,{size:`sm`,variant:`ghost`,onClick:()=>g(h===e.id?null:e.id),children:[(0,X.jsx)(kt,{className:`h-3 w-3 mr-1`}),`Add Key`]})]}),e.apiKeys.length===0&&!h&&(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`No keys configured`}),e.apiKeys.map(t=>(0,X.jsxs)(`div`,{className:`flex items-center justify-between p-2 bg-muted/50 rounded`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`span`,{className:`text-sm font-medium`,children:t.label}),t.isActive&&(0,X.jsx)(`span`,{className:`ml-2 text-xs bg-green-500/10 text-green-600 px-1.5 py-0.5 rounded`,children:`Active`}),(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground font-mono`,children:t.maskedKey})]}),(0,X.jsxs)(`div`,{className:`flex gap-1`,children:[!t.isActive&&(0,X.jsx)($,{size:`sm`,variant:`ghost`,onClick:()=>u(e.id,t.label),children:`Set Active`}),(0,X.jsx)($,{size:`icon`,variant:`ghost`,onClick:()=>l(e.id,t.label),children:(0,X.jsx)(at,{className:`h-3 w-3 text-destructive`})})]})]},t.label)),h===e.id&&(0,X.jsxs)(`div`,{className:`p-3 border rounded space-y-2 bg-background`,children:[(0,X.jsx)(ss,{placeholder:`Key label (e.g. default, production)`,value:_,onChange:e=>v(e.target.value)}),(0,X.jsxs)(`div`,{className:`flex gap-2`,children:[(0,X.jsx)(ss,{type:x?`text`:`password`,placeholder:`API key`,value:y,onChange:e=>b(e.target.value)}),(0,X.jsx)($,{size:`icon`,variant:`ghost`,onClick:()=>S(!x),children:x?(0,X.jsx)(se,{className:`h-4 w-4`}):(0,X.jsx)(Ot,{className:`h-4 w-4`})})]}),(0,X.jsxs)(`div`,{className:`flex gap-2`,children:[(0,X.jsx)($,{size:`sm`,onClick:()=>M(e.id),disabled:!_.trim()||!y.trim(),children:`Save Key`}),(0,X.jsx)($,{size:`sm`,variant:`ghost`,onClick:()=>{g(null),v(``),b(``)},children:`Cancel`})]})]})]})]},e.id))]})]})}function ys({provider:e,catalogModels:t,currentCatalogProvider:n,isLoadingModels:r,setIsLoadingModels:i,onModelSelect:a,refreshModels:o}){let s=U(e=>e.model);return(0,X.jsx)(`div`,{className:`space-y-4`,children:e?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`p`,{className:`text-sm font-medium`,children:n?.name||e}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e})]}),(0,X.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>{i(!0),o(e)},children:(0,X.jsx)(Mt,{className:Y(`h-4 w-4`,r&&`animate-spin`)})})]}),r&&!t[e]?(0,X.jsxs)(`div`,{className:`flex items-center justify-center py-8`,children:[(0,X.jsx)(L,{className:`h-6 w-6 animate-spin text-muted-foreground`}),(0,X.jsx)(`span`,{className:`ml-2 text-muted-foreground`,children:`Loading models...`})]}):(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(t[e]||[]).map(e=>(0,X.jsxs)(`button`,{type:`button`,onClick:()=>a(e.id),className:Y(`w-full flex items-center justify-between p-3 rounded-lg border text-left transition-all`,s===e.id?`border-primary bg-primary/5 ring-2 ring-primary/20`:`border-border hover:bg-muted`),children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`span`,{className:`font-medium`,children:e.name||e.id}),(0,X.jsx)(`div`,{className:`flex gap-2 mt-1`,children:e.capabilities.map(e=>(0,X.jsx)(`span`,{className:`text-xs bg-muted px-1.5 py-0.5 rounded`,children:e},e))})]}),(0,X.jsxs)(`div`,{className:`text-right text-xs text-muted-foreground`,children:[e.contextWindow&&(0,X.jsxs)(`div`,{children:[e.contextWindow/1e3,`k context`]}),e.inputCost&&e.outputCost&&(0,X.jsxs)(`div`,{children:[`$`,e.inputCost,`/$`,e.outputCost]}),s===e.id&&(0,X.jsx)(Be,{className:`h-4 w-4 text-primary mt-1`})]})]},e.id)),t[e]?.length===0&&(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground text-center py-4`,children:`No models found for this provider. The catalog might be empty or still loading.`})]})]}):(0,X.jsxs)(`div`,{className:`text-center py-8 text-muted-foreground`,children:[(0,X.jsx)(c,{className:`h-8 w-8 mx-auto mb-2 opacity-50`}),(0,X.jsx)(`p`,{children:`Select a provider first`})]})})}function bs(){let{setCurrentView:e}=G(),{provider:t,model:n,setProvider:r,setModel:i,wsConnected:a}=U(),{theme:s,setTheme:u}=Ti(),d=Z(),f=d.client,{updatePrefs:p,switchAutonomy:m}=d,h=hr(),g=(0,B.useCallback)((e,t)=>{h.set({[e]:t}),p({[e]:t})},[h,p]),[_,v]=(0,B.useState)([]),[y,b]=(0,B.useState)({}),[x,S]=(0,B.useState)([]),[C,w]=(0,B.useState)(!1),[T,E]=(0,B.useState)(!1),[D,O]=(0,B.useState)(!1),[k,A]=(0,B.useState)(`catalog`),[j,ee]=(0,B.useState)(``),M=_.find(e=>e.id===t);(0,B.useEffect)(()=>{let e=e=>{if(e.type===`provider.catalog`){let t=e.payload;v(t.providers.sort((e,t)=>e.id.localeCompare(t.id))),w(!1)}},t=e=>{if(e.type===`provider.models`){let t=e.payload;b(e=>({...e,[t.provider]:t.models})),E(!1)}},n=e=>{if(e.type===`providers.saved`){let t=e.payload.providers.sort((e,t)=>e.id.localeCompare(t.id));S(t),O(!1),t.length>0&&A(`saved`)}};if(!a||!f)return;let r=f.on(`provider.catalog`,e),i=f.on(`provider.models`,t),o=f.on(`providers.saved`,n);return w(!0),O(!0),f.listProviders(),f.listSavedProviders(),()=>{r?.(),i?.(),o?.()}},[a,f]);let te=(0,B.useCallback)(e=>{r(e),y[e]||(E(!0),d.listProviderModels?.(e))},[y,r,d]),N=(0,B.useCallback)(e=>{i(e);let t=U.getState().provider;d.switchModel?.(t,e),Sr.success(`Switching to ${t} / ${e}…`)},[i,d]),ne=(0,B.useCallback)((e,t,n)=>{d.addKey?.(e,t,n)},[d]),re=(0,B.useCallback)((e,t)=>{d.deleteKey?.(e,t)},[d]),ie=(0,B.useCallback)((e,t)=>{d.setActiveKey?.(e,t)},[d]),ae=(0,B.useCallback)((e,t,n,r)=>{d.addProvider?.(e,t,n,r)},[d]),oe=(0,B.useCallback)(e=>{d.removeProvider?.(e)},[d]);return(0,X.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,X.jsxs)(`header`,{className:`flex items-center justify-between px-4 py-3 border-b bg-card shrink-0`,children:[(0,X.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Settings`}),(0,X.jsx)($,{variant:`ghost`,size:`icon`,onClick:()=>e(`chat`),children:(0,X.jsx)(Ie,{className:`h-4 w-4`})})]}),(0,X.jsx)(cs,{className:`flex-1`,children:(0,X.jsx)(`div`,{className:`p-6 max-w-2xl mx-auto`,children:(0,X.jsxs)(us,{defaultValue:`provider`,children:[(0,X.jsxs)(ds,{className:`w-full justify-start mb-6 grid grid-cols-5`,children:[(0,X.jsxs)(fs,{value:`provider`,className:`gap-1 text-xs`,children:[(0,X.jsx)(Me,{className:`h-3.5 w-3.5`}),`Provider`]}),(0,X.jsxs)(fs,{value:`connection`,className:`gap-1 text-xs`,children:[(0,X.jsx)(st,{className:`h-3.5 w-3.5`}),`Connect`]}),(0,X.jsxs)(fs,{value:`appearance`,className:`gap-1 text-xs`,children:[(0,X.jsx)(l,{className:`h-3.5 w-3.5`}),`Look`]}),(0,X.jsxs)(fs,{value:`agent`,className:`gap-1 text-xs`,children:[(0,X.jsx)(R,{className:`h-3.5 w-3.5`}),`Agent`]}),(0,X.jsxs)(fs,{value:`features`,className:`gap-1 text-xs`,children:[(0,X.jsx)(o,{className:`h-3.5 w-3.5`}),`Feat.`]})]}),(0,X.jsxs)(ps,{value:`provider`,className:`space-y-4`,children:[(0,X.jsx)(vs,{activeProvider:t,catalogProviders:_,isLoadingCatalog:C,savedProviders:x,isLoadingSaved:D,providerTab:k,setProviderTab:A,onSelectProvider:te,onAddKey:ne,onDeleteKey:re,onSetActiveKey:ie,onAddProvider:ae,onRemoveProvider:oe,catalogQuery:j,setCatalogQuery:ee}),(0,X.jsxs)(`div`,{className:`pt-4 border-t`,children:[(0,X.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 flex items-center gap-2`,children:[(0,X.jsx)(c,{className:`h-4 w-4 text-muted-foreground`}),`Model`]}),(0,X.jsx)(ys,{provider:t,catalogModels:y,currentCatalogProvider:M,isLoadingModels:T,setIsLoadingModels:E,onModelSelect:N,refreshModels:e=>d.listProviderModels?.(e)})]})]}),(0,X.jsxs)(ps,{value:`connection`,className:`space-y-4`,children:[(0,X.jsxs)(`div`,{className:`space-y-3`,children:[(0,X.jsxs)(`label`,{htmlFor:`websocket-url`,className:`text-sm font-medium flex items-center gap-2`,children:[(0,X.jsx)(st,{className:`h-4 w-4 text-muted-foreground`}),`WebSocket Server URL`]}),(0,X.jsx)(ss,{id:`websocket-url`,value:U.getState().wsUrl,onChange:e=>U.getState().setConfig({wsUrl:e.target.value}),placeholder:`ws://localhost:3457`,className:`font-mono text-sm`}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`URL of the agent WebSocket server. The server runs alongside the CLI.`})]}),(0,X.jsxs)(`div`,{className:`p-4 rounded-lg border bg-muted/50`,children:[(0,X.jsx)(`h4`,{className:`text-sm font-medium mb-2`,children:`Starting the WebSocket Server`}),(0,X.jsxs)(`p`,{className:`text-xs text-muted-foreground mb-3`,children:[`Standalone: run `,(0,X.jsx)(`code`,{className:`bg-muted px-1 py-0.5 rounded`,children:`./dev.ps1`}),` `,`from the repo root, or set WS_HOST/WS_PORT before launching`,` `,(0,X.jsx)(`code`,{className:`bg-muted px-1 py-0.5 rounded`,children:`node packages/webui/dist/server/entry.js`}),`. Or alongside the CLI:`,` `,(0,X.jsx)(`code`,{className:`bg-muted px-1 py-0.5 rounded`,children:`wstack --webui`}),`.`]})]})]}),(0,X.jsxs)(ps,{value:`appearance`,className:`space-y-4`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h3`,{className:`text-sm font-semibold mb-3`,children:`Theme`}),(0,X.jsxs)(`div`,{className:`grid grid-cols-3 gap-2 max-w-md`,children:[(0,X.jsxs)($,{variant:s===`light`?`default`:`outline`,size:`sm`,onClick:()=>u(`light`),children:[(0,X.jsx)(ht,{className:`h-4 w-4 mr-1`}),`Light`]}),(0,X.jsxs)($,{variant:s===`dark`?`default`:`outline`,size:`sm`,onClick:()=>u(`dark`),children:[(0,X.jsx)(ke,{className:`h-4 w-4 mr-1`}),`Dark`]}),(0,X.jsxs)($,{variant:s===`system`?`default`:`outline`,size:`sm`,onClick:()=>u(`system`),children:[(0,X.jsx)(Fe,{className:`h-4 w-4 mr-1`}),`System`]})]}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground mt-2`,children:`System follows your OS-level light/dark preference.`})]}),(0,X.jsxs)(`div`,{className:`pt-2 border-t`,children:[(0,X.jsx)(`h3`,{className:`text-sm font-semibold mb-3 mt-3`,children:`Preferences`}),(0,X.jsx)(ms,{label:`Compact density`,hint:`Tighter spacing throughout the chat.`,selector:e=>e.compactMode,onChange:()=>G.getState().toggleCompactMode()}),(0,X.jsx)(ms,{label:`Sound on completion`,hint:`Play a soft chime when a run finishes.`,selector:null,configKey:`soundOnComplete`})]})]}),(0,X.jsxs)(ps,{value:`agent`,className:`space-y-4`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 flex items-center gap-2`,children:[(0,X.jsx)(ct,{className:`h-4 w-4 text-muted-foreground`}),`Autonomy & Behavior`]}),(0,X.jsx)(gs,{label:`Autonomy mode`,hint:`How independently the agent proceeds between turns.`,value:h.autonomy,options:[{value:`off`,label:`Off — full manual control`},{value:`suggest`,label:`Suggest — suggests next steps`},{value:`auto`,label:`Auto — brief confirmation delay`},{value:`eternal`,label:`Eternal — autonomous until goal done`},{value:`eternal-parallel`,label:`Eternal Parallel — multi-agent fleet`}],onChange:e=>{h.set({autonomy:e}),m(e)}}),(0,X.jsx)(hs,{label:`Auto-proceed delay`,hint:`Milliseconds before the agent auto-proceeds in Auto mode. 0 = immediate.`,value:h.autonomyDelayMs,min:0,max:1e4,step:500,unit:`ms`,onChange:e=>g(`autonomyDelayMs`,e)}),(0,X.jsx)(ms,{label:`YOLO mode`,hint:`Bypass tool confirmation prompts — the agent runs without asking.`,value:h.yolo,onChange:()=>g(`yolo`,!h.yolo)})]}),(0,X.jsxs)(`div`,{className:`pt-2 border-t`,children:[(0,X.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 mt-3 flex items-center gap-2`,children:[(0,X.jsx)(ze,{className:`h-4 w-4 text-muted-foreground`}),`Prompt Refinement`]}),(0,X.jsx)(ms,{label:`Enable refine`,hint:`Rewrite prompts before sending — clearer instructions, better results.`,value:h.enhanceEnabled,onChange:()=>g(`enhanceEnabled`,!h.enhanceEnabled)}),(0,X.jsx)(hs,{label:`Refine delay`,hint:`Countdown before the refined prompt auto-sends.`,value:h.enhanceDelayMs,min:3e4,max:12e4,step:15e3,unit:`ms`,onChange:e=>g(`enhanceDelayMs`,e)}),(0,X.jsx)(gs,{label:`Refine language`,hint:`Keep your language or translate to English for the model.`,value:h.enhanceLanguage,options:[{value:`original`,label:`Original — keep your language`},{value:`english`,label:`English — translate to English`}],onChange:e=>g(`enhanceLanguage`,e)})]}),(0,X.jsxs)(`div`,{className:`pt-2 border-t`,children:[(0,X.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 mt-3 flex items-center gap-2`,children:[(0,X.jsx)(ze,{className:`h-4 w-4 text-muted-foreground`}),`Execution`]}),(0,X.jsx)(hs,{label:`Max iterations per run`,hint:`Hard cap on LLM turns per agent.run().`,value:h.maxIterations,min:10,max:2e3,step:10,onChange:e=>g(`maxIterations`,e)}),(0,X.jsx)(hs,{label:`Auto-proceed max iterations`,hint:`Stop auto-proceed after N iterations. 0 = unlimited.`,value:h.autoProceedMaxIterations,min:0,max:250,step:5,onChange:e=>g(`autoProceedMaxIterations`,e)}),(0,X.jsx)(ms,{label:`Confirm before exit`,hint:`First Ctrl+C aborts work, second confirms exit.`,value:h.confirmExit,onChange:()=>g(`confirmExit`,!h.confirmExit)}),(0,X.jsx)(ms,{label:`Chime on completion`,hint:`Terminal bell when an agent run finishes.`,value:h.chime,onChange:()=>g(`chime`,!h.chime)})]}),(0,X.jsxs)(`div`,{className:`pt-2 border-t`,children:[(0,X.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 mt-3 flex items-center gap-2`,children:[(0,X.jsx)(Tt,{className:`h-4 w-4 text-muted-foreground`}),`Fleet & Streaming`]}),(0,X.jsx)(ms,{label:`Stream fleet events`,hint:`Show live subagent activity in the fleet panel.`,value:h.streamFleet,onChange:()=>g(`streamFleet`,!h.streamFleet)}),(0,X.jsx)(ms,{label:`Next-step prediction`,hint:`After a turn completes, predict likely next steps.`,value:h.nextPrediction,onChange:()=>g(`nextPrediction`,!h.nextPrediction)})]})]}),(0,X.jsxs)(ps,{value:`features`,className:`space-y-4`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 flex items-center gap-2`,children:[(0,X.jsx)(o,{className:`h-4 w-4 text-muted-foreground`}),`Feature Flags`]}),(0,X.jsx)(ms,{label:`MCP servers`,hint:`Enable Model Context Protocol integrations.`,value:h.featureMcp,onChange:()=>g(`featureMcp`,!h.featureMcp)}),(0,X.jsx)(ms,{label:`Plugins`,hint:`Load and run user-installed plugins.`,value:h.featurePlugins,onChange:()=>g(`featurePlugins`,!h.featurePlugins)}),(0,X.jsx)(ms,{label:`Memory`,hint:`Persist and recall facts across sessions.`,value:h.featureMemory,onChange:()=>g(`featureMemory`,!h.featureMemory)}),(0,X.jsx)(ms,{label:`Skills`,hint:`Load domain-specific skill prompts.`,value:h.featureSkills,onChange:()=>g(`featureSkills`,!h.featureSkills)}),(0,X.jsx)(ms,{label:`Models registry`,hint:`Use the models.dev catalog for provider discovery.`,value:h.featureModelsRegistry,onChange:()=>g(`featureModelsRegistry`,!h.featureModelsRegistry)}),(0,X.jsx)(ms,{label:`Index on start`,hint:`Build the codebase symbol index at session start.`,value:h.indexOnStart,onChange:()=>g(`indexOnStart`,!h.indexOnStart)})]}),(0,X.jsxs)(`div`,{className:`pt-2 border-t`,children:[(0,X.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 mt-3 flex items-center gap-2`,children:[(0,X.jsx)(tt,{className:`h-4 w-4 text-muted-foreground`}),`Context & Debug`]}),(0,X.jsx)(ms,{label:`Auto-compact context`,hint:`Automatically trim the context window when near limits.`,value:h.contextAutoCompact,onChange:()=>g(`contextAutoCompact`,!h.contextAutoCompact)}),(0,X.jsx)(gs,{label:`Compactor strategy`,hint:`How the context is compacted when it grows too large.`,value:h.contextStrategy,options:[{value:`hybrid`,label:`Hybrid — fast rules (default)`},{value:`intelligent`,label:`Intelligent — LLM summarization`},{value:`selective`,label:`Selective — LLM-driven selection`}],onChange:e=>g(`contextStrategy`,e)}),(0,X.jsx)(gs,{label:`Log level`,hint:`Minimum severity for server-side logging.`,value:h.logLevel,options:[{value:`debug`,label:`Debug — everything`},{value:`info`,label:`Info — normal flow`},{value:`warn`,label:`Warn — problems only`},{value:`error`,label:`Error — failures only`}],onChange:e=>g(`logLevel`,e)}),(0,X.jsx)(gs,{label:`Audit level`,hint:`Detail level for session audit logs.`,value:h.auditLevel,options:[{value:`minimal`,label:`Minimal — errors only`},{value:`standard`,label:`Standard — tool calls + errors`},{value:`full`,label:`Full — every event (large logs)`}],onChange:e=>g(`auditLevel`,e)})]})]})]})})})]})}function xs({provider:e,isSelected:t,onSelect:n}){return(0,X.jsx)(`button`,{type:`button`,onClick:n,className:Y(`w-full text-left rounded-xl border p-4 transition-all`,`hover:border-primary/40 hover:bg-primary/5`,t?`border-primary bg-primary/10 ring-1 ring-primary/30`:`border-border bg-card`),children:(0,X.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,X.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`span`,{className:`font-semibold text-sm`,children:e.name}),e.hasApiKey&&(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded-full bg-emerald-500/10 text-emerald-600 dark:text-emerald-400 border border-emerald-500/20`,children:[(0,X.jsx)(pn,{className:`h-2.5 w-2.5`}),`Key set`]})]}),(0,X.jsxs)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:[e.family,` · `,e.modelCount,` models`]})]}),t&&(0,X.jsx)(`div`,{className:`w-5 h-5 rounded-full bg-primary flex items-center justify-center shrink-0`,children:(0,X.jsx)(pn,{className:`h-3 h-3 text-primary-foreground`})})]})})}function Ss({model:e,isSelected:t,onSelect:n}){let r=e.inputCost==null?null:`$${e.inputCost}/1M tok`,i=e.outputCost==null?null:`$${e.outputCost}/1M tok`,a=e.contextWindow?`${(e.contextWindow/1e6).toFixed(0)}M ctx`:null;return(0,X.jsx)(`button`,{type:`button`,onClick:n,className:Y(`w-full text-left rounded-xl border p-3 transition-all`,`hover:border-primary/40 hover:bg-primary/5`,t?`border-primary bg-primary/10 ring-1 ring-primary/30`:`border-border bg-card`),children:(0,X.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,X.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,X.jsx)(`span`,{className:`font-medium text-sm`,children:e.name}),(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 mt-1`,children:[a&&(0,X.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:a}),r&&i&&(0,X.jsxs)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:[r,` · `,i]}),e.capabilities.slice(0,3).map(e=>(0,X.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-primary/10 text-primary border border-primary/20`,children:e},e))]})]}),t&&(0,X.jsx)(`div`,{className:`w-5 h-5 rounded-full bg-primary flex items-center justify-center shrink-0`,children:(0,X.jsx)(pn,{className:`h-3 w-3 text-primary-foreground`})})]})})}function Cs({providerId:e,onSave:t}){let[n,r]=(0,B.useState)(``),[i,a]=(0,B.useState)(`default`),[o,s]=(0,B.useState)(!1);return(0,X.jsxs)(`div`,{className:`space-y-3 p-4 rounded-xl border border-amber-500/30 bg-amber-500/5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-amber-600 dark:text-amber-400`,children:[(0,X.jsx)(cn,{className:`h-4 w-4`}),(0,X.jsx)(`span`,{className:`text-sm font-medium`,children:`API Key required`})]}),(0,X.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Enter your API key for `,e,`. The key is stored locally and never sent to any server other than the provider's API endpoint.`]}),(0,X.jsxs)(`div`,{className:`flex gap-2`,children:[(0,X.jsx)(ss,{type:`password`,placeholder:`sk-...`,value:n,onChange:e=>r(e.target.value),className:`font-mono text-sm`}),(0,X.jsx)(ss,{placeholder:`Label (optional)`,value:i,onChange:e=>a(e.target.value),className:`w-28 text-sm`})]}),(0,X.jsx)($,{onClick:async()=>{if(n.trim()){s(!0);try{V(U.getState().wsUrl).addKey(e,i.trim()||`default`,n.trim()),t(n.trim()),r(``),Sr.success(`API key saved`)}catch{Sr.error(`Failed to save API key`)}finally{s(!1)}}},disabled:!n.trim()||o,size:`sm`,children:o?(0,X.jsx)(L,{className:`h-4 w-4 animate-spin`}):`Save Key`})]})}function ws(){let{setCurrentView:e}=G(),{provider:t,model:r,setProvider:i,setModel:a,wsConnected:o,wsUrl:s}=U();Z();let[l,u]=(0,B.useState)(`provider`),[d,f]=(0,B.useState)([]),[p,m]=(0,B.useState)({}),[h,g]=(0,B.useState)([]),[_,v]=(0,B.useState)(!1),[y,b]=(0,B.useState)(!1),[x,S]=(0,B.useState)(null),[C,w]=(0,B.useState)(null);(0,B.useEffect)(()=>{if(!o)return;let e=V(s),n=e.on(`provider.catalog`,e=>{if(e.type===`provider.catalog`){let n=e.payload.providers.sort((e,t)=>e.id.localeCompare(t.id));f(n),v(!1),t&&n.some(e=>e.id===t)?S(t):n.length===1&&S(n[0].id)}}),i=e.on(`provider.models`,e=>{if(e.type===`provider.models`){let t=e.payload;m(e=>({...e,[t.provider]:t.models})),b(!1),t.models.length===1?w(t.models[0].id):r&&t.models.some(e=>e.id===r)&&w(r)}}),a=e.on(`providers.saved`,e=>{if(e.type===`providers.saved`){let t=e.payload;g(t.providers.sort((e,t)=>e.id.localeCompare(t.id)))}});return v(!0),e.listProviders(),()=>{n?.(),i?.(),a?.()}},[o,s,t,r]),(0,B.useEffect)(()=>{if(!x||!o)return;let e=V(s);p[x]||(b(!0),e.listProviderModels(x))},[x,o,s,p]);let T=d.find(e=>e.id===x),E=h.find(e=>e.id===x)?.apiKeys.some(e=>e.isActive)||T?.hasApiKey,D=(0,B.useCallback)(e=>{S(e),w(null),u(`model`)},[]),O=(0,B.useCallback)(e=>{w(e),u(E?`done`:`apikey`)},[E]),k=(0,B.useCallback)(()=>{u(`done`)},[]),A=(0,B.useCallback)(()=>{if(!x||!C)return;i(x),a(C);let t=V(s);t.switchModel(x,C);let n=null,r=()=>{n&&clearTimeout(n)},o=t.on(`key.operation_result`,n=>{let i=n.payload;r(),o(),i.success?(t.newSession(),e(`chat`)):Sr.error(i.message)});n=setTimeout(()=>{r(),o(),Sr.error(`Model switch timed out. Please try again.`)},5e3)},[x,C,i,a,s,e]),j=x?p[x]??[]:[];return(0,X.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,X.jsx)(`header`,{className:`flex items-center justify-between px-6 py-4 border-b bg-card shrink-0`,children:(0,X.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,X.jsx)(`div`,{className:`w-10 h-10 rounded-xl bg-gradient-to-br from-primary via-primary to-primary/60 flex items-center justify-center`,children:(0,X.jsx)(ze,{className:`h-5 w-5 text-primary-foreground`})}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Welcome to WrongStack`}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Configure your AI provider to get started`})]})]})}),(0,X.jsx)(cs,{className:`flex-1`,children:(0,X.jsxs)(`div`,{className:`p-6 max-w-2xl mx-auto space-y-8`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,X.jsxs)(`div`,{className:Y(`flex items-center gap-1.5`,l===`provider`&&`text-primary font-medium`),children:[(0,X.jsx)(Me,{className:`h-4 w-4`}),(0,X.jsx)(`span`,{children:`Provider`})]}),(0,X.jsx)(n,{className:`h-4 w-4 text-muted-foreground`}),(0,X.jsxs)(`div`,{className:Y(`flex items-center gap-1.5`,l===`model`&&`text-primary font-medium`),children:[(0,X.jsx)(c,{className:`h-4 w-4`}),(0,X.jsx)(`span`,{children:`Model`})]}),(0,X.jsx)(n,{className:`h-4 w-4 text-muted-foreground`}),(0,X.jsxs)(`div`,{className:Y(`flex items-center gap-1.5`,(l===`apikey`||l===`done`)&&`text-primary font-medium`),children:[(0,X.jsx)(cn,{className:`h-4 w-4`}),(0,X.jsx)(`span`,{children:`API Key`})]})]}),l===`provider`&&(0,X.jsxs)(`div`,{className:`space-y-4`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`h2`,{className:`text-base font-semibold flex items-center gap-2`,children:[(0,X.jsx)(Me,{className:`h-4 w-4 text-primary`}),`Choose a Provider`]}),(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:`Select the AI provider you want to use. You can add API keys in the next step.`})]}),_?(0,X.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,X.jsx)(L,{className:`h-6 w-6 animate-spin text-muted-foreground`})}):(0,X.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:d.map(e=>(0,X.jsx)(xs,{provider:e,isSelected:x===e.id,onSelect:()=>D(e.id)},e.id))})]}),l===`model`&&(0,X.jsxs)(`div`,{className:`space-y-4`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`h2`,{className:`text-base font-semibold flex items-center gap-2`,children:[(0,X.jsx)(c,{className:`h-4 w-4 text-primary`}),`Choose a Model`]}),(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:T?`Models available for ${T.name}`:`Loading models...`})]}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>u(`provider`),className:`text-xs text-muted-foreground hover:text-foreground transition-colors`,children:`← Change provider`}),y?(0,X.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,X.jsx)(L,{className:`h-6 w-6 animate-spin text-muted-foreground`})}):j.length>0?(0,X.jsx)(`div`,{className:`grid grid-cols-1 gap-2`,children:j.map(e=>(0,X.jsx)(Ss,{model:e,isSelected:C===e.id,onSelect:()=>O(e.id)},e.id))}):(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground py-8 text-center`,children:`No models available. Please check your API key.`})]}),l===`apikey`&&(0,X.jsxs)(`div`,{className:`space-y-4`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`h2`,{className:`text-base font-semibold flex items-center gap-2`,children:[(0,X.jsx)(cn,{className:`h-4 w-4 text-primary`}),`Add Your API Key`]}),(0,X.jsxs)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:[T?`Enter your API key for ${T.name}. `:`Enter your API key. `,`The key is stored locally and encrypted.`]})]}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>u(`model`),className:`text-xs text-muted-foreground hover:text-foreground transition-colors`,children:`← Change model`}),x&&(0,X.jsx)(Cs,{providerId:x,onSave:k})]}),l===`done`&&(0,X.jsxs)(`div`,{className:`space-y-6`,children:[(0,X.jsxs)(`div`,{className:`flex flex-col items-center text-center py-8`,children:[(0,X.jsx)(`div`,{className:`w-16 h-16 rounded-2xl bg-gradient-to-br from-emerald-500/20 to-emerald-500/5 border border-emerald-500/30 flex items-center justify-center mb-4`,children:(0,X.jsx)(pn,{className:`h-8 w-8 text-emerald-500`})}),(0,X.jsx)(`h2`,{className:`text-xl font-semibold`,children:`You're all set!`}),(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground mt-2 max-w-sm`,children:`Configuration complete. Your agent is ready to start working.`})]}),(0,X.jsxs)(`div`,{className:`rounded-xl border bg-card p-4 space-y-3`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between text-sm`,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`Provider`}),(0,X.jsx)(`span`,{className:`font-medium`,children:x})]}),(0,X.jsxs)(`div`,{className:`flex items-center justify-between text-sm`,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`Model`}),(0,X.jsx)(`span`,{className:`font-medium`,children:C})]})]}),(0,X.jsxs)($,{onClick:A,className:`w-full`,size:`lg`,children:[(0,X.jsx)(R,{className:`h-4 w-4 mr-2`}),`Start Session`,(0,X.jsx)(ln,{className:`h-4 w-4 ml-2`})]})]})]})})]})}function Ts(e){switch(e){case`running`:return`▶`;case`streaming`:return`↻`;case`waiting_user`:return`⏳`;case`error`:return`✗`;case`idle`:return`■`;default:return`?`}}function Es(e){switch(e){case`running`:return`text-emerald-400`;case`streaming`:return`text-cyan-400`;case`waiting_user`:return`text-amber-400`;case`error`:return`text-red-400`;default:return`text-slate-500`}}function Ds(e){switch(e){case`active`:return`text-emerald-400`;case`idle`:return`text-cyan-400`;case`closing`:return`text-amber-400`;default:return`text-slate-500`}}function Os(e){let t=Date.now()-new Date(e).getTime(),n=Math.floor(t/6e4);if(n<1)return`<1m`;if(n<60)return`${n}m`;let r=Math.floor(n/60);return r<24?`${r}h ${n%60}m`:`${Math.floor(r/24)}d`}function ks(e){let t=Date.now()-new Date(e).getTime(),n=Math.floor(t/1e3);if(n<10)return`just now`;if(n<60)return`${n}s ago`;let r=Math.floor(n/60);return r<60?`${r}m ago`:`${Math.floor(r/60)}h ago`}function As(){let[e,n]=(0,B.useState)([]),[r,i]=(0,B.useState)(!0),[a,o]=(0,B.useState)(null),s=(0,B.useCallback)(async()=>{try{let e=await fetch(`/api/sessions`);if(!e.ok){if(e.status===404){o(null),n([]);return}throw Error(`HTTP ${e.status}`)}n(await e.json()),o(null)}catch(e){o(e instanceof Error?e.message:String(e))}finally{i(!1)}},[]);return(0,B.useEffect)(()=>{s();let e=setInterval(s,5e3);return()=>clearInterval(e)},[s]),r?(0,X.jsxs)(`div`,{className:`flex items-center gap-2 p-4 text-slate-400`,children:[(0,X.jsx)(L,{className:`h-4 w-4 animate-spin`}),`Loading sessions...`]}):a?(0,X.jsxs)(`div`,{className:`p-4 text-slate-500 text-sm`,children:[`Session API unavailable — run `,(0,X.jsx)(`code`,{className:`text-cyan-400`,children:`wstack --webui`}),` with session tracking enabled.`]}):e.length===0?(0,X.jsx)(`div`,{className:`p-4 text-slate-500 text-sm`,children:`No live sessions. Open another wstack instance to see it here.`}):(0,X.jsxs)(`div`,{className:`p-4 space-y-3`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 mb-4`,children:[(0,X.jsxs)(`h2`,{className:`text-sm font-semibold text-slate-200 uppercase tracking-wider`,children:[`Live Sessions (`,e.length,`)`]}),(0,X.jsx)(`span`,{className:`text-xs text-slate-500`,children:`auto-refresh every 5s`})]}),e.map(e=>(0,X.jsxs)(`div`,{className:`rounded-lg border border-slate-700 bg-slate-800/50 p-3 space-y-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,X.jsx)(`span`,{className:Ds(e.status),children:e.status===`active`?(0,X.jsx)(ge,{className:`h-3.5 w-3.5 inline`}):e.status===`idle`?(0,X.jsx)(t,{className:`h-3.5 w-3.5 inline`}):null}),(0,X.jsx)(`span`,{className:`font-medium text-slate-200 text-sm`,children:e.projectName}),(0,X.jsxs)(`span`,{className:`text-slate-500 text-xs`,children:[`[`,e.projectSlug,`]`]}),e.gitBranch?(0,X.jsxs)(`span`,{className:`text-purple-400 text-xs flex items-center gap-1`,children:[(0,X.jsx)(kn,{className:`h-3 w-3`}),e.gitBranch]}):null,(0,X.jsxs)(`span`,{className:`text-slate-500 text-xs ml-auto flex items-center gap-1`,children:[(0,X.jsx)(Pe,{className:`h-3 w-3`}),Os(e.startedAt)]}),(0,X.jsxs)(`span`,{className:`text-slate-600 text-xs`,children:[`PID `,e.pid]})]}),(0,X.jsxs)(`div`,{className:`text-slate-500 text-xs flex items-center gap-1`,children:[(0,X.jsx)(c,{className:`h-3 w-3`}),e.workingDir]}),(0,X.jsxs)(`div`,{className:`space-y-1 mt-2`,children:[e.agents.slice(0,5).map(e=>(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-xs pl-2 border-l-2 border-slate-700`,children:[(0,X.jsx)(`span`,{className:Es(e.status),children:Ts(e.status)}),(0,X.jsx)(`span`,{className:`text-slate-300 font-medium`,children:e.name}),e.currentTool?(0,X.jsxs)(`span`,{className:`text-slate-500`,children:[`[`,e.currentTool,`]`]}):null,(0,X.jsxs)(`span`,{className:`text-slate-600 ml-auto`,children:[e.iterations,` iter · `,e.toolCalls,` tools · `,ks(e.lastActivityAt)]})]},e.id)),e.agents.length>5?(0,X.jsxs)(`div`,{className:`text-slate-600 text-xs pl-4`,children:[`... and `,e.agents.length-5,` more`]}):null,e.agents.length===0?(0,X.jsx)(`div`,{className:`text-slate-600 text-xs pl-4`,children:`No agents`}):null]})]},e.sessionId))]})}var js=[{section:`Global`,items:[{keys:[`Ctrl`,`K`],description:`Open command palette`},{keys:[`?`],description:`Show this shortcuts overlay`},{keys:[`Ctrl`,`\\`],description:`Toggle sidebar`},{keys:[`Ctrl`,`1-6`],description:`Open side panel (Session, Agents, History, Files, Projects, Mailbox)`},{keys:[`Ctrl`,`/`],description:`Focus the message input`}]},{section:`Fleet & Agents`,items:[{keys:[`Ctrl`,`Shift`,`M`],description:`Open Fleet Monitor overlay`},{keys:[`Ctrl`,`Shift`,`A`],description:`Open Agents Monitor overlay`},{keys:[`↑`,`↓`],description:`Navigate agents in monitor`},{keys:[`Enter`],description:`Select focused agent`},{keys:[`Esc`],description:`Close active overlay`}]},{section:`Chat input`,items:[{keys:[`Enter`],description:`Send message`},{keys:[`Shift`,`Enter`],description:`Insert a newline`},{keys:[`↑`],description:`Recall previous prompt (in empty input)`},{keys:[`↓`],description:`Recall next prompt`},{keys:[`/`],description:`Open slash command popup`},{keys:[`Tab`],description:`Autocomplete highlighted command`},{keys:[`Esc`],description:`Dismiss popup / clear input`}]},{section:`Chat`,items:[{keys:[`Ctrl`,`F`],description:`Search within current chat`},{keys:[`Ctrl`,`L`],description:`Clear context (same as /clear)`},{keys:[`Ctrl`,`N`],description:`Start a new session (same as /new)`},{keys:[`Ctrl`,`E`],description:`Export chat as markdown`},{keys:[`Ctrl`,`M`],description:`Quick model switcher overlay`},{keys:[`Ctrl`,`Shift`,`D`],description:`Toggle compact UI density`},{keys:[`Esc`],description:`Abort the current run (when running)`}]},{section:`Chat navigation (when not typing)`,items:[{keys:[`j`],description:`Focus next message (alias: ↓)`},{keys:[`k`],description:`Focus previous message (alias: ↑)`},{keys:[`g`],description:`Jump to first message`},{keys:[`Shift`,`G`],description:`Jump to last message`},{keys:[`c`],description:`Copy focused message text`},{keys:[`Esc`],description:`Clear focused message`}]}];function Ms(){let e=G(e=>e.shortcutsOpen),t=G(e=>e.setShortcutsOpen);return(0,B.useEffect)(()=>{let e=e=>{let n=e.target,r=n?.tagName?.toLowerCase();if(!(r===`input`||r===`textarea`||n?.isContentEditable)&&e.key===`?`&&!e.ctrlKey&&!e.metaKey&&!e.altKey){e.preventDefault(),t(!G.getState().shortcutsOpen);return}e.key===`Escape`&&G.getState().shortcutsOpen&&(e.preventDefault(),t(!1))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]),e?(0,X.jsx)(`div`,{className:`fixed inset-0 z-50 bg-background/60 backdrop-blur-sm flex items-center justify-center px-4`,onClick:()=>t(!1),onKeyDown:e=>{e.key===`Escape`&&t(!1)},children:(0,X.jsxs)(`div`,{onClick:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation(),className:`w-full max-w-2xl rounded-xl border bg-popover shadow-2xl overflow-hidden flex flex-col max-h-[80vh]`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between px-5 py-4 border-b`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(Xe,{className:`h-4 w-4 text-muted-foreground`}),(0,X.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Keyboard shortcuts`})]}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>t(!1),className:`text-muted-foreground hover:text-foreground p-1 rounded hover:bg-muted`,children:(0,X.jsx)(Ie,{className:`h-4 w-4`})})]}),(0,X.jsx)(`div`,{className:`overflow-y-auto px-5 py-4 space-y-6`,children:js.map(e=>(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground mb-2`,children:e.section}),(0,X.jsx)(`div`,{className:`grid grid-cols-1 gap-1.5`,children:e.items.map(e=>(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-3 text-sm px-2 py-1.5 rounded hover:bg-muted/40`,children:[(0,X.jsx)(`span`,{className:`text-foreground/80`,children:e.description}),(0,X.jsx)(`span`,{className:`flex items-center gap-1 shrink-0`,children:e.keys.map((e,t)=>(0,X.jsxs)(`span`,{className:`flex items-center gap-1`,children:[t>0&&(0,X.jsx)(`span`,{className:`text-muted-foreground/40 text-xs`,children:`+`}),(0,X.jsx)(`kbd`,{className:`font-mono text-[10px] border rounded px-1.5 py-0.5 bg-background`,children:e})]},e))})]},e.description))})]},e.section))}),(0,X.jsxs)(`div`,{className:`border-t px-5 py-3 text-xs text-muted-foreground`,children:[`Press`,` `,(0,X.jsx)(`kbd`,{className:`font-mono text-[10px] border rounded px-1 py-0.5 bg-background`,children:`?`}),` `,`any time to reopen this list.`]})]})}):null}function Ns(){return(0,X.jsx)(`style`,{children:`
103
+ `).trim();return(0,X.jsxs)(`div`,{className:`flex gap-3 animate-message`,children:[(0,X.jsx)(`div`,{className:`flex-shrink-0 w-8 h-8 rounded-full flex items-center justify-center bg-violet-500/10 text-violet-600 dark:text-violet-400 ring-2 ring-offset-2 ring-offset-background ring-violet-500/20`,children:(0,X.jsx)(an,{className:`h-4 w-4 animate-pulse`})}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-1 max-w-[85%] min-w-0`,children:[(0,X.jsx)(`span`,{className:`text-xs font-medium text-violet-600 dark:text-violet-400 px-1`,children:`Thinking…`}),(0,X.jsx)(`div`,{className:`rounded-2xl rounded-bl-md px-3 py-2 bg-violet-500/[0.04] border border-violet-500/20 text-foreground/80`,children:(0,X.jsx)(`pre`,{className:`whitespace-pre-wrap break-words font-sans text-xs leading-relaxed italic max-h-32 overflow-hidden`,children:t||`…`})})]})]})}var Io=(0,B.memo)(function({row:e,isLoading:t,compactMode:n,isFirstRow:r}){let i=Y(`mx-auto max-w-5xl w-full px-4`,r&&`pt-4`,n?`pb-3`:`pb-6`);return e.kind===`day`?(0,X.jsx)(`div`,{className:i,children:(0,X.jsxs)(`div`,{className:`flex items-center gap-3 py-1 text-[11px] text-muted-foreground/70 uppercase tracking-wider font-medium`,children:[(0,X.jsx)(`div`,{className:`flex-1 h-px bg-border/50`}),(0,X.jsx)(`span`,{children:e.label}),(0,X.jsx)(`div`,{className:`flex-1 h-px bg-border/50`})]})}):e.kind===`user`?(0,X.jsx)(`div`,{className:i,children:(0,X.jsx)(wo,{message:e.message,isFirst:!0})}):(0,X.jsx)(`div`,{className:i,children:(0,X.jsx)(`div`,{className:Y(`chat-turn`,n?`space-y-1`:`space-y-1.5`),children:e.items.map(n=>{if(n.kind===`msg`)return(0,X.jsx)(wo,{message:n.message,isFirst:n.isFirst,isContinuation:n.isContinuation},n.key);let r=e.isLastTurn&&n.isLastGroup&&t&&n.hasRunningTool;return(0,X.jsx)(Ao,{tools:n.tools,defaultOpen:r,isContinuation:n.isContinuation},n.key)})})})});function Lo(){let e=H(e=>e.messages),t=H(e=>e.isLoading),n=G(e=>e.sidebarOpen),r=G(e=>e.toggleSidebar),i=G(e=>e.compactMode),{totalTokens:a,startTime:o,lastInputTokens:s,maxContext:l,iteration:u}=W(),d=W(e=>e.session),f=d?.id,p=G(e=>f?e.sessionNicknames[f]:void 0),m=G(e=>e.setSessionNickname),h=d?.title,[g,_]=(0,B.useState)(!1),[v,y]=(0,B.useState)(``),b=nr(e=>e.entries),[C,w]=(0,B.useState)(!1),T=(0,B.useRef)(null);(0,B.useEffect)(()=>{if(!C)return;let e=e=>{T.current?.contains(e.target)||w(!1)},t=e=>{e.key===`Escape`&&w(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[C]);let{provider:E,model:D}=U(),O=(0,B.useRef)(null),k=(0,B.useMemo)(()=>Fi(e),[e]),A=(0,B.useRef)(0);A.current=k.length+1;let j=(0,B.useMemo)(()=>{let e=new Map;return k.forEach((t,n)=>{if(t.kind===`user`)e.set(t.message.id,n);else if(t.kind===`agent`)for(let r of t.items)if(r.kind===`msg`)e.set(r.message.id,n);else for(let t of r.tools)e.set(t.id,n)}),e},[k]),ee=G(e=>e.scrollTarget),M=hr(e=>e.autonomy),te=(0,B.useCallback)(e=>{hr.getState().set({autonomy:e}),V()?.send?.({type:`autonomy.switch`,payload:{mode:e}})},[]),[N,ne]=(0,B.useState)(!1),[re,ie]=(0,B.useState)(!1),[ae,oe]=(0,B.useState)(!1);(0,B.useEffect)(()=>{let e=()=>oe(!0);return document.addEventListener(`open:context-breakdown`,e),()=>document.removeEventListener(`open:context-breakdown`,e)},[]);let se=l>0&&s>0?Math.round(s/l*100):0,[ce,le]=(0,B.useState)(!0),[ue,P]=(0,B.useState)(0),[de,F]=(0,B.useState)(!1),fe=(0,B.useRef)(e.length),pe=(0,B.useCallback)(()=>{let e=O.current;if(!e)return;let t=e.scrollSize-e.scrollOffset-e.viewportSize<120;le(t),t&&(P(0),fe.current=H.getState().messages.length),F(e.scrollOffset>e.viewportSize&&e.scrollSize>e.viewportSize*2.5)},[]),me=(0,B.useCallback)(e=>{V()?.resumeSession?.(e),w(!1)},[]);(0,B.useEffect)(()=>{let t=O.current;if(t)if(ce)t.scrollToIndex(A.current-1,{align:`end`}),fe.current=e.length;else{let t=e.length-fe.current;t>0&&P(t)}},[e,ce]),(0,B.useEffect)(()=>{le(!0),P(0),fe.current=H.getState().messages.length,requestAnimationFrame(()=>{O.current?.scrollToIndex(A.current-1,{align:`end`})})},[f]),(0,B.useEffect)(()=>{if(!ee)return;let e=j.get(ee.id);e!==void 0&&O.current?.scrollToIndex(e,{align:`center`,smooth:!0})},[ee,j]);let he=(0,B.useCallback)(()=>{O.current?.scrollToIndex(A.current-1,{align:`end`,smooth:!0}),le(!0),P(0),fe.current=H.getState().messages.length},[]),ge=(0,B.useCallback)(()=>{O.current?.scrollToIndex(0,{align:`start`,smooth:!0})},[]),[_e,ve]=(0,B.useState)(null),[ye,be]=(0,B.useState)(()=>Date.now()),Se=(0,B.useRef)(null),I=(0,B.useMemo)(()=>{let t=e[e.length-1],n=e.filter(e=>e.role===`tool`&&e.toolResult===void 0),r=`Thinking…`;if(n.length>0){let e=Array.from(new Set(n.map(e=>e.toolName).filter(Boolean))),t=e.slice(0,2).join(`, `),i=e.length>2?` +${e.length-2}`:``;r=n.length===1?`Running ${t||`tool`}…`:`Running ${n.length} tools (${t}${i})…`}else t?.role===`assistant`&&t.content?r=`Writing reply…`:t?.role===`tool`&&t.toolResult!==void 0&&(r=`Thinking about the next step…`);let i=_e?Math.max(0,Math.floor((ye-_e)/1e3)):0,a=i<60?`${i}s`:`${Math.floor(i/60)}m ${i%60}s`,o=``,s=t?.role===`assistant`&&t.streaming&&t.content?t:null;if(s){let e=Se.current;if(!e||e.id!==s.id)Se.current={id:s.id,at:Date.now(),len:s.content.length};else{let t=Math.max(1,ye-e.at),n=Math.max(0,s.content.length-e.len);if(t>500&&n>0){let e=n*1e3/t;o=e>=1e3?`${(e/1e3).toFixed(1)}k ch/s`:`${Math.round(e)} ch/s`}}}else Se.current&&=null;return{label:r,elapsed:a,speedLabel:o}},[e,ye,_e]);(0,B.useEffect)(()=>{t&&_e===null&&ve(Date.now()),!t&&_e!==null&&ve(null)},[t,_e]),(0,B.useEffect)(()=>{if(!t)return;let e=setInterval(()=>be(Date.now()),500);return()=>clearInterval(e)},[t]);let Ce=e=>{if(!e)return`--`;let t=Math.floor((Date.now()-e)/1e3);return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`},we=(()=>{if(!t)return`idle`;let n=e[e.length-1];return n?.role===`assistant`&&n.content&&n.streaming?`streaming`:`thinking`})(),Te=we===`idle`?`bg-muted text-muted-foreground`:we===`streaming`?`bg-blue-500/10 text-blue-600 dark:text-blue-400`:`bg-amber-500/10 text-amber-600 dark:text-amber-400`,Ee=l>0&&s>0||a.input>0||!!o;return(0,X.jsxs)(`div`,{className:`flex flex-col flex-1 min-h-0`,children:[(0,X.jsxs)(`header`,{className:`flex flex-col border-b bg-card/95 backdrop-blur-sm supports-[backdrop-filter]:bg-card/80 shrink-0 sticky top-0 z-20`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-3 py-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0 flex-1 overflow-hidden`,children:[!n&&(0,X.jsx)($,{variant:`ghost`,size:`icon`,className:`h-7 w-7 shrink-0`,onClick:r,title:`Open sidebar (Ctrl+\\\\)`,children:(0,X.jsx)(xe,{className:`h-4 w-4`})}),!n&&(0,X.jsx)(`div`,{className:`flex items-center gap-1.5 shrink-0 mr-1`,children:(0,X.jsx)(`div`,{className:`w-5 h-5 rounded bg-primary flex items-center justify-center`,children:(0,X.jsx)(ze,{className:`h-3 w-3 text-primary-foreground`})})}),(0,X.jsxs)(`span`,{className:Y(`flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[11px] font-medium shrink-0 tabular-nums`,Te),title:`Agent state: ${we}`,children:[we!==`idle`&&(0,X.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-current animate-pulse`}),(0,X.jsx)(`span`,{children:we})]}),f&&(g?(0,X.jsx)(`input`,{value:v,onChange:e=>y(e.target.value),onBlur:()=>{v.trim()&&m(f,v),_(!1)},onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),v.trim()&&m(f,v),_(!1)):e.key===`Escape`&&(e.preventDefault(),_(!1))},placeholder:`Session name…`,className:`h-5 px-1.5 text-[11px] bg-background border border-primary/40 rounded focus:outline-none focus:ring-1 focus:ring-ring shrink-0 w-32`,autoFocus:!0}):(0,X.jsxs)(`button`,{type:`button`,onClick:()=>{y(p||h||``),_(!0)},className:`flex items-center gap-1 text-[11px] font-medium text-foreground/80 hover:text-foreground truncate max-w-[12rem] shrink-0 px-1 -mx-1 rounded hover:bg-muted/50 transition-colors`,title:`Click to rename session`,children:[(0,X.jsx)(x,{className:`h-2.5 w-2.5 text-muted-foreground shrink-0`}),(0,X.jsx)(`span`,{className:`truncate`,children:p||h||`Untitled`})]}))]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 shrink-0`,children:[b.length>1&&(0,X.jsxs)(`div`,{ref:T,className:`relative shrink-0`,children:[(0,X.jsxs)(`button`,{type:`button`,onClick:()=>w(e=>!e),className:`flex items-center gap-0.5 px-1 py-0.5 rounded text-[10px] text-muted-foreground hover:text-foreground hover:bg-muted/50 transition-colors`,title:`Switch session`,children:[(0,X.jsx)(Pt,{className:`h-3 w-3`}),(0,X.jsx)(ut,{className:`h-2.5 w-2.5`})]}),C&&(0,X.jsx)(`div`,{className:`absolute left-0 top-full mt-1 z-40 w-64 rounded-md border bg-popover shadow-lg p-1 max-h-60 overflow-y-auto`,children:b.slice(0,15).map(e=>(0,X.jsxs)(`button`,{type:`button`,onClick:()=>me(e.id),className:Y(`w-full text-left px-2 py-1.5 rounded text-xs hover:bg-accent transition-colors`,e.isCurrent&&`bg-primary/10`),children:[(0,X.jsx)(`div`,{className:`font-medium truncate`,children:e.title||`(empty)`}),(0,X.jsxs)(`div`,{className:`text-[10px] text-muted-foreground font-mono truncate`,children:[e.provider,`/`,e.model,` · `,e.tokenTotal.toLocaleString(),` tok`]})]},e.id))})]}),(0,X.jsxs)(`button`,{type:`button`,onClick:()=>G.getState().setModelSwitcherOpen(!0),className:`group hidden sm:flex items-center gap-1 px-2 py-0.5 rounded-md border bg-background/50 hover:bg-accent hover:border-primary/40 transition-colors text-[11px] min-w-0 shrink-0`,title:`Change provider / model (Ctrl+M)`,children:[(0,X.jsx)(c,{className:`h-3 w-3 text-muted-foreground group-hover:text-foreground shrink-0`}),(0,X.jsxs)(`span`,{className:`font-mono truncate max-w-[9rem] xl:max-w-[16rem]`,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:E||`no-provider`}),(0,X.jsx)(`span`,{className:`text-muted-foreground/40 mx-0.5`,children:`/`}),(0,X.jsx)(`span`,{className:`font-medium`,children:D||`no-model`})]})]}),(0,X.jsxs)(`div`,{className:`hidden md:flex items-center gap-1.5 shrink-0`,children:[(0,X.jsx)(To,{}),(0,X.jsx)(Ha,{})]}),u&&(0,X.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[11px] font-medium bg-primary/10 text-primary shrink-0 hover:bg-primary/20 transition-colors cursor-pointer`,title:`Agent iteration — click to jump to live activity`,onClick:()=>document.getElementById(`chat-activity`)?.scrollIntoView({behavior:`smooth`,block:`center`}),children:[(0,X.jsx)(ct,{className:`h-3 w-3 animate-pulse`}),`iter `,u.index,u.max>0?`/${u.max}`:``]}),(0,X.jsx)(ba,{value:M,onChange:te,compact:!0})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-0.5 shrink-0`,children:[(0,X.jsxs)($,{variant:N?`secondary`:`ghost`,size:`icon`,className:Y(`h-7 w-7 relative`,N&&`bg-amber-500/10 text-amber-600 dark:text-amber-400`),onClick:()=>ne(e=>!e),title:`Running processes`,children:[(0,X.jsx)(vn,{className:`h-4 w-4`}),N&&(0,X.jsx)(`span`,{className:`absolute -bottom-0.5 left-1/2 -translate-x-1/2 w-1 h-1 rounded-full bg-amber-500`})]}),(0,X.jsxs)($,{variant:re?`secondary`:`ghost`,size:`icon`,className:Y(`h-7 w-7 relative`,re&&`bg-violet-500/10 text-violet-600 dark:text-violet-400`),onClick:()=>ie(e=>!e),title:`Session checkpoints — rewind`,children:[(0,X.jsx)(Pt,{className:`h-4 w-4`}),re&&(0,X.jsx)(`span`,{className:`absolute -bottom-0.5 left-1/2 -translate-x-1/2 w-1 h-1 rounded-full bg-violet-500`})]})]})]}),Ee&&(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-3 py-1 border-t bg-muted/20 text-[11px] text-muted-foreground`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1 tabular-nums`,children:[s>0&&(0,X.jsx)(Bi,{pct:se,tokens:s,maxTokens:l>0?l:void 0,onClick:()=>oe(!0)}),a.input>0&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,X.jsx)(`span`,{className:`font-medium text-foreground`,children:Q(a.input)}),(0,X.jsx)(`span`,{children:`in`})]}),(0,X.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,X.jsx)(`span`,{className:`font-medium text-foreground`,children:Q(a.output)}),(0,X.jsx)(`span`,{children:`out`})]}),a.cacheRead&&a.cacheRead>0&&(()=>{let e=(a.cacheRead??0)+a.input,t=e>0?Math.round((a.cacheRead??0)/e*100):0;return(0,X.jsxs)(`span`,{className:`flex items-center gap-1`,title:`Cache hit ratio: ${t}%`,children:[(0,X.jsx)(`span`,{className:`font-medium text-foreground`,children:Q(a.cacheRead)}),(0,X.jsxs)(`span`,{children:[`cache (`,t,`%)`]})]})})(),(0,X.jsx)(Ua,{})]})]}),o&&(0,X.jsx)(`span`,{className:`text-muted-foreground/70 tabular-nums shrink-0`,children:Ce(o)})]})]}),(0,X.jsxs)(`div`,{className:`flex-1 relative overflow-hidden`,children:[(0,X.jsx)(Oo,{}),!ce&&(0,X.jsxs)(`button`,{type:`button`,onClick:he,className:Y(`absolute bottom-4 left-1/2 -translate-x-1/2 z-10 jump-bottom`,`flex items-center gap-2 px-4 py-2 rounded-full shadow-lg`,`bg-primary text-primary-foreground text-xs font-medium`,`hover:bg-primary/90 transition-colors animate-message`),children:[(0,X.jsx)(Ft,{className:`h-3.5 w-3.5`}),ue>0?`${ue} new message${ue===1?``:`s`}`:`Jump to latest`]}),de&&(0,X.jsxs)(`button`,{type:`button`,onClick:ge,title:`Scroll to top (oldest)`,className:Y(`absolute top-3 right-3 z-10`,`flex items-center gap-1 px-2.5 py-1 rounded-full shadow-md border`,`bg-background/90 backdrop-blur-sm text-[11px] text-muted-foreground`,`hover:text-foreground hover:bg-background transition-colors animate-message`),children:[(0,X.jsx)(qt,{className:`h-3 w-3`}),(0,X.jsx)(`span`,{children:`Top`})]}),k.length===0&&!t?(0,X.jsx)(`div`,{className:`mx-auto max-w-5xl w-full px-4 pt-4`,children:(0,X.jsx)(Po,{})}):(0,X.jsxs)(S,{ref:O,className:`h-full`,onScroll:pe,children:[k.map((e,n)=>(0,X.jsx)(Io,{row:e,isLoading:t,compactMode:i,isFirstRow:n===0},e.key)),(0,X.jsxs)(`div`,{id:`chat-activity`,className:Y(`mx-auto max-w-5xl w-full px-4`,i?`pb-3`:`pb-8`),children:[(0,X.jsx)(Fo,{}),t&&(0,X.jsxs)(`div`,{className:`flex gap-3 animate-message`,children:[(0,X.jsx)(`div`,{className:`flex-shrink-0 w-8 h-8 rounded-full flex items-center justify-center bg-accent text-accent-foreground ring-2 ring-offset-2 ring-offset-background ring-accent/20`,children:(0,X.jsx)(R,{className:`h-4 w-4`})}),(0,X.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:(0,X.jsx)(`div`,{className:`rounded-2xl px-4 py-3 bg-card border text-foreground`,children:(0,X.jsxs)(`div`,{className:`flex items-center gap-3 text-sm`,children:[(0,X.jsxs)(`span`,{className:`flex gap-1`,children:[(0,X.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-primary/70 animate-bounce [animation-delay:-0.3s]`}),(0,X.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-primary/70 animate-bounce [animation-delay:-0.15s]`}),(0,X.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-primary/70 animate-bounce`})]}),(0,X.jsx)(`span`,{className:`text-foreground/90`,children:I.label}),(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums`,children:I.elapsed}),u&&(0,X.jsxs)(`span`,{className:`text-xs text-muted-foreground tabular-nums`,children:[`· iter `,u.index,u.max>0?`/${u.max}`:``]}),I.speedLabel&&(0,X.jsxs)(`span`,{className:`text-xs text-muted-foreground/80 tabular-nums`,children:[`· `,I.speedLabel]})]})})})]})]},`__live`)]})]}),(0,X.jsxs)(`div`,{className:`border-t bg-card/50 backdrop-blur supports-[backdrop-filter]:bg-card/50 shrink-0`,children:[(0,X.jsxs)(`div`,{className:`max-w-5xl mx-auto px-4 pt-1.5 flex items-center gap-3 text-[10px] text-muted-foreground/50 select-none overflow-x-auto`,children:[(0,X.jsxs)(`span`,{title:`Enter`,className:`inline-flex items-center gap-1`,children:[(0,X.jsx)(`kbd`,{children:`Enter`}),` send`]}),(0,X.jsx)(`span`,{className:`opacity-50`,children:`·`}),(0,X.jsxs)(`span`,{title:`Shift+Enter`,className:`inline-flex items-center gap-1`,children:[(0,X.jsx)(`kbd`,{children:`Shift`}),`+`,(0,X.jsx)(`kbd`,{children:`↵`}),` newline`]}),(0,X.jsx)(`span`,{className:`opacity-50`,children:`·`}),(0,X.jsxs)(`span`,{title:`Ctrl+\\\\`,className:`inline-flex items-center gap-1`,children:[(0,X.jsx)(`kbd`,{children:`Ctrl+\\`}),` sidebar`]}),(0,X.jsx)(`span`,{className:`opacity-50`,children:`·`}),(0,X.jsxs)(`span`,{title:`Ctrl+F`,className:`inline-flex items-center gap-1`,children:[(0,X.jsx)(`kbd`,{children:`Ctrl+F`}),` search`]}),(0,X.jsx)(`span`,{className:`opacity-50`,children:`·`}),(0,X.jsxs)(`span`,{title:`Ctrl+K`,className:`inline-flex items-center gap-1`,children:[(0,X.jsx)(`kbd`,{children:`Ctrl+K`}),` palette`]}),(0,X.jsx)(`span`,{className:`opacity-50`,children:`·`}),(0,X.jsxs)(`span`,{title:`Ctrl+L / Ctrl+N`,className:`inline-flex items-center gap-1`,children:[(0,X.jsx)(`kbd`,{children:`Ctrl+L`}),` clear`]}),(0,X.jsx)(`span`,{className:`opacity-50`,children:`·`}),(0,X.jsxs)(`span`,{title:`j/k to navigate`,className:`inline-flex items-center gap-1`,children:[(0,X.jsx)(`kbd`,{children:`j`}),(0,X.jsx)(`kbd`,{children:`k`}),` navigate`]}),(0,X.jsx)(`span`,{className:`opacity-50`,children:`·`}),(0,X.jsxs)(`span`,{title:`Ctrl+M`,className:`inline-flex items-center gap-1`,children:[(0,X.jsx)(`kbd`,{children:`Ctrl+M`}),` model`]}),(0,X.jsx)(`span`,{className:`opacity-50`,children:`·`}),(0,X.jsxs)(`span`,{title:`Ctrl+Shift+D`,className:`inline-flex items-center gap-1`,children:[(0,X.jsx)(`kbd`,{children:`Ctrl+⇧D`}),` density`]})]}),(0,X.jsx)(`div`,{className:`p-4`,children:(0,X.jsx)(`div`,{className:`max-w-5xl mx-auto`,children:(0,X.jsx)(za,{onOpenBreakdown:()=>oe(!0)})})})]}),(0,X.jsx)(Eo,{open:N,onClose:()=>ne(!1)}),(0,X.jsx)(Ba,{open:re,onClose:()=>ie(!1)}),(0,X.jsx)(Vi,{open:ae,onClose:()=>oe(!1)})]})}jn.defineTheme(`wrongstack-dark`,{base:`vs-dark`,inherit:!0,rules:[{token:`comment`,foreground:`6e717a`,fontStyle:`italic`},{token:`comment.line`,foreground:`6e717a`,fontStyle:`italic`},{token:`comment.block`,foreground:`6e717a`,fontStyle:`italic`},{token:`comment.documentation`,foreground:`6e717a`,fontStyle:`italic`},{token:`string`,foreground:`64d488`},{token:`string.escape`,foreground:`49d3c5`},{token:`string.template`,foreground:`64d488`},{token:`number`,foreground:`f2a23a`},{token:`number.hex`,foreground:`f2a23a`},{token:`number.float`,foreground:`f2a23a`},{token:`keyword`,foreground:`f28dbc`},{token:`keyword.control`,foreground:`f28dbc`},{token:`keyword.operator`,foreground:`9ea0a8`},{token:`type`,foreground:`6cb6ff`},{token:`type.identifier`,foreground:`6cb6ff`},{token:`type.parameter`,foreground:`eeede7`},{token:`function`,foreground:`6cb6ff`},{token:`predefined`,foreground:`6cb6ff`},{token:`variable`,foreground:`eeede7`},{token:`variable.parameter`,foreground:`f2a23a`},{token:`variable.readonly`,foreground:`f2a23a`},{token:`variable.language`,foreground:`f28dbc`},{token:`tag`,foreground:`f47a95`},{token:`metatag`,foreground:`f47a95`},{token:`tag.html`,foreground:`f47a95`},{token:`tag.jsx`,foreground:`f47a95`},{token:`tag.tsx`,foreground:`f47a95`},{token:`attribute.name`,foreground:`ffb055`},{token:`attribute.value`,foreground:`64d488`},{token:`attribute.name.html`,foreground:`ffb055`},{token:`attribute.name.jsx`,foreground:`ffb055`},{token:`regexp`,foreground:`49d3c5`},{token:`delimiter`,foreground:`9ea0a8`},{token:`delimiter.bracket`,foreground:`9ea0a8`},{token:`delimiter.parenthesis`,foreground:`9ea0a8`},{token:`delimiter.curly`,foreground:`9ea0a8`},{token:`delimiter.square`,foreground:`9ea0a8`},{token:`delimiter.array`,foreground:`9ea0a8`},{token:`operator`,foreground:`9ea0a8`},{token:`constant`,foreground:`f2a23a`},{token:`constant.language`,foreground:`f28dbc`},{token:`support`,foreground:`6cb6ff`},{token:`support.function`,foreground:`6cb6ff`},{token:`support.type`,foreground:`6cb6ff`},{token:`support.constant`,foreground:`f2a23a`},{token:`support.variable`,foreground:`eeede7`},{token:`storage`,foreground:`f28dbc`},{token:`storage.modifier`,foreground:`f28dbc`},{token:`storage.type`,foreground:`6cb6ff`},{token:`entity.name.type`,foreground:`6cb6ff`},{token:`entity.name.function`,foreground:`6cb6ff`},{token:`entity.other.inherited-class`,foreground:`6cb6ff`},{token:`entity.name.tag`,foreground:`f47a95`},{token:`entity.other.attribute-name`,foreground:`ffb055`},{token:`invalid`,foreground:`d63c3c`},{token:`invalid.deprecated`,foreground:`d63c3c`},{token:`emphasis`,fontStyle:`italic`},{token:`strong`,fontStyle:`bold`},{token:`header`,foreground:`6cb6ff`,fontStyle:`bold`},{token:`link`,foreground:`49d3c5`,fontStyle:`underline`},{token:`class`,foreground:`6cb6ff`},{token:`interface`,foreground:`49d3c5`},{token:`enum`,foreground:`f2a23a`},{token:`enumMember`,foreground:`f2a23a`},{token:`typeParameter`,foreground:`f2a23a`},{token:`namespace`,foreground:`6cb6ff`},{token:`method`,foreground:`6cb6ff`},{token:`property`,foreground:`eeede7`},{token:`property.readonly`,foreground:`f2a23a`},{token:`property.static`,foreground:`eeede7`},{token:`parameter`,foreground:`f2a23a`},{token:`variable.defaultLibrary`,foreground:`6cb6ff`},{token:`function.defaultLibrary`,foreground:`6cb6ff`},{token:`macro`,foreground:`c4a0ff`},{token:`decorator`,foreground:`c4a0ff`},{token:`label`,foreground:`f2a23a`},{token:`comment.deprecated`,foreground:`6e717a`,fontStyle:`italic strikethrough`},{token:`variable.deprecated`,foreground:`6e717a`,fontStyle:`strikethrough`}],colors:{"editor.background":`#121318`,"editor.foreground":`#eeede7`,"editorCursor.foreground":`#f2a23a`,"editor.selectionBackground":`#f2a23a25`,"editor.selectionHighlightBackground":`#f2a23a15`,"editor.inactiveSelectionBackground":`#f2a23a10`,"editor.lineHighlightBackground":`#1a1c23`,"editorLineNumber.foreground":`#4a4d55`,"editorLineNumber.activeForeground":`#9ea0a8`,"editorRuler.foreground":`#1e2028`,"editorBracketMatch.background":`#f2a23a15`,"editorBracketMatch.border":`#f2a23a30`,"editor.findMatchBackground":`#f2a23a30`,"editor.findMatchHighlightBackground":`#f2a23a15`,"editorWidget.background":`#1a1c23`,"editorWidget.border":`#262830`,"editorSuggestWidget.background":`#1a1c23`,"editorSuggestWidget.border":`#262830`,"editorSuggestWidget.selectedBackground":`#262830`,"editorHoverWidget.background":`#1a1c23`,"editorHoverWidget.border":`#262830`,"scrollbar.shadow":`#00000000`,"scrollbarSlider.background":`#4a4d5530`,"scrollbarSlider.hoverBackground":`#f2a23a50`,"scrollbarSlider.activeBackground":`#f2a23a70`,"minimap.background":`#121318`,"diffEditor.insertedTextBackground":`#64d48815`,"diffEditor.removedTextBackground":`#d63c3c15`,"sideBar.background":`#121318`,"sideBar.border":`#1e2028`,"input.background":`#1a1c23`,"input.border":`#262830`,"input.foreground":`#eeede7`,"input.placeholderForeground":`#6e717a`,focusBorder:`#f2a23a40`,"list.activeSelectionBackground":`#262830`,"list.hoverBackground":`#1e2028`,"dropdown.background":`#1a1c23`,"dropdown.border":`#262830`,"badge.background":`#f2a23a`,"badge.foreground":`#1a1208`,"editorBracketHighlighting.foreground1":`#f2a23a`,"editorBracketHighlighting.foreground2":`#6cb6ff`,"editorBracketHighlighting.foreground3":`#f28dbc`,"editorBracketHighlighting.foreground4":`#64d488`,"editorBracketHighlighting.foreground5":`#49d3c5`,"editorBracketHighlighting.foreground6":`#c4a0ff`,"editorBracketPairGuide.background1":`#f2a23a18`,"editorBracketPairGuide.background2":`#6cb6ff18`,"editorBracketPairGuide.background3":`#f28dbc18`,"editorBracketPairGuide.background4":`#64d48818`,"editorBracketPairGuide.background5":`#49d3c518`,"editorBracketPairGuide.background6":`#c4a0ff18`,"editorBracketPairGuide.activeBackground1":`#f2a23a30`,"editorBracketPairGuide.activeBackground2":`#6cb6ff30`,"editorBracketPairGuide.activeBackground3":`#f28dbc30`,"editorBracketPairGuide.activeBackground4":`#64d48830`,"editorBracketPairGuide.activeBackground5":`#49d3c530`,"editorBracketPairGuide.activeBackground6":`#c4a0ff30`}}),jn.defineTheme(`wrongstack-light`,{base:`vs`,inherit:!0,rules:[{token:`comment`,foreground:`9a9d99`,fontStyle:`italic`},{token:`comment.line`,foreground:`9a9d99`,fontStyle:`italic`},{token:`comment.block`,foreground:`9a9d99`,fontStyle:`italic`},{token:`comment.documentation`,foreground:`9a9d99`,fontStyle:`italic`},{token:`string`,foreground:`3b8c5a`},{token:`string.escape`,foreground:`17998e`},{token:`string.template`,foreground:`3b8c5a`},{token:`number`,foreground:`d97a12`},{token:`number.hex`,foreground:`d97a12`},{token:`number.float`,foreground:`d97a12`},{token:`keyword`,foreground:`d65a9a`},{token:`keyword.control`,foreground:`d65a9a`},{token:`keyword.operator`,foreground:`6b6d72`},{token:`type`,foreground:`3178c6`},{token:`type.identifier`,foreground:`3178c6`},{token:`type.parameter`,foreground:`1a1c23`},{token:`function`,foreground:`3178c6`},{token:`predefined`,foreground:`3178c6`},{token:`variable`,foreground:`1a1c23`},{token:`variable.parameter`,foreground:`d97a12`},{token:`variable.readonly`,foreground:`d97a12`},{token:`variable.language`,foreground:`d65a9a`},{token:`tag`,foreground:`c93a5e`},{token:`metatag`,foreground:`c93a5e`},{token:`tag.html`,foreground:`c93a5e`},{token:`tag.jsx`,foreground:`c93a5e`},{token:`tag.tsx`,foreground:`c93a5e`},{token:`attribute.name`,foreground:`d4893a`},{token:`attribute.value`,foreground:`3b8c5a`},{token:`attribute.name.html`,foreground:`d4893a`},{token:`attribute.name.jsx`,foreground:`d4893a`},{token:`regexp`,foreground:`17998e`},{token:`delimiter`,foreground:`6b6d72`},{token:`delimiter.bracket`,foreground:`6b6d72`},{token:`delimiter.parenthesis`,foreground:`6b6d72`},{token:`delimiter.curly`,foreground:`6b6d72`},{token:`delimiter.square`,foreground:`6b6d72`},{token:`delimiter.array`,foreground:`6b6d72`},{token:`operator`,foreground:`6b6d72`},{token:`constant`,foreground:`d97a12`},{token:`constant.language`,foreground:`d65a9a`},{token:`support`,foreground:`3178c6`},{token:`support.function`,foreground:`3178c6`},{token:`support.type`,foreground:`3178c6`},{token:`support.constant`,foreground:`d97a12`},{token:`support.variable`,foreground:`1a1c23`},{token:`storage`,foreground:`d65a9a`},{token:`storage.modifier`,foreground:`d65a9a`},{token:`storage.type`,foreground:`3178c6`},{token:`entity.name.type`,foreground:`3178c6`},{token:`entity.name.function`,foreground:`3178c6`},{token:`entity.other.inherited-class`,foreground:`3178c6`},{token:`entity.name.tag`,foreground:`c93a5e`},{token:`entity.other.attribute-name`,foreground:`d4893a`},{token:`invalid`,foreground:`d63c3c`},{token:`invalid.deprecated`,foreground:`d63c3c`},{token:`emphasis`,fontStyle:`italic`},{token:`strong`,fontStyle:`bold`},{token:`header`,foreground:`3178c6`,fontStyle:`bold`},{token:`link`,foreground:`17998e`,fontStyle:`underline`},{token:`class`,foreground:`3178c6`},{token:`interface`,foreground:`17998e`},{token:`enum`,foreground:`d97a12`},{token:`enumMember`,foreground:`d97a12`},{token:`typeParameter`,foreground:`d97a12`},{token:`namespace`,foreground:`3178c6`},{token:`method`,foreground:`3178c6`},{token:`property`,foreground:`1a1c23`},{token:`property.readonly`,foreground:`d97a12`},{token:`property.static`,foreground:`1a1c23`},{token:`parameter`,foreground:`d97a12`},{token:`variable.defaultLibrary`,foreground:`3178c6`},{token:`function.defaultLibrary`,foreground:`3178c6`},{token:`macro`,foreground:`8b5cf6`},{token:`decorator`,foreground:`8b5cf6`},{token:`label`,foreground:`d97a12`},{token:`comment.deprecated`,foreground:`9a9d99`,fontStyle:`italic strikethrough`},{token:`variable.deprecated`,foreground:`9a9d99`,fontStyle:`strikethrough`}],colors:{"editor.background":`#f7f7f5`,"editor.foreground":`#1a1c23`,"editorCursor.foreground":`#e07b0e`,"editor.selectionBackground":`#e07b0e18`,"editor.selectionHighlightBackground":`#e07b0e10`,"editor.inactiveSelectionBackground":`#e07b0e08`,"editor.lineHighlightBackground":`#f0efe9`,"editorLineNumber.foreground":`#bab8b0`,"editorLineNumber.activeForeground":`#6b6d72`,"editorRuler.foreground":`#e8e6de`,"editorBracketMatch.background":`#e07b0e12`,"editorBracketMatch.border":`#e07b0e25`,"editor.findMatchBackground":`#e07b0e25`,"editor.findMatchHighlightBackground":`#e07b0e12`,"editorWidget.background":`#f7f7f5`,"editorWidget.border":`#ddd9d0`,"editorSuggestWidget.background":`#f7f7f5`,"editorSuggestWidget.border":`#ddd9d0`,"editorSuggestWidget.selectedBackground":`#eeece2`,"editorHoverWidget.background":`#f7f7f5`,"editorHoverWidget.border":`#ddd9d0`,"scrollbar.shadow":`#00000000`,"scrollbarSlider.background":`#bab8b040`,"scrollbarSlider.hoverBackground":`#e07b0e50`,"scrollbarSlider.activeBackground":`#e07b0e70`,"minimap.background":`#f7f7f5`,"diffEditor.insertedTextBackground":`#3b8c5a12`,"diffEditor.removedTextBackground":`#d63c3c12`,"sideBar.background":`#f7f7f5`,"sideBar.border":`#e8e6de`,"input.background":`#ffffff`,"input.border":`#ddd9d0`,"input.foreground":`#1a1c23`,"input.placeholderForeground":`#9a9d99`,focusBorder:`#e07b0e35`,"list.activeSelectionBackground":`#eeece2`,"list.hoverBackground":`#f0efe9`,"dropdown.background":`#ffffff`,"dropdown.border":`#ddd9d0`,"badge.background":`#e07b0e`,"badge.foreground":`#ffffff`,"editorBracketHighlighting.foreground1":`#d97a12`,"editorBracketHighlighting.foreground2":`#3178c6`,"editorBracketHighlighting.foreground3":`#d65a9a`,"editorBracketHighlighting.foreground4":`#3b8c5a`,"editorBracketHighlighting.foreground5":`#17998e`,"editorBracketHighlighting.foreground6":`#8b5cf6`,"editorBracketPairGuide.background1":`#d97a1215`,"editorBracketPairGuide.background2":`#3178c615`,"editorBracketPairGuide.background3":`#d65a9a15`,"editorBracketPairGuide.background4":`#3b8c5a15`,"editorBracketPairGuide.background5":`#17998e15`,"editorBracketPairGuide.background6":`#8b5cf615`,"editorBracketPairGuide.activeBackground1":`#d97a1228`,"editorBracketPairGuide.activeBackground2":`#3178c628`,"editorBracketPairGuide.activeBackground3":`#d65a9a28`,"editorBracketPairGuide.activeBackground4":`#3b8c5a28`,"editorBracketPairGuide.activeBackground5":`#17998e28`,"editorBracketPairGuide.activeBackground6":`#8b5cf628`}});function Ro(){return typeof document>`u`||document.documentElement.classList.contains(`dark`)?`wrongstack-dark`:`wrongstack-light`}Ae.config({monaco:ye});var zo={ts:`typescript`,tsx:`typescript`,js:`javascript`,jsx:`javascript`,json:`json`,css:`css`,html:`html`,svg:`xml`,md:`markdown`,yml:`yaml`,yaml:`yaml`,toml:`toml`,sh:`shell`,bash:`shell`,ps1:`powershell`,py:`python`,rs:`rust`,go:`go`,rb:`ruby`,java:`java`,c:`c`,cpp:`cpp`,h:`c`,hpp:`cpp`,sql:`sql`,xml:`xml`};function Bo(e){return zo[e.split(`.`).pop()?.toLowerCase()??``]??`plaintext`}function Vo(){let e=q(e=>e.openFiles),t=q(e=>e.activeFilePath),n=q(e=>e.setActiveFile),r=q(e=>e.closeFile);return e.length===0?null:(0,X.jsx)(`div`,{className:`flex items-center border-b bg-muted/40 overflow-x-auto shrink-0`,children:e.map(e=>{let i=e.path===t,a=e.path.split(`/`).pop()??e.path;return(0,X.jsxs)(`button`,{type:`button`,onClick:()=>n(e.path),onMouseDown:t=>{t.button===1&&(t.preventDefault(),r(e.path))},className:Y(`group flex items-center gap-1.5 px-3 py-1.5 text-[11px] border-r whitespace-nowrap min-w-0 max-w-[180px] transition-colors`,i?`bg-background border-t-2 border-t-primary text-foreground -mb-px`:`text-muted-foreground hover:bg-muted/60 hover:text-foreground`),title:e.path,children:[e.dirty&&(0,X.jsx)(C,{className:`h-2 w-2 fill-current text-primary shrink-0`}),(0,X.jsx)(`span`,{className:`truncate`,children:a}),(0,X.jsx)(Ie,{className:Y(`h-3 w-3 shrink-0 rounded-sm hover:bg-muted-foreground/20 opacity-0 group-hover:opacity-100 transition-opacity`,i&&`opacity-100`),onClick:t=>{t.stopPropagation(),r(e.path)}})]},e.path)})})}function Ho(){let e=q(e=>e.openFiles),t=q(e=>e.activeFilePath),n=q(e=>e.updateContent),{theme:r}=Ti(),i=(0,B.useRef)(null),a=(0,B.useMemo)(()=>e.find(e=>e.path===t)??null,[e,t]),o=t?Bo(t):`plaintext`,c=Ro();(0,B.useEffect)(()=>{let e=Ro();jn.setTheme(e)},[r]);let l=(0,B.useCallback)(e=>{i.current=e,jn.setTheme(Ro())},[]),u=(0,B.useCallback)(e=>{t&&e!==void 0&&n(t,e)},[t,n]);return(0,B.useEffect)(()=>{let e=e=>{let n=e.ctrlKey||e.metaKey,r=e.target?.tagName?.toLowerCase()===`textarea`||e.target?.closest(`.monaco-editor`)!==null;!n||!r||(e.key.toLowerCase()===`s`&&(e.preventDefault(),window.dispatchEvent(new CustomEvent(`wrongstack:save-file`,{detail:{filePath:t}}))),e.key.toLowerCase()===`w`&&(e.preventDefault(),t&&q.getState().closeFile(t)))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]),e.length===0?(0,X.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,X.jsxs)(`div`,{className:`text-center space-y-2`,children:[(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No files open`}),(0,X.jsx)(`p`,{className:`text-[11px] text-muted-foreground/60`,children:`Select a file from the explorer to start editing`})]})}):(0,X.jsxs)(`div`,{className:`flex-1 flex flex-col overflow-hidden`,children:[(0,X.jsx)(Vo,{}),(0,X.jsx)(`div`,{className:`flex-1 relative`,children:a?(0,X.jsx)(s,{language:o,value:a.content,onChange:u,theme:c,onMount:l,loading:(0,X.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,X.jsx)(`span`,{className:`text-[11px] text-muted-foreground animate-pulse`,children:`Loading editor…`})}),options:{minimap:{enabled:!1},fontSize:13,fontFamily:`'IBM Plex Mono', 'Cascadia Code', 'Fira Code', 'JetBrains Mono', monospace`,lineNumbers:`on`,renderWhitespace:`selection`,scrollBeyondLastLine:!1,wordWrap:`off`,tabSize:2,smoothScrolling:!0,cursorBlinking:`smooth`,cursorSmoothCaretAnimation:`on`,bracketPairColorization:{enabled:!0},"semanticHighlighting.enabled":!0,automaticLayout:!0,padding:{top:8}}},a.path):(0,X.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,X.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`Select a tab to view its content`})})})]})}var Uo=y,Wo=re,Go=pe,Ko=B.forwardRef(({className:e,...t},n)=>(0,X.jsx)(le,{ref:n,className:Y(`fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0`,e),...t}));Ko.displayName=le.displayName;var qo=B.forwardRef(({className:e,children:t,...n},r)=>(0,X.jsxs)(Go,{children:[(0,X.jsx)(Ko,{}),(0,X.jsxs)(Dt,{ref:r,className:Y(`fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg`,e),...n,children:[t,(0,X.jsxs)(i,{className:`absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground`,children:[(0,X.jsx)(Ie,{className:`h-4 w-4`}),(0,X.jsx)(`span`,{className:`sr-only`,children:`Close`})]})]})]}));qo.displayName=Dt.displayName;var Jo=({className:e,...t})=>(0,X.jsx)(`div`,{className:Y(`flex flex-col space-y-1.5 text-center sm:text-left`,e),...t});Jo.displayName=`DialogHeader`;var Yo=({className:e,...t})=>(0,X.jsx)(`div`,{className:Y(`flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2`,e),...t});Yo.displayName=`DialogFooter`;var Xo=B.forwardRef(({className:e,...t},n)=>(0,X.jsx)(O,{ref:n,className:Y(`text-lg font-semibold leading-none tracking-tight`,e),...t}));Xo.displayName=O.displayName;var Zo=B.forwardRef(({className:e,...t},n)=>(0,X.jsx)(oe,{ref:n,className:Y(`text-sm text-muted-foreground`,e),...t}));Zo.displayName=oe.displayName;function Qo(e){return/edit|write|create|patch/i.test(e)?Cn:/bash|shell|exec|run|command/i.test(e)?vn:/fetch|http|web|curl|request/i.test(e)?st:He}function $o({toolName:e,input:t}){let n=Qa(e,t);if(n)return(0,X.jsx)(`div`,{className:`rounded-lg overflow-hidden border`,children:(0,X.jsx)(Ya,{oldText:n.oldText,newText:n.newText,caption:n.caption})});if(typeof t==`object`&&t){let e=t,n=e.command??e.cmd??e.script;if(typeof n==`string`&&n.trim().length>0)return(0,X.jsxs)(`div`,{className:`rounded-lg border bg-background/40 overflow-hidden`,children:[(0,X.jsxs)(`div`,{className:`px-3 py-1.5 text-[10px] uppercase tracking-wider text-muted-foreground border-b bg-muted/40 flex items-center gap-1.5`,children:[(0,X.jsx)(vn,{className:`h-3 w-3`}),(0,X.jsx)(`span`,{children:`Command`})]}),(0,X.jsxs)(`pre`,{className:`px-3 py-2 text-xs font-mono whitespace-pre-wrap break-all max-h-40 overflow-auto`,children:[`$`,n]})]});let r=e.url;if(typeof r==`string`)return(0,X.jsxs)(`div`,{className:`rounded-lg border bg-background/40 px-3 py-2 text-xs font-mono`,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:(e.method??`GET`).toUpperCase()}),` `,(0,X.jsx)(`span`,{className:`break-all`,children:r})]})}return(0,X.jsxs)(`div`,{className:`p-3 rounded-lg bg-muted/50 border text-xs font-mono`,children:[(0,X.jsx)(`div`,{className:`text-muted-foreground mb-2`,children:`Input:`}),(0,X.jsx)(`pre`,{className:`whitespace-pre-wrap break-all max-h-60 overflow-auto`,children:JSON.stringify(t,null,2)})]})}function es(){let{showConfirmDialog:e,confirmInfo:t,hideConfirm:n}=G(),{sendConfirm:r}=Z(),i=(0,B.useRef)(null),a=e=>{t&&r(t.id,e),n()};if((0,B.useEffect)(()=>{if(!e)return;let t=e=>{let t=e.target?.tagName?.toLowerCase();t===`input`||t===`textarea`||(e.key===`y`||e.key===`Y`?(e.preventDefault(),a(`yes`)):e.key===`n`||e.key===`N`||e.key===`Escape`?(e.preventDefault(),a(`no`)):e.key===`a`||e.key===`A`?(e.preventDefault(),a(`always`)):(e.key===`d`||e.key===`D`)&&(e.preventDefault(),a(`deny`)))};return window.addEventListener(`keydown`,t),i.current?.focus(),()=>window.removeEventListener(`keydown`,t)},[e,t?.id]),!t)return(0,X.jsx)(Uo,{open:e,onOpenChange:()=>n(),children:(0,X.jsx)(qo,{})});let o=Qo(t.toolName),s=/edit|write/i.test(t.toolName);return(0,X.jsx)(Uo,{open:e,onOpenChange:()=>n(),children:(0,X.jsxs)(qo,{className:`sm:max-w-2xl border-yellow-500/50`,ref:i,tabIndex:-1,children:[(0,X.jsxs)(Jo,{children:[(0,X.jsxs)(Xo,{className:`flex items-center gap-2`,children:[(0,X.jsx)(Dn,{className:`h-5 w-5 text-yellow-500 animate-pulse`}),`Approval required: `,t.toolName]}),(0,X.jsxs)(Zo,{children:[`The agent wants to `,s?`modify a file`:`run this tool`,`. Review the request below and decide whether to proceed.`]})]}),(0,X.jsxs)(`div`,{className:`py-2 space-y-3`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-3 p-3 rounded-lg bg-muted`,children:[(0,X.jsx)(o,{className:`h-5 w-5 text-muted-foreground`}),(0,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsx)(`div`,{className:`font-medium font-mono truncate`,children:t.toolName}),(0,X.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[s?`File modification`:`Tool execution`,` — preview below`]})]})]}),t.input!==void 0&&(0,X.jsx)($o,{toolName:t.toolName,input:t.input}),t.suggestedPattern&&(0,X.jsxs)(`div`,{className:`flex items-start gap-2 p-3 rounded-lg bg-yellow-500/10 border border-yellow-500/20`,children:[(0,X.jsx)(Qe,{className:`h-4 w-4 text-yellow-600 mt-0.5 shrink-0`}),(0,X.jsxs)(`div`,{className:`text-sm min-w-0`,children:[(0,X.jsx)(`div`,{className:`font-medium text-yellow-800 dark:text-yellow-200`,children:`Trust pattern suggestion`}),(0,X.jsx)(`div`,{className:`font-mono text-xs mt-1 break-all`,children:t.suggestedPattern}),(0,X.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-1`,children:[`Picking `,(0,X.jsx)(`span`,{className:`font-medium`,children:`Always`}),` will whitelist matching calls for this project.`]})]})]})]}),(0,X.jsxs)(Yo,{className:`gap-2 sm:gap-2 flex-wrap`,children:[(0,X.jsxs)($,{variant:`outline`,size:`sm`,onClick:()=>a(`deny`),title:`Reject this and all future calls matching the pattern (d)`,children:[`Deny always `,(0,X.jsx)(`kbd`,{className:`ml-1 text-[10px] border rounded px-1 bg-background`,children:`d`})]}),(0,X.jsxs)($,{variant:`outline`,size:`sm`,onClick:()=>a(`no`),title:`Reject this single call (Esc / n)`,children:[`No `,(0,X.jsx)(`kbd`,{className:`ml-1 text-[10px] border rounded px-1 bg-background`,children:`n`})]}),(0,X.jsxs)($,{variant:`outline`,size:`sm`,onClick:()=>a(`always`),title:`Approve and remember the pattern for the project (a)`,children:[`Always `,(0,X.jsx)(`kbd`,{className:`ml-1 text-[10px] border rounded px-1 bg-background`,children:`a`})]}),(0,X.jsxs)($,{size:`sm`,onClick:()=>a(`yes`),title:`Approve this single call (y)`,children:[`Yes `,(0,X.jsx)(`kbd`,{className:`ml-1 text-[10px] border rounded px-1 bg-background/80`,children:`y`})]})]})]})})}var ts=St()((e,t)=>({request:null,open:n=>{t().request?.resolve(!1),e({request:n})},settle:n=>{t().request?.resolve(n),e({request:null})}}));function ns(e){return new Promise(t=>{ts.getState().open({...e,resolve:t})})}function rs(){let e=ts(e=>e.request),t=ts(e=>e.settle);return(0,B.useEffect)(()=>{if(!e)return;let t=e=>{e.key===`Enter`&&(e.preventDefault(),ts.getState().settle(!0))};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e]),(0,X.jsx)(Uo,{open:e!==null,onOpenChange:e=>{e||t(!1)},children:(0,X.jsxs)(qo,{className:`max-w-md`,children:[(0,X.jsxs)(Jo,{children:[(0,X.jsx)(Xo,{children:e?.title}),e?.message&&(0,X.jsx)(Zo,{children:e.message})]}),(0,X.jsxs)(Yo,{className:`gap-2`,children:[(0,X.jsx)($,{variant:`outline`,size:`sm`,onClick:()=>t(!1),children:e?.cancelLabel??`Cancel`}),(0,X.jsx)($,{variant:e?.danger?`destructive`:`default`,size:`sm`,autoFocus:!0,onClick:()=>t(!0),children:e?.confirmLabel??`Confirm`})]})]})})}function is(){let e=U(e=>e.wsStatus),n=U(e=>e.wsUrl),[r,i]=(0,B.useState)(!1),[a,o]=(0,B.useState)(Date.now());if((0,B.useEffect)(()=>{if(e.state!==`reconnecting`)return;let t=setInterval(()=>o(Date.now()),500);return()=>clearInterval(t)},[e.state]),(0,B.useEffect)(()=>{e.state===`open`&&i(!1)},[e.state]),e.state===`open`||e.state===`connecting`||r)return null;let s=()=>V(n).retryNow(),c=e.state===`reconnecting`,l=e.state===`closed`?e.error:e.state===`reconnecting`?e.lastError:void 0,u=c?Math.max(0,Math.ceil((e.nextRetryAt-a)/1e3)):0;return(0,X.jsxs)(`div`,{className:Y(`flex items-center gap-3 px-4 py-2 border-b text-sm`,c?`bg-orange-500/10 text-orange-700 dark:text-orange-300 border-orange-500/30`:`bg-red-500/10 text-red-700 dark:text-red-300 border-red-500/30`),children:[c?(0,X.jsx)(L,{className:`h-4 w-4 animate-spin shrink-0`}):(0,X.jsx)(t,{className:`h-4 w-4 shrink-0`}),(0,X.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,X.jsx)(`div`,{className:`font-medium`,children:c?`Reconnecting to backend (attempt ${e.attempt}) — retrying in ${u}s`:`Disconnected from backend`}),l&&(0,X.jsx)(`div`,{className:`text-xs opacity-80 truncate`,children:l})]}),(0,X.jsxs)(`button`,{type:`button`,onClick:s,className:Y(`inline-flex items-center gap-1 px-2.5 py-1 rounded-md border text-xs font-medium`,`hover:bg-background/30 transition-colors shrink-0`,c?`border-orange-500/40`:`border-red-500/40`),title:`Retry connection now`,children:[(0,X.jsx)(v,{className:`h-3 w-3`}),`Retry now`]}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>i(!0),className:`text-current/60 hover:text-current shrink-0`,title:`Dismiss (chip in topbar still shows status)`,children:(0,X.jsx)(Ie,{className:`h-4 w-4`})})]})}var as=class extends B.Component{state={error:null};static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e,t){console.error(`[ErrorBoundary]`,e,t.componentStack),this.props.onError?.(e,t)}handleReset=()=>{this.setState({error:null})};render(){return this.state.error?(0,X.jsx)(`div`,{className:`flex items-center justify-center h-screen bg-background`,children:(0,X.jsxs)(`div`,{className:`flex flex-col items-center gap-4 p-8 max-w-md text-center`,children:[(0,X.jsx)(Qe,{className:`h-12 w-12 text-destructive`}),(0,X.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Something went wrong`}),(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`A rendering error occurred. Your session is still active on the server — reloading will pick up where you left off.`}),(0,X.jsx)(`pre`,{className:`text-xs font-mono text-muted-foreground bg-muted/50 rounded p-3 max-h-32 overflow-auto w-full text-left`,children:this.state.error.message}),(0,X.jsxs)(`div`,{className:`flex gap-2`,children:[(0,X.jsxs)($,{size:`sm`,variant:`outline`,onClick:()=>window.location.reload(),children:[(0,X.jsx)(Mt,{className:`h-4 w-4 mr-1`}),`Reload page`]}),(0,X.jsx)($,{size:`sm`,onClick:this.handleReset,children:`Try again`})]})]})}):this.props.children}};function os(e,t,n,r,i){let a=[];for(let n of e){let e=t[n.id]??[];for(let t of e)a.push({provider:n.id,model:t.id,modelName:t.name||t.id,contextWindow:t.contextWindow,isCurrent:n.id===r&&t.id===i})}let o=n.toLowerCase().trim();return(o?a.filter(e=>e.provider.toLowerCase().includes(o)||e.model.toLowerCase().includes(o)||e.modelName.toLowerCase().includes(o)):a).sort((e,t)=>e.isCurrent===t.isCurrent?e.provider.localeCompare(t.provider)||e.model.localeCompare(t.model):e.isCurrent?-1:1)}function ss(){let e=G(e=>e.modelSwitcherOpen),t=G(e=>e.setModelSwitcherOpen),[n,r]=(0,B.useState)(``),[i,a]=(0,B.useState)(0),[o,s]=(0,B.useState)([]),[l,u]=(0,B.useState)({}),d=(0,B.useRef)(null),f=U(e=>e.wsUrl),p=U(e=>e.provider),m=U(e=>e.model),h=G(e=>e.paletteOpen),{listSavedProviders:g,listProviderModels:_,switchModel:v}=Z();(0,B.useEffect)(()=>{let n=n=>{if((n.ctrlKey||n.metaKey)&&n.key.toLowerCase()===`m`&&!n.shiftKey&&!n.altKey){if(h)return;n.preventDefault(),t(!e);return}n.key===`Escape`&&e&&(n.preventDefault(),t(!1))};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,h]),(0,B.useEffect)(()=>{let e=V(f),t=e.on(`providers.saved`,e=>{let t=e.payload;s(t.providers??[])}),n=e.on(`provider.models`,e=>{let t=e.payload;u(e=>({...e,[t.provider]:t.models}))});return()=>{t(),n()}},[f]),(0,B.useEffect)(()=>{e&&(r(``),a(0),g(),requestAnimationFrame(()=>d.current?.focus()))},[e,g]),(0,B.useEffect)(()=>{if(e)for(let e of o)l[e.id]||_(e.id)},[e,o,l,_]);let y=(0,B.useMemo)(()=>os(o,l,n,p,m),[o,l,n,p,m]);(0,B.useEffect)(()=>{i>=y.length&&a(0)},[y.length,i]);let b=e=>{let n=y[e];n&&(v(n.provider,n.model),t(!1))};return e?(0,X.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-start justify-center bg-background/60 backdrop-blur-sm pt-[15vh]`,onClick:e=>{e.target===e.currentTarget&&t(!1)},onKeyDown:e=>{e.key===`Escape`&&t(!1)},children:(0,X.jsxs)(`div`,{className:`w-full max-w-xl rounded-xl border bg-popover shadow-2xl overflow-hidden`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 border-b px-3 py-2`,children:[(0,X.jsx)(wn,{className:`h-4 w-4 text-muted-foreground`}),(0,X.jsx)(`input`,{ref:d,value:n,onChange:e=>{r(e.target.value),a(0)},onKeyDown:e=>{e.key===`ArrowDown`?(e.preventDefault(),a(e=>Math.min(y.length-1,e+1))):e.key===`ArrowUp`?(e.preventDefault(),a(e=>Math.max(0,e-1))):e.key===`Enter`?(e.preventDefault(),b(i)):e.key===`Escape`&&(e.preventDefault(),t(!1))},placeholder:`Filter providers and models…`,className:`flex-1 bg-transparent outline-none text-sm placeholder:text-muted-foreground`}),(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground font-mono`,children:`↑↓ · Enter · Esc`})]}),(0,X.jsx)(`div`,{className:`max-h-[50vh] overflow-y-auto py-1`,children:y.length===0?(0,X.jsx)(`div`,{className:`px-4 py-8 text-center text-sm text-muted-foreground`,children:o.length===0?`No saved providers — register a key in Settings first.`:`Loading models…`}):y.map((e,t)=>(0,X.jsxs)(`button`,{type:`button`,onClick:()=>b(t),onMouseEnter:()=>a(t),className:Y(`w-full flex items-center gap-3 px-3 py-2 text-left text-sm transition-colors`,t===i?`bg-accent text-accent-foreground`:`hover:bg-accent/40`,e.isCurrent&&`font-medium`),children:[(0,X.jsx)(c,{className:Y(`h-4 w-4 shrink-0`,e.isCurrent?`text-primary`:`text-muted-foreground`)}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`truncate`,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:e.provider}),(0,X.jsx)(`span`,{className:`mx-1 text-muted-foreground/40`,children:`·`}),(0,X.jsx)(`span`,{children:e.modelName})]}),e.contextWindow&&(0,X.jsxs)(`div`,{className:`text-[10px] text-muted-foreground font-mono`,children:[e.model,` · ctx `,e.contextWindow.toLocaleString()]})]}),e.isCurrent?(0,X.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-primary font-semibold`,children:`active`}):(0,X.jsx)(ln,{className:`h-3.5 w-3.5 text-muted-foreground opacity-0 group-hover:opacity-100`})]},`${e.provider}:${e.model}`))})]})}):null}var cs=B.forwardRef(({className:e,type:t,...n},r)=>(0,X.jsx)(`input`,{type:t,className:Y(`flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,e),ref:r,...n}));cs.displayName=`Input`;var ls=B.forwardRef(({className:e,children:t,...n},r)=>(0,X.jsxs)(g,{ref:r,className:Y(`relative overflow-hidden`,e),...n,children:[(0,X.jsx)(At,{className:`h-full w-full rounded-[inherit]`,children:t}),(0,X.jsx)(us,{}),(0,X.jsx)(we,{})]}));ls.displayName=g.displayName;var us=B.forwardRef(({className:e,orientation:t=`vertical`,...n},r)=>(0,X.jsx)(p,{ref:r,orientation:t,className:Y(`flex touch-none select-none transition-colors`,t===`vertical`&&`h-full w-2.5 border-l border-l-transparent p-[1px]`,t===`horizontal`&&`h-2.5 flex-col border-t border-t-transparent p-[1px]`,e),...n,children:(0,X.jsx)(de,{className:`relative flex-1 rounded-full bg-border`})}));us.displayName=p.displayName;var ds=u,fs=B.forwardRef(({className:e,...t},n)=>(0,X.jsx)(Se,{ref:n,className:Y(`inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground`,e),...t}));fs.displayName=Se.displayName;var ps=B.forwardRef(({className:e,...t},n)=>(0,X.jsx)(Sn,{ref:n,className:Y(`inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow-sm`,e),...t}));ps.displayName=Sn.displayName;var ms=B.forwardRef(({className:e,...t},n)=>(0,X.jsx)(Tn,{ref:n,className:Y(`mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2`,e),...t}));ms.displayName=Tn.displayName;function hs({label:e,hint:t,selector:n,onChange:r,configKey:i,value:a}){let o=typeof a==`boolean`,s=G(e=>n?n(e):!1),c=U(e=>i?e[i]:!1),l=o?a:n?s:c;return(0,X.jsxs)(`div`,{className:`flex items-start justify-between gap-3 py-2`,children:[(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`div`,{className:`text-sm font-medium`,children:e}),t&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:t})]}),(0,X.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":l,onClick:()=>{if(o)r?.();else if(n)r?.();else if(i===`soundOnComplete`){let e=!U.getState().soundOnComplete;U.getState().setSoundOnComplete(e),e&&kr()}},className:Y(`shrink-0 relative inline-flex h-5 w-9 rounded-full border transition-colors`,l?`bg-primary border-primary`:`bg-muted border-input hover:bg-muted/80`),children:(0,X.jsx)(`span`,{className:Y(`absolute top-0.5 left-0.5 h-3.5 w-3.5 rounded-full bg-background shadow transition-transform`,l&&`translate-x-4`)})})]})}function gs({label:e,hint:t,value:n,min:r,max:i,step:a=1,onChange:o,unit:s}){return(0,X.jsxs)(`div`,{className:`flex items-start justify-between gap-3 py-2`,children:[(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`div`,{className:`text-sm font-medium`,children:e}),t&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:t})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,X.jsx)(`input`,{type:`range`,min:r,max:i,step:a,value:n,onChange:e=>o(Number(e.target.value)),className:`w-24 h-1.5 accent-primary`}),(0,X.jsxs)(`span`,{className:`text-xs tabular-nums w-10 text-right text-muted-foreground`,children:[n,s??``]})]})]})}function _s({label:e,hint:t,value:n,options:r,onChange:i}){return(0,X.jsxs)(`div`,{className:`flex items-start justify-between gap-3 py-2`,children:[(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`div`,{className:`text-sm font-medium`,children:e}),t&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:t})]}),(0,X.jsx)(`select`,{value:n,onChange:e=>i(e.target.value),className:`shrink-0 h-8 rounded-md border bg-background px-2 text-xs`,children:r.map(e=>(0,X.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})}var vs=[`anthropic`,`openai`,`google`,`openai-compatible`];function ys({activeProvider:e,catalogProviders:t,isLoadingCatalog:n,savedProviders:r,isLoadingSaved:i,providerTab:a,setProviderTab:o,onSelectProvider:s,onAddKey:c,onDeleteKey:l,onSetActiveKey:u,onAddProvider:d,onRemoveProvider:f,catalogQuery:p,setCatalogQuery:m}){let[h,g]=(0,B.useState)(null),[_,v]=(0,B.useState)(``),[y,b]=(0,B.useState)(``),[x,S]=(0,B.useState)(!1),[C,w]=(0,B.useState)(!1),[T,E]=(0,B.useState)(``),[D,O]=(0,B.useState)(`openai-compatible`),[k,A]=(0,B.useState)(``),[j,ee]=(0,B.useState)(``),M=(0,B.useCallback)(e=>{!_.trim()||!y.trim()||(c(e,_.trim(),y.trim()),v(``),b(``),g(null))},[c,_,y]),te=(0,B.useCallback)(()=>{T.trim()&&(d(T.trim(),D,k||void 0,j||void 0),E(``),O(`openai-compatible`),A(``),ee(``),w(!1))},[d,T,D,k,j]),N=p.trim()?t.filter(e=>{let t=p.trim().toLowerCase();return e.id.toLowerCase().includes(t)||e.name.toLowerCase().includes(t)||e.family.toLowerCase().includes(t)}):t,ne=N.reduce((e,t)=>(e[t.family]||(e[t.family]=[]),e[t.family]?.push(t),e),{});return(0,X.jsxs)(`div`,{className:`space-y-4`,children:[(0,X.jsxs)(`div`,{className:`flex gap-2 mb-4`,children:[(0,X.jsxs)($,{variant:a===`catalog`?`default`:`outline`,size:`sm`,onClick:()=>o(`catalog`),children:[(0,X.jsx)(st,{className:`h-4 w-4 mr-1`}),`Catalog`]}),(0,X.jsxs)($,{variant:a===`saved`?`default`:`outline`,size:`sm`,onClick:()=>o(`saved`),children:[(0,X.jsx)(Kt,{className:`h-4 w-4 mr-1`}),`Saved (`,r.length,`)`]})]}),a===`catalog`&&(0,X.jsxs)(`div`,{className:`space-y-4`,children:[(0,X.jsx)(cs,{placeholder:`Search ${t.length} providers (name / id / family)…`,value:p,onChange:e=>m(e.target.value),className:`text-sm`}),n&&t.length===0?(0,X.jsxs)(`div`,{className:`flex items-center justify-center py-8`,children:[(0,X.jsx)(L,{className:`h-6 w-6 animate-spin text-muted-foreground`}),(0,X.jsx)(`span`,{className:`ml-2 text-muted-foreground`,children:`Loading catalog...`})]}):N.length===0&&p?(0,X.jsxs)(`div`,{className:`text-center py-8 text-muted-foreground text-sm`,children:[`No providers match "`,(0,X.jsx)(`span`,{className:`font-mono`,children:p}),`".`]}):(0,X.jsx)(X.Fragment,{children:vs.map(t=>{let n=ne[t];return n?.length?(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(`h3`,{className:`text-sm font-semibold text-muted-foreground uppercase tracking-wider`,children:t}),(0,X.jsx)(`div`,{className:`grid grid-cols-1 gap-2`,children:n.map(t=>(0,X.jsxs)(`button`,{type:`button`,onClick:()=>s(t.id),className:Y(`flex flex-col items-start p-3 rounded-lg border text-left transition-all`,e===t.id?`border-primary bg-primary/5 ring-2 ring-primary/20`:`border-border hover:bg-muted`),children:[(0,X.jsxs)(`div`,{className:`flex w-full justify-between items-start`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`span`,{className:`font-medium`,children:t.name}),(0,X.jsxs)(`span`,{className:`ml-2 text-xs text-muted-foreground`,children:[`(`,t.id,`)`]})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[t.hasApiKey&&(0,X.jsxs)(`span`,{className:`text-xs bg-green-500/10 text-green-600 px-2 py-0.5 rounded`,children:[(0,X.jsx)(Kt,{className:`h-3 w-3 inline mr-1`}),`Configured`]}),t.envVars[0]&&(0,X.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`ENV: `,t.envVars[0]]}),e===t.id&&(0,X.jsx)(Be,{className:`h-4 w-4 text-primary`})]})]}),(0,X.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-1`,children:[t.modelCount,` models`,t.apiBase&&` · ${t.apiBase}`]})]},t.id))})]},t):null})})]}),a===`saved`&&(0,X.jsxs)(`div`,{className:`space-y-4`,children:[(0,X.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Manage your API keys and provider configurations`}),(0,X.jsxs)($,{size:`sm`,variant:`outline`,onClick:()=>w(!C),children:[(0,X.jsx)(kt,{className:`h-4 w-4 mr-1`}),`Add Provider`]})]}),C&&(0,X.jsxs)(`div`,{className:`p-4 border rounded-lg space-y-3 bg-muted/50`,children:[(0,X.jsx)(`h4`,{className:`font-medium`,children:`Add Custom Provider`}),(0,X.jsx)(cs,{placeholder:`Provider ID (e.g. my-llm-server)`,value:T,onChange:e=>E(e.target.value)}),(0,X.jsxs)(`select`,{className:`flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm`,value:D,onChange:e=>O(e.target.value),children:[(0,X.jsx)(`option`,{value:`anthropic`,children:`Anthropic`}),(0,X.jsx)(`option`,{value:`openai`,children:`OpenAI`}),(0,X.jsx)(`option`,{value:`openai-compatible`,children:`OpenAI Compatible`}),(0,X.jsx)(`option`,{value:`google`,children:`Google`})]}),(0,X.jsx)(cs,{placeholder:`Base URL (optional, e.g. http://localhost:11434/v1)`,value:k,onChange:e=>A(e.target.value)}),(0,X.jsx)(cs,{type:`password`,placeholder:`API Key (optional)`,value:j,onChange:e=>ee(e.target.value)}),(0,X.jsxs)(`div`,{className:`flex gap-2`,children:[(0,X.jsx)($,{size:`sm`,onClick:te,disabled:!T.trim(),children:`Add`}),(0,X.jsx)($,{size:`sm`,variant:`ghost`,onClick:()=>w(!1),children:`Cancel`})]})]}),i?(0,X.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,X.jsx)(L,{className:`h-6 w-6 animate-spin text-muted-foreground`})}):r.length===0?(0,X.jsxs)(`div`,{className:`text-center py-8 text-muted-foreground`,children:[(0,X.jsx)(Kt,{className:`h-8 w-8 mx-auto mb-2 opacity-50`}),(0,X.jsx)(`p`,{children:`No saved providers yet`}),(0,X.jsx)(`p`,{className:`text-sm`,children:`Add a provider to get started`})]}):r.map(e=>(0,X.jsxs)(`div`,{className:`border rounded-lg p-4 space-y-3`,children:[(0,X.jsxs)(`div`,{className:`flex justify-between items-start`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h4`,{className:`font-medium`,children:e.id}),e.family&&(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e.family})]}),(0,X.jsx)(`div`,{className:`flex gap-2`,children:(0,X.jsx)($,{size:`icon`,variant:`ghost`,onClick:()=>f(e.id),children:(0,X.jsx)(at,{className:`h-4 w-4 text-destructive`})})})]}),e.baseUrl&&(0,X.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[(0,X.jsx)(st,{className:`h-3 w-3 inline mr-1`}),e.baseUrl]}),(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,X.jsx)(`span`,{className:`text-sm font-medium`,children:`API Keys`}),(0,X.jsxs)($,{size:`sm`,variant:`ghost`,onClick:()=>g(h===e.id?null:e.id),children:[(0,X.jsx)(kt,{className:`h-3 w-3 mr-1`}),`Add Key`]})]}),e.apiKeys.length===0&&!h&&(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`No keys configured`}),e.apiKeys.map(t=>(0,X.jsxs)(`div`,{className:`flex items-center justify-between p-2 bg-muted/50 rounded`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`span`,{className:`text-sm font-medium`,children:t.label}),t.isActive&&(0,X.jsx)(`span`,{className:`ml-2 text-xs bg-green-500/10 text-green-600 px-1.5 py-0.5 rounded`,children:`Active`}),(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground font-mono`,children:t.maskedKey})]}),(0,X.jsxs)(`div`,{className:`flex gap-1`,children:[!t.isActive&&(0,X.jsx)($,{size:`sm`,variant:`ghost`,onClick:()=>u(e.id,t.label),children:`Set Active`}),(0,X.jsx)($,{size:`icon`,variant:`ghost`,onClick:()=>l(e.id,t.label),children:(0,X.jsx)(at,{className:`h-3 w-3 text-destructive`})})]})]},t.label)),h===e.id&&(0,X.jsxs)(`div`,{className:`p-3 border rounded space-y-2 bg-background`,children:[(0,X.jsx)(cs,{placeholder:`Key label (e.g. default, production)`,value:_,onChange:e=>v(e.target.value)}),(0,X.jsxs)(`div`,{className:`flex gap-2`,children:[(0,X.jsx)(cs,{type:x?`text`:`password`,placeholder:`API key`,value:y,onChange:e=>b(e.target.value)}),(0,X.jsx)($,{size:`icon`,variant:`ghost`,onClick:()=>S(!x),children:x?(0,X.jsx)(se,{className:`h-4 w-4`}):(0,X.jsx)(Ot,{className:`h-4 w-4`})})]}),(0,X.jsxs)(`div`,{className:`flex gap-2`,children:[(0,X.jsx)($,{size:`sm`,onClick:()=>M(e.id),disabled:!_.trim()||!y.trim(),children:`Save Key`}),(0,X.jsx)($,{size:`sm`,variant:`ghost`,onClick:()=>{g(null),v(``),b(``)},children:`Cancel`})]})]})]})]},e.id))]})]})}function bs({provider:e,catalogModels:t,currentCatalogProvider:n,isLoadingModels:r,setIsLoadingModels:i,onModelSelect:a,refreshModels:o}){let s=U(e=>e.model);return(0,X.jsx)(`div`,{className:`space-y-4`,children:e?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`p`,{className:`text-sm font-medium`,children:n?.name||e}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e})]}),(0,X.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>{i(!0),o(e)},children:(0,X.jsx)(Mt,{className:Y(`h-4 w-4`,r&&`animate-spin`)})})]}),r&&!t[e]?(0,X.jsxs)(`div`,{className:`flex items-center justify-center py-8`,children:[(0,X.jsx)(L,{className:`h-6 w-6 animate-spin text-muted-foreground`}),(0,X.jsx)(`span`,{className:`ml-2 text-muted-foreground`,children:`Loading models...`})]}):(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(t[e]||[]).map(e=>(0,X.jsxs)(`button`,{type:`button`,onClick:()=>a(e.id),className:Y(`w-full flex items-center justify-between p-3 rounded-lg border text-left transition-all`,s===e.id?`border-primary bg-primary/5 ring-2 ring-primary/20`:`border-border hover:bg-muted`),children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`span`,{className:`font-medium`,children:e.name||e.id}),(0,X.jsx)(`div`,{className:`flex gap-2 mt-1`,children:e.capabilities.map(e=>(0,X.jsx)(`span`,{className:`text-xs bg-muted px-1.5 py-0.5 rounded`,children:e},e))})]}),(0,X.jsxs)(`div`,{className:`text-right text-xs text-muted-foreground`,children:[e.contextWindow&&(0,X.jsxs)(`div`,{children:[e.contextWindow/1e3,`k context`]}),e.inputCost&&e.outputCost&&(0,X.jsxs)(`div`,{children:[`$`,e.inputCost,`/$`,e.outputCost]}),s===e.id&&(0,X.jsx)(Be,{className:`h-4 w-4 text-primary mt-1`})]})]},e.id)),t[e]?.length===0&&(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground text-center py-4`,children:`No models found for this provider. The catalog might be empty or still loading.`})]})]}):(0,X.jsxs)(`div`,{className:`text-center py-8 text-muted-foreground`,children:[(0,X.jsx)(c,{className:`h-8 w-8 mx-auto mb-2 opacity-50`}),(0,X.jsx)(`p`,{children:`Select a provider first`})]})})}function xs(){let{setCurrentView:e}=G(),{provider:t,model:n,setProvider:r,setModel:i,wsConnected:a}=U(),{theme:s,setTheme:u}=Ti(),d=Z(),f=d.client,{updatePrefs:p,switchAutonomy:m}=d,h=hr(),g=(0,B.useCallback)((e,t)=>{h.set({[e]:t}),p({[e]:t})},[h,p]),[_,v]=(0,B.useState)([]),[y,b]=(0,B.useState)({}),[x,S]=(0,B.useState)([]),[C,w]=(0,B.useState)(!1),[T,E]=(0,B.useState)(!1),[D,O]=(0,B.useState)(!1),[k,A]=(0,B.useState)(`catalog`),[j,ee]=(0,B.useState)(``),M=_.find(e=>e.id===t);(0,B.useEffect)(()=>{let e=e=>{if(e.type===`provider.catalog`){let t=e.payload;v(t.providers.sort((e,t)=>e.id.localeCompare(t.id))),w(!1)}},t=e=>{if(e.type===`provider.models`){let t=e.payload;b(e=>({...e,[t.provider]:t.models})),E(!1)}},n=e=>{if(e.type===`providers.saved`){let t=e.payload.providers.sort((e,t)=>e.id.localeCompare(t.id));S(t),O(!1),t.length>0&&A(`saved`)}};if(!a||!f)return;let r=f.on(`provider.catalog`,e),i=f.on(`provider.models`,t),o=f.on(`providers.saved`,n);return w(!0),O(!0),f.listProviders(),f.listSavedProviders(),()=>{r?.(),i?.(),o?.()}},[a,f]);let te=(0,B.useCallback)(e=>{r(e),y[e]||(E(!0),d.listProviderModels?.(e))},[y,r,d]),N=(0,B.useCallback)(e=>{i(e);let t=U.getState().provider;d.switchModel?.(t,e),Sr.success(`Switching to ${t} / ${e}…`)},[i,d]),ne=(0,B.useCallback)((e,t,n)=>{d.addKey?.(e,t,n)},[d]),re=(0,B.useCallback)((e,t)=>{d.deleteKey?.(e,t)},[d]),ie=(0,B.useCallback)((e,t)=>{d.setActiveKey?.(e,t)},[d]),ae=(0,B.useCallback)((e,t,n,r)=>{d.addProvider?.(e,t,n,r)},[d]),oe=(0,B.useCallback)(e=>{d.removeProvider?.(e)},[d]);return(0,X.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,X.jsxs)(`header`,{className:`flex items-center justify-between px-4 py-3 border-b bg-card shrink-0`,children:[(0,X.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Settings`}),(0,X.jsx)($,{variant:`ghost`,size:`icon`,onClick:()=>e(`chat`),children:(0,X.jsx)(Ie,{className:`h-4 w-4`})})]}),(0,X.jsx)(ls,{className:`flex-1`,children:(0,X.jsx)(`div`,{className:`p-6 max-w-2xl mx-auto`,children:(0,X.jsxs)(ds,{defaultValue:`provider`,children:[(0,X.jsxs)(fs,{className:`w-full justify-start mb-6 grid grid-cols-5`,children:[(0,X.jsxs)(ps,{value:`provider`,className:`gap-1 text-xs`,children:[(0,X.jsx)(Me,{className:`h-3.5 w-3.5`}),`Provider`]}),(0,X.jsxs)(ps,{value:`connection`,className:`gap-1 text-xs`,children:[(0,X.jsx)(st,{className:`h-3.5 w-3.5`}),`Connect`]}),(0,X.jsxs)(ps,{value:`appearance`,className:`gap-1 text-xs`,children:[(0,X.jsx)(l,{className:`h-3.5 w-3.5`}),`Look`]}),(0,X.jsxs)(ps,{value:`agent`,className:`gap-1 text-xs`,children:[(0,X.jsx)(R,{className:`h-3.5 w-3.5`}),`Agent`]}),(0,X.jsxs)(ps,{value:`features`,className:`gap-1 text-xs`,children:[(0,X.jsx)(o,{className:`h-3.5 w-3.5`}),`Feat.`]})]}),(0,X.jsxs)(ms,{value:`provider`,className:`space-y-4`,children:[(0,X.jsx)(ys,{activeProvider:t,catalogProviders:_,isLoadingCatalog:C,savedProviders:x,isLoadingSaved:D,providerTab:k,setProviderTab:A,onSelectProvider:te,onAddKey:ne,onDeleteKey:re,onSetActiveKey:ie,onAddProvider:ae,onRemoveProvider:oe,catalogQuery:j,setCatalogQuery:ee}),(0,X.jsxs)(`div`,{className:`pt-4 border-t`,children:[(0,X.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 flex items-center gap-2`,children:[(0,X.jsx)(c,{className:`h-4 w-4 text-muted-foreground`}),`Model`]}),(0,X.jsx)(bs,{provider:t,catalogModels:y,currentCatalogProvider:M,isLoadingModels:T,setIsLoadingModels:E,onModelSelect:N,refreshModels:e=>d.listProviderModels?.(e)})]})]}),(0,X.jsxs)(ms,{value:`connection`,className:`space-y-4`,children:[(0,X.jsxs)(`div`,{className:`space-y-3`,children:[(0,X.jsxs)(`label`,{htmlFor:`websocket-url`,className:`text-sm font-medium flex items-center gap-2`,children:[(0,X.jsx)(st,{className:`h-4 w-4 text-muted-foreground`}),`WebSocket Server URL`]}),(0,X.jsx)(cs,{id:`websocket-url`,value:U.getState().wsUrl,onChange:e=>U.getState().setConfig({wsUrl:e.target.value}),placeholder:`ws://localhost:3457`,className:`font-mono text-sm`}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`URL of the agent WebSocket server. The server runs alongside the CLI.`})]}),(0,X.jsxs)(`div`,{className:`p-4 rounded-lg border bg-muted/50`,children:[(0,X.jsx)(`h4`,{className:`text-sm font-medium mb-2`,children:`Starting the WebSocket Server`}),(0,X.jsxs)(`p`,{className:`text-xs text-muted-foreground mb-3`,children:[`Standalone: run `,(0,X.jsx)(`code`,{className:`bg-muted px-1 py-0.5 rounded`,children:`./dev.ps1`}),` `,`from the repo root, or set WS_HOST/WS_PORT before launching`,` `,(0,X.jsx)(`code`,{className:`bg-muted px-1 py-0.5 rounded`,children:`node packages/webui/dist/server/entry.js`}),`. Or alongside the CLI:`,` `,(0,X.jsx)(`code`,{className:`bg-muted px-1 py-0.5 rounded`,children:`wstack --webui`}),`.`]})]})]}),(0,X.jsxs)(ms,{value:`appearance`,className:`space-y-4`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h3`,{className:`text-sm font-semibold mb-3`,children:`Theme`}),(0,X.jsxs)(`div`,{className:`grid grid-cols-3 gap-2 max-w-md`,children:[(0,X.jsxs)($,{variant:s===`light`?`default`:`outline`,size:`sm`,onClick:()=>u(`light`),children:[(0,X.jsx)(ht,{className:`h-4 w-4 mr-1`}),`Light`]}),(0,X.jsxs)($,{variant:s===`dark`?`default`:`outline`,size:`sm`,onClick:()=>u(`dark`),children:[(0,X.jsx)(ke,{className:`h-4 w-4 mr-1`}),`Dark`]}),(0,X.jsxs)($,{variant:s===`system`?`default`:`outline`,size:`sm`,onClick:()=>u(`system`),children:[(0,X.jsx)(Fe,{className:`h-4 w-4 mr-1`}),`System`]})]}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground mt-2`,children:`System follows your OS-level light/dark preference.`})]}),(0,X.jsxs)(`div`,{className:`pt-2 border-t`,children:[(0,X.jsx)(`h3`,{className:`text-sm font-semibold mb-3 mt-3`,children:`Preferences`}),(0,X.jsx)(hs,{label:`Compact density`,hint:`Tighter spacing throughout the chat.`,selector:e=>e.compactMode,onChange:()=>G.getState().toggleCompactMode()}),(0,X.jsx)(hs,{label:`Sound on completion`,hint:`Play a soft chime when a run finishes.`,selector:null,configKey:`soundOnComplete`})]})]}),(0,X.jsxs)(ms,{value:`agent`,className:`space-y-4`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 flex items-center gap-2`,children:[(0,X.jsx)(ct,{className:`h-4 w-4 text-muted-foreground`}),`Autonomy & Behavior`]}),(0,X.jsx)(_s,{label:`Autonomy mode`,hint:`How independently the agent proceeds between turns.`,value:h.autonomy,options:[{value:`off`,label:`Off — full manual control`},{value:`suggest`,label:`Suggest — suggests next steps`},{value:`auto`,label:`Auto — brief confirmation delay`},{value:`eternal`,label:`Eternal — autonomous until goal done`},{value:`eternal-parallel`,label:`Eternal Parallel — multi-agent fleet`}],onChange:e=>{h.set({autonomy:e}),m(e)}}),(0,X.jsx)(gs,{label:`Auto-proceed delay`,hint:`Milliseconds before the agent auto-proceeds in Auto mode. 0 = immediate.`,value:h.autonomyDelayMs,min:0,max:1e4,step:500,unit:`ms`,onChange:e=>g(`autonomyDelayMs`,e)}),(0,X.jsx)(hs,{label:`YOLO mode`,hint:`Bypass tool confirmation prompts — the agent runs without asking.`,value:h.yolo,onChange:()=>g(`yolo`,!h.yolo)})]}),(0,X.jsxs)(`div`,{className:`pt-2 border-t`,children:[(0,X.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 mt-3 flex items-center gap-2`,children:[(0,X.jsx)(ze,{className:`h-4 w-4 text-muted-foreground`}),`Prompt Refinement`]}),(0,X.jsx)(hs,{label:`Enable refine`,hint:`Rewrite prompts before sending — clearer instructions, better results.`,value:h.enhanceEnabled,onChange:()=>g(`enhanceEnabled`,!h.enhanceEnabled)}),(0,X.jsx)(gs,{label:`Refine delay`,hint:`Countdown before the refined prompt auto-sends.`,value:h.enhanceDelayMs,min:3e4,max:12e4,step:15e3,unit:`ms`,onChange:e=>g(`enhanceDelayMs`,e)}),(0,X.jsx)(_s,{label:`Refine language`,hint:`Keep your language or translate to English for the model.`,value:h.enhanceLanguage,options:[{value:`original`,label:`Original — keep your language`},{value:`english`,label:`English — translate to English`}],onChange:e=>g(`enhanceLanguage`,e)})]}),(0,X.jsxs)(`div`,{className:`pt-2 border-t`,children:[(0,X.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 mt-3 flex items-center gap-2`,children:[(0,X.jsx)(ze,{className:`h-4 w-4 text-muted-foreground`}),`Execution`]}),(0,X.jsx)(gs,{label:`Max iterations per run`,hint:`Hard cap on LLM turns per agent.run().`,value:h.maxIterations,min:10,max:2e3,step:10,onChange:e=>g(`maxIterations`,e)}),(0,X.jsx)(gs,{label:`Auto-proceed max iterations`,hint:`Stop auto-proceed after N iterations. 0 = unlimited.`,value:h.autoProceedMaxIterations,min:0,max:250,step:5,onChange:e=>g(`autoProceedMaxIterations`,e)}),(0,X.jsx)(hs,{label:`Confirm before exit`,hint:`First Ctrl+C aborts work, second confirms exit.`,value:h.confirmExit,onChange:()=>g(`confirmExit`,!h.confirmExit)}),(0,X.jsx)(hs,{label:`Chime on completion`,hint:`Terminal bell when an agent run finishes.`,value:h.chime,onChange:()=>g(`chime`,!h.chime)})]}),(0,X.jsxs)(`div`,{className:`pt-2 border-t`,children:[(0,X.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 mt-3 flex items-center gap-2`,children:[(0,X.jsx)(Tt,{className:`h-4 w-4 text-muted-foreground`}),`Fleet & Streaming`]}),(0,X.jsx)(hs,{label:`Stream fleet events`,hint:`Show live subagent activity in the fleet panel.`,value:h.streamFleet,onChange:()=>g(`streamFleet`,!h.streamFleet)}),(0,X.jsx)(hs,{label:`Next-step prediction`,hint:`After a turn completes, predict likely next steps.`,value:h.nextPrediction,onChange:()=>g(`nextPrediction`,!h.nextPrediction)})]})]}),(0,X.jsxs)(ms,{value:`features`,className:`space-y-4`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 flex items-center gap-2`,children:[(0,X.jsx)(o,{className:`h-4 w-4 text-muted-foreground`}),`Feature Flags`]}),(0,X.jsx)(hs,{label:`MCP servers`,hint:`Enable Model Context Protocol integrations.`,value:h.featureMcp,onChange:()=>g(`featureMcp`,!h.featureMcp)}),(0,X.jsx)(hs,{label:`Plugins`,hint:`Load and run user-installed plugins.`,value:h.featurePlugins,onChange:()=>g(`featurePlugins`,!h.featurePlugins)}),(0,X.jsx)(hs,{label:`Memory`,hint:`Persist and recall facts across sessions.`,value:h.featureMemory,onChange:()=>g(`featureMemory`,!h.featureMemory)}),(0,X.jsx)(hs,{label:`Skills`,hint:`Load domain-specific skill prompts.`,value:h.featureSkills,onChange:()=>g(`featureSkills`,!h.featureSkills)}),(0,X.jsx)(hs,{label:`Models registry`,hint:`Use the models.dev catalog for provider discovery.`,value:h.featureModelsRegistry,onChange:()=>g(`featureModelsRegistry`,!h.featureModelsRegistry)}),(0,X.jsx)(hs,{label:`Index on start`,hint:`Build the codebase symbol index at session start.`,value:h.indexOnStart,onChange:()=>g(`indexOnStart`,!h.indexOnStart)})]}),(0,X.jsxs)(`div`,{className:`pt-2 border-t`,children:[(0,X.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 mt-3 flex items-center gap-2`,children:[(0,X.jsx)(tt,{className:`h-4 w-4 text-muted-foreground`}),`Context & Debug`]}),(0,X.jsx)(hs,{label:`Auto-compact context`,hint:`Automatically trim the context window when near limits.`,value:h.contextAutoCompact,onChange:()=>g(`contextAutoCompact`,!h.contextAutoCompact)}),(0,X.jsx)(_s,{label:`Compactor strategy`,hint:`How the context is compacted when it grows too large.`,value:h.contextStrategy,options:[{value:`hybrid`,label:`Hybrid — fast rules (default)`},{value:`intelligent`,label:`Intelligent — LLM summarization`},{value:`selective`,label:`Selective — LLM-driven selection`}],onChange:e=>g(`contextStrategy`,e)}),(0,X.jsx)(_s,{label:`Log level`,hint:`Minimum severity for server-side logging.`,value:h.logLevel,options:[{value:`debug`,label:`Debug — everything`},{value:`info`,label:`Info — normal flow`},{value:`warn`,label:`Warn — problems only`},{value:`error`,label:`Error — failures only`}],onChange:e=>g(`logLevel`,e)}),(0,X.jsx)(_s,{label:`Audit level`,hint:`Detail level for session audit logs.`,value:h.auditLevel,options:[{value:`minimal`,label:`Minimal — errors only`},{value:`standard`,label:`Standard — tool calls + errors`},{value:`full`,label:`Full — every event (large logs)`}],onChange:e=>g(`auditLevel`,e)})]})]})]})})})]})}function Ss({provider:e,isSelected:t,onSelect:n}){return(0,X.jsx)(`button`,{type:`button`,onClick:n,className:Y(`w-full text-left rounded-xl border p-4 transition-all`,`hover:border-primary/40 hover:bg-primary/5`,t?`border-primary bg-primary/10 ring-1 ring-primary/30`:`border-border bg-card`),children:(0,X.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,X.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`span`,{className:`font-semibold text-sm`,children:e.name}),e.hasApiKey&&(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded-full bg-emerald-500/10 text-emerald-600 dark:text-emerald-400 border border-emerald-500/20`,children:[(0,X.jsx)(pn,{className:`h-2.5 w-2.5`}),`Key set`]})]}),(0,X.jsxs)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:[e.family,` · `,e.modelCount,` models`]})]}),t&&(0,X.jsx)(`div`,{className:`w-5 h-5 rounded-full bg-primary flex items-center justify-center shrink-0`,children:(0,X.jsx)(pn,{className:`h-3 h-3 text-primary-foreground`})})]})})}function Cs({model:e,isSelected:t,onSelect:n}){let r=e.inputCost==null?null:`$${e.inputCost}/1M tok`,i=e.outputCost==null?null:`$${e.outputCost}/1M tok`,a=e.contextWindow?`${(e.contextWindow/1e6).toFixed(0)}M ctx`:null;return(0,X.jsx)(`button`,{type:`button`,onClick:n,className:Y(`w-full text-left rounded-xl border p-3 transition-all`,`hover:border-primary/40 hover:bg-primary/5`,t?`border-primary bg-primary/10 ring-1 ring-primary/30`:`border-border bg-card`),children:(0,X.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,X.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,X.jsx)(`span`,{className:`font-medium text-sm`,children:e.name}),(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 mt-1`,children:[a&&(0,X.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:a}),r&&i&&(0,X.jsxs)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:[r,` · `,i]}),e.capabilities.slice(0,3).map(e=>(0,X.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-primary/10 text-primary border border-primary/20`,children:e},e))]})]}),t&&(0,X.jsx)(`div`,{className:`w-5 h-5 rounded-full bg-primary flex items-center justify-center shrink-0`,children:(0,X.jsx)(pn,{className:`h-3 w-3 text-primary-foreground`})})]})})}function ws({providerId:e,onSave:t}){let[n,r]=(0,B.useState)(``),[i,a]=(0,B.useState)(`default`),[o,s]=(0,B.useState)(!1);return(0,X.jsxs)(`div`,{className:`space-y-3 p-4 rounded-xl border border-amber-500/30 bg-amber-500/5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-amber-600 dark:text-amber-400`,children:[(0,X.jsx)(cn,{className:`h-4 w-4`}),(0,X.jsx)(`span`,{className:`text-sm font-medium`,children:`API Key required`})]}),(0,X.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Enter your API key for `,e,`. The key is stored locally and never sent to any server other than the provider's API endpoint.`]}),(0,X.jsxs)(`div`,{className:`flex gap-2`,children:[(0,X.jsx)(cs,{type:`password`,placeholder:`sk-...`,value:n,onChange:e=>r(e.target.value),className:`font-mono text-sm`}),(0,X.jsx)(cs,{placeholder:`Label (optional)`,value:i,onChange:e=>a(e.target.value),className:`w-28 text-sm`})]}),(0,X.jsx)($,{onClick:async()=>{if(n.trim()){s(!0);try{V(U.getState().wsUrl).addKey(e,i.trim()||`default`,n.trim()),t(n.trim()),r(``),Sr.success(`API key saved`)}catch{Sr.error(`Failed to save API key`)}finally{s(!1)}}},disabled:!n.trim()||o,size:`sm`,children:o?(0,X.jsx)(L,{className:`h-4 w-4 animate-spin`}):`Save Key`})]})}function Ts(){let{setCurrentView:e}=G(),{provider:t,model:r,setProvider:i,setModel:a,wsConnected:o,wsUrl:s}=U();Z();let[l,u]=(0,B.useState)(`provider`),[d,f]=(0,B.useState)([]),[p,m]=(0,B.useState)({}),[h,g]=(0,B.useState)([]),[_,v]=(0,B.useState)(!1),[y,b]=(0,B.useState)(!1),[x,S]=(0,B.useState)(null),[C,w]=(0,B.useState)(null);(0,B.useEffect)(()=>{if(!o)return;let e=V(s),n=e.on(`provider.catalog`,e=>{if(e.type===`provider.catalog`){let n=e.payload.providers.sort((e,t)=>e.id.localeCompare(t.id));f(n),v(!1),t&&n.some(e=>e.id===t)?S(t):n.length===1&&S(n[0].id)}}),i=e.on(`provider.models`,e=>{if(e.type===`provider.models`){let t=e.payload;m(e=>({...e,[t.provider]:t.models})),b(!1),t.models.length===1?w(t.models[0].id):r&&t.models.some(e=>e.id===r)&&w(r)}}),a=e.on(`providers.saved`,e=>{if(e.type===`providers.saved`){let t=e.payload;g(t.providers.sort((e,t)=>e.id.localeCompare(t.id)))}});return v(!0),e.listProviders(),()=>{n?.(),i?.(),a?.()}},[o,s,t,r]),(0,B.useEffect)(()=>{if(!x||!o)return;let e=V(s);p[x]||(b(!0),e.listProviderModels(x))},[x,o,s,p]);let T=d.find(e=>e.id===x),E=h.find(e=>e.id===x)?.apiKeys.some(e=>e.isActive)||T?.hasApiKey,D=(0,B.useCallback)(e=>{S(e),w(null),u(`model`)},[]),O=(0,B.useCallback)(e=>{w(e),u(E?`done`:`apikey`)},[E]),k=(0,B.useCallback)(()=>{u(`done`)},[]),A=(0,B.useCallback)(()=>{if(!x||!C)return;i(x),a(C);let t=V(s);t.switchModel(x,C);let n=null,r=()=>{n&&clearTimeout(n)},o=t.on(`key.operation_result`,n=>{let i=n.payload;r(),o(),i.success?(t.newSession(),e(`chat`)):Sr.error(i.message)});n=setTimeout(()=>{r(),o(),Sr.error(`Model switch timed out. Please try again.`)},5e3)},[x,C,i,a,s,e]),j=x?p[x]??[]:[];return(0,X.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,X.jsx)(`header`,{className:`flex items-center justify-between px-6 py-4 border-b bg-card shrink-0`,children:(0,X.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,X.jsx)(`div`,{className:`w-10 h-10 rounded-xl bg-gradient-to-br from-primary via-primary to-primary/60 flex items-center justify-center`,children:(0,X.jsx)(ze,{className:`h-5 w-5 text-primary-foreground`})}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Welcome to WrongStack`}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Configure your AI provider to get started`})]})]})}),(0,X.jsx)(ls,{className:`flex-1`,children:(0,X.jsxs)(`div`,{className:`p-6 max-w-2xl mx-auto space-y-8`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,X.jsxs)(`div`,{className:Y(`flex items-center gap-1.5`,l===`provider`&&`text-primary font-medium`),children:[(0,X.jsx)(Me,{className:`h-4 w-4`}),(0,X.jsx)(`span`,{children:`Provider`})]}),(0,X.jsx)(n,{className:`h-4 w-4 text-muted-foreground`}),(0,X.jsxs)(`div`,{className:Y(`flex items-center gap-1.5`,l===`model`&&`text-primary font-medium`),children:[(0,X.jsx)(c,{className:`h-4 w-4`}),(0,X.jsx)(`span`,{children:`Model`})]}),(0,X.jsx)(n,{className:`h-4 w-4 text-muted-foreground`}),(0,X.jsxs)(`div`,{className:Y(`flex items-center gap-1.5`,(l===`apikey`||l===`done`)&&`text-primary font-medium`),children:[(0,X.jsx)(cn,{className:`h-4 w-4`}),(0,X.jsx)(`span`,{children:`API Key`})]})]}),l===`provider`&&(0,X.jsxs)(`div`,{className:`space-y-4`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`h2`,{className:`text-base font-semibold flex items-center gap-2`,children:[(0,X.jsx)(Me,{className:`h-4 w-4 text-primary`}),`Choose a Provider`]}),(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:`Select the AI provider you want to use. You can add API keys in the next step.`})]}),_?(0,X.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,X.jsx)(L,{className:`h-6 w-6 animate-spin text-muted-foreground`})}):(0,X.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:d.map(e=>(0,X.jsx)(Ss,{provider:e,isSelected:x===e.id,onSelect:()=>D(e.id)},e.id))})]}),l===`model`&&(0,X.jsxs)(`div`,{className:`space-y-4`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`h2`,{className:`text-base font-semibold flex items-center gap-2`,children:[(0,X.jsx)(c,{className:`h-4 w-4 text-primary`}),`Choose a Model`]}),(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:T?`Models available for ${T.name}`:`Loading models...`})]}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>u(`provider`),className:`text-xs text-muted-foreground hover:text-foreground transition-colors`,children:`← Change provider`}),y?(0,X.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,X.jsx)(L,{className:`h-6 w-6 animate-spin text-muted-foreground`})}):j.length>0?(0,X.jsx)(`div`,{className:`grid grid-cols-1 gap-2`,children:j.map(e=>(0,X.jsx)(Cs,{model:e,isSelected:C===e.id,onSelect:()=>O(e.id)},e.id))}):(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground py-8 text-center`,children:`No models available. Please check your API key.`})]}),l===`apikey`&&(0,X.jsxs)(`div`,{className:`space-y-4`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`h2`,{className:`text-base font-semibold flex items-center gap-2`,children:[(0,X.jsx)(cn,{className:`h-4 w-4 text-primary`}),`Add Your API Key`]}),(0,X.jsxs)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:[T?`Enter your API key for ${T.name}. `:`Enter your API key. `,`The key is stored locally and encrypted.`]})]}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>u(`model`),className:`text-xs text-muted-foreground hover:text-foreground transition-colors`,children:`← Change model`}),x&&(0,X.jsx)(ws,{providerId:x,onSave:k})]}),l===`done`&&(0,X.jsxs)(`div`,{className:`space-y-6`,children:[(0,X.jsxs)(`div`,{className:`flex flex-col items-center text-center py-8`,children:[(0,X.jsx)(`div`,{className:`w-16 h-16 rounded-2xl bg-gradient-to-br from-emerald-500/20 to-emerald-500/5 border border-emerald-500/30 flex items-center justify-center mb-4`,children:(0,X.jsx)(pn,{className:`h-8 w-8 text-emerald-500`})}),(0,X.jsx)(`h2`,{className:`text-xl font-semibold`,children:`You're all set!`}),(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground mt-2 max-w-sm`,children:`Configuration complete. Your agent is ready to start working.`})]}),(0,X.jsxs)(`div`,{className:`rounded-xl border bg-card p-4 space-y-3`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between text-sm`,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`Provider`}),(0,X.jsx)(`span`,{className:`font-medium`,children:x})]}),(0,X.jsxs)(`div`,{className:`flex items-center justify-between text-sm`,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`Model`}),(0,X.jsx)(`span`,{className:`font-medium`,children:C})]})]}),(0,X.jsxs)($,{onClick:A,className:`w-full`,size:`lg`,children:[(0,X.jsx)(R,{className:`h-4 w-4 mr-2`}),`Start Session`,(0,X.jsx)(ln,{className:`h-4 w-4 ml-2`})]})]})]})})]})}function Es(e){switch(e){case`running`:return`▶`;case`streaming`:return`↻`;case`waiting_user`:return`⏳`;case`error`:return`✗`;case`idle`:return`■`;default:return`?`}}function Ds(e){switch(e){case`running`:return`text-emerald-400`;case`streaming`:return`text-cyan-400`;case`waiting_user`:return`text-amber-400`;case`error`:return`text-red-400`;default:return`text-slate-500`}}function Os(e){switch(e){case`active`:return`text-emerald-400`;case`idle`:return`text-cyan-400`;case`closing`:return`text-amber-400`;default:return`text-slate-500`}}function ks(e){let t=Date.now()-new Date(e).getTime(),n=Math.floor(t/6e4);if(n<1)return`<1m`;if(n<60)return`${n}m`;let r=Math.floor(n/60);return r<24?`${r}h ${n%60}m`:`${Math.floor(r/24)}d`}function As(e){let t=Date.now()-new Date(e).getTime(),n=Math.floor(t/1e3);if(n<10)return`just now`;if(n<60)return`${n}s ago`;let r=Math.floor(n/60);return r<60?`${r}m ago`:`${Math.floor(r/60)}h ago`}function js(){let[e,n]=(0,B.useState)([]),[r,i]=(0,B.useState)(!0),[a,o]=(0,B.useState)(null),s=(0,B.useCallback)(async()=>{try{let e=await fetch(`/api/sessions`);if(!e.ok){if(e.status===404){o(null),n([]);return}throw Error(`HTTP ${e.status}`)}n(await e.json()),o(null)}catch(e){o(e instanceof Error?e.message:String(e))}finally{i(!1)}},[]);return(0,B.useEffect)(()=>{s();let e=setInterval(s,5e3);return()=>clearInterval(e)},[s]),r?(0,X.jsxs)(`div`,{className:`flex items-center gap-2 p-4 text-slate-400`,children:[(0,X.jsx)(L,{className:`h-4 w-4 animate-spin`}),`Loading sessions...`]}):a?(0,X.jsxs)(`div`,{className:`p-4 text-slate-500 text-sm`,children:[`Session API unavailable — run `,(0,X.jsx)(`code`,{className:`text-cyan-400`,children:`wstack --webui`}),` with session tracking enabled.`]}):e.length===0?(0,X.jsx)(`div`,{className:`p-4 text-slate-500 text-sm`,children:`No live sessions. Open another wstack instance to see it here.`}):(0,X.jsxs)(`div`,{className:`p-4 space-y-3`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 mb-4`,children:[(0,X.jsxs)(`h2`,{className:`text-sm font-semibold text-slate-200 uppercase tracking-wider`,children:[`Live Sessions (`,e.length,`)`]}),(0,X.jsx)(`span`,{className:`text-xs text-slate-500`,children:`auto-refresh every 5s`})]}),e.map(e=>(0,X.jsxs)(`div`,{className:`rounded-lg border border-slate-700 bg-slate-800/50 p-3 space-y-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,X.jsx)(`span`,{className:Os(e.status),children:e.status===`active`?(0,X.jsx)(ge,{className:`h-3.5 w-3.5 inline`}):e.status===`idle`?(0,X.jsx)(t,{className:`h-3.5 w-3.5 inline`}):null}),(0,X.jsx)(`span`,{className:`font-medium text-slate-200 text-sm`,children:e.projectName}),(0,X.jsxs)(`span`,{className:`text-slate-500 text-xs`,children:[`[`,e.projectSlug,`]`]}),e.gitBranch?(0,X.jsxs)(`span`,{className:`text-purple-400 text-xs flex items-center gap-1`,children:[(0,X.jsx)(kn,{className:`h-3 w-3`}),e.gitBranch]}):null,(0,X.jsxs)(`span`,{className:`text-slate-500 text-xs ml-auto flex items-center gap-1`,children:[(0,X.jsx)(Pe,{className:`h-3 w-3`}),ks(e.startedAt)]}),(0,X.jsxs)(`span`,{className:`text-slate-600 text-xs`,children:[`PID `,e.pid]})]}),(0,X.jsxs)(`div`,{className:`text-slate-500 text-xs flex items-center gap-1`,children:[(0,X.jsx)(c,{className:`h-3 w-3`}),e.workingDir]}),(0,X.jsxs)(`div`,{className:`space-y-1 mt-2`,children:[e.agents.slice(0,5).map(e=>(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-xs pl-2 border-l-2 border-slate-700`,children:[(0,X.jsx)(`span`,{className:Ds(e.status),children:Es(e.status)}),(0,X.jsx)(`span`,{className:`text-slate-300 font-medium`,children:e.name}),e.currentTool?(0,X.jsxs)(`span`,{className:`text-slate-500`,children:[`[`,e.currentTool,`]`]}):null,(0,X.jsxs)(`span`,{className:`text-slate-600 ml-auto`,children:[e.iterations,` iter · `,e.toolCalls,` tools · `,As(e.lastActivityAt)]})]},e.id)),e.agents.length>5?(0,X.jsxs)(`div`,{className:`text-slate-600 text-xs pl-4`,children:[`... and `,e.agents.length-5,` more`]}):null,e.agents.length===0?(0,X.jsx)(`div`,{className:`text-slate-600 text-xs pl-4`,children:`No agents`}):null]})]},e.sessionId))]})}var Ms=[{section:`Global`,items:[{keys:[`Ctrl`,`K`],description:`Open command palette`},{keys:[`?`],description:`Show this shortcuts overlay`},{keys:[`Ctrl`,`\\`],description:`Toggle sidebar`},{keys:[`Ctrl`,`1-6`],description:`Open side panel (Session, Agents, History, Files, Projects, Mailbox)`},{keys:[`Ctrl`,`/`],description:`Focus the message input`}]},{section:`Fleet & Agents`,items:[{keys:[`Ctrl`,`Shift`,`M`],description:`Open Fleet Monitor overlay`},{keys:[`Ctrl`,`Shift`,`A`],description:`Open Agents Monitor overlay`},{keys:[`↑`,`↓`],description:`Navigate agents in monitor`},{keys:[`Enter`],description:`Select focused agent`},{keys:[`Esc`],description:`Close active overlay`}]},{section:`Chat input`,items:[{keys:[`Enter`],description:`Send message`},{keys:[`Shift`,`Enter`],description:`Insert a newline`},{keys:[`↑`],description:`Recall previous prompt (in empty input)`},{keys:[`↓`],description:`Recall next prompt`},{keys:[`/`],description:`Open slash command popup`},{keys:[`Tab`],description:`Autocomplete highlighted command`},{keys:[`Esc`],description:`Dismiss popup / clear input`}]},{section:`Chat`,items:[{keys:[`Ctrl`,`F`],description:`Search within current chat`},{keys:[`Ctrl`,`L`],description:`Clear context (same as /clear)`},{keys:[`Ctrl`,`N`],description:`Start a new session (same as /new)`},{keys:[`Ctrl`,`E`],description:`Export chat as markdown`},{keys:[`Ctrl`,`M`],description:`Quick model switcher overlay`},{keys:[`Ctrl`,`Shift`,`D`],description:`Toggle compact UI density`},{keys:[`Esc`],description:`Abort the current run (when running)`}]},{section:`Chat navigation (when not typing)`,items:[{keys:[`j`],description:`Focus next message (alias: ↓)`},{keys:[`k`],description:`Focus previous message (alias: ↑)`},{keys:[`g`],description:`Jump to first message`},{keys:[`Shift`,`G`],description:`Jump to last message`},{keys:[`c`],description:`Copy focused message text`},{keys:[`Esc`],description:`Clear focused message`}]}];function Ns(){let e=G(e=>e.shortcutsOpen),t=G(e=>e.setShortcutsOpen);return(0,B.useEffect)(()=>{let e=e=>{let n=e.target,r=n?.tagName?.toLowerCase();if(!(r===`input`||r===`textarea`||n?.isContentEditable)&&e.key===`?`&&!e.ctrlKey&&!e.metaKey&&!e.altKey){e.preventDefault(),t(!G.getState().shortcutsOpen);return}e.key===`Escape`&&G.getState().shortcutsOpen&&(e.preventDefault(),t(!1))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]),e?(0,X.jsx)(`div`,{className:`fixed inset-0 z-50 bg-background/60 backdrop-blur-sm flex items-center justify-center px-4`,onClick:()=>t(!1),onKeyDown:e=>{e.key===`Escape`&&t(!1)},children:(0,X.jsxs)(`div`,{onClick:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation(),className:`w-full max-w-2xl rounded-xl border bg-popover shadow-2xl overflow-hidden flex flex-col max-h-[80vh]`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between px-5 py-4 border-b`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(Xe,{className:`h-4 w-4 text-muted-foreground`}),(0,X.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Keyboard shortcuts`})]}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>t(!1),className:`text-muted-foreground hover:text-foreground p-1 rounded hover:bg-muted`,children:(0,X.jsx)(Ie,{className:`h-4 w-4`})})]}),(0,X.jsx)(`div`,{className:`overflow-y-auto px-5 py-4 space-y-6`,children:Ms.map(e=>(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground mb-2`,children:e.section}),(0,X.jsx)(`div`,{className:`grid grid-cols-1 gap-1.5`,children:e.items.map(e=>(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-3 text-sm px-2 py-1.5 rounded hover:bg-muted/40`,children:[(0,X.jsx)(`span`,{className:`text-foreground/80`,children:e.description}),(0,X.jsx)(`span`,{className:`flex items-center gap-1 shrink-0`,children:e.keys.map((e,t)=>(0,X.jsxs)(`span`,{className:`flex items-center gap-1`,children:[t>0&&(0,X.jsx)(`span`,{className:`text-muted-foreground/40 text-xs`,children:`+`}),(0,X.jsx)(`kbd`,{className:`font-mono text-[10px] border rounded px-1.5 py-0.5 bg-background`,children:e})]},e))})]},e.description))})]},e.section))}),(0,X.jsxs)(`div`,{className:`border-t px-5 py-3 text-xs text-muted-foreground`,children:[`Press`,` `,(0,X.jsx)(`kbd`,{className:`font-mono text-[10px] border rounded px-1 py-0.5 bg-background`,children:`?`}),` `,`any time to reopen this list.`]})]})}):null}function Ps(){return(0,X.jsx)(`style`,{children:`
108
104
  .react-flow__node {
109
105
  cursor: pointer;
110
106
  transition: transform 0.15s ease;
@@ -164,4 +160,4 @@ ${o.join(``)}
164
160
  .react-flow__background {
165
161
  background-color: hsl(var(--background));
166
162
  }
167
- `})}var Ps={read:(0,X.jsx)(I,{className:`h-3 w-3`}),write:(0,X.jsx)(I,{className:`h-3 w-3`}),bash:(0,X.jsx)(vn,{className:`h-3 w-3`}),exec:(0,X.jsx)(vn,{className:`h-3 w-3`}),glob:(0,X.jsx)(Ke,{className:`h-3 w-3`}),grep:(0,X.jsx)(lt,{className:`h-3 w-3`}),edit:(0,X.jsx)(He,{className:`h-3 w-3`}),fetch:(0,X.jsx)(st,{className:`h-3 w-3`}),search:(0,X.jsx)(lt,{className:`h-3 w-3`})};function Fs({data:e}){let t=e.status===`active`||e.status===`streaming`,n=e.color||`#22c55e`;return(0,X.jsxs)(`div`,{className:Y(`rounded-lg border-2 p-3 min-w-[160px] transition-all`,t?`border-emerald-500/50 bg-emerald-500/10`:`border-gray-500/40 bg-gray-500/10`),children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`div`,{className:Y(`flex items-center justify-center w-8 h-8 rounded-lg`,t?`bg-emerald-500/20`:`bg-gray-500/20`),children:(0,X.jsx)(Ke,{className:`h-4 w-4`,style:{color:n}})}),(0,X.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,X.jsx)(`div`,{className:`text-[11px] font-bold truncate`,style:{color:n},children:e.label}),e.sublabel&&(0,X.jsx)(`div`,{className:`text-[9px] text-gray-500 truncate`,children:e.sublabel})]}),t&&(0,X.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-emerald-400 animate-pulse`,style:{boxShadow:`0 0 8px hsl(140,70%,50%)`}})]}),e.stats&&(0,X.jsxs)(`div`,{className:`mt-2 pt-2 border-t border-white/10 grid grid-cols-3 gap-1 text-[9px]`,children:[e.stats.iterations!==void 0&&(0,X.jsxs)(`div`,{className:`text-center`,children:[(0,X.jsx)(`div`,{className:`font-mono text-emerald-400`,children:e.stats.iterations}),(0,X.jsx)(`div`,{className:`text-gray-500`,children:`iter`})]}),e.stats.toolCalls!==void 0&&(0,X.jsxs)(`div`,{className:`text-center`,children:[(0,X.jsx)(`div`,{className:`font-mono text-blue-400`,children:e.stats.toolCalls}),(0,X.jsx)(`div`,{className:`text-gray-500`,children:`tools`})]}),e.stats.costUsd!==void 0&&e.stats.costUsd>0&&(0,X.jsxs)(`div`,{className:`text-center`,children:[(0,X.jsxs)(`div`,{className:`font-mono text-amber-400`,children:[`$`,e.stats.costUsd.toFixed(3)]}),(0,X.jsx)(`div`,{className:`text-gray-500`,children:`cost`})]})]})]})}function Is({data:e}){let t=e.status===`active`||e.status===`streaming`,n=e.status===`error`,r=e.color||`#a855f7`;return(0,X.jsxs)(`div`,{className:Y(`rounded-lg border-2 p-2.5 min-w-[140px] transition-all`,t?`border-purple-500/50 bg-purple-500/10`:n?`border-red-500/50 bg-red-500/10`:`border-gray-500/40 bg-gray-500/10`),children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`div`,{className:Y(`flex items-center justify-center w-7 h-7 rounded-lg`,t?`bg-purple-500/20`:`bg-purple-500/10`),children:(0,X.jsx)(R,{className:`h-4 w-4`,style:{color:r}})}),(0,X.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,X.jsx)(`div`,{className:`text-[10px] font-bold truncate`,style:{color:r},children:e.label}),e.currentTool&&(0,X.jsxs)(`div`,{className:`flex items-center gap-1 text-[9px] text-amber-400/70`,children:[(0,X.jsx)(He,{className:`h-2.5 w-2.5`}),(0,X.jsx)(`span`,{className:`truncate font-mono`,children:e.currentTool})]})]}),t&&(0,X.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-purple-400 animate-pulse`,style:{boxShadow:`0 0 6px hsl(280,80%,60%)`}})]}),(0,X.jsxs)(`div`,{className:`mt-1.5 flex items-center justify-between text-[9px]`,children:[(0,X.jsxs)(`span`,{className:`text-gray-500`,children:[`iter `,e.stats?.iterations??0]}),(0,X.jsxs)(`span`,{className:`text-gray-500`,children:[`tools `,e.stats?.toolCalls??0]}),e.stats?.costUsd!==void 0&&e.stats.costUsd>0&&(0,X.jsxs)(`span`,{className:`text-emerald-400/70`,children:[`$`,e.stats.costUsd.toFixed(3)]})]}),e.stats?.ctxPct!==void 0&&(0,X.jsxs)(`div`,{className:`mt-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between text-[9px] mb-0.5`,children:[(0,X.jsx)(`span`,{className:`text-gray-500`,children:`ctx`}),(0,X.jsxs)(`span`,{className:e.stats.ctxPct>80?`text-red-400`:e.stats.ctxPct>60?`text-amber-400`:`text-gray-400`,children:[e.stats.ctxPct,`%`]})]}),(0,X.jsx)(`div`,{className:`h-1 rounded-full bg-black/30 overflow-hidden`,children:(0,X.jsx)(`div`,{className:Y(`h-full rounded-full transition-all`,e.stats.ctxPct>80?`bg-red-500`:e.stats.ctxPct>60?`bg-amber-500`:`bg-blue-500`),style:{width:`${Math.min(100,e.stats.ctxPct)}%`}})})]})]})}function Ls({data:e}){let t=e.color||`#f59e0b`,n=Ps[e.label?.toLowerCase()??``]||(0,X.jsx)(He,{className:`h-3 w-3`});return(0,X.jsxs)(`div`,{className:`rounded-lg border border-amber-500/30 bg-amber-500/10 p-2 min-w-[100px] transition-all`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`span`,{style:{color:t},children:n}),(0,X.jsx)(`span`,{className:`text-[10px] font-mono font-medium truncate`,style:{color:t},children:e.label})]}),e.stats?.durationMs!==void 0&&(0,X.jsxs)(`div`,{className:`mt-1 text-[9px] text-gray-500 text-center`,children:[e.stats.durationMs,`ms`]})]})}function Rs({data:e}){let t=e.status===`active`||e.status===`streaming`,n=e.color||`#06b6d4`;return(0,X.jsx)(`div`,{className:Y(`rounded-lg border-2 p-3 min-w-[120px] transition-all`,t?`border-cyan-500/50 bg-cyan-500/10`:`border-cyan-500/30 bg-cyan-500/5`),children:(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`div`,{className:Y(`flex items-center justify-center w-8 h-8 rounded-lg`,t?`bg-cyan-500/20`:`bg-cyan-500/10`),children:(0,X.jsx)(c,{className:`h-4 w-4`,style:{color:n}})}),(0,X.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,X.jsx)(`div`,{className:`text-[10px] font-bold`,style:{color:n},children:`LLM`}),(0,X.jsx)(`div`,{className:`text-[9px] text-gray-500 truncate`,children:e.sublabel||`Provider`})]}),t&&(0,X.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-cyan-400 animate-pulse`,style:{boxShadow:`0 0 8px hsl(180,80%,60%)`}})]})})}function zs({data:e}){let t=e.color||`#3b82f6`;return(0,X.jsxs)(`div`,{className:`rounded-lg border border-blue-500/30 bg-blue-500/10 p-2 min-w-[90px] transition-all`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(ie,{className:`h-3 w-3`,style:{color:t}}),(0,X.jsx)(`span`,{className:`text-[10px] font-medium`,style:{color:t},children:`Context`})]}),e.stats?.ctxPct!==void 0&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`mt-1 text-[9px] text-center text-gray-400`,children:[e.stats.ctxPct,`%`]}),(0,X.jsx)(`div`,{className:`h-1 mt-0.5 rounded-full bg-black/30 overflow-hidden`,children:(0,X.jsx)(`div`,{className:`h-full rounded-full bg-blue-500`,style:{width:`${Math.min(100,e.stats.ctxPct)}%`}})})]})]})}var Bs={session:Fs,agent:Is,tool:Ls,provider:Rs,context:zs};function Vs({id:e,sourceX:t,sourceY:n,targetX:r,targetY:i,data:a,selected:o}){let[s,c,l]=Hs(t,n,r,i),u=a?.color||`#6366f1`,d=a?.animated,f=a?.flowType||`response`,p=a?.sequence,m={prompt:{icon:`📥`,bg:`bg-blue-500/20`,text:`text-blue-400`},response:{icon:`📤`,bg:`bg-emerald-500/20`,text:`text-emerald-400`},tool_result:{icon:`🔧`,bg:`bg-amber-500/20`,text:`text-amber-400`},tokens:{icon:`💎`,bg:`bg-cyan-500/20`,text:`text-cyan-400`},spawn:{icon:`✨`,bg:`bg-purple-500/20`,text:`text-purple-400`},status:{icon:`📊`,bg:`bg-pink-500/20`,text:`text-pink-400`}},h=m[f]||m.response;return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`path`,{id:e,d:s,fill:`none`,stroke:u,strokeWidth:o?3:2,strokeOpacity:o?.9:.4,className:`react-flow__edge-path`,markerEnd:`url(#arrow-${u.replace(`#`,``)})`}),d&&(0,X.jsx)(`path`,{d:s,fill:`none`,stroke:u,strokeWidth:2.5,strokeDasharray:`8 4`,className:`animated-edge`,opacity:.8}),p!==void 0&&(0,X.jsxs)(`g`,{transform:`translate(${c-6}, ${l-18})`,children:[(0,X.jsx)(`circle`,{r:`8`,fill:u,opacity:.9}),(0,X.jsx)(`text`,{x:`0`,y:`3`,textAnchor:`middle`,fill:`white`,fontSize:`9`,fontWeight:`bold`,children:p})]}),a?.label&&(0,X.jsx)(`foreignObject`,{width:100,height:28,x:c-50,y:l-14,className:`overflow-visible`,children:(0,X.jsxs)(`div`,{className:`flex items-center justify-center gap-1`,children:[(0,X.jsx)(`span`,{className:`text-[10px]`,children:h.icon}),(0,X.jsx)(`div`,{className:Y(`px-2 py-1 rounded-md border text-[9px] font-medium`,h.bg,`border-border/50`,h.text),children:a.label})]})}),(0,X.jsx)(`defs`,{children:(0,X.jsx)(`marker`,{id:`arrow-${u.replace(`#`,``)}`,viewBox:`0 0 10 10`,refX:`9`,refY:`5`,markerWidth:`6`,markerHeight:`6`,orient:`auto-start-reverse`,children:(0,X.jsx)(`path`,{d:`M 0 0 L 10 5 L 0 10 z`,fill:u,opacity:.7})})})]})}function Hs(e,t,n,r){let i=Math.abs(n-e),a=Math.max(40,i*.4),o=(e+n)/2,s=Math.min(t,r)-a;return[`M ${e} ${t} C ${e} ${s}, ${n} ${s}, ${n} ${r}`,o,s]}var Us={flow:Vs};function Ws({containerRef:e}){let{fitView:t}=$e(),n=W(e=>e.session),r=W(e=>e.projectName),i=W(e=>e.iteration),a=W(e=>e.cost),o=W(e=>e.lastInputTokens),s=W(e=>e.maxContext),c=K(e=>e.agents);yr(e=>e.nodes),yr(e=>e.edges);let l=yr(e=>e.events),u=yr(e=>e.counters),[d,f,p]=On([]),[m,h,g]=yn([]),[_,v]=(0,B.useState)(null);(0,B.useEffect)(()=>{let e=[],l=[];e.push({id:`provider`,type:`provider`,position:{x:400,y:20},data:{label:`LLM`,sublabel:n?.model||`claude-3-5-sonnet`,type:`provider`,status:n?`active`:`idle`,color:`#06b6d4`}}),e.push({id:`session`,type:`session`,position:{x:400,y:120},data:{label:n?.title||r||`Session`,sublabel:n?.id.slice(0,8),type:`session`,status:n?`active`:`idle`,color:`#22c55e`,stats:{iterations:i?.index,toolCalls:Array.from(c.values()).reduce((e,t)=>e+t.toolCalls,0),costUsd:a}}});let u=s?Math.round(o/s*100):0;e.push({id:`context`,type:`context`,position:{x:700,y:200},data:{label:`Context`,type:`context`,status:u>80?`active`:`idle`,color:`#3b82f6`,stats:{ctxPct:u}}});let d=Array.from(c.values()),p=Math.min(200,800/(d.length+1)),m=Math.max(100,(800-(d.length-1)*p)/2);d.forEach((t,n)=>{let r=t.status===`running`,i=t.status===`failed`,a=`agent-${t.id}`,o=i?`#ef4444`:r?`#a855f7`:`#8b5cf6`;e.push({id:a,type:`agent`,position:{x:m+n*p,y:300},data:{label:t.name,type:`agent`,status:r?`active`:i?`error`:t.status===`completed`?`completed`:`idle`,color:o,stats:{iterations:t.iteration,toolCalls:t.toolCalls,costUsd:t.costUsd,ctxPct:t.ctxPct},currentTool:t.currentTool||t.lastTool}}),l.push({id:`session->${a}`,source:`session`,target:a,type:`flow`,animated:r,data:{color:o,animated:r,label:`task`,flowType:`prompt`,sequence:n+1}}),l.push({id:`${a}->provider`,source:a,target:`provider`,type:`flow`,animated:r,data:{color:`#06b6d4`,animated:r,label:`prompt`,flowType:`prompt`,sequence:0}});let s=t.currentTool||t.lastTool;if(s){let i=`tool-${t.id}-${d.indexOf(t)}`;e.push({id:i,type:`tool`,position:{x:m+n*p,y:450},data:{label:s,type:`tool`,status:r?`active`:`idle`,color:`#f59e0b`,stats:{durationMs:t.toolLog?.[0]?.durationMs}}}),l.push({id:`${a}->${i}`,source:a,target:i,type:`flow`,animated:r,data:{color:`#f59e0b`,animated:r,label:`execute`,flowType:`tool_result`,sequence:2}}),l.push({id:`${i}->${a}`,source:i,target:a,type:`flow`,animated:!1,data:{color:`#22c55e`,animated:!1,label:`result`,flowType:`tool_result`,sequence:3}})}}),l.push({id:`provider->session`,source:`provider`,target:`session`,type:`flow`,animated:!!n,data:{color:`#06b6d4`,animated:!!n,label:`response`,flowType:`response`,sequence:4}}),l.push({id:`context->session`,source:`context`,target:`session`,type:`flow`,data:{color:`#3b82f6`,animated:!1,label:`tokens`,flowType:`tokens`}}),f(e),h(l),setTimeout(()=>t({padding:.2,duration:300}),50)},[n,r,i,c,a,o,s,f,h,t]),(0,B.useEffect)(()=>{if(l.length===0)return;let e=l[0];if(e){if(e.kind===`agent:tool`&&e.source){let t=`agent-${e.source}`;f(n=>n.map(n=>n.id===t?{...n,data:{...n.data,status:`streaming`,currentTool:e.label}}:n))}if(e.kind===`agent:status`){let t=`agent-${e.source}`,n=e.label.includes(`completed`)?`completed`:e.label.includes(`failed`)?`error`:e.label.includes(`running`)?`active`:`idle`;f(e=>e.map(e=>e.id===t?{...e,data:{...e.data,status:n}}:e))}}},[l,f]);let y=(0,B.useCallback)(e=>h(t=>gt({...e,type:`flow`},t)),[h]),b=(0,B.useCallback)((e,t)=>{v(t)},[]),x=(0,B.useCallback)(()=>{v(null)},[]);return(0,X.jsxs)(`div`,{className:`w-full h-full bg-background relative`,children:[(0,X.jsx)(Ns,{}),(0,X.jsxs)(Ge,{nodes:d,edges:m,onNodesChange:p,onEdgesChange:g,onConnect:y,onNodeClick:b,onPaneClick:x,nodeTypes:Bs,edgeTypes:Us,fitView:!0,attributionPosition:`bottom-left`,proOptions:{hideAttribution:!0},children:[(0,X.jsx)(ot,{variant:ft.Dots,gap:20,size:1,color:`hsl(var(--border))`}),(0,X.jsx)(Yt,{className:`!bg-background/80 !border-border backdrop-blur`}),(0,X.jsx)(Lt,{className:`!bg-background/80 !border-border`,nodeColor:e=>{switch(e.type){case`session`:return`#22c55e`;case`agent`:return`#a855f7`;case`tool`:return`#f59e0b`;case`provider`:return`#06b6d4`;case`context`:return`#3b82f6`;default:return`#6366f1`}}})]}),_&&(0,X.jsxs)(`div`,{className:`absolute top-4 right-4 w-64 bg-background/95 border border-border rounded-lg shadow-xl backdrop-blur z-50`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between p-3 border-b border-border`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`span`,{className:`text-xs font-bold capitalize`,children:_.type}),(0,X.jsx)(`span`,{className:Y(`px-1.5 py-0.5 rounded text-[9px] font-medium`,_.data.status===`active`&&`bg-emerald-500/20 text-emerald-400`,_.data.status===`streaming`&&`bg-blue-500/20 text-blue-400`,_.data.status===`error`&&`bg-red-500/20 text-red-400`,_.data.status===`completed`&&`bg-blue-500/20 text-blue-400`,_.data.status===`idle`&&`bg-gray-500/20 text-gray-400`),children:_.data.status})]}),(0,X.jsx)(`button`,{onClick:()=>v(null),className:`text-muted-foreground hover:text-foreground`,children:(0,X.jsx)(Ie,{className:`h-4 w-4`})})]}),(0,X.jsxs)(`div`,{className:`p-3 space-y-2 text-[11px]`,children:[(0,X.jsxs)(`div`,{className:`flex justify-between`,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`Label`}),(0,X.jsx)(`span`,{className:`font-mono`,children:String(_.data.label??``)})]}),_.data.sublabel&&(0,X.jsxs)(`div`,{className:`flex justify-between`,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`Sublabel`}),(0,X.jsx)(`span`,{className:`font-mono text-[10px]`,children:String(_.data.sublabel)})]}),_.data.currentTool&&(0,X.jsxs)(`div`,{className:`flex justify-between`,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`Tool`}),(0,X.jsx)(`span`,{className:`font-mono text-amber-400`,children:String(_.data.currentTool)})]}),_.data.stats&&(0,X.jsxs)(X.Fragment,{children:[_.data.stats.iterations!==void 0&&(0,X.jsxs)(`div`,{className:`flex justify-between`,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`Iterations`}),(0,X.jsx)(`span`,{className:`font-mono`,children:_.data.stats.iterations})]}),_.data.stats.toolCalls!==void 0&&(0,X.jsxs)(`div`,{className:`flex justify-between`,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`Tool Calls`}),(0,X.jsx)(`span`,{className:`font-mono`,children:_.data.stats.toolCalls})]}),_.data.stats.costUsd!==void 0&&(0,X.jsxs)(`div`,{className:`flex justify-between`,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`Cost`}),(0,X.jsxs)(`span`,{className:`font-mono text-emerald-400`,children:[`$`,_.data.stats.costUsd.toFixed(4)]})]}),_.data.stats.ctxPct!==void 0&&(0,X.jsxs)(`div`,{className:`flex justify-between`,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`Context`}),(0,X.jsxs)(`span`,{className:`font-mono`,children:[_.data.stats.ctxPct,`%`]})]})]})]})]}),(0,X.jsxs)(`div`,{className:`absolute bottom-4 left-4 bg-background/95 border border-border rounded-lg p-2 backdrop-blur`,children:[(0,X.jsx)(`div`,{className:`text-[9px] text-muted-foreground mb-1 font-semibold uppercase tracking-wider`,children:`Live`}),(0,X.jsxs)(`div`,{className:`grid grid-cols-3 gap-x-3 gap-y-1 text-[10px]`,children:[(0,X.jsx)(Gs,{label:`Tokens`,value:u.totalTokens.toLocaleString()}),(0,X.jsx)(Gs,{label:`Cost`,value:`$${u.totalCost.toFixed(3)}`}),(0,X.jsx)(Gs,{label:`Tools`,value:u.totalToolCalls}),(0,X.jsx)(Gs,{label:`Agents`,value:u.activeAgents}),(0,X.jsx)(Gs,{label:`Done`,value:u.completedTasks}),(0,X.jsx)(Gs,{label:`Errors`,value:u.errors})]})]}),(0,X.jsxs)(`div`,{className:`absolute top-4 left-4 bg-background/95 border border-border rounded-lg p-3 backdrop-blur z-50 max-w-xs`,children:[(0,X.jsxs)(`div`,{className:`text-[9px] text-muted-foreground mb-2 font-semibold uppercase tracking-wider flex items-center gap-2`,children:[(0,X.jsx)(`span`,{className:`text-primary`,children:`⟳`}),` Flow Sequence`]}),(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(qs,{sequence:0,icon:`📥`,label:`Prompt`,description:`User input → LLM`,color:`#06b6d4`}),(0,X.jsx)(qs,{sequence:1,icon:`👤`,label:`Task`,description:`Session → Agent`,color:`#a855f7`}),(0,X.jsx)(qs,{sequence:2,icon:`🔧`,label:`Execute`,description:`Agent → Tool`,color:`#f59e0b`}),(0,X.jsx)(qs,{sequence:3,icon:`✅`,label:`Result`,description:`Tool → Agent`,color:`#22c55e`}),(0,X.jsx)(qs,{sequence:4,icon:`📤`,label:`Response`,description:`LLM → Session`,color:`#06b6d4`})]}),(0,X.jsx)(`div`,{className:`mt-2 pt-2 border-t border-border`,children:(0,X.jsxs)(`div`,{className:`text-[9px] text-muted-foreground flex items-center gap-2`,children:[(0,X.jsx)(`span`,{children:`💎`}),` Tokens: Context → Session`]})})]}),(0,X.jsxs)(`div`,{className:`absolute bottom-4 right-4 bg-background/95 border border-border rounded-lg p-2 backdrop-blur`,children:[(0,X.jsx)(`div`,{className:`text-[9px] text-muted-foreground mb-1 font-semibold uppercase tracking-wider`,children:`Nodes`}),(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(Ks,{color:`#22c55e`,label:`Session`}),(0,X.jsx)(Ks,{color:`#a855f7`,label:`Agent`}),(0,X.jsx)(Ks,{color:`#f59e0b`,label:`Tool`}),(0,X.jsx)(Ks,{color:`#06b6d4`,label:`Provider`}),(0,X.jsx)(Ks,{color:`#3b82f6`,label:`Context`})]})]})]})}function Gs({label:e,value:t}){return(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:e}),(0,X.jsx)(`span`,{className:`font-mono font-bold text-foreground`,children:t})]})}function Ks({color:e,label:t}){return(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px]`,children:[(0,X.jsx)(`span`,{className:`w-2.5 h-2.5 rounded-sm`,style:{backgroundColor:e}}),(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:t})]})}function qs({sequence:e,icon:t,label:n,description:r,color:i}){return(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px]`,children:[(0,X.jsx)(`div`,{className:`w-5 h-5 rounded-full flex items-center justify-center text-[9px] font-bold text-white shrink-0`,style:{backgroundColor:i},children:e}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,X.jsx)(`span`,{children:t}),(0,X.jsx)(`span`,{className:`font-medium`,style:{color:i},children:n}),(0,X.jsx)(`span`,{className:`text-muted-foreground text-[9px]`,children:r})]})]})}function Js(e){return(0,X.jsx)(bt,{children:(0,X.jsx)(Ws,{...e})})}var Ys={ts:F,tsx:F,js:F,jsx:F,mjs:F,cjs:F,json:a,lock:Te,css:I,scss:I,less:I,html:En,htm:En,svg:_,xml:En,md:I,mdx:I,txt:I,yml:I,yaml:I,toml:m,env:m,gitignore:m,editorconfig:m,sh:F,bash:F,zsh:F,fish:F,ps1:F,bat:F,py:F,pyi:F,pyx:F,rs:F,go:F,rb:F,java:F,c:F,cpp:F,h:F,hpp:F,sql:F,graphql:F,png:_,jpg:_,jpeg:_,gif:_,webp:_,ico:_};function Xs(e,t){if(t){let t=e.toLowerCase();return t===`.git`?`text-orange-500/80 dark:text-orange-400/80`:t===`node_modules`?`text-red-400/60 dark:text-red-500/60`:t===`src`||t===`lib`||t===`packages`?`text-amber-500/70 dark:text-amber-400/70`:t===`tests`||t===`test`||t===`__tests__`?`text-emerald-500/70 dark:text-emerald-400/70`:t===`dist`||t===`build`||t===`.next`?`text-muted-foreground/50`:`text-amber-500/70 dark:text-amber-400/70`}let n=e.split(`.`).pop()?.toLowerCase()??``;return/^(ts|tsx|js|jsx|mjs|cjs)$/.test(n)?`text-blue-500 dark:text-blue-400`:/^(json|lock)$/.test(n)?`text-amber-500 dark:text-amber-400`:/^(css|scss|less|sass)$/.test(n)?`text-teal-500 dark:text-teal-400`:/^(html|htm|xml|svg)$/.test(n)?`text-rose-500 dark:text-rose-400`:/^(md|mdx)$/.test(n)?`text-violet-500 dark:text-violet-400`:/^(yml|yaml|toml|env)$/.test(n)?`text-emerald-500 dark:text-emerald-400`:/^(sh|bash|zsh|fish|ps1|bat)$/.test(n)?`text-orange-400 dark:text-orange-300`:/^(py|pyi|pyx)$/.test(n)?`text-cyan-500 dark:text-cyan-400`:n===`rs`?`text-orange-500 dark:text-orange-400`:n===`go`?`text-sky-500 dark:text-sky-400`:n===`rb`?`text-red-400 dark:text-red-400`:/^(c|h|cpp|hpp|cc|hh)$/.test(n)?`text-slate-500 dark:text-slate-400`:/^(png|jpe?g|gif|webp|ico|svg)$/.test(n)?`text-purple-500 dark:text-purple-400`:/^(gitignore|editorconfig|prettierrc|eslintrc)$/.test(n)?`text-muted-foreground/60`:`text-muted-foreground`}function Zs(e){return Ys[e.split(`.`).pop()?.toLowerCase()??``]??et}function Qs({node:e,depth:t,selectedPath:r,forceExpand:i,onSelect:a,onOpen:o}){let[s,c]=(0,B.useState)(t<1),l=q(e=>e.activeFilePath),u=e.type===`file`&&e.path===l;if((0,B.useEffect)(()=>{i!==null&&c(i)},[i]),e.type===`directory`){let l=(e.children?.length??0)>0,u=s?Ke:xt,d=e.name===`.git`,f=Xs(e.name,!0);return(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`button`,{type:`button`,onClick:()=>c(e=>!e),className:Y(`flex items-center gap-1 w-full text-left px-1 py-0.5 text-[11px] rounded`,`hover:bg-muted/60 transition-colors`),style:{paddingLeft:`${t*14+4}px`},children:[(0,X.jsx)(n,{className:Y(`h-3 w-3 shrink-0 text-muted-foreground transition-transform`,s&&`rotate-90`)}),d?(0,X.jsx)(bn,{className:Y(`h-3.5 w-3.5 shrink-0`,f)}):(0,X.jsx)(u,{className:Y(`h-3.5 w-3.5 shrink-0`,f)}),(0,X.jsx)(`span`,{className:`truncate font-medium flex-1 min-w-0`,children:e.name})]}),s&&l&&(0,X.jsx)(`div`,{children:(e.children??[]).map(e=>(0,X.jsx)(Qs,{node:e,depth:t+1,selectedPath:r,forceExpand:i,onSelect:a,onOpen:o},e.path))}),s&&!l&&(0,X.jsx)(`div`,{className:`text-[10px] text-muted-foreground italic py-0.5`,style:{paddingLeft:`${(t+1)*14+4}px`},children:`empty`})]})}let d=Zs(e.name),f=Xs(e.name,!1),p=e.path===r;return(0,X.jsxs)(`button`,{type:`button`,onClick:()=>a(e.path),onDoubleClick:t=>{t.preventDefault(),o(e.path)},className:Y(`flex items-center gap-1.5 w-full text-left px-1 py-0.5 text-[11px] rounded`,`hover:bg-muted/60 transition-colors`,u&&`bg-primary/10 text-primary`,p&&!u&&`bg-muted/70 ring-1 ring-inset ring-border`),style:{paddingLeft:`${t*14+4}px`},children:[(0,X.jsx)(`span`,{className:`w-3 shrink-0`}),` `,(0,X.jsx)(d,{className:Y(`h-3.5 w-3.5 shrink-0`,f)}),(0,X.jsx)(`span`,{className:`truncate`,children:e.name})]})}function $s(){let e=q(e=>e.tree),t=q(e=>e.treeLoading),n=q(e=>e.error),r=q(e=>e.openFiles),i=q(e=>e.activeFilePath),a=W(e=>e.cwd),o=W(e=>e.projectName),s=a?.includes(`\\`)?`\\`:`/`,c=(e,t=8,n=4)=>e.length<=t+n+2?e:`${e.slice(0,t)}…${e.slice(-n)}`,l=(()=>{if(!a||!o)return!0;let e=a.replace(/\\/g,`/`).split(`/`).filter(Boolean);return(e[e.length-1]??``)===o})(),u=(0,B.useMemo)(()=>{if(!a||!o)return[];let e=a.replace(/\\/g,`/`).split(`/`).filter(Boolean),t=-1;for(let n=e.length-1;n>=0;n--)if(e[n]===o){t=n;break}if(t===-1)return e.map((t,n)=>({label:t,path:`/`+e.slice(0,n+1).join(`/`),isLast:n===e.length-1}));let n=e.slice(t);return n.map((r,i)=>({label:r,path:`/`+e.slice(0,t+i+1).join(`/`),isLast:i===n.length-1}))},[a,o]),d=(0,B.useRef)(null);(0,B.useEffect)(()=>{let e=d.current;e&&u.length>1&&(e.scrollLeft=e.scrollWidth)},[u]);let f=(0,B.useCallback)(e=>{V().send({type:`working_dir.set`,payload:{path:e}})},[]),[p,m]=(0,B.useState)(null);(0,B.useEffect)(()=>{if(!p)return;let e=()=>m(null),t=t=>{t.key===`Escape`&&e()};return window.addEventListener(`click`,e),window.addEventListener(`keydown`,t),()=>{window.removeEventListener(`click`,e),window.removeEventListener(`keydown`,t)}},[p]);let h=(0,B.useCallback)((e,t)=>{e.preventDefault(),e.stopPropagation(),m({x:e.clientX,y:e.clientY,crumb:t})},[]),g=(0,B.useCallback)(e=>{navigator.clipboard.writeText(e),m(null)},[]),_=(0,B.useCallback)(()=>{if(!i)return;let e=i.replace(/\\/g,`/`).split(`/`).slice(0,-1).join(`/`)||`.`;V().send({type:`working_dir.set`,payload:{path:e}})},[i]),v=(0,B.useCallback)((e,t)=>{V().send({type:`shell.open`,payload:{path:e,target:t}}),m(null)},[]),y=(0,B.useCallback)(()=>{if(!a)return;let e=a.replace(/\\/g,`/`),t=e.split(`/`).slice(0,-1).join(`/`)||e;V().send({type:`working_dir.set`,payload:{path:t}})},[a]),[b,x]=(0,B.useState)(!1),S=(0,B.useRef)(null);(0,B.useEffect)(()=>(t?S.current=setTimeout(()=>x(!0),150):(S.current&&clearTimeout(S.current),x(!1)),()=>{S.current&&clearTimeout(S.current)}),[t]);let[C,w]=(0,B.useState)(null),[T,E]=(0,B.useState)(null),D=(0,B.useMemo)(()=>{let t=0,n=e=>{for(let r of e)r.type===`directory`&&t++,r.children&&n(r.children)};return n(e),t},[e]),O=(0,B.useMemo)(()=>{let t=0,n=0;for(let r of e)r.type===`directory`?n++:t++;return{files:t,dirs:n}},[e]),k={value:!1},A=(0,B.useCallback)(()=>{k.value=!0,E(!1),setTimeout(()=>{k.value=!1},400)},[]),j=(0,B.useCallback)(()=>{k.value=!0,E(!0),setTimeout(()=>{k.value=!1},400)},[]),ee=(0,B.useCallback)(e=>{if(r.find(t=>t.path===e)){q.getState().setActiveFile(e);return}w(t=>t===e?null:e)},[r]),M=(0,B.useCallback)(e=>{window.dispatchEvent(new CustomEvent(`wrongstack:open-file`,{detail:{filePath:e}})),w(null)},[]);return(0,B.useEffect)(()=>{i&&w(null)},[i]),b?(0,X.jsx)(`div`,{className:`flex items-center justify-center h-full py-8`,children:(0,X.jsx)(L,{className:`h-5 w-5 animate-spin text-muted-foreground`})}):n?(0,X.jsxs)(`div`,{className:`p-3 text-[11px] text-destructive`,children:[`Failed to load files: `,n]}):(0,X.jsxs)(`div`,{className:`h-full flex flex-col overflow-hidden`,children:[e.length>0&&D>0&&(0,X.jsxs)(`div`,{className:`flex items-center gap-0.5 px-2 py-0.5 border-b shrink-0`,children:[(0,X.jsxs)(`button`,{type:`button`,onClick:j,className:Y(`flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] transition-colors`,`hover:bg-muted/60 text-muted-foreground hover:text-foreground`),title:`Expand all directories`,children:[(0,X.jsx)(Rt,{className:`h-3 w-3`}),(0,X.jsx)(`span`,{children:`Expand all`})]}),(0,X.jsxs)(`button`,{type:`button`,onClick:A,className:Y(`flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] transition-colors`,`hover:bg-muted/60 text-muted-foreground hover:text-foreground`),title:`Collapse all directories`,children:[(0,X.jsx)(ne,{className:`h-3 w-3`}),(0,X.jsx)(`span`,{children:`Collapse`})]}),(0,X.jsxs)(`span`,{className:`ml-auto text-[9px] text-muted-foreground/50 tabular-nums`,children:[D,` folder`,D===1?``:`s`]})]}),(0,X.jsxs)(`div`,{className:`flex-1 overflow-y-auto py-1`,children:[u.length>0&&(0,X.jsxs)(`div`,{ref:d,className:`relative flex items-center gap-0.5 px-1 pb-1 border-b border-border/30 overflow-x-auto`,children:[(0,X.jsx)(`span`,{className:`sticky left-0 shrink-0 w-3 h-full bg-gradient-to-r from-background to-transparent pointer-events-none`}),u.map((e,t)=>{let n=e.isLast?e.label:c(e.label),r=e.path.replace(/\//g,s),i=a?a.replace(/\\/g,`/`).split(`/`).filter(Boolean):[],l=(()=>{for(let e=i.length-1;e>=0;e--)if(i[e]===o)return e;return-1})(),u=l>=0?i.slice(0,l+t+1):i.slice(0,t+1),d=s===`\\`?u.join(`\\`):`/`+u.join(`/`),p=(l>=0?i.slice(l+1,l+t+1):[]).join(s)||`.`;return(0,X.jsxs)(`span`,{className:`flex items-center gap-0.5 shrink-0`,children:[t>0&&(0,X.jsx)(`span`,{className:`text-[9px] text-muted-foreground/40 select-none`,children:s}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>f(e.path),onContextMenu:e=>h(e,{absPath:d,relPath:p}),className:Y(`px-1 py-0.5 rounded text-[11px] transition-colors whitespace-nowrap`,e.isLast?`text-foreground font-medium`:`text-muted-foreground hover:text-foreground hover:bg-muted/60`),title:e.isLast?`Current directory: ${r}`:`Navigate to ${r}`,children:n})]},e.path)}),e.length>0&&(0,X.jsxs)(`span`,{className:`ml-auto shrink-0 text-[9px] text-muted-foreground/50 tabular-nums pl-2`,children:[O.files>0&&`${O.files} file${O.files===1?``:`s`}`,O.files>0&&O.dirs>0&&`, `,O.dirs>0&&`${O.dirs} folder${O.dirs===1?``:`s`}`]})]}),i&&(0,X.jsxs)(`button`,{type:`button`,onClick:_,className:`flex items-center gap-1 w-full text-left px-2 py-0.5 border-b border-border/30 text-[10px] text-muted-foreground hover:text-foreground hover:bg-accent/50 transition-colors`,title:`Navigate to parent directory of ${i.replace(/\//g,s)}`,children:[(0,X.jsx)(F,{className:`h-3 w-3 shrink-0`}),(0,X.jsx)(`span`,{className:`truncate`,children:(()=>{let e=i.replace(/\\/g,`/`).split(`/`);return e[e.length-1]??i})()}),(0,X.jsx)(`span`,{className:`ml-auto text-[8px] text-muted-foreground/40 shrink-0`,children:`go to dir`})]}),u.length===0&&!l&&(0,X.jsxs)(`button`,{type:`button`,onClick:y,className:Y(`flex items-center gap-1.5 w-full text-left px-1 py-0.5 text-[11px] rounded`,`hover:bg-muted/60 transition-colors text-muted-foreground hover:text-foreground`,`font-medium`),children:[(0,X.jsx)(je,{className:`h-3.5 w-3.5 shrink-0`}),(0,X.jsx)(`span`,{children:`..`}),(0,X.jsx)(`span`,{className:`text-[9px] text-muted-foreground/50 ml-auto`,children:`parent directory`})]}),e.map(e=>(0,X.jsx)(Qs,{node:e,depth:0,selectedPath:C,forceExpand:T,onSelect:ee,onOpen:M},e.path)),e.length===0&&(0,X.jsx)(`p`,{className:`text-[11px] text-muted-foreground italic p-2`,children:`No files found`})]}),p&&(0,X.jsxs)(`div`,{className:`fixed z-50 min-w-[140px] bg-popover border rounded-md shadow-md py-1 text-[11px]`,style:{left:p.x,top:p.y},children:[(0,X.jsx)(`button`,{type:`button`,onClick:()=>g(p.crumb.absPath),className:`flex items-center gap-2 w-full text-left px-3 py-1.5 hover:bg-accent transition-colors`,children:`Copy absolute path`}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>g(p.crumb.relPath),className:`flex items-center gap-2 w-full text-left px-3 py-1.5 hover:bg-accent transition-colors`,children:`Copy relative path`}),(0,X.jsx)(`div`,{className:`border-t border-border/50 my-0.5`}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>v(p.crumb.absPath,`terminal`),className:`flex items-center gap-2 w-full text-left px-3 py-1.5 hover:bg-accent transition-colors`,children:`Open in terminal`}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>v(p.crumb.absPath,`file-manager`),className:`flex items-center gap-2 w-full text-left px-3 py-1.5 hover:bg-accent transition-colors`,children:`Open in file manager`}),(0,X.jsx)(`div`,{className:`border-t border-border/50 mt-0.5 pt-0.5`,children:(0,X.jsx)(`div`,{className:`px-3 py-1 text-[9px] text-muted-foreground/50 truncate max-w-[200px]`,children:p.crumb.absPath})})]})]})}var ec={note:I,ask:en,assign:f,steer:Ee,btw:Ze,broadcast:f,status:C,result:Be};function tc(e){let t=new Date(e),n=Date.now()-t.getTime();return n<6e4?`now`:n<36e5?`${Math.round(n/6e4)}m`:n<864e5?`${Math.round(n/36e5)}h`:t.toLocaleDateString()}function nc({className:e}){let t=er(e=>e.messages),n=er(e=>e.agents),[r,i]=(0,B.useState)(!1),[a,o]=(0,B.useState)(!1),{client:s}=Z(),[c,l]=(0,B.useState)(s.status.state===`open`);(0,B.useEffect)(()=>s.onStatus(e=>l(e.state===`open`)),[s]),(0,B.useEffect)(()=>{c&&(s.send({type:`mailbox.messages`,payload:{limit:30}}),s.send({type:`mailbox.agents`,payload:{}}))},[c,s]);let u=t.filter(e=>!e.completed).length,d=n.filter(e=>e.online).length;async function f(){t.length!==0&&await ts({title:`Delete all ${t.length} message${t.length===1?``:`s`}?`,message:`The mailbox file is truncated for every agent. This cannot be undone.`,confirmLabel:`Delete all`,danger:!0})&&(o(!0),s.send({type:`mailbox.clear`}))}return(0,B.useEffect)(()=>{a&&t.length===0&&o(!1)},[a,t.length]),(0,X.jsxs)(`div`,{className:Y(`rounded-lg border border-border bg-card/60 backdrop-blur-sm`,e),children:[(0,X.jsxs)(`button`,{type:`button`,onClick:()=>i(e=>!e),className:`flex w-full items-center gap-2 px-3 py-2.5 text-left hover:bg-accent/40 rounded-t-lg transition-colors`,children:[(0,X.jsx)(Re,{className:`h-4 w-4 text-cyan-500`}),(0,X.jsx)(`span`,{className:`text-xs font-semibold text-foreground flex-1 min-w-0 truncate`,children:`Mailbox`}),u>0&&(0,X.jsx)(`span`,{className:`inline-flex items-center px-1.5 py-0.5 rounded-full text-[10px] font-bold bg-yellow-100 dark:bg-yellow-900/40 text-yellow-700 dark:text-yellow-400`,children:u}),(0,X.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[d,` online`]})]}),!r&&(0,X.jsxs)(`div`,{className:`px-3 pb-3 space-y-2`,children:[t.length>0?(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsx)(`span`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wide`,children:`Messages`}),(0,X.jsxs)(`button`,{type:`button`,onClick:f,disabled:a,className:`flex items-center gap-1 text-[10px] text-muted-foreground hover:text-red-500 disabled:opacity-40 transition-colors`,title:`Delete all messages`,children:[(0,X.jsx)(at,{className:`h-3 w-3`}),a?`Deleting…`:`Delete all`]})]}),t.slice(0,8).map(e=>{let t=ec[e.type]??tn,n=e.readByCount>0;return(0,X.jsxs)(`div`,{className:Y(`flex items-start gap-2 px-2 py-1.5 rounded text-xs`,!n&&`bg-yellow-50 dark:bg-yellow-950/20`),children:[(0,X.jsx)(t,{className:Y(`h-3.5 w-3.5 mt-0.5 shrink-0`,n?`text-muted-foreground`:`text-yellow-600`)}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(`span`,{className:Y(`font-medium truncate`,!n&&`text-yellow-800 dark:text-yellow-300`),children:e.from}),e.completed&&(0,X.jsx)(Be,{className:`h-3 w-3 text-green-500 shrink-0`}),!n&&(0,X.jsx)(`span`,{className:`text-[9px] text-yellow-600 font-bold`,children:`NEW`})]}),(0,X.jsx)(`div`,{className:`text-muted-foreground truncate`,children:e.subject}),(0,X.jsxs)(`div`,{className:`text-[10px] text-muted-foreground/70 truncate`,children:[e.body.slice(0,60),e.body.length>60?`…`:``]})]}),(0,X.jsxs)(`div`,{className:`shrink-0 text-[10px] text-muted-foreground flex flex-col items-end gap-0.5`,children:[(0,X.jsx)(`span`,{children:tc(e.timestamp)}),n&&(0,X.jsxs)(`span`,{className:`flex items-center gap-0.5`,children:[(0,X.jsx)(Et,{className:`h-3 w-3`}),e.readByCount]})]})]},e.id)})]}):(0,X.jsxs)(`div`,{className:`text-xs text-muted-foreground py-2 text-center`,children:[(0,X.jsx)(We,{className:`h-4 w-4 mx-auto mb-1 opacity-40`}),`No messages yet.`]}),n.length>0&&(0,X.jsxs)(`div`,{className:`border-t border-border pt-2`,children:[(0,X.jsxs)(`div`,{className:`text-[10px] font-semibold text-muted-foreground mb-1 flex items-center gap-1`,children:[(0,X.jsx)(Wt,{className:`h-3 w-3`}),` Agents`]}),n.filter(e=>e.online).slice(0,5).map(e=>(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] text-muted-foreground py-0.5`,children:[(0,X.jsx)(`span`,{className:Y(`h-1.5 w-1.5 rounded-full`,e.online?`bg-green-500`:`bg-muted-foreground/30`)}),(0,X.jsx)(`span`,{className:`font-medium text-foreground/80`,children:e.name}),e.role&&(0,X.jsxs)(`span`,{className:`opacity-60`,children:[`(`,e.role,`)`]}),(0,X.jsx)(`span`,{className:`opacity-50`,children:e.status}),e.currentTool&&(0,X.jsx)(`span`,{className:`text-cyan-500`,children:e.currentTool}),(0,X.jsx)(`span`,{className:`ml-auto opacity-50`,children:tc(e.lastSeenAt)})]},e.agentId)),n.filter(e=>!e.online).length>0&&(0,X.jsxs)(`div`,{className:`text-[10px] text-muted-foreground/50 mt-0.5`,children:[`+`,n.filter(e=>!e.online).length,` offline`]})]})]})]})}function rc({fullView:e}){let[t,n]=(0,B.useState)([]),[r,i]=(0,B.useState)(!0),[a,o]=(0,B.useState)(!1),[s,c]=(0,B.useState)(``),[l,u]=(0,B.useState)(``),[d,f]=(0,B.useState)(!1),p=(0,B.useRef)(null),[m,h]=(0,B.useState)({open:!1,project:null,agentCount:0}),g=(0,B.useCallback)(()=>{V().send({type:`projects.list`})},[]);(0,B.useEffect)(()=>{i(!0);let e=V(),t=e.on(`projects.list`,e=>{let t=e.payload;n(t.projects??[]),i(!1)}),r=e.on(`projects.added`,e=>{let t=e.payload;t.slug?(Sr.success(t.message),g()):Sr.error(t.message)});return g(),()=>{t(),r()}},[g]);let _=e=>{if(!e)return`never`;let t=Date.now()-new Date(e).getTime(),n=Math.floor(t/6e4);if(n<1)return`just now`;if(n<60)return`${n}m ago`;let r=Math.floor(n/60);if(r<24)return`${r}h ago`;let i=Math.floor(r/24);return i===1?`yesterday`:i<30?`${i}d ago`:i<365?`${Math.floor(i/30)}mo ago`:`${Math.floor(i/365)}y ago`},v=(0,B.useCallback)(e=>{let t=W.getState().session?.id;if(t){let n=K.getState().getAgentsBySession(t).filter(e=>e.status===`running`);if(n.length>0){h({open:!0,project:e,agentCount:n.length});return}}y(e)},[]),y=(0,B.useCallback)(e=>{let t=V();t.send({type:`projects.select`,payload:{root:e.root,name:e.name}});let n=t.on(`projects.selected`,e=>{let t=e.payload;n();let r=t.message.match(/(https?:\/\/[^\s]+)/);r&&r[1]?(window.open(r[1],`_blank`),Sr.success(`Opening ${t.name} in a new tab...`)):Sr.info(t.message)})},[]),b=(0,B.useCallback)(()=>{let e=s.trim();if(!e){Sr.error(`Please enter a folder path.`);return}o(!0);let t=V();t.send({type:`projects.add`,payload:{root:e,name:l.trim()||void 0}});let n=t.on(`projects.added`,()=>{n(),o(!1),f(!1),c(``),u(``)})},[s,l]),x=m.open&&m.project&&(0,X.jsx)(Ho,{open:!0,onOpenChange:()=>h({open:!1,project:null,agentCount:0}),children:(0,X.jsxs)(Ko,{className:`sm:max-w-sm`,children:[(0,X.jsxs)(qo,{children:[(0,X.jsx)(Yo,{children:`Running Agents`}),(0,X.jsxs)(Xo,{children:[m.agentCount,` agent`,m.agentCount===1?` is`:`s are`,` running in the current session. Switching projects will stop them.`]})]}),(0,X.jsxs)(Jo,{children:[(0,X.jsx)($,{variant:`outline`,size:`sm`,onClick:()=>h({open:!1,project:null,agentCount:0}),children:`Cancel`}),(0,X.jsx)($,{size:`sm`,variant:`destructive`,onClick:()=>{let e=m.project;h({open:!1,project:null,agentCount:0}),y(e)},children:`Switch anyway`})]})]})}),S=[...t].sort((e,t)=>e.lastSeen&&t.lastSeen?t.lastSeen.localeCompare(e.lastSeen):e.lastSeen?-1:t.lastSeen?1:e.name.localeCompare(t.name)),C=(0,X.jsxs)(Ho,{open:d,onOpenChange:f,children:[(0,X.jsx)(Uo,{asChild:!0,children:(0,X.jsxs)($,{variant:`outline`,size:`sm`,className:`gap-1 h-7 text-xs`,children:[(0,X.jsx)(_t,{className:`h-3 w-3`}),`Register Project`]})}),(0,X.jsxs)(Ko,{className:`sm:max-w-md`,children:[(0,X.jsxs)(qo,{children:[(0,X.jsx)(Yo,{children:`Register New Project`}),(0,X.jsxs)(Xo,{children:[`Enter the absolute path to a project folder. The project will be added to`,` `,(0,X.jsx)(`code`,{className:`font-mono bg-muted/40 px-1 rounded text-xs`,children:`~/.wrongstack/projects.json`}),`.`]})]}),(0,X.jsxs)(`div`,{className:`space-y-3`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{htmlFor:`proj-folder`,className:`text-xs font-medium text-muted-foreground mb-1 block`,children:`Folder path`}),(0,X.jsx)(ss,{id:`proj-folder`,placeholder:`/home/user/my-project or C:\\Users\\me\\my-project`,value:s,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`&&p.current?.focus()}})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{htmlFor:`proj-name`,className:`text-xs font-medium text-muted-foreground mb-1 block`,children:`Project name (optional — defaults to folder name)`}),(0,X.jsx)(ss,{id:`proj-name`,ref:p,placeholder:`My Project`,value:l,onChange:e=>u(e.target.value),onKeyDown:e=>{e.key===`Enter`&&b()}})]})]}),(0,X.jsxs)(Jo,{children:[(0,X.jsx)($,{variant:`outline`,size:`sm`,onClick:()=>f(!1),children:`Cancel`}),(0,X.jsxs)($,{size:`sm`,onClick:b,disabled:a||!s.trim(),children:[a?(0,X.jsx)(L,{className:`h-3 w-3 animate-spin mr-1`}):null,`Register`]})]})]})]});if(r){let t=(0,X.jsx)(`div`,{className:`flex items-center justify-center py-6`,children:(0,X.jsx)(L,{className:`h-4 w-4 animate-spin text-muted-foreground`})});return e?(0,X.jsxs)(`div`,{className:`h-full flex flex-col overflow-hidden`,children:[(0,X.jsx)(`div`,{className:`px-3 py-2 border-b flex items-center justify-between`,children:(0,X.jsx)(`h2`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:`Projects`})}),(0,X.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:t})]}):t}let w=(0,X.jsx)(`div`,{className:Y(`space-y-1`,e&&`p-2`),children:S.map(e=>(0,X.jsxs)(`button`,{type:`button`,onClick:()=>v(e),className:`flex items-start gap-2 w-full text-left px-2 py-1.5 rounded border bg-card/40 text-xs hover:bg-accent hover:border-primary/40 transition-colors`,children:[(0,X.jsx)(xt,{className:`h-3.5 w-3.5 shrink-0 mt-0.5 text-muted-foreground`}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`div`,{className:`font-medium truncate`,children:e.name}),(0,X.jsx)(`div`,{className:`font-mono text-[10px] text-muted-foreground truncate`,children:e.root}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5 text-[10px] text-muted-foreground/60`,children:[(0,X.jsx)(`span`,{className:`font-mono`,children:e.slug}),e.lastSeen&&(0,X.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,X.jsx)(Pt,{className:`h-2.5 w-2.5`}),_(e.lastSeen)]})]})]}),(0,X.jsx)(ue,{className:`h-3 w-3 shrink-0 mt-1 text-muted-foreground/40`})]},e.slug))});return e?(0,X.jsxs)(`div`,{className:`h-full flex flex-col overflow-hidden`,children:[x,(0,X.jsxs)(`div`,{className:`px-3 py-2 border-b shrink-0`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsx)(`h2`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:`Projects`}),C]}),(0,X.jsxs)(`p`,{className:`text-[10px] text-muted-foreground/60 mt-0.5`,children:[`Known projects from`,` `,(0,X.jsx)(`code`,{className:`font-mono bg-muted/40 px-0.5 rounded`,children:`~/.wrongstack/projects.json`})]})]}),t.length===0?(0,X.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,X.jsxs)(`div`,{className:`text-xs text-muted-foreground italic py-2`,children:[`No projects registered. Use the button above or run`,` `,(0,X.jsx)(`code`,{className:`font-mono bg-muted/40 px-1 rounded`,children:`wstack`}),` `,`in a directory to register it.`]})}):(0,X.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:w}),(0,X.jsx)(`div`,{className:`px-3 py-2 border-t shrink-0`,children:(0,X.jsx)(`p`,{className:`text-[9px] text-muted-foreground/40 text-center`,children:`Click a project to open it in a new WebUI tab`})})]}):(0,X.jsxs)(`div`,{className:`space-y-2`,children:[x,(0,X.jsx)(`div`,{className:`flex items-center justify-between`,children:C}),t.length===0?(0,X.jsxs)(`div`,{className:`text-xs text-muted-foreground italic py-2`,children:[`No projects registered. Use the button above or run`,` `,(0,X.jsx)(`code`,{className:`font-mono bg-muted/40 px-1 rounded`,children:`wstack`}),` `,`in a directory to register it.`]}):w]})}var ic=[` `,`▁`,`▂`,`▃`,`▄`,`▅`,`▆`,`▇`,`█`],ac=12;function oc(e,t){return t===0?0:Math.min(8,Math.round(e/t*8))}function sc({bins:e,className:t,width:n=ac}){let r=Array.from({length:ac},(t,n)=>e.at(-(ac-n))??0),i=Math.max(...r,1);return i===1&&r.every(e=>e===0)?(0,X.jsx)(`span`,{className:t,"aria-label":`No activity`,title:`No activity yet`,children:`—`}):(0,X.jsx)(`span`,{className:t,"aria-label":`Activity sparkline: max ${i} events`,title:`Activity sparkline — peak ${i} events/bucket`,children:r.map((e,t)=>{let n=oc(e,i),r=ic[n];return(0,X.jsx)(`span`,{style:{color:n>=7?`hsl(var(--success))`:`hsl(var(--muted-foreground))`,opacity:n>0?void 0:.3},children:r},t)})})}var cc={running:{led:`text-[hsl(var(--success))]`,label:`running`,pulse:!0},completed:{led:`text-[hsl(var(--success))]`,label:`done`,pulse:!1},failed:{led:`text-destructive`,label:`failed`,pulse:!1},timeout:{led:`text-[hsl(var(--warning))]`,label:`timeout`,pulse:!1},stopped:{led:`text-muted-foreground`,label:`stopped`,pulse:!1}};function lc(e){return e<=0?`$0`:e>=.01?`$${e.toFixed(3)}`:`$${e.toFixed(5)}`.replace(/0+$/,``).replace(/\.$/,``)}function uc(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e)}function dc(e){let t=Math.floor(e/1e3);return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`}function fc({agent:e,onClose:t}){let n=cc[e.status],r=e.status===`running`,i=e.currentTool??e.lastTool,a=Date.now()-e.startedAt,[o,s]=(0,B.useState)(!1),l=K(e=>e.leaderId),u=e.id===l,d=(0,B.useCallback)(async e=>{try{await navigator.clipboard.writeText(e),s(!0),setTimeout(()=>s(!1),2e3)}catch{}},[]),f=e.ctxPct>=85?`bg-red-500/15 text-red-600 dark:text-red-400`:e.ctxPct>=70?`bg-amber-500/15 text-amber-600 dark:text-amber-400`:`bg-muted text-muted-foreground`;return(0,X.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-start justify-center pt-[10vh] bg-black/40 backdrop-blur-sm`,children:(0,X.jsxs)(`div`,{className:`w-full max-w-xl max-h-[80vh] overflow-y-auto rounded-xl border bg-card shadow-2xl`,children:[(0,X.jsxs)(`div`,{className:Y(`flex items-center justify-between px-4 py-3 border-b`,r?`border-primary/20`:`border-border`),children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`span`,{className:Y(`led`,n.led,n.pulse&&`led-pulse`)}),(0,X.jsx)(`h3`,{className:`text-sm font-semibold`,children:e.name}),u&&(0,X.jsx)(be,{className:`h-3.5 w-3.5 text-amber-500 shrink-0`,"aria-label":`leader`}),(0,X.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:n.label})]}),(0,X.jsx)(`button`,{type:`button`,onClick:t,className:`p-1 rounded-md hover:bg-muted transition-colors`,children:(0,X.jsx)(Ie,{className:`h-4 w-4`})})]}),(0,X.jsxs)(`div`,{className:`p-4 space-y-4`,children:[e.description&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground leading-relaxed`,children:e.description}),(0,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,X.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-3 py-2`,children:[(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Provider / Model`}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1 mt-0.5`,children:[(0,X.jsx)(c,{className:`h-3 w-3 text-muted-foreground`}),(0,X.jsxs)(`span`,{className:`text-xs font-mono font-medium`,children:[e.provider??`?`,`/`,e.model??`?`]})]})]}),(0,X.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-3 py-2`,children:[(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Elapsed`}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1 mt-0.5`,children:[(0,X.jsx)(Pe,{className:`h-3 w-3 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`text-xs font-mono tabular`,children:dc(a)}),r&&(0,X.jsx)(`span`,{className:`text-[10px] text-[hsl(var(--success))]`,children:`· running`})]})]}),(0,X.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-3 py-2`,children:[(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Iterations`}),(0,X.jsx)(`span`,{className:`block text-xs font-mono font-medium mt-0.5 tabular`,children:e.iteration})]}),(0,X.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-3 py-2`,children:[(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Tool Calls`}),(0,X.jsx)(`span`,{className:`block text-xs font-mono font-medium mt-0.5 tabular`,children:e.toolCalls})]}),(0,X.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-3 py-2`,children:[(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Cost`}),(0,X.jsx)(`span`,{className:`block text-xs font-mono font-medium mt-0.5 tabular`,children:lc(e.costUsd)})]}),e.extensions>0&&(0,X.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-3 py-2`,children:[(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Budget Extensions`}),(0,X.jsxs)(`span`,{className:`block text-xs font-mono font-medium mt-0.5 tabular`,children:[`⚡×`,e.extensions]})]})]}),r&&(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Activity`}),(0,X.jsx)(sc,{bins:e.sparklineBins,className:`font-mono`})]}),e.budgetWarning&&(0,X.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg bg-amber-500/10 border border-amber-500/20 text-xs`,children:[(0,X.jsx)(ze,{className:`h-3.5 w-3.5 text-amber-500 shrink-0`}),(0,X.jsxs)(`span`,{className:`text-amber-600 dark:text-amber-400`,children:[`⚡ hitting `,(0,X.jsx)(`strong`,{children:e.budgetWarning.kind}),` limit (`,e.budgetWarning.used,`/`,e.budgetWarning.limit,`) — extending`]})]}),e.maxContext>0&&(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between text-[10px]`,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`Context window`}),(0,X.jsxs)(`span`,{className:Y(`tabular font-medium`,f.replace(/bg-\S+\s*/g,``)),children:[e.ctxPct,`%`]})]}),(0,X.jsx)(`div`,{className:`h-1.5 w-full overflow-hidden rounded-full bg-muted`,children:(0,X.jsx)(`div`,{className:Y(`h-full rounded-full transition-all`,e.ctxPct>=85?`bg-destructive`:e.ctxPct>=70?`bg-[hsl(var(--warning))]`:`bg-primary`),style:{width:`${Math.min(200,Math.max(2,e.ctxPct))}%`}})}),(0,X.jsxs)(`div`,{className:`text-[10px] text-muted-foreground tabular text-right`,children:[uc(e.ctxTokens),` / `,uc(e.maxContext),` tokens`]})]}),i&&(0,X.jsxs)(`div`,{className:Y(`flex items-center gap-2 rounded-lg border px-3 py-2`,r?`border-primary/30 bg-primary/[0.04]`:`border-border bg-muted/30`),children:[(0,X.jsx)(He,{className:Y(`h-3.5 w-3.5`,r?`text-primary animate-pulse`:`text-muted-foreground`)}),(0,X.jsx)(`span`,{className:`text-xs font-mono`,children:i}),(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground ml-auto`,children:e.currentTool?`running…`:`last tool`})]}),e.error&&(0,X.jsxs)(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 p-3`,children:[(0,X.jsx)(`span`,{className:`text-[10px] font-semibold text-destructive uppercase tracking-wider`,children:`Error`}),(0,X.jsx)(`p`,{className:`text-xs text-destructive/90 mt-1 leading-relaxed`,children:e.error.message})]}),e.finalText?(0,X.jsxs)(`div`,{className:`rounded-lg border bg-muted/20 p-3`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between mb-1.5`,children:[(0,X.jsx)(`span`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wider`,children:`Final Output`}),(0,X.jsxs)(`button`,{type:`button`,onClick:()=>d(e.finalText),className:`flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] text-muted-foreground hover:text-foreground hover:bg-muted transition-colors`,title:`Copy output`,children:[o?(0,X.jsx)(pn,{className:`h-3 w-3 text-emerald-500`}):(0,X.jsx)(E,{className:`h-3 w-3`}),o?`Copied`:`Copy`]})]}),(0,X.jsx)(`pre`,{className:`text-xs whitespace-pre-wrap font-mono text-foreground/80 leading-relaxed max-h-64 overflow-y-auto`,children:e.finalText})]}):e.partialText?(0,X.jsxs)(`div`,{className:`rounded-lg border bg-muted/20 p-3`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between mb-1.5`,children:[(0,X.jsx)(`span`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wider`,children:`Live Output`}),(0,X.jsxs)(`button`,{type:`button`,onClick:()=>d(e.partialText),className:`flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] text-muted-foreground hover:text-foreground hover:bg-muted transition-colors`,title:`Copy output`,children:[o?(0,X.jsx)(pn,{className:`h-3 w-3 text-emerald-500`}):(0,X.jsx)(E,{className:`h-3 w-3`}),o?`Copied`:`Copy`]})]}),(0,X.jsx)(`pre`,{className:`text-xs whitespace-pre-wrap font-mono text-foreground/80 leading-relaxed max-h-48 overflow-y-auto`,children:e.partialText})]}):r?(0,X.jsxs)(`div`,{className:`rounded-lg border border-dashed border-border p-3 text-center`,children:[(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Waiting for output…`}),(0,X.jsx)(`p`,{className:`text-[10px] text-muted-foreground/60 mt-0.5`,children:`Output appears here as the agent streams text.`})]}):null,e.toolLog.length>0&&(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsxs)(`span`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wider`,children:[`Tool Log (`,e.toolLog.length,`)`]}),(0,X.jsxs)(`div`,{className:`max-h-40 overflow-y-auto space-y-0.5`,children:[e.toolLog.slice(0,15).map((e,t)=>(0,X.jsxs)(`div`,{className:Y(`flex items-center gap-2 rounded px-2 py-1 text-[10px]`,e.ok?`bg-muted/30`:`bg-destructive/5 border border-destructive/20`),children:[(0,X.jsx)(`span`,{className:Y(`led shrink-0`,e.ok?`text-[hsl(var(--success))]`:`text-destructive`)}),(0,X.jsx)(`span`,{className:`font-mono truncate flex-1`,children:e.name}),(0,X.jsxs)(`span`,{className:`tabular text-muted-foreground`,children:[e.durationMs,`ms`]}),!e.ok&&(0,X.jsx)(`span`,{className:`text-destructive font-medium`,children:`fail`})]},`${e.name}-${e.at}-${t}`)),e.toolLog.length>15&&(0,X.jsxs)(`p`,{className:`text-[9px] text-muted-foreground text-center px-2 py-0.5`,children:[`+`,e.toolLog.length-15,` more tools`]})]})]})]})]})})}function pc({a:e,onClick:t}){let n=cc[e.status],r=e.status===`running`,i=e.currentTool??e.lastTool;return(0,X.jsxs)(`button`,{type:`button`,onClick:t,className:Y(`flex min-w-[12rem] max-w-[15rem] flex-col gap-1 rounded-lg border p-2 transition-colors text-left cursor-pointer`,`hover:border-primary/40 hover:bg-primary/[0.06]`,r?`border-primary/30 bg-primary/[0.04]`:`border-border bg-card opacity-85`),children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,X.jsx)(`span`,{className:Y(`led shrink-0`,n.led,n.pulse&&`led-pulse`)}),(0,X.jsx)(`span`,{className:`truncate text-[11px] font-semibold text-foreground`,title:e.name,children:e.name}),(0,X.jsxs)(`span`,{className:`tabular ml-auto shrink-0 text-[10px] text-muted-foreground`,children:[e.iteration,`it · `,e.toolCalls,`t`]})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[e.model&&(0,X.jsxs)(`span`,{className:`flex items-center gap-0.5 text-[10px] text-muted-foreground truncate`,title:`${e.provider??``}/${e.model}`,children:[(0,X.jsx)(c,{className:`h-2.5 w-2.5 shrink-0`}),(0,X.jsx)(`span`,{className:`truncate font-mono`,children:e.model})]}),(0,X.jsx)(`span`,{className:`tabular text-[10px] text-foreground/75 ml-auto`,children:lc(e.costUsd)})]}),i&&(0,X.jsxs)(`div`,{className:Y(`flex items-center gap-1 text-[10px] truncate`,r?`text-primary`:`text-muted-foreground`),title:e.currentTool?`running ${i}`:`last: ${i}`,children:[(0,X.jsx)(He,{className:Y(`h-2.5 w-2.5 shrink-0`,r&&`animate-pulse`)}),(0,X.jsx)(`span`,{className:`truncate font-mono`,children:i})]}),r&&e.maxContext>0&&(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,title:`Context ${e.ctxPct}%`,children:[(0,X.jsx)(`div`,{className:`h-1 flex-1 overflow-hidden rounded-full bg-muted`,children:(0,X.jsx)(`div`,{className:Y(`h-full rounded-full transition-all`,e.ctxPct>=85?`bg-destructive`:e.ctxPct>=70?`bg-[hsl(var(--warning))]`:`bg-primary`),style:{width:`${Math.min(200,Math.max(2,e.ctxPct))}%`}})}),(0,X.jsx)(`span`,{className:`tabular text-[9px] text-muted-foreground`,children:e.maxContext>0?`${e.ctxPct}%`:`—`})]}),e.error&&(0,X.jsx)(`div`,{className:`truncate rounded bg-destructive/10 px-1 py-0.5 text-[9px] text-destructive`,title:e.error.message,children:e.error.message})]})}function mc({className:e}){let t=K(e=>e.agents),[r,i]=(0,B.useState)(!0),[a,o]=(0,B.useState)(null),s=(0,B.useMemo)(()=>{let e=Array.from(t.values());return e.sort((e,t)=>{let n=e.status===`running`?0:1,r=t.status===`running`?0:1;return n===r?e.startedAt-t.startedAt:n-r}),e},[t]),c=a?s.find(e=>e.id===a):null;if(s.length===0)return null;let l=s.filter(e=>e.status===`running`),u=s.filter(e=>e.status===`completed`),d=s.filter(e=>e.status===`failed`||e.status===`timeout`),f=s.reduce((e,t)=>e+(t.costUsd??0),0),p=r&&s.length>=3;return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:Y(`rounded-lg border border-border bg-card/50 backdrop-blur-sm overflow-hidden`,e),children:[(0,X.jsxs)(`button`,{type:`button`,onClick:()=>i(e=>!e),className:`flex w-full items-center gap-2 px-3 py-1.5 text-left hover:bg-muted/30 transition-colors`,children:[(0,X.jsx)(R,{className:`h-3.5 w-3.5 text-primary`}),(0,X.jsx)(`span`,{className:`text-[11px] font-semibold text-foreground`,children:`Fleet`}),(0,X.jsxs)(`span`,{className:`flex items-center gap-1.5 ml-auto text-[10px]`,children:[l.length>0&&(0,X.jsxs)(`span`,{className:`flex items-center gap-1 text-[hsl(var(--success))]`,children:[(0,X.jsx)(`span`,{className:`led led-pulse text-[hsl(var(--success))]`}),l.length]}),u.length>0&&(0,X.jsxs)(`span`,{className:`text-muted-foreground`,children:[u.length,` done`]}),d.length>0&&(0,X.jsxs)(`span`,{className:`text-destructive`,children:[d.length,` err`]}),f>0&&(0,X.jsx)(`span`,{className:`tabular text-foreground/70`,children:lc(f)})]}),p?(0,X.jsx)(n,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}):(0,X.jsx)(ut,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`})]}),!p&&(0,X.jsx)(`div`,{className:`flex gap-2 overflow-x-auto px-2 pb-2`,children:s.map(e=>(0,X.jsx)(pc,{a:e,onClick:()=>o(e.id)},e.id))})]}),c&&(0,X.jsx)(fc,{agent:c,onClose:()=>o(null)})]})}var hc={running:{led:`text-[hsl(var(--success))]`,label:`running`,pulse:!0},completed:{led:`text-[hsl(var(--success))]`,label:`done`,pulse:!1},failed:{led:`text-destructive`,label:`failed`,pulse:!1},timeout:{led:`text-[hsl(var(--warning))]`,label:`timeout`,pulse:!1},stopped:{led:`text-muted-foreground`,label:`stopped`,pulse:!1}};function gc(e){return e<=0?`$0`:e>=.01?`$${e.toFixed(3)}`:`$${e.toFixed(4)}`}function _c({agent:e,onClick:t}){let n=hc[e.status],r=e.status===`running`;return(0,X.jsxs)(`button`,{type:`button`,onClick:t,className:Y(`w-full text-left rounded-lg border px-2.5 py-2 transition-colors`,`hover:border-primary/40 hover:bg-primary/[0.04]`,r?`border-primary/30 bg-primary/[0.03]`:`border-border/60 bg-card/40`),children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,X.jsx)(`span`,{className:Y(`led shrink-0`,n.led,n.pulse&&`led-pulse`)}),(0,X.jsx)(`span`,{className:`truncate text-[11px] font-semibold`,title:e.name,children:e.name}),(0,X.jsxs)(`span`,{className:`tabular ml-auto shrink-0 text-[10px] text-muted-foreground`,children:[e.iteration,`it`]})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-0.5 min-w-0`,children:[e.model?(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground truncate font-mono`,children:e.model}):(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground italic`,children:`pending…`}),(0,X.jsx)(`span`,{className:`tabular ml-auto text-[10px] text-foreground/70`,children:gc(e.costUsd)})]}),(e.currentTool||e.lastTool)&&(0,X.jsxs)(`div`,{className:`flex items-center gap-1 mt-1 text-[10px] text-muted-foreground truncate`,children:[(0,X.jsx)(He,{className:Y(`h-2.5 w-2.5 shrink-0`,r&&`animate-pulse text-primary`)}),(0,X.jsx)(`span`,{className:`truncate font-mono`,children:e.currentTool??e.lastTool})]})]})}function vc(){let e=K(e=>e.agents),t=G(e=>e.setCurrentView),[n,r]=(0,B.useState)(null),i=(0,B.useMemo)(()=>{let t=Array.from(e.values());return t.sort((e,t)=>{let n=e.status===`running`?0:1,r=t.status===`running`?0:1;return n===r?e.startedAt-t.startedAt:n-r}),t},[e]),a=i.filter(e=>e.status===`running`).length,o=n?i.find(e=>e.id===n)??null:null;return i.length===0?(0,X.jsx)(`div`,{className:`flex-1 flex items-center justify-center p-4`,children:(0,X.jsxs)(`div`,{className:`text-center text-muted-foreground`,children:[(0,X.jsx)(R,{className:`h-8 w-8 mx-auto mb-3 opacity-20`}),(0,X.jsx)(`p`,{className:`text-sm font-medium`,children:`No agents yet`}),(0,X.jsx)(`p`,{className:`text-xs mt-1`,children:`Subagents appear here when the fleet is active.`})]})}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`px-3 py-2 border-b text-[10px] text-muted-foreground flex items-center gap-2`,children:[(0,X.jsx)(`span`,{className:`font-semibold uppercase tracking-wider`,children:`Fleet`}),(0,X.jsxs)(`span`,{className:`ml-auto tabular-nums`,children:[a>0?`${a} running · `:``,i.length,` total`]})]}),(0,X.jsx)(`div`,{className:`flex-1 overflow-y-auto p-2 space-y-1.5`,children:i.map(e=>(0,X.jsx)(_c,{agent:e,onClick:()=>r(e.id)},e.id))}),(0,X.jsx)(`div`,{className:`border-t px-3 py-2 shrink-0`,children:(0,X.jsxs)(`button`,{type:`button`,onClick:()=>t(`agents`),className:`w-full flex items-center justify-center gap-1.5 h-7 rounded-md border border-border text-[11px] text-muted-foreground hover:text-foreground hover:bg-accent transition-colors`,children:[(0,X.jsx)(rn,{className:`h-3 w-3`}),`Open full agents view`]})}),o&&(0,X.jsx)(fc,{agent:o,onClose:()=>r(null)})]})}var yc=e=>{let t=Date.parse(e);if(Number.isNaN(t))return``;let n=Date.now()-t;if(n<6e4)return`just now`;if(n<36e5)return`${Math.floor(n/6e4)}m ago`;if(n<864e5)return`${Math.floor(n/36e5)}h ago`;let r=Math.floor(n/864e5);return r<7?`${r}d ago`:new Date(t).toLocaleDateString()};function bc(e){return e.filter(e=>e.tokenTotal===0&&!e.isCurrent).map(e=>e.id)}function xc({historyQuery:e,setHistoryQuery:t,historyEntries:n,historyLoading:r,historyError:i,wsConnected:a,listSessions:o,resumeSession:s,deleteSession:c}){let l=G(e=>e.favoriteSessionIds),u=G(e=>e.toggleFavoriteSession),d=G(e=>e.sessionNicknames),f=G(e=>e.setSessionNickname),[p,m]=(0,B.useState)(null),[h,g]=(0,B.useState)(``),[_,v]=(0,B.useState)(null);(0,B.useEffect)(()=>{_&&n.some(e=>e.id===_&&e.isCurrent)&&v(null)},[_,n]);let y=(0,B.useCallback)(e=>{v(e),s(e),setTimeout(()=>v(t=>t===e?null:t),1e4)},[s]),b=(0,B.useMemo)(()=>bc(n),[n]),x=(0,B.useCallback)(async()=>{if(b.length!==0&&await ts({title:b.length===1?`Delete 1 empty session?`:`Delete ${b.length} empty sessions?`,message:`Sessions without any token usage are removed from disk.`,confirmLabel:`Delete`,danger:!0}))for(let e of b)c(e)},[b,c]),S=(()=>{let t=e.trim().toLowerCase(),r=t?n.filter(e=>e.title.toLowerCase().includes(t)||e.model.toLowerCase().includes(t)||e.provider.toLowerCase().includes(t)||e.id.toLowerCase().includes(t)):n,i=new Date;i.setHours(0,0,0,0);let a=i.getTime(),o=a-864e5,s=a-6*864e5,c={today:[],yesterday:[],week:[],older:[]};for(let e of r){let t=Date.parse(e.startedAt);if(Number.isNaN(t)){c.older.push(e);continue}t>=a?c.today.push(e):t>=o?c.yesterday.push(e):t>=s?c.week.push(e):c.older.push(e)}let u=new Set(l),d=r.filter(e=>u.has(e.id)),f=[];d.length&&f.push({label:`Favorites`,rows:d,star:!0});let p=e=>e.filter(e=>!u.has(e.id)),m=p(c.today),h=p(c.yesterday),g=p(c.week),_=p(c.older);return m.length&&f.push({label:`Today`,rows:m}),h.length&&f.push({label:`Yesterday`,rows:h}),g.length&&f.push({label:`This week`,rows:g}),_.length&&f.push({label:`Earlier`,rows:_}),f})();return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b`,children:[(0,X.jsx)(`span`,{className:`text-xs uppercase tracking-wider text-muted-foreground`,children:`Recent sessions`}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,children:[b.length>0&&(0,X.jsx)(`button`,{type:`button`,className:`h-6 w-6 inline-flex items-center justify-center rounded-md hover:bg-muted text-muted-foreground hover:text-destructive`,onClick:x,disabled:!a,title:`Delete ${b.length} empty session${b.length===1?``:`s`}`,children:(0,X.jsx)(at,{className:`h-3.5 w-3.5`})}),(0,X.jsx)(`button`,{type:`button`,className:`h-6 w-6 inline-flex items-center justify-center rounded-md hover:bg-muted`,onClick:()=>o(50),disabled:!a,title:`Refresh`,children:r?(0,X.jsx)(L,{className:`h-3.5 w-3.5 animate-spin`}):(0,X.jsx)(Mt,{className:`h-3.5 w-3.5`})})]})]}),n.length>3&&(0,X.jsx)(`div`,{className:`px-3 py-2 border-b`,children:(0,X.jsxs)(`div`,{className:`relative`,children:[(0,X.jsx)(wn,{className:`absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground/60`}),(0,X.jsx)(`input`,{type:`text`,value:e,onChange:e=>t(e.target.value),placeholder:`Filter title, model, provider…`,className:`w-full pl-7 pr-7 py-1 text-xs rounded-md bg-muted/40 border border-transparent focus:bg-background focus:border-input focus:outline-none focus:ring-1 focus:ring-ring placeholder:text-muted-foreground/50`}),e&&(0,X.jsx)(`button`,{type:`button`,onClick:()=>t(``),className:`absolute right-1 top-1/2 -translate-y-1/2 text-muted-foreground/60 hover:text-foreground p-0.5`,title:`Clear filter`,children:(0,X.jsx)(Ie,{className:`h-3 w-3`})})]})}),i&&(0,X.jsx)(`div`,{className:`px-4 py-2 text-xs text-destructive bg-destructive/5 border-b`,children:i}),(0,X.jsx)(cs,{className:`flex-1`,children:n.length===0&&!r?(0,X.jsxs)(`div`,{className:`text-center text-muted-foreground py-8 px-4`,children:[(0,X.jsx)(Pt,{className:`h-8 w-8 mx-auto mb-3 opacity-20`}),(0,X.jsx)(`p`,{className:`text-sm font-medium`,children:`No history yet`}),(0,X.jsx)(`p`,{className:`text-xs mt-1`,children:`Your conversations will appear here`})]}):S.length===0?(0,X.jsxs)(`div`,{className:`text-center text-muted-foreground py-8 px-4`,children:[(0,X.jsx)(wn,{className:`h-8 w-8 mx-auto mb-3 opacity-20`}),(0,X.jsx)(`p`,{className:`text-sm font-medium`,children:`No matches`}),(0,X.jsx)(`p`,{className:`text-xs mt-1`,children:`Try a different filter`})]}):(0,X.jsx)(`div`,{className:`p-2 space-y-3`,children:S.map(e=>(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsxs)(`div`,{className:Y(`sticky top-0 z-[1] px-1 pb-1 text-[10px] uppercase tracking-wider font-semibold bg-card/90 backdrop-blur-sm flex items-center gap-1`,e.star?`text-amber-500`:`text-muted-foreground/80`),children:[e.star&&(0,X.jsx)(Bt,{className:`h-3 w-3 fill-current`}),e.label,` `,(0,X.jsxs)(`span`,{className:`text-muted-foreground/50 font-normal normal-case ml-1`,children:[`(`,e.rows.length,`)`]})]}),e.rows.map(e=>(0,X.jsxs)(`div`,{className:Y(`group relative rounded-md border text-sm transition-colors`,e.isCurrent?`bg-primary/5 border-primary/40`:`bg-card border-border/60 hover:bg-muted/40 hover:border-primary/40`),children:[(0,X.jsx)(`button`,{type:`button`,disabled:e.isCurrent||p===e.id||_!==null,onClick:()=>y(e.id),onDoubleClick:t=>{t.stopPropagation(),m(e.id),g(d[e.id]??e.title??``)},className:`block w-full rounded-md px-3 py-2 pr-16 text-left disabled:cursor-default focus:outline-none focus-visible:ring-2 focus-visible:ring-ring`,children:(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[p===e.id?(0,X.jsx)(`input`,{value:h,onChange:e=>g(e.target.value),onClick:e=>e.stopPropagation(),onBlur:()=>{f(e.id,h),m(null)},onKeyDown:t=>{t.key===`Enter`?(t.preventDefault(),f(e.id,h),m(null)):t.key===`Escape`&&(t.preventDefault(),m(null))},placeholder:e.title||`Nickname`,className:`w-full text-sm bg-background border border-input rounded px-1.5 py-0.5 focus:outline-none focus:ring-1 focus:ring-ring`}):(0,X.jsx)(`div`,{className:`font-medium truncate text-foreground`,title:d[e.id]?`${d[e.id]} — original: ${e.title}`:`${e.title}\n\nDouble-click to rename`,children:d[e.id]||e.title||`(empty)`}),(0,X.jsxs)(`div`,{className:`text-[10px] text-muted-foreground font-mono truncate mt-0.5`,children:[e.provider,`/`,e.model]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] text-muted-foreground/80 mt-0.5`,children:[_===e.id?(0,X.jsxs)(`span`,{className:`flex items-center gap-1 text-primary font-medium`,children:[(0,X.jsx)(L,{className:`h-3 w-3 animate-spin`}),`resuming…`]}):(0,X.jsx)(`span`,{children:yc(e.startedAt)}),e.tokenTotal>0&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`opacity-50`,children:`·`}),(0,X.jsxs)(`span`,{className:`tabular-nums`,children:[e.tokenTotal.toLocaleString(),` tok`]})]}),e.isCurrent&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`opacity-50`,children:`·`}),(0,X.jsx)(`span`,{className:`text-primary font-medium`,children:`active`})]})]})]})}),(0,X.jsxs)(`div`,{className:`absolute right-2 top-2 flex items-center gap-1`,children:[(0,X.jsx)(`button`,{type:`button`,onClick:()=>u(e.id),className:Y(`transition-opacity hover:text-amber-500`,l.includes(e.id)?`opacity-100 text-amber-500`:`opacity-0 group-hover:opacity-100 text-muted-foreground`),title:l.includes(e.id)?`Unfavorite`:`Mark as favorite`,children:(0,X.jsx)(Bt,{className:Y(`h-3.5 w-3.5`,l.includes(e.id)&&`fill-current`)})}),!e.isCurrent&&(0,X.jsx)(`button`,{type:`button`,onClick:async()=>{await ts({title:`Delete session?`,message:`"${d[e.id]||e.title||`(empty)`}" will be removed from disk. This cannot be undone.`,confirmLabel:`Delete`,danger:!0})&&c(e.id)},className:`opacity-0 group-hover:opacity-100 transition-opacity text-muted-foreground hover:text-destructive`,title:`Delete session`,children:(0,X.jsx)(at,{className:`h-3.5 w-3.5`})})]})]},e.id))]},e.label))})})]})}function Sc(){let e=U(e=>e.wsConnected),{entries:t,loading:n,error:r}=nr(),{listSessions:i,resumeSession:a,deleteSession:o}=Z(),s=G(e=>e.setCurrentView),c=W(e=>e.session?.id),[l,u]=(0,B.useState)(``);return(0,B.useEffect)(()=>{e&&i(50)},[e,c,i]),(0,X.jsxs)(`div`,{className:`flex-1 flex flex-col overflow-hidden`,children:[(0,X.jsx)(xc,{historyQuery:l,setHistoryQuery:u,historyEntries:t,historyLoading:n,historyError:r,wsConnected:e,listSessions:i,resumeSession:a,deleteSession:o}),(0,X.jsx)(`div`,{className:`border-t px-3 py-2 shrink-0`,children:(0,X.jsxs)(`button`,{type:`button`,onClick:()=>s(`sessions`),className:`w-full flex items-center justify-center gap-1.5 h-7 rounded-md border border-border text-[11px] text-muted-foreground hover:text-foreground hover:bg-accent transition-colors`,children:[(0,X.jsx)(rn,{className:`h-3 w-3`}),`Open sessions dashboard`]})})]})}function Cc(e){return e<=0?`$0.000`:e>=.01?`$${e.toFixed(3)}`:`$${e.toFixed(4)}`}function wc(e){if(e<=0)return`--`;let t=Math.floor(e/1e3);if(t<60)return`${t}s`;let n=Math.floor(t/60);return n<60?`${n}m ${t%60}s`:`${Math.floor(n/60)}h ${n%60}m`}function Tc({icon:e,label:t,onClick:n,disabled:r,tone:i,title:a}){return(0,X.jsxs)(`button`,{type:`button`,onClick:n,disabled:r,title:a??t,className:Y(`flex items-center justify-center gap-1.5 h-8 rounded-md border text-[11px] font-medium transition-colors`,`disabled:opacity-40 disabled:cursor-not-allowed`,i===`primary`?`border-primary/40 bg-primary/10 text-primary hover:bg-primary/20`:i===`danger`?`border-destructive/40 bg-destructive/10 text-destructive hover:bg-destructive/20`:`border-border bg-card hover:bg-accent text-foreground/80`),children:[e,t]})}function Ec({label:e,value:t,sub:n}){return(0,X.jsxs)(`div`,{className:`flex flex-col p-2 rounded-lg bg-muted/40 border border-border/40 min-w-0`,children:[(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:e}),(0,X.jsx)(`span`,{className:`text-sm font-semibold tabular-nums truncate`,children:t}),n&&(0,X.jsx)(`span`,{className:`text-[9px] text-muted-foreground/70 truncate`,children:n})]})}function Dc({icon:e,label:t,right:n}){return(0,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[10px] uppercase tracking-wider text-muted-foreground font-semibold`,children:[e,t]}),n]})}function Oc({label:e,value:t,onChange:n,title:r}){return(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-2 py-1`,title:r,children:[(0,X.jsx)(`span`,{className:`text-xs text-foreground/80`,children:e}),(0,X.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":t,onClick:n,className:Y(`shrink-0 relative inline-flex h-4 w-7 rounded-full border transition-colors`,t?`bg-primary border-primary`:`bg-muted border-input hover:bg-muted/80`),children:(0,X.jsx)(`span`,{className:Y(`absolute top-0.5 left-0.5 h-2.5 w-2.5 rounded-full bg-background shadow transition-transform`,t&&`translate-x-3`)})})]})}function kc(){let{client:e,updatePrefs:n,switchAutonomy:r}=Z(),i=U(e=>e.wsConnected),a=U(e=>e.wsUrl),o=U(e=>e.provider),s=U(e=>e.model),l=U(e=>e.soundOnComplete),u=W(e=>e.session),d=W(e=>e.totalTokens),f=W(e=>e.cost),p=W(e=>e.iteration),m=W(e=>e.todos),h=W(e=>e.lastInputTokens),g=W(e=>e.maxContext),_=H(e=>e.messages),v=H(e=>e.isLoading),y=K(e=>e.agents),x=G(e=>e.pinnedIds),S=G(e=>e.unpinAll),w=G(e=>e.setModelSwitcherOpen),T=hr(),E=(0,B.useCallback)((e,t)=>{T.set({[e]:t}),n({[e]:t})},[T,n]),[D,O]=(0,B.useState)(!1),k=u?.startedAt??null,[A,j]=(0,B.useState)(()=>Date.now());(0,B.useEffect)(()=>{if(!k)return;let e=setInterval(()=>j(Date.now()),1e3);return()=>clearInterval(e)},[k]);let M=(0,B.useMemo)(()=>Array.from(y.values()).filter(e=>e.status===`running`).length,[y]),te=g>0&&h>0?Math.round(h/g*100):0,N=x.map(e=>_.find(t=>t.id===e)).filter(e=>!!e&&e.content.length>0),ne=e=>V(a)?.send?.(e);return(0,X.jsxs)(`div`,{className:`flex-1 overflow-y-auto`,children:[(0,X.jsxs)(`div`,{className:`px-3 py-2.5 border-b grid grid-cols-2 gap-1.5`,children:[v?(0,X.jsx)(Tc,{icon:(0,X.jsx)(Ct,{className:`h-3 w-3`}),label:`Abort`,tone:`danger`,onClick:()=>ne({type:`abort`,payload:{}}),disabled:!i}):(0,X.jsx)(Tc,{icon:(0,X.jsx)(kt,{className:`h-3 w-3`}),label:`New session`,tone:`primary`,onClick:()=>{e?.newSession?.(),G.getState().setCurrentView(`chat`)},disabled:!i,title:`Start a new session (Ctrl+N)`}),(0,X.jsx)(Tc,{icon:(0,X.jsx)(b,{className:`h-3 w-3`}),label:`Export`,onClick:()=>xa(),title:`Export chat as markdown (Ctrl+E)`}),(0,X.jsx)(Tc,{icon:(0,X.jsx)(An,{className:`h-3 w-3`}),label:`Compact`,onClick:()=>ne({type:`context.compact`,payload:{aggressive:!1}}),disabled:!i,title:`Compact the context window`}),(0,X.jsx)(Tc,{icon:(0,X.jsx)(me,{className:`h-3 w-3`}),label:`Clear`,onClick:()=>ne({type:`context.clear`}),disabled:!i,title:`Clear context (Ctrl+L)`})]}),(0,X.jsxs)(`button`,{type:`button`,onClick:()=>w(!0),className:`w-full px-4 py-2.5 border-b text-left hover:bg-muted/40 transition-colors`,title:`Change model (Ctrl+M)`,children:[(0,X.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground mb-0.5`,children:`Model`}),(0,X.jsxs)(`div`,{className:`font-mono text-xs truncate`,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:o||`—`}),(0,X.jsx)(`span`,{className:`text-muted-foreground/40 mx-1`,children:`/`}),(0,X.jsx)(`span`,{className:`font-medium`,children:s||`—`})]})]}),g>0&&(0,X.jsxs)(`div`,{className:`px-4 py-2.5 border-b space-y-1.5`,children:[(0,X.jsx)(`button`,{type:`button`,onClick:()=>O(!0),className:`w-full block text-left`,title:`Click for a context breakdown`,children:(0,X.jsx)(Dc,{icon:null,label:`Context`,right:(0,X.jsxs)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums font-mono`,children:[Q(h),`/`,Q(g),` · `,te,`%`]})})}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>O(!0),className:`w-full block`,title:`Click for a context breakdown`,children:(0,X.jsx)(Bi,{pct:te,tokens:h,maxTokens:g,showTokens:!0})})]}),(0,X.jsxs)(`div`,{className:`px-3 py-2.5 border-b space-y-1.5`,children:[(0,X.jsx)(Dc,{icon:(0,X.jsx)(c,{className:`h-3 w-3`}),label:`Session`}),(0,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-1.5`,children:[(0,X.jsx)(Ec,{label:`Messages`,value:_.length}),(0,X.jsx)(Ec,{label:`Elapsed`,value:k?wc(A-k):`--`}),(0,X.jsx)(Ec,{label:`Tokens`,value:Q(d.input+d.output),sub:`${Q(d.input)} in / ${Q(d.output)} out`}),(0,X.jsx)(Ec,{label:`Cost`,value:Cc(f)}),p&&(0,X.jsx)(Ec,{label:`Iteration`,value:p.index,sub:p.max?`of ${p.max}`:void 0}),y.size>0&&(0,X.jsx)(Ec,{label:`Agents`,value:y.size,sub:M>0?`${M} running`:void 0})]})]}),m.length>0&&(()=>{let e=m.filter(e=>e.status===`completed`).length,t=m.filter(e=>e.status===`in_progress`).length,n=Math.round(e/m.length*100),r=e===m.length;return(0,X.jsxs)(`div`,{className:`px-3 py-2.5 border-b space-y-1.5`,children:[(0,X.jsx)(Dc,{icon:(0,X.jsx)(fn,{className:`h-3 w-3`}),label:`Plan`,right:(0,X.jsxs)(`span`,{className:`tabular-nums text-[10px] text-muted-foreground`,children:[e,`/`,m.length]})}),(0,X.jsx)(`div`,{className:Y(`relative h-1.5 w-full overflow-hidden rounded-full bg-muted`,t>0&&`bar-sweep`),title:`${n}% complete`,children:(0,X.jsx)(`div`,{className:Y(`h-full rounded-full transition-all duration-500`,r?`bg-[hsl(var(--success))]`:`bg-primary`),style:{width:`${Math.max(n,t>0?4:0)}%`}})}),(0,X.jsx)(`ul`,{className:`space-y-0.5 max-h-56 overflow-y-auto pr-1 -mx-1`,children:m.map(e=>{let t=e.status===`completed`?Be:e.status===`in_progress`?ee:C,n=e.status===`in_progress`,r=e.status===`completed`?`text-[hsl(var(--success))] line-through opacity-60`:n?`text-foreground`:`text-muted-foreground`;return(0,X.jsxs)(`li`,{className:Y(`flex items-start gap-2 text-xs leading-snug rounded-md px-1.5 py-1 transition-colors`,n&&`bg-primary/10 ring-1 ring-inset ring-primary/20`,r),children:[(0,X.jsx)(t,{className:Y(`h-3.5 w-3.5 mt-0.5 shrink-0`,n&&`text-primary animate-pulse`)}),(0,X.jsx)(`span`,{className:`break-words`,children:n&&e.activeForm?e.activeForm:e.content})]},e.id)})})]})})(),N.length>0&&(0,X.jsxs)(`div`,{className:`px-3 py-2.5 border-b space-y-1.5`,children:[(0,X.jsx)(Dc,{icon:(0,X.jsx)(P,{className:`h-3 w-3 text-amber-500`}),label:`Pinned`,right:(0,X.jsx)(`button`,{type:`button`,onClick:S,className:`text-[10px] text-muted-foreground hover:text-destructive`,children:`Clear`})}),(0,X.jsx)(`ul`,{className:`space-y-1 max-h-48 overflow-y-auto pr-1`,children:N.map(e=>{let t=e.content.replace(/\s+/g,` `).slice(0,80);return(0,X.jsx)(`li`,{children:(0,X.jsxs)(`button`,{type:`button`,onClick:()=>{let t=document.querySelector(`[data-message-id="${e.id}"]`);t&&(t.scrollIntoView({behavior:`smooth`,block:`center`}),t.classList.add(`ring-2`,`ring-amber-500/60`),setTimeout(()=>{t.classList.remove(`ring-2`,`ring-amber-500/60`)},1600))},className:`w-full text-left text-xs px-2 py-1.5 rounded bg-muted/40 hover:bg-muted/70 border border-amber-500/20 leading-snug`,title:e.content.slice(0,400),children:[t,e.content.length>80?`…`:``]})},e.id)})})]}),(0,X.jsxs)(`div`,{className:`px-3 py-2.5 border-b space-y-1`,children:[(0,X.jsx)(Dc,{icon:(0,X.jsx)(Je,{className:`h-3 w-3`}),label:`Quick settings`}),(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-2 py-1`,children:[(0,X.jsx)(`span`,{className:`text-xs text-foreground/80`,children:`Autonomy`}),(0,X.jsxs)(`select`,{value:T.autonomy,onChange:e=>{let t=e.target.value;T.set({autonomy:t}),r(t)},className:`shrink-0 h-6 max-w-[150px] rounded-md border bg-background px-1.5 text-[11px]`,children:[(0,X.jsx)(`option`,{value:`off`,children:`Off`}),(0,X.jsx)(`option`,{value:`suggest`,children:`Suggest`}),(0,X.jsx)(`option`,{value:`auto`,children:`Auto`}),(0,X.jsx)(`option`,{value:`eternal`,children:`Eternal`}),(0,X.jsx)(`option`,{value:`eternal-parallel`,children:`Eternal Parallel`})]})]}),(0,X.jsx)(Oc,{label:`YOLO mode`,title:`Bypass tool confirmation prompts`,value:T.yolo,onChange:()=>E(`yolo`,!T.yolo)}),(0,X.jsx)(Oc,{label:`Refine prompts`,title:`Rewrite prompts before sending`,value:T.enhanceEnabled,onChange:()=>E(`enhanceEnabled`,!T.enhanceEnabled)}),(0,X.jsx)(Oc,{label:`Sound on completion`,title:`Play a soft chime when a run finishes`,value:l,onChange:()=>{let e=!U.getState().soundOnComplete;U.getState().setSoundOnComplete(e),e&&kr()}})]}),(0,X.jsxs)(`div`,{className:`px-4 py-2.5`,children:[(0,X.jsxs)(`div`,{className:Y(`flex items-center gap-2 text-[11px]`,i?`text-[hsl(var(--success))]`:`text-[hsl(var(--warning))]`),children:[i?(0,X.jsx)(ge,{className:`h-3.5 w-3.5`}):(0,X.jsx)(t,{className:`h-3.5 w-3.5`}),(0,X.jsx)(`span`,{className:`font-medium`,children:i?`Connected`:`Disconnected`}),(0,X.jsx)(`span`,{className:`text-muted-foreground font-mono truncate ml-auto`,title:a,children:a})]}),u&&(0,X.jsxs)(`div`,{className:`text-[10px] text-muted-foreground font-mono mt-1 truncate`,title:u.id,children:[`session `,u.id.slice(0,8)]})]}),(0,X.jsx)(Vi,{open:D,onClose:()=>O(!1)})]})}var Ac={chat:`Session`,agents:`Agents`,history:`History`,files:`Files`,projects:`Projects`,mailbox:`Mailbox`};function jc(){let e=G(e=>e.activeActivity),t=G(e=>e.setSidebarOpen),n=G(e=>e.sidebarWidth),r=G(e=>e.setSidebarWidth),i=U(e=>e.wsConnected),{client:a}=Z();return(0,B.useEffect)(()=>{if(e!==`files`||!i)return;q.getState().setTreeLoading(!0);let t=W.getState().cwd;a?.send({type:`files.tree`,payload:t?{path:t}:{}})},[e,i,a]),(0,X.jsxs)(`aside`,{style:{width:`${n}px`},className:`relative border-r bg-card flex flex-col shrink-0 overflow-hidden animate-slide-in`,children:[(0,X.jsx)(`div`,{onMouseDown:e=>{e.preventDefault();let t=e.clientX,i=n,a=e=>r(i+(e.clientX-t)),o=()=>{window.removeEventListener(`mousemove`,a),window.removeEventListener(`mouseup`,o),document.body.style.cursor=``,document.body.style.userSelect=``};window.addEventListener(`mousemove`,a),window.addEventListener(`mouseup`,o),document.body.style.cursor=`col-resize`,document.body.style.userSelect=`none`},onDoubleClick:()=>r(304),className:`group/handle absolute top-0 right-0 h-full w-2 cursor-col-resize z-10 flex items-center justify-end`,title:`Drag to resize · double-click to reset`,children:(0,X.jsx)(`div`,{className:`h-full w-px bg-border group-hover/handle:bg-primary/60 group-hover/handle:w-0.5 transition-all`})}),(0,X.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2.5 border-b shrink-0`,children:[(0,X.jsx)(`span`,{className:`text-xs font-semibold tracking-tight text-muted-foreground uppercase`,children:Ac[e]}),(0,X.jsx)($,{variant:`ghost`,size:`icon`,className:`h-6 w-6`,onClick:()=>t(!1),title:`Collapse panel (Ctrl+\\)`,children:(0,X.jsx)(Nn,{className:`h-3.5 w-3.5`})})]}),(0,X.jsxs)(`div`,{className:`flex-1 flex flex-col overflow-hidden`,children:[e===`chat`&&(0,X.jsx)(kc,{}),e===`agents`&&(0,X.jsx)(vc,{}),e===`history`&&(0,X.jsx)(Sc,{}),e===`files`&&(0,X.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:(0,X.jsx)($s,{})}),e===`projects`&&(0,X.jsx)(`div`,{className:`flex-1 overflow-y-auto p-3`,children:(0,X.jsx)(rc,{})}),e===`mailbox`&&(0,X.jsx)(`div`,{className:`flex-1 overflow-y-auto p-3`,children:(0,X.jsx)(nc,{})})]})]})}function Mc({sessionId:e,className:t}){let[n,i]=(0,B.useState)([]),[a,o]=(0,B.useState)(!1),[s,c]=(0,B.useState)(null),[l,u]=(0,B.useState)(null),[d,f]=(0,B.useState)(0),[p,m]=(0,B.useState)(!1),h=V(U(e=>e.wsUrl));(0,B.useEffect)(()=>{let t=[];return t.push(h.on(`collab.state`,t=>{let n=t.payload;n.sessionId===e&&i(n.participants??[])})),t.push(h.on(`collab.participant.joined`,t=>{let n=t.payload;n.sessionId===e&&i(e=>e.some(e=>e.participantId===n.participantId)?e:[...e,{participantId:n.participantId,role:n.role,joinedAt:n.joinedAt}])})),t.push(h.on(`collab.participant.left`,t=>{let n=t.payload;if(n.sessionId!==e)return;let r=n.participantId;i(e=>e.filter(e=>e.participantId!==r))})),t.push(h.on(`error`,e=>{let t=e.payload;t.phase===`collab`&&(u(t.message),o(!1))})),t.push(h.on(`collab.annotation.added`,t=>{let n=t.payload;n.sessionId===e&&(n.annotation?.resolved||f(e=>e+1))})),t.push(h.on(`collab.annotation.resolved`,t=>{t.payload.sessionId===e&&f(e=>Math.max(0,e-1))})),t.push(h.on(`collab.pause.granted`,t=>{t.payload.sessionId===e&&m(!0)})),t.push(h.on(`collab.pause.released`,t=>{t.payload.sessionId===e&&m(!1)})),()=>{for(let e of t)e()}},[h,e]);let g=(t=`observer`)=>{u(null),h.send({type:`collab.join`,payload:{sessionId:e,role:t}}),o(!0),c(t)};return n.length===0&&!l?(0,X.jsxs)(`div`,{className:Y(`flex items-center gap-2 px-3 py-2 rounded-md border border-dashed border-border bg-card/40`,t),children:[(0,X.jsx)(Wt,{className:`w-4 h-4 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`No live observers`}),(0,X.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[(0,X.jsxs)(`button`,{type:`button`,onClick:()=>g(`observer`),className:`inline-flex items-center gap-1 text-xs px-2 py-1 rounded bg-primary text-primary-foreground hover:bg-primary/90 transition-colors`,title:`Join as a read-only observer (Phase 1)`,children:[(0,X.jsx)(r,{className:`w-3 h-3`}),`observer`]}),(0,X.jsxs)(`button`,{type:`button`,onClick:()=>g(`annotator`),className:`inline-flex items-center gap-1 text-xs px-2 py-1 rounded border border-amber-500/40 bg-amber-500/10 text-amber-700 dark:text-amber-300 hover:bg-amber-500/20 transition-colors`,title:`Join as an annotator — leave inline notes on tool calls (Phase 2)`,children:[(0,X.jsx)(M,{className:`w-3 h-3`}),`annotator`]}),(0,X.jsxs)(`button`,{type:`button`,onClick:()=>g(`controller`),className:`inline-flex items-center gap-1 text-xs px-2 py-1 rounded border border-rose-500/40 bg-rose-500/10 text-rose-700 dark:text-rose-300 hover:bg-rose-500/20 transition-colors`,title:`Join as a controller — can pause the agent loop (Phase 3)`,children:[(0,X.jsx)(ae,{className:`w-3 h-3`}),`controller`]})]})]}):l?(0,X.jsxs)(`div`,{className:Y(`flex items-center gap-2 px-3 py-2 rounded-md border border-destructive/50 bg-destructive/10`,t),role:`alert`,children:[(0,X.jsxs)(`span`,{className:`text-xs text-destructive`,children:[`Collab: `,l]}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>{u(null),o(!1)},className:`ml-auto text-xs underline text-destructive`,children:`dismiss`})]}):(0,X.jsxs)(`div`,{className:Y(`flex items-center gap-2 px-3 py-2 rounded-md border border-emerald-500/40 bg-emerald-500/5`,t),children:[(0,X.jsxs)(`span`,{className:`relative flex h-2 w-2`,"aria-label":`Live`,children:[(0,X.jsx)(`span`,{className:`absolute inline-flex h-full w-full rounded-full bg-emerald-400 opacity-75 animate-ping`}),(0,X.jsx)(`span`,{className:`relative inline-flex rounded-full h-2 w-2 bg-emerald-500`})]}),(0,X.jsx)(Wt,{className:`w-4 h-4 text-emerald-700 dark:text-emerald-400`}),(0,X.jsxs)(`span`,{className:`text-xs font-medium text-emerald-700 dark:text-emerald-300`,children:[n.length,` `,n.length===1?`observer`:`observers`]}),d>0&&(0,X.jsxs)(`span`,{title:`${d} open annotation(s) — annotators reviewing this session`,className:`ml-2 inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded bg-amber-500/15 text-amber-700 dark:text-amber-300 border border-amber-500/30`,children:[(0,X.jsx)(M,{className:`w-3 h-3`}),d,` note`,d===1?``:`s`]}),p&&(0,X.jsxs)(`span`,{title:`Agent loop is paused — a controller is reviewing`,className:`ml-2 inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded bg-rose-500/15 text-rose-700 dark:text-rose-300 border border-rose-500/40`,children:[(0,X.jsx)(ae,{className:`w-3 h-3`}),`paused`]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1 ml-2`,children:[n.slice(0,3).map(e=>(0,X.jsxs)(`span`,{title:`Joined ${new Date(e.joinedAt).toLocaleTimeString()}`,className:`inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded bg-emerald-500/10 text-emerald-700 dark:text-emerald-300`,children:[(0,X.jsx)(Ot,{className:`w-3 h-3`}),e.role]},e.participantId)),n.length>3&&(0,X.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[`+`,n.length-3]})]}),a&&s===`controller`&&(p?(0,X.jsxs)(`button`,{type:`button`,onClick:()=>{h.send({type:`collab.resume`,payload:{sessionId:e}})},className:`ml-auto inline-flex items-center gap-1 text-xs px-2 py-1 rounded border border-rose-500/40 bg-rose-500/10 text-rose-700 dark:text-rose-300 hover:bg-rose-500/20 transition-colors`,title:`Resume the agent loop`,children:[(0,X.jsx)(ce,{className:`w-3 h-3`}),`Resume`]}):(0,X.jsxs)(`button`,{type:`button`,onClick:()=>{h.send({type:`collab.request_pause`,payload:{sessionId:e}})},className:`ml-auto inline-flex items-center gap-1 text-xs px-2 py-1 rounded border border-amber-500/40 bg-amber-500/10 text-amber-700 dark:text-amber-300 hover:bg-amber-500/20 transition-colors`,title:`Pause the agent before the next tool call`,children:[(0,X.jsx)(ae,{className:`w-3 h-3`}),`Pause agent`]})),a&&s!==`controller`&&(0,X.jsxs)(`button`,{type:`button`,onClick:()=>{h.send({type:`collab.leave`,payload:{sessionId:e}}),o(!1),i([])},className:`ml-auto inline-flex items-center gap-1 text-xs px-2 py-1 rounded border border-border hover:bg-muted transition-colors`,title:`Leave the observer session`,children:[(0,X.jsx)(ve,{className:`w-3 h-3`}),`Leave`]})]})}var Nc={up:(0,X.jsx)(Jt,{className:`h-3.5 w-3.5 text-emerald-500`}),down:(0,X.jsx)(un,{className:`h-3.5 w-3.5 text-red-500`}),stable:(0,X.jsx)(w,{className:`h-3.5 w-3.5 text-amber-500`})},Pc={active:{color:`text-emerald-600 dark:text-emerald-400`,bg:`bg-emerald-100 dark:bg-emerald-900/40`,label:`Active`},paused:{color:`text-amber-600 dark:text-amber-400`,bg:`bg-amber-100 dark:bg-amber-900/40`,label:`Paused`},completed:{color:`text-blue-600 dark:text-blue-400`,bg:`bg-blue-100 dark:bg-blue-900/40`,label:`Done`},failed:{color:`text-red-600 dark:text-red-400`,bg:`bg-red-100 dark:bg-red-900/40`,label:`Failed`},abandoned:{color:`text-stone-600 dark:text-stone-400`,bg:`bg-stone-100 dark:bg-stone-900/40`,label:`Abandoned`}};function Fc({goal:e,className:t}){let[r,i]=(0,B.useState)(!1);if((0,B.useEffect)(()=>{let e=V();e?.send?.({type:`goal.get`});let t=setInterval(()=>{e?.send?.({type:`goal.get`})},1e4);return()=>clearInterval(t)},[]),(0,B.useEffect)(()=>{(!e||e.goalState===`completed`||e.goalState===`failed`||e.goalState===`abandoned`)&&i(!0)},[e]),!e||e.goalState===`completed`||e.goalState===`failed`||e.goalState===`abandoned`)return null;let a=Pc[e.goalState],o=e.deliverables?.filter(e=>e.status===`done`).length??0,s=e.deliverables?.length??0,c=e.journal?.slice(-5).reverse()??[],l=e.progressTrend?Nc[e.progressTrend]:null;return(0,X.jsxs)(`div`,{className:Y(`rounded-lg border border-border bg-card/60 backdrop-blur-sm`,t),children:[(0,X.jsxs)(`button`,{type:`button`,onClick:()=>i(e=>!e),className:`flex w-full items-center gap-2 px-3 py-2.5 text-left hover:bg-accent/40 rounded-t-lg transition-colors`,children:[(0,X.jsx)(lt,{className:`h-4 w-4 text-rose-500`}),(0,X.jsx)(`span`,{className:`text-xs font-semibold text-foreground flex-1 min-w-0 truncate`,children:`Goal`}),(0,X.jsx)(`span`,{className:Y(`inline-flex items-center px-1.5 py-0.5 rounded-full text-[10px] font-medium shrink-0`,a.bg,a.color),children:a.label}),r?(0,X.jsx)(n,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}):(0,X.jsx)(ut,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`})]}),!r&&(0,X.jsxs)(`div`,{className:`px-3 pb-3 space-y-3 border-t pt-2`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`p`,{className:`text-xs text-foreground leading-relaxed whitespace-pre-wrap break-words`,children:e.goal}),e.refinedGoal&&e.refinedGoal!==e.goal&&(0,X.jsxs)(`div`,{className:`mt-1.5 p-2 rounded bg-accent/40 border border-border/50`,children:[(0,X.jsx)(`p`,{className:`text-[10px] text-muted-foreground mb-0.5 uppercase tracking-wider font-medium`,children:`Refined`}),(0,X.jsx)(`p`,{className:`text-xs leading-relaxed whitespace-pre-wrap break-words`,children:e.refinedGoal})]})]}),(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between text-[10px]`,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground uppercase tracking-wider font-medium`,children:`Progress`}),(0,X.jsxs)(`span`,{className:`flex items-center gap-1 tabular-nums`,children:[l,(0,X.jsxs)(`span`,{className:`font-medium text-foreground`,children:[e.progress,`%`]})]})]}),(0,X.jsx)(`div`,{className:`h-1.5 bg-muted rounded-full overflow-hidden`,children:(0,X.jsx)(`div`,{className:Y(`h-full transition-all duration-700 rounded-full`,e.progress>=80?`bg-emerald-500`:e.progress>=50?`bg-amber-500`:`bg-primary`),style:{width:`${e.progress>0?Math.max(2,e.progress):0}%`}})}),e.progressNote&&(0,X.jsx)(`p`,{className:`text-[10px] text-muted-foreground italic`,children:e.progressNote})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] text-muted-foreground`,children:[(0,X.jsx)(Pe,{className:`h-3 w-3`}),(0,X.jsx)(`span`,{className:`tabular-nums font-medium`,children:e.iterations}),(0,X.jsx)(`span`,{children:`iterations`}),e.lastStatus&&(0,X.jsx)(`span`,{className:`text-border`,children:`·`}),e.lastStatus&&(0,X.jsx)(`span`,{className:`truncate`,children:e.lastStatus})]}),s>0&&(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between text-[10px] text-muted-foreground uppercase tracking-wider font-medium`,children:[(0,X.jsx)(`span`,{children:`Deliverables`}),(0,X.jsxs)(`span`,{className:`tabular-nums`,children:[o,`/`,s]})]}),(0,X.jsx)(`ul`,{className:`space-y-0.5`,children:e.deliverables?.map(e=>(0,X.jsxs)(`li`,{className:`flex items-start gap-1.5 text-[11px]`,children:[e.status===`done`?(0,X.jsx)(Be,{className:`h-3 w-3 text-emerald-500 mt-0.5 shrink-0`}):(0,X.jsx)(C,{className:`h-3 w-3 text-muted-foreground/50 mt-0.5 shrink-0`}),(0,X.jsx)(`span`,{className:Y(`leading-snug`,e.status===`done`?`text-muted-foreground line-through`:`text-foreground`),children:e.text})]},e.id))})]}),c.length>0&&(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(`p`,{className:`text-[10px] text-muted-foreground uppercase tracking-wider font-medium`,children:`Recent Activity`}),(0,X.jsx)(`div`,{className:`space-y-1`,children:c.map((e,t)=>(0,X.jsxs)(`div`,{className:`flex items-start gap-1.5 text-[10px] text-muted-foreground`,children:[(0,X.jsxs)(`span`,{className:`font-mono tabular-nums shrink-0 text-foreground/60`,children:[`#`,e.iteration]}),(0,X.jsx)(`span`,{className:`truncate`,children:e.task||e.status||e.progressNote||`…`})]},`${e.iteration}-${t}`))})]})]})]})}var Ic={in_progress:0,pending:1,completed:2};function Lc(){let[e,t]=(0,B.useState)([]),[n,r]=(0,B.useState)(new Set),i=V(),a=(0,B.useRef)(null);(0,B.useEffect)(()=>(i.send({type:`todos.get`}),a.current=i.on(`todos.updated`,e=>{let n=e?.payload;n?.todos&&t(n.todos)}),()=>{a.current?.()}),[i]);let o=(0,B.useCallback)(e=>{i.removeTodo(e)},[i]),s=(0,B.useCallback)(e=>{if(e.status===`in_progress`)return;let t=e.status===`completed`?`pending`:`completed`;i.updateTodoStatus(e.id,t)},[i]),c=[...e].sort((e,t)=>(Ic[e.status]??9)-(Ic[t.status]??9)),l=c.filter(e=>e.status===`in_progress`),u=c.filter(e=>e.status===`pending`),d=c.filter(e=>e.status===`completed`),f=d.length>0,p=n.has(`completed`),m=e=>{r(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},h=e=>{let t=e.status===`in_progress`&&e.activeForm?e.activeForm:e.content,n=e.status===`in_progress`,r=e.status===`completed`,i=!n;return(0,X.jsxs)(`div`,{onClick:()=>i&&s(e),className:Y(`px-3 py-1.5 flex items-start gap-2 text-[13px] group transition-colors`,i&&`cursor-pointer hover:bg-accent/40`,n?`bg-yellow-50/40 dark:bg-yellow-950/25`:r?`bg-emerald-50/20 dark:bg-emerald-950/10`:`bg-background`),role:i?`button`:void 0,"aria-label":i?`Toggle ${e.content}`:void 0,tabIndex:i?0:void 0,onKeyDown:t=>{i&&(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),s(e))},children:[(0,X.jsx)(`span`,{className:`mt-0.5 shrink-0`,children:r?(0,X.jsx)(Be,{className:`w-3.5 h-3.5 text-emerald-500`}):n?(0,X.jsx)(Pe,{className:`w-3.5 h-3.5 text-yellow-500 animate-spin`}):(0,X.jsx)(C,{className:Y(`w-3.5 h-3.5 transition-colors`,`text-muted-foreground/40 group-hover:text-emerald-400`)})}),(0,X.jsx)(`span`,{className:Y(`leading-snug flex-1 min-w-0`,n?`text-yellow-800 dark:text-yellow-200 font-medium`:r?`text-muted-foreground line-through`:`text-foreground/80`),children:t}),(0,X.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),o(e.id)},className:`shrink-0 p-0.5 rounded opacity-0 group-hover:opacity-50 hover:opacity-100 hover:bg-destructive/10 transition-all`,title:`Remove todo`,"aria-label":`Remove "${e.content}"`,children:(0,X.jsx)(at,{className:`w-3 h-3 text-muted-foreground`})})]},e.id)};return e.length===0?null:(0,X.jsxs)(`div`,{className:`rounded-lg border border-border bg-card/50 backdrop-blur-sm overflow-hidden`,children:[(0,X.jsxs)(`div`,{className:`px-3 py-1.5 flex items-center gap-2 border-b border-border/50`,children:[(0,X.jsx)(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:`Todos`}),(0,X.jsxs)(`span`,{className:`tabular text-[10px] text-muted-foreground ml-auto`,children:[d.length,`/`,e.length]})]}),l.length>0&&(0,X.jsx)(`div`,{className:`border-b border-border/30 last:border-b-0`,children:l.map(h)}),u.length>0&&(0,X.jsx)(`div`,{className:`border-b border-border/30 last:border-b-0`,children:u.map(h)}),f&&(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`button`,{type:`button`,onClick:()=>m(`completed`),className:`w-full px-3 py-1 flex items-center gap-1.5 text-[10px] text-muted-foreground hover:text-foreground transition-colors`,children:(0,X.jsxs)(`span`,{className:`tabular`,children:[p?`▶`:`▼`,` `,d.length,` completed`]})}),!p&&d.map(h)]})]})}var Rc={pending:{icon:(0,X.jsx)(C,{className:`w-3.5 h-3.5`}),label:`Pending`,color:`text-muted-foreground/50`},in_progress:{icon:(0,X.jsx)(Pe,{className:`w-3.5 h-3.5 animate-spin`}),label:`In Progress`,color:`text-yellow-500`},blocked:{icon:(0,X.jsx)(ae,{className:`w-3.5 h-3.5`}),label:`Blocked`,color:`text-orange-500`},failed:{icon:(0,X.jsx)(N,{className:`w-3.5 h-3.5`}),label:`Failed`,color:`text-red-500`},review:{icon:(0,X.jsx)(v,{className:`w-3.5 h-3.5`}),label:`Review`,color:`text-blue-500`},completed:{icon:(0,X.jsx)(Be,{className:`w-3.5 h-3.5`}),label:`Done`,color:`text-emerald-500`}},zc={critical:`text-red-600 dark:text-red-400`,high:`text-orange-600 dark:text-orange-400`,medium:`text-yellow-600 dark:text-yellow-400`,low:`text-muted-foreground`},Bc={feature:`⚡`,bugfix:`🐛`,refactor:`♻️`,docs:`📝`,test:`🧪`,chore:`🔧`};function Vc(){let[e,t]=(0,B.useState)([]),[n,r]=(0,B.useState)(new Set),i=V(),a=(0,B.useRef)(null);(0,B.useEffect)(()=>(i.getTasks(),a.current=i.on(`tasks.updated`,e=>{let n=e?.payload;n?.tasks&&t(n.tasks)}),()=>{a.current?.()}),[i]);let o=(0,B.useCallback)(e=>{r(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),s=(0,B.useCallback)((e,t)=>{i.updateTaskStatus(e,t)},[i]),c=[`in_progress`,`blocked`,`review`,`pending`,`failed`,`completed`],l=new Map;for(let t of e){let e=l.get(t.status)??[];e.push(t),l.set(t.status,e)}let u=l.get(`completed`)?.length??0;return e.length===0?null:(0,X.jsxs)(`div`,{className:`rounded-lg border border-border bg-card/50 backdrop-blur-sm overflow-hidden`,children:[(0,X.jsxs)(`div`,{className:`px-3 py-1.5 flex items-center gap-2 border-b border-border/50`,children:[(0,X.jsx)(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:`Tasks`}),(0,X.jsxs)(`span`,{className:`tabular text-[10px] text-muted-foreground ml-auto`,children:[u,`/`,e.length]})]}),c.map(e=>{let t=l.get(e);if(!t||t.length===0)return null;let r=Rc[e],i=n.has(e);return(0,X.jsxs)(`div`,{className:`border-b border-border/30 last:border-b-0`,children:[(0,X.jsx)(`button`,{type:`button`,onClick:()=>o(e),className:`w-full px-3 py-1 flex items-center gap-1.5 text-[10px] text-muted-foreground hover:text-foreground transition-colors`,children:(0,X.jsxs)(`span`,{className:`tabular`,children:[i?`▶`:`▼`,` `,t.length,` `,r.label]})}),!i&&t.map(e=>(0,X.jsxs)(`div`,{className:Y(`px-3 py-1.5 flex items-start gap-2 text-[13px] group`,e.status===`in_progress`?`bg-yellow-50/40 dark:bg-yellow-950/25`:``),children:[(0,X.jsx)(`span`,{className:Y(`mt-0.5 shrink-0`,r.color),children:r.icon}),(0,X.jsxs)(`span`,{className:`leading-snug flex-1 min-w-0`,children:[(0,X.jsxs)(`span`,{className:Y(e.status===`completed`?`text-muted-foreground line-through`:`text-foreground/80`),children:[Bc[e.type],` `,e.title]}),e.priority!==`medium`&&(0,X.jsx)(`span`,{className:Y(`ml-1 text-[10px]`,zc[e.priority]),children:e.priority}),e.assignee&&(0,X.jsxs)(`span`,{className:`ml-1 text-[10px] text-muted-foreground`,children:[`@`,e.assignee]}),e.estimateHours&&(0,X.jsxs)(`span`,{className:`ml-1 text-[10px] text-muted-foreground`,children:[e.estimateHours,`h`]})]}),(0,X.jsxs)(`div`,{className:`flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity shrink-0`,children:[e.status!==`in_progress`&&e.status!==`completed`&&(0,X.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),s(e.id,`in_progress`)},className:`px-1.5 py-0.5 text-[9px] rounded bg-primary/15 text-primary hover:bg-primary/25 transition-colors`,title:`Start`,children:`Start`}),e.status===`in_progress`&&(0,X.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),s(e.id,`completed`)},className:`px-1.5 py-0.5 text-[9px] rounded bg-[hsl(var(--success)/0.15)] text-[hsl(var(--success))] hover:bg-[hsl(var(--success)/0.25)] transition-colors`,title:`Complete`,children:`Done`}),e.status!==`completed`&&e.status!==`failed`&&(0,X.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),s(e.id,`failed`)},className:`px-1.5 py-0.5 text-[9px] rounded bg-destructive/15 text-destructive hover:bg-destructive/25 transition-colors`,title:`Mark failed`,children:`Fail`})]})]},e.id))]},e)})]})}var Hc={open:{icon:(0,X.jsx)(C,{className:`w-3.5 h-3.5`}),label:`Open`,color:`text-muted-foreground/50`},in_progress:{icon:(0,X.jsx)(Pe,{className:`w-3.5 h-3.5 animate-spin`}),label:`In Progress`,color:`text-yellow-500`},done:{icon:(0,X.jsx)(Be,{className:`w-3.5 h-3.5`}),label:`Done`,color:`text-emerald-500`}};function Uc(){let[e,t]=(0,B.useState)([]),[n,r]=(0,B.useState)(new Set),i=V(),a=(0,B.useRef)(null);(0,B.useEffect)(()=>(i.getPlan(),a.current=i.on(`plan.updated`,e=>{let n=e?.payload;n?.plan?.items&&t(n.plan.items)}),()=>{a.current?.()}),[i]);let o=(0,B.useCallback)(e=>{r(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),s=(0,B.useCallback)((e,t)=>{i.updatePlanItem(e.id,t)},[i]),c=[`in_progress`,`open`,`done`],l=new Map;for(let t of e){let e=l.get(t.status)??[];e.push(t),l.set(t.status,e)}let u=l.get(`done`)?.length??0;return e.length===0?null:(0,X.jsxs)(`div`,{className:`rounded-lg border border-border bg-card/50 backdrop-blur-sm overflow-hidden`,children:[(0,X.jsxs)(`div`,{className:`px-3 py-1.5 flex items-center gap-2 border-b border-border/50`,children:[(0,X.jsx)(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:`📋 Plan`}),(0,X.jsxs)(`span`,{className:`tabular text-[10px] text-muted-foreground ml-auto`,children:[u,`/`,e.length]})]}),c.map(e=>{let t=l.get(e);if(!t||t.length===0)return null;let r=Hc[e],i=n.has(e);return(0,X.jsxs)(`div`,{className:`border-b border-border/30 last:border-b-0`,children:[(0,X.jsx)(`button`,{type:`button`,onClick:()=>o(e),className:`w-full px-3 py-1 flex items-center gap-1.5 text-[10px] text-muted-foreground hover:text-foreground transition-colors`,children:(0,X.jsxs)(`span`,{className:`tabular`,children:[i?`▶`:`▼`,` `,t.length,` `,r.label]})}),!i&&t.map(e=>(0,X.jsxs)(`div`,{className:Y(`px-3 py-1.5 flex items-start gap-2 text-[13px] group`,e.status===`in_progress`?`bg-yellow-50/40 dark:bg-yellow-950/25`:``),children:[(0,X.jsx)(`span`,{className:Y(`mt-0.5 shrink-0`,r.color),children:r.icon}),(0,X.jsx)(`span`,{className:Y(`leading-snug flex-1 min-w-0`,e.status===`done`?`text-muted-foreground line-through`:`text-foreground/80`),children:e.title}),(0,X.jsxs)(`div`,{className:`flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity shrink-0`,children:[e.status===`open`&&(0,X.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),s(e,`in_progress`)},className:`px-1.5 py-0.5 text-[9px] rounded bg-primary/15 text-primary hover:bg-primary/25 transition-colors`,title:`Start`,children:`Start`}),e.status!==`done`&&(0,X.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),s(e,`done`)},className:`px-1.5 py-0.5 text-[9px] rounded bg-[hsl(var(--success)/0.15)] text-[hsl(var(--success))] hover:bg-[hsl(var(--success)/0.25)] transition-colors`,title:`Mark done`,children:`Done`}),e.status===`done`&&(0,X.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),s(e,`open`)},className:`px-1.5 py-0.5 text-[9px] rounded bg-muted text-muted-foreground hover:bg-accent hover:text-foreground transition-colors`,title:`Reopen`,children:`Reopen`})]})]},e.id))]},e)})]})}var Wc=[{id:`todos`,label:`Todos`,icon:`✅`},{id:`tasks`,label:`Tasks`,icon:`📋`},{id:`plan`,label:`Plan`,icon:`🗺️`}];function Gc(){let[e,t]=(0,B.useState)(`todos`);return(0,X.jsxs)(`div`,{className:`rounded-lg border border-border bg-card/50 backdrop-blur-sm overflow-hidden`,children:[(0,X.jsx)(`div`,{className:`flex border-b border-border/50 bg-muted/30`,children:Wc.map(n=>(0,X.jsxs)(`button`,{type:`button`,onClick:()=>t(n.id),className:Y(`flex items-center gap-1 px-3 py-1.5 text-[11px] font-medium transition-colors`,`border-b-2 -mb-px`,e===n.id?`border-primary text-foreground bg-background`:`border-transparent text-muted-foreground hover:text-foreground hover:bg-accent/30`),children:[(0,X.jsx)(`span`,{className:`text-xs`,children:n.icon}),n.label]},n.id))}),(0,X.jsx)(`div`,{className:Y(e===`todos`?`block`:`hidden`),children:(0,X.jsx)(Lc,{})}),(0,X.jsx)(`div`,{className:Y(e===`tasks`?`block`:`hidden`),children:(0,X.jsx)(Vc,{})}),(0,X.jsx)(`div`,{className:Y(e===`plan`?`block`:`hidden`),children:(0,X.jsx)(Uc,{})})]})}var Kc={autophase:{active:`bg-primary/15 border-primary/40 text-primary`,idle:`text-primary/80 hover:bg-primary/10`},goal:{active:`bg-rose-500/15 border-rose-500/40 text-rose-600 dark:text-rose-400`,idle:`text-rose-600/80 dark:text-rose-400/80 hover:bg-rose-500/10`},fleet:{active:`bg-emerald-500/15 border-emerald-500/40 text-emerald-600 dark:text-emerald-400`,idle:`text-emerald-600/80 dark:text-emerald-400/80 hover:bg-emerald-500/10`},work:{active:`bg-amber-500/15 border-amber-500/40 text-amber-600 dark:text-amber-400`,idle:`text-amber-600/80 dark:text-amber-400/80 hover:bg-amber-500/10`},worktrees:{active:`bg-violet-500/15 border-violet-500/40 text-violet-600 dark:text-violet-400`,idle:`text-violet-600/80 dark:text-violet-400/80 hover:bg-violet-500/10`},collab:{active:`bg-cyan-500/15 border-cyan-500/40 text-cyan-600 dark:text-cyan-400`,idle:`text-muted-foreground hover:bg-muted/60`}};function qc({section:e,icon:t,label:n,value:r,active:i,pulse:a,onClick:o}){let s=Kc[e];return(0,X.jsxs)(`button`,{type:`button`,onClick:o,title:i?`Collapse ${n}`:`Expand ${n}`,className:Y(`flex items-center gap-1.5 h-6 px-2 rounded-full border text-[11px] font-medium shrink-0 transition-colors`,i?s.active:Y(`border-transparent`,s.idle)),children:[(0,X.jsx)(`span`,{className:Y(a&&`animate-pulse`),children:t}),n,r&&(0,X.jsx)(`span`,{className:`tabular-nums opacity-80`,children:r})]})}function Jc({sessionId:e}){let{selectAutoPhase:t,toggleAutoPhaseAutonomous:n}=Z(),r=G(e=>e.dockSection),i=G(e=>e.toggleDockSection),a=G(e=>e.setCurrentView),o=fr(e=>e.goal),s=pr(e=>e),c=rr(e=>e.worktrees),l=rr(e=>e.baseBranch),u=W(e=>e.todos),d=K(e=>e.agents),f=(0,B.useCallback)(e=>t(e),[t]),p=(0,B.useCallback)(()=>n(!s.autonomous),[n,s.autonomous]),[m,g]=(0,B.useState)(`graph`),_=d.size,v=(0,B.useMemo)(()=>Array.from(d.values()).filter(e=>e.status===`running`).length,[d]),y=u.filter(e=>e.status===`completed`).length,b=u.some(e=>e.status===`in_progress`),x=s.phases.length>0,S=(0,B.useRef)(s.phases.length);(0,B.useEffect)(()=>{let e=G.getState();S.current===0&&s.phases.length>0&&e.dockSection===null&&e.setDockSection(`autophase`),s.phases.length===0&&e.dockSection===`autophase`&&e.setDockSection(null),S.current=s.phases.length},[s.phases.length]);let C={autophase:x,goal:o!==null,fleet:_>0,work:!0,worktrees:c.length>0,collab:!0},w=r&&C[r]?r:null;return(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1`,children:[C.autophase&&(0,X.jsx)(qc,{section:`autophase`,icon:(0,X.jsx)(h,{className:`h-3 w-3`}),label:`AutoPhase`,value:`${s.overallPercent}%`,active:w===`autophase`,pulse:s.activePhaseId!=null,onClick:()=>i(`autophase`)}),C.goal&&o&&(0,X.jsx)(qc,{section:`goal`,icon:(0,X.jsx)(lt,{className:`h-3 w-3`}),label:`Goal`,value:`${o.progress}%`,active:w===`goal`,pulse:o.goalState===`active`,onClick:()=>i(`goal`)}),C.fleet&&(0,X.jsx)(qc,{section:`fleet`,icon:(0,X.jsx)(R,{className:`h-3 w-3`}),label:`Fleet`,value:`${v}/${_}`,active:w===`fleet`,pulse:v>0,onClick:()=>i(`fleet`)}),(0,X.jsx)(qc,{section:`work`,icon:(0,X.jsx)(fn,{className:`h-3 w-3`}),label:`Work`,value:u.length>0?`${y}/${u.length}`:void 0,active:w===`work`,pulse:b,onClick:()=>i(`work`)}),C.worktrees&&(0,X.jsx)(qc,{section:`worktrees`,icon:(0,X.jsx)(pt,{className:`h-3 w-3`}),label:`Worktrees`,value:String(c.length),active:w===`worktrees`,onClick:()=>i(`worktrees`)}),(0,X.jsx)(qc,{section:`collab`,icon:(0,X.jsx)(Wt,{className:`h-3 w-3`}),label:`Collab`,active:w===`collab`,onClick:()=>i(`collab`)})]}),w===`autophase`&&x&&(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(`div`,{className:`flex justify-end`,children:(0,X.jsxs)($,{variant:`outline`,size:`sm`,className:`h-6 gap-1 text-[10px]`,onClick:()=>a(`autophase`),children:[(0,X.jsx)(Ve,{className:`h-3 w-3`}),`Full view`]})}),(0,X.jsx)(na,{phases:s.phases,activePhaseId:s.activePhaseId??void 0,overallPercent:s.overallPercent,autonomous:s.autonomous,onPhaseClick:f,onToggleAutonomous:p,className:`w-72 shrink-0`})]}),w===`goal`&&(0,X.jsx)(Fc,{goal:o}),w===`fleet`&&(0,X.jsx)(mc,{}),w===`worktrees`&&(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(`div`,{className:`flex items-center gap-2`,children:[`graph`,`lanes`].map(e=>(0,X.jsx)(`button`,{type:`button`,onClick:()=>g(e),className:Y(`text-[10px] px-2 py-0.5 rounded-full border transition-colors capitalize`,m===e?`bg-primary/10 border-primary/30 text-primary`:`border-border text-muted-foreground hover:text-foreground`),children:e},e))}),m===`graph`?(0,X.jsx)(fa,{worktrees:c,baseBranch:l||`HEAD`}):(0,X.jsx)(ga,{worktrees:c,baseBranch:l||`HEAD`})]}),(0,X.jsx)(`div`,{className:Y(w===`work`?`block`:`hidden`),id:`panel-work`,children:(0,X.jsx)(Gc,{})}),(0,X.jsx)(`div`,{className:Y(w===`collab`?`block`:`hidden`),children:(0,X.jsx)(Mc,{sessionId:e})})]})}var Yc=B.forwardRef(({className:e,inset:t,children:r,...i},a)=>(0,X.jsxs)(hn,{ref:a,className:Y(`flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent`,t&&`pl-8`,e),...i,children:[r,(0,X.jsx)(n,{className:`ml-auto h-4 w-4`})]}));Yc.displayName=hn.displayName;var Xc=B.forwardRef(({className:e,...t},n)=>(0,X.jsx)(Nt,{ref:n,className:Y(`z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2`,e),...t}));Xc.displayName=Nt.displayName;var Zc=B.forwardRef(({className:e,sideOffset:t=4,...n},r)=>(0,X.jsx)(Gt,{children:(0,X.jsx)(Vt,{ref:r,sideOffset:t,className:Y(`z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2`,e),...n})}));Zc.displayName=Vt.displayName;var Qc=B.forwardRef(({className:e,inset:t,...n},r)=>(0,X.jsx)(nn,{ref:r,className:Y(`relative flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&>svg]:size-4 [&>svg]:shrink-0`,t&&`pl-8`,e),...n}));Qc.displayName=nn.displayName;var $c=B.forwardRef(({className:e,children:t,checked:n,...r},i)=>(0,X.jsxs)(dn,{ref:i,className:Y(`relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50`,e),checked:n,...r,children:[(0,X.jsx)(`span`,{className:`absolute left-2 flex h-3.5 w-3.5 items-center justify-center`,children:(0,X.jsx)(wt,{children:(0,X.jsx)(pn,{className:`h-4 w-4`})})}),t]}));$c.displayName=dn.displayName;var el=B.forwardRef(({className:e,children:t,...n},r)=>(0,X.jsxs)(sn,{ref:r,className:Y(`relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50`,e),...n,children:[(0,X.jsx)(`span`,{className:`absolute left-2 flex h-3.5 w-3.5 items-center justify-center`,children:(0,X.jsx)(wt,{children:(0,X.jsx)(C,{className:`h-2 w-2 fill-current`})})}),t]}));el.displayName=sn.displayName;var tl=B.forwardRef(({className:e,inset:t,...n},r)=>(0,X.jsx)(Ye,{ref:r,className:Y(`px-2 py-1.5 text-sm font-semibold`,t&&`pl-8`,e),...n}));tl.displayName=Ye.displayName;var nl=B.forwardRef(({className:e,...t},n)=>(0,X.jsx)(nt,{ref:n,className:Y(`-mx-1 my-1 h-px bg-muted`,e),...t}));nl.displayName=nt.displayName;var rl=({className:e,...t})=>(0,X.jsx)(`span`,{className:Y(`ml-auto text-xs tracking-widest opacity-60`,e),...t});rl.displayName=`DropdownMenuShortcut`;function il({current:e,max:t,className:n,showLabel:r=!0}){let i=Math.min(e,t),a=Math.max(0,t-i),o=t>0?i/t*100:0,s=o>=90?`text-destructive`:o>=70?`text-[hsl(var(--warning))]`:`text-[hsl(var(--success))]`;return(0,X.jsxs)(`span`,{className:n,title:`Fleet concurrency: ${e}/${t}`,children:[(0,X.jsxs)(`span`,{"aria-hidden":`true`,className:`font-mono text-[10px] tracking-tight`,children:[`[`,(0,X.jsx)(`span`,{className:s,children:`█`.repeat(i)}),(0,X.jsx)(`span`,{className:`text-[hsl(var(--muted))]`,children:`░`.repeat(a)}),`]`]}),r&&(0,X.jsxs)(`span`,{className:`ml-1.5 tabular-nums text-[10px] text-muted-foreground font-mono`,children:[e,`/`,t]})]})}function al(e){let t=Date.now()-e;return t<5e3?`just now`:t<6e4?`${Math.floor(t/1e3)}s ago`:t<36e5?`${Math.floor(t/6e4)}m ago`:`${Math.floor(t/36e5)}h ago`}var ol={spawned:`🚀`,task_started:`▶`,tool_executed:`⚡`,iteration_summary:`🔄`,budget_extended:`⚡`,task_completed:`✅`,ctx_pct:`💬`,leader_updated:`👑`};function sl({events:e,max:t=20,className:n}){let r=e.slice(0,t);return r.length===0?(0,X.jsx)(`div`,{className:`py-4 text-center text-xs text-muted-foreground ${n??``}`,children:`No events yet.`}):(0,X.jsx)(`div`,{className:`space-y-0.5 overflow-y-auto max-h-48 ${n??``}`,children:r.map(e=>(0,X.jsxs)(`div`,{className:`flex items-start gap-2 text-[10px] leading-tight py-0.5 px-1 rounded hover:bg-accent/50 transition-colors`,children:[(0,X.jsx)(`span`,{className:`shrink-0 w-5 text-center`,"aria-hidden":`true`,children:ol[e.kind]??`·`}),(0,X.jsx)(`span`,{className:`shrink-0 w-12 text-right text-muted-foreground font-mono tabular-nums`,children:al(e.timestamp)}),(0,X.jsx)(`span`,{className:`truncate text-foreground/90`,children:e.message}),e.value!==void 0&&e.kind===`tool_executed`&&(0,X.jsx)(`span`,{className:`ml-auto shrink-0 tabular-nums text-muted-foreground font-mono`,children:e.value>=1e3?`${(e.value/1e3).toFixed(1)}s`:`${e.value}ms`}),e.value!==void 0&&e.kind===`ctx_pct`&&(0,X.jsxs)(`span`,{className:`ml-auto shrink-0 tabular-nums text-muted-foreground font-mono`,children:[e.value,`%`]})]},e.id))})}function cl(e){return e<=0?`$0`:e>=.01?`$${e.toFixed(3)}`:`$${e.toFixed(5)}`.replace(/0+$/,``).replace(/\.$/,``)}function ll(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e)}function ul(e){let t=Math.floor(e/1e3),n=Math.floor(t/60),r=Math.floor(n/60);return r>0?`${r}h ${n%60}m`:n>0?`${n}m ${t%60}s`:`${t}s`}var dl={running:{led:`bg-emerald-500`,label:`running`,pulse:!0,color:`text-emerald-500`},completed:{led:`bg-emerald-500`,label:`done`,pulse:!1,color:`text-emerald-500`},failed:{led:`bg-destructive`,label:`failed`,pulse:!1,color:`text-destructive`},timeout:{led:`bg-amber-500`,label:`timeout`,pulse:!1,color:`text-amber-500`},stopped:{led:`bg-muted-foreground`,label:`stopped`,pulse:!1,color:`text-muted-foreground`}};function fl({agent:e,now:t}){let[r,i]=(0,B.useState)(!1),[a,o]=(0,B.useState)(!1),s=dl[e.status],l=e.status===`running`,u=(0,B.useCallback)(async e=>{try{await navigator.clipboard.writeText(e),i(!0),setTimeout(()=>i(!1),2e3)}catch{}},[]),d=e.toolLog.reduce((e,t)=>e+t.durationMs,0),f=e.toolLog.length>0?Math.round(d/e.toolLog.length):0,p=(0,B.useMemo)(()=>{let t=new Set;return e.toolLog.forEach(e=>t.add(e.name)),t.size},[e.toolLog]),m=e.partialText||e.finalText||void 0,h=!e.finalText&&!!e.partialText;return(0,X.jsxs)(`div`,{className:`h-full flex flex-col`,children:[(0,X.jsxs)(`div`,{className:`shrink-0 border-b bg-card p-4 space-y-3`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,X.jsx)(`div`,{className:`flex items-center justify-center w-10 h-10 rounded-lg bg-primary/10`,children:(0,X.jsx)(R,{className:`h-5 w-5 text-primary`})}),(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`span`,{className:`text-base font-semibold`,children:e.name}),(0,X.jsx)(`span`,{className:Y(`px-2 py-0.5 rounded text-[10px] font-medium uppercase tracking-wider`,e.status===`running`?`bg-emerald-500/15 text-emerald-600 dark:text-emerald-400`:e.status===`failed`||e.status===`timeout`?`bg-destructive/15 text-destructive`:`bg-muted text-muted-foreground`),children:s.label})]}),(0,X.jsxs)(`span`,{className:`text-[10px] text-muted-foreground font-mono`,children:[`session: `,e.sessionId?.slice(0,12),`…`]})]})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] text-muted-foreground`,children:[l&&(0,X.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(It,{className:`h-3.5 w-3.5`}),(0,X.jsx)(`span`,{className:`tabular-nums font-mono`,children:ul(Math.max(0,t-e.startedAt))})]}),(0,X.jsx)(`span`,{className:Y(`led`,s.led,l&&`led-pulse`)})]})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-2 rounded-lg bg-muted/30`,children:[(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground uppercase tracking-wider`,children:`Activity`}),(0,X.jsx)(sc,{bins:e.sparklineBins,className:`font-mono text-[9px]`}),e.budgetWarning&&(0,X.jsxs)(`span`,{className:`ml-auto flex items-center gap-1 text-[10px] text-amber-500`,children:[(0,X.jsx)(ze,{className:`h-3 w-3`}),`budget warning`]})]}),e.description&&(0,X.jsxs)(`div`,{className:`px-3 py-2 rounded-lg bg-muted/20 border border-border/50`,children:[(0,X.jsx)(`span`,{className:`text-[9px] text-muted-foreground uppercase tracking-wider`,children:`Current Task`}),(0,X.jsx)(`p`,{className:`text-xs mt-1 text-foreground/80`,children:e.description})]})]}),(0,X.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-4 space-y-4`,children:[(0,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,X.jsxs)(`div`,{className:`rounded-lg border bg-card p-3`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-[9px] text-muted-foreground uppercase tracking-wider mb-2`,children:[(0,X.jsx)(c,{className:`h-3 w-3`}),` Provider / Model`]}),(0,X.jsxs)(`div`,{className:`text-sm font-mono font-medium`,children:[e.provider??`?`,`/`,e.model??`?`]})]}),(0,X.jsxs)(`div`,{className:`rounded-lg border bg-card p-3`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-[9px] text-muted-foreground uppercase tracking-wider mb-2`,children:[(0,X.jsx)(ct,{className:`h-3 w-3`}),` Performance`]}),(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsxs)(`div`,{className:`flex justify-between text-[11px]`,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`Iterations`}),(0,X.jsx)(`span`,{className:`font-mono font-medium`,children:e.iteration})]}),(0,X.jsxs)(`div`,{className:`flex justify-between text-[11px]`,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`Tool Calls`}),(0,X.jsx)(`span`,{className:`font-mono font-medium`,children:e.toolCalls})]}),(0,X.jsxs)(`div`,{className:`flex justify-between text-[11px]`,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`Unique Tools`}),(0,X.jsx)(`span`,{className:`font-mono font-medium`,children:p})]})]})]}),(0,X.jsxs)(`div`,{className:`rounded-lg border bg-card p-3`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-[9px] text-muted-foreground uppercase tracking-wider mb-2`,children:[(0,X.jsx)(k,{className:`h-3 w-3`}),` Cost`]}),(0,X.jsx)(`div`,{className:`text-lg font-mono font-bold text-emerald-500`,children:cl(e.costUsd)}),(0,X.jsxs)(`div`,{className:`text-[10px] text-muted-foreground mt-1`,children:[`avg `,f,`ms per tool`]})]}),(0,X.jsxs)(`div`,{className:`rounded-lg border bg-card p-3`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-[9px] text-muted-foreground uppercase tracking-wider mb-2`,children:[(0,X.jsx)(ie,{className:`h-3 w-3`}),` Context`]}),(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsxs)(`div`,{className:`flex justify-between text-[11px]`,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`Tokens`}),(0,X.jsx)(`span`,{className:`font-mono font-medium`,children:ll(e.ctxTokens)})]}),(0,X.jsx)(`div`,{className:`h-2 w-full rounded-full bg-muted overflow-hidden`,children:(0,X.jsx)(`div`,{className:Y(`h-full rounded-full transition-all`,e.ctxPct>=85?`bg-destructive`:e.ctxPct>=70?`bg-amber-500`:`bg-emerald-500`),style:{width:`${Math.min(200,e.ctxPct)}%`}})}),(0,X.jsxs)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums font-mono`,children:[e.ctxPct,`% used`]})]})]})]}),e.currentTool&&(0,X.jsxs)(`div`,{className:Y(`rounded-lg border px-4 py-3 flex items-center gap-3`,l?`border-primary/30 bg-primary/[0.04]`:`border-border bg-muted/30`),children:[(0,X.jsx)(He,{className:Y(`h-4 w-4`,l?`text-primary animate-pulse`:`text-muted-foreground`)}),(0,X.jsx)(`span`,{className:`text-sm font-mono font-medium`,children:e.currentTool}),l?(0,X.jsxs)(`span`,{className:`ml-auto flex items-center gap-1.5 text-[10px] text-primary`,children:[(0,X.jsx)(L,{className:`h-3 w-3 animate-spin`}),` running…`]}):(0,X.jsx)(`span`,{className:`ml-auto text-[10px] text-muted-foreground`,children:`completed`})]}),m?(0,X.jsxs)(`div`,{className:`rounded-lg border bg-card`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b bg-muted/30`,children:[(0,X.jsx)(`span`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wider flex items-center gap-2`,children:h?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-blue-500 animate-pulse`}),`Live Output`]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Ke,{className:`h-3 w-3`}),`Final Output`]})}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>u(m),className:`flex items-center gap-1 px-2 py-1 rounded text-[10px] text-muted-foreground hover:text-foreground hover:bg-muted transition-colors`,children:r?`✓ Copied`:`Copy`})]}),(0,X.jsx)(`pre`,{className:`p-4 text-xs whitespace-pre-wrap font-mono text-foreground/80 leading-relaxed max-h-64 overflow-y-auto`,children:m})]}):l?(0,X.jsxs)(`div`,{className:`rounded-lg border border-dashed border-border p-6 text-center`,children:[(0,X.jsx)(L,{className:`h-6 w-6 mx-auto mb-2 text-muted-foreground/50 animate-spin`}),(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Waiting for output…`})]}):null,e.budgetWarning&&(0,X.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3 rounded-lg bg-amber-500/10 border border-amber-500/20`,children:[(0,X.jsx)(ze,{className:`h-5 w-5 text-amber-500 shrink-0`}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`span`,{className:`text-sm font-medium text-amber-600 dark:text-amber-400`,children:`⚡ Budget Warning`}),(0,X.jsxs)(`p`,{className:`text-[11px] text-amber-600/80 dark:text-amber-400/80 mt-0.5`,children:[`Hitting `,e.budgetWarning.kind,` limit (`,e.budgetWarning.used,`/`,e.budgetWarning.limit,`)`]})]})]}),e.extensions>0&&(0,X.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3 rounded-lg bg-amber-500/10 border border-amber-500/20`,children:[(0,X.jsx)(ze,{className:`h-5 w-5 text-amber-500 shrink-0`}),(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`span`,{className:`text-sm font-medium`,children:[e.extensions,` Budget Extension`,e.extensions===1?``:`s`]}),(0,X.jsxs)(`p`,{className:`text-[11px] text-muted-foreground mt-0.5`,children:[`Agent extended its budget `,e.extensions,` time`,e.extensions===1?``:`s`,` due to long-running tasks`]})]})]}),e.error&&(0,X.jsxs)(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 p-4`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,X.jsx)(N,{className:`h-4 w-4 text-destructive`}),(0,X.jsx)(`span`,{className:`text-[10px] font-semibold text-destructive uppercase tracking-wider`,children:`Error`})]}),(0,X.jsx)(`p`,{className:`text-sm text-destructive/90`,children:e.error.message})]}),e.failureReason&&(0,X.jsxs)(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 p-4`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,X.jsx)(N,{className:`h-4 w-4 text-destructive`}),(0,X.jsx)(`span`,{className:`text-[10px] font-semibold text-destructive uppercase tracking-wider`,children:`Failure Reason`})]}),(0,X.jsx)(`p`,{className:`text-sm text-destructive/90`,children:e.failureReason})]}),e.toolLog.length>0&&(0,X.jsxs)(`div`,{className:`rounded-lg border bg-card`,children:[(0,X.jsxs)(`button`,{type:`button`,onClick:()=>o(!a),className:`w-full flex items-center justify-between px-4 py-2 border-b bg-muted/30 hover:bg-muted/50 transition-colors`,children:[(0,X.jsxs)(`span`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wider flex items-center gap-2`,children:[(0,X.jsx)(He,{className:`h-3 w-3`}),`Tool Log (`,e.toolLog.length,` calls)`]}),(0,X.jsx)(n,{className:Y(`h-4 w-4 text-muted-foreground transition-transform`,a&&`rotate-90`)})]}),(0,X.jsx)(`div`,{className:Y(`overflow-hidden transition-all`,a?`max-h-[500px]`:`max-h-48`),children:(0,X.jsx)(`div`,{className:`p-2 space-y-0.5`,children:e.toolLog.map((e,t)=>(0,X.jsxs)(`div`,{className:Y(`flex items-center gap-3 rounded px-3 py-2 text-[11px]`,e.ok?`bg-muted/30 hover:bg-muted/50`:`bg-destructive/5 border border-destructive/20`),children:[(0,X.jsx)(`span`,{className:Y(`led shrink-0`,e.ok?`bg-emerald-500`:`bg-destructive`)}),(0,X.jsx)(`span`,{className:Y(`font-mono font-medium w-20 shrink-0`,e.ok?`text-foreground`:`text-destructive`),children:e.name}),(0,X.jsx)(`span`,{className:`text-muted-foreground tabular-nums text-[10px]`,children:e.durationMs>=1e3?`${(e.durationMs/1e3).toFixed(2)}s`:`${e.durationMs}ms`}),!e.ok&&(0,X.jsx)(`span`,{className:`ml-auto text-[10px] text-destructive font-medium`,children:`Failed`}),(0,X.jsx)(`span`,{className:`ml-auto text-[9px] text-muted-foreground tabular-nums`,children:new Date(e.at).toLocaleTimeString()})]},`${e.name}-${e.at}-${t}`))})})]})]})]})}function pl({agent:e,isSelected:t,isLeader:n,onClick:r}){let i=dl[e.status],a=e.status===`running`;return(0,X.jsxs)(`button`,{type:`button`,onClick:r,className:Y(`w-full text-left grid grid-cols-[140px_60px_1fr_60px_60px_60px_60px_50px_50px] items-center gap-x-2 px-3 py-1.5 rounded-md text-xs transition-colors`,t?`bg-primary/15 ring-1 ring-primary/40`:`hover:bg-accent/50`,a&&!t&&`bg-muted/30`),children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1 min-w-0`,children:[(0,X.jsx)(`span`,{className:Y(`led shrink-0`,i.led,i.pulse&&`led-pulse`)}),(0,X.jsx)(`span`,{className:`truncate font-medium`,children:e.name}),n&&(0,X.jsx)(be,{className:`h-3 w-3 shrink-0 text-amber-500`,"aria-label":`leader`})]}),(0,X.jsx)(`span`,{className:Y(`text-[10px] tabular-nums`,a?`text-emerald-500`:`text-muted-foreground`),children:i.label}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1 min-w-0`,children:[(0,X.jsx)(sc,{bins:e.sparklineBins,className:`font-mono text-[9px]`}),e.budgetWarning&&(0,X.jsx)(`span`,{title:`⚡ hitting ${e.budgetWarning.kind} limit (${e.budgetWarning.used}/${e.budgetWarning.limit})`,children:(0,X.jsx)(ze,{className:`h-3 w-3 shrink-0 text-amber-500`,"aria-label":`budget warning`})})]}),(0,X.jsxs)(`span`,{className:`tabular-nums text-muted-foreground text-[10px]`,children:[e.iteration,`it`]}),(0,X.jsxs)(`span`,{className:`tabular-nums text-muted-foreground text-[10px]`,children:[e.toolCalls,`tc`]}),(0,X.jsx)(`span`,{className:`tabular-nums font-mono text-[10px]`,children:cl(e.costUsd)}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-0.5 min-w-0`,children:[(0,X.jsx)(`div`,{className:`h-1.5 w-full rounded-full bg-muted overflow-hidden`,children:(0,X.jsx)(`div`,{className:Y(`h-full rounded-full transition-all`,e.ctxPct>=85?`bg-destructive`:e.ctxPct>=70?`bg-amber-500`:`bg-emerald-500`),style:{width:`${Math.min(200,e.ctxPct)}%`}})}),(0,X.jsx)(`span`,{className:`text-[9px] tabular-nums text-muted-foreground font-mono leading-none`,children:e.maxContext>0?`${e.ctxPct}%`:`—`})]}),(0,X.jsx)(`span`,{className:`tabular-nums text-[10px] text-muted-foreground`,children:e.extensions>0?`⚡×${e.extensions}`:`—`}),(0,X.jsx)(`span`,{className:`text-[9px] text-destructive truncate`,title:e.failureReason,children:e.failureReason??``})]})}function ml({onClose:e,onSelectAgent:t,isOverlay:n=!1}){let r=K(e=>e.agents),i=K(e=>e.leaderId),a=K(e=>e.fleetTokensIn),o=K(e=>e.fleetTokensOut),s=K(e=>e.fleetConcurrency),c=K(e=>e.fleetConcurrencyMax),l=K(e=>e.eventTimeline),[u,d]=(0,B.useState)(null),[f,p]=(0,B.useState)(Date.now());(0,B.useEffect)(()=>{let e=setInterval(()=>p(Date.now()),1e3);return()=>clearInterval(e)},[]);let m=(0,B.useMemo)(()=>{let e=Array.from(r.values());return e.sort((e,t)=>{if(e.id===i)return-1;if(t.id===i)return 1;let n=e.status===`running`?0:1,r=t.status===`running`?0:1;return n===r?e.startedAt-t.startedAt:n-r}),e},[r,i]),h=(0,B.useMemo)(()=>Array.from(r.values()).reduce((e,t)=>e+t.costUsd,0),[r]),g=m.filter(e=>e.status===`running`).length,_=u===null?null:m[u],v=(0,B.useCallback)(n=>{if(n.key===`Escape`){u===null?e&&e():d(null);return}if(n.key===`ArrowDown`){n.preventDefault(),d(e=>Math.min((e??-1)+1,m.length-1));return}if(n.key===`ArrowUp`){n.preventDefault(),d(e=>Math.max((e??0)-1,0));return}n.key===`Enter`&&m[u??0]&&t?.(m[u??0])},[m,u,e,t]);return(0,B.useEffect)(()=>{let t=t=>{t.key===`Escape`&&e&&e()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e]),(0,X.jsxs)(`div`,{className:n?`fixed inset-0 z-50 flex flex-col bg-background/95 backdrop-blur-md`:`flex flex-col h-full`,onKeyDown:v,tabIndex:-1,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b bg-card/80 backdrop-blur shrink-0`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,X.jsx)(R,{className:`h-5 w-5 text-primary`}),(0,X.jsxs)(`h2`,{className:`text-sm font-semibold flex items-center gap-2`,children:[`FLEET MONITOR`,g>0&&(0,X.jsxs)(`span`,{className:`flex items-center gap-1 text-[11px] text-emerald-500 font-normal`,children:[(0,X.jsx)(`span`,{className:`led led-pulse bg-emerald-500`}),g,` running`]})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,X.jsxs)(`span`,{children:[m.length,` total agents`]}),(0,X.jsx)(il,{current:s,max:c,showLabel:!0})]})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,X.jsxs)(`span`,{className:`text-xs text-muted-foreground tabular-nums font-mono`,children:[`↓`,ll(a),` ↑`,ll(o),` · `,cl(h)]}),(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums font-mono`,children:i?`👑 ${r.get(i)?.name??i}`:`no leader`}),n&&e&&(0,X.jsx)(`button`,{type:`button`,onClick:e,className:`p-1.5 rounded-md hover:bg-muted transition-colors`,"aria-label":`Close fleet monitor`,children:(0,X.jsx)(N,{className:`h-4 w-4`})})]})]}),(0,X.jsxs)(`div`,{className:`flex-1 flex overflow-hidden`,children:[(0,X.jsxs)(`div`,{className:Y(`flex flex-col border-r transition-all duration-200`,_?`w-[500px] shrink-0`:`w-full`),children:[(0,X.jsx)(`div`,{className:`border-b bg-card/80 px-3 py-2`,children:(0,X.jsxs)(`div`,{className:`grid grid-cols-[140px_60px_1fr_60px_60px_60px_60px_50px_50px] gap-x-2 text-[9px] uppercase tracking-wider text-muted-foreground font-medium`,children:[(0,X.jsx)(`span`,{children:`Name`}),(0,X.jsx)(`span`,{children:`Status`}),(0,X.jsx)(`span`,{children:`Activity`}),(0,X.jsx)(`span`,{children:`Iters`}),(0,X.jsx)(`span`,{children:`Tools`}),(0,X.jsx)(`span`,{children:`Cost`}),(0,X.jsx)(`span`,{children:`CTX`}),(0,X.jsx)(`span`,{children:`Ext`}),(0,X.jsx)(`span`,{children:`Reason`})]})}),(0,X.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:m.length===0?(0,X.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full text-muted-foreground`,children:[(0,X.jsx)(Wt,{className:`h-12 w-12 mb-3 opacity-20`}),(0,X.jsx)(`p`,{className:`text-sm font-medium`,children:`No agents active`}),(0,X.jsx)(`p`,{className:`text-xs mt-1`,children:`Agents appear here when the fleet is active.`})]}):(0,X.jsx)(`div`,{className:`p-2 space-y-0.5`,children:m.map((e,t)=>(0,X.jsx)(pl,{agent:e,isSelected:t===u,isLeader:e.id===i,onClick:()=>d(t===u?null:t)},e.id))})}),(0,X.jsxs)(`div`,{className:`border-t bg-card/80 shrink-0`,children:[(0,X.jsx)(`div`,{className:`px-4 py-2 border-b`,children:(0,X.jsxs)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground font-medium flex items-center gap-2`,children:[(0,X.jsx)(Pe,{className:`h-3 w-3`}),`Event Timeline`]})}),(0,X.jsx)(`div`,{className:`px-4 py-2 max-h-32 overflow-y-auto`,children:(0,X.jsx)(sl,{events:l,max:10})}),(0,X.jsxs)(`div`,{className:`px-4 py-1.5 border-t text-[10px] text-muted-foreground flex items-center gap-4`,children:[(0,X.jsx)(`span`,{children:`↑↓ navigate`}),(0,X.jsx)(`span`,{children:`↵ select detail`}),(0,X.jsx)(`span`,{children:`Esc deselect / close`})]})]})]}),_&&(0,X.jsx)(`div`,{className:`flex-1 overflow-hidden bg-card/50`,children:(0,X.jsxs)(`div`,{className:`h-full flex flex-col`,children:[(0,X.jsxs)(`div`,{className:`shrink-0 px-4 py-2 border-b bg-card/80 flex items-center gap-2`,children:[(0,X.jsx)(ln,{className:`h-4 w-4 text-primary`}),(0,X.jsx)(`span`,{className:`text-xs font-semibold text-primary`,children:_.name}),(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`detailed view`}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>d(null),className:`ml-auto text-[10px] text-muted-foreground hover:text-foreground transition-colors flex items-center gap-1`,children:`✕ close`})]}),(0,X.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:(0,X.jsx)(fl,{agent:_,now:f})})]})}),!_&&m.length>0&&(0,X.jsx)(`div`,{className:`flex-1 flex items-center justify-center bg-muted/20`,children:(0,X.jsxs)(`div`,{className:`text-center space-y-3 max-w-sm`,children:[(0,X.jsx)(Wt,{className:`h-12 w-12 text-muted-foreground/30 mx-auto`}),(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Select an agent to view detailed information`}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground/60`,children:`Click on any agent in the list to see detailed metrics, tool logs, streaming output, and more — similar to the chat history detailed view.`}),(0,X.jsxs)(`div`,{className:`flex items-center justify-center gap-4 pt-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] text-muted-foreground`,children:[(0,X.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted border text-[9px]`,children:`↑`}),(0,X.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted border text-[9px]`,children:`↓`}),(0,X.jsx)(`span`,{children:`navigate`})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] text-muted-foreground`,children:[(0,X.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted border text-[9px]`,children:`Enter`}),(0,X.jsx)(`span`,{children:`select`})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] text-muted-foreground`,children:[(0,X.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted border text-[9px]`,children:`Esc`}),(0,X.jsx)(`span`,{children:`deselect`})]})]})]})})]})]})}function hl(e){return e<=0?`$0`:e>=.01?`$${e.toFixed(3)}`:`$${e.toFixed(5)}`.replace(/0+$/,``).replace(/\.$/,``)}function gl(e){let t=Math.floor(e/1e3);return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`}var _l={running:{led:`bg-[hsl(var(--success))]`,label:`running`,pulse:!0,badge:`bg-[hsl(var(--success))]/15 text-[hsl(var(--success))]`},completed:{led:`bg-[hsl(var(--success))]`,label:`done`,pulse:!1,badge:`bg-muted text-muted-foreground`},failed:{led:`bg-destructive`,label:`failed`,pulse:!1,badge:`bg-destructive/15 text-destructive`},timeout:{led:`bg-[hsl(var(--warning))]`,label:`timeout`,pulse:!1,badge:`bg-amber-500/15 text-amber-500`},stopped:{led:`bg-muted-foreground`,label:`stopped`,pulse:!1,badge:`bg-muted text-muted-foreground`}};function vl({agent:e,isLeader:t}){let n=_l[e.status],r=e.status===`running`,i=Date.now()-e.startedAt,a=[...e.toolLog.slice(0,8)].reverse();return(0,X.jsxs)(`div`,{className:Y(`rounded-xl border p-4 space-y-3`,r?`border-primary/20 bg-primary/[0.02]`:`border-border bg-card`,t&&`ring-2 ring-amber-500/30`),children:[(0,X.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`span`,{className:Y(`led`,n.led,n.pulse&&`led-pulse`,`mt-0.5`)}),(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(`span`,{className:`text-sm font-semibold`,children:e.name}),t&&(0,X.jsx)(be,{className:`h-3.5 w-3.5 text-amber-500`,"aria-label":`leader`}),e.extensions>0&&(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded-full bg-amber-500/15 text-[10px] text-amber-600 dark:text-amber-400 font-medium`,children:[(0,X.jsx)(ze,{className:`h-2.5 w-2.5`}),`×`,e.extensions]})]}),(0,X.jsx)(`span`,{className:Y(`inline-block mt-0.5 px-1.5 py-0.5 rounded text-[10px] font-medium`,n.badge),children:n.label})]})]}),(0,X.jsx)(`div`,{className:`flex items-center gap-1 text-[10px] text-muted-foreground`,children:t&&(0,X.jsx)(`span`,{className:`text-[9px] bg-amber-500/15 text-amber-600 dark:text-amber-400 px-1.5 py-0.5 rounded`,children:`LEADER`})})]}),e.description&&(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground leading-relaxed line-clamp-2`,children:e.description}),e.budgetWarning&&(0,X.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg bg-amber-500/10 border border-amber-500/20 text-xs`,children:[(0,X.jsx)(ze,{className:`h-3.5 w-3.5 text-amber-500 shrink-0`}),(0,X.jsxs)(`span`,{className:`text-amber-600 dark:text-amber-400`,children:[`⚡ hitting `,(0,X.jsx)(`strong`,{children:e.budgetWarning.kind}),` limit (`,e.budgetWarning.used,`/`,e.budgetWarning.limit,`) — extending`]})]}),e.failureReason&&(0,X.jsx)(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg bg-destructive/10 border border-destructive/20 text-xs`,children:(0,X.jsxs)(`span`,{className:`text-destructive font-medium`,children:[`✗ `,e.failureReason]})}),(0,X.jsxs)(`div`,{className:`grid grid-cols-4 gap-2`,children:[(0,X.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-2 py-1.5 text-center`,children:[(0,X.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:`Iters`}),(0,X.jsx)(`div`,{className:`text-xs font-mono font-semibold tabular-nums`,children:e.iteration})]}),(0,X.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-2 py-1.5 text-center`,children:[(0,X.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:`Tools`}),(0,X.jsx)(`div`,{className:`text-xs font-mono font-semibold tabular-nums`,children:e.toolCalls})]}),(0,X.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-2 py-1.5 text-center`,children:[(0,X.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:`Cost`}),(0,X.jsx)(`div`,{className:`text-xs font-mono font-semibold tabular-nums`,children:hl(e.costUsd)})]}),(0,X.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-2 py-1.5 text-center`,children:[(0,X.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:`Elapsed`}),(0,X.jsx)(`div`,{className:`text-xs font-mono font-semibold tabular-nums`,children:gl(i)})]})]}),(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Activity (12 bins)`}),(0,X.jsx)(sc,{bins:e.sparklineBins,className:`font-mono text-[9px]`})]}),(0,X.jsx)(zi,{pct:e.ctxPct,tokens:e.ctxTokens,maxTokens:e.maxContext})]}),(e.provider||e.model)&&(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] text-muted-foreground`,children:[(0,X.jsx)(c,{className:`h-3 w-3`}),(0,X.jsxs)(`span`,{className:`font-mono`,children:[e.provider??`?`,`/`,e.model??`?`]})]}),(e.currentTool||e.lastTool)&&(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] text-muted-foreground`,children:[(0,X.jsx)(He,{className:Y(`h-3 w-3`,r&&`animate-pulse text-primary`)}),(0,X.jsx)(`span`,{className:`font-mono`,children:e.currentTool??e.lastTool}),r&&(0,X.jsx)(L,{className:`h-3 w-3 animate-spin`})]}),e.partialText&&r&&(0,X.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 p-2`,children:[(0,X.jsx)(`div`,{className:`text-[9px] text-muted-foreground uppercase tracking-wider mb-1`,children:`Streaming output`}),(0,X.jsx)(`pre`,{className:`text-[10px] font-mono text-foreground/80 whitespace-pre-wrap line-clamp-3 leading-relaxed`,children:e.partialText})]}),a.length>0&&(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(`div`,{className:`text-[9px] text-muted-foreground uppercase tracking-wider`,children:`Recent tools`}),(0,X.jsx)(`div`,{className:`space-y-0.5`,children:a.map((e,t)=>(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] font-mono`,children:[(0,X.jsx)(`span`,{className:Y(`shrink-0`,e.ok?`text-[hsl(var(--success))]`:`text-destructive`),children:e.ok?`✓`:`✗`}),(0,X.jsx)(`span`,{className:`text-muted-foreground truncate`,children:e.name}),(0,X.jsx)(`span`,{className:`ml-auto tabular-nums text-muted-foreground shrink-0`,children:e.durationMs>=1e3?`${(e.durationMs/1e3).toFixed(1)}s`:`${e.durationMs}ms`})]},t))})]}),e.finalText&&!r&&(0,X.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 p-2`,children:[(0,X.jsx)(`div`,{className:`text-[9px] text-muted-foreground uppercase tracking-wider mb-1`,children:`Final output`}),(0,X.jsx)(`pre`,{className:`text-[10px] font-mono text-foreground/80 whitespace-pre-wrap line-clamp-4 leading-relaxed`,children:e.finalText})]})]})}var yl=320;function bl(e){return e<=0?`$0`:e>=.01?`$${e.toFixed(3)}`:`$${e.toFixed(5)}`.replace(/0+$/,``).replace(/\.$/,``)}function xl(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e)}function Sl(e,t){let n=Array.from(e.values());return n.sort((e,n)=>{if(e.id===t)return-1;if(n.id===t)return 1;let r=e.status===`running`?0:1,i=n.status===`running`?0:1;return r===i?e.startedAt-n.startedAt:r-i}),n}function Cl(){let e=G(e=>e.inspectorOpen),t=G(e=>e.inspectorTab),n=G(e=>e.toggleInspector),r=G(e=>e.setInspectorOpen),i=G(e=>e.setInspectorTab),a=K(e=>e.agents),o=K(e=>e.leaderId),s=K(e=>e.fleetTokensIn),c=K(e=>e.fleetTokensOut),l=K(e=>e.fleetConcurrency),u=K(e=>e.fleetConcurrencyMax),d=K(e=>e.eventTimeline),f=(0,B.useMemo)(()=>Sl(a,o),[a,o]),p=f.filter(e=>e.status===`running`).length,m=f.reduce((e,t)=>e+t.costUsd,0),h=f.length,[g,_]=(0,B.useState)(null),v=(0,B.useMemo)(()=>g?a.get(g)??f[0]??null:f[0]??null,[g,f,a]),y=()=>i(`fleet`),b=()=>i(`agents`);return(0,X.jsxs)(`div`,{className:`shrink-0 border-t bg-card flex flex-col`,children:[(0,X.jsxs)(`button`,{type:`button`,onClick:n,className:Y(`group w-full flex items-center justify-between gap-2 px-3 h-7 text-[11px]`,`text-muted-foreground hover:text-foreground hover:bg-accent/40 transition-colors`),title:e?`Hide inspector panel`:`Show inspector panel (Fleet / Agents)`,children:[(0,X.jsxs)(`span`,{className:`flex items-center gap-2 min-w-0`,children:[e?(0,X.jsx)(ut,{className:`h-3.5 w-3.5 shrink-0`}):(0,X.jsx)(_e,{className:`h-3.5 w-3.5 shrink-0`}),(0,X.jsx)(`span`,{className:`font-medium uppercase tracking-wider`,children:`Inspector`}),h>0&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`opacity-40`,children:`·`}),(0,X.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,X.jsx)(`span`,{className:Y(`h-1.5 w-1.5 rounded-full`,p>0?`bg-emerald-500 animate-pulse`:`bg-muted-foreground/50`)}),(0,X.jsxs)(`span`,{className:`tabular-nums`,children:[p,`/`,h]})]}),(0,X.jsx)(`span`,{className:`opacity-40 hidden sm:inline`,children:`·`}),(0,X.jsxs)(`span`,{className:`tabular-nums font-mono hidden sm:inline`,children:[`↓`,xl(s),` ↑`,xl(c),` · `,bl(m)]})]})]}),(0,X.jsxs)(`span`,{className:`flex items-center gap-1 shrink-0 opacity-70 group-hover:opacity-100`,children:[(0,X.jsx)(R,{className:`h-3 w-3`}),(0,X.jsx)(Wt,{className:`h-3 w-3`})]})]}),(0,X.jsx)(`div`,{className:`overflow-hidden transition-[height] duration-300 ease-[cubic-bezier(0.16,1,0.3,1)]`,style:{height:e?yl:0},children:(0,X.jsxs)(`div`,{className:`flex flex-col`,style:{height:yl},children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1 px-2 h-8 border-b bg-muted/30 shrink-0`,children:[(0,X.jsx)(wl,{active:t===`fleet`,onClick:y,icon:(0,X.jsx)(R,{className:`h-3.5 w-3.5`}),label:`Fleet`,count:h,running:p}),(0,X.jsx)(wl,{active:t===`agents`,onClick:b,icon:(0,X.jsx)(Wt,{className:`h-3.5 w-3.5`}),label:`Agents`,count:h}),(0,X.jsx)(`div`,{className:`flex-1`}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>r(!1),className:`p-1 rounded hover:bg-muted transition-colors text-muted-foreground hover:text-foreground`,"aria-label":`Collapse inspector panel`,title:`Collapse (Esc)`,children:(0,X.jsx)(ut,{className:`h-4 w-4`})})]}),(0,X.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto`,children:t===`fleet`?(0,X.jsx)(Tl,{fleetList:f,leaderId:o,selectedAgentId:g,runningCount:p,fleetConcurrency:l,fleetConcurrencyMax:u,fleetTokensIn:s,fleetTokensOut:c,totalCost:m,eventTimeline:d,onSelectAgent:e=>{_(e.id),b()}}):(0,X.jsx)(El,{fleetList:f,selectedAgent:v,leaderId:o,selectedAgentId:v?.id??null,onSelectAgent:_})})]})})]})}function wl({active:e,onClick:t,icon:n,label:r,count:i,running:a}){return(0,X.jsxs)(`button`,{type:`button`,onClick:t,className:Y(`flex items-center gap-1.5 px-2.5 h-6 rounded-md text-[11px] font-medium transition-colors`,e?`bg-background text-foreground shadow-sm ring-1 ring-border`:`text-muted-foreground hover:text-foreground hover:bg-background/60`),children:[n,r,i>0&&(0,X.jsx)(`span`,{className:Y(`tabular-nums text-[10px] px-1 rounded-full`,a&&a>0?`bg-emerald-500/15 text-emerald-600 dark:text-emerald-400`:`bg-muted text-muted-foreground`),children:a===void 0?i:`${a}/${i}`})]})}function Tl({fleetList:e,leaderId:t,selectedAgentId:n,runningCount:r,fleetConcurrency:i,fleetConcurrencyMax:a,fleetTokensIn:o,fleetTokensOut:s,totalCost:c,eventTimeline:l,onSelectAgent:u}){return(0,X.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-1.5 border-b text-[11px] text-muted-foreground shrink-0`,children:[(0,X.jsxs)(`span`,{className:`flex items-center gap-1`,children:[r>0&&(0,X.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-emerald-500 animate-pulse`}),(0,X.jsxs)(`span`,{className:`tabular-nums`,children:[r,` running · `,e.length,` total`]})]}),(0,X.jsx)(il,{current:i,max:a,showLabel:!0}),(0,X.jsx)(`div`,{className:`flex-1`}),(0,X.jsxs)(`span`,{className:`tabular-nums font-mono`,children:[`↓`,xl(o),` ↑`,xl(s),` · `,bl(c)]})]}),e.length===0?(0,X.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-8 text-muted-foreground`,children:[(0,X.jsx)(Wt,{className:`h-8 w-8 mb-2 opacity-20`}),(0,X.jsx)(`p`,{className:`text-xs font-medium`,children:`No agents active`}),(0,X.jsx)(`p`,{className:`text-[11px] mt-0.5`,children:`Agents appear here when the fleet is active.`})]}):(0,X.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-1.5`,children:e.map(e=>(0,X.jsx)(pl,{agent:e,isSelected:n===e.id,isLeader:e.id===t,onClick:()=>u(e)},e.id))}),l.length>0&&(0,X.jsx)(`div`,{className:`border-t px-3 py-1.5 shrink-0`,children:(0,X.jsx)(sl,{events:l,max:4})})]})}function El({fleetList:e,selectedAgent:t,leaderId:n,selectedAgentId:r,onSelectAgent:i}){if(e.length===0)return(0,X.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-8 text-muted-foreground`,children:[(0,X.jsx)(R,{className:`h-8 w-8 mb-2 opacity-20`}),(0,X.jsx)(`p`,{className:`text-xs font-medium`,children:`No agents active`})]});if(!t)return null;let a=Math.max(0,e.findIndex(e=>e.id===r));return(0,X.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,X.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-3`,children:(0,X.jsx)(`div`,{className:`max-w-2xl mx-auto`,children:(0,X.jsx)(vl,{agent:t,isLeader:t.id===n})})}),(0,X.jsx)(`div`,{className:`border-t px-2 py-1.5 shrink-0`,children:(0,X.jsx)(`div`,{className:`flex items-center gap-1 overflow-x-auto pb-0.5`,children:e.map((e,n)=>(0,X.jsxs)(`button`,{type:`button`,onClick:()=>i(e.id),className:Y(`shrink-0 flex items-center gap-1.5 px-2 py-1 rounded-md text-[10px] transition-colors`,e.id===t?.id?`bg-primary/15 text-primary ring-1 ring-primary/40`:`hover:bg-accent text-muted-foreground`),title:`${e.name}${n===a?` (selected)`:``}`,children:[(0,X.jsx)(`span`,{className:Y(`h-1.5 w-1.5 rounded-full shrink-0`,e.status===`running`?`bg-emerald-500 animate-pulse`:e.status===`failed`?`bg-destructive`:`bg-muted-foreground/50`)}),(0,X.jsx)(`span`,{className:`truncate max-w-[8rem]`,children:e.name})]},e.id))})})]})}function Dl(){let{theme:e}=Ti(),{currentView:t,sidebarOpen:n,toggleSidebar:r,setSearchOpen:i,setSidebarOpen:a,setCurrentView:o,setInspectorTab:s,toggleInspector:c}=G(),l=H(e=>e.isLoading),u=W(e=>e.iteration),d=W(e=>e.projectName),f=W(e=>e.session?.title),p=W(e=>e.session?.id),m=G(e=>p?e.sessionNicknames[p]:void 0);return(0,B.useEffect)(()=>{let e=e=>{let{filePath:t}=e.detail,n=V(U.getState().wsUrl);n&&n.send({type:`files.read`,payload:{filePath:t}})};return window.addEventListener(`wrongstack:open-file`,e),()=>window.removeEventListener(`wrongstack:open-file`,e)},[]),(0,B.useEffect)(()=>{let e=e=>{let{filePath:t}=e.detail,n=q.getState().openFiles.find(e=>e.path===t);if(!n)return;let r=V(U.getState().wsUrl);r&&r.send({type:`files.write`,payload:{filePath:t,content:n.content}})};return window.addEventListener(`wrongstack:save-file`,e),()=>window.removeEventListener(`wrongstack:save-file`,e)},[]),(0,B.useEffect)(()=>{if(typeof window>`u`)return;let e=window.matchMedia(`(max-width: 768px)`),t=()=>{e.matches&&G.getState().sidebarOpen&&a(!1)};return t(),e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[a]),Si(),(0,B.useEffect)(()=>{let e=[];if(l){let t=u?` iter ${u.index}${u.max?`/${u.max}`:``}`:``;e.push(`●${t}`)}let t=m?.trim()||f?.trim(),n=d?.trim();t&&e.push(t),n&&e.push(n),e.length===0&&e.push(n||`AI Agent`);let r=e.filter(Boolean).join(` · `);return document.title=r,()=>{document.title=d||`AI Agent`}},[l,u,d,f,m]),(0,B.useEffect)(()=>{let e=e=>{let t=e.target,n=t?.tagName?.toLowerCase(),a=n===`input`||n===`textarea`||t?.isContentEditable,o=e.ctrlKey||e.metaKey;if(o&&e.key===`\\`){e.preventDefault(),r();return}if(o&&!e.shiftKey&&!e.altKey&&e.key>=`1`&&e.key<=String(ki.length)){let t=ki[Number(e.key)-1];if(t){e.preventDefault(),Oi(t);return}}if(o&&e.key.toLowerCase()===`f`){e.preventDefault(),i(!0);return}if(o&&e.key.toLowerCase()===`/`){e.preventDefault(),document.querySelector(`textarea`)?.focus();return}if(o&&!a&&(e.key.toLowerCase()===`l`?(e.preventDefault(),H.getState().clearMessages(),V(U.getState().wsUrl)?.clearContext?.()):e.key.toLowerCase()===`n`?(e.preventDefault(),V(U.getState().wsUrl)?.newSession?.(),G.getState().setCurrentView(`chat`)):e.key.toLowerCase()===`e`&&(e.preventDefault(),xa())),o&&e.shiftKey&&e.key.toLowerCase()===`d`&&(e.preventDefault(),G.getState().toggleCompactMode()),o&&e.shiftKey&&e.key.toLowerCase()===`m`){e.preventDefault();let t=G.getState();t.inspectorOpen&&t.inspectorTab===`fleet`?c():(s(`fleet`),t.inspectorOpen||c())}if(o&&e.shiftKey&&e.key.toLowerCase()===`a`){e.preventDefault();let t=G.getState();t.inspectorOpen&&t.inspectorTab===`agents`?c():(s(`agents`),t.inspectorOpen||c())}if(e.key===`Escape`&&!o&&G.getState().inspectorOpen&&G.getState().setInspectorOpen(!1),!a&&!o&&!e.altKey){let t=Array.from(document.querySelectorAll(`[data-message-id]`));if(t.length===0)return;let n=document.querySelector(`[data-message-id][data-focused="true"]`),r=n?t.indexOf(n):-1,i=e=>{for(let e of t)e.removeAttribute(`data-focused`);e.setAttribute(`data-focused`,`true`),e.scrollIntoView({behavior:`smooth`,block:`center`})};if(e.key===`j`||e.key===`ArrowDown`){let n=t[Math.min(t.length-1,Math.max(0,r+1))];n&&(e.preventDefault(),i(n));return}if(e.key===`k`||e.key===`ArrowUp`){let n=t[Math.max(0,r<=0?0:r-1)];n&&(e.preventDefault(),i(n));return}if(e.key===`g`&&!e.shiftKey){e.preventDefault(),i(z(t[0]));return}if(e.key===`G`||e.key===`g`&&e.shiftKey){e.preventDefault(),i(z(t[t.length-1]));return}if(e.key===`Escape`&&n){e.preventDefault(),n.removeAttribute(`data-focused`);return}if(e.key===`c`&&n){let t=n.querySelector(`.markdown-content`)?.innerText??n.innerText;t&&(navigator.clipboard?.writeText(t).catch(()=>{}),e.preventDefault());return}}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r,i]),(0,X.jsxs)(`div`,{className:Y(`flex h-screen`,e),children:[t!==`setup`&&(0,X.jsx)(Ai,{}),n&&t!==`setup`&&(0,X.jsx)(jc,{}),(0,X.jsxs)(`main`,{className:`flex-1 flex flex-col overflow-hidden`,children:[t!==`setup`&&(0,X.jsx)(rs,{}),t===`chat`&&(0,X.jsxs)(X.Fragment,{children:[p&&(0,X.jsx)(`div`,{className:`px-4 pt-2`,children:(0,X.jsx)(Jc,{sessionId:p})}),(0,X.jsx)(Io,{}),(0,X.jsx)(Cl,{})]}),t===`settings`&&(0,X.jsx)(bs,{}),t===`setup`&&(0,X.jsx)(ws,{}),t===`autophase`&&(0,X.jsx)(va,{onClose:()=>o(`chat`)}),t===`agents`&&(0,X.jsx)(`div`,{className:`flex-1 flex flex-col overflow-hidden`,children:(0,X.jsx)(Qi,{})}),t===`agentflow`&&(0,X.jsx)(`div`,{className:`flex-1 flex flex-col overflow-hidden`,children:(0,X.jsx)(Js,{})}),t===`fleet`&&(0,X.jsx)(`div`,{className:`flex-1 flex flex-col overflow-hidden`,children:(0,X.jsx)(ml,{isOverlay:!1})}),t===`sessions`&&(0,X.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:(0,X.jsx)(As,{})}),t===`files`&&(0,X.jsx)(Vo,{})]}),(0,X.jsx)($o,{}),(0,X.jsx)(ns,{}),(0,X.jsx)(Ca,{}),(0,X.jsx)(Ms,{}),(0,X.jsx)(os,{}),(0,X.jsx)(Tr,{})]})}function Ol(){return(0,X.jsx)(is,{children:(0,X.jsx)(wi,{defaultTheme:`system`,children:(0,X.jsx)(Dl,{})})})}Fn.createRoot(z(document.getElementById(`root`))).render((0,X.jsx)(B.StrictMode,{children:(0,X.jsx)(Ol,{})}));
163
+ `})}var Fs={read:(0,X.jsx)(I,{className:`h-3 w-3`}),write:(0,X.jsx)(I,{className:`h-3 w-3`}),bash:(0,X.jsx)(vn,{className:`h-3 w-3`}),exec:(0,X.jsx)(vn,{className:`h-3 w-3`}),glob:(0,X.jsx)(Ke,{className:`h-3 w-3`}),grep:(0,X.jsx)(lt,{className:`h-3 w-3`}),edit:(0,X.jsx)(He,{className:`h-3 w-3`}),fetch:(0,X.jsx)(st,{className:`h-3 w-3`}),search:(0,X.jsx)(lt,{className:`h-3 w-3`})};function Is({data:e}){let t=e.status===`active`||e.status===`streaming`,n=e.color||`#22c55e`;return(0,X.jsxs)(`div`,{className:Y(`rounded-lg border-2 p-3 min-w-[160px] transition-all`,t?`border-emerald-500/50 bg-emerald-500/10`:`border-gray-500/40 bg-gray-500/10`),children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`div`,{className:Y(`flex items-center justify-center w-8 h-8 rounded-lg`,t?`bg-emerald-500/20`:`bg-gray-500/20`),children:(0,X.jsx)(Ke,{className:`h-4 w-4`,style:{color:n}})}),(0,X.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,X.jsx)(`div`,{className:`text-[11px] font-bold truncate`,style:{color:n},children:e.label}),e.sublabel&&(0,X.jsx)(`div`,{className:`text-[9px] text-gray-500 truncate`,children:e.sublabel})]}),t&&(0,X.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-emerald-400 animate-pulse`,style:{boxShadow:`0 0 8px hsl(140,70%,50%)`}})]}),e.stats&&(0,X.jsxs)(`div`,{className:`mt-2 pt-2 border-t border-white/10 grid grid-cols-3 gap-1 text-[9px]`,children:[e.stats.iterations!==void 0&&(0,X.jsxs)(`div`,{className:`text-center`,children:[(0,X.jsx)(`div`,{className:`font-mono text-emerald-400`,children:e.stats.iterations}),(0,X.jsx)(`div`,{className:`text-gray-500`,children:`iter`})]}),e.stats.toolCalls!==void 0&&(0,X.jsxs)(`div`,{className:`text-center`,children:[(0,X.jsx)(`div`,{className:`font-mono text-blue-400`,children:e.stats.toolCalls}),(0,X.jsx)(`div`,{className:`text-gray-500`,children:`tools`})]}),e.stats.costUsd!==void 0&&e.stats.costUsd>0&&(0,X.jsxs)(`div`,{className:`text-center`,children:[(0,X.jsxs)(`div`,{className:`font-mono text-amber-400`,children:[`$`,e.stats.costUsd.toFixed(3)]}),(0,X.jsx)(`div`,{className:`text-gray-500`,children:`cost`})]})]})]})}function Ls({data:e}){let t=e.status===`active`||e.status===`streaming`,n=e.status===`error`,r=e.color||`#a855f7`;return(0,X.jsxs)(`div`,{className:Y(`rounded-lg border-2 p-2.5 min-w-[140px] transition-all`,t?`border-purple-500/50 bg-purple-500/10`:n?`border-red-500/50 bg-red-500/10`:`border-gray-500/40 bg-gray-500/10`),children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`div`,{className:Y(`flex items-center justify-center w-7 h-7 rounded-lg`,t?`bg-purple-500/20`:`bg-purple-500/10`),children:(0,X.jsx)(R,{className:`h-4 w-4`,style:{color:r}})}),(0,X.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,X.jsx)(`div`,{className:`text-[10px] font-bold truncate`,style:{color:r},children:e.label}),e.currentTool&&(0,X.jsxs)(`div`,{className:`flex items-center gap-1 text-[9px] text-amber-400/70`,children:[(0,X.jsx)(He,{className:`h-2.5 w-2.5`}),(0,X.jsx)(`span`,{className:`truncate font-mono`,children:e.currentTool})]})]}),t&&(0,X.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-purple-400 animate-pulse`,style:{boxShadow:`0 0 6px hsl(280,80%,60%)`}})]}),(0,X.jsxs)(`div`,{className:`mt-1.5 flex items-center justify-between text-[9px]`,children:[(0,X.jsxs)(`span`,{className:`text-gray-500`,children:[`iter `,e.stats?.iterations??0]}),(0,X.jsxs)(`span`,{className:`text-gray-500`,children:[`tools `,e.stats?.toolCalls??0]}),e.stats?.costUsd!==void 0&&e.stats.costUsd>0&&(0,X.jsxs)(`span`,{className:`text-emerald-400/70`,children:[`$`,e.stats.costUsd.toFixed(3)]})]}),e.stats?.ctxPct!==void 0&&(0,X.jsxs)(`div`,{className:`mt-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between text-[9px] mb-0.5`,children:[(0,X.jsx)(`span`,{className:`text-gray-500`,children:`ctx`}),(0,X.jsxs)(`span`,{className:e.stats.ctxPct>80?`text-red-400`:e.stats.ctxPct>60?`text-amber-400`:`text-gray-400`,children:[e.stats.ctxPct,`%`]})]}),(0,X.jsx)(`div`,{className:`h-1 rounded-full bg-black/30 overflow-hidden`,children:(0,X.jsx)(`div`,{className:Y(`h-full rounded-full transition-all`,e.stats.ctxPct>80?`bg-red-500`:e.stats.ctxPct>60?`bg-amber-500`:`bg-blue-500`),style:{width:`${Math.min(100,e.stats.ctxPct)}%`}})})]})]})}function Rs({data:e}){let t=e.color||`#f59e0b`,n=Fs[e.label?.toLowerCase()??``]||(0,X.jsx)(He,{className:`h-3 w-3`});return(0,X.jsxs)(`div`,{className:`rounded-lg border border-amber-500/30 bg-amber-500/10 p-2 min-w-[100px] transition-all`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`span`,{style:{color:t},children:n}),(0,X.jsx)(`span`,{className:`text-[10px] font-mono font-medium truncate`,style:{color:t},children:e.label})]}),e.stats?.durationMs!==void 0&&(0,X.jsxs)(`div`,{className:`mt-1 text-[9px] text-gray-500 text-center`,children:[e.stats.durationMs,`ms`]})]})}function zs({data:e}){let t=e.status===`active`||e.status===`streaming`,n=e.color||`#06b6d4`;return(0,X.jsx)(`div`,{className:Y(`rounded-lg border-2 p-3 min-w-[120px] transition-all`,t?`border-cyan-500/50 bg-cyan-500/10`:`border-cyan-500/30 bg-cyan-500/5`),children:(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`div`,{className:Y(`flex items-center justify-center w-8 h-8 rounded-lg`,t?`bg-cyan-500/20`:`bg-cyan-500/10`),children:(0,X.jsx)(c,{className:`h-4 w-4`,style:{color:n}})}),(0,X.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,X.jsx)(`div`,{className:`text-[10px] font-bold`,style:{color:n},children:`LLM`}),(0,X.jsx)(`div`,{className:`text-[9px] text-gray-500 truncate`,children:e.sublabel||`Provider`})]}),t&&(0,X.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-cyan-400 animate-pulse`,style:{boxShadow:`0 0 8px hsl(180,80%,60%)`}})]})})}function Bs({data:e}){let t=e.color||`#3b82f6`;return(0,X.jsxs)(`div`,{className:`rounded-lg border border-blue-500/30 bg-blue-500/10 p-2 min-w-[90px] transition-all`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(ie,{className:`h-3 w-3`,style:{color:t}}),(0,X.jsx)(`span`,{className:`text-[10px] font-medium`,style:{color:t},children:`Context`})]}),e.stats?.ctxPct!==void 0&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`mt-1 text-[9px] text-center text-gray-400`,children:[e.stats.ctxPct,`%`]}),(0,X.jsx)(`div`,{className:`h-1 mt-0.5 rounded-full bg-black/30 overflow-hidden`,children:(0,X.jsx)(`div`,{className:`h-full rounded-full bg-blue-500`,style:{width:`${Math.min(100,e.stats.ctxPct)}%`}})})]})]})}var Vs={session:Is,agent:Ls,tool:Rs,provider:zs,context:Bs};function Hs({id:e,sourceX:t,sourceY:n,targetX:r,targetY:i,data:a,selected:o}){let[s,c,l]=Us(t,n,r,i),u=a?.color||`#6366f1`,d=a?.animated,f=a?.flowType||`response`,p=a?.sequence,m={prompt:{icon:`📥`,bg:`bg-blue-500/20`,text:`text-blue-400`},response:{icon:`📤`,bg:`bg-emerald-500/20`,text:`text-emerald-400`},tool_result:{icon:`🔧`,bg:`bg-amber-500/20`,text:`text-amber-400`},tokens:{icon:`💎`,bg:`bg-cyan-500/20`,text:`text-cyan-400`},spawn:{icon:`✨`,bg:`bg-purple-500/20`,text:`text-purple-400`},status:{icon:`📊`,bg:`bg-pink-500/20`,text:`text-pink-400`}},h=m[f]||m.response;return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`path`,{id:e,d:s,fill:`none`,stroke:u,strokeWidth:o?3:2,strokeOpacity:o?.9:.4,className:`react-flow__edge-path`,markerEnd:`url(#arrow-${u.replace(`#`,``)})`}),d&&(0,X.jsx)(`path`,{d:s,fill:`none`,stroke:u,strokeWidth:2.5,strokeDasharray:`8 4`,className:`animated-edge`,opacity:.8}),p!==void 0&&(0,X.jsxs)(`g`,{transform:`translate(${c-6}, ${l-18})`,children:[(0,X.jsx)(`circle`,{r:`8`,fill:u,opacity:.9}),(0,X.jsx)(`text`,{x:`0`,y:`3`,textAnchor:`middle`,fill:`white`,fontSize:`9`,fontWeight:`bold`,children:p})]}),a?.label&&(0,X.jsx)(`foreignObject`,{width:100,height:28,x:c-50,y:l-14,className:`overflow-visible`,children:(0,X.jsxs)(`div`,{className:`flex items-center justify-center gap-1`,children:[(0,X.jsx)(`span`,{className:`text-[10px]`,children:h.icon}),(0,X.jsx)(`div`,{className:Y(`px-2 py-1 rounded-md border text-[9px] font-medium`,h.bg,`border-border/50`,h.text),children:a.label})]})}),(0,X.jsx)(`defs`,{children:(0,X.jsx)(`marker`,{id:`arrow-${u.replace(`#`,``)}`,viewBox:`0 0 10 10`,refX:`9`,refY:`5`,markerWidth:`6`,markerHeight:`6`,orient:`auto-start-reverse`,children:(0,X.jsx)(`path`,{d:`M 0 0 L 10 5 L 0 10 z`,fill:u,opacity:.7})})})]})}function Us(e,t,n,r){let i=Math.abs(n-e),a=Math.max(40,i*.4),o=(e+n)/2,s=Math.min(t,r)-a;return[`M ${e} ${t} C ${e} ${s}, ${n} ${s}, ${n} ${r}`,o,s]}var Ws={flow:Hs};function Gs({containerRef:e}){let{fitView:t}=$e(),n=W(e=>e.session),r=W(e=>e.projectName),i=W(e=>e.iteration),a=W(e=>e.cost),o=W(e=>e.lastInputTokens),s=W(e=>e.maxContext),c=K(e=>e.agents);yr(e=>e.nodes),yr(e=>e.edges);let l=yr(e=>e.events),u=yr(e=>e.counters),[d,f,p]=On([]),[m,h,g]=yn([]),[_,v]=(0,B.useState)(null);(0,B.useEffect)(()=>{let e=[],l=[];e.push({id:`provider`,type:`provider`,position:{x:400,y:20},data:{label:`LLM`,sublabel:n?.model||`claude-3-5-sonnet`,type:`provider`,status:n?`active`:`idle`,color:`#06b6d4`}}),e.push({id:`session`,type:`session`,position:{x:400,y:120},data:{label:n?.title||r||`Session`,sublabel:n?.id.slice(0,8),type:`session`,status:n?`active`:`idle`,color:`#22c55e`,stats:{iterations:i?.index,toolCalls:Array.from(c.values()).reduce((e,t)=>e+t.toolCalls,0),costUsd:a}}});let u=s?Math.round(o/s*100):0;e.push({id:`context`,type:`context`,position:{x:700,y:200},data:{label:`Context`,type:`context`,status:u>80?`active`:`idle`,color:`#3b82f6`,stats:{ctxPct:u}}});let d=Array.from(c.values()),p=Math.min(200,800/(d.length+1)),m=Math.max(100,(800-(d.length-1)*p)/2);d.forEach((t,n)=>{let r=t.status===`running`,i=t.status===`failed`,a=`agent-${t.id}`,o=i?`#ef4444`:r?`#a855f7`:`#8b5cf6`;e.push({id:a,type:`agent`,position:{x:m+n*p,y:300},data:{label:t.name,type:`agent`,status:r?`active`:i?`error`:t.status===`completed`?`completed`:`idle`,color:o,stats:{iterations:t.iteration,toolCalls:t.toolCalls,costUsd:t.costUsd,ctxPct:t.ctxPct},currentTool:t.currentTool||t.lastTool}}),l.push({id:`session->${a}`,source:`session`,target:a,type:`flow`,animated:r,data:{color:o,animated:r,label:`task`,flowType:`prompt`,sequence:n+1}}),l.push({id:`${a}->provider`,source:a,target:`provider`,type:`flow`,animated:r,data:{color:`#06b6d4`,animated:r,label:`prompt`,flowType:`prompt`,sequence:0}});let s=t.currentTool||t.lastTool;if(s){let i=`tool-${t.id}-${d.indexOf(t)}`;e.push({id:i,type:`tool`,position:{x:m+n*p,y:450},data:{label:s,type:`tool`,status:r?`active`:`idle`,color:`#f59e0b`,stats:{durationMs:t.toolLog?.[0]?.durationMs}}}),l.push({id:`${a}->${i}`,source:a,target:i,type:`flow`,animated:r,data:{color:`#f59e0b`,animated:r,label:`execute`,flowType:`tool_result`,sequence:2}}),l.push({id:`${i}->${a}`,source:i,target:a,type:`flow`,animated:!1,data:{color:`#22c55e`,animated:!1,label:`result`,flowType:`tool_result`,sequence:3}})}}),l.push({id:`provider->session`,source:`provider`,target:`session`,type:`flow`,animated:!!n,data:{color:`#06b6d4`,animated:!!n,label:`response`,flowType:`response`,sequence:4}}),l.push({id:`context->session`,source:`context`,target:`session`,type:`flow`,data:{color:`#3b82f6`,animated:!1,label:`tokens`,flowType:`tokens`}}),f(e),h(l),setTimeout(()=>t({padding:.2,duration:300}),50)},[n,r,i,c,a,o,s,f,h,t]),(0,B.useEffect)(()=>{if(l.length===0)return;let e=l[0];if(e){if(e.kind===`agent:tool`&&e.source){let t=`agent-${e.source}`;f(n=>n.map(n=>n.id===t?{...n,data:{...n.data,status:`streaming`,currentTool:e.label}}:n))}if(e.kind===`agent:status`){let t=`agent-${e.source}`,n=e.label.includes(`completed`)?`completed`:e.label.includes(`failed`)?`error`:e.label.includes(`running`)?`active`:`idle`;f(e=>e.map(e=>e.id===t?{...e,data:{...e.data,status:n}}:e))}}},[l,f]);let y=(0,B.useCallback)(e=>h(t=>gt({...e,type:`flow`},t)),[h]),b=(0,B.useCallback)((e,t)=>{v(t)},[]),x=(0,B.useCallback)(()=>{v(null)},[]);return(0,X.jsxs)(`div`,{className:`w-full h-full bg-background relative`,children:[(0,X.jsx)(Ps,{}),(0,X.jsxs)(Ge,{nodes:d,edges:m,onNodesChange:p,onEdgesChange:g,onConnect:y,onNodeClick:b,onPaneClick:x,nodeTypes:Vs,edgeTypes:Ws,fitView:!0,attributionPosition:`bottom-left`,proOptions:{hideAttribution:!0},children:[(0,X.jsx)(ot,{variant:ft.Dots,gap:20,size:1,color:`hsl(var(--border))`}),(0,X.jsx)(Yt,{className:`!bg-background/80 !border-border backdrop-blur`}),(0,X.jsx)(Lt,{className:`!bg-background/80 !border-border`,nodeColor:e=>{switch(e.type){case`session`:return`#22c55e`;case`agent`:return`#a855f7`;case`tool`:return`#f59e0b`;case`provider`:return`#06b6d4`;case`context`:return`#3b82f6`;default:return`#6366f1`}}})]}),_&&(0,X.jsxs)(`div`,{className:`absolute top-4 right-4 w-64 bg-background/95 border border-border rounded-lg shadow-xl backdrop-blur z-50`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between p-3 border-b border-border`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`span`,{className:`text-xs font-bold capitalize`,children:_.type}),(0,X.jsx)(`span`,{className:Y(`px-1.5 py-0.5 rounded text-[9px] font-medium`,_.data.status===`active`&&`bg-emerald-500/20 text-emerald-400`,_.data.status===`streaming`&&`bg-blue-500/20 text-blue-400`,_.data.status===`error`&&`bg-red-500/20 text-red-400`,_.data.status===`completed`&&`bg-blue-500/20 text-blue-400`,_.data.status===`idle`&&`bg-gray-500/20 text-gray-400`),children:_.data.status})]}),(0,X.jsx)(`button`,{onClick:()=>v(null),className:`text-muted-foreground hover:text-foreground`,children:(0,X.jsx)(Ie,{className:`h-4 w-4`})})]}),(0,X.jsxs)(`div`,{className:`p-3 space-y-2 text-[11px]`,children:[(0,X.jsxs)(`div`,{className:`flex justify-between`,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`Label`}),(0,X.jsx)(`span`,{className:`font-mono`,children:String(_.data.label??``)})]}),_.data.sublabel&&(0,X.jsxs)(`div`,{className:`flex justify-between`,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`Sublabel`}),(0,X.jsx)(`span`,{className:`font-mono text-[10px]`,children:String(_.data.sublabel)})]}),_.data.currentTool&&(0,X.jsxs)(`div`,{className:`flex justify-between`,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`Tool`}),(0,X.jsx)(`span`,{className:`font-mono text-amber-400`,children:String(_.data.currentTool)})]}),_.data.stats&&(0,X.jsxs)(X.Fragment,{children:[_.data.stats.iterations!==void 0&&(0,X.jsxs)(`div`,{className:`flex justify-between`,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`Iterations`}),(0,X.jsx)(`span`,{className:`font-mono`,children:_.data.stats.iterations})]}),_.data.stats.toolCalls!==void 0&&(0,X.jsxs)(`div`,{className:`flex justify-between`,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`Tool Calls`}),(0,X.jsx)(`span`,{className:`font-mono`,children:_.data.stats.toolCalls})]}),_.data.stats.costUsd!==void 0&&(0,X.jsxs)(`div`,{className:`flex justify-between`,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`Cost`}),(0,X.jsxs)(`span`,{className:`font-mono text-emerald-400`,children:[`$`,_.data.stats.costUsd.toFixed(4)]})]}),_.data.stats.ctxPct!==void 0&&(0,X.jsxs)(`div`,{className:`flex justify-between`,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`Context`}),(0,X.jsxs)(`span`,{className:`font-mono`,children:[_.data.stats.ctxPct,`%`]})]})]})]})]}),(0,X.jsxs)(`div`,{className:`absolute bottom-4 left-4 bg-background/95 border border-border rounded-lg p-2 backdrop-blur`,children:[(0,X.jsx)(`div`,{className:`text-[9px] text-muted-foreground mb-1 font-semibold uppercase tracking-wider`,children:`Live`}),(0,X.jsxs)(`div`,{className:`grid grid-cols-3 gap-x-3 gap-y-1 text-[10px]`,children:[(0,X.jsx)(Ks,{label:`Tokens`,value:u.totalTokens.toLocaleString()}),(0,X.jsx)(Ks,{label:`Cost`,value:`$${u.totalCost.toFixed(3)}`}),(0,X.jsx)(Ks,{label:`Tools`,value:u.totalToolCalls}),(0,X.jsx)(Ks,{label:`Agents`,value:u.activeAgents}),(0,X.jsx)(Ks,{label:`Done`,value:u.completedTasks}),(0,X.jsx)(Ks,{label:`Errors`,value:u.errors})]})]}),(0,X.jsxs)(`div`,{className:`absolute top-4 left-4 bg-background/95 border border-border rounded-lg p-3 backdrop-blur z-50 max-w-xs`,children:[(0,X.jsxs)(`div`,{className:`text-[9px] text-muted-foreground mb-2 font-semibold uppercase tracking-wider flex items-center gap-2`,children:[(0,X.jsx)(`span`,{className:`text-primary`,children:`⟳`}),` Flow Sequence`]}),(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(Js,{sequence:0,icon:`📥`,label:`Prompt`,description:`User input → LLM`,color:`#06b6d4`}),(0,X.jsx)(Js,{sequence:1,icon:`👤`,label:`Task`,description:`Session → Agent`,color:`#a855f7`}),(0,X.jsx)(Js,{sequence:2,icon:`🔧`,label:`Execute`,description:`Agent → Tool`,color:`#f59e0b`}),(0,X.jsx)(Js,{sequence:3,icon:`✅`,label:`Result`,description:`Tool → Agent`,color:`#22c55e`}),(0,X.jsx)(Js,{sequence:4,icon:`📤`,label:`Response`,description:`LLM → Session`,color:`#06b6d4`})]}),(0,X.jsx)(`div`,{className:`mt-2 pt-2 border-t border-border`,children:(0,X.jsxs)(`div`,{className:`text-[9px] text-muted-foreground flex items-center gap-2`,children:[(0,X.jsx)(`span`,{children:`💎`}),` Tokens: Context → Session`]})})]}),(0,X.jsxs)(`div`,{className:`absolute bottom-4 right-4 bg-background/95 border border-border rounded-lg p-2 backdrop-blur`,children:[(0,X.jsx)(`div`,{className:`text-[9px] text-muted-foreground mb-1 font-semibold uppercase tracking-wider`,children:`Nodes`}),(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(qs,{color:`#22c55e`,label:`Session`}),(0,X.jsx)(qs,{color:`#a855f7`,label:`Agent`}),(0,X.jsx)(qs,{color:`#f59e0b`,label:`Tool`}),(0,X.jsx)(qs,{color:`#06b6d4`,label:`Provider`}),(0,X.jsx)(qs,{color:`#3b82f6`,label:`Context`})]})]})]})}function Ks({label:e,value:t}){return(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:e}),(0,X.jsx)(`span`,{className:`font-mono font-bold text-foreground`,children:t})]})}function qs({color:e,label:t}){return(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px]`,children:[(0,X.jsx)(`span`,{className:`w-2.5 h-2.5 rounded-sm`,style:{backgroundColor:e}}),(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:t})]})}function Js({sequence:e,icon:t,label:n,description:r,color:i}){return(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px]`,children:[(0,X.jsx)(`div`,{className:`w-5 h-5 rounded-full flex items-center justify-center text-[9px] font-bold text-white shrink-0`,style:{backgroundColor:i},children:e}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,X.jsx)(`span`,{children:t}),(0,X.jsx)(`span`,{className:`font-medium`,style:{color:i},children:n}),(0,X.jsx)(`span`,{className:`text-muted-foreground text-[9px]`,children:r})]})]})}function Ys(e){return(0,X.jsx)(bt,{children:(0,X.jsx)(Gs,{...e})})}var Xs={ts:F,tsx:F,js:F,jsx:F,mjs:F,cjs:F,json:a,lock:Te,css:I,scss:I,less:I,html:En,htm:En,svg:_,xml:En,md:I,mdx:I,txt:I,yml:I,yaml:I,toml:m,env:m,gitignore:m,editorconfig:m,sh:F,bash:F,zsh:F,fish:F,ps1:F,bat:F,py:F,pyi:F,pyx:F,rs:F,go:F,rb:F,java:F,c:F,cpp:F,h:F,hpp:F,sql:F,graphql:F,png:_,jpg:_,jpeg:_,gif:_,webp:_,ico:_};function Zs(e,t){if(t){let t=e.toLowerCase();return t===`.git`?`text-orange-500/80 dark:text-orange-400/80`:t===`node_modules`?`text-red-400/60 dark:text-red-500/60`:t===`src`||t===`lib`||t===`packages`?`text-amber-500/70 dark:text-amber-400/70`:t===`tests`||t===`test`||t===`__tests__`?`text-emerald-500/70 dark:text-emerald-400/70`:t===`dist`||t===`build`||t===`.next`?`text-muted-foreground/50`:`text-amber-500/70 dark:text-amber-400/70`}let n=e.split(`.`).pop()?.toLowerCase()??``;return/^(ts|tsx|js|jsx|mjs|cjs)$/.test(n)?`text-blue-500 dark:text-blue-400`:/^(json|lock)$/.test(n)?`text-amber-500 dark:text-amber-400`:/^(css|scss|less|sass)$/.test(n)?`text-teal-500 dark:text-teal-400`:/^(html|htm|xml|svg)$/.test(n)?`text-rose-500 dark:text-rose-400`:/^(md|mdx)$/.test(n)?`text-violet-500 dark:text-violet-400`:/^(yml|yaml|toml|env)$/.test(n)?`text-emerald-500 dark:text-emerald-400`:/^(sh|bash|zsh|fish|ps1|bat)$/.test(n)?`text-orange-400 dark:text-orange-300`:/^(py|pyi|pyx)$/.test(n)?`text-cyan-500 dark:text-cyan-400`:n===`rs`?`text-orange-500 dark:text-orange-400`:n===`go`?`text-sky-500 dark:text-sky-400`:n===`rb`?`text-red-400 dark:text-red-400`:/^(c|h|cpp|hpp|cc|hh)$/.test(n)?`text-slate-500 dark:text-slate-400`:/^(png|jpe?g|gif|webp|ico|svg)$/.test(n)?`text-purple-500 dark:text-purple-400`:/^(gitignore|editorconfig|prettierrc|eslintrc)$/.test(n)?`text-muted-foreground/60`:`text-muted-foreground`}function Qs(e){return Xs[e.split(`.`).pop()?.toLowerCase()??``]??et}function $s({node:e,depth:t,selectedPath:r,forceExpand:i,onSelect:a,onOpen:o}){let[s,c]=(0,B.useState)(t<1),l=q(e=>e.activeFilePath),u=e.type===`file`&&e.path===l;if((0,B.useEffect)(()=>{i!==null&&c(i)},[i]),e.type===`directory`){let l=(e.children?.length??0)>0,u=s?Ke:xt,d=e.name===`.git`,f=Zs(e.name,!0);return(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`button`,{type:`button`,onClick:()=>c(e=>!e),className:Y(`flex items-center gap-1 w-full text-left px-1 py-0.5 text-[11px] rounded`,`hover:bg-muted/60 transition-colors`),style:{paddingLeft:`${t*14+4}px`},children:[(0,X.jsx)(n,{className:Y(`h-3 w-3 shrink-0 text-muted-foreground transition-transform`,s&&`rotate-90`)}),d?(0,X.jsx)(bn,{className:Y(`h-3.5 w-3.5 shrink-0`,f)}):(0,X.jsx)(u,{className:Y(`h-3.5 w-3.5 shrink-0`,f)}),(0,X.jsx)(`span`,{className:`truncate font-medium flex-1 min-w-0`,children:e.name})]}),s&&l&&(0,X.jsx)(`div`,{children:(e.children??[]).map(e=>(0,X.jsx)($s,{node:e,depth:t+1,selectedPath:r,forceExpand:i,onSelect:a,onOpen:o},e.path))}),s&&!l&&(0,X.jsx)(`div`,{className:`text-[10px] text-muted-foreground italic py-0.5`,style:{paddingLeft:`${(t+1)*14+4}px`},children:`empty`})]})}let d=Qs(e.name),f=Zs(e.name,!1),p=e.path===r;return(0,X.jsxs)(`button`,{type:`button`,onClick:()=>a(e.path),onDoubleClick:t=>{t.preventDefault(),o(e.path)},className:Y(`flex items-center gap-1.5 w-full text-left px-1 py-0.5 text-[11px] rounded`,`hover:bg-muted/60 transition-colors`,u&&`bg-primary/10 text-primary`,p&&!u&&`bg-muted/70 ring-1 ring-inset ring-border`),style:{paddingLeft:`${t*14+4}px`},children:[(0,X.jsx)(`span`,{className:`w-3 shrink-0`}),` `,(0,X.jsx)(d,{className:Y(`h-3.5 w-3.5 shrink-0`,f)}),(0,X.jsx)(`span`,{className:`truncate`,children:e.name})]})}function ec(){let e=q(e=>e.tree),t=q(e=>e.treeLoading),n=q(e=>e.error),r=q(e=>e.openFiles),i=q(e=>e.activeFilePath),a=W(e=>e.cwd),o=W(e=>e.projectName),s=a?.includes(`\\`)?`\\`:`/`,c=(e,t=8,n=4)=>e.length<=t+n+2?e:`${e.slice(0,t)}…${e.slice(-n)}`,l=(()=>{if(!a||!o)return!0;let e=a.replace(/\\/g,`/`).split(`/`).filter(Boolean);return(e[e.length-1]??``)===o})(),u=(0,B.useMemo)(()=>{if(!a||!o)return[];let e=a.replace(/\\/g,`/`).split(`/`).filter(Boolean),t=-1;for(let n=e.length-1;n>=0;n--)if(e[n]===o){t=n;break}if(t===-1)return e.map((t,n)=>({label:t,path:`/`+e.slice(0,n+1).join(`/`),isLast:n===e.length-1}));let n=e.slice(t);return n.map((r,i)=>({label:r,path:`/`+e.slice(0,t+i+1).join(`/`),isLast:i===n.length-1}))},[a,o]),d=(0,B.useRef)(null);(0,B.useEffect)(()=>{let e=d.current;e&&u.length>1&&(e.scrollLeft=e.scrollWidth)},[u]);let f=(0,B.useCallback)(e=>{V().send({type:`working_dir.set`,payload:{path:e}})},[]),[p,m]=(0,B.useState)(null);(0,B.useEffect)(()=>{if(!p)return;let e=()=>m(null),t=t=>{t.key===`Escape`&&e()};return window.addEventListener(`click`,e),window.addEventListener(`keydown`,t),()=>{window.removeEventListener(`click`,e),window.removeEventListener(`keydown`,t)}},[p]);let h=(0,B.useCallback)((e,t)=>{e.preventDefault(),e.stopPropagation(),m({x:e.clientX,y:e.clientY,crumb:t})},[]),g=(0,B.useCallback)(e=>{navigator.clipboard.writeText(e),m(null)},[]),_=(0,B.useCallback)(()=>{if(!i)return;let e=i.replace(/\\/g,`/`).split(`/`).slice(0,-1).join(`/`)||`.`;V().send({type:`working_dir.set`,payload:{path:e}})},[i]),v=(0,B.useCallback)((e,t)=>{V().send({type:`shell.open`,payload:{path:e,target:t}}),m(null)},[]),y=(0,B.useCallback)(()=>{if(!a)return;let e=a.replace(/\\/g,`/`),t=e.split(`/`).slice(0,-1).join(`/`)||e;V().send({type:`working_dir.set`,payload:{path:t}})},[a]),[b,x]=(0,B.useState)(!1),S=(0,B.useRef)(null);(0,B.useEffect)(()=>(t?S.current=setTimeout(()=>x(!0),150):(S.current&&clearTimeout(S.current),x(!1)),()=>{S.current&&clearTimeout(S.current)}),[t]);let[C,w]=(0,B.useState)(null),[T,E]=(0,B.useState)(null),D=(0,B.useMemo)(()=>{let t=0,n=e=>{for(let r of e)r.type===`directory`&&t++,r.children&&n(r.children)};return n(e),t},[e]),O=(0,B.useMemo)(()=>{let t=0,n=0;for(let r of e)r.type===`directory`?n++:t++;return{files:t,dirs:n}},[e]),k={value:!1},A=(0,B.useCallback)(()=>{k.value=!0,E(!1),setTimeout(()=>{k.value=!1},400)},[]),j=(0,B.useCallback)(()=>{k.value=!0,E(!0),setTimeout(()=>{k.value=!1},400)},[]),ee=(0,B.useCallback)(e=>{if(r.find(t=>t.path===e)){q.getState().setActiveFile(e);return}w(t=>t===e?null:e)},[r]),M=(0,B.useCallback)(e=>{window.dispatchEvent(new CustomEvent(`wrongstack:open-file`,{detail:{filePath:e}})),w(null)},[]);return(0,B.useEffect)(()=>{i&&w(null)},[i]),b?(0,X.jsx)(`div`,{className:`flex items-center justify-center h-full py-8`,children:(0,X.jsx)(L,{className:`h-5 w-5 animate-spin text-muted-foreground`})}):n?(0,X.jsxs)(`div`,{className:`p-3 text-[11px] text-destructive`,children:[`Failed to load files: `,n]}):(0,X.jsxs)(`div`,{className:`h-full flex flex-col overflow-hidden`,children:[e.length>0&&D>0&&(0,X.jsxs)(`div`,{className:`flex items-center gap-0.5 px-2 py-0.5 border-b shrink-0`,children:[(0,X.jsxs)(`button`,{type:`button`,onClick:j,className:Y(`flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] transition-colors`,`hover:bg-muted/60 text-muted-foreground hover:text-foreground`),title:`Expand all directories`,children:[(0,X.jsx)(Rt,{className:`h-3 w-3`}),(0,X.jsx)(`span`,{children:`Expand all`})]}),(0,X.jsxs)(`button`,{type:`button`,onClick:A,className:Y(`flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] transition-colors`,`hover:bg-muted/60 text-muted-foreground hover:text-foreground`),title:`Collapse all directories`,children:[(0,X.jsx)(ne,{className:`h-3 w-3`}),(0,X.jsx)(`span`,{children:`Collapse`})]}),(0,X.jsxs)(`span`,{className:`ml-auto text-[9px] text-muted-foreground/50 tabular-nums`,children:[D,` folder`,D===1?``:`s`]})]}),(0,X.jsxs)(`div`,{className:`flex-1 overflow-y-auto py-1`,children:[u.length>0&&(0,X.jsxs)(`div`,{ref:d,className:`relative flex items-center gap-0.5 px-1 pb-1 border-b border-border/30 overflow-x-auto`,children:[(0,X.jsx)(`span`,{className:`sticky left-0 shrink-0 w-3 h-full bg-gradient-to-r from-background to-transparent pointer-events-none`}),u.map((e,t)=>{let n=e.isLast?e.label:c(e.label),r=e.path.replace(/\//g,s),i=a?a.replace(/\\/g,`/`).split(`/`).filter(Boolean):[],l=(()=>{for(let e=i.length-1;e>=0;e--)if(i[e]===o)return e;return-1})(),u=l>=0?i.slice(0,l+t+1):i.slice(0,t+1),d=s===`\\`?u.join(`\\`):`/`+u.join(`/`),p=(l>=0?i.slice(l+1,l+t+1):[]).join(s)||`.`;return(0,X.jsxs)(`span`,{className:`flex items-center gap-0.5 shrink-0`,children:[t>0&&(0,X.jsx)(`span`,{className:`text-[9px] text-muted-foreground/40 select-none`,children:s}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>f(e.path),onContextMenu:e=>h(e,{absPath:d,relPath:p}),className:Y(`px-1 py-0.5 rounded text-[11px] transition-colors whitespace-nowrap`,e.isLast?`text-foreground font-medium`:`text-muted-foreground hover:text-foreground hover:bg-muted/60`),title:e.isLast?`Current directory: ${r}`:`Navigate to ${r}`,children:n})]},e.path)}),e.length>0&&(0,X.jsxs)(`span`,{className:`ml-auto shrink-0 text-[9px] text-muted-foreground/50 tabular-nums pl-2`,children:[O.files>0&&`${O.files} file${O.files===1?``:`s`}`,O.files>0&&O.dirs>0&&`, `,O.dirs>0&&`${O.dirs} folder${O.dirs===1?``:`s`}`]})]}),i&&(0,X.jsxs)(`button`,{type:`button`,onClick:_,className:`flex items-center gap-1 w-full text-left px-2 py-0.5 border-b border-border/30 text-[10px] text-muted-foreground hover:text-foreground hover:bg-accent/50 transition-colors`,title:`Navigate to parent directory of ${i.replace(/\//g,s)}`,children:[(0,X.jsx)(F,{className:`h-3 w-3 shrink-0`}),(0,X.jsx)(`span`,{className:`truncate`,children:(()=>{let e=i.replace(/\\/g,`/`).split(`/`);return e[e.length-1]??i})()}),(0,X.jsx)(`span`,{className:`ml-auto text-[8px] text-muted-foreground/40 shrink-0`,children:`go to dir`})]}),u.length===0&&!l&&(0,X.jsxs)(`button`,{type:`button`,onClick:y,className:Y(`flex items-center gap-1.5 w-full text-left px-1 py-0.5 text-[11px] rounded`,`hover:bg-muted/60 transition-colors text-muted-foreground hover:text-foreground`,`font-medium`),children:[(0,X.jsx)(je,{className:`h-3.5 w-3.5 shrink-0`}),(0,X.jsx)(`span`,{children:`..`}),(0,X.jsx)(`span`,{className:`text-[9px] text-muted-foreground/50 ml-auto`,children:`parent directory`})]}),e.map(e=>(0,X.jsx)($s,{node:e,depth:0,selectedPath:C,forceExpand:T,onSelect:ee,onOpen:M},e.path)),e.length===0&&(0,X.jsx)(`p`,{className:`text-[11px] text-muted-foreground italic p-2`,children:`No files found`})]}),p&&(0,X.jsxs)(`div`,{className:`fixed z-50 min-w-[140px] bg-popover border rounded-md shadow-md py-1 text-[11px]`,style:{left:p.x,top:p.y},children:[(0,X.jsx)(`button`,{type:`button`,onClick:()=>g(p.crumb.absPath),className:`flex items-center gap-2 w-full text-left px-3 py-1.5 hover:bg-accent transition-colors`,children:`Copy absolute path`}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>g(p.crumb.relPath),className:`flex items-center gap-2 w-full text-left px-3 py-1.5 hover:bg-accent transition-colors`,children:`Copy relative path`}),(0,X.jsx)(`div`,{className:`border-t border-border/50 my-0.5`}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>v(p.crumb.absPath,`terminal`),className:`flex items-center gap-2 w-full text-left px-3 py-1.5 hover:bg-accent transition-colors`,children:`Open in terminal`}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>v(p.crumb.absPath,`file-manager`),className:`flex items-center gap-2 w-full text-left px-3 py-1.5 hover:bg-accent transition-colors`,children:`Open in file manager`}),(0,X.jsx)(`div`,{className:`border-t border-border/50 mt-0.5 pt-0.5`,children:(0,X.jsx)(`div`,{className:`px-3 py-1 text-[9px] text-muted-foreground/50 truncate max-w-[200px]`,children:p.crumb.absPath})})]})]})}var tc={note:I,ask:en,assign:f,steer:Ee,btw:Ze,broadcast:f,status:C,result:Be};function nc(e){let t=new Date(e),n=Date.now()-t.getTime();return n<6e4?`now`:n<36e5?`${Math.round(n/6e4)}m`:n<864e5?`${Math.round(n/36e5)}h`:t.toLocaleDateString()}function rc({className:e}){let t=er(e=>e.messages),n=er(e=>e.agents),[r,i]=(0,B.useState)(!1),[a,o]=(0,B.useState)(!1),{client:s}=Z(),[c,l]=(0,B.useState)(s.status.state===`open`);(0,B.useEffect)(()=>{let e=s.onStatus(e=>l(e.state===`open`));return()=>e()},[s]),(0,B.useEffect)(()=>{c&&(s.send({type:`mailbox.messages`,payload:{limit:30}}),s.send({type:`mailbox.agents`,payload:{}}))},[c,s]);let u=t.filter(e=>!e.completed).length,d=n.filter(e=>e.online).length;async function f(){t.length!==0&&await ns({title:`Delete all ${t.length} message${t.length===1?``:`s`}?`,message:`The mailbox file is truncated for every agent. This cannot be undone.`,confirmLabel:`Delete all`,danger:!0})&&(o(!0),s.send({type:`mailbox.clear`}))}return(0,B.useEffect)(()=>{a&&t.length===0&&o(!1)},[a,t.length]),(0,X.jsxs)(`div`,{className:Y(`rounded-lg border border-border bg-card/60 backdrop-blur-sm`,e),children:[(0,X.jsxs)(`button`,{type:`button`,onClick:()=>i(e=>!e),className:`flex w-full items-center gap-2 px-3 py-2.5 text-left hover:bg-accent/40 rounded-t-lg transition-colors`,children:[(0,X.jsx)(Re,{className:`h-4 w-4 text-cyan-500`}),(0,X.jsx)(`span`,{className:`text-xs font-semibold text-foreground flex-1 min-w-0 truncate`,children:`Mailbox`}),u>0&&(0,X.jsx)(`span`,{className:`inline-flex items-center px-1.5 py-0.5 rounded-full text-[10px] font-bold bg-yellow-100 dark:bg-yellow-900/40 text-yellow-700 dark:text-yellow-400`,children:u}),(0,X.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[d,` online`]})]}),!r&&(0,X.jsxs)(`div`,{className:`px-3 pb-3 space-y-2`,children:[t.length>0?(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsx)(`span`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wide`,children:`Messages`}),(0,X.jsxs)(`button`,{type:`button`,onClick:f,disabled:a,className:`flex items-center gap-1 text-[10px] text-muted-foreground hover:text-red-500 disabled:opacity-40 transition-colors`,title:`Delete all messages`,children:[(0,X.jsx)(at,{className:`h-3 w-3`}),a?`Deleting…`:`Delete all`]})]}),t.slice(0,8).map(e=>{let t=tc[e.type]??tn,n=e.readByCount>0;return(0,X.jsxs)(`div`,{className:Y(`flex items-start gap-2 px-2 py-1.5 rounded text-xs`,!n&&`bg-yellow-50 dark:bg-yellow-950/20`),children:[(0,X.jsx)(t,{className:Y(`h-3.5 w-3.5 mt-0.5 shrink-0`,n?`text-muted-foreground`:`text-yellow-600`)}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(`span`,{className:Y(`font-medium truncate`,!n&&`text-yellow-800 dark:text-yellow-300`),children:e.from}),e.completed&&(0,X.jsx)(Be,{className:`h-3 w-3 text-green-500 shrink-0`}),!n&&(0,X.jsx)(`span`,{className:`text-[9px] text-yellow-600 font-bold`,children:`NEW`})]}),(0,X.jsx)(`div`,{className:`text-muted-foreground truncate`,children:e.subject}),(0,X.jsxs)(`div`,{className:`text-[10px] text-muted-foreground/70 truncate`,children:[e.body.slice(0,60),e.body.length>60?`…`:``]})]}),(0,X.jsxs)(`div`,{className:`shrink-0 text-[10px] text-muted-foreground flex flex-col items-end gap-0.5`,children:[(0,X.jsx)(`span`,{children:nc(e.timestamp)}),n&&(0,X.jsxs)(`span`,{className:`flex items-center gap-0.5`,children:[(0,X.jsx)(Et,{className:`h-3 w-3`}),e.readByCount]})]})]},e.id)})]}):(0,X.jsxs)(`div`,{className:`text-xs text-muted-foreground py-2 text-center`,children:[(0,X.jsx)(We,{className:`h-4 w-4 mx-auto mb-1 opacity-40`}),`No messages yet.`]}),n.length>0&&(0,X.jsxs)(`div`,{className:`border-t border-border pt-2`,children:[(0,X.jsxs)(`div`,{className:`text-[10px] font-semibold text-muted-foreground mb-1 flex items-center gap-1`,children:[(0,X.jsx)(Wt,{className:`h-3 w-3`}),` Agents`]}),n.filter(e=>e.online).slice(0,5).map(e=>(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] text-muted-foreground py-0.5`,children:[(0,X.jsx)(`span`,{className:Y(`h-1.5 w-1.5 rounded-full`,e.online?`bg-green-500`:`bg-muted-foreground/30`)}),(0,X.jsx)(`span`,{className:`font-medium text-foreground/80`,children:e.name}),e.role&&(0,X.jsxs)(`span`,{className:`opacity-60`,children:[`(`,e.role,`)`]}),(0,X.jsx)(`span`,{className:`opacity-50`,children:e.status}),e.currentTool&&(0,X.jsx)(`span`,{className:`text-cyan-500`,children:e.currentTool}),(0,X.jsx)(`span`,{className:`ml-auto opacity-50`,children:nc(e.lastSeenAt)})]},e.agentId)),n.filter(e=>!e.online).length>0&&(0,X.jsxs)(`div`,{className:`text-[10px] text-muted-foreground/50 mt-0.5`,children:[`+`,n.filter(e=>!e.online).length,` offline`]})]})]})]})}function ic({fullView:e}){let[t,n]=(0,B.useState)([]),[r,i]=(0,B.useState)(!0),[a,o]=(0,B.useState)(!1),[s,c]=(0,B.useState)(``),[l,u]=(0,B.useState)(``),[d,f]=(0,B.useState)(!1),p=(0,B.useRef)(null),[m,h]=(0,B.useState)({open:!1,project:null,agentCount:0}),g=(0,B.useCallback)(()=>{V().send({type:`projects.list`})},[]);(0,B.useEffect)(()=>{i(!0);let e=V(),t=e.on(`projects.list`,e=>{let t=e.payload;n(t.projects??[]),i(!1)}),r=e.on(`projects.added`,e=>{let t=e.payload;t.slug?(Sr.success(t.message),g()):Sr.error(t.message)});return g(),()=>{t(),r()}},[g]);let _=e=>{if(!e)return`never`;let t=Date.now()-new Date(e).getTime(),n=Math.floor(t/6e4);if(n<1)return`just now`;if(n<60)return`${n}m ago`;let r=Math.floor(n/60);if(r<24)return`${r}h ago`;let i=Math.floor(r/24);return i===1?`yesterday`:i<30?`${i}d ago`:i<365?`${Math.floor(i/30)}mo ago`:`${Math.floor(i/365)}y ago`},v=(0,B.useCallback)(e=>{let t=W.getState().session?.id;if(t){let n=K.getState().getAgentsBySession(t).filter(e=>e.status===`running`);if(n.length>0){h({open:!0,project:e,agentCount:n.length});return}}y(e)},[]),y=(0,B.useCallback)(e=>{let t=V();t.send({type:`projects.select`,payload:{root:e.root,name:e.name}});let n=t.on(`projects.selected`,e=>{let t=e.payload;n();let r=t.message.match(/(https?:\/\/[^\s]+)/);r&&r[1]?(window.open(r[1],`_blank`),Sr.success(`Opening ${t.name} in a new tab...`)):Sr.info(t.message)})},[]),b=(0,B.useCallback)(()=>{let e=s.trim();if(!e){Sr.error(`Please enter a folder path.`);return}o(!0);let t=V();t.send({type:`projects.add`,payload:{root:e,name:l.trim()||void 0}});let n=t.on(`projects.added`,()=>{n(),o(!1),f(!1),c(``),u(``)})},[s,l]),x=m.open&&m.project&&(0,X.jsx)(Uo,{open:!0,onOpenChange:()=>h({open:!1,project:null,agentCount:0}),children:(0,X.jsxs)(qo,{className:`sm:max-w-sm`,children:[(0,X.jsxs)(Jo,{children:[(0,X.jsx)(Xo,{children:`Running Agents`}),(0,X.jsxs)(Zo,{children:[m.agentCount,` agent`,m.agentCount===1?` is`:`s are`,` running in the current session. Switching projects will stop them.`]})]}),(0,X.jsxs)(Yo,{children:[(0,X.jsx)($,{variant:`outline`,size:`sm`,onClick:()=>h({open:!1,project:null,agentCount:0}),children:`Cancel`}),(0,X.jsx)($,{size:`sm`,variant:`destructive`,onClick:()=>{let e=m.project;h({open:!1,project:null,agentCount:0}),y(e)},children:`Switch anyway`})]})]})}),S=[...t].sort((e,t)=>e.lastSeen&&t.lastSeen?t.lastSeen.localeCompare(e.lastSeen):e.lastSeen?-1:t.lastSeen?1:e.name.localeCompare(t.name)),C=(0,X.jsxs)(Uo,{open:d,onOpenChange:f,children:[(0,X.jsx)(Wo,{asChild:!0,children:(0,X.jsxs)($,{variant:`outline`,size:`sm`,className:`gap-1 h-7 text-xs`,children:[(0,X.jsx)(_t,{className:`h-3 w-3`}),`Register Project`]})}),(0,X.jsxs)(qo,{className:`sm:max-w-md`,children:[(0,X.jsxs)(Jo,{children:[(0,X.jsx)(Xo,{children:`Register New Project`}),(0,X.jsxs)(Zo,{children:[`Enter the absolute path to a project folder. The project will be added to`,` `,(0,X.jsx)(`code`,{className:`font-mono bg-muted/40 px-1 rounded text-xs`,children:`~/.wrongstack/projects.json`}),`.`]})]}),(0,X.jsxs)(`div`,{className:`space-y-3`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{htmlFor:`proj-folder`,className:`text-xs font-medium text-muted-foreground mb-1 block`,children:`Folder path`}),(0,X.jsx)(cs,{id:`proj-folder`,placeholder:`/home/user/my-project or C:\\Users\\me\\my-project`,value:s,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`&&p.current?.focus()}})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{htmlFor:`proj-name`,className:`text-xs font-medium text-muted-foreground mb-1 block`,children:`Project name (optional — defaults to folder name)`}),(0,X.jsx)(cs,{id:`proj-name`,ref:p,placeholder:`My Project`,value:l,onChange:e=>u(e.target.value),onKeyDown:e=>{e.key===`Enter`&&b()}})]})]}),(0,X.jsxs)(Yo,{children:[(0,X.jsx)($,{variant:`outline`,size:`sm`,onClick:()=>f(!1),children:`Cancel`}),(0,X.jsxs)($,{size:`sm`,onClick:b,disabled:a||!s.trim(),children:[a?(0,X.jsx)(L,{className:`h-3 w-3 animate-spin mr-1`}):null,`Register`]})]})]})]});if(r){let t=(0,X.jsx)(`div`,{className:`flex items-center justify-center py-6`,children:(0,X.jsx)(L,{className:`h-4 w-4 animate-spin text-muted-foreground`})});return e?(0,X.jsxs)(`div`,{className:`h-full flex flex-col overflow-hidden`,children:[(0,X.jsx)(`div`,{className:`px-3 py-2 border-b flex items-center justify-between`,children:(0,X.jsx)(`h2`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:`Projects`})}),(0,X.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:t})]}):t}let w=(0,X.jsx)(`div`,{className:Y(`space-y-1`,e&&`p-2`),children:S.map(e=>(0,X.jsxs)(`button`,{type:`button`,onClick:()=>v(e),className:`flex items-start gap-2 w-full text-left px-2 py-1.5 rounded border bg-card/40 text-xs hover:bg-accent hover:border-primary/40 transition-colors`,children:[(0,X.jsx)(xt,{className:`h-3.5 w-3.5 shrink-0 mt-0.5 text-muted-foreground`}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`div`,{className:`font-medium truncate`,children:e.name}),(0,X.jsx)(`div`,{className:`font-mono text-[10px] text-muted-foreground truncate`,children:e.root}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5 text-[10px] text-muted-foreground/60`,children:[(0,X.jsx)(`span`,{className:`font-mono`,children:e.slug}),e.lastSeen&&(0,X.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,X.jsx)(Pt,{className:`h-2.5 w-2.5`}),_(e.lastSeen)]})]})]}),(0,X.jsx)(ue,{className:`h-3 w-3 shrink-0 mt-1 text-muted-foreground/40`})]},e.slug))});return e?(0,X.jsxs)(`div`,{className:`h-full flex flex-col overflow-hidden`,children:[x,(0,X.jsxs)(`div`,{className:`px-3 py-2 border-b shrink-0`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsx)(`h2`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:`Projects`}),C]}),(0,X.jsxs)(`p`,{className:`text-[10px] text-muted-foreground/60 mt-0.5`,children:[`Known projects from`,` `,(0,X.jsx)(`code`,{className:`font-mono bg-muted/40 px-0.5 rounded`,children:`~/.wrongstack/projects.json`})]})]}),t.length===0?(0,X.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,X.jsxs)(`div`,{className:`text-xs text-muted-foreground italic py-2`,children:[`No projects registered. Use the button above or run`,` `,(0,X.jsx)(`code`,{className:`font-mono bg-muted/40 px-1 rounded`,children:`wstack`}),` `,`in a directory to register it.`]})}):(0,X.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:w}),(0,X.jsx)(`div`,{className:`px-3 py-2 border-t shrink-0`,children:(0,X.jsx)(`p`,{className:`text-[9px] text-muted-foreground/40 text-center`,children:`Click a project to open it in a new WebUI tab`})})]}):(0,X.jsxs)(`div`,{className:`space-y-2`,children:[x,(0,X.jsx)(`div`,{className:`flex items-center justify-between`,children:C}),t.length===0?(0,X.jsxs)(`div`,{className:`text-xs text-muted-foreground italic py-2`,children:[`No projects registered. Use the button above or run`,` `,(0,X.jsx)(`code`,{className:`font-mono bg-muted/40 px-1 rounded`,children:`wstack`}),` `,`in a directory to register it.`]}):w]})}var ac=[` `,`▁`,`▂`,`▃`,`▄`,`▅`,`▆`,`▇`,`█`],oc=12;function sc(e,t){return t===0?0:Math.min(8,Math.round(e/t*8))}function cc({bins:e,className:t,width:n=oc}){let r=Array.from({length:oc},(t,n)=>e.at(-(oc-n))??0),i=Math.max(...r,1);return i===1&&r.every(e=>e===0)?(0,X.jsx)(`span`,{className:t,"aria-label":`No activity`,title:`No activity yet`,children:`—`}):(0,X.jsx)(`span`,{className:t,"aria-label":`Activity sparkline: max ${i} events`,title:`Activity sparkline — peak ${i} events/bucket`,children:r.map((e,t)=>{let n=sc(e,i),r=ac[n];return(0,X.jsx)(`span`,{style:{color:n>=7?`hsl(var(--success))`:`hsl(var(--muted-foreground))`,opacity:n>0?void 0:.3},children:r},t)})})}var lc={running:{led:`text-[hsl(var(--success))]`,label:`running`,pulse:!0},completed:{led:`text-[hsl(var(--success))]`,label:`done`,pulse:!1},failed:{led:`text-destructive`,label:`failed`,pulse:!1},timeout:{led:`text-[hsl(var(--warning))]`,label:`timeout`,pulse:!1},stopped:{led:`text-muted-foreground`,label:`stopped`,pulse:!1}};function uc(e){return e<=0?`$0`:e>=.01?`$${e.toFixed(3)}`:`$${e.toFixed(5)}`.replace(/0+$/,``).replace(/\.$/,``)}function dc(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e)}function fc(e){let t=Math.floor(e/1e3);return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`}function pc({agent:e,onClose:t}){let n=lc[e.status],r=e.status===`running`,i=e.currentTool??e.lastTool,a=Date.now()-e.startedAt,[o,s]=(0,B.useState)(!1),l=K(e=>e.leaderId),u=e.id===l,d=(0,B.useCallback)(async e=>{try{await navigator.clipboard.writeText(e),s(!0),setTimeout(()=>s(!1),2e3)}catch{}},[]),f=e.ctxPct>=85?`bg-red-500/15 text-red-600 dark:text-red-400`:e.ctxPct>=70?`bg-amber-500/15 text-amber-600 dark:text-amber-400`:`bg-muted text-muted-foreground`;return(0,X.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-start justify-center pt-[10vh] bg-black/40 backdrop-blur-sm`,children:(0,X.jsxs)(`div`,{className:`w-full max-w-xl max-h-[80vh] overflow-y-auto rounded-xl border bg-card shadow-2xl`,children:[(0,X.jsxs)(`div`,{className:Y(`flex items-center justify-between px-4 py-3 border-b`,r?`border-primary/20`:`border-border`),children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`span`,{className:Y(`led`,n.led,n.pulse&&`led-pulse`)}),(0,X.jsx)(`h3`,{className:`text-sm font-semibold`,children:e.name}),u&&(0,X.jsx)(be,{className:`h-3.5 w-3.5 text-amber-500 shrink-0`,"aria-label":`leader`}),(0,X.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:n.label})]}),(0,X.jsx)(`button`,{type:`button`,onClick:t,className:`p-1 rounded-md hover:bg-muted transition-colors`,children:(0,X.jsx)(Ie,{className:`h-4 w-4`})})]}),(0,X.jsxs)(`div`,{className:`p-4 space-y-4`,children:[e.description&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground leading-relaxed`,children:e.description}),(0,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,X.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-3 py-2`,children:[(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Provider / Model`}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1 mt-0.5`,children:[(0,X.jsx)(c,{className:`h-3 w-3 text-muted-foreground`}),(0,X.jsxs)(`span`,{className:`text-xs font-mono font-medium`,children:[e.provider??`?`,`/`,e.model??`?`]})]})]}),(0,X.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-3 py-2`,children:[(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Elapsed`}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1 mt-0.5`,children:[(0,X.jsx)(Pe,{className:`h-3 w-3 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`text-xs font-mono tabular`,children:fc(a)}),r&&(0,X.jsx)(`span`,{className:`text-[10px] text-[hsl(var(--success))]`,children:`· running`})]})]}),(0,X.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-3 py-2`,children:[(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Iterations`}),(0,X.jsx)(`span`,{className:`block text-xs font-mono font-medium mt-0.5 tabular`,children:e.iteration})]}),(0,X.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-3 py-2`,children:[(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Tool Calls`}),(0,X.jsx)(`span`,{className:`block text-xs font-mono font-medium mt-0.5 tabular`,children:e.toolCalls})]}),(0,X.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-3 py-2`,children:[(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Cost`}),(0,X.jsx)(`span`,{className:`block text-xs font-mono font-medium mt-0.5 tabular`,children:uc(e.costUsd)})]}),e.extensions>0&&(0,X.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-3 py-2`,children:[(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Budget Extensions`}),(0,X.jsxs)(`span`,{className:`block text-xs font-mono font-medium mt-0.5 tabular`,children:[`⚡×`,e.extensions]})]})]}),r&&(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Activity`}),(0,X.jsx)(cc,{bins:e.sparklineBins,className:`font-mono`})]}),e.budgetWarning&&(0,X.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg bg-amber-500/10 border border-amber-500/20 text-xs`,children:[(0,X.jsx)(ze,{className:`h-3.5 w-3.5 text-amber-500 shrink-0`}),(0,X.jsxs)(`span`,{className:`text-amber-600 dark:text-amber-400`,children:[`⚡ hitting `,(0,X.jsx)(`strong`,{children:e.budgetWarning.kind}),` limit (`,e.budgetWarning.used,`/`,e.budgetWarning.limit,`) — extending`]})]}),e.maxContext>0&&(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between text-[10px]`,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`Context window`}),(0,X.jsxs)(`span`,{className:Y(`tabular font-medium`,f.replace(/bg-\S+\s*/g,``)),children:[e.ctxPct,`%`]})]}),(0,X.jsx)(`div`,{className:`h-1.5 w-full overflow-hidden rounded-full bg-muted`,children:(0,X.jsx)(`div`,{className:Y(`h-full rounded-full transition-all`,e.ctxPct>=85?`bg-destructive`:e.ctxPct>=70?`bg-[hsl(var(--warning))]`:`bg-primary`),style:{width:`${Math.min(200,Math.max(2,e.ctxPct))}%`}})}),(0,X.jsxs)(`div`,{className:`text-[10px] text-muted-foreground tabular text-right`,children:[dc(e.ctxTokens),` / `,dc(e.maxContext),` tokens`]})]}),i&&(0,X.jsxs)(`div`,{className:Y(`flex items-center gap-2 rounded-lg border px-3 py-2`,r?`border-primary/30 bg-primary/[0.04]`:`border-border bg-muted/30`),children:[(0,X.jsx)(He,{className:Y(`h-3.5 w-3.5`,r?`text-primary animate-pulse`:`text-muted-foreground`)}),(0,X.jsx)(`span`,{className:`text-xs font-mono`,children:i}),(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground ml-auto`,children:e.currentTool?`running…`:`last tool`})]}),e.error&&(0,X.jsxs)(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 p-3`,children:[(0,X.jsx)(`span`,{className:`text-[10px] font-semibold text-destructive uppercase tracking-wider`,children:`Error`}),(0,X.jsx)(`p`,{className:`text-xs text-destructive/90 mt-1 leading-relaxed`,children:e.error.message})]}),e.finalText?(0,X.jsxs)(`div`,{className:`rounded-lg border bg-muted/20 p-3`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between mb-1.5`,children:[(0,X.jsx)(`span`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wider`,children:`Final Output`}),(0,X.jsxs)(`button`,{type:`button`,onClick:()=>d(e.finalText),className:`flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] text-muted-foreground hover:text-foreground hover:bg-muted transition-colors`,title:`Copy output`,children:[o?(0,X.jsx)(pn,{className:`h-3 w-3 text-emerald-500`}):(0,X.jsx)(E,{className:`h-3 w-3`}),o?`Copied`:`Copy`]})]}),(0,X.jsx)(`pre`,{className:`text-xs whitespace-pre-wrap font-mono text-foreground/80 leading-relaxed max-h-64 overflow-y-auto`,children:e.finalText})]}):e.partialText?(0,X.jsxs)(`div`,{className:`rounded-lg border bg-muted/20 p-3`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between mb-1.5`,children:[(0,X.jsx)(`span`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wider`,children:`Live Output`}),(0,X.jsxs)(`button`,{type:`button`,onClick:()=>d(e.partialText),className:`flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] text-muted-foreground hover:text-foreground hover:bg-muted transition-colors`,title:`Copy output`,children:[o?(0,X.jsx)(pn,{className:`h-3 w-3 text-emerald-500`}):(0,X.jsx)(E,{className:`h-3 w-3`}),o?`Copied`:`Copy`]})]}),(0,X.jsx)(`pre`,{className:`text-xs whitespace-pre-wrap font-mono text-foreground/80 leading-relaxed max-h-48 overflow-y-auto`,children:e.partialText})]}):r?(0,X.jsxs)(`div`,{className:`rounded-lg border border-dashed border-border p-3 text-center`,children:[(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Waiting for output…`}),(0,X.jsx)(`p`,{className:`text-[10px] text-muted-foreground/60 mt-0.5`,children:`Output appears here as the agent streams text.`})]}):null,e.toolLog.length>0&&(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsxs)(`span`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wider`,children:[`Tool Log (`,e.toolLog.length,`)`]}),(0,X.jsxs)(`div`,{className:`max-h-40 overflow-y-auto space-y-0.5`,children:[e.toolLog.slice(0,15).map((e,t)=>(0,X.jsxs)(`div`,{className:Y(`flex items-center gap-2 rounded px-2 py-1 text-[10px]`,e.ok?`bg-muted/30`:`bg-destructive/5 border border-destructive/20`),children:[(0,X.jsx)(`span`,{className:Y(`led shrink-0`,e.ok?`text-[hsl(var(--success))]`:`text-destructive`)}),(0,X.jsx)(`span`,{className:`font-mono truncate flex-1`,children:e.name}),(0,X.jsxs)(`span`,{className:`tabular text-muted-foreground`,children:[e.durationMs,`ms`]}),!e.ok&&(0,X.jsx)(`span`,{className:`text-destructive font-medium`,children:`fail`})]},`${e.name}-${e.at}-${t}`)),e.toolLog.length>15&&(0,X.jsxs)(`p`,{className:`text-[9px] text-muted-foreground text-center px-2 py-0.5`,children:[`+`,e.toolLog.length-15,` more tools`]})]})]})]})]})})}function mc({a:e,onClick:t}){let n=lc[e.status],r=e.status===`running`,i=e.currentTool??e.lastTool;return(0,X.jsxs)(`button`,{type:`button`,onClick:t,className:Y(`flex min-w-[12rem] max-w-[15rem] flex-col gap-1 rounded-lg border p-2 transition-colors text-left cursor-pointer`,`hover:border-primary/40 hover:bg-primary/[0.06]`,r?`border-primary/30 bg-primary/[0.04]`:`border-border bg-card opacity-85`),children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,X.jsx)(`span`,{className:Y(`led shrink-0`,n.led,n.pulse&&`led-pulse`)}),(0,X.jsx)(`span`,{className:`truncate text-[11px] font-semibold text-foreground`,title:e.name,children:e.name}),(0,X.jsxs)(`span`,{className:`tabular ml-auto shrink-0 text-[10px] text-muted-foreground`,children:[e.iteration,`it · `,e.toolCalls,`t`]})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[e.model&&(0,X.jsxs)(`span`,{className:`flex items-center gap-0.5 text-[10px] text-muted-foreground truncate`,title:`${e.provider??``}/${e.model}`,children:[(0,X.jsx)(c,{className:`h-2.5 w-2.5 shrink-0`}),(0,X.jsx)(`span`,{className:`truncate font-mono`,children:e.model})]}),(0,X.jsx)(`span`,{className:`tabular text-[10px] text-foreground/75 ml-auto`,children:uc(e.costUsd)})]}),i&&(0,X.jsxs)(`div`,{className:Y(`flex items-center gap-1 text-[10px] truncate`,r?`text-primary`:`text-muted-foreground`),title:e.currentTool?`running ${i}`:`last: ${i}`,children:[(0,X.jsx)(He,{className:Y(`h-2.5 w-2.5 shrink-0`,r&&`animate-pulse`)}),(0,X.jsx)(`span`,{className:`truncate font-mono`,children:i})]}),r&&e.maxContext>0&&(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,title:`Context ${e.ctxPct}%`,children:[(0,X.jsx)(`div`,{className:`h-1 flex-1 overflow-hidden rounded-full bg-muted`,children:(0,X.jsx)(`div`,{className:Y(`h-full rounded-full transition-all`,e.ctxPct>=85?`bg-destructive`:e.ctxPct>=70?`bg-[hsl(var(--warning))]`:`bg-primary`),style:{width:`${Math.min(200,Math.max(2,e.ctxPct))}%`}})}),(0,X.jsx)(`span`,{className:`tabular text-[9px] text-muted-foreground`,children:e.maxContext>0?`${e.ctxPct}%`:`—`})]}),e.error&&(0,X.jsx)(`div`,{className:`truncate rounded bg-destructive/10 px-1 py-0.5 text-[9px] text-destructive`,title:e.error.message,children:e.error.message})]})}function hc({className:e}){let t=K(e=>e.agents),[r,i]=(0,B.useState)(!0),[a,o]=(0,B.useState)(null),s=(0,B.useMemo)(()=>{let e=Array.from(t.values());return e.sort((e,t)=>{let n=e.status===`running`?0:1,r=t.status===`running`?0:1;return n===r?e.startedAt-t.startedAt:n-r}),e},[t]),c=a?s.find(e=>e.id===a):null;if(s.length===0)return null;let l=s.filter(e=>e.status===`running`),u=s.filter(e=>e.status===`completed`),d=s.filter(e=>e.status===`failed`||e.status===`timeout`),f=s.reduce((e,t)=>e+(t.costUsd??0),0),p=r&&s.length>=3;return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:Y(`rounded-lg border border-border bg-card/50 backdrop-blur-sm overflow-hidden`,e),children:[(0,X.jsxs)(`button`,{type:`button`,onClick:()=>i(e=>!e),className:`flex w-full items-center gap-2 px-3 py-1.5 text-left hover:bg-muted/30 transition-colors`,children:[(0,X.jsx)(R,{className:`h-3.5 w-3.5 text-primary`}),(0,X.jsx)(`span`,{className:`text-[11px] font-semibold text-foreground`,children:`Fleet`}),(0,X.jsxs)(`span`,{className:`flex items-center gap-1.5 ml-auto text-[10px]`,children:[l.length>0&&(0,X.jsxs)(`span`,{className:`flex items-center gap-1 text-[hsl(var(--success))]`,children:[(0,X.jsx)(`span`,{className:`led led-pulse text-[hsl(var(--success))]`}),l.length]}),u.length>0&&(0,X.jsxs)(`span`,{className:`text-muted-foreground`,children:[u.length,` done`]}),d.length>0&&(0,X.jsxs)(`span`,{className:`text-destructive`,children:[d.length,` err`]}),f>0&&(0,X.jsx)(`span`,{className:`tabular text-foreground/70`,children:uc(f)})]}),p?(0,X.jsx)(n,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}):(0,X.jsx)(ut,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`})]}),!p&&(0,X.jsx)(`div`,{className:`flex gap-2 overflow-x-auto px-2 pb-2`,children:s.map(e=>(0,X.jsx)(mc,{a:e,onClick:()=>o(e.id)},e.id))})]}),c&&(0,X.jsx)(pc,{agent:c,onClose:()=>o(null)})]})}var gc={running:{led:`text-[hsl(var(--success))]`,label:`running`,pulse:!0},completed:{led:`text-[hsl(var(--success))]`,label:`done`,pulse:!1},failed:{led:`text-destructive`,label:`failed`,pulse:!1},timeout:{led:`text-[hsl(var(--warning))]`,label:`timeout`,pulse:!1},stopped:{led:`text-muted-foreground`,label:`stopped`,pulse:!1}};function _c(e){return e<=0?`$0`:e>=.01?`$${e.toFixed(3)}`:`$${e.toFixed(4)}`}function vc({agent:e,onClick:t}){let n=gc[e.status],r=e.status===`running`;return(0,X.jsxs)(`button`,{type:`button`,onClick:t,className:Y(`w-full text-left rounded-lg border px-2.5 py-2 transition-colors`,`hover:border-primary/40 hover:bg-primary/[0.04]`,r?`border-primary/30 bg-primary/[0.03]`:`border-border/60 bg-card/40`),children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,X.jsx)(`span`,{className:Y(`led shrink-0`,n.led,n.pulse&&`led-pulse`)}),(0,X.jsx)(`span`,{className:`truncate text-[11px] font-semibold`,title:e.name,children:e.name}),(0,X.jsxs)(`span`,{className:`tabular ml-auto shrink-0 text-[10px] text-muted-foreground`,children:[e.iteration,`it`]})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-0.5 min-w-0`,children:[e.model?(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground truncate font-mono`,children:e.model}):(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground italic`,children:`pending…`}),(0,X.jsx)(`span`,{className:`tabular ml-auto text-[10px] text-foreground/70`,children:_c(e.costUsd)})]}),(e.currentTool||e.lastTool)&&(0,X.jsxs)(`div`,{className:`flex items-center gap-1 mt-1 text-[10px] text-muted-foreground truncate`,children:[(0,X.jsx)(He,{className:Y(`h-2.5 w-2.5 shrink-0`,r&&`animate-pulse text-primary`)}),(0,X.jsx)(`span`,{className:`truncate font-mono`,children:e.currentTool??e.lastTool})]})]})}function yc(){let e=K(e=>e.agents),t=G(e=>e.setCurrentView),[n,r]=(0,B.useState)(null),i=(0,B.useMemo)(()=>{let t=Array.from(e.values());return t.sort((e,t)=>{let n=e.status===`running`?0:1,r=t.status===`running`?0:1;return n===r?e.startedAt-t.startedAt:n-r}),t},[e]),a=i.filter(e=>e.status===`running`).length,o=n?i.find(e=>e.id===n)??null:null;return i.length===0?(0,X.jsx)(`div`,{className:`flex-1 flex items-center justify-center p-4`,children:(0,X.jsxs)(`div`,{className:`text-center text-muted-foreground`,children:[(0,X.jsx)(R,{className:`h-8 w-8 mx-auto mb-3 opacity-20`}),(0,X.jsx)(`p`,{className:`text-sm font-medium`,children:`No agents yet`}),(0,X.jsx)(`p`,{className:`text-xs mt-1`,children:`Subagents appear here when the fleet is active.`})]})}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`px-3 py-2 border-b text-[10px] text-muted-foreground flex items-center gap-2`,children:[(0,X.jsx)(`span`,{className:`font-semibold uppercase tracking-wider`,children:`Fleet`}),(0,X.jsxs)(`span`,{className:`ml-auto tabular-nums`,children:[a>0?`${a} running · `:``,i.length,` total`]})]}),(0,X.jsx)(`div`,{className:`flex-1 overflow-y-auto p-2 space-y-1.5`,children:i.map(e=>(0,X.jsx)(vc,{agent:e,onClick:()=>r(e.id)},e.id))}),(0,X.jsx)(`div`,{className:`border-t px-3 py-2 shrink-0`,children:(0,X.jsxs)(`button`,{type:`button`,onClick:()=>t(`agents`),className:`w-full flex items-center justify-center gap-1.5 h-7 rounded-md border border-border text-[11px] text-muted-foreground hover:text-foreground hover:bg-accent transition-colors`,children:[(0,X.jsx)(rn,{className:`h-3 w-3`}),`Open full agents view`]})}),o&&(0,X.jsx)(pc,{agent:o,onClose:()=>r(null)})]})}var bc=e=>{let t=Date.parse(e);if(Number.isNaN(t))return``;let n=Date.now()-t;if(n<6e4)return`just now`;if(n<36e5)return`${Math.floor(n/6e4)}m ago`;if(n<864e5)return`${Math.floor(n/36e5)}h ago`;let r=Math.floor(n/864e5);return r<7?`${r}d ago`:new Date(t).toLocaleDateString()};function xc(e){return e.filter(e=>e.tokenTotal===0&&!e.isCurrent).map(e=>e.id)}function Sc({historyQuery:e,setHistoryQuery:t,historyEntries:n,historyLoading:r,historyError:i,wsConnected:a,listSessions:o,resumeSession:s,deleteSession:c}){let l=G(e=>e.favoriteSessionIds),u=G(e=>e.toggleFavoriteSession),d=G(e=>e.sessionNicknames),f=G(e=>e.setSessionNickname),[p,m]=(0,B.useState)(null),[h,g]=(0,B.useState)(``),[_,v]=(0,B.useState)(null);(0,B.useEffect)(()=>{_&&n.some(e=>e.id===_&&e.isCurrent)&&v(null)},[_,n]);let y=(0,B.useCallback)(e=>{v(e),s(e),setTimeout(()=>v(t=>t===e?null:t),1e4)},[s]),b=(0,B.useMemo)(()=>xc(n),[n]),x=(0,B.useCallback)(async()=>{if(b.length!==0&&await ns({title:b.length===1?`Delete 1 empty session?`:`Delete ${b.length} empty sessions?`,message:`Sessions without any token usage are removed from disk.`,confirmLabel:`Delete`,danger:!0}))for(let e of b)c(e)},[b,c]),S=(()=>{let t=e.trim().toLowerCase(),r=t?n.filter(e=>e.title.toLowerCase().includes(t)||e.model.toLowerCase().includes(t)||e.provider.toLowerCase().includes(t)||e.id.toLowerCase().includes(t)):n,i=new Date;i.setHours(0,0,0,0);let a=i.getTime(),o=a-864e5,s=a-6*864e5,c={today:[],yesterday:[],week:[],older:[]};for(let e of r){let t=Date.parse(e.startedAt);if(Number.isNaN(t)){c.older.push(e);continue}t>=a?c.today.push(e):t>=o?c.yesterday.push(e):t>=s?c.week.push(e):c.older.push(e)}let u=new Set(l),d=r.filter(e=>u.has(e.id)),f=[];d.length&&f.push({label:`Favorites`,rows:d,star:!0});let p=e=>e.filter(e=>!u.has(e.id)),m=p(c.today),h=p(c.yesterday),g=p(c.week),_=p(c.older);return m.length&&f.push({label:`Today`,rows:m}),h.length&&f.push({label:`Yesterday`,rows:h}),g.length&&f.push({label:`This week`,rows:g}),_.length&&f.push({label:`Earlier`,rows:_}),f})();return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b`,children:[(0,X.jsx)(`span`,{className:`text-xs uppercase tracking-wider text-muted-foreground`,children:`Recent sessions`}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,children:[b.length>0&&(0,X.jsx)(`button`,{type:`button`,className:`h-6 w-6 inline-flex items-center justify-center rounded-md hover:bg-muted text-muted-foreground hover:text-destructive`,onClick:x,disabled:!a,title:`Delete ${b.length} empty session${b.length===1?``:`s`}`,children:(0,X.jsx)(at,{className:`h-3.5 w-3.5`})}),(0,X.jsx)(`button`,{type:`button`,className:`h-6 w-6 inline-flex items-center justify-center rounded-md hover:bg-muted`,onClick:()=>o(50),disabled:!a,title:`Refresh`,children:r?(0,X.jsx)(L,{className:`h-3.5 w-3.5 animate-spin`}):(0,X.jsx)(Mt,{className:`h-3.5 w-3.5`})})]})]}),n.length>3&&(0,X.jsx)(`div`,{className:`px-3 py-2 border-b`,children:(0,X.jsxs)(`div`,{className:`relative`,children:[(0,X.jsx)(wn,{className:`absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground/60`}),(0,X.jsx)(`input`,{type:`text`,value:e,onChange:e=>t(e.target.value),placeholder:`Filter title, model, provider…`,className:`w-full pl-7 pr-7 py-1 text-xs rounded-md bg-muted/40 border border-transparent focus:bg-background focus:border-input focus:outline-none focus:ring-1 focus:ring-ring placeholder:text-muted-foreground/50`}),e&&(0,X.jsx)(`button`,{type:`button`,onClick:()=>t(``),className:`absolute right-1 top-1/2 -translate-y-1/2 text-muted-foreground/60 hover:text-foreground p-0.5`,title:`Clear filter`,children:(0,X.jsx)(Ie,{className:`h-3 w-3`})})]})}),i&&(0,X.jsx)(`div`,{className:`px-4 py-2 text-xs text-destructive bg-destructive/5 border-b`,children:i}),(0,X.jsx)(ls,{className:`flex-1`,children:n.length===0&&!r?(0,X.jsxs)(`div`,{className:`text-center text-muted-foreground py-8 px-4`,children:[(0,X.jsx)(Pt,{className:`h-8 w-8 mx-auto mb-3 opacity-20`}),(0,X.jsx)(`p`,{className:`text-sm font-medium`,children:`No history yet`}),(0,X.jsx)(`p`,{className:`text-xs mt-1`,children:`Your conversations will appear here`})]}):S.length===0?(0,X.jsxs)(`div`,{className:`text-center text-muted-foreground py-8 px-4`,children:[(0,X.jsx)(wn,{className:`h-8 w-8 mx-auto mb-3 opacity-20`}),(0,X.jsx)(`p`,{className:`text-sm font-medium`,children:`No matches`}),(0,X.jsx)(`p`,{className:`text-xs mt-1`,children:`Try a different filter`})]}):(0,X.jsx)(`div`,{className:`p-2 space-y-3`,children:S.map(e=>(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsxs)(`div`,{className:Y(`sticky top-0 z-[1] px-1 pb-1 text-[10px] uppercase tracking-wider font-semibold bg-card/90 backdrop-blur-sm flex items-center gap-1`,e.star?`text-amber-500`:`text-muted-foreground/80`),children:[e.star&&(0,X.jsx)(Bt,{className:`h-3 w-3 fill-current`}),e.label,` `,(0,X.jsxs)(`span`,{className:`text-muted-foreground/50 font-normal normal-case ml-1`,children:[`(`,e.rows.length,`)`]})]}),e.rows.map(e=>(0,X.jsxs)(`div`,{className:Y(`group relative rounded-md border text-sm transition-colors`,e.isCurrent?`bg-primary/5 border-primary/40`:`bg-card border-border/60 hover:bg-muted/40 hover:border-primary/40`),children:[(0,X.jsx)(`button`,{type:`button`,disabled:e.isCurrent||p===e.id||_!==null,onClick:()=>y(e.id),onDoubleClick:t=>{t.stopPropagation(),m(e.id),g(d[e.id]??e.title??``)},className:`block w-full rounded-md px-3 py-2 pr-16 text-left disabled:cursor-default focus:outline-none focus-visible:ring-2 focus-visible:ring-ring`,children:(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[p===e.id?(0,X.jsx)(`input`,{value:h,onChange:e=>g(e.target.value),onClick:e=>e.stopPropagation(),onBlur:()=>{f(e.id,h),m(null)},onKeyDown:t=>{t.key===`Enter`?(t.preventDefault(),f(e.id,h),m(null)):t.key===`Escape`&&(t.preventDefault(),m(null))},placeholder:e.title||`Nickname`,className:`w-full text-sm bg-background border border-input rounded px-1.5 py-0.5 focus:outline-none focus:ring-1 focus:ring-ring`}):(0,X.jsx)(`div`,{className:`font-medium truncate text-foreground`,title:d[e.id]?`${d[e.id]} — original: ${e.title}`:`${e.title}\n\nDouble-click to rename`,children:d[e.id]||e.title||`(empty)`}),(0,X.jsxs)(`div`,{className:`text-[10px] text-muted-foreground font-mono truncate mt-0.5`,children:[e.provider,`/`,e.model]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] text-muted-foreground/80 mt-0.5`,children:[_===e.id?(0,X.jsxs)(`span`,{className:`flex items-center gap-1 text-primary font-medium`,children:[(0,X.jsx)(L,{className:`h-3 w-3 animate-spin`}),`resuming…`]}):(0,X.jsx)(`span`,{children:bc(e.startedAt)}),e.tokenTotal>0&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`opacity-50`,children:`·`}),(0,X.jsxs)(`span`,{className:`tabular-nums`,children:[e.tokenTotal.toLocaleString(),` tok`]})]}),e.isCurrent&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`opacity-50`,children:`·`}),(0,X.jsx)(`span`,{className:`text-primary font-medium`,children:`active`})]})]})]})}),(0,X.jsxs)(`div`,{className:`absolute right-2 top-2 flex items-center gap-1`,children:[(0,X.jsx)(`button`,{type:`button`,onClick:()=>u(e.id),className:Y(`transition-opacity hover:text-amber-500`,l.includes(e.id)?`opacity-100 text-amber-500`:`opacity-0 group-hover:opacity-100 text-muted-foreground`),title:l.includes(e.id)?`Unfavorite`:`Mark as favorite`,children:(0,X.jsx)(Bt,{className:Y(`h-3.5 w-3.5`,l.includes(e.id)&&`fill-current`)})}),!e.isCurrent&&(0,X.jsx)(`button`,{type:`button`,onClick:async()=>{await ns({title:`Delete session?`,message:`"${d[e.id]||e.title||`(empty)`}" will be removed from disk. This cannot be undone.`,confirmLabel:`Delete`,danger:!0})&&c(e.id)},className:`opacity-0 group-hover:opacity-100 transition-opacity text-muted-foreground hover:text-destructive`,title:`Delete session`,children:(0,X.jsx)(at,{className:`h-3.5 w-3.5`})})]})]},e.id))]},e.label))})})]})}function Cc(){let e=U(e=>e.wsConnected),{entries:t,loading:n,error:r}=nr(),{listSessions:i,resumeSession:a,deleteSession:o}=Z(),s=G(e=>e.setCurrentView),c=W(e=>e.session?.id),[l,u]=(0,B.useState)(``);return(0,B.useEffect)(()=>{e&&i(50)},[e,c,i]),(0,X.jsxs)(`div`,{className:`flex-1 flex flex-col overflow-hidden`,children:[(0,X.jsx)(Sc,{historyQuery:l,setHistoryQuery:u,historyEntries:t,historyLoading:n,historyError:r,wsConnected:e,listSessions:i,resumeSession:a,deleteSession:o}),(0,X.jsx)(`div`,{className:`border-t px-3 py-2 shrink-0`,children:(0,X.jsxs)(`button`,{type:`button`,onClick:()=>s(`sessions`),className:`w-full flex items-center justify-center gap-1.5 h-7 rounded-md border border-border text-[11px] text-muted-foreground hover:text-foreground hover:bg-accent transition-colors`,children:[(0,X.jsx)(rn,{className:`h-3 w-3`}),`Open sessions dashboard`]})})]})}function wc(e){return e<=0?`$0.000`:e>=.01?`$${e.toFixed(3)}`:`$${e.toFixed(4)}`}function Tc(e){if(e<=0)return`--`;let t=Math.floor(e/1e3);if(t<60)return`${t}s`;let n=Math.floor(t/60);return n<60?`${n}m ${t%60}s`:`${Math.floor(n/60)}h ${n%60}m`}function Ec({icon:e,label:t,onClick:n,disabled:r,tone:i,title:a}){return(0,X.jsxs)(`button`,{type:`button`,onClick:n,disabled:r,title:a??t,className:Y(`flex items-center justify-center gap-1.5 h-8 rounded-md border text-[11px] font-medium transition-colors`,`disabled:opacity-40 disabled:cursor-not-allowed`,i===`primary`?`border-primary/40 bg-primary/10 text-primary hover:bg-primary/20`:i===`danger`?`border-destructive/40 bg-destructive/10 text-destructive hover:bg-destructive/20`:`border-border bg-card hover:bg-accent text-foreground/80`),children:[e,t]})}function Dc({label:e,value:t,sub:n}){return(0,X.jsxs)(`div`,{className:`flex flex-col p-2 rounded-lg bg-muted/40 border border-border/40 min-w-0`,children:[(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:e}),(0,X.jsx)(`span`,{className:`text-sm font-semibold tabular-nums truncate`,children:t}),n&&(0,X.jsx)(`span`,{className:`text-[9px] text-muted-foreground/70 truncate`,children:n})]})}function Oc({icon:e,label:t,right:n}){return(0,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[10px] uppercase tracking-wider text-muted-foreground font-semibold`,children:[e,t]}),n]})}function kc({label:e,value:t,onChange:n,title:r}){return(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-2 py-1`,title:r,children:[(0,X.jsx)(`span`,{className:`text-xs text-foreground/80`,children:e}),(0,X.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":t,onClick:n,className:Y(`shrink-0 relative inline-flex h-4 w-7 rounded-full border transition-colors`,t?`bg-primary border-primary`:`bg-muted border-input hover:bg-muted/80`),children:(0,X.jsx)(`span`,{className:Y(`absolute top-0.5 left-0.5 h-2.5 w-2.5 rounded-full bg-background shadow transition-transform`,t&&`translate-x-3`)})})]})}function Ac(){let{client:e,updatePrefs:n,switchAutonomy:r}=Z(),i=U(e=>e.wsConnected),a=U(e=>e.wsUrl),o=U(e=>e.provider),s=U(e=>e.model),l=U(e=>e.soundOnComplete),u=W(e=>e.session),d=W(e=>e.totalTokens),f=W(e=>e.cost),p=W(e=>e.iteration),m=W(e=>e.todos),h=W(e=>e.lastInputTokens),g=W(e=>e.maxContext),_=H(e=>e.messages),v=H(e=>e.isLoading),y=K(e=>e.agents),x=G(e=>e.pinnedIds),S=G(e=>e.unpinAll),w=G(e=>e.setModelSwitcherOpen),T=hr(),E=(0,B.useCallback)((e,t)=>{T.set({[e]:t}),n({[e]:t})},[T,n]),[D,O]=(0,B.useState)(!1),k=u?.startedAt??null,[A,j]=(0,B.useState)(()=>Date.now());(0,B.useEffect)(()=>{if(!k)return;let e=setInterval(()=>j(Date.now()),1e3);return()=>clearInterval(e)},[k]);let M=(0,B.useMemo)(()=>Array.from(y.values()).filter(e=>e.status===`running`).length,[y]),te=g>0&&h>0?Math.round(h/g*100):0,N=x.map(e=>_.find(t=>t.id===e)).filter(e=>!!e&&e.content.length>0),ne=e=>V(a)?.send?.(e);return(0,X.jsxs)(`div`,{className:`flex-1 overflow-y-auto`,children:[(0,X.jsxs)(`div`,{className:`px-3 py-2.5 border-b grid grid-cols-2 gap-1.5`,children:[v?(0,X.jsx)(Ec,{icon:(0,X.jsx)(Ct,{className:`h-3 w-3`}),label:`Abort`,tone:`danger`,onClick:()=>ne({type:`abort`,payload:{}}),disabled:!i}):(0,X.jsx)(Ec,{icon:(0,X.jsx)(kt,{className:`h-3 w-3`}),label:`New session`,tone:`primary`,onClick:()=>{e?.newSession?.(),G.getState().setCurrentView(`chat`)},disabled:!i,title:`Start a new session (Ctrl+N)`}),(0,X.jsx)(Ec,{icon:(0,X.jsx)(b,{className:`h-3 w-3`}),label:`Export`,onClick:()=>xa(),title:`Export chat as markdown (Ctrl+E)`}),(0,X.jsx)(Ec,{icon:(0,X.jsx)(An,{className:`h-3 w-3`}),label:`Compact`,onClick:()=>ne({type:`context.compact`,payload:{aggressive:!1}}),disabled:!i,title:`Compact the context window`}),(0,X.jsx)(Ec,{icon:(0,X.jsx)(me,{className:`h-3 w-3`}),label:`Clear`,onClick:()=>ne({type:`context.clear`}),disabled:!i,title:`Clear context (Ctrl+L)`})]}),(0,X.jsxs)(`button`,{type:`button`,onClick:()=>w(!0),className:`w-full px-4 py-2.5 border-b text-left hover:bg-muted/40 transition-colors`,title:`Change model (Ctrl+M)`,children:[(0,X.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground mb-0.5`,children:`Model`}),(0,X.jsxs)(`div`,{className:`font-mono text-xs truncate`,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:o||`—`}),(0,X.jsx)(`span`,{className:`text-muted-foreground/40 mx-1`,children:`/`}),(0,X.jsx)(`span`,{className:`font-medium`,children:s||`—`})]})]}),g>0&&(0,X.jsxs)(`div`,{className:`px-4 py-2.5 border-b space-y-1.5`,children:[(0,X.jsx)(`button`,{type:`button`,onClick:()=>O(!0),className:`w-full block text-left`,title:`Click for a context breakdown`,children:(0,X.jsx)(Oc,{icon:null,label:`Context`,right:(0,X.jsxs)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums font-mono`,children:[Q(h),`/`,Q(g),` · `,te,`%`]})})}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>O(!0),className:`w-full block`,title:`Click for a context breakdown`,children:(0,X.jsx)(Bi,{pct:te,tokens:h,maxTokens:g,showTokens:!0})})]}),(0,X.jsxs)(`div`,{className:`px-3 py-2.5 border-b space-y-1.5`,children:[(0,X.jsx)(Oc,{icon:(0,X.jsx)(c,{className:`h-3 w-3`}),label:`Session`}),(0,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-1.5`,children:[(0,X.jsx)(Dc,{label:`Messages`,value:_.length}),(0,X.jsx)(Dc,{label:`Elapsed`,value:k?Tc(A-k):`--`}),(0,X.jsx)(Dc,{label:`Tokens`,value:Q(d.input+d.output),sub:`${Q(d.input)} in / ${Q(d.output)} out`}),(0,X.jsx)(Dc,{label:`Cost`,value:wc(f)}),p&&(0,X.jsx)(Dc,{label:`Iteration`,value:p.index,sub:p.max?`of ${p.max}`:void 0}),y.size>0&&(0,X.jsx)(Dc,{label:`Agents`,value:y.size,sub:M>0?`${M} running`:void 0})]})]}),m.length>0&&(()=>{let e=m.filter(e=>e.status===`completed`).length,t=m.filter(e=>e.status===`in_progress`).length,n=Math.round(e/m.length*100),r=e===m.length;return(0,X.jsxs)(`div`,{className:`px-3 py-2.5 border-b space-y-1.5`,children:[(0,X.jsx)(Oc,{icon:(0,X.jsx)(fn,{className:`h-3 w-3`}),label:`Plan`,right:(0,X.jsxs)(`span`,{className:`tabular-nums text-[10px] text-muted-foreground`,children:[e,`/`,m.length]})}),(0,X.jsx)(`div`,{className:Y(`relative h-1.5 w-full overflow-hidden rounded-full bg-muted`,t>0&&`bar-sweep`),title:`${n}% complete`,children:(0,X.jsx)(`div`,{className:Y(`h-full rounded-full transition-all duration-500`,r?`bg-[hsl(var(--success))]`:`bg-primary`),style:{width:`${Math.max(n,t>0?4:0)}%`}})}),(0,X.jsx)(`ul`,{className:`space-y-0.5 max-h-56 overflow-y-auto pr-1 -mx-1`,children:m.map(e=>{let t=e.status===`completed`?Be:e.status===`in_progress`?ee:C,n=e.status===`in_progress`,r=e.status===`completed`?`text-[hsl(var(--success))] line-through opacity-60`:n?`text-foreground`:`text-muted-foreground`;return(0,X.jsxs)(`li`,{className:Y(`flex items-start gap-2 text-xs leading-snug rounded-md px-1.5 py-1 transition-colors`,n&&`bg-primary/10 ring-1 ring-inset ring-primary/20`,r),children:[(0,X.jsx)(t,{className:Y(`h-3.5 w-3.5 mt-0.5 shrink-0`,n&&`text-primary animate-pulse`)}),(0,X.jsx)(`span`,{className:`break-words`,children:n&&e.activeForm?e.activeForm:e.content})]},e.id)})})]})})(),N.length>0&&(0,X.jsxs)(`div`,{className:`px-3 py-2.5 border-b space-y-1.5`,children:[(0,X.jsx)(Oc,{icon:(0,X.jsx)(P,{className:`h-3 w-3 text-amber-500`}),label:`Pinned`,right:(0,X.jsx)(`button`,{type:`button`,onClick:S,className:`text-[10px] text-muted-foreground hover:text-destructive`,children:`Clear`})}),(0,X.jsx)(`ul`,{className:`space-y-1 max-h-48 overflow-y-auto pr-1`,children:N.map(e=>{let t=e.content.replace(/\s+/g,` `).slice(0,80);return(0,X.jsx)(`li`,{children:(0,X.jsxs)(`button`,{type:`button`,onClick:()=>{let t=document.querySelector(`[data-message-id="${e.id}"]`);t&&(t.scrollIntoView({behavior:`smooth`,block:`center`}),t.classList.add(`ring-2`,`ring-amber-500/60`),setTimeout(()=>{t.classList.remove(`ring-2`,`ring-amber-500/60`)},1600))},className:`w-full text-left text-xs px-2 py-1.5 rounded bg-muted/40 hover:bg-muted/70 border border-amber-500/20 leading-snug`,title:e.content.slice(0,400),children:[t,e.content.length>80?`…`:``]})},e.id)})})]}),(0,X.jsxs)(`div`,{className:`px-3 py-2.5 border-b space-y-1`,children:[(0,X.jsx)(Oc,{icon:(0,X.jsx)(Je,{className:`h-3 w-3`}),label:`Quick settings`}),(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-2 py-1`,children:[(0,X.jsx)(`span`,{className:`text-xs text-foreground/80`,children:`Autonomy`}),(0,X.jsxs)(`select`,{value:T.autonomy,onChange:e=>{let t=e.target.value;T.set({autonomy:t}),r(t)},className:`shrink-0 h-6 max-w-[150px] rounded-md border bg-background px-1.5 text-[11px]`,children:[(0,X.jsx)(`option`,{value:`off`,children:`Off`}),(0,X.jsx)(`option`,{value:`suggest`,children:`Suggest`}),(0,X.jsx)(`option`,{value:`auto`,children:`Auto`}),(0,X.jsx)(`option`,{value:`eternal`,children:`Eternal`}),(0,X.jsx)(`option`,{value:`eternal-parallel`,children:`Eternal Parallel`})]})]}),(0,X.jsx)(kc,{label:`YOLO mode`,title:`Bypass tool confirmation prompts`,value:T.yolo,onChange:()=>E(`yolo`,!T.yolo)}),(0,X.jsx)(kc,{label:`Refine prompts`,title:`Rewrite prompts before sending`,value:T.enhanceEnabled,onChange:()=>E(`enhanceEnabled`,!T.enhanceEnabled)}),(0,X.jsx)(kc,{label:`Sound on completion`,title:`Play a soft chime when a run finishes`,value:l,onChange:()=>{let e=!U.getState().soundOnComplete;U.getState().setSoundOnComplete(e),e&&kr()}})]}),(0,X.jsxs)(`div`,{className:`px-4 py-2.5`,children:[(0,X.jsxs)(`div`,{className:Y(`flex items-center gap-2 text-[11px]`,i?`text-[hsl(var(--success))]`:`text-[hsl(var(--warning))]`),children:[i?(0,X.jsx)(ge,{className:`h-3.5 w-3.5`}):(0,X.jsx)(t,{className:`h-3.5 w-3.5`}),(0,X.jsx)(`span`,{className:`font-medium`,children:i?`Connected`:`Disconnected`}),(0,X.jsx)(`span`,{className:`text-muted-foreground font-mono truncate ml-auto`,title:a,children:a})]}),u&&(0,X.jsxs)(`div`,{className:`text-[10px] text-muted-foreground font-mono mt-1 truncate`,title:u.id,children:[`session `,u.id.slice(0,8)]})]}),(0,X.jsx)(Vi,{open:D,onClose:()=>O(!1)})]})}var jc={chat:`Session`,agents:`Agents`,history:`History`,files:`Files`,projects:`Projects`,mailbox:`Mailbox`};function Mc(){let e=G(e=>e.activeActivity),t=G(e=>e.setSidebarOpen),n=G(e=>e.sidebarWidth),r=G(e=>e.setSidebarWidth),i=U(e=>e.wsConnected),{client:a}=Z();return(0,B.useEffect)(()=>{if(e!==`files`||!i)return;q.getState().setTreeLoading(!0);let t=W.getState().cwd;a?.send({type:`files.tree`,payload:t?{path:t}:{}})},[e,i,a]),(0,X.jsxs)(`aside`,{style:{width:`${n}px`},className:`relative border-r bg-card flex flex-col shrink-0 overflow-hidden animate-slide-in`,children:[(0,X.jsx)(`div`,{onMouseDown:e=>{e.preventDefault();let t=e.clientX,i=n,a=e=>r(i+(e.clientX-t)),o=()=>{window.removeEventListener(`mousemove`,a),window.removeEventListener(`mouseup`,o),document.body.style.cursor=``,document.body.style.userSelect=``};window.addEventListener(`mousemove`,a),window.addEventListener(`mouseup`,o),document.body.style.cursor=`col-resize`,document.body.style.userSelect=`none`},onDoubleClick:()=>r(304),className:`group/handle absolute top-0 right-0 h-full w-2 cursor-col-resize z-10 flex items-center justify-end`,title:`Drag to resize · double-click to reset`,children:(0,X.jsx)(`div`,{className:`h-full w-px bg-border group-hover/handle:bg-primary/60 group-hover/handle:w-0.5 transition-all`})}),(0,X.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2.5 border-b shrink-0`,children:[(0,X.jsx)(`span`,{className:`text-xs font-semibold tracking-tight text-muted-foreground uppercase`,children:jc[e]}),(0,X.jsx)($,{variant:`ghost`,size:`icon`,className:`h-6 w-6`,onClick:()=>t(!1),title:`Collapse panel (Ctrl+\\)`,children:(0,X.jsx)(Nn,{className:`h-3.5 w-3.5`})})]}),(0,X.jsxs)(`div`,{className:`flex-1 flex flex-col overflow-hidden`,children:[e===`chat`&&(0,X.jsx)(Ac,{}),e===`agents`&&(0,X.jsx)(yc,{}),e===`history`&&(0,X.jsx)(Cc,{}),e===`files`&&(0,X.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:(0,X.jsx)(ec,{})}),e===`projects`&&(0,X.jsx)(`div`,{className:`flex-1 overflow-y-auto p-3`,children:(0,X.jsx)(ic,{})}),e===`mailbox`&&(0,X.jsx)(`div`,{className:`flex-1 overflow-y-auto p-3`,children:(0,X.jsx)(rc,{})})]})]})}function Nc({sessionId:e,className:t}){let[n,i]=(0,B.useState)([]),[a,o]=(0,B.useState)(!1),[s,c]=(0,B.useState)(null),[l,u]=(0,B.useState)(null),[d,f]=(0,B.useState)(0),[p,m]=(0,B.useState)(!1),h=V(U(e=>e.wsUrl));(0,B.useEffect)(()=>{let t=[];return t.push(h.on(`collab.state`,t=>{let n=t.payload;n.sessionId===e&&i(n.participants??[])})),t.push(h.on(`collab.participant.joined`,t=>{let n=t.payload;n.sessionId===e&&i(e=>e.some(e=>e.participantId===n.participantId)?e:[...e,{participantId:n.participantId,role:n.role,joinedAt:n.joinedAt}])})),t.push(h.on(`collab.participant.left`,t=>{let n=t.payload;if(n.sessionId!==e)return;let r=n.participantId;i(e=>e.filter(e=>e.participantId!==r))})),t.push(h.on(`error`,e=>{let t=e.payload;t.phase===`collab`&&(u(t.message),o(!1))})),t.push(h.on(`collab.annotation.added`,t=>{let n=t.payload;n.sessionId===e&&(n.annotation?.resolved||f(e=>e+1))})),t.push(h.on(`collab.annotation.resolved`,t=>{t.payload.sessionId===e&&f(e=>Math.max(0,e-1))})),t.push(h.on(`collab.pause.granted`,t=>{t.payload.sessionId===e&&m(!0)})),t.push(h.on(`collab.pause.released`,t=>{t.payload.sessionId===e&&m(!1)})),()=>{for(let e of t)e()}},[h,e]);let g=(t=`observer`)=>{u(null),h.send({type:`collab.join`,payload:{sessionId:e,role:t}}),o(!0),c(t)};return n.length===0&&!l?(0,X.jsxs)(`div`,{className:Y(`flex items-center gap-2 px-3 py-2 rounded-md border border-dashed border-border bg-card/40`,t),children:[(0,X.jsx)(Wt,{className:`w-4 h-4 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`No live observers`}),(0,X.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[(0,X.jsxs)(`button`,{type:`button`,onClick:()=>g(`observer`),className:`inline-flex items-center gap-1 text-xs px-2 py-1 rounded bg-primary text-primary-foreground hover:bg-primary/90 transition-colors`,title:`Join as a read-only observer (Phase 1)`,children:[(0,X.jsx)(r,{className:`w-3 h-3`}),`observer`]}),(0,X.jsxs)(`button`,{type:`button`,onClick:()=>g(`annotator`),className:`inline-flex items-center gap-1 text-xs px-2 py-1 rounded border border-amber-500/40 bg-amber-500/10 text-amber-700 dark:text-amber-300 hover:bg-amber-500/20 transition-colors`,title:`Join as an annotator — leave inline notes on tool calls (Phase 2)`,children:[(0,X.jsx)(M,{className:`w-3 h-3`}),`annotator`]}),(0,X.jsxs)(`button`,{type:`button`,onClick:()=>g(`controller`),className:`inline-flex items-center gap-1 text-xs px-2 py-1 rounded border border-rose-500/40 bg-rose-500/10 text-rose-700 dark:text-rose-300 hover:bg-rose-500/20 transition-colors`,title:`Join as a controller — can pause the agent loop (Phase 3)`,children:[(0,X.jsx)(ae,{className:`w-3 h-3`}),`controller`]})]})]}):l?(0,X.jsxs)(`div`,{className:Y(`flex items-center gap-2 px-3 py-2 rounded-md border border-destructive/50 bg-destructive/10`,t),role:`alert`,children:[(0,X.jsxs)(`span`,{className:`text-xs text-destructive`,children:[`Collab: `,l]}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>{u(null),o(!1)},className:`ml-auto text-xs underline text-destructive`,children:`dismiss`})]}):(0,X.jsxs)(`div`,{className:Y(`flex items-center gap-2 px-3 py-2 rounded-md border border-emerald-500/40 bg-emerald-500/5`,t),children:[(0,X.jsxs)(`span`,{className:`relative flex h-2 w-2`,"aria-label":`Live`,children:[(0,X.jsx)(`span`,{className:`absolute inline-flex h-full w-full rounded-full bg-emerald-400 opacity-75 animate-ping`}),(0,X.jsx)(`span`,{className:`relative inline-flex rounded-full h-2 w-2 bg-emerald-500`})]}),(0,X.jsx)(Wt,{className:`w-4 h-4 text-emerald-700 dark:text-emerald-400`}),(0,X.jsxs)(`span`,{className:`text-xs font-medium text-emerald-700 dark:text-emerald-300`,children:[n.length,` `,n.length===1?`observer`:`observers`]}),d>0&&(0,X.jsxs)(`span`,{title:`${d} open annotation(s) — annotators reviewing this session`,className:`ml-2 inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded bg-amber-500/15 text-amber-700 dark:text-amber-300 border border-amber-500/30`,children:[(0,X.jsx)(M,{className:`w-3 h-3`}),d,` note`,d===1?``:`s`]}),p&&(0,X.jsxs)(`span`,{title:`Agent loop is paused — a controller is reviewing`,className:`ml-2 inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded bg-rose-500/15 text-rose-700 dark:text-rose-300 border border-rose-500/40`,children:[(0,X.jsx)(ae,{className:`w-3 h-3`}),`paused`]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1 ml-2`,children:[n.slice(0,3).map(e=>(0,X.jsxs)(`span`,{title:`Joined ${new Date(e.joinedAt).toLocaleTimeString()}`,className:`inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded bg-emerald-500/10 text-emerald-700 dark:text-emerald-300`,children:[(0,X.jsx)(Ot,{className:`w-3 h-3`}),e.role]},e.participantId)),n.length>3&&(0,X.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[`+`,n.length-3]})]}),a&&s===`controller`&&(p?(0,X.jsxs)(`button`,{type:`button`,onClick:()=>{h.send({type:`collab.resume`,payload:{sessionId:e}})},className:`ml-auto inline-flex items-center gap-1 text-xs px-2 py-1 rounded border border-rose-500/40 bg-rose-500/10 text-rose-700 dark:text-rose-300 hover:bg-rose-500/20 transition-colors`,title:`Resume the agent loop`,children:[(0,X.jsx)(ce,{className:`w-3 h-3`}),`Resume`]}):(0,X.jsxs)(`button`,{type:`button`,onClick:()=>{h.send({type:`collab.request_pause`,payload:{sessionId:e}})},className:`ml-auto inline-flex items-center gap-1 text-xs px-2 py-1 rounded border border-amber-500/40 bg-amber-500/10 text-amber-700 dark:text-amber-300 hover:bg-amber-500/20 transition-colors`,title:`Pause the agent before the next tool call`,children:[(0,X.jsx)(ae,{className:`w-3 h-3`}),`Pause agent`]})),a&&s!==`controller`&&(0,X.jsxs)(`button`,{type:`button`,onClick:()=>{h.send({type:`collab.leave`,payload:{sessionId:e}}),o(!1),i([])},className:`ml-auto inline-flex items-center gap-1 text-xs px-2 py-1 rounded border border-border hover:bg-muted transition-colors`,title:`Leave the observer session`,children:[(0,X.jsx)(ve,{className:`w-3 h-3`}),`Leave`]})]})}var Pc={up:(0,X.jsx)(Jt,{className:`h-3.5 w-3.5 text-emerald-500`}),down:(0,X.jsx)(un,{className:`h-3.5 w-3.5 text-red-500`}),stable:(0,X.jsx)(w,{className:`h-3.5 w-3.5 text-amber-500`})},Fc={active:{color:`text-emerald-600 dark:text-emerald-400`,bg:`bg-emerald-100 dark:bg-emerald-900/40`,label:`Active`},paused:{color:`text-amber-600 dark:text-amber-400`,bg:`bg-amber-100 dark:bg-amber-900/40`,label:`Paused`},completed:{color:`text-blue-600 dark:text-blue-400`,bg:`bg-blue-100 dark:bg-blue-900/40`,label:`Done`},failed:{color:`text-red-600 dark:text-red-400`,bg:`bg-red-100 dark:bg-red-900/40`,label:`Failed`},abandoned:{color:`text-stone-600 dark:text-stone-400`,bg:`bg-stone-100 dark:bg-stone-900/40`,label:`Abandoned`}};function Ic({goal:e,className:t}){let[r,i]=(0,B.useState)(!1);if((0,B.useEffect)(()=>{let e=V();e?.send?.({type:`goal.get`});let t=setInterval(()=>{e?.send?.({type:`goal.get`})},1e4);return()=>clearInterval(t)},[]),(0,B.useEffect)(()=>{(!e||e.goalState===`completed`||e.goalState===`failed`||e.goalState===`abandoned`)&&i(!0)},[e]),!e||e.goalState===`completed`||e.goalState===`failed`||e.goalState===`abandoned`)return null;let a=Fc[e.goalState],o=e.deliverables?.filter(e=>e.status===`done`).length??0,s=e.deliverables?.length??0,c=e.journal?.slice(-5).reverse()??[],l=e.progressTrend?Pc[e.progressTrend]:null;return(0,X.jsxs)(`div`,{className:Y(`rounded-lg border border-border bg-card/60 backdrop-blur-sm`,t),children:[(0,X.jsxs)(`button`,{type:`button`,onClick:()=>i(e=>!e),className:`flex w-full items-center gap-2 px-3 py-2.5 text-left hover:bg-accent/40 rounded-t-lg transition-colors`,children:[(0,X.jsx)(lt,{className:`h-4 w-4 text-rose-500`}),(0,X.jsx)(`span`,{className:`text-xs font-semibold text-foreground flex-1 min-w-0 truncate`,children:`Goal`}),(0,X.jsx)(`span`,{className:Y(`inline-flex items-center px-1.5 py-0.5 rounded-full text-[10px] font-medium shrink-0`,a.bg,a.color),children:a.label}),r?(0,X.jsx)(n,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}):(0,X.jsx)(ut,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`})]}),!r&&(0,X.jsxs)(`div`,{className:`px-3 pb-3 space-y-3 border-t pt-2`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`p`,{className:`text-xs text-foreground leading-relaxed whitespace-pre-wrap break-words`,children:e.goal}),e.refinedGoal&&e.refinedGoal!==e.goal&&(0,X.jsxs)(`div`,{className:`mt-1.5 p-2 rounded bg-accent/40 border border-border/50`,children:[(0,X.jsx)(`p`,{className:`text-[10px] text-muted-foreground mb-0.5 uppercase tracking-wider font-medium`,children:`Refined`}),(0,X.jsx)(`p`,{className:`text-xs leading-relaxed whitespace-pre-wrap break-words`,children:e.refinedGoal})]})]}),(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between text-[10px]`,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground uppercase tracking-wider font-medium`,children:`Progress`}),(0,X.jsxs)(`span`,{className:`flex items-center gap-1 tabular-nums`,children:[l,(0,X.jsxs)(`span`,{className:`font-medium text-foreground`,children:[e.progress,`%`]})]})]}),(0,X.jsx)(`div`,{className:`h-1.5 bg-muted rounded-full overflow-hidden`,children:(0,X.jsx)(`div`,{className:Y(`h-full transition-all duration-700 rounded-full`,e.progress>=80?`bg-emerald-500`:e.progress>=50?`bg-amber-500`:`bg-primary`),style:{width:`${e.progress>0?Math.max(2,e.progress):0}%`}})}),e.progressNote&&(0,X.jsx)(`p`,{className:`text-[10px] text-muted-foreground italic`,children:e.progressNote})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] text-muted-foreground`,children:[(0,X.jsx)(Pe,{className:`h-3 w-3`}),(0,X.jsx)(`span`,{className:`tabular-nums font-medium`,children:e.iterations}),(0,X.jsx)(`span`,{children:`iterations`}),e.lastStatus&&(0,X.jsx)(`span`,{className:`text-border`,children:`·`}),e.lastStatus&&(0,X.jsx)(`span`,{className:`truncate`,children:e.lastStatus})]}),s>0&&(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between text-[10px] text-muted-foreground uppercase tracking-wider font-medium`,children:[(0,X.jsx)(`span`,{children:`Deliverables`}),(0,X.jsxs)(`span`,{className:`tabular-nums`,children:[o,`/`,s]})]}),(0,X.jsx)(`ul`,{className:`space-y-0.5`,children:e.deliverables?.map(e=>(0,X.jsxs)(`li`,{className:`flex items-start gap-1.5 text-[11px]`,children:[e.status===`done`?(0,X.jsx)(Be,{className:`h-3 w-3 text-emerald-500 mt-0.5 shrink-0`}):(0,X.jsx)(C,{className:`h-3 w-3 text-muted-foreground/50 mt-0.5 shrink-0`}),(0,X.jsx)(`span`,{className:Y(`leading-snug`,e.status===`done`?`text-muted-foreground line-through`:`text-foreground`),children:e.text})]},e.id))})]}),c.length>0&&(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(`p`,{className:`text-[10px] text-muted-foreground uppercase tracking-wider font-medium`,children:`Recent Activity`}),(0,X.jsx)(`div`,{className:`space-y-1`,children:c.map((e,t)=>(0,X.jsxs)(`div`,{className:`flex items-start gap-1.5 text-[10px] text-muted-foreground`,children:[(0,X.jsxs)(`span`,{className:`font-mono tabular-nums shrink-0 text-foreground/60`,children:[`#`,e.iteration]}),(0,X.jsx)(`span`,{className:`truncate`,children:e.task||e.status||e.progressNote||`…`})]},`${e.iteration}-${t}`))})]})]})]})}var Lc={in_progress:0,pending:1,completed:2};function Rc(){let[e,t]=(0,B.useState)([]),[n,r]=(0,B.useState)(new Set),i=V(),a=(0,B.useRef)(null);(0,B.useEffect)(()=>(i.send({type:`todos.get`}),a.current=i.on(`todos.updated`,e=>{let n=e?.payload;n?.todos&&t(n.todos)}),()=>{a.current?.()}),[i]);let o=(0,B.useCallback)(e=>{i.removeTodo(e)},[i]),s=(0,B.useCallback)(e=>{if(e.status===`in_progress`)return;let t=e.status===`completed`?`pending`:`completed`;i.updateTodoStatus(e.id,t)},[i]),c=[...e].sort((e,t)=>(Lc[e.status]??9)-(Lc[t.status]??9)),l=c.filter(e=>e.status===`in_progress`),u=c.filter(e=>e.status===`pending`),d=c.filter(e=>e.status===`completed`),f=d.length>0,p=n.has(`completed`),m=e=>{r(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},h=e=>{let t=e.status===`in_progress`&&e.activeForm?e.activeForm:e.content,n=e.status===`in_progress`,r=e.status===`completed`,i=!n;return(0,X.jsxs)(`div`,{onClick:()=>i&&s(e),className:Y(`px-3 py-1.5 flex items-start gap-2 text-[13px] group transition-colors`,i&&`cursor-pointer hover:bg-accent/40`,n?`bg-yellow-50/40 dark:bg-yellow-950/25`:r?`bg-emerald-50/20 dark:bg-emerald-950/10`:`bg-background`),role:i?`button`:void 0,"aria-label":i?`Toggle ${e.content}`:void 0,tabIndex:i?0:void 0,onKeyDown:t=>{i&&(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),s(e))},children:[(0,X.jsx)(`span`,{className:`mt-0.5 shrink-0`,children:r?(0,X.jsx)(Be,{className:`w-3.5 h-3.5 text-emerald-500`}):n?(0,X.jsx)(Pe,{className:`w-3.5 h-3.5 text-yellow-500 animate-spin`}):(0,X.jsx)(C,{className:Y(`w-3.5 h-3.5 transition-colors`,`text-muted-foreground/40 group-hover:text-emerald-400`)})}),(0,X.jsx)(`span`,{className:Y(`leading-snug flex-1 min-w-0`,n?`text-yellow-800 dark:text-yellow-200 font-medium`:r?`text-muted-foreground line-through`:`text-foreground/80`),children:t}),(0,X.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),o(e.id)},className:`shrink-0 p-0.5 rounded opacity-0 group-hover:opacity-50 hover:opacity-100 hover:bg-destructive/10 transition-all`,title:`Remove todo`,"aria-label":`Remove "${e.content}"`,children:(0,X.jsx)(at,{className:`w-3 h-3 text-muted-foreground`})})]},e.id)};return e.length===0?null:(0,X.jsxs)(`div`,{className:`rounded-lg border border-border bg-card/50 backdrop-blur-sm overflow-hidden`,children:[(0,X.jsxs)(`div`,{className:`px-3 py-1.5 flex items-center gap-2 border-b border-border/50`,children:[(0,X.jsx)(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:`Todos`}),(0,X.jsxs)(`span`,{className:`tabular text-[10px] text-muted-foreground ml-auto`,children:[d.length,`/`,e.length]})]}),l.length>0&&(0,X.jsx)(`div`,{className:`border-b border-border/30 last:border-b-0`,children:l.map(h)}),u.length>0&&(0,X.jsx)(`div`,{className:`border-b border-border/30 last:border-b-0`,children:u.map(h)}),f&&(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`button`,{type:`button`,onClick:()=>m(`completed`),className:`w-full px-3 py-1 flex items-center gap-1.5 text-[10px] text-muted-foreground hover:text-foreground transition-colors`,children:(0,X.jsxs)(`span`,{className:`tabular`,children:[p?`▶`:`▼`,` `,d.length,` completed`]})}),!p&&d.map(h)]})]})}var zc={pending:{icon:(0,X.jsx)(C,{className:`w-3.5 h-3.5`}),label:`Pending`,color:`text-muted-foreground/50`},in_progress:{icon:(0,X.jsx)(Pe,{className:`w-3.5 h-3.5 animate-spin`}),label:`In Progress`,color:`text-yellow-500`},blocked:{icon:(0,X.jsx)(ae,{className:`w-3.5 h-3.5`}),label:`Blocked`,color:`text-orange-500`},failed:{icon:(0,X.jsx)(N,{className:`w-3.5 h-3.5`}),label:`Failed`,color:`text-red-500`},review:{icon:(0,X.jsx)(v,{className:`w-3.5 h-3.5`}),label:`Review`,color:`text-blue-500`},completed:{icon:(0,X.jsx)(Be,{className:`w-3.5 h-3.5`}),label:`Done`,color:`text-emerald-500`}},Bc={critical:`text-red-600 dark:text-red-400`,high:`text-orange-600 dark:text-orange-400`,medium:`text-yellow-600 dark:text-yellow-400`,low:`text-muted-foreground`},Vc={feature:`⚡`,bugfix:`🐛`,refactor:`♻️`,docs:`📝`,test:`🧪`,chore:`🔧`};function Hc(){let[e,t]=(0,B.useState)([]),[n,r]=(0,B.useState)(new Set),i=V(),a=(0,B.useRef)(null);(0,B.useEffect)(()=>(i.getTasks(),a.current=i.on(`tasks.updated`,e=>{let n=e?.payload;n?.tasks&&t(n.tasks)}),()=>{a.current?.()}),[i]);let o=(0,B.useCallback)(e=>{r(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),s=(0,B.useCallback)((e,t)=>{i.updateTaskStatus(e,t)},[i]),c=[`in_progress`,`blocked`,`review`,`pending`,`failed`,`completed`],l=new Map;for(let t of e){let e=l.get(t.status)??[];e.push(t),l.set(t.status,e)}let u=l.get(`completed`)?.length??0;return e.length===0?null:(0,X.jsxs)(`div`,{className:`rounded-lg border border-border bg-card/50 backdrop-blur-sm overflow-hidden`,children:[(0,X.jsxs)(`div`,{className:`px-3 py-1.5 flex items-center gap-2 border-b border-border/50`,children:[(0,X.jsx)(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:`Tasks`}),(0,X.jsxs)(`span`,{className:`tabular text-[10px] text-muted-foreground ml-auto`,children:[u,`/`,e.length]})]}),c.map(e=>{let t=l.get(e);if(!t||t.length===0)return null;let r=zc[e],i=n.has(e);return(0,X.jsxs)(`div`,{className:`border-b border-border/30 last:border-b-0`,children:[(0,X.jsx)(`button`,{type:`button`,onClick:()=>o(e),className:`w-full px-3 py-1 flex items-center gap-1.5 text-[10px] text-muted-foreground hover:text-foreground transition-colors`,children:(0,X.jsxs)(`span`,{className:`tabular`,children:[i?`▶`:`▼`,` `,t.length,` `,r.label]})}),!i&&t.map(e=>(0,X.jsxs)(`div`,{className:Y(`px-3 py-1.5 flex items-start gap-2 text-[13px] group`,e.status===`in_progress`?`bg-yellow-50/40 dark:bg-yellow-950/25`:``),children:[(0,X.jsx)(`span`,{className:Y(`mt-0.5 shrink-0`,r.color),children:r.icon}),(0,X.jsxs)(`span`,{className:`leading-snug flex-1 min-w-0`,children:[(0,X.jsxs)(`span`,{className:Y(e.status===`completed`?`text-muted-foreground line-through`:`text-foreground/80`),children:[Vc[e.type],` `,e.title]}),e.priority!==`medium`&&(0,X.jsx)(`span`,{className:Y(`ml-1 text-[10px]`,Bc[e.priority]),children:e.priority}),e.assignee&&(0,X.jsxs)(`span`,{className:`ml-1 text-[10px] text-muted-foreground`,children:[`@`,e.assignee]}),e.estimateHours&&(0,X.jsxs)(`span`,{className:`ml-1 text-[10px] text-muted-foreground`,children:[e.estimateHours,`h`]})]}),(0,X.jsxs)(`div`,{className:`flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity shrink-0`,children:[e.status!==`in_progress`&&e.status!==`completed`&&(0,X.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),s(e.id,`in_progress`)},className:`px-1.5 py-0.5 text-[9px] rounded bg-primary/15 text-primary hover:bg-primary/25 transition-colors`,title:`Start`,children:`Start`}),e.status===`in_progress`&&(0,X.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),s(e.id,`completed`)},className:`px-1.5 py-0.5 text-[9px] rounded bg-[hsl(var(--success)/0.15)] text-[hsl(var(--success))] hover:bg-[hsl(var(--success)/0.25)] transition-colors`,title:`Complete`,children:`Done`}),e.status!==`completed`&&e.status!==`failed`&&(0,X.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),s(e.id,`failed`)},className:`px-1.5 py-0.5 text-[9px] rounded bg-destructive/15 text-destructive hover:bg-destructive/25 transition-colors`,title:`Mark failed`,children:`Fail`})]})]},e.id))]},e)})]})}var Uc={open:{icon:(0,X.jsx)(C,{className:`w-3.5 h-3.5`}),label:`Open`,color:`text-muted-foreground/50`},in_progress:{icon:(0,X.jsx)(Pe,{className:`w-3.5 h-3.5 animate-spin`}),label:`In Progress`,color:`text-yellow-500`},done:{icon:(0,X.jsx)(Be,{className:`w-3.5 h-3.5`}),label:`Done`,color:`text-emerald-500`}};function Wc(){let[e,t]=(0,B.useState)([]),[n,r]=(0,B.useState)(new Set),i=V(),a=(0,B.useRef)(null);(0,B.useEffect)(()=>(i.getPlan(),a.current=i.on(`plan.updated`,e=>{let n=e?.payload;n?.plan?.items&&t(n.plan.items)}),()=>{a.current?.()}),[i]);let o=(0,B.useCallback)(e=>{r(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),s=(0,B.useCallback)((e,t)=>{i.updatePlanItem(e.id,t)},[i]),c=[`in_progress`,`open`,`done`],l=new Map;for(let t of e){let e=l.get(t.status)??[];e.push(t),l.set(t.status,e)}let u=l.get(`done`)?.length??0;return e.length===0?null:(0,X.jsxs)(`div`,{className:`rounded-lg border border-border bg-card/50 backdrop-blur-sm overflow-hidden`,children:[(0,X.jsxs)(`div`,{className:`px-3 py-1.5 flex items-center gap-2 border-b border-border/50`,children:[(0,X.jsx)(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:`📋 Plan`}),(0,X.jsxs)(`span`,{className:`tabular text-[10px] text-muted-foreground ml-auto`,children:[u,`/`,e.length]})]}),c.map(e=>{let t=l.get(e);if(!t||t.length===0)return null;let r=Uc[e],i=n.has(e);return(0,X.jsxs)(`div`,{className:`border-b border-border/30 last:border-b-0`,children:[(0,X.jsx)(`button`,{type:`button`,onClick:()=>o(e),className:`w-full px-3 py-1 flex items-center gap-1.5 text-[10px] text-muted-foreground hover:text-foreground transition-colors`,children:(0,X.jsxs)(`span`,{className:`tabular`,children:[i?`▶`:`▼`,` `,t.length,` `,r.label]})}),!i&&t.map(e=>(0,X.jsxs)(`div`,{className:Y(`px-3 py-1.5 flex items-start gap-2 text-[13px] group`,e.status===`in_progress`?`bg-yellow-50/40 dark:bg-yellow-950/25`:``),children:[(0,X.jsx)(`span`,{className:Y(`mt-0.5 shrink-0`,r.color),children:r.icon}),(0,X.jsx)(`span`,{className:Y(`leading-snug flex-1 min-w-0`,e.status===`done`?`text-muted-foreground line-through`:`text-foreground/80`),children:e.title}),(0,X.jsxs)(`div`,{className:`flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity shrink-0`,children:[e.status===`open`&&(0,X.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),s(e,`in_progress`)},className:`px-1.5 py-0.5 text-[9px] rounded bg-primary/15 text-primary hover:bg-primary/25 transition-colors`,title:`Start`,children:`Start`}),e.status!==`done`&&(0,X.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),s(e,`done`)},className:`px-1.5 py-0.5 text-[9px] rounded bg-[hsl(var(--success)/0.15)] text-[hsl(var(--success))] hover:bg-[hsl(var(--success)/0.25)] transition-colors`,title:`Mark done`,children:`Done`}),e.status===`done`&&(0,X.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),s(e,`open`)},className:`px-1.5 py-0.5 text-[9px] rounded bg-muted text-muted-foreground hover:bg-accent hover:text-foreground transition-colors`,title:`Reopen`,children:`Reopen`})]})]},e.id))]},e)})]})}var Gc=[{id:`todos`,label:`Todos`,icon:`✅`},{id:`tasks`,label:`Tasks`,icon:`📋`},{id:`plan`,label:`Plan`,icon:`🗺️`}];function Kc(){let[e,t]=(0,B.useState)(`todos`);return(0,X.jsxs)(`div`,{className:`rounded-lg border border-border bg-card/50 backdrop-blur-sm overflow-hidden`,children:[(0,X.jsx)(`div`,{className:`flex border-b border-border/50 bg-muted/30`,children:Gc.map(n=>(0,X.jsxs)(`button`,{type:`button`,onClick:()=>t(n.id),className:Y(`flex items-center gap-1 px-3 py-1.5 text-[11px] font-medium transition-colors`,`border-b-2 -mb-px`,e===n.id?`border-primary text-foreground bg-background`:`border-transparent text-muted-foreground hover:text-foreground hover:bg-accent/30`),children:[(0,X.jsx)(`span`,{className:`text-xs`,children:n.icon}),n.label]},n.id))}),(0,X.jsx)(`div`,{className:Y(e===`todos`?`block`:`hidden`),children:(0,X.jsx)(Rc,{})}),(0,X.jsx)(`div`,{className:Y(e===`tasks`?`block`:`hidden`),children:(0,X.jsx)(Hc,{})}),(0,X.jsx)(`div`,{className:Y(e===`plan`?`block`:`hidden`),children:(0,X.jsx)(Wc,{})})]})}var qc={autophase:{active:`bg-primary/15 border-primary/40 text-primary`,idle:`text-primary/80 hover:bg-primary/10`},goal:{active:`bg-rose-500/15 border-rose-500/40 text-rose-600 dark:text-rose-400`,idle:`text-rose-600/80 dark:text-rose-400/80 hover:bg-rose-500/10`},fleet:{active:`bg-emerald-500/15 border-emerald-500/40 text-emerald-600 dark:text-emerald-400`,idle:`text-emerald-600/80 dark:text-emerald-400/80 hover:bg-emerald-500/10`},work:{active:`bg-amber-500/15 border-amber-500/40 text-amber-600 dark:text-amber-400`,idle:`text-amber-600/80 dark:text-amber-400/80 hover:bg-amber-500/10`},worktrees:{active:`bg-violet-500/15 border-violet-500/40 text-violet-600 dark:text-violet-400`,idle:`text-violet-600/80 dark:text-violet-400/80 hover:bg-violet-500/10`},collab:{active:`bg-cyan-500/15 border-cyan-500/40 text-cyan-600 dark:text-cyan-400`,idle:`text-muted-foreground hover:bg-muted/60`}};function Jc({section:e,icon:t,label:n,value:r,active:i,pulse:a,onClick:o}){let s=qc[e];return(0,X.jsxs)(`button`,{type:`button`,onClick:o,title:i?`Collapse ${n}`:`Expand ${n}`,className:Y(`flex items-center gap-1.5 h-6 px-2 rounded-full border text-[11px] font-medium shrink-0 transition-colors`,i?s.active:Y(`border-transparent`,s.idle)),children:[(0,X.jsx)(`span`,{className:Y(a&&`animate-pulse`),children:t}),n,r&&(0,X.jsx)(`span`,{className:`tabular-nums opacity-80`,children:r})]})}function Yc({sessionId:e}){let{selectAutoPhase:t,toggleAutoPhaseAutonomous:n}=Z(),r=G(e=>e.dockSection),i=G(e=>e.toggleDockSection),a=G(e=>e.setCurrentView),o=fr(e=>e.goal),s=pr(e=>e),c=rr(e=>e.worktrees),l=rr(e=>e.baseBranch),u=W(e=>e.todos),d=K(e=>e.agents),f=(0,B.useCallback)(e=>t(e),[t]),p=(0,B.useCallback)(()=>n(!s.autonomous),[n,s.autonomous]),[m,g]=(0,B.useState)(`graph`),_=d.size,v=(0,B.useMemo)(()=>Array.from(d.values()).filter(e=>e.status===`running`).length,[d]),y=u.filter(e=>e.status===`completed`).length,b=u.some(e=>e.status===`in_progress`),x=s.phases.length>0,S=(0,B.useRef)(s.phases.length);(0,B.useEffect)(()=>{let e=G.getState();S.current===0&&s.phases.length>0&&e.dockSection===null&&e.setDockSection(`autophase`),s.phases.length===0&&e.dockSection===`autophase`&&e.setDockSection(null),S.current=s.phases.length},[s.phases.length]);let C={autophase:x,goal:o!==null,fleet:_>0,work:!0,worktrees:c.length>0,collab:!0},w=r&&C[r]?r:null;return(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1`,children:[C.autophase&&(0,X.jsx)(Jc,{section:`autophase`,icon:(0,X.jsx)(h,{className:`h-3 w-3`}),label:`AutoPhase`,value:`${s.overallPercent}%`,active:w===`autophase`,pulse:s.activePhaseId!=null,onClick:()=>i(`autophase`)}),C.goal&&o&&(0,X.jsx)(Jc,{section:`goal`,icon:(0,X.jsx)(lt,{className:`h-3 w-3`}),label:`Goal`,value:`${o.progress}%`,active:w===`goal`,pulse:o.goalState===`active`,onClick:()=>i(`goal`)}),C.fleet&&(0,X.jsx)(Jc,{section:`fleet`,icon:(0,X.jsx)(R,{className:`h-3 w-3`}),label:`Fleet`,value:`${v}/${_}`,active:w===`fleet`,pulse:v>0,onClick:()=>i(`fleet`)}),(0,X.jsx)(Jc,{section:`work`,icon:(0,X.jsx)(fn,{className:`h-3 w-3`}),label:`Work`,value:u.length>0?`${y}/${u.length}`:void 0,active:w===`work`,pulse:b,onClick:()=>i(`work`)}),C.worktrees&&(0,X.jsx)(Jc,{section:`worktrees`,icon:(0,X.jsx)(pt,{className:`h-3 w-3`}),label:`Worktrees`,value:String(c.length),active:w===`worktrees`,onClick:()=>i(`worktrees`)}),(0,X.jsx)(Jc,{section:`collab`,icon:(0,X.jsx)(Wt,{className:`h-3 w-3`}),label:`Collab`,active:w===`collab`,onClick:()=>i(`collab`)})]}),w===`autophase`&&x&&(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(`div`,{className:`flex justify-end`,children:(0,X.jsxs)($,{variant:`outline`,size:`sm`,className:`h-6 gap-1 text-[10px]`,onClick:()=>a(`autophase`),children:[(0,X.jsx)(Ve,{className:`h-3 w-3`}),`Full view`]})}),(0,X.jsx)(na,{phases:s.phases,activePhaseId:s.activePhaseId??void 0,overallPercent:s.overallPercent,autonomous:s.autonomous,onPhaseClick:f,onToggleAutonomous:p,className:`w-72 shrink-0`})]}),w===`goal`&&(0,X.jsx)(Ic,{goal:o}),w===`fleet`&&(0,X.jsx)(hc,{}),w===`worktrees`&&(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(`div`,{className:`flex items-center gap-2`,children:[`graph`,`lanes`].map(e=>(0,X.jsx)(`button`,{type:`button`,onClick:()=>g(e),className:Y(`text-[10px] px-2 py-0.5 rounded-full border transition-colors capitalize`,m===e?`bg-primary/10 border-primary/30 text-primary`:`border-border text-muted-foreground hover:text-foreground`),children:e},e))}),m===`graph`?(0,X.jsx)(fa,{worktrees:c,baseBranch:l||`HEAD`}):(0,X.jsx)(ga,{worktrees:c,baseBranch:l||`HEAD`})]}),(0,X.jsx)(`div`,{className:Y(w===`work`?`block`:`hidden`),id:`panel-work`,children:(0,X.jsx)(Kc,{})}),(0,X.jsx)(`div`,{className:Y(w===`collab`?`block`:`hidden`),children:(0,X.jsx)(Nc,{sessionId:e})})]})}var Xc=B.forwardRef(({className:e,inset:t,children:r,...i},a)=>(0,X.jsxs)(hn,{ref:a,className:Y(`flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent`,t&&`pl-8`,e),...i,children:[r,(0,X.jsx)(n,{className:`ml-auto h-4 w-4`})]}));Xc.displayName=hn.displayName;var Zc=B.forwardRef(({className:e,...t},n)=>(0,X.jsx)(Nt,{ref:n,className:Y(`z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2`,e),...t}));Zc.displayName=Nt.displayName;var Qc=B.forwardRef(({className:e,sideOffset:t=4,...n},r)=>(0,X.jsx)(Gt,{children:(0,X.jsx)(Vt,{ref:r,sideOffset:t,className:Y(`z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2`,e),...n})}));Qc.displayName=Vt.displayName;var $c=B.forwardRef(({className:e,inset:t,...n},r)=>(0,X.jsx)(nn,{ref:r,className:Y(`relative flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&>svg]:size-4 [&>svg]:shrink-0`,t&&`pl-8`,e),...n}));$c.displayName=nn.displayName;var el=B.forwardRef(({className:e,children:t,checked:n,...r},i)=>(0,X.jsxs)(dn,{ref:i,className:Y(`relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50`,e),checked:n,...r,children:[(0,X.jsx)(`span`,{className:`absolute left-2 flex h-3.5 w-3.5 items-center justify-center`,children:(0,X.jsx)(wt,{children:(0,X.jsx)(pn,{className:`h-4 w-4`})})}),t]}));el.displayName=dn.displayName;var tl=B.forwardRef(({className:e,children:t,...n},r)=>(0,X.jsxs)(sn,{ref:r,className:Y(`relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50`,e),...n,children:[(0,X.jsx)(`span`,{className:`absolute left-2 flex h-3.5 w-3.5 items-center justify-center`,children:(0,X.jsx)(wt,{children:(0,X.jsx)(C,{className:`h-2 w-2 fill-current`})})}),t]}));tl.displayName=sn.displayName;var nl=B.forwardRef(({className:e,inset:t,...n},r)=>(0,X.jsx)(Ye,{ref:r,className:Y(`px-2 py-1.5 text-sm font-semibold`,t&&`pl-8`,e),...n}));nl.displayName=Ye.displayName;var rl=B.forwardRef(({className:e,...t},n)=>(0,X.jsx)(nt,{ref:n,className:Y(`-mx-1 my-1 h-px bg-muted`,e),...t}));rl.displayName=nt.displayName;var il=({className:e,...t})=>(0,X.jsx)(`span`,{className:Y(`ml-auto text-xs tracking-widest opacity-60`,e),...t});il.displayName=`DropdownMenuShortcut`;function al({current:e,max:t,className:n,showLabel:r=!0}){let i=Math.min(e,t),a=Math.max(0,t-i),o=t>0?i/t*100:0,s=o>=90?`text-destructive`:o>=70?`text-[hsl(var(--warning))]`:`text-[hsl(var(--success))]`;return(0,X.jsxs)(`span`,{className:n,title:`Fleet concurrency: ${e}/${t}`,children:[(0,X.jsxs)(`span`,{"aria-hidden":`true`,className:`font-mono text-[10px] tracking-tight`,children:[`[`,(0,X.jsx)(`span`,{className:s,children:`█`.repeat(i)}),(0,X.jsx)(`span`,{className:`text-[hsl(var(--muted))]`,children:`░`.repeat(a)}),`]`]}),r&&(0,X.jsxs)(`span`,{className:`ml-1.5 tabular-nums text-[10px] text-muted-foreground font-mono`,children:[e,`/`,t]})]})}function ol(e){let t=Date.now()-e;return t<5e3?`just now`:t<6e4?`${Math.floor(t/1e3)}s ago`:t<36e5?`${Math.floor(t/6e4)}m ago`:`${Math.floor(t/36e5)}h ago`}var sl={spawned:`🚀`,task_started:`▶`,tool_executed:`⚡`,iteration_summary:`🔄`,budget_extended:`⚡`,task_completed:`✅`,ctx_pct:`💬`,leader_updated:`👑`};function cl({events:e,max:t=20,className:n}){let r=e.slice(0,t);return r.length===0?(0,X.jsx)(`div`,{className:`py-4 text-center text-xs text-muted-foreground ${n??``}`,children:`No events yet.`}):(0,X.jsx)(`div`,{className:`space-y-0.5 overflow-y-auto max-h-48 ${n??``}`,children:r.map(e=>(0,X.jsxs)(`div`,{className:`flex items-start gap-2 text-[10px] leading-tight py-0.5 px-1 rounded hover:bg-accent/50 transition-colors`,children:[(0,X.jsx)(`span`,{className:`shrink-0 w-5 text-center`,"aria-hidden":`true`,children:sl[e.kind]??`·`}),(0,X.jsx)(`span`,{className:`shrink-0 w-12 text-right text-muted-foreground font-mono tabular-nums`,children:ol(e.timestamp)}),(0,X.jsx)(`span`,{className:`truncate text-foreground/90`,children:e.message}),e.value!==void 0&&e.kind===`tool_executed`&&(0,X.jsx)(`span`,{className:`ml-auto shrink-0 tabular-nums text-muted-foreground font-mono`,children:e.value>=1e3?`${(e.value/1e3).toFixed(1)}s`:`${e.value}ms`}),e.value!==void 0&&e.kind===`ctx_pct`&&(0,X.jsxs)(`span`,{className:`ml-auto shrink-0 tabular-nums text-muted-foreground font-mono`,children:[e.value,`%`]})]},e.id))})}function ll(e){return e<=0?`$0`:e>=.01?`$${e.toFixed(3)}`:`$${e.toFixed(5)}`.replace(/0+$/,``).replace(/\.$/,``)}function ul(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e)}function dl(e){let t=Math.floor(e/1e3),n=Math.floor(t/60),r=Math.floor(n/60);return r>0?`${r}h ${n%60}m`:n>0?`${n}m ${t%60}s`:`${t}s`}var fl={running:{led:`bg-emerald-500`,label:`running`,pulse:!0,color:`text-emerald-500`},completed:{led:`bg-emerald-500`,label:`done`,pulse:!1,color:`text-emerald-500`},failed:{led:`bg-destructive`,label:`failed`,pulse:!1,color:`text-destructive`},timeout:{led:`bg-amber-500`,label:`timeout`,pulse:!1,color:`text-amber-500`},stopped:{led:`bg-muted-foreground`,label:`stopped`,pulse:!1,color:`text-muted-foreground`}};function pl({agent:e,now:t}){let[r,i]=(0,B.useState)(!1),[a,o]=(0,B.useState)(!1),s=fl[e.status],l=e.status===`running`,u=(0,B.useCallback)(async e=>{try{await navigator.clipboard.writeText(e),i(!0),setTimeout(()=>i(!1),2e3)}catch{}},[]),d=e.toolLog.reduce((e,t)=>e+t.durationMs,0),f=e.toolLog.length>0?Math.round(d/e.toolLog.length):0,p=(0,B.useMemo)(()=>{let t=new Set;return e.toolLog.forEach(e=>t.add(e.name)),t.size},[e.toolLog]),m=e.partialText||e.finalText||void 0,h=!e.finalText&&!!e.partialText;return(0,X.jsxs)(`div`,{className:`h-full flex flex-col`,children:[(0,X.jsxs)(`div`,{className:`shrink-0 border-b bg-card p-4 space-y-3`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,X.jsx)(`div`,{className:`flex items-center justify-center w-10 h-10 rounded-lg bg-primary/10`,children:(0,X.jsx)(R,{className:`h-5 w-5 text-primary`})}),(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`span`,{className:`text-base font-semibold`,children:e.name}),(0,X.jsx)(`span`,{className:Y(`px-2 py-0.5 rounded text-[10px] font-medium uppercase tracking-wider`,e.status===`running`?`bg-emerald-500/15 text-emerald-600 dark:text-emerald-400`:e.status===`failed`||e.status===`timeout`?`bg-destructive/15 text-destructive`:`bg-muted text-muted-foreground`),children:s.label})]}),(0,X.jsxs)(`span`,{className:`text-[10px] text-muted-foreground font-mono`,children:[`session: `,e.sessionId?.slice(0,12),`…`]})]})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] text-muted-foreground`,children:[l&&(0,X.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(It,{className:`h-3.5 w-3.5`}),(0,X.jsx)(`span`,{className:`tabular-nums font-mono`,children:dl(Math.max(0,t-e.startedAt))})]}),(0,X.jsx)(`span`,{className:Y(`led`,s.led,l&&`led-pulse`)})]})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-2 rounded-lg bg-muted/30`,children:[(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground uppercase tracking-wider`,children:`Activity`}),(0,X.jsx)(cc,{bins:e.sparklineBins,className:`font-mono text-[9px]`}),e.budgetWarning&&(0,X.jsxs)(`span`,{className:`ml-auto flex items-center gap-1 text-[10px] text-amber-500`,children:[(0,X.jsx)(ze,{className:`h-3 w-3`}),`budget warning`]})]}),e.description&&(0,X.jsxs)(`div`,{className:`px-3 py-2 rounded-lg bg-muted/20 border border-border/50`,children:[(0,X.jsx)(`span`,{className:`text-[9px] text-muted-foreground uppercase tracking-wider`,children:`Current Task`}),(0,X.jsx)(`p`,{className:`text-xs mt-1 text-foreground/80`,children:e.description})]})]}),(0,X.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-4 space-y-4`,children:[(0,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,X.jsxs)(`div`,{className:`rounded-lg border bg-card p-3`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-[9px] text-muted-foreground uppercase tracking-wider mb-2`,children:[(0,X.jsx)(c,{className:`h-3 w-3`}),` Provider / Model`]}),(0,X.jsxs)(`div`,{className:`text-sm font-mono font-medium`,children:[e.provider??`?`,`/`,e.model??`?`]})]}),(0,X.jsxs)(`div`,{className:`rounded-lg border bg-card p-3`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-[9px] text-muted-foreground uppercase tracking-wider mb-2`,children:[(0,X.jsx)(ct,{className:`h-3 w-3`}),` Performance`]}),(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsxs)(`div`,{className:`flex justify-between text-[11px]`,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`Iterations`}),(0,X.jsx)(`span`,{className:`font-mono font-medium`,children:e.iteration})]}),(0,X.jsxs)(`div`,{className:`flex justify-between text-[11px]`,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`Tool Calls`}),(0,X.jsx)(`span`,{className:`font-mono font-medium`,children:e.toolCalls})]}),(0,X.jsxs)(`div`,{className:`flex justify-between text-[11px]`,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`Unique Tools`}),(0,X.jsx)(`span`,{className:`font-mono font-medium`,children:p})]})]})]}),(0,X.jsxs)(`div`,{className:`rounded-lg border bg-card p-3`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-[9px] text-muted-foreground uppercase tracking-wider mb-2`,children:[(0,X.jsx)(k,{className:`h-3 w-3`}),` Cost`]}),(0,X.jsx)(`div`,{className:`text-lg font-mono font-bold text-emerald-500`,children:ll(e.costUsd)}),(0,X.jsxs)(`div`,{className:`text-[10px] text-muted-foreground mt-1`,children:[`avg `,f,`ms per tool`]})]}),(0,X.jsxs)(`div`,{className:`rounded-lg border bg-card p-3`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-[9px] text-muted-foreground uppercase tracking-wider mb-2`,children:[(0,X.jsx)(ie,{className:`h-3 w-3`}),` Context`]}),(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsxs)(`div`,{className:`flex justify-between text-[11px]`,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`Tokens`}),(0,X.jsx)(`span`,{className:`font-mono font-medium`,children:ul(e.ctxTokens)})]}),(0,X.jsx)(`div`,{className:`h-2 w-full rounded-full bg-muted overflow-hidden`,children:(0,X.jsx)(`div`,{className:Y(`h-full rounded-full transition-all`,e.ctxPct>=85?`bg-destructive`:e.ctxPct>=70?`bg-amber-500`:`bg-emerald-500`),style:{width:`${Math.min(200,e.ctxPct)}%`}})}),(0,X.jsxs)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums font-mono`,children:[e.ctxPct,`% used`]})]})]})]}),e.currentTool&&(0,X.jsxs)(`div`,{className:Y(`rounded-lg border px-4 py-3 flex items-center gap-3`,l?`border-primary/30 bg-primary/[0.04]`:`border-border bg-muted/30`),children:[(0,X.jsx)(He,{className:Y(`h-4 w-4`,l?`text-primary animate-pulse`:`text-muted-foreground`)}),(0,X.jsx)(`span`,{className:`text-sm font-mono font-medium`,children:e.currentTool}),l?(0,X.jsxs)(`span`,{className:`ml-auto flex items-center gap-1.5 text-[10px] text-primary`,children:[(0,X.jsx)(L,{className:`h-3 w-3 animate-spin`}),` running…`]}):(0,X.jsx)(`span`,{className:`ml-auto text-[10px] text-muted-foreground`,children:`completed`})]}),m?(0,X.jsxs)(`div`,{className:`rounded-lg border bg-card`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b bg-muted/30`,children:[(0,X.jsx)(`span`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wider flex items-center gap-2`,children:h?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-blue-500 animate-pulse`}),`Live Output`]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Ke,{className:`h-3 w-3`}),`Final Output`]})}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>u(m),className:`flex items-center gap-1 px-2 py-1 rounded text-[10px] text-muted-foreground hover:text-foreground hover:bg-muted transition-colors`,children:r?`✓ Copied`:`Copy`})]}),(0,X.jsx)(`pre`,{className:`p-4 text-xs whitespace-pre-wrap font-mono text-foreground/80 leading-relaxed max-h-64 overflow-y-auto`,children:m})]}):l?(0,X.jsxs)(`div`,{className:`rounded-lg border border-dashed border-border p-6 text-center`,children:[(0,X.jsx)(L,{className:`h-6 w-6 mx-auto mb-2 text-muted-foreground/50 animate-spin`}),(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Waiting for output…`})]}):null,e.budgetWarning&&(0,X.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3 rounded-lg bg-amber-500/10 border border-amber-500/20`,children:[(0,X.jsx)(ze,{className:`h-5 w-5 text-amber-500 shrink-0`}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`span`,{className:`text-sm font-medium text-amber-600 dark:text-amber-400`,children:`⚡ Budget Warning`}),(0,X.jsxs)(`p`,{className:`text-[11px] text-amber-600/80 dark:text-amber-400/80 mt-0.5`,children:[`Hitting `,e.budgetWarning.kind,` limit (`,e.budgetWarning.used,`/`,e.budgetWarning.limit,`)`]})]})]}),e.extensions>0&&(0,X.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3 rounded-lg bg-amber-500/10 border border-amber-500/20`,children:[(0,X.jsx)(ze,{className:`h-5 w-5 text-amber-500 shrink-0`}),(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`span`,{className:`text-sm font-medium`,children:[e.extensions,` Budget Extension`,e.extensions===1?``:`s`]}),(0,X.jsxs)(`p`,{className:`text-[11px] text-muted-foreground mt-0.5`,children:[`Agent extended its budget `,e.extensions,` time`,e.extensions===1?``:`s`,` due to long-running tasks`]})]})]}),e.error&&(0,X.jsxs)(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 p-4`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,X.jsx)(N,{className:`h-4 w-4 text-destructive`}),(0,X.jsx)(`span`,{className:`text-[10px] font-semibold text-destructive uppercase tracking-wider`,children:`Error`})]}),(0,X.jsx)(`p`,{className:`text-sm text-destructive/90`,children:e.error.message})]}),e.failureReason&&(0,X.jsxs)(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 p-4`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,X.jsx)(N,{className:`h-4 w-4 text-destructive`}),(0,X.jsx)(`span`,{className:`text-[10px] font-semibold text-destructive uppercase tracking-wider`,children:`Failure Reason`})]}),(0,X.jsx)(`p`,{className:`text-sm text-destructive/90`,children:e.failureReason})]}),e.toolLog.length>0&&(0,X.jsxs)(`div`,{className:`rounded-lg border bg-card`,children:[(0,X.jsxs)(`button`,{type:`button`,onClick:()=>o(!a),className:`w-full flex items-center justify-between px-4 py-2 border-b bg-muted/30 hover:bg-muted/50 transition-colors`,children:[(0,X.jsxs)(`span`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wider flex items-center gap-2`,children:[(0,X.jsx)(He,{className:`h-3 w-3`}),`Tool Log (`,e.toolLog.length,` calls)`]}),(0,X.jsx)(n,{className:Y(`h-4 w-4 text-muted-foreground transition-transform`,a&&`rotate-90`)})]}),(0,X.jsx)(`div`,{className:Y(`overflow-hidden transition-all`,a?`max-h-[500px]`:`max-h-48`),children:(0,X.jsx)(`div`,{className:`p-2 space-y-0.5`,children:e.toolLog.map((e,t)=>(0,X.jsxs)(`div`,{className:Y(`flex items-center gap-3 rounded px-3 py-2 text-[11px]`,e.ok?`bg-muted/30 hover:bg-muted/50`:`bg-destructive/5 border border-destructive/20`),children:[(0,X.jsx)(`span`,{className:Y(`led shrink-0`,e.ok?`bg-emerald-500`:`bg-destructive`)}),(0,X.jsx)(`span`,{className:Y(`font-mono font-medium w-20 shrink-0`,e.ok?`text-foreground`:`text-destructive`),children:e.name}),(0,X.jsx)(`span`,{className:`text-muted-foreground tabular-nums text-[10px]`,children:e.durationMs>=1e3?`${(e.durationMs/1e3).toFixed(2)}s`:`${e.durationMs}ms`}),!e.ok&&(0,X.jsx)(`span`,{className:`ml-auto text-[10px] text-destructive font-medium`,children:`Failed`}),(0,X.jsx)(`span`,{className:`ml-auto text-[9px] text-muted-foreground tabular-nums`,children:new Date(e.at).toLocaleTimeString()})]},`${e.name}-${e.at}-${t}`))})})]})]})]})}function ml({agent:e,isSelected:t,isLeader:n,onClick:r}){let i=fl[e.status],a=e.status===`running`;return(0,X.jsxs)(`button`,{type:`button`,onClick:r,className:Y(`w-full text-left grid grid-cols-[140px_60px_1fr_60px_60px_60px_60px_50px_50px] items-center gap-x-2 px-3 py-1.5 rounded-md text-xs transition-colors`,t?`bg-primary/15 ring-1 ring-primary/40`:`hover:bg-accent/50`,a&&!t&&`bg-muted/30`),children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1 min-w-0`,children:[(0,X.jsx)(`span`,{className:Y(`led shrink-0`,i.led,i.pulse&&`led-pulse`)}),(0,X.jsx)(`span`,{className:`truncate font-medium`,children:e.name}),n&&(0,X.jsx)(be,{className:`h-3 w-3 shrink-0 text-amber-500`,"aria-label":`leader`})]}),(0,X.jsx)(`span`,{className:Y(`text-[10px] tabular-nums`,a?`text-emerald-500`:`text-muted-foreground`),children:i.label}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1 min-w-0`,children:[(0,X.jsx)(cc,{bins:e.sparklineBins,className:`font-mono text-[9px]`}),e.budgetWarning&&(0,X.jsx)(`span`,{title:`⚡ hitting ${e.budgetWarning.kind} limit (${e.budgetWarning.used}/${e.budgetWarning.limit})`,children:(0,X.jsx)(ze,{className:`h-3 w-3 shrink-0 text-amber-500`,"aria-label":`budget warning`})})]}),(0,X.jsxs)(`span`,{className:`tabular-nums text-muted-foreground text-[10px]`,children:[e.iteration,`it`]}),(0,X.jsxs)(`span`,{className:`tabular-nums text-muted-foreground text-[10px]`,children:[e.toolCalls,`tc`]}),(0,X.jsx)(`span`,{className:`tabular-nums font-mono text-[10px]`,children:ll(e.costUsd)}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-0.5 min-w-0`,children:[(0,X.jsx)(`div`,{className:`h-1.5 w-full rounded-full bg-muted overflow-hidden`,children:(0,X.jsx)(`div`,{className:Y(`h-full rounded-full transition-all`,e.ctxPct>=85?`bg-destructive`:e.ctxPct>=70?`bg-amber-500`:`bg-emerald-500`),style:{width:`${Math.min(200,e.ctxPct)}%`}})}),(0,X.jsx)(`span`,{className:`text-[9px] tabular-nums text-muted-foreground font-mono leading-none`,children:e.maxContext>0?`${e.ctxPct}%`:`—`})]}),(0,X.jsx)(`span`,{className:`tabular-nums text-[10px] text-muted-foreground`,children:e.extensions>0?`⚡×${e.extensions}`:`—`}),(0,X.jsx)(`span`,{className:`text-[9px] text-destructive truncate`,title:e.failureReason,children:e.failureReason??``})]})}function hl({onClose:e,onSelectAgent:t,isOverlay:n=!1}){let r=K(e=>e.agents),i=K(e=>e.leaderId),a=K(e=>e.fleetTokensIn),o=K(e=>e.fleetTokensOut),s=K(e=>e.fleetConcurrency),c=K(e=>e.fleetConcurrencyMax),l=K(e=>e.eventTimeline),[u,d]=(0,B.useState)(null),[f,p]=(0,B.useState)(Date.now());(0,B.useEffect)(()=>{let e=setInterval(()=>p(Date.now()),1e3);return()=>clearInterval(e)},[]);let m=(0,B.useMemo)(()=>{let e=Array.from(r.values());return e.sort((e,t)=>{if(e.id===i)return-1;if(t.id===i)return 1;let n=e.status===`running`?0:1,r=t.status===`running`?0:1;return n===r?e.startedAt-t.startedAt:n-r}),e},[r,i]),h=(0,B.useMemo)(()=>Array.from(r.values()).reduce((e,t)=>e+t.costUsd,0),[r]),g=m.filter(e=>e.status===`running`).length,_=u===null?null:m[u],v=(0,B.useCallback)(e=>d(t=>t===e?null:e),[]),y=(0,B.useCallback)(n=>{if(n.key===`Escape`){u===null?e&&e():d(null);return}if(n.key===`ArrowDown`){n.preventDefault(),d(e=>Math.min((e??-1)+1,m.length-1));return}if(n.key===`ArrowUp`){n.preventDefault(),d(e=>Math.max((e??0)-1,0));return}n.key===`Enter`&&m[u??0]&&t?.(m[u??0])},[m,u,e,t]);return(0,B.useEffect)(()=>{let t=t=>{t.key===`Escape`&&e&&e()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e]),(0,X.jsxs)(`div`,{className:n?`fixed inset-0 z-50 flex flex-col bg-background/95 backdrop-blur-md`:`flex flex-col h-full`,onKeyDown:y,tabIndex:-1,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b bg-card/80 backdrop-blur shrink-0`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,X.jsx)(R,{className:`h-5 w-5 text-primary`}),(0,X.jsxs)(`h2`,{className:`text-sm font-semibold flex items-center gap-2`,children:[`FLEET MONITOR`,g>0&&(0,X.jsxs)(`span`,{className:`flex items-center gap-1 text-[11px] text-emerald-500 font-normal`,children:[(0,X.jsx)(`span`,{className:`led led-pulse bg-emerald-500`}),g,` running`]})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,X.jsxs)(`span`,{children:[m.length,` total agents`]}),(0,X.jsx)(al,{current:s,max:c,showLabel:!0})]})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,X.jsxs)(`span`,{className:`text-xs text-muted-foreground tabular-nums font-mono`,children:[`↓`,ul(a),` ↑`,ul(o),` · `,ll(h)]}),(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums font-mono`,children:i?`👑 ${r.get(i)?.name??i}`:`no leader`}),n&&e&&(0,X.jsx)(`button`,{type:`button`,onClick:e,className:`p-1.5 rounded-md hover:bg-muted transition-colors`,"aria-label":`Close fleet monitor`,children:(0,X.jsx)(N,{className:`h-4 w-4`})})]})]}),(0,X.jsxs)(`div`,{className:`flex-1 flex overflow-hidden`,children:[(0,X.jsxs)(`div`,{className:Y(`flex flex-col border-r transition-all duration-200`,_?`w-[500px] shrink-0`:`w-full`),children:[(0,X.jsx)(`div`,{className:`border-b bg-card/80 px-3 py-2`,children:(0,X.jsxs)(`div`,{className:`grid grid-cols-[140px_60px_1fr_60px_60px_60px_60px_50px_50px] gap-x-2 text-[9px] uppercase tracking-wider text-muted-foreground font-medium`,children:[(0,X.jsx)(`span`,{children:`Name`}),(0,X.jsx)(`span`,{children:`Status`}),(0,X.jsx)(`span`,{children:`Activity`}),(0,X.jsx)(`span`,{children:`Iters`}),(0,X.jsx)(`span`,{children:`Tools`}),(0,X.jsx)(`span`,{children:`Cost`}),(0,X.jsx)(`span`,{children:`CTX`}),(0,X.jsx)(`span`,{children:`Ext`}),(0,X.jsx)(`span`,{children:`Reason`})]})}),(0,X.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:m.length===0?(0,X.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full text-muted-foreground`,children:[(0,X.jsx)(Wt,{className:`h-12 w-12 mb-3 opacity-20`}),(0,X.jsx)(`p`,{className:`text-sm font-medium`,children:`No agents active`}),(0,X.jsx)(`p`,{className:`text-xs mt-1`,children:`Agents appear here when the fleet is active.`})]}):(0,X.jsx)(`div`,{className:`p-2 space-y-0.5`,children:m.map((e,t)=>(0,X.jsx)(ml,{agent:e,isSelected:t===u,isLeader:e.id===i,onClick:()=>v(t)},e.id))})}),(0,X.jsxs)(`div`,{className:`border-t bg-card/80 shrink-0`,children:[(0,X.jsx)(`div`,{className:`px-4 py-2 border-b`,children:(0,X.jsxs)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground font-medium flex items-center gap-2`,children:[(0,X.jsx)(Pe,{className:`h-3 w-3`}),`Event Timeline`]})}),(0,X.jsx)(`div`,{className:`px-4 py-2 max-h-32 overflow-y-auto`,children:(0,X.jsx)(cl,{events:l,max:10})}),(0,X.jsxs)(`div`,{className:`px-4 py-1.5 border-t text-[10px] text-muted-foreground flex items-center gap-4`,children:[(0,X.jsx)(`span`,{children:`↑↓ navigate`}),(0,X.jsx)(`span`,{children:`↵ select detail`}),(0,X.jsx)(`span`,{children:`Esc deselect / close`})]})]})]}),_&&(0,X.jsx)(`div`,{className:`flex-1 overflow-hidden bg-card/50`,children:(0,X.jsxs)(`div`,{className:`h-full flex flex-col`,children:[(0,X.jsxs)(`div`,{className:`shrink-0 px-4 py-2 border-b bg-card/80 flex items-center gap-2`,children:[(0,X.jsx)(ln,{className:`h-4 w-4 text-primary`}),(0,X.jsx)(`span`,{className:`text-xs font-semibold text-primary`,children:_.name}),(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`detailed view`}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>d(null),className:`ml-auto text-[10px] text-muted-foreground hover:text-foreground transition-colors flex items-center gap-1`,children:`✕ close`})]}),(0,X.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:(0,X.jsx)(pl,{agent:_,now:f})})]})}),!_&&m.length>0&&(0,X.jsx)(`div`,{className:`flex-1 flex items-center justify-center bg-muted/20`,children:(0,X.jsxs)(`div`,{className:`text-center space-y-3 max-w-sm`,children:[(0,X.jsx)(Wt,{className:`h-12 w-12 text-muted-foreground/30 mx-auto`}),(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Select an agent to view detailed information`}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground/60`,children:`Click on any agent in the list to see detailed metrics, tool logs, streaming output, and more — similar to the chat history detailed view.`}),(0,X.jsxs)(`div`,{className:`flex items-center justify-center gap-4 pt-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] text-muted-foreground`,children:[(0,X.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted border text-[9px]`,children:`↑`}),(0,X.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted border text-[9px]`,children:`↓`}),(0,X.jsx)(`span`,{children:`navigate`})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] text-muted-foreground`,children:[(0,X.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted border text-[9px]`,children:`Enter`}),(0,X.jsx)(`span`,{children:`select`})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] text-muted-foreground`,children:[(0,X.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted border text-[9px]`,children:`Esc`}),(0,X.jsx)(`span`,{children:`deselect`})]})]})]})})]})]})}function gl(e){return e<=0?`$0`:e>=.01?`$${e.toFixed(3)}`:`$${e.toFixed(5)}`.replace(/0+$/,``).replace(/\.$/,``)}function _l(e){let t=Math.floor(e/1e3);return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`}var vl={running:{led:`bg-[hsl(var(--success))]`,label:`running`,pulse:!0,badge:`bg-[hsl(var(--success))]/15 text-[hsl(var(--success))]`},completed:{led:`bg-[hsl(var(--success))]`,label:`done`,pulse:!1,badge:`bg-muted text-muted-foreground`},failed:{led:`bg-destructive`,label:`failed`,pulse:!1,badge:`bg-destructive/15 text-destructive`},timeout:{led:`bg-[hsl(var(--warning))]`,label:`timeout`,pulse:!1,badge:`bg-amber-500/15 text-amber-500`},stopped:{led:`bg-muted-foreground`,label:`stopped`,pulse:!1,badge:`bg-muted text-muted-foreground`}};function yl({agent:e,isLeader:t}){let n=vl[e.status],r=e.status===`running`,i=Date.now()-e.startedAt,a=[...e.toolLog.slice(0,8)].reverse();return(0,X.jsxs)(`div`,{className:Y(`rounded-xl border p-4 space-y-3`,r?`border-primary/20 bg-primary/[0.02]`:`border-border bg-card`,t&&`ring-2 ring-amber-500/30`),children:[(0,X.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`span`,{className:Y(`led`,n.led,n.pulse&&`led-pulse`,`mt-0.5`)}),(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(`span`,{className:`text-sm font-semibold`,children:e.name}),t&&(0,X.jsx)(be,{className:`h-3.5 w-3.5 text-amber-500`,"aria-label":`leader`}),e.extensions>0&&(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded-full bg-amber-500/15 text-[10px] text-amber-600 dark:text-amber-400 font-medium`,children:[(0,X.jsx)(ze,{className:`h-2.5 w-2.5`}),`×`,e.extensions]})]}),(0,X.jsx)(`span`,{className:Y(`inline-block mt-0.5 px-1.5 py-0.5 rounded text-[10px] font-medium`,n.badge),children:n.label})]})]}),(0,X.jsx)(`div`,{className:`flex items-center gap-1 text-[10px] text-muted-foreground`,children:t&&(0,X.jsx)(`span`,{className:`text-[9px] bg-amber-500/15 text-amber-600 dark:text-amber-400 px-1.5 py-0.5 rounded`,children:`LEADER`})})]}),e.description&&(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground leading-relaxed line-clamp-2`,children:e.description}),e.budgetWarning&&(0,X.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg bg-amber-500/10 border border-amber-500/20 text-xs`,children:[(0,X.jsx)(ze,{className:`h-3.5 w-3.5 text-amber-500 shrink-0`}),(0,X.jsxs)(`span`,{className:`text-amber-600 dark:text-amber-400`,children:[`⚡ hitting `,(0,X.jsx)(`strong`,{children:e.budgetWarning.kind}),` limit (`,e.budgetWarning.used,`/`,e.budgetWarning.limit,`) — extending`]})]}),e.failureReason&&(0,X.jsx)(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg bg-destructive/10 border border-destructive/20 text-xs`,children:(0,X.jsxs)(`span`,{className:`text-destructive font-medium`,children:[`✗ `,e.failureReason]})}),(0,X.jsxs)(`div`,{className:`grid grid-cols-4 gap-2`,children:[(0,X.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-2 py-1.5 text-center`,children:[(0,X.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:`Iters`}),(0,X.jsx)(`div`,{className:`text-xs font-mono font-semibold tabular-nums`,children:e.iteration})]}),(0,X.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-2 py-1.5 text-center`,children:[(0,X.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:`Tools`}),(0,X.jsx)(`div`,{className:`text-xs font-mono font-semibold tabular-nums`,children:e.toolCalls})]}),(0,X.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-2 py-1.5 text-center`,children:[(0,X.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:`Cost`}),(0,X.jsx)(`div`,{className:`text-xs font-mono font-semibold tabular-nums`,children:gl(e.costUsd)})]}),(0,X.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-2 py-1.5 text-center`,children:[(0,X.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:`Elapsed`}),(0,X.jsx)(`div`,{className:`text-xs font-mono font-semibold tabular-nums`,children:_l(i)})]})]}),(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Activity (12 bins)`}),(0,X.jsx)(cc,{bins:e.sparklineBins,className:`font-mono text-[9px]`})]}),(0,X.jsx)(zi,{pct:e.ctxPct,tokens:e.ctxTokens,maxTokens:e.maxContext})]}),(e.provider||e.model)&&(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] text-muted-foreground`,children:[(0,X.jsx)(c,{className:`h-3 w-3`}),(0,X.jsxs)(`span`,{className:`font-mono`,children:[e.provider??`?`,`/`,e.model??`?`]})]}),(e.currentTool||e.lastTool)&&(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] text-muted-foreground`,children:[(0,X.jsx)(He,{className:Y(`h-3 w-3`,r&&`animate-pulse text-primary`)}),(0,X.jsx)(`span`,{className:`font-mono`,children:e.currentTool??e.lastTool}),r&&(0,X.jsx)(L,{className:`h-3 w-3 animate-spin`})]}),e.partialText&&r&&(0,X.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 p-2`,children:[(0,X.jsx)(`div`,{className:`text-[9px] text-muted-foreground uppercase tracking-wider mb-1`,children:`Streaming output`}),(0,X.jsx)(`pre`,{className:`text-[10px] font-mono text-foreground/80 whitespace-pre-wrap line-clamp-3 leading-relaxed`,children:e.partialText})]}),a.length>0&&(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(`div`,{className:`text-[9px] text-muted-foreground uppercase tracking-wider`,children:`Recent tools`}),(0,X.jsx)(`div`,{className:`space-y-0.5`,children:a.map((e,t)=>(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] font-mono`,children:[(0,X.jsx)(`span`,{className:Y(`shrink-0`,e.ok?`text-[hsl(var(--success))]`:`text-destructive`),children:e.ok?`✓`:`✗`}),(0,X.jsx)(`span`,{className:`text-muted-foreground truncate`,children:e.name}),(0,X.jsx)(`span`,{className:`ml-auto tabular-nums text-muted-foreground shrink-0`,children:e.durationMs>=1e3?`${(e.durationMs/1e3).toFixed(1)}s`:`${e.durationMs}ms`})]},t))})]}),e.finalText&&!r&&(0,X.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 p-2`,children:[(0,X.jsx)(`div`,{className:`text-[9px] text-muted-foreground uppercase tracking-wider mb-1`,children:`Final output`}),(0,X.jsx)(`pre`,{className:`text-[10px] font-mono text-foreground/80 whitespace-pre-wrap line-clamp-4 leading-relaxed`,children:e.finalText})]})]})}var bl=320;function xl(e){return e<=0?`$0`:e>=.01?`$${e.toFixed(3)}`:`$${e.toFixed(5)}`.replace(/0+$/,``).replace(/\.$/,``)}function Sl(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e)}function Cl(e,t){let n=Array.from(e.values());return n.sort((e,n)=>{if(e.id===t)return-1;if(n.id===t)return 1;let r=e.status===`running`?0:1,i=n.status===`running`?0:1;return r===i?e.startedAt-n.startedAt:r-i}),n}function wl(){let e=G(e=>e.inspectorOpen),t=G(e=>e.inspectorTab),n=G(e=>e.toggleInspector),r=G(e=>e.setInspectorOpen),i=G(e=>e.setInspectorTab),a=K(e=>e.agents),o=K(e=>e.leaderId),s=K(e=>e.fleetTokensIn),c=K(e=>e.fleetTokensOut),l=K(e=>e.fleetConcurrency),u=K(e=>e.fleetConcurrencyMax),d=K(e=>e.eventTimeline),f=(0,B.useMemo)(()=>Cl(a,o),[a,o]),p=f.filter(e=>e.status===`running`).length,m=f.reduce((e,t)=>e+t.costUsd,0),h=f.length,[g,_]=(0,B.useState)(null),v=(0,B.useMemo)(()=>g?a.get(g)??f[0]??null:f[0]??null,[g,f,a]),y=()=>i(`fleet`),b=()=>i(`agents`);return(0,X.jsxs)(`div`,{className:`shrink-0 border-t bg-card flex flex-col`,children:[(0,X.jsxs)(`button`,{type:`button`,onClick:n,className:Y(`group w-full flex items-center justify-between gap-2 px-3 h-7 text-[11px]`,`text-muted-foreground hover:text-foreground hover:bg-accent/40 transition-colors`),title:e?`Hide inspector panel`:`Show inspector panel (Fleet / Agents)`,children:[(0,X.jsxs)(`span`,{className:`flex items-center gap-2 min-w-0`,children:[e?(0,X.jsx)(ut,{className:`h-3.5 w-3.5 shrink-0`}):(0,X.jsx)(_e,{className:`h-3.5 w-3.5 shrink-0`}),(0,X.jsx)(`span`,{className:`font-medium uppercase tracking-wider`,children:`Inspector`}),h>0&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`opacity-40`,children:`·`}),(0,X.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,X.jsx)(`span`,{className:Y(`h-1.5 w-1.5 rounded-full`,p>0?`bg-emerald-500 animate-pulse`:`bg-muted-foreground/50`)}),(0,X.jsxs)(`span`,{className:`tabular-nums`,children:[p,`/`,h]})]}),(0,X.jsx)(`span`,{className:`opacity-40 hidden sm:inline`,children:`·`}),(0,X.jsxs)(`span`,{className:`tabular-nums font-mono hidden sm:inline`,children:[`↓`,Sl(s),` ↑`,Sl(c),` · `,xl(m)]})]})]}),(0,X.jsxs)(`span`,{className:`flex items-center gap-1 shrink-0 opacity-70 group-hover:opacity-100`,children:[(0,X.jsx)(R,{className:`h-3 w-3`}),(0,X.jsx)(Wt,{className:`h-3 w-3`})]})]}),(0,X.jsx)(`div`,{className:`overflow-hidden transition-[height] duration-300 ease-[cubic-bezier(0.16,1,0.3,1)]`,style:{height:e?bl:0},children:(0,X.jsxs)(`div`,{className:`flex flex-col`,style:{height:bl},children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1 px-2 h-8 border-b bg-muted/30 shrink-0`,children:[(0,X.jsx)(Tl,{active:t===`fleet`,onClick:y,icon:(0,X.jsx)(R,{className:`h-3.5 w-3.5`}),label:`Fleet`,count:h,running:p}),(0,X.jsx)(Tl,{active:t===`agents`,onClick:b,icon:(0,X.jsx)(Wt,{className:`h-3.5 w-3.5`}),label:`Agents`,count:h}),(0,X.jsx)(`div`,{className:`flex-1`}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>r(!1),className:`p-1 rounded hover:bg-muted transition-colors text-muted-foreground hover:text-foreground`,"aria-label":`Collapse inspector panel`,title:`Collapse (Esc)`,children:(0,X.jsx)(ut,{className:`h-4 w-4`})})]}),(0,X.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto`,children:t===`fleet`?(0,X.jsx)(El,{fleetList:f,leaderId:o,selectedAgentId:g,runningCount:p,fleetConcurrency:l,fleetConcurrencyMax:u,fleetTokensIn:s,fleetTokensOut:c,totalCost:m,eventTimeline:d,onSelectAgent:e=>{_(e.id),b()}}):(0,X.jsx)(Dl,{fleetList:f,selectedAgent:v,leaderId:o,selectedAgentId:v?.id??null,onSelectAgent:_})})]})})]})}function Tl({active:e,onClick:t,icon:n,label:r,count:i,running:a}){return(0,X.jsxs)(`button`,{type:`button`,onClick:t,className:Y(`flex items-center gap-1.5 px-2.5 h-6 rounded-md text-[11px] font-medium transition-colors`,e?`bg-background text-foreground shadow-sm ring-1 ring-border`:`text-muted-foreground hover:text-foreground hover:bg-background/60`),children:[n,r,i>0&&(0,X.jsx)(`span`,{className:Y(`tabular-nums text-[10px] px-1 rounded-full`,a&&a>0?`bg-emerald-500/15 text-emerald-600 dark:text-emerald-400`:`bg-muted text-muted-foreground`),children:a===void 0?i:`${a}/${i}`})]})}function El({fleetList:e,leaderId:t,selectedAgentId:n,runningCount:r,fleetConcurrency:i,fleetConcurrencyMax:a,fleetTokensIn:o,fleetTokensOut:s,totalCost:c,eventTimeline:l,onSelectAgent:u}){return(0,X.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-1.5 border-b text-[11px] text-muted-foreground shrink-0`,children:[(0,X.jsxs)(`span`,{className:`flex items-center gap-1`,children:[r>0&&(0,X.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-emerald-500 animate-pulse`}),(0,X.jsxs)(`span`,{className:`tabular-nums`,children:[r,` running · `,e.length,` total`]})]}),(0,X.jsx)(al,{current:i,max:a,showLabel:!0}),(0,X.jsx)(`div`,{className:`flex-1`}),(0,X.jsxs)(`span`,{className:`tabular-nums font-mono`,children:[`↓`,Sl(o),` ↑`,Sl(s),` · `,xl(c)]})]}),e.length===0?(0,X.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-8 text-muted-foreground`,children:[(0,X.jsx)(Wt,{className:`h-8 w-8 mb-2 opacity-20`}),(0,X.jsx)(`p`,{className:`text-xs font-medium`,children:`No agents active`}),(0,X.jsx)(`p`,{className:`text-[11px] mt-0.5`,children:`Agents appear here when the fleet is active.`})]}):(0,X.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-1.5`,children:e.map(e=>(0,X.jsx)(ml,{agent:e,isSelected:n===e.id,isLeader:e.id===t,onClick:()=>u(e)},e.id))}),l.length>0&&(0,X.jsx)(`div`,{className:`border-t px-3 py-1.5 shrink-0`,children:(0,X.jsx)(cl,{events:l,max:4})})]})}function Dl({fleetList:e,selectedAgent:t,leaderId:n,selectedAgentId:r,onSelectAgent:i}){if(e.length===0)return(0,X.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-8 text-muted-foreground`,children:[(0,X.jsx)(R,{className:`h-8 w-8 mb-2 opacity-20`}),(0,X.jsx)(`p`,{className:`text-xs font-medium`,children:`No agents active`})]});if(!t)return null;let a=Math.max(0,e.findIndex(e=>e.id===r));return(0,X.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,X.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-3`,children:(0,X.jsx)(`div`,{className:`max-w-2xl mx-auto`,children:(0,X.jsx)(yl,{agent:t,isLeader:t.id===n})})}),(0,X.jsx)(`div`,{className:`border-t px-2 py-1.5 shrink-0`,children:(0,X.jsx)(`div`,{className:`flex items-center gap-1 overflow-x-auto pb-0.5`,children:e.map((e,n)=>(0,X.jsxs)(`button`,{type:`button`,onClick:()=>i(e.id),className:Y(`shrink-0 flex items-center gap-1.5 px-2 py-1 rounded-md text-[10px] transition-colors`,e.id===t?.id?`bg-primary/15 text-primary ring-1 ring-primary/40`:`hover:bg-accent text-muted-foreground`),title:`${e.name}${n===a?` (selected)`:``}`,children:[(0,X.jsx)(`span`,{className:Y(`h-1.5 w-1.5 rounded-full shrink-0`,e.status===`running`?`bg-emerald-500 animate-pulse`:e.status===`failed`?`bg-destructive`:`bg-muted-foreground/50`)}),(0,X.jsx)(`span`,{className:`truncate max-w-[8rem]`,children:e.name})]},e.id))})})]})}function Ol(){let{theme:e}=Ti(),{currentView:t,sidebarOpen:n,toggleSidebar:r,setSearchOpen:i,setSidebarOpen:a,setCurrentView:o,setInspectorTab:s,toggleInspector:c}=G(),l=H(e=>e.isLoading),u=W(e=>e.iteration),d=W(e=>e.projectName),f=W(e=>e.session?.title),p=W(e=>e.session?.id),m=G(e=>p?e.sessionNicknames[p]:void 0);return(0,B.useEffect)(()=>{let e=e=>{let{filePath:t}=e.detail,n=V(U.getState().wsUrl);n&&n.send({type:`files.read`,payload:{filePath:t}})};return window.addEventListener(`wrongstack:open-file`,e),()=>window.removeEventListener(`wrongstack:open-file`,e)},[]),(0,B.useEffect)(()=>{let e=e=>{let{filePath:t}=e.detail,n=q.getState().openFiles.find(e=>e.path===t);if(!n)return;let r=V(U.getState().wsUrl);r&&r.send({type:`files.write`,payload:{filePath:t,content:n.content}})};return window.addEventListener(`wrongstack:save-file`,e),()=>window.removeEventListener(`wrongstack:save-file`,e)},[]),(0,B.useEffect)(()=>{if(typeof window>`u`)return;let e=window.matchMedia(`(max-width: 768px)`),t=()=>{e.matches&&G.getState().sidebarOpen&&a(!1)};return t(),e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[a]),Si(),(0,B.useEffect)(()=>{let e=[];if(l){let t=u?` iter ${u.index}${u.max?`/${u.max}`:``}`:``;e.push(`●${t}`)}let t=m?.trim()||f?.trim(),n=d?.trim();t&&e.push(t),n&&e.push(n),e.length===0&&e.push(n||`AI Agent`);let r=e.filter(Boolean).join(` · `);return document.title=r,()=>{document.title=d||`AI Agent`}},[l,u,d,f,m]),(0,B.useEffect)(()=>{let e=e=>{let t=e.target,n=t?.tagName?.toLowerCase(),a=n===`input`||n===`textarea`||t?.isContentEditable,o=e.ctrlKey||e.metaKey;if(o&&e.key===`\\`){e.preventDefault(),r();return}if(o&&!e.shiftKey&&!e.altKey&&e.key>=`1`&&e.key<=String(ki.length)){let t=ki[Number(e.key)-1];if(t){e.preventDefault(),Oi(t);return}}if(o&&e.key.toLowerCase()===`f`){e.preventDefault(),i(!0);return}if(o&&e.key.toLowerCase()===`/`){e.preventDefault(),document.querySelector(`textarea`)?.focus();return}if(o&&!a&&(e.key.toLowerCase()===`l`?(e.preventDefault(),H.getState().clearMessages(),V(U.getState().wsUrl)?.clearContext?.()):e.key.toLowerCase()===`n`?(e.preventDefault(),V(U.getState().wsUrl)?.newSession?.(),G.getState().setCurrentView(`chat`)):e.key.toLowerCase()===`e`&&(e.preventDefault(),xa())),o&&e.shiftKey&&e.key.toLowerCase()===`d`&&(e.preventDefault(),G.getState().toggleCompactMode()),o&&e.shiftKey&&e.key.toLowerCase()===`m`){e.preventDefault();let t=G.getState();t.inspectorOpen&&t.inspectorTab===`fleet`?c():(s(`fleet`),t.inspectorOpen||c())}if(o&&e.shiftKey&&e.key.toLowerCase()===`a`){e.preventDefault();let t=G.getState();t.inspectorOpen&&t.inspectorTab===`agents`?c():(s(`agents`),t.inspectorOpen||c())}if(e.key===`Escape`&&!o&&G.getState().inspectorOpen&&G.getState().setInspectorOpen(!1),!a&&!o&&!e.altKey){let t=Array.from(document.querySelectorAll(`[data-message-id]`));if(t.length===0)return;let n=document.querySelector(`[data-message-id][data-focused="true"]`),r=n?t.indexOf(n):-1,i=e=>{for(let e of t)e.removeAttribute(`data-focused`);e.setAttribute(`data-focused`,`true`),e.scrollIntoView({behavior:`smooth`,block:`center`})};if(e.key===`j`||e.key===`ArrowDown`){let n=t[Math.min(t.length-1,Math.max(0,r+1))];n&&(e.preventDefault(),i(n));return}if(e.key===`k`||e.key===`ArrowUp`){let n=t[Math.max(0,r<=0?0:r-1)];n&&(e.preventDefault(),i(n));return}if(e.key===`g`&&!e.shiftKey){e.preventDefault(),i(z(t[0]));return}if(e.key===`G`||e.key===`g`&&e.shiftKey){e.preventDefault(),i(z(t[t.length-1]));return}if(e.key===`Escape`&&n){e.preventDefault(),n.removeAttribute(`data-focused`);return}if(e.key===`c`&&n){let t=n.querySelector(`.markdown-content`)?.innerText??n.innerText;t&&(navigator.clipboard?.writeText(t).catch(()=>{}),e.preventDefault());return}}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r,i]),(0,X.jsxs)(`div`,{className:Y(`flex h-screen`,e),children:[t!==`setup`&&(0,X.jsx)(Ai,{}),n&&t!==`setup`&&(0,X.jsx)(Mc,{}),(0,X.jsxs)(`main`,{className:`flex-1 flex flex-col overflow-hidden`,children:[t!==`setup`&&(0,X.jsx)(is,{}),t===`chat`&&(0,X.jsxs)(X.Fragment,{children:[p&&(0,X.jsx)(`div`,{className:`px-4 pt-2`,children:(0,X.jsx)(Yc,{sessionId:p})}),(0,X.jsx)(Lo,{}),(0,X.jsx)(wl,{})]}),t===`settings`&&(0,X.jsx)(xs,{}),t===`setup`&&(0,X.jsx)(Ts,{}),t===`autophase`&&(0,X.jsx)(va,{onClose:()=>o(`chat`)}),t===`agents`&&(0,X.jsx)(`div`,{className:`flex-1 flex flex-col overflow-hidden`,children:(0,X.jsx)(Qi,{})}),t===`agentflow`&&(0,X.jsx)(`div`,{className:`flex-1 flex flex-col overflow-hidden`,children:(0,X.jsx)(Ys,{})}),t===`fleet`&&(0,X.jsx)(`div`,{className:`flex-1 flex flex-col overflow-hidden`,children:(0,X.jsx)(hl,{isOverlay:!1})}),t===`sessions`&&(0,X.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:(0,X.jsx)(js,{})}),t===`files`&&(0,X.jsx)(Ho,{})]}),(0,X.jsx)(es,{}),(0,X.jsx)(rs,{}),(0,X.jsx)(Ca,{}),(0,X.jsx)(Ns,{}),(0,X.jsx)(ss,{}),(0,X.jsx)(Tr,{})]})}function kl(){return(0,X.jsx)(as,{children:(0,X.jsx)(wi,{defaultTheme:`system`,children:(0,X.jsx)(Ol,{})})})}Fn.createRoot(z(document.getElementById(`root`))).render((0,X.jsx)(B.StrictMode,{children:(0,X.jsx)(kl,{})}));