@openchamber/web 1.16.0 → 1.16.1

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 (54) hide show
  1. package/README.md +5 -5
  2. package/dist/assets/{DiagramView-he_RFVx5.js → DiagramView-Elkp8b4l.js} +1 -1
  3. package/dist/assets/{MarkdownRendererImpl-CdBIHSPZ.js → MarkdownRendererImpl-DLhrL6oX.js} +4 -4
  4. package/dist/assets/{MultiRunWindow-B_C-tvVq.js → MultiRunWindow-DVpNCqnE.js} +1 -1
  5. package/dist/assets/{OnboardingScreen-BBnTt-9w.js → OnboardingScreen-CpcR0gyq.js} +1 -1
  6. package/dist/assets/SessionSwitcherDropdown-DHO5Je6v.js +1 -0
  7. package/dist/assets/{SettingsWindow-CjqLdpTE.js → SettingsWindow-Bewo7vwh.js} +1 -1
  8. package/dist/assets/{TerminalView-DQcdegHp.js → TerminalView-D9C7fNLm.js} +1 -1
  9. package/dist/assets/es-D9nOo8Wx.js +15 -0
  10. package/dist/assets/fr-DEF71lgt.js +13 -0
  11. package/dist/assets/index-BklNmnVr.js +2 -0
  12. package/dist/assets/index-C3uMIExE.css +1 -0
  13. package/dist/assets/ja-CpNfaEje.js +15 -0
  14. package/dist/assets/ko-DLS_rnE-.js +15 -0
  15. package/dist/assets/main-B0CxEOP5.js +237 -0
  16. package/dist/assets/{main-Dfm-VKZ9.js → main-Ck3ZNw8-.js} +2 -2
  17. package/dist/assets/miniChat-BAJj2Ome.js +2 -0
  18. package/dist/assets/mobile-CJoX4Cdj.js +2 -0
  19. package/dist/assets/pl-BjtFn5-n.js +15 -0
  20. package/dist/assets/pt-BR-C0_4Rnzn.js +15 -0
  21. package/dist/assets/renderElectronMiniChatApp-D4-OXCXM.js +2 -0
  22. package/dist/assets/{renderMobileApp-o7Fs9EBx.js → renderMobileApp-DHWdI195.js} +3 -3
  23. package/dist/assets/runtimeEndpointReset-B0P2DED1.js +167 -0
  24. package/dist/assets/uk-BDu4E0s0.js +15 -0
  25. package/dist/assets/{useAppFontEffects-DkPuAMXD.js → useAppFontEffects-9LFMCKYW.js} +127 -127
  26. package/dist/assets/zh-CN-BcwMqxIR.js +15 -0
  27. package/dist/assets/zh-TW-bNDQjKEu.js +15 -0
  28. package/dist/index.html +3 -3
  29. package/dist/mini-chat.html +3 -3
  30. package/dist/mobile.html +3 -3
  31. package/package.json +1 -1
  32. package/server/lib/opencode/settings-helpers.js +9 -0
  33. package/server/lib/package-manager.js +1 -1
  34. package/server/lib/small-model/DOCUMENTATION.md +3 -1
  35. package/server/lib/small-model/call.js +45 -8
  36. package/server/lib/small-model/call.test.js +338 -0
  37. package/server/lib/small-model/index.js +1 -0
  38. package/dist/assets/SessionSwitcherDropdown-CWWrCFzr.js +0 -1
  39. package/dist/assets/es-r0_jT91q.js +0 -15
  40. package/dist/assets/fr-Bo8rtAJ1.js +0 -13
  41. package/dist/assets/index-8J6waVO6.js +0 -2
  42. package/dist/assets/index-DEMqM4Lz.css +0 -1
  43. package/dist/assets/ja-BPWtkG-c.js +0 -15
  44. package/dist/assets/ko-Bv0k-0E3.js +0 -15
  45. package/dist/assets/main-B-GA5Tg5.js +0 -237
  46. package/dist/assets/miniChat-CfmCFFfu.js +0 -2
  47. package/dist/assets/mobile-CXJqeDlm.js +0 -2
  48. package/dist/assets/pl-CiTP50bz.js +0 -15
  49. package/dist/assets/pt-BR-DadIjX5L.js +0 -15
  50. package/dist/assets/renderElectronMiniChatApp-DS7Dy2ii.js +0 -2
  51. package/dist/assets/runtimeEndpointReset-MTaPPm4F.js +0 -167
  52. package/dist/assets/uk-2RpsWGoZ.js +0 -15
  53. package/dist/assets/zh-CN-BwKWaTuz.js +0 -15
  54. package/dist/assets/zh-TW--f_BqBpD.js +0 -15
