@openchamber/web 1.10.3 → 1.10.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/dist/assets/{JsonTreeView-BhnwxlMV.js → JsonTreeView-DjN_Y61c.js} +1 -1
  2. package/dist/assets/{MarkdownRendererImpl-BL9AWfBg.js → MarkdownRendererImpl-D8Pj3Iy7.js} +3 -3
  3. package/dist/assets/{MultiRunWindow-C2H5hpiq.js → MultiRunWindow-BQtAxwtT.js} +1 -1
  4. package/dist/assets/{OnboardingScreen-B0qAcM9E.js → OnboardingScreen-Bm0_2bRQ.js} +2 -2
  5. package/dist/assets/{SettingsWindow-BPWLJy6K.js → SettingsWindow-DfL6vlAG.js} +1 -1
  6. package/dist/assets/{TerminalView-CSEtmbyD.js → TerminalView-DiV5PHoV.js} +1 -1
  7. package/dist/assets/{ToolOutputDialog-U8mr6h7H.js → ToolOutputDialog-D32OrEUX.js} +6 -6
  8. package/dist/assets/{es-RQYrOImo.js → es-B8ic5apd.js} +1 -1
  9. package/dist/assets/{index-pJeohTL6.css → index-4bBArO_M.css} +1 -1
  10. package/dist/assets/index-DqXJOAVZ.js +1 -0
  11. package/dist/assets/{ko-BqABW41E.js → ko-pXQ0SsBr.js} +1 -1
  12. package/dist/assets/main-BRTUWU3R.js +126 -0
  13. package/dist/assets/{main-DkIlaUcs.js → main-DXB_3esA.js} +2 -2
  14. package/dist/assets/miniChat-CZqOFY1k.js +2 -0
  15. package/dist/assets/{modelPrefsAutoSave-BHV5Gay8.js → modelPrefsAutoSave-DlTpduDU.js} +84 -84
  16. package/dist/assets/{pl-BFhTdei9.js → pl-DP_0oFey.js} +1 -1
  17. package/dist/assets/{pt-BR-Cw30xZ9f.js → pt-BR-BmQJZ1NW.js} +1 -1
  18. package/dist/assets/renderElectronMiniChatApp-DuNBYm_K.js +2 -0
  19. package/dist/assets/{uk-C6rZuAGS.js → uk-CrHgOUe5.js} +1 -1
  20. package/dist/assets/{vendor-.bun-kY4nnc4l.js → vendor-.bun-0geEbyBQ.js} +1 -1
  21. package/dist/assets/{zh-CN-bjbBXFpu.js → zh-CN-DyZ0csLN.js} +1 -1
  22. package/dist/index.html +4 -4
  23. package/dist/mini-chat.html +4 -4
  24. package/package.json +1 -1
  25. package/dist/assets/index-CX9TA5UH.js +0 -1
  26. package/dist/assets/main-Qzl_qZz0.js +0 -126
  27. package/dist/assets/miniChat-DO_5ziuU.js +0 -2
  28. package/dist/assets/renderElectronMiniChatApp-B6udecQK.js +0 -2
