pi-kot 0.1.15 → 0.1.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # pi-kot v0.1.15
1
+ # pi-kot v0.1.16
2
2
 
3
3
  Browser UI for the [pi coding agent](https://pi.dev).
4
4
  Self-hosted React workbench: streaming chat, session tree, file browser, terminal, git panel.
@@ -307,7 +307,7 @@ l0,-`+(t+144)+`c-2,-159.3,-10,-310.7,-24,-454c-53.3,-528,-210,-949.7,
307
307
  `),u=l.split(`
308
308
  `).find(e=>e.trim().length>0)??``,d=ax(i,a),f=lx(i);return(0,M.jsxs)(`div`,{className:`tool-timeline-node`,children:[(0,M.jsx)(`span`,{className:`tool-timeline-icon${c?` running`:s?` error`:` success`}`,"aria-hidden":`true`,children:f}),(0,M.jsxs)(`div`,{className:`tool-timeline-content`,children:[(0,M.jsxs)(`div`,{className:`tool-timeline-row`,children:[(0,M.jsx)(`span`,{className:`tool-timeline-name`,children:i}),d&&(0,M.jsx)(`span`,{className:`tool-timeline-arg`,title:d,children:d}),c&&(0,M.jsx)(`span`,{className:`tool-timeline-running`,"aria-label":`running`,children:`running…`}),!c&&l.length>0&&(0,M.jsx)(`button`,{type:`button`,className:`tool-timeline-details-btn`,onClick:()=>r(e=>!e),"aria-expanded":n,"aria-label":n?`Hide details`:`Show details`,children:n?`hide`:`details`})]}),!c&&!n&&u.length>0&&(0,M.jsxs)(`div`,{className:`tool-timeline-output-preview`,title:u,children:[s?`✖ `:`✓ `,u]}),n&&(0,M.jsxs)(`div`,{className:`tool-timeline-details`,children:[o.length>2&&(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`div`,{className:`tool-timeline-section-label`,children:`input`}),(0,M.jsx)(`pre`,{className:`tool-timeline-code`,children:o.length>2e3?o.slice(0,2e3)+`
309
309
  …(truncated)`:o})]}),l.length>0&&(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`div`,{className:`tool-timeline-section-label`,children:s?`error`:`output`}),(0,M.jsx)(`pre`,{className:`tool-timeline-code`,children:l.length>4e3?l.slice(0,4e3)+`
310
- …(truncated)`:l})]})]})]})]})}function fx({entries:e}){let[t,n]=(0,b.useState)(!1),r=e.filter(e=>e.kind===`tool`),i=r.length,a=r.some(e=>e.result?.isError===!0),o=[...new Set(r.map(e=>String(e.block.name??`tool`)))],s=o.slice(0,4).join(` · `)+(o.length>4?` · …`:``);return(0,M.jsxs)(`details`,{open:t,className:`tool-timeline`,style:{marginLeft:0},children:[(0,M.jsxs)(`summary`,{className:`tool-timeline-header`,onClick:e=>{e.preventDefault(),n(e=>!e)},"aria-label":`${i} tool ${i===1?`call`:`calls`}: ${s}`,children:[(0,M.jsx)(`span`,{className:`tool-timeline-chevron`,"aria-hidden":`true`,children:t?`▾`:`▸`}),(0,M.jsxs)(`span`,{className:`tool-timeline-batch-label`,children:[`↳ `,i,` `,i===1?`tool`:`tools`]}),(0,M.jsx)(`span`,{className:`tool-timeline-batch-preview`,children:s}),a&&(0,M.jsx)(`span`,{className:`tool-timeline-badge error`,"aria-label":`error`,children:`error`})]}),(0,M.jsx)(`div`,{className:`tool-timeline-track`,children:e.map((e,t)=>e.kind===`thinking`?(0,M.jsx)(ux,{text:e.block.thinking??``},t):(0,M.jsx)(dx,{block:e.block,result:e.result},t))})]})}function px({block:e}){let t=e.type;return t===`text`&&typeof e.text==`string`?(0,M.jsx)(Ib,{text:e.text}):t===`thinking`&&typeof e.thinking==`string`?(0,M.jsx)(ux,{text:e.thinking}):null}function mx({segment:e}){if(e.kind===`assistant`&&e.content!==void 0){let t=e.content;return(0,M.jsx)(`div`,{className:`assistant-blocks`,children:t.map((e,t)=>(0,M.jsx)(px,{block:e},t))})}let t=e.entries;if(!t)return null;let n=t.find(e=>e.kind===`tool`),r=t.some(e=>e.kind===`thinking`);return t.filter(e=>e.kind===`tool`).length===1&&!r&&n!==void 0?(0,M.jsx)(`div`,{className:`tool-timeline`,children:(0,M.jsx)(dx,{block:n.block,result:n.result})}):(0,M.jsx)(fx,{entries:t})}function hx({text:e,isSteer:t,images:n}){let[r,i]=(0,b.useState)(!1),[a,o]=(0,b.useState)(!1),s=(0,b.useRef)(null);return(0,b.useEffect)(()=>{let e=s.current;if(!e)return;let t=()=>{r||o(e.scrollHeight>e.clientHeight)};t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[e,r]),(0,M.jsx)(`div`,{className:`message-row user`,children:(0,M.jsxs)(`div`,{className:`message-bubble user`,children:[t&&(0,M.jsx)(`span`,{className:`steer-tag`,children:`steer`}),n!==void 0&&n.length>0&&(0,M.jsx)(cx,{images:n}),(0,M.jsx)(`div`,{ref:s,style:{overflow:`hidden`,transition:`max-height 0.25s ease`,maxHeight:r?`2000px`:`4em`,...r?{}:{display:`-webkit-box`,WebkitLineClamp:2,WebkitBoxOrient:`vertical`}},children:e}),a&&(0,M.jsx)(`div`,{onClick:()=>i(e=>!e),style:{marginTop:6,fontSize:12,color:`var(--accent-text)`,cursor:`pointer`,userSelect:`none`},children:r?`▲ Show less`:`▼ Show more`})]})})}function gx({getText:e}){let[t,n]=(0,b.useState)(!1),r=()=>{let t=e();if(t.length===0)return;let r=navigator.clipboard?.writeText?.bind(navigator.clipboard);r===void 0?i(t):r(t).then(()=>{n(!0),window.setTimeout(()=>n(!1),1200)}).catch(()=>i(t))},i=e=>{try{let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t),t.select(),document.execCommand(`copy`),document.body.removeChild(t),n(!0),window.setTimeout(()=>n(!1),1200)}catch{}};return(0,M.jsx)(`button`,{type:`button`,onClick:e=>{e.preventDefault(),e.stopPropagation(),r()},className:`copy-msg-btn`,title:`Copy message`,"aria-label":`Copy message`,children:t?(0,M.jsx)(mn,{size:12}):(0,M.jsx)(bn,{size:12})})}function _x({msg:e,sessionId:t}){let[n,r]=(0,b.useState)(e.output.length<=500),i=e._pendingExec===!0,a=i&&e.exitCode===void 0,o=e.output.length>0,s=(0,b.useRef)(a);s.current=a;let c,l;return a?(c=`⟳`,l=`running`):e.cancelled?(c=`⛔`,l=`cancelled`):e.exitCode===0?(c=`✅`,l=`success`):(c=`❌`,l=`exit ${e.exitCode??`?`}`),(0,M.jsx)(`div`,{className:`message-row user`,children:(0,M.jsxs)(`div`,{className:`message-bubble user`,style:{borderLeft:`3px solid var(--accent-text)`,maxWidth:`100%`},children:[(0,M.jsxs)(`div`,{role:`button`,tabIndex:0,onClick:()=>o&&r(e=>!e),onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),o&&r(e=>!e))},style:{display:`flex`,alignItems:`center`,gap:6,fontSize:12,cursor:o?`pointer`:`default`,userSelect:`none`},children:[o&&(0,M.jsx)(`span`,{style:{fontSize:9,opacity:.5,width:12,textAlign:`center`,flexShrink:0},children:n?`▾`:`▸`}),(0,M.jsxs)(`span`,{style:{fontFamily:`monospace`,fontWeight:600},children:[`$ `,e.command]}),(0,M.jsxs)(`span`,{style:{fontSize:10,opacity:.65},children:[c,` `,l]}),e.excludeFromContext&&(0,M.jsx)(`span`,{style:{fontSize:9,padding:`0 4px`,borderRadius:3,background:`var(--bg-subtle)`,opacity:.5},children:`local only`}),i&&a&&(0,M.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),Je(t)},style:{marginLeft:`auto`,background:`var(--bg-glass-active)`,border:`1px solid var(--border)`,borderRadius:`var(--radius-sm)`,padding:`1px 6px`,fontSize:10,cursor:`pointer`,color:`var(--text-secondary)`},children:`cancel`}),o&&!n&&!a&&(0,M.jsx)(`span`,{style:{fontSize:9,opacity:.4,marginLeft:`auto`},children:e.output.length<1024?`${e.output.length} B`:`${(e.output.length/1024).toFixed(1)} KB`})]}),a&&(0,M.jsxs)(`pre`,{style:{fontSize:11,fontFamily:`monospace`,whiteSpace:`pre-wrap`,wordBreak:`break-all`,margin:`6px 0 0`,maxHeight:400,overflow:`auto`,opacity:.85},children:[e.output||``,(0,M.jsx)(`span`,{style:{animation:`blink 1s step-end infinite`},children:`█`})]}),o&&!a&&n&&(0,M.jsx)(`pre`,{style:{fontSize:11,fontFamily:`monospace`,whiteSpace:`pre-wrap`,wordBreak:`break-all`,margin:`6px 0 0`,maxHeight:400,overflow:`auto`},children:e.truncated?e.output+`
310
+ …(truncated)`:l})]})]})]})]})}function fx({entries:e}){let[t,n]=(0,b.useState)(!1),r=e.filter(e=>e.kind===`tool`),i=r.length,a=r.some(e=>e.result?.isError===!0),o=[...new Set(r.map(e=>String(e.block.name??`tool`)))],s=o.slice(0,4).join(` · `)+(o.length>4?` · …`:``);return(0,M.jsxs)(`details`,{open:t,className:`tool-timeline`,style:{marginLeft:0},children:[(0,M.jsxs)(`summary`,{className:`tool-timeline-header`,onClick:e=>{e.preventDefault(),n(e=>!e)},"aria-label":`${i} tool ${i===1?`call`:`calls`}: ${s}`,children:[(0,M.jsx)(`span`,{className:`tool-timeline-chevron`,"aria-hidden":`true`,children:t?`▾`:`▸`}),(0,M.jsxs)(`span`,{className:`tool-timeline-batch-label`,children:[`↳ `,i,` `,i===1?`tool`:`tools`]}),(0,M.jsx)(`span`,{className:`tool-timeline-batch-preview`,children:s}),a&&(0,M.jsx)(`span`,{className:`tool-timeline-badge error`,"aria-label":`error`,children:`error`})]}),(0,M.jsx)(`div`,{className:`tool-timeline-track`,children:e.map((e,t)=>e.kind===`thinking`?(0,M.jsx)(ux,{text:e.block.thinking??``},t):(0,M.jsx)(dx,{block:e.block,result:e.result},t))})]})}function px({block:e}){let t=e.type;return t===`text`&&typeof e.text==`string`?(0,M.jsx)(Ib,{text:e.text}):t===`thinking`&&typeof e.thinking==`string`?(0,M.jsx)(ux,{text:e.thinking}):null}function mx({segment:e}){if(e.kind===`assistant`&&e.content!==void 0){let t=e.content;return(0,M.jsx)(`div`,{className:`assistant-blocks`,children:t.map((e,t)=>(0,M.jsx)(px,{block:e},t))})}let t=e.entries;if(!t)return null;let n=t.find(e=>e.kind===`tool`),r=t.some(e=>e.kind===`thinking`);return t.filter(e=>e.kind===`tool`).length===1&&!r&&n!==void 0?(0,M.jsx)(`div`,{className:`tool-timeline`,children:(0,M.jsx)(dx,{block:n.block,result:n.result})}):(0,M.jsx)(fx,{entries:t})}function hx({text:e,isSteer:t,images:n}){let[r,i]=(0,b.useState)(!1),[a,o]=(0,b.useState)(!1),s=(0,b.useRef)(null);return(0,b.useEffect)(()=>{let e=s.current;if(!e)return;let t=()=>{r||o(e.scrollHeight>e.clientHeight)};t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[e,r]),(0,M.jsx)(`div`,{className:`message-row user`,children:(0,M.jsxs)(`div`,{className:`message-bubble user`,children:[t&&(0,M.jsx)(`span`,{className:`steer-tag`,children:`steer`}),n!==void 0&&n.length>0&&(0,M.jsx)(cx,{images:n}),(0,M.jsx)(`div`,{ref:s,style:{overflow:`hidden`,transition:`max-height 0.25s ease`,maxHeight:r?`2000px`:`4em`,...r?{}:{display:`-webkit-box`,WebkitLineClamp:2,WebkitBoxOrient:`vertical`}},children:e}),a&&(0,M.jsx)(`div`,{onClick:()=>i(e=>!e),style:{marginTop:6,fontSize:12,color:`var(--accent-text)`,cursor:`pointer`,userSelect:`none`},children:r?`▲ Show less`:`▼ Show more`})]})})}function gx({getText:e}){let[t,n]=(0,b.useState)(!1),r=()=>{let t=e();if(t.length===0)return;let r=navigator.clipboard?.writeText?.bind(navigator.clipboard);r===void 0?i(t):r(t).then(()=>{n(!0),window.setTimeout(()=>n(!1),1200)}).catch(()=>i(t))},i=e=>{try{let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t),t.select(),document.execCommand(`copy`),document.body.removeChild(t),n(!0),window.setTimeout(()=>n(!1),1200)}catch{}};return(0,M.jsx)(`button`,{type:`button`,onClick:e=>{e.preventDefault(),e.stopPropagation(),r()},className:`copy-msg-btn`,title:`Copy message`,"aria-label":`Copy message`,children:t?(0,M.jsx)(mn,{size:12}):(0,M.jsx)(bn,{size:12})})}function _x({msg:e,sessionId:t}){let[n,r]=(0,b.useState)(!1),[i,a]=(0,b.useState)(!1),[o,s]=(0,b.useState)(!1),c=e._pendingExec===!0,l=c&&e.exitCode===void 0,u=e.output.length>0,d=(0,b.useRef)(l);(0,b.useEffect)(()=>{d.current&&!l&&r(!0),d.current=l},[l]),(0,b.useEffect)(()=>{if(!i)return;let e=setTimeout(()=>{a(!1),s(!0)},3e3);return()=>clearTimeout(e)},[i]);let f,p;return e.cancelled?(f=`⛔`,p=`cancelled`):o?(f=`⚠️`,p=`cancel timed out`):i?(f=`⏳`,p=`cancelling…`):l?(f=`⟳`,p=`running`):e.exitCode===0?(f=`✅`,p=`success`):(f=`❌`,p=`exit ${e.exitCode??`?`}`),(0,M.jsx)(`div`,{className:`message-row user`,children:(0,M.jsxs)(`div`,{className:`message-bubble user`,style:{borderLeft:`3px solid var(--accent-text)`,maxWidth:`100%`},children:[(0,M.jsxs)(`div`,{role:u?`button`:void 0,tabIndex:u?0:void 0,onClick:()=>{!l&&u&&r(e=>!e)},onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&!l&&u&&(e.preventDefault(),r(e=>!e))},style:{display:`flex`,alignItems:`center`,gap:6,fontSize:12,cursor:u&&!l?`pointer`:`default`,userSelect:`none`},children:[u&&!l&&(0,M.jsx)(`span`,{style:{fontSize:9,opacity:.5,width:12,textAlign:`center`,flexShrink:0},children:n?`▾`:`▸`}),(0,M.jsxs)(`span`,{style:{fontFamily:`monospace`,fontWeight:600},children:[`$ `,e.command]}),(0,M.jsxs)(`span`,{style:{fontSize:10,opacity:.65},children:[f,` `,p]}),e.excludeFromContext&&(0,M.jsx)(`span`,{style:{fontSize:9,padding:`0 4px`,borderRadius:3,background:`var(--bg-subtle)`,opacity:.5},children:`local only`}),c&&l&&!i&&(0,M.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),a(!0),Je(t)},style:{marginLeft:`auto`,background:`var(--bg-glass-active)`,border:`1px solid var(--border)`,borderRadius:`var(--radius-sm)`,padding:`1px 6px`,fontSize:10,cursor:`pointer`,color:`var(--text-secondary)`},children:`cancel`}),i&&c&&(0,M.jsx)(`span`,{style:{fontSize:9,opacity:.5,marginLeft:`auto`},children:`cancelling…`}),u&&!n&&!l&&(0,M.jsx)(`span`,{style:{fontSize:9,opacity:.4,marginLeft:`auto`},children:e.output.length<1024?`${e.output.length} B`:`${(e.output.length/1024).toFixed(1)} KB`})]}),l&&(0,M.jsxs)(`pre`,{style:{fontSize:11,fontFamily:`monospace`,whiteSpace:`pre-wrap`,wordBreak:`break-all`,margin:`6px 0 0`,maxHeight:400,overflow:`auto`,opacity:.85},children:[e.output||``,(0,M.jsx)(`span`,{style:{animation:`blink 1s step-end infinite`},children:`█`})]}),!l&&u&&n&&(0,M.jsx)(`pre`,{style:{fontSize:11,fontFamily:`monospace`,whiteSpace:`pre-wrap`,wordBreak:`break-all`,margin:`6px 0 0`,maxHeight:400,overflow:`auto`},children:e.truncated?e.output+`
311
311
  …(truncated)`:e.output})]})})}function vx({msg:e}){let t=e?.usage,n=t?.input,r=t?.output,i=t?.cacheRead;return n==null&&r==null&&!(i&&i>0)?null:(0,M.jsxs)(`span`,{style:{display:`flex`,alignItems:`center`,gap:6},children:[n!=null&&(0,M.jsxs)(`span`,{style:{fontSize:10,color:`var(--text-secondary)`},children:[`↑ `,n.toLocaleString(),` in`]}),r!=null&&(0,M.jsxs)(`span`,{style:{fontSize:10,color:`var(--text-secondary)`},children:[`↓ `,r.toLocaleString(),` out`]}),i&&i>0&&(0,M.jsxs)(`span`,{style:{fontSize:10,color:`var(--text-secondary)`},children:[`⚡ `,i.toLocaleString(),` cached`]})]})}function yx({sessionId:e}){let[t,n]=(0,b.useState)(!1);return(0,M.jsx)(`button`,{type:`button`,disabled:t,onClick:async t=>{t.preventDefault(),t.stopPropagation(),n(!0);try{await St(e,`rewind`)}catch{}finally{n(!1)}},className:`copy-msg-btn rewind-btn`,title:`Rewind to checkpoint (requires pi-rewind)`,"aria-label":`Rewind`,children:(0,M.jsx)(xn,{size:12})})}function bx({msg:e,fallbackModel:t,fallbackProvider:n}){let r=(typeof e?.model==`string`?e.model:void 0)??t,i=(typeof e?.provider==`string`?e.provider:void 0)??n;return r?(0,M.jsxs)(`span`,{className:`assistant-msg-model`,children:[i?`${i} / `:``,r]}):null}function xx({sessionId:e,modelName:t,providerName:n}){let r=tn(e=>e.messages),i=tn(t=>t.compactionsBySession[e]??Xt),a=r[0]?.role===`compactionSummary`?i:Xt,o=tn(e=>e.streamState.text),s=tn(e=>e.streamState.isStreaming),c=tn(e=>e.streamState.activeToolName),l=tn(t=>t.queuedBySession[e]),u=tn(e=>e.error),d=tn(e=>e.clearError);tn(e=>e.sendPrompt);let{rewind:f}=zn(),p=Gb(e=>e.stickyUserHeader),m=Gb(e=>e.showTokenUsage),h=(0,b.useRef)(null),g=(0,b.useRef)(!0),_=(0,b.useRef)(0),v=()=>{let e=h.current;if(e===null)return;let t=e.scrollHeight-e.scrollTop-e.clientHeight;g.current=!(e.scrollTop<_.current-1)&&t<=24,_.current=e.scrollTop};(0,b.useLayoutEffect)(()=>{let e=h.current;e===null||r.length===0||(g.current?(e.scrollTop=e.scrollHeight,_.current=e.scrollTop):e.scrollTop=_.current)},[r,o]);let y=(0,b.useMemo)(()=>Kb(r),[r]),x=(0,b.useMemo)(()=>{let{toolResultsById:i}=y,o=[],s=new Map;for(let e of a){let t=s.get(e.insertBeforeIndex)??[];t.push(e),s.set(e.insertBeforeIndex,t)}let c=e=>{let t=s.get(e);if(t!==void 0)for(let e of t)o.push((0,M.jsx)(Bb,{event:e},`compaction-${e.id}`))},l=a.length>0?a[a.length-1]:void 0,u=l?.insertBeforeIndex??0,d=e=>sx(e.content),h=(e,t)=>{let n=[],r=[],a=0,o=()=>{if(r.length===0)return;let e=[...r];r.length=0;let i=`turn-${t}-batch-${a}`;n.push((0,M.jsx)(`div`,{children:(0,M.jsx)(fx,{entries:e})},i)),a+=1};for(let a of e){if(Array.isArray(a.content)){let e=ix(a.content,i);if(e!==void 0){for(let i of e){if(i.kind===`tools`&&i.entries){r.push(...i.entries);continue}o(),n.push((0,M.jsx)(`div`,{className:`message-row assistant`,children:(0,M.jsx)(`div`,{className:`message-bubble assistant`,children:(0,M.jsx)(mx,{segment:i})})},`turn-${t}-seg-${n.length}`))}continue}}o();let e=ox(a.content);e.length>0&&n.push((0,M.jsx)(`div`,{className:`message-row assistant`,children:(0,M.jsx)(`div`,{className:`message-bubble assistant`,children:(0,M.jsx)(Ib,{text:e})})},`turn-${t}-text-${n.length}`))}return o(),n},g=-1,_,v=[],b=()=>{if(_===void 0)return;let r=ox(_.content),i=v.map(e=>ox(e.content)).filter(e=>e.length>0).join(`
312
312
 
313
313
  `),a=_.metadata?.steer===!0,s=v.length>0?v[v.length-1]:void 0;p&&r.length>0?o.push((0,M.jsxs)(`div`,{style:{position:`relative`},children:[(0,M.jsxs)(`div`,{style:{position:`sticky`,top:0,zIndex:10,background:`var(--bg-solid)`,overflowAnchor:`none`},children:[(0,M.jsx)(hx,{text:r,isSteer:a,images:d(_)}),r.length>0&&(0,M.jsxs)(`div`,{className:`assistant-msg-footer user`,children:[(0,M.jsx)(gx,{getText:()=>r}),f&&(0,M.jsx)(yx,{sessionId:e})]}),(0,M.jsx)(`div`,{"aria-hidden":`true`,style:{pointerEvents:`none`,position:`absolute`,left:0,right:0,top:`100%`,zIndex:0,height:12,background:`linear-gradient(to bottom, var(--bg-solid), transparent)`}})]}),v.length>0&&h(v,g),i.length>0&&(0,M.jsxs)(`div`,{className:`assistant-msg-footer`,children:[(0,M.jsx)(gx,{getText:()=>i}),m&&(0,M.jsx)(vx,{msg:s}),(0,M.jsx)(bx,{msg:s,fallbackModel:t,fallbackProvider:n})]})]},`turn-${g}`)):(o.push((0,M.jsx)(`div`,{className:`message-row user`,"data-message-index":g,children:(0,M.jsxs)(`div`,{className:`message-bubble user`,children:[a&&(0,M.jsx)(`span`,{className:`steer-tag`,children:`steer`}),(0,M.jsx)(cx,{images:d(_)}),r]})},`user-${g}`)),r.length>0&&o.push((0,M.jsxs)(`div`,{className:`assistant-msg-footer user`,children:[(0,M.jsx)(gx,{getText:()=>r}),f&&(0,M.jsx)(yx,{sessionId:e})]},`user-${g}-copy`)),v.length>0&&o.push(...h(v,g)),i.length>0&&o.push((0,M.jsxs)(`div`,{className:`assistant-msg-footer`,children:[(0,M.jsx)(gx,{getText:()=>i}),m&&(0,M.jsx)(vx,{msg:s}),(0,M.jsx)(bx,{msg:s,fallbackModel:t,fallbackProvider:n})]},`turn-${g}-copy`))),_=void 0,v.length=0};for(let t=0;t<r.length;t++){let n=r[t];c(t),!qb(y,n)&&n.role!==`compactionSummary`&&(l!==void 0&&t>=1&&t<u||(n.role===`user`?(b(),g=t,_=n):n.role===`assistant`?_===void 0?o.push((0,M.jsx)(`div`,{"data-message-index":t,children:h([n],t)},`orphan-${t}`)):v.push(n):n.role===`bashExecution`&&(b(),o.push((0,M.jsx)(_x,{msg:n,sessionId:e},`bash-${t}`)))))}return b(),c(r.length),o},[r,y,p,a,e,f]);return(0,M.jsxs)(`div`,{className:`messages-container`,style:p?{paddingTop:50}:void 0,children:[u!==void 0&&(0,M.jsxs)(`div`,{onClick:d,className:`error-banner`,children:[u,` — click to dismiss`]}),r.length===0&&!s?(0,M.jsxs)(`div`,{className:`welcome`,children:[(0,M.jsx)(`div`,{className:`welcome-icon`,children:`💬`}),(0,M.jsx)(`div`,{className:`welcome-text`,children:`Send a message to start chatting`}),(0,M.jsx)(`div`,{className:`welcome-hint`,children:`with the pi coding agent`})]}):(0,M.jsx)(`div`,{ref:h,onScroll:v,style:p?{paddingTop:0}:void 0,className:`chat-scroll`,children:(0,M.jsxs)(`div`,{className:`chat-message-list`,children:[x,s&&o.length>0&&(0,M.jsx)(`div`,{className:`message-row assistant streaming-row`,children:(0,M.jsxs)(`div`,{className:`message-bubble assistant streaming-bubble`,children:[c&&(0,M.jsxs)(`div`,{className:`tool-badge`,children:[(0,M.jsx)(`span`,{className:`tool-badge-dot`}),c]}),(0,M.jsxs)(`div`,{className:`streaming-text`,children:[(0,M.jsx)(Ib,{text:o}),(0,M.jsx)(`span`,{className:`streaming-cursor`,children:`▊`})]})]})}),s&&o.length===0&&(0,M.jsx)(`div`,{className:`message-row assistant streaming-row`,children:(0,M.jsx)(`div`,{className:`message-bubble assistant thinking-bubble`,children:c?(0,M.jsxs)(`span`,{className:`thinking-running`,children:[(0,M.jsx)(`span`,{className:`tool-badge-dot`}),`running `,(0,M.jsx)(`code`,{className:`thinking-code`,children:c})]}):(0,M.jsxs)(`span`,{className:`pi-thinking-dots`,"aria-hidden":`true`,children:[(0,M.jsx)(`span`,{children:`.`}),(0,M.jsx)(`span`,{children:`.`}),(0,M.jsx)(`span`,{children:`.`})]})})}),l!==void 0&&(l.steering.length>0||l.followUp.length>0)&&(0,M.jsx)(`div`,{className:`queued-msgs`,children:[...l.steering.map(e=>({kind:`steer`,text:e})),...l.followUp.map(e=>({kind:`followUp`,text:e}))].map((e,t)=>(0,M.jsxs)(`div`,{className:`queued-msg-item`,children:[(0,M.jsx)(`span`,{className:`queued-badge ${e.kind}`,children:e.kind===`steer`?`steer`:`follow-up`}),(0,M.jsx)(`span`,{className:`queued-msg-text`,title:e.text,children:e.text})]},t))})]})})]})}function Sx(e){let t=[];for(let n of e)for(let e of n.models)t.push({value:e.id,provider:n.provider,name:e.name,hasAuth:e.hasAuth,contextWindow:e.contextWindow});return t}function Cx(e,t){let n=t.toLowerCase();if(e.name.toLowerCase().startsWith(n))return 0;if(e.provider.toLowerCase().includes(n))return 1;if(e.name.toLowerCase().includes(n))return 2;if(e.value.toLowerCase().includes(n))return 3}function wx({sessionId:e,selected:t,onSelect:n,onError:r,compact:i}){let[a,o]=(0,b.useState)(!1),[s,c]=(0,b.useState)([]),[l,u]=(0,b.useState)(void 0),[d,f]=(0,b.useState)(``),[p,m]=(0,b.useState)(-1),[h,g]=(0,b.useState)(void 0),_=(0,b.useRef)(null),v=(0,b.useRef)(null),y=(0,b.useRef)(null);(0,b.useEffect)(()=>{(async()=>{try{let[e,t,n]=await Promise.all([Me(),Ie(),Ue()]),r=n.enabledModels;if(r!==null&&r.length>0){let t=new Set(r);c(e.providers.map(e=>({...e,models:e.models.filter(n=>t.has(`${e.provider}/${n.id}`))})).filter(e=>e.models.length>0))}else c(e.providers);let i=t.defaultProvider,a=t.defaultModel;i&&a&&u({provider:i,modelId:a})}catch{}})()},[]),(0,b.useEffect)(()=>{if(!a)return;let e=e=>{_.current&&!_.current.contains(e.target)&&o(!1)};return window.addEventListener(`mousedown`,e),()=>window.removeEventListener(`mousedown`,e)},[a]),(0,b.useEffect)(()=>{a&&(f(``),m(-1))},[a]);let x=(0,b.useMemo)(()=>Sx(s),[s]),S=(0,b.useMemo)(()=>{let e=x.filter(e=>e.hasAuth);if(d.trim().length===0)return e;let t=[];for(let n of e){let e=Cx(n,d);e!==void 0&&t.push({opt:n,score:e})}return t.sort((e,t)=>e.score-t.score),t.map(e=>e.opt)},[x,d]),C=x.find(e=>e.value===t),w=i?(C?.name??l?.modelId??`default`).slice(0,20):C===void 0?l!==void 0&&l.provider.length>0&&l.modelId.length>0?`${l.provider} / ${l.modelId} (default)`:`default model`:`${C.provider} / ${C.name}`,ee=t=>{if(o(!1),t===-1){e===void 0?n(``,``):(g(`default`),Ge(e,l?.provider??``,l?.modelId??``).then(()=>n(``,``)).catch(e=>r(e instanceof Error?e.message:`Failed`)).finally(()=>g(void 0)));return}let i=S[t];if(i!==void 0){if(e===void 0){n(i.value,i.provider);return}g(i.value),Ge(e,i.provider,i.value).then(()=>n(i.value,i.provider)).catch(e=>r(e instanceof Error?e.message:`Failed`)).finally(()=>g(void 0))}},T=(0,b.useCallback)(e=>{e.key===`ArrowDown`?(e.preventDefault(),m(e=>Math.min(e+1,S.length))):e.key===`ArrowUp`?(e.preventDefault(),m(e=>Math.max(e-1,-1))):e.key===`Enter`?(e.preventDefault(),ee(p)):e.key===`Escape`&&(e.preventDefault(),o(!1))},[S,p]);return(0,b.useEffect)(()=>{!a||y.current===null||p<0||y.current.querySelector(`[data-idx="${p}"]`)?.scrollIntoView({block:`nearest`})},[a,p]),(0,M.jsxs)(`div`,{ref:_,className:`model-dropdown`,children:[(0,M.jsxs)(`button`,{type:`button`,className:`model-dropdown-btn`,onClick:()=>o(e=>!e),disabled:h!==void 0,title:w,style:{opacity:h===void 0?1:.6},children:[(0,M.jsx)(`span`,{style:{flex:1,minWidth:0,overflow:`hidden`,textOverflow:`ellipsis`},children:h===void 0?w:`Setting...`}),(0,M.jsx)(`span`,{className:`model-dropdown-chevron`,children:`▾`})]}),a&&(0,M.jsxs)(`div`,{className:`model-dropdown-menu`,style:{left:`auto`,right:0,maxWidth:`calc(100vw - 32px)`},children:[(0,M.jsx)(`input`,{ref:v,type:`text`,value:d,onChange:e=>{f(e.target.value),m(-1)},onKeyDown:T,placeholder:`Search provider or model…`,className:`model-dropdown-search`,autoComplete:`off`,autoCorrect:`off`,autoCapitalize:`none`,spellCheck:!1}),(0,M.jsxs)(`div`,{ref:y,className:`model-dropdown-list`,children:[(0,M.jsxs)(`button`,{"data-idx":-1,onMouseEnter:()=>m(-1),onClick:()=>ee(-1),className:`model-dropdown-item ${p===-1?`model-dropdown-active`:``}`,children:[(0,M.jsx)(`span`,{children:`Use agent default`}),l!==void 0&&l.provider.length>0&&(0,M.jsxs)(`span`,{className:`model-dropdown-item-ctx`,children:[l.provider,` / `,l.modelId]}),t===``&&(0,M.jsx)(`span`,{className:`text-green`,children:`●`})]}),S.length===0?(0,M.jsx)(`div`,{className:`model-dropdown-empty`,children:d?`No models match`:`No models available`}):S.map((e,n)=>(0,M.jsxs)(`button`,{"data-idx":n,onMouseEnter:()=>m(n),onClick:()=>ee(n),className:`model-dropdown-item ${p===n?`model-dropdown-active`:``}`,style:{opacity:e.hasAuth?1:.4,cursor:e.hasAuth?`pointer`:`not-allowed`},title:e.hasAuth?void 0:`No API key for ${e.provider}`,children:[(0,M.jsxs)(`span`,{className:`model-dropdown-item-main`,children:[(0,M.jsx)(`span`,{className:`model-dropdown-provider`,children:e.provider}),(0,M.jsx)(`span`,{className:`model-dropdown-name`,children:e.name})]}),!e.hasAuth&&(0,M.jsx)(`span`,{className:`model-dropdown-warn`,children:`⚠`}),e.value===t&&(0,M.jsx)(`span`,{className:`text-green`,children:`●`})]},e.value))]}),(0,M.jsxs)(`div`,{className:`model-dropdown-footer`,children:[S.length,` of `,x.length,` models — ↑↓ move, Enter pick, Esc close`]})]})]})}function Tx({sessionId:e,showOrch:t,setShowOrch:n,selectedModel:r,onModelSelect:i,onModelError:a}){let o=(0,b.useRef)(null),s=tn(e=>e.streamState.isStreaming),c=tn(e=>e.streamState.activeToolName),l=tn(e=>e.sendPrompt),u=tn(e=>e.sendSteer),d=tn(e=>e.abort),f=tn(e=>e.reloadMessages),[p,m]=(0,b.useState)([]),[h,g]=(0,b.useState)([]),[_,v]=(0,b.useState)(!1),[y,x]=(0,b.useState)(null),S=tn(e=>{if(e.activeProjectId!==void 0)return e.projects.find(t=>t.id===e.activeProjectId)}),[C,w]=(0,b.useState)(),[ee,E]=(0,b.useState)([]),[te,D]=(0,b.useState)(0),ne=(0,b.useRef)(0),O=(()=>{if(s)return;let e=o.current?.value??``;if(e.startsWith(`!!`))return`local`;if(e.startsWith(`!`))return`context`})();(0,b.useEffect)(()=>{if(y===null)return;let e=setTimeout(()=>x(null),2500);return()=>clearTimeout(e)},[y]),(0,b.useEffect)(()=>{if(!e)return;let t=!1;return xt(e).then(e=>{t||g(e.commands.map(e=>({name:`/`+e.invocationName,description:e.description||`Extension command`,handler:async t=>{let{invokeExtensionCommand:n}=await Yt(async()=>{let{invokeExtensionCommand:e}=await Promise.resolve().then(()=>T);return{invokeExtensionCommand:e}},void 0);await n(t,e.invocationName)},isExtension:!0})))}).catch(()=>{}),()=>{t=!0}},[e]);let re=[{name:`/compact`,description:`Manually compact the session context`,handler:async e=>{try{await tn.getState().compactAndReload(e)}catch(e){if((e instanceof Error?e.message:String(e)).includes(`nothing_to_compact`)){x(`Nothing to compact`);return}throw e}}},{name:`/compact with summary`,description:`Compact and keep focus on specific areas`,handler:async e=>{try{await tn.getState().compactAndReload(e)}catch(e){if((e instanceof Error?e.message:String(e)).includes(`nothing_to_compact`)){x(`Nothing to compact`);return}throw e}}},{name:`/reload`,description:`Reload agent config and rebuild session tools`,handler:async()=>{let{reloadAgent:e}=await Yt(async()=>{let{reloadAgent:e}=await Promise.resolve().then(()=>T);return{reloadAgent:e}},void 0);await e()}},{name:`/abort`,description:`Abort the current streaming response`,handler:async()=>{tn.getState().abort()}},...h],[k,ie]=(0,b.useState)([]),ae=(0,b.useRef)(null),oe=[`image/png`,`image/jpeg`,`image/webp`,`image/gif`],se=e=>new Promise((t,n)=>{let r=new FileReader;r.onload=()=>{let e=r.result,n=e.indexOf(`,`);t(n===-1?e:e.slice(n+1))},r.onerror=()=>n(r.error),r.readAsDataURL(e)}),ce=e=>{let t=[...k];for(let n of e){if(!oe.includes(n.type)||n.size>10485760)continue;if(t.length>=5)break;let e=URL.createObjectURL(n);t.push({file:n,dataUrl:e})}ie(t)},le=e=>{let t=k[e];t!==void 0&&URL.revokeObjectURL(t.dataUrl),ie(t=>t.filter((t,n)=>n!==e))},ue=()=>ae.current?.click(),de=e=>{e.target.files&&ce(e.target.files),e.target.value=``},fe=e=>{let t=e.clipboardData?.items;if(!t)return;let n=[];for(let e=0;e<t.length;e++){let r=t[e];if(r.type.startsWith(`image/`)){let e=r.getAsFile();e&&n.push(e)}}n.length>0&&(e.preventDefault(),ce(n))},pe=e=>{e.preventDefault(),e.stopPropagation()},me=e=>{e.preventDefault(),e.stopPropagation(),e.dataTransfer.files&&ce(e.dataTransfer.files)};(0,b.useEffect)(()=>{let e=o.current;e!==null&&(e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,200)}px`)},[]);let he=(e,t)=>{if(t<=0)return;let n=t-1;for(;n>=0;){let r=e[n];if(r===void 0)break;if(/\s/.test(r))return;if(r===`@`){let r=n===0?` `:e[n-1];return r===void 0||/\s/.test(r)?{start:n,end:t,query:e.slice(n+1,t)}:void 0}--n}};(0,b.useEffect)(()=>{if(C===void 0||S===void 0)return;let e=ne.current+1;ne.current=e;let t=window.setTimeout(()=>{dt(S.id,C.query,{limit:20}).then(t=>{ne.current===e&&(E(t.paths),D(0))}).catch(()=>{ne.current===e&&E([])})},100);return()=>window.clearTimeout(t)},[C,S]);let ge=e=>{if(C===void 0)return;let t=o.current;if(t===null)return;let n=t.value.slice(0,C.start),r=t.value.slice(C.end),i=`@"${e}"`;t.value=`${n}${i}${r}`,w(void 0),E([]);let a=C.start+i.length;t.setSelectionRange(a,a),t.style.height=`auto`,t.style.height=`${Math.min(t.scrollHeight,200)}px`},_e=()=>{w(void 0),E([])},ve=async t=>{t.preventDefault();let n=o.current;if(n===null)return;let r=n.value.trim();if(r.length===0&&k.length===0)return;if(r.startsWith(`/`)&&!s){let t=r.trim().toLowerCase(),i=re.find(e=>e.name.startsWith(t));if(i){n.value=``,n.style.height=`auto`,m([]),ie([]),_e(),await i.handler(e);return}}if(!s&&/^!!?[^!]/.test(r)){let t=r.startsWith(`!!`),i=r.slice(t?2:1).trim();if(i.length===0){x("Empty bash command. Type something after the `!`.");return}n.value=``,n.style.height=`auto`,m([]),ie([]),_e();let{promise:a}=qe(e,i,{excludeFromContext:t});try{await a,await f(e)}catch(e){x(`Command failed: ${e instanceof Error?e.message:String(e)}`)}return}let i;k.length>0&&(i=await Promise.all(k.map(async({file:e})=>({type:`image`,data:await se(e),mimeType:e.type})))),n.value=``,n.style.height=`auto`,m([]),_e(),ie([]),s?await u(r,i):await l(r,i)},ye=e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),ve(e))},be=(0,b.useCallback)(()=>{let e=o.current;if(e===null)return;e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,200)}px`;let t=e.value;if(t.startsWith(`/`)){let e=t.trim().toLowerCase();m(re.filter(t=>t.name.startsWith(e)))}else m([]);let n=e.selectionStart;n!==void 0&&!s?w(he(t,n)):_e()},[h,re,s]),xe=async t=>{let n=o.current;if(n!==null){n.value=``,n.style.height=`auto`,m([]),_e(),v(!0);try{await t.handler(e)}catch(e){console.error(`Slash command failed:`,e)}finally{v(!1)}}};return(0,M.jsxs)(`form`,{onSubmit:ve,onDragOver:pe,onDrop:me,className:`ti-area`,children:[s&&(0,M.jsxs)(`div`,{className:`ti-steer-badge`,children:[(0,M.jsxs)(`svg`,{width:`10`,height:`10`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,style:{flexShrink:0},children:[(0,M.jsx)(`path`,{d:`M12 2L2 7l10 5 10-5-10-5z`}),(0,M.jsx)(`path`,{d:`M2 17l10 5 10-5`}),(0,M.jsx)(`path`,{d:`M2 12l10 5 10-5`})]}),(0,M.jsx)(`span`,{children:`Your message will redirect the agent after its current tool calls`})]}),(0,M.jsxs)(`div`,{className:`ti-container`,children:[y!==null&&(0,M.jsx)(`div`,{style:{fontSize:11,color:`var(--text-dim)`,padding:`2px 0 0`,textAlign:`center`},children:y}),p.length>0&&(0,M.jsx)(`div`,{className:`ti-slash-suggestions`,children:p.map(e=>(0,M.jsxs)(`button`,{type:`button`,className:`ti-slash-item`,onClick:()=>xe(e),disabled:_,children:[(0,M.jsx)(`span`,{className:`ti-slash-name`,children:e.name}),(0,M.jsx)(`span`,{className:`ti-slash-desc`,children:e.description})]},e.name))}),C!==void 0&&ee.length>0&&(0,M.jsxs)(`div`,{style:{position:`absolute`,bottom:`100%`,left:0,right:0,zIndex:10,marginBottom:4,overflow:`hidden`,borderRadius:`var(--radius-sm)`,border:`1px solid var(--border)`,background:`var(--bg-frosted)`,boxShadow:`0 8px 24px rgba(0,0,0,0.4)`},children:[(0,M.jsx)(`div`,{style:{maxHeight:`60vh`,overflowY:`auto`,padding:`4px 0`},children:ee.map((e,t)=>(0,M.jsx)(`button`,{onMouseDown:t=>{t.preventDefault(),ge(e)},onMouseEnter:()=>D(t),style:{display:`block`,width:`100%`,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`,padding:`6px 12px`,textAlign:`left`,fontFamily:`monospace`,fontSize:12,border:`none`,cursor:`pointer`,background:t===te?`var(--accent-bg, var(--bg-glass-active))`:`transparent`,color:t===te?`var(--text-primary)`:`var(--text-secondary)`},title:e,children:e},e))}),(0,M.jsx)(`div`,{style:{borderTop:`1px solid var(--border)`,padding:`4px 12px`,fontSize:10,color:`var(--text-dim)`},children:`↑↓ navigate · Enter/Tab insert · Esc close`})]}),k.length>0&&(0,M.jsx)(`div`,{className:`ti-image-preview-row`,children:k.map((e,t)=>(0,M.jsxs)(`div`,{className:`ti-image-preview-item`,children:[(0,M.jsx)(`img`,{src:e.dataUrl,alt:`Attachment ${t+1}`,className:`ti-image-thumb`}),(0,M.jsx)(`button`,{type:`button`,className:`ti-image-remove`,onClick:()=>le(t),"aria-label":`Remove image`,children:(0,M.jsxs)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,M.jsx)(`line`,{x1:`18`,y1:`6`,x2:`6`,y2:`18`}),(0,M.jsx)(`line`,{x1:`6`,y1:`6`,x2:`18`,y2:`18`})]})})]},t))}),(0,M.jsx)(`textarea`,{ref:o,className:`ti-input`,onKeyDown:ye,onPaste:fe,onInput:be,placeholder:_?`Compacting…`:s?`Steer the agent…`:`Send a message... (/compact, /abort, !cmd, @file)`,disabled:_,rows:1}),(0,M.jsxs)(`div`,{className:`ti-toolbar`,children:[(0,M.jsxs)(`div`,{className:`ti-toolbar-left`,children:[O!==void 0&&(0,M.jsx)(`span`,{style:{fontSize:10,color:O===`local`?`var(--accent-text)`:`var(--text-secondary)`,padding:`0 6px`,fontFamily:`monospace`,letterSpacing:`0.5px`,textTransform:`uppercase`,opacity:.7},title:O===`local`?`!! — bash runs locally, output stays out of LLM context`:`! — bash runs, output feeds into next LLM turn`,children:O===`local`?`!! local`:`! context`}),(0,M.jsx)(`button`,{type:`button`,className:`ti-toolbar-btn`,onClick:ue,title:`Attach image`,tabIndex:-1,disabled:k.length>=5,children:(0,M.jsxs)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,M.jsx)(`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`,ry:`2`}),(0,M.jsx)(`circle`,{cx:`8.5`,cy:`8.5`,r:`1.5`}),(0,M.jsx)(`polyline`,{points:`21 15 16 10 5 21`})]})}),(0,M.jsx)(`input`,{ref:ae,type:`file`,accept:`image/png,image/jpeg,image/webp,image/gif`,multiple:!0,style:{display:`none`},onChange:de}),(0,M.jsx)(`button`,{type:`button`,className:`ti-toolbar-btn`,onClick:()=>n?.(!t),title:`Subagent`,tabIndex:-1,children:(0,M.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,M.jsx)(`polygon`,{points:`13 2 3 14 12 14 11 22 21 10 12 10 13 2`,style:{fill:t?`currentColor`:`none`}})})})]}),(0,M.jsxs)(`div`,{className:`ti-toolbar-right`,children:[i!==void 0&&(0,M.jsx)(wx,{sessionId:e,selected:r??``,onSelect:i,onError:a??(()=>{}),compact:!0}),s?(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(`button`,{type:`button`,onClick:d,className:`ti-abort-btn`,title:`Abort`,tabIndex:-1,children:(0,M.jsx)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`currentColor`,children:(0,M.jsx)(`rect`,{x:`4`,y:`4`,width:`16`,height:`16`,rx:`2`})})}),(0,M.jsx)(`button`,{type:`submit`,className:`ti-send-btn ti-steer-send`,title:`Send (steer)`,tabIndex:-1,disabled:_,children:(0,M.jsx)(`span`,{className:`ti-send-icon`,children:(0,M.jsxs)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,M.jsx)(`line`,{x1:`12`,y1:`19`,x2:`12`,y2:`5`}),(0,M.jsx)(`polyline`,{points:`5 12 12 5 19 12`})]})})})]}):(0,M.jsx)(`button`,{type:`submit`,className:`ti-send-btn${s&&c?` pulsing`:``}`,title:`Send`,tabIndex:-1,disabled:_,children:(0,M.jsx)(`span`,{className:`ti-send-icon`,children:(0,M.jsxs)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,M.jsx)(`line`,{x1:`12`,y1:`19`,x2:`12`,y2:`5`}),(0,M.jsx)(`polyline`,{points:`5 12 12 5 19 12`})]})})})]})]})]})]})}function Ex({sessionId:e}){let t=Ut(t=>t.pendingBySession[e]);return t===void 0?null:(0,M.jsx)(Dx,{pending:t},t.requestId)}function Dx({pending:e}){let t=Ut(e=>e.clearPending),[n,r]=(0,b.useState)(0),[i,a]=(0,b.useState)(!1),[o,s]=(0,b.useState)(void 0),[c,l]=(0,b.useState)(()=>e.questions.map(()=>null)),u=e.questions[n];if(u===void 0)return null;let d=n===e.questions.length-1,f=e=>{l(t=>{let r=[...t];return r[n]=e,r})},p=()=>c[n]??{},m=()=>e.questions.map((e,t)=>{let n=c[t];return n===null?{questionIndex:t,question:e.question,kind:`chat`,answer:null}:n.customText===void 0?e.multiSelect?{questionIndex:t,question:e.question,kind:`multi`,answer:null,selected:n.multiLabels??[]}:{questionIndex:t,question:e.question,kind:`option`,answer:n.selectedLabel??null}:{questionIndex:t,question:e.question,kind:`custom`,answer:n.customText}}),h=async(n=!1)=>{a(!0),s(void 0);try{let r=n?[]:m();await et(e.sessionId,e.requestId,r,n),t(e.sessionId,e.requestId)}catch(e){s(e instanceof Error?e.message:String(e))}finally{a(!1)}};return(0,M.jsxs)(`div`,{style:{border:`1px solid var(--border)`,borderRadius:12,background:`var(--bg-glass-strong)`,padding:16,margin:`8px auto`,maxWidth:800,width:`100%`,boxSizing:`border-box`},children:[(0,M.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,marginBottom:12},children:[(0,M.jsx)(`span`,{style:{fontSize:13,fontWeight:600,color:`var(--text-primary)`},children:u.header}),e.questions.length>1&&(0,M.jsxs)(`span`,{style:{fontSize:11,color:`var(--text-dim)`},children:[n+1,` / `,e.questions.length]}),(0,M.jsx)(`div`,{style:{flex:1}}),(0,M.jsx)(`button`,{onClick:()=>void h(!0),disabled:i,style:{background:`none`,border:`none`,color:`var(--text-tertiary)`,cursor:`pointer`,fontSize:12,padding:`2px 6px`,borderRadius:4},title:`Chat about this instead`,children:`✕ Chat about it`})]}),(0,M.jsx)(`div`,{style:{fontSize:14,color:`var(--text-primary)`,marginBottom:12,lineHeight:1.5},children:u.question}),(0,M.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:6},children:[u.multiSelect?(0,M.jsx)(Ax,{options:u.options,selected:p().multiLabels??[],onChange:e=>f({multiLabels:e})}):(0,M.jsx)(kx,{options:u.options,selected:p().selectedLabel,onSelect:e=>f({selectedLabel:e,customText:void 0})}),!u.multiSelect&&(0,M.jsx)(`div`,{style:{marginTop:8},children:(0,M.jsx)(`input`,{type:`text`,placeholder:`Type something...`,value:p().customText??``,onChange:e=>f({customText:e.target.value,selectedLabel:void 0}),style:{width:`100%`,padding:`8px 12px`,borderRadius:8,border:`1px solid var(--input-border)`,background:`var(--input-bg)`,color:`var(--text-primary)`,fontSize:13,fontFamily:`inherit`,outline:`none`}})})]}),o!==void 0&&(0,M.jsx)(`div`,{style:{fontSize:12,color:`var(--error)`,marginTop:8},children:o}),(0,M.jsxs)(`div`,{style:{display:`flex`,justifyContent:`space-between`,alignItems:`center`,marginTop:12,gap:8},children:[(0,M.jsx)(`div`,{children:n>0&&(0,M.jsx)(`button`,{onClick:()=>{r(e=>Math.max(e-1,0))},disabled:i,style:Ox,children:`← Back`})}),(0,M.jsx)(`div`,{style:{display:`flex`,gap:6},children:d?(0,M.jsx)(`button`,{onClick:()=>void h(!1),disabled:i,style:{...Ox,background:`var(--accent)`,color:`#fff`},children:i?`Submitting...`:`Submit`}):(0,M.jsx)(`button`,{onClick:()=>{r(t=>Math.min(t+1,e.questions.length-1))},disabled:i,style:Ox,children:`Next →`})})]})]})}var Ox={padding:`6px 14px`,borderRadius:8,border:`1px solid var(--border)`,background:`var(--bg-glass-hover)`,color:`var(--text-primary)`,fontSize:13,cursor:`pointer`,fontFamily:`inherit`};function kx({options:e,selected:t,onSelect:n}){return(0,M.jsx)(M.Fragment,{children:e.map(e=>(0,M.jsxs)(`button`,{onClick:()=>n(e.label),style:{display:`flex`,flexDirection:`column`,gap:2,padding:`8px 12px`,borderRadius:8,border:`1px solid ${t===e.label?`var(--accent)`:`var(--border)`}`,background:t===e.label?`var(--accent-subtle)`:`var(--bg-glass)`,color:`var(--text-primary)`,cursor:`pointer`,textAlign:`left`,fontSize:13,fontFamily:`inherit`,transition:`all 0.15s`},children:[(0,M.jsx)(`span`,{style:{fontWeight:500},children:e.label}),(0,M.jsx)(`span`,{style:{fontSize:12,color:`var(--text-secondary)`},children:e.description})]},e.label))})}function Ax({options:e,selected:t,onChange:n}){let r=e=>{t.includes(e)?n(t.filter(t=>t!==e)):n([...t,e])};return(0,M.jsx)(M.Fragment,{children:e.map(e=>{let n=t.includes(e.label);return(0,M.jsxs)(`label`,{style:{display:`flex`,alignItems:`flex-start`,gap:10,padding:`8px 12px`,borderRadius:8,border:`1px solid ${n?`var(--accent)`:`var(--border)`}`,background:n?`var(--accent-subtle)`:`var(--bg-glass)`,cursor:`pointer`,fontSize:13,fontFamily:`inherit`,transition:`all 0.15s`},children:[(0,M.jsx)(`input`,{type:`checkbox`,checked:n,onChange:()=>r(e.label),style:{marginTop:2,accentColor:`var(--accent-text)`}}),(0,M.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:2},children:[(0,M.jsx)(`span`,{style:{fontWeight:500},children:e.label}),(0,M.jsx)(`span`,{style:{fontSize:12,color:`var(--text-secondary)`},children:e.description})]})]},e.label)})})}function jx({variant:e=`text`,count:t=1,width:n,height:r,style:i}){let a=(0,b.useId)(),o={borderRadius:`4px`,background:`linear-gradient(90deg,
@@ -428,4 +428,4 @@ ${s.join(`
428
428
  }
429
429
  `}),(0,M.jsx)(`button`,{className:`terminal-quick-key ${f?`active`:``}`,onPointerDown:e=>{e.preventDefault(),p(e=>!e)},children:`CTRL`}),(0,M.jsx)(`button`,{className:`terminal-quick-key`,onPointerDown:e=>{e.preventDefault(),y(``)},children:`^C`}),(0,M.jsx)(`button`,{className:`terminal-quick-key`,onPointerDown:e=>{e.preventDefault(),y(`\x1B`)},children:`ESC`}),(0,M.jsx)(`button`,{className:`terminal-quick-key`,onPointerDown:e=>{e.preventDefault(),y(` `)},children:`TAB`}),(0,M.jsx)(`div`,{style:{width:1,height:20,background:`var(--border-color, #313244)`,margin:`0 4px`}}),(0,M.jsx)(`button`,{className:`terminal-quick-key`,onPointerDown:e=>{e.preventDefault(),y(`\x1B[A`)},children:`↑`}),(0,M.jsx)(`button`,{className:`terminal-quick-key`,onPointerDown:e=>{e.preventDefault(),y(`\x1B[B`)},children:`↓`}),(0,M.jsx)(`button`,{className:`terminal-quick-key`,onPointerDown:e=>{e.preventDefault(),y(`\x1B[D`)},children:`←`}),(0,M.jsx)(`button`,{className:`terminal-quick-key`,onPointerDown:e=>{e.preventDefault(),y(`\x1B[C`)},children:`→`})]})]})}function lre({tab:e,visible:t,ctrlActive:n,setCtrlActive:r}){let i=(0,b.useRef)(null),a=(0,b.useRef)(n);return(0,b.useEffect)(()=>{a.current=n},[n]),(0,b.useEffect)(()=>{if(i.current===null)return;let t=i.current,n=z9.get(e.id);if(n!==void 0){try{let e=n.term.element;e!==void 0&&e.parentNode!==t?t.appendChild(e):n.term.open(t),B9(t),V9(n,!0)}catch{}let e=new ResizeObserver(()=>{try{V9(n)}catch{}});e.observe(t);try{n.observer.disconnect()}catch{}return n.observer=e,requestAnimationFrame(()=>{try{V9(n),n.term.focus()}catch{}}),()=>{try{e.disconnect()}catch{}}}let o=window.innerWidth<=600,s=new Qne({theme:{background:U9(`--bg-solid`,`#1e1e2e`),foreground:U9(`--text-primary`,`#cdd6f4`),cursor:U9(`--accent-text`,`#89b4fa`),selectionBackground:U9(`--accent`,`#89b4fa`),black:U9(`--ansi-black`,`#45475a`),red:U9(`--ansi-red`,`#f38ba8`),green:U9(`--ansi-green`,`#a6e3a1`),yellow:U9(`--ansi-yellow`,`#f9e2af`),blue:U9(`--ansi-blue`,`#89b4fa`),magenta:U9(`--ansi-magenta`,`#f5c2e7`),cyan:U9(`--ansi-cyan`,`#94e2d5`),white:U9(`--ansi-white`,`#bac2de`),brightBlack:U9(`--ansi-bright-black`,`#585b70`),brightRed:U9(`--ansi-bright-red`,`#f38ba8`),brightGreen:U9(`--ansi-bright-green`,`#a6e3a1`),brightYellow:U9(`--ansi-bright-yellow`,`#f9e2af`),brightBlue:U9(`--ansi-bright-blue`,`#89b4fa`),brightMagenta:U9(`--ansi-bright-magenta`,`#f5c2e7`),brightCyan:U9(`--ansi-bright-cyan`,`#94e2d5`),brightWhite:U9(`--ansi-bright-white`,`#a6adc8`)},fontFamily:`ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace`,fontSize:o?12:13,cursorBlink:!0,scrollback:5e3,allowTransparency:!0}),c=new tre;s.loadAddon(c),s.open(t),B9(t),c.fit();let l={cols:s.cols,rows:s.rows},u=H9(e.id,e.projectId,s,l,!1);s.onData(t=>{let n=z9.get(e.id)?.ws;if(n?.readyState===WebSocket.OPEN)if(a.current&&t.length===1){let e=t.charCodeAt(0),i=t;e>=97&&e<=122?i=String.fromCharCode(e-96):e>=65&&e<=90&&(i=String.fromCharCode(e-64)),n.send(JSON.stringify({type:`input`,data:i})),r(!1)}else n.send(JSON.stringify({type:`input`,data:t}))});let d=new ResizeObserver(()=>{try{let t=z9.get(e.id);if(t===void 0)return;V9(t)}catch{}});d.observe(t);let f=null,p=null,m=null,h=0,g,_=!1,v,y=0,b=0,x=``,S=-1,C=0,w=[{minDist:0,interval:150},{minDist:100,interval:80},{minDist:200,interval:40}];function ee(e){for(let t=w.length-1;t>=0;t--)if(e>=w[t].minDist)return t;return 0}function T(){v!==void 0&&(clearInterval(v),v=void 0),_=!1,x=``,S=-1,t.style.userSelect=``}function E(t,n){let r=t-y,i=n-b,a=Math.sqrt(r*r+i*i);if(a<15)return;let o=Math.abs(r)>Math.abs(i)?r>0?`right`:`left`:i>0?`down`:`up`,s=ee(a);if(o!==x||s!==S){x=o,S=s,v!==void 0&&clearInterval(v);let t=o===`right`?`\x1B[C`:o===`left`?`\x1B[D`:o===`down`?`\x1B[B`:`\x1B[A`,n=z9.get(e.id)?.ws;n?.readyState===WebSocket.OPEN&&n.send(JSON.stringify({type:`input`,data:t})),v=setInterval(()=>{let n=z9.get(e.id)?.ws;n?.readyState===WebSocket.OPEN&&n.send(JSON.stringify({type:`input`,data:t}))},w[s].interval)}}let te=e=>{e.touches.length===1?(f=e.touches[0].clientX,p=e.touches[0].clientY,g!==void 0&&clearTimeout(g),g=setTimeout(()=>{y=f,b=p,_=!0,t.style.userSelect=`none`},150)):e.touches.length===2&&(g!==void 0&&(clearTimeout(g),g=void 0),m=(e.touches[0].clientY+e.touches[1].clientY)/2,h=0)},D=e=>{if(e.touches.length===2&&m!==null){g!==void 0&&(clearTimeout(g),g=void 0);let t=(e.touches[0].clientY+e.touches[1].clientY)/2,n=m-t;if(m=t,Math.abs(n)<1)return;e.preventDefault(),e.stopPropagation();let r=h+n,i=Math.trunc(r/16);h=r-i*16,i!==0&&s.scrollLines(i);return}if(e.touches.length===1&&_){e.preventDefault(),e.stopPropagation(),E(e.touches[0].clientX,e.touches[0].clientY);return}if(e.touches.length===1&&!_&&f!==null&&p!==null&&g!==void 0){let t=e.touches[0].clientX-f,n=e.touches[0].clientY-p;Math.max(Math.abs(t),Math.abs(n))>20&&(clearTimeout(g),g=void 0)}},ne=t=>{if(t.changedTouches.length===3){T(),g!==void 0&&(clearTimeout(g),g=void 0),navigator.clipboard.readText().then(t=>{let n=z9.get(e.id)?.ws;n?.readyState===WebSocket.OPEN&&n.send(JSON.stringify({type:`input`,data:t}))}).catch(()=>{}),f=null,p=null,m=null;return}if(_){T(),f=null,p=null,m=null;return}if(g!==void 0){clearTimeout(g),g=void 0;let t=Date.now();if(f!==null&&p!==null)if(t-C<300){let t=z9.get(e.id)?.ws;t?.readyState===WebSocket.OPEN&&t.send(JSON.stringify({type:`input`,data:` `})),C=0}else C=t}s.focus(),f=null,p=null,m=null},O=()=>{T(),g!==void 0&&(clearTimeout(g),g=void 0),f=null,p=null,m=null};t.addEventListener(`touchstart`,te,{passive:!1}),t.addEventListener(`touchmove`,D,{passive:!1}),t.addEventListener(`touchend`,ne),t.addEventListener(`touchcancel`,O);let re=e=>{e.preventDefault()},k=e=>{e.preventDefault()};return t.addEventListener(`contextmenu`,re),t.addEventListener(`selectstart`,k),t.style.setProperty(`-webkit-touch-callout`,`none`),z9.set(e.id,{term:s,fit:c,ws:u,observer:d,lastSize:l,reconnectAttempt:0,reconnectTimer:void 0,disposed:!1,ctrlActive:!1}),()=>{try{d.disconnect(),t.removeEventListener(`touchstart`,te),t.removeEventListener(`touchmove`,D),t.removeEventListener(`touchend`,ne),t.removeEventListener(`touchcancel`,O),t.removeEventListener(`contextmenu`,re),t.removeEventListener(`selectstart`,k),t.style.setProperty(`-webkit-touch-callout`,``)}catch{}}},[e.id]),(0,b.useEffect)(()=>{if(!t)return;let n=z9.get(e.id);n!==void 0&&requestAnimationFrame(()=>{try{V9(n),n.term.focus()}catch{}})},[t,e.id]),(0,M.jsx)(`div`,{ref:i,onClick:()=>{z9.get(e.id)?.term.focus()},className:`terminal-host`,style:{position:`absolute`,inset:0,visibility:t?`visible`:`hidden`,pointerEvents:t?`auto`:`none`,zIndex:+!!t,padding:`2px 4px 8px 4px`,touchAction:`none`,userSelect:`none`,WebkitUserSelect:`none`}})}function H9(e,t,n,r,i){let a=window.location.protocol===`https:`?`wss`:`ws`,o=ie(),s=o===void 0?``:`&token=${encodeURIComponent(o)}`,c=`${a}://${window.location.host}/api/v1/terminal?projectId=${encodeURIComponent(t)}&tabId=${encodeURIComponent(e)}${s}`,l=new WebSocket(c);return l.binaryType=`arraybuffer`,l.onopen=()=>{let t=z9.get(e),n=t===void 0?r:{cols:t.term.cols,rows:t.term.rows};l.send(JSON.stringify({type:`resize`,cols:n.cols,rows:n.rows})),t!==void 0&&(t.lastSize=n,t.reconnectAttempt=0)},l.onmessage=e=>{if(typeof e.data==`string`)try{let t=JSON.parse(e.data);if(t.type===`open`){n.writeln(`\r\n\x1b[32mTerminal opened at ${t.cwd}\x1b[0m`);return}if(t.type===`exit`){n.writeln(`\r\n\x1b[31mProcess exited with code ${t.code}\x1b[0m`);return}if(t.type===`error`){n.writeln(`\r\n\x1b[31mError: ${t.message}\x1b[0m`);return}}catch{n.write(e.data)}else e.data instanceof ArrayBuffer&&n.write(new Uint8Array(e.data))},l.onclose=r=>{let i=z9.get(e);if(i===void 0||i.disposed)return;if(sre(r.code)){let e=`[connection closed: ${String(r.code)}]`;r.code===4401?e=`[connection closed (4401): session expired — refresh the page after logging back in]`:r.code===4404&&(e=`[connection closed (4404): project no longer exists]`),n.write(`\r\n${e}\r\n`);return}let a=i.reconnectAttempt+1;i.reconnectAttempt=a;let o=ore(a);n.write(`\r\n[connection lost (${String(r.code)}) — reconnecting in ${String(o/1e3)}s, attempt ${String(a)}]\r\n`),i.reconnectTimer=setTimeout(()=>{let r=z9.get(e);r===void 0||r.disposed||(r.reconnectTimer=void 0,r.ws=H9(e,t,n,r.lastSize,!0))},o)},l}function ure(e){let t=z9.get(e);if(t!==void 0){t.disposed=!0,t.reconnectTimer!==void 0&&clearTimeout(t.reconnectTimer),z9.delete(e);try{t.observer.disconnect()}catch{}try{(t.ws.readyState===WebSocket.OPEN||t.ws.readyState===WebSocket.CONNECTING)&&t.ws.close(1e3,`tab_closed`)}catch{}try{t.term.dispose()}catch{}}}function U9(e,t){return typeof document>`u`?t:getComputedStyle(document.documentElement).getPropertyValue(e).trim()||t}function dre({sessionId:e}){let t=Gt(e=>e.activeInteraction);Gt(e=>e.clearInteraction);let n=Gt(e=>e.cancelCommand),r=Gt(e=>e.commandRunning),[i,a]=(0,b.useState)(``),[o,s]=(0,b.useState)(0),c=(0,b.useCallback)(()=>{let t=Gt.getState().activeInteraction;if(t&&`requestId`in t){let n=t.requestId;Ct(e,n,``).catch(()=>{})}n()},[e,n]);if((0,b.useEffect)(()=>{a(``),s(0)},[t?.type]),t===void 0&&!r||!r&&t===void 0)return null;let l=t?.type??``;if(l===`extension_ui_select`){let n=t;return(0,M.jsx)(`div`,{className:`settings-overlay`,onClick:c,children:(0,M.jsxs)(`div`,{className:`settings-panel rewind-panel`,onClick:e=>e.stopPropagation(),style:{width:520,maxWidth:`92vw`,height:`auto`,maxHeight:`80vh`,display:`flex`,flexDirection:`column`},children:[(0,M.jsxs)(`header`,{className:`settings-header`,children:[(0,M.jsx)(`span`,{style:{fontSize:14,fontWeight:600},children:n.title}),(0,M.jsx)(`button`,{onClick:c,className:`settings-close`,title:`Cancel`,children:`✕`})]}),(0,M.jsx)(`div`,{className:`settings-body`,style:{padding:`12px 16px`,overflowY:`auto`,flex:1},children:(0,M.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:3},children:n.options.map((t,r)=>{let i=t.split(`
430
430
  `).filter(Boolean),a=i[0]??t,c=i.slice(1).join(` `).trim().replace(/\u001b\[[0-9;]*m/g,``);return(0,M.jsxs)(`button`,{onClick:async r=>{r.stopPropagation();try{await Ct(e,n.requestId,t)}catch(e){console.error(`Extension UI respond failed:`,e)}},onMouseEnter:()=>s(r),style:{display:`flex`,width:`100%`,alignItems:`flex-start`,gap:10,padding:`8px 10px`,borderRadius:6,border:r===o?`1px solid var(--accent-border)`:`1px solid transparent`,background:r===o?`var(--accent-subtle)`:`none`,cursor:`pointer`,textAlign:`left`,fontSize:11,fontFamily:`inherit`,color:`var(--text-primary)`,transition:`background 0.15s`},children:[(0,M.jsx)(`span`,{style:{display:`inline-flex`,alignItems:`center`,justifyContent:`center`,width:22,height:22,borderRadius:`50%`,background:`var(--bg-glass-hover)`,color:`var(--text-dim)`,fontSize:10,fontWeight:700,flexShrink:0,marginTop:1},children:r+1}),(0,M.jsxs)(`div`,{style:{flex:1,minWidth:0},children:[(0,M.jsx)(`div`,{style:{fontSize:11,fontWeight:500,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:a}),c&&(0,M.jsx)(`div`,{style:{fontSize:10,color:`var(--text-dim)`,marginTop:2,fontFamily:`monospace`},children:c})]})]},r)})})}),(0,M.jsx)(`div`,{style:{padding:`8px 16px`,borderTop:`1px solid var(--border-color)`,fontSize:10,color:`var(--text-dim)`,textAlign:`center`},children:`Select an option above`})]})})}if(l===`extension_ui_confirm`){let n=t;return(0,M.jsx)(`div`,{className:`settings-overlay`,onClick:c,children:(0,M.jsxs)(`div`,{className:`settings-panel rewind-panel`,onClick:e=>e.stopPropagation(),style:{width:420,maxWidth:`92vw`,height:`auto`,minHeight:0},children:[(0,M.jsxs)(`header`,{className:`settings-header`,children:[(0,M.jsx)(`span`,{style:{fontSize:14,fontWeight:600},children:n.title}),(0,M.jsx)(`button`,{onClick:c,className:`settings-close`,title:`Cancel`,children:`✕`})]}),(0,M.jsxs)(`div`,{className:`settings-body`,style:{padding:`16px`},children:[(0,M.jsx)(`p`,{style:{fontSize:13,color:`var(--text-secondary)`,marginBottom:20,lineHeight:1.5},children:n.message}),(0,M.jsxs)(`div`,{style:{display:`flex`,gap:8,justifyContent:`flex-end`},children:[(0,M.jsx)(`button`,{onClick:async t=>{t.stopPropagation();try{await Ct(e,n.requestId,!1)}catch(e){console.error(e)}},className:`settings-tab`,style:{padding:`6px 14px`,fontSize:12},children:`No`}),(0,M.jsx)(`button`,{onClick:async t=>{t.stopPropagation();try{await Ct(e,n.requestId,!0)}catch(e){console.error(e)}},className:`settings-tab settings-tab-active`,style:{padding:`6px 14px`,fontSize:12},children:`Yes`})]})]})]})})}if(l===`extension_ui_input`){let n=t;return(0,M.jsx)(`div`,{className:`settings-overlay`,onClick:c,children:(0,M.jsxs)(`div`,{className:`settings-panel rewind-panel`,onClick:e=>e.stopPropagation(),style:{width:420,maxWidth:`92vw`,height:`auto`,minHeight:0},children:[(0,M.jsxs)(`header`,{className:`settings-header`,children:[(0,M.jsx)(`span`,{style:{fontSize:14,fontWeight:600},children:n.title}),(0,M.jsx)(`button`,{onClick:c,className:`settings-close`,title:`Cancel`,children:`✕`})]}),(0,M.jsxs)(`div`,{className:`settings-body`,style:{padding:`16px`},children:[(0,M.jsx)(`input`,{type:`text`,value:i,onChange:e=>a(e.target.value),placeholder:n.placeholder,autoFocus:!0,style:{width:`100%`,padding:`8px 10px`,fontSize:12,borderRadius:6,border:`1px solid var(--border-color)`,background:`var(--bg-glass)`,color:`var(--text-primary)`,outline:`none`,fontFamily:`inherit`,boxSizing:`border-box`,marginBottom:12},onKeyDown:async t=>{if(t.key===`Enter`){t.stopPropagation();try{await Ct(e,n.requestId,i)}catch(e){console.error(e)}}t.key===`Escape`&&c()}}),(0,M.jsxs)(`div`,{style:{display:`flex`,gap:8,justifyContent:`flex-end`},children:[(0,M.jsx)(`button`,{onClick:c,className:`settings-tab`,style:{padding:`6px 14px`,fontSize:12},children:`Cancel`}),(0,M.jsx)(`button`,{onClick:async t=>{t.stopPropagation();try{await Ct(e,n.requestId,i)}catch(e){console.error(e)}},className:`settings-tab settings-tab-active`,style:{padding:`6px 14px`,fontSize:12},children:`OK`})]})]})]})})}return r&&t===void 0?(0,M.jsx)(`div`,{className:`settings-overlay`,children:(0,M.jsx)(`div`,{className:`settings-panel rewind-panel`,onClick:e=>e.stopPropagation(),style:{width:300,maxWidth:`92vw`,height:`auto`,minHeight:0,textAlign:`center`},children:(0,M.jsx)(`div`,{className:`settings-body`,style:{padding:`20px`},children:(0,M.jsx)(`div`,{style:{fontSize:12,color:`var(--text-dim)`},children:`Extension command running…`})})})}):null}function fre(){let e=Gt(e=>e.notifications),t=Gt(e=>e.dismissNotification),[n,r]=(0,b.useState)(null),[i,a]=(0,b.useState)(``),[o,s]=(0,b.useState)(`info`),[c,l]=(0,b.useState)(!1),u=e[e.length-1];(0,b.useEffect)(()=>{if(u&&u.id!==n){r(u.id),a(u.message),s(u.type),l(!0);let e=setTimeout(()=>{l(!1),setTimeout(()=>t(u.id),300)},15e3);return()=>clearTimeout(e)}},[u,n,t]);let d=()=>{n&&(l(!1),setTimeout(()=>{t(n),r(null)},250))};return!n||!i?null:(0,M.jsx)(`div`,{className:`toast-overlay`,onClick:d,children:(0,M.jsxs)(`div`,{className:`toast-card ${c?`toast-card-enter`:`toast-card-exit`}`,onClick:e=>e.stopPropagation(),role:`alert`,children:[(0,M.jsxs)(`header`,{className:`toast-card-header`,children:[(0,M.jsxs)(`span`,{className:`toast-card-title`,children:[o===`info`&&`ℹ️`,o===`warning`&&`⚠️`,o===`error`&&`❌`,(0,M.jsxs)(`span`,{style:{marginLeft:6},children:[o===`info`&&`Context Mode`,o===`warning`&&`Warning`,o===`error`&&`Error`]})]}),(0,M.jsx)(`button`,{className:`toast-card-close`,onClick:d,"aria-label":`Dismiss`,children:`✕`})]}),(0,M.jsx)(`div`,{className:`toast-card-body`,children:(0,M.jsx)(`pre`,{className:`toast-card-content`,children:i})})]})})}var W9=`pi-kot/favorite-sessions`;function pre(){try{let e=localStorage.getItem(W9);return e?JSON.parse(e):[]}catch{return[]}}function mre(e){try{localStorage.setItem(W9,JSON.stringify(e))}catch{}}var hre=w((e,t)=>({favorites:pre(),toggle:n=>{let r=t().favorites,i=r.includes(n)?r.filter(e=>e!==n):[...r,n];mre(i),e({favorites:i})}})),G9=8,gre=10;function _re({projectId:e,sessions:t,activeSessionId:n,isStreaming:r,renamingSessionId:i,renameValue:a,renameInputRef:o,expandedWorkerGroups:s,onSelect:c,onRenameStart:l,onRenameChange:u,onRenameCommit:d,onRenameCancel:f,onToggleWorkerGroup:p,onNewSession:m}){let[h,g]=(0,b.useState)(``),[_,v]=(0,b.useState)(!1),y=(0,b.useMemo)(()=>t.filter(e=>!e.supervisorId),[t]),x=(0,b.useMemo)(()=>t.filter(e=>e.supervisorId),[t]),S=(0,b.useMemo)(()=>x.filter(e=>!y.some(t=>t.sessionId===e.supervisorId)),[x,y]),C=h.trim().toLowerCase(),w=(0,b.useMemo)(()=>C?y.filter(e=>(e.name??`Session ${e.sessionId.slice(0,8)}`).toLowerCase().includes(C)):y,[y,C]),ee=!_&&!C&&w.length>G9,T=ee?w.slice(0,G9).includes(w.find(e=>e.sessionId===n)??w[0])?w.slice(0,G9):[...w.slice(0,G9-1),w.find(e=>e.sessionId===n)??w[G9-1]].filter(Boolean):w,E=w.length-T.length,{favorites:te,toggle:D}=hre(),{favSessions:ne,normalSessions:O}=(0,b.useMemo)(()=>{let e=[],t=[];for(let n of T)te.includes(n.sessionId)?e.push(n):t.push(n);return{favSessions:e,normalSessions:t}},[T,te]),re=t.length>=gre,k=e=>{let t=x.filter(t=>t.supervisorId===e.sessionId),m=s.has(e.sessionId),h=n===e.sessionId,g=e.name??`Session ${e.sessionId.slice(0,8)}`,_=te.includes(e.sessionId);return(0,M.jsxs)(`div`,{children:[(0,M.jsxs)(`div`,{onClick:t=>{i!==e.sessionId&&(t.stopPropagation(),c(e.sessionId))},className:`session-item${h?` active`:``}`,onDoubleClick:t=>{t.stopPropagation(),l(e.sessionId,g)},children:[t.length>0&&(0,M.jsx)(`span`,{className:`project-chevron`,onClick:t=>{t.stopPropagation(),p(e.sessionId)},style:{cursor:`pointer`,marginRight:`4px`},children:m?`▾`:`▶`}),i===e.sessionId?(0,M.jsx)(`input`,{ref:o,className:`session-rename-input`,value:a,onChange:e=>u(e.target.value),onBlur:()=>d(e.sessionId,g),onKeyDown:e=>{e.key===`Enter`?e.currentTarget.blur():e.key===`Escape`&&f()},onClick:e=>e.stopPropagation()}):(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(`button`,{className:`session-fav-btn${_?` favorited`:``}`,onClick:t=>{t.stopPropagation(),D(e.sessionId)},title:_?`Remove from favorites`:`Add to favorites`,children:_?`★`:`☆`}),(0,M.jsx)(`span`,{className:`session-name`,children:g}),(0,M.jsx)(`button`,{className:`session-archive-btn`,title:`Archive session`,onClick:t=>{t.stopPropagation(),confirm(`Archive "${g}"?`)&&tn.getState().archiveSession(e.sessionId)},children:`✕`})]})]}),t.length>0&&m&&(0,M.jsx)(`div`,{className:`session-children`,children:t.map(e=>(0,M.jsx)(K9,{worker:e,isActive:n===e.sessionId,isStreaming:r&&n===e.sessionId,onSelect:c},e.sessionId))})]},e.sessionId)};return(0,M.jsxs)(`div`,{className:`session-list project-sublist`,children:[re&&(0,M.jsx)(`div`,{style:{padding:`4px 8px 6px`},children:(0,M.jsx)(`input`,{value:h,onChange:e=>{g(e.target.value),v(!1)},placeholder:`Search sessions…`,className:`session-search-input`,type:`search`})}),y.length===0&&x.length===0&&(0,M.jsx)(`div`,{style:{padding:`6px 12px 2px`,fontSize:`11px`,color:`var(--text-dim)`,fontStyle:`italic`},children:`No sessions yet`}),C&&w.length===0&&(0,M.jsxs)(`div`,{style:{padding:`6px 12px 2px`,fontSize:`11px`,color:`var(--text-dim)`,fontStyle:`italic`},children:[`No matches for "`,h,`"`]}),ne.length>0&&!C&&(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(`div`,{className:`favorites-section-header`,children:`★ Favorites`}),ne.map(k),O.length>0&&(0,M.jsx)(`div`,{className:`favorites-section-divider`})]}),C?T.map(k):O.map(k),ee&&E>0&&(0,M.jsxs)(`button`,{className:`session-show-more-btn`,onClick:()=>v(!0),type:`button`,children:[`↓ `,E,` more session`,E===1?``:`s`]}),_&&w.length>G9&&(0,M.jsx)(`button`,{className:`session-show-more-btn`,onClick:()=>v(!1),type:`button`,children:`↑ Show less`}),S.map(e=>(0,M.jsx)(K9,{worker:e,isActive:n===e.sessionId,isStreaming:r&&n===e.sessionId,onSelect:c},e.sessionId)),(0,M.jsxs)(`button`,{className:`new-session-row`,onClick:e=>{e.stopPropagation(),m()},type:`button`,children:[(0,M.jsx)(`span`,{style:{fontSize:`14px`,lineHeight:1},children:`+`}),`New session`]})]})}function K9({worker:e,isActive:t,isStreaming:n,onSelect:r}){return(0,M.jsxs)(`div`,{onClick:t=>{t.stopPropagation(),r(e.sessionId)},className:`session-item session-worker-item${t?` active`:``}`,children:[(0,M.jsx)(`span`,{className:`session-worker-dot${n?` active`:``}`,style:{background:e.isLive&&!n?`#98c379`:e.isLive?void 0:`#56b6c2`}}),(0,M.jsx)(`span`,{className:`session-worker-name`,children:e.name??`Session ${e.sessionId.slice(0,8)}`})]})}function q9(e,t){return e===`~`?t:e.startsWith(`~/`)?t+e.slice(1):e}function J9(e){if(e.endsWith(`/`))return e;let t=e.lastIndexOf(`/`);return t>=0?e.slice(0,t+1):e}function vre(e){if(e.endsWith(`/`))return``;let t=e.lastIndexOf(`/`);return t>=0?e.slice(t+1):e}function yre({open:e,onClose:t}){let[n,r]=(0,b.useState)(``),[i,a]=(0,b.useState)(`~/`),[o,s]=(0,b.useState)([]),[c,l]=(0,b.useState)(!1),[u,d]=(0,b.useState)(),[f,p]=(0,b.useState)(0),[m,h]=(0,b.useState)(!1),[g,_]=(0,b.useState)(!1),[v,y]=(0,b.useState)(``),[x,S]=(0,b.useState)(!1),[C,w]=(0,b.useState)(!1),ee=(0,b.useRef)(null),T=tn(e=>e.loadProjects),E=tn(e=>e.setActiveProject);(0,b.useEffect)(()=>{if(!e)return;let t=!1;return a(`~/`),y(``),_(!1),h(!1),p(0),d(void 0),w(!1),S(!1),Se().then(e=>{t||(r(e),requestAnimationFrame(()=>ee.current?.focus()))}).catch(()=>{t||(r(`/`),requestAnimationFrame(()=>ee.current?.focus()))}),()=>{t=!0}},[e]);let te=(0,b.useMemo)(()=>n?q9(J9(i),n):``,[i,n]);(0,b.useEffect)(()=>{if(!e||!te){s([]);return}let t=!1;return l(!0),d(void 0),Ce(te).then(e=>{t||s(e)}).catch(e=>{t||(s([]),d(e instanceof Error?e.message:`Failed to load directory`))}).finally(()=>{t||l(!1)}),()=>{t=!0}},[e,te]);let D=vre(i),ne=(0,b.useMemo)(()=>{let e=D.toLowerCase(),t=m||D.startsWith(`.`);return o.filter(n=>n.isDirectory&&(t||!n.name.startsWith(`.`))&&n.name.toLowerCase().startsWith(e))},[o,D,m]);(0,b.useEffect)(()=>{p(0)},[ne.length]);let O=i!==`~/`&&i!==`/`,re=(0,b.useMemo)(()=>n?q9(i.replace(/\/+$/,``),n):``,[i,n]),k=(0,b.useCallback)(e=>{a((e.startsWith(n)?`~`+e.slice(n.length):e)+`/`)},[n]),ie=(0,b.useCallback)(()=>{let e=J9(i.replace(/\/+$/,``)).replace(/\/+$/,``);if(e===`~`||e===``){let e=n&&n.split(`/`).slice(0,-1).join(`/`)||`/`,t=e===`/`?`/`:`~`+e.slice(n.lastIndexOf(`/`));a(t.endsWith(`/`)?t:t+`/`);return}let t=e.lastIndexOf(`/`);a(t>=0?e.slice(0,t+1):`/`)},[i,n]),ae=(0,b.useCallback)(async e=>{try{await be(e.split(`/`).filter(Boolean).pop()||`unnamed`,e),await T();let n=tn.getState(),r=n.projects[n.projects.length-1];r&&E(r.id),t()}catch(e){d(e instanceof Error?e.message:`Failed to add project`)}},[T,E,t]),oe=(0,b.useCallback)(async()=>{if(!(!re||C)){w(!0),d(void 0);try{await be(re.split(`/`).filter(Boolean).pop()||`unnamed`,re),await T();let e=tn.getState(),n=e.projects[e.projects.length-1];n&&E(n.id),t()}catch(e){d(e instanceof Error?e.message:`Failed to add project`)}finally{w(!1)}}},[re,C,T,E,t]),se=(0,b.useCallback)(()=>{if(!v.trim()||!re||x)return;S(!0),d(void 0);let e=re.split(`/`).filter(Boolean).pop()||`repo`;je({url:v.trim(),folderName:e,projectName:e},e=>{switch(e.type){case`done`:T().then(()=>{let e=tn.getState(),n=e.projects[e.projects.length-1];n&&E(n.id),t()}),S(!1);break;case`error`:d(e.message),S(!1);break}},e=>{d(e.message),S(!1)})},[v,re,x,T,E,t]),ce=(0,b.useCallback)(e=>{if(e.key===`ArrowDown`)e.preventDefault(),p(e=>Math.min(ne.length-1,e+1));else if(e.key===`ArrowUp`)e.preventDefault(),p(e=>Math.max(0,e-1));else if(e.key===`Enter`){if(e.preventDefault(),ne.length>0&&f>=0){let e=ne[f];D&&!e.name.startsWith(D)?a(J9(i)+e.name+`/`):k(e.path)}}else e.key===`Backspace`&&!i&&(e.preventDefault(),t())},[ne,f,D,i,k,t]);return e?(0,M.jsx)(`div`,{className:`settings-overlay`,onClick:t,children:(0,M.jsxs)(`div`,{className:`settings-panel add-project-settings-panel`,onClick:e=>e.stopPropagation(),children:[(0,M.jsxs)(`header`,{className:`settings-header`,children:[(0,M.jsx)(`span`,{style:{fontSize:`14px`,fontWeight:700,color:`var(--accent-text)`},children:`Add Project`}),(0,M.jsx)(`button`,{className:`settings-close`,onClick:t,title:`Close`,children:(0,M.jsx)(Pn,{size:16})})]}),(0,M.jsxs)(`div`,{className:`add-project-dialog-body`,children:[(0,M.jsxs)(`div`,{className:`add-project-dialog-bar`,children:[(0,M.jsxs)(`button`,{className:`add-project-dialog-tab`+(g?``:` active`),onClick:()=>_(!1),children:[(0,M.jsx)(wn,{size:14}),`Browse`]}),(0,M.jsxs)(`button`,{className:`add-project-dialog-tab`+(g?` active`:``),onClick:()=>_(!0),children:[(0,M.jsx)(Tn,{size:14}),`Clone`]})]}),g&&(0,M.jsxs)(`div`,{className:`add-project-dialog-clone-row`,children:[(0,M.jsx)(En,{size:14,className:`add-project-dialog-icon`}),(0,M.jsx)(`input`,{type:`text`,value:v,onChange:e=>y(e.target.value),placeholder:`https://github.com/user/repo.git`,className:`add-project-dialog-input`,style:{paddingLeft:`30px`},spellCheck:!1})]}),(0,M.jsxs)(`div`,{className:`add-project-dialog-path-row`,children:[(0,M.jsx)(wn,{size:14,className:`add-project-dialog-icon`}),(0,M.jsx)(`input`,{ref:ee,type:`text`,value:i,onChange:e=>a(e.target.value.replace(/\\/g,`/`)),onKeyDown:ce,placeholder:`~/`,className:`add-project-dialog-input`,spellCheck:!1}),(0,M.jsx)(`button`,{className:`add-project-dialog-btn`,disabled:g?!v.trim()||!re||x:!re||C,onClick:g?se:oe,children:g?x?`Cloning…`:`Clone & Add`:C?`Adding…`:`Add`})]}),(0,M.jsxs)(`div`,{className:`add-project-dialog-tools`,children:[(0,M.jsxs)(`button`,{className:`add-project-dialog-tool`,onClick:ie,disabled:!O,title:`Go up`,children:[(0,M.jsx)(pn,{size:14}),(0,M.jsx)(`span`,{children:`..`})]}),(0,M.jsxs)(`button`,{className:`add-project-dialog-tool`,onClick:()=>h(e=>!e),title:m?`Hide hidden files`:`Show hidden files`,children:[m?(0,M.jsx)(Sn,{size:14}):(0,M.jsx)(Cn,{size:14}),(0,M.jsx)(`span`,{children:m?`Hide hidden`:`Show hidden`})]}),(0,M.jsx)(`span`,{className:`add-project-dialog-path-display`,children:re})]}),u&&(0,M.jsx)(`div`,{className:`add-project-dialog-error`,children:u}),(0,M.jsx)(`div`,{className:`add-project-dialog-list`,children:c?(0,M.jsx)(`div`,{className:`add-project-dialog-empty`,children:`Loading…`}):ne.length===0?(0,M.jsx)(`div`,{className:`add-project-dialog-empty`,children:D?`No matching directories`:`Empty directory`}):ne.map((e,t)=>(0,M.jsxs)(`div`,{className:`add-project-dialog-entry`+(t===f?` highlighted`:``),onMouseEnter:()=>p(t),onClick:()=>k(e.path),children:[(0,M.jsx)(gn,{size:14,className:`add-project-dialog-entry-arrow`}),(0,M.jsx)(wn,{size:14,className:`add-project-dialog-entry-folder`}),(0,M.jsx)(`span`,{className:`add-project-dialog-entry-name`,children:e.name}),(0,M.jsx)(`button`,{className:`add-project-dialog-entry-add`,onClick:t=>{t.stopPropagation(),ae(e.path)},title:`Add as project`,children:(0,M.jsx)(An,{size:14})})]},e.path))})]}),(0,M.jsx)(`div`,{className:`add-project-dialog-footer`,children:`↑↓ Navigate · Enter browse · + quick-add`})]})}):null}var Y9=class extends b.Component{constructor(e){super(e),this.state={error:null}}static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e,t){console.error(`[ErrorBoundary${this.props.label?`:${this.props.label}`:``}]`,e,t.componentStack)}handleRetry=()=>{this.setState({error:null})};render(){if(this.state.error===null)return this.props.children;let{error:e}=this.state,{compact:t}=this.props;return t?(0,M.jsxs)(`div`,{style:{padding:`12px`,margin:`8px`,borderRadius:`6px`,background:`var(--bg-glass, rgba(220,80,80,0.08))`,border:`1px solid var(--accent-red, #e06c75)`,fontSize:`12px`,color:`var(--text-secondary, #999)`,lineHeight:1.4},children:[(0,M.jsxs)(`div`,{style:{fontWeight:600,color:`var(--accent-red, #e06c75)`,marginBottom:4},children:[`⚠️ `,e.name??`Error`]}),(0,M.jsx)(`div`,{style:{marginBottom:8,wordBreak:`break-word`},children:e.message}),(0,M.jsx)(`button`,{onClick:this.handleRetry,style:{padding:`4px 10px`,fontSize:`11px`,borderRadius:`4px`,border:`1px solid var(--border, #444)`,background:`var(--bg-surface, #1e1e1e)`,color:`var(--text-primary, #ddd)`,cursor:`pointer`},children:`Retry`})]}):(0,M.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`center`,padding:`40px 24px`,height:`100%`,boxSizing:`border-box`},children:(0,M.jsxs)(`div`,{style:{maxWidth:480,width:`100%`,padding:`24px`,borderRadius:`8px`,background:`var(--bg-surface, #1e1e1e)`,border:`1px solid var(--border, #444)`},children:[(0,M.jsx)(`div`,{style:{fontSize:14,fontWeight:600,color:`var(--accent-red, #e06c75)`,marginBottom:8},children:`Something went wrong`}),(0,M.jsx)(`div`,{style:{fontSize:12,color:`var(--text-secondary, #999)`,marginBottom:4,fontFamily:`monospace`},children:e.name}),(0,M.jsx)(`div`,{style:{fontSize:13,color:`var(--text-primary, #ddd)`,marginBottom:20,lineHeight:1.5,wordBreak:`break-word`},children:e.message}),(0,M.jsxs)(`div`,{style:{display:`flex`,gap:8},children:[(0,M.jsx)(`button`,{onClick:this.handleRetry,style:{padding:`6px 16px`,fontSize:12,borderRadius:`6px`,border:`none`,background:`var(--accent-primary, #569cd6)`,color:`#fff`,cursor:`pointer`},children:`Retry`}),(0,M.jsx)(`button`,{onClick:()=>{this.setState({error:null}),window.location.reload()},style:{padding:`6px 16px`,fontSize:12,borderRadius:`6px`,border:`1px solid var(--border, #444)`,background:`transparent`,color:`var(--text-secondary, #999)`,cursor:`pointer`},children:`Reload page`})]})]})})}};function bre(e){let t=(0,b.useRef)(null),n=e.threshold||50;(0,b.useEffect)(()=>{let r=e=>{t.current={x:e.touches[0].clientX,y:e.touches[0].clientY}},i=r=>{if(!t.current)return;let i=t.current.x-r.changedTouches[0].clientX,a=t.current.y-r.changedTouches[0].clientY;Math.abs(i)>Math.abs(a)&&Math.abs(i)>n&&(i>0&&e.onSwipeLeft?e.onSwipeLeft():i<0&&e.onSwipeRight&&e.onSwipeRight()),t.current=null};return window.addEventListener(`touchstart`,r,{passive:!0}),window.addEventListener(`touchend`,i,{passive:!0}),()=>{window.removeEventListener(`touchstart`,r),window.removeEventListener(`touchend`,i)}},[e.onSwipeLeft,e.onSwipeRight,n])}var X9=new Set,Z9=!1,Q9=[`var(--accent)`,`#d19a66`,`#56b6c2`,`#c678dd`,`#e5c07b`,`#98c379`,`#e06c75`,`#61afef`];function xre(e){let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n),t|=0;return Q9[Math.abs(t)%Q9.length]}function Sre(){let e=tn(e=>e.activeSessionId),t=tn(e=>e.activeProjectId);tn(e=>e.sessions);let n=tn(e=>e.projects),r=tn(e=>e.projectSessions),i=tn(e=>e.loadProjects),a=tn(e=>e.setActiveProject),o=tn(e=>e.createAndActivate),s=tn(e=>e.setActiveSession);tn(e=>e.refreshSessions);let c=tn(e=>e.streamState.isStreaming),[l,u]=(0,b.useState)(!1),[d,f]=(0,b.useState)(``),[p,m]=(0,b.useState)(),[h,g]=(0,b.useState)(!0),[_,v]=(0,b.useState)(!1),[y,x]=(0,b.useState)(``),[S,C]=(0,b.useState)(``),[w,ee]=(0,b.useState)([]),[T,E]=(0,b.useState)(),[te,ne]=(0,b.useState)(new Set),[O,re]=(0,b.useState)(!1),[k,ie]=(0,b.useState)(!1),[ce,le]=(0,b.useState)(),[ue,de]=(0,b.useState)(``),[fe,pe]=(0,b.useState)(),[me,he]=(0,b.useState)(),[ge,_e]=(0,b.useState)(!1),[ve,ye]=(0,b.useState)(void 0),[be,xe]=(0,b.useState)(void 0),[Se,Ce]=(0,b.useState)(!1),[we,Te]=(0,b.useState)(!1),[Ee,De]=(0,b.useState)(!1),[Oe,ke]=(0,b.useState)(new Set),Ae=(0,b.useRef)(null),je=Nx(e),[Ne,Pe]=(0,b.useState)(window.innerWidth<=600);(0,b.useEffect)(()=>{let e=()=>Pe(window.innerWidth<=600);return window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[]),bre({onSwipeLeft:()=>v(!0),onSwipeRight:()=>v(!1),threshold:60}),(0,b.useEffect)(()=>{(async()=>{try{let{authEnabled:e}=await oe();if(e&&(typeof localStorage<`u`?localStorage.getItem(`pi-kot/auth-token`):null)===null){u(!0),g(!1);return}await i()}catch{}try{let e=await Me();ee(e.providers);let t=e.providers.flatMap(e=>e.models),n=!1;try{let e=localStorage.getItem(`pi-kot-model`);if(e){let r=JSON.parse(e),i=t.find(e=>e.id===r.modelId&&e.hasAuth);i&&(x(i.id),C(r.provider),n=!0)}}catch{}if(!n){let n=t.find(e=>e.hasAuth);n?(x(n.id),C(e.providers.find(e=>e.models.some(e=>e.id===n.id))?.provider??``)):t.length>0&&(x(t[0].id),C(e.providers[0]?.provider??``))}}catch{}g(!1)})()},[]),(0,b.useEffect)(()=>{t!==void 0&&ne(e=>new Set(e).add(t))},[t]),(0,b.useEffect)(()=>{if(h||l||n.length===0||t===void 0)return;let i=r[t];if(i!==void 0&&!Z9){if(Z9=!0,e!==void 0){if(!i.some(t=>t.sessionId===e)){try{localStorage.removeItem(`pi-kot/active-session-id`)}catch{}tn.setState({activeSessionId:void 0});return}tn.getState().sseClient===void 0&&s(e);return}i.length>0?s(i[0].sessionId):X9.has(t)||(X9.add(t),o(t))}},[h,l,t,r,e]),(0,b.useEffect)(()=>{e&&(async()=>{try{let t=await Ke(e);if(t.provider&&t.modelId){x(t.modelId),C(t.provider);try{localStorage.setItem(`pi-kot-model`,JSON.stringify({modelId:t.modelId,provider:t.provider}))}catch{}}}catch{}})()},[e]),(0,b.useEffect)(()=>{let n=t,r=e,i;i=n&&r?`#/project/${n}/session/${r}`:n?`#/project/${n}`:`#`,window.location.hash!==i&&history.replaceState(null,``,i)},[t,e]),(0,b.useEffect)(()=>{let e=()=>{let e=window.location.hash.match(/^#\/project\/([^/]+)(?:\/session\/([^/]+))?$/);if(!e)return;let t=e[1],n=e[2]??void 0,r=tn.getState();n&&n!==r.activeSessionId&&Object.values(r.projectSessions).some(e=>e.some(e=>e.sessionId===n))&&(t===r.activeProjectId?r.setActiveSession(n):r.setActiveProject(t).then(()=>{r.setActiveSession(n)}))};return window.addEventListener(`hashchange`,e),()=>window.removeEventListener(`hashchange`,e)},[]),(0,b.useEffect)(()=>D(()=>{f(``),m(void 0),u(!0)}),[]);let Fe=(0,b.useCallback)(()=>{ae(),f(``),m(void 0),u(!0)},[]);(0,b.useEffect)(()=>{let e=Object.values(r).flat(),t=new Set(Oe);e.filter(e=>e.supervisorId&&e.isLive).forEach(e=>t.add(e.supervisorId)),ke(t)},[r]);let Ie=async()=>{try{await se(d),m(void 0),u(!1),await i()}catch{m(`Invalid password`)}},Le=(0,b.useCallback)(()=>{v(e=>(e&&xe(void 0),!e))},[]),Re=(0,b.useCallback)(()=>{window.innerWidth<=600&&v(!0)},[]),ze=(0,b.useCallback)((e,t)=>{x(e),C(t),E(void 0);try{localStorage.setItem(`pi-kot-model`,JSON.stringify({modelId:e,provider:t}))}catch{}},[]),Be=(0,b.useCallback)(e=>{E(e)},[]),Ve=e=>{ne(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return h?(0,M.jsx)(`div`,{className:`centered`,children:(0,M.jsxs)(`div`,{style:{width:`100%`,maxWidth:400,display:`flex`,flexDirection:`column`,gap:24},children:[(0,M.jsx)(jx,{variant:`card`,count:2}),(0,M.jsx)(jx,{variant:`list`,count:4})]})}):l?(0,M.jsx)(`div`,{className:`centered`,children:(0,M.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),Ie()},className:`login-form`,children:[(0,M.jsx)(`h2`,{className:`login-title`,children:`pi-kot`}),(0,M.jsx)(`input`,{type:`password`,value:d,onChange:e=>{f(e.target.value),m(void 0)},placeholder:`Enter password`,autoFocus:!0,autoComplete:`new-password`,className:`login-input${p?` login-input-error`:``}`}),p&&(0,M.jsx)(`div`,{className:`login-error`,children:p}),(0,M.jsx)(`button`,{type:`submit`,className:`login-btn`,children:`Login`}),(0,M.jsx)(`button`,{type:`button`,onClick:Fe,className:`login-btn`,style:{background:`none`,border:`1px solid var(--border-color, #444)`,color:`var(--text-dim, #888)`,fontSize:`11px`,marginTop:`4px`},children:`Clear stored token`})]})}):(0,M.jsxs)(`div`,{className:`app-layout`,children:[!_&&(0,M.jsx)(`div`,{className:`sidebar-backdrop`,onClick:()=>v(!0),"aria-hidden":`true`}),(0,M.jsxs)(`div`,{className:`sidebar${_?` collapsed`:``}`,children:[(0,M.jsxs)(`div`,{className:`sidebar-header`,style:{display:`flex`,justifyContent:`space-between`,alignItems:`center`},children:[(0,M.jsx)(`span`,{style:{fontSize:`14px`,fontWeight:700,color:`var(--accent-text)`},children:`pi-kot`}),(0,M.jsx)(`button`,{onClick:()=>re(!0),title:`Add a new project`,style:{background:`transparent`,border:`1px solid var(--border)`,color:`var(--text-secondary)`,fontSize:`11px`,fontWeight:600,textTransform:`uppercase`,letterSpacing:`0.05em`,cursor:`pointer`,lineHeight:1,padding:`4px 8px`,borderRadius:`var(--radius-sm)`,transition:`all var(--duration) var(--ease)`},onMouseOver:e=>{e.currentTarget.style.color=`var(--text-primary)`,e.currentTarget.style.background=`var(--bg-glass-hover)`},onMouseOut:e=>{e.currentTarget.style.color=`var(--text-secondary)`,e.currentTarget.style.background=`transparent`},children:`Add Project`})]}),(0,M.jsx)(`div`,{className:`project-list`,children:n.map(n=>{let i=n.id===t,l=te.has(n.id),u=r[n.id]??[];return(0,M.jsxs)(`div`,{className:`project-group${i?` active`:``}`,children:[(0,M.jsxs)(`div`,{className:`project-row${i?` active`:``}`,onClick:()=>{i?Ve(n.id):a(n.id)},role:`button`,tabIndex:0,children:[(0,M.jsxs)(`span`,{className:`project-icon`,children:[(0,M.jsx)(`svg`,{className:`project-icon-folder`,width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,style:{color:xre(n.id)},children:(0,M.jsx)(`path`,{d:`M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z`})}),(0,M.jsx)(`svg`,{className:`project-icon-arrow`,width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,M.jsx)(`path`,{d:`M9 18l6-6-6-6`})})]}),(0,M.jsx)(`span`,{className:`project-name`,children:n.name.toLowerCase()}),(0,M.jsx)(`div`,{className:`project-actions-left`,children:n.name!==`Default`&&(0,M.jsx)(`button`,{onClick:e=>{e.stopPropagation(),he(n.id)},className:`project-action-btn`,title:`Remove from sidebar`,children:(0,M.jsxs)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,M.jsx)(`polygon`,{points:`5 14 12 5 19 14`}),(0,M.jsx)(`line`,{x1:`4`,y1:`19`,x2:`20`,y2:`19`})]})})}),(0,M.jsx)(`div`,{className:`project-actions-right`,children:(0,M.jsx)(`button`,{onClick:e=>{e.stopPropagation(),o(n.id)},className:`project-action-btn`,title:`New draft session`,children:(0,M.jsxs)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,M.jsx)(`line`,{x1:`12`,y1:`5`,x2:`12`,y2:`19`}),(0,M.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`})]})})})]}),l&&(0,M.jsx)(_re,{projectId:n.id,sessions:u,activeSessionId:e,isStreaming:c,renamingSessionId:ce,renameValue:ue,renameInputRef:Ae,expandedWorkerGroups:Oe,onSelect:e=>{s(e),Re()},onRenameStart:(e,t)=>{le(e),de(t),setTimeout(()=>Ae.current?.focus(),50)},onRenameChange:de,onRenameCommit:(e,t)=>{let n=ue.trim();n.length>0&&n!==t&&tn.getState().renameSession(e,n),le(void 0)},onRenameCancel:()=>le(void 0),onToggleWorkerGroup:e=>{ke(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},onNewSession:()=>{o(n.id),Re()}})]},n.id)})}),t!==void 0&&(0,M.jsxs)(M.Fragment,{children:[(0,M.jsxs)(`div`,{className:`archived-toggle`,onClick:()=>{let e=fe===t?void 0:t;e!==void 0&&tn.getState().loadArchivedSessions(t),pe(e)},children:[(0,M.jsx)(`span`,{className:`project-chevron`,children:fe===t?`▾`:`▸`}),(0,M.jsx)(`span`,{className:`project-name`,style:{fontSize:`12px`},children:`Archived`})]}),fe===t&&(()=>{let e=tn.getState().archivedSessions[t];return e===void 0?(0,M.jsx)(`div`,{className:`archived-status`,children:(0,M.jsx)(jx,{variant:`list`,count:2})}):e.length===0?(0,M.jsx)(`div`,{className:`archived-status`,children:`No archived sessions`}):(0,M.jsx)(`div`,{className:`session-list project-sublist archived-list`,children:e.map(e=>(0,M.jsxs)(`div`,{className:`session-item archived`,children:[(0,M.jsx)(`span`,{className:`session-name`,children:e.name??`Session ${e.sessionId.slice(0,8)}`}),(0,M.jsx)(`button`,{className:`session-restore-btn`,title:`Restore session`,onClick:n=>{n.stopPropagation(),tn.getState().unarchiveSession(e.sessionId,t)},children:`↻`})]},e.sessionId))})})()]}),(0,M.jsx)(`div`,{className:`sidebar-footer`,children:(0,M.jsxs)(`div`,{className:`mobile-only`,style:{display:`flex`,flexDirection:`column`,gap:`4px`},children:[(0,M.jsxs)(`button`,{type:`button`,onClick:()=>{Te(!0),v(!0)},className:`add-project-toggle`,style:{display:`flex`,alignItems:`center`,gap:`8px`},children:[(0,M.jsxs)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,M.jsx)(`path`,{d:`M12 2L2 7l10 5 10-5-10-5z`}),(0,M.jsx)(`path`,{d:`M2 17l10 5 10-5`}),(0,M.jsx)(`path`,{d:`M2 12l10 5 10-5`})]}),`MCP Settings`]}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>{_e(!0),v(!0)},className:`add-project-toggle`,style:{display:`flex`,alignItems:`center`,gap:`8px`},children:`⚙ Settings`}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>{Fe(),v(!0)},className:`add-project-toggle`,style:{display:`flex`,alignItems:`center`,gap:`8px`,color:`var(--text-secondary)`},children:`Sign out`})]})})]}),(0,M.jsxs)(`div`,{className:`main-area`,children:[(0,M.jsxs)(`div`,{className:`header`,children:[(0,M.jsxs)(`div`,{className:`header-left`,children:[(0,M.jsx)(`button`,{type:`button`,onClick:Le,className:`sidebar-toggle`,title:_?`Show sidebar`:`Hide sidebar`,children:_?`☰`:`✕`}),e!==void 0&&(0,M.jsxs)(M.Fragment,{children:[(0,M.jsxs)(`span`,{style:{fontSize:`13px`,fontWeight:500,color:`var(--text-secondary)`,marginLeft:`8px`},children:[`Session `,e.slice(0,8)]}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>ie(!0),title:`Session tree (branching history)`,style:{background:`none`,border:`none`,color:`var(--text-dim)`,fontSize:`12px`,cursor:`pointer`,padding:`3px 6px`,borderRadius:`var(--radius-sm)`,lineHeight:1},children:`🌿`})]})]}),(0,M.jsxs)(`div`,{className:`header-right`,children:[(0,M.jsx)(Px,{data:je,onInspect:e=>ye(e)}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>{let e=be===void 0;xe(be===`files`?void 0:`files`),e&&v(!0)},title:`File explorer`,style:{background:`none`,border:`none`,color:be===`files`?`var(--accent-text)`:`var(--text-dim)`,fontSize:`12px`,cursor:`pointer`,padding:`3px 6px`,borderRadius:`var(--radius-sm)`,lineHeight:1},children:`📂`}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>{De(!0),v(!0)},title:`Terminal`,style:{background:`none`,border:`none`,color:Ee?`var(--accent-text)`:`var(--text-dim)`,fontSize:`12px`,cursor:`pointer`,padding:`3px 6px`,borderRadius:`var(--radius-sm)`,lineHeight:1},children:`>_`}),(0,M.jsxs)(`div`,{className:`header-overflow desktop-only`,children:[(0,M.jsx)(`button`,{type:`button`,onClick:()=>Te(!0),title:`MCP Settings`,style:{background:`none`,border:`none`,color:we?`var(--accent-text)`:`var(--text-dim)`,fontSize:`12px`,cursor:`pointer`,padding:`3px 6px`,borderRadius:`var(--radius-sm)`,lineHeight:1},children:(0,M.jsxs)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,M.jsx)(`path`,{d:`M12 2L2 7l10 5 10-5-10-5z`}),(0,M.jsx)(`path`,{d:`M2 17l10 5 10-5`}),(0,M.jsx)(`path`,{d:`M2 12l10 5 10-5`})]})}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>_e(!0),title:`Settings`,style:{background:`none`,border:`none`,color:ge?`var(--accent-text)`:`var(--text-dim)`,fontSize:`14px`,cursor:`pointer`,padding:`3px 6px`,borderRadius:`var(--radius-sm)`,lineHeight:1},children:`⚙`}),(0,M.jsx)(`button`,{type:`button`,onClick:Fe,title:`Sign out (clear stored token)`,style:{background:`none`,border:`none`,color:`var(--text-dim)`,fontSize:`12px`,cursor:`pointer`,padding:`3px 6px`,borderRadius:`var(--radius-sm)`,lineHeight:1},children:`Sign out`})]})]})]}),T!==void 0&&(0,M.jsxs)(`div`,{onClick:()=>E(void 0),className:`error-banner`,style:{position:`absolute`,top:`52px`,left:`16px`,right:`16px`,zIndex:9,cursor:`pointer`},children:[T,` — click to dismiss`]}),e===void 0?(0,M.jsx)(`div`,{className:`centered`,style:{height:`100%`},children:(0,M.jsxs)(`div`,{className:`welcome`,children:[(0,M.jsx)(`div`,{className:`welcome-icon`,children:`⌨️`}),(0,M.jsx)(`div`,{className:`welcome-text`,children:`Select or create a session`}),(0,M.jsx)(`div`,{className:`welcome-hint`,children:`to start chatting with the coding agent`})]})}):(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(Y9,{label:`ChatView`,compact:!0,children:(0,M.jsx)(xx,{sessionId:e,modelName:y||void 0,providerName:S||void 0})}),(0,M.jsx)(Y9,{label:`OrchestrationPanel`,compact:!0,children:(0,M.jsx)(Mx,{sessionId:e,open:Se,onClose:()=>Ce(!1)})}),(0,M.jsx)(Ex,{sessionId:e}),(0,M.jsx)(Tx,{sessionId:e,showOrch:Se,setShowOrch:Ce,selectedModel:y,onModelSelect:ze,onModelError:Be})]})]}),e!==void 0&&t!==void 0&&(0,M.jsx)(Y9,{label:`SessionTreePanel`,compact:!0,children:(0,M.jsx)($x,{sessionId:e,projectId:t,open:k,onClose:()=>ie(!1)})}),t!==void 0&&(0,M.jsx)(Y9,{label:`FileExplorer`,compact:!0,children:(0,M.jsx)(v2,{projectId:t,open:be!==void 0,onClose:()=>xe(void 0),initialTab:be})}),me!==void 0&&(0,M.jsx)(`div`,{className:`settings-overlay`,onClick:()=>he(void 0),children:(0,M.jsxs)(`div`,{className:`settings-panel rewind-panel`,onClick:e=>e.stopPropagation(),style:{width:420,maxWidth:`90vw`,height:`auto`,minHeight:0},children:[(0,M.jsxs)(`header`,{className:`settings-header`,children:[(0,M.jsx)(`span`,{style:{fontSize:14,fontWeight:600},children:`Remove project?`}),(0,M.jsx)(`button`,{onClick:()=>he(void 0),className:`settings-close`,title:`Close`,children:`✕`})]}),(0,M.jsxs)(`div`,{className:`settings-body`,style:{padding:`16px`},children:[(0,M.jsxs)(`p`,{style:{fontSize:13,color:`var(--text-secondary)`,marginBottom:20,lineHeight:1.5},children:[`This removes `,(0,M.jsx)(`strong`,{children:n.find(e=>e.id===me)?.name??me}),` from the sidebar — all sessions stay safely on disk. You can add it back anytime.`]}),(0,M.jsxs)(`div`,{style:{display:`flex`,gap:8,justifyContent:`flex-end`},children:[(0,M.jsx)(`button`,{onClick:()=>he(void 0),className:`settings-tab`,style:{padding:`6px 14px`,fontSize:12},children:`Cancel`}),(0,M.jsx)(`button`,{onClick:()=>{tn.getState().deleteProject(me),he(void 0)},className:`settings-tab settings-tab-active`,style:{padding:`6px 14px`,fontSize:12,background:`var(--accent-red, #e06c75)`,color:`#fff`,border:`none`},children:`Remove`})]})]})]})}),ge&&(0,M.jsx)(Y9,{label:`SettingsPanel`,compact:!0,children:(0,M.jsx)(zS,{onClose:()=>_e(!1)})}),ve!==void 0&&(0,M.jsx)(Ix,{data:ve,onClose:()=>ye(void 0),sessionId:e}),(0,M.jsx)(Y9,{label:`TerminalPanel`,compact:!0,children:(0,M.jsx)(cre,{open:Ee,onClose:()=>De(!1)})}),we&&(0,M.jsx)(Y9,{label:`MCPPanel`,compact:!0,children:(0,M.jsx)(Gx,{onClose:()=>Te(!1)})}),e!==void 0&&(0,M.jsx)(dre,{sessionId:e}),(0,M.jsx)(fre,{}),O&&(0,M.jsx)(yre,{open:O,onClose:()=>re(!1)})]})}SS(xS());var $9=document.getElementById(`root`);if($9===null)throw Error(`root element not found`);(0,ee.createRoot)($9).render((0,M.jsx)(b.StrictMode,{children:(0,M.jsx)(Sre,{})}));
431
- //# sourceMappingURL=index-DRvWtJ8F.js.map
431
+ //# sourceMappingURL=index-DOXZHHGF.js.map