pi-forge 1.3.4 → 1.3.5
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 +1 -1
- package/dist/client/assets/{CodeMirrorEditor-B4s5rJXF.js → CodeMirrorEditor-iLMm0PBW.js} +2 -2
- package/dist/client/assets/{CodeMirrorEditor-B4s5rJXF.js.map → CodeMirrorEditor-iLMm0PBW.js.map} +1 -1
- package/dist/client/assets/{index-x-u_kklU.js → index-ChVHn55j.js} +20 -20
- package/dist/client/assets/{index-x-u_kklU.js.map → index-ChVHn55j.js.map} +1 -1
- package/dist/client/assets/index-D311Lak3.css +1 -0
- package/dist/client/index.html +2 -2
- package/dist/client/sw.js +1 -1
- package/dist/client/sw.js.map +1 -1
- package/dist/server/routes/projects.js +13 -8
- package/dist/server/routes/projects.js.map +1 -1
- package/package.json +1 -1
- package/dist/client/assets/index-VyHgL4FY.css +0 -1
|
@@ -340,36 +340,36 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
|
340
340
|
`)+`
|
|
341
341
|
`}function yk(e){try{return NC(e)}catch{return[]}}function bk(e){return e.length>0&&e.some(e=>e.hunks.length>0)}function xk(e){let t=/^@@ /m.test(e),n=/^--- /m.test(e)&&/^\+\+\+ /m.test(e);return t&&!n}function Sk({diff:e}){return(0,R.jsx)(`pre`,{className:`overflow-auto px-3 pb-2 font-mono text-[11px] leading-tight`,children:e.split(`
|
|
342
342
|
`).map((e,t)=>(0,R.jsx)(`div`,{className:Ck(e),children:e.length===0?`\xA0`:e},t))})}function Ck(e){return e.startsWith(`+++`)||e.startsWith(`---`)?`text-neutral-500`:e.startsWith(`@@`)?`bg-neutral-900 text-cyan-400 light:text-cyan-700`:e.startsWith(`+`)?`bg-emerald-950/60 text-emerald-200 light:bg-emerald-50 light:text-emerald-800`:e.startsWith(`-`)?`bg-red-950/60 text-red-200 light:bg-red-50 light:text-red-800`:`text-neutral-400`}var wk=`pi-forge/model/`,Tk=`pi-forge/sessionTree.view`;function Ek({sessionId:e,projectId:t,onClose:n}){let r=Jr(t=>t.streamingBySession[e]??!1),i=Jr(e=>e.setActiveSession),a=Jr(e=>e.loadSessionsForProject),o=Jr(e=>e.reloadMessages),s=Jr(e=>e.setPendingDraft),c=Jr(t=>t.agentEndCountBySession[e]??0),[l,u]=(0,v.useState)(void 0),[d,f]=(0,v.useState)(!0),[p,m]=(0,v.useState)(void 0),[h,g]=(0,v.useState)(!1),[_,y]=(0,v.useState)(void 0),b=async()=>{f(!0),m(void 0);try{u(await L.getSessionTree(e))}catch(e){m(e instanceof N?e.code:e.message)}finally{f(!1)}};(0,v.useEffect)(()=>{b()},[e]),(0,v.useEffect)(()=>{c!==0&&b()},[c]);let x=(0,v.useMemo)(()=>l===void 0?[]:Fk(l),[l]),[S,C]=(0,v.useState)(()=>{try{return localStorage.getItem(Tk)===`list`?`list`:`graph`}catch{return`graph`}}),w=e=>{C(e);try{localStorage.setItem(Tk,e)}catch{}},T=e=>{if(h||l?.leafId===e)return;let t=Nk(l,e);if(r||t){y({entryId:e,abandonsBranch:t,isStreaming:r});return}E(e,{})},E=async(t,n)=>{g(!0),m(void 0);try{await L.navigateSession(e,t,n),await b(),o(e)}catch(e){m(e instanceof N?e.code:e.message)}finally{g(!1)}},D=async(r,o={})=>{if(!h){g(!0),m(void 0);try{let c=o.parentId!==void 0&&o.parentId!==null?o.parentId:r,l=await L.forkSession(e,c);try{let t=localStorage.getItem(wk+e);t!==null&&t.length>0&&localStorage.setItem(wk+l.sessionId,t)}catch{}o.editDraft!==void 0&&o.editDraft.length>0&&s(l.sessionId,o.editDraft),await a(t),i(l.sessionId),n()}catch(e){m(e instanceof N?e.code:e.message),g(!1)}}};return(0,R.jsxs)(`div`,{className:`fixed inset-0 z-40 flex items-center justify-center bg-black/60 px-4 py-8`,onClick:n,children:[(0,R.jsxs)(`div`,{onClick:e=>e.stopPropagation(),className:`flex h-[min(90vh,900px)] w-[min(95vw,1400px)] flex-col overflow-hidden rounded-lg border border-neutral-800 bg-neutral-950 shadow-2xl`,children:[(0,R.jsxs)(`header`,{className:`flex items-center justify-between border-b border-neutral-800 px-4 py-2.5`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,R.jsx)(De,{size:14,className:`text-neutral-400`}),(0,R.jsx)(`h2`,{className:`text-sm font-semibold text-neutral-100`,children:`Session tree`}),h&&(0,R.jsx)(Ne,{size:11,className:`animate-spin text-neutral-500`})]}),(0,R.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,R.jsxs)(`div`,{className:`mr-1 flex overflow-hidden rounded border border-neutral-700`,children:[(0,R.jsx)(`button`,{onClick:()=>w(`list`),className:`px-2 py-0.5 text-[10px] uppercase tracking-wider ${S===`list`?`bg-neutral-700 text-neutral-100`:`text-neutral-400 hover:bg-neutral-800`}`,title:`Vertical list view`,children:`List`}),(0,R.jsx)(`button`,{onClick:()=>w(`graph`),className:`px-2 py-0.5 text-[10px] uppercase tracking-wider ${S===`graph`?`bg-neutral-700 text-neutral-100`:`text-neutral-400 hover:bg-neutral-800`}`,title:`Branching graph view (turn-grouped)`,children:`Graph`})]}),(0,R.jsx)(`button`,{onClick:()=>void b(),disabled:d||h,className:`rounded p-1 text-neutral-400 hover:bg-neutral-800 hover:text-neutral-200 disabled:opacity-40`,title:`Refresh tree`,children:(0,R.jsx)(Ue,{size:13,className:d?`animate-spin`:``})}),(0,R.jsx)(`button`,{onClick:n,className:`rounded p-2 text-neutral-400 hover:bg-neutral-800 hover:text-neutral-200`,title:`Close (Esc)`,children:(0,R.jsx)(it,{size:20})})]})]}),p!==void 0&&(0,R.jsx)(`div`,{className:`border-b border-red-700/40 bg-red-900/20 px-4 py-1.5 text-xs text-red-300 light:border-red-300 light:bg-red-50 light:text-red-700`,children:p}),(0,R.jsxs)(`div`,{className:`flex-1 overflow-y-auto px-2 py-2`,children:[d&&l===void 0&&(0,R.jsx)(`div`,{className:`px-4 py-6 text-center text-xs italic text-neutral-500`,children:`Loading tree…`}),!d&&x.length===0&&(0,R.jsx)(`div`,{className:`px-4 py-6 text-center text-xs italic text-neutral-500`,children:`No entries yet.`}),S===`list`?(0,R.jsx)(`ul`,{className:`space-y-0.5`,children:x.map(e=>(0,R.jsx)(Mk,{node:e,disabled:h,onNavigate:()=>void T(e.id),onFork:()=>void D(e.id,{...e.type===`message`&&e.role===`user`?{editDraft:e.preview??``,parentId:e.parentId}:{}})},e.id))}):l===void 0?null:(0,R.jsx)(Gk,{tree:l,disabled:h,onNavigate:e=>T(e),onForkAfterTurn:e=>void D(e)})]}),(0,R.jsxs)(`footer`,{className:`flex items-center justify-between border-t border-neutral-800 bg-neutral-900/40 px-4 py-2 text-[10px] text-neutral-500`,children:[(0,R.jsx)(`span`,{children:`Click a row to navigate · fork icon on user messages to branch from that point`}),l!==void 0&&(0,R.jsxs)(`span`,{children:[l.entries.length,` `,l.entries.length===1?`entry`:`entries`]})]})]}),(0,R.jsx)(Dk,{state:_,onCancel:()=>y(void 0),onConfirm:e=>{if(_===void 0)return;let{entryId:t}=_;y(void 0),E(t,e)}})]})}function Dk({state:e,onCancel:t,onConfirm:n}){let[r,i]=(0,v.useState)(``),[a,o]=(0,v.useState)(!1),[s,c]=(0,v.useState)(``),l=(0,v.useRef)(null);(0,v.useEffect)(()=>{e!==void 0&&(i(``),o(!1),c(``))},[e]);let u=e!==void 0,d=e?.abandonsBranch===!0,f=()=>{let e={},t=r.trim();if(t.length>0&&(e.label=t),a){e.summarize=!0;let t=s.trim();t.length>0&&(e.customInstructions=t)}n(e)};return(0,R.jsx)(wi,{open:u,onClose:t,title:`Navigate session leaf`,width:d?`max-w-md`:`max-w-sm`,...d?{initialFocusRef:l}:{},children:(0,R.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),f()},className:`flex flex-col gap-3 px-4 py-3 text-xs text-neutral-200`,children:[e?.isStreaming===!0&&(0,R.jsx)(`p`,{className:`rounded border border-amber-700/50 bg-amber-900/20 px-2 py-1.5 text-amber-200 light:border-amber-300 light:bg-amber-50 light:text-amber-800`,children:`The agent is currently running. Navigating will abort the in-progress turn.`}),d?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`p`,{className:`text-neutral-400`,children:`You’re leaving the current branch behind. The tip stays on the tree (you can navigate back to it any time), but you can also bookmark + summarize it before moving on.`}),(0,R.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,R.jsxs)(`span`,{className:`text-neutral-500`,children:[`Label for the abandoned branch tip`,` `,(0,R.jsx)(`span`,{className:`text-neutral-600`,children:`(optional)`})]}),(0,R.jsx)(`input`,{ref:l,type:`text`,value:r,onChange:e=>i(e.target.value),placeholder:`e.g. wrong-approach`,maxLength:200,className:`rounded border border-neutral-700 bg-neutral-950 px-2 py-1 text-neutral-100 outline-none focus:border-neutral-500`})]}),(0,R.jsxs)(`label`,{className:`flex items-start gap-2 rounded border border-neutral-800 bg-neutral-950 px-2 py-1.5`,children:[(0,R.jsx)(`input`,{type:`checkbox`,checked:a,onChange:e=>o(e.target.checked),className:`mt-0.5 h-3 w-3`}),(0,R.jsxs)(`span`,{className:`flex-1 text-neutral-300`,children:[`Have pi write a `,(0,R.jsx)(`code`,{className:`font-mono text-[11px]`,children:`branch_summary`}),` entry capturing what this branch did. Costs one extra LLM call.`]})]}),a&&(0,R.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,R.jsxs)(`span`,{className:`text-neutral-500`,children:[`Custom summarizer instructions`,` `,(0,R.jsx)(`span`,{className:`text-neutral-600`,children:`(optional)`})]}),(0,R.jsx)(`textarea`,{value:s,onChange:e=>c(e.target.value),rows:3,placeholder:`e.g. Focus on what files were changed and why`,className:`rounded border border-neutral-700 bg-neutral-950 px-2 py-1 font-mono text-[11px] text-neutral-100 outline-none focus:border-neutral-500`})]})]}):(0,R.jsx)(`p`,{className:`text-neutral-400`,children:`Confirm navigation?`}),(0,R.jsxs)(`footer`,{className:`flex justify-end gap-2 pt-1`,children:[(0,R.jsx)(`button`,{type:`button`,onClick:t,className:`rounded-md border border-neutral-700 px-3 py-1 text-xs text-neutral-200 hover:bg-neutral-800`,children:`Cancel`}),(0,R.jsx)(`button`,{type:`submit`,className:`rounded-md px-3 py-1 text-xs font-medium ${e?.isStreaming===!0?`bg-amber-600 text-amber-50 hover:bg-amber-500 light:bg-amber-500 light:text-white light:hover:bg-amber-600`:`bg-neutral-100 text-neutral-900 hover:bg-white`}`,children:e?.isStreaming===!0?`Abort & navigate`:`Navigate`})]})]})})}var Ok=4,kk=18,Ak=10,jk=8;function Mk({node:e,disabled:t,onNavigate:n,onFork:r}){let i=Math.min(e.depth,Ok)*kk+Math.min(e.branchLevel,jk)*Ak,a=e.type===`message`&&e.role===`user`,o=!e.onActivePath,s=Rk(e);return(0,R.jsx)(`li`,{className:`group min-w-0`,style:{paddingLeft:`${i}px`},children:(0,R.jsxs)(`div`,{className:`flex min-w-0 items-start gap-1.5 rounded border px-2 py-1.5 ${e.isLeaf?`border-emerald-700/60 bg-emerald-900/10`:e.onActivePath?`border-neutral-700 bg-neutral-900/40`:`border-neutral-800/50 bg-transparent`} ${o?`opacity-60`:``}`,style:e.branchLevel>0?{boxShadow:`inset 3px 0 0 ${Lk(e.branchLevel)}`}:void 0,children:[(0,R.jsxs)(`div`,{className:`flex shrink-0 items-center gap-0.5 pt-0.5`,children:[e.isLeaf?(0,R.jsx)(`span`,{className:`inline-block w-[22px]`,"aria-hidden":`true`}):(0,R.jsx)(`button`,{onClick:n,disabled:t,className:`rounded p-1 text-neutral-500 hover:bg-neutral-800 hover:text-neutral-100 disabled:opacity-40`,title:`Navigate the session leaf to this entry`,children:(0,R.jsx)(ze,{size:11})}),a?(0,R.jsx)(`button`,{onClick:r,disabled:t,className:`rounded p-1 text-neutral-500 hover:bg-neutral-800 hover:text-emerald-300 disabled:opacity-40 light:hover:text-emerald-700`,title:`Fork BEFORE this message — opens a new session with the message text loaded into the input for editing.`,children:(0,R.jsx)(De,{size:11})}):(0,R.jsx)(`span`,{className:`inline-block w-[22px]`,"aria-hidden":`true`})]}),(0,R.jsxs)(`button`,{onClick:n,disabled:t||e.isLeaf,className:`flex min-w-0 flex-1 flex-col items-start gap-0.5 text-left disabled:cursor-default`,title:e.isLeaf?`Current leaf`:`Navigate the session leaf to this entry`,children:[(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,R.jsx)(`span`,{className:`rounded px-1.5 py-0.5 text-[9px] uppercase tracking-wider ${e.role===`user`?`bg-sky-900/40 text-sky-300 light:bg-sky-100 light:text-sky-800`:e.role===`assistant`?`bg-violet-900/40 text-violet-300 light:bg-violet-100 light:text-violet-800`:e.type===`branch_summary`?`bg-amber-900/40 text-amber-300 light:bg-amber-100 light:text-amber-800`:e.type===`compaction`?`bg-fuchsia-900/40 text-fuchsia-300 light:bg-fuchsia-100 light:text-fuchsia-800`:`bg-neutral-800 text-neutral-400`}`,children:s}),e.isBranchHead&&(0,R.jsxs)(`span`,{className:`rounded px-1.5 py-0.5 text-[9px] uppercase tracking-wider`,style:{background:`${Lk(e.branchLevel)}33`,color:Lk(e.branchLevel)},title:`First entry of a divergent branch`,children:[`branch `,e.branchLevel]}),e.label!==void 0&&e.label.length>0&&(0,R.jsxs)(`span`,{className:`rounded bg-neutral-800 px-1.5 py-0.5 text-[9px] text-neutral-300`,children:[`★ `,e.label]}),e.isLeaf&&(0,R.jsx)(`span`,{className:`rounded bg-emerald-900/40 px-1.5 py-0.5 text-[9px] text-emerald-300 light:bg-emerald-100 light:text-emerald-800`,children:`leaf`}),e.siblings>1&&(0,R.jsxs)(`span`,{className:`text-[9px] text-amber-400 light:text-amber-700`,title:`${e.siblings} branches diverge from this point`,children:[`⑂ `,e.siblings]}),(0,R.jsx)(`span`,{className:`text-[9px] text-neutral-600`,children:new Date(e.timestamp).toLocaleString()})]}),e.preview!==void 0&&(0,R.jsx)(`p`,{className:`w-full truncate text-[11px] text-neutral-300`,children:e.preview})]})]})})}function Nk(e,t){if(e===void 0||e.leafId===null||e.leafId===t)return!1;let n=new Map(e.entries.map(e=>[e.id,e])),r=e.leafId;for(;r!==null;){if(r===t)return!1;r=n.get(r)?.parentId??null}return!0}function Pk(e){return e.type!==`message`||e.role===`user`?0:e.role===`tool`?2:1}function Fk(e){let t=new Map;for(let n of e.entries){let e=t.get(n.parentId);e===void 0?t.set(n.parentId,[n]):e.push(n)}for(let e of t.values())e.sort((e,t)=>e.timestamp.localeCompare(t.timestamp));let n=new Set(e.branchIds),r=[],i=(a,o)=>{let s=t.get(a);if(s===void 0)return;let c=s.length;s.forEach((t,a)=>{let s=a===0?o:o+1,l=a>0&&s>0;r.push({...t,depth:Pk(t),branchLevel:s,onActivePath:n.has(t.id),isLeaf:e.leafId===t.id,siblings:c,isBranchHead:l}),i(t.id,s)})};return i(null,0),r}var Ik=[`#f59e0b`,`#0ea5e9`,`#ec4899`,`#10b981`,`#8b5cf6`,`#f97316`];function Lk(e){return e<=0?`transparent`:Ik[(e-1)%Ik.length]}function Rk(e){return e.type===`message`?e.role??`message`:e.type===`thinking_level_change`?`thinking`:e.type===`model_change`?`model`:e.type===`compaction`?`compact`:e.type===`branch_summary`?`branch`:e.type===`label`?`label`:e.type===`session_info`?`info`:e.type===`custom`?`custom`:e.type===`custom_message`?`extension`:e.type}var zk=220,Bk=78,Vk=64,Hk=28,Uk=24;function Wk(e){let t=new Map(e.entries.map(e=>[e.id,e])),n=new Map;for(let t of e.entries){let e=n.get(t.parentId);e===void 0?n.set(t.parentId,[t]):e.push(t)}for(let e of n.values())e.sort((e,t)=>e.timestamp.localeCompare(t.timestamp));let r=new Map,i=e=>{let n=r.get(e.id);if(n!==void 0)return n;if(e.type===`message`&&e.role===`user`||e.parentId===null)return r.set(e.id,e.id),e.id;let a=t.get(e.parentId);if(a===void 0)return r.set(e.id,e.id),e.id;let o=i(a);return r.set(e.id,o),o};for(let t of e.entries)i(t);let a=new Map;for(let t of e.entries){if(r.get(t.id)!==t.id)continue;let e=t.type===`message`&&t.role===`user`;a.set(t.id,{id:t.id,parentId:null,col:0,row:0,isOnActivePath:!1,isLeafTurn:!1,hasMultipleChildren:!1,childCount:0,roleLabel:e?`user`:Rk(t),preview:t.preview??``,insideCounts:{assistant:0,tool:0,thinking:0,meta:0},isUserAnchor:e,anchorParentId:t.parentId,lastEntryId:t.id,timestamp:t.timestamp})}for(let n of e.entries){let e=r.get(n.id),i=a.get(e);if(i===void 0)continue;let o=t.get(i.lastEntryId);(o===void 0||n.timestamp.localeCompare(o.timestamp)>0)&&(i.lastEntryId=n.id),e!==n.id&&(n.type===`message`&&n.role===`assistant`?i.insideCounts.assistant+=1:n.type===`message`&&(n.role===`tool`||n.role===`toolResult`)?i.insideCounts.tool+=1:(n.type===`message`&&n.role,i.insideCounts.meta+=1))}for(let e of a.values()){if(e.anchorParentId===null)continue;let t=r.get(e.anchorParentId);t!==void 0&&t!==e.id&&(e.parentId=t)}let o=new Map;for(let e of a.values()){let t=o.get(e.parentId);t===void 0?o.set(e.parentId,[e]):t.push(e)}for(let e of o.values())e.sort((e,t)=>e.timestamp.localeCompare(t.timestamp));for(let e of a.values()){let t=o.get(e.id)??[];e.childCount=t.length,e.hasMultipleChildren=t.length>1}let s=new Set(e.branchIds),c=e.leafId===null?void 0:r.get(e.leafId);for(let e of a.values())e.isOnActivePath=s.has(e.id),e.isLeafTurn=c===e.id;let l=0,u=new Map,d=(e,t)=>{(o.get(e)??[]).forEach((e,n)=>{let r;n===0?r=t:(r=l,l+=1),e.col=r,u.set(e.id,r),d(e.id,r)})};(o.get(null)??[]).forEach((e,t)=>{t===0?(e.col=0,l=Math.max(l,1)):(e.col=l,l+=1),u.set(e.id,e.col),d(e.id,e.col)});let f=(e,t)=>{let n=t.get(e.id);if(n!==void 0)return n;if(e.parentId===null)return t.set(e.id,0),0;let r=a.get(e.parentId);if(r===void 0)return t.set(e.id,0),0;let i=f(r,t)+1;return t.set(e.id,i),i},p=new Map;for(let e of a.values())e.row=f(e,p);return[...a.values()].sort((e,t)=>e.row===t.row?e.col-t.col:e.row-t.row)}function Gk({tree:e,disabled:t,onNavigate:n,onForkAfterTurn:r}){let i=(0,v.useMemo)(()=>Wk(e),[e]),a=(0,v.useMemo)(()=>{if(i.length===0)return{width:0,height:0};let e=i.reduce((e,t)=>Math.max(e,t.col),0),t=i.reduce((e,t)=>Math.max(e,t.row),0);return{width:Uk*2+(e+1)*zk+e*Vk,height:Uk*2+(t+1)*Bk+t*Hk}},[i]);if(i.length===0)return(0,R.jsx)(`div`,{className:`px-4 py-6 text-center text-xs italic text-neutral-500`,children:`No turns to render.`});let o=e=>Uk+e*284,s=e=>Uk+e*106,c=new Map(i.map(e=>[e.id,e]));return(0,R.jsxs)(`div`,{className:`relative`,style:{width:`${a.width}px`,height:`${a.height}px`},children:[(0,R.jsx)(`svg`,{"aria-hidden":`true`,className:`pointer-events-none absolute left-0 top-0`,width:a.width,height:a.height,children:i.map(e=>{if(e.parentId===null)return null;let t=c.get(e.parentId);if(t===void 0)return null;let n=o(t.col)+zk/2,r=s(t.row)+Bk,i=o(e.col)+zk/2,a=s(e.row),l=e.isOnActivePath&&t.isOnActivePath;return(0,R.jsx)(`path`,{d:n===i?`M ${n} ${r} L ${i} ${a}`:(()=>{let e=r+(a-r)/2,t=i>n,o=t?n+8:n-8,s=t?i-8:i+8;return[`M ${n} ${r}`,`L ${n} ${e-8}`,`Q ${n} ${e} ${o} ${e}`,`L ${s} ${e}`,`Q ${i} ${e} ${i} ${e+8}`,`L ${i} ${a}`].join(` `)})(),fill:`none`,stroke:l?`#a3a3a3`:`#404040`,strokeWidth:l?1.5:1,strokeOpacity:l?.85:.5},e.id)})}),i.map(e=>(0,R.jsx)(Kk,{turn:e,x:o(e.col),y:s(e.row),disabled:t,onNavigate:()=>n(e.lastEntryId),onForkAfterTurn:()=>r(e.lastEntryId)},e.id))]})}function Kk({turn:e,x:t,y:n,disabled:r,onNavigate:i,onForkAfterTurn:a}){let o=!e.isOnActivePath;return(0,R.jsx)(`div`,{className:`absolute overflow-hidden rounded-lg border ${e.isLeafTurn?`border-emerald-700/70 bg-emerald-900/15`:e.isOnActivePath?`border-neutral-600 bg-neutral-900`:`border-neutral-800 bg-neutral-950`} ${o?`opacity-60`:``}`,style:{left:`${t}px`,top:`${n}px`,width:`${zk}px`,height:`${Bk}px`},children:(0,R.jsxs)(`button`,{onClick:i,disabled:r||e.isLeafTurn,className:`flex h-full w-full flex-col items-stretch gap-1 px-2 py-1.5 text-left disabled:cursor-default`,title:e.isLeafTurn?`Current leaf turn`:`Navigate to this turn`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,R.jsx)(`span`,{className:`rounded px-1.5 py-0.5 text-[9px] uppercase tracking-wider ${e.roleLabel===`user`?`bg-sky-900/40 text-sky-300 light:bg-sky-100 light:text-sky-800`:e.roleLabel===`compact`?`bg-fuchsia-900/40 text-fuchsia-300 light:bg-fuchsia-100 light:text-fuchsia-800`:e.roleLabel===`branch`?`bg-amber-900/40 text-amber-300 light:bg-amber-100 light:text-amber-800`:`bg-neutral-800 text-neutral-400`}`,children:e.roleLabel}),e.isLeafTurn&&(0,R.jsx)(`span`,{className:`rounded bg-emerald-900/40 px-1.5 py-0.5 text-[9px] text-emerald-300 light:bg-emerald-100 light:text-emerald-800`,children:`leaf`}),e.hasMultipleChildren&&(0,R.jsxs)(`span`,{className:`text-[9px] text-amber-400 light:text-amber-700`,title:`${e.childCount} branches diverge from here`,children:[`⑂ `,e.childCount]}),(0,R.jsx)(`button`,{onClick:e=>{e.stopPropagation(),a()},disabled:r,className:`ml-auto rounded p-0.5 text-neutral-500 hover:bg-neutral-800 hover:text-emerald-300 disabled:opacity-40 light:hover:text-emerald-700`,title:`Fork AFTER this turn — opens a new session that includes this turn's full output, ready for the next prompt.`,children:(0,R.jsx)(De,{size:11})})]}),(0,R.jsx)(`p`,{className:`line-clamp-2 flex-1 text-[11px] text-neutral-200`,children:e.preview.length>0?e.preview:(0,R.jsx)(`em`,{className:`text-neutral-500`,children:`(no text)`})}),(0,R.jsxs)(`div`,{className:`flex items-center gap-2 text-[9px] text-neutral-500`,children:[e.insideCounts.assistant>0&&(0,R.jsxs)(`span`,{title:`Assistant messages within this turn`,children:[e.insideCounts.assistant,`a`]}),e.insideCounts.tool>0&&(0,R.jsxs)(`span`,{title:`Tool results within this turn`,children:[e.insideCounts.tool,`t`]}),e.insideCounts.thinking>0&&(0,R.jsxs)(`span`,{title:`Thinking blocks`,children:[e.insideCounts.thinking,`th`]}),e.insideCounts.meta>0&&(0,R.jsxs)(`span`,{title:`Meta entries (model_change, branch_summary, etc.)`,children:[e.insideCounts.meta,`m`]}),(0,R.jsx)(`span`,{className:`ml-auto`,children:new Date(e.timestamp).toLocaleTimeString()})]})]})})}var qk=pt(e=>({pendingInsert:void 0,setPendingInsert:(t,n)=>e({pendingInsert:{sessionId:t,text:n}}),consumePendingInsert:()=>e({pendingInsert:void 0})}));function Jk(e){return typeof e.command==`string`&&e.command.length>0}function Yk(e){return typeof e.text==`string`&&e.text.length>0}function Xk(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?crypto.randomUUID():`run-${Date.now()}-${Math.random().toString(36).slice(2)}`}function Zk({sessionId:e,projectId:t}){let n=li(e=>e.loaded),r=li(e=>e.actions),i=ci(e=>e.minimal),a=ui(e=>e.addRun),o=ui(e=>e.updateRun),s=ui(e=>e.runs),c=Jr(e=>e.sendPrompt),l=qk(e=>e.setPendingInsert),[u,d]=(0,v.useState)(!1),f=(0,v.useRef)(null);(0,v.useEffect)(()=>{if(!u)return;let e=e=>{f.current!==null&&(f.current.contains(e.target)||d(!1))};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[u]);let p=r.filter(e=>!(e.enabled===!1||i&&Jk(e))),m=new Map,h=0;for(let e of s)e.status===`running`&&(h+=1,m.set(e.actionId,(m.get(e.actionId)??0)+1));if(!n||p.length===0)return null;let g=n=>{let r=Xk(),i=new AbortController;a({runId:r,sessionId:e,actionId:n.id,actionName:n.name,startedAt:Date.now(),status:`running`,abort:()=>{try{i.abort()}catch{}}}),L.runQuickAction(n.id,t).then(e=>{o(r,{status:i.signal.aborted?`aborted`:`done`,result:e})}).catch(e=>{o(r,{status:`done`,error:e instanceof N?`${e.code}: ${e.message}`:e.message})})},_=t=>{let n=t.text??``;n.length!==0&&((t.mode??`send`)===`insert`?l(e,n):c(e,n))},y=e=>{d(!1),Jk(e)?g(e):Yk(e)&&_(e)};return(0,R.jsxs)(`div`,{ref:f,className:`relative`,children:[(0,R.jsxs)(`button`,{type:`button`,onClick:()=>d(e=>!e),"aria-haspopup":`menu`,"aria-expanded":u,className:`flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] uppercase tracking-wider text-neutral-400 hover:bg-neutral-800 hover:text-neutral-200 light:text-neutral-600 light:hover:bg-neutral-200 light:hover:text-neutral-900`,title:`Run a saved quick action`,children:[(0,R.jsx)(at,{size:11}),`Actions`,h>0&&(0,R.jsxs)(`span`,{className:`ml-0.5 flex items-center gap-0.5 rounded bg-amber-700/40 px-1 text-[9px] normal-case text-amber-100 light:bg-amber-200 light:text-amber-900`,title:`${h} action${h===1?``:`s`} running`,children:[(0,R.jsx)(Ne,{size:9,className:`animate-spin`}),h]}),(0,R.jsx)(ue,{size:11})]}),u&&(0,R.jsx)(`div`,{role:`menu`,className:`absolute left-0 top-full z-30 mt-1 min-w-[14rem] max-w-[20rem] rounded-md border border-neutral-700 bg-neutral-900 py-1 shadow-xl light:border-neutral-300 light:bg-white`,children:p.map(e=>{let t=Jk(e),n=t?Ze:Le,r=m.get(e.id)??0;return(0,R.jsxs)(`button`,{role:`menuitem`,onClick:()=>y(e),className:`flex w-full items-center gap-2 px-3 py-1.5 text-left text-xs text-neutral-200 hover:bg-neutral-800 light:text-neutral-800 light:hover:bg-neutral-100`,title:t?e.command??``:`${e.mode===`insert`?`Insert`:`Send`}: ${e.text??``}`,children:[(0,R.jsx)(n,{size:12,className:t?`text-amber-400 light:text-amber-700`:`text-sky-400 light:text-sky-700`}),(0,R.jsx)(`span`,{className:`flex-1 truncate`,children:e.name}),r>0&&(0,R.jsx)(Ne,{size:11,className:`animate-spin text-amber-400 light:text-amber-700`})]},e.id)})})]})}function Qk(e){return e<1e3?`${e} ms`:`${(e/1e3).toFixed(1)} s`}function $k({run:e}){let t=ui(e=>e.removeRun),n=qk(e=>e.setPendingInsert),[r,i]=(0,v.useState)(!1),a=e.result,o=e.status===`running`,s=e.error!==void 0,c=a?.success===!0&&!s,l=a?.exitCode??null,u=o?`border-l-amber-500 light:border-l-amber-600`:c?`border-l-emerald-500 light:border-l-emerald-600`:`border-l-red-500 light:border-l-red-600`,d=o?`running`:s?`error`:a?.timedOut===!0?`timed out`:e.status===`aborted`?`aborted`:l===0?`exit 0`:`exit ${l??`?`}`,f=()=>{if(a===void 0)return``;let t=[`Ran quick action: ${e.actionName}`,``];return a.stdout.length>0&&t.push("```",a.stdout.replace(/\s+$/,``),"```"),a.stderr.length>0&&t.push(``,`stderr:`,"```",a.stderr.replace(/\s+$/,``),"```"),a.exitCode!==null&&a.exitCode!==0&&t.push(``,`exit code: ${a.exitCode}`),t.join(`
|
|
343
|
-
`)};return(0,R.jsxs)(`div`,{className:`rounded-lg border border-neutral-800 border-l-4 bg-neutral-900/40 px-3 py-2 text-xs light:border-neutral-300 light:bg-neutral-50 ${u}`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,R.jsx)(Ze,{size:12,className:`text-neutral-500 light:text-neutral-600`}),(0,R.jsx)(`span`,{className:`font-mono text-neutral-300 light:text-neutral-800`,children:e.actionName}),(0,R.jsx)(`span`,{className:`text-neutral-500 light:text-neutral-600`,children:`·`}),o?(0,R.jsxs)(`span`,{className:`flex items-center gap-1 text-amber-400 light:text-amber-700`,children:[(0,R.jsx)(Ne,{size:11,className:`animate-spin`}),d]}):c?(0,R.jsxs)(`span`,{className:`flex items-center gap-1 text-emerald-400 light:text-emerald-700`,children:[(0,R.jsx)(le,{size:11}),d]}):(0,R.jsxs)(`span`,{className:`flex items-center gap-1 text-red-400 light:text-red-700`,children:[(0,R.jsx)(it,{size:11}),d]}),a!==void 0&&(0,R.jsxs)(`span`,{className:`text-neutral-500 light:text-neutral-600`,children:[`· `,Qk(a.durationMs)]}),a?.truncated===!0&&(0,R.jsx)(`span`,{className:`rounded bg-amber-700/40 px-1 text-[10px] text-amber-100 light:bg-amber-200 light:text-amber-900`,title:`Output exceeded the per-stream cap and was cut off`,children:`truncated`}),(0,R.jsx)(`div`,{className:`flex-1`}),o?(0,R.jsx)(`button`,{type:`button`,onClick:()=>{e.abort(),ui.getState().updateRun(e.runId,{status:`aborted`})},className:`rounded px-1.5 py-0.5 text-[10px] uppercase tracking-wider text-neutral-400 hover:bg-neutral-800 hover:text-neutral-200 light:text-neutral-600 light:hover:bg-neutral-200`,title:`Stop waiting on this run (server-side abort coming later)`,children:`Stop`}):(0,R.jsxs)(R.Fragment,{children:[a!==void 0&&(a.stdout.length>0||a.stderr.length>0)&&(0,R.jsxs)(`button`,{type:`button`,onClick:()=>n(e.sessionId,f()),className:`flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] uppercase tracking-wider text-sky-400 hover:bg-neutral-800 hover:text-sky-200 light:text-sky-700 light:hover:bg-neutral-200 light:hover:text-sky-900`,title:`Insert the captured output into the composer for your next prompt`,children:[(0,R.jsx)(Ie,{size:11}),`Use as context`]}),(0,R.jsx)(`button`,{type:`button`,onClick:()=>t(e.runId),className:`rounded px-1.5 py-0.5 text-[10px] uppercase tracking-wider text-neutral-500 hover:bg-neutral-800 hover:text-neutral-200 light:text-neutral-500 light:hover:bg-neutral-200 light:hover:text-neutral-900`,title:`Dismiss`,children:`Dismiss`})]})]}),a!==void 0&&(a.stdout.length>0||a.stderr.length>0||a.exitCode!==0)||s?(0,R.jsx)(`button`,{type:`button`,onClick:()=>i(e=>!e),className:`mt-1 cursor-pointer text-[10px] uppercase tracking-wider text-neutral-500 hover:text-neutral-300 light:text-neutral-600 light:hover:text-neutral-900`,children:r?`Hide output`:`Show output`}):null,r&&(0,R.jsxs)(`div`,{className:`mt-2 space-y-2`,children:[s&&(0,R.jsx)(`pre`,{className:`overflow-auto whitespace-pre-wrap rounded bg-neutral-950 px-2 py-1 font-mono text-[11px] text-red-300 light:bg-red-50 light:text-red-800`,children:e.error}),a!==void 0&&a.stdout.length>0&&(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`div`,{className:`mb-0.5 text-[10px] uppercase tracking-wider text-neutral-500 light:text-neutral-600`,children:`stdout`}),(0,R.jsx)(`pre`,{className:`max-h-72 overflow-auto whitespace-pre-wrap rounded bg-neutral-950 px-2 py-1 font-mono text-[11px] text-neutral-200 light:bg-white light:text-neutral-800`,children:a.stdout})]}),a!==void 0&&a.stderr.length>0&&(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`div`,{className:`mb-0.5 text-[10px] uppercase tracking-wider text-neutral-500 light:text-neutral-600`,children:`stderr`}),(0,R.jsx)(`pre`,{className:`max-h-72 overflow-auto whitespace-pre-wrap rounded bg-neutral-950 px-2 py-1 font-mono text-[11px] text-red-300 light:bg-red-50 light:text-red-800`,children:a.stderr})]})]})]})}var eA=new Set([`single`,`parallel`,`chain`,`management`]);function tA(e){if(!e.endsWith(`.jsonl`))return;let t=Math.max(e.lastIndexOf(`/`),e.lastIndexOf(`\\`)),n=(t>=0?e.slice(t+1):e).slice(0,-6);if(n.length!==0)return n}function nA(e){if(typeof e!=`object`||!e)return{mode:`unknown`,results:[]};let t=e,n=eA.has(t.mode)?t.mode:`unknown`,r=typeof t.runId==`string`&&t.runId.length>0?t.runId:void 0,i=t.context===`fresh`||t.context===`fork`?t.context:void 0,a=[];if(Array.isArray(t.results))for(let e of t.results){if(typeof e!=`object`||!e)continue;let t=e,n={agent:typeof t.agent==`string`?t.agent:`agent`,task:typeof t.task==`string`?t.task:``,exitCode:typeof t.exitCode==`number`?t.exitCode:0};if(typeof t.sessionFile==`string`&&t.sessionFile.length>0){n.sessionFile=t.sessionFile;let e=tA(t.sessionFile);e!==void 0&&(n.sessionId=e)}typeof t.finalOutput==`string`&&t.finalOutput.length>0&&(n.finalOutput=t.finalOutput),a.push(n)}return{mode:n,...r===void 0?{}:{runId:r},...i===void 0?{}:{context:i},results:a}}function rA({sessionId:e,onClose:t}){let n=ci(e=>e.orchestrationEnabled),[r,i]=(0,v.useState)(void 0),[a,o]=(0,v.useState)([]),[s,c]=(0,v.useState)([]),[l,u]=(0,v.useState)(!1),[d,f]=(0,v.useState)(!1),[p,m]=(0,v.useState)(!1),[h,g]=(0,v.useState)(void 0),_=async()=>{f(!0),g(void 0);try{let t=await L.getSessionLink(e);i(t),t.role===`supervisor`?(o((await L.listSupervisorWorkers(e)).workers),c((await L.listSupervisorInbox(e)).items)):(o([]),c([]))}catch(e){g(e instanceof N?e.code:e.message)}finally{f(!1)}};if((0,v.useEffect)(()=>{if(!n)return;_();let e=setInterval(()=>{_()},4e3);return()=>clearInterval(e)},[n,e]),!n)return null;let y=r?.role??`standalone`;return(0,R.jsxs)(`div`,{className:`rounded-md border border-zinc-200 dark:border-zinc-800 bg-zinc-50 dark:bg-zinc-900/50 p-3 text-sm`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2 font-medium`,children:[(0,R.jsx)(rt,{size:14}),(0,R.jsx)(`span`,{children:`Orchestration`}),(0,R.jsx)(iA,{role:y})]}),(0,R.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,R.jsx)(`button`,{type:`button`,onClick:()=>{_()},title:`Refresh`,className:`p-1 text-zinc-500 hover:text-zinc-900 dark:hover:text-zinc-100`,children:d?(0,R.jsx)(Ne,{size:14,className:`animate-spin`}):(0,R.jsx)(Ue,{size:14})}),t!==void 0&&(0,R.jsx)(`button`,{type:`button`,onClick:t,title:`Close`,className:`p-1 text-zinc-500 hover:text-zinc-900 dark:hover:text-zinc-100`,children:(0,R.jsx)(it,{size:14})})]})]}),h!==void 0&&(0,R.jsx)(`div`,{className:`mt-2 rounded bg-red-100 dark:bg-red-900/30 text-red-800 dark:text-red-300 px-2 py-1 text-xs`,children:h}),y===`standalone`&&(0,R.jsx)(aA,{sessionId:e,busy:p,setBusy:m,setError:g,onAfter:_}),y===`supervisor`&&r!==void 0&&(0,R.jsx)(oA,{link:r,workers:a,inbox:s,showInbox:l,setShowInbox:u,busy:p,setBusy:m,setError:g,onAfter:_}),y===`worker`&&r!==void 0&&(0,R.jsx)(lA,{link:r})]})}function iA({role:e}){return(0,R.jsx)(`span`,{className:`rounded px-1.5 py-0.5 text-xs font-medium ${e===`supervisor`?`bg-violet-100 text-violet-800 dark:bg-violet-900/40 dark:text-violet-200`:e===`worker`?`bg-sky-100 text-sky-800 dark:bg-sky-900/40 dark:text-sky-200`:`bg-zinc-200 text-zinc-700 dark:bg-zinc-800 dark:text-zinc-300`}`,children:e===`supervisor`?`Supervisor`:e===`worker`?`Worker`:`Standalone`})}function aA({sessionId:e,busy:t,setBusy:n,setError:r,onAfter:i}){let a=async()=>{n(!0),r(void 0);try{await L.enableSupervisor(e),await i()}catch(e){r(e instanceof N?e.code:e.message)}finally{n(!1)}};return(0,R.jsxs)(`div`,{className:`mt-2 space-y-2`,children:[(0,R.jsxs)(`p`,{className:`text-xs text-zinc-600 dark:text-zinc-400`,children:[`This session is standalone. Enable supervisor mode to give this session the`,` `,(0,R.jsx)(`code`,{className:`text-xs`,children:`orchestrate_*`}),` tools — letting it spawn, observe, and coordinate other worker sessions in the same project.`]}),(0,R.jsx)(`button`,{type:`button`,onClick:()=>{a()},disabled:t,className:`rounded bg-violet-600 px-2.5 py-1 text-xs font-medium text-white hover:bg-violet-500 disabled:opacity-50`,children:t?`Enabling…`:`Enable supervisor mode`}),(0,R.jsx)(`p`,{className:`text-[11px] text-zinc-500 dark:text-zinc-400`,children:`The agent's tool list refreshes immediately — no reload needed.`})]})}function oA({link:e,workers:t,inbox:n,showInbox:r,setShowInbox:i,busy:a,setBusy:o,setError:s,onAfter:c}){let l=Jr(e=>e.setActiveSession),u=async()=>{if(confirm(`Disable supervisor mode? Linked workers become standalone sessions.`)){o(!0),s(void 0);try{await L.disableSupervisor(e.sessionId),await c()}catch(e){s(e instanceof N?e.code:e.message)}finally{o(!1)}}},d=async t=>{o(!0),s(void 0);try{await L.detachWorker(e.sessionId,t),await c()}catch(e){s(e instanceof N?e.code:e.message)}finally{o(!1)}},f=async t=>{if(confirm(`Kill worker ${t.slice(0,8)}? (Transcript stays on disk.)`)){o(!0),s(void 0);try{await L.killWorker(e.sessionId,t),await c()}catch(e){s(e instanceof N?e.code:e.message)}finally{o(!1)}}},p=async t=>{o(!0),s(void 0);try{await L.resumeWorker(e.sessionId,t),await c()}catch(e){s(e instanceof N?e.code:e.message)}finally{o(!1)}},m=async()=>{if(confirm(`Clear inbox history?`)){o(!0),s(void 0);try{await L.clearSupervisorInbox(e.sessionId),await c()}catch(e){s(e instanceof N?e.code:e.message)}finally{o(!1)}}},h=e.pendingInbox??0;return(0,R.jsxs)(`div`,{className:`mt-2 space-y-2`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,R.jsxs)(`div`,{className:`text-xs text-zinc-600 dark:text-zinc-400`,children:[t.length,` worker`,t.length===1?``:`s`,h>0?(0,R.jsxs)(`span`,{className:`ml-2 rounded bg-amber-200 dark:bg-amber-700/50 text-amber-900 dark:text-amber-100 px-1.5 py-0.5`,children:[h,` pending inbox`]}):null]}),(0,R.jsx)(`button`,{type:`button`,onClick:()=>{u()},disabled:a,className:`rounded text-xs text-zinc-600 dark:text-zinc-400 hover:text-red-600 dark:hover:text-red-400 disabled:opacity-50 px-1.5 py-0.5`,children:`Disable supervisor mode`})]}),t.length===0?(0,R.jsxs)(`p`,{className:`text-xs italic text-zinc-500 dark:text-zinc-400`,children:[`No workers yet. The agent can spawn one with`,` `,(0,R.jsx)(`code`,{className:`text-xs`,children:`orchestrate_spawn_worker`}),`.`]}):(0,R.jsx)(`ul`,{className:`divide-y divide-zinc-200 dark:divide-zinc-800 rounded border border-zinc-200 dark:border-zinc-800 bg-white dark:bg-zinc-950`,children:t.map(e=>(0,R.jsxs)(`li`,{className:`flex items-center gap-2 px-2 py-1.5`,children:[(0,R.jsx)(uA,{state:e.state??(e.isLive?`idle`:`cold`)}),(0,R.jsxs)(`button`,{type:`button`,onClick:()=>l(e.workerId),className:`flex-1 text-left truncate text-xs hover:underline`,title:e.workerId,children:[(0,R.jsx)(`span`,{className:`font-medium`,children:e.name??e.workerId.slice(0,8)}),e.messageCount!==void 0&&(0,R.jsxs)(`span`,{className:`ml-1 text-zinc-500`,children:[`(`,e.messageCount,` msgs)`]})]}),(0,R.jsxs)(`div`,{className:`flex items-center gap-1`,children:[!e.isLive&&(0,R.jsx)(`button`,{type:`button`,onClick:()=>{p(e.workerId)},disabled:a,className:`text-[11px] text-zinc-600 dark:text-zinc-400 hover:text-violet-700 dark:hover:text-violet-300 disabled:opacity-50 px-1 py-0.5`,children:`Resume`}),(0,R.jsx)(`button`,{type:`button`,onClick:()=>{d(e.workerId)},disabled:a,className:`text-[11px] text-zinc-600 dark:text-zinc-400 hover:text-amber-700 dark:hover:text-amber-300 disabled:opacity-50 px-1 py-0.5`,title:`Detach (worker continues as standalone)`,children:`Detach`}),(0,R.jsx)(`button`,{type:`button`,onClick:()=>{f(e.workerId)},disabled:a,className:`text-[11px] text-zinc-600 dark:text-zinc-400 hover:text-red-700 dark:hover:text-red-300 disabled:opacity-50 px-1 py-0.5`,title:`Kill (dispose live session; transcript stays on disk)`,children:`Kill`})]})]},e.workerId))}),(0,R.jsxs)(`details`,{open:r,onToggle:e=>i(e.currentTarget.open),children:[(0,R.jsxs)(`summary`,{className:`cursor-pointer text-xs text-zinc-600 dark:text-zinc-400 select-none`,children:[`Inbox history (`,n.length,`) `,h>0&&`— ${h} pending`]}),n.length===0?(0,R.jsx)(`p`,{className:`text-xs italic text-zinc-500 dark:text-zinc-400 mt-1`,children:`No inbox items.`}):(0,R.jsxs)(`div`,{className:`mt-1 space-y-1`,children:[(0,R.jsx)(`ul`,{className:`divide-y divide-zinc-200 dark:divide-zinc-800 rounded border border-zinc-200 dark:border-zinc-800 bg-white dark:bg-zinc-950 max-h-48 overflow-auto`,children:n.map(e=>(0,R.jsx)(sA,{item:e},e.id))}),(0,R.jsx)(`button`,{type:`button`,onClick:()=>{m()},disabled:a,className:`text-[11px] text-zinc-500 dark:text-zinc-400 hover:text-red-600 dark:hover:text-red-400 disabled:opacity-50`,children:`Clear inbox`})]})]})]})}function sA({item:e}){let t=cA(e.type);return(0,R.jsxs)(`li`,{className:`flex items-baseline gap-2 px-2 py-1 text-xs`,children:[(0,R.jsx)(`span`,{className:`rounded px-1 py-0.5 ${e.delivered?`bg-zinc-200 text-zinc-600 dark:bg-zinc-800 dark:text-zinc-400`:`bg-amber-200 text-amber-900 dark:bg-amber-700/40 dark:text-amber-200`}`,children:t}),(0,R.jsx)(`span`,{className:`font-mono text-zinc-500`,title:e.workerId,children:e.workerId.slice(0,8)}),(0,R.jsx)(`span`,{className:`text-zinc-500 ml-auto`,children:new Date(e.occurredAt).toLocaleTimeString()})]})}function cA(e){switch(e){case`worker.ended`:return`ended`;case`worker.ask_user`:return`asked`;case`worker.auto_retry_failed`:return`retry failed`;case`worker.process_alert`:return`process`;case`worker.deleted`:return`deleted`}}function lA({link:e}){let t=Jr(e=>e.setActiveSession),n=e.supervisorId;return n===void 0?null:(0,R.jsxs)(`div`,{className:`mt-2 text-xs text-zinc-600 dark:text-zinc-400`,children:[`Owned by supervisor`,` `,(0,R.jsx)(`button`,{type:`button`,onClick:()=>t(n),className:`font-mono underline hover:text-violet-700 dark:hover:text-violet-300`,title:n,children:n.slice(0,8)}),e.spawnedFrom!==void 0&&e.spawnedFrom.mode===`summary`&&(0,R.jsx)(`span`,{className:`ml-2 italic`,children:`(handoff with context summary)`})]})}function uA({state:e}){return(0,R.jsx)(`span`,{className:`inline-block h-2 w-2 rounded-full ${e===`streaming`?`bg-emerald-500 animate-pulse`:e===`idle`?`bg-sky-500`:`bg-zinc-400`}`,title:e,"aria-label":e})}var dA=(0,v.createContext)({viewType:`unified`,setViewType:()=>void 0}),fA=`forge.chat.viewType`;function pA(){try{return localStorage.getItem(fA)===`split`?`split`:`unified`}catch{return`unified`}}function mA({sessionId:e}){let t=Jr(t=>t.messagesBySession[e]??zr),n=Jr(t=>t.compactionsBySession[e]??Br),r=Jr(t=>t.streamingTextBySession[e]??``),i=Jr(t=>t.streamingBySession[e]??!1),a=Jr(t=>t.activeToolBySession[e]),o=Jr(t=>t.bannerBySession[e]),s=Jr(e=>e.clearBanner),c=Jr(t=>t.queuedBySession[e]),l=Jr(e=>e.openStream),u=Jr(e=>e.closeStream),d=Jr(t=>t.pendingScrollByMessageIndex[e]),f=Jr(e=>e.consumePendingScroll),p=ui(e=>e.runs),m=(0,v.useMemo)(()=>p.filter(t=>t.sessionId===e),[p,e]),[h,g]=(0,v.useState)(pA),_=e=>{g(e);try{localStorage.setItem(fA,e)}catch{}},y=dr(),[b,x]=(0,v.useState)(!1),[S,C]=(0,v.useState)(!1),w=ci(e=>e.orchestrationEnabled),T=st(),[E,D]=(0,v.useState)(!1),[O,k]=(0,v.useState)(void 0),ee=(0,v.useRef)(null);(0,v.useEffect)(()=>{if(!E)return;let e=e=>{ee.current!==null&&(ee.current.contains(e.target)||D(!1))};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[E]);let A=async t=>{D(!1),k(void 0);try{let{blob:n,filename:r}=await L.exportSession(e,t),i=URL.createObjectURL(n),a=document.createElement(`a`);a.href=i,a.download=r,document.body.appendChild(a),a.click(),a.remove(),window.setTimeout(()=>URL.revokeObjectURL(i),1e3)}catch(e){k(e instanceof N?`${e.code} (${e.status})`:e instanceof Error?e.message:`export_failed`),window.setTimeout(()=>k(void 0),4e3)}};(0,v.useEffect)(()=>(l(e),()=>{u(e)}),[e,l,u]);let te=(0,v.useRef)(null),ne=(0,v.useRef)(!0),re=()=>{let e=te.current;e!==null&&(ne.current=e.scrollHeight-e.scrollTop-e.clientHeight<=96)};(0,v.useEffect)(()=>{let e=te.current;e!==null&&ne.current&&(e.scrollTop=e.scrollHeight)},[t,r,i]);let ie=(0,v.useRef)(0);return(0,v.useEffect)(()=>{let e=t.reduce((e,t)=>t.role===`user`?e+1:e,0);if(e>ie.current){let e=te.current;e!==null&&(e.scrollTop=e.scrollHeight),ne.current=!0}ie.current=e},[t]),(0,v.useEffect)(()=>{if(d===void 0||t.length<=d)return;let n=te.current;if(n===null)return;let r=n.querySelector(`[data-message-index="${d}"]`);r!==null&&(r.scrollIntoView({block:`center`,behavior:`smooth`}),ne.current=!1,f(e))},[d,t.length,e,f]),(0,R.jsxs)(dA.Provider,{value:{viewType:h,setViewType:_},children:[(0,R.jsxs)(`div`,{className:`flex flex-1 flex-col overflow-hidden`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between gap-1 border-b border-neutral-800 bg-neutral-900/30 px-3 py-1`,children:[(0,R.jsx)(`div`,{className:`flex items-center gap-1`,children:y!==void 0&&(0,R.jsx)(Zk,{sessionId:e,projectId:y.id})}),(0,R.jsxs)(`div`,{className:`flex items-center gap-1`,children:[!T&&(0,R.jsxs)(`div`,{ref:ee,className:`relative`,children:[(0,R.jsxs)(`button`,{onClick:()=>D(e=>!e),"aria-haspopup":`menu`,"aria-expanded":E,className:`flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] uppercase tracking-wider text-neutral-400 hover:bg-neutral-800 hover:text-neutral-200`,title:`Export this conversation`,children:[(0,R.jsx)(ye,{size:11}),`Export`]}),E&&(0,R.jsxs)(`div`,{role:`menu`,className:`absolute right-0 top-full z-30 mt-1 min-w-[12rem] rounded-md border border-neutral-700 bg-neutral-900 py-1 shadow-xl`,children:[(0,R.jsxs)(`button`,{role:`menuitem`,onClick:()=>void A(`markdown`),className:`block w-full px-3 py-1.5 text-left text-xs text-neutral-200 hover:bg-neutral-800`,children:[`Markdown `,(0,R.jsx)(`span`,{className:`text-neutral-500`,children:`(.md)`})]}),(0,R.jsxs)(`button`,{role:`menuitem`,onClick:()=>void A(`jsonl`),className:`block w-full px-3 py-1.5 text-left text-xs text-neutral-200 hover:bg-neutral-800`,children:[`Raw JSONL `,(0,R.jsx)(`span`,{className:`text-neutral-500`,children:`(.jsonl)`})]})]})]}),O!==void 0&&(0,R.jsxs)(`span`,{className:`text-[10px] text-amber-400 light:text-amber-700`,role:`status`,children:[`Export failed: `,O]}),(0,R.jsxs)(`button`,{onClick:()=>x(!0),className:`flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] uppercase tracking-wider text-neutral-400 hover:bg-neutral-800 hover:text-neutral-200`,title:`Open session tree (navigate / fork from any prior point)`,children:[(0,R.jsx)(De,{size:11}),`Tree`]}),w&&(0,R.jsxs)(`button`,{onClick:()=>C(e=>!e),"aria-pressed":S,className:`flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] uppercase tracking-wider hover:bg-neutral-800 ${S?`bg-neutral-800 text-violet-300`:`text-neutral-400 hover:text-neutral-200`}`,title:`Orchestration — supervisor / worker controls`,children:[(0,R.jsx)(rt,{size:11}),`Orch`]})]})]}),S&&w&&(0,R.jsx)(`div`,{className:`border-b border-neutral-800 bg-neutral-900/40 px-3 py-2`,children:(0,R.jsx)(rA,{sessionId:e,onClose:()=>C(!1)})}),o!==void 0&&(0,R.jsxs)(`div`,{className:`flex items-start gap-2 border-b border-amber-700/40 bg-amber-900/20 px-6 py-2 text-xs text-amber-200 light:border-amber-300 light:bg-amber-50 light:text-amber-800`,children:[(0,R.jsx)(`div`,{className:`flex-1`,children:o}),(0,R.jsx)(`button`,{type:`button`,onClick:()=>s(e),className:`-mr-1 shrink-0 rounded p-0.5 text-amber-300 hover:bg-amber-900/40 hover:text-amber-100 light:text-amber-700 light:hover:bg-amber-100 light:hover:text-amber-900`,title:`Dismiss`,"aria-label":`Dismiss banner`,children:(0,R.jsx)(it,{size:14})})]}),(0,R.jsxs)(`div`,{ref:te,onScroll:re,className:`flex-1 overflow-y-auto px-6 py-4`,children:[t.length===0&&r.length===0&&!i&&(0,R.jsx)(`p`,{className:`mt-12 text-center text-sm text-neutral-500`,children:`No messages yet. Send a prompt to get started.`}),(0,R.jsxs)(`div`,{className:`chat-message-list mx-auto max-w-3xl space-y-4`,children:[(()=>{let e=new Map,r=new Set;for(let n of t)n.role===`toolResult`&&typeof n.toolCallId==`string`&&e.set(n.toolCallId,n);for(let e of t)if(!(e.role!==`assistant`||!Array.isArray(e.content)))for(let t of e.content)t.type===`toolCall`&&typeof t.id==`string`&&r.add(t.id);let i=new Map;for(let e of n){let t=i.get(e.insertBeforeIndex)??[];t.push(e),i.set(e.insertBeforeIndex,t)}let a=t=>t.archivedMessages.map((t,n)=>(0,R.jsx)(bA,{message:t,toolResultsById:e},n)),o=[],s=e=>{let t=i.get(e);if(t!==void 0)for(let e of t)o.push((0,R.jsx)(sC,{event:e,renderArchived:()=>a(e)},`compaction-${e.id}`))},c=n.length>0?n[n.length-1]:void 0,l=c?.insertBeforeIndex??0;for(let n=0;n<t.length;n++){let i=t[n];if(s(n),i.role===`toolResult`&&typeof i.toolCallId==`string`&&r.has(i.toolCallId)||i.role===`compactionSummary`||c!==void 0&&n>=1&&n<l)continue;let a=OA(i,e);if(a!==void 0&&DA(a)===1){let i=[...a],u=n+1;for(;u<t.length&&DA(i)<SA;){let n=t[u];if(n.role===`toolResult`&&typeof n.toolCallId==`string`&&r.has(n.toolCallId)){s(u),u+=1;continue}if(n.role===`compactionSummary`||c!==void 0&&u>=1&&u<l)break;let a=OA(n,e);if(a===void 0||DA(a)!==1)break;i.push(...a),u+=1}if(i.length>1){o.push((0,R.jsx)(`div`,{"data-message-index":n,children:(0,R.jsx)(AA,{entries:i})},`tool-batch-${n}`)),n=u-1;continue}}o.push((0,R.jsx)(`div`,{"data-message-index":n,children:(0,R.jsx)(bA,{message:i,toolResultsById:e})},n))}return s(t.length),o})(),r.length>0&&(0,R.jsxs)(`div`,{className:`message-bubble rounded-lg border border-neutral-800 bg-neutral-900 px-4 py-3`,children:[(0,R.jsx)(`div`,{className:`mb-1 text-[10px] uppercase tracking-wider text-neutral-500`,children:`assistant (streaming)`}),(0,R.jsxs)(`div`,{className:`text-neutral-100`,children:[(0,R.jsx)(oC,{text:r}),(0,R.jsx)(`span`,{className:`ml-1 inline-block h-3 w-1.5 animate-pulse bg-neutral-300 align-text-bottom`})]})]}),i&&r.length===0&&(0,R.jsx)(gA,{tool:a}),c!==void 0&&(0,R.jsx)(hA,{queued:c}),m.map(e=>(0,R.jsx)($k,{run:e},e.runId))]})]})]}),b&&y!==void 0&&(0,R.jsx)(Ek,{sessionId:e,projectId:y.id,onClose:()=>x(!1)})]})}function hA({queued:e}){let t=[];for(let n of e.steering)t.push({kind:`steer`,text:n});for(let n of e.followUp)t.push({kind:`followUp`,text:n});return t.length===0?null:(0,R.jsxs)(`div`,{className:`rounded-md border border-neutral-800 bg-neutral-900/40 px-3 py-2`,children:[(0,R.jsxs)(`div`,{className:`mb-1 text-[10px] uppercase tracking-wider text-neutral-500`,children:[`queued (`,t.length,`)`]}),(0,R.jsx)(`ul`,{className:`space-y-1`,children:t.map(e=>(0,R.jsxs)(`li`,{className:`flex items-baseline gap-2 text-xs text-neutral-300`,children:[(0,R.jsx)(`span`,{className:e.kind===`steer`?`shrink-0 rounded bg-amber-900/30 px-1.5 py-0.5 text-[9px] uppercase tracking-wider text-amber-300 light:bg-amber-100 light:text-amber-800`:`shrink-0 rounded bg-neutral-800 px-1.5 py-0.5 text-[9px] uppercase tracking-wider text-neutral-400`,title:e.kind===`steer`?`Delivered at the agent's next decision point (often mid-tool)`:`Delivered after the agent goes fully idle`,children:e.kind===`steer`?`steer`:`follow-up`}),(0,R.jsx)(`span`,{className:`truncate`,children:e.text})]},`${e.kind}:${e.text}`))})]})}function gA({tool:e}){return e===void 0?(0,R.jsxs)(`div`,{className:`flex items-center gap-2 text-xs italic text-neutral-500`,"aria-live":`polite`,"aria-label":`Agent is thinking`,children:[(0,R.jsx)(`span`,{children:`Thinking`}),(0,R.jsxs)(`span`,{className:`pi-thinking-dots`,"aria-hidden":`true`,children:[(0,R.jsx)(`span`,{children:`.`}),(0,R.jsx)(`span`,{children:`.`}),(0,R.jsx)(`span`,{children:`.`})]})]}):(0,R.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-neutral-400`,children:[(0,R.jsx)(`span`,{className:`inline-block h-1.5 w-1.5 animate-pulse rounded-full bg-neutral-400`}),(0,R.jsx)(`span`,{className:`text-neutral-500`,children:`running`}),(0,R.jsx)(`code`,{className:`rounded bg-neutral-800 px-1.5 py-0.5 font-mono text-[11px] text-neutral-200`,children:e.name}),e.summary!==void 0&&(0,R.jsx)(`code`,{className:`truncate rounded bg-neutral-900 px-1.5 py-0.5 font-mono text-[11px] text-neutral-300`,title:e.summary,children:e.summary})]})}function _A({diff:e,filename:t,adds:n,dels:r}){let{viewType:i,setViewType:a}=(0,v.useContext)(dA);return(0,R.jsxs)(`details`,{className:`group rounded border border-neutral-800 bg-neutral-950 text-xs`,children:[(0,R.jsxs)(`summary`,{className:`flex cursor-pointer items-center justify-between gap-2 px-3 py-2 text-neutral-300`,children:[(0,R.jsxs)(`span`,{className:`flex min-w-0 items-baseline gap-2`,children:[(0,R.jsxs)(`span`,{className:`text-neutral-500`,children:[`edit`,t===void 0?``:` `]}),t!==void 0&&(0,R.jsx)(`span`,{className:`truncate font-mono`,children:t}),(0,R.jsxs)(`span`,{className:`ml-2 text-emerald-400 light:text-emerald-700`,children:[`+`,n]}),(0,R.jsxs)(`span`,{className:`ml-1 text-red-400 light:text-red-700`,children:[`−`,r]})]}),(0,R.jsx)(`button`,{onClick:e=>{e.preventDefault(),e.stopPropagation(),a(i===`split`?`unified`:`split`)},className:`rounded p-0.5 text-neutral-500 hover:bg-neutral-800 hover:text-neutral-200`,title:i===`split`?`Switch chat diffs to unified view`:`Switch chat diffs to side-by-side view`,children:i===`split`?(0,R.jsx)(Ge,{size:11}):(0,R.jsx)(_e,{size:11})})]}),(0,R.jsx)(mk,{diff:e,viewType:i})]})}function vA(e){let t=[],n=e.replace(/\n?(`{3,})(\w*)\s+file:\s+([^\n]+)\n([\s\S]*?)\n\1\n?/g,(e,n,r,i,a)=>(t.push({kind:`inline`,path:i.trim(),lang:r,content:a}),``)),r=/(^|\s)@(?:"([^"\n]+)"|([^\s]+?))(?=[?,;:!)\]]?(?:\s|$))/g,i;for(;(i=r.exec(n))!==null;){let e=(i[2]??i[3]??``).trim();e.length!==0&&(t.some(t=>t.kind===`inline`&&t.path===e)||t.push({kind:`defer`,path:e}))}return n=n.replace(/\n{3,}/g,`
|
|
343
|
+
`)};return(0,R.jsxs)(`div`,{className:`rounded-lg border border-neutral-800 border-l-4 bg-neutral-900/40 px-3 py-2 text-xs light:border-neutral-300 light:bg-neutral-50 ${u}`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,R.jsx)(Ze,{size:12,className:`text-neutral-500 light:text-neutral-600`}),(0,R.jsx)(`span`,{className:`font-mono text-neutral-300 light:text-neutral-800`,children:e.actionName}),(0,R.jsx)(`span`,{className:`text-neutral-500 light:text-neutral-600`,children:`·`}),o?(0,R.jsxs)(`span`,{className:`flex items-center gap-1 text-amber-400 light:text-amber-700`,children:[(0,R.jsx)(Ne,{size:11,className:`animate-spin`}),d]}):c?(0,R.jsxs)(`span`,{className:`flex items-center gap-1 text-emerald-400 light:text-emerald-700`,children:[(0,R.jsx)(le,{size:11}),d]}):(0,R.jsxs)(`span`,{className:`flex items-center gap-1 text-red-400 light:text-red-700`,children:[(0,R.jsx)(it,{size:11}),d]}),a!==void 0&&(0,R.jsxs)(`span`,{className:`text-neutral-500 light:text-neutral-600`,children:[`· `,Qk(a.durationMs)]}),a?.truncated===!0&&(0,R.jsx)(`span`,{className:`rounded bg-amber-700/40 px-1 text-[10px] text-amber-100 light:bg-amber-200 light:text-amber-900`,title:`Output exceeded the per-stream cap and was cut off`,children:`truncated`}),(0,R.jsx)(`div`,{className:`flex-1`}),o?(0,R.jsx)(`button`,{type:`button`,onClick:()=>{e.abort(),ui.getState().updateRun(e.runId,{status:`aborted`})},className:`rounded px-1.5 py-0.5 text-[10px] uppercase tracking-wider text-neutral-400 hover:bg-neutral-800 hover:text-neutral-200 light:text-neutral-600 light:hover:bg-neutral-200`,title:`Stop waiting on this run (server-side abort coming later)`,children:`Stop`}):(0,R.jsxs)(R.Fragment,{children:[a!==void 0&&(a.stdout.length>0||a.stderr.length>0)&&(0,R.jsxs)(`button`,{type:`button`,onClick:()=>n(e.sessionId,f()),className:`flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] uppercase tracking-wider text-sky-400 hover:bg-neutral-800 hover:text-sky-200 light:text-sky-700 light:hover:bg-neutral-200 light:hover:text-sky-900`,title:`Insert the captured output into the composer for your next prompt`,children:[(0,R.jsx)(Ie,{size:11}),`Use as context`]}),(0,R.jsx)(`button`,{type:`button`,onClick:()=>t(e.runId),className:`rounded px-1.5 py-0.5 text-[10px] uppercase tracking-wider text-neutral-500 hover:bg-neutral-800 hover:text-neutral-200 light:text-neutral-500 light:hover:bg-neutral-200 light:hover:text-neutral-900`,title:`Dismiss`,children:`Dismiss`})]})]}),a!==void 0&&(a.stdout.length>0||a.stderr.length>0||a.exitCode!==0)||s?(0,R.jsx)(`button`,{type:`button`,onClick:()=>i(e=>!e),className:`mt-1 cursor-pointer text-[10px] uppercase tracking-wider text-neutral-500 hover:text-neutral-300 light:text-neutral-600 light:hover:text-neutral-900`,children:r?`Hide output`:`Show output`}):null,r&&(0,R.jsxs)(`div`,{className:`mt-2 space-y-2`,children:[s&&(0,R.jsx)(`pre`,{className:`overflow-auto whitespace-pre-wrap rounded bg-neutral-950 px-2 py-1 font-mono text-[11px] text-red-300 light:bg-red-50 light:text-red-800`,children:e.error}),a!==void 0&&a.stdout.length>0&&(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`div`,{className:`mb-0.5 text-[10px] uppercase tracking-wider text-neutral-500 light:text-neutral-600`,children:`stdout`}),(0,R.jsx)(`pre`,{className:`max-h-72 overflow-auto whitespace-pre-wrap rounded bg-neutral-950 px-2 py-1 font-mono text-[11px] text-neutral-200 light:bg-white light:text-neutral-800`,children:a.stdout})]}),a!==void 0&&a.stderr.length>0&&(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`div`,{className:`mb-0.5 text-[10px] uppercase tracking-wider text-neutral-500 light:text-neutral-600`,children:`stderr`}),(0,R.jsx)(`pre`,{className:`max-h-72 overflow-auto whitespace-pre-wrap rounded bg-neutral-950 px-2 py-1 font-mono text-[11px] text-red-300 light:bg-red-50 light:text-red-800`,children:a.stderr})]})]})]})}var eA=new Set([`single`,`parallel`,`chain`,`management`]);function tA(e){if(!e.endsWith(`.jsonl`))return;let t=Math.max(e.lastIndexOf(`/`),e.lastIndexOf(`\\`)),n=(t>=0?e.slice(t+1):e).slice(0,-6);if(n.length!==0)return n}function nA(e){if(typeof e!=`object`||!e)return{mode:`unknown`,results:[]};let t=e,n=eA.has(t.mode)?t.mode:`unknown`,r=typeof t.runId==`string`&&t.runId.length>0?t.runId:void 0,i=t.context===`fresh`||t.context===`fork`?t.context:void 0,a=[];if(Array.isArray(t.results))for(let e of t.results){if(typeof e!=`object`||!e)continue;let t=e,n={agent:typeof t.agent==`string`?t.agent:`agent`,task:typeof t.task==`string`?t.task:``,exitCode:typeof t.exitCode==`number`?t.exitCode:0};if(typeof t.sessionFile==`string`&&t.sessionFile.length>0){n.sessionFile=t.sessionFile;let e=tA(t.sessionFile);e!==void 0&&(n.sessionId=e)}typeof t.finalOutput==`string`&&t.finalOutput.length>0&&(n.finalOutput=t.finalOutput),a.push(n)}return{mode:n,...r===void 0?{}:{runId:r},...i===void 0?{}:{context:i},results:a}}function rA({sessionId:e,onClose:t}){let n=ci(e=>e.orchestrationEnabled),[r,i]=(0,v.useState)(void 0),[a,o]=(0,v.useState)([]),[s,c]=(0,v.useState)([]),[l,u]=(0,v.useState)(!1),[d,f]=(0,v.useState)(!1),[p,m]=(0,v.useState)(!1),[h,g]=(0,v.useState)(void 0),_=async()=>{f(!0),g(void 0);try{let t=await L.getSessionLink(e);i(t),t.role===`supervisor`?(o((await L.listSupervisorWorkers(e)).workers),c((await L.listSupervisorInbox(e)).items)):(o([]),c([]))}catch(e){g(e instanceof N?e.code:e.message)}finally{f(!1)}};if((0,v.useEffect)(()=>{if(!n)return;_();let e=setInterval(()=>{_()},4e3);return()=>clearInterval(e)},[n,e]),!n)return null;let y=r?.role??`standalone`;return(0,R.jsxs)(`div`,{className:`rounded-md border border-zinc-200 dark:border-zinc-800 bg-zinc-50 dark:bg-zinc-900/50 p-3 text-sm`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2 font-medium`,children:[(0,R.jsx)(rt,{size:14}),(0,R.jsx)(`span`,{children:`Orchestration`}),(0,R.jsx)(iA,{role:y})]}),(0,R.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,R.jsx)(`button`,{type:`button`,onClick:()=>{_()},title:`Refresh`,className:`p-1 text-zinc-500 hover:text-zinc-900 dark:hover:text-zinc-100`,children:d?(0,R.jsx)(Ne,{size:14,className:`animate-spin`}):(0,R.jsx)(Ue,{size:14})}),t!==void 0&&(0,R.jsx)(`button`,{type:`button`,onClick:t,title:`Close`,className:`p-1 text-zinc-500 hover:text-zinc-900 dark:hover:text-zinc-100`,children:(0,R.jsx)(it,{size:14})})]})]}),h!==void 0&&(0,R.jsx)(`div`,{className:`mt-2 rounded bg-red-100 dark:bg-red-900/30 text-red-800 dark:text-red-300 px-2 py-1 text-xs`,children:h}),y===`standalone`&&(0,R.jsx)(aA,{sessionId:e,busy:p,setBusy:m,setError:g,onAfter:_}),y===`supervisor`&&r!==void 0&&(0,R.jsx)(oA,{link:r,workers:a,inbox:s,showInbox:l,setShowInbox:u,busy:p,setBusy:m,setError:g,onAfter:_}),y===`worker`&&r!==void 0&&(0,R.jsx)(lA,{link:r})]})}function iA({role:e}){return(0,R.jsx)(`span`,{className:`rounded px-1.5 py-0.5 text-xs font-medium ${e===`supervisor`?`bg-violet-100 text-violet-800 dark:bg-violet-900/40 dark:text-violet-200`:e===`worker`?`bg-sky-100 text-sky-800 dark:bg-sky-900/40 dark:text-sky-200`:`bg-zinc-200 text-zinc-700 dark:bg-zinc-800 dark:text-zinc-300`}`,children:e===`supervisor`?`Supervisor`:e===`worker`?`Worker`:`Standalone`})}function aA({sessionId:e,busy:t,setBusy:n,setError:r,onAfter:i}){let a=async()=>{n(!0),r(void 0);try{await L.enableSupervisor(e),await i()}catch(e){r(e instanceof N?e.code:e.message)}finally{n(!1)}};return(0,R.jsxs)(`div`,{className:`mt-2 space-y-2`,children:[(0,R.jsxs)(`p`,{className:`text-xs text-zinc-600 dark:text-zinc-400`,children:[`This session is standalone. Enable supervisor mode to give this session the`,` `,(0,R.jsx)(`code`,{className:`text-xs`,children:`orchestrate_*`}),` tools — letting it spawn, observe, and coordinate other worker sessions in the same project.`]}),(0,R.jsx)(`button`,{type:`button`,onClick:()=>{a()},disabled:t,className:`rounded bg-violet-600 px-2.5 py-1 text-xs font-medium text-white hover:bg-violet-500 disabled:opacity-50`,children:t?`Enabling…`:`Enable supervisor mode`}),(0,R.jsx)(`p`,{className:`text-[11px] text-zinc-500 dark:text-zinc-400`,children:`The agent's tool list refreshes immediately — no reload needed.`})]})}function oA({link:e,workers:t,inbox:n,showInbox:r,setShowInbox:i,busy:a,setBusy:o,setError:s,onAfter:c}){let l=Jr(e=>e.setActiveSession),u=async()=>{if(confirm(`Disable supervisor mode? Linked workers become standalone sessions.`)){o(!0),s(void 0);try{await L.disableSupervisor(e.sessionId),await c()}catch(e){s(e instanceof N?e.code:e.message)}finally{o(!1)}}},d=async t=>{o(!0),s(void 0);try{await L.detachWorker(e.sessionId,t),await c()}catch(e){s(e instanceof N?e.code:e.message)}finally{o(!1)}},f=async t=>{if(confirm(`Kill worker ${t.slice(0,8)}? (Transcript stays on disk.)`)){o(!0),s(void 0);try{await L.killWorker(e.sessionId,t),await c()}catch(e){s(e instanceof N?e.code:e.message)}finally{o(!1)}}},p=async t=>{o(!0),s(void 0);try{await L.resumeWorker(e.sessionId,t),await c()}catch(e){s(e instanceof N?e.code:e.message)}finally{o(!1)}},m=async()=>{if(confirm(`Clear inbox history?`)){o(!0),s(void 0);try{await L.clearSupervisorInbox(e.sessionId),await c()}catch(e){s(e instanceof N?e.code:e.message)}finally{o(!1)}}},h=e.pendingInbox??0;return(0,R.jsxs)(`div`,{className:`mt-2 space-y-2`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,R.jsxs)(`div`,{className:`text-xs text-zinc-600 dark:text-zinc-400`,children:[t.length,` worker`,t.length===1?``:`s`,h>0?(0,R.jsxs)(`span`,{className:`ml-2 rounded bg-amber-200 dark:bg-amber-700/50 text-amber-900 dark:text-amber-100 px-1.5 py-0.5`,children:[h,` pending inbox`]}):null]}),(0,R.jsx)(`button`,{type:`button`,onClick:()=>{u()},disabled:a,className:`rounded text-xs text-zinc-600 dark:text-zinc-400 hover:text-red-600 dark:hover:text-red-400 disabled:opacity-50 px-1.5 py-0.5`,children:`Disable supervisor mode`})]}),t.length===0?(0,R.jsxs)(`p`,{className:`text-xs italic text-zinc-500 dark:text-zinc-400`,children:[`No workers yet. The agent can spawn one with`,` `,(0,R.jsx)(`code`,{className:`text-xs`,children:`orchestrate_spawn_worker`}),`.`]}):(0,R.jsx)(`ul`,{className:`divide-y divide-zinc-200 dark:divide-zinc-800 rounded border border-zinc-200 dark:border-zinc-800 bg-white dark:bg-zinc-950`,children:t.map(e=>(0,R.jsxs)(`li`,{className:`flex items-center gap-2 px-2 py-1.5`,children:[(0,R.jsx)(uA,{state:e.state??(e.isLive?`idle`:`cold`)}),(0,R.jsxs)(`button`,{type:`button`,onClick:()=>l(e.workerId),className:`flex-1 text-left truncate text-xs hover:underline`,title:e.workerId,children:[(0,R.jsx)(`span`,{className:`font-medium`,children:e.name??e.workerId.slice(0,8)}),e.messageCount!==void 0&&(0,R.jsxs)(`span`,{className:`ml-1 text-zinc-500`,children:[`(`,e.messageCount,` msgs)`]})]}),(0,R.jsxs)(`div`,{className:`flex items-center gap-1`,children:[!e.isLive&&(0,R.jsx)(`button`,{type:`button`,onClick:()=>{p(e.workerId)},disabled:a,className:`text-[11px] text-zinc-600 dark:text-zinc-400 hover:text-violet-700 dark:hover:text-violet-300 disabled:opacity-50 px-1 py-0.5`,children:`Resume`}),(0,R.jsx)(`button`,{type:`button`,onClick:()=>{d(e.workerId)},disabled:a,className:`text-[11px] text-zinc-600 dark:text-zinc-400 hover:text-amber-700 dark:hover:text-amber-300 disabled:opacity-50 px-1 py-0.5`,title:`Detach (worker continues as standalone)`,children:`Detach`}),(0,R.jsx)(`button`,{type:`button`,onClick:()=>{f(e.workerId)},disabled:a,className:`text-[11px] text-zinc-600 dark:text-zinc-400 hover:text-red-700 dark:hover:text-red-300 disabled:opacity-50 px-1 py-0.5`,title:`Kill (dispose live session; transcript stays on disk)`,children:`Kill`})]})]},e.workerId))}),(0,R.jsxs)(`details`,{open:r,onToggle:e=>i(e.currentTarget.open),children:[(0,R.jsxs)(`summary`,{className:`cursor-pointer text-xs text-zinc-600 dark:text-zinc-400 select-none`,children:[`Inbox history (`,n.length,`) `,h>0&&`— ${h} pending`]}),n.length===0?(0,R.jsx)(`p`,{className:`text-xs italic text-zinc-500 dark:text-zinc-400 mt-1`,children:`No inbox items.`}):(0,R.jsxs)(`div`,{className:`mt-1 space-y-1`,children:[(0,R.jsx)(`ul`,{className:`divide-y divide-zinc-200 dark:divide-zinc-800 rounded border border-zinc-200 dark:border-zinc-800 bg-white dark:bg-zinc-950 max-h-48 overflow-auto`,children:n.map(e=>(0,R.jsx)(sA,{item:e},e.id))}),(0,R.jsx)(`button`,{type:`button`,onClick:()=>{m()},disabled:a,className:`text-[11px] text-zinc-500 dark:text-zinc-400 hover:text-red-600 dark:hover:text-red-400 disabled:opacity-50`,children:`Clear inbox`})]})]})]})}function sA({item:e}){let t=cA(e.type);return(0,R.jsxs)(`li`,{className:`flex items-baseline gap-2 px-2 py-1 text-xs`,children:[(0,R.jsx)(`span`,{className:`rounded px-1 py-0.5 ${e.delivered?`bg-zinc-200 text-zinc-600 dark:bg-zinc-800 dark:text-zinc-400`:`bg-amber-200 text-amber-900 dark:bg-amber-700/40 dark:text-amber-200`}`,children:t}),(0,R.jsx)(`span`,{className:`font-mono text-zinc-500`,title:e.workerId,children:e.workerId.slice(0,8)}),(0,R.jsx)(`span`,{className:`text-zinc-500 ml-auto`,children:new Date(e.occurredAt).toLocaleTimeString()})]})}function cA(e){switch(e){case`worker.ended`:return`ended`;case`worker.ask_user`:return`asked`;case`worker.auto_retry_failed`:return`retry failed`;case`worker.process_alert`:return`process`;case`worker.deleted`:return`deleted`}}function lA({link:e}){let t=Jr(e=>e.setActiveSession),n=e.supervisorId;return n===void 0?null:(0,R.jsxs)(`div`,{className:`mt-2 text-xs text-zinc-600 dark:text-zinc-400`,children:[`Owned by supervisor`,` `,(0,R.jsx)(`button`,{type:`button`,onClick:()=>t(n),className:`font-mono underline hover:text-violet-700 dark:hover:text-violet-300`,title:n,children:n.slice(0,8)}),e.spawnedFrom!==void 0&&e.spawnedFrom.mode===`summary`&&(0,R.jsx)(`span`,{className:`ml-2 italic`,children:`(handoff with context summary)`})]})}function uA({state:e}){return(0,R.jsx)(`span`,{className:`inline-block h-2 w-2 rounded-full ${e===`streaming`?`bg-emerald-500 animate-pulse`:e===`idle`?`bg-sky-500`:`bg-zinc-400`}`,title:e,"aria-label":e})}var dA=(0,v.createContext)({viewType:`unified`,setViewType:()=>void 0}),fA=`forge.chat.viewType`;function pA(){try{return localStorage.getItem(fA)===`split`?`split`:`unified`}catch{return`unified`}}function mA({sessionId:e}){let t=Jr(t=>t.messagesBySession[e]??zr),n=Jr(t=>t.compactionsBySession[e]??Br),r=Jr(t=>t.streamingTextBySession[e]??``),i=Jr(t=>t.streamingBySession[e]??!1),a=Jr(t=>t.activeToolBySession[e]),o=Jr(t=>t.bannerBySession[e]),s=Jr(e=>e.clearBanner),c=Jr(t=>t.queuedBySession[e]),l=Jr(e=>e.openStream),u=Jr(e=>e.closeStream),d=Jr(t=>t.pendingScrollByMessageIndex[e]),f=Jr(e=>e.consumePendingScroll),p=ui(e=>e.runs),m=(0,v.useMemo)(()=>p.filter(t=>t.sessionId===e),[p,e]),[h,g]=(0,v.useState)(pA),_=e=>{g(e);try{localStorage.setItem(fA,e)}catch{}},y=dr(),[b,x]=(0,v.useState)(!1),[S,C]=(0,v.useState)(!1),w=ci(e=>e.orchestrationEnabled),T=st(),[E,D]=(0,v.useState)(!1),[O,k]=(0,v.useState)(void 0),ee=(0,v.useRef)(null);(0,v.useEffect)(()=>{if(!E)return;let e=e=>{ee.current!==null&&(ee.current.contains(e.target)||D(!1))};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[E]);let A=async t=>{D(!1),k(void 0);try{let{blob:n,filename:r}=await L.exportSession(e,t),i=URL.createObjectURL(n),a=document.createElement(`a`);a.href=i,a.download=r,document.body.appendChild(a),a.click(),a.remove(),window.setTimeout(()=>URL.revokeObjectURL(i),1e3)}catch(e){k(e instanceof N?`${e.code} (${e.status})`:e instanceof Error?e.message:`export_failed`),window.setTimeout(()=>k(void 0),4e3)}};(0,v.useEffect)(()=>(l(e),()=>{u(e)}),[e,l,u]);let te=(0,v.useRef)(null),ne=(0,v.useRef)(!0),re=()=>{let e=te.current;e!==null&&(ne.current=e.scrollHeight-e.scrollTop-e.clientHeight<=96)};(0,v.useEffect)(()=>{let e=te.current;e!==null&&ne.current&&(e.scrollTop=e.scrollHeight)},[t,r,i]);let ie=(0,v.useRef)(0);return(0,v.useEffect)(()=>{let e=t.reduce((e,t)=>t.role===`user`?e+1:e,0);if(e>ie.current){let e=te.current;e!==null&&(e.scrollTop=e.scrollHeight),ne.current=!0}ie.current=e},[t]),(0,v.useEffect)(()=>{if(d===void 0||t.length<=d)return;let n=te.current;if(n===null)return;let r=n.querySelector(`[data-message-index="${d}"]`);r!==null&&(r.scrollIntoView({block:`center`,behavior:`smooth`}),ne.current=!1,f(e))},[d,t.length,e,f]),(0,R.jsxs)(dA.Provider,{value:{viewType:h,setViewType:_},children:[(0,R.jsxs)(`div`,{className:`flex flex-1 flex-col overflow-hidden`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between gap-1 border-b border-neutral-800 bg-neutral-900/30 px-3 py-1`,children:[(0,R.jsx)(`div`,{className:`flex items-center gap-1`,children:y!==void 0&&(0,R.jsx)(Zk,{sessionId:e,projectId:y.id})}),(0,R.jsxs)(`div`,{className:`flex items-center gap-1`,children:[!T&&(0,R.jsxs)(`div`,{ref:ee,className:`relative`,children:[(0,R.jsxs)(`button`,{onClick:()=>D(e=>!e),"aria-haspopup":`menu`,"aria-expanded":E,className:`flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] uppercase tracking-wider text-neutral-400 hover:bg-neutral-800 hover:text-neutral-200`,title:`Export this conversation`,children:[(0,R.jsx)(ye,{size:11}),`Export`]}),E&&(0,R.jsxs)(`div`,{role:`menu`,className:`absolute right-0 top-full z-30 mt-1 min-w-[12rem] rounded-md border border-neutral-700 bg-neutral-900 py-1 shadow-xl`,children:[(0,R.jsxs)(`button`,{role:`menuitem`,onClick:()=>void A(`markdown`),className:`block w-full px-3 py-1.5 text-left text-xs text-neutral-200 hover:bg-neutral-800`,children:[`Markdown `,(0,R.jsx)(`span`,{className:`text-neutral-500`,children:`(.md)`})]}),(0,R.jsxs)(`button`,{role:`menuitem`,onClick:()=>void A(`jsonl`),className:`block w-full px-3 py-1.5 text-left text-xs text-neutral-200 hover:bg-neutral-800`,children:[`Raw JSONL `,(0,R.jsx)(`span`,{className:`text-neutral-500`,children:`(.jsonl)`})]})]})]}),O!==void 0&&(0,R.jsxs)(`span`,{className:`text-[10px] text-amber-400 light:text-amber-700`,role:`status`,children:[`Export failed: `,O]}),(0,R.jsxs)(`button`,{onClick:()=>x(!0),className:`flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] uppercase tracking-wider text-neutral-400 hover:bg-neutral-800 hover:text-neutral-200`,title:`Open session tree (navigate / fork from any prior point)`,children:[(0,R.jsx)(De,{size:11}),`Tree`]}),w&&(0,R.jsxs)(`button`,{onClick:()=>C(e=>!e),"aria-pressed":S,className:`flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] uppercase tracking-wider hover:bg-neutral-800 ${S?`bg-neutral-800 text-violet-300`:`text-neutral-400 hover:text-neutral-200`}`,title:`Orchestration — supervisor / worker controls`,children:[(0,R.jsx)(rt,{size:11}),`Orch`]})]})]}),S&&w&&(0,R.jsx)(`div`,{className:`border-b border-neutral-800 bg-neutral-900/40 px-3 py-2`,children:(0,R.jsx)(rA,{sessionId:e,onClose:()=>C(!1)})}),o!==void 0&&(0,R.jsxs)(`div`,{className:`flex items-start gap-2 border-b border-amber-700/40 bg-amber-900/20 px-6 py-2 text-xs text-amber-200 light:border-amber-300 light:bg-amber-50 light:text-amber-800`,children:[(0,R.jsx)(`div`,{className:`flex-1`,children:o}),(0,R.jsx)(`button`,{type:`button`,onClick:()=>s(e),className:`-mr-1 shrink-0 rounded p-0.5 text-amber-300 hover:bg-amber-900/40 hover:text-amber-100 light:text-amber-700 light:hover:bg-amber-100 light:hover:text-amber-900`,title:`Dismiss`,"aria-label":`Dismiss banner`,children:(0,R.jsx)(it,{size:14})})]}),(0,R.jsxs)(`div`,{ref:te,onScroll:re,className:`flex-1 overflow-y-auto px-6 py-4`,children:[t.length===0&&r.length===0&&!i&&(0,R.jsx)(`p`,{className:`mt-12 text-center text-sm text-neutral-500`,children:`No messages yet. Send a prompt to get started.`}),(0,R.jsxs)(`div`,{className:`chat-message-list mx-auto max-w-3xl space-y-4`,children:[(()=>{let e=new Map,r=new Set;for(let n of t)n.role===`toolResult`&&typeof n.toolCallId==`string`&&e.set(n.toolCallId,n);for(let e of t)if(!(e.role!==`assistant`||!Array.isArray(e.content)))for(let t of e.content)t.type===`toolCall`&&typeof t.id==`string`&&r.add(t.id);let i=new Map;for(let e of n){let t=i.get(e.insertBeforeIndex)??[];t.push(e),i.set(e.insertBeforeIndex,t)}let a=t=>t.archivedMessages.map((t,n)=>(0,R.jsx)(bA,{message:t,toolResultsById:e},n)),o=[],s=[],c=0,l=0,u=(e,t)=>{let n=jA(e),r=e.find(e=>e.kind===`tool`),i=e.some(e=>e.kind===`thinking`);return n===1&&!i&&r!==void 0?(0,R.jsx)(IA,{block:r.block,result:r.result},t):(0,R.jsx)(PA,{entries:e},t)},d=()=>{if(s.length===0)return;let e=[],t=c,n=()=>{if(e.length===0)return;let n=`tool-batch-${l}`;o.push((0,R.jsx)(`div`,{"data-message-index":t,children:u(e,`${n}-card`)},n)),e=[],l+=1};for(let r of s)r.kind===`tool`&&jA(e)>=TA&&(n(),t=c),e.push(r);n(),s=[]},f=e=>{let t=i.get(e);if(t!==void 0){d();for(let e of t)o.push((0,R.jsx)(sC,{event:e,renderArchived:()=>a(e)},`compaction-${e.id}`))}},p=n.length>0?n[n.length-1]:void 0,m=p?.insertBeforeIndex??0;for(let n=0;n<t.length;n++){let i=t[n];if(f(n),!(i.role===`toolResult`&&typeof i.toolCallId==`string`&&r.has(i.toolCallId))){if(i.role===`compactionSummary`){d();continue}if(p!==void 0&&n>=1&&n<m){d();continue}if(i.role===`assistant`&&Array.isArray(i.content)){let t=CA(i.content,e);if(t!==void 0){for(let[r,a]of t.entries()){if(a.kind===`tools`&&a.batchable){s.length===0&&(c=n),s.push(...a.entries);continue}d(),o.push((0,R.jsx)(`div`,{"data-message-index":n,children:(0,R.jsx)(SA,{segment:a,message:i,toolResultsById:e,showRaw:void 0,setShowRaw:void 0})},`${n}-${a.kind}-${r}`))}continue}}d(),o.push((0,R.jsx)(`div`,{"data-message-index":n,children:(0,R.jsx)(bA,{message:i,toolResultsById:e})},n))}}return d(),f(t.length),o})(),r.length>0&&(0,R.jsxs)(`div`,{className:`message-bubble rounded-lg border border-neutral-800 bg-neutral-900 px-4 py-3`,children:[(0,R.jsx)(`div`,{className:`mb-1 text-[10px] uppercase tracking-wider text-neutral-500`,children:`assistant (streaming)`}),(0,R.jsxs)(`div`,{className:`text-neutral-100`,children:[(0,R.jsx)(oC,{text:r}),(0,R.jsx)(`span`,{className:`ml-1 inline-block h-3 w-1.5 animate-pulse bg-neutral-300 align-text-bottom`})]})]}),i&&r.length===0&&(0,R.jsx)(gA,{tool:a}),c!==void 0&&(0,R.jsx)(hA,{queued:c}),m.map(e=>(0,R.jsx)($k,{run:e},e.runId))]})]})]}),b&&y!==void 0&&(0,R.jsx)(Ek,{sessionId:e,projectId:y.id,onClose:()=>x(!1)})]})}function hA({queued:e}){let t=[];for(let n of e.steering)t.push({kind:`steer`,text:n});for(let n of e.followUp)t.push({kind:`followUp`,text:n});return t.length===0?null:(0,R.jsxs)(`div`,{className:`rounded-md border border-neutral-800 bg-neutral-900/40 px-3 py-2`,children:[(0,R.jsxs)(`div`,{className:`mb-1 text-[10px] uppercase tracking-wider text-neutral-500`,children:[`queued (`,t.length,`)`]}),(0,R.jsx)(`ul`,{className:`space-y-1`,children:t.map(e=>(0,R.jsxs)(`li`,{className:`flex items-baseline gap-2 text-xs text-neutral-300`,children:[(0,R.jsx)(`span`,{className:e.kind===`steer`?`shrink-0 rounded bg-amber-900/30 px-1.5 py-0.5 text-[9px] uppercase tracking-wider text-amber-300 light:bg-amber-100 light:text-amber-800`:`shrink-0 rounded bg-neutral-800 px-1.5 py-0.5 text-[9px] uppercase tracking-wider text-neutral-400`,title:e.kind===`steer`?`Delivered at the agent's next decision point (often mid-tool)`:`Delivered after the agent goes fully idle`,children:e.kind===`steer`?`steer`:`follow-up`}),(0,R.jsx)(`span`,{className:`truncate`,children:e.text})]},`${e.kind}:${e.text}`))})]})}function gA({tool:e}){return e===void 0?(0,R.jsxs)(`div`,{className:`flex items-center gap-2 text-xs italic text-neutral-500`,"aria-live":`polite`,"aria-label":`Agent is thinking`,children:[(0,R.jsx)(`span`,{children:`Thinking`}),(0,R.jsxs)(`span`,{className:`pi-thinking-dots`,"aria-hidden":`true`,children:[(0,R.jsx)(`span`,{children:`.`}),(0,R.jsx)(`span`,{children:`.`}),(0,R.jsx)(`span`,{children:`.`})]})]}):(0,R.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-neutral-400`,children:[(0,R.jsx)(`span`,{className:`inline-block h-1.5 w-1.5 animate-pulse rounded-full bg-neutral-400`}),(0,R.jsx)(`span`,{className:`text-neutral-500`,children:`running`}),(0,R.jsx)(`code`,{className:`rounded bg-neutral-800 px-1.5 py-0.5 font-mono text-[11px] text-neutral-200`,children:e.name}),e.summary!==void 0&&(0,R.jsx)(`code`,{className:`truncate rounded bg-neutral-900 px-1.5 py-0.5 font-mono text-[11px] text-neutral-300`,title:e.summary,children:e.summary})]})}function _A({diff:e,filename:t,adds:n,dels:r}){let{viewType:i,setViewType:a}=(0,v.useContext)(dA);return(0,R.jsxs)(`details`,{className:`group rounded border border-neutral-800 bg-neutral-950 text-xs`,children:[(0,R.jsxs)(`summary`,{className:`flex cursor-pointer items-center justify-between gap-2 px-3 py-2 text-neutral-300`,children:[(0,R.jsxs)(`span`,{className:`flex min-w-0 items-baseline gap-2`,children:[(0,R.jsxs)(`span`,{className:`text-neutral-500`,children:[`edit`,t===void 0?``:` `]}),t!==void 0&&(0,R.jsx)(`span`,{className:`truncate font-mono`,children:t}),(0,R.jsxs)(`span`,{className:`ml-2 text-emerald-400 light:text-emerald-700`,children:[`+`,n]}),(0,R.jsxs)(`span`,{className:`ml-1 text-red-400 light:text-red-700`,children:[`−`,r]})]}),(0,R.jsx)(`button`,{onClick:e=>{e.preventDefault(),e.stopPropagation(),a(i===`split`?`unified`:`split`)},className:`rounded p-0.5 text-neutral-500 hover:bg-neutral-800 hover:text-neutral-200`,title:i===`split`?`Switch chat diffs to unified view`:`Switch chat diffs to side-by-side view`,children:i===`split`?(0,R.jsx)(Ge,{size:11}):(0,R.jsx)(_e,{size:11})})]}),(0,R.jsx)(mk,{diff:e,viewType:i})]})}function vA(e){let t=[],n=e.replace(/\n?(`{3,})(\w*)\s+file:\s+([^\n]+)\n([\s\S]*?)\n\1\n?/g,(e,n,r,i,a)=>(t.push({kind:`inline`,path:i.trim(),lang:r,content:a}),``)),r=/(^|\s)@(?:"([^"\n]+)"|([^\s]+?))(?=[?,;:!)\]]?(?:\s|$))/g,i;for(;(i=r.exec(n))!==null;){let e=(i[2]??i[3]??``).trim();e.length!==0&&(t.some(t=>t.kind===`inline`&&t.path===e)||t.push({kind:`defer`,path:e}))}return n=n.replace(/\n{3,}/g,`
|
|
344
344
|
|
|
345
|
-
`).trim(),{stripped:n,refs:t}}function yA({ref:e}){let[t,n]=(0,v.useState)(!1),r=e.kind===`inline`;return(0,R.jsxs)(`div`,{className:`overflow-hidden rounded border bg-neutral-900 ${r?`border-neutral-700`:`border-emerald-700/60 bg-emerald-900/15`}`,children:[(0,R.jsxs)(`button`,{type:`button`,onClick:()=>r&&n(e=>!e),disabled:!r,className:`flex min-h-11 w-full items-center gap-1.5 px-2 py-1 text-left text-[11px] md:min-h-0 ${r?`text-neutral-200 hover:bg-neutral-800`:`cursor-default text-emerald-200 light:text-emerald-800`}`,title:r?`${e.path} — click to ${t?`collapse`:`expand`}`:`${e.path} — model will load this on demand using its read tool (file is larger than the inline threshold)`,children:[r?t?(0,R.jsx)(ue,{size:12}):(0,R.jsx)(fe,{size:12}):(0,R.jsx)(se,{size:12,className:`text-emerald-300/80 light:text-emerald-700`}),(0,R.jsx)(xe,{size:12,className:r?`text-neutral-400`:`text-emerald-300/80`}),(0,R.jsx)(`span`,{className:`font-mono`,children:e.path}),r&&(0,R.jsx)(`span`,{className:`text-[10px] text-neutral-500`,children:e.content.length<1024?`${e.content.length} B`:`${(e.content.length/1024).toFixed(1)} KB`}),!r&&(0,R.jsx)(`span`,{className:`text-[10px] text-emerald-300/70 light:text-emerald-700/80`,children:`on demand`})]}),r&&t&&(0,R.jsx)(`pre`,{className:`max-h-72 overflow-auto border-t border-neutral-800 bg-neutral-950 px-3 py-2 font-mono text-[11px] leading-relaxed text-neutral-300`,children:e.content})]})}function bA({message:e,toolResultsById:t}){let[n,r]=(0,v.useState)(!1);if(e.role===`user`){let{stripped:t,refs:i}=vA(WA(e)),a=Array.isArray(e.content)?e.content:[],o=[],s=[];for(let e=0;e<a.length;e++){let t=a[e];if(t.type===`image`){let n=typeof t.data==`string`?t.data:``,r=typeof t.mimeType==`string`?t.mimeType:`image/png`,i=t.__blobUrl===!0?n:`data:${r};base64,${n}`;n.length>0&&o.push({src:i,key:`img-${e}`})}else if(t.type===`file`){let n={name:typeof t.filename==`string`?t.filename:`attachment`,key:`file-${e}`};typeof t.size==`number`&&(n.size=t.size),s.push(n)}}return(0,R.jsxs)(`div`,{className:`message-bubble group rounded-lg bg-neutral-800 px-4 py-3`,"data-message-role":`user`,children:[(0,R.jsxs)(`div`,{className:`mb-1 flex items-center justify-between`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,R.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-neutral-400`,children:`you`}),(0,R.jsx)(UA,{ts:e.timestamp})]}),t.length>0&&(0,R.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,R.jsx)(RA,{getText:()=>t,title:`Copy message text`}),(0,R.jsx)(BA,{showRaw:n,onToggle:r})]})]}),t.length>0&&(0,R.jsx)(`div`,{className:`text-neutral-100`,children:n?(0,R.jsx)(VA,{text:t}):(0,R.jsx)(oC,{text:t,chatStyleBreaks:!0})}),i.length>0&&(0,R.jsx)(`div`,{className:`mt-2 flex flex-col gap-1`,children:i.map((e,t)=>(0,R.jsx)(yA,{ref:e},`fileref-${t}-${e.path}`))}),o.length>0&&(0,R.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-2`,children:o.map(e=>(0,R.jsx)(`img`,{src:e.src,alt:``,className:`max-h-48 max-w-full rounded border border-neutral-700`},e.key))}),s.length>0&&(0,R.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-2`,children:s.map(e=>(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded border border-neutral-700 bg-neutral-900 px-2 py-1 text-[11px] text-neutral-300`,title:e.name,children:[(0,R.jsx)(`span`,{className:`font-mono`,children:e.name}),e.size!==void 0&&(0,R.jsx)(`span`,{className:`text-[10px] text-neutral-500`,children:e.size<1024?`${e.size} B`:e.size<1024*1024?`${(e.size/1024).toFixed(1)} KB`:`${(e.size/(1024*1024)).toFixed(1)} MB`})]},e.key))})]})}if(e.role===`assistant`){let i=Array.isArray(e.content)?e.content:[],a=i.some(e=>e.type===`text`),o=e.stopReason,s=e.errorMessage,c=o===`error`&&typeof s==`string`&&s.length>0?s:void 0;return(0,R.jsxs)(`div`,{className:`message-bubble group rounded-lg border border-neutral-800 bg-neutral-900 px-4 py-3`,"data-message-role":`assistant`,children:[(0,R.jsxs)(`div`,{className:`mb-1 flex items-center justify-between`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,R.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-neutral-500`,children:`assistant`}),(0,R.jsx)(UA,{ts:e.timestamp})]}),a&&(0,R.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,R.jsx)(RA,{getText:()=>zA(i),title:`Copy all text from this assistant message`}),(0,R.jsx)(BA,{showRaw:n,onToggle:r})]})]}),(0,R.jsx)(`div`,{className:`space-y-2 text-sm text-neutral-100`,children:xA(i,t,n)}),c!==void 0&&(0,R.jsxs)(`div`,{className:`mt-2 rounded border border-amber-700/40 bg-amber-900/20 px-3 py-2 text-xs text-amber-200 light:border-amber-300 light:bg-amber-50 light:text-amber-800`,role:`alert`,children:[(0,R.jsx)(`span`,{className:`font-medium`,children:`Provider error: `}),c]})]})}return e.role===`toolResult`?(0,R.jsx)(NA,{message:e}):e.role===`bashExecution`||e.type===`bashExecution`||e.customType===`bashExecution`?(0,R.jsx)(LA,{message:e}):(0,R.jsxs)(`details`,{className:`rounded-lg border border-neutral-800 bg-neutral-900/40 px-3 py-2 text-xs text-neutral-400`,children:[(0,R.jsxs)(`summary`,{className:`cursor-pointer`,children:[`unknown message (`,String(e.role??e.type??`?`),`)`]}),(0,R.jsx)(`pre`,{className:`mt-2 overflow-auto whitespace-pre-wrap text-[10px] text-neutral-500`,children:JSON.stringify(e,null,2)})]})}function xA(e,t,n){let r=[],i=0;for(;i<e.length;){let a=e[i];if(wA(a)){let n=i,a=[];for(;i<e.length&&DA(a)<SA;){let n=e[i];if(n===void 0)break;if(TA(n)){a.push({kind:`thinking`,block:n}),i+=1;continue}if(EA(n)){i+=1;continue}if(!wA(n))break;let r=typeof n.id==`string`?n.id:void 0,o=r===void 0?void 0:t?.get(r);a.push({kind:`tool`,block:n,result:o}),i+=1}if(DA(a)===1){let e=a.find(e=>e.kind===`tool`);e!==void 0&&r.push((0,R.jsx)(MA,{block:e.block,result:e.result},n))}else r.push((0,R.jsx)(AA,{entries:a},`tool-batch-${n}`));continue}let o={block:a,showRaw:n};t!==void 0&&(o.toolResultsById=t),r.push((0,R.jsx)(jA,{...o},i)),i+=1}return r}var SA=10,CA=new Set([`read`,`grep`,`find`,`ls`,`todo`,`process`,`bash`]);function wA(e){return e?.type===`toolCall`&&CA.has(String(e.name??``))}function TA(e){return e?.type===`thinking`}function EA(e){return e?.type===`text`&&typeof e.text==`string`&&e.text.trim().length===0}function DA(e){return e.filter(e=>e.kind===`tool`).length}function OA(e,t){if(e.role!==`assistant`||!Array.isArray(e.content))return;let n=[];for(let r of e.content){if(TA(r)){n.push({kind:`thinking`,block:r});continue}if(EA(r))continue;if(!wA(r))return;let e=typeof r.id==`string`?r.id:void 0;n.push({kind:`tool`,block:r,result:e===void 0?void 0:t?.get(e)})}return DA(n)>0?n:void 0}function kA(e,t){let n=HA(t)?t:void 0;if(e===`bash`)return typeof n?.command==`string`?n.command:void 0;if(e===`process`){let e=typeof n?.action==`string`?n.action:void 0,t=typeof n?.name==`string`?n.name:void 0,r=typeof n?.command==`string`?n.command:void 0;return[e,t??r].filter(Boolean).join(` `)||void 0}if(e===`todo`)return[typeof n?.action==`string`?n.action:void 0,typeof n?.subject==`string`?n.subject:void 0].filter(Boolean).join(` `)||void 0;if((e===`read`||e===`grep`||e===`find`||e===`ls`)&&n!==void 0){let e=typeof n.path==`string`?n.path:void 0,t=typeof n.pattern==`string`?n.pattern:void 0;return e??t}}function AA({entries:e}){let t=e.filter(e=>e.kind===`tool`),n=t.length,r=t.filter(e=>e.result===void 0).length,i=t.some(e=>e.result?.isError===!0),a=new Map;for(let e of t){let t=String(e.block.name??`tool`);a.set(t,(a.get(t)??0)+1)}let o=[...a].map(([e,t])=>`${e} ×${t}`).join(` · `),s=t.map(e=>{let t=String(e.block.name??`tool`),n=kA(t,e.block.input??e.block.arguments??{});return n===void 0?t:`${t}: ${n}`}).slice(0,3);return(0,R.jsxs)(`details`,{className:`group rounded border border-neutral-800 bg-neutral-950 text-xs`,children:[(0,R.jsxs)(`summary`,{className:`flex cursor-pointer items-center justify-between gap-2 px-3 py-2 text-neutral-300`,children:[(0,R.jsxs)(`span`,{className:`flex min-w-0 items-baseline gap-2`,children:[(0,R.jsx)(`span`,{className:`text-neutral-500`,children:`→`}),(0,R.jsx)(`span`,{className:`font-mono`,children:`tools`}),(0,R.jsxs)(`span`,{className:`text-neutral-500`,children:[`×`,n,` `,n===1?`call`:`calls`]}),(0,R.jsx)(`span`,{className:`truncate text-neutral-400`,title:o,children:o}),s.length>0&&(0,R.jsxs)(`span`,{className:`ml-2 truncate font-mono text-[10px] text-neutral-500`,children:[s.join(` · `),n>s.length?` · …`:``]})]}),(0,R.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[r>0&&(0,R.jsxs)(`span`,{className:`rounded bg-neutral-800 px-1.5 py-0.5 text-[10px] uppercase tracking-wider text-neutral-400`,children:[r,` running…`]}),i&&(0,R.jsx)(`span`,{className:`rounded bg-red-900/30 px-1.5 py-0.5 text-[10px] uppercase tracking-wider text-red-300 light:bg-red-100 light:text-red-800`,children:`error`})]})]}),(0,R.jsx)(`div`,{className:`space-y-2 border-t border-neutral-800/60 px-3 py-2`,children:e.map((e,t)=>e.kind===`thinking`?(0,R.jsx)(jA,{block:e.block},t):(0,R.jsx)(MA,{block:e.block,result:e.result},t))})]})}function jA({block:e,toolResultsById:t,showRaw:n=!1}){let r=e.type;if(r===`text`&&typeof e.text==`string`)return n?(0,R.jsx)(VA,{text:e.text}):(0,R.jsx)(oC,{text:e.text});if(r===`thinking`&&typeof e.thinking==`string`)return(0,R.jsxs)(`details`,{className:`rounded border border-neutral-800 px-2 py-1 text-xs text-neutral-400`,children:[(0,R.jsx)(`summary`,{className:`cursor-pointer`,children:`Thinking…`}),(0,R.jsx)(`pre`,{className:`mt-1 whitespace-pre-wrap break-words font-sans text-[12px]`,children:e.thinking})]});if(r===`toolCall`){let n=typeof e.id==`string`?e.id:void 0;return(0,R.jsx)(MA,{block:e,result:n===void 0?void 0:t?.get(n)})}return(0,R.jsxs)(`details`,{className:`text-xs text-neutral-500`,children:[(0,R.jsxs)(`summary`,{className:`cursor-pointer`,children:[`block (`,String(r??`?`),`)`]}),(0,R.jsx)(`pre`,{className:`mt-1 overflow-auto whitespace-pre-wrap text-[10px]`,children:JSON.stringify(e,null,2)})]})}function MA({block:e,result:t}){let n=String(e.name??`tool`),r=e.input??e.arguments??{},i=typeof r==`string`?r:JSON.stringify(r,null,2),a=t?.isError===!0,o=Array.isArray(t?.content)?t?.content:[],s=HA(r)?r:void 0,c=n===`bash`&&typeof s?.command==`string`?s.command:(n===`read`||n===`write`||n===`edit`)&&typeof s?.path==`string`?s.path:void 0,l=o.filter(e=>{let t=e;return t.type===`text`&&typeof t.text==`string`}).map(e=>e.text).join(`
|
|
346
|
-
`),u=n===`edit`&&t!==void 0?(()=>{let e=t.details?.diff;return typeof e==`string`?e:l})():void 0,d=n===`edit`&&t!==void 0?
|
|
347
|
-
`);if(t===`edit`){let t=e.details,n=typeof t?.diff==`string`?t.diff:r,i=
|
|
348
|
-
`).length,` lines)`]})]}),(0,R.jsx)(`pre`,{className:`overflow-auto px-3 pb-2 font-mono text-[11px] text-neutral-400`,children:r})]})}return t===`subagent`?(0,R.jsx)(
|
|
345
|
+
`).trim(),{stripped:n,refs:t}}function yA({ref:e}){let[t,n]=(0,v.useState)(!1),r=e.kind===`inline`;return(0,R.jsxs)(`div`,{className:`overflow-hidden rounded border bg-neutral-900 ${r?`border-neutral-700`:`border-emerald-700/60 bg-emerald-900/15`}`,children:[(0,R.jsxs)(`button`,{type:`button`,onClick:()=>r&&n(e=>!e),disabled:!r,className:`flex min-h-11 w-full items-center gap-1.5 px-2 py-1 text-left text-[11px] md:min-h-0 ${r?`text-neutral-200 hover:bg-neutral-800`:`cursor-default text-emerald-200 light:text-emerald-800`}`,title:r?`${e.path} — click to ${t?`collapse`:`expand`}`:`${e.path} — model will load this on demand using its read tool (file is larger than the inline threshold)`,children:[r?t?(0,R.jsx)(ue,{size:12}):(0,R.jsx)(fe,{size:12}):(0,R.jsx)(se,{size:12,className:`text-emerald-300/80 light:text-emerald-700`}),(0,R.jsx)(xe,{size:12,className:r?`text-neutral-400`:`text-emerald-300/80`}),(0,R.jsx)(`span`,{className:`font-mono`,children:e.path}),r&&(0,R.jsx)(`span`,{className:`text-[10px] text-neutral-500`,children:e.content.length<1024?`${e.content.length} B`:`${(e.content.length/1024).toFixed(1)} KB`}),!r&&(0,R.jsx)(`span`,{className:`text-[10px] text-emerald-300/70 light:text-emerald-700/80`,children:`on demand`})]}),r&&t&&(0,R.jsx)(`pre`,{className:`max-h-72 overflow-auto border-t border-neutral-800 bg-neutral-950 px-3 py-2 font-mono text-[11px] leading-relaxed text-neutral-300`,children:e.content})]})}function bA({message:e,toolResultsById:t}){let[n,r]=(0,v.useState)(!1);if(e.role===`user`){let{stripped:t,refs:i}=vA(JA(e)),a=Array.isArray(e.content)?e.content:[],o=[],s=[];for(let e=0;e<a.length;e++){let t=a[e];if(t.type===`image`){let n=typeof t.data==`string`?t.data:``,r=typeof t.mimeType==`string`?t.mimeType:`image/png`,i=t.__blobUrl===!0?n:`data:${r};base64,${n}`;n.length>0&&o.push({src:i,key:`img-${e}`})}else if(t.type===`file`){let n={name:typeof t.filename==`string`?t.filename:`attachment`,key:`file-${e}`};typeof t.size==`number`&&(n.size=t.size),s.push(n)}}return(0,R.jsxs)(`div`,{className:`message-bubble group rounded-lg bg-neutral-800 px-4 py-3`,"data-message-role":`user`,children:[(0,R.jsxs)(`div`,{className:`mb-1 flex items-center justify-between`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,R.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-neutral-400`,children:`you`}),(0,R.jsx)(qA,{ts:e.timestamp})]}),t.length>0&&(0,R.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,R.jsx)(HA,{getText:()=>t,title:`Copy message text`}),(0,R.jsx)(WA,{showRaw:n,onToggle:r})]})]}),t.length>0&&(0,R.jsx)(`div`,{className:`text-neutral-100`,children:n?(0,R.jsx)(GA,{text:t}):(0,R.jsx)(oC,{text:t,chatStyleBreaks:!0})}),i.length>0&&(0,R.jsx)(`div`,{className:`mt-2 flex flex-col gap-1`,children:i.map((e,t)=>(0,R.jsx)(yA,{ref:e},`fileref-${t}-${e.path}`))}),o.length>0&&(0,R.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-2`,children:o.map(e=>(0,R.jsx)(`img`,{src:e.src,alt:``,className:`max-h-48 max-w-full rounded border border-neutral-700`},e.key))}),s.length>0&&(0,R.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-2`,children:s.map(e=>(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded border border-neutral-700 bg-neutral-900 px-2 py-1 text-[11px] text-neutral-300`,title:e.name,children:[(0,R.jsx)(`span`,{className:`font-mono`,children:e.name}),e.size!==void 0&&(0,R.jsx)(`span`,{className:`text-[10px] text-neutral-500`,children:e.size<1024?`${e.size} B`:e.size<1024*1024?`${(e.size/1024).toFixed(1)} KB`:`${(e.size/(1024*1024)).toFixed(1)} MB`})]},e.key))})]})}if(e.role===`assistant`){let i=Array.isArray(e.content)?e.content:[],a=CA(i,t);return a===void 0?(0,R.jsx)(xA,{message:e,content:i,toolResultsById:t,showRaw:n,setShowRaw:r}):(0,R.jsx)(`div`,{className:`space-y-2`,children:a.map((i,a)=>(0,R.jsx)(SA,{segment:i,message:e,toolResultsById:t,showRaw:n,setShowRaw:r},`${i.kind}-${a}`))})}return e.role===`toolResult`?(0,R.jsx)(LA,{message:e}):e.role===`bashExecution`||e.type===`bashExecution`||e.customType===`bashExecution`?(0,R.jsx)(VA,{message:e}):(0,R.jsxs)(`details`,{className:`rounded-lg border border-neutral-800 bg-neutral-900/40 px-3 py-2 text-xs text-neutral-400`,children:[(0,R.jsxs)(`summary`,{className:`cursor-pointer`,children:[`unknown message (`,String(e.role??e.type??`?`),`)`]}),(0,R.jsx)(`pre`,{className:`mt-2 overflow-auto whitespace-pre-wrap text-[10px] text-neutral-500`,children:JSON.stringify(e,null,2)})]})}function xA({message:e,content:t,toolResultsById:n,showRaw:r,setShowRaw:i}){let a=t.some(e=>e.type===`text`),o=e.stopReason,s=e.errorMessage,c=o===`error`&&typeof s==`string`&&s.length>0?s:void 0;return(0,R.jsxs)(`div`,{className:`message-bubble group rounded-lg border border-neutral-800 bg-neutral-900 px-4 py-3`,"data-message-role":`assistant`,children:[(0,R.jsxs)(`div`,{className:`mb-1 flex items-center justify-between`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,R.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-neutral-500`,children:`assistant`}),(0,R.jsx)(qA,{ts:e.timestamp})]}),a&&(0,R.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,R.jsx)(HA,{getText:()=>UA(t),title:`Copy all text from this assistant message`}),(0,R.jsx)(WA,{showRaw:r,onToggle:i})]})]}),(0,R.jsx)(`div`,{className:`space-y-2 text-sm text-neutral-100`,children:wA(t,n,r)}),c!==void 0&&(0,R.jsxs)(`div`,{className:`mt-2 rounded border border-amber-700/40 bg-amber-900/20 px-3 py-2 text-xs text-amber-200 light:border-amber-300 light:bg-amber-50 light:text-amber-800`,role:`alert`,children:[(0,R.jsx)(`span`,{className:`font-medium`,children:`Provider error: `}),c]})]})}function SA({segment:e,message:t,toolResultsById:n,showRaw:r,setShowRaw:i}){let[a,o]=(0,v.useState)(!1),s=r??a,c=i??o;if(e.kind===`assistant`)return(0,R.jsx)(xA,{message:t,content:e.content,toolResultsById:n,showRaw:s,setShowRaw:c});let l=jA(e.entries),u=e.entries.find(e=>e.kind===`tool`),d=e.entries.some(e=>e.kind===`thinking`);return!e.batchable&&u!==void 0?(0,R.jsx)(`div`,{className:`space-y-2`,children:e.entries.map((e,t)=>e.kind===`thinking`?(0,R.jsx)(FA,{block:e.block},`thinking-${t}`):(0,R.jsx)(IA,{block:e.block,result:e.result},`tool-${t}`))}):l===1&&!d&&u!==void 0?(0,R.jsx)(IA,{block:u.block,result:u.result}):(0,R.jsx)(PA,{entries:e.entries})}function CA(e,t){let n=[],r=[],i=!1,a=()=>{r.length!==0&&(n.push({kind:`assistant`,content:r}),r=[])},o=0;for(;o<e.length;){let s=e[o];if(!DA(s)){r.push(s),o+=1;continue}let c=MA(r);if(a(),i=!0,!OA(s)){let e=typeof s.id==`string`?s.id:void 0;n.push({kind:`tools`,batchable:!1,entries:[...c,{kind:`tool`,block:s,result:e===void 0?void 0:t?.get(e)}]}),o+=1;continue}let l=[...c];for(;o<e.length&&jA(l)<TA;){let n=e[o];if(n===void 0)break;if(kA(n)){l.push({kind:`thinking`,block:n}),o+=1;continue}if(AA(n)){o+=1;continue}if(!OA(n))break;let r=typeof n.id==`string`?n.id:void 0;l.push({kind:`tool`,block:n,result:r===void 0?void 0:t?.get(r)}),o+=1}n.push({kind:`tools`,batchable:!0,entries:l})}return a(),i?n:void 0}function wA(e,t,n){return e.map((e,r)=>{let i={block:e,showRaw:n};return t!==void 0&&(i.toolResultsById=t),(0,R.jsx)(FA,{...i},r)})}var TA=10,EA=new Set([`edit`,`write`]);function DA(e){return e?.type===`toolCall`}function OA(e){return e?.type===`toolCall`&&!EA.has(String(e.name??``))}function kA(e){return e?.type===`thinking`}function AA(e){return e?.type===`text`&&typeof e.text==`string`&&e.text.trim().length===0}function jA(e){return e.filter(e=>e.kind===`tool`).length}function MA(e){let t=[];for(;e.length>0;){let n=e[e.length-1];if(AA(n)){e.pop();continue}if(!kA(n))break;t.unshift({kind:`thinking`,block:n}),e.pop()}return t}function NA(e,t){let n=KA(t)?t:void 0;if(e===`bash`)return typeof n?.command==`string`?n.command:void 0;if(e===`process`){let e=typeof n?.action==`string`?n.action:void 0,t=typeof n?.name==`string`?n.name:void 0,r=typeof n?.command==`string`?n.command:void 0;return[e,t??r].filter(Boolean).join(` `)||void 0}if(e===`todo`)return[typeof n?.action==`string`?n.action:void 0,typeof n?.subject==`string`?n.subject:void 0].filter(Boolean).join(` `)||void 0;if((e===`read`||e===`grep`||e===`find`||e===`ls`)&&n!==void 0){let e=typeof n.path==`string`?n.path:void 0,t=typeof n.pattern==`string`?n.pattern:void 0;return e??t}}function PA({entries:e}){let t=e.filter(e=>e.kind===`tool`),n=t.length,r=t.filter(e=>e.result===void 0).length,i=t.some(e=>e.result?.isError===!0),a=new Map;for(let e of t){let t=String(e.block.name??`tool`);a.set(t,(a.get(t)??0)+1)}let o=[...a].map(([e,t])=>`${e} ×${t}`).join(` · `),s=t.map(e=>{let t=String(e.block.name??`tool`),n=NA(t,e.block.input??e.block.arguments??{});return n===void 0?t:`${t}: ${n}`}).slice(0,3);return(0,R.jsxs)(`details`,{className:`group rounded border border-neutral-800 bg-neutral-950 text-xs`,children:[(0,R.jsxs)(`summary`,{className:`flex cursor-pointer flex-col gap-2 px-3 py-2 text-neutral-300 sm:flex-row sm:items-center sm:justify-between`,children:[(0,R.jsxs)(`span`,{className:`flex min-w-0 flex-wrap items-baseline gap-x-2 gap-y-1`,children:[(0,R.jsx)(`span`,{className:`text-neutral-500`,children:`→`}),(0,R.jsx)(`span`,{className:`font-mono`,children:`tools`}),(0,R.jsxs)(`span`,{className:`text-neutral-500`,children:[`×`,n,` `,n===1?`call`:`calls`]}),(0,R.jsx)(`span`,{className:`max-w-full truncate text-neutral-400`,title:o,children:o}),s.length>0&&(0,R.jsxs)(`span`,{className:`basis-full truncate font-mono text-[10px] text-neutral-500 sm:ml-2 sm:basis-auto`,children:[s.join(` · `),n>s.length?` · …`:``]})]}),(0,R.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1 self-start sm:self-auto`,children:[r>0&&(0,R.jsxs)(`span`,{className:`rounded bg-neutral-800 px-1.5 py-0.5 text-[10px] uppercase tracking-wider text-neutral-400`,children:[r,` running…`]}),i&&(0,R.jsx)(`span`,{className:`rounded bg-red-900/30 px-1.5 py-0.5 text-[10px] uppercase tracking-wider text-red-300 light:bg-red-100 light:text-red-800`,children:`error`})]})]}),(0,R.jsx)(`div`,{className:`space-y-2 border-t border-neutral-800/60 px-3 py-2`,children:e.map((e,t)=>e.kind===`thinking`?(0,R.jsx)(FA,{block:e.block},t):(0,R.jsx)(IA,{block:e.block,result:e.result},t))})]})}function FA({block:e,toolResultsById:t,showRaw:n=!1}){let r=e.type;if(r===`text`&&typeof e.text==`string`)return n?(0,R.jsx)(GA,{text:e.text}):(0,R.jsx)(oC,{text:e.text});if(r===`thinking`&&typeof e.thinking==`string`)return(0,R.jsxs)(`details`,{className:`rounded border border-neutral-800 px-2 py-1 text-xs text-neutral-400`,children:[(0,R.jsx)(`summary`,{className:`cursor-pointer`,children:`Thinking…`}),(0,R.jsx)(`pre`,{className:`mt-1 whitespace-pre-wrap break-words font-sans text-[12px]`,children:e.thinking})]});if(r===`toolCall`){let n=typeof e.id==`string`?e.id:void 0;return(0,R.jsx)(IA,{block:e,result:n===void 0?void 0:t?.get(n)})}return(0,R.jsxs)(`details`,{className:`text-xs text-neutral-500`,children:[(0,R.jsxs)(`summary`,{className:`cursor-pointer`,children:[`block (`,String(r??`?`),`)`]}),(0,R.jsx)(`pre`,{className:`mt-1 overflow-auto whitespace-pre-wrap text-[10px]`,children:JSON.stringify(e,null,2)})]})}function IA({block:e,result:t}){let n=String(e.name??`tool`),r=e.input??e.arguments??{},i=typeof r==`string`?r:JSON.stringify(r,null,2),a=t?.isError===!0,o=Array.isArray(t?.content)?t?.content:[],s=KA(r)?r:void 0,c=n===`bash`&&typeof s?.command==`string`?s.command:(n===`read`||n===`write`||n===`edit`)&&typeof s?.path==`string`?s.path:void 0,l=o.filter(e=>{let t=e;return t.type===`text`&&typeof t.text==`string`}).map(e=>e.text).join(`
|
|
346
|
+
`),u=n===`edit`&&t!==void 0?(()=>{let e=t.details?.diff;return typeof e==`string`?e:l})():void 0,d=n===`edit`&&t!==void 0?YA(t):void 0,f=u===void 0?void 0:XA(u);return n===`subagent`?(0,R.jsx)(RA,{argsText:i,input:s,result:t,isError:a,outputText:l}):(0,R.jsxs)(`div`,{className:`rounded border ${t===void 0?`border-neutral-700`:a?`border-red-700/50`:`border-neutral-800`} bg-neutral-950 text-xs`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2 text-neutral-300`,children:[(0,R.jsxs)(`div`,{className:`min-w-0 flex-1 truncate`,children:[(0,R.jsx)(`span`,{className:`text-neutral-500`,children:`→ `}),(0,R.jsx)(`span`,{className:`font-mono`,children:n}),c!==void 0&&(0,R.jsx)(`span`,{className:`ml-2 truncate font-mono text-neutral-400`,title:c,children:c})]}),(0,R.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[t===void 0&&(0,R.jsx)(`span`,{className:`rounded bg-neutral-800 px-1.5 py-0.5 text-[10px] uppercase tracking-wider text-neutral-400`,children:`running…`}),a&&(0,R.jsx)(`span`,{className:`rounded bg-red-900/30 px-1.5 py-0.5 text-[10px] uppercase tracking-wider text-red-300 light:bg-red-100 light:text-red-800`,children:`error`})]})]}),i.length>0&&(0,R.jsxs)(`details`,{className:`border-t border-neutral-800/60`,children:[(0,R.jsx)(`summary`,{className:`cursor-pointer px-3 py-1.5 text-[11px] text-neutral-500 hover:text-neutral-300`,children:`Input`}),(0,R.jsx)(`pre`,{className:`overflow-auto px-3 pb-2 font-mono text-[11px] text-neutral-400`,children:i})]}),t!==void 0&&(0,R.jsxs)(`details`,{className:`border-t border-neutral-800/60`,children:[(0,R.jsxs)(`summary`,{className:`cursor-pointer px-3 py-1.5 text-[11px] text-neutral-500 hover:text-neutral-300`,children:[`Output`,f!==void 0&&(0,R.jsxs)(`span`,{className:`ml-2 font-mono text-[10px]`,children:[(0,R.jsxs)(`span`,{className:`text-emerald-400 light:text-emerald-700`,children:[`+`,f.adds]}),` `,(0,R.jsxs)(`span`,{className:`text-red-400 light:text-red-700`,children:[`-`,f.dels]})]}),d!==void 0&&(0,R.jsx)(`span`,{className:`ml-2 font-mono text-[10px] text-neutral-500`,children:d})]}),u!==void 0&&f!==void 0?(0,R.jsx)(`div`,{className:`px-3 pb-2`,children:(0,R.jsx)(_A,{diff:u,filename:d,adds:f.adds,dels:f.dels})}):(0,R.jsx)(`pre`,{className:`max-h-96 overflow-auto px-3 pb-2 font-mono text-[11px] text-neutral-300`,children:l.length>0?l:`(empty)`})]})]})}function LA({message:e}){let t=String(e.toolName??`tool`),n=e.isError===!0,r=(Array.isArray(e.content)?e.content:[]).filter(e=>{let t=e;return t.type===`text`&&typeof t.text==`string`}).map(e=>e.text).join(`
|
|
347
|
+
`);if(t===`edit`){let t=e.details,n=typeof t?.diff==`string`?t.diff:r,i=YA(e),{adds:a,dels:o}=XA(n);return(0,R.jsx)(_A,{diff:n,filename:i,adds:a,dels:o})}if(t===`read`){let t=YA(e);return(0,R.jsxs)(`details`,{className:`rounded border border-neutral-800 bg-neutral-950 text-xs`,children:[(0,R.jsxs)(`summary`,{className:`cursor-pointer px-3 py-2 text-neutral-300`,children:[(0,R.jsxs)(`span`,{className:`text-neutral-500`,children:[`read`,t===void 0?``:` `]}),t!==void 0&&(0,R.jsx)(`span`,{className:`font-mono`,children:t})]}),(0,R.jsx)(`pre`,{className:`overflow-auto px-3 pb-2 font-mono text-[11px] text-neutral-400`,children:r})]})}if(t===`bash`){let t=ZA(e);return(0,R.jsxs)(`div`,{className:`rounded border ${n?`border-red-700/40`:`border-neutral-800`} bg-neutral-950 text-xs`,children:[(0,R.jsxs)(`div`,{className:`px-3 py-2 text-neutral-400`,children:[(0,R.jsxs)(`span`,{className:`text-neutral-500`,children:[`bash`,t===void 0?` output`:` → `]}),t!==void 0&&(0,R.jsx)(`span`,{className:`font-mono`,children:t})]}),(0,R.jsx)(`pre`,{className:`max-h-64 overflow-auto px-3 pb-2 font-mono text-[11px] text-neutral-300`,children:r})]})}if(t===`write`){let t=YA(e);return(0,R.jsxs)(`details`,{className:`rounded border border-neutral-800 bg-neutral-950 text-xs`,children:[(0,R.jsxs)(`summary`,{className:`cursor-pointer px-3 py-2 text-neutral-300`,children:[(0,R.jsxs)(`span`,{className:`text-neutral-500`,children:[`write`,t===void 0?``:` `]}),t!==void 0&&(0,R.jsx)(`span`,{className:`font-mono`,children:t}),(0,R.jsxs)(`span`,{className:`ml-2 text-neutral-500`,children:[`(`,r.split(`
|
|
348
|
+
`).length,` lines)`]})]}),(0,R.jsx)(`pre`,{className:`overflow-auto px-3 pb-2 font-mono text-[11px] text-neutral-400`,children:r})]})}return t===`subagent`?(0,R.jsx)(zA,{message:e,argsText:``,outputText:r,isError:n}):(0,R.jsxs)(`details`,{className:`rounded border ${n?`border-red-700/40 light:border-red-300`:`border-neutral-800`} bg-neutral-950 text-xs`,children:[(0,R.jsxs)(`summary`,{className:`cursor-pointer px-3 py-2 text-neutral-300`,children:[(0,R.jsx)(`span`,{className:`text-neutral-500`,children:t}),n&&(0,R.jsx)(`span`,{className:`ml-2 text-red-400 light:text-red-700`,children:`error`})]}),(0,R.jsx)(`pre`,{className:`overflow-auto px-3 pb-2 font-mono text-[11px] text-neutral-400`,children:r})]})}function RA({argsText:e,input:t,result:n,isError:r,outputText:i}){if(n!==void 0)return(0,R.jsx)(zA,{message:n,argsText:e,outputText:i,isError:r});let a;if(t!==void 0){let e=typeof t.agent==`string`?t.agent:void 0,n=typeof t.task==`string`?t.task:void 0,r=typeof t.action==`string`?t.action:void 0,i=Array.isArray(t.tasks)?t.tasks.length:void 0,o=Array.isArray(t.chain)?t.chain.length:void 0;r===void 0?i===void 0?o===void 0?e!==void 0&&n!==void 0?a=`${e} — ${n}`:e!==void 0&&(a=e):a=`${o}-step chain`:a=`${i} parallel task${i===1?``:`s`}`:a=`action: ${r}`}return(0,R.jsx)(`div`,{className:`overflow-hidden rounded border border-l-2 border-sky-700/50 border-l-sky-400 bg-sky-950/15 text-xs light:border-sky-300 light:border-l-sky-600 light:bg-sky-50`,children:(0,R.jsx)(`div`,{className:`flex items-center justify-between gap-2 px-2.5 py-1.5`,children:(0,R.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5`,children:[(0,R.jsx)(rt,{size:11,className:`shrink-0 text-sky-300 light:text-sky-700`}),(0,R.jsx)(`span`,{className:`truncate font-medium text-sky-100 light:text-sky-900`,children:`Sub-agent running…`}),a!==void 0&&(0,R.jsx)(`span`,{className:`ml-1 truncate font-mono text-[11px] text-sky-200/70 light:text-sky-800/80`,title:a,children:a})]})})})}function zA({message:e,argsText:t,outputText:n,isError:r}){let i=Jr(e=>e.setActiveSession),a=ur(e=>e.setActive),o=Jr(e=>e.byProject),s=(0,v.useMemo)(()=>{let e=new Map;for(let t of Object.values(o))for(let n of t)typeof n.path==`string`&&n.path.length>0&&e.set(n.path,{sessionId:n.sessionId,projectId:n.projectId});return e},[o]),c=e=>{if(e===void 0){console.warn(`[subagent] Open clicked but result has no sessionFile`);return}let t=s.get(e);if(console.info(`[subagent] Open clicked`,{sessionFile:e,match:t}),t===void 0){console.warn(`[subagent] Open: sessionFile not found in any project's session list`,e);return}a(t.projectId),i(t.sessionId)},l=nA(e.details),u=l.mode===`management`,d=l.results.length,f=d===1?`Sub-agent: ${l.results[0].agent}`:d>1?`${d} sub-agents (${l.mode})`:u?`Sub-agent management`:`Sub-agent`;return(0,R.jsxs)(`div`,{className:`overflow-hidden rounded border border-l-2 ${r?`border-red-700/50 border-l-red-400 bg-red-950/15 light:border-red-300 light:border-l-red-600 light:bg-red-50`:`border-sky-700/50 border-l-sky-400 bg-sky-950/15 light:border-sky-300 light:border-l-sky-600 light:bg-sky-50`} text-xs`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-2.5 py-1.5`,children:[(0,R.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5`,children:[(0,R.jsx)(rt,{size:11,className:`shrink-0 text-sky-300 light:text-sky-700`}),(0,R.jsx)(`span`,{className:`truncate font-medium text-sky-100 light:text-sky-900`,children:f}),l.context!==void 0&&(0,R.jsx)(`span`,{className:`shrink-0 rounded bg-sky-900/40 px-1 py-0.5 text-[9px] font-medium uppercase tracking-wider text-sky-200 light:bg-sky-100 light:text-sky-800`,title:l.context===`fork`?`Forked from parent context`:`Fresh context`,children:l.context}),r&&(0,R.jsx)(`span`,{className:`shrink-0 rounded bg-red-900/40 px-1 py-0.5 text-[9px] font-medium uppercase tracking-wider text-red-200 light:bg-red-100 light:text-red-800`,children:`error`})]}),l.results.length===1&&l.results[0].sessionFile!==void 0&&(0,R.jsxs)(`button`,{onClick:()=>c(l.results[0].sessionFile),className:`inline-flex min-h-11 shrink-0 items-center gap-1 rounded border border-sky-700/60 px-2 py-1 text-[12px] font-medium text-sky-200 hover:border-sky-500 hover:bg-sky-900/30 hover:text-sky-100 light:border-sky-400 light:text-sky-800 light:hover:border-sky-600 light:hover:bg-sky-100 light:hover:text-sky-900 md:min-h-0 md:px-1.5 md:py-0.5 md:text-[10px]`,title:`Open sub-agent session — ${l.results[0].sessionFile}`,children:[(0,R.jsx)(be,{size:12}),`Open`]})]}),d>1&&(0,R.jsx)(`div`,{className:`space-y-1.5 border-t border-sky-900/30 px-2.5 py-2`,children:l.results.map((e,t)=>(0,R.jsx)(BA,{result:e,onOpenFile:c},e.sessionFile??`${t}-${e.agent}`))}),t.length>0&&(0,R.jsxs)(`details`,{className:`border-t border-sky-900/30`,children:[(0,R.jsx)(`summary`,{className:`cursor-pointer px-2.5 py-1 text-[11px] text-neutral-500 hover:text-neutral-300`,children:`Input`}),(0,R.jsx)(`pre`,{className:`overflow-auto px-2.5 pb-2 font-mono text-[11px] text-neutral-400`,children:t})]}),n.length>0&&(0,R.jsxs)(`details`,{open:r,className:`border-t border-sky-900/30`,children:[(0,R.jsx)(`summary`,{className:`cursor-pointer px-2.5 py-1 text-[11px] text-neutral-500 hover:text-neutral-300`,children:`Output`}),(0,R.jsx)(`pre`,{className:`overflow-auto px-2.5 pb-2 font-mono text-[11px] text-neutral-300 whitespace-pre-wrap`,children:n})]})]})}function BA({result:e,onOpenFile:t}){let n=e.exitCode!==0;return(0,R.jsxs)(`div`,{className:`flex items-center justify-between gap-2 rounded border ${n?`border-red-700/40 light:border-red-300`:`border-sky-900/40 light:border-sky-300`} bg-neutral-950/60 px-2 py-1.5`,children:[(0,R.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,R.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,R.jsx)(`span`,{className:`font-mono text-[11px] font-medium text-sky-200 light:text-sky-800`,children:e.agent}),n&&(0,R.jsxs)(`span`,{className:`text-[10px] font-medium text-red-400 light:text-red-700`,children:[`exit `,e.exitCode]})]}),e.task.length>0&&(0,R.jsx)(`div`,{className:`mt-0.5 truncate text-[11px] text-neutral-400`,title:e.task,children:e.task})]}),e.sessionFile!==void 0&&(0,R.jsxs)(`button`,{onClick:()=>t(e.sessionFile),className:`inline-flex shrink-0 items-center gap-1 rounded border border-sky-700/60 px-1.5 py-0.5 text-[10px] font-medium text-sky-200 hover:border-sky-500 hover:bg-sky-900/30 hover:text-sky-100 light:border-sky-400 light:text-sky-800 light:hover:border-sky-600 light:hover:bg-sky-100 light:hover:text-sky-900`,title:e.sessionFile,children:[(0,R.jsx)(be,{size:10}),`Open`]})]})}function VA({message:e}){let t=String(e.command??``),n=String(e.output??``),r=typeof e.exitCode==`number`?e.exitCode:void 0,i=e.truncated===!0,a=e.cancelled===!0,o=e.excludeFromContext===!0;return(0,R.jsxs)(`div`,{className:`rounded border border-neutral-800 bg-neutral-950 text-xs`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-3 py-2 text-neutral-400`,children:[(0,R.jsxs)(`div`,{className:`min-w-0 flex-1 truncate`,children:[(0,R.jsx)(`span`,{className:`text-neutral-500`,children:`$ `}),(0,R.jsx)(`span`,{className:`font-mono text-neutral-200`,children:t})]}),(0,R.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[o&&(0,R.jsx)(`span`,{className:`rounded bg-neutral-800 px-1.5 py-0.5 text-[10px] uppercase tracking-wider text-neutral-400`,title:`!! prefix — kept out of LLM context on the next turn`,children:`local-only`}),a&&(0,R.jsx)(`span`,{className:`rounded bg-amber-900/40 px-1.5 py-0.5 text-[10px] uppercase tracking-wider text-amber-300 light:bg-amber-100 light:text-amber-800`,children:`timed out`}),i&&!a&&(0,R.jsx)(`span`,{className:`rounded bg-amber-900/40 px-1.5 py-0.5 text-[10px] uppercase tracking-wider text-amber-300 light:bg-amber-100 light:text-amber-800`,children:`truncated`}),r!==void 0&&(0,R.jsxs)(`span`,{className:`rounded px-1.5 py-0.5 text-[10px] font-mono ${r===0?`bg-emerald-900/30 text-emerald-300 light:bg-emerald-100 light:text-emerald-800`:`bg-red-900/30 text-red-300 light:bg-red-100 light:text-red-800`}`,title:r===0?`exit 0`:`exit ${String(r)}`,children:[`exit `,r]})]})]}),n.length>0&&(0,R.jsx)(`pre`,{className:`max-h-64 overflow-auto px-3 pb-2 font-mono text-[11px] text-neutral-300`,children:n})]})}function HA({getText:e,title:t}){let[n,r]=(0,v.useState)(!1),i=()=>{let t=e();if(t.length===0)return;let n=navigator.clipboard?.writeText?.bind(navigator.clipboard);n===void 0?a(t):n(t).then(()=>{r(!0),window.setTimeout(()=>r(!1),1200)}).catch(()=>a(t))},a=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),r(!0),window.setTimeout(()=>r(!1),1200)}catch{}};return(0,R.jsx)(`button`,{type:`button`,onClick:i,className:`inline-flex min-h-11 min-w-11 items-center justify-center rounded px-1.5 py-0.5 text-neutral-500 hover:bg-neutral-700/40 hover:text-neutral-300 md:min-h-0 md:min-w-0`,title:t,"aria-label":t,children:n?(0,R.jsx)(le,{size:14}):(0,R.jsx)(ve,{size:14})})}function UA(e){let t=[];for(let n of e)n.type===`text`&&typeof n.text==`string`&&t.push(n.text);return t.join(`
|
|
349
349
|
|
|
350
|
-
`)}function
|
|
351
|
-
`):``}function
|
|
352
|
-
`))r.startsWith(`+++`)||r.startsWith(`---`)||(r.startsWith(`+`)?t+=1:r.startsWith(`-`)&&(n+=1));return{adds:t,dels:n}}function
|
|
353
|
-
`)}a=a.trim(),a.length!==0&&a!==n&&(t.push(a),n=a)}return t}var
|
|
350
|
+
`)}function WA({showRaw:e,onToggle:t}){return(0,R.jsx)(`button`,{type:`button`,onClick:()=>t(!e),className:`inline-flex min-h-11 min-w-11 items-center justify-center rounded px-1.5 py-0.5 text-[10px] uppercase tracking-wider text-neutral-500 hover:bg-neutral-700/40 hover:text-neutral-300 md:min-h-0 md:min-w-0`,title:e?`Show rendered markdown`:`Show raw text`,children:e?`rendered`:`raw`})}function GA({text:e}){return(0,R.jsx)(`pre`,{className:`whitespace-pre-wrap break-words font-sans text-sm text-neutral-100 [overflow-wrap:anywhere]`,children:e})}function KA(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function qA({ts:e}){if(typeof e!=`number`||!Number.isFinite(e)||e<=0)return null;let t=new Date(e),n=t.toLocaleTimeString([],{hour:`numeric`,minute:`2-digit`});return(0,R.jsx)(`span`,{className:`text-[10px] tabular-nums text-neutral-500 opacity-0 transition-opacity duration-150 group-hover:opacity-100`,title:t.toLocaleString([],{dateStyle:`medium`,timeStyle:`medium`}),children:n})}function JA(e){return typeof e.content==`string`?e.content:Array.isArray(e.content)?e.content.filter(e=>{let t=e;return t.type===`text`&&typeof t.text==`string`}).map(e=>e.text).join(`
|
|
351
|
+
`):``}function YA(e){let t=e.details,n=e.input;for(let e of[t,n])if(e!==void 0){if(typeof e.path==`string`)return e.path;if(typeof e.filename==`string`)return e.filename;if(typeof e.file==`string`)return e.file;if(typeof e.file_path==`string`)return e.file_path}}function XA(e){let t=0,n=0;for(let r of e.split(`
|
|
352
|
+
`))r.startsWith(`+++`)||r.startsWith(`---`)||(r.startsWith(`+`)?t+=1:r.startsWith(`-`)&&(n+=1));return{adds:t,dels:n}}function ZA(e){let t=e.details,n=e.input;if(typeof t?.command==`string`)return t.command;if(typeof n?.command==`string`)return n.command}var QA=pt((e,t)=>({settingsRequest:void 0,_settingsSeq:0,openSettings:n=>{let r=t()._settingsSeq+1,i={seq:r};n!==void 0&&(i.tab=n),e({_settingsSeq:r,settingsRequest:i})},clearSettingsRequest:()=>{e({settingsRequest:void 0})},chatInsertRequest:void 0,_chatInsertSeq:0,requestChatInsert:n=>{let r=t()._chatInsertSeq+1;e({_chatInsertSeq:r,chatInsertRequest:{text:n,seq:r}})},clearChatInsertRequest:()=>{e({chatInsertRequest:void 0})},promptsRefreshTrigger:0,bumpPromptsRefresh:()=>{e(e=>({promptsRefreshTrigger:e.promptsRefreshTrigger+1}))},todoPanelOpen:(()=>{try{return localStorage.getItem(`pi-forge/todo-panel-open`)===`true`}catch{return!1}})(),setTodoPanelOpen:t=>{try{localStorage.setItem(`pi-forge/todo-panel-open`,t?`true`:`false`)}catch{}e({todoPanelOpen:t})},openProcessesTabSeq:0,openProcessesTab:()=>e(e=>({openProcessesTabSeq:e.openProcessesTabSeq+1})),openEditorPaneSeq:0,openEditorPane:()=>e(e=>({openEditorPaneSeq:e.openEditorPaneSeq+1}))}));function $A({open:e,onClose:t,anchorRef:n,title:r,children:i}){let a=(0,v.useRef)(null);return(0,v.useEffect)(()=>{if(!e)return;let r=e=>{let r=e.target;r instanceof Element&&n.current?.contains(r)!==!0&&a.current?.contains(r)!==!0&&t()},i=e=>{e.key===`Escape`&&t()};return document.addEventListener(`pointerdown`,r),document.addEventListener(`keydown`,i),()=>{document.removeEventListener(`pointerdown`,r),document.removeEventListener(`keydown`,i)}},[e,t,n]),e?(0,R.jsxs)(`div`,{ref:a,role:`dialog`,"aria-label":r,className:`absolute bottom-full right-0 z-30 mb-1 w-72 max-w-[calc(100vw-1rem)] overflow-hidden rounded-md border border-neutral-700 bg-neutral-900 shadow-xl light:border-neutral-300 light:bg-white`,children:[(0,R.jsxs)(`header`,{className:`flex items-center justify-between gap-2 border-b border-neutral-800 px-3 py-2 text-[11px] uppercase tracking-wider text-neutral-400 light:border-neutral-200 light:text-neutral-500`,children:[(0,R.jsx)(`span`,{children:r}),(0,R.jsx)(`button`,{type:`button`,onClick:t,className:`rounded p-0.5 text-neutral-500 hover:bg-neutral-800 hover:text-neutral-200 light:hover:bg-neutral-100 light:hover:text-neutral-700`,"aria-label":`Close`,children:(0,R.jsx)(it,{size:12})})]}),(0,R.jsx)(`div`,{className:`max-h-72 overflow-y-auto`,children:i})]}):null}function ej(e,t){let n=Math.max(0,Math.floor(((t??Date.now())-e)/1e3));return n<60?`${n}s`:n<3600?`${Math.floor(n/60)}m ${n%60}s`:`${Math.floor(n/3600)}h ${Math.floor(n%3600/60)}m`}function tj({status:e}){return(0,R.jsx)(`span`,{className:`rounded px-1 py-0.5 text-[9px] uppercase tracking-wider ${e===`running`?`bg-emerald-900/40 text-emerald-200 light:bg-emerald-100 light:text-emerald-800`:e===`terminating`||e===`terminate_timeout`?`bg-amber-900/40 text-amber-200 light:bg-amber-100 light:text-amber-800`:e===`killed`?`bg-red-900/40 text-red-200 light:bg-red-100 light:text-red-800`:`bg-neutral-800 text-neutral-300 light:bg-neutral-200 light:text-neutral-700`}`,children:e})}function nj({open:e,onClose:t,anchorRef:n,sessionId:r}){let i=Nr(e=>Pr(e,r)),a=i.filter(e=>kr.has(e.status)),o=i.filter(e=>!kr.has(e.status)),[,s]=(0,v.useState)(0);(0,v.useEffect)(()=>{if(!e||a.length===0)return;let t=window.setInterval(()=>s(e=>e+1),1e3);return()=>window.clearInterval(t)},[e,a.length]);let[c,l]=(0,v.useState)(),u=async e=>{if(r!==void 0){l(e);try{await L.killProcess(r,e)}catch{}finally{l(void 0)}}};return(0,R.jsx)($A,{open:e,onClose:t,anchorRef:n,title:`Processes (${a.length} running)`,children:i.length===0?(0,R.jsx)(`p`,{className:`px-3 py-3 text-xs italic text-neutral-500`,children:`No processes.`}):(0,R.jsxs)(`ul`,{className:`divide-y divide-neutral-800 light:divide-neutral-200`,children:[a.map(e=>(0,R.jsx)(rj,{process:e,busy:c===e.id,onKill:()=>void u(e.id)},e.id)),o.length>0&&a.length>0&&(0,R.jsx)(`li`,{className:`bg-neutral-950 px-3 py-1 text-[10px] uppercase tracking-wider text-neutral-500 light:bg-neutral-100`,children:`Finished`}),o.map(e=>(0,R.jsx)(rj,{process:e,busy:!1},e.id))]})})}function rj({process:e,busy:t,onKill:n}){let r=kr.has(e.status);return(0,R.jsxs)(`li`,{className:`flex items-start justify-between gap-2 px-3 py-2 text-xs`,children:[(0,R.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,R.jsx)(`span`,{className:`truncate font-medium text-neutral-200 light:text-neutral-800`,children:e.name}),(0,R.jsx)(tj,{status:e.status})]}),(0,R.jsxs)(`div`,{className:`mt-0.5 flex items-center gap-2 text-[10px] text-neutral-500`,children:[(0,R.jsxs)(`span`,{children:[`pid `,e.pid]}),(0,R.jsx)(`span`,{children:`·`}),(0,R.jsx)(`span`,{children:ej(e.startTime,e.endTime)}),e.exitCode!==null&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`span`,{children:`·`}),(0,R.jsxs)(`span`,{children:[`exit `,e.exitCode]})]})]})]}),r&&n!==void 0&&(0,R.jsx)(`button`,{type:`button`,onClick:n,disabled:t,className:`shrink-0 rounded border border-red-800 px-1.5 py-0.5 text-[10px] text-red-300 hover:bg-red-900/40 disabled:opacity-50 light:border-red-300 light:text-red-700 light:hover:bg-red-50`,title:`Kill this process`,children:t?`…`:`Kill`})]})}function ij({status:e}){return(0,R.jsx)(`span`,{className:`inline-block w-4 text-center ${e===`completed`?`text-emerald-400 light:text-emerald-700`:e===`in_progress`?`text-amber-400 light:text-amber-700`:e===`deleted`?`text-neutral-600 light:text-neutral-400`:`text-neutral-500`}`,children:e===`completed`?`✓`:e===`in_progress`?`◐`:e===`deleted`?`×`:`○`})}function aj({open:e,onClose:t,anchorRef:n,sessionId:r}){let i=Er(e=>Dr(e,r)).tasks.filter(e=>e.status!==`deleted`),a=i.filter(e=>e.status===`completed`).length,o=i.filter(e=>e.status===`in_progress`).length;return(0,R.jsx)($A,{open:e,onClose:t,anchorRef:n,title:i.length===0?`Tasks`:`Tasks · ${a}/${i.length}${o>0?` · ${o} in progress`:``}`,children:i.length===0?(0,R.jsx)(`p`,{className:`px-3 py-3 text-xs italic text-neutral-500`,children:`No tasks.`}):(0,R.jsx)(`ul`,{className:`divide-y divide-neutral-800 light:divide-neutral-200`,children:i.map(e=>(0,R.jsxs)(`li`,{className:`flex items-start gap-2 px-3 py-2 text-xs`,children:[(0,R.jsx)(ij,{status:e.status}),(0,R.jsx)(`span`,{className:`min-w-0 flex-1 ${e.status===`completed`?`text-neutral-500 line-through light:text-neutral-400`:`text-neutral-200 light:text-neutral-800`}`,children:e.subject})]},e.id))})})}function oj(e){let t=/(?:^|\s)@(?:"([^"\n]+)"|([^\s]+?))(?=[?,;:!)\]]?(?:\s|$))/g,n=[],r;for(;(r=t.exec(e))!==null;){let e=r[1]??r[2];e!==void 0&&n.push(e)}return n}function sj(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function cj(e){let t=sj(e);return RegExp(`(^|\\s)@(?:"${t}"|${t})\\s?`,`g`)}var lj=100,uj=`forge.input.history.v1:`;function dj(e){try{let t=localStorage.getItem(uj+e);if(t===null)return[];let n=JSON.parse(t);return Array.isArray(n)?n.filter(e=>typeof e==`string`).slice(0,lj):[]}catch{return[]}}function fj(e,t){let n=t.trim();if(n.length!==0)try{let t=dj(e);if(t[0]===n)return;let r=[n,...t].slice(0,lj);localStorage.setItem(uj+e,JSON.stringify(r))}catch{}}function pj(e){let t=[],n;for(let r=e.length-1;r>=0;r--){let i=e[r];if(i?.role!==`user`)continue;let a=``;if(typeof i.content==`string`)a=i.content;else if(Array.isArray(i.content)){let e=[];for(let t of i.content){let n=t;n.type===`text`&&typeof n.text==`string`&&e.push(n.text)}a=e.join(`
|
|
353
|
+
`)}a=a.trim(),a.length!==0&&a!==n&&(t.push(a),n=a)}return t}var mj=`pi-forge/model/`;function hj(e){if(e===void 0)return[];let t=[];for(let n of e.providers)for(let e of n.models)e.hasAuth&&t.push({value:`${n.provider}:${e.id}`,provider:n.provider,modelId:e.id,name:e.name,haystack:`${n.provider} ${e.name} ${e.id}`.toLowerCase()});return t}function gj(e,t){if(t.length===0)return 0;let n=t.toLowerCase(),r=n.split(/\s+/).filter(e=>e.length>0),i=0;for(let t of r){let n=e.haystack.indexOf(t);if(n===-1)return;i+=n}return e.modelId.toLowerCase().startsWith(n)&&(i-=50),e.name.toLowerCase().startsWith(n)&&(i-=30),e.provider.toLowerCase()===n&&(i-=20),i}var _j=600;function vj({sessionId:e}){let t=Jr(t=>t.streamingBySession[e]??!1),n=ci(e=>e.minimal),r=Jr(t=>t.bannerBySession[e]),i=r!==void 0&&r.startsWith(`Retrying (`),a=Jr(e=>e.sendPrompt),o=Jr(e=>e.sendSteer),s=Jr(e=>e.reloadMessages),c=Jr(e=>e.abortSession),l=Jr(e=>e.error),[u,d]=(0,v.useState)(``),[f,p]=(0,v.useState)(!1),m=Or(Er(t=>Dr(t,e))),h=QA(e=>e.todoPanelOpen),g=QA(e=>e.setTodoPanelOpen),_=Ir(Nr(t=>Pr(t,e))),y=QA(e=>e.openProcessesTab),[b,x]=(0,v.useState)(!1),[S,C]=(0,v.useState)(!1),w=(0,v.useRef)(null),T=(0,v.useRef)(null),E=dr(),D=(0,v.useRef)(null),O=st(),k=`pi-forge:chat-input-height`,ee=()=>({min:60,max:Math.floor(window.innerHeight*.6)}),[A,te]=(0,v.useState)(()=>{if(typeof window>`u`)return;let e=window.localStorage.getItem(k);if(e===null)return;let t=Number.parseInt(e,10);if(!Number.isFinite(t))return;let{min:n,max:r}=ee();return Math.max(n,Math.min(r,t))}),ne=e=>{e.preventDefault();let t=e.currentTarget;t.setPointerCapture(e.pointerId);let n=e.clientY,r=D.current?.getBoundingClientRect().height??60,{min:i,max:a}=ee(),o=e=>{let t=n-e.clientY;te(Math.max(i,Math.min(a,r+t)))},s=e=>{t.removeEventListener(`pointermove`,o),t.removeEventListener(`pointerup`,s),t.removeEventListener(`pointercancel`,s);try{t.releasePointerCapture(e.pointerId)}catch{}let n=D.current?.getBoundingClientRect().height;n!==void 0&&Number.isFinite(n)&&window.localStorage.setItem(k,String(Math.round(n)))};t.addEventListener(`pointermove`,o),t.addEventListener(`pointerup`,s),t.addEventListener(`pointercancel`,s)},re=()=>{te(void 0),window.localStorage.removeItem(k)},[ie,j]=(0,v.useState)(void 0),[ae,M]=(0,v.useState)([]),[ce,le]=(0,v.useState)(0),ue=(0,v.useRef)(0),de=QA(e=>e.openSettings),fe=QA(e=>e.chatInsertRequest),pe=QA(e=>e.clearChatInsertRequest),me=QA(e=>e.promptsRefreshTrigger),he=(0,v.useRef)(0),[ge,_e]=(0,v.useState)(0),ve=u.startsWith(`/`)&&!u.includes(`
|
|
354
354
|
`),ye=ve?u.slice(1).split(/\s/)[0]??``:``,[be,xe]=(0,v.useState)([]);(0,v.useEffect)(()=>{if(E===void 0){xe([]);return}let e=!1;return L.listPrompts(E.id).then(t=>{e||xe(t.prompts.filter(e=>e.effective).map(e=>{let t={name:e.name,description:e.description};return e.argumentHint!==void 0&&(t.argumentHint=e.argumentHint),t}))}).catch(()=>{e||xe([])}),()=>{e=!0}},[E?.id,me]);let Se=qk(e=>e.pendingInsert),Ce=qk(e=>e.consumePendingInsert);(0,v.useEffect)(()=>{Se!==void 0&&Se.sessionId===e&&(d(e=>e.length===0?Se.text:e+(e.endsWith(`
|
|
355
355
|
`)?``:`
|
|
356
356
|
|
|
357
|
-
`)+Se.text),Ce(),setTimeout(()=>{let e=D.current;e!==null&&(e.focus(),e.setSelectionRange(e.value.length,e.value.length))},0))},[Se,e,Ce]);let we=(()=>{if(!t&&!n){if(u.startsWith(`!!`))return`local`;if(u.startsWith(`!`))return`context`}})(),Te=(0,v.useMemo)(()=>{let r=[{name:`/compact`,description:`Manually compact the session context`,available:!t,run:async()=>{try{await L.compact(e),s(e)}catch(e){Ke(`Compact failed: ${e instanceof N?e.code:e.message}`)}}},{name:`/clear`,description:`Compact context (alias for /compact)`,available:!t,run:async()=>{try{await L.compact(e),s(e)}catch(e){Ke(`Clear failed: ${e instanceof N?e.code:e.message}`)}}},{name:`/abort`,description:`Stop the agent (alias for the Abort button)`,available:t,run:()=>c(e)},{name:`/settings`,description:`Open the Settings panel`,available:!0,run:()=>de()},{name:`/skills`,description:`Open Settings → Skills`,available:!0,run:()=>de(`skills`)},{name:`/mcp`,description:`Open Settings → MCP`,available:!0,run:()=>de(`mcp`)},{name:`/providers`,description:`Open Settings → Providers`,available:!0,run:()=>de(`providers`)},{name:`/help`,description:n?"Show what `/` and `@` do in the input":"Show what `/`, `!`, `@` do in the input",available:!0,run:()=>{Ke(n?`/<cmd> runs a pi-forge command (compact, abort, settings, …). @<path> references a project file (autocomplete from the popover).`:`/<cmd> runs a pi-forge command (compact, abort, settings, …). !cmd runs bash (output → next LLM context); !!cmd runs bash local-only. @<path> references a project file (autocomplete from the popover).`)}}];for(let e of be){let n=e.argumentHint===void 0?e.description:`${e.description} — args: ${e.argumentHint}`;r.push({name:`/${e.name}`,description:n,available:!t,run:()=>{let t=`/${e.name} `;d(t),requestAnimationFrame(()=>{let e=D.current;e!==null&&(e.focus(),e.setSelectionRange(t.length,t.length))})}})}return r},[t,e,c,s,de,n,be]),Ee=(0,v.useMemo)(()=>{let e=ye.toLowerCase();return e.length===0?Te:Te.filter(t=>t.name.slice(1).toLowerCase().startsWith(e))},[Te,ye]),De=(0,v.useMemo)(()=>{if(!ve)return!1;let e=u.slice(1).split(/\s/)[0]??``;return e.length===0||!be.some(t=>t.name===e)?!1:u===`/${e}`||u.startsWith(`/${e} `)},[ve,u,be]),Oe=e=>{let t=Ee[e??ge];t===void 0||!t.available||(d(``),_e(0),t.run())},ke=(0,v.useRef)(0),[je,Ne]=(0,v.useState)([]),Pe=(0,v.useRef)(new Map),Fe=(0,v.useRef)(null),Ie=(0,v.useRef)(null),[Le,Re]=(0,v.useState)(!1),ze=(0,v.useRef)(null),[Ve,He]=(0,v.useState)(void 0),Ue=new Set(`doc.xls.ppt.pptx.vsd.vsdx.odt.ods.odp.rtf.zip.tar.gz.bz2.xz.7z.rar.exe.dll.so.dylib.bin.o.a.class.jar.wasm.mp3.mp4.m4a.wav.flac.ogg.avi.mov.wmv.mkv.heic.heif.tiff.tif.bmp.ico.psd.ttf.otf.woff.woff2.eot.sqlite.db.iso.dmg`.split(`.`)),[Ge,Ke]=(0,v.useState)(void 0),qe=e=>{Ke(void 0);let t=je,n=[...t],r=t.filter(e=>e.type.startsWith(`image/`)).length;for(let t of e){if(n.length>=8){Ke(`Up to 8 attachments per message; "${t.name}" dropped.`);continue}if(t.size>20971520){Ke(`"${t.name}" exceeds the 20 MB per-file limit.`);continue}if(t.type.startsWith(`image/`)&&r>=4){Ke(`Up to 4 images per message; "${t.name}" dropped.`);continue}let e=t.name.includes(`.`)?t.name.split(`.`).pop()?.toLowerCase():void 0;if(e!==void 0&&Ue.has(e)){Ke(`"${t.name}" is a binary format that the agent can't read directly. Convert to text/markdown (or to a PNG/JPEG screenshot for diagrams) and try again.`);continue}n.push(t),t.type.startsWith(`image/`)&&(r+=1,Pe.current.set(t,URL.createObjectURL(t)))}Ne(n)},Je=e=>{let t=Pe.current.get(e);t!==void 0&&(URL.revokeObjectURL(t),Pe.current.delete(e)),Ne(t=>t.filter(t=>t!==e))},Ye=()=>{for(let e of Pe.current.values())URL.revokeObjectURL(e);Pe.current.clear(),Ne([]),Ke(void 0)};(0,v.useEffect)(()=>{let e=Pe.current;return()=>{for(let t of e.values())URL.revokeObjectURL(t);e.clear()}},[]);let Xe=Jr(t=>t.messagesBySession[e]??zr),[Ze,Qe]=(0,v.useState)(0),$e=(0,v.useMemo)(()=>{let t=sj(e),n=lj(Xe),r=new Set,i=[];for(let e of[...t,...n])r.has(e)||(r.add(e),i.push(e));return i},[Xe,e,Ze]),[et,tt]=(0,v.useState)(void 0),nt=(0,v.useRef)(``);(0,v.useEffect)(()=>{tt(void 0),nt.current=``},[e]),(0,v.useEffect)(()=>{ke.current=0},[e]);let rt=uj+e,[at,ot]=(0,v.useState)(void 0),[ct,lt]=(0,v.useState)(void 0),[ut,dt]=(0,v.useState)(()=>localStorage.getItem(uj+e)??``),[ft,pt]=(0,v.useState)(void 0),[mt,ht]=(0,v.useState)(void 0),[gt,_t]=(0,v.useState)(void 0),[vt,yt]=(0,v.useState)(void 0);(0,v.useEffect)(()=>{L.getProviders().then(ot).catch(e=>{pt(`models unavailable (${e instanceof N?e.code:e.message})`)}),L.getSettings().then(e=>{lt({provider:typeof e.defaultProvider==`string`?e.defaultProvider:``,modelId:typeof e.defaultModel==`string`?e.defaultModel:``})}).catch(()=>{})},[]),(0,v.useEffect)(()=>{let t=localStorage.getItem(uj+e)??``;dt(t),pt(void 0),_t(void 0),ht(void 0),yt(void 0);{let t=e;L.getSession(t).then(n=>{t===e&&(ht(n.thinkingLevel),n.modelProvider!==void 0&&n.modelId!==void 0&&yt({provider:n.modelProvider,modelId:n.modelId}))}).catch(()=>{})}if(t===``)return;let[n,...r]=t.split(`:`),i=r.join(`:`);if(n===void 0||i.length===0)return;let a=e;L.setModel(a,n,i).catch(t=>{a===e&&pt(`set model failed: ${t instanceof N?t.code:t.message}`)})},[e]);let bt=Jr(t=>t.pendingDraftBySession[e]),xt=Jr(e=>e.consumePendingDraft);(0,v.useEffect)(()=>{bt!==void 0&&(d(bt),xt(e))},[bt,e,xt]),(0,v.useEffect)(()=>{if(fe===void 0||fe.seq<=he.current)return;he.current=fe.seq;let e=fe.text;d(t=>t.length===0?e:`${t}${/\s$/.test(t)?``:` `}${e}`),requestAnimationFrame(()=>{let e=D.current;if(e===null)return;e.focus();let t=e.value.length;e.setSelectionRange(t,t)}),pe()},[fe,pe]);let St=async t=>{if(dt(t),t===``){localStorage.removeItem(rt);return}let[n,...r]=t.split(`:`),i=r.join(`:`);if(!(n===void 0||i.length===0))try{await L.setModel(e,n,i),localStorage.setItem(rt,t),pt(void 0);let r=e;L.getSession(r).then(t=>{r===e&&(ht(t.thinkingLevel),t.modelProvider!==void 0&&t.modelId!==void 0&&yt({provider:t.modelProvider,modelId:t.modelId}))}).catch(()=>{})}catch(e){pt(`set model failed: ${e instanceof N?e.code:e.message}`)}},Ct=(0,v.useMemo)(()=>{if(at===void 0)return;let e,t;if(ut.length>0){let[n,...r]=ut.split(`:`);if(n===void 0)return;e=n,t=r.join(`:`)}else if(vt!==void 0)e=vt.provider,t=vt.modelId;else return;return at.providers.find(t=>t.provider===e)?.models.find(e=>e.id===t)},[at,ut,vt]),wt=async t=>{ht(t);try{ht((await L.setThinkingLevel(e,t)).level),_t(void 0)}catch(e){_t(`set thinking level failed: ${e instanceof N?e.code:e.message}`)}},Tt=async()=>{let r=u.trim();if(!(r.length===0&&je.length===0||f)){if(r.length>0&&(cj(e,r),Qe(e=>e+1)),ve&&!De){Ee.length>0?Oe():Ke(`Unknown command "${u.split(/\s/)[0]??u}". Type /help to see commands.`);return}p(!0);try{if(!t&&/^!!?[^!]/.test(r)){if(n){Ke(`Bash exec is disabled in this deployment.`);return}let t=r.startsWith(`!!`),i=r.slice(t?2:1).trim();if(i.length===0){Ke("Empty bash command. Type something after the `!`.");return}je.length>0&&(Ye(),Ke("Attachments aren't sent with `!` exec. Cleared.")),await L.exec(e,i,{excludeFromContext:t}),s(e),d(``),tt(void 0),nt.current=``;return}t?(je.length>0&&(Ye(),Ke(`Attachments aren't sent on steer (mid-turn). Cleared.`)),await o(e,r)):await a(e,r,je.length>0?je:void 0),d(``),Ye(),tt(void 0),nt.current=``,O&&D.current?.blur()}catch(e){Ke(`Command failed: ${e instanceof N?e.code:e.message}`)}finally{p(!1)}}},Et=n=>{if(ve){if(n.key===`Escape`){n.preventDefault(),d(``);return}if(Ee.length>0){if(n.key===`ArrowDown`){n.preventDefault(),_e(e=>Math.min(e+1,Ee.length-1));return}if(n.key===`ArrowUp`){n.preventDefault(),_e(e=>Math.max(e-1,0));return}if((n.key===`Enter`||n.key===`Tab`)&&!(De&&n.key===`Enter`&&!n.shiftKey)){n.preventDefault(),Oe();return}}else if(n.key===`Enter`&&!n.shiftKey){n.preventDefault(),Ke(`Unknown command "${u.split(/\s/)[0]??u}". Type /help to see commands, or backspace the leading / to send as a prompt.`);return}}if(ie!==void 0&&ae.length>0){if(n.key===`ArrowDown`){n.preventDefault(),le(e=>Math.min(e+1,ae.length-1));return}if(n.key===`ArrowUp`){n.preventDefault(),le(e=>Math.max(e-1,0));return}if(n.key===`Enter`||n.key===`Tab`){let e=ae[ce];if(e!==void 0){n.preventDefault(),kt(e);return}}if(n.key===`Escape`){n.preventDefault(),At();return}}if(n.key===`Enter`&&!n.shiftKey&&!O){n.preventDefault(),Tt();return}if(n.key===`ArrowUp`){let e=et!==void 0;if(e||u.length===0){if($e.length===0)return;n.preventDefault();let t=e?Math.min((et??0)+1,$e.length-1):0;e||(nt.current=u),tt(t);let r=$e[t];r!==void 0&&d(r)}return}if(n.key===`ArrowDown`){if(et===void 0)return;if(n.preventDefault(),et>0){let e=et-1;tt(e);let t=$e[e];t!==void 0&&d(t)}else tt(void 0),d(nt.current),nt.current=``;return}if(n.key===`Escape`){if(!t)return;n.preventDefault();let r=Date.now(),i=r-ke.current;ke.current=r,i<pj&&(ke.current=0,c(e))}},Dt=e=>{d(e),et!==void 0&&(tt(void 0),nt.current=``);let t=Ot(e,D.current?.selectionStart??e.length);j(t),t===void 0&&M([]),le(0)};function Ot(e,t){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,v.useEffect)(()=>{if(ie===void 0||E===void 0)return;let e=ue.current+1;ue.current=e;let t=window.setTimeout(()=>{L.completeFiles(E.id,ie.query,{limit:20}).then(t=>{ue.current===e&&(M(t.paths),le(0))}).catch(()=>{ue.current===e&&M([])})},100);return()=>window.clearTimeout(t)},[ie,E]);let kt=e=>{if(ie===void 0)return;let t=u.slice(0,ie.start),n=u.slice(ie.end),r=`@"${e}"`;d(`${t}${r}${n}`),j(void 0),M([]);let i=t.length+r.length;requestAnimationFrame(()=>{let e=D.current;e!==null&&(e.focus(),e.setSelectionRange(i,i))})},At=()=>{j(void 0),M([])},jt=nj(u),Mt=e=>{let t=ij(e);d(e=>e.replace(t,(e,t)=>t).trimEnd())};return(0,v.useEffect)(()=>{if(!Le)return;let e=e=>{let t=ze.current;t!==null&&(t.contains(e.target)||Re(!1))},t=e=>{e.key===`Escape`&&Re(!1)};return window.addEventListener(`mousedown`,e),window.addEventListener(`touchstart`,e),window.addEventListener(`keydown`,t),()=>{window.removeEventListener(`mousedown`,e),window.removeEventListener(`touchstart`,e),window.removeEventListener(`keydown`,t)}},[Le]),(0,v.useEffect)(()=>{if(!O){Ve!==void 0&&He(void 0);return}let e=D.current;if(e===null)return;let t=e.style.height;e.style.height=`auto`;let n=e.scrollHeight;e.style.height=t;let r=Math.round(window.innerHeight*.3),i=Math.max(44,Math.min(n,r));i!==Ve&&He(i)},[u,O]),(0,R.jsxs)(`div`,{className:`bg-neutral-950`,children:[(0,R.jsx)(`div`,{role:`separator`,"aria-orientation":`horizontal`,"aria-label":`Resize chat input`,onPointerDown:ne,className:`group relative hidden h-px cursor-row-resize bg-neutral-800 hover:bg-neutral-600 active:bg-neutral-500 md:block`,children:(0,R.jsx)(`div`,{className:`absolute inset-x-0 -top-1 h-2`})}),(0,R.jsxs)(`div`,{className:`mx-auto max-w-3xl space-y-2 px-3 pt-2 md:px-6 md:py-3`,style:{paddingBottom:`max(0.5rem, env(safe-area-inset-bottom))`},children:[(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,R.jsx)(hj,{providers:at,defaultModel:ct,value:ut,onChange:e=>void St(e)}),Ct!==void 0&&Ct.supportedThinkingLevels.length>1&&mt!==void 0&&(0,R.jsx)(gj,{value:mt,options:Ct.supportedThinkingLevels,onChange:e=>void wt(e)}),jt.length>0&&(0,R.jsx)(`div`,{className:`flex flex-wrap items-center gap-1`,children:jt.map((e,t)=>(0,R.jsxs)(`span`,{className:`inline-flex max-w-[220px] items-center gap-1 truncate rounded border border-emerald-700/60 bg-emerald-900/20 px-1.5 py-0.5 text-[11px] text-emerald-200`,title:`@${e} — model will use its read tool to load this file when it needs to`,children:[(0,R.jsx)(se,{size:11,className:`shrink-0`}),(0,R.jsx)(`span`,{className:`truncate font-mono`,children:e}),(0,R.jsx)(`button`,{type:`button`,onClick:()=>Mt(e),className:`-mr-0.5 ml-0.5 rounded p-0.5 text-emerald-300/70 hover:bg-emerald-900/40 hover:text-emerald-100`,title:`Remove @${e}`,children:(0,R.jsx)(it,{size:10})})]},`ref-${t}-${e}`))}),(ft!==void 0||gt!==void 0||A!==void 0||m.total>0||_>0)&&(0,R.jsxs)(`div`,{className:`ml-auto flex items-center gap-2`,children:[ft!==void 0&&(0,R.jsx)(`span`,{className:`text-[11px] text-red-400`,children:ft}),gt!==void 0&&(0,R.jsx)(`span`,{className:`text-[11px] text-red-400`,children:gt}),!O&&A!==void 0&&(0,R.jsx)(`button`,{type:`button`,onClick:re,className:`rounded p-1 text-neutral-500 hover:bg-neutral-800 hover:text-neutral-200`,title:`Reset chat input height to default`,"aria-label":`Reset chat input height to default`,children:(0,R.jsx)(We,{size:12})}),_>0&&(0,R.jsxs)(`div`,{className:`relative`,children:[(0,R.jsxs)(`button`,{ref:w,type:`button`,onClick:()=>{O?x(e=>!e):y()},className:`flex items-center gap-1 rounded px-1.5 py-1 text-[11px] ${O&&b?`bg-neutral-800 text-neutral-100 light:bg-neutral-200 light:text-neutral-900`:`text-neutral-400 hover:bg-neutral-800 hover:text-neutral-200 light:text-neutral-600 light:hover:bg-neutral-200 light:hover:text-neutral-900`}`,title:O?`${_} background process(es) running — show list`:`${_} background process(es) running — view processes panel`,"aria-label":O?`Show processes list`:`View processes panel`,"aria-expanded":O?b:void 0,children:[(0,R.jsx)(oe,{size:12,className:`text-emerald-400 light:text-emerald-700`}),(0,R.jsx)(`span`,{children:_})]}),O&&(0,R.jsx)(QA,{open:b,onClose:()=>x(!1),anchorRef:w,sessionId:e})]}),m.total>0&&(0,R.jsxs)(`div`,{className:`relative`,children:[(0,R.jsxs)(`button`,{ref:T,type:`button`,onClick:()=>{O?C(e=>!e):g(!h)},className:`flex items-center gap-1 rounded px-1.5 py-1 text-[11px] ${(O?S:h)?`bg-amber-900/40 text-amber-200 light:bg-amber-100 light:text-amber-900`:`text-neutral-400 hover:bg-neutral-800 hover:text-neutral-200 light:text-neutral-600 light:hover:bg-neutral-200 light:hover:text-neutral-900`}`,title:O?`Tasks: ${m.completed}/${m.total} done${m.inProgress>0?`, ${m.inProgress} in progress`:``}`:h?`Hide todo panel`:`Show todo panel (${m.completed}/${m.total} done${m.inProgress>0?`, ${m.inProgress} in progress`:``})`,"aria-label":O?`Show tasks list`:`Toggle todo panel`,"aria-expanded":O?S:void 0,"aria-pressed":O?void 0:h,children:[(0,R.jsx)(Me,{size:12}),(0,R.jsxs)(`span`,{children:[m.completed,`/`,m.total]})]}),O&&(0,R.jsx)(tj,{open:S,onClose:()=>C(!1),anchorRef:T,sessionId:e})]})]})]}),l!==void 0&&(0,R.jsxs)(`p`,{className:`text-xs text-red-400`,children:[`Error: `,l]}),Ge!==void 0&&(0,R.jsx)(`p`,{className:`text-xs text-amber-400`,children:Ge}),je.length>0&&(0,R.jsx)(_j,{attachments:je,previewUrls:Pe.current,onRemove:Je}),(0,R.jsxs)(`div`,{className:`flex items-end gap-2`,children:[(0,R.jsx)(`input`,{ref:Fe,type:`file`,multiple:!0,className:`hidden`,onChange:e=>{e.target.files!==null&&qe(e.target.files),e.target.value=``}}),O&&(0,R.jsx)(`input`,{ref:Ie,type:`file`,accept:`image/*`,multiple:!0,className:`hidden`,onChange:e=>{e.target.files!==null&&qe(e.target.files),e.target.value=``}}),O?(0,R.jsxs)(`div`,{className:`relative`,ref:ze,children:[(0,R.jsx)(`button`,{onClick:()=>Re(e=>!e),disabled:f||t,"aria-label":`Attach`,"aria-expanded":Le,className:`inline-flex min-h-11 min-w-11 items-center justify-center self-stretch rounded-md border border-neutral-700 bg-neutral-900 px-2 text-neutral-300 hover:border-neutral-500 hover:text-neutral-100 disabled:cursor-not-allowed disabled:opacity-50`,title:t?`Attachments aren't sent on steer (mid-turn).`:`Attach a photo or a file`,children:(0,R.jsx)(Be,{size:16})}),Le&&(0,R.jsxs)(`div`,{className:`absolute bottom-full left-0 z-20 mb-1 flex flex-col overflow-hidden rounded-md border border-neutral-700 bg-neutral-900 shadow-lg`,children:[(0,R.jsxs)(`button`,{onClick:()=>{Ie.current?.click(),Re(!1)},className:`flex min-h-11 items-center gap-2 px-3 text-left text-[14px] text-neutral-200 hover:bg-neutral-800`,children:[(0,R.jsx)(Ae,{size:16,className:`shrink-0 text-neutral-400`}),`Photo`]}),(0,R.jsxs)(`button`,{onClick:()=>{Fe.current?.click(),Re(!1)},className:`flex min-h-11 items-center gap-2 border-t border-neutral-800 px-3 text-left text-[14px] text-neutral-200 hover:bg-neutral-800`,children:[(0,R.jsx)(Be,{size:16,className:`shrink-0 text-neutral-400`}),`File`]})]})]}):(0,R.jsx)(`button`,{onClick:()=>Fe.current?.click(),disabled:f||t,"aria-label":`Attach files`,className:`inline-flex items-center justify-center self-stretch rounded-md border border-neutral-700 bg-neutral-900 px-2 text-neutral-300 hover:border-neutral-500 hover:text-neutral-100 disabled:cursor-not-allowed disabled:opacity-50`,title:t?`Attachments aren't sent on steer (mid-turn). Wait for the current run to finish.`:`Attach files (images go into model context; text files are prepended to the prompt)`,children:(0,R.jsx)(Be,{size:14})}),(0,R.jsxs)(`div`,{className:`relative flex-1`,children:[ve&&Ee.length>0&&(0,R.jsxs)(`div`,{className:`absolute bottom-full left-0 right-0 z-10 mb-1 overflow-hidden rounded-md border border-neutral-700 bg-neutral-900 shadow-lg`,children:[(0,R.jsx)(`div`,{className:`max-h-[60vh] overflow-y-auto py-1 md:max-h-64`,children:Ee.map((e,t)=>(0,R.jsx)(`button`,{onMouseDown:n=>{n.preventDefault(),e.available&&(_e(t),Oe(t))},onMouseEnter:()=>_e(t),disabled:!e.available,className:`block w-full px-3 py-2.5 text-left text-[14px] md:py-1 md:text-[12px] ${t===ge&&e.available?`bg-neutral-800 text-neutral-100`:`text-neutral-300 hover:bg-neutral-900/80`} ${e.available?``:`opacity-40`}`,title:e.available?e.description:`${e.description} — unavailable right now`,children:(0,R.jsxs)(`div`,{className:`flex flex-col md:block`,children:[(0,R.jsx)(`span`,{className:`font-mono text-neutral-200`,children:e.name}),(0,R.jsx)(`span`,{className:`text-[12px] text-neutral-500 md:ml-2 md:text-[10px]`,children:e.description})]})},e.name))}),(0,R.jsx)(`div`,{className:`hidden border-t border-neutral-800 px-3 py-1 text-[10px] text-neutral-500 md:block`,children:`↑↓ navigate · Enter/Tab run · Esc cancel`})]}),ie!==void 0&&ae.length>0&&(0,R.jsxs)(`div`,{className:`absolute bottom-full left-0 right-0 z-10 mb-1 overflow-hidden rounded-md border border-neutral-700 bg-neutral-900 shadow-lg`,children:[(0,R.jsx)(`div`,{className:`max-h-[60vh] overflow-y-auto py-1 md:max-h-64`,children:ae.map((e,t)=>(0,R.jsx)(`button`,{onMouseDown:t=>{t.preventDefault(),kt(e)},onMouseEnter:()=>le(t),className:`block w-full truncate px-3 py-2.5 text-left font-mono text-[14px] md:py-1 md:text-[12px] ${t===ce?`bg-neutral-800 text-neutral-100`:`text-neutral-300 hover:bg-neutral-900/80`}`,title:e,children:e},e))}),(0,R.jsx)(`div`,{className:`hidden border-t border-neutral-800 px-3 py-1 text-[10px] text-neutral-500 md:block`,children:`↑↓ navigate · Enter/Tab insert · Esc close`})]}),(0,R.jsx)(`textarea`,{ref:D,value:u,onChange:e=>Dt(e.target.value),onKeyDown:Et,onBlur:()=>{setTimeout(()=>{D.current!==document.activeElement&&At()},0)},placeholder:i?`Auto-retry in progress — your message will be queued and sent after the retry completes…`:t?O?`Steer the agent…`:`Steer the agent (Enter to send, Shift+Enter for newline)…`:O?n?"Ask pi — `/` runs commands, `@path` references files…":"Ask pi — `/` runs commands, `!` runs bash, `@path` references files…":n?"Ask pi (Enter to send, Shift+Enter for newline) — `/` runs commands, `@path` references files…":"Ask pi (Enter to send, Shift+Enter for newline) — `/` runs commands, `!` runs bash, `@path` references files…",title:i?`The agent is auto-retrying after a provider error. New messages are queued and delivered when the retry succeeds.`:void 0,rows:O?2:3,style:O&&Ve!==void 0?{height:`${Ve}px`,maxHeight:`30vh`}:!O&&A!==void 0?{height:`${A}px`}:void 0,className:`block w-full resize-none rounded-md border bg-neutral-900 px-3 py-2 text-sm text-neutral-100 outline-none min-h-11 md:min-h-0 ${we===`local`?`border-amber-500 focus:border-amber-400`:we===`context`?`border-emerald-500 focus:border-emerald-400`:`border-neutral-700 focus:border-neutral-500`}`}),we!==void 0&&(0,R.jsx)(`span`,{className:`pointer-events-none absolute right-2 top-2 select-none rounded px-1.5 py-0.5 font-mono text-[10px] uppercase tracking-wide ${we===`local`?`bg-amber-500/15 text-amber-300`:`bg-emerald-500/15 text-emerald-300`}`,title:we===`local`?`!! — runs bash; output stays local (excluded from LLM context)`:`! — runs bash; output is added to the next turn's LLM context`,children:we===`local`?`bash · local`:`bash · context`})]}),(0,R.jsxs)(`div`,{className:`flex flex-col-reverse gap-1 self-stretch md:flex-row md:items-end md:self-auto`,children:[(0,R.jsx)(`button`,{onClick:()=>void Tt(),disabled:u.trim().length===0&&je.length===0||f,className:`flex-1 rounded-md bg-neutral-100 px-4 text-sm font-medium text-neutral-900 disabled:cursor-not-allowed disabled:opacity-50 md:flex-none md:py-2`,title:t?`Send (Pi queues at the next agent break — steer or follow-up depending on agent state)`:`Send (Enter)`,children:`Send`}),t&&(0,R.jsx)(`button`,{onClick:()=>void c(e),className:`flex-1 rounded-md border border-red-700/60 bg-red-950/30 px-3 text-sm font-medium text-red-300 hover:bg-red-900/40 hover:text-red-100 md:flex-none md:py-2`,title:`Stop the agent (or press Esc twice in the textbox)`,children:`Abort`})]})]}),t&&(0,R.jsx)(`p`,{className:`text-[10px] text-neutral-600`,children:`Send queues at the next agent break — Pi picks steer or follow-up. Abort: stop the agent (or press Esc twice in the textbox).`})]})]})}function hj({providers:e,defaultModel:t,value:n,onChange:r}){let i=(0,v.useMemo)(()=>dj(e),[e]),[a,o]=(0,v.useState)(!1),[s,c]=(0,v.useState)(``),[l,u]=(0,v.useState)(0),d=(0,v.useRef)(null),f=(0,v.useRef)(null),p=(0,v.useRef)(null),m=(0,v.useMemo)(()=>{if(s.trim().length===0)return i;let e=[];for(let t of i){let n=fj(t,s);n!==void 0&&e.push({opt:t,score:n})}return e.sort((e,t)=>e.score-t.score),e.map(e=>e.opt)},[i,s]),h=i.find(e=>e.value===n),g=t!==void 0&&t.provider.length>0&&t.modelId.length>0?`${t.provider} / ${t.modelId}`:``,_=h===void 0?g.length>0?`${g} (default)`:`default model`:`${h.provider} / ${h.name}`;(0,v.useEffect)(()=>{if(!a)return;let e=e=>{d.current!==null&&(d.current.contains(e.target)||o(!1))};return window.addEventListener(`mousedown`,e),()=>window.removeEventListener(`mousedown`,e)},[a]),(0,v.useEffect)(()=>{a&&(c(``),u(0),requestAnimationFrame(()=>f.current?.focus()))},[a]),(0,v.useEffect)(()=>{!a||p.current===null||p.current.querySelector(`[data-idx="${l}"]`)?.scrollIntoView({block:`nearest`})},[a,l]);let y=e=>{if(e===-1)r(``);else{let t=m[e];if(t===void 0)return;r(t.value)}o(!1)};return(0,R.jsxs)(`div`,{ref:d,className:`relative`,children:[(0,R.jsxs)(`button`,{onClick:()=>o(e=>!e),disabled:e===void 0,className:`flex max-w-[260px] items-center gap-1 truncate rounded border border-neutral-700 bg-neutral-900 px-2 py-1 text-left text-[11px] text-neutral-200 disabled:opacity-50`,title:`Override the model for this session (click to search)`,children:[(0,R.jsx)(`span`,{className:`text-neutral-500`,children:`model:`}),(0,R.jsx)(`span`,{className:`truncate`,children:_}),(0,R.jsx)(`span`,{className:`ml-1 text-neutral-500`,children:`▾`})]}),a&&(0,R.jsxs)(`div`,{className:`absolute bottom-full left-0 z-10 mb-1 w-[360px] rounded border border-neutral-700 bg-neutral-950 shadow-xl`,children:[(0,R.jsx)(`input`,{ref:f,value:s,onChange:e=>{c(e.target.value),u(0)},onKeyDown:e=>{e.key===`ArrowDown`?(e.preventDefault(),u(e=>Math.min(e+1,m.length-1))):e.key===`ArrowUp`?(e.preventDefault(),u(e=>Math.max(e-1,-1))):e.key===`Enter`?(e.preventDefault(),y(l)):e.key===`Escape`&&(e.preventDefault(),o(!1))},placeholder:`Search provider or model…`,className:`w-full border-b border-neutral-800 bg-transparent px-3 py-2 text-xs text-neutral-100 outline-none`}),(0,R.jsxs)(`div`,{ref:p,className:`max-h-72 overflow-y-auto py-1`,children:[(0,R.jsxs)(`button`,{"data-idx":-1,onMouseEnter:()=>u(-1),onClick:()=>y(-1),className:`flex w-full items-center justify-between px-3 py-1.5 text-left text-xs ${l===-1?`bg-neutral-800 text-neutral-100`:`text-neutral-400`}`,children:[(0,R.jsxs)(`span`,{className:`flex min-w-0 items-baseline gap-2`,children:[(0,R.jsx)(`span`,{children:`Use agent default`}),g.length>0&&(0,R.jsx)(`span`,{className:`truncate font-mono text-[10px] text-neutral-500`,children:g})]}),n===``&&(0,R.jsx)(`span`,{className:`text-emerald-400`,children:`●`})]}),m.length===0?(0,R.jsx)(`p`,{className:`px-3 py-2 text-xs italic text-neutral-500`,children:`No models match. Add an API key in Settings → Providers.`}):m.map((e,t)=>(0,R.jsxs)(`button`,{"data-idx":t,onMouseEnter:()=>u(t),onClick:()=>y(t),className:`flex w-full items-center justify-between px-3 py-1.5 text-left text-xs ${t===l?`bg-neutral-800 text-neutral-100`:`text-neutral-300`}`,children:[(0,R.jsxs)(`span`,{className:`flex min-w-0 items-baseline gap-2`,children:[(0,R.jsx)(`span`,{className:`text-neutral-500`,children:e.provider}),(0,R.jsx)(`span`,{className:`truncate font-mono`,children:e.name})]}),e.value===n&&(0,R.jsx)(`span`,{className:`text-emerald-400`,children:`●`})]},e.value))]}),(0,R.jsxs)(`div`,{className:`border-t border-neutral-800 px-3 py-1.5 text-[10px] text-neutral-600`,children:[m.length,` of `,i.length,` models — ↑↓ to move, Enter to pick, Esc to close`]})]})]})}function gj({value:e,options:t,onChange:n}){let[r,i]=(0,v.useState)(!1),a=(0,v.useRef)(null);return(0,v.useEffect)(()=>{if(!r)return;let e=e=>{a.current!==null&&(a.current.contains(e.target)||i(!1))};return window.addEventListener(`mousedown`,e),()=>window.removeEventListener(`mousedown`,e)},[r]),(0,R.jsxs)(`div`,{ref:a,className:`relative`,children:[(0,R.jsxs)(`button`,{onClick:()=>i(e=>!e),className:`flex items-center gap-1 rounded border border-neutral-700 bg-neutral-900 px-2 py-1 text-left text-[11px] text-neutral-200`,title:`Override the thinking level for this session`,children:[(0,R.jsx)(`span`,{className:`text-neutral-500`,children:`thinking:`}),(0,R.jsx)(`span`,{className:`truncate`,children:e}),(0,R.jsx)(`span`,{className:`ml-1 text-neutral-500`,children:`▾`})]}),r&&(0,R.jsx)(`div`,{className:`absolute bottom-full left-0 z-10 mb-1 w-[140px] rounded border border-neutral-700 bg-neutral-950 shadow-xl`,children:t.map(t=>(0,R.jsxs)(`button`,{onClick:()=>{n(t),i(!1)},className:`flex w-full items-center justify-between px-3 py-1.5 text-left text-xs ${t===e?`bg-neutral-800 text-neutral-100`:`text-neutral-300`}`,children:[(0,R.jsx)(`span`,{children:t}),t===e&&(0,R.jsx)(`span`,{className:`text-emerald-400`,children:`●`})]},t))})]})}function _j({attachments:e,previewUrls:t,onRemove:n}){return(0,R.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:e.map((e,r)=>{let i=e.type.startsWith(`image/`),a=t.get(e);return(0,R.jsxs)(`div`,{className:`group relative flex items-center gap-1.5 rounded-md border border-neutral-700 bg-neutral-900 pr-1 text-xs text-neutral-200`,children:[i&&a!==void 0?(0,R.jsx)(`img`,{src:a,alt:e.name,className:`h-12 w-12 shrink-0 rounded-l-md object-cover`}):(0,R.jsx)(`span`,{className:`flex h-8 w-8 shrink-0 items-center justify-center rounded-l-md bg-neutral-800 text-neutral-400`,children:i?(0,R.jsx)(Ae,{size:14}):(0,R.jsx)(Be,{size:12})}),(0,R.jsxs)(`span`,{className:`flex flex-col py-1 pl-1`,children:[(0,R.jsx)(`span`,{className:`max-w-[160px] truncate font-mono text-[11px]`,title:e.name,children:e.name}),(0,R.jsx)(`span`,{className:`text-[10px] text-neutral-500`,children:vj(e.size)})]}),(0,R.jsx)(`button`,{onClick:()=>n(e),className:`ml-1 rounded p-1 text-neutral-500 hover:bg-neutral-800 hover:text-red-300`,title:`Remove ${e.name}`,children:(0,R.jsx)(it,{size:16})})]},`${r}-${e.name}`)})})}function vj(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function yj({sessionId:e,alreadyOnChangesTab:t,onOpen:n}){let r=Jr(t=>t.streamingBySession[e]??!1),i=Jr(t=>t.agentEndCountBySession[e]??0),[a,o]=(0,v.useState)(0);return(0,v.useEffect)(()=>{o(0)},[e]),(0,v.useEffect)(()=>{if(r)return;let t=!1;return L.getTurnDiff(e).then(e=>{t||o(e.entries.length)}).catch(e=>{t||(e instanceof N&&e.status===404||typeof console<`u`&&console.warn(`[ChangedFilesBadge] turn-diff fetch failed:`,e),o(0))}),()=>{t=!0}},[e,i,r]),a===0||t?null:(0,R.jsx)(`div`,{className:`border-t border-neutral-800 bg-neutral-950 px-6 py-2`,children:(0,R.jsx)(`div`,{className:`mx-auto max-w-3xl`,children:(0,R.jsxs)(`button`,{onClick:n,className:`flex items-center gap-2 rounded-md border border-neutral-700 bg-neutral-900 px-3 py-1.5 text-xs text-neutral-200 hover:border-neutral-500 hover:bg-neutral-800`,title:`Open the Last turn pane to review what the agent just wrote`,children:[(0,R.jsx)(Se,{size:12}),a===1?`1 file edited`:`${a} files edited`,(0,R.jsx)(`span`,{className:`text-[10px] text-neutral-500`,children:`— review`})]})})})}var bj=3e4,xj=[];function Sj(e){return e instanceof N?e.code:e instanceof Error?e.message:String(e)}var Cj=pt((e,t)=>({settings:void 0,globalServers:{},byProject:{},loading:!1,error:void 0,pollHandle:void 0,startPolling:()=>{if(t().pollHandle!==void 0)return;let n=()=>{typeof document<`u`&&document.hidden||t().refreshSettings()};n(),e({pollHandle:window.setInterval(n,bj)})},stopPolling:()=>{let n=t().pollHandle;n!==void 0&&(window.clearInterval(n),e({pollHandle:void 0}))},refreshSettings:async()=>{try{e({settings:await L.getMcpSettings(),error:void 0})}catch(t){if(!(t instanceof N)||t.status===401)return;e({error:Sj(t)})}},refreshProject:async t=>{if(t===void 0){try{e({globalServers:(await L.listMcpServers()).servers,error:void 0})}catch(t){if(t instanceof N&&t.status===401)return;e({error:Sj(t)})}return}e({loading:!0});try{let n=await L.listMcpServers(t);e(e=>{let r={status:n.status,loadedAt:Date.now()};return n.stdioTrust!==void 0&&(r.stdioTrust=n.stdioTrust),{loading:!1,error:void 0,globalServers:n.servers,byProject:{...e.byProject,[t]:r}}})}catch(t){e({loading:!1,error:Sj(t)})}},setMcpEnabled:async n=>{let r=t().settings;r!==void 0&&e({settings:{...r,enabled:n}});try{e({settings:await L.setMcpEnabled(n),error:void 0})}catch(t){throw r!==void 0&&e({settings:r}),e({error:Sj(t)}),t}},upsertServer:async(n,r)=>{try{await L.upsertMcpServer(n,r),await Promise.all([t().refreshSettings(),...Object.keys(t().byProject).map(e=>t().refreshProject(e))])}catch(t){throw e({error:Sj(t)}),t}},deleteServer:async n=>{try{await L.deleteMcpServer(n),await Promise.all([t().refreshSettings(),...Object.keys(t().byProject).map(e=>t().refreshProject(e))])}catch(t){throw e({error:Sj(t)}),t}},probeServer:async(n,r)=>{try{await L.probeMcpServer(n,r),await Promise.all([t().refreshSettings(),t().refreshProject(r)])}catch(t){throw e({error:Sj(t)}),t}},grantStdioTrust:async n=>{try{await L.grantStdioMcpTrust(n),await t().refreshProject(n)}catch(t){throw e({error:Sj(t)}),t}},revokeStdioTrust:async n=>{try{await L.revokeStdioMcpTrust(n),await t().refreshProject(n)}catch(t){throw e({error:Sj(t)}),t}}})),wj={agent_end:`Agent turn finished`,ask_user_question:`Agent asked a question (waiting on user)`,process_alert:`Background process exited`,auto_retry_end:`Auto-retry exhausted (provider failure)`,compaction_end:`Context compaction completed`,session_created:`Session created`,session_deleted:`Session deleted`};function Tj(){return{name:``,url:``,events:new Set,scope:{kind:`global`},secret:``,headersText:``,insecureTls:!1,enabled:!0}}function Ej(e){return{id:e.id,name:e.name,url:e.url,events:new Set(e.events),scope:e.scope,secret:``,headersText:e.headers===void 0?``:Object.entries(e.headers).map(([e,t])=>`${e}: ${t}`).join(`
|
|
358
|
-
`),insecureTls:e.insecureTls===!0,enabled:e.enabled}}function
|
|
359
|
-
`)){let e=n.trim();if(e.length===0)continue;let r=e.indexOf(`:`);if(r===-1)continue;let i=e.slice(0,r).trim(),a=e.slice(r+1).trim();i.length!==0&&(t[i]=a)}return Object.keys(t).length===0?void 0:t}function
|
|
360
|
-
X-Custom: value`,disabled:n,className:`w-full rounded border border-neutral-700 bg-neutral-900 px-2 py-1 font-mono text-xs outline-none focus:border-neutral-500`}),o&&(0,R.jsxs)(`span`,{className:`block text-[11px] text-neutral-500`,children:[`Stored values are masked as `,(0,R.jsx)(`code`,{className:`font-mono`,children:`***REDACTED***`}),` for safety. Leave any line with the sentinel intact to keep the original value; replace it to update; delete the line to remove the header.`]})]}),(0,R.jsxs)(`label`,{className:`flex items-start gap-2 rounded border border-amber-900/40 bg-amber-950/30 px-2 py-1.5 text-xs light:border-amber-300 light:bg-amber-50`,children:[(0,R.jsx)(`input`,{type:`checkbox`,checked:e.insecureTls,onChange:e=>s({insecureTls:e.target.checked}),disabled:n,className:`mt-0.5`}),(0,R.jsxs)(`span`,{children:[(0,R.jsx)(`span`,{className:`text-amber-200 light:text-amber-800`,children:`Allow self-signed / invalid TLS certificate`}),(0,R.jsx)(`br`,{}),(0,R.jsx)(`span`,{className:`text-[11px] text-amber-300/70 light:text-amber-700/80`,children:`⚠ Disables MITM protection. Use only for internal hosts with known self-signed certs. Every fire logs to stderr so the relaxed security is visible in operator logs.`})]})]}),(0,R.jsxs)(`label`,{className:`flex items-center gap-2 text-xs`,children:[(0,R.jsx)(`input`,{type:`checkbox`,checked:e.enabled,onChange:e=>s({enabled:e.target.checked}),disabled:n}),(0,R.jsx)(`span`,{children:`Enabled (disable to pause without losing config)`})]}),(0,R.jsxs)(`footer`,{className:`flex justify-end gap-2 pt-1`,children:[(0,R.jsx)(`button`,{type:`button`,onClick:i,disabled:n,className:`rounded border border-neutral-700 px-3 py-1 text-xs text-neutral-300 hover:bg-neutral-800 disabled:opacity-50`,children:`Cancel`}),(0,R.jsx)(`button`,{type:`button`,onClick:a,disabled:n,className:`rounded bg-neutral-100 px-3 py-1 text-xs font-medium text-neutral-900 disabled:opacity-50`,children:n?`Saving…`:o?`Save changes`:`Create webhook`})]})]})}function Aj({webhook:e,projects:t,isPendingDelete:n,isExpanded:r,onArmDelete:i,onCancelDelete:a,onConfirmDelete:o,onEdit:s,onTest:c,onToggleDeliveries:l}){let u=e.scope.kind===`global`?`Global`:`Project: ${t.find(t=>t.id===e.scope.kind&&t.id===e.scope.projectId)?.name??e.scope.projectId}`;return(0,R.jsxs)(`li`,{className:`rounded-md border ${e.enabled?`border-neutral-800`:`border-neutral-800/60 opacity-60`} bg-neutral-900`,children:[(0,R.jsxs)(`div`,{className:`flex items-start gap-2 px-3 py-2`,children:[(0,R.jsx)(`button`,{type:`button`,onClick:l,className:`mt-0.5 text-neutral-500 hover:text-neutral-300`,"aria-label":r?`Hide deliveries`:`Show recent deliveries`,children:r?(0,R.jsx)(ue,{size:14}):(0,R.jsx)(fe,{size:14})}),(0,R.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,R.jsx)(`span`,{className:`truncate text-sm font-medium text-neutral-100`,children:e.name}),(0,R.jsx)(`span`,{className:`rounded px-1.5 py-0.5 text-[10px] uppercase tracking-wider ${e.enabled?`bg-emerald-900/40 text-emerald-300`:`bg-neutral-800 text-neutral-400`}`,children:e.enabled?`enabled`:`disabled`}),(0,R.jsx)(`span`,{className:`rounded bg-neutral-800 px-1.5 py-0.5 text-[10px] uppercase tracking-wider text-neutral-300`,children:u}),e.hasSecret&&(0,R.jsx)(`span`,{className:`rounded bg-sky-900/40 px-1.5 py-0.5 text-[10px] uppercase tracking-wider text-sky-300`,children:`signed`}),e.insecureTls===!0&&(0,R.jsx)(`span`,{className:`rounded bg-amber-900/40 px-1.5 py-0.5 text-[10px] uppercase tracking-wider text-amber-300`,title:`TLS cert validation disabled for this webhook`,children:`insecure TLS`})]}),(0,R.jsx)(`div`,{className:`mt-0.5 truncate font-mono text-[11px] text-neutral-500`,children:e.url}),(0,R.jsx)(`div`,{className:`mt-0.5 font-mono text-[10px] text-neutral-500`,children:e.events.join(` · `)})]}),(0,R.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[(0,R.jsxs)(`button`,{type:`button`,onClick:c,className:`rounded border border-neutral-700 px-2 py-1 text-[11px] text-neutral-300 hover:bg-neutral-800`,title:`Fire a synthetic webhook.test event at this webhook`,children:[(0,R.jsx)(Je,{size:12,className:`mr-1 inline`}),`Test`]}),(0,R.jsx)(`button`,{type:`button`,onClick:s,className:`rounded border border-neutral-700 px-2 py-1 text-[11px] text-neutral-300 hover:bg-neutral-800`,children:`Edit`}),n?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`button`,{type:`button`,onClick:o,className:`rounded bg-red-700 px-2 py-1 text-[11px] font-medium text-red-50`,children:`Confirm`}),(0,R.jsx)(`button`,{type:`button`,onClick:a,className:`rounded border border-neutral-700 px-2 py-1 text-[11px] text-neutral-300 hover:bg-neutral-800`,children:`Cancel`})]}):(0,R.jsx)(`button`,{type:`button`,onClick:i,className:`rounded border border-neutral-700 px-2 py-1 text-[11px] text-red-300 hover:bg-red-900/40`,title:`Delete this webhook`,"aria-label":`Delete this webhook`,children:(0,R.jsx)($e,{size:12})})]})]}),r&&(0,R.jsx)(jj,{webhookId:e.id})]})}function jj({webhookId:e}){let[t,n]=(0,v.useState)([]),[r,i]=(0,v.useState)(!0),[a,o]=(0,v.useState)(),s=(0,v.useCallback)(async()=>{i(!0),o(void 0);try{let{deliveries:t}=await L.listWebhookDeliveries(e);n(t)}catch(e){o(e instanceof N?e.code:e.message)}finally{i(!1)}},[e]);return(0,v.useEffect)(()=>{s();let e=window.setInterval(()=>void s(),3e3);return()=>window.clearInterval(e)},[s]),(0,R.jsxs)(`div`,{className:`border-t border-neutral-800 bg-neutral-950 px-3 py-2`,children:[(0,R.jsxs)(`div`,{className:`mb-1 flex items-center justify-between`,children:[(0,R.jsxs)(`span`,{className:`text-[11px] uppercase tracking-wider text-neutral-500`,children:[`Recent deliveries `,t.length>0&&`(${t.length})`]}),(0,R.jsx)(`button`,{type:`button`,onClick:()=>void s(),className:`rounded border border-neutral-700 px-1.5 py-0.5 text-[10px] text-neutral-300 hover:bg-neutral-800`,children:`Refresh`})]}),r&&(0,R.jsx)(`p`,{className:`text-xs text-neutral-500`,children:`Loading…`}),a!==void 0&&(0,R.jsx)(`p`,{className:`text-xs text-red-400`,children:a}),!r&&a===void 0&&t.length===0&&(0,R.jsx)(`p`,{className:`text-xs italic text-neutral-500`,children:`No deliveries yet.`}),t.length>0&&(0,R.jsx)(`ul`,{className:`space-y-1`,children:t.map(e=>(0,R.jsxs)(`li`,{className:`grid grid-cols-12 items-baseline gap-2 rounded bg-neutral-900 px-2 py-1 font-mono text-[10px]`,children:[(0,R.jsxs)(`span`,{className:`col-span-2 ${e.status===`delivered`?`text-emerald-400`:e.status===`failed`?`text-red-400`:`text-amber-400`}`,children:[e.status,e.statusCode===void 0?``:` ${e.statusCode}`]}),(0,R.jsx)(`span`,{className:`col-span-2 text-neutral-400`,children:e.event}),(0,R.jsxs)(`span`,{className:`col-span-1 text-neutral-500`,children:[`a`,e.attempt]}),(0,R.jsxs)(`span`,{className:`col-span-2 text-neutral-500`,children:[e.durationMs,`ms`]}),(0,R.jsx)(`span`,{className:`col-span-5 truncate text-neutral-500`,title:e.errorPreview??``,children:e.errorPreview??new Date(e.requestedAt).toLocaleString()})]},e.id))})]})}function Mj({onClose:e,initialTab:t}){let n=ci(e=>e.minimal),r=(0,v.useMemo)(()=>n?[`skills`,`prompts`,`systemPrompt`,`tools`,`quickActions`,`appearance`,`backup`,`general`]:[`providers`,`agent`,`mcp`,`tools`,`skills`,`prompts`,`systemPrompt`,`quickActions`,`webhooks`,`appearance`,`backup`,`general`],[n]),[i,a]=(0,v.useState)(t??(n?`skills`:`providers`));(0,v.useEffect)(()=>{r.includes(i)||a(r[0])},[r,i]),(0,v.useEffect)(()=>{t!==void 0&&r.includes(t)&&a(t)},[t,r]);let[o,s]=(0,v.useState)(void 0);return(0,R.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 px-4 py-8`,onClick:e,children:(0,R.jsxs)(`div`,{onClick:e=>e.stopPropagation(),className:`flex h-full max-h-[720px] w-full max-w-6xl flex-col overflow-hidden rounded-lg border border-neutral-800 bg-neutral-950 shadow-2xl`,children:[(0,R.jsxs)(`header`,{className:`flex items-center gap-3 border-b border-neutral-800 px-4 py-3`,children:[(0,R.jsx)(`div`,{className:`-mx-1 min-w-0 flex-1 overflow-x-auto px-1`,children:(0,R.jsx)(`div`,{className:`flex min-w-max items-center gap-1`,children:r.map(e=>(0,R.jsx)(`button`,{onClick:()=>a(e),className:`shrink-0 whitespace-nowrap rounded px-3 py-1 text-xs ${i===e?`bg-neutral-800 text-neutral-100`:`text-neutral-400 hover:bg-neutral-900 hover:text-neutral-200`}`,children:e===`providers`?`Providers`:e===`agent`?`Agent`:e===`mcp`?`MCP`:e===`tools`?`Tools`:e===`skills`?`Skills`:e===`prompts`?`Prompts`:e===`systemPrompt`?`System Prompt`:e===`quickActions`?`Quick Actions`:e===`webhooks`?`Webhooks`:e===`appearance`?`Appearance`:e===`backup`?`Backup`:`General`},e))})}),(0,R.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[(0,R.jsx)(`button`,{onClick:()=>{let e=Vt(),t=e===void 0?`/api/docs`:`/api/docs?token=${encodeURIComponent(e.token)}`;window.open(t,`_blank`,`noopener,noreferrer`)},className:`rounded border border-neutral-700 px-2 py-1 text-xs text-neutral-300 hover:border-neutral-500`,title:`Open the OpenAPI / Swagger UI in a new tab. Carries your auth token automatically.`,children:`API Docs ↗`}),(0,R.jsx)(`button`,{onClick:e,className:`rounded border border-neutral-700 px-2 py-1 text-xs text-neutral-300 hover:border-neutral-500`,title:`Close (Esc)`,children:`Close`})]})]}),o!==void 0&&(0,R.jsx)(`div`,{className:`border-b border-red-700/40 bg-red-900/20 px-4 py-2 text-xs text-red-300`,children:o}),(0,R.jsxs)(`div`,{className:`flex-1 overflow-y-auto px-4 py-3 text-sm text-neutral-200`,children:[i===`providers`&&(0,R.jsx)(Pj,{onError:s}),i===`agent`&&(0,R.jsx)(Ij,{onError:s}),i===`mcp`&&(0,R.jsx)(aM,{onError:s}),i===`tools`&&(0,R.jsx)(Jj,{onError:s}),i===`skills`&&(0,R.jsx)(Uj,{onError:s}),i===`prompts`&&(0,R.jsx)(Wj,{onError:s}),i===`systemPrompt`&&(0,R.jsx)(Xj,{onError:s}),i===`quickActions`&&(0,R.jsx)(Qj,{onError:s}),i===`webhooks`&&(0,R.jsx)(Oj,{onError:s}),i===`appearance`&&(0,R.jsx)($j,{}),i===`backup`&&(0,R.jsx)(tM,{onError:s}),i===`general`&&(0,R.jsx)(fM,{})]})]})})}function Nj(e){return e instanceof N?e.code:e.message}function Pj({onError:e}){let[t,n]=(0,v.useState)(void 0),[r,i]=(0,v.useState)(void 0),[a,o]=(0,v.useState)(void 0),[s,c]=(0,v.useState)(``),[l,u]=(0,v.useState)(!1),d=async()=>{e(void 0);try{let[e,t]=await Promise.all([L.getProviders(),L.getAuthSummary()]);n(e),i(t)}catch(t){e(`Failed to load providers: ${Nj(t)}`)}};(0,v.useEffect)(()=>{d()},[]);let f=async t=>{if(s.trim().length!==0){u(!0);try{await L.setApiKey(t,s.trim()),o(void 0),c(``),await d()}catch(t){e(`Save key failed: ${Nj(t)}`)}finally{u(!1)}}},p=async t=>{if(confirm(`Remove the stored key for "${t}"?`)){u(!0);try{await L.removeApiKey(t),await d()}catch(t){e(`Remove key failed: ${Nj(t)}`)}finally{u(!1)}}};return t===void 0?(0,R.jsx)(`p`,{className:`text-xs italic text-neutral-500`,children:`Loading providers…`}):(0,R.jsxs)(`div`,{className:`space-y-3`,children:[(0,R.jsxs)(`p`,{className:`text-xs text-neutral-500`,children:[`Built-in providers and anything in `,(0,R.jsx)(`code`,{className:`font-mono`,children:`models.json`}),`. Stored API keys are presence-only — actual values are never sent to the browser.`]}),t.providers.length===0&&(0,R.jsx)(`p`,{className:`text-xs italic text-neutral-500`,children:`No providers configured.`}),t.providers.map(e=>{let t=r?.providers[e.provider],n=t?.configured===!0,i=a===e.provider;return(0,R.jsxs)(`div`,{className:`rounded border border-neutral-800 bg-neutral-900/40 p-3`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,R.jsx)(`span`,{className:`font-mono text-sm text-neutral-100`,children:e.provider}),(0,R.jsx)(`span`,{className:`rounded px-1.5 py-0.5 text-[10px] uppercase tracking-wider ${n?`bg-emerald-900/40 text-emerald-300 light:bg-emerald-100 light:text-emerald-800`:`bg-neutral-800 text-neutral-500`}`,children:n?`key set`:`no key`}),t?.source!==void 0&&(0,R.jsxs)(`span`,{className:`text-[10px] text-neutral-500`,children:[`via `,t.source]})]}),(0,R.jsxs)(`div`,{className:`flex items-center gap-1 text-xs`,children:[!i&&(0,R.jsx)(`button`,{onClick:()=>{o(e.provider),c(``)},className:`rounded border border-neutral-700 px-2 py-0.5 text-neutral-300 hover:border-neutral-500`,children:n?`Replace key`:`Add key`}),n&&!i&&(0,R.jsx)(`button`,{onClick:()=>void p(e.provider),disabled:l,className:`rounded border border-red-700/50 px-2 py-0.5 text-red-300 hover:bg-red-900/20 disabled:opacity-50`,children:`Remove`})]})]}),i&&(0,R.jsxs)(`div`,{className:`mt-2 flex items-center gap-2`,children:[(0,R.jsx)(`input`,{type:`password`,value:s,onChange:e=>c(e.target.value),placeholder:`Paste API key`,autoFocus:!0,className:`flex-1 rounded border border-neutral-700 bg-neutral-950 px-2 py-1 text-xs text-neutral-100 outline-none focus:border-neutral-500`}),(0,R.jsx)(`button`,{onClick:()=>void f(e.provider),disabled:l||s.trim().length===0,className:`rounded bg-neutral-100 px-2 py-1 text-xs font-medium text-neutral-900 disabled:opacity-50`,children:`Save`}),(0,R.jsx)(`button`,{onClick:()=>{o(void 0),c(``)},className:`rounded border border-neutral-700 px-2 py-1 text-xs text-neutral-300`,children:`Cancel`})]}),(0,R.jsxs)(`details`,{className:`mt-2`,children:[(0,R.jsxs)(`summary`,{className:`cursor-pointer text-[11px] text-neutral-500 light:text-neutral-600`,children:[e.models.length,` model`,e.models.length===1?``:`s`]}),(0,R.jsx)(`ul`,{className:`mt-1 space-y-0.5 text-[11px]`,children:e.models.map(e=>(0,R.jsxs)(`li`,{className:`flex justify-between font-mono`,children:[(0,R.jsx)(`span`,{className:e.hasAuth?`text-neutral-300`:`text-neutral-600 light:text-neutral-400`,children:e.name}),(0,R.jsxs)(`span`,{className:`text-neutral-600 light:text-neutral-400`,children:[`ctx `,Math.round(e.contextWindow/1e3),`k`]})]},e.id))})]})]},e.provider)}),(0,R.jsx)(Fj,{onError:e})]})}function Fj({onError:e}){let[t,n]=(0,v.useState)(void 0),[r,i]=(0,v.useState)(!1),[a,o]=(0,v.useState)(void 0);zj(a,()=>o(void 0));let s=async()=>{try{let e=await L.getModelsJson();n(JSON.stringify(e,null,2))}catch(t){e(`Load models.json failed: ${Nj(t)}`)}},c=async()=>{if(t===void 0)return;let n;try{n=JSON.parse(t)}catch{e(`models.json: invalid JSON`);return}if(typeof n!=`object`||!n||typeof n.providers!=`object`||n.providers===null){e(`models.json: top-level must be { "providers": { ... } }`);return}i(!0),o(void 0);try{await L.setModelsJson(n),e(void 0),o(Date.now())}catch(t){e(`Save failed: ${Nj(t)}`)}finally{i(!1)}};return(0,R.jsxs)(`details`,{className:`rounded border border-neutral-800 bg-neutral-900/40 p-3`,children:[(0,R.jsx)(`summary`,{className:`cursor-pointer text-xs text-neutral-300`,onClick:()=>{t===void 0&&s()},children:`Custom providers (models.json)`}),(0,R.jsx)(`p`,{className:`mt-1 text-[11px] text-neutral-500`,children:`Raw JSON editor. Add vLLM / LiteLLM / Ollama / OpenAI-compatible endpoints here. The SDK validates on next session creation.`}),t===void 0?(0,R.jsx)(`p`,{className:`mt-2 text-xs italic text-neutral-500`,children:`Loading…`}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`textarea`,{value:t,onChange:e=>n(e.target.value),spellCheck:!1,rows:10,className:`mt-2 w-full rounded border border-neutral-700 bg-neutral-950 px-2 py-1 font-mono text-[11px] text-neutral-100 outline-none focus:border-neutral-500`}),(0,R.jsxs)(`div`,{className:`mt-2 flex items-center justify-end gap-2 text-xs`,children:[a!==void 0&&(0,R.jsx)(`span`,{className:`text-emerald-400 light:text-emerald-700`,"aria-live":`polite`,children:`Saved`}),(0,R.jsx)(`button`,{onClick:()=>void s(),disabled:r,className:`rounded border border-neutral-700 px-2 py-1 text-neutral-300`,children:`Reload`}),(0,R.jsx)(`button`,{onClick:()=>void c(),disabled:r,className:`rounded bg-neutral-100 px-3 py-1 font-medium text-neutral-900 disabled:opacity-50`,children:r?`Saving…`:`Save`})]})]})]})}function Ij({onError:e}){let[t,n]=(0,v.useState)(void 0),[r,i]=(0,v.useState)(!1),[a,o]=(0,v.useState)(`form`),s=async()=>{e(void 0);try{n(await L.getSettings())}catch(t){e(`Failed to load settings: ${Nj(t)}`)}};(0,v.useEffect)(()=>{s()},[]);let c=e=>{if(t===void 0)return``;let n=t[e];return typeof n==`string`?n:``},l=async t=>{i(!0);try{n(await L.updateSettings(t))}catch(t){e(`Save failed: ${Nj(t)}`)}finally{i(!1)}};return t===void 0?(0,R.jsx)(`p`,{className:`text-xs italic text-neutral-500`,children:`Loading settings…`}):a===`json`?(0,R.jsx)(Lj,{initial:t,onSave:async r=>{let a={...r};for(let e of Object.keys(t))e in r||(a[e]=null);i(!0);try{n(await L.updateSettings(a)),e(void 0)}catch(t){throw e(`Save failed: ${Nj(t)}`),t}finally{i(!1)}},onSwitchToForm:()=>o(`form`),busy:r,onError:e}):(0,R.jsxs)(`div`,{className:`space-y-4`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,R.jsx)(`p`,{className:`text-xs text-neutral-500`,children:`Defaults for new sessions. The form covers common keys; switch to JSON to edit anything the SDK accepts.`}),(0,R.jsx)(`button`,{onClick:()=>o(`json`),className:`rounded border border-neutral-700 px-2 py-0.5 text-[11px] text-neutral-300 hover:border-neutral-500`,children:`Edit as JSON`})]}),(0,R.jsx)(Bj,{label:`Default provider`,hint:`e.g. anthropic, openai, google, custom`,children:(0,R.jsx)(Vj,{value:c(`defaultProvider`),onSave:e=>l({defaultProvider:e.length===0?null:e}),disabled:r})}),(0,R.jsx)(Bj,{label:`Default model`,hint:`model id from the chosen provider`,children:(0,R.jsx)(Vj,{value:c(`defaultModel`),onSave:e=>l({defaultModel:e.length===0?null:e}),disabled:r})}),(0,R.jsx)(Bj,{label:`Thinking level`,hint:`off, low, medium, high (provider-dependent)`,children:(0,R.jsx)(Hj,{value:c(`defaultThinkingLevel`),options:[``,`off`,`low`,`medium`,`high`],onSave:e=>l({defaultThinkingLevel:e.length===0?null:e}),disabled:r})})]})}function Lj({initial:e,onSave:t,onSwitchToForm:n,busy:r,onError:i}){let[a,o]=(0,v.useState)(()=>JSON.stringify(e,null,2)),[s,c]=(0,v.useState)(void 0);zj(s,()=>c(void 0));let l=async()=>{let e;try{e=JSON.parse(a)}catch{i(`settings.json: invalid JSON`);return}if(typeof e!=`object`||!e||Array.isArray(e)){i(`settings.json: top-level must be an object`);return}c(void 0);try{await t(e),c(Date.now())}catch{}};return(0,R.jsxs)(`div`,{className:`space-y-2`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,R.jsxs)(`p`,{className:`text-[11px] text-neutral-500`,children:[`Raw `,(0,R.jsx)(`code`,{className:`font-mono`,children:`settings.json`}),`. Keys removed here are deleted on save (mapped to `,(0,R.jsx)(`code`,{className:`font-mono`,children:`null`}),` in the merge patch). The SDK validates on next session creation.`]}),(0,R.jsx)(`button`,{onClick:n,className:`rounded border border-neutral-700 px-2 py-0.5 text-[11px] text-neutral-300 hover:border-neutral-500`,children:`Back to form`})]}),(0,R.jsx)(`textarea`,{value:a,onChange:e=>o(e.target.value),spellCheck:!1,rows:18,className:`w-full rounded border border-neutral-700 bg-neutral-950 px-2 py-1 font-mono text-[11px] text-neutral-100 outline-none focus:border-neutral-500`}),(0,R.jsxs)(`div`,{className:`flex items-center justify-end gap-2 text-xs`,children:[s!==void 0&&(0,R.jsx)(`span`,{className:`text-emerald-400 light:text-emerald-700`,"aria-live":`polite`,children:`Saved`}),(0,R.jsx)(`button`,{onClick:()=>o(JSON.stringify(e,null,2)),disabled:r,className:`rounded border border-neutral-700 px-2 py-1 text-neutral-300`,children:`Reset`}),(0,R.jsx)(`button`,{onClick:()=>void l(),disabled:r,className:`rounded bg-neutral-100 px-3 py-1 font-medium text-neutral-900 disabled:opacity-50`,children:r?`Saving…`:`Save`})]})]})}var Rj=2500;function zj(e,t){(0,v.useEffect)(()=>{if(e===void 0)return;let n=window.setTimeout(t,Rj);return()=>window.clearTimeout(n)},[e,t])}function Bj({label:e,hint:t,children:n}){return(0,R.jsxs)(`div`,{className:`space-y-1`,children:[(0,R.jsx)(`label`,{className:`block text-xs font-medium text-neutral-200`,children:e}),t!==void 0&&(0,R.jsx)(`p`,{className:`text-[11px] text-neutral-500`,children:t}),n]})}function Vj({value:e,onSave:t,disabled:n}){let[r,i]=(0,v.useState)(e);return(0,v.useEffect)(()=>i(e),[e]),(0,R.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,R.jsx)(`input`,{value:r,onChange:e=>i(e.target.value),disabled:n,className:`flex-1 rounded border border-neutral-700 bg-neutral-950 px-2 py-1 text-xs text-neutral-100 outline-none focus:border-neutral-500`}),(0,R.jsx)(`button`,{onClick:()=>void t(r),disabled:n||r===e,className:`rounded bg-neutral-100 px-2 py-1 text-xs font-medium text-neutral-900 disabled:opacity-50`,children:`Save`})]})}function Hj({value:e,options:t,onSave:n,disabled:r}){return(0,R.jsx)(`select`,{value:e,disabled:r,onChange:e=>void n(e.target.value),className:`rounded border border-neutral-700 bg-neutral-950 px-2 py-1 text-xs text-neutral-100`,children:t.map(e=>(0,R.jsx)(`option`,{value:e,children:e.length===0?`(unset)`:e},e))})}function Uj({onError:e}){let t=dr(),n=ur(e=>e.projects),[r,i]=(0,v.useState)(void 0),[a,o]=(0,v.useState)([]),[s,c]=(0,v.useState)({}),[l,u]=(0,v.useState)({}),[d,f]=(0,v.useState)(!1),p=async()=>{if(t!==void 0){e(void 0);try{let[{skills:e,diagnostics:n},r]=await Promise.all([L.listSkills(t.id),L.listSkillOverrides()]);i(e),o(n),c(r.projects)}catch(t){e(`Failed to load skills: ${Nj(t)}`)}}};if((0,v.useEffect)(()=>{p()},[t?.id]),t===void 0)return(0,R.jsx)(`p`,{className:`text-xs italic text-neutral-500`,children:`Pick a project from the header to manage its skills.`});if(r===void 0)return(0,R.jsxs)(`p`,{className:`text-xs italic text-neutral-500`,children:[`Loading skills for `,t.name,`…`]});let m=async(n,r)=>{f(!0);try{let{skills:e}=await L.setSkillEnabled(t.id,n,r,`global`);i(e)}catch(t){e(`Toggle failed: ${Nj(t)}`)}finally{f(!1)}},h=async(t,n,r)=>{f(!0);try{r===void 0?await L.clearSkillProjectOverride(t,n):await L.setSkillEnabled(t,n,r===`enabled`,`project`),await p()}catch(t){e(`Override write failed: ${Nj(t)}`)}finally{f(!1)}},g=(e,t)=>{let n=s[e];if(n!==void 0){if(n.enable.includes(t))return`enabled`;if(n.disable.includes(t))return`disabled`}};return(0,R.jsxs)(`div`,{className:`space-y-2`,children:[(0,R.jsxs)(`p`,{className:`text-xs text-neutral-500`,children:[`Skills discovered in `,(0,R.jsx)(`code`,{className:`font-mono`,children:`~/.pi/agent/skills/`}),` and`,` `,(0,R.jsxs)(`code`,{className:`font-mono`,children:[t.path,`/.pi/skills/`]}),`. The global toggle writes to pi's `,(0,R.jsx)(`code`,{className:`font-mono`,children:`settings.skills`}),`; per-project overrides write to the pi-forge-private file at`,` `,(0,R.jsx)(`code`,{className:`font-mono`,children:"${FORGE_DATA_DIR}/skills-overrides.json"}),`.`]}),(0,R.jsxs)(`div`,{className:`rounded border border-amber-700/40 bg-amber-900/10 px-3 py-2 text-[11px] text-amber-200 light:border-amber-300 light:bg-amber-50 light:text-amber-800`,children:[`Skill changes apply to the `,(0,R.jsx)(`strong`,{children:`next session`}),` you start in the affected project. Live sessions keep the skill set they booted with — start a new session to use a freshly enabled skill.`]}),a.length>0&&(0,R.jsx)(Gj,{diagnostics:a}),r.length===0&&(0,R.jsx)(`p`,{className:`text-xs italic text-neutral-500`,children:`No skills found for this project.`}),r.map(e=>{let r=`${e.source}:${e.name}`,i=l[r]===!0,a=n.map(t=>({project:t,state:g(t.id,e.name)})).filter(e=>e.state!==void 0),o=n.filter(t=>g(t.id,e.name)===void 0);return(0,R.jsxs)(`div`,{className:`rounded border border-neutral-800 bg-neutral-900/40`,children:[(0,R.jsxs)(`div`,{className:`flex items-start gap-3 p-3`,children:[(0,R.jsx)(`span`,{className:`mt-1.5 inline-block h-2.5 w-2.5 rounded-full ${e.effective?`bg-emerald-500`:`bg-neutral-700`}`,title:`Effective for ${t.name}: ${e.effective?`enabled`:`disabled`}`}),(0,R.jsxs)(`div`,{className:`flex-1 space-y-0.5`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,R.jsx)(`span`,{className:`font-mono text-neutral-100`,children:e.name}),(0,R.jsx)(`span`,{className:`rounded bg-neutral-800 px-1.5 py-0.5 text-[10px] uppercase tracking-wider text-neutral-400`,children:e.source}),e.projectOverride!==void 0&&(0,R.jsxs)(`span`,{className:`rounded px-1.5 py-0.5 text-[10px] uppercase tracking-wider ${e.projectOverride===`enabled`?`bg-emerald-900/40 text-emerald-300 light:bg-emerald-100 light:text-emerald-800`:`bg-red-900/40 text-red-300 light:bg-red-100 light:text-red-800`}`,title:`Active project ('${t.name}') has an override`,children:[`Project: `,e.projectOverride]})]}),(0,R.jsx)(`p`,{className:`text-xs text-neutral-400`,children:e.description||`(no description)`}),(0,R.jsx)(`p`,{className:`font-mono text-[10px] text-neutral-600`,children:e.filePath})]}),(0,R.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1 text-xs`,children:[(0,R.jsxs)(`button`,{onClick:()=>void m(e.name,!e.enabled),disabled:d,className:`rounded border px-2 py-0.5 ${e.enabled?`border-emerald-700/50 bg-emerald-900/20 text-emerald-300 light:border-emerald-300 light:bg-emerald-50 light:text-emerald-800`:`border-neutral-700 text-neutral-300 hover:border-neutral-500`}`,title:`Global enable in pi's settings.skills`,children:[`Global: `,e.enabled?`enabled`:`disabled`]}),(0,R.jsx)(`button`,{onClick:()=>u(e=>({...e,[r]:!i})),className:`rounded border border-neutral-700 px-2 py-0.5 text-neutral-300 hover:border-neutral-500`,title:`Show per-project overrides`,children:i?`▾ Overrides`:`▸ Overrides (${a.length})`})]})]}),i&&(0,R.jsxs)(`div`,{className:`border-t border-neutral-800 px-3 py-2`,children:[a.length===0?(0,R.jsx)(`p`,{className:`mb-2 text-[11px] italic text-neutral-500`,children:`No project overrides yet — every project inherits the global state.`}):(0,R.jsx)(`div`,{className:`mb-2 space-y-1`,children:a.map(({project:t,state:n})=>(0,R.jsxs)(`div`,{className:`flex items-center justify-between gap-2 rounded bg-neutral-900/60 px-2 py-1 text-xs`,children:[(0,R.jsx)(`span`,{className:`truncate text-neutral-200`,title:t.path,children:t.name}),(0,R.jsx)(Kj,{value:n,disabled:d,onChange:n=>void h(t.id,e.name,n)})]},t.id))}),o.length>0&&(0,R.jsx)(qj,{projects:o,disabled:d,onAdd:(t,n)=>void h(t,e.name,n)})]})]},r)})]})}function Wj({onError:e}){let t=dr(),n=ur(e=>e.projects),r=JA(e=>e.bumpPromptsRefresh),[i,a]=(0,v.useState)(void 0),[o,s]=(0,v.useState)([]),[c,l]=(0,v.useState)({}),[u,d]=(0,v.useState)({}),[f,p]=(0,v.useState)(!1),m=async()=>{if(t!==void 0){e(void 0);try{let[{prompts:e,diagnostics:n},r]=await Promise.all([L.listPrompts(t.id),L.listPromptOverrides()]);a(e),s(n),l(r.projects)}catch(t){e(`Failed to load prompts: ${Nj(t)}`)}}};if((0,v.useEffect)(()=>{m()},[t?.id]),t===void 0)return(0,R.jsx)(`p`,{className:`text-xs italic text-neutral-500`,children:`Pick a project from the header to manage its prompts.`});if(i===void 0)return(0,R.jsxs)(`p`,{className:`text-xs italic text-neutral-500`,children:[`Loading prompts for `,t.name,`…`]});let h=async(n,i)=>{p(!0);try{let{prompts:e}=await L.setPromptEnabled(t.id,n,i,`global`);a(e),r()}catch(t){e(`Toggle failed: ${Nj(t)}`)}finally{p(!1)}},g=async(t,n,i)=>{p(!0);try{i===void 0?await L.clearPromptProjectOverride(t,n):await L.setPromptEnabled(t,n,i===`enabled`,`project`),await m(),r()}catch(t){e(`Override write failed: ${Nj(t)}`)}finally{p(!1)}},_=(e,t)=>{let n=c[e];if(n!==void 0){if(n.enable.includes(t))return`enabled`;if(n.disable.includes(t))return`disabled`}};return(0,R.jsxs)(`div`,{className:`space-y-2`,children:[(0,R.jsxs)(`p`,{className:`text-xs text-neutral-500`,children:[`Pi prompt templates discovered in `,(0,R.jsx)(`code`,{className:`font-mono`,children:`~/.pi/agent/prompts/`}),` `,`and `,(0,R.jsxs)(`code`,{className:`font-mono`,children:[t.path,`/.pi/prompts/`]}),`. Invoke from the chat input via `,(0,R.jsx)(`code`,{className:`font-mono`,children:`/<name>`}),`; the global toggle writes to pi's `,(0,R.jsx)(`code`,{className:`font-mono`,children:`settings.prompts`}),`; per-project overrides write to `,(0,R.jsx)(`code`,{className:`font-mono`,children:"${FORGE_DATA_DIR}/prompts-overrides.json"}),`.`]}),(0,R.jsxs)(`div`,{className:`rounded border border-amber-700/40 bg-amber-900/10 px-3 py-2 text-[11px] text-amber-200 light:border-amber-300 light:bg-amber-50 light:text-amber-800`,children:[`Prompt changes apply to the `,(0,R.jsx)(`strong`,{children:`next session`}),` you start in the affected project. Live sessions keep the prompt set they booted with — start a new session to use a freshly enabled prompt.`]}),o.length>0&&(0,R.jsx)(Gj,{diagnostics:o}),i.length===0&&(0,R.jsx)(`p`,{className:`text-xs italic text-neutral-500`,children:`No prompts found for this project.`}),i.map(e=>{let r=`${e.source}:${e.name}`,i=u[r]===!0,a=n.map(t=>({project:t,state:_(t.id,e.name)})).filter(e=>e.state!==void 0),o=n.filter(t=>_(t.id,e.name)===void 0);return(0,R.jsxs)(`div`,{className:`rounded border border-neutral-800 bg-neutral-900/40`,children:[(0,R.jsxs)(`div`,{className:`flex items-start gap-3 p-3`,children:[(0,R.jsx)(`span`,{className:`mt-1.5 inline-block h-2.5 w-2.5 rounded-full ${e.effective?`bg-emerald-500`:`bg-neutral-700`}`,title:`Effective for ${t.name}: ${e.effective?`enabled`:`disabled`}`}),(0,R.jsxs)(`div`,{className:`flex-1 space-y-0.5`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,R.jsxs)(`span`,{className:`font-mono text-neutral-100`,children:[`/`,e.name]}),(0,R.jsx)(`span`,{className:`rounded bg-neutral-800 px-1.5 py-0.5 text-[10px] uppercase tracking-wider text-neutral-400`,children:e.source}),e.argumentHint!==void 0&&(0,R.jsx)(`span`,{className:`rounded bg-neutral-800/60 px-1.5 py-0.5 font-mono text-[10px] text-neutral-300`,title:`Argument hint from the prompt's frontmatter`,children:e.argumentHint}),e.projectOverride!==void 0&&(0,R.jsxs)(`span`,{className:`rounded px-1.5 py-0.5 text-[10px] uppercase tracking-wider ${e.projectOverride===`enabled`?`bg-emerald-900/40 text-emerald-300 light:bg-emerald-100 light:text-emerald-800`:`bg-red-900/40 text-red-300 light:bg-red-100 light:text-red-800`}`,title:`Active project ('${t.name}') has an override`,children:[`Project: `,e.projectOverride]})]}),(0,R.jsx)(`p`,{className:`text-xs text-neutral-400`,children:e.description||`(no description)`}),(0,R.jsx)(`p`,{className:`font-mono text-[10px] text-neutral-600`,children:e.filePath})]}),(0,R.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1 text-xs`,children:[(0,R.jsxs)(`button`,{onClick:()=>void h(e.name,!e.enabled),disabled:f,className:`rounded border px-2 py-0.5 ${e.enabled?`border-emerald-700/50 bg-emerald-900/20 text-emerald-300 light:border-emerald-300 light:bg-emerald-50 light:text-emerald-800`:`border-neutral-700 text-neutral-300 hover:border-neutral-500`}`,title:`Global enable in pi's settings.prompts`,children:[`Global: `,e.enabled?`enabled`:`disabled`]}),(0,R.jsx)(`button`,{onClick:()=>d(e=>({...e,[r]:!i})),className:`rounded border border-neutral-700 px-2 py-0.5 text-neutral-300 hover:border-neutral-500`,title:`Show per-project overrides`,children:i?`▾ Overrides`:`▸ Overrides (${a.length})`})]})]}),i&&(0,R.jsxs)(`div`,{className:`border-t border-neutral-800 px-3 py-2`,children:[a.length===0?(0,R.jsx)(`p`,{className:`mb-2 text-[11px] italic text-neutral-500`,children:`No project overrides yet — every project inherits the global state.`}):(0,R.jsx)(`div`,{className:`mb-2 space-y-1`,children:a.map(({project:t,state:n})=>(0,R.jsxs)(`div`,{className:`flex items-center justify-between gap-2 rounded bg-neutral-900/60 px-2 py-1 text-xs`,children:[(0,R.jsx)(`span`,{className:`truncate text-neutral-200`,title:t.path,children:t.name}),(0,R.jsx)(Kj,{value:n,disabled:f,onChange:n=>void g(t.id,e.name,n)})]},t.id))}),o.length>0&&(0,R.jsx)(qj,{projects:o,disabled:f,onAdd:(t,n)=>void g(t,e.name,n)})]})]},r)})]})}function Gj({diagnostics:e}){return(0,R.jsxs)(`div`,{className:`space-y-1 rounded border border-red-700/40 bg-red-900/10 px-3 py-2 text-[11px] text-red-200`,children:[(0,R.jsxs)(`p`,{className:`font-medium`,children:[e.length,` skill `,e.length===1?`file`:`files`,` were not loaded:`]}),(0,R.jsx)(`ul`,{className:`space-y-1.5`,children:e.map((e,t)=>(0,R.jsxs)(`li`,{className:`border-l-2 border-red-700/60 pl-2`,children:[(0,R.jsxs)(`div`,{className:`text-red-100`,children:[(0,R.jsx)(`span`,{className:`rounded bg-red-900/40 px-1 py-0.5 text-[10px] uppercase tracking-wider text-red-300`,children:e.type}),` `,e.message]}),e.collision!==void 0&&(0,R.jsxs)(`div`,{className:`mt-0.5 font-mono text-[10px] text-red-300/80`,children:[(0,R.jsxs)(`div`,{children:[`loser:\xA0\xA0`,(0,R.jsx)(`span`,{className:`text-red-200`,children:e.collision.loserPath})]}),(0,R.jsxs)(`div`,{children:[`winner:\xA0`,(0,R.jsx)(`span`,{className:`text-red-200`,children:e.collision.winnerPath})]}),(0,R.jsxs)(`div`,{className:`mt-1 text-red-300/70`,children:[`Add `,(0,R.jsxs)(`code`,{className:`rounded bg-red-900/40 px-1`,children:[`name: `,`<unique>`]}),` to the loser's frontmatter, or move it to`,` `,(0,R.jsx)(`code`,{className:`rounded bg-red-900/40 px-1`,children:`<unique>/SKILL.md`}),` so the parent dir name disambiguates.`]})]}),e.collision===void 0&&e.path!==void 0&&(0,R.jsx)(`div`,{className:`mt-0.5 font-mono text-[10px] text-red-300/80`,children:e.path})]},t))})]})}function Kj({value:e,disabled:t,onChange:n}){let r=(e,r,i)=>(0,R.jsx)(`button`,{onClick:()=>n(r),disabled:t,className:`rounded px-2 py-0.5 text-[11px] ${i?r===`enabled`?`bg-emerald-900/40 text-emerald-300 light:bg-emerald-100 light:text-emerald-800`:r===`disabled`?`bg-red-900/40 text-red-300 light:bg-red-100 light:text-red-800`:`bg-neutral-800 text-neutral-400`:`text-neutral-500 hover:bg-neutral-800 hover:text-neutral-300`}`,children:e});return(0,R.jsxs)(`div`,{className:`flex shrink-0 items-center gap-0.5 rounded border border-neutral-700 px-0.5`,children:[r(`Inherit`,void 0,e===void 0),r(`Enabled`,`enabled`,e===`enabled`),r(`Disabled`,`disabled`,e===`disabled`)]})}function qj({projects:e,disabled:t,onAdd:n}){let[r,i]=(0,v.useState)(!1),[a,o]=(0,v.useState)(``);return r?(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1 text-[11px]`,children:[(0,R.jsxs)(`select`,{value:a,onChange:e=>o(e.target.value),className:`rounded border border-neutral-700 bg-neutral-950 px-2 py-0.5 text-neutral-100 outline-none focus:border-neutral-500`,children:[(0,R.jsx)(`option`,{value:``,children:`Pick project…`}),e.map(e=>(0,R.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,R.jsx)(`button`,{onClick:()=>{a.length!==0&&(n(a,`enabled`),i(!1),o(``))},disabled:t||a.length===0,className:`rounded bg-emerald-900/40 px-2 py-0.5 text-emerald-300 disabled:opacity-50 light:bg-emerald-100 light:text-emerald-800`,children:`Enable here`}),(0,R.jsx)(`button`,{onClick:()=>{a.length!==0&&(n(a,`disabled`),i(!1),o(``))},disabled:t||a.length===0,className:`rounded bg-red-900/40 px-2 py-0.5 text-red-300 disabled:opacity-50`,children:`Disable here`}),(0,R.jsx)(`button`,{onClick:()=>{i(!1),o(``)},className:`rounded border border-neutral-700 px-2 py-0.5 text-neutral-400 hover:border-neutral-500`,children:`Cancel`})]}):(0,R.jsx)(`button`,{onClick:()=>i(!0),disabled:t,className:`rounded border border-neutral-700 px-2 py-0.5 text-[11px] text-neutral-300 hover:border-neutral-500`,children:`+ Add override for…`})}function Jj({onError:e}){let t=ur(e=>e.projects),[n,r]=(0,v.useState)(void 0),[i,a]=(0,v.useState)({}),[o,s]=(0,v.useState)(!1),c=async()=>{e(void 0);try{let[e,t]=await Promise.all([L.listTools(),L.listToolOverrides()]);r(e),a(t.projects)}catch(t){e(`Failed to load tools: ${Nj(t)}`)}};(0,v.useEffect)(()=>{c()},[]);let l=async(t,n,r)=>{s(!0);try{await L.setToolEnabled(t,n,r,`global`),await c()}catch(t){e(`Toggle failed: ${Nj(t)}`)}finally{s(!1)}},u=async(t,n,r,i)=>{s(!0);try{i===void 0?await L.clearToolProjectOverride(t,r,n):await L.setToolEnabled(t,r,i===`enabled`,`project`,n),await c()}catch(t){e(`Override write failed: ${Nj(t)}`)}finally{s(!1)}};return n===void 0?(0,R.jsx)(`p`,{className:`text-xs italic text-neutral-500`,children:`Loading tools…`}):(0,R.jsxs)(`div`,{className:`space-y-4`,children:[(0,R.jsxs)(`p`,{className:`text-xs text-neutral-500`,children:[`Toggle individual built-in tools the agent can call. The global toggle on the right is the default for every project. Use `,(0,R.jsx)(`strong`,{children:`Overrides`}),` to enable/disable a tool per project — explicit project overrides win over the global default. Changes apply to the next session — already-running sessions keep the tool set they started with. MCP server tools live under their respective server in the `,(0,R.jsx)(`strong`,{children:`MCP`}),` tab.`]}),(0,R.jsxs)(`section`,{children:[(0,R.jsx)(`h3`,{className:`mb-2 text-xs font-semibold uppercase tracking-wider text-neutral-400`,children:`Built-in tools`}),(0,R.jsx)(`div`,{className:`space-y-2`,children:n.builtin.map(e=>(0,R.jsx)(Yj,{family:`builtin`,name:e.name,fqn:e.name,description:e.description,globalEnabled:e.globalEnabled,projects:t,allOverrides:i,busy:o,onToggleGlobal:t=>void l(`builtin`,e.name,t),onSetProjectOverride:(t,n)=>void u(`builtin`,t,e.name,n)},`builtin:${e.name}`))})]}),n.extension.length>0&&(0,R.jsxs)(`section`,{children:[(0,R.jsx)(`h3`,{className:`mb-2 text-xs font-semibold uppercase tracking-wider text-neutral-400`,children:`Extension tools`}),(0,R.jsxs)(`p`,{className:`mb-2 text-[11px] text-neutral-500`,children:[`Tools registered programmatically by pi extensions installed under`,` `,(0,R.jsx)(`code`,{className:`font-mono`,children:`~/.pi/agent/extensions/`}),` or a project's`,` `,(0,R.jsx)(`code`,{className:`font-mono`,children:`.pi/extensions/`}),`. Disabled tools are dropped from the allowlist passed to the next session — the extension itself remains loaded.`]}),(0,R.jsx)(`div`,{className:`space-y-4`,children:n.extension.map(e=>(0,R.jsxs)(`div`,{className:`space-y-2`,children:[(0,R.jsxs)(`div`,{className:`text-[11px] font-semibold text-neutral-300`,children:[`Package: `,(0,R.jsx)(`code`,{className:`font-mono text-neutral-400`,children:e.packageSource})]}),(0,R.jsx)(`div`,{className:`space-y-2`,children:e.tools.map(n=>(0,R.jsx)(Yj,{family:`extension`,name:n.name,fqn:n.name,description:n.description,globalEnabled:n.globalEnabled,projects:t,allOverrides:i,busy:o,onToggleGlobal:e=>void l(`extension`,n.name,e),onSetProjectOverride:(e,t)=>void u(`extension`,e,n.name,t)},`extension:${e.packageSource}:${n.name}`))})]},e.packageSource))})]})]})}function Yj({family:e,name:t,fqn:n,description:r,globalEnabled:i,projects:a,allOverrides:o,busy:s,onToggleGlobal:c,onSetProjectOverride:l}){let[u,d]=(0,v.useState)(!1),f=t=>{let r=o[t];if(r===void 0)return;let i=e===`builtin`?r.builtin:e===`mcp`?r.mcp:r.extension;if(i!==void 0){if(i.enable.includes(n))return`enabled`;if(i.disable.includes(n))return`disabled`}},p=a.map(e=>({project:e,state:f(e.id)})).filter(e=>e.state!==void 0),m=a.filter(e=>f(e.id)===void 0);return(0,R.jsxs)(`div`,{className:`rounded border border-neutral-800 bg-neutral-900/40`,children:[(0,R.jsxs)(`div`,{className:`flex items-start gap-3 p-3`,children:[(0,R.jsx)(`span`,{className:`mt-1.5 inline-block h-2.5 w-2.5 rounded-full ${i?`bg-emerald-500`:`bg-neutral-700`}`,title:`Global default: ${i?`enabled`:`disabled`}`}),(0,R.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-0.5`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,R.jsx)(`span`,{className:`font-mono text-neutral-100`,children:t}),n!==t&&(0,R.jsx)(`span`,{className:`font-mono text-[10px] text-neutral-500`,title:`Bridged tool name pi sees on the wire`,children:n})]}),r.length>0&&(0,R.jsx)(`p`,{className:`line-clamp-2 text-[11px] text-neutral-500`,title:r,children:r})]}),(0,R.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1 text-xs`,children:[(0,R.jsxs)(`button`,{onClick:()=>c(!i),disabled:s,className:`rounded border px-2 py-0.5 disabled:opacity-50 ${i?`border-emerald-700/50 bg-emerald-900/20 text-emerald-300 light:border-emerald-300 light:bg-emerald-50 light:text-emerald-800`:`border-neutral-700 text-neutral-300 hover:border-neutral-500`}`,title:`Global default for every project that doesn't override`,children:[`Global: `,i?`enabled`:`disabled`]}),(0,R.jsx)(`button`,{onClick:()=>d(e=>!e),className:`rounded border border-neutral-700 px-2 py-0.5 text-neutral-300 hover:border-neutral-500`,title:`Show per-project overrides`,children:u?`▾ Overrides`:`▸ Overrides (${p.length})`})]})]}),u&&(0,R.jsxs)(`div`,{className:`border-t border-neutral-800 px-3 py-2`,children:[p.length===0?(0,R.jsx)(`p`,{className:`mb-2 text-[11px] italic text-neutral-500`,children:`No project overrides yet — every project inherits the global state.`}):(0,R.jsx)(`div`,{className:`mb-2 space-y-1`,children:p.map(({project:e,state:t})=>(0,R.jsxs)(`div`,{className:`flex items-center justify-between gap-2 rounded bg-neutral-900/60 px-2 py-1 text-xs`,children:[(0,R.jsx)(`span`,{className:`truncate text-neutral-200`,title:e.path,children:e.name}),(0,R.jsx)(Kj,{value:t,disabled:s,onChange:t=>l(e.id,t)})]},e.id))}),m.length>0&&(0,R.jsx)(qj,{projects:m,disabled:s,onAdd:(e,t)=>l(e,t)}),a.length===0&&(0,R.jsx)(`p`,{className:`text-[11px] italic text-neutral-500`,children:`No projects exist yet. Create a project first to add per-project overrides.`})]})]})}function Xj({onError:e}){let t=dr(),[n,r]=(0,v.useState)(void 0),[i,a]=(0,v.useState)(``),[o,s]=(0,v.useState)(2e4),[c,l]=(0,v.useState)(!1),[u,d]=(0,v.useState)(void 0);if((0,v.useEffect)(()=>{if(t===void 0){r(void 0),a(``);return}let n=!1;return e(void 0),(async()=>{try{let e=await L.getProjectSystemPrompt(t.id);if(n)return;r(e.addendum),a(e.addendum),s(e.maxBytes)}catch(t){if(n)return;e(`Failed to load system prompt: ${Nj(t)}`)}})(),()=>{n=!0}},[t?.id]),t===void 0)return(0,R.jsx)(`p`,{className:`text-xs italic text-neutral-500`,children:`Pick a project from the header to edit its system prompt addendum.`});if(n===void 0)return(0,R.jsxs)(`p`,{className:`text-xs italic text-neutral-500`,children:[`Loading system prompt for `,t.name,`…`]});let f=new Blob([i]).size,p=f>o,m=i!==n,h=async()=>{if(!p){l(!0),d(void 0),e(void 0);try{let e=await L.setProjectSystemPrompt(t.id,i);r(e.addendum),a(e.addendum),s(e.maxBytes),d(`Saved. Applies to the next session you start in this project.`),window.setTimeout(()=>d(void 0),4e3)}catch(t){e(`Save failed: ${Nj(t)}`)}finally{l(!1)}}},g=async()=>{if(confirm(`Clear the system prompt addendum for "${t.name}"?`)){l(!0),d(void 0),e(void 0);try{let e=await L.setProjectSystemPrompt(t.id,``);r(e.addendum),a(e.addendum),s(e.maxBytes),d(`Cleared. Applies to the next session you start in this project.`),window.setTimeout(()=>d(void 0),4e3)}catch(t){e(`Clear failed: ${Nj(t)}`)}finally{l(!1)}}};return(0,R.jsxs)(`div`,{className:`space-y-3`,children:[(0,R.jsxs)(`div`,{className:`space-y-1 text-xs text-neutral-400`,children:[(0,R.jsxs)(`p`,{children:[`Free-form text appended to the agent's base system prompt for sessions in`,` `,(0,R.jsx)(`strong`,{className:`text-neutral-200`,children:t.name}),`. Use this to layer project-specific behavior on top of pi's defaults — coding conventions, domain context, persona, etc.`]}),(0,R.jsxs)(`p`,{className:`text-[11px]`,children:[`Append-only — the base prompt (which defines the tool-calling protocol) is not editable. Changes apply to the `,(0,R.jsx)(`strong`,{children:`next session`}),` you start in this project; running sessions keep the prompt they were built with.`]})]}),(0,R.jsx)(`textarea`,{value:i,onChange:e=>a(e.target.value),disabled:c,rows:14,spellCheck:!1,placeholder:"e.g. This project uses TypeScript strict mode and never uses default exports. Always run `npm run check` before declaring a task complete.",className:`w-full resize-y rounded border border-neutral-800 bg-neutral-900 px-3 py-2 font-mono text-xs leading-relaxed text-neutral-100 placeholder:text-neutral-600 focus:border-neutral-600 focus:outline-none disabled:opacity-50`}),(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 text-[11px]`,children:[(0,R.jsxs)(`span`,{className:p?`text-red-400`:`text-neutral-500`,children:[f.toLocaleString(),` / `,o.toLocaleString(),` bytes`,p&&` — too long, please trim before saving`]}),(0,R.jsxs)(`div`,{className:`flex items-center gap-2`,children:[u!==void 0&&(0,R.jsx)(`span`,{className:`text-green-400`,children:u}),m&&(0,R.jsx)(`button`,{type:`button`,onClick:()=>a(n),disabled:c,className:`rounded border border-neutral-800 px-3 py-1 text-xs text-neutral-300 hover:border-neutral-600 disabled:opacity-50`,children:`Revert`}),n.length>0&&(0,R.jsx)(`button`,{type:`button`,onClick:()=>void g(),disabled:c,className:`rounded border border-neutral-800 px-3 py-1 text-xs text-neutral-300 hover:border-red-500 hover:text-red-300 disabled:opacity-50`,children:`Clear`}),(0,R.jsx)(`button`,{type:`button`,onClick:()=>void h(),disabled:c||p||!m,className:`rounded bg-neutral-100 px-3 py-1 text-xs font-medium text-neutral-900 hover:bg-white disabled:opacity-50`,children:c?`Saving…`:`Save`})]})]})]})}function Zj(e){return{name:``,kind:e,enabled:!0,command:``,timeoutSec:`30`,text:``,mode:`send`}}function Qj({onError:e}){let t=ci(e=>e.minimal),n=li(e=>e.loaded),r=li(e=>e.actions),i=li(e=>e.load),a=li(e=>e.create),o=li(e=>e.update),s=li(e=>e.remove),[c,l]=(0,v.useState)(void 0),[u,d]=(0,v.useState)(void 0),[f,p]=(0,v.useState)(!1);(0,v.useEffect)(()=>{e(void 0),n||i()},[i,n,e]);let m=e=>{let t=typeof e.command==`string`&&e.command.length>0;l({id:e.id,name:e.name,kind:t?`command`:`prompt`,enabled:e.enabled!==!1,command:e.command??``,timeoutSec:String(Math.round((e.timeoutMs??3e4)/1e3)),text:e.text??``,mode:e.mode??`send`})},h=async()=>{if(c===void 0)return;let t=c.name.trim();if(t.length===0){e(`Name is required`);return}let n={name:t,enabled:c.enabled};if(c.kind===`command`){let t=c.command.trim();if(t.length===0){e(`Command is required`);return}n.command=t;let r=Number.parseInt(c.timeoutSec,10);Number.isFinite(r)&&r>0&&(n.timeoutMs=r*1e3)}else{let t=c.text.trim();if(t.length===0){e(`Prompt text is required`);return}n.text=t,n.mode=c.mode}p(!0);try{c.id===void 0?await a(n):await o(c.id,n),l(void 0),e(void 0)}catch(t){e(`Save failed: ${Nj(t)}`)}finally{p(!1)}},g=async t=>{p(!0);try{await s(t),d(void 0),c?.id===t&&l(void 0)}catch(t){e(`Delete failed: ${Nj(t)}`)}finally{p(!1)}};return(0,R.jsxs)(`div`,{className:`space-y-4`,children:[(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`h2`,{className:`text-sm font-semibold text-neutral-100 light:text-neutral-900`,children:`Quick action chips`}),(0,R.jsxs)(`p`,{className:`mt-1 text-xs text-neutral-400 light:text-neutral-600`,children:[`One-click buttons on the chat toolbar. Two kinds:`,` `,(0,R.jsx)(`span`,{className:`text-amber-400 light:text-amber-700`,children:`command`}),` chips run a shell snippet in the active project's folder;`,` `,(0,R.jsx)(`span`,{className:`text-sky-400 light:text-sky-700`,children:`prompt`}),` chips either send a templated prompt to the agent or insert it into the composer so you can tweak it before sending. Chips are stored globally (not per-project) — they're your personal toolbox.`]})]}),t&&(0,R.jsx)(`div`,{className:`rounded border border-amber-700/40 bg-amber-900/20 px-3 py-2 text-xs text-amber-200 light:border-amber-300 light:bg-amber-50 light:text-amber-800`,children:`MINIMAL_UI is enabled. Command chips are listed below but are hidden from the toolbar and the server refuses to run them. Prompt chips are unaffected.`}),(0,R.jsxs)(`div`,{className:`space-y-1`,children:[r.length===0&&n&&(0,R.jsx)(`p`,{className:`text-xs italic text-neutral-500 light:text-neutral-600`,children:`No chips defined yet. Click “New” below to add one.`}),r.map(e=>{let n=typeof e.command==`string`&&e.command.length>0,r=t&&n;return(0,R.jsxs)(`div`,{className:`flex items-center gap-2 rounded border border-neutral-800 bg-neutral-900/40 px-3 py-2 text-xs light:border-neutral-300 light:bg-neutral-50 ${e.enabled===!1?`opacity-60`:``}`,children:[(0,R.jsx)(`span`,{className:`rounded px-1.5 py-0.5 text-[10px] uppercase tracking-wider ${n?`bg-amber-900/40 text-amber-300 light:bg-amber-100 light:text-amber-900`:`bg-sky-900/40 text-sky-300 light:bg-sky-100 light:text-sky-900`}`,children:n?`cmd`:`prompt`}),(0,R.jsx)(`span`,{className:`flex-1 truncate font-medium text-neutral-200 light:text-neutral-900`,children:e.name}),e.enabled===!1&&(0,R.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-neutral-500`,children:`disabled`}),r&&(0,R.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-amber-400 light:text-amber-700`,children:`hidden by MINIMAL_UI`}),(0,R.jsx)(`button`,{onClick:()=>m(e),className:`rounded border border-neutral-700 px-2 py-0.5 text-[11px] text-neutral-300 hover:border-neutral-500 light:border-neutral-400 light:text-neutral-700`,children:`Edit`}),u===e.id?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`button`,{onClick:()=>void g(e.id),disabled:f,className:`rounded border border-red-700 px-2 py-0.5 text-[11px] text-red-300 hover:bg-red-900/40 light:border-red-400 light:text-red-700`,children:`Confirm`}),(0,R.jsx)(`button`,{onClick:()=>d(void 0),className:`rounded border border-neutral-700 px-2 py-0.5 text-[11px] text-neutral-400 hover:border-neutral-500 light:border-neutral-400 light:text-neutral-600`,children:`Cancel`})]}):(0,R.jsx)(`button`,{onClick:()=>d(e.id),className:`rounded border border-neutral-700 px-2 py-0.5 text-[11px] text-neutral-400 hover:border-red-500 hover:text-red-300 light:border-neutral-400 light:text-neutral-600`,children:`Delete`})]},e.id)})]}),c===void 0&&(0,R.jsx)(`button`,{onClick:()=>l(Zj(`prompt`)),className:`rounded border border-neutral-700 px-3 py-1 text-xs text-neutral-200 hover:border-neutral-500 light:border-neutral-400 light:text-neutral-800`,children:`+ New chip`}),c!==void 0&&(0,R.jsxs)(`div`,{className:`space-y-3 rounded border border-neutral-700 bg-neutral-900/60 p-3 light:border-neutral-300 light:bg-white`,children:[(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`label`,{className:`mb-1 block text-[11px] uppercase tracking-wider text-neutral-400 light:text-neutral-600`,children:`Name`}),(0,R.jsx)(`input`,{value:c.name,onChange:e=>l({...c,name:e.target.value}),placeholder:`e.g. Run tests`,className:`w-full rounded border border-neutral-700 bg-neutral-950 px-2 py-1 text-sm text-neutral-100 light:border-neutral-300 light:bg-white light:text-neutral-900`})]}),(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`label`,{className:`mb-1 block text-[11px] uppercase tracking-wider text-neutral-400 light:text-neutral-600`,children:`Kind`}),(0,R.jsxs)(`div`,{className:`flex items-center gap-3 text-xs text-neutral-300 light:text-neutral-800`,children:[(0,R.jsxs)(`label`,{className:`flex items-center gap-1.5`,children:[(0,R.jsx)(`input`,{type:`radio`,checked:c.kind===`prompt`,onChange:()=>l({...c,kind:`prompt`})}),`Prompt`]}),(0,R.jsxs)(`label`,{className:`flex items-center gap-1.5 ${t?`opacity-50`:``}`,title:t?`Command chips are disabled by MINIMAL_UI. The server refuses to run them.`:void 0,children:[(0,R.jsx)(`input`,{type:`radio`,checked:c.kind===`command`,disabled:t,onChange:()=>l({...c,kind:`command`})}),`Command`,t?` (disabled by MINIMAL_UI)`:``]})]})]}),c.kind===`command`?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`label`,{className:`mb-1 block text-[11px] uppercase tracking-wider text-neutral-400 light:text-neutral-600`,children:`Command`}),(0,R.jsx)(`textarea`,{value:c.command,onChange:e=>l({...c,command:e.target.value}),rows:3,placeholder:`npm test`,className:`w-full rounded border border-neutral-700 bg-neutral-950 px-2 py-1 font-mono text-xs text-neutral-100 light:border-neutral-300 light:bg-white light:text-neutral-900`}),(0,R.jsxs)(`p`,{className:`mt-1 text-[11px] text-neutral-500 light:text-neutral-600`,children:[`Runs in the active project's folder via `,(0,R.jsx)(`code`,{children:`/bin/sh -c`}),`. Multi-line is fine (`,(0,R.jsx)(`code`,{children:`&&`}),`, `,(0,R.jsx)(`code`,{children:`;`}),`, etc.). Environment is scrubbed of pi-forge and provider secrets (same as the integrated terminal).`]})]}),(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`label`,{className:`mb-1 block text-[11px] uppercase tracking-wider text-neutral-400 light:text-neutral-600`,children:`Timeout (seconds)`}),(0,R.jsx)(`input`,{value:c.timeoutSec,onChange:e=>l({...c,timeoutSec:e.target.value}),placeholder:`30`,className:`w-24 rounded border border-neutral-700 bg-neutral-950 px-2 py-1 text-sm text-neutral-100 light:border-neutral-300 light:bg-white light:text-neutral-900`}),(0,R.jsx)(`p`,{className:`mt-1 text-[11px] text-neutral-500 light:text-neutral-600`,children:`Max 300 (five minutes). Past that, use the integrated terminal.`})]})]}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`label`,{className:`mb-1 block text-[11px] uppercase tracking-wider text-neutral-400 light:text-neutral-600`,children:`Prompt text`}),(0,R.jsx)(`textarea`,{value:c.text,onChange:e=>l({...c,text:e.target.value}),rows:4,placeholder:`Review the staged changes for security issues.`,className:`w-full rounded border border-neutral-700 bg-neutral-950 px-2 py-1 text-xs text-neutral-100 light:border-neutral-300 light:bg-white light:text-neutral-900`})]}),(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`label`,{className:`mb-1 block text-[11px] uppercase tracking-wider text-neutral-400 light:text-neutral-600`,children:`Mode`}),(0,R.jsxs)(`div`,{className:`flex items-center gap-3 text-xs text-neutral-300 light:text-neutral-800`,children:[(0,R.jsxs)(`label`,{className:`flex items-center gap-1.5`,children:[(0,R.jsx)(`input`,{type:`radio`,checked:c.mode===`send`,onChange:()=>l({...c,mode:`send`})}),`Send immediately`]}),(0,R.jsxs)(`label`,{className:`flex items-center gap-1.5`,children:[(0,R.jsx)(`input`,{type:`radio`,checked:c.mode===`insert`,onChange:()=>l({...c,mode:`insert`})}),`Insert into composer`]})]})]})]}),(0,R.jsx)(`div`,{children:(0,R.jsxs)(`label`,{className:`flex items-center gap-1.5 text-xs text-neutral-300 light:text-neutral-800`,children:[(0,R.jsx)(`input`,{type:`checkbox`,checked:c.enabled,onChange:e=>l({...c,enabled:e.target.checked})}),`Enabled (visible in the menu)`]})}),(0,R.jsxs)(`div`,{className:`flex items-center gap-2 border-t border-neutral-800 pt-3 light:border-neutral-300`,children:[(0,R.jsx)(`button`,{onClick:()=>void h(),disabled:f,className:`rounded bg-emerald-700 px-3 py-1 text-xs text-white hover:bg-emerald-600 disabled:opacity-50`,children:c.id===void 0?`Create`:`Save`}),(0,R.jsx)(`button`,{onClick:()=>l(void 0),className:`rounded border border-neutral-700 px-3 py-1 text-xs text-neutral-300 hover:border-neutral-500 light:border-neutral-400 light:text-neutral-700`,children:`Cancel`})]})]})]})}function $j(){let e=tC(e=>e.theme),t=tC(e=>e.setTheme);return(0,R.jsxs)(`div`,{className:`space-y-4`,children:[(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`h2`,{className:`text-sm font-semibold text-neutral-100`,children:`Theme`}),(0,R.jsx)(`p`,{className:`mt-1 text-xs text-neutral-400`,children:`Sets the color palette for the chrome, editor, and terminal. Persisted in this browser only — open in another browser to use a different theme there.`})]}),(0,R.jsx)(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2`,children:KS.map(n=>(0,R.jsxs)(`button`,{onClick:()=>t(n.id),className:`flex items-center justify-between gap-3 rounded border px-3 py-2 text-left ${n.id===e?`border-neutral-400 bg-neutral-800`:`border-neutral-700 hover:border-neutral-500`}`,children:[(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`div`,{className:`text-sm text-neutral-100`,children:n.label}),(0,R.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-neutral-500`,children:n.mode})]}),(0,R.jsx)(eM,{id:n.id})]},n.id))})]})}function eM({id:e}){return(0,R.jsxs)(`div`,{"data-theme":e,className:`flex h-6 overflow-hidden rounded border border-neutral-700`,children:[(0,R.jsx)(`div`,{className:`w-4 bg-neutral-950`}),(0,R.jsx)(`div`,{className:`w-4 bg-neutral-800`}),(0,R.jsx)(`div`,{className:`w-4 bg-neutral-500`}),(0,R.jsx)(`div`,{className:`w-4 bg-neutral-200`})]})}function tM({onError:e}){let[t,n]=(0,v.useState)(!1),[r,i]=(0,v.useState)(void 0),[a,o]=(0,v.useState)(void 0),s=(0,v.useRef)(null),[c,l]=(0,v.useState)(void 0),[u,d]=(0,v.useState)(void 0),f=(0,v.useRef)(null),p=(0,v.useRef)(null),m=async()=>{e(void 0),n(!0),o(void 0);try{let{blob:e,filename:t,files:n}=await L.exportConfig(),r=URL.createObjectURL(e),a=document.createElement(`a`);a.href=r,a.download=t,document.body.appendChild(a),a.click(),document.body.removeChild(a),requestAnimationFrame(()=>URL.revokeObjectURL(r)),i({filename:t,files:n})}catch(t){e(`Export failed: ${Nj(t)}`)}finally{n(!1)}},h=async t=>{e(void 0),n(!0),i(void 0);try{o(await L.importConfig(t))}catch(t){e(`Import failed: ${Nj(t)}`)}finally{n(!1),s.current&&(s.current.value=``)}},g=(e,t)=>{let n=URL.createObjectURL(e),r=document.createElement(`a`);r.href=n,r.download=t,document.body.appendChild(r),r.click(),document.body.removeChild(r),requestAnimationFrame(()=>URL.revokeObjectURL(n))},_=async()=>{e(void 0),n(!0),d(void 0),l(void 0);try{let{blob:e,filename:t,fileCount:n}=await L.exportSkills();g(e,t),l({filename:t,fileCount:n})}catch(t){t instanceof N&&t.code===`skills_directory_empty`?l({filename:``,fileCount:0}):e(`Skills export failed: ${Nj(t)}`)}finally{n(!1)}},y=async t=>{if(t.length!==0){e(void 0),n(!0),l(void 0);try{d(await L.importSkills(t))}catch(t){e(`Skills import failed: ${Nj(t)}`)}finally{n(!1),f.current&&(f.current.value=``),p.current&&(p.current.value=``)}}};return(0,R.jsxs)(`div`,{className:`space-y-6`,children:[(0,R.jsxs)(`section`,{children:[(0,R.jsx)(`h3`,{className:`mb-2 text-sm font-medium text-neutral-100`,children:`Export config`}),(0,R.jsxs)(`p`,{className:`mb-3 text-xs text-neutral-400`,children:[`Downloads a `,(0,R.jsx)(`code`,{className:`font-mono`,children:`.tar.gz`}),` with`,` `,(0,R.jsx)(`code`,{className:`font-mono`,children:`mcp.json`}),`,`,` `,(0,R.jsx)(`code`,{className:`font-mono`,children:`settings.json`}),`,`,` `,(0,R.jsx)(`code`,{className:`font-mono`,children:`models.json`}),`,`,` `,(0,R.jsx)(`code`,{className:`font-mono`,children:`skills-overrides.json`}),`, and`,` `,(0,R.jsx)(`code`,{className:`font-mono`,children:`tool-overrides.json`}),`. Provider auth (`,(0,R.jsx)(`code`,{className:`font-mono`,children:`auth.json`}),` — API keys, OAuth tokens) is`,` `,(0,R.jsx)(`strong`,{children:`not`}),` included; re-authenticate providers after restoring on a new install.`]}),(0,R.jsx)(`button`,{onClick:()=>void m(),disabled:t,className:`rounded border border-neutral-700 bg-neutral-900 px-3 py-1.5 text-xs text-neutral-100 hover:border-neutral-500 disabled:opacity-50`,children:t?`Exporting…`:`Download config archive`}),r!==void 0&&(0,R.jsxs)(`p`,{className:`mt-2 text-xs text-emerald-400 light:text-emerald-700`,children:[`Exported `,(0,R.jsx)(`code`,{className:`font-mono`,children:r.filename}),` (`,r.files.length===0?`no files were on disk`:`included: ${r.files.join(`, `)}`,`)`]})]}),(0,R.jsxs)(`section`,{children:[(0,R.jsx)(`h3`,{className:`mb-2 text-sm font-medium text-neutral-100`,children:`Import config`}),(0,R.jsxs)(`p`,{className:`mb-3 text-xs text-neutral-400`,children:[`Restores a previously-exported archive. Each file is parsed before any disk write — if any file fails validation, `,(0,R.jsx)(`strong`,{children:`nothing`}),` is imported. Existing live agent sessions keep their original settings until restarted.`]}),(0,R.jsx)(`input`,{ref:s,type:`file`,accept:`.gz,.tgz,application/gzip,application/x-gzip`,disabled:t,onChange:e=>{let t=e.target.files?.[0];t!==void 0&&h(t)},className:`block text-xs text-neutral-300 file:mr-3 file:rounded file:border file:border-neutral-700 file:bg-neutral-900 file:px-3 file:py-1.5 file:text-xs file:text-neutral-100 hover:file:border-neutral-500 disabled:opacity-50`}),a!==void 0&&(0,R.jsxs)(`div`,{className:`mt-3 space-y-1 text-xs`,children:[a.imported.length>0&&(0,R.jsxs)(`p`,{className:`text-emerald-400 light:text-emerald-700`,children:[`Imported: `,(0,R.jsx)(`code`,{className:`font-mono`,children:a.imported.join(`, `)})]}),a.skipped.length>0&&(0,R.jsxs)(`p`,{className:`text-amber-400 light:text-amber-700`,children:[`Skipped (not in allow-list):`,` `,(0,R.jsx)(`code`,{className:`font-mono`,children:a.skipped.join(`, `)})]}),a.errors.length>0&&(0,R.jsxs)(`div`,{className:`text-red-400`,children:[(0,R.jsx)(`p`,{children:`Errors — nothing was written:`}),(0,R.jsx)(`ul`,{className:`ml-4 list-disc`,children:a.errors.map(e=>(0,R.jsxs)(`li`,{children:[(0,R.jsx)(`code`,{className:`font-mono`,children:e.file}),`: `,e.reason]},e.file))})]}),a.imported.length===0&&a.errors.length===0&&a.skipped.length===0&&(0,R.jsx)(`p`,{className:`italic text-neutral-500`,children:`Archive was empty.`})]})]}),(0,R.jsxs)(`section`,{children:[(0,R.jsx)(`h3`,{className:`mb-2 text-sm font-medium text-neutral-100`,children:`Export skills`}),(0,R.jsxs)(`p`,{className:`mb-3 text-xs text-neutral-400`,children:[`Downloads a `,(0,R.jsx)(`code`,{className:`font-mono`,children:`.tar.gz`}),` of every file under`,` `,(0,R.jsx)(`code`,{className:`font-mono`,children:`~/.pi/agent/skills/`}),` — both single-file (`,(0,R.jsx)(`code`,{className:`font-mono`,children:`<name>.md`}),`) and directory skills (`,(0,R.jsx)(`code`,{className:`font-mono`,children:`<name>/SKILL.md`}),` + assets) round-trip verbatim.`]}),(0,R.jsx)(`button`,{onClick:()=>void _(),disabled:t,className:`rounded border border-neutral-700 bg-neutral-900 px-3 py-1.5 text-xs text-neutral-100 hover:border-neutral-500 disabled:opacity-50`,children:t?`Working…`:`Download skills archive`}),c!==void 0&&(c.fileCount===0?(0,R.jsx)(`p`,{className:`mt-2 text-xs text-neutral-400`,children:`No skills to export — your skills directory is empty.`}):(0,R.jsxs)(`p`,{className:`mt-2 text-xs text-emerald-400 light:text-emerald-700`,children:[`Exported `,(0,R.jsx)(`code`,{className:`font-mono`,children:c.filename}),` (`,c.fileCount,` file`,c.fileCount===1?``:`s`,` packed)`]}))]}),(0,R.jsxs)(`section`,{children:[(0,R.jsx)(`h3`,{className:`mb-2 text-sm font-medium text-neutral-100`,children:`Import skills`}),(0,R.jsxs)(`p`,{className:`mb-3 text-xs text-neutral-400`,children:[`Restore skills from a previously-exported `,(0,R.jsx)(`code`,{className:`font-mono`,children:`.tar.gz`}),`, OR upload a folder of skill files directly. Existing files at the same path are`,` `,(0,R.jsx)(`strong`,{children:`overwritten`}),`; new files are added. Path traversal and absolute paths are rejected.`]}),(0,R.jsxs)(`div`,{className:`space-y-3`,children:[(0,R.jsxs)(`label`,{className:`block space-y-1`,children:[(0,R.jsx)(`span`,{className:`text-[11px] uppercase tracking-wider text-neutral-500`,children:`From tar.gz`}),(0,R.jsx)(`input`,{ref:f,type:`file`,accept:`.gz,.tgz,application/gzip,application/x-gzip`,disabled:t,onChange:e=>{let t=e.target.files?.[0];t!==void 0&&y([t])},className:`block text-xs text-neutral-300 file:mr-3 file:rounded file:border file:border-neutral-700 file:bg-neutral-900 file:px-3 file:py-1.5 file:text-xs file:text-neutral-100 hover:file:border-neutral-500 disabled:opacity-50`})]}),(0,R.jsxs)(`label`,{className:`block space-y-1`,children:[(0,R.jsx)(`span`,{className:`text-[11px] uppercase tracking-wider text-neutral-500`,children:`From folder (Chromium / WebKit only)`}),(0,R.jsx)(`input`,{ref:p,type:`file`,multiple:!0,webkitdirectory:``,disabled:t,onChange:e=>{let t=e.target.files;t===null||t.length===0||y(Array.from(t))},className:`block text-xs text-neutral-300 file:mr-3 file:rounded file:border file:border-neutral-700 file:bg-neutral-900 file:px-3 file:py-1.5 file:text-xs file:text-neutral-100 hover:file:border-neutral-500 disabled:opacity-50`})]})]}),u!==void 0&&(0,R.jsxs)(`div`,{className:`mt-3 space-y-1 text-xs`,children:[u.imported.length>0&&(0,R.jsxs)(`p`,{className:`text-emerald-400 light:text-emerald-700`,children:[`Imported `,u.imported.length,` file`,u.imported.length===1?``:`s`,`:`,` `,(0,R.jsx)(`code`,{className:`font-mono`,children:u.imported.join(`, `)})]}),u.skipped.length>0&&(0,R.jsxs)(`div`,{className:`text-amber-400 light:text-amber-700`,children:[(0,R.jsxs)(`p`,{children:[`Skipped `,u.skipped.length,` entr`,u.skipped.length===1?`y`:`ies`,`:`]}),(0,R.jsx)(`ul`,{className:`ml-4 list-disc`,children:u.skipped.map(e=>(0,R.jsxs)(`li`,{children:[(0,R.jsx)(`code`,{className:`font-mono`,children:e.name}),` (`,e.reason,`)`]},e.name))})]}),u.imported.length===0&&u.skipped.length===0&&(0,R.jsx)(`p`,{className:`italic text-neutral-500`,children:`No files were imported.`})]})]})]})}var nM=`***REDACTED***`;function rM(){return{name:``,kind:`remote`,enabled:!0,url:``,transport:`auto`,headers:[],command:``,argsText:``,env:[],cwd:``}}function iM(e){return e.split(`
|
|
361
|
-
`).map(e=>e.trim()).filter(e=>e.length>0)}function
|
|
362
|
-
`),env:Object.entries(t.env??{}).map(([e,t])=>({key:e,value:t})),cwd:t.cwd??``}))},ne=()=>{_(void 0),h(rM())},re=async()=>{if(m===void 0)return;if(m.name.trim().length===0){e(`Name is required.`);return}if(m.kind===`remote`&&m.url.trim().length===0){e(`URL is required for remote servers.`);return}if(m.kind===`stdio`&&m.command.trim().length===0){e(`Command is required for stdio servers.`);return}let t={enabled:m.enabled};if(m.kind===`remote`){t.url=m.url,t.transport=m.transport;let e={};for(let t of m.headers)t.key.trim().length!==0&&(e[t.key]=t.value);Object.keys(e).length>0&&(t.headers=e)}else{t.command=m.command;let e=iM(m.argsText);e.length>0&&(t.args=e);let n={};for(let e of m.env)e.key.trim().length!==0&&(n[e.key]=e.value);Object.keys(n).length>0&&(t.env=n),m.cwd.trim().length>0&&(t.cwd=m.cwd)}b(!0);try{await l(m.name,t),e(void 0),h(void 0),_(void 0)}catch(t){e(`Failed to save server: ${Nj(t)}`)}finally{b(!1)}},ie=async t=>{if(window.confirm(`Remove MCP server '${t}' from the global registry?`)){b(!0);try{await u(t),e(void 0)}catch(t){e(`Failed to remove server: ${Nj(t)}`)}finally{b(!1)}}},j=async(n,r)=>{S(n);try{await d(n,r===`project`?t?.id:void 0),e(void 0),k()}catch(t){e(`Probe failed for '${n}': ${Nj(t)}`)}finally{S(void 0)}},ae=async(t,n)=>{b(!0);try{await L.setToolEnabled(`mcp`,t,n,`global`),await k()}catch(t){e(`Toggle failed: ${Nj(t)}`)}finally{b(!1)}},M=async(t,n,r)=>{b(!0);try{r===void 0?await L.clearToolProjectOverride(`mcp`,n,t):await L.setToolEnabled(`mcp`,n,r===`enabled`,`project`,t),await k()}catch(t){e(`Override write failed: ${Nj(t)}`)}finally{b(!1)}},oe=e=>{O(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};if(r===void 0)return(0,R.jsx)(`p`,{className:`text-xs italic text-neutral-500`,children:`Loading MCP config…`});let se=r.enabled,ce=a.filter(e=>e.scope===`global`),le=a.filter(e=>e.scope===`project`);return(0,R.jsxs)(`div`,{className:`space-y-4`,children:[(0,R.jsxs)(`p`,{className:`text-xs text-neutral-500`,children:[`MCP servers extend the agent with custom tools. Servers configured here are loaded by every new session. Project-scoped servers in `,(0,R.jsx)(`code`,{className:`font-mono`,children:`.mcp.json`}),` at the project root are also loaded for sessions in that project (project entries override globals on name collision).`]}),(0,R.jsxs)(`div`,{className:`flex items-center justify-between rounded border border-neutral-800 bg-neutral-900/40 p-3`,children:[(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`div`,{className:`text-sm font-medium text-neutral-100`,children:`MCP tools`}),(0,R.jsx)(`div`,{className:`text-[11px] text-neutral-500`,children:`Master switch. When off, no MCP tools reach the agent regardless of per-server state.`})]}),(0,R.jsx)(`button`,{onClick:()=>void ee(!se),disabled:y,className:`rounded border px-3 py-1 text-xs ${se?`border-emerald-700/50 bg-emerald-900/20 text-emerald-300 light:border-emerald-300 light:bg-emerald-50 light:text-emerald-800`:`border-neutral-700 text-neutral-300 hover:border-neutral-500`}`,children:se?`Enabled`:`Disabled`})]}),t!==void 0&&(0,R.jsx)(cM,{projectName:t.name,trusted:o?.trusted===!0,gatedCount:a.filter(e=>e.scope===`project`&&e.state===`trust_required`).length,busy:y,onGrant:async()=>{b(!0);try{await f(t.id),e(void 0)}catch(t){e(`Failed to grant trust: ${Nj(t)}`)}finally{b(!1)}},onRevoke:async()=>{if(window.confirm(`Revoke stdio MCP trust for "${t.name}"? This disconnects every running project-scoped MCP server.`)){b(!0);try{await p(t.id),e(void 0)}catch(t){e(`Failed to revoke trust: ${Nj(t)}`)}finally{b(!1)}}}}),(0,R.jsx)(oM,{title:`Global servers`,emptyHint:`No global MCP servers configured. Click 'Add server' to add one.`,servers:ce.map(e=>({status:e,config:i[e.name]})),editable:!0,editingName:g??null,probingName:x??null,toolsByServer:C,expandedServers:D,allOverrides:T,projects:n,busy:y,onToggleExpanded:oe,onToggleToolGlobal:(e,t)=>void ae(e,t),onSetProjectToolOverride:(e,t,n)=>void M(e,t,n),onToggle:(e,t)=>void A(e,t),onProbe:e=>void j(e,`global`),onEdit:te,onRemove:e=>void ie(e)}),t!==void 0&&(0,R.jsx)(oM,{title:`Project servers (${t.name})`,emptyHint:(0,R.jsxs)(R.Fragment,{children:[`No project servers. Add a `,(0,R.jsx)(`code`,{className:`font-mono`,children:`.mcp.json`}),` file at the project root to define some — supports both`,` `,(0,R.jsx)(`code`,{className:`font-mono`,children:`{ servers: {...} }`}),` and the standard`,` `,(0,R.jsx)(`code`,{className:`font-mono`,children:`{ mcpServers: {...} }`}),` shape.`]}),servers:le.map(e=>({status:e,config:void 0})),editable:!1,probingName:x??null,toolsByServer:C,expandedServers:D,allOverrides:T,projects:n,busy:y,onToggleExpanded:oe,onToggleToolGlobal:(e,t)=>void ae(e,t),onSetProjectToolOverride:(e,t,n)=>void M(e,t,n),onProbe:e=>void j(e,`project`)}),m===void 0?(0,R.jsx)(`button`,{onClick:ne,className:`rounded-md border border-neutral-700 px-3 py-1 text-xs text-neutral-200 hover:border-neutral-500`,children:`+ Add server`}):(0,R.jsx)(lM,{draft:m,isEditing:g!==void 0,busy:y,onChange:h,onSave:()=>void re(),onCancel:()=>{h(void 0),_(void 0)}})]})}function oM(e){return(0,R.jsxs)(`section`,{className:`space-y-2`,children:[(0,R.jsx)(`h3`,{className:`text-xs font-semibold uppercase tracking-wider text-neutral-400`,children:e.title}),e.servers.length===0?(0,R.jsx)(`p`,{className:`text-[11px] italic text-neutral-500`,children:e.emptyHint}):(0,R.jsx)(`div`,{className:`space-y-2`,children:e.servers.map(t=>{let n=t.status,r=e.editingName===n.name,i=e.probingName===n.name,a=`${n.scope}:${n.name}`,o=e.toolsByServer.get(a)??[],s=e.expandedServers.has(a),c=o.length>0;return(0,R.jsxs)(`div`,{className:`rounded border ${r?`border-neutral-500 bg-neutral-900`:`border-neutral-800 bg-neutral-900/40`}`,children:[(0,R.jsxs)(`div`,{className:`p-3`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,R.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,R.jsx)(`button`,{type:`button`,onClick:()=>c&&e.onToggleExpanded(a),disabled:!c,className:`flex h-5 w-5 items-center justify-center rounded text-neutral-300 hover:bg-neutral-800 hover:text-neutral-100 disabled:opacity-30`,title:c?s?`Hide tools`:`Show tools`:`No tools to show (server not connected or empty)`,children:s?(0,R.jsx)(ue,{size:16}):(0,R.jsx)(fe,{size:16})}),(0,R.jsx)(sM,{state:n.state}),(0,R.jsx)(`span`,{className:`font-mono text-sm text-neutral-100`,children:n.name}),(0,R.jsx)(`span`,{className:`rounded bg-neutral-800 px-1.5 py-0.5 text-[10px] uppercase tracking-wider text-neutral-400`,children:n.transport??`auto`}),(0,R.jsxs)(`span`,{className:`text-[11px] text-neutral-500`,children:[n.toolCount,` tools`]})]}),(0,R.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1 text-xs`,children:[e.editable&&e.onToggle!==void 0&&(0,R.jsx)(`button`,{onClick:()=>e.onToggle?.(n.name,!n.enabled),className:`rounded border px-2 py-0.5 ${n.enabled?`border-emerald-700/50 bg-emerald-900/20 text-emerald-300 light:border-emerald-300 light:bg-emerald-50 light:text-emerald-800`:`border-neutral-700 text-neutral-400 hover:border-neutral-500`}`,children:n.enabled?`Enabled`:`Disabled`}),(0,R.jsx)(`button`,{onClick:()=>e.onProbe(n.name),disabled:i,className:`rounded border border-neutral-700 px-2 py-0.5 text-neutral-300 hover:border-neutral-500 disabled:opacity-50`,title:`Reconnect and refresh tool list`,children:i?`Probing…`:`Probe`}),e.editable&&e.onEdit!==void 0&&(0,R.jsx)(`button`,{onClick:()=>e.onEdit?.(n.name),className:`rounded border border-neutral-700 px-2 py-0.5 text-neutral-300 hover:border-neutral-500`,children:`Edit`}),e.editable&&e.onRemove!==void 0&&(0,R.jsx)(`button`,{onClick:()=>e.onRemove?.(n.name),className:`rounded border border-red-700/50 px-2 py-0.5 text-red-300 hover:bg-red-900/20`,children:`Remove`})]})]}),n.kind===`stdio`?(0,R.jsxs)(`div`,{className:`mt-1 truncate font-mono text-[11px] text-neutral-500`,title:`${n.command??``} ${(n.args??[]).join(` `)}`.trim(),children:[n.command,` `,(n.args??[]).join(` `)]}):(0,R.jsx)(`div`,{className:`mt-1 truncate text-[11px] text-neutral-500`,title:n.url??``,children:n.url}),n.lastError!==void 0&&(0,R.jsx)(`div`,{className:`mt-1 truncate text-[11px] text-red-300 light:text-red-700`,title:n.lastError,children:n.lastError})]}),s&&c&&(0,R.jsxs)(`div`,{className:`space-y-2 border-t border-neutral-800 bg-neutral-950/40 px-3 py-2`,children:[(0,R.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-neutral-500`,children:`Tools`}),(0,R.jsx)(`div`,{className:`space-y-2`,children:o.map(t=>(0,R.jsx)(Yj,{family:`mcp`,name:t.shortName,fqn:t.name,description:t.description,globalEnabled:t.globalEnabled,projects:e.projects,allOverrides:e.allOverrides,busy:e.busy,onToggleGlobal:n=>e.onToggleToolGlobal(t.name,n),onSetProjectOverride:(n,r)=>e.onSetProjectToolOverride(n,t.name,r)},`mcp:${t.name}`))})]})]},a)})})]})}function sM({state:e}){return(0,R.jsx)(`span`,{className:`h-2 w-2 rounded-full ${e===`connected`?`bg-emerald-500`:e===`connecting`?`bg-amber-400 animate-pulse`:e===`error`?`bg-red-500`:e===`disabled`?`bg-neutral-700`:`bg-neutral-500`}`,title:e})}function cM(e){return e.trusted?(0,R.jsxs)(`div`,{className:`flex items-center justify-between rounded border border-neutral-800 bg-neutral-900/40 px-3 py-1.5 text-[11px] text-neutral-500`,children:[(0,R.jsxs)(`span`,{children:[`Stdio MCP trust granted for`,` `,(0,R.jsx)(`strong`,{className:`text-neutral-300`,children:e.projectName}),`. Project-local stdio MCP servers from `,(0,R.jsx)(`code`,{className:`font-mono`,children:`.mcp.json`}),` will spawn on session create.`]}),(0,R.jsx)(`button`,{onClick:()=>void e.onRevoke(),disabled:e.busy,className:`rounded border border-neutral-700 px-2 py-0.5 text-[10px] text-neutral-400 hover:border-neutral-500 hover:text-neutral-200 disabled:opacity-50`,title:`Disconnects every running project-scoped MCP server`,children:`Revoke`})]}):e.gatedCount===0?null:(0,R.jsxs)(`div`,{className:`rounded border border-amber-700/40 bg-amber-900/20 p-3 text-xs text-amber-200 light:border-amber-300 light:bg-amber-50 light:text-amber-800`,children:[(0,R.jsxs)(`div`,{className:`mb-2 font-medium`,children:[`This project wants to spawn `,e.gatedCount,` stdio MCP server`,e.gatedCount===1?``:`s`,`.`]}),(0,R.jsxs)(`p`,{className:`text-[11px] leading-relaxed`,children:[(0,R.jsx)(`strong`,{children:e.projectName}),`'s `,(0,R.jsx)(`code`,{className:`font-mono`,children:`.mcp.json`}),` declares MCP server`,e.gatedCount===1?``:`s`,` that pi-forge would launch as local subprocess`,e.gatedCount===1?``:`es`,`. Stdio MCP runs arbitrary commands on this machine with whatever env you've passed through — only trust projects whose`,` `,(0,R.jsx)(`code`,{className:`font-mono`,children:`.mcp.json`}),` you've reviewed and approve of. Remote (URL) entries in this project are unaffected by this gate.`]}),(0,R.jsx)(`div`,{className:`mt-2 flex gap-2`,children:(0,R.jsx)(`button`,{onClick:()=>void e.onGrant(),disabled:e.busy,className:`rounded bg-amber-200 px-3 py-1 text-[11px] font-medium text-amber-900 hover:bg-amber-100 disabled:opacity-50 light:bg-amber-600 light:text-amber-50 light:hover:bg-amber-700`,children:e.busy?`Granting…`:`Trust this project`})})]})}function lM(e){let{draft:t,busy:n}=e,r=(n,r)=>{e.onChange({...t,[n]:r})};return(0,R.jsxs)(`div`,{className:`rounded border border-neutral-700 bg-neutral-900 p-3`,children:[(0,R.jsx)(`h4`,{className:`mb-2 text-xs font-semibold uppercase tracking-wider text-neutral-400`,children:e.isEditing?`Edit '${t.name}'`:`Add MCP server`}),(0,R.jsxs)(`div`,{className:`mb-3 flex items-center gap-3 rounded border border-neutral-800 bg-neutral-950 p-2 text-[11px]`,children:[(0,R.jsx)(`span`,{className:`text-neutral-500`,children:`Type`}),(0,R.jsxs)(`label`,{className:`flex items-center gap-1.5 ${e.isEditing?`cursor-not-allowed opacity-60`:`cursor-pointer`}`,children:[(0,R.jsx)(`input`,{type:`radio`,name:`mcp-kind`,checked:t.kind===`remote`,disabled:e.isEditing,onChange:()=>r(`kind`,`remote`)}),(0,R.jsx)(`span`,{children:`Remote URL`})]}),(0,R.jsxs)(`label`,{className:`flex items-center gap-1.5 ${e.isEditing?`cursor-not-allowed opacity-60`:`cursor-pointer`}`,children:[(0,R.jsx)(`input`,{type:`radio`,name:`mcp-kind`,checked:t.kind===`stdio`,disabled:e.isEditing,onChange:()=>r(`kind`,`stdio`)}),(0,R.jsx)(`span`,{children:`Local subprocess (stdio)`})]}),e.isEditing&&(0,R.jsx)(`span`,{className:`text-[10px] italic text-neutral-600`,children:`Locked while editing — delete and re-add to change type.`})]}),(0,R.jsxs)(`div`,{className:`grid grid-cols-[80px_1fr] items-center gap-2 text-xs`,children:[(0,R.jsx)(`label`,{className:`text-neutral-500`,children:`Name`}),(0,R.jsx)(`input`,{value:t.name,onChange:e=>r(`name`,e.target.value),disabled:e.isEditing,placeholder:`my-server`,className:`rounded border border-neutral-700 bg-neutral-950 px-2 py-1 text-neutral-100 outline-none focus:border-neutral-500 disabled:opacity-50`}),t.kind===`remote`?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`label`,{className:`text-neutral-500`,children:`URL`}),(0,R.jsx)(`input`,{value:t.url,onChange:e=>r(`url`,e.target.value),placeholder:`https://mcp.example.com/sse`,className:`rounded border border-neutral-700 bg-neutral-950 px-2 py-1 text-neutral-100 outline-none focus:border-neutral-500`}),(0,R.jsx)(`label`,{className:`text-neutral-500`,children:`Transport`}),(0,R.jsxs)(`select`,{value:t.transport,onChange:e=>r(`transport`,e.target.value),className:`rounded border border-neutral-700 bg-neutral-950 px-2 py-1 text-neutral-100 outline-none focus:border-neutral-500`,children:[(0,R.jsx)(`option`,{value:`auto`,children:`auto (StreamableHTTP, fall back to SSE)`}),(0,R.jsx)(`option`,{value:`streamable-http`,children:`streamable-http`}),(0,R.jsx)(`option`,{value:`sse`,children:`sse`})]})]}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`label`,{className:`text-neutral-500`,children:`Command`}),(0,R.jsx)(`input`,{value:t.command,onChange:e=>r(`command`,e.target.value),placeholder:`npx (or absolute path to a binary)`,className:`rounded border border-neutral-700 bg-neutral-950 px-2 py-1 font-mono text-neutral-100 outline-none focus:border-neutral-500`}),(0,R.jsx)(`label`,{className:`self-start pt-1 text-neutral-500`,children:`Args`}),(0,R.jsx)(`textarea`,{value:t.argsText,onChange:e=>r(`argsText`,e.target.value),placeholder:`-y
|
|
363
|
-
@modelcontextprotocol/server-everything`,rows:3,spellCheck:!1,className:`rounded border border-neutral-700 bg-neutral-950 px-2 py-1 font-mono text-[11px] text-neutral-100 outline-none focus:border-neutral-500`}),(0,R.jsx)(`label`,{className:`text-neutral-500`,children:`cwd`}),(0,R.jsx)(`input`,{value:t.cwd,onChange:e=>r(`cwd`,e.target.value),placeholder:`(blank ↦ default: project path for project servers)`,className:`rounded border border-neutral-700 bg-neutral-950 px-2 py-1 font-mono text-neutral-100 outline-none focus:border-neutral-500`})]}),(0,R.jsx)(`label`,{className:`text-neutral-500`,children:`Enabled`}),(0,R.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,R.jsx)(`input`,{type:`checkbox`,checked:t.enabled,onChange:e=>r(`enabled`,e.target.checked)}),(0,R.jsx)(`span`,{className:`text-[11px] text-neutral-500`,children:`Disabled servers don't connect or contribute tools.`})]})]}),t.kind===`remote`?(0,R.jsx)(uM,{label:`Headers`,emptyHint:"No headers. Add `Authorization: Bearer …` here for auth.",keyPlaceholder:`Authorization`,valuePlaceholder:`Bearer …`,rows:t.headers,onChange:e=>r(`headers`,e)}):(0,R.jsx)(uM,{label:`Env`,emptyHint:`No env. Add API keys / config your subprocess needs (PATH / HOME / locale are inherited automatically).`,keyPlaceholder:`GITHUB_TOKEN`,valuePlaceholder:`ghp_…`,rows:t.env,onChange:e=>r(`env`,e)}),(0,R.jsxs)(`div`,{className:`mt-3 flex justify-end gap-2`,children:[(0,R.jsx)(`button`,{onClick:e.onCancel,className:`rounded border border-neutral-700 px-3 py-1 text-xs text-neutral-300 hover:border-neutral-500`,children:`Cancel`}),(0,R.jsx)(`button`,{onClick:e.onSave,disabled:n,className:`rounded bg-neutral-100 px-3 py-1 text-xs font-medium text-neutral-900 disabled:opacity-50`,children:n?`Saving…`:`Save`})]})]})}function uM(e){let{rows:t}=e;return(0,R.jsxs)(`div`,{className:`mt-3`,children:[(0,R.jsxs)(`div`,{className:`mb-1 flex items-center justify-between`,children:[(0,R.jsx)(`h5`,{className:`text-[11px] font-semibold uppercase tracking-wider text-neutral-500`,children:e.label}),(0,R.jsxs)(`button`,{onClick:()=>e.onChange([...t,{key:``,value:``}]),className:`rounded border border-neutral-700 px-2 py-0.5 text-[11px] text-neutral-300 hover:border-neutral-500`,children:[`+ `,e.label.replace(/s$/,``)]})]}),t.length===0&&(0,R.jsx)(`p`,{className:`text-[11px] italic text-neutral-600`,children:e.emptyHint}),t.map((n,r)=>(0,R.jsxs)(`div`,{className:`mb-1 grid grid-cols-[1fr_2fr_auto] gap-1`,children:[(0,R.jsx)(`input`,{value:n.key,onChange:i=>{let a=[...t];a[r]={...n,key:i.target.value},e.onChange(a)},placeholder:e.keyPlaceholder,className:`rounded border border-neutral-700 bg-neutral-950 px-2 py-1 text-[11px] font-mono text-neutral-100 outline-none focus:border-neutral-500`}),(0,R.jsx)(`input`,{value:n.value===nM?``:n.value,onChange:i=>{let a=[...t];a[r]={...n,value:i.target.value},e.onChange(a)},placeholder:n.value===nM?`leave blank to keep stored value`:e.valuePlaceholder,type:`password`,className:`rounded border border-neutral-700 bg-neutral-950 px-2 py-1 text-[11px] font-mono text-neutral-100 outline-none focus:border-neutral-500`}),(0,R.jsx)(`button`,{onClick:()=>e.onChange(t.filter((e,t)=>t!==r)),className:`rounded border border-neutral-700 px-2 text-[11px] text-neutral-400 hover:text-red-300 light:hover:text-red-700`,title:`Remove ${e.label.toLowerCase()}`,children:`×`})]},r)),t.some(e=>e.value===nM)&&(0,R.jsx)(`p`,{className:`mt-1 text-[10px] italic text-neutral-500`,children:`Values with the redaction sentinel keep their stored value when you save.`})]})}var dM=8;function fM(){let e=ci(e=>e.version),t=ci(e=>e.loaded),n=ci(e=>e.passwordAuthEnabled);return(0,R.jsxs)(`div`,{className:`space-y-6 text-sm text-neutral-300`,children:[(0,R.jsxs)(`header`,{className:`space-y-1`,children:[(0,R.jsx)(`h2`,{className:`text-base font-semibold text-neutral-100`,children:`pi-forge`}),(0,R.jsxs)(`p`,{className:`text-xs text-neutral-500`,children:[`Browser interface for the`,` `,(0,R.jsx)(`a`,{href:`https://github.com/badlogic/pi-mono`,target:`_blank`,rel:`noopener noreferrer`,className:`text-blue-400 underline hover:text-blue-300 light:text-blue-700 light:hover:text-blue-900`,children:`pi coding agent`}),`.`]})]}),(0,R.jsxs)(`section`,{className:`space-y-2`,children:[(0,R.jsx)(`h3`,{className:`text-xs font-semibold uppercase tracking-wider text-neutral-500`,children:`Version`}),(0,R.jsx)(`p`,{className:`font-mono text-sm`,children:t?e.length>0?e:(0,R.jsx)(`span`,{className:`text-neutral-500`,children:`unknown`}):(0,R.jsx)(`span`,{className:`text-neutral-500`,children:`loading…`})})]}),(0,R.jsxs)(`section`,{className:`space-y-2`,children:[(0,R.jsx)(`h3`,{className:`text-xs font-semibold uppercase tracking-wider text-neutral-500`,children:`Links`}),(0,R.jsxs)(`ul`,{className:`space-y-1 text-xs`,children:[(0,R.jsx)(`li`,{children:(0,R.jsx)(`a`,{href:`https://github.com/Devin-Marks/pi-forge`,target:`_blank`,rel:`noopener noreferrer`,className:`text-blue-400 underline hover:text-blue-300 light:text-blue-700 light:hover:text-blue-900`,children:`github.com/Devin-Marks/pi-forge`})}),(0,R.jsx)(`li`,{children:(0,R.jsx)(`a`,{href:`https://github.com/Devin-Marks/pi-forge/blob/main/CHANGELOG.md`,target:`_blank`,rel:`noopener noreferrer`,className:`text-blue-400 underline hover:text-blue-300 light:text-blue-700 light:hover:text-blue-900`,children:`Changelog`})}),(0,R.jsx)(`li`,{children:(0,R.jsx)(`a`,{href:`https://github.com/Devin-Marks/pi-forge/blob/main/SECURITY.md`,target:`_blank`,rel:`noopener noreferrer`,className:`text-blue-400 underline hover:text-blue-300 light:text-blue-700 light:hover:text-blue-900`,children:`Security`})})]})]}),n&&(0,R.jsx)(pM,{})]})}function pM(){let e=ar(e=>e.changePassword),t=ar(e=>e.changePasswordPending),n=ar(e=>e.changePasswordError),[r,i]=(0,v.useState)(``),[a,o]=(0,v.useState)(``),[s,c]=(0,v.useState)(``),[l,u]=(0,v.useState)(void 0),[d,f]=(0,v.useState)(!1),p=(0,v.useRef)(!1);(0,v.useEffect)(()=>{if(p.current&&!t&&n===void 0){i(``),o(``),c(``),f(!0);let e=window.setTimeout(()=>f(!1),2500);return()=>window.clearTimeout(e)}p.current=t},[t,n]);let m=t=>{if(t.preventDefault(),u(void 0),f(!1),a.length<dM){u(`New password must be at least ${dM} characters.`);return}if(a!==s){u(`New password and confirmation do not match.`);return}if(a===r){u(`New password must differ from the current one.`);return}e(r,a)},h=l??mM(n);return(0,R.jsxs)(`section`,{className:`space-y-2 border-t border-neutral-800 pt-5`,children:[(0,R.jsx)(`h3`,{className:`text-xs font-semibold uppercase tracking-wider text-neutral-500`,children:`Change password`}),(0,R.jsx)(`p`,{className:`text-xs text-neutral-500`,children:`Updates the scrypt hash on disk; existing browser sessions stay signed in.`}),(0,R.jsxs)(`form`,{onSubmit:m,className:`space-y-2`,children:[(0,R.jsxs)(`label`,{className:`block space-y-1`,children:[(0,R.jsx)(`span`,{className:`text-xs text-neutral-400`,children:`Current password`}),(0,R.jsx)(`input`,{type:`password`,value:r,onChange:e=>i(e.target.value),autoComplete:`current-password`,className:`w-full rounded-md border border-neutral-700 bg-neutral-950 px-3 py-1.5 text-sm outline-none focus:border-neutral-500`})]}),(0,R.jsxs)(`label`,{className:`block space-y-1`,children:[(0,R.jsx)(`span`,{className:`text-xs text-neutral-400`,children:`New password`}),(0,R.jsx)(`input`,{type:`password`,value:a,onChange:e=>o(e.target.value),autoComplete:`new-password`,minLength:dM,className:`w-full rounded-md border border-neutral-700 bg-neutral-950 px-3 py-1.5 text-sm outline-none focus:border-neutral-500`})]}),(0,R.jsxs)(`label`,{className:`block space-y-1`,children:[(0,R.jsx)(`span`,{className:`text-xs text-neutral-400`,children:`Confirm new password`}),(0,R.jsx)(`input`,{type:`password`,value:s,onChange:e=>c(e.target.value),autoComplete:`new-password`,minLength:dM,className:`w-full rounded-md border border-neutral-700 bg-neutral-950 px-3 py-1.5 text-sm outline-none focus:border-neutral-500`})]}),h!==void 0&&(0,R.jsx)(`p`,{role:`alert`,className:`text-xs text-red-400`,children:h}),d&&(0,R.jsx)(`p`,{role:`status`,className:`text-xs text-emerald-400 light:text-emerald-700`,children:`Password updated.`}),(0,R.jsx)(`button`,{type:`submit`,disabled:t||r.length===0||a.length===0,className:`rounded-md bg-neutral-100 px-3 py-1.5 text-xs font-medium text-neutral-900 transition hover:bg-white disabled:cursor-not-allowed disabled:opacity-50`,children:t?`Saving…`:`Update password`})]})]})}function mM(e){if(e!==void 0)switch(e){case`invalid_password`:return`Current password is incorrect.`;case`password_unchanged`:return`New password must differ from the current one.`;case`ui_password_not_configured`:return`Password auth is not configured on this server.`;case`auth_required`:return`Session expired — sign in again.`;default:return`Could not change password: ${e}`}}function hM({sessionId:e}){let t=wr(t=>t.pendingBySession[e]);return t===void 0?null:(0,R.jsx)(gM,{pending:t},t.requestId)}function gM({pending:e}){let t=wr(e=>e.clearPending),[n,r]=(0,v.useState)(0),[i,a]=(0,v.useState)(!1),[o,s]=(0,v.useState)(void 0),[c,l]=(0,v.useState)(()=>e.questions.map(()=>null)),u=e.questions[n];if(u===void 0)return null;let d=e=>{l(t=>{let r=t.slice();return r[n]={...r[n]??{},...e},r})},f=c[n],p=()=>u.multiSelect===!0?f?.multiLabels!==void 0&&f.multiLabels.length>0:f?.selectedLabel!==void 0||f?.customText!==void 0&&f.customText.trim().length>0,m=()=>{let t=[];for(let n=0;n<e.questions.length;n+=1){let r=e.questions[n],i=c[n];if(i!=null){if(r.multiSelect===!0){t.push({questionIndex:n,question:r.question,kind:`multi`,answer:null,...i.multiLabels===void 0?{}:{selected:i.multiLabels}});continue}if(i.selectedLabel!==void 0){let e=r.options.find(e=>e.label===i.selectedLabel);t.push({questionIndex:n,question:r.question,kind:`option`,answer:i.selectedLabel,...e?.preview===void 0?{}:{preview:e.preview}});continue}if(i.customText!==void 0&&i.customText.trim().length>0){t.push({questionIndex:n,question:r.question,kind:`custom`,answer:i.customText.trim()});continue}}}return t},h=async()=>{if(p()){if(n<e.questions.length-1){r(n+1);return}a(!0),s(void 0);try{await L.submitAskUserQuestionAnswer(e.sessionId,{requestId:e.requestId,answers:m()}),t(e.sessionId,e.requestId)}catch(e){s(e instanceof N?`${e.code}: ${e.message}`:e.message),a(!1)}}},g=async()=>{a(!0),s(void 0);try{let r={questionIndex:n,question:u.question,kind:`chat`,answer:`Chat about this`};await L.submitAskUserQuestionAnswer(e.sessionId,{requestId:e.requestId,answers:[r],cancelled:!0}),t(e.sessionId,e.requestId)}catch(e){s(e instanceof N?`${e.code}: ${e.message}`:e.message),a(!1)}};return(0,R.jsx)(`div`,{className:`flex max-h-[60vh] shrink-0 flex-col overflow-hidden border-t border-amber-700/50 bg-neutral-900/40 light:border-amber-400 light:bg-amber-50/60`,children:(0,R.jsxs)(`div`,{className:`flex flex-col overflow-hidden`,children:[(0,R.jsxs)(`header`,{className:`flex items-center gap-2 border-b border-neutral-800 px-4 py-2 light:border-neutral-200`,children:[(0,R.jsx)(`span`,{className:`text-[10px] font-semibold uppercase tracking-wider text-amber-400 light:text-amber-700`,children:`Agent question`}),e.questions.length>1&&(0,R.jsx)(`div`,{className:`ml-2 flex items-center gap-1 text-[10px] uppercase tracking-wider text-neutral-500`,children:e.questions.map((e,t)=>(0,R.jsx)(`span`,{className:`rounded px-1.5 py-0.5 ${t===n?`bg-amber-900/40 text-amber-200 light:bg-amber-100 light:text-amber-900`:c[t]===null?`text-neutral-500`:`bg-neutral-800 text-neutral-300 light:bg-neutral-200 light:text-neutral-700`}`,title:e.question,children:e.header},t))}),(0,R.jsx)(`div`,{className:`flex-1`}),(0,R.jsxs)(`span`,{className:`text-[10px] uppercase tracking-wider text-neutral-500`,children:[n+1,` of `,e.questions.length]})]}),o!==void 0&&(0,R.jsx)(`div`,{className:`border-b border-red-700/40 bg-red-900/20 px-4 py-2 text-xs text-red-300 light:border-red-300 light:bg-red-50 light:text-red-800`,children:o}),(0,R.jsx)(`div`,{className:`flex-1 overflow-y-auto px-4 py-3`,children:(0,R.jsx)(_M,{question:u,draft:f??null,onChange:e=>d(e)})}),(0,R.jsxs)(`footer`,{className:`flex items-center gap-2 border-t border-neutral-800 px-4 py-2 light:border-neutral-200`,children:[(0,R.jsxs)(`button`,{type:`button`,onClick:()=>void g(),disabled:i,className:`flex items-center gap-1 rounded border border-neutral-700 px-3 py-1 text-xs text-neutral-300 hover:border-neutral-500 disabled:opacity-50 light:border-neutral-400 light:text-neutral-700`,title:`Abandon the structured questionnaire and reply in free-form chat`,children:[(0,R.jsx)(Fe,{size:12}),`Chat about this`]}),(0,R.jsx)(`div`,{className:`flex-1`}),n>0&&(0,R.jsxs)(`button`,{type:`button`,onClick:()=>r(n-1),disabled:i,className:`flex items-center gap-1 rounded border border-neutral-700 px-3 py-1 text-xs text-neutral-300 hover:border-neutral-500 disabled:opacity-50 light:border-neutral-400 light:text-neutral-700`,children:[(0,R.jsx)(de,{size:12}),`Back`]}),(0,R.jsxs)(`button`,{type:`button`,onClick:()=>void h(),disabled:i||!p(),className:`flex items-center gap-1 rounded bg-emerald-700 px-3 py-1 text-xs text-white hover:bg-emerald-600 disabled:opacity-50`,children:[i?(0,R.jsx)(Ne,{size:12,className:`animate-spin`}):null,n<e.questions.length-1?(0,R.jsxs)(R.Fragment,{children:[`Next `,(0,R.jsx)(fe,{size:12})]}):i?`Submitting…`:`Submit`]})]})]})})}function _M({question:e,draft:t,onChange:n}){let r=(0,v.useMemo)(()=>e.options.some(e=>typeof e.preview==`string`&&e.preview.length>0),[e.options]),i=e.multiSelect===!0,a=!i&&!r,[o,s]=(0,v.useState)(void 0),c=e.options.find(e=>e.label===o);return(0,v.useEffect)(()=>{r&&o===void 0&&e.options[0]!==void 0&&s(e.options[0].label)},[r,o,e.options]),(0,R.jsxs)(`div`,{className:`space-y-3`,children:[(0,R.jsx)(`h2`,{className:`text-base font-medium text-neutral-100 light:text-neutral-900`,children:e.question}),r&&!i?(0,R.jsxs)(`div`,{className:`grid grid-cols-3 gap-3`,children:[(0,R.jsx)(`div`,{className:`col-span-1 space-y-1`,children:e.options.map(e=>(0,R.jsxs)(`button`,{type:`button`,onClick:()=>{n({selectedLabel:e.label}),s(e.label)},onMouseEnter:()=>s(e.label),className:`w-full rounded border px-2 py-1.5 text-left text-xs ${t?.selectedLabel===e.label?`border-emerald-600 bg-emerald-900/30 text-emerald-100 light:bg-emerald-50 light:text-emerald-900`:o===e.label?`border-neutral-600 bg-neutral-900 text-neutral-100 light:border-neutral-400 light:bg-neutral-100 light:text-neutral-900`:`border-neutral-800 bg-neutral-900/40 text-neutral-300 hover:border-neutral-600 light:border-neutral-300 light:bg-neutral-50 light:text-neutral-700`}`,children:[(0,R.jsx)(`div`,{className:`font-medium`,children:e.label}),(0,R.jsx)(`div`,{className:`mt-0.5 text-[11px] text-neutral-400 light:text-neutral-600`,children:e.description})]},e.label))}),(0,R.jsx)(`div`,{className:`col-span-2 overflow-auto rounded border border-neutral-800 bg-neutral-950 p-3 light:border-neutral-300 light:bg-neutral-50`,children:c?.preview!==void 0&&c.preview.length>0?(0,R.jsx)(`pre`,{className:`whitespace-pre-wrap font-mono text-[11px] text-neutral-200 light:text-neutral-800`,children:c.preview}):(0,R.jsx)(`p`,{className:`text-xs italic text-neutral-500 light:text-neutral-600`,children:`No preview for this option.`})})]}):i?(0,R.jsx)(`div`,{className:`space-y-1`,children:e.options.map(e=>{let r=(t?.multiLabels??[]).includes(e.label);return(0,R.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 rounded border px-2 py-1.5 text-xs ${r?`border-emerald-600 bg-emerald-900/30 light:bg-emerald-50`:`border-neutral-800 bg-neutral-900/40 hover:border-neutral-600 light:border-neutral-300 light:bg-neutral-50`}`,children:[(0,R.jsx)(`input`,{type:`checkbox`,checked:r,onChange:()=>{let i=new Set(t?.multiLabels??[]);r?i.delete(e.label):i.add(e.label),n({multiLabels:Array.from(i)})},className:`mt-1`}),(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`div`,{className:`font-medium text-neutral-100 light:text-neutral-900`,children:e.label}),(0,R.jsx)(`div`,{className:`mt-0.5 text-[11px] text-neutral-400 light:text-neutral-600`,children:e.description})]})]},e.label)})}):(0,R.jsxs)(`div`,{className:`space-y-1`,children:[e.options.map(e=>(0,R.jsxs)(`button`,{type:`button`,onClick:()=>n({selectedLabel:e.label,customText:void 0}),className:`w-full rounded border px-2 py-1.5 text-left text-xs ${t?.selectedLabel===e.label?`border-emerald-600 bg-emerald-900/30 light:bg-emerald-50`:`border-neutral-800 bg-neutral-900/40 hover:border-neutral-600 light:border-neutral-300 light:bg-neutral-50`}`,children:[(0,R.jsx)(`div`,{className:`font-medium text-neutral-100 light:text-neutral-900`,children:e.label}),(0,R.jsx)(`div`,{className:`mt-0.5 text-[11px] text-neutral-400 light:text-neutral-600`,children:e.description})]},e.label)),a&&(0,R.jsxs)(`div`,{className:`pt-2`,children:[(0,R.jsx)(`label`,{className:`mb-1 block text-[10px] uppercase tracking-wider text-neutral-500 light:text-neutral-600`,children:`Type something`}),(0,R.jsx)(`textarea`,{value:t?.customText??``,onChange:e=>n({customText:e.target.value,selectedLabel:void 0}),rows:2,placeholder:`Or type your own answer…`,className:`w-full rounded border border-neutral-700 bg-neutral-950 px-2 py-1 text-xs text-neutral-100 light:border-neutral-300 light:bg-white light:text-neutral-900`})]})]})]})}function vM({sessionId:e,onClose:t}){let n=Er(t=>Dr(t,e)),r=Er(e=>e.set),[i,a]=(0,v.useState)(void 0);(0,v.useEffect)(()=>{let t=!1;return L.listTodos(e).then(n=>{if(t)return;let i=Er.getState().byId[e];(i===void 0||i.tasks.length===0)&&r(e,{tasks:n.tasks,nextId:n.nextId})}).catch(e=>{t||a(e instanceof N?e.code:e.message)}),()=>{t=!0}},[e,r]);let o=(0,v.useMemo)(()=>Or(n),[n]),s=(0,v.useMemo)(()=>yM(n.tasks),[n.tasks]);return(0,R.jsxs)(`div`,{className:`flex h-full flex-col overflow-hidden bg-neutral-950 text-neutral-200 light:bg-white light:text-neutral-900`,children:[(0,R.jsxs)(`header`,{className:`flex items-center gap-2 border-b border-neutral-800 px-3 py-1.5 text-xs light:border-neutral-200`,children:[(0,R.jsx)(`span`,{className:`font-semibold uppercase tracking-wider text-neutral-400 light:text-neutral-600`,children:`Todos`}),(0,R.jsxs)(`span`,{className:`text-neutral-500 light:text-neutral-600`,children:[o.completed,`/`,o.total,o.inProgress>0?` · ${o.inProgress} in progress`:``]}),(0,R.jsx)(`div`,{className:`flex-1`}),(0,R.jsx)(`button`,{type:`button`,onClick:t,className:`rounded p-0.5 text-neutral-500 hover:bg-neutral-800 hover:text-neutral-200 light:hover:bg-neutral-200 light:hover:text-neutral-900`,title:`Hide todo panel`,children:(0,R.jsx)(it,{size:12})})]}),i!==void 0&&n.tasks.length===0&&(0,R.jsxs)(`div`,{className:`border-b border-red-700/40 bg-red-900/20 px-3 py-1.5 text-[11px] text-red-300 light:border-red-300 light:bg-red-50 light:text-red-800`,children:[`Failed to load todos: `,i]}),(0,R.jsx)(`div`,{className:`flex-1 overflow-y-auto px-2 py-2`,children:o.total===0?(0,R.jsx)(`p`,{className:`px-1 text-[11px] italic text-neutral-500 light:text-neutral-600`,children:`No todos yet. The agent will add tasks here when it's planning multi-step work.`}):(0,R.jsxs)(`div`,{className:`space-y-2`,children:[s.in_progress.length>0&&(0,R.jsx)(bM,{label:`In Progress`,tasks:s.in_progress}),s.pending.length>0&&(0,R.jsx)(bM,{label:`Pending`,tasks:s.pending}),s.completed.length>0&&(0,R.jsx)(bM,{label:`Completed`,tasks:s.completed})]})})]})}function yM(e){let t={pending:[],in_progress:[],completed:[],deleted:[]};for(let n of e)t[n.status].push(n);return t}function bM({label:e,tasks:t}){return(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`div`,{className:`mb-1 px-1 text-[10px] uppercase tracking-wider text-neutral-500 light:text-neutral-600`,children:e}),(0,R.jsx)(`div`,{className:`space-y-0.5`,children:t.map(e=>(0,R.jsx)(xM,{task:e},e.id))})]})}function xM({task:e}){let[t,n]=(0,v.useState)(!1),r=e.description!==void 0||e.activeForm!==void 0||e.blockedBy!==void 0&&e.blockedBy.length>0||e.owner!==void 0;return(0,R.jsxs)(`div`,{className:`rounded border border-transparent px-1 py-0.5 text-xs hover:border-neutral-800 light:hover:border-neutral-300`,children:[(0,R.jsxs)(`button`,{type:`button`,onClick:()=>r&&n(e=>!e),className:`flex w-full items-start gap-1.5 text-left ${r?`cursor-pointer`:`cursor-default`}`,children:[r&&(0,R.jsx)(fe,{size:11,className:`mt-0.5 shrink-0 text-neutral-500 transition-transform light:text-neutral-600 ${t?`rotate-90`:``}`}),!r&&(0,R.jsx)(`span`,{className:`inline-block w-[11px] shrink-0`}),(0,R.jsx)(SM,{status:e.status,activeForm:e.activeForm}),(0,R.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,R.jsx)(`span`,{className:`${e.status===`completed`?`text-neutral-500 line-through light:text-neutral-500`:e.status===`in_progress`?`text-neutral-100 light:text-neutral-900`:`text-neutral-300 light:text-neutral-700`}`,children:e.subject}),e.status===`in_progress`&&e.activeForm!==void 0&&(0,R.jsx)(`span`,{className:`ml-1 text-[10px] italic text-amber-400 light:text-amber-700`,children:e.activeForm})]}),(0,R.jsxs)(`span`,{className:`shrink-0 text-[10px] text-neutral-500 light:text-neutral-600`,children:[`#`,e.id]})]}),t&&r&&(0,R.jsxs)(`div`,{className:`mt-1 space-y-0.5 pl-[34px] text-[11px] text-neutral-400 light:text-neutral-600`,children:[e.description!==void 0&&(0,R.jsx)(`div`,{children:e.description}),e.blockedBy!==void 0&&e.blockedBy.length>0&&(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`span`,{className:`text-neutral-500 light:text-neutral-600`,children:`blocked by:`}),` `,e.blockedBy.map(e=>`#${e}`).join(`, `)]}),e.owner!==void 0&&(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`span`,{className:`text-neutral-500 light:text-neutral-600`,children:`owner:`}),` `,e.owner]})]})]})}function SM({status:e,activeForm:t}){return e===`in_progress`?(0,R.jsx)(Ne,{size:11,className:`mt-0.5 shrink-0 animate-spin text-amber-400 light:text-amber-700`,"aria-label":t??`in progress`}):e===`completed`?(0,R.jsx)(le,{size:11,className:`mt-0.5 shrink-0 text-emerald-400 light:text-emerald-700`,"aria-label":`completed`}):e===`deleted`?(0,R.jsx)(it,{size:11,className:`mt-0.5 shrink-0 text-neutral-500 light:text-neutral-500`,"aria-label":`deleted`}):(0,R.jsx)(he,{size:11,className:`mt-0.5 shrink-0 text-neutral-500 light:text-neutral-500`,"aria-label":`pending`})}function CM({sessionId:e}){let t=Nr(t=>Pr(t,e)),n=Nr(t=>Fr(t,e)),r=Nr(e=>e.setProcesses),i=Nr(e=>e.clearWatches),[a,o]=(0,v.useState)(void 0),[s,c]=(0,v.useState)(!1);(0,v.useEffect)(()=>{let t=!1;return L.listProcesses(e).then(n=>{if(t)return;let i=Nr.getState().bySession[e];(i===void 0||i.length===0)&&r(e,n.processes)}).catch(e=>{t||o(e instanceof N?e.code:e.message)}),()=>{t=!0}},[e,r]);let l=(0,v.useMemo)(()=>wM(t),[t]),u=Ir(t),d=t.length-u,f=async()=>{c(!0),o(void 0);try{await L.clearProcesses(e)}catch(e){o(e instanceof N?e.code:e.message)}finally{c(!1)}};return(0,R.jsxs)(`div`,{className:`flex h-full flex-col overflow-hidden bg-neutral-950 text-neutral-200 light:bg-white light:text-neutral-900`,children:[(0,R.jsxs)(`header`,{className:`flex items-center gap-2 border-b border-neutral-800 px-3 py-1.5 text-xs light:border-neutral-200`,children:[(0,R.jsx)(`span`,{className:`font-semibold uppercase tracking-wider text-neutral-400 light:text-neutral-600`,children:`Processes`}),(0,R.jsxs)(`span`,{className:`text-neutral-500 light:text-neutral-600`,children:[u,` running · `,d,` finished`]}),(0,R.jsx)(`div`,{className:`flex-1`}),d>0&&(0,R.jsxs)(`button`,{type:`button`,onClick:()=>void f(),disabled:s,className:`flex items-center gap-1 rounded border border-neutral-700 px-1.5 py-0.5 text-[10px] text-neutral-400 hover:border-neutral-500 hover:text-neutral-200 disabled:opacity-50 light:border-neutral-400 light:text-neutral-600`,title:`Drop all FINISHED processes from the list (running ones stay)`,children:[(0,R.jsx)($e,{size:10}),`Clear finished`]})]}),a!==void 0&&(0,R.jsx)(`div`,{className:`border-b border-red-700/40 bg-red-900/20 px-3 py-1.5 text-[11px] text-red-300 light:border-red-300 light:bg-red-50 light:text-red-800`,children:a}),n.length>0&&(0,R.jsxs)(`div`,{className:`flex items-start gap-2 border-b border-amber-700/40 bg-amber-900/20 px-3 py-1.5 text-[11px] text-amber-200 light:border-amber-300 light:bg-amber-50 light:text-amber-800`,children:[(0,R.jsx)(ce,{size:11,className:`mt-0.5 shrink-0`}),(0,R.jsxs)(`div`,{className:`flex-1 space-y-0.5`,children:[n.slice(-3).map((e,t)=>(0,R.jsxs)(`div`,{className:`truncate font-mono`,children:[(0,R.jsxs)(`span`,{className:`text-neutral-500 light:text-neutral-600`,children:[`[`,e.processName,`]`]}),` `,e.line]},`${e.processId}-${t}`)),n.length>3&&(0,R.jsxs)(`div`,{className:`text-neutral-500 light:text-neutral-600`,children:[`+`,n.length-3,` more watch match(es)`]})]}),(0,R.jsx)(`button`,{type:`button`,onClick:()=>i(e),className:`rounded p-0.5 text-amber-300 hover:text-amber-100 light:text-amber-700 light:hover:text-amber-900`,title:`Clear watch alerts`,children:(0,R.jsx)(We,{size:11})})]}),(0,R.jsx)(`div`,{className:`flex-1 overflow-y-auto px-2 py-2`,children:t.length===0?(0,R.jsx)(`p`,{className:`px-1 text-[11px] italic text-neutral-500 light:text-neutral-600`,children:`No background processes yet. The agent will add them here when it starts dev servers, test watchers, builds, etc.`}):(0,R.jsxs)(`div`,{className:`space-y-2`,children:[l.live.length>0&&(0,R.jsx)(TM,{label:`Running`,items:l.live,sessionId:e}),l.finished.length>0&&(0,R.jsx)(TM,{label:`Finished`,items:l.finished,sessionId:e})]})}),(0,R.jsx)(`footer`,{className:`border-t border-neutral-800 px-3 py-1 text-[10px] italic text-neutral-500 light:border-neutral-200 light:text-neutral-600`,children:`In-memory only — processes don't survive a server restart.`})]})}function wM(e){let t=[],n=[];for(let r of e)kr.has(r.status)?t.push(r):n.push(r);return{live:t,finished:n}}function TM({label:e,items:t,sessionId:n}){return(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`div`,{className:`mb-1 px-1 text-[10px] uppercase tracking-wider text-neutral-500 light:text-neutral-600`,children:e}),(0,R.jsx)(`div`,{className:`space-y-1`,children:t.map(e=>(0,R.jsx)(EM,{process:e,sessionId:n},e.id))})]})}function EM({process:e,sessionId:t}){let[n,r]=(0,v.useState)(!1),[i,a]=(0,v.useState)(void 0),[o,s]=(0,v.useState)(!1),[c,l]=(0,v.useState)(void 0),u=kr.has(e.status);(0,v.useEffect)(()=>{if(!n)return;let r=!1;return L.getProcessOutput(t,e.id,80).then(e=>{r||a(e)}).catch(()=>{}),()=>{r=!0}},[n,t,e.id,e.endTime,e.status]);let d=Nr(e=>e.setProcesses),f=async()=>{s(!0),l(void 0);try{let n=await L.killProcess(t,e.id);n.ok||l(n.reason??`kill failed`),setTimeout(()=>{L.listProcesses(t).then(e=>d(t,e.processes)).catch(()=>void 0)},800)}catch(e){l(e instanceof N?e.code:e.message)}finally{s(!1)}},p=kM(e.startTime,e.endTime);return(0,R.jsxs)(`div`,{className:`rounded border px-1.5 py-1 text-xs ${DM(e.status)} ${u?`bg-neutral-900/40 light:bg-neutral-50`:`bg-neutral-900/20 light:bg-neutral-50/60`}`,children:[(0,R.jsxs)(`button`,{type:`button`,onClick:()=>r(e=>!e),className:`flex w-full items-start gap-1.5 text-left`,children:[(0,R.jsx)(fe,{size:11,className:`mt-0.5 shrink-0 text-neutral-500 transition-transform light:text-neutral-600 ${n?`rotate-90`:``}`}),(0,R.jsx)(OM,{status:e.status,success:e.success}),(0,R.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,R.jsxs)(`div`,{className:`flex items-baseline gap-1.5`,children:[(0,R.jsx)(`span`,{className:`truncate font-medium text-neutral-100 light:text-neutral-900`,children:e.name}),(0,R.jsx)(`span`,{className:`shrink-0 text-[10px] text-neutral-500 light:text-neutral-600`,children:e.id})]}),(0,R.jsx)(`div`,{className:`truncate font-mono text-[10px] text-neutral-500 light:text-neutral-600`,children:e.command})]}),(0,R.jsx)(`span`,{className:`shrink-0 text-[10px] text-neutral-500 light:text-neutral-600`,children:p})]}),n&&(0,R.jsxs)(`div`,{className:`mt-1 space-y-1 pl-[24px]`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] text-neutral-500 light:text-neutral-600`,children:[(0,R.jsxs)(`span`,{children:[`PID `,e.pid]}),e.exitCode!==null&&(0,R.jsxs)(`span`,{children:[`exit `,e.exitCode]}),(0,R.jsx)(`div`,{className:`flex-1`}),u&&(0,R.jsxs)(`button`,{type:`button`,onClick:()=>void f(),disabled:o,className:`flex items-center gap-1 rounded border border-red-700/40 px-1.5 py-0.5 text-[10px] text-red-300 hover:bg-red-900/40 disabled:opacity-50 light:border-red-400 light:text-red-700 light:hover:bg-red-100`,children:[(0,R.jsx)(me,{size:10}),`Kill`]})]}),c!==void 0&&(0,R.jsx)(`div`,{className:`text-[10px] text-red-300 light:text-red-700`,children:c}),i!==void 0&&i.stdout.length>0&&(0,R.jsxs)(`details`,{className:`rounded bg-neutral-950 light:bg-white`,children:[(0,R.jsx)(`summary`,{className:`cursor-pointer px-1 py-0.5 text-[10px] uppercase tracking-wider text-neutral-500 hover:text-neutral-300 light:text-neutral-600 light:hover:text-neutral-900`,children:`stdout (tail)`}),(0,R.jsx)(`pre`,{className:`max-h-48 overflow-auto whitespace-pre-wrap px-1.5 py-1 font-mono text-[10px] text-neutral-300 light:text-neutral-800`,children:i.stdout.join(`
|
|
357
|
+
`)+Se.text),Ce(),setTimeout(()=>{let e=D.current;e!==null&&(e.focus(),e.setSelectionRange(e.value.length,e.value.length))},0))},[Se,e,Ce]);let we=(()=>{if(!t&&!n){if(u.startsWith(`!!`))return`local`;if(u.startsWith(`!`))return`context`}})(),Te=(0,v.useMemo)(()=>{let r=[{name:`/compact`,description:`Manually compact the session context`,available:!t,run:async()=>{try{await L.compact(e),s(e)}catch(e){Ke(`Compact failed: ${e instanceof N?e.code:e.message}`)}}},{name:`/clear`,description:`Compact context (alias for /compact)`,available:!t,run:async()=>{try{await L.compact(e),s(e)}catch(e){Ke(`Clear failed: ${e instanceof N?e.code:e.message}`)}}},{name:`/abort`,description:`Stop the agent (alias for the Abort button)`,available:t,run:()=>c(e)},{name:`/settings`,description:`Open the Settings panel`,available:!0,run:()=>de()},{name:`/skills`,description:`Open Settings → Skills`,available:!0,run:()=>de(`skills`)},{name:`/mcp`,description:`Open Settings → MCP`,available:!0,run:()=>de(`mcp`)},{name:`/providers`,description:`Open Settings → Providers`,available:!0,run:()=>de(`providers`)},{name:`/help`,description:n?"Show what `/` and `@` do in the input":"Show what `/`, `!`, `@` do in the input",available:!0,run:()=>{Ke(n?`/<cmd> runs a pi-forge command (compact, abort, settings, …). @<path> references a project file (autocomplete from the popover).`:`/<cmd> runs a pi-forge command (compact, abort, settings, …). !cmd runs bash (output → next LLM context); !!cmd runs bash local-only. @<path> references a project file (autocomplete from the popover).`)}}];for(let e of be){let n=e.argumentHint===void 0?e.description:`${e.description} — args: ${e.argumentHint}`;r.push({name:`/${e.name}`,description:n,available:!t,run:()=>{let t=`/${e.name} `;d(t),requestAnimationFrame(()=>{let e=D.current;e!==null&&(e.focus(),e.setSelectionRange(t.length,t.length))})}})}return r},[t,e,c,s,de,n,be]),Ee=(0,v.useMemo)(()=>{let e=ye.toLowerCase();return e.length===0?Te:Te.filter(t=>t.name.slice(1).toLowerCase().startsWith(e))},[Te,ye]),De=(0,v.useMemo)(()=>{if(!ve)return!1;let e=u.slice(1).split(/\s/)[0]??``;return e.length===0||!be.some(t=>t.name===e)?!1:u===`/${e}`||u.startsWith(`/${e} `)},[ve,u,be]),Oe=e=>{let t=Ee[e??ge];t===void 0||!t.available||(d(``),_e(0),t.run())},ke=(0,v.useRef)(0),[je,Ne]=(0,v.useState)([]),Pe=(0,v.useRef)(new Map),Fe=(0,v.useRef)(null),Ie=(0,v.useRef)(null),[Le,Re]=(0,v.useState)(!1),ze=(0,v.useRef)(null),[Ve,He]=(0,v.useState)(void 0),Ue=new Set(`doc.xls.ppt.pptx.vsd.vsdx.odt.ods.odp.rtf.zip.tar.gz.bz2.xz.7z.rar.exe.dll.so.dylib.bin.o.a.class.jar.wasm.mp3.mp4.m4a.wav.flac.ogg.avi.mov.wmv.mkv.heic.heif.tiff.tif.bmp.ico.psd.ttf.otf.woff.woff2.eot.sqlite.db.iso.dmg`.split(`.`)),[Ge,Ke]=(0,v.useState)(void 0),qe=e=>{Ke(void 0);let t=je,n=[...t],r=t.filter(e=>e.type.startsWith(`image/`)).length;for(let t of e){if(n.length>=8){Ke(`Up to 8 attachments per message; "${t.name}" dropped.`);continue}if(t.size>20971520){Ke(`"${t.name}" exceeds the 20 MB per-file limit.`);continue}if(t.type.startsWith(`image/`)&&r>=4){Ke(`Up to 4 images per message; "${t.name}" dropped.`);continue}let e=t.name.includes(`.`)?t.name.split(`.`).pop()?.toLowerCase():void 0;if(e!==void 0&&Ue.has(e)){Ke(`"${t.name}" is a binary format that the agent can't read directly. Convert to text/markdown (or to a PNG/JPEG screenshot for diagrams) and try again.`);continue}n.push(t),t.type.startsWith(`image/`)&&(r+=1,Pe.current.set(t,URL.createObjectURL(t)))}Ne(n)},Je=e=>{let t=Pe.current.get(e);t!==void 0&&(URL.revokeObjectURL(t),Pe.current.delete(e)),Ne(t=>t.filter(t=>t!==e))},Ye=()=>{for(let e of Pe.current.values())URL.revokeObjectURL(e);Pe.current.clear(),Ne([]),Ke(void 0)};(0,v.useEffect)(()=>{let e=Pe.current;return()=>{for(let t of e.values())URL.revokeObjectURL(t);e.clear()}},[]);let Xe=Jr(t=>t.messagesBySession[e]??zr),[Ze,Qe]=(0,v.useState)(0),$e=(0,v.useMemo)(()=>{let t=dj(e),n=pj(Xe),r=new Set,i=[];for(let e of[...t,...n])r.has(e)||(r.add(e),i.push(e));return i},[Xe,e,Ze]),[et,tt]=(0,v.useState)(void 0),nt=(0,v.useRef)(``);(0,v.useEffect)(()=>{tt(void 0),nt.current=``},[e]),(0,v.useEffect)(()=>{ke.current=0},[e]);let rt=mj+e,[at,ot]=(0,v.useState)(void 0),[ct,lt]=(0,v.useState)(void 0),[ut,dt]=(0,v.useState)(()=>localStorage.getItem(mj+e)??``),[ft,pt]=(0,v.useState)(void 0),[mt,ht]=(0,v.useState)(void 0),[gt,_t]=(0,v.useState)(void 0),[vt,yt]=(0,v.useState)(void 0);(0,v.useEffect)(()=>{L.getProviders().then(ot).catch(e=>{pt(`models unavailable (${e instanceof N?e.code:e.message})`)}),L.getSettings().then(e=>{lt({provider:typeof e.defaultProvider==`string`?e.defaultProvider:``,modelId:typeof e.defaultModel==`string`?e.defaultModel:``})}).catch(()=>{})},[]),(0,v.useEffect)(()=>{let t=localStorage.getItem(mj+e)??``;dt(t),pt(void 0),_t(void 0),ht(void 0),yt(void 0);{let t=e;L.getSession(t).then(n=>{t===e&&(ht(n.thinkingLevel),n.modelProvider!==void 0&&n.modelId!==void 0&&yt({provider:n.modelProvider,modelId:n.modelId}))}).catch(()=>{})}if(t===``)return;let[n,...r]=t.split(`:`),i=r.join(`:`);if(n===void 0||i.length===0)return;let a=e;L.setModel(a,n,i).catch(t=>{a===e&&pt(`set model failed: ${t instanceof N?t.code:t.message}`)})},[e]);let bt=Jr(t=>t.pendingDraftBySession[e]),xt=Jr(e=>e.consumePendingDraft);(0,v.useEffect)(()=>{bt!==void 0&&(d(bt),xt(e))},[bt,e,xt]),(0,v.useEffect)(()=>{if(fe===void 0||fe.seq<=he.current)return;he.current=fe.seq;let e=fe.text;d(t=>t.length===0?e:`${t}${/\s$/.test(t)?``:` `}${e}`),requestAnimationFrame(()=>{let e=D.current;if(e===null)return;e.focus();let t=e.value.length;e.setSelectionRange(t,t)}),pe()},[fe,pe]);let St=async t=>{if(dt(t),t===``){localStorage.removeItem(rt);return}let[n,...r]=t.split(`:`),i=r.join(`:`);if(!(n===void 0||i.length===0))try{await L.setModel(e,n,i),localStorage.setItem(rt,t),pt(void 0);let r=e;L.getSession(r).then(t=>{r===e&&(ht(t.thinkingLevel),t.modelProvider!==void 0&&t.modelId!==void 0&&yt({provider:t.modelProvider,modelId:t.modelId}))}).catch(()=>{})}catch(e){pt(`set model failed: ${e instanceof N?e.code:e.message}`)}},Ct=(0,v.useMemo)(()=>{if(at===void 0)return;let e,t;if(ut.length>0){let[n,...r]=ut.split(`:`);if(n===void 0)return;e=n,t=r.join(`:`)}else if(vt!==void 0)e=vt.provider,t=vt.modelId;else return;return at.providers.find(t=>t.provider===e)?.models.find(e=>e.id===t)},[at,ut,vt]),wt=async t=>{ht(t);try{ht((await L.setThinkingLevel(e,t)).level),_t(void 0)}catch(e){_t(`set thinking level failed: ${e instanceof N?e.code:e.message}`)}},Tt=async()=>{let r=u.trim();if(!(r.length===0&&je.length===0||f)){if(r.length>0&&(fj(e,r),Qe(e=>e+1)),ve&&!De){Ee.length>0?Oe():Ke(`Unknown command "${u.split(/\s/)[0]??u}". Type /help to see commands.`);return}p(!0);try{if(!t&&/^!!?[^!]/.test(r)){if(n){Ke(`Bash exec is disabled in this deployment.`);return}let t=r.startsWith(`!!`),i=r.slice(t?2:1).trim();if(i.length===0){Ke("Empty bash command. Type something after the `!`.");return}je.length>0&&(Ye(),Ke("Attachments aren't sent with `!` exec. Cleared.")),await L.exec(e,i,{excludeFromContext:t}),s(e),d(``),tt(void 0),nt.current=``;return}t?(je.length>0&&(Ye(),Ke(`Attachments aren't sent on steer (mid-turn). Cleared.`)),await o(e,r)):await a(e,r,je.length>0?je:void 0),d(``),Ye(),tt(void 0),nt.current=``,O&&D.current?.blur()}catch(e){Ke(`Command failed: ${e instanceof N?e.code:e.message}`)}finally{p(!1)}}},Et=n=>{if(ve){if(n.key===`Escape`){n.preventDefault(),d(``);return}if(Ee.length>0){if(n.key===`ArrowDown`){n.preventDefault(),_e(e=>Math.min(e+1,Ee.length-1));return}if(n.key===`ArrowUp`){n.preventDefault(),_e(e=>Math.max(e-1,0));return}if((n.key===`Enter`||n.key===`Tab`)&&!(De&&n.key===`Enter`&&!n.shiftKey)){n.preventDefault(),Oe();return}}else if(n.key===`Enter`&&!n.shiftKey){n.preventDefault(),Ke(`Unknown command "${u.split(/\s/)[0]??u}". Type /help to see commands, or backspace the leading / to send as a prompt.`);return}}if(ie!==void 0&&ae.length>0){if(n.key===`ArrowDown`){n.preventDefault(),le(e=>Math.min(e+1,ae.length-1));return}if(n.key===`ArrowUp`){n.preventDefault(),le(e=>Math.max(e-1,0));return}if(n.key===`Enter`||n.key===`Tab`){let e=ae[ce];if(e!==void 0){n.preventDefault(),kt(e);return}}if(n.key===`Escape`){n.preventDefault(),At();return}}if(n.key===`Enter`&&!n.shiftKey&&!O){n.preventDefault(),Tt();return}if(n.key===`ArrowUp`){let e=et!==void 0;if(e||u.length===0){if($e.length===0)return;n.preventDefault();let t=e?Math.min((et??0)+1,$e.length-1):0;e||(nt.current=u),tt(t);let r=$e[t];r!==void 0&&d(r)}return}if(n.key===`ArrowDown`){if(et===void 0)return;if(n.preventDefault(),et>0){let e=et-1;tt(e);let t=$e[e];t!==void 0&&d(t)}else tt(void 0),d(nt.current),nt.current=``;return}if(n.key===`Escape`){if(!t)return;n.preventDefault();let r=Date.now(),i=r-ke.current;ke.current=r,i<_j&&(ke.current=0,c(e))}},Dt=e=>{d(e),et!==void 0&&(tt(void 0),nt.current=``);let t=Ot(e,D.current?.selectionStart??e.length);j(t),t===void 0&&M([]),le(0)};function Ot(e,t){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,v.useEffect)(()=>{if(ie===void 0||E===void 0)return;let e=ue.current+1;ue.current=e;let t=window.setTimeout(()=>{L.completeFiles(E.id,ie.query,{limit:20}).then(t=>{ue.current===e&&(M(t.paths),le(0))}).catch(()=>{ue.current===e&&M([])})},100);return()=>window.clearTimeout(t)},[ie,E]);let kt=e=>{if(ie===void 0)return;let t=u.slice(0,ie.start),n=u.slice(ie.end),r=`@"${e}"`;d(`${t}${r}${n}`),j(void 0),M([]);let i=t.length+r.length;requestAnimationFrame(()=>{let e=D.current;e!==null&&(e.focus(),e.setSelectionRange(i,i))})},At=()=>{j(void 0),M([])},jt=oj(u),Mt=e=>{let t=cj(e);d(e=>e.replace(t,(e,t)=>t).trimEnd())};return(0,v.useEffect)(()=>{if(!Le)return;let e=e=>{let t=ze.current;t!==null&&(t.contains(e.target)||Re(!1))},t=e=>{e.key===`Escape`&&Re(!1)};return window.addEventListener(`mousedown`,e),window.addEventListener(`touchstart`,e),window.addEventListener(`keydown`,t),()=>{window.removeEventListener(`mousedown`,e),window.removeEventListener(`touchstart`,e),window.removeEventListener(`keydown`,t)}},[Le]),(0,v.useEffect)(()=>{if(!O){Ve!==void 0&&He(void 0);return}let e=D.current;if(e===null)return;let t=e.style.height;e.style.height=`auto`;let n=e.scrollHeight;e.style.height=t;let r=Math.round(window.innerHeight*.3),i=Math.max(44,Math.min(n,r));i!==Ve&&He(i)},[u,O]),(0,R.jsxs)(`div`,{className:`bg-neutral-950`,children:[(0,R.jsx)(`div`,{role:`separator`,"aria-orientation":`horizontal`,"aria-label":`Resize chat input`,onPointerDown:ne,className:`group relative hidden h-px cursor-row-resize bg-neutral-800 hover:bg-neutral-600 active:bg-neutral-500 md:block`,children:(0,R.jsx)(`div`,{className:`absolute inset-x-0 -top-1 h-2`})}),(0,R.jsxs)(`div`,{className:`mx-auto max-w-3xl space-y-2 px-3 pt-2 md:px-6 md:py-3`,style:{paddingBottom:`max(0.5rem, env(safe-area-inset-bottom))`},children:[(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,R.jsx)(yj,{providers:at,defaultModel:ct,value:ut,onChange:e=>void St(e)}),Ct!==void 0&&Ct.supportedThinkingLevels.length>1&&mt!==void 0&&(0,R.jsx)(bj,{value:mt,options:Ct.supportedThinkingLevels,onChange:e=>void wt(e)}),jt.length>0&&(0,R.jsx)(`div`,{className:`flex flex-wrap items-center gap-1`,children:jt.map((e,t)=>(0,R.jsxs)(`span`,{className:`inline-flex max-w-[220px] items-center gap-1 truncate rounded border border-emerald-700/60 bg-emerald-900/20 px-1.5 py-0.5 text-[11px] text-emerald-200`,title:`@${e} — model will use its read tool to load this file when it needs to`,children:[(0,R.jsx)(se,{size:11,className:`shrink-0`}),(0,R.jsx)(`span`,{className:`truncate font-mono`,children:e}),(0,R.jsx)(`button`,{type:`button`,onClick:()=>Mt(e),className:`-mr-0.5 ml-0.5 rounded p-0.5 text-emerald-300/70 hover:bg-emerald-900/40 hover:text-emerald-100`,title:`Remove @${e}`,children:(0,R.jsx)(it,{size:10})})]},`ref-${t}-${e}`))}),(ft!==void 0||gt!==void 0||A!==void 0||m.total>0||_>0)&&(0,R.jsxs)(`div`,{className:`ml-auto flex items-center gap-2`,children:[ft!==void 0&&(0,R.jsx)(`span`,{className:`text-[11px] text-red-400`,children:ft}),gt!==void 0&&(0,R.jsx)(`span`,{className:`text-[11px] text-red-400`,children:gt}),!O&&A!==void 0&&(0,R.jsx)(`button`,{type:`button`,onClick:re,className:`rounded p-1 text-neutral-500 hover:bg-neutral-800 hover:text-neutral-200`,title:`Reset chat input height to default`,"aria-label":`Reset chat input height to default`,children:(0,R.jsx)(We,{size:12})}),_>0&&(0,R.jsxs)(`div`,{className:`relative`,children:[(0,R.jsxs)(`button`,{ref:w,type:`button`,onClick:()=>{O?x(e=>!e):y()},className:`flex items-center gap-1 rounded px-1.5 py-1 text-[11px] ${O&&b?`bg-neutral-800 text-neutral-100 light:bg-neutral-200 light:text-neutral-900`:`text-neutral-400 hover:bg-neutral-800 hover:text-neutral-200 light:text-neutral-600 light:hover:bg-neutral-200 light:hover:text-neutral-900`}`,title:O?`${_} background process(es) running — show list`:`${_} background process(es) running — view processes panel`,"aria-label":O?`Show processes list`:`View processes panel`,"aria-expanded":O?b:void 0,children:[(0,R.jsx)(oe,{size:12,className:`text-emerald-400 light:text-emerald-700`}),(0,R.jsx)(`span`,{children:_})]}),O&&(0,R.jsx)(nj,{open:b,onClose:()=>x(!1),anchorRef:w,sessionId:e})]}),m.total>0&&(0,R.jsxs)(`div`,{className:`relative`,children:[(0,R.jsxs)(`button`,{ref:T,type:`button`,onClick:()=>{O?C(e=>!e):g(!h)},className:`flex items-center gap-1 rounded px-1.5 py-1 text-[11px] ${(O?S:h)?`bg-amber-900/40 text-amber-200 light:bg-amber-100 light:text-amber-900`:`text-neutral-400 hover:bg-neutral-800 hover:text-neutral-200 light:text-neutral-600 light:hover:bg-neutral-200 light:hover:text-neutral-900`}`,title:O?`Tasks: ${m.completed}/${m.total} done${m.inProgress>0?`, ${m.inProgress} in progress`:``}`:h?`Hide todo panel`:`Show todo panel (${m.completed}/${m.total} done${m.inProgress>0?`, ${m.inProgress} in progress`:``})`,"aria-label":O?`Show tasks list`:`Toggle todo panel`,"aria-expanded":O?S:void 0,"aria-pressed":O?void 0:h,children:[(0,R.jsx)(Me,{size:12}),(0,R.jsxs)(`span`,{children:[m.completed,`/`,m.total]})]}),O&&(0,R.jsx)(aj,{open:S,onClose:()=>C(!1),anchorRef:T,sessionId:e})]})]})]}),l!==void 0&&(0,R.jsxs)(`p`,{className:`text-xs text-red-400`,children:[`Error: `,l]}),Ge!==void 0&&(0,R.jsx)(`p`,{className:`text-xs text-amber-400`,children:Ge}),je.length>0&&(0,R.jsx)(xj,{attachments:je,previewUrls:Pe.current,onRemove:Je}),(0,R.jsxs)(`div`,{className:`flex items-end gap-2`,children:[(0,R.jsx)(`input`,{ref:Fe,type:`file`,multiple:!0,className:`hidden`,onChange:e=>{e.target.files!==null&&qe(e.target.files),e.target.value=``}}),O&&(0,R.jsx)(`input`,{ref:Ie,type:`file`,accept:`image/*`,multiple:!0,className:`hidden`,onChange:e=>{e.target.files!==null&&qe(e.target.files),e.target.value=``}}),O?(0,R.jsxs)(`div`,{className:`relative`,ref:ze,children:[(0,R.jsx)(`button`,{onClick:()=>Re(e=>!e),disabled:f||t,"aria-label":`Attach`,"aria-expanded":Le,className:`inline-flex min-h-11 min-w-11 items-center justify-center self-stretch rounded-md border border-neutral-700 bg-neutral-900 px-2 text-neutral-300 hover:border-neutral-500 hover:text-neutral-100 disabled:cursor-not-allowed disabled:opacity-50`,title:t?`Attachments aren't sent on steer (mid-turn).`:`Attach a photo or a file`,children:(0,R.jsx)(Be,{size:16})}),Le&&(0,R.jsxs)(`div`,{className:`absolute bottom-full left-0 z-20 mb-1 flex flex-col overflow-hidden rounded-md border border-neutral-700 bg-neutral-900 shadow-lg`,children:[(0,R.jsxs)(`button`,{onClick:()=>{Ie.current?.click(),Re(!1)},className:`flex min-h-11 items-center gap-2 px-3 text-left text-[14px] text-neutral-200 hover:bg-neutral-800`,children:[(0,R.jsx)(Ae,{size:16,className:`shrink-0 text-neutral-400`}),`Photo`]}),(0,R.jsxs)(`button`,{onClick:()=>{Fe.current?.click(),Re(!1)},className:`flex min-h-11 items-center gap-2 border-t border-neutral-800 px-3 text-left text-[14px] text-neutral-200 hover:bg-neutral-800`,children:[(0,R.jsx)(Be,{size:16,className:`shrink-0 text-neutral-400`}),`File`]})]})]}):(0,R.jsx)(`button`,{onClick:()=>Fe.current?.click(),disabled:f||t,"aria-label":`Attach files`,className:`inline-flex items-center justify-center self-stretch rounded-md border border-neutral-700 bg-neutral-900 px-2 text-neutral-300 hover:border-neutral-500 hover:text-neutral-100 disabled:cursor-not-allowed disabled:opacity-50`,title:t?`Attachments aren't sent on steer (mid-turn). Wait for the current run to finish.`:`Attach files (images go into model context; text files are prepended to the prompt)`,children:(0,R.jsx)(Be,{size:14})}),(0,R.jsxs)(`div`,{className:`relative flex-1`,children:[ve&&Ee.length>0&&(0,R.jsxs)(`div`,{className:`absolute bottom-full left-0 right-0 z-10 mb-1 overflow-hidden rounded-md border border-neutral-700 bg-neutral-900 shadow-lg`,children:[(0,R.jsx)(`div`,{className:`max-h-[60vh] overflow-y-auto py-1 md:max-h-64`,children:Ee.map((e,t)=>(0,R.jsx)(`button`,{onMouseDown:n=>{n.preventDefault(),e.available&&(_e(t),Oe(t))},onMouseEnter:()=>_e(t),disabled:!e.available,className:`block w-full px-3 py-2.5 text-left text-[14px] md:py-1 md:text-[12px] ${t===ge&&e.available?`bg-neutral-800 text-neutral-100`:`text-neutral-300 hover:bg-neutral-900/80`} ${e.available?``:`opacity-40`}`,title:e.available?e.description:`${e.description} — unavailable right now`,children:(0,R.jsxs)(`div`,{className:`flex flex-col md:block`,children:[(0,R.jsx)(`span`,{className:`font-mono text-neutral-200`,children:e.name}),(0,R.jsx)(`span`,{className:`text-[12px] text-neutral-500 md:ml-2 md:text-[10px]`,children:e.description})]})},e.name))}),(0,R.jsx)(`div`,{className:`hidden border-t border-neutral-800 px-3 py-1 text-[10px] text-neutral-500 md:block`,children:`↑↓ navigate · Enter/Tab run · Esc cancel`})]}),ie!==void 0&&ae.length>0&&(0,R.jsxs)(`div`,{className:`absolute bottom-full left-0 right-0 z-10 mb-1 overflow-hidden rounded-md border border-neutral-700 bg-neutral-900 shadow-lg`,children:[(0,R.jsx)(`div`,{className:`max-h-[60vh] overflow-y-auto py-1 md:max-h-64`,children:ae.map((e,t)=>(0,R.jsx)(`button`,{onMouseDown:t=>{t.preventDefault(),kt(e)},onMouseEnter:()=>le(t),className:`block w-full truncate px-3 py-2.5 text-left font-mono text-[14px] md:py-1 md:text-[12px] ${t===ce?`bg-neutral-800 text-neutral-100`:`text-neutral-300 hover:bg-neutral-900/80`}`,title:e,children:e},e))}),(0,R.jsx)(`div`,{className:`hidden border-t border-neutral-800 px-3 py-1 text-[10px] text-neutral-500 md:block`,children:`↑↓ navigate · Enter/Tab insert · Esc close`})]}),(0,R.jsx)(`textarea`,{ref:D,value:u,onChange:e=>Dt(e.target.value),onKeyDown:Et,onBlur:()=>{setTimeout(()=>{D.current!==document.activeElement&&At()},0)},placeholder:i?`Auto-retry in progress — your message will be queued and sent after the retry completes…`:t?O?`Steer the agent…`:`Steer the agent (Enter to send, Shift+Enter for newline)…`:O?n?"Ask pi — `/` runs commands, `@path` references files…":"Ask pi — `/` runs commands, `!` runs bash, `@path` references files…":n?"Ask pi (Enter to send, Shift+Enter for newline) — `/` runs commands, `@path` references files…":"Ask pi (Enter to send, Shift+Enter for newline) — `/` runs commands, `!` runs bash, `@path` references files…",title:i?`The agent is auto-retrying after a provider error. New messages are queued and delivered when the retry succeeds.`:void 0,rows:O?2:3,style:O&&Ve!==void 0?{height:`${Ve}px`,maxHeight:`30vh`}:!O&&A!==void 0?{height:`${A}px`}:void 0,className:`block w-full resize-none rounded-md border bg-neutral-900 px-3 py-2 text-sm text-neutral-100 outline-none min-h-11 md:min-h-0 ${we===`local`?`border-amber-500 focus:border-amber-400`:we===`context`?`border-emerald-500 focus:border-emerald-400`:`border-neutral-700 focus:border-neutral-500`}`}),we!==void 0&&(0,R.jsx)(`span`,{className:`pointer-events-none absolute right-2 top-2 select-none rounded px-1.5 py-0.5 font-mono text-[10px] uppercase tracking-wide ${we===`local`?`bg-amber-500/15 text-amber-300`:`bg-emerald-500/15 text-emerald-300`}`,title:we===`local`?`!! — runs bash; output stays local (excluded from LLM context)`:`! — runs bash; output is added to the next turn's LLM context`,children:we===`local`?`bash · local`:`bash · context`})]}),(0,R.jsxs)(`div`,{className:`flex flex-col-reverse gap-1 self-stretch md:flex-row md:items-end md:self-auto`,children:[(0,R.jsx)(`button`,{onClick:()=>void Tt(),disabled:u.trim().length===0&&je.length===0||f,className:`flex-1 rounded-md bg-neutral-100 px-4 text-sm font-medium text-neutral-900 disabled:cursor-not-allowed disabled:opacity-50 md:flex-none md:py-2`,title:t?`Send (Pi queues at the next agent break — steer or follow-up depending on agent state)`:`Send (Enter)`,children:`Send`}),t&&(0,R.jsx)(`button`,{onClick:()=>void c(e),className:`flex-1 rounded-md border border-red-700/60 bg-red-950/30 px-3 text-sm font-medium text-red-300 hover:bg-red-900/40 hover:text-red-100 md:flex-none md:py-2`,title:`Stop the agent (or press Esc twice in the textbox)`,children:`Abort`})]})]}),t&&(0,R.jsx)(`p`,{className:`text-[10px] text-neutral-600`,children:`Send queues at the next agent break — Pi picks steer or follow-up. Abort: stop the agent (or press Esc twice in the textbox).`})]})]})}function yj({providers:e,defaultModel:t,value:n,onChange:r}){let i=(0,v.useMemo)(()=>hj(e),[e]),[a,o]=(0,v.useState)(!1),[s,c]=(0,v.useState)(``),[l,u]=(0,v.useState)(0),d=(0,v.useRef)(null),f=(0,v.useRef)(null),p=(0,v.useRef)(null),m=(0,v.useMemo)(()=>{if(s.trim().length===0)return i;let e=[];for(let t of i){let n=gj(t,s);n!==void 0&&e.push({opt:t,score:n})}return e.sort((e,t)=>e.score-t.score),e.map(e=>e.opt)},[i,s]),h=i.find(e=>e.value===n),g=t!==void 0&&t.provider.length>0&&t.modelId.length>0?`${t.provider} / ${t.modelId}`:``,_=h===void 0?g.length>0?`${g} (default)`:`default model`:`${h.provider} / ${h.name}`;(0,v.useEffect)(()=>{if(!a)return;let e=e=>{d.current!==null&&(d.current.contains(e.target)||o(!1))};return window.addEventListener(`mousedown`,e),()=>window.removeEventListener(`mousedown`,e)},[a]),(0,v.useEffect)(()=>{a&&(c(``),u(0),requestAnimationFrame(()=>f.current?.focus()))},[a]),(0,v.useEffect)(()=>{!a||p.current===null||p.current.querySelector(`[data-idx="${l}"]`)?.scrollIntoView({block:`nearest`})},[a,l]);let y=e=>{if(e===-1)r(``);else{let t=m[e];if(t===void 0)return;r(t.value)}o(!1)};return(0,R.jsxs)(`div`,{ref:d,className:`relative`,children:[(0,R.jsxs)(`button`,{onClick:()=>o(e=>!e),disabled:e===void 0,className:`flex max-w-[260px] items-center gap-1 truncate rounded border border-neutral-700 bg-neutral-900 px-2 py-1 text-left text-[11px] text-neutral-200 disabled:opacity-50`,title:`Override the model for this session (click to search)`,children:[(0,R.jsx)(`span`,{className:`text-neutral-500`,children:`model:`}),(0,R.jsx)(`span`,{className:`truncate`,children:_}),(0,R.jsx)(`span`,{className:`ml-1 text-neutral-500`,children:`▾`})]}),a&&(0,R.jsxs)(`div`,{className:`absolute bottom-full left-0 z-10 mb-1 w-[360px] rounded border border-neutral-700 bg-neutral-950 shadow-xl`,children:[(0,R.jsx)(`input`,{ref:f,value:s,onChange:e=>{c(e.target.value),u(0)},onKeyDown:e=>{e.key===`ArrowDown`?(e.preventDefault(),u(e=>Math.min(e+1,m.length-1))):e.key===`ArrowUp`?(e.preventDefault(),u(e=>Math.max(e-1,-1))):e.key===`Enter`?(e.preventDefault(),y(l)):e.key===`Escape`&&(e.preventDefault(),o(!1))},placeholder:`Search provider or model…`,className:`w-full border-b border-neutral-800 bg-transparent px-3 py-2 text-xs text-neutral-100 outline-none`}),(0,R.jsxs)(`div`,{ref:p,className:`max-h-72 overflow-y-auto py-1`,children:[(0,R.jsxs)(`button`,{"data-idx":-1,onMouseEnter:()=>u(-1),onClick:()=>y(-1),className:`flex w-full items-center justify-between px-3 py-1.5 text-left text-xs ${l===-1?`bg-neutral-800 text-neutral-100`:`text-neutral-400`}`,children:[(0,R.jsxs)(`span`,{className:`flex min-w-0 items-baseline gap-2`,children:[(0,R.jsx)(`span`,{children:`Use agent default`}),g.length>0&&(0,R.jsx)(`span`,{className:`truncate font-mono text-[10px] text-neutral-500`,children:g})]}),n===``&&(0,R.jsx)(`span`,{className:`text-emerald-400`,children:`●`})]}),m.length===0?(0,R.jsx)(`p`,{className:`px-3 py-2 text-xs italic text-neutral-500`,children:`No models match. Add an API key in Settings → Providers.`}):m.map((e,t)=>(0,R.jsxs)(`button`,{"data-idx":t,onMouseEnter:()=>u(t),onClick:()=>y(t),className:`flex w-full items-center justify-between px-3 py-1.5 text-left text-xs ${t===l?`bg-neutral-800 text-neutral-100`:`text-neutral-300`}`,children:[(0,R.jsxs)(`span`,{className:`flex min-w-0 items-baseline gap-2`,children:[(0,R.jsx)(`span`,{className:`text-neutral-500`,children:e.provider}),(0,R.jsx)(`span`,{className:`truncate font-mono`,children:e.name})]}),e.value===n&&(0,R.jsx)(`span`,{className:`text-emerald-400`,children:`●`})]},e.value))]}),(0,R.jsxs)(`div`,{className:`border-t border-neutral-800 px-3 py-1.5 text-[10px] text-neutral-600`,children:[m.length,` of `,i.length,` models — ↑↓ to move, Enter to pick, Esc to close`]})]})]})}function bj({value:e,options:t,onChange:n}){let[r,i]=(0,v.useState)(!1),a=(0,v.useRef)(null);return(0,v.useEffect)(()=>{if(!r)return;let e=e=>{a.current!==null&&(a.current.contains(e.target)||i(!1))};return window.addEventListener(`mousedown`,e),()=>window.removeEventListener(`mousedown`,e)},[r]),(0,R.jsxs)(`div`,{ref:a,className:`relative`,children:[(0,R.jsxs)(`button`,{onClick:()=>i(e=>!e),className:`flex items-center gap-1 rounded border border-neutral-700 bg-neutral-900 px-2 py-1 text-left text-[11px] text-neutral-200`,title:`Override the thinking level for this session`,children:[(0,R.jsx)(`span`,{className:`text-neutral-500`,children:`thinking:`}),(0,R.jsx)(`span`,{className:`truncate`,children:e}),(0,R.jsx)(`span`,{className:`ml-1 text-neutral-500`,children:`▾`})]}),r&&(0,R.jsx)(`div`,{className:`absolute bottom-full left-0 z-10 mb-1 w-[140px] rounded border border-neutral-700 bg-neutral-950 shadow-xl`,children:t.map(t=>(0,R.jsxs)(`button`,{onClick:()=>{n(t),i(!1)},className:`flex w-full items-center justify-between px-3 py-1.5 text-left text-xs ${t===e?`bg-neutral-800 text-neutral-100`:`text-neutral-300`}`,children:[(0,R.jsx)(`span`,{children:t}),t===e&&(0,R.jsx)(`span`,{className:`text-emerald-400`,children:`●`})]},t))})]})}function xj({attachments:e,previewUrls:t,onRemove:n}){return(0,R.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:e.map((e,r)=>{let i=e.type.startsWith(`image/`),a=t.get(e);return(0,R.jsxs)(`div`,{className:`group relative flex items-center gap-1.5 rounded-md border border-neutral-700 bg-neutral-900 pr-1 text-xs text-neutral-200`,children:[i&&a!==void 0?(0,R.jsx)(`img`,{src:a,alt:e.name,className:`h-12 w-12 shrink-0 rounded-l-md object-cover`}):(0,R.jsx)(`span`,{className:`flex h-8 w-8 shrink-0 items-center justify-center rounded-l-md bg-neutral-800 text-neutral-400`,children:i?(0,R.jsx)(Ae,{size:14}):(0,R.jsx)(Be,{size:12})}),(0,R.jsxs)(`span`,{className:`flex flex-col py-1 pl-1`,children:[(0,R.jsx)(`span`,{className:`max-w-[160px] truncate font-mono text-[11px]`,title:e.name,children:e.name}),(0,R.jsx)(`span`,{className:`text-[10px] text-neutral-500`,children:Sj(e.size)})]}),(0,R.jsx)(`button`,{onClick:()=>n(e),className:`ml-1 rounded p-1 text-neutral-500 hover:bg-neutral-800 hover:text-red-300`,title:`Remove ${e.name}`,children:(0,R.jsx)(it,{size:16})})]},`${r}-${e.name}`)})})}function Sj(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function Cj({sessionId:e,alreadyOnChangesTab:t,onOpen:n}){let r=Jr(t=>t.streamingBySession[e]??!1),i=Jr(t=>t.agentEndCountBySession[e]??0),[a,o]=(0,v.useState)(0);return(0,v.useEffect)(()=>{o(0)},[e]),(0,v.useEffect)(()=>{if(r)return;let t=!1;return L.getTurnDiff(e).then(e=>{t||o(e.entries.length)}).catch(e=>{t||(e instanceof N&&e.status===404||typeof console<`u`&&console.warn(`[ChangedFilesBadge] turn-diff fetch failed:`,e),o(0))}),()=>{t=!0}},[e,i,r]),a===0||t?null:(0,R.jsx)(`div`,{className:`border-t border-neutral-800 bg-neutral-950 px-6 py-2`,children:(0,R.jsx)(`div`,{className:`mx-auto max-w-3xl`,children:(0,R.jsxs)(`button`,{onClick:n,className:`flex items-center gap-2 rounded-md border border-neutral-700 bg-neutral-900 px-3 py-1.5 text-xs text-neutral-200 hover:border-neutral-500 hover:bg-neutral-800`,title:`Open the Last turn pane to review what the agent just wrote`,children:[(0,R.jsx)(Se,{size:12}),a===1?`1 file edited`:`${a} files edited`,(0,R.jsx)(`span`,{className:`text-[10px] text-neutral-500`,children:`— review`})]})})})}var wj=3e4,Tj=[];function Ej(e){return e instanceof N?e.code:e instanceof Error?e.message:String(e)}var Dj=pt((e,t)=>({settings:void 0,globalServers:{},byProject:{},loading:!1,error:void 0,pollHandle:void 0,startPolling:()=>{if(t().pollHandle!==void 0)return;let n=()=>{typeof document<`u`&&document.hidden||t().refreshSettings()};n(),e({pollHandle:window.setInterval(n,wj)})},stopPolling:()=>{let n=t().pollHandle;n!==void 0&&(window.clearInterval(n),e({pollHandle:void 0}))},refreshSettings:async()=>{try{e({settings:await L.getMcpSettings(),error:void 0})}catch(t){if(!(t instanceof N)||t.status===401)return;e({error:Ej(t)})}},refreshProject:async t=>{if(t===void 0){try{e({globalServers:(await L.listMcpServers()).servers,error:void 0})}catch(t){if(t instanceof N&&t.status===401)return;e({error:Ej(t)})}return}e({loading:!0});try{let n=await L.listMcpServers(t);e(e=>{let r={status:n.status,loadedAt:Date.now()};return n.stdioTrust!==void 0&&(r.stdioTrust=n.stdioTrust),{loading:!1,error:void 0,globalServers:n.servers,byProject:{...e.byProject,[t]:r}}})}catch(t){e({loading:!1,error:Ej(t)})}},setMcpEnabled:async n=>{let r=t().settings;r!==void 0&&e({settings:{...r,enabled:n}});try{e({settings:await L.setMcpEnabled(n),error:void 0})}catch(t){throw r!==void 0&&e({settings:r}),e({error:Ej(t)}),t}},upsertServer:async(n,r)=>{try{await L.upsertMcpServer(n,r),await Promise.all([t().refreshSettings(),...Object.keys(t().byProject).map(e=>t().refreshProject(e))])}catch(t){throw e({error:Ej(t)}),t}},deleteServer:async n=>{try{await L.deleteMcpServer(n),await Promise.all([t().refreshSettings(),...Object.keys(t().byProject).map(e=>t().refreshProject(e))])}catch(t){throw e({error:Ej(t)}),t}},probeServer:async(n,r)=>{try{await L.probeMcpServer(n,r),await Promise.all([t().refreshSettings(),t().refreshProject(r)])}catch(t){throw e({error:Ej(t)}),t}},grantStdioTrust:async n=>{try{await L.grantStdioMcpTrust(n),await t().refreshProject(n)}catch(t){throw e({error:Ej(t)}),t}},revokeStdioTrust:async n=>{try{await L.revokeStdioMcpTrust(n),await t().refreshProject(n)}catch(t){throw e({error:Ej(t)}),t}}})),Oj={agent_end:`Agent turn finished`,ask_user_question:`Agent asked a question (waiting on user)`,process_alert:`Background process exited`,auto_retry_end:`Auto-retry exhausted (provider failure)`,compaction_end:`Context compaction completed`,session_created:`Session created`,session_deleted:`Session deleted`};function kj(){return{name:``,url:``,events:new Set,scope:{kind:`global`},secret:``,headersText:``,insecureTls:!1,enabled:!0}}function Aj(e){return{id:e.id,name:e.name,url:e.url,events:new Set(e.events),scope:e.scope,secret:``,headersText:e.headers===void 0?``:Object.entries(e.headers).map(([e,t])=>`${e}: ${t}`).join(`
|
|
358
|
+
`),insecureTls:e.insecureTls===!0,enabled:e.enabled}}function jj(e){let t={};for(let n of e.split(`
|
|
359
|
+
`)){let e=n.trim();if(e.length===0)continue;let r=e.indexOf(`:`);if(r===-1)continue;let i=e.slice(0,r).trim(),a=e.slice(r+1).trim();i.length!==0&&(t[i]=a)}return Object.keys(t).length===0?void 0:t}function Mj({onError:e}){let t=ur(e=>e.projects),[n,r]=(0,v.useState)([]),[i,a]=(0,v.useState)(!0),[o,s]=(0,v.useState)(void 0),[c,l]=(0,v.useState)(!1),[u,d]=(0,v.useState)(),[f,p]=(0,v.useState)(),m=(0,v.useCallback)(async()=>{e(void 0),a(!0);try{let{webhooks:e}=await L.listWebhooks();r(e)}catch(t){e(t instanceof N?t.code:t.message)}finally{a(!1)}},[e]);(0,v.useEffect)(()=>{m()},[m]);let h=async()=>{if(o===void 0)return;let t=Array.from(o.events);if(o.name.trim().length===0){e(`name_required`);return}if(o.url.trim().length===0){e(`url_required`);return}if(t.length===0){e(`no_events`);return}l(!0),e(void 0);try{let e={name:o.name.trim(),url:o.url.trim(),events:t,scope:o.scope,enabled:o.enabled};o.secret.length>0&&(e.secret=o.secret);let n=jj(o.headersText);if(n!==void 0&&(e.headers=n),o.insecureTls&&(e.insecureTls=!0),o.id===void 0)await L.createWebhook(e);else{let t={name:e.name,url:e.url,events:e.events,scope:e.scope,enabled:o.enabled,headers:n??{},insecureTls:o.insecureTls};o.secret.length>0&&(t.secret=o.secret),await L.updateWebhook(o.id,t)}s(void 0),await m()}catch(t){e(t instanceof N?`${t.code}: ${t.message??``}`:t.message)}finally{l(!1)}},g=async t=>{e(void 0);try{await L.deleteWebhook(t),d(void 0),await m()}catch(t){e(t instanceof N?t.code:t.message)}},_=async t=>{e(void 0);try{await L.testWebhook(t),p(t)}catch(t){e(t instanceof N?t.code:t.message)}};return i?(0,R.jsx)(`p`,{className:`px-4 py-6 text-sm text-neutral-400`,children:`Loading…`}):(0,R.jsxs)(`div`,{className:`space-y-3 px-4 py-3`,children:[(0,R.jsxs)(`header`,{className:`flex items-center justify-between`,children:[(0,R.jsxs)(`p`,{className:`text-sm text-neutral-400`,children:[`Webhooks fire HTTP POSTs to URLs you configure when agent or session events happen. Useful for Slack notifications, CI integrations, audit logs, etc. Stored at`,` `,(0,R.jsx)(`code`,{className:`font-mono text-xs`,children:`$FORGE_DATA_DIR/webhooks.json`}),`.`]}),o===void 0&&(0,R.jsx)(`button`,{type:`button`,onClick:()=>s(kj()),className:`shrink-0 rounded bg-neutral-100 px-3 py-1 text-xs font-medium text-neutral-900`,children:`+ New webhook`})]}),o!==void 0&&(0,R.jsx)(Nj,{draft:o,projects:t.map(e=>({id:e.id,name:e.name})),submitting:c,onChange:s,onCancel:()=>s(void 0),onSave:()=>void h()}),n.length===0?(0,R.jsx)(`p`,{className:`rounded border border-dashed border-neutral-700 px-4 py-6 text-center text-sm italic text-neutral-500`,children:`No webhooks configured.`}):(0,R.jsx)(`ul`,{className:`space-y-2`,children:n.map(e=>(0,R.jsx)(Pj,{webhook:e,projects:t.map(e=>({id:e.id,name:e.name})),isPendingDelete:u===e.id,isExpanded:f===e.id,onArmDelete:()=>d(e.id),onCancelDelete:()=>d(void 0),onConfirmDelete:()=>void g(e.id),onEdit:()=>s(Aj(e)),onTest:()=>void _(e.id),onToggleDeliveries:()=>p(t=>t===e.id?void 0:e.id)},e.id))})]})}function Nj({draft:e,projects:t,submitting:n,onChange:r,onCancel:i,onSave:a}){let o=e.id!==void 0,s=t=>r({...e,...t}),c=t=>{let n=new Set(e.events);n.has(t)?n.delete(t):n.add(t),s({events:n})};return(0,R.jsxs)(`div`,{className:`space-y-3 rounded-md border border-neutral-700 bg-neutral-950 p-3`,children:[(0,R.jsx)(`header`,{className:`text-xs uppercase tracking-wider text-neutral-400`,children:o?`Edit webhook`:`New webhook`}),(0,R.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,R.jsxs)(`label`,{className:`block space-y-1`,children:[(0,R.jsx)(`span`,{className:`text-xs text-neutral-300`,children:`Name`}),(0,R.jsx)(`input`,{value:e.name,onChange:e=>s({name:e.target.value}),placeholder:`my-slack-channel`,disabled:n,className:`w-full rounded border border-neutral-700 bg-neutral-900 px-2 py-1 text-sm outline-none focus:border-neutral-500`})]}),(0,R.jsxs)(`label`,{className:`block space-y-1`,children:[(0,R.jsx)(`span`,{className:`text-xs text-neutral-300`,children:`URL (HTTPS only)`}),(0,R.jsx)(`input`,{value:e.url,onChange:e=>s({url:e.target.value}),placeholder:`https://hooks.slack.com/...`,disabled:n,className:`w-full rounded border border-neutral-700 bg-neutral-900 px-2 py-1 font-mono text-xs outline-none focus:border-neutral-500`})]})]}),(0,R.jsxs)(`fieldset`,{className:`space-y-1`,children:[(0,R.jsx)(`legend`,{className:`text-xs text-neutral-300`,children:`Events`}),(0,R.jsx)(`div`,{className:`grid grid-cols-1 gap-1 sm:grid-cols-2`,children:kn.map(t=>(0,R.jsxs)(`label`,{className:`flex items-start gap-2 rounded border border-neutral-800 px-2 py-1.5 hover:border-neutral-600`,children:[(0,R.jsx)(`input`,{type:`checkbox`,checked:e.events.has(t),onChange:()=>c(t),disabled:n,className:`mt-0.5`}),(0,R.jsxs)(`span`,{className:`flex flex-col text-[11px]`,children:[(0,R.jsx)(`span`,{className:`text-neutral-200`,children:Oj[t]}),(0,R.jsx)(`code`,{className:`font-mono text-[10px] text-neutral-500`,children:t})]})]},t))})]}),(0,R.jsxs)(`fieldset`,{className:`space-y-1`,children:[(0,R.jsx)(`legend`,{className:`text-xs text-neutral-300`,children:`Scope`}),(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 text-xs`,children:[(0,R.jsxs)(`label`,{className:`flex items-center gap-1`,children:[(0,R.jsx)(`input`,{type:`radio`,checked:e.scope.kind===`global`,onChange:()=>s({scope:{kind:`global`}}),disabled:n}),(0,R.jsx)(`span`,{children:`Global (every project)`})]}),(0,R.jsxs)(`label`,{className:`flex items-center gap-1`,children:[(0,R.jsx)(`input`,{type:`radio`,checked:e.scope.kind===`project`,onChange:()=>s({scope:{kind:`project`,projectId:t[0]?.id??``}}),disabled:n||t.length===0}),(0,R.jsx)(`span`,{children:`Specific project:`}),(0,R.jsx)(`select`,{value:e.scope.kind===`project`?e.scope.projectId:``,onChange:e=>s({scope:{kind:`project`,projectId:e.target.value}}),disabled:n||e.scope.kind!==`project`,className:`rounded border border-neutral-700 bg-neutral-900 px-2 py-0.5`,children:t.map(e=>(0,R.jsx)(`option`,{value:e.id,children:e.name},e.id))})]})]})]}),(0,R.jsxs)(`label`,{className:`block space-y-1`,children:[(0,R.jsxs)(`span`,{className:`text-xs text-neutral-300`,children:[`HMAC secret (optional)`,` `,o&&(0,R.jsx)(`span`,{className:`text-neutral-500`,children:`— leave blank to keep the existing secret`})]}),(0,R.jsx)(`input`,{type:`password`,value:e.secret,onChange:e=>s({secret:e.target.value}),placeholder:o?`(unchanged)`:`shared secret for X-Pi-Forge-Signature`,disabled:n,className:`w-full rounded border border-neutral-700 bg-neutral-900 px-2 py-1 font-mono text-xs outline-none focus:border-neutral-500`})]}),(0,R.jsxs)(`label`,{className:`block space-y-1`,children:[(0,R.jsxs)(`span`,{className:`text-xs text-neutral-300`,children:[`Custom headers (optional, one per line, `,(0,R.jsx)(`code`,{children:`Name: value`}),`)`]}),(0,R.jsx)(`textarea`,{rows:3,value:e.headersText,onChange:e=>s({headersText:e.target.value}),placeholder:`Authorization: Bearer xxx
|
|
360
|
+
X-Custom: value`,disabled:n,className:`w-full rounded border border-neutral-700 bg-neutral-900 px-2 py-1 font-mono text-xs outline-none focus:border-neutral-500`}),o&&(0,R.jsxs)(`span`,{className:`block text-[11px] text-neutral-500`,children:[`Stored values are masked as `,(0,R.jsx)(`code`,{className:`font-mono`,children:`***REDACTED***`}),` for safety. Leave any line with the sentinel intact to keep the original value; replace it to update; delete the line to remove the header.`]})]}),(0,R.jsxs)(`label`,{className:`flex items-start gap-2 rounded border border-amber-900/40 bg-amber-950/30 px-2 py-1.5 text-xs light:border-amber-300 light:bg-amber-50`,children:[(0,R.jsx)(`input`,{type:`checkbox`,checked:e.insecureTls,onChange:e=>s({insecureTls:e.target.checked}),disabled:n,className:`mt-0.5`}),(0,R.jsxs)(`span`,{children:[(0,R.jsx)(`span`,{className:`text-amber-200 light:text-amber-800`,children:`Allow self-signed / invalid TLS certificate`}),(0,R.jsx)(`br`,{}),(0,R.jsx)(`span`,{className:`text-[11px] text-amber-300/70 light:text-amber-700/80`,children:`⚠ Disables MITM protection. Use only for internal hosts with known self-signed certs. Every fire logs to stderr so the relaxed security is visible in operator logs.`})]})]}),(0,R.jsxs)(`label`,{className:`flex items-center gap-2 text-xs`,children:[(0,R.jsx)(`input`,{type:`checkbox`,checked:e.enabled,onChange:e=>s({enabled:e.target.checked}),disabled:n}),(0,R.jsx)(`span`,{children:`Enabled (disable to pause without losing config)`})]}),(0,R.jsxs)(`footer`,{className:`flex justify-end gap-2 pt-1`,children:[(0,R.jsx)(`button`,{type:`button`,onClick:i,disabled:n,className:`rounded border border-neutral-700 px-3 py-1 text-xs text-neutral-300 hover:bg-neutral-800 disabled:opacity-50`,children:`Cancel`}),(0,R.jsx)(`button`,{type:`button`,onClick:a,disabled:n,className:`rounded bg-neutral-100 px-3 py-1 text-xs font-medium text-neutral-900 disabled:opacity-50`,children:n?`Saving…`:o?`Save changes`:`Create webhook`})]})]})}function Pj({webhook:e,projects:t,isPendingDelete:n,isExpanded:r,onArmDelete:i,onCancelDelete:a,onConfirmDelete:o,onEdit:s,onTest:c,onToggleDeliveries:l}){let u=e.scope.kind===`global`?`Global`:`Project: ${t.find(t=>t.id===e.scope.kind&&t.id===e.scope.projectId)?.name??e.scope.projectId}`;return(0,R.jsxs)(`li`,{className:`rounded-md border ${e.enabled?`border-neutral-800`:`border-neutral-800/60 opacity-60`} bg-neutral-900`,children:[(0,R.jsxs)(`div`,{className:`flex items-start gap-2 px-3 py-2`,children:[(0,R.jsx)(`button`,{type:`button`,onClick:l,className:`mt-0.5 text-neutral-500 hover:text-neutral-300`,"aria-label":r?`Hide deliveries`:`Show recent deliveries`,children:r?(0,R.jsx)(ue,{size:14}):(0,R.jsx)(fe,{size:14})}),(0,R.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,R.jsx)(`span`,{className:`truncate text-sm font-medium text-neutral-100`,children:e.name}),(0,R.jsx)(`span`,{className:`rounded px-1.5 py-0.5 text-[10px] uppercase tracking-wider ${e.enabled?`bg-emerald-900/40 text-emerald-300`:`bg-neutral-800 text-neutral-400`}`,children:e.enabled?`enabled`:`disabled`}),(0,R.jsx)(`span`,{className:`rounded bg-neutral-800 px-1.5 py-0.5 text-[10px] uppercase tracking-wider text-neutral-300`,children:u}),e.hasSecret&&(0,R.jsx)(`span`,{className:`rounded bg-sky-900/40 px-1.5 py-0.5 text-[10px] uppercase tracking-wider text-sky-300`,children:`signed`}),e.insecureTls===!0&&(0,R.jsx)(`span`,{className:`rounded bg-amber-900/40 px-1.5 py-0.5 text-[10px] uppercase tracking-wider text-amber-300`,title:`TLS cert validation disabled for this webhook`,children:`insecure TLS`})]}),(0,R.jsx)(`div`,{className:`mt-0.5 truncate font-mono text-[11px] text-neutral-500`,children:e.url}),(0,R.jsx)(`div`,{className:`mt-0.5 font-mono text-[10px] text-neutral-500`,children:e.events.join(` · `)})]}),(0,R.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[(0,R.jsxs)(`button`,{type:`button`,onClick:c,className:`rounded border border-neutral-700 px-2 py-1 text-[11px] text-neutral-300 hover:bg-neutral-800`,title:`Fire a synthetic webhook.test event at this webhook`,children:[(0,R.jsx)(Je,{size:12,className:`mr-1 inline`}),`Test`]}),(0,R.jsx)(`button`,{type:`button`,onClick:s,className:`rounded border border-neutral-700 px-2 py-1 text-[11px] text-neutral-300 hover:bg-neutral-800`,children:`Edit`}),n?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`button`,{type:`button`,onClick:o,className:`rounded bg-red-700 px-2 py-1 text-[11px] font-medium text-red-50`,children:`Confirm`}),(0,R.jsx)(`button`,{type:`button`,onClick:a,className:`rounded border border-neutral-700 px-2 py-1 text-[11px] text-neutral-300 hover:bg-neutral-800`,children:`Cancel`})]}):(0,R.jsx)(`button`,{type:`button`,onClick:i,className:`rounded border border-neutral-700 px-2 py-1 text-[11px] text-red-300 hover:bg-red-900/40`,title:`Delete this webhook`,"aria-label":`Delete this webhook`,children:(0,R.jsx)($e,{size:12})})]})]}),r&&(0,R.jsx)(Fj,{webhookId:e.id})]})}function Fj({webhookId:e}){let[t,n]=(0,v.useState)([]),[r,i]=(0,v.useState)(!0),[a,o]=(0,v.useState)(),s=(0,v.useCallback)(async()=>{i(!0),o(void 0);try{let{deliveries:t}=await L.listWebhookDeliveries(e);n(t)}catch(e){o(e instanceof N?e.code:e.message)}finally{i(!1)}},[e]);return(0,v.useEffect)(()=>{s();let e=window.setInterval(()=>void s(),3e3);return()=>window.clearInterval(e)},[s]),(0,R.jsxs)(`div`,{className:`border-t border-neutral-800 bg-neutral-950 px-3 py-2`,children:[(0,R.jsxs)(`div`,{className:`mb-1 flex items-center justify-between`,children:[(0,R.jsxs)(`span`,{className:`text-[11px] uppercase tracking-wider text-neutral-500`,children:[`Recent deliveries `,t.length>0&&`(${t.length})`]}),(0,R.jsx)(`button`,{type:`button`,onClick:()=>void s(),className:`rounded border border-neutral-700 px-1.5 py-0.5 text-[10px] text-neutral-300 hover:bg-neutral-800`,children:`Refresh`})]}),r&&(0,R.jsx)(`p`,{className:`text-xs text-neutral-500`,children:`Loading…`}),a!==void 0&&(0,R.jsx)(`p`,{className:`text-xs text-red-400`,children:a}),!r&&a===void 0&&t.length===0&&(0,R.jsx)(`p`,{className:`text-xs italic text-neutral-500`,children:`No deliveries yet.`}),t.length>0&&(0,R.jsx)(`ul`,{className:`space-y-1`,children:t.map(e=>(0,R.jsxs)(`li`,{className:`grid grid-cols-12 items-baseline gap-2 rounded bg-neutral-900 px-2 py-1 font-mono text-[10px]`,children:[(0,R.jsxs)(`span`,{className:`col-span-2 ${e.status===`delivered`?`text-emerald-400`:e.status===`failed`?`text-red-400`:`text-amber-400`}`,children:[e.status,e.statusCode===void 0?``:` ${e.statusCode}`]}),(0,R.jsx)(`span`,{className:`col-span-2 text-neutral-400`,children:e.event}),(0,R.jsxs)(`span`,{className:`col-span-1 text-neutral-500`,children:[`a`,e.attempt]}),(0,R.jsxs)(`span`,{className:`col-span-2 text-neutral-500`,children:[e.durationMs,`ms`]}),(0,R.jsx)(`span`,{className:`col-span-5 truncate text-neutral-500`,title:e.errorPreview??``,children:e.errorPreview??new Date(e.requestedAt).toLocaleString()})]},e.id))})]})}function Ij({onClose:e,initialTab:t}){let n=ci(e=>e.minimal),r=(0,v.useMemo)(()=>n?[`skills`,`prompts`,`systemPrompt`,`tools`,`quickActions`,`appearance`,`backup`,`general`]:[`providers`,`agent`,`mcp`,`tools`,`skills`,`prompts`,`systemPrompt`,`quickActions`,`webhooks`,`appearance`,`backup`,`general`],[n]),[i,a]=(0,v.useState)(t??(n?`skills`:`providers`));(0,v.useEffect)(()=>{r.includes(i)||a(r[0])},[r,i]),(0,v.useEffect)(()=>{t!==void 0&&r.includes(t)&&a(t)},[t,r]);let[o,s]=(0,v.useState)(void 0);return(0,R.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 px-4 py-8`,onClick:e,children:(0,R.jsxs)(`div`,{onClick:e=>e.stopPropagation(),className:`flex h-full max-h-[720px] w-full max-w-6xl flex-col overflow-hidden rounded-lg border border-neutral-800 bg-neutral-950 shadow-2xl`,children:[(0,R.jsxs)(`header`,{className:`flex items-center gap-3 border-b border-neutral-800 px-4 py-3`,children:[(0,R.jsx)(`div`,{className:`-mx-1 min-w-0 flex-1 overflow-x-auto px-1`,children:(0,R.jsx)(`div`,{className:`flex min-w-max items-center gap-1`,children:r.map(e=>(0,R.jsx)(`button`,{onClick:()=>a(e),className:`shrink-0 whitespace-nowrap rounded px-3 py-1 text-xs ${i===e?`bg-neutral-800 text-neutral-100`:`text-neutral-400 hover:bg-neutral-900 hover:text-neutral-200`}`,children:e===`providers`?`Providers`:e===`agent`?`Agent`:e===`mcp`?`MCP`:e===`tools`?`Tools`:e===`skills`?`Skills`:e===`prompts`?`Prompts`:e===`systemPrompt`?`System Prompt`:e===`quickActions`?`Quick Actions`:e===`webhooks`?`Webhooks`:e===`appearance`?`Appearance`:e===`backup`?`Backup`:`General`},e))})}),(0,R.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[(0,R.jsx)(`button`,{onClick:()=>{let e=Vt(),t=e===void 0?`/api/docs`:`/api/docs?token=${encodeURIComponent(e.token)}`;window.open(t,`_blank`,`noopener,noreferrer`)},className:`rounded border border-neutral-700 px-2 py-1 text-xs text-neutral-300 hover:border-neutral-500`,title:`Open the OpenAPI / Swagger UI in a new tab. Carries your auth token automatically.`,children:`API Docs ↗`}),(0,R.jsx)(`button`,{onClick:e,className:`rounded border border-neutral-700 px-2 py-1 text-xs text-neutral-300 hover:border-neutral-500`,title:`Close (Esc)`,children:`Close`})]})]}),o!==void 0&&(0,R.jsx)(`div`,{className:`border-b border-red-700/40 bg-red-900/20 px-4 py-2 text-xs text-red-300`,children:o}),(0,R.jsxs)(`div`,{className:`flex-1 overflow-y-auto px-4 py-3 text-sm text-neutral-200`,children:[i===`providers`&&(0,R.jsx)(Rj,{onError:s}),i===`agent`&&(0,R.jsx)(Bj,{onError:s}),i===`mcp`&&(0,R.jsx)(lM,{onError:s}),i===`tools`&&(0,R.jsx)(Qj,{onError:s}),i===`skills`&&(0,R.jsx)(qj,{onError:s}),i===`prompts`&&(0,R.jsx)(Jj,{onError:s}),i===`systemPrompt`&&(0,R.jsx)(eM,{onError:s}),i===`quickActions`&&(0,R.jsx)(nM,{onError:s}),i===`webhooks`&&(0,R.jsx)(Mj,{onError:s}),i===`appearance`&&(0,R.jsx)(rM,{}),i===`backup`&&(0,R.jsx)(aM,{onError:s}),i===`general`&&(0,R.jsx)(gM,{})]})]})})}function Lj(e){return e instanceof N?e.code:e.message}function Rj({onError:e}){let[t,n]=(0,v.useState)(void 0),[r,i]=(0,v.useState)(void 0),[a,o]=(0,v.useState)(void 0),[s,c]=(0,v.useState)(``),[l,u]=(0,v.useState)(!1),d=async()=>{e(void 0);try{let[e,t]=await Promise.all([L.getProviders(),L.getAuthSummary()]);n(e),i(t)}catch(t){e(`Failed to load providers: ${Lj(t)}`)}};(0,v.useEffect)(()=>{d()},[]);let f=async t=>{if(s.trim().length!==0){u(!0);try{await L.setApiKey(t,s.trim()),o(void 0),c(``),await d()}catch(t){e(`Save key failed: ${Lj(t)}`)}finally{u(!1)}}},p=async t=>{if(confirm(`Remove the stored key for "${t}"?`)){u(!0);try{await L.removeApiKey(t),await d()}catch(t){e(`Remove key failed: ${Lj(t)}`)}finally{u(!1)}}};return t===void 0?(0,R.jsx)(`p`,{className:`text-xs italic text-neutral-500`,children:`Loading providers…`}):(0,R.jsxs)(`div`,{className:`space-y-3`,children:[(0,R.jsxs)(`p`,{className:`text-xs text-neutral-500`,children:[`Built-in providers and anything in `,(0,R.jsx)(`code`,{className:`font-mono`,children:`models.json`}),`. Stored API keys are presence-only — actual values are never sent to the browser.`]}),t.providers.length===0&&(0,R.jsx)(`p`,{className:`text-xs italic text-neutral-500`,children:`No providers configured.`}),t.providers.map(e=>{let t=r?.providers[e.provider],n=t?.configured===!0,i=a===e.provider;return(0,R.jsxs)(`div`,{className:`rounded border border-neutral-800 bg-neutral-900/40 p-3`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,R.jsx)(`span`,{className:`font-mono text-sm text-neutral-100`,children:e.provider}),(0,R.jsx)(`span`,{className:`rounded px-1.5 py-0.5 text-[10px] uppercase tracking-wider ${n?`bg-emerald-900/40 text-emerald-300 light:bg-emerald-100 light:text-emerald-800`:`bg-neutral-800 text-neutral-500`}`,children:n?`key set`:`no key`}),t?.source!==void 0&&(0,R.jsxs)(`span`,{className:`text-[10px] text-neutral-500`,children:[`via `,t.source]})]}),(0,R.jsxs)(`div`,{className:`flex items-center gap-1 text-xs`,children:[!i&&(0,R.jsx)(`button`,{onClick:()=>{o(e.provider),c(``)},className:`rounded border border-neutral-700 px-2 py-0.5 text-neutral-300 hover:border-neutral-500`,children:n?`Replace key`:`Add key`}),n&&!i&&(0,R.jsx)(`button`,{onClick:()=>void p(e.provider),disabled:l,className:`rounded border border-red-700/50 px-2 py-0.5 text-red-300 hover:bg-red-900/20 disabled:opacity-50`,children:`Remove`})]})]}),i&&(0,R.jsxs)(`div`,{className:`mt-2 flex items-center gap-2`,children:[(0,R.jsx)(`input`,{type:`password`,value:s,onChange:e=>c(e.target.value),placeholder:`Paste API key`,autoFocus:!0,className:`flex-1 rounded border border-neutral-700 bg-neutral-950 px-2 py-1 text-xs text-neutral-100 outline-none focus:border-neutral-500`}),(0,R.jsx)(`button`,{onClick:()=>void f(e.provider),disabled:l||s.trim().length===0,className:`rounded bg-neutral-100 px-2 py-1 text-xs font-medium text-neutral-900 disabled:opacity-50`,children:`Save`}),(0,R.jsx)(`button`,{onClick:()=>{o(void 0),c(``)},className:`rounded border border-neutral-700 px-2 py-1 text-xs text-neutral-300`,children:`Cancel`})]}),(0,R.jsxs)(`details`,{className:`mt-2`,children:[(0,R.jsxs)(`summary`,{className:`cursor-pointer text-[11px] text-neutral-500 light:text-neutral-600`,children:[e.models.length,` model`,e.models.length===1?``:`s`]}),(0,R.jsx)(`ul`,{className:`mt-1 space-y-0.5 text-[11px]`,children:e.models.map(e=>(0,R.jsxs)(`li`,{className:`flex justify-between font-mono`,children:[(0,R.jsx)(`span`,{className:e.hasAuth?`text-neutral-300`:`text-neutral-600 light:text-neutral-400`,children:e.name}),(0,R.jsxs)(`span`,{className:`text-neutral-600 light:text-neutral-400`,children:[`ctx `,Math.round(e.contextWindow/1e3),`k`]})]},e.id))})]})]},e.provider)}),(0,R.jsx)(zj,{onError:e})]})}function zj({onError:e}){let[t,n]=(0,v.useState)(void 0),[r,i]=(0,v.useState)(!1),[a,o]=(0,v.useState)(void 0);Uj(a,()=>o(void 0));let s=async()=>{try{let e=await L.getModelsJson();n(JSON.stringify(e,null,2))}catch(t){e(`Load models.json failed: ${Lj(t)}`)}},c=async()=>{if(t===void 0)return;let n;try{n=JSON.parse(t)}catch{e(`models.json: invalid JSON`);return}if(typeof n!=`object`||!n||typeof n.providers!=`object`||n.providers===null){e(`models.json: top-level must be { "providers": { ... } }`);return}i(!0),o(void 0);try{await L.setModelsJson(n),e(void 0),o(Date.now())}catch(t){e(`Save failed: ${Lj(t)}`)}finally{i(!1)}};return(0,R.jsxs)(`details`,{className:`rounded border border-neutral-800 bg-neutral-900/40 p-3`,children:[(0,R.jsx)(`summary`,{className:`cursor-pointer text-xs text-neutral-300`,onClick:()=>{t===void 0&&s()},children:`Custom providers (models.json)`}),(0,R.jsx)(`p`,{className:`mt-1 text-[11px] text-neutral-500`,children:`Raw JSON editor. Add vLLM / LiteLLM / Ollama / OpenAI-compatible endpoints here. The SDK validates on next session creation.`}),t===void 0?(0,R.jsx)(`p`,{className:`mt-2 text-xs italic text-neutral-500`,children:`Loading…`}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`textarea`,{value:t,onChange:e=>n(e.target.value),spellCheck:!1,rows:10,className:`mt-2 w-full rounded border border-neutral-700 bg-neutral-950 px-2 py-1 font-mono text-[11px] text-neutral-100 outline-none focus:border-neutral-500`}),(0,R.jsxs)(`div`,{className:`mt-2 flex items-center justify-end gap-2 text-xs`,children:[a!==void 0&&(0,R.jsx)(`span`,{className:`text-emerald-400 light:text-emerald-700`,"aria-live":`polite`,children:`Saved`}),(0,R.jsx)(`button`,{onClick:()=>void s(),disabled:r,className:`rounded border border-neutral-700 px-2 py-1 text-neutral-300`,children:`Reload`}),(0,R.jsx)(`button`,{onClick:()=>void c(),disabled:r,className:`rounded bg-neutral-100 px-3 py-1 font-medium text-neutral-900 disabled:opacity-50`,children:r?`Saving…`:`Save`})]})]})]})}function Bj({onError:e}){let[t,n]=(0,v.useState)(void 0),[r,i]=(0,v.useState)(!1),[a,o]=(0,v.useState)(`form`),s=async()=>{e(void 0);try{n(await L.getSettings())}catch(t){e(`Failed to load settings: ${Lj(t)}`)}};(0,v.useEffect)(()=>{s()},[]);let c=e=>{if(t===void 0)return``;let n=t[e];return typeof n==`string`?n:``},l=async t=>{i(!0);try{n(await L.updateSettings(t))}catch(t){e(`Save failed: ${Lj(t)}`)}finally{i(!1)}};return t===void 0?(0,R.jsx)(`p`,{className:`text-xs italic text-neutral-500`,children:`Loading settings…`}):a===`json`?(0,R.jsx)(Vj,{initial:t,onSave:async r=>{let a={...r};for(let e of Object.keys(t))e in r||(a[e]=null);i(!0);try{n(await L.updateSettings(a)),e(void 0)}catch(t){throw e(`Save failed: ${Lj(t)}`),t}finally{i(!1)}},onSwitchToForm:()=>o(`form`),busy:r,onError:e}):(0,R.jsxs)(`div`,{className:`space-y-4`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,R.jsx)(`p`,{className:`text-xs text-neutral-500`,children:`Defaults for new sessions. The form covers common keys; switch to JSON to edit anything the SDK accepts.`}),(0,R.jsx)(`button`,{onClick:()=>o(`json`),className:`rounded border border-neutral-700 px-2 py-0.5 text-[11px] text-neutral-300 hover:border-neutral-500`,children:`Edit as JSON`})]}),(0,R.jsx)(Wj,{label:`Default provider`,hint:`e.g. anthropic, openai, google, custom`,children:(0,R.jsx)(Gj,{value:c(`defaultProvider`),onSave:e=>l({defaultProvider:e.length===0?null:e}),disabled:r})}),(0,R.jsx)(Wj,{label:`Default model`,hint:`model id from the chosen provider`,children:(0,R.jsx)(Gj,{value:c(`defaultModel`),onSave:e=>l({defaultModel:e.length===0?null:e}),disabled:r})}),(0,R.jsx)(Wj,{label:`Thinking level`,hint:`off, low, medium, high (provider-dependent)`,children:(0,R.jsx)(Kj,{value:c(`defaultThinkingLevel`),options:[``,`off`,`low`,`medium`,`high`],onSave:e=>l({defaultThinkingLevel:e.length===0?null:e}),disabled:r})})]})}function Vj({initial:e,onSave:t,onSwitchToForm:n,busy:r,onError:i}){let[a,o]=(0,v.useState)(()=>JSON.stringify(e,null,2)),[s,c]=(0,v.useState)(void 0);Uj(s,()=>c(void 0));let l=async()=>{let e;try{e=JSON.parse(a)}catch{i(`settings.json: invalid JSON`);return}if(typeof e!=`object`||!e||Array.isArray(e)){i(`settings.json: top-level must be an object`);return}c(void 0);try{await t(e),c(Date.now())}catch{}};return(0,R.jsxs)(`div`,{className:`space-y-2`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,R.jsxs)(`p`,{className:`text-[11px] text-neutral-500`,children:[`Raw `,(0,R.jsx)(`code`,{className:`font-mono`,children:`settings.json`}),`. Keys removed here are deleted on save (mapped to `,(0,R.jsx)(`code`,{className:`font-mono`,children:`null`}),` in the merge patch). The SDK validates on next session creation.`]}),(0,R.jsx)(`button`,{onClick:n,className:`rounded border border-neutral-700 px-2 py-0.5 text-[11px] text-neutral-300 hover:border-neutral-500`,children:`Back to form`})]}),(0,R.jsx)(`textarea`,{value:a,onChange:e=>o(e.target.value),spellCheck:!1,rows:18,className:`w-full rounded border border-neutral-700 bg-neutral-950 px-2 py-1 font-mono text-[11px] text-neutral-100 outline-none focus:border-neutral-500`}),(0,R.jsxs)(`div`,{className:`flex items-center justify-end gap-2 text-xs`,children:[s!==void 0&&(0,R.jsx)(`span`,{className:`text-emerald-400 light:text-emerald-700`,"aria-live":`polite`,children:`Saved`}),(0,R.jsx)(`button`,{onClick:()=>o(JSON.stringify(e,null,2)),disabled:r,className:`rounded border border-neutral-700 px-2 py-1 text-neutral-300`,children:`Reset`}),(0,R.jsx)(`button`,{onClick:()=>void l(),disabled:r,className:`rounded bg-neutral-100 px-3 py-1 font-medium text-neutral-900 disabled:opacity-50`,children:r?`Saving…`:`Save`})]})]})}var Hj=2500;function Uj(e,t){(0,v.useEffect)(()=>{if(e===void 0)return;let n=window.setTimeout(t,Hj);return()=>window.clearTimeout(n)},[e,t])}function Wj({label:e,hint:t,children:n}){return(0,R.jsxs)(`div`,{className:`space-y-1`,children:[(0,R.jsx)(`label`,{className:`block text-xs font-medium text-neutral-200`,children:e}),t!==void 0&&(0,R.jsx)(`p`,{className:`text-[11px] text-neutral-500`,children:t}),n]})}function Gj({value:e,onSave:t,disabled:n}){let[r,i]=(0,v.useState)(e);return(0,v.useEffect)(()=>i(e),[e]),(0,R.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,R.jsx)(`input`,{value:r,onChange:e=>i(e.target.value),disabled:n,className:`flex-1 rounded border border-neutral-700 bg-neutral-950 px-2 py-1 text-xs text-neutral-100 outline-none focus:border-neutral-500`}),(0,R.jsx)(`button`,{onClick:()=>void t(r),disabled:n||r===e,className:`rounded bg-neutral-100 px-2 py-1 text-xs font-medium text-neutral-900 disabled:opacity-50`,children:`Save`})]})}function Kj({value:e,options:t,onSave:n,disabled:r}){return(0,R.jsx)(`select`,{value:e,disabled:r,onChange:e=>void n(e.target.value),className:`rounded border border-neutral-700 bg-neutral-950 px-2 py-1 text-xs text-neutral-100`,children:t.map(e=>(0,R.jsx)(`option`,{value:e,children:e.length===0?`(unset)`:e},e))})}function qj({onError:e}){let t=dr(),n=ur(e=>e.projects),[r,i]=(0,v.useState)(void 0),[a,o]=(0,v.useState)([]),[s,c]=(0,v.useState)({}),[l,u]=(0,v.useState)({}),[d,f]=(0,v.useState)(!1),p=async()=>{if(t!==void 0){e(void 0);try{let[{skills:e,diagnostics:n},r]=await Promise.all([L.listSkills(t.id),L.listSkillOverrides()]);i(e),o(n),c(r.projects)}catch(t){e(`Failed to load skills: ${Lj(t)}`)}}};if((0,v.useEffect)(()=>{p()},[t?.id]),t===void 0)return(0,R.jsx)(`p`,{className:`text-xs italic text-neutral-500`,children:`Pick a project from the header to manage its skills.`});if(r===void 0)return(0,R.jsxs)(`p`,{className:`text-xs italic text-neutral-500`,children:[`Loading skills for `,t.name,`…`]});let m=async(n,r)=>{f(!0);try{let{skills:e}=await L.setSkillEnabled(t.id,n,r,`global`);i(e)}catch(t){e(`Toggle failed: ${Lj(t)}`)}finally{f(!1)}},h=async(t,n,r)=>{f(!0);try{r===void 0?await L.clearSkillProjectOverride(t,n):await L.setSkillEnabled(t,n,r===`enabled`,`project`),await p()}catch(t){e(`Override write failed: ${Lj(t)}`)}finally{f(!1)}},g=(e,t)=>{let n=s[e];if(n!==void 0){if(n.enable.includes(t))return`enabled`;if(n.disable.includes(t))return`disabled`}};return(0,R.jsxs)(`div`,{className:`space-y-2`,children:[(0,R.jsxs)(`p`,{className:`text-xs text-neutral-500`,children:[`Skills discovered in `,(0,R.jsx)(`code`,{className:`font-mono`,children:`~/.pi/agent/skills/`}),` and`,` `,(0,R.jsxs)(`code`,{className:`font-mono`,children:[t.path,`/.pi/skills/`]}),`. The global toggle writes to pi's `,(0,R.jsx)(`code`,{className:`font-mono`,children:`settings.skills`}),`; per-project overrides write to the pi-forge-private file at`,` `,(0,R.jsx)(`code`,{className:`font-mono`,children:"${FORGE_DATA_DIR}/skills-overrides.json"}),`.`]}),(0,R.jsxs)(`div`,{className:`rounded border border-amber-700/40 bg-amber-900/10 px-3 py-2 text-[11px] text-amber-200 light:border-amber-300 light:bg-amber-50 light:text-amber-800`,children:[`Skill changes apply to the `,(0,R.jsx)(`strong`,{children:`next session`}),` you start in the affected project. Live sessions keep the skill set they booted with — start a new session to use a freshly enabled skill.`]}),a.length>0&&(0,R.jsx)(Yj,{diagnostics:a}),r.length===0&&(0,R.jsx)(`p`,{className:`text-xs italic text-neutral-500`,children:`No skills found for this project.`}),r.map(e=>{let r=`${e.source}:${e.name}`,i=l[r]===!0,a=n.map(t=>({project:t,state:g(t.id,e.name)})).filter(e=>e.state!==void 0),o=n.filter(t=>g(t.id,e.name)===void 0);return(0,R.jsxs)(`div`,{className:`rounded border border-neutral-800 bg-neutral-900/40`,children:[(0,R.jsxs)(`div`,{className:`flex items-start gap-3 p-3`,children:[(0,R.jsx)(`span`,{className:`mt-1.5 inline-block h-2.5 w-2.5 rounded-full ${e.effective?`bg-emerald-500`:`bg-neutral-700`}`,title:`Effective for ${t.name}: ${e.effective?`enabled`:`disabled`}`}),(0,R.jsxs)(`div`,{className:`flex-1 space-y-0.5`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,R.jsx)(`span`,{className:`font-mono text-neutral-100`,children:e.name}),(0,R.jsx)(`span`,{className:`rounded bg-neutral-800 px-1.5 py-0.5 text-[10px] uppercase tracking-wider text-neutral-400`,children:e.source}),e.projectOverride!==void 0&&(0,R.jsxs)(`span`,{className:`rounded px-1.5 py-0.5 text-[10px] uppercase tracking-wider ${e.projectOverride===`enabled`?`bg-emerald-900/40 text-emerald-300 light:bg-emerald-100 light:text-emerald-800`:`bg-red-900/40 text-red-300 light:bg-red-100 light:text-red-800`}`,title:`Active project ('${t.name}') has an override`,children:[`Project: `,e.projectOverride]})]}),(0,R.jsx)(`p`,{className:`text-xs text-neutral-400`,children:e.description||`(no description)`}),(0,R.jsx)(`p`,{className:`font-mono text-[10px] text-neutral-600`,children:e.filePath})]}),(0,R.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1 text-xs`,children:[(0,R.jsxs)(`button`,{onClick:()=>void m(e.name,!e.enabled),disabled:d,className:`rounded border px-2 py-0.5 ${e.enabled?`border-emerald-700/50 bg-emerald-900/20 text-emerald-300 light:border-emerald-300 light:bg-emerald-50 light:text-emerald-800`:`border-neutral-700 text-neutral-300 hover:border-neutral-500`}`,title:`Global enable in pi's settings.skills`,children:[`Global: `,e.enabled?`enabled`:`disabled`]}),(0,R.jsx)(`button`,{onClick:()=>u(e=>({...e,[r]:!i})),className:`rounded border border-neutral-700 px-2 py-0.5 text-neutral-300 hover:border-neutral-500`,title:`Show per-project overrides`,children:i?`▾ Overrides`:`▸ Overrides (${a.length})`})]})]}),i&&(0,R.jsxs)(`div`,{className:`border-t border-neutral-800 px-3 py-2`,children:[a.length===0?(0,R.jsx)(`p`,{className:`mb-2 text-[11px] italic text-neutral-500`,children:`No project overrides yet — every project inherits the global state.`}):(0,R.jsx)(`div`,{className:`mb-2 space-y-1`,children:a.map(({project:t,state:n})=>(0,R.jsxs)(`div`,{className:`flex items-center justify-between gap-2 rounded bg-neutral-900/60 px-2 py-1 text-xs`,children:[(0,R.jsx)(`span`,{className:`truncate text-neutral-200`,title:t.path,children:t.name}),(0,R.jsx)(Xj,{value:n,disabled:d,onChange:n=>void h(t.id,e.name,n)})]},t.id))}),o.length>0&&(0,R.jsx)(Zj,{projects:o,disabled:d,onAdd:(t,n)=>void h(t,e.name,n)})]})]},r)})]})}function Jj({onError:e}){let t=dr(),n=ur(e=>e.projects),r=QA(e=>e.bumpPromptsRefresh),[i,a]=(0,v.useState)(void 0),[o,s]=(0,v.useState)([]),[c,l]=(0,v.useState)({}),[u,d]=(0,v.useState)({}),[f,p]=(0,v.useState)(!1),m=async()=>{if(t!==void 0){e(void 0);try{let[{prompts:e,diagnostics:n},r]=await Promise.all([L.listPrompts(t.id),L.listPromptOverrides()]);a(e),s(n),l(r.projects)}catch(t){e(`Failed to load prompts: ${Lj(t)}`)}}};if((0,v.useEffect)(()=>{m()},[t?.id]),t===void 0)return(0,R.jsx)(`p`,{className:`text-xs italic text-neutral-500`,children:`Pick a project from the header to manage its prompts.`});if(i===void 0)return(0,R.jsxs)(`p`,{className:`text-xs italic text-neutral-500`,children:[`Loading prompts for `,t.name,`…`]});let h=async(n,i)=>{p(!0);try{let{prompts:e}=await L.setPromptEnabled(t.id,n,i,`global`);a(e),r()}catch(t){e(`Toggle failed: ${Lj(t)}`)}finally{p(!1)}},g=async(t,n,i)=>{p(!0);try{i===void 0?await L.clearPromptProjectOverride(t,n):await L.setPromptEnabled(t,n,i===`enabled`,`project`),await m(),r()}catch(t){e(`Override write failed: ${Lj(t)}`)}finally{p(!1)}},_=(e,t)=>{let n=c[e];if(n!==void 0){if(n.enable.includes(t))return`enabled`;if(n.disable.includes(t))return`disabled`}};return(0,R.jsxs)(`div`,{className:`space-y-2`,children:[(0,R.jsxs)(`p`,{className:`text-xs text-neutral-500`,children:[`Pi prompt templates discovered in `,(0,R.jsx)(`code`,{className:`font-mono`,children:`~/.pi/agent/prompts/`}),` `,`and `,(0,R.jsxs)(`code`,{className:`font-mono`,children:[t.path,`/.pi/prompts/`]}),`. Invoke from the chat input via `,(0,R.jsx)(`code`,{className:`font-mono`,children:`/<name>`}),`; the global toggle writes to pi's `,(0,R.jsx)(`code`,{className:`font-mono`,children:`settings.prompts`}),`; per-project overrides write to `,(0,R.jsx)(`code`,{className:`font-mono`,children:"${FORGE_DATA_DIR}/prompts-overrides.json"}),`.`]}),(0,R.jsxs)(`div`,{className:`rounded border border-amber-700/40 bg-amber-900/10 px-3 py-2 text-[11px] text-amber-200 light:border-amber-300 light:bg-amber-50 light:text-amber-800`,children:[`Prompt changes apply to the `,(0,R.jsx)(`strong`,{children:`next session`}),` you start in the affected project. Live sessions keep the prompt set they booted with — start a new session to use a freshly enabled prompt.`]}),o.length>0&&(0,R.jsx)(Yj,{diagnostics:o}),i.length===0&&(0,R.jsx)(`p`,{className:`text-xs italic text-neutral-500`,children:`No prompts found for this project.`}),i.map(e=>{let r=`${e.source}:${e.name}`,i=u[r]===!0,a=n.map(t=>({project:t,state:_(t.id,e.name)})).filter(e=>e.state!==void 0),o=n.filter(t=>_(t.id,e.name)===void 0);return(0,R.jsxs)(`div`,{className:`rounded border border-neutral-800 bg-neutral-900/40`,children:[(0,R.jsxs)(`div`,{className:`flex items-start gap-3 p-3`,children:[(0,R.jsx)(`span`,{className:`mt-1.5 inline-block h-2.5 w-2.5 rounded-full ${e.effective?`bg-emerald-500`:`bg-neutral-700`}`,title:`Effective for ${t.name}: ${e.effective?`enabled`:`disabled`}`}),(0,R.jsxs)(`div`,{className:`flex-1 space-y-0.5`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,R.jsxs)(`span`,{className:`font-mono text-neutral-100`,children:[`/`,e.name]}),(0,R.jsx)(`span`,{className:`rounded bg-neutral-800 px-1.5 py-0.5 text-[10px] uppercase tracking-wider text-neutral-400`,children:e.source}),e.argumentHint!==void 0&&(0,R.jsx)(`span`,{className:`rounded bg-neutral-800/60 px-1.5 py-0.5 font-mono text-[10px] text-neutral-300`,title:`Argument hint from the prompt's frontmatter`,children:e.argumentHint}),e.projectOverride!==void 0&&(0,R.jsxs)(`span`,{className:`rounded px-1.5 py-0.5 text-[10px] uppercase tracking-wider ${e.projectOverride===`enabled`?`bg-emerald-900/40 text-emerald-300 light:bg-emerald-100 light:text-emerald-800`:`bg-red-900/40 text-red-300 light:bg-red-100 light:text-red-800`}`,title:`Active project ('${t.name}') has an override`,children:[`Project: `,e.projectOverride]})]}),(0,R.jsx)(`p`,{className:`text-xs text-neutral-400`,children:e.description||`(no description)`}),(0,R.jsx)(`p`,{className:`font-mono text-[10px] text-neutral-600`,children:e.filePath})]}),(0,R.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1 text-xs`,children:[(0,R.jsxs)(`button`,{onClick:()=>void h(e.name,!e.enabled),disabled:f,className:`rounded border px-2 py-0.5 ${e.enabled?`border-emerald-700/50 bg-emerald-900/20 text-emerald-300 light:border-emerald-300 light:bg-emerald-50 light:text-emerald-800`:`border-neutral-700 text-neutral-300 hover:border-neutral-500`}`,title:`Global enable in pi's settings.prompts`,children:[`Global: `,e.enabled?`enabled`:`disabled`]}),(0,R.jsx)(`button`,{onClick:()=>d(e=>({...e,[r]:!i})),className:`rounded border border-neutral-700 px-2 py-0.5 text-neutral-300 hover:border-neutral-500`,title:`Show per-project overrides`,children:i?`▾ Overrides`:`▸ Overrides (${a.length})`})]})]}),i&&(0,R.jsxs)(`div`,{className:`border-t border-neutral-800 px-3 py-2`,children:[a.length===0?(0,R.jsx)(`p`,{className:`mb-2 text-[11px] italic text-neutral-500`,children:`No project overrides yet — every project inherits the global state.`}):(0,R.jsx)(`div`,{className:`mb-2 space-y-1`,children:a.map(({project:t,state:n})=>(0,R.jsxs)(`div`,{className:`flex items-center justify-between gap-2 rounded bg-neutral-900/60 px-2 py-1 text-xs`,children:[(0,R.jsx)(`span`,{className:`truncate text-neutral-200`,title:t.path,children:t.name}),(0,R.jsx)(Xj,{value:n,disabled:f,onChange:n=>void g(t.id,e.name,n)})]},t.id))}),o.length>0&&(0,R.jsx)(Zj,{projects:o,disabled:f,onAdd:(t,n)=>void g(t,e.name,n)})]})]},r)})]})}function Yj({diagnostics:e}){return(0,R.jsxs)(`div`,{className:`space-y-1 rounded border border-red-700/40 bg-red-900/10 px-3 py-2 text-[11px] text-red-200`,children:[(0,R.jsxs)(`p`,{className:`font-medium`,children:[e.length,` skill `,e.length===1?`file`:`files`,` were not loaded:`]}),(0,R.jsx)(`ul`,{className:`space-y-1.5`,children:e.map((e,t)=>(0,R.jsxs)(`li`,{className:`border-l-2 border-red-700/60 pl-2`,children:[(0,R.jsxs)(`div`,{className:`text-red-100`,children:[(0,R.jsx)(`span`,{className:`rounded bg-red-900/40 px-1 py-0.5 text-[10px] uppercase tracking-wider text-red-300`,children:e.type}),` `,e.message]}),e.collision!==void 0&&(0,R.jsxs)(`div`,{className:`mt-0.5 font-mono text-[10px] text-red-300/80`,children:[(0,R.jsxs)(`div`,{children:[`loser:\xA0\xA0`,(0,R.jsx)(`span`,{className:`text-red-200`,children:e.collision.loserPath})]}),(0,R.jsxs)(`div`,{children:[`winner:\xA0`,(0,R.jsx)(`span`,{className:`text-red-200`,children:e.collision.winnerPath})]}),(0,R.jsxs)(`div`,{className:`mt-1 text-red-300/70`,children:[`Add `,(0,R.jsxs)(`code`,{className:`rounded bg-red-900/40 px-1`,children:[`name: `,`<unique>`]}),` to the loser's frontmatter, or move it to`,` `,(0,R.jsx)(`code`,{className:`rounded bg-red-900/40 px-1`,children:`<unique>/SKILL.md`}),` so the parent dir name disambiguates.`]})]}),e.collision===void 0&&e.path!==void 0&&(0,R.jsx)(`div`,{className:`mt-0.5 font-mono text-[10px] text-red-300/80`,children:e.path})]},t))})]})}function Xj({value:e,disabled:t,onChange:n}){let r=(e,r,i)=>(0,R.jsx)(`button`,{onClick:()=>n(r),disabled:t,className:`rounded px-2 py-0.5 text-[11px] ${i?r===`enabled`?`bg-emerald-900/40 text-emerald-300 light:bg-emerald-100 light:text-emerald-800`:r===`disabled`?`bg-red-900/40 text-red-300 light:bg-red-100 light:text-red-800`:`bg-neutral-800 text-neutral-400`:`text-neutral-500 hover:bg-neutral-800 hover:text-neutral-300`}`,children:e});return(0,R.jsxs)(`div`,{className:`flex shrink-0 items-center gap-0.5 rounded border border-neutral-700 px-0.5`,children:[r(`Inherit`,void 0,e===void 0),r(`Enabled`,`enabled`,e===`enabled`),r(`Disabled`,`disabled`,e===`disabled`)]})}function Zj({projects:e,disabled:t,onAdd:n}){let[r,i]=(0,v.useState)(!1),[a,o]=(0,v.useState)(``);return r?(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1 text-[11px]`,children:[(0,R.jsxs)(`select`,{value:a,onChange:e=>o(e.target.value),className:`rounded border border-neutral-700 bg-neutral-950 px-2 py-0.5 text-neutral-100 outline-none focus:border-neutral-500`,children:[(0,R.jsx)(`option`,{value:``,children:`Pick project…`}),e.map(e=>(0,R.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,R.jsx)(`button`,{onClick:()=>{a.length!==0&&(n(a,`enabled`),i(!1),o(``))},disabled:t||a.length===0,className:`rounded bg-emerald-900/40 px-2 py-0.5 text-emerald-300 disabled:opacity-50 light:bg-emerald-100 light:text-emerald-800`,children:`Enable here`}),(0,R.jsx)(`button`,{onClick:()=>{a.length!==0&&(n(a,`disabled`),i(!1),o(``))},disabled:t||a.length===0,className:`rounded bg-red-900/40 px-2 py-0.5 text-red-300 disabled:opacity-50`,children:`Disable here`}),(0,R.jsx)(`button`,{onClick:()=>{i(!1),o(``)},className:`rounded border border-neutral-700 px-2 py-0.5 text-neutral-400 hover:border-neutral-500`,children:`Cancel`})]}):(0,R.jsx)(`button`,{onClick:()=>i(!0),disabled:t,className:`rounded border border-neutral-700 px-2 py-0.5 text-[11px] text-neutral-300 hover:border-neutral-500`,children:`+ Add override for…`})}function Qj({onError:e}){let t=ur(e=>e.projects),[n,r]=(0,v.useState)(void 0),[i,a]=(0,v.useState)({}),[o,s]=(0,v.useState)(!1),c=async()=>{e(void 0);try{let[e,t]=await Promise.all([L.listTools(),L.listToolOverrides()]);r(e),a(t.projects)}catch(t){e(`Failed to load tools: ${Lj(t)}`)}};(0,v.useEffect)(()=>{c()},[]);let l=async(t,n,r)=>{s(!0);try{await L.setToolEnabled(t,n,r,`global`),await c()}catch(t){e(`Toggle failed: ${Lj(t)}`)}finally{s(!1)}},u=async(t,n,r,i)=>{s(!0);try{i===void 0?await L.clearToolProjectOverride(t,r,n):await L.setToolEnabled(t,r,i===`enabled`,`project`,n),await c()}catch(t){e(`Override write failed: ${Lj(t)}`)}finally{s(!1)}};return n===void 0?(0,R.jsx)(`p`,{className:`text-xs italic text-neutral-500`,children:`Loading tools…`}):(0,R.jsxs)(`div`,{className:`space-y-4`,children:[(0,R.jsxs)(`p`,{className:`text-xs text-neutral-500`,children:[`Toggle individual built-in tools the agent can call. The global toggle on the right is the default for every project. Use `,(0,R.jsx)(`strong`,{children:`Overrides`}),` to enable/disable a tool per project — explicit project overrides win over the global default. Changes apply to the next session — already-running sessions keep the tool set they started with. MCP server tools live under their respective server in the `,(0,R.jsx)(`strong`,{children:`MCP`}),` tab.`]}),(0,R.jsxs)(`section`,{children:[(0,R.jsx)(`h3`,{className:`mb-2 text-xs font-semibold uppercase tracking-wider text-neutral-400`,children:`Built-in tools`}),(0,R.jsx)(`div`,{className:`space-y-2`,children:n.builtin.map(e=>(0,R.jsx)($j,{family:`builtin`,name:e.name,fqn:e.name,description:e.description,globalEnabled:e.globalEnabled,projects:t,allOverrides:i,busy:o,onToggleGlobal:t=>void l(`builtin`,e.name,t),onSetProjectOverride:(t,n)=>void u(`builtin`,t,e.name,n)},`builtin:${e.name}`))})]}),n.extension.length>0&&(0,R.jsxs)(`section`,{children:[(0,R.jsx)(`h3`,{className:`mb-2 text-xs font-semibold uppercase tracking-wider text-neutral-400`,children:`Extension tools`}),(0,R.jsxs)(`p`,{className:`mb-2 text-[11px] text-neutral-500`,children:[`Tools registered programmatically by pi extensions installed under`,` `,(0,R.jsx)(`code`,{className:`font-mono`,children:`~/.pi/agent/extensions/`}),` or a project's`,` `,(0,R.jsx)(`code`,{className:`font-mono`,children:`.pi/extensions/`}),`. Disabled tools are dropped from the allowlist passed to the next session — the extension itself remains loaded.`]}),(0,R.jsx)(`div`,{className:`space-y-4`,children:n.extension.map(e=>(0,R.jsxs)(`div`,{className:`space-y-2`,children:[(0,R.jsxs)(`div`,{className:`text-[11px] font-semibold text-neutral-300`,children:[`Package: `,(0,R.jsx)(`code`,{className:`font-mono text-neutral-400`,children:e.packageSource})]}),(0,R.jsx)(`div`,{className:`space-y-2`,children:e.tools.map(n=>(0,R.jsx)($j,{family:`extension`,name:n.name,fqn:n.name,description:n.description,globalEnabled:n.globalEnabled,projects:t,allOverrides:i,busy:o,onToggleGlobal:e=>void l(`extension`,n.name,e),onSetProjectOverride:(e,t)=>void u(`extension`,e,n.name,t)},`extension:${e.packageSource}:${n.name}`))})]},e.packageSource))})]})]})}function $j({family:e,name:t,fqn:n,description:r,globalEnabled:i,projects:a,allOverrides:o,busy:s,onToggleGlobal:c,onSetProjectOverride:l}){let[u,d]=(0,v.useState)(!1),f=t=>{let r=o[t];if(r===void 0)return;let i=e===`builtin`?r.builtin:e===`mcp`?r.mcp:r.extension;if(i!==void 0){if(i.enable.includes(n))return`enabled`;if(i.disable.includes(n))return`disabled`}},p=a.map(e=>({project:e,state:f(e.id)})).filter(e=>e.state!==void 0),m=a.filter(e=>f(e.id)===void 0);return(0,R.jsxs)(`div`,{className:`rounded border border-neutral-800 bg-neutral-900/40`,children:[(0,R.jsxs)(`div`,{className:`flex items-start gap-3 p-3`,children:[(0,R.jsx)(`span`,{className:`mt-1.5 inline-block h-2.5 w-2.5 rounded-full ${i?`bg-emerald-500`:`bg-neutral-700`}`,title:`Global default: ${i?`enabled`:`disabled`}`}),(0,R.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-0.5`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,R.jsx)(`span`,{className:`font-mono text-neutral-100`,children:t}),n!==t&&(0,R.jsx)(`span`,{className:`font-mono text-[10px] text-neutral-500`,title:`Bridged tool name pi sees on the wire`,children:n})]}),r.length>0&&(0,R.jsx)(`p`,{className:`line-clamp-2 text-[11px] text-neutral-500`,title:r,children:r})]}),(0,R.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1 text-xs`,children:[(0,R.jsxs)(`button`,{onClick:()=>c(!i),disabled:s,className:`rounded border px-2 py-0.5 disabled:opacity-50 ${i?`border-emerald-700/50 bg-emerald-900/20 text-emerald-300 light:border-emerald-300 light:bg-emerald-50 light:text-emerald-800`:`border-neutral-700 text-neutral-300 hover:border-neutral-500`}`,title:`Global default for every project that doesn't override`,children:[`Global: `,i?`enabled`:`disabled`]}),(0,R.jsx)(`button`,{onClick:()=>d(e=>!e),className:`rounded border border-neutral-700 px-2 py-0.5 text-neutral-300 hover:border-neutral-500`,title:`Show per-project overrides`,children:u?`▾ Overrides`:`▸ Overrides (${p.length})`})]})]}),u&&(0,R.jsxs)(`div`,{className:`border-t border-neutral-800 px-3 py-2`,children:[p.length===0?(0,R.jsx)(`p`,{className:`mb-2 text-[11px] italic text-neutral-500`,children:`No project overrides yet — every project inherits the global state.`}):(0,R.jsx)(`div`,{className:`mb-2 space-y-1`,children:p.map(({project:e,state:t})=>(0,R.jsxs)(`div`,{className:`flex items-center justify-between gap-2 rounded bg-neutral-900/60 px-2 py-1 text-xs`,children:[(0,R.jsx)(`span`,{className:`truncate text-neutral-200`,title:e.path,children:e.name}),(0,R.jsx)(Xj,{value:t,disabled:s,onChange:t=>l(e.id,t)})]},e.id))}),m.length>0&&(0,R.jsx)(Zj,{projects:m,disabled:s,onAdd:(e,t)=>l(e,t)}),a.length===0&&(0,R.jsx)(`p`,{className:`text-[11px] italic text-neutral-500`,children:`No projects exist yet. Create a project first to add per-project overrides.`})]})]})}function eM({onError:e}){let t=dr(),[n,r]=(0,v.useState)(void 0),[i,a]=(0,v.useState)(``),[o,s]=(0,v.useState)(2e4),[c,l]=(0,v.useState)(!1),[u,d]=(0,v.useState)(void 0);if((0,v.useEffect)(()=>{if(t===void 0){r(void 0),a(``);return}let n=!1;return e(void 0),(async()=>{try{let e=await L.getProjectSystemPrompt(t.id);if(n)return;r(e.addendum),a(e.addendum),s(e.maxBytes)}catch(t){if(n)return;e(`Failed to load system prompt: ${Lj(t)}`)}})(),()=>{n=!0}},[t?.id]),t===void 0)return(0,R.jsx)(`p`,{className:`text-xs italic text-neutral-500`,children:`Pick a project from the header to edit its system prompt addendum.`});if(n===void 0)return(0,R.jsxs)(`p`,{className:`text-xs italic text-neutral-500`,children:[`Loading system prompt for `,t.name,`…`]});let f=new Blob([i]).size,p=f>o,m=i!==n,h=async()=>{if(!p){l(!0),d(void 0),e(void 0);try{let e=await L.setProjectSystemPrompt(t.id,i);r(e.addendum),a(e.addendum),s(e.maxBytes),d(`Saved. Applies to the next session you start in this project.`),window.setTimeout(()=>d(void 0),4e3)}catch(t){e(`Save failed: ${Lj(t)}`)}finally{l(!1)}}},g=async()=>{if(confirm(`Clear the system prompt addendum for "${t.name}"?`)){l(!0),d(void 0),e(void 0);try{let e=await L.setProjectSystemPrompt(t.id,``);r(e.addendum),a(e.addendum),s(e.maxBytes),d(`Cleared. Applies to the next session you start in this project.`),window.setTimeout(()=>d(void 0),4e3)}catch(t){e(`Clear failed: ${Lj(t)}`)}finally{l(!1)}}};return(0,R.jsxs)(`div`,{className:`space-y-3`,children:[(0,R.jsxs)(`div`,{className:`space-y-1 text-xs text-neutral-400`,children:[(0,R.jsxs)(`p`,{children:[`Free-form text appended to the agent's base system prompt for sessions in`,` `,(0,R.jsx)(`strong`,{className:`text-neutral-200`,children:t.name}),`. Use this to layer project-specific behavior on top of pi's defaults — coding conventions, domain context, persona, etc.`]}),(0,R.jsxs)(`p`,{className:`text-[11px]`,children:[`Append-only — the base prompt (which defines the tool-calling protocol) is not editable. Changes apply to the `,(0,R.jsx)(`strong`,{children:`next session`}),` you start in this project; running sessions keep the prompt they were built with.`]})]}),(0,R.jsx)(`textarea`,{value:i,onChange:e=>a(e.target.value),disabled:c,rows:14,spellCheck:!1,placeholder:"e.g. This project uses TypeScript strict mode and never uses default exports. Always run `npm run check` before declaring a task complete.",className:`w-full resize-y rounded border border-neutral-800 bg-neutral-900 px-3 py-2 font-mono text-xs leading-relaxed text-neutral-100 placeholder:text-neutral-600 focus:border-neutral-600 focus:outline-none disabled:opacity-50`}),(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 text-[11px]`,children:[(0,R.jsxs)(`span`,{className:p?`text-red-400`:`text-neutral-500`,children:[f.toLocaleString(),` / `,o.toLocaleString(),` bytes`,p&&` — too long, please trim before saving`]}),(0,R.jsxs)(`div`,{className:`flex items-center gap-2`,children:[u!==void 0&&(0,R.jsx)(`span`,{className:`text-green-400`,children:u}),m&&(0,R.jsx)(`button`,{type:`button`,onClick:()=>a(n),disabled:c,className:`rounded border border-neutral-800 px-3 py-1 text-xs text-neutral-300 hover:border-neutral-600 disabled:opacity-50`,children:`Revert`}),n.length>0&&(0,R.jsx)(`button`,{type:`button`,onClick:()=>void g(),disabled:c,className:`rounded border border-neutral-800 px-3 py-1 text-xs text-neutral-300 hover:border-red-500 hover:text-red-300 disabled:opacity-50`,children:`Clear`}),(0,R.jsx)(`button`,{type:`button`,onClick:()=>void h(),disabled:c||p||!m,className:`rounded bg-neutral-100 px-3 py-1 text-xs font-medium text-neutral-900 hover:bg-white disabled:opacity-50`,children:c?`Saving…`:`Save`})]})]})]})}function tM(e){return{name:``,kind:e,enabled:!0,command:``,timeoutSec:`30`,text:``,mode:`send`}}function nM({onError:e}){let t=ci(e=>e.minimal),n=li(e=>e.loaded),r=li(e=>e.actions),i=li(e=>e.load),a=li(e=>e.create),o=li(e=>e.update),s=li(e=>e.remove),[c,l]=(0,v.useState)(void 0),[u,d]=(0,v.useState)(void 0),[f,p]=(0,v.useState)(!1);(0,v.useEffect)(()=>{e(void 0),n||i()},[i,n,e]);let m=e=>{let t=typeof e.command==`string`&&e.command.length>0;l({id:e.id,name:e.name,kind:t?`command`:`prompt`,enabled:e.enabled!==!1,command:e.command??``,timeoutSec:String(Math.round((e.timeoutMs??3e4)/1e3)),text:e.text??``,mode:e.mode??`send`})},h=async()=>{if(c===void 0)return;let t=c.name.trim();if(t.length===0){e(`Name is required`);return}let n={name:t,enabled:c.enabled};if(c.kind===`command`){let t=c.command.trim();if(t.length===0){e(`Command is required`);return}n.command=t;let r=Number.parseInt(c.timeoutSec,10);Number.isFinite(r)&&r>0&&(n.timeoutMs=r*1e3)}else{let t=c.text.trim();if(t.length===0){e(`Prompt text is required`);return}n.text=t,n.mode=c.mode}p(!0);try{c.id===void 0?await a(n):await o(c.id,n),l(void 0),e(void 0)}catch(t){e(`Save failed: ${Lj(t)}`)}finally{p(!1)}},g=async t=>{p(!0);try{await s(t),d(void 0),c?.id===t&&l(void 0)}catch(t){e(`Delete failed: ${Lj(t)}`)}finally{p(!1)}};return(0,R.jsxs)(`div`,{className:`space-y-4`,children:[(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`h2`,{className:`text-sm font-semibold text-neutral-100 light:text-neutral-900`,children:`Quick action chips`}),(0,R.jsxs)(`p`,{className:`mt-1 text-xs text-neutral-400 light:text-neutral-600`,children:[`One-click buttons on the chat toolbar. Two kinds:`,` `,(0,R.jsx)(`span`,{className:`text-amber-400 light:text-amber-700`,children:`command`}),` chips run a shell snippet in the active project's folder;`,` `,(0,R.jsx)(`span`,{className:`text-sky-400 light:text-sky-700`,children:`prompt`}),` chips either send a templated prompt to the agent or insert it into the composer so you can tweak it before sending. Chips are stored globally (not per-project) — they're your personal toolbox.`]})]}),t&&(0,R.jsx)(`div`,{className:`rounded border border-amber-700/40 bg-amber-900/20 px-3 py-2 text-xs text-amber-200 light:border-amber-300 light:bg-amber-50 light:text-amber-800`,children:`MINIMAL_UI is enabled. Command chips are listed below but are hidden from the toolbar and the server refuses to run them. Prompt chips are unaffected.`}),(0,R.jsxs)(`div`,{className:`space-y-1`,children:[r.length===0&&n&&(0,R.jsx)(`p`,{className:`text-xs italic text-neutral-500 light:text-neutral-600`,children:`No chips defined yet. Click “New” below to add one.`}),r.map(e=>{let n=typeof e.command==`string`&&e.command.length>0,r=t&&n;return(0,R.jsxs)(`div`,{className:`flex items-center gap-2 rounded border border-neutral-800 bg-neutral-900/40 px-3 py-2 text-xs light:border-neutral-300 light:bg-neutral-50 ${e.enabled===!1?`opacity-60`:``}`,children:[(0,R.jsx)(`span`,{className:`rounded px-1.5 py-0.5 text-[10px] uppercase tracking-wider ${n?`bg-amber-900/40 text-amber-300 light:bg-amber-100 light:text-amber-900`:`bg-sky-900/40 text-sky-300 light:bg-sky-100 light:text-sky-900`}`,children:n?`cmd`:`prompt`}),(0,R.jsx)(`span`,{className:`flex-1 truncate font-medium text-neutral-200 light:text-neutral-900`,children:e.name}),e.enabled===!1&&(0,R.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-neutral-500`,children:`disabled`}),r&&(0,R.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-amber-400 light:text-amber-700`,children:`hidden by MINIMAL_UI`}),(0,R.jsx)(`button`,{onClick:()=>m(e),className:`rounded border border-neutral-700 px-2 py-0.5 text-[11px] text-neutral-300 hover:border-neutral-500 light:border-neutral-400 light:text-neutral-700`,children:`Edit`}),u===e.id?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`button`,{onClick:()=>void g(e.id),disabled:f,className:`rounded border border-red-700 px-2 py-0.5 text-[11px] text-red-300 hover:bg-red-900/40 light:border-red-400 light:text-red-700`,children:`Confirm`}),(0,R.jsx)(`button`,{onClick:()=>d(void 0),className:`rounded border border-neutral-700 px-2 py-0.5 text-[11px] text-neutral-400 hover:border-neutral-500 light:border-neutral-400 light:text-neutral-600`,children:`Cancel`})]}):(0,R.jsx)(`button`,{onClick:()=>d(e.id),className:`rounded border border-neutral-700 px-2 py-0.5 text-[11px] text-neutral-400 hover:border-red-500 hover:text-red-300 light:border-neutral-400 light:text-neutral-600`,children:`Delete`})]},e.id)})]}),c===void 0&&(0,R.jsx)(`button`,{onClick:()=>l(tM(`prompt`)),className:`rounded border border-neutral-700 px-3 py-1 text-xs text-neutral-200 hover:border-neutral-500 light:border-neutral-400 light:text-neutral-800`,children:`+ New chip`}),c!==void 0&&(0,R.jsxs)(`div`,{className:`space-y-3 rounded border border-neutral-700 bg-neutral-900/60 p-3 light:border-neutral-300 light:bg-white`,children:[(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`label`,{className:`mb-1 block text-[11px] uppercase tracking-wider text-neutral-400 light:text-neutral-600`,children:`Name`}),(0,R.jsx)(`input`,{value:c.name,onChange:e=>l({...c,name:e.target.value}),placeholder:`e.g. Run tests`,className:`w-full rounded border border-neutral-700 bg-neutral-950 px-2 py-1 text-sm text-neutral-100 light:border-neutral-300 light:bg-white light:text-neutral-900`})]}),(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`label`,{className:`mb-1 block text-[11px] uppercase tracking-wider text-neutral-400 light:text-neutral-600`,children:`Kind`}),(0,R.jsxs)(`div`,{className:`flex items-center gap-3 text-xs text-neutral-300 light:text-neutral-800`,children:[(0,R.jsxs)(`label`,{className:`flex items-center gap-1.5`,children:[(0,R.jsx)(`input`,{type:`radio`,checked:c.kind===`prompt`,onChange:()=>l({...c,kind:`prompt`})}),`Prompt`]}),(0,R.jsxs)(`label`,{className:`flex items-center gap-1.5 ${t?`opacity-50`:``}`,title:t?`Command chips are disabled by MINIMAL_UI. The server refuses to run them.`:void 0,children:[(0,R.jsx)(`input`,{type:`radio`,checked:c.kind===`command`,disabled:t,onChange:()=>l({...c,kind:`command`})}),`Command`,t?` (disabled by MINIMAL_UI)`:``]})]})]}),c.kind===`command`?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`label`,{className:`mb-1 block text-[11px] uppercase tracking-wider text-neutral-400 light:text-neutral-600`,children:`Command`}),(0,R.jsx)(`textarea`,{value:c.command,onChange:e=>l({...c,command:e.target.value}),rows:3,placeholder:`npm test`,className:`w-full rounded border border-neutral-700 bg-neutral-950 px-2 py-1 font-mono text-xs text-neutral-100 light:border-neutral-300 light:bg-white light:text-neutral-900`}),(0,R.jsxs)(`p`,{className:`mt-1 text-[11px] text-neutral-500 light:text-neutral-600`,children:[`Runs in the active project's folder via `,(0,R.jsx)(`code`,{children:`/bin/sh -c`}),`. Multi-line is fine (`,(0,R.jsx)(`code`,{children:`&&`}),`, `,(0,R.jsx)(`code`,{children:`;`}),`, etc.). Environment is scrubbed of pi-forge and provider secrets (same as the integrated terminal).`]})]}),(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`label`,{className:`mb-1 block text-[11px] uppercase tracking-wider text-neutral-400 light:text-neutral-600`,children:`Timeout (seconds)`}),(0,R.jsx)(`input`,{value:c.timeoutSec,onChange:e=>l({...c,timeoutSec:e.target.value}),placeholder:`30`,className:`w-24 rounded border border-neutral-700 bg-neutral-950 px-2 py-1 text-sm text-neutral-100 light:border-neutral-300 light:bg-white light:text-neutral-900`}),(0,R.jsx)(`p`,{className:`mt-1 text-[11px] text-neutral-500 light:text-neutral-600`,children:`Max 300 (five minutes). Past that, use the integrated terminal.`})]})]}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`label`,{className:`mb-1 block text-[11px] uppercase tracking-wider text-neutral-400 light:text-neutral-600`,children:`Prompt text`}),(0,R.jsx)(`textarea`,{value:c.text,onChange:e=>l({...c,text:e.target.value}),rows:4,placeholder:`Review the staged changes for security issues.`,className:`w-full rounded border border-neutral-700 bg-neutral-950 px-2 py-1 text-xs text-neutral-100 light:border-neutral-300 light:bg-white light:text-neutral-900`})]}),(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`label`,{className:`mb-1 block text-[11px] uppercase tracking-wider text-neutral-400 light:text-neutral-600`,children:`Mode`}),(0,R.jsxs)(`div`,{className:`flex items-center gap-3 text-xs text-neutral-300 light:text-neutral-800`,children:[(0,R.jsxs)(`label`,{className:`flex items-center gap-1.5`,children:[(0,R.jsx)(`input`,{type:`radio`,checked:c.mode===`send`,onChange:()=>l({...c,mode:`send`})}),`Send immediately`]}),(0,R.jsxs)(`label`,{className:`flex items-center gap-1.5`,children:[(0,R.jsx)(`input`,{type:`radio`,checked:c.mode===`insert`,onChange:()=>l({...c,mode:`insert`})}),`Insert into composer`]})]})]})]}),(0,R.jsx)(`div`,{children:(0,R.jsxs)(`label`,{className:`flex items-center gap-1.5 text-xs text-neutral-300 light:text-neutral-800`,children:[(0,R.jsx)(`input`,{type:`checkbox`,checked:c.enabled,onChange:e=>l({...c,enabled:e.target.checked})}),`Enabled (visible in the menu)`]})}),(0,R.jsxs)(`div`,{className:`flex items-center gap-2 border-t border-neutral-800 pt-3 light:border-neutral-300`,children:[(0,R.jsx)(`button`,{onClick:()=>void h(),disabled:f,className:`rounded bg-emerald-700 px-3 py-1 text-xs text-white hover:bg-emerald-600 disabled:opacity-50`,children:c.id===void 0?`Create`:`Save`}),(0,R.jsx)(`button`,{onClick:()=>l(void 0),className:`rounded border border-neutral-700 px-3 py-1 text-xs text-neutral-300 hover:border-neutral-500 light:border-neutral-400 light:text-neutral-700`,children:`Cancel`})]})]})]})}function rM(){let e=tC(e=>e.theme),t=tC(e=>e.setTheme);return(0,R.jsxs)(`div`,{className:`space-y-4`,children:[(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`h2`,{className:`text-sm font-semibold text-neutral-100`,children:`Theme`}),(0,R.jsx)(`p`,{className:`mt-1 text-xs text-neutral-400`,children:`Sets the color palette for the chrome, editor, and terminal. Persisted in this browser only — open in another browser to use a different theme there.`})]}),(0,R.jsx)(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2`,children:KS.map(n=>(0,R.jsxs)(`button`,{onClick:()=>t(n.id),className:`flex items-center justify-between gap-3 rounded border px-3 py-2 text-left ${n.id===e?`border-neutral-400 bg-neutral-800`:`border-neutral-700 hover:border-neutral-500`}`,children:[(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`div`,{className:`text-sm text-neutral-100`,children:n.label}),(0,R.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-neutral-500`,children:n.mode})]}),(0,R.jsx)(iM,{id:n.id})]},n.id))})]})}function iM({id:e}){return(0,R.jsxs)(`div`,{"data-theme":e,className:`flex h-6 overflow-hidden rounded border border-neutral-700`,children:[(0,R.jsx)(`div`,{className:`w-4 bg-neutral-950`}),(0,R.jsx)(`div`,{className:`w-4 bg-neutral-800`}),(0,R.jsx)(`div`,{className:`w-4 bg-neutral-500`}),(0,R.jsx)(`div`,{className:`w-4 bg-neutral-200`})]})}function aM({onError:e}){let[t,n]=(0,v.useState)(!1),[r,i]=(0,v.useState)(void 0),[a,o]=(0,v.useState)(void 0),s=(0,v.useRef)(null),[c,l]=(0,v.useState)(void 0),[u,d]=(0,v.useState)(void 0),f=(0,v.useRef)(null),p=(0,v.useRef)(null),m=async()=>{e(void 0),n(!0),o(void 0);try{let{blob:e,filename:t,files:n}=await L.exportConfig(),r=URL.createObjectURL(e),a=document.createElement(`a`);a.href=r,a.download=t,document.body.appendChild(a),a.click(),document.body.removeChild(a),requestAnimationFrame(()=>URL.revokeObjectURL(r)),i({filename:t,files:n})}catch(t){e(`Export failed: ${Lj(t)}`)}finally{n(!1)}},h=async t=>{e(void 0),n(!0),i(void 0);try{o(await L.importConfig(t))}catch(t){e(`Import failed: ${Lj(t)}`)}finally{n(!1),s.current&&(s.current.value=``)}},g=(e,t)=>{let n=URL.createObjectURL(e),r=document.createElement(`a`);r.href=n,r.download=t,document.body.appendChild(r),r.click(),document.body.removeChild(r),requestAnimationFrame(()=>URL.revokeObjectURL(n))},_=async()=>{e(void 0),n(!0),d(void 0),l(void 0);try{let{blob:e,filename:t,fileCount:n}=await L.exportSkills();g(e,t),l({filename:t,fileCount:n})}catch(t){t instanceof N&&t.code===`skills_directory_empty`?l({filename:``,fileCount:0}):e(`Skills export failed: ${Lj(t)}`)}finally{n(!1)}},y=async t=>{if(t.length!==0){e(void 0),n(!0),l(void 0);try{d(await L.importSkills(t))}catch(t){e(`Skills import failed: ${Lj(t)}`)}finally{n(!1),f.current&&(f.current.value=``),p.current&&(p.current.value=``)}}};return(0,R.jsxs)(`div`,{className:`space-y-6`,children:[(0,R.jsxs)(`section`,{children:[(0,R.jsx)(`h3`,{className:`mb-2 text-sm font-medium text-neutral-100`,children:`Export config`}),(0,R.jsxs)(`p`,{className:`mb-3 text-xs text-neutral-400`,children:[`Downloads a `,(0,R.jsx)(`code`,{className:`font-mono`,children:`.tar.gz`}),` with`,` `,(0,R.jsx)(`code`,{className:`font-mono`,children:`mcp.json`}),`,`,` `,(0,R.jsx)(`code`,{className:`font-mono`,children:`settings.json`}),`,`,` `,(0,R.jsx)(`code`,{className:`font-mono`,children:`models.json`}),`,`,` `,(0,R.jsx)(`code`,{className:`font-mono`,children:`skills-overrides.json`}),`, and`,` `,(0,R.jsx)(`code`,{className:`font-mono`,children:`tool-overrides.json`}),`. Provider auth (`,(0,R.jsx)(`code`,{className:`font-mono`,children:`auth.json`}),` — API keys, OAuth tokens) is`,` `,(0,R.jsx)(`strong`,{children:`not`}),` included; re-authenticate providers after restoring on a new install.`]}),(0,R.jsx)(`button`,{onClick:()=>void m(),disabled:t,className:`rounded border border-neutral-700 bg-neutral-900 px-3 py-1.5 text-xs text-neutral-100 hover:border-neutral-500 disabled:opacity-50`,children:t?`Exporting…`:`Download config archive`}),r!==void 0&&(0,R.jsxs)(`p`,{className:`mt-2 text-xs text-emerald-400 light:text-emerald-700`,children:[`Exported `,(0,R.jsx)(`code`,{className:`font-mono`,children:r.filename}),` (`,r.files.length===0?`no files were on disk`:`included: ${r.files.join(`, `)}`,`)`]})]}),(0,R.jsxs)(`section`,{children:[(0,R.jsx)(`h3`,{className:`mb-2 text-sm font-medium text-neutral-100`,children:`Import config`}),(0,R.jsxs)(`p`,{className:`mb-3 text-xs text-neutral-400`,children:[`Restores a previously-exported archive. Each file is parsed before any disk write — if any file fails validation, `,(0,R.jsx)(`strong`,{children:`nothing`}),` is imported. Existing live agent sessions keep their original settings until restarted.`]}),(0,R.jsx)(`input`,{ref:s,type:`file`,accept:`.gz,.tgz,application/gzip,application/x-gzip`,disabled:t,onChange:e=>{let t=e.target.files?.[0];t!==void 0&&h(t)},className:`block text-xs text-neutral-300 file:mr-3 file:rounded file:border file:border-neutral-700 file:bg-neutral-900 file:px-3 file:py-1.5 file:text-xs file:text-neutral-100 hover:file:border-neutral-500 disabled:opacity-50`}),a!==void 0&&(0,R.jsxs)(`div`,{className:`mt-3 space-y-1 text-xs`,children:[a.imported.length>0&&(0,R.jsxs)(`p`,{className:`text-emerald-400 light:text-emerald-700`,children:[`Imported: `,(0,R.jsx)(`code`,{className:`font-mono`,children:a.imported.join(`, `)})]}),a.skipped.length>0&&(0,R.jsxs)(`p`,{className:`text-amber-400 light:text-amber-700`,children:[`Skipped (not in allow-list):`,` `,(0,R.jsx)(`code`,{className:`font-mono`,children:a.skipped.join(`, `)})]}),a.errors.length>0&&(0,R.jsxs)(`div`,{className:`text-red-400`,children:[(0,R.jsx)(`p`,{children:`Errors — nothing was written:`}),(0,R.jsx)(`ul`,{className:`ml-4 list-disc`,children:a.errors.map(e=>(0,R.jsxs)(`li`,{children:[(0,R.jsx)(`code`,{className:`font-mono`,children:e.file}),`: `,e.reason]},e.file))})]}),a.imported.length===0&&a.errors.length===0&&a.skipped.length===0&&(0,R.jsx)(`p`,{className:`italic text-neutral-500`,children:`Archive was empty.`})]})]}),(0,R.jsxs)(`section`,{children:[(0,R.jsx)(`h3`,{className:`mb-2 text-sm font-medium text-neutral-100`,children:`Export skills`}),(0,R.jsxs)(`p`,{className:`mb-3 text-xs text-neutral-400`,children:[`Downloads a `,(0,R.jsx)(`code`,{className:`font-mono`,children:`.tar.gz`}),` of every file under`,` `,(0,R.jsx)(`code`,{className:`font-mono`,children:`~/.pi/agent/skills/`}),` — both single-file (`,(0,R.jsx)(`code`,{className:`font-mono`,children:`<name>.md`}),`) and directory skills (`,(0,R.jsx)(`code`,{className:`font-mono`,children:`<name>/SKILL.md`}),` + assets) round-trip verbatim.`]}),(0,R.jsx)(`button`,{onClick:()=>void _(),disabled:t,className:`rounded border border-neutral-700 bg-neutral-900 px-3 py-1.5 text-xs text-neutral-100 hover:border-neutral-500 disabled:opacity-50`,children:t?`Working…`:`Download skills archive`}),c!==void 0&&(c.fileCount===0?(0,R.jsx)(`p`,{className:`mt-2 text-xs text-neutral-400`,children:`No skills to export — your skills directory is empty.`}):(0,R.jsxs)(`p`,{className:`mt-2 text-xs text-emerald-400 light:text-emerald-700`,children:[`Exported `,(0,R.jsx)(`code`,{className:`font-mono`,children:c.filename}),` (`,c.fileCount,` file`,c.fileCount===1?``:`s`,` packed)`]}))]}),(0,R.jsxs)(`section`,{children:[(0,R.jsx)(`h3`,{className:`mb-2 text-sm font-medium text-neutral-100`,children:`Import skills`}),(0,R.jsxs)(`p`,{className:`mb-3 text-xs text-neutral-400`,children:[`Restore skills from a previously-exported `,(0,R.jsx)(`code`,{className:`font-mono`,children:`.tar.gz`}),`, OR upload a folder of skill files directly. Existing files at the same path are`,` `,(0,R.jsx)(`strong`,{children:`overwritten`}),`; new files are added. Path traversal and absolute paths are rejected.`]}),(0,R.jsxs)(`div`,{className:`space-y-3`,children:[(0,R.jsxs)(`label`,{className:`block space-y-1`,children:[(0,R.jsx)(`span`,{className:`text-[11px] uppercase tracking-wider text-neutral-500`,children:`From tar.gz`}),(0,R.jsx)(`input`,{ref:f,type:`file`,accept:`.gz,.tgz,application/gzip,application/x-gzip`,disabled:t,onChange:e=>{let t=e.target.files?.[0];t!==void 0&&y([t])},className:`block text-xs text-neutral-300 file:mr-3 file:rounded file:border file:border-neutral-700 file:bg-neutral-900 file:px-3 file:py-1.5 file:text-xs file:text-neutral-100 hover:file:border-neutral-500 disabled:opacity-50`})]}),(0,R.jsxs)(`label`,{className:`block space-y-1`,children:[(0,R.jsx)(`span`,{className:`text-[11px] uppercase tracking-wider text-neutral-500`,children:`From folder (Chromium / WebKit only)`}),(0,R.jsx)(`input`,{ref:p,type:`file`,multiple:!0,webkitdirectory:``,disabled:t,onChange:e=>{let t=e.target.files;t===null||t.length===0||y(Array.from(t))},className:`block text-xs text-neutral-300 file:mr-3 file:rounded file:border file:border-neutral-700 file:bg-neutral-900 file:px-3 file:py-1.5 file:text-xs file:text-neutral-100 hover:file:border-neutral-500 disabled:opacity-50`})]})]}),u!==void 0&&(0,R.jsxs)(`div`,{className:`mt-3 space-y-1 text-xs`,children:[u.imported.length>0&&(0,R.jsxs)(`p`,{className:`text-emerald-400 light:text-emerald-700`,children:[`Imported `,u.imported.length,` file`,u.imported.length===1?``:`s`,`:`,` `,(0,R.jsx)(`code`,{className:`font-mono`,children:u.imported.join(`, `)})]}),u.skipped.length>0&&(0,R.jsxs)(`div`,{className:`text-amber-400 light:text-amber-700`,children:[(0,R.jsxs)(`p`,{children:[`Skipped `,u.skipped.length,` entr`,u.skipped.length===1?`y`:`ies`,`:`]}),(0,R.jsx)(`ul`,{className:`ml-4 list-disc`,children:u.skipped.map(e=>(0,R.jsxs)(`li`,{children:[(0,R.jsx)(`code`,{className:`font-mono`,children:e.name}),` (`,e.reason,`)`]},e.name))})]}),u.imported.length===0&&u.skipped.length===0&&(0,R.jsx)(`p`,{className:`italic text-neutral-500`,children:`No files were imported.`})]})]})]})}var oM=`***REDACTED***`;function sM(){return{name:``,kind:`remote`,enabled:!0,url:``,transport:`auto`,headers:[],command:``,argsText:``,env:[],cwd:``}}function cM(e){return e.split(`
|
|
361
|
+
`).map(e=>e.trim()).filter(e=>e.length>0)}function lM({onError:e}){let t=dr(),n=ur(e=>e.projects),r=Dj(e=>e.settings),i=Dj(e=>e.globalServers),a=Dj(e=>e.byProject[t?.id??`__no_project__`]?.status??Tj),o=Dj(e=>e.byProject[t?.id??`__no_project__`]?.stdioTrust),s=Dj(e=>e.refreshProject),c=Dj(e=>e.setMcpEnabled),l=Dj(e=>e.upsertServer),u=Dj(e=>e.deleteServer),d=Dj(e=>e.probeServer),f=Dj(e=>e.grantStdioTrust),p=Dj(e=>e.revokeStdioTrust),[m,h]=(0,v.useState)(void 0),[g,_]=(0,v.useState)(void 0),[y,b]=(0,v.useState)(!1),[x,S]=(0,v.useState)(void 0),[C,w]=(0,v.useState)(new Map),[T,E]=(0,v.useState)({}),[D,O]=(0,v.useState)(new Set),k=async()=>{try{let[e,n]=await Promise.all([L.listTools(t?.id),L.listToolOverrides()]),r=new Map;for(let t of e.mcp)r.set(`${t.scope}:${t.server}`,t.tools);w(r),E(n.projects)}catch(t){e(`Failed to load tool listing: ${Lj(t)}`)}};(0,v.useEffect)(()=>{s(t?.id).catch(t=>{e(`Failed to load MCP config: ${Lj(t)}`)}),k()},[t?.id]);let ee=async n=>{b(!0);try{await c(n),e(void 0),await s(t?.id)}catch(t){e(`Failed to toggle MCP: ${Lj(t)}`)}finally{b(!1)}},A=async(t,n)=>{let r=i[t];if(r!==void 0){b(!0);try{await l(t,{...r,enabled:n}),e(void 0)}catch(t){e(`Failed to update server: ${Lj(t)}`)}finally{b(!1)}}},te=e=>{let t=i[e];t!==void 0&&(_(e),h({name:e,kind:typeof t.command==`string`&&t.command.length>0?`stdio`:`remote`,enabled:t.enabled!==!1,url:t.url??``,transport:t.transport??`auto`,headers:Object.entries(t.headers??{}).map(([e,t])=>({key:e,value:t})),command:t.command??``,argsText:(t.args??[]).join(`
|
|
362
|
+
`),env:Object.entries(t.env??{}).map(([e,t])=>({key:e,value:t})),cwd:t.cwd??``}))},ne=()=>{_(void 0),h(sM())},re=async()=>{if(m===void 0)return;if(m.name.trim().length===0){e(`Name is required.`);return}if(m.kind===`remote`&&m.url.trim().length===0){e(`URL is required for remote servers.`);return}if(m.kind===`stdio`&&m.command.trim().length===0){e(`Command is required for stdio servers.`);return}let t={enabled:m.enabled};if(m.kind===`remote`){t.url=m.url,t.transport=m.transport;let e={};for(let t of m.headers)t.key.trim().length!==0&&(e[t.key]=t.value);Object.keys(e).length>0&&(t.headers=e)}else{t.command=m.command;let e=cM(m.argsText);e.length>0&&(t.args=e);let n={};for(let e of m.env)e.key.trim().length!==0&&(n[e.key]=e.value);Object.keys(n).length>0&&(t.env=n),m.cwd.trim().length>0&&(t.cwd=m.cwd)}b(!0);try{await l(m.name,t),e(void 0),h(void 0),_(void 0)}catch(t){e(`Failed to save server: ${Lj(t)}`)}finally{b(!1)}},ie=async t=>{if(window.confirm(`Remove MCP server '${t}' from the global registry?`)){b(!0);try{await u(t),e(void 0)}catch(t){e(`Failed to remove server: ${Lj(t)}`)}finally{b(!1)}}},j=async(n,r)=>{S(n);try{await d(n,r===`project`?t?.id:void 0),e(void 0),k()}catch(t){e(`Probe failed for '${n}': ${Lj(t)}`)}finally{S(void 0)}},ae=async(t,n)=>{b(!0);try{await L.setToolEnabled(`mcp`,t,n,`global`),await k()}catch(t){e(`Toggle failed: ${Lj(t)}`)}finally{b(!1)}},M=async(t,n,r)=>{b(!0);try{r===void 0?await L.clearToolProjectOverride(`mcp`,n,t):await L.setToolEnabled(`mcp`,n,r===`enabled`,`project`,t),await k()}catch(t){e(`Override write failed: ${Lj(t)}`)}finally{b(!1)}},oe=e=>{O(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};if(r===void 0)return(0,R.jsx)(`p`,{className:`text-xs italic text-neutral-500`,children:`Loading MCP config…`});let se=r.enabled,ce=a.filter(e=>e.scope===`global`),le=a.filter(e=>e.scope===`project`);return(0,R.jsxs)(`div`,{className:`space-y-4`,children:[(0,R.jsxs)(`p`,{className:`text-xs text-neutral-500`,children:[`MCP servers extend the agent with custom tools. Servers configured here are loaded by every new session. Project-scoped servers in `,(0,R.jsx)(`code`,{className:`font-mono`,children:`.mcp.json`}),` at the project root are also loaded for sessions in that project (project entries override globals on name collision).`]}),(0,R.jsxs)(`div`,{className:`flex items-center justify-between rounded border border-neutral-800 bg-neutral-900/40 p-3`,children:[(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`div`,{className:`text-sm font-medium text-neutral-100`,children:`MCP tools`}),(0,R.jsx)(`div`,{className:`text-[11px] text-neutral-500`,children:`Master switch. When off, no MCP tools reach the agent regardless of per-server state.`})]}),(0,R.jsx)(`button`,{onClick:()=>void ee(!se),disabled:y,className:`rounded border px-3 py-1 text-xs ${se?`border-emerald-700/50 bg-emerald-900/20 text-emerald-300 light:border-emerald-300 light:bg-emerald-50 light:text-emerald-800`:`border-neutral-700 text-neutral-300 hover:border-neutral-500`}`,children:se?`Enabled`:`Disabled`})]}),t!==void 0&&(0,R.jsx)(fM,{projectName:t.name,trusted:o?.trusted===!0,gatedCount:a.filter(e=>e.scope===`project`&&e.state===`trust_required`).length,busy:y,onGrant:async()=>{b(!0);try{await f(t.id),e(void 0)}catch(t){e(`Failed to grant trust: ${Lj(t)}`)}finally{b(!1)}},onRevoke:async()=>{if(window.confirm(`Revoke stdio MCP trust for "${t.name}"? This disconnects every running project-scoped MCP server.`)){b(!0);try{await p(t.id),e(void 0)}catch(t){e(`Failed to revoke trust: ${Lj(t)}`)}finally{b(!1)}}}}),(0,R.jsx)(uM,{title:`Global servers`,emptyHint:`No global MCP servers configured. Click 'Add server' to add one.`,servers:ce.map(e=>({status:e,config:i[e.name]})),editable:!0,editingName:g??null,probingName:x??null,toolsByServer:C,expandedServers:D,allOverrides:T,projects:n,busy:y,onToggleExpanded:oe,onToggleToolGlobal:(e,t)=>void ae(e,t),onSetProjectToolOverride:(e,t,n)=>void M(e,t,n),onToggle:(e,t)=>void A(e,t),onProbe:e=>void j(e,`global`),onEdit:te,onRemove:e=>void ie(e)}),t!==void 0&&(0,R.jsx)(uM,{title:`Project servers (${t.name})`,emptyHint:(0,R.jsxs)(R.Fragment,{children:[`No project servers. Add a `,(0,R.jsx)(`code`,{className:`font-mono`,children:`.mcp.json`}),` file at the project root to define some — supports both`,` `,(0,R.jsx)(`code`,{className:`font-mono`,children:`{ servers: {...} }`}),` and the standard`,` `,(0,R.jsx)(`code`,{className:`font-mono`,children:`{ mcpServers: {...} }`}),` shape.`]}),servers:le.map(e=>({status:e,config:void 0})),editable:!1,probingName:x??null,toolsByServer:C,expandedServers:D,allOverrides:T,projects:n,busy:y,onToggleExpanded:oe,onToggleToolGlobal:(e,t)=>void ae(e,t),onSetProjectToolOverride:(e,t,n)=>void M(e,t,n),onProbe:e=>void j(e,`project`)}),m===void 0?(0,R.jsx)(`button`,{onClick:ne,className:`rounded-md border border-neutral-700 px-3 py-1 text-xs text-neutral-200 hover:border-neutral-500`,children:`+ Add server`}):(0,R.jsx)(pM,{draft:m,isEditing:g!==void 0,busy:y,onChange:h,onSave:()=>void re(),onCancel:()=>{h(void 0),_(void 0)}})]})}function uM(e){return(0,R.jsxs)(`section`,{className:`space-y-2`,children:[(0,R.jsx)(`h3`,{className:`text-xs font-semibold uppercase tracking-wider text-neutral-400`,children:e.title}),e.servers.length===0?(0,R.jsx)(`p`,{className:`text-[11px] italic text-neutral-500`,children:e.emptyHint}):(0,R.jsx)(`div`,{className:`space-y-2`,children:e.servers.map(t=>{let n=t.status,r=e.editingName===n.name,i=e.probingName===n.name,a=`${n.scope}:${n.name}`,o=e.toolsByServer.get(a)??[],s=e.expandedServers.has(a),c=o.length>0;return(0,R.jsxs)(`div`,{className:`rounded border ${r?`border-neutral-500 bg-neutral-900`:`border-neutral-800 bg-neutral-900/40`}`,children:[(0,R.jsxs)(`div`,{className:`p-3`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,R.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,R.jsx)(`button`,{type:`button`,onClick:()=>c&&e.onToggleExpanded(a),disabled:!c,className:`flex h-5 w-5 items-center justify-center rounded text-neutral-300 hover:bg-neutral-800 hover:text-neutral-100 disabled:opacity-30`,title:c?s?`Hide tools`:`Show tools`:`No tools to show (server not connected or empty)`,children:s?(0,R.jsx)(ue,{size:16}):(0,R.jsx)(fe,{size:16})}),(0,R.jsx)(dM,{state:n.state}),(0,R.jsx)(`span`,{className:`font-mono text-sm text-neutral-100`,children:n.name}),(0,R.jsx)(`span`,{className:`rounded bg-neutral-800 px-1.5 py-0.5 text-[10px] uppercase tracking-wider text-neutral-400`,children:n.transport??`auto`}),(0,R.jsxs)(`span`,{className:`text-[11px] text-neutral-500`,children:[n.toolCount,` tools`]})]}),(0,R.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1 text-xs`,children:[e.editable&&e.onToggle!==void 0&&(0,R.jsx)(`button`,{onClick:()=>e.onToggle?.(n.name,!n.enabled),className:`rounded border px-2 py-0.5 ${n.enabled?`border-emerald-700/50 bg-emerald-900/20 text-emerald-300 light:border-emerald-300 light:bg-emerald-50 light:text-emerald-800`:`border-neutral-700 text-neutral-400 hover:border-neutral-500`}`,children:n.enabled?`Enabled`:`Disabled`}),(0,R.jsx)(`button`,{onClick:()=>e.onProbe(n.name),disabled:i,className:`rounded border border-neutral-700 px-2 py-0.5 text-neutral-300 hover:border-neutral-500 disabled:opacity-50`,title:`Reconnect and refresh tool list`,children:i?`Probing…`:`Probe`}),e.editable&&e.onEdit!==void 0&&(0,R.jsx)(`button`,{onClick:()=>e.onEdit?.(n.name),className:`rounded border border-neutral-700 px-2 py-0.5 text-neutral-300 hover:border-neutral-500`,children:`Edit`}),e.editable&&e.onRemove!==void 0&&(0,R.jsx)(`button`,{onClick:()=>e.onRemove?.(n.name),className:`rounded border border-red-700/50 px-2 py-0.5 text-red-300 hover:bg-red-900/20`,children:`Remove`})]})]}),n.kind===`stdio`?(0,R.jsxs)(`div`,{className:`mt-1 truncate font-mono text-[11px] text-neutral-500`,title:`${n.command??``} ${(n.args??[]).join(` `)}`.trim(),children:[n.command,` `,(n.args??[]).join(` `)]}):(0,R.jsx)(`div`,{className:`mt-1 truncate text-[11px] text-neutral-500`,title:n.url??``,children:n.url}),n.lastError!==void 0&&(0,R.jsx)(`div`,{className:`mt-1 truncate text-[11px] text-red-300 light:text-red-700`,title:n.lastError,children:n.lastError})]}),s&&c&&(0,R.jsxs)(`div`,{className:`space-y-2 border-t border-neutral-800 bg-neutral-950/40 px-3 py-2`,children:[(0,R.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-neutral-500`,children:`Tools`}),(0,R.jsx)(`div`,{className:`space-y-2`,children:o.map(t=>(0,R.jsx)($j,{family:`mcp`,name:t.shortName,fqn:t.name,description:t.description,globalEnabled:t.globalEnabled,projects:e.projects,allOverrides:e.allOverrides,busy:e.busy,onToggleGlobal:n=>e.onToggleToolGlobal(t.name,n),onSetProjectOverride:(n,r)=>e.onSetProjectToolOverride(n,t.name,r)},`mcp:${t.name}`))})]})]},a)})})]})}function dM({state:e}){return(0,R.jsx)(`span`,{className:`h-2 w-2 rounded-full ${e===`connected`?`bg-emerald-500`:e===`connecting`?`bg-amber-400 animate-pulse`:e===`error`?`bg-red-500`:e===`disabled`?`bg-neutral-700`:`bg-neutral-500`}`,title:e})}function fM(e){return e.trusted?(0,R.jsxs)(`div`,{className:`flex items-center justify-between rounded border border-neutral-800 bg-neutral-900/40 px-3 py-1.5 text-[11px] text-neutral-500`,children:[(0,R.jsxs)(`span`,{children:[`Stdio MCP trust granted for`,` `,(0,R.jsx)(`strong`,{className:`text-neutral-300`,children:e.projectName}),`. Project-local stdio MCP servers from `,(0,R.jsx)(`code`,{className:`font-mono`,children:`.mcp.json`}),` will spawn on session create.`]}),(0,R.jsx)(`button`,{onClick:()=>void e.onRevoke(),disabled:e.busy,className:`rounded border border-neutral-700 px-2 py-0.5 text-[10px] text-neutral-400 hover:border-neutral-500 hover:text-neutral-200 disabled:opacity-50`,title:`Disconnects every running project-scoped MCP server`,children:`Revoke`})]}):e.gatedCount===0?null:(0,R.jsxs)(`div`,{className:`rounded border border-amber-700/40 bg-amber-900/20 p-3 text-xs text-amber-200 light:border-amber-300 light:bg-amber-50 light:text-amber-800`,children:[(0,R.jsxs)(`div`,{className:`mb-2 font-medium`,children:[`This project wants to spawn `,e.gatedCount,` stdio MCP server`,e.gatedCount===1?``:`s`,`.`]}),(0,R.jsxs)(`p`,{className:`text-[11px] leading-relaxed`,children:[(0,R.jsx)(`strong`,{children:e.projectName}),`'s `,(0,R.jsx)(`code`,{className:`font-mono`,children:`.mcp.json`}),` declares MCP server`,e.gatedCount===1?``:`s`,` that pi-forge would launch as local subprocess`,e.gatedCount===1?``:`es`,`. Stdio MCP runs arbitrary commands on this machine with whatever env you've passed through — only trust projects whose`,` `,(0,R.jsx)(`code`,{className:`font-mono`,children:`.mcp.json`}),` you've reviewed and approve of. Remote (URL) entries in this project are unaffected by this gate.`]}),(0,R.jsx)(`div`,{className:`mt-2 flex gap-2`,children:(0,R.jsx)(`button`,{onClick:()=>void e.onGrant(),disabled:e.busy,className:`rounded bg-amber-200 px-3 py-1 text-[11px] font-medium text-amber-900 hover:bg-amber-100 disabled:opacity-50 light:bg-amber-600 light:text-amber-50 light:hover:bg-amber-700`,children:e.busy?`Granting…`:`Trust this project`})})]})}function pM(e){let{draft:t,busy:n}=e,r=(n,r)=>{e.onChange({...t,[n]:r})};return(0,R.jsxs)(`div`,{className:`rounded border border-neutral-700 bg-neutral-900 p-3`,children:[(0,R.jsx)(`h4`,{className:`mb-2 text-xs font-semibold uppercase tracking-wider text-neutral-400`,children:e.isEditing?`Edit '${t.name}'`:`Add MCP server`}),(0,R.jsxs)(`div`,{className:`mb-3 flex items-center gap-3 rounded border border-neutral-800 bg-neutral-950 p-2 text-[11px]`,children:[(0,R.jsx)(`span`,{className:`text-neutral-500`,children:`Type`}),(0,R.jsxs)(`label`,{className:`flex items-center gap-1.5 ${e.isEditing?`cursor-not-allowed opacity-60`:`cursor-pointer`}`,children:[(0,R.jsx)(`input`,{type:`radio`,name:`mcp-kind`,checked:t.kind===`remote`,disabled:e.isEditing,onChange:()=>r(`kind`,`remote`)}),(0,R.jsx)(`span`,{children:`Remote URL`})]}),(0,R.jsxs)(`label`,{className:`flex items-center gap-1.5 ${e.isEditing?`cursor-not-allowed opacity-60`:`cursor-pointer`}`,children:[(0,R.jsx)(`input`,{type:`radio`,name:`mcp-kind`,checked:t.kind===`stdio`,disabled:e.isEditing,onChange:()=>r(`kind`,`stdio`)}),(0,R.jsx)(`span`,{children:`Local subprocess (stdio)`})]}),e.isEditing&&(0,R.jsx)(`span`,{className:`text-[10px] italic text-neutral-600`,children:`Locked while editing — delete and re-add to change type.`})]}),(0,R.jsxs)(`div`,{className:`grid grid-cols-[80px_1fr] items-center gap-2 text-xs`,children:[(0,R.jsx)(`label`,{className:`text-neutral-500`,children:`Name`}),(0,R.jsx)(`input`,{value:t.name,onChange:e=>r(`name`,e.target.value),disabled:e.isEditing,placeholder:`my-server`,className:`rounded border border-neutral-700 bg-neutral-950 px-2 py-1 text-neutral-100 outline-none focus:border-neutral-500 disabled:opacity-50`}),t.kind===`remote`?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`label`,{className:`text-neutral-500`,children:`URL`}),(0,R.jsx)(`input`,{value:t.url,onChange:e=>r(`url`,e.target.value),placeholder:`https://mcp.example.com/sse`,className:`rounded border border-neutral-700 bg-neutral-950 px-2 py-1 text-neutral-100 outline-none focus:border-neutral-500`}),(0,R.jsx)(`label`,{className:`text-neutral-500`,children:`Transport`}),(0,R.jsxs)(`select`,{value:t.transport,onChange:e=>r(`transport`,e.target.value),className:`rounded border border-neutral-700 bg-neutral-950 px-2 py-1 text-neutral-100 outline-none focus:border-neutral-500`,children:[(0,R.jsx)(`option`,{value:`auto`,children:`auto (StreamableHTTP, fall back to SSE)`}),(0,R.jsx)(`option`,{value:`streamable-http`,children:`streamable-http`}),(0,R.jsx)(`option`,{value:`sse`,children:`sse`})]})]}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`label`,{className:`text-neutral-500`,children:`Command`}),(0,R.jsx)(`input`,{value:t.command,onChange:e=>r(`command`,e.target.value),placeholder:`npx (or absolute path to a binary)`,className:`rounded border border-neutral-700 bg-neutral-950 px-2 py-1 font-mono text-neutral-100 outline-none focus:border-neutral-500`}),(0,R.jsx)(`label`,{className:`self-start pt-1 text-neutral-500`,children:`Args`}),(0,R.jsx)(`textarea`,{value:t.argsText,onChange:e=>r(`argsText`,e.target.value),placeholder:`-y
|
|
363
|
+
@modelcontextprotocol/server-everything`,rows:3,spellCheck:!1,className:`rounded border border-neutral-700 bg-neutral-950 px-2 py-1 font-mono text-[11px] text-neutral-100 outline-none focus:border-neutral-500`}),(0,R.jsx)(`label`,{className:`text-neutral-500`,children:`cwd`}),(0,R.jsx)(`input`,{value:t.cwd,onChange:e=>r(`cwd`,e.target.value),placeholder:`(blank ↦ default: project path for project servers)`,className:`rounded border border-neutral-700 bg-neutral-950 px-2 py-1 font-mono text-neutral-100 outline-none focus:border-neutral-500`})]}),(0,R.jsx)(`label`,{className:`text-neutral-500`,children:`Enabled`}),(0,R.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,R.jsx)(`input`,{type:`checkbox`,checked:t.enabled,onChange:e=>r(`enabled`,e.target.checked)}),(0,R.jsx)(`span`,{className:`text-[11px] text-neutral-500`,children:`Disabled servers don't connect or contribute tools.`})]})]}),t.kind===`remote`?(0,R.jsx)(mM,{label:`Headers`,emptyHint:"No headers. Add `Authorization: Bearer …` here for auth.",keyPlaceholder:`Authorization`,valuePlaceholder:`Bearer …`,rows:t.headers,onChange:e=>r(`headers`,e)}):(0,R.jsx)(mM,{label:`Env`,emptyHint:`No env. Add API keys / config your subprocess needs (PATH / HOME / locale are inherited automatically).`,keyPlaceholder:`GITHUB_TOKEN`,valuePlaceholder:`ghp_…`,rows:t.env,onChange:e=>r(`env`,e)}),(0,R.jsxs)(`div`,{className:`mt-3 flex justify-end gap-2`,children:[(0,R.jsx)(`button`,{onClick:e.onCancel,className:`rounded border border-neutral-700 px-3 py-1 text-xs text-neutral-300 hover:border-neutral-500`,children:`Cancel`}),(0,R.jsx)(`button`,{onClick:e.onSave,disabled:n,className:`rounded bg-neutral-100 px-3 py-1 text-xs font-medium text-neutral-900 disabled:opacity-50`,children:n?`Saving…`:`Save`})]})]})}function mM(e){let{rows:t}=e;return(0,R.jsxs)(`div`,{className:`mt-3`,children:[(0,R.jsxs)(`div`,{className:`mb-1 flex items-center justify-between`,children:[(0,R.jsx)(`h5`,{className:`text-[11px] font-semibold uppercase tracking-wider text-neutral-500`,children:e.label}),(0,R.jsxs)(`button`,{onClick:()=>e.onChange([...t,{key:``,value:``}]),className:`rounded border border-neutral-700 px-2 py-0.5 text-[11px] text-neutral-300 hover:border-neutral-500`,children:[`+ `,e.label.replace(/s$/,``)]})]}),t.length===0&&(0,R.jsx)(`p`,{className:`text-[11px] italic text-neutral-600`,children:e.emptyHint}),t.map((n,r)=>(0,R.jsxs)(`div`,{className:`mb-1 grid grid-cols-[1fr_2fr_auto] gap-1`,children:[(0,R.jsx)(`input`,{value:n.key,onChange:i=>{let a=[...t];a[r]={...n,key:i.target.value},e.onChange(a)},placeholder:e.keyPlaceholder,className:`rounded border border-neutral-700 bg-neutral-950 px-2 py-1 text-[11px] font-mono text-neutral-100 outline-none focus:border-neutral-500`}),(0,R.jsx)(`input`,{value:n.value===oM?``:n.value,onChange:i=>{let a=[...t];a[r]={...n,value:i.target.value},e.onChange(a)},placeholder:n.value===oM?`leave blank to keep stored value`:e.valuePlaceholder,type:`password`,className:`rounded border border-neutral-700 bg-neutral-950 px-2 py-1 text-[11px] font-mono text-neutral-100 outline-none focus:border-neutral-500`}),(0,R.jsx)(`button`,{onClick:()=>e.onChange(t.filter((e,t)=>t!==r)),className:`rounded border border-neutral-700 px-2 text-[11px] text-neutral-400 hover:text-red-300 light:hover:text-red-700`,title:`Remove ${e.label.toLowerCase()}`,children:`×`})]},r)),t.some(e=>e.value===oM)&&(0,R.jsx)(`p`,{className:`mt-1 text-[10px] italic text-neutral-500`,children:`Values with the redaction sentinel keep their stored value when you save.`})]})}var hM=8;function gM(){let e=ci(e=>e.version),t=ci(e=>e.loaded),n=ci(e=>e.passwordAuthEnabled);return(0,R.jsxs)(`div`,{className:`space-y-6 text-sm text-neutral-300`,children:[(0,R.jsxs)(`header`,{className:`space-y-1`,children:[(0,R.jsx)(`h2`,{className:`text-base font-semibold text-neutral-100`,children:`pi-forge`}),(0,R.jsxs)(`p`,{className:`text-xs text-neutral-500`,children:[`Browser interface for the`,` `,(0,R.jsx)(`a`,{href:`https://github.com/badlogic/pi-mono`,target:`_blank`,rel:`noopener noreferrer`,className:`text-blue-400 underline hover:text-blue-300 light:text-blue-700 light:hover:text-blue-900`,children:`pi coding agent`}),`.`]})]}),(0,R.jsxs)(`section`,{className:`space-y-2`,children:[(0,R.jsx)(`h3`,{className:`text-xs font-semibold uppercase tracking-wider text-neutral-500`,children:`Version`}),(0,R.jsx)(`p`,{className:`font-mono text-sm`,children:t?e.length>0?e:(0,R.jsx)(`span`,{className:`text-neutral-500`,children:`unknown`}):(0,R.jsx)(`span`,{className:`text-neutral-500`,children:`loading…`})})]}),(0,R.jsxs)(`section`,{className:`space-y-2`,children:[(0,R.jsx)(`h3`,{className:`text-xs font-semibold uppercase tracking-wider text-neutral-500`,children:`Links`}),(0,R.jsxs)(`ul`,{className:`space-y-1 text-xs`,children:[(0,R.jsx)(`li`,{children:(0,R.jsx)(`a`,{href:`https://github.com/Devin-Marks/pi-forge`,target:`_blank`,rel:`noopener noreferrer`,className:`text-blue-400 underline hover:text-blue-300 light:text-blue-700 light:hover:text-blue-900`,children:`github.com/Devin-Marks/pi-forge`})}),(0,R.jsx)(`li`,{children:(0,R.jsx)(`a`,{href:`https://github.com/Devin-Marks/pi-forge/blob/main/CHANGELOG.md`,target:`_blank`,rel:`noopener noreferrer`,className:`text-blue-400 underline hover:text-blue-300 light:text-blue-700 light:hover:text-blue-900`,children:`Changelog`})}),(0,R.jsx)(`li`,{children:(0,R.jsx)(`a`,{href:`https://github.com/Devin-Marks/pi-forge/blob/main/SECURITY.md`,target:`_blank`,rel:`noopener noreferrer`,className:`text-blue-400 underline hover:text-blue-300 light:text-blue-700 light:hover:text-blue-900`,children:`Security`})})]})]}),n&&(0,R.jsx)(_M,{})]})}function _M(){let e=ar(e=>e.changePassword),t=ar(e=>e.changePasswordPending),n=ar(e=>e.changePasswordError),[r,i]=(0,v.useState)(``),[a,o]=(0,v.useState)(``),[s,c]=(0,v.useState)(``),[l,u]=(0,v.useState)(void 0),[d,f]=(0,v.useState)(!1),p=(0,v.useRef)(!1);(0,v.useEffect)(()=>{if(p.current&&!t&&n===void 0){i(``),o(``),c(``),f(!0);let e=window.setTimeout(()=>f(!1),2500);return()=>window.clearTimeout(e)}p.current=t},[t,n]);let m=t=>{if(t.preventDefault(),u(void 0),f(!1),a.length<hM){u(`New password must be at least ${hM} characters.`);return}if(a!==s){u(`New password and confirmation do not match.`);return}if(a===r){u(`New password must differ from the current one.`);return}e(r,a)},h=l??vM(n);return(0,R.jsxs)(`section`,{className:`space-y-2 border-t border-neutral-800 pt-5`,children:[(0,R.jsx)(`h3`,{className:`text-xs font-semibold uppercase tracking-wider text-neutral-500`,children:`Change password`}),(0,R.jsx)(`p`,{className:`text-xs text-neutral-500`,children:`Updates the scrypt hash on disk; existing browser sessions stay signed in.`}),(0,R.jsxs)(`form`,{onSubmit:m,className:`space-y-2`,children:[(0,R.jsxs)(`label`,{className:`block space-y-1`,children:[(0,R.jsx)(`span`,{className:`text-xs text-neutral-400`,children:`Current password`}),(0,R.jsx)(`input`,{type:`password`,value:r,onChange:e=>i(e.target.value),autoComplete:`current-password`,className:`w-full rounded-md border border-neutral-700 bg-neutral-950 px-3 py-1.5 text-sm outline-none focus:border-neutral-500`})]}),(0,R.jsxs)(`label`,{className:`block space-y-1`,children:[(0,R.jsx)(`span`,{className:`text-xs text-neutral-400`,children:`New password`}),(0,R.jsx)(`input`,{type:`password`,value:a,onChange:e=>o(e.target.value),autoComplete:`new-password`,minLength:hM,className:`w-full rounded-md border border-neutral-700 bg-neutral-950 px-3 py-1.5 text-sm outline-none focus:border-neutral-500`})]}),(0,R.jsxs)(`label`,{className:`block space-y-1`,children:[(0,R.jsx)(`span`,{className:`text-xs text-neutral-400`,children:`Confirm new password`}),(0,R.jsx)(`input`,{type:`password`,value:s,onChange:e=>c(e.target.value),autoComplete:`new-password`,minLength:hM,className:`w-full rounded-md border border-neutral-700 bg-neutral-950 px-3 py-1.5 text-sm outline-none focus:border-neutral-500`})]}),h!==void 0&&(0,R.jsx)(`p`,{role:`alert`,className:`text-xs text-red-400`,children:h}),d&&(0,R.jsx)(`p`,{role:`status`,className:`text-xs text-emerald-400 light:text-emerald-700`,children:`Password updated.`}),(0,R.jsx)(`button`,{type:`submit`,disabled:t||r.length===0||a.length===0,className:`rounded-md bg-neutral-100 px-3 py-1.5 text-xs font-medium text-neutral-900 transition hover:bg-white disabled:cursor-not-allowed disabled:opacity-50`,children:t?`Saving…`:`Update password`})]})]})}function vM(e){if(e!==void 0)switch(e){case`invalid_password`:return`Current password is incorrect.`;case`password_unchanged`:return`New password must differ from the current one.`;case`ui_password_not_configured`:return`Password auth is not configured on this server.`;case`auth_required`:return`Session expired — sign in again.`;default:return`Could not change password: ${e}`}}function yM({sessionId:e}){let t=wr(t=>t.pendingBySession[e]);return t===void 0?null:(0,R.jsx)(bM,{pending:t},t.requestId)}function bM({pending:e}){let t=wr(e=>e.clearPending),[n,r]=(0,v.useState)(0),[i,a]=(0,v.useState)(!1),[o,s]=(0,v.useState)(void 0),[c,l]=(0,v.useState)(()=>e.questions.map(()=>null)),u=e.questions[n];if(u===void 0)return null;let d=e=>{l(t=>{let r=t.slice();return r[n]={...r[n]??{},...e},r})},f=c[n],p=()=>u.multiSelect===!0?f?.multiLabels!==void 0&&f.multiLabels.length>0:f?.selectedLabel!==void 0||f?.customText!==void 0&&f.customText.trim().length>0,m=()=>{let t=[];for(let n=0;n<e.questions.length;n+=1){let r=e.questions[n],i=c[n];if(i!=null){if(r.multiSelect===!0){t.push({questionIndex:n,question:r.question,kind:`multi`,answer:null,...i.multiLabels===void 0?{}:{selected:i.multiLabels}});continue}if(i.selectedLabel!==void 0){let e=r.options.find(e=>e.label===i.selectedLabel);t.push({questionIndex:n,question:r.question,kind:`option`,answer:i.selectedLabel,...e?.preview===void 0?{}:{preview:e.preview}});continue}if(i.customText!==void 0&&i.customText.trim().length>0){t.push({questionIndex:n,question:r.question,kind:`custom`,answer:i.customText.trim()});continue}}}return t},h=async()=>{if(p()){if(n<e.questions.length-1){r(n+1);return}a(!0),s(void 0);try{await L.submitAskUserQuestionAnswer(e.sessionId,{requestId:e.requestId,answers:m()}),t(e.sessionId,e.requestId)}catch(e){s(e instanceof N?`${e.code}: ${e.message}`:e.message),a(!1)}}},g=async()=>{a(!0),s(void 0);try{let r={questionIndex:n,question:u.question,kind:`chat`,answer:`Chat about this`};await L.submitAskUserQuestionAnswer(e.sessionId,{requestId:e.requestId,answers:[r],cancelled:!0}),t(e.sessionId,e.requestId)}catch(e){s(e instanceof N?`${e.code}: ${e.message}`:e.message),a(!1)}};return(0,R.jsx)(`div`,{className:`flex max-h-[60vh] shrink-0 flex-col overflow-hidden border-t border-amber-700/50 bg-neutral-900/40 light:border-amber-400 light:bg-amber-50/60`,children:(0,R.jsxs)(`div`,{className:`flex flex-col overflow-hidden`,children:[(0,R.jsxs)(`header`,{className:`flex items-center gap-2 border-b border-neutral-800 px-4 py-2 light:border-neutral-200`,children:[(0,R.jsx)(`span`,{className:`text-[10px] font-semibold uppercase tracking-wider text-amber-400 light:text-amber-700`,children:`Agent question`}),e.questions.length>1&&(0,R.jsx)(`div`,{className:`ml-2 flex items-center gap-1 text-[10px] uppercase tracking-wider text-neutral-500`,children:e.questions.map((e,t)=>(0,R.jsx)(`span`,{className:`rounded px-1.5 py-0.5 ${t===n?`bg-amber-900/40 text-amber-200 light:bg-amber-100 light:text-amber-900`:c[t]===null?`text-neutral-500`:`bg-neutral-800 text-neutral-300 light:bg-neutral-200 light:text-neutral-700`}`,title:e.question,children:e.header},t))}),(0,R.jsx)(`div`,{className:`flex-1`}),(0,R.jsxs)(`span`,{className:`text-[10px] uppercase tracking-wider text-neutral-500`,children:[n+1,` of `,e.questions.length]})]}),o!==void 0&&(0,R.jsx)(`div`,{className:`border-b border-red-700/40 bg-red-900/20 px-4 py-2 text-xs text-red-300 light:border-red-300 light:bg-red-50 light:text-red-800`,children:o}),(0,R.jsx)(`div`,{className:`flex-1 overflow-y-auto px-4 py-3`,children:(0,R.jsx)(xM,{question:u,draft:f??null,onChange:e=>d(e)})}),(0,R.jsxs)(`footer`,{className:`flex items-center gap-2 border-t border-neutral-800 px-4 py-2 light:border-neutral-200`,children:[(0,R.jsxs)(`button`,{type:`button`,onClick:()=>void g(),disabled:i,className:`flex items-center gap-1 rounded border border-neutral-700 px-3 py-1 text-xs text-neutral-300 hover:border-neutral-500 disabled:opacity-50 light:border-neutral-400 light:text-neutral-700`,title:`Abandon the structured questionnaire and reply in free-form chat`,children:[(0,R.jsx)(Fe,{size:12}),`Chat about this`]}),(0,R.jsx)(`div`,{className:`flex-1`}),n>0&&(0,R.jsxs)(`button`,{type:`button`,onClick:()=>r(n-1),disabled:i,className:`flex items-center gap-1 rounded border border-neutral-700 px-3 py-1 text-xs text-neutral-300 hover:border-neutral-500 disabled:opacity-50 light:border-neutral-400 light:text-neutral-700`,children:[(0,R.jsx)(de,{size:12}),`Back`]}),(0,R.jsxs)(`button`,{type:`button`,onClick:()=>void h(),disabled:i||!p(),className:`flex items-center gap-1 rounded bg-emerald-700 px-3 py-1 text-xs text-white hover:bg-emerald-600 disabled:opacity-50`,children:[i?(0,R.jsx)(Ne,{size:12,className:`animate-spin`}):null,n<e.questions.length-1?(0,R.jsxs)(R.Fragment,{children:[`Next `,(0,R.jsx)(fe,{size:12})]}):i?`Submitting…`:`Submit`]})]})]})})}function xM({question:e,draft:t,onChange:n}){let r=(0,v.useMemo)(()=>e.options.some(e=>typeof e.preview==`string`&&e.preview.length>0),[e.options]),i=e.multiSelect===!0,a=!i&&!r,[o,s]=(0,v.useState)(void 0),c=e.options.find(e=>e.label===o);return(0,v.useEffect)(()=>{r&&o===void 0&&e.options[0]!==void 0&&s(e.options[0].label)},[r,o,e.options]),(0,R.jsxs)(`div`,{className:`space-y-3`,children:[(0,R.jsx)(`h2`,{className:`text-base font-medium text-neutral-100 light:text-neutral-900`,children:e.question}),r&&!i?(0,R.jsxs)(`div`,{className:`grid grid-cols-3 gap-3`,children:[(0,R.jsx)(`div`,{className:`col-span-1 space-y-1`,children:e.options.map(e=>(0,R.jsxs)(`button`,{type:`button`,onClick:()=>{n({selectedLabel:e.label}),s(e.label)},onMouseEnter:()=>s(e.label),className:`w-full rounded border px-2 py-1.5 text-left text-xs ${t?.selectedLabel===e.label?`border-emerald-600 bg-emerald-900/30 text-emerald-100 light:bg-emerald-50 light:text-emerald-900`:o===e.label?`border-neutral-600 bg-neutral-900 text-neutral-100 light:border-neutral-400 light:bg-neutral-100 light:text-neutral-900`:`border-neutral-800 bg-neutral-900/40 text-neutral-300 hover:border-neutral-600 light:border-neutral-300 light:bg-neutral-50 light:text-neutral-700`}`,children:[(0,R.jsx)(`div`,{className:`font-medium`,children:e.label}),(0,R.jsx)(`div`,{className:`mt-0.5 text-[11px] text-neutral-400 light:text-neutral-600`,children:e.description})]},e.label))}),(0,R.jsx)(`div`,{className:`col-span-2 overflow-auto rounded border border-neutral-800 bg-neutral-950 p-3 light:border-neutral-300 light:bg-neutral-50`,children:c?.preview!==void 0&&c.preview.length>0?(0,R.jsx)(`pre`,{className:`whitespace-pre-wrap font-mono text-[11px] text-neutral-200 light:text-neutral-800`,children:c.preview}):(0,R.jsx)(`p`,{className:`text-xs italic text-neutral-500 light:text-neutral-600`,children:`No preview for this option.`})})]}):i?(0,R.jsx)(`div`,{className:`space-y-1`,children:e.options.map(e=>{let r=(t?.multiLabels??[]).includes(e.label);return(0,R.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 rounded border px-2 py-1.5 text-xs ${r?`border-emerald-600 bg-emerald-900/30 light:bg-emerald-50`:`border-neutral-800 bg-neutral-900/40 hover:border-neutral-600 light:border-neutral-300 light:bg-neutral-50`}`,children:[(0,R.jsx)(`input`,{type:`checkbox`,checked:r,onChange:()=>{let i=new Set(t?.multiLabels??[]);r?i.delete(e.label):i.add(e.label),n({multiLabels:Array.from(i)})},className:`mt-1`}),(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`div`,{className:`font-medium text-neutral-100 light:text-neutral-900`,children:e.label}),(0,R.jsx)(`div`,{className:`mt-0.5 text-[11px] text-neutral-400 light:text-neutral-600`,children:e.description})]})]},e.label)})}):(0,R.jsxs)(`div`,{className:`space-y-1`,children:[e.options.map(e=>(0,R.jsxs)(`button`,{type:`button`,onClick:()=>n({selectedLabel:e.label,customText:void 0}),className:`w-full rounded border px-2 py-1.5 text-left text-xs ${t?.selectedLabel===e.label?`border-emerald-600 bg-emerald-900/30 light:bg-emerald-50`:`border-neutral-800 bg-neutral-900/40 hover:border-neutral-600 light:border-neutral-300 light:bg-neutral-50`}`,children:[(0,R.jsx)(`div`,{className:`font-medium text-neutral-100 light:text-neutral-900`,children:e.label}),(0,R.jsx)(`div`,{className:`mt-0.5 text-[11px] text-neutral-400 light:text-neutral-600`,children:e.description})]},e.label)),a&&(0,R.jsxs)(`div`,{className:`pt-2`,children:[(0,R.jsx)(`label`,{className:`mb-1 block text-[10px] uppercase tracking-wider text-neutral-500 light:text-neutral-600`,children:`Type something`}),(0,R.jsx)(`textarea`,{value:t?.customText??``,onChange:e=>n({customText:e.target.value,selectedLabel:void 0}),rows:2,placeholder:`Or type your own answer…`,className:`w-full rounded border border-neutral-700 bg-neutral-950 px-2 py-1 text-xs text-neutral-100 light:border-neutral-300 light:bg-white light:text-neutral-900`})]})]})]})}function SM({sessionId:e,onClose:t}){let n=Er(t=>Dr(t,e)),r=Er(e=>e.set),[i,a]=(0,v.useState)(void 0);(0,v.useEffect)(()=>{let t=!1;return L.listTodos(e).then(n=>{if(t)return;let i=Er.getState().byId[e];(i===void 0||i.tasks.length===0)&&r(e,{tasks:n.tasks,nextId:n.nextId})}).catch(e=>{t||a(e instanceof N?e.code:e.message)}),()=>{t=!0}},[e,r]);let o=(0,v.useMemo)(()=>Or(n),[n]),s=(0,v.useMemo)(()=>CM(n.tasks),[n.tasks]);return(0,R.jsxs)(`div`,{className:`flex h-full flex-col overflow-hidden bg-neutral-950 text-neutral-200 light:bg-white light:text-neutral-900`,children:[(0,R.jsxs)(`header`,{className:`flex items-center gap-2 border-b border-neutral-800 px-3 py-1.5 text-xs light:border-neutral-200`,children:[(0,R.jsx)(`span`,{className:`font-semibold uppercase tracking-wider text-neutral-400 light:text-neutral-600`,children:`Todos`}),(0,R.jsxs)(`span`,{className:`text-neutral-500 light:text-neutral-600`,children:[o.completed,`/`,o.total,o.inProgress>0?` · ${o.inProgress} in progress`:``]}),(0,R.jsx)(`div`,{className:`flex-1`}),(0,R.jsx)(`button`,{type:`button`,onClick:t,className:`rounded p-0.5 text-neutral-500 hover:bg-neutral-800 hover:text-neutral-200 light:hover:bg-neutral-200 light:hover:text-neutral-900`,title:`Hide todo panel`,children:(0,R.jsx)(it,{size:12})})]}),i!==void 0&&n.tasks.length===0&&(0,R.jsxs)(`div`,{className:`border-b border-red-700/40 bg-red-900/20 px-3 py-1.5 text-[11px] text-red-300 light:border-red-300 light:bg-red-50 light:text-red-800`,children:[`Failed to load todos: `,i]}),(0,R.jsx)(`div`,{className:`flex-1 overflow-y-auto px-2 py-2`,children:o.total===0?(0,R.jsx)(`p`,{className:`px-1 text-[11px] italic text-neutral-500 light:text-neutral-600`,children:`No todos yet. The agent will add tasks here when it's planning multi-step work.`}):(0,R.jsxs)(`div`,{className:`space-y-2`,children:[s.in_progress.length>0&&(0,R.jsx)(wM,{label:`In Progress`,tasks:s.in_progress}),s.pending.length>0&&(0,R.jsx)(wM,{label:`Pending`,tasks:s.pending}),s.completed.length>0&&(0,R.jsx)(wM,{label:`Completed`,tasks:s.completed})]})})]})}function CM(e){let t={pending:[],in_progress:[],completed:[],deleted:[]};for(let n of e)t[n.status].push(n);return t}function wM({label:e,tasks:t}){return(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`div`,{className:`mb-1 px-1 text-[10px] uppercase tracking-wider text-neutral-500 light:text-neutral-600`,children:e}),(0,R.jsx)(`div`,{className:`space-y-0.5`,children:t.map(e=>(0,R.jsx)(TM,{task:e},e.id))})]})}function TM({task:e}){let[t,n]=(0,v.useState)(!1),r=e.description!==void 0||e.activeForm!==void 0||e.blockedBy!==void 0&&e.blockedBy.length>0||e.owner!==void 0;return(0,R.jsxs)(`div`,{className:`rounded border border-transparent px-1 py-0.5 text-xs hover:border-neutral-800 light:hover:border-neutral-300`,children:[(0,R.jsxs)(`button`,{type:`button`,onClick:()=>r&&n(e=>!e),className:`flex w-full items-start gap-1.5 text-left ${r?`cursor-pointer`:`cursor-default`}`,children:[r&&(0,R.jsx)(fe,{size:11,className:`mt-0.5 shrink-0 text-neutral-500 transition-transform light:text-neutral-600 ${t?`rotate-90`:``}`}),!r&&(0,R.jsx)(`span`,{className:`inline-block w-[11px] shrink-0`}),(0,R.jsx)(EM,{status:e.status,activeForm:e.activeForm}),(0,R.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,R.jsx)(`span`,{className:`${e.status===`completed`?`text-neutral-500 line-through light:text-neutral-500`:e.status===`in_progress`?`text-neutral-100 light:text-neutral-900`:`text-neutral-300 light:text-neutral-700`}`,children:e.subject}),e.status===`in_progress`&&e.activeForm!==void 0&&(0,R.jsx)(`span`,{className:`ml-1 text-[10px] italic text-amber-400 light:text-amber-700`,children:e.activeForm})]}),(0,R.jsxs)(`span`,{className:`shrink-0 text-[10px] text-neutral-500 light:text-neutral-600`,children:[`#`,e.id]})]}),t&&r&&(0,R.jsxs)(`div`,{className:`mt-1 space-y-0.5 pl-[34px] text-[11px] text-neutral-400 light:text-neutral-600`,children:[e.description!==void 0&&(0,R.jsx)(`div`,{children:e.description}),e.blockedBy!==void 0&&e.blockedBy.length>0&&(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`span`,{className:`text-neutral-500 light:text-neutral-600`,children:`blocked by:`}),` `,e.blockedBy.map(e=>`#${e}`).join(`, `)]}),e.owner!==void 0&&(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`span`,{className:`text-neutral-500 light:text-neutral-600`,children:`owner:`}),` `,e.owner]})]})]})}function EM({status:e,activeForm:t}){return e===`in_progress`?(0,R.jsx)(Ne,{size:11,className:`mt-0.5 shrink-0 animate-spin text-amber-400 light:text-amber-700`,"aria-label":t??`in progress`}):e===`completed`?(0,R.jsx)(le,{size:11,className:`mt-0.5 shrink-0 text-emerald-400 light:text-emerald-700`,"aria-label":`completed`}):e===`deleted`?(0,R.jsx)(it,{size:11,className:`mt-0.5 shrink-0 text-neutral-500 light:text-neutral-500`,"aria-label":`deleted`}):(0,R.jsx)(he,{size:11,className:`mt-0.5 shrink-0 text-neutral-500 light:text-neutral-500`,"aria-label":`pending`})}function DM({sessionId:e}){let t=Nr(t=>Pr(t,e)),n=Nr(t=>Fr(t,e)),r=Nr(e=>e.setProcesses),i=Nr(e=>e.clearWatches),[a,o]=(0,v.useState)(void 0),[s,c]=(0,v.useState)(!1);(0,v.useEffect)(()=>{let t=!1;return L.listProcesses(e).then(n=>{if(t)return;let i=Nr.getState().bySession[e];(i===void 0||i.length===0)&&r(e,n.processes)}).catch(e=>{t||o(e instanceof N?e.code:e.message)}),()=>{t=!0}},[e,r]);let l=(0,v.useMemo)(()=>OM(t),[t]),u=Ir(t),d=t.length-u,f=async()=>{c(!0),o(void 0);try{await L.clearProcesses(e)}catch(e){o(e instanceof N?e.code:e.message)}finally{c(!1)}};return(0,R.jsxs)(`div`,{className:`flex h-full flex-col overflow-hidden bg-neutral-950 text-neutral-200 light:bg-white light:text-neutral-900`,children:[(0,R.jsxs)(`header`,{className:`flex items-center gap-2 border-b border-neutral-800 px-3 py-1.5 text-xs light:border-neutral-200`,children:[(0,R.jsx)(`span`,{className:`font-semibold uppercase tracking-wider text-neutral-400 light:text-neutral-600`,children:`Processes`}),(0,R.jsxs)(`span`,{className:`text-neutral-500 light:text-neutral-600`,children:[u,` running · `,d,` finished`]}),(0,R.jsx)(`div`,{className:`flex-1`}),d>0&&(0,R.jsxs)(`button`,{type:`button`,onClick:()=>void f(),disabled:s,className:`flex items-center gap-1 rounded border border-neutral-700 px-1.5 py-0.5 text-[10px] text-neutral-400 hover:border-neutral-500 hover:text-neutral-200 disabled:opacity-50 light:border-neutral-400 light:text-neutral-600`,title:`Drop all FINISHED processes from the list (running ones stay)`,children:[(0,R.jsx)($e,{size:10}),`Clear finished`]})]}),a!==void 0&&(0,R.jsx)(`div`,{className:`border-b border-red-700/40 bg-red-900/20 px-3 py-1.5 text-[11px] text-red-300 light:border-red-300 light:bg-red-50 light:text-red-800`,children:a}),n.length>0&&(0,R.jsxs)(`div`,{className:`flex items-start gap-2 border-b border-amber-700/40 bg-amber-900/20 px-3 py-1.5 text-[11px] text-amber-200 light:border-amber-300 light:bg-amber-50 light:text-amber-800`,children:[(0,R.jsx)(ce,{size:11,className:`mt-0.5 shrink-0`}),(0,R.jsxs)(`div`,{className:`flex-1 space-y-0.5`,children:[n.slice(-3).map((e,t)=>(0,R.jsxs)(`div`,{className:`truncate font-mono`,children:[(0,R.jsxs)(`span`,{className:`text-neutral-500 light:text-neutral-600`,children:[`[`,e.processName,`]`]}),` `,e.line]},`${e.processId}-${t}`)),n.length>3&&(0,R.jsxs)(`div`,{className:`text-neutral-500 light:text-neutral-600`,children:[`+`,n.length-3,` more watch match(es)`]})]}),(0,R.jsx)(`button`,{type:`button`,onClick:()=>i(e),className:`rounded p-0.5 text-amber-300 hover:text-amber-100 light:text-amber-700 light:hover:text-amber-900`,title:`Clear watch alerts`,children:(0,R.jsx)(We,{size:11})})]}),(0,R.jsx)(`div`,{className:`flex-1 overflow-y-auto px-2 py-2`,children:t.length===0?(0,R.jsx)(`p`,{className:`px-1 text-[11px] italic text-neutral-500 light:text-neutral-600`,children:`No background processes yet. The agent will add them here when it starts dev servers, test watchers, builds, etc.`}):(0,R.jsxs)(`div`,{className:`space-y-2`,children:[l.live.length>0&&(0,R.jsx)(kM,{label:`Running`,items:l.live,sessionId:e}),l.finished.length>0&&(0,R.jsx)(kM,{label:`Finished`,items:l.finished,sessionId:e})]})}),(0,R.jsx)(`footer`,{className:`border-t border-neutral-800 px-3 py-1 text-[10px] italic text-neutral-500 light:border-neutral-200 light:text-neutral-600`,children:`In-memory only — processes don't survive a server restart.`})]})}function OM(e){let t=[],n=[];for(let r of e)kr.has(r.status)?t.push(r):n.push(r);return{live:t,finished:n}}function kM({label:e,items:t,sessionId:n}){return(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`div`,{className:`mb-1 px-1 text-[10px] uppercase tracking-wider text-neutral-500 light:text-neutral-600`,children:e}),(0,R.jsx)(`div`,{className:`space-y-1`,children:t.map(e=>(0,R.jsx)(AM,{process:e,sessionId:n},e.id))})]})}function AM({process:e,sessionId:t}){let[n,r]=(0,v.useState)(!1),[i,a]=(0,v.useState)(void 0),[o,s]=(0,v.useState)(!1),[c,l]=(0,v.useState)(void 0),u=kr.has(e.status);(0,v.useEffect)(()=>{if(!n)return;let r=!1;return L.getProcessOutput(t,e.id,80).then(e=>{r||a(e)}).catch(()=>{}),()=>{r=!0}},[n,t,e.id,e.endTime,e.status]);let d=Nr(e=>e.setProcesses),f=async()=>{s(!0),l(void 0);try{let n=await L.killProcess(t,e.id);n.ok||l(n.reason??`kill failed`),setTimeout(()=>{L.listProcesses(t).then(e=>d(t,e.processes)).catch(()=>void 0)},800)}catch(e){l(e instanceof N?e.code:e.message)}finally{s(!1)}},p=NM(e.startTime,e.endTime);return(0,R.jsxs)(`div`,{className:`rounded border px-1.5 py-1 text-xs ${jM(e.status)} ${u?`bg-neutral-900/40 light:bg-neutral-50`:`bg-neutral-900/20 light:bg-neutral-50/60`}`,children:[(0,R.jsxs)(`button`,{type:`button`,onClick:()=>r(e=>!e),className:`flex w-full items-start gap-1.5 text-left`,children:[(0,R.jsx)(fe,{size:11,className:`mt-0.5 shrink-0 text-neutral-500 transition-transform light:text-neutral-600 ${n?`rotate-90`:``}`}),(0,R.jsx)(MM,{status:e.status,success:e.success}),(0,R.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,R.jsxs)(`div`,{className:`flex items-baseline gap-1.5`,children:[(0,R.jsx)(`span`,{className:`truncate font-medium text-neutral-100 light:text-neutral-900`,children:e.name}),(0,R.jsx)(`span`,{className:`shrink-0 text-[10px] text-neutral-500 light:text-neutral-600`,children:e.id})]}),(0,R.jsx)(`div`,{className:`truncate font-mono text-[10px] text-neutral-500 light:text-neutral-600`,children:e.command})]}),(0,R.jsx)(`span`,{className:`shrink-0 text-[10px] text-neutral-500 light:text-neutral-600`,children:p})]}),n&&(0,R.jsxs)(`div`,{className:`mt-1 space-y-1 pl-[24px]`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] text-neutral-500 light:text-neutral-600`,children:[(0,R.jsxs)(`span`,{children:[`PID `,e.pid]}),e.exitCode!==null&&(0,R.jsxs)(`span`,{children:[`exit `,e.exitCode]}),(0,R.jsx)(`div`,{className:`flex-1`}),u&&(0,R.jsxs)(`button`,{type:`button`,onClick:()=>void f(),disabled:o,className:`flex items-center gap-1 rounded border border-red-700/40 px-1.5 py-0.5 text-[10px] text-red-300 hover:bg-red-900/40 disabled:opacity-50 light:border-red-400 light:text-red-700 light:hover:bg-red-100`,children:[(0,R.jsx)(me,{size:10}),`Kill`]})]}),c!==void 0&&(0,R.jsx)(`div`,{className:`text-[10px] text-red-300 light:text-red-700`,children:c}),i!==void 0&&i.stdout.length>0&&(0,R.jsxs)(`details`,{className:`rounded bg-neutral-950 light:bg-white`,children:[(0,R.jsx)(`summary`,{className:`cursor-pointer px-1 py-0.5 text-[10px] uppercase tracking-wider text-neutral-500 hover:text-neutral-300 light:text-neutral-600 light:hover:text-neutral-900`,children:`stdout (tail)`}),(0,R.jsx)(`pre`,{className:`max-h-48 overflow-auto whitespace-pre-wrap px-1.5 py-1 font-mono text-[10px] text-neutral-300 light:text-neutral-800`,children:i.stdout.join(`
|
|
364
364
|
`)})]}),i!==void 0&&i.stderr.length>0&&(0,R.jsxs)(`details`,{className:`rounded bg-neutral-950 light:bg-white`,children:[(0,R.jsx)(`summary`,{className:`cursor-pointer px-1 py-0.5 text-[10px] uppercase tracking-wider text-neutral-500 hover:text-neutral-300 light:text-neutral-600 light:hover:text-neutral-900`,children:`stderr (tail)`}),(0,R.jsx)(`pre`,{className:`max-h-48 overflow-auto whitespace-pre-wrap px-1.5 py-1 font-mono text-[10px] text-red-300 light:text-red-700`,children:i.stderr.join(`
|
|
365
|
-
`)})]}),(0,R.jsxs)(`div`,{className:`flex gap-2 text-[10px]`,children:[(0,R.jsx)(jM,{sessionId:t,processId:e.id,stream:`stdout`}),(0,R.jsx)(jM,{sessionId:t,processId:e.id,stream:`stderr`})]})]})]})}function DM(e){return e===`running`||e===`terminating`?`border-neutral-700 light:border-neutral-300`:e===`terminate_timeout`?`border-amber-700/50 light:border-amber-400`:e===`killed`?`border-amber-700/40 light:border-amber-400`:`border-neutral-800 light:border-neutral-200`}function OM({status:e,success:t}){return e===`running`?(0,R.jsx)(Ne,{size:11,className:`mt-0.5 shrink-0 animate-spin text-emerald-400 light:text-emerald-700`,"aria-label":`running`}):e===`terminating`||e===`terminate_timeout`?(0,R.jsx)(at,{size:11,className:`mt-0.5 shrink-0 text-amber-400 light:text-amber-700`,"aria-label":`terminating`}):e===`killed`?(0,R.jsx)(et,{size:11,className:`mt-0.5 shrink-0 text-amber-400 light:text-amber-700`,"aria-label":`killed`}):t===!0?(0,R.jsx)(pe,{size:11,className:`mt-0.5 shrink-0 text-emerald-400 light:text-emerald-700`,"aria-label":`exited 0`}):(0,R.jsx)(me,{size:11,className:`mt-0.5 shrink-0 text-red-400 light:text-red-700`,"aria-label":`exited non-zero`})}function kM(e,t){let n=(t??Date.now())-e;if(n<1e3)return`${n}ms`;let r=n/1e3;if(r<60)return`${r.toFixed(1)}s`;let i=r/60;return i<60?`${i.toFixed(1)}m`:`${(i/60).toFixed(1)}h`}function AM(e){return e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`).replace(/'/g,`'`)}function jM({sessionId:e,processId:t,stream:n}){let[r,i]=(0,v.useState)(!1),[a,o]=(0,v.useState)(void 0);return(0,R.jsx)(`button`,{type:`button`,onClick:()=>{let r=window.open(`about:blank`,`_blank`);if(r===null){o(`popup blocked — allow popups for this site`);return}i(!0),o(void 0),(async()=>{try{let i=L.processLogFileUrl(e,t,n),a=Vt(),s={};a!==void 0&&(s.Authorization=`Bearer ${a.token}`);let c=await fetch(i,{headers:s});if(!c.ok){r.close(),o(`${c.status} ${c.statusText}`);return}let l=await c.text(),u=`<!doctype html><html><head><meta charset="utf-8"><title>${AM(`${n} — ${t}`)}</title><meta name="color-scheme" content="dark light"><style>html,body{margin:0;padding:0;background:#0a0a0a;color:#e5e5e5;font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:13px;line-height:1.5;tab-size:4}@media (prefers-color-scheme: light){html,body{background:#fafafa;color:#171717}}pre{margin:0;padding:1rem;white-space:pre-wrap;word-break:break-word}</style></head><body><pre>${AM(l)}</pre></body></html>`,d=new Blob([u],{type:`text/html;charset=utf-8`}),f=URL.createObjectURL(d);r.location.href=f,setTimeout(()=>URL.revokeObjectURL(f),6e4)}catch(e){r.close(),o(e instanceof Error?e.message:String(e))}finally{i(!1)}})()},disabled:r,className:`text-sky-400 hover:underline disabled:opacity-50 light:text-sky-700`,title:a,children:r?`loading…`:a===void 0?`full ${n} log`:`${n}: ${a}`})}function MM(){let e=dr(),t=ai(t=>e===void 0?void 0:t.treeByProject[e.id]),n=ai(t=>e===void 0?!1:t.treeLoading[e.id]??!1),r=ai(e=>e.error),i=ai(e=>e.loadTree),a=ai(e=>e.openFile),o=ai(e=>e.createFile),s=ai(e=>e.createFolder),c=ai(e=>e.renameEntry),l=ai(e=>e.moveEntry),u=ai(e=>e.deleteEntry),[d,f]=(0,v.useState)({"":!0}),[p,m]=(0,v.useState)(void 0),[h,g]=(0,v.useState)(``),[_,y]=(0,v.useState)(void 0),[b,x]=(0,v.useState)(void 0),[S,C]=(0,v.useState)(void 0),w=(0,v.useRef)(null),T=(0,v.useRef)(void 0),E=ai(e=>e.uploadFiles),[D,O]=(0,v.useState)(void 0),k=JA(e=>e.requestChatInsert),ee=JA(e=>e.openEditorPane),[A,te]=(0,v.useState)(new Set);if((0,v.useEffect)(()=>{e!==void 0&&i(e.id)},[e?.id,i]),e===void 0)return(0,R.jsx)(`div`,{className:`p-4 text-xs italic text-neutral-500`,children:`Select a project to browse its files.`});let ne=async(t,n,r)=>{x(void 0);try{if(t===`file`){let t=await o(e.id,n,r);await a(e.id,t),ee()}else await s(e.id,n,r)}catch{}},re=(e,t,n)=>{f(e=>({...e,[t]:!0})),x({kind:`create`,entryKind:n,parentAbsPath:e})},ie=(e,t)=>{m(e),g(t)},j=async t=>{let n=h.trim();if(m(void 0),g(``),n.length!==0)try{await c(e.id,t,n)}catch{}},ae=()=>te(new Set),M=e=>{te(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},oe=(e,t,n)=>{x({kind:`delete`,absPath:e,name:t,isDir:n,recursive:!1})},se=async()=>{if(b?.kind!==`delete`)return;let{absPath:t,name:n,isDir:r,recursive:i}=b;x(void 0);try{await u(e.id,t,i?{recursive:!0}:void 0)}catch(e){if(e instanceof N&&e.code===`directory_not_empty`){x({kind:`delete`,absPath:t,name:n,isDir:r,recursive:!0});return}}},ce=async()=>{if(b?.kind!==`deleteMany`)return;let{paths:t}=b;x(void 0);for(let n of t)try{await u(e.id,n,{recursive:!0})}catch{}ae()},le=async t=>{if(t.type===`directory`){f(e=>({...e,[t.path]:!e[t.path]}));return}await a(e.id,IM(e.path,t.path)),ee()},ue=(e,t)=>{e.preventDefault(),e.stopPropagation(),O({x:e.clientX,y:e.clientY,kind:t.isDir?`folder`:`file`,absPath:t.absPath,name:t.name,relPath:t.relPath})},de=t=>{t.preventDefault(),O({x:t.clientX,y:t.clientY,kind:`empty`,absPath:e.path,name:``,relPath:``})},fe=t=>{let n=t;t.startsWith(`${e.path}/`)&&(n=t.slice(e.path.length+1)),k(/\s/.test(n)?`@"${n}"`:`@${n}`),O(void 0)},pe=async(t,n)=>{if(t.preventDefault(),t.stopPropagation(),y(void 0),t.dataTransfer.files.length>0){await me(n,Array.from(t.dataTransfer.files));return}let r=t.dataTransfer.getData(`application/x-pi-path`);if(r.length===0)return;let i=r.split(`/`).pop()??``;if(i.length===0)return;let a=`${n}/${i}`;if(a!==r&&!(n===r||n.startsWith(`${r}/`)))try{await l(e.id,r,a)}catch{}},me=async(t,n)=>{if(n.length===0)return;let r=n.reduce((e,t)=>e+t.size,0);C(`Hashing ${n.length} file${n.length===1?``:`s`} (${VM(r)})…`);try{let r=await E(e.id,t,n,{onHashProgress:(e,t)=>{C(e<t?`Hashing ${VM(e)} / ${VM(t)} (${Math.floor(e/t*100)}%)…`:`Uploading ${n.length} file${n.length===1?``:`s`} (${VM(t)})…`)}});C(`Uploaded ${r.length} file${r.length===1?``:`s`}.`),window.setTimeout(()=>C(void 0),2500)}catch{C(void 0)}},he=e=>{T.current=e,w.current?.click()},ge=async t=>{C(`Preparing download…`);try{let{blob:n,filename:r}=await L.filesDownload(e.id,t),i=URL.createObjectURL(n),a=document.createElement(`a`);a.href=i,a.download=r,document.body.appendChild(a),a.click(),a.remove(),window.setTimeout(()=>URL.revokeObjectURL(i),1e3),C(void 0)}catch(e){C(void 0),ai.setState({error:e instanceof Error?e.message:`download_failed`})}},_e=async t=>{let n=t.target.files,r=n===null?[]:Array.from(n),i=T.current??e.path;t.target.value=``,T.current=void 0,r.length!==0&&await me(i,r)};return(0,R.jsxs)(`div`,{className:`flex h-full flex-col text-xs text-neutral-300`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between border-b border-neutral-800 px-3 py-2`,children:[(0,R.jsx)(`span`,{className:`truncate font-medium text-neutral-200`,title:e.path,children:e.name}),(0,R.jsxs)(`div`,{className:`flex gap-1`,children:[(0,R.jsx)(`button`,{onClick:()=>x({kind:`create`,entryKind:`file`,parentAbsPath:e.path}),className:`rounded p-1 text-neutral-400 hover:bg-neutral-800 hover:text-neutral-200`,title:`New file`,children:(0,R.jsx)(Ce,{size:14})}),(0,R.jsx)(`button`,{onClick:()=>x({kind:`create`,entryKind:`folder`,parentAbsPath:e.path}),className:`rounded p-1 text-neutral-400 hover:bg-neutral-800 hover:text-neutral-200`,title:`New folder`,children:(0,R.jsx)(Te,{size:14})}),(0,R.jsx)(`button`,{onClick:()=>he(e.path),className:`rounded p-1 text-neutral-400 hover:bg-neutral-800 hover:text-neutral-200`,title:`Upload files into project root (drag-and-drop also works on any folder)`,children:(0,R.jsx)(nt,{size:14})}),(0,R.jsx)(`button`,{onClick:()=>void ge(void 0),className:`rounded p-1 text-neutral-400 hover:bg-neutral-800 hover:text-neutral-200`,title:`Download project as .tar.gz (skips node_modules, .git, dist, etc.)`,children:(0,R.jsx)(ye,{size:14})}),(0,R.jsx)(`button`,{onClick:()=>void i(e.id),className:`rounded p-1 text-neutral-400 hover:bg-neutral-800 hover:text-neutral-200`,title:`Refresh`,children:(0,R.jsx)(Ue,{size:14,className:n?`animate-spin`:``})})]})]}),(0,R.jsx)(`input`,{ref:w,type:`file`,multiple:!0,className:`hidden`,onChange:e=>void _e(e)}),S!==void 0&&(0,R.jsxs)(`div`,{className:`flex items-center gap-1.5 border-b border-emerald-700/40 bg-emerald-900/20 px-3 py-1.5 text-[11px] text-emerald-200 light:border-emerald-300 light:bg-emerald-50 light:text-emerald-800`,children:[!S.startsWith(`Uploaded`)&&(0,R.jsx)(Ne,{size:11,className:`animate-spin`}),(0,R.jsx)(`span`,{children:S})]}),r!==void 0&&(0,R.jsx)(`div`,{className:`border-b border-red-700/40 bg-red-900/20 px-3 py-1.5 text-[11px] text-red-300 light:border-red-300 light:bg-red-50 light:text-red-700`,children:r}),A.size>0&&(0,R.jsxs)(`div`,{className:`flex items-center justify-between gap-2 border-b border-neutral-800 bg-neutral-900/60 px-3 py-1.5 text-[11px] text-neutral-300`,children:[(0,R.jsxs)(`span`,{children:[A.size,` selected`,(0,R.jsx)(`span`,{className:`ml-2 text-neutral-500`,children:`(Cmd/Ctrl+click rows to add or remove)`})]}),(0,R.jsxs)(`div`,{className:`flex gap-1`,children:[(0,R.jsx)(`button`,{onClick:()=>x({kind:`deleteMany`,paths:Array.from(A)}),className:`rounded border border-red-700/50 px-2 py-0.5 text-red-300 hover:bg-red-900/20 light:border-red-400 light:text-red-700 light:hover:bg-red-50`,children:`Delete selected`}),(0,R.jsx)(`button`,{onClick:ae,className:`rounded border border-neutral-700 px-2 py-0.5 text-neutral-300 hover:border-neutral-500`,children:`Clear`})]})]}),(0,R.jsxs)(`div`,{className:`flex-1 overflow-y-auto py-1`,onContextMenu:de,onDragOver:e=>{(e.dataTransfer.types.includes(`application/x-pi-path`)||e.dataTransfer.types.includes(`Files`))&&(e.preventDefault(),e.dataTransfer.dropEffect=e.dataTransfer.types.includes(`Files`)?`copy`:`move`)},onDrop:t=>void pe(t,e.path),children:[t===void 0&&!n&&(0,R.jsx)(`p`,{className:`px-3 py-2 italic text-neutral-500`,children:`Tree not loaded.`}),t!==void 0&&(0,R.jsx)(FM,{node:t,depth:0,projectPath:e.path,expanded:d,onToggle:e=>f(t=>({...t,[e]:!t[e]})),onOpen:e=>void le(e),renaming:p,renameDraft:h,onRenameDraftChange:g,onRenameCommit:e=>void j(e),onRenameStart:ie,onDelete:(e,t,n)=>oe(e,t,n),onCreate:(e,t,n)=>re(e,t,n),onUpload:e=>he(e),onDownload:e=>void ge(e),dropTarget:_,onDropTargetChange:y,onDrop:(e,t)=>void pe(e,t),onContextMenu:ue,selectedPaths:A,onToggleSelect:M})]}),(0,R.jsx)(Ti,{open:b?.kind===`create`,onClose:()=>x(void 0),onSubmit:e=>{b?.kind===`create`&&ne(b.entryKind,b.parentAbsPath,e)},title:RM(b,e.path),label:zM(b,e.path),placeholder:BM(b),primaryLabel:`Create`}),(0,R.jsx)(Ei,{open:b?.kind===`delete`,onClose:()=>x(void 0),onConfirm:()=>void se(),title:b?.kind===`delete`?b.recursive?`"${b.name}" is not empty`:b.isDir?`Delete directory`:`Delete file`:``,message:b?.kind===`delete`?b.recursive?`"${b.name}" contains files. Delete the directory and ALL its contents? This cannot be undone.`:`Delete ${b.isDir?`directory`:`file`} "${b.name}"? This cannot be undone.`:``,primaryLabel:b?.kind===`delete`&&b.recursive?`Delete contents`:`Delete`,tone:`danger`}),(0,R.jsx)(Ei,{open:b?.kind===`deleteMany`,onClose:()=>x(void 0),onConfirm:()=>void ce(),title:b?.kind===`deleteMany`?`Delete ${b.paths.length} item${b.paths.length===1?``:`s`}`:``,message:b?.kind===`deleteMany`?`Delete the ${b.paths.length} selected file${b.paths.length===1?``:`s`} / folder${b.paths.length===1?``:`s`}? Folders are deleted recursively. This cannot be undone.`:``,primaryLabel:`Delete all`,tone:`danger`}),D!==void 0&&(0,R.jsx)(NM,{x:D.x,y:D.y,kind:D.kind,onClose:()=>O(void 0),onAddAsContext:()=>fe(D.absPath),...D.kind!==`empty`&&{onRename:()=>ie(D.absPath,D.name),onDelete:()=>oe(D.absPath,D.name,D.kind===`folder`),onDownload:()=>void ge(D.absPath)},...D.kind!==`file`&&{onAddFile:()=>re(D.absPath,D.relPath,`file`),onAddFolder:()=>re(D.absPath,D.relPath,`folder`)}})]})}function NM(e){let t=(0,v.useRef)(e.onClose);t.current=e.onClose,(0,v.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t.current()},n=()=>t.current();window.addEventListener(`keydown`,e);let r=setTimeout(()=>window.addEventListener(`mousedown`,n),0);return()=>{window.removeEventListener(`keydown`,e),window.removeEventListener(`mousedown`,n),clearTimeout(r)}},[]);let n=t=>{if(t!==void 0)return()=>{t(),e.onClose()}},r=e.kind===`empty`?void 0:n(e.onAddAsContext),i=n(e.onRename),a=n(e.onDelete),o=n(e.onDownload),s=n(e.onAddFile),c=n(e.onAddFolder);return(0,R.jsxs)(`div`,{className:`fixed z-50 min-w-[200px] overflow-hidden rounded-md border border-neutral-700 bg-neutral-900 shadow-lg`,style:{left:e.x,top:e.y},onMouseDown:e=>e.stopPropagation(),children:[r!==void 0&&(0,R.jsx)(PM,{onClick:r,icon:(0,R.jsx)(se,{size:12}),label:`Add as @ context`,title:e.kind===`folder`?`Append @<path>/ to the chat input so the model can ls / grep this folder`:`Append @<path> to the chat input so the file's content is sent with the next prompt`}),s!==void 0&&(0,R.jsx)(PM,{onClick:s,icon:(0,R.jsx)(Ce,{size:12}),label:`Add file`,title:e.kind===`folder`?`Create a new file inside this folder`:`Create a new file at the project root`}),c!==void 0&&(0,R.jsx)(PM,{onClick:c,icon:(0,R.jsx)(Te,{size:12}),label:`Add folder`,title:e.kind===`folder`?`Create a new subfolder inside this folder`:`Create a new folder at the project root`}),i!==void 0&&(0,R.jsx)(PM,{onClick:i,icon:(0,R.jsx)(Ve,{size:12}),label:`Rename`,title:`Rename this file or folder`}),o!==void 0&&(0,R.jsx)(PM,{onClick:o,icon:(0,R.jsx)(ye,{size:12}),label:`Download`,title:e.kind===`folder`?`Download folder as .tar.gz`:`Download this file`}),a!==void 0&&(0,R.jsx)(PM,{onClick:a,icon:(0,R.jsx)($e,{size:12}),label:`Delete`,title:`Delete this file or folder`,tone:`danger`})]})}function PM(e){let t=e.tone===`danger`;return(0,R.jsxs)(`button`,{type:`button`,onClick:e.onClick,title:e.title,className:`flex w-full items-center gap-2 px-3 py-1.5 text-left text-xs ${t?`text-red-300 hover:bg-red-900/30 hover:text-red-100 light:text-red-700 light:hover:bg-red-100 light:hover:text-red-900`:`text-neutral-200 hover:bg-neutral-800`}`,children:[e.icon,e.label]})}function FM(e){let{node:t,depth:n,projectPath:r}=e;if(n===0&&t.type===`directory`)return(0,R.jsx)(`ul`,{children:t.children?.map(t=>(0,R.jsx)(FM,{...e,node:t,depth:1},t.path))});let i=IM(r,t.path),a=t.type===`directory`,o=a&&(e.expanded[t.path]??!1),s=e.renaming===i,c=a&&e.dropTarget===i;return(0,R.jsxs)(`li`,{children:[(0,R.jsxs)(`div`,{className:`group flex items-center gap-1 border-l-2 py-0.5 pr-2 ${e.selectedPaths.has(i)?`border-blue-400 bg-blue-500/15 hover:bg-blue-500/25`:`border-transparent hover:bg-neutral-900`} ${c?`bg-emerald-900/30 ring-1 ring-emerald-700/50`:``}`,style:{paddingLeft:`${n*12+6}px`},onContextMenu:s?void 0:n=>e.onContextMenu(n,{absPath:i,isDir:a,name:t.name,relPath:t.path}),draggable:!s,onDragStart:e=>{e.dataTransfer.setData(`application/x-pi-path`,i),e.dataTransfer.effectAllowed=`move`},onDragOver:a?t=>{let n=t.dataTransfer.types.includes(`Files`),r=t.dataTransfer.types.includes(`application/x-pi-path`);!n&&!r||(t.preventDefault(),t.stopPropagation(),t.dataTransfer.dropEffect=n?`copy`:`move`,e.dropTarget!==i&&e.onDropTargetChange(i))}:void 0,onDragLeave:a?()=>{e.dropTarget===i&&e.onDropTargetChange(void 0)}:void 0,onDrop:a?t=>{t.stopPropagation(),e.onDrop(t,i)}:void 0,children:[(0,R.jsxs)(`button`,{onClick:n=>{if(n.metaKey||n.ctrlKey){e.onToggleSelect(i);return}e.onOpen(t)},className:`flex flex-1 items-center gap-1 truncate text-left`,title:i,children:[a?o?(0,R.jsx)(ue,{size:12,className:`text-neutral-500`}):(0,R.jsx)(fe,{size:12,className:`text-neutral-500`}):(0,R.jsx)(`span`,{className:`inline-block w-3`}),s?(0,R.jsx)(`input`,{autoFocus:!0,value:e.renameDraft,onChange:t=>e.onRenameDraftChange(t.target.value),onKeyDown:t=>{(t.key===`Enter`||t.key===`Escape`)&&(t.preventDefault(),e.onRenameCommit(i))},onBlur:()=>e.onRenameCommit(i),onClick:e=>e.stopPropagation(),className:`flex-1 rounded border border-neutral-700 bg-neutral-950 px-1 text-[11px] text-neutral-100 outline-none focus:border-neutral-500`}):(0,R.jsx)(`span`,{className:`truncate ${a?`text-neutral-200`:`text-neutral-300`}`,children:t.name}),t.truncated===!0&&(0,R.jsx)(`span`,{className:`ml-1 text-[10px] text-neutral-600`,children:`…`})]}),!s&&(0,R.jsxs)(`div`,{className:`hidden items-center gap-0.5 group-hover:flex`,children:[a&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`button`,{onClick:n=>{n.stopPropagation(),e.onCreate(i,t.path,`file`)},className:`rounded p-0.5 text-neutral-500 hover:bg-neutral-800 hover:text-neutral-200`,title:`New file in this folder`,children:(0,R.jsx)(Ce,{size:11})}),(0,R.jsx)(`button`,{onClick:n=>{n.stopPropagation(),e.onCreate(i,t.path,`folder`)},className:`rounded p-0.5 text-neutral-500 hover:bg-neutral-800 hover:text-neutral-200`,title:`New subfolder in this folder`,children:(0,R.jsx)(Te,{size:11})}),(0,R.jsx)(`button`,{onClick:t=>{t.stopPropagation(),e.onUpload(i)},className:`rounded p-0.5 text-neutral-500 hover:bg-neutral-800 hover:text-neutral-200`,title:`Upload into this folder`,children:(0,R.jsx)(nt,{size:11})})]}),(0,R.jsx)(`button`,{onClick:t=>{t.stopPropagation(),e.onDownload(i)},className:`rounded p-0.5 text-neutral-500 hover:bg-neutral-800 hover:text-neutral-200`,title:a?`Download folder as .tar.gz`:`Download file`,children:(0,R.jsx)(ye,{size:11})}),(0,R.jsx)(`button`,{onClick:n=>{n.stopPropagation(),e.onRenameStart(i,t.name)},className:`rounded p-0.5 text-neutral-500 hover:bg-neutral-800 hover:text-neutral-200`,title:`Rename`,children:(0,R.jsx)(Ve,{size:11})}),(0,R.jsx)(`button`,{onClick:n=>{n.stopPropagation(),e.onDelete(i,t.name,a)},className:`rounded p-0.5 text-neutral-500 hover:bg-red-900/30 hover:text-red-300 light:hover:bg-red-100 light:hover:text-red-700`,title:`Delete`,children:(0,R.jsx)($e,{size:11})})]})]}),a&&o&&t.children!==void 0&&(0,R.jsx)(`ul`,{children:t.children.map(t=>(0,R.jsx)(FM,{...e,node:t,depth:n+1},t.path))})]})}function IM(e,t){return t===``?e:`${e}/${t.replaceAll(`\\`,`/`)}`}function LM(e,t){if(e!==t)return e.startsWith(`${t}/`)?e.slice(t.length+1):e}function RM(e,t){if(e?.kind!==`create`)return``;let n=LM(e.parentAbsPath,t),r=e.entryKind===`folder`?`folder`:`file`;return n===void 0?`New ${r}`:`New ${r} in ${n}/`}function zM(e,t){if(e?.kind!==`create`)return``;let n=LM(e.parentAbsPath,t),r=e.entryKind===`folder`?`Folder name`:`File name`;return n===void 0?`${r} (relative to project root)`:`${r} (in ${n}/)`}function BM(e){return e?.kind===`create`?e.entryKind===`folder`?`utils`:`index.ts`:``}function VM(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:e<1024*1024*1024?`${(e/(1024*1024)).toFixed(1)} MB`:`${(e/(1024*1024*1024)).toFixed(2)} GB`}var HM=`forge.editor.wrap.`,UM=[];function WM(e){let t=Math.max(e.lastIndexOf(`/`),e.lastIndexOf(`\\`)),n=t===-1?e:e.slice(t+1),r=n.lastIndexOf(`.`);return r<=0?``:n.slice(r+1).toLowerCase()}function GM(e){try{let t=localStorage.getItem(HM+e);if(t===`0`)return!1;if(t===`1`)return!0}catch{}return!0}function KM(e,t){try{localStorage.setItem(HM+e,t?`1`:`0`)}catch{}}var qM=(0,v.lazy)(()=>C(()=>import(`./CodeMirrorEditor-B4s5rJXF.js`).then(e=>({default:e.CodeMirrorEditor})),[]));function JM(){let e=dr(),t=ai(e=>e.openFiles),n=ai(e=>e.activePath),r=ai(e=>e.setActiveFile),i=ai(e=>e.closeFile),a=ai(e=>e.closeAllFiles),o=ai(e=>e.updateDraft),s=ai(e=>e.saveFile),c=ai(e=>e.reloadFile),l=ai(e=>e.externallyChanged),u=ai(e=>e.gitDiffByPath),d=t.find(e=>e.path===n),f=d===void 0?``:WM(d.path),[p,m]=(0,v.useState)(()=>GM(f));(0,v.useEffect)(()=>{m(GM(f))},[f]);let h=(0,v.useCallback)(()=>{m(e=>{let t=!e;return KM(f,t),t})},[f]);return(0,R.jsxs)(`div`,{className:`flex h-full flex-col bg-neutral-950 text-sm text-neutral-200`,children:[(0,R.jsx)(XM,{files:t,activePath:n,externallyChanged:l,onActivate:r,onClose:i,onCloseAll:a}),d===void 0?(0,R.jsx)(`div`,{className:`flex flex-1 items-center justify-center text-xs italic text-neutral-500`,children:`No file open. Click a file in the tree to start editing.`}):(0,R.jsxs)(R.Fragment,{children:[l[d.path]===!0&&(0,R.jsx)(ZM,{path:d.path,onReload:()=>{e!==void 0&&c(e.id,d.path)},onDiscard:()=>ai.getState().dismissExternallyChanged(d.path)}),d.binary?(0,R.jsx)(`div`,{className:`flex flex-1 items-center justify-center px-6 text-center text-sm text-neutral-500`,children:d.loadingError??`Binary file.`}):(0,R.jsx)(v.Suspense,{fallback:(0,R.jsx)(YM,{}),children:(0,R.jsx)(qM,{file:d,wrap:p,diffChanges:u[d.path]??UM,onChange:e=>o(d.path,e),onSaveShortcut:()=>{e!==void 0&&s(e.id,d.path)},onConsumePendingNav:e=>ai.getState().consumePendingNav(e)},d.tabId)}),(0,R.jsx)(QM,{file:d,wrap:p,onToggleWrap:h,onSave:()=>{e!==void 0&&s(e.id,d.path)}})]})]})}function YM(){return(0,R.jsx)(`div`,{className:`flex flex-1 items-center justify-center text-xs italic text-neutral-500`,children:`Loading editor…`})}function XM({files:e,activePath:t,externallyChanged:n,onActivate:r,onClose:i,onCloseAll:a}){if(e.length===0)return null;let o=e.filter(e=>e.dirty).length;return(0,R.jsxs)(`div`,{className:`flex border-b border-neutral-800 bg-neutral-900/40`,children:[(0,R.jsx)(`button`,{onClick:()=>{o>0&&!window.confirm(`Close ${e.length} tab${e.length===1?``:`s`}? ${o} ha${o===1?`s`:`ve`} unsaved changes that will be lost.`)||a()},className:`flex shrink-0 items-center justify-center border-r border-neutral-800 px-2 py-1.5 text-neutral-500 hover:bg-neutral-800 hover:text-neutral-200`,title:`Close all ${e.length} tab${e.length===1?``:`s`}`,children:(0,R.jsx)(Xe,{size:14})}),(0,R.jsx)(`div`,{className:`flex flex-1 overflow-x-auto`,children:e.map(e=>{let a=e.path.split(`/`).pop()??e.path,o=e.path===t,s=n[e.path]===!0;return(0,R.jsxs)(`div`,{className:`group flex items-center gap-1 border-r border-neutral-800 px-3 py-1.5 text-xs ${o?`bg-neutral-950 text-neutral-100`:`text-neutral-400 hover:bg-neutral-900 hover:text-neutral-200`} ${s?`bg-amber-900/30 text-amber-200 light:bg-amber-100 light:text-amber-800`:``}`,title:s?`${e.path}\n\nExternal change while you have unsaved edits — open the tab to review.`:e.path,children:[(0,R.jsxs)(`button`,{onClick:()=>r(e.path),className:`truncate`,children:[s?(0,R.jsx)(et,{size:11,className:`mr-1 inline text-amber-400 light:text-amber-700`}):e.dirty?(0,R.jsx)(`span`,{className:`mr-1.5 inline-block h-2.5 w-2.5 rounded-full bg-amber-400 align-middle`,"aria-label":`Unsaved changes`,title:`Unsaved changes`}):null,a]}),(0,R.jsx)(`button`,{onClick:()=>i(e.path),className:`rounded p-1 text-neutral-600 hover:bg-neutral-800 hover:text-neutral-200`,title:`Close (any unsaved changes are lost)`,children:(0,R.jsx)(it,{size:16})})]},e.tabId)})})]})}function ZM({path:e,onReload:t,onDiscard:n}){return(0,R.jsxs)(`div`,{className:`flex items-center justify-between gap-3 border-b border-amber-700/40 bg-amber-900/20 px-4 py-1.5 text-xs text-amber-200 light:border-amber-300 light:bg-amber-50 light:text-amber-800`,children:[(0,R.jsxs)(`span`,{children:[`File changed externally — local edits in this tab are stale. Reload from disk?`,(0,R.jsx)(`span`,{className:`ml-2 font-mono text-[10px] text-amber-400/70 light:text-amber-700/80`,children:e})]}),(0,R.jsxs)(`div`,{className:`flex gap-1`,children:[(0,R.jsx)(`button`,{onClick:t,className:`rounded border border-amber-700/50 px-2 py-0.5 hover:bg-amber-900/30 light:border-amber-400 light:hover:bg-amber-100`,children:`Reload`}),(0,R.jsx)(`button`,{onClick:n,className:`rounded border border-neutral-700 px-2 py-0.5 text-neutral-300 hover:border-neutral-500`,children:`Keep mine`})]})]})}function QM({file:e,wrap:t,onToggleWrap:n,onSave:r}){let i=e.dirty,a=e.saving,o=e.savedAt,s=e.saveError,c,l=`text-neutral-500`;s===void 0?a?c=`Saving…`:i?(c=`Unsaved changes`,l=`text-amber-400 light:text-amber-700`):o===void 0?c=`Up to date`:(c=`Saved ${new Date(o).toLocaleTimeString()}`,l=`text-emerald-500 light:text-emerald-700`):(c=`Save failed (${s}) — Cmd/Ctrl+S or Save to retry`,l=`text-rose-400 light:text-rose-700`);let u=(i||s!==void 0)&&!a&&!e.binary;return(0,R.jsxs)(`div`,{className:`flex items-center justify-between gap-3 border-t border-neutral-800 bg-neutral-900/40 px-3 py-1 text-[11px]`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,R.jsx)(`span`,{className:`font-mono text-neutral-500`,children:e.language}),(0,R.jsxs)(`button`,{onClick:n,className:`flex items-center gap-1 rounded px-1 py-0.5 text-[10px] hover:bg-neutral-800 ${t?`text-neutral-300`:`text-neutral-500`}`,title:t?`Wrap on (click to switch to horizontal scroll, persisted per file extension)`:`Wrap off (click to enable wrap, persisted per file extension)`,children:[(0,R.jsx)(Qe,{size:11}),t?`wrap`:`no wrap`]})]}),(0,R.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,R.jsx)(`span`,{className:l,children:c}),(0,R.jsxs)(`button`,{onClick:r,disabled:!u,className:`flex items-center gap-1 rounded border border-neutral-700 px-1.5 py-0.5 text-[10px] text-neutral-200 hover:border-neutral-500 disabled:cursor-not-allowed disabled:border-neutral-800 disabled:text-neutral-600`,title:`Save (Cmd/Ctrl+S)`,children:[(0,R.jsx)(Ke,{size:11}),`Save`]})]})]})}var $M=o(((e,t)=>{(function(n,r){if(typeof e==`object`&&typeof t==`object`)t.exports=r();else if(typeof define==`function`&&define.amd)define([],r);else{var i=r();for(var a in i)(typeof e==`object`?e:n)[a]=i[a]}})(globalThis,(()=>(()=>{var e={4567:function(e,t,n){var r=this&&this.__decorate||function(e,t,n,r){var i,a=arguments.length,o=a<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)o=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o},i=this&&this.__param||function(e,t){return function(n,r){t(n,r,e)}};Object.defineProperty(t,"__esModule",{value:!0}),t.AccessibilityManager=void 0;let a=n(9042),o=n(9924),s=n(844),c=n(4725),l=n(2585),u=n(3656),d=t.AccessibilityManager=class extends s.Disposable{constructor(e,t,n,r){super(),this._terminal=e,this._coreBrowserService=n,this._renderService=r,this._rowColumns=new WeakMap,this._liveRegionLineCount=0,this._charsToConsume=[],this._charsToAnnounce=``,this._accessibilityContainer=this._coreBrowserService.mainDocument.createElement(`div`),this._accessibilityContainer.classList.add(`xterm-accessibility`),this._rowContainer=this._coreBrowserService.mainDocument.createElement(`div`),this._rowContainer.setAttribute(`role`,`list`),this._rowContainer.classList.add(`xterm-accessibility-tree`),this._rowElements=[];for(let e=0;e<this._terminal.rows;e++)this._rowElements[e]=this._createAccessibilityTreeNode(),this._rowContainer.appendChild(this._rowElements[e]);if(this._topBoundaryFocusListener=e=>this._handleBoundaryFocus(e,0),this._bottomBoundaryFocusListener=e=>this._handleBoundaryFocus(e,1),this._rowElements[0].addEventListener(`focus`,this._topBoundaryFocusListener),this._rowElements[this._rowElements.length-1].addEventListener(`focus`,this._bottomBoundaryFocusListener),this._refreshRowsDimensions(),this._accessibilityContainer.appendChild(this._rowContainer),this._liveRegion=this._coreBrowserService.mainDocument.createElement(`div`),this._liveRegion.classList.add(`live-region`),this._liveRegion.setAttribute(`aria-live`,`assertive`),this._accessibilityContainer.appendChild(this._liveRegion),this._liveRegionDebouncer=this.register(new o.TimeBasedDebouncer(this._renderRows.bind(this))),!this._terminal.element)throw Error(`Cannot enable accessibility before Terminal.open`);this._terminal.element.insertAdjacentElement(`afterbegin`,this._accessibilityContainer),this.register(this._terminal.onResize((e=>this._handleResize(e.rows)))),this.register(this._terminal.onRender((e=>this._refreshRows(e.start,e.end)))),this.register(this._terminal.onScroll((()=>this._refreshRows()))),this.register(this._terminal.onA11yChar((e=>this._handleChar(e)))),this.register(this._terminal.onLineFeed((()=>this._handleChar(`
|
|
365
|
+
`)})]}),(0,R.jsxs)(`div`,{className:`flex gap-2 text-[10px]`,children:[(0,R.jsx)(FM,{sessionId:t,processId:e.id,stream:`stdout`}),(0,R.jsx)(FM,{sessionId:t,processId:e.id,stream:`stderr`})]})]})]})}function jM(e){return e===`running`||e===`terminating`?`border-neutral-700 light:border-neutral-300`:e===`terminate_timeout`?`border-amber-700/50 light:border-amber-400`:e===`killed`?`border-amber-700/40 light:border-amber-400`:`border-neutral-800 light:border-neutral-200`}function MM({status:e,success:t}){return e===`running`?(0,R.jsx)(Ne,{size:11,className:`mt-0.5 shrink-0 animate-spin text-emerald-400 light:text-emerald-700`,"aria-label":`running`}):e===`terminating`||e===`terminate_timeout`?(0,R.jsx)(at,{size:11,className:`mt-0.5 shrink-0 text-amber-400 light:text-amber-700`,"aria-label":`terminating`}):e===`killed`?(0,R.jsx)(et,{size:11,className:`mt-0.5 shrink-0 text-amber-400 light:text-amber-700`,"aria-label":`killed`}):t===!0?(0,R.jsx)(pe,{size:11,className:`mt-0.5 shrink-0 text-emerald-400 light:text-emerald-700`,"aria-label":`exited 0`}):(0,R.jsx)(me,{size:11,className:`mt-0.5 shrink-0 text-red-400 light:text-red-700`,"aria-label":`exited non-zero`})}function NM(e,t){let n=(t??Date.now())-e;if(n<1e3)return`${n}ms`;let r=n/1e3;if(r<60)return`${r.toFixed(1)}s`;let i=r/60;return i<60?`${i.toFixed(1)}m`:`${(i/60).toFixed(1)}h`}function PM(e){return e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`).replace(/'/g,`'`)}function FM({sessionId:e,processId:t,stream:n}){let[r,i]=(0,v.useState)(!1),[a,o]=(0,v.useState)(void 0);return(0,R.jsx)(`button`,{type:`button`,onClick:()=>{let r=window.open(`about:blank`,`_blank`);if(r===null){o(`popup blocked — allow popups for this site`);return}i(!0),o(void 0),(async()=>{try{let i=L.processLogFileUrl(e,t,n),a=Vt(),s={};a!==void 0&&(s.Authorization=`Bearer ${a.token}`);let c=await fetch(i,{headers:s});if(!c.ok){r.close(),o(`${c.status} ${c.statusText}`);return}let l=await c.text(),u=`<!doctype html><html><head><meta charset="utf-8"><title>${PM(`${n} — ${t}`)}</title><meta name="color-scheme" content="dark light"><style>html,body{margin:0;padding:0;background:#0a0a0a;color:#e5e5e5;font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:13px;line-height:1.5;tab-size:4}@media (prefers-color-scheme: light){html,body{background:#fafafa;color:#171717}}pre{margin:0;padding:1rem;white-space:pre-wrap;word-break:break-word}</style></head><body><pre>${PM(l)}</pre></body></html>`,d=new Blob([u],{type:`text/html;charset=utf-8`}),f=URL.createObjectURL(d);r.location.href=f,setTimeout(()=>URL.revokeObjectURL(f),6e4)}catch(e){r.close(),o(e instanceof Error?e.message:String(e))}finally{i(!1)}})()},disabled:r,className:`text-sky-400 hover:underline disabled:opacity-50 light:text-sky-700`,title:a,children:r?`loading…`:a===void 0?`full ${n} log`:`${n}: ${a}`})}function IM(){let e=dr(),t=ai(t=>e===void 0?void 0:t.treeByProject[e.id]),n=ai(t=>e===void 0?!1:t.treeLoading[e.id]??!1),r=ai(e=>e.error),i=ai(e=>e.loadTree),a=ai(e=>e.openFile),o=ai(e=>e.createFile),s=ai(e=>e.createFolder),c=ai(e=>e.renameEntry),l=ai(e=>e.moveEntry),u=ai(e=>e.deleteEntry),[d,f]=(0,v.useState)({"":!0}),[p,m]=(0,v.useState)(void 0),[h,g]=(0,v.useState)(``),[_,y]=(0,v.useState)(void 0),[b,x]=(0,v.useState)(void 0),[S,C]=(0,v.useState)(void 0),w=(0,v.useRef)(null),T=(0,v.useRef)(void 0),E=ai(e=>e.uploadFiles),[D,O]=(0,v.useState)(void 0),k=QA(e=>e.requestChatInsert),ee=QA(e=>e.openEditorPane),[A,te]=(0,v.useState)(new Set);if((0,v.useEffect)(()=>{e!==void 0&&i(e.id)},[e?.id,i]),e===void 0)return(0,R.jsx)(`div`,{className:`p-4 text-xs italic text-neutral-500`,children:`Select a project to browse its files.`});let ne=async(t,n,r)=>{x(void 0);try{if(t===`file`){let t=await o(e.id,n,r);await a(e.id,t),ee()}else await s(e.id,n,r)}catch{}},re=(e,t,n)=>{f(e=>({...e,[t]:!0})),x({kind:`create`,entryKind:n,parentAbsPath:e})},ie=(e,t)=>{m(e),g(t)},j=async t=>{let n=h.trim();if(m(void 0),g(``),n.length!==0)try{await c(e.id,t,n)}catch{}},ae=()=>te(new Set),M=e=>{te(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},oe=(e,t,n)=>{x({kind:`delete`,absPath:e,name:t,isDir:n,recursive:!1})},se=async()=>{if(b?.kind!==`delete`)return;let{absPath:t,name:n,isDir:r,recursive:i}=b;x(void 0);try{await u(e.id,t,i?{recursive:!0}:void 0)}catch(e){if(e instanceof N&&e.code===`directory_not_empty`){x({kind:`delete`,absPath:t,name:n,isDir:r,recursive:!0});return}}},ce=async()=>{if(b?.kind!==`deleteMany`)return;let{paths:t}=b;x(void 0);for(let n of t)try{await u(e.id,n,{recursive:!0})}catch{}ae()},le=async t=>{if(t.type===`directory`){f(e=>({...e,[t.path]:!e[t.path]}));return}await a(e.id,BM(e.path,t.path)),ee()},ue=(e,t)=>{e.preventDefault(),e.stopPropagation(),O({x:e.clientX,y:e.clientY,kind:t.isDir?`folder`:`file`,absPath:t.absPath,name:t.name,relPath:t.relPath})},de=t=>{t.preventDefault(),O({x:t.clientX,y:t.clientY,kind:`empty`,absPath:e.path,name:``,relPath:``})},fe=t=>{let n=t;t.startsWith(`${e.path}/`)&&(n=t.slice(e.path.length+1)),k(/\s/.test(n)?`@"${n}"`:`@${n}`),O(void 0)},pe=async(t,n)=>{if(t.preventDefault(),t.stopPropagation(),y(void 0),t.dataTransfer.files.length>0){await me(n,Array.from(t.dataTransfer.files));return}let r=t.dataTransfer.getData(`application/x-pi-path`);if(r.length===0)return;let i=r.split(`/`).pop()??``;if(i.length===0)return;let a=`${n}/${i}`;if(a!==r&&!(n===r||n.startsWith(`${r}/`)))try{await l(e.id,r,a)}catch{}},me=async(t,n)=>{if(n.length===0)return;let r=n.reduce((e,t)=>e+t.size,0);C(`Hashing ${n.length} file${n.length===1?``:`s`} (${GM(r)})…`);try{let r=await E(e.id,t,n,{onHashProgress:(e,t)=>{C(e<t?`Hashing ${GM(e)} / ${GM(t)} (${Math.floor(e/t*100)}%)…`:`Uploading ${n.length} file${n.length===1?``:`s`} (${GM(t)})…`)}});C(`Uploaded ${r.length} file${r.length===1?``:`s`}.`),window.setTimeout(()=>C(void 0),2500)}catch{C(void 0)}},he=e=>{T.current=e,w.current?.click()},ge=async t=>{C(`Preparing download…`);try{let{blob:n,filename:r}=await L.filesDownload(e.id,t),i=URL.createObjectURL(n),a=document.createElement(`a`);a.href=i,a.download=r,document.body.appendChild(a),a.click(),a.remove(),window.setTimeout(()=>URL.revokeObjectURL(i),1e3),C(void 0)}catch(e){C(void 0),ai.setState({error:e instanceof Error?e.message:`download_failed`})}},_e=async t=>{let n=t.target.files,r=n===null?[]:Array.from(n),i=T.current??e.path;t.target.value=``,T.current=void 0,r.length!==0&&await me(i,r)};return(0,R.jsxs)(`div`,{className:`flex h-full flex-col text-xs text-neutral-300`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between border-b border-neutral-800 px-3 py-2`,children:[(0,R.jsx)(`span`,{className:`truncate font-medium text-neutral-200`,title:e.path,children:e.name}),(0,R.jsxs)(`div`,{className:`flex gap-1`,children:[(0,R.jsx)(`button`,{onClick:()=>x({kind:`create`,entryKind:`file`,parentAbsPath:e.path}),className:`rounded p-1 text-neutral-400 hover:bg-neutral-800 hover:text-neutral-200`,title:`New file`,children:(0,R.jsx)(Ce,{size:14})}),(0,R.jsx)(`button`,{onClick:()=>x({kind:`create`,entryKind:`folder`,parentAbsPath:e.path}),className:`rounded p-1 text-neutral-400 hover:bg-neutral-800 hover:text-neutral-200`,title:`New folder`,children:(0,R.jsx)(Te,{size:14})}),(0,R.jsx)(`button`,{onClick:()=>he(e.path),className:`rounded p-1 text-neutral-400 hover:bg-neutral-800 hover:text-neutral-200`,title:`Upload files into project root (drag-and-drop also works on any folder)`,children:(0,R.jsx)(nt,{size:14})}),(0,R.jsx)(`button`,{onClick:()=>void ge(void 0),className:`rounded p-1 text-neutral-400 hover:bg-neutral-800 hover:text-neutral-200`,title:`Download project as .tar.gz (skips node_modules, .git, dist, etc.)`,children:(0,R.jsx)(ye,{size:14})}),(0,R.jsx)(`button`,{onClick:()=>void i(e.id),className:`rounded p-1 text-neutral-400 hover:bg-neutral-800 hover:text-neutral-200`,title:`Refresh`,children:(0,R.jsx)(Ue,{size:14,className:n?`animate-spin`:``})})]})]}),(0,R.jsx)(`input`,{ref:w,type:`file`,multiple:!0,className:`hidden`,onChange:e=>void _e(e)}),S!==void 0&&(0,R.jsxs)(`div`,{className:`flex items-center gap-1.5 border-b border-emerald-700/40 bg-emerald-900/20 px-3 py-1.5 text-[11px] text-emerald-200 light:border-emerald-300 light:bg-emerald-50 light:text-emerald-800`,children:[!S.startsWith(`Uploaded`)&&(0,R.jsx)(Ne,{size:11,className:`animate-spin`}),(0,R.jsx)(`span`,{children:S})]}),r!==void 0&&(0,R.jsx)(`div`,{className:`border-b border-red-700/40 bg-red-900/20 px-3 py-1.5 text-[11px] text-red-300 light:border-red-300 light:bg-red-50 light:text-red-700`,children:r}),A.size>0&&(0,R.jsxs)(`div`,{className:`flex items-center justify-between gap-2 border-b border-neutral-800 bg-neutral-900/60 px-3 py-1.5 text-[11px] text-neutral-300`,children:[(0,R.jsxs)(`span`,{children:[A.size,` selected`,(0,R.jsx)(`span`,{className:`ml-2 text-neutral-500`,children:`(Cmd/Ctrl+click rows to add or remove)`})]}),(0,R.jsxs)(`div`,{className:`flex gap-1`,children:[(0,R.jsx)(`button`,{onClick:()=>x({kind:`deleteMany`,paths:Array.from(A)}),className:`rounded border border-red-700/50 px-2 py-0.5 text-red-300 hover:bg-red-900/20 light:border-red-400 light:text-red-700 light:hover:bg-red-50`,children:`Delete selected`}),(0,R.jsx)(`button`,{onClick:ae,className:`rounded border border-neutral-700 px-2 py-0.5 text-neutral-300 hover:border-neutral-500`,children:`Clear`})]})]}),(0,R.jsxs)(`div`,{className:`flex-1 overflow-y-auto py-1`,onContextMenu:de,onDragOver:e=>{(e.dataTransfer.types.includes(`application/x-pi-path`)||e.dataTransfer.types.includes(`Files`))&&(e.preventDefault(),e.dataTransfer.dropEffect=e.dataTransfer.types.includes(`Files`)?`copy`:`move`)},onDrop:t=>void pe(t,e.path),children:[t===void 0&&!n&&(0,R.jsx)(`p`,{className:`px-3 py-2 italic text-neutral-500`,children:`Tree not loaded.`}),t!==void 0&&(0,R.jsx)(zM,{node:t,depth:0,projectPath:e.path,expanded:d,onToggle:e=>f(t=>({...t,[e]:!t[e]})),onOpen:e=>void le(e),renaming:p,renameDraft:h,onRenameDraftChange:g,onRenameCommit:e=>void j(e),onRenameStart:ie,onDelete:(e,t,n)=>oe(e,t,n),onCreate:(e,t,n)=>re(e,t,n),onUpload:e=>he(e),onDownload:e=>void ge(e),dropTarget:_,onDropTargetChange:y,onDrop:(e,t)=>void pe(e,t),onContextMenu:ue,selectedPaths:A,onToggleSelect:M})]}),(0,R.jsx)(Ti,{open:b?.kind===`create`,onClose:()=>x(void 0),onSubmit:e=>{b?.kind===`create`&&ne(b.entryKind,b.parentAbsPath,e)},title:HM(b,e.path),label:UM(b,e.path),placeholder:WM(b),primaryLabel:`Create`}),(0,R.jsx)(Ei,{open:b?.kind===`delete`,onClose:()=>x(void 0),onConfirm:()=>void se(),title:b?.kind===`delete`?b.recursive?`"${b.name}" is not empty`:b.isDir?`Delete directory`:`Delete file`:``,message:b?.kind===`delete`?b.recursive?`"${b.name}" contains files. Delete the directory and ALL its contents? This cannot be undone.`:`Delete ${b.isDir?`directory`:`file`} "${b.name}"? This cannot be undone.`:``,primaryLabel:b?.kind===`delete`&&b.recursive?`Delete contents`:`Delete`,tone:`danger`}),(0,R.jsx)(Ei,{open:b?.kind===`deleteMany`,onClose:()=>x(void 0),onConfirm:()=>void ce(),title:b?.kind===`deleteMany`?`Delete ${b.paths.length} item${b.paths.length===1?``:`s`}`:``,message:b?.kind===`deleteMany`?`Delete the ${b.paths.length} selected file${b.paths.length===1?``:`s`} / folder${b.paths.length===1?``:`s`}? Folders are deleted recursively. This cannot be undone.`:``,primaryLabel:`Delete all`,tone:`danger`}),D!==void 0&&(0,R.jsx)(LM,{x:D.x,y:D.y,kind:D.kind,onClose:()=>O(void 0),onAddAsContext:()=>fe(D.absPath),...D.kind!==`empty`&&{onRename:()=>ie(D.absPath,D.name),onDelete:()=>oe(D.absPath,D.name,D.kind===`folder`),onDownload:()=>void ge(D.absPath)},...D.kind!==`file`&&{onAddFile:()=>re(D.absPath,D.relPath,`file`),onAddFolder:()=>re(D.absPath,D.relPath,`folder`)}})]})}function LM(e){let t=(0,v.useRef)(e.onClose);t.current=e.onClose,(0,v.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t.current()},n=()=>t.current();window.addEventListener(`keydown`,e);let r=setTimeout(()=>window.addEventListener(`mousedown`,n),0);return()=>{window.removeEventListener(`keydown`,e),window.removeEventListener(`mousedown`,n),clearTimeout(r)}},[]);let n=t=>{if(t!==void 0)return()=>{t(),e.onClose()}},r=e.kind===`empty`?void 0:n(e.onAddAsContext),i=n(e.onRename),a=n(e.onDelete),o=n(e.onDownload),s=n(e.onAddFile),c=n(e.onAddFolder);return(0,R.jsxs)(`div`,{className:`fixed z-50 min-w-[200px] overflow-hidden rounded-md border border-neutral-700 bg-neutral-900 shadow-lg`,style:{left:e.x,top:e.y},onMouseDown:e=>e.stopPropagation(),children:[r!==void 0&&(0,R.jsx)(RM,{onClick:r,icon:(0,R.jsx)(se,{size:12}),label:`Add as @ context`,title:e.kind===`folder`?`Append @<path>/ to the chat input so the model can ls / grep this folder`:`Append @<path> to the chat input so the file's content is sent with the next prompt`}),s!==void 0&&(0,R.jsx)(RM,{onClick:s,icon:(0,R.jsx)(Ce,{size:12}),label:`Add file`,title:e.kind===`folder`?`Create a new file inside this folder`:`Create a new file at the project root`}),c!==void 0&&(0,R.jsx)(RM,{onClick:c,icon:(0,R.jsx)(Te,{size:12}),label:`Add folder`,title:e.kind===`folder`?`Create a new subfolder inside this folder`:`Create a new folder at the project root`}),i!==void 0&&(0,R.jsx)(RM,{onClick:i,icon:(0,R.jsx)(Ve,{size:12}),label:`Rename`,title:`Rename this file or folder`}),o!==void 0&&(0,R.jsx)(RM,{onClick:o,icon:(0,R.jsx)(ye,{size:12}),label:`Download`,title:e.kind===`folder`?`Download folder as .tar.gz`:`Download this file`}),a!==void 0&&(0,R.jsx)(RM,{onClick:a,icon:(0,R.jsx)($e,{size:12}),label:`Delete`,title:`Delete this file or folder`,tone:`danger`})]})}function RM(e){let t=e.tone===`danger`;return(0,R.jsxs)(`button`,{type:`button`,onClick:e.onClick,title:e.title,className:`flex w-full items-center gap-2 px-3 py-1.5 text-left text-xs ${t?`text-red-300 hover:bg-red-900/30 hover:text-red-100 light:text-red-700 light:hover:bg-red-100 light:hover:text-red-900`:`text-neutral-200 hover:bg-neutral-800`}`,children:[e.icon,e.label]})}function zM(e){let{node:t,depth:n,projectPath:r}=e;if(n===0&&t.type===`directory`)return(0,R.jsx)(`ul`,{children:t.children?.map(t=>(0,R.jsx)(zM,{...e,node:t,depth:1},t.path))});let i=BM(r,t.path),a=t.type===`directory`,o=a&&(e.expanded[t.path]??!1),s=e.renaming===i,c=a&&e.dropTarget===i;return(0,R.jsxs)(`li`,{children:[(0,R.jsxs)(`div`,{className:`group flex items-center gap-1 border-l-2 py-0.5 pr-2 ${e.selectedPaths.has(i)?`border-blue-400 bg-blue-500/15 hover:bg-blue-500/25`:`border-transparent hover:bg-neutral-900`} ${c?`bg-emerald-900/30 ring-1 ring-emerald-700/50`:``}`,style:{paddingLeft:`${n*12+6}px`},onContextMenu:s?void 0:n=>e.onContextMenu(n,{absPath:i,isDir:a,name:t.name,relPath:t.path}),draggable:!s,onDragStart:e=>{e.dataTransfer.setData(`application/x-pi-path`,i),e.dataTransfer.effectAllowed=`move`},onDragOver:a?t=>{let n=t.dataTransfer.types.includes(`Files`),r=t.dataTransfer.types.includes(`application/x-pi-path`);!n&&!r||(t.preventDefault(),t.stopPropagation(),t.dataTransfer.dropEffect=n?`copy`:`move`,e.dropTarget!==i&&e.onDropTargetChange(i))}:void 0,onDragLeave:a?()=>{e.dropTarget===i&&e.onDropTargetChange(void 0)}:void 0,onDrop:a?t=>{t.stopPropagation(),e.onDrop(t,i)}:void 0,children:[(0,R.jsxs)(`button`,{onClick:n=>{if(n.metaKey||n.ctrlKey){e.onToggleSelect(i);return}e.onOpen(t)},className:`flex flex-1 items-center gap-1 truncate text-left`,title:i,children:[a?o?(0,R.jsx)(ue,{size:12,className:`text-neutral-500`}):(0,R.jsx)(fe,{size:12,className:`text-neutral-500`}):(0,R.jsx)(`span`,{className:`inline-block w-3`}),s?(0,R.jsx)(`input`,{autoFocus:!0,value:e.renameDraft,onChange:t=>e.onRenameDraftChange(t.target.value),onKeyDown:t=>{(t.key===`Enter`||t.key===`Escape`)&&(t.preventDefault(),e.onRenameCommit(i))},onBlur:()=>e.onRenameCommit(i),onClick:e=>e.stopPropagation(),className:`flex-1 rounded border border-neutral-700 bg-neutral-950 px-1 text-[11px] text-neutral-100 outline-none focus:border-neutral-500`}):(0,R.jsx)(`span`,{className:`truncate ${a?`text-neutral-200`:`text-neutral-300`}`,children:t.name}),t.truncated===!0&&(0,R.jsx)(`span`,{className:`ml-1 text-[10px] text-neutral-600`,children:`…`})]}),!s&&(0,R.jsxs)(`div`,{className:`hidden items-center gap-0.5 group-hover:flex`,children:[a&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`button`,{onClick:n=>{n.stopPropagation(),e.onCreate(i,t.path,`file`)},className:`rounded p-0.5 text-neutral-500 hover:bg-neutral-800 hover:text-neutral-200`,title:`New file in this folder`,children:(0,R.jsx)(Ce,{size:11})}),(0,R.jsx)(`button`,{onClick:n=>{n.stopPropagation(),e.onCreate(i,t.path,`folder`)},className:`rounded p-0.5 text-neutral-500 hover:bg-neutral-800 hover:text-neutral-200`,title:`New subfolder in this folder`,children:(0,R.jsx)(Te,{size:11})}),(0,R.jsx)(`button`,{onClick:t=>{t.stopPropagation(),e.onUpload(i)},className:`rounded p-0.5 text-neutral-500 hover:bg-neutral-800 hover:text-neutral-200`,title:`Upload into this folder`,children:(0,R.jsx)(nt,{size:11})})]}),(0,R.jsx)(`button`,{onClick:t=>{t.stopPropagation(),e.onDownload(i)},className:`rounded p-0.5 text-neutral-500 hover:bg-neutral-800 hover:text-neutral-200`,title:a?`Download folder as .tar.gz`:`Download file`,children:(0,R.jsx)(ye,{size:11})}),(0,R.jsx)(`button`,{onClick:n=>{n.stopPropagation(),e.onRenameStart(i,t.name)},className:`rounded p-0.5 text-neutral-500 hover:bg-neutral-800 hover:text-neutral-200`,title:`Rename`,children:(0,R.jsx)(Ve,{size:11})}),(0,R.jsx)(`button`,{onClick:n=>{n.stopPropagation(),e.onDelete(i,t.name,a)},className:`rounded p-0.5 text-neutral-500 hover:bg-red-900/30 hover:text-red-300 light:hover:bg-red-100 light:hover:text-red-700`,title:`Delete`,children:(0,R.jsx)($e,{size:11})})]})]}),a&&o&&t.children!==void 0&&(0,R.jsx)(`ul`,{children:t.children.map(t=>(0,R.jsx)(zM,{...e,node:t,depth:n+1},t.path))})]})}function BM(e,t){return t===``?e:`${e}/${t.replaceAll(`\\`,`/`)}`}function VM(e,t){if(e!==t)return e.startsWith(`${t}/`)?e.slice(t.length+1):e}function HM(e,t){if(e?.kind!==`create`)return``;let n=VM(e.parentAbsPath,t),r=e.entryKind===`folder`?`folder`:`file`;return n===void 0?`New ${r}`:`New ${r} in ${n}/`}function UM(e,t){if(e?.kind!==`create`)return``;let n=VM(e.parentAbsPath,t),r=e.entryKind===`folder`?`Folder name`:`File name`;return n===void 0?`${r} (relative to project root)`:`${r} (in ${n}/)`}function WM(e){return e?.kind===`create`?e.entryKind===`folder`?`utils`:`index.ts`:``}function GM(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:e<1024*1024*1024?`${(e/(1024*1024)).toFixed(1)} MB`:`${(e/(1024*1024*1024)).toFixed(2)} GB`}var KM=`forge.editor.wrap.`,qM=[];function JM(e){let t=Math.max(e.lastIndexOf(`/`),e.lastIndexOf(`\\`)),n=t===-1?e:e.slice(t+1),r=n.lastIndexOf(`.`);return r<=0?``:n.slice(r+1).toLowerCase()}function YM(e){try{let t=localStorage.getItem(KM+e);if(t===`0`)return!1;if(t===`1`)return!0}catch{}return!0}function XM(e,t){try{localStorage.setItem(KM+e,t?`1`:`0`)}catch{}}var ZM=(0,v.lazy)(()=>C(()=>import(`./CodeMirrorEditor-iLMm0PBW.js`).then(e=>({default:e.CodeMirrorEditor})),[]));function QM(){let e=dr(),t=ai(e=>e.openFiles),n=ai(e=>e.activePath),r=ai(e=>e.setActiveFile),i=ai(e=>e.closeFile),a=ai(e=>e.closeAllFiles),o=ai(e=>e.updateDraft),s=ai(e=>e.saveFile),c=ai(e=>e.reloadFile),l=ai(e=>e.externallyChanged),u=ai(e=>e.gitDiffByPath),d=t.find(e=>e.path===n),f=d===void 0?``:JM(d.path),[p,m]=(0,v.useState)(()=>YM(f));(0,v.useEffect)(()=>{m(YM(f))},[f]);let h=(0,v.useCallback)(()=>{m(e=>{let t=!e;return XM(f,t),t})},[f]);return(0,R.jsxs)(`div`,{className:`flex h-full flex-col bg-neutral-950 text-sm text-neutral-200`,children:[(0,R.jsx)(eN,{files:t,activePath:n,externallyChanged:l,onActivate:r,onClose:i,onCloseAll:a}),d===void 0?(0,R.jsx)(`div`,{className:`flex flex-1 items-center justify-center text-xs italic text-neutral-500`,children:`No file open. Click a file in the tree to start editing.`}):(0,R.jsxs)(R.Fragment,{children:[l[d.path]===!0&&(0,R.jsx)(tN,{path:d.path,onReload:()=>{e!==void 0&&c(e.id,d.path)},onDiscard:()=>ai.getState().dismissExternallyChanged(d.path)}),d.binary?(0,R.jsx)(`div`,{className:`flex flex-1 items-center justify-center px-6 text-center text-sm text-neutral-500`,children:d.loadingError??`Binary file.`}):(0,R.jsx)(v.Suspense,{fallback:(0,R.jsx)($M,{}),children:(0,R.jsx)(ZM,{file:d,wrap:p,diffChanges:u[d.path]??qM,onChange:e=>o(d.path,e),onSaveShortcut:()=>{e!==void 0&&s(e.id,d.path)},onConsumePendingNav:e=>ai.getState().consumePendingNav(e)},d.tabId)}),(0,R.jsx)(nN,{file:d,wrap:p,onToggleWrap:h,onSave:()=>{e!==void 0&&s(e.id,d.path)}})]})]})}function $M(){return(0,R.jsx)(`div`,{className:`flex flex-1 items-center justify-center text-xs italic text-neutral-500`,children:`Loading editor…`})}function eN({files:e,activePath:t,externallyChanged:n,onActivate:r,onClose:i,onCloseAll:a}){if(e.length===0)return null;let o=e.filter(e=>e.dirty).length;return(0,R.jsxs)(`div`,{className:`flex border-b border-neutral-800 bg-neutral-900/40`,children:[(0,R.jsx)(`button`,{onClick:()=>{o>0&&!window.confirm(`Close ${e.length} tab${e.length===1?``:`s`}? ${o} ha${o===1?`s`:`ve`} unsaved changes that will be lost.`)||a()},className:`flex shrink-0 items-center justify-center border-r border-neutral-800 px-2 py-1.5 text-neutral-500 hover:bg-neutral-800 hover:text-neutral-200`,title:`Close all ${e.length} tab${e.length===1?``:`s`}`,children:(0,R.jsx)(Xe,{size:14})}),(0,R.jsx)(`div`,{className:`flex flex-1 overflow-x-auto`,children:e.map(e=>{let a=e.path.split(`/`).pop()??e.path,o=e.path===t,s=n[e.path]===!0;return(0,R.jsxs)(`div`,{className:`group flex items-center gap-1 border-r border-neutral-800 px-3 py-1.5 text-xs ${o?`bg-neutral-950 text-neutral-100`:`text-neutral-400 hover:bg-neutral-900 hover:text-neutral-200`} ${s?`bg-amber-900/30 text-amber-200 light:bg-amber-100 light:text-amber-800`:``}`,title:s?`${e.path}\n\nExternal change while you have unsaved edits — open the tab to review.`:e.path,children:[(0,R.jsxs)(`button`,{onClick:()=>r(e.path),className:`truncate`,children:[s?(0,R.jsx)(et,{size:11,className:`mr-1 inline text-amber-400 light:text-amber-700`}):e.dirty?(0,R.jsx)(`span`,{className:`mr-1.5 inline-block h-2.5 w-2.5 rounded-full bg-amber-400 align-middle`,"aria-label":`Unsaved changes`,title:`Unsaved changes`}):null,a]}),(0,R.jsx)(`button`,{onClick:()=>i(e.path),className:`rounded p-1 text-neutral-600 hover:bg-neutral-800 hover:text-neutral-200`,title:`Close (any unsaved changes are lost)`,children:(0,R.jsx)(it,{size:16})})]},e.tabId)})})]})}function tN({path:e,onReload:t,onDiscard:n}){return(0,R.jsxs)(`div`,{className:`flex items-center justify-between gap-3 border-b border-amber-700/40 bg-amber-900/20 px-4 py-1.5 text-xs text-amber-200 light:border-amber-300 light:bg-amber-50 light:text-amber-800`,children:[(0,R.jsxs)(`span`,{children:[`File changed externally — local edits in this tab are stale. Reload from disk?`,(0,R.jsx)(`span`,{className:`ml-2 font-mono text-[10px] text-amber-400/70 light:text-amber-700/80`,children:e})]}),(0,R.jsxs)(`div`,{className:`flex gap-1`,children:[(0,R.jsx)(`button`,{onClick:t,className:`rounded border border-amber-700/50 px-2 py-0.5 hover:bg-amber-900/30 light:border-amber-400 light:hover:bg-amber-100`,children:`Reload`}),(0,R.jsx)(`button`,{onClick:n,className:`rounded border border-neutral-700 px-2 py-0.5 text-neutral-300 hover:border-neutral-500`,children:`Keep mine`})]})]})}function nN({file:e,wrap:t,onToggleWrap:n,onSave:r}){let i=e.dirty,a=e.saving,o=e.savedAt,s=e.saveError,c,l=`text-neutral-500`;s===void 0?a?c=`Saving…`:i?(c=`Unsaved changes`,l=`text-amber-400 light:text-amber-700`):o===void 0?c=`Up to date`:(c=`Saved ${new Date(o).toLocaleTimeString()}`,l=`text-emerald-500 light:text-emerald-700`):(c=`Save failed (${s}) — Cmd/Ctrl+S or Save to retry`,l=`text-rose-400 light:text-rose-700`);let u=(i||s!==void 0)&&!a&&!e.binary;return(0,R.jsxs)(`div`,{className:`flex items-center justify-between gap-3 border-t border-neutral-800 bg-neutral-900/40 px-3 py-1 text-[11px]`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,R.jsx)(`span`,{className:`font-mono text-neutral-500`,children:e.language}),(0,R.jsxs)(`button`,{onClick:n,className:`flex items-center gap-1 rounded px-1 py-0.5 text-[10px] hover:bg-neutral-800 ${t?`text-neutral-300`:`text-neutral-500`}`,title:t?`Wrap on (click to switch to horizontal scroll, persisted per file extension)`:`Wrap off (click to enable wrap, persisted per file extension)`,children:[(0,R.jsx)(Qe,{size:11}),t?`wrap`:`no wrap`]})]}),(0,R.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,R.jsx)(`span`,{className:l,children:c}),(0,R.jsxs)(`button`,{onClick:r,disabled:!u,className:`flex items-center gap-1 rounded border border-neutral-700 px-1.5 py-0.5 text-[10px] text-neutral-200 hover:border-neutral-500 disabled:cursor-not-allowed disabled:border-neutral-800 disabled:text-neutral-600`,title:`Save (Cmd/Ctrl+S)`,children:[(0,R.jsx)(Ke,{size:11}),`Save`]})]})]})}var rN=o(((e,t)=>{(function(n,r){if(typeof e==`object`&&typeof t==`object`)t.exports=r();else if(typeof define==`function`&&define.amd)define([],r);else{var i=r();for(var a in i)(typeof e==`object`?e:n)[a]=i[a]}})(globalThis,(()=>(()=>{var e={4567:function(e,t,n){var r=this&&this.__decorate||function(e,t,n,r){var i,a=arguments.length,o=a<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)o=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o},i=this&&this.__param||function(e,t){return function(n,r){t(n,r,e)}};Object.defineProperty(t,"__esModule",{value:!0}),t.AccessibilityManager=void 0;let a=n(9042),o=n(9924),s=n(844),c=n(4725),l=n(2585),u=n(3656),d=t.AccessibilityManager=class extends s.Disposable{constructor(e,t,n,r){super(),this._terminal=e,this._coreBrowserService=n,this._renderService=r,this._rowColumns=new WeakMap,this._liveRegionLineCount=0,this._charsToConsume=[],this._charsToAnnounce=``,this._accessibilityContainer=this._coreBrowserService.mainDocument.createElement(`div`),this._accessibilityContainer.classList.add(`xterm-accessibility`),this._rowContainer=this._coreBrowserService.mainDocument.createElement(`div`),this._rowContainer.setAttribute(`role`,`list`),this._rowContainer.classList.add(`xterm-accessibility-tree`),this._rowElements=[];for(let e=0;e<this._terminal.rows;e++)this._rowElements[e]=this._createAccessibilityTreeNode(),this._rowContainer.appendChild(this._rowElements[e]);if(this._topBoundaryFocusListener=e=>this._handleBoundaryFocus(e,0),this._bottomBoundaryFocusListener=e=>this._handleBoundaryFocus(e,1),this._rowElements[0].addEventListener(`focus`,this._topBoundaryFocusListener),this._rowElements[this._rowElements.length-1].addEventListener(`focus`,this._bottomBoundaryFocusListener),this._refreshRowsDimensions(),this._accessibilityContainer.appendChild(this._rowContainer),this._liveRegion=this._coreBrowserService.mainDocument.createElement(`div`),this._liveRegion.classList.add(`live-region`),this._liveRegion.setAttribute(`aria-live`,`assertive`),this._accessibilityContainer.appendChild(this._liveRegion),this._liveRegionDebouncer=this.register(new o.TimeBasedDebouncer(this._renderRows.bind(this))),!this._terminal.element)throw Error(`Cannot enable accessibility before Terminal.open`);this._terminal.element.insertAdjacentElement(`afterbegin`,this._accessibilityContainer),this.register(this._terminal.onResize((e=>this._handleResize(e.rows)))),this.register(this._terminal.onRender((e=>this._refreshRows(e.start,e.end)))),this.register(this._terminal.onScroll((()=>this._refreshRows()))),this.register(this._terminal.onA11yChar((e=>this._handleChar(e)))),this.register(this._terminal.onLineFeed((()=>this._handleChar(`
|
|
366
366
|
`)))),this.register(this._terminal.onA11yTab((e=>this._handleTab(e)))),this.register(this._terminal.onKey((e=>this._handleKey(e.key)))),this.register(this._terminal.onBlur((()=>this._clearLiveRegion()))),this.register(this._renderService.onDimensionsChange((()=>this._refreshRowsDimensions()))),this.register((0,u.addDisposableDomListener)(document,`selectionchange`,(()=>this._handleSelectionChange()))),this.register(this._coreBrowserService.onDprChange((()=>this._refreshRowsDimensions()))),this._refreshRows(),this.register((0,s.toDisposable)((()=>{this._accessibilityContainer.remove(),this._rowElements.length=0})))}_handleTab(e){for(let t=0;t<e;t++)this._handleChar(` `)}_handleChar(e){this._liveRegionLineCount<21&&(this._charsToConsume.length>0?this._charsToConsume.shift()!==e&&(this._charsToAnnounce+=e):this._charsToAnnounce+=e,e===`
|
|
367
367
|
`&&(this._liveRegionLineCount++,this._liveRegionLineCount===21&&(this._liveRegion.textContent+=a.tooMuchOutput)))}_clearLiveRegion(){this._liveRegion.textContent=``,this._liveRegionLineCount=0}_handleKey(e){this._clearLiveRegion(),/\p{Control}/u.test(e)||this._charsToConsume.push(e)}_refreshRows(e,t){this._liveRegionDebouncer.refresh(e,t,this._terminal.rows)}_renderRows(e,t){let n=this._terminal.buffer,r=n.lines.length.toString();for(let i=e;i<=t;i++){let e=n.lines.get(n.ydisp+i),t=[],a=e?.translateToString(!0,void 0,void 0,t)||``,o=(n.ydisp+i+1).toString(),s=this._rowElements[i];s&&(a.length===0?(s.innerText=`\xA0`,this._rowColumns.set(s,[0,1])):(s.textContent=a,this._rowColumns.set(s,t)),s.setAttribute(`aria-posinset`,o),s.setAttribute(`aria-setsize`,r))}this._announceCharacters()}_announceCharacters(){this._charsToAnnounce.length!==0&&(this._liveRegion.textContent+=this._charsToAnnounce,this._charsToAnnounce=``)}_handleBoundaryFocus(e,t){let n=e.target,r=this._rowElements[t===0?1:this._rowElements.length-2];if(n.getAttribute(`aria-posinset`)===(t===0?`1`:`${this._terminal.buffer.lines.length}`)||e.relatedTarget!==r)return;let i,a;if(t===0?(i=n,a=this._rowElements.pop(),this._rowContainer.removeChild(a)):(i=this._rowElements.shift(),a=n,this._rowContainer.removeChild(i)),i.removeEventListener(`focus`,this._topBoundaryFocusListener),a.removeEventListener(`focus`,this._bottomBoundaryFocusListener),t===0){let e=this._createAccessibilityTreeNode();this._rowElements.unshift(e),this._rowContainer.insertAdjacentElement(`afterbegin`,e)}else{let e=this._createAccessibilityTreeNode();this._rowElements.push(e),this._rowContainer.appendChild(e)}this._rowElements[0].addEventListener(`focus`,this._topBoundaryFocusListener),this._rowElements[this._rowElements.length-1].addEventListener(`focus`,this._bottomBoundaryFocusListener),this._terminal.scrollLines(t===0?-1:1),this._rowElements[t===0?1:this._rowElements.length-2].focus(),e.preventDefault(),e.stopImmediatePropagation()}_handleSelectionChange(){if(this._rowElements.length===0)return;let e=document.getSelection();if(!e)return;if(e.isCollapsed)return void(this._rowContainer.contains(e.anchorNode)&&this._terminal.clearSelection());if(!e.anchorNode||!e.focusNode)return void console.error(`anchorNode and/or focusNode are null`);let t={node:e.anchorNode,offset:e.anchorOffset},n={node:e.focusNode,offset:e.focusOffset};if((t.node.compareDocumentPosition(n.node)&Node.DOCUMENT_POSITION_PRECEDING||t.node===n.node&&t.offset>n.offset)&&([t,n]=[n,t]),t.node.compareDocumentPosition(this._rowElements[0])&(Node.DOCUMENT_POSITION_CONTAINED_BY|Node.DOCUMENT_POSITION_FOLLOWING)&&(t={node:this._rowElements[0].childNodes[0],offset:0}),!this._rowContainer.contains(t.node))return;let r=this._rowElements.slice(-1)[0];if(n.node.compareDocumentPosition(r)&(Node.DOCUMENT_POSITION_CONTAINED_BY|Node.DOCUMENT_POSITION_PRECEDING)&&(n={node:r,offset:r.textContent?.length??0}),!this._rowContainer.contains(n.node))return;let i=({node:e,offset:t})=>{let n=e instanceof Text?e.parentNode:e,r=parseInt(n?.getAttribute(`aria-posinset`),10)-1;if(isNaN(r))return console.warn(`row is invalid. Race condition?`),null;let i=this._rowColumns.get(n);if(!i)return console.warn(`columns is null. Race condition?`),null;let a=t<i.length?i[t]:i.slice(-1)[0]+1;return a>=this._terminal.cols&&(++r,a=0),{row:r,column:a}},a=i(t),o=i(n);if(a&&o){if(a.row>o.row||a.row===o.row&&a.column>=o.column)throw Error(`invalid range`);this._terminal.select(a.column,a.row,(o.row-a.row)*this._terminal.cols-a.column+o.column)}}_handleResize(e){this._rowElements[this._rowElements.length-1].removeEventListener(`focus`,this._bottomBoundaryFocusListener);for(let e=this._rowContainer.children.length;e<this._terminal.rows;e++)this._rowElements[e]=this._createAccessibilityTreeNode(),this._rowContainer.appendChild(this._rowElements[e]);for(;this._rowElements.length>e;)this._rowContainer.removeChild(this._rowElements.pop());this._rowElements[this._rowElements.length-1].addEventListener(`focus`,this._bottomBoundaryFocusListener),this._refreshRowsDimensions()}_createAccessibilityTreeNode(){let e=this._coreBrowserService.mainDocument.createElement(`div`);return e.setAttribute(`role`,`listitem`),e.tabIndex=-1,this._refreshRowDimensions(e),e}_refreshRowsDimensions(){if(this._renderService.dimensions.css.cell.height){this._accessibilityContainer.style.width=`${this._renderService.dimensions.css.canvas.width}px`,this._rowElements.length!==this._terminal.rows&&this._handleResize(this._terminal.rows);for(let e=0;e<this._terminal.rows;e++)this._refreshRowDimensions(this._rowElements[e])}}_refreshRowDimensions(e){e.style.height=`${this._renderService.dimensions.css.cell.height}px`}};t.AccessibilityManager=d=r([i(1,l.IInstantiationService),i(2,c.ICoreBrowserService),i(3,c.IRenderService)],d)},3614:(e,t)=>{function n(e){return e.replace(/\r?\n/g,`\r`)}function r(e,t){return t?`\x1B[200~`+e+`\x1B[201~`:e}function i(e,t,i,a){e=r(e=n(e),i.decPrivateModes.bracketedPasteMode&&!0!==a.rawOptions.ignoreBracketedPasteMode),i.triggerDataEvent(e,!0),t.value=``}function a(e,t,n){let r=n.getBoundingClientRect(),i=e.clientX-r.left-10,a=e.clientY-r.top-10;t.style.width=`20px`,t.style.height=`20px`,t.style.left=`${i}px`,t.style.top=`${a}px`,t.style.zIndex=`1000`,t.focus()}Object.defineProperty(t,"__esModule",{value:!0}),t.rightClickHandler=t.moveTextAreaUnderMouseCursor=t.paste=t.handlePasteEvent=t.copyHandler=t.bracketTextForPaste=t.prepareTextForTerminal=void 0,t.prepareTextForTerminal=n,t.bracketTextForPaste=r,t.copyHandler=function(e,t){e.clipboardData&&e.clipboardData.setData(`text/plain`,t.selectionText),e.preventDefault()},t.handlePasteEvent=function(e,t,n,r){e.stopPropagation(),e.clipboardData&&i(e.clipboardData.getData(`text/plain`),t,n,r)},t.paste=i,t.moveTextAreaUnderMouseCursor=a,t.rightClickHandler=function(e,t,n,r,i){a(e,t,n),i&&r.rightClickSelect(e),t.value=r.selectionText,t.select()}},7239:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ColorContrastCache=void 0;let r=n(1505);t.ColorContrastCache=class{constructor(){this._color=new r.TwoKeyMap,this._css=new r.TwoKeyMap}setCss(e,t,n){this._css.set(e,t,n)}getCss(e,t){return this._css.get(e,t)}setColor(e,t,n){this._color.set(e,t,n)}getColor(e,t){return this._color.get(e,t)}clear(){this._color.clear(),this._css.clear()}}},3656:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.addDisposableDomListener=void 0,t.addDisposableDomListener=function(e,t,n,r){e.addEventListener(t,n,r);let i=!1;return{dispose:()=>{i||(i=!0,e.removeEventListener(t,n,r))}}}},3551:function(e,t,n){var r=this&&this.__decorate||function(e,t,n,r){var i,a=arguments.length,o=a<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)o=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o},i=this&&this.__param||function(e,t){return function(n,r){t(n,r,e)}};Object.defineProperty(t,"__esModule",{value:!0}),t.Linkifier=void 0;let a=n(3656),o=n(8460),s=n(844),c=n(2585),l=n(4725),u=t.Linkifier=class extends s.Disposable{get currentLink(){return this._currentLink}constructor(e,t,n,r,i){super(),this._element=e,this._mouseService=t,this._renderService=n,this._bufferService=r,this._linkProviderService=i,this._linkCacheDisposables=[],this._isMouseOut=!0,this._wasResized=!1,this._activeLine=-1,this._onShowLinkUnderline=this.register(new o.EventEmitter),this.onShowLinkUnderline=this._onShowLinkUnderline.event,this._onHideLinkUnderline=this.register(new o.EventEmitter),this.onHideLinkUnderline=this._onHideLinkUnderline.event,this.register((0,s.getDisposeArrayDisposable)(this._linkCacheDisposables)),this.register((0,s.toDisposable)((()=>{this._lastMouseEvent=void 0,this._activeProviderReplies?.clear()}))),this.register(this._bufferService.onResize((()=>{this._clearCurrentLink(),this._wasResized=!0}))),this.register((0,a.addDisposableDomListener)(this._element,`mouseleave`,(()=>{this._isMouseOut=!0,this._clearCurrentLink()}))),this.register((0,a.addDisposableDomListener)(this._element,`mousemove`,this._handleMouseMove.bind(this))),this.register((0,a.addDisposableDomListener)(this._element,`mousedown`,this._handleMouseDown.bind(this))),this.register((0,a.addDisposableDomListener)(this._element,`mouseup`,this._handleMouseUp.bind(this)))}_handleMouseMove(e){this._lastMouseEvent=e;let t=this._positionFromMouseEvent(e,this._element,this._mouseService);if(!t)return;this._isMouseOut=!1;let n=e.composedPath();for(let e=0;e<n.length;e++){let t=n[e];if(t.classList.contains(`xterm`))break;if(t.classList.contains(`xterm-hover`))return}this._lastBufferCell&&t.x===this._lastBufferCell.x&&t.y===this._lastBufferCell.y||(this._handleHover(t),this._lastBufferCell=t)}_handleHover(e){if(this._activeLine!==e.y||this._wasResized)return this._clearCurrentLink(),this._askForLink(e,!1),void(this._wasResized=!1);this._currentLink&&this._linkAtPosition(this._currentLink.link,e)||(this._clearCurrentLink(),this._askForLink(e,!0))}_askForLink(e,t){this._activeProviderReplies&&t||(this._activeProviderReplies?.forEach((e=>{e?.forEach((e=>{e.link.dispose&&e.link.dispose()}))})),this._activeProviderReplies=new Map,this._activeLine=e.y);let n=!1;for(let[r,i]of this._linkProviderService.linkProviders.entries())t?this._activeProviderReplies?.get(r)&&(n=this._checkLinkProviderResult(r,e,n)):i.provideLinks(e.y,(t=>{if(this._isMouseOut)return;let i=t?.map((e=>({link:e})));this._activeProviderReplies?.set(r,i),n=this._checkLinkProviderResult(r,e,n),this._activeProviderReplies?.size===this._linkProviderService.linkProviders.length&&this._removeIntersectingLinks(e.y,this._activeProviderReplies)}))}_removeIntersectingLinks(e,t){let n=new Set;for(let r=0;r<t.size;r++){let i=t.get(r);if(i)for(let t=0;t<i.length;t++){let r=i[t],a=r.link.range.start.y<e?0:r.link.range.start.x,o=r.link.range.end.y>e?this._bufferService.cols:r.link.range.end.x;for(let e=a;e<=o;e++){if(n.has(e)){i.splice(t--,1);break}n.add(e)}}}}_checkLinkProviderResult(e,t,n){if(!this._activeProviderReplies)return n;let r=this._activeProviderReplies.get(e),i=!1;for(let t=0;t<e;t++)this._activeProviderReplies.has(t)&&!this._activeProviderReplies.get(t)||(i=!0);if(!i&&r){let e=r.find((e=>this._linkAtPosition(e.link,t)));e&&(n=!0,this._handleNewLink(e))}if(this._activeProviderReplies.size===this._linkProviderService.linkProviders.length&&!n)for(let e=0;e<this._activeProviderReplies.size;e++){let r=this._activeProviderReplies.get(e)?.find((e=>this._linkAtPosition(e.link,t)));if(r){n=!0,this._handleNewLink(r);break}}return n}_handleMouseDown(){this._mouseDownLink=this._currentLink}_handleMouseUp(e){if(!this._currentLink)return;let t=this._positionFromMouseEvent(e,this._element,this._mouseService);t&&this._mouseDownLink===this._currentLink&&this._linkAtPosition(this._currentLink.link,t)&&this._currentLink.link.activate(e,this._currentLink.link.text)}_clearCurrentLink(e,t){this._currentLink&&this._lastMouseEvent&&(!e||!t||this._currentLink.link.range.start.y>=e&&this._currentLink.link.range.end.y<=t)&&(this._linkLeave(this._element,this._currentLink.link,this._lastMouseEvent),this._currentLink=void 0,(0,s.disposeArray)(this._linkCacheDisposables))}_handleNewLink(e){if(!this._lastMouseEvent)return;let t=this._positionFromMouseEvent(this._lastMouseEvent,this._element,this._mouseService);t&&this._linkAtPosition(e.link,t)&&(this._currentLink=e,this._currentLink.state={decorations:{underline:e.link.decorations===void 0||e.link.decorations.underline,pointerCursor:e.link.decorations===void 0||e.link.decorations.pointerCursor},isHovered:!0},this._linkHover(this._element,e.link,this._lastMouseEvent),e.link.decorations={},Object.defineProperties(e.link.decorations,{pointerCursor:{get:()=>this._currentLink?.state?.decorations.pointerCursor,set:e=>{this._currentLink?.state&&this._currentLink.state.decorations.pointerCursor!==e&&(this._currentLink.state.decorations.pointerCursor=e,this._currentLink.state.isHovered&&this._element.classList.toggle(`xterm-cursor-pointer`,e))}},underline:{get:()=>this._currentLink?.state?.decorations.underline,set:t=>{this._currentLink?.state&&this._currentLink?.state?.decorations.underline!==t&&(this._currentLink.state.decorations.underline=t,this._currentLink.state.isHovered&&this._fireUnderlineEvent(e.link,t))}}}),this._linkCacheDisposables.push(this._renderService.onRenderedViewportChange((e=>{if(!this._currentLink)return;let t=e.start===0?0:e.start+1+this._bufferService.buffer.ydisp,n=this._bufferService.buffer.ydisp+1+e.end;if(this._currentLink.link.range.start.y>=t&&this._currentLink.link.range.end.y<=n&&(this._clearCurrentLink(t,n),this._lastMouseEvent)){let e=this._positionFromMouseEvent(this._lastMouseEvent,this._element,this._mouseService);e&&this._askForLink(e,!1)}}))))}_linkHover(e,t,n){this._currentLink?.state&&(this._currentLink.state.isHovered=!0,this._currentLink.state.decorations.underline&&this._fireUnderlineEvent(t,!0),this._currentLink.state.decorations.pointerCursor&&e.classList.add(`xterm-cursor-pointer`)),t.hover&&t.hover(n,t.text)}_fireUnderlineEvent(e,t){let n=e.range,r=this._bufferService.buffer.ydisp,i=this._createLinkUnderlineEvent(n.start.x-1,n.start.y-r-1,n.end.x,n.end.y-r-1,void 0);(t?this._onShowLinkUnderline:this._onHideLinkUnderline).fire(i)}_linkLeave(e,t,n){this._currentLink?.state&&(this._currentLink.state.isHovered=!1,this._currentLink.state.decorations.underline&&this._fireUnderlineEvent(t,!1),this._currentLink.state.decorations.pointerCursor&&e.classList.remove(`xterm-cursor-pointer`)),t.leave&&t.leave(n,t.text)}_linkAtPosition(e,t){let n=e.range.start.y*this._bufferService.cols+e.range.start.x,r=e.range.end.y*this._bufferService.cols+e.range.end.x,i=t.y*this._bufferService.cols+t.x;return n<=i&&i<=r}_positionFromMouseEvent(e,t,n){let r=n.getCoords(e,t,this._bufferService.cols,this._bufferService.rows);if(r)return{x:r[0],y:r[1]+this._bufferService.buffer.ydisp}}_createLinkUnderlineEvent(e,t,n,r,i){return{x1:e,y1:t,x2:n,y2:r,cols:this._bufferService.cols,fg:i}}};t.Linkifier=u=r([i(1,l.IMouseService),i(2,l.IRenderService),i(3,c.IBufferService),i(4,l.ILinkProviderService)],u)},9042:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.tooMuchOutput=t.promptLabel=void 0,t.promptLabel=`Terminal input`,t.tooMuchOutput=`Too much output to announce, navigate to rows manually to read`},3730:function(e,t,n){var r=this&&this.__decorate||function(e,t,n,r){var i,a=arguments.length,o=a<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)o=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o},i=this&&this.__param||function(e,t){return function(n,r){t(n,r,e)}};Object.defineProperty(t,"__esModule",{value:!0}),t.OscLinkProvider=void 0;let a=n(511),o=n(2585),s=t.OscLinkProvider=class{constructor(e,t,n){this._bufferService=e,this._optionsService=t,this._oscLinkService=n}provideLinks(e,t){let n=this._bufferService.buffer.lines.get(e-1);if(!n)return void t(void 0);let r=[],i=this._optionsService.rawOptions.linkHandler,o=new a.CellData,s=n.getTrimmedLength(),l=-1,u=-1,d=!1;for(let t=0;t<s;t++)if(u!==-1||n.hasContent(t)){if(n.loadCell(t,o),o.hasExtendedAttrs()&&o.extended.urlId){if(u===-1){u=t,l=o.extended.urlId;continue}d=o.extended.urlId!==l}else u!==-1&&(d=!0);if(d||u!==-1&&t===s-1){let n=this._oscLinkService.getLinkData(l)?.uri;if(n){let a={start:{x:u+1,y:e},end:{x:t+(d||t!==s-1?0:1),y:e}},o=!1;if(!i?.allowNonHttpProtocols)try{let e=new URL(n);[`http:`,`https:`].includes(e.protocol)||(o=!0)}catch{o=!0}o||r.push({text:n,range:a,activate:(e,t)=>i?i.activate(e,t,a):c(0,t),hover:(e,t)=>i?.hover?.(e,t,a),leave:(e,t)=>i?.leave?.(e,t,a)})}d=!1,o.hasExtendedAttrs()&&o.extended.urlId?(u=t,l=o.extended.urlId):(u=-1,l=-1)}}t(r)}};function c(e,t){if(confirm(`Do you want to navigate to ${t}?\n\nWARNING: This link could potentially be dangerous`)){let e=window.open();if(e){try{e.opener=null}catch{}e.location.href=t}else console.warn(`Opening link blocked as opener could not be cleared`)}}t.OscLinkProvider=s=r([i(0,o.IBufferService),i(1,o.IOptionsService),i(2,o.IOscLinkService)],s)},6193:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.RenderDebouncer=void 0,t.RenderDebouncer=class{constructor(e,t){this._renderCallback=e,this._coreBrowserService=t,this._refreshCallbacks=[]}dispose(){this._animationFrame&&=(this._coreBrowserService.window.cancelAnimationFrame(this._animationFrame),void 0)}addRefreshCallback(e){return this._refreshCallbacks.push(e),this._animationFrame||=this._coreBrowserService.window.requestAnimationFrame((()=>this._innerRefresh())),this._animationFrame}refresh(e,t,n){this._rowCount=n,e=e===void 0?0:e,t=t===void 0?this._rowCount-1:t,this._rowStart=this._rowStart===void 0?e:Math.min(this._rowStart,e),this._rowEnd=this._rowEnd===void 0?t:Math.max(this._rowEnd,t),this._animationFrame||=this._coreBrowserService.window.requestAnimationFrame((()=>this._innerRefresh()))}_innerRefresh(){if(this._animationFrame=void 0,this._rowStart===void 0||this._rowEnd===void 0||this._rowCount===void 0)return void this._runRefreshCallbacks();let e=Math.max(this._rowStart,0),t=Math.min(this._rowEnd,this._rowCount-1);this._rowStart=void 0,this._rowEnd=void 0,this._renderCallback(e,t),this._runRefreshCallbacks()}_runRefreshCallbacks(){for(let e of this._refreshCallbacks)e(0);this._refreshCallbacks=[]}}},3236:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Terminal=void 0;let r=n(3614),i=n(3656),a=n(3551),o=n(9042),s=n(3730),c=n(1680),l=n(3107),u=n(5744),d=n(2950),f=n(1296),p=n(428),m=n(4269),h=n(5114),g=n(8934),_=n(3230),v=n(9312),y=n(4725),b=n(6731),x=n(8055),S=n(8969),C=n(8460),w=n(844),T=n(6114),E=n(8437),D=n(2584),O=n(7399),k=n(5941),ee=n(9074),A=n(2585),te=n(5435),ne=n(4567),re=n(779);class ie extends S.CoreTerminal{get onFocus(){return this._onFocus.event}get onBlur(){return this._onBlur.event}get onA11yChar(){return this._onA11yCharEmitter.event}get onA11yTab(){return this._onA11yTabEmitter.event}get onWillOpen(){return this._onWillOpen.event}constructor(e={}){super(e),this.browser=T,this._keyDownHandled=!1,this._keyDownSeen=!1,this._keyPressHandled=!1,this._unprocessedDeadKey=!1,this._accessibilityManager=this.register(new w.MutableDisposable),this._onCursorMove=this.register(new C.EventEmitter),this.onCursorMove=this._onCursorMove.event,this._onKey=this.register(new C.EventEmitter),this.onKey=this._onKey.event,this._onRender=this.register(new C.EventEmitter),this.onRender=this._onRender.event,this._onSelectionChange=this.register(new C.EventEmitter),this.onSelectionChange=this._onSelectionChange.event,this._onTitleChange=this.register(new C.EventEmitter),this.onTitleChange=this._onTitleChange.event,this._onBell=this.register(new C.EventEmitter),this.onBell=this._onBell.event,this._onFocus=this.register(new C.EventEmitter),this._onBlur=this.register(new C.EventEmitter),this._onA11yCharEmitter=this.register(new C.EventEmitter),this._onA11yTabEmitter=this.register(new C.EventEmitter),this._onWillOpen=this.register(new C.EventEmitter),this._setup(),this._decorationService=this._instantiationService.createInstance(ee.DecorationService),this._instantiationService.setService(A.IDecorationService,this._decorationService),this._linkProviderService=this._instantiationService.createInstance(re.LinkProviderService),this._instantiationService.setService(y.ILinkProviderService,this._linkProviderService),this._linkProviderService.registerLinkProvider(this._instantiationService.createInstance(s.OscLinkProvider)),this.register(this._inputHandler.onRequestBell((()=>this._onBell.fire()))),this.register(this._inputHandler.onRequestRefreshRows(((e,t)=>this.refresh(e,t)))),this.register(this._inputHandler.onRequestSendFocus((()=>this._reportFocus()))),this.register(this._inputHandler.onRequestReset((()=>this.reset()))),this.register(this._inputHandler.onRequestWindowsOptionsReport((e=>this._reportWindowsOptions(e)))),this.register(this._inputHandler.onColor((e=>this._handleColorEvent(e)))),this.register((0,C.forwardEvent)(this._inputHandler.onCursorMove,this._onCursorMove)),this.register((0,C.forwardEvent)(this._inputHandler.onTitleChange,this._onTitleChange)),this.register((0,C.forwardEvent)(this._inputHandler.onA11yChar,this._onA11yCharEmitter)),this.register((0,C.forwardEvent)(this._inputHandler.onA11yTab,this._onA11yTabEmitter)),this.register(this._bufferService.onResize((e=>this._afterResize(e.cols,e.rows)))),this.register((0,w.toDisposable)((()=>{this._customKeyEventHandler=void 0,this.element?.parentNode?.removeChild(this.element)})))}_handleColorEvent(e){if(this._themeService)for(let t of e){let e,n=``;switch(t.index){case 256:e=`foreground`,n=`10`;break;case 257:e=`background`,n=`11`;break;case 258:e=`cursor`,n=`12`;break;default:e=`ansi`,n=`4;`+t.index}switch(t.type){case 0:let r=x.color.toColorRGB(e===`ansi`?this._themeService.colors.ansi[t.index]:this._themeService.colors[e]);this.coreService.triggerDataEvent(`${D.C0.ESC}]${n};${(0,k.toRgbString)(r)}${D.C1_ESCAPED.ST}`);break;case 1:if(e===`ansi`)this._themeService.modifyColors((e=>e.ansi[t.index]=x.channels.toColor(...t.color)));else{let n=e;this._themeService.modifyColors((e=>e[n]=x.channels.toColor(...t.color)))}break;case 2:this._themeService.restoreColor(t.index)}}}_setup(){super._setup(),this._customKeyEventHandler=void 0}get buffer(){return this.buffers.active}focus(){this.textarea&&this.textarea.focus({preventScroll:!0})}_handleScreenReaderModeOptionChange(e){e?!this._accessibilityManager.value&&this._renderService&&(this._accessibilityManager.value=this._instantiationService.createInstance(ne.AccessibilityManager,this)):this._accessibilityManager.clear()}_handleTextAreaFocus(e){this.coreService.decPrivateModes.sendFocus&&this.coreService.triggerDataEvent(D.C0.ESC+`[I`),this.element.classList.add(`focus`),this._showCursor(),this._onFocus.fire()}blur(){return this.textarea?.blur()}_handleTextAreaBlur(){this.textarea.value=``,this.refresh(this.buffer.y,this.buffer.y),this.coreService.decPrivateModes.sendFocus&&this.coreService.triggerDataEvent(D.C0.ESC+`[O`),this.element.classList.remove(`focus`),this._onBlur.fire()}_syncTextArea(){if(!this.textarea||!this.buffer.isCursorInViewport||this._compositionHelper.isComposing||!this._renderService)return;let e=this.buffer.ybase+this.buffer.y,t=this.buffer.lines.get(e);if(!t)return;let n=Math.min(this.buffer.x,this.cols-1),r=this._renderService.dimensions.css.cell.height,i=t.getWidth(n),a=this._renderService.dimensions.css.cell.width*i,o=this.buffer.y*this._renderService.dimensions.css.cell.height,s=n*this._renderService.dimensions.css.cell.width;this.textarea.style.left=s+`px`,this.textarea.style.top=o+`px`,this.textarea.style.width=a+`px`,this.textarea.style.height=r+`px`,this.textarea.style.lineHeight=r+`px`,this.textarea.style.zIndex=`-5`}_initGlobal(){this._bindKeys(),this.register((0,i.addDisposableDomListener)(this.element,`copy`,(e=>{this.hasSelection()&&(0,r.copyHandler)(e,this._selectionService)})));let e=e=>(0,r.handlePasteEvent)(e,this.textarea,this.coreService,this.optionsService);this.register((0,i.addDisposableDomListener)(this.textarea,`paste`,e)),this.register((0,i.addDisposableDomListener)(this.element,`paste`,e)),T.isFirefox?this.register((0,i.addDisposableDomListener)(this.element,`mousedown`,(e=>{e.button===2&&(0,r.rightClickHandler)(e,this.textarea,this.screenElement,this._selectionService,this.options.rightClickSelectsWord)}))):this.register((0,i.addDisposableDomListener)(this.element,`contextmenu`,(e=>{(0,r.rightClickHandler)(e,this.textarea,this.screenElement,this._selectionService,this.options.rightClickSelectsWord)}))),T.isLinux&&this.register((0,i.addDisposableDomListener)(this.element,`auxclick`,(e=>{e.button===1&&(0,r.moveTextAreaUnderMouseCursor)(e,this.textarea,this.screenElement)})))}_bindKeys(){this.register((0,i.addDisposableDomListener)(this.textarea,`keyup`,(e=>this._keyUp(e)),!0)),this.register((0,i.addDisposableDomListener)(this.textarea,`keydown`,(e=>this._keyDown(e)),!0)),this.register((0,i.addDisposableDomListener)(this.textarea,`keypress`,(e=>this._keyPress(e)),!0)),this.register((0,i.addDisposableDomListener)(this.textarea,`compositionstart`,(()=>this._compositionHelper.compositionstart()))),this.register((0,i.addDisposableDomListener)(this.textarea,`compositionupdate`,(e=>this._compositionHelper.compositionupdate(e)))),this.register((0,i.addDisposableDomListener)(this.textarea,`compositionend`,(()=>this._compositionHelper.compositionend()))),this.register((0,i.addDisposableDomListener)(this.textarea,`input`,(e=>this._inputEvent(e)),!0)),this.register(this.onRender((()=>this._compositionHelper.updateCompositionElements())))}open(e){if(!e)throw Error(`Terminal requires a parent element.`);if(e.isConnected||this._logService.debug(`Terminal.open was called on an element that was not attached to the DOM`),this.element?.ownerDocument.defaultView&&this._coreBrowserService)return void(this.element.ownerDocument.defaultView!==this._coreBrowserService.window&&(this._coreBrowserService.window=this.element.ownerDocument.defaultView));this._document=e.ownerDocument,this.options.documentOverride&&this.options.documentOverride instanceof Document&&(this._document=this.optionsService.rawOptions.documentOverride),this.element=this._document.createElement(`div`),this.element.dir=`ltr`,this.element.classList.add(`terminal`),this.element.classList.add(`xterm`),e.appendChild(this.element);let t=this._document.createDocumentFragment();this._viewportElement=this._document.createElement(`div`),this._viewportElement.classList.add(`xterm-viewport`),t.appendChild(this._viewportElement),this._viewportScrollArea=this._document.createElement(`div`),this._viewportScrollArea.classList.add(`xterm-scroll-area`),this._viewportElement.appendChild(this._viewportScrollArea),this.screenElement=this._document.createElement(`div`),this.screenElement.classList.add(`xterm-screen`),this.register((0,i.addDisposableDomListener)(this.screenElement,`mousemove`,(e=>this.updateCursorStyle(e)))),this._helperContainer=this._document.createElement(`div`),this._helperContainer.classList.add(`xterm-helpers`),this.screenElement.appendChild(this._helperContainer),t.appendChild(this.screenElement),this.textarea=this._document.createElement(`textarea`),this.textarea.classList.add(`xterm-helper-textarea`),this.textarea.setAttribute(`aria-label`,o.promptLabel),T.isChromeOS||this.textarea.setAttribute(`aria-multiline`,`false`),this.textarea.setAttribute(`autocorrect`,`off`),this.textarea.setAttribute(`autocapitalize`,`off`),this.textarea.setAttribute(`spellcheck`,`false`),this.textarea.tabIndex=0,this._coreBrowserService=this.register(this._instantiationService.createInstance(h.CoreBrowserService,this.textarea,e.ownerDocument.defaultView??window,this._document??typeof window<`u`?window.document:null)),this._instantiationService.setService(y.ICoreBrowserService,this._coreBrowserService),this.register((0,i.addDisposableDomListener)(this.textarea,`focus`,(e=>this._handleTextAreaFocus(e)))),this.register((0,i.addDisposableDomListener)(this.textarea,`blur`,(()=>this._handleTextAreaBlur()))),this._helperContainer.appendChild(this.textarea),this._charSizeService=this._instantiationService.createInstance(p.CharSizeService,this._document,this._helperContainer),this._instantiationService.setService(y.ICharSizeService,this._charSizeService),this._themeService=this._instantiationService.createInstance(b.ThemeService),this._instantiationService.setService(y.IThemeService,this._themeService),this._characterJoinerService=this._instantiationService.createInstance(m.CharacterJoinerService),this._instantiationService.setService(y.ICharacterJoinerService,this._characterJoinerService),this._renderService=this.register(this._instantiationService.createInstance(_.RenderService,this.rows,this.screenElement)),this._instantiationService.setService(y.IRenderService,this._renderService),this.register(this._renderService.onRenderedViewportChange((e=>this._onRender.fire(e)))),this.onResize((e=>this._renderService.resize(e.cols,e.rows))),this._compositionView=this._document.createElement(`div`),this._compositionView.classList.add(`composition-view`),this._compositionHelper=this._instantiationService.createInstance(d.CompositionHelper,this.textarea,this._compositionView),this._helperContainer.appendChild(this._compositionView),this._mouseService=this._instantiationService.createInstance(g.MouseService),this._instantiationService.setService(y.IMouseService,this._mouseService),this.linkifier=this.register(this._instantiationService.createInstance(a.Linkifier,this.screenElement)),this.element.appendChild(t);try{this._onWillOpen.fire(this.element)}catch{}this._renderService.hasRenderer()||this._renderService.setRenderer(this._createRenderer()),this.viewport=this._instantiationService.createInstance(c.Viewport,this._viewportElement,this._viewportScrollArea),this.viewport.onRequestScrollLines((e=>this.scrollLines(e.amount,e.suppressScrollEvent,1))),this.register(this._inputHandler.onRequestSyncScrollBar((()=>this.viewport.syncScrollArea()))),this.register(this.viewport),this.register(this.onCursorMove((()=>{this._renderService.handleCursorMove(),this._syncTextArea()}))),this.register(this.onResize((()=>this._renderService.handleResize(this.cols,this.rows)))),this.register(this.onBlur((()=>this._renderService.handleBlur()))),this.register(this.onFocus((()=>this._renderService.handleFocus()))),this.register(this._renderService.onDimensionsChange((()=>this.viewport.syncScrollArea()))),this._selectionService=this.register(this._instantiationService.createInstance(v.SelectionService,this.element,this.screenElement,this.linkifier)),this._instantiationService.setService(y.ISelectionService,this._selectionService),this.register(this._selectionService.onRequestScrollLines((e=>this.scrollLines(e.amount,e.suppressScrollEvent)))),this.register(this._selectionService.onSelectionChange((()=>this._onSelectionChange.fire()))),this.register(this._selectionService.onRequestRedraw((e=>this._renderService.handleSelectionChanged(e.start,e.end,e.columnSelectMode)))),this.register(this._selectionService.onLinuxMouseSelection((e=>{this.textarea.value=e,this.textarea.focus(),this.textarea.select()}))),this.register(this._onScroll.event((e=>{this.viewport.syncScrollArea(),this._selectionService.refresh()}))),this.register((0,i.addDisposableDomListener)(this._viewportElement,`scroll`,(()=>this._selectionService.refresh()))),this.register(this._instantiationService.createInstance(l.BufferDecorationRenderer,this.screenElement)),this.register((0,i.addDisposableDomListener)(this.element,`mousedown`,(e=>this._selectionService.handleMouseDown(e)))),this.coreMouseService.areMouseEventsActive?(this._selectionService.disable(),this.element.classList.add(`enable-mouse-events`)):this._selectionService.enable(),this.options.screenReaderMode&&(this._accessibilityManager.value=this._instantiationService.createInstance(ne.AccessibilityManager,this)),this.register(this.optionsService.onSpecificOptionChange(`screenReaderMode`,(e=>this._handleScreenReaderModeOptionChange(e)))),this.options.overviewRulerWidth&&(this._overviewRulerRenderer=this.register(this._instantiationService.createInstance(u.OverviewRulerRenderer,this._viewportElement,this.screenElement))),this.optionsService.onSpecificOptionChange(`overviewRulerWidth`,(e=>{!this._overviewRulerRenderer&&e&&this._viewportElement&&this.screenElement&&(this._overviewRulerRenderer=this.register(this._instantiationService.createInstance(u.OverviewRulerRenderer,this._viewportElement,this.screenElement)))})),this._charSizeService.measure(),this.refresh(0,this.rows-1),this._initGlobal(),this.bindMouse()}_createRenderer(){return this._instantiationService.createInstance(f.DomRenderer,this,this._document,this.element,this.screenElement,this._viewportElement,this._helperContainer,this.linkifier)}bindMouse(){let e=this,t=this.element;function n(t){let n=e._mouseService.getMouseReportCoords(t,e.screenElement);if(!n)return!1;let r,i;switch(t.overrideType||t.type){case`mousemove`:i=32,t.buttons===void 0?(r=3,t.button!==void 0&&(r=t.button<3?t.button:3)):r=1&t.buttons?0:4&t.buttons?1:2&t.buttons?2:3;break;case`mouseup`:i=0,r=t.button<3?t.button:3;break;case`mousedown`:i=1,r=t.button<3?t.button:3;break;case`wheel`:if(e._customWheelEventHandler&&!1===e._customWheelEventHandler(t)||e.viewport.getLinesScrolled(t)===0)return!1;i=t.deltaY<0?0:1,r=4;break;default:return!1}return!(i===void 0||r===void 0||r>4)&&e.coreMouseService.triggerMouseEvent({col:n.col,row:n.row,x:n.x,y:n.y,button:r,action:i,ctrl:t.ctrlKey,alt:t.altKey,shift:t.shiftKey})}let r={mouseup:null,wheel:null,mousedrag:null,mousemove:null},a={mouseup:e=>(n(e),e.buttons||(this._document.removeEventListener(`mouseup`,r.mouseup),r.mousedrag&&this._document.removeEventListener(`mousemove`,r.mousedrag)),this.cancel(e)),wheel:e=>(n(e),this.cancel(e,!0)),mousedrag:e=>{e.buttons&&n(e)},mousemove:e=>{e.buttons||n(e)}};this.register(this.coreMouseService.onProtocolChange((e=>{e?(this.optionsService.rawOptions.logLevel===`debug`&&this._logService.debug(`Binding to mouse events:`,this.coreMouseService.explainEvents(e)),this.element.classList.add(`enable-mouse-events`),this._selectionService.disable()):(this._logService.debug(`Unbinding from mouse events.`),this.element.classList.remove(`enable-mouse-events`),this._selectionService.enable()),8&e?r.mousemove||=(t.addEventListener(`mousemove`,a.mousemove),a.mousemove):(t.removeEventListener(`mousemove`,r.mousemove),r.mousemove=null),16&e?r.wheel||=(t.addEventListener(`wheel`,a.wheel,{passive:!1}),a.wheel):(t.removeEventListener(`wheel`,r.wheel),r.wheel=null),2&e?r.mouseup||=a.mouseup:(this._document.removeEventListener(`mouseup`,r.mouseup),r.mouseup=null),4&e?r.mousedrag||=a.mousedrag:(this._document.removeEventListener(`mousemove`,r.mousedrag),r.mousedrag=null)}))),this.coreMouseService.activeProtocol=this.coreMouseService.activeProtocol,this.register((0,i.addDisposableDomListener)(t,`mousedown`,(e=>{if(e.preventDefault(),this.focus(),this.coreMouseService.areMouseEventsActive&&!this._selectionService.shouldForceSelection(e))return n(e),r.mouseup&&this._document.addEventListener(`mouseup`,r.mouseup),r.mousedrag&&this._document.addEventListener(`mousemove`,r.mousedrag),this.cancel(e)}))),this.register((0,i.addDisposableDomListener)(t,`wheel`,(e=>{if(!r.wheel){if(this._customWheelEventHandler&&!1===this._customWheelEventHandler(e))return!1;if(!this.buffer.hasScrollback){let t=this.viewport.getLinesScrolled(e);if(t===0)return;let n=D.C0.ESC+(this.coreService.decPrivateModes.applicationCursorKeys?`O`:`[`)+(e.deltaY<0?`A`:`B`),r=``;for(let e=0;e<Math.abs(t);e++)r+=n;return this.coreService.triggerDataEvent(r,!0),this.cancel(e,!0)}return this.viewport.handleWheel(e)?this.cancel(e):void 0}}),{passive:!1})),this.register((0,i.addDisposableDomListener)(t,`touchstart`,(e=>{if(!this.coreMouseService.areMouseEventsActive)return this.viewport.handleTouchStart(e),this.cancel(e)}),{passive:!0})),this.register((0,i.addDisposableDomListener)(t,`touchmove`,(e=>{if(!this.coreMouseService.areMouseEventsActive)return this.viewport.handleTouchMove(e)?void 0:this.cancel(e)}),{passive:!1}))}refresh(e,t){this._renderService?.refreshRows(e,t)}updateCursorStyle(e){this._selectionService?.shouldColumnSelect(e)?this.element.classList.add(`column-select`):this.element.classList.remove(`column-select`)}_showCursor(){this.coreService.isCursorInitialized||(this.coreService.isCursorInitialized=!0,this.refresh(this.buffer.y,this.buffer.y))}scrollLines(e,t,n=0){n===1?(super.scrollLines(e,t,n),this.refresh(0,this.rows-1)):this.viewport?.scrollLines(e)}paste(e){(0,r.paste)(e,this.textarea,this.coreService,this.optionsService)}attachCustomKeyEventHandler(e){this._customKeyEventHandler=e}attachCustomWheelEventHandler(e){this._customWheelEventHandler=e}registerLinkProvider(e){return this._linkProviderService.registerLinkProvider(e)}registerCharacterJoiner(e){if(!this._characterJoinerService)throw Error(`Terminal must be opened first`);let t=this._characterJoinerService.register(e);return this.refresh(0,this.rows-1),t}deregisterCharacterJoiner(e){if(!this._characterJoinerService)throw Error(`Terminal must be opened first`);this._characterJoinerService.deregister(e)&&this.refresh(0,this.rows-1)}get markers(){return this.buffer.markers}registerMarker(e){return this.buffer.addMarker(this.buffer.ybase+this.buffer.y+e)}registerDecoration(e){return this._decorationService.registerDecoration(e)}hasSelection(){return!!this._selectionService&&this._selectionService.hasSelection}select(e,t,n){this._selectionService.setSelection(e,t,n)}getSelection(){return this._selectionService?this._selectionService.selectionText:``}getSelectionPosition(){if(this._selectionService&&this._selectionService.hasSelection)return{start:{x:this._selectionService.selectionStart[0],y:this._selectionService.selectionStart[1]},end:{x:this._selectionService.selectionEnd[0],y:this._selectionService.selectionEnd[1]}}}clearSelection(){this._selectionService?.clearSelection()}selectAll(){this._selectionService?.selectAll()}selectLines(e,t){this._selectionService?.selectLines(e,t)}_keyDown(e){if(this._keyDownHandled=!1,this._keyDownSeen=!0,this._customKeyEventHandler&&!1===this._customKeyEventHandler(e))return!1;let t=this.browser.isMac&&this.options.macOptionIsMeta&&e.altKey;if(!t&&!this._compositionHelper.keydown(e))return this.options.scrollOnUserInput&&this.buffer.ybase!==this.buffer.ydisp&&this.scrollToBottom(),!1;t||e.key!==`Dead`&&e.key!==`AltGraph`||(this._unprocessedDeadKey=!0);let n=(0,O.evaluateKeyboardEvent)(e,this.coreService.decPrivateModes.applicationCursorKeys,this.browser.isMac,this.options.macOptionIsMeta);if(this.updateCursorStyle(e),n.type===3||n.type===2){let t=this.rows-1;return this.scrollLines(n.type===2?-t:t),this.cancel(e,!0)}return n.type===1&&this.selectAll(),!!this._isThirdLevelShift(this.browser,e)||(n.cancel&&this.cancel(e,!0),!n.key||!!(e.key&&!e.ctrlKey&&!e.altKey&&!e.metaKey&&e.key.length===1&&e.key.charCodeAt(0)>=65&&e.key.charCodeAt(0)<=90)||(this._unprocessedDeadKey?(this._unprocessedDeadKey=!1,!0):(n.key!==D.C0.ETX&&n.key!==D.C0.CR||(this.textarea.value=``),this._onKey.fire({key:n.key,domEvent:e}),this._showCursor(),this.coreService.triggerDataEvent(n.key,!0),!this.optionsService.rawOptions.screenReaderMode||e.altKey||e.ctrlKey?this.cancel(e,!0):void(this._keyDownHandled=!0))))}_isThirdLevelShift(e,t){let n=e.isMac&&!this.options.macOptionIsMeta&&t.altKey&&!t.ctrlKey&&!t.metaKey||e.isWindows&&t.altKey&&t.ctrlKey&&!t.metaKey||e.isWindows&&t.getModifierState(`AltGraph`);return t.type===`keypress`?n:n&&(!t.keyCode||t.keyCode>47)}_keyUp(e){this._keyDownSeen=!1,this._customKeyEventHandler&&!1===this._customKeyEventHandler(e)||(function(e){return e.keyCode===16||e.keyCode===17||e.keyCode===18}(e)||this.focus(),this.updateCursorStyle(e),this._keyPressHandled=!1)}_keyPress(e){let t;if(this._keyPressHandled=!1,this._keyDownHandled||this._customKeyEventHandler&&!1===this._customKeyEventHandler(e))return!1;if(this.cancel(e),e.charCode)t=e.charCode;else if(e.which===null||e.which===void 0)t=e.keyCode;else{if(e.which===0||e.charCode===0)return!1;t=e.which}return!(!t||(e.altKey||e.ctrlKey||e.metaKey)&&!this._isThirdLevelShift(this.browser,e)||(t=String.fromCharCode(t),this._onKey.fire({key:t,domEvent:e}),this._showCursor(),this.coreService.triggerDataEvent(t,!0),this._keyPressHandled=!0,this._unprocessedDeadKey=!1,0))}_inputEvent(e){if(e.data&&e.inputType===`insertText`&&(!e.composed||!this._keyDownSeen)&&!this.optionsService.rawOptions.screenReaderMode){if(this._keyPressHandled)return!1;this._unprocessedDeadKey=!1;let t=e.data;return this.coreService.triggerDataEvent(t,!0),this.cancel(e),!0}return!1}resize(e,t){e!==this.cols||t!==this.rows?super.resize(e,t):this._charSizeService&&!this._charSizeService.hasValidSize&&this._charSizeService.measure()}_afterResize(e,t){this._charSizeService?.measure(),this.viewport?.syncScrollArea(!0)}clear(){if(this.buffer.ybase!==0||this.buffer.y!==0){this.buffer.clearAllMarkers(),this.buffer.lines.set(0,this.buffer.lines.get(this.buffer.ybase+this.buffer.y)),this.buffer.lines.length=1,this.buffer.ydisp=0,this.buffer.ybase=0,this.buffer.y=0;for(let e=1;e<this.rows;e++)this.buffer.lines.push(this.buffer.getBlankLine(E.DEFAULT_ATTR_DATA));this._onScroll.fire({position:this.buffer.ydisp,source:0}),this.viewport?.reset(),this.refresh(0,this.rows-1)}}reset(){this.options.rows=this.rows,this.options.cols=this.cols;let e=this._customKeyEventHandler;this._setup(),super.reset(),this._selectionService?.reset(),this._decorationService.reset(),this.viewport?.reset(),this._customKeyEventHandler=e,this.refresh(0,this.rows-1)}clearTextureAtlas(){this._renderService?.clearTextureAtlas()}_reportFocus(){this.element?.classList.contains(`focus`)?this.coreService.triggerDataEvent(D.C0.ESC+`[I`):this.coreService.triggerDataEvent(D.C0.ESC+`[O`)}_reportWindowsOptions(e){if(this._renderService)switch(e){case te.WindowsOptionsReportType.GET_WIN_SIZE_PIXELS:let e=this._renderService.dimensions.css.canvas.width.toFixed(0),t=this._renderService.dimensions.css.canvas.height.toFixed(0);this.coreService.triggerDataEvent(`${D.C0.ESC}[4;${t};${e}t`);break;case te.WindowsOptionsReportType.GET_CELL_SIZE_PIXELS:let n=this._renderService.dimensions.css.cell.width.toFixed(0),r=this._renderService.dimensions.css.cell.height.toFixed(0);this.coreService.triggerDataEvent(`${D.C0.ESC}[6;${r};${n}t`)}}cancel(e,t){if(this.options.cancelEvents||t)return e.preventDefault(),e.stopPropagation(),!1}}t.Terminal=ie},9924:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.TimeBasedDebouncer=void 0,t.TimeBasedDebouncer=class{constructor(e,t=1e3){this._renderCallback=e,this._debounceThresholdMS=t,this._lastRefreshMs=0,this._additionalRefreshRequested=!1}dispose(){this._refreshTimeoutID&&clearTimeout(this._refreshTimeoutID)}refresh(e,t,n){this._rowCount=n,e=e===void 0?0:e,t=t===void 0?this._rowCount-1:t,this._rowStart=this._rowStart===void 0?e:Math.min(this._rowStart,e),this._rowEnd=this._rowEnd===void 0?t:Math.max(this._rowEnd,t);let r=Date.now();if(r-this._lastRefreshMs>=this._debounceThresholdMS)this._lastRefreshMs=r,this._innerRefresh();else if(!this._additionalRefreshRequested){let e=r-this._lastRefreshMs,t=this._debounceThresholdMS-e;this._additionalRefreshRequested=!0,this._refreshTimeoutID=window.setTimeout((()=>{this._lastRefreshMs=Date.now(),this._innerRefresh(),this._additionalRefreshRequested=!1,this._refreshTimeoutID=void 0}),t)}}_innerRefresh(){if(this._rowStart===void 0||this._rowEnd===void 0||this._rowCount===void 0)return;let e=Math.max(this._rowStart,0),t=Math.min(this._rowEnd,this._rowCount-1);this._rowStart=void 0,this._rowEnd=void 0,this._renderCallback(e,t)}}},1680:function(e,t,n){var r=this&&this.__decorate||function(e,t,n,r){var i,a=arguments.length,o=a<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)o=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o},i=this&&this.__param||function(e,t){return function(n,r){t(n,r,e)}};Object.defineProperty(t,"__esModule",{value:!0}),t.Viewport=void 0;let a=n(3656),o=n(4725),s=n(8460),c=n(844),l=n(2585),u=t.Viewport=class extends c.Disposable{constructor(e,t,n,r,i,o,c,l){super(),this._viewportElement=e,this._scrollArea=t,this._bufferService=n,this._optionsService=r,this._charSizeService=i,this._renderService=o,this._coreBrowserService=c,this.scrollBarWidth=0,this._currentRowHeight=0,this._currentDeviceCellHeight=0,this._lastRecordedBufferLength=0,this._lastRecordedViewportHeight=0,this._lastRecordedBufferHeight=0,this._lastTouchY=0,this._lastScrollTop=0,this._wheelPartialScroll=0,this._refreshAnimationFrame=null,this._ignoreNextScrollEvent=!1,this._smoothScrollState={startTime:0,origin:-1,target:-1},this._onRequestScrollLines=this.register(new s.EventEmitter),this.onRequestScrollLines=this._onRequestScrollLines.event,this.scrollBarWidth=this._viewportElement.offsetWidth-this._scrollArea.offsetWidth||15,this.register((0,a.addDisposableDomListener)(this._viewportElement,`scroll`,this._handleScroll.bind(this))),this._activeBuffer=this._bufferService.buffer,this.register(this._bufferService.buffers.onBufferActivate((e=>this._activeBuffer=e.activeBuffer))),this._renderDimensions=this._renderService.dimensions,this.register(this._renderService.onDimensionsChange((e=>this._renderDimensions=e))),this._handleThemeChange(l.colors),this.register(l.onChangeColors((e=>this._handleThemeChange(e)))),this.register(this._optionsService.onSpecificOptionChange(`scrollback`,(()=>this.syncScrollArea()))),setTimeout((()=>this.syncScrollArea()))}_handleThemeChange(e){this._viewportElement.style.backgroundColor=e.background.css}reset(){this._currentRowHeight=0,this._currentDeviceCellHeight=0,this._lastRecordedBufferLength=0,this._lastRecordedViewportHeight=0,this._lastRecordedBufferHeight=0,this._lastTouchY=0,this._lastScrollTop=0,this._coreBrowserService.window.requestAnimationFrame((()=>this.syncScrollArea()))}_refresh(e){if(e)return this._innerRefresh(),void(this._refreshAnimationFrame!==null&&this._coreBrowserService.window.cancelAnimationFrame(this._refreshAnimationFrame));this._refreshAnimationFrame===null&&(this._refreshAnimationFrame=this._coreBrowserService.window.requestAnimationFrame((()=>this._innerRefresh())))}_innerRefresh(){if(this._charSizeService.height>0){this._currentRowHeight=this._renderDimensions.device.cell.height/this._coreBrowserService.dpr,this._currentDeviceCellHeight=this._renderDimensions.device.cell.height,this._lastRecordedViewportHeight=this._viewportElement.offsetHeight;let e=Math.round(this._currentRowHeight*this._lastRecordedBufferLength)+(this._lastRecordedViewportHeight-this._renderDimensions.css.canvas.height);this._lastRecordedBufferHeight!==e&&(this._lastRecordedBufferHeight=e,this._scrollArea.style.height=this._lastRecordedBufferHeight+`px`)}let e=this._bufferService.buffer.ydisp*this._currentRowHeight;this._viewportElement.scrollTop!==e&&(this._ignoreNextScrollEvent=!0,this._viewportElement.scrollTop=e),this._refreshAnimationFrame=null}syncScrollArea(e=!1){if(this._lastRecordedBufferLength!==this._bufferService.buffer.lines.length)return this._lastRecordedBufferLength=this._bufferService.buffer.lines.length,void this._refresh(e);this._lastRecordedViewportHeight===this._renderService.dimensions.css.canvas.height&&this._lastScrollTop===this._activeBuffer.ydisp*this._currentRowHeight&&this._renderDimensions.device.cell.height===this._currentDeviceCellHeight||this._refresh(e)}_handleScroll(e){if(this._lastScrollTop=this._viewportElement.scrollTop,!this._viewportElement.offsetParent)return;if(this._ignoreNextScrollEvent)return this._ignoreNextScrollEvent=!1,void this._onRequestScrollLines.fire({amount:0,suppressScrollEvent:!0});let t=Math.round(this._lastScrollTop/this._currentRowHeight)-this._bufferService.buffer.ydisp;this._onRequestScrollLines.fire({amount:t,suppressScrollEvent:!0})}_smoothScroll(){if(this._isDisposed||this._smoothScrollState.origin===-1||this._smoothScrollState.target===-1)return;let e=this._smoothScrollPercent();this._viewportElement.scrollTop=this._smoothScrollState.origin+Math.round(e*(this._smoothScrollState.target-this._smoothScrollState.origin)),e<1?this._coreBrowserService.window.requestAnimationFrame((()=>this._smoothScroll())):this._clearSmoothScrollState()}_smoothScrollPercent(){return this._optionsService.rawOptions.smoothScrollDuration&&this._smoothScrollState.startTime?Math.max(Math.min((Date.now()-this._smoothScrollState.startTime)/this._optionsService.rawOptions.smoothScrollDuration,1),0):1}_clearSmoothScrollState(){this._smoothScrollState.startTime=0,this._smoothScrollState.origin=-1,this._smoothScrollState.target=-1}_bubbleScroll(e,t){let n=this._viewportElement.scrollTop+this._lastRecordedViewportHeight;return!(t<0&&this._viewportElement.scrollTop!==0||t>0&&n<this._lastRecordedBufferHeight)||(e.cancelable&&e.preventDefault(),!1)}handleWheel(e){let t=this._getPixelsScrolled(e);return t!==0&&(this._optionsService.rawOptions.smoothScrollDuration?(this._smoothScrollState.startTime=Date.now(),this._smoothScrollPercent()<1?(this._smoothScrollState.origin=this._viewportElement.scrollTop,this._smoothScrollState.target===-1?this._smoothScrollState.target=this._viewportElement.scrollTop+t:this._smoothScrollState.target+=t,this._smoothScrollState.target=Math.max(Math.min(this._smoothScrollState.target,this._viewportElement.scrollHeight),0),this._smoothScroll()):this._clearSmoothScrollState()):this._viewportElement.scrollTop+=t,this._bubbleScroll(e,t))}scrollLines(e){if(e!==0)if(this._optionsService.rawOptions.smoothScrollDuration){let t=e*this._currentRowHeight;this._smoothScrollState.startTime=Date.now(),this._smoothScrollPercent()<1?(this._smoothScrollState.origin=this._viewportElement.scrollTop,this._smoothScrollState.target=this._smoothScrollState.origin+t,this._smoothScrollState.target=Math.max(Math.min(this._smoothScrollState.target,this._viewportElement.scrollHeight),0),this._smoothScroll()):this._clearSmoothScrollState()}else this._onRequestScrollLines.fire({amount:e,suppressScrollEvent:!1})}_getPixelsScrolled(e){if(e.deltaY===0||e.shiftKey)return 0;let t=this._applyScrollModifier(e.deltaY,e);return e.deltaMode===WheelEvent.DOM_DELTA_LINE?t*=this._currentRowHeight:e.deltaMode===WheelEvent.DOM_DELTA_PAGE&&(t*=this._currentRowHeight*this._bufferService.rows),t}getBufferElements(e,t){let n,r=``,i=[],a=t??this._bufferService.buffer.lines.length,o=this._bufferService.buffer.lines;for(let t=e;t<a;t++){let e=o.get(t);if(!e)continue;let a=o.get(t+1)?.isWrapped;if(r+=e.translateToString(!a),!a||t===o.length-1){let e=document.createElement(`div`);e.textContent=r,i.push(e),r.length>0&&(n=e),r=``}}return{bufferElements:i,cursorElement:n}}getLinesScrolled(e){if(e.deltaY===0||e.shiftKey)return 0;let t=this._applyScrollModifier(e.deltaY,e);return e.deltaMode===WheelEvent.DOM_DELTA_PIXEL?(t/=this._currentRowHeight+0,this._wheelPartialScroll+=t,t=Math.floor(Math.abs(this._wheelPartialScroll))*(this._wheelPartialScroll>0?1:-1),this._wheelPartialScroll%=1):e.deltaMode===WheelEvent.DOM_DELTA_PAGE&&(t*=this._bufferService.rows),t}_applyScrollModifier(e,t){let n=this._optionsService.rawOptions.fastScrollModifier;return n===`alt`&&t.altKey||n===`ctrl`&&t.ctrlKey||n===`shift`&&t.shiftKey?e*this._optionsService.rawOptions.fastScrollSensitivity*this._optionsService.rawOptions.scrollSensitivity:e*this._optionsService.rawOptions.scrollSensitivity}handleTouchStart(e){this._lastTouchY=e.touches[0].pageY}handleTouchMove(e){let t=this._lastTouchY-e.touches[0].pageY;return this._lastTouchY=e.touches[0].pageY,t!==0&&(this._viewportElement.scrollTop+=t,this._bubbleScroll(e,t))}};t.Viewport=u=r([i(2,l.IBufferService),i(3,l.IOptionsService),i(4,o.ICharSizeService),i(5,o.IRenderService),i(6,o.ICoreBrowserService),i(7,o.IThemeService)],u)},3107:function(e,t,n){var r=this&&this.__decorate||function(e,t,n,r){var i,a=arguments.length,o=a<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)o=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o},i=this&&this.__param||function(e,t){return function(n,r){t(n,r,e)}};Object.defineProperty(t,"__esModule",{value:!0}),t.BufferDecorationRenderer=void 0;let a=n(4725),o=n(844),s=n(2585),c=t.BufferDecorationRenderer=class extends o.Disposable{constructor(e,t,n,r,i){super(),this._screenElement=e,this._bufferService=t,this._coreBrowserService=n,this._decorationService=r,this._renderService=i,this._decorationElements=new Map,this._altBufferIsActive=!1,this._dimensionsChanged=!1,this._container=document.createElement(`div`),this._container.classList.add(`xterm-decoration-container`),this._screenElement.appendChild(this._container),this.register(this._renderService.onRenderedViewportChange((()=>this._doRefreshDecorations()))),this.register(this._renderService.onDimensionsChange((()=>{this._dimensionsChanged=!0,this._queueRefresh()}))),this.register(this._coreBrowserService.onDprChange((()=>this._queueRefresh()))),this.register(this._bufferService.buffers.onBufferActivate((()=>{this._altBufferIsActive=this._bufferService.buffer===this._bufferService.buffers.alt}))),this.register(this._decorationService.onDecorationRegistered((()=>this._queueRefresh()))),this.register(this._decorationService.onDecorationRemoved((e=>this._removeDecoration(e)))),this.register((0,o.toDisposable)((()=>{this._container.remove(),this._decorationElements.clear()})))}_queueRefresh(){this._animationFrame===void 0&&(this._animationFrame=this._renderService.addRefreshCallback((()=>{this._doRefreshDecorations(),this._animationFrame=void 0})))}_doRefreshDecorations(){for(let e of this._decorationService.decorations)this._renderDecoration(e);this._dimensionsChanged=!1}_renderDecoration(e){this._refreshStyle(e),this._dimensionsChanged&&this._refreshXPosition(e)}_createElement(e){let t=this._coreBrowserService.mainDocument.createElement(`div`);t.classList.add(`xterm-decoration`),t.classList.toggle(`xterm-decoration-top-layer`,e?.options?.layer===`top`),t.style.width=`${Math.round((e.options.width||1)*this._renderService.dimensions.css.cell.width)}px`,t.style.height=(e.options.height||1)*this._renderService.dimensions.css.cell.height+`px`,t.style.top=(e.marker.line-this._bufferService.buffers.active.ydisp)*this._renderService.dimensions.css.cell.height+`px`,t.style.lineHeight=`${this._renderService.dimensions.css.cell.height}px`;let n=e.options.x??0;return n&&n>this._bufferService.cols&&(t.style.display=`none`),this._refreshXPosition(e,t),t}_refreshStyle(e){let t=e.marker.line-this._bufferService.buffers.active.ydisp;if(t<0||t>=this._bufferService.rows)e.element&&(e.element.style.display=`none`,e.onRenderEmitter.fire(e.element));else{let n=this._decorationElements.get(e);n||(n=this._createElement(e),e.element=n,this._decorationElements.set(e,n),this._container.appendChild(n),e.onDispose((()=>{this._decorationElements.delete(e),n.remove()}))),n.style.top=t*this._renderService.dimensions.css.cell.height+`px`,n.style.display=this._altBufferIsActive?`none`:`block`,e.onRenderEmitter.fire(n)}}_refreshXPosition(e,t=e.element){if(!t)return;let n=e.options.x??0;(e.options.anchor||`left`)===`right`?t.style.right=n?n*this._renderService.dimensions.css.cell.width+`px`:``:t.style.left=n?n*this._renderService.dimensions.css.cell.width+`px`:``}_removeDecoration(e){this._decorationElements.get(e)?.remove(),this._decorationElements.delete(e),e.dispose()}};t.BufferDecorationRenderer=c=r([i(1,s.IBufferService),i(2,a.ICoreBrowserService),i(3,s.IDecorationService),i(4,a.IRenderService)],c)},5871:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ColorZoneStore=void 0,t.ColorZoneStore=class{constructor(){this._zones=[],this._zonePool=[],this._zonePoolIndex=0,this._linePadding={full:0,left:0,center:0,right:0}}get zones(){return this._zonePool.length=Math.min(this._zonePool.length,this._zones.length),this._zones}clear(){this._zones.length=0,this._zonePoolIndex=0}addDecoration(e){if(e.options.overviewRulerOptions){for(let t of this._zones)if(t.color===e.options.overviewRulerOptions.color&&t.position===e.options.overviewRulerOptions.position){if(this._lineIntersectsZone(t,e.marker.line))return;if(this._lineAdjacentToZone(t,e.marker.line,e.options.overviewRulerOptions.position))return void this._addLineToZone(t,e.marker.line)}if(this._zonePoolIndex<this._zonePool.length)return this._zonePool[this._zonePoolIndex].color=e.options.overviewRulerOptions.color,this._zonePool[this._zonePoolIndex].position=e.options.overviewRulerOptions.position,this._zonePool[this._zonePoolIndex].startBufferLine=e.marker.line,this._zonePool[this._zonePoolIndex].endBufferLine=e.marker.line,void this._zones.push(this._zonePool[this._zonePoolIndex++]);this._zones.push({color:e.options.overviewRulerOptions.color,position:e.options.overviewRulerOptions.position,startBufferLine:e.marker.line,endBufferLine:e.marker.line}),this._zonePool.push(this._zones[this._zones.length-1]),this._zonePoolIndex++}}setPadding(e){this._linePadding=e}_lineIntersectsZone(e,t){return t>=e.startBufferLine&&t<=e.endBufferLine}_lineAdjacentToZone(e,t,n){return t>=e.startBufferLine-this._linePadding[n||`full`]&&t<=e.endBufferLine+this._linePadding[n||`full`]}_addLineToZone(e,t){e.startBufferLine=Math.min(e.startBufferLine,t),e.endBufferLine=Math.max(e.endBufferLine,t)}}},5744:function(e,t,n){var r=this&&this.__decorate||function(e,t,n,r){var i,a=arguments.length,o=a<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)o=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o},i=this&&this.__param||function(e,t){return function(n,r){t(n,r,e)}};Object.defineProperty(t,"__esModule",{value:!0}),t.OverviewRulerRenderer=void 0;let a=n(5871),o=n(4725),s=n(844),c=n(2585),l={full:0,left:0,center:0,right:0},u={full:0,left:0,center:0,right:0},d={full:0,left:0,center:0,right:0},f=t.OverviewRulerRenderer=class extends s.Disposable{get _width(){return this._optionsService.options.overviewRulerWidth||0}constructor(e,t,n,r,i,o,c){super(),this._viewportElement=e,this._screenElement=t,this._bufferService=n,this._decorationService=r,this._renderService=i,this._optionsService=o,this._coreBrowserService=c,this._colorZoneStore=new a.ColorZoneStore,this._shouldUpdateDimensions=!0,this._shouldUpdateAnchor=!0,this._lastKnownBufferLength=0,this._canvas=this._coreBrowserService.mainDocument.createElement(`canvas`),this._canvas.classList.add(`xterm-decoration-overview-ruler`),this._refreshCanvasDimensions(),this._viewportElement.parentElement?.insertBefore(this._canvas,this._viewportElement);let l=this._canvas.getContext(`2d`);if(!l)throw Error(`Ctx cannot be null`);this._ctx=l,this._registerDecorationListeners(),this._registerBufferChangeListeners(),this._registerDimensionChangeListeners(),this.register((0,s.toDisposable)((()=>{this._canvas?.remove()})))}_registerDecorationListeners(){this.register(this._decorationService.onDecorationRegistered((()=>this._queueRefresh(void 0,!0)))),this.register(this._decorationService.onDecorationRemoved((()=>this._queueRefresh(void 0,!0))))}_registerBufferChangeListeners(){this.register(this._renderService.onRenderedViewportChange((()=>this._queueRefresh()))),this.register(this._bufferService.buffers.onBufferActivate((()=>{this._canvas.style.display=this._bufferService.buffer===this._bufferService.buffers.alt?`none`:`block`}))),this.register(this._bufferService.onScroll((()=>{this._lastKnownBufferLength!==this._bufferService.buffers.normal.lines.length&&(this._refreshDrawHeightConstants(),this._refreshColorZonePadding())})))}_registerDimensionChangeListeners(){this.register(this._renderService.onRender((()=>{this._containerHeight&&this._containerHeight===this._screenElement.clientHeight||(this._queueRefresh(!0),this._containerHeight=this._screenElement.clientHeight)}))),this.register(this._optionsService.onSpecificOptionChange(`overviewRulerWidth`,(()=>this._queueRefresh(!0)))),this.register(this._coreBrowserService.onDprChange((()=>this._queueRefresh(!0)))),this._queueRefresh(!0)}_refreshDrawConstants(){let e=Math.floor(this._canvas.width/3),t=Math.ceil(this._canvas.width/3);u.full=this._canvas.width,u.left=e,u.center=t,u.right=e,this._refreshDrawHeightConstants(),d.full=0,d.left=0,d.center=u.left,d.right=u.left+u.center}_refreshDrawHeightConstants(){l.full=Math.round(2*this._coreBrowserService.dpr);let e=this._canvas.height/this._bufferService.buffer.lines.length,t=Math.round(Math.max(Math.min(e,12),6)*this._coreBrowserService.dpr);l.left=t,l.center=t,l.right=t}_refreshColorZonePadding(){this._colorZoneStore.setPadding({full:Math.floor(this._bufferService.buffers.active.lines.length/(this._canvas.height-1)*l.full),left:Math.floor(this._bufferService.buffers.active.lines.length/(this._canvas.height-1)*l.left),center:Math.floor(this._bufferService.buffers.active.lines.length/(this._canvas.height-1)*l.center),right:Math.floor(this._bufferService.buffers.active.lines.length/(this._canvas.height-1)*l.right)}),this._lastKnownBufferLength=this._bufferService.buffers.normal.lines.length}_refreshCanvasDimensions(){this._canvas.style.width=`${this._width}px`,this._canvas.width=Math.round(this._width*this._coreBrowserService.dpr),this._canvas.style.height=`${this._screenElement.clientHeight}px`,this._canvas.height=Math.round(this._screenElement.clientHeight*this._coreBrowserService.dpr),this._refreshDrawConstants(),this._refreshColorZonePadding()}_refreshDecorations(){this._shouldUpdateDimensions&&this._refreshCanvasDimensions(),this._ctx.clearRect(0,0,this._canvas.width,this._canvas.height),this._colorZoneStore.clear();for(let e of this._decorationService.decorations)this._colorZoneStore.addDecoration(e);this._ctx.lineWidth=1;let e=this._colorZoneStore.zones;for(let t of e)t.position!==`full`&&this._renderColorZone(t);for(let t of e)t.position===`full`&&this._renderColorZone(t);this._shouldUpdateDimensions=!1,this._shouldUpdateAnchor=!1}_renderColorZone(e){this._ctx.fillStyle=e.color,this._ctx.fillRect(d[e.position||`full`],Math.round((this._canvas.height-1)*(e.startBufferLine/this._bufferService.buffers.active.lines.length)-l[e.position||`full`]/2),u[e.position||`full`],Math.round((this._canvas.height-1)*((e.endBufferLine-e.startBufferLine)/this._bufferService.buffers.active.lines.length)+l[e.position||`full`]))}_queueRefresh(e,t){this._shouldUpdateDimensions=e||this._shouldUpdateDimensions,this._shouldUpdateAnchor=t||this._shouldUpdateAnchor,this._animationFrame===void 0&&(this._animationFrame=this._coreBrowserService.window.requestAnimationFrame((()=>{this._refreshDecorations(),this._animationFrame=void 0})))}};t.OverviewRulerRenderer=f=r([i(2,c.IBufferService),i(3,c.IDecorationService),i(4,o.IRenderService),i(5,c.IOptionsService),i(6,o.ICoreBrowserService)],f)},2950:function(e,t,n){var r=this&&this.__decorate||function(e,t,n,r){var i,a=arguments.length,o=a<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)o=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o},i=this&&this.__param||function(e,t){return function(n,r){t(n,r,e)}};Object.defineProperty(t,"__esModule",{value:!0}),t.CompositionHelper=void 0;let a=n(4725),o=n(2585),s=n(2584),c=t.CompositionHelper=class{get isComposing(){return this._isComposing}constructor(e,t,n,r,i,a){this._textarea=e,this._compositionView=t,this._bufferService=n,this._optionsService=r,this._coreService=i,this._renderService=a,this._isComposing=!1,this._isSendingComposition=!1,this._compositionPosition={start:0,end:0},this._dataAlreadySent=``}compositionstart(){this._isComposing=!0,this._compositionPosition.start=this._textarea.value.length,this._compositionView.textContent=``,this._dataAlreadySent=``,this._compositionView.classList.add(`active`)}compositionupdate(e){this._compositionView.textContent=e.data,this.updateCompositionElements(),setTimeout((()=>{this._compositionPosition.end=this._textarea.value.length}),0)}compositionend(){this._finalizeComposition(!0)}keydown(e){if(this._isComposing||this._isSendingComposition){if(e.keyCode===229||e.keyCode===16||e.keyCode===17||e.keyCode===18)return!1;this._finalizeComposition(!1)}return e.keyCode!==229||(this._handleAnyTextareaChanges(),!1)}_finalizeComposition(e){if(this._compositionView.classList.remove(`active`),this._isComposing=!1,e){let e={start:this._compositionPosition.start,end:this._compositionPosition.end};this._isSendingComposition=!0,setTimeout((()=>{if(this._isSendingComposition){let t;this._isSendingComposition=!1,e.start+=this._dataAlreadySent.length,t=this._isComposing?this._textarea.value.substring(e.start,e.end):this._textarea.value.substring(e.start),t.length>0&&this._coreService.triggerDataEvent(t,!0)}}),0)}else{this._isSendingComposition=!1;let e=this._textarea.value.substring(this._compositionPosition.start,this._compositionPosition.end);this._coreService.triggerDataEvent(e,!0)}}_handleAnyTextareaChanges(){let e=this._textarea.value;setTimeout((()=>{if(!this._isComposing){let t=this._textarea.value,n=t.replace(e,``);this._dataAlreadySent=n,t.length>e.length?this._coreService.triggerDataEvent(n,!0):t.length<e.length?this._coreService.triggerDataEvent(`${s.C0.DEL}`,!0):t.length===e.length&&t!==e&&this._coreService.triggerDataEvent(t,!0)}}),0)}updateCompositionElements(e){if(this._isComposing){if(this._bufferService.buffer.isCursorInViewport){let e=Math.min(this._bufferService.buffer.x,this._bufferService.cols-1),t=this._renderService.dimensions.css.cell.height,n=this._bufferService.buffer.y*this._renderService.dimensions.css.cell.height,r=e*this._renderService.dimensions.css.cell.width;this._compositionView.style.left=r+`px`,this._compositionView.style.top=n+`px`,this._compositionView.style.height=t+`px`,this._compositionView.style.lineHeight=t+`px`,this._compositionView.style.fontFamily=this._optionsService.rawOptions.fontFamily,this._compositionView.style.fontSize=this._optionsService.rawOptions.fontSize+`px`;let i=this._compositionView.getBoundingClientRect();this._textarea.style.left=r+`px`,this._textarea.style.top=n+`px`,this._textarea.style.width=Math.max(i.width,1)+`px`,this._textarea.style.height=Math.max(i.height,1)+`px`,this._textarea.style.lineHeight=i.height+`px`}e||setTimeout((()=>this.updateCompositionElements(!0)),0)}}};t.CompositionHelper=c=r([i(2,o.IBufferService),i(3,o.IOptionsService),i(4,o.ICoreService),i(5,a.IRenderService)],c)},9806:(e,t)=>{function n(e,t,n){let r=n.getBoundingClientRect(),i=e.getComputedStyle(n),a=parseInt(i.getPropertyValue(`padding-left`)),o=parseInt(i.getPropertyValue(`padding-top`));return[t.clientX-r.left-a,t.clientY-r.top-o]}Object.defineProperty(t,"__esModule",{value:!0}),t.getCoords=t.getCoordsRelativeToElement=void 0,t.getCoordsRelativeToElement=n,t.getCoords=function(e,t,r,i,a,o,s,c,l){if(!o)return;let u=n(e,t,r);return u?(u[0]=Math.ceil((u[0]+(l?s/2:0))/s),u[1]=Math.ceil(u[1]/c),u[0]=Math.min(Math.max(u[0],1),i+ +!!l),u[1]=Math.min(Math.max(u[1],1),a),u):void 0}},9504:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.moveToCellSequence=void 0;let r=n(2584);function i(e,t,n,r){let i=e-a(e,n),s=t-a(t,n);return l(Math.abs(i-s)-function(e,t,n){let r=0,i=e-a(e,n),s=t-a(t,n);for(let a=0;a<Math.abs(i-s);a++){let s=o(e,t)===`A`?-1:1;n.buffer.lines.get(i+s*a)?.isWrapped&&r++}return r}(e,t,n),c(o(e,t),r))}function a(e,t){let n=0,r=t.buffer.lines.get(e),i=r?.isWrapped;for(;i&&e>=0&&e<t.rows;)n++,r=t.buffer.lines.get(--e),i=r?.isWrapped;return n}function o(e,t){return e>t?`A`:`B`}function s(e,t,n,r,i,a){let o=e,s=t,c=``;for(;o!==n||s!==r;)o+=i?1:-1,i&&o>a.cols-1?(c+=a.buffer.translateBufferLineToString(s,!1,e,o),o=0,e=0,s++):!i&&o<0&&(c+=a.buffer.translateBufferLineToString(s,!1,0,e+1),o=a.cols-1,e=o,s--);return c+a.buffer.translateBufferLineToString(s,!1,e,o)}function c(e,t){let n=t?`O`:`[`;return r.C0.ESC+n+e}function l(e,t){e=Math.floor(e);let n=``;for(let r=0;r<e;r++)n+=t;return n}t.moveToCellSequence=function(e,t,n,r){let o=n.buffer.x,u=n.buffer.y;if(!n.buffer.hasScrollback)return function(e,t,n,r,o,u){return i(t,r,o,u).length===0?``:l(s(e,t,e,t-a(t,o),!1,o).length,c(`D`,u))}(o,u,0,t,n,r)+i(u,t,n,r)+function(e,t,n,r,o,u){let d;d=i(t,r,o,u).length>0?r-a(r,o):t;let f=r,p=function(e,t,n,r,o,s){let c;return c=i(n,r,o,s).length>0?r-a(r,o):t,e<n&&c<=r||e>=n&&c<r?`C`:`D`}(e,t,n,r,o,u);return l(s(e,d,n,f,p===`C`,o).length,c(p,u))}(o,u,e,t,n,r);let d;if(u===t)return d=o>e?`D`:`C`,l(Math.abs(o-e),c(d,r));d=u>t?`D`:`C`;let f=Math.abs(u-t);return l(function(e,t){return t.cols-e}(u>t?e:o,n)+(f-1)*n.cols+1+((u>t?o:e)-1),c(d,r))}},1296:function(e,t,n){var r=this&&this.__decorate||function(e,t,n,r){var i,a=arguments.length,o=a<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)o=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o},i=this&&this.__param||function(e,t){return function(n,r){t(n,r,e)}};Object.defineProperty(t,"__esModule",{value:!0}),t.DomRenderer=void 0;let a=n(3787),o=n(2550),s=n(2223),c=n(6171),l=n(6052),u=n(4725),d=n(8055),f=n(8460),p=n(844),m=n(2585),h=`xterm-dom-renderer-owner-`,g=`xterm-rows`,_=`xterm-fg-`,v=`xterm-bg-`,y=`xterm-focus`,b=`xterm-selection`,x=1,S=t.DomRenderer=class extends p.Disposable{constructor(e,t,n,r,i,s,u,d,m,_,v,y,S){super(),this._terminal=e,this._document=t,this._element=n,this._screenElement=r,this._viewportElement=i,this._helperContainer=s,this._linkifier2=u,this._charSizeService=m,this._optionsService=_,this._bufferService=v,this._coreBrowserService=y,this._themeService=S,this._terminalClass=x++,this._rowElements=[],this._selectionRenderModel=(0,l.createSelectionRenderModel)(),this.onRequestRedraw=this.register(new f.EventEmitter).event,this._rowContainer=this._document.createElement(`div`),this._rowContainer.classList.add(g),this._rowContainer.style.lineHeight=`normal`,this._rowContainer.setAttribute(`aria-hidden`,`true`),this._refreshRowElements(this._bufferService.cols,this._bufferService.rows),this._selectionContainer=this._document.createElement(`div`),this._selectionContainer.classList.add(b),this._selectionContainer.setAttribute(`aria-hidden`,`true`),this.dimensions=(0,c.createRenderDimensions)(),this._updateDimensions(),this.register(this._optionsService.onOptionChange((()=>this._handleOptionsChanged()))),this.register(this._themeService.onChangeColors((e=>this._injectCss(e)))),this._injectCss(this._themeService.colors),this._rowFactory=d.createInstance(a.DomRendererRowFactory,document),this._element.classList.add(h+this._terminalClass),this._screenElement.appendChild(this._rowContainer),this._screenElement.appendChild(this._selectionContainer),this.register(this._linkifier2.onShowLinkUnderline((e=>this._handleLinkHover(e)))),this.register(this._linkifier2.onHideLinkUnderline((e=>this._handleLinkLeave(e)))),this.register((0,p.toDisposable)((()=>{this._element.classList.remove(h+this._terminalClass),this._rowContainer.remove(),this._selectionContainer.remove(),this._widthCache.dispose(),this._themeStyleElement.remove(),this._dimensionsStyleElement.remove()}))),this._widthCache=new o.WidthCache(this._document,this._helperContainer),this._widthCache.setFont(this._optionsService.rawOptions.fontFamily,this._optionsService.rawOptions.fontSize,this._optionsService.rawOptions.fontWeight,this._optionsService.rawOptions.fontWeightBold),this._setDefaultSpacing()}_updateDimensions(){let e=this._coreBrowserService.dpr;this.dimensions.device.char.width=this._charSizeService.width*e,this.dimensions.device.char.height=Math.ceil(this._charSizeService.height*e),this.dimensions.device.cell.width=this.dimensions.device.char.width+Math.round(this._optionsService.rawOptions.letterSpacing),this.dimensions.device.cell.height=Math.floor(this.dimensions.device.char.height*this._optionsService.rawOptions.lineHeight),this.dimensions.device.char.left=0,this.dimensions.device.char.top=0,this.dimensions.device.canvas.width=this.dimensions.device.cell.width*this._bufferService.cols,this.dimensions.device.canvas.height=this.dimensions.device.cell.height*this._bufferService.rows,this.dimensions.css.canvas.width=Math.round(this.dimensions.device.canvas.width/e),this.dimensions.css.canvas.height=Math.round(this.dimensions.device.canvas.height/e),this.dimensions.css.cell.width=this.dimensions.css.canvas.width/this._bufferService.cols,this.dimensions.css.cell.height=this.dimensions.css.canvas.height/this._bufferService.rows;for(let e of this._rowElements)e.style.width=`${this.dimensions.css.canvas.width}px`,e.style.height=`${this.dimensions.css.cell.height}px`,e.style.lineHeight=`${this.dimensions.css.cell.height}px`,e.style.overflow=`hidden`;this._dimensionsStyleElement||(this._dimensionsStyleElement=this._document.createElement(`style`),this._screenElement.appendChild(this._dimensionsStyleElement));let t=`${this._terminalSelector} .${g} span { display: inline-block; height: 100%; vertical-align: top;}`;this._dimensionsStyleElement.textContent=t,this._selectionContainer.style.height=this._viewportElement.style.height,this._screenElement.style.width=`${this.dimensions.css.canvas.width}px`,this._screenElement.style.height=`${this.dimensions.css.canvas.height}px`}_injectCss(e){this._themeStyleElement||(this._themeStyleElement=this._document.createElement(`style`),this._screenElement.appendChild(this._themeStyleElement));let t=`${this._terminalSelector} .${g} { color: ${e.foreground.css}; font-family: ${this._optionsService.rawOptions.fontFamily}; font-size: ${this._optionsService.rawOptions.fontSize}px; font-kerning: none; white-space: pre}`;t+=`${this._terminalSelector} .${g} .xterm-dim { color: ${d.color.multiplyOpacity(e.foreground,.5).css};}`,t+=`${this._terminalSelector} span:not(.xterm-bold) { font-weight: ${this._optionsService.rawOptions.fontWeight};}${this._terminalSelector} span.xterm-bold { font-weight: ${this._optionsService.rawOptions.fontWeightBold};}${this._terminalSelector} span.xterm-italic { font-style: italic;}`;let n=`blink_underline_${this._terminalClass}`,r=`blink_bar_${this._terminalClass}`,i=`blink_block_${this._terminalClass}`;t+=`@keyframes ${n} { 50% { border-bottom-style: hidden; }}`,t+=`@keyframes ${r} { 50% { box-shadow: none; }}`,t+=`@keyframes ${i} { 0% { background-color: ${e.cursor.css}; color: ${e.cursorAccent.css}; } 50% { background-color: inherit; color: ${e.cursor.css}; }}`,t+=`${this._terminalSelector} .${g}.${y} .xterm-cursor.xterm-cursor-blink.xterm-cursor-underline { animation: ${n} 1s step-end infinite;}${this._terminalSelector} .${g}.${y} .xterm-cursor.xterm-cursor-blink.xterm-cursor-bar { animation: ${r} 1s step-end infinite;}${this._terminalSelector} .${g}.${y} .xterm-cursor.xterm-cursor-blink.xterm-cursor-block { animation: ${i} 1s step-end infinite;}${this._terminalSelector} .${g} .xterm-cursor.xterm-cursor-block { background-color: ${e.cursor.css}; color: ${e.cursorAccent.css};}${this._terminalSelector} .${g} .xterm-cursor.xterm-cursor-block:not(.xterm-cursor-blink) { background-color: ${e.cursor.css} !important; color: ${e.cursorAccent.css} !important;}${this._terminalSelector} .${g} .xterm-cursor.xterm-cursor-outline { outline: 1px solid ${e.cursor.css}; outline-offset: -1px;}${this._terminalSelector} .${g} .xterm-cursor.xterm-cursor-bar { box-shadow: ${this._optionsService.rawOptions.cursorWidth}px 0 0 ${e.cursor.css} inset;}${this._terminalSelector} .${g} .xterm-cursor.xterm-cursor-underline { border-bottom: 1px ${e.cursor.css}; border-bottom-style: solid; height: calc(100% - 1px);}`,t+=`${this._terminalSelector} .${b} { position: absolute; top: 0; left: 0; z-index: 1; pointer-events: none;}${this._terminalSelector}.focus .${b} div { position: absolute; background-color: ${e.selectionBackgroundOpaque.css};}${this._terminalSelector} .${b} div { position: absolute; background-color: ${e.selectionInactiveBackgroundOpaque.css};}`;for(let[n,r]of e.ansi.entries())t+=`${this._terminalSelector} .${_}${n} { color: ${r.css}; }${this._terminalSelector} .${_}${n}.xterm-dim { color: ${d.color.multiplyOpacity(r,.5).css}; }${this._terminalSelector} .${v}${n} { background-color: ${r.css}; }`;t+=`${this._terminalSelector} .${_}${s.INVERTED_DEFAULT_COLOR} { color: ${d.color.opaque(e.background).css}; }${this._terminalSelector} .${_}${s.INVERTED_DEFAULT_COLOR}.xterm-dim { color: ${d.color.multiplyOpacity(d.color.opaque(e.background),.5).css}; }${this._terminalSelector} .${v}${s.INVERTED_DEFAULT_COLOR} { background-color: ${e.foreground.css}; }`,this._themeStyleElement.textContent=t}_setDefaultSpacing(){let e=this.dimensions.css.cell.width-this._widthCache.get(`W`,!1,!1);this._rowContainer.style.letterSpacing=`${e}px`,this._rowFactory.defaultSpacing=e}handleDevicePixelRatioChange(){this._updateDimensions(),this._widthCache.clear(),this._setDefaultSpacing()}_refreshRowElements(e,t){for(let e=this._rowElements.length;e<=t;e++){let e=this._document.createElement(`div`);this._rowContainer.appendChild(e),this._rowElements.push(e)}for(;this._rowElements.length>t;)this._rowContainer.removeChild(this._rowElements.pop())}handleResize(e,t){this._refreshRowElements(e,t),this._updateDimensions(),this.handleSelectionChanged(this._selectionRenderModel.selectionStart,this._selectionRenderModel.selectionEnd,this._selectionRenderModel.columnSelectMode)}handleCharSizeChanged(){this._updateDimensions(),this._widthCache.clear(),this._setDefaultSpacing()}handleBlur(){this._rowContainer.classList.remove(y),this.renderRows(0,this._bufferService.rows-1)}handleFocus(){this._rowContainer.classList.add(y),this.renderRows(this._bufferService.buffer.y,this._bufferService.buffer.y)}handleSelectionChanged(e,t,n){if(this._selectionContainer.replaceChildren(),this._rowFactory.handleSelectionChanged(e,t,n),this.renderRows(0,this._bufferService.rows-1),!e||!t)return;this._selectionRenderModel.update(this._terminal,e,t,n);let r=this._selectionRenderModel.viewportStartRow,i=this._selectionRenderModel.viewportEndRow,a=this._selectionRenderModel.viewportCappedStartRow,o=this._selectionRenderModel.viewportCappedEndRow;if(a>=this._bufferService.rows||o<0)return;let s=this._document.createDocumentFragment();if(n){let n=e[0]>t[0];s.appendChild(this._createSelectionElement(a,n?t[0]:e[0],n?e[0]:t[0],o-a+1))}else{let n=r===a?e[0]:0,c=a===i?t[0]:this._bufferService.cols;s.appendChild(this._createSelectionElement(a,n,c));let l=o-a-1;if(s.appendChild(this._createSelectionElement(a+1,0,this._bufferService.cols,l)),a!==o){let e=i===o?t[0]:this._bufferService.cols;s.appendChild(this._createSelectionElement(o,0,e))}}this._selectionContainer.appendChild(s)}_createSelectionElement(e,t,n,r=1){let i=this._document.createElement(`div`),a=t*this.dimensions.css.cell.width,o=this.dimensions.css.cell.width*(n-t);return a+o>this.dimensions.css.canvas.width&&(o=this.dimensions.css.canvas.width-a),i.style.height=r*this.dimensions.css.cell.height+`px`,i.style.top=e*this.dimensions.css.cell.height+`px`,i.style.left=`${a}px`,i.style.width=`${o}px`,i}handleCursorMove(){}_handleOptionsChanged(){this._updateDimensions(),this._injectCss(this._themeService.colors),this._widthCache.setFont(this._optionsService.rawOptions.fontFamily,this._optionsService.rawOptions.fontSize,this._optionsService.rawOptions.fontWeight,this._optionsService.rawOptions.fontWeightBold),this._setDefaultSpacing()}clear(){for(let e of this._rowElements)e.replaceChildren()}renderRows(e,t){let n=this._bufferService.buffer,r=n.ybase+n.y,i=Math.min(n.x,this._bufferService.cols-1),a=this._optionsService.rawOptions.cursorBlink,o=this._optionsService.rawOptions.cursorStyle,s=this._optionsService.rawOptions.cursorInactiveStyle;for(let c=e;c<=t;c++){let e=c+n.ydisp,t=this._rowElements[c],l=n.lines.get(e);if(!t||!l)break;t.replaceChildren(...this._rowFactory.createRow(l,e,e===r,o,s,i,a,this.dimensions.css.cell.width,this._widthCache,-1,-1))}}get _terminalSelector(){return`.${h}${this._terminalClass}`}_handleLinkHover(e){this._setCellUnderline(e.x1,e.x2,e.y1,e.y2,e.cols,!0)}_handleLinkLeave(e){this._setCellUnderline(e.x1,e.x2,e.y1,e.y2,e.cols,!1)}_setCellUnderline(e,t,n,r,i,a){n<0&&(e=0),r<0&&(t=0);let o=this._bufferService.rows-1;n=Math.max(Math.min(n,o),0),r=Math.max(Math.min(r,o),0),i=Math.min(i,this._bufferService.cols);let s=this._bufferService.buffer,c=s.ybase+s.y,l=Math.min(s.x,i-1),u=this._optionsService.rawOptions.cursorBlink,d=this._optionsService.rawOptions.cursorStyle,f=this._optionsService.rawOptions.cursorInactiveStyle;for(let o=n;o<=r;++o){let p=o+s.ydisp,m=this._rowElements[o],h=s.lines.get(p);if(!m||!h)break;m.replaceChildren(...this._rowFactory.createRow(h,p,p===c,d,f,l,u,this.dimensions.css.cell.width,this._widthCache,a?o===n?e:0:-1,a?(o===r?t:i)-1:-1))}}};t.DomRenderer=S=r([i(7,m.IInstantiationService),i(8,u.ICharSizeService),i(9,m.IOptionsService),i(10,m.IBufferService),i(11,u.ICoreBrowserService),i(12,u.IThemeService)],S)},3787:function(e,t,n){var r=this&&this.__decorate||function(e,t,n,r){var i,a=arguments.length,o=a<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)o=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o},i=this&&this.__param||function(e,t){return function(n,r){t(n,r,e)}};Object.defineProperty(t,"__esModule",{value:!0}),t.DomRendererRowFactory=void 0;let a=n(2223),o=n(643),s=n(511),c=n(2585),l=n(8055),u=n(4725),d=n(4269),f=n(6171),p=n(3734),m=t.DomRendererRowFactory=class{constructor(e,t,n,r,i,a,o){this._document=e,this._characterJoinerService=t,this._optionsService=n,this._coreBrowserService=r,this._coreService=i,this._decorationService=a,this._themeService=o,this._workCell=new s.CellData,this._columnSelectMode=!1,this.defaultSpacing=0}handleSelectionChanged(e,t,n){this._selectionStart=e,this._selectionEnd=t,this._columnSelectMode=n}createRow(e,t,n,r,i,s,c,u,f,m,g){let _=[],v=this._characterJoinerService.getJoinedCharacters(t),y=this._themeService.colors,b,x=e.getNoBgTrimmedLength();n&&x<s+1&&(x=s+1);let S=0,C=``,w=0,T=0,E=0,D=!1,O=0,k=!1,ee=0,A=[],te=m!==-1&&g!==-1;for(let ne=0;ne<x;ne++){e.loadCell(ne,this._workCell);let x=this._workCell.getWidth();if(x===0)continue;let re=!1,ie=ne,j=this._workCell;if(v.length>0&&ne===v[0][0]){re=!0;let t=v.shift();j=new d.JoinedCellData(this._workCell,e.translateToString(!0,t[0],t[1]),t[1]-t[0]),ie=t[1]-1,x=j.getWidth()}let ae=this._isCellInSelection(ne,t),M=n&&ne===s,oe=te&&ne>=m&&ne<=g,se=!1;this._decorationService.forEachDecorationAtCell(ne,t,void 0,(e=>{se=!0}));let ce=j.getChars()||o.WHITESPACE_CELL_CHAR;if(ce===` `&&(j.isUnderline()||j.isOverline())&&(ce=`\xA0`),ee=x*u-f.get(ce,j.isBold(),j.isItalic()),b){if(S&&(ae&&k||!ae&&!k&&j.bg===w)&&(ae&&k&&y.selectionForeground||j.fg===T)&&j.extended.ext===E&&oe===D&&ee===O&&!M&&!re&&!se){j.isInvisible()?C+=o.WHITESPACE_CELL_CHAR:C+=ce,S++;continue}S&&(b.textContent=C),b=this._document.createElement(`span`),S=0,C=``}else b=this._document.createElement(`span`);if(w=j.bg,T=j.fg,E=j.extended.ext,D=oe,O=ee,k=ae,re&&s>=ne&&s<=ie&&(s=ne),!this._coreService.isCursorHidden&&M&&this._coreService.isCursorInitialized){if(A.push(`xterm-cursor`),this._coreBrowserService.isFocused)c&&A.push(`xterm-cursor-blink`),A.push(r===`bar`?`xterm-cursor-bar`:r===`underline`?`xterm-cursor-underline`:`xterm-cursor-block`);else if(i)switch(i){case`outline`:A.push(`xterm-cursor-outline`);break;case`block`:A.push(`xterm-cursor-block`);break;case`bar`:A.push(`xterm-cursor-bar`);break;case`underline`:A.push(`xterm-cursor-underline`)}}if(j.isBold()&&A.push(`xterm-bold`),j.isItalic()&&A.push(`xterm-italic`),j.isDim()&&A.push(`xterm-dim`),C=j.isInvisible()?o.WHITESPACE_CELL_CHAR:j.getChars()||o.WHITESPACE_CELL_CHAR,j.isUnderline()&&(A.push(`xterm-underline-${j.extended.underlineStyle}`),C===` `&&(C=`\xA0`),!j.isUnderlineColorDefault()))if(j.isUnderlineColorRGB())b.style.textDecorationColor=`rgb(${p.AttributeData.toColorRGB(j.getUnderlineColor()).join(`,`)})`;else{let e=j.getUnderlineColor();this._optionsService.rawOptions.drawBoldTextInBrightColors&&j.isBold()&&e<8&&(e+=8),b.style.textDecorationColor=y.ansi[e].css}j.isOverline()&&(A.push(`xterm-overline`),C===` `&&(C=`\xA0`)),j.isStrikethrough()&&A.push(`xterm-strikethrough`),oe&&(b.style.textDecoration=`underline`);let le=j.getFgColor(),ue=j.getFgColorMode(),de=j.getBgColor(),fe=j.getBgColorMode(),pe=!!j.isInverse();if(pe){let e=le;le=de,de=e;let t=ue;ue=fe,fe=t}let me,he,ge,_e=!1;switch(this._decorationService.forEachDecorationAtCell(ne,t,void 0,(e=>{e.options.layer!==`top`&&_e||(e.backgroundColorRGB&&(fe=50331648,de=e.backgroundColorRGB.rgba>>8&16777215,me=e.backgroundColorRGB),e.foregroundColorRGB&&(ue=50331648,le=e.foregroundColorRGB.rgba>>8&16777215,he=e.foregroundColorRGB),_e=e.options.layer===`top`)})),!_e&&ae&&(me=this._coreBrowserService.isFocused?y.selectionBackgroundOpaque:y.selectionInactiveBackgroundOpaque,de=me.rgba>>8&16777215,fe=50331648,_e=!0,y.selectionForeground&&(ue=50331648,le=y.selectionForeground.rgba>>8&16777215,he=y.selectionForeground)),_e&&A.push(`xterm-decoration-top`),fe){case 16777216:case 33554432:ge=y.ansi[de],A.push(`xterm-bg-${de}`);break;case 50331648:ge=l.channels.toColor(de>>16,de>>8&255,255&de),this._addStyle(b,`background-color:#${h((de>>>0).toString(16),`0`,6)}`);break;default:pe?(ge=y.foreground,A.push(`xterm-bg-${a.INVERTED_DEFAULT_COLOR}`)):ge=y.background}switch(me||j.isDim()&&(me=l.color.multiplyOpacity(ge,.5)),ue){case 16777216:case 33554432:j.isBold()&&le<8&&this._optionsService.rawOptions.drawBoldTextInBrightColors&&(le+=8),this._applyMinimumContrast(b,ge,y.ansi[le],j,me,void 0)||A.push(`xterm-fg-${le}`);break;case 50331648:let e=l.channels.toColor(le>>16&255,le>>8&255,255&le);this._applyMinimumContrast(b,ge,e,j,me,he)||this._addStyle(b,`color:#${h(le.toString(16),`0`,6)}`);break;default:this._applyMinimumContrast(b,ge,y.foreground,j,me,he)||pe&&A.push(`xterm-fg-${a.INVERTED_DEFAULT_COLOR}`)}A.length&&=(b.className=A.join(` `),0),M||re||se?b.textContent=C:S++,ee!==this.defaultSpacing&&(b.style.letterSpacing=`${ee}px`),_.push(b),ne=ie}return b&&S&&(b.textContent=C),_}_applyMinimumContrast(e,t,n,r,i,a){if(this._optionsService.rawOptions.minimumContrastRatio===1||(0,f.treatGlyphAsBackgroundColor)(r.getCode()))return!1;let o=this._getContrastCache(r),s;if(i||a||(s=o.getColor(t.rgba,n.rgba)),s===void 0){let e=this._optionsService.rawOptions.minimumContrastRatio/(r.isDim()?2:1);s=l.color.ensureContrastRatio(i||t,a||n,e),o.setColor((i||t).rgba,(a||n).rgba,s??null)}return!!s&&(this._addStyle(e,`color:${s.css}`),!0)}_getContrastCache(e){return e.isDim()?this._themeService.colors.halfContrastCache:this._themeService.colors.contrastCache}_addStyle(e,t){e.setAttribute(`style`,`${e.getAttribute(`style`)||``}${t};`)}_isCellInSelection(e,t){let n=this._selectionStart,r=this._selectionEnd;return!(!n||!r)&&(this._columnSelectMode?n[0]<=r[0]?e>=n[0]&&t>=n[1]&&e<r[0]&&t<=r[1]:e<n[0]&&t>=n[1]&&e>=r[0]&&t<=r[1]:t>n[1]&&t<r[1]||n[1]===r[1]&&t===n[1]&&e>=n[0]&&e<r[0]||n[1]<r[1]&&t===r[1]&&e<r[0]||n[1]<r[1]&&t===n[1]&&e>=n[0])}};function h(e,t,n){for(;e.length<n;)e=t+e;return e}t.DomRendererRowFactory=m=r([i(1,u.ICharacterJoinerService),i(2,c.IOptionsService),i(3,u.ICoreBrowserService),i(4,c.ICoreService),i(5,c.IDecorationService),i(6,u.IThemeService)],m)},2550:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WidthCache=void 0,t.WidthCache=class{constructor(e,t){this._flat=new Float32Array(256),this._font=``,this._fontSize=0,this._weight=`normal`,this._weightBold=`bold`,this._measureElements=[],this._container=e.createElement(`div`),this._container.classList.add(`xterm-width-cache-measure-container`),this._container.setAttribute(`aria-hidden`,`true`),this._container.style.whiteSpace=`pre`,this._container.style.fontKerning=`none`;let n=e.createElement(`span`);n.classList.add(`xterm-char-measure-element`);let r=e.createElement(`span`);r.classList.add(`xterm-char-measure-element`),r.style.fontWeight=`bold`;let i=e.createElement(`span`);i.classList.add(`xterm-char-measure-element`),i.style.fontStyle=`italic`;let a=e.createElement(`span`);a.classList.add(`xterm-char-measure-element`),a.style.fontWeight=`bold`,a.style.fontStyle=`italic`,this._measureElements=[n,r,i,a],this._container.appendChild(n),this._container.appendChild(r),this._container.appendChild(i),this._container.appendChild(a),t.appendChild(this._container),this.clear()}dispose(){this._container.remove(),this._measureElements.length=0,this._holey=void 0}clear(){this._flat.fill(-9999),this._holey=new Map}setFont(e,t,n,r){e===this._font&&t===this._fontSize&&n===this._weight&&r===this._weightBold||(this._font=e,this._fontSize=t,this._weight=n,this._weightBold=r,this._container.style.fontFamily=this._font,this._container.style.fontSize=`${this._fontSize}px`,this._measureElements[0].style.fontWeight=`${n}`,this._measureElements[1].style.fontWeight=`${r}`,this._measureElements[2].style.fontWeight=`${n}`,this._measureElements[3].style.fontWeight=`${r}`,this.clear())}get(e,t,n){let r=0;if(!t&&!n&&e.length===1&&(r=e.charCodeAt(0))<256){if(this._flat[r]!==-9999)return this._flat[r];let t=this._measure(e,0);return t>0&&(this._flat[r]=t),t}let i=e;t&&(i+=`B`),n&&(i+=`I`);let a=this._holey.get(i);if(a===void 0){let r=0;t&&(r|=1),n&&(r|=2),a=this._measure(e,r),a>0&&this._holey.set(i,a)}return a}_measure(e,t){let n=this._measureElements[t];return n.textContent=e.repeat(32),n.offsetWidth/32}}},2223:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.TEXT_BASELINE=t.DIM_OPACITY=t.INVERTED_DEFAULT_COLOR=void 0;let r=n(6114);t.INVERTED_DEFAULT_COLOR=257,t.DIM_OPACITY=.5,t.TEXT_BASELINE=r.isFirefox||r.isLegacyEdge?`bottom`:`ideographic`},6171:(e,t)=>{function n(e){return 57508<=e&&e<=57558}function r(e){return e>=128512&&e<=128591||e>=127744&&e<=128511||e>=128640&&e<=128767||e>=9728&&e<=9983||e>=9984&&e<=10175||e>=65024&&e<=65039||e>=129280&&e<=129535||e>=127462&&e<=127487}Object.defineProperty(t,"__esModule",{value:!0}),t.computeNextVariantOffset=t.createRenderDimensions=t.treatGlyphAsBackgroundColor=t.allowRescaling=t.isEmoji=t.isRestrictedPowerlineGlyph=t.isPowerlineGlyph=t.throwIfFalsy=void 0,t.throwIfFalsy=function(e){if(!e)throw Error(`value must not be falsy`);return e},t.isPowerlineGlyph=n,t.isRestrictedPowerlineGlyph=function(e){return 57520<=e&&e<=57527},t.isEmoji=r,t.allowRescaling=function(e,t,i,a){return t===1&&i>Math.ceil(1.5*a)&&e!==void 0&&e>255&&!r(e)&&!n(e)&&!function(e){return 57344<=e&&e<=63743}(e)},t.treatGlyphAsBackgroundColor=function(e){return n(e)||function(e){return 9472<=e&&e<=9631}(e)},t.createRenderDimensions=function(){return{css:{canvas:{width:0,height:0},cell:{width:0,height:0}},device:{canvas:{width:0,height:0},cell:{width:0,height:0},char:{width:0,height:0,left:0,top:0}}}},t.computeNextVariantOffset=function(e,t,n=0){return(e-(2*Math.round(t)-n))%(2*Math.round(t))}},6052:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.createSelectionRenderModel=void 0;class n{constructor(){this.clear()}clear(){this.hasSelection=!1,this.columnSelectMode=!1,this.viewportStartRow=0,this.viewportEndRow=0,this.viewportCappedStartRow=0,this.viewportCappedEndRow=0,this.startCol=0,this.endCol=0,this.selectionStart=void 0,this.selectionEnd=void 0}update(e,t,n,r=!1){if(this.selectionStart=t,this.selectionEnd=n,!t||!n||t[0]===n[0]&&t[1]===n[1])return void this.clear();let i=e.buffers.active.ydisp,a=t[1]-i,o=n[1]-i,s=Math.max(a,0),c=Math.min(o,e.rows-1);s>=e.rows||c<0?this.clear():(this.hasSelection=!0,this.columnSelectMode=r,this.viewportStartRow=a,this.viewportEndRow=o,this.viewportCappedStartRow=s,this.viewportCappedEndRow=c,this.startCol=t[0],this.endCol=n[0])}isCellSelected(e,t,n){return!!this.hasSelection&&(n-=e.buffer.active.viewportY,this.columnSelectMode?this.startCol<=this.endCol?t>=this.startCol&&n>=this.viewportCappedStartRow&&t<this.endCol&&n<=this.viewportCappedEndRow:t<this.startCol&&n>=this.viewportCappedStartRow&&t>=this.endCol&&n<=this.viewportCappedEndRow:n>this.viewportStartRow&&n<this.viewportEndRow||this.viewportStartRow===this.viewportEndRow&&n===this.viewportStartRow&&t>=this.startCol&&t<this.endCol||this.viewportStartRow<this.viewportEndRow&&n===this.viewportEndRow&&t<this.endCol||this.viewportStartRow<this.viewportEndRow&&n===this.viewportStartRow&&t>=this.startCol)}}t.createSelectionRenderModel=function(){return new n}},456:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SelectionModel=void 0,t.SelectionModel=class{constructor(e){this._bufferService=e,this.isSelectAllActive=!1,this.selectionStartLength=0}clearSelection(){this.selectionStart=void 0,this.selectionEnd=void 0,this.isSelectAllActive=!1,this.selectionStartLength=0}get finalSelectionStart(){return this.isSelectAllActive?[0,0]:this.selectionEnd&&this.selectionStart&&this.areSelectionValuesReversed()?this.selectionEnd:this.selectionStart}get finalSelectionEnd(){if(this.isSelectAllActive)return[this._bufferService.cols,this._bufferService.buffer.ybase+this._bufferService.rows-1];if(this.selectionStart){if(!this.selectionEnd||this.areSelectionValuesReversed()){let e=this.selectionStart[0]+this.selectionStartLength;return e>this._bufferService.cols?e%this._bufferService.cols==0?[this._bufferService.cols,this.selectionStart[1]+Math.floor(e/this._bufferService.cols)-1]:[e%this._bufferService.cols,this.selectionStart[1]+Math.floor(e/this._bufferService.cols)]:[e,this.selectionStart[1]]}if(this.selectionStartLength&&this.selectionEnd[1]===this.selectionStart[1]){let e=this.selectionStart[0]+this.selectionStartLength;return e>this._bufferService.cols?[e%this._bufferService.cols,this.selectionStart[1]+Math.floor(e/this._bufferService.cols)]:[Math.max(e,this.selectionEnd[0]),this.selectionEnd[1]]}return this.selectionEnd}}areSelectionValuesReversed(){let e=this.selectionStart,t=this.selectionEnd;return!(!e||!t)&&(e[1]>t[1]||e[1]===t[1]&&e[0]>t[0])}handleTrim(e){return this.selectionStart&&(this.selectionStart[1]-=e),this.selectionEnd&&(this.selectionEnd[1]-=e),this.selectionEnd&&this.selectionEnd[1]<0?(this.clearSelection(),!0):(this.selectionStart&&this.selectionStart[1]<0&&(this.selectionStart[1]=0),!1)}}},428:function(e,t,n){var r=this&&this.__decorate||function(e,t,n,r){var i,a=arguments.length,o=a<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)o=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o},i=this&&this.__param||function(e,t){return function(n,r){t(n,r,e)}};Object.defineProperty(t,"__esModule",{value:!0}),t.CharSizeService=void 0;let a=n(2585),o=n(8460),s=n(844),c=t.CharSizeService=class extends s.Disposable{get hasValidSize(){return this.width>0&&this.height>0}constructor(e,t,n){super(),this._optionsService=n,this.width=0,this.height=0,this._onCharSizeChange=this.register(new o.EventEmitter),this.onCharSizeChange=this._onCharSizeChange.event;try{this._measureStrategy=this.register(new d(this._optionsService))}catch{this._measureStrategy=this.register(new u(e,t,this._optionsService))}this.register(this._optionsService.onMultipleOptionChange([`fontFamily`,`fontSize`],(()=>this.measure())))}measure(){let e=this._measureStrategy.measure();e.width===this.width&&e.height===this.height||(this.width=e.width,this.height=e.height,this._onCharSizeChange.fire())}};t.CharSizeService=c=r([i(2,a.IOptionsService)],c);class l extends s.Disposable{constructor(){super(...arguments),this._result={width:0,height:0}}_validateAndSet(e,t){e!==void 0&&e>0&&t!==void 0&&t>0&&(this._result.width=e,this._result.height=t)}}class u extends l{constructor(e,t,n){super(),this._document=e,this._parentElement=t,this._optionsService=n,this._measureElement=this._document.createElement(`span`),this._measureElement.classList.add(`xterm-char-measure-element`),this._measureElement.textContent=`W`.repeat(32),this._measureElement.setAttribute(`aria-hidden`,`true`),this._measureElement.style.whiteSpace=`pre`,this._measureElement.style.fontKerning=`none`,this._parentElement.appendChild(this._measureElement)}measure(){return this._measureElement.style.fontFamily=this._optionsService.rawOptions.fontFamily,this._measureElement.style.fontSize=`${this._optionsService.rawOptions.fontSize}px`,this._validateAndSet(Number(this._measureElement.offsetWidth)/32,Number(this._measureElement.offsetHeight)),this._result}}class d extends l{constructor(e){super(),this._optionsService=e,this._canvas=new OffscreenCanvas(100,100),this._ctx=this._canvas.getContext(`2d`);let t=this._ctx.measureText(`W`);if(!(`width`in t&&`fontBoundingBoxAscent`in t&&`fontBoundingBoxDescent`in t))throw Error(`Required font metrics not supported`)}measure(){this._ctx.font=`${this._optionsService.rawOptions.fontSize}px ${this._optionsService.rawOptions.fontFamily}`;let e=this._ctx.measureText(`W`);return this._validateAndSet(e.width,e.fontBoundingBoxAscent+e.fontBoundingBoxDescent),this._result}}},4269:function(e,t,n){var r=this&&this.__decorate||function(e,t,n,r){var i,a=arguments.length,o=a<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)o=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o},i=this&&this.__param||function(e,t){return function(n,r){t(n,r,e)}};Object.defineProperty(t,"__esModule",{value:!0}),t.CharacterJoinerService=t.JoinedCellData=void 0;let a=n(3734),o=n(643),s=n(511),c=n(2585);class l extends a.AttributeData{constructor(e,t,n){super(),this.content=0,this.combinedData=``,this.fg=e.fg,this.bg=e.bg,this.combinedData=t,this._width=n}isCombined(){return 2097152}getWidth(){return this._width}getChars(){return this.combinedData}getCode(){return 2097151}setFromCharData(e){throw Error(`not implemented`)}getAsCharData(){return[this.fg,this.getChars(),this.getWidth(),this.getCode()]}}t.JoinedCellData=l;let u=t.CharacterJoinerService=class e{constructor(e){this._bufferService=e,this._characterJoiners=[],this._nextCharacterJoinerId=0,this._workCell=new s.CellData}register(e){let t={id:this._nextCharacterJoinerId++,handler:e};return this._characterJoiners.push(t),t.id}deregister(e){for(let t=0;t<this._characterJoiners.length;t++)if(this._characterJoiners[t].id===e)return this._characterJoiners.splice(t,1),!0;return!1}getJoinedCharacters(e){if(this._characterJoiners.length===0)return[];let t=this._bufferService.buffer.lines.get(e);if(!t||t.length===0)return[];let n=[],r=t.translateToString(!0),i=0,a=0,s=0,c=t.getFg(0),l=t.getBg(0);for(let e=0;e<t.getTrimmedLength();e++)if(t.loadCell(e,this._workCell),this._workCell.getWidth()!==0){if(this._workCell.fg!==c||this._workCell.bg!==l){if(e-i>1){let e=this._getJoinedRanges(r,s,a,t,i);for(let t=0;t<e.length;t++)n.push(e[t])}i=e,s=a,c=this._workCell.fg,l=this._workCell.bg}a+=this._workCell.getChars().length||o.WHITESPACE_CELL_CHAR.length}if(this._bufferService.cols-i>1){let e=this._getJoinedRanges(r,s,a,t,i);for(let t=0;t<e.length;t++)n.push(e[t])}return n}_getJoinedRanges(t,n,r,i,a){let o=t.substring(n,r),s=[];try{s=this._characterJoiners[0].handler(o)}catch(e){console.error(e)}for(let t=1;t<this._characterJoiners.length;t++)try{let n=this._characterJoiners[t].handler(o);for(let t=0;t<n.length;t++)e._mergeRanges(s,n[t])}catch(e){console.error(e)}return this._stringRangesToCellRanges(s,i,a),s}_stringRangesToCellRanges(e,t,n){let r=0,i=!1,a=0,s=e[r];if(s){for(let c=n;c<this._bufferService.cols;c++){let n=t.getWidth(c),l=t.getString(c).length||o.WHITESPACE_CELL_CHAR.length;if(n!==0){if(!i&&s[0]<=a&&(s[0]=c,i=!0),s[1]<=a){if(s[1]=c,s=e[++r],!s)break;s[0]<=a?(s[0]=c,i=!0):i=!1}a+=l}}s&&(s[1]=this._bufferService.cols)}}static _mergeRanges(e,t){let n=!1;for(let r=0;r<e.length;r++){let i=e[r];if(n){if(t[1]<=i[0])return e[r-1][1]=t[1],e;if(t[1]<=i[1])return e[r-1][1]=Math.max(t[1],i[1]),e.splice(r,1),e;e.splice(r,1),r--}else{if(t[1]<=i[0])return e.splice(r,0,t),e;if(t[1]<=i[1])return i[0]=Math.min(t[0],i[0]),e;t[0]<i[1]&&(i[0]=Math.min(t[0],i[0]),n=!0)}}return n?e[e.length-1][1]=t[1]:e.push(t),e}};t.CharacterJoinerService=u=r([i(0,c.IBufferService)],u)},5114:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.CoreBrowserService=void 0;let r=n(844),i=n(8460),a=n(3656);class o extends r.Disposable{constructor(e,t,n){super(),this._textarea=e,this._window=t,this.mainDocument=n,this._isFocused=!1,this._cachedIsFocused=void 0,this._screenDprMonitor=new s(this._window),this._onDprChange=this.register(new i.EventEmitter),this.onDprChange=this._onDprChange.event,this._onWindowChange=this.register(new i.EventEmitter),this.onWindowChange=this._onWindowChange.event,this.register(this.onWindowChange((e=>this._screenDprMonitor.setWindow(e)))),this.register((0,i.forwardEvent)(this._screenDprMonitor.onDprChange,this._onDprChange)),this._textarea.addEventListener(`focus`,(()=>this._isFocused=!0)),this._textarea.addEventListener(`blur`,(()=>this._isFocused=!1))}get window(){return this._window}set window(e){this._window!==e&&(this._window=e,this._onWindowChange.fire(this._window))}get dpr(){return this.window.devicePixelRatio}get isFocused(){return this._cachedIsFocused===void 0&&(this._cachedIsFocused=this._isFocused&&this._textarea.ownerDocument.hasFocus(),queueMicrotask((()=>this._cachedIsFocused=void 0))),this._cachedIsFocused}}t.CoreBrowserService=o;class s extends r.Disposable{constructor(e){super(),this._parentWindow=e,this._windowResizeListener=this.register(new r.MutableDisposable),this._onDprChange=this.register(new i.EventEmitter),this.onDprChange=this._onDprChange.event,this._outerListener=()=>this._setDprAndFireIfDiffers(),this._currentDevicePixelRatio=this._parentWindow.devicePixelRatio,this._updateDpr(),this._setWindowResizeListener(),this.register((0,r.toDisposable)((()=>this.clearListener())))}setWindow(e){this._parentWindow=e,this._setWindowResizeListener(),this._setDprAndFireIfDiffers()}_setWindowResizeListener(){this._windowResizeListener.value=(0,a.addDisposableDomListener)(this._parentWindow,`resize`,(()=>this._setDprAndFireIfDiffers()))}_setDprAndFireIfDiffers(){this._parentWindow.devicePixelRatio!==this._currentDevicePixelRatio&&this._onDprChange.fire(this._parentWindow.devicePixelRatio),this._updateDpr()}_updateDpr(){this._outerListener&&(this._resolutionMediaMatchList?.removeListener(this._outerListener),this._currentDevicePixelRatio=this._parentWindow.devicePixelRatio,this._resolutionMediaMatchList=this._parentWindow.matchMedia(`screen and (resolution: ${this._parentWindow.devicePixelRatio}dppx)`),this._resolutionMediaMatchList.addListener(this._outerListener))}clearListener(){this._resolutionMediaMatchList&&this._outerListener&&(this._resolutionMediaMatchList.removeListener(this._outerListener),this._resolutionMediaMatchList=void 0,this._outerListener=void 0)}}},779:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.LinkProviderService=void 0;let r=n(844);class i extends r.Disposable{constructor(){super(),this.linkProviders=[],this.register((0,r.toDisposable)((()=>this.linkProviders.length=0)))}registerLinkProvider(e){return this.linkProviders.push(e),{dispose:()=>{let t=this.linkProviders.indexOf(e);t!==-1&&this.linkProviders.splice(t,1)}}}}t.LinkProviderService=i},8934:function(e,t,n){var r=this&&this.__decorate||function(e,t,n,r){var i,a=arguments.length,o=a<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)o=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o},i=this&&this.__param||function(e,t){return function(n,r){t(n,r,e)}};Object.defineProperty(t,"__esModule",{value:!0}),t.MouseService=void 0;let a=n(4725),o=n(9806),s=t.MouseService=class{constructor(e,t){this._renderService=e,this._charSizeService=t}getCoords(e,t,n,r,i){return(0,o.getCoords)(window,e,t,n,r,this._charSizeService.hasValidSize,this._renderService.dimensions.css.cell.width,this._renderService.dimensions.css.cell.height,i)}getMouseReportCoords(e,t){let n=(0,o.getCoordsRelativeToElement)(window,e,t);if(this._charSizeService.hasValidSize)return n[0]=Math.min(Math.max(n[0],0),this._renderService.dimensions.css.canvas.width-1),n[1]=Math.min(Math.max(n[1],0),this._renderService.dimensions.css.canvas.height-1),{col:Math.floor(n[0]/this._renderService.dimensions.css.cell.width),row:Math.floor(n[1]/this._renderService.dimensions.css.cell.height),x:Math.floor(n[0]),y:Math.floor(n[1])}}};t.MouseService=s=r([i(0,a.IRenderService),i(1,a.ICharSizeService)],s)},3230:function(e,t,n){var r=this&&this.__decorate||function(e,t,n,r){var i,a=arguments.length,o=a<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)o=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o},i=this&&this.__param||function(e,t){return function(n,r){t(n,r,e)}};Object.defineProperty(t,"__esModule",{value:!0}),t.RenderService=void 0;let a=n(6193),o=n(4725),s=n(8460),c=n(844),l=n(7226),u=n(2585),d=t.RenderService=class extends c.Disposable{get dimensions(){return this._renderer.value.dimensions}constructor(e,t,n,r,i,o,u,d){super(),this._rowCount=e,this._charSizeService=r,this._renderer=this.register(new c.MutableDisposable),this._pausedResizeTask=new l.DebouncedIdleTask,this._observerDisposable=this.register(new c.MutableDisposable),this._isPaused=!1,this._needsFullRefresh=!1,this._isNextRenderRedrawOnly=!0,this._needsSelectionRefresh=!1,this._canvasWidth=0,this._canvasHeight=0,this._selectionState={start:void 0,end:void 0,columnSelectMode:!1},this._onDimensionsChange=this.register(new s.EventEmitter),this.onDimensionsChange=this._onDimensionsChange.event,this._onRenderedViewportChange=this.register(new s.EventEmitter),this.onRenderedViewportChange=this._onRenderedViewportChange.event,this._onRender=this.register(new s.EventEmitter),this.onRender=this._onRender.event,this._onRefreshRequest=this.register(new s.EventEmitter),this.onRefreshRequest=this._onRefreshRequest.event,this._renderDebouncer=new a.RenderDebouncer(((e,t)=>this._renderRows(e,t)),u),this.register(this._renderDebouncer),this.register(u.onDprChange((()=>this.handleDevicePixelRatioChange()))),this.register(o.onResize((()=>this._fullRefresh()))),this.register(o.buffers.onBufferActivate((()=>this._renderer.value?.clear()))),this.register(n.onOptionChange((()=>this._handleOptionsChanged()))),this.register(this._charSizeService.onCharSizeChange((()=>this.handleCharSizeChanged()))),this.register(i.onDecorationRegistered((()=>this._fullRefresh()))),this.register(i.onDecorationRemoved((()=>this._fullRefresh()))),this.register(n.onMultipleOptionChange([`customGlyphs`,`drawBoldTextInBrightColors`,`letterSpacing`,`lineHeight`,`fontFamily`,`fontSize`,`fontWeight`,`fontWeightBold`,`minimumContrastRatio`,`rescaleOverlappingGlyphs`],(()=>{this.clear(),this.handleResize(o.cols,o.rows),this._fullRefresh()}))),this.register(n.onMultipleOptionChange([`cursorBlink`,`cursorStyle`],(()=>this.refreshRows(o.buffer.y,o.buffer.y,!0)))),this.register(d.onChangeColors((()=>this._fullRefresh()))),this._registerIntersectionObserver(u.window,t),this.register(u.onWindowChange((e=>this._registerIntersectionObserver(e,t))))}_registerIntersectionObserver(e,t){if(`IntersectionObserver`in e){let n=new e.IntersectionObserver((e=>this._handleIntersectionChange(e[e.length-1])),{threshold:0});n.observe(t),this._observerDisposable.value=(0,c.toDisposable)((()=>n.disconnect()))}}_handleIntersectionChange(e){this._isPaused=e.isIntersecting===void 0?e.intersectionRatio===0:!e.isIntersecting,this._isPaused||this._charSizeService.hasValidSize||this._charSizeService.measure(),!this._isPaused&&this._needsFullRefresh&&(this._pausedResizeTask.flush(),this.refreshRows(0,this._rowCount-1),this._needsFullRefresh=!1)}refreshRows(e,t,n=!1){this._isPaused?this._needsFullRefresh=!0:(n||(this._isNextRenderRedrawOnly=!1),this._renderDebouncer.refresh(e,t,this._rowCount))}_renderRows(e,t){this._renderer.value&&(e=Math.min(e,this._rowCount-1),t=Math.min(t,this._rowCount-1),this._renderer.value.renderRows(e,t),this._needsSelectionRefresh&&=(this._renderer.value.handleSelectionChanged(this._selectionState.start,this._selectionState.end,this._selectionState.columnSelectMode),!1),this._isNextRenderRedrawOnly||this._onRenderedViewportChange.fire({start:e,end:t}),this._onRender.fire({start:e,end:t}),this._isNextRenderRedrawOnly=!0)}resize(e,t){this._rowCount=t,this._fireOnCanvasResize()}_handleOptionsChanged(){this._renderer.value&&(this.refreshRows(0,this._rowCount-1),this._fireOnCanvasResize())}_fireOnCanvasResize(){this._renderer.value&&(this._renderer.value.dimensions.css.canvas.width===this._canvasWidth&&this._renderer.value.dimensions.css.canvas.height===this._canvasHeight||this._onDimensionsChange.fire(this._renderer.value.dimensions))}hasRenderer(){return!!this._renderer.value}setRenderer(e){this._renderer.value=e,this._renderer.value&&(this._renderer.value.onRequestRedraw((e=>this.refreshRows(e.start,e.end,!0))),this._needsSelectionRefresh=!0,this._fullRefresh())}addRefreshCallback(e){return this._renderDebouncer.addRefreshCallback(e)}_fullRefresh(){this._isPaused?this._needsFullRefresh=!0:this.refreshRows(0,this._rowCount-1)}clearTextureAtlas(){this._renderer.value&&(this._renderer.value.clearTextureAtlas?.(),this._fullRefresh())}handleDevicePixelRatioChange(){this._charSizeService.measure(),this._renderer.value&&(this._renderer.value.handleDevicePixelRatioChange(),this.refreshRows(0,this._rowCount-1))}handleResize(e,t){this._renderer.value&&(this._isPaused?this._pausedResizeTask.set((()=>this._renderer.value?.handleResize(e,t))):this._renderer.value.handleResize(e,t),this._fullRefresh())}handleCharSizeChanged(){this._renderer.value?.handleCharSizeChanged()}handleBlur(){this._renderer.value?.handleBlur()}handleFocus(){this._renderer.value?.handleFocus()}handleSelectionChanged(e,t,n){this._selectionState.start=e,this._selectionState.end=t,this._selectionState.columnSelectMode=n,this._renderer.value?.handleSelectionChanged(e,t,n)}handleCursorMove(){this._renderer.value?.handleCursorMove()}clear(){this._renderer.value?.clear()}};t.RenderService=d=r([i(2,u.IOptionsService),i(3,o.ICharSizeService),i(4,u.IDecorationService),i(5,u.IBufferService),i(6,o.ICoreBrowserService),i(7,o.IThemeService)],d)},9312:function(e,t,n){var r=this&&this.__decorate||function(e,t,n,r){var i,a=arguments.length,o=a<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)o=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o},i=this&&this.__param||function(e,t){return function(n,r){t(n,r,e)}};Object.defineProperty(t,"__esModule",{value:!0}),t.SelectionService=void 0;let a=n(9806),o=n(9504),s=n(456),c=n(4725),l=n(8460),u=n(844),d=n(6114),f=n(4841),p=n(511),m=n(2585),h=RegExp(`\xA0`,`g`),g=t.SelectionService=class extends u.Disposable{constructor(e,t,n,r,i,a,o,c,d){super(),this._element=e,this._screenElement=t,this._linkifier=n,this._bufferService=r,this._coreService=i,this._mouseService=a,this._optionsService=o,this._renderService=c,this._coreBrowserService=d,this._dragScrollAmount=0,this._enabled=!0,this._workCell=new p.CellData,this._mouseDownTimeStamp=0,this._oldHasSelection=!1,this._oldSelectionStart=void 0,this._oldSelectionEnd=void 0,this._onLinuxMouseSelection=this.register(new l.EventEmitter),this.onLinuxMouseSelection=this._onLinuxMouseSelection.event,this._onRedrawRequest=this.register(new l.EventEmitter),this.onRequestRedraw=this._onRedrawRequest.event,this._onSelectionChange=this.register(new l.EventEmitter),this.onSelectionChange=this._onSelectionChange.event,this._onRequestScrollLines=this.register(new l.EventEmitter),this.onRequestScrollLines=this._onRequestScrollLines.event,this._mouseMoveListener=e=>this._handleMouseMove(e),this._mouseUpListener=e=>this._handleMouseUp(e),this._coreService.onUserInput((()=>{this.hasSelection&&this.clearSelection()})),this._trimListener=this._bufferService.buffer.lines.onTrim((e=>this._handleTrim(e))),this.register(this._bufferService.buffers.onBufferActivate((e=>this._handleBufferActivate(e)))),this.enable(),this._model=new s.SelectionModel(this._bufferService),this._activeSelectionMode=0,this.register((0,u.toDisposable)((()=>{this._removeMouseDownListeners()})))}reset(){this.clearSelection()}disable(){this.clearSelection(),this._enabled=!1}enable(){this._enabled=!0}get selectionStart(){return this._model.finalSelectionStart}get selectionEnd(){return this._model.finalSelectionEnd}get hasSelection(){let e=this._model.finalSelectionStart,t=this._model.finalSelectionEnd;return!(!e||!t||e[0]===t[0]&&e[1]===t[1])}get selectionText(){let e=this._model.finalSelectionStart,t=this._model.finalSelectionEnd;if(!e||!t)return``;let n=this._bufferService.buffer,r=[];if(this._activeSelectionMode===3){if(e[0]===t[0])return``;let i=e[0]<t[0]?e[0]:t[0],a=e[0]<t[0]?t[0]:e[0];for(let o=e[1];o<=t[1];o++){let e=n.translateBufferLineToString(o,!0,i,a);r.push(e)}}else{let i=e[1]===t[1]?t[0]:void 0;r.push(n.translateBufferLineToString(e[1],!0,e[0],i));for(let i=e[1]+1;i<=t[1]-1;i++){let e=n.lines.get(i),t=n.translateBufferLineToString(i,!0);e?.isWrapped?r[r.length-1]+=t:r.push(t)}if(e[1]!==t[1]){let e=n.lines.get(t[1]),i=n.translateBufferLineToString(t[1],!0,0,t[0]);e&&e.isWrapped?r[r.length-1]+=i:r.push(i)}}return r.map((e=>e.replace(h,` `))).join(d.isWindows?`\r
|
|
368
368
|
`:`
|
|
369
369
|
`)}clearSelection(){this._model.clearSelection(),this._removeMouseDownListeners(),this.refresh(),this._onSelectionChange.fire()}refresh(e){this._refreshAnimationFrame||=this._coreBrowserService.window.requestAnimationFrame((()=>this._refresh())),d.isLinux&&e&&this.selectionText.length&&this._onLinuxMouseSelection.fire(this.selectionText)}_refresh(){this._refreshAnimationFrame=void 0,this._onRedrawRequest.fire({start:this._model.finalSelectionStart,end:this._model.finalSelectionEnd,columnSelectMode:this._activeSelectionMode===3})}_isClickInSelection(e){let t=this._getMouseBufferCoords(e),n=this._model.finalSelectionStart,r=this._model.finalSelectionEnd;return!!(n&&r&&t)&&this._areCoordsInSelection(t,n,r)}isCellInSelection(e,t){let n=this._model.finalSelectionStart,r=this._model.finalSelectionEnd;return!(!n||!r)&&this._areCoordsInSelection([e,t],n,r)}_areCoordsInSelection(e,t,n){return e[1]>t[1]&&e[1]<n[1]||t[1]===n[1]&&e[1]===t[1]&&e[0]>=t[0]&&e[0]<n[0]||t[1]<n[1]&&e[1]===n[1]&&e[0]<n[0]||t[1]<n[1]&&e[1]===t[1]&&e[0]>=t[0]}_selectWordAtCursor(e,t){let n=this._linkifier.currentLink?.link?.range;if(n)return this._model.selectionStart=[n.start.x-1,n.start.y-1],this._model.selectionStartLength=(0,f.getRangeLength)(n,this._bufferService.cols),this._model.selectionEnd=void 0,!0;let r=this._getMouseBufferCoords(e);return!!r&&(this._selectWordAt(r,t),this._model.selectionEnd=void 0,!0)}selectAll(){this._model.isSelectAllActive=!0,this.refresh(),this._onSelectionChange.fire()}selectLines(e,t){this._model.clearSelection(),e=Math.max(e,0),t=Math.min(t,this._bufferService.buffer.lines.length-1),this._model.selectionStart=[0,e],this._model.selectionEnd=[this._bufferService.cols,t],this.refresh(),this._onSelectionChange.fire()}_handleTrim(e){this._model.handleTrim(e)&&this.refresh()}_getMouseBufferCoords(e){let t=this._mouseService.getCoords(e,this._screenElement,this._bufferService.cols,this._bufferService.rows,!0);if(t)return t[0]--,t[1]--,t[1]+=this._bufferService.buffer.ydisp,t}_getMouseEventScrollAmount(e){let t=(0,a.getCoordsRelativeToElement)(this._coreBrowserService.window,e,this._screenElement)[1],n=this._renderService.dimensions.css.canvas.height;return t>=0&&t<=n?0:(t>n&&(t-=n),t=Math.min(Math.max(t,-50),50),t/=50,t/Math.abs(t)+Math.round(14*t))}shouldForceSelection(e){return d.isMac?e.altKey&&this._optionsService.rawOptions.macOptionClickForcesSelection:e.shiftKey}handleMouseDown(e){if(this._mouseDownTimeStamp=e.timeStamp,(e.button!==2||!this.hasSelection)&&e.button===0){if(!this._enabled){if(!this.shouldForceSelection(e))return;e.stopPropagation()}e.preventDefault(),this._dragScrollAmount=0,this._enabled&&e.shiftKey?this._handleIncrementalClick(e):e.detail===1?this._handleSingleClick(e):e.detail===2?this._handleDoubleClick(e):e.detail===3&&this._handleTripleClick(e),this._addMouseDownListeners(),this.refresh(!0)}}_addMouseDownListeners(){this._screenElement.ownerDocument&&(this._screenElement.ownerDocument.addEventListener(`mousemove`,this._mouseMoveListener),this._screenElement.ownerDocument.addEventListener(`mouseup`,this._mouseUpListener)),this._dragScrollIntervalTimer=this._coreBrowserService.window.setInterval((()=>this._dragScroll()),50)}_removeMouseDownListeners(){this._screenElement.ownerDocument&&(this._screenElement.ownerDocument.removeEventListener(`mousemove`,this._mouseMoveListener),this._screenElement.ownerDocument.removeEventListener(`mouseup`,this._mouseUpListener)),this._coreBrowserService.window.clearInterval(this._dragScrollIntervalTimer),this._dragScrollIntervalTimer=void 0}_handleIncrementalClick(e){this._model.selectionStart&&(this._model.selectionEnd=this._getMouseBufferCoords(e))}_handleSingleClick(e){if(this._model.selectionStartLength=0,this._model.isSelectAllActive=!1,this._activeSelectionMode=this.shouldColumnSelect(e)?3:0,this._model.selectionStart=this._getMouseBufferCoords(e),!this._model.selectionStart)return;this._model.selectionEnd=void 0;let t=this._bufferService.buffer.lines.get(this._model.selectionStart[1]);t&&t.length!==this._model.selectionStart[0]&&t.hasWidth(this._model.selectionStart[0])===0&&this._model.selectionStart[0]++}_handleDoubleClick(e){this._selectWordAtCursor(e,!0)&&(this._activeSelectionMode=1)}_handleTripleClick(e){let t=this._getMouseBufferCoords(e);t&&(this._activeSelectionMode=2,this._selectLineAt(t[1]))}shouldColumnSelect(e){return e.altKey&&!(d.isMac&&this._optionsService.rawOptions.macOptionClickForcesSelection)}_handleMouseMove(e){if(e.stopImmediatePropagation(),!this._model.selectionStart)return;let t=this._model.selectionEnd?[this._model.selectionEnd[0],this._model.selectionEnd[1]]:null;if(this._model.selectionEnd=this._getMouseBufferCoords(e),!this._model.selectionEnd)return void this.refresh(!0);this._activeSelectionMode===2?this._model.selectionEnd[1]<this._model.selectionStart[1]?this._model.selectionEnd[0]=0:this._model.selectionEnd[0]=this._bufferService.cols:this._activeSelectionMode===1&&this._selectToWordAt(this._model.selectionEnd),this._dragScrollAmount=this._getMouseEventScrollAmount(e),this._activeSelectionMode!==3&&(this._dragScrollAmount>0?this._model.selectionEnd[0]=this._bufferService.cols:this._dragScrollAmount<0&&(this._model.selectionEnd[0]=0));let n=this._bufferService.buffer;if(this._model.selectionEnd[1]<n.lines.length){let e=n.lines.get(this._model.selectionEnd[1]);e&&e.hasWidth(this._model.selectionEnd[0])===0&&this._model.selectionEnd[0]<this._bufferService.cols&&this._model.selectionEnd[0]++}t&&t[0]===this._model.selectionEnd[0]&&t[1]===this._model.selectionEnd[1]||this.refresh(!0)}_dragScroll(){if(this._model.selectionEnd&&this._model.selectionStart&&this._dragScrollAmount){this._onRequestScrollLines.fire({amount:this._dragScrollAmount,suppressScrollEvent:!1});let e=this._bufferService.buffer;this._dragScrollAmount>0?(this._activeSelectionMode!==3&&(this._model.selectionEnd[0]=this._bufferService.cols),this._model.selectionEnd[1]=Math.min(e.ydisp+this._bufferService.rows,e.lines.length-1)):(this._activeSelectionMode!==3&&(this._model.selectionEnd[0]=0),this._model.selectionEnd[1]=e.ydisp),this.refresh()}}_handleMouseUp(e){let t=e.timeStamp-this._mouseDownTimeStamp;if(this._removeMouseDownListeners(),this.selectionText.length<=1&&t<500&&e.altKey&&this._optionsService.rawOptions.altClickMovesCursor){if(this._bufferService.buffer.ybase===this._bufferService.buffer.ydisp){let t=this._mouseService.getCoords(e,this._element,this._bufferService.cols,this._bufferService.rows,!1);if(t&&t[0]!==void 0&&t[1]!==void 0){let e=(0,o.moveToCellSequence)(t[0]-1,t[1]-1,this._bufferService,this._coreService.decPrivateModes.applicationCursorKeys);this._coreService.triggerDataEvent(e,!0)}}}else this._fireEventIfSelectionChanged()}_fireEventIfSelectionChanged(){let e=this._model.finalSelectionStart,t=this._model.finalSelectionEnd,n=!(!e||!t||e[0]===t[0]&&e[1]===t[1]);n?e&&t&&(this._oldSelectionStart&&this._oldSelectionEnd&&e[0]===this._oldSelectionStart[0]&&e[1]===this._oldSelectionStart[1]&&t[0]===this._oldSelectionEnd[0]&&t[1]===this._oldSelectionEnd[1]||this._fireOnSelectionChange(e,t,n)):this._oldHasSelection&&this._fireOnSelectionChange(e,t,n)}_fireOnSelectionChange(e,t,n){this._oldSelectionStart=e,this._oldSelectionEnd=t,this._oldHasSelection=n,this._onSelectionChange.fire()}_handleBufferActivate(e){this.clearSelection(),this._trimListener.dispose(),this._trimListener=e.activeBuffer.lines.onTrim((e=>this._handleTrim(e)))}_convertViewportColToCharacterIndex(e,t){let n=t;for(let r=0;t>=r;r++){let i=e.loadCell(r,this._workCell).getChars().length;this._workCell.getWidth()===0?n--:i>1&&t!==r&&(n+=i-1)}return n}setSelection(e,t,n){this._model.clearSelection(),this._removeMouseDownListeners(),this._model.selectionStart=[e,t],this._model.selectionStartLength=n,this.refresh(),this._fireEventIfSelectionChanged()}rightClickSelect(e){this._isClickInSelection(e)||(this._selectWordAtCursor(e,!1)&&this.refresh(!0),this._fireEventIfSelectionChanged())}_getWordAt(e,t,n=!0,r=!0){if(e[0]>=this._bufferService.cols)return;let i=this._bufferService.buffer,a=i.lines.get(e[1]);if(!a)return;let o=i.translateBufferLineToString(e[1],!1),s=this._convertViewportColToCharacterIndex(a,e[0]),c=s,l=e[0]-s,u=0,d=0,f=0,p=0;if(o.charAt(s)===` `){for(;s>0&&o.charAt(s-1)===` `;)s--;for(;c<o.length&&o.charAt(c+1)===` `;)c++}else{let t=e[0],n=e[0];a.getWidth(t)===0&&(u++,t--),a.getWidth(n)===2&&(d++,n++);let r=a.getString(n).length;for(r>1&&(p+=r-1,c+=r-1);t>0&&s>0&&!this._isCharWordSeparator(a.loadCell(t-1,this._workCell));){a.loadCell(t-1,this._workCell);let e=this._workCell.getChars().length;this._workCell.getWidth()===0?(u++,t--):e>1&&(f+=e-1,s-=e-1),s--,t--}for(;n<a.length&&c+1<o.length&&!this._isCharWordSeparator(a.loadCell(n+1,this._workCell));){a.loadCell(n+1,this._workCell);let e=this._workCell.getChars().length;this._workCell.getWidth()===2?(d++,n++):e>1&&(p+=e-1,c+=e-1),c++,n++}}c++;let m=s+l-u+f,h=Math.min(this._bufferService.cols,c-s+u+d-f-p);if(t||o.slice(s,c).trim()!==``){if(n&&m===0&&a.getCodePoint(0)!==32){let t=i.lines.get(e[1]-1);if(t&&a.isWrapped&&t.getCodePoint(this._bufferService.cols-1)!==32){let t=this._getWordAt([this._bufferService.cols-1,e[1]-1],!1,!0,!1);if(t){let e=this._bufferService.cols-t.start;m-=e,h+=e}}}if(r&&m+h===this._bufferService.cols&&a.getCodePoint(this._bufferService.cols-1)!==32){let t=i.lines.get(e[1]+1);if(t?.isWrapped&&t.getCodePoint(0)!==32){let t=this._getWordAt([0,e[1]+1],!1,!1,!0);t&&(h+=t.length)}}return{start:m,length:h}}}_selectWordAt(e,t){let n=this._getWordAt(e,t);if(n){for(;n.start<0;)n.start+=this._bufferService.cols,e[1]--;this._model.selectionStart=[n.start,e[1]],this._model.selectionStartLength=n.length}}_selectToWordAt(e){let t=this._getWordAt(e,!0);if(t){let n=e[1];for(;t.start<0;)t.start+=this._bufferService.cols,n--;if(!this._model.areSelectionValuesReversed())for(;t.start+t.length>this._bufferService.cols;)t.length-=this._bufferService.cols,n++;this._model.selectionEnd=[this._model.areSelectionValuesReversed()?t.start:t.start+t.length,n]}}_isCharWordSeparator(e){return e.getWidth()!==0&&this._optionsService.rawOptions.wordSeparator.indexOf(e.getChars())>=0}_selectLineAt(e){let t=this._bufferService.buffer.getWrappedRangeForLine(e),n={start:{x:0,y:t.first},end:{x:this._bufferService.cols-1,y:t.last}};this._model.selectionStart=[0,t.first],this._model.selectionEnd=void 0,this._model.selectionStartLength=(0,f.getRangeLength)(n,this._bufferService.cols)}};t.SelectionService=g=r([i(3,m.IBufferService),i(4,m.ICoreService),i(5,c.IMouseService),i(6,m.IOptionsService),i(7,c.IRenderService),i(8,c.ICoreBrowserService)],g)},4725:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ILinkProviderService=t.IThemeService=t.ICharacterJoinerService=t.ISelectionService=t.IRenderService=t.IMouseService=t.ICoreBrowserService=t.ICharSizeService=void 0;let r=n(8343);t.ICharSizeService=(0,r.createDecorator)(`CharSizeService`),t.ICoreBrowserService=(0,r.createDecorator)(`CoreBrowserService`),t.IMouseService=(0,r.createDecorator)(`MouseService`),t.IRenderService=(0,r.createDecorator)(`RenderService`),t.ISelectionService=(0,r.createDecorator)(`SelectionService`),t.ICharacterJoinerService=(0,r.createDecorator)(`CharacterJoinerService`),t.IThemeService=(0,r.createDecorator)(`ThemeService`),t.ILinkProviderService=(0,r.createDecorator)(`LinkProviderService`)},6731:function(e,t,n){var r=this&&this.__decorate||function(e,t,n,r){var i,a=arguments.length,o=a<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)o=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o},i=this&&this.__param||function(e,t){return function(n,r){t(n,r,e)}};Object.defineProperty(t,"__esModule",{value:!0}),t.ThemeService=t.DEFAULT_ANSI_COLORS=void 0;let a=n(7239),o=n(8055),s=n(8460),c=n(844),l=n(2585),u=o.css.toColor(`#ffffff`),d=o.css.toColor(`#000000`),f=o.css.toColor(`#ffffff`),p=o.css.toColor(`#000000`),m={css:`rgba(255, 255, 255, 0.3)`,rgba:4294967117};t.DEFAULT_ANSI_COLORS=Object.freeze((()=>{let e=[o.css.toColor(`#2e3436`),o.css.toColor(`#cc0000`),o.css.toColor(`#4e9a06`),o.css.toColor(`#c4a000`),o.css.toColor(`#3465a4`),o.css.toColor(`#75507b`),o.css.toColor(`#06989a`),o.css.toColor(`#d3d7cf`),o.css.toColor(`#555753`),o.css.toColor(`#ef2929`),o.css.toColor(`#8ae234`),o.css.toColor(`#fce94f`),o.css.toColor(`#729fcf`),o.css.toColor(`#ad7fa8`),o.css.toColor(`#34e2e2`),o.css.toColor(`#eeeeec`)],t=[0,95,135,175,215,255];for(let n=0;n<216;n++){let r=t[n/36%6|0],i=t[n/6%6|0],a=t[n%6];e.push({css:o.channels.toCss(r,i,a),rgba:o.channels.toRgba(r,i,a)})}for(let t=0;t<24;t++){let n=8+10*t;e.push({css:o.channels.toCss(n,n,n),rgba:o.channels.toRgba(n,n,n)})}return e})());let h=t.ThemeService=class extends c.Disposable{get colors(){return this._colors}constructor(e){super(),this._optionsService=e,this._contrastCache=new a.ColorContrastCache,this._halfContrastCache=new a.ColorContrastCache,this._onChangeColors=this.register(new s.EventEmitter),this.onChangeColors=this._onChangeColors.event,this._colors={foreground:u,background:d,cursor:f,cursorAccent:p,selectionForeground:void 0,selectionBackgroundTransparent:m,selectionBackgroundOpaque:o.color.blend(d,m),selectionInactiveBackgroundTransparent:m,selectionInactiveBackgroundOpaque:o.color.blend(d,m),ansi:t.DEFAULT_ANSI_COLORS.slice(),contrastCache:this._contrastCache,halfContrastCache:this._halfContrastCache},this._updateRestoreColors(),this._setTheme(this._optionsService.rawOptions.theme),this.register(this._optionsService.onSpecificOptionChange(`minimumContrastRatio`,(()=>this._contrastCache.clear()))),this.register(this._optionsService.onSpecificOptionChange(`theme`,(()=>this._setTheme(this._optionsService.rawOptions.theme))))}_setTheme(e={}){let n=this._colors;if(n.foreground=g(e.foreground,u),n.background=g(e.background,d),n.cursor=g(e.cursor,f),n.cursorAccent=g(e.cursorAccent,p),n.selectionBackgroundTransparent=g(e.selectionBackground,m),n.selectionBackgroundOpaque=o.color.blend(n.background,n.selectionBackgroundTransparent),n.selectionInactiveBackgroundTransparent=g(e.selectionInactiveBackground,n.selectionBackgroundTransparent),n.selectionInactiveBackgroundOpaque=o.color.blend(n.background,n.selectionInactiveBackgroundTransparent),n.selectionForeground=e.selectionForeground?g(e.selectionForeground,o.NULL_COLOR):void 0,n.selectionForeground===o.NULL_COLOR&&(n.selectionForeground=void 0),o.color.isOpaque(n.selectionBackgroundTransparent)&&(n.selectionBackgroundTransparent=o.color.opacity(n.selectionBackgroundTransparent,.3)),o.color.isOpaque(n.selectionInactiveBackgroundTransparent)&&(n.selectionInactiveBackgroundTransparent=o.color.opacity(n.selectionInactiveBackgroundTransparent,.3)),n.ansi=t.DEFAULT_ANSI_COLORS.slice(),n.ansi[0]=g(e.black,t.DEFAULT_ANSI_COLORS[0]),n.ansi[1]=g(e.red,t.DEFAULT_ANSI_COLORS[1]),n.ansi[2]=g(e.green,t.DEFAULT_ANSI_COLORS[2]),n.ansi[3]=g(e.yellow,t.DEFAULT_ANSI_COLORS[3]),n.ansi[4]=g(e.blue,t.DEFAULT_ANSI_COLORS[4]),n.ansi[5]=g(e.magenta,t.DEFAULT_ANSI_COLORS[5]),n.ansi[6]=g(e.cyan,t.DEFAULT_ANSI_COLORS[6]),n.ansi[7]=g(e.white,t.DEFAULT_ANSI_COLORS[7]),n.ansi[8]=g(e.brightBlack,t.DEFAULT_ANSI_COLORS[8]),n.ansi[9]=g(e.brightRed,t.DEFAULT_ANSI_COLORS[9]),n.ansi[10]=g(e.brightGreen,t.DEFAULT_ANSI_COLORS[10]),n.ansi[11]=g(e.brightYellow,t.DEFAULT_ANSI_COLORS[11]),n.ansi[12]=g(e.brightBlue,t.DEFAULT_ANSI_COLORS[12]),n.ansi[13]=g(e.brightMagenta,t.DEFAULT_ANSI_COLORS[13]),n.ansi[14]=g(e.brightCyan,t.DEFAULT_ANSI_COLORS[14]),n.ansi[15]=g(e.brightWhite,t.DEFAULT_ANSI_COLORS[15]),e.extendedAnsi){let r=Math.min(n.ansi.length-16,e.extendedAnsi.length);for(let i=0;i<r;i++)n.ansi[i+16]=g(e.extendedAnsi[i],t.DEFAULT_ANSI_COLORS[i+16])}this._contrastCache.clear(),this._halfContrastCache.clear(),this._updateRestoreColors(),this._onChangeColors.fire(this.colors)}restoreColor(e){this._restoreColor(e),this._onChangeColors.fire(this.colors)}_restoreColor(e){if(e!==void 0)switch(e){case 256:this._colors.foreground=this._restoreColors.foreground;break;case 257:this._colors.background=this._restoreColors.background;break;case 258:this._colors.cursor=this._restoreColors.cursor;break;default:this._colors.ansi[e]=this._restoreColors.ansi[e]}else for(let e=0;e<this._restoreColors.ansi.length;++e)this._colors.ansi[e]=this._restoreColors.ansi[e]}modifyColors(e){e(this._colors),this._onChangeColors.fire(this.colors)}_updateRestoreColors(){this._restoreColors={foreground:this._colors.foreground,background:this._colors.background,cursor:this._colors.cursor,ansi:this._colors.ansi.slice()}}};function g(e,t){if(e!==void 0)try{return o.css.toColor(e)}catch{}return t}t.ThemeService=h=r([i(0,l.IOptionsService)],h)},6349:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.CircularList=void 0;let r=n(8460),i=n(844);class a extends i.Disposable{constructor(e){super(),this._maxLength=e,this.onDeleteEmitter=this.register(new r.EventEmitter),this.onDelete=this.onDeleteEmitter.event,this.onInsertEmitter=this.register(new r.EventEmitter),this.onInsert=this.onInsertEmitter.event,this.onTrimEmitter=this.register(new r.EventEmitter),this.onTrim=this.onTrimEmitter.event,this._array=Array(this._maxLength),this._startIndex=0,this._length=0}get maxLength(){return this._maxLength}set maxLength(e){if(this._maxLength===e)return;let t=Array(e);for(let n=0;n<Math.min(e,this.length);n++)t[n]=this._array[this._getCyclicIndex(n)];this._array=t,this._maxLength=e,this._startIndex=0}get length(){return this._length}set length(e){if(e>this._length)for(let t=this._length;t<e;t++)this._array[t]=void 0;this._length=e}get(e){return this._array[this._getCyclicIndex(e)]}set(e,t){this._array[this._getCyclicIndex(e)]=t}push(e){this._array[this._getCyclicIndex(this._length)]=e,this._length===this._maxLength?(this._startIndex=++this._startIndex%this._maxLength,this.onTrimEmitter.fire(1)):this._length++}recycle(){if(this._length!==this._maxLength)throw Error(`Can only recycle when the buffer is full`);return this._startIndex=++this._startIndex%this._maxLength,this.onTrimEmitter.fire(1),this._array[this._getCyclicIndex(this._length-1)]}get isFull(){return this._length===this._maxLength}pop(){return this._array[this._getCyclicIndex(this._length---1)]}splice(e,t,...n){if(t){for(let n=e;n<this._length-t;n++)this._array[this._getCyclicIndex(n)]=this._array[this._getCyclicIndex(n+t)];this._length-=t,this.onDeleteEmitter.fire({index:e,amount:t})}for(let t=this._length-1;t>=e;t--)this._array[this._getCyclicIndex(t+n.length)]=this._array[this._getCyclicIndex(t)];for(let t=0;t<n.length;t++)this._array[this._getCyclicIndex(e+t)]=n[t];if(n.length&&this.onInsertEmitter.fire({index:e,amount:n.length}),this._length+n.length>this._maxLength){let e=this._length+n.length-this._maxLength;this._startIndex+=e,this._length=this._maxLength,this.onTrimEmitter.fire(e)}else this._length+=n.length}trimStart(e){e>this._length&&(e=this._length),this._startIndex+=e,this._length-=e,this.onTrimEmitter.fire(e)}shiftElements(e,t,n){if(!(t<=0)){if(e<0||e>=this._length)throw Error(`start argument out of range`);if(e+n<0)throw Error(`Cannot shift elements in list beyond index 0`);if(n>0){for(let r=t-1;r>=0;r--)this.set(e+r+n,this.get(e+r));let r=e+t+n-this._length;if(r>0)for(this._length+=r;this._length>this._maxLength;)this._length--,this._startIndex++,this.onTrimEmitter.fire(1)}else for(let r=0;r<t;r++)this.set(e+r+n,this.get(e+r))}}_getCyclicIndex(e){return(this._startIndex+e)%this._maxLength}}t.CircularList=a},1439:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.clone=void 0,t.clone=function e(t,n=5){if(typeof t!=`object`)return t;let r=Array.isArray(t)?[]:{};for(let i in t)r[i]=n<=1?t[i]:t[i]&&e(t[i],n-1);return r}},8055:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.contrastRatio=t.toPaddedHex=t.rgba=t.rgb=t.css=t.color=t.channels=t.NULL_COLOR=void 0;let n=0,r=0,i=0,a=0;var o,s,c,l,u;function d(e){let t=e.toString(16);return t.length<2?`0`+t:t}function f(e,t){return e<t?(t+.05)/(e+.05):(e+.05)/(t+.05)}t.NULL_COLOR={css:`#00000000`,rgba:0},function(e){e.toCss=function(e,t,n,r){return r===void 0?`#${d(e)}${d(t)}${d(n)}`:`#${d(e)}${d(t)}${d(n)}${d(r)}`},e.toRgba=function(e,t,n,r=255){return(e<<24|t<<16|n<<8|r)>>>0},e.toColor=function(t,n,r,i){return{css:e.toCss(t,n,r,i),rgba:e.toRgba(t,n,r,i)}}}(o||(t.channels=o={})),function(e){function t(e,t){return a=Math.round(255*t),[n,r,i]=u.toChannels(e.rgba),{css:o.toCss(n,r,i,a),rgba:o.toRgba(n,r,i,a)}}e.blend=function(e,t){if(a=(255&t.rgba)/255,a===1)return{css:t.css,rgba:t.rgba};let s=t.rgba>>24&255,c=t.rgba>>16&255,l=t.rgba>>8&255,u=e.rgba>>24&255,d=e.rgba>>16&255,f=e.rgba>>8&255;return n=u+Math.round((s-u)*a),r=d+Math.round((c-d)*a),i=f+Math.round((l-f)*a),{css:o.toCss(n,r,i),rgba:o.toRgba(n,r,i)}},e.isOpaque=function(e){return(255&e.rgba)==255},e.ensureContrastRatio=function(e,t,n){let r=u.ensureContrastRatio(e.rgba,t.rgba,n);if(r)return o.toColor(r>>24&255,r>>16&255,r>>8&255)},e.opaque=function(e){let t=(255|e.rgba)>>>0;return[n,r,i]=u.toChannels(t),{css:o.toCss(n,r,i),rgba:t}},e.opacity=t,e.multiplyOpacity=function(e,n){return a=255&e.rgba,t(e,a*n/255)},e.toColorRGB=function(e){return[e.rgba>>24&255,e.rgba>>16&255,e.rgba>>8&255]}}(s||(t.color=s={})),function(e){let t,s;try{let e=document.createElement(`canvas`);e.width=1,e.height=1;let n=e.getContext(`2d`,{willReadFrequently:!0});n&&(t=n,t.globalCompositeOperation=`copy`,s=t.createLinearGradient(0,0,1,1))}catch{}e.toColor=function(e){if(e.match(/#[\da-f]{3,8}/i))switch(e.length){case 4:return n=parseInt(e.slice(1,2).repeat(2),16),r=parseInt(e.slice(2,3).repeat(2),16),i=parseInt(e.slice(3,4).repeat(2),16),o.toColor(n,r,i);case 5:return n=parseInt(e.slice(1,2).repeat(2),16),r=parseInt(e.slice(2,3).repeat(2),16),i=parseInt(e.slice(3,4).repeat(2),16),a=parseInt(e.slice(4,5).repeat(2),16),o.toColor(n,r,i,a);case 7:return{css:e,rgba:(parseInt(e.slice(1),16)<<8|255)>>>0};case 9:return{css:e,rgba:parseInt(e.slice(1),16)>>>0}}let c=e.match(/rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(,\s*(0|1|\d?\.(\d+))\s*)?\)/);if(c)return n=parseInt(c[1]),r=parseInt(c[2]),i=parseInt(c[3]),a=Math.round(255*(c[5]===void 0?1:parseFloat(c[5]))),o.toColor(n,r,i,a);if(!t||!s||(t.fillStyle=s,t.fillStyle=e,typeof t.fillStyle!=`string`)||(t.fillRect(0,0,1,1),[n,r,i,a]=t.getImageData(0,0,1,1).data,a!==255))throw Error(`css.toColor: Unsupported css format`);return{rgba:o.toRgba(n,r,i,a),css:e}}}(c||(t.css=c={})),function(e){function t(e,t,n){let r=e/255,i=t/255,a=n/255;return .2126*(r<=.03928?r/12.92:((r+.055)/1.055)**2.4)+.7152*(i<=.03928?i/12.92:((i+.055)/1.055)**2.4)+.0722*(a<=.03928?a/12.92:((a+.055)/1.055)**2.4)}e.relativeLuminance=function(e){return t(e>>16&255,e>>8&255,255&e)},e.relativeLuminance2=t}(l||(t.rgb=l={})),function(e){function t(e,t,n){let r=e>>24&255,i=e>>16&255,a=e>>8&255,o=t>>24&255,s=t>>16&255,c=t>>8&255,u=f(l.relativeLuminance2(o,s,c),l.relativeLuminance2(r,i,a));for(;u<n&&(o>0||s>0||c>0);)o-=Math.max(0,Math.ceil(.1*o)),s-=Math.max(0,Math.ceil(.1*s)),c-=Math.max(0,Math.ceil(.1*c)),u=f(l.relativeLuminance2(o,s,c),l.relativeLuminance2(r,i,a));return(o<<24|s<<16|c<<8|255)>>>0}function s(e,t,n){let r=e>>24&255,i=e>>16&255,a=e>>8&255,o=t>>24&255,s=t>>16&255,c=t>>8&255,u=f(l.relativeLuminance2(o,s,c),l.relativeLuminance2(r,i,a));for(;u<n&&(o<255||s<255||c<255);)o=Math.min(255,o+Math.ceil(.1*(255-o))),s=Math.min(255,s+Math.ceil(.1*(255-s))),c=Math.min(255,c+Math.ceil(.1*(255-c))),u=f(l.relativeLuminance2(o,s,c),l.relativeLuminance2(r,i,a));return(o<<24|s<<16|c<<8|255)>>>0}e.blend=function(e,t){if(a=(255&t)/255,a===1)return t;let s=t>>24&255,c=t>>16&255,l=t>>8&255,u=e>>24&255,d=e>>16&255,f=e>>8&255;return n=u+Math.round((s-u)*a),r=d+Math.round((c-d)*a),i=f+Math.round((l-f)*a),o.toRgba(n,r,i)},e.ensureContrastRatio=function(e,n,r){let i=l.relativeLuminance(e>>8),a=l.relativeLuminance(n>>8);if(f(i,a)<r){if(a<i){let a=t(e,n,r),o=f(i,l.relativeLuminance(a>>8));if(o<r){let t=s(e,n,r);return o>f(i,l.relativeLuminance(t>>8))?a:t}return a}let o=s(e,n,r),c=f(i,l.relativeLuminance(o>>8));if(c<r){let a=t(e,n,r);return c>f(i,l.relativeLuminance(a>>8))?o:a}return o}},e.reduceLuminance=t,e.increaseLuminance=s,e.toChannels=function(e){return[e>>24&255,e>>16&255,e>>8&255,255&e]}}(u||(t.rgba=u={})),t.toPaddedHex=d,t.contrastRatio=f},8969:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.CoreTerminal=void 0;let r=n(844),i=n(2585),a=n(4348),o=n(7866),s=n(744),c=n(7302),l=n(6975),u=n(8460),d=n(1753),f=n(1480),p=n(7994),m=n(9282),h=n(5435),g=n(5981),_=n(2660),v=!1;class y extends r.Disposable{get onScroll(){return this._onScrollApi||(this._onScrollApi=this.register(new u.EventEmitter),this._onScroll.event((e=>{this._onScrollApi?.fire(e.position)}))),this._onScrollApi.event}get cols(){return this._bufferService.cols}get rows(){return this._bufferService.rows}get buffers(){return this._bufferService.buffers}get options(){return this.optionsService.options}set options(e){for(let t in e)this.optionsService.options[t]=e[t]}constructor(e){super(),this._windowsWrappingHeuristics=this.register(new r.MutableDisposable),this._onBinary=this.register(new u.EventEmitter),this.onBinary=this._onBinary.event,this._onData=this.register(new u.EventEmitter),this.onData=this._onData.event,this._onLineFeed=this.register(new u.EventEmitter),this.onLineFeed=this._onLineFeed.event,this._onResize=this.register(new u.EventEmitter),this.onResize=this._onResize.event,this._onWriteParsed=this.register(new u.EventEmitter),this.onWriteParsed=this._onWriteParsed.event,this._onScroll=this.register(new u.EventEmitter),this._instantiationService=new a.InstantiationService,this.optionsService=this.register(new c.OptionsService(e)),this._instantiationService.setService(i.IOptionsService,this.optionsService),this._bufferService=this.register(this._instantiationService.createInstance(s.BufferService)),this._instantiationService.setService(i.IBufferService,this._bufferService),this._logService=this.register(this._instantiationService.createInstance(o.LogService)),this._instantiationService.setService(i.ILogService,this._logService),this.coreService=this.register(this._instantiationService.createInstance(l.CoreService)),this._instantiationService.setService(i.ICoreService,this.coreService),this.coreMouseService=this.register(this._instantiationService.createInstance(d.CoreMouseService)),this._instantiationService.setService(i.ICoreMouseService,this.coreMouseService),this.unicodeService=this.register(this._instantiationService.createInstance(f.UnicodeService)),this._instantiationService.setService(i.IUnicodeService,this.unicodeService),this._charsetService=this._instantiationService.createInstance(p.CharsetService),this._instantiationService.setService(i.ICharsetService,this._charsetService),this._oscLinkService=this._instantiationService.createInstance(_.OscLinkService),this._instantiationService.setService(i.IOscLinkService,this._oscLinkService),this._inputHandler=this.register(new h.InputHandler(this._bufferService,this._charsetService,this.coreService,this._logService,this.optionsService,this._oscLinkService,this.coreMouseService,this.unicodeService)),this.register((0,u.forwardEvent)(this._inputHandler.onLineFeed,this._onLineFeed)),this.register(this._inputHandler),this.register((0,u.forwardEvent)(this._bufferService.onResize,this._onResize)),this.register((0,u.forwardEvent)(this.coreService.onData,this._onData)),this.register((0,u.forwardEvent)(this.coreService.onBinary,this._onBinary)),this.register(this.coreService.onRequestScrollToBottom((()=>this.scrollToBottom()))),this.register(this.coreService.onUserInput((()=>this._writeBuffer.handleUserInput()))),this.register(this.optionsService.onMultipleOptionChange([`windowsMode`,`windowsPty`],(()=>this._handleWindowsPtyOptionChange()))),this.register(this._bufferService.onScroll((e=>{this._onScroll.fire({position:this._bufferService.buffer.ydisp,source:0}),this._inputHandler.markRangeDirty(this._bufferService.buffer.scrollTop,this._bufferService.buffer.scrollBottom)}))),this.register(this._inputHandler.onScroll((e=>{this._onScroll.fire({position:this._bufferService.buffer.ydisp,source:0}),this._inputHandler.markRangeDirty(this._bufferService.buffer.scrollTop,this._bufferService.buffer.scrollBottom)}))),this._writeBuffer=this.register(new g.WriteBuffer(((e,t)=>this._inputHandler.parse(e,t)))),this.register((0,u.forwardEvent)(this._writeBuffer.onWriteParsed,this._onWriteParsed))}write(e,t){this._writeBuffer.write(e,t)}writeSync(e,t){this._logService.logLevel<=i.LogLevelEnum.WARN&&!v&&(this._logService.warn(`writeSync is unreliable and will be removed soon.`),v=!0),this._writeBuffer.writeSync(e,t)}input(e,t=!0){this.coreService.triggerDataEvent(e,t)}resize(e,t){isNaN(e)||isNaN(t)||(e=Math.max(e,s.MINIMUM_COLS),t=Math.max(t,s.MINIMUM_ROWS),this._bufferService.resize(e,t))}scroll(e,t=!1){this._bufferService.scroll(e,t)}scrollLines(e,t,n){this._bufferService.scrollLines(e,t,n)}scrollPages(e){this.scrollLines(e*(this.rows-1))}scrollToTop(){this.scrollLines(-this._bufferService.buffer.ydisp)}scrollToBottom(){this.scrollLines(this._bufferService.buffer.ybase-this._bufferService.buffer.ydisp)}scrollToLine(e){let t=e-this._bufferService.buffer.ydisp;t!==0&&this.scrollLines(t)}registerEscHandler(e,t){return this._inputHandler.registerEscHandler(e,t)}registerDcsHandler(e,t){return this._inputHandler.registerDcsHandler(e,t)}registerCsiHandler(e,t){return this._inputHandler.registerCsiHandler(e,t)}registerOscHandler(e,t){return this._inputHandler.registerOscHandler(e,t)}_setup(){this._handleWindowsPtyOptionChange()}reset(){this._inputHandler.reset(),this._bufferService.reset(),this._charsetService.reset(),this.coreService.reset(),this.coreMouseService.reset()}_handleWindowsPtyOptionChange(){let e=!1,t=this.optionsService.rawOptions.windowsPty;t&&t.buildNumber!==void 0&&t.buildNumber!==void 0?e=t.backend===`conpty`&&t.buildNumber<21376:this.optionsService.rawOptions.windowsMode&&(e=!0),e?this._enableWindowsWrappingHeuristics():this._windowsWrappingHeuristics.clear()}_enableWindowsWrappingHeuristics(){if(!this._windowsWrappingHeuristics.value){let e=[];e.push(this.onLineFeed(m.updateWindowsModeWrappedState.bind(null,this._bufferService))),e.push(this.registerCsiHandler({final:`H`},(()=>((0,m.updateWindowsModeWrappedState)(this._bufferService),!1)))),this._windowsWrappingHeuristics.value=(0,r.toDisposable)((()=>{for(let t of e)t.dispose()}))}}}t.CoreTerminal=y},8460:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.runAndSubscribe=t.forwardEvent=t.EventEmitter=void 0,t.EventEmitter=class{constructor(){this._listeners=[],this._disposed=!1}get event(){return this._event||=e=>(this._listeners.push(e),{dispose:()=>{if(!this._disposed){for(let t=0;t<this._listeners.length;t++)if(this._listeners[t]===e)return void this._listeners.splice(t,1)}}}),this._event}fire(e,t){let n=[];for(let e=0;e<this._listeners.length;e++)n.push(this._listeners[e]);for(let r=0;r<n.length;r++)n[r].call(void 0,e,t)}dispose(){this.clearListeners(),this._disposed=!0}clearListeners(){this._listeners&&(this._listeners.length=0)}},t.forwardEvent=function(e,t){return e((e=>t.fire(e)))},t.runAndSubscribe=function(e,t){return t(void 0),e((e=>t(e)))}},5435:function(e,t,n){var r=this&&this.__decorate||function(e,t,n,r){var i,a=arguments.length,o=a<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)o=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o},i=this&&this.__param||function(e,t){return function(n,r){t(n,r,e)}};Object.defineProperty(t,"__esModule",{value:!0}),t.InputHandler=t.WindowsOptionsReportType=void 0;let a=n(2584),o=n(7116),s=n(2015),c=n(844),l=n(482),u=n(8437),d=n(8460),f=n(643),p=n(511),m=n(3734),h=n(2585),g=n(1480),_=n(6242),v=n(6351),y=n(5941),b={"(":0,")":1,"*":2,"+":3,"-":1,".":2},x=131072;function S(e,t){if(e>24)return t.setWinLines||!1;switch(e){case 1:return!!t.restoreWin;case 2:return!!t.minimizeWin;case 3:return!!t.setWinPosition;case 4:return!!t.setWinSizePixels;case 5:return!!t.raiseWin;case 6:return!!t.lowerWin;case 7:return!!t.refreshWin;case 8:return!!t.setWinSizeChars;case 9:return!!t.maximizeWin;case 10:return!!t.fullscreenWin;case 11:return!!t.getWinState;case 13:return!!t.getWinPosition;case 14:return!!t.getWinSizePixels;case 15:return!!t.getScreenSizePixels;case 16:return!!t.getCellSizePixels;case 18:return!!t.getWinSizeChars;case 19:return!!t.getScreenSizeChars;case 20:return!!t.getIconTitle;case 21:return!!t.getWinTitle;case 22:return!!t.pushTitle;case 23:return!!t.popTitle;case 24:return!!t.setWinLines}return!1}var C;(function(e){e[e.GET_WIN_SIZE_PIXELS=0]=`GET_WIN_SIZE_PIXELS`,e[e.GET_CELL_SIZE_PIXELS=1]=`GET_CELL_SIZE_PIXELS`})(C||(t.WindowsOptionsReportType=C={}));let w=0;class T extends c.Disposable{getAttrData(){return this._curAttrData}constructor(e,t,n,r,i,c,f,m,h=new s.EscapeSequenceParser){super(),this._bufferService=e,this._charsetService=t,this._coreService=n,this._logService=r,this._optionsService=i,this._oscLinkService=c,this._coreMouseService=f,this._unicodeService=m,this._parser=h,this._parseBuffer=new Uint32Array(4096),this._stringDecoder=new l.StringToUtf32,this._utf8Decoder=new l.Utf8ToUtf32,this._workCell=new p.CellData,this._windowTitle=``,this._iconName=``,this._windowTitleStack=[],this._iconNameStack=[],this._curAttrData=u.DEFAULT_ATTR_DATA.clone(),this._eraseAttrDataInternal=u.DEFAULT_ATTR_DATA.clone(),this._onRequestBell=this.register(new d.EventEmitter),this.onRequestBell=this._onRequestBell.event,this._onRequestRefreshRows=this.register(new d.EventEmitter),this.onRequestRefreshRows=this._onRequestRefreshRows.event,this._onRequestReset=this.register(new d.EventEmitter),this.onRequestReset=this._onRequestReset.event,this._onRequestSendFocus=this.register(new d.EventEmitter),this.onRequestSendFocus=this._onRequestSendFocus.event,this._onRequestSyncScrollBar=this.register(new d.EventEmitter),this.onRequestSyncScrollBar=this._onRequestSyncScrollBar.event,this._onRequestWindowsOptionsReport=this.register(new d.EventEmitter),this.onRequestWindowsOptionsReport=this._onRequestWindowsOptionsReport.event,this._onA11yChar=this.register(new d.EventEmitter),this.onA11yChar=this._onA11yChar.event,this._onA11yTab=this.register(new d.EventEmitter),this.onA11yTab=this._onA11yTab.event,this._onCursorMove=this.register(new d.EventEmitter),this.onCursorMove=this._onCursorMove.event,this._onLineFeed=this.register(new d.EventEmitter),this.onLineFeed=this._onLineFeed.event,this._onScroll=this.register(new d.EventEmitter),this.onScroll=this._onScroll.event,this._onTitleChange=this.register(new d.EventEmitter),this.onTitleChange=this._onTitleChange.event,this._onColor=this.register(new d.EventEmitter),this.onColor=this._onColor.event,this._parseStack={paused:!1,cursorStartX:0,cursorStartY:0,decodedLength:0,position:0},this._specialColors=[256,257,258],this.register(this._parser),this._dirtyRowTracker=new E(this._bufferService),this._activeBuffer=this._bufferService.buffer,this.register(this._bufferService.buffers.onBufferActivate((e=>this._activeBuffer=e.activeBuffer))),this._parser.setCsiHandlerFallback(((e,t)=>{this._logService.debug(`Unknown CSI code: `,{identifier:this._parser.identToString(e),params:t.toArray()})})),this._parser.setEscHandlerFallback((e=>{this._logService.debug(`Unknown ESC code: `,{identifier:this._parser.identToString(e)})})),this._parser.setExecuteHandlerFallback((e=>{this._logService.debug(`Unknown EXECUTE code: `,{code:e})})),this._parser.setOscHandlerFallback(((e,t,n)=>{this._logService.debug(`Unknown OSC code: `,{identifier:e,action:t,data:n})})),this._parser.setDcsHandlerFallback(((e,t,n)=>{t===`HOOK`&&(n=n.toArray()),this._logService.debug(`Unknown DCS code: `,{identifier:this._parser.identToString(e),action:t,payload:n})})),this._parser.setPrintHandler(((e,t,n)=>this.print(e,t,n))),this._parser.registerCsiHandler({final:`@`},(e=>this.insertChars(e))),this._parser.registerCsiHandler({intermediates:` `,final:`@`},(e=>this.scrollLeft(e))),this._parser.registerCsiHandler({final:`A`},(e=>this.cursorUp(e))),this._parser.registerCsiHandler({intermediates:` `,final:`A`},(e=>this.scrollRight(e))),this._parser.registerCsiHandler({final:`B`},(e=>this.cursorDown(e))),this._parser.registerCsiHandler({final:`C`},(e=>this.cursorForward(e))),this._parser.registerCsiHandler({final:`D`},(e=>this.cursorBackward(e))),this._parser.registerCsiHandler({final:`E`},(e=>this.cursorNextLine(e))),this._parser.registerCsiHandler({final:`F`},(e=>this.cursorPrecedingLine(e))),this._parser.registerCsiHandler({final:`G`},(e=>this.cursorCharAbsolute(e))),this._parser.registerCsiHandler({final:`H`},(e=>this.cursorPosition(e))),this._parser.registerCsiHandler({final:`I`},(e=>this.cursorForwardTab(e))),this._parser.registerCsiHandler({final:`J`},(e=>this.eraseInDisplay(e,!1))),this._parser.registerCsiHandler({prefix:`?`,final:`J`},(e=>this.eraseInDisplay(e,!0))),this._parser.registerCsiHandler({final:`K`},(e=>this.eraseInLine(e,!1))),this._parser.registerCsiHandler({prefix:`?`,final:`K`},(e=>this.eraseInLine(e,!0))),this._parser.registerCsiHandler({final:`L`},(e=>this.insertLines(e))),this._parser.registerCsiHandler({final:`M`},(e=>this.deleteLines(e))),this._parser.registerCsiHandler({final:`P`},(e=>this.deleteChars(e))),this._parser.registerCsiHandler({final:`S`},(e=>this.scrollUp(e))),this._parser.registerCsiHandler({final:`T`},(e=>this.scrollDown(e))),this._parser.registerCsiHandler({final:`X`},(e=>this.eraseChars(e))),this._parser.registerCsiHandler({final:`Z`},(e=>this.cursorBackwardTab(e))),this._parser.registerCsiHandler({final:"`"},(e=>this.charPosAbsolute(e))),this._parser.registerCsiHandler({final:`a`},(e=>this.hPositionRelative(e))),this._parser.registerCsiHandler({final:`b`},(e=>this.repeatPrecedingCharacter(e))),this._parser.registerCsiHandler({final:`c`},(e=>this.sendDeviceAttributesPrimary(e))),this._parser.registerCsiHandler({prefix:`>`,final:`c`},(e=>this.sendDeviceAttributesSecondary(e))),this._parser.registerCsiHandler({final:`d`},(e=>this.linePosAbsolute(e))),this._parser.registerCsiHandler({final:`e`},(e=>this.vPositionRelative(e))),this._parser.registerCsiHandler({final:`f`},(e=>this.hVPosition(e))),this._parser.registerCsiHandler({final:`g`},(e=>this.tabClear(e))),this._parser.registerCsiHandler({final:`h`},(e=>this.setMode(e))),this._parser.registerCsiHandler({prefix:`?`,final:`h`},(e=>this.setModePrivate(e))),this._parser.registerCsiHandler({final:`l`},(e=>this.resetMode(e))),this._parser.registerCsiHandler({prefix:`?`,final:`l`},(e=>this.resetModePrivate(e))),this._parser.registerCsiHandler({final:`m`},(e=>this.charAttributes(e))),this._parser.registerCsiHandler({final:`n`},(e=>this.deviceStatus(e))),this._parser.registerCsiHandler({prefix:`?`,final:`n`},(e=>this.deviceStatusPrivate(e))),this._parser.registerCsiHandler({intermediates:`!`,final:`p`},(e=>this.softReset(e))),this._parser.registerCsiHandler({intermediates:` `,final:`q`},(e=>this.setCursorStyle(e))),this._parser.registerCsiHandler({final:`r`},(e=>this.setScrollRegion(e))),this._parser.registerCsiHandler({final:`s`},(e=>this.saveCursor(e))),this._parser.registerCsiHandler({final:`t`},(e=>this.windowOptions(e))),this._parser.registerCsiHandler({final:`u`},(e=>this.restoreCursor(e))),this._parser.registerCsiHandler({intermediates:`'`,final:`}`},(e=>this.insertColumns(e))),this._parser.registerCsiHandler({intermediates:`'`,final:`~`},(e=>this.deleteColumns(e))),this._parser.registerCsiHandler({intermediates:`"`,final:`q`},(e=>this.selectProtected(e))),this._parser.registerCsiHandler({intermediates:`$`,final:`p`},(e=>this.requestMode(e,!0))),this._parser.registerCsiHandler({prefix:`?`,intermediates:`$`,final:`p`},(e=>this.requestMode(e,!1))),this._parser.setExecuteHandler(a.C0.BEL,(()=>this.bell())),this._parser.setExecuteHandler(a.C0.LF,(()=>this.lineFeed())),this._parser.setExecuteHandler(a.C0.VT,(()=>this.lineFeed())),this._parser.setExecuteHandler(a.C0.FF,(()=>this.lineFeed())),this._parser.setExecuteHandler(a.C0.CR,(()=>this.carriageReturn())),this._parser.setExecuteHandler(a.C0.BS,(()=>this.backspace())),this._parser.setExecuteHandler(a.C0.HT,(()=>this.tab())),this._parser.setExecuteHandler(a.C0.SO,(()=>this.shiftOut())),this._parser.setExecuteHandler(a.C0.SI,(()=>this.shiftIn())),this._parser.setExecuteHandler(a.C1.IND,(()=>this.index())),this._parser.setExecuteHandler(a.C1.NEL,(()=>this.nextLine())),this._parser.setExecuteHandler(a.C1.HTS,(()=>this.tabSet())),this._parser.registerOscHandler(0,new _.OscHandler((e=>(this.setTitle(e),this.setIconName(e),!0)))),this._parser.registerOscHandler(1,new _.OscHandler((e=>this.setIconName(e)))),this._parser.registerOscHandler(2,new _.OscHandler((e=>this.setTitle(e)))),this._parser.registerOscHandler(4,new _.OscHandler((e=>this.setOrReportIndexedColor(e)))),this._parser.registerOscHandler(8,new _.OscHandler((e=>this.setHyperlink(e)))),this._parser.registerOscHandler(10,new _.OscHandler((e=>this.setOrReportFgColor(e)))),this._parser.registerOscHandler(11,new _.OscHandler((e=>this.setOrReportBgColor(e)))),this._parser.registerOscHandler(12,new _.OscHandler((e=>this.setOrReportCursorColor(e)))),this._parser.registerOscHandler(104,new _.OscHandler((e=>this.restoreIndexedColor(e)))),this._parser.registerOscHandler(110,new _.OscHandler((e=>this.restoreFgColor(e)))),this._parser.registerOscHandler(111,new _.OscHandler((e=>this.restoreBgColor(e)))),this._parser.registerOscHandler(112,new _.OscHandler((e=>this.restoreCursorColor(e)))),this._parser.registerEscHandler({final:`7`},(()=>this.saveCursor())),this._parser.registerEscHandler({final:`8`},(()=>this.restoreCursor())),this._parser.registerEscHandler({final:`D`},(()=>this.index())),this._parser.registerEscHandler({final:`E`},(()=>this.nextLine())),this._parser.registerEscHandler({final:`H`},(()=>this.tabSet())),this._parser.registerEscHandler({final:`M`},(()=>this.reverseIndex())),this._parser.registerEscHandler({final:`=`},(()=>this.keypadApplicationMode())),this._parser.registerEscHandler({final:`>`},(()=>this.keypadNumericMode())),this._parser.registerEscHandler({final:`c`},(()=>this.fullReset())),this._parser.registerEscHandler({final:`n`},(()=>this.setgLevel(2))),this._parser.registerEscHandler({final:`o`},(()=>this.setgLevel(3))),this._parser.registerEscHandler({final:`|`},(()=>this.setgLevel(3))),this._parser.registerEscHandler({final:`}`},(()=>this.setgLevel(2))),this._parser.registerEscHandler({final:`~`},(()=>this.setgLevel(1))),this._parser.registerEscHandler({intermediates:`%`,final:`@`},(()=>this.selectDefaultCharset())),this._parser.registerEscHandler({intermediates:`%`,final:`G`},(()=>this.selectDefaultCharset()));for(let e in o.CHARSETS)this._parser.registerEscHandler({intermediates:`(`,final:e},(()=>this.selectCharset(`(`+e))),this._parser.registerEscHandler({intermediates:`)`,final:e},(()=>this.selectCharset(`)`+e))),this._parser.registerEscHandler({intermediates:`*`,final:e},(()=>this.selectCharset(`*`+e))),this._parser.registerEscHandler({intermediates:`+`,final:e},(()=>this.selectCharset(`+`+e))),this._parser.registerEscHandler({intermediates:`-`,final:e},(()=>this.selectCharset(`-`+e))),this._parser.registerEscHandler({intermediates:`.`,final:e},(()=>this.selectCharset(`.`+e))),this._parser.registerEscHandler({intermediates:`/`,final:e},(()=>this.selectCharset(`/`+e)));this._parser.registerEscHandler({intermediates:`#`,final:`8`},(()=>this.screenAlignmentPattern())),this._parser.setErrorHandler((e=>(this._logService.error(`Parsing error: `,e),e))),this._parser.registerDcsHandler({intermediates:`$`,final:`q`},new v.DcsHandler(((e,t)=>this.requestStatusString(e,t))))}_preserveStack(e,t,n,r){this._parseStack.paused=!0,this._parseStack.cursorStartX=e,this._parseStack.cursorStartY=t,this._parseStack.decodedLength=n,this._parseStack.position=r}_logSlowResolvingAsync(e){this._logService.logLevel<=h.LogLevelEnum.WARN&&Promise.race([e,new Promise(((e,t)=>setTimeout((()=>t(`#SLOW_TIMEOUT`)),5e3)))]).catch((e=>{if(e!==`#SLOW_TIMEOUT`)throw e;console.warn(`async parser handler taking longer than 5000 ms`)}))}_getCurrentLinkId(){return this._curAttrData.extended.urlId}parse(e,t){let n,r=this._activeBuffer.x,i=this._activeBuffer.y,a=0,o=this._parseStack.paused;if(o){if(n=this._parser.parse(this._parseBuffer,this._parseStack.decodedLength,t))return this._logSlowResolvingAsync(n),n;r=this._parseStack.cursorStartX,i=this._parseStack.cursorStartY,this._parseStack.paused=!1,e.length>x&&(a=this._parseStack.position+x)}if(this._logService.logLevel<=h.LogLevelEnum.DEBUG&&this._logService.debug(`parsing data`+(typeof e==`string`?` "${e}"`:` "${Array.prototype.map.call(e,(e=>String.fromCharCode(e))).join(``)}"`),typeof e==`string`?e.split(``).map((e=>e.charCodeAt(0))):e),this._parseBuffer.length<e.length&&this._parseBuffer.length<x&&(this._parseBuffer=new Uint32Array(Math.min(e.length,x))),o||this._dirtyRowTracker.clearRange(),e.length>x)for(let t=a;t<e.length;t+=x){let a=t+x<e.length?t+x:e.length,o=typeof e==`string`?this._stringDecoder.decode(e.substring(t,a),this._parseBuffer):this._utf8Decoder.decode(e.subarray(t,a),this._parseBuffer);if(n=this._parser.parse(this._parseBuffer,o))return this._preserveStack(r,i,o,t),this._logSlowResolvingAsync(n),n}else if(!o){let t=typeof e==`string`?this._stringDecoder.decode(e,this._parseBuffer):this._utf8Decoder.decode(e,this._parseBuffer);if(n=this._parser.parse(this._parseBuffer,t))return this._preserveStack(r,i,t,0),this._logSlowResolvingAsync(n),n}this._activeBuffer.x===r&&this._activeBuffer.y===i||this._onCursorMove.fire();let s=this._dirtyRowTracker.end+(this._bufferService.buffer.ybase-this._bufferService.buffer.ydisp),c=this._dirtyRowTracker.start+(this._bufferService.buffer.ybase-this._bufferService.buffer.ydisp);c<this._bufferService.rows&&this._onRequestRefreshRows.fire(Math.min(c,this._bufferService.rows-1),Math.min(s,this._bufferService.rows-1))}print(e,t,n){let r,i,a=this._charsetService.charset,o=this._optionsService.rawOptions.screenReaderMode,s=this._bufferService.cols,c=this._coreService.decPrivateModes.wraparound,d=this._coreService.modes.insertMode,p=this._curAttrData,m=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y);this._dirtyRowTracker.markDirty(this._activeBuffer.y),this._activeBuffer.x&&n-t>0&&m.getWidth(this._activeBuffer.x-1)===2&&m.setCellFromCodepoint(this._activeBuffer.x-1,0,1,p);let h=this._parser.precedingJoinState;for(let _=t;_<n;++_){if(r=e[_],r<127&&a){let e=a[String.fromCharCode(r)];e&&(r=e.charCodeAt(0))}let t=this._unicodeService.charProperties(r,h);i=g.UnicodeService.extractWidth(t);let n=g.UnicodeService.extractShouldJoin(t),v=n?g.UnicodeService.extractWidth(h):0;if(h=t,o&&this._onA11yChar.fire((0,l.stringFromCodePoint)(r)),this._getCurrentLinkId()&&this._oscLinkService.addLineToLink(this._getCurrentLinkId(),this._activeBuffer.ybase+this._activeBuffer.y),this._activeBuffer.x+i-v>s){if(c){let e=m,t=this._activeBuffer.x-v;for(this._activeBuffer.x=v,this._activeBuffer.y++,this._activeBuffer.y===this._activeBuffer.scrollBottom+1?(this._activeBuffer.y--,this._bufferService.scroll(this._eraseAttrData(),!0)):(this._activeBuffer.y>=this._bufferService.rows&&(this._activeBuffer.y=this._bufferService.rows-1),this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y).isWrapped=!0),m=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y),v>0&&m instanceof u.BufferLine&&m.copyCellsFrom(e,t,0,v,!1);t<s;)e.setCellFromCodepoint(t++,0,1,p)}else if(this._activeBuffer.x=s-1,i===2)continue}if(n&&this._activeBuffer.x){let e=m.getWidth(this._activeBuffer.x-1)?1:2;m.addCodepointToCell(this._activeBuffer.x-e,r,i);for(let e=i-v;--e>=0;)m.setCellFromCodepoint(this._activeBuffer.x++,0,0,p)}else if(d&&(m.insertCells(this._activeBuffer.x,i-v,this._activeBuffer.getNullCell(p)),m.getWidth(s-1)===2&&m.setCellFromCodepoint(s-1,f.NULL_CELL_CODE,f.NULL_CELL_WIDTH,p)),m.setCellFromCodepoint(this._activeBuffer.x++,r,i,p),i>0)for(;--i;)m.setCellFromCodepoint(this._activeBuffer.x++,0,0,p)}this._parser.precedingJoinState=h,this._activeBuffer.x<s&&n-t>0&&m.getWidth(this._activeBuffer.x)===0&&!m.hasContent(this._activeBuffer.x)&&m.setCellFromCodepoint(this._activeBuffer.x,0,1,p),this._dirtyRowTracker.markDirty(this._activeBuffer.y)}registerCsiHandler(e,t){return e.final!==`t`||e.prefix||e.intermediates?this._parser.registerCsiHandler(e,t):this._parser.registerCsiHandler(e,(e=>!S(e.params[0],this._optionsService.rawOptions.windowOptions)||t(e)))}registerDcsHandler(e,t){return this._parser.registerDcsHandler(e,new v.DcsHandler(t))}registerEscHandler(e,t){return this._parser.registerEscHandler(e,t)}registerOscHandler(e,t){return this._parser.registerOscHandler(e,new _.OscHandler(t))}bell(){return this._onRequestBell.fire(),!0}lineFeed(){return this._dirtyRowTracker.markDirty(this._activeBuffer.y),this._optionsService.rawOptions.convertEol&&(this._activeBuffer.x=0),this._activeBuffer.y++,this._activeBuffer.y===this._activeBuffer.scrollBottom+1?(this._activeBuffer.y--,this._bufferService.scroll(this._eraseAttrData())):this._activeBuffer.y>=this._bufferService.rows?this._activeBuffer.y=this._bufferService.rows-1:this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y).isWrapped=!1,this._activeBuffer.x>=this._bufferService.cols&&this._activeBuffer.x--,this._dirtyRowTracker.markDirty(this._activeBuffer.y),this._onLineFeed.fire(),!0}carriageReturn(){return this._activeBuffer.x=0,!0}backspace(){if(!this._coreService.decPrivateModes.reverseWraparound)return this._restrictCursor(),this._activeBuffer.x>0&&this._activeBuffer.x--,!0;if(this._restrictCursor(this._bufferService.cols),this._activeBuffer.x>0)this._activeBuffer.x--;else if(this._activeBuffer.x===0&&this._activeBuffer.y>this._activeBuffer.scrollTop&&this._activeBuffer.y<=this._activeBuffer.scrollBottom&&this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y)?.isWrapped){this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y).isWrapped=!1,this._activeBuffer.y--,this._activeBuffer.x=this._bufferService.cols-1;let e=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y);e.hasWidth(this._activeBuffer.x)&&!e.hasContent(this._activeBuffer.x)&&this._activeBuffer.x--}return this._restrictCursor(),!0}tab(){if(this._activeBuffer.x>=this._bufferService.cols)return!0;let e=this._activeBuffer.x;return this._activeBuffer.x=this._activeBuffer.nextStop(),this._optionsService.rawOptions.screenReaderMode&&this._onA11yTab.fire(this._activeBuffer.x-e),!0}shiftOut(){return this._charsetService.setgLevel(1),!0}shiftIn(){return this._charsetService.setgLevel(0),!0}_restrictCursor(e=this._bufferService.cols-1){this._activeBuffer.x=Math.min(e,Math.max(0,this._activeBuffer.x)),this._activeBuffer.y=this._coreService.decPrivateModes.origin?Math.min(this._activeBuffer.scrollBottom,Math.max(this._activeBuffer.scrollTop,this._activeBuffer.y)):Math.min(this._bufferService.rows-1,Math.max(0,this._activeBuffer.y)),this._dirtyRowTracker.markDirty(this._activeBuffer.y)}_setCursor(e,t){this._dirtyRowTracker.markDirty(this._activeBuffer.y),this._coreService.decPrivateModes.origin?(this._activeBuffer.x=e,this._activeBuffer.y=this._activeBuffer.scrollTop+t):(this._activeBuffer.x=e,this._activeBuffer.y=t),this._restrictCursor(),this._dirtyRowTracker.markDirty(this._activeBuffer.y)}_moveCursor(e,t){this._restrictCursor(),this._setCursor(this._activeBuffer.x+e,this._activeBuffer.y+t)}cursorUp(e){let t=this._activeBuffer.y-this._activeBuffer.scrollTop;return t>=0?this._moveCursor(0,-Math.min(t,e.params[0]||1)):this._moveCursor(0,-(e.params[0]||1)),!0}cursorDown(e){let t=this._activeBuffer.scrollBottom-this._activeBuffer.y;return t>=0?this._moveCursor(0,Math.min(t,e.params[0]||1)):this._moveCursor(0,e.params[0]||1),!0}cursorForward(e){return this._moveCursor(e.params[0]||1,0),!0}cursorBackward(e){return this._moveCursor(-(e.params[0]||1),0),!0}cursorNextLine(e){return this.cursorDown(e),this._activeBuffer.x=0,!0}cursorPrecedingLine(e){return this.cursorUp(e),this._activeBuffer.x=0,!0}cursorCharAbsolute(e){return this._setCursor((e.params[0]||1)-1,this._activeBuffer.y),!0}cursorPosition(e){return this._setCursor(e.length>=2?(e.params[1]||1)-1:0,(e.params[0]||1)-1),!0}charPosAbsolute(e){return this._setCursor((e.params[0]||1)-1,this._activeBuffer.y),!0}hPositionRelative(e){return this._moveCursor(e.params[0]||1,0),!0}linePosAbsolute(e){return this._setCursor(this._activeBuffer.x,(e.params[0]||1)-1),!0}vPositionRelative(e){return this._moveCursor(0,e.params[0]||1),!0}hVPosition(e){return this.cursorPosition(e),!0}tabClear(e){let t=e.params[0];return t===0?delete this._activeBuffer.tabs[this._activeBuffer.x]:t===3&&(this._activeBuffer.tabs={}),!0}cursorForwardTab(e){if(this._activeBuffer.x>=this._bufferService.cols)return!0;let t=e.params[0]||1;for(;t--;)this._activeBuffer.x=this._activeBuffer.nextStop();return!0}cursorBackwardTab(e){if(this._activeBuffer.x>=this._bufferService.cols)return!0;let t=e.params[0]||1;for(;t--;)this._activeBuffer.x=this._activeBuffer.prevStop();return!0}selectProtected(e){let t=e.params[0];return t===1&&(this._curAttrData.bg|=536870912),t!==2&&t!==0||(this._curAttrData.bg&=-536870913),!0}_eraseInBufferLine(e,t,n,r=!1,i=!1){let a=this._activeBuffer.lines.get(this._activeBuffer.ybase+e);a.replaceCells(t,n,this._activeBuffer.getNullCell(this._eraseAttrData()),i),r&&(a.isWrapped=!1)}_resetBufferLine(e,t=!1){let n=this._activeBuffer.lines.get(this._activeBuffer.ybase+e);n&&(n.fill(this._activeBuffer.getNullCell(this._eraseAttrData()),t),this._bufferService.buffer.clearMarkers(this._activeBuffer.ybase+e),n.isWrapped=!1)}eraseInDisplay(e,t=!1){let n;switch(this._restrictCursor(this._bufferService.cols),e.params[0]){case 0:for(n=this._activeBuffer.y,this._dirtyRowTracker.markDirty(n),this._eraseInBufferLine(n++,this._activeBuffer.x,this._bufferService.cols,this._activeBuffer.x===0,t);n<this._bufferService.rows;n++)this._resetBufferLine(n,t);this._dirtyRowTracker.markDirty(n);break;case 1:for(n=this._activeBuffer.y,this._dirtyRowTracker.markDirty(n),this._eraseInBufferLine(n,0,this._activeBuffer.x+1,!0,t),this._activeBuffer.x+1>=this._bufferService.cols&&(this._activeBuffer.lines.get(n+1).isWrapped=!1);n--;)this._resetBufferLine(n,t);this._dirtyRowTracker.markDirty(0);break;case 2:for(n=this._bufferService.rows,this._dirtyRowTracker.markDirty(n-1);n--;)this._resetBufferLine(n,t);this._dirtyRowTracker.markDirty(0);break;case 3:let e=this._activeBuffer.lines.length-this._bufferService.rows;e>0&&(this._activeBuffer.lines.trimStart(e),this._activeBuffer.ybase=Math.max(this._activeBuffer.ybase-e,0),this._activeBuffer.ydisp=Math.max(this._activeBuffer.ydisp-e,0),this._onScroll.fire(0))}return!0}eraseInLine(e,t=!1){switch(this._restrictCursor(this._bufferService.cols),e.params[0]){case 0:this._eraseInBufferLine(this._activeBuffer.y,this._activeBuffer.x,this._bufferService.cols,this._activeBuffer.x===0,t);break;case 1:this._eraseInBufferLine(this._activeBuffer.y,0,this._activeBuffer.x+1,!1,t);break;case 2:this._eraseInBufferLine(this._activeBuffer.y,0,this._bufferService.cols,!0,t)}return this._dirtyRowTracker.markDirty(this._activeBuffer.y),!0}insertLines(e){this._restrictCursor();let t=e.params[0]||1;if(this._activeBuffer.y>this._activeBuffer.scrollBottom||this._activeBuffer.y<this._activeBuffer.scrollTop)return!0;let n=this._activeBuffer.ybase+this._activeBuffer.y,r=this._bufferService.rows-1-this._activeBuffer.scrollBottom,i=this._bufferService.rows-1+this._activeBuffer.ybase-r+1;for(;t--;)this._activeBuffer.lines.splice(i-1,1),this._activeBuffer.lines.splice(n,0,this._activeBuffer.getBlankLine(this._eraseAttrData()));return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.y,this._activeBuffer.scrollBottom),this._activeBuffer.x=0,!0}deleteLines(e){this._restrictCursor();let t=e.params[0]||1;if(this._activeBuffer.y>this._activeBuffer.scrollBottom||this._activeBuffer.y<this._activeBuffer.scrollTop)return!0;let n=this._activeBuffer.ybase+this._activeBuffer.y,r;for(r=this._bufferService.rows-1-this._activeBuffer.scrollBottom,r=this._bufferService.rows-1+this._activeBuffer.ybase-r;t--;)this._activeBuffer.lines.splice(n,1),this._activeBuffer.lines.splice(r,0,this._activeBuffer.getBlankLine(this._eraseAttrData()));return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.y,this._activeBuffer.scrollBottom),this._activeBuffer.x=0,!0}insertChars(e){this._restrictCursor();let t=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y);return t&&(t.insertCells(this._activeBuffer.x,e.params[0]||1,this._activeBuffer.getNullCell(this._eraseAttrData())),this._dirtyRowTracker.markDirty(this._activeBuffer.y)),!0}deleteChars(e){this._restrictCursor();let t=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y);return t&&(t.deleteCells(this._activeBuffer.x,e.params[0]||1,this._activeBuffer.getNullCell(this._eraseAttrData())),this._dirtyRowTracker.markDirty(this._activeBuffer.y)),!0}scrollUp(e){let t=e.params[0]||1;for(;t--;)this._activeBuffer.lines.splice(this._activeBuffer.ybase+this._activeBuffer.scrollTop,1),this._activeBuffer.lines.splice(this._activeBuffer.ybase+this._activeBuffer.scrollBottom,0,this._activeBuffer.getBlankLine(this._eraseAttrData()));return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom),!0}scrollDown(e){let t=e.params[0]||1;for(;t--;)this._activeBuffer.lines.splice(this._activeBuffer.ybase+this._activeBuffer.scrollBottom,1),this._activeBuffer.lines.splice(this._activeBuffer.ybase+this._activeBuffer.scrollTop,0,this._activeBuffer.getBlankLine(u.DEFAULT_ATTR_DATA));return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom),!0}scrollLeft(e){if(this._activeBuffer.y>this._activeBuffer.scrollBottom||this._activeBuffer.y<this._activeBuffer.scrollTop)return!0;let t=e.params[0]||1;for(let e=this._activeBuffer.scrollTop;e<=this._activeBuffer.scrollBottom;++e){let n=this._activeBuffer.lines.get(this._activeBuffer.ybase+e);n.deleteCells(0,t,this._activeBuffer.getNullCell(this._eraseAttrData())),n.isWrapped=!1}return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom),!0}scrollRight(e){if(this._activeBuffer.y>this._activeBuffer.scrollBottom||this._activeBuffer.y<this._activeBuffer.scrollTop)return!0;let t=e.params[0]||1;for(let e=this._activeBuffer.scrollTop;e<=this._activeBuffer.scrollBottom;++e){let n=this._activeBuffer.lines.get(this._activeBuffer.ybase+e);n.insertCells(0,t,this._activeBuffer.getNullCell(this._eraseAttrData())),n.isWrapped=!1}return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom),!0}insertColumns(e){if(this._activeBuffer.y>this._activeBuffer.scrollBottom||this._activeBuffer.y<this._activeBuffer.scrollTop)return!0;let t=e.params[0]||1;for(let e=this._activeBuffer.scrollTop;e<=this._activeBuffer.scrollBottom;++e){let n=this._activeBuffer.lines.get(this._activeBuffer.ybase+e);n.insertCells(this._activeBuffer.x,t,this._activeBuffer.getNullCell(this._eraseAttrData())),n.isWrapped=!1}return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom),!0}deleteColumns(e){if(this._activeBuffer.y>this._activeBuffer.scrollBottom||this._activeBuffer.y<this._activeBuffer.scrollTop)return!0;let t=e.params[0]||1;for(let e=this._activeBuffer.scrollTop;e<=this._activeBuffer.scrollBottom;++e){let n=this._activeBuffer.lines.get(this._activeBuffer.ybase+e);n.deleteCells(this._activeBuffer.x,t,this._activeBuffer.getNullCell(this._eraseAttrData())),n.isWrapped=!1}return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom),!0}eraseChars(e){this._restrictCursor();let t=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y);return t&&(t.replaceCells(this._activeBuffer.x,this._activeBuffer.x+(e.params[0]||1),this._activeBuffer.getNullCell(this._eraseAttrData())),this._dirtyRowTracker.markDirty(this._activeBuffer.y)),!0}repeatPrecedingCharacter(e){let t=this._parser.precedingJoinState;if(!t)return!0;let n=e.params[0]||1,r=g.UnicodeService.extractWidth(t),i=this._activeBuffer.x-r,a=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y).getString(i),o=new Uint32Array(a.length*n),s=0;for(let e=0;e<a.length;){let t=a.codePointAt(e)||0;o[s++]=t,e+=t>65535?2:1}let c=s;for(let e=1;e<n;++e)o.copyWithin(c,0,s),c+=s;return this.print(o,0,c),!0}sendDeviceAttributesPrimary(e){return e.params[0]>0||(this._is(`xterm`)||this._is(`rxvt-unicode`)||this._is(`screen`)?this._coreService.triggerDataEvent(a.C0.ESC+`[?1;2c`):this._is(`linux`)&&this._coreService.triggerDataEvent(a.C0.ESC+`[?6c`)),!0}sendDeviceAttributesSecondary(e){return e.params[0]>0||(this._is(`xterm`)?this._coreService.triggerDataEvent(a.C0.ESC+`[>0;276;0c`):this._is(`rxvt-unicode`)?this._coreService.triggerDataEvent(a.C0.ESC+`[>85;95;0c`):this._is(`linux`)?this._coreService.triggerDataEvent(e.params[0]+`c`):this._is(`screen`)&&this._coreService.triggerDataEvent(a.C0.ESC+`[>83;40003;0c`)),!0}_is(e){return(this._optionsService.rawOptions.termName+``).indexOf(e)===0}setMode(e){for(let t=0;t<e.length;t++)switch(e.params[t]){case 4:this._coreService.modes.insertMode=!0;break;case 20:this._optionsService.options.convertEol=!0}return!0}setModePrivate(e){for(let t=0;t<e.length;t++)switch(e.params[t]){case 1:this._coreService.decPrivateModes.applicationCursorKeys=!0;break;case 2:this._charsetService.setgCharset(0,o.DEFAULT_CHARSET),this._charsetService.setgCharset(1,o.DEFAULT_CHARSET),this._charsetService.setgCharset(2,o.DEFAULT_CHARSET),this._charsetService.setgCharset(3,o.DEFAULT_CHARSET);break;case 3:this._optionsService.rawOptions.windowOptions.setWinLines&&(this._bufferService.resize(132,this._bufferService.rows),this._onRequestReset.fire());break;case 6:this._coreService.decPrivateModes.origin=!0,this._setCursor(0,0);break;case 7:this._coreService.decPrivateModes.wraparound=!0;break;case 12:this._optionsService.options.cursorBlink=!0;break;case 45:this._coreService.decPrivateModes.reverseWraparound=!0;break;case 66:this._logService.debug(`Serial port requested application keypad.`),this._coreService.decPrivateModes.applicationKeypad=!0,this._onRequestSyncScrollBar.fire();break;case 9:this._coreMouseService.activeProtocol=`X10`;break;case 1e3:this._coreMouseService.activeProtocol=`VT200`;break;case 1002:this._coreMouseService.activeProtocol=`DRAG`;break;case 1003:this._coreMouseService.activeProtocol=`ANY`;break;case 1004:this._coreService.decPrivateModes.sendFocus=!0,this._onRequestSendFocus.fire();break;case 1005:this._logService.debug(`DECSET 1005 not supported (see #2507)`);break;case 1006:this._coreMouseService.activeEncoding=`SGR`;break;case 1015:this._logService.debug(`DECSET 1015 not supported (see #2507)`);break;case 1016:this._coreMouseService.activeEncoding=`SGR_PIXELS`;break;case 25:this._coreService.isCursorHidden=!1;break;case 1048:this.saveCursor();break;case 1049:this.saveCursor();case 47:case 1047:this._bufferService.buffers.activateAltBuffer(this._eraseAttrData()),this._coreService.isCursorInitialized=!0,this._onRequestRefreshRows.fire(0,this._bufferService.rows-1),this._onRequestSyncScrollBar.fire();break;case 2004:this._coreService.decPrivateModes.bracketedPasteMode=!0}return!0}resetMode(e){for(let t=0;t<e.length;t++)switch(e.params[t]){case 4:this._coreService.modes.insertMode=!1;break;case 20:this._optionsService.options.convertEol=!1}return!0}resetModePrivate(e){for(let t=0;t<e.length;t++)switch(e.params[t]){case 1:this._coreService.decPrivateModes.applicationCursorKeys=!1;break;case 3:this._optionsService.rawOptions.windowOptions.setWinLines&&(this._bufferService.resize(80,this._bufferService.rows),this._onRequestReset.fire());break;case 6:this._coreService.decPrivateModes.origin=!1,this._setCursor(0,0);break;case 7:this._coreService.decPrivateModes.wraparound=!1;break;case 12:this._optionsService.options.cursorBlink=!1;break;case 45:this._coreService.decPrivateModes.reverseWraparound=!1;break;case 66:this._logService.debug(`Switching back to normal keypad.`),this._coreService.decPrivateModes.applicationKeypad=!1,this._onRequestSyncScrollBar.fire();break;case 9:case 1e3:case 1002:case 1003:this._coreMouseService.activeProtocol=`NONE`;break;case 1004:this._coreService.decPrivateModes.sendFocus=!1;break;case 1005:this._logService.debug(`DECRST 1005 not supported (see #2507)`);break;case 1006:case 1016:this._coreMouseService.activeEncoding=`DEFAULT`;break;case 1015:this._logService.debug(`DECRST 1015 not supported (see #2507)`);break;case 25:this._coreService.isCursorHidden=!0;break;case 1048:this.restoreCursor();break;case 1049:case 47:case 1047:this._bufferService.buffers.activateNormalBuffer(),e.params[t]===1049&&this.restoreCursor(),this._coreService.isCursorInitialized=!0,this._onRequestRefreshRows.fire(0,this._bufferService.rows-1),this._onRequestSyncScrollBar.fire();break;case 2004:this._coreService.decPrivateModes.bracketedPasteMode=!1}return!0}requestMode(e,t){let n=this._coreService.decPrivateModes,{activeProtocol:r,activeEncoding:i}=this._coreMouseService,o=this._coreService,{buffers:s,cols:c}=this._bufferService,{active:l,alt:u}=s,d=this._optionsService.rawOptions,f=e=>e?1:2,p=e.params[0];return m=p,h=t?p===2?4:p===4?f(o.modes.insertMode):p===12?3:p===20?f(d.convertEol):0:p===1?f(n.applicationCursorKeys):p===3?d.windowOptions.setWinLines?c===80?2:+(c===132):0:p===6?f(n.origin):p===7?f(n.wraparound):p===8?3:p===9?f(r===`X10`):p===12?f(d.cursorBlink):p===25?f(!o.isCursorHidden):p===45?f(n.reverseWraparound):p===66?f(n.applicationKeypad):p===67?4:p===1e3?f(r===`VT200`):p===1002?f(r===`DRAG`):p===1003?f(r===`ANY`):p===1004?f(n.sendFocus):p===1005?4:p===1006?f(i===`SGR`):p===1015?4:p===1016?f(i===`SGR_PIXELS`):p===1048?1:p===47||p===1047||p===1049?f(l===u):p===2004?f(n.bracketedPasteMode):0,o.triggerDataEvent(`${a.C0.ESC}[${t?``:`?`}${m};${h}$y`),!0;var m,h}_updateAttrColor(e,t,n,r,i){return t===2?(e|=50331648,e&=-16777216,e|=m.AttributeData.fromColorRGB([n,r,i])):t===5&&(e&=-50331904,e|=33554432|255&n),e}_extractColor(e,t,n){let r=[0,0,-1,0,0,0],i=0,a=0;do{if(r[a+i]=e.params[t+a],e.hasSubParams(t+a)){let n=e.getSubParams(t+a),o=0;do r[1]===5&&(i=1),r[a+o+1+i]=n[o];while(++o<n.length&&o+a+1+i<r.length);break}if(r[1]===5&&a+i>=2||r[1]===2&&a+i>=5)break;r[1]&&(i=1)}while(++a+t<e.length&&a+i<r.length);for(let e=2;e<r.length;++e)r[e]===-1&&(r[e]=0);switch(r[0]){case 38:n.fg=this._updateAttrColor(n.fg,r[1],r[3],r[4],r[5]);break;case 48:n.bg=this._updateAttrColor(n.bg,r[1],r[3],r[4],r[5]);break;case 58:n.extended=n.extended.clone(),n.extended.underlineColor=this._updateAttrColor(n.extended.underlineColor,r[1],r[3],r[4],r[5])}return a}_processUnderline(e,t){t.extended=t.extended.clone(),(!~e||e>5)&&(e=1),t.extended.underlineStyle=e,t.fg|=268435456,e===0&&(t.fg&=-268435457),t.updateExtended()}_processSGR0(e){e.fg=u.DEFAULT_ATTR_DATA.fg,e.bg=u.DEFAULT_ATTR_DATA.bg,e.extended=e.extended.clone(),e.extended.underlineStyle=0,e.extended.underlineColor&=-67108864,e.updateExtended()}charAttributes(e){if(e.length===1&&e.params[0]===0)return this._processSGR0(this._curAttrData),!0;let t=e.length,n,r=this._curAttrData;for(let i=0;i<t;i++)n=e.params[i],n>=30&&n<=37?(r.fg&=-50331904,r.fg|=16777216|n-30):n>=40&&n<=47?(r.bg&=-50331904,r.bg|=16777216|n-40):n>=90&&n<=97?(r.fg&=-50331904,r.fg|=16777224|n-90):n>=100&&n<=107?(r.bg&=-50331904,r.bg|=16777224|n-100):n===0?this._processSGR0(r):n===1?r.fg|=134217728:n===3?r.bg|=67108864:n===4?(r.fg|=268435456,this._processUnderline(e.hasSubParams(i)?e.getSubParams(i)[0]:1,r)):n===5?r.fg|=536870912:n===7?r.fg|=67108864:n===8?r.fg|=1073741824:n===9?r.fg|=2147483648:n===2?r.bg|=134217728:n===21?this._processUnderline(2,r):n===22?(r.fg&=-134217729,r.bg&=-134217729):n===23?r.bg&=-67108865:n===24?(r.fg&=-268435457,this._processUnderline(0,r)):n===25?r.fg&=-536870913:n===27?r.fg&=-67108865:n===28?r.fg&=-1073741825:n===29?r.fg&=2147483647:n===39?(r.fg&=-67108864,r.fg|=16777215&u.DEFAULT_ATTR_DATA.fg):n===49?(r.bg&=-67108864,r.bg|=16777215&u.DEFAULT_ATTR_DATA.bg):n===38||n===48||n===58?i+=this._extractColor(e,i,r):n===53?r.bg|=1073741824:n===55?r.bg&=-1073741825:n===59?(r.extended=r.extended.clone(),r.extended.underlineColor=-1,r.updateExtended()):n===100?(r.fg&=-67108864,r.fg|=16777215&u.DEFAULT_ATTR_DATA.fg,r.bg&=-67108864,r.bg|=16777215&u.DEFAULT_ATTR_DATA.bg):this._logService.debug(`Unknown SGR attribute: %d.`,n);return!0}deviceStatus(e){switch(e.params[0]){case 5:this._coreService.triggerDataEvent(`${a.C0.ESC}[0n`);break;case 6:let e=this._activeBuffer.y+1,t=this._activeBuffer.x+1;this._coreService.triggerDataEvent(`${a.C0.ESC}[${e};${t}R`)}return!0}deviceStatusPrivate(e){if(e.params[0]===6){let e=this._activeBuffer.y+1,t=this._activeBuffer.x+1;this._coreService.triggerDataEvent(`${a.C0.ESC}[?${e};${t}R`)}return!0}softReset(e){return this._coreService.isCursorHidden=!1,this._onRequestSyncScrollBar.fire(),this._activeBuffer.scrollTop=0,this._activeBuffer.scrollBottom=this._bufferService.rows-1,this._curAttrData=u.DEFAULT_ATTR_DATA.clone(),this._coreService.reset(),this._charsetService.reset(),this._activeBuffer.savedX=0,this._activeBuffer.savedY=this._activeBuffer.ybase,this._activeBuffer.savedCurAttrData.fg=this._curAttrData.fg,this._activeBuffer.savedCurAttrData.bg=this._curAttrData.bg,this._activeBuffer.savedCharset=this._charsetService.charset,this._coreService.decPrivateModes.origin=!1,!0}setCursorStyle(e){let t=e.params[0]||1;switch(t){case 1:case 2:this._optionsService.options.cursorStyle=`block`;break;case 3:case 4:this._optionsService.options.cursorStyle=`underline`;break;case 5:case 6:this._optionsService.options.cursorStyle=`bar`}let n=t%2==1;return this._optionsService.options.cursorBlink=n,!0}setScrollRegion(e){let t=e.params[0]||1,n;return(e.length<2||(n=e.params[1])>this._bufferService.rows||n===0)&&(n=this._bufferService.rows),n>t&&(this._activeBuffer.scrollTop=t-1,this._activeBuffer.scrollBottom=n-1,this._setCursor(0,0)),!0}windowOptions(e){if(!S(e.params[0],this._optionsService.rawOptions.windowOptions))return!0;let t=e.length>1?e.params[1]:0;switch(e.params[0]){case 14:t!==2&&this._onRequestWindowsOptionsReport.fire(C.GET_WIN_SIZE_PIXELS);break;case 16:this._onRequestWindowsOptionsReport.fire(C.GET_CELL_SIZE_PIXELS);break;case 18:this._bufferService&&this._coreService.triggerDataEvent(`${a.C0.ESC}[8;${this._bufferService.rows};${this._bufferService.cols}t`);break;case 22:t!==0&&t!==2||(this._windowTitleStack.push(this._windowTitle),this._windowTitleStack.length>10&&this._windowTitleStack.shift()),t!==0&&t!==1||(this._iconNameStack.push(this._iconName),this._iconNameStack.length>10&&this._iconNameStack.shift());break;case 23:t!==0&&t!==2||this._windowTitleStack.length&&this.setTitle(this._windowTitleStack.pop()),t!==0&&t!==1||this._iconNameStack.length&&this.setIconName(this._iconNameStack.pop())}return!0}saveCursor(e){return this._activeBuffer.savedX=this._activeBuffer.x,this._activeBuffer.savedY=this._activeBuffer.ybase+this._activeBuffer.y,this._activeBuffer.savedCurAttrData.fg=this._curAttrData.fg,this._activeBuffer.savedCurAttrData.bg=this._curAttrData.bg,this._activeBuffer.savedCharset=this._charsetService.charset,!0}restoreCursor(e){return this._activeBuffer.x=this._activeBuffer.savedX||0,this._activeBuffer.y=Math.max(this._activeBuffer.savedY-this._activeBuffer.ybase,0),this._curAttrData.fg=this._activeBuffer.savedCurAttrData.fg,this._curAttrData.bg=this._activeBuffer.savedCurAttrData.bg,this._charsetService.charset=this._savedCharset,this._activeBuffer.savedCharset&&(this._charsetService.charset=this._activeBuffer.savedCharset),this._restrictCursor(),!0}setTitle(e){return this._windowTitle=e,this._onTitleChange.fire(e),!0}setIconName(e){return this._iconName=e,!0}setOrReportIndexedColor(e){let t=[],n=e.split(`;`);for(;n.length>1;){let e=n.shift(),r=n.shift();if(/^\d+$/.exec(e)){let n=parseInt(e);if(D(n))if(r===`?`)t.push({type:0,index:n});else{let e=(0,y.parseColor)(r);e&&t.push({type:1,index:n,color:e})}}}return t.length&&this._onColor.fire(t),!0}setHyperlink(e){let t=e.split(`;`);return!(t.length<2)&&(t[1]?this._createHyperlink(t[0],t[1]):!t[0]&&this._finishHyperlink())}_createHyperlink(e,t){this._getCurrentLinkId()&&this._finishHyperlink();let n=e.split(`:`),r,i=n.findIndex((e=>e.startsWith(`id=`)));return i!==-1&&(r=n[i].slice(3)||void 0),this._curAttrData.extended=this._curAttrData.extended.clone(),this._curAttrData.extended.urlId=this._oscLinkService.registerLink({id:r,uri:t}),this._curAttrData.updateExtended(),!0}_finishHyperlink(){return this._curAttrData.extended=this._curAttrData.extended.clone(),this._curAttrData.extended.urlId=0,this._curAttrData.updateExtended(),!0}_setOrReportSpecialColor(e,t){let n=e.split(`;`);for(let e=0;e<n.length&&!(t>=this._specialColors.length);++e,++t)if(n[e]===`?`)this._onColor.fire([{type:0,index:this._specialColors[t]}]);else{let r=(0,y.parseColor)(n[e]);r&&this._onColor.fire([{type:1,index:this._specialColors[t],color:r}])}return!0}setOrReportFgColor(e){return this._setOrReportSpecialColor(e,0)}setOrReportBgColor(e){return this._setOrReportSpecialColor(e,1)}setOrReportCursorColor(e){return this._setOrReportSpecialColor(e,2)}restoreIndexedColor(e){if(!e)return this._onColor.fire([{type:2}]),!0;let t=[],n=e.split(`;`);for(let e=0;e<n.length;++e)if(/^\d+$/.exec(n[e])){let r=parseInt(n[e]);D(r)&&t.push({type:2,index:r})}return t.length&&this._onColor.fire(t),!0}restoreFgColor(e){return this._onColor.fire([{type:2,index:256}]),!0}restoreBgColor(e){return this._onColor.fire([{type:2,index:257}]),!0}restoreCursorColor(e){return this._onColor.fire([{type:2,index:258}]),!0}nextLine(){return this._activeBuffer.x=0,this.index(),!0}keypadApplicationMode(){return this._logService.debug(`Serial port requested application keypad.`),this._coreService.decPrivateModes.applicationKeypad=!0,this._onRequestSyncScrollBar.fire(),!0}keypadNumericMode(){return this._logService.debug(`Switching back to normal keypad.`),this._coreService.decPrivateModes.applicationKeypad=!1,this._onRequestSyncScrollBar.fire(),!0}selectDefaultCharset(){return this._charsetService.setgLevel(0),this._charsetService.setgCharset(0,o.DEFAULT_CHARSET),!0}selectCharset(e){return e.length===2?(e[0]===`/`||this._charsetService.setgCharset(b[e[0]],o.CHARSETS[e[1]]||o.DEFAULT_CHARSET),!0):(this.selectDefaultCharset(),!0)}index(){return this._restrictCursor(),this._activeBuffer.y++,this._activeBuffer.y===this._activeBuffer.scrollBottom+1?(this._activeBuffer.y--,this._bufferService.scroll(this._eraseAttrData())):this._activeBuffer.y>=this._bufferService.rows&&(this._activeBuffer.y=this._bufferService.rows-1),this._restrictCursor(),!0}tabSet(){return this._activeBuffer.tabs[this._activeBuffer.x]=!0,!0}reverseIndex(){if(this._restrictCursor(),this._activeBuffer.y===this._activeBuffer.scrollTop){let e=this._activeBuffer.scrollBottom-this._activeBuffer.scrollTop;this._activeBuffer.lines.shiftElements(this._activeBuffer.ybase+this._activeBuffer.y,e,1),this._activeBuffer.lines.set(this._activeBuffer.ybase+this._activeBuffer.y,this._activeBuffer.getBlankLine(this._eraseAttrData())),this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom)}else this._activeBuffer.y--,this._restrictCursor();return!0}fullReset(){return this._parser.reset(),this._onRequestReset.fire(),!0}reset(){this._curAttrData=u.DEFAULT_ATTR_DATA.clone(),this._eraseAttrDataInternal=u.DEFAULT_ATTR_DATA.clone()}_eraseAttrData(){return this._eraseAttrDataInternal.bg&=-67108864,this._eraseAttrDataInternal.bg|=67108863&this._curAttrData.bg,this._eraseAttrDataInternal}setgLevel(e){return this._charsetService.setgLevel(e),!0}screenAlignmentPattern(){let e=new p.CellData;e.content=4194373,e.fg=this._curAttrData.fg,e.bg=this._curAttrData.bg,this._setCursor(0,0);for(let t=0;t<this._bufferService.rows;++t){let n=this._activeBuffer.ybase+this._activeBuffer.y+t,r=this._activeBuffer.lines.get(n);r&&(r.fill(e),r.isWrapped=!1)}return this._dirtyRowTracker.markAllDirty(),this._setCursor(0,0),!0}requestStatusString(e,t){let n=this._bufferService.buffer,r=this._optionsService.rawOptions;return(e=>(this._coreService.triggerDataEvent(`${a.C0.ESC}${e}${a.C0.ESC}\\`),!0))(e===`"q`?`P1$r${+!!this._curAttrData.isProtected()}"q`:e===`"p`?`P1$r61;1"p`:e===`r`?`P1$r${n.scrollTop+1};${n.scrollBottom+1}r`:e===`m`?`P1$r0m`:e===` q`?`P1$r${{block:2,underline:4,bar:6}[r.cursorStyle]-+!!r.cursorBlink} q`:`P0$r`)}markRangeDirty(e,t){this._dirtyRowTracker.markRangeDirty(e,t)}}t.InputHandler=T;let E=class{constructor(e){this._bufferService=e,this.clearRange()}clearRange(){this.start=this._bufferService.buffer.y,this.end=this._bufferService.buffer.y}markDirty(e){e<this.start?this.start=e:e>this.end&&(this.end=e)}markRangeDirty(e,t){e>t&&(w=e,e=t,t=w),e<this.start&&(this.start=e),t>this.end&&(this.end=t)}markAllDirty(){this.markRangeDirty(0,this._bufferService.rows-1)}};function D(e){return 0<=e&&e<256}E=r([i(0,h.IBufferService)],E)},844:(e,t)=>{function n(e){for(let t of e)t.dispose();e.length=0}Object.defineProperty(t,"__esModule",{value:!0}),t.getDisposeArrayDisposable=t.disposeArray=t.toDisposable=t.MutableDisposable=t.Disposable=void 0,t.Disposable=class{constructor(){this._disposables=[],this._isDisposed=!1}dispose(){this._isDisposed=!0;for(let e of this._disposables)e.dispose();this._disposables.length=0}register(e){return this._disposables.push(e),e}unregister(e){let t=this._disposables.indexOf(e);t!==-1&&this._disposables.splice(t,1)}},t.MutableDisposable=class{constructor(){this._isDisposed=!1}get value(){return this._isDisposed?void 0:this._value}set value(e){this._isDisposed||e===this._value||(this._value?.dispose(),this._value=e)}clear(){this.value=void 0}dispose(){this._isDisposed=!0,this._value?.dispose(),this._value=void 0}},t.toDisposable=function(e){return{dispose:e}},t.disposeArray=n,t.getDisposeArrayDisposable=function(e){return{dispose:()=>n(e)}}},1505:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.FourKeyMap=t.TwoKeyMap=void 0;class n{constructor(){this._data={}}set(e,t,n){this._data[e]||(this._data[e]={}),this._data[e][t]=n}get(e,t){return this._data[e]?this._data[e][t]:void 0}clear(){this._data={}}}t.TwoKeyMap=n,t.FourKeyMap=class{constructor(){this._data=new n}set(e,t,r,i,a){this._data.get(e,t)||this._data.set(e,t,new n),this._data.get(e,t).set(r,i,a)}get(e,t,n,r){return this._data.get(e,t)?.get(n,r)}clear(){this._data.clear()}}},6114:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.isChromeOS=t.isLinux=t.isWindows=t.isIphone=t.isIpad=t.isMac=t.getSafariVersion=t.isSafari=t.isLegacyEdge=t.isFirefox=t.isNode=void 0,t.isNode=typeof process<`u`&&`title`in process;let n=t.isNode?`node`:navigator.userAgent,r=t.isNode?`node`:navigator.platform;t.isFirefox=n.includes(`Firefox`),t.isLegacyEdge=n.includes(`Edge`),t.isSafari=/^((?!chrome|android).)*safari/i.test(n),t.getSafariVersion=function(){if(!t.isSafari)return 0;let e=n.match(/Version\/(\d+)/);return e===null||e.length<2?0:parseInt(e[1])},t.isMac=[`Macintosh`,`MacIntel`,`MacPPC`,`Mac68K`].includes(r),t.isIpad=r===`iPad`,t.isIphone=r===`iPhone`,t.isWindows=[`Windows`,`Win16`,`Win32`,`WinCE`].includes(r),t.isLinux=r.indexOf(`Linux`)>=0,t.isChromeOS=/\bCrOS\b/.test(n)},6106:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SortedList=void 0;let n=0;t.SortedList=class{constructor(e){this._getKey=e,this._array=[]}clear(){this._array.length=0}insert(e){this._array.length===0?this._array.push(e):(n=this._search(this._getKey(e)),this._array.splice(n,0,e))}delete(e){if(this._array.length===0)return!1;let t=this._getKey(e);if(t===void 0||(n=this._search(t),n===-1)||this._getKey(this._array[n])!==t)return!1;do if(this._array[n]===e)return this._array.splice(n,1),!0;while(++n<this._array.length&&this._getKey(this._array[n])===t);return!1}*getKeyIterator(e){if(this._array.length!==0&&(n=this._search(e),!(n<0||n>=this._array.length)&&this._getKey(this._array[n])===e))do yield this._array[n];while(++n<this._array.length&&this._getKey(this._array[n])===e)}forEachByKey(e,t){if(this._array.length!==0&&(n=this._search(e),!(n<0||n>=this._array.length)&&this._getKey(this._array[n])===e))do t(this._array[n]);while(++n<this._array.length&&this._getKey(this._array[n])===e)}values(){return[...this._array].values()}_search(e){let t=0,n=this._array.length-1;for(;n>=t;){let r=t+n>>1,i=this._getKey(this._array[r]);if(i>e)n=r-1;else{if(!(i<e)){for(;r>0&&this._getKey(this._array[r-1])===e;)r--;return r}t=r+1}}return t}}},7226:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.DebouncedIdleTask=t.IdleTaskQueue=t.PriorityTaskQueue=void 0;let r=n(6114);class i{constructor(){this._tasks=[],this._i=0}enqueue(e){this._tasks.push(e),this._start()}flush(){for(;this._i<this._tasks.length;)this._tasks[this._i]()||this._i++;this.clear()}clear(){this._idleCallback&&=(this._cancelCallback(this._idleCallback),void 0),this._i=0,this._tasks.length=0}_start(){this._idleCallback||=this._requestCallback(this._process.bind(this))}_process(e){this._idleCallback=void 0;let t=0,n=0,r=e.timeRemaining(),i=0;for(;this._i<this._tasks.length;){if(t=Date.now(),this._tasks[this._i]()||this._i++,t=Math.max(1,Date.now()-t),n=Math.max(t,n),i=e.timeRemaining(),1.5*n>i)return r-t<-20&&console.warn(`task queue exceeded allotted deadline by ${Math.abs(Math.round(r-t))}ms`),void this._start();r=i}this.clear()}}class a extends i{_requestCallback(e){return setTimeout((()=>e(this._createDeadline(16))))}_cancelCallback(e){clearTimeout(e)}_createDeadline(e){let t=Date.now()+e;return{timeRemaining:()=>Math.max(0,t-Date.now())}}}t.PriorityTaskQueue=a,t.IdleTaskQueue=!r.isNode&&`requestIdleCallback`in window?class extends i{_requestCallback(e){return requestIdleCallback(e)}_cancelCallback(e){cancelIdleCallback(e)}}:a,t.DebouncedIdleTask=class{constructor(){this._queue=new t.IdleTaskQueue}set(e){this._queue.clear(),this._queue.enqueue(e)}flush(){this._queue.flush()}}},9282:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.updateWindowsModeWrappedState=void 0;let r=n(643);t.updateWindowsModeWrappedState=function(e){let t=e.buffer.lines.get(e.buffer.ybase+e.buffer.y-1)?.get(e.cols-1),n=e.buffer.lines.get(e.buffer.ybase+e.buffer.y);n&&t&&(n.isWrapped=t[r.CHAR_DATA_CODE_INDEX]!==r.NULL_CELL_CODE&&t[r.CHAR_DATA_CODE_INDEX]!==r.WHITESPACE_CELL_CODE)}},3734:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ExtendedAttrs=t.AttributeData=void 0;class n{constructor(){this.fg=0,this.bg=0,this.extended=new r}static toColorRGB(e){return[e>>>16&255,e>>>8&255,255&e]}static fromColorRGB(e){return(255&e[0])<<16|(255&e[1])<<8|255&e[2]}clone(){let e=new n;return e.fg=this.fg,e.bg=this.bg,e.extended=this.extended.clone(),e}isInverse(){return 67108864&this.fg}isBold(){return 134217728&this.fg}isUnderline(){return this.hasExtendedAttrs()&&this.extended.underlineStyle!==0?1:268435456&this.fg}isBlink(){return 536870912&this.fg}isInvisible(){return 1073741824&this.fg}isItalic(){return 67108864&this.bg}isDim(){return 134217728&this.bg}isStrikethrough(){return 2147483648&this.fg}isProtected(){return 536870912&this.bg}isOverline(){return 1073741824&this.bg}getFgColorMode(){return 50331648&this.fg}getBgColorMode(){return 50331648&this.bg}isFgRGB(){return(50331648&this.fg)==50331648}isBgRGB(){return(50331648&this.bg)==50331648}isFgPalette(){return(50331648&this.fg)==16777216||(50331648&this.fg)==33554432}isBgPalette(){return(50331648&this.bg)==16777216||(50331648&this.bg)==33554432}isFgDefault(){return(50331648&this.fg)==0}isBgDefault(){return(50331648&this.bg)==0}isAttributeDefault(){return this.fg===0&&this.bg===0}getFgColor(){switch(50331648&this.fg){case 16777216:case 33554432:return 255&this.fg;case 50331648:return 16777215&this.fg;default:return-1}}getBgColor(){switch(50331648&this.bg){case 16777216:case 33554432:return 255&this.bg;case 50331648:return 16777215&this.bg;default:return-1}}hasExtendedAttrs(){return 268435456&this.bg}updateExtended(){this.extended.isEmpty()?this.bg&=-268435457:this.bg|=268435456}getUnderlineColor(){if(268435456&this.bg&&~this.extended.underlineColor)switch(50331648&this.extended.underlineColor){case 16777216:case 33554432:return 255&this.extended.underlineColor;case 50331648:return 16777215&this.extended.underlineColor;default:return this.getFgColor()}return this.getFgColor()}getUnderlineColorMode(){return 268435456&this.bg&&~this.extended.underlineColor?50331648&this.extended.underlineColor:this.getFgColorMode()}isUnderlineColorRGB(){return 268435456&this.bg&&~this.extended.underlineColor?(50331648&this.extended.underlineColor)==50331648:this.isFgRGB()}isUnderlineColorPalette(){return 268435456&this.bg&&~this.extended.underlineColor?(50331648&this.extended.underlineColor)==16777216||(50331648&this.extended.underlineColor)==33554432:this.isFgPalette()}isUnderlineColorDefault(){return 268435456&this.bg&&~this.extended.underlineColor?(50331648&this.extended.underlineColor)==0:this.isFgDefault()}getUnderlineStyle(){return 268435456&this.fg?268435456&this.bg?this.extended.underlineStyle:1:0}getUnderlineVariantOffset(){return this.extended.underlineVariantOffset}}t.AttributeData=n;class r{get ext(){return this._urlId?-469762049&this._ext|this.underlineStyle<<26:this._ext}set ext(e){this._ext=e}get underlineStyle(){return this._urlId?5:(469762048&this._ext)>>26}set underlineStyle(e){this._ext&=-469762049,this._ext|=e<<26&469762048}get underlineColor(){return 67108863&this._ext}set underlineColor(e){this._ext&=-67108864,this._ext|=67108863&e}get urlId(){return this._urlId}set urlId(e){this._urlId=e}get underlineVariantOffset(){let e=(3758096384&this._ext)>>29;return e<0?4294967288^e:e}set underlineVariantOffset(e){this._ext&=536870911,this._ext|=e<<29&3758096384}constructor(e=0,t=0){this._ext=0,this._urlId=0,this._ext=e,this._urlId=t}clone(){return new r(this._ext,this._urlId)}isEmpty(){return this.underlineStyle===0&&this._urlId===0}}t.ExtendedAttrs=r},9092:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Buffer=t.MAX_BUFFER_SIZE=void 0;let r=n(6349),i=n(7226),a=n(3734),o=n(8437),s=n(4634),c=n(511),l=n(643),u=n(4863),d=n(7116);t.MAX_BUFFER_SIZE=4294967295,t.Buffer=class{constructor(e,t,n){this._hasScrollback=e,this._optionsService=t,this._bufferService=n,this.ydisp=0,this.ybase=0,this.y=0,this.x=0,this.tabs={},this.savedY=0,this.savedX=0,this.savedCurAttrData=o.DEFAULT_ATTR_DATA.clone(),this.savedCharset=d.DEFAULT_CHARSET,this.markers=[],this._nullCell=c.CellData.fromCharData([0,l.NULL_CELL_CHAR,l.NULL_CELL_WIDTH,l.NULL_CELL_CODE]),this._whitespaceCell=c.CellData.fromCharData([0,l.WHITESPACE_CELL_CHAR,l.WHITESPACE_CELL_WIDTH,l.WHITESPACE_CELL_CODE]),this._isClearing=!1,this._memoryCleanupQueue=new i.IdleTaskQueue,this._memoryCleanupPosition=0,this._cols=this._bufferService.cols,this._rows=this._bufferService.rows,this.lines=new r.CircularList(this._getCorrectBufferLength(this._rows)),this.scrollTop=0,this.scrollBottom=this._rows-1,this.setupTabStops()}getNullCell(e){return e?(this._nullCell.fg=e.fg,this._nullCell.bg=e.bg,this._nullCell.extended=e.extended):(this._nullCell.fg=0,this._nullCell.bg=0,this._nullCell.extended=new a.ExtendedAttrs),this._nullCell}getWhitespaceCell(e){return e?(this._whitespaceCell.fg=e.fg,this._whitespaceCell.bg=e.bg,this._whitespaceCell.extended=e.extended):(this._whitespaceCell.fg=0,this._whitespaceCell.bg=0,this._whitespaceCell.extended=new a.ExtendedAttrs),this._whitespaceCell}getBlankLine(e,t){return new o.BufferLine(this._bufferService.cols,this.getNullCell(e),t)}get hasScrollback(){return this._hasScrollback&&this.lines.maxLength>this._rows}get isCursorInViewport(){let e=this.ybase+this.y-this.ydisp;return e>=0&&e<this._rows}_getCorrectBufferLength(e){if(!this._hasScrollback)return e;let n=e+this._optionsService.rawOptions.scrollback;return n>t.MAX_BUFFER_SIZE?t.MAX_BUFFER_SIZE:n}fillViewportRows(e){if(this.lines.length===0){e===void 0&&(e=o.DEFAULT_ATTR_DATA);let t=this._rows;for(;t--;)this.lines.push(this.getBlankLine(e))}}clear(){this.ydisp=0,this.ybase=0,this.y=0,this.x=0,this.lines=new r.CircularList(this._getCorrectBufferLength(this._rows)),this.scrollTop=0,this.scrollBottom=this._rows-1,this.setupTabStops()}resize(e,t){let n=this.getNullCell(o.DEFAULT_ATTR_DATA),r=0,i=this._getCorrectBufferLength(t);if(i>this.lines.maxLength&&(this.lines.maxLength=i),this.lines.length>0){if(this._cols<e)for(let t=0;t<this.lines.length;t++)r+=+this.lines.get(t).resize(e,n);let a=0;if(this._rows<t)for(let r=this._rows;r<t;r++)this.lines.length<t+this.ybase&&(this._optionsService.rawOptions.windowsMode||this._optionsService.rawOptions.windowsPty.backend!==void 0||this._optionsService.rawOptions.windowsPty.buildNumber!==void 0?this.lines.push(new o.BufferLine(e,n)):this.ybase>0&&this.lines.length<=this.ybase+this.y+a+1?(this.ybase--,a++,this.ydisp>0&&this.ydisp--):this.lines.push(new o.BufferLine(e,n)));else for(let e=this._rows;e>t;e--)this.lines.length>t+this.ybase&&(this.lines.length>this.ybase+this.y+1?this.lines.pop():(this.ybase++,this.ydisp++));if(i<this.lines.maxLength){let e=this.lines.length-i;e>0&&(this.lines.trimStart(e),this.ybase=Math.max(this.ybase-e,0),this.ydisp=Math.max(this.ydisp-e,0),this.savedY=Math.max(this.savedY-e,0)),this.lines.maxLength=i}this.x=Math.min(this.x,e-1),this.y=Math.min(this.y,t-1),a&&(this.y+=a),this.savedX=Math.min(this.savedX,e-1),this.scrollTop=0}if(this.scrollBottom=t-1,this._isReflowEnabled&&(this._reflow(e,t),this._cols>e))for(let t=0;t<this.lines.length;t++)r+=+this.lines.get(t).resize(e,n);this._cols=e,this._rows=t,this._memoryCleanupQueue.clear(),r>.1*this.lines.length&&(this._memoryCleanupPosition=0,this._memoryCleanupQueue.enqueue((()=>this._batchedMemoryCleanup())))}_batchedMemoryCleanup(){let e=!0;this._memoryCleanupPosition>=this.lines.length&&(this._memoryCleanupPosition=0,e=!1);let t=0;for(;this._memoryCleanupPosition<this.lines.length;)if(t+=this.lines.get(this._memoryCleanupPosition++).cleanupMemory(),t>100)return!0;return e}get _isReflowEnabled(){let e=this._optionsService.rawOptions.windowsPty;return e&&e.buildNumber?this._hasScrollback&&e.backend===`conpty`&&e.buildNumber>=21376:this._hasScrollback&&!this._optionsService.rawOptions.windowsMode}_reflow(e,t){this._cols!==e&&(e>this._cols?this._reflowLarger(e,t):this._reflowSmaller(e,t))}_reflowLarger(e,t){let n=(0,s.reflowLargerGetLinesToRemove)(this.lines,this._cols,e,this.ybase+this.y,this.getNullCell(o.DEFAULT_ATTR_DATA));if(n.length>0){let r=(0,s.reflowLargerCreateNewLayout)(this.lines,n);(0,s.reflowLargerApplyNewLayout)(this.lines,r.layout),this._reflowLargerAdjustViewport(e,t,r.countRemoved)}}_reflowLargerAdjustViewport(e,t,n){let r=this.getNullCell(o.DEFAULT_ATTR_DATA),i=n;for(;i-- >0;)this.ybase===0?(this.y>0&&this.y--,this.lines.length<t&&this.lines.push(new o.BufferLine(e,r))):(this.ydisp===this.ybase&&this.ydisp--,this.ybase--);this.savedY=Math.max(this.savedY-n,0)}_reflowSmaller(e,t){let n=this.getNullCell(o.DEFAULT_ATTR_DATA),r=[],i=0;for(let a=this.lines.length-1;a>=0;a--){let c=this.lines.get(a);if(!c||!c.isWrapped&&c.getTrimmedLength()<=e)continue;let l=[c];for(;c.isWrapped&&a>0;)c=this.lines.get(--a),l.unshift(c);let u=this.ybase+this.y;if(u>=a&&u<a+l.length)continue;let d=l[l.length-1].getTrimmedLength(),f=(0,s.reflowSmallerGetNewLineLengths)(l,this._cols,e),p=f.length-l.length,m;m=this.ybase===0&&this.y!==this.lines.length-1?Math.max(0,this.y-this.lines.maxLength+p):Math.max(0,this.lines.length-this.lines.maxLength+p);let h=[];for(let e=0;e<p;e++){let e=this.getBlankLine(o.DEFAULT_ATTR_DATA,!0);h.push(e)}h.length>0&&(r.push({start:a+l.length+i,newLines:h}),i+=h.length),l.push(...h);let g=f.length-1,_=f[g];_===0&&(g--,_=f[g]);let v=l.length-p-1,y=d;for(;v>=0;){let e=Math.min(y,_);if(l[g]===void 0)break;if(l[g].copyCellsFrom(l[v],y-e,_-e,e,!0),_-=e,_===0&&(g--,_=f[g]),y-=e,y===0){v--;let e=Math.max(v,0);y=(0,s.getWrappedLineTrimmedLength)(l,e,this._cols)}}for(let t=0;t<l.length;t++)f[t]<e&&l[t].setCell(f[t],n);let b=p-m;for(;b-- >0;)this.ybase===0?this.y<t-1?(this.y++,this.lines.pop()):(this.ybase++,this.ydisp++):this.ybase<Math.min(this.lines.maxLength,this.lines.length+i)-t&&(this.ybase===this.ydisp&&this.ydisp++,this.ybase++);this.savedY=Math.min(this.savedY+p,this.ybase+t-1)}if(r.length>0){let e=[],t=[];for(let e=0;e<this.lines.length;e++)t.push(this.lines.get(e));let n=this.lines.length,a=n-1,o=0,s=r[o];this.lines.length=Math.min(this.lines.maxLength,this.lines.length+i);let c=0;for(let l=Math.min(this.lines.maxLength-1,n+i-1);l>=0;l--)if(s&&s.start>a+c){for(let e=s.newLines.length-1;e>=0;e--)this.lines.set(l--,s.newLines[e]);l++,e.push({index:a+1,amount:s.newLines.length}),c+=s.newLines.length,s=r[++o]}else this.lines.set(l,t[a--]);let l=0;for(let t=e.length-1;t>=0;t--)e[t].index+=l,this.lines.onInsertEmitter.fire(e[t]),l+=e[t].amount;let u=Math.max(0,n+i-this.lines.maxLength);u>0&&this.lines.onTrimEmitter.fire(u)}}translateBufferLineToString(e,t,n=0,r){let i=this.lines.get(e);return i?i.translateToString(t,n,r):``}getWrappedRangeForLine(e){let t=e,n=e;for(;t>0&&this.lines.get(t).isWrapped;)t--;for(;n+1<this.lines.length&&this.lines.get(n+1).isWrapped;)n++;return{first:t,last:n}}setupTabStops(e){for(e==null?(this.tabs={},e=0):this.tabs[e]||(e=this.prevStop(e));e<this._cols;e+=this._optionsService.rawOptions.tabStopWidth)this.tabs[e]=!0}prevStop(e){for(e??=this.x;!this.tabs[--e]&&e>0;);return e>=this._cols?this._cols-1:e<0?0:e}nextStop(e){for(e??=this.x;!this.tabs[++e]&&e<this._cols;);return e>=this._cols?this._cols-1:e<0?0:e}clearMarkers(e){this._isClearing=!0;for(let t=0;t<this.markers.length;t++)this.markers[t].line===e&&(this.markers[t].dispose(),this.markers.splice(t--,1));this._isClearing=!1}clearAllMarkers(){this._isClearing=!0;for(let e=0;e<this.markers.length;e++)this.markers[e].dispose(),this.markers.splice(e--,1);this._isClearing=!1}addMarker(e){let t=new u.Marker(e);return this.markers.push(t),t.register(this.lines.onTrim((e=>{t.line-=e,t.line<0&&t.dispose()}))),t.register(this.lines.onInsert((e=>{t.line>=e.index&&(t.line+=e.amount)}))),t.register(this.lines.onDelete((e=>{t.line>=e.index&&t.line<e.index+e.amount&&t.dispose(),t.line>e.index&&(t.line-=e.amount)}))),t.register(t.onDispose((()=>this._removeMarker(t)))),t}_removeMarker(e){this._isClearing||this.markers.splice(this.markers.indexOf(e),1)}}},8437:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.BufferLine=t.DEFAULT_ATTR_DATA=void 0;let r=n(3734),i=n(511),a=n(643),o=n(482);t.DEFAULT_ATTR_DATA=Object.freeze(new r.AttributeData);let s=0;class c{constructor(e,t,n=!1){this.isWrapped=n,this._combined={},this._extendedAttrs={},this._data=new Uint32Array(3*e);let r=t||i.CellData.fromCharData([0,a.NULL_CELL_CHAR,a.NULL_CELL_WIDTH,a.NULL_CELL_CODE]);for(let t=0;t<e;++t)this.setCell(t,r);this.length=e}get(e){let t=this._data[3*e+0],n=2097151&t;return[this._data[3*e+1],2097152&t?this._combined[e]:n?(0,o.stringFromCodePoint)(n):``,t>>22,2097152&t?this._combined[e].charCodeAt(this._combined[e].length-1):n]}set(e,t){this._data[3*e+1]=t[a.CHAR_DATA_ATTR_INDEX],t[a.CHAR_DATA_CHAR_INDEX].length>1?(this._combined[e]=t[1],this._data[3*e+0]=2097152|e|t[a.CHAR_DATA_WIDTH_INDEX]<<22):this._data[3*e+0]=t[a.CHAR_DATA_CHAR_INDEX].charCodeAt(0)|t[a.CHAR_DATA_WIDTH_INDEX]<<22}getWidth(e){return this._data[3*e+0]>>22}hasWidth(e){return 12582912&this._data[3*e+0]}getFg(e){return this._data[3*e+1]}getBg(e){return this._data[3*e+2]}hasContent(e){return 4194303&this._data[3*e+0]}getCodePoint(e){let t=this._data[3*e+0];return 2097152&t?this._combined[e].charCodeAt(this._combined[e].length-1):2097151&t}isCombined(e){return 2097152&this._data[3*e+0]}getString(e){let t=this._data[3*e+0];return 2097152&t?this._combined[e]:2097151&t?(0,o.stringFromCodePoint)(2097151&t):``}isProtected(e){return 536870912&this._data[3*e+2]}loadCell(e,t){return s=3*e,t.content=this._data[s+0],t.fg=this._data[s+1],t.bg=this._data[s+2],2097152&t.content&&(t.combinedData=this._combined[e]),268435456&t.bg&&(t.extended=this._extendedAttrs[e]),t}setCell(e,t){2097152&t.content&&(this._combined[e]=t.combinedData),268435456&t.bg&&(this._extendedAttrs[e]=t.extended),this._data[3*e+0]=t.content,this._data[3*e+1]=t.fg,this._data[3*e+2]=t.bg}setCellFromCodepoint(e,t,n,r){268435456&r.bg&&(this._extendedAttrs[e]=r.extended),this._data[3*e+0]=t|n<<22,this._data[3*e+1]=r.fg,this._data[3*e+2]=r.bg}addCodepointToCell(e,t,n){let r=this._data[3*e+0];2097152&r?this._combined[e]+=(0,o.stringFromCodePoint)(t):2097151&r?(this._combined[e]=(0,o.stringFromCodePoint)(2097151&r)+(0,o.stringFromCodePoint)(t),r&=-2097152,r|=2097152):r=t|1<<22,n&&(r&=-12582913,r|=n<<22),this._data[3*e+0]=r}insertCells(e,t,n){if((e%=this.length)&&this.getWidth(e-1)===2&&this.setCellFromCodepoint(e-1,0,1,n),t<this.length-e){let r=new i.CellData;for(let n=this.length-e-t-1;n>=0;--n)this.setCell(e+t+n,this.loadCell(e+n,r));for(let r=0;r<t;++r)this.setCell(e+r,n)}else for(let t=e;t<this.length;++t)this.setCell(t,n);this.getWidth(this.length-1)===2&&this.setCellFromCodepoint(this.length-1,0,1,n)}deleteCells(e,t,n){if(e%=this.length,t<this.length-e){let r=new i.CellData;for(let n=0;n<this.length-e-t;++n)this.setCell(e+n,this.loadCell(e+t+n,r));for(let e=this.length-t;e<this.length;++e)this.setCell(e,n)}else for(let t=e;t<this.length;++t)this.setCell(t,n);e&&this.getWidth(e-1)===2&&this.setCellFromCodepoint(e-1,0,1,n),this.getWidth(e)!==0||this.hasContent(e)||this.setCellFromCodepoint(e,0,1,n)}replaceCells(e,t,n,r=!1){if(r)for(e&&this.getWidth(e-1)===2&&!this.isProtected(e-1)&&this.setCellFromCodepoint(e-1,0,1,n),t<this.length&&this.getWidth(t-1)===2&&!this.isProtected(t)&&this.setCellFromCodepoint(t,0,1,n);e<t&&e<this.length;)this.isProtected(e)||this.setCell(e,n),e++;else for(e&&this.getWidth(e-1)===2&&this.setCellFromCodepoint(e-1,0,1,n),t<this.length&&this.getWidth(t-1)===2&&this.setCellFromCodepoint(t,0,1,n);e<t&&e<this.length;)this.setCell(e++,n)}resize(e,t){if(e===this.length)return 4*this._data.length*2<this._data.buffer.byteLength;let n=3*e;if(e>this.length){if(this._data.buffer.byteLength>=4*n)this._data=new Uint32Array(this._data.buffer,0,n);else{let e=new Uint32Array(n);e.set(this._data),this._data=e}for(let n=this.length;n<e;++n)this.setCell(n,t)}else{this._data=this._data.subarray(0,n);let t=Object.keys(this._combined);for(let n=0;n<t.length;n++){let r=parseInt(t[n],10);r>=e&&delete this._combined[r]}let r=Object.keys(this._extendedAttrs);for(let t=0;t<r.length;t++){let n=parseInt(r[t],10);n>=e&&delete this._extendedAttrs[n]}}return this.length=e,4*n*2<this._data.buffer.byteLength}cleanupMemory(){if(4*this._data.length*2<this._data.buffer.byteLength){let e=new Uint32Array(this._data.length);return e.set(this._data),this._data=e,1}return 0}fill(e,t=!1){if(t)for(let t=0;t<this.length;++t)this.isProtected(t)||this.setCell(t,e);else{this._combined={},this._extendedAttrs={};for(let t=0;t<this.length;++t)this.setCell(t,e)}}copyFrom(e){this.length===e.length?this._data.set(e._data):this._data=new Uint32Array(e._data),this.length=e.length,this._combined={};for(let t in e._combined)this._combined[t]=e._combined[t];this._extendedAttrs={};for(let t in e._extendedAttrs)this._extendedAttrs[t]=e._extendedAttrs[t];this.isWrapped=e.isWrapped}clone(){let e=new c(0);e._data=new Uint32Array(this._data),e.length=this.length;for(let t in this._combined)e._combined[t]=this._combined[t];for(let t in this._extendedAttrs)e._extendedAttrs[t]=this._extendedAttrs[t];return e.isWrapped=this.isWrapped,e}getTrimmedLength(){for(let e=this.length-1;e>=0;--e)if(4194303&this._data[3*e+0])return e+(this._data[3*e+0]>>22);return 0}getNoBgTrimmedLength(){for(let e=this.length-1;e>=0;--e)if(4194303&this._data[3*e+0]||50331648&this._data[3*e+2])return e+(this._data[3*e+0]>>22);return 0}copyCellsFrom(e,t,n,r,i){let a=e._data;if(i)for(let i=r-1;i>=0;i--){for(let e=0;e<3;e++)this._data[3*(n+i)+e]=a[3*(t+i)+e];268435456&a[3*(t+i)+2]&&(this._extendedAttrs[n+i]=e._extendedAttrs[t+i])}else for(let i=0;i<r;i++){for(let e=0;e<3;e++)this._data[3*(n+i)+e]=a[3*(t+i)+e];268435456&a[3*(t+i)+2]&&(this._extendedAttrs[n+i]=e._extendedAttrs[t+i])}let o=Object.keys(e._combined);for(let r=0;r<o.length;r++){let i=parseInt(o[r],10);i>=t&&(this._combined[i-t+n]=e._combined[i])}}translateToString(e,t,n,r){t??=0,n??=this.length,e&&(n=Math.min(n,this.getTrimmedLength())),r&&(r.length=0);let i=``;for(;t<n;){let e=this._data[3*t+0],n=2097151&e,s=2097152&e?this._combined[t]:n?(0,o.stringFromCodePoint)(n):a.WHITESPACE_CELL_CHAR;if(i+=s,r)for(let e=0;e<s.length;++e)r.push(t);t+=e>>22||1}return r&&r.push(t),i}}t.BufferLine=c},4841:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getRangeLength=void 0,t.getRangeLength=function(e,t){if(e.start.y>e.end.y)throw Error(`Buffer range end (${e.end.x}, ${e.end.y}) cannot be before start (${e.start.x}, ${e.start.y})`);return t*(e.end.y-e.start.y)+(e.end.x-e.start.x+1)}},4634:(e,t)=>{function n(e,t,n){if(t===e.length-1)return e[t].getTrimmedLength();let r=!e[t].hasContent(n-1)&&e[t].getWidth(n-1)===1,i=e[t+1].getWidth(0)===2;return r&&i?n-1:n}Object.defineProperty(t,"__esModule",{value:!0}),t.getWrappedLineTrimmedLength=t.reflowSmallerGetNewLineLengths=t.reflowLargerApplyNewLayout=t.reflowLargerCreateNewLayout=t.reflowLargerGetLinesToRemove=void 0,t.reflowLargerGetLinesToRemove=function(e,t,r,i,a){let o=[];for(let s=0;s<e.length-1;s++){let c=s,l=e.get(++c);if(!l.isWrapped)continue;let u=[e.get(s)];for(;c<e.length&&l.isWrapped;)u.push(l),l=e.get(++c);if(i>=s&&i<c){s+=u.length-1;continue}let d=0,f=n(u,d,t),p=1,m=0;for(;p<u.length;){let e=n(u,p,t),i=e-m,o=r-f,s=Math.min(i,o);u[d].copyCellsFrom(u[p],m,f,s,!1),f+=s,f===r&&(d++,f=0),m+=s,m===e&&(p++,m=0),f===0&&d!==0&&u[d-1].getWidth(r-1)===2&&(u[d].copyCellsFrom(u[d-1],r-1,f++,1,!1),u[d-1].setCell(r-1,a))}u[d].replaceCells(f,r,a);let h=0;for(let e=u.length-1;e>0&&(e>d||u[e].getTrimmedLength()===0);e--)h++;h>0&&(o.push(s+u.length-h),o.push(h)),s+=u.length-1}return o},t.reflowLargerCreateNewLayout=function(e,t){let n=[],r=0,i=t[r],a=0;for(let o=0;o<e.length;o++)if(i===o){let n=t[++r];e.onDeleteEmitter.fire({index:o-a,amount:n}),o+=n-1,a+=n,i=t[++r]}else n.push(o);return{layout:n,countRemoved:a}},t.reflowLargerApplyNewLayout=function(e,t){let n=[];for(let r=0;r<t.length;r++)n.push(e.get(t[r]));for(let t=0;t<n.length;t++)e.set(t,n[t]);e.length=t.length},t.reflowSmallerGetNewLineLengths=function(e,t,r){let i=[],a=e.map(((r,i)=>n(e,i,t))).reduce(((e,t)=>e+t)),o=0,s=0,c=0;for(;c<a;){if(a-c<r){i.push(a-c);break}o+=r;let l=n(e,s,t);o>l&&(o-=l,s++);let u=e[s].getWidth(o-1)===2;u&&o--;let d=u?r-1:r;i.push(d),c+=d}return i},t.getWrappedLineTrimmedLength=n},5295:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.BufferSet=void 0;let r=n(8460),i=n(844),a=n(9092);class o extends i.Disposable{constructor(e,t){super(),this._optionsService=e,this._bufferService=t,this._onBufferActivate=this.register(new r.EventEmitter),this.onBufferActivate=this._onBufferActivate.event,this.reset(),this.register(this._optionsService.onSpecificOptionChange(`scrollback`,(()=>this.resize(this._bufferService.cols,this._bufferService.rows)))),this.register(this._optionsService.onSpecificOptionChange(`tabStopWidth`,(()=>this.setupTabStops())))}reset(){this._normal=new a.Buffer(!0,this._optionsService,this._bufferService),this._normal.fillViewportRows(),this._alt=new a.Buffer(!1,this._optionsService,this._bufferService),this._activeBuffer=this._normal,this._onBufferActivate.fire({activeBuffer:this._normal,inactiveBuffer:this._alt}),this.setupTabStops()}get alt(){return this._alt}get active(){return this._activeBuffer}get normal(){return this._normal}activateNormalBuffer(){this._activeBuffer!==this._normal&&(this._normal.x=this._alt.x,this._normal.y=this._alt.y,this._alt.clearAllMarkers(),this._alt.clear(),this._activeBuffer=this._normal,this._onBufferActivate.fire({activeBuffer:this._normal,inactiveBuffer:this._alt}))}activateAltBuffer(e){this._activeBuffer!==this._alt&&(this._alt.fillViewportRows(e),this._alt.x=this._normal.x,this._alt.y=this._normal.y,this._activeBuffer=this._alt,this._onBufferActivate.fire({activeBuffer:this._alt,inactiveBuffer:this._normal}))}resize(e,t){this._normal.resize(e,t),this._alt.resize(e,t),this.setupTabStops(e)}setupTabStops(e){this._normal.setupTabStops(e),this._alt.setupTabStops(e)}}t.BufferSet=o},511:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.CellData=void 0;let r=n(482),i=n(643),a=n(3734);class o extends a.AttributeData{constructor(){super(...arguments),this.content=0,this.fg=0,this.bg=0,this.extended=new a.ExtendedAttrs,this.combinedData=``}static fromCharData(e){let t=new o;return t.setFromCharData(e),t}isCombined(){return 2097152&this.content}getWidth(){return this.content>>22}getChars(){return 2097152&this.content?this.combinedData:2097151&this.content?(0,r.stringFromCodePoint)(2097151&this.content):``}getCode(){return this.isCombined()?this.combinedData.charCodeAt(this.combinedData.length-1):2097151&this.content}setFromCharData(e){this.fg=e[i.CHAR_DATA_ATTR_INDEX],this.bg=0;let t=!1;if(e[i.CHAR_DATA_CHAR_INDEX].length>2)t=!0;else if(e[i.CHAR_DATA_CHAR_INDEX].length===2){let n=e[i.CHAR_DATA_CHAR_INDEX].charCodeAt(0);if(55296<=n&&n<=56319){let r=e[i.CHAR_DATA_CHAR_INDEX].charCodeAt(1);56320<=r&&r<=57343?this.content=1024*(n-55296)+r-56320+65536|e[i.CHAR_DATA_WIDTH_INDEX]<<22:t=!0}else t=!0}else this.content=e[i.CHAR_DATA_CHAR_INDEX].charCodeAt(0)|e[i.CHAR_DATA_WIDTH_INDEX]<<22;t&&(this.combinedData=e[i.CHAR_DATA_CHAR_INDEX],this.content=2097152|e[i.CHAR_DATA_WIDTH_INDEX]<<22)}getAsCharData(){return[this.fg,this.getChars(),this.getWidth(),this.getCode()]}}t.CellData=o},643:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WHITESPACE_CELL_CODE=t.WHITESPACE_CELL_WIDTH=t.WHITESPACE_CELL_CHAR=t.NULL_CELL_CODE=t.NULL_CELL_WIDTH=t.NULL_CELL_CHAR=t.CHAR_DATA_CODE_INDEX=t.CHAR_DATA_WIDTH_INDEX=t.CHAR_DATA_CHAR_INDEX=t.CHAR_DATA_ATTR_INDEX=t.DEFAULT_EXT=t.DEFAULT_ATTR=t.DEFAULT_COLOR=void 0,t.DEFAULT_COLOR=0,t.DEFAULT_ATTR=256|t.DEFAULT_COLOR<<9,t.DEFAULT_EXT=0,t.CHAR_DATA_ATTR_INDEX=0,t.CHAR_DATA_CHAR_INDEX=1,t.CHAR_DATA_WIDTH_INDEX=2,t.CHAR_DATA_CODE_INDEX=3,t.NULL_CELL_CHAR=``,t.NULL_CELL_WIDTH=1,t.NULL_CELL_CODE=0,t.WHITESPACE_CELL_CHAR=` `,t.WHITESPACE_CELL_WIDTH=1,t.WHITESPACE_CELL_CODE=32},4863:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Marker=void 0;let r=n(8460),i=n(844);class a{get id(){return this._id}constructor(e){this.line=e,this.isDisposed=!1,this._disposables=[],this._id=a._nextId++,this._onDispose=this.register(new r.EventEmitter),this.onDispose=this._onDispose.event}dispose(){this.isDisposed||(this.isDisposed=!0,this.line=-1,this._onDispose.fire(),(0,i.disposeArray)(this._disposables),this._disposables.length=0)}register(e){return this._disposables.push(e),e}}t.Marker=a,a._nextId=1},7116:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.DEFAULT_CHARSET=t.CHARSETS=void 0,t.CHARSETS={},t.DEFAULT_CHARSET=t.CHARSETS.B,t.CHARSETS[0]={"`":`◆`,a:`▒`,b:`␉`,c:`␌`,d:`␍`,e:`␊`,f:`°`,g:`±`,h:``,i:`␋`,j:`┘`,k:`┐`,l:`┌`,m:`└`,n:`┼`,o:`⎺`,p:`⎻`,q:`─`,r:`⎼`,s:`⎽`,t:`├`,u:`┤`,v:`┴`,w:`┬`,x:`│`,y:`≤`,z:`≥`,"{":`π`,"|":`≠`,"}":`£`,"~":`·`},t.CHARSETS.A={"#":`£`},t.CHARSETS.B=void 0,t.CHARSETS[4]={"#":`£`,"@":`¾`,"[":`ij`,"\\":`½`,"]":`|`,"{":`¨`,"|":`f`,"}":`¼`,"~":`´`},t.CHARSETS.C=t.CHARSETS[5]={"[":`Ä`,"\\":`Ö`,"]":`Å`,"^":`Ü`,"`":`é`,"{":`ä`,"|":`ö`,"}":`å`,"~":`ü`},t.CHARSETS.R={"#":`£`,"@":`à`,"[":`°`,"\\":`ç`,"]":`§`,"{":`é`,"|":`ù`,"}":`è`,"~":`¨`},t.CHARSETS.Q={"@":`à`,"[":`â`,"\\":`ç`,"]":`ê`,"^":`î`,"`":`ô`,"{":`é`,"|":`ù`,"}":`è`,"~":`û`},t.CHARSETS.K={"@":`§`,"[":`Ä`,"\\":`Ö`,"]":`Ü`,"{":`ä`,"|":`ö`,"}":`ü`,"~":`ß`},t.CHARSETS.Y={"#":`£`,"@":`§`,"[":`°`,"\\":`ç`,"]":`é`,"`":`ù`,"{":`à`,"|":`ò`,"}":`è`,"~":`ì`},t.CHARSETS.E=t.CHARSETS[6]={"@":`Ä`,"[":`Æ`,"\\":`Ø`,"]":`Å`,"^":`Ü`,"`":`ä`,"{":`æ`,"|":`ø`,"}":`å`,"~":`ü`},t.CHARSETS.Z={"#":`£`,"@":`§`,"[":`¡`,"\\":`Ñ`,"]":`¿`,"{":`°`,"|":`ñ`,"}":`ç`},t.CHARSETS.H=t.CHARSETS[7]={"@":`É`,"[":`Ä`,"\\":`Ö`,"]":`Å`,"^":`Ü`,"`":`é`,"{":`ä`,"|":`ö`,"}":`å`,"~":`ü`},t.CHARSETS[`=`]={"#":`ù`,"@":`à`,"[":`é`,"\\":`ç`,"]":`ê`,"^":`î`,_:`è`,"`":`ô`,"{":`ä`,"|":`ö`,"}":`ü`,"~":`û`}},2584:(e,t)=>{var n,r,i;Object.defineProperty(t,"__esModule",{value:!0}),t.C1_ESCAPED=t.C1=t.C0=void 0,function(e){e.NUL=`\0`,e.SOH=``,e.STX=``,e.ETX=``,e.EOT=``,e.ENQ=``,e.ACK=``,e.BEL=`\x07`,e.BS=`\b`,e.HT=` `,e.LF=`
|
|
370
370
|
`,e.VT=`\v`,e.FF=`\f`,e.CR=`\r`,e.SO=``,e.SI=``,e.DLE=``,e.DC1=``,e.DC2=``,e.DC3=``,e.DC4=``,e.NAK=``,e.SYN=``,e.ETB=``,e.CAN=``,e.EM=``,e.SUB=``,e.ESC=`\x1B`,e.FS=``,e.GS=``,e.RS=``,e.US=``,e.SP=` `,e.DEL=``}(n||(t.C0=n={})),function(e){e.PAD=``,e.HOP=``,e.BPH=``,e.NBH=``,e.IND=``,e.NEL=`
`,e.SSA=``,e.ESA=``,e.HTS=``,e.HTJ=``,e.VTS=``,e.PLD=``,e.PLU=``,e.RI=``,e.SS2=``,e.SS3=``,e.DCS=``,e.PU1=``,e.PU2=``,e.STS=``,e.CCH=``,e.MW=``,e.SPA=``,e.EPA=``,e.SOS=``,e.SGCI=``,e.SCI=``,e.CSI=``,e.ST=``,e.OSC=``,e.PM=``,e.APC=``}(r||(t.C1=r={})),function(e){e.ST=`${n.ESC}\\`}(i||(t.C1_ESCAPED=i={}))},7399:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.evaluateKeyboardEvent=void 0;let r=n(2584),i={48:[`0`,`)`],49:[`1`,`!`],50:[`2`,`@`],51:[`3`,`#`],52:[`4`,`$`],53:[`5`,`%`],54:[`6`,`^`],55:[`7`,`&`],56:[`8`,`*`],57:[`9`,`(`],186:[`;`,`:`],187:[`=`,`+`],188:[`,`,`<`],189:[`-`,`_`],190:[`.`,`>`],191:[`/`,`?`],192:["`",`~`],219:[`[`,`{`],220:[`\\`,`|`],221:[`]`,`}`],222:[`'`,`"`]};t.evaluateKeyboardEvent=function(e,t,n,a){let o={type:0,cancel:!1,key:void 0},s=!!e.shiftKey|(e.altKey?2:0)|(e.ctrlKey?4:0)|(e.metaKey?8:0);switch(e.keyCode){case 0:e.key===`UIKeyInputUpArrow`?o.key=t?r.C0.ESC+`OA`:r.C0.ESC+`[A`:e.key===`UIKeyInputLeftArrow`?o.key=t?r.C0.ESC+`OD`:r.C0.ESC+`[D`:e.key===`UIKeyInputRightArrow`?o.key=t?r.C0.ESC+`OC`:r.C0.ESC+`[C`:e.key===`UIKeyInputDownArrow`&&(o.key=t?r.C0.ESC+`OB`:r.C0.ESC+`[B`);break;case 8:o.key=e.ctrlKey?`\b`:r.C0.DEL,e.altKey&&(o.key=r.C0.ESC+o.key);break;case 9:if(e.shiftKey){o.key=r.C0.ESC+`[Z`;break}o.key=r.C0.HT,o.cancel=!0;break;case 13:o.key=e.altKey?r.C0.ESC+r.C0.CR:r.C0.CR,o.cancel=!0;break;case 27:o.key=r.C0.ESC,e.altKey&&(o.key=r.C0.ESC+r.C0.ESC),o.cancel=!0;break;case 37:if(e.metaKey)break;s?(o.key=r.C0.ESC+`[1;`+(s+1)+`D`,o.key===r.C0.ESC+`[1;3D`&&(o.key=r.C0.ESC+(n?`b`:`[1;5D`))):o.key=t?r.C0.ESC+`OD`:r.C0.ESC+`[D`;break;case 39:if(e.metaKey)break;s?(o.key=r.C0.ESC+`[1;`+(s+1)+`C`,o.key===r.C0.ESC+`[1;3C`&&(o.key=r.C0.ESC+(n?`f`:`[1;5C`))):o.key=t?r.C0.ESC+`OC`:r.C0.ESC+`[C`;break;case 38:if(e.metaKey)break;s?(o.key=r.C0.ESC+`[1;`+(s+1)+`A`,n||o.key!==r.C0.ESC+`[1;3A`||(o.key=r.C0.ESC+`[1;5A`)):o.key=t?r.C0.ESC+`OA`:r.C0.ESC+`[A`;break;case 40:if(e.metaKey)break;s?(o.key=r.C0.ESC+`[1;`+(s+1)+`B`,n||o.key!==r.C0.ESC+`[1;3B`||(o.key=r.C0.ESC+`[1;5B`)):o.key=t?r.C0.ESC+`OB`:r.C0.ESC+`[B`;break;case 45:e.shiftKey||e.ctrlKey||(o.key=r.C0.ESC+`[2~`);break;case 46:o.key=s?r.C0.ESC+`[3;`+(s+1)+`~`:r.C0.ESC+`[3~`;break;case 36:o.key=s?r.C0.ESC+`[1;`+(s+1)+`H`:t?r.C0.ESC+`OH`:r.C0.ESC+`[H`;break;case 35:o.key=s?r.C0.ESC+`[1;`+(s+1)+`F`:t?r.C0.ESC+`OF`:r.C0.ESC+`[F`;break;case 33:e.shiftKey?o.type=2:e.ctrlKey?o.key=r.C0.ESC+`[5;`+(s+1)+`~`:o.key=r.C0.ESC+`[5~`;break;case 34:e.shiftKey?o.type=3:e.ctrlKey?o.key=r.C0.ESC+`[6;`+(s+1)+`~`:o.key=r.C0.ESC+`[6~`;break;case 112:o.key=s?r.C0.ESC+`[1;`+(s+1)+`P`:r.C0.ESC+`OP`;break;case 113:o.key=s?r.C0.ESC+`[1;`+(s+1)+`Q`:r.C0.ESC+`OQ`;break;case 114:o.key=s?r.C0.ESC+`[1;`+(s+1)+`R`:r.C0.ESC+`OR`;break;case 115:o.key=s?r.C0.ESC+`[1;`+(s+1)+`S`:r.C0.ESC+`OS`;break;case 116:o.key=s?r.C0.ESC+`[15;`+(s+1)+`~`:r.C0.ESC+`[15~`;break;case 117:o.key=s?r.C0.ESC+`[17;`+(s+1)+`~`:r.C0.ESC+`[17~`;break;case 118:o.key=s?r.C0.ESC+`[18;`+(s+1)+`~`:r.C0.ESC+`[18~`;break;case 119:o.key=s?r.C0.ESC+`[19;`+(s+1)+`~`:r.C0.ESC+`[19~`;break;case 120:o.key=s?r.C0.ESC+`[20;`+(s+1)+`~`:r.C0.ESC+`[20~`;break;case 121:o.key=s?r.C0.ESC+`[21;`+(s+1)+`~`:r.C0.ESC+`[21~`;break;case 122:o.key=s?r.C0.ESC+`[23;`+(s+1)+`~`:r.C0.ESC+`[23~`;break;case 123:o.key=s?r.C0.ESC+`[24;`+(s+1)+`~`:r.C0.ESC+`[24~`;break;default:if(!e.ctrlKey||e.shiftKey||e.altKey||e.metaKey)if(n&&!a||!e.altKey||e.metaKey)!n||e.altKey||e.ctrlKey||e.shiftKey||!e.metaKey?e.key&&!e.ctrlKey&&!e.altKey&&!e.metaKey&&e.keyCode>=48&&e.key.length===1?o.key=e.key:e.key&&e.ctrlKey&&(e.key===`_`&&(o.key=r.C0.US),e.key===`@`&&(o.key=r.C0.NUL)):e.keyCode===65&&(o.type=1);else{let t=i[e.keyCode]?.[+!!e.shiftKey];if(t)o.key=r.C0.ESC+t;else if(e.keyCode>=65&&e.keyCode<=90){let t=e.ctrlKey?e.keyCode-64:e.keyCode+32,n=String.fromCharCode(t);e.shiftKey&&(n=n.toUpperCase()),o.key=r.C0.ESC+n}else if(e.keyCode===32)o.key=r.C0.ESC+(e.ctrlKey?r.C0.NUL:` `);else if(e.key===`Dead`&&e.code.startsWith(`Key`)){let t=e.code.slice(3,4);e.shiftKey||(t=t.toLowerCase()),o.key=r.C0.ESC+t,o.cancel=!0}}else e.keyCode>=65&&e.keyCode<=90?o.key=String.fromCharCode(e.keyCode-64):e.keyCode===32?o.key=r.C0.NUL:e.keyCode>=51&&e.keyCode<=55?o.key=String.fromCharCode(e.keyCode-51+27):e.keyCode===56?o.key=r.C0.DEL:e.keyCode===219?o.key=r.C0.ESC:e.keyCode===220?o.key=r.C0.FS:e.keyCode===221&&(o.key=r.C0.GS)}return o}},482:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Utf8ToUtf32=t.StringToUtf32=t.utf32ToString=t.stringFromCodePoint=void 0,t.stringFromCodePoint=function(e){return e>65535?(e-=65536,String.fromCharCode(55296+(e>>10))+String.fromCharCode(e%1024+56320)):String.fromCharCode(e)},t.utf32ToString=function(e,t=0,n=e.length){let r=``;for(let i=t;i<n;++i){let t=e[i];t>65535?(t-=65536,r+=String.fromCharCode(55296+(t>>10))+String.fromCharCode(t%1024+56320)):r+=String.fromCharCode(t)}return r},t.StringToUtf32=class{constructor(){this._interim=0}clear(){this._interim=0}decode(e,t){let n=e.length;if(!n)return 0;let r=0,i=0;if(this._interim){let n=e.charCodeAt(i++);56320<=n&&n<=57343?t[r++]=1024*(this._interim-55296)+n-56320+65536:(t[r++]=this._interim,t[r++]=n),this._interim=0}for(let a=i;a<n;++a){let i=e.charCodeAt(a);if(55296<=i&&i<=56319){if(++a>=n)return this._interim=i,r;let o=e.charCodeAt(a);56320<=o&&o<=57343?t[r++]=1024*(i-55296)+o-56320+65536:(t[r++]=i,t[r++]=o)}else i!==65279&&(t[r++]=i)}return r}},t.Utf8ToUtf32=class{constructor(){this.interim=new Uint8Array(3)}clear(){this.interim.fill(0)}decode(e,t){let n=e.length;if(!n)return 0;let r,i,a,o,s=0,c=0,l=0;if(this.interim[0]){let r=!1,i=this.interim[0];i&=(224&i)==192?31:(240&i)==224?15:7;let a,o=0;for(;(a=63&this.interim[++o])&&o<4;)i<<=6,i|=a;let c=(224&this.interim[0])==192?2:(240&this.interim[0])==224?3:4,u=c-o;for(;l<u;){if(l>=n)return 0;if(a=e[l++],(192&a)!=128){l--,r=!0;break}this.interim[o++]=a,i<<=6,i|=63&a}r||(c===2?i<128?l--:t[s++]=i:c===3?i<2048||i>=55296&&i<=57343||i===65279||(t[s++]=i):i<65536||i>1114111||(t[s++]=i)),this.interim.fill(0)}let u=n-4,d=l;for(;d<n;){for(;!(!(d<u)||128&(r=e[d])||128&(i=e[d+1])||128&(a=e[d+2])||128&(o=e[d+3]));)t[s++]=r,t[s++]=i,t[s++]=a,t[s++]=o,d+=4;if(r=e[d++],r<128)t[s++]=r;else if((224&r)==192){if(d>=n)return this.interim[0]=r,s;if(i=e[d++],(192&i)!=128){d--;continue}if(c=(31&r)<<6|63&i,c<128){d--;continue}t[s++]=c}else if((240&r)==224){if(d>=n)return this.interim[0]=r,s;if(i=e[d++],(192&i)!=128){d--;continue}if(d>=n)return this.interim[0]=r,this.interim[1]=i,s;if(a=e[d++],(192&a)!=128){d--;continue}if(c=(15&r)<<12|(63&i)<<6|63&a,c<2048||c>=55296&&c<=57343||c===65279)continue;t[s++]=c}else if((248&r)==240){if(d>=n)return this.interim[0]=r,s;if(i=e[d++],(192&i)!=128){d--;continue}if(d>=n)return this.interim[0]=r,this.interim[1]=i,s;if(a=e[d++],(192&a)!=128){d--;continue}if(d>=n)return this.interim[0]=r,this.interim[1]=i,this.interim[2]=a,s;if(o=e[d++],(192&o)!=128){d--;continue}if(c=(7&r)<<18|(63&i)<<12|(63&a)<<6|63&o,c<65536||c>1114111)continue;t[s++]=c}}return s}}},225:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.UnicodeV6=void 0;let r=n(1480),i=[[768,879],[1155,1158],[1160,1161],[1425,1469],[1471,1471],[1473,1474],[1476,1477],[1479,1479],[1536,1539],[1552,1557],[1611,1630],[1648,1648],[1750,1764],[1767,1768],[1770,1773],[1807,1807],[1809,1809],[1840,1866],[1958,1968],[2027,2035],[2305,2306],[2364,2364],[2369,2376],[2381,2381],[2385,2388],[2402,2403],[2433,2433],[2492,2492],[2497,2500],[2509,2509],[2530,2531],[2561,2562],[2620,2620],[2625,2626],[2631,2632],[2635,2637],[2672,2673],[2689,2690],[2748,2748],[2753,2757],[2759,2760],[2765,2765],[2786,2787],[2817,2817],[2876,2876],[2879,2879],[2881,2883],[2893,2893],[2902,2902],[2946,2946],[3008,3008],[3021,3021],[3134,3136],[3142,3144],[3146,3149],[3157,3158],[3260,3260],[3263,3263],[3270,3270],[3276,3277],[3298,3299],[3393,3395],[3405,3405],[3530,3530],[3538,3540],[3542,3542],[3633,3633],[3636,3642],[3655,3662],[3761,3761],[3764,3769],[3771,3772],[3784,3789],[3864,3865],[3893,3893],[3895,3895],[3897,3897],[3953,3966],[3968,3972],[3974,3975],[3984,3991],[3993,4028],[4038,4038],[4141,4144],[4146,4146],[4150,4151],[4153,4153],[4184,4185],[4448,4607],[4959,4959],[5906,5908],[5938,5940],[5970,5971],[6002,6003],[6068,6069],[6071,6077],[6086,6086],[6089,6099],[6109,6109],[6155,6157],[6313,6313],[6432,6434],[6439,6440],[6450,6450],[6457,6459],[6679,6680],[6912,6915],[6964,6964],[6966,6970],[6972,6972],[6978,6978],[7019,7027],[7616,7626],[7678,7679],[8203,8207],[8234,8238],[8288,8291],[8298,8303],[8400,8431],[12330,12335],[12441,12442],[43014,43014],[43019,43019],[43045,43046],[64286,64286],[65024,65039],[65056,65059],[65279,65279],[65529,65531]],a=[[68097,68099],[68101,68102],[68108,68111],[68152,68154],[68159,68159],[119143,119145],[119155,119170],[119173,119179],[119210,119213],[119362,119364],[917505,917505],[917536,917631],[917760,917999]],o;t.UnicodeV6=class{constructor(){if(this.version=`6`,!o){o=new Uint8Array(65536),o.fill(1),o[0]=0,o.fill(0,1,32),o.fill(0,127,160),o.fill(2,4352,4448),o[9001]=2,o[9002]=2,o.fill(2,11904,42192),o[12351]=1,o.fill(2,44032,55204),o.fill(2,63744,64256),o.fill(2,65040,65050),o.fill(2,65072,65136),o.fill(2,65280,65377),o.fill(2,65504,65511);for(let e=0;e<i.length;++e)o.fill(0,i[e][0],i[e][1]+1)}}wcwidth(e){return e<32?0:e<127?1:e<65536?o[e]:function(e,t){let n,r=0,i=t.length-1;if(e<t[0][0]||e>t[i][1])return!1;for(;i>=r;)if(n=r+i>>1,e>t[n][1])r=n+1;else{if(!(e<t[n][0]))return!0;i=n-1}return!1}(e,a)?0:e>=131072&&e<=196605||e>=196608&&e<=262141?2:1}charProperties(e,t){let n=this.wcwidth(e),i=n===0&&t!==0;if(i){let e=r.UnicodeService.extractWidth(t);e===0?i=!1:e>n&&(n=e)}return r.UnicodeService.createPropertyValue(0,n,i)}}},5981:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WriteBuffer=void 0;let r=n(8460),i=n(844);class a extends i.Disposable{constructor(e){super(),this._action=e,this._writeBuffer=[],this._callbacks=[],this._pendingData=0,this._bufferOffset=0,this._isSyncWriting=!1,this._syncCalls=0,this._didUserInput=!1,this._onWriteParsed=this.register(new r.EventEmitter),this.onWriteParsed=this._onWriteParsed.event}handleUserInput(){this._didUserInput=!0}writeSync(e,t){if(t!==void 0&&this._syncCalls>t)return void(this._syncCalls=0);if(this._pendingData+=e.length,this._writeBuffer.push(e),this._callbacks.push(void 0),this._syncCalls++,this._isSyncWriting)return;let n;for(this._isSyncWriting=!0;n=this._writeBuffer.shift();){this._action(n);let e=this._callbacks.shift();e&&e()}this._pendingData=0,this._bufferOffset=2147483647,this._isSyncWriting=!1,this._syncCalls=0}write(e,t){if(this._pendingData>5e7)throw Error(`write data discarded, use flow control to avoid losing data`);if(!this._writeBuffer.length){if(this._bufferOffset=0,this._didUserInput)return this._didUserInput=!1,this._pendingData+=e.length,this._writeBuffer.push(e),this._callbacks.push(t),void this._innerWrite();setTimeout((()=>this._innerWrite()))}this._pendingData+=e.length,this._writeBuffer.push(e),this._callbacks.push(t)}_innerWrite(e=0,t=!0){let n=e||Date.now();for(;this._writeBuffer.length>this._bufferOffset;){let e=this._writeBuffer[this._bufferOffset],r=this._action(e,t);if(r){r.catch((e=>(queueMicrotask((()=>{throw e})),Promise.resolve(!1)))).then(e=>Date.now()-n>=12?setTimeout((()=>this._innerWrite(0,e))):this._innerWrite(n,e));return}let i=this._callbacks[this._bufferOffset];if(i&&i(),this._bufferOffset++,this._pendingData-=e.length,Date.now()-n>=12)break}this._writeBuffer.length>this._bufferOffset?(this._bufferOffset>50&&(this._writeBuffer=this._writeBuffer.slice(this._bufferOffset),this._callbacks=this._callbacks.slice(this._bufferOffset),this._bufferOffset=0),setTimeout((()=>this._innerWrite()))):(this._writeBuffer.length=0,this._callbacks.length=0,this._pendingData=0,this._bufferOffset=0),this._onWriteParsed.fire()}}t.WriteBuffer=a},5941:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.toRgbString=t.parseColor=void 0;let n=/^([\da-f])\/([\da-f])\/([\da-f])$|^([\da-f]{2})\/([\da-f]{2})\/([\da-f]{2})$|^([\da-f]{3})\/([\da-f]{3})\/([\da-f]{3})$|^([\da-f]{4})\/([\da-f]{4})\/([\da-f]{4})$/,r=/^[\da-f]+$/;function i(e,t){let n=e.toString(16),r=n.length<2?`0`+n:n;switch(t){case 4:return n[0];case 8:return r;case 12:return(r+r).slice(0,3);default:return r+r}}t.parseColor=function(e){if(!e)return;let t=e.toLowerCase();if(t.indexOf(`rgb:`)===0){t=t.slice(4);let e=n.exec(t);if(e){let t=e[1]?15:e[4]?255:e[7]?4095:65535;return[Math.round(parseInt(e[1]||e[4]||e[7]||e[10],16)/t*255),Math.round(parseInt(e[2]||e[5]||e[8]||e[11],16)/t*255),Math.round(parseInt(e[3]||e[6]||e[9]||e[12],16)/t*255)]}}else if(t.indexOf(`#`)===0&&(t=t.slice(1),r.exec(t)&&[3,6,9,12].includes(t.length))){let e=t.length/3,n=[0,0,0];for(let r=0;r<3;++r){let i=parseInt(t.slice(e*r,e*r+e),16);n[r]=e===1?i<<4:e===2?i:e===3?i>>4:i>>8}return n}},t.toRgbString=function(e,t=16){let[n,r,a]=e;return`rgb:${i(n,t)}/${i(r,t)}/${i(a,t)}`}},5770:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.PAYLOAD_LIMIT=void 0,t.PAYLOAD_LIMIT=1e7},6351:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.DcsHandler=t.DcsParser=void 0;let r=n(482),i=n(8742),a=n(5770),o=[];t.DcsParser=class{constructor(){this._handlers=Object.create(null),this._active=o,this._ident=0,this._handlerFb=()=>{},this._stack={paused:!1,loopPosition:0,fallThrough:!1}}dispose(){this._handlers=Object.create(null),this._handlerFb=()=>{},this._active=o}registerHandler(e,t){this._handlers[e]===void 0&&(this._handlers[e]=[]);let n=this._handlers[e];return n.push(t),{dispose:()=>{let e=n.indexOf(t);e!==-1&&n.splice(e,1)}}}clearHandler(e){this._handlers[e]&&delete this._handlers[e]}setHandlerFallback(e){this._handlerFb=e}reset(){if(this._active.length)for(let e=this._stack.paused?this._stack.loopPosition-1:this._active.length-1;e>=0;--e)this._active[e].unhook(!1);this._stack.paused=!1,this._active=o,this._ident=0}hook(e,t){if(this.reset(),this._ident=e,this._active=this._handlers[e]||o,this._active.length)for(let e=this._active.length-1;e>=0;e--)this._active[e].hook(t);else this._handlerFb(this._ident,`HOOK`,t)}put(e,t,n){if(this._active.length)for(let r=this._active.length-1;r>=0;r--)this._active[r].put(e,t,n);else this._handlerFb(this._ident,`PUT`,(0,r.utf32ToString)(e,t,n))}unhook(e,t=!0){if(this._active.length){let n=!1,r=this._active.length-1,i=!1;if(this._stack.paused&&(r=this._stack.loopPosition-1,n=t,i=this._stack.fallThrough,this._stack.paused=!1),!i&&!1===n){for(;r>=0&&(n=this._active[r].unhook(e),!0!==n);r--)if(n instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=r,this._stack.fallThrough=!1,n;r--}for(;r>=0;r--)if(n=this._active[r].unhook(!1),n instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=r,this._stack.fallThrough=!0,n}else this._handlerFb(this._ident,`UNHOOK`,e);this._active=o,this._ident=0}};let s=new i.Params;s.addParam(0),t.DcsHandler=class{constructor(e){this._handler=e,this._data=``,this._params=s,this._hitLimit=!1}hook(e){this._params=e.length>1||e.params[0]?e.clone():s,this._data=``,this._hitLimit=!1}put(e,t,n){this._hitLimit||(this._data+=(0,r.utf32ToString)(e,t,n),this._data.length>a.PAYLOAD_LIMIT&&(this._data=``,this._hitLimit=!0))}unhook(e){let t=!1;if(this._hitLimit)t=!1;else if(e&&(t=this._handler(this._data,this._params),t instanceof Promise))return t.then((e=>(this._params=s,this._data=``,this._hitLimit=!1,e)));return this._params=s,this._data=``,this._hitLimit=!1,t}}},2015:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EscapeSequenceParser=t.VT500_TRANSITION_TABLE=t.TransitionTable=void 0;let r=n(844),i=n(8742),a=n(6242),o=n(6351);class s{constructor(e){this.table=new Uint8Array(e)}setDefault(e,t){this.table.fill(e<<4|t)}add(e,t,n,r){this.table[t<<8|e]=n<<4|r}addMany(e,t,n,r){for(let i=0;i<e.length;i++)this.table[t<<8|e[i]]=n<<4|r}}t.TransitionTable=s,t.VT500_TRANSITION_TABLE=function(){let e=new s(4095),t=Array.apply(null,Array(256)).map(((e,t)=>t)),n=(e,n)=>t.slice(e,n),r=n(32,127),i=n(0,24);i.push(25),i.push.apply(i,n(28,32));let a=n(0,14),o;for(o in e.setDefault(1,0),e.addMany(r,0,2,0),a)e.addMany([24,26,153,154],o,3,0),e.addMany(n(128,144),o,3,0),e.addMany(n(144,152),o,3,0),e.add(156,o,0,0),e.add(27,o,11,1),e.add(157,o,4,8),e.addMany([152,158,159],o,0,7),e.add(155,o,11,3),e.add(144,o,11,9);return e.addMany(i,0,3,0),e.addMany(i,1,3,1),e.add(127,1,0,1),e.addMany(i,8,0,8),e.addMany(i,3,3,3),e.add(127,3,0,3),e.addMany(i,4,3,4),e.add(127,4,0,4),e.addMany(i,6,3,6),e.addMany(i,5,3,5),e.add(127,5,0,5),e.addMany(i,2,3,2),e.add(127,2,0,2),e.add(93,1,4,8),e.addMany(r,8,5,8),e.add(127,8,5,8),e.addMany([156,27,24,26,7],8,6,0),e.addMany(n(28,32),8,0,8),e.addMany([88,94,95],1,0,7),e.addMany(r,7,0,7),e.addMany(i,7,0,7),e.add(156,7,0,0),e.add(127,7,0,7),e.add(91,1,11,3),e.addMany(n(64,127),3,7,0),e.addMany(n(48,60),3,8,4),e.addMany([60,61,62,63],3,9,4),e.addMany(n(48,60),4,8,4),e.addMany(n(64,127),4,7,0),e.addMany([60,61,62,63],4,0,6),e.addMany(n(32,64),6,0,6),e.add(127,6,0,6),e.addMany(n(64,127),6,0,0),e.addMany(n(32,48),3,9,5),e.addMany(n(32,48),5,9,5),e.addMany(n(48,64),5,0,6),e.addMany(n(64,127),5,7,0),e.addMany(n(32,48),4,9,5),e.addMany(n(32,48),1,9,2),e.addMany(n(32,48),2,9,2),e.addMany(n(48,127),2,10,0),e.addMany(n(48,80),1,10,0),e.addMany(n(81,88),1,10,0),e.addMany([89,90,92],1,10,0),e.addMany(n(96,127),1,10,0),e.add(80,1,11,9),e.addMany(i,9,0,9),e.add(127,9,0,9),e.addMany(n(28,32),9,0,9),e.addMany(n(32,48),9,9,12),e.addMany(n(48,60),9,8,10),e.addMany([60,61,62,63],9,9,10),e.addMany(i,11,0,11),e.addMany(n(32,128),11,0,11),e.addMany(n(28,32),11,0,11),e.addMany(i,10,0,10),e.add(127,10,0,10),e.addMany(n(28,32),10,0,10),e.addMany(n(48,60),10,8,10),e.addMany([60,61,62,63],10,0,11),e.addMany(n(32,48),10,9,12),e.addMany(i,12,0,12),e.add(127,12,0,12),e.addMany(n(28,32),12,0,12),e.addMany(n(32,48),12,9,12),e.addMany(n(48,64),12,0,11),e.addMany(n(64,127),12,12,13),e.addMany(n(64,127),10,12,13),e.addMany(n(64,127),9,12,13),e.addMany(i,13,13,13),e.addMany(r,13,13,13),e.add(127,13,0,13),e.addMany([27,156,24,26],13,14,0),e.add(160,0,2,0),e.add(160,8,5,8),e.add(160,6,0,6),e.add(160,11,0,11),e.add(160,13,13,13),e}();class c extends r.Disposable{constructor(e=t.VT500_TRANSITION_TABLE){super(),this._transitions=e,this._parseStack={state:0,handlers:[],handlerPos:0,transition:0,chunkPos:0},this.initialState=0,this.currentState=this.initialState,this._params=new i.Params,this._params.addParam(0),this._collect=0,this.precedingJoinState=0,this._printHandlerFb=(e,t,n)=>{},this._executeHandlerFb=e=>{},this._csiHandlerFb=(e,t)=>{},this._escHandlerFb=e=>{},this._errorHandlerFb=e=>e,this._printHandler=this._printHandlerFb,this._executeHandlers=Object.create(null),this._csiHandlers=Object.create(null),this._escHandlers=Object.create(null),this.register((0,r.toDisposable)((()=>{this._csiHandlers=Object.create(null),this._executeHandlers=Object.create(null),this._escHandlers=Object.create(null)}))),this._oscParser=this.register(new a.OscParser),this._dcsParser=this.register(new o.DcsParser),this._errorHandler=this._errorHandlerFb,this.registerEscHandler({final:`\\`},(()=>!0))}_identifier(e,t=[64,126]){let n=0;if(e.prefix){if(e.prefix.length>1)throw Error(`only one byte as prefix supported`);if(n=e.prefix.charCodeAt(0),n&&60>n||n>63)throw Error(`prefix must be in range 0x3c .. 0x3f`)}if(e.intermediates){if(e.intermediates.length>2)throw Error(`only two bytes as intermediates are supported`);for(let t=0;t<e.intermediates.length;++t){let r=e.intermediates.charCodeAt(t);if(32>r||r>47)throw Error(`intermediate must be in range 0x20 .. 0x2f`);n<<=8,n|=r}}if(e.final.length!==1)throw Error(`final must be a single byte`);let r=e.final.charCodeAt(0);if(t[0]>r||r>t[1])throw Error(`final must be in range ${t[0]} .. ${t[1]}`);return n<<=8,n|=r,n}identToString(e){let t=[];for(;e;)t.push(String.fromCharCode(255&e)),e>>=8;return t.reverse().join(``)}setPrintHandler(e){this._printHandler=e}clearPrintHandler(){this._printHandler=this._printHandlerFb}registerEscHandler(e,t){let n=this._identifier(e,[48,126]);this._escHandlers[n]===void 0&&(this._escHandlers[n]=[]);let r=this._escHandlers[n];return r.push(t),{dispose:()=>{let e=r.indexOf(t);e!==-1&&r.splice(e,1)}}}clearEscHandler(e){this._escHandlers[this._identifier(e,[48,126])]&&delete this._escHandlers[this._identifier(e,[48,126])]}setEscHandlerFallback(e){this._escHandlerFb=e}setExecuteHandler(e,t){this._executeHandlers[e.charCodeAt(0)]=t}clearExecuteHandler(e){this._executeHandlers[e.charCodeAt(0)]&&delete this._executeHandlers[e.charCodeAt(0)]}setExecuteHandlerFallback(e){this._executeHandlerFb=e}registerCsiHandler(e,t){let n=this._identifier(e);this._csiHandlers[n]===void 0&&(this._csiHandlers[n]=[]);let r=this._csiHandlers[n];return r.push(t),{dispose:()=>{let e=r.indexOf(t);e!==-1&&r.splice(e,1)}}}clearCsiHandler(e){this._csiHandlers[this._identifier(e)]&&delete this._csiHandlers[this._identifier(e)]}setCsiHandlerFallback(e){this._csiHandlerFb=e}registerDcsHandler(e,t){return this._dcsParser.registerHandler(this._identifier(e),t)}clearDcsHandler(e){this._dcsParser.clearHandler(this._identifier(e))}setDcsHandlerFallback(e){this._dcsParser.setHandlerFallback(e)}registerOscHandler(e,t){return this._oscParser.registerHandler(e,t)}clearOscHandler(e){this._oscParser.clearHandler(e)}setOscHandlerFallback(e){this._oscParser.setHandlerFallback(e)}setErrorHandler(e){this._errorHandler=e}clearErrorHandler(){this._errorHandler=this._errorHandlerFb}reset(){this.currentState=this.initialState,this._oscParser.reset(),this._dcsParser.reset(),this._params.reset(),this._params.addParam(0),this._collect=0,this.precedingJoinState=0,this._parseStack.state!==0&&(this._parseStack.state=2,this._parseStack.handlers=[])}_preserveStack(e,t,n,r,i){this._parseStack.state=e,this._parseStack.handlers=t,this._parseStack.handlerPos=n,this._parseStack.transition=r,this._parseStack.chunkPos=i}parse(e,t,n){let r,i=0,a=0,o=0;if(this._parseStack.state)if(this._parseStack.state===2)this._parseStack.state=0,o=this._parseStack.chunkPos+1;else{if(n===void 0||this._parseStack.state===1)throw this._parseStack.state=1,Error(`improper continuation due to previous async handler, giving up parsing`);let t=this._parseStack.handlers,a=this._parseStack.handlerPos-1;switch(this._parseStack.state){case 3:if(!1===n&&a>-1){for(;a>=0&&(r=t[a](this._params),!0!==r);a--)if(r instanceof Promise)return this._parseStack.handlerPos=a,r}this._parseStack.handlers=[];break;case 4:if(!1===n&&a>-1){for(;a>=0&&(r=t[a](),!0!==r);a--)if(r instanceof Promise)return this._parseStack.handlerPos=a,r}this._parseStack.handlers=[];break;case 6:if(i=e[this._parseStack.chunkPos],r=this._dcsParser.unhook(i!==24&&i!==26,n),r)return r;i===27&&(this._parseStack.transition|=1),this._params.reset(),this._params.addParam(0),this._collect=0;break;case 5:if(i=e[this._parseStack.chunkPos],r=this._oscParser.end(i!==24&&i!==26,n),r)return r;i===27&&(this._parseStack.transition|=1),this._params.reset(),this._params.addParam(0),this._collect=0}this._parseStack.state=0,o=this._parseStack.chunkPos+1,this.precedingJoinState=0,this.currentState=15&this._parseStack.transition}for(let n=o;n<t;++n){switch(i=e[n],a=this._transitions.table[this.currentState<<8|(i<160?i:160)],a>>4){case 2:for(let r=n+1;;++r){if(r>=t||(i=e[r])<32||i>126&&i<160){this._printHandler(e,n,r),n=r-1;break}if(++r>=t||(i=e[r])<32||i>126&&i<160){this._printHandler(e,n,r),n=r-1;break}if(++r>=t||(i=e[r])<32||i>126&&i<160){this._printHandler(e,n,r),n=r-1;break}if(++r>=t||(i=e[r])<32||i>126&&i<160){this._printHandler(e,n,r),n=r-1;break}}break;case 3:this._executeHandlers[i]?this._executeHandlers[i]():this._executeHandlerFb(i),this.precedingJoinState=0;break;case 0:break;case 1:if(this._errorHandler({position:n,code:i,currentState:this.currentState,collect:this._collect,params:this._params,abort:!1}).abort)return;break;case 7:let o=this._csiHandlers[this._collect<<8|i],s=o?o.length-1:-1;for(;s>=0&&(r=o[s](this._params),!0!==r);s--)if(r instanceof Promise)return this._preserveStack(3,o,s,a,n),r;s<0&&this._csiHandlerFb(this._collect<<8|i,this._params),this.precedingJoinState=0;break;case 8:do switch(i){case 59:this._params.addParam(0);break;case 58:this._params.addSubParam(-1);break;default:this._params.addDigit(i-48)}while(++n<t&&(i=e[n])>47&&i<60);n--;break;case 9:this._collect<<=8,this._collect|=i;break;case 10:let c=this._escHandlers[this._collect<<8|i],l=c?c.length-1:-1;for(;l>=0&&(r=c[l](),!0!==r);l--)if(r instanceof Promise)return this._preserveStack(4,c,l,a,n),r;l<0&&this._escHandlerFb(this._collect<<8|i),this.precedingJoinState=0;break;case 11:this._params.reset(),this._params.addParam(0),this._collect=0;break;case 12:this._dcsParser.hook(this._collect<<8|i,this._params);break;case 13:for(let r=n+1;;++r)if(r>=t||(i=e[r])===24||i===26||i===27||i>127&&i<160){this._dcsParser.put(e,n,r),n=r-1;break}break;case 14:if(r=this._dcsParser.unhook(i!==24&&i!==26),r)return this._preserveStack(6,[],0,a,n),r;i===27&&(a|=1),this._params.reset(),this._params.addParam(0),this._collect=0,this.precedingJoinState=0;break;case 4:this._oscParser.start();break;case 5:for(let r=n+1;;r++)if(r>=t||(i=e[r])<32||i>127&&i<160){this._oscParser.put(e,n,r),n=r-1;break}break;case 6:if(r=this._oscParser.end(i!==24&&i!==26),r)return this._preserveStack(5,[],0,a,n),r;i===27&&(a|=1),this._params.reset(),this._params.addParam(0),this._collect=0,this.precedingJoinState=0}this.currentState=15&a}}}t.EscapeSequenceParser=c},6242:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.OscHandler=t.OscParser=void 0;let r=n(5770),i=n(482),a=[];t.OscParser=class{constructor(){this._state=0,this._active=a,this._id=-1,this._handlers=Object.create(null),this._handlerFb=()=>{},this._stack={paused:!1,loopPosition:0,fallThrough:!1}}registerHandler(e,t){this._handlers[e]===void 0&&(this._handlers[e]=[]);let n=this._handlers[e];return n.push(t),{dispose:()=>{let e=n.indexOf(t);e!==-1&&n.splice(e,1)}}}clearHandler(e){this._handlers[e]&&delete this._handlers[e]}setHandlerFallback(e){this._handlerFb=e}dispose(){this._handlers=Object.create(null),this._handlerFb=()=>{},this._active=a}reset(){if(this._state===2)for(let e=this._stack.paused?this._stack.loopPosition-1:this._active.length-1;e>=0;--e)this._active[e].end(!1);this._stack.paused=!1,this._active=a,this._id=-1,this._state=0}_start(){if(this._active=this._handlers[this._id]||a,this._active.length)for(let e=this._active.length-1;e>=0;e--)this._active[e].start();else this._handlerFb(this._id,`START`)}_put(e,t,n){if(this._active.length)for(let r=this._active.length-1;r>=0;r--)this._active[r].put(e,t,n);else this._handlerFb(this._id,`PUT`,(0,i.utf32ToString)(e,t,n))}start(){this.reset(),this._state=1}put(e,t,n){if(this._state!==3){if(this._state===1)for(;t<n;){let n=e[t++];if(n===59){this._state=2,this._start();break}if(n<48||57<n)return void(this._state=3);this._id===-1&&(this._id=0),this._id=10*this._id+n-48}this._state===2&&n-t>0&&this._put(e,t,n)}}end(e,t=!0){if(this._state!==0){if(this._state!==3)if(this._state===1&&this._start(),this._active.length){let n=!1,r=this._active.length-1,i=!1;if(this._stack.paused&&(r=this._stack.loopPosition-1,n=t,i=this._stack.fallThrough,this._stack.paused=!1),!i&&!1===n){for(;r>=0&&(n=this._active[r].end(e),!0!==n);r--)if(n instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=r,this._stack.fallThrough=!1,n;r--}for(;r>=0;r--)if(n=this._active[r].end(!1),n instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=r,this._stack.fallThrough=!0,n}else this._handlerFb(this._id,`END`,e);this._active=a,this._id=-1,this._state=0}}},t.OscHandler=class{constructor(e){this._handler=e,this._data=``,this._hitLimit=!1}start(){this._data=``,this._hitLimit=!1}put(e,t,n){this._hitLimit||(this._data+=(0,i.utf32ToString)(e,t,n),this._data.length>r.PAYLOAD_LIMIT&&(this._data=``,this._hitLimit=!0))}end(e){let t=!1;if(this._hitLimit)t=!1;else if(e&&(t=this._handler(this._data),t instanceof Promise))return t.then((e=>(this._data=``,this._hitLimit=!1,e)));return this._data=``,this._hitLimit=!1,t}}},8742:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Params=void 0;let n=2147483647;class r{static fromArray(e){let t=new r;if(!e.length)return t;for(let n=+!!Array.isArray(e[0]);n<e.length;++n){let r=e[n];if(Array.isArray(r))for(let e=0;e<r.length;++e)t.addSubParam(r[e]);else t.addParam(r)}return t}constructor(e=32,t=32){if(this.maxLength=e,this.maxSubParamsLength=t,t>256)throw Error(`maxSubParamsLength must not be greater than 256`);this.params=new Int32Array(e),this.length=0,this._subParams=new Int32Array(t),this._subParamsLength=0,this._subParamsIdx=new Uint16Array(e),this._rejectDigits=!1,this._rejectSubDigits=!1,this._digitIsSub=!1}clone(){let e=new r(this.maxLength,this.maxSubParamsLength);return e.params.set(this.params),e.length=this.length,e._subParams.set(this._subParams),e._subParamsLength=this._subParamsLength,e._subParamsIdx.set(this._subParamsIdx),e._rejectDigits=this._rejectDigits,e._rejectSubDigits=this._rejectSubDigits,e._digitIsSub=this._digitIsSub,e}toArray(){let e=[];for(let t=0;t<this.length;++t){e.push(this.params[t]);let n=this._subParamsIdx[t]>>8,r=255&this._subParamsIdx[t];r-n>0&&e.push(Array.prototype.slice.call(this._subParams,n,r))}return e}reset(){this.length=0,this._subParamsLength=0,this._rejectDigits=!1,this._rejectSubDigits=!1,this._digitIsSub=!1}addParam(e){if(this._digitIsSub=!1,this.length>=this.maxLength)this._rejectDigits=!0;else{if(e<-1)throw Error(`values lesser than -1 are not allowed`);this._subParamsIdx[this.length]=this._subParamsLength<<8|this._subParamsLength,this.params[this.length++]=e>n?n:e}}addSubParam(e){if(this._digitIsSub=!0,this.length)if(this._rejectDigits||this._subParamsLength>=this.maxSubParamsLength)this._rejectSubDigits=!0;else{if(e<-1)throw Error(`values lesser than -1 are not allowed`);this._subParams[this._subParamsLength++]=e>n?n:e,this._subParamsIdx[this.length-1]++}}hasSubParams(e){return(255&this._subParamsIdx[e])-(this._subParamsIdx[e]>>8)>0}getSubParams(e){let t=this._subParamsIdx[e]>>8,n=255&this._subParamsIdx[e];return n-t>0?this._subParams.subarray(t,n):null}getSubParamsAll(){let e={};for(let t=0;t<this.length;++t){let n=this._subParamsIdx[t]>>8,r=255&this._subParamsIdx[t];r-n>0&&(e[t]=this._subParams.slice(n,r))}return e}addDigit(e){let t;if(this._rejectDigits||!(t=this._digitIsSub?this._subParamsLength:this.length)||this._digitIsSub&&this._rejectSubDigits)return;let r=this._digitIsSub?this._subParams:this.params,i=r[t-1];r[t-1]=~i?Math.min(10*i+e,n):e}}t.Params=r},5741:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.AddonManager=void 0,t.AddonManager=class{constructor(){this._addons=[]}dispose(){for(let e=this._addons.length-1;e>=0;e--)this._addons[e].instance.dispose()}loadAddon(e,t){let n={instance:t,dispose:t.dispose,isDisposed:!1};this._addons.push(n),t.dispose=()=>this._wrappedAddonDispose(n),t.activate(e)}_wrappedAddonDispose(e){if(e.isDisposed)return;let t=-1;for(let n=0;n<this._addons.length;n++)if(this._addons[n]===e){t=n;break}if(t===-1)throw Error(`Could not dispose an addon that has not been loaded`);e.isDisposed=!0,e.dispose.apply(e.instance),this._addons.splice(t,1)}}},8771:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.BufferApiView=void 0;let r=n(3785),i=n(511);t.BufferApiView=class{constructor(e,t){this._buffer=e,this.type=t}init(e){return this._buffer=e,this}get cursorY(){return this._buffer.y}get cursorX(){return this._buffer.x}get viewportY(){return this._buffer.ydisp}get baseY(){return this._buffer.ybase}get length(){return this._buffer.lines.length}getLine(e){let t=this._buffer.lines.get(e);if(t)return new r.BufferLineApiView(t)}getNullCell(){return new i.CellData}}},3785:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.BufferLineApiView=void 0;let r=n(511);t.BufferLineApiView=class{constructor(e){this._line=e}get isWrapped(){return this._line.isWrapped}get length(){return this._line.length}getCell(e,t){if(!(e<0||e>=this._line.length))return t?(this._line.loadCell(e,t),t):this._line.loadCell(e,new r.CellData)}translateToString(e,t,n){return this._line.translateToString(e,t,n)}}},8285:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.BufferNamespaceApi=void 0;let r=n(8771),i=n(8460),a=n(844);class o extends a.Disposable{constructor(e){super(),this._core=e,this._onBufferChange=this.register(new i.EventEmitter),this.onBufferChange=this._onBufferChange.event,this._normal=new r.BufferApiView(this._core.buffers.normal,`normal`),this._alternate=new r.BufferApiView(this._core.buffers.alt,`alternate`),this._core.buffers.onBufferActivate((()=>this._onBufferChange.fire(this.active)))}get active(){if(this._core.buffers.active===this._core.buffers.normal)return this.normal;if(this._core.buffers.active===this._core.buffers.alt)return this.alternate;throw Error(`Active buffer is neither normal nor alternate`)}get normal(){return this._normal.init(this._core.buffers.normal)}get alternate(){return this._alternate.init(this._core.buffers.alt)}}t.BufferNamespaceApi=o},7975:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ParserApi=void 0,t.ParserApi=class{constructor(e){this._core=e}registerCsiHandler(e,t){return this._core.registerCsiHandler(e,(e=>t(e.toArray())))}addCsiHandler(e,t){return this.registerCsiHandler(e,t)}registerDcsHandler(e,t){return this._core.registerDcsHandler(e,((e,n)=>t(e,n.toArray())))}addDcsHandler(e,t){return this.registerDcsHandler(e,t)}registerEscHandler(e,t){return this._core.registerEscHandler(e,t)}addEscHandler(e,t){return this.registerEscHandler(e,t)}registerOscHandler(e,t){return this._core.registerOscHandler(e,t)}addOscHandler(e,t){return this.registerOscHandler(e,t)}}},7090:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.UnicodeApi=void 0,t.UnicodeApi=class{constructor(e){this._core=e}register(e){this._core.unicodeService.register(e)}get versions(){return this._core.unicodeService.versions}get activeVersion(){return this._core.unicodeService.activeVersion}set activeVersion(e){this._core.unicodeService.activeVersion=e}}},744:function(e,t,n){var r=this&&this.__decorate||function(e,t,n,r){var i,a=arguments.length,o=a<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)o=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o},i=this&&this.__param||function(e,t){return function(n,r){t(n,r,e)}};Object.defineProperty(t,"__esModule",{value:!0}),t.BufferService=t.MINIMUM_ROWS=t.MINIMUM_COLS=void 0;let a=n(8460),o=n(844),s=n(5295),c=n(2585);t.MINIMUM_COLS=2,t.MINIMUM_ROWS=1;let l=t.BufferService=class extends o.Disposable{get buffer(){return this.buffers.active}constructor(e){super(),this.isUserScrolling=!1,this._onResize=this.register(new a.EventEmitter),this.onResize=this._onResize.event,this._onScroll=this.register(new a.EventEmitter),this.onScroll=this._onScroll.event,this.cols=Math.max(e.rawOptions.cols||0,t.MINIMUM_COLS),this.rows=Math.max(e.rawOptions.rows||0,t.MINIMUM_ROWS),this.buffers=this.register(new s.BufferSet(e,this))}resize(e,t){this.cols=e,this.rows=t,this.buffers.resize(e,t),this._onResize.fire({cols:e,rows:t})}reset(){this.buffers.reset(),this.isUserScrolling=!1}scroll(e,t=!1){let n=this.buffer,r;r=this._cachedBlankLine,r&&r.length===this.cols&&r.getFg(0)===e.fg&&r.getBg(0)===e.bg||(r=n.getBlankLine(e,t),this._cachedBlankLine=r),r.isWrapped=t;let i=n.ybase+n.scrollTop,a=n.ybase+n.scrollBottom;if(n.scrollTop===0){let e=n.lines.isFull;a===n.lines.length-1?e?n.lines.recycle().copyFrom(r):n.lines.push(r.clone()):n.lines.splice(a+1,0,r.clone()),e?this.isUserScrolling&&(n.ydisp=Math.max(n.ydisp-1,0)):(n.ybase++,this.isUserScrolling||n.ydisp++)}else{let e=a-i+1;n.lines.shiftElements(i+1,e-1,-1),n.lines.set(a,r.clone())}this.isUserScrolling||(n.ydisp=n.ybase),this._onScroll.fire(n.ydisp)}scrollLines(e,t,n){let r=this.buffer;if(e<0){if(r.ydisp===0)return;this.isUserScrolling=!0}else e+r.ydisp>=r.ybase&&(this.isUserScrolling=!1);let i=r.ydisp;r.ydisp=Math.max(Math.min(r.ydisp+e,r.ybase),0),i!==r.ydisp&&(t||this._onScroll.fire(r.ydisp))}};t.BufferService=l=r([i(0,c.IOptionsService)],l)},7994:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.CharsetService=void 0,t.CharsetService=class{constructor(){this.glevel=0,this._charsets=[]}reset(){this.charset=void 0,this._charsets=[],this.glevel=0}setgLevel(e){this.glevel=e,this.charset=this._charsets[e]}setgCharset(e,t){this._charsets[e]=t,this.glevel===e&&(this.charset=t)}}},1753:function(e,t,n){var r=this&&this.__decorate||function(e,t,n,r){var i,a=arguments.length,o=a<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)o=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o},i=this&&this.__param||function(e,t){return function(n,r){t(n,r,e)}};Object.defineProperty(t,"__esModule",{value:!0}),t.CoreMouseService=void 0;let a=n(2585),o=n(8460),s=n(844),c={NONE:{events:0,restrict:()=>!1},X10:{events:1,restrict:e=>e.button!==4&&e.action===1&&(e.ctrl=!1,e.alt=!1,e.shift=!1,!0)},VT200:{events:19,restrict:e=>e.action!==32},DRAG:{events:23,restrict:e=>e.action!==32||e.button!==3},ANY:{events:31,restrict:e=>!0}};function l(e,t){let n=(e.ctrl?16:0)|(e.shift?4:0)|(e.alt?8:0);return e.button===4?(n|=64,n|=e.action):(n|=3&e.button,4&e.button&&(n|=64),8&e.button&&(n|=128),e.action===32?n|=32:e.action!==0||t||(n|=3)),n}let u=String.fromCharCode,d={DEFAULT:e=>{let t=[l(e,!1)+32,e.col+32,e.row+32];return t[0]>255||t[1]>255||t[2]>255?``:`[M${u(t[0])}${u(t[1])}${u(t[2])}`},SGR:e=>{let t=e.action===0&&e.button!==4?`m`:`M`;return`[<${l(e,!0)};${e.col};${e.row}${t}`},SGR_PIXELS:e=>{let t=e.action===0&&e.button!==4?`m`:`M`;return`[<${l(e,!0)};${e.x};${e.y}${t}`}},f=t.CoreMouseService=class extends s.Disposable{constructor(e,t){super(),this._bufferService=e,this._coreService=t,this._protocols={},this._encodings={},this._activeProtocol=``,this._activeEncoding=``,this._lastEvent=null,this._onProtocolChange=this.register(new o.EventEmitter),this.onProtocolChange=this._onProtocolChange.event;for(let e of Object.keys(c))this.addProtocol(e,c[e]);for(let e of Object.keys(d))this.addEncoding(e,d[e]);this.reset()}addProtocol(e,t){this._protocols[e]=t}addEncoding(e,t){this._encodings[e]=t}get activeProtocol(){return this._activeProtocol}get areMouseEventsActive(){return this._protocols[this._activeProtocol].events!==0}set activeProtocol(e){if(!this._protocols[e])throw Error(`unknown protocol "${e}"`);this._activeProtocol=e,this._onProtocolChange.fire(this._protocols[e].events)}get activeEncoding(){return this._activeEncoding}set activeEncoding(e){if(!this._encodings[e])throw Error(`unknown encoding "${e}"`);this._activeEncoding=e}reset(){this.activeProtocol=`NONE`,this.activeEncoding=`DEFAULT`,this._lastEvent=null}triggerMouseEvent(e){if(e.col<0||e.col>=this._bufferService.cols||e.row<0||e.row>=this._bufferService.rows||e.button===4&&e.action===32||e.button===3&&e.action!==32||e.button!==4&&(e.action===2||e.action===3)||(e.col++,e.row++,e.action===32&&this._lastEvent&&this._equalEvents(this._lastEvent,e,this._activeEncoding===`SGR_PIXELS`))||!this._protocols[this._activeProtocol].restrict(e))return!1;let t=this._encodings[this._activeEncoding](e);return t&&(this._activeEncoding===`DEFAULT`?this._coreService.triggerBinaryEvent(t):this._coreService.triggerDataEvent(t,!0)),this._lastEvent=e,!0}explainEvents(e){return{down:!!(1&e),up:!!(2&e),drag:!!(4&e),move:!!(8&e),wheel:!!(16&e)}}_equalEvents(e,t,n){if(n){if(e.x!==t.x||e.y!==t.y)return!1}else if(e.col!==t.col||e.row!==t.row)return!1;return e.button===t.button&&e.action===t.action&&e.ctrl===t.ctrl&&e.alt===t.alt&&e.shift===t.shift}};t.CoreMouseService=f=r([i(0,a.IBufferService),i(1,a.ICoreService)],f)},6975:function(e,t,n){var r=this&&this.__decorate||function(e,t,n,r){var i,a=arguments.length,o=a<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)o=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o},i=this&&this.__param||function(e,t){return function(n,r){t(n,r,e)}};Object.defineProperty(t,"__esModule",{value:!0}),t.CoreService=void 0;let a=n(1439),o=n(8460),s=n(844),c=n(2585),l=Object.freeze({insertMode:!1}),u=Object.freeze({applicationCursorKeys:!1,applicationKeypad:!1,bracketedPasteMode:!1,origin:!1,reverseWraparound:!1,sendFocus:!1,wraparound:!0}),d=t.CoreService=class extends s.Disposable{constructor(e,t,n){super(),this._bufferService=e,this._logService=t,this._optionsService=n,this.isCursorInitialized=!1,this.isCursorHidden=!1,this._onData=this.register(new o.EventEmitter),this.onData=this._onData.event,this._onUserInput=this.register(new o.EventEmitter),this.onUserInput=this._onUserInput.event,this._onBinary=this.register(new o.EventEmitter),this.onBinary=this._onBinary.event,this._onRequestScrollToBottom=this.register(new o.EventEmitter),this.onRequestScrollToBottom=this._onRequestScrollToBottom.event,this.modes=(0,a.clone)(l),this.decPrivateModes=(0,a.clone)(u)}reset(){this.modes=(0,a.clone)(l),this.decPrivateModes=(0,a.clone)(u)}triggerDataEvent(e,t=!1){if(this._optionsService.rawOptions.disableStdin)return;let n=this._bufferService.buffer;t&&this._optionsService.rawOptions.scrollOnUserInput&&n.ybase!==n.ydisp&&this._onRequestScrollToBottom.fire(),t&&this._onUserInput.fire(),this._logService.debug(`sending data "${e}"`,(()=>e.split(``).map((e=>e.charCodeAt(0))))),this._onData.fire(e)}triggerBinaryEvent(e){this._optionsService.rawOptions.disableStdin||(this._logService.debug(`sending binary "${e}"`,(()=>e.split(``).map((e=>e.charCodeAt(0))))),this._onBinary.fire(e))}};t.CoreService=d=r([i(0,c.IBufferService),i(1,c.ILogService),i(2,c.IOptionsService)],d)},9074:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.DecorationService=void 0;let r=n(8055),i=n(8460),a=n(844),o=n(6106),s=0,c=0;class l extends a.Disposable{get decorations(){return this._decorations.values()}constructor(){super(),this._decorations=new o.SortedList((e=>e?.marker.line)),this._onDecorationRegistered=this.register(new i.EventEmitter),this.onDecorationRegistered=this._onDecorationRegistered.event,this._onDecorationRemoved=this.register(new i.EventEmitter),this.onDecorationRemoved=this._onDecorationRemoved.event,this.register((0,a.toDisposable)((()=>this.reset())))}registerDecoration(e){if(e.marker.isDisposed)return;let t=new u(e);if(t){let e=t.marker.onDispose((()=>t.dispose()));t.onDispose((()=>{t&&(this._decorations.delete(t)&&this._onDecorationRemoved.fire(t),e.dispose())})),this._decorations.insert(t),this._onDecorationRegistered.fire(t)}return t}reset(){for(let e of this._decorations.values())e.dispose();this._decorations.clear()}*getDecorationsAtCell(e,t,n){let r=0,i=0;for(let a of this._decorations.getKeyIterator(t))r=a.options.x??0,i=r+(a.options.width??1),e>=r&&e<i&&(!n||(a.options.layer??`bottom`)===n)&&(yield a)}forEachDecorationAtCell(e,t,n,r){this._decorations.forEachByKey(t,(t=>{s=t.options.x??0,c=s+(t.options.width??1),e>=s&&e<c&&(!n||(t.options.layer??`bottom`)===n)&&r(t)}))}}t.DecorationService=l;class u extends a.Disposable{get isDisposed(){return this._isDisposed}get backgroundColorRGB(){return this._cachedBg===null&&(this.options.backgroundColor?this._cachedBg=r.css.toColor(this.options.backgroundColor):this._cachedBg=void 0),this._cachedBg}get foregroundColorRGB(){return this._cachedFg===null&&(this.options.foregroundColor?this._cachedFg=r.css.toColor(this.options.foregroundColor):this._cachedFg=void 0),this._cachedFg}constructor(e){super(),this.options=e,this.onRenderEmitter=this.register(new i.EventEmitter),this.onRender=this.onRenderEmitter.event,this._onDispose=this.register(new i.EventEmitter),this.onDispose=this._onDispose.event,this._cachedBg=null,this._cachedFg=null,this.marker=e.marker,this.options.overviewRulerOptions&&!this.options.overviewRulerOptions.position&&(this.options.overviewRulerOptions.position=`full`)}dispose(){this._onDispose.fire(),super.dispose()}}},4348:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.InstantiationService=t.ServiceCollection=void 0;let r=n(2585),i=n(8343);class a{constructor(...e){this._entries=new Map;for(let[t,n]of e)this.set(t,n)}set(e,t){let n=this._entries.get(e);return this._entries.set(e,t),n}forEach(e){for(let[t,n]of this._entries.entries())e(t,n)}has(e){return this._entries.has(e)}get(e){return this._entries.get(e)}}t.ServiceCollection=a,t.InstantiationService=class{constructor(){this._services=new a,this._services.set(r.IInstantiationService,this)}setService(e,t){this._services.set(e,t)}getService(e){return this._services.get(e)}createInstance(e,...t){let n=(0,i.getServiceDependencies)(e).sort(((e,t)=>e.index-t.index)),r=[];for(let t of n){let n=this._services.get(t.id);if(!n)throw Error(`[createInstance] ${e.name} depends on UNKNOWN service ${t.id}.`);r.push(n)}let a=n.length>0?n[0].index:t.length;if(t.length!==a)throw Error(`[createInstance] First service dependency of ${e.name} at position ${a+1} conflicts with ${t.length} static arguments`);return new e(...t,...r)}}},7866:function(e,t,n){var r=this&&this.__decorate||function(e,t,n,r){var i,a=arguments.length,o=a<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)o=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o},i=this&&this.__param||function(e,t){return function(n,r){t(n,r,e)}};Object.defineProperty(t,"__esModule",{value:!0}),t.traceCall=t.setTraceLogger=t.LogService=void 0;let a=n(844),o=n(2585),s={trace:o.LogLevelEnum.TRACE,debug:o.LogLevelEnum.DEBUG,info:o.LogLevelEnum.INFO,warn:o.LogLevelEnum.WARN,error:o.LogLevelEnum.ERROR,off:o.LogLevelEnum.OFF},c,l=t.LogService=class extends a.Disposable{get logLevel(){return this._logLevel}constructor(e){super(),this._optionsService=e,this._logLevel=o.LogLevelEnum.OFF,this._updateLogLevel(),this.register(this._optionsService.onSpecificOptionChange(`logLevel`,(()=>this._updateLogLevel()))),c=this}_updateLogLevel(){this._logLevel=s[this._optionsService.rawOptions.logLevel]}_evalLazyOptionalParams(e){for(let t=0;t<e.length;t++)typeof e[t]==`function`&&(e[t]=e[t]())}_log(e,t,n){this._evalLazyOptionalParams(n),e.call(console,(this._optionsService.options.logger?``:`xterm.js: `)+t,...n)}trace(e,...t){this._logLevel<=o.LogLevelEnum.TRACE&&this._log(this._optionsService.options.logger?.trace.bind(this._optionsService.options.logger)??console.log,e,t)}debug(e,...t){this._logLevel<=o.LogLevelEnum.DEBUG&&this._log(this._optionsService.options.logger?.debug.bind(this._optionsService.options.logger)??console.log,e,t)}info(e,...t){this._logLevel<=o.LogLevelEnum.INFO&&this._log(this._optionsService.options.logger?.info.bind(this._optionsService.options.logger)??console.info,e,t)}warn(e,...t){this._logLevel<=o.LogLevelEnum.WARN&&this._log(this._optionsService.options.logger?.warn.bind(this._optionsService.options.logger)??console.warn,e,t)}error(e,...t){this._logLevel<=o.LogLevelEnum.ERROR&&this._log(this._optionsService.options.logger?.error.bind(this._optionsService.options.logger)??console.error,e,t)}};t.LogService=l=r([i(0,o.IOptionsService)],l),t.setTraceLogger=function(e){c=e},t.traceCall=function(e,t,n){if(typeof n.value!=`function`)throw Error(`not supported`);let r=n.value;n.value=function(...e){if(c.logLevel!==o.LogLevelEnum.TRACE)return r.apply(this,e);c.trace(`GlyphRenderer#${r.name}(${e.map((e=>JSON.stringify(e))).join(`, `)})`);let t=r.apply(this,e);return c.trace(`GlyphRenderer#${r.name} return`,t),t}}},7302:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.OptionsService=t.DEFAULT_OPTIONS=void 0;let r=n(8460),i=n(844);t.DEFAULT_OPTIONS={cols:80,rows:24,cursorBlink:!1,cursorStyle:`block`,cursorWidth:1,cursorInactiveStyle:`outline`,customGlyphs:!0,drawBoldTextInBrightColors:!0,documentOverride:null,fastScrollModifier:`alt`,fastScrollSensitivity:5,fontFamily:`courier-new, courier, monospace`,fontSize:15,fontWeight:`normal`,fontWeightBold:`bold`,ignoreBracketedPasteMode:!1,lineHeight:1,letterSpacing:0,linkHandler:null,logLevel:`info`,logger:null,scrollback:1e3,scrollOnUserInput:!0,scrollSensitivity:1,screenReaderMode:!1,smoothScrollDuration:0,macOptionIsMeta:!1,macOptionClickForcesSelection:!1,minimumContrastRatio:1,disableStdin:!1,allowProposedApi:!1,allowTransparency:!1,tabStopWidth:8,theme:{},rescaleOverlappingGlyphs:!1,rightClickSelectsWord:n(6114).isMac,windowOptions:{},windowsMode:!1,windowsPty:{},wordSeparator:` ()[]{}',"\``,altClickMovesCursor:!0,convertEol:!1,termName:`xterm`,cancelEvents:!1,overviewRulerWidth:0};let a=[`normal`,`bold`,`100`,`200`,`300`,`400`,`500`,`600`,`700`,`800`,`900`];class o extends i.Disposable{constructor(e){super(),this._onOptionChange=this.register(new r.EventEmitter),this.onOptionChange=this._onOptionChange.event;let n={...t.DEFAULT_OPTIONS};for(let t in e)if(t in n)try{let r=e[t];n[t]=this._sanitizeAndValidateOption(t,r)}catch(e){console.error(e)}this.rawOptions=n,this.options={...n},this._setupOptions(),this.register((0,i.toDisposable)((()=>{this.rawOptions.linkHandler=null,this.rawOptions.documentOverride=null})))}onSpecificOptionChange(e,t){return this.onOptionChange((n=>{n===e&&t(this.rawOptions[e])}))}onMultipleOptionChange(e,t){return this.onOptionChange((n=>{e.indexOf(n)!==-1&&t()}))}_setupOptions(){let e=e=>{if(!(e in t.DEFAULT_OPTIONS))throw Error(`No option with key "${e}"`);return this.rawOptions[e]},n=(e,n)=>{if(!(e in t.DEFAULT_OPTIONS))throw Error(`No option with key "${e}"`);n=this._sanitizeAndValidateOption(e,n),this.rawOptions[e]!==n&&(this.rawOptions[e]=n,this._onOptionChange.fire(e))};for(let t in this.rawOptions){let r={get:e.bind(this,t),set:n.bind(this,t)};Object.defineProperty(this.options,t,r)}}_sanitizeAndValidateOption(e,n){switch(e){case`cursorStyle`:if(n||=t.DEFAULT_OPTIONS[e],!function(e){return e===`block`||e===`underline`||e===`bar`}(n))throw Error(`"${n}" is not a valid value for ${e}`);break;case`wordSeparator`:n||=t.DEFAULT_OPTIONS[e];break;case`fontWeight`:case`fontWeightBold`:if(typeof n==`number`&&1<=n&&n<=1e3)break;n=a.includes(n)?n:t.DEFAULT_OPTIONS[e];break;case`cursorWidth`:n=Math.floor(n);case`lineHeight`:case`tabStopWidth`:if(n<1)throw Error(`${e} cannot be less than 1, value: ${n}`);break;case`minimumContrastRatio`:n=Math.max(1,Math.min(21,Math.round(10*n)/10));break;case`scrollback`:if((n=Math.min(n,4294967295))<0)throw Error(`${e} cannot be less than 0, value: ${n}`);break;case`fastScrollSensitivity`:case`scrollSensitivity`:if(n<=0)throw Error(`${e} cannot be less than or equal to 0, value: ${n}`);break;case`rows`:case`cols`:if(!n&&n!==0)throw Error(`${e} must be numeric, value: ${n}`);break;case`windowsPty`:n??={}}return n}}t.OptionsService=o},2660:function(e,t,n){var r=this&&this.__decorate||function(e,t,n,r){var i,a=arguments.length,o=a<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)o=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o},i=this&&this.__param||function(e,t){return function(n,r){t(n,r,e)}};Object.defineProperty(t,"__esModule",{value:!0}),t.OscLinkService=void 0;let a=n(2585),o=t.OscLinkService=class{constructor(e){this._bufferService=e,this._nextId=1,this._entriesWithId=new Map,this._dataByLinkId=new Map}registerLink(e){let t=this._bufferService.buffer;if(e.id===void 0){let n=t.addMarker(t.ybase+t.y),r={data:e,id:this._nextId++,lines:[n]};return n.onDispose((()=>this._removeMarkerFromLink(r,n))),this._dataByLinkId.set(r.id,r),r.id}let n=e,r=this._getEntryIdKey(n),i=this._entriesWithId.get(r);if(i)return this.addLineToLink(i.id,t.ybase+t.y),i.id;let a=t.addMarker(t.ybase+t.y),o={id:this._nextId++,key:this._getEntryIdKey(n),data:n,lines:[a]};return a.onDispose((()=>this._removeMarkerFromLink(o,a))),this._entriesWithId.set(o.key,o),this._dataByLinkId.set(o.id,o),o.id}addLineToLink(e,t){let n=this._dataByLinkId.get(e);if(n&&n.lines.every((e=>e.line!==t))){let e=this._bufferService.buffer.addMarker(t);n.lines.push(e),e.onDispose((()=>this._removeMarkerFromLink(n,e)))}}getLinkData(e){return this._dataByLinkId.get(e)?.data}_getEntryIdKey(e){return`${e.id};;${e.uri}`}_removeMarkerFromLink(e,t){let n=e.lines.indexOf(t);n!==-1&&(e.lines.splice(n,1),e.lines.length===0&&(e.data.id!==void 0&&this._entriesWithId.delete(e.key),this._dataByLinkId.delete(e.id)))}};t.OscLinkService=o=r([i(0,a.IBufferService)],o)},8343:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.createDecorator=t.getServiceDependencies=t.serviceRegistry=void 0;let n=`di$target`,r=`di$dependencies`;t.serviceRegistry=new Map,t.getServiceDependencies=function(e){return e[r]||[]},t.createDecorator=function(e){if(t.serviceRegistry.has(e))return t.serviceRegistry.get(e);let i=function(e,t,a){if(arguments.length!==3)throw Error(`@IServiceName-decorator can only be used to decorate a parameter`);(function(e,t,i){t[n]===t?t[r].push({id:e,index:i}):(t[r]=[{id:e,index:i}],t[n]=t)})(i,e,a)};return i.toString=()=>e,t.serviceRegistry.set(e,i),i}},2585:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.IDecorationService=t.IUnicodeService=t.IOscLinkService=t.IOptionsService=t.ILogService=t.LogLevelEnum=t.IInstantiationService=t.ICharsetService=t.ICoreService=t.ICoreMouseService=t.IBufferService=void 0;let r=n(8343);var i;t.IBufferService=(0,r.createDecorator)(`BufferService`),t.ICoreMouseService=(0,r.createDecorator)(`CoreMouseService`),t.ICoreService=(0,r.createDecorator)(`CoreService`),t.ICharsetService=(0,r.createDecorator)(`CharsetService`),t.IInstantiationService=(0,r.createDecorator)(`InstantiationService`),function(e){e[e.TRACE=0]=`TRACE`,e[e.DEBUG=1]=`DEBUG`,e[e.INFO=2]=`INFO`,e[e.WARN=3]=`WARN`,e[e.ERROR=4]=`ERROR`,e[e.OFF=5]=`OFF`}(i||(t.LogLevelEnum=i={})),t.ILogService=(0,r.createDecorator)(`LogService`),t.IOptionsService=(0,r.createDecorator)(`OptionsService`),t.IOscLinkService=(0,r.createDecorator)(`OscLinkService`),t.IUnicodeService=(0,r.createDecorator)(`UnicodeService`),t.IDecorationService=(0,r.createDecorator)(`DecorationService`)},1480:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.UnicodeService=void 0;let r=n(8460),i=n(225);class a{static extractShouldJoin(e){return(1&e)!=0}static extractWidth(e){return e>>1&3}static extractCharKind(e){return e>>3}static createPropertyValue(e,t,n=!1){return(16777215&e)<<3|(3&t)<<1|!!n}constructor(){this._providers=Object.create(null),this._active=``,this._onChange=new r.EventEmitter,this.onChange=this._onChange.event;let e=new i.UnicodeV6;this.register(e),this._active=e.version,this._activeProvider=e}dispose(){this._onChange.dispose()}get versions(){return Object.keys(this._providers)}get activeVersion(){return this._active}set activeVersion(e){if(!this._providers[e])throw Error(`unknown Unicode version "${e}"`);this._active=e,this._activeProvider=this._providers[e],this._onChange.fire(e)}register(e){this._providers[e.version]=e}wcwidth(e){return this._activeProvider.wcwidth(e)}getStringCellWidth(e){let t=0,n=0,r=e.length;for(let i=0;i<r;++i){let o=e.charCodeAt(i);if(55296<=o&&o<=56319){if(++i>=r)return t+this.wcwidth(o);let n=e.charCodeAt(i);56320<=n&&n<=57343?o=1024*(o-55296)+n-56320+65536:t+=this.wcwidth(n)}let s=this.charProperties(o,n),c=a.extractWidth(s);a.extractShouldJoin(s)&&(c-=a.extractWidth(n)),t+=c,n=s}return t}charProperties(e,t){return this._activeProvider.charProperties(e,t)}}t.UnicodeService=a}},t={};function n(r){var i=t[r];if(i!==void 0)return i.exports;var a=t[r]={exports:{}};return e[r].call(a.exports,a,a.exports,n),a.exports}var r={};return(()=>{var e=r;Object.defineProperty(e,"__esModule",{value:!0}),e.Terminal=void 0;let t=n(9042),i=n(3236),a=n(844),o=n(5741),s=n(8285),c=n(7975),l=n(7090),u=[`cols`,`rows`];class d extends a.Disposable{constructor(e){super(),this._core=this.register(new i.Terminal(e)),this._addonManager=this.register(new o.AddonManager),this._publicOptions={...this._core.options};let t=e=>this._core.options[e],n=(e,t)=>{this._checkReadonlyOptions(e),this._core.options[e]=t};for(let e in this._core.options){let r={get:t.bind(this,e),set:n.bind(this,e)};Object.defineProperty(this._publicOptions,e,r)}}_checkReadonlyOptions(e){if(u.includes(e))throw Error(`Option "${e}" can only be set in the constructor`)}_checkProposedApi(){if(!this._core.optionsService.rawOptions.allowProposedApi)throw Error(`You must set the allowProposedApi option to true to use proposed API`)}get onBell(){return this._core.onBell}get onBinary(){return this._core.onBinary}get onCursorMove(){return this._core.onCursorMove}get onData(){return this._core.onData}get onKey(){return this._core.onKey}get onLineFeed(){return this._core.onLineFeed}get onRender(){return this._core.onRender}get onResize(){return this._core.onResize}get onScroll(){return this._core.onScroll}get onSelectionChange(){return this._core.onSelectionChange}get onTitleChange(){return this._core.onTitleChange}get onWriteParsed(){return this._core.onWriteParsed}get element(){return this._core.element}get parser(){return this._parser||=new c.ParserApi(this._core),this._parser}get unicode(){return this._checkProposedApi(),new l.UnicodeApi(this._core)}get textarea(){return this._core.textarea}get rows(){return this._core.rows}get cols(){return this._core.cols}get buffer(){return this._buffer||=this.register(new s.BufferNamespaceApi(this._core)),this._buffer}get markers(){return this._checkProposedApi(),this._core.markers}get modes(){let e=this._core.coreService.decPrivateModes,t=`none`;switch(this._core.coreMouseService.activeProtocol){case`X10`:t=`x10`;break;case`VT200`:t=`vt200`;break;case`DRAG`:t=`drag`;break;case`ANY`:t=`any`}return{applicationCursorKeysMode:e.applicationCursorKeys,applicationKeypadMode:e.applicationKeypad,bracketedPasteMode:e.bracketedPasteMode,insertMode:this._core.coreService.modes.insertMode,mouseTrackingMode:t,originMode:e.origin,reverseWraparoundMode:e.reverseWraparound,sendFocusMode:e.sendFocus,wraparoundMode:e.wraparound}}get options(){return this._publicOptions}set options(e){for(let t in e)this._publicOptions[t]=e[t]}blur(){this._core.blur()}focus(){this._core.focus()}input(e,t=!0){this._core.input(e,t)}resize(e,t){this._verifyIntegers(e,t),this._core.resize(e,t)}open(e){this._core.open(e)}attachCustomKeyEventHandler(e){this._core.attachCustomKeyEventHandler(e)}attachCustomWheelEventHandler(e){this._core.attachCustomWheelEventHandler(e)}registerLinkProvider(e){return this._core.registerLinkProvider(e)}registerCharacterJoiner(e){return this._checkProposedApi(),this._core.registerCharacterJoiner(e)}deregisterCharacterJoiner(e){this._checkProposedApi(),this._core.deregisterCharacterJoiner(e)}registerMarker(e=0){return this._verifyIntegers(e),this._core.registerMarker(e)}registerDecoration(e){return this._checkProposedApi(),this._verifyPositiveIntegers(e.x??0,e.width??0,e.height??0),this._core.registerDecoration(e)}hasSelection(){return this._core.hasSelection()}select(e,t,n){this._verifyIntegers(e,t,n),this._core.select(e,t,n)}getSelection(){return this._core.getSelection()}getSelectionPosition(){return this._core.getSelectionPosition()}clearSelection(){this._core.clearSelection()}selectAll(){this._core.selectAll()}selectLines(e,t){this._verifyIntegers(e,t),this._core.selectLines(e,t)}dispose(){super.dispose()}scrollLines(e){this._verifyIntegers(e),this._core.scrollLines(e)}scrollPages(e){this._verifyIntegers(e),this._core.scrollPages(e)}scrollToTop(){this._core.scrollToTop()}scrollToBottom(){this._core.scrollToBottom()}scrollToLine(e){this._verifyIntegers(e),this._core.scrollToLine(e)}clear(){this._core.clear()}write(e,t){this._core.write(e,t)}writeln(e,t){this._core.write(e),this._core.write(`\r
|
|
371
|
-
`,t)}paste(e){this._core.paste(e)}refresh(e,t){this._verifyIntegers(e,t),this._core.refresh(e,t)}reset(){this._core.reset()}clearTextureAtlas(){this._core.clearTextureAtlas()}loadAddon(e){this._addonManager.loadAddon(this,e)}static get strings(){return t}_verifyIntegers(...e){for(let t of e)if(t===1/0||isNaN(t)||t%1!=0)throw Error(`This API only accepts integers`)}_verifyPositiveIntegers(...e){for(let t of e)if(t&&(t===1/0||isNaN(t)||t%1!=0||t<0))throw Error(`This API only accepts positive integers`)}}e.Terminal=d})(),r})()))}))(),eN=2,tN=1,nN=class{activate(e){this._terminal=e}dispose(){}fit(){let e=this.proposeDimensions();if(!e||!this._terminal||isNaN(e.cols)||isNaN(e.rows))return;let t=this._terminal._core;(this._terminal.rows!==e.rows||this._terminal.cols!==e.cols)&&(t._renderService.clear(),this._terminal.resize(e.cols,e.rows))}proposeDimensions(){if(!this._terminal||!this._terminal.element||!this._terminal.element.parentElement)return;let e=this._terminal._core._renderService.dimensions;if(e.css.cell.width===0||e.css.cell.height===0)return;let t=this._terminal.options.scrollback===0?0:this._terminal.options.overviewRuler?.width||14,n=window.getComputedStyle(this._terminal.element.parentElement),r=parseInt(n.getPropertyValue(`height`)),i=Math.max(0,parseInt(n.getPropertyValue(`width`))),a=window.getComputedStyle(this._terminal.element),o={top:parseInt(a.getPropertyValue(`padding-top`)),bottom:parseInt(a.getPropertyValue(`padding-bottom`)),right:parseInt(a.getPropertyValue(`padding-right`)),left:parseInt(a.getPropertyValue(`padding-left`))},s=o.top+o.bottom,c=o.right+o.left,l=r-s,u=i-c-t;return{cols:Math.max(eN,Math.floor(u/e.css.cell.width)),rows:Math.max(tN,Math.floor(l/e.css.cell.height))}}},rN=class{constructor(e,t,n,r={}){this._terminal=e,this._regex=t,this._handler=n,this._options=r}provideLinks(e,t){let n=aN.computeLink(e,this._regex,this._terminal,this._handler);t(this._addCallbacks(n))}_addCallbacks(e){return e.map(e=>(e.leave=this._options.leave,e.hover=(t,n)=>{if(this._options.hover){let{range:r}=e;this._options.hover(t,n,r)}},e))}};function iN(e){try{let t=new URL(e),n=t.password&&t.username?`${t.protocol}//${t.username}:${t.password}@${t.host}`:t.username?`${t.protocol}//${t.username}@${t.host}`:`${t.protocol}//${t.host}`;return e.toLocaleLowerCase().startsWith(n.toLocaleLowerCase())}catch{return!1}}var aN=class e{static computeLink(t,n,r,i){let a=new RegExp(n.source,(n.flags||``)+`g`),[o,s]=e._getWindowedLineStrings(t-1,r),c=o.join(``),l,u=[];for(;l=a.exec(c);){let t=l[0];if(!iN(t))continue;let[n,a]=e._mapStrIdx(r,s,0,l.index),[o,c]=e._mapStrIdx(r,n,a,t.length);if(n===-1||a===-1||o===-1||c===-1)continue;let d={start:{x:a+1,y:n+1},end:{x:c,y:o+1}};u.push({range:d,text:t,activate:i})}return u}static _getWindowedLineStrings(e,t){let n,r=e,i=e,a=0,o=``,s=[];if(n=t.buffer.active.getLine(e)){let e=n.translateToString(!0);if(n.isWrapped&&e[0]!==` `){for(a=0;(n=t.buffer.active.getLine(--r))&&a<2048&&(o=n.translateToString(!0),a+=o.length,s.push(o),!(!n.isWrapped||o.indexOf(` `)!==-1)););s.reverse()}for(s.push(e),a=0;(n=t.buffer.active.getLine(++i))&&n.isWrapped&&a<2048&&(o=n.translateToString(!0),a+=o.length,s.push(o),o.indexOf(` `)===-1););}return[s,r]}static _mapStrIdx(e,t,n,r){let i=e.buffer.active,a=i.getNullCell(),o=n;for(;r;){let e=i.getLine(t);if(!e)return[-1,-1];for(let n=o;n<e.length;++n){e.getCell(n,a);let o=a.getChars();if(a.getWidth()&&(r-=o.length||1,n===e.length-1&&o===``)){let e=i.getLine(t+1);e&&e.isWrapped&&(e.getCell(0,a),a.getWidth()===2&&(r+=1))}if(r<0)return[t,n]}t++,o=0}return[t,o]}},oN=/(https?|HTTPS?):[/]{2}[^\s"'!*(){}|\\\^<>`]*[^\s"':,.!?{}|\\\^~\[\]`()<>]/;function sN(e,t){let n=window.open();if(n){try{n.opener=null}catch{}n.location.href=t}else console.warn(`Opening link blocked as opener could not be cleared`)}var cN=class{constructor(e=sN,t={}){this._handler=e,this._options=t}activate(e){this._terminal=e;let t=this._options,n=t.urlRegex||oN;this._linkProvider=this._terminal.registerLinkProvider(new rN(this._terminal,n,this._handler,t))}dispose(){this._linkProvider?.dispose()}},lN=`forge.terminal.tabs.v1`;function uN(){try{if(sessionStorage.getItem(lN)===null){let e=localStorage.getItem(lN);e!==null&&(sessionStorage.setItem(lN,e),localStorage.removeItem(lN))}let e=sessionStorage.getItem(lN);if(e===null)return{tabs:[],activeTabId:void 0};let t=JSON.parse(e);if(typeof t!=`object`||!t||!Array.isArray(t.tabs))return{tabs:[],activeTabId:void 0};let n=[];for(let e of t.tabs)typeof e==`object`&&e&&typeof e.id==`string`&&typeof e.projectId==`string`&&typeof e.label==`string`&&typeof e.createdAt==`number`&&n.push(e);let r=t.activeTabId,i=typeof r==`string`?r:void 0;return{tabs:n,activeTabId:n.some(e=>e.id===i)?i:n[0]?.id}}catch{return{tabs:[],activeTabId:void 0}}}function dN(e){try{sessionStorage.setItem(lN,JSON.stringify(e))}catch{}}var fN=0,pN=()=>`term-${Date.now().toString(36)}-${(fN++).toString(36)}`,mN=uN(),hN=pt(e=>({tabs:mN.tabs,activeTabId:mN.activeTabId,openTab:t=>{let n=pN();return e(e=>{let r={id:n,projectId:t,label:`Terminal ${e.tabs.filter(e=>e.projectId===t).length+1}`,createdAt:Date.now()},i={tabs:[...e.tabs,r],activeTabId:n};return dN(i),i}),n},closeTab:t=>{e(e=>{let n=e.tabs.findIndex(e=>e.id===t);if(n===-1)return{};let r=e.tabs.slice(0,n).concat(e.tabs.slice(n+1)),i={tabs:r,activeTabId:e.activeTabId===t?(r[n]??r[n-1]??r[0])?.id:e.activeTabId};return dN(i),i})},setActiveTab:t=>e(e=>(dN({tabs:{...e,activeTabId:t}.tabs,activeTabId:t}),{activeTabId:t})),closeProjectTabs:t=>{e(e=>{let n=e.tabs.filter(e=>e.projectId!==t),r={tabs:n,activeTabId:n.some(t=>t.id===e.activeTabId)?e.activeTabId:n[0]?.id};return dN(r),r})}})),gN=new Map;function _N(e){let t=[1,2,4,8,16,30];return(t[Math.min(e,t.length-1)]??30)*1e3}function vN(e){return e===1e3||e===4401||e===4404}function yN(){let e=dr(),t=hN(e=>e.tabs),n=hN(e=>e.activeTabId),r=hN(e=>e.openTab),i=hN(e=>e.closeTab),a=hN(e=>e.setActiveTab),o=ur(e=>e.projects),s=t.filter(t=>t.projectId===e?.id),c=s.find(e=>e.id===n)??s[0],l=new Map(o.map(e=>[e.id,e.path]));if(e===void 0)return(0,R.jsx)(`div`,{className:`flex h-full items-center justify-center text-xs italic text-neutral-500`,children:`Select a project to open a terminal.`});let u=()=>{r(e.id)},d=e=>{SN(e),i(e)};return(0,R.jsxs)(`div`,{className:`flex h-full flex-col bg-black`,children:[(0,R.jsx)(`div`,{className:`flex items-center justify-between border-b border-neutral-800 bg-neutral-900/40 px-2 py-1`,children:(0,R.jsxs)(`div`,{className:`flex items-center gap-1 overflow-x-auto`,children:[s.length===0&&(0,R.jsx)(`span`,{className:`px-2 text-[11px] italic text-neutral-500`,children:`No terminals open.`}),s.map(e=>(0,R.jsxs)(`div`,{className:`group flex items-center gap-1 rounded px-2 py-0.5 text-xs ${e.id===c?.id?`bg-neutral-800 text-neutral-100`:`text-neutral-400 hover:bg-neutral-900 hover:text-neutral-200`}`,children:[(0,R.jsxs)(`button`,{onClick:()=>a(e.id),className:`flex items-center gap-1`,children:[(0,R.jsx)(Ze,{size:11}),e.label]}),(0,R.jsx)(`button`,{onClick:()=>d(e.id),className:`rounded p-1 text-neutral-600 hover:bg-neutral-800 hover:text-neutral-200`,title:`Close terminal (kills the PTY)`,children:(0,R.jsx)(it,{size:16})})]},e.id)),(0,R.jsxs)(`button`,{onClick:u,className:`ml-1 flex items-center gap-1 rounded px-2 py-0.5 text-xs text-neutral-400 hover:bg-neutral-900 hover:text-neutral-200 light:text-neutral-200 light:hover:bg-neutral-800 light:hover:text-neutral-50`,title:`New terminal`,children:[(0,R.jsx)(He,{size:14}),`New`]})]})}),(0,R.jsxs)(`div`,{className:`relative flex-1 overflow-hidden`,children:[s.length===0&&(0,R.jsxs)(`div`,{className:`flex h-full items-center justify-center text-xs italic text-neutral-500`,children:[`Click "New" to open a terminal in `,e.path,`.`]}),t.map(t=>(0,R.jsx)(bN,{tab:t,projectPath:l.get(t.projectId)??``,visible:t.projectId===e.id&&t.id===c?.id},t.id))]})]})}function bN({tab:e,projectPath:t,visible:n}){let r=(0,v.useRef)(null);return(0,v.useEffect)(()=>{if(r.current===null)return;let t=r.current,n=gN.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),n.fit.fit()}catch{}let e=new ResizeObserver(()=>{try{n.fit.fit()}catch{}let e=n.term.cols,t=n.term.rows;e===n.lastSize.cols&&t===n.lastSize.rows||(n.lastSize={cols:e,rows:t},n.ws.readyState===WebSocket.OPEN&&n.ws.send(JSON.stringify({type:`resize`,cols:e,rows:t})))});e.observe(t);try{n.observer.disconnect()}catch{}return n.observer=e,requestAnimationFrame(()=>{try{n.fit.fit(),n.term.focus()}catch{}}),()=>{try{e.disconnect()}catch{}}}let i=new $M.Terminal({theme:{background:rC(`--pi-terminal-bg`,`#0a0a0a`),foreground:rC(`--pi-terminal-fg`,`#e5e5e5`),cursor:rC(`--pi-terminal-fg`,`#e5e5e5`),black:rC(`--color-neutral-800`,`#262626`),brightBlack:rC(`--color-neutral-600`,`#525252`)},fontFamily:`ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace`,fontSize:13,cursorBlink:!0,scrollback:5e3,convertEol:!1}),a=new nN,o=new cN;i.loadAddon(a),i.loadAddon(o),i.open(t),a.fit();let s={cols:i.cols,rows:i.rows},c=xN(e.id,e.projectId,i,s,!1);i.onData(t=>{let n=gN.get(e.id)?.ws;n?.readyState===WebSocket.OPEN&&n.send(JSON.stringify({type:`input`,data:t}))});let l=new ResizeObserver(()=>{try{a.fit()}catch{}let t=i.cols,n=i.rows,r=gN.get(e.id);r!==void 0&&(t===r.lastSize.cols&&n===r.lastSize.rows||(r.lastSize={cols:t,rows:n},r.ws.readyState===WebSocket.OPEN&&r.ws.send(JSON.stringify({type:`resize`,cols:t,rows:n}))))});return l.observe(r.current),gN.set(e.id,{term:i,fit:a,ws:c,observer:l,lastSize:s,reconnectAttempt:0,reconnectTimer:void 0,disposed:!1}),()=>{try{l.disconnect()}catch{}}},[e.id]),(0,v.useEffect)(()=>{if(!n)return;let t=gN.get(e.id);t!==void 0&&requestAnimationFrame(()=>{try{t.fit.fit(),t.term.focus()}catch{}})},[n,e.id]),(0,v.useEffect)(()=>{let t=gN.get(e.id);t!==void 0&&(t.term.options.theme={background:rC(`--pi-terminal-bg`,`#0a0a0a`),foreground:rC(`--pi-terminal-fg`,`#e5e5e5`),cursor:rC(`--pi-terminal-fg`,`#e5e5e5`),black:rC(`--color-neutral-800`,`#262626`),brightBlack:rC(`--color-neutral-600`,`#525252`)})},[tC(e=>e.theme),e.id]),(0,R.jsx)(`div`,{ref:r,onClick:()=>{gN.get(e.id)?.term.focus()},className:`absolute inset-y-0 left-2 right-0`,style:{visibility:n?`visible`:`hidden`,pointerEvents:n?`auto`:`none`,zIndex:+!!n},title:t})}function xN(e,t,n,r,i){let a=window.location.protocol===`https:`?`wss`:`ws`,o=Vt(),s=o===void 0?``:`&token=${encodeURIComponent(o.token)}`,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=()=>{l.send(JSON.stringify({type:`resize`,cols:r.cols,rows:r.rows}));let t=gN.get(e);t!==void 0&&(t.reconnectAttempt=0)},l.onmessage=e=>{typeof e.data==`string`?n.write(e.data):e.data instanceof ArrayBuffer&&n.write(new Uint8Array(e.data))},l.onclose=r=>{let i=gN.get(e);if(i===void 0||i.disposed)return;if(vN(r.code)){let e=`[connection closed: ${String(r.code)}]`;r.code===4401?e=`[connection closed (4401): your 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=_N(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=gN.get(e);r===void 0||r.disposed||(r.reconnectTimer=void 0,r.ws=xN(e,t,n,r.lastSize,!0))},o)},l}function SN(e){let t=gN.get(e);if(t!==void 0){t.disposed=!0,t.reconnectTimer!==void 0&&clearTimeout(t.reconnectTimer),gN.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 CN(){let e=st(),[t,n]=(0,v.useState)(``),[r,i]=(0,v.useState)([]),[a,o]=(0,v.useState)(!1),[s,c]=(0,v.useState)(!1),[l,u]=(0,v.useState)(void 0),[d,f]=(0,v.useState)(0),p=(0,v.useRef)(null),m=(0,v.useRef)(null),h=(0,v.useRef)(void 0),g=ur(e=>e.setActive),_=ur(e=>e.activeProjectId),y=Jr(e=>e.setActiveSession),b=Jr(e=>e.requestScrollToMessage),x=(0,v.useMemo)(()=>{let e=[];return r.forEach((t,n)=>{t.matches.forEach((r,i)=>{e.push({group:t,match:r,groupIndex:n,matchIndex:i})})}),e},[r]);if((0,v.useEffect)(()=>{f(0)},[r]),(0,v.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&e.key.toLowerCase()===`k`&&(e.preventDefault(),p.current?.focus(),p.current?.select())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[]),(0,v.useEffect)(()=>{if(!a)return;let e=e=>{m.current!==null&&(m.current.contains(e.target)||o(!1))};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[a]),(0,v.useEffect)(()=>{if(t.trim().length===0){i([]),u(void 0),c(!1),h.current?.abort();return}let e=new AbortController;h.current?.abort(),h.current=e,c(!0),u(void 0);let n=window.setTimeout(()=>{L.searchSessions(t.trim(),{signal:e.signal}).then(t=>{e.signal.aborted||(i(t.results),c(!1),o(!0))}).catch(t=>{e.signal.aborted||(c(!1),u(t instanceof Error?t.message:`search failed`))})},250);return()=>{window.clearTimeout(n),e.abort()}},[t]),e)return null;let S=(e,t)=>{b(e.sessionId,t.messageIndex),_!==e.projectId&&g(e.projectId),y(e.sessionId),o(!1),n(``),p.current?.blur()},C=e=>{if(e.key===`Escape`){o(!1),p.current?.blur();return}if(!(!a||x.length===0)){if(e.key===`ArrowDown`)e.preventDefault(),f(e=>Math.min(x.length-1,e+1));else if(e.key===`ArrowUp`)e.preventDefault(),f(e=>Math.max(0,e-1));else if(e.key===`Enter`){e.preventDefault();let t=x[d];t!==void 0&&S(t.group,t.match)}}},w=e=>{let t=e.snippet.slice(0,e.matchOffset),n=e.snippet.slice(e.matchOffset,e.matchOffset+e.matchLength),r=e.snippet.slice(e.matchOffset+e.matchLength);return(0,R.jsxs)(R.Fragment,{children:[t,(0,R.jsx)(`mark`,{className:`rounded bg-amber-300/30 text-amber-100 light:bg-amber-200 light:text-amber-900`,children:n}),r]})},T=e=>e===`user`?`you`:e===`assistant`?`agent`:`tool`;return(0,R.jsxs)(`div`,{ref:m,className:`relative`,children:[(0,R.jsxs)(`div`,{className:`relative`,children:[(0,R.jsx)(qe,{size:13,className:`pointer-events-none absolute left-2 top-1/2 -translate-y-1/2 text-neutral-500`,"aria-hidden":`true`}),(0,R.jsx)(`input`,{ref:p,type:`text`,value:t,onChange:e=>n(e.target.value),onFocus:()=>{r.length>0&&o(!0)},onKeyDown:C,placeholder:`Search sessions… ⌘K`,"aria-label":`Search across all sessions`,className:`w-64 rounded-md border border-neutral-700 bg-neutral-900 py-1 pl-7 pr-7 text-xs text-neutral-200 placeholder-neutral-500 focus:border-neutral-500 focus:outline-none`}),t.length>0&&(0,R.jsx)(`button`,{type:`button`,onClick:()=>{n(``),i([]),o(!1),p.current?.focus()},"aria-label":`Clear search`,className:`absolute right-1 top-1/2 -translate-y-1/2 rounded p-0.5 text-neutral-500 hover:bg-neutral-800 hover:text-neutral-200`,children:(0,R.jsx)(it,{size:12})})]}),a&&(0,R.jsxs)(`div`,{role:`listbox`,"aria-label":`Search results`,className:`absolute right-0 top-full z-50 mt-1 max-h-[60vh] w-96 overflow-y-auto rounded-md border border-neutral-700 bg-neutral-900 shadow-xl`,children:[s&&(0,R.jsx)(`div`,{className:`px-3 py-2 text-xs text-neutral-400`,children:`Searching…`}),!s&&l!==void 0&&(0,R.jsx)(`div`,{className:`px-3 py-2 text-xs text-amber-400 light:text-amber-700`,children:l}),!s&&l===void 0&&x.length===0&&(0,R.jsx)(`div`,{className:`px-3 py-2 text-xs text-neutral-500`,children:`No matches.`}),x.length>0&&(0,R.jsx)(`div`,{children:r.map((e,t)=>(0,R.jsxs)(`div`,{className:`border-b border-neutral-800 last:border-b-0`,children:[(0,R.jsxs)(`div`,{className:`bg-neutral-950 px-3 py-1 text-[10px] uppercase tracking-wider text-neutral-500`,children:[(0,R.jsx)(`span`,{className:`text-neutral-300`,children:e.projectName}),e.sessionName!==void 0&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`span`,{className:`mx-1.5 text-neutral-600`,children:`/`}),(0,R.jsx)(`span`,{className:`text-neutral-400 normal-case tracking-normal`,children:e.sessionName})]})]}),e.matches.map((n,r)=>{let i=x.findIndex(e=>e.groupIndex===t&&e.matchIndex===r),a=i===d;return(0,R.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":a,onMouseEnter:()=>f(i),onClick:()=>S(e,n),className:`flex w-full items-start gap-2 px-3 py-1.5 text-left text-xs ${a?`bg-neutral-800 text-neutral-100`:`text-neutral-300 hover:bg-neutral-800/60`}`,children:[(0,R.jsx)(`span`,{className:`mt-0.5 shrink-0 rounded bg-neutral-800 px-1 py-0.5 text-[9px] uppercase tracking-wider text-neutral-400`,children:T(n.kind)}),(0,R.jsx)(`span`,{className:`flex-1 break-words`,children:w(n)})]},`${n.messageIndex}-${n.matchOffset}`)})]},e.sessionId))})]})]})}function wN(){let e=Cj(e=>e.settings),t=JA(e=>e.openSettings);if(e===void 0||e.total===0&&e.enabled)return null;let{enabled:n,connected:r,total:i}=e,a=n?r===i?`bg-emerald-500`:r===0?`bg-red-500`:`bg-amber-400`:`bg-neutral-600`,o=n?`MCP ${r}/${i}`:`MCP off`;return(0,R.jsxs)(`button`,{type:`button`,onClick:()=>t(`mcp`),className:`inline-flex items-center gap-1.5 rounded-md border border-neutral-700 px-2 py-1 text-xs text-neutral-300 hover:border-neutral-500 hover:text-neutral-100`,title:n?`${r} of ${i} MCP server(s) connected. Click to open Settings → MCP.`:`MCP tools disabled. Click to open Settings → MCP.`,children:[(0,R.jsx)(`span`,{className:`h-2 w-2 rounded-full ${a}`}),o]})}var TN=`forge.turnDiff.viewType`;function EN(){try{return localStorage.getItem(TN)===`split`?`split`:`unified`}catch{return`unified`}}function DN(){let e=Jr(e=>e.activeSessionId),t=Jr(t=>e===void 0?0:t.agentEndCountBySession[e]??0),n=Jr(t=>e===void 0?!1:t.streamingBySession[e]??!1),[r,i]=(0,v.useState)([]),[a,o]=(0,v.useState)(void 0),[s,c]=(0,v.useState)(!1),[l,u]=(0,v.useState)({}),[d,f]=(0,v.useState)(EN),p=e=>{f(e);try{localStorage.setItem(TN,e)}catch{}},m=async()=>{if(e!==void 0){c(!0),o(void 0);try{i((await L.getTurnDiff(e)).entries)}catch(e){e instanceof N&&e.status===404?i([]):(i([]),o(e instanceof N?e.code:e.message))}finally{c(!1)}}};return(0,v.useEffect)(()=>{i([]),o(void 0)},[e]),(0,v.useEffect)(()=>{e===void 0||n||m()},[e,t,n]),e===void 0?(0,R.jsx)(`div`,{className:`flex h-full items-center justify-center px-4 text-center text-xs italic text-neutral-500`,children:`Pick a session to see its file changes.`}):(0,R.jsxs)(`div`,{className:`flex h-full flex-col text-xs text-neutral-300`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between border-b border-neutral-800 px-3 py-2`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2 font-medium text-neutral-200`,children:[(0,R.jsx)(Se,{size:13}),`Last turn`,r.length>0&&(0,R.jsx)(`span`,{className:`rounded bg-neutral-800 px-1.5 py-0.5 text-[10px] text-neutral-400`,children:r.length})]}),(0,R.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,R.jsx)(`button`,{onClick:()=>p(d===`split`?`unified`:`split`),className:`rounded p-1 text-neutral-400 hover:bg-neutral-800 hover:text-neutral-200`,title:d===`split`?`Switch to unified view`:`Switch to side-by-side view`,children:d===`split`?(0,R.jsx)(Ge,{size:13}):(0,R.jsx)(_e,{size:13})}),(0,R.jsx)(`button`,{onClick:()=>void m(),className:`rounded p-1 text-neutral-400 hover:bg-neutral-800 hover:text-neutral-200`,title:`Refresh diff`,children:(0,R.jsx)(Ue,{size:13,className:s?`animate-spin`:``})})]})]}),a!==void 0&&(0,R.jsx)(`div`,{className:`border-b border-red-700/40 bg-red-900/20 px-3 py-1.5 text-[11px] text-red-300`,children:a}),(0,R.jsxs)(`div`,{className:`flex-1 overflow-y-auto`,children:[r.length===0&&(0,R.jsx)(`p`,{className:`px-3 py-3 italic text-neutral-500`,children:s?`Loading…`:a===void 0?`No file changes from the most recent turn.`:`Couldn't load the latest turn diff (see banner).`}),r.map(e=>{let t=l[e.file]??!1,n=e.file.split(`/`).pop()??e.file;return(0,R.jsxs)(`div`,{className:`border-b border-neutral-800/60`,children:[(0,R.jsxs)(`button`,{onClick:()=>u(n=>({...n,[e.file]:!t})),className:`flex w-full items-center justify-between gap-2 px-3 py-2 text-left hover:bg-neutral-900`,title:e.file,children:[(0,R.jsxs)(`span`,{className:`flex min-w-0 items-baseline gap-2`,children:[(0,R.jsx)(`span`,{className:`truncate font-mono text-neutral-200`,children:n}),e.isPureAddition&&(0,R.jsx)(`span`,{className:`rounded bg-emerald-900/40 px-1 py-0.5 text-[9px] uppercase tracking-wider text-emerald-300 light:bg-emerald-100 light:text-emerald-800`,children:`new`})]}),(0,R.jsxs)(`span`,{className:`flex shrink-0 items-baseline gap-2 text-[11px]`,children:[(0,R.jsxs)(`span`,{className:`text-emerald-400 light:text-emerald-700`,children:[`+`,e.additions]}),(0,R.jsxs)(`span`,{className:`text-red-400 light:text-red-700`,children:[`−`,e.deletions]})]})]}),t&&(0,R.jsx)(mk,{diff:e.diff,viewType:d})]},e.file)})]})]})}var ON=15e3;function kN(e){let[t,n]=(0,v.useState)(void 0),[r,i]=(0,v.useState)(void 0),a=Jr(e=>e.activeSessionId),o=Jr(e=>a===void 0?!1:e.streamingBySession[a]??!1),s=Jr(e=>a===void 0?0:e.agentEndCountBySession[a]??0),c=(0,v.useRef)(0),l=async()=>{if(e===void 0)return;let t=c.current,r=e;try{let e=await L.gitStatus(r);if(c.current!==t)return;n(e),i(void 0)}catch(e){if(c.current!==t)return;i(e instanceof N?e.code:e.message)}};return(0,v.useEffect)(()=>{c.current+=1,n(void 0),i(void 0)},[e]),(0,v.useEffect)(()=>{if(e===void 0)return;if(l(),o)return()=>void 0;let t=window.setInterval(()=>{l()},ON);return()=>{window.clearInterval(t)}},[e,o]),(0,v.useEffect)(()=>{e!==void 0&&s!==0&&l()},[e,a,s]),{status:t,error:r,refresh:l}}function AN(e){let t=[],n=[];for(let r of e){let e=t.slice(),i=t.findIndex(e=>e===r.hash);i===-1&&(i=t.findIndex(e=>e===void 0),i===-1&&(i=t.length,t.push(void 0)));let a=[];for(let e=0;e<t.length;e++)t[e]===r.hash&&a.push(e);for(let e of a)t[e]=void 0;let o=[];if(r.parents.length>0){let e=r.parents[0];t[i]=e,o.push({lane:i,parent:e})}for(let e=1;e<r.parents.length;e++){let n=r.parents[e],i=t.findIndex(e=>e===n);i===-1&&(i=t.findIndex(e=>e===void 0),i===-1&&(i=t.length,t.push(void 0)),t[i]=n),o.push({lane:i,parent:n})}for(;t.length>0&&t[t.length-1]===void 0;)t.pop();let s=[];for(let t=0;t<e.length;t++)e[t]!==void 0&&t!==i&&(a.includes(t)||s.push(t));let c=Math.max(i+1,t.length,...a.map(e=>e+1),...o.map(e=>e.lane+1),...s.map(e=>e+1));n.push({hash:r.hash,lane:i,incomingLanes:a,outgoingLanes:o,through:s,width:c})}return n}var jN=[`#a5b4fc`,`#fde047`,`#a3e635`,`#f472b6`,`#67e8f9`,`#fb923c`,`#c084fc`,`#86efac`];function MN(e){return jN[e%jN.length]??`#a5b4fc`}function NN(){let e=dr(),{status:t,error:n,refresh:r}=kN(e?.id),[i,a]=(0,v.useState)(``),[o,s]=(0,v.useState)(!1),[c,l]=(0,v.useState)(void 0),[u,d]=(0,v.useState)(void 0),[f,p]=(0,v.useState)(void 0),[m,h]=(0,v.useState)(void 0),[g,_]=(0,v.useState)(void 0),[y,b]=(0,v.useState)(!1),[x,S]=(0,v.useState)(!1),[C,w]=(0,v.useState)(!1),[T,E]=(0,v.useState)(void 0),[D,O]=(0,v.useState)(void 0),[k,ee]=(0,v.useState)(void 0),[A,te]=(0,v.useState)(!1),[ne,re]=(0,v.useState)(``),[ie,j]=(0,v.useState)(``),[ae,M]=(0,v.useState)(void 0),oe=async()=>{if(e!==void 0)try{_((await L.gitRemotes(e.id)).remotes)}catch(e){l(e instanceof N?e.code:e.message)}},se=async()=>{if(e===void 0)return;let t=ne.trim(),n=ie.trim();if(!(t.length===0||n.length===0)){ee(t),l(void 0);try{await L.gitRemoteAdd(e.id,t,n),te(!1),re(``),j(``),await oe()}catch(e){l(e instanceof N?e.message||e.code:e.message)}finally{ee(void 0)}}},ce=async()=>{if(e===void 0||ae===void 0)return;let t=ae;M(void 0),ee(t),l(void 0);try{await L.gitRemoteRemove(e.id,t),await oe()}catch(e){l(e instanceof N?e.message||e.code:e.message)}finally{ee(void 0)}},ue=async()=>{if(e!==void 0)try{h((await L.gitBranches(e.id)).branches)}catch(e){l(e instanceof N?e.code:e.message)}},de=async t=>{if(e!==void 0){E(t),l(void 0);try{await L.gitCheckout(e.id,t),await ue(),r()}catch(e){l(e instanceof N?e.code:e.message)}finally{E(void 0)}}},fe=async t=>{if(e!==void 0){O(void 0),E(t),l(void 0);try{await L.gitBranchCreate(e.id,t,{checkout:!0}),await ue(),r()}catch(e){l(e instanceof N?e.code:e.message)}finally{E(void 0)}}},pe=async t=>{if(e===void 0||D?.kind!==`delete`)return;let{name:n}=D;O(void 0),E(n),l(void 0);try{await L.gitBranchDelete(e.id,n,t),await ue()}catch(e){l(e instanceof N?e.code:e.message)}finally{E(void 0)}},[me,he]=(0,v.useState)({}),[ge,ve]=(0,v.useState)(void 0),[ye,be]=(0,v.useState)(void 0),[xe,Se]=(0,v.useState)(``),[Ce,we]=(0,v.useState)(!1),[Te,Ee]=(0,v.useState)(!1),[ke,Ae]=(0,v.useState)(()=>{try{return localStorage.getItem(`forge.gitPanel.viewType`)===`split`?`split`:`unified`}catch{return`unified`}}),je=e=>{Ae(e);try{localStorage.setItem(`forge.gitPanel.viewType`,e)}catch{}};if((0,v.useEffect)(()=>{if(t===void 0)return;let e=new Set(t.files.map(e=>e.path));he(t=>{let n=!1,r={};for(let[i,a]of Object.entries(t)){let t=i.split(`|`)[0]??``;e.has(t)?r[i]=a:n=!0}return n?r:t})},[t]),(0,v.useEffect)(()=>{y&&e!==void 0&&L.gitLog(e.id,30).then(e=>p(e.commits)).catch(e=>l(e instanceof N?e.code:e.message))},[y,e?.id]),(0,v.useEffect)(()=>{x&&e!==void 0&&L.gitBranches(e.id).then(e=>h(e.branches)).catch(e=>l(e instanceof N?e.code:e.message))},[x,e?.id]),(0,v.useEffect)(()=>{C&&e!==void 0&&L.gitRemotes(e.id).then(e=>_(e.remotes)).catch(e=>l(e instanceof N?e.code:e.message))},[C,e?.id]),e===void 0)return(0,R.jsx)(`div`,{className:`flex h-full items-center justify-center px-4 text-center text-xs italic text-neutral-500`,children:`Pick a project to see its git status.`});if(t?.isGitRepo===!1){let t=async()=>{s(!0),l(void 0);try{await L.gitInit(e.id),await r()}catch(e){l(e instanceof N?e.code:e.message)}finally{s(!1)}};return(0,R.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-3 px-4 text-center text-xs text-neutral-500`,children:[(0,R.jsxs)(`p`,{className:`italic`,children:[e.name,` isn't a git repository.`]}),(0,R.jsx)(`button`,{onClick:()=>void t(),disabled:o,className:`rounded-md bg-neutral-100 px-3 py-1.5 text-xs font-medium text-neutral-900 hover:bg-white disabled:cursor-not-allowed disabled:opacity-50`,title:"Run `git init -b main` in the project root",children:o?`Initializing…`:`Initialize git repo`}),(0,R.jsxs)(`p`,{className:`text-[10px] text-neutral-600`,children:[`Default branch will be `,(0,R.jsx)(`code`,{className:`font-mono text-neutral-400`,children:`main`}),`.`]}),c!==void 0&&(0,R.jsxs)(`p`,{className:`text-[10px] text-red-400 light:text-red-700`,children:[`git init failed: `,c]})]})}let Me=t?.files.filter(e=>e.staged)??[],Ne=t?.files.filter(e=>e.unstaged)??[],Pe=t?.files.filter(e=>e.kind===`untracked`)??[],Fe=async(t,n)=>{let r=`${t.path}|${n?`staged`:`unstaged`}`;if(me[r]!==void 0){he(e=>{let t={...e};return delete t[r],t});return}he(e=>({...e,[r]:`loading`}));try{let i=await L.gitDiffFile(e.id,t.path,n);he(e=>({...e,[r]:i.diff}))}catch{he(e=>({...e,[r]:`error`}))}},Ie=async t=>{if(t.length!==0){s(!0),l(void 0);try{await L.gitStage(e.id,t),await r()}catch(e){l((e instanceof N,e.message))}finally{s(!1)}}},Le=async t=>{if(t.length!==0){s(!0),l(void 0),d(void 0);try{await L.gitRevert(e.id,t),d(t.length===1?`Reverted ${t[0]}`:`Reverted ${t.length} files`),await r()}catch(e){l((e instanceof N,e.message))}finally{s(!1)}}},Re=async t=>{if(t.length!==0){s(!0),l(void 0);try{await L.gitUnstage(e.id,t),await r()}catch(e){l((e instanceof N,e.message))}finally{s(!1)}}},ze=async(t,n,i)=>{ve(t.path),l(void 0);try{let a=await L.gitApplyHunks(e.id,t.path,i,[n]);if(a.ok!==!0){l(`Hunk apply failed: ${a.error??`unknown_error`}`);return}await Promise.all([Be(t,!0),Be(t,!1),r()])}catch(e){l((e instanceof N,e.message))}finally{ve(void 0)}},Be=async(t,n)=>{let r=`${t.path}|${n?`staged`:`unstaged`}`;if(me[r]!==void 0){he(e=>({...e,[r]:`loading`}));try{let i=await L.gitDiffFile(e.id,t.path,n);he(e=>{if(i.diff.length===0){let t={...e};return delete t[r],t}return{...e,[r]:i.diff}})}catch{he(e=>({...e,[r]:`error`}))}}},Ve=async()=>{let t=i.trim();if(t.length!==0){s(!0),l(void 0),d(void 0);try{let{hash:n}=await L.gitCommit(e.id,t);a(``),d(`Committed ${n.slice(0,7)}`),await r(),y&&p((await L.gitLog(e.id,30)).commits)}catch(e){l((e instanceof N,e.message))}finally{s(!1)}}},We=(()=>{if(g!==void 0)return g.map(e=>e.name).sort();if(m===void 0)return[];let e=new Set;for(let t of m){if(!t.remote)continue;let n=t.name.indexOf(`/`);n>0&&e.add(t.name.slice(0,n))}return Array.from(e).sort()})(),Ke=m===void 0?[]:m.filter(e=>!e.remote).map(e=>e.name).sort(),qe=async()=>{s(!0),l(void 0),d(void 0);try{let t={};ye!==void 0&&(t.remote=ye);let{output:n}=await L.gitFetch(e.id,t);d(n.trim().length>0?n.trim().split(`
|
|
371
|
+
`,t)}paste(e){this._core.paste(e)}refresh(e,t){this._verifyIntegers(e,t),this._core.refresh(e,t)}reset(){this._core.reset()}clearTextureAtlas(){this._core.clearTextureAtlas()}loadAddon(e){this._addonManager.loadAddon(this,e)}static get strings(){return t}_verifyIntegers(...e){for(let t of e)if(t===1/0||isNaN(t)||t%1!=0)throw Error(`This API only accepts integers`)}_verifyPositiveIntegers(...e){for(let t of e)if(t&&(t===1/0||isNaN(t)||t%1!=0||t<0))throw Error(`This API only accepts positive integers`)}}e.Terminal=d})(),r})()))}))(),iN=2,aN=1,oN=class{activate(e){this._terminal=e}dispose(){}fit(){let e=this.proposeDimensions();if(!e||!this._terminal||isNaN(e.cols)||isNaN(e.rows))return;let t=this._terminal._core;(this._terminal.rows!==e.rows||this._terminal.cols!==e.cols)&&(t._renderService.clear(),this._terminal.resize(e.cols,e.rows))}proposeDimensions(){if(!this._terminal||!this._terminal.element||!this._terminal.element.parentElement)return;let e=this._terminal._core._renderService.dimensions;if(e.css.cell.width===0||e.css.cell.height===0)return;let t=this._terminal.options.scrollback===0?0:this._terminal.options.overviewRuler?.width||14,n=window.getComputedStyle(this._terminal.element.parentElement),r=parseInt(n.getPropertyValue(`height`)),i=Math.max(0,parseInt(n.getPropertyValue(`width`))),a=window.getComputedStyle(this._terminal.element),o={top:parseInt(a.getPropertyValue(`padding-top`)),bottom:parseInt(a.getPropertyValue(`padding-bottom`)),right:parseInt(a.getPropertyValue(`padding-right`)),left:parseInt(a.getPropertyValue(`padding-left`))},s=o.top+o.bottom,c=o.right+o.left,l=r-s,u=i-c-t;return{cols:Math.max(iN,Math.floor(u/e.css.cell.width)),rows:Math.max(aN,Math.floor(l/e.css.cell.height))}}},sN=class{constructor(e,t,n,r={}){this._terminal=e,this._regex=t,this._handler=n,this._options=r}provideLinks(e,t){let n=lN.computeLink(e,this._regex,this._terminal,this._handler);t(this._addCallbacks(n))}_addCallbacks(e){return e.map(e=>(e.leave=this._options.leave,e.hover=(t,n)=>{if(this._options.hover){let{range:r}=e;this._options.hover(t,n,r)}},e))}};function cN(e){try{let t=new URL(e),n=t.password&&t.username?`${t.protocol}//${t.username}:${t.password}@${t.host}`:t.username?`${t.protocol}//${t.username}@${t.host}`:`${t.protocol}//${t.host}`;return e.toLocaleLowerCase().startsWith(n.toLocaleLowerCase())}catch{return!1}}var lN=class e{static computeLink(t,n,r,i){let a=new RegExp(n.source,(n.flags||``)+`g`),[o,s]=e._getWindowedLineStrings(t-1,r),c=o.join(``),l,u=[];for(;l=a.exec(c);){let t=l[0];if(!cN(t))continue;let[n,a]=e._mapStrIdx(r,s,0,l.index),[o,c]=e._mapStrIdx(r,n,a,t.length);if(n===-1||a===-1||o===-1||c===-1)continue;let d={start:{x:a+1,y:n+1},end:{x:c,y:o+1}};u.push({range:d,text:t,activate:i})}return u}static _getWindowedLineStrings(e,t){let n,r=e,i=e,a=0,o=``,s=[];if(n=t.buffer.active.getLine(e)){let e=n.translateToString(!0);if(n.isWrapped&&e[0]!==` `){for(a=0;(n=t.buffer.active.getLine(--r))&&a<2048&&(o=n.translateToString(!0),a+=o.length,s.push(o),!(!n.isWrapped||o.indexOf(` `)!==-1)););s.reverse()}for(s.push(e),a=0;(n=t.buffer.active.getLine(++i))&&n.isWrapped&&a<2048&&(o=n.translateToString(!0),a+=o.length,s.push(o),o.indexOf(` `)===-1););}return[s,r]}static _mapStrIdx(e,t,n,r){let i=e.buffer.active,a=i.getNullCell(),o=n;for(;r;){let e=i.getLine(t);if(!e)return[-1,-1];for(let n=o;n<e.length;++n){e.getCell(n,a);let o=a.getChars();if(a.getWidth()&&(r-=o.length||1,n===e.length-1&&o===``)){let e=i.getLine(t+1);e&&e.isWrapped&&(e.getCell(0,a),a.getWidth()===2&&(r+=1))}if(r<0)return[t,n]}t++,o=0}return[t,o]}},uN=/(https?|HTTPS?):[/]{2}[^\s"'!*(){}|\\\^<>`]*[^\s"':,.!?{}|\\\^~\[\]`()<>]/;function dN(e,t){let n=window.open();if(n){try{n.opener=null}catch{}n.location.href=t}else console.warn(`Opening link blocked as opener could not be cleared`)}var fN=class{constructor(e=dN,t={}){this._handler=e,this._options=t}activate(e){this._terminal=e;let t=this._options,n=t.urlRegex||uN;this._linkProvider=this._terminal.registerLinkProvider(new sN(this._terminal,n,this._handler,t))}dispose(){this._linkProvider?.dispose()}},pN=`forge.terminal.tabs.v1`;function mN(){try{if(sessionStorage.getItem(pN)===null){let e=localStorage.getItem(pN);e!==null&&(sessionStorage.setItem(pN,e),localStorage.removeItem(pN))}let e=sessionStorage.getItem(pN);if(e===null)return{tabs:[],activeTabId:void 0};let t=JSON.parse(e);if(typeof t!=`object`||!t||!Array.isArray(t.tabs))return{tabs:[],activeTabId:void 0};let n=[];for(let e of t.tabs)typeof e==`object`&&e&&typeof e.id==`string`&&typeof e.projectId==`string`&&typeof e.label==`string`&&typeof e.createdAt==`number`&&n.push(e);let r=t.activeTabId,i=typeof r==`string`?r:void 0;return{tabs:n,activeTabId:n.some(e=>e.id===i)?i:n[0]?.id}}catch{return{tabs:[],activeTabId:void 0}}}function hN(e){try{sessionStorage.setItem(pN,JSON.stringify(e))}catch{}}var gN=0,_N=()=>`term-${Date.now().toString(36)}-${(gN++).toString(36)}`,vN=mN(),yN=pt(e=>({tabs:vN.tabs,activeTabId:vN.activeTabId,openTab:t=>{let n=_N();return e(e=>{let r={id:n,projectId:t,label:`Terminal ${e.tabs.filter(e=>e.projectId===t).length+1}`,createdAt:Date.now()},i={tabs:[...e.tabs,r],activeTabId:n};return hN(i),i}),n},closeTab:t=>{e(e=>{let n=e.tabs.findIndex(e=>e.id===t);if(n===-1)return{};let r=e.tabs.slice(0,n).concat(e.tabs.slice(n+1)),i={tabs:r,activeTabId:e.activeTabId===t?(r[n]??r[n-1]??r[0])?.id:e.activeTabId};return hN(i),i})},setActiveTab:t=>e(e=>(hN({tabs:{...e,activeTabId:t}.tabs,activeTabId:t}),{activeTabId:t})),closeProjectTabs:t=>{e(e=>{let n=e.tabs.filter(e=>e.projectId!==t),r={tabs:n,activeTabId:n.some(t=>t.id===e.activeTabId)?e.activeTabId:n[0]?.id};return hN(r),r})}})),bN=new Map;function xN(e){let t=[1,2,4,8,16,30];return(t[Math.min(e,t.length-1)]??30)*1e3}function SN(e){return e===1e3||e===4401||e===4404}function CN(){let e=dr(),t=yN(e=>e.tabs),n=yN(e=>e.activeTabId),r=yN(e=>e.openTab),i=yN(e=>e.closeTab),a=yN(e=>e.setActiveTab),o=ur(e=>e.projects),s=t.filter(t=>t.projectId===e?.id),c=s.find(e=>e.id===n)??s[0],l=new Map(o.map(e=>[e.id,e.path]));if(e===void 0)return(0,R.jsx)(`div`,{className:`flex h-full items-center justify-center text-xs italic text-neutral-500`,children:`Select a project to open a terminal.`});let u=()=>{r(e.id)},d=e=>{EN(e),i(e)};return(0,R.jsxs)(`div`,{className:`flex h-full flex-col bg-black`,children:[(0,R.jsx)(`div`,{className:`flex items-center justify-between border-b border-neutral-800 bg-neutral-900/40 px-2 py-1`,children:(0,R.jsxs)(`div`,{className:`flex items-center gap-1 overflow-x-auto`,children:[s.length===0&&(0,R.jsx)(`span`,{className:`px-2 text-[11px] italic text-neutral-500`,children:`No terminals open.`}),s.map(e=>(0,R.jsxs)(`div`,{className:`group flex items-center gap-1 rounded px-2 py-0.5 text-xs ${e.id===c?.id?`bg-neutral-800 text-neutral-100`:`text-neutral-400 hover:bg-neutral-900 hover:text-neutral-200`}`,children:[(0,R.jsxs)(`button`,{onClick:()=>a(e.id),className:`flex items-center gap-1`,children:[(0,R.jsx)(Ze,{size:11}),e.label]}),(0,R.jsx)(`button`,{onClick:()=>d(e.id),className:`rounded p-1 text-neutral-600 hover:bg-neutral-800 hover:text-neutral-200`,title:`Close terminal (kills the PTY)`,children:(0,R.jsx)(it,{size:16})})]},e.id)),(0,R.jsxs)(`button`,{onClick:u,className:`ml-1 flex items-center gap-1 rounded px-2 py-0.5 text-xs text-neutral-400 hover:bg-neutral-900 hover:text-neutral-200 light:text-neutral-200 light:hover:bg-neutral-800 light:hover:text-neutral-50`,title:`New terminal`,children:[(0,R.jsx)(He,{size:14}),`New`]})]})}),(0,R.jsxs)(`div`,{className:`relative flex-1 overflow-hidden`,children:[s.length===0&&(0,R.jsxs)(`div`,{className:`flex h-full items-center justify-center text-xs italic text-neutral-500`,children:[`Click "New" to open a terminal in `,e.path,`.`]}),t.map(t=>(0,R.jsx)(wN,{tab:t,projectPath:l.get(t.projectId)??``,visible:t.projectId===e.id&&t.id===c?.id},t.id))]})]})}function wN({tab:e,projectPath:t,visible:n}){let r=(0,v.useRef)(null);return(0,v.useEffect)(()=>{if(r.current===null)return;let t=r.current,n=bN.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),n.fit.fit()}catch{}let e=new ResizeObserver(()=>{try{n.fit.fit()}catch{}let e=n.term.cols,t=n.term.rows;e===n.lastSize.cols&&t===n.lastSize.rows||(n.lastSize={cols:e,rows:t},n.ws.readyState===WebSocket.OPEN&&n.ws.send(JSON.stringify({type:`resize`,cols:e,rows:t})))});e.observe(t);try{n.observer.disconnect()}catch{}return n.observer=e,requestAnimationFrame(()=>{try{n.fit.fit(),n.term.focus()}catch{}}),()=>{try{e.disconnect()}catch{}}}let i=new rN.Terminal({theme:{background:rC(`--pi-terminal-bg`,`#0a0a0a`),foreground:rC(`--pi-terminal-fg`,`#e5e5e5`),cursor:rC(`--pi-terminal-fg`,`#e5e5e5`),black:rC(`--color-neutral-800`,`#262626`),brightBlack:rC(`--color-neutral-600`,`#525252`)},fontFamily:`ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace`,fontSize:13,cursorBlink:!0,scrollback:5e3,convertEol:!1}),a=new oN,o=new fN;i.loadAddon(a),i.loadAddon(o),i.open(t),a.fit();let s={cols:i.cols,rows:i.rows},c=TN(e.id,e.projectId,i,s,!1);i.onData(t=>{let n=bN.get(e.id)?.ws;n?.readyState===WebSocket.OPEN&&n.send(JSON.stringify({type:`input`,data:t}))});let l=new ResizeObserver(()=>{try{a.fit()}catch{}let t=i.cols,n=i.rows,r=bN.get(e.id);r!==void 0&&(t===r.lastSize.cols&&n===r.lastSize.rows||(r.lastSize={cols:t,rows:n},r.ws.readyState===WebSocket.OPEN&&r.ws.send(JSON.stringify({type:`resize`,cols:t,rows:n}))))});return l.observe(r.current),bN.set(e.id,{term:i,fit:a,ws:c,observer:l,lastSize:s,reconnectAttempt:0,reconnectTimer:void 0,disposed:!1}),()=>{try{l.disconnect()}catch{}}},[e.id]),(0,v.useEffect)(()=>{if(!n)return;let t=bN.get(e.id);t!==void 0&&requestAnimationFrame(()=>{try{t.fit.fit(),t.term.focus()}catch{}})},[n,e.id]),(0,v.useEffect)(()=>{let t=bN.get(e.id);t!==void 0&&(t.term.options.theme={background:rC(`--pi-terminal-bg`,`#0a0a0a`),foreground:rC(`--pi-terminal-fg`,`#e5e5e5`),cursor:rC(`--pi-terminal-fg`,`#e5e5e5`),black:rC(`--color-neutral-800`,`#262626`),brightBlack:rC(`--color-neutral-600`,`#525252`)})},[tC(e=>e.theme),e.id]),(0,R.jsx)(`div`,{ref:r,onClick:()=>{bN.get(e.id)?.term.focus()},className:`absolute inset-y-0 left-2 right-0`,style:{visibility:n?`visible`:`hidden`,pointerEvents:n?`auto`:`none`,zIndex:+!!n},title:t})}function TN(e,t,n,r,i){let a=window.location.protocol===`https:`?`wss`:`ws`,o=Vt(),s=o===void 0?``:`&token=${encodeURIComponent(o.token)}`,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=()=>{l.send(JSON.stringify({type:`resize`,cols:r.cols,rows:r.rows}));let t=bN.get(e);t!==void 0&&(t.reconnectAttempt=0)},l.onmessage=e=>{typeof e.data==`string`?n.write(e.data):e.data instanceof ArrayBuffer&&n.write(new Uint8Array(e.data))},l.onclose=r=>{let i=bN.get(e);if(i===void 0||i.disposed)return;if(SN(r.code)){let e=`[connection closed: ${String(r.code)}]`;r.code===4401?e=`[connection closed (4401): your 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=xN(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=bN.get(e);r===void 0||r.disposed||(r.reconnectTimer=void 0,r.ws=TN(e,t,n,r.lastSize,!0))},o)},l}function EN(e){let t=bN.get(e);if(t!==void 0){t.disposed=!0,t.reconnectTimer!==void 0&&clearTimeout(t.reconnectTimer),bN.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 DN(){let e=st(),[t,n]=(0,v.useState)(``),[r,i]=(0,v.useState)([]),[a,o]=(0,v.useState)(!1),[s,c]=(0,v.useState)(!1),[l,u]=(0,v.useState)(void 0),[d,f]=(0,v.useState)(0),p=(0,v.useRef)(null),m=(0,v.useRef)(null),h=(0,v.useRef)(void 0),g=ur(e=>e.setActive),_=ur(e=>e.activeProjectId),y=Jr(e=>e.setActiveSession),b=Jr(e=>e.requestScrollToMessage),x=(0,v.useMemo)(()=>{let e=[];return r.forEach((t,n)=>{t.matches.forEach((r,i)=>{e.push({group:t,match:r,groupIndex:n,matchIndex:i})})}),e},[r]);if((0,v.useEffect)(()=>{f(0)},[r]),(0,v.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&e.key.toLowerCase()===`k`&&(e.preventDefault(),p.current?.focus(),p.current?.select())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[]),(0,v.useEffect)(()=>{if(!a)return;let e=e=>{m.current!==null&&(m.current.contains(e.target)||o(!1))};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[a]),(0,v.useEffect)(()=>{if(t.trim().length===0){i([]),u(void 0),c(!1),h.current?.abort();return}let e=new AbortController;h.current?.abort(),h.current=e,c(!0),u(void 0);let n=window.setTimeout(()=>{L.searchSessions(t.trim(),{signal:e.signal}).then(t=>{e.signal.aborted||(i(t.results),c(!1),o(!0))}).catch(t=>{e.signal.aborted||(c(!1),u(t instanceof Error?t.message:`search failed`))})},250);return()=>{window.clearTimeout(n),e.abort()}},[t]),e)return null;let S=(e,t)=>{b(e.sessionId,t.messageIndex),_!==e.projectId&&g(e.projectId),y(e.sessionId),o(!1),n(``),p.current?.blur()},C=e=>{if(e.key===`Escape`){o(!1),p.current?.blur();return}if(!(!a||x.length===0)){if(e.key===`ArrowDown`)e.preventDefault(),f(e=>Math.min(x.length-1,e+1));else if(e.key===`ArrowUp`)e.preventDefault(),f(e=>Math.max(0,e-1));else if(e.key===`Enter`){e.preventDefault();let t=x[d];t!==void 0&&S(t.group,t.match)}}},w=e=>{let t=e.snippet.slice(0,e.matchOffset),n=e.snippet.slice(e.matchOffset,e.matchOffset+e.matchLength),r=e.snippet.slice(e.matchOffset+e.matchLength);return(0,R.jsxs)(R.Fragment,{children:[t,(0,R.jsx)(`mark`,{className:`rounded bg-amber-300/30 text-amber-100 light:bg-amber-200 light:text-amber-900`,children:n}),r]})},T=e=>e===`user`?`you`:e===`assistant`?`agent`:`tool`;return(0,R.jsxs)(`div`,{ref:m,className:`relative`,children:[(0,R.jsxs)(`div`,{className:`relative`,children:[(0,R.jsx)(qe,{size:13,className:`pointer-events-none absolute left-2 top-1/2 -translate-y-1/2 text-neutral-500`,"aria-hidden":`true`}),(0,R.jsx)(`input`,{ref:p,type:`text`,value:t,onChange:e=>n(e.target.value),onFocus:()=>{r.length>0&&o(!0)},onKeyDown:C,placeholder:`Search sessions… ⌘K`,"aria-label":`Search across all sessions`,className:`w-64 rounded-md border border-neutral-700 bg-neutral-900 py-1 pl-7 pr-7 text-xs text-neutral-200 placeholder-neutral-500 focus:border-neutral-500 focus:outline-none`}),t.length>0&&(0,R.jsx)(`button`,{type:`button`,onClick:()=>{n(``),i([]),o(!1),p.current?.focus()},"aria-label":`Clear search`,className:`absolute right-1 top-1/2 -translate-y-1/2 rounded p-0.5 text-neutral-500 hover:bg-neutral-800 hover:text-neutral-200`,children:(0,R.jsx)(it,{size:12})})]}),a&&(0,R.jsxs)(`div`,{role:`listbox`,"aria-label":`Search results`,className:`absolute right-0 top-full z-50 mt-1 max-h-[60vh] w-96 overflow-y-auto rounded-md border border-neutral-700 bg-neutral-900 shadow-xl`,children:[s&&(0,R.jsx)(`div`,{className:`px-3 py-2 text-xs text-neutral-400`,children:`Searching…`}),!s&&l!==void 0&&(0,R.jsx)(`div`,{className:`px-3 py-2 text-xs text-amber-400 light:text-amber-700`,children:l}),!s&&l===void 0&&x.length===0&&(0,R.jsx)(`div`,{className:`px-3 py-2 text-xs text-neutral-500`,children:`No matches.`}),x.length>0&&(0,R.jsx)(`div`,{children:r.map((e,t)=>(0,R.jsxs)(`div`,{className:`border-b border-neutral-800 last:border-b-0`,children:[(0,R.jsxs)(`div`,{className:`bg-neutral-950 px-3 py-1 text-[10px] uppercase tracking-wider text-neutral-500`,children:[(0,R.jsx)(`span`,{className:`text-neutral-300`,children:e.projectName}),e.sessionName!==void 0&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`span`,{className:`mx-1.5 text-neutral-600`,children:`/`}),(0,R.jsx)(`span`,{className:`text-neutral-400 normal-case tracking-normal`,children:e.sessionName})]})]}),e.matches.map((n,r)=>{let i=x.findIndex(e=>e.groupIndex===t&&e.matchIndex===r),a=i===d;return(0,R.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":a,onMouseEnter:()=>f(i),onClick:()=>S(e,n),className:`flex w-full items-start gap-2 px-3 py-1.5 text-left text-xs ${a?`bg-neutral-800 text-neutral-100`:`text-neutral-300 hover:bg-neutral-800/60`}`,children:[(0,R.jsx)(`span`,{className:`mt-0.5 shrink-0 rounded bg-neutral-800 px-1 py-0.5 text-[9px] uppercase tracking-wider text-neutral-400`,children:T(n.kind)}),(0,R.jsx)(`span`,{className:`flex-1 break-words`,children:w(n)})]},`${n.messageIndex}-${n.matchOffset}`)})]},e.sessionId))})]})]})}function ON(){let e=Dj(e=>e.settings),t=QA(e=>e.openSettings);if(e===void 0||e.total===0&&e.enabled)return null;let{enabled:n,connected:r,total:i}=e,a=n?r===i?`bg-emerald-500`:r===0?`bg-red-500`:`bg-amber-400`:`bg-neutral-600`,o=n?`MCP ${r}/${i}`:`MCP off`;return(0,R.jsxs)(`button`,{type:`button`,onClick:()=>t(`mcp`),className:`inline-flex items-center gap-1.5 rounded-md border border-neutral-700 px-2 py-1 text-xs text-neutral-300 hover:border-neutral-500 hover:text-neutral-100`,title:n?`${r} of ${i} MCP server(s) connected. Click to open Settings → MCP.`:`MCP tools disabled. Click to open Settings → MCP.`,children:[(0,R.jsx)(`span`,{className:`h-2 w-2 rounded-full ${a}`}),o]})}var kN=`forge.turnDiff.viewType`;function AN(){try{return localStorage.getItem(kN)===`split`?`split`:`unified`}catch{return`unified`}}function jN(){let e=Jr(e=>e.activeSessionId),t=Jr(t=>e===void 0?0:t.agentEndCountBySession[e]??0),n=Jr(t=>e===void 0?!1:t.streamingBySession[e]??!1),[r,i]=(0,v.useState)([]),[a,o]=(0,v.useState)(void 0),[s,c]=(0,v.useState)(!1),[l,u]=(0,v.useState)({}),[d,f]=(0,v.useState)(AN),p=e=>{f(e);try{localStorage.setItem(kN,e)}catch{}},m=async()=>{if(e!==void 0){c(!0),o(void 0);try{i((await L.getTurnDiff(e)).entries)}catch(e){e instanceof N&&e.status===404?i([]):(i([]),o(e instanceof N?e.code:e.message))}finally{c(!1)}}};return(0,v.useEffect)(()=>{i([]),o(void 0)},[e]),(0,v.useEffect)(()=>{e===void 0||n||m()},[e,t,n]),e===void 0?(0,R.jsx)(`div`,{className:`flex h-full items-center justify-center px-4 text-center text-xs italic text-neutral-500`,children:`Pick a session to see its file changes.`}):(0,R.jsxs)(`div`,{className:`flex h-full flex-col text-xs text-neutral-300`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between border-b border-neutral-800 px-3 py-2`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2 font-medium text-neutral-200`,children:[(0,R.jsx)(Se,{size:13}),`Last turn`,r.length>0&&(0,R.jsx)(`span`,{className:`rounded bg-neutral-800 px-1.5 py-0.5 text-[10px] text-neutral-400`,children:r.length})]}),(0,R.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,R.jsx)(`button`,{onClick:()=>p(d===`split`?`unified`:`split`),className:`rounded p-1 text-neutral-400 hover:bg-neutral-800 hover:text-neutral-200`,title:d===`split`?`Switch to unified view`:`Switch to side-by-side view`,children:d===`split`?(0,R.jsx)(Ge,{size:13}):(0,R.jsx)(_e,{size:13})}),(0,R.jsx)(`button`,{onClick:()=>void m(),className:`rounded p-1 text-neutral-400 hover:bg-neutral-800 hover:text-neutral-200`,title:`Refresh diff`,children:(0,R.jsx)(Ue,{size:13,className:s?`animate-spin`:``})})]})]}),a!==void 0&&(0,R.jsx)(`div`,{className:`border-b border-red-700/40 bg-red-900/20 px-3 py-1.5 text-[11px] text-red-300`,children:a}),(0,R.jsxs)(`div`,{className:`flex-1 overflow-y-auto`,children:[r.length===0&&(0,R.jsx)(`p`,{className:`px-3 py-3 italic text-neutral-500`,children:s?`Loading…`:a===void 0?`No file changes from the most recent turn.`:`Couldn't load the latest turn diff (see banner).`}),r.map(e=>{let t=l[e.file]??!1,n=e.file.split(`/`).pop()??e.file;return(0,R.jsxs)(`div`,{className:`border-b border-neutral-800/60`,children:[(0,R.jsxs)(`button`,{onClick:()=>u(n=>({...n,[e.file]:!t})),className:`flex w-full items-center justify-between gap-2 px-3 py-2 text-left hover:bg-neutral-900`,title:e.file,children:[(0,R.jsxs)(`span`,{className:`flex min-w-0 items-baseline gap-2`,children:[(0,R.jsx)(`span`,{className:`truncate font-mono text-neutral-200`,children:n}),e.isPureAddition&&(0,R.jsx)(`span`,{className:`rounded bg-emerald-900/40 px-1 py-0.5 text-[9px] uppercase tracking-wider text-emerald-300 light:bg-emerald-100 light:text-emerald-800`,children:`new`})]}),(0,R.jsxs)(`span`,{className:`flex shrink-0 items-baseline gap-2 text-[11px]`,children:[(0,R.jsxs)(`span`,{className:`text-emerald-400 light:text-emerald-700`,children:[`+`,e.additions]}),(0,R.jsxs)(`span`,{className:`text-red-400 light:text-red-700`,children:[`−`,e.deletions]})]})]}),t&&(0,R.jsx)(mk,{diff:e.diff,viewType:d})]},e.file)})]})]})}var MN=15e3;function NN(e){let[t,n]=(0,v.useState)(void 0),[r,i]=(0,v.useState)(void 0),a=Jr(e=>e.activeSessionId),o=Jr(e=>a===void 0?!1:e.streamingBySession[a]??!1),s=Jr(e=>a===void 0?0:e.agentEndCountBySession[a]??0),c=(0,v.useRef)(0),l=async()=>{if(e===void 0)return;let t=c.current,r=e;try{let e=await L.gitStatus(r);if(c.current!==t)return;n(e),i(void 0)}catch(e){if(c.current!==t)return;i(e instanceof N?e.code:e.message)}};return(0,v.useEffect)(()=>{c.current+=1,n(void 0),i(void 0)},[e]),(0,v.useEffect)(()=>{if(e===void 0)return;if(l(),o)return()=>void 0;let t=window.setInterval(()=>{l()},MN);return()=>{window.clearInterval(t)}},[e,o]),(0,v.useEffect)(()=>{e!==void 0&&s!==0&&l()},[e,a,s]),{status:t,error:r,refresh:l}}function PN(e){let t=[],n=[];for(let r of e){let e=t.slice(),i=t.findIndex(e=>e===r.hash);i===-1&&(i=t.findIndex(e=>e===void 0),i===-1&&(i=t.length,t.push(void 0)));let a=[];for(let e=0;e<t.length;e++)t[e]===r.hash&&a.push(e);for(let e of a)t[e]=void 0;let o=[];if(r.parents.length>0){let e=r.parents[0];t[i]=e,o.push({lane:i,parent:e})}for(let e=1;e<r.parents.length;e++){let n=r.parents[e],i=t.findIndex(e=>e===n);i===-1&&(i=t.findIndex(e=>e===void 0),i===-1&&(i=t.length,t.push(void 0)),t[i]=n),o.push({lane:i,parent:n})}for(;t.length>0&&t[t.length-1]===void 0;)t.pop();let s=[];for(let t=0;t<e.length;t++)e[t]!==void 0&&t!==i&&(a.includes(t)||s.push(t));let c=Math.max(i+1,t.length,...a.map(e=>e+1),...o.map(e=>e.lane+1),...s.map(e=>e+1));n.push({hash:r.hash,lane:i,incomingLanes:a,outgoingLanes:o,through:s,width:c})}return n}var FN=[`#a5b4fc`,`#fde047`,`#a3e635`,`#f472b6`,`#67e8f9`,`#fb923c`,`#c084fc`,`#86efac`];function IN(e){return FN[e%FN.length]??`#a5b4fc`}function LN(){let e=dr(),{status:t,error:n,refresh:r}=NN(e?.id),[i,a]=(0,v.useState)(``),[o,s]=(0,v.useState)(!1),[c,l]=(0,v.useState)(void 0),[u,d]=(0,v.useState)(void 0),[f,p]=(0,v.useState)(void 0),[m,h]=(0,v.useState)(void 0),[g,_]=(0,v.useState)(void 0),[y,b]=(0,v.useState)(!1),[x,S]=(0,v.useState)(!1),[C,w]=(0,v.useState)(!1),[T,E]=(0,v.useState)(void 0),[D,O]=(0,v.useState)(void 0),[k,ee]=(0,v.useState)(void 0),[A,te]=(0,v.useState)(!1),[ne,re]=(0,v.useState)(``),[ie,j]=(0,v.useState)(``),[ae,M]=(0,v.useState)(void 0),oe=async()=>{if(e!==void 0)try{_((await L.gitRemotes(e.id)).remotes)}catch(e){l(e instanceof N?e.code:e.message)}},se=async()=>{if(e===void 0)return;let t=ne.trim(),n=ie.trim();if(!(t.length===0||n.length===0)){ee(t),l(void 0);try{await L.gitRemoteAdd(e.id,t,n),te(!1),re(``),j(``),await oe()}catch(e){l(e instanceof N?e.message||e.code:e.message)}finally{ee(void 0)}}},ce=async()=>{if(e===void 0||ae===void 0)return;let t=ae;M(void 0),ee(t),l(void 0);try{await L.gitRemoteRemove(e.id,t),await oe()}catch(e){l(e instanceof N?e.message||e.code:e.message)}finally{ee(void 0)}},ue=async()=>{if(e!==void 0)try{h((await L.gitBranches(e.id)).branches)}catch(e){l(e instanceof N?e.code:e.message)}},de=async t=>{if(e!==void 0){E(t),l(void 0);try{await L.gitCheckout(e.id,t),await ue(),r()}catch(e){l(e instanceof N?e.code:e.message)}finally{E(void 0)}}},fe=async t=>{if(e!==void 0){O(void 0),E(t),l(void 0);try{await L.gitBranchCreate(e.id,t,{checkout:!0}),await ue(),r()}catch(e){l(e instanceof N?e.code:e.message)}finally{E(void 0)}}},pe=async t=>{if(e===void 0||D?.kind!==`delete`)return;let{name:n}=D;O(void 0),E(n),l(void 0);try{await L.gitBranchDelete(e.id,n,t),await ue()}catch(e){l(e instanceof N?e.code:e.message)}finally{E(void 0)}},[me,he]=(0,v.useState)({}),[ge,ve]=(0,v.useState)(void 0),[ye,be]=(0,v.useState)(void 0),[xe,Se]=(0,v.useState)(``),[Ce,we]=(0,v.useState)(!1),[Te,Ee]=(0,v.useState)(!1),[ke,Ae]=(0,v.useState)(()=>{try{return localStorage.getItem(`forge.gitPanel.viewType`)===`split`?`split`:`unified`}catch{return`unified`}}),je=e=>{Ae(e);try{localStorage.setItem(`forge.gitPanel.viewType`,e)}catch{}};if((0,v.useEffect)(()=>{if(t===void 0)return;let e=new Set(t.files.map(e=>e.path));he(t=>{let n=!1,r={};for(let[i,a]of Object.entries(t)){let t=i.split(`|`)[0]??``;e.has(t)?r[i]=a:n=!0}return n?r:t})},[t]),(0,v.useEffect)(()=>{y&&e!==void 0&&L.gitLog(e.id,30).then(e=>p(e.commits)).catch(e=>l(e instanceof N?e.code:e.message))},[y,e?.id]),(0,v.useEffect)(()=>{x&&e!==void 0&&L.gitBranches(e.id).then(e=>h(e.branches)).catch(e=>l(e instanceof N?e.code:e.message))},[x,e?.id]),(0,v.useEffect)(()=>{C&&e!==void 0&&L.gitRemotes(e.id).then(e=>_(e.remotes)).catch(e=>l(e instanceof N?e.code:e.message))},[C,e?.id]),e===void 0)return(0,R.jsx)(`div`,{className:`flex h-full items-center justify-center px-4 text-center text-xs italic text-neutral-500`,children:`Pick a project to see its git status.`});if(t?.isGitRepo===!1){let t=async()=>{s(!0),l(void 0);try{await L.gitInit(e.id),await r()}catch(e){l(e instanceof N?e.code:e.message)}finally{s(!1)}};return(0,R.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-3 px-4 text-center text-xs text-neutral-500`,children:[(0,R.jsxs)(`p`,{className:`italic`,children:[e.name,` isn't a git repository.`]}),(0,R.jsx)(`button`,{onClick:()=>void t(),disabled:o,className:`rounded-md bg-neutral-100 px-3 py-1.5 text-xs font-medium text-neutral-900 hover:bg-white disabled:cursor-not-allowed disabled:opacity-50`,title:"Run `git init -b main` in the project root",children:o?`Initializing…`:`Initialize git repo`}),(0,R.jsxs)(`p`,{className:`text-[10px] text-neutral-600`,children:[`Default branch will be `,(0,R.jsx)(`code`,{className:`font-mono text-neutral-400`,children:`main`}),`.`]}),c!==void 0&&(0,R.jsxs)(`p`,{className:`text-[10px] text-red-400 light:text-red-700`,children:[`git init failed: `,c]})]})}let Me=t?.files.filter(e=>e.staged)??[],Ne=t?.files.filter(e=>e.unstaged)??[],Pe=t?.files.filter(e=>e.kind===`untracked`)??[],Fe=async(t,n)=>{let r=`${t.path}|${n?`staged`:`unstaged`}`;if(me[r]!==void 0){he(e=>{let t={...e};return delete t[r],t});return}he(e=>({...e,[r]:`loading`}));try{let i=await L.gitDiffFile(e.id,t.path,n);he(e=>({...e,[r]:i.diff}))}catch{he(e=>({...e,[r]:`error`}))}},Ie=async t=>{if(t.length!==0){s(!0),l(void 0);try{await L.gitStage(e.id,t),await r()}catch(e){l((e instanceof N,e.message))}finally{s(!1)}}},Le=async t=>{if(t.length!==0){s(!0),l(void 0),d(void 0);try{await L.gitRevert(e.id,t),d(t.length===1?`Reverted ${t[0]}`:`Reverted ${t.length} files`),await r()}catch(e){l((e instanceof N,e.message))}finally{s(!1)}}},Re=async t=>{if(t.length!==0){s(!0),l(void 0);try{await L.gitUnstage(e.id,t),await r()}catch(e){l((e instanceof N,e.message))}finally{s(!1)}}},ze=async(t,n,i)=>{ve(t.path),l(void 0);try{let a=await L.gitApplyHunks(e.id,t.path,i,[n]);if(a.ok!==!0){l(`Hunk apply failed: ${a.error??`unknown_error`}`);return}await Promise.all([Be(t,!0),Be(t,!1),r()])}catch(e){l((e instanceof N,e.message))}finally{ve(void 0)}},Be=async(t,n)=>{let r=`${t.path}|${n?`staged`:`unstaged`}`;if(me[r]!==void 0){he(e=>({...e,[r]:`loading`}));try{let i=await L.gitDiffFile(e.id,t.path,n);he(e=>{if(i.diff.length===0){let t={...e};return delete t[r],t}return{...e,[r]:i.diff}})}catch{he(e=>({...e,[r]:`error`}))}}},Ve=async()=>{let t=i.trim();if(t.length!==0){s(!0),l(void 0),d(void 0);try{let{hash:n}=await L.gitCommit(e.id,t);a(``),d(`Committed ${n.slice(0,7)}`),await r(),y&&p((await L.gitLog(e.id,30)).commits)}catch(e){l((e instanceof N,e.message))}finally{s(!1)}}},We=(()=>{if(g!==void 0)return g.map(e=>e.name).sort();if(m===void 0)return[];let e=new Set;for(let t of m){if(!t.remote)continue;let n=t.name.indexOf(`/`);n>0&&e.add(t.name.slice(0,n))}return Array.from(e).sort()})(),Ke=m===void 0?[]:m.filter(e=>!e.remote).map(e=>e.name).sort(),qe=async()=>{s(!0),l(void 0),d(void 0);try{let t={};ye!==void 0&&(t.remote=ye);let{output:n}=await L.gitFetch(e.id,t);d(n.trim().length>0?n.trim().split(`
|
|
372
372
|
`).pop()??`Fetched`:`Fetched`)}catch(e){l((e instanceof N,e.message))}finally{s(!1)}},Je=async()=>{s(!0),l(void 0),d(void 0);try{let t={};ye!==void 0&&(t.remote=ye);let n=xe.trim();n.length>0&&(t.branch=n);let{output:i}=await L.gitPull(e.id,t);d(i.trim().length>0?i.trim().split(`
|
|
373
373
|
`).pop()??`Pulled`:`Pulled`),r()}catch(e){l((e instanceof N,e.message))}finally{s(!1)}},Ye=async()=>{s(!0),l(void 0),d(void 0);try{let t={};ye!==void 0&&(t.remote=ye);let n=xe.trim();n.length>0&&(t.branch=n),Ce&&(t.setUpstream=!0);let{output:r}=await L.gitPush(e.id,t);d(r.trim().length>0?r.trim().split(`
|
|
374
|
-
`).pop()??`Pushed`:`Pushed`),Ce&&we(!1)}catch(e){l((e instanceof N,e.message))}finally{s(!1)}};return(0,R.jsxs)(`div`,{className:`flex h-full flex-col text-xs text-neutral-300`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between border-b border-neutral-800 px-3 py-2`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2 font-medium text-neutral-200`,children:[(0,R.jsx)(De,{size:13}),t?.branch??`—`,t!==void 0&&t.files.length>0&&(0,R.jsx)(`span`,{className:`rounded bg-neutral-800 px-1.5 py-0.5 text-[10px] text-neutral-400`,children:t.files.length})]}),(0,R.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,R.jsx)(`button`,{onClick:()=>je(ke===`split`?`unified`:`split`),className:`rounded p-1 text-neutral-400 hover:bg-neutral-800 hover:text-neutral-200`,title:ke===`split`?`Switch git diffs to unified view`:`Switch git diffs to side-by-side view`,children:ke===`split`?(0,R.jsx)(Ge,{size:13}):(0,R.jsx)(_e,{size:13})}),(0,R.jsx)(`button`,{onClick:()=>void r(),className:`rounded p-1 text-neutral-400 hover:bg-neutral-800 hover:text-neutral-200`,title:`Refresh`,children:(0,R.jsx)(Ue,{size:13,className:o?`animate-spin`:``})})]})]}),(n!==void 0||c!==void 0)&&(0,R.jsx)(`div`,{className:`border-b border-red-700/40 bg-red-900/20 px-3 py-1.5 text-[11px] text-red-300 light:border-red-300 light:bg-red-50 light:text-red-700`,children:c??n}),u!==void 0&&(0,R.jsx)(`div`,{className:`border-b border-emerald-700/40 bg-emerald-900/20 px-3 py-1.5 text-[11px] text-emerald-300 light:border-emerald-300 light:bg-emerald-50 light:text-emerald-800`,children:u}),(0,R.jsxs)(`div`,{className:`flex-1 overflow-y-auto`,children:[t===void 0&&(0,R.jsx)(`p`,{className:`px-3 py-3 italic text-neutral-500`,children:`Loading…`}),t?.files.length===0&&(0,R.jsx)(`p`,{className:`px-3 py-3 italic text-neutral-500`,children:`Working tree clean.`}),Me.length>0&&(0,R.jsx)(FN,{label:`Staged`,files:Me,actionLabel:`Unstage all`,onGroupAction:()=>void Re(Me.map(e=>e.path)),onFileAction:e=>void Re([e.path]),fileActionLabel:`Unstage`,onRevert:e=>void Le([e.path]),onClickFile:e=>void Fe(e,!0),openDiffs:me,staged:!0,diffViewType:ke,onHunkAction:(e,t)=>void ze(e,t,`unstage`),pendingHunkPath:ge}),Ne.length>0&&(0,R.jsx)(FN,{label:`Unstaged`,files:Ne,actionLabel:`Stage all`,onGroupAction:()=>void Ie(Ne.map(e=>e.path)),onFileAction:e=>void Ie([e.path]),fileActionLabel:`Stage`,onRevert:e=>void Le([e.path]),onClickFile:e=>void Fe(e,!1),openDiffs:me,staged:!1,diffViewType:ke,onHunkAction:(e,t)=>void ze(e,t,`stage`),pendingHunkPath:ge}),Pe.length>0&&(0,R.jsx)(FN,{label:`Untracked`,files:Pe,actionLabel:`Stage all`,onGroupAction:()=>void Ie(Pe.map(e=>e.path)),onFileAction:e=>void Ie([e.path]),fileActionLabel:`Stage`,onRevert:void 0,onClickFile:e=>void Fe(e,!1),openDiffs:me,staged:!1,diffViewType:ke}),(0,R.jsxs)(`div`,{className:`border-t border-neutral-800/60 px-3 py-3`,children:[(0,R.jsxs)(`div`,{className:`mb-1 flex items-center gap-1 text-[10px] uppercase tracking-wider text-neutral-500`,children:[(0,R.jsx)(Oe,{size:10}),` Commit`]}),(0,R.jsx)(`textarea`,{value:i,onChange:e=>a(e.target.value),placeholder:`Commit message…`,rows:3,className:`w-full resize-none rounded border border-neutral-700 bg-neutral-950 px-2 py-1 text-xs text-neutral-100 outline-none focus:border-neutral-500`}),(0,R.jsxs)(`div`,{className:`mt-1 flex items-center justify-between gap-2`,children:[(0,R.jsxs)(`span`,{className:`text-[10px] text-neutral-500`,children:[Me.length,` staged`]}),(0,R.jsx)(`button`,{onClick:()=>void Ve(),disabled:o||Me.length===0||i.trim().length===0,className:`rounded bg-neutral-100 px-3 py-1 text-xs font-medium text-neutral-900 disabled:cursor-not-allowed disabled:opacity-50`,children:`Commit`})]})]}),(0,R.jsxs)(`div`,{className:`border-t border-neutral-800/60 px-3 py-3`,children:[(0,R.jsxs)(`div`,{className:`mb-1 flex items-center justify-between gap-1 text-[10px] uppercase tracking-wider text-neutral-500`,children:[(0,R.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,R.jsx)(nt,{size:10}),` Push`]}),(0,R.jsx)(`button`,{onClick:()=>{Ee(e=>!e),!Te&&m===void 0&&L.gitBranches(e.id).then(e=>h(e.branches)).catch(()=>void 0),!Te&&g===void 0&&L.gitRemotes(e.id).then(e=>_(e.remotes)).catch(()=>void 0)},className:`rounded px-1 py-0.5 text-[10px] normal-case text-neutral-400 hover:bg-neutral-900 hover:text-neutral-200`,children:Te?`Hide options`:`Options`})]}),Te&&(0,R.jsxs)(`div`,{className:`mb-2 space-y-1.5 rounded border border-neutral-800 bg-neutral-900/40 p-2`,children:[(0,R.jsxs)(`label`,{className:`flex items-center gap-2 text-[11px]`,children:[(0,R.jsx)(`span`,{className:`w-16 shrink-0 text-neutral-400`,children:`Remote`}),We.length>0?(0,R.jsxs)(`select`,{value:ye??``,onChange:e=>be(e.target.value===``?void 0:e.target.value),className:`flex-1 rounded border border-neutral-700 bg-neutral-950 px-1 py-0.5 text-[11px] text-neutral-100 outline-none focus:border-neutral-500`,children:[(0,R.jsx)(`option`,{value:``,children:`configured upstream`}),We.map(e=>(0,R.jsx)(`option`,{value:e,children:e},e))]}):(0,R.jsx)(`input`,{type:`text`,value:ye??``,onChange:e=>be(e.target.value.length===0?void 0:e.target.value),placeholder:`origin`,className:`flex-1 rounded border border-neutral-700 bg-neutral-950 px-1 py-0.5 text-[11px] text-neutral-100 outline-none focus:border-neutral-500`})]}),(0,R.jsxs)(`label`,{className:`flex items-center gap-2 text-[11px]`,children:[(0,R.jsx)(`span`,{className:`w-16 shrink-0 text-neutral-400`,children:`Branch`}),Ke.length>0?(0,R.jsxs)(`select`,{value:xe,onChange:e=>Se(e.target.value),className:`flex-1 rounded border border-neutral-700 bg-neutral-950 px-1 py-0.5 text-[11px] text-neutral-100 outline-none focus:border-neutral-500`,children:[(0,R.jsx)(`option`,{value:``,children:t?.branch??`current branch`}),Ke.map(e=>(0,R.jsx)(`option`,{value:e,children:e},e))]}):(0,R.jsx)(`input`,{type:`text`,value:xe,onChange:e=>Se(e.target.value),placeholder:t?.branch??`current`,className:`flex-1 rounded border border-neutral-700 bg-neutral-950 px-1 py-0.5 text-[11px] text-neutral-100 outline-none focus:border-neutral-500`})]}),(0,R.jsxs)(`label`,{className:`flex items-center gap-2 text-[11px] text-neutral-300`,children:[(0,R.jsx)(`input`,{type:`checkbox`,checked:Ce,onChange:e=>we(e.target.checked),className:`h-3 w-3`}),(0,R.jsx)(`span`,{children:`Set upstream (first push of a new branch)`})]})]}),(0,R.jsxs)(`div`,{className:`flex gap-1`,children:[(0,R.jsx)(`button`,{onClick:()=>void qe(),disabled:o,className:`flex-1 rounded border border-neutral-700 px-3 py-1 text-xs text-neutral-200 hover:border-neutral-500 disabled:opacity-50`,title:ye===void 0?`git fetch (configured upstream)`:`git fetch ${ye}`,children:`Fetch`}),(0,R.jsx)(`button`,{onClick:()=>void Je(),disabled:o,className:`flex-1 rounded border border-neutral-700 px-3 py-1 text-xs text-neutral-200 hover:border-neutral-500 disabled:opacity-50`,title:`git pull — conflicts surface in the error banner; resolve via the integrated terminal`,children:`Pull`}),(0,R.jsx)(`button`,{onClick:()=>void Ye(),disabled:o,className:`flex-1 rounded border border-neutral-700 px-3 py-1 text-xs text-neutral-200 hover:border-neutral-500 disabled:opacity-50`,title:ye===void 0&&xe.trim().length===0?`git push (configured upstream)`:`git push ${ye??`(upstream)`}${xe.trim().length>0?` ${xe.trim()}`:``}`,children:`Push`})]})]}),(0,R.jsxs)(`div`,{className:`border-t border-neutral-800/60`,children:[(0,R.jsxs)(`button`,{onClick:()=>b(e=>!e),className:`flex w-full items-center justify-between px-3 py-2 text-left text-[10px] uppercase tracking-wider text-neutral-400 hover:bg-neutral-900`,children:[(0,R.jsx)(`span`,{children:`Log`}),(0,R.jsx)(`span`,{children:y?`−`:`+`})]}),y&&(0,R.jsx)(`div`,{className:`px-3 pb-3 text-[11px]`,children:f===void 0?(0,R.jsx)(`p`,{className:`italic text-neutral-500`,children:`Loading…`}):f.length===0?(0,R.jsx)(`p`,{className:`italic text-neutral-500`,children:`No commits yet.`}):(0,R.jsx)(zN,{commits:f})})]}),(0,R.jsxs)(`div`,{className:`border-t border-neutral-800/60`,children:[(0,R.jsxs)(`button`,{onClick:()=>S(e=>!e),className:`flex w-full items-center justify-between px-3 py-2 text-left text-[10px] uppercase tracking-wider text-neutral-400 hover:bg-neutral-900`,children:[(0,R.jsx)(`span`,{children:`Branches`}),(0,R.jsx)(`span`,{children:x?`−`:`+`})]}),x&&(0,R.jsx)(`div`,{className:`px-3 pb-3 text-[11px]`,children:m===void 0?(0,R.jsx)(`p`,{className:`italic text-neutral-500`,children:`Loading…`}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`ul`,{className:`space-y-0.5`,children:m.map(e=>{let t=T===e.name;return(0,R.jsxs)(`li`,{className:`group flex items-center gap-1 rounded px-1 py-0.5 font-mono hover:bg-neutral-900 ${e.current?`text-emerald-400 light:text-emerald-700`:`text-neutral-300`}`,children:[(0,R.jsx)(`span`,{className:`w-3 shrink-0`,children:e.current?(0,R.jsx)(le,{size:10}):null}),(0,R.jsx)(`span`,{className:`flex-1 truncate`,title:e.name,children:e.name}),e.remote&&(0,R.jsx)(`span`,{className:`ml-1 text-[10px] text-neutral-600`,children:`remote`}),!e.current&&(0,R.jsxs)(`div`,{className:`hidden gap-0.5 group-hover:flex`,children:[(0,R.jsx)(`button`,{onClick:()=>void de(e.name),disabled:t,className:`rounded px-1 py-0.5 text-[10px] text-neutral-400 hover:bg-neutral-800 hover:text-neutral-100 disabled:opacity-40`,title:e.remote?`Checkout (creates a tracking branch from ${e.name})`:`Checkout ${e.name}`,children:`checkout`}),!e.remote&&(0,R.jsx)(`button`,{onClick:()=>O({kind:`delete`,name:e.name}),disabled:t,className:`rounded p-0.5 text-neutral-500 hover:bg-red-900/30 hover:text-red-300 disabled:opacity-40 light:hover:bg-red-100 light:hover:text-red-700`,title:`Delete branch`,children:(0,R.jsx)($e,{size:10})})]})]},e.name)})}),(0,R.jsxs)(`button`,{onClick:()=>O({kind:`create`}),className:`mt-2 flex items-center gap-1 rounded px-1 py-0.5 text-[11px] text-neutral-400 hover:bg-neutral-900 hover:text-neutral-100`,children:[(0,R.jsx)(He,{size:10}),` New branch`]})]})})]}),(0,R.jsxs)(`div`,{className:`border-t border-neutral-800/60`,children:[(0,R.jsxs)(`button`,{onClick:()=>w(e=>!e),className:`flex w-full items-center justify-between px-3 py-2 text-left text-[10px] uppercase tracking-wider text-neutral-400 hover:bg-neutral-900`,children:[(0,R.jsx)(`span`,{children:`Remotes`}),(0,R.jsx)(`span`,{children:C?`−`:`+`})]}),C&&(0,R.jsx)(`div`,{className:`px-3 pb-3 text-[11px]`,children:g===void 0?(0,R.jsx)(`p`,{className:`italic text-neutral-500`,children:`Loading…`}):(0,R.jsxs)(R.Fragment,{children:[g.length===0?(0,R.jsx)(`p`,{className:`italic text-neutral-500`,children:`No remotes configured.`}):(0,R.jsx)(`ul`,{className:`space-y-1`,children:g.map(e=>{let t=e.fetchUrl!==e.pushUrl,n=k===e.name;return(0,R.jsxs)(`li`,{className:`group flex flex-col gap-0.5`,children:[(0,R.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,R.jsx)(`span`,{className:`font-mono text-neutral-200`,children:e.name}),t&&(0,R.jsx)(`span`,{className:`rounded bg-amber-900/30 px-1 py-0.5 text-[9px] uppercase tracking-wider text-amber-300 light:bg-amber-100 light:text-amber-800`,children:`fetch ≠ push`}),(0,R.jsx)(`button`,{onClick:()=>M(e.name),disabled:n,className:`ml-auto hidden rounded p-0.5 text-neutral-500 hover:bg-red-900/30 hover:text-red-300 disabled:opacity-40 group-hover:inline-flex light:hover:bg-red-100 light:hover:text-red-700`,title:`Remove remote "${e.name}"`,children:(0,R.jsx)($e,{size:10})})]}),(0,R.jsx)(`span`,{className:`break-all font-mono text-[10px] text-neutral-500`,title:e.fetchUrl,children:e.fetchUrl}),t&&(0,R.jsxs)(`span`,{className:`break-all font-mono text-[10px] text-neutral-500`,title:`push → ${e.pushUrl}`,children:[`push → `,e.pushUrl]})]},e.name)})}),(0,R.jsxs)(`button`,{onClick:()=>{re(``),j(``),te(!0)},className:`mt-2 flex items-center gap-1 rounded px-1 py-0.5 text-[11px] text-neutral-400 hover:bg-neutral-900 hover:text-neutral-100`,children:[(0,R.jsx)(He,{size:10}),` Add remote`]})]})})]})]}),(0,R.jsx)(Ti,{open:D?.kind===`create`,onClose:()=>O(void 0),onSubmit:e=>void fe(e),title:`New branch`,label:`Branch name`,placeholder:`feature/my-change`,primaryLabel:`Create + checkout`}),(0,R.jsx)(Ei,{open:D?.kind===`delete`,onClose:()=>O(void 0),onConfirm:()=>void pe(!1),title:`Delete branch`,message:D?.kind===`delete`?`Delete branch "${D.name}"? Refused if not merged into HEAD; force-delete from the terminal if you really mean it.`:``,primaryLabel:`Delete`,tone:`danger`}),(0,R.jsx)(wi,{open:A,onClose:()=>te(!1),title:`Add remote`,children:(0,R.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),se()},className:`flex flex-col gap-3 px-4 py-3`,children:[(0,R.jsxs)(`label`,{className:`block space-y-1.5`,children:[(0,R.jsx)(`span`,{className:`text-xs text-neutral-300`,children:`Name`}),(0,R.jsx)(`input`,{type:`text`,value:ne,onChange:e=>re(e.target.value),placeholder:`origin`,autoFocus:!0,className:`w-full rounded-md border border-neutral-700 bg-neutral-950 px-3 py-1.5 font-mono text-sm text-neutral-100 outline-none focus:border-neutral-500`})]}),(0,R.jsxs)(`label`,{className:`block space-y-1.5`,children:[(0,R.jsx)(`span`,{className:`text-xs text-neutral-300`,children:`URL`}),(0,R.jsx)(`input`,{type:`text`,value:ie,onChange:e=>j(e.target.value),placeholder:`git@github.com:user/repo.git`,className:`w-full rounded-md border border-neutral-700 bg-neutral-950 px-3 py-1.5 font-mono text-sm text-neutral-100 outline-none focus:border-neutral-500`})]}),(0,R.jsxs)(`footer`,{className:`flex justify-end gap-2 pt-1`,children:[(0,R.jsx)(`button`,{type:`button`,onClick:()=>te(!1),className:`rounded-md border border-neutral-700 px-3 py-1 text-xs text-neutral-200 hover:bg-neutral-800`,children:`Cancel`}),(0,R.jsx)(`button`,{type:`submit`,disabled:ne.trim().length===0||ie.trim().length===0,className:`rounded-md bg-neutral-100 px-3 py-1 text-xs font-medium text-neutral-900 hover:bg-white disabled:cursor-not-allowed disabled:opacity-40`,children:`Add`})]})]})}),(0,R.jsx)(Ei,{open:ae!==void 0,onClose:()=>M(void 0),onConfirm:()=>void ce(),title:`Remove remote`,message:ae===void 0?``:`Remove remote "${ae}"? The local repo loses its reference to this URL; existing commits aren't affected.`,primaryLabel:`Remove`,tone:`danger`})]})}var PN=3e3;function FN(e){let[t,n]=(0,v.useState)(void 0),r=(0,v.useRef)(void 0),i=()=>{r.current!==void 0&&(window.clearTimeout(r.current),r.current=void 0),n(void 0)};(0,v.useEffect)(()=>()=>{r.current!==void 0&&window.clearTimeout(r.current)},[]);let a=a=>{if(e.onRevert!==void 0){if(t===a.path){i(),e.onRevert(a);return}r.current!==void 0&&window.clearTimeout(r.current),n(a.path),r.current=window.setTimeout(()=>{n(void 0),r.current=void 0},PN)}};return(0,R.jsxs)(`div`,{className:`border-t border-neutral-800/60`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-1.5`,children:[(0,R.jsxs)(`span`,{className:`text-[10px] uppercase tracking-wider text-neutral-500`,children:[e.label,` (`,e.files.length,`)`]}),(0,R.jsx)(`button`,{onClick:e.onGroupAction,className:`text-[10px] text-neutral-400 hover:text-neutral-200`,children:e.actionLabel})]}),(0,R.jsx)(`ul`,{children:e.files.map(n=>{let r=`${n.path}|${e.staged?`staged`:`unstaged`}`,i=e.openDiffs[r],o=t===n.path;return(0,R.jsxs)(`li`,{className:`border-t border-neutral-900`,children:[(0,R.jsxs)(`div`,{className:`group flex items-center gap-2 px-3 py-1 hover:bg-neutral-900`,children:[(0,R.jsx)(`span`,{className:`inline-block w-5 shrink-0 text-center font-mono text-[10px] text-neutral-500`,title:`porcelain code: ${n.code}`,children:IN(n.kind)}),(0,R.jsx)(`button`,{onClick:()=>e.onClickFile(n),className:`flex-1 truncate text-left font-mono`,title:n.path,children:n.path}),e.onRevert!==void 0&&(0,R.jsxs)(`button`,{onClick:()=>a(n),className:o?`inline-flex items-center gap-1 rounded bg-red-900/40 px-1 py-0.5 text-[10px] text-red-200 light:bg-red-100 light:text-red-800`:`hidden items-center gap-1 text-[10px] text-neutral-500 hover:text-red-300 group-hover:inline-flex light:hover:text-red-700`,title:o?`Click again to discard local changes (this cannot be undone)`:`Revert: discard local changes for this file`,children:[(0,R.jsx)(tt,{size:10}),o?`Confirm?`:`Revert`]}),(0,R.jsxs)(`button`,{onClick:()=>e.onFileAction(n),className:`ml-3 hidden items-center gap-1 text-[10px] text-neutral-500 hover:text-neutral-200 group-hover:inline-flex`,children:[e.fileActionLabel===`Stage`?(0,R.jsx)(He,{size:10}):e.fileActionLabel===`Unstage`?(0,R.jsx)(Re,{size:10}):null,e.fileActionLabel]})]}),i!==void 0&&(0,R.jsx)(`div`,{className:`border-t border-neutral-900 bg-neutral-950`,children:i===`loading`?(0,R.jsx)(`p`,{className:`px-3 py-2 italic text-neutral-500`,children:`Loading…`}):i===`error`?(0,R.jsx)(`p`,{className:`px-3 py-2 text-red-400 light:text-red-700`,children:`Failed to load diff.`}):i.length===0?(0,R.jsx)(`p`,{className:`px-3 py-2 italic text-neutral-500`,children:`(no diff — file is binary or unchanged)`}):(0,R.jsx)(mk,{diff:i,viewType:e.diffViewType,onHunkAction:e.onHunkAction===void 0?void 0:t=>e.onHunkAction?.(n,t),hunkActionLabel:e.staged?`Unstage hunk`:`Stage hunk`,hunkActionDisabled:e.pendingHunkPath===n.path})})]},n.path)})})]})}function IN(e){switch(e){case`modified`:return`M`;case`added`:return`A`;case`deleted`:return`D`;case`renamed`:return`R`;case`copied`:return`C`;case`untracked`:return`?`;case`ignored`:return`!`;case`conflicted`:return`U`;default:return`·`}}var LN=14,RN=36;function zN({commits:e}){let t=AN(e),n=Math.max(1,...t.map(e=>e.width));return(0,R.jsx)(`ul`,{className:`space-y-0`,children:e.map((e,r)=>{let i=t[r];return i===void 0?null:(0,R.jsxs)(`li`,{className:`group flex items-stretch`,children:[(0,R.jsx)(BN,{layout:i,isLast:r===t.length-1,maxLanes:n}),(0,R.jsxs)(`div`,{className:`flex flex-col justify-center gap-0.5 pl-2`,style:{minHeight:RN},children:[(0,R.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,R.jsx)(`span`,{className:`font-mono text-neutral-500`,children:e.hash.slice(0,7)}),e.refs.map((e,t)=>(0,R.jsx)(VN,{ref_:e},`${t}-${e}`)),(0,R.jsx)(`span`,{className:`truncate text-neutral-200`,title:e.message,children:e.message})]}),(0,R.jsxs)(`span`,{className:`font-mono text-[10px] text-neutral-600`,children:[e.author,` · `,new Date(e.date).toLocaleString()]})]})]},e.hash)})})}function BN({layout:e,isLast:t,maxLanes:n}){let r=n*LN,i=RN,a=e.lane*LN+LN/2,o=i/2,s=[];for(let t of e.through){let e=t*LN+LN/2;s.push({x1:e,y1:0,x2:e,y2:i,color:MN(t)})}for(let t of e.incomingLanes){let e=t*LN+LN/2;s.push({x1:e,y1:0,x2:a,y2:o,color:MN(t)})}if(!t)for(let t of e.outgoingLanes){let e=t.lane*LN+LN/2;s.push({x1:a,y1:o,x2:e,y2:i,color:MN(t.lane)})}if(t&&e.outgoingLanes.length>0)for(let t of e.outgoingLanes){let e=t.lane*LN+LN/2;s.push({x1:a,y1:o,x2:e,y2:24,color:MN(t.lane)})}return(0,R.jsxs)(`svg`,{width:r,height:i,viewBox:`0 0 ${r} ${i}`,className:`shrink-0`,"aria-hidden":!0,children:[s.map((e,t)=>(0,R.jsx)(`line`,{x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2,stroke:e.color,strokeWidth:1.5,strokeLinecap:`round`},t)),(0,R.jsx)(`circle`,{cx:a,cy:o,r:3.5,fill:MN(e.lane)})]})}function VN({ref_:e}){let t=e.startsWith(`HEAD ->`)||e===`HEAD`,n=e.startsWith(`tag:`),r=t?e.replace(/^HEAD ->\s*/,``):n?e.replace(/^tag:\s*/,``):e;return(0,R.jsx)(`span`,{className:`shrink-0 rounded px-1.5 py-0 text-[9px] uppercase tracking-wider ${t?`bg-emerald-900/40 text-emerald-300 light:bg-emerald-100 light:text-emerald-800`:n?`bg-amber-900/40 text-amber-300 light:bg-amber-100 light:text-amber-800`:e.includes(`/`)?`bg-neutral-800 text-neutral-500`:`bg-neutral-800 text-neutral-300`}`,children:n?`▼ ${r}`:r})}var HN=250,UN=2,WN=200;function GN(){let e=dr(),t=ai(e=>e.openFile),n=JA(e=>e.openEditorPane),[r,i]=(0,v.useState)(``),[a,o]=(0,v.useState)(!1),[s,c]=(0,v.useState)(!1),[l,u]=(0,v.useState)(!1),[d,f]=(0,v.useState)(``),[p,m]=(0,v.useState)(``),[h,g]=(0,v.useState)(!1),[_,y]=(0,v.useState)(void 0),[b,x]=(0,v.useState)(!1),[S,C]=(0,v.useState)(void 0),w=(0,v.useRef)(void 0),T=(0,v.useCallback)(async t=>{if(e===void 0)return;if(t.length<UN){y(void 0),C(void 0);return}w.current?.abort();let n=new AbortController;w.current=n,x(!0),C(void 0);try{let r={query:t,regex:a,caseSensitive:s,includeGitignored:l,limit:WN,...d.length>0?{include:d}:{},...p.length>0?{exclude:p}:{}},i=await L.searchFiles(e.id,r,n.signal);if(n.signal.aborted)return;y(i)}catch(e){if(n.signal.aborted||e instanceof Error&&e.name===`AbortError`)return;e instanceof N&&e.code===`invalid_response_body`?C(`server returned an unexpected response`):e instanceof Error?C(e.message):C(`search failed`),y(void 0)}finally{n.signal.aborted||x(!1)}},[e,a,s,l,d,p]);(0,v.useEffect)(()=>{let e=window.setTimeout(()=>void T(r),HN);return()=>window.clearTimeout(e)},[r,T]),(0,v.useEffect)(()=>()=>{w.current?.abort()},[]);let E=(0,v.useMemo)(()=>qN(_?.matches??[]),[_]);return e===void 0?(0,R.jsx)(`div`,{className:`p-4 text-xs italic text-neutral-500`,children:`Select a project to search its files.`}):(0,R.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,R.jsxs)(`div`,{className:`border-b border-neutral-800 bg-neutral-900/40 p-2`,children:[(0,R.jsxs)(`div`,{className:`relative`,children:[(0,R.jsx)(qe,{size:12,className:`pointer-events-none absolute left-2 top-1/2 -translate-y-1/2 text-neutral-500`}),(0,R.jsx)(`input`,{type:`text`,value:r,onChange:e=>i(e.target.value),placeholder:a?`Regex…`:`Search project…`,className:`w-full rounded border border-neutral-700 bg-neutral-900 py-1.5 pl-7 pr-2 text-xs text-neutral-100 placeholder:text-neutral-500 focus:border-neutral-500 focus:outline-none`,autoFocus:!0})]}),(0,R.jsxs)(`div`,{className:`mt-2 flex flex-wrap gap-1`,children:[(0,R.jsx)(JN,{label:`Regex`,active:a,onClick:()=>o(e=>!e)}),(0,R.jsx)(JN,{label:`Aa`,title:`Case sensitive`,active:s,onClick:()=>c(e=>!e)}),(0,R.jsx)(JN,{label:`+ignored`,title:`Include files that .gitignore would normally skip`,active:l,onClick:()=>u(e=>!e)}),(0,R.jsxs)(`button`,{onClick:()=>g(e=>!e),className:`ml-auto flex items-center gap-1 rounded border border-neutral-700 px-1.5 py-0.5 text-[10px] text-neutral-400 hover:border-neutral-500`,children:[h?(0,R.jsx)(ue,{size:10}):(0,R.jsx)(fe,{size:10}),`Globs`]})]}),h&&(0,R.jsxs)(`div`,{className:`mt-2 grid grid-cols-1 gap-1.5`,children:[(0,R.jsx)(`input`,{type:`text`,value:d,onChange:e=>f(e.target.value),placeholder:`include glob — e.g. **/*.ts`,className:`rounded border border-neutral-700 bg-neutral-900 px-2 py-1 text-[11px] text-neutral-200 placeholder:text-neutral-500 focus:border-neutral-500 focus:outline-none`}),(0,R.jsx)(`input`,{type:`text`,value:p,onChange:e=>m(e.target.value),placeholder:`exclude glob — e.g. **/dist/**`,className:`rounded border border-neutral-700 bg-neutral-900 px-2 py-1 text-[11px] text-neutral-200 placeholder:text-neutral-500 focus:border-neutral-500 focus:outline-none`})]})]}),(0,R.jsxs)(`div`,{className:`flex-1 overflow-auto`,children:[(0,R.jsx)(YN,{query:r,loading:b,error:S,results:_,totalFiles:E.length}),(0,R.jsx)(`ul`,{className:`divide-y divide-neutral-900`,children:E.map(([r,i])=>(0,R.jsx)(XN,{path:r,matches:i,onPick:i=>{t(e.id,KN(e.path,r),{line:i.line,column:i.column}),n()}},r))})]})]})}function KN(e,t){return t.startsWith(`/`)?t:`${e}${e.endsWith(`/`)?``:`/`}${t}`}function qN(e){let t=new Map;for(let n of e){let e=t.get(n.path);e===void 0?t.set(n.path,[n]):e.push(n)}return Array.from(t.entries())}function JN({label:e,title:t,active:n,onClick:r}){return(0,R.jsx)(`button`,{onClick:r,title:t,className:`rounded border px-1.5 py-0.5 text-[10px] ${n?`border-neutral-500 bg-neutral-800 text-neutral-100`:`border-neutral-700 text-neutral-400 hover:border-neutral-500`}`,children:e})}function YN({query:e,loading:t,error:n,results:r,totalFiles:i}){return e.length===0?(0,R.jsxs)(`div`,{className:`flex flex-col items-center gap-2 px-4 py-8 text-center text-xs text-neutral-500`,children:[(0,R.jsx)(we,{size:20,className:`text-neutral-700`}),(0,R.jsx)(`p`,{children:`Type to search across project files.`}),(0,R.jsxs)(`p`,{className:`text-[10px] text-neutral-600`,children:[`Min `,UN,` chars · Click a result to jump to that line.`]})]}):e.length<UN?(0,R.jsxs)(`div`,{className:`px-4 py-3 text-xs italic text-neutral-500`,children:[`Keep typing — at least `,UN,` characters.`]}):t&&r===void 0?(0,R.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-3 text-xs text-neutral-400`,children:[(0,R.jsx)(Ne,{size:12,className:`animate-spin`}),` Searching…`]}):n===void 0?r===void 0?null:r.matches.length===0?(0,R.jsx)(`div`,{className:`px-4 py-3 text-xs italic text-neutral-500`,children:`No matches.`}):(0,R.jsxs)(`div`,{className:`flex items-center justify-between gap-2 border-b border-neutral-800 bg-neutral-950/60 px-3 py-1.5 text-[10px]`,children:[(0,R.jsxs)(`span`,{className:`text-neutral-400`,children:[r.matches.length,` match`,r.matches.length===1?``:`es`,` in `,i,` `,`file`,i===1?``:`s`,r.truncated&&(0,R.jsxs)(`span`,{className:`ml-1 text-amber-400 light:text-amber-700`,children:[`· truncated at `,WN]})]}),r.engine===`node`&&(0,R.jsx)(`span`,{className:`rounded bg-amber-900/40 px-1.5 py-0.5 text-[9px] uppercase tracking-wider text-amber-300 light:bg-amber-100 light:text-amber-800`,title:`ripgrep was not found on this host — using the slower in-process fallback`,children:`fallback`})]}):(0,R.jsx)(`div`,{className:`px-4 py-3 text-xs text-rose-400 light:text-rose-700`,children:n})}function XN({path:e,matches:t,onPick:n}){let[r,i]=(0,v.useState)(!0);return(0,R.jsxs)(`li`,{className:`bg-neutral-950`,children:[(0,R.jsxs)(`button`,{onClick:()=>i(e=>!e),className:`flex w-full items-center gap-1 truncate px-2 py-1 text-left text-[11px] text-neutral-300 hover:bg-neutral-900`,title:e,children:[r?(0,R.jsx)(ue,{size:11}):(0,R.jsx)(fe,{size:11}),(0,R.jsx)(`span`,{className:`truncate font-mono`,children:e}),(0,R.jsx)(`span`,{className:`ml-auto text-[10px] text-neutral-500`,children:t.length})]}),r&&(0,R.jsx)(`ul`,{children:t.map((t,r)=>(0,R.jsx)(`li`,{children:(0,R.jsxs)(`button`,{onClick:()=>n(t),className:`flex w-full gap-2 px-2 py-0.5 text-left font-mono text-[11px] text-neutral-400 hover:bg-neutral-900 hover:text-neutral-100`,title:`${e}:${t.line}:${t.column}`,children:[(0,R.jsx)(`span`,{className:`w-10 shrink-0 text-right text-neutral-600`,children:t.line}),(0,R.jsx)(`span`,{className:`truncate`,children:ZN(t.lineSnippet,t.column,t.length)})]})},`${t.line}:${t.column}:${r}`))})]})}function ZN(e,t,n){let r=Math.max(0,Math.min(e.length,t-1)),i=Math.max(r,Math.min(e.length,r+n)),a=e.length-e.trimStart().length,o=Math.min(a,r),s=e.slice(o,r),c=e.slice(r,i),l=e.slice(i);return n===0||c.length===0?(0,R.jsx)(`span`,{children:e.slice(o)}):(0,R.jsxs)(`span`,{children:[(0,R.jsx)(`span`,{children:s}),(0,R.jsx)(`span`,{className:`bg-amber-700/30 text-amber-100 light:bg-amber-200 light:text-amber-900`,children:c}),(0,R.jsx)(`span`,{children:l})]})}var QN=3;function $N(){let e=Jr(e=>e.activeSessionId),t=Jr(t=>e===void 0?0:t.agentEndCountBySession[e]??0),n=Jr(t=>e===void 0?0:t.compactionEndCountBySession[e]??0),r=Jr(t=>e===void 0?!1:t.streamingBySession[e]??!1),i=Jr(t=>e===void 0?``:t.streamingTextBySession[e]??``),[a,o]=(0,v.useState)(void 0),[s,c]=(0,v.useState)(!1),[l,u]=(0,v.useState)(void 0),[d,f]=(0,v.useState)(!1),[p,m]=(0,v.useState)(!1),[h,g]=(0,v.useState)(``),[_,y]=(0,v.useState)(void 0),b=(0,v.useRef)(void 0),x=async()=>{if(e===void 0){o(void 0);return}b.current?.abort();let t=new AbortController;b.current=t,c(!0),u(void 0);try{let n=await L.getSessionContext(e,t.signal);if(t.signal.aborted)return;o(n)}catch(e){if(t.signal.aborted||e instanceof Error&&e.name===`AbortError`)return;e instanceof N&&e.status===404?(o(void 0),u(void 0)):u(e instanceof N?e.code:e.message)}finally{t.signal.aborted||c(!1)}};return(0,v.useEffect)(()=>{x()},[e,t,n]),(0,v.useEffect)(()=>()=>{b.current?.abort()},[]),e===void 0?(0,R.jsx)(`div`,{className:`flex h-full items-center justify-center px-4 py-6 text-center text-xs italic text-neutral-500`,children:`Select a session to inspect its context.`}):(0,R.jsxs)(`div`,{className:`flex h-full flex-col bg-neutral-950 text-xs text-neutral-200`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between border-b border-neutral-800 bg-neutral-900/40 px-3 py-1.5`,children:[(0,R.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-neutral-400`,children:`Context inspector`}),(0,R.jsxs)(`div`,{className:`flex items-center gap-1`,children:[s&&(0,R.jsx)(Ne,{size:11,className:`animate-spin text-neutral-500`}),(0,R.jsx)(`button`,{onClick:()=>void x(),disabled:s,className:`rounded p-1 text-neutral-500 hover:bg-neutral-800 hover:text-neutral-200 disabled:opacity-40`,title:`Refresh`,children:(0,R.jsx)(Ue,{size:11,className:s?`animate-spin`:``})})]})]}),l!==void 0&&(0,R.jsx)(`div`,{className:`border-b border-red-700/40 bg-red-900/20 px-3 py-1.5 text-[11px] text-red-300 light:border-red-300 light:bg-red-50 light:text-red-700`,children:l}),(0,R.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:a===void 0?(0,R.jsx)(`div`,{className:`px-4 py-6 text-center text-xs italic text-neutral-500`,children:s?`Loading…`:`No data — try refresh.`}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(eP,{data:a,turnsExpanded:d,onToggleTurns:()=>f(e=>!e)}),(0,R.jsx)(aP,{messages:a.messages,showThinking:p,onToggleThinking:()=>m(e=>!e),onViewRaw:(e,t)=>y({index:e,payload:t}),search:h,onSearchChange:g,...r&&i.length>0?{streamingTail:{content:i}}:{}})]})}),_!==void 0&&(0,R.jsx)(sP,{title:`Message ${_.index} — raw AgentMessage JSON`,payload:_.payload,onClose:()=>y(void 0)})]})}function eP({data:e,turnsExpanded:t,onToggleTurns:n}){let r=e.contextUsage,i=(0,v.useMemo)(()=>rP(e.messages,r.tokens),[e.messages,r.tokens]),a=(0,v.useMemo)(()=>dP(e.messages,e.turns),[e.messages,e.turns]),o=r.tokens??i.total,s=r.contextWindow>0?Math.min(1,o/r.contextWindow):0;return(0,R.jsxs)(`div`,{className:`space-y-2 border-b border-neutral-800 px-3 py-2`,children:[(0,R.jsxs)(`div`,{children:[(0,R.jsxs)(`div`,{className:`mb-1 flex items-center justify-between text-[10px] text-neutral-400`,children:[(0,R.jsxs)(`span`,{children:[`Context window (`,r.tokens===void 0?`estimate`:`current`,`)`]}),(0,R.jsxs)(`span`,{children:[mP(o),` /`,` `,r.contextWindow>0?mP(r.contextWindow):`unknown`,r.contextWindow>0&&(0,R.jsxs)(`span`,{className:`ml-1 text-neutral-600`,children:[`(`,(s*100).toFixed(1),`%)`]})]})]}),(0,R.jsx)(`div`,{className:`h-1.5 w-full overflow-hidden rounded bg-neutral-800`,children:(0,R.jsx)(`div`,{className:`h-full ${s>.9?`bg-red-500`:s>.7?`bg-amber-500`:`bg-emerald-500`}`,style:{width:`${Math.max(2,Math.min(100,s*100))}%`}})})]}),(0,R.jsx)(nP,{breakdown:i,contextWindow:r.contextWindow}),(0,R.jsxs)(`div`,{className:`space-y-0.5 border-t border-neutral-800 pt-1.5`,children:[e.turns.length>0&&(()=>{let t=e.turns[e.turns.length-1],n=a.get(t.index)??0;return(0,R.jsxs)(`div`,{className:`flex items-center justify-between text-[11px]`,children:[(0,R.jsx)(`span`,{className:`text-neutral-500`,children:`Last turn`}),(0,R.jsxs)(`span`,{className:`font-mono text-neutral-300`,title:`New = user message + tool results since the prior assistant turn (estimate). Out = assistant output tokens. Cost = that turn's billed cost.`,children:[`~`,mP(n),` new · `,mP(t.outputTokens),` out ·`,` `,hP(t.cost)]})]})})(),(0,R.jsxs)(`div`,{className:`flex items-center justify-between text-[11px]`,children:[(0,R.jsx)(`span`,{className:`text-neutral-500`,title:"Sum of `usage.input` per turn — NEW non-cached input the LLM saw across the session. Excludes cached portions (tracked separately below).",children:`Input (lifetime)`}),(0,R.jsx)(`span`,{className:`font-mono text-neutral-400`,children:mP(e.totalInputTokens)})]}),(0,R.jsxs)(`div`,{className:`flex items-center justify-between text-[11px]`,children:[(0,R.jsx)(`span`,{className:`text-neutral-500`,title:"Sum of `usage.cacheRead` per turn — prior context served from the prompt cache. Counted ONCE PER API CALL: every turn re-reads the same cached content and re-pays the (discounted) read fee, so this number grows ~quadratically with conversation length. Billed at ~10% of input rate on most providers.",children:`Cache served (lifetime)`}),(0,R.jsx)(`span`,{className:`font-mono text-neutral-400`,children:mP(e.totalCacheReadTokens)})]}),(0,R.jsxs)(`div`,{className:`flex items-center justify-between text-[11px]`,children:[(0,R.jsx)(`span`,{className:`text-neutral-500`,title:"Sum of `usage.cacheWrite` per turn — portions cached for reuse on subsequent turns. Billed at ~125% of input rate; small premium up front for big savings on the cache-served line.",children:`Cache written (lifetime)`}),(0,R.jsx)(`span`,{className:`font-mono text-neutral-400`,children:mP(e.totalCacheWriteTokens)})]}),(0,R.jsxs)(`div`,{className:`flex items-center justify-between text-[11px]`,children:[(0,R.jsx)(`span`,{className:`text-neutral-500`,title:"Sum of `usage.output` per turn — assistant tokens generated.",children:`Output (lifetime)`}),(0,R.jsx)(`span`,{className:`font-mono text-neutral-400`,children:mP(e.totalOutputTokens)})]}),(0,R.jsxs)(`div`,{className:`flex items-center justify-between text-[11px] font-medium`,children:[(0,R.jsx)(`span`,{className:`text-neutral-300`,children:`Total cost`}),(0,R.jsx)(`span`,{className:`font-mono text-emerald-400 light:text-emerald-700`,children:hP(e.totalCost)})]})]}),e.turns.length>0&&(0,R.jsxs)(`div`,{children:[(0,R.jsxs)(`button`,{onClick:n,className:`flex items-center gap-1 text-[10px] uppercase tracking-wider text-neutral-400 hover:text-neutral-200`,children:[t?(0,R.jsx)(ue,{size:10}):(0,R.jsx)(fe,{size:10}),`Per-turn (`,e.turns.length,`)`]}),t&&(0,R.jsx)(iP,{turns:e.turns,newDeltas:a})]})]})}var tP=[{key:`systemAndTools`,label:`System + tools`,color:`#64748b`},{key:`userPrompts`,label:`User prompts`,color:`#0ea5e9`},{key:`assistantText`,label:`Assistant text`,color:`#a78bfa`},{key:`thinking`,label:`Thinking`,color:`#71717a`},{key:`toolCalls`,label:`Tool calls`,color:`#f59e0b`},{key:`toolResults`,label:`Tool results`,color:`#10b981`},{key:`images`,label:`Images`,color:`#ec4899`}];function nP({breakdown:e,contextWindow:t}){let n=e.total;return n===0?null:(0,R.jsxs)(`div`,{children:[(0,R.jsxs)(`div`,{className:`mb-1 flex items-center justify-between text-[10px] text-neutral-400`,children:[(0,R.jsx)(`span`,{children:`What’s in the context`}),(0,R.jsxs)(`span`,{className:`text-neutral-600`,title:`Sum of category estimates (~chars/3)`,children:[`~`,mP(n),` tok`,t>0&&(0,R.jsxs)(`span`,{className:`ml-1`,children:[`(`,(n/t*100).toFixed(1),`%)`]})]})]}),(0,R.jsx)(`div`,{className:`flex h-1.5 w-full overflow-hidden rounded bg-neutral-800`,children:tP.map(t=>{let r=e[t.key];if(r===0)return null;let i=r/n*100;return(0,R.jsx)(`div`,{style:{width:`${i}%`,background:t.color},title:`${t.label}: ${mP(r)} tok (${i.toFixed(1)}%)`},t.key)})}),(0,R.jsx)(`ul`,{className:`mt-1 grid grid-cols-2 gap-x-3 gap-y-0.5 text-[10px]`,children:tP.map(t=>{let r=e[t.key];if(r===0)return null;let i=r/n*100;return(0,R.jsxs)(`li`,{className:`flex items-center gap-1.5`,children:[(0,R.jsx)(`span`,{className:`inline-block h-2 w-2 rounded-sm`,style:{background:t.color},"aria-hidden":`true`}),(0,R.jsx)(`span`,{className:`flex-1 truncate text-neutral-400`,children:t.label}),(0,R.jsx)(`span`,{className:`font-mono text-neutral-300`,children:mP(r)}),(0,R.jsxs)(`span`,{className:`w-10 text-right text-neutral-600`,children:[i.toFixed(0),`%`]})]},t.key)})})]})}function rP(e,t){let n=0,r=0,i=0,a=0,o=0,s=0;for(let t of e){let e=typeof t.role==`string`?t.role:``,c=t.content;if(e===`user`){if(typeof c==`string`)n+=c.length;else if(Array.isArray(c))for(let e of c){let t=e;t.type===`text`&&typeof t.text==`string`?n+=t.text.length:t.type===`image`&&(s+=1)}}else if(e===`assistant`&&Array.isArray(c))for(let e of c){let t=e;if(t.type===`text`&&typeof t.text==`string`)r+=t.text.length;else if(t.type===`thinking`&&typeof t.thinking==`string`)i+=t.thinking.length;else if(t.type===`toolCall`)try{a+=JSON.stringify(t.arguments??{}).length}catch{a+=String(t.arguments??``).length}}else if(e===`toolResult`){if(typeof c==`string`)o+=c.length;else if(Array.isArray(c))for(let e of c){let t=e;t.type===`text`&&typeof t.text==`string`?o+=t.text.length:t.type===`image`&&(s+=1)}}}let c=e=>Math.ceil(e/QN),l=c(n),u=c(r),d=c(i),f=c(a),p=c(o),m=s*1500,h=l+u+d+f+p+m,g=t!==void 0&&t>h?t-h:0;return{systemAndTools:g,userPrompts:l,assistantText:u,thinking:d,toolCalls:f,toolResults:p,images:m,total:h+g}}function iP({turns:e,newDeltas:t}){return(0,R.jsx)(`div`,{className:`mt-1 overflow-x-auto`,children:(0,R.jsxs)(`table`,{className:`w-full font-mono text-[10px]`,children:[(0,R.jsx)(`thead`,{className:`text-neutral-500`,children:(0,R.jsxs)(`tr`,{children:[(0,R.jsx)(`th`,{className:`pr-2 text-left font-normal`,children:`#`}),(0,R.jsx)(`th`,{className:`pr-2 text-left font-normal`,children:`Model`}),(0,R.jsx)(`th`,{className:`pr-2 text-right font-normal`,title:`Estimated new tokens this turn — user message + tool results since the prior assistant turn (~chars/3 estimate). Distinct from Prompt.`,children:`New`}),(0,R.jsx)(`th`,{className:`pr-2 text-right font-normal`,title:`Full prompt sent to the LLM = usage.input + cacheRead + cacheWrite. Includes ALL re-sent prior context — this grows monotonically with conversation length, which is normal LLM behavior.`,children:`Prompt`}),(0,R.jsx)(`th`,{className:`pr-2 text-right font-normal`,title:`Assistant output tokens this turn`,children:`Out`}),(0,R.jsx)(`th`,{className:`text-right font-normal`,title:`Cost billed for this turn`,children:`Cost`})]})}),(0,R.jsx)(`tbody`,{className:`text-neutral-300`,children:e.map((e,n)=>{let r=e.inputTokens+e.cacheReadTokens+e.cacheWriteTokens,i=t.get(e.index)??0;return(0,R.jsxs)(`tr`,{className:`border-t border-neutral-800/60`,children:[(0,R.jsx)(`td`,{className:`pr-2 text-neutral-600`,children:n+1}),(0,R.jsx)(`td`,{className:`max-w-[140px] truncate pr-2`,title:`${e.provider}/${e.model}`,children:e.model}),(0,R.jsxs)(`td`,{className:`pr-2 text-right text-neutral-200`,title:`New content (estimate)`,children:[`~`,mP(i)]}),(0,R.jsx)(`td`,{className:`pr-2 text-right`,title:`input ${mP(e.inputTokens)} + cR ${mP(e.cacheReadTokens)} + cW ${mP(e.cacheWriteTokens)}`,children:mP(r)}),(0,R.jsx)(`td`,{className:`pr-2 text-right`,children:mP(e.outputTokens)}),(0,R.jsx)(`td`,{className:`text-right text-emerald-400 light:text-emerald-700`,children:hP(e.cost)})]},`${e.index}-${e.timestamp}`)})})]})})}function aP({messages:e,showThinking:t,onToggleThinking:n,onViewRaw:r,search:i,onSearchChange:a,streamingTail:o}){let s=i.trim().toLowerCase(),c=(0,v.useMemo)(()=>s.length===0?e.map((e,t)=>({msg:e,originalIndex:t})):e.map((e,t)=>({msg:e,originalIndex:t})).filter(({msg:e})=>(typeof e.role==`string`?e.role.toLowerCase():``).includes(s)?!0:lP(e,!0).toLowerCase().includes(s)),[e,s]);return(0,R.jsxs)(`div`,{className:`px-2 py-2`,children:[(0,R.jsxs)(`div`,{className:`mb-1 flex items-center justify-between gap-2 px-1`,children:[(0,R.jsxs)(`span`,{className:`shrink-0 text-[10px] uppercase tracking-wider text-neutral-400`,children:[`Messages (`,s.length>0?`${c.length}/${e.length}`:e.length,`)`]}),(0,R.jsxs)(`label`,{className:`flex items-center gap-1 text-[10px] text-neutral-500 hover:text-neutral-300`,children:[(0,R.jsx)(`input`,{type:`checkbox`,checked:t,onChange:n,className:`h-3 w-3`}),`Show thinking blocks`]})]}),e.length>=10&&(0,R.jsxs)(`div`,{className:`relative mb-1 px-1`,children:[(0,R.jsx)(qe,{size:11,className:`pointer-events-none absolute left-2.5 top-1/2 -translate-y-1/2 text-neutral-500`}),(0,R.jsx)(`input`,{type:`text`,value:i,onChange:e=>a(e.target.value),placeholder:`Find in messages…`,className:`w-full rounded border border-neutral-800 bg-neutral-950 py-1 pl-6 pr-2 text-[11px] text-neutral-200 placeholder:text-neutral-600 focus:border-neutral-600 focus:outline-none`})]}),(0,R.jsxs)(`ul`,{className:`space-y-1`,children:[c.map(({msg:e,originalIndex:n})=>(0,R.jsx)(oP,{index:n,message:e,showThinking:t,onViewRaw:()=>r(n,e)},n)),o!==void 0&&s.length===0&&(0,R.jsx)(`li`,{className:`rounded border border-violet-700/40 bg-violet-900/10 light:border-violet-300 light:bg-violet-50`,children:(0,R.jsxs)(`div`,{className:`flex items-start gap-2 px-2 py-1.5`,children:[(0,R.jsx)(Ne,{size:11,className:`mt-0.5 shrink-0 animate-spin text-violet-300 light:text-violet-700`}),(0,R.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-0.5`,children:[(0,R.jsx)(`div`,{className:`flex items-center gap-1.5`,children:(0,R.jsx)(`span`,{className:`rounded bg-violet-900/40 px-1.5 py-0.5 text-[9px] uppercase tracking-wider text-violet-300 light:bg-violet-100 light:text-violet-800`,children:`assistant (streaming)`})}),(0,R.jsx)(`p`,{className:`line-clamp-2 text-[11px] text-neutral-300`,children:o.content})]})]})})]})]})}function oP({index:e,message:t,showThinking:n,onViewRaw:r}){let[i,a]=(0,v.useState)(!1),o=typeof t.role==`string`?t.role:`unknown`,s=o===`compactionSummary`,c=(0,v.useMemo)(()=>lP(t,n),[t,n]),l=uP(t),u=typeof t.timestamp==`number`?t.timestamp:0;return(0,R.jsxs)(`li`,{className:`rounded border border-neutral-800/70 bg-neutral-900/30`,children:[(0,R.jsxs)(`button`,{onClick:()=>a(e=>!e),className:`flex w-full items-start gap-2 px-2 py-1.5 text-left hover:bg-neutral-900/60`,children:[(0,R.jsx)(`span`,{className:`pt-0.5 text-neutral-600`,children:i?(0,R.jsx)(ue,{size:11}):(0,R.jsx)(fe,{size:11})}),(0,R.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-0.5`,children:[(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,R.jsx)(`span`,{className:`rounded px-1.5 py-0.5 text-[9px] uppercase tracking-wider ${cP(o)}`,children:o}),s&&(0,R.jsx)(`span`,{className:`rounded bg-fuchsia-900/40 px-1.5 py-0.5 text-[9px] text-fuchsia-300 light:bg-fuchsia-100 light:text-fuchsia-800`,children:`compacted`}),(0,R.jsxs)(`span`,{className:`text-[10px] text-neutral-600`,children:[`~`,mP(l),` tok`]}),u>0&&(0,R.jsx)(`span`,{className:`text-[10px] text-neutral-600`,children:new Date(u).toLocaleTimeString()})]}),!i&&c.length>0&&(0,R.jsx)(`p`,{className:`line-clamp-2 text-[11px] text-neutral-400`,children:c})]}),(0,R.jsx)(`button`,{onClick:e=>{e.stopPropagation(),r()},className:`rounded p-1 text-neutral-500 hover:bg-neutral-800 hover:text-neutral-100`,title:`View raw AgentMessage JSON`,children:(0,R.jsx)(ge,{size:11})})]}),i&&(0,R.jsx)(`div`,{className:`space-y-1 border-t border-neutral-800/70 px-3 py-2`,children:fP(t,n,e)})]})}function sP({title:e,payload:t,onClose:n}){let r=(0,v.useMemo)(()=>{try{return JSON.stringify(t,null,2)}catch{return String(t)}},[t]);return(0,v.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]),(0,R.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/70 px-4 py-8`,onClick:n,children:(0,R.jsxs)(`div`,{onClick:e=>e.stopPropagation(),className:`flex h-full max-h-[720px] w-full max-w-4xl flex-col overflow-hidden rounded-lg border border-neutral-800 bg-neutral-950 shadow-2xl`,children:[(0,R.jsxs)(`header`,{className:`flex items-center justify-between border-b border-neutral-800 px-3 py-2`,children:[(0,R.jsx)(`span`,{className:`text-xs text-neutral-200`,children:e}),(0,R.jsx)(`button`,{onClick:n,className:`rounded p-2 text-neutral-400 hover:bg-neutral-800 hover:text-neutral-200`,title:`Close (Esc)`,children:(0,R.jsx)(it,{size:20})})]}),(0,R.jsx)(Oa,{code:r,language:`json`,theme:Zi.vsDark,children:({style:e,tokens:t,getLineProps:n,getTokenProps:r})=>(0,R.jsx)(`pre`,{className:`flex-1 overflow-auto whitespace-pre p-3 font-mono text-[11px]`,style:{...e,background:`transparent`},children:t.map((e,t)=>(0,R.jsx)(`div`,{...n({line:e}),children:e.map((e,t)=>(0,R.jsx)(`span`,{...r({token:e})},t))},t))})})]})})}function cP(e){return e===`user`?`bg-sky-900/40 text-sky-300 light:bg-sky-100 light:text-sky-800`:e===`assistant`?`bg-violet-900/40 text-violet-300 light:bg-violet-100 light:text-violet-800`:e===`tool`||e===`toolResult`?`bg-amber-900/40 text-amber-300 light:bg-amber-100 light:text-amber-800`:e===`compactionSummary`?`bg-fuchsia-900/40 text-fuchsia-300 light:bg-fuchsia-100 light:text-fuchsia-800`:`bg-neutral-800 text-neutral-400`}function lP(e,t){let n=e.content;if(typeof n==`string`)return n.slice(0,200);if(!Array.isArray(n))return``;let r=[];for(let e of n){let n=e;n.type===`thinking`&&!t||(n.type===`text`&&typeof n.text==`string`?r.push(n.text):n.type===`thinking`&&typeof n.thinking==`string`?r.push(`[thinking] ${n.thinking}`):n.type===`toolCall`&&typeof n.name==`string`&&r.push(`[tool: ${n.name}]`))}return r.join(` `).slice(0,200)}function uP(e){let t=e.usage;if(t!==void 0&&typeof t.totalTokens==`number`)return t.totalTokens;let n=e.content;if(typeof n==`string`)return Math.ceil(n.length/QN);if(!Array.isArray(n))return 0;let r=0,i=0;for(let e of n){let t=e;typeof t.text==`string`&&(r+=t.text.length),t.type===`image`&&(i+=1)}return Math.ceil(r/QN)+i*1500}function dP(e,t){let n=new Map,r=-1;for(let i of t){let t=0;for(let n=r+1;n<i.index;n++){let r=e[n];if(r===void 0)continue;let i=typeof r.role==`string`?r.role:``;i!==`user`&&i!==`toolResult`||(t+=uP(r))}n.set(i.index,t),r=i.index}return n}function fP(e,t,n){let r=typeof e.role==`string`?e.role:`unknown`,i=e.content;return r===`toolResult`?(0,R.jsxs)(`div`,{children:[(0,R.jsxs)(`p`,{className:`mb-1 text-[10px] text-neutral-500`,children:[`tool: `,(0,R.jsx)(`span`,{className:`font-mono`,children:String(e.toolName??`unknown`)}),` `,e.isError===!0&&(0,R.jsx)(`span`,{className:`text-red-400 light:text-red-700`,children:`(error)`})]}),(0,R.jsx)(`pre`,{className:`max-h-64 overflow-auto whitespace-pre-wrap break-words rounded bg-neutral-950 p-2 font-mono text-[10px] text-neutral-300`,children:pP(i)})]}):Array.isArray(i)?(0,R.jsx)(R.Fragment,{children:i.map((e,r)=>{let i=e;if(i.type===`thinking`&&!t)return null;if(i.type===`text`||i.type===`thinking`){let e=i.type===`thinking`?i.thinking:i.text;return(0,R.jsx)(`pre`,{className:`whitespace-pre-wrap break-words font-sans text-[11px] ${i.type===`thinking`?`italic text-neutral-500`:`text-neutral-200`}`,children:String(e??``)},`${n}-${r}`)}return i.type===`toolCall`?(0,R.jsxs)(`div`,{className:`rounded border border-neutral-800 p-2`,children:[(0,R.jsxs)(`p`,{className:`mb-1 text-[10px] text-neutral-500`,children:[`tool call: `,(0,R.jsx)(`span`,{className:`font-mono`,children:String(i.name??`unknown`)})]}),(0,R.jsx)(`pre`,{className:`max-h-48 overflow-auto whitespace-pre-wrap break-words font-mono text-[10px] text-neutral-300`,children:pP(i.arguments)})]},`${n}-${r}`):i.type===`image`?(0,R.jsx)(`p`,{className:`text-[11px] italic text-neutral-500`,children:`[image attachment]`},`${n}-${r}`):(0,R.jsx)(`pre`,{className:`whitespace-pre-wrap break-words font-mono text-[10px] text-neutral-500`,children:pP(i)},`${n}-${r}`)})}):typeof i==`string`?(0,R.jsx)(`pre`,{className:`whitespace-pre-wrap break-words font-sans text-[11px] text-neutral-200`,children:i}):(0,R.jsx)(`pre`,{className:`whitespace-pre-wrap break-words font-mono text-[10px] text-neutral-500`,children:pP(e)})}function pP(e){try{return JSON.stringify(e,null,2)}catch{return String(e)}}function mP(e){return e<1e3?String(e):e<1e6?`${(e/1e3).toFixed(+(e<1e4))}k`:`${(e/1e6).toFixed(2)}M`}function hP(e){return e===0?`$0`:e<.01?`$${e.toFixed(4)}`:e<1?`$${e.toFixed(3)}`:`$${e.toFixed(2)}`}function gP({getStartSize:e,onResize:t,direction:n,minSize:r,maxSize:i,orientation:a=`vertical`}){let o=(0,v.useRef)(null),s=a===`horizontal`,c=s?`row-resize`:`col-resize`;(0,v.useEffect)(()=>{let e=()=>{o.current!==null&&(o.current=null,document.body.style.removeProperty(`cursor`),document.body.style.removeProperty(`user-select`))},t=t=>{t.key===`Escape`&&e()};return window.addEventListener(`keydown`,t),window.addEventListener(`blur`,e),()=>{e(),window.removeEventListener(`keydown`,t),window.removeEventListener(`blur`,e)}},[]);let l=t=>{t.preventDefault(),t.currentTarget.setPointerCapture(t.pointerId),o.current={start:s?t.clientY:t.clientX,startSize:e()},document.body.style.cursor=c,document.body.style.userSelect=`none`},u=e=>{if(o.current===null)return;let a=(s?e.clientY:e.clientX)-o.current.start,c=o.current.startSize+a*n;t(Math.min(Math.max(c,r),i))},d=e=>{o.current!==null&&(e.currentTarget.releasePointerCapture(e.pointerId),o.current=null,document.body.style.removeProperty(`cursor`),document.body.style.removeProperty(`user-select`))},f=s?`h-1 w-full cursor-row-resize`:`w-1 h-full cursor-col-resize`,p=s?`absolute inset-x-0 -top-1 -bottom-1`:`absolute inset-y-0 -left-1 -right-1`;return(0,R.jsx)(`div`,{onPointerDown:l,onPointerMove:u,onPointerUp:d,onPointerCancel:d,className:`group relative shrink-0 bg-neutral-800 hover:bg-neutral-600 active:bg-neutral-500 ${f}`,role:`separator`,"aria-orientation":s?`horizontal`:`vertical`,children:(0,R.jsx)(`div`,{className:p})})}var _P=`pi-forge/files-width`,vP=`pi-forge/editor-width`,yP=`pi-forge/terminal-height`,bP=`pi-forge/todo-panel-height`,xP=280,SP=480,CP=280,wP=200,TP=200,EP=320,DP=320,OP=140,kP=100;function AP(e,t){let n=localStorage.getItem(e);if(n===null)return t;let r=Number.parseInt(n,10);return Number.isFinite(r)&&r>0?r:t}function jP(){let e=ar(e=>e.ready),t=ar(e=>e.isAuthenticated),n=ar(e=>e.mustChangePassword),r=ar(e=>e.bootstrap),i=ar(e=>e.logout),a=ur(e=>e.projects),o=ur(e=>!e.loading),s=ur(e=>e.load),c=dr(),l=ur(e=>e.activeProjectId),u=Jr(e=>e.activeSessionId),d=st(),[f,p]=(0,v.useState)(!1),[m,h]=(0,v.useState)(!1),[g,_]=(0,v.useState)(()=>localStorage.getItem(`pi-forge/files-open`)===`true`),y=e=>{_(e),localStorage.setItem(`pi-forge/files-open`,e?`true`:`false`)},[b,x]=(0,v.useState)(()=>{let e=localStorage.getItem(`pi-forge/right-tab`);return e===`files`||e===`search`||e===`changes`||e===`git`||e===`context`||e===`processes`?e:`files`}),S=e=>{x(e),localStorage.setItem(`pi-forge/right-tab`,e)},[C,w]=(0,v.useState)(()=>localStorage.getItem(`pi-forge/terminal-open`)===`true`),T=e=>{w(e),localStorage.setItem(`pi-forge/terminal-open`,e?`true`:`false`)},[E,D]=(0,v.useState)(()=>localStorage.getItem(`pi-forge/chat-open`)!==`false`),O=e=>{D(e),localStorage.setItem(`pi-forge/chat-open`,e?`true`:`false`)},[k,ee]=(0,v.useState)(()=>localStorage.getItem(`pi-forge/editor-open`)!==`false`),A=e=>{ee(e),localStorage.setItem(`pi-forge/editor-open`,e?`true`:`false`)},[te,ne]=(0,v.useState)(!1),[re,ie]=(0,v.useState)(()=>AP(yP,CP)),j=(0,v.useRef)(re);(0,v.useEffect)(()=>{j.current=re,localStorage.setItem(yP,String(re))},[re]);let[ae,M]=(0,v.useState)(()=>AP(bP,wP)),oe=(0,v.useRef)(ae);(0,v.useEffect)(()=>{oe.current=ae,localStorage.setItem(bP,String(ae))},[ae]);let se=JA(e=>e.todoPanelOpen);(0,v.useEffect)(()=>{se&&!g&&!d&&y(!0)},[se]);let ce=JA(e=>e.openProcessesTabSeq);(0,v.useEffect)(()=>{ce!==0&&(!g&&!d&&y(!0),S(`processes`))},[ce]);let le=JA(e=>e.openEditorPaneSeq);(0,v.useEffect)(()=>{le!==0&&A(!0)},[le]);let[ue,de]=(0,v.useState)(()=>AP(_P,xP)),[fe,pe]=(0,v.useState)(()=>AP(vP,SP)),me=(0,v.useRef)(ue),he=(0,v.useRef)(fe);(0,v.useEffect)(()=>{me.current=ue,localStorage.setItem(_P,String(ue))},[ue]),(0,v.useEffect)(()=>{he.current=fe,localStorage.setItem(vP,String(fe))},[fe]);let ge=ai(e=>e.openFiles.length),_e=k&&ge>0,ve=kN(c?.id).status?.files.length??0,ye=Ir(Nr(e=>Pr(e,u))),be=Jr(e=>u===void 0?0:e.agentEndCountBySession[u]??0),Se=Jr(e=>u===void 0?!1:e.streamingBySession[u]??!1),Ce=ai(e=>e.loadTree),we=ai(e=>e.restoreTabs),Te=ai(e=>e.refreshOpenFiles);(0,v.useEffect)(()=>{c===void 0||Se||(Ce(c.id),Te(c.id))},[c?.id,Se,be]),(0,v.useEffect)(()=>{c!==void 0&&we(c.id)},[c?.id]),(0,v.useEffect)(()=>{if(!m)return;let e=e=>{e.key===`Escape`&&h(!1)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[m]);let De=(0,v.useRef)(!0);(0,v.useEffect)(()=>{if(De.current){De.current=!1;return}f&&p(!1)},[l,u]),(0,v.useEffect)(()=>{if(!f)return;let e=e=>{e.key===`Escape`&&p(!1)};window.addEventListener(`keydown`,e);let t=document.body.style.overflow;return document.body.style.overflow=`hidden`,()=>{window.removeEventListener(`keydown`,e),document.body.style.overflow=t}},[f]),(0,v.useEffect)(()=>{!d&&f&&p(!1)},[d,f]);let Oe=JA(e=>e.settingsRequest),ke=JA(e=>e.clearSettingsRequest),[Ae,je]=(0,v.useState)(void 0);(0,v.useEffect)(()=>{Oe!==void 0&&(h(!0),Oe.tab!==void 0&&je(Oe.tab),ke())},[Oe,ke]),(0,v.useEffect)(()=>{r()},[r]);let Me=ci(e=>e.load),Ne=ci(e=>e.minimal);(0,v.useEffect)(()=>{Me()},[Me]),(0,v.useEffect)(()=>{t&&!n&&s()},[t,n,s]);let Fe=li(e=>e.load);(0,v.useEffect)(()=>{t&&!n&&Fe()},[t,n,Fe]);let Ie=Cj(e=>e.startPolling),Re=Cj(e=>e.stopPolling);return(0,v.useEffect)(()=>{t&&!n?Ie():Re()},[t,n,Ie,Re]),e?t?n?(0,R.jsx)(hi,{}):(0,R.jsxs)(`div`,{className:`flex h-screen flex-col bg-neutral-950 text-neutral-100`,children:[(0,R.jsxs)(`header`,{className:`flex items-center justify-between border-b border-neutral-800 px-4 py-2`,style:{paddingTop:`max(0.5rem, env(safe-area-inset-top))`},children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,R.jsx)(`button`,{type:`button`,onClick:()=>p(e=>!e),"aria-label":f?`Close project sidebar`:`Open project sidebar`,"aria-expanded":f,className:`-ml-1 inline-flex min-h-11 min-w-11 items-center justify-center rounded-md text-neutral-300 hover:bg-neutral-800 md:hidden`,children:(0,R.jsx)(Pe,{size:20})}),(0,R.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,R.jsx)(`img`,{src:`/icons/icon.svg`,alt:``,className:`h-8 w-8`,"aria-hidden":`true`}),(0,R.jsx)(`span`,{className:`text-sm font-semibold tracking-tight`,children:`pi-forge`})]})]}),(0,R.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,R.jsxs)(`div`,{className:`hidden md:contents`,children:[(0,R.jsxs)(`button`,{onClick:()=>O(!E),className:`flex items-center gap-1 rounded-md border px-2 py-1 text-xs ${E?`border-neutral-500 bg-neutral-800 text-neutral-100`:`border-neutral-700 text-neutral-300 hover:border-neutral-500`}`,title:`Toggle the chat pane`,children:[(0,R.jsx)(Le,{size:13}),`Chat`]}),(0,R.jsxs)(`button`,{onClick:()=>A(!k),className:`flex items-center gap-1 rounded-md border px-2 py-1 text-xs ${k?`border-neutral-500 bg-neutral-800 text-neutral-100`:`border-neutral-700 text-neutral-300 hover:border-neutral-500`}`,title:`Toggle the editor pane (open tabs persist across reloads)`,children:[(0,R.jsx)(xe,{size:13}),`Editor`]}),(0,R.jsxs)(`button`,{onClick:()=>y(!g),className:`flex items-center gap-1 rounded-md border px-2 py-1 text-xs ${g?`border-neutral-500 bg-neutral-800 text-neutral-100`:`border-neutral-700 text-neutral-300 hover:border-neutral-500`}`,title:`Toggle the file browser tree`,children:[(0,R.jsx)(Ee,{size:13}),`Files`]}),!Ne&&(0,R.jsxs)(`button`,{onClick:()=>T(!C),className:`flex items-center gap-1 rounded-md border px-2 py-1 text-xs ${C?`border-neutral-500 bg-neutral-800 text-neutral-100`:`border-neutral-700 text-neutral-300 hover:border-neutral-500`}`,title:`Toggle the integrated terminal`,children:[(0,R.jsx)(Ze,{size:13}),`Terminal`]})]}),(0,R.jsx)(`div`,{className:`hidden md:block`,children:(0,R.jsx)(CN,{})}),(0,R.jsx)(wN,{}),(0,R.jsx)(`button`,{onClick:()=>h(!0),className:`rounded-md border border-neutral-700 px-2 py-1 text-xs text-neutral-300 hover:border-neutral-500`,title:`Settings (providers, agent defaults, MCP, skills)`,children:`Settings`}),(0,R.jsx)(`button`,{onClick:i,className:`rounded-md border border-neutral-700 px-2 py-1 text-xs text-neutral-300 hover:border-neutral-500`,children:`Sign out`})]})]}),(0,R.jsx)(bi,{}),m&&(0,R.jsx)(Mj,{onClose:()=>{h(!1),je(void 0)},...Ae===void 0?{}:{initialTab:Ae}}),(0,R.jsxs)(`div`,{className:`flex flex-1 flex-col overflow-hidden`,children:[(0,R.jsxs)(`div`,{className:`flex flex-1 overflow-hidden`,children:[f&&(0,R.jsx)(`div`,{className:`fixed inset-0 z-30 bg-black/50 md:hidden`,onClick:()=>p(!1),"aria-hidden":!0}),d&&!f&&(0,R.jsx)(`div`,{className:`fixed inset-y-0 left-0 z-20 w-5 md:hidden`,"aria-hidden":!0,onPointerDown:e=>{let t=e.clientX,n=!1,r=e=>{n||e.clientX-t>50&&(p(!0),n=!0,i())},i=()=>{window.removeEventListener(`pointermove`,r),window.removeEventListener(`pointerup`,i),window.removeEventListener(`pointercancel`,i)};window.addEventListener(`pointermove`,r),window.addEventListener(`pointerup`,i),window.addEventListener(`pointercancel`,i)}}),(0,R.jsx)(Ai,{className:`fixed inset-y-0 left-0 z-40 shadow-2xl transition-transform duration-200 ease-out md:static md:inset-auto md:z-auto md:shadow-none md:transition-none `+(f?`max-md:translate-x-0`:`max-md:-translate-x-full`)}),(0,R.jsxs)(`main`,{className:`flex flex-1 overflow-hidden`,children:[E&&(0,R.jsx)(`div`,{className:`flex flex-1 flex-col overflow-hidden`,children:o&&a.length===0?te?(0,R.jsx)(`div`,{className:`flex flex-1 items-center justify-center px-6 text-center`,children:(0,R.jsxs)(`div`,{className:`space-y-3 text-sm text-neutral-400`,children:[(0,R.jsx)(`p`,{children:`No projects yet.`}),(0,R.jsx)(`button`,{onClick:()=>ne(!1),className:`rounded-md bg-neutral-100 px-3 py-1.5 text-sm font-medium text-neutral-900 hover:bg-white`,children:`+ New project`})]})}):(0,R.jsx)(`div`,{className:`flex flex-1 items-center justify-center`,children:(0,R.jsx)(xi,{onClose:()=>ne(!0)})}):u===void 0?c?(0,R.jsx)(`div`,{className:`flex flex-1 items-center justify-center px-6 text-center`,children:(0,R.jsxs)(`div`,{className:`space-y-3 text-sm text-neutral-400`,children:[(0,R.jsx)(`h2`,{className:`text-xl font-semibold text-neutral-100`,children:c.name}),(0,R.jsx)(`p`,{className:`font-mono text-xs`,children:c.path}),(0,R.jsx)(`p`,{children:`Pick a session from the sidebar — or start a new one here.`}),(0,R.jsx)(`button`,{onClick:()=>{Jr.getState().createSession(c.id)},className:`rounded-md bg-neutral-100 px-3 py-1.5 text-sm font-medium text-neutral-900 hover:bg-white`,children:`+ New session`})]})}):(0,R.jsx)(`div`,{className:`flex flex-1 items-center justify-center`,children:(0,R.jsx)(`p`,{className:`text-sm text-neutral-400`,children:`Select a project from the sidebar.`})}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(mA,{sessionId:u}),!Ne&&(0,R.jsx)(yj,{sessionId:u,alreadyOnChangesTab:g&&b===`changes`,onOpen:()=>{g||y(!0),S(`changes`)}}),(0,R.jsx)(hM,{sessionId:u}),(0,R.jsx)(mj,{sessionId:u})]})}),!d&&_e&&(E?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(gP,{getStartSize:()=>he.current,onResize:e=>pe(e),direction:-1,minSize:EP,maxSize:Math.max(EP,window.innerWidth-(g?ue:0)-DP-240)}),(0,R.jsx)(`div`,{className:`flex shrink-0 flex-col border-l border-neutral-800`,style:{width:`${fe}px`},children:(0,R.jsx)(JM,{})})]}):(0,R.jsx)(`div`,{className:`flex flex-1 flex-col overflow-hidden`,children:(0,R.jsx)(JM,{})})),!d&&g&&(()=>{let e=!E&&!_e,t=(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`div`,{className:`flex border-b border-neutral-800 bg-neutral-900/40`,children:(Ne?[`files`,`search`,`processes`,`context`]:[`files`,`search`,`changes`,`git`,`processes`,`context`]).map(e=>(0,R.jsxs)(`button`,{onClick:()=>S(e),className:`flex items-center gap-1 px-3 py-1.5 text-[11px] uppercase tracking-wider ${b===e?`border-b border-neutral-100 text-neutral-100`:`text-neutral-500 hover:text-neutral-300`}`,children:[e===`files`?`Files`:e===`search`?`Search`:e===`changes`?`Last turn`:e===`git`?`Git`:e===`processes`?`Processes`:`Context`,e===`git`&&ve>0&&(0,R.jsx)(`span`,{className:`rounded bg-amber-900/40 px-1 py-0.5 text-[9px] text-amber-300 light:bg-amber-100 light:text-amber-800`,children:ve}),e===`processes`&&ye>0&&(0,R.jsx)(`span`,{className:`rounded bg-emerald-900/40 px-1 py-0.5 text-[9px] text-emerald-300 light:bg-emerald-100 light:text-emerald-800`,children:ye})]},e))}),(0,R.jsxs)(`div`,{className:`flex flex-1 flex-col overflow-hidden`,children:[(0,R.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:b===`files`?(0,R.jsx)(MM,{}):b===`search`?(0,R.jsx)(GN,{}):!Ne&&b===`changes`?(0,R.jsx)(DN,{}):!Ne&&b===`git`?(0,R.jsx)(NN,{}):b===`context`?(0,R.jsx)($N,{}):b===`processes`&&u!==void 0?(0,R.jsx)(CM,{sessionId:u}):(0,R.jsx)(MM,{})}),se&&u!==void 0&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(gP,{orientation:`horizontal`,getStartSize:()=>oe.current,onResize:e=>M(e),direction:-1,minSize:kP,maxSize:Math.max(kP,window.innerHeight*.7)}),(0,R.jsx)(`div`,{className:`shrink-0 overflow-hidden border-t border-neutral-800 light:border-neutral-200`,style:{height:`${ae}px`},children:(0,R.jsx)(vM,{sessionId:u,onClose:()=>JA.getState().setTodoPanelOpen(!1)})})]})]})]});return e?(0,R.jsx)(`div`,{className:`flex flex-1 flex-col overflow-hidden`,children:t}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(gP,{getStartSize:()=>me.current,onResize:e=>de(e),direction:-1,minSize:TP,maxSize:Math.max(TP,window.innerWidth-DP-240-(_e?EP:0))}),(0,R.jsx)(`div`,{className:`flex shrink-0 flex-col border-l border-neutral-800`,style:{width:`${ue}px`},children:t})]})})()]})]}),!d&&!Ne&&C&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(gP,{orientation:`horizontal`,getStartSize:()=>j.current,onResize:e=>ie(e),direction:-1,minSize:OP,maxSize:Math.max(OP,Math.floor(window.innerHeight*.7))}),(0,R.jsx)(`div`,{className:`shrink-0 border-t border-neutral-800`,style:{height:`${re}px`},children:(0,R.jsx)(yN,{})})]})]})]}):(0,R.jsx)(pi,{}):(0,R.jsx)(`main`,{className:`flex min-h-screen items-center justify-center text-sm text-neutral-400`,children:`Loading…`})}eC(),O({immediate:!0});var MP=class extends v.Component{state={error:null};static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e,t){console.error(`[pi-forge] root render error`,e,t)}render(){return this.state.error===null?this.props.children:(0,R.jsxs)(`main`,{style:{padding:`2rem`,fontFamily:`monospace`,color:`#fca5a5`,background:`#0a0a0a`,minHeight:`100vh`,whiteSpace:`pre-wrap`,overflow:`auto`},children:[(0,R.jsx)(`h1`,{style:{color:`#fff`,marginBottom:`1rem`},children:`pi-forge: render crash`}),(0,R.jsx)(`p`,{style:{color:`#d4d4d4`,marginBottom:`1rem`},children:this.state.error.message}),(0,R.jsx)(`pre`,{style:{fontSize:`11px`,color:`#a3a3a3`},children:this.state.error.stack??`(no stack)`}),(0,R.jsx)(`p`,{style:{marginTop:`2rem`,color:`#71717a`,fontSize:`12px`},children:`Tip: open the browser console for more detail. Try clearing localStorage (devtools → Application → Local Storage → Clear) and refreshing if the error mentions stale state.`})]})}};window.addEventListener(`error`,e=>{console.error(`[pi-forge] uncaught error`,e.error)}),window.addEventListener(`unhandledrejection`,e=>{console.error(`[pi-forge] unhandled rejection`,e.reason)});var NP=document.getElementById(`root`);if(!NP)throw Error(`#root element missing in index.html`);(0,y.createRoot)(NP).render((0,R.jsx)(v.StrictMode,{children:(0,R.jsx)(MP,{children:(0,R.jsx)(jP,{})})}));export{l as a,d as i,tC as n,fi as r,nC as t};
|
|
375
|
-
//# sourceMappingURL=index-
|
|
374
|
+
`).pop()??`Pushed`:`Pushed`),Ce&&we(!1)}catch(e){l((e instanceof N,e.message))}finally{s(!1)}};return(0,R.jsxs)(`div`,{className:`flex h-full flex-col text-xs text-neutral-300`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between border-b border-neutral-800 px-3 py-2`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2 font-medium text-neutral-200`,children:[(0,R.jsx)(De,{size:13}),t?.branch??`—`,t!==void 0&&t.files.length>0&&(0,R.jsx)(`span`,{className:`rounded bg-neutral-800 px-1.5 py-0.5 text-[10px] text-neutral-400`,children:t.files.length})]}),(0,R.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,R.jsx)(`button`,{onClick:()=>je(ke===`split`?`unified`:`split`),className:`rounded p-1 text-neutral-400 hover:bg-neutral-800 hover:text-neutral-200`,title:ke===`split`?`Switch git diffs to unified view`:`Switch git diffs to side-by-side view`,children:ke===`split`?(0,R.jsx)(Ge,{size:13}):(0,R.jsx)(_e,{size:13})}),(0,R.jsx)(`button`,{onClick:()=>void r(),className:`rounded p-1 text-neutral-400 hover:bg-neutral-800 hover:text-neutral-200`,title:`Refresh`,children:(0,R.jsx)(Ue,{size:13,className:o?`animate-spin`:``})})]})]}),(n!==void 0||c!==void 0)&&(0,R.jsx)(`div`,{className:`border-b border-red-700/40 bg-red-900/20 px-3 py-1.5 text-[11px] text-red-300 light:border-red-300 light:bg-red-50 light:text-red-700`,children:c??n}),u!==void 0&&(0,R.jsx)(`div`,{className:`border-b border-emerald-700/40 bg-emerald-900/20 px-3 py-1.5 text-[11px] text-emerald-300 light:border-emerald-300 light:bg-emerald-50 light:text-emerald-800`,children:u}),(0,R.jsxs)(`div`,{className:`flex-1 overflow-y-auto`,children:[t===void 0&&(0,R.jsx)(`p`,{className:`px-3 py-3 italic text-neutral-500`,children:`Loading…`}),t?.files.length===0&&(0,R.jsx)(`p`,{className:`px-3 py-3 italic text-neutral-500`,children:`Working tree clean.`}),Me.length>0&&(0,R.jsx)(zN,{label:`Staged`,files:Me,actionLabel:`Unstage all`,onGroupAction:()=>void Re(Me.map(e=>e.path)),onFileAction:e=>void Re([e.path]),fileActionLabel:`Unstage`,onRevert:e=>void Le([e.path]),onClickFile:e=>void Fe(e,!0),openDiffs:me,staged:!0,diffViewType:ke,onHunkAction:(e,t)=>void ze(e,t,`unstage`),pendingHunkPath:ge}),Ne.length>0&&(0,R.jsx)(zN,{label:`Unstaged`,files:Ne,actionLabel:`Stage all`,onGroupAction:()=>void Ie(Ne.map(e=>e.path)),onFileAction:e=>void Ie([e.path]),fileActionLabel:`Stage`,onRevert:e=>void Le([e.path]),onClickFile:e=>void Fe(e,!1),openDiffs:me,staged:!1,diffViewType:ke,onHunkAction:(e,t)=>void ze(e,t,`stage`),pendingHunkPath:ge}),Pe.length>0&&(0,R.jsx)(zN,{label:`Untracked`,files:Pe,actionLabel:`Stage all`,onGroupAction:()=>void Ie(Pe.map(e=>e.path)),onFileAction:e=>void Ie([e.path]),fileActionLabel:`Stage`,onRevert:void 0,onClickFile:e=>void Fe(e,!1),openDiffs:me,staged:!1,diffViewType:ke}),(0,R.jsxs)(`div`,{className:`border-t border-neutral-800/60 px-3 py-3`,children:[(0,R.jsxs)(`div`,{className:`mb-1 flex items-center gap-1 text-[10px] uppercase tracking-wider text-neutral-500`,children:[(0,R.jsx)(Oe,{size:10}),` Commit`]}),(0,R.jsx)(`textarea`,{value:i,onChange:e=>a(e.target.value),placeholder:`Commit message…`,rows:3,className:`w-full resize-none rounded border border-neutral-700 bg-neutral-950 px-2 py-1 text-xs text-neutral-100 outline-none focus:border-neutral-500`}),(0,R.jsxs)(`div`,{className:`mt-1 flex items-center justify-between gap-2`,children:[(0,R.jsxs)(`span`,{className:`text-[10px] text-neutral-500`,children:[Me.length,` staged`]}),(0,R.jsx)(`button`,{onClick:()=>void Ve(),disabled:o||Me.length===0||i.trim().length===0,className:`rounded bg-neutral-100 px-3 py-1 text-xs font-medium text-neutral-900 disabled:cursor-not-allowed disabled:opacity-50`,children:`Commit`})]})]}),(0,R.jsxs)(`div`,{className:`border-t border-neutral-800/60 px-3 py-3`,children:[(0,R.jsxs)(`div`,{className:`mb-1 flex items-center justify-between gap-1 text-[10px] uppercase tracking-wider text-neutral-500`,children:[(0,R.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,R.jsx)(nt,{size:10}),` Push`]}),(0,R.jsx)(`button`,{onClick:()=>{Ee(e=>!e),!Te&&m===void 0&&L.gitBranches(e.id).then(e=>h(e.branches)).catch(()=>void 0),!Te&&g===void 0&&L.gitRemotes(e.id).then(e=>_(e.remotes)).catch(()=>void 0)},className:`rounded px-1 py-0.5 text-[10px] normal-case text-neutral-400 hover:bg-neutral-900 hover:text-neutral-200`,children:Te?`Hide options`:`Options`})]}),Te&&(0,R.jsxs)(`div`,{className:`mb-2 space-y-1.5 rounded border border-neutral-800 bg-neutral-900/40 p-2`,children:[(0,R.jsxs)(`label`,{className:`flex items-center gap-2 text-[11px]`,children:[(0,R.jsx)(`span`,{className:`w-16 shrink-0 text-neutral-400`,children:`Remote`}),We.length>0?(0,R.jsxs)(`select`,{value:ye??``,onChange:e=>be(e.target.value===``?void 0:e.target.value),className:`flex-1 rounded border border-neutral-700 bg-neutral-950 px-1 py-0.5 text-[11px] text-neutral-100 outline-none focus:border-neutral-500`,children:[(0,R.jsx)(`option`,{value:``,children:`configured upstream`}),We.map(e=>(0,R.jsx)(`option`,{value:e,children:e},e))]}):(0,R.jsx)(`input`,{type:`text`,value:ye??``,onChange:e=>be(e.target.value.length===0?void 0:e.target.value),placeholder:`origin`,className:`flex-1 rounded border border-neutral-700 bg-neutral-950 px-1 py-0.5 text-[11px] text-neutral-100 outline-none focus:border-neutral-500`})]}),(0,R.jsxs)(`label`,{className:`flex items-center gap-2 text-[11px]`,children:[(0,R.jsx)(`span`,{className:`w-16 shrink-0 text-neutral-400`,children:`Branch`}),Ke.length>0?(0,R.jsxs)(`select`,{value:xe,onChange:e=>Se(e.target.value),className:`flex-1 rounded border border-neutral-700 bg-neutral-950 px-1 py-0.5 text-[11px] text-neutral-100 outline-none focus:border-neutral-500`,children:[(0,R.jsx)(`option`,{value:``,children:t?.branch??`current branch`}),Ke.map(e=>(0,R.jsx)(`option`,{value:e,children:e},e))]}):(0,R.jsx)(`input`,{type:`text`,value:xe,onChange:e=>Se(e.target.value),placeholder:t?.branch??`current`,className:`flex-1 rounded border border-neutral-700 bg-neutral-950 px-1 py-0.5 text-[11px] text-neutral-100 outline-none focus:border-neutral-500`})]}),(0,R.jsxs)(`label`,{className:`flex items-center gap-2 text-[11px] text-neutral-300`,children:[(0,R.jsx)(`input`,{type:`checkbox`,checked:Ce,onChange:e=>we(e.target.checked),className:`h-3 w-3`}),(0,R.jsx)(`span`,{children:`Set upstream (first push of a new branch)`})]})]}),(0,R.jsxs)(`div`,{className:`flex gap-1`,children:[(0,R.jsx)(`button`,{onClick:()=>void qe(),disabled:o,className:`flex-1 rounded border border-neutral-700 px-3 py-1 text-xs text-neutral-200 hover:border-neutral-500 disabled:opacity-50`,title:ye===void 0?`git fetch (configured upstream)`:`git fetch ${ye}`,children:`Fetch`}),(0,R.jsx)(`button`,{onClick:()=>void Je(),disabled:o,className:`flex-1 rounded border border-neutral-700 px-3 py-1 text-xs text-neutral-200 hover:border-neutral-500 disabled:opacity-50`,title:`git pull — conflicts surface in the error banner; resolve via the integrated terminal`,children:`Pull`}),(0,R.jsx)(`button`,{onClick:()=>void Ye(),disabled:o,className:`flex-1 rounded border border-neutral-700 px-3 py-1 text-xs text-neutral-200 hover:border-neutral-500 disabled:opacity-50`,title:ye===void 0&&xe.trim().length===0?`git push (configured upstream)`:`git push ${ye??`(upstream)`}${xe.trim().length>0?` ${xe.trim()}`:``}`,children:`Push`})]})]}),(0,R.jsxs)(`div`,{className:`border-t border-neutral-800/60`,children:[(0,R.jsxs)(`button`,{onClick:()=>b(e=>!e),className:`flex w-full items-center justify-between px-3 py-2 text-left text-[10px] uppercase tracking-wider text-neutral-400 hover:bg-neutral-900`,children:[(0,R.jsx)(`span`,{children:`Log`}),(0,R.jsx)(`span`,{children:y?`−`:`+`})]}),y&&(0,R.jsx)(`div`,{className:`px-3 pb-3 text-[11px]`,children:f===void 0?(0,R.jsx)(`p`,{className:`italic text-neutral-500`,children:`Loading…`}):f.length===0?(0,R.jsx)(`p`,{className:`italic text-neutral-500`,children:`No commits yet.`}):(0,R.jsx)(UN,{commits:f})})]}),(0,R.jsxs)(`div`,{className:`border-t border-neutral-800/60`,children:[(0,R.jsxs)(`button`,{onClick:()=>S(e=>!e),className:`flex w-full items-center justify-between px-3 py-2 text-left text-[10px] uppercase tracking-wider text-neutral-400 hover:bg-neutral-900`,children:[(0,R.jsx)(`span`,{children:`Branches`}),(0,R.jsx)(`span`,{children:x?`−`:`+`})]}),x&&(0,R.jsx)(`div`,{className:`px-3 pb-3 text-[11px]`,children:m===void 0?(0,R.jsx)(`p`,{className:`italic text-neutral-500`,children:`Loading…`}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`ul`,{className:`space-y-0.5`,children:m.map(e=>{let t=T===e.name;return(0,R.jsxs)(`li`,{className:`group flex items-center gap-1 rounded px-1 py-0.5 font-mono hover:bg-neutral-900 ${e.current?`text-emerald-400 light:text-emerald-700`:`text-neutral-300`}`,children:[(0,R.jsx)(`span`,{className:`w-3 shrink-0`,children:e.current?(0,R.jsx)(le,{size:10}):null}),(0,R.jsx)(`span`,{className:`flex-1 truncate`,title:e.name,children:e.name}),e.remote&&(0,R.jsx)(`span`,{className:`ml-1 text-[10px] text-neutral-600`,children:`remote`}),!e.current&&(0,R.jsxs)(`div`,{className:`hidden gap-0.5 group-hover:flex`,children:[(0,R.jsx)(`button`,{onClick:()=>void de(e.name),disabled:t,className:`rounded px-1 py-0.5 text-[10px] text-neutral-400 hover:bg-neutral-800 hover:text-neutral-100 disabled:opacity-40`,title:e.remote?`Checkout (creates a tracking branch from ${e.name})`:`Checkout ${e.name}`,children:`checkout`}),!e.remote&&(0,R.jsx)(`button`,{onClick:()=>O({kind:`delete`,name:e.name}),disabled:t,className:`rounded p-0.5 text-neutral-500 hover:bg-red-900/30 hover:text-red-300 disabled:opacity-40 light:hover:bg-red-100 light:hover:text-red-700`,title:`Delete branch`,children:(0,R.jsx)($e,{size:10})})]})]},e.name)})}),(0,R.jsxs)(`button`,{onClick:()=>O({kind:`create`}),className:`mt-2 flex items-center gap-1 rounded px-1 py-0.5 text-[11px] text-neutral-400 hover:bg-neutral-900 hover:text-neutral-100`,children:[(0,R.jsx)(He,{size:10}),` New branch`]})]})})]}),(0,R.jsxs)(`div`,{className:`border-t border-neutral-800/60`,children:[(0,R.jsxs)(`button`,{onClick:()=>w(e=>!e),className:`flex w-full items-center justify-between px-3 py-2 text-left text-[10px] uppercase tracking-wider text-neutral-400 hover:bg-neutral-900`,children:[(0,R.jsx)(`span`,{children:`Remotes`}),(0,R.jsx)(`span`,{children:C?`−`:`+`})]}),C&&(0,R.jsx)(`div`,{className:`px-3 pb-3 text-[11px]`,children:g===void 0?(0,R.jsx)(`p`,{className:`italic text-neutral-500`,children:`Loading…`}):(0,R.jsxs)(R.Fragment,{children:[g.length===0?(0,R.jsx)(`p`,{className:`italic text-neutral-500`,children:`No remotes configured.`}):(0,R.jsx)(`ul`,{className:`space-y-1`,children:g.map(e=>{let t=e.fetchUrl!==e.pushUrl,n=k===e.name;return(0,R.jsxs)(`li`,{className:`group flex flex-col gap-0.5`,children:[(0,R.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,R.jsx)(`span`,{className:`font-mono text-neutral-200`,children:e.name}),t&&(0,R.jsx)(`span`,{className:`rounded bg-amber-900/30 px-1 py-0.5 text-[9px] uppercase tracking-wider text-amber-300 light:bg-amber-100 light:text-amber-800`,children:`fetch ≠ push`}),(0,R.jsx)(`button`,{onClick:()=>M(e.name),disabled:n,className:`ml-auto hidden rounded p-0.5 text-neutral-500 hover:bg-red-900/30 hover:text-red-300 disabled:opacity-40 group-hover:inline-flex light:hover:bg-red-100 light:hover:text-red-700`,title:`Remove remote "${e.name}"`,children:(0,R.jsx)($e,{size:10})})]}),(0,R.jsx)(`span`,{className:`break-all font-mono text-[10px] text-neutral-500`,title:e.fetchUrl,children:e.fetchUrl}),t&&(0,R.jsxs)(`span`,{className:`break-all font-mono text-[10px] text-neutral-500`,title:`push → ${e.pushUrl}`,children:[`push → `,e.pushUrl]})]},e.name)})}),(0,R.jsxs)(`button`,{onClick:()=>{re(``),j(``),te(!0)},className:`mt-2 flex items-center gap-1 rounded px-1 py-0.5 text-[11px] text-neutral-400 hover:bg-neutral-900 hover:text-neutral-100`,children:[(0,R.jsx)(He,{size:10}),` Add remote`]})]})})]})]}),(0,R.jsx)(Ti,{open:D?.kind===`create`,onClose:()=>O(void 0),onSubmit:e=>void fe(e),title:`New branch`,label:`Branch name`,placeholder:`feature/my-change`,primaryLabel:`Create + checkout`}),(0,R.jsx)(Ei,{open:D?.kind===`delete`,onClose:()=>O(void 0),onConfirm:()=>void pe(!1),title:`Delete branch`,message:D?.kind===`delete`?`Delete branch "${D.name}"? Refused if not merged into HEAD; force-delete from the terminal if you really mean it.`:``,primaryLabel:`Delete`,tone:`danger`}),(0,R.jsx)(wi,{open:A,onClose:()=>te(!1),title:`Add remote`,children:(0,R.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),se()},className:`flex flex-col gap-3 px-4 py-3`,children:[(0,R.jsxs)(`label`,{className:`block space-y-1.5`,children:[(0,R.jsx)(`span`,{className:`text-xs text-neutral-300`,children:`Name`}),(0,R.jsx)(`input`,{type:`text`,value:ne,onChange:e=>re(e.target.value),placeholder:`origin`,autoFocus:!0,className:`w-full rounded-md border border-neutral-700 bg-neutral-950 px-3 py-1.5 font-mono text-sm text-neutral-100 outline-none focus:border-neutral-500`})]}),(0,R.jsxs)(`label`,{className:`block space-y-1.5`,children:[(0,R.jsx)(`span`,{className:`text-xs text-neutral-300`,children:`URL`}),(0,R.jsx)(`input`,{type:`text`,value:ie,onChange:e=>j(e.target.value),placeholder:`git@github.com:user/repo.git`,className:`w-full rounded-md border border-neutral-700 bg-neutral-950 px-3 py-1.5 font-mono text-sm text-neutral-100 outline-none focus:border-neutral-500`})]}),(0,R.jsxs)(`footer`,{className:`flex justify-end gap-2 pt-1`,children:[(0,R.jsx)(`button`,{type:`button`,onClick:()=>te(!1),className:`rounded-md border border-neutral-700 px-3 py-1 text-xs text-neutral-200 hover:bg-neutral-800`,children:`Cancel`}),(0,R.jsx)(`button`,{type:`submit`,disabled:ne.trim().length===0||ie.trim().length===0,className:`rounded-md bg-neutral-100 px-3 py-1 text-xs font-medium text-neutral-900 hover:bg-white disabled:cursor-not-allowed disabled:opacity-40`,children:`Add`})]})]})}),(0,R.jsx)(Ei,{open:ae!==void 0,onClose:()=>M(void 0),onConfirm:()=>void ce(),title:`Remove remote`,message:ae===void 0?``:`Remove remote "${ae}"? The local repo loses its reference to this URL; existing commits aren't affected.`,primaryLabel:`Remove`,tone:`danger`})]})}var RN=3e3;function zN(e){let[t,n]=(0,v.useState)(void 0),r=(0,v.useRef)(void 0),i=()=>{r.current!==void 0&&(window.clearTimeout(r.current),r.current=void 0),n(void 0)};(0,v.useEffect)(()=>()=>{r.current!==void 0&&window.clearTimeout(r.current)},[]);let a=a=>{if(e.onRevert!==void 0){if(t===a.path){i(),e.onRevert(a);return}r.current!==void 0&&window.clearTimeout(r.current),n(a.path),r.current=window.setTimeout(()=>{n(void 0),r.current=void 0},RN)}};return(0,R.jsxs)(`div`,{className:`border-t border-neutral-800/60`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-1.5`,children:[(0,R.jsxs)(`span`,{className:`text-[10px] uppercase tracking-wider text-neutral-500`,children:[e.label,` (`,e.files.length,`)`]}),(0,R.jsx)(`button`,{onClick:e.onGroupAction,className:`text-[10px] text-neutral-400 hover:text-neutral-200`,children:e.actionLabel})]}),(0,R.jsx)(`ul`,{children:e.files.map(n=>{let r=`${n.path}|${e.staged?`staged`:`unstaged`}`,i=e.openDiffs[r],o=t===n.path;return(0,R.jsxs)(`li`,{className:`border-t border-neutral-900`,children:[(0,R.jsxs)(`div`,{className:`group flex items-center gap-2 px-3 py-1 hover:bg-neutral-900`,children:[(0,R.jsx)(`span`,{className:`inline-block w-5 shrink-0 text-center font-mono text-[10px] text-neutral-500`,title:`porcelain code: ${n.code}`,children:BN(n.kind)}),(0,R.jsx)(`button`,{onClick:()=>e.onClickFile(n),className:`flex-1 truncate text-left font-mono`,title:n.path,children:n.path}),e.onRevert!==void 0&&(0,R.jsxs)(`button`,{onClick:()=>a(n),className:o?`inline-flex items-center gap-1 rounded bg-red-900/40 px-1 py-0.5 text-[10px] text-red-200 light:bg-red-100 light:text-red-800`:`hidden items-center gap-1 text-[10px] text-neutral-500 hover:text-red-300 group-hover:inline-flex light:hover:text-red-700`,title:o?`Click again to discard local changes (this cannot be undone)`:`Revert: discard local changes for this file`,children:[(0,R.jsx)(tt,{size:10}),o?`Confirm?`:`Revert`]}),(0,R.jsxs)(`button`,{onClick:()=>e.onFileAction(n),className:`ml-3 hidden items-center gap-1 text-[10px] text-neutral-500 hover:text-neutral-200 group-hover:inline-flex`,children:[e.fileActionLabel===`Stage`?(0,R.jsx)(He,{size:10}):e.fileActionLabel===`Unstage`?(0,R.jsx)(Re,{size:10}):null,e.fileActionLabel]})]}),i!==void 0&&(0,R.jsx)(`div`,{className:`border-t border-neutral-900 bg-neutral-950`,children:i===`loading`?(0,R.jsx)(`p`,{className:`px-3 py-2 italic text-neutral-500`,children:`Loading…`}):i===`error`?(0,R.jsx)(`p`,{className:`px-3 py-2 text-red-400 light:text-red-700`,children:`Failed to load diff.`}):i.length===0?(0,R.jsx)(`p`,{className:`px-3 py-2 italic text-neutral-500`,children:`(no diff — file is binary or unchanged)`}):(0,R.jsx)(mk,{diff:i,viewType:e.diffViewType,onHunkAction:e.onHunkAction===void 0?void 0:t=>e.onHunkAction?.(n,t),hunkActionLabel:e.staged?`Unstage hunk`:`Stage hunk`,hunkActionDisabled:e.pendingHunkPath===n.path})})]},n.path)})})]})}function BN(e){switch(e){case`modified`:return`M`;case`added`:return`A`;case`deleted`:return`D`;case`renamed`:return`R`;case`copied`:return`C`;case`untracked`:return`?`;case`ignored`:return`!`;case`conflicted`:return`U`;default:return`·`}}var VN=14,HN=36;function UN({commits:e}){let t=PN(e),n=Math.max(1,...t.map(e=>e.width));return(0,R.jsx)(`ul`,{className:`space-y-0`,children:e.map((e,r)=>{let i=t[r];return i===void 0?null:(0,R.jsxs)(`li`,{className:`group flex items-stretch`,children:[(0,R.jsx)(WN,{layout:i,isLast:r===t.length-1,maxLanes:n}),(0,R.jsxs)(`div`,{className:`flex flex-col justify-center gap-0.5 pl-2`,style:{minHeight:HN},children:[(0,R.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,R.jsx)(`span`,{className:`font-mono text-neutral-500`,children:e.hash.slice(0,7)}),e.refs.map((e,t)=>(0,R.jsx)(GN,{ref_:e},`${t}-${e}`)),(0,R.jsx)(`span`,{className:`truncate text-neutral-200`,title:e.message,children:e.message})]}),(0,R.jsxs)(`span`,{className:`font-mono text-[10px] text-neutral-600`,children:[e.author,` · `,new Date(e.date).toLocaleString()]})]})]},e.hash)})})}function WN({layout:e,isLast:t,maxLanes:n}){let r=n*VN,i=HN,a=e.lane*VN+VN/2,o=i/2,s=[];for(let t of e.through){let e=t*VN+VN/2;s.push({x1:e,y1:0,x2:e,y2:i,color:IN(t)})}for(let t of e.incomingLanes){let e=t*VN+VN/2;s.push({x1:e,y1:0,x2:a,y2:o,color:IN(t)})}if(!t)for(let t of e.outgoingLanes){let e=t.lane*VN+VN/2;s.push({x1:a,y1:o,x2:e,y2:i,color:IN(t.lane)})}if(t&&e.outgoingLanes.length>0)for(let t of e.outgoingLanes){let e=t.lane*VN+VN/2;s.push({x1:a,y1:o,x2:e,y2:24,color:IN(t.lane)})}return(0,R.jsxs)(`svg`,{width:r,height:i,viewBox:`0 0 ${r} ${i}`,className:`shrink-0`,"aria-hidden":!0,children:[s.map((e,t)=>(0,R.jsx)(`line`,{x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2,stroke:e.color,strokeWidth:1.5,strokeLinecap:`round`},t)),(0,R.jsx)(`circle`,{cx:a,cy:o,r:3.5,fill:IN(e.lane)})]})}function GN({ref_:e}){let t=e.startsWith(`HEAD ->`)||e===`HEAD`,n=e.startsWith(`tag:`),r=t?e.replace(/^HEAD ->\s*/,``):n?e.replace(/^tag:\s*/,``):e;return(0,R.jsx)(`span`,{className:`shrink-0 rounded px-1.5 py-0 text-[9px] uppercase tracking-wider ${t?`bg-emerald-900/40 text-emerald-300 light:bg-emerald-100 light:text-emerald-800`:n?`bg-amber-900/40 text-amber-300 light:bg-amber-100 light:text-amber-800`:e.includes(`/`)?`bg-neutral-800 text-neutral-500`:`bg-neutral-800 text-neutral-300`}`,children:n?`▼ ${r}`:r})}var KN=250,qN=2,JN=200;function YN(){let e=dr(),t=ai(e=>e.openFile),n=QA(e=>e.openEditorPane),[r,i]=(0,v.useState)(``),[a,o]=(0,v.useState)(!1),[s,c]=(0,v.useState)(!1),[l,u]=(0,v.useState)(!1),[d,f]=(0,v.useState)(``),[p,m]=(0,v.useState)(``),[h,g]=(0,v.useState)(!1),[_,y]=(0,v.useState)(void 0),[b,x]=(0,v.useState)(!1),[S,C]=(0,v.useState)(void 0),w=(0,v.useRef)(void 0),T=(0,v.useCallback)(async t=>{if(e===void 0)return;if(t.length<qN){y(void 0),C(void 0);return}w.current?.abort();let n=new AbortController;w.current=n,x(!0),C(void 0);try{let r={query:t,regex:a,caseSensitive:s,includeGitignored:l,limit:JN,...d.length>0?{include:d}:{},...p.length>0?{exclude:p}:{}},i=await L.searchFiles(e.id,r,n.signal);if(n.signal.aborted)return;y(i)}catch(e){if(n.signal.aborted||e instanceof Error&&e.name===`AbortError`)return;e instanceof N&&e.code===`invalid_response_body`?C(`server returned an unexpected response`):e instanceof Error?C(e.message):C(`search failed`),y(void 0)}finally{n.signal.aborted||x(!1)}},[e,a,s,l,d,p]);(0,v.useEffect)(()=>{let e=window.setTimeout(()=>void T(r),KN);return()=>window.clearTimeout(e)},[r,T]),(0,v.useEffect)(()=>()=>{w.current?.abort()},[]);let E=(0,v.useMemo)(()=>ZN(_?.matches??[]),[_]);return e===void 0?(0,R.jsx)(`div`,{className:`p-4 text-xs italic text-neutral-500`,children:`Select a project to search its files.`}):(0,R.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,R.jsxs)(`div`,{className:`border-b border-neutral-800 bg-neutral-900/40 p-2`,children:[(0,R.jsxs)(`div`,{className:`relative`,children:[(0,R.jsx)(qe,{size:12,className:`pointer-events-none absolute left-2 top-1/2 -translate-y-1/2 text-neutral-500`}),(0,R.jsx)(`input`,{type:`text`,value:r,onChange:e=>i(e.target.value),placeholder:a?`Regex…`:`Search project…`,className:`w-full rounded border border-neutral-700 bg-neutral-900 py-1.5 pl-7 pr-2 text-xs text-neutral-100 placeholder:text-neutral-500 focus:border-neutral-500 focus:outline-none`,autoFocus:!0})]}),(0,R.jsxs)(`div`,{className:`mt-2 flex flex-wrap gap-1`,children:[(0,R.jsx)(QN,{label:`Regex`,active:a,onClick:()=>o(e=>!e)}),(0,R.jsx)(QN,{label:`Aa`,title:`Case sensitive`,active:s,onClick:()=>c(e=>!e)}),(0,R.jsx)(QN,{label:`+ignored`,title:`Include files that .gitignore would normally skip`,active:l,onClick:()=>u(e=>!e)}),(0,R.jsxs)(`button`,{onClick:()=>g(e=>!e),className:`ml-auto flex items-center gap-1 rounded border border-neutral-700 px-1.5 py-0.5 text-[10px] text-neutral-400 hover:border-neutral-500`,children:[h?(0,R.jsx)(ue,{size:10}):(0,R.jsx)(fe,{size:10}),`Globs`]})]}),h&&(0,R.jsxs)(`div`,{className:`mt-2 grid grid-cols-1 gap-1.5`,children:[(0,R.jsx)(`input`,{type:`text`,value:d,onChange:e=>f(e.target.value),placeholder:`include glob — e.g. **/*.ts`,className:`rounded border border-neutral-700 bg-neutral-900 px-2 py-1 text-[11px] text-neutral-200 placeholder:text-neutral-500 focus:border-neutral-500 focus:outline-none`}),(0,R.jsx)(`input`,{type:`text`,value:p,onChange:e=>m(e.target.value),placeholder:`exclude glob — e.g. **/dist/**`,className:`rounded border border-neutral-700 bg-neutral-900 px-2 py-1 text-[11px] text-neutral-200 placeholder:text-neutral-500 focus:border-neutral-500 focus:outline-none`})]})]}),(0,R.jsxs)(`div`,{className:`flex-1 overflow-auto`,children:[(0,R.jsx)($N,{query:r,loading:b,error:S,results:_,totalFiles:E.length}),(0,R.jsx)(`ul`,{className:`divide-y divide-neutral-900`,children:E.map(([r,i])=>(0,R.jsx)(eP,{path:r,matches:i,onPick:i=>{t(e.id,XN(e.path,r),{line:i.line,column:i.column}),n()}},r))})]})]})}function XN(e,t){return t.startsWith(`/`)?t:`${e}${e.endsWith(`/`)?``:`/`}${t}`}function ZN(e){let t=new Map;for(let n of e){let e=t.get(n.path);e===void 0?t.set(n.path,[n]):e.push(n)}return Array.from(t.entries())}function QN({label:e,title:t,active:n,onClick:r}){return(0,R.jsx)(`button`,{onClick:r,title:t,className:`rounded border px-1.5 py-0.5 text-[10px] ${n?`border-neutral-500 bg-neutral-800 text-neutral-100`:`border-neutral-700 text-neutral-400 hover:border-neutral-500`}`,children:e})}function $N({query:e,loading:t,error:n,results:r,totalFiles:i}){return e.length===0?(0,R.jsxs)(`div`,{className:`flex flex-col items-center gap-2 px-4 py-8 text-center text-xs text-neutral-500`,children:[(0,R.jsx)(we,{size:20,className:`text-neutral-700`}),(0,R.jsx)(`p`,{children:`Type to search across project files.`}),(0,R.jsxs)(`p`,{className:`text-[10px] text-neutral-600`,children:[`Min `,qN,` chars · Click a result to jump to that line.`]})]}):e.length<qN?(0,R.jsxs)(`div`,{className:`px-4 py-3 text-xs italic text-neutral-500`,children:[`Keep typing — at least `,qN,` characters.`]}):t&&r===void 0?(0,R.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-3 text-xs text-neutral-400`,children:[(0,R.jsx)(Ne,{size:12,className:`animate-spin`}),` Searching…`]}):n===void 0?r===void 0?null:r.matches.length===0?(0,R.jsx)(`div`,{className:`px-4 py-3 text-xs italic text-neutral-500`,children:`No matches.`}):(0,R.jsxs)(`div`,{className:`flex items-center justify-between gap-2 border-b border-neutral-800 bg-neutral-950/60 px-3 py-1.5 text-[10px]`,children:[(0,R.jsxs)(`span`,{className:`text-neutral-400`,children:[r.matches.length,` match`,r.matches.length===1?``:`es`,` in `,i,` `,`file`,i===1?``:`s`,r.truncated&&(0,R.jsxs)(`span`,{className:`ml-1 text-amber-400 light:text-amber-700`,children:[`· truncated at `,JN]})]}),r.engine===`node`&&(0,R.jsx)(`span`,{className:`rounded bg-amber-900/40 px-1.5 py-0.5 text-[9px] uppercase tracking-wider text-amber-300 light:bg-amber-100 light:text-amber-800`,title:`ripgrep was not found on this host — using the slower in-process fallback`,children:`fallback`})]}):(0,R.jsx)(`div`,{className:`px-4 py-3 text-xs text-rose-400 light:text-rose-700`,children:n})}function eP({path:e,matches:t,onPick:n}){let[r,i]=(0,v.useState)(!0);return(0,R.jsxs)(`li`,{className:`bg-neutral-950`,children:[(0,R.jsxs)(`button`,{onClick:()=>i(e=>!e),className:`flex w-full items-center gap-1 truncate px-2 py-1 text-left text-[11px] text-neutral-300 hover:bg-neutral-900`,title:e,children:[r?(0,R.jsx)(ue,{size:11}):(0,R.jsx)(fe,{size:11}),(0,R.jsx)(`span`,{className:`truncate font-mono`,children:e}),(0,R.jsx)(`span`,{className:`ml-auto text-[10px] text-neutral-500`,children:t.length})]}),r&&(0,R.jsx)(`ul`,{children:t.map((t,r)=>(0,R.jsx)(`li`,{children:(0,R.jsxs)(`button`,{onClick:()=>n(t),className:`flex w-full gap-2 px-2 py-0.5 text-left font-mono text-[11px] text-neutral-400 hover:bg-neutral-900 hover:text-neutral-100`,title:`${e}:${t.line}:${t.column}`,children:[(0,R.jsx)(`span`,{className:`w-10 shrink-0 text-right text-neutral-600`,children:t.line}),(0,R.jsx)(`span`,{className:`truncate`,children:tP(t.lineSnippet,t.column,t.length)})]})},`${t.line}:${t.column}:${r}`))})]})}function tP(e,t,n){let r=Math.max(0,Math.min(e.length,t-1)),i=Math.max(r,Math.min(e.length,r+n)),a=e.length-e.trimStart().length,o=Math.min(a,r),s=e.slice(o,r),c=e.slice(r,i),l=e.slice(i);return n===0||c.length===0?(0,R.jsx)(`span`,{children:e.slice(o)}):(0,R.jsxs)(`span`,{children:[(0,R.jsx)(`span`,{children:s}),(0,R.jsx)(`span`,{className:`bg-amber-700/30 text-amber-100 light:bg-amber-200 light:text-amber-900`,children:c}),(0,R.jsx)(`span`,{children:l})]})}var nP=3;function rP(){let e=Jr(e=>e.activeSessionId),t=Jr(t=>e===void 0?0:t.agentEndCountBySession[e]??0),n=Jr(t=>e===void 0?0:t.compactionEndCountBySession[e]??0),r=Jr(t=>e===void 0?!1:t.streamingBySession[e]??!1),i=Jr(t=>e===void 0?``:t.streamingTextBySession[e]??``),[a,o]=(0,v.useState)(void 0),[s,c]=(0,v.useState)(!1),[l,u]=(0,v.useState)(void 0),[d,f]=(0,v.useState)(!1),[p,m]=(0,v.useState)(!1),[h,g]=(0,v.useState)(``),[_,y]=(0,v.useState)(void 0),b=(0,v.useRef)(void 0),x=async()=>{if(e===void 0){o(void 0);return}b.current?.abort();let t=new AbortController;b.current=t,c(!0),u(void 0);try{let n=await L.getSessionContext(e,t.signal);if(t.signal.aborted)return;o(n)}catch(e){if(t.signal.aborted||e instanceof Error&&e.name===`AbortError`)return;e instanceof N&&e.status===404?(o(void 0),u(void 0)):u(e instanceof N?e.code:e.message)}finally{t.signal.aborted||c(!1)}};return(0,v.useEffect)(()=>{x()},[e,t,n]),(0,v.useEffect)(()=>()=>{b.current?.abort()},[]),e===void 0?(0,R.jsx)(`div`,{className:`flex h-full items-center justify-center px-4 py-6 text-center text-xs italic text-neutral-500`,children:`Select a session to inspect its context.`}):(0,R.jsxs)(`div`,{className:`flex h-full flex-col bg-neutral-950 text-xs text-neutral-200`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between border-b border-neutral-800 bg-neutral-900/40 px-3 py-1.5`,children:[(0,R.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-neutral-400`,children:`Context inspector`}),(0,R.jsxs)(`div`,{className:`flex items-center gap-1`,children:[s&&(0,R.jsx)(Ne,{size:11,className:`animate-spin text-neutral-500`}),(0,R.jsx)(`button`,{onClick:()=>void x(),disabled:s,className:`rounded p-1 text-neutral-500 hover:bg-neutral-800 hover:text-neutral-200 disabled:opacity-40`,title:`Refresh`,children:(0,R.jsx)(Ue,{size:11,className:s?`animate-spin`:``})})]})]}),l!==void 0&&(0,R.jsx)(`div`,{className:`border-b border-red-700/40 bg-red-900/20 px-3 py-1.5 text-[11px] text-red-300 light:border-red-300 light:bg-red-50 light:text-red-700`,children:l}),(0,R.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:a===void 0?(0,R.jsx)(`div`,{className:`px-4 py-6 text-center text-xs italic text-neutral-500`,children:s?`Loading…`:`No data — try refresh.`}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(iP,{data:a,turnsExpanded:d,onToggleTurns:()=>f(e=>!e)}),(0,R.jsx)(lP,{messages:a.messages,showThinking:p,onToggleThinking:()=>m(e=>!e),onViewRaw:(e,t)=>y({index:e,payload:t}),search:h,onSearchChange:g,...r&&i.length>0?{streamingTail:{content:i}}:{}})]})}),_!==void 0&&(0,R.jsx)(dP,{title:`Message ${_.index} — raw AgentMessage JSON`,payload:_.payload,onClose:()=>y(void 0)})]})}function iP({data:e,turnsExpanded:t,onToggleTurns:n}){let r=e.contextUsage,i=(0,v.useMemo)(()=>sP(e.messages,r.tokens),[e.messages,r.tokens]),a=(0,v.useMemo)(()=>hP(e.messages,e.turns),[e.messages,e.turns]),o=r.tokens??i.total,s=r.contextWindow>0?Math.min(1,o/r.contextWindow):0;return(0,R.jsxs)(`div`,{className:`space-y-2 border-b border-neutral-800 px-3 py-2`,children:[(0,R.jsxs)(`div`,{children:[(0,R.jsxs)(`div`,{className:`mb-1 flex items-center justify-between text-[10px] text-neutral-400`,children:[(0,R.jsxs)(`span`,{children:[`Context window (`,r.tokens===void 0?`estimate`:`current`,`)`]}),(0,R.jsxs)(`span`,{children:[vP(o),` /`,` `,r.contextWindow>0?vP(r.contextWindow):`unknown`,r.contextWindow>0&&(0,R.jsxs)(`span`,{className:`ml-1 text-neutral-600`,children:[`(`,(s*100).toFixed(1),`%)`]})]})]}),(0,R.jsx)(`div`,{className:`h-1.5 w-full overflow-hidden rounded bg-neutral-800`,children:(0,R.jsx)(`div`,{className:`h-full ${s>.9?`bg-red-500`:s>.7?`bg-amber-500`:`bg-emerald-500`}`,style:{width:`${Math.max(2,Math.min(100,s*100))}%`}})})]}),(0,R.jsx)(oP,{breakdown:i,contextWindow:r.contextWindow}),(0,R.jsxs)(`div`,{className:`space-y-0.5 border-t border-neutral-800 pt-1.5`,children:[e.turns.length>0&&(()=>{let t=e.turns[e.turns.length-1],n=a.get(t.index)??0;return(0,R.jsxs)(`div`,{className:`flex items-center justify-between text-[11px]`,children:[(0,R.jsx)(`span`,{className:`text-neutral-500`,children:`Last turn`}),(0,R.jsxs)(`span`,{className:`font-mono text-neutral-300`,title:`New = user message + tool results since the prior assistant turn (estimate). Out = assistant output tokens. Cost = that turn's billed cost.`,children:[`~`,vP(n),` new · `,vP(t.outputTokens),` out ·`,` `,yP(t.cost)]})]})})(),(0,R.jsxs)(`div`,{className:`flex items-center justify-between text-[11px]`,children:[(0,R.jsx)(`span`,{className:`text-neutral-500`,title:"Sum of `usage.input` per turn — NEW non-cached input the LLM saw across the session. Excludes cached portions (tracked separately below).",children:`Input (lifetime)`}),(0,R.jsx)(`span`,{className:`font-mono text-neutral-400`,children:vP(e.totalInputTokens)})]}),(0,R.jsxs)(`div`,{className:`flex items-center justify-between text-[11px]`,children:[(0,R.jsx)(`span`,{className:`text-neutral-500`,title:"Sum of `usage.cacheRead` per turn — prior context served from the prompt cache. Counted ONCE PER API CALL: every turn re-reads the same cached content and re-pays the (discounted) read fee, so this number grows ~quadratically with conversation length. Billed at ~10% of input rate on most providers.",children:`Cache served (lifetime)`}),(0,R.jsx)(`span`,{className:`font-mono text-neutral-400`,children:vP(e.totalCacheReadTokens)})]}),(0,R.jsxs)(`div`,{className:`flex items-center justify-between text-[11px]`,children:[(0,R.jsx)(`span`,{className:`text-neutral-500`,title:"Sum of `usage.cacheWrite` per turn — portions cached for reuse on subsequent turns. Billed at ~125% of input rate; small premium up front for big savings on the cache-served line.",children:`Cache written (lifetime)`}),(0,R.jsx)(`span`,{className:`font-mono text-neutral-400`,children:vP(e.totalCacheWriteTokens)})]}),(0,R.jsxs)(`div`,{className:`flex items-center justify-between text-[11px]`,children:[(0,R.jsx)(`span`,{className:`text-neutral-500`,title:"Sum of `usage.output` per turn — assistant tokens generated.",children:`Output (lifetime)`}),(0,R.jsx)(`span`,{className:`font-mono text-neutral-400`,children:vP(e.totalOutputTokens)})]}),(0,R.jsxs)(`div`,{className:`flex items-center justify-between text-[11px] font-medium`,children:[(0,R.jsx)(`span`,{className:`text-neutral-300`,children:`Total cost`}),(0,R.jsx)(`span`,{className:`font-mono text-emerald-400 light:text-emerald-700`,children:yP(e.totalCost)})]})]}),e.turns.length>0&&(0,R.jsxs)(`div`,{children:[(0,R.jsxs)(`button`,{onClick:n,className:`flex items-center gap-1 text-[10px] uppercase tracking-wider text-neutral-400 hover:text-neutral-200`,children:[t?(0,R.jsx)(ue,{size:10}):(0,R.jsx)(fe,{size:10}),`Per-turn (`,e.turns.length,`)`]}),t&&(0,R.jsx)(cP,{turns:e.turns,newDeltas:a})]})]})}var aP=[{key:`systemAndTools`,label:`System + tools`,color:`#64748b`},{key:`userPrompts`,label:`User prompts`,color:`#0ea5e9`},{key:`assistantText`,label:`Assistant text`,color:`#a78bfa`},{key:`thinking`,label:`Thinking`,color:`#71717a`},{key:`toolCalls`,label:`Tool calls`,color:`#f59e0b`},{key:`toolResults`,label:`Tool results`,color:`#10b981`},{key:`images`,label:`Images`,color:`#ec4899`}];function oP({breakdown:e,contextWindow:t}){let n=e.total;return n===0?null:(0,R.jsxs)(`div`,{children:[(0,R.jsxs)(`div`,{className:`mb-1 flex items-center justify-between text-[10px] text-neutral-400`,children:[(0,R.jsx)(`span`,{children:`What’s in the context`}),(0,R.jsxs)(`span`,{className:`text-neutral-600`,title:`Sum of category estimates (~chars/3)`,children:[`~`,vP(n),` tok`,t>0&&(0,R.jsxs)(`span`,{className:`ml-1`,children:[`(`,(n/t*100).toFixed(1),`%)`]})]})]}),(0,R.jsx)(`div`,{className:`flex h-1.5 w-full overflow-hidden rounded bg-neutral-800`,children:aP.map(t=>{let r=e[t.key];if(r===0)return null;let i=r/n*100;return(0,R.jsx)(`div`,{style:{width:`${i}%`,background:t.color},title:`${t.label}: ${vP(r)} tok (${i.toFixed(1)}%)`},t.key)})}),(0,R.jsx)(`ul`,{className:`mt-1 grid grid-cols-2 gap-x-3 gap-y-0.5 text-[10px]`,children:aP.map(t=>{let r=e[t.key];if(r===0)return null;let i=r/n*100;return(0,R.jsxs)(`li`,{className:`flex items-center gap-1.5`,children:[(0,R.jsx)(`span`,{className:`inline-block h-2 w-2 rounded-sm`,style:{background:t.color},"aria-hidden":`true`}),(0,R.jsx)(`span`,{className:`flex-1 truncate text-neutral-400`,children:t.label}),(0,R.jsx)(`span`,{className:`font-mono text-neutral-300`,children:vP(r)}),(0,R.jsxs)(`span`,{className:`w-10 text-right text-neutral-600`,children:[i.toFixed(0),`%`]})]},t.key)})})]})}function sP(e,t){let n=0,r=0,i=0,a=0,o=0,s=0;for(let t of e){let e=typeof t.role==`string`?t.role:``,c=t.content;if(e===`user`){if(typeof c==`string`)n+=c.length;else if(Array.isArray(c))for(let e of c){let t=e;t.type===`text`&&typeof t.text==`string`?n+=t.text.length:t.type===`image`&&(s+=1)}}else if(e===`assistant`&&Array.isArray(c))for(let e of c){let t=e;if(t.type===`text`&&typeof t.text==`string`)r+=t.text.length;else if(t.type===`thinking`&&typeof t.thinking==`string`)i+=t.thinking.length;else if(t.type===`toolCall`)try{a+=JSON.stringify(t.arguments??{}).length}catch{a+=String(t.arguments??``).length}}else if(e===`toolResult`){if(typeof c==`string`)o+=c.length;else if(Array.isArray(c))for(let e of c){let t=e;t.type===`text`&&typeof t.text==`string`?o+=t.text.length:t.type===`image`&&(s+=1)}}}let c=e=>Math.ceil(e/nP),l=c(n),u=c(r),d=c(i),f=c(a),p=c(o),m=s*1500,h=l+u+d+f+p+m,g=t!==void 0&&t>h?t-h:0;return{systemAndTools:g,userPrompts:l,assistantText:u,thinking:d,toolCalls:f,toolResults:p,images:m,total:h+g}}function cP({turns:e,newDeltas:t}){return(0,R.jsx)(`div`,{className:`mt-1 overflow-x-auto`,children:(0,R.jsxs)(`table`,{className:`w-full font-mono text-[10px]`,children:[(0,R.jsx)(`thead`,{className:`text-neutral-500`,children:(0,R.jsxs)(`tr`,{children:[(0,R.jsx)(`th`,{className:`pr-2 text-left font-normal`,children:`#`}),(0,R.jsx)(`th`,{className:`pr-2 text-left font-normal`,children:`Model`}),(0,R.jsx)(`th`,{className:`pr-2 text-right font-normal`,title:`Estimated new tokens this turn — user message + tool results since the prior assistant turn (~chars/3 estimate). Distinct from Prompt.`,children:`New`}),(0,R.jsx)(`th`,{className:`pr-2 text-right font-normal`,title:`Full prompt sent to the LLM = usage.input + cacheRead + cacheWrite. Includes ALL re-sent prior context — this grows monotonically with conversation length, which is normal LLM behavior.`,children:`Prompt`}),(0,R.jsx)(`th`,{className:`pr-2 text-right font-normal`,title:`Assistant output tokens this turn`,children:`Out`}),(0,R.jsx)(`th`,{className:`text-right font-normal`,title:`Cost billed for this turn`,children:`Cost`})]})}),(0,R.jsx)(`tbody`,{className:`text-neutral-300`,children:e.map((e,n)=>{let r=e.inputTokens+e.cacheReadTokens+e.cacheWriteTokens,i=t.get(e.index)??0;return(0,R.jsxs)(`tr`,{className:`border-t border-neutral-800/60`,children:[(0,R.jsx)(`td`,{className:`pr-2 text-neutral-600`,children:n+1}),(0,R.jsx)(`td`,{className:`max-w-[140px] truncate pr-2`,title:`${e.provider}/${e.model}`,children:e.model}),(0,R.jsxs)(`td`,{className:`pr-2 text-right text-neutral-200`,title:`New content (estimate)`,children:[`~`,vP(i)]}),(0,R.jsx)(`td`,{className:`pr-2 text-right`,title:`input ${vP(e.inputTokens)} + cR ${vP(e.cacheReadTokens)} + cW ${vP(e.cacheWriteTokens)}`,children:vP(r)}),(0,R.jsx)(`td`,{className:`pr-2 text-right`,children:vP(e.outputTokens)}),(0,R.jsx)(`td`,{className:`text-right text-emerald-400 light:text-emerald-700`,children:yP(e.cost)})]},`${e.index}-${e.timestamp}`)})})]})})}function lP({messages:e,showThinking:t,onToggleThinking:n,onViewRaw:r,search:i,onSearchChange:a,streamingTail:o}){let s=i.trim().toLowerCase(),c=(0,v.useMemo)(()=>s.length===0?e.map((e,t)=>({msg:e,originalIndex:t})):e.map((e,t)=>({msg:e,originalIndex:t})).filter(({msg:e})=>(typeof e.role==`string`?e.role.toLowerCase():``).includes(s)?!0:pP(e,!0).toLowerCase().includes(s)),[e,s]);return(0,R.jsxs)(`div`,{className:`px-2 py-2`,children:[(0,R.jsxs)(`div`,{className:`mb-1 flex items-center justify-between gap-2 px-1`,children:[(0,R.jsxs)(`span`,{className:`shrink-0 text-[10px] uppercase tracking-wider text-neutral-400`,children:[`Messages (`,s.length>0?`${c.length}/${e.length}`:e.length,`)`]}),(0,R.jsxs)(`label`,{className:`flex items-center gap-1 text-[10px] text-neutral-500 hover:text-neutral-300`,children:[(0,R.jsx)(`input`,{type:`checkbox`,checked:t,onChange:n,className:`h-3 w-3`}),`Show thinking blocks`]})]}),e.length>=10&&(0,R.jsxs)(`div`,{className:`relative mb-1 px-1`,children:[(0,R.jsx)(qe,{size:11,className:`pointer-events-none absolute left-2.5 top-1/2 -translate-y-1/2 text-neutral-500`}),(0,R.jsx)(`input`,{type:`text`,value:i,onChange:e=>a(e.target.value),placeholder:`Find in messages…`,className:`w-full rounded border border-neutral-800 bg-neutral-950 py-1 pl-6 pr-2 text-[11px] text-neutral-200 placeholder:text-neutral-600 focus:border-neutral-600 focus:outline-none`})]}),(0,R.jsxs)(`ul`,{className:`space-y-1`,children:[c.map(({msg:e,originalIndex:n})=>(0,R.jsx)(uP,{index:n,message:e,showThinking:t,onViewRaw:()=>r(n,e)},n)),o!==void 0&&s.length===0&&(0,R.jsx)(`li`,{className:`rounded border border-violet-700/40 bg-violet-900/10 light:border-violet-300 light:bg-violet-50`,children:(0,R.jsxs)(`div`,{className:`flex items-start gap-2 px-2 py-1.5`,children:[(0,R.jsx)(Ne,{size:11,className:`mt-0.5 shrink-0 animate-spin text-violet-300 light:text-violet-700`}),(0,R.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-0.5`,children:[(0,R.jsx)(`div`,{className:`flex items-center gap-1.5`,children:(0,R.jsx)(`span`,{className:`rounded bg-violet-900/40 px-1.5 py-0.5 text-[9px] uppercase tracking-wider text-violet-300 light:bg-violet-100 light:text-violet-800`,children:`assistant (streaming)`})}),(0,R.jsx)(`p`,{className:`line-clamp-2 text-[11px] text-neutral-300`,children:o.content})]})]})})]})]})}function uP({index:e,message:t,showThinking:n,onViewRaw:r}){let[i,a]=(0,v.useState)(!1),o=typeof t.role==`string`?t.role:`unknown`,s=o===`compactionSummary`,c=(0,v.useMemo)(()=>pP(t,n),[t,n]),l=mP(t),u=typeof t.timestamp==`number`?t.timestamp:0;return(0,R.jsxs)(`li`,{className:`rounded border border-neutral-800/70 bg-neutral-900/30`,children:[(0,R.jsxs)(`button`,{onClick:()=>a(e=>!e),className:`flex w-full items-start gap-2 px-2 py-1.5 text-left hover:bg-neutral-900/60`,children:[(0,R.jsx)(`span`,{className:`pt-0.5 text-neutral-600`,children:i?(0,R.jsx)(ue,{size:11}):(0,R.jsx)(fe,{size:11})}),(0,R.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-0.5`,children:[(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,R.jsx)(`span`,{className:`rounded px-1.5 py-0.5 text-[9px] uppercase tracking-wider ${fP(o)}`,children:o}),s&&(0,R.jsx)(`span`,{className:`rounded bg-fuchsia-900/40 px-1.5 py-0.5 text-[9px] text-fuchsia-300 light:bg-fuchsia-100 light:text-fuchsia-800`,children:`compacted`}),(0,R.jsxs)(`span`,{className:`text-[10px] text-neutral-600`,children:[`~`,vP(l),` tok`]}),u>0&&(0,R.jsx)(`span`,{className:`text-[10px] text-neutral-600`,children:new Date(u).toLocaleTimeString()})]}),!i&&c.length>0&&(0,R.jsx)(`p`,{className:`line-clamp-2 text-[11px] text-neutral-400`,children:c})]}),(0,R.jsx)(`button`,{onClick:e=>{e.stopPropagation(),r()},className:`rounded p-1 text-neutral-500 hover:bg-neutral-800 hover:text-neutral-100`,title:`View raw AgentMessage JSON`,children:(0,R.jsx)(ge,{size:11})})]}),i&&(0,R.jsx)(`div`,{className:`space-y-1 border-t border-neutral-800/70 px-3 py-2`,children:gP(t,n,e)})]})}function dP({title:e,payload:t,onClose:n}){let r=(0,v.useMemo)(()=>{try{return JSON.stringify(t,null,2)}catch{return String(t)}},[t]);return(0,v.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]),(0,R.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/70 px-4 py-8`,onClick:n,children:(0,R.jsxs)(`div`,{onClick:e=>e.stopPropagation(),className:`flex h-full max-h-[720px] w-full max-w-4xl flex-col overflow-hidden rounded-lg border border-neutral-800 bg-neutral-950 shadow-2xl`,children:[(0,R.jsxs)(`header`,{className:`flex items-center justify-between border-b border-neutral-800 px-3 py-2`,children:[(0,R.jsx)(`span`,{className:`text-xs text-neutral-200`,children:e}),(0,R.jsx)(`button`,{onClick:n,className:`rounded p-2 text-neutral-400 hover:bg-neutral-800 hover:text-neutral-200`,title:`Close (Esc)`,children:(0,R.jsx)(it,{size:20})})]}),(0,R.jsx)(Oa,{code:r,language:`json`,theme:Zi.vsDark,children:({style:e,tokens:t,getLineProps:n,getTokenProps:r})=>(0,R.jsx)(`pre`,{className:`flex-1 overflow-auto whitespace-pre p-3 font-mono text-[11px]`,style:{...e,background:`transparent`},children:t.map((e,t)=>(0,R.jsx)(`div`,{...n({line:e}),children:e.map((e,t)=>(0,R.jsx)(`span`,{...r({token:e})},t))},t))})})]})})}function fP(e){return e===`user`?`bg-sky-900/40 text-sky-300 light:bg-sky-100 light:text-sky-800`:e===`assistant`?`bg-violet-900/40 text-violet-300 light:bg-violet-100 light:text-violet-800`:e===`tool`||e===`toolResult`?`bg-amber-900/40 text-amber-300 light:bg-amber-100 light:text-amber-800`:e===`compactionSummary`?`bg-fuchsia-900/40 text-fuchsia-300 light:bg-fuchsia-100 light:text-fuchsia-800`:`bg-neutral-800 text-neutral-400`}function pP(e,t){let n=e.content;if(typeof n==`string`)return n.slice(0,200);if(!Array.isArray(n))return``;let r=[];for(let e of n){let n=e;n.type===`thinking`&&!t||(n.type===`text`&&typeof n.text==`string`?r.push(n.text):n.type===`thinking`&&typeof n.thinking==`string`?r.push(`[thinking] ${n.thinking}`):n.type===`toolCall`&&typeof n.name==`string`&&r.push(`[tool: ${n.name}]`))}return r.join(` `).slice(0,200)}function mP(e){let t=e.usage;if(t!==void 0&&typeof t.totalTokens==`number`)return t.totalTokens;let n=e.content;if(typeof n==`string`)return Math.ceil(n.length/nP);if(!Array.isArray(n))return 0;let r=0,i=0;for(let e of n){let t=e;typeof t.text==`string`&&(r+=t.text.length),t.type===`image`&&(i+=1)}return Math.ceil(r/nP)+i*1500}function hP(e,t){let n=new Map,r=-1;for(let i of t){let t=0;for(let n=r+1;n<i.index;n++){let r=e[n];if(r===void 0)continue;let i=typeof r.role==`string`?r.role:``;i!==`user`&&i!==`toolResult`||(t+=mP(r))}n.set(i.index,t),r=i.index}return n}function gP(e,t,n){let r=typeof e.role==`string`?e.role:`unknown`,i=e.content;return r===`toolResult`?(0,R.jsxs)(`div`,{children:[(0,R.jsxs)(`p`,{className:`mb-1 text-[10px] text-neutral-500`,children:[`tool: `,(0,R.jsx)(`span`,{className:`font-mono`,children:String(e.toolName??`unknown`)}),` `,e.isError===!0&&(0,R.jsx)(`span`,{className:`text-red-400 light:text-red-700`,children:`(error)`})]}),(0,R.jsx)(`pre`,{className:`max-h-64 overflow-auto whitespace-pre-wrap break-words rounded bg-neutral-950 p-2 font-mono text-[10px] text-neutral-300`,children:_P(i)})]}):Array.isArray(i)?(0,R.jsx)(R.Fragment,{children:i.map((e,r)=>{let i=e;if(i.type===`thinking`&&!t)return null;if(i.type===`text`||i.type===`thinking`){let e=i.type===`thinking`?i.thinking:i.text;return(0,R.jsx)(`pre`,{className:`whitespace-pre-wrap break-words font-sans text-[11px] ${i.type===`thinking`?`italic text-neutral-500`:`text-neutral-200`}`,children:String(e??``)},`${n}-${r}`)}return i.type===`toolCall`?(0,R.jsxs)(`div`,{className:`rounded border border-neutral-800 p-2`,children:[(0,R.jsxs)(`p`,{className:`mb-1 text-[10px] text-neutral-500`,children:[`tool call: `,(0,R.jsx)(`span`,{className:`font-mono`,children:String(i.name??`unknown`)})]}),(0,R.jsx)(`pre`,{className:`max-h-48 overflow-auto whitespace-pre-wrap break-words font-mono text-[10px] text-neutral-300`,children:_P(i.arguments)})]},`${n}-${r}`):i.type===`image`?(0,R.jsx)(`p`,{className:`text-[11px] italic text-neutral-500`,children:`[image attachment]`},`${n}-${r}`):(0,R.jsx)(`pre`,{className:`whitespace-pre-wrap break-words font-mono text-[10px] text-neutral-500`,children:_P(i)},`${n}-${r}`)})}):typeof i==`string`?(0,R.jsx)(`pre`,{className:`whitespace-pre-wrap break-words font-sans text-[11px] text-neutral-200`,children:i}):(0,R.jsx)(`pre`,{className:`whitespace-pre-wrap break-words font-mono text-[10px] text-neutral-500`,children:_P(e)})}function _P(e){try{return JSON.stringify(e,null,2)}catch{return String(e)}}function vP(e){return e<1e3?String(e):e<1e6?`${(e/1e3).toFixed(+(e<1e4))}k`:`${(e/1e6).toFixed(2)}M`}function yP(e){return e===0?`$0`:e<.01?`$${e.toFixed(4)}`:e<1?`$${e.toFixed(3)}`:`$${e.toFixed(2)}`}function bP({getStartSize:e,onResize:t,direction:n,minSize:r,maxSize:i,orientation:a=`vertical`}){let o=(0,v.useRef)(null),s=a===`horizontal`,c=s?`row-resize`:`col-resize`;(0,v.useEffect)(()=>{let e=()=>{o.current!==null&&(o.current=null,document.body.style.removeProperty(`cursor`),document.body.style.removeProperty(`user-select`))},t=t=>{t.key===`Escape`&&e()};return window.addEventListener(`keydown`,t),window.addEventListener(`blur`,e),()=>{e(),window.removeEventListener(`keydown`,t),window.removeEventListener(`blur`,e)}},[]);let l=t=>{t.preventDefault(),t.currentTarget.setPointerCapture(t.pointerId),o.current={start:s?t.clientY:t.clientX,startSize:e()},document.body.style.cursor=c,document.body.style.userSelect=`none`},u=e=>{if(o.current===null)return;let a=(s?e.clientY:e.clientX)-o.current.start,c=o.current.startSize+a*n;t(Math.min(Math.max(c,r),i))},d=e=>{o.current!==null&&(e.currentTarget.releasePointerCapture(e.pointerId),o.current=null,document.body.style.removeProperty(`cursor`),document.body.style.removeProperty(`user-select`))},f=s?`h-1 w-full cursor-row-resize`:`w-1 h-full cursor-col-resize`,p=s?`absolute inset-x-0 -top-1 -bottom-1`:`absolute inset-y-0 -left-1 -right-1`;return(0,R.jsx)(`div`,{onPointerDown:l,onPointerMove:u,onPointerUp:d,onPointerCancel:d,className:`group relative shrink-0 bg-neutral-800 hover:bg-neutral-600 active:bg-neutral-500 ${f}`,role:`separator`,"aria-orientation":s?`horizontal`:`vertical`,children:(0,R.jsx)(`div`,{className:p})})}var xP=`pi-forge/files-width`,SP=`pi-forge/editor-width`,CP=`pi-forge/terminal-height`,wP=`pi-forge/todo-panel-height`,TP=280,EP=480,DP=280,OP=200,kP=200,AP=320,jP=320,MP=140,NP=100;function PP(e,t){let n=localStorage.getItem(e);if(n===null)return t;let r=Number.parseInt(n,10);return Number.isFinite(r)&&r>0?r:t}function FP(){let e=ar(e=>e.ready),t=ar(e=>e.isAuthenticated),n=ar(e=>e.mustChangePassword),r=ar(e=>e.bootstrap),i=ar(e=>e.logout),a=ur(e=>e.projects),o=ur(e=>!e.loading),s=ur(e=>e.load),c=dr(),l=ur(e=>e.activeProjectId),u=Jr(e=>e.activeSessionId),d=st(),[f,p]=(0,v.useState)(!1),[m,h]=(0,v.useState)(!1),[g,_]=(0,v.useState)(()=>localStorage.getItem(`pi-forge/files-open`)===`true`),y=e=>{_(e),localStorage.setItem(`pi-forge/files-open`,e?`true`:`false`)},[b,x]=(0,v.useState)(()=>{let e=localStorage.getItem(`pi-forge/right-tab`);return e===`files`||e===`search`||e===`changes`||e===`git`||e===`context`||e===`processes`?e:`files`}),S=e=>{x(e),localStorage.setItem(`pi-forge/right-tab`,e)},[C,w]=(0,v.useState)(()=>localStorage.getItem(`pi-forge/terminal-open`)===`true`),T=e=>{w(e),localStorage.setItem(`pi-forge/terminal-open`,e?`true`:`false`)},[E,D]=(0,v.useState)(()=>localStorage.getItem(`pi-forge/chat-open`)!==`false`),O=e=>{D(e),localStorage.setItem(`pi-forge/chat-open`,e?`true`:`false`)},[k,ee]=(0,v.useState)(()=>localStorage.getItem(`pi-forge/editor-open`)!==`false`),A=e=>{ee(e),localStorage.setItem(`pi-forge/editor-open`,e?`true`:`false`)},[te,ne]=(0,v.useState)(!1),[re,ie]=(0,v.useState)(()=>PP(CP,DP)),j=(0,v.useRef)(re);(0,v.useEffect)(()=>{j.current=re,localStorage.setItem(CP,String(re))},[re]);let[ae,M]=(0,v.useState)(()=>PP(wP,OP)),oe=(0,v.useRef)(ae);(0,v.useEffect)(()=>{oe.current=ae,localStorage.setItem(wP,String(ae))},[ae]);let se=QA(e=>e.todoPanelOpen);(0,v.useEffect)(()=>{se&&!g&&!d&&y(!0)},[se]);let ce=QA(e=>e.openProcessesTabSeq);(0,v.useEffect)(()=>{ce!==0&&(!g&&!d&&y(!0),S(`processes`))},[ce]);let le=QA(e=>e.openEditorPaneSeq);(0,v.useEffect)(()=>{le!==0&&A(!0)},[le]);let[ue,de]=(0,v.useState)(()=>PP(xP,TP)),[fe,pe]=(0,v.useState)(()=>PP(SP,EP)),me=(0,v.useRef)(ue),he=(0,v.useRef)(fe);(0,v.useEffect)(()=>{me.current=ue,localStorage.setItem(xP,String(ue))},[ue]),(0,v.useEffect)(()=>{he.current=fe,localStorage.setItem(SP,String(fe))},[fe]);let ge=ai(e=>e.openFiles.length),_e=k&&ge>0,ve=NN(c?.id).status?.files.length??0,ye=Ir(Nr(e=>Pr(e,u))),be=Jr(e=>u===void 0?0:e.agentEndCountBySession[u]??0),Se=Jr(e=>u===void 0?!1:e.streamingBySession[u]??!1),Ce=ai(e=>e.loadTree),we=ai(e=>e.restoreTabs),Te=ai(e=>e.refreshOpenFiles);(0,v.useEffect)(()=>{c===void 0||Se||(Ce(c.id),Te(c.id))},[c?.id,Se,be]),(0,v.useEffect)(()=>{c!==void 0&&we(c.id)},[c?.id]),(0,v.useEffect)(()=>{if(!m)return;let e=e=>{e.key===`Escape`&&h(!1)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[m]);let De=(0,v.useRef)(!0);(0,v.useEffect)(()=>{if(De.current){De.current=!1;return}f&&p(!1)},[l,u]),(0,v.useEffect)(()=>{if(!f)return;let e=e=>{e.key===`Escape`&&p(!1)};window.addEventListener(`keydown`,e);let t=document.body.style.overflow;return document.body.style.overflow=`hidden`,()=>{window.removeEventListener(`keydown`,e),document.body.style.overflow=t}},[f]),(0,v.useEffect)(()=>{!d&&f&&p(!1)},[d,f]);let Oe=QA(e=>e.settingsRequest),ke=QA(e=>e.clearSettingsRequest),[Ae,je]=(0,v.useState)(void 0);(0,v.useEffect)(()=>{Oe!==void 0&&(h(!0),Oe.tab!==void 0&&je(Oe.tab),ke())},[Oe,ke]),(0,v.useEffect)(()=>{r()},[r]);let Me=ci(e=>e.load),Ne=ci(e=>e.minimal);(0,v.useEffect)(()=>{Me()},[Me]),(0,v.useEffect)(()=>{t&&!n&&s()},[t,n,s]);let Fe=li(e=>e.load);(0,v.useEffect)(()=>{t&&!n&&Fe()},[t,n,Fe]);let Ie=Dj(e=>e.startPolling),Re=Dj(e=>e.stopPolling);return(0,v.useEffect)(()=>{t&&!n?Ie():Re()},[t,n,Ie,Re]),e?t?n?(0,R.jsx)(hi,{}):(0,R.jsxs)(`div`,{className:`flex h-screen flex-col bg-neutral-950 text-neutral-100`,children:[(0,R.jsxs)(`header`,{className:`flex items-center justify-between border-b border-neutral-800 px-4 py-2`,style:{paddingTop:`max(0.5rem, env(safe-area-inset-top))`},children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,R.jsx)(`button`,{type:`button`,onClick:()=>p(e=>!e),"aria-label":f?`Close project sidebar`:`Open project sidebar`,"aria-expanded":f,className:`-ml-1 inline-flex min-h-11 min-w-11 items-center justify-center rounded-md text-neutral-300 hover:bg-neutral-800 md:hidden`,children:(0,R.jsx)(Pe,{size:20})}),(0,R.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,R.jsx)(`img`,{src:`/icons/icon.svg`,alt:``,className:`h-8 w-8`,"aria-hidden":`true`}),(0,R.jsx)(`span`,{className:`text-sm font-semibold tracking-tight`,children:`pi-forge`})]})]}),(0,R.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,R.jsxs)(`div`,{className:`hidden md:contents`,children:[(0,R.jsxs)(`button`,{onClick:()=>O(!E),className:`flex items-center gap-1 rounded-md border px-2 py-1 text-xs ${E?`border-neutral-500 bg-neutral-800 text-neutral-100`:`border-neutral-700 text-neutral-300 hover:border-neutral-500`}`,title:`Toggle the chat pane`,children:[(0,R.jsx)(Le,{size:13}),`Chat`]}),(0,R.jsxs)(`button`,{onClick:()=>A(!k),className:`flex items-center gap-1 rounded-md border px-2 py-1 text-xs ${k?`border-neutral-500 bg-neutral-800 text-neutral-100`:`border-neutral-700 text-neutral-300 hover:border-neutral-500`}`,title:`Toggle the editor pane (open tabs persist across reloads)`,children:[(0,R.jsx)(xe,{size:13}),`Editor`]}),(0,R.jsxs)(`button`,{onClick:()=>y(!g),className:`flex items-center gap-1 rounded-md border px-2 py-1 text-xs ${g?`border-neutral-500 bg-neutral-800 text-neutral-100`:`border-neutral-700 text-neutral-300 hover:border-neutral-500`}`,title:`Toggle the file browser tree`,children:[(0,R.jsx)(Ee,{size:13}),`Files`]}),!Ne&&(0,R.jsxs)(`button`,{onClick:()=>T(!C),className:`flex items-center gap-1 rounded-md border px-2 py-1 text-xs ${C?`border-neutral-500 bg-neutral-800 text-neutral-100`:`border-neutral-700 text-neutral-300 hover:border-neutral-500`}`,title:`Toggle the integrated terminal`,children:[(0,R.jsx)(Ze,{size:13}),`Terminal`]})]}),(0,R.jsx)(`div`,{className:`hidden md:block`,children:(0,R.jsx)(DN,{})}),(0,R.jsx)(ON,{}),(0,R.jsx)(`button`,{onClick:()=>h(!0),className:`rounded-md border border-neutral-700 px-2 py-1 text-xs text-neutral-300 hover:border-neutral-500`,title:`Settings (providers, agent defaults, MCP, skills)`,children:`Settings`}),(0,R.jsx)(`button`,{onClick:i,className:`rounded-md border border-neutral-700 px-2 py-1 text-xs text-neutral-300 hover:border-neutral-500`,children:`Sign out`})]})]}),(0,R.jsx)(bi,{}),m&&(0,R.jsx)(Ij,{onClose:()=>{h(!1),je(void 0)},...Ae===void 0?{}:{initialTab:Ae}}),(0,R.jsxs)(`div`,{className:`flex flex-1 flex-col overflow-hidden`,children:[(0,R.jsxs)(`div`,{className:`flex flex-1 overflow-hidden`,children:[f&&(0,R.jsx)(`div`,{className:`fixed inset-0 z-30 bg-black/50 md:hidden`,onClick:()=>p(!1),"aria-hidden":!0}),d&&!f&&(0,R.jsx)(`div`,{className:`fixed inset-y-0 left-0 z-20 w-5 md:hidden`,"aria-hidden":!0,onPointerDown:e=>{let t=e.clientX,n=!1,r=e=>{n||e.clientX-t>50&&(p(!0),n=!0,i())},i=()=>{window.removeEventListener(`pointermove`,r),window.removeEventListener(`pointerup`,i),window.removeEventListener(`pointercancel`,i)};window.addEventListener(`pointermove`,r),window.addEventListener(`pointerup`,i),window.addEventListener(`pointercancel`,i)}}),(0,R.jsx)(Ai,{className:`fixed inset-y-0 left-0 z-40 shadow-2xl transition-transform duration-200 ease-out md:static md:inset-auto md:z-auto md:shadow-none md:transition-none `+(f?`max-md:translate-x-0`:`max-md:-translate-x-full`)}),(0,R.jsxs)(`main`,{className:`flex flex-1 overflow-hidden`,children:[E&&(0,R.jsx)(`div`,{className:`flex flex-1 flex-col overflow-hidden`,children:o&&a.length===0?te?(0,R.jsx)(`div`,{className:`flex flex-1 items-center justify-center px-6 text-center`,children:(0,R.jsxs)(`div`,{className:`space-y-3 text-sm text-neutral-400`,children:[(0,R.jsx)(`p`,{children:`No projects yet.`}),(0,R.jsx)(`button`,{onClick:()=>ne(!1),className:`rounded-md bg-neutral-100 px-3 py-1.5 text-sm font-medium text-neutral-900 hover:bg-white`,children:`+ New project`})]})}):(0,R.jsx)(`div`,{className:`flex flex-1 items-center justify-center`,children:(0,R.jsx)(xi,{onClose:()=>ne(!0)})}):u===void 0?c?(0,R.jsx)(`div`,{className:`flex flex-1 items-center justify-center px-6 text-center`,children:(0,R.jsxs)(`div`,{className:`space-y-3 text-sm text-neutral-400`,children:[(0,R.jsx)(`h2`,{className:`text-xl font-semibold text-neutral-100`,children:c.name}),(0,R.jsx)(`p`,{className:`font-mono text-xs`,children:c.path}),(0,R.jsx)(`p`,{children:`Pick a session from the sidebar — or start a new one here.`}),(0,R.jsx)(`button`,{onClick:()=>{Jr.getState().createSession(c.id)},className:`rounded-md bg-neutral-100 px-3 py-1.5 text-sm font-medium text-neutral-900 hover:bg-white`,children:`+ New session`})]})}):(0,R.jsx)(`div`,{className:`flex flex-1 items-center justify-center`,children:(0,R.jsx)(`p`,{className:`text-sm text-neutral-400`,children:`Select a project from the sidebar.`})}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(mA,{sessionId:u}),!Ne&&(0,R.jsx)(Cj,{sessionId:u,alreadyOnChangesTab:g&&b===`changes`,onOpen:()=>{g||y(!0),S(`changes`)}}),(0,R.jsx)(yM,{sessionId:u}),(0,R.jsx)(vj,{sessionId:u})]})}),!d&&_e&&(E?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(bP,{getStartSize:()=>he.current,onResize:e=>pe(e),direction:-1,minSize:AP,maxSize:Math.max(AP,window.innerWidth-(g?ue:0)-jP-240)}),(0,R.jsx)(`div`,{className:`flex shrink-0 flex-col border-l border-neutral-800`,style:{width:`${fe}px`},children:(0,R.jsx)(QM,{})})]}):(0,R.jsx)(`div`,{className:`flex flex-1 flex-col overflow-hidden`,children:(0,R.jsx)(QM,{})})),!d&&g&&(()=>{let e=!E&&!_e,t=(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`div`,{className:`flex border-b border-neutral-800 bg-neutral-900/40`,children:(Ne?[`files`,`search`,`processes`,`context`]:[`files`,`search`,`changes`,`git`,`processes`,`context`]).map(e=>(0,R.jsxs)(`button`,{onClick:()=>S(e),className:`flex items-center gap-1 px-3 py-1.5 text-[11px] uppercase tracking-wider ${b===e?`border-b border-neutral-100 text-neutral-100`:`text-neutral-500 hover:text-neutral-300`}`,children:[e===`files`?`Files`:e===`search`?`Search`:e===`changes`?`Last turn`:e===`git`?`Git`:e===`processes`?`Processes`:`Context`,e===`git`&&ve>0&&(0,R.jsx)(`span`,{className:`rounded bg-amber-900/40 px-1 py-0.5 text-[9px] text-amber-300 light:bg-amber-100 light:text-amber-800`,children:ve}),e===`processes`&&ye>0&&(0,R.jsx)(`span`,{className:`rounded bg-emerald-900/40 px-1 py-0.5 text-[9px] text-emerald-300 light:bg-emerald-100 light:text-emerald-800`,children:ye})]},e))}),(0,R.jsxs)(`div`,{className:`flex flex-1 flex-col overflow-hidden`,children:[(0,R.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:b===`files`?(0,R.jsx)(IM,{}):b===`search`?(0,R.jsx)(YN,{}):!Ne&&b===`changes`?(0,R.jsx)(jN,{}):!Ne&&b===`git`?(0,R.jsx)(LN,{}):b===`context`?(0,R.jsx)(rP,{}):b===`processes`&&u!==void 0?(0,R.jsx)(DM,{sessionId:u}):(0,R.jsx)(IM,{})}),se&&u!==void 0&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(bP,{orientation:`horizontal`,getStartSize:()=>oe.current,onResize:e=>M(e),direction:-1,minSize:NP,maxSize:Math.max(NP,window.innerHeight*.7)}),(0,R.jsx)(`div`,{className:`shrink-0 overflow-hidden border-t border-neutral-800 light:border-neutral-200`,style:{height:`${ae}px`},children:(0,R.jsx)(SM,{sessionId:u,onClose:()=>QA.getState().setTodoPanelOpen(!1)})})]})]})]});return e?(0,R.jsx)(`div`,{className:`flex flex-1 flex-col overflow-hidden`,children:t}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(bP,{getStartSize:()=>me.current,onResize:e=>de(e),direction:-1,minSize:kP,maxSize:Math.max(kP,window.innerWidth-jP-240-(_e?AP:0))}),(0,R.jsx)(`div`,{className:`flex shrink-0 flex-col border-l border-neutral-800`,style:{width:`${ue}px`},children:t})]})})()]})]}),!d&&!Ne&&C&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(bP,{orientation:`horizontal`,getStartSize:()=>j.current,onResize:e=>ie(e),direction:-1,minSize:MP,maxSize:Math.max(MP,Math.floor(window.innerHeight*.7))}),(0,R.jsx)(`div`,{className:`shrink-0 border-t border-neutral-800`,style:{height:`${re}px`},children:(0,R.jsx)(CN,{})})]})]})]}):(0,R.jsx)(pi,{}):(0,R.jsx)(`main`,{className:`flex min-h-screen items-center justify-center text-sm text-neutral-400`,children:`Loading…`})}eC(),O({immediate:!0});var IP=class extends v.Component{state={error:null};static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e,t){console.error(`[pi-forge] root render error`,e,t)}render(){return this.state.error===null?this.props.children:(0,R.jsxs)(`main`,{style:{padding:`2rem`,fontFamily:`monospace`,color:`#fca5a5`,background:`#0a0a0a`,minHeight:`100vh`,whiteSpace:`pre-wrap`,overflow:`auto`},children:[(0,R.jsx)(`h1`,{style:{color:`#fff`,marginBottom:`1rem`},children:`pi-forge: render crash`}),(0,R.jsx)(`p`,{style:{color:`#d4d4d4`,marginBottom:`1rem`},children:this.state.error.message}),(0,R.jsx)(`pre`,{style:{fontSize:`11px`,color:`#a3a3a3`},children:this.state.error.stack??`(no stack)`}),(0,R.jsx)(`p`,{style:{marginTop:`2rem`,color:`#71717a`,fontSize:`12px`},children:`Tip: open the browser console for more detail. Try clearing localStorage (devtools → Application → Local Storage → Clear) and refreshing if the error mentions stale state.`})]})}};window.addEventListener(`error`,e=>{console.error(`[pi-forge] uncaught error`,e.error)}),window.addEventListener(`unhandledrejection`,e=>{console.error(`[pi-forge] unhandled rejection`,e.reason)});var LP=document.getElementById(`root`);if(!LP)throw Error(`#root element missing in index.html`);(0,y.createRoot)(LP).render((0,R.jsx)(v.StrictMode,{children:(0,R.jsx)(IP,{children:(0,R.jsx)(FP,{})})}));export{l as a,d as i,tC as n,fi as r,nC as t};
|
|
375
|
+
//# sourceMappingURL=index-ChVHn55j.js.map
|