@@ -1 +1 @@
1
- import{R as n,j as a,ad as ht,eZ as bt,e_ as gt,e$ as xt,cl as ut,ce as ft,Q as vt,al as Tt,ao as kt,aE as Ct,aA as Et,$ as At,Z as Rt,bT as St,bU as It,d as Mt}from"./vendor-.bun-kY4nnc4l.js";import{u as pt,v as Bt,aX as Dt,c as Xe,L as Vt,bC as Pt,eB as jt,a as Se,b as Nt,V as dt,b5 as Lt,eC as Je,co as at,aq as Q}from"./modelPrefsAutoSave-BHV5Gay8.js";import{u as J,P as Ft,S as Kt}from"./main-Qzl_qZz0.js";import{a3 as Yt}from"./index-CX9TA5UH.js";import"./JsonTreeView-BhnwxlMV.js";function zt(f){const{colors:p}=f,m=p.syntax.base;return{background:p.surface.background,foreground:m.foreground,cursor:p.interactive.cursor,cursorAccent:p.surface.background,selectionBackground:p.interactive.selection,selectionForeground:p.interactive.selectionForeground,selectionInactiveBackground:p.interactive.selection+"50",black:p.surface.muted,red:p.status.error,green:p.status.success,yellow:p.status.warning,blue:m.function,magenta:m.keyword,cyan:m.type,white:m.foreground,brightBlack:m.comment,brightRed:p.status.error,brightGreen:p.status.success,brightYellow:p.status.warning,brightBlue:m.function,brightMagenta:m.keyword,brightCyan:m.type,brightWhite:p.surface.elevatedForeground}}function Ot(f,p,m,ee,fe=!1){const we=`${f}, "JetBrainsMonoNL Nerd Font", "FiraCode Nerd Font", "Cascadia Code PL", "Fira Code", "JetBrains Mono", "SFMono-Regular", Menlo, Consolas, "Liberation Mono", "Courier New", monospace`;return{cursorBlink:!1,cursorStyle:"bar",fontSize:p,lineHeight:1.15,fontFamily:we,allowTransparency:!1,theme:{background:m.background,foreground:m.foreground,cursor:m.cursor,cursorAccent:m.cursorAccent,selectionBackground:m.selectionBackground,selectionForeground:m.selectionForeground,black:m.black,red:m.red,green:m.green,yellow:m.yellow,blue:m.blue,magenta:m.magenta,cyan:m.cyan,white:m.white,brightBlack:m.brightBlack,brightRed:m.brightRed,brightGreen:m.brightGreen,brightYellow:m.brightYellow,brightBlue:m.brightBlue,brightMagenta:m.brightMagenta,brightCyan:m.brightCyan,brightWhite:m.brightWhite},scrollback:1e4,ghostty:ee,disableStdin:fe}}let ct=null;function Ht(){return ct||(ct=xt.load()),ct}function qt(f){if(typeof window>"u")return null;const p=[f,...Array.from(f.querySelectorAll("*"))];let m=null;for(const ee of p){const Ie=window.getComputedStyle(ee).overflowY;if(!(Ie!=="auto"&&Ie!=="scroll")){if(ee.scrollHeight-ee.clientHeight>2)return ee;m||(m=ee)}}return m}const mt=n.forwardRef(({sessionKey:f,chunks:p,onInput:m,onResize:ee,theme:fe,fontFamily:Ie,fontSize:we,className:Me,enableTouchScroll:E,autoFocus:et=!0,isVisible:je=!0},ye)=>{const{t:L}=pt(),V=n.useRef(null),Ne=n.useRef(null),I=n.useRef(null),Ue=n.useRef(null),j=n.useRef(m),Oe=n.useRef(ee),h=n.useRef(null),he=n.useRef(""),te=n.useRef(null),Le=n.useRef(!1),Fe=n.useRef(null),de=n.useRef(!0),ne=n.useRef(null),q=n.useRef(null),be=n.useRef(0),re=n.useRef(null),He=n.useRef(null),ae=n.useRef(!1),k=n.useRef(!1),A=n.useRef(null),pe=n.useRef(null),Ke=n.useRef(null),N=n.useRef(""),Ye=n.useRef(null),ge=n.useRef(!E),_e=n.useRef(je),[,tt]=n.useReducer(e=>e+1,0),[qe,z]=n.useReducer(e=>e+1,0);j.current=m,Oe.current=ee;const it=typeof navigator<"u"&&(/Android/i.test(navigator.userAgent)||navigator.userAgentData?.platform==="Android"),y=!!E;n.useEffect(()=>{if(!E){ge.current=!0,_e.current=je;return}!_e.current&&je&&(ge.current=!1),_e.current=je},[E,je]);const xe=n.useCallback(()=>{if(!y)return;const e=V.current,o=re.current;if(!e)return;const s=[];e.getAttribute("contenteditable")==="true"&&s.push(e),s.push(...Array.from(e.querySelectorAll('[contenteditable="true"]'))),s.forEach(r=>{r.setAttribute("data-terminal-disabled-contenteditable","true"),r.setAttribute("contenteditable","false"),r.setAttribute("aria-hidden","true"),r.tabIndex=-1,r.style.setProperty("caret-color","transparent"),r.style.color="transparent",r.style.setProperty("-webkit-text-fill-color","transparent"),r.style.background="transparent",r.style.outline="none",r.style.boxShadow="none",r.style.textShadow="none",r.style.setProperty("user-select","none"),r.style.setProperty("-webkit-user-select","none")}),e.tabIndex=-1,e.removeAttribute("role"),e.removeAttribute("aria-multiline"),Array.from(e.querySelectorAll("textarea")).forEach(r=>{r.style.setProperty("caret-color","transparent"),r.style.color="transparent",r.style.setProperty("-webkit-text-fill-color","transparent"),r.style.background="transparent",r.style.border="0",r.style.outline="none",r.style.boxShadow="none",r.style.textShadow="none",r.style.fontSize="0",r.style.lineHeight="0",r!==o&&r.getAttribute("data-terminal-disabled-input")!=="true"&&(r.setAttribute("data-terminal-disabled-input","true"),r.setAttribute("aria-hidden","true"),r.tabIndex=-1,r.disabled=!0,r.style.position="absolute",r.style.opacity="0",r.style.width="0px",r.style.height="0px",r.style.pointerEvents="none",r.style.zIndex="-1")})},[y]),R=n.useCallback(e=>{if(Ye.current===e)return;const o=I.current;if(o)try{if(typeof o.setOption=="function"){o.setOption("cursorBlink",e),Ye.current=e;return}o.options&&(o.options.cursorBlink=e,Ye.current=e)}catch{}},[]),M=y&&it,C=n.useCallback((e,o)=>{const s=M?He.current:re.current,c=V.current;if(!s||!c)return;const r=c.getBoundingClientRect(),v=typeof window<"u"?window.innerWidth:r.width,S=typeof window<"u"?window.innerHeight:r.height,D=r.left+r.width/2,Z=r.top+r.height-12,l=typeof e=="number"?e:D,T=typeof o=="number"?o:Z,P=8,O=Math.max(P,Math.min(v-P,l)),K=Math.max(P,Math.min(S-P,T));s.style.left=`${O}px`,s.style.top=`${K}px`,s.style.bottom="",(s instanceof HTMLTextAreaElement||s instanceof HTMLInputElement)&&(s.disabled=!1,s.readOnly=!1,s.removeAttribute("disabled"),s.removeAttribute("readonly"));try{s.focus({preventScroll:!0})}catch{try{s.focus()}catch{}}},[M]),ve=n.useCallback(()=>{if(y){C(),R(!0);return}I.current?.focus(),R(!0)},[C,R,y]),ce=n.useCallback(e=>e instanceof HTMLTextAreaElement||e instanceof HTMLInputElement?e.value:e.textContent??"",[]),W=n.useCallback(e=>{if(e instanceof HTMLTextAreaElement||e instanceof HTMLInputElement){e.value="";return}e.textContent=""},[]),ze=n.useCallback(e=>{if(typeof window>"u"||M)return;Ke.current!==null&&(window.clearTimeout(Ke.current),Ke.current=null);let o=0;const s=3,c=()=>{Ke.current=window.setTimeout(()=>{Ke.current=null;const r=ce(e);if(!r){if(o+=1,o<s){c();return}return}const v=N.current;N.current=r;const S=r.startsWith(v)?r.slice(v.length):r;S&&j.current(S.replace(/\r\n|\r|\n/g,"\r")),W(e),N.current=""},o===0?0:24)};c()},[W,ce,M]);n.useEffect(()=>{const e=V.current;if(!y||!e||E)return;const o=s=>{const c=s.target;if(c&&c.getAttribute("data-terminal-hidden-input")!=="true"&&e.contains(c)){try{c.blur()}catch{}C()}};return e.addEventListener("focusin",o,!0),()=>{e.removeEventListener("focusin",o,!0)}},[E,y,C]);const Be=n.useCallback(()=>{const e=I.current;if(!e||typeof e.getSelection!="function")return"";const o=e.getSelection();return typeof o=="string"?o:""},[]),le=n.useCallback(()=>{if(typeof window>"u")return"";const e=window.getSelection();if(!e)return"";const o=e.toString();if(!o.trim())return"";const s=V.current;if(!s)return"";const c=e.anchorNode,r=e.focusNode;return c&&!s.contains(c)||r&&!s.contains(r)?"":o},[]),Te=n.useCallback(async()=>{if(typeof document>"u")return;const e=Be()||le();e.trim()&&await Bt(e)},[le,Be]),X=n.useCallback(()=>Be().trim()?!0:!!le().trim(),[le,Be]);n.useEffect(()=>{if(typeof window>"u")return;const e=o=>{X()&&(o.preventDefault(),Te())};return window.addEventListener("openchamber:copy",e),()=>{window.removeEventListener("openchamber:copy",e)}},[Te,X]);const U=n.useCallback(()=>{he.current="",te.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(te.current),te.current=null,Le.current=!1,Fe.current=null},[]),F=n.useCallback(()=>{const e=Ue.current,o=I.current,s=V.current;if(!e||!o||!s)return;const c=s.getBoundingClientRect();if(!(c.width<24||c.height<24))try{e.fit();const r={cols:o.cols,rows:o.rows},v=h.current;(!v||v.cols!==r.cols||v.rows!==r.rows)&&(h.current=r,Oe.current(r.cols,r.rows))}catch{}},[]),De=n.useCallback(()=>{if(Le.current)return;const e=I.current;if(!e){U();return}if(!he.current)return;const o=he.current;he.current="",Le.current=!0,e.write(o,()=>{Le.current=!1,he.current&&(typeof window<"u"?te.current=window.requestAnimationFrame(()=>{te.current=null,De()}):De())})},[U]),$e=n.useCallback(()=>{te.current===null&&(typeof window<"u"?te.current=window.requestAnimationFrame(()=>{te.current=null,De()}):De())},[De]),We=n.useCallback(e=>{e&&(he.current+=e,$e())},[$e]),ke=n.useCallback(()=>{if(ne.current?.(),ne.current=null,q.current!==null&&typeof window<"u"&&(window.clearTimeout(q.current),q.current=null),!E){be.current=0;return}const e=V.current;if(!e)return;const o=I.current;if(!o)return;be.current=0;const s=2.2,c=2.8,r=25,v=.25,S=8,D=.05,Z=.015,l={lastY:null,lastTime:null,velocity:0,rafId:null,startX:null,startY:null,didMove:!1},T=()=>typeof performance<"u"?performance.now():Date.now(),P=Math.max(12,Math.round(we*1.35));let O=0;const K=t=>{if(!t)return!1;const u=o.getViewportY(),i=O+t,b=Math.trunc(i/P);return O=i-b*P,b!==0&&o.scrollLines(b),o.getViewportY()!==u},Y=()=>{l.rafId!==null&&typeof window<"u"&&window.cancelAnimationFrame(l.rafId),l.rafId=null},x={passive:!1,capture:!1};if(typeof window<"u"&&"PointerEvent"in window){const t=Object.assign(l,{pointerId:null,startX:null,startY:null,moved:!1}),u=6,i=d=>{if(d.pointerType==="touch"){Y(),t.pointerId=d.pointerId,t.startX=d.clientX,t.startY=d.clientY,t.moved=!1,t.lastY=d.clientY,t.lastTime=T(),t.velocity=0;try{e.setPointerCapture(d.pointerId)}catch{}}},b=d=>{if(d.pointerType!=="touch"||t.pointerId!==d.pointerId)return;if(t.startX!==null&&t.startY!==null&&!t.moved){const wt=d.clientX-t.startX,yt=d.clientY-t.startY;Math.hypot(wt,yt)>=u&&(t.moved=!0)}if(t.lastY===null){t.lastY=d.clientY,t.lastTime=T();return}const _=t.lastY,oe=t.lastTime??T(),$=T();t.lastY=d.clientY,t.lastTime=$;const ie=_-d.clientY;if(Math.abs(ie)<1)return;const Re=Math.max($-oe,8),se=s+Math.min(c,Math.abs(ie)/r),Pe=ie*se,Qe=Pe/Re;t.velocity=t.velocity*(1-v)+Qe*v,t.velocity>S?t.velocity=S:t.velocity<-S&&(t.velocity=-S),t.moved&&(d.cancelable&&d.preventDefault(),d.stopPropagation()),K(Pe)},w=d=>{if(d.pointerType!=="touch"||t.pointerId!==d.pointerId)return;const _=!t.moved;t.pointerId=null,t.startX=null,t.startY=null,t.moved=!1,t.lastY=null,t.lastTime=null;try{e.releasePointerCapture(d.pointerId)}catch{}if(_){y?C(d.clientX,d.clientY):E&&!ge.current&&(ge.current=!0,I.current?.focus());return}if(typeof window>"u")return;if(Math.abs(t.velocity)<D){t.velocity=0;return}let oe=T();const $=()=>{const ie=T(),Re=Math.max(ie-oe,8);oe=ie;const se=K(t.velocity*Re)??!1,Pe=Math.sign(t.velocity),Qe=Math.max(0,Math.abs(t.velocity)-Z*Re);if(t.velocity=Qe*Pe,!se||Qe<=D){Y(),t.velocity=0;return}t.rafId=window.requestAnimationFrame($)};t.rafId=window.requestAnimationFrame($)};e.addEventListener("pointerdown",i,x),e.addEventListener("pointermove",b,x),e.addEventListener("pointerup",w,x),e.addEventListener("pointercancel",w,x);const g=e.style.touchAction;e.style.touchAction="manipulation",ne.current=()=>{Y(),q.current!==null&&typeof window<"u"&&(window.clearTimeout(q.current),q.current=null),be.current=0,e.removeEventListener("pointerdown",i,x),e.removeEventListener("pointermove",b,x),e.removeEventListener("pointerup",w,x),e.removeEventListener("pointercancel",w,x),e.style.touchAction=g};return}const Ee=6,H=t=>{t.touches.length===1&&(Y(),l.lastY=t.touches[0].clientY,l.lastTime=T(),l.velocity=0,l.startX=t.touches[0].clientX,l.startY=t.touches[0].clientY,l.didMove=!1)},Ve=t=>{if(t.touches.length!==1){l.lastY=null,l.lastTime=null,l.velocity=0,l.startX=null,l.startY=null,l.didMove=!1,Y();return}const u=t.touches[0].clientX,i=t.touches[0].clientY;if(l.startX!==null&&l.startY!==null&&!l.didMove){const Re=u-l.startX,se=i-l.startY;Math.hypot(Re,se)>=Ee&&(l.didMove=!0)}if(l.lastY===null){l.lastY=i,l.lastTime=T();return}const b=l.lastY,w=l.lastTime??T(),g=T();l.lastY=i,l.lastTime=g;const d=b-i;if(Math.abs(d)<1)return;const _=Math.max(g-w,8),oe=s+Math.min(c,Math.abs(d)/r),$=d*oe,ie=$/_;l.velocity=l.velocity*(1-v)+ie*v,l.velocity>S?l.velocity=S:l.velocity<-S&&(l.velocity=-S),l.didMove&&(t.preventDefault(),t.stopPropagation()),K($)},Ae=t=>{const u=!l.didMove;l.lastY=null,l.lastTime=null;const i=l.velocity;if(l.startX=null,l.startY=null,l.didMove=!1,u){const g=t.changedTouches?.[0];y?C(g?.clientX,g?.clientY):E&&!ge.current&&(ge.current=!0,I.current?.focus());return}if(typeof window>"u")return;if(Math.abs(i)<D){l.velocity=0;return}let b=T();const w=()=>{const g=T(),d=Math.max(g-b,8);b=g;const _=K(l.velocity*d)??!1,oe=Math.sign(l.velocity),$=Math.max(0,Math.abs(l.velocity)-Z*d);if(l.velocity=$*oe,!_||$<=D){Y(),l.velocity=0;return}l.rafId=window.requestAnimationFrame(w)};l.rafId=window.requestAnimationFrame(w)};e.addEventListener("touchstart",H,x),e.addEventListener("touchmove",Ve,x),e.addEventListener("touchend",Ae,x),e.addEventListener("touchcancel",Ae,x);const G=e.style.touchAction;e.style.touchAction="manipulation",ne.current=()=>{Y(),q.current!==null&&typeof window<"u"&&(window.clearTimeout(q.current),q.current=null),be.current=0,e.removeEventListener("touchstart",H,x),e.removeEventListener("touchmove",Ve,x),e.removeEventListener("touchend",Ae,x),e.removeEventListener("touchcancel",Ae,x),e.style.touchAction=G}},[E,y,C,we]);n.useEffect(()=>{let e=!1,o=null,s=null,c=null,r=[],v=null,S=null;const D=V.current;if(!D)return;if(D.tabIndex=y?-1:0,y){const Y=D.focus.bind(D),x=D;x.focus=((...B)=>{C()}),S=()=>{x.focus=Y}}const Z=()=>{R(!0)},l=()=>{R(!1)},T=Y=>{const x=Y.target;if(x&&D.contains(x)){if(y&&x instanceof HTMLElement){window.setTimeout(()=>{x.blur(),C()},0),R(!1);return}if(E&&!ge.current&&x instanceof HTMLElement){window.setTimeout(()=>{x.blur()},0),R(!1);return}R(!0);return}R(!1)},P=()=>{R(!1)};let O=null;return(async()=>{try{const Y=await Ht();if(e)return;const x=Ot(Ie,we,fe,Y,!1),B=new bt(x);de.current=!0,y&&(B.focus=()=>{});const Ee=B;if(typeof Ee.scrollToBottom=="function"){const G=Ee.scrollToBottom.bind(Ee);Ee.scrollToBottom=()=>{de.current&&G()},v=()=>{Ee.scrollToBottom=G}}const H=new gt;o=B,I.current=B,Ue.current=H,B.loadAddon(H),B.open(D),z(),Ye.current=!1,O=B.textarea??D.querySelector("textarea"),O&&(O.addEventListener("focus",Z),O.addEventListener("blur",l)),xe(),typeof MutationObserver<"u"&&(c=new MutationObserver(()=>{xe()}),c.observe(D,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["contenteditable","role","tabindex","aria-label"]}));const Ve=qt(D);Ve?(Ve.classList.add("overlay-scrollbar-target","overlay-scrollbar-container"),Ne.current=Ve,tt()):Ne.current=null,F();const Ae=H;typeof Ae.observeResize=="function"&&Ae.observeResize(),ke(),r=[B.onData(G=>{j.current(G)}),B.onScroll(G=>{if(typeof G=="number"&&Number.isFinite(G)){const t=typeof B.hasSelection=="function"&&B.hasSelection();de.current=!t&&G<=.5}}),B.onSelectionChange(()=>{if(typeof B.hasSelection=="function"&&B.hasSelection()){de.current=!1;return}const t=typeof B.getViewportY=="function"?B.getViewportY():0;de.current=t<=.5})],s=new ResizeObserver(()=>{F()}),s.observe(D),typeof window<"u"&&window.setTimeout(()=>{F()},0)}catch{}})(),document.addEventListener("focusin",T,!0),window.addEventListener("blur",P),()=>{e=!0,ne.current?.(),ne.current=null,document.removeEventListener("focusin",T,!0),window.removeEventListener("blur",P),r.forEach(Y=>Y.dispose()),v?.(),v=null,O&&(O.removeEventListener("focus",Z),O.removeEventListener("blur",l)),s?.disconnect(),c?.disconnect(),S?.(),o?.dispose(),I.current=null,Ue.current=null,Ne.current=null,h.current=null,Ye.current=null,U()}},[xe,E,F,C,Ie,we,ke,fe,U,R,y]),n.useEffect(()=>{const e=I.current;e&&(e.reset(),U(),h.current=null,F())},[f,qe,F,U]),n.useEffect(()=>{!et||!I.current||ve()},[et,ve,f,qe]),n.useEffect(()=>(ke(),()=>{ne.current?.(),ne.current=null}),[ke,f]),n.useEffect(()=>{const e=I.current;if(!e)return;if(p.length===0){Fe.current!==null&&(e.reset(),U(),F());return}const o=Fe.current;let s;if(o===null)s=p;else{const c=p.findIndex(r=>r.id===o);s=c>=0?p.slice(c+1):p}s.length>0&&We(s.map(c=>c.data).join("")),Fe.current=p[p.length-1].id},[p,qe,We,F,U]),n.useImperativeHandle(ye,()=>({focus:()=>{ve()},clear:()=>{const e=I.current;e&&(e.reset(),U(),F())},fit:()=>{F()}}),[ve,F,U]);const Ze=n.useCallback(e=>{if(!y)return;const o=V.current,s=e.relatedTarget,c=s?.tagName,r=c==="INPUT"||c==="TEXTAREA"||s?.isContentEditable,v=s?.getAttribute("data-terminal-hidden-input")==="true",S=!!(s&&o?.contains(s))},[y]),me=n.useCallback(e=>{const o=e.nativeEvent,s=o?.inputType??"",c=typeof o?.data=="string"?o.data:"";if(pe.current=typeof performance<"u"?performance.now():Date.now(),s==="insertCompositionText"){ae.current=!0;return}if(!s&&c){if(ae.current)return;e.preventDefault(),j.current(c),A.current={type:"insertText",at:typeof performance<"u"?performance.now():Date.now()},k.current=!0;return}if(s==="insertText"&&c){if(ae.current)return;e.preventDefault(),j.current(c),A.current={type:s,at:typeof performance<"u"?performance.now():Date.now()},k.current=!0;return}if(s==="insertLineBreak"){if(ae.current)return;e.preventDefault(),j.current("\r"),A.current={type:s,at:typeof performance<"u"?performance.now():Date.now()},k.current=!0;return}if(s==="deleteContentBackward"){if(ae.current)return;e.preventDefault(),j.current(""),A.current={type:s,at:typeof performance<"u"?performance.now():Date.now()},k.current=!0}},[]),ue=n.useCallback(e=>{const o=e.currentTarget;if(pe.current=typeof performance<"u"?performance.now():Date.now(),ae.current)return;if(k.current){const r=A.current,v=typeof performance<"u"?performance.now():Date.now();if(r&&v-r.at<50){k.current=!1,W(o);return}k.current=!1}const s=ce(o);if(!s)return;N.current=s;const c=s.replace(/\r\n|\r|\n/g,"\r");j.current(c),W(o),N.current=""},[W,ce]),nt=n.useCallback(e=>{e.stopPropagation();const o=e.key.toLowerCase(),s=e.metaKey&&!e.ctrlKey&&!e.altKey&&o==="c",c=e.ctrlKey&&e.shiftKey&&!e.metaKey&&!e.altKey&&o==="c";if((s||c)&&X()){e.preventDefault(),Te();return}if(e.ctrlKey&&!e.metaKey&&!e.altKey&&e.key.length===1){const P=e.key.toUpperCase();if(P>="A"&&P<="Z"){e.preventDefault(),e.nativeEvent?.stopImmediatePropagation(),j.current(String.fromCharCode(P.charCodeAt(0)-64)),W(e.currentTarget);return}}if(e.altKey&&!e.ctrlKey&&!e.metaKey&&e.key.length===1){e.preventDefault(),e.nativeEvent?.stopImmediatePropagation(),j.current("\x1B"+e.key),W(e.currentTarget);return}const v={ArrowUp:"\x1B[A",ArrowDown:"\x1B[B",ArrowRight:"\x1B[C",ArrowLeft:"\x1B[D",Escape:"\x1B",Tab:" ",Delete:"\x1B[3~",Home:"\x1B[H",End:"\x1B[F"}[e.key];if(v){e.preventDefault(),j.current(v),W(e.currentTarget);return}const S=e.currentTarget;if(e.nativeEvent?.isComposing)return;const Z=A.current,l=typeof performance<"u"?performance.now():Date.now(),T=!!(Z&&l-Z.at<50);if(e.key==="Enter"){if(T&&Z?.type==="insertLineBreak")return;e.preventDefault(),j.current("\r"),W(S);return}if(e.key==="Backspace"){if(e.preventDefault(),T&&Z?.type==="deleteContentBackward")return;ce(S)||j.current("")}if(e.key.length===1&&!e.ctrlKey&&!e.metaKey&&!e.altKey){const P=pe.current;P&&l-P<50||(e.preventDefault(),j.current(e.key),k.current=!0,A.current={type:"keydown-text",at:l})}ze(S)},[W,Te,X,ce,ze]),Ce=n.useCallback(e=>{e.stopPropagation();const o=e.currentTarget;e.nativeEvent?.isComposing||ze(o)},[ze]),rt=n.useCallback(e=>{const o=e.currentTarget;ae.current=!1;const s=e.data||ce(o);if(pe.current=typeof performance<"u"?performance.now():Date.now(),!s)return;const c=s.replace(/\r\n|\r|\n/g,"\r");j.current(c),W(o),A.current={type:"compositionend",at:typeof performance<"u"?performance.now():Date.now()},k.current=!0},[W,ce]),ot=n.useCallback(e=>{e.stopPropagation();const o=e.clipboardData?.getData("text")??"";if(!o)return;e.preventDefault();const c=I.current?.hasBracketedPaste?.()?`\x1B[200~${o}\x1B[201~`:o;j.current(c)},[]),Ge={position:"fixed",left:0,top:0,width:1,height:1,opacity:0,zIndex:-1,background:"transparent",color:"transparent",WebkitTextFillColor:"transparent",caretColor:"transparent",textShadow:"none",WebkitAppearance:"none",appearance:"none",resize:"none",overflow:"hidden",whiteSpace:"nowrap",border:"0",padding:0,margin:0,outline:"none",outlineOffset:0,fontSize:16,fontWeight:400,pointerEvents:"none",WebkitUserSelect:"none",userSelect:"none"};return a.jsxs("div",{ref:V,className:Xe("relative h-full w-full terminal-viewport-container",Me),"data-hidden-input-overlay-active":y?"true":void 0,style:{backgroundColor:fe.background},onTouchStart:e=>{if(!(!y||E)&&!X()){const o=e.touches?.[0];C(o?.clientX,o?.clientY)}},onClick:e=>{if(!E)if(y){if(X())return;C(e.clientX,e.clientY)}else I.current?.focus()},onMouseUp:()=>{!E&&X()&&Te()},onTouchEnd:()=>{!E&&X()&&Te()},children:[y&&typeof document<"u"?ht.createPortal(a.jsxs(a.Fragment,{children:[a.jsx("input",{ref:He,type:"text",inputMode:"text",autoCapitalize:"off",autoComplete:"off",autoCorrect:"off",spellCheck:!1,tabIndex:-1,enterKeyHint:"send","data-terminal-hidden-input":"true","aria-label":L("terminalView.viewport.inputAria"),"aria-hidden":"true",style:{...Ge,display:M?"block":"none"},onBlur:Ze,onBeforeInput:me,onCompositionStart:()=>{ae.current=!0},onInput:ue,onKeyDown:nt,onKeyUp:Ce,onCompositionEnd:rt,onPaste:ot}),a.jsx("textarea",{ref:re,inputMode:"text",autoCapitalize:"off",autoComplete:"off",autoCorrect:"off",spellCheck:!1,tabIndex:-1,enterKeyHint:"send","data-terminal-hidden-input":"true","aria-label":L("terminalView.viewport.inputAria"),"aria-hidden":"true",style:{...Ge,display:M?"none":"block"},onBlur:Ze,onBeforeInput:me,onCompositionStart:()=>{ae.current=!0},onInput:ue,onKeyDown:nt,onKeyUp:Ce,onCompositionEnd:rt,onPaste:ot})]}),document.body):null,Ne.current&&!E?a.jsx(Dt,{containerRef:Ne,disableHorizontal:!0,className:"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero"}):null]})});mt.displayName="TerminalViewport";const Wt={esc:"\x1B",tab:" ",enter:"\r","arrow-up":"\x1B[A","arrow-down":"\x1B[B","arrow-left":"\x1B[D","arrow-right":"\x1B[C"},st={ctrl:"5",cmd:"3"},lt={retry:{maxRetries:3,initialDelayMs:500,maxDelayMs:8e3},connectionTimeoutMs:1e4},Xt={retry:{...lt.retry,initialDelayMs:200,maxDelayMs:500},connectionTimeoutMs:1500},Ut=(f,p)=>{if(p)switch(f){case"arrow-up":return`\x1B[1;${st[p]}A`;case"arrow-down":return`\x1B[1;${st[p]}B`;case"arrow-right":return`\x1B[1;${st[p]}C`;case"arrow-left":return`\x1B[1;${st[p]}D`}return Wt[f]??null},Jt=()=>{const{t:f}=pt(),{terminal:p,runtime:m}=Vt(),{currentTheme:ee}=Pt(),{monoFont:fe}=jt(),Ie=Se(t=>t.terminalFontSize),we=Se(t=>t.bottomTerminalHeight),Me=Se(t=>t.isBottomTerminalExpanded),{isMobile:E,isTablet:et,hasTouchOnlyPointer:je}=Nt(),ye=E||et,L=(ye||je)&&m.platform==="web",V=m.platform!=="vscode",Ne=Se(t=>t.showTerminalQuickKeysOnDesktop),I=ye||Ne,Ue=dt(t=>t.currentSessionId),j=dt(t=>t.newSessionDraft),Oe=Ue!==null||j?.open===!0,h=Lt()??null,he=J(t=>t.sessions),te=J(t=>t.hasHydrated),Le=J(t=>t.ensureDirectory),Fe=J(t=>t.createTab),de=J(t=>t.setActiveTab),ne=J(t=>t.closeTab),q=J(t=>t.setTabSessionId),be=J(t=>t.setTabLifecycle),re=J(t=>t.setConnecting),He=J(t=>t.appendToBuffer),ae=Se(t=>t.openContextPreview),k=n.useMemo(()=>{if(h)return he.get(h)},[he,h]),A=n.useMemo(()=>k?V?k.activeTabId??k.tabs[0]?.id??null:k.tabs[0]?.id??null:null,[k,V]),pe=n.useMemo(()=>{if(k)return A?k.tabs.find(t=>t.id===A)??k.tabs[0]:k.tabs[0]},[k,A]),Ke=n.useMemo(()=>(k?.tabs??[]).map(t=>({icon:(()=>{const u=t.iconKey?Ft[t.iconKey]??ut:ut;return a.jsx(u,{className:"h-4 w-4"})})(),id:t.id,label:t.label,title:t.label,closeLabel:f("terminalView.tabs.closeTabTitle")})),[k?.tabs,f]),N=pe?.terminalSessionId??null,Ye=pe?.lifecycle??"idle",ge=pe?.bufferChunks??[],_e=pe?.isConnecting??!1,tt=pe?.previewUrl??null,[qe,z]=n.useState(null),[it,y]=n.useState(!1),[xe,R]=n.useState(!1),[M,C]=n.useState(null),[ve,ce]=n.useState(!1),[W,ze]=n.useState(0),Be=n.useRef(null),le=n.useRef(null),Te=n.useRef(A),X=n.useRef(N),U=n.useRef(h),F=n.useRef(null),De=n.useRef(null),$e=n.useRef(!1),We=n.useRef(null),ke=n.useRef(new Set),Ze=n.useRef(!1),me=n.useCallback(()=>{L||typeof document<"u"&&!document.hasFocus()||F.current?.focus()},[L]),ue=n.useCallback(()=>{L||F.current?.focus()},[L]);n.useEffect(()=>{if(!te||Ze.current)return;Ze.current=!0;const t=new Set;for(const[,u]of J.getState().sessions.entries())for(const i of u.tabs)i.terminalSessionId&&t.add(i.terminalSessionId);ke.current=t},[te]);const nt=Se(t=>t.activeMainTab),Ce=Se(t=>t.isBottomTerminalOpen),rt=Se(t=>t.setBottomTerminalOpen),ot=Se(t=>t.setBottomTerminalExpanded),Ge=nt==="terminal",e=Ge||Ce,[o,s]=n.useState(e);n.useEffect(()=>{!e||m.platform==="vscode"||Yt()},[e,m.platform]),n.useEffect(()=>{e&&s(!0)},[e]),n.useEffect(()=>{$e.current=e},[e]),n.useEffect(()=>{X.current=N},[N]),n.useEffect(()=>{Te.current=A},[A]),n.useEffect(()=>{U.current=h},[h]),n.useEffect(()=>{!I&&M!==null&&C(null)},[I,M,C]),n.useEffect(()=>{!N&&M!==null&&C(null)},[N,M,C]);const c=n.useCallback(()=>{Be.current?.(),Be.current=null,le.current=null,R(!1)},[]);n.useEffect(()=>()=>{c(),X.current=null},[c]);const r=n.useCallback((t,u,i,b=lt)=>{if(le.current===i)return;c(),le.current=i;const w=p.connect(i,{onEvent:g=>{if(le.current===i)switch(g.type){case"connected":{re(t,u,!1),z(null),y(!1),R(!1),me(),We.current===i&&(We.current=null,p.sendInput(i,"\r").catch(()=>{}));break}case"reconnecting":{z(null),y(!1),R(!0);break}case"data":{g.data&&He(t,u,g.data);break}case"exit":{const d=typeof g.exitCode=="number"?g.exitCode:null,_=typeof g.signal=="number"?g.signal:null,$=!!J.getState().getDirectoryState(t)?.tabs.find(ie=>ie.id===u)?.label?.startsWith("Action:");He(t,u,f("terminalView.stream.processExitedMessage",{exitCodeSegment:d!==null?f("terminalView.stream.processExitedWithCode",{exitCode:d}):"",signalSegment:_!==null?f("terminalView.stream.processExitedWithSignal",{signal:_}):""})),be(t,u,"exited"),q(t,u,null),re(t,u,!1),z($?null:f("terminalView.error.sessionEnded")),y(!1),R(!1),c();break}}},onError:(g,d)=>{if(le.current===i){if(!d){z(null),y(!1);return}R(!1),z(f("terminalView.error.connectionFailed",{message:g.message})),y(!0),re(t,u,!1),be(t,u,"exited"),q(t,u,null),c()}}},b);Be.current=()=>{w.close(),le.current=null}},[He,c,me,re,be,q,f,p]);n.useEffect(()=>{let t=!1;if(!te||!o)return;if(!h){z(f(Oe?"terminalView.empty.noWorkingDirectory":"terminalView.empty.selectSession")),c();return}return(async()=>{const i=h;if(!U.current||U.current!==i)return;Le(i);const b=J.getState().getDirectoryState(i);if(!b||b.tabs.length===0)return;const w=V?b.activeTabId??b.tabs[0]?.id??null:b.tabs[0]?.id??null;if(!w)return;const g=b.tabs.find(se=>se.id===w)??b.tabs[0];let d=g?.terminalSessionId??null;const _=g?.lifecycle??"idle",oe=!!g?.label?.startsWith("Action:"),$=(g?.bufferLength??0)>0||(g?.bufferChunks?.length??0)>0,ie=!!d&&ke.current.has(d)&&(g?.bufferLength??0)===0&&(g?.bufferChunks?.length??0)===0,Re=!!d&&ke.current.has(d);if(!d){if(_==="exited"){re(i,w,!1);return}if(oe&&$){re(i,w,!1);return}z(null),y(!1),R(!1),re(i,w,!0);try{const se=De.current,Pe=await p.createSession({cwd:i,cols:se?.cols,rows:se?.rows});if(!(!t&&U.current===i&&Te.current===w)){try{await p.close(Pe.sessionId)}catch{}return}q(i,w,Pe.sessionId),d=Pe.sessionId}catch(se){t||(z(se instanceof Error?se.message:f("terminalView.error.startSessionFailed")),y(!0),R(!1),re(i,w,!1));return}}!d||t||(X.current=d,Re&&ke.current.delete(d),ie&&(We.current=d),r(i,w,d,Re?Xt:lt))})(),()=>{t=!0,X.current=null,c()}},[Oe,h,N,Ye,A,o,V,te,Le,re,be,q,r,c,f,p]),n.useEffect(()=>{if(!e||L)return;if(typeof window>"u"){me();return}const t=window.requestAnimationFrame(()=>{me()});return()=>{window.cancelAnimationFrame(t)}},[A,me,e,L]);const v=n.useCallback(async()=>{if(!h||ve)return;const t=J.getState().getDirectoryState(h),u=V?A??t?.activeTabId??t?.tabs[0]?.id??null:t?.tabs[0]?.id??null;if(u){ce(!0),z(null),y(!1),R(!1),c();try{await ne(h,u)}catch(i){z(i instanceof Error?i.message:f("terminalView.error.restartFailed")),y(!0),R(!1)}finally{ce(!1)}}},[A,ne,c,h,V,ve,f]),S=n.useCallback(async()=>{await v()},[v]),D=n.useCallback(()=>{if(!h)return;const t=Fe(h);de(h,t),z(null),y(!1),R(!1),c()},[Fe,c,h,de]),Z=n.useCallback(t=>{h&&(de(h,t),z(null),y(!1),R(!1),c())},[c,h,de]),l=n.useCallback(t=>{h&&(t===A&&c(),z(null),y(!1),R(!1),ne(h,t))},[A,ne,c,h]),T=n.useCallback(t=>{if(!t||xe)return;let u=t,i=!1;if(M&&t.length>0){const w=t[0];if(w.length===1&&/[a-zA-Z]/.test(w)){const g=w.toUpperCase();(M==="ctrl"||M==="cmd")&&(u=String.fromCharCode(g.charCodeAt(0)&31),i=!0)}i||(i=!0)}const b=X.current;b&&(p.sendInput(b,u).catch(w=>{xe||z(w instanceof Error?w.message:f("terminalView.error.sendInputFailed"))}),i&&(C(null),ue()))},[M,ue,xe,C,f,p]),P=n.useCallback((t,u)=>{if(De.current={cols:t,rows:u},!$e.current)return;const i=X.current;i&&p.resize({sessionId:i,cols:t,rows:u}).catch(()=>{})},[p]),O=n.useCallback(t=>{C(u=>u===t?null:t),ue()},[ue,C]),K=n.useCallback(t=>{const u=Ut(t,M);u&&(T(u),C(null),ue())},[M,ue,T,C]);n.useEffect(()=>{if(!I||!M||!N)return;const t=u=>{if(u.repeat)return;const i=u.key;if(!i||i==="Control"||i==="Meta"||i==="Alt"||i==="Shift")return;const b=i.length===1?i.toLowerCase():i,w=u.code??"",g=w.startsWith("Key")&&w.length===4?w.slice(3).toUpperCase():null,d=i.length===1&&/[a-zA-Z]/.test(i)?i.toUpperCase():g,_={Tab:"tab",Enter:"enter",ArrowUp:"arrow-up",ArrowDown:"arrow-down",ArrowLeft:"arrow-left",ArrowRight:"arrow-right",Escape:"esc",tab:"tab",enter:"enter",arrowup:"arrow-up",arrowdown:"arrow-down",arrowleft:"arrow-left",arrowright:"arrow-right",escape:"esc"};if(b in _){u.preventDefault(),u.stopPropagation(),K(_[b]);return}if(M==="ctrl"&&d&&d.length===1&&d>="A"&&d<="Z"){const oe=String.fromCharCode(d.charCodeAt(0)&31);u.preventDefault(),u.stopPropagation(),T(oe),C(null),ue()}};return window.addEventListener("keydown",t),()=>{window.removeEventListener("keydown",t)}},[M,K,T,ue,I,C,N]);const Y=n.useMemo(()=>{const t=Je[at].stack;if(typeof window>"u")return(Je[fe]??Je[at]).stack;const i=window.getComputedStyle(document.documentElement).getPropertyValue("--font-family-mono");return i&&i.trim().length>0?i.trim():(Je[fe]??Je[at]).stack??t},[fe]),x=n.useMemo(()=>zt(ee),[ee]),B=n.useMemo(()=>`${h??"no-dir"}::${A??"no-tab"}::${N??"no-terminal"}`,[h,A,N]),Ee=n.useMemo(()=>`${B}::layout-${W}`,[B,W]);if(n.useEffect(()=>{if(L||!Ce||!e)return;if(typeof window>"u"){ze(u=>u+1);return}const t=window.setTimeout(()=>{ze(u=>u+1)},140);return()=>{window.clearTimeout(t)}},[we,Me,Ce,e,L]),n.useEffect(()=>{if(!e||L)return;const t=F.current;if(!t)return;const u=()=>{t.fit()};if(typeof window<"u"){const i=window.requestAnimationFrame(()=>{u(),me()}),b=[220,400].map(w=>window.setTimeout(u,w));return()=>{window.cancelAnimationFrame(i),b.forEach(w=>window.clearTimeout(w))}}u()},[me,e,L,B,N]),n.useEffect(()=>{if(L||!e||!Ce)return;const t=F.current;if(!t)return;const u=()=>{t.fit()};if(typeof window<"u"){const i=window.requestAnimationFrame(()=>{u()}),b=[0,80,180,320].map(w=>window.setTimeout(u,w));return()=>{window.cancelAnimationFrame(i),b.forEach(w=>window.clearTimeout(w))}}u()},[we,Me,Ce,e,L]),!Oe)return a.jsx("div",{className:"flex h-full items-center justify-center p-4 text-center text-sm text-muted-foreground",children:f("terminalView.empty.selectSession")});if(!h)return a.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 p-4 text-center text-sm text-muted-foreground",children:[a.jsx("p",{children:f("terminalView.empty.noWorkingDirectoryForSession")}),a.jsx("button",{onClick:v,className:"rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90",children:f("terminalView.actions.retry")})]});const H=!N||_e||ve||xe,Ve=o,Ae=!ye&&Ce&&!Ge,G=a.jsxs(a.Fragment,{children:[a.jsx(Q,{type:"button",size:"sm",variant:"outline",className:"h-6 px-2 text-xs",onClick:()=>K("esc"),disabled:H,children:f("terminalView.quickKeys.escape")}),a.jsxs(Q,{type:"button",size:"sm",variant:"outline",className:"h-6 w-9 p-0",onClick:()=>K("tab"),disabled:H,children:[a.jsx(ft,{size:16}),a.jsx("span",{className:"sr-only",children:f("terminalView.quickKeys.tabAria")})]}),a.jsxs(Q,{type:"button",size:"sm",variant:"chip","aria-pressed":M==="ctrl",className:"h-6 w-9 p-0",onClick:()=>O("ctrl"),disabled:H,children:[a.jsx("span",{className:"text-xs font-medium",children:f("terminalView.quickKeys.controlLabel")}),a.jsx("span",{className:"sr-only",children:f("terminalView.quickKeys.controlModifierAria")})]}),a.jsxs(Q,{type:"button",size:"sm",variant:"chip","aria-pressed":M==="cmd",className:"h-6 w-9 p-0",onClick:()=>O("cmd"),disabled:H,children:[a.jsx(vt,{size:16}),a.jsx("span",{className:"sr-only",children:f("terminalView.quickKeys.commandModifierAria")})]}),a.jsxs(Q,{type:"button",size:"sm",variant:"outline",className:"h-6 w-9 p-0",onClick:()=>K("arrow-up"),disabled:H,children:[a.jsx(Tt,{size:16}),a.jsx("span",{className:"sr-only",children:f("terminalView.quickKeys.arrowUpAria")})]}),a.jsxs(Q,{type:"button",size:"sm",variant:"outline",className:"h-6 w-9 p-0",onClick:()=>K("arrow-left"),disabled:H,children:[a.jsx(kt,{size:16}),a.jsx("span",{className:"sr-only",children:f("terminalView.quickKeys.arrowLeftAria")})]}),a.jsxs(Q,{type:"button",size:"sm",variant:"outline",className:"h-6 w-9 p-0",onClick:()=>K("arrow-down"),disabled:H,children:[a.jsx(Ct,{size:16}),a.jsx("span",{className:"sr-only",children:f("terminalView.quickKeys.arrowDownAria")})]}),a.jsxs(Q,{type:"button",size:"sm",variant:"outline",className:"h-6 w-9 p-0",onClick:()=>K("arrow-right"),disabled:H,children:[a.jsx(ft,{size:16}),a.jsx("span",{className:"sr-only",children:f("terminalView.quickKeys.arrowRightAria")})]}),a.jsxs(Q,{type:"button",size:"sm",variant:"outline",className:"h-6 w-9 p-0",onClick:()=>K("enter"),disabled:H,children:[a.jsx(Et,{size:16}),a.jsx("span",{className:"sr-only",children:f("terminalView.quickKeys.enterAria")})]})]});return a.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-[var(--surface-background)]",children:[a.jsxs("div",{className:Xe("app-region-no-drag sticky top-0 z-20 shrink-0 bg-[var(--surface-background)] text-xs",ye?"px-3 py-1.5":"pl-3 pr-1.5 py-1"),children:[V&&k?a.jsxs("div",{className:"flex items-center gap-2 pl-1 pr-1",children:[a.jsx("div",{className:Xe("min-w-0 flex-1",ye?"h-8":"h-7"),children:a.jsx(Kt,{items:Ke,activeId:A,onSelect:Z,onClose:l,layoutMode:"scrollable",variant:"default",className:"h-full bg-transparent"})}),a.jsx(Q,{type:"button",size:"xs",variant:"ghost",className:Xe("shrink-0",ye?"h-8 w-8 p-0":"h-7 w-7 p-0"),onClick:D,title:f("terminalView.tabs.newTabTitle"),children:a.jsx(At,{size:ye?18:16})}),a.jsxs("div",{className:"flex shrink-0 items-center gap-1 overflow-visible",children:[tt?a.jsxs(Q,{type:"button",size:"xs",variant:"outline",className:"h-6 shrink-0 gap-1 px-2",onClick:()=>{h&&ae(h,tt)},title:f("terminalView.preview.openTitle"),children:[a.jsx(Rt,{className:"h-3.5 w-3.5 shrink-0"}),a.jsx("span",{className:"whitespace-nowrap",children:f("terminalView.preview.open")})]}):null,Ae?a.jsxs(a.Fragment,{children:[a.jsx(Q,{type:"button",size:"xs",variant:"ghost",onClick:()=>ot(!Me),className:Xe("shrink-0 p-0",E?"h-8 w-8":"h-7 w-7"),title:f(Me?"terminalView.bottomDock.restoreTitle":"terminalView.bottomDock.expandTitle"),"aria-label":f(Me?"terminalView.bottomDock.restoreAria":"terminalView.bottomDock.expandAria"),children:Me?a.jsx(St,{className:"h-4 w-4"}):a.jsx(It,{className:"h-4 w-4"})}),a.jsx(Q,{type:"button",size:"xs",variant:"ghost",onClick:()=>rt(!1),className:Xe("shrink-0 p-0",E?"h-8 w-8":"h-7 w-7"),title:f("terminalView.bottomDock.closeTitle"),"aria-label":f("terminalView.bottomDock.closeAria"),children:a.jsx(Mt,{className:"h-4 w-4"})})]}):null]})]}):null,!E&&I&&V&&k?a.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-1 pl-1 pr-1",children:G}):null,I&&(E||!V||!k)?a.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-1",children:G}):null]}),a.jsxs("div",{className:"relative flex-1 overflow-hidden",style:{backgroundColor:x.background},children:[a.jsx("div",{className:"h-full w-full box-border pl-4 pr-1.5 pt-3 pb-4",children:Ve?a.jsx(mt,{ref:t=>{F.current=t},sessionKey:Ee,chunks:ge,onInput:T,onResize:P,theme:x,fontFamily:Y,fontSize:Ie,enableTouchScroll:L,autoFocus:!L&&e,isVisible:e}):null}),!xe&&qe&&a.jsxs("div",{className:"absolute inset-x-0 bottom-0 bg-[var(--status-error-background)] px-3 py-2 text-xs text-[var(--status-error-foreground)] flex items-center justify-between gap-2",children:[a.jsx("span",{children:qe}),it&&E&&a.jsx(Q,{size:"sm",variant:"secondary",className:"h-6 px-2 py-0 text-xs",onClick:S,disabled:ve,title:f("terminalView.actions.hardRestartTitle"),type:"button",children:f("terminalView.actions.hardRestart")})]})]})]})};export{Jt as TerminalView};
1
+ import{R as n,j as a,aa as ht,eZ as bt,e_ as gt,e$ as xt,cj as ut,cc as ft,J as vt,ai as Tt,al as kt,aB as Ct,ax as Et,X as Rt,V as At,bQ as St,bR as It,d as Mt}from"./vendor-.bun-0geEbyBQ.js";import{u as pt,v as Bt,aY as Dt,c as Xe,L as Vt,bD as jt,eD as Pt,a as Se,b as Nt,U as dt,b6 as Lt,eE as Je,cp as at,ar as Z}from"./modelPrefsAutoSave-DlTpduDU.js";import{u as J,P as Ft,S as Kt}from"./main-BRTUWU3R.js";import{a3 as Yt}from"./index-DqXJOAVZ.js";import"./JsonTreeView-DjN_Y61c.js";function zt(f){const{colors:p}=f,m=p.syntax.base;return{background:p.surface.background,foreground:m.foreground,cursor:p.interactive.cursor,cursorAccent:p.surface.background,selectionBackground:p.interactive.selection,selectionForeground:p.interactive.selectionForeground,selectionInactiveBackground:p.interactive.selection+"50",black:p.surface.muted,red:p.status.error,green:p.status.success,yellow:p.status.warning,blue:m.function,magenta:m.keyword,cyan:m.type,white:m.foreground,brightBlack:m.comment,brightRed:p.status.error,brightGreen:p.status.success,brightYellow:p.status.warning,brightBlue:m.function,brightMagenta:m.keyword,brightCyan:m.type,brightWhite:p.surface.elevatedForeground}}function Ot(f,p,m,ee,fe=!1){const we=`${f}, "JetBrainsMonoNL Nerd Font", "FiraCode Nerd Font", "Cascadia Code PL", "Fira Code", "JetBrains Mono", "SFMono-Regular", Menlo, Consolas, "Liberation Mono", "Courier New", monospace`;return{cursorBlink:!1,cursorStyle:"bar",fontSize:p,lineHeight:1.15,fontFamily:we,allowTransparency:!1,theme:{background:m.background,foreground:m.foreground,cursor:m.cursor,cursorAccent:m.cursorAccent,selectionBackground:m.selectionBackground,selectionForeground:m.selectionForeground,black:m.black,red:m.red,green:m.green,yellow:m.yellow,blue:m.blue,magenta:m.magenta,cyan:m.cyan,white:m.white,brightBlack:m.brightBlack,brightRed:m.brightRed,brightGreen:m.brightGreen,brightYellow:m.brightYellow,brightBlue:m.brightBlue,brightMagenta:m.brightMagenta,brightCyan:m.brightCyan,brightWhite:m.brightWhite},scrollback:1e4,ghostty:ee,disableStdin:fe}}let ct=null;function Ht(){return ct||(ct=xt.load()),ct}function qt(f){if(typeof window>"u")return null;const p=[f,...Array.from(f.querySelectorAll("*"))];let m=null;for(const ee of p){const Ie=window.getComputedStyle(ee).overflowY;if(!(Ie!=="auto"&&Ie!=="scroll")){if(ee.scrollHeight-ee.clientHeight>2)return ee;m||(m=ee)}}return m}const mt=n.forwardRef(({sessionKey:f,chunks:p,onInput:m,onResize:ee,theme:fe,fontFamily:Ie,fontSize:we,className:Me,enableTouchScroll:E,autoFocus:et=!0,isVisible:Pe=!0},ye)=>{const{t:L}=pt(),V=n.useRef(null),Ne=n.useRef(null),I=n.useRef(null),Ue=n.useRef(null),P=n.useRef(m),Oe=n.useRef(ee),h=n.useRef(null),he=n.useRef(""),te=n.useRef(null),Le=n.useRef(!1),Fe=n.useRef(null),de=n.useRef(!0),ne=n.useRef(null),q=n.useRef(null),be=n.useRef(0),re=n.useRef(null),He=n.useRef(null),ae=n.useRef(!1),k=n.useRef(!1),R=n.useRef(null),pe=n.useRef(null),Ke=n.useRef(null),N=n.useRef(""),Ye=n.useRef(null),ge=n.useRef(!E),_e=n.useRef(Pe),[,tt]=n.useReducer(e=>e+1,0),[qe,z]=n.useReducer(e=>e+1,0);P.current=m,Oe.current=ee;const it=typeof navigator<"u"&&(/Android/i.test(navigator.userAgent)||navigator.userAgentData?.platform==="Android"),y=!!E;n.useEffect(()=>{if(!E){ge.current=!0,_e.current=Pe;return}!_e.current&&Pe&&(ge.current=!1),_e.current=Pe},[E,Pe]);const xe=n.useCallback(()=>{if(!y)return;const e=V.current,o=re.current;if(!e)return;const s=[];e.getAttribute("contenteditable")==="true"&&s.push(e),s.push(...Array.from(e.querySelectorAll('[contenteditable="true"]'))),s.forEach(r=>{r.setAttribute("data-terminal-disabled-contenteditable","true"),r.setAttribute("contenteditable","false"),r.setAttribute("aria-hidden","true"),r.tabIndex=-1,r.style.setProperty("caret-color","transparent"),r.style.color="transparent",r.style.setProperty("-webkit-text-fill-color","transparent"),r.style.background="transparent",r.style.outline="none",r.style.boxShadow="none",r.style.textShadow="none",r.style.setProperty("user-select","none"),r.style.setProperty("-webkit-user-select","none")}),e.tabIndex=-1,e.removeAttribute("role"),e.removeAttribute("aria-multiline"),Array.from(e.querySelectorAll("textarea")).forEach(r=>{r.style.setProperty("caret-color","transparent"),r.style.color="transparent",r.style.setProperty("-webkit-text-fill-color","transparent"),r.style.background="transparent",r.style.border="0",r.style.outline="none",r.style.boxShadow="none",r.style.textShadow="none",r.style.fontSize="0",r.style.lineHeight="0",r!==o&&r.getAttribute("data-terminal-disabled-input")!=="true"&&(r.setAttribute("data-terminal-disabled-input","true"),r.setAttribute("aria-hidden","true"),r.tabIndex=-1,r.disabled=!0,r.style.position="absolute",r.style.opacity="0",r.style.width="0px",r.style.height="0px",r.style.pointerEvents="none",r.style.zIndex="-1")})},[y]),A=n.useCallback(e=>{if(Ye.current===e)return;const o=I.current;if(o)try{if(typeof o.setOption=="function"){o.setOption("cursorBlink",e),Ye.current=e;return}o.options&&(o.options.cursorBlink=e,Ye.current=e)}catch{}},[]),M=y&&it,C=n.useCallback((e,o)=>{const s=M?He.current:re.current,c=V.current;if(!s||!c)return;const r=c.getBoundingClientRect(),v=typeof window<"u"?window.innerWidth:r.width,S=typeof window<"u"?window.innerHeight:r.height,D=r.left+r.width/2,G=r.top+r.height-12,l=typeof e=="number"?e:D,T=typeof o=="number"?o:G,j=8,O=Math.max(j,Math.min(v-j,l)),K=Math.max(j,Math.min(S-j,T));s.style.left=`${O}px`,s.style.top=`${K}px`,s.style.bottom="",(s instanceof HTMLTextAreaElement||s instanceof HTMLInputElement)&&(s.disabled=!1,s.readOnly=!1,s.removeAttribute("disabled"),s.removeAttribute("readonly"));try{s.focus({preventScroll:!0})}catch{try{s.focus()}catch{}}},[M]),ve=n.useCallback(()=>{if(y){C(),A(!0);return}I.current?.focus(),A(!0)},[C,A,y]),ce=n.useCallback(e=>e instanceof HTMLTextAreaElement||e instanceof HTMLInputElement?e.value:e.textContent??"",[]),W=n.useCallback(e=>{if(e instanceof HTMLTextAreaElement||e instanceof HTMLInputElement){e.value="";return}e.textContent=""},[]),ze=n.useCallback(e=>{if(typeof window>"u"||M)return;Ke.current!==null&&(window.clearTimeout(Ke.current),Ke.current=null);let o=0;const s=3,c=()=>{Ke.current=window.setTimeout(()=>{Ke.current=null;const r=ce(e);if(!r){if(o+=1,o<s){c();return}return}const v=N.current;N.current=r;const S=r.startsWith(v)?r.slice(v.length):r;S&&P.current(S.replace(/\r\n|\r|\n/g,"\r")),W(e),N.current=""},o===0?0:24)};c()},[W,ce,M]);n.useEffect(()=>{const e=V.current;if(!y||!e||E)return;const o=s=>{const c=s.target;if(c&&c.getAttribute("data-terminal-hidden-input")!=="true"&&e.contains(c)){try{c.blur()}catch{}C()}};return e.addEventListener("focusin",o,!0),()=>{e.removeEventListener("focusin",o,!0)}},[E,y,C]);const Be=n.useCallback(()=>{const e=I.current;if(!e||typeof e.getSelection!="function")return"";const o=e.getSelection();return typeof o=="string"?o:""},[]),le=n.useCallback(()=>{if(typeof window>"u")return"";const e=window.getSelection();if(!e)return"";const o=e.toString();if(!o.trim())return"";const s=V.current;if(!s)return"";const c=e.anchorNode,r=e.focusNode;return c&&!s.contains(c)||r&&!s.contains(r)?"":o},[]),Te=n.useCallback(async()=>{if(typeof document>"u")return;const e=Be()||le();e.trim()&&await Bt(e)},[le,Be]),X=n.useCallback(()=>Be().trim()?!0:!!le().trim(),[le,Be]);n.useEffect(()=>{if(typeof window>"u")return;const e=o=>{X()&&(o.preventDefault(),Te())};return window.addEventListener("openchamber:copy",e),()=>{window.removeEventListener("openchamber:copy",e)}},[Te,X]);const U=n.useCallback(()=>{he.current="",te.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(te.current),te.current=null,Le.current=!1,Fe.current=null},[]),F=n.useCallback(()=>{const e=Ue.current,o=I.current,s=V.current;if(!e||!o||!s)return;const c=s.getBoundingClientRect();if(!(c.width<24||c.height<24))try{e.fit();const r={cols:o.cols,rows:o.rows},v=h.current;(!v||v.cols!==r.cols||v.rows!==r.rows)&&(h.current=r,Oe.current(r.cols,r.rows))}catch{}},[]),De=n.useCallback(()=>{if(Le.current)return;const e=I.current;if(!e){U();return}if(!he.current)return;const o=he.current;he.current="",Le.current=!0,e.write(o,()=>{Le.current=!1,he.current&&(typeof window<"u"?te.current=window.requestAnimationFrame(()=>{te.current=null,De()}):De())})},[U]),$e=n.useCallback(()=>{te.current===null&&(typeof window<"u"?te.current=window.requestAnimationFrame(()=>{te.current=null,De()}):De())},[De]),We=n.useCallback(e=>{e&&(he.current+=e,$e())},[$e]),ke=n.useCallback(()=>{if(ne.current?.(),ne.current=null,q.current!==null&&typeof window<"u"&&(window.clearTimeout(q.current),q.current=null),!E){be.current=0;return}const e=V.current;if(!e)return;const o=I.current;if(!o)return;be.current=0;const s=2.2,c=2.8,r=25,v=.25,S=8,D=.05,G=.015,l={lastY:null,lastTime:null,velocity:0,rafId:null,startX:null,startY:null,didMove:!1},T=()=>typeof performance<"u"?performance.now():Date.now(),j=Math.max(12,Math.round(we*1.35));let O=0;const K=t=>{if(!t)return!1;const u=o.getViewportY(),i=O+t,b=Math.trunc(i/j);return O=i-b*j,b!==0&&o.scrollLines(b),o.getViewportY()!==u},Y=()=>{l.rafId!==null&&typeof window<"u"&&window.cancelAnimationFrame(l.rafId),l.rafId=null},x={passive:!1,capture:!1};if(typeof window<"u"&&"PointerEvent"in window){const t=Object.assign(l,{pointerId:null,startX:null,startY:null,moved:!1}),u=6,i=d=>{if(d.pointerType==="touch"){Y(),t.pointerId=d.pointerId,t.startX=d.clientX,t.startY=d.clientY,t.moved=!1,t.lastY=d.clientY,t.lastTime=T(),t.velocity=0;try{e.setPointerCapture(d.pointerId)}catch{}}},b=d=>{if(d.pointerType!=="touch"||t.pointerId!==d.pointerId)return;if(t.startX!==null&&t.startY!==null&&!t.moved){const wt=d.clientX-t.startX,yt=d.clientY-t.startY;Math.hypot(wt,yt)>=u&&(t.moved=!0)}if(t.lastY===null){t.lastY=d.clientY,t.lastTime=T();return}const _=t.lastY,oe=t.lastTime??T(),$=T();t.lastY=d.clientY,t.lastTime=$;const ie=_-d.clientY;if(Math.abs(ie)<1)return;const Ae=Math.max($-oe,8),se=s+Math.min(c,Math.abs(ie)/r),je=ie*se,Ze=je/Ae;t.velocity=t.velocity*(1-v)+Ze*v,t.velocity>S?t.velocity=S:t.velocity<-S&&(t.velocity=-S),t.moved&&(d.cancelable&&d.preventDefault(),d.stopPropagation()),K(je)},w=d=>{if(d.pointerType!=="touch"||t.pointerId!==d.pointerId)return;const _=!t.moved;t.pointerId=null,t.startX=null,t.startY=null,t.moved=!1,t.lastY=null,t.lastTime=null;try{e.releasePointerCapture(d.pointerId)}catch{}if(_){y?C(d.clientX,d.clientY):E&&!ge.current&&(ge.current=!0,I.current?.focus());return}if(typeof window>"u")return;if(Math.abs(t.velocity)<D){t.velocity=0;return}let oe=T();const $=()=>{const ie=T(),Ae=Math.max(ie-oe,8);oe=ie;const se=K(t.velocity*Ae)??!1,je=Math.sign(t.velocity),Ze=Math.max(0,Math.abs(t.velocity)-G*Ae);if(t.velocity=Ze*je,!se||Ze<=D){Y(),t.velocity=0;return}t.rafId=window.requestAnimationFrame($)};t.rafId=window.requestAnimationFrame($)};e.addEventListener("pointerdown",i,x),e.addEventListener("pointermove",b,x),e.addEventListener("pointerup",w,x),e.addEventListener("pointercancel",w,x);const g=e.style.touchAction;e.style.touchAction="manipulation",ne.current=()=>{Y(),q.current!==null&&typeof window<"u"&&(window.clearTimeout(q.current),q.current=null),be.current=0,e.removeEventListener("pointerdown",i,x),e.removeEventListener("pointermove",b,x),e.removeEventListener("pointerup",w,x),e.removeEventListener("pointercancel",w,x),e.style.touchAction=g};return}const Ee=6,H=t=>{t.touches.length===1&&(Y(),l.lastY=t.touches[0].clientY,l.lastTime=T(),l.velocity=0,l.startX=t.touches[0].clientX,l.startY=t.touches[0].clientY,l.didMove=!1)},Ve=t=>{if(t.touches.length!==1){l.lastY=null,l.lastTime=null,l.velocity=0,l.startX=null,l.startY=null,l.didMove=!1,Y();return}const u=t.touches[0].clientX,i=t.touches[0].clientY;if(l.startX!==null&&l.startY!==null&&!l.didMove){const Ae=u-l.startX,se=i-l.startY;Math.hypot(Ae,se)>=Ee&&(l.didMove=!0)}if(l.lastY===null){l.lastY=i,l.lastTime=T();return}const b=l.lastY,w=l.lastTime??T(),g=T();l.lastY=i,l.lastTime=g;const d=b-i;if(Math.abs(d)<1)return;const _=Math.max(g-w,8),oe=s+Math.min(c,Math.abs(d)/r),$=d*oe,ie=$/_;l.velocity=l.velocity*(1-v)+ie*v,l.velocity>S?l.velocity=S:l.velocity<-S&&(l.velocity=-S),l.didMove&&(t.preventDefault(),t.stopPropagation()),K($)},Re=t=>{const u=!l.didMove;l.lastY=null,l.lastTime=null;const i=l.velocity;if(l.startX=null,l.startY=null,l.didMove=!1,u){const g=t.changedTouches?.[0];y?C(g?.clientX,g?.clientY):E&&!ge.current&&(ge.current=!0,I.current?.focus());return}if(typeof window>"u")return;if(Math.abs(i)<D){l.velocity=0;return}let b=T();const w=()=>{const g=T(),d=Math.max(g-b,8);b=g;const _=K(l.velocity*d)??!1,oe=Math.sign(l.velocity),$=Math.max(0,Math.abs(l.velocity)-G*d);if(l.velocity=$*oe,!_||$<=D){Y(),l.velocity=0;return}l.rafId=window.requestAnimationFrame(w)};l.rafId=window.requestAnimationFrame(w)};e.addEventListener("touchstart",H,x),e.addEventListener("touchmove",Ve,x),e.addEventListener("touchend",Re,x),e.addEventListener("touchcancel",Re,x);const Q=e.style.touchAction;e.style.touchAction="manipulation",ne.current=()=>{Y(),q.current!==null&&typeof window<"u"&&(window.clearTimeout(q.current),q.current=null),be.current=0,e.removeEventListener("touchstart",H,x),e.removeEventListener("touchmove",Ve,x),e.removeEventListener("touchend",Re,x),e.removeEventListener("touchcancel",Re,x),e.style.touchAction=Q}},[E,y,C,we]);n.useEffect(()=>{let e=!1,o=null,s=null,c=null,r=[],v=null,S=null;const D=V.current;if(!D)return;if(D.tabIndex=y?-1:0,y){const Y=D.focus.bind(D),x=D;x.focus=((...B)=>{C()}),S=()=>{x.focus=Y}}const G=()=>{A(!0)},l=()=>{A(!1)},T=Y=>{const x=Y.target;if(x&&D.contains(x)){if(y&&x instanceof HTMLElement){window.setTimeout(()=>{x.blur(),C()},0),A(!1);return}if(E&&!ge.current&&x instanceof HTMLElement){window.setTimeout(()=>{x.blur()},0),A(!1);return}A(!0);return}A(!1)},j=()=>{A(!1)};let O=null;return(async()=>{try{const Y=await Ht();if(e)return;const x=Ot(Ie,we,fe,Y,!1),B=new bt(x);de.current=!0,y&&(B.focus=()=>{});const Ee=B;if(typeof Ee.scrollToBottom=="function"){const Q=Ee.scrollToBottom.bind(Ee);Ee.scrollToBottom=()=>{de.current&&Q()},v=()=>{Ee.scrollToBottom=Q}}const H=new gt;o=B,I.current=B,Ue.current=H,B.loadAddon(H),B.open(D),z(),Ye.current=!1,O=B.textarea??D.querySelector("textarea"),O&&(O.addEventListener("focus",G),O.addEventListener("blur",l)),xe(),typeof MutationObserver<"u"&&(c=new MutationObserver(()=>{xe()}),c.observe(D,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["contenteditable","role","tabindex","aria-label"]}));const Ve=qt(D);Ve?(Ve.classList.add("overlay-scrollbar-target","overlay-scrollbar-container"),Ne.current=Ve,tt()):Ne.current=null,F();const Re=H;typeof Re.observeResize=="function"&&Re.observeResize(),ke(),r=[B.onData(Q=>{P.current(Q)}),B.onScroll(Q=>{if(typeof Q=="number"&&Number.isFinite(Q)){const t=typeof B.hasSelection=="function"&&B.hasSelection();de.current=!t&&Q<=.5}}),B.onSelectionChange(()=>{if(typeof B.hasSelection=="function"&&B.hasSelection()){de.current=!1;return}const t=typeof B.getViewportY=="function"?B.getViewportY():0;de.current=t<=.5})],s=new ResizeObserver(()=>{F()}),s.observe(D),typeof window<"u"&&window.setTimeout(()=>{F()},0)}catch{}})(),document.addEventListener("focusin",T,!0),window.addEventListener("blur",j),()=>{e=!0,ne.current?.(),ne.current=null,document.removeEventListener("focusin",T,!0),window.removeEventListener("blur",j),r.forEach(Y=>Y.dispose()),v?.(),v=null,O&&(O.removeEventListener("focus",G),O.removeEventListener("blur",l)),s?.disconnect(),c?.disconnect(),S?.(),o?.dispose(),I.current=null,Ue.current=null,Ne.current=null,h.current=null,Ye.current=null,U()}},[xe,E,F,C,Ie,we,ke,fe,U,A,y]),n.useEffect(()=>{const e=I.current;e&&(e.reset(),U(),h.current=null,F())},[f,qe,F,U]),n.useEffect(()=>{!et||!I.current||ve()},[et,ve,f,qe]),n.useEffect(()=>(ke(),()=>{ne.current?.(),ne.current=null}),[ke,f]),n.useEffect(()=>{const e=I.current;if(!e)return;if(p.length===0){Fe.current!==null&&(e.reset(),U(),F());return}const o=Fe.current;let s;if(o===null)s=p;else{const c=p.findIndex(r=>r.id===o);s=c>=0?p.slice(c+1):p}s.length>0&&We(s.map(c=>c.data).join("")),Fe.current=p[p.length-1].id},[p,qe,We,F,U]),n.useImperativeHandle(ye,()=>({focus:()=>{ve()},clear:()=>{const e=I.current;e&&(e.reset(),U(),F())},fit:()=>{F()}}),[ve,F,U]);const Ge=n.useCallback(e=>{if(!y)return;const o=V.current,s=e.relatedTarget,c=s?.tagName,r=c==="INPUT"||c==="TEXTAREA"||s?.isContentEditable,v=s?.getAttribute("data-terminal-hidden-input")==="true",S=!!(s&&o?.contains(s))},[y]),me=n.useCallback(e=>{const o=e.nativeEvent,s=o?.inputType??"",c=typeof o?.data=="string"?o.data:"";if(pe.current=typeof performance<"u"?performance.now():Date.now(),s==="insertCompositionText"){ae.current=!0;return}if(!s&&c){if(ae.current)return;e.preventDefault(),P.current(c),R.current={type:"insertText",at:typeof performance<"u"?performance.now():Date.now()},k.current=!0;return}if(s==="insertText"&&c){if(ae.current)return;e.preventDefault(),P.current(c),R.current={type:s,at:typeof performance<"u"?performance.now():Date.now()},k.current=!0;return}if(s==="insertLineBreak"){if(ae.current)return;e.preventDefault(),P.current("\r"),R.current={type:s,at:typeof performance<"u"?performance.now():Date.now()},k.current=!0;return}if(s==="deleteContentBackward"){if(ae.current)return;e.preventDefault(),P.current(""),R.current={type:s,at:typeof performance<"u"?performance.now():Date.now()},k.current=!0}},[]),ue=n.useCallback(e=>{const o=e.currentTarget;if(pe.current=typeof performance<"u"?performance.now():Date.now(),ae.current)return;if(k.current){const r=R.current,v=typeof performance<"u"?performance.now():Date.now();if(r&&v-r.at<50){k.current=!1,W(o);return}k.current=!1}const s=ce(o);if(!s)return;N.current=s;const c=s.replace(/\r\n|\r|\n/g,"\r");P.current(c),W(o),N.current=""},[W,ce]),nt=n.useCallback(e=>{e.stopPropagation();const o=e.key.toLowerCase(),s=e.metaKey&&!e.ctrlKey&&!e.altKey&&o==="c",c=e.ctrlKey&&e.shiftKey&&!e.metaKey&&!e.altKey&&o==="c";if((s||c)&&X()){e.preventDefault(),Te();return}if(e.ctrlKey&&!e.metaKey&&!e.altKey&&e.key.length===1){const j=e.key.toUpperCase();if(j>="A"&&j<="Z"){e.preventDefault(),e.nativeEvent?.stopImmediatePropagation(),P.current(String.fromCharCode(j.charCodeAt(0)-64)),W(e.currentTarget);return}}if(e.altKey&&!e.ctrlKey&&!e.metaKey&&e.key.length===1){e.preventDefault(),e.nativeEvent?.stopImmediatePropagation(),P.current("\x1B"+e.key),W(e.currentTarget);return}const v={ArrowUp:"\x1B[A",ArrowDown:"\x1B[B",ArrowRight:"\x1B[C",ArrowLeft:"\x1B[D",Escape:"\x1B",Tab:" ",Delete:"\x1B[3~",Home:"\x1B[H",End:"\x1B[F"}[e.key];if(v){e.preventDefault(),P.current(v),W(e.currentTarget);return}const S=e.currentTarget;if(e.nativeEvent?.isComposing)return;const G=R.current,l=typeof performance<"u"?performance.now():Date.now(),T=!!(G&&l-G.at<50);if(e.key==="Enter"){if(T&&G?.type==="insertLineBreak")return;e.preventDefault(),P.current("\r"),W(S);return}if(e.key==="Backspace"){if(e.preventDefault(),T&&G?.type==="deleteContentBackward")return;ce(S)||P.current("")}if(e.key.length===1&&!e.ctrlKey&&!e.metaKey&&!e.altKey){const j=pe.current;j&&l-j<50||(e.preventDefault(),P.current(e.key),k.current=!0,R.current={type:"keydown-text",at:l})}ze(S)},[W,Te,X,ce,ze]),Ce=n.useCallback(e=>{e.stopPropagation();const o=e.currentTarget;e.nativeEvent?.isComposing||ze(o)},[ze]),rt=n.useCallback(e=>{const o=e.currentTarget;ae.current=!1;const s=e.data||ce(o);if(pe.current=typeof performance<"u"?performance.now():Date.now(),!s)return;const c=s.replace(/\r\n|\r|\n/g,"\r");P.current(c),W(o),R.current={type:"compositionend",at:typeof performance<"u"?performance.now():Date.now()},k.current=!0},[W,ce]),ot=n.useCallback(e=>{e.stopPropagation();const o=e.clipboardData?.getData("text")??"";if(!o)return;e.preventDefault();const c=I.current?.hasBracketedPaste?.()?`\x1B[200~${o}\x1B[201~`:o;P.current(c)},[]),Qe={position:"fixed",left:0,top:0,width:1,height:1,opacity:0,zIndex:-1,background:"transparent",color:"transparent",WebkitTextFillColor:"transparent",caretColor:"transparent",textShadow:"none",WebkitAppearance:"none",appearance:"none",resize:"none",overflow:"hidden",whiteSpace:"nowrap",border:"0",padding:0,margin:0,outline:"none",outlineOffset:0,fontSize:16,fontWeight:400,pointerEvents:"none",WebkitUserSelect:"none",userSelect:"none"};return a.jsxs("div",{ref:V,className:Xe("relative h-full w-full terminal-viewport-container",Me),"data-hidden-input-overlay-active":y?"true":void 0,style:{backgroundColor:fe.background},onTouchStart:e=>{if(!(!y||E)&&!X()){const o=e.touches?.[0];C(o?.clientX,o?.clientY)}},onClick:e=>{if(!E)if(y){if(X())return;C(e.clientX,e.clientY)}else I.current?.focus()},onMouseUp:()=>{!E&&X()&&Te()},onTouchEnd:()=>{!E&&X()&&Te()},children:[y&&typeof document<"u"?ht.createPortal(a.jsxs(a.Fragment,{children:[a.jsx("input",{ref:He,type:"text",inputMode:"text",autoCapitalize:"off",autoComplete:"off",autoCorrect:"off",spellCheck:!1,tabIndex:-1,enterKeyHint:"send","data-terminal-hidden-input":"true","aria-label":L("terminalView.viewport.inputAria"),"aria-hidden":"true",style:{...Qe,display:M?"block":"none"},onBlur:Ge,onBeforeInput:me,onCompositionStart:()=>{ae.current=!0},onInput:ue,onKeyDown:nt,onKeyUp:Ce,onCompositionEnd:rt,onPaste:ot}),a.jsx("textarea",{ref:re,inputMode:"text",autoCapitalize:"off",autoComplete:"off",autoCorrect:"off",spellCheck:!1,tabIndex:-1,enterKeyHint:"send","data-terminal-hidden-input":"true","aria-label":L("terminalView.viewport.inputAria"),"aria-hidden":"true",style:{...Qe,display:M?"none":"block"},onBlur:Ge,onBeforeInput:me,onCompositionStart:()=>{ae.current=!0},onInput:ue,onKeyDown:nt,onKeyUp:Ce,onCompositionEnd:rt,onPaste:ot})]}),document.body):null,Ne.current&&!E?a.jsx(Dt,{containerRef:Ne,disableHorizontal:!0,className:"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero"}):null]})});mt.displayName="TerminalViewport";const Wt={esc:"\x1B",tab:" ",enter:"\r","arrow-up":"\x1B[A","arrow-down":"\x1B[B","arrow-left":"\x1B[D","arrow-right":"\x1B[C"},st={ctrl:"5",cmd:"3"},lt={retry:{maxRetries:3,initialDelayMs:500,maxDelayMs:8e3},connectionTimeoutMs:1e4},Xt={retry:{...lt.retry,initialDelayMs:200,maxDelayMs:500},connectionTimeoutMs:1500},Ut=(f,p)=>{if(p)switch(f){case"arrow-up":return`\x1B[1;${st[p]}A`;case"arrow-down":return`\x1B[1;${st[p]}B`;case"arrow-right":return`\x1B[1;${st[p]}C`;case"arrow-left":return`\x1B[1;${st[p]}D`}return Wt[f]??null},Jt=()=>{const{t:f}=pt(),{terminal:p,runtime:m}=Vt(),{currentTheme:ee}=jt(),{monoFont:fe}=Pt(),Ie=Se(t=>t.terminalFontSize),we=Se(t=>t.bottomTerminalHeight),Me=Se(t=>t.isBottomTerminalExpanded),{isMobile:E,isTablet:et,hasTouchOnlyPointer:Pe}=Nt(),ye=E||et,L=(ye||Pe)&&m.platform==="web",V=m.platform!=="vscode",Ne=Se(t=>t.showTerminalQuickKeysOnDesktop),I=ye||Ne,Ue=dt(t=>t.currentSessionId),P=dt(t=>t.newSessionDraft),Oe=Ue!==null||P?.open===!0,h=Lt()??null,he=J(t=>t.sessions),te=J(t=>t.hasHydrated),Le=J(t=>t.ensureDirectory),Fe=J(t=>t.createTab),de=J(t=>t.setActiveTab),ne=J(t=>t.closeTab),q=J(t=>t.setTabSessionId),be=J(t=>t.setTabLifecycle),re=J(t=>t.setConnecting),He=J(t=>t.appendToBuffer),ae=Se(t=>t.openContextPreview),k=n.useMemo(()=>{if(h)return he.get(h)},[he,h]),R=n.useMemo(()=>k?V?k.activeTabId??k.tabs[0]?.id??null:k.tabs[0]?.id??null:null,[k,V]),pe=n.useMemo(()=>{if(k)return R?k.tabs.find(t=>t.id===R)??k.tabs[0]:k.tabs[0]},[k,R]),Ke=n.useMemo(()=>(k?.tabs??[]).map(t=>({icon:(()=>{const u=t.iconKey?Ft[t.iconKey]??ut:ut;return a.jsx(u,{className:"h-4 w-4"})})(),id:t.id,label:t.label,title:t.label,closeLabel:f("terminalView.tabs.closeTabTitle")})),[k?.tabs,f]),N=pe?.terminalSessionId??null,Ye=pe?.lifecycle??"idle",ge=pe?.bufferChunks??[],_e=pe?.isConnecting??!1,tt=pe?.previewUrl??null,[qe,z]=n.useState(null),[it,y]=n.useState(!1),[xe,A]=n.useState(!1),[M,C]=n.useState(null),[ve,ce]=n.useState(!1),[W,ze]=n.useState(0),Be=n.useRef(null),le=n.useRef(null),Te=n.useRef(R),X=n.useRef(N),U=n.useRef(h),F=n.useRef(null),De=n.useRef(null),$e=n.useRef(!1),We=n.useRef(null),ke=n.useRef(new Set),Ge=n.useRef(!1),me=n.useCallback(()=>{L||typeof document<"u"&&!document.hasFocus()||F.current?.focus()},[L]),ue=n.useCallback(()=>{L||F.current?.focus()},[L]);n.useEffect(()=>{if(!te||Ge.current)return;Ge.current=!0;const t=new Set;for(const[,u]of J.getState().sessions.entries())for(const i of u.tabs)i.terminalSessionId&&t.add(i.terminalSessionId);ke.current=t},[te]);const nt=Se(t=>t.activeMainTab),Ce=Se(t=>t.isBottomTerminalOpen),rt=Se(t=>t.setBottomTerminalOpen),ot=Se(t=>t.setBottomTerminalExpanded),Qe=nt==="terminal",e=Qe||Ce,[o,s]=n.useState(e);n.useEffect(()=>{!e||m.platform==="vscode"||Yt()},[e,m.platform]),n.useEffect(()=>{e&&s(!0)},[e]),n.useEffect(()=>{$e.current=e},[e]),n.useEffect(()=>{X.current=N},[N]),n.useEffect(()=>{Te.current=R},[R]),n.useEffect(()=>{U.current=h},[h]),n.useEffect(()=>{!I&&M!==null&&C(null)},[I,M,C]),n.useEffect(()=>{!N&&M!==null&&C(null)},[N,M,C]);const c=n.useCallback(()=>{Be.current?.(),Be.current=null,le.current=null,A(!1)},[]);n.useEffect(()=>()=>{c(),X.current=null},[c]);const r=n.useCallback((t,u,i,b=lt)=>{if(le.current===i)return;c(),le.current=i;const w=p.connect(i,{onEvent:g=>{if(le.current===i)switch(g.type){case"connected":{re(t,u,!1),z(null),y(!1),A(!1),me(),We.current===i&&(We.current=null,p.sendInput(i,"\r").catch(()=>{}));break}case"reconnecting":{z(null),y(!1),A(!0);break}case"data":{g.data&&He(t,u,g.data);break}case"exit":{const d=typeof g.exitCode=="number"?g.exitCode:null,_=typeof g.signal=="number"?g.signal:null,$=!!J.getState().getDirectoryState(t)?.tabs.find(ie=>ie.id===u)?.label?.startsWith("Action:");He(t,u,f("terminalView.stream.processExitedMessage",{exitCodeSegment:d!==null?f("terminalView.stream.processExitedWithCode",{exitCode:d}):"",signalSegment:_!==null?f("terminalView.stream.processExitedWithSignal",{signal:_}):""})),be(t,u,"exited"),q(t,u,null),re(t,u,!1),z($?null:f("terminalView.error.sessionEnded")),y(!1),A(!1),c();break}}},onError:(g,d)=>{if(le.current===i){if(!d){z(null),y(!1);return}A(!1),z(f("terminalView.error.connectionFailed",{message:g.message})),y(!0),re(t,u,!1),be(t,u,"exited"),q(t,u,null),c()}}},b);Be.current=()=>{w.close(),le.current=null}},[He,c,me,re,be,q,f,p]);n.useEffect(()=>{let t=!1;if(!te||!o)return;if(!h){z(f(Oe?"terminalView.empty.noWorkingDirectory":"terminalView.empty.selectSession")),c();return}return(async()=>{const i=h;if(!U.current||U.current!==i)return;Le(i);const b=J.getState().getDirectoryState(i);if(!b||b.tabs.length===0)return;const w=V?b.activeTabId??b.tabs[0]?.id??null:b.tabs[0]?.id??null;if(!w)return;const g=b.tabs.find(se=>se.id===w)??b.tabs[0];let d=g?.terminalSessionId??null;const _=g?.lifecycle??"idle",oe=!!g?.label?.startsWith("Action:"),$=(g?.bufferLength??0)>0||(g?.bufferChunks?.length??0)>0,ie=!!d&&ke.current.has(d)&&(g?.bufferLength??0)===0&&(g?.bufferChunks?.length??0)===0,Ae=!!d&&ke.current.has(d);if(!d){if(_==="exited"){re(i,w,!1);return}if(oe&&$){re(i,w,!1);return}z(null),y(!1),A(!1),re(i,w,!0);try{const se=De.current,je=await p.createSession({cwd:i,cols:se?.cols,rows:se?.rows});if(!(!t&&U.current===i&&Te.current===w)){try{await p.close(je.sessionId)}catch{}return}q(i,w,je.sessionId),d=je.sessionId}catch(se){t||(z(se instanceof Error?se.message:f("terminalView.error.startSessionFailed")),y(!0),A(!1),re(i,w,!1));return}}!d||t||(X.current=d,Ae&&ke.current.delete(d),ie&&(We.current=d),r(i,w,d,Ae?Xt:lt))})(),()=>{t=!0,X.current=null,c()}},[Oe,h,N,Ye,R,o,V,te,Le,re,be,q,r,c,f,p]),n.useEffect(()=>{if(!e||L)return;if(typeof window>"u"){me();return}const t=window.requestAnimationFrame(()=>{me()});return()=>{window.cancelAnimationFrame(t)}},[R,me,e,L]);const v=n.useCallback(async()=>{if(!h||ve)return;const t=J.getState().getDirectoryState(h),u=V?R??t?.activeTabId??t?.tabs[0]?.id??null:t?.tabs[0]?.id??null;if(u){ce(!0),z(null),y(!1),A(!1),c();try{await ne(h,u)}catch(i){z(i instanceof Error?i.message:f("terminalView.error.restartFailed")),y(!0),A(!1)}finally{ce(!1)}}},[R,ne,c,h,V,ve,f]),S=n.useCallback(async()=>{await v()},[v]),D=n.useCallback(()=>{if(!h)return;const t=Fe(h);de(h,t),z(null),y(!1),A(!1),c()},[Fe,c,h,de]),G=n.useCallback(t=>{h&&(de(h,t),z(null),y(!1),A(!1),c())},[c,h,de]),l=n.useCallback(t=>{h&&(t===R&&c(),z(null),y(!1),A(!1),ne(h,t))},[R,ne,c,h]),T=n.useCallback(t=>{if(!t||xe)return;let u=t,i=!1;if(M&&t.length>0){const w=t[0];if(w.length===1&&/[a-zA-Z]/.test(w)){const g=w.toUpperCase();(M==="ctrl"||M==="cmd")&&(u=String.fromCharCode(g.charCodeAt(0)&31),i=!0)}i||(i=!0)}const b=X.current;b&&(p.sendInput(b,u).catch(w=>{xe||z(w instanceof Error?w.message:f("terminalView.error.sendInputFailed"))}),i&&(C(null),ue()))},[M,ue,xe,C,f,p]),j=n.useCallback((t,u)=>{if(De.current={cols:t,rows:u},!$e.current)return;const i=X.current;i&&p.resize({sessionId:i,cols:t,rows:u}).catch(()=>{})},[p]),O=n.useCallback(t=>{C(u=>u===t?null:t),ue()},[ue,C]),K=n.useCallback(t=>{const u=Ut(t,M);u&&(T(u),C(null),ue())},[M,ue,T,C]);n.useEffect(()=>{if(!I||!M||!N)return;const t=u=>{if(u.repeat)return;const i=u.key;if(!i||i==="Control"||i==="Meta"||i==="Alt"||i==="Shift")return;const b=i.length===1?i.toLowerCase():i,w=u.code??"",g=w.startsWith("Key")&&w.length===4?w.slice(3).toUpperCase():null,d=i.length===1&&/[a-zA-Z]/.test(i)?i.toUpperCase():g,_={Tab:"tab",Enter:"enter",ArrowUp:"arrow-up",ArrowDown:"arrow-down",ArrowLeft:"arrow-left",ArrowRight:"arrow-right",Escape:"esc",tab:"tab",enter:"enter",arrowup:"arrow-up",arrowdown:"arrow-down",arrowleft:"arrow-left",arrowright:"arrow-right",escape:"esc"};if(b in _){u.preventDefault(),u.stopPropagation(),K(_[b]);return}if(M==="ctrl"&&d&&d.length===1&&d>="A"&&d<="Z"){const oe=String.fromCharCode(d.charCodeAt(0)&31);u.preventDefault(),u.stopPropagation(),T(oe),C(null),ue()}};return window.addEventListener("keydown",t),()=>{window.removeEventListener("keydown",t)}},[M,K,T,ue,I,C,N]);const Y=n.useMemo(()=>{const t=Je[at].stack;if(typeof window>"u")return(Je[fe]??Je[at]).stack;const i=window.getComputedStyle(document.documentElement).getPropertyValue("--font-family-mono");return i&&i.trim().length>0?i.trim():(Je[fe]??Je[at]).stack??t},[fe]),x=n.useMemo(()=>zt(ee),[ee]),B=n.useMemo(()=>`${h??"no-dir"}::${R??"no-tab"}::${N??"no-terminal"}`,[h,R,N]),Ee=n.useMemo(()=>`${B}::layout-${W}`,[B,W]);if(n.useEffect(()=>{if(L||!Ce||!e)return;if(typeof window>"u"){ze(u=>u+1);return}const t=window.setTimeout(()=>{ze(u=>u+1)},140);return()=>{window.clearTimeout(t)}},[we,Me,Ce,e,L]),n.useEffect(()=>{if(!e||L)return;const t=F.current;if(!t)return;const u=()=>{t.fit()};if(typeof window<"u"){const i=window.requestAnimationFrame(()=>{u(),me()}),b=[220,400].map(w=>window.setTimeout(u,w));return()=>{window.cancelAnimationFrame(i),b.forEach(w=>window.clearTimeout(w))}}u()},[me,e,L,B,N]),n.useEffect(()=>{if(L||!e||!Ce)return;const t=F.current;if(!t)return;const u=()=>{t.fit()};if(typeof window<"u"){const i=window.requestAnimationFrame(()=>{u()}),b=[0,80,180,320].map(w=>window.setTimeout(u,w));return()=>{window.cancelAnimationFrame(i),b.forEach(w=>window.clearTimeout(w))}}u()},[we,Me,Ce,e,L]),!Oe)return a.jsx("div",{className:"flex h-full items-center justify-center p-4 text-center text-sm text-muted-foreground",children:f("terminalView.empty.selectSession")});if(!h)return a.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 p-4 text-center text-sm text-muted-foreground",children:[a.jsx("p",{children:f("terminalView.empty.noWorkingDirectoryForSession")}),a.jsx("button",{onClick:v,className:"rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90",children:f("terminalView.actions.retry")})]});const H=!N||_e||ve||xe,Ve=o,Re=!ye&&Ce&&!Qe,Q=a.jsxs(a.Fragment,{children:[a.jsx(Z,{type:"button",size:"sm",variant:"outline",className:"h-6 px-2 text-xs",onClick:()=>K("esc"),disabled:H,children:f("terminalView.quickKeys.escape")}),a.jsxs(Z,{type:"button",size:"sm",variant:"outline",className:"h-6 w-9 p-0",onClick:()=>K("tab"),disabled:H,children:[a.jsx(ft,{size:16}),a.jsx("span",{className:"sr-only",children:f("terminalView.quickKeys.tabAria")})]}),a.jsxs(Z,{type:"button",size:"sm",variant:"chip","aria-pressed":M==="ctrl",className:"h-6 w-9 p-0",onClick:()=>O("ctrl"),disabled:H,children:[a.jsx("span",{className:"text-xs font-medium",children:f("terminalView.quickKeys.controlLabel")}),a.jsx("span",{className:"sr-only",children:f("terminalView.quickKeys.controlModifierAria")})]}),a.jsxs(Z,{type:"button",size:"sm",variant:"chip","aria-pressed":M==="cmd",className:"h-6 w-9 p-0",onClick:()=>O("cmd"),disabled:H,children:[a.jsx(vt,{size:16}),a.jsx("span",{className:"sr-only",children:f("terminalView.quickKeys.commandModifierAria")})]}),a.jsxs(Z,{type:"button",size:"sm",variant:"outline",className:"h-6 w-9 p-0",onClick:()=>K("arrow-up"),disabled:H,children:[a.jsx(Tt,{size:16}),a.jsx("span",{className:"sr-only",children:f("terminalView.quickKeys.arrowUpAria")})]}),a.jsxs(Z,{type:"button",size:"sm",variant:"outline",className:"h-6 w-9 p-0",onClick:()=>K("arrow-left"),disabled:H,children:[a.jsx(kt,{size:16}),a.jsx("span",{className:"sr-only",children:f("terminalView.quickKeys.arrowLeftAria")})]}),a.jsxs(Z,{type:"button",size:"sm",variant:"outline",className:"h-6 w-9 p-0",onClick:()=>K("arrow-down"),disabled:H,children:[a.jsx(Ct,{size:16}),a.jsx("span",{className:"sr-only",children:f("terminalView.quickKeys.arrowDownAria")})]}),a.jsxs(Z,{type:"button",size:"sm",variant:"outline",className:"h-6 w-9 p-0",onClick:()=>K("arrow-right"),disabled:H,children:[a.jsx(ft,{size:16}),a.jsx("span",{className:"sr-only",children:f("terminalView.quickKeys.arrowRightAria")})]}),a.jsxs(Z,{type:"button",size:"sm",variant:"outline",className:"h-6 w-9 p-0",onClick:()=>K("enter"),disabled:H,children:[a.jsx(Et,{size:16}),a.jsx("span",{className:"sr-only",children:f("terminalView.quickKeys.enterAria")})]})]});return a.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-[var(--surface-background)]",children:[a.jsxs("div",{className:Xe("app-region-no-drag sticky top-0 z-20 shrink-0 bg-[var(--surface-background)] text-xs",ye?"px-3 py-1.5":"pl-3 pr-1.5 py-1"),children:[V&&k?a.jsxs("div",{className:"flex items-center gap-2 pl-1 pr-1",children:[a.jsx("div",{className:Xe("min-w-0 flex-1",ye?"h-8":"h-7"),children:a.jsx(Kt,{items:Ke,activeId:R,onSelect:G,onClose:l,layoutMode:"scrollable",variant:"default",className:"h-full bg-transparent"})}),a.jsx(Z,{type:"button",size:"xs",variant:"ghost",className:Xe("shrink-0",ye?"h-8 w-8 p-0":"h-7 w-7 p-0"),onClick:D,title:f("terminalView.tabs.newTabTitle"),children:a.jsx(Rt,{size:ye?18:16})}),a.jsxs("div",{className:"flex shrink-0 items-center gap-1 overflow-visible",children:[tt?a.jsxs(Z,{type:"button",size:"xs",variant:"outline",className:"h-6 shrink-0 gap-1 px-2",onClick:()=>{h&&ae(h,tt)},title:f("terminalView.preview.openTitle"),children:[a.jsx(At,{className:"h-3.5 w-3.5 shrink-0"}),a.jsx("span",{className:"whitespace-nowrap",children:f("terminalView.preview.open")})]}):null,Re?a.jsxs(a.Fragment,{children:[a.jsx(Z,{type:"button",size:"xs",variant:"ghost",onClick:()=>ot(!Me),className:Xe("shrink-0 p-0",E?"h-8 w-8":"h-7 w-7"),title:f(Me?"terminalView.bottomDock.restoreTitle":"terminalView.bottomDock.expandTitle"),"aria-label":f(Me?"terminalView.bottomDock.restoreAria":"terminalView.bottomDock.expandAria"),children:Me?a.jsx(St,{className:"h-4 w-4"}):a.jsx(It,{className:"h-4 w-4"})}),a.jsx(Z,{type:"button",size:"xs",variant:"ghost",onClick:()=>rt(!1),className:Xe("shrink-0 p-0",E?"h-8 w-8":"h-7 w-7"),title:f("terminalView.bottomDock.closeTitle"),"aria-label":f("terminalView.bottomDock.closeAria"),children:a.jsx(Mt,{className:"h-4 w-4"})})]}):null]})]}):null,!E&&I&&V&&k?a.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-1 pl-1 pr-1",children:Q}):null,I&&(E||!V||!k)?a.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-1",children:Q}):null]}),a.jsxs("div",{className:"relative flex-1 overflow-hidden",style:{backgroundColor:x.background},children:[a.jsx("div",{className:"h-full w-full box-border pl-4 pr-1.5 pt-3 pb-4",children:Ve?a.jsx(mt,{ref:t=>{F.current=t},sessionKey:Ee,chunks:ge,onInput:T,onResize:j,theme:x,fontFamily:Y,fontSize:Ie,enableTouchScroll:L,autoFocus:!L&&e,isVisible:e}):null}),!xe&&qe&&a.jsxs("div",{className:"absolute inset-x-0 bottom-0 bg-[var(--status-error-background)] px-3 py-2 text-xs text-[var(--status-error-foreground)] flex items-center justify-between gap-2",children:[a.jsx("span",{children:qe}),it&&E&&a.jsx(Z,{size:"sm",variant:"secondary",className:"h-6 px-2 py-0 text-xs",onClick:S,disabled:ve,title:f("terminalView.actions.hardRestartTitle"),type:"button",children:f("terminalView.actions.hardRestart")})]})]})]})};export{Jt as TerminalView};
@@ -1,16 +1,16 @@
1
- import{R as v,c as me,j as i,aB as et,f8 as Pe,z as Ve,bX as ke,bI as We,H as tt,cf as nt,eO as De,ae as it,em as Ee,K as st,a3 as ot,F as Ce,eK as rt,Z as at,eL as lt,eP as ct,W as dt,eQ as ut,a7 as ft,a1 as mt,ad as Ue,V as ht,d as Be}from"./vendor-.bun-kY4nnc4l.js";import{u as Le,c as he,bA as pt,eH as Ne,by as Ge,eI as gt,eJ as xt,eK as wt,eL as bt,eM as yt,b3 as Ke,eN as jt,eO as vt,br as Nt,bt as Ae,eP as Tt,bu as Oe,ar as St,as as _t}from"./modelPrefsAutoSave-BHV5Gay8.js";import{J as kt}from"./JsonTreeView-BhnwxlMV.js";import"./index-CX9TA5UH.js";const Rt=80,It=20,Pt=n=>n.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`),Lt=n=>Object.entries(n).filter(([,e])=>e!=null).map(([e,t])=>`${Pt(e)}:${String(t)};`).join(""),Mt=n=>n.split(",").map(e=>e.trim()).filter(Boolean).flatMap(e=>e.startsWith(".token")?[`.oc-virtualized-prism ${e}`]:e.startsWith("token.")?[`.oc-virtualized-prism .${e}`]:/^[a-z0-9_-]+$/i.test(e)?[`.oc-virtualized-prism .token.${e}`]:e.includes("token")?[`.oc-virtualized-prism ${e}`]:[]),Dt=n=>{const e=[];return Object.entries(n).forEach(([t,a])=>{const l=Mt(t);if(l.length===0)return;const o=Lt(a);o&&e.push(`${l.join(",")}{${o}}`)}),e.join(`
1
+ import{R as v,c as me,j as i,ay as et,f8 as Ie,y as Ve,bU as ke,bF as We,F as tt,cd as nt,eO as De,ab as it,em as Ee,K as st,a1 as ot,E as Ce,eK as rt,V as at,eL as lt,eP as ct,W as dt,eQ as ut,a5 as ft,$ as mt,aa as Ue,U as ht,d as Be}from"./vendor-.bun-0geEbyBQ.js";import{u as Le,c as he,bB as pt,eJ as Ne,bz as Ge,eK as gt,eL as xt,eM as wt,eN as bt,eO as yt,b4 as Ke,eP as jt,eQ as vt,bs as Nt,bu as Ae,eR as Tt,bv as Oe,as as St,at as _t}from"./modelPrefsAutoSave-DlTpduDU.js";import{J as kt}from"./JsonTreeView-DjN_Y61c.js";import"./index-DqXJOAVZ.js";const Rt=80,Pt=20,It=n=>n.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`),Lt=n=>Object.entries(n).filter(([,e])=>e!=null).map(([e,t])=>`${It(e)}:${String(t)};`).join(""),Mt=n=>n.split(",").map(e=>e.trim()).filter(Boolean).flatMap(e=>e.startsWith(".token")?[`.oc-virtualized-prism ${e}`]:e.startsWith("token.")?[`.oc-virtualized-prism .${e}`]:/^[a-z0-9_-]+$/i.test(e)?[`.oc-virtualized-prism .token.${e}`]:e.includes("token")?[`.oc-virtualized-prism ${e}`]:[]),Dt=n=>{const e=[];return Object.entries(n).forEach(([t,a])=>{const l=Mt(t);if(l.length===0)return;const o=Lt(a);o&&e.push(`${l.join(",")}{${o}}`)}),e.join(`
2
2
  `)},Et={text:"plain",plaintext:"plain",shell:"bash",sh:"bash",zsh:"bash",patch:"diff",dockerfile:"docker",js:"javascript",ts:"typescript"},Ct=n=>{const e=n.toLowerCase();return Et[e]??e},At=5e3,be=new Map,Ot=(n,e)=>{const t=Ct(e),a=`${t}