@@ -1 +1 @@
1
- import{b as x,R as y,j as t,bl as j,bj as w,bk as k,bh as v,bf as D}from"./vendor-.bun-BE757pvp.js";import{c as R,v as u}from"./useAppFontEffects-DkPuAMXD.js";import{k as S}from"./runtimeEndpointReset-MTaPPm4F.js";import"./index-8J6waVO6.js";import"./mobileLayoutPreference-Dio-WWkI.js";const B=b=>{const e=x.c(19),{open:m,onOpenChange:n}=b,{t:f}=R(),s=y.useId(),h=_;let a;e[0]!==n?(a=g=>{!g&&h()||n(g)},e[0]=n,e[1]=a):a=e[1];let d;e[2]===Symbol.for("react.memo_cache_sentinel")?(d=t.jsx(j,{className:u("fixed inset-0 z-50 bg-black/50 dark:bg-black/75","transition-opacity duration-150 ease-out","data-[starting-style]:opacity-0 data-[ending-style]:opacity-0")}),e[2]=d):d=e[2];let c;e[3]===Symbol.for("react.memo_cache_sentinel")?(c=u("relative pointer-events-auto","w-[90vw] max-w-[1200px] h-[85vh] max-h-[900px]","rounded-xl border shadow-none overflow-hidden origin-center","bg-background","transition-all duration-150 ease-out","data-[starting-style]:opacity-0 data-[starting-style]:scale-[0.98]","data-[ending-style]:opacity-0 data-[ending-style]:scale-[0.98]","data-[nested-dialog-open]:brightness-[0.55] dark:data-[nested-dialog-open]:brightness-[0.4]"),e[3]=c):c=e[3];let o;e[4]!==f?(o=f("settings.window.description"),e[4]=f,e[5]=o):o=e[5];let i;e[6]!==s||e[7]!==o?(i=t.jsx(w,{id:s,className:"sr-only",children:o}),e[6]=s,e[7]=o,e[8]=i):i=e[8];let l;e[9]!==n?(l=t.jsx(S,{onClose:()=>n(!1),isWindowed:!0}),e[9]=n,e[10]=l):l=e[10];let r;e[11]!==s||e[12]!==i||e[13]!==l?(r=t.jsxs(k,{children:[d,t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center pointer-events-none",children:t.jsxs(v,{"aria-describedby":s,className:c,children:[i,l]})})]}),e[11]=s,e[12]=i,e[13]=l,e[14]=r):r=e[14];let p;return e[15]!==m||e[16]!==a||e[17]!==r?(p=t.jsx(D,{open:m,onOpenChange:a,children:r}),e[15]=m,e[16]=a,e[17]=r,e[18]=p):p=e[18],p};function _(){return typeof document>"u"?!1:!!document.querySelector('[data-slot="dropdown-menu-content"][data-open], [data-slot="select-content"][data-open]')}export{B as SettingsWindow};
1
+ import{b as x,R as y,j as t,bl as j,bj as w,bk as k,bh as v,bf as D}from"./vendor-.bun-BE757pvp.js";import{c as R,v as u}from"./useAppFontEffects-9LFMCKYW.js";import{k as S}from"./runtimeEndpointReset-B0P2DED1.js";import"./index-BklNmnVr.js";import"./mobileLayoutPreference-Dio-WWkI.js";const B=b=>{const e=x.c(19),{open:m,onOpenChange:n}=b,{t:f}=R(),s=y.useId(),h=_;let a;e[0]!==n?(a=g=>{!g&&h()||n(g)},e[0]=n,e[1]=a):a=e[1];let d;e[2]===Symbol.for("react.memo_cache_sentinel")?(d=t.jsx(j,{className:u("fixed inset-0 z-50 bg-black/50 dark:bg-black/75","transition-opacity duration-150 ease-out","data-[starting-style]:opacity-0 data-[ending-style]:opacity-0")}),e[2]=d):d=e[2];let c;e[3]===Symbol.for("react.memo_cache_sentinel")?(c=u("relative pointer-events-auto","w-[90vw] max-w-[1200px] h-[85vh] max-h-[900px]","rounded-xl border shadow-none overflow-hidden origin-center","bg-background","transition-all duration-150 ease-out","data-[starting-style]:opacity-0 data-[starting-style]:scale-[0.98]","data-[ending-style]:opacity-0 data-[ending-style]:scale-[0.98]","data-[nested-dialog-open]:brightness-[0.55] dark:data-[nested-dialog-open]:brightness-[0.4]"),e[3]=c):c=e[3];let o;e[4]!==f?(o=f("settings.window.description"),e[4]=f,e[5]=o):o=e[5];let i;e[6]!==s||e[7]!==o?(i=t.jsx(w,{id:s,className:"sr-only",children:o}),e[6]=s,e[7]=o,e[8]=i):i=e[8];let l;e[9]!==n?(l=t.jsx(S,{onClose:()=>n(!1),isWindowed:!0}),e[9]=n,e[10]=l):l=e[10];let r;e[11]!==s||e[12]!==i||e[13]!==l?(r=t.jsxs(k,{children:[d,t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center pointer-events-none",children:t.jsxs(v,{"aria-describedby":s,className:c,children:[i,l]})})]}),e[11]=s,e[12]=i,e[13]=l,e[14]=r):r=e[14];let p;return e[15]!==m||e[16]!==a||e[17]!==r?(p=t.jsx(D,{open:m,onOpenChange:a,children:r}),e[15]=m,e[16]=a,e[17]=r,e[18]=p):p=e[18],p};function _(){return typeof document>"u"?!1:!!document.querySelector('[data-slot="dropdown-menu-content"][data-open], [data-slot="select-content"][data-open]')}export{B as SettingsWindow};
@@ -1,4 +1,4 @@
1
- import{R as n,j as f,k as vt,cm as xt,cn as Tt,co as kt}from"./vendor-.bun-BE757pvp.js";import{c as bt,y as Ct,eM as Et,v as et,d as Rt,z as St,W as At,aH as It,G as ht,e as Bt,I as fe,B as oe}from"./useAppFontEffects-DkPuAMXD.js";import{u as q}from"./main-B-GA5Tg5.js";import{h as Mt,u as Me,cd as Pt,cc as it,at as pt}from"./index-8J6waVO6.js";import{y as Dt,z as Nt}from"./runtimeEndpointReset-MTaPPm4F.js";import"./SessionSwitcherDropdown-CWWrCFzr.js";import"./mobileLayoutPreference-Dio-WWkI.js";function jt(u){const{colors:l}=u,d=l.syntax.base;return{background:l.surface.background,foreground:d.foreground,cursor:l.interactive.cursor,cursorAccent:l.surface.background,selectionBackground:l.interactive.selection,selectionForeground:l.interactive.selectionForeground,selectionInactiveBackground:l.interactive.selection+"50",black:l.surface.muted,red:l.status.error,green:l.status.success,yellow:l.status.warning,blue:d.function,magenta:d.keyword,cyan:d.type,white:d.foreground,brightBlack:d.comment,brightRed:l.status.error,brightGreen:l.status.success,brightYellow:l.status.warning,brightBlue:d.function,brightMagenta:d.keyword,brightCyan:d.type,brightWhite:l.surface.elevatedForeground}}function Vt(u,l,d,I,E=!1){const _=`${u}, "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:l,lineHeight:1.15,fontFamily:_,allowTransparency:!1,theme:{background:d.background,foreground:d.foreground,cursor:d.cursor,cursorAccent:d.cursorAccent,selectionBackground:d.selectionBackground,selectionForeground:d.selectionForeground,black:d.black,red:d.red,green:d.green,yellow:d.yellow,blue:d.blue,magenta:d.magenta,cyan:d.cyan,white:d.white,brightBlack:d.brightBlack,brightRed:d.brightRed,brightGreen:d.brightGreen,brightYellow:d.brightYellow,brightBlue:d.brightBlue,brightMagenta:d.brightMagenta,brightCyan:d.brightCyan,brightWhite:d.brightWhite},scrollback:1e4,ghostty:I,disableStdin:E}}let mt=null;function Lt(){return mt||(mt=kt.load()),mt}function Ft(u){if(typeof window>"u")return null;const l=[u,...Array.from(u.querySelectorAll("*"))];let d=null;for(const I of l){const X=window.getComputedStyle(I).overflowY;if(!(X!=="auto"&&X!=="scroll")){if(I.scrollHeight-I.clientHeight>2)return I;d||(d=I)}}return d}const gt=n.forwardRef(({sessionKey:u,chunks:l,onInput:d,onResize:I,theme:E,fontFamily:X,fontSize:_,className:ye,enableTouchScroll:R,autoFocus:at=!0,isVisible:Ne=!0},Se)=>{const{t:J}=bt(),O=n.useRef(null),je=n.useRef(null),B=n.useRef(null),tt=n.useRef(null),K=n.useRef(d),Ue=n.useRef(I),v=n.useRef(null),Ae=n.useRef(""),se=n.useRef(null),Ve=n.useRef(!1),Le=n.useRef(null),be=n.useRef(!0),ie=n.useRef(null),Q=n.useRef(null),Ie=n.useRef(0),ae=n.useRef(null),We=n.useRef(null),de=n.useRef(!1),ee=n.useRef(!1),ge=n.useRef(null),V=n.useRef(null),D=n.useRef(null),he=n.useRef(""),Fe=n.useRef(null),L=n.useRef(!R),nt=n.useRef(Ne),[,dt]=n.useReducer(e=>e+1,0),[rt,ct]=n.useReducer(e=>e+1,0);K.current=d,Ue.current=I;const lt=typeof navigator<"u"&&(/Android/i.test(navigator.userAgent)||navigator.userAgentData?.platform==="Android"),b=!!R;n.useEffect(()=>{if(!R){L.current=!0,nt.current=Ne;return}!nt.current&&Ne&&(L.current=!1),nt.current=Ne},[R,Ne]);const ot=n.useCallback(()=>{if(!b)return;const e=O.current,c=ae.current;if(!e)return;const a=[];e.getAttribute("contenteditable")==="true"&&a.push(e),a.push(...Array.from(e.querySelectorAll('[contenteditable="true"]'))),a.forEach(s=>{s.setAttribute("data-terminal-disabled-contenteditable","true"),s.setAttribute("contenteditable","false"),s.setAttribute("aria-hidden","true"),s.tabIndex=-1,s.style.setProperty("caret-color","transparent"),s.style.color="transparent",s.style.setProperty("-webkit-text-fill-color","transparent"),s.style.background="transparent",s.style.outline="none",s.style.boxShadow="none",s.style.textShadow="none",s.style.setProperty("user-select","none"),s.style.setProperty("-webkit-user-select","none")}),e.tabIndex=-1,e.removeAttribute("role"),e.removeAttribute("aria-multiline"),Array.from(e.querySelectorAll("textarea")).forEach(s=>{s.style.setProperty("caret-color","transparent"),s.style.color="transparent",s.style.setProperty("-webkit-text-fill-color","transparent"),s.style.background="transparent",s.style.border="0",s.style.outline="none",s.style.boxShadow="none",s.style.textShadow="none",s.style.fontSize="0",s.style.lineHeight="0",s!==c&&s.getAttribute("data-terminal-disabled-input")!=="true"&&(s.setAttribute("data-terminal-disabled-input","true"),s.setAttribute("aria-hidden","true"),s.tabIndex=-1,s.disabled=!0,s.style.position="absolute",s.style.opacity="0",s.style.width="0px",s.style.height="0px",s.style.pointerEvents="none",s.style.zIndex="-1")})},[b]),A=n.useCallback(e=>{if(Fe.current===e)return;const c=B.current;if(c)try{if(typeof c.setOption=="function"){c.setOption("cursorBlink",e),Fe.current=e;return}c.options&&(c.options.cursorBlink=e,Fe.current=e)}catch{}},[]),pe=b&&lt,S=n.useCallback((e,c)=>{const a=pe?We.current:ae.current,w=O.current;if(!a||!w)return;const s=w.getBoundingClientRect(),T=typeof window<"u"?window.innerWidth:s.width,h=typeof window<"u"?window.innerHeight:s.height,te=s.left+s.width/2,M=s.top+s.height-12,o=typeof e=="number"?e:te,P=typeof c=="number"?c:M,Y=8,me=Math.max(Y,Math.min(T-Y,o)),$=Math.max(Y,Math.min(h-Y,P));a.style.left=`${me}px`,a.style.top=`${$}px`,a.style.bottom="",(a instanceof HTMLTextAreaElement||a instanceof HTMLInputElement)&&(a.disabled=!1,a.readOnly=!1,a.removeAttribute("disabled"),a.removeAttribute("readonly"));try{a.focus({preventScroll:!0})}catch{try{a.focus()}catch{}}},[pe]),F=n.useCallback(()=>{if(b){S(),A(!0);return}B.current?.focus(),A(!0)},[S,A,b]),N=n.useCallback(e=>e instanceof HTMLTextAreaElement||e instanceof HTMLInputElement?e.value:e.textContent??"",[]),U=n.useCallback(e=>{if(e instanceof HTMLTextAreaElement||e instanceof HTMLInputElement){e.value="";return}e.textContent=""},[]),Ye=n.useCallback(e=>{if(typeof window>"u"||pe)return;D.current!==null&&(window.clearTimeout(D.current),D.current=null);let c=0;const a=3,w=()=>{D.current=window.setTimeout(()=>{D.current=null;const s=N(e);if(!s){if(c+=1,c<a){w();return}return}const T=he.current;he.current=s;const h=s.startsWith(T)?s.slice(T.length):s;h&&K.current(h.replace(/\r\n|\r|\n/g,"\r")),U(e),he.current=""},c===0?0:24)};w()},[U,N,pe]);n.useEffect(()=>{const e=O.current;if(!b||!e||R)return;const c=a=>{const w=a.target;if(w&&w.getAttribute("data-terminal-hidden-input")!=="true"&&e.contains(w)){try{w.blur()}catch{}S()}};return e.addEventListener("focusin",c,!0),()=>{e.removeEventListener("focusin",c,!0)}},[R,b,S]);const qe=n.useCallback(()=>{const e=B.current;if(!e||typeof e.getSelection!="function")return"";const c=e.getSelection();return typeof c=="string"?c:""},[]),Xe=n.useCallback(()=>{if(typeof window>"u")return"";const e=window.getSelection();if(!e)return"";const c=e.toString();if(!c.trim())return"";const a=O.current;if(!a)return"";const w=e.anchorNode,s=e.focusNode;return w&&!a.contains(w)||s&&!a.contains(s)?"":c},[]),ve=n.useCallback(async()=>{if(typeof document>"u")return;const e=qe()||Xe();e.trim()&&await Ct(e)},[Xe,qe]),Z=n.useCallback(()=>qe().trim()?!0:!!Xe().trim(),[Xe,qe]);n.useEffect(()=>{if(typeof window>"u")return;const e=c=>{Z()&&(c.preventDefault(),ve())};return window.addEventListener("openchamber:copy",e),()=>{window.removeEventListener("openchamber:copy",e)}},[ve,Z]);const ce=n.useCallback(()=>{Ae.current="",se.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(se.current),se.current=null,Ve.current=!1,Le.current=null},[]),H=n.useCallback(()=>{const e=tt.current,c=B.current,a=O.current;if(!e||!c||!a)return;const w=a.getBoundingClientRect();if(!(w.width<24||w.height<24))try{e.fit();const s={cols:c.cols,rows:c.rows},T=v.current;(!T||T.cols!==s.cols||T.rows!==s.rows)&&(v.current=s,Ue.current(s.cols,s.rows))}catch{}},[]),xe=n.useCallback(()=>{if(Ve.current)return;const e=B.current;if(!e){ce();return}if(!Ae.current)return;const c=Ae.current;Ae.current="",Ve.current=!0,e.write(c,()=>{Ve.current=!1,Ae.current&&(typeof window<"u"?se.current=window.requestAnimationFrame(()=>{se.current=null,xe()}):xe())})},[ce]),Pe=n.useCallback(()=>{se.current===null&&(typeof window<"u"?se.current=window.requestAnimationFrame(()=>{se.current=null,xe()}):xe())},[xe]),$e=n.useCallback(e=>{e&&(Ae.current+=e,Pe())},[Pe]),De=n.useCallback(()=>{if(ie.current?.(),ie.current=null,Q.current!==null&&typeof window<"u"&&(window.clearTimeout(Q.current),Q.current=null),!R){Ie.current=0;return}const e=O.current;if(!e)return;const c=B.current;if(!c)return;Ie.current=0;const a=2.2,w=2.8,s=25,T=.25,h=8,te=.05,M=.015,o={lastY:null,lastTime:null,velocity:0,rafId:null,startX:null,startY:null,didMove:!1},P=()=>typeof performance<"u"?performance.now():Date.now(),Y=Math.max(12,Math.round(_*1.35));let me=0;const $=i=>{if(!i)return!1;const W=c.getViewportY(),re=me+i,le=Math.trunc(re/Y);return me=re-le*Y,le!==0&&c.scrollLines(le),c.getViewportY()!==W},ke=()=>{o.rafId!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.rafId),o.rafId=null},k={passive:!1,capture:!1};if(typeof window<"u"&&"PointerEvent"in window){const i=Object.assign(o,{pointerId:null,startX:null,startY:null,moved:!1}),W=6,re=r=>{if(r.pointerType==="touch"){ke(),i.pointerId=r.pointerId,i.startX=r.clientX,i.startY=r.clientY,i.moved=!1,i.lastY=r.clientY,i.lastTime=P(),i.velocity=0;try{e.setPointerCapture(r.pointerId)}catch{}}},le=r=>{if(r.pointerType!=="touch"||i.pointerId!==r.pointerId)return;if(i.startX!==null&&i.startY!==null&&!i.moved){const ut=r.clientX-i.startX,ze=r.clientY-i.startY;Math.hypot(ut,ze)>=W&&(i.moved=!0)}if(i.lastY===null){i.lastY=r.clientY,i.lastTime=P();return}const g=i.lastY,m=i.lastTime??P(),x=P();i.lastY=r.clientY,i.lastTime=x;const y=g-r.clientY;if(Math.abs(y)<1)return;const G=Math.max(x-m,8),Ee=a+Math.min(w,Math.abs(y)/s),we=y*Ee,Re=we/G;i.velocity=i.velocity*(1-T)+Re*T,i.velocity>h?i.velocity=h:i.velocity<-h&&(i.velocity=-h),i.moved&&(r.cancelable&&r.preventDefault(),r.stopPropagation()),$(we)},ue=r=>{if(r.pointerType!=="touch"||i.pointerId!==r.pointerId)return;const g=!i.moved;i.pointerId=null,i.startX=null,i.startY=null,i.moved=!1,i.lastY=null,i.lastTime=null;try{e.releasePointerCapture(r.pointerId)}catch{}if(g){b?S(r.clientX,r.clientY):R&&!L.current&&(L.current=!0,B.current?.focus());return}if(typeof window>"u")return;if(Math.abs(i.velocity)<te){i.velocity=0;return}let m=P();const x=()=>{const y=P(),G=Math.max(y-m,8);m=y;const Ee=$(i.velocity*G)??!1,we=Math.sign(i.velocity),Re=Math.max(0,Math.abs(i.velocity)-M*G);if(i.velocity=Re*we,!Ee||Re<=te){ke(),i.velocity=0;return}i.rafId=window.requestAnimationFrame(x)};i.rafId=window.requestAnimationFrame(x)};e.addEventListener("pointerdown",re,k),e.addEventListener("pointermove",le,k),e.addEventListener("pointerup",ue,k),e.addEventListener("pointercancel",ue,k);const t=e.style.touchAction,p=e.style.overscrollBehaviorY;e.style.touchAction="none",e.style.overscrollBehaviorY="contain",ie.current=()=>{ke(),Q.current!==null&&typeof window<"u"&&(window.clearTimeout(Q.current),Q.current=null),Ie.current=0,e.removeEventListener("pointerdown",re,k),e.removeEventListener("pointermove",le,k),e.removeEventListener("pointerup",ue,k),e.removeEventListener("pointercancel",ue,k),e.style.touchAction=t,e.style.overscrollBehaviorY=p};return}const C=6,Ce=i=>{i.touches.length===1&&(ke(),o.lastY=i.touches[0].clientY,o.lastTime=P(),o.velocity=0,o.startX=i.touches[0].clientX,o.startY=i.touches[0].clientY,o.didMove=!1)},Be=i=>{if(i.touches.length!==1){o.lastY=null,o.lastTime=null,o.velocity=0,o.startX=null,o.startY=null,o.didMove=!1,ke();return}const W=i.touches[0].clientX,re=i.touches[0].clientY;if(o.startX!==null&&o.startY!==null&&!o.didMove){const y=W-o.startX,G=re-o.startY;Math.hypot(y,G)>=C&&(o.didMove=!0)}if(o.lastY===null){o.lastY=re,o.lastTime=P();return}const le=o.lastY,ue=o.lastTime??P(),t=P();o.lastY=re,o.lastTime=t;const p=le-re;if(Math.abs(p)<1)return;const r=Math.max(t-ue,8),g=a+Math.min(w,Math.abs(p)/s),m=p*g,x=m/r;o.velocity=o.velocity*(1-T)+x*T,o.velocity>h?o.velocity=h:o.velocity<-h&&(o.velocity=-h),o.didMove&&(i.preventDefault(),i.stopPropagation()),$(m)},z=i=>{const W=!o.didMove;o.lastY=null,o.lastTime=null;const re=o.velocity;if(o.startX=null,o.startY=null,o.didMove=!1,W){const t=i.changedTouches?.[0];b?S(t?.clientX,t?.clientY):R&&!L.current&&(L.current=!0,B.current?.focus());return}if(typeof window>"u")return;if(Math.abs(re)<te){o.velocity=0;return}let le=P();const ue=()=>{const t=P(),p=Math.max(t-le,8);le=t;const r=$(o.velocity*p)??!1,g=Math.sign(o.velocity),m=Math.max(0,Math.abs(o.velocity)-M*p);if(o.velocity=m*g,!r||m<=te){ke(),o.velocity=0;return}o.rafId=window.requestAnimationFrame(ue)};o.rafId=window.requestAnimationFrame(ue)};e.addEventListener("touchstart",Ce,k),e.addEventListener("touchmove",Be,k),e.addEventListener("touchend",z,k),e.addEventListener("touchcancel",z,k);const Qe=e.style.touchAction,j=e.style.overscrollBehaviorY;e.style.touchAction="none",e.style.overscrollBehaviorY="contain",ie.current=()=>{ke(),Q.current!==null&&typeof window<"u"&&(window.clearTimeout(Q.current),Q.current=null),Ie.current=0,e.removeEventListener("touchstart",Ce,k),e.removeEventListener("touchmove",Be,k),e.removeEventListener("touchend",z,k),e.removeEventListener("touchcancel",z,k),e.style.touchAction=Qe,e.style.overscrollBehaviorY=j}},[R,b,S,_]);n.useEffect(()=>{let e=!1,c=null,a=null,w=null,s=[],T=null,h=null,te=null;const M=O.current;if(!M)return;if(M.tabIndex=b?-1:0,b){const k=M.focus.bind(M),ne=M;ne.focus=((...C)=>{S()}),te=()=>{ne.focus=k}}const o=()=>{A(!0)},P=()=>{A(!1)},Y=k=>{const ne=k.target;if(ne&&M.contains(ne)){if(b&&ne instanceof HTMLElement){window.setTimeout(()=>{ne.blur(),S()},0),A(!1);return}if(R&&!L.current&&ne instanceof HTMLElement){window.setTimeout(()=>{ne.blur()},0),A(!1);return}A(!0);return}A(!1)},me=()=>{A(!1)};let $=null;return(async()=>{try{const k=await Lt();if(e)return;const ne=Vt(X,_,E,k,!1),C=new xt(ne);be.current=!0,b&&(C.focus=()=>{});const Ce=C;if(typeof Ce.scrollToBottom=="function"){const j=Ce.scrollToBottom.bind(Ce);Ce.scrollToBottom=()=>{be.current&&j()},T=()=>{Ce.scrollToBottom=j}}const Be=new Tt;if(c=C,B.current=C,tt.current=Be,C.loadAddon(Be),C.open(M),R){const j=C.renderer;if(j&&typeof j.renderScrollbar=="function"){const i=j.renderScrollbar.bind(j);j.renderScrollbar=()=>{},h=()=>{j.renderScrollbar=i}}}ct(),Fe.current=!1,$=C.textarea??M.querySelector("textarea"),$&&($.addEventListener("focus",o),$.addEventListener("blur",P)),ot(),typeof MutationObserver<"u"&&(w=new MutationObserver(()=>{ot()}),w.observe(M,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["contenteditable","role","tabindex","aria-label"]}));const z=Ft(M);z?(z.classList.add("overlay-scrollbar-target","overlay-scrollbar-container"),je.current=z,dt()):je.current=null,H();const Qe=Be;typeof Qe.observeResize=="function"&&Qe.observeResize(),De(),s=[C.onData(j=>{K.current(j)}),C.onScroll(j=>{if(typeof j=="number"&&Number.isFinite(j)){const i=typeof C.hasSelection=="function"&&C.hasSelection();be.current=!i&&j<=.5}}),C.onSelectionChange(()=>{if(typeof C.hasSelection=="function"&&C.hasSelection()){be.current=!1;return}const i=typeof C.getViewportY=="function"?C.getViewportY():0;be.current=i<=.5})],a=new ResizeObserver(()=>{H()}),a.observe(M),typeof window<"u"&&window.setTimeout(()=>{H()},0)}catch{}})(),document.addEventListener("focusin",Y,!0),window.addEventListener("blur",me),()=>{e=!0,ie.current?.(),ie.current=null,document.removeEventListener("focusin",Y,!0),window.removeEventListener("blur",me),s.forEach(k=>k.dispose()),T?.(),T=null,h?.(),h=null,$&&($.removeEventListener("focus",o),$.removeEventListener("blur",P)),a?.disconnect(),w?.disconnect(),te?.(),c?.dispose(),B.current=null,tt.current=null,je.current=null,v.current=null,Fe.current=null,ce()}},[ot,R,H,S,X,_,De,E,ce,A,b]),n.useEffect(()=>{const e=B.current;e&&(e.reset(),ce(),v.current=null,H())},[u,rt,H,ce]),n.useEffect(()=>{!at||!B.current||F()},[at,F,u,rt]),n.useEffect(()=>(De(),()=>{ie.current?.(),ie.current=null}),[De,u]),n.useEffect(()=>{const e=B.current;if(!e)return;if(l.length===0){Le.current!==null&&(e.reset(),ce(),H());return}const c=Le.current;let a;if(c===null)a=l;else{const w=l.findIndex(s=>s.id===c);a=w>=0?l.slice(w+1):l}a.length>0&&$e(a.map(w=>w.data).join("")),Le.current=l[l.length-1].id},[l,rt,$e,H,ce]),n.useImperativeHandle(Se,()=>({focus:()=>{F()},clear:()=>{const e=B.current;e&&(e.reset(),ce(),H())},fit:()=>{H()}}),[F,H,ce]);const Ge=n.useCallback(e=>{if(!b)return;const c=O.current,a=e.relatedTarget,w=a?.tagName,s=w==="INPUT"||w==="TEXTAREA"||a?.isContentEditable,T=a?.getAttribute("data-terminal-hidden-input")==="true",h=!!(a&&c?.contains(a))},[b]),Oe=n.useCallback(e=>{const c=e.nativeEvent,a=c?.inputType??"",w=typeof c?.data=="string"?c.data:"";if(V.current=typeof performance<"u"?performance.now():Date.now(),a==="insertCompositionText"){de.current=!0;return}if(!a&&w){if(de.current)return;e.preventDefault(),K.current(w),ge.current={type:"insertText",at:typeof performance<"u"?performance.now():Date.now()},ee.current=!0;return}if(a==="insertText"&&w){if(de.current)return;e.preventDefault(),K.current(w),ge.current={type:a,at:typeof performance<"u"?performance.now():Date.now()},ee.current=!0;return}if(a==="insertLineBreak"){if(de.current)return;e.preventDefault(),K.current("\r"),ge.current={type:a,at:typeof performance<"u"?performance.now():Date.now()},ee.current=!0;return}if(a==="deleteContentBackward"){if(de.current)return;e.preventDefault(),K.current(""),ge.current={type:a,at:typeof performance<"u"?performance.now():Date.now()},ee.current=!0}},[]),st=n.useCallback(e=>{const c=e.currentTarget;if(V.current=typeof performance<"u"?performance.now():Date.now(),de.current)return;if(ee.current){const s=ge.current,T=typeof performance<"u"?performance.now():Date.now();if(s&&T-s.at<50){ee.current=!1,U(c);return}ee.current=!1}const a=N(c);if(!a)return;he.current=a;const w=a.replace(/\r\n|\r|\n/g,"\r");K.current(w),U(c),he.current=""},[U,N]),_e=n.useCallback(e=>{e.stopPropagation();const c=e.key.toLowerCase(),a=e.metaKey&&!e.ctrlKey&&!e.altKey&&c==="c",w=e.ctrlKey&&e.shiftKey&&!e.metaKey&&!e.altKey&&c==="c";if((a||w)&&Z()){e.preventDefault(),ve();return}if(e.ctrlKey&&!e.metaKey&&!e.altKey&&e.key.length===1){const Y=e.key.toUpperCase();if(Y>="A"&&Y<="Z"){e.preventDefault(),e.nativeEvent?.stopImmediatePropagation(),K.current(String.fromCharCode(Y.charCodeAt(0)-64)),U(e.currentTarget);return}}if(e.altKey&&!e.ctrlKey&&!e.metaKey&&e.key.length===1){e.preventDefault(),e.nativeEvent?.stopImmediatePropagation(),K.current("\x1B"+e.key),U(e.currentTarget);return}const T={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(T){e.preventDefault(),K.current(T),U(e.currentTarget);return}const h=e.currentTarget;if(e.nativeEvent?.isComposing)return;const M=ge.current,o=typeof performance<"u"?performance.now():Date.now(),P=!!(M&&o-M.at<50);if(e.key==="Enter"){if(P&&M?.type==="insertLineBreak")return;e.preventDefault(),K.current("\r"),U(h);return}if(e.key==="Backspace"){if(e.preventDefault(),P&&M?.type==="deleteContentBackward")return;N(h)||K.current("")}if(e.key.length===1&&!e.ctrlKey&&!e.metaKey&&!e.altKey){const Y=V.current;Y&&o-Y<50||(e.preventDefault(),K.current(e.key),ee.current=!0,ge.current={type:"keydown-text",at:o})}Ye(h)},[U,ve,Z,N,Ye]),Ke=n.useCallback(e=>{e.stopPropagation();const c=e.currentTarget;e.nativeEvent?.isComposing||Ye(c)},[Ye]),Je=n.useCallback(e=>{const c=e.currentTarget;de.current=!1;const a=e.data||N(c);if(V.current=typeof performance<"u"?performance.now():Date.now(),!a)return;const w=a.replace(/\r\n|\r|\n/g,"\r");K.current(w),U(c),ge.current={type:"compositionend",at:typeof performance<"u"?performance.now():Date.now()},ee.current=!0},[U,N]),He=n.useCallback(e=>{e.stopPropagation();const c=e.clipboardData?.getData("text")??"";if(!c)return;e.preventDefault();const w=B.current?.hasBracketedPaste?.()?`\x1B[200~${c}\x1B[201~`:c;K.current(w)},[]),Te={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 f.jsxs("div",{ref:O,className:et("relative h-full w-full terminal-viewport-container",ye),"data-hidden-input-overlay-active":b?"true":void 0,style:{backgroundColor:E.background},onTouchStart:e=>{if(!(!b||R)&&!Z()){const c=e.touches?.[0];S(c?.clientX,c?.clientY)}},onClick:e=>{if(!R)if(b){if(Z())return;S(e.clientX,e.clientY)}else B.current?.focus()},onMouseUp:()=>{!R&&Z()&&ve()},onTouchEnd:()=>{!R&&Z()&&ve()},children:[b&&typeof document<"u"?vt.createPortal(f.jsxs(f.Fragment,{children:[f.jsx("input",{ref:We,type:"text",inputMode:"text",autoCapitalize:"off",autoComplete:"off",autoCorrect:"off",spellCheck:!1,tabIndex:-1,enterKeyHint:"send","data-terminal-hidden-input":"true","aria-label":J("terminalView.viewport.inputAria"),"aria-hidden":"true",style:{...Te,display:pe?"block":"none"},onBlur:Ge,onBeforeInput:Oe,onCompositionStart:()=>{de.current=!0},onInput:st,onKeyDown:_e,onKeyUp:Ke,onCompositionEnd:Je,onPaste:He}),f.jsx("textarea",{ref:ae,inputMode:"text",autoCapitalize:"off",autoComplete:"off",autoCorrect:"off",spellCheck:!1,tabIndex:-1,enterKeyHint:"send","data-terminal-hidden-input":"true","aria-label":J("terminalView.viewport.inputAria"),"aria-hidden":"true",style:{...Te,display:pe?"none":"block"},onBlur:Ge,onBeforeInput:Oe,onCompositionStart:()=>{de.current=!0},onInput:st,onKeyDown:_e,onKeyUp:Ke,onCompositionEnd:Je,onPaste:He})]}),document.body):null,je.current&&!R?f.jsx(Et,{containerRef:je,disableHorizontal:!0,className:"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero"}):null]})});gt.displayName="TerminalViewport";const Yt="\x1B",Ot=new RegExp(`${Yt}\\[[0-9;?]*[ -/]*[@-~]`,"g"),Kt=/(https?:\/\/(?:localhost|127\.0\.0\.1|0\.0\.0\.0|\[(?:::1|::)\])(?::\d{2,5})?(?:\/[^\s<>'"`]*)?)/gi,Ht=/(?:➜\s*(?:Local|Network):)|\b(?:local|network|loopback|serving|listening|available|ready|started|running|server|vite|webpack|next\.js|astro|sveltekit|nuxt)\b/i,zt=/Serving HTTP on .*? port (\d{2,5})/i,Ut=new Set([".",",",";",":","!","?"]),Wt=u=>{let l=u;for(;l.length>0;){const d=l[l.length-1];if(d===")"||d==="]"||d==="}"||d===">"){const I=d===")"?"(":d==="]"?"[":d==="}"?"{":"<",E=l.slice(0,-1),X=(E.match(new RegExp(`\\${I}`,"g"))||[]).length,_=(E.match(new RegExp(`\\${d}`,"g"))||[]).length;if(X>_)break;l=E;continue}if(Ut.has(d)){l=l.slice(0,-1);continue}break}return l},yt=u=>{let l=Wt(u);return l=l.replace("0.0.0.0","127.0.0.1"),l=l.replace("[::1]","127.0.0.1"),l=l.replace("[::]","127.0.0.1"),l},qt=u=>{if(!u)return null;const l=u.replace(Ot,""),d=l.match(zt);if(d?.[1]){const E=Number.parseInt(d[1],10);if(Number.isFinite(E)&&E>0&&E<=65535)return`http://127.0.0.1:${E}/`}const I=l.split(`
1
+ import{R as n,j as f,k as vt,cm as xt,cn as Tt,co as kt}from"./vendor-.bun-BE757pvp.js";import{c as bt,y as Ct,eO as Et,v as et,d as Rt,z as St,W as At,aH as It,G as ht,e as Bt,I as fe,B as oe}from"./useAppFontEffects-9LFMCKYW.js";import{u as q}from"./main-B0CxEOP5.js";import{h as Mt,u as Me,cf as Pt,ce as it,at as pt}from"./index-BklNmnVr.js";import{y as Dt,z as Nt}from"./runtimeEndpointReset-B0P2DED1.js";import"./SessionSwitcherDropdown-DHO5Je6v.js";import"./mobileLayoutPreference-Dio-WWkI.js";function jt(u){const{colors:l}=u,d=l.syntax.base;return{background:l.surface.background,foreground:d.foreground,cursor:l.interactive.cursor,cursorAccent:l.surface.background,selectionBackground:l.interactive.selection,selectionForeground:l.interactive.selectionForeground,selectionInactiveBackground:l.interactive.selection+"50",black:l.surface.muted,red:l.status.error,green:l.status.success,yellow:l.status.warning,blue:d.function,magenta:d.keyword,cyan:d.type,white:d.foreground,brightBlack:d.comment,brightRed:l.status.error,brightGreen:l.status.success,brightYellow:l.status.warning,brightBlue:d.function,brightMagenta:d.keyword,brightCyan:d.type,brightWhite:l.surface.elevatedForeground}}function Vt(u,l,d,I,E=!1){const _=`${u}, "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:l,lineHeight:1.15,fontFamily:_,allowTransparency:!1,theme:{background:d.background,foreground:d.foreground,cursor:d.cursor,cursorAccent:d.cursorAccent,selectionBackground:d.selectionBackground,selectionForeground:d.selectionForeground,black:d.black,red:d.red,green:d.green,yellow:d.yellow,blue:d.blue,magenta:d.magenta,cyan:d.cyan,white:d.white,brightBlack:d.brightBlack,brightRed:d.brightRed,brightGreen:d.brightGreen,brightYellow:d.brightYellow,brightBlue:d.brightBlue,brightMagenta:d.brightMagenta,brightCyan:d.brightCyan,brightWhite:d.brightWhite},scrollback:1e4,ghostty:I,disableStdin:E}}let mt=null;function Lt(){return mt||(mt=kt.load()),mt}function Ft(u){if(typeof window>"u")return null;const l=[u,...Array.from(u.querySelectorAll("*"))];let d=null;for(const I of l){const X=window.getComputedStyle(I).overflowY;if(!(X!=="auto"&&X!=="scroll")){if(I.scrollHeight-I.clientHeight>2)return I;d||(d=I)}}return d}const gt=n.forwardRef(({sessionKey:u,chunks:l,onInput:d,onResize:I,theme:E,fontFamily:X,fontSize:_,className:ye,enableTouchScroll:R,autoFocus:at=!0,isVisible:Ne=!0},Se)=>{const{t:J}=bt(),O=n.useRef(null),je=n.useRef(null),B=n.useRef(null),tt=n.useRef(null),K=n.useRef(d),Ue=n.useRef(I),v=n.useRef(null),Ae=n.useRef(""),se=n.useRef(null),Ve=n.useRef(!1),Le=n.useRef(null),be=n.useRef(!0),ie=n.useRef(null),Q=n.useRef(null),Ie=n.useRef(0),ae=n.useRef(null),We=n.useRef(null),de=n.useRef(!1),ee=n.useRef(!1),ge=n.useRef(null),V=n.useRef(null),D=n.useRef(null),he=n.useRef(""),Fe=n.useRef(null),L=n.useRef(!R),nt=n.useRef(Ne),[,dt]=n.useReducer(e=>e+1,0),[rt,ct]=n.useReducer(e=>e+1,0);K.current=d,Ue.current=I;const lt=typeof navigator<"u"&&(/Android/i.test(navigator.userAgent)||navigator.userAgentData?.platform==="Android"),b=!!R;n.useEffect(()=>{if(!R){L.current=!0,nt.current=Ne;return}!nt.current&&Ne&&(L.current=!1),nt.current=Ne},[R,Ne]);const ot=n.useCallback(()=>{if(!b)return;const e=O.current,c=ae.current;if(!e)return;const a=[];e.getAttribute("contenteditable")==="true"&&a.push(e),a.push(...Array.from(e.querySelectorAll('[contenteditable="true"]'))),a.forEach(s=>{s.setAttribute("data-terminal-disabled-contenteditable","true"),s.setAttribute("contenteditable","false"),s.setAttribute("aria-hidden","true"),s.tabIndex=-1,s.style.setProperty("caret-color","transparent"),s.style.color="transparent",s.style.setProperty("-webkit-text-fill-color","transparent"),s.style.background="transparent",s.style.outline="none",s.style.boxShadow="none",s.style.textShadow="none",s.style.setProperty("user-select","none"),s.style.setProperty("-webkit-user-select","none")}),e.tabIndex=-1,e.removeAttribute("role"),e.removeAttribute("aria-multiline"),Array.from(e.querySelectorAll("textarea")).forEach(s=>{s.style.setProperty("caret-color","transparent"),s.style.color="transparent",s.style.setProperty("-webkit-text-fill-color","transparent"),s.style.background="transparent",s.style.border="0",s.style.outline="none",s.style.boxShadow="none",s.style.textShadow="none",s.style.fontSize="0",s.style.lineHeight="0",s!==c&&s.getAttribute("data-terminal-disabled-input")!=="true"&&(s.setAttribute("data-terminal-disabled-input","true"),s.setAttribute("aria-hidden","true"),s.tabIndex=-1,s.disabled=!0,s.style.position="absolute",s.style.opacity="0",s.style.width="0px",s.style.height="0px",s.style.pointerEvents="none",s.style.zIndex="-1")})},[b]),A=n.useCallback(e=>{if(Fe.current===e)return;const c=B.current;if(c)try{if(typeof c.setOption=="function"){c.setOption("cursorBlink",e),Fe.current=e;return}c.options&&(c.options.cursorBlink=e,Fe.current=e)}catch{}},[]),pe=b&&lt,S=n.useCallback((e,c)=>{const a=pe?We.current:ae.current,w=O.current;if(!a||!w)return;const s=w.getBoundingClientRect(),T=typeof window<"u"?window.innerWidth:s.width,h=typeof window<"u"?window.innerHeight:s.height,te=s.left+s.width/2,M=s.top+s.height-12,o=typeof e=="number"?e:te,P=typeof c=="number"?c:M,Y=8,me=Math.max(Y,Math.min(T-Y,o)),$=Math.max(Y,Math.min(h-Y,P));a.style.left=`${me}px`,a.style.top=`${$}px`,a.style.bottom="",(a instanceof HTMLTextAreaElement||a instanceof HTMLInputElement)&&(a.disabled=!1,a.readOnly=!1,a.removeAttribute("disabled"),a.removeAttribute("readonly"));try{a.focus({preventScroll:!0})}catch{try{a.focus()}catch{}}},[pe]),F=n.useCallback(()=>{if(b){S(),A(!0);return}B.current?.focus(),A(!0)},[S,A,b]),N=n.useCallback(e=>e instanceof HTMLTextAreaElement||e instanceof HTMLInputElement?e.value:e.textContent??"",[]),U=n.useCallback(e=>{if(e instanceof HTMLTextAreaElement||e instanceof HTMLInputElement){e.value="";return}e.textContent=""},[]),Ye=n.useCallback(e=>{if(typeof window>"u"||pe)return;D.current!==null&&(window.clearTimeout(D.current),D.current=null);let c=0;const a=3,w=()=>{D.current=window.setTimeout(()=>{D.current=null;const s=N(e);if(!s){if(c+=1,c<a){w();return}return}const T=he.current;he.current=s;const h=s.startsWith(T)?s.slice(T.length):s;h&&K.current(h.replace(/\r\n|\r|\n/g,"\r")),U(e),he.current=""},c===0?0:24)};w()},[U,N,pe]);n.useEffect(()=>{const e=O.current;if(!b||!e||R)return;const c=a=>{const w=a.target;if(w&&w.getAttribute("data-terminal-hidden-input")!=="true"&&e.contains(w)){try{w.blur()}catch{}S()}};return e.addEventListener("focusin",c,!0),()=>{e.removeEventListener("focusin",c,!0)}},[R,b,S]);const qe=n.useCallback(()=>{const e=B.current;if(!e||typeof e.getSelection!="function")return"";const c=e.getSelection();return typeof c=="string"?c:""},[]),Xe=n.useCallback(()=>{if(typeof window>"u")return"";const e=window.getSelection();if(!e)return"";const c=e.toString();if(!c.trim())return"";const a=O.current;if(!a)return"";const w=e.anchorNode,s=e.focusNode;return w&&!a.contains(w)||s&&!a.contains(s)?"":c},[]),ve=n.useCallback(async()=>{if(typeof document>"u")return;const e=qe()||Xe();e.trim()&&await Ct(e)},[Xe,qe]),Z=n.useCallback(()=>qe().trim()?!0:!!Xe().trim(),[Xe,qe]);n.useEffect(()=>{if(typeof window>"u")return;const e=c=>{Z()&&(c.preventDefault(),ve())};return window.addEventListener("openchamber:copy",e),()=>{window.removeEventListener("openchamber:copy",e)}},[ve,Z]);const ce=n.useCallback(()=>{Ae.current="",se.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(se.current),se.current=null,Ve.current=!1,Le.current=null},[]),H=n.useCallback(()=>{const e=tt.current,c=B.current,a=O.current;if(!e||!c||!a)return;const w=a.getBoundingClientRect();if(!(w.width<24||w.height<24))try{e.fit();const s={cols:c.cols,rows:c.rows},T=v.current;(!T||T.cols!==s.cols||T.rows!==s.rows)&&(v.current=s,Ue.current(s.cols,s.rows))}catch{}},[]),xe=n.useCallback(()=>{if(Ve.current)return;const e=B.current;if(!e){ce();return}if(!Ae.current)return;const c=Ae.current;Ae.current="",Ve.current=!0,e.write(c,()=>{Ve.current=!1,Ae.current&&(typeof window<"u"?se.current=window.requestAnimationFrame(()=>{se.current=null,xe()}):xe())})},[ce]),Pe=n.useCallback(()=>{se.current===null&&(typeof window<"u"?se.current=window.requestAnimationFrame(()=>{se.current=null,xe()}):xe())},[xe]),$e=n.useCallback(e=>{e&&(Ae.current+=e,Pe())},[Pe]),De=n.useCallback(()=>{if(ie.current?.(),ie.current=null,Q.current!==null&&typeof window<"u"&&(window.clearTimeout(Q.current),Q.current=null),!R){Ie.current=0;return}const e=O.current;if(!e)return;const c=B.current;if(!c)return;Ie.current=0;const a=2.2,w=2.8,s=25,T=.25,h=8,te=.05,M=.015,o={lastY:null,lastTime:null,velocity:0,rafId:null,startX:null,startY:null,didMove:!1},P=()=>typeof performance<"u"?performance.now():Date.now(),Y=Math.max(12,Math.round(_*1.35));let me=0;const $=i=>{if(!i)return!1;const W=c.getViewportY(),re=me+i,le=Math.trunc(re/Y);return me=re-le*Y,le!==0&&c.scrollLines(le),c.getViewportY()!==W},ke=()=>{o.rafId!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.rafId),o.rafId=null},k={passive:!1,capture:!1};if(typeof window<"u"&&"PointerEvent"in window){const i=Object.assign(o,{pointerId:null,startX:null,startY:null,moved:!1}),W=6,re=r=>{if(r.pointerType==="touch"){ke(),i.pointerId=r.pointerId,i.startX=r.clientX,i.startY=r.clientY,i.moved=!1,i.lastY=r.clientY,i.lastTime=P(),i.velocity=0;try{e.setPointerCapture(r.pointerId)}catch{}}},le=r=>{if(r.pointerType!=="touch"||i.pointerId!==r.pointerId)return;if(i.startX!==null&&i.startY!==null&&!i.moved){const ut=r.clientX-i.startX,ze=r.clientY-i.startY;Math.hypot(ut,ze)>=W&&(i.moved=!0)}if(i.lastY===null){i.lastY=r.clientY,i.lastTime=P();return}const g=i.lastY,m=i.lastTime??P(),x=P();i.lastY=r.clientY,i.lastTime=x;const y=g-r.clientY;if(Math.abs(y)<1)return;const G=Math.max(x-m,8),Ee=a+Math.min(w,Math.abs(y)/s),we=y*Ee,Re=we/G;i.velocity=i.velocity*(1-T)+Re*T,i.velocity>h?i.velocity=h:i.velocity<-h&&(i.velocity=-h),i.moved&&(r.cancelable&&r.preventDefault(),r.stopPropagation()),$(we)},ue=r=>{if(r.pointerType!=="touch"||i.pointerId!==r.pointerId)return;const g=!i.moved;i.pointerId=null,i.startX=null,i.startY=null,i.moved=!1,i.lastY=null,i.lastTime=null;try{e.releasePointerCapture(r.pointerId)}catch{}if(g){b?S(r.clientX,r.clientY):R&&!L.current&&(L.current=!0,B.current?.focus());return}if(typeof window>"u")return;if(Math.abs(i.velocity)<te){i.velocity=0;return}let m=P();const x=()=>{const y=P(),G=Math.max(y-m,8);m=y;const Ee=$(i.velocity*G)??!1,we=Math.sign(i.velocity),Re=Math.max(0,Math.abs(i.velocity)-M*G);if(i.velocity=Re*we,!Ee||Re<=te){ke(),i.velocity=0;return}i.rafId=window.requestAnimationFrame(x)};i.rafId=window.requestAnimationFrame(x)};e.addEventListener("pointerdown",re,k),e.addEventListener("pointermove",le,k),e.addEventListener("pointerup",ue,k),e.addEventListener("pointercancel",ue,k);const t=e.style.touchAction,p=e.style.overscrollBehaviorY;e.style.touchAction="none",e.style.overscrollBehaviorY="contain",ie.current=()=>{ke(),Q.current!==null&&typeof window<"u"&&(window.clearTimeout(Q.current),Q.current=null),Ie.current=0,e.removeEventListener("pointerdown",re,k),e.removeEventListener("pointermove",le,k),e.removeEventListener("pointerup",ue,k),e.removeEventListener("pointercancel",ue,k),e.style.touchAction=t,e.style.overscrollBehaviorY=p};return}const C=6,Ce=i=>{i.touches.length===1&&(ke(),o.lastY=i.touches[0].clientY,o.lastTime=P(),o.velocity=0,o.startX=i.touches[0].clientX,o.startY=i.touches[0].clientY,o.didMove=!1)},Be=i=>{if(i.touches.length!==1){o.lastY=null,o.lastTime=null,o.velocity=0,o.startX=null,o.startY=null,o.didMove=!1,ke();return}const W=i.touches[0].clientX,re=i.touches[0].clientY;if(o.startX!==null&&o.startY!==null&&!o.didMove){const y=W-o.startX,G=re-o.startY;Math.hypot(y,G)>=C&&(o.didMove=!0)}if(o.lastY===null){o.lastY=re,o.lastTime=P();return}const le=o.lastY,ue=o.lastTime??P(),t=P();o.lastY=re,o.lastTime=t;const p=le-re;if(Math.abs(p)<1)return;const r=Math.max(t-ue,8),g=a+Math.min(w,Math.abs(p)/s),m=p*g,x=m/r;o.velocity=o.velocity*(1-T)+x*T,o.velocity>h?o.velocity=h:o.velocity<-h&&(o.velocity=-h),o.didMove&&(i.preventDefault(),i.stopPropagation()),$(m)},z=i=>{const W=!o.didMove;o.lastY=null,o.lastTime=null;const re=o.velocity;if(o.startX=null,o.startY=null,o.didMove=!1,W){const t=i.changedTouches?.[0];b?S(t?.clientX,t?.clientY):R&&!L.current&&(L.current=!0,B.current?.focus());return}if(typeof window>"u")return;if(Math.abs(re)<te){o.velocity=0;return}let le=P();const ue=()=>{const t=P(),p=Math.max(t-le,8);le=t;const r=$(o.velocity*p)??!1,g=Math.sign(o.velocity),m=Math.max(0,Math.abs(o.velocity)-M*p);if(o.velocity=m*g,!r||m<=te){ke(),o.velocity=0;return}o.rafId=window.requestAnimationFrame(ue)};o.rafId=window.requestAnimationFrame(ue)};e.addEventListener("touchstart",Ce,k),e.addEventListener("touchmove",Be,k),e.addEventListener("touchend",z,k),e.addEventListener("touchcancel",z,k);const Qe=e.style.touchAction,j=e.style.overscrollBehaviorY;e.style.touchAction="none",e.style.overscrollBehaviorY="contain",ie.current=()=>{ke(),Q.current!==null&&typeof window<"u"&&(window.clearTimeout(Q.current),Q.current=null),Ie.current=0,e.removeEventListener("touchstart",Ce,k),e.removeEventListener("touchmove",Be,k),e.removeEventListener("touchend",z,k),e.removeEventListener("touchcancel",z,k),e.style.touchAction=Qe,e.style.overscrollBehaviorY=j}},[R,b,S,_]);n.useEffect(()=>{let e=!1,c=null,a=null,w=null,s=[],T=null,h=null,te=null;const M=O.current;if(!M)return;if(M.tabIndex=b?-1:0,b){const k=M.focus.bind(M),ne=M;ne.focus=((...C)=>{S()}),te=()=>{ne.focus=k}}const o=()=>{A(!0)},P=()=>{A(!1)},Y=k=>{const ne=k.target;if(ne&&M.contains(ne)){if(b&&ne instanceof HTMLElement){window.setTimeout(()=>{ne.blur(),S()},0),A(!1);return}if(R&&!L.current&&ne instanceof HTMLElement){window.setTimeout(()=>{ne.blur()},0),A(!1);return}A(!0);return}A(!1)},me=()=>{A(!1)};let $=null;return(async()=>{try{const k=await Lt();if(e)return;const ne=Vt(X,_,E,k,!1),C=new xt(ne);be.current=!0,b&&(C.focus=()=>{});const Ce=C;if(typeof Ce.scrollToBottom=="function"){const j=Ce.scrollToBottom.bind(Ce);Ce.scrollToBottom=()=>{be.current&&j()},T=()=>{Ce.scrollToBottom=j}}const Be=new Tt;if(c=C,B.current=C,tt.current=Be,C.loadAddon(Be),C.open(M),R){const j=C.renderer;if(j&&typeof j.renderScrollbar=="function"){const i=j.renderScrollbar.bind(j);j.renderScrollbar=()=>{},h=()=>{j.renderScrollbar=i}}}ct(),Fe.current=!1,$=C.textarea??M.querySelector("textarea"),$&&($.addEventListener("focus",o),$.addEventListener("blur",P)),ot(),typeof MutationObserver<"u"&&(w=new MutationObserver(()=>{ot()}),w.observe(M,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["contenteditable","role","tabindex","aria-label"]}));const z=Ft(M);z?(z.classList.add("overlay-scrollbar-target","overlay-scrollbar-container"),je.current=z,dt()):je.current=null,H();const Qe=Be;typeof Qe.observeResize=="function"&&Qe.observeResize(),De(),s=[C.onData(j=>{K.current(j)}),C.onScroll(j=>{if(typeof j=="number"&&Number.isFinite(j)){const i=typeof C.hasSelection=="function"&&C.hasSelection();be.current=!i&&j<=.5}}),C.onSelectionChange(()=>{if(typeof C.hasSelection=="function"&&C.hasSelection()){be.current=!1;return}const i=typeof C.getViewportY=="function"?C.getViewportY():0;be.current=i<=.5})],a=new ResizeObserver(()=>{H()}),a.observe(M),typeof window<"u"&&window.setTimeout(()=>{H()},0)}catch{}})(),document.addEventListener("focusin",Y,!0),window.addEventListener("blur",me),()=>{e=!0,ie.current?.(),ie.current=null,document.removeEventListener("focusin",Y,!0),window.removeEventListener("blur",me),s.forEach(k=>k.dispose()),T?.(),T=null,h?.(),h=null,$&&($.removeEventListener("focus",o),$.removeEventListener("blur",P)),a?.disconnect(),w?.disconnect(),te?.(),c?.dispose(),B.current=null,tt.current=null,je.current=null,v.current=null,Fe.current=null,ce()}},[ot,R,H,S,X,_,De,E,ce,A,b]),n.useEffect(()=>{const e=B.current;e&&(e.reset(),ce(),v.current=null,H())},[u,rt,H,ce]),n.useEffect(()=>{!at||!B.current||F()},[at,F,u,rt]),n.useEffect(()=>(De(),()=>{ie.current?.(),ie.current=null}),[De,u]),n.useEffect(()=>{const e=B.current;if(!e)return;if(l.length===0){Le.current!==null&&(e.reset(),ce(),H());return}const c=Le.current;let a;if(c===null)a=l;else{const w=l.findIndex(s=>s.id===c);a=w>=0?l.slice(w+1):l}a.length>0&&$e(a.map(w=>w.data).join("")),Le.current=l[l.length-1].id},[l,rt,$e,H,ce]),n.useImperativeHandle(Se,()=>({focus:()=>{F()},clear:()=>{const e=B.current;e&&(e.reset(),ce(),H())},fit:()=>{H()}}),[F,H,ce]);const Ge=n.useCallback(e=>{if(!b)return;const c=O.current,a=e.relatedTarget,w=a?.tagName,s=w==="INPUT"||w==="TEXTAREA"||a?.isContentEditable,T=a?.getAttribute("data-terminal-hidden-input")==="true",h=!!(a&&c?.contains(a))},[b]),Oe=n.useCallback(e=>{const c=e.nativeEvent,a=c?.inputType??"",w=typeof c?.data=="string"?c.data:"";if(V.current=typeof performance<"u"?performance.now():Date.now(),a==="insertCompositionText"){de.current=!0;return}if(!a&&w){if(de.current)return;e.preventDefault(),K.current(w),ge.current={type:"insertText",at:typeof performance<"u"?performance.now():Date.now()},ee.current=!0;return}if(a==="insertText"&&w){if(de.current)return;e.preventDefault(),K.current(w),ge.current={type:a,at:typeof performance<"u"?performance.now():Date.now()},ee.current=!0;return}if(a==="insertLineBreak"){if(de.current)return;e.preventDefault(),K.current("\r"),ge.current={type:a,at:typeof performance<"u"?performance.now():Date.now()},ee.current=!0;return}if(a==="deleteContentBackward"){if(de.current)return;e.preventDefault(),K.current(""),ge.current={type:a,at:typeof performance<"u"?performance.now():Date.now()},ee.current=!0}},[]),st=n.useCallback(e=>{const c=e.currentTarget;if(V.current=typeof performance<"u"?performance.now():Date.now(),de.current)return;if(ee.current){const s=ge.current,T=typeof performance<"u"?performance.now():Date.now();if(s&&T-s.at<50){ee.current=!1,U(c);return}ee.current=!1}const a=N(c);if(!a)return;he.current=a;const w=a.replace(/\r\n|\r|\n/g,"\r");K.current(w),U(c),he.current=""},[U,N]),_e=n.useCallback(e=>{e.stopPropagation();const c=e.key.toLowerCase(),a=e.metaKey&&!e.ctrlKey&&!e.altKey&&c==="c",w=e.ctrlKey&&e.shiftKey&&!e.metaKey&&!e.altKey&&c==="c";if((a||w)&&Z()){e.preventDefault(),ve();return}if(e.ctrlKey&&!e.metaKey&&!e.altKey&&e.key.length===1){const Y=e.key.toUpperCase();if(Y>="A"&&Y<="Z"){e.preventDefault(),e.nativeEvent?.stopImmediatePropagation(),K.current(String.fromCharCode(Y.charCodeAt(0)-64)),U(e.currentTarget);return}}if(e.altKey&&!e.ctrlKey&&!e.metaKey&&e.key.length===1){e.preventDefault(),e.nativeEvent?.stopImmediatePropagation(),K.current("\x1B"+e.key),U(e.currentTarget);return}const T={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(T){e.preventDefault(),K.current(T),U(e.currentTarget);return}const h=e.currentTarget;if(e.nativeEvent?.isComposing)return;const M=ge.current,o=typeof performance<"u"?performance.now():Date.now(),P=!!(M&&o-M.at<50);if(e.key==="Enter"){if(P&&M?.type==="insertLineBreak")return;e.preventDefault(),K.current("\r"),U(h);return}if(e.key==="Backspace"){if(e.preventDefault(),P&&M?.type==="deleteContentBackward")return;N(h)||K.current("")}if(e.key.length===1&&!e.ctrlKey&&!e.metaKey&&!e.altKey){const Y=V.current;Y&&o-Y<50||(e.preventDefault(),K.current(e.key),ee.current=!0,ge.current={type:"keydown-text",at:o})}Ye(h)},[U,ve,Z,N,Ye]),Ke=n.useCallback(e=>{e.stopPropagation();const c=e.currentTarget;e.nativeEvent?.isComposing||Ye(c)},[Ye]),Je=n.useCallback(e=>{const c=e.currentTarget;de.current=!1;const a=e.data||N(c);if(V.current=typeof performance<"u"?performance.now():Date.now(),!a)return;const w=a.replace(/\r\n|\r|\n/g,"\r");K.current(w),U(c),ge.current={type:"compositionend",at:typeof performance<"u"?performance.now():Date.now()},ee.current=!0},[U,N]),He=n.useCallback(e=>{e.stopPropagation();const c=e.clipboardData?.getData("text")??"";if(!c)return;e.preventDefault();const w=B.current?.hasBracketedPaste?.()?`\x1B[200~${c}\x1B[201~`:c;K.current(w)},[]),Te={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 f.jsxs("div",{ref:O,className:et("relative h-full w-full terminal-viewport-container",ye),"data-hidden-input-overlay-active":b?"true":void 0,style:{backgroundColor:E.background},onTouchStart:e=>{if(!(!b||R)&&!Z()){const c=e.touches?.[0];S(c?.clientX,c?.clientY)}},onClick:e=>{if(!R)if(b){if(Z())return;S(e.clientX,e.clientY)}else B.current?.focus()},onMouseUp:()=>{!R&&Z()&&ve()},onTouchEnd:()=>{!R&&Z()&&ve()},children:[b&&typeof document<"u"?vt.createPortal(f.jsxs(f.Fragment,{children:[f.jsx("input",{ref:We,type:"text",inputMode:"text",autoCapitalize:"off",autoComplete:"off",autoCorrect:"off",spellCheck:!1,tabIndex:-1,enterKeyHint:"send","data-terminal-hidden-input":"true","aria-label":J("terminalView.viewport.inputAria"),"aria-hidden":"true",style:{...Te,display:pe?"block":"none"},onBlur:Ge,onBeforeInput:Oe,onCompositionStart:()=>{de.current=!0},onInput:st,onKeyDown:_e,onKeyUp:Ke,onCompositionEnd:Je,onPaste:He}),f.jsx("textarea",{ref:ae,inputMode:"text",autoCapitalize:"off",autoComplete:"off",autoCorrect:"off",spellCheck:!1,tabIndex:-1,enterKeyHint:"send","data-terminal-hidden-input":"true","aria-label":J("terminalView.viewport.inputAria"),"aria-hidden":"true",style:{...Te,display:pe?"none":"block"},onBlur:Ge,onBeforeInput:Oe,onCompositionStart:()=>{de.current=!0},onInput:st,onKeyDown:_e,onKeyUp:Ke,onCompositionEnd:Je,onPaste:He})]}),document.body):null,je.current&&!R?f.jsx(Et,{containerRef:je,disableHorizontal:!0,className:"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero"}):null]})});gt.displayName="TerminalViewport";const Yt="\x1B",Ot=new RegExp(`${Yt}\\[[0-9;?]*[ -/]*[@-~]`,"g"),Kt=/(https?:\/\/(?:localhost|127\.0\.0\.1|0\.0\.0\.0|\[(?:::1|::)\])(?::\d{2,5})?(?:\/[^\s<>'"`]*)?)/gi,Ht=/(?:➜\s*(?:Local|Network):)|\b(?:local|network|loopback|serving|listening|available|ready|started|running|server|vite|webpack|next\.js|astro|sveltekit|nuxt)\b/i,zt=/Serving HTTP on .*? port (\d{2,5})/i,Ut=new Set([".",",",";",":","!","?"]),Wt=u=>{let l=u;for(;l.length>0;){const d=l[l.length-1];if(d===")"||d==="]"||d==="}"||d===">"){const I=d===")"?"(":d==="]"?"[":d==="}"?"{":"<",E=l.slice(0,-1),X=(E.match(new RegExp(`\\${I}`,"g"))||[]).length,_=(E.match(new RegExp(`\\${d}`,"g"))||[]).length;if(X>_)break;l=E;continue}if(Ut.has(d)){l=l.slice(0,-1);continue}break}return l},yt=u=>{let l=Wt(u);return l=l.replace("0.0.0.0","127.0.0.1"),l=l.replace("[::1]","127.0.0.1"),l=l.replace("[::]","127.0.0.1"),l},qt=u=>{if(!u)return null;const l=u.replace(Ot,""),d=l.match(zt);if(d?.[1]){const E=Number.parseInt(d[1],10);if(Number.isFinite(E)&&E>0&&E<=65535)return`http://127.0.0.1:${E}/`}const I=l.split(`
2
2
  `);for(const E of I){if(!Ht.test(E))continue;const X=Array.from(E.matchAll(Kt));if(X.length===0)continue;const _=X.find(ye=>{try{return!!new URL(yt(ye[1])).port}catch{return!1}});return yt((_??X[0])[1])}return null},Xt=async(u,l=1500)=>{if(!u||typeof window>"u")return!1;let d;try{d=new URL(u)}catch{return!1}if(d.protocol!=="http:"&&d.protocol!=="https:")return!1;const I=d.hostname.toLowerCase();if(I!=="localhost"&&I!=="127.0.0.1"&&I!=="0.0.0.0"&&I!=="::1"&&I!=="::")return!1;const E=new AbortController,X=window.setTimeout(()=>E.abort(),l);try{const _=await Mt("/api/system/probe-url",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:d.toString()}),cache:"no-store",signal:E.signal});return _.ok?(await _.json().catch(()=>null))?.ok===!0:!1}catch{return!1}finally{window.clearTimeout(X)}},$t={esc:"\x1B",tab:" ",enter:"\r","arrow-up":"\x1B[A","arrow-down":"\x1B[B","arrow-left":"\x1B[D","arrow-right":"\x1B[C"},ft={ctrl:"5",cmd:"3"},wt={retry:{maxRetries:3,initialDelayMs:500,maxDelayMs:8e3},connectionTimeoutMs:1e4},Gt={retry:{...wt.retry,initialDelayMs:200,maxDelayMs:500},connectionTimeoutMs:1500},_t=(u,l)=>{if(l)switch(u){case"arrow-up":return`\x1B[1;${ft[l]}A`;case"arrow-down":return`\x1B[1;${ft[l]}B`;case"arrow-right":return`\x1B[1;${ft[l]}C`;case"arrow-left":return`\x1B[1;${ft[l]}D`}return $t[u]??null},sn=()=>{const{t:u}=bt(),{terminal:l,runtime:d}=Rt(),{currentTheme:I}=St(),{monoFont:E}=At(),X=Me(t=>t.terminalFontSize),_=Me(t=>t.bottomTerminalHeight),ye=Me(t=>t.isBottomTerminalExpanded),{isMobile:R,isTablet:at,hasTouchOnlyPointer:Ne}=It(),Se=R||at,J=(Se||Ne)&&d.platform==="web",O=d.platform!=="vscode",je=Me(t=>t.showTerminalQuickKeysOnDesktop),B=Se||je,tt=ht(t=>t.currentSessionId),K=ht(t=>t.newSessionDraft),Ue=tt!==null||K?.open===!0,v=Bt()??null,Ae=q(t=>t.sessions),se=q(t=>t.hasHydrated),Ve=q(t=>t.ensureDirectory),Le=q(t=>t.createTab),be=q(t=>t.setActiveTab),ie=q(t=>t.closeTab),Q=q(t=>t.setTabSessionId),Ie=q(t=>t.setTabLifecycle),ae=q(t=>t.setConnecting),We=q(t=>t.appendToBuffer),de=q(t=>t.setTabPreviewUrl),ee=q(t=>t.clearBuffer),ge=Me(t=>t.openContextPreview),V=n.useMemo(()=>{if(v)return Ae.get(v)},[Ae,v]),D=n.useMemo(()=>V?O?V.activeTabId??V.tabs[0]?.id??null:V.tabs[0]?.id??null:null,[V,O]),he=n.useMemo(()=>{if(V)return D?V.tabs.find(t=>t.id===D)??V.tabs[0]:V.tabs[0]},[V,D]),Fe=n.useMemo(()=>(V?.tabs??[]).map(t=>({icon:(()=>{const p=t.iconKey?Dt[t.iconKey]??"terminal":"terminal";return f.jsx(fe,{name:p,className:"h-4 w-4"})})(),id:t.id,label:t.label,title:t.label,closeLabel:u("terminalView.tabs.closeTabTitle")})),[V?.tabs,u]),L=he?.terminalSessionId??null,nt=he?.lifecycle??"idle",dt=he?.bufferChunks??[],rt=he?.isConnecting??!1,ct=he?.previewUrl??null,[lt,b]=n.useState(null),[ot,A]=n.useState(!1),[pe,S]=n.useState(!1),[F,N]=n.useState(null),[U,Ye]=n.useState(!1),[qe,Xe]=n.useState(0),ve=n.useRef(null),Z=n.useRef(null),ce=n.useRef(D),H=n.useRef(L),xe=n.useRef(v),Pe=n.useRef(null),$e=n.useRef(null),De=n.useRef(!1),Ge=n.useRef(null),Oe=n.useRef(new Set),st=n.useRef(!1),_e=n.useRef(""),Ke=n.useRef(new Set),Je=n.useRef(0),He=n.useCallback(()=>{_e.current="",Ke.current.clear(),Je.current+=1},[]),Te=n.useCallback(()=>{J||typeof document<"u"&&!document.hasFocus()||Pe.current?.focus()},[J]),e=n.useCallback(()=>{J||Pe.current?.focus()},[J]);n.useEffect(()=>{if(!se||st.current)return;st.current=!0;const t=new Set;for(const[,p]of q.getState().sessions.entries())for(const r of p.tabs)r.terminalSessionId&&t.add(r.terminalSessionId);Oe.current=t},[se]);const c=Me(t=>t.activeMainTab),a=Me(t=>t.isBottomTerminalOpen),w=Me(t=>t.setBottomTerminalOpen),s=Me(t=>t.setBottomTerminalExpanded),T=c==="terminal",h=T||a,[te,M]=n.useState(h);n.useEffect(()=>{!h||d.platform==="vscode"||Pt()},[h,d.platform]),n.useEffect(()=>{h&&M(!0)},[h]),n.useEffect(()=>{De.current=h},[h]),n.useEffect(()=>{H.current=L},[L]),n.useEffect(()=>{ce.current=D,He()},[D,He]),n.useEffect(()=>{xe.current=v},[v]),n.useEffect(()=>{!B&&F!==null&&N(null)},[B,F,N]),n.useEffect(()=>{!L&&F!==null&&N(null)},[L,F,N]);const o=n.useCallback(()=>{ve.current?.(),ve.current=null,Z.current=null,S(!1)},[]);n.useEffect(()=>()=>{o(),H.current=null},[o]);const P=n.useCallback((t,p,r)=>{if(!r)return;const g=`${_e.current}${r}`.replace(/\r\n|\r/g,`
3
3
  `),m=g.split(`
4
4
  `),x=g.endsWith(`