3
- ${n}`,l=be.get(a);if(l!==void 0)return l;const o=Pe.languages[t]??Pe.languages.text;if(!o){const r=ze(n);return be.set(a,r),r}try{const r=Pe.highlight(n,o,t);if(be.size>=At){const s=be.keys().next().value;typeof s=="string"&&be.delete(s)}return be.set(a,r),r}catch{const r=ze(n);return be.set(a,r),r}};function ze(n){return n.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}const qe=v.memo(n=>{const e=me.c(26),{lines:t,language:a,syntaxTheme:l,maxHeight:o,showLineNumbers:r,lineStyles:s}=n,c=o===void 0?"60vh":o,d=r===void 0?!0:r;let f;e[0]!==l?(f=Dt(l),e[0]=l,e[1]=f):f=e[1];const g=f;if(!(t.length>Rt)){let b;e[2]!==c?(b={maxHeight:c,overflow:"auto"},e[2]=c,e[3]=b):b=e[3];let w;e[4]!==g?(w=g?i.jsx("style",{children:g}):null,e[4]=g,e[5]=w):w=e[5];let y;if(e[6]!==a||e[7]!==s||e[8]!==t||e[9]!==d){let x;e[11]!==a||e[12]!==s||e[13]!==d?(x=(_,k)=>i.jsx(Me,{line:_,language:a,showLineNumbers:d,style:s?.(_)},k),e[11]=a,e[12]=s,e[13]=d,e[14]=x):x=e[14],y=t.map(x),e[6]=a,e[7]=s,e[8]=t,e[9]=d,e[10]=y}else y=e[10];let P;return e[15]!==b||e[16]!==w||e[17]!==y?(P=i.jsxs("div",{className:"typography-code font-mono w-full min-w-0 oc-virtualized-prism",style:b,children:[w,y]}),e[15]=b,e[16]=w,e[17]=y,e[18]=P):P=e[18],P}let I;return e[19]!==a||e[20]!==s||e[21]!==t||e[22]!==c||e[23]!==g||e[24]!==d?(I=i.jsx(Je,{lines:t,language:a,prismThemeCss:g,maxHeight:c,showLineNumbers:d,lineStyles:s}),e[19]=a,e[20]=s,e[21]=t,e[22]=c,e[23]=g,e[24]=d,e[25]=I):I=e[25],I});qe.displayName="VirtualizedCodeBlock";const Je=v.memo(({lines:n,language:e,prismThemeCss:t,maxHeight:a,showLineNumbers:l,lineStyles:o})=>{const r=v.useRef(null),s=et({count:n.length,getScrollElement:()=>r.current,estimateSize:()=>It,overscan:20});return i.jsxs("div",{ref:r,className:"typography-code font-mono w-full min-w-0 oc-virtualized-prism",style:{maxHeight:a,overflow:"auto"},children:[t?i.jsx("style",{children:t}):null,i.jsx("div",{style:{height:`${s.getTotalSize()}px`,width:"100%",position:"relative"},children:s.getVirtualItems().map(c=>{const d=n[c.index];return i.jsx("div",{style:{position:"absolute",top:0,left:0,width:"100%",height:`${c.size}px`,transform:`translateY(${c.start}px)`},children:i.jsx(Me,{line:d,language:e,showLineNumbers:l,style:o?.(d)})},c.index)})})]})});Je.displayName="VirtualizedRows";const Me=v.memo(n=>{const e=me.c(15),{line:t,language:a,showLineNumbers:l,style:o}=n;let r;e[0]!==a||e[1]!==t.text?(r=Ot(t.text,a),e[0]=a,e[1]=t.text,e[2]=r):r=e[2];const s=r;let c;e[3]!==t.isInfo||e[4]!==t.lineNumber||e[5]!==l?(c=l&&i.jsx("span",{className:"w-10 flex-shrink-0 text-right pr-3 select-none border-r mr-3 -my-0.5 py-0.5",style:{color:"var(--tools-edit-line-number)",borderColor:"var(--tools-border)"},children:!t.isInfo&&t.lineNumber!=null?t.lineNumber:""}),e[3]=t.isInfo,e[4]=t.lineNumber,e[5]=l,e[6]=c):c=e[6];let d;e[7]!==s||e[8]!==t.isInfo||e[9]!==t.text?(d=i.jsx("div",{className:"flex-1 min-w-0",children:t.isInfo?i.jsx("div",{className:"whitespace-pre-wrap break-words text-muted-foreground/70 italic",children:t.text}):i.jsx("div",{className:"whitespace-pre",dangerouslySetInnerHTML:{__html:s}})}),e[7]=s,e[8]=t.isInfo,e[9]=t.text,e[10]=d):d=e[10];let f;return e[11]!==o||e[12]!==c||e[13]!==d?(f=i.jsxs("div",{className:"typography-code font-mono flex w-full min-w-0",style:o,children:[c,d]}),e[11]=o,e[12]=c,e[13]=d,e[14]=f):f=e[14],f});Me.displayName="VirtualizedCodeBlock.Row";const zt=n=>{const e="h-3.5 w-3.5 flex-shrink-0",t=n.toLowerCase();return t==="reasoning"?i.jsx(tt,{className:e}):t==="image-preview"?i.jsx(nt,{className:e}):t==="mermaid-preview"?i.jsx(De,{className:e}):t==="edit"||t==="multiedit"||t==="apply_patch"||t==="str_replace"||t==="str_replace_based_edit_tool"?i.jsx(it,{className:e}):t==="write"||t==="create"||t==="file_write"?i.jsx(Ee,{className:e}):t==="read"||t==="view"||t==="file_read"||t==="cat"?i.jsx(Ee,{className:e}):t==="bash"||t==="shell"||t==="cmd"||t==="terminal"?i.jsx(st,{className:e}):t==="list"||t==="ls"||t==="dir"||t==="list_files"?i.jsx(ot,{className:e}):t==="search"||t==="grep"||t==="find"||t==="ripgrep"?i.jsx(Ce,{className:e}):t==="glob"?i.jsx(rt,{className:e}):t==="fetch"||t==="curl"||t==="wget"||t==="webfetch"?i.jsx(at,{className:e}):t==="web-search"||t==="websearch"||t==="search_web"||t==="google"||t==="bing"||t==="duckduckgo"?i.jsx(Ce,{className:e}):t==="todowrite"||t==="todoread"?i.jsx(lt,{className:e}):t==="plan_enter"?i.jsx(De,{className:e}):t==="plan_exit"?i.jsx(ct,{className:e}):t.startsWith("git")?i.jsx(dt,{className:e}):i.jsx(Ve,{className:e})},$e=150,$t=40,Ht=120,Ft=3,Re={style:{background:"transparent",backgroundColor:"transparent",fontSize:"inherit"}},Vt={download:!1,copy:!1,fullscreen:!1,panZoom:!0},Wt=`
3
+ ${n}`,l=be.get(a);if(l!==void 0)return l;const o=Ie.languages[t]??Ie.languages.text;if(!o){const r=ze(n);return be.set(a,r),r}try{const r=Ie.highlight(n,o,t);if(be.size>=At){const s=be.keys().next().value;typeof s=="string"&&be.delete(s)}return be.set(a,r),r}catch{const r=ze(n);return be.set(a,r),r}};function ze(n){return n.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}const qe=v.memo(n=>{const e=me.c(26),{lines:t,language:a,syntaxTheme:l,maxHeight:o,showLineNumbers:r,lineStyles:s}=n,c=o===void 0?"60vh":o,d=r===void 0?!0:r;let f;e[0]!==l?(f=Dt(l),e[0]=l,e[1]=f):f=e[1];const g=f;if(!(t.length>Rt)){let b;e[2]!==c?(b={maxHeight:c,overflow:"auto"},e[2]=c,e[3]=b):b=e[3];let w;e[4]!==g?(w=g?i.jsx("style",{children:g}):null,e[4]=g,e[5]=w):w=e[5];let y;if(e[6]!==a||e[7]!==s||e[8]!==t||e[9]!==d){let x;e[11]!==a||e[12]!==s||e[13]!==d?(x=(_,k)=>i.jsx(Me,{line:_,language:a,showLineNumbers:d,style:s?.(_)},k),e[11]=a,e[12]=s,e[13]=d,e[14]=x):x=e[14],y=t.map(x),e[6]=a,e[7]=s,e[8]=t,e[9]=d,e[10]=y}else y=e[10];let I;return e[15]!==b||e[16]!==w||e[17]!==y?(I=i.jsxs("div",{className:"typography-code font-mono w-full min-w-0 oc-virtualized-prism",style:b,children:[w,y]}),e[15]=b,e[16]=w,e[17]=y,e[18]=I):I=e[18],I}let P;return e[19]!==a||e[20]!==s||e[21]!==t||e[22]!==c||e[23]!==g||e[24]!==d?(P=i.jsx(Je,{lines:t,language:a,prismThemeCss:g,maxHeight:c,showLineNumbers:d,lineStyles:s}),e[19]=a,e[20]=s,e[21]=t,e[22]=c,e[23]=g,e[24]=d,e[25]=P):P=e[25],P});qe.displayName="VirtualizedCodeBlock";const Je=v.memo(({lines:n,language:e,prismThemeCss:t,maxHeight:a,showLineNumbers:l,lineStyles:o})=>{const r=v.useRef(null),s=et({count:n.length,getScrollElement:()=>r.current,estimateSize:()=>Pt,overscan:20});return i.jsxs("div",{ref:r,className:"typography-code font-mono w-full min-w-0 oc-virtualized-prism",style:{maxHeight:a,overflow:"auto"},children:[t?i.jsx("style",{children:t}):null,i.jsx("div",{style:{height:`${s.getTotalSize()}px`,width:"100%",position:"relative"},children:s.getVirtualItems().map(c=>{const d=n[c.index];return i.jsx("div",{style:{position:"absolute",top:0,left:0,width:"100%",height:`${c.size}px`,transform:`translateY(${c.start}px)`},children:i.jsx(Me,{line:d,language:e,showLineNumbers:l,style:o?.(d)})},c.index)})})]})});Je.displayName="VirtualizedRows";const Me=v.memo(n=>{const e=me.c(15),{line:t,language:a,showLineNumbers:l,style:o}=n;let r;e[0]!==a||e[1]!==t.text?(r=Ot(t.text,a),e[0]=a,e[1]=t.text,e[2]=r):r=e[2];const s=r;let c;e[3]!==t.isInfo||e[4]!==t.lineNumber||e[5]!==l?(c=l&&i.jsx("span",{className:"w-10 flex-shrink-0 text-right pr-3 select-none border-r mr-3 -my-0.5 py-0.5",style:{color:"var(--tools-edit-line-number)",borderColor:"var(--tools-border)"},children:!t.isInfo&&t.lineNumber!=null?t.lineNumber:""}),e[3]=t.isInfo,e[4]=t.lineNumber,e[5]=l,e[6]=c):c=e[6];let d;e[7]!==s||e[8]!==t.isInfo||e[9]!==t.text?(d=i.jsx("div",{className:"flex-1 min-w-0",children:t.isInfo?i.jsx("div",{className:"whitespace-pre-wrap break-words text-muted-foreground/70 italic",children:t.text}):i.jsx("div",{className:"whitespace-pre",dangerouslySetInnerHTML:{__html:s}})}),e[7]=s,e[8]=t.isInfo,e[9]=t.text,e[10]=d):d=e[10];let f;return e[11]!==o||e[12]!==c||e[13]!==d?(f=i.jsxs("div",{className:"typography-code font-mono flex w-full min-w-0",style:o,children:[c,d]}),e[11]=o,e[12]=c,e[13]=d,e[14]=f):f=e[14],f});Me.displayName="VirtualizedCodeBlock.Row";const zt=n=>{const e="h-3.5 w-3.5 flex-shrink-0",t=n.toLowerCase();return t==="reasoning"?i.jsx(tt,{className:e}):t==="image-preview"?i.jsx(nt,{className:e}):t==="mermaid-preview"?i.jsx(De,{className:e}):t==="edit"||t==="multiedit"||t==="apply_patch"||t==="str_replace"||t==="str_replace_based_edit_tool"?i.jsx(it,{className:e}):t==="write"||t==="create"||t==="file_write"?i.jsx(Ee,{className:e}):t==="read"||t==="view"||t==="file_read"||t==="cat"?i.jsx(Ee,{className:e}):t==="bash"||t==="shell"||t==="cmd"||t==="terminal"?i.jsx(st,{className:e}):t==="list"||t==="ls"||t==="dir"||t==="list_files"?i.jsx(ot,{className:e}):t==="search"||t==="grep"||t==="find"||t==="ripgrep"?i.jsx(Ce,{className:e}):t==="glob"?i.jsx(rt,{className:e}):t==="fetch"||t==="curl"||t==="wget"||t==="webfetch"?i.jsx(at,{className:e}):t==="web-search"||t==="websearch"||t==="search_web"||t==="google"||t==="bing"||t==="duckduckgo"?i.jsx(Ce,{className:e}):t==="todowrite"||t==="todoread"?i.jsx(lt,{className:e}):t==="plan_enter"?i.jsx(De,{className:e}):t==="plan_exit"?i.jsx(ct,{className:e}):t.startsWith("git")?i.jsx(dt,{className:e}):i.jsx(Ve,{className:e})},$e=150,$t=40,Ft=120,Ht=3,Re={style:{background:"transparent",backgroundColor:"transparent",fontSize:"inherit"}},Vt={download:!1,copy:!1,fullscreen:!1,panZoom:!0},Wt=`
4
4
  [data-diff-header],
5
5
  [data-diff] {
6
6
  [data-separator] {
7
7
  height: 24px !important;
8
8
  }
9
9
  }
10
- `,Ut={hunkLineCount:50,lineHeight:24,diffHeaderHeight:44,hunkSeparatorHeight:24,fileGap:0},Bt=()=>{const n=me.c(22),e=Nt();let t;n[0]===Symbol.for("react.memo_cache_sentinel")?(t=Ae(!1),n[0]=t):t=n[0];const a=t;let l;n[1]===Symbol.for("react.memo_cache_sentinel")?(l=Ae(!0),n[1]=l):l=n[1];const o=l;let r;n[2]!==e?.availableThemes?(r=()=>e?.availableThemes??[a,o],n[2]=e?.availableThemes,n[3]=r):r=n[3],e?.availableThemes;let s;n[4]!==r?(s=r(),n[4]=r,n[5]=s):s=n[5];const c=s,d=e?.lightThemeId??a.metadata.id,f=e?.darkThemeId??o.metadata.id;let g;n[6]!==c||n[7]!==d?(g=c.find(N=>N.metadata.id===d)??a,n[6]=c,n[7]=d,n[8]=g):g=n[8];const D=g;let I;n[9]!==c||n[10]!==f?(I=c.find(N=>N.metadata.id===f)??o,n[9]=c,n[10]=f,n[11]=I):I=n[11];const b=I;let w,y;n[12]!==b||n[13]!==D?(w=()=>{Oe(D),Oe(b)},y=[b,D],n[12]=b,n[13]=D,n[14]=w,n[15]=y):(w=n[14],y=n[15]),v.useEffect(w,y);const P=e?.currentTheme.metadata.variant??"light";let x;n[16]!==b.metadata.id||n[17]!==D.metadata.id?(x={light:D.metadata.id,dark:b.metadata.id},n[16]=b.metadata.id,n[17]=D.metadata.id,n[18]=x):x=n[18];const _=P==="dark"?"dark":"light";let k;return n[19]!==x||n[20]!==_?(k={theme:x,themeType:_},n[19]=x,n[20]=_,n[21]=k):k=n[21],k},He=()=>({width:typeof window<"u"?window.innerWidth:0,height:typeof window<"u"?window.innerHeight:0}),Fe={mobile:{widthRatio:.94,heightRatio:.86,padding:10},desktop:{widthRatio:.8,heightRatio:.8,padding:16}},Gt=(n,e)=>{const t=e?Fe.mobile:Fe.desktop,a=Math.max(160,n.width-t.padding*2),l=Math.max(160,n.height-t.padding*2);return{maxWidth:Math.max(160,Math.min(a,n.width*t.widthRatio)),maxHeight:Math.max(160,Math.min(l,n.height*t.heightRatio))}},Kt=n=>{try{const o=Array.from(n.querySelectorAll("g"));let r=0,s=null;for(const c of o){if(!(c instanceof SVGGraphicsElement))continue;const d=c.getBBox();if(!(d.width>0&&d.height>0))continue;const f=d.width*d.height;f>r&&(r=f,s=d.width/d.height)}if(s&&Number.isFinite(s)&&s>0)return s}catch{}const e=n.getAttribute("viewBox");if(e){const o=e.trim().split(/\s+/).map(Number);if(o.length===4){const r=o[2],s=o[3];if(Number.isFinite(r)&&Number.isFinite(s)&&r>0&&s>0)return r/s}}const t=Number(n.getAttribute("width")),a=Number(n.getAttribute("height"));if(Number.isFinite(t)&&Number.isFinite(a)&&t>0&&a>0)return t/a;const l=n.getBoundingClientRect();return l.width>0&&l.height>0?l.width/l.height:null},Ze=n=>{const e=me.c(7),[t,a]=v.useState(n),[l,o]=v.useState(n),[r,s]=v.useState(!1);let c,d;e[0]!==n?(c=()=>{if(n){if(a(!0),s(!0),typeof window>"u"){o(!0);return}const D=window.requestAnimationFrame(()=>{o(!0)}),I=window.setTimeout(()=>{s(!1)},$e);return()=>{window.cancelAnimationFrame(D),window.clearTimeout(I)}}if(o(!1),s(!0),typeof window>"u"){a(!1);return}const g=window.setTimeout(()=>{a(!1),s(!1)},$e);return()=>{window.clearTimeout(g)}},d=[n],e[0]=n,e[1]=c,e[2]=d):(c=e[1],d=e[2]),v.useEffect(c,d);let f;return e[3]!==t||e[4]!==r||e[5]!==l?(f={isRendered:t,isVisible:l,isTransitioning:r},e[3]=t,e[4]=r,e[5]=l,e[6]=f):f=e[6],f},Ye=n=>{const e=me.c(3),[t,a]=v.useState(He);let l,o;return e[0]!==n?(l=()=>{if(!n||typeof window>"u")return;const r=()=>{a(He())};return r(),window.addEventListener("resize",r),()=>{window.removeEventListener("resize",r)}},o=[n],e[0]=n,e[1]=l,e[2]=o):(l=e[1],o=e[2]),v.useEffect(l,o),t},qt=n=>{const e=me.c(103),{popup:t,onOpenChange:a,isMobile:l}=n,{t:o}=Le();let r;e:{const u=t.image;if(!u){let R;e[0]===Symbol.for("react.memo_cache_sentinel")?(R=[],e[0]=R):R=e[0],r=R;break e}let h;e[1]!==u.gallery?(h=Array.isArray(u.gallery)?u.gallery.filter(Zt):[],e[1]=u.gallery,e[2]=h):h=e[2];const M=h;if(M.length>0){r=M;break e}let E;e[3]!==u.filename||e[4]!==u.mimeType||e[5]!==u.size||e[6]!==u.url?(E=[{url:u.url,mimeType:u.mimeType,filename:u.filename,size:u.size}],e[3]=u.filename,e[4]=u.mimeType,e[5]=u.size,e[6]=u.url,e[7]=E):E=e[7],r=E}const s=r,[c,d]=v.useState(0),[f,g]=v.useState(null),{isRendered:D,isVisible:I,isTransitioning:b}=Ze(t.open),w=Ye(t.open);let y;e[8]!==s||e[9]!==t.image||e[10]!==t.open?(y=()=>{if(!t.open||s.length===0)return;const u=typeof t.image?.index=="number"?t.image.index:-1;if(u>=0&&u<s.length){d(u);return}const h=t.image?.url?s.findIndex(M=>M.url===t.image?.url):-1;d(h>=0?h:0)},e[8]=s,e[9]=t.image,e[10]=t.open,e[11]=y):y=e[11];const P=t.image?.index,x=t.image?.url;let _;e[12]!==s||e[13]!==t.open||e[14]!==P||e[15]!==x?(_=[s,P,x,t.open],e[12]=s,e[13]=t.open,e[14]=P,e[15]=x,e[16]=_):_=e[16],v.useEffect(y,_);const k=s[c]??s[0]??t.image,N=k?.filename||t.title||"Image preview",p=s.length>1;let T;e[17]!==s.length?(T=()=>{s.length<=1||d(u=>(u-1+s.length)%s.length)},e[17]=s.length,e[18]=T):T=e[18];const S=T;let O;e[19]!==s.length?(O=()=>{s.length<=1||d(u=>(u+1)%s.length)},e[19]=s.length,e[20]=O):O=e[20];const m=O;let z,L;e[21]!==p||e[22]!==a||e[23]!==t.open||e[24]!==m||e[25]!==S?(z=()=>{if(!t.open)return;const u=h=>{if(h.key==="Escape"){a(!1);return}if(h.key==="ArrowLeft"&&p){h.preventDefault(),S();return}h.key==="ArrowRight"&&p&&(h.preventDefault(),m())};return window.addEventListener("keydown",u),()=>{window.removeEventListener("keydown",u)}},L=[p,a,t.open,m,S],e[21]=p,e[22]=a,e[23]=t.open,e[24]=m,e[25]=S,e[26]=z,e[27]=L):(z=e[26],L=e[27]),v.useEffect(z,L);let Y;e[28]===Symbol.for("react.memo_cache_sentinel")?(Y=()=>{g(null)},e[28]=Y):Y=e[28];const J=k?.url;let ne;e[29]!==J?(ne=[J],e[29]=J,e[30]=ne):ne=e[30],v.useEffect(Y,ne);let ye;e:{const u=Math.max(160,w.width*(l?.86:.75)),h=Math.max(160,w.height*(l?.72:.75));if(!f){let je;e[31]!==u?(je=Math.round(u),e[31]=u,e[32]=je):je=e[32];let ve;e[33]!==h?(ve=Math.round(h),e[33]=h,e[34]=ve):ve=e[34];let _e;e[35]!==je||e[36]!==ve?(_e={width:je,height:ve},e[35]=je,e[36]=ve,e[37]=_e):_e=e[37],ye=_e;break e}const M=u/f.width,E=h/f.height,R=Math.min(M,E);let C;e[38]!==f.width||e[39]!==R?(C=Math.round(f.width*R),e[38]=f.width,e[39]=R,e[40]=C):C=e[40];const Z=Math.max(1,C);let Te;e[41]!==f.height||e[42]!==R?(Te=Math.round(f.height*R),e[41]=f.height,e[42]=R,e[43]=Te):Te=e[43];const Ie=Math.max(1,Te);let Se;e[44]!==Z||e[45]!==Ie?(Se={width:Z,height:Ie},e[44]=Z,e[45]=Ie,e[46]=Se):Se=e[46],ye=Se}const pe=ye;if(!D||!k||typeof document>"u")return null;const ie=t.open?"pointer-events-auto":"pointer-events-none";let se;e[47]!==ie?(se=he("fixed inset-0 z-50",ie),e[47]=ie,e[48]=se):se=e[48];const ge=b&&"transition-opacity duration-150 ease-out",oe=I?"opacity-100":"opacity-0";let $;e[49]!==ge||e[50]!==oe?($=he("absolute inset-0 bg-black/40",ge,oe),e[49]=ge,e[50]=oe,e[51]=$):$=e[51];let H;e[52]!==a?(H=()=>a(!1),e[52]=a,e[53]=H):H=e[53];let re;e[54]!==$||e[55]!==H?(re=i.jsx("div",{"aria-hidden":"true",className:$,onMouseDown:H}),e[54]=$,e[55]=H,e[56]=re):re=e[56];let F;e[57]!==p||e[58]!==m||e[59]!==S||e[60]!==o?(F=p&&i.jsxs(i.Fragment,{children:[i.jsx("button",{type:"button",onMouseDown:Yt,onClick:S,className:"absolute left-3 top-1/2 -translate-y-1/2 z-10 h-10 w-10 flex items-center justify-center rounded-full bg-black/40 text-foreground/90 hover:bg-black/55 focus:outline-none focus:ring-2 focus:ring-primary/60","aria-label":o("chat.toolOutputDialog.image.previousAria"),children:i.jsx(ft,{className:"h-6 w-6"})}),i.jsx("button",{type:"button",onMouseDown:Xt,onClick:m,className:"absolute right-3 top-1/2 -translate-y-1/2 z-10 h-10 w-10 flex items-center justify-center rounded-full bg-black/40 text-foreground/90 hover:bg-black/55 focus:outline-none focus:ring-2 focus:ring-primary/60","aria-label":o("chat.toolOutputDialog.image.nextAria"),children:i.jsx(mt,{className:"h-6 w-6"})})]}),e[57]=p,e[58]=m,e[59]=S,e[60]=o,e[61]=F):F=e[61];const xe=l?"p-2.5":"p-4";let ae;e[62]!==xe?(ae=he("absolute inset-0 flex items-center justify-center pointer-events-none",xe),e[62]=xe,e[63]=ae):ae=e[63];const le=b&&"transition-opacity duration-150 ease-out",we=I?"opacity-100":"opacity-0";let V;e[64]!==le||e[65]!==we?(V=he("pointer-events-auto flex flex-col gap-2",le,we),e[64]=le,e[65]=we,e[66]=V):V=e[66];const ce=`${pe.width}px`;let W;e[67]!==ce?(W={width:ce},e[67]=ce,e[68]=W):W=e[68];let X;e[69]!==N?(X=i.jsx("div",{className:"min-w-0 flex-1 text-foreground typography-ui-header font-semibold truncate",title:N,children:N}),e[69]=N,e[70]=X):X=e[70];let U;e[71]!==a?(U=()=>a(!1),e[71]=a,e[72]=U):U=e[72];let de;e[73]!==o?(de=o("chat.toolOutputDialog.image.closeAria"),e[73]=o,e[74]=de):de=e[74];let Q;e[75]===Symbol.for("react.memo_cache_sentinel")?(Q=i.jsx(Be,{className:"h-4 w-4"}),e[75]=Q):Q=e[75];let B;e[76]!==U||e[77]!==de?(B=i.jsx("button",{type:"button",className:"h-8 w-8 flex items-center justify-center rounded-lg text-muted-foreground/80 hover:text-foreground focus:outline-none focus:ring-2 focus:ring-primary/60",onClick:U,"aria-label":de,children:Q}),e[76]=U,e[77]=de,e[78]=B):B=e[78];let G;e[79]!==X||e[80]!==B?(G=i.jsxs("div",{className:"flex items-center justify-between gap-2",children:[X,B]}),e[79]=X,e[80]=B,e[81]=G):G=e[81];const ue=`${pe.width}px`,fe=`${pe.height}px`;let K;e[82]!==ue||e[83]!==fe?(K={width:ue,height:fe},e[82]=ue,e[83]=fe,e[84]=K):K=e[84];let ee;e[85]===Symbol.for("react.memo_cache_sentinel")?(ee=u=>{const h=u.currentTarget,M=h.naturalWidth,E=h.naturalHeight;M>0&&E>0&&g(R=>R&&R.width===M&&R.height===E?R:{width:M,height:E})},e[85]=ee):ee=e[85];let q;e[86]!==k.url||e[87]!==N||e[88]!==K?(q=i.jsx("img",{src:k.url,alt:N,className:"block object-contain",style:K,loading:"lazy",onLoad:ee}),e[86]=k.url,e[87]=N,e[88]=K,e[89]=q):q=e[89];let te;e[90]!==V||e[91]!==W||e[92]!==G||e[93]!==q?(te=i.jsxs("div",{className:V,style:W,children:[G,q]}),e[90]=V,e[91]=W,e[92]=G,e[93]=q,e[94]=te):te=e[94];let j;e[95]!==ae||e[96]!==te?(j=i.jsx("div",{className:ae,children:te}),e[95]=ae,e[96]=te,e[97]=j):j=e[97];let A;if(e[98]!==se||e[99]!==re||e[100]!==F||e[101]!==j){const u=i.jsxs("div",{className:se,children:[re,F,j]});A=Ue.createPortal(u,document.body),e[98]=se,e[99]=re,e[100]=F,e[101]=j,e[102]=A}else A=e[102];return A},Xe=v.memo(n=>{const e=me.c(7),{popup:t,diffViewMode:a,pierreThemeConfig:l}=n,o=t.content||"",r=a==="unified"?"unified":"split";let s;e[0]!==l.theme||e[1]!==l.themeType||e[2]!==r?(s={diffStyle:r,diffIndicators:"none",hunkSeparators:"line-info-basic",lineDiffType:"none",disableFileHeader:!0,maxLineDiffLength:1e3,expansionLineCount:20,overflow:"wrap",theme:l.theme,themeType:l.themeType,unsafeCSS:Wt},e[0]=l.theme,e[1]=l.themeType,e[2]=r,e[3]=s):s=e[3];let c;return e[4]!==o||e[5]!==s?(c=i.jsx("div",{className:"typography-code",children:i.jsx(ut,{patch:o,metrics:Ut,options:s,className:"block w-full"})}),e[4]=o,e[5]=s,e[6]=c):c=e[6],c});Xe.displayName="DialogUnifiedDiff";const Qe=v.memo(n=>{const e=me.c(30),{popup:t,syntaxTheme:a,pierreThemeConfig:l}=n;let o;e[0]!==t.content?(o=Tt(t.content),e[0]=t.content,e[1]=o):o=e[1];const r=o,s=t.metadata?.input;let c;e[2]!==s?(c=typeof s=="object"&&s!==null?s:{},e[2]=s,e[3]=c):c=e[3];const d=c,f=typeof d.offset=="number"?d.offset:0,g=typeof d.file_path=="string"?d.file_path:typeof d.filePath=="string"?d.filePath:typeof d.path=="string"?d.path:"read-output";let D;e[4]!==r.lines?(D=r.lines.map(Qt).join(`
11
- `),e[4]=r.lines,e[5]=D):D=e[5];const I=D;let b;e[6]!==g||e[7]!==t.language?(b=t.language||Ge(g)||"text",e[6]=g,e[7]=t.language,e[8]=b):b=e[8];const w=b;let y;e[9]!==r.lines?(y=r.lines.some(en),e[9]=r.lines,e[10]=y):y=e[10];const P=y;let x;if(e[11]!==P||e[12]!==f||e[13]!==r.lines||e[14]!==r.type){x=[];let N=f;for(const p of r.lines){p.lineNumber!==null&&(N=p.lineNumber);const T=r.type==="file"&&!P&&p.lineNumber===null&&!p.isInfo,S=p.lineNumber??(T?N+1:null);typeof S=="number"&&(N=S),x.push({text:p.text,lineNumber:S,isInfo:p.isInfo})}e[11]=P,e[12]=f,e[13]=r.lines,e[14]=r.type,e[15]=x}else x=e[15];const _=x;if(r.type==="file"){const N=w||void 0;let p;e[16]!==I||e[17]!==g||e[18]!==N?(p={name:g,contents:I,lang:N},e[16]=I,e[17]=g,e[18]=N,e[19]=p):p=e[19];let T;e[20]!==l.theme||e[21]!==l.themeType?(T={disableFileHeader:!0,overflow:"wrap",theme:l.theme,themeType:l.themeType},e[20]=l.theme,e[21]=l.themeType,e[22]=T):T=e[22];let S;return e[23]!==p||e[24]!==T?(S=i.jsx(We,{file:p,options:T,className:"block w-full"}),e[23]=p,e[24]=T,e[25]=S):S=e[25],S}let k;return e[26]!==_||e[27]!==w||e[28]!==a?(k=i.jsx(qe,{lines:_,language:w,syntaxTheme:a,maxHeight:"70vh"}),e[26]=_,e[27]=w,e[28]=a,e[29]=k):k=e[29],k});Qe.displayName="DialogReadContent";const Jt=n=>{const e=me.c(89),{popup:t,onOpenChange:a,isMobile:l}=n,{t:o}=Le(),[r,s]=v.useState(t.mermaid?.source||""),[c,d]=v.useState(t.mermaid?.source?"ready":"idle"),[f,g]=v.useState(""),{isRendered:D,isVisible:I,isTransitioning:b}=Ze(t.open),[w,y]=v.useState(null),P=Ye(t.open),x=v.useRef(0),_=v.useRef(null),k=on,N=rn;let p;e[0]!==t.mermaid||e[1]!==o?(p=async()=>{const j=t.mermaid;if(!j?.url){d("error"),g(o("chat.toolOutputDialog.mermaid.missingSource"));return}if(j.source){s(j.source),d("ready"),g("");return}const A=x.current+1;x.current=A,d("loading"),g("");let u;if(j.url.startsWith("data:"))u=Promise.resolve(N(j.url));else if(j.url.toLowerCase().startsWith("file://")){const h=k(j.url);h?u=fetch(`/api/fs/raw?path=${encodeURIComponent(h)}`).then(an):u=Promise.reject(new Error("Invalid local file path for Mermaid preview."))}else{const M=(typeof URL.canParse=="function"?URL.canParse(j.url,window.location.origin):!1)?new URL(j.url,window.location.origin):null;!M||M.protocol!=="http:"&&M.protocol!=="https:"?u=Promise.reject(new Error("Unsupported Mermaid URL protocol.")):u=fetch(M.toString()).then(ln)}await u.then(h=>{x.current===A&&(s(h),d("ready"))}).catch(h=>{x.current===A&&(d("error"),g(h instanceof Error?h.message:o("chat.toolOutputDialog.mermaid.loadFailed")))})},e[0]=t.mermaid,e[1]=o,e[2]=p):p=e[2];const T=p;let S,O;e[3]!==T||e[4]!==t.mermaid||e[5]!==t.open?(S=()=>{!t.open||!t.mermaid||T()},O=[T,t.mermaid,t.open],e[3]=T,e[4]=t.mermaid,e[5]=t.open,e[6]=S,e[7]=O):(S=e[6],O=e[7]),v.useEffect(S,O);let m,z;e[8]!==a||e[9]!==t.open?(m=()=>{if(!t.open)return;const j=A=>{A.key==="Escape"&&a(!1)};return window.addEventListener("keydown",j),()=>{window.removeEventListener("keydown",j)}},z=[a,t.open],e[8]=a,e[9]=t.open,e[10]=m,e[11]=z):(m=e[10],z=e[11]),v.useEffect(m,z);let L;e[12]!==t.open||e[13]!==c?(L=()=>{if(!t.open||c!=="ready"){y(null);return}const j=()=>{const R=_.current?.querySelector("svg");if(!R)return!1;const C=Kt(R);return!C||!Number.isFinite(C)||C<=0?!1:(y(Z=>Z&&Math.abs(Z-C)<.001?Z:C),!0)};let A=window.requestAnimationFrame(()=>{j()||(A=window.requestAnimationFrame(()=>{j()}))}),u=0,h;const M=()=>{u>=Ft||(h=window.setTimeout(()=>{u=u+1,j()||M()},Ht))};M();const E=new MutationObserver(()=>{j()});return _.current&&E.observe(_.current,{childList:!0,subtree:!0,attributes:!0}),()=>{window.cancelAnimationFrame(A),typeof h=="number"&&window.clearTimeout(h),E.disconnect()}},e[12]=t.open,e[13]=c,e[14]=L):L=e[14];let Y;e[15]!==t.open||e[16]!==r||e[17]!==c?(Y=[t.open,r,c],e[15]=t.open,e[16]=r,e[17]=c,e[18]=Y):Y=e[18],v.useEffect(L,Y);const J=`\`\`\`mermaid
10
+ `,Ut={hunkLineCount:50,lineHeight:24,diffHeaderHeight:44,hunkSeparatorHeight:24,fileGap:0},Bt=()=>{const n=me.c(22),e=Nt();let t;n[0]===Symbol.for("react.memo_cache_sentinel")?(t=Ae(!1),n[0]=t):t=n[0];const a=t;let l;n[1]===Symbol.for("react.memo_cache_sentinel")?(l=Ae(!0),n[1]=l):l=n[1];const o=l;let r;n[2]!==e?.availableThemes?(r=()=>e?.availableThemes??[a,o],n[2]=e?.availableThemes,n[3]=r):r=n[3],e?.availableThemes;let s;n[4]!==r?(s=r(),n[4]=r,n[5]=s):s=n[5];const c=s,d=e?.lightThemeId??a.metadata.id,f=e?.darkThemeId??o.metadata.id;let g;n[6]!==c||n[7]!==d?(g=c.find(N=>N.metadata.id===d)??a,n[6]=c,n[7]=d,n[8]=g):g=n[8];const D=g;let P;n[9]!==c||n[10]!==f?(P=c.find(N=>N.metadata.id===f)??o,n[9]=c,n[10]=f,n[11]=P):P=n[11];const b=P;let w,y;n[12]!==b||n[13]!==D?(w=()=>{Oe(D),Oe(b)},y=[b,D],n[12]=b,n[13]=D,n[14]=w,n[15]=y):(w=n[14],y=n[15]),v.useEffect(w,y);const I=e?.currentTheme.metadata.variant??"light";let x;n[16]!==b.metadata.id||n[17]!==D.metadata.id?(x={light:D.metadata.id,dark:b.metadata.id},n[16]=b.metadata.id,n[17]=D.metadata.id,n[18]=x):x=n[18];const _=I==="dark"?"dark":"light";let k;return n[19]!==x||n[20]!==_?(k={theme:x,themeType:_},n[19]=x,n[20]=_,n[21]=k):k=n[21],k},Fe=()=>({width:typeof window<"u"?window.innerWidth:0,height:typeof window<"u"?window.innerHeight:0}),He={mobile:{widthRatio:.94,heightRatio:.86,padding:10},desktop:{widthRatio:.8,heightRatio:.8,padding:16}},Gt=(n,e)=>{const t=e?He.mobile:He.desktop,a=Math.max(160,n.width-t.padding*2),l=Math.max(160,n.height-t.padding*2);return{maxWidth:Math.max(160,Math.min(a,n.width*t.widthRatio)),maxHeight:Math.max(160,Math.min(l,n.height*t.heightRatio))}},Kt=n=>{try{const o=Array.from(n.querySelectorAll("g"));let r=0,s=null;for(const c of o){if(!(c instanceof SVGGraphicsElement))continue;const d=c.getBBox();if(!(d.width>0&&d.height>0))continue;const f=d.width*d.height;f>r&&(r=f,s=d.width/d.height)}if(s&&Number.isFinite(s)&&s>0)return s}catch{}const e=n.getAttribute("viewBox");if(e){const o=e.trim().split(/\s+/).map(Number);if(o.length===4){const r=o[2],s=o[3];if(Number.isFinite(r)&&Number.isFinite(s)&&r>0&&s>0)return r/s}}const t=Number(n.getAttribute("width")),a=Number(n.getAttribute("height"));if(Number.isFinite(t)&&Number.isFinite(a)&&t>0&&a>0)return t/a;const l=n.getBoundingClientRect();return l.width>0&&l.height>0?l.width/l.height:null},Ze=n=>{const e=me.c(7),[t,a]=v.useState(n),[l,o]=v.useState(n),[r,s]=v.useState(!1);let c,d;e[0]!==n?(c=()=>{if(n){if(a(!0),s(!0),typeof window>"u"){o(!0);return}const D=window.requestAnimationFrame(()=>{o(!0)}),P=window.setTimeout(()=>{s(!1)},$e);return()=>{window.cancelAnimationFrame(D),window.clearTimeout(P)}}if(o(!1),s(!0),typeof window>"u"){a(!1);return}const g=window.setTimeout(()=>{a(!1),s(!1)},$e);return()=>{window.clearTimeout(g)}},d=[n],e[0]=n,e[1]=c,e[2]=d):(c=e[1],d=e[2]),v.useEffect(c,d);let f;return e[3]!==t||e[4]!==r||e[5]!==l?(f={isRendered:t,isVisible:l,isTransitioning:r},e[3]=t,e[4]=r,e[5]=l,e[6]=f):f=e[6],f},Ye=n=>{const e=me.c(3),[t,a]=v.useState(Fe);let l,o;return e[0]!==n?(l=()=>{if(!n||typeof window>"u")return;const r=()=>{a(Fe())};return r(),window.addEventListener("resize",r),()=>{window.removeEventListener("resize",r)}},o=[n],e[0]=n,e[1]=l,e[2]=o):(l=e[1],o=e[2]),v.useEffect(l,o),t},qt=n=>{const e=me.c(103),{popup:t,onOpenChange:a,isMobile:l}=n,{t:o}=Le();let r;e:{const u=t.image;if(!u){let R;e[0]===Symbol.for("react.memo_cache_sentinel")?(R=[],e[0]=R):R=e[0],r=R;break e}let h;e[1]!==u.gallery?(h=Array.isArray(u.gallery)?u.gallery.filter(Zt):[],e[1]=u.gallery,e[2]=h):h=e[2];const M=h;if(M.length>0){r=M;break e}let E;e[3]!==u.filename||e[4]!==u.mimeType||e[5]!==u.size||e[6]!==u.url?(E=[{url:u.url,mimeType:u.mimeType,filename:u.filename,size:u.size}],e[3]=u.filename,e[4]=u.mimeType,e[5]=u.size,e[6]=u.url,e[7]=E):E=e[7],r=E}const s=r,[c,d]=v.useState(0),[f,g]=v.useState(null),{isRendered:D,isVisible:P,isTransitioning:b}=Ze(t.open),w=Ye(t.open);let y;e[8]!==s||e[9]!==t.image||e[10]!==t.open?(y=()=>{if(!t.open||s.length===0)return;const u=typeof t.image?.index=="number"?t.image.index:-1;if(u>=0&&u<s.length){d(u);return}const h=t.image?.url?s.findIndex(M=>M.url===t.image?.url):-1;d(h>=0?h:0)},e[8]=s,e[9]=t.image,e[10]=t.open,e[11]=y):y=e[11];const I=t.image?.index,x=t.image?.url;let _;e[12]!==s||e[13]!==t.open||e[14]!==I||e[15]!==x?(_=[s,I,x,t.open],e[12]=s,e[13]=t.open,e[14]=I,e[15]=x,e[16]=_):_=e[16],v.useEffect(y,_);const k=s[c]??s[0]??t.image,N=k?.filename||t.title||"Image preview",p=s.length>1;let T;e[17]!==s.length?(T=()=>{s.length<=1||d(u=>(u-1+s.length)%s.length)},e[17]=s.length,e[18]=T):T=e[18];const S=T;let O;e[19]!==s.length?(O=()=>{s.length<=1||d(u=>(u+1)%s.length)},e[19]=s.length,e[20]=O):O=e[20];const m=O;let z,L;e[21]!==p||e[22]!==a||e[23]!==t.open||e[24]!==m||e[25]!==S?(z=()=>{if(!t.open)return;const u=h=>{if(h.key==="Escape"){a(!1);return}if(h.key==="ArrowLeft"&&p){h.preventDefault(),S();return}h.key==="ArrowRight"&&p&&(h.preventDefault(),m())};return window.addEventListener("keydown",u),()=>{window.removeEventListener("keydown",u)}},L=[p,a,t.open,m,S],e[21]=p,e[22]=a,e[23]=t.open,e[24]=m,e[25]=S,e[26]=z,e[27]=L):(z=e[26],L=e[27]),v.useEffect(z,L);let Y;e[28]===Symbol.for("react.memo_cache_sentinel")?(Y=()=>{g(null)},e[28]=Y):Y=e[28];const J=k?.url;let ne;e[29]!==J?(ne=[J],e[29]=J,e[30]=ne):ne=e[30],v.useEffect(Y,ne);let ye;e:{const u=Math.max(160,w.width*(l?.86:.75)),h=Math.max(160,w.height*(l?.72:.75));if(!f){let je;e[31]!==u?(je=Math.round(u),e[31]=u,e[32]=je):je=e[32];let ve;e[33]!==h?(ve=Math.round(h),e[33]=h,e[34]=ve):ve=e[34];let _e;e[35]!==je||e[36]!==ve?(_e={width:je,height:ve},e[35]=je,e[36]=ve,e[37]=_e):_e=e[37],ye=_e;break e}const M=u/f.width,E=h/f.height,R=Math.min(M,E);let C;e[38]!==f.width||e[39]!==R?(C=Math.round(f.width*R),e[38]=f.width,e[39]=R,e[40]=C):C=e[40];const Z=Math.max(1,C);let Te;e[41]!==f.height||e[42]!==R?(Te=Math.round(f.height*R),e[41]=f.height,e[42]=R,e[43]=Te):Te=e[43];const Pe=Math.max(1,Te);let Se;e[44]!==Z||e[45]!==Pe?(Se={width:Z,height:Pe},e[44]=Z,e[45]=Pe,e[46]=Se):Se=e[46],ye=Se}const pe=ye;if(!D||!k||typeof document>"u")return null;const ie=t.open?"pointer-events-auto":"pointer-events-none";let se;e[47]!==ie?(se=he("fixed inset-0 z-50",ie),e[47]=ie,e[48]=se):se=e[48];const ge=b&&"transition-opacity duration-150 ease-out",oe=P?"opacity-100":"opacity-0";let $;e[49]!==ge||e[50]!==oe?($=he("absolute inset-0 bg-black/40",ge,oe),e[49]=ge,e[50]=oe,e[51]=$):$=e[51];let F;e[52]!==a?(F=()=>a(!1),e[52]=a,e[53]=F):F=e[53];let re;e[54]!==$||e[55]!==F?(re=i.jsx("div",{"aria-hidden":"true",className:$,onMouseDown:F}),e[54]=$,e[55]=F,e[56]=re):re=e[56];let H;e[57]!==p||e[58]!==m||e[59]!==S||e[60]!==o?(H=p&&i.jsxs(i.Fragment,{children:[i.jsx("button",{type:"button",onMouseDown:Yt,onClick:S,className:"absolute left-3 top-1/2 -translate-y-1/2 z-10 h-10 w-10 flex items-center justify-center rounded-full bg-black/40 text-foreground/90 hover:bg-black/55 focus:outline-none focus:ring-2 focus:ring-primary/60","aria-label":o("chat.toolOutputDialog.image.previousAria"),children:i.jsx(ft,{className:"h-6 w-6"})}),i.jsx("button",{type:"button",onMouseDown:Qt,onClick:m,className:"absolute right-3 top-1/2 -translate-y-1/2 z-10 h-10 w-10 flex items-center justify-center rounded-full bg-black/40 text-foreground/90 hover:bg-black/55 focus:outline-none focus:ring-2 focus:ring-primary/60","aria-label":o("chat.toolOutputDialog.image.nextAria"),children:i.jsx(mt,{className:"h-6 w-6"})})]}),e[57]=p,e[58]=m,e[59]=S,e[60]=o,e[61]=H):H=e[61];const xe=l?"p-2.5":"p-4";let ae;e[62]!==xe?(ae=he("absolute inset-0 flex items-center justify-center pointer-events-none",xe),e[62]=xe,e[63]=ae):ae=e[63];const le=b&&"transition-opacity duration-150 ease-out",we=P?"opacity-100":"opacity-0";let V;e[64]!==le||e[65]!==we?(V=he("pointer-events-auto flex flex-col gap-2",le,we),e[64]=le,e[65]=we,e[66]=V):V=e[66];const ce=`${pe.width}px`;let W;e[67]!==ce?(W={width:ce},e[67]=ce,e[68]=W):W=e[68];let Q;e[69]!==N?(Q=i.jsx("div",{className:"min-w-0 flex-1 text-foreground typography-ui-header font-semibold truncate",title:N,children:N}),e[69]=N,e[70]=Q):Q=e[70];let U;e[71]!==a?(U=()=>a(!1),e[71]=a,e[72]=U):U=e[72];let de;e[73]!==o?(de=o("chat.toolOutputDialog.image.closeAria"),e[73]=o,e[74]=de):de=e[74];let X;e[75]===Symbol.for("react.memo_cache_sentinel")?(X=i.jsx(Be,{className:"h-4 w-4"}),e[75]=X):X=e[75];let B;e[76]!==U||e[77]!==de?(B=i.jsx("button",{type:"button",className:"h-8 w-8 flex items-center justify-center rounded-lg text-muted-foreground/80 hover:text-foreground focus:outline-none focus:ring-2 focus:ring-primary/60",onClick:U,"aria-label":de,children:X}),e[76]=U,e[77]=de,e[78]=B):B=e[78];let G;e[79]!==Q||e[80]!==B?(G=i.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Q,B]}),e[79]=Q,e[80]=B,e[81]=G):G=e[81];const ue=`${pe.width}px`,fe=`${pe.height}px`;let K;e[82]!==ue||e[83]!==fe?(K={width:ue,height:fe},e[82]=ue,e[83]=fe,e[84]=K):K=e[84];let ee;e[85]===Symbol.for("react.memo_cache_sentinel")?(ee=u=>{const h=u.currentTarget,M=h.naturalWidth,E=h.naturalHeight;M>0&&E>0&&g(R=>R&&R.width===M&&R.height===E?R:{width:M,height:E})},e[85]=ee):ee=e[85];let q;e[86]!==k.url||e[87]!==N||e[88]!==K?(q=i.jsx("img",{src:k.url,alt:N,className:"block object-contain",style:K,loading:"lazy",onLoad:ee}),e[86]=k.url,e[87]=N,e[88]=K,e[89]=q):q=e[89];let te;e[90]!==V||e[91]!==W||e[92]!==G||e[93]!==q?(te=i.jsxs("div",{className:V,style:W,children:[G,q]}),e[90]=V,e[91]=W,e[92]=G,e[93]=q,e[94]=te):te=e[94];let j;e[95]!==ae||e[96]!==te?(j=i.jsx("div",{className:ae,children:te}),e[95]=ae,e[96]=te,e[97]=j):j=e[97];let A;if(e[98]!==se||e[99]!==re||e[100]!==H||e[101]!==j){const u=i.jsxs("div",{className:se,children:[re,H,j]});A=Ue.createPortal(u,document.body),e[98]=se,e[99]=re,e[100]=H,e[101]=j,e[102]=A}else A=e[102];return A},Qe=v.memo(n=>{const e=me.c(7),{popup:t,diffViewMode:a,pierreThemeConfig:l}=n,o=t.content||"",r=a==="unified"?"unified":"split";let s;e[0]!==l.theme||e[1]!==l.themeType||e[2]!==r?(s={diffStyle:r,diffIndicators:"none",hunkSeparators:"line-info-basic",lineDiffType:"none",disableFileHeader:!0,maxLineDiffLength:1e3,expansionLineCount:20,overflow:"wrap",theme:l.theme,themeType:l.themeType,unsafeCSS:Wt},e[0]=l.theme,e[1]=l.themeType,e[2]=r,e[3]=s):s=e[3];let c;return e[4]!==o||e[5]!==s?(c=i.jsx("div",{className:"typography-code",children:i.jsx(ut,{patch:o,metrics:Ut,options:s,className:"block w-full"})}),e[4]=o,e[5]=s,e[6]=c):c=e[6],c});Qe.displayName="DialogUnifiedDiff";const Xe=v.memo(n=>{const e=me.c(30),{popup:t,syntaxTheme:a,pierreThemeConfig:l}=n;let o;e[0]!==t.content?(o=Tt(t.content),e[0]=t.content,e[1]=o):o=e[1];const r=o,s=t.metadata?.input;let c;e[2]!==s?(c=typeof s=="object"&&s!==null?s:{},e[2]=s,e[3]=c):c=e[3];const d=c,f=typeof d.offset=="number"?d.offset:0,g=typeof d.file_path=="string"?d.file_path:typeof d.filePath=="string"?d.filePath:typeof d.path=="string"?d.path:"read-output";let D;e[4]!==r.lines?(D=r.lines.map(Xt).join(`
11
+ `),e[4]=r.lines,e[5]=D):D=e[5];const P=D;let b;e[6]!==g||e[7]!==t.language?(b=t.language||Ge(g)||"text",e[6]=g,e[7]=t.language,e[8]=b):b=e[8];const w=b;let y;e[9]!==r.lines?(y=r.lines.some(en),e[9]=r.lines,e[10]=y):y=e[10];const I=y;let x;if(e[11]!==I||e[12]!==f||e[13]!==r.lines||e[14]!==r.type){x=[];let N=f;for(const p of r.lines){p.lineNumber!==null&&(N=p.lineNumber);const T=r.type==="file"&&!I&&p.lineNumber===null&&!p.isInfo,S=p.lineNumber??(T?N+1:null);typeof S=="number"&&(N=S),x.push({text:p.text,lineNumber:S,isInfo:p.isInfo})}e[11]=I,e[12]=f,e[13]=r.lines,e[14]=r.type,e[15]=x}else x=e[15];const _=x;if(r.type==="file"){const N=w||void 0;let p;e[16]!==P||e[17]!==g||e[18]!==N?(p={name:g,contents:P,lang:N},e[16]=P,e[17]=g,e[18]=N,e[19]=p):p=e[19];let T;e[20]!==l.theme||e[21]!==l.themeType?(T={disableFileHeader:!0,overflow:"wrap",theme:l.theme,themeType:l.themeType},e[20]=l.theme,e[21]=l.themeType,e[22]=T):T=e[22];let S;return e[23]!==p||e[24]!==T?(S=i.jsx(We,{file:p,options:T,className:"block w-full"}),e[23]=p,e[24]=T,e[25]=S):S=e[25],S}let k;return e[26]!==_||e[27]!==w||e[28]!==a?(k=i.jsx(qe,{lines:_,language:w,syntaxTheme:a,maxHeight:"70vh"}),e[26]=_,e[27]=w,e[28]=a,e[29]=k):k=e[29],k});Xe.displayName="DialogReadContent";const Jt=n=>{const e=me.c(89),{popup:t,onOpenChange:a,isMobile:l}=n,{t:o}=Le(),[r,s]=v.useState(t.mermaid?.source||""),[c,d]=v.useState(t.mermaid?.source?"ready":"idle"),[f,g]=v.useState(""),{isRendered:D,isVisible:P,isTransitioning:b}=Ze(t.open),[w,y]=v.useState(null),I=Ye(t.open),x=v.useRef(0),_=v.useRef(null),k=on,N=rn;let p;e[0]!==t.mermaid||e[1]!==o?(p=async()=>{const j=t.mermaid;if(!j?.url){d("error"),g(o("chat.toolOutputDialog.mermaid.missingSource"));return}if(j.source){s(j.source),d("ready"),g("");return}const A=x.current+1;x.current=A,d("loading"),g("");let u;if(j.url.startsWith("data:"))u=Promise.resolve(N(j.url));else if(j.url.toLowerCase().startsWith("file://")){const h=k(j.url);h?u=fetch(`/api/fs/raw?path=${encodeURIComponent(h)}`).then(an):u=Promise.reject(new Error("Invalid local file path for Mermaid preview."))}else{const M=(typeof URL.canParse=="function"?URL.canParse(j.url,window.location.origin):!1)?new URL(j.url,window.location.origin):null;!M||M.protocol!=="http:"&&M.protocol!=="https:"?u=Promise.reject(new Error("Unsupported Mermaid URL protocol.")):u=fetch(M.toString()).then(ln)}await u.then(h=>{x.current===A&&(s(h),d("ready"))}).catch(h=>{x.current===A&&(d("error"),g(h instanceof Error?h.message:o("chat.toolOutputDialog.mermaid.loadFailed")))})},e[0]=t.mermaid,e[1]=o,e[2]=p):p=e[2];const T=p;let S,O;e[3]!==T||e[4]!==t.mermaid||e[5]!==t.open?(S=()=>{!t.open||!t.mermaid||T()},O=[T,t.mermaid,t.open],e[3]=T,e[4]=t.mermaid,e[5]=t.open,e[6]=S,e[7]=O):(S=e[6],O=e[7]),v.useEffect(S,O);let m,z;e[8]!==a||e[9]!==t.open?(m=()=>{if(!t.open)return;const j=A=>{A.key==="Escape"&&a(!1)};return window.addEventListener("keydown",j),()=>{window.removeEventListener("keydown",j)}},z=[a,t.open],e[8]=a,e[9]=t.open,e[10]=m,e[11]=z):(m=e[10],z=e[11]),v.useEffect(m,z);let L;e[12]!==t.open||e[13]!==c?(L=()=>{if(!t.open||c!=="ready"){y(null);return}const j=()=>{const R=_.current?.querySelector("svg");if(!R)return!1;const C=Kt(R);return!C||!Number.isFinite(C)||C<=0?!1:(y(Z=>Z&&Math.abs(Z-C)<.001?Z:C),!0)};let A=window.requestAnimationFrame(()=>{j()||(A=window.requestAnimationFrame(()=>{j()}))}),u=0,h;const M=()=>{u>=Ht||(h=window.setTimeout(()=>{u=u+1,j()||M()},Ft))};M();const E=new MutationObserver(()=>{j()});return _.current&&E.observe(_.current,{childList:!0,subtree:!0,attributes:!0}),()=>{window.cancelAnimationFrame(A),typeof h=="number"&&window.clearTimeout(h),E.disconnect()}},e[12]=t.open,e[13]=c,e[14]=L):L=e[14];let Y;e[15]!==t.open||e[16]!==r||e[17]!==c?(Y=[t.open,r,c],e[15]=t.open,e[16]=r,e[17]=c,e[18]=Y):Y=e[18],v.useEffect(L,Y);const J=`\`\`\`mermaid
12
12
  ${r}
13
- \`\`\``;let ne;if(e[19]!==w||e[20]!==l||e[21]!==P){e:{const{maxWidth:j,maxHeight:A}=Gt(P,l),u=Math.max(160,A-$t);if(w&&w<1){const E=Math.min(j,u);let R;e[23]!==E?(R=Math.round(E),e[23]=E,e[24]=R):R=e[24];let C;e[25]!==E?(C=Math.round(E),e[25]=E,e[26]=C):C=e[26];let Z;e[27]!==C||e[28]!==R?(Z={width:R,height:C},e[27]=C,e[28]=R,e[29]=Z):Z=e[29],ne=Z;break e}const h=Math.round(j);let M;e[30]!==u?(M=Math.round(u),e[30]=u,e[31]=M):M=e[31],ne={width:h,height:M}}e[19]=w,e[20]=l,e[21]=P,e[22]=ne}else ne=e[22];const ye=ne;if(!D||typeof document>"u")return null;const pe=t.open?"pointer-events-auto":"pointer-events-none";let ie;e[32]!==pe?(ie=he("fixed inset-0 z-50",pe),e[32]=pe,e[33]=ie):ie=e[33];const se=b&&"transition-opacity duration-150 ease-out",ge=I?"opacity-100":"opacity-0";let oe;e[34]!==se||e[35]!==ge?(oe=he("absolute inset-0 bg-black/40",se,ge),e[34]=se,e[35]=ge,e[36]=oe):oe=e[36];let $;e[37]!==a?($=()=>a(!1),e[37]=a,e[38]=$):$=e[38];let H;e[39]!==oe||e[40]!==$?(H=i.jsx("div",{"aria-hidden":"true",className:oe,onMouseDown:$}),e[39]=oe,e[40]=$,e[41]=H):H=e[41];const re=l?"p-2.5":"p-4";let F;e[42]!==re?(F=he("absolute inset-0 flex items-center justify-center pointer-events-none",re),e[42]=re,e[43]=F):F=e[43];const xe=b&&"transition-opacity duration-150 ease-out",ae=I?"opacity-100":"opacity-0";let le;e[44]!==xe||e[45]!==ae?(le=he("pointer-events-auto flex flex-col gap-2",xe,ae),e[44]=xe,e[45]=ae,e[46]=le):le=e[46];const we=`${ye.width}px`;let V;e[47]!==we?(V={width:we},e[47]=we,e[48]=V):V=e[48];let ce;e[49]!==a?(ce=()=>a(!1),e[49]=a,e[50]=ce):ce=e[50];let W;e[51]!==o?(W=o("chat.toolOutputDialog.mermaid.closeAria"),e[51]=o,e[52]=W):W=e[52];let X;e[53]===Symbol.for("react.memo_cache_sentinel")?(X=i.jsx(Be,{className:"h-4 w-4"}),e[53]=X):X=e[53];let U;e[54]!==ce||e[55]!==W?(U=i.jsx("div",{className:"flex items-center justify-end",children:i.jsx("button",{type:"button",className:"h-8 w-8 flex items-center justify-center rounded-lg text-muted-foreground/80 hover:text-foreground focus:outline-none focus:ring-2 focus:ring-primary/60",onClick:ce,"aria-label":W,children:X})}),e[54]=ce,e[55]=W,e[56]=U):U=e[56];const de=`${ye.height}px`;let Q;e[57]!==de?(Q={height:de},e[57]=de,e[58]=Q):Q=e[58];let B;e[59]!==c||e[60]!==o?(B=c==="loading"&&i.jsxs("div",{className:"h-full min-h-28 flex items-center justify-center gap-2 text-muted-foreground typography-meta",children:[i.jsx(ht,{className:"h-4 w-4 animate-spin"}),i.jsx("span",{children:o("chat.toolOutputDialog.mermaid.loading")})]}),e[59]=c,e[60]=o,e[61]=B):B=e[61];let G;e[62]!==f||e[63]!==T||e[64]!==c||e[65]!==o?(G=c==="error"&&i.jsxs("div",{className:"rounded-xl border border-border/30 bg-muted/20 p-3 space-y-3",children:[i.jsx("p",{className:"typography-markdown",style:{color:"var(--status-error)"},children:f||o("chat.toolOutputDialog.mermaid.renderFailed")}),i.jsx("button",{type:"button",onClick:()=>{T()},className:"px-3 py-1.5 rounded-lg typography-meta border transition-colors hover:bg-[var(--interactive-hover)]",style:{borderColor:"var(--interactive-border)",color:"var(--surface-foreground)"},children:o("chat.toolOutputDialog.mermaid.retry")})]}),e[62]=f,e[63]=T,e[64]=c,e[65]=o,e[66]=G):G=e[66];let ue;e[67]!==J||e[68]!==c?(ue=c==="ready"&&i.jsx("div",{ref:_,className:"h-full",children:i.jsx(Ke,{content:J,variant:"tool",allowMermaidWheelZoom:!0,className:"markdown-mermaid-fullscreen h-full [&_[data-markdown='mermaid-block']_button]:hidden",mermaidControls:Vt})}),e[67]=J,e[68]=c,e[69]=ue):ue=e[69];let fe;e[70]!==B||e[71]!==G||e[72]!==ue?(fe=i.jsxs("div",{className:"h-full overflow-hidden",children:[B,G,ue]}),e[70]=B,e[71]=G,e[72]=ue,e[73]=fe):fe=e[73];let K;e[74]!==Q||e[75]!==fe?(K=i.jsx("div",{className:"relative overflow-hidden",style:Q,children:fe}),e[74]=Q,e[75]=fe,e[76]=K):K=e[76];let ee;e[77]!==le||e[78]!==V||e[79]!==U||e[80]!==K?(ee=i.jsxs("div",{className:le,style:V,onMouseDown:cn,children:[U,K]}),e[77]=le,e[78]=V,e[79]=U,e[80]=K,e[81]=ee):ee=e[81];let q;e[82]!==F||e[83]!==ee?(q=i.jsx("div",{className:F,children:ee}),e[82]=F,e[83]=ee,e[84]=q):q=e[84];let te;if(e[85]!==ie||e[86]!==H||e[87]!==q){const j=i.jsxs("div",{className:ie,children:[H,q]});te=Ue.createPortal(j,document.body),e[85]=ie,e[86]=H,e[87]=q,e[88]=te}else te=e[88];return te},hn=n=>{const e=me.c(50),{popup:t,onOpenChange:a,syntaxTheme:l,isMobile:o}=n,{t:r}=Le(),[s,c]=v.useState("unified"),d=Bt();let f;e[0]!==t.open?(f=()=>{t.open&&c("unified")},e[0]=t.open,e[1]=f):f=e[1];let g;if(e[2]!==t.open||e[3]!==t.title?(g=[t.open,t.title],e[2]=t.open,e[3]=t.title,e[4]=g):g=e[4],v.useEffect(f,g),t.image){let m;return e[5]!==o||e[6]!==a||e[7]!==t?(m=i.jsx(qt,{popup:t,onOpenChange:a,isMobile:o}),e[5]=o,e[6]=a,e[7]=t,e[8]=m):m=e[8],m}if(t.mermaid){let m;return e[9]!==o||e[10]!==a||e[11]!==t?(m=i.jsx(Jt,{popup:t,onOpenChange:a,isMobile:o}),e[9]=o,e[10]=a,e[11]=t,e[12]=m):m=e[12],m}const D=t.open,I=o?"w-[95vw] max-w-[95vw]":"max-w-5xl",b=o?"[&>button]:right-1":"[&>button]:top-2.5 [&>button]:right-4";let w;e[13]!==I||e[14]!==b?(w=he("overflow-hidden flex flex-col min-h-0 pt-3 pb-4 px-4 gap-1","[&>button]:top-1.5",I,b),e[13]=I,e[14]=b,e[15]=w):w=e[15];let y;e[16]===Symbol.for("react.memo_cache_sentinel")?(y={maxHeight:"90vh"},e[16]=y):y=e[16];let P;e[17]!==t.metadata?(P=t.metadata?.tool?zt(t.metadata.tool):i.jsx(Ve,{className:"h-3.5 w-3.5 text-foreground flex-shrink-0"}),e[17]=t.metadata,e[18]=P):P=e[18];let x;e[19]!==t.title?(x=i.jsx("span",{className:"break-words flex-1 leading-tight",children:t.title}),e[19]=t.title,e[20]=x):x=e[20];let _;e[21]!==s||e[22]!==t.isDiff?(_=t.isDiff&&i.jsx(pt,{mode:s,onModeChange:c,className:"mr-8 flex-shrink-0"}),e[21]=s,e[22]=t.isDiff,e[23]=_):_=e[23];let k;e[24]!==_||e[25]!==P||e[26]!==x?(k=i.jsx("div",{className:"flex-shrink-0 pb-1",children:i.jsxs("div",{className:"flex items-start gap-2 text-foreground typography-ui-header font-semibold",children:[P,x,_]})}),e[24]=_,e[25]=P,e[26]=x,e[27]=k):k=e[27];let N;e[28]!==d||e[29]!==t.metadata||e[30]!==l?(N=t.metadata?.input&&typeof t.metadata.input=="object"&&Object.keys(t.metadata.input).length>0&&t.metadata?.tool!=="todowrite"&&t.metadata?.tool!=="todoread"&&t.metadata?.tool!=="apply_patch"?(()=>{const m=t.metadata,z=m.input,L=Y=>{const J=z[Y];return typeof J=="string"?J:typeof J=="number"?String(J):null};return i.jsxs("div",{className:"border-b border-border/20 p-4 -mx-3",children:[i.jsx("div",{className:"typography-markdown font-medium text-muted-foreground mb-2 px-3",children:m.tool==="bash"?"Command:":m.tool==="task"?"Task Details:":"Input:"}),m.tool==="bash"&&L("command")?i.jsx("div",{className:"tool-input-surface bg-transparent rounded-xl border border-border/20 mx-3",children:i.jsx(ke,{style:l,language:"bash",PreTag:"div",customStyle:Ne.getPopupStyles(),codeTagProps:Re,wrapLongLines:!0,children:L("command")})}):m.tool==="task"&&L("prompt")?i.jsxs("div",{className:"tool-input-surface bg-transparent rounded-xl border border-border/20 font-mono whitespace-pre-wrap text-foreground/90 mx-3",style:Ne.getPopupStyles(),children:[L("description")?`Task: ${L("description")}
13
+ \`\`\``;let ne;if(e[19]!==w||e[20]!==l||e[21]!==I){e:{const{maxWidth:j,maxHeight:A}=Gt(I,l),u=Math.max(160,A-$t);if(w&&w<1){const E=Math.min(j,u);let R;e[23]!==E?(R=Math.round(E),e[23]=E,e[24]=R):R=e[24];let C;e[25]!==E?(C=Math.round(E),e[25]=E,e[26]=C):C=e[26];let Z;e[27]!==C||e[28]!==R?(Z={width:R,height:C},e[27]=C,e[28]=R,e[29]=Z):Z=e[29],ne=Z;break e}const h=Math.round(j);let M;e[30]!==u?(M=Math.round(u),e[30]=u,e[31]=M):M=e[31],ne={width:h,height:M}}e[19]=w,e[20]=l,e[21]=I,e[22]=ne}else ne=e[22];const ye=ne;if(!D||typeof document>"u")return null;const pe=t.open?"pointer-events-auto":"pointer-events-none";let ie;e[32]!==pe?(ie=he("fixed inset-0 z-50",pe),e[32]=pe,e[33]=ie):ie=e[33];const se=b&&"transition-opacity duration-150 ease-out",ge=P?"opacity-100":"opacity-0";let oe;e[34]!==se||e[35]!==ge?(oe=he("absolute inset-0 bg-black/40",se,ge),e[34]=se,e[35]=ge,e[36]=oe):oe=e[36];let $;e[37]!==a?($=()=>a(!1),e[37]=a,e[38]=$):$=e[38];let F;e[39]!==oe||e[40]!==$?(F=i.jsx("div",{"aria-hidden":"true",className:oe,onMouseDown:$}),e[39]=oe,e[40]=$,e[41]=F):F=e[41];const re=l?"p-2.5":"p-4";let H;e[42]!==re?(H=he("absolute inset-0 flex items-center justify-center pointer-events-none",re),e[42]=re,e[43]=H):H=e[43];const xe=b&&"transition-opacity duration-150 ease-out",ae=P?"opacity-100":"opacity-0";let le;e[44]!==xe||e[45]!==ae?(le=he("pointer-events-auto flex flex-col gap-2",xe,ae),e[44]=xe,e[45]=ae,e[46]=le):le=e[46];const we=`${ye.width}px`;let V;e[47]!==we?(V={width:we},e[47]=we,e[48]=V):V=e[48];let ce;e[49]!==a?(ce=()=>a(!1),e[49]=a,e[50]=ce):ce=e[50];let W;e[51]!==o?(W=o("chat.toolOutputDialog.mermaid.closeAria"),e[51]=o,e[52]=W):W=e[52];let Q;e[53]===Symbol.for("react.memo_cache_sentinel")?(Q=i.jsx(Be,{className:"h-4 w-4"}),e[53]=Q):Q=e[53];let U;e[54]!==ce||e[55]!==W?(U=i.jsx("div",{className:"flex items-center justify-end",children:i.jsx("button",{type:"button",className:"h-8 w-8 flex items-center justify-center rounded-lg text-muted-foreground/80 hover:text-foreground focus:outline-none focus:ring-2 focus:ring-primary/60",onClick:ce,"aria-label":W,children:Q})}),e[54]=ce,e[55]=W,e[56]=U):U=e[56];const de=`${ye.height}px`;let X;e[57]!==de?(X={height:de},e[57]=de,e[58]=X):X=e[58];let B;e[59]!==c||e[60]!==o?(B=c==="loading"&&i.jsxs("div",{className:"h-full min-h-28 flex items-center justify-center gap-2 text-muted-foreground typography-meta",children:[i.jsx(ht,{className:"h-4 w-4 animate-spin"}),i.jsx("span",{children:o("chat.toolOutputDialog.mermaid.loading")})]}),e[59]=c,e[60]=o,e[61]=B):B=e[61];let G;e[62]!==f||e[63]!==T||e[64]!==c||e[65]!==o?(G=c==="error"&&i.jsxs("div",{className:"rounded-xl border border-border/30 bg-muted/20 p-3 space-y-3",children:[i.jsx("p",{className:"typography-markdown",style:{color:"var(--status-error)"},children:f||o("chat.toolOutputDialog.mermaid.renderFailed")}),i.jsx("button",{type:"button",onClick:()=>{T()},className:"px-3 py-1.5 rounded-lg typography-meta border transition-colors hover:bg-[var(--interactive-hover)]",style:{borderColor:"var(--interactive-border)",color:"var(--surface-foreground)"},children:o("chat.toolOutputDialog.mermaid.retry")})]}),e[62]=f,e[63]=T,e[64]=c,e[65]=o,e[66]=G):G=e[66];let ue;e[67]!==J||e[68]!==c?(ue=c==="ready"&&i.jsx("div",{ref:_,className:"h-full",children:i.jsx(Ke,{content:J,variant:"tool",allowMermaidWheelZoom:!0,className:"markdown-mermaid-fullscreen h-full [&_[data-markdown='mermaid-block']_button]:hidden",mermaidControls:Vt})}),e[67]=J,e[68]=c,e[69]=ue):ue=e[69];let fe;e[70]!==B||e[71]!==G||e[72]!==ue?(fe=i.jsxs("div",{className:"h-full overflow-hidden",children:[B,G,ue]}),e[70]=B,e[71]=G,e[72]=ue,e[73]=fe):fe=e[73];let K;e[74]!==X||e[75]!==fe?(K=i.jsx("div",{className:"relative overflow-hidden",style:X,children:fe}),e[74]=X,e[75]=fe,e[76]=K):K=e[76];let ee;e[77]!==le||e[78]!==V||e[79]!==U||e[80]!==K?(ee=i.jsxs("div",{className:le,style:V,onMouseDown:cn,children:[U,K]}),e[77]=le,e[78]=V,e[79]=U,e[80]=K,e[81]=ee):ee=e[81];let q;e[82]!==H||e[83]!==ee?(q=i.jsx("div",{className:H,children:ee}),e[82]=H,e[83]=ee,e[84]=q):q=e[84];let te;if(e[85]!==ie||e[86]!==F||e[87]!==q){const j=i.jsxs("div",{className:ie,children:[F,q]});te=Ue.createPortal(j,document.body),e[85]=ie,e[86]=F,e[87]=q,e[88]=te}else te=e[88];return te},hn=n=>{const e=me.c(50),{popup:t,onOpenChange:a,syntaxTheme:l,isMobile:o}=n,{t:r}=Le(),[s,c]=v.useState("unified"),d=Bt();let f;e[0]!==t.open?(f=()=>{t.open&&c("unified")},e[0]=t.open,e[1]=f):f=e[1];let g;if(e[2]!==t.open||e[3]!==t.title?(g=[t.open,t.title],e[2]=t.open,e[3]=t.title,e[4]=g):g=e[4],v.useEffect(f,g),t.image){let m;return e[5]!==o||e[6]!==a||e[7]!==t?(m=i.jsx(qt,{popup:t,onOpenChange:a,isMobile:o}),e[5]=o,e[6]=a,e[7]=t,e[8]=m):m=e[8],m}if(t.mermaid){let m;return e[9]!==o||e[10]!==a||e[11]!==t?(m=i.jsx(Jt,{popup:t,onOpenChange:a,isMobile:o}),e[9]=o,e[10]=a,e[11]=t,e[12]=m):m=e[12],m}const D=t.open,P=o?"w-[95vw] max-w-[95vw]":"max-w-5xl",b=o?"[&>button]:right-1":"[&>button]:top-2.5 [&>button]:right-4";let w;e[13]!==P||e[14]!==b?(w=he("overflow-hidden flex flex-col min-h-0 pt-3 pb-4 px-4 gap-1","[&>button]:top-1.5",P,b),e[13]=P,e[14]=b,e[15]=w):w=e[15];let y;e[16]===Symbol.for("react.memo_cache_sentinel")?(y={maxHeight:"90vh"},e[16]=y):y=e[16];let I;e[17]!==t.metadata?(I=t.metadata?.tool?zt(t.metadata.tool):i.jsx(Ve,{className:"h-3.5 w-3.5 text-foreground flex-shrink-0"}),e[17]=t.metadata,e[18]=I):I=e[18];let x;e[19]!==t.title?(x=i.jsx("span",{className:"break-words flex-1 leading-tight",children:t.title}),e[19]=t.title,e[20]=x):x=e[20];let _;e[21]!==s||e[22]!==t.isDiff?(_=t.isDiff&&i.jsx(pt,{mode:s,onModeChange:c,className:"mr-8 flex-shrink-0"}),e[21]=s,e[22]=t.isDiff,e[23]=_):_=e[23];let k;e[24]!==_||e[25]!==I||e[26]!==x?(k=i.jsx("div",{className:"flex-shrink-0 pb-1",children:i.jsxs("div",{className:"flex items-start gap-2 text-foreground typography-ui-header font-semibold",children:[I,x,_]})}),e[24]=_,e[25]=I,e[26]=x,e[27]=k):k=e[27];let N;e[28]!==d||e[29]!==t.metadata||e[30]!==l?(N=t.metadata?.input&&typeof t.metadata.input=="object"&&Object.keys(t.metadata.input).length>0&&t.metadata?.tool!=="todowrite"&&t.metadata?.tool!=="todoread"&&t.metadata?.tool!=="apply_patch"?(()=>{const m=t.metadata,z=m.input,L=Y=>{const J=z[Y];return typeof J=="string"?J:typeof J=="number"?String(J):null};return i.jsxs("div",{className:"border-b border-border/20 p-4 -mx-3",children:[i.jsx("div",{className:"typography-markdown font-medium text-muted-foreground mb-2 px-3",children:m.tool==="bash"?"Command:":m.tool==="task"?"Task Details:":"Input:"}),m.tool==="bash"&&L("command")?i.jsx("div",{className:"tool-input-surface bg-transparent rounded-xl border border-border/20 mx-3",children:i.jsx(ke,{style:l,language:"bash",PreTag:"div",customStyle:Ne.getPopupStyles(),codeTagProps:Re,wrapLongLines:!0,children:L("command")})}):m.tool==="task"&&L("prompt")?i.jsxs("div",{className:"tool-input-surface bg-transparent rounded-xl border border-border/20 font-mono whitespace-pre-wrap text-foreground/90 mx-3",style:Ne.getPopupStyles(),children:[L("description")?`Task: ${L("description")}
14
14
  `:"",L("subagent_type")?`Agent Type: ${L("subagent_type")}
15
15
  `:"",`Instructions:
16
- ${L("prompt")}`]}):m.tool==="write"&&L("content")?i.jsx("div",{className:"tool-input-surface bg-transparent rounded-xl border border-border/20 mx-3",children:i.jsx(We,{file:{name:L("filePath")||L("file_path")||"new-file",contents:L("content"),lang:Ge(L("filePath")||L("file_path")||"")||void 0},options:{disableFileHeader:!0,overflow:"wrap",theme:d.theme,themeType:d.themeType},className:"block w-full"})}):i.jsx("div",{className:"tool-input-surface bg-transparent rounded-xl border border-border/20 font-mono whitespace-pre-wrap text-foreground/90 mx-3",style:Ne.getPopupStyles(),children:gt(z,m.tool)})]})})():null,e[28]=d,e[29]=t.metadata,e[30]=l,e[31]=N):N=e[31];let p;e[32]!==s||e[33]!==o||e[34]!==d||e[35]!==t||e[36]!==l||e[37]!==r?(p=t.isDiff?i.jsx(Xe,{popup:t,diffViewMode:s,pierreThemeConfig:d}):t.content?i.jsx("div",{className:"p-4",children:(()=>{const m=t.metadata?.tool;return m==="todowrite"||m==="todoread"?xt(t.content,{total:r("chat.todo.total"),inProgress:r("chat.todo.inProgress"),pending:r("chat.todo.pending"),completed:r("chat.todo.completed"),cancelled:r("chat.todo.cancelled")})||i.jsx(ke,{style:l,language:"json",PreTag:"div",wrapLongLines:!0,customStyle:Ne.getPopupContainerStyles(),codeTagProps:Re,children:t.content}):m==="list"?wt(t.content)||i.jsx("pre",{className:"typography-markdown bg-muted/30 p-2 rounded-xl border border-border/20 font-mono whitespace-pre-wrap",children:t.content}):m==="grep"?bt(t.content,o)||i.jsx("pre",{className:"typography-code bg-muted/30 p-2 rounded-xl border border-border/20 font-mono whitespace-pre-wrap",children:t.content}):m==="glob"?yt(t.content,o)||i.jsx("pre",{className:"typography-code bg-muted/30 p-2 rounded-xl border border-border/20 font-mono whitespace-pre-wrap",children:t.content}):m==="task"||m==="reasoning"?i.jsx("div",{className:m==="reasoning"?"text-muted-foreground/70":"",children:i.jsx(Ke,{content:t.content,variant:"tool"})}):m==="web-search"||m==="websearch"||m==="search_web"?jt(t.content)||i.jsx(ke,{style:l,language:"text",PreTag:"div",wrapLongLines:!0,customStyle:Ne.getPopupContainerStyles(),codeTagProps:Re,children:t.content}):m==="read"?i.jsx(Qe,{popup:t,syntaxTheme:l,pierreThemeConfig:d}):(t.content?vt(t.content):{isJson:!1}).isJson?i.jsx(kt,{jsonString:t.content,initiallyExpandedDepth:3,maxHeight:"70vh"}):i.jsx(ke,{style:l,language:t.language||"text",PreTag:"div",wrapLongLines:!0,customStyle:Ne.getPopupContainerStyles(),codeTagProps:Re,children:t.content})})()}):i.jsxs("div",{className:"p-8 text-muted-foreground typography-ui-header",children:[i.jsx("div",{className:"mb-2",children:r("chat.toolOutputDialog.commandCompleted")}),i.jsx("div",{className:"typography-meta",children:r("chat.toolOutputDialog.noOutputProduced")})]}),e[32]=s,e[33]=o,e[34]=d,e[35]=t,e[36]=l,e[37]=r,e[38]=p):p=e[38];let T;e[39]!==N||e[40]!==p?(T=i.jsx("div",{className:"flex-1 min-h-0 rounded-xl border border-border/30 bg-muted/10 overflow-hidden",children:i.jsxs("div",{className:"tool-output-surface h-full max-h-[75vh] overflow-y-auto px-3 pr-4",children:[N,p]})}),e[39]=N,e[40]=p,e[41]=T):T=e[41];let S;e[42]!==k||e[43]!==T||e[44]!==w?(S=i.jsxs(St,{className:w,style:y,children:[k,T]}),e[42]=k,e[43]=T,e[44]=w,e[45]=S):S=e[45];let O;return e[46]!==a||e[47]!==t.open||e[48]!==S?(O=i.jsx(_t,{open:D,onOpenChange:a,children:S}),e[46]=a,e[47]=t.open,e[48]=S,e[49]=O):O=e[49],O};function Zt(n){return!!n?.url}function Yt(n){return n.stopPropagation()}function Xt(n){return n.stopPropagation()}function Qt(n){return n.text}function en(n){return n.lineNumber!==null}function tn(n){if(!n||/[\0\r\n]/.test(n))return!1;const e=n.replace(/\\/g,"/");return e.split("/").filter(Boolean).includes("..")?!1:e.startsWith("/")?!0:/^[A-Za-z]:\//.test(e)}function nn(n,e){const t=Number.parseInt(e,16);return Number.isFinite(t)?String.fromCharCode(t):`%${e}`}function sn(n){return n.replace(/%([0-9A-Fa-f]{2})/g,nn)}function on(n){const e=n.trim();if(!e.toLowerCase().startsWith("file://"))return null;const t=tn,a=sn;if(typeof URL.canParse=="function"?URL.canParse(e):!1){let s=a(new URL(e).pathname||"");return/^\/[A-Za-z]:\//.test(s)&&(s=s.slice(1)),t(s)?s:null}const o=e.replace(/^file:\/\//i,""),r=a(o);return t(r)?r:t(o)?o:null}function rn(n){const e=n.indexOf(",");if(e<0)throw new Error("Malformed data URL");const t=n.slice(0,e).toLowerCase(),a=n.slice(e+1);return t.includes(";base64")?atob(a):decodeURIComponent(a)}function an(n){return n.ok?n.text():Promise.reject(new Error(`Failed to read diagram file (${n.status})`))}function ln(n){return n.ok?n.text():Promise.reject(new Error(`Failed to load diagram (${n.status})`))}function cn(n){return n.stopPropagation()}export{hn as default};
16
+ ${L("prompt")}`]}):m.tool==="write"&&L("content")?i.jsx("div",{className:"tool-input-surface bg-transparent rounded-xl border border-border/20 mx-3",children:i.jsx(We,{file:{name:L("filePath")||L("file_path")||"new-file",contents:L("content"),lang:Ge(L("filePath")||L("file_path")||"")||void 0},options:{disableFileHeader:!0,overflow:"wrap",theme:d.theme,themeType:d.themeType},className:"block w-full"})}):i.jsx("div",{className:"tool-input-surface bg-transparent rounded-xl border border-border/20 font-mono whitespace-pre-wrap text-foreground/90 mx-3",style:Ne.getPopupStyles(),children:gt(z,m.tool)})]})})():null,e[28]=d,e[29]=t.metadata,e[30]=l,e[31]=N):N=e[31];let p;e[32]!==s||e[33]!==o||e[34]!==d||e[35]!==t||e[36]!==l||e[37]!==r?(p=t.isDiff?i.jsx(Qe,{popup:t,diffViewMode:s,pierreThemeConfig:d}):t.content?i.jsx("div",{className:"p-4",children:(()=>{const m=t.metadata?.tool;return m==="todowrite"||m==="todoread"?xt(t.content,{total:r("chat.todo.total"),inProgress:r("chat.todo.inProgress"),pending:r("chat.todo.pending"),completed:r("chat.todo.completed"),cancelled:r("chat.todo.cancelled")})||i.jsx(ke,{style:l,language:"json",PreTag:"div",wrapLongLines:!0,customStyle:Ne.getPopupContainerStyles(),codeTagProps:Re,children:t.content}):m==="list"?wt(t.content)||i.jsx("pre",{className:"typography-markdown bg-muted/30 p-2 rounded-xl border border-border/20 font-mono whitespace-pre-wrap",children:t.content}):m==="grep"?bt(t.content,o)||i.jsx("pre",{className:"typography-code bg-muted/30 p-2 rounded-xl border border-border/20 font-mono whitespace-pre-wrap",children:t.content}):m==="glob"?yt(t.content,o)||i.jsx("pre",{className:"typography-code bg-muted/30 p-2 rounded-xl border border-border/20 font-mono whitespace-pre-wrap",children:t.content}):m==="task"||m==="reasoning"?i.jsx("div",{className:m==="reasoning"?"text-muted-foreground/70":"",children:i.jsx(Ke,{content:t.content,variant:"tool"})}):m==="web-search"||m==="websearch"||m==="search_web"?jt(t.content)||i.jsx(ke,{style:l,language:"text",PreTag:"div",wrapLongLines:!0,customStyle:Ne.getPopupContainerStyles(),codeTagProps:Re,children:t.content}):m==="read"?i.jsx(Xe,{popup:t,syntaxTheme:l,pierreThemeConfig:d}):(t.content?vt(t.content):{isJson:!1}).isJson?i.jsx(kt,{jsonString:t.content,initiallyExpandedDepth:3,maxHeight:"70vh"}):i.jsx(ke,{style:l,language:t.language||"text",PreTag:"div",wrapLongLines:!0,customStyle:Ne.getPopupContainerStyles(),codeTagProps:Re,children:t.content})})()}):i.jsxs("div",{className:"p-8 text-muted-foreground typography-ui-header",children:[i.jsx("div",{className:"mb-2",children:r("chat.toolOutputDialog.commandCompleted")}),i.jsx("div",{className:"typography-meta",children:r("chat.toolOutputDialog.noOutputProduced")})]}),e[32]=s,e[33]=o,e[34]=d,e[35]=t,e[36]=l,e[37]=r,e[38]=p):p=e[38];let T;e[39]!==N||e[40]!==p?(T=i.jsx("div",{className:"flex-1 min-h-0 rounded-xl border border-border/30 bg-muted/10 overflow-hidden",children:i.jsxs("div",{className:"tool-output-surface h-full max-h-[75vh] overflow-y-auto px-3 pr-4",children:[N,p]})}),e[39]=N,e[40]=p,e[41]=T):T=e[41];let S;e[42]!==k||e[43]!==T||e[44]!==w?(S=i.jsxs(St,{className:w,style:y,children:[k,T]}),e[42]=k,e[43]=T,e[44]=w,e[45]=S):S=e[45];let O;return e[46]!==a||e[47]!==t.open||e[48]!==S?(O=i.jsx(_t,{open:D,onOpenChange:a,children:S}),e[46]=a,e[47]=t.open,e[48]=S,e[49]=O):O=e[49],O};function Zt(n){return!!n?.url}function Yt(n){return n.stopPropagation()}function Qt(n){return n.stopPropagation()}function Xt(n){return n.text}function en(n){return n.lineNumber!==null}function tn(n){if(!n||/[\0\r\n]/.test(n))return!1;const e=n.replace(/\\/g,"/");return e.split("/").filter(Boolean).includes("..")?!1:e.startsWith("/")?!0:/^[A-Za-z]:\//.test(e)}function nn(n,e){const t=Number.parseInt(e,16);return Number.isFinite(t)?String.fromCharCode(t):`%${e}`}function sn(n){return n.replace(/%([0-9A-Fa-f]{2})/g,nn)}function on(n){const e=n.trim();if(!e.toLowerCase().startsWith("file://"))return null;const t=tn,a=sn;if(typeof URL.canParse=="function"?URL.canParse(e):!1){let s=a(new URL(e).pathname||"");return/^\/[A-Za-z]:\//.test(s)&&(s=s.slice(1)),t(s)?s:null}const o=e.replace(/^file:\/\//i,""),r=a(o);return t(r)?r:t(o)?o:null}function rn(n){const e=n.indexOf(",");if(e<0)throw new Error("Malformed data URL");const t=n.slice(0,e).toLowerCase(),a=n.slice(e+1);return t.includes(";base64")?atob(a):decodeURIComponent(a)}function an(n){return n.ok?n.text():Promise.reject(new Error(`Failed to read diagram file (${n.status})`))}function ln(n){return n.ok?n.text():Promise.reject(new Error(`Failed to load diagram (${n.status})`))}function cn(n){return n.stopPropagation()}export{hn as default};