9remote 3.0.52 → 3.0.53

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 (194) hide show
  1. package/dist/cli.cjs +2 -2
  2. package/dist/server.cjs +4 -4
  3. package/dist/ui/assets/index-DeWyLHd6.js +8 -0
  4. package/dist/ui/index.html +1 -1
  5. package/dist/web/404.html +1 -1
  6. package/dist/web/__next.__PAGE__.txt +1 -1
  7. package/dist/web/__next._full.txt +1 -1
  8. package/dist/web/__next._head.txt +1 -1
  9. package/dist/web/__next._index.txt +1 -1
  10. package/dist/web/__next._tree.txt +1 -1
  11. package/dist/web/_next/static/chunks/{8126-f4d44cf6bcc47fd8.js → 8126-a51f1e8e7bd07374.js} +1 -1
  12. package/dist/web/_next/static/chunks/app/workspace/{layout-ff89db2ea6f5ca76.js → layout-2df6569422bc5b2e.js} +1 -1
  13. package/dist/web/_not-found/__next._full.txt +1 -1
  14. package/dist/web/_not-found/__next._head.txt +1 -1
  15. package/dist/web/_not-found/__next._index.txt +1 -1
  16. package/dist/web/_not-found/__next._not-found.__PAGE__.txt +1 -1
  17. package/dist/web/_not-found/__next._not-found.txt +1 -1
  18. package/dist/web/_not-found/__next._tree.txt +1 -1
  19. package/dist/web/_not-found.html +1 -1
  20. package/dist/web/_not-found.txt +1 -1
  21. package/dist/web/admin/__next._full.txt +1 -1
  22. package/dist/web/admin/__next._head.txt +1 -1
  23. package/dist/web/admin/__next._index.txt +1 -1
  24. package/dist/web/admin/__next._tree.txt +1 -1
  25. package/dist/web/admin/__next.admin.__PAGE__.txt +1 -1
  26. package/dist/web/admin/__next.admin.txt +1 -1
  27. package/dist/web/admin/access/__next._full.txt +1 -1
  28. package/dist/web/admin/access/__next._head.txt +1 -1
  29. package/dist/web/admin/access/__next._index.txt +1 -1
  30. package/dist/web/admin/access/__next._tree.txt +1 -1
  31. package/dist/web/admin/access/__next.admin.access.__PAGE__.txt +1 -1
  32. package/dist/web/admin/access/__next.admin.access.txt +1 -1
  33. package/dist/web/admin/access/__next.admin.txt +1 -1
  34. package/dist/web/admin/access.html +1 -1
  35. package/dist/web/admin/access.txt +1 -1
  36. package/dist/web/admin/login/__next._full.txt +1 -1
  37. package/dist/web/admin/login/__next._head.txt +1 -1
  38. package/dist/web/admin/login/__next._index.txt +1 -1
  39. package/dist/web/admin/login/__next._tree.txt +1 -1
  40. package/dist/web/admin/login/__next.admin.login.__PAGE__.txt +1 -1
  41. package/dist/web/admin/login/__next.admin.login.txt +1 -1
  42. package/dist/web/admin/login/__next.admin.txt +1 -1
  43. package/dist/web/admin/login.html +1 -1
  44. package/dist/web/admin/login.txt +1 -1
  45. package/dist/web/admin/ota/__next._full.txt +1 -1
  46. package/dist/web/admin/ota/__next._head.txt +1 -1
  47. package/dist/web/admin/ota/__next._index.txt +1 -1
  48. package/dist/web/admin/ota/__next._tree.txt +1 -1
  49. package/dist/web/admin/ota/__next.admin.ota.__PAGE__.txt +1 -1
  50. package/dist/web/admin/ota/__next.admin.ota.txt +1 -1
  51. package/dist/web/admin/ota/__next.admin.txt +1 -1
  52. package/dist/web/admin/ota.html +1 -1
  53. package/dist/web/admin/ota.txt +1 -1
  54. package/dist/web/admin/turn/__next._full.txt +1 -1
  55. package/dist/web/admin/turn/__next._head.txt +1 -1
  56. package/dist/web/admin/turn/__next._index.txt +1 -1
  57. package/dist/web/admin/turn/__next._tree.txt +1 -1
  58. package/dist/web/admin/turn/__next.admin.turn.__PAGE__.txt +1 -1
  59. package/dist/web/admin/turn/__next.admin.turn.txt +1 -1
  60. package/dist/web/admin/turn/__next.admin.txt +1 -1
  61. package/dist/web/admin/turn.html +1 -1
  62. package/dist/web/admin/turn.txt +1 -1
  63. package/dist/web/admin.html +1 -1
  64. package/dist/web/admin.txt +1 -1
  65. package/dist/web/download/__next._full.txt +1 -1
  66. package/dist/web/download/__next._head.txt +1 -1
  67. package/dist/web/download/__next._index.txt +1 -1
  68. package/dist/web/download/__next._tree.txt +1 -1
  69. package/dist/web/download/__next.download.__PAGE__.txt +1 -1
  70. package/dist/web/download/__next.download.txt +1 -1
  71. package/dist/web/download.html +1 -1
  72. package/dist/web/download.txt +1 -1
  73. package/dist/web/index.html +1 -1
  74. package/dist/web/index.txt +1 -1
  75. package/dist/web/login/__next._full.txt +2 -2
  76. package/dist/web/login/__next._head.txt +1 -1
  77. package/dist/web/login/__next._index.txt +1 -1
  78. package/dist/web/login/__next._tree.txt +1 -1
  79. package/dist/web/login/__next.login.__PAGE__.txt +2 -2
  80. package/dist/web/login/__next.login.txt +1 -1
  81. package/dist/web/login.html +1 -1
  82. package/dist/web/login.txt +2 -2
  83. package/dist/web/workspace/__next._full.txt +2 -2
  84. package/dist/web/workspace/__next._head.txt +1 -1
  85. package/dist/web/workspace/__next._index.txt +1 -1
  86. package/dist/web/workspace/__next._tree.txt +1 -1
  87. package/dist/web/workspace/__next.workspace.__PAGE__.txt +1 -1
  88. package/dist/web/workspace/__next.workspace.txt +2 -2
  89. package/dist/web/workspace/browse/__next._full.txt +2 -2
  90. package/dist/web/workspace/browse/__next._head.txt +1 -1
  91. package/dist/web/workspace/browse/__next._index.txt +1 -1
  92. package/dist/web/workspace/browse/__next._tree.txt +1 -1
  93. package/dist/web/workspace/browse/__next.workspace.browse.__PAGE__.txt +1 -1
  94. package/dist/web/workspace/browse/__next.workspace.browse.txt +1 -1
  95. package/dist/web/workspace/browse/__next.workspace.txt +2 -2
  96. package/dist/web/workspace/browse.html +1 -1
  97. package/dist/web/workspace/browse.txt +2 -2
  98. package/dist/web/workspace/editor/__next._full.txt +2 -2
  99. package/dist/web/workspace/editor/__next._head.txt +1 -1
  100. package/dist/web/workspace/editor/__next._index.txt +1 -1
  101. package/dist/web/workspace/editor/__next._tree.txt +1 -1
  102. package/dist/web/workspace/editor/__next.workspace.editor.__PAGE__.txt +1 -1
  103. package/dist/web/workspace/editor/__next.workspace.editor.txt +1 -1
  104. package/dist/web/workspace/editor/__next.workspace.txt +2 -2
  105. package/dist/web/workspace/editor.html +1 -1
  106. package/dist/web/workspace/editor.txt +2 -2
  107. package/dist/web/workspace/files/__next._full.txt +2 -2
  108. package/dist/web/workspace/files/__next._head.txt +1 -1
  109. package/dist/web/workspace/files/__next._index.txt +1 -1
  110. package/dist/web/workspace/files/__next._tree.txt +1 -1
  111. package/dist/web/workspace/files/__next.workspace.files.__PAGE__.txt +1 -1
  112. package/dist/web/workspace/files/__next.workspace.files.txt +1 -1
  113. package/dist/web/workspace/files/__next.workspace.txt +2 -2
  114. package/dist/web/workspace/files.html +1 -1
  115. package/dist/web/workspace/files.txt +2 -2
  116. package/dist/web/workspace/git/__next._full.txt +2 -2
  117. package/dist/web/workspace/git/__next._head.txt +1 -1
  118. package/dist/web/workspace/git/__next._index.txt +1 -1
  119. package/dist/web/workspace/git/__next._tree.txt +1 -1
  120. package/dist/web/workspace/git/__next.workspace.git.__PAGE__.txt +1 -1
  121. package/dist/web/workspace/git/__next.workspace.git.txt +1 -1
  122. package/dist/web/workspace/git/__next.workspace.txt +2 -2
  123. package/dist/web/workspace/git.html +1 -1
  124. package/dist/web/workspace/git.txt +2 -2
  125. package/dist/web/workspace/mobile/__next._full.txt +2 -2
  126. package/dist/web/workspace/mobile/__next._head.txt +1 -1
  127. package/dist/web/workspace/mobile/__next._index.txt +1 -1
  128. package/dist/web/workspace/mobile/__next._tree.txt +1 -1
  129. package/dist/web/workspace/mobile/__next.workspace.mobile.__PAGE__.txt +1 -1
  130. package/dist/web/workspace/mobile/__next.workspace.mobile.txt +1 -1
  131. package/dist/web/workspace/mobile/__next.workspace.txt +2 -2
  132. package/dist/web/workspace/mobile.html +1 -1
  133. package/dist/web/workspace/mobile.txt +2 -2
  134. package/dist/web/workspace/pair/__next._full.txt +2 -2
  135. package/dist/web/workspace/pair/__next._head.txt +1 -1
  136. package/dist/web/workspace/pair/__next._index.txt +1 -1
  137. package/dist/web/workspace/pair/__next._tree.txt +1 -1
  138. package/dist/web/workspace/pair/__next.workspace.pair.__PAGE__.txt +1 -1
  139. package/dist/web/workspace/pair/__next.workspace.pair.txt +1 -1
  140. package/dist/web/workspace/pair/__next.workspace.txt +2 -2
  141. package/dist/web/workspace/pair.html +1 -1
  142. package/dist/web/workspace/pair.txt +2 -2
  143. package/dist/web/workspace/remote/__next._full.txt +2 -2
  144. package/dist/web/workspace/remote/__next._head.txt +1 -1
  145. package/dist/web/workspace/remote/__next._index.txt +1 -1
  146. package/dist/web/workspace/remote/__next._tree.txt +1 -1
  147. package/dist/web/workspace/remote/__next.workspace.remote.__PAGE__.txt +1 -1
  148. package/dist/web/workspace/remote/__next.workspace.remote.txt +1 -1
  149. package/dist/web/workspace/remote/__next.workspace.txt +2 -2
  150. package/dist/web/workspace/remote.html +1 -1
  151. package/dist/web/workspace/remote.txt +2 -2
  152. package/dist/web/workspace/settings/__next._full.txt +2 -2
  153. package/dist/web/workspace/settings/__next._head.txt +1 -1
  154. package/dist/web/workspace/settings/__next._index.txt +1 -1
  155. package/dist/web/workspace/settings/__next._tree.txt +1 -1
  156. package/dist/web/workspace/settings/__next.workspace.settings.__PAGE__.txt +1 -1
  157. package/dist/web/workspace/settings/__next.workspace.settings.txt +1 -1
  158. package/dist/web/workspace/settings/__next.workspace.txt +2 -2
  159. package/dist/web/workspace/settings.html +1 -1
  160. package/dist/web/workspace/settings.txt +2 -2
  161. package/dist/web/workspace/terminal/default/__next._full.txt +2 -2
  162. package/dist/web/workspace/terminal/default/__next._head.txt +1 -1
  163. package/dist/web/workspace/terminal/default/__next._index.txt +1 -1
  164. package/dist/web/workspace/terminal/default/__next._tree.txt +1 -1
  165. package/dist/web/workspace/terminal/default/__next.workspace.terminal.$d$sessionId.__PAGE__.txt +1 -1
  166. package/dist/web/workspace/terminal/default/__next.workspace.terminal.$d$sessionId.txt +1 -1
  167. package/dist/web/workspace/terminal/default/__next.workspace.terminal.txt +1 -1
  168. package/dist/web/workspace/terminal/default/__next.workspace.txt +2 -2
  169. package/dist/web/workspace/terminal/default.html +1 -1
  170. package/dist/web/workspace/terminal/default.txt +2 -2
  171. package/dist/web/workspace/welcome/__next._full.txt +2 -2
  172. package/dist/web/workspace/welcome/__next._head.txt +1 -1
  173. package/dist/web/workspace/welcome/__next._index.txt +1 -1
  174. package/dist/web/workspace/welcome/__next._tree.txt +1 -1
  175. package/dist/web/workspace/welcome/__next.workspace.txt +2 -2
  176. package/dist/web/workspace/welcome/__next.workspace.welcome.__PAGE__.txt +1 -1
  177. package/dist/web/workspace/welcome/__next.workspace.welcome.txt +1 -1
  178. package/dist/web/workspace/welcome.html +1 -1
  179. package/dist/web/workspace/welcome.txt +2 -2
  180. package/dist/web/workspace/workspaces/__next._full.txt +2 -2
  181. package/dist/web/workspace/workspaces/__next._head.txt +1 -1
  182. package/dist/web/workspace/workspaces/__next._index.txt +1 -1
  183. package/dist/web/workspace/workspaces/__next._tree.txt +1 -1
  184. package/dist/web/workspace/workspaces/__next.workspace.txt +2 -2
  185. package/dist/web/workspace/workspaces/__next.workspace.workspaces.__PAGE__.txt +1 -1
  186. package/dist/web/workspace/workspaces/__next.workspace.workspaces.txt +1 -1
  187. package/dist/web/workspace/workspaces.html +1 -1
  188. package/dist/web/workspace/workspaces.txt +2 -2
  189. package/dist/web/workspace.html +1 -1
  190. package/dist/web/workspace.txt +2 -2
  191. package/package.json +1 -1
  192. package/dist/ui/assets/index-BgdHbxnD.js +0 -8
  193. /package/dist/web/_next/static/{Sbm6VmM9scgfPUKCTCQc1 → jLJ84zU9gIrZyC5esrgWl}/_buildManifest.js +0 -0
  194. /package/dist/web/_next/static/{Sbm6VmM9scgfPUKCTCQc1 → jLJ84zU9gIrZyC5esrgWl}/_ssgManifest.js +0 -0
@@ -10,7 +10,7 @@ ${r0(h||[])}`}),setTimeout(()=>t?.emit("input",{sessionId:s,data:"\r"}),ez.YS),a
10
10
  \x1b[1;31mError: ${a.error||"Failed to join session"}\x1b[0m\r
11
11
  `)}})}};return u}({bus:b,sessionId:s,term:i,fitAddon:m,writeBatcherRef:y,doResizeRef:S,fireJoinRef:E,refs:{historyMirrorRef:H,historyBytesRef:q,historyTotalRef:U,historyFetchingRef:X,userAtTopRef:ex,joiningRef:Q,joinClaimedRef:ee,joinQueueRef:er,joinGenRef:el,lastSeqRef:Z,cwdRef:z,setJoining:en},setCwd:I}),eE=c>0?setTimeout(eT,c):null;eE||eT(),T.current=eT;let eR=()=>{if(g.current){var e;(e={historyFetching:X,historyHaveAtEmit:G,awaitingTuiOutput:F,joining:Q,joinClaimed:ee,joinQueue:er,prefixFrags:J}).historyFetching&&(e.historyFetching.current=!1),e.historyHaveAtEmit&&(e.historyHaveAtEmit.current=0),e.awaitingTuiOutput&&(e.awaitingTuiOutput.current=!1),e.joining&&(e.joining.current=!1),e.joinClaimed&&(e.joinClaimed.current=!1),e.joinQueue&&(e.joinQueue.current=[]),e.prefixFrags&&(e.prefixFrags.current=null),e.awaitingGap&&(e.awaitingGap.current?.timer&&clearTimeout(e.awaitingGap.current.timer),e.awaitingGap.current=null),ev.cancel(),B.cancel(),clearTimeout(es),es=null,ed=!1,eg++,eu(!1),en(!1),ew("reconnect")}};b.on("connect",eR);let eM=()=>setTimeout(()=>{let e=g.current,t=v.current;e&&!e._isDisposed&&t&&(t.fit(),t.fit(),S.current?.({force:!0}))},ez.Uc);window.addEventListener("orientationchange",eM);let e$=()=>{!document.hidden&&g.current&&(g.current.refresh(0,g.current.rows-1),u.d.getState().connected&&ew("visible"))};return document.addEventListener("visibilitychange",e$),()=>{window.removeEventListener("orientationchange",eM),document.removeEventListener("visibilitychange",e$),D.disconnect(),h.removeEventListener("wheel",R),b.off("connect",eR),b.off("output",eC),b.off("cwdChange",eS),ea.current&&ea.current.dispose(),ep.current=null,i.textarea?.removeEventListener("keyup",_),N.current&&N.current.dispose(),C.current&&clearTimeout(C.current),ev.cancel(),eE&&clearTimeout(eE),W&&clearTimeout(W),es&&clearTimeout(es),clearInterval(ek),w.current&&w.current.dispose(),y.current&&y.current.dispose(),x(),p(),m.dispose(),i.dispose(),g.current=null,K(!1)}},[b,s]),(0,r.useEffect)(()=>{let e=g.current,t=v.current;e&&t&&b&&s&&(D?j.current?.():k.current?.())},[D,b,s]),(0,r.useEffect)(()=>{let e=g.current,t=v.current;e&&t&&b&&s&&null!=L&&(e.options.fontSize=L,t.fit(),eb(),e.refresh(0,e.rows-1))},[L,b,s,eb]),(0,r.useEffect)(()=>{g.current&&b&&s&&(N.current&&(N.current.dispose(),N.current=null),i&&(N.current=g.current.onData(e=>{(Q.current||X.current)&&(0,ez.Nz)(e)||p()||((0,ez.b9)(e)&&m?.(s),b.emit("input",{sessionId:s,data:e}))})))},[i,b,s,m,p]),(0,r.useEffect)(()=>{if(!g.current||!b||!s||i)return;let e=g.current.onData(e=>{!p()&&(e.startsWith("\x1b[<")||e.startsWith("\x1b[M"))&&b.emit("input",{sessionId:s,data:e})});return()=>e.dispose()},[i,b,s,p]),(0,r.useEffect)(()=>{if(!a||!v.current||!g.current)return;let e=setTimeout(()=>{if(ei.current){let e=ei.current;ei.current=null,(0,Y.Lq)("reconnect",`deferred recover → fire (pane now visible, ${e})`),eo.current?.(e)}eg({force:!0}),requestAnimationFrame(()=>g.current?.refresh(0,g.current.rows-1))},100);return()=>clearTimeout(e)},[a,eg]),(0,r.useEffect)(()=>{if(!i)return;let e=window.innerWidth<760,t=setTimeout(()=>{eg(e?{force:!0}:void 0),requestAnimationFrame(()=>g.current?.refresh(0,g.current.rows-1))},100);return()=>clearTimeout(t)},[i,eg]),(0,r.useEffect)(()=>{let e=g.current;if(!e)return;let t="dark"===n?d:"none";e.options.theme=(0,ez.pt)((0,rq.In)(n,l)||rU.dark,t),e.refresh(0,e.rows-1)},[n,l,d]),function(e){let{termRef:t,termReady:s,isVisible:n,bus:l,sessionId:a,onSelectionMadeRef:i,awaitingTuiOutputRef:o,maybeFetchHistoryRef:c,userAtTopRef:d,stopMomentumRef:u}=e;(0,r.useEffect)(()=>{if(!s||!t.current)return;let e=t.current.element?.querySelector(".xterm-screen");if(!e)return;let n=0,r=0,m=0,x=null,p=0,h=0,f=ez.Il.sensitivity,b=ez.Il.lineHeight,g=ez.Il.friction,v=ez.Il.minVelocity,y=ez.Il.maxVelocity,w=ez.Il.tuiThrottleMs,j=ez.Il.momentumRenderCadenceMs,k=ez.Il.tuiBackpressureTimeoutMs,N=0,C=0,S=null,T=()=>{if(S=null,!C)return;let e=t.current;if(!e){C=0;return}let s=Math.max(1,Math.ceil(e.cols/2)),n=Math.max(1,Math.ceil(e.rows/2)),r=C>0?ez.Il.sgrDown(s,n):ez.Il.sgrUp(s,n),i=Math.min(Math.abs(C),ez.Il.wheelStepLines);for(let e=0;e<i;e++)l.emit("input",{sessionId:a,data:r});C=0,N=performance.now(),o.current=!0},E=e=>{let s=t.current;if(s)if("alternate"===s.buffer.active.type){if(o.current&&performance.now()-N<k)return;C+=e;let t=performance.now()-N;t>=w?T():S||(S=setTimeout(T,w-t))}else s.scrollLines(Math.max(-3,Math.min(3,e))),e<0&&s.buffer.active.viewportY<=ez.iW.topThresholdLines&&(d.current=!0,c.current?.())},R=()=>{x&&(cancelAnimationFrame(x),x=null),m=0},M=()=>{if(!t.current||Math.abs(m)<v){x=null;return}let e=t.current.buffer?.active?.type==="alternate",s=performance.now(),n=e&&o.current&&s-N<k,r=!e&&s-h>=j;if(!n&&(e||r)){m*=g;let e=Math.trunc((p+=m)/b);0!==e&&(E(e),p-=e*b,h=performance.now())}x=requestAnimationFrame(M)},$=null,z=!1,P=null,A=0,I=0,D=0,L=0,B=!1,F=null,O=(s,n)=>{let r=t.current,l=F||e.getBoundingClientRect(),a=l.width/r.cols,i=l.height/r.rows,o=Math.max(0,Math.min(r.cols-1,Math.floor((s-l.left)/a))),c=Math.max(0,Math.min(r.rows-1,Math.floor((n-l.top)/i)));return{col:o,row:r.buffer.active.viewportY+c}},_=s=>{R();let l=s.touches[0];n=l.clientY,A=D=l.clientX,I=L=l.clientY,r=Date.now(),m=0,p=0,z=!1,B=!1,t.current?.clearSelection(),$=setTimeout(()=>{!B&&t.current&&(z=!0,(0,eN.e)(),F=e.getBoundingClientRect(),(e=>{let{col:s,row:n}=e,r=t.current,l=r.buffer.active.getLine(n);if(!l)return;let a=l.translateToString(!1),i=e=>e&&ez.FC.wordChars.test(e);if(!i(a[s]))return r.select(s,n,1);let o=s,c=s;for(;o>0&&i(a[o-1]);)o--;for(;c<a.length-1&&i(a[c+1]);)c++;r.select(o,n,c-o+1)})(P=O(A,I)))},ez.FC.longPressMs)},K=s=>{if(!t.current)return;let l=s.touches[0];if(D=l.clientX,L=l.clientY,!B&&Math.hypot(D-A,L-I)>ez.FC.moveTolerance&&(B=!0,z||clearTimeout($)),z){s.preventDefault();var a=O(D,L);let e=t.current;if(a.row===P.row){let t=Math.min(a.col,P.col);e.select(t,a.row,Math.abs(a.col-P.col)+1)}else e.selectLines(Math.min(a.row,P.row),Math.max(a.row,P.row));return}let i=l.clientY,o=Date.now(),c=n-i,d=o-r||1,u=e.closest(".terminal-scroll.is-scrollable");if(u&&u.scrollHeight>u.clientHeight+1){let e=u.scrollHeight-u.clientHeight,t=u.scrollTop<=.5,l=u.scrollTop>=e-.5;if(!(c<0&&t||c>0&&l)){0!==c&&(s.preventDefault(),u.scrollTop=Math.max(0,Math.min(e,u.scrollTop+c))),n=i,r=o,m=0,p=0;return}}let x=c*f,h=Math.trunc((p+=x)/b);0!==h&&(s.preventDefault(),E(h),p-=h*b),m=Math.min(x/d*16,y),n=i,r=o},W=()=>{if(clearTimeout($),F=null,z){z=!1;let e=t.current?.getSelection();e&&e.trim()&&i.current?.(e,{x:D,y:L});return}Math.abs(m)>v&&(x=requestAnimationFrame(M))};u.current=R,e.addEventListener("touchstart",_,{passive:!0}),e.addEventListener("touchmove",K,{passive:!1}),e.addEventListener("touchend",W,{passive:!0});let H=e=>{let s=t.current;s&&e.deltaY<0&&s.buffer.active.viewportY<=ez.iW.topThresholdLines&&(d.current=!0,c.current?.())};return e.addEventListener("wheel",H,{passive:!0}),()=>{R(),u.current=null,clearTimeout($),e.removeEventListener("touchstart",_),e.removeEventListener("touchmove",K),e.removeEventListener("touchend",W),e.removeEventListener("wheel",H)}},[s,n,t,l,a,i,o,c,d,u])}({termRef:g,termReady:_,isVisible:a,bus:b,sessionId:s,onSelectionMadeRef:B,awaitingTuiOutputRef:F,maybeFetchHistoryRef:em,userAtTopRef:ex,stopMomentumRef:$});let ev=(0,r.useCallback)(()=>{let e=g.current;e&&b&&((0,Y.Lq)("join","manual reload (user refetch)"),T.current?.(!0),D?(k.current?.(),j.current?.()):e.refresh(0,e.rows-1))},[b,D]);return{termRef:g,cwdRef:z,cwd:A,searchAddonRef:O,termReady:_,joining:es,doResize:eg,reload:ev,focus:()=>g.current?.focus(),stopMomentum:()=>$.current?.(),historyFetching:ed}}({bus:q,sessionId:a,theme:N,terminalTheme:X,isVisible:c,isFocused:d,containerRef:T,mountDelay:m,bgKey:em?Q:"none",onInput:eu,onSelectionMade:(e,t)=>O({text:e,x:t.x,y:t.y})}),eS=(0,r.useCallback)(()=>{let e=E.current,t=ex.current;if(!e||!t)return;let s=R.current.height;if(null==s||e.clientHeight>=s-1)return;let n=t.buffer.active,r=n.baseY+n.cursorY,l=t.element?.querySelector(".xterm-screen")?.getBoundingClientRect()?.height?t.element.querySelector(".xterm-screen").getBoundingClientRect().height/t.rows:0;if(l<=0){e.scrollTop=e.scrollHeight;return}let a=e.clientHeight;if((n.baseY+t.rows)*l<=s){e.scrollTop=0;return}let i=Math.max(0,Math.min(r*l-a+2*l,e.scrollHeight-e.clientHeight));e.scrollTop=i},[ex]);(0,r.useEffect)(()=>{let e=E.current;if(!e)return;let t=0,s=()=>{if(window.innerWidth>=ez.jK){R.current={width:0,height:null},t=0,$(null),A(!1);return}let s=e.clientWidth,n=e.clientHeight;if(n<=0)return;let r=R.current;s!==r.width||null==r.height||n>=r.height-2?(R.current={width:s,height:n},$(n),t=n,A(!1)):null!=r.height&&n<r.height&&n<t-8?(t=n,A(!0),requestAnimationFrame(eS)):t=n};s();let n=new ResizeObserver(s);return n.observe(e),window.addEventListener("orientationchange",s),()=>{n.disconnect(),window.removeEventListener("orientationchange",s)}},[eS]);let eT=(0,n.jsx)(r3,{onOpenRemote:w,onOpenMobile:j});(0,r.useEffect)(()=>{if(p)return p(a,{focus:ew,doResize:eg}),()=>p(a,null)},[a,ew,eg,p]);let eE=(0,rq.In)(N,X)||rU.dark;(0,r.useEffect)(()=>{if(!ef||!ex.current||!c)return;let e=ex.current,t=()=>{let t=E.current,s=!!t?.classList.contains("is-scrollable")&&t.scrollHeight>t.clientHeight+1&&t.scrollHeight-t.clientHeight-t.scrollTop>5,n=e.buffer.active,r=n.baseY-n.viewportY>5;D(s||r)},s=null,n=()=>{s||(s=requestAnimationFrame(()=>{s=null,t()}))};t();let r=e.onScroll(n),l=()=>n();return E.current?.addEventListener("scroll",l,{passive:!0}),()=>{s&&cancelAnimationFrame(s),r.dispose(),E.current?.removeEventListener("scroll",l),D(!1)}},[ex,ef,c]);let{count:eR}=rB(s||eh,g,{enabled:c}),eM=eR>ez.KN?`${ez.KN}+`:eR,e$=r4({isFocused:d,onActivate:()=>x?.(a)}),eP=[b&&d?"terminal-focus-glow":""].filter(Boolean).join(" "),eA=`rgba(${ez.c},${V??ez._z})`,eI=`rgba(${ez.pZ},${ez.B$})`;return q?(0,n.jsxs)("div",{className:`h-full w-full flex flex-col overflow-hidden relative touch-none px-1.5 py-1.5 ${eP}${em?" terminal-has-bg":""}`,style:em?{background:`linear-gradient(${eA},${eA}), linear-gradient(${eI},${eI}), center / cover no-repeat url("${em}")`,backgroundBlendMode:"normal, screen, normal"}:{background:eE.background},onMouseDown:e$.onMouseDown,onTouchStart:e$.onTouchStart,children:[!el&&(0,n.jsxs)("div",{style:{height:26},className:"sm:hidden flex items-center gap-2 px-2 -mt-1.5 -mx-1.5 mb-1.5 flex-shrink-0 bg-surface/80 backdrop-blur-md text-[11px] select-none relative z-10",children:[(0,n.jsx)("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${np(S)}`,style:{background:nx(S).dot}}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate text-text",children:i||k("terminal.defaultName")}),eT]}),el&&(0,n.jsx)(r5,{bus:q,sessionId:a,variant:"pinned",rightSlot:eT}),(0,n.jsxs)("div",{ref:E,className:`terminal-wrapper terminal-scroll flex-1 min-h-0 relative ${z?" is-scrollable":""}`,children:[(0,n.jsx)("div",{ref:T,className:"xterm-screen w-full rounded-sm overflow-hidden",style:null!=M?{height:M,minHeight:M}:{height:"100%",minHeight:"100%"}}),(eb||!ef)&&(0,n.jsx)("div",{className:"absolute inset-0 z-40 flex items-center justify-center pointer-events-none",children:(0,n.jsx)("span",{className:"w-6 h-6 border-2 border-brand-500 border-t-transparent rounded-full animate-spin"})}),ek&&(0,n.jsx)("div",{className:"absolute top-2 left-1/2 -translate-x-1/2 z-40 pointer-events-none",children:(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-full bg-surface-2/80 backdrop-blur-sm shadow-md text-xs text-text-secondary",children:[(0,n.jsx)("span",{className:"w-3 h-3 border-2 border-brand-500 border-t-transparent rounded-full animate-spin"}),"Loading history…"]})}),F&&(0,n.jsx)(rP,{text:F.text,position:F,onOpenUrl:e=>window.open(e,"_blank"),onCopy:e=>{try{navigator.clipboard?.writeText(e)}catch{}},onAddToNote:e=>{O(null),ed(e),eo(!0)},onClose:()=>{ex.current?.clearSelection(),O(null)}})]}),I&&(0,n.jsx)("button",{onMouseDown:e=>{e.preventDefault(),e.stopPropagation()},onTouchStart:e=>{e.preventDefault(),e.stopPropagation()},onClick:e=>{let t;e.stopPropagation(),(0,eN.e)(),ej(),t=E.current,t?.classList.contains("is-scrollable")&&t.scrollHeight>t.clientHeight+1&&(t.scrollTop=t.scrollHeight),ex.current?.scrollToBottom()},className:"absolute bottom-3 right-5 z-[2] p-2 bg-surface-2 hover:bg-surface-3 text-text rounded-full shadow-md transition-all duration-150 ease-out active:scale-[0.94] touch-none",title:k("terminalPane.scrollToBottom"),children:(0,n.jsx)(ev.yQ,{size:20})}),d&&(0,n.jsxs)("div",{className:`absolute right-2 z-[2] flex flex-col items-end gap-2 pointer-events-auto touch-none ${el?"top-9":"top-9 sm:top-2"}`,children:[(0,n.jsxs)("div",{className:"flex flex-row gap-2",children:[et&&(0,n.jsx)("button",{onMouseDown:e=>{e.preventDefault(),e.stopPropagation()},onTouchStart:e=>{e.preventDefault(),e.stopPropagation()},onClick:e=>{e.stopPropagation(),(0,eN.e)(),ed(null),eo(!0)},className:r6,title:k("terminalPane.note"),children:(0,n.jsx)(ev.y8,{size:16,className:r8})}),(0,n.jsx)("button",{onMouseDown:e=>{e.preventDefault(),e.stopPropagation()},onTouchStart:e=>{e.preventDefault(),e.stopPropagation()},onClick:e=>{e.stopPropagation(),L||((0,eN.e)(),B(!0),ey(),setTimeout(()=>B(!1),700))},className:r6,title:k("terminalPane.refresh"),children:(0,n.jsx)(ev.e9,{size:16,className:`${r8} ${L?"animate-spin":""}`})})]}),ee&&(eh||s)&&(0,n.jsxs)("button",{onMouseDown:e=>{e.preventDefault(),e.stopPropagation()},onTouchStart:e=>{e.preventDefault(),e.stopPropagation()},onClick:e=>{e.stopPropagation(),(0,eN.e)(),W(s,U||s),window.innerWidth>=ez.jK?_("files",s):K()},className:`relative ${r6}`,title:k("terminalPane.openFolderHere"),children:[(0,n.jsx)(ev.vd,{size:16,className:r8}),eR>0&&(0,n.jsx)("span",{className:"absolute -top-1 -right-1 min-w-[16px] h-4 px-1 flex items-center justify-center text-[10px] font-semibold text-white bg-brand-500 rounded-full",children:eM})]}),y&&es?.length>0&&(0,n.jsxs)("button",{onMouseDown:e=>{e.preventDefault(),e.stopPropagation()},onTouchStart:e=>{e.preventDefault(),e.stopPropagation()},onClick:e=>{e.stopPropagation(),(0,eN.e)(),y(a,es[0])},className:`relative ${r6}`,title:k("terminalPane.artifacts"),children:[(0,n.jsx)(ev.sU,{size:16,className:r8}),(0,n.jsx)("span",{className:"absolute -top-1 -right-1 min-w-[16px] h-4 px-1 flex items-center justify-center text-[10px] font-semibold text-white bg-brand-500 rounded-full",children:es.length})]})]}),ei&&et&&(0,n.jsx)(r5,{bus:t,sessionId:a,appendOnOpen:ec,pinned:en,onPin:e=>er(a,e),onClose:()=>{eo(!1),ed(null)}})]}):(0,n.jsxs)("div",{className:"h-full w-full flex items-center justify-center gap-2 text-text-muted text-xs",children:[(0,n.jsx)(ev.kr,{size:13,className:"animate-spin"}),(0,n.jsx)("span",{children:k("hosts.connecting")})]})},(e,t)=>e.bus===t.bus&&e.sessionId===t.sessionId&&e.isVisible===t.isVisible&&e.isFocused===t.isFocused&&e.bgIndex===t.bgIndex&&e.connected===t.connected&&e.showFocusBorder===t.showFocusBorder&&e.sessionName===t.sessionName&&e.sessionState===t.sessionState&&e.onOpenArtifact===t.onOpenArtifact);function r7(e){let{items:t,size:s=12,label:l="",revealCls:a="",className:i="",anchor:o=null,onClose:c}=e,d=t.filter(Boolean),[u,m]=(0,r.useState)(null),x=o??u,p=null!==x,h=(0,r.useRef)(null),f=n2(h,x?.left??0,x?.top??0),b=(0,r.useCallback)(()=>{m(null),c?.()},[c]);return((0,r.useEffect)(()=>{if(!p)return;let e=e=>{"Escape"===e.key&&(e.stopPropagation(),b())};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[p,b]),d.length)?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{type:"button",onClick:e=>{if(e.stopPropagation(),(0,eN.e)(),p)return void b();let t=e.currentTarget.getBoundingClientRect();m({left:t.left,top:t.bottom+2})},className:`p-0.5 text-text-subtle hover:text-text rounded-[2px] hover:bg-surface-2 transition-colors ${a} ${i}`,title:l,"aria-label":l,"aria-haspopup":"menu",children:(0,n.jsx)(ev.a4,{size:s})}),p&&"u">typeof document&&(0,sp.createPortal)((0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"fixed inset-0 z-[69]",onPointerDown:e=>{e.stopPropagation(),b()},onClick:e=>{e.stopPropagation(),b()},onContextMenu:e=>{e.preventDefault(),e.stopPropagation(),b()}}),(0,n.jsx)("div",{ref:h,role:"menu",className:"fixed z-[70] menu-popover p-1 min-w-[160px] pop-in shadow-xl",style:{left:f.left,top:f.top},children:d.map(e=>{let{icon:t,label:s,danger:r,amber:l,onClick:a}=e;return(0,n.jsxs)("button",{type:"button",onClick:e=>{e.stopPropagation(),(0,eN.e)(),b(),a?.()},className:`w-full text-left px-2.5 py-1.5 text-xs rounded-[6px] flex items-center gap-2 transition-colors ${r?"text-red-500 hover:bg-red-500/10":l?"text-amber-500 hover:bg-amber-500/10":"text-text hover:bg-surface-2/80"}`,children:[t&&(0,n.jsx)(t,{size:13,className:"flex-shrink-0"}),(0,n.jsx)("span",{className:"truncate",children:s})]},s)})})]}),document.body)]}):null}var le=s(32763),lt=s(70658),ls=s(44964),ln=s(14757);function lr(e){let{onClose:t}=e,{t:s}=(0,eC.s)(),{authenticateWithApiKey:l,authenticateWithToken:a}=(0,lt.As)(),{saveKey:i}=(0,ls.u)(),[o,c]=(0,r.useState)(""),[d,u]=(0,r.useState)(!0),[m,x]=(0,r.useState)(!1),[f,b]=(0,r.useState)(""),[g,v]=(0,r.useState)(!1),y=(0,r.useRef)(null);(0,r.useEffect)(()=>{window.matchMedia("(pointer: fine)").matches&&requestAnimationFrame(()=>y.current?.focus())},[]),(0,r.useEffect)(()=>{let e=e=>{"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),t?.())};return window.addEventListener("keydown",e,!0),()=>window.removeEventListener("keydown",e,!0)},[t]);let w=async e=>{if(!e||m)return!1;if((0,p.PF)(e))return b(s("login.legacyKeyError")),!1;(0,eN.e)(),x(!0),b("");let n=(0,ln.k)(e),r=!!n?.tempKey;try{r&&(0,to.U)(d);let o=r?await a(n.tempKey,!0,n.tail):await l(e,{persistSession:!1});if(!o?.success)return b(o?.error&&"wrong-key-tail"!==o.error?o.error:s("login.invalidKeyTail")),!1;if(r)return(0,to.zm)(n,{remember:d,leavingHead:P.rh.getState().currentKey,navigate:!1}),t?.(),!0;let c=(0,p.Uo)(e),u=(0,p.Cj)(e);return u&&c&&(0,h.LG)(c,{tail:u}),d&&c&&(i(e,""),P.rh.getState().setAutoConnect(c,!0)),t?.(),!0}catch(e){return b(e?.message||s("login.invalidKeyTail")),!1}finally{x(!1)}};return"u"<typeof document?null:(0,sp.createPortal)((0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"modal-overlay z-[70] scrim fade-in",onClick:t,children:(0,n.jsxs)("form",{role:"dialog","aria-modal":"true","aria-label":s("hosts.addHost"),onSubmit:e=>{e?.preventDefault(),w(o.trim())},className:"card-elev w-[26rem] max-w-full overflow-hidden flex flex-col my-auto pop-in",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"px-4 pt-4 pb-3 flex items-center gap-2.5 border-b border-border-subtle flex-shrink-0",children:[(0,n.jsx)("div",{className:"p-1.5 bg-brand-500/10 dark:bg-white/10 rounded-brand flex-shrink-0",children:(0,n.jsx)(ev.kV,{className:"text-brand-500 dark:text-white w-4 h-4"})}),(0,n.jsx)("h2",{className:"flex-1 text-sm font-semibold text-text truncate",children:s("hosts.addHost")}),(0,n.jsx)("button",{type:"button",onClick:t,"aria-label":s("common.cancel"),className:"text-text-muted hover:text-text shrink-0",children:(0,n.jsx)(ev.X,{size:18})})]}),(0,n.jsxs)("div",{className:"px-4 py-4 space-y-3 flex-1 min-h-0 overflow-y-auto modal-scrollable",children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("input",{ref:y,type:"text",value:o,onChange:e=>{c(e.target.value),b("")},placeholder:s("login.placeholder"),spellCheck:!1,autoComplete:"off",className:"w-full pl-3 pr-11 py-2.5 bg-surface-2 border border-border-subtle rounded-[10px] font-mono text-sm text-text placeholder-text-subtle focus:outline-none focus:border-brand-500 focus:ring-2 focus:ring-brand-500/20 transition-all duration-150"}),(0,n.jsx)("button",{type:"button",onMouseDown:e=>e.preventDefault(),onClick:()=>{(0,eN.e)(),v(!0)},className:"absolute right-2 top-1/2 -translate-y-1/2 w-7 h-7 grid place-items-center rounded-[7px] text-text-subtle hover:bg-surface-3 hover:text-brand-500 transition-colors","aria-label":s("login.scanQr"),children:(0,n.jsx)(ev.vW,{size:16})})]}),(0,n.jsxs)("label",{className:"flex items-center gap-2 px-0.5 text-xs text-text-muted cursor-pointer select-none",children:[(0,n.jsx)("input",{type:"checkbox",checked:d,onChange:e=>u(e.target.checked),className:"w-4 h-4 accent-brand-500 cursor-pointer"}),s("login.rememberKey")]}),f&&(0,n.jsx)("p",{className:"text-xs text-red-400 px-0.5",children:f})]}),(0,n.jsxs)("div",{className:"px-4 pb-4 pt-3 flex gap-2 flex-shrink-0",children:[(0,n.jsx)("button",{type:"button",onClick:t,className:"flex-1 py-2 text-sm text-text-muted bg-surface-2 hover:bg-surface-3 rounded-brand transition-colors",children:s("common.cancel")}),(0,n.jsxs)("button",{type:"submit",disabled:!o.trim()||m,className:"flex-1 py-2 text-sm font-semibold text-white bg-brand-500 hover:bg-brand-600 rounded-brand transition-colors flex items-center justify-center gap-1.5 disabled:opacity-50 disabled:cursor-not-allowed",children:[m&&(0,n.jsx)(ev.kr,{size:14,className:"animate-spin"}),s("login.connect")]})]})]})}),g&&(0,n.jsx)("div",{className:"fixed inset-0 z-[80]",children:(0,n.jsx)(le.A,{isOpen:!0,onClose:()=>v(!1),onScan:e=>w(String(e||"").trim())})})]}),document.body)}function ll(e){let{hostKey:t=null,label:s="",connected:l=!0,collapsed:a=!1,onToggleCollapse:i=null,onRename:o=null,onDelete:c=null,onDisconnect:d=null,onAddWorkspace:u=null,meta:m=null,mutedOffline:x=!1,connecting:p=!1,onConnect:h=null,onRetry:b=null,showAdd:g=!0,hostUpdating:v=!1,onOpenRemote:y=null,onOpenMobile:w=null,mobile:j=!1,className:k=""}=e,{t:N}=(0,eC.s)(),C=(0,f.B)(e=>e.hiddenHeaderButtons),[S,T]=(0,r.useState)(null),[E,R]=(0,r.useState)(!1),[M,$]=(0,r.useState)(!1),[z,P]=(0,r.useState)(!1),[A,I]=(0,r.useState)(null),D=s||"Local";return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:`relative pr-2 ${j?"pt-3 pb-1":"py-1"} flex items-center gap-1.5 group group/host ${k}`,onContextMenu:e=>{e.preventDefault(),(0,eN.e)(),I({left:e.clientX,top:e.clientY})},children:[i?(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),(0,eN.e)(),i()},className:"text-text-subtle hover:text-text flex-shrink-0",tabIndex:-1,"aria-expanded":!a,"aria-label":D,children:(0,n.jsx)(ev.c_,{size:j?18:12,className:`transition-transform duration-150 ${a?"":"rotate-90"}`})}):(0,n.jsx)("span",{className:"flex-shrink-0 invisible","aria-hidden":"true",children:(0,n.jsx)(ev.c_,{size:j?18:12})}),(0,n.jsxs)("span",{className:"relative flex-shrink-0",children:[(0,n.jsx)(ev.VA,{size:j?16:15,className:"text-text-muted"}),(0,n.jsx)("span",{className:`absolute -bottom-0.5 -right-0.5 w-1.5 h-1.5 rounded-full ring-1 ring-surface ${p?"bg-amber-400 animate-pulse":l?"bg-green-500":x?"bg-text-subtle":"bg-red-500 animate-pulse"}`})]}),(0,n.jsx)("button",{type:"button",onClick:()=>{i&&((0,eN.e)(),i())},className:"flex-1 min-w-0 py-0.5 pr-1 text-left",children:(0,n.jsx)("span",{className:`block font-medium uppercase truncate ${j?`text-[13px] tracking-wide ${l?"text-text":"text-text-muted"}`:`text-[12px] ${l?"text-text":"text-text-muted"}`}`,"data-tip":D,children:D})}),v&&(0,n.jsx)(ev.kr,{size:j?14:12,className:"animate-spin text-brand-400 shrink-0","aria-label":N("menu.updating")}),m&&(0,n.jsx)("span",{className:"text-[10px] text-text-subtle truncate min-w-0 max-w-[45%] mr-1",children:m}),(0,n.jsxs)("div",{className:`absolute right-1 top-1/2 -translate-y-1/2 flex items-center ${j?"gap-1.5 opacity-100":"gap-1 sm:gap-1.5 px-1 rounded-[3px] bg-surface-2 opacity-0 group-hover:opacity-100 [@media(hover:none)]:opacity-100"} transition-opacity`,children:[g&&!v&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),(0,eN.e)(),P(!0)},className:"p-0.5 text-text-subtle hover:text-text rounded-[2px] transition-colors",title:N("hosts.addHost"),children:(0,n.jsx)(ev.kV,{size:13.5})}),(h||b)&&!l&&!p&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),(0,eN.e)(),(h||b)()},className:`${j?"p-1.5":"p-0.5"} text-text-subtle hover:text-text rounded-[2px] transition-colors`,title:N("common.connect"),children:(0,n.jsx)(ev.Fc,{size:j?16:13})}),u&&!v&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),(0,eN.e)(),u()},className:`${j?"p-1.5":"p-0.5"} text-text-subtle hover:text-text rounded-[2px] transition-colors`,title:N("workspaces.newWorkspace"),children:(0,n.jsx)(ev.vd,{size:j?18:13.5})}),(0,n.jsx)(r7,{size:j?18:13.5,label:N("sessions.sessionActions"),revealCls:"",anchor:A,onClose:()=>I(null),items:[o&&t&&{icon:ev.gH,label:N("sessions.editName"),onClick:()=>T(D)},u&&!v&&{icon:ev.vd,label:N("workspaces.newWorkspace"),onClick:()=>u()},{icon:ev.kV,label:N("hosts.addHost"),onClick:()=>P(!0)},y&&!C.includes("remote")&&!v&&{icon:ev.VA,label:N("menu.remoteDesktop"),onClick:()=>{I(null),(0,eN.e)(),y()}},w&&!C.includes("mobile")&&!v&&{icon:ev.wO,label:N("mobile.androidDevice"),onClick:()=>{I(null),(0,eN.e)(),w()}},c&&t&&{icon:ev.TB,label:N("hosts.removeHost"),danger:!0,onClick:()=>R(!0)},d&&{icon:ev.Mr,label:N("common.disconnect"),danger:!0,onClick:()=>{I(null),$(!0)}}]})]})]}),z&&(0,n.jsx)(lr,{onClose:()=>P(!1)}),null!==S&&(0,n.jsx)(nL,{title:N("sessions.editName"),placeholder:D,value:S,onChange:T,onSubmit:()=>{let e=S.trim();e&&t&&o?.(t,e),T(null)},onClose:()=>T(null)}),(0,n.jsx)(ek.A,{isOpen:E,onClose:()=>R(!1),onConfirm:()=>{R(!1),t&&c?.(t)},title:N("hosts.removeHost"),message:N("hosts.removeHostMessage",{name:D}),confirmText:N("common.delete")}),(0,n.jsx)(ek.A,{isOpen:M,onClose:()=>$(!1),onConfirm:()=>{$(!1),d?.()},title:N("common.disconnect"),message:N("hosts.disconnectMessage",{name:D}),confirmText:N("common.disconnect")})]})}let la="9remote_tree_collapsed",li="_root";function lo(){try{return JSON.parse(localStorage.getItem(la))||{}}catch{return{}}}function lc(e){let{name:t,size:s=20,className:r=""}=e,l=("default"===t?"D":t).trim().charAt(0).toUpperCase();return(0,n.jsx)("span",{className:`shrink-0 rounded-full flex items-center justify-center text-white font-bold ${r}`,style:{backgroundColor:function(e){let t=0;for(let s of String(e))t=(31*t+s.charCodeAt(0))%360;return`hsl(${t} 62% 45%)`}(t),width:s,height:s,fontSize:Math.max(9,Math.round(s/2))},children:l})}let ld=new WeakMap,lu={branch:null};function lm(e,t){if(e.refs<=0||e.inflight)return;let s=e.fileBus?.gitBranch?.(t);if(!s?.then)return;let n=null,r=new Promise(e=>{n=setTimeout(()=>e(null),8e3)});e.inflight=!0,Promise.race([s.catch(()=>null),r]).then(t=>{if(clearTimeout(n),e.inflight=!1,e.refs<=0)return;let s=t?.success&&t.branch||null;e.state.branch!==s&&(e.state={branch:s},e.subs.forEach(t=>t(e.state)))})}function lx(e,t){let{enabled:s=!0}=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},[n,l]=(0,r.useState)(lu),a=t||eb.getState();return(0,r.useEffect)(()=>{let t,n,r;if(!e||!a||!s)return;let i=((t=ld.get(a))||(t=new Map,ld.set(a,t)),(r=(n=t).get(e))?r.refs++:(r={state:lu,stop:null,refs:0,subs:new Set,fileBus:a,inflight:!1},n.set(e,r),r.refs++,lm(r,e),r.stop=n$(()=>lm(r,e),ez.KA)),r);return i.subs.add(l),l(e=>e===i.state?e:i.state),()=>{let t,s;i.subs.delete(l),t=ld.get(a),(s=t?.get(e))&&(s.refs--,s.refs>0||(s.stop?.(),t.delete(e)))}},[e,a,s]),n}function lp(e){let{branch:t,dirty:s,size:r=10,className:l="",iconClassName:a=""}=e;return t?(0,n.jsxs)("span",{className:`inline-flex items-center gap-0.5 min-w-0 ${l}`,title:t,children:[(0,n.jsx)(ev.Zr,{size:r,className:`flex-shrink-0 ${a||"opacity-70"}`}),(0,n.jsxs)("span",{className:"truncate",children:[t,s?"*":""]})]}):null}function lh(e){let{workspace:t,isActive:s,connected:r,collapsed:l,fileBus:a,onToggleCollapse:i,onSelect:o,onNewTerminal:c,onDelete:d,onRename:u,onAddWorkspace:m=null,statusMap:x=null,mobile:p=!1}=e,{t:h}=(0,eC.s)(),f=nS(t),{branch:b}=lx(f,a,{enabled:!!a}),{count:g}=rB(f,a,{enabled:!!a}),v=l?nf((t.items||[]).map(e=>x?.[e.id]?.state)):[],y=i?()=>{(0,eN.e)(),i()}:o;return(0,n.jsxs)("div",{onClick:y,className:`relative pr-2 flex items-center gap-1.5 group group/grp transition-colors ${p?"py-1 mt-1":"py-1.5"} ${y?"cursor-pointer hover:bg-text/[0.06]":""}`,children:[(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),(0,eN.e)(),i?.()},className:"text-text-subtle hover:text-text flex-shrink-0",tabIndex:-1,children:(0,n.jsx)(ev.c_,{size:p?18:12,className:`transition-transform duration-150 ${l?"":"rotate-90"}`})}),(0,n.jsx)(ev.vd,{size:p?14:13.5,className:"text-text-muted flex-shrink-0"}),(0,n.jsxs)("span",{className:"flex-1 min-w-0 flex flex-col",children:[(0,n.jsxs)("span",{className:`flex items-center gap-1.5 min-w-0 ${s?"text-text":"text-text-muted"}`,children:[(0,n.jsx)("span",{className:`font-medium uppercase truncate ${p?`text-[13px] tracking-wide ${s?"text-text":"text-text/90"}`:`text-[12px] ${s?"text-text":"text-text-muted"}`}`,"data-tip":t.name,children:t.name}),v.map(e=>{let{state:t,count:s}=e,r=nx(t);return(0,n.jsxs)("span",{className:"flex items-center gap-0.5 flex-shrink-0",title:`${h(r.label)}${s>1?` \xd7${s}`:""}`,children:[(0,n.jsx)("span",{className:`w-2 h-2 rounded-full term-dot ${r.cls}${r.pulse?` pulse-${r.pulse}`:""}`,style:{background:r.dot}}),s>1&&(0,n.jsx)("span",{className:"text-[10px] text-text-subtle leading-none",children:s})]},t)})]}),b&&!(0,ez.ok)(b)&&b!==t.name&&(0,n.jsx)("span",{className:"text-[10px] text-text-subtle leading-tight flex items-center gap-1 min-w-0",children:(0,n.jsx)(lp,{branch:b,dirty:g>0,className:"truncate flex-shrink-0 max-w-[7rem]"})})]}),(0,n.jsxs)("div",{className:`absolute right-1 top-1/2 -translate-y-1/2 flex items-center gap-1.5 ${p?"opacity-100":"px-1 rounded-[3px] bg-surface-2 opacity-0 group-hover:opacity-100 [@media(hover:none)]:opacity-100"} transition-opacity`,children:[c&&(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),(0,eN.e)(),c()},disabled:!r,className:`${p?"p-1.5":"p-0.5"} text-text-subtle hover:text-text rounded-[2px] transition-colors disabled:opacity-40`,title:h("terminal.newTerminal"),children:(0,n.jsx)(ev.FW,{size:p?18:13.5})}),(0,n.jsx)(r7,{size:p?18:13.5,label:h("sessions.sessionActions"),revealCls:"",items:[c&&r&&{icon:ev.FW,label:h("terminal.newTerminal"),onClick:()=>c()},m&&r&&{icon:ev.vd,label:h("workspaces.newWorkspace"),onClick:()=>m()},u&&{icon:ev.gH,label:h("workspaces.rename"),onClick:()=>u()},d&&r&&{icon:ev.TB,label:h("workspaces.delete"),danger:!0,onClick:()=>d()}]})]})]})}let lf=function(e){let t,{fileBus:s,cwd:r,basePath:l,homeDir:a,mobile:i=!1}=e,{branch:o}=lx(r,s),{count:c,perRepo:d}=rB(l||r,s,{enabled:!!r}),u=rD(d,r,c)>0,m=!!o&&!(0,ez.ok)(o),x=m?null:r&&l&&r.startsWith(`${l}/`)?r.slice(l.length+1):r&&l&&r!==l?(t=nC(r,a)).split("/").length>2?`…/${t.split("/").slice(-2).join("/")}`:t:null;return m||x?(0,n.jsxs)("span",{className:`${i?"text-xs":"text-[10px]"} text-text-subtle truncate leading-tight flex items-center gap-1.5`,children:[m&&(0,n.jsx)(lp,{branch:o,dirty:u,className:"truncate italic"}),x&&(0,n.jsx)("span",{className:"truncate opacity-70","data-tip":x,children:x})]}):null},lb=new Set(["Agent","Task","Workflow","task","browser_subagent","invoke_subagent","spawn_agent"]),lg=e=>e?.input?.subagent_type||e?.input?.agent||e?.input?.description||"agent",lv=e=>e?.input?.description||e?.input?.command||"shell";function ly(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";if(!t)return null;let s=null,n=e=>{for(let r of e||[]){if(r?.id===t)return s=r,!0;if(r?.children?.length&&n(r.children))return!0}return!1};for(let t=e.length-1;t>=0&&!s;t--)n(e[t]?.tools);return s}function lw(e){let{includeAsync:t=!1}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return(e||[]).map(e=>{let s=e.children?lw(e.children,{includeAsync:t}):null;return"running"!==e.status||e.async&&!t?s?{...e,children:s}:e:{...e,status:"done",...s?{children:s}:null}})}function lj(e,t,s){let n=!1,r=(e||[]).map(e=>{if(t(e))return n=!0,s(e);let r=lj(e.children,t,s);return r?(n=!0,{...e,children:r}):e});return n?r:null}let lk=e=>"string"==typeof e&&e.replace(/\\/g,"/").split("/").filter(Boolean).pop()||"",lN=e=>{if("string"!=typeof e)return"";let t=e.slice(-512).split("\n");for(let e=t.length-1;e>=0;e--){let s=t[e].trim();if(s)return s}return""},lC=(e,t)=>e.length>t?`${e.slice(0,t-1)}…`:e,lS=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",t=/^mcp__[^_]+(?:_[^_]+)*__(.+)$/.exec(e);return t?t[1]:e},lT=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return e.url||e.query||e.pattern||e.name||lk(e.path)||lk(e.file_path)||""};function lE(e){let t=Number(e)||0,s=t>=1e6?[1e6,"M"]:t>=1e3?[1e3,"k"]:null;if(!s)return String(t);let n=t/s[0];return`${n>=100?Math.round(n):n.toFixed(1).replace(/\.0$/,"")}${s[1]}`}let lR=new Set(["Edit","Write","MultiEdit","NotebookEdit","edit","write","patch","apply","write_to_file","replace_file_content","multi_replace_file_content","sed_file","file_change"]),lM=e=>"string"==typeof e&&e?e.split("\n").length:0;function l$(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=0,s=0;for(let n=e.length-1;n>=0;n--){let r=e[n];if("user"===r.role)break;let l=r.diffs||[];for(let e of l)for(let n of(e.patch||e.diff||"").split("\n"))n.startsWith("+")&&!n.startsWith("+++")?t++:n.startsWith("-")&&!n.startsWith("---")&&s++;let a=new Set(l.map(e=>e.file).filter(Boolean));for(let e of r.tools||[]){if(!lR.has(e?.name))continue;let n=e.input?.file_path||e.input?.path||e.input?.file||"";if(n&&a.has(n))continue;let r=function(e){let t=e.input;if(!t||"string"==typeof t)return null;let s=t.file_path||t.path||t.file||"",n=Array.isArray(t.edits)?t.edits:Array.isArray(t.replacement_chunks)?t.replacement_chunks:Array.isArray(t.replacements)?t.replacements:null;if(n){let e=0,t=0;for(let s of n)t+=lM(s.old_string??s.oldString??s.old??s.target_content),e+=lM(s.new_string??s.newString??s.new??s.replacement_content);return{file:s,added:e,removed:t}}if("string"==typeof t.content&&t.content)return{file:s,added:lM(t.content),removed:0};let r=t.old_string??t.oldString??t.old_str??t.target_content??t.TargetContent,l=t.new_string??t.newString??t.new_str??t.replacement_content??t.ReplacementContent;return void 0===r&&void 0===l?null:{file:s,added:lM(l),removed:lM(r)}}(e);r&&(t+=r.added,s+=r.removed)}}return{added:t,removed:s}}let lz=/^\s*<(task-notification|environment_context|turn_aborted|persisted-output)>/,lP=e=>lz.test(String(e||""));function lA(e){let t=String(e||"").trim();if(!t)return"";if(!t.startsWith("<persisted-output>"))return t;let s=/saved to: (\S+)/.exec(t);return s?`saved to: ${s[1]}`:""}let lI=new Set(["completed","failed","killed","stopped"]),lD=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Date.now();return e?.usage?.duration_ms>0?e.usage.duration_ms:e?.endedAt&&e?.startedAt?Math.max(0,e.endedAt-e.startedAt):e?.startedAt?Math.max(0,t-e.startedAt):0},lL=(e,t)=>t?.startedAt?null:{startedAt:Date.now()-(Number.isFinite(e)?Math.max(0,e):0)},lB=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];for(let t=e.length-1;t>=0;t--)if(e[t]?.compacting)return t;return -1},lF=new Set(["compacting"]);function lO(e,t,s,n){let r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:void 0;if("system"!==t)return e;let l=Number.isFinite(r)?r:n?.ageMs;switch(s){case"task_started":if(!n?.task_id)return e;return l_(e,n.task_id,{taskId:n.task_id,status:"running",background:!!n.is_backgrounded,...n.tool_use_id?{toolUseId:n.tool_use_id}:null,...n.description?{description:n.description}:null,...n.subagent_type?{subagentType:n.subagent_type}:null,...n.task_type?{taskType:n.task_type}:null,...lL(l,e.find(e=>e.taskId===n.task_id))});case"task_updated":{let t=e.findIndex(e=>e.taskId===n?.task_id);if(-1===t)return e;let s=n.patch||{},r=e.slice(),a=s.status&&!lI.has(s.status),i={...r[t],...s.status?{status:s.status}:null,...s.description?{description:s.description}:null,...s.end_time?{endedAt:s.end_time}:null};return a&&delete i.endedAt,a&&r[t].endedAt&&Object.assign(i,lL(l,null)),r[t]=i,r}case"task_notification":{let t=e.findIndex(e=>e.taskId===n?.task_id);if(-1===t)return e;let s=e.slice();return s[t]={...s[t],status:n.status||"completed",endedAt:s[t].endedAt||Date.now(),...n.output_file?{outputFile:n.output_file}:null,...n.summary?{summary:n.summary}:null,...n.usage?{usage:n.usage}:null},s}case"background_tasks_changed":{let t=new Set((n?.tasks||[]).map(e=>e.task_id)),s=e;for(let e of(s.some(e=>e.background&&!lI.has(e.status)&&!t.has(e.taskId))&&(s=s.map(e=>!e.background||lI.has(e.status)||t.has(e.taskId)?e:{...e,status:"stopped",endedAt:e.endedAt||Date.now()})),n?.tasks||[]))s=l_(s,e.task_id,{background:!0,status:"running",...e.description?{description:e.description}:null,...e.task_type?{taskType:e.task_type}:null,...lL(l,s.find(t=>t.taskId===e.task_id))});return s}default:return e}}function l_(e,t,s){let n=e.findIndex(e=>e.taskId===t);if(-1===n)return[...e,{taskId:t,toolUseId:"",...s}];let r={...e[n],...s};if(lK(r,e[n]))return e;let l=e.slice();return l[n]=r,l}let lK=(e,t)=>{let s=Object.keys(e);return s.length===Object.keys(t).length&&s.every(s=>e[s]===t[s])};function lW(e,t){let s=[];for(let t of e||[])t&&(s=lO(s,t.type||"system",t.subtype||"",t.record||null,t.ageMs));let n=new Map(s.map(e=>[e.taskId,e]));for(let e of t||[])e?.taskId&&n.set(e.taskId,{...n.get(e.taskId),...e});return[...n.values()]}let lH=[e=>"string"==typeof e.content?e.content:"",e=>"string"==typeof e.message?e.message:"",e=>"string"==typeof e.error?.formatted?e.error.formatted:"",e=>"string"==typeof e.error?.message?e.error.message:"",e=>e.summary||e.details?[e.summary,e.details].filter(Boolean).join(" — "):"",e=>"string"==typeof e.reason?e.reason:""],lq=new Set(["tool_progress","thinking_tokens","hook_started","hook_progress","hook_response","control_response"]),lU=new Set(["info","suggestion","warning","error"]),lX={warning:"warning",guardianWarning:"warning",configWarning:"warning",deprecationNotice:"warning",notice:"warning"};function lV(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;if(!t)return null;let n=ss(s);if(n.suppressedNotices?.has?.(e))return null;let r=n.notices,l=r&&Object.prototype.hasOwnProperty.call(r,e)?r[e]:null;if(l){let s=String(l.text?.(t)||"").trim();if(s)return{subtype:e,level:l.level||"info",content:s}}if(e.startsWith("session.next.")){if("session.next.retried"===e)return{subtype:e,level:"warning",content:`Retrying (attempt ${t.attempt??"?"}): ${t.error?.message||""}`.trim()};if("session.next.compaction.started"===e)return{subtype:e,level:"info",content:"Compacting…",compacting:!0};if("session.next.compaction.ended"===e)return{subtype:e,level:"info",content:"Compacted",compactSettled:!0};if("session.next.revert.staged"===e)return{subtype:e,level:"info",content:"Rewind staged"};if("session.next.revert.committed"===e)return{subtype:e,level:"info",content:"Rewound the conversation"};if("session.next.agent.switched"===e)return{subtype:e,level:"info",content:`Agent: ${t.agent||""}`}}if("model/rerouted"===e)return{subtype:e,level:"warning",content:`Model rerouted: ${t.fromModel} → ${t.toModel}`};if("system"===e&&("model_fallback"===t.subtype||"model_consent_fallback"===t.subtype)){let e=t.original_model&&t.fallback_model?`${t.original_model} → ${t.fallback_model}`:t.original_model||t.fallback_model||"model changed",s="string"==typeof t.content?t.content.trim():"";return{subtype:t.subtype,level:"warning",content:s?`Model fallback: ${e} — ${s}`:`Model fallback: ${e}`}}if("system"===e&&"api_retry"===t.subtype){let e=Math.round((Number(t.retry_delay_ms)||0)/1e3),s=null!=t.error_status?` ${t.error_status}`:"";return{subtype:"api_retry",level:"warning",retrying:!0,content:`API error${s} — retrying in ${e}s (attempt ${t.attempt??"?"}/${t.max_retries??"?"})`}}if("thread/compacted"===e)return{subtype:e,level:"info",content:"Compacted",compactSettled:!0};if("system"===e&&"compact_boundary"===t.subtype){let e=function(e){let t=e.compact_metadata||e.compactMetadata;if(!t||"object"!=typeof t)return null;let s=e=>Number.isFinite(e)?e:null,n=s(t.pre_tokens??t.preTokens),r=s(t.post_tokens??t.postTokens),l=null!=n&&null!=r?`${lE(n)} → ${lE(r)} tokens`:"";return{trigger:t.trigger||"auto",preTokens:n,postTokens:r,durationMs:s(t.duration_ms??t.durationMs),...l?{detail:l}:null}}(t),s="string"==typeof t.content?t.content.trim():"";return e||s?{subtype:"compact_boundary",level:t.level||"info",content:s||"Compacted",compactSettled:!0,...e?{compact:e}:null}:null}if("system"===e&&"status"===t.subtype){if(lF.has(t.status))return{subtype:"status",level:"info",content:"Compacting…",compacting:!0};if(null!=t.status&&!t.compact_result)return null;let e="failed"===t.compact_result;return{subtype:"status",level:e?"error":"info",content:e?String(t.compact_error||"").trim()||"Compaction failed":"",compactSettled:!0}}if("attachment"===e){let e=t.attachment||t,s=e.type||"";if("edited_text_file"===s)return null;if("hook_success"===s){if("SessionStart"!==e.hookEvent)return null;let t=lA(e.content);return t?{subtype:s,level:"info",content:t}:null}let n="queued_command"===s?e.prompt:"";if("string"!=typeof n||!n.trim()||lP(n))return null;let r=lA(n);return r?{subtype:s,level:"info",content:r}:null}if("system"===e){if(lP(t.content))return null;let e="string"==typeof t.content&&t.content.trim()?t.content.trim():"string"==typeof t.error?.formatted&&t.error.formatted.trim()?t.error.formatted.trim():"string"==typeof t.error?.message&&t.error.message.trim()?t.error.message.trim():"";return e?{subtype:t.subtype||"",level:t.level||"info",content:e}:null}if(lq.has(e))return null;for(let s of lH){let n=lA(s(t)).trim();if(!n||lP(n))continue;let r="error"===e&&t.willRetry?"warning":lU.has(t?.level)?t.level:Object.prototype.hasOwnProperty.call(lX,e)?lX[e]:/error|fail/i.test(e)?"error":/warn|retr/i.test(e)?"warning":"info";return{subtype:e,level:r,content:n}}return null}function lG(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments.length>1?arguments[1]:void 0;if(!t)return e||[];if(t.replaceAll)return t.todos||[];let s=e||[],n=t.taskId?String(t.taskId):"",r=t.id?String(t.id):"",l=s.findIndex(e=>n&&String(e.taskId)===n||r&&e.id&&String(e.id)===r);if("deleted"===t.status)return -1===l?s:[...s.slice(0,l),...s.slice(l+1)];if(-1===l)return t.subject?[...s,t]:s;let a=s.slice();return a[l]={...a[l],...t},a}let lJ=(0,sh.KU)(()=>window.localStorage),lY=null,lZ=lJ&&{...lJ,setItem:(e,t)=>{t!==lY&&(lY=t,lJ.setItem(e,t))}},lQ=0,l0=e=>`${e}-${Date.now()}-${++lQ}`,l1={messages:[],isTurnRunning:!1,turnStartedAt:0,lastTurnMs:0,activePermission:null,gateError:!1,activeBlocked:null,permissionMode:null,stats:{inputTokens:0,outputTokens:0,totalTurns:0,totalCost:0,reasoningTokens:0},turnBaseline:{inputTokens:0,outputTokens:0},metadata:{model:"",skills:[],mcpServers:[]},tasks:[],harnessTasks:[],queue:[]},l2=(e,t)=>({...l1,...e.bySession[t]});function l5(e,t){if(!t?.length)return null;let s=e.filter(e=>e.toolUseId&&lI.has(e.status));if(!s.length)return null;let n=t;for(let e of s){let t="failed"===e.status?"error":"done",s=n.map(s=>{if(!s.tools)return s;let n=lj(s.tools,t=>t.id===e.toolUseId&&"running"===t.status,e=>({...e,status:t}));return n?{...s,tools:n}:s});s.some((e,t)=>e!==n[t])&&(n=s)}return n===t?null:n}let l3=(e,t)=>e.status!==(t.status||"done")||Object.keys(t).some(s=>e[s]!==t[s]),l4=(0,b.v)((0,sh.Zr)((e,t)=>({bySession:{},initSession:s=>{s&&!t().bySession[s]&&e(e=>({bySession:{...e.bySession,[s]:{...l1}}}))},setTaskRecords:(t,s)=>{t&&Array.isArray(s)&&e(e=>{let n=l2(e,t),r=lW(s,[]),l=l5(r,n.messages);return r!==n.harnessTasks||l?{bySession:{...e.bySession,[t]:{...n,harnessTasks:r,...l?{messages:l}:null}}}:e})},applyTaskRecords:(t,s)=>{t&&s?.length&&e(e=>{let n=l2(e,t),r=n.harnessTasks||[],l=r;for(let[e,t,n,r]of s)l=lO(l,e,t,n,r);let a=l5(l,n.messages);return l!==r||a?{bySession:{...e.bySession,[t]:{...n,harnessTasks:l,...a?{messages:a}:null}}}:e})},addNotice:(t,s)=>{let n="string"==typeof s?.content?s.content.trim():"";!t||(n||s?.compactSettled)&&e(e=>{let r=l2(e,t);if(s?.compacting&&-1!==lB(r.messages))return e;if(s?.retrying){let s=r.messages.map(e=>e?.retrying).lastIndexOf(!0);if(-1!==s){let l=[...r.messages];return l[s]={...l[s],content:n},{bySession:{...e.bySession,[t]:{...r,messages:l}}}}}if(-1!==(s?.compactSettled?lB(r.messages):-1)){let l=r.messages.findIndex(e=>e?.compacting),a=r.messages.filter(e=>!e?.compacting);return n&&a.splice(l,0,{id:l0("n"),role:"notice",subtype:s.subtype||"",level:s.level||"info",content:n,...s.compact?{compact:s.compact}:null}),{bySession:{...e.bySession,[t]:{...r,messages:a}}}}if(!n)return e;let l={id:l0("n"),role:"notice",subtype:s.subtype||"",level:s.level||"info",content:n,...s.file?{file:s.file}:null,...s.compact?{compact:s.compact}:null,...s.compacting?{compacting:!0}:null,...s.retrying?{retrying:!0}:null},a=r.messages[r.messages.length-1],i=!a||"assistant"!==a.role||a.content||a.thinking||(a.tools||[]).length?[...r.messages,l]:[...r.messages.slice(0,-1),l];return{bySession:{...e.bySession,[t]:{...r,messages:i}}}})},setPermissionMode:(t,s)=>{e(e=>{let n=l2(e,t);return{bySession:{...e.bySession,[t]:{...n,permissionMode:s}}}})},setTurnRunning:(t,s)=>{e(e=>{let n=l2(e,t);return{bySession:{...e.bySession,[t]:{...n,isTurnRunning:s}}}})},ensureTurnLive:t=>{e(e=>{let s=l2(e,t);return s.isTurnRunning?e:{bySession:{...e.bySession,[t]:{...s,isTurnRunning:!0,turnStartedAt:Date.now(),lastTurnMs:0}}}})},setQueue:(t,s)=>{t&&e(e=>{let n=l2(e,t),r=Array.isArray(s)?s:[];return{bySession:{...e.bySession,[t]:{...n,queue:r}}}})},setMetadata:(t,s)=>{e(e=>{let n=l2(e,t);return{bySession:{...e.bySession,[t]:{...n,metadata:{...n.metadata,...s}}}}})},setStats:(t,s)=>{e(e=>{let n=l2(e,t);return{bySession:{...e.bySession,[t]:{...n,stats:{...n.stats,...s}}}}})},addUserMessage:function(t,s){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,r=arguments.length>3&&void 0!==arguments[3]&&arguments[3];e(e=>{let l=l2(e,t),a={id:l0("u"),role:"user",content:s,attachments:n||[]},i={id:l0("a"),role:"assistant",content:"",thinking:"",diffs:[],tools:[],isLive:!0};return{bySession:{...e.bySession,[t]:{...l,...r?null:{isTurnRunning:!0,turnStartedAt:Date.now(),lastTurnMs:0,turnBaseline:{inputTokens:l.stats.inputTokens||0,outputTokens:l.stats.outputTokens||0},activeBlocked:null},messages:[...l.messages,a,i]}}}})},appendDelta:(t,s)=>{e(e=>{let n=l2(e,t),r=[...n.messages],l=r[r.length-1];return l&&"assistant"===l.role&&l.isLive?r[r.length-1]={...l,content:(l.content||"")+(s||"")}:r.push({id:l0("msg"),role:"assistant",content:s||"",isLive:!0,diffs:[],tools:[]}),{bySession:{...e.bySession,[t]:{...n,messages:r}}}})},appendThinking:(t,s)=>{e(e=>{let n=l2(e,t),r=[...n.messages],l=r[r.length-1];return l&&"assistant"===l.role&&l.isLive?r[r.length-1]={...l,thinking:(l.thinking||"")+(s||"")}:r.push({id:l0("msg"),role:"assistant",content:"",thinking:s||"",isLive:!0,diffs:[],tools:[]}),{bySession:{...e.bySession,[t]:{...n,messages:r}}}})},appendStream:(t,s,n)=>{e(e=>{let r=l2(e,t),l=[...r.messages],a=l[l.length-1];return a&&"assistant"===a.role&&a.isLive?l[l.length-1]={...a,...s?{content:(a.content||"")+s}:null,...n?{thinking:(a.thinking||"")+n}:null}:l.push({id:l0("msg"),role:"assistant",content:s||"",thinking:n||"",isLive:!0,diffs:[],tools:[]}),{bySession:{...e.bySession,[t]:{...r,messages:l}}}})},appendDiff:(t,s)=>{e(e=>{let n=l2(e,t),r=[...n.messages],l=r[r.length-1];l&&"assistant"===l.role?(l={...l},r[r.length-1]=l):(l={id:l0("msg"),role:"assistant",content:"",isLive:!0,diffs:[],tools:[]},r.push(l));let a=[...l.diffs||[]],i=a.findIndex(e=>e.file===s.file);return -1!==i?a[i]=s:a.push(s),l.diffs=a,{bySession:{...e.bySession,[t]:{...n,messages:r}}}})},appendTool:(t,s)=>{e(e=>{let n=l2(e,t),r=[...n.messages],l=r[r.length-1];if(l&&"assistant"===l.role&&l.isLive&&(l.content||l.thinking||"").length>0)r[r.length-1]={...l,isLive:!1},r.push({id:l0("msg"),role:"assistant",content:"",isLive:!0,diffs:[],tools:[{...s,status:s.status||"running"}]});else if(l&&"assistant"===l.role){let e=[...l.tools||[]],t=e.findIndex(e=>e.id===s.id);-1!==t?e[t]={...e[t],...s}:e.push({...s,status:s.status||"running"}),r[r.length-1]={...l,tools:e}}else r.push({id:l0("msg"),role:"assistant",content:"",isLive:!0,diffs:[],tools:[{...s,status:s.status||"running"}]});return{bySession:{...e.bySession,[t]:{...n,messages:r}}}})},updateToolResult:(t,s)=>{e(e=>{let n=l2(e,t);for(let r=n.messages.length-1;r>=0;r--){let l=n.messages[r];if(!l?.tools)continue;let a=l.tools.findIndex(e=>e.id===s.id);if(-1===a)continue;if(!l3(l.tools[a],s))break;let i=[...l.tools];i[a]={...i[a],...s,status:s.status||"done"};let o=[...n.messages];return o[r]={...l,tools:i},{bySession:{...e.bySession,[t]:{...n,messages:o}}}}return e})},nestTool:(t,s)=>{e(e=>{let n=l2(e,t),r=[...n.messages];for(let e=r.length-1;e>=0;e--){let t=r[e],n=lj(t?.tools,e=>e.id===s.parentToolUseId,e=>{let t=[...e.children||[]],n=t.findIndex(e=>e.id===s.id);return -1!==n?t[n]={...t[n],...s}:t.push({...s,status:s.status||"running"}),{...e,children:t}});if(n){r[e]={...t,tools:n};break}}return{bySession:{...e.bySession,[t]:{...n,messages:r}}}})},nestToolResult:(t,s)=>{e(e=>{let n=l2(e,t);for(let r=n.messages.length-1;r>=0;r--){let l=n.messages[r],a=lj(l?.tools,e=>(e.children||[]).some(e=>e.id===s.id),e=>{let t=e.children.find(e=>e.id===s.id);return t&&!l3(t,s)?e:{...e,children:e.children.map(e=>e.id===s.id?{...e,...s,status:s.status||"done"}:e)}});if(!a)continue;if(a.every((e,t)=>e===l.tools[t]))break;let i=[...n.messages];return i[r]={...l,tools:a},{bySession:{...e.bySession,[t]:{...n,messages:i}}}}return e})},setPermission:(t,s)=>{e(e=>{let n=l2(e,t);return{bySession:{...e.bySession,[t]:{...n,activePermission:s,gateError:!1}}}})},clearPermission:t=>{e(e=>{let s=l2(e,t);return{bySession:{...e.bySession,[t]:{...s,activePermission:null}}}})},setBlocked:(t,s)=>{e(e=>{let n=l2(e,t);return{bySession:{...e.bySession,[t]:{...n,activeBlocked:s}}}})},clearBlocked:t=>{e(e=>{let s=l2(e,t);return{bySession:{...e.bySession,[t]:{...s,activeBlocked:null}}}})},setPromptError:function(t,s,n){let r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,l=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null,a=arguments.length>5&&void 0!==arguments[5]?arguments[5]:0;e(e=>{let i=l2(e,t),o=i.promptError,c=[...o?.attachments||[],...r||[]],d=o&&o.text!==s?`${o.text}
12
12
 
13
- ${s}`:s;return{bySession:{...e.bySession,[t]:{...i,promptError:{text:d,reason:n,attachments:c.length?c:null,promptId:o?null:l,retries:o?0:a}}}}})},setPromptSending:(t,s)=>{e(e=>{let n=l2(e,t);return{bySession:{...e.bySession,[t]:{...n,promptSending:{text:s,at:Date.now()}}}}})},clearPromptSending:(t,s)=>{e(e=>{let n=l2(e,t);if(!n.promptSending||null!=s&&n.promptSending.text!==s)return e;let{promptSending:r,...l}=n;return{bySession:{...e.bySession,[t]:l}}})},setPromptErrorText:(t,s)=>{e(e=>{let n=l2(e,t);return n.promptError?{bySession:{...e.bySession,[t]:{...n,promptError:{...n.promptError,text:s}}}}:e})},clearPromptError:t=>{e(e=>{let s=l2(e,t);if(!s.promptError)return e;let{promptError:n,...r}=s;return{bySession:{...e.bySession,[t]:r}}})},setGateError:function(t,s){let n=!(arguments.length>2)||void 0===arguments[2]||arguments[2];e(e=>{let r=l2(e,t);return r.activePermission?.requestId!==s?e:{bySession:{...e.bySession,[t]:{...r,gateError:n}}}})},finishTurn:function(t,s){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,r=arguments.length>3&&void 0!==arguments[3]&&arguments[3];e(e=>{let l=l2(e,t),a=l.messages.map((e,t)=>{let s=e.tools?lw(e.tools):null,n=!!s&&(s.length!==e.tools.length||s.some((t,s)=>t!==e.tools[s])),r=t===l.messages.length-1&&!1!==e.isLive;return n||r?{...e,...r?{isLive:!1}:null,...n?{tools:s}:null}:e});return{bySession:{...e.bySession,[t]:{...l,...r?{activePermission:null}:{isTurnRunning:!1,lastTurnMs:n||(l.turnStartedAt?Date.now()-l.turnStartedAt:l.lastTurnMs),activePermission:null,stats:s?{...l.stats,...s}:l.stats},messages:a}}}})},settleDeadTasks:t=>{t&&e(e=>{let s=l2(e,t),n=s.harnessTasks||[],r=n.some(e=>!lI.has(e.status))?n.map(e=>lI.has(e.status)?e:{...e,status:"stopped",endedAt:e.endedAt||Date.now()}):n,l=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=!1,s=e.map(e=>{if(!e.tools)return e;let s=lw(e.tools,{includeAsync:!0}),n=s.length!==e.tools.length||s.some((t,s)=>t!==e.tools[s]);return n&&(t=!0),n?{...e,tools:s}:e});return t?s:null}(s.messages);return r!==n||l?{bySession:{...e.bySession,[t]:{...s,harnessTasks:r,...l?{messages:l}:null}}}:e})},clearMessages:t=>{e(e=>{let s=l2(e,t);return{bySession:{...e.bySession,[t]:{...s,messages:[],tasks:[],turnStartedAt:0,lastTurnMs:0,activePermission:null,activeBlocked:null,stats:{inputTokens:0,outputTokens:0,totalTurns:0,totalCost:0,reasoningTokens:0},turnBaseline:{inputTokens:0,outputTokens:0}}}}})},rewindToMessage:(t,s,n)=>{e(e=>{let r=l2(e,t),l=r.messages.findIndex(e=>e.id===s);if(-1===l)return e;let a=r.messages.slice(0,l+1);return n&&(a[l]={...a[l],content:n}),{bySession:{...e.bySession,[t]:{...r,messages:a,isTurnRunning:!1,turnStartedAt:0,lastTurnMs:0,activePermission:null}}}})},upsertTask:(t,s)=>{e(e=>{let n=l2(e,t),r=lG(n.tasks,s);return r===n.tasks?e:{bySession:{...e.bySession,[t]:{...n,tasks:r}}}})},hydrateSession:(t,s)=>{let{messages:n=[],tasks:r=[],isTurnRunning:l=!1,metadata:a={},stats:i=null,permissionMode:o=null,activeBlocked:c=null,elapsedMs:d=0,lastTurnMs:u=0,harnessTasks:m=null,queue:x=null}=s;e(e=>{let s=l2(e,t),p=(m?l5(m,n):null)||n,h=l?p:p.map(e=>e.isLive?{...e,isLive:!1}:e);return{bySession:{...e.bySession,[t]:{...s,activePermission:null,messages:h,tasks:r,isTurnRunning:l,...Array.isArray(x)?{queue:x}:{},turnStartedAt:l?Date.now()-(d||0):0,lastTurnMs:l?0:u||0,turnBaseline:l?{inputTokens:0,outputTokens:0}:{inputTokens:i?.inputTokens||0,outputTokens:i?.outputTokens||0},metadata:{...s.metadata,...a},stats:i?{...s.stats,...i}:s.stats,activeBlocked:c,...o?{permissionMode:o}:{},...m?{harnessTasks:m}:{}}}}})},prependMessages:(t,s)=>{s?.length&&e(e=>{let n=l2(e,t),r=l5(n.harnessTasks||[],s)||s,l=new Set(n.messages.map(e=>e.id)),a=r.map(e=>l.has(e.id)?{...e,id:l0(e.id.split("-")[0])}:(l.add(e.id),e));return{bySession:{...e.bySession,[t]:{...n,messages:[...a,...n.messages]}}}})},restoreTurnState:function(t){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(void 0===s.isTurnRunning)return;let{isTurnRunning:n,lastTurnMs:r=0,elapsedMs:l=0}=s;(n||r)&&e(e=>{let s=l2(e,t);return{bySession:{...e.bySession,[t]:{...s,isTurnRunning:n,lastTurnMs:r,turnStartedAt:n?Date.now()-(l||0):0}}}})},removeSession:t=>{e(e=>{let{[t]:s,...n}=e.bySession;return{bySession:n}})}}),{name:"9remote-ai-store",storage:lZ,partialize:e=>({bySession:Object.fromEntries(Object.entries(e?.bySession||{}).map(e=>{let[t,s]=e;return[t,{permissionMode:s?.permissionMode??null,metadata:{model:s?.metadata?.model||"",effort:s?.metadata?.effort||""}}]}))})}));function l6(e){if(!e)return 0;let t=(e.content?.length||0)+(e.thinking?.length||0);if(Array.isArray(e.tools))for(let s of e.tools)t+=(s.command?.length||0)+(s.output?.length||0)+120;if(Array.isArray(e.diffs))for(let s of e.diffs)t+=(s.diff?.length||0)+(s.file?.length||0)+80;return Math.max(t,100)}function l8(e,t,s){let n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:2;if(!Array.isArray(e)||0===e.length)return 0;let r=Math.min(s??e.length,e.length),l=0,a=0;for(let s=r-1;s>=0&&(l+=l6(e[s]),a++,!(l>=t)||!(a>=n));s--);return r-a}async function l9(e){let{startSeq:t,fetchChunk:s,reduceChunk:n,maxChunks:r=8,pageBudget:l=131072,estimateBytes:a=()=>0}=e,i=t,o=[],c=0,d=!0,u=0,m=!1;for(;u<r;){let e=await s(i);if(u++,null==e)break;if(!e.success||!e.events?.length){d=!1;break}m=!0;let t=n(e.events,o.length);if(o=[...t,...o],c+=t.reduce((e,t)=>e+a(t),0),i=e.events[0].seq,!(d=!!e.hasMore)||c>=l)break}return{messages:o,before:i,hasMore:d,answered:m,chunks:u}}let l7=[1200,3e3,6e3];function ae(e,t){let{seq:s,epoch:n}=e,{appliedSeq:r,logEpoch:l}=t;return null!=n&&null==l?"adopt":null!=n&&null!=l&&n!==l?n>l?"resync":"stale":null==s?"apply":s<=r?"dup":null!=n&&n===l&&s>r+1?"gap":"apply"}function at(e,t){let{appliedSeq:s,logEpoch:n}=t,r=[],l=[],a=s,i=n;for(let t of e){if(l.length){l.push(t);continue}if("conversation_reset"===t.event){r.push(t),a=0,i=t.data?.epoch??(i??0)+1;continue}let e=ae(t,{appliedSeq:a,logEpoch:i});if("resync"===e)return{apply:r,held:[],resync:!0,appliedSeq:a,logEpoch:i};if("gap"===e){l.push(t);continue}"adopt"===e&&(i=t.epoch),"stale"!==e&&"dup"!==e&&(r.push(t),null!=t.seq&&(a=t.seq))}return{apply:r,held:l,resync:!1,appliedSeq:a,logEpoch:i}}let as={recover:0,gap:1,hydrate:2,now:3};function an(e){return`9remote_pendingPrompts_${e}`}function ar(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:globalThis.localStorage;if(!e||!t)return[];try{let s=JSON.parse(t.getItem(an(e))||"[]");return Array.isArray(s)?s.filter(e=>e&&"string"==typeof e.id&&"string"==typeof e.text):[]}catch{return[]}}function al(e,t,s){if(e&&s)try{t.length?s.setItem(an(e),JSON.stringify(t)):s.removeItem(an(e))}catch{}}function aa(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:globalThis.localStorage,n=ar(e,s),r=n.filter(e=>e.id!==t);r.length!==n.length&&al(e,r,s)}function ai(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:globalThis.localStorage;if(!t)return;let n=ar(e,s),r=n.filter(e=>!t.includes(e.text));r.length!==n.length&&al(e,r,s)}let ao=e=>Array.isArray(e)?e.map(e=>"string"==typeof e?{id:e,name:e,description:""}:e):[],ac=Math.random().toString(36).slice(2,10);function ad(e,t){let s=String(t||"").trim();if(!s)return!1;let n=e[e.length-1];return!!(n&&"assistant"===n.role&&String(n.content||"").trim().endsWith(s))}let au=/\u001b\[[0-9;?]*[A-Za-z]/g,am=e=>String(e||"").replace(au,"").trim(),ax=(e,t)=>{if(String(t||"").trim())return!1;let s=e[e.length-1];return!!(s&&"notice"===s.role&&"error"===s.level)},ap=e=>e?.text?`Not sent — ${e.reason||"the turn is still running"}: ${e.text}`:e?.reason||"Not sent";function ah(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"claude",s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,n=[],r=[],l=[],a={model:"",skills:[],mcpServers:[]},i={inputTokens:0,outputTokens:0,totalTurns:0,totalCost:0,reasoningTokens:0},o=!1,c=null,d=null,u=null,m=!1,x=!1,p=s;for(let s of e){let e=s?.event,h=s?.data;if(e)switch(e){case"user_message":o=!0,x=!1,d=null,n.push({id:`u-${++p}`,role:"user",content:h?.text||"",attachments:h?.attachments||[]}),n.push({id:`a-${++p}`,role:"assistant",content:"",thinking:"",diffs:[],tools:[],isLive:!0});break;case"init":{x=!1;let e=ao(h?.skills),t=e.length>0?e:a.skills,{model:s,...n}=h||{};a={...a,...n,skills:t,...s?{model:s}:{}};break}case"goal":a={...a,goal:h?.goal||null};break;case"cli_reset":break;case"delta":{let e=n[n.length-1];e&&"assistant"===e.role||(e={id:`msg-${++p}`,role:"assistant",content:"",isLive:!0,diffs:[],tools:[]},n.push(e)),e.content=(e.content||"")+(h?.text||"");break}case"thinking":{let e=n[n.length-1];e&&"assistant"===e.role||(e={id:`msg-${++p}`,role:"assistant",content:"",thinking:"",isLive:!0,diffs:[],tools:[]},n.push(e)),e.thinking=(e.thinking||"")+(h?.text||"");break}case"diff":{if(!h)break;let e=n[n.length-1];e&&"assistant"===e.role||(e={id:`msg-${++p}`,role:"assistant",content:"",isLive:!0,diffs:[],tools:[]},n.push(e));let t=e.diffs||(e.diffs=[]),s=t.findIndex(e=>e.file===h.file);-1!==s?t[s]=h:t.push(h);break}case"tool_child":if(!h)break;for(let e=n.length-1;e>=0;e--){let t=lj(n[e]?.tools,e=>e.id===h.parentToolUseId,e=>{let t=[...e.children||[]],s=t.findIndex(e=>e.id===h.id);return -1!==s?t[s]={...t[s],...h}:t.push({...h,status:h.status||"running"}),{...e,children:t}});if(t){n[e].tools=t;break}}break;case"tool_result_child":if(!h?.id)break;for(let e=n.length-1;e>=0;e--){let t=lj(n[e]?.tools,e=>(e.children||[]).some(e=>e.id===h.id),e=>({...e,children:e.children.map(e=>e.id===h.id?{...e,...h,status:h.status||"done"}:e)}));if(t){n[e].tools=t;break}}break;case"tool_start":{if(!h)break;let e=n[n.length-1];if(e&&"assistant"===e.role&&e.isLive&&(e.content||e.thinking||"").length>0)e.isLive=!1,e={id:`msg-${++p}`,role:"assistant",content:"",isLive:!0,diffs:[],tools:[{...h,status:h.status||"running"}]},n.push(e);else if(e&&"assistant"===e.role){let t=e.tools||(e.tools=[]),s=t.findIndex(e=>e.id===h.id);-1!==s?t[s]={...t[s],...h}:t.push({...h,status:h.status||"running"})}else e={id:`msg-${++p}`,role:"assistant",content:"",isLive:!0,diffs:[],tools:[{...h,status:h.status||"running"}]},n.push(e);if(h.name){let e=sr(t,h.name,h.input,h.id,r);e&&(r=lG(r,e))}break}case"tool_result":{if(!h?.id)break;for(let e=n.length-1;e>=0;e--){let t=n[e],s=t?.tools?.find(e=>e.id===h.id);if(s){Object.assign(s,h,{status:h.status||"done"});break}}let e=sl(t,h.name||"",h.output||"",h.id);e&&(r=lG(r,e));break}case"permission_request":c=h;break;case"permission_resolved":c=null;break;case"blocked":d=h;break;case"options_changed":h?.permissionMode&&(u=h.permissionMode),h?.model&&(a.model=h.model),h?.effort&&(a.effort=h.effort);break;case"turn_complete":m=!0,o=!1,c=null,h?.stats&&(i={...i,...h.stats}),n.length>0&&(n[n.length-1].isLive=!1),!h?.isError||ax(n,h.result)||ad(n,h.result)||n.push({id:`n-${++p}`,role:"notice",subtype:h.subtype||"",level:"error",content:h.result||"The turn ended in an error."});break;case"stats":h?.stats&&(i={...i,...h.stats});break;case"stopped":m=!0,o=!1,c=null;break;case"stall":for(let e of(m=!0,o=!1,c=null,n))e.isLive&&(e.isLive=!1);break;case"exit":for(let e of(m=!0,x=!0,o=!1,c=null,n))e.isLive&&(e.isLive=!1);(h?.error||h?.code!=null&&0!==h.code)&&n.push({id:`n-${++p}`,role:"notice",subtype:"exit",level:"error",content:h.error||`The AI process exited (code ${h.code}).`});break;case"error":for(let e of(m=!0,o=!1,n))e.isLive&&(e.isLive=!1);n.push({id:`n-${++p}`,role:"notice",subtype:"error",level:"error",content:h?.message||"AI process failed"});break;case"prompt_refused":n.push({id:`n-${++p}`,role:"notice",subtype:"prompt_refused",level:"error",content:ap(h)});break;case"conversation_reset":n.length=0,r.length=0,l.length=0,o=!1,x=!1,c=null,d=null;break;case"cli_event":{let e=h?.type||"",s=h?.record||null;l.push([e,h?.subtype||"",s,h?.ageMs]);let r=lV(e,s,t);if(!r)break;let{compactSettled:a,...i}=r,o=a?lB(n):-1;if(-1!==o){i.content?.trim()?n[o]={id:`n-${++p}`,role:"notice",...i}:n.splice(o,1);break}if(!i.content?.trim())break;let c=n[n.length-1];!c||"assistant"!==c.role||c.content||c.thinking||(c.tools||[]).length||n.pop(),n.push({id:`n-${++p}`,role:"notice",...i});break}case"ansi":{let e=am(h?.chunk);if(!e)break;let t=n[n.length-1];!t||"assistant"!==t.role||t.content||t.thinking||(t.tools||[]).length||n.pop(),n.push({id:`n-${++p}`,role:"notice",subtype:"ansi",level:"warning",content:e})}}}if(m||x)for(let e of n)e.tools&&(e.tools=lw(e.tools,{includeAsync:x}));let h=[];for(let[e,t,s]of l)h=lO(h,e,t,s);return x&&(h=h.map(e=>lI.has(e.status)?e:{...e,status:"stopped",endedAt:e.endedAt||Date.now()})),{messages:n,tasks:r,metadata:a,stats:i,isTurnRunning:o,activePermission:c,activeBlocked:d,permissionMode:u,harnessRecords:l,harnessTasks:h}}function af(e,t){if(!t)return!1;let s=[...l4.getState().bySession[e]?.messages||[]].reverse().find(e=>"user"===e.role);return!!s&&(s.content===t||String(t).endsWith("\n\n"+s.content))}function ab(e,t){let s=l4.getState().bySession[e]?.promptError;if(!s||!t)return;if(s.text===t)return void l4.getState().clearPromptError(e);let n=s.text.split("\n\n"),r=n.indexOf(t);if(-1===r)return;n.splice(r,1);let l=n.filter(Boolean).join("\n\n");l?l4.getState().setPromptErrorText(e,l):l4.getState().clearPromptError(e)}let ag=e=>String(e).padStart(2,"0");function av(e){let t=Math.max(0,Math.floor((Number(e)||0)/1e3)),s=Math.floor(t/3600),n=Math.floor(t%3600/60),r=t%60;return s>0?`${s}h ${ag(n)}m`:n>0?`${n}m ${ag(r)}s`:`${r}s`}let ay=(0,r.memo)(function(e){let{message:t,engine:s="claude",workspacePath:l="",onResolvePermission:a,onRewind:i,onPreviewRewind:o,onCutLocal:c,rewindIndex:d=null,canRewind:u=!1}=e,[m,x]=(0,r.useState)(!1),[p,h]=(0,r.useState)(!1),[b,g]=(0,r.useState)(""),[v,y]=(0,r.useState)(null),[w,j]=(0,r.useState)(!1),[k,N]=(0,r.useState)(null);(0,f.B)(e=>e.openEditorFile);let{id:C,role:S,content:T,thinking:E,diffs:R=[],tools:M=[],permission:$=null,isLive:z=!1,attachments:P=[]}=t;if("user"===S){let e=async e=>{j(!0),N("preview");let t=await o?.(null,{index:d});(j(!1),N(null),t?.ok)?y({files:t.files||[],text:e}):y({error:t?.error||"The host could not preview this rewind.",text:e})},t=async()=>{let e=v?.text;y(null),j(!0),N("apply"),c?.(C,e);let t=await i?.(null,e,{index:d});(j(!1),N(null),t&&!t.ok)?y({error:t.error||"The rewind did not go through.",text:e}):h(!1)},s=(0,n.jsx)(ek.A,{isOpen:!!v,onClose:()=>y(null),onConfirm:v?.error?()=>y(null):t,title:v?.error?"Cannot rewind":"Rewind to this prompt?",message:v?.error?v.error:["This discards every turn after this prompt and re-sends your edited text.",v?.files?.length?`These ${v.files.length} file${1===v.files.length?"":"s"} go back to how they were:`:"No file changes to restore — this rewinds the conversation only.",...v?.files?.slice(0,8).map(e=>`\xb7 ${e.file}${e.status?` (${e.status})`:""}`)||[],v?.files?.length>8?`… and ${v.files.length-8} more`:"","Edits made by hand, or by shell commands, are NOT restored."].filter(Boolean).join("\n"),confirmText:v?.error?"OK":"Rewind"});if(p)return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"flex justify-end my-3",children:(0,n.jsxs)("div",{className:"max-w-[85%] sm:max-w-[75%] w-full",children:[(0,n.jsx)("textarea",{value:b,onChange:e=>g(e.target.value),onBlur:()=>{w||v||h(!1)},onKeyDown:t=>{if("Enter"===t.key&&!t.shiftKey){if(t.nativeEvent.isComposing||229===t.keyCode||(t.preventDefault(),w||v))return;b.trim()&&e(b.trim())}"Escape"===t.key&&h(!1)},rows:Math.min(10,b.split("\n").length+1),className:"w-full resize-none overflow-hidden rounded-brand-lg bg-surface-2 px-4 py-2.5 text-sm text-text focus:outline-none focus:ring-1 focus:ring-brand-500 leading-relaxed",autoFocus:!0}),(0,n.jsxs)("div",{className:"flex justify-end items-center gap-1.5 mt-1.5 text-[11px] text-text-muted",children:[w&&(0,n.jsx)(ev.kr,{size:11,className:"animate-spin"}),(0,n.jsx)("span",{children:"apply"===k?"Rewinding...":"preview"===k?"Checking what this would change...":"Enter to rewind, Esc to cancel"})]})]})}),s]});let r=u&&!!i,l=()=>{(0,eN.e)(),g(T||""),h(!0)};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"group/msg flex flex-col items-end my-3 list-rise",children:[(0,n.jsxs)("div",{className:"max-w-[92%] @2xl:max-w-[768px] flex flex-col items-end gap-1.5",children:[P.length>0&&(0,n.jsx)("div",{className:"flex flex-wrap justify-end gap-1.5",children:P.map((e,t)=>(0,n.jsxs)("span",{className:`inline-flex items-center gap-1 rounded-full border px-2 py-0.5 text-[11px] ${e.isImage?"border-brand-500/40 bg-brand-500/10 text-brand-500":"border-border-subtle bg-surface-2 text-text-muted"}`,children:[e.isImage?(0,n.jsx)(ev._V,{size:10}):(0,n.jsx)(ev.xv,{size:10}),(0,n.jsx)("span",{className:"max-w-[160px] truncate",children:e.filename})]},`${e.filename}-${t}`))}),T&&(0,n.jsx)("div",{onClick:r?e=>{let t=window.getSelection();t&&!t.isCollapsed&&t.containsNode(e.currentTarget,!0)||l()}:void 0,className:`px-3.5 py-2 rounded-[16px] rounded-tr-[4px] bg-[var(--chat-bubble-mine)] text-[var(--chat-meta-on-mine)] text-sm whitespace-pre-wrap wrap-anywhere shadow-[0_1px_2px_rgba(0,0,0,0.08)] ${r?"cursor-pointer":""}`,children:T})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1 mt-1",children:[(0,n.jsx)("button",{type:"button",onClick:()=>{(0,eN.e)(),T&&(navigator.clipboard.writeText(T),x(!0),setTimeout(()=>x(!1),2e3))},className:"px-1.5 py-0.5 rounded text-[11px] text-text-muted hover:text-text hover:bg-surface-2 flex items-center gap-1 transition-colors",title:"Copy this prompt",children:m?(0,n.jsx)(ev.aJ,{size:11,className:"text-success"}):(0,n.jsx)(ev.QR,{size:11})}),r&&(0,n.jsx)("button",{type:"button",disabled:w,onClick:l,className:"px-1.5 py-0.5 rounded text-[11px] text-text-muted hover:text-text hover:bg-surface-2 flex items-center gap-1 transition-colors disabled:opacity-40",title:"Edit & rewind to here",children:w&&"preview"===k?(0,n.jsx)(ev.kr,{size:11,className:"animate-spin"}):(0,n.jsx)(ev.gH,{size:11})})]})]}),s]})}return null},(e,t)=>e.message===t.message&&e.onResolvePermission===t.onResolvePermission&&e.rewindIndex===t.rewindIndex||!e.message.isLive&&!t.message.isLive&&e.message.id===t.message.id&&e.message.content===t.message.content&&e.message.thinking===t.message.thinking&&e.message.permission===t.message.permission&&e.message.tools===t.message.tools&&e.message.diffs===t.message.diffs&&e.canRewind===t.canRewind&&e.rewindIndex===t.rewindIndex&&e.onResolvePermission===t.onResolvePermission);function aw(e,t){if("string"!=typeof e||!e)return{dir:"",name:""};let s=e.replace(/\\/g,"/"),n=t?t.replace(/\\/g,"/").replace(/\/+$/,""):"",r=!!n&&s.startsWith(`${n}/`),l=r?5:4,a=(r?s.slice(n.length+1):s).split("/").filter(Boolean);a.length>l&&(a=["…",...a.slice(-l)]);let i=a.pop()||"";return{dir:a.join("/"),name:i}}let aj=(0,r.memo)(function(e){let{images:t=[],index:s=0,onClose:l,fileBus:a=null}=e,[i,o]=(0,r.useState)(s),[c,d]=(0,r.useState)(null),[u,m]=(0,r.useState)(!1),[x,p]=(0,r.useState)(1),[h,f]=(0,r.useState)({x:0,y:0}),b=(0,r.useRef)(null),g=(0,r.useRef)(null),v=(0,r.useRef)(null),y=(0,r.useRef)(null),w=t[i]||null;(0,r.useEffect)(()=>{if(d(null),m(!1),p(1),f({x:0,y:0}),!w?.path||!a?.readMedia)return;let e=!0;return a.readMedia(w.path).then(t=>{e&&(t?.success&&t.dataUrl?d(t.dataUrl):m(!0))}).catch(()=>{e&&m(!0)}),()=>{e=!1}},[w?.path,a]);let j=(0,r.useCallback)(e=>{o(s=>{let n=s+e;return n<0||n>=t.length?s:n})},[t.length]),k=(0,r.useCallback)((e,t)=>{let s=y.current;if(!s||t<=1)return{x:0,y:0};let n=s.clientWidth*(t-1)/2,r=s.clientHeight*(t-1)/2;return{x:Math.max(-n,Math.min(n,e.x)),y:Math.max(-r,Math.min(r,e.y))}},[]),N=(0,r.useCallback)(e=>{let t=Math.min(4,Math.max(1,e));p(t),1===t?f({x:0,y:0}):f(e=>k(e,t))},[k]);(0,r.useEffect)(()=>{let e=e=>{"Escape"===e.key?(e.preventDefault(),e.stopPropagation(),l?.()):"ArrowLeft"===e.key?(e.preventDefault(),j(-1)):"ArrowRight"===e.key?(e.preventDefault(),j(1)):"0"===e.key&&(p(1),f({x:0,y:0}))};return window.addEventListener("keydown",e,!0),()=>window.removeEventListener("keydown",e,!0)},[l,j]);let C=e=>{let t=b.current;if(!t)return;if(t.pointers.size>1){t.pointers.delete(e.pointerId),t.pinch0=null;return}if(t.pointers.delete(e.pointerId),t.pointers.size>0)return;b.current=null;let s=t.movedX||0,n=g.current?.clientWidth||window.innerWidth;1===x&&Math.abs(s)>60&&Math.abs(s)>.18*n&&j(s<0?1:-1),1===x&&f({x:0,y:0}),!t.swiped&&t.startedOnBackdrop&&l?.()};return"u"<typeof document||!w?null:(0,sp.createPortal)((0,n.jsx)("div",{ref:g,className:"scrim-lightbox fixed inset-0 z-[9999] flex items-center justify-center select-none",onPointerDown:e=>{let t=b.current;if(t){t.pointers.set(e.pointerId,{x:e.clientX,y:e.clientY}),t.pinch0=null,t.swiped=!0;return}b.current={id:e.pointerId,x:e.clientX,y:e.clientY,movedX:0,zoom0:x,pan0:h,pinch0:null,startedOnBackdrop:e.target===g.current,pointers:new Map([[e.pointerId,{x:e.clientX,y:e.clientY}]])}},onPointerMove:e=>{let t=b.current;if(!t)return;if(t.pointers.set(e.pointerId,{x:e.clientX,y:e.clientY}),2===t.pointers.size){let[e,s]=[...t.pointers.values()],n=Math.hypot(e.x-s.x,e.y-s.y);if(!t.pinch0){t.pinch0=n,t.zoom0=x;return}N(t.zoom0*(n/t.pinch0)),t.swiped=!0;return}let s=e.clientX-t.x,n=e.clientY-t.y;if(x>1){f(k({x:t.pan0.x+s,y:t.pan0.y+n},x)),t.swiped=!0;return}t.movedX=s,Math.abs(s)>8&&(t.swiped=!0),f({x:s,y:0})},onPointerUp:C,onPointerCancel:C,onWheel:e=>{(e.ctrlKey||e.metaKey)&&(e.preventDefault(),N(x-.002*e.deltaY))},onClick:e=>{e.target===g.current&&l?.()},children:(0,n.jsxs)("div",{ref:v,className:"lightbox-panel relative z-10 flex max-h-[min(88vh,calc(var(--app-height,100vh)-2rem))] w-[min(94vw,1100px)] flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex shrink-0 items-center gap-2 px-2.5 py-2",children:[(0,n.jsx)("span",{className:"min-w-0 truncate font-mono text-[11.5px] text-white/75",children:w.name}),t.length>1&&(0,n.jsxs)("span",{className:"shrink-0 rounded-full bg-white/10 px-2 py-0.5 font-mono text-[10.5px] text-white/60 tabular-nums",children:[i+1," / ",t.length]}),(0,n.jsx)("span",{className:"flex-1"}),(0,n.jsx)("button",{type:"button",onClick:l,className:"shrink-0 rounded-full p-1.5 text-white/60 transition-colors hover:bg-white/15 hover:text-white",title:"Close",children:(0,n.jsx)(ev.X,{size:16})})]}),(0,n.jsxs)("div",{className:"relative min-h-0 flex-1",children:[t.length>1&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{type:"button",onClick:()=>j(-1),disabled:0===i,className:"lightbox-arrow absolute left-2 top-1/2 z-10 -translate-y-1/2 rounded-full p-2 text-white/70 transition-colors hover:text-white disabled:opacity-20",title:"Previous",children:(0,n.jsx)(ev.JG,{size:18})}),(0,n.jsx)("button",{type:"button",onClick:()=>j(1),disabled:i===t.length-1,className:"lightbox-arrow absolute right-2 top-1/2 z-10 -translate-y-1/2 rounded-full p-2 text-white/70 transition-colors hover:text-white disabled:opacity-20",title:"Next",children:(0,n.jsx)(ev.c_,{size:18})})]}),c?(0,n.jsx)("img",{ref:y,src:c,alt:w.name,draggable:!1,className:"lightbox-image mx-auto block max-h-full max-w-full object-contain",style:{transform:`translate(${h.x}px, ${h.y}px) scale(${x})`,transition:b.current?"none":"transform 160ms ease-out",touchAction:"none"}}):u?(0,n.jsx)("span",{className:"flex h-full items-center justify-center font-mono text-xs text-white/55",children:"This image is no longer on the host."}):(0,n.jsx)("span",{className:"flex h-full items-center justify-center",children:(0,n.jsx)(ev.kr,{size:22,className:"animate-spin text-white/60"})})]})]})}),document.body)}),ak=/\.(png|jpe?g|gif|webp|avif|bmp|svg)$/i,aN=(0,r.memo)(function(e){let{img:t,fileBus:s=null,images:l=null,index:a=0}=e,[i,o]=(0,r.useState)(null),[c,d]=(0,r.useState)(!1),[u,m]=(0,r.useState)(!1);return((0,r.useEffect)(()=>{if(!t?.path||!s?.readMedia)return;let e=!0;return s.readMedia(t.path,{maxDim:320}).then(t=>{e&&(t?.success&&t.dataUrl?o(t.dataUrl):d(!0))}).catch(()=>{e&&d(!0)}),()=>{e=!1}},[t?.path,s]),!t?.path||c)?null:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{type:"button",onClick:()=>m(!0),className:"h-10 w-14 shrink-0 overflow-hidden rounded-brand border border-border-subtle/60 bg-surface-2/60 transition-opacity hover:opacity-90",title:`${t.name} — open in viewer`,children:i?(0,n.jsx)("img",{src:i,alt:t.name,className:"h-full w-full object-cover",draggable:!1}):(0,n.jsx)("span",{className:"block h-full w-full animate-pulse bg-surface-3/40"})}),u&&(0,n.jsx)(aj,{images:l||[t],index:l?a:0,fileBus:s,onClose:()=>m(!1)})]})}),aC={file:ev.kU};function aS(e){let{path:t,fileBus:s,onOpen:l}=e,[a,i]=(0,r.useState)(null);return((0,r.useEffect)(()=>{if(!t||!s?.readMedia)return;let e=!0;return s.readMedia(t).then(t=>{e&&t?.success&&t.dataUrl&&i(t.dataUrl)}).catch(()=>{}),()=>{e=!1}},[t,s]),a)?(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),(0,eN.e)(),l()},className:"shrink-0 overflow-hidden rounded border border-border-subtle/60 hover:border-border-subtle transition-colors",title:"View full size",children:(0,n.jsx)("img",{src:a,alt:"",className:"h-7 w-10 object-cover",draggable:!1})}):null}let aT=(0,r.memo)(function e(t){let{id:s="",name:l="tool",command:a="",input:i=null,output:o="",error:c="",status:d="done",children:u=[],engine:m="claude",workspacePath:x="",fileBus:p=null}=t,h="running"===d,b=!!(c||"error"===d),[g,v]=(0,r.useState)(!1),[y,w]=(0,r.useState)(!1),j=(0,f.B)(e=>e.openEditorFile),k=!!a||"string"!=typeof i&&!!i?.command,N="string"==typeof i?"":i?.file_path||i?.notebook_path||i?.path||i?.file||"",C=a||N||("string"==typeof i?i:i?.command||i?.pattern||i?.query||""),S=!k&&N&&C===N?function(e,t){let{dir:s,name:n}=aw(e,t);return s?`${s}/${n}`:n}(C,x):C,T="string"==typeof i?i:i&&Object.keys(i).length?JSON.stringify(i,null,2):"",E=i?.file_path||i?.path||i?.file||"",R=ak.test(E),[M,$]=(0,r.useState)(!1),z=aC[sn(m,l)]||ev.Jl;return(0,n.jsxs)("div",{className:"my-1 text-xs",children:[(0,n.jsxs)("div",{onClick:()=>v(!g),className:"flex items-center justify-between py-1 px-0 hover:bg-surface-2/40 cursor-pointer data-pane-control select-none transition-colors group/tool",children:[(0,n.jsxs)("div",{className:"flex items-start gap-2 min-w-0 flex-1",children:[(0,n.jsx)("span",{className:"shrink-0 mt-0.5",children:h?(0,n.jsx)(ev.kr,{size:13,className:"animate-spin text-accent"}):b?(0,n.jsx)(ev.RI,{size:13,className:"text-danger"}):(0,n.jsx)(z,{size:13,className:"text-success"})}),(0,n.jsxs)("div",{className:"min-w-0 flex-1 font-mono text-[11px] leading-relaxed line-clamp-2",children:[(0,n.jsx)("span",{className:"text-[10px] font-semibold text-text uppercase tracking-wider break-all px-1 py-0.5 rounded bg-surface-2/80 [box-decoration-break:clone]",title:l,children:l}),S&&(0,n.jsxs)(n.Fragment,{children:[" ",(0,n.jsx)("span",{className:"text-text-muted break-all",title:S,children:S})]})]}),(0,n.jsx)("span",{className:"text-text-muted/50 shrink-0 self-center",children:g?(0,n.jsx)(ev.yQ,{size:11}):(0,n.jsx)(ev.c_,{size:11})})]}),(0,n.jsxs)("div",{className:`flex items-center gap-1 shrink-0 ml-2 ${R?"":"opacity-0 group-hover/tool:opacity-100"}`,children:[R&&!h&&!b&&p&&(0,n.jsx)(aS,{path:E,fileBus:p,onOpen:()=>$(!0)}),E&&(0,n.jsx)("button",{type:"button",onClick:e=>{if(e.stopPropagation(),(0,eN.e)(),E){if(R)return void $(!0);j(E)}},className:"p-0.5 text-text-muted hover:text-text rounded hover:bg-surface-3 transition-colors flex items-center gap-1",title:R?"View image":"Open file in editor",children:(0,n.jsx)(ev.Gr,{size:11})}),(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),(0,eN.e)();let t=o||c||S;t&&(navigator.clipboard.writeText("string"==typeof t?t:JSON.stringify(t,null,2)),w(!0),setTimeout(()=>w(!1),2e3))},className:"p-0.5 text-text-muted hover:text-text rounded hover:bg-surface-3 transition-colors opacity-0 group-hover/tool:opacity-100",title:"Copy output",children:y?(0,n.jsx)(ev.aJ,{size:11,className:"text-success"}):(0,n.jsx)(ev.QR,{size:11})})]})]}),g&&(0,n.jsxs)("div",{className:"mt-1 ml-3.5 pl-3 border-l-2 border-border-subtle/80 bg-surface-2/20 rounded-r-brand p-2 overflow-x-auto max-h-[260px] overflow-y-auto font-mono text-[11px] select-text",children:[T&&(0,n.jsx)("div",{className:"text-text-muted whitespace-pre-wrap break-all leading-relaxed mb-1.5",children:T}),c&&(0,n.jsx)("div",{className:"text-danger mb-1.5 whitespace-pre-wrap wrap-anywhere",children:c}),o?(0,n.jsx)("div",{className:"text-text whitespace-pre-wrap wrap-anywhere leading-relaxed",children:"string"==typeof o?o:JSON.stringify(o,null,2)}):c?null:(0,n.jsx)("div",{className:"text-text-muted italic",children:"Running or no output returned..."})]}),g&&u.length>0&&(0,n.jsx)("div",{className:"ml-3.5 pl-3 border-l-2 border-border-subtle/80",children:u.map(t=>(0,n.jsx)(e,{...t,engine:m,workspacePath:x,fileBus:p},t.id))}),M&&(0,n.jsx)(aj,{images:[{path:E,name:E.split(/[/\\]/).pop()||E}],index:0,fileBus:p,onClose:()=>$(!1)})]})}),aE=new Set(["TaskCreate","TaskUpdate","TodoWrite","todowrite"]),aR=e=>!!ss(e).questionGate,aM=new Set(["Edit","Write","MultiEdit","NotebookEdit","file_change","edit","write","write_to_file","replace_file_content"]),a$=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return e.file_path||e.notebook_path||e.path||e.filePath||e.file||""},az=/\.(png|jpe?g|gif|webp|avif|bmp|svg)$/i,aP=["file_path","notebook_path","path","file"],aA=e=>"thought"===e.kind||"tool"===e.kind||"diff"===e.kind;function aI(e){let{total:t,windowSize:s=3,children:l}=e,[a,i]=(0,r.useState)(0),o=function(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,n=e-Math.max(0,s);return n>t+1?n-t:0}(t,s,a);return(0,n.jsxs)(n.Fragment,{children:[a>0?(0,n.jsx)("button",{type:"button",onClick:()=>i(e=>e-Math.min(12,Math.max(0,e))),className:"py-0.5 text-left font-mono text-[10.5px] text-text-subtle hover:text-text",children:"▼ show less"}):o>0?(0,n.jsxs)("button",{type:"button",onClick:()=>i(e=>e+Math.min(12,Math.max(0,o))),className:"py-0.5 text-left font-mono text-[10.5px] text-text-subtle hover:text-text",children:["▲ ",o," more ",1===o?"step":"steps"]}):null,l(o)]})}function aD(){let[e,t]=(0,r.useState)(!1);return(0,r.useEffect)(()=>{let e=window.matchMedia("(hover: none), (pointer: coarse)"),s=()=>t(e.matches);return s(),e.addEventListener("change",s),()=>e.removeEventListener("change",s)},[]),e}let aL=(0,r.memo)(function(e){let{file:t="",patch:s="",diff:l="",content:a="",workspacePath:i=""}=e,[o,c]=(0,r.useState)(!1),d=(0,f.B)(e=>e.openEditorFile),u=aD(),m=s||l||(s||l||!a?"":String(a).split("\n").map(e=>`+${e}`).join("\n")),x=m?m.split("\n"):[],p=aw(t,i),h=x.filter(e=>e.startsWith("+")&&!e.startsWith("+++")).length,b=x.filter(e=>e.startsWith("-")&&!e.startsWith("---")).length;return(0,n.jsxs)("div",{className:"my-1 text-xs",children:[(0,n.jsxs)("div",{onClick:()=>c(!o),className:"flex items-center justify-between py-1 px-0 hover:bg-surface-2/40 cursor-pointer data-pane-control select-none transition-colors group/tool",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,n.jsx)(ev.GD,{size:13,className:"text-success shrink-0"}),(0,n.jsx)("span",{className:"min-w-0 font-mono font-medium text-text text-[11px] break-all",title:t,children:p.dir?`${p.dir}/${p.name}`:p.name||"diff"}),(h>0||b>0)&&(0,n.jsxs)("span",{className:"flex items-center gap-1 font-mono text-[10px] shrink-0 text-text-muted",children:[h>0&&(0,n.jsxs)("span",{className:"text-success",children:["+",h]}),b>0&&(0,n.jsxs)("span",{className:"text-danger",children:["-",b]})]}),(0,n.jsx)("span",{className:"text-text-muted/50 shrink-0",children:o?(0,n.jsx)(ev.yQ,{size:11}):(0,n.jsx)(ev.c_,{size:11})})]}),(0,n.jsx)("div",{className:`flex items-center gap-1 shrink-0 ml-2 transition-opacity ${u?"opacity-100":"opacity-0 group-hover/tool:opacity-100"}`,children:t&&(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),(0,eN.e)(),t&&d(t)},className:"p-0.5 text-text-muted hover:text-text rounded hover:bg-surface-3 transition-colors flex items-center gap-1 text-[10px]",title:"Open file in editor",children:(0,n.jsx)(ev.Gr,{size:11})})})]}),o&&(0,n.jsx)("div",{className:"mt-1 ml-3.5 pl-3 border-l-2 border-border-subtle/80 bg-surface-2/20 rounded-r-brand p-2 overflow-x-auto max-h-[300px] overflow-y-auto font-mono text-[11px] leading-relaxed select-text",children:0===x.length?(0,n.jsx)("div",{className:"text-text-muted italic py-1 px-2",children:"No changes"}):x.map((e,t)=>{let s=e.startsWith("+")&&!e.startsWith("+++"),r=e.startsWith("-")&&!e.startsWith("---"),l=e.startsWith("@@"),a="text-text",i="";return s?(a="text-success",i="bg-success/10"):r?(a="text-danger",i="bg-danger/10"):l&&(a="text-text-muted",i="bg-surface-2/40"),(0,n.jsx)("div",{className:`px-2 py-0.5 rounded-sm whitespace-pre ${a} ${i}`,children:e},t)})})]})}),aB=/"((?:[^"\\]|\\.)*)"\s*=\s*"((?:[^"\\]|\\.)*)"/g,aF=e=>e.replace(/\\(.)/g,"$1"),aO=e=>[...e.matchAll(aB)].map(e=>[aF(e[1]),aF(e[2])]),a_=(0,r.createContext)({sessionId:"",isFocused:!0,activate:null}),aK=()=>(0,r.useContext)(a_),aW=(e,t,s)=>s?`ai-${e}-${t}-${s}`:void 0,aH=(0,r.memo)(function(e){let{requestId:t="",questions:s=[],answers:l=null,declined:a=!1,failed:i=!1,onResolve:o,engine:c=""}=e,{isFocused:d,activate:u}=aK(),[m,x]=(0,r.useState)({}),[p,h]=(0,r.useState)({}),[f,b]=(0,r.useState)(!1),[g,v]=(0,r.useState)(!1),[y,w]=(0,r.useState)(0),j=(0,r.useRef)(l);(0,r.useEffect)(()=>{j.current=l});let k=(0,r.useRef)(a);(0,r.useEffect)(()=>{k.current=a});let N=(0,r.useRef)(f);(0,r.useEffect)(()=>{N.current=f}),(0,r.useEffect)(()=>{i&&(N.current=!1,b(!1))},[i]);let C=s[Math.min(y,s.length-1)],S=y>=s.length-1,T=!!m[C?.question]||g,E=(0,r.useCallback)(()=>{j.current||k.current||N.current||s.every(e=>!!m[e.question])&&((0,eN.e)(),N.current=!0,b(!0),o?.(t,"allow","",m))},[s,m,t,o]),R=(0,r.useCallback)(()=>{N.current||k.current||!T||((0,eN.e)(),S?E():w(e=>e+1))},[T,S,E]),M=(0,r.useCallback)(()=>{0!==y&&((0,eN.e)(),w(e=>e-1))},[y]),$=(0,r.useCallback)(()=>{N.current||k.current||j.current||((0,eN.e)(),N.current=!0,b(!0),o?.(t,su,sm))},[t,o]),z=(0,r.useCallback)((e,t,s)=>{if(!N.current){if((0,eN.e)(),!s){x(s=>({...s,[e]:t})),h(t=>t[e]?{...t,[e]:""}:t),S||w(e=>e+1);return}x(s=>{let n=s[e]?s[e].split(", "):[],r=n.indexOf(t);return r>-1?n.splice(r,1):n.push(t),{...s,[e]:n.join(", ")}})}},[S]),P=(0,r.useCallback)(()=>{d||u?.()},[d,u]);(0,r.useEffect)(()=>{if(!d||f||l||a||!C)return;let e=e=>{if(e.target?.tagName==="INPUT"||e.target?.tagName==="TEXTAREA")return;if("Enter"===e.key){e.preventDefault(),R();return}let t=parseInt(e.key,10);if(t>=1&&t<=9&&C.options?.[t-1]){let e=C.options[t-1];z(C.question,e.label,C.multiSelect)}};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[C,f,l,a,R,z,d]);let A=l?"string"==typeof l?function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],s=String(e||"");if(!t.length){let e=aO(s);return e.length?Object.fromEntries(e):null}let n={},r=0;for(let[e,l]of t.entries()){let a=s.indexOf(`"${l}"=`,r);if(-1===a)continue;let i=a+l.length+3,o=t[e+1]?s.indexOf(`"${t[e+1]}"=`,i):-1,c=s.slice(i,-1===o?void 0:o),d=c.lastIndexOf('"');d<=0||(n[l]=aF(c.slice(1,d)),r=i+d)}if(Object.keys(n).length)return n;let l=aO(s);return l.length?Object.fromEntries(l):null}(l,s.map(e=>e.question)):l:null;if(a)return(0,n.jsxs)("div",{className:"my-2 p-3 rounded-brand-lg bg-surface text-[14px] flex flex-col gap-1",children:[(0,n.jsx)("span",{className:"text-text-muted font-medium",children:"Skipped"}),C&&(0,n.jsx)("span",{className:"text-text-muted/70 leading-snug",children:C.question}),!!ss(c).headlessQuestions&&(0,n.jsx)("span",{className:"text-[12px] text-text-muted/60 leading-snug",children:"Headless Antigravity cannot wait for an answer — open it in a terminal (new terminal → Antigravity) to answer questions interactively."})]});if(l)return(0,n.jsxs)("div",{className:"my-2 p-3 rounded-brand-lg border border-success/30 bg-success/10 text-[14px] font-medium flex flex-col gap-1.5",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 text-success",children:[(0,n.jsx)(ev.aJ,{size:14}),(0,n.jsx)("span",{children:"Answered"})]}),s.map((e,t)=>{let s=A?.[e.question];return s?(0,n.jsxs)("div",{className:"flex flex-col gap-0.5",children:[(0,n.jsx)("span",{className:"text-[12px] font-normal text-text-muted leading-snug",children:e.question}),(0,n.jsx)("span",{className:"font-mono text-text pl-2 border-l-2 border-success/40 wrap-anywhere",children:s})]},t):null}),!A&&(0,n.jsx)("span",{className:"font-mono text-text wrap-anywhere",children:String(l)})]});if(!C||!o)return null;let I=m[C.question]||"",D=C.multiSelect&&I?I.split(", "):[I];return(0,n.jsxs)("div",{onPointerDown:P,className:"my-2 p-3 rounded-brand-lg shadow-sm text-[14px] select-none border border-warning/30 bg-warning/[0.06]",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 mb-2 text-warning font-medium",children:[(0,n.jsx)(ev.mN,{size:16,className:"text-warning shrink-0"}),(0,n.jsx)("span",{children:"Question"}),s.length>1&&(0,n.jsxs)("span",{className:"font-mono text-[12px] px-1.5 py-0.5 rounded bg-surface-2 text-text-muted",children:[y+1,"/",s.length]}),C.multiSelect&&(0,n.jsx)("span",{className:"font-mono text-[12px] px-1.5 py-0.5 rounded bg-surface-2 text-text-muted uppercase",children:"multi"})]}),(0,n.jsx)("div",{className:"text-text leading-snug mb-1.5",children:C.question}),C.options?.length>0&&(0,n.jsx)("div",{className:"flex flex-col",children:C.options.map((e,t)=>{let s=D.includes(e.label);return(0,n.jsxs)("button",{type:"button",onClick:()=>z(C.question,e.label,C.multiSelect),className:`px-1.5 py-1 rounded text-left flex items-start gap-2 transition-colors text-[13px] ${s?"bg-brand-500/12":"text-text-muted hover:bg-surface-2 hover:text-text"}`,children:[(0,n.jsx)("span",{className:"font-mono text-[12px] text-text-muted/70 shrink-0 mt-0.5 w-2.5",children:t+1}),(0,n.jsxs)("span",{className:"flex flex-col gap-0.5 min-w-0 flex-1",children:[(0,n.jsx)("span",{className:`font-medium ${s?"text-brand-400":"text-text"}`,children:e.label}),e.description&&(0,n.jsx)("span",{className:"text-[12px] text-text-muted/70 leading-snug",children:e.description})]}),s&&(0,n.jsx)(ev.aJ,{size:12,className:"text-brand-500 shrink-0 mt-0.5"})]},t)})}),(0,n.jsx)("input",{type:"text",value:p[C.question]||"",disabled:f,onFocus:()=>v(!0),onChange:e=>{var t,s;return t=C.question,s=e.target.value,void(h(e=>({...e,[t]:s})),x(e=>({...e,[t]:s})))},onKeyDown:e=>{"Enter"!==e.key||e.nativeEvent?.isComposing||229===e.keyCode||(e.preventDefault(),R())},placeholder:"Type your answer...",className:`w-full px-1.5 py-1 rounded bg-bg border border-border-subtle text-[13px] text-text placeholder-text-muted/70 focus:outline-none focus:border-brand-500 disabled:opacity-40 ${C.options?.length?"mt-1.5":"mt-1"}`}),i&&(0,n.jsx)("div",{className:"mt-1.5 text-[13px] text-danger leading-snug",children:"Not sent — the host did not answer. Try again."}),(0,n.jsxs)("div",{className:"mt-2 flex items-center gap-1.5 justify-end",children:[(0,n.jsx)("button",{type:"button",onClick:$,disabled:f,className:"px-2 py-1 rounded text-[13px] text-text-muted hover:text-text hover:bg-surface-2 transition-colors disabled:opacity-40 disabled:cursor-not-allowed",children:"Skip"}),y>0&&(0,n.jsxs)("button",{type:"button",onClick:M,className:"px-2 py-1 rounded text-[13px] text-text-muted hover:text-text hover:bg-surface-2 transition-colors flex items-center gap-0.5",children:[(0,n.jsx)(ev.JG,{size:13}),(0,n.jsx)("span",{children:"Back"})]}),(0,n.jsxs)("button",{type:"button",onClick:R,disabled:f||!T,className:"px-2.5 py-1 rounded bg-brand-500 hover:bg-brand-600 text-white flex items-center gap-1 text-[13px] font-medium transition-colors disabled:opacity-40 disabled:cursor-not-allowed",children:[(0,n.jsx)("span",{children:S?f?"Sending…":"Submit":"Next"}),S?(0,n.jsx)(ev.Lt,{size:11}):(0,n.jsx)(ev.c_,{size:12})]})]})]})}),aq=(0,r.memo)(function(e){let{text:t="",isLive:s=!1,defaultOpen:l=!1}=e,[a,i]=(0,r.useState)(l);return t?.trim()?(0,n.jsxs)("div",{className:"my-1.5 text-xs select-none",children:[(0,n.jsxs)("button",{type:"button",onClick:()=>i(e=>!e),className:"inline-flex items-center gap-1.5 text-[11px] text-text-muted hover:text-text py-0.5 transition-colors cursor-pointer group",children:[(0,n.jsx)(ev.sU,{size:12,className:s?"animate-pulse text-success":"text-success"}),(0,n.jsx)("span",{className:"italic",children:s?"Thinking...":"Thought process"}),(0,n.jsx)("span",{className:"text-text-muted/50 group-hover:text-text-muted",children:a?(0,n.jsx)(ev.yQ,{size:12}):(0,n.jsx)(ev.c_,{size:12})})]}),a&&(0,n.jsx)("div",{className:"mt-1 pl-3.5 border-l-2 border-border-subtle/80 font-mono text-[11px] text-text-muted leading-relaxed whitespace-pre-wrap max-h-[260px] overflow-y-auto custom-scrollbar select-text py-1",children:t})]}):null}),aU=/Command running in background with ID:\s*([^\s.]+)/,aX=(0,r.memo)(function(e){let t,{id:s="",name:l="Bash",input:a=null,output:i="",error:o="",status:c="done",defaultExpanded:d=!1}=e,{sessionId:u}=aK(),m=!!(o||"error"===c),[x,p]=(0,r.useState)(d),[h,f]=(0,r.useState)(!1),[b,g]=(0,r.useState)(!1),v=a?.command||"",y=a?.description||"",w=o||i||"",j="string"==typeof w?w:w?JSON.stringify(w,null,2):"",k=(t=aU.exec("string"==typeof i?i:""))?t[1]:"",N=!!(a?.run_in_background||k);return(0,n.jsxs)("div",{className:"my-1 text-xs",id:aW(u,"shell",s),children:[(0,n.jsxs)("div",{onClick:()=>p(!x),className:"flex items-start justify-between py-1 px-0 hover:bg-surface-2/40 cursor-pointer data-pane-control select-none transition-colors group/tool",children:[(0,n.jsxs)("div",{className:"flex items-start gap-2 min-w-0 flex-1",children:[(0,n.jsx)("span",{className:"shrink-0 mt-0.5",children:"running"===c?(0,n.jsx)(ev.kr,{size:13,className:"animate-spin text-accent"}):m?(0,n.jsx)(ev.RI,{size:13,className:"text-danger"}):(0,n.jsx)(ev.Jl,{size:13,className:"text-success"})}),(0,n.jsx)("span",{className:`min-w-0 flex-1 text-[11px] leading-relaxed break-words ${y?"text-text":"font-mono text-text wrap-anywhere"}`,title:y||v,children:y||function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";if(!e)return"";let t=e.split(/\n/)[0].replace(/\s*<<-?\s*['"]?[A-Za-z_][A-Za-z0-9_]*['"]?.*$/," <<…");if((t=(t=t.replace(/\s*2?>\s*\/dev\/null/g,"").replace(/\s+/g," ").trim()).replace(/(['"])((?:\\.|(?!\1).){24,})\1/g,(e,t,s)=>s.length<=18?`${t}${s}${t}`:`${t}${s.slice(0,18)}…${t}`)).length>72){let e=t.slice(0,72),s=e.lastIndexOf(" ");t=`${(s>24?e.slice(0,s):e).trimEnd()}…`}return t}(v)||l}),N&&(0,n.jsxs)("span",{className:"font-mono text-[10px] font-semibold text-warning shrink-0 px-1 py-0.5 rounded bg-warning/10",title:k?`Background shell ${k}`:"Running in the background",children:["BG",k?` ${k}`:""]}),j&&(0,n.jsx)("span",{className:"text-text-muted/50 shrink-0",children:x?(0,n.jsx)(ev.yQ,{size:11}):(0,n.jsx)(ev.c_,{size:11})})]}),(0,n.jsx)("div",{className:"flex items-center gap-1 shrink-0 ml-2 opacity-0 group-hover/tool:opacity-100 transition-opacity",children:v&&(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),(0,eN.e)(),navigator.clipboard.writeText(v),f(!0),setTimeout(()=>f(!1),2e3)},className:"p-0.5 text-text-muted hover:text-text rounded hover:bg-surface-3 transition-colors text-[10px] flex items-center gap-0.5",title:"Copy command",children:h?(0,n.jsx)(ev.aJ,{size:11,className:"text-success"}):(0,n.jsx)(ev.QR,{size:11})})})]}),x&&(j||v)&&(0,n.jsxs)("div",{className:"mt-1 ml-3.5 pl-3 border-l-2 border-border-subtle/80 bg-surface-2/20 rounded-r-brand overflow-x-auto max-h-[260px] overflow-y-auto font-mono text-[11px] select-text relative group/out",children:[v&&(0,n.jsxs)("pre",{className:"p-2 pb-1 whitespace-pre-wrap wrap-anywhere leading-relaxed text-text-muted",children:[(0,n.jsx)("span",{className:"select-none opacity-60",children:"$ "}),v]}),j&&(0,n.jsx)("pre",{className:`p-2 whitespace-pre-wrap wrap-anywhere leading-relaxed ${m?"text-danger":"text-text"} ${v?"pt-0":""}`,children:j}),(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),(0,eN.e)(),navigator.clipboard.writeText(j),g(!0),setTimeout(()=>g(!1),2e3)},className:"absolute top-1.5 right-1.5 p-1 rounded bg-surface-3/80 hover:bg-surface-3 text-text-muted hover:text-text opacity-0 group-hover/out:opacity-100 transition-opacity text-[10px]",title:"Copy output",children:b?(0,n.jsx)(ev.aJ,{size:10,className:"text-success"}):(0,n.jsx)(ev.QR,{size:10})})]})]})});function aV(e){let t=String(e||"").split("\n")[0].trim();return t.length>140?`${t.slice(0,140)}…`:t}let aG=(0,r.memo)(function(e){let{id:t="",name:s="Agent",input:l=null,output:a="",error:i="",status:o="done",children:c=[],engine:d="claude",workspacePath:u="",defaultExpanded:m=!1}=e,{sessionId:x}=aK(),p="running"===o,h=!!(i||"error"===o),f=c.filter(e=>"running"===e.status).length,[b,g]=(0,r.useState)(h||m);(0,r.useEffect)(()=>{h&&g(!0)},[h]);let v=lb.has(s),y=v?lg({input:l}):s||"agent",w=v?aV(l?.prompt??l?.description??l?.message):aV(l?.message??l?.prompt??l?.query);return(0,n.jsxs)("div",{className:"my-1 text-xs",id:aW(x,"agent",t),children:[(0,n.jsxs)("div",{onClick:()=>g(!b),className:"flex items-center justify-between py-1 px-0 hover:bg-surface-2/40 cursor-pointer data-pane-control select-none transition-colors group/tool",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[(0,n.jsx)("span",{className:"shrink-0",children:p?(0,n.jsx)(ev.kr,{size:13,className:"animate-spin text-accent"}):h?(0,n.jsx)(ev.RI,{size:13,className:"text-danger"}):(0,n.jsx)(ev.Jl,{size:13,className:"text-success"})}),(0,n.jsx)("span",{className:"font-mono text-[10px] font-semibold text-text uppercase tracking-wider shrink-0 px-1 py-0.5 rounded bg-surface-2/80",children:"AGENT"}),(0,n.jsx)("span",{className:"font-mono text-[11px] font-semibold text-brand-500 shrink-0",children:y}),w&&(0,n.jsx)("span",{className:"text-[11px] text-text-muted truncate min-w-0",title:w,children:w})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2 shrink-0 ml-2",children:[c.length>0&&(0,n.jsxs)("span",{className:"font-mono text-[10px] text-text-subtle",title:`${c.length} sub-agent tool calls`,children:[p&&f>0?`${f}/${c.length}`:c.length," tools"]}),(0,n.jsx)("span",{className:"text-text-muted/50",children:b?(0,n.jsx)(ev.yQ,{size:11}):(0,n.jsx)(ev.c_,{size:11})})]})]}),b&&(0,n.jsxs)("div",{className:"mt-1 ml-3.5 pl-3 border-l-2 border-border-subtle/80 py-1 space-y-0.5",children:[c.length>0?(0,n.jsx)(aI,{total:c.length,children:e=>(e>0?c.slice(e):c).map(e=>a0(d,e,{workspacePath:u})||(0,n.jsx)(aT,{...e,engine:d,workspacePath:u},e.id))}):(0,n.jsx)("div",{className:"text-text-muted italic py-0.5",children:p?"Sub-agent started…":"No tool calls reported."}),!p&&(a||i)&&(0,n.jsx)("div",{className:"mt-1 pl-3 border-l-2 border-border-subtle/60 font-mono text-[11px] max-h-[240px] overflow-y-auto select-text",children:(0,n.jsx)("div",{className:`whitespace-pre-wrap wrap-anywhere leading-relaxed ${h?"text-danger":"text-text-muted"}`,children:"string"==typeof(i||a)?i||a:JSON.stringify(i||a,null,2)})})]})]})}),aJ=(0,r.memo)(function(e){let{toolName:t="EnterPlanMode",input:s={}}=e,r="string"==typeof s?.plan?s.plan.trim():"";if(r)return(0,n.jsx)(aY,{plan:r,explanation:s?.explanation||""});let l="EnterPlanMode"===t,a=s?.reason||(l?"Exploring codebase and designing implementation approach":"Implementation plan finalized");return(0,n.jsxs)("div",{className:`p-3.5 rounded-brand-lg border flex flex-col gap-2 my-2 text-xs ${l?"bg-brand-500/10 border-brand-500/30 text-text":"bg-success/10 border-success/30 text-success"}`,children:[(0,n.jsxs)("div",{className:"flex items-center justify-between font-semibold",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[l?(0,n.jsx)(ev.y8,{size:16,className:"text-brand-500"}):(0,n.jsx)(ev.Jl,{size:16,className:"text-success"}),(0,n.jsx)("span",{children:l?"Plan Mode Activated":"Plan Mode Completed"})]}),(0,n.jsx)("span",{className:"font-mono text-[10px] px-2 py-0.5 rounded bg-surface-2 text-text-muted",children:t})]}),(0,n.jsxs)("div",{className:"text-xs text-text leading-relaxed font-sans pl-6",children:[(0,n.jsx)("span",{className:"text-text-muted",children:"Reason: "}),a]}),l&&(0,n.jsx)("div",{className:"text-[11px] text-text-muted/80 italic pl-6 select-none",children:"Plan mode reads files and drafts an approach — nothing is applied without your review, in whichever CLI this chat is running."})]})}),aY=(0,r.memo)(function(e){let{plan:t,explanation:s=""}=e;return(0,n.jsxs)("div",{className:"p-3.5 rounded-brand-lg border border-brand-500/30 bg-brand-500/10 text-text my-2 text-xs flex flex-col gap-2",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 font-semibold",children:[(0,n.jsx)(ev.y8,{size:16,className:"text-brand-500"}),(0,n.jsx)("span",{children:"Plan"})]}),(0,n.jsx)("pre",{className:"font-mono text-[11px] leading-relaxed whitespace-pre-wrap wrap-anywhere pl-6 max-h-[320px] overflow-y-auto",children:t}),s&&(0,n.jsx)("div",{className:"text-[11px] text-text-muted pl-6 italic",children:s})]})}),aZ=(0,r.memo)(function(e){let{toolName:t="enteredReviewMode",input:s={}}=e,r="enteredReviewMode"===t,l=String(s?.review||"").trim();return(0,n.jsxs)("div",{className:`p-3.5 rounded-brand-lg border flex flex-col gap-2 my-2 text-xs ${r?"bg-brand-500/10 border-brand-500/30 text-text":"bg-success/10 border-success/30 text-success"}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 font-semibold",children:[r?(0,n.jsx)(ev.kU,{size:16,className:"text-brand-500"}):(0,n.jsx)(ev.Jl,{size:16,className:"text-success"}),(0,n.jsx)("span",{children:r?"Code review started":"Code review finished"})]}),l&&(0,n.jsxs)("div",{className:"text-xs text-text leading-relaxed font-sans pl-6",children:[(0,n.jsx)("span",{className:"text-text-muted",children:"Reviewing: "}),l]})]})}),aQ={bash:(e,t,s)=>(0,n.jsx)(aX,{...e,deferred:t,defaultExpanded:s?.defaultExpanded},e.id),agent:(e,t,s)=>{let{engine:r,workspacePath:l,defaultExpanded:a}=s;return(0,n.jsx)(aG,{...e,engine:r,workspacePath:l,defaultExpanded:a},e.id)},plan:e=>(0,n.jsx)(aJ,{toolName:e.name,input:e.input},e.id),review:e=>(0,n.jsx)(aZ,{toolName:e.name,input:e.input},e.id),question:(e,t,s)=>{if("running"===e.status||!e.output&&!e.error)return null;let r=!!ss(s?.engine).headlessQuestions&&/user skipped/i.test(String(e.output||""));return(0,n.jsx)(aH,{engine:s?.engine,questions:e.input?.questions||[],answers:r||e.error?null:e.output||"",declined:r||!!e.error||"error"===e.status},e.id)}};function a0(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=aQ[sn(e,t.name)];return n?n(t,s.deferred,{...s,engine:e}):null}var a1=s(7601),a2=s(46118);function a5(e,t){let s=window.__TAURI__?.opener;s?.openUrl&&(e.preventDefault(),s.openUrl(t).catch(()=>{}))}let a3=(e,t)=>function(s){let{children:r,className:l,node:a,...i}=s;return(0,n.jsx)(e,{className:l?`${t} ${l}`:t,...i,children:r})},a4={h1:a3("h1","text-xl sm:text-2xl font-bold border-b border-border-subtle pb-2 mt-5 mb-3 text-text first:mt-0"),h2:a3("h2","text-lg sm:text-xl font-bold border-b border-border-subtle pb-1.5 mt-4 mb-2.5 text-text first:mt-0"),h3:a3("h3","text-base sm:text-lg font-semibold mt-3.5 mb-2 text-text"),h4:a3("h4","text-sm sm:text-base font-semibold mt-3 mb-1.5 text-text"),h5:a3("h5","text-xs sm:text-sm font-semibold mt-2.5 mb-1 text-text"),h6:a3("h6","text-xs font-semibold mt-2 mb-1 text-text-muted"),p:a3("p","my-2 leading-relaxed text-text text-sm"),ul:a3("ul","list-disc pl-5 my-2 space-y-1 text-sm text-text"),ol:a3("ol","list-decimal pl-5 my-2 space-y-1 text-sm text-text"),li:a3("li","leading-relaxed"),blockquote:a3("blockquote","border-l-4 border-brand-500/40 pl-3.5 my-2.5 text-text-muted italic text-sm"),th:a3("th","border border-border-subtle bg-surface-2 px-3 py-1.5 font-semibold text-left text-text align-top wrap-anywhere min-w-[80px]"),td:a3("td","border border-border-subtle px-3 py-1.5 text-text align-top wrap-anywhere min-w-[80px]"),hr:a3("hr","border-t border-border-subtle my-4"),img:e=>{let{alt:t="",node:s,...r}=e;return(0,n.jsx)("img",{className:"max-w-full h-auto rounded my-2",alt:t,...r})},a:e=>{let{children:t,className:s,href:r,node:l,...a}=e;return(0,n.jsx)("a",{className:`text-brand-500 hover:underline wrap-anywhere${s?` ${s}`:""}`,target:"_blank",rel:"noopener noreferrer",onClick:e=>a5(e,r),...a,children:t})},table:e=>{let{children:t,node:s,...r}=e;return(0,n.jsx)("div",{className:"my-3 overflow-x-auto custom-scrollbar",children:(0,n.jsx)("table",{className:"w-full table-auto border-collapse border border-border-subtle text-xs",...r,children:t})})},pre:function(e){let{children:t,node:s,...l}=e,[a,i]=(0,r.useState)(!1),o=(0,r.useRef)(null);return(0,n.jsxs)("div",{className:"relative group/code my-2.5",children:[(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),(0,eN.e)();let t=o.current?.innerText||"";try{navigator.clipboard.writeText(t)}catch{}i(!0),setTimeout(()=>i(!1),2e3)},className:"absolute top-2 right-2 p-1 rounded bg-surface-3/80 hover:bg-surface-3 text-text-muted hover:text-text opacity-100 sm:opacity-0 sm:group-hover/code:opacity-100 transition-opacity z-10",title:"Copy code",children:a?(0,n.jsx)(ev.aJ,{size:13,className:"text-brand-500"}):(0,n.jsx)(ev.QR,{size:13})}),(0,n.jsx)("pre",{ref:o,className:"p-3 rounded bg-surface-2 whitespace-pre-wrap break-words text-[12px] font-mono border border-border-subtle text-text [&_code]:bg-transparent [&_code]:p-0 [&_code]:border-0 [&_code]:text-text",...l,children:t})]})},code:e=>{let{children:t,className:s,node:r,...l}=e,a=/language-/.test(s||"");return(0,n.jsx)("code",{className:`${a?"font-mono text-[12px] text-text":"font-mono text-[0.9em] text-accent wrap-anywhere"}${s?` ${s}`:""}`,...l,children:t})},input:e=>{let{type:t,checked:s,node:r,...l}=e;return"checkbox"===t?(0,n.jsx)("input",{type:"checkbox",checked:s,readOnly:!0,className:"mr-2 rounded accent-brand-500 cursor-default",...l}):(0,n.jsx)("input",{type:t,...l})}},a6=(0,r.memo)(function(e){let{content:t,components:s}=e;return(0,n.jsx)(a1.oz,{remarkPlugins:[a2.A],components:s?{...a4,...s}:a4,children:t})},(e,t)=>e.content===t.content);function a8(e){let{row:t,engine:s,workspacePath:r,deferred:l}=e;if("thought"===t.kind)return(0,n.jsx)(aq,{text:t.text,isLive:t.isLive});if("diff"===t.kind){let e=t.diff;return(0,n.jsx)(aL,{file:e.file,patch:e.patch,diff:e.diff,content:e.content,workspacePath:r})}let a=t.tool;return a0(s,a,{workspacePath:r,deferred:l})||(0,n.jsx)(aT,{...a,engine:s,workspacePath:r,deferred:l})}let a9={info:"text-text-muted",suggestion:"text-text-muted",warning:"text-warning",error:"text-danger"};function a7(e){let{notice:t}=e;if(!t?.content)return null;let s=`text-xs leading-relaxed py-1 px-2 my-0.5 rounded border-l-2 border-current/30 bg-surface-2/40 wrap-anywhere ${a9[t.level]||a9.info}`;return t.compacting?(0,n.jsxs)("div",{className:`${s} flex items-center gap-2`,children:[(0,n.jsx)(ev.kr,{size:12,className:"animate-spin text-brand-500 shrink-0"}),(0,n.jsx)("span",{children:t.content}),(0,n.jsx)(it,{})]}):(0,n.jsxs)("div",{className:s,children:[t.content,t.compact?.detail&&(0,n.jsxs)("span",{className:"text-text-muted",children:[" \xb7 ",t.compact.detail]}),t.compact?.durationMs?(0,n.jsxs)("span",{className:"text-text-muted",children:[" \xb7 ",ie(t.compact.durationMs)]}):null]})}function ie(e){let t=e/1e3;return t<60?`${t.toFixed(1)}s`:`${Math.floor(t/60)}m ${Math.round(t%60)}s`}function it(){let[e]=(0,r.useState)(()=>Date.now()),[t,s]=(0,r.useState)(e);return(0,r.useEffect)(()=>{let e=setInterval(()=>s(Date.now()),1e3);return()=>clearInterval(e)},[]),(0,n.jsx)("span",{className:"text-text-muted/70 tabular-nums",children:ie(t-e)})}function is(e){let{content:t,isLive:s,images:l=[],fileBus:a=null}=e,i=function(e,t){let[s,n]=(0,r.useState)(e),l=(0,r.useRef)(e);return(0,r.useEffect)(()=>{l.current=e},[e]),(0,r.useEffect)(()=>{if(!t)return;let e=setInterval(()=>{n(e=>e===l.current?e:l.current)},80);return()=>clearInterval(e)},[t]),t?s:e}(t,s);return(0,n.jsx)("div",{className:"flex justify-start mb-3 mt-1",children:(0,n.jsxs)("div",{className:"max-w-[94%] @2xl:max-w-[768px] min-w-0 px-3.5 py-2 rounded-[16px] rounded-tl-[4px] bg-[var(--chat-bubble-theirs)] shadow-[0_1px_2px_rgba(0,0,0,0.08)] text-sm leading-relaxed text-[var(--chat-bubble-theirs-text)] wrap-anywhere",children:[(0,n.jsx)(a6,{content:i}),s&&(0,n.jsx)("span",{className:"inline-block w-1.5 h-3.5 bg-brand-500 animate-pulse ml-1 align-middle"}),l.length>0&&(0,n.jsx)("div",{className:"mt-2 flex flex-wrap gap-1",children:l.map((e,t)=>(0,n.jsx)(aN,{img:e,fileBus:a,images:l,index:t},`${e.path}-${t}`))})]})})}let ir=(0,r.memo)(function(e){let{messages:t=[],engine:s="claude",workspacePath:l="",onResolvePermission:a,isLive:i=!0,fileBus:o=null,showImages:c=!0}=e,d=(0,r.useMemo)(()=>(function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"claude",s=[],n=new Set;for(let r of e){if("notice"===r.role){s.push({kind:"notice",id:r.id,notice:{subtype:r.subtype,level:r.level,content:r.content,...r.compact?{compact:r.compact}:null,...r.compacting?{compacting:!0}:null}});continue}if("assistant"!==r.role)continue;r.thinking?.trim()&&s.push({kind:"thought",id:`${r.id}-th`,text:r.thinking});let e=function(e,t,s){return(t||[]).filter(t=>!(!t||!t.name||(s||[]).some(e=>{let s;return e.file&&(s=e.file,aM.has(t?.name)&&s&&((t.input?.paths||[]).includes(s)||a$(t.input)===s))})||"task"===sn(e,t.name)&&aE.has(t.name)))}(t,r.tools,r.diffs);for(let l=0;l<e.length;l++){let a=e[l];if("question"===sn(t,a.name)&&"running"===a.status&&aR(t))continue;let i=a.id||`${r.id}-t${l}`;n.has(i)||(n.add(i),s.push({kind:"tool",id:i,tool:a,engine:t}))}for(let e=0;e<(r.diffs?.length||0);e++){let t=r.diffs[e];s.push({kind:"diff",id:`${r.id}-d${e}`,diff:t})}r.content&&s.push({kind:"prose",id:`${r.id}-p`,content:r.content,isLive:r.isLive}),r.permission&&s.push({kind:"permission",id:`${r.id}-perm`,permission:r.permission})}return s})(t,s),[t,s]),u=(0,r.useMemo)(()=>(function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:6,{deferred:s=!1}=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=[];for(let t of e)if(aA(t)){let e=n[n.length-1];e?.type==="steps"?e.rows.push(t):n.push({type:"steps",rows:[t]})}else n.push({type:"row",row:t});return n.map((e,n)=>{if("steps"!==e.type)return{...e,key:`r${n}`,deferred:s};let r=e.rows.length>t+1?e.rows.length-t:0;return{type:"steps",key:`s${n}`,rows:e.rows,hidden:r,deferred:s}})})(d,3,{deferred:!i}),[d,i]),m=(0,r.useMemo)(()=>(function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=[],s=new Set,n=e=>{let r=e?.input,l="string"==typeof r?"":aP.map(e=>r?.[e]).find(e=>"string"==typeof e&&e);for(let r of(l&&az.test(l)&&!s.has(l)&&(s.add(l),t.push({path:l,name:String(l).split(/[/\\]/).pop()||l,toolName:e?.name})),e?.children||[]))n(r)};for(let t of e)"tool"===t.kind&&n(t.tool);return t})(d),[d]),x=(0,r.useMemo)(()=>{for(let e=d.length-1;e>=0;e--)if("prose"===d[e].kind)return d[e].id;return null},[d]);return(0,n.jsx)("div",{className:"my-1",children:u.map(e=>{if("steps"!==e.type){if("prose"===e.row.kind){let t=e.row.id===x;return(0,n.jsx)(is,{content:e.row.content,isLive:e.row.isLive,images:t&&c?m:[],fileBus:t&&c?o:null},e.key)}if("notice"===e.row.kind)return(0,n.jsx)(a7,{notice:e.row.notice},e.key);if("permission"===e.row.kind){let t=e.row.permission;return(0,n.jsx)(aH,{requestId:t.requestId,questions:t.input?.questions||[],onResolve:a},e.key)}return null}return(0,n.jsx)("div",{className:"relative pl-2.5 border-l-2 border-border-subtle/50 my-1",children:(0,n.jsx)(aI,{total:e.rows.length,children:t=>(t>0?e.rows.slice(t):e.rows).map(e=>(0,n.jsx)(a8,{row:e,engine:s,workspacePath:l,deferred:!i},e.id))})},e.key)})})},(e,t)=>{if(e.messages.length!==t.messages.length)return!1;for(let s=0;s<e.messages.length;s++)if(e.messages[s]!==t.messages[s])return!1;return e.engine===t.engine&&e.workspacePath===t.workspacePath&&e.isLive===t.isLive&&e.showImages===t.showImages&&e.onResolvePermission===t.onResolvePermission});function il(e){let{background:t=!1,engine:s="claude",size:r=16,className:l=""}=e;if(t)return(0,n.jsx)(ev.BK,{size:r,className:l||"text-text"});let a=tu(s);return a?(0,n.jsx)("img",{src:a,alt:s,draggable:!1,style:{width:r,height:r},className:`flex-shrink-0 object-contain ${td} ${l}`}):(0,n.jsx)(ev.cC,{size:r,className:l||"text-text"})}let ia=(0,r.memo)(function(e){let{tasks:t=[],messages:s=[],engine:l="claude",sessionId:a="",onStopTask:i,onClose:o}=e,[c,d]=(0,r.useState)(()=>Date.now()),[u,m]=(0,r.useState)(null),x=l4(e=>e.bySession[a]?.harnessTasks);(0,r.useEffect)(()=>{let e=setInterval(()=>d(Date.now()),1e3);return()=>clearInterval(e)},[]);let p=(0,r.useMemo)(()=>t.map(e=>x?.find(t=>t.taskId===e.taskId)||e),[t,x]),h=p.find(e=>e.taskId===u)||p[0];if(!h)return null;let f=lD(h,c),b=!h.endedAt&&("running"===h.status||"paused"===h.status);return(0,n.jsxs)(rb,{icon:(0,n.jsx)(il,{background:h.background,engine:l,size:16}),iconClass:"",title:h.description||h.subagentType||"Task",subtitle:b?`Running for ${av(f)}`:`Ended \xb7 ${av(f)}`,onClose:o,actions:b&&h.taskId&&i?(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eN.e)(),i(h.taskId)},className:"px-2.5 py-1 rounded-brand text-xs font-medium text-danger bg-danger/10 hover:bg-danger/20 transition-colors flex items-center gap-1.5",title:"Stop this task",children:[(0,n.jsx)(ev.M6,{size:10,className:"fill-current"}),(0,n.jsx)("span",{children:"Stop"})]}):null,children:[p.length>1&&(0,n.jsx)("div",{className:"px-4 py-2 border-b border-border-subtle bg-bg flex items-center gap-1 overflow-x-auto custom-scrollbar shrink-0",children:p.map((e,t)=>{let s=e.taskId===h.taskId;return(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eN.e)(),m(e.taskId)},className:`shrink-0 flex items-center gap-1.5 px-2.5 py-1 rounded-brand text-xs transition-colors ${s?"bg-surface-2 text-text font-medium":"text-text-muted hover:text-text hover:bg-surface-2/40"}`,children:[(0,n.jsx)(il,{background:e.background,engine:l,size:13,className:s?"opacity-100":"opacity-60"}),(0,n.jsx)("span",{className:"truncate max-w-[140px]",children:e.description||e.subagentType||e.taskId}),(0,n.jsx)("span",{className:"font-mono text-[10px] opacity-60 tabular-nums",children:"running"===e.status?av(lD(e,c)):e.status})]},e.taskId||e.id||t)})}),(0,n.jsxs)("div",{className:"p-3 flex-1 overflow-y-auto custom-scrollbar",children:[(0,n.jsx)(ii,{task:h,messages:s,engine:l,running:b}),h.summary&&(0,n.jsx)("p",{className:"mt-3 text-[11px] text-text-muted leading-relaxed",children:h.summary}),h.outputFile&&(0,n.jsxs)("p",{className:"mt-3 font-mono text-[10px] text-text-subtle truncate",title:h.outputFile,children:["output \xb7 ",h.outputFile]})]})]})});function ii(e){let{task:t,messages:s,engine:r,running:l}=e,a=ly(s,t.toolUseId);if(!a)return(0,n.jsx)("div",{className:"flex flex-col items-center justify-center gap-2.5 py-14 text-text-muted select-none",children:l?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(ev.kr,{size:24,className:"animate-spin text-brand-500 opacity-80"}),(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("div",{className:"text-xs font-medium text-text",children:"Task is running..."}),(0,n.jsx)("div",{className:"text-[11px] text-text-subtle mt-0.5",children:"Waiting for task calls or tool events"})]})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(il,{background:t.background,engine:r,size:28,className:"opacity-40"}),(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("div",{className:"text-xs font-medium text-text",children:"No calls recorded"}),(0,n.jsx)("div",{className:"text-[11px] text-text-subtle mt-0.5",children:"This task ended without child tool calls"})]})]})});let i=a.children?.length?a.children:[a],o=a.input?.prompt||a.input?.description||"",c=a.error||a.output||"";return(0,n.jsxs)("div",{className:"flex flex-col",children:[o&&!a.async&&(0,n.jsx)(ay,{message:{id:`${a.id}:p`,role:"user",content:o},engine:r}),i.map(e=>a0(r,e,{deferred:!l,workspacePath:""})||(0,n.jsx)(aT,{...e,engine:r,workspacePath:"",deferred:!l},e.id)),!l&&c&&(0,n.jsx)(ir,{messages:[{id:`${a.id}:r`,role:"assistant",content:String(c),isLive:!1}],engine:r,isLive:!1})]})}let io=[{start:0,until:50,pct:[0,70],key:"menu.updateInstalling"},{start:50,until:80,pct:[70,90],key:"menu.updateRestarting"},{start:80,until:95,pct:[90,99],key:"menu.updateReconnecting"}],ic=io[io.length-1];function id(e){let{className:t=""}=e,{t:s}=(0,eC.s)(),[l,a]=(0,r.useState)(0);(0,r.useEffect)(()=>{let e=Date.now(),t=setInterval(()=>a((Date.now()-e)/1e3),500);return()=>clearInterval(t)},[]);let i=io.find(e=>l<e.until)||ic,o=Math.min(1,Math.max(0,(l-i.start)/(i.until-i.start))),c=Math.round(i.pct[0]+(i.pct[1]-i.pct[0])*o);return(0,n.jsxs)("div",{className:`flex items-center gap-2 min-w-0 ${t}`,title:`${s(i.key)} — ${c}%`,children:[(0,n.jsx)(ev.kr,{size:12,className:"animate-spin text-brand-400 shrink-0"}),(0,n.jsx)("span",{className:"h-1 flex-1 min-w-[60px] rounded-full bg-surface-2 overflow-hidden",children:(0,n.jsx)("span",{className:"block h-full bg-brand-500 rounded-full transition-[width] duration-500 ease-out",style:{width:`${c}%`}})})]})}function iu(e){let{hostKey:t,approval:s,onDeleteHost:r=null}=e,{t:l}=(0,eC.s)();if(!s)return null;let a="pending"===s;return(0,n.jsxs)("div",{className:`flex items-center gap-2 py-1.5 ${a?"":"text-red-400"}`,children:[a?(0,n.jsx)(ev.kr,{size:14,className:"animate-spin text-text-subtle shrink-0"}):(0,n.jsx)(ev.MA,{size:14,className:"shrink-0"}),(0,n.jsx)("span",{className:"text-[11px] truncate flex-1 min-w-0",title:l(a?"connection.approvalHint":"connection.rejectedDescription"),children:l(a?"connection.waitingApproval":"connection.rejectedTitle")}),(0,n.jsx)("button",{type:"button",onClick:()=>{(0,eN.e)(),P.rh.getState().connectHost(t)},className:"px-2 py-0.5 text-[11px] text-text-muted hover:text-text bg-surface-2 hover:bg-surface-3 rounded-brand transition-colors shrink-0",children:l("common.retry")}),a?(0,n.jsx)("button",{type:"button",onClick:()=>{(0,eN.e)(),P.rh.getState().disconnectHost(t)},className:"px-2 py-0.5 text-[11px] text-text-muted hover:text-text bg-surface-2 hover:bg-surface-3 rounded-brand transition-colors shrink-0",children:l("common.cancel")}):r&&(0,n.jsx)("button",{type:"button",onClick:()=>{(0,eN.e)(),r(t)},className:"px-2 py-0.5 text-[11px] text-red-400 hover:text-red-300 bg-red-500/10 hover:bg-red-500/20 rounded-brand transition-colors shrink-0",children:l("hosts.removeHost")})]})}let im=[];function ix(e){let{host:t,actions:s={},busRef:l=null,activeSessionId:a=null,activeWorkspaceId:i=null,connected:o=!0,fileBus:c=null,homeDir:d=null,hiddenPaneSessionIds:u=[],onUnhidePane:m=null,onAddWorkspace:x=null,menuAddWorkspace:p=null,onOpenRemoteHost:h=null,onOpenMobileHost:f=null,onRowContextMenu:b=null,onRowTouch:g=null,onRowMenu:v=null,agentBySession:y=null,cwdBySession:w=null,treeCls:j="pl-3.5",mobile:k=!1,onResumeAgentSession:N=null,rowCls:C="hover:bg-text/5 hover:text-text"}=e,{t:S}=(0,eC.s)(),{isCollapsed:T,toggle:E}=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",[t,s]=(0,r.useState)(()=>new Set(lo()[e]||[])),n=(0,r.useCallback)(t=>{s(s=>{let n=new Set(s);n.has(t)?n.delete(t):n.add(t);let r=lo();r[e]=[...n];try{localStorage.setItem(la,JSON.stringify(r))}catch{}return n})},[e]);return{isCollapsed:(0,r.useCallback)(e=>t.has(e),[t]),toggle:n}}(t.key),R=!T(li),[M,$]=(0,r.useState)(null),[z,A]=(0,r.useState)(null),[I,D]=(0,r.useState)(null),[L,B]=(0,r.useState)(null),[F,O]=(0,r.useState)(null),[_,K]=(0,r.useState)(!1),[W,H]=(0,r.useState)([]),[q,U]=(0,r.useState)(!1),X=t.status||"full",V="connecting"===X,G="full"===X||"online"===X,J="full"===X?o:G,Y="full"!==X?eH(t.key):null,Z=l||Y?.busRef||null;(0,r.useEffect)(()=>{null!==M&&Z?.current?.emit&&Z.current.emit("getShells",e=>H(e?.shells||[]))},[M,Z]);let Q=e=>{(0,eN.e)(),s.selectSession?.(e)},{dragId:ee,registerEl:et,startDrag:es,consumeClick:en}=n9({axis:"y",onTap:Q,onCommit:e=>s.reorderSession?.(e)}),er=(0,r.useRef)(null),el=()=>{er.current&&(clearTimeout(er.current.timer),er.current=null)},ea=e=>{let t=er.current;t&&(Math.abs(e.clientX-t.start.x)>ez.Qe||Math.abs(e.clientY-t.start.y)>ez.Qe)&&el()};(0,r.useEffect)(()=>{if(!ee)return;let e=e=>e.preventDefault();return window.addEventListener("touchmove",e,{passive:!1}),()=>window.removeEventListener("touchmove",e)},[ee]);let ei=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],s=new Set(t.map(e=>e.id)),n=new Map;for(let t of e){let e=s.has(t.workspaceId)?t.workspaceId:null;n.has(e)||n.set(e,[]),n.get(e).push(t)}return[...t.map(e=>({workspace:e,sessions:n.get(e.id)||[]})),...n.has(null)?[{workspace:null,sessions:n.get(null)}]:[]]}(t.sessions,t.workspaces),eo=(0,r.useMemo)(()=>new Set((t.sessions||[]).map(e=>e.id)),[t.sessions]);return(0,n.jsxs)("div",{children:[(0,n.jsx)(ll,{mobile:k,hostKey:t.key,label:t.label,connected:G,connecting:V,mutedOffline:"full"!==X,collapsed:!R,meta:V?(0,n.jsx)(ev.kr,{size:12,className:"animate-spin text-text-subtle"}):null,hostUpdating:!!t.updating,onOpenRemote:G&&t.remoteAvailable&&h?()=>h(t.key):null,onOpenMobile:G&&t.mobileAvailable&&f&&!t.updating?()=>f(t.key):null,onToggleCollapse:G?()=>{(0,eN.e)(),R||P.rh.getState().ensureHost(t.key),E(li)}:null,onConnect:"offline"===X?t.onConnect||(()=>P.rh.getState().connectHost(t.key)):null,onDisconnect:t.onDisconnect,onAddWorkspace:J?p??("full"!==X?()=>K(!0):null):null,onRename:s.renameHost,onDelete:s.deleteHost,showAdd:!1}),t.updating?(0,n.jsx)("div",{className:`${j} py-2`,children:(0,n.jsx)(id,{})}):t.approval?(0,n.jsx)("div",{className:j,children:(0,n.jsx)(iu,{hostKey:t.key,approval:t.approval,onDeleteHost:s.deleteHost})}):R&&G&&(0,n.jsxs)("div",{className:j,children:[t.updateAvailable&&t.canSelfUpdate&&!t.approval&&(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eN.e)(),U(!0)},title:S("menu.updateAvailableTitle"),className:"flex items-center gap-1.5 px-2 py-1 mb-1 max-w-full text-[11px] font-medium text-brand-400 hover:text-brand-300 bg-brand-500/10 hover:bg-brand-500/20 rounded-brand transition-colors",children:[(0,n.jsx)(ev.f5,{size:12,className:"shrink-0"}),(0,n.jsxs)("span",{className:"truncate",children:[S("menu.updateNow"),t.updateAvailable?.version?` \xb7 ${t.updateAvailable.version}`:""]})]}),ei.map(e=>{let{workspace:o,sessions:x}=e,h=o?.id??null,f=h??"ungrouped",j=i===h;return(0,n.jsxs)("div",{className:`flex flex-col ${k?"":"mt-1 first:mt-0"}`,children:[(0,n.jsx)(lh,{mobile:k,workspace:{id:h,name:o?.name||S("workspaces.ungrouped"),path:o?.path||null,items:x},isActive:j,connected:J,fileBus:c,statusMap:t.statusMap,collapsed:T(f),onToggleCollapse:()=>E(f),onSelect:s.selectWorkspace?()=>{(0,eN.e)(),s.selectWorkspace(h)}:null,onNewTerminal:s.createSession?()=>$(f):null,onAddWorkspace:p,onRename:s.renameWorkspace&&null!=h?()=>A({id:h,value:o.name}):null,onDelete:s.deleteWorkspace&&null!=h?()=>D({id:h,name:o.name}):null}),!T(f)&&x.map((e,l)=>{let i=t.statusMap?.[e.id]?.state||"idle",p=nx(i),j=a===e.id,N=ee===e.id,T=u.includes(e.id),E=e.name||S("terminal.defaultName");return(0,n.jsx)(r.Fragment,{children:(0,n.jsxs)("div",{ref:et(e.id),"data-sid":e.id,style:k?{"--i":String(Math.min(l,6))}:void 0,className:`group flex items-center gap-1.5 ${k?"pl-6 pr-9 list-rise":"pl-3.5 pr-2"} py-1.5 ml-0.5 rounded-[3px] text-left relative cursor-pointer select-none touch-manipulation touch-pan-y ${j?"bg-brand-500/15 text-text":`text-text/85 active:bg-text/[0.06] ${C}`} ${N?"z-20 opacity-90 shadow-lg ring-1 ring-brand-500":"transition-colors"}`,onClick:()=>{en()||Q(e.id)},onPointerDown:t=>((e,t,s)=>{if(s.length<2||!J)return;if("mouse"===e.pointerType)return void es(e,t,s);if(g)return;let n={x:e.clientX,y:e.clientY};er.current={timer:setTimeout(()=>{el(),(0,eN.e)(),es(e,t,s)},ez.A_),start:n}})(t,e.id,x.map(e=>e.id)),onPointerMove:ea,onPointerUp:el,onPointerCancel:el,onPointerLeave:el,onContextMenu:b?t=>b(t,e.id,E):void 0,onTouchStart:g?.start,onTouchMove:g?.move,onTouchEnd:g?.end,children:[J&&(0,n.jsx)("button",{"data-gid":"ungrouped"===f?"":h,"data-sid":e.id,onPointerDown:t=>{t.stopPropagation(),es(t,e.id,x.map(e=>e.id))},disabled:x.length<2,className:"absolute left-0 top-1/2 -translate-y-1/2 z-10 p-0.5 text-text-subtle opacity-0 group-hover:opacity-100 cursor-grab active:cursor-grabbing touch-none disabled:opacity-0 disabled:cursor-default",tabIndex:-1,children:(0,n.jsx)(ev.f2,{size:12})}),(0,n.jsx)("span",{className:`w-2 h-2 rounded-full flex-shrink-0 term-dot ${p.cls}${p.pulse?` pulse-${p.pulse}`:""}`,style:{background:p.dot}}),(0,n.jsxs)("span",{className:"flex-1 min-w-0 flex flex-col",children:[(0,n.jsxs)("span",{className:`flex items-center gap-1.5 min-w-0 ${j?"font-medium":""}`,children:[(0,n.jsx)(nM,{agent:y?.[e.id]??e.agent,tool:t.statusMap?.[e.id]?.tool}),(0,n.jsx)("span",{className:`${k?"text-[17px]":"text-[11px]"} truncate`,"data-tip":E,children:E}),T&&m&&(0,n.jsx)("button",{type:"button",tabIndex:-1,onPointerDown:e=>e.stopPropagation(),onMouseDown:e=>e.stopPropagation(),onClick:t=>{t.stopPropagation(),(0,eN.e)(),m(e.id)},className:"p-0.5 rounded text-amber-400 hover:text-amber-300 hover:bg-amber-400/20 transition-colors flex items-center justify-center shrink-0 ml-1",title:S("sessions.showPanel")||"Show panel",children:(0,n.jsx)(ev.X_,{size:12})})]}),(0,n.jsx)(lf,{mobile:k,fileBus:c,cwd:w?.[e.id]??e.cwd??e.workspacePath,basePath:nS({path:o?.path||null,items:x}),homeDir:d})]}),(0,n.jsx)("div",{className:`absolute right-1 top-1/2 -translate-y-1/2 flex items-center ${k?"opacity-100":"px-1 rounded-[3px] bg-surface-2 opacity-0 group-hover:opacity-100 [@media(hover:none)]:opacity-60"} transition-opacity`,children:v?(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),(0,eN.e)();let s=t.currentTarget.getBoundingClientRect();v(e.id,E,s)},className:"p-0.5 text-text-subtle hover:text-text rounded-[2px] transition-colors",title:S("sessions.sessionActions"),children:(0,n.jsx)(ev.a4,{size:k?18:13.5})}):(0,n.jsx)(r7,{size:k?18:13.5,label:S("sessions.sessionActions"),revealCls:"",items:["done"===i&&{icon:ev.aJ,label:S("sessions.markRead"),amber:!0,onClick:()=>eL.getState().clearNotification(e.id)},s.renameSession&&{icon:ev.gH,label:S("sessions.editName"),onClick:()=>B({id:e.id,value:e.name||""})},s.backgroundSession&&{icon:ev._V,label:S("menu.terminalBackground"),onClick:()=>s.backgroundSession(e)},s.deleteSession&&{icon:ev.TB,label:S("sessions.deleteTitle"),danger:!0,onClick:()=>O({id:e.id,name:e.name||""})}]})})]})},e.id)}),!T(f)&&l&&(0,n.jsx)(ip,{busRef:l,storeKey:h??"default",workspaceId:h,mobile:k,rowCls:C,onSelectWorkspace:s.selectWorkspace?()=>s.selectWorkspace(h):null}),!T(f)&&(k?(0,n.jsxs)("button",{onClick:()=>{(0,eN.e)(),$(f)},disabled:!J,className:"w-full flex items-center gap-1.5 pl-[38px] py-1.5 text-left text-[15px] text-text-muted hover:text-brand-500 transition-colors disabled:opacity-40",title:S("workspaces.addTerminal"),children:[(0,n.jsx)(ev.FW,{size:15,className:"flex-shrink-0"}),(0,n.jsx)("span",{children:S("terminal.newTerminal")})]}):0===x.length?(0,n.jsxs)("button",{onClick:()=>{(0,eN.e)(),$(f)},disabled:!J,className:"w-full flex items-center gap-1.5 pl-3.5 pr-2 py-1.5 text-left text-[12px] text-text-subtle hover:text-brand-500 transition-colors disabled:opacity-40",title:S("workspaces.addTerminal"),children:[(0,n.jsx)(ev.FW,{size:12,className:"flex-shrink-0"}),(0,n.jsx)("span",{children:S("terminal.newTerminal")})]}):null)]},f)}),(0,n.jsxs)("button",{onClick:()=>{(0,eN.e)(),x?x():K(!0)},disabled:!J,className:`w-full flex items-center gap-1.5 ${k?"text-[15px] text-text-muted":"text-[12px] mt-1 text-text-subtle"} py-1.5 text-left hover:text-brand-500 transition-colors disabled:opacity-40`,title:S("workspaces.newWorkspace"),children:[(0,n.jsx)(ev.FW,{size:k?18:12,className:"flex-shrink-0"}),(0,n.jsx)("span",{children:S("workspaces.newWorkspace")})]})]}),null!==M&&(0,n.jsx)(n1,{onClose:()=>$(null),onCreate:(e,t,n,r,l,a)=>{s.createSession?.(e,"ungrouped"===M?null:M,t,l,n,r,a),$(null)},shells:W,busRef:Z,hostKey:t.key,onResumeAgentSession:N,onSelectSession:s.selectSession,liveSessionIds:eo,connected:J,workspaceId:"ungrouped"===M?null:M,workspacePath:t.workspaces?.find(e=>e.id===("ungrouped"===M?null:M))?.path||null,workspaceName:"ungrouped"===M?S("workspaces.ungrouped"):t.workspaces?.find(e=>e.id===M)?.name||"",suggestName:`${S("terminal.defaultName")} ${(t.sessions?.length||0)+1}`}),_&&Y&&(0,n.jsx)(nG,{fileBus:Y.fileBus,scope:Y.scope,onSelect:e=>{if(K(!1),!e)return;let t=e.split("/").filter(Boolean).pop()||e;eM(e,Y.scope),s.createWorkspace?.(t,e,t=>{let n=t?.workspace||t?.group;t?.success&&n?.id&&s.createSession?.(null,n.id,null,e)})},onClose:()=>K(!1)}),null!==z&&(0,n.jsx)(nL,{title:S("workspaces.rename"),value:z.value,onChange:e=>A({...z,value:e}),onSubmit:()=>{let e=z.value.trim();e&&s.renameWorkspace?.(z.id,e),A(null)},onClose:()=>A(null)}),null!==I&&(0,n.jsx)(ek.A,{isOpen:!0,onClose:()=>D(null),onConfirm:()=>{s.deleteWorkspace?.(I.id),D(null)},title:S("workspaces.deleteTitle"),message:S("workspaces.deleteMessage",{name:I.name}),confirmText:S("common.delete")}),(0,n.jsx)(ek.A,{isOpen:q,onClose:()=>U(!1),onConfirm:()=>{U(!1),P.rh.getState().requestHostUpdate(t.key,"update")},title:S("menu.updateConfirmTitle"),message:S("menu.updateConfirmMessage")}),null!==L&&(0,n.jsx)(nL,{title:S("sessions.editName"),value:L.value,onChange:e=>B({...L,value:e}),onSubmit:()=>{let e=L.value.trim();e&&s.renameSession?.(L.id,e),B(null)},onClose:()=>B(null)}),null!==F&&(0,n.jsx)(ek.A,{isOpen:!0,onClose:()=>O(null),onConfirm:()=>{s.deleteSession?.(F.id),O(null)},title:S("sessions.deleteTitle"),message:S("sessions.deleteMessage",{name:F.name||""}),confirmText:S("common.delete")})]})}function ip(e){let{busRef:t,storeKey:s,workspaceId:r,mobile:l,rowCls:a,onSelectWorkspace:i}=e,o=nk(e=>e.workspaceProfiles[s]||"default"),c=nk(e=>e.tabsByWorkspace[s]??im),d=nk(e=>e.activeByWorkspace[s]||null),u=(0,f.B)(e=>{let t=e.viewStack;return!!(t&&t[t.length-1]?.type==="browser")}),m=(0,f.B)(e=>e.pushView),x=(0,f.B)(e=>(e.activeWorkspaceId??null)===r),p=(0,f.B)(e=>e.setActiveWorkspaceId);return c.length?c.map(e=>{let c=u&&x&&e.id===d,h=e.title||"Browser";return(0,n.jsxs)("div",{className:`group flex items-center gap-1.5 ${l?"pl-6":"pl-3.5"} pr-2 py-1.5 ml-0.5 rounded-[3px] text-left relative cursor-pointer select-none touch-manipulation touch-pan-y transition-colors ${c?"bg-brand-500/15 text-text":`text-text-muted ${a}`}`,onClick:()=>{var t;return t=e.id,void((0,eN.e)(),!x&&(i?i():p(r)),nk.getState().setActive(s,t),m({type:"browser"}))},title:e.url,children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full flex-shrink-0 bg-white shadow-[0_0_4px_rgba(255,255,255,0.8)]"}),(0,n.jsx)(lc,{name:o,size:14}),(0,n.jsx)("span",{className:`flex-1 min-w-0 truncate ${l?"text-base":"text-[11px]"} ${c?"font-medium":""}`,"data-tip":h,children:h}),(0,n.jsx)("button",{onClick:n=>{n.stopPropagation(),(0,eN.e)(),t?.current?.emit?.("browser:invoke",{action:"close",payload:{targetId:e.id,profile:nk.getState().workspaceProfiles[s]||"default"}},()=>{});let r=nk.getState(),l=(r.tabsByWorkspace[s]||[]).filter(t=>t.id!==e.id);r.setTabs(s,l),r.activeByWorkspace[s]===e.id&&r.setActive(s,l[0]?.id||null)},className:`p-0.5 rounded text-text-muted hover:text-text hover:bg-surface-3 shrink-0 ${l?"flex":"opacity-0 group-hover:opacity-100"} transition-opacity`,title:"Close tab",children:(0,n.jsx)(ev.X,{size:12})})]},e.id)}):null}let ih=(0,m.gJ)(),ib=(0,r.memo)(function(e){let{allSessions:t=[],mainSessions:s=null,workspaces:l=[],activeSessionId:a,activeWorkspaceId:i,sessionStatus:o,notifications:c,onSelectSession:d,onSelectWorkspace:u,onCreateNamedSession:x,onDeleteWorkspace:p,shells:h=[],onRenameSession:b,onDeleteSession:g,onReorderSession:v,onAddWorkspace:y,onRenameWorkspace:w=null,onOpenSettings:j,onOpenRemoteHost:k=null,onOpenMobileHost:N=null,onRenameHost:C=null,onDeleteHost:S=null,onMainDisconnect:T=null,onMainReconnect:E=null,busRef:R=null,fileBus:M,homeDir:$,cwdBySession:z={},connected:A=!0,width:I=ez.gH.default,onResize:D,onCollapse:L,onResumeAgentSession:B}=e,{t:F}=(0,eC.s)(),O=(0,f.B)(e=>e.agentBySession||{}),_=Object.values((0,P.rh)(e=>e.hosts)),K=(0,P.rh)(e=>e.currentKey),W=_.find(e=>e.key===K),[H,q]=(0,r.useState)(!1),U=e_(_,W?.key),X=(0,f.B)(e=>e.fullModes||{});(0,f.B)(e=>e.fullMode);let V=(0,f.B)(e=>e.toggleFullMode),G=(0,f.B)(e=>e.setFullMode),J=(0,f.B)(e=>e.pushView),Y=(0,f.B)(e=>e.viewStack),Z=(0,f.B)(e=>e.setViewStack),Q=Y[Y.length-1]?.type,ee=(0,f.B)(e=>e.hiddenPaneSessionIds||[]),et=(0,f.B)(e=>e.toggleHidePane),es=(0,f.B)(e=>e.unhidePane),en=eG(),er=o||en,el="mouse"===sD()?tI(F("common.close"),"toggleSidebar"):F("common.close"),ea=(0,r.useMemo)(()=>new Set(t.map(e=>e.id)),[t]),ei=(0,r.useMemo)(()=>s||t.filter(e=>!e.hostKey),[s,t]),eo=a?z[a]??t.find(e=>e.id===a)?.cwd??t.find(e=>e.id===a)?.workspacePath??null:null,ec=eq(a),ed=tr(e=>e.canInstall),eu=tr(e=>e.isInstalled),em=tr(e=>e.install),ex=window.matchMedia("(display-mode: standalone)").matches||!!window.ReactNativeWebView,ep=ed&&!ex&&!eu&&!(0,m.gJ)(),[eh,ef]=(0,r.useState)(null),eb=(0,r.useRef)(null),eg=n2(eb,eh?.left??0,eh?.top??0),[ey,ew]=(0,r.useState)(null),ej=O[eh?.sessionId]||er[eh?.sessionId]?.tool||t.find(e=>e.id===eh?.sessionId)?.agent,eS=ej?.endsWith("-ui");er[eh?.sessionId]?.conversationId;let eT=rR(ej),eE=eT&&rE.has(er[eh?.sessionId]?.state||"idle"),eR=(0,ti.xs)(t.find(e=>e.id===eh?.sessionId))??ti.AD,eM=X[eR]??!1,[e$,eP]=(0,r.useState)({sessionId:null,name:"",value:""}),[eA,eI]=(0,r.useState)(null);(0,r.useEffect)(()=>{if(!eh)return;let e=e=>{eb.current&&!eb.current.contains(e.target)&&ef(null)},t=e=>{"Escape"===e.key&&ef(null)};return document.addEventListener("mousedown",e),document.addEventListener("touchstart",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("touchstart",e),document.removeEventListener("keydown",t)}},[eh]);let eD=e=>t.find(t=>t.id===e),eB=e=>{e.preventDefault(),e.stopPropagation();let t=e.currentTarget.dataset.sid,s=eD(t);ef({sessionId:t,left:e.clientX,top:e.clientY,name:s?.name||""})},eF=(0,r.useRef)(null),eK=()=>{eF.current&&(clearTimeout(eF.current),eF.current=null)},eW=e=>{let t,s;t=e.currentTarget.dataset.sid,s=e.touches[0],eF.current=setTimeout(()=>{(0,eN.e)();let e=eD(t);ef({sessionId:t,left:s.clientX,top:s.clientY,name:e?.name||""})},500)};return(0,n.jsxs)("div",{className:"flex-shrink-0 h-full hidden sm:flex flex-col terminal-sidebar-bg border-r border-border-subtle relative",style:{width:I},children:[(0,n.jsxs)("div",{style:{height:32},className:"pl-[18px] pr-1 flex items-center justify-between flex-shrink-0 border-b border-border-subtle relative z-10",children:[(0,n.jsxs)("button",{onClick:()=>{(0,eN.e)(),Z([{type:"list"}])},title:"9Remote",className:"flex items-center gap-2 min-w-0 flex-shrink-0",children:[(0,n.jsx)("img",{src:"/icon-192.png",alt:"9Remote",draggable:!1,className:"w-4 h-4 rounded-[4px] object-contain flex-shrink-0 pointer-events-none select-none"}),(0,n.jsx)("span",{className:"text-[13px] font-semibold text-text truncate",children:"9Remote"})]}),(0,n.jsxs)("div",{className:"flex items-center gap-0.5 flex-shrink-0",children:[(0,n.jsx)("button",{onClick:()=>{(0,eN.e)(),q(!0)},className:"p-1 text-text-muted hover:text-text rounded-[3px] hover:bg-surface-2 transition-colors",title:F("hosts.addHost"),children:(0,n.jsx)(ev.kV,{size:14})}),L&&(0,n.jsx)("button",{onClick:()=>{(0,eN.e)(),L()},className:"p-1 text-text-muted hover:text-text rounded-[3px] hover:bg-surface-2 transition-colors",title:el,children:(0,n.jsx)(ev.e6,{size:14})})]})]}),(0,n.jsxs)("div",{className:"flex-1 min-h-0 overflow-y-auto modal-scrollable pt-1.5 pl-3.5 relative z-10",children:[ih&&(0,n.jsxs)("button",{onClick:()=>{(0,eN.e)(),J({type:"pair"})},"aria-label":"Pair Device",className:`-ml-3.5 w-[calc(100%+0.875rem)] flex items-center gap-2 pl-[17px] pr-3 py-1 rounded-[6px] text-left transition-colors duration-150 ${"pair"===Q?"bg-brand-500/10 text-brand-500":"text-text-muted hover:text-text hover:bg-surface-2"}`,title:"Pair Device",children:[(0,n.jsx)(ev.vW,{size:15,className:"flex-shrink-0"}),(0,n.jsx)("span",{className:"text-xs font-medium truncate",children:"Pair Device"})]}),U.map((e,t)=>(0,n.jsx)("div",{className:0===t?"-ml-3.5":"mt-1 -ml-3.5 border-t border-border-subtle pt-1",children:e.key===(W?.key||"main")?(0,n.jsx)(ix,{host:{...W||{},key:W?.key||"main",label:W?.label||"",workspaces:l,sessions:ei,statusMap:er,onDisconnect:T,onConnect:E},busRef:R,actions:{selectSession:e=>{ee.includes(e)&&es(e),d?.(e)},selectWorkspace:e=>{(0,eN.e)(),u?.(e)},createSession:x,renameSession:b,deleteSession:g,reorderSession:v,renameWorkspace:w,deleteWorkspace:p,renameHost:C,deleteHost:S},activeSessionId:a,activeWorkspaceId:i,connected:A,fileBus:M,homeDir:$,cwdBySession:z,agentBySession:O,hiddenPaneSessionIds:ee,onUnhidePane:es,onAddWorkspace:y,menuAddWorkspace:y,onOpenRemoteHost:k,onOpenMobileHost:N,onRowContextMenu:eB,onRowTouch:{start:eW,move:eK,end:eK},onRowMenu:(e,t,s)=>ef({sessionId:e,left:s.left,top:s.bottom+2,name:t}),treeCls:"pl-3.5"}):(0,n.jsx)(ix,{host:{...e,onDisconnect:()=>P.rh.getState().disconnectHost(e.key)},actions:{...tw(e,{onSelectSession:d,onSelectWorkspace:u}),renameHost:C,deleteHost:S},activeSessionId:a,activeWorkspaceId:function(e,t){let s=eO(e,t);if(null!==s)return"_"===s?null:s}(i,e.key),connected:A,hiddenPaneSessionIds:ee,onOpenRemoteHost:k,onOpenMobileHost:N,onUnhidePane:es,treeCls:"pl-3.5"})},e.key))]}),B&&(0,n.jsx)(nD,{busRef:ec.busRef,scope:ec.scope,cwd:eo,onResume:B,onSelectSession:d,liveSessionIds:ea,activeSessionId:a,connected:A}),(ep||j)&&(0,n.jsxs)("div",{className:"p-1.5 border-t border-border-subtle flex-shrink-0 relative z-10",children:[ep&&(0,n.jsxs)("button",{onClick:()=>{(0,eN.e)(),em()},className:"w-full flex items-center gap-2 pl-3 pr-2 py-1.5 text-xs text-text-muted hover:text-text hover:bg-surface-2 rounded-[3px] transition-colors",title:F("menu.installApp"),children:[(0,n.jsx)(ev.f5,{size:14}),(0,n.jsx)("span",{children:F("menu.installApp")})]}),j&&(0,n.jsxs)("button",{onClick:()=>{(0,eN.e)(),j()},className:"w-full flex items-center gap-2 pl-3 pr-2 py-1.5 text-xs text-text-muted hover:text-text hover:bg-surface-2 rounded-[3px] transition-colors",title:F("menu.settings"),children:[(0,n.jsx)(ev.wB,{size:14}),(0,n.jsx)("span",{children:F("menu.settings")})]})]}),H&&(0,n.jsx)(lr,{onClose:()=>q(!1)}),(0,n.jsx)("div",{onPointerDown:e=>{e.stopPropagation(),ts(e,{startWidth:I,onWidth:e=>D?.(e)})},className:"absolute top-0 right-0 bottom-0 w-1 cursor-col-resize hover:bg-brand-500/40 transition-colors z-20"}),eh&&(0,n.jsxs)("div",{ref:eb,className:"fixed z-[70] menu-popover p-1 min-w-[160px] pop-in",style:{left:eg.left,top:eg.top},children:[er[eh.sessionId]?.state==="done"&&(0,n.jsxs)("button",{onClick:()=>{(0,eN.e)(),eL.getState().clearNotification(eh.sessionId),ef(null)},className:"w-full text-left px-2.5 py-1.5 text-xs text-amber-500 hover:bg-amber-500/10 rounded-[6px] flex items-center gap-2",children:[(0,n.jsx)(ev.aJ,{size:13})," ",F("sessions.markRead")]}),(0,n.jsxs)("button",{onClick:()=>{var e;let t;return e=eh.sessionId,t=eD(e)?.name||"",void(eP({sessionId:e,name:t,value:t}),ef(null))},className:"w-full text-left px-2.5 py-1.5 text-xs text-text hover:bg-surface-2/80 rounded-[6px] flex items-center gap-2",children:[(0,n.jsx)(ev.gH,{size:13})," ",F("sessions.editName")]}),(0,n.jsxs)("div",{className:"relative group/split",children:[(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eN.e)();let e=eh.sessionId;!eM&&e&&e!==a&&d?.(e),V(eR),ef(null)},className:"w-full text-left px-2.5 py-1.5 text-xs text-text hover:bg-surface-2/80 rounded-[6px] flex items-center justify-between",children:[(0,n.jsxs)("span",{className:"flex items-center gap-2",children:[(0,n.jsx)(ev.Wn,{size:13}),(0,n.jsx)("span",{children:F("sessions.split")||"Split"})]}),(0,n.jsx)(ev.c_,{size:12,className:"text-text-muted"})]}),(0,n.jsxs)("div",{className:`hidden group-hover/split:block absolute top-0 menu-popover p-1 min-w-[130px] shadow-xl z-20 ${eg.left>window.innerWidth-280?"right-full -mr-0.5":"left-full -ml-0.5"}`,children:[(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eN.e)();let e=eh.sessionId;!eM&&e&&e!==a&&d?.(e),V(eR),ef(null)},className:"w-full text-left px-2 py-1.5 text-xs text-text hover:bg-surface-2/80 rounded-[6px] flex items-center justify-between",children:[(0,n.jsxs)("span",{className:"flex items-center gap-1.5",children:[eM?(0,n.jsx)(ev.xq,{size:12}):(0,n.jsx)(ev.h1,{size:12}),(0,n.jsx)("span",{className:"whitespace-nowrap",children:eM?"Restore":"Maximize"})]}),(0,n.jsx)("span",{className:"text-[10px] text-text-muted",children:"100%"})]}),(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eN.e)(),eh.sessionId&&eh.sessionId!==a&&d?.(eh.sessionId),eM&&G(eR,!1),window.dispatchEvent(new CustomEvent("terminal:splitPreset",{detail:{fraction:2}})),ef(null)},className:"w-full text-left px-2 py-1.5 text-xs text-text hover:bg-surface-2/80 rounded-[6px] flex items-center justify-between",children:[(0,n.jsx)("span",{children:"1/2"}),(0,n.jsx)("span",{className:"text-[10px] text-text-muted",children:"50%"})]}),(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eN.e)(),eh.sessionId&&eh.sessionId!==a&&d?.(eh.sessionId),eM&&G(eR,!1),window.dispatchEvent(new CustomEvent("terminal:splitPreset",{detail:{fraction:3}})),ef(null)},className:"w-full text-left px-2 py-1.5 text-xs text-text hover:bg-surface-2/80 rounded-[6px] flex items-center justify-between",children:[(0,n.jsx)("span",{children:"1/3"}),(0,n.jsx)("span",{className:"text-[10px] text-text-muted",children:"33%"})]}),(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eN.e)(),eh.sessionId&&eh.sessionId!==a&&d?.(eh.sessionId),eM&&G(eR,!1),window.dispatchEvent(new CustomEvent("terminal:splitPreset",{detail:{fraction:4}})),ef(null)},className:"w-full text-left px-2 py-1.5 text-xs text-text hover:bg-surface-2/80 rounded-[6px] flex items-center justify-between",children:[(0,n.jsx)("span",{children:"1/4"}),(0,n.jsx)("span",{className:"text-[10px] text-text-muted",children:"25%"})]}),(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eN.e)(),eh.sessionId&&eh.sessionId!==a&&d?.(eh.sessionId),eM&&G(eR,!1),window.dispatchEvent(new CustomEvent("terminal:splitPreset",{detail:{fraction:"auto"}})),ef(null)},className:"w-full text-left px-2 py-1.5 text-xs text-text hover:bg-surface-2/80 rounded-[6px] flex items-center justify-between",children:[(0,n.jsx)("span",{children:"Auto Fit"}),(0,n.jsx)("span",{className:"text-[10px] text-text-muted",children:"Auto"})]}),(0,n.jsx)("div",{className:"h-px bg-border-subtle my-1"}),(0,n.jsx)("button",{type:"button",onClick:()=>{(0,eN.e)(),et(eh.sessionId),ef(null)},className:"w-full text-left px-2 py-1.5 text-xs text-text hover:bg-surface-2/80 rounded-[6px] flex items-center justify-between",children:(0,n.jsxs)("span",{className:"flex items-center gap-1.5",children:[ee.includes(eh.sessionId)?(0,n.jsx)(ev.kU,{size:12}):(0,n.jsx)(ev.X_,{size:12}),(0,n.jsx)("span",{children:ee.includes(eh.sessionId)?F("sessions.showPanel")||"Show":F("sessions.hidePanel")||"Hide"})]})})]})]}),(0,n.jsxs)("button",{onClick:()=>{(0,eN.e)(),ew(eh.sessionId),ef(null)},className:"w-full text-left px-2.5 py-1.5 text-xs text-text hover:bg-surface-2/80 rounded-[6px] flex items-center gap-2",children:[(0,n.jsx)(ev._V,{size:13,className:"flex-shrink-0"})," ",F("menu.terminalBackground")]}),(O[eh.sessionId]?.endsWith("-ui")||er[eh.sessionId]?.conversationId)&&(0,n.jsxs)("button",{onClick:()=>{(0,eN.e)();let e=eh.sessionId,t=eq(e).bus;O[e]?.endsWith("-ui")?t?.emit("ai:restart",{sessionId:e}):t?.emit("session-resume",{sessionId:e}),ef(null)},className:"w-full text-left px-2.5 py-1.5 text-xs text-text hover:bg-surface-2/80 rounded-[6px] flex items-center gap-2",children:[(0,n.jsx)(ev.kt,{size:13})," ",O[eh.sessionId]?.endsWith("-ui")?F("sessions.restartAi")||"Restart AI":F("sessions.resumeSession")]}),eT&&(0,n.jsxs)("button",{disabled:!eE,onClick:()=>{(0,eN.e)();let e=eh.sessionId;eq(e).bus?.emit("setSessionMode",{sessionId:e,mode:eS?"terminal":"ui"},e=>{e?.success||alert(e?.error||F("sessions.modeSwitchFailed"))}),ef(null)},className:`w-full text-left px-2.5 py-1.5 text-xs rounded-[6px] flex items-center gap-2 ${eE?"text-text hover:bg-surface-2/80":"text-text-subtle cursor-not-allowed"}`,children:[(0,n.jsx)(ev.sU,{size:13})," ",eS?F("sessions.openAsTerminal"):F("sessions.openAsUi")]}),(0,n.jsx)("div",{className:"h-px bg-border-subtle my-1"}),(0,n.jsxs)("button",{onClick:()=>{eI({sessionId:eh.sessionId,name:eh.name}),ef(null)},className:"w-full text-left px-2.5 py-1.5 text-xs text-red-500 hover:bg-red-500/10 rounded-[6px] flex items-center gap-2",children:[(0,n.jsx)(ev.TB,{size:13})," ",F("sessions.deleteTitle")]})]}),ey&&(0,n.jsx)(n6,{sessionId:ey,title:eD(ey)?.name,busRef:R,onClose:()=>ew(null)}),e$.sessionId&&(0,n.jsx)(nL,{title:F("sessions.editName"),placeholder:e$.name,value:e$.value,onChange:e=>eP({...e$,value:e}),onSubmit:()=>{let e=e$.value.trim();e$.sessionId&&e&&b?.(e$.sessionId,e),eP({sessionId:null,name:"",value:""})},onClose:()=>eP({sessionId:null,name:"",value:""})}),(0,n.jsx)(ek.A,{isOpen:!!eA,onClose:()=>eI(null),onConfirm:()=>{eA?.sessionId&&g?.(eA.sessionId)},title:F("sessions.deleteTitle"),message:F("sessions.deleteMessage",{name:eA?.name||""}),confirmText:F("common.delete")})]})}),ig={claude:"Claude",codex:"Codex",kimi:"Kimi",grok:"Grok"};function iv(e){return e<60?"bg-text-muted/40":e<80?"bg-yellow-500":"bg-red-500"}function iy(e){let{enabled:t=!0}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},[s,n]=(0,r.useState)(null);return(0,r.useEffect)(()=>{if(!t||!e)return;let s=!1,r=()=>{e.current&&e.current.emit("quota:get",{},e=>{!s&&e?.success&&e.providers&&n(e)})};r();let l=n$(r,6e4);return()=>{s=!0,l()}},[e,t]),s}let iw=[["session","5h"],["weekly","wk"],["monthly","mo"]];function ij(e){let{usedPct:t}=e;return(0,n.jsx)("span",{className:"w-10 h-[5px] rounded-full bg-text-muted/20 overflow-hidden flex-shrink-0",children:(0,n.jsx)("span",{className:`block h-full rounded-full transition-all duration-300 ${iv(t)}`,style:{width:`${Math.min(100,Math.max(0,t))}%`}})})}function ik(e){let{provider:t}=e,[s,l]=(0,r.useState)(!1);return s?(0,n.jsx)("span",{className:"text-text-subtle",children:ig[t]||t}):(0,n.jsx)("img",{src:tu(t),alt:"",width:14,height:14,onError:()=>l(!0),className:`w-3.5 h-3.5 object-contain ${td}`})}function iN(e){let{label:t,window:s}=e;return s?(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"w-16 truncate text-text-muted",children:t}),(0,n.jsxs)("span",{className:"w-9 text-right tabular-nums",children:[Math.round(s.usedPercent),"%"]}),(0,n.jsx)(ij,{usedPct:s.usedPercent}),s.resetsAt&&(0,n.jsx)("span",{className:"text-text-subtle whitespace-nowrap",children:function(e){if(!e)return"";let t=new Date(e),s=t.toDateString()===new Date().toDateString(),n=t.toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"});return s?n:`${t.toLocaleDateString(void 0,{weekday:"short"})} ${n}`}(s.resetsAt)})]}):null}function iC(e){let{p:t,onClose:s}=e,l=(0,r.useRef)(null),{t:a}=(0,eC.s)();return(0,r.useEffect)(()=>{let e=e=>{l.current?.contains(e.target)||s()},t=e=>{"Escape"===e.key&&s()};return document.addEventListener("pointerdown",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("pointerdown",e),document.removeEventListener("keydown",t)}},[s]),(0,n.jsxs)("div",{ref:l,className:"absolute bottom-full right-0 mb-2 z-50 w-64 p-3 rounded-brand-lg bg-surface-2 border border-border shadow-lg text-[11px] flex flex-col gap-2",children:[(0,n.jsx)("div",{className:"font-medium",children:ig[t.provider]||t.provider}),iw.map(e=>{let[s,r]=e;return(0,n.jsx)(iN,{label:r,window:t[s]},s)}),(t.buckets||[]).map(e=>(0,n.jsx)(iN,{label:e.name,window:e},e.name)),!t.session&&!t.weekly&&!t.monthly&&!(t.buckets||[]).length&&(0,n.jsx)("div",{className:"text-text-muted",children:t.error||a("terminal.quotaNoData")}),t.error&&(t.session||t.weekly||t.monthly)&&(0,n.jsx)("div",{className:"text-text-subtle border-t border-border-subtle pt-1.5",children:t.error})]})}function iS(e){let{quota:t}=e,[s,l]=(0,r.useState)(null),{t:a}=(0,eC.s)();if(!t?.providers)return null;let i=Object.values(t.providers).filter(e=>e&&"ok"===e.status&&(e.session||e.weekly||e.monthly||e.buckets?.length));return i.length?(0,n.jsx)("span",{className:"relative flex items-center gap-1 flex-shrink-0",children:i.map(e=>{let t=e.session||e.weekly||e.monthly||e.buckets[0];return(0,n.jsxs)("span",{className:"relative",children:[(0,n.jsxs)("button",{type:"button",className:"flex items-center gap-1.5 px-1.5 py-0.5 rounded-[2px] hover:bg-white/10 transition-colors",onClick:()=>l(s===e.provider?null:e.provider),title:`${ig[e.provider]||e.provider} ${a("terminal.quotaUsageTitle")}`,children:[(0,n.jsx)(ik,{provider:e.provider}),(0,n.jsx)(ij,{usedPct:t.usedPercent}),(0,n.jsxs)("span",{className:"tabular-nums",children:[Math.round(t.usedPercent),"%"]})]}),s===e.provider&&(0,n.jsx)(iC,{p:e,onClose:()=>l(null)})]},e.provider)})}):null}function iT(e){let{left:t,right:s,className:r="flex"}=e;return(0,n.jsxs)("div",{style:{height:26},className:`statusbar-glass items-center gap-3 px-3 flex-shrink-0 border-t border-border-subtle text-[11px] text-text-muted select-none ${r}`,children:[(0,n.jsx)("div",{className:"flex items-center gap-3 min-w-0 flex-1",children:t}),(0,n.jsx)("div",{className:"flex items-center gap-3 flex-shrink-0",children:s})]})}let iE="flex items-center gap-1.5 px-1.5 py-0.5 rounded-[2px] hover:bg-white/10 transition-colors cursor-pointer",iR="flex items-center gap-1.5 px-1.5 py-0.5",iM={darwin:"mac",win32:"win",linux:"linux"};function i$(e){let{pages:t,activeKey:s}=e;return(0,n.jsx)("span",{className:"grid justify-items-end",children:t.map(e=>{let{key:t,node:r}=e;return(0,n.jsx)("span",{"aria-hidden":t!==s,className:"[grid-area:1/1] flex items-center min-w-0 motion-reduce:transition-none",style:{opacity:+(t===s),transform:t===s?"translateY(0)":"translateY(2px)",pointerEvents:t===s?"auto":"none",transition:`opacity ${ez.ZU}ms ease, transform ${ez.ZU}ms ease`},children:r},t)})})}let iz=(0,r.memo)(function(e){let t,s,l,{sessionId:a,fileBus:i,busRef:o,onReveal:c,workspacePath:d=null}=e,u=(0,f.B)(e=>e.cwdBySession[a])||"",{branch:m}=lx(u,i,{enabled:!!u}),{count:x,perRepo:p}=rB(d||u,i,{enabled:!!u}),h=(s=iy(o,{enabled:!!(t=(0,f.B)(e=>e.agentBySession[a])||"")}),(l=t?s?.providers?.[t]:null)&&"ok"===l.status&&l.session?{agentId:t,usedPct:l.session.usedPercent}:null),[b,g]=(0,r.useState)(!1),v=u?u.replace(/\\+|\/+$/g,"").split(/[\\/]/).filter(Boolean):[],y=v.length?v.slice(-2).join("/"):"";(0,r.useEffect)(()=>{if(!b)return;let e=setTimeout(()=>g(!1),ez.wu);return()=>clearTimeout(e)},[b]);let w=[];y&&w.push({key:"path",node:(0,n.jsxs)("button",{type:"button",onClick:c?()=>c(a,u):void 0,title:u,className:`flex items-center gap-1 min-w-0 font-mono ${c?"hover:text-text":""}`,children:[(0,n.jsx)(ev.vd,{size:10,className:"opacity-70 flex-shrink-0"}),(0,n.jsx)("span",{className:"truncate",children:y})]})}),h&&w.push({key:"quota",node:(0,n.jsxs)("button",{type:"button",onClick:()=>g(!0),className:"flex items-center gap-1.5 flex-shrink-0",children:[(0,n.jsx)("img",{src:tu(h.agentId),alt:"",width:11,height:11,draggable:!1,className:`w-[11px] h-[11px] object-contain ${td}`}),(0,n.jsx)("span",{className:"w-8 h-[4px] rounded-full bg-text-muted/20 overflow-hidden",children:(0,n.jsx)("span",{className:`block h-full rounded-full transition-all duration-300 ${iv(h.usedPct)}`,style:{width:`${Math.min(100,Math.max(0,h.usedPct))}%`}})}),(0,n.jsxs)("span",{className:"tabular-nums text-text-muted",children:[Math.round(h.usedPct),"%"]})]})});let j=h&&h.usedPct>=ez.W$?w.findIndex(e=>"quota"===e.key):-1,[k]=function(e){let{pinnedIndex:t=-1,paused:s=!1}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},[n,l]=(0,r.useState)(0);return((0,r.useEffect)(()=>{if(!(e<2)&&!s&&!(t>=0))return n$(()=>l(e=>e+1),ez.wu,{fireOnReturn:!1})},[e,s,t]),e)?[t>=0?t:n%e,l]:[0,l]}(w.length,{pinnedIndex:j,paused:b}),N=rD(p,u,x);return(0,n.jsxs)("div",{className:"flex items-center justify-between gap-2 px-3 h-6 border-t border-border-subtle text-[10px] text-text-subtle bg-bg flex-shrink-0",children:[m&&(0,n.jsxs)("span",{className:"flex items-center gap-1 flex-shrink-0",children:[(0,n.jsx)(ev.Zr,{size:10,className:"opacity-70"}),(0,n.jsx)("span",{className:"max-w-[90px] truncate text-text-muted",title:m,children:m}),N>0&&(0,n.jsx)("span",{className:"px-1 leading-tight bg-brand-500/15 text-brand-400 rounded-[2px] font-medium",children:N>ez.KN?`${ez.KN}+`:N})]}),w.length>0&&(0,n.jsx)(i$,{pages:w,activeKey:w[k]?.key})]})}),iP=(0,r.memo)(function(e){let{cwd:t,workspacePath:s=null,sessionId:r,hostKey:l=null,sessionState:a,sessionName:i="",hostVersion:o="",agentVersion:c="",platform:d="",homeDir:m=null}=e,{t:x}=(0,eC.s)(),p=function(e){let t=e&&e===P.rh.getState().currentKey?null:e,s=(0,u.d)(e=>t?null:e.connected),n=(0,u.d)(e=>t?"ws":e.carrier),r=(0,P.rh)(e=>e.hosts[t||e.currentKey]);if(!t)return{head:null,connected:!!s,status:s?"full":"offline",carrier:n||"ws",platform:r?.platform||null,version:r?.version||null};let l=r?.status||"offline";return{head:t,connected:"online"===l,status:l,carrier:r?.carrier||"ws",platform:r?.platform||null,version:r?.version||null}}(l),h=eH(l).busRef,b=eH(l).fileBus,g=(0,u.d)(e=>l?null:e.connectionMode),v=(0,u.d)(e=>l?"":e.endpoint),y=eU(r),w=p.connected,j=p.carrier,k=a||y||"idle",N=iy(h),C=(0,f.B)(e=>(e.agentBySession||{})[r])||"",S=i||"—",T=C?tu(C):null,{branch:E}=lx(t,b,{enabled:!!t}),{count:R,perRepo:M}=rB(s||t,b,{enabled:!!t}),$=rD(M,t,R),z=nx(k),A=x("working"===k?"common.statusWorking":"blocked"===k?"common.statusBlocked":"done"===k?"common.statusDone":"sleep"===k?"common.statusSleep":"common.statusIdle"),I=t?nC(t.replace(/\\/g,"/"),m):"",D=$>ez.KN?`${ez.KN}+`:$;return(0,n.jsx)(iT,{className:"hidden sm:flex",left:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("span",{className:"flex items-center gap-1.5 flex-shrink-0 max-w-[200px]",children:[T?(0,n.jsx)("img",{src:T,alt:"",draggable:!1,className:`w-3.5 h-3.5 object-contain flex-shrink-0 ${td}`}):(0,n.jsx)(nR,{size:14}),(0,n.jsx)("span",{className:"truncate font-medium text-text",title:S,children:S})]}),(0,n.jsx)("span",{className:"text-text-subtle flex-shrink-0",children:"›"}),(0,n.jsxs)("span",{className:"flex items-center gap-1.5 min-w-0 flex-shrink",children:[(0,n.jsx)(ev.vd,{size:12,className:"opacity-60 flex-shrink-0"}),(0,n.jsx)("span",{className:"truncate",title:t||"",children:I||x("common.loading")})]}),t&&E&&(0,n.jsxs)("span",{className:"flex items-center gap-1.5 flex-shrink-0",children:[(0,n.jsx)(ev.Zr,{size:12,className:"opacity-60 text-brand-500"}),(0,n.jsx)("span",{className:"truncate max-w-[160px]",title:E,children:E}),$>0&&(0,n.jsx)("span",{className:"px-1 leading-tight bg-brand-500/15 text-brand-400 rounded-[2px] font-medium",children:D})]})]}),right:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(iS,{quota:N}),(p.platform||d)&&(0,n.jsx)("span",{className:"uppercase tracking-wide",children:iM[p.platform||d]||p.platform||d}),(p.version||o||c)&&(0,n.jsxs)("span",{className:"text-text-subtle",children:["v",p.version||o||c]}),(0,n.jsxs)("span",{className:"flex items-center gap-1.5",title:`${v||""}${j&&"ws"!==j?` (${j})`:""}`,children:[(0,n.jsx)("span",{className:`w-2 h-2 rounded-full ${w?"local"===g?"bg-emerald-400":"bg-green-500":"bg-red-500 animate-pulse"}`}),(0,n.jsx)("span",{className:"uppercase tracking-wide",children:j&&"ws"!==j?"STUN":`WS${"local"===g?" \xb7 LOCAL":""}`})]}),(0,n.jsxs)("span",{className:"flex items-center gap-1.5",children:[(0,n.jsx)("span",{className:`w-2 h-2 rounded-full term-dot ${z.cls}${z.pulse?` pulse-${z.pulse}`:""}`,style:{background:z.dot}}),(0,n.jsx)("span",{children:A})]})]})})}),iA=(e,t,s)=>Math.max(t,Math.min(s,e));function iI(e){let t=window.innerWidth-4*ez.qj.margin,s=window.innerHeight-3*ez.qj.margin;return{...e,x:iA(e.x,ez.qj.margin-e.w+4*ez.qj.margin,t),y:iA(e.y,ez.qj.margin,s)}}function iD(e){let t=!1,s=null,n=e.length,r=0;for(;r+2<n;){if(0===e[r]&&0===e[r+1]){let l=0;if(1===e[r+2]?l=3:r+3<n&&0===e[r+2]&&1===e[r+3]&&(l=4),l){let n=31&e[r+l];7!==n||s||(s=e.subarray(r+l)),5===n&&(t=!0),r+=l+1;continue}}r++}return{isKey:t,spsBytes:s}}let iL="VideoDecoder"in window&&"EncodedVideoChunk"in window,iB=/^(\d\d-\d\d \d\d:\d\d:\d\d\.\d+)\s+\d+\s+\d+\s+([VDIWEF])\s+([^:]*):\s?(.*)$/;function iF(e){let{state:t}=e;return(0,n.jsx)("span",{className:`w-2 h-2 rounded-full flex-shrink-0 ${"running"===t?"bg-green-500 animate-pulse":"starting"===t||"stopping"===t?"bg-amber-400 animate-pulse":"bg-text-muted/40"}`})}function iO(e){let{devices:t,canManage:s,booting:l,stopping:a,loading:i,error:o,onOpen:c,onStop:d,onRefresh:u,lowPower:m,onLowPowerChange:x,onAddDevice:p,onDeleteAvd:h,onWipeAvd:f,sdkJob:b,onShowSetup:g}=e,{t:v}=(0,eC.s)(),[y,w]=(0,r.useState)(null),[j,k]=(0,r.useState)(null);return(0,n.jsxs)("div",{className:"w-full max-w-sm mx-auto p-4 space-y-3 fade-in",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("h2",{className:"text-text text-sm font-medium flex-1",children:v("mobile.pickDevice")}),(0,n.jsx)("button",{onClick:()=>{(0,eN.e)(),p?.()},className:"p-1.5 text-text-muted hover:text-brand-500 hover:bg-surface-2 rounded-brand transition-all duration-150 ease-out active:scale-[0.94]",title:v("mobile.addDevice"),"aria-label":v("mobile.addDevice"),children:(0,n.jsx)(ev.FW,{size:15})}),(0,n.jsx)("button",{onClick:()=>{(0,eN.e)(),u?.()},className:"p-1.5 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-all duration-150 ease-out active:scale-[0.94]",title:v("mobile.refreshDevices"),"aria-label":v("mobile.refreshDevices"),children:(0,n.jsx)(ev.e9,{size:15})})]}),b&&"done"!==b.phase&&"error"!==b.phase&&(0,n.jsxs)("button",{onClick:()=>{(0,eN.e)(),g?.()},className:"w-full flex items-center gap-2.5 bg-surface rounded-brand-lg px-3 py-2.5 hover:bg-surface-2 transition-colors text-left",children:[(0,n.jsx)(ev.kr,{size:15,className:"text-brand-500 animate-spin flex-shrink-0"}),(0,n.jsxs)("div",{className:"flex flex-col min-w-0 flex-1",children:[(0,n.jsx)("span",{className:"text-xs text-text truncate",children:v(function(e){if(e?.step)return`mobile.provisionStep_${e.step}`;let t=e?.component||"";return t.startsWith("system-images;")?"mobile.provisionStep_image":`mobile.provisionStep_${t}`}(b))}),(0,n.jsx)("span",{className:"text-[10px] text-text-muted",children:"image"===b.kind||"image"===b.step?`${b.percent??0}%`:`${Math.round((b.received||0)/1024/1024)} MB${b.bytesPerSec?` \xb7 ${Math.round(b.bytesPerSec/1024/1024)} MB/s`:""}`})]})]}),0===t.length&&(0,n.jsx)("div",{className:"text-center py-8 space-y-2 fade-in",children:i?(0,n.jsx)(ev.kr,{size:20,className:"text-brand-500 animate-spin mx-auto"}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(ev.wO,{size:26,className:"text-text-muted mx-auto"}),(0,n.jsx)("p",{className:"text-text-muted text-sm",children:v("mobile.noDevicesHint")})]})}),(0,n.jsx)("div",{className:"space-y-1.5",children:t.map((e,t)=>{let r=l?.avdName&&l.avdName===e.avdName,i=a?.has(e.serial),o="running"===e.state;return(0,n.jsxs)("div",{className:"bg-surface rounded-brand-lg overflow-hidden list-rise",style:{"--i":Math.min(t,8)},children:[(0,n.jsxs)("div",{className:"flex items-center gap-2.5 px-3 py-2",children:[(0,n.jsxs)("button",{onClick:()=>{(0,eN.e)(),c?.(e)},disabled:r||i,className:"flex items-center gap-2.5 flex-1 min-w-0 text-left disabled:opacity-60 transition-all duration-150 ease-out active:scale-[0.99]",children:["physical"===e.kind?(0,n.jsx)(ev.wO,{size:16,className:"text-brand-500 dark:text-white flex-shrink-0"}):(0,n.jsx)(ev.VA,{size:16,className:"text-brand-500 dark:text-white flex-shrink-0"}),(0,n.jsxs)("div",{className:"flex flex-col min-w-0 flex-1",children:[(0,n.jsx)("span",{className:"text-sm text-text truncate",children:e.name}),(0,n.jsx)("span",{className:"text-xs text-text-muted truncate",children:r?v(`mobile.phase${l.phase.charAt(0).toUpperCase()}${l.phase.slice(1)}`):i?v("mobile.stoppingDevice"):e.serial||v("mobile.stopped")})]}),(0,n.jsx)(iF,{state:r||i?"starting":e.state})]}),r?(0,n.jsx)(ev.kr,{size:15,className:"text-brand-500 animate-spin flex-shrink-0"}):o&&e.canStop?i?(0,n.jsx)(ev.kr,{size:15,className:"text-brand-500 animate-spin flex-shrink-0"}):(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),(0,eN.e)(),d?.(e)},className:"p-1.5 text-text-muted hover:text-red-400 hover:bg-surface-2 rounded-brand transition-all duration-150 ease-out active:scale-[0.94] flex-shrink-0",title:v("mobile.stopDevice"),"aria-label":v("mobile.stopDevice"),children:(0,n.jsx)(ev.M6,{size:14})}):o?null:(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),(0,eN.e)(),c?.(e)},className:"p-1.5 text-text-muted hover:text-brand-500 hover:bg-surface-2 rounded-brand transition-all duration-150 ease-out active:scale-[0.94] flex-shrink-0",title:v("mobile.startDevice"),"aria-label":v("mobile.startDevice"),children:(0,n.jsx)(ev.jG,{size:14})}),s&&"emulator"===e.kind&&e.avdName&&!o&&!r&&(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),(0,eN.e)(),w(y===e.id?null:e.id)},className:"p-1.5 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors flex-shrink-0","aria-label":v("mobile.avdMenu"),children:(0,n.jsx)(ev.Gv,{size:14})})]}),y===e.id&&(0,n.jsxs)("div",{className:"flex items-center gap-1 px-3 py-1.5 border-t border-border bg-surface-2/50",children:[(0,n.jsxs)("button",{onClick:()=>{(0,eN.e)(),k({kind:"wipe",avdName:e.avdName,name:e.name}),w(null)},className:"flex items-center gap-1.5 px-2 py-1 text-[11px] text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors",children:[(0,n.jsx)(ev.kt,{size:12})," ",v("mobile.avdWipe")]}),(0,n.jsx)("div",{className:"flex-1"}),(0,n.jsxs)("button",{onClick:()=>{(0,eN.e)(),k({kind:"delete",avdName:e.avdName,name:e.name}),w(null)},className:"flex items-center gap-1.5 px-2 py-1 text-[11px] text-text-muted hover:text-red-400 hover:bg-surface-2 rounded-brand transition-colors",children:[(0,n.jsx)(ev.TB,{size:12})," ",v("mobile.avdDelete")]})]})]},e.id)})}),s&&t.some(e=>"running"!==e.state)&&(0,n.jsxs)("button",{onClick:()=>{(0,eN.e)(),x?.(!m)},className:"w-full bg-surface rounded-brand-lg px-3 py-2 flex items-center gap-2.5 text-left hover:bg-surface-2 transition-colors",children:[(0,n.jsx)(ev.Kq,{size:15,className:m?"text-brand-500 dark:text-white flex-shrink-0":"text-text-muted flex-shrink-0"}),(0,n.jsxs)("div",{className:"flex flex-col min-w-0 flex-1",children:[(0,n.jsx)("span",{className:"text-sm text-text",children:v("mobile.lowPower")}),(0,n.jsx)("span",{className:"text-xs text-text-muted",children:v("mobile.lowPowerHint")})]}),(0,n.jsx)("span",{className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors border border-transparent flex-shrink-0 ${m?"bg-brand-500 dark:bg-white":"bg-surface-2 dark:border-white/15"}`,children:(0,n.jsx)("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${m?"translate-x-4 dark:bg-dark-800":"translate-x-0.5 dark:bg-white/50"}`})})]}),o&&(0,n.jsx)("p",{className:"text-red-400 text-xs text-center",children:o}),(0,n.jsx)(ek.A,{isOpen:!!j,onClose:()=>k(null),onConfirm:()=>{j&&("delete"===j.kind?h?.(j.avdName):f?.(j.avdName),k(null))},title:v(j?.kind==="delete"?"mobile.avdDeleteTitle":"mobile.avdWipeTitle"),message:v(j?.kind==="delete"?"mobile.avdDeleteMessage":"mobile.avdWipeMessage",{name:j?.name||""}),confirmText:v(j?.kind==="delete"?"common.delete":"mobile.avdWipe")})]})}function i_(e){if(!Number.isFinite(e)||e<=0)return"";let t=["B","KB","MB","GB"],s=0,n=e;for(;n>=1024&&s<t.length-1;)n/=1024,s++;return`${n>=10?Math.round(n):n.toFixed(1)} ${t[s]}`}function iK(e){let{isOpen:t,onClose:s,presets:l,sdkJob:a,onProvision:i,onCancel:o}=e,{t:c}=(0,eC.s)(),[d,u]=(0,r.useState)(null),[m,x]=(0,r.useState)(null),p=a&&"done"!==a.phase&&"error"!==a.phase?a:null,h=a?.phase==="error"&&"cancelled"!==a.error?a.error:null,f=(0,r.useCallback)(()=>{u(null),x(null),s?.()},[s]);if((0,r.useEffect)(()=>{if(!t||p)return;let e=e=>{"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),f())};return window.addEventListener("keydown",e,!0),()=>window.removeEventListener("keydown",e,!0)},[t,p,f]),!t||"u"<typeof document)return null;let b=async e=>{if(d||p)return;(0,eN.e)(),u(e.id),x(e);let t=await i?.(e.id);u(null),t&&f()};return(0,sp.createPortal)((0,n.jsx)("div",{className:"fixed inset-0 z-[100] flex items-center justify-center p-4 scrim fade-in",onClick:f,children:(0,n.jsxs)("div",{className:"card-elev w-full max-w-sm max-h-[80vh] flex flex-col pop-in",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-4 py-3 border-b border-border flex-shrink-0",children:[(0,n.jsx)(ev.wO,{size:15,className:"text-brand-500 dark:text-white flex-shrink-0"}),(0,n.jsx)("span",{className:"text-sm text-text flex-1",children:c("mobile.addDevice")}),(0,n.jsx)("button",{onClick:()=>{(0,eN.e)(),f()},className:"p-1 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand",children:(0,n.jsx)(ev.X,{size:15})})]}),(0,n.jsx)("div",{className:"p-3 space-y-1.5 overflow-y-auto modal-scrollable",children:p||h?(0,n.jsx)("div",{className:"flex flex-col items-center gap-3 py-8 px-4 text-center",children:h?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("p",{className:"text-red-400 text-xs",children:h}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[m&&(0,n.jsx)("button",{onClick:()=>b(m),className:"px-3 py-1.5 text-xs text-brand-500 bg-brand-500/10 dark:text-white dark:bg-white/10 rounded-brand",children:c("common.retry")}),(0,n.jsx)("button",{onClick:()=>{(0,eN.e)(),f()},className:"px-3 py-1.5 text-xs text-text-muted hover:text-text rounded-brand",children:c("common.close")})]})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(ev.kr,{size:20,className:"text-brand-500 animate-spin"}),(0,n.jsx)("p",{className:"text-text text-sm",children:c(function(e){if(e?.step)return`mobile.provisionStep_${e.step}`;let t=e?.component||"";return t.startsWith("system-images;")?"mobile.provisionStep_image":`mobile.provisionStep_${t}`}(p))}),(0,n.jsx)("p",{className:"text-text-muted text-xs",children:"image"===p.kind||"image"===p.step?`${p.percent??0}%`:`${i_(p.received)}${p.total?` / ${i_(p.total)}`:""}${p.bytesPerSec?` \xb7 ${i_(p.bytesPerSec)}/s`:""}`}),(0,n.jsx)("button",{onClick:()=>{(0,eN.e)(),o?.()},className:"px-3 py-1 text-[11px] text-text-muted hover:text-red-400 rounded-brand transition-colors",children:c("common.cancel")})]})}):(l||[]).map(e=>(0,n.jsxs)("button",{onClick:()=>b(e),className:"w-full flex items-center gap-2.5 px-3 py-2.5 bg-surface rounded-brand-lg hover:bg-surface-2 transition-colors text-left",children:["tablet"===e.id?(0,n.jsx)(ev.VA,{size:16,className:"text-brand-500 dark:text-white flex-shrink-0"}):(0,n.jsx)(ev.wO,{size:16,className:"text-brand-500 dark:text-white flex-shrink-0"}),(0,n.jsxs)("div",{className:"flex flex-col min-w-0 flex-1",children:[(0,n.jsx)("span",{className:"text-sm text-text truncate",children:e.label}),(0,n.jsx)("span",{className:"text-[10px] text-text-muted",children:e.ready?c("mobile.presetReady"):c("mobile.presetDownload")})]}),e.ready?(0,n.jsx)(ev.aJ,{size:13,className:"text-green-500 flex-shrink-0"}):(0,n.jsx)(ev.f5,{size:13,className:"text-text-muted flex-shrink-0"})]},e.id))})]})}),document.body)}function iW(e){let{apps:t,foreground:s,busy:l,progress:a,error:i,onInstall:o,onLaunch:c,onStopApp:d,onClearData:u,onUninstall:m,onOpenLink:x,onRefresh:p}=e,{t:h}=(0,eC.s)(),f=(0,r.useRef)(null),[b,g]=(0,r.useState)(!1),[v,y]=(0,r.useState)(""),w=(0,r.useCallback)(e=>{let t=[...e||[]].find(e=>e.name.toLowerCase().endsWith(".apk"));t&&o?.(t)},[o]),j=(0,r.useCallback)(e=>{e.preventDefault(),g(!1),w(e.dataTransfer?.files)},[w]),k="install"===l;return(0,n.jsxs)("div",{className:"h-full overflow-y-auto modal-scrollable p-3 space-y-3",onDragOver:e=>{e.preventDefault(),g(!0)},onDragLeave:()=>g(!1),onDrop:j,children:[(0,n.jsx)("button",{onClick:()=>{(0,eN.e)(),f.current?.click()},disabled:k,className:`w-full rounded-brand-lg border border-dashed px-3 py-5 flex flex-col items-center gap-1.5 transition-colors duration-150 ${b?"border-brand-500 bg-brand-500/5":"border-border hover:border-brand-500/50"} disabled:opacity-60`,children:k?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(ev.kr,{size:20,className:"text-brand-500 animate-spin"}),(0,n.jsx)("span",{className:"text-sm text-text",children:h("mobile.installing")}),a>0&&(0,n.jsx)("div",{className:"w-full max-w-[180px] h-1 bg-surface-2 rounded-full overflow-hidden mt-1",children:(0,n.jsx)("div",{className:"h-full bg-brand-500 transition-[width] duration-150",style:{width:`${Math.round(100*a)}%`}})})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(ev._O,{size:20,className:"text-text-muted"}),(0,n.jsx)("span",{className:"text-sm text-text",children:h("mobile.dropApk")}),(0,n.jsx)("span",{className:"text-xs text-text-muted",children:h("mobile.dropApkHint")})]})}),(0,n.jsx)("input",{ref:f,type:"file",accept:".apk,application/vnd.android.package-archive",className:"hidden",onChange:e=>{w(e.target.files),e.target.value=""}}),(0,n.jsxs)("form",{onSubmit:e=>{e.preventDefault(),v.trim()&&(x?.(v.trim()),y(""))},className:"flex items-center gap-1.5",children:[(0,n.jsxs)("div",{className:"flex-1 flex items-center gap-2 bg-surface rounded-brand px-2.5 py-1.5",children:[(0,n.jsx)(ev.vv,{size:14,className:"text-text-muted flex-shrink-0"}),(0,n.jsx)("input",{value:v,onChange:e=>y(e.target.value),placeholder:h("mobile.deepLinkPlaceholder"),className:"flex-1 bg-transparent text-sm text-text placeholder:text-text-muted focus:outline-none min-w-0",autoCapitalize:"none",autoCorrect:"off",spellCheck:!1})]}),(0,n.jsx)("button",{type:"submit",disabled:!v.trim(),className:"px-2.5 py-1.5 text-sm text-text bg-surface hover:bg-surface-2 rounded-brand transition-all duration-150 ease-out active:scale-[0.97] disabled:opacity-40",children:h("common.open")})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2 pt-1",children:[(0,n.jsx)("span",{className:"text-xs text-text-muted flex-1",children:h("mobile.installedApps")}),(0,n.jsx)("button",{onClick:()=>{(0,eN.e)(),p?.()},className:"p-1 text-text-muted hover:text-text rounded-brand transition-colors",title:h("common.refresh"),"aria-label":h("common.refresh"),children:(0,n.jsx)(ev.e9,{size:13})})]}),0===t.length&&(0,n.jsx)("p",{className:"text-text-muted text-xs text-center py-4",children:h("mobile.noApps")}),(0,n.jsx)("div",{className:"space-y-1",children:t.map(e=>{let t=s?.packageName===e.packageName,r=l===e.packageName;return(0,n.jsxs)("div",{className:"bg-surface rounded-brand px-2.5 py-2 flex items-center gap-2",children:[(0,n.jsx)(ev.lP,{size:14,className:t?"text-brand-500 flex-shrink-0":"text-text-muted flex-shrink-0"}),(0,n.jsx)("span",{className:"text-sm text-text truncate flex-1",title:e.packageName,children:e.packageName}),r?(0,n.jsx)(ev.kr,{size:14,className:"text-brand-500 animate-spin flex-shrink-0"}):(0,n.jsxs)("div",{className:"flex items-center gap-0.5 flex-shrink-0",children:[e.launchable&&(0,n.jsx)("button",{onClick:()=>{(0,eN.e)(),c?.(e.packageName)},className:"p-1.5 text-text-muted hover:text-brand-500 hover:bg-surface-2 rounded-brand transition-colors",title:h("mobile.launch"),"aria-label":h("mobile.launch"),children:(0,n.jsx)(ev.jG,{size:13})}),t&&(0,n.jsx)("button",{onClick:()=>{(0,eN.e)(),d?.(e.packageName)},className:"p-1.5 text-text-muted hover:text-amber-400 hover:bg-surface-2 rounded-brand transition-colors",title:h("mobile.forceStop"),"aria-label":h("mobile.forceStop"),children:(0,n.jsx)(ev.M6,{size:13})}),(0,n.jsx)("button",{onClick:()=>{(0,eN.e)(),u?.(e.packageName)},className:"p-1.5 text-text-muted hover:text-amber-400 hover:bg-surface-2 rounded-brand transition-colors",title:h("mobile.clearData"),"aria-label":h("mobile.clearData"),children:(0,n.jsx)(ev.e9,{size:13})}),(0,n.jsx)("button",{onClick:()=>{(0,eN.e)(),m?.(e.packageName)},className:"p-1.5 text-text-muted hover:text-red-400 hover:bg-surface-2 rounded-brand transition-colors",title:h("mobile.uninstall"),"aria-label":h("mobile.uninstall"),children:(0,n.jsx)(ev.TB,{size:13})})]})]},e.packageName)})}),i&&(0,n.jsx)("p",{className:"text-red-400 text-xs",children:i})]})}function iH(e){let{logcat:t,apps:s}=e,{lines:l,clear:a,minLevel:i,setMinLevel:o,search:c,setSearch:d,packageName:u,setPackageName:m,paused:x,setPaused:p,includeNoise:h,setIncludeNoise:f}=t,{t:b}=(0,eC.s)(),g=(0,r.useRef)(null),[v,y]=(0,r.useState)(!0),w=()=>{y(!0)};return(0,r.useLayoutEffect)(()=>{v&&g.current&&(g.current.scrollTop=g.current.scrollHeight)},[l,v]),(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1.5 border-b border-border flex-shrink-0 flex-wrap",children:[(0,n.jsxs)("select",{value:u||"",onChange:e=>{(0,eN.e)(),m(e.target.value||null),w()},className:"bg-surface-2 text-text text-xs rounded-brand px-1.5 py-1 focus:outline-none max-w-[40%]",title:b("mobile.filterByApp"),children:[(0,n.jsx)("option",{value:"",children:b("mobile.allApps")}),s.map(e=>(0,n.jsx)("option",{value:e.packageName,children:e.packageName},e.packageName))]}),(0,n.jsx)("select",{value:i,onChange:e=>{(0,eN.e)(),o(e.target.value),w()},className:"bg-surface-2 text-text text-xs rounded-brand px-1.5 py-1 focus:outline-none",title:b("mobile.minLevel"),children:el.map(e=>(0,n.jsx)("option",{value:e,children:e},e))}),(0,n.jsxs)("div",{className:"flex items-center gap-1 bg-surface-2 rounded-brand px-1.5 py-1 flex-1 min-w-[90px]",children:[(0,n.jsx)(ev.vj,{size:12,className:"text-text-muted flex-shrink-0"}),(0,n.jsx)("input",{value:c,onChange:e=>d(e.target.value),placeholder:b("common.search"),className:"bg-transparent text-xs text-text placeholder:text-text-muted focus:outline-none w-full min-w-0",autoCapitalize:"none",autoCorrect:"off",spellCheck:!1})]}),(0,n.jsx)("button",{onClick:()=>{(0,eN.e)(),p(!x)},className:`p-1.5 rounded-brand transition-colors ${x?"text-brand-500 bg-surface-2":"text-text-muted hover:text-text"}`,title:b(x?"mobile.resumeLog":"mobile.pauseLog"),"aria-label":b(x?"mobile.resumeLog":"mobile.pauseLog"),children:x?(0,n.jsx)(ev.jG,{size:13}):(0,n.jsx)(ev.vR,{size:13})}),(0,n.jsx)("button",{onClick:()=>{(0,eN.e)(),f(!h),w()},className:`p-1.5 rounded-brand transition-colors ${h?"text-amber-400 bg-surface-2":"text-text-muted hover:text-text"}`,title:b(h?"mobile.hideNoise":"mobile.showNoise"),"aria-label":b(h?"mobile.hideNoise":"mobile.showNoise"),children:(0,n.jsx)(ev.dJ,{size:13})}),(0,n.jsx)("button",{onClick:()=>{let e;(0,eN.e)(),e=l.map(e=>`${e.time} ${e.level} ${e.tag}: ${e.message}`).join("\n"),navigator.clipboard?.writeText(e)},className:"p-1.5 text-text-muted hover:text-text rounded-brand transition-colors",title:b("common.clipboardCopy"),"aria-label":b("common.clipboardCopy"),children:(0,n.jsx)(ev.QR,{size:13})}),(0,n.jsx)("button",{onClick:()=>{(0,eN.e)(),a()},className:"p-1.5 text-text-muted hover:text-red-400 rounded-brand transition-colors",title:b("mobile.clearLog"),"aria-label":b("mobile.clearLog"),children:(0,n.jsx)(ev.TB,{size:13})})]}),(0,n.jsxs)("div",{ref:g,onScroll:()=>{let e=g.current;e&&y(e.scrollHeight-e.scrollTop-e.clientHeight<40)},className:"flex-1 overflow-auto modal-scrollable font-mono text-[11px] leading-[1.45] p-2",children:[0===l.length&&(0,n.jsx)("p",{className:"text-text-muted text-xs text-center py-6 font-sans",children:b("mobile.noLogs")}),l.map(e=>(0,n.jsxs)("div",{className:"whitespace-pre-wrap break-all",children:[(0,n.jsx)("span",{className:"text-text-muted/60",children:e.time})," ",(0,n.jsx)("span",{className:ea[e.level]||"text-text",children:e.level})," ",(0,n.jsx)("span",{className:"text-brand-500/70",children:e.tag}),e.tag?": ":"",(0,n.jsx)("span",{className:ea[e.level]||"text-text",children:e.message})]},e.seq))]}),x&&(0,n.jsx)("div",{className:"px-2 py-1 text-[11px] text-amber-400 bg-amber-400/10 flex-shrink-0 text-center",children:b("mobile.logPaused")})]})}function iq(e){let{onClose:t,busRef:s,protocolRef:l,connected:a,variant:i="fullscreen"}=e,{t:o}=(0,eC.s)(),c=(0,r.useRef)(null),[d,u]=(0,r.useState)(null),[m,x]=(0,r.useState)(!1),[p,h]=(0,r.useState)(!1),b=function(e){let{busRef:t,connected:s}=e,[n,l]=(0,r.useState)([]),[a,i]=(0,r.useState)(!1),[o,c]=(0,r.useState)(null),[d,u]=(0,r.useState)(()=>new Set),[m,x]=(0,r.useState)(null),[p,h]=(0,r.useState)(!1),[b,g]=(0,r.useState)(null),v=(0,f.B)(e=>e.mobileLowPower),y=(0,f.B)(e=>e.setMobileLowPower),w=(0,r.useCallback)(async()=>{let e=t?.current;if(!e||!s)return[];let n=await ei(e,"mobile:list",{});if(!n?.success)return[];h(!0),i(!!n.canManageEmulators),n.env&&g(n.env.job||null);let r=Array.isArray(n.devices)?n.devices:[];return l(r),u(e=>{let t=new Set(r.map(e=>e.serial).filter(Boolean));for(let s of e)if(t.has(s))return e;let s=new Set([...e].filter(e=>t.has(e)));return s.size===e.size?e:s}),r},[t,s]);(0,r.useEffect)(()=>{let e=t?.current;if(!e||!s)return;let n=e=>{let{avdName:t,phase:s}=e;return c({avdName:t,phase:s})};e.on("mobile:avdProgress",n);let r=e=>{g(e),("done"===e.phase||"error"===e.phase)&&w()};return e.on("mobile:sdkProgress",r),()=>{e.off("mobile:avdProgress",n),e.off("mobile:sdkProgress",r)}},[t,s,w]),(0,r.useEffect)(()=>{if(!s)return;w();let e=setInterval(w,5e3);return()=>clearInterval(e)},[s,w]);let j=(0,r.useCallback)(async e=>{x(null),c({avdName:e,phase:"launching"});let s=await ei(t?.current,"mobile:avdStart",{avdName:e,lowPower:v});return(c(null),await w(),s?.success)?s.serial:(x(s?.error||"Could not start"),null)},[t,w,v]),k=(0,r.useCallback)(async e=>{if(!e)return!1;x(null),u(t=>new Set(t).add(e));let s=await ei(t?.current,"mobile:avdStop",{serial:e});return await w(),u(t=>{let s=new Set(t);return s.delete(e),s}),s?.success||x(s?.error||"Could not stop"),s?.success},[t,w]),[N,C]=(0,r.useState)([]),S=(0,r.useCallback)(async()=>{let e=await ei(t?.current,"mobile:provisionPresets",{});e?.success&&C(Array.isArray(e.presets)?e.presets:[])},[t]),T=(0,r.useCallback)(async e=>{x(null);let s=await ei(t?.current,"mobile:provision",{presetId:e});return await Promise.all([w(),S()]),!!s?.success||(x(s?.error||"Could not create device"),!1)},[t,w,S]),E=(0,r.useCallback)(async()=>{await ei(t?.current,"mobile:sdkCancel",{}),await w()},[t,w]),R=(0,r.useCallback)(async e=>{let s=await ei(t?.current,"mobile:avdDelete",{avdName:e});return s?.success||x(s?.error||"Could not delete"),await w(),s?.success},[t,w]),M=(0,r.useCallback)(async e=>{let s=await ei(t?.current,"mobile:avdWipe",{avdName:e});return s?.success||x(s?.error||"Could not wipe"),await w(),s?.success},[t,w]);return{devices:n,canManage:a,booting:o,error:m,setError:x,refresh:w,startAvd:j,stopAvd:k,stopping:d,lowPower:v,setLowPower:y,sdkJob:b,presets:N,refreshPresets:S,provision:T,cancelSetup:E,deleteAvd:R,wipeAvd:M,loaded:p}}({busRef:s,connected:a}),{devices:g,canManage:v,booting:y,refresh:w,startAvd:j,stopAvd:k,stopping:N,lowPower:C,setLowPower:S,sdkJob:T,presets:E,refreshPresets:R,provision:M,cancelSetup:$,deleteAvd:z,wipeAvd:P}=b,{serial:A,meta:I,starting:D,error:L,open:B,stop:F,cancel:O}=function(e){let{busRef:t,connected:s,devices:n,startAvd:l,stopAvd:a,stopping:i}=e,o=(0,f.B)(e=>e.mobileSession),c=(0,f.B)(e=>e.setMobileSession),d=o?.serial??null,u=o?.meta??null,[m,x]=(0,r.useState)(!1),[p,h]=(0,r.useState)(null),b=(0,r.useRef)(!1),g=(0,r.useRef)(!1),v=(0,r.useRef)(new Set);(0,r.useEffect)(()=>{u&&(b.current=!0)},[u]);let y=(0,r.useCallback)(()=>{t?.current?.emit("mobile:stop"),b.current=!1,c(null)},[t,c]),w=(0,r.useCallback)(()=>{g.current=!0,y()},[y]),j=(0,r.useCallback)(async e=>{let s=Math.max(window.innerWidth,window.innerHeight),n=window.devicePixelRatio,r=await ei(t?.current,"mobile:start",{serial:e,options:function(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,n=en[e]||en[er],r=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,n=Math.min(1600,Math.max(640,Math.round(e*Math.min(t||1,3)*s)));return n-n%8}(t,s,n.edgeScale),l=r*Math.round(.45*r);return{maxSize:r,bitRate:Math.min(n.maxBitRate,Math.round(l*n.maxFps*n.bitsPerPixel)),maxFps:n.maxFps}}(er,s,n)});if(!r?.success)throw Error(r?.error||"Failed to start");return b.current=!0,c({serial:e,meta:r.meta}),r.meta},[t,c]),k=(0,r.useCallback)(async e=>{if(e){g.current=!1,x(!0),h(null),v.current.add(e.id);try{let t=e.serial||(e.avdName?await l(e.avdName):null);if(g.current){t&&a?.(t);return}if(!t)throw Error("Device did not start");await j(t),g.current&&(y(),t&&a?.(t))}catch(e){g.current||h(e.message)}finally{x(!1)}}},[l,j,a,y]);return(0,r.useEffect)(()=>{if(u||m||d)return;let e=n.filter(e=>"running"===e.state);if(1!==e.length||1!==n.length)return;let t=e[0];if(v.current.has(t.id)||i?.has(t.serial))return;let s=setTimeout(()=>k(t),0);return()=>clearTimeout(s)},[n,u,m,d,k,i]),(0,r.useEffect)(()=>{let e=t?.current;if(!e||!s)return;let n=e=>{let{meta:t}=e;t&&c(e=>e?{...e,meta:t}:e)};return e.on("mobile:resized",n),()=>e.off("mobile:resized",n)},[t,s,c]),(0,r.useEffect)(()=>{!s&&b.current&&(b.current=!1,c(null))},[s,c]),{serial:d,meta:u,starting:m,error:p,setError:h,open:k,stop:y,cancel:w}}({busRef:s,connected:a,devices:g,startAvd:j,stopAvd:k,stopping:N}),{status:_,fps:K}=function(e){let{busRef:t,connected:s,canvasRef:n,meta:l}=e,[a,i]=(0,r.useState)("idle"),[o,c]=(0,r.useState)(0),d=(0,r.useRef)(null),u=(0,r.useCallback)(()=>{let e=d.current,s=performance.now();e&&s-e.lastKeyframeReq<1e3||(e&&(e.lastKeyframeReq=s),t?.current?.emit("mobile:keyframe"))},[t]);return(0,r.useEffect)(()=>{let e=t?.current;if(!e||!s||!l||!iL)return;let r={decoder:null,pending:new Map,queue:[],raf:0,sawKey:!1,dropping:!1,lastKeyframeReq:0,ackedSeq:-1,config:null,frameCount:0,fpsAt:performance.now()};d.current=r,i("connecting");let a=()=>{if(r.decoder&&"closed"!==r.decoder.state)try{r.decoder.close()}catch{}for(let e of(r.decoder=null,r.sawKey=!1,r.queue))e.close();r.queue=[]},o=()=>{r.raf=0;let e=n.current;for(;r.queue.length>1;)r.queue.shift()?.close();let t=r.queue.shift();if(!t)return;let s=e?.getContext("2d",{alpha:!1,desynchronized:!0});s&&s.drawImage(t,0,0,e.width,e.height),t.close(),r.frameCount++;let l=performance.now();l-r.fpsAt>=1e3&&(c(Math.round(1e3*r.frameCount/(l-r.fpsAt))),r.frameCount=0,r.fpsAt=l),r.queue.length&&(r.raf=requestAnimationFrame(o))},m=()=>{a(),r.dropping=!0,u()},x=e=>{if(r.decoder?.state==="configured")return!0;a();let t=new VideoDecoder({output:e=>{r.decoder!==t?e.close():(r.queue.length>=3&&r.queue.shift()?.close(),r.queue.push(e),r.raf||(r.raf=requestAnimationFrame(o)))},error:()=>{r.decoder===t&&m()}});try{let s;return t.configure({codec:(s=e=>e.toString(16).padStart(2,"0"),`avc1.${s(e[1])}${s(e[2])}${s(e[3])}`),optimizeForLatency:!0}),r.decoder=t,!0}catch{try{t.close()}catch{}return i("decoder failed"),u(),!1}},p=e=>{let{data:t,isKey:s,isConfig:n,ptsMs:l}=e,a=t;if(n){r.config=a;let e=iD(a).spsBytes;e&&x(e);return}if(s&&r.decoder?.state!=="configured"){if(!r.config)return void u();let e=iD(r.config).spsBytes;if(!e||!x(e))return}if(s&&r.config){let e=new Uint8Array(r.config.byteLength+a.byteLength);e.set(r.config,0),e.set(a,r.config.byteLength),a=e}if(r.dropping){if(!s||r.decoder?.state!=="configured")return void u();r.dropping=!1}if(r.decoder?.state!=="configured"){s||u();return}if(r.decoder.decodeQueueSize>30)return void(r.dropping=!0,u());if(!r.sawKey){if(!s)return void u();r.sawKey=!0,i("streaming")}try{r.decoder.decode(new EncodedVideoChunk({type:s?"key":"delta",timestamp:1e3*l,data:a}))}catch{m()}},h=t=>{t<=r.ackedSeq||(r.ackedSeq=t,e.emit("mobile:ack",{seq:t}))},f=e=>{let t=function(e){let t=e instanceof ArrayBuffer?new Uint8Array(e):e;if(t.byteLength<18)return null;let s=new DataView(t.buffer,t.byteOffset,t.byteLength);if(0xffffffff!==s.getUint32(0))return null;let n=s.getUint8(12);return{frameSeq:s.getUint32(4),chunkIdx:s.getUint16(8),chunkCount:s.getUint16(10),isKey:(1&n)!=0,isConfig:(2&n)!=0,ptsMs:s.getUint32(14),payload:t.slice(18)}}(e);if(!t)return;if(1===t.chunkCount){h(t.frameSeq),p({data:t.payload,isKey:t.isKey,isConfig:t.isConfig,ptsMs:t.ptsMs});return}let s=r.pending.get(t.frameSeq);if(!s)for(let e of(s={chunks:Array(t.chunkCount),received:0,count:t.chunkCount,isKey:t.isKey,isConfig:t.isConfig,ptsMs:t.ptsMs},r.pending.set(t.frameSeq,s),r.pending.keys()))t.frameSeq-e>96&&r.pending.delete(e);if(s.chunks[t.chunkIdx]||(s.chunks[t.chunkIdx]=t.payload,s.received++,s.received!==s.count))return;r.pending.delete(t.frameSeq),h(t.frameSeq);let n=new Uint8Array(s.chunks.reduce((e,t)=>e+t.byteLength,0)),l=0;for(let e of s.chunks)n.set(e,l),l+=e.byteLength;p({data:n,isKey:s.isKey,isConfig:s.isConfig,ptsMs:s.ptsMs})},b=()=>i("ended");return e.on("mobile-bin",f),e.on("file-bin",f),e.on("mobile:ended",b),u(),()=>{e.off("mobile-bin",f),e.off("file-bin",f),e.off("mobile:ended",b),r.raf&&cancelAnimationFrame(r.raf),a(),r.pending.clear(),d.current=null}},[t,s,n,l,u]),(0,r.useEffect)(()=>{let e=t?.current;if(!e||!s||!l)return;let n=()=>{let t=!document.hidden;e.emit("mobile:visible",{visible:t}),t&&u()};return document.addEventListener("visibilitychange",n),e.emit("mobile:visible",{visible:!document.hidden}),()=>document.removeEventListener("visibilitychange",n)},[t,s,l,u]),{status:iL?a:"unsupported",fps:o,requestKeyframe:u}}({busRef:s,connected:a,canvasRef:c,meta:I}),W=function(e){let{busRef:t,canvasRef:s}=e,n=(0,r.useRef)(null),l=(0,r.useRef)(null),a=(0,r.useRef)(0),i=(0,r.useCallback)(e=>{t?.current?.emit("mobile:input",e)},[t]),o=(0,r.useCallback)(()=>{a.current=0;let e=l.current;e&&(l.current=null,i({type:"touch",action:"move",...e}))},[i]),c=(0,r.useCallback)(e=>{let t=s.current;if(!t)return null;let n=t.getBoundingClientRect(),r=Math.min(n.width/t.width,n.height/t.height),l=t.width*r,a=t.height*r,i=n.left+(n.width-l)/2,o=n.top+(n.height-a)/2,c=(e.clientX-i)/l,d=(e.clientY-o)/a;return c<0||c>1||d<0||d>1?null:{x:c,y:d}},[s]),d=(0,r.useCallback)(e=>{let t=c(e);t&&(e.currentTarget.setPointerCapture?.(e.pointerId),n.current=t,i({type:"touch",action:"down",...t}))},[i,c]),u=(0,r.useCallback)(e=>{if(!n.current)return;let t=c(e);t&&(l.current=t,a.current||(a.current=requestAnimationFrame(o)))},[o,c]),m=(0,r.useCallback)(e=>{let t=c(e);if(!t)return;e.preventDefault();let s=1===e.deltaMode?16:2===e.deltaMode?400:1,n=e=>Math.max(-16,Math.min(16,-(e*s)/100));i({type:"scroll",...t,hscroll:n(e.deltaX),vscroll:n(e.deltaY)})},[i,c]),x=(0,r.useCallback)(e=>{let t=n.current;t&&(n.current=null,l.current=null,a.current&&(cancelAnimationFrame(a.current),a.current=0),i({type:"touch",action:"up",...c(e)||{x:t.x,y:t.y}}))},[i,c]);return{onPointerDown:d,onPointerMove:u,onPointerUp:x,onPointerCancel:x,onWheel:m,sendKey:(0,r.useCallback)(e=>i({type:"key",name:e}),[i])}}({busRef:s,canvasRef:c}),H=function(e){let{busRef:t,protocolRef:s,serial:n,enabled:l}=e,[a,i]=(0,r.useState)([]),[o,c]=(0,r.useState)(null),[d,u]=(0,r.useState)(null),[m,x]=(0,r.useState)(0),[p,h]=(0,r.useState)(null),f=(0,r.useCallback)(async()=>{if(!n||!l)return;let e=await ei(t?.current,"mobile:apps",{serial:n});e?.success&&(i(e.apps||[]),c(e.foreground||null))},[t,n,l]);(0,r.useEffect)(()=>{f()},[f]);let b=(0,r.useCallback)(async(e,s,r)=>{u(s),h(null);let l=await ei(t?.current,e,{serial:n,packageName:s});return(u(null),l?.success)?(r&&await f(),!0):(h(l?.error||"Failed"),!1)},[t,n,f]),g=(0,r.useCallback)(e=>b("mobile:launch",e),[b]),v=(0,r.useCallback)(e=>b("mobile:stopApp",e),[b]),y=(0,r.useCallback)(e=>b("mobile:clearApp",e),[b]),w=(0,r.useCallback)(e=>b("mobile:uninstall",e,!0),[b]),j=(0,r.useCallback)(async e=>{if(e&&n){u("install"),h(null),x(0);try{let r=await ei(t?.current,"mobile:apkStage",{name:e.name,size:e.size});if(!r?.success)throw Error(r?.error||"Cannot stage APK");let l=null;if(await ed({bus:t?.current,protocolRef:s,targetDir:r.targetDir,items:[{file:e,relativePath:r.fileName}],callbacks:{onProgress:(e,t,s)=>x(s?t/s:0),onError:(e,t)=>{l=t}}}),l)throw l;let a=await ei(t?.current,"mobile:install",{serial:n,fileName:r.fileName,launch:!0});if(!a?.success)throw Error(a?.error||"Install failed");return await f(),a.packageName}catch(e){return h(e.message),null}finally{u(null),x(0)}}},[t,s,n,f]),k=(0,r.useCallback)(async e=>{h(null);let s=await ei(t?.current,"mobile:openLink",{serial:n,url:e});return s?.success||h(s?.error||"Could not open link"),s?.success},[t,n]);return{apps:a,foreground:o,busy:d,progress:m,error:p,setError:h,refresh:f,install:j,launch:g,stopApp:v,clearData:y,uninstall:w,openLink:k}}({busRef:s,protocolRef:l,serial:A,enabled:!!I}),q=function(e){let{busRef:t,serial:s,active:n,foregroundPackage:l}=e,[a,i]=(0,r.useState)([]),[o,c]=(0,r.useState)("I"),[d,u]=(0,r.useState)(""),[m,x]=(0,r.useState)(null),p=(0,r.useRef)(!1);(0,r.useEffect)(()=>{!p.current&&l&&x(l)},[l]);let h=(0,r.useCallback)(e=>{p.current=!0,x(e)},[]),[f,b]=(0,r.useState)(!1),[g,v]=(0,r.useState)(!1),y=(0,r.useRef)(0),w=(0,r.useRef)(!1);(0,r.useEffect)(()=>{w.current=f},[f]);let j=(0,r.useCallback)(()=>i([]),[]);return(0,r.useEffect)(()=>{let e=t?.current;if(!e||!s||!n)return;i([]);let r=e=>{let{lines:t}=e;!w.current&&Array.isArray(t)&&i(e=>{let s=e.concat(t.map(e=>{var t;let s;return t=y.current++,(s=iB.exec(e))?{seq:t,time:s[1].slice(6),level:s[2],tag:s[3].trim(),message:s[4]}:{seq:t,time:"",level:"V",tag:"",message:e}}));return s.length>5e3?s.slice(s.length-5e3):s})};return e.on("mobile:logcat",r),ei(e,"mobile:logcatStart",{serial:s,minLevel:o,search:d,includeNoise:g,...p.current||m?{packageName:m}:{}}),()=>{e.off("mobile:logcat",r),e.emit("mobile:logcatStop")}},[t,s,n]),(0,r.useEffect)(()=>{if(!n||!s)return;let e=setTimeout(()=>{t?.current?.emit("mobile:logcatFilter",{minLevel:o,search:d,packageName:m,includeNoise:g})},200);return()=>clearTimeout(e)},[o,d,m,g,n,s,t]),{lines:a,clear:j,minLevel:o,setMinLevel:c,search:d,setSearch:u,packageName:m,setPackageName:h,paused:f,setPaused:b,includeNoise:g,setIncludeNoise:v}}({busRef:s,serial:A,active:!!I&&"logs"===d,foregroundPackage:H.foreground?.packageName});(0,r.useEffect)(()=>{let e=c.current;e&&I&&(e.width=I.width,e.height=I.height)},[I]);let U="panel"===i,X=g.find(e=>e.serial===A)||null,V=(0,r.useCallback)(async()=>{x(!1),F(),A&&await k(A)},[A,F,k]),G=(0,r.useCallback)(async e=>{e.serial===A&&F(),await k(e.serial)},[A,F,k]),J=(0,r.useCallback)(()=>{U||F(),t?.()},[U,F,t]),Y=(0,r.useCallback)(()=>{let e=g.find(e=>e.serial===A);e&&B(e)},[g,A,B]);if(!I){let e;return(0,n.jsxs)("div",{className:"absolute inset-0 flex flex-col bg-bg",children:[!U&&(0,n.jsxs)("header",{className:"flex items-center gap-2 px-2 py-1.5 border-b border-border flex-shrink-0",children:[(0,n.jsx)("button",{onClick:()=>{(0,eN.e)(),J()},className:"p-1.5 text-text hover:bg-surface-2 rounded-brand transition-all duration-150 ease-out active:scale-[0.94]","aria-label":o("common.back"),children:(0,n.jsx)(ev.JG,{size:18})}),(0,n.jsx)(ev.wO,{size:16,className:"text-brand-500 flex-shrink-0"}),(0,n.jsx)("span",{className:"text-sm text-text truncate",children:o("mobile.title")})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto modal-scrollable flex items-center justify-center",children:D||y?(0,n.jsxs)("div",{className:"flex flex-col items-center gap-3 p-6 text-center",children:[(0,n.jsx)(ev.kr,{size:22,className:"text-brand-500 animate-spin"}),(0,n.jsx)("p",{className:"text-text text-sm",children:y?(e=y.phase,o(`mobile.phase${e.charAt(0).toUpperCase()}${e.slice(1)}`)):o("mobile.starting")}),y&&(0,n.jsx)("p",{className:"text-text-muted text-xs",children:y.avdName}),(0,n.jsx)("button",{onClick:()=>{(0,eN.e)(),O()},className:"px-3 py-1.5 text-xs text-text-muted bg-surface hover:bg-surface-2 rounded-brand transition-colors",children:o("common.cancel")})]}):iL?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(iO,{devices:g,canManage:v,booting:y,stopping:N,loading:!b.loaded,error:L||b.error,onOpen:B,onStop:G,onRefresh:w,lowPower:C,onLowPowerChange:S,onAddDevice:()=>{R(),h(!0)},onDeleteAvd:z,onWipeAvd:P,sdkJob:T,onShowSetup:()=>h(!0)}),(0,n.jsx)(iK,{isOpen:p,onClose:()=>h(!1),presets:E,sdkJob:T,onProvision:M,onCancel:$})]}):(0,n.jsx)("p",{className:"text-text-muted text-sm max-w-xs text-center p-6",children:o("mobile.unsupportedBrowser")})})]})}return(0,n.jsxs)("div",{className:"absolute inset-0 flex bg-bg",children:[(0,n.jsx)(ek.A,{isOpen:m,onClose:()=>x(!1),onConfirm:V,title:o("mobile.shutdownTitle"),message:o("mobile.shutdownMessage",{name:I.deviceName}),confirmText:o("mobile.shutdownConfirm")}),(0,n.jsxs)("div",{className:"flex-1 min-w-0 relative flex items-center justify-center bg-black",children:[(0,n.jsx)("canvas",{ref:c,onPointerDown:W.onPointerDown,onPointerMove:W.onPointerMove,onPointerUp:W.onPointerUp,onPointerCancel:W.onPointerCancel,onWheel:W.onWheel,className:"max-w-full max-h-full object-contain touch-none"}),("connecting"===_||"idle"===_)&&(0,n.jsx)("div",{className:"absolute inset-0 flex items-center justify-center pointer-events-none",children:(0,n.jsx)(ev.kr,{size:22,className:"text-brand-500 animate-spin"})}),("ended"===_||"decoder failed"===_)&&(0,n.jsxs)("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-3 px-6 text-center bg-black/40",children:[(0,n.jsx)("p",{className:"text-text text-sm",children:o("ended"===_?"mobile.streamEnded":"mobile.streamFailed")}),X?(0,n.jsx)("button",{onClick:()=>{(0,eN.e)(),Y()},className:"px-3 py-1.5 text-xs text-brand-500 bg-surface hover:bg-surface-2 rounded-brand transition-colors",children:o("mobile.retry")}):(0,n.jsx)("p",{className:"text-text-muted text-xs",children:o("mobile.streamGone")})]}),"streaming"===_&&K>0&&(0,n.jsxs)("span",{className:"absolute top-2 right-2 px-1.5 py-0.5 rounded bg-black/50 text-[10px] text-white/80 pointer-events-none",children:[K," fps"]}),d&&(0,n.jsx)("button",{onClick:()=>{(0,eN.e)(),u(null)},className:"absolute inset-x-0 top-0 h-16 z-10 cursor-pointer","aria-label":o("mobile.backToScreen")}),d&&(0,n.jsxs)("div",{className:"absolute inset-x-0 bottom-0 top-16 bg-bg border-t border-border flex flex-col shadow-[0_-8px_24px_rgba(0,0,0,0.35)] sheet-rise",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-2.5 py-1.5 border-b border-border flex-shrink-0",children:["apps"===d?(0,n.jsx)(ev.lP,{size:14,className:"text-brand-500 flex-shrink-0"}):(0,n.jsx)(ev.iU,{size:14,className:"text-brand-500 flex-shrink-0"}),(0,n.jsx)("span",{className:"text-xs text-text flex-1 truncate",children:o("apps"===d?"mobile.tabApps":"mobile.tabLogs")}),(0,n.jsx)("button",{onClick:()=>{(0,eN.e)(),u(null)},className:"p-1 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors",title:o("mobile.backToScreen"),"aria-label":o("mobile.backToScreen"),children:(0,n.jsx)(ev.X,{size:14})})]}),"apps"===d?(0,n.jsx)(iW,{apps:H.apps,foreground:H.foreground,busy:H.busy,progress:H.progress,error:H.error,onInstall:H.install,onLaunch:H.launch,onStopApp:H.stopApp,onClearData:H.clearData,onUninstall:H.uninstall,onOpenLink:H.openLink,onRefresh:H.refresh}):(0,n.jsx)(iH,{logcat:q,apps:H.apps})]},d)]}),(0,n.jsxs)("div",{className:"flex flex-col items-center gap-0.5 px-1 py-1.5 pb-safe border-l border-border flex-shrink-0 overflow-y-auto modal-scrollable",children:[(0,n.jsx)(iU,{icon:(0,n.jsx)(ev.lM,{size:15,className:"-rotate-90"}),label:o("mobile.back"),onClick:()=>W.sendKey("back")}),(0,n.jsx)(iU,{icon:(0,n.jsx)(ev.jl,{size:15}),label:o("mobile.home"),onClick:()=>W.sendKey("home")}),(0,n.jsx)(iU,{icon:(0,n.jsx)(ev.M6,{size:14}),label:o("mobile.recents"),onClick:()=>W.sendKey("recents")}),(0,n.jsx)("div",{className:"w-5 h-px bg-border my-1"}),(0,n.jsx)(iU,{icon:(0,n.jsx)(ev.LM,{size:15}),label:o("mobile.power"),onClick:()=>W.sendKey("power")}),(0,n.jsx)("div",{className:"w-5 h-px bg-border my-1"}),(0,n.jsx)(iU,{icon:(0,n.jsx)(ev.lP,{size:15}),label:o("mobile.tabApps"),onClick:()=>u("apps"===d?null:"apps"),active:"apps"===d}),(0,n.jsx)(iU,{icon:(0,n.jsx)(ev.iU,{size:15}),label:o("mobile.tabLogs"),onClick:()=>u("logs"===d?null:"logs"),active:"logs"===d}),(0,n.jsx)("div",{className:"flex-1 min-h-2"}),(0,n.jsx)(iU,{icon:(0,n.jsx)(ev.wO,{size:15}),label:o("mobile.switchDevice"),onClick:F}),X?.canStop&&(0,n.jsx)("button",{onClick:()=>{(0,eN.e)(),x(!0)},className:"p-2 rounded-brand transition-all duration-150 ease-out active:scale-[0.94] flex-shrink-0 text-red-400 hover:bg-red-500/15",title:o("mobile.shutdownDevice"),"aria-label":o("mobile.shutdownDevice"),children:(0,n.jsx)(ev.$o,{size:15})}),!U&&(0,n.jsx)(iU,{icon:(0,n.jsx)(ev.X,{size:15}),label:o("common.close"),onClick:J})]})]})}function iU(e){let{icon:t,label:s,onClick:r,active:l=!1}=e;return(0,n.jsx)("button",{onClick:()=>{(0,eN.e)(),r?.()},className:`p-2 rounded-brand transition-all duration-150 ease-out active:scale-[0.94] flex-shrink-0 ${l?"text-brand-500 bg-surface-2":"text-text hover:bg-surface-2"}`,title:s,"aria-label":s,"aria-pressed":l,children:t})}let iX=[{edge:"n",className:"top-0 left-3 right-3 h-1",cursor:"cursor-ns-resize"},{edge:"s",className:"bottom-0 left-3 right-3 h-1",cursor:"cursor-ns-resize"},{edge:"w",className:"top-3 bottom-3 left-0 w-1",cursor:"cursor-ew-resize"},{edge:"e",className:"top-3 bottom-3 right-0 w-1",cursor:"cursor-ew-resize"},{edge:"nw",className:"top-0 left-0 w-3 h-3",cursor:"cursor-nwse-resize"},{edge:"ne",className:"top-0 right-0 w-3 h-3",cursor:"cursor-nesw-resize"},{edge:"sw",className:"bottom-0 left-0 w-3 h-3",cursor:"cursor-nesw-resize"},{edge:"se",className:"bottom-0 right-0 w-3 h-3",cursor:"cursor-nwse-resize"}];function iV(e){let{busRef:t,protocolRef:s,connected:l,pinSlot:a=null}=e,{t:i}=(0,eC.s)(),o=(0,f.B)(e=>e.mobileMode),c=(0,f.B)(e=>e.mobileFloatRect),d=(0,f.B)(e=>e.setMobileOpen),u=(0,f.B)(e=>e.setMobileSession),m=(0,f.B)(e=>e.setMobileMode),x=function(e){let{rect:t,onChange:s,enabled:n}=e,[l,a]=(0,r.useState)(()=>{let e,s;return t?iI(t):(e=ez.qj.width.default,s=Math.min(ez.qj.height.default,window.innerHeight-2*ez.qj.defaultOffset),{x:Math.max(ez.qj.margin,window.innerWidth-e-ez.qj.defaultOffset),y:Math.max(ez.qj.margin,window.innerHeight-s-ez.qj.defaultOffset),w:e,h:s})}),[i,o]=(0,r.useState)(!1),c=(0,r.useRef)(null),d=(0,r.useRef)(l),u=(0,r.useCallback)(e=>{d.current=e,a(e)},[]);(0,r.useEffect)(()=>{if(!n)return;let e=()=>{let e=d.current;if(!e)return;let t=Math.min(e.h,window.innerHeight-2*ez.qj.margin);u(iI({...e,h:t}))};return window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[n,u]);let m=(0,r.useCallback)((e,t)=>{(null==e.button||0===e.button)&&(e.preventDefault(),e.currentTarget.setPointerCapture?.(e.pointerId),c.current={mode:t,pointerId:e.pointerId,startX:e.clientX,startY:e.clientY,origin:l},o(!0))},[l]),x=(0,r.useCallback)(e=>{let t=c.current;if(!t||t.pointerId!==e.pointerId)return;if("mouse"===e.pointerType&&0===e.buttons)return void p(e);let s=e.clientX-t.startX,n=e.clientY-t.startY;if("move"===t.mode)return void u(iI({...t.origin,x:t.origin.x+s,y:t.origin.y+n}));let{origin:r,mode:l}=t,a=l.includes("w"),i=l.includes("n"),o=a||l.includes("e"),d=i||l.includes("s"),m=window.innerHeight-2*ez.qj.margin,x=i?r.y+r.h-ez.qj.margin:m,h=a?r.x+r.w-ez.qj.margin:ez.qj.width.max,f=o?iA(a?r.w-s:r.w+s,ez.qj.width.min,Math.min(ez.qj.width.max,h)):r.w,b=d?iA(i?r.h-n:r.h+n,ez.qj.height.min,Math.min(m,x)):r.h;u({x:a?r.x+(r.w-f):r.x,y:i?r.y+(r.h-b):r.y,w:f,h:b})},[u]),p=(0,r.useCallback)(e=>{let t=c.current;t&&t.pointerId===e.pointerId&&(c.current=null,o(!1),d.current&&s?.(d.current))},[s]);return(0,r.useEffect)(()=>{if(!i)return;let e=()=>{c.current=null,o(!1),d.current&&s?.(d.current)};return window.addEventListener("blur",e),()=>window.removeEventListener("blur",e)},[i,s]),{rect:l,dragging:i,onDragHandlePointerDown:e=>m(e,"move"),onResizeHandlePointerDown:e=>t=>m(t,e),onPointerMove:x,onPointerUp:p,onPointerCancel:p}}({rect:c,onChange:(0,f.B)(e=>e.setMobileFloatRect),enabled:"float"===o}),p=(0,r.useCallback)(()=>{t?.current?.emit("mobile:stop"),u(null),d(!1)},[t,u,d]),h="pin"===o,b=e=>(0,n.jsxs)("div",{className:"flex flex-col h-full w-full bg-bg overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex items-center gap-0.5 px-1.5 py-1 bg-surface flex-shrink-0",children:[(0,n.jsxs)("div",{className:`flex items-center gap-1 flex-1 min-w-0 ${e?"cursor-grab active:cursor-grabbing":""}`,onPointerDown:e?x.onDragHandlePointerDown:void 0,children:[e&&(0,n.jsx)(ev.f2,{size:13,className:"text-text-muted flex-shrink-0"}),(0,n.jsx)("span",{className:"text-xs text-text-muted select-none truncate",children:i("mobile.title")})]}),(0,n.jsx)("button",{onClick:()=>{(0,eN.e)(),m(h?"float":"pin")},className:`p-1.5 rounded-brand transition-colors ${h?"text-brand-500 bg-surface-2":"text-text-muted hover:text-text hover:bg-surface-2"}`,title:h?i("mobile.modeFloat"):i("mobile.modePin"),"aria-label":h?i("mobile.modeFloat"):i("mobile.modePin"),"aria-pressed":h,children:(0,n.jsx)(ev.jz,{size:13})}),(0,n.jsx)("button",{onClick:()=>{(0,eN.e)(),p()},className:"p-1.5 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors",title:i("common.close"),"aria-label":i("common.close"),children:(0,n.jsx)(ev.X,{size:13})})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0 relative",children:(0,n.jsx)(iq,{busRef:t,protocolRef:s,connected:l,variant:"panel",onClose:p})})]});if(h)return a?(0,sp.createPortal)(b(!1),a):null;let g=x.rect;return g?(0,sp.createPortal)((0,n.jsxs)("div",{className:"fixed z-40 flex flex-col rounded-brand-lg overflow-hidden border border-border shadow-2xl bg-bg",style:{left:g.x,top:g.y,width:g.w,height:g.h},onPointerMove:x.onPointerMove,onPointerUp:x.onPointerUp,onPointerCancel:x.onPointerCancel,children:[b(!0),iX.map(e=>{let{edge:t,className:s,cursor:r}=e;return(0,n.jsx)("div",{onPointerDown:x.onResizeHandlePointerDown(t),className:`absolute ${s} ${r}`,"aria-label":i("mobile.resize")},t)})]}),document.body):null}let iG=e=>e?.error==="Not connected";async function iJ(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:()=>!0,s=await e(),n=ez.Tk.retryBaseMs;for(;iG(s)&&t()&&n<=ez.Tk.retryMaxMs&&(await new Promise(e=>setTimeout(e,n)),t());)n*=2,s=await e();return s}let iY=e=>(e||"").split("/").filter(Boolean).pop()||e;function iZ(e,t){return e?e.endsWith("/")?`${e}${t}`:`${e}/${t}`:t}function iQ(e){let t=e.lastIndexOf("/");return t<=0?"/":e.slice(0,t)}function i0(e){if(!e)return"";let t=e.split("/").filter(Boolean);return t[t.length-1]||e}function i1(e){let{dirs:t,fileBus:s,onDirsChanged:n,enabled:l=!0,debounceMs:a=et.Jl.DEBOUNCE_MS}=e,i=(0,r.useRef)(new Set),o=(0,r.useRef)(n);(0,r.useEffect)(()=>{o.current=n},[n]);let{watchDir:c,unwatchDir:d,onFileChange:u}=s||{},m=t.join("\n");(0,r.useEffect)(()=>{if(!l||!c||!d)return;let e=!0,t=i.current,s=new Set,n=null,r=new Set([...m?m.split("\n"):[]].sort((e,t)=>t.split("/").length-e.split("/").length).slice(0,et.Jl.MAX_DIRS)),x=()=>{if(n=null,!e||!s.size)return;let t=[...s];s.clear(),o.current?.(t)},p=async()=>{for(let e of t)r.has(e)||(t.delete(e),d(e));for(let s of r){if(t.has(s))continue;t.add(s);let n=await c(s);e&&n?.watching!==!1||t.delete(s)}},h=u?.(e=>{let{type:t,path:l}=e;if(!l)return;let i="flooded"===t?l:l.slice(0,l.lastIndexOf("/"))||"/";r.has(i)&&(s.add(i),n||(n=setTimeout(x,a)))})||(()=>{});return p(),()=>{for(let s of(e=!1,clearTimeout(n),h(),t))d(s);t.clear()}},[m,l,a,c,d,u])}function i2(){let[e,t]=(0,r.useState)(()=>"u"<typeof document||!document.hidden);return(0,r.useEffect)(()=>{let e=()=>t(!document.hidden);return document.addEventListener("visibilitychange",e),()=>document.removeEventListener("visibilitychange",e)},[]),e}function i5(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";if(!e?.success)return{};let s=e.files||e.status||[],n={};for(let e of s){let s=e?.path||e?.file,r=e?.status||e?.code;if(!s||!r)continue;n[t+s]=r;let l=s.split("/");for(let e=1;e<l.length;e++){let s=t+l.slice(0,e).join("/");n[s]||(n[s]="folder-changed")}}return n}async function i3(e,t){let s=await e.gitStatus(t);if(s?.success)return{hasGit:!0,map:i5(s)};let n=await e.gitScanRepos?.(t),r=(n?.success?n.repos:[])||[],l=await Promise.all(r.map(async t=>{let s=String(t.relPath||"").split("\\").join("/");if(!s)return null;let n=await e.gitStatus(t.path);if(!n?.success)return null;let r=i5(n,`${s}/`);return Object.keys(r).length&&(r[s]||="folder-changed"),r})),a=Object.assign({},...l.filter(Boolean));return{hasGit:l.some(Boolean),map:a}}function i4(){try{let e=window.localStorage.getItem(et.d5.expandedFolders),t=e?JSON.parse(e):{};return Array.isArray(t)?{legacy:t}:t}catch{return{}}}function i6(){try{let e=window.localStorage.getItem(et.d5.showHidden);if(null===e)return!0;return!1!==JSON.parse(e)}catch{return!0}}let i8={created:"fileExplorer:fileCreated",deleted:"fileExplorer:fileDeleted",renamed:"fileExplorer:fileRenamed"};function i9(e){window.dispatchEvent(new CustomEvent(i8[e]))}let{xT:i7,Qm:oe,Pv:ot}=JSON.parse('{"xT":{"js":"js","mjs":"js","cjs":"js","jsx":"reactjs","ts":"typescript","tsx":"reactts","json":"json","json5":"json5","yml":"yaml","yaml":"yaml","toml":"toml","xml":"xml","ini":"ini","env":"dotenv","md":"markdown","markdown":"markdown","mdx":"mdx","pdf":"pdf","csv":"text","html":"html","css":"css","scss":"scss","sass":"sass","less":"less","styl":"stylus","vue":"vue","svelte":"svelte","astro":"astro","py":"python","pyw":"python","rb":"ruby","php":"php","go":"go","rs":"rust","java":"java","kt":"kotlin","swift":"swift","scala":"scala","cljs":"clojure","ex":"elixir","erl":"erlang","hs":"haskell","ml":"ocaml","dart":"dartlang","lua":"lua","r":"r","c":"c","h":"c","cpp":"cpp","hpp":"cpp","cs":"csharp","m":"objectivec","sh":"shell","bash":"shell","zsh":"shell","fish":"shell","ps1":"powershell","bat":"bat","sql":"sql","gql":"graphql","proto":"protobuf","png":"image","jpg":"image","jpeg":"image","gif":"image","webp":"image","ico":"image","bmp":"image","svg":"svg","avif":"image","tiff":"image","mp4":"video","m4v":"video","webm":"video","mov":"video","mkv":"video","avi":"video","mp3":"audio","wav":"audio","ogg":"audio","flac":"audio","m4a":"audio","aac":"audio","zip":"zip","tar":"zip","gz":"zip","tgz":"zip","rar":"zip","7z":"zip","bz2":"zip","xz":"zip","jar":"jar","log":"log","diff":"diff","patch":"diff","woff":"font","woff2":"font","ttf":"font","eot":"font","otf":"font","db":"datadog","sqlite":"sqlite","sqlite3":"sqlite","jsonc":"json","cfg":"ini","conf":"ini","txt":"text","htm":"html","kts":"kotlin","clj":"clojure","exs":"elixir","cc":"cpp","cxx":"cpp","graphql":"graphql","tif":"image"},"Qm":{".editorconfig":"editorconfig",".env":"dotenv",".gitattributes":"git",".gitignore":"git",".npmrc":"npm","docker-compose.yaml":"docker","docker-compose.yml":"docker","dockerfile":"docker","license":"license","makefile":"gnu","package-lock.json":"npm","package.json":"npm","tsconfig.json":"typescript"},"Pv":{"src":"src","source":"src","sources":"src","lib":"library","libs":"library","library":"library","app":"app","apps":"app","application":"app","component":"component","components":"component","page":"view","pages":"view","view":"view","views":"view","html":"view","model":"model","models":"model","controller":"controller","controllers":"controller","handler":"controller","handlers":"controller","route":"route","routes":"route","router":"route","routers":"route","public":"public","assets":"images","images":"images","image":"images","img":"images","icon":"images","icons":"images","font":"fonts","fonts":"fonts","style":"style","styles":"style","css":"style","docs":"docs","doc":"docs","test":"test","tests":"test","__tests__":"test","spec":"test","specs":"test","coverage":"test","util":"tools","utils":"tools","tool":"tools","tools":"tools","helpers":"tools","helper":"tools","script":"script","scripts":"script","config":"config","configs":"config","configuration":"config",".github":"github",".git":"git",".vscode":"vscode",".idea":"idea","node_modules":"node","bower_components":"bower","dist":"dist","out":"dist","export":"dist","exports":"dist","build":"dist","target":"dist","api":"api","apis":"api","server":"server","services":"server","service":"server","locale":"locale","locales":"locale","i18n":"locale","lang":"locale","languages":"locale","bin":"azurepipelines",".bin":"azurepipelines","middleware":"middleware","middlewares":"middleware","store":"redux","stores":"redux","hook":"hook","hooks":"hook","types":"typescript","typings":"typescript","@types":"typescript","interface":"interfaces","interfaces":"interfaces","theme":"theme","themes":"theme","layout":"view","layouts":"view","ios":"ios","static":"public","asset":"images","documentation":"docs","__specs__":"test","state":"redux","type":"typescript","constant":"tools","constants":"tools","core":"src","main":"src","android":"android"}}'),os="/icons/file-types",on="/icons/folder-types",or=`${os}/default.svg`,ol=`${on}/default.svg`,oa=`${on}/default-open.svg`;function oi(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],s=ot[(e||"").toLowerCase()];return s?{src:t?`${on}/${s}-open.svg`:`${on}/${s}.svg`,alt:s}:{src:t?oa:ol,alt:"folder"}}function oo(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:16,{src:s,alt:r}=function(e){if(!e)return{src:or,alt:"file"};if("folder"===e.type)return oi(e.name,!1);let t=(e.name||"").toLowerCase(),s=function(e){if(!e)return"";let t=e.toLowerCase(),s=t.lastIndexOf(".");return s<=0?t:t.slice(s+1)}(e.name);if(oe[t]){let e=oe[t];return{src:`${os}/${e}.svg`,alt:e}}if(i7[s]){let e=i7[s];return{src:`${os}/${e}.svg`,alt:e}}return{src:or,alt:"file"}}(e);return(0,n.jsx)("img",{src:s,alt:r,width:t,height:t,className:"pointer-events-none select-none",draggable:"false"})}let oc=e=>e?et.xW.compact:et.xW.normal,od=function(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],s=oc(t);return s.indentBase+e*s.indentStep};function ou(e){let{status:t}=e;return t?"folder-changed"===t?(0,n.jsx)("span",{className:"ml-auto mr-2 w-1.5 h-1.5 rounded-full bg-blue-400/70"}):(0,n.jsx)("span",{className:`ml-auto mr-2 text-[10px] font-semibold ${et.vs[t]||"text-text-muted"}`,children:t}):null}function om(e){let{depth:t,compact:s=!1}=e;return(0,n.jsx)("div",{className:"text-[11px] text-text-muted italic py-0.5 pr-2",style:{paddingLeft:od(t,s)},children:"Showing first 300 entries — use search for the rest."})}let ox=(0,r.memo)(function(e){let{file:t,depth:s,isFolder:r,isExpanded:l,isLoading:a,isActive:i,isSelected:o,isRenaming:c,isDragOver:d,isCut:u,gitStatus:m,renameValue:x,renameInputRef:p,onRenameChange:h,onRenameSubmit:f,onRenameCancel:b,onToggleFolder:g,onClick:v,onContextMenu:y,onTouchStart:w,onTouchEnd:j,onDragStart:k,onDragOver:N,onDragLeave:C,onDrop:S,compact:T=!1,children:E}=e,R=oc(T);return(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{"data-path":t.path,draggable:!c,onDragStart:e=>k(e,t),onDragOver:e=>N(e,t),onDragLeave:()=>C(t),onDrop:e=>S(e,t),className:`group relative flex items-center gap-1 rounded-[3px] mx-0.5 pr-2 cursor-pointer select-none ${R.text} ${R.padY} ${u?"opacity-50":""} ${d?"bg-brand-500/30 ring-1 ring-brand-500":o?"bg-brand-500/25":i?"bg-brand-500/15":"hover:bg-surface-2"}`,style:{paddingLeft:od(s,T)},onContextMenu:e=>y(e,t),onTouchStart:e=>w(e,t),onTouchEnd:j,onTouchMove:j,onClick:e=>!c&&v(t,e),children:[r?(0,n.jsx)("span",{onClick:e=>{e.stopPropagation(),g(t)},className:"flex items-center justify-center w-4 h-4 text-text-muted",children:a?(0,n.jsx)(ev.Ay,{name:"Loader2",size:R.chevron-2,className:"animate-spin"}):(0,n.jsx)(ev.Ay,{name:"ChevronRight",size:R.chevron,className:`transition-transform duration-150 ${l?"rotate-90":""}`})}):(0,n.jsx)("span",{className:"w-4 h-4"}),(0,n.jsx)("span",{className:"shrink-0",children:r?function(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:16,{src:r,alt:l}=oi(e,t);return(0,n.jsx)("img",{src:r,alt:l,width:s,height:s,className:"pointer-events-none select-none",draggable:"false"})}(t.name,l,R.icon):oo(t,R.icon)}),c?(0,n.jsx)("input",{ref:p,value:x,onChange:e=>h(e.target.value),onClick:e=>e.stopPropagation(),onBlur:f,onKeyDown:e=>{"Enter"===e.key?f():"Escape"===e.key&&b()},className:`flex-1 bg-surface-3 text-text ${R.text} px-1 py-0.5 rounded outline-none border border-brand-500`}):(0,n.jsx)("span",{className:`flex-1 truncate text-text ${et.vs[m]||""}`,title:t.name,children:t.name}),!c&&(0,n.jsx)(ou,{status:m}),!c&&(0,n.jsx)("div",{className:"absolute top-1/2 -translate-y-1/2 flex items-center pl-2 pr-1 rounded-[3px] bg-surface-2 opacity-0 group-hover:opacity-100 transition-opacity",style:{right:(0,et.mv)(m)},children:(0,n.jsx)("button",{onClick:e=>y(e,t),className:"p-0.5 text-text-muted hover:text-text",children:(0,n.jsx)(ev.Ay,{name:"MoreHorizontal",size:R.chevron})})})]}),E]})});async function op(e,t,s){let n=t?`${t}/${e.name}`:e.name;if(e.isFile){let t=await new Promise((t,s)=>e.file(t,s));s.push({file:t,relativePath:n})}else if(e.isDirectory){var r;for(let t of(await (r=e.createReader(),new Promise(e=>{let t=[],s=()=>r.readEntries(n=>{n.length?(t.push(...n),s()):e(t)},()=>e(t));s()}))))await op(t,n,s)}}async function oh(e){let t=[],s=[...e.items||[]].map(e=>e.webkitGetAsEntry?.()).filter(Boolean);if(s.length)for(let e of s)await op(e,"",t);else for(let s of e.files||[])t.push({file:s,relativePath:s.name});return t}let of="modal-overlay z-50",ob="w-full px-3 py-2 bg-surface-2 rounded-brand text-text focus:outline-none focus:ring-2 focus:ring-brand-500/40 transition-all duration-150 ease-out",og="flex-1 py-2 bg-surface-2 text-text rounded-brand hover:bg-surface-3 transition-all duration-150 ease-out active:scale-[0.98]",ov="flex-1 py-2 bg-brand-500 text-white rounded-brand hover:bg-brand-600 transition-all duration-150 ease-out active:scale-[0.98]";function oy(e){let{label:t,ratio:s}=e;return(0,n.jsxs)("div",{className:"bg-brand-500/10 border-b border-brand-500/30 px-4 py-2 text-text text-xs flex items-center gap-2",children:[(0,n.jsx)(ev.kr,{className:"animate-spin flex-shrink-0",size:14}),(0,n.jsx)("span",{className:"truncate flex-1",children:t}),(0,n.jsx)("div",{className:"w-16 h-1.5 bg-surface-2 rounded-full overflow-hidden flex-shrink-0",children:(0,n.jsx)("div",{className:"h-full bg-brand-500 transition-all",style:{width:`${Math.round(100*(s||0))}%`}})})]})}function ow(e){let{query:t,loading:s,onChange:r,onClose:l,compact:a=!1}=e,{t:i}=(0,eC.s)();return a?(0,n.jsx)("div",{className:"px-2 py-1.5 border-b border-border-subtle flex-shrink-0",children:(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)(ev.vj,{size:14,className:"absolute left-2 top-1/2 -translate-y-1/2 text-text-subtle pointer-events-none"}),(0,n.jsx)("input",{type:"text",value:t,onChange:e=>r(e.target.value),placeholder:i("files.searchPlaceholder"),className:"w-full min-w-0 bg-surface-2 border border-border rounded-brand pl-7 pr-7 h-8 text-xs text-text placeholder-text-subtle focus:outline-none focus:border-brand-500",autoFocus:!0}),s?(0,n.jsx)(ev.kr,{size:14,className:"absolute right-2 top-1/2 -translate-y-1/2 animate-spin text-brand-500"}):(0,n.jsx)("button",{onClick:()=>{(0,eN.e)(),l()},className:"absolute right-1 top-1/2 -translate-y-1/2 p-1 text-text-subtle hover:text-text",children:(0,n.jsx)(ev.X,{size:14})})]})}):(0,n.jsxs)("div",{className:"bg-surface-2 px-4 py-2 flex items-center gap-2 flex-shrink-0",children:[(0,n.jsx)(ev.vj,{className:"text-text-muted flex-shrink-0",size:20}),(0,n.jsx)("input",{type:"text",value:t,onChange:e=>r(e.target.value),placeholder:i("files.searchPlaceholder"),className:"flex-1 min-w-0 w-0 bg-transparent text-text placeholder-text-subtle focus:outline-none",autoFocus:!0}),s&&(0,n.jsx)(ev.kr,{className:"animate-spin text-brand-500",size:16}),(0,n.jsx)("button",{onClick:()=>{(0,eN.e)(),l()},className:"p-1 text-text-muted hover:text-text transition-colors",children:(0,n.jsx)(ev.X,{size:20})})]})}function oj(e){let{type:t,name:s,onTypeChange:l,onNameChange:a,onSubmit:i,onPickFile:o,onPickFolder:c,onClose:d}=e,{t:u}=(0,eC.s)(),[m]=(0,r.useState)(()=>"u">typeof document&&"webkitdirectory"in document.createElement("input")),x="upload"===t;return(0,r.useEffect)(()=>{let e=e=>{"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),d())};return window.addEventListener("keydown",e,!0),()=>window.removeEventListener("keydown",e,!0)},[d]),(0,sp.createPortal)((0,n.jsxs)("div",{className:of,children:[(0,n.jsx)("div",{className:"absolute inset-0 scrim fade-in",onClick:d}),(0,n.jsxs)("div",{className:"relative card-elev w-full max-w-sm my-auto overflow-y-auto pop-in",children:[(0,n.jsx)("div",{className:"px-4 py-3",children:(0,n.jsx)("h3",{className:"text-text font-semibold",children:u("files.createNew")})}),(0,n.jsxs)("div",{className:"p-4 space-y-4",children:[(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsxs)("button",{onClick:()=>{(0,eN.e)(),l("file")},className:`flex-1 py-2 rounded-brand transition flex items-center justify-center gap-2 ${"file"===t?"bg-brand-500 text-white dark:bg-white dark:text-black":"bg-surface-2 text-text"}`,children:[(0,n.jsx)(ev.ZH,{size:16,className:"text-text-subtle"})," ",u("files.file")]}),(0,n.jsxs)("button",{onClick:()=>{(0,eN.e)(),l("folder")},className:`flex-1 py-2 rounded-brand transition flex items-center justify-center gap-2 ${"folder"===t?"bg-brand-500 text-white dark:bg-white dark:text-black":"bg-surface-2 text-text"}`,children:[(0,n.jsx)(ev.vd,{size:16,className:"text-orange-500/70"})," ",u("files.folder")]}),(0,n.jsxs)("button",{onClick:()=>{(0,eN.e)(),l("upload")},className:`flex-1 py-2 rounded-brand transition flex items-center justify-center gap-2 ${x?"bg-brand-500 text-white dark:bg-white dark:text-black":"bg-surface-2 text-text"}`,children:[(0,n.jsx)(ev._O,{size:16,className:"text-brand-500"})," ",u("common.upload")]})]}),x?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("button",{onClick:()=>{(0,eN.e)(),o()},className:`${ov} flex items-center justify-center gap-2`,children:[(0,n.jsx)(ev.ZH,{size:16})," ",u("files.pickFile")]}),m&&(0,n.jsxs)("button",{onClick:()=>{(0,eN.e)(),c()},className:`${og} flex items-center justify-center gap-2`,children:[(0,n.jsx)(ev.vd,{size:16})," ",u("files.pickFolder")]}),(0,n.jsxs)("button",{onClick:()=>{(0,eN.e)(),d()},className:`${og} flex items-center justify-center gap-1.5`,children:[(0,n.jsx)("span",{children:u("common.cancel")}),(0,n.jsx)("kbd",{className:"hidden sm:inline-flex items-center text-[10px] font-mono px-1 py-0.5 rounded bg-surface-3 text-text-muted leading-none",children:"Esc"})]})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("input",{type:"text",value:s,onChange:e=>a(e.target.value),onKeyDown:e=>"Enter"===e.key&&i(),placeholder:u("file"===t?"files.placeholderFile":"files.placeholderFolder"),className:ob,autoFocus:!0}),(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsxs)("button",{onClick:()=>{(0,eN.e)(),d()},className:`${og} flex items-center justify-center gap-1.5`,children:[(0,n.jsx)("span",{children:u("common.cancel")}),(0,n.jsx)("kbd",{className:"hidden sm:inline-flex items-center text-[10px] font-mono px-1 py-0.5 rounded bg-surface-3 text-text-muted leading-none",children:"Esc"})]}),(0,n.jsxs)("button",{onClick:()=>{(0,eN.e)(),i()},className:`${ov} flex items-center justify-center gap-1.5`,children:[(0,n.jsx)("span",{children:u("common.create")}),(0,n.jsx)("kbd",{className:"hidden sm:inline-flex items-center justify-center w-4 h-4 rounded bg-white/20 text-white",children:(0,n.jsx)(ev.Lt,{size:10,strokeWidth:2.5})})]})]})]})]})]})]}),document.body)}function ok(e){let{value:t,onChange:s,onSubmit:l,onClose:a}=e,{t:i}=(0,eC.s)();return(0,r.useEffect)(()=>{let e=e=>{"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),a())};return window.addEventListener("keydown",e,!0),()=>window.removeEventListener("keydown",e,!0)},[a]),(0,sp.createPortal)((0,n.jsxs)("div",{className:of,children:[(0,n.jsx)("div",{className:"absolute inset-0 scrim fade-in",onClick:a}),(0,n.jsxs)("div",{className:"relative card-elev w-full max-w-sm my-auto max-h-[min(85%,calc(var(--app-height,85vh)-2rem))] overflow-y-auto pop-in",children:[(0,n.jsx)("div",{className:"px-4 py-3",children:(0,n.jsx)("h3",{className:"text-text font-semibold",children:i("files.rename")})}),(0,n.jsxs)("div",{className:"p-4 space-y-4",children:[(0,n.jsx)("input",{type:"text",value:t,onChange:e=>s(e.target.value),onKeyDown:e=>"Enter"===e.key&&l(),className:ob,autoFocus:!0}),(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsxs)("button",{onClick:()=>{(0,eN.e)(),a()},className:`${og} flex items-center justify-center gap-1.5`,children:[(0,n.jsx)("span",{children:i("common.cancel")}),(0,n.jsx)("kbd",{className:"hidden sm:inline-flex items-center text-[10px] font-mono px-1 py-0.5 rounded bg-surface-3 text-text-muted leading-none",children:"Esc"})]}),(0,n.jsxs)("button",{onClick:()=>{(0,eN.e)(),l()},className:`${ov} flex items-center justify-center gap-1.5`,children:[(0,n.jsx)("span",{children:i("files.rename")}),(0,n.jsx)("kbd",{className:"hidden sm:inline-flex items-center justify-center w-4 h-4 rounded bg-white/20 text-white",children:(0,n.jsx)(ev.Lt,{size:10,strokeWidth:2.5})})]})]})]})]})]}),document.body)}function oN(e){let{name:t,onResolve:s}=e,{t:l}=(0,eC.s)();(0,r.useEffect)(()=>{let e=e=>{"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),s?.("skip"))};return window.addEventListener("keydown",e,!0),()=>window.removeEventListener("keydown",e,!0)},[s]);let a=function(e,t){let r=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return(0,n.jsxs)("button",{onClick:()=>{(0,eN.e)(),s(e)},className:`py-2 rounded-brand text-sm flex items-center justify-center gap-1.5 ${t}`,children:[(0,n.jsx)("span",{children:l(`menu.${e}`)}),r&&(0,n.jsx)("kbd",{className:"hidden sm:inline-flex items-center text-[10px] font-mono px-1 py-0.5 rounded bg-surface-3 text-text-muted leading-none",children:"Esc"})]})};return(0,sp.createPortal)((0,n.jsxs)("div",{className:of,children:[(0,n.jsx)("div",{className:"absolute inset-0 scrim fade-in",onClick:()=>s?.("skip")}),(0,n.jsxs)("div",{className:"relative card-elev w-full max-w-sm pop-in",children:[(0,n.jsx)("div",{className:"px-4 py-3",children:(0,n.jsx)("h3",{className:"text-text font-semibold",children:l("menu.conflictTitle")})}),(0,n.jsx)("div",{className:"px-4 pb-3 text-text-muted text-sm break-all",children:l("menu.conflictMessage",{name:t})}),(0,n.jsxs)("div",{className:"p-4 grid grid-cols-2 gap-2",children:[a("skip","bg-surface-2 text-text hover:bg-surface-3",!0),a("skipAll","bg-surface-2 text-text hover:bg-surface-3"),a("replace","bg-brand-500 text-white hover:bg-brand-600"),a("replaceAll","bg-brand-500 text-white hover:bg-brand-600")]})]})]}),document.body)}async function oC(e,t,s){let n=arguments.length>3&&void 0!==arguments[3]&&arguments[3];if(!e||!t||!s)return{success:!1};let r=iZ(t,".gitignore"),l=s.replace(/^\/+/,"");n&&!l.endsWith("/")&&(l=`${l}/`);let a=await e.readFile(r),i=a?.success&&a.content||"",o=i.split(/\r?\n/),c=l.replace(/\/$/,"");if(o.includes(l)||o.includes(c)||o.includes(`/${l}`)||o.includes(`/${c}`))return{success:!0,alreadyIgnored:!0};let d=i?i.endsWith("\n")?`${i}${l}
13
+ ${s}`:s;return{bySession:{...e.bySession,[t]:{...i,promptError:{text:d,reason:n,attachments:c.length?c:null,promptId:o?null:l,retries:o?0:a}}}}})},setPromptSending:(t,s)=>{e(e=>{let n=l2(e,t);return{bySession:{...e.bySession,[t]:{...n,promptSending:{text:s,at:Date.now()}}}}})},clearPromptSending:(t,s)=>{e(e=>{let n=l2(e,t);if(!n.promptSending||null!=s&&n.promptSending.text!==s)return e;let{promptSending:r,...l}=n;return{bySession:{...e.bySession,[t]:l}}})},setPromptErrorText:(t,s)=>{e(e=>{let n=l2(e,t);return n.promptError?{bySession:{...e.bySession,[t]:{...n,promptError:{...n.promptError,text:s}}}}:e})},clearPromptError:t=>{e(e=>{let s=l2(e,t);if(!s.promptError)return e;let{promptError:n,...r}=s;return{bySession:{...e.bySession,[t]:r}}})},setGateError:function(t,s){let n=!(arguments.length>2)||void 0===arguments[2]||arguments[2];e(e=>{let r=l2(e,t);return r.activePermission?.requestId!==s?e:{bySession:{...e.bySession,[t]:{...r,gateError:n}}}})},finishTurn:function(t,s){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,r=arguments.length>3&&void 0!==arguments[3]&&arguments[3];e(e=>{let l=l2(e,t),a=l.messages.map((e,t)=>{let s=e.tools?lw(e.tools):null,n=!!s&&(s.length!==e.tools.length||s.some((t,s)=>t!==e.tools[s])),r=t===l.messages.length-1&&!1!==e.isLive;return n||r?{...e,...r?{isLive:!1}:null,...n?{tools:s}:null}:e});return{bySession:{...e.bySession,[t]:{...l,...r?{activePermission:null}:{isTurnRunning:!1,lastTurnMs:n||(l.turnStartedAt?Date.now()-l.turnStartedAt:l.lastTurnMs),activePermission:null,stats:s?{...l.stats,...s}:l.stats},messages:a}}}})},settleDeadTasks:t=>{t&&e(e=>{let s=l2(e,t),n=s.harnessTasks||[],r=n.some(e=>!lI.has(e.status))?n.map(e=>lI.has(e.status)?e:{...e,status:"stopped",endedAt:e.endedAt||Date.now()}):n,l=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=!1,s=e.map(e=>{if(!e.tools)return e;let s=lw(e.tools,{includeAsync:!0}),n=s.length!==e.tools.length||s.some((t,s)=>t!==e.tools[s]);return n&&(t=!0),n?{...e,tools:s}:e});return t?s:null}(s.messages);return r!==n||l?{bySession:{...e.bySession,[t]:{...s,harnessTasks:r,...l?{messages:l}:null}}}:e})},clearMessages:t=>{e(e=>{let s=l2(e,t);return{bySession:{...e.bySession,[t]:{...s,messages:[],tasks:[],turnStartedAt:0,lastTurnMs:0,activePermission:null,activeBlocked:null,stats:{inputTokens:0,outputTokens:0,totalTurns:0,totalCost:0,reasoningTokens:0},turnBaseline:{inputTokens:0,outputTokens:0}}}}})},rewindToMessage:(t,s,n)=>{e(e=>{let r=l2(e,t),l=r.messages.findIndex(e=>e.id===s);if(-1===l)return e;let a=r.messages.slice(0,l+1);return n&&(a[l]={...a[l],content:n}),{bySession:{...e.bySession,[t]:{...r,messages:a,isTurnRunning:!1,turnStartedAt:0,lastTurnMs:0,activePermission:null}}}})},upsertTask:(t,s)=>{e(e=>{let n=l2(e,t),r=lG(n.tasks,s);return r===n.tasks?e:{bySession:{...e.bySession,[t]:{...n,tasks:r}}}})},hydrateSession:(t,s)=>{let{messages:n=[],tasks:r=[],isTurnRunning:l=!1,metadata:a={},stats:i=null,permissionMode:o=null,activeBlocked:c=null,elapsedMs:d=0,lastTurnMs:u=0,harnessTasks:m=null,queue:x=null}=s;e(e=>{let s=l2(e,t),p=(m?l5(m,n):null)||n,h=l?p:p.map(e=>e.isLive?{...e,isLive:!1}:e);return{bySession:{...e.bySession,[t]:{...s,activePermission:null,messages:h,tasks:r,isTurnRunning:l,...Array.isArray(x)?{queue:x}:{},turnStartedAt:l?Date.now()-(d||0):0,lastTurnMs:l?0:u||0,turnBaseline:l?{inputTokens:0,outputTokens:0}:{inputTokens:i?.inputTokens||0,outputTokens:i?.outputTokens||0},metadata:{...s.metadata,...a},stats:i?{...s.stats,...i}:s.stats,activeBlocked:c,...o?{permissionMode:o}:{},...m?{harnessTasks:m}:{}}}}})},prependMessages:(t,s)=>{s?.length&&e(e=>{let n=l2(e,t),r=l5(n.harnessTasks||[],s)||s,l=new Set(n.messages.map(e=>e.id)),a=r.map(e=>l.has(e.id)?{...e,id:l0(e.id.split("-")[0])}:(l.add(e.id),e));return{bySession:{...e.bySession,[t]:{...n,messages:[...a,...n.messages]}}}})},restoreTurnState:function(t){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(void 0===s.isTurnRunning)return;let{isTurnRunning:n,lastTurnMs:r=0,elapsedMs:l=0}=s;(n||r)&&e(e=>{let s=l2(e,t);return{bySession:{...e.bySession,[t]:{...s,isTurnRunning:n,lastTurnMs:r,turnStartedAt:n?Date.now()-(l||0):0}}}})},removeSession:t=>{e(e=>{let{[t]:s,...n}=e.bySession;return{bySession:n}})}}),{name:"9remote-ai-store",storage:lZ,partialize:e=>({bySession:Object.fromEntries(Object.entries(e?.bySession||{}).map(e=>{let[t,s]=e;return[t,{permissionMode:s?.permissionMode??null,metadata:{model:s?.metadata?.model||"",effort:s?.metadata?.effort||""}}]}))})}));function l6(e){if(!e)return 0;let t=(e.content?.length||0)+(e.thinking?.length||0);if(Array.isArray(e.tools))for(let s of e.tools)t+=(s.command?.length||0)+(s.output?.length||0)+120;if(Array.isArray(e.diffs))for(let s of e.diffs)t+=(s.diff?.length||0)+(s.file?.length||0)+80;return Math.max(t,100)}function l8(e,t,s){let n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:2;if(!Array.isArray(e)||0===e.length)return 0;let r=Math.min(s??e.length,e.length),l=0,a=0;for(let s=r-1;s>=0&&(l+=l6(e[s]),a++,!(l>=t)||!(a>=n));s--);return r-a}async function l9(e){let{startSeq:t,fetchChunk:s,reduceChunk:n,maxChunks:r=8,pageBudget:l=131072,estimateBytes:a=()=>0}=e,i=t,o=[],c=0,d=!0,u=0,m=!1;for(;u<r;){let e=await s(i);if(u++,null==e)break;if(!e.success||!e.events?.length){d=!1;break}m=!0;let t=n(e.events,o.length);if(o=[...t,...o],c+=t.reduce((e,t)=>e+a(t),0),i=e.events[0].seq,!(d=!!e.hasMore)||c>=l)break}return{messages:o,before:i,hasMore:d,answered:m,chunks:u}}let l7=[1200,3e3,6e3];function ae(e,t){let{seq:s,epoch:n}=e,{appliedSeq:r,logEpoch:l}=t;return null!=n&&null==l?"adopt":null!=n&&null!=l&&n!==l?n>l?"resync":"stale":null==s?"apply":s<=r?"dup":null!=n&&n===l&&s>r+1?"gap":"apply"}function at(e,t){let{appliedSeq:s,logEpoch:n}=t,r=[],l=[],a=s,i=n;for(let t of e){if(l.length){l.push(t);continue}if("conversation_reset"===t.event){r.push(t),a=0,i=t.data?.epoch??(i??0)+1;continue}let e=ae(t,{appliedSeq:a,logEpoch:i});if("resync"===e)return{apply:r,held:[],resync:!0,appliedSeq:a,logEpoch:i};if("gap"===e){l.push(t);continue}"adopt"===e&&(i=t.epoch),"stale"!==e&&"dup"!==e&&(r.push(t),null!=t.seq&&(a=t.seq))}return{apply:r,held:l,resync:!1,appliedSeq:a,logEpoch:i}}let as={recover:0,gap:1,hydrate:2,now:3};function an(e){return`9remote_pendingPrompts_${e}`}function ar(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:globalThis.localStorage;if(!e||!t)return[];try{let s=JSON.parse(t.getItem(an(e))||"[]");return Array.isArray(s)?s.filter(e=>e&&"string"==typeof e.id&&"string"==typeof e.text):[]}catch{return[]}}function al(e,t,s){if(e&&s)try{t.length?s.setItem(an(e),JSON.stringify(t)):s.removeItem(an(e))}catch{}}function aa(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:globalThis.localStorage,n=ar(e,s),r=n.filter(e=>e.id!==t);r.length!==n.length&&al(e,r,s)}function ai(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:globalThis.localStorage;if(!t)return;let n=ar(e,s),r=n.filter(e=>!t.includes(e.text));r.length!==n.length&&al(e,r,s)}let ao=e=>Array.isArray(e)?e.map(e=>"string"==typeof e?{id:e,name:e,description:""}:e):[],ac=Math.random().toString(36).slice(2,10);function ad(e,t){let s=String(t||"").trim();if(!s)return!1;let n=e[e.length-1];return!!(n&&"assistant"===n.role&&String(n.content||"").trim().endsWith(s))}let au=/\u001b\[[0-9;?]*[A-Za-z]/g,am=e=>String(e||"").replace(au,"").trim(),ax=(e,t)=>{if(String(t||"").trim())return!1;let s=e[e.length-1];return!!(s&&"notice"===s.role&&"error"===s.level)},ap=e=>e?.text?`Not sent — ${e.reason||"the turn is still running"}: ${e.text}`:e?.reason||"Not sent";function ah(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"claude",s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,n=[],r=[],l=[],a={model:"",skills:[],mcpServers:[]},i={inputTokens:0,outputTokens:0,totalTurns:0,totalCost:0,reasoningTokens:0},o=!1,c=null,d=null,u=null,m=!1,x=!1,p=s;for(let s of e){let e=s?.event,h=s?.data;if(e)switch(e){case"user_message":o=!0,x=!1,d=null,n.push({id:`u-${++p}`,role:"user",content:h?.text||"",attachments:h?.attachments||[]}),n.push({id:`a-${++p}`,role:"assistant",content:"",thinking:"",diffs:[],tools:[],isLive:!0});break;case"init":{x=!1;let e=ao(h?.skills),t=e.length>0?e:a.skills,{model:s,...n}=h||{};a={...a,...n,skills:t,...s?{model:s}:{}};break}case"goal":a={...a,goal:h?.goal||null};break;case"cli_reset":break;case"delta":{let e=n[n.length-1];e&&"assistant"===e.role||(e={id:`msg-${++p}`,role:"assistant",content:"",isLive:!0,diffs:[],tools:[]},n.push(e)),e.content=(e.content||"")+(h?.text||"");break}case"thinking":{let e=n[n.length-1];e&&"assistant"===e.role||(e={id:`msg-${++p}`,role:"assistant",content:"",thinking:"",isLive:!0,diffs:[],tools:[]},n.push(e)),e.thinking=(e.thinking||"")+(h?.text||"");break}case"diff":{if(!h)break;let e=n[n.length-1];e&&"assistant"===e.role||(e={id:`msg-${++p}`,role:"assistant",content:"",isLive:!0,diffs:[],tools:[]},n.push(e));let t=e.diffs||(e.diffs=[]),s=t.findIndex(e=>e.file===h.file);-1!==s?t[s]=h:t.push(h);break}case"tool_child":if(!h)break;for(let e=n.length-1;e>=0;e--){let t=lj(n[e]?.tools,e=>e.id===h.parentToolUseId,e=>{let t=[...e.children||[]],s=t.findIndex(e=>e.id===h.id);return -1!==s?t[s]={...t[s],...h}:t.push({...h,status:h.status||"running"}),{...e,children:t}});if(t){n[e].tools=t;break}}break;case"tool_result_child":if(!h?.id)break;for(let e=n.length-1;e>=0;e--){let t=lj(n[e]?.tools,e=>(e.children||[]).some(e=>e.id===h.id),e=>({...e,children:e.children.map(e=>e.id===h.id?{...e,...h,status:h.status||"done"}:e)}));if(t){n[e].tools=t;break}}break;case"tool_start":{if(!h)break;let e=n[n.length-1];if(e&&"assistant"===e.role&&e.isLive&&(e.content||e.thinking||"").length>0)e.isLive=!1,e={id:`msg-${++p}`,role:"assistant",content:"",isLive:!0,diffs:[],tools:[{...h,status:h.status||"running"}]},n.push(e);else if(e&&"assistant"===e.role){let t=e.tools||(e.tools=[]),s=t.findIndex(e=>e.id===h.id);-1!==s?t[s]={...t[s],...h}:t.push({...h,status:h.status||"running"})}else e={id:`msg-${++p}`,role:"assistant",content:"",isLive:!0,diffs:[],tools:[{...h,status:h.status||"running"}]},n.push(e);if(h.name){let e=sr(t,h.name,h.input,h.id,r);e&&(r=lG(r,e))}break}case"tool_result":{if(!h?.id)break;for(let e=n.length-1;e>=0;e--){let t=n[e],s=t?.tools?.find(e=>e.id===h.id);if(s){Object.assign(s,h,{status:h.status||"done"});break}}let e=sl(t,h.name||"",h.output||"",h.id);e&&(r=lG(r,e));break}case"permission_request":c=h;break;case"permission_resolved":c=null;break;case"blocked":d=h;break;case"options_changed":h?.permissionMode&&(u=h.permissionMode),h?.model&&(a.model=h.model),h?.effort&&(a.effort=h.effort);break;case"turn_complete":m=!0,o=!1,c=null,h?.stats&&(i={...i,...h.stats}),n.length>0&&(n[n.length-1].isLive=!1),!h?.isError||ax(n,h.result)||ad(n,h.result)||n.push({id:`n-${++p}`,role:"notice",subtype:h.subtype||"",level:"error",content:h.result||"The turn ended in an error."});break;case"stats":h?.stats&&(i={...i,...h.stats});break;case"stopped":m=!0,o=!1,c=null;break;case"stall":for(let e of(m=!0,o=!1,c=null,n))e.isLive&&(e.isLive=!1);break;case"exit":for(let e of(m=!0,x=!0,o=!1,c=null,n))e.isLive&&(e.isLive=!1);(h?.error||h?.code!=null&&0!==h.code)&&n.push({id:`n-${++p}`,role:"notice",subtype:"exit",level:"error",content:h.error||`The AI process exited (code ${h.code}).`});break;case"error":for(let e of(m=!0,o=!1,n))e.isLive&&(e.isLive=!1);n.push({id:`n-${++p}`,role:"notice",subtype:"error",level:"error",content:h?.message||"AI process failed"});break;case"prompt_refused":n.push({id:`n-${++p}`,role:"notice",subtype:"prompt_refused",level:"error",content:ap(h)});break;case"conversation_reset":n.length=0,r.length=0,l.length=0,o=!1,x=!1,c=null,d=null;break;case"cli_event":{let e=h?.type||"",s=h?.record||null;l.push([e,h?.subtype||"",s,h?.ageMs]);let r=lV(e,s,t);if(!r)break;let{compactSettled:a,...i}=r,o=a?lB(n):-1;if(-1!==o){i.content?.trim()?n[o]={id:`n-${++p}`,role:"notice",...i}:n.splice(o,1);break}if(!i.content?.trim())break;let c=n[n.length-1];!c||"assistant"!==c.role||c.content||c.thinking||(c.tools||[]).length||n.pop(),n.push({id:`n-${++p}`,role:"notice",...i});break}case"ansi":{let e=am(h?.chunk);if(!e)break;let t=n[n.length-1];!t||"assistant"!==t.role||t.content||t.thinking||(t.tools||[]).length||n.pop(),n.push({id:`n-${++p}`,role:"notice",subtype:"ansi",level:"warning",content:e})}}}if(m||x)for(let e of n)e.tools&&(e.tools=lw(e.tools,{includeAsync:x}));let h=[];for(let[e,t,s]of l)h=lO(h,e,t,s);return x&&(h=h.map(e=>lI.has(e.status)?e:{...e,status:"stopped",endedAt:e.endedAt||Date.now()})),{messages:n,tasks:r,metadata:a,stats:i,isTurnRunning:o,activePermission:c,activeBlocked:d,permissionMode:u,harnessRecords:l,harnessTasks:h}}function af(e,t){if(!t)return!1;let s=[...l4.getState().bySession[e]?.messages||[]].reverse().find(e=>"user"===e.role);return!!s&&(s.content===t||String(t).endsWith("\n\n"+s.content))}function ab(e,t){let s=l4.getState().bySession[e]?.promptError;if(!s||!t)return;if(s.text===t)return void l4.getState().clearPromptError(e);let n=s.text.split("\n\n"),r=n.indexOf(t);if(-1===r)return;n.splice(r,1);let l=n.filter(Boolean).join("\n\n");l?l4.getState().setPromptErrorText(e,l):l4.getState().clearPromptError(e)}let ag=e=>String(e).padStart(2,"0");function av(e){let t=Math.max(0,Math.floor((Number(e)||0)/1e3)),s=Math.floor(t/3600),n=Math.floor(t%3600/60),r=t%60;return s>0?`${s}h ${ag(n)}m`:n>0?`${n}m ${ag(r)}s`:`${r}s`}let ay=(0,r.memo)(function(e){let{message:t,engine:s="claude",workspacePath:l="",onResolvePermission:a,onRewind:i,onPreviewRewind:o,onCutLocal:c,rewindIndex:d=null,canRewind:u=!1}=e,[m,x]=(0,r.useState)(!1),[p,h]=(0,r.useState)(!1),[b,g]=(0,r.useState)(""),[v,y]=(0,r.useState)(null),[w,j]=(0,r.useState)(!1),[k,N]=(0,r.useState)(null);(0,f.B)(e=>e.openEditorFile);let{id:C,role:S,content:T,thinking:E,diffs:R=[],tools:M=[],permission:$=null,isLive:z=!1,attachments:P=[]}=t;if("user"===S){let e=async e=>{j(!0),N("preview");let t=await o?.(null,{index:d});(j(!1),N(null),t?.ok)?y({files:t.files||[],text:e}):y({error:t?.error||"The host could not preview this rewind.",text:e})},t=async()=>{let e=v?.text;y(null),j(!0),N("apply"),c?.(C,e);let t=await i?.(null,e,{index:d});(j(!1),N(null),t&&!t.ok)?y({error:t.error||"The rewind did not go through.",text:e}):h(!1)},s=(0,n.jsx)(ek.A,{isOpen:!!v,onClose:()=>y(null),onConfirm:v?.error?()=>y(null):t,title:v?.error?"Cannot rewind":"Rewind to this prompt?",message:v?.error?v.error:["This discards every turn after this prompt and re-sends your edited text.",v?.files?.length?`These ${v.files.length} file${1===v.files.length?"":"s"} go back to how they were:`:"No file changes to restore — this rewinds the conversation only.",...v?.files?.slice(0,8).map(e=>`\xb7 ${e.file}${e.status?` (${e.status})`:""}`)||[],v?.files?.length>8?`… and ${v.files.length-8} more`:"","Edits made by hand, or by shell commands, are NOT restored."].filter(Boolean).join("\n"),confirmText:v?.error?"OK":"Rewind"});if(p)return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"flex justify-end my-3",children:(0,n.jsxs)("div",{className:"max-w-[85%] sm:max-w-[75%] w-full",children:[(0,n.jsx)("textarea",{value:b,onChange:e=>g(e.target.value),onBlur:()=>{w||v||h(!1)},onKeyDown:t=>{if("Enter"===t.key&&!t.shiftKey){if(t.nativeEvent.isComposing||229===t.keyCode||(t.preventDefault(),w||v))return;b.trim()&&e(b.trim())}"Escape"===t.key&&h(!1)},rows:Math.min(10,b.split("\n").length+1),className:"w-full resize-none overflow-hidden rounded-brand-lg bg-surface-2 px-4 py-2.5 text-sm text-text focus:outline-none focus:ring-1 focus:ring-brand-500 leading-relaxed",autoFocus:!0}),(0,n.jsxs)("div",{className:"flex justify-end items-center gap-1.5 mt-1.5 text-[11px] text-text-muted",children:[w&&(0,n.jsx)(ev.kr,{size:11,className:"animate-spin"}),(0,n.jsx)("span",{children:"apply"===k?"Rewinding...":"preview"===k?"Checking what this would change...":"Enter to rewind, Esc to cancel"})]})]})}),s]});let r=u&&!!i,l=()=>{(0,eN.e)(),g(T||""),h(!0)};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"group/msg flex flex-col items-end my-3 list-rise",children:[(0,n.jsxs)("div",{className:"max-w-[92%] @2xl:max-w-[768px] flex flex-col items-end gap-1.5",children:[P.length>0&&(0,n.jsx)("div",{className:"flex flex-wrap justify-end gap-1.5",children:P.map((e,t)=>(0,n.jsxs)("span",{className:`inline-flex items-center gap-1 rounded-full border px-2 py-0.5 text-[11px] ${e.isImage?"border-brand-500/40 bg-brand-500/10 text-brand-500":"border-border-subtle bg-surface-2 text-text-muted"}`,children:[e.isImage?(0,n.jsx)(ev._V,{size:10}):(0,n.jsx)(ev.xv,{size:10}),(0,n.jsx)("span",{className:"max-w-[160px] truncate",children:e.filename})]},`${e.filename}-${t}`))}),T&&(0,n.jsx)("div",{onClick:r?e=>{let t=window.getSelection();t&&!t.isCollapsed&&t.containsNode(e.currentTarget,!0)||l()}:void 0,className:`px-3.5 py-2 rounded-[16px] rounded-tr-[4px] bg-[var(--chat-bubble-mine)] text-[var(--chat-meta-on-mine)] text-sm whitespace-pre-wrap wrap-anywhere shadow-[0_1px_2px_rgba(0,0,0,0.08)] ${r?"cursor-pointer":""}`,children:T})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1 mt-1",children:[(0,n.jsx)("button",{type:"button",onClick:()=>{(0,eN.e)(),T&&(navigator.clipboard.writeText(T),x(!0),setTimeout(()=>x(!1),2e3))},className:"px-1.5 py-0.5 rounded text-[11px] text-text-muted hover:text-text hover:bg-surface-2 flex items-center gap-1 transition-colors",title:"Copy this prompt",children:m?(0,n.jsx)(ev.aJ,{size:11,className:"text-success"}):(0,n.jsx)(ev.QR,{size:11})}),r&&(0,n.jsx)("button",{type:"button",disabled:w,onClick:l,className:"px-1.5 py-0.5 rounded text-[11px] text-text-muted hover:text-text hover:bg-surface-2 flex items-center gap-1 transition-colors disabled:opacity-40",title:"Edit & rewind to here",children:w&&"preview"===k?(0,n.jsx)(ev.kr,{size:11,className:"animate-spin"}):(0,n.jsx)(ev.gH,{size:11})})]})]}),s]})}return null},(e,t)=>e.message===t.message&&e.onResolvePermission===t.onResolvePermission&&e.rewindIndex===t.rewindIndex||!e.message.isLive&&!t.message.isLive&&e.message.id===t.message.id&&e.message.content===t.message.content&&e.message.thinking===t.message.thinking&&e.message.permission===t.message.permission&&e.message.tools===t.message.tools&&e.message.diffs===t.message.diffs&&e.canRewind===t.canRewind&&e.rewindIndex===t.rewindIndex&&e.onResolvePermission===t.onResolvePermission);function aw(e,t){if("string"!=typeof e||!e)return{dir:"",name:""};let s=e.replace(/\\/g,"/"),n=t?t.replace(/\\/g,"/").replace(/\/+$/,""):"",r=!!n&&s.startsWith(`${n}/`),l=r?5:4,a=(r?s.slice(n.length+1):s).split("/").filter(Boolean);a.length>l&&(a=["…",...a.slice(-l)]);let i=a.pop()||"";return{dir:a.join("/"),name:i}}let aj=(0,r.memo)(function(e){let{images:t=[],index:s=0,onClose:l,fileBus:a=null}=e,[i,o]=(0,r.useState)(s),[c,d]=(0,r.useState)(null),[u,m]=(0,r.useState)(!1),[x,p]=(0,r.useState)(1),[h,f]=(0,r.useState)({x:0,y:0}),b=(0,r.useRef)(null),g=(0,r.useRef)(null),v=(0,r.useRef)(null),y=(0,r.useRef)(null),w=t[i]||null;(0,r.useEffect)(()=>{if(d(null),m(!1),p(1),f({x:0,y:0}),!w?.path||!a?.readMedia)return;let e=!0;return a.readMedia(w.path).then(t=>{e&&(t?.success&&t.dataUrl?d(t.dataUrl):m(!0))}).catch(()=>{e&&m(!0)}),()=>{e=!1}},[w?.path,a]);let j=(0,r.useCallback)(e=>{o(s=>{let n=s+e;return n<0||n>=t.length?s:n})},[t.length]),k=(0,r.useCallback)((e,t)=>{let s=y.current;if(!s||t<=1)return{x:0,y:0};let n=s.clientWidth*(t-1)/2,r=s.clientHeight*(t-1)/2;return{x:Math.max(-n,Math.min(n,e.x)),y:Math.max(-r,Math.min(r,e.y))}},[]),N=(0,r.useCallback)(e=>{let t=Math.min(4,Math.max(1,e));p(t),1===t?f({x:0,y:0}):f(e=>k(e,t))},[k]);(0,r.useEffect)(()=>{let e=e=>{"Escape"===e.key?(e.preventDefault(),e.stopPropagation(),l?.()):"ArrowLeft"===e.key?(e.preventDefault(),j(-1)):"ArrowRight"===e.key?(e.preventDefault(),j(1)):"0"===e.key&&(p(1),f({x:0,y:0}))};return window.addEventListener("keydown",e,!0),()=>window.removeEventListener("keydown",e,!0)},[l,j]);let C=e=>{let t=b.current;if(!t)return;if(t.pointers.size>1){t.pointers.delete(e.pointerId),t.pinch0=null;return}if(t.pointers.delete(e.pointerId),t.pointers.size>0)return;b.current=null;let s=t.movedX||0,n=g.current?.clientWidth||window.innerWidth;1===x&&Math.abs(s)>60&&Math.abs(s)>.18*n&&j(s<0?1:-1),1===x&&f({x:0,y:0}),!t.swiped&&t.startedOnBackdrop&&l?.()};return"u"<typeof document||!w?null:(0,sp.createPortal)((0,n.jsx)("div",{ref:g,className:"scrim-lightbox fixed inset-0 z-[9999] flex items-center justify-center select-none",onPointerDown:e=>{let t=b.current;if(t){t.pointers.set(e.pointerId,{x:e.clientX,y:e.clientY}),t.pinch0=null,t.swiped=!0;return}b.current={id:e.pointerId,x:e.clientX,y:e.clientY,movedX:0,zoom0:x,pan0:h,pinch0:null,startedOnBackdrop:e.target===g.current,pointers:new Map([[e.pointerId,{x:e.clientX,y:e.clientY}]])}},onPointerMove:e=>{let t=b.current;if(!t)return;if(t.pointers.set(e.pointerId,{x:e.clientX,y:e.clientY}),2===t.pointers.size){let[e,s]=[...t.pointers.values()],n=Math.hypot(e.x-s.x,e.y-s.y);if(!t.pinch0){t.pinch0=n,t.zoom0=x;return}N(t.zoom0*(n/t.pinch0)),t.swiped=!0;return}let s=e.clientX-t.x,n=e.clientY-t.y;if(x>1){f(k({x:t.pan0.x+s,y:t.pan0.y+n},x)),t.swiped=!0;return}t.movedX=s,Math.abs(s)>8&&(t.swiped=!0),f({x:s,y:0})},onPointerUp:C,onPointerCancel:C,onWheel:e=>{(e.ctrlKey||e.metaKey)&&(e.preventDefault(),N(x-.002*e.deltaY))},onClick:e=>{e.target===g.current&&l?.()},children:(0,n.jsxs)("div",{ref:v,className:"lightbox-panel relative z-10 flex max-h-[min(88vh,calc(var(--app-height,100vh)-2rem))] w-[min(94vw,1100px)] flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex shrink-0 items-center gap-2 px-2.5 py-2",children:[(0,n.jsx)("span",{className:"min-w-0 truncate font-mono text-[11.5px] text-white/75",children:w.name}),t.length>1&&(0,n.jsxs)("span",{className:"shrink-0 rounded-full bg-white/10 px-2 py-0.5 font-mono text-[10.5px] text-white/60 tabular-nums",children:[i+1," / ",t.length]}),(0,n.jsx)("span",{className:"flex-1"}),(0,n.jsx)("button",{type:"button",onClick:l,className:"shrink-0 rounded-full p-1.5 text-white/60 transition-colors hover:bg-white/15 hover:text-white",title:"Close",children:(0,n.jsx)(ev.X,{size:16})})]}),(0,n.jsxs)("div",{className:"relative min-h-0 flex-1",children:[t.length>1&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{type:"button",onClick:()=>j(-1),disabled:0===i,className:"lightbox-arrow absolute left-2 top-1/2 z-10 -translate-y-1/2 rounded-full p-2 text-white/70 transition-colors hover:text-white disabled:opacity-20",title:"Previous",children:(0,n.jsx)(ev.JG,{size:18})}),(0,n.jsx)("button",{type:"button",onClick:()=>j(1),disabled:i===t.length-1,className:"lightbox-arrow absolute right-2 top-1/2 z-10 -translate-y-1/2 rounded-full p-2 text-white/70 transition-colors hover:text-white disabled:opacity-20",title:"Next",children:(0,n.jsx)(ev.c_,{size:18})})]}),c?(0,n.jsx)("img",{ref:y,src:c,alt:w.name,draggable:!1,className:"lightbox-image mx-auto block max-h-full max-w-full object-contain",style:{transform:`translate(${h.x}px, ${h.y}px) scale(${x})`,transition:b.current?"none":"transform 160ms ease-out",touchAction:"none"}}):u?(0,n.jsx)("span",{className:"flex h-full items-center justify-center font-mono text-xs text-white/55",children:"This image is no longer on the host."}):(0,n.jsx)("span",{className:"flex h-full items-center justify-center",children:(0,n.jsx)(ev.kr,{size:22,className:"animate-spin text-white/60"})})]})]})}),document.body)}),ak=/\.(png|jpe?g|gif|webp|avif|bmp|svg)$/i,aN=(0,r.memo)(function(e){let{img:t,fileBus:s=null,images:l=null,index:a=0}=e,[i,o]=(0,r.useState)(null),[c,d]=(0,r.useState)(!1),[u,m]=(0,r.useState)(!1);return((0,r.useEffect)(()=>{if(!t?.path||!s?.readMedia)return;let e=!0;return s.readMedia(t.path,{maxDim:320}).then(t=>{e&&(t?.success&&t.dataUrl?o(t.dataUrl):d(!0))}).catch(()=>{e&&d(!0)}),()=>{e=!1}},[t?.path,s]),!t?.path||c)?null:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{type:"button",onClick:()=>m(!0),className:"h-10 w-14 shrink-0 overflow-hidden rounded-brand border border-border-subtle/60 bg-surface-2/60 transition-opacity hover:opacity-90",title:`${t.name} — open in viewer`,children:i?(0,n.jsx)("img",{src:i,alt:t.name,className:"h-full w-full object-cover",draggable:!1}):(0,n.jsx)("span",{className:"block h-full w-full animate-pulse bg-surface-3/40"})}),u&&(0,n.jsx)(aj,{images:l||[t],index:l?a:0,fileBus:s,onClose:()=>m(!1)})]})}),aC={file:ev.kU};function aS(e){let{path:t,fileBus:s,onOpen:l}=e,[a,i]=(0,r.useState)(null);return((0,r.useEffect)(()=>{if(!t||!s?.readMedia)return;let e=!0;return s.readMedia(t).then(t=>{e&&t?.success&&t.dataUrl&&i(t.dataUrl)}).catch(()=>{}),()=>{e=!1}},[t,s]),a)?(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),(0,eN.e)(),l()},className:"shrink-0 overflow-hidden rounded border border-border-subtle/60 hover:border-border-subtle transition-colors",title:"View full size",children:(0,n.jsx)("img",{src:a,alt:"",className:"h-7 w-10 object-cover",draggable:!1})}):null}let aT=(0,r.memo)(function e(t){let{id:s="",name:l="tool",command:a="",input:i=null,output:o="",error:c="",status:d="done",children:u=[],engine:m="claude",workspacePath:x="",fileBus:p=null}=t,h="running"===d,b=!!(c||"error"===d),[g,v]=(0,r.useState)(!1),[y,w]=(0,r.useState)(!1),j=(0,f.B)(e=>e.openEditorFile),k=!!a||"string"!=typeof i&&!!i?.command,N="string"==typeof i?"":i?.file_path||i?.notebook_path||i?.path||i?.file||"",C=a||N||("string"==typeof i?i:i?.command||i?.pattern||i?.query||""),S=!k&&N&&C===N?function(e,t){let{dir:s,name:n}=aw(e,t);return s?`${s}/${n}`:n}(C,x):C,T="string"==typeof i?i:i&&Object.keys(i).length?JSON.stringify(i,null,2):"",E=i?.file_path||i?.path||i?.file||"",R=ak.test(E),[M,$]=(0,r.useState)(!1),z=aC[sn(m,l)]||ev.Jl;return(0,n.jsxs)("div",{className:"my-1 text-xs",children:[(0,n.jsxs)("div",{onClick:()=>v(!g),className:"flex items-center justify-between py-1 px-0 hover:bg-surface-2/40 cursor-pointer data-pane-control select-none transition-colors group/tool",children:[(0,n.jsxs)("div",{className:"flex items-start gap-2 min-w-0 flex-1",children:[(0,n.jsx)("span",{className:"shrink-0 mt-0.5",children:h?(0,n.jsx)(ev.kr,{size:13,className:"animate-spin text-accent"}):b?(0,n.jsx)(ev.RI,{size:13,className:"text-danger"}):(0,n.jsx)(z,{size:13,className:"text-success"})}),(0,n.jsxs)("div",{className:"min-w-0 flex-1 font-mono text-[11px] leading-relaxed line-clamp-2",children:[(0,n.jsx)("span",{className:"text-[10px] font-semibold text-text uppercase tracking-wider break-all px-1 py-0.5 rounded bg-surface-2/80 [box-decoration-break:clone]",title:l,children:l}),S&&(0,n.jsxs)(n.Fragment,{children:[" ",(0,n.jsx)("span",{className:"text-text-muted break-all",title:S,children:S})]})]}),(0,n.jsx)("span",{className:"text-text-muted/50 shrink-0 self-center",children:g?(0,n.jsx)(ev.yQ,{size:11}):(0,n.jsx)(ev.c_,{size:11})})]}),(0,n.jsxs)("div",{className:`flex items-center gap-1 shrink-0 ml-2 ${R?"":"opacity-0 group-hover/tool:opacity-100"}`,children:[R&&!h&&!b&&p&&(0,n.jsx)(aS,{path:E,fileBus:p,onOpen:()=>$(!0)}),E&&(0,n.jsx)("button",{type:"button",onClick:e=>{if(e.stopPropagation(),(0,eN.e)(),E){if(R)return void $(!0);j(E)}},className:"p-0.5 text-text-muted hover:text-text rounded hover:bg-surface-3 transition-colors flex items-center gap-1",title:R?"View image":"Open file in editor",children:(0,n.jsx)(ev.Gr,{size:11})}),(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),(0,eN.e)();let t=o||c||S;t&&(navigator.clipboard.writeText("string"==typeof t?t:JSON.stringify(t,null,2)),w(!0),setTimeout(()=>w(!1),2e3))},className:"p-0.5 text-text-muted hover:text-text rounded hover:bg-surface-3 transition-colors opacity-0 group-hover/tool:opacity-100",title:"Copy output",children:y?(0,n.jsx)(ev.aJ,{size:11,className:"text-success"}):(0,n.jsx)(ev.QR,{size:11})})]})]}),g&&(0,n.jsxs)("div",{className:"mt-1 ml-3.5 pl-3 border-l-2 border-border-subtle/80 bg-surface-2/20 rounded-r-brand p-2 overflow-x-auto max-h-[260px] overflow-y-auto font-mono text-[11px] select-text",children:[T&&(0,n.jsx)("div",{className:"text-text-muted whitespace-pre-wrap break-all leading-relaxed mb-1.5",children:T}),c&&(0,n.jsx)("div",{className:"text-danger mb-1.5 whitespace-pre-wrap wrap-anywhere",children:c}),o?(0,n.jsx)("div",{className:"text-text whitespace-pre-wrap wrap-anywhere leading-relaxed",children:"string"==typeof o?o:JSON.stringify(o,null,2)}):c?null:(0,n.jsx)("div",{className:"text-text-muted italic",children:"Running or no output returned..."})]}),g&&u.length>0&&(0,n.jsx)("div",{className:"ml-3.5 pl-3 border-l-2 border-border-subtle/80",children:u.map(t=>(0,n.jsx)(e,{...t,engine:m,workspacePath:x,fileBus:p},t.id))}),M&&(0,n.jsx)(aj,{images:[{path:E,name:E.split(/[/\\]/).pop()||E}],index:0,fileBus:p,onClose:()=>$(!1)})]})}),aE=new Set(["TaskCreate","TaskUpdate","TodoWrite","todowrite"]),aR=e=>!!ss(e).questionGate,aM=new Set(["Edit","Write","MultiEdit","NotebookEdit","file_change","edit","write","write_to_file","replace_file_content"]),a$=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return e.file_path||e.notebook_path||e.path||e.filePath||e.file||""},az=/\.(png|jpe?g|gif|webp|avif|bmp|svg)$/i,aP=["file_path","notebook_path","path","file"],aA=e=>"thought"===e.kind||"tool"===e.kind||"diff"===e.kind;function aI(e){let{total:t,windowSize:s=3,children:l}=e,[a,i]=(0,r.useState)(0),o=function(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,n=e-Math.max(0,s);return n>t+1?n-t:0}(t,s,a);return(0,n.jsxs)(n.Fragment,{children:[a>0?(0,n.jsx)("button",{type:"button",onClick:()=>i(e=>e-Math.min(12,Math.max(0,e))),className:"py-0.5 text-left font-mono text-[10.5px] text-text-subtle hover:text-text",children:"▼ show less"}):o>0?(0,n.jsxs)("button",{type:"button",onClick:()=>i(e=>e+Math.min(12,Math.max(0,o))),className:"py-0.5 text-left font-mono text-[10.5px] text-text-subtle hover:text-text",children:["▲ ",o," more ",1===o?"step":"steps"]}):null,l(o)]})}function aD(){let[e,t]=(0,r.useState)(!1);return(0,r.useEffect)(()=>{let e=window.matchMedia("(hover: none), (pointer: coarse)"),s=()=>t(e.matches);return s(),e.addEventListener("change",s),()=>e.removeEventListener("change",s)},[]),e}let aL=(0,r.memo)(function(e){let{file:t="",patch:s="",diff:l="",content:a="",workspacePath:i=""}=e,[o,c]=(0,r.useState)(!1),d=(0,f.B)(e=>e.openEditorFile),u=aD(),m=s||l||(s||l||!a?"":String(a).split("\n").map(e=>`+${e}`).join("\n")),x=m?m.split("\n"):[],p=aw(t,i),h=x.filter(e=>e.startsWith("+")&&!e.startsWith("+++")).length,b=x.filter(e=>e.startsWith("-")&&!e.startsWith("---")).length;return(0,n.jsxs)("div",{className:"my-1 text-xs",children:[(0,n.jsxs)("div",{onClick:()=>c(!o),className:"flex items-center justify-between py-1 px-0 hover:bg-surface-2/40 cursor-pointer data-pane-control select-none transition-colors group/tool",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,n.jsx)(ev.GD,{size:13,className:"text-success shrink-0"}),(0,n.jsx)("span",{className:"min-w-0 font-mono font-medium text-text text-[11px] break-all",title:t,children:p.dir?`${p.dir}/${p.name}`:p.name||"diff"}),(h>0||b>0)&&(0,n.jsxs)("span",{className:"flex items-center gap-1 font-mono text-[10px] shrink-0 text-text-muted",children:[h>0&&(0,n.jsxs)("span",{className:"text-success",children:["+",h]}),b>0&&(0,n.jsxs)("span",{className:"text-danger",children:["-",b]})]}),(0,n.jsx)("span",{className:"text-text-muted/50 shrink-0",children:o?(0,n.jsx)(ev.yQ,{size:11}):(0,n.jsx)(ev.c_,{size:11})})]}),(0,n.jsx)("div",{className:`flex items-center gap-1 shrink-0 ml-2 transition-opacity ${u?"opacity-100":"opacity-0 group-hover/tool:opacity-100"}`,children:t&&(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),(0,eN.e)(),t&&d(t)},className:"p-0.5 text-text-muted hover:text-text rounded hover:bg-surface-3 transition-colors flex items-center gap-1 text-[10px]",title:"Open file in editor",children:(0,n.jsx)(ev.Gr,{size:11})})})]}),o&&(0,n.jsx)("div",{className:"mt-1 ml-3.5 pl-3 border-l-2 border-border-subtle/80 bg-surface-2/20 rounded-r-brand p-2 overflow-x-auto max-h-[300px] overflow-y-auto font-mono text-[11px] leading-relaxed select-text",children:0===x.length?(0,n.jsx)("div",{className:"text-text-muted italic py-1 px-2",children:"No changes"}):x.map((e,t)=>{let s=e.startsWith("+")&&!e.startsWith("+++"),r=e.startsWith("-")&&!e.startsWith("---"),l=e.startsWith("@@"),a="text-text",i="";return s?(a="text-success",i="bg-success/10"):r?(a="text-danger",i="bg-danger/10"):l&&(a="text-text-muted",i="bg-surface-2/40"),(0,n.jsx)("div",{className:`px-2 py-0.5 rounded-sm whitespace-pre ${a} ${i}`,children:e},t)})})]})}),aB=/"((?:[^"\\]|\\.)*)"\s*=\s*"((?:[^"\\]|\\.)*)"/g,aF=e=>e.replace(/\\(.)/g,"$1"),aO=e=>[...e.matchAll(aB)].map(e=>[aF(e[1]),aF(e[2])]),a_=(0,r.createContext)({sessionId:"",isFocused:!0,activate:null}),aK=()=>(0,r.useContext)(a_),aW=(e,t,s)=>s?`ai-${e}-${t}-${s}`:void 0,aH=(0,r.memo)(function(e){let{requestId:t="",questions:s=[],answers:l=null,declined:a=!1,failed:i=!1,onResolve:o,engine:c=""}=e,{isFocused:d,activate:u}=aK(),[m,x]=(0,r.useState)({}),[p,h]=(0,r.useState)({}),[f,b]=(0,r.useState)(!1),[g,v]=(0,r.useState)(!1),[y,w]=(0,r.useState)(0),j=(0,r.useRef)(l);(0,r.useEffect)(()=>{j.current=l});let k=(0,r.useRef)(a);(0,r.useEffect)(()=>{k.current=a});let N=(0,r.useRef)(f);(0,r.useEffect)(()=>{N.current=f}),(0,r.useEffect)(()=>{i&&(N.current=!1,b(!1))},[i]);let C=s[Math.min(y,s.length-1)],S=y>=s.length-1,T=!!m[C?.question]||g,E=(0,r.useCallback)(()=>{j.current||k.current||N.current||s.every(e=>!!m[e.question])&&((0,eN.e)(),N.current=!0,b(!0),o?.(t,"allow","",m))},[s,m,t,o]),R=(0,r.useCallback)(()=>{N.current||k.current||!T||((0,eN.e)(),S?E():w(e=>e+1))},[T,S,E]),M=(0,r.useCallback)(()=>{0!==y&&((0,eN.e)(),w(e=>e-1))},[y]),$=(0,r.useCallback)(()=>{N.current||k.current||j.current||((0,eN.e)(),N.current=!0,b(!0),o?.(t,su,sm))},[t,o]),z=(0,r.useCallback)((e,t,s)=>{if(!N.current){if((0,eN.e)(),!s){x(s=>({...s,[e]:t})),h(t=>t[e]?{...t,[e]:""}:t),S||w(e=>e+1);return}x(s=>{let n=s[e]?s[e].split(", "):[],r=n.indexOf(t);return r>-1?n.splice(r,1):n.push(t),{...s,[e]:n.join(", ")}})}},[S]),P=(0,r.useCallback)(()=>{d||u?.()},[d,u]);(0,r.useEffect)(()=>{if(!d||f||l||a||!C)return;let e=e=>{if(e.target?.tagName==="INPUT"||e.target?.tagName==="TEXTAREA")return;if("Enter"===e.key){e.preventDefault(),R();return}let t=parseInt(e.key,10);if(t>=1&&t<=9&&C.options?.[t-1]){let e=C.options[t-1];z(C.question,e.label,C.multiSelect)}};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[C,f,l,a,R,z,d]);let A=l?"string"==typeof l?function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],s=String(e||"");if(!t.length){let e=aO(s);return e.length?Object.fromEntries(e):null}let n={},r=0;for(let[e,l]of t.entries()){let a=s.indexOf(`"${l}"=`,r);if(-1===a)continue;let i=a+l.length+3,o=t[e+1]?s.indexOf(`"${t[e+1]}"=`,i):-1,c=s.slice(i,-1===o?void 0:o),d=c.lastIndexOf('"');d<=0||(n[l]=aF(c.slice(1,d)),r=i+d)}if(Object.keys(n).length)return n;let l=aO(s);return l.length?Object.fromEntries(l):null}(l,s.map(e=>e.question)):l:null;if(a)return(0,n.jsxs)("div",{className:"my-2 p-3 rounded-brand-lg bg-surface text-[14px] flex flex-col gap-1",children:[(0,n.jsx)("span",{className:"text-text-muted font-medium",children:"Skipped"}),C&&(0,n.jsx)("span",{className:"text-text-muted/70 leading-snug",children:C.question}),!!ss(c).headlessQuestions&&(0,n.jsx)("span",{className:"text-[12px] text-text-muted/60 leading-snug",children:"Headless Antigravity cannot wait for an answer — open it in a terminal (new terminal → Antigravity) to answer questions interactively."})]});if(l)return(0,n.jsxs)("div",{className:"my-2 p-3 rounded-brand-lg border border-success/30 bg-success/10 text-[14px] font-medium flex flex-col gap-1.5",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 text-success",children:[(0,n.jsx)(ev.aJ,{size:14}),(0,n.jsx)("span",{children:"Answered"})]}),s.map((e,t)=>{let s=A?.[e.question];return s?(0,n.jsxs)("div",{className:"flex flex-col gap-0.5",children:[(0,n.jsx)("span",{className:"text-[12px] font-normal text-text-muted leading-snug",children:e.question}),(0,n.jsx)("span",{className:"font-mono text-text pl-2 border-l-2 border-success/40 wrap-anywhere",children:s})]},t):null}),!A&&(0,n.jsx)("span",{className:"font-mono text-text wrap-anywhere",children:String(l)})]});if(!C||!o)return null;let I=m[C.question]||"",D=C.multiSelect&&I?I.split(", "):[I];return(0,n.jsxs)("div",{onPointerDown:P,className:"my-2 p-3 rounded-brand-lg shadow-sm text-[14px] select-none border border-warning/30 bg-warning/[0.06]",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 mb-2 text-warning font-medium",children:[(0,n.jsx)(ev.mN,{size:16,className:"text-warning shrink-0"}),(0,n.jsx)("span",{children:"Question"}),s.length>1&&(0,n.jsxs)("span",{className:"font-mono text-[12px] px-1.5 py-0.5 rounded bg-surface-2 text-text-muted",children:[y+1,"/",s.length]}),C.multiSelect&&(0,n.jsx)("span",{className:"font-mono text-[12px] px-1.5 py-0.5 rounded bg-surface-2 text-text-muted uppercase",children:"multi"})]}),(0,n.jsx)("div",{className:"text-text leading-snug mb-1.5",children:C.question}),C.options?.length>0&&(0,n.jsx)("div",{className:"flex flex-col",children:C.options.map((e,t)=>{let s=D.includes(e.label);return(0,n.jsxs)("button",{type:"button",onClick:()=>z(C.question,e.label,C.multiSelect),className:`px-1.5 py-1 rounded text-left flex items-start gap-2 transition-colors text-[13px] ${s?"bg-brand-500/12":"text-text-muted hover:bg-surface-2 hover:text-text"}`,children:[(0,n.jsx)("span",{className:"font-mono text-[12px] text-text-muted/70 shrink-0 mt-0.5 w-2.5",children:t+1}),(0,n.jsxs)("span",{className:"flex flex-col gap-0.5 min-w-0 flex-1",children:[(0,n.jsx)("span",{className:`font-medium ${s?"text-brand-400":"text-text"}`,children:e.label}),e.description&&(0,n.jsx)("span",{className:"text-[12px] text-text-muted/70 leading-snug",children:e.description})]}),s&&(0,n.jsx)(ev.aJ,{size:12,className:"text-brand-500 shrink-0 mt-0.5"})]},t)})}),(0,n.jsx)("input",{type:"text",value:p[C.question]||"",disabled:f,onFocus:()=>v(!0),onChange:e=>{var t,s;return t=C.question,s=e.target.value,void(h(e=>({...e,[t]:s})),x(e=>({...e,[t]:s})))},onKeyDown:e=>{"Enter"!==e.key||e.nativeEvent?.isComposing||229===e.keyCode||(e.preventDefault(),R())},placeholder:"Type your answer...",className:`w-full px-1.5 py-1 rounded bg-bg border border-border-subtle text-[13px] text-text placeholder-text-muted/70 focus:outline-none focus:border-brand-500 disabled:opacity-40 ${C.options?.length?"mt-1.5":"mt-1"}`}),i&&(0,n.jsx)("div",{className:"mt-1.5 text-[13px] text-danger leading-snug",children:"Not sent — the host did not answer. Try again."}),(0,n.jsxs)("div",{className:"mt-2 flex items-center gap-1.5 justify-end",children:[(0,n.jsx)("button",{type:"button",onClick:$,disabled:f,className:"px-2 py-1 rounded text-[13px] text-text-muted hover:text-text hover:bg-surface-2 transition-colors disabled:opacity-40 disabled:cursor-not-allowed",children:"Skip"}),y>0&&(0,n.jsxs)("button",{type:"button",onClick:M,className:"px-2 py-1 rounded text-[13px] text-text-muted hover:text-text hover:bg-surface-2 transition-colors flex items-center gap-0.5",children:[(0,n.jsx)(ev.JG,{size:13}),(0,n.jsx)("span",{children:"Back"})]}),(0,n.jsxs)("button",{type:"button",onClick:R,disabled:f||!T,className:"px-2.5 py-1 rounded bg-brand-500 hover:bg-brand-600 text-white flex items-center gap-1 text-[13px] font-medium transition-colors disabled:opacity-40 disabled:cursor-not-allowed",children:[(0,n.jsx)("span",{children:S?f?"Sending…":"Submit":"Next"}),S?(0,n.jsx)(ev.Lt,{size:11}):(0,n.jsx)(ev.c_,{size:12})]})]})]})}),aq=(0,r.memo)(function(e){let{text:t="",isLive:s=!1,defaultOpen:l=!1}=e,[a,i]=(0,r.useState)(l);return t?.trim()?(0,n.jsxs)("div",{className:"my-1.5 text-xs select-none",children:[(0,n.jsxs)("button",{type:"button",onClick:()=>i(e=>!e),className:"inline-flex items-center gap-1.5 text-[11px] text-text-muted hover:text-text py-0.5 transition-colors cursor-pointer group",children:[(0,n.jsx)(ev.sU,{size:12,className:s?"animate-pulse text-success":"text-success"}),(0,n.jsx)("span",{className:"italic",children:s?"Thinking...":"Thought process"}),(0,n.jsx)("span",{className:"text-text-muted/50 group-hover:text-text-muted",children:a?(0,n.jsx)(ev.yQ,{size:12}):(0,n.jsx)(ev.c_,{size:12})})]}),a&&(0,n.jsx)("div",{className:"mt-1 pl-3.5 border-l-2 border-border-subtle/80 font-mono text-[11px] text-text-muted leading-relaxed whitespace-pre-wrap max-h-[260px] overflow-y-auto custom-scrollbar select-text py-1",children:t})]}):null}),aU=/Command running in background with ID:\s*([^\s.]+)/,aX=(0,r.memo)(function(e){let t,{id:s="",name:l="Bash",input:a=null,output:i="",error:o="",status:c="done",defaultExpanded:d=!1}=e,{sessionId:u}=aK(),m=!!(o||"error"===c),[x,p]=(0,r.useState)(d),[h,f]=(0,r.useState)(!1),[b,g]=(0,r.useState)(!1),v=a?.command||"",y=a?.description||"",w=o||i||"",j="string"==typeof w?w:w?JSON.stringify(w,null,2):"",k=(t=aU.exec("string"==typeof i?i:""))?t[1]:"",N=!!(a?.run_in_background||k);return(0,n.jsxs)("div",{className:"my-1 text-xs",id:aW(u,"shell",s),children:[(0,n.jsxs)("div",{onClick:()=>p(!x),className:"flex items-start justify-between py-1 px-0 hover:bg-surface-2/40 cursor-pointer data-pane-control select-none transition-colors group/tool",children:[(0,n.jsxs)("div",{className:"flex items-start gap-2 min-w-0 flex-1",children:[(0,n.jsx)("span",{className:"shrink-0 mt-0.5",children:"running"===c?(0,n.jsx)(ev.kr,{size:13,className:"animate-spin text-accent"}):m?(0,n.jsx)(ev.RI,{size:13,className:"text-danger"}):(0,n.jsx)(ev.Jl,{size:13,className:"text-success"})}),(0,n.jsx)("span",{className:`min-w-0 flex-1 text-[11px] leading-relaxed break-words ${y?"text-text":"font-mono text-text wrap-anywhere"}`,title:y||v,children:y||function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";if(!e)return"";let t=e.split(/\n/)[0].replace(/\s*<<-?\s*['"]?[A-Za-z_][A-Za-z0-9_]*['"]?.*$/," <<…");if((t=(t=t.replace(/\s*2?>\s*\/dev\/null/g,"").replace(/\s+/g," ").trim()).replace(/(['"])((?:\\.|(?!\1).){24,})\1/g,(e,t,s)=>s.length<=18?`${t}${s}${t}`:`${t}${s.slice(0,18)}…${t}`)).length>72){let e=t.slice(0,72),s=e.lastIndexOf(" ");t=`${(s>24?e.slice(0,s):e).trimEnd()}…`}return t}(v)||l}),N&&(0,n.jsxs)("span",{className:"font-mono text-[10px] font-semibold text-warning shrink-0 px-1 py-0.5 rounded bg-warning/10",title:k?`Background shell ${k}`:"Running in the background",children:["BG",k?` ${k}`:""]}),j&&(0,n.jsx)("span",{className:"text-text-muted/50 shrink-0",children:x?(0,n.jsx)(ev.yQ,{size:11}):(0,n.jsx)(ev.c_,{size:11})})]}),(0,n.jsx)("div",{className:"flex items-center gap-1 shrink-0 ml-2 opacity-0 group-hover/tool:opacity-100 transition-opacity",children:v&&(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),(0,eN.e)(),navigator.clipboard.writeText(v),f(!0),setTimeout(()=>f(!1),2e3)},className:"p-0.5 text-text-muted hover:text-text rounded hover:bg-surface-3 transition-colors text-[10px] flex items-center gap-0.5",title:"Copy command",children:h?(0,n.jsx)(ev.aJ,{size:11,className:"text-success"}):(0,n.jsx)(ev.QR,{size:11})})})]}),x&&(j||v)&&(0,n.jsxs)("div",{className:"mt-1 ml-3.5 pl-3 border-l-2 border-border-subtle/80 bg-surface-2/20 rounded-r-brand overflow-x-auto max-h-[260px] overflow-y-auto font-mono text-[11px] select-text relative group/out",children:[v&&(0,n.jsxs)("pre",{className:"p-2 pb-1 whitespace-pre-wrap wrap-anywhere leading-relaxed text-text-muted",children:[(0,n.jsx)("span",{className:"select-none opacity-60",children:"$ "}),v]}),j&&(0,n.jsx)("pre",{className:`p-2 whitespace-pre-wrap wrap-anywhere leading-relaxed ${m?"text-danger":"text-text"} ${v?"pt-0":""}`,children:j}),(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),(0,eN.e)(),navigator.clipboard.writeText(j),g(!0),setTimeout(()=>g(!1),2e3)},className:"absolute top-1.5 right-1.5 p-1 rounded bg-surface-3/80 hover:bg-surface-3 text-text-muted hover:text-text opacity-0 group-hover/out:opacity-100 transition-opacity text-[10px]",title:"Copy output",children:b?(0,n.jsx)(ev.aJ,{size:10,className:"text-success"}):(0,n.jsx)(ev.QR,{size:10})})]})]})});function aV(e){let t=String(e||"").split("\n")[0].trim();return t.length>140?`${t.slice(0,140)}…`:t}let aG=(0,r.memo)(function(e){let{id:t="",name:s="Agent",input:l=null,output:a="",error:i="",status:o="done",children:c=[],engine:d="claude",workspacePath:u="",defaultExpanded:m=!1}=e,{sessionId:x}=aK(),p="running"===o,h=!!(i||"error"===o),f=c.filter(e=>"running"===e.status).length,[b,g]=(0,r.useState)(h||m);(0,r.useEffect)(()=>{h&&g(!0)},[h]);let v=lb.has(s),y=v?lg({input:l}):s||"agent",w=v?aV(l?.prompt??l?.description??l?.message):aV(l?.message??l?.prompt??l?.query);return(0,n.jsxs)("div",{className:"my-1 text-xs",id:aW(x,"agent",t),children:[(0,n.jsxs)("div",{onClick:()=>g(!b),className:"flex items-center justify-between py-1 px-0 hover:bg-surface-2/40 cursor-pointer data-pane-control select-none transition-colors group/tool",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[(0,n.jsx)("span",{className:"shrink-0",children:p?(0,n.jsx)(ev.kr,{size:13,className:"animate-spin text-accent"}):h?(0,n.jsx)(ev.RI,{size:13,className:"text-danger"}):(0,n.jsx)(ev.Jl,{size:13,className:"text-success"})}),(0,n.jsx)("span",{className:"font-mono text-[10px] font-semibold text-text uppercase tracking-wider shrink-0 px-1 py-0.5 rounded bg-surface-2/80",children:"AGENT"}),(0,n.jsx)("span",{className:"font-mono text-[11px] font-semibold text-brand-500 shrink-0",children:y}),w&&(0,n.jsx)("span",{className:"text-[11px] text-text-muted truncate min-w-0",title:w,children:w})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2 shrink-0 ml-2",children:[c.length>0&&(0,n.jsxs)("span",{className:"font-mono text-[10px] text-text-subtle",title:`${c.length} sub-agent tool calls`,children:[p&&f>0?`${f}/${c.length}`:c.length," tools"]}),(0,n.jsx)("span",{className:"text-text-muted/50",children:b?(0,n.jsx)(ev.yQ,{size:11}):(0,n.jsx)(ev.c_,{size:11})})]})]}),b&&(0,n.jsxs)("div",{className:"mt-1 ml-3.5 pl-3 border-l-2 border-border-subtle/80 py-1 space-y-0.5",children:[c.length>0?(0,n.jsx)(aI,{total:c.length,children:e=>(e>0?c.slice(e):c).map(e=>a0(d,e,{workspacePath:u})||(0,n.jsx)(aT,{...e,engine:d,workspacePath:u},e.id))}):(0,n.jsx)("div",{className:"text-text-muted italic py-0.5",children:p?"Sub-agent started…":"No tool calls reported."}),!p&&(a||i)&&(0,n.jsx)("div",{className:"mt-1 pl-3 border-l-2 border-border-subtle/60 font-mono text-[11px] max-h-[240px] overflow-y-auto select-text",children:(0,n.jsx)("div",{className:`whitespace-pre-wrap wrap-anywhere leading-relaxed ${h?"text-danger":"text-text-muted"}`,children:"string"==typeof(i||a)?i||a:JSON.stringify(i||a,null,2)})})]})]})}),aJ=(0,r.memo)(function(e){let{toolName:t="EnterPlanMode",input:s={}}=e,r="string"==typeof s?.plan?s.plan.trim():"";if(r)return(0,n.jsx)(aY,{plan:r,explanation:s?.explanation||""});let l="EnterPlanMode"===t,a=s?.reason||(l?"Exploring codebase and designing implementation approach":"Implementation plan finalized");return(0,n.jsxs)("div",{className:`p-3.5 rounded-brand-lg border flex flex-col gap-2 my-2 text-xs ${l?"bg-brand-500/10 border-brand-500/30 text-text":"bg-success/10 border-success/30 text-success"}`,children:[(0,n.jsxs)("div",{className:"flex items-center justify-between font-semibold",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[l?(0,n.jsx)(ev.y8,{size:16,className:"text-brand-500"}):(0,n.jsx)(ev.Jl,{size:16,className:"text-success"}),(0,n.jsx)("span",{children:l?"Plan Mode Activated":"Plan Mode Completed"})]}),(0,n.jsx)("span",{className:"font-mono text-[10px] px-2 py-0.5 rounded bg-surface-2 text-text-muted",children:t})]}),(0,n.jsxs)("div",{className:"text-xs text-text leading-relaxed font-sans pl-6",children:[(0,n.jsx)("span",{className:"text-text-muted",children:"Reason: "}),a]}),l&&(0,n.jsx)("div",{className:"text-[11px] text-text-muted/80 italic pl-6 select-none",children:"Plan mode reads files and drafts an approach — nothing is applied without your review, in whichever CLI this chat is running."})]})}),aY=(0,r.memo)(function(e){let{plan:t,explanation:s=""}=e;return(0,n.jsxs)("div",{className:"p-3.5 rounded-brand-lg border border-brand-500/30 bg-brand-500/10 text-text my-2 text-xs flex flex-col gap-2",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 font-semibold",children:[(0,n.jsx)(ev.y8,{size:16,className:"text-brand-500"}),(0,n.jsx)("span",{children:"Plan"})]}),(0,n.jsx)("pre",{className:"font-mono text-[11px] leading-relaxed whitespace-pre-wrap wrap-anywhere pl-6 max-h-[320px] overflow-y-auto",children:t}),s&&(0,n.jsx)("div",{className:"text-[11px] text-text-muted pl-6 italic",children:s})]})}),aZ=(0,r.memo)(function(e){let{toolName:t="enteredReviewMode",input:s={}}=e,r="enteredReviewMode"===t,l=String(s?.review||"").trim();return(0,n.jsxs)("div",{className:`p-3.5 rounded-brand-lg border flex flex-col gap-2 my-2 text-xs ${r?"bg-brand-500/10 border-brand-500/30 text-text":"bg-success/10 border-success/30 text-success"}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 font-semibold",children:[r?(0,n.jsx)(ev.kU,{size:16,className:"text-brand-500"}):(0,n.jsx)(ev.Jl,{size:16,className:"text-success"}),(0,n.jsx)("span",{children:r?"Code review started":"Code review finished"})]}),l&&(0,n.jsxs)("div",{className:"text-xs text-text leading-relaxed font-sans pl-6",children:[(0,n.jsx)("span",{className:"text-text-muted",children:"Reviewing: "}),l]})]})}),aQ={bash:(e,t,s)=>(0,n.jsx)(aX,{...e,deferred:t,defaultExpanded:s?.defaultExpanded},e.id),agent:(e,t,s)=>{let{engine:r,workspacePath:l,defaultExpanded:a}=s;return(0,n.jsx)(aG,{...e,engine:r,workspacePath:l,defaultExpanded:a},e.id)},plan:e=>(0,n.jsx)(aJ,{toolName:e.name,input:e.input},e.id),review:e=>(0,n.jsx)(aZ,{toolName:e.name,input:e.input},e.id),question:(e,t,s)=>{if("running"===e.status||!e.output&&!e.error)return null;let r=!!ss(s?.engine).headlessQuestions&&/user skipped/i.test(String(e.output||""));return(0,n.jsx)(aH,{engine:s?.engine,questions:e.input?.questions||[],answers:r||e.error?null:e.output||"",declined:r||!!e.error||"error"===e.status},e.id)}};function a0(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=aQ[sn(e,t.name)];return n?n(t,s.deferred,{...s,engine:e}):null}var a1=s(7601),a2=s(46118);function a5(e,t){let s=window.__TAURI__?.opener;s?.openUrl&&(e.preventDefault(),s.openUrl(t).catch(()=>{}))}let a3=(e,t)=>function(s){let{children:r,className:l,node:a,...i}=s;return(0,n.jsx)(e,{className:l?`${t} ${l}`:t,...i,children:r})},a4={h1:a3("h1","text-xl sm:text-2xl font-bold border-b border-border-subtle pb-2 mt-5 mb-3 text-text first:mt-0"),h2:a3("h2","text-lg sm:text-xl font-bold border-b border-border-subtle pb-1.5 mt-4 mb-2.5 text-text first:mt-0"),h3:a3("h3","text-base sm:text-lg font-semibold mt-3.5 mb-2 text-text"),h4:a3("h4","text-sm sm:text-base font-semibold mt-3 mb-1.5 text-text"),h5:a3("h5","text-xs sm:text-sm font-semibold mt-2.5 mb-1 text-text"),h6:a3("h6","text-xs font-semibold mt-2 mb-1 text-text-muted"),p:a3("p","my-2 leading-relaxed text-text text-sm"),ul:a3("ul","list-disc pl-5 my-2 space-y-1 text-sm text-text"),ol:a3("ol","list-decimal pl-5 my-2 space-y-1 text-sm text-text"),li:a3("li","leading-relaxed"),blockquote:a3("blockquote","border-l-4 border-brand-500/40 pl-3.5 my-2.5 text-text-muted italic text-sm"),th:a3("th","border border-border-subtle bg-surface-2 px-3 py-1.5 font-semibold text-left text-text align-top wrap-anywhere min-w-[80px]"),td:a3("td","border border-border-subtle px-3 py-1.5 text-text align-top wrap-anywhere min-w-[80px]"),hr:a3("hr","border-t border-border-subtle my-4"),img:e=>{let{alt:t="",node:s,...r}=e;return(0,n.jsx)("img",{className:"max-w-full h-auto rounded my-2",alt:t,...r})},a:e=>{let{children:t,className:s,href:r,node:l,...a}=e;return(0,n.jsx)("a",{className:`text-brand-500 hover:underline wrap-anywhere${s?` ${s}`:""}`,target:"_blank",rel:"noopener noreferrer",onClick:e=>a5(e,r),...a,children:t})},table:e=>{let{children:t,node:s,...r}=e;return(0,n.jsx)("div",{className:"my-3 overflow-x-auto custom-scrollbar",children:(0,n.jsx)("table",{className:"w-full table-auto border-collapse border border-border-subtle text-xs",...r,children:t})})},pre:function(e){let{children:t,node:s,...l}=e,[a,i]=(0,r.useState)(!1),o=(0,r.useRef)(null);return(0,n.jsxs)("div",{className:"relative group/code my-2.5",children:[(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),(0,eN.e)();let t=o.current?.innerText||"";try{navigator.clipboard.writeText(t)}catch{}i(!0),setTimeout(()=>i(!1),2e3)},className:"absolute top-2 right-2 p-1 rounded bg-surface-3/80 hover:bg-surface-3 text-text-muted hover:text-text opacity-100 sm:opacity-0 sm:group-hover/code:opacity-100 transition-opacity z-10",title:"Copy code",children:a?(0,n.jsx)(ev.aJ,{size:13,className:"text-brand-500"}):(0,n.jsx)(ev.QR,{size:13})}),(0,n.jsx)("pre",{ref:o,className:"p-3 rounded bg-surface-2 whitespace-pre-wrap break-words text-[12px] font-mono border border-border-subtle text-text [&_code]:bg-transparent [&_code]:p-0 [&_code]:border-0 [&_code]:text-text",...l,children:t})]})},code:e=>{let{children:t,className:s,node:r,...l}=e,a=/language-/.test(s||"");return(0,n.jsx)("code",{className:`${a?"font-mono text-[12px] text-text":"font-mono text-[0.9em] text-accent wrap-anywhere"}${s?` ${s}`:""}`,...l,children:t})},input:e=>{let{type:t,checked:s,node:r,...l}=e;return"checkbox"===t?(0,n.jsx)("input",{type:"checkbox",checked:s,readOnly:!0,className:"mr-2 rounded accent-brand-500 cursor-default",...l}):(0,n.jsx)("input",{type:t,...l})}},a6=(0,r.memo)(function(e){let{content:t,components:s}=e;return(0,n.jsx)(a1.oz,{remarkPlugins:[a2.A],components:s?{...a4,...s}:a4,children:t})},(e,t)=>e.content===t.content);function a8(e){let{row:t,engine:s,workspacePath:r,deferred:l}=e;if("thought"===t.kind)return(0,n.jsx)(aq,{text:t.text,isLive:t.isLive});if("diff"===t.kind){let e=t.diff;return(0,n.jsx)(aL,{file:e.file,patch:e.patch,diff:e.diff,content:e.content,workspacePath:r})}let a=t.tool;return a0(s,a,{workspacePath:r,deferred:l})||(0,n.jsx)(aT,{...a,engine:s,workspacePath:r,deferred:l})}let a9={info:"text-text-muted",suggestion:"text-text-muted",warning:"text-warning",error:"text-danger"};function a7(e){let{notice:t}=e;if(!t?.content)return null;let s=`text-xs leading-relaxed py-1 px-2 my-0.5 rounded border-l-2 border-current/30 bg-surface-2/40 wrap-anywhere ${a9[t.level]||a9.info}`;return t.compacting?(0,n.jsxs)("div",{className:`${s} flex items-center gap-2`,children:[(0,n.jsx)(ev.kr,{size:12,className:"animate-spin text-brand-500 shrink-0"}),(0,n.jsx)("span",{children:t.content}),(0,n.jsx)(it,{})]}):(0,n.jsxs)("div",{className:s,children:[t.content,t.compact?.detail&&(0,n.jsxs)("span",{className:"text-text-muted",children:[" \xb7 ",t.compact.detail]}),t.compact?.durationMs?(0,n.jsxs)("span",{className:"text-text-muted",children:[" \xb7 ",ie(t.compact.durationMs)]}):null]})}function ie(e){let t=e/1e3;return t<60?`${t.toFixed(1)}s`:`${Math.floor(t/60)}m ${Math.round(t%60)}s`}function it(){let[e]=(0,r.useState)(()=>Date.now()),[t,s]=(0,r.useState)(e);return(0,r.useEffect)(()=>{let e=setInterval(()=>s(Date.now()),1e3);return()=>clearInterval(e)},[]),(0,n.jsx)("span",{className:"text-text-muted/70 tabular-nums",children:ie(t-e)})}function is(e){let{content:t,isLive:s,images:l=[],fileBus:a=null}=e,i=function(e,t){let[s,n]=(0,r.useState)(e),l=(0,r.useRef)(e);return(0,r.useEffect)(()=>{l.current=e},[e]),(0,r.useEffect)(()=>{if(!t)return;let e=setInterval(()=>{n(e=>e===l.current?e:l.current)},80);return()=>clearInterval(e)},[t]),t?s:e}(t,s);return(0,n.jsx)("div",{className:"flex justify-start mb-3 mt-1",children:(0,n.jsxs)("div",{className:"max-w-[94%] @2xl:max-w-[768px] min-w-0 px-3.5 py-2 rounded-[16px] rounded-tl-[4px] bg-[var(--chat-bubble-theirs)] shadow-[0_1px_2px_rgba(0,0,0,0.08)] text-sm leading-relaxed text-[var(--chat-bubble-theirs-text)] wrap-anywhere",children:[(0,n.jsx)(a6,{content:i}),s&&(0,n.jsx)("span",{className:"inline-block w-1.5 h-3.5 bg-brand-500 animate-pulse ml-1 align-middle"}),l.length>0&&(0,n.jsx)("div",{className:"mt-2 flex flex-wrap gap-1",children:l.map((e,t)=>(0,n.jsx)(aN,{img:e,fileBus:a,images:l,index:t},`${e.path}-${t}`))})]})})}let ir=(0,r.memo)(function(e){let{messages:t=[],engine:s="claude",workspacePath:l="",onResolvePermission:a,isLive:i=!0,fileBus:o=null,showImages:c=!0}=e,d=(0,r.useMemo)(()=>(function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"claude",s=[],n=new Set;for(let r of e){if("notice"===r.role){s.push({kind:"notice",id:r.id,notice:{subtype:r.subtype,level:r.level,content:r.content,...r.compact?{compact:r.compact}:null,...r.compacting?{compacting:!0}:null}});continue}if("assistant"!==r.role)continue;r.thinking?.trim()&&s.push({kind:"thought",id:`${r.id}-th`,text:r.thinking});let e=function(e,t,s){return(t||[]).filter(t=>!(!t||!t.name||(s||[]).some(e=>{let s;return e.file&&(s=e.file,aM.has(t?.name)&&s&&((t.input?.paths||[]).includes(s)||a$(t.input)===s))})||"task"===sn(e,t.name)&&aE.has(t.name)))}(t,r.tools,r.diffs);for(let l=0;l<e.length;l++){let a=e[l];if("question"===sn(t,a.name)&&"running"===a.status&&aR(t))continue;let i=a.id||`${r.id}-t${l}`;n.has(i)||(n.add(i),s.push({kind:"tool",id:i,tool:a,engine:t}))}for(let e=0;e<(r.diffs?.length||0);e++){let t=r.diffs[e];s.push({kind:"diff",id:`${r.id}-d${e}`,diff:t})}r.content&&s.push({kind:"prose",id:`${r.id}-p`,content:r.content,isLive:r.isLive}),r.permission&&s.push({kind:"permission",id:`${r.id}-perm`,permission:r.permission})}return s})(t,s),[t,s]),u=(0,r.useMemo)(()=>(function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:6,{deferred:s=!1}=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=[];for(let t of e)if(aA(t)){let e=n[n.length-1];e?.type==="steps"?e.rows.push(t):n.push({type:"steps",rows:[t]})}else n.push({type:"row",row:t});return n.map((e,n)=>{if("steps"!==e.type)return{...e,key:`r${n}`,deferred:s};let r=e.rows.length>t+1?e.rows.length-t:0;return{type:"steps",key:`s${n}`,rows:e.rows,hidden:r,deferred:s}})})(d,3,{deferred:!i}),[d,i]),m=(0,r.useMemo)(()=>(function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=[],s=new Set,n=e=>{let r=e?.input,l="string"==typeof r?"":aP.map(e=>r?.[e]).find(e=>"string"==typeof e&&e);for(let r of(l&&az.test(l)&&!s.has(l)&&(s.add(l),t.push({path:l,name:String(l).split(/[/\\]/).pop()||l,toolName:e?.name})),e?.children||[]))n(r)};for(let t of e)"tool"===t.kind&&n(t.tool);return t})(d),[d]),x=(0,r.useMemo)(()=>{for(let e=d.length-1;e>=0;e--)if("prose"===d[e].kind)return d[e].id;return null},[d]);return(0,n.jsx)("div",{className:"my-1",children:u.map(e=>{if("steps"!==e.type){if("prose"===e.row.kind){let t=e.row.id===x;return(0,n.jsx)(is,{content:e.row.content,isLive:i&&e.row.isLive,images:t&&c?m:[],fileBus:t&&c?o:null},e.key)}if("notice"===e.row.kind)return(0,n.jsx)(a7,{notice:e.row.notice},e.key);if("permission"===e.row.kind){let t=e.row.permission;return(0,n.jsx)(aH,{requestId:t.requestId,questions:t.input?.questions||[],onResolve:a},e.key)}return null}return(0,n.jsx)("div",{className:"relative pl-2.5 border-l-2 border-border-subtle/50 my-1",children:(0,n.jsx)(aI,{total:e.rows.length,children:t=>(t>0?e.rows.slice(t):e.rows).map(e=>(0,n.jsx)(a8,{row:e,engine:s,workspacePath:l,deferred:!i},e.id))})},e.key)})})},(e,t)=>{if(e.messages.length!==t.messages.length)return!1;for(let s=0;s<e.messages.length;s++)if(e.messages[s]!==t.messages[s])return!1;return e.engine===t.engine&&e.workspacePath===t.workspacePath&&e.isLive===t.isLive&&e.showImages===t.showImages&&e.onResolvePermission===t.onResolvePermission});function il(e){let{background:t=!1,engine:s="claude",size:r=16,className:l=""}=e;if(t)return(0,n.jsx)(ev.BK,{size:r,className:l||"text-text"});let a=tu(s);return a?(0,n.jsx)("img",{src:a,alt:s,draggable:!1,style:{width:r,height:r},className:`flex-shrink-0 object-contain ${td} ${l}`}):(0,n.jsx)(ev.cC,{size:r,className:l||"text-text"})}let ia=(0,r.memo)(function(e){let{tasks:t=[],messages:s=[],engine:l="claude",sessionId:a="",onStopTask:i,onClose:o}=e,[c,d]=(0,r.useState)(()=>Date.now()),[u,m]=(0,r.useState)(null),x=l4(e=>e.bySession[a]?.harnessTasks);(0,r.useEffect)(()=>{let e=setInterval(()=>d(Date.now()),1e3);return()=>clearInterval(e)},[]);let p=(0,r.useMemo)(()=>t.map(e=>x?.find(t=>t.taskId===e.taskId)||e),[t,x]),h=p.find(e=>e.taskId===u)||p[0];if(!h)return null;let f=lD(h,c),b=!h.endedAt&&("running"===h.status||"paused"===h.status);return(0,n.jsxs)(rb,{icon:(0,n.jsx)(il,{background:h.background,engine:l,size:16}),iconClass:"",title:h.description||h.subagentType||"Task",subtitle:b?`Running for ${av(f)}`:`Ended \xb7 ${av(f)}`,onClose:o,actions:b&&h.taskId&&i?(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eN.e)(),i(h.taskId)},className:"px-2.5 py-1 rounded-brand text-xs font-medium text-danger bg-danger/10 hover:bg-danger/20 transition-colors flex items-center gap-1.5",title:"Stop this task",children:[(0,n.jsx)(ev.M6,{size:10,className:"fill-current"}),(0,n.jsx)("span",{children:"Stop"})]}):null,children:[p.length>1&&(0,n.jsx)("div",{className:"px-4 py-2 border-b border-border-subtle bg-bg flex items-center gap-1 overflow-x-auto custom-scrollbar shrink-0",children:p.map((e,t)=>{let s=e.taskId===h.taskId;return(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eN.e)(),m(e.taskId)},className:`shrink-0 flex items-center gap-1.5 px-2.5 py-1 rounded-brand text-xs transition-colors ${s?"bg-surface-2 text-text font-medium":"text-text-muted hover:text-text hover:bg-surface-2/40"}`,children:[(0,n.jsx)(il,{background:e.background,engine:l,size:13,className:s?"opacity-100":"opacity-60"}),(0,n.jsx)("span",{className:"truncate max-w-[140px]",children:e.description||e.subagentType||e.taskId}),(0,n.jsx)("span",{className:"font-mono text-[10px] opacity-60 tabular-nums",children:"running"===e.status?av(lD(e,c)):e.status})]},e.taskId||e.id||t)})}),(0,n.jsxs)("div",{className:"p-3 flex-1 overflow-y-auto custom-scrollbar",children:[(0,n.jsx)(ii,{task:h,messages:s,engine:l,running:b}),h.summary&&(0,n.jsx)("p",{className:"mt-3 text-[11px] text-text-muted leading-relaxed",children:h.summary}),h.outputFile&&(0,n.jsxs)("p",{className:"mt-3 font-mono text-[10px] text-text-subtle truncate",title:h.outputFile,children:["output \xb7 ",h.outputFile]})]})]})});function ii(e){let{task:t,messages:s,engine:r,running:l}=e,a=ly(s,t.toolUseId);if(!a)return(0,n.jsx)("div",{className:"flex flex-col items-center justify-center gap-2.5 py-14 text-text-muted select-none",children:l?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(ev.kr,{size:24,className:"animate-spin text-brand-500 opacity-80"}),(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("div",{className:"text-xs font-medium text-text",children:"Task is running..."}),(0,n.jsx)("div",{className:"text-[11px] text-text-subtle mt-0.5",children:"Waiting for task calls or tool events"})]})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(il,{background:t.background,engine:r,size:28,className:"opacity-40"}),(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("div",{className:"text-xs font-medium text-text",children:"No calls recorded"}),(0,n.jsx)("div",{className:"text-[11px] text-text-subtle mt-0.5",children:"This task ended without child tool calls"})]})]})});let i=a.children?.length?a.children:[a],o=a.input?.prompt||a.input?.description||"",c=a.error||a.output||"";return(0,n.jsxs)("div",{className:"flex flex-col",children:[o&&!a.async&&(0,n.jsx)(ay,{message:{id:`${a.id}:p`,role:"user",content:o},engine:r}),i.map(e=>a0(r,e,{deferred:!l,workspacePath:""})||(0,n.jsx)(aT,{...e,engine:r,workspacePath:"",deferred:!l},e.id)),!l&&c&&(0,n.jsx)(ir,{messages:[{id:`${a.id}:r`,role:"assistant",content:String(c),isLive:!1}],engine:r,isLive:!1})]})}let io=[{start:0,until:50,pct:[0,70],key:"menu.updateInstalling"},{start:50,until:80,pct:[70,90],key:"menu.updateRestarting"},{start:80,until:95,pct:[90,99],key:"menu.updateReconnecting"}],ic=io[io.length-1];function id(e){let{className:t=""}=e,{t:s}=(0,eC.s)(),[l,a]=(0,r.useState)(0);(0,r.useEffect)(()=>{let e=Date.now(),t=setInterval(()=>a((Date.now()-e)/1e3),500);return()=>clearInterval(t)},[]);let i=io.find(e=>l<e.until)||ic,o=Math.min(1,Math.max(0,(l-i.start)/(i.until-i.start))),c=Math.round(i.pct[0]+(i.pct[1]-i.pct[0])*o);return(0,n.jsxs)("div",{className:`flex items-center gap-2 min-w-0 ${t}`,title:`${s(i.key)} — ${c}%`,children:[(0,n.jsx)(ev.kr,{size:12,className:"animate-spin text-brand-400 shrink-0"}),(0,n.jsx)("span",{className:"h-1 flex-1 min-w-[60px] rounded-full bg-surface-2 overflow-hidden",children:(0,n.jsx)("span",{className:"block h-full bg-brand-500 rounded-full transition-[width] duration-500 ease-out",style:{width:`${c}%`}})})]})}function iu(e){let{hostKey:t,approval:s,onDeleteHost:r=null}=e,{t:l}=(0,eC.s)();if(!s)return null;let a="pending"===s;return(0,n.jsxs)("div",{className:`flex items-center gap-2 py-1.5 ${a?"":"text-red-400"}`,children:[a?(0,n.jsx)(ev.kr,{size:14,className:"animate-spin text-text-subtle shrink-0"}):(0,n.jsx)(ev.MA,{size:14,className:"shrink-0"}),(0,n.jsx)("span",{className:"text-[11px] truncate flex-1 min-w-0",title:l(a?"connection.approvalHint":"connection.rejectedDescription"),children:l(a?"connection.waitingApproval":"connection.rejectedTitle")}),(0,n.jsx)("button",{type:"button",onClick:()=>{(0,eN.e)(),P.rh.getState().connectHost(t)},className:"px-2 py-0.5 text-[11px] text-text-muted hover:text-text bg-surface-2 hover:bg-surface-3 rounded-brand transition-colors shrink-0",children:l("common.retry")}),a?(0,n.jsx)("button",{type:"button",onClick:()=>{(0,eN.e)(),P.rh.getState().disconnectHost(t)},className:"px-2 py-0.5 text-[11px] text-text-muted hover:text-text bg-surface-2 hover:bg-surface-3 rounded-brand transition-colors shrink-0",children:l("common.cancel")}):r&&(0,n.jsx)("button",{type:"button",onClick:()=>{(0,eN.e)(),r(t)},className:"px-2 py-0.5 text-[11px] text-red-400 hover:text-red-300 bg-red-500/10 hover:bg-red-500/20 rounded-brand transition-colors shrink-0",children:l("hosts.removeHost")})]})}let im=[];function ix(e){let{host:t,actions:s={},busRef:l=null,activeSessionId:a=null,activeWorkspaceId:i=null,connected:o=!0,fileBus:c=null,homeDir:d=null,hiddenPaneSessionIds:u=[],onUnhidePane:m=null,onAddWorkspace:x=null,menuAddWorkspace:p=null,onOpenRemoteHost:h=null,onOpenMobileHost:f=null,onRowContextMenu:b=null,onRowTouch:g=null,onRowMenu:v=null,agentBySession:y=null,cwdBySession:w=null,treeCls:j="pl-3.5",mobile:k=!1,onResumeAgentSession:N=null,rowCls:C="hover:bg-text/5 hover:text-text"}=e,{t:S}=(0,eC.s)(),{isCollapsed:T,toggle:E}=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",[t,s]=(0,r.useState)(()=>new Set(lo()[e]||[])),n=(0,r.useCallback)(t=>{s(s=>{let n=new Set(s);n.has(t)?n.delete(t):n.add(t);let r=lo();r[e]=[...n];try{localStorage.setItem(la,JSON.stringify(r))}catch{}return n})},[e]);return{isCollapsed:(0,r.useCallback)(e=>t.has(e),[t]),toggle:n}}(t.key),R=!T(li),[M,$]=(0,r.useState)(null),[z,A]=(0,r.useState)(null),[I,D]=(0,r.useState)(null),[L,B]=(0,r.useState)(null),[F,O]=(0,r.useState)(null),[_,K]=(0,r.useState)(!1),[W,H]=(0,r.useState)([]),[q,U]=(0,r.useState)(!1),X=t.status||"full",V="connecting"===X,G="full"===X||"online"===X,J="full"===X?o:G,Y="full"!==X?eH(t.key):null,Z=l||Y?.busRef||null;(0,r.useEffect)(()=>{null!==M&&Z?.current?.emit&&Z.current.emit("getShells",e=>H(e?.shells||[]))},[M,Z]);let Q=e=>{(0,eN.e)(),s.selectSession?.(e)},{dragId:ee,registerEl:et,startDrag:es,consumeClick:en}=n9({axis:"y",onTap:Q,onCommit:e=>s.reorderSession?.(e)}),er=(0,r.useRef)(null),el=()=>{er.current&&(clearTimeout(er.current.timer),er.current=null)},ea=e=>{let t=er.current;t&&(Math.abs(e.clientX-t.start.x)>ez.Qe||Math.abs(e.clientY-t.start.y)>ez.Qe)&&el()};(0,r.useEffect)(()=>{if(!ee)return;let e=e=>e.preventDefault();return window.addEventListener("touchmove",e,{passive:!1}),()=>window.removeEventListener("touchmove",e)},[ee]);let ei=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],s=new Set(t.map(e=>e.id)),n=new Map;for(let t of e){let e=s.has(t.workspaceId)?t.workspaceId:null;n.has(e)||n.set(e,[]),n.get(e).push(t)}return[...t.map(e=>({workspace:e,sessions:n.get(e.id)||[]})),...n.has(null)?[{workspace:null,sessions:n.get(null)}]:[]]}(t.sessions,t.workspaces),eo=(0,r.useMemo)(()=>new Set((t.sessions||[]).map(e=>e.id)),[t.sessions]);return(0,n.jsxs)("div",{children:[(0,n.jsx)(ll,{mobile:k,hostKey:t.key,label:t.label,connected:G,connecting:V,mutedOffline:"full"!==X,collapsed:!R,meta:V?(0,n.jsx)(ev.kr,{size:12,className:"animate-spin text-text-subtle"}):null,hostUpdating:!!t.updating,onOpenRemote:G&&t.remoteAvailable&&h?()=>h(t.key):null,onOpenMobile:G&&t.mobileAvailable&&f&&!t.updating?()=>f(t.key):null,onToggleCollapse:G?()=>{(0,eN.e)(),R||P.rh.getState().ensureHost(t.key),E(li)}:null,onConnect:"offline"===X?t.onConnect||(()=>P.rh.getState().connectHost(t.key)):null,onDisconnect:t.onDisconnect,onAddWorkspace:J?p??("full"!==X?()=>K(!0):null):null,onRename:s.renameHost,onDelete:s.deleteHost,showAdd:!1}),t.updating?(0,n.jsx)("div",{className:`${j} py-2`,children:(0,n.jsx)(id,{})}):t.approval?(0,n.jsx)("div",{className:j,children:(0,n.jsx)(iu,{hostKey:t.key,approval:t.approval,onDeleteHost:s.deleteHost})}):R&&G&&(0,n.jsxs)("div",{className:j,children:[t.updateAvailable&&t.canSelfUpdate&&!t.approval&&(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eN.e)(),U(!0)},title:S("menu.updateAvailableTitle"),className:"flex items-center gap-1.5 px-2 py-1 mb-1 max-w-full text-[11px] font-medium text-brand-400 hover:text-brand-300 bg-brand-500/10 hover:bg-brand-500/20 rounded-brand transition-colors",children:[(0,n.jsx)(ev.f5,{size:12,className:"shrink-0"}),(0,n.jsxs)("span",{className:"truncate",children:[S("menu.updateNow"),t.updateAvailable?.version?` \xb7 ${t.updateAvailable.version}`:""]})]}),ei.map(e=>{let{workspace:o,sessions:x}=e,h=o?.id??null,f=h??"ungrouped",j=i===h;return(0,n.jsxs)("div",{className:`flex flex-col ${k?"":"mt-1 first:mt-0"}`,children:[(0,n.jsx)(lh,{mobile:k,workspace:{id:h,name:o?.name||S("workspaces.ungrouped"),path:o?.path||null,items:x},isActive:j,connected:J,fileBus:c,statusMap:t.statusMap,collapsed:T(f),onToggleCollapse:()=>E(f),onSelect:s.selectWorkspace?()=>{(0,eN.e)(),s.selectWorkspace(h)}:null,onNewTerminal:s.createSession?()=>$(f):null,onAddWorkspace:p,onRename:s.renameWorkspace&&null!=h?()=>A({id:h,value:o.name}):null,onDelete:s.deleteWorkspace&&null!=h?()=>D({id:h,name:o.name}):null}),!T(f)&&x.map((e,l)=>{let i=t.statusMap?.[e.id]?.state||"idle",p=nx(i),j=a===e.id,N=ee===e.id,T=u.includes(e.id),E=e.name||S("terminal.defaultName");return(0,n.jsx)(r.Fragment,{children:(0,n.jsxs)("div",{ref:et(e.id),"data-sid":e.id,style:k?{"--i":String(Math.min(l,6))}:void 0,className:`group flex items-center gap-1.5 ${k?"pl-6 pr-9 list-rise":"pl-3.5 pr-2"} py-1.5 ml-0.5 rounded-[3px] text-left relative cursor-pointer select-none touch-manipulation touch-pan-y ${j?"bg-brand-500/15 text-text":`text-text/85 active:bg-text/[0.06] ${C}`} ${N?"z-20 opacity-90 shadow-lg ring-1 ring-brand-500":"transition-colors"}`,onClick:()=>{en()||Q(e.id)},onPointerDown:t=>((e,t,s)=>{if(s.length<2||!J)return;if("mouse"===e.pointerType)return void es(e,t,s);if(g)return;let n={x:e.clientX,y:e.clientY};er.current={timer:setTimeout(()=>{el(),(0,eN.e)(),es(e,t,s)},ez.A_),start:n}})(t,e.id,x.map(e=>e.id)),onPointerMove:ea,onPointerUp:el,onPointerCancel:el,onPointerLeave:el,onContextMenu:b?t=>b(t,e.id,E):void 0,onTouchStart:g?.start,onTouchMove:g?.move,onTouchEnd:g?.end,children:[J&&(0,n.jsx)("button",{"data-gid":"ungrouped"===f?"":h,"data-sid":e.id,onPointerDown:t=>{t.stopPropagation(),es(t,e.id,x.map(e=>e.id))},disabled:x.length<2,className:"absolute left-0 top-1/2 -translate-y-1/2 z-10 p-0.5 text-text-subtle opacity-0 group-hover:opacity-100 cursor-grab active:cursor-grabbing touch-none disabled:opacity-0 disabled:cursor-default",tabIndex:-1,children:(0,n.jsx)(ev.f2,{size:12})}),(0,n.jsx)("span",{className:`w-2 h-2 rounded-full flex-shrink-0 term-dot ${p.cls}${p.pulse?` pulse-${p.pulse}`:""}`,style:{background:p.dot}}),(0,n.jsxs)("span",{className:"flex-1 min-w-0 flex flex-col",children:[(0,n.jsxs)("span",{className:`flex items-center gap-1.5 min-w-0 ${j?"font-medium":""}`,children:[(0,n.jsx)(nM,{agent:y?.[e.id]??e.agent,tool:t.statusMap?.[e.id]?.tool}),(0,n.jsx)("span",{className:`${k?"text-[17px]":"text-[11px]"} truncate`,"data-tip":E,children:E}),T&&m&&(0,n.jsx)("button",{type:"button",tabIndex:-1,onPointerDown:e=>e.stopPropagation(),onMouseDown:e=>e.stopPropagation(),onClick:t=>{t.stopPropagation(),(0,eN.e)(),m(e.id)},className:"p-0.5 rounded text-amber-400 hover:text-amber-300 hover:bg-amber-400/20 transition-colors flex items-center justify-center shrink-0 ml-1",title:S("sessions.showPanel")||"Show panel",children:(0,n.jsx)(ev.X_,{size:12})})]}),(0,n.jsx)(lf,{mobile:k,fileBus:c,cwd:w?.[e.id]??e.cwd??e.workspacePath,basePath:nS({path:o?.path||null,items:x}),homeDir:d})]}),(0,n.jsx)("div",{className:`absolute right-1 top-1/2 -translate-y-1/2 flex items-center ${k?"opacity-100":"px-1 rounded-[3px] bg-surface-2 opacity-0 group-hover:opacity-100 [@media(hover:none)]:opacity-60"} transition-opacity`,children:v?(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),(0,eN.e)();let s=t.currentTarget.getBoundingClientRect();v(e.id,E,s)},className:"p-0.5 text-text-subtle hover:text-text rounded-[2px] transition-colors",title:S("sessions.sessionActions"),children:(0,n.jsx)(ev.a4,{size:k?18:13.5})}):(0,n.jsx)(r7,{size:k?18:13.5,label:S("sessions.sessionActions"),revealCls:"",items:["done"===i&&{icon:ev.aJ,label:S("sessions.markRead"),amber:!0,onClick:()=>eL.getState().clearNotification(e.id)},s.renameSession&&{icon:ev.gH,label:S("sessions.editName"),onClick:()=>B({id:e.id,value:e.name||""})},s.backgroundSession&&{icon:ev._V,label:S("menu.terminalBackground"),onClick:()=>s.backgroundSession(e)},s.deleteSession&&{icon:ev.TB,label:S("sessions.deleteTitle"),danger:!0,onClick:()=>O({id:e.id,name:e.name||""})}]})})]})},e.id)}),!T(f)&&l&&(0,n.jsx)(ip,{busRef:l,storeKey:h??"default",workspaceId:h,mobile:k,rowCls:C,onSelectWorkspace:s.selectWorkspace?()=>s.selectWorkspace(h):null}),!T(f)&&(k?(0,n.jsxs)("button",{onClick:()=>{(0,eN.e)(),$(f)},disabled:!J,className:"w-full flex items-center gap-1.5 pl-[38px] py-1.5 text-left text-[15px] text-text-muted hover:text-brand-500 transition-colors disabled:opacity-40",title:S("workspaces.addTerminal"),children:[(0,n.jsx)(ev.FW,{size:15,className:"flex-shrink-0"}),(0,n.jsx)("span",{children:S("terminal.newTerminal")})]}):0===x.length?(0,n.jsxs)("button",{onClick:()=>{(0,eN.e)(),$(f)},disabled:!J,className:"w-full flex items-center gap-1.5 pl-3.5 pr-2 py-1.5 text-left text-[12px] text-text-subtle hover:text-brand-500 transition-colors disabled:opacity-40",title:S("workspaces.addTerminal"),children:[(0,n.jsx)(ev.FW,{size:12,className:"flex-shrink-0"}),(0,n.jsx)("span",{children:S("terminal.newTerminal")})]}):null)]},f)}),(0,n.jsxs)("button",{onClick:()=>{(0,eN.e)(),x?x():K(!0)},disabled:!J,className:`w-full flex items-center gap-1.5 ${k?"text-[15px] text-text-muted":"text-[12px] mt-1 text-text-subtle"} py-1.5 text-left hover:text-brand-500 transition-colors disabled:opacity-40`,title:S("workspaces.newWorkspace"),children:[(0,n.jsx)(ev.FW,{size:k?18:12,className:"flex-shrink-0"}),(0,n.jsx)("span",{children:S("workspaces.newWorkspace")})]})]}),null!==M&&(0,n.jsx)(n1,{onClose:()=>$(null),onCreate:(e,t,n,r,l,a)=>{s.createSession?.(e,"ungrouped"===M?null:M,t,l,n,r,a),$(null)},shells:W,busRef:Z,hostKey:t.key,onResumeAgentSession:N,onSelectSession:s.selectSession,liveSessionIds:eo,connected:J,workspaceId:"ungrouped"===M?null:M,workspacePath:t.workspaces?.find(e=>e.id===("ungrouped"===M?null:M))?.path||null,workspaceName:"ungrouped"===M?S("workspaces.ungrouped"):t.workspaces?.find(e=>e.id===M)?.name||"",suggestName:`${S("terminal.defaultName")} ${(t.sessions?.length||0)+1}`}),_&&Y&&(0,n.jsx)(nG,{fileBus:Y.fileBus,scope:Y.scope,onSelect:e=>{if(K(!1),!e)return;let t=e.split("/").filter(Boolean).pop()||e;eM(e,Y.scope),s.createWorkspace?.(t,e,t=>{let n=t?.workspace||t?.group;t?.success&&n?.id&&s.createSession?.(null,n.id,null,e)})},onClose:()=>K(!1)}),null!==z&&(0,n.jsx)(nL,{title:S("workspaces.rename"),value:z.value,onChange:e=>A({...z,value:e}),onSubmit:()=>{let e=z.value.trim();e&&s.renameWorkspace?.(z.id,e),A(null)},onClose:()=>A(null)}),null!==I&&(0,n.jsx)(ek.A,{isOpen:!0,onClose:()=>D(null),onConfirm:()=>{s.deleteWorkspace?.(I.id),D(null)},title:S("workspaces.deleteTitle"),message:S("workspaces.deleteMessage",{name:I.name}),confirmText:S("common.delete")}),(0,n.jsx)(ek.A,{isOpen:q,onClose:()=>U(!1),onConfirm:()=>{U(!1),P.rh.getState().requestHostUpdate(t.key,"update")},title:S("menu.updateConfirmTitle"),message:S("menu.updateConfirmMessage")}),null!==L&&(0,n.jsx)(nL,{title:S("sessions.editName"),value:L.value,onChange:e=>B({...L,value:e}),onSubmit:()=>{let e=L.value.trim();e&&s.renameSession?.(L.id,e),B(null)},onClose:()=>B(null)}),null!==F&&(0,n.jsx)(ek.A,{isOpen:!0,onClose:()=>O(null),onConfirm:()=>{s.deleteSession?.(F.id),O(null)},title:S("sessions.deleteTitle"),message:S("sessions.deleteMessage",{name:F.name||""}),confirmText:S("common.delete")})]})}function ip(e){let{busRef:t,storeKey:s,workspaceId:r,mobile:l,rowCls:a,onSelectWorkspace:i}=e,o=nk(e=>e.workspaceProfiles[s]||"default"),c=nk(e=>e.tabsByWorkspace[s]??im),d=nk(e=>e.activeByWorkspace[s]||null),u=(0,f.B)(e=>{let t=e.viewStack;return!!(t&&t[t.length-1]?.type==="browser")}),m=(0,f.B)(e=>e.pushView),x=(0,f.B)(e=>(e.activeWorkspaceId??null)===r),p=(0,f.B)(e=>e.setActiveWorkspaceId);return c.length?c.map(e=>{let c=u&&x&&e.id===d,h=e.title||"Browser";return(0,n.jsxs)("div",{className:`group flex items-center gap-1.5 ${l?"pl-6":"pl-3.5"} pr-2 py-1.5 ml-0.5 rounded-[3px] text-left relative cursor-pointer select-none touch-manipulation touch-pan-y transition-colors ${c?"bg-brand-500/15 text-text":`text-text-muted ${a}`}`,onClick:()=>{var t;return t=e.id,void((0,eN.e)(),!x&&(i?i():p(r)),nk.getState().setActive(s,t),m({type:"browser"}))},title:e.url,children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full flex-shrink-0 bg-white shadow-[0_0_4px_rgba(255,255,255,0.8)]"}),(0,n.jsx)(lc,{name:o,size:14}),(0,n.jsx)("span",{className:`flex-1 min-w-0 truncate ${l?"text-base":"text-[11px]"} ${c?"font-medium":""}`,"data-tip":h,children:h}),(0,n.jsx)("button",{onClick:n=>{n.stopPropagation(),(0,eN.e)(),t?.current?.emit?.("browser:invoke",{action:"close",payload:{targetId:e.id,profile:nk.getState().workspaceProfiles[s]||"default"}},()=>{});let r=nk.getState(),l=(r.tabsByWorkspace[s]||[]).filter(t=>t.id!==e.id);r.setTabs(s,l),r.activeByWorkspace[s]===e.id&&r.setActive(s,l[0]?.id||null)},className:`p-0.5 rounded text-text-muted hover:text-text hover:bg-surface-3 shrink-0 ${l?"flex":"opacity-0 group-hover:opacity-100"} transition-opacity`,title:"Close tab",children:(0,n.jsx)(ev.X,{size:12})})]},e.id)}):null}let ih=(0,m.gJ)(),ib=(0,r.memo)(function(e){let{allSessions:t=[],mainSessions:s=null,workspaces:l=[],activeSessionId:a,activeWorkspaceId:i,sessionStatus:o,notifications:c,onSelectSession:d,onSelectWorkspace:u,onCreateNamedSession:x,onDeleteWorkspace:p,shells:h=[],onRenameSession:b,onDeleteSession:g,onReorderSession:v,onAddWorkspace:y,onRenameWorkspace:w=null,onOpenSettings:j,onOpenRemoteHost:k=null,onOpenMobileHost:N=null,onRenameHost:C=null,onDeleteHost:S=null,onMainDisconnect:T=null,onMainReconnect:E=null,busRef:R=null,fileBus:M,homeDir:$,cwdBySession:z={},connected:A=!0,width:I=ez.gH.default,onResize:D,onCollapse:L,onResumeAgentSession:B}=e,{t:F}=(0,eC.s)(),O=(0,f.B)(e=>e.agentBySession||{}),_=Object.values((0,P.rh)(e=>e.hosts)),K=(0,P.rh)(e=>e.currentKey),W=_.find(e=>e.key===K),[H,q]=(0,r.useState)(!1),U=e_(_,W?.key),X=(0,f.B)(e=>e.fullModes||{});(0,f.B)(e=>e.fullMode);let V=(0,f.B)(e=>e.toggleFullMode),G=(0,f.B)(e=>e.setFullMode),J=(0,f.B)(e=>e.pushView),Y=(0,f.B)(e=>e.viewStack),Z=(0,f.B)(e=>e.setViewStack),Q=Y[Y.length-1]?.type,ee=(0,f.B)(e=>e.hiddenPaneSessionIds||[]),et=(0,f.B)(e=>e.toggleHidePane),es=(0,f.B)(e=>e.unhidePane),en=eG(),er=o||en,el="mouse"===sD()?tI(F("common.close"),"toggleSidebar"):F("common.close"),ea=(0,r.useMemo)(()=>new Set(t.map(e=>e.id)),[t]),ei=(0,r.useMemo)(()=>s||t.filter(e=>!e.hostKey),[s,t]),eo=a?z[a]??t.find(e=>e.id===a)?.cwd??t.find(e=>e.id===a)?.workspacePath??null:null,ec=eq(a),ed=tr(e=>e.canInstall),eu=tr(e=>e.isInstalled),em=tr(e=>e.install),ex=window.matchMedia("(display-mode: standalone)").matches||!!window.ReactNativeWebView,ep=ed&&!ex&&!eu&&!(0,m.gJ)(),[eh,ef]=(0,r.useState)(null),eb=(0,r.useRef)(null),eg=n2(eb,eh?.left??0,eh?.top??0),[ey,ew]=(0,r.useState)(null),ej=O[eh?.sessionId]||er[eh?.sessionId]?.tool||t.find(e=>e.id===eh?.sessionId)?.agent,eS=ej?.endsWith("-ui");er[eh?.sessionId]?.conversationId;let eT=rR(ej),eE=eT&&rE.has(er[eh?.sessionId]?.state||"idle"),eR=(0,ti.xs)(t.find(e=>e.id===eh?.sessionId))??ti.AD,eM=X[eR]??!1,[e$,eP]=(0,r.useState)({sessionId:null,name:"",value:""}),[eA,eI]=(0,r.useState)(null);(0,r.useEffect)(()=>{if(!eh)return;let e=e=>{eb.current&&!eb.current.contains(e.target)&&ef(null)},t=e=>{"Escape"===e.key&&ef(null)};return document.addEventListener("mousedown",e),document.addEventListener("touchstart",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("touchstart",e),document.removeEventListener("keydown",t)}},[eh]);let eD=e=>t.find(t=>t.id===e),eB=e=>{e.preventDefault(),e.stopPropagation();let t=e.currentTarget.dataset.sid,s=eD(t);ef({sessionId:t,left:e.clientX,top:e.clientY,name:s?.name||""})},eF=(0,r.useRef)(null),eK=()=>{eF.current&&(clearTimeout(eF.current),eF.current=null)},eW=e=>{let t,s;t=e.currentTarget.dataset.sid,s=e.touches[0],eF.current=setTimeout(()=>{(0,eN.e)();let e=eD(t);ef({sessionId:t,left:s.clientX,top:s.clientY,name:e?.name||""})},500)};return(0,n.jsxs)("div",{className:"flex-shrink-0 h-full hidden sm:flex flex-col terminal-sidebar-bg border-r border-border-subtle relative",style:{width:I},children:[(0,n.jsxs)("div",{style:{height:32},className:"pl-[18px] pr-1 flex items-center justify-between flex-shrink-0 border-b border-border-subtle relative z-10",children:[(0,n.jsxs)("button",{onClick:()=>{(0,eN.e)(),Z([{type:"list"}])},title:"9Remote",className:"flex items-center gap-2 min-w-0 flex-shrink-0",children:[(0,n.jsx)("img",{src:"/icon-192.png",alt:"9Remote",draggable:!1,className:"w-4 h-4 rounded-[4px] object-contain flex-shrink-0 pointer-events-none select-none"}),(0,n.jsx)("span",{className:"text-[13px] font-semibold text-text truncate",children:"9Remote"})]}),(0,n.jsxs)("div",{className:"flex items-center gap-0.5 flex-shrink-0",children:[(0,n.jsx)("button",{onClick:()=>{(0,eN.e)(),q(!0)},className:"p-1 text-text-muted hover:text-text rounded-[3px] hover:bg-surface-2 transition-colors",title:F("hosts.addHost"),children:(0,n.jsx)(ev.kV,{size:14})}),L&&(0,n.jsx)("button",{onClick:()=>{(0,eN.e)(),L()},className:"p-1 text-text-muted hover:text-text rounded-[3px] hover:bg-surface-2 transition-colors",title:el,children:(0,n.jsx)(ev.e6,{size:14})})]})]}),(0,n.jsxs)("div",{className:"flex-1 min-h-0 overflow-y-auto modal-scrollable pt-1.5 pl-3.5 relative z-10",children:[ih&&(0,n.jsxs)("button",{onClick:()=>{(0,eN.e)(),J({type:"pair"})},"aria-label":"Pair Device",className:`-ml-3.5 w-[calc(100%+0.875rem)] flex items-center gap-2 pl-[17px] pr-3 py-1 rounded-[6px] text-left transition-colors duration-150 ${"pair"===Q?"bg-brand-500/10 text-brand-500":"text-text-muted hover:text-text hover:bg-surface-2"}`,title:"Pair Device",children:[(0,n.jsx)(ev.vW,{size:15,className:"flex-shrink-0"}),(0,n.jsx)("span",{className:"text-xs font-medium truncate",children:"Pair Device"})]}),U.map((e,t)=>(0,n.jsx)("div",{className:0===t?"-ml-3.5":"mt-1 -ml-3.5 border-t border-border-subtle pt-1",children:e.key===(W?.key||"main")?(0,n.jsx)(ix,{host:{...W||{},key:W?.key||"main",label:W?.label||"",workspaces:l,sessions:ei,statusMap:er,onDisconnect:T,onConnect:E},busRef:R,actions:{selectSession:e=>{ee.includes(e)&&es(e),d?.(e)},selectWorkspace:e=>{(0,eN.e)(),u?.(e)},createSession:x,renameSession:b,deleteSession:g,reorderSession:v,renameWorkspace:w,deleteWorkspace:p,renameHost:C,deleteHost:S},activeSessionId:a,activeWorkspaceId:i,connected:A,fileBus:M,homeDir:$,cwdBySession:z,agentBySession:O,hiddenPaneSessionIds:ee,onUnhidePane:es,onAddWorkspace:y,menuAddWorkspace:y,onOpenRemoteHost:k,onOpenMobileHost:N,onRowContextMenu:eB,onRowTouch:{start:eW,move:eK,end:eK},onRowMenu:(e,t,s)=>ef({sessionId:e,left:s.left,top:s.bottom+2,name:t}),treeCls:"pl-3.5"}):(0,n.jsx)(ix,{host:{...e,onDisconnect:()=>P.rh.getState().disconnectHost(e.key)},actions:{...tw(e,{onSelectSession:d,onSelectWorkspace:u}),renameHost:C,deleteHost:S},activeSessionId:a,activeWorkspaceId:function(e,t){let s=eO(e,t);if(null!==s)return"_"===s?null:s}(i,e.key),connected:A,hiddenPaneSessionIds:ee,onOpenRemoteHost:k,onOpenMobileHost:N,onUnhidePane:es,treeCls:"pl-3.5"})},e.key))]}),B&&(0,n.jsx)(nD,{busRef:ec.busRef,scope:ec.scope,cwd:eo,onResume:B,onSelectSession:d,liveSessionIds:ea,activeSessionId:a,connected:A}),(ep||j)&&(0,n.jsxs)("div",{className:"p-1.5 border-t border-border-subtle flex-shrink-0 relative z-10",children:[ep&&(0,n.jsxs)("button",{onClick:()=>{(0,eN.e)(),em()},className:"w-full flex items-center gap-2 pl-3 pr-2 py-1.5 text-xs text-text-muted hover:text-text hover:bg-surface-2 rounded-[3px] transition-colors",title:F("menu.installApp"),children:[(0,n.jsx)(ev.f5,{size:14}),(0,n.jsx)("span",{children:F("menu.installApp")})]}),j&&(0,n.jsxs)("button",{onClick:()=>{(0,eN.e)(),j()},className:"w-full flex items-center gap-2 pl-3 pr-2 py-1.5 text-xs text-text-muted hover:text-text hover:bg-surface-2 rounded-[3px] transition-colors",title:F("menu.settings"),children:[(0,n.jsx)(ev.wB,{size:14}),(0,n.jsx)("span",{children:F("menu.settings")})]})]}),H&&(0,n.jsx)(lr,{onClose:()=>q(!1)}),(0,n.jsx)("div",{onPointerDown:e=>{e.stopPropagation(),ts(e,{startWidth:I,onWidth:e=>D?.(e)})},className:"absolute top-0 right-0 bottom-0 w-1 cursor-col-resize hover:bg-brand-500/40 transition-colors z-20"}),eh&&(0,n.jsxs)("div",{ref:eb,className:"fixed z-[70] menu-popover p-1 min-w-[160px] pop-in",style:{left:eg.left,top:eg.top},children:[er[eh.sessionId]?.state==="done"&&(0,n.jsxs)("button",{onClick:()=>{(0,eN.e)(),eL.getState().clearNotification(eh.sessionId),ef(null)},className:"w-full text-left px-2.5 py-1.5 text-xs text-amber-500 hover:bg-amber-500/10 rounded-[6px] flex items-center gap-2",children:[(0,n.jsx)(ev.aJ,{size:13})," ",F("sessions.markRead")]}),(0,n.jsxs)("button",{onClick:()=>{var e;let t;return e=eh.sessionId,t=eD(e)?.name||"",void(eP({sessionId:e,name:t,value:t}),ef(null))},className:"w-full text-left px-2.5 py-1.5 text-xs text-text hover:bg-surface-2/80 rounded-[6px] flex items-center gap-2",children:[(0,n.jsx)(ev.gH,{size:13})," ",F("sessions.editName")]}),(0,n.jsxs)("div",{className:"relative group/split",children:[(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eN.e)();let e=eh.sessionId;!eM&&e&&e!==a&&d?.(e),V(eR),ef(null)},className:"w-full text-left px-2.5 py-1.5 text-xs text-text hover:bg-surface-2/80 rounded-[6px] flex items-center justify-between",children:[(0,n.jsxs)("span",{className:"flex items-center gap-2",children:[(0,n.jsx)(ev.Wn,{size:13}),(0,n.jsx)("span",{children:F("sessions.split")||"Split"})]}),(0,n.jsx)(ev.c_,{size:12,className:"text-text-muted"})]}),(0,n.jsxs)("div",{className:`hidden group-hover/split:block absolute top-0 menu-popover p-1 min-w-[130px] shadow-xl z-20 ${eg.left>window.innerWidth-280?"right-full -mr-0.5":"left-full -ml-0.5"}`,children:[(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eN.e)();let e=eh.sessionId;!eM&&e&&e!==a&&d?.(e),V(eR),ef(null)},className:"w-full text-left px-2 py-1.5 text-xs text-text hover:bg-surface-2/80 rounded-[6px] flex items-center justify-between",children:[(0,n.jsxs)("span",{className:"flex items-center gap-1.5",children:[eM?(0,n.jsx)(ev.xq,{size:12}):(0,n.jsx)(ev.h1,{size:12}),(0,n.jsx)("span",{className:"whitespace-nowrap",children:eM?"Restore":"Maximize"})]}),(0,n.jsx)("span",{className:"text-[10px] text-text-muted",children:"100%"})]}),(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eN.e)(),eh.sessionId&&eh.sessionId!==a&&d?.(eh.sessionId),eM&&G(eR,!1),window.dispatchEvent(new CustomEvent("terminal:splitPreset",{detail:{fraction:2}})),ef(null)},className:"w-full text-left px-2 py-1.5 text-xs text-text hover:bg-surface-2/80 rounded-[6px] flex items-center justify-between",children:[(0,n.jsx)("span",{children:"1/2"}),(0,n.jsx)("span",{className:"text-[10px] text-text-muted",children:"50%"})]}),(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eN.e)(),eh.sessionId&&eh.sessionId!==a&&d?.(eh.sessionId),eM&&G(eR,!1),window.dispatchEvent(new CustomEvent("terminal:splitPreset",{detail:{fraction:3}})),ef(null)},className:"w-full text-left px-2 py-1.5 text-xs text-text hover:bg-surface-2/80 rounded-[6px] flex items-center justify-between",children:[(0,n.jsx)("span",{children:"1/3"}),(0,n.jsx)("span",{className:"text-[10px] text-text-muted",children:"33%"})]}),(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eN.e)(),eh.sessionId&&eh.sessionId!==a&&d?.(eh.sessionId),eM&&G(eR,!1),window.dispatchEvent(new CustomEvent("terminal:splitPreset",{detail:{fraction:4}})),ef(null)},className:"w-full text-left px-2 py-1.5 text-xs text-text hover:bg-surface-2/80 rounded-[6px] flex items-center justify-between",children:[(0,n.jsx)("span",{children:"1/4"}),(0,n.jsx)("span",{className:"text-[10px] text-text-muted",children:"25%"})]}),(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eN.e)(),eh.sessionId&&eh.sessionId!==a&&d?.(eh.sessionId),eM&&G(eR,!1),window.dispatchEvent(new CustomEvent("terminal:splitPreset",{detail:{fraction:"auto"}})),ef(null)},className:"w-full text-left px-2 py-1.5 text-xs text-text hover:bg-surface-2/80 rounded-[6px] flex items-center justify-between",children:[(0,n.jsx)("span",{children:"Auto Fit"}),(0,n.jsx)("span",{className:"text-[10px] text-text-muted",children:"Auto"})]}),(0,n.jsx)("div",{className:"h-px bg-border-subtle my-1"}),(0,n.jsx)("button",{type:"button",onClick:()=>{(0,eN.e)(),et(eh.sessionId),ef(null)},className:"w-full text-left px-2 py-1.5 text-xs text-text hover:bg-surface-2/80 rounded-[6px] flex items-center justify-between",children:(0,n.jsxs)("span",{className:"flex items-center gap-1.5",children:[ee.includes(eh.sessionId)?(0,n.jsx)(ev.kU,{size:12}):(0,n.jsx)(ev.X_,{size:12}),(0,n.jsx)("span",{children:ee.includes(eh.sessionId)?F("sessions.showPanel")||"Show":F("sessions.hidePanel")||"Hide"})]})})]})]}),(0,n.jsxs)("button",{onClick:()=>{(0,eN.e)(),ew(eh.sessionId),ef(null)},className:"w-full text-left px-2.5 py-1.5 text-xs text-text hover:bg-surface-2/80 rounded-[6px] flex items-center gap-2",children:[(0,n.jsx)(ev._V,{size:13,className:"flex-shrink-0"})," ",F("menu.terminalBackground")]}),(O[eh.sessionId]?.endsWith("-ui")||er[eh.sessionId]?.conversationId)&&(0,n.jsxs)("button",{onClick:()=>{(0,eN.e)();let e=eh.sessionId,t=eq(e).bus;O[e]?.endsWith("-ui")?t?.emit("ai:restart",{sessionId:e}):t?.emit("session-resume",{sessionId:e}),ef(null)},className:"w-full text-left px-2.5 py-1.5 text-xs text-text hover:bg-surface-2/80 rounded-[6px] flex items-center gap-2",children:[(0,n.jsx)(ev.kt,{size:13})," ",O[eh.sessionId]?.endsWith("-ui")?F("sessions.restartAi")||"Restart AI":F("sessions.resumeSession")]}),eT&&(0,n.jsxs)("button",{disabled:!eE,onClick:()=>{(0,eN.e)();let e=eh.sessionId;eq(e).bus?.emit("setSessionMode",{sessionId:e,mode:eS?"terminal":"ui"},e=>{e?.success||alert(e?.error||F("sessions.modeSwitchFailed"))}),ef(null)},className:`w-full text-left px-2.5 py-1.5 text-xs rounded-[6px] flex items-center gap-2 ${eE?"text-text hover:bg-surface-2/80":"text-text-subtle cursor-not-allowed"}`,children:[(0,n.jsx)(ev.sU,{size:13})," ",eS?F("sessions.openAsTerminal"):F("sessions.openAsUi")]}),(0,n.jsx)("div",{className:"h-px bg-border-subtle my-1"}),(0,n.jsxs)("button",{onClick:()=>{eI({sessionId:eh.sessionId,name:eh.name}),ef(null)},className:"w-full text-left px-2.5 py-1.5 text-xs text-red-500 hover:bg-red-500/10 rounded-[6px] flex items-center gap-2",children:[(0,n.jsx)(ev.TB,{size:13})," ",F("sessions.deleteTitle")]})]}),ey&&(0,n.jsx)(n6,{sessionId:ey,title:eD(ey)?.name,busRef:R,onClose:()=>ew(null)}),e$.sessionId&&(0,n.jsx)(nL,{title:F("sessions.editName"),placeholder:e$.name,value:e$.value,onChange:e=>eP({...e$,value:e}),onSubmit:()=>{let e=e$.value.trim();e$.sessionId&&e&&b?.(e$.sessionId,e),eP({sessionId:null,name:"",value:""})},onClose:()=>eP({sessionId:null,name:"",value:""})}),(0,n.jsx)(ek.A,{isOpen:!!eA,onClose:()=>eI(null),onConfirm:()=>{eA?.sessionId&&g?.(eA.sessionId)},title:F("sessions.deleteTitle"),message:F("sessions.deleteMessage",{name:eA?.name||""}),confirmText:F("common.delete")})]})}),ig={claude:"Claude",codex:"Codex",kimi:"Kimi",grok:"Grok"};function iv(e){return e<60?"bg-text-muted/40":e<80?"bg-yellow-500":"bg-red-500"}function iy(e){let{enabled:t=!0}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},[s,n]=(0,r.useState)(null);return(0,r.useEffect)(()=>{if(!t||!e)return;let s=!1,r=()=>{e.current&&e.current.emit("quota:get",{},e=>{!s&&e?.success&&e.providers&&n(e)})};r();let l=n$(r,6e4);return()=>{s=!0,l()}},[e,t]),s}let iw=[["session","5h"],["weekly","wk"],["monthly","mo"]];function ij(e){let{usedPct:t}=e;return(0,n.jsx)("span",{className:"w-10 h-[5px] rounded-full bg-text-muted/20 overflow-hidden flex-shrink-0",children:(0,n.jsx)("span",{className:`block h-full rounded-full transition-all duration-300 ${iv(t)}`,style:{width:`${Math.min(100,Math.max(0,t))}%`}})})}function ik(e){let{provider:t}=e,[s,l]=(0,r.useState)(!1);return s?(0,n.jsx)("span",{className:"text-text-subtle",children:ig[t]||t}):(0,n.jsx)("img",{src:tu(t),alt:"",width:14,height:14,onError:()=>l(!0),className:`w-3.5 h-3.5 object-contain ${td}`})}function iN(e){let{label:t,window:s}=e;return s?(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"w-16 truncate text-text-muted",children:t}),(0,n.jsxs)("span",{className:"w-9 text-right tabular-nums",children:[Math.round(s.usedPercent),"%"]}),(0,n.jsx)(ij,{usedPct:s.usedPercent}),s.resetsAt&&(0,n.jsx)("span",{className:"text-text-subtle whitespace-nowrap",children:function(e){if(!e)return"";let t=new Date(e),s=t.toDateString()===new Date().toDateString(),n=t.toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"});return s?n:`${t.toLocaleDateString(void 0,{weekday:"short"})} ${n}`}(s.resetsAt)})]}):null}function iC(e){let{p:t,onClose:s}=e,l=(0,r.useRef)(null),{t:a}=(0,eC.s)();return(0,r.useEffect)(()=>{let e=e=>{l.current?.contains(e.target)||s()},t=e=>{"Escape"===e.key&&s()};return document.addEventListener("pointerdown",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("pointerdown",e),document.removeEventListener("keydown",t)}},[s]),(0,n.jsxs)("div",{ref:l,className:"absolute bottom-full right-0 mb-2 z-50 w-64 p-3 rounded-brand-lg bg-surface-2 border border-border shadow-lg text-[11px] flex flex-col gap-2",children:[(0,n.jsx)("div",{className:"font-medium",children:ig[t.provider]||t.provider}),iw.map(e=>{let[s,r]=e;return(0,n.jsx)(iN,{label:r,window:t[s]},s)}),(t.buckets||[]).map(e=>(0,n.jsx)(iN,{label:e.name,window:e},e.name)),!t.session&&!t.weekly&&!t.monthly&&!(t.buckets||[]).length&&(0,n.jsx)("div",{className:"text-text-muted",children:t.error||a("terminal.quotaNoData")}),t.error&&(t.session||t.weekly||t.monthly)&&(0,n.jsx)("div",{className:"text-text-subtle border-t border-border-subtle pt-1.5",children:t.error})]})}function iS(e){let{quota:t}=e,[s,l]=(0,r.useState)(null),{t:a}=(0,eC.s)();if(!t?.providers)return null;let i=Object.values(t.providers).filter(e=>e&&"ok"===e.status&&(e.session||e.weekly||e.monthly||e.buckets?.length));return i.length?(0,n.jsx)("span",{className:"relative flex items-center gap-1 flex-shrink-0",children:i.map(e=>{let t=e.session||e.weekly||e.monthly||e.buckets[0];return(0,n.jsxs)("span",{className:"relative",children:[(0,n.jsxs)("button",{type:"button",className:"flex items-center gap-1.5 px-1.5 py-0.5 rounded-[2px] hover:bg-white/10 transition-colors",onClick:()=>l(s===e.provider?null:e.provider),title:`${ig[e.provider]||e.provider} ${a("terminal.quotaUsageTitle")}`,children:[(0,n.jsx)(ik,{provider:e.provider}),(0,n.jsx)(ij,{usedPct:t.usedPercent}),(0,n.jsxs)("span",{className:"tabular-nums",children:[Math.round(t.usedPercent),"%"]})]}),s===e.provider&&(0,n.jsx)(iC,{p:e,onClose:()=>l(null)})]},e.provider)})}):null}function iT(e){let{left:t,right:s,className:r="flex"}=e;return(0,n.jsxs)("div",{style:{height:26},className:`statusbar-glass items-center gap-3 px-3 flex-shrink-0 border-t border-border-subtle text-[11px] text-text-muted select-none ${r}`,children:[(0,n.jsx)("div",{className:"flex items-center gap-3 min-w-0 flex-1",children:t}),(0,n.jsx)("div",{className:"flex items-center gap-3 flex-shrink-0",children:s})]})}let iE="flex items-center gap-1.5 px-1.5 py-0.5 rounded-[2px] hover:bg-white/10 transition-colors cursor-pointer",iR="flex items-center gap-1.5 px-1.5 py-0.5",iM={darwin:"mac",win32:"win",linux:"linux"};function i$(e){let{pages:t,activeKey:s}=e;return(0,n.jsx)("span",{className:"grid justify-items-end",children:t.map(e=>{let{key:t,node:r}=e;return(0,n.jsx)("span",{"aria-hidden":t!==s,className:"[grid-area:1/1] flex items-center min-w-0 motion-reduce:transition-none",style:{opacity:+(t===s),transform:t===s?"translateY(0)":"translateY(2px)",pointerEvents:t===s?"auto":"none",transition:`opacity ${ez.ZU}ms ease, transform ${ez.ZU}ms ease`},children:r},t)})})}let iz=(0,r.memo)(function(e){let t,s,l,{sessionId:a,fileBus:i,busRef:o,onReveal:c,workspacePath:d=null}=e,u=(0,f.B)(e=>e.cwdBySession[a])||"",{branch:m}=lx(u,i,{enabled:!!u}),{count:x,perRepo:p}=rB(d||u,i,{enabled:!!u}),h=(s=iy(o,{enabled:!!(t=(0,f.B)(e=>e.agentBySession[a])||"")}),(l=t?s?.providers?.[t]:null)&&"ok"===l.status&&l.session?{agentId:t,usedPct:l.session.usedPercent}:null),[b,g]=(0,r.useState)(!1),v=u?u.replace(/\\+|\/+$/g,"").split(/[\\/]/).filter(Boolean):[],y=v.length?v.slice(-2).join("/"):"";(0,r.useEffect)(()=>{if(!b)return;let e=setTimeout(()=>g(!1),ez.wu);return()=>clearTimeout(e)},[b]);let w=[];y&&w.push({key:"path",node:(0,n.jsxs)("button",{type:"button",onClick:c?()=>c(a,u):void 0,title:u,className:`flex items-center gap-1 min-w-0 font-mono ${c?"hover:text-text":""}`,children:[(0,n.jsx)(ev.vd,{size:10,className:"opacity-70 flex-shrink-0"}),(0,n.jsx)("span",{className:"truncate",children:y})]})}),h&&w.push({key:"quota",node:(0,n.jsxs)("button",{type:"button",onClick:()=>g(!0),className:"flex items-center gap-1.5 flex-shrink-0",children:[(0,n.jsx)("img",{src:tu(h.agentId),alt:"",width:11,height:11,draggable:!1,className:`w-[11px] h-[11px] object-contain ${td}`}),(0,n.jsx)("span",{className:"w-8 h-[4px] rounded-full bg-text-muted/20 overflow-hidden",children:(0,n.jsx)("span",{className:`block h-full rounded-full transition-all duration-300 ${iv(h.usedPct)}`,style:{width:`${Math.min(100,Math.max(0,h.usedPct))}%`}})}),(0,n.jsxs)("span",{className:"tabular-nums text-text-muted",children:[Math.round(h.usedPct),"%"]})]})});let j=h&&h.usedPct>=ez.W$?w.findIndex(e=>"quota"===e.key):-1,[k]=function(e){let{pinnedIndex:t=-1,paused:s=!1}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},[n,l]=(0,r.useState)(0);return((0,r.useEffect)(()=>{if(!(e<2)&&!s&&!(t>=0))return n$(()=>l(e=>e+1),ez.wu,{fireOnReturn:!1})},[e,s,t]),e)?[t>=0?t:n%e,l]:[0,l]}(w.length,{pinnedIndex:j,paused:b}),N=rD(p,u,x);return(0,n.jsxs)("div",{className:"flex items-center justify-between gap-2 px-3 h-6 border-t border-border-subtle text-[10px] text-text-subtle bg-bg flex-shrink-0",children:[m&&(0,n.jsxs)("span",{className:"flex items-center gap-1 flex-shrink-0",children:[(0,n.jsx)(ev.Zr,{size:10,className:"opacity-70"}),(0,n.jsx)("span",{className:"max-w-[90px] truncate text-text-muted",title:m,children:m}),N>0&&(0,n.jsx)("span",{className:"px-1 leading-tight bg-brand-500/15 text-brand-400 rounded-[2px] font-medium",children:N>ez.KN?`${ez.KN}+`:N})]}),w.length>0&&(0,n.jsx)(i$,{pages:w,activeKey:w[k]?.key})]})}),iP=(0,r.memo)(function(e){let{cwd:t,workspacePath:s=null,sessionId:r,hostKey:l=null,sessionState:a,sessionName:i="",hostVersion:o="",agentVersion:c="",platform:d="",homeDir:m=null}=e,{t:x}=(0,eC.s)(),p=function(e){let t=e&&e===P.rh.getState().currentKey?null:e,s=(0,u.d)(e=>t?null:e.connected),n=(0,u.d)(e=>t?"ws":e.carrier),r=(0,P.rh)(e=>e.hosts[t||e.currentKey]);if(!t)return{head:null,connected:!!s,status:s?"full":"offline",carrier:n||"ws",platform:r?.platform||null,version:r?.version||null};let l=r?.status||"offline";return{head:t,connected:"online"===l,status:l,carrier:r?.carrier||"ws",platform:r?.platform||null,version:r?.version||null}}(l),h=eH(l).busRef,b=eH(l).fileBus,g=(0,u.d)(e=>l?null:e.connectionMode),v=(0,u.d)(e=>l?"":e.endpoint),y=eU(r),w=p.connected,j=p.carrier,k=a||y||"idle",N=iy(h),C=(0,f.B)(e=>(e.agentBySession||{})[r])||"",S=i||"—",T=C?tu(C):null,{branch:E}=lx(t,b,{enabled:!!t}),{count:R,perRepo:M}=rB(s||t,b,{enabled:!!t}),$=rD(M,t,R),z=nx(k),A=x("working"===k?"common.statusWorking":"blocked"===k?"common.statusBlocked":"done"===k?"common.statusDone":"sleep"===k?"common.statusSleep":"common.statusIdle"),I=t?nC(t.replace(/\\/g,"/"),m):"",D=$>ez.KN?`${ez.KN}+`:$;return(0,n.jsx)(iT,{className:"hidden sm:flex",left:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("span",{className:"flex items-center gap-1.5 flex-shrink-0 max-w-[200px]",children:[T?(0,n.jsx)("img",{src:T,alt:"",draggable:!1,className:`w-3.5 h-3.5 object-contain flex-shrink-0 ${td}`}):(0,n.jsx)(nR,{size:14}),(0,n.jsx)("span",{className:"truncate font-medium text-text",title:S,children:S})]}),(0,n.jsx)("span",{className:"text-text-subtle flex-shrink-0",children:"›"}),(0,n.jsxs)("span",{className:"flex items-center gap-1.5 min-w-0 flex-shrink",children:[(0,n.jsx)(ev.vd,{size:12,className:"opacity-60 flex-shrink-0"}),(0,n.jsx)("span",{className:"truncate",title:t||"",children:I||x("common.loading")})]}),t&&E&&(0,n.jsxs)("span",{className:"flex items-center gap-1.5 flex-shrink-0",children:[(0,n.jsx)(ev.Zr,{size:12,className:"opacity-60 text-brand-500"}),(0,n.jsx)("span",{className:"truncate max-w-[160px]",title:E,children:E}),$>0&&(0,n.jsx)("span",{className:"px-1 leading-tight bg-brand-500/15 text-brand-400 rounded-[2px] font-medium",children:D})]})]}),right:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(iS,{quota:N}),(p.platform||d)&&(0,n.jsx)("span",{className:"uppercase tracking-wide",children:iM[p.platform||d]||p.platform||d}),(p.version||o||c)&&(0,n.jsxs)("span",{className:"text-text-subtle",children:["v",p.version||o||c]}),(0,n.jsxs)("span",{className:"flex items-center gap-1.5",title:`${v||""}${j&&"ws"!==j?` (${j})`:""}`,children:[(0,n.jsx)("span",{className:`w-2 h-2 rounded-full ${w?"local"===g?"bg-emerald-400":"bg-green-500":"bg-red-500 animate-pulse"}`}),(0,n.jsx)("span",{className:"uppercase tracking-wide",children:j&&"ws"!==j?"STUN":`WS${"local"===g?" \xb7 LOCAL":""}`})]}),(0,n.jsxs)("span",{className:"flex items-center gap-1.5",children:[(0,n.jsx)("span",{className:`w-2 h-2 rounded-full term-dot ${z.cls}${z.pulse?` pulse-${z.pulse}`:""}`,style:{background:z.dot}}),(0,n.jsx)("span",{children:A})]})]})})}),iA=(e,t,s)=>Math.max(t,Math.min(s,e));function iI(e){let t=window.innerWidth-4*ez.qj.margin,s=window.innerHeight-3*ez.qj.margin;return{...e,x:iA(e.x,ez.qj.margin-e.w+4*ez.qj.margin,t),y:iA(e.y,ez.qj.margin,s)}}function iD(e){let t=!1,s=null,n=e.length,r=0;for(;r+2<n;){if(0===e[r]&&0===e[r+1]){let l=0;if(1===e[r+2]?l=3:r+3<n&&0===e[r+2]&&1===e[r+3]&&(l=4),l){let n=31&e[r+l];7!==n||s||(s=e.subarray(r+l)),5===n&&(t=!0),r+=l+1;continue}}r++}return{isKey:t,spsBytes:s}}let iL="VideoDecoder"in window&&"EncodedVideoChunk"in window,iB=/^(\d\d-\d\d \d\d:\d\d:\d\d\.\d+)\s+\d+\s+\d+\s+([VDIWEF])\s+([^:]*):\s?(.*)$/;function iF(e){let{state:t}=e;return(0,n.jsx)("span",{className:`w-2 h-2 rounded-full flex-shrink-0 ${"running"===t?"bg-green-500 animate-pulse":"starting"===t||"stopping"===t?"bg-amber-400 animate-pulse":"bg-text-muted/40"}`})}function iO(e){let{devices:t,canManage:s,booting:l,stopping:a,loading:i,error:o,onOpen:c,onStop:d,onRefresh:u,lowPower:m,onLowPowerChange:x,onAddDevice:p,onDeleteAvd:h,onWipeAvd:f,sdkJob:b,onShowSetup:g}=e,{t:v}=(0,eC.s)(),[y,w]=(0,r.useState)(null),[j,k]=(0,r.useState)(null);return(0,n.jsxs)("div",{className:"w-full max-w-sm mx-auto p-4 space-y-3 fade-in",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("h2",{className:"text-text text-sm font-medium flex-1",children:v("mobile.pickDevice")}),(0,n.jsx)("button",{onClick:()=>{(0,eN.e)(),p?.()},className:"p-1.5 text-text-muted hover:text-brand-500 hover:bg-surface-2 rounded-brand transition-all duration-150 ease-out active:scale-[0.94]",title:v("mobile.addDevice"),"aria-label":v("mobile.addDevice"),children:(0,n.jsx)(ev.FW,{size:15})}),(0,n.jsx)("button",{onClick:()=>{(0,eN.e)(),u?.()},className:"p-1.5 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-all duration-150 ease-out active:scale-[0.94]",title:v("mobile.refreshDevices"),"aria-label":v("mobile.refreshDevices"),children:(0,n.jsx)(ev.e9,{size:15})})]}),b&&"done"!==b.phase&&"error"!==b.phase&&(0,n.jsxs)("button",{onClick:()=>{(0,eN.e)(),g?.()},className:"w-full flex items-center gap-2.5 bg-surface rounded-brand-lg px-3 py-2.5 hover:bg-surface-2 transition-colors text-left",children:[(0,n.jsx)(ev.kr,{size:15,className:"text-brand-500 animate-spin flex-shrink-0"}),(0,n.jsxs)("div",{className:"flex flex-col min-w-0 flex-1",children:[(0,n.jsx)("span",{className:"text-xs text-text truncate",children:v(function(e){if(e?.step)return`mobile.provisionStep_${e.step}`;let t=e?.component||"";return t.startsWith("system-images;")?"mobile.provisionStep_image":`mobile.provisionStep_${t}`}(b))}),(0,n.jsx)("span",{className:"text-[10px] text-text-muted",children:"image"===b.kind||"image"===b.step?`${b.percent??0}%`:`${Math.round((b.received||0)/1024/1024)} MB${b.bytesPerSec?` \xb7 ${Math.round(b.bytesPerSec/1024/1024)} MB/s`:""}`})]})]}),0===t.length&&(0,n.jsx)("div",{className:"text-center py-8 space-y-2 fade-in",children:i?(0,n.jsx)(ev.kr,{size:20,className:"text-brand-500 animate-spin mx-auto"}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(ev.wO,{size:26,className:"text-text-muted mx-auto"}),(0,n.jsx)("p",{className:"text-text-muted text-sm",children:v("mobile.noDevicesHint")})]})}),(0,n.jsx)("div",{className:"space-y-1.5",children:t.map((e,t)=>{let r=l?.avdName&&l.avdName===e.avdName,i=a?.has(e.serial),o="running"===e.state;return(0,n.jsxs)("div",{className:"bg-surface rounded-brand-lg overflow-hidden list-rise",style:{"--i":Math.min(t,8)},children:[(0,n.jsxs)("div",{className:"flex items-center gap-2.5 px-3 py-2",children:[(0,n.jsxs)("button",{onClick:()=>{(0,eN.e)(),c?.(e)},disabled:r||i,className:"flex items-center gap-2.5 flex-1 min-w-0 text-left disabled:opacity-60 transition-all duration-150 ease-out active:scale-[0.99]",children:["physical"===e.kind?(0,n.jsx)(ev.wO,{size:16,className:"text-brand-500 dark:text-white flex-shrink-0"}):(0,n.jsx)(ev.VA,{size:16,className:"text-brand-500 dark:text-white flex-shrink-0"}),(0,n.jsxs)("div",{className:"flex flex-col min-w-0 flex-1",children:[(0,n.jsx)("span",{className:"text-sm text-text truncate",children:e.name}),(0,n.jsx)("span",{className:"text-xs text-text-muted truncate",children:r?v(`mobile.phase${l.phase.charAt(0).toUpperCase()}${l.phase.slice(1)}`):i?v("mobile.stoppingDevice"):e.serial||v("mobile.stopped")})]}),(0,n.jsx)(iF,{state:r||i?"starting":e.state})]}),r?(0,n.jsx)(ev.kr,{size:15,className:"text-brand-500 animate-spin flex-shrink-0"}):o&&e.canStop?i?(0,n.jsx)(ev.kr,{size:15,className:"text-brand-500 animate-spin flex-shrink-0"}):(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),(0,eN.e)(),d?.(e)},className:"p-1.5 text-text-muted hover:text-red-400 hover:bg-surface-2 rounded-brand transition-all duration-150 ease-out active:scale-[0.94] flex-shrink-0",title:v("mobile.stopDevice"),"aria-label":v("mobile.stopDevice"),children:(0,n.jsx)(ev.M6,{size:14})}):o?null:(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),(0,eN.e)(),c?.(e)},className:"p-1.5 text-text-muted hover:text-brand-500 hover:bg-surface-2 rounded-brand transition-all duration-150 ease-out active:scale-[0.94] flex-shrink-0",title:v("mobile.startDevice"),"aria-label":v("mobile.startDevice"),children:(0,n.jsx)(ev.jG,{size:14})}),s&&"emulator"===e.kind&&e.avdName&&!o&&!r&&(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),(0,eN.e)(),w(y===e.id?null:e.id)},className:"p-1.5 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors flex-shrink-0","aria-label":v("mobile.avdMenu"),children:(0,n.jsx)(ev.Gv,{size:14})})]}),y===e.id&&(0,n.jsxs)("div",{className:"flex items-center gap-1 px-3 py-1.5 border-t border-border bg-surface-2/50",children:[(0,n.jsxs)("button",{onClick:()=>{(0,eN.e)(),k({kind:"wipe",avdName:e.avdName,name:e.name}),w(null)},className:"flex items-center gap-1.5 px-2 py-1 text-[11px] text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors",children:[(0,n.jsx)(ev.kt,{size:12})," ",v("mobile.avdWipe")]}),(0,n.jsx)("div",{className:"flex-1"}),(0,n.jsxs)("button",{onClick:()=>{(0,eN.e)(),k({kind:"delete",avdName:e.avdName,name:e.name}),w(null)},className:"flex items-center gap-1.5 px-2 py-1 text-[11px] text-text-muted hover:text-red-400 hover:bg-surface-2 rounded-brand transition-colors",children:[(0,n.jsx)(ev.TB,{size:12})," ",v("mobile.avdDelete")]})]})]},e.id)})}),s&&t.some(e=>"running"!==e.state)&&(0,n.jsxs)("button",{onClick:()=>{(0,eN.e)(),x?.(!m)},className:"w-full bg-surface rounded-brand-lg px-3 py-2 flex items-center gap-2.5 text-left hover:bg-surface-2 transition-colors",children:[(0,n.jsx)(ev.Kq,{size:15,className:m?"text-brand-500 dark:text-white flex-shrink-0":"text-text-muted flex-shrink-0"}),(0,n.jsxs)("div",{className:"flex flex-col min-w-0 flex-1",children:[(0,n.jsx)("span",{className:"text-sm text-text",children:v("mobile.lowPower")}),(0,n.jsx)("span",{className:"text-xs text-text-muted",children:v("mobile.lowPowerHint")})]}),(0,n.jsx)("span",{className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors border border-transparent flex-shrink-0 ${m?"bg-brand-500 dark:bg-white":"bg-surface-2 dark:border-white/15"}`,children:(0,n.jsx)("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${m?"translate-x-4 dark:bg-dark-800":"translate-x-0.5 dark:bg-white/50"}`})})]}),o&&(0,n.jsx)("p",{className:"text-red-400 text-xs text-center",children:o}),(0,n.jsx)(ek.A,{isOpen:!!j,onClose:()=>k(null),onConfirm:()=>{j&&("delete"===j.kind?h?.(j.avdName):f?.(j.avdName),k(null))},title:v(j?.kind==="delete"?"mobile.avdDeleteTitle":"mobile.avdWipeTitle"),message:v(j?.kind==="delete"?"mobile.avdDeleteMessage":"mobile.avdWipeMessage",{name:j?.name||""}),confirmText:v(j?.kind==="delete"?"common.delete":"mobile.avdWipe")})]})}function i_(e){if(!Number.isFinite(e)||e<=0)return"";let t=["B","KB","MB","GB"],s=0,n=e;for(;n>=1024&&s<t.length-1;)n/=1024,s++;return`${n>=10?Math.round(n):n.toFixed(1)} ${t[s]}`}function iK(e){let{isOpen:t,onClose:s,presets:l,sdkJob:a,onProvision:i,onCancel:o}=e,{t:c}=(0,eC.s)(),[d,u]=(0,r.useState)(null),[m,x]=(0,r.useState)(null),p=a&&"done"!==a.phase&&"error"!==a.phase?a:null,h=a?.phase==="error"&&"cancelled"!==a.error?a.error:null,f=(0,r.useCallback)(()=>{u(null),x(null),s?.()},[s]);if((0,r.useEffect)(()=>{if(!t||p)return;let e=e=>{"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),f())};return window.addEventListener("keydown",e,!0),()=>window.removeEventListener("keydown",e,!0)},[t,p,f]),!t||"u"<typeof document)return null;let b=async e=>{if(d||p)return;(0,eN.e)(),u(e.id),x(e);let t=await i?.(e.id);u(null),t&&f()};return(0,sp.createPortal)((0,n.jsx)("div",{className:"fixed inset-0 z-[100] flex items-center justify-center p-4 scrim fade-in",onClick:f,children:(0,n.jsxs)("div",{className:"card-elev w-full max-w-sm max-h-[80vh] flex flex-col pop-in",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-4 py-3 border-b border-border flex-shrink-0",children:[(0,n.jsx)(ev.wO,{size:15,className:"text-brand-500 dark:text-white flex-shrink-0"}),(0,n.jsx)("span",{className:"text-sm text-text flex-1",children:c("mobile.addDevice")}),(0,n.jsx)("button",{onClick:()=>{(0,eN.e)(),f()},className:"p-1 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand",children:(0,n.jsx)(ev.X,{size:15})})]}),(0,n.jsx)("div",{className:"p-3 space-y-1.5 overflow-y-auto modal-scrollable",children:p||h?(0,n.jsx)("div",{className:"flex flex-col items-center gap-3 py-8 px-4 text-center",children:h?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("p",{className:"text-red-400 text-xs",children:h}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[m&&(0,n.jsx)("button",{onClick:()=>b(m),className:"px-3 py-1.5 text-xs text-brand-500 bg-brand-500/10 dark:text-white dark:bg-white/10 rounded-brand",children:c("common.retry")}),(0,n.jsx)("button",{onClick:()=>{(0,eN.e)(),f()},className:"px-3 py-1.5 text-xs text-text-muted hover:text-text rounded-brand",children:c("common.close")})]})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(ev.kr,{size:20,className:"text-brand-500 animate-spin"}),(0,n.jsx)("p",{className:"text-text text-sm",children:c(function(e){if(e?.step)return`mobile.provisionStep_${e.step}`;let t=e?.component||"";return t.startsWith("system-images;")?"mobile.provisionStep_image":`mobile.provisionStep_${t}`}(p))}),(0,n.jsx)("p",{className:"text-text-muted text-xs",children:"image"===p.kind||"image"===p.step?`${p.percent??0}%`:`${i_(p.received)}${p.total?` / ${i_(p.total)}`:""}${p.bytesPerSec?` \xb7 ${i_(p.bytesPerSec)}/s`:""}`}),(0,n.jsx)("button",{onClick:()=>{(0,eN.e)(),o?.()},className:"px-3 py-1 text-[11px] text-text-muted hover:text-red-400 rounded-brand transition-colors",children:c("common.cancel")})]})}):(l||[]).map(e=>(0,n.jsxs)("button",{onClick:()=>b(e),className:"w-full flex items-center gap-2.5 px-3 py-2.5 bg-surface rounded-brand-lg hover:bg-surface-2 transition-colors text-left",children:["tablet"===e.id?(0,n.jsx)(ev.VA,{size:16,className:"text-brand-500 dark:text-white flex-shrink-0"}):(0,n.jsx)(ev.wO,{size:16,className:"text-brand-500 dark:text-white flex-shrink-0"}),(0,n.jsxs)("div",{className:"flex flex-col min-w-0 flex-1",children:[(0,n.jsx)("span",{className:"text-sm text-text truncate",children:e.label}),(0,n.jsx)("span",{className:"text-[10px] text-text-muted",children:e.ready?c("mobile.presetReady"):c("mobile.presetDownload")})]}),e.ready?(0,n.jsx)(ev.aJ,{size:13,className:"text-green-500 flex-shrink-0"}):(0,n.jsx)(ev.f5,{size:13,className:"text-text-muted flex-shrink-0"})]},e.id))})]})}),document.body)}function iW(e){let{apps:t,foreground:s,busy:l,progress:a,error:i,onInstall:o,onLaunch:c,onStopApp:d,onClearData:u,onUninstall:m,onOpenLink:x,onRefresh:p}=e,{t:h}=(0,eC.s)(),f=(0,r.useRef)(null),[b,g]=(0,r.useState)(!1),[v,y]=(0,r.useState)(""),w=(0,r.useCallback)(e=>{let t=[...e||[]].find(e=>e.name.toLowerCase().endsWith(".apk"));t&&o?.(t)},[o]),j=(0,r.useCallback)(e=>{e.preventDefault(),g(!1),w(e.dataTransfer?.files)},[w]),k="install"===l;return(0,n.jsxs)("div",{className:"h-full overflow-y-auto modal-scrollable p-3 space-y-3",onDragOver:e=>{e.preventDefault(),g(!0)},onDragLeave:()=>g(!1),onDrop:j,children:[(0,n.jsx)("button",{onClick:()=>{(0,eN.e)(),f.current?.click()},disabled:k,className:`w-full rounded-brand-lg border border-dashed px-3 py-5 flex flex-col items-center gap-1.5 transition-colors duration-150 ${b?"border-brand-500 bg-brand-500/5":"border-border hover:border-brand-500/50"} disabled:opacity-60`,children:k?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(ev.kr,{size:20,className:"text-brand-500 animate-spin"}),(0,n.jsx)("span",{className:"text-sm text-text",children:h("mobile.installing")}),a>0&&(0,n.jsx)("div",{className:"w-full max-w-[180px] h-1 bg-surface-2 rounded-full overflow-hidden mt-1",children:(0,n.jsx)("div",{className:"h-full bg-brand-500 transition-[width] duration-150",style:{width:`${Math.round(100*a)}%`}})})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(ev._O,{size:20,className:"text-text-muted"}),(0,n.jsx)("span",{className:"text-sm text-text",children:h("mobile.dropApk")}),(0,n.jsx)("span",{className:"text-xs text-text-muted",children:h("mobile.dropApkHint")})]})}),(0,n.jsx)("input",{ref:f,type:"file",accept:".apk,application/vnd.android.package-archive",className:"hidden",onChange:e=>{w(e.target.files),e.target.value=""}}),(0,n.jsxs)("form",{onSubmit:e=>{e.preventDefault(),v.trim()&&(x?.(v.trim()),y(""))},className:"flex items-center gap-1.5",children:[(0,n.jsxs)("div",{className:"flex-1 flex items-center gap-2 bg-surface rounded-brand px-2.5 py-1.5",children:[(0,n.jsx)(ev.vv,{size:14,className:"text-text-muted flex-shrink-0"}),(0,n.jsx)("input",{value:v,onChange:e=>y(e.target.value),placeholder:h("mobile.deepLinkPlaceholder"),className:"flex-1 bg-transparent text-sm text-text placeholder:text-text-muted focus:outline-none min-w-0",autoCapitalize:"none",autoCorrect:"off",spellCheck:!1})]}),(0,n.jsx)("button",{type:"submit",disabled:!v.trim(),className:"px-2.5 py-1.5 text-sm text-text bg-surface hover:bg-surface-2 rounded-brand transition-all duration-150 ease-out active:scale-[0.97] disabled:opacity-40",children:h("common.open")})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2 pt-1",children:[(0,n.jsx)("span",{className:"text-xs text-text-muted flex-1",children:h("mobile.installedApps")}),(0,n.jsx)("button",{onClick:()=>{(0,eN.e)(),p?.()},className:"p-1 text-text-muted hover:text-text rounded-brand transition-colors",title:h("common.refresh"),"aria-label":h("common.refresh"),children:(0,n.jsx)(ev.e9,{size:13})})]}),0===t.length&&(0,n.jsx)("p",{className:"text-text-muted text-xs text-center py-4",children:h("mobile.noApps")}),(0,n.jsx)("div",{className:"space-y-1",children:t.map(e=>{let t=s?.packageName===e.packageName,r=l===e.packageName;return(0,n.jsxs)("div",{className:"bg-surface rounded-brand px-2.5 py-2 flex items-center gap-2",children:[(0,n.jsx)(ev.lP,{size:14,className:t?"text-brand-500 flex-shrink-0":"text-text-muted flex-shrink-0"}),(0,n.jsx)("span",{className:"text-sm text-text truncate flex-1",title:e.packageName,children:e.packageName}),r?(0,n.jsx)(ev.kr,{size:14,className:"text-brand-500 animate-spin flex-shrink-0"}):(0,n.jsxs)("div",{className:"flex items-center gap-0.5 flex-shrink-0",children:[e.launchable&&(0,n.jsx)("button",{onClick:()=>{(0,eN.e)(),c?.(e.packageName)},className:"p-1.5 text-text-muted hover:text-brand-500 hover:bg-surface-2 rounded-brand transition-colors",title:h("mobile.launch"),"aria-label":h("mobile.launch"),children:(0,n.jsx)(ev.jG,{size:13})}),t&&(0,n.jsx)("button",{onClick:()=>{(0,eN.e)(),d?.(e.packageName)},className:"p-1.5 text-text-muted hover:text-amber-400 hover:bg-surface-2 rounded-brand transition-colors",title:h("mobile.forceStop"),"aria-label":h("mobile.forceStop"),children:(0,n.jsx)(ev.M6,{size:13})}),(0,n.jsx)("button",{onClick:()=>{(0,eN.e)(),u?.(e.packageName)},className:"p-1.5 text-text-muted hover:text-amber-400 hover:bg-surface-2 rounded-brand transition-colors",title:h("mobile.clearData"),"aria-label":h("mobile.clearData"),children:(0,n.jsx)(ev.e9,{size:13})}),(0,n.jsx)("button",{onClick:()=>{(0,eN.e)(),m?.(e.packageName)},className:"p-1.5 text-text-muted hover:text-red-400 hover:bg-surface-2 rounded-brand transition-colors",title:h("mobile.uninstall"),"aria-label":h("mobile.uninstall"),children:(0,n.jsx)(ev.TB,{size:13})})]})]},e.packageName)})}),i&&(0,n.jsx)("p",{className:"text-red-400 text-xs",children:i})]})}function iH(e){let{logcat:t,apps:s}=e,{lines:l,clear:a,minLevel:i,setMinLevel:o,search:c,setSearch:d,packageName:u,setPackageName:m,paused:x,setPaused:p,includeNoise:h,setIncludeNoise:f}=t,{t:b}=(0,eC.s)(),g=(0,r.useRef)(null),[v,y]=(0,r.useState)(!0),w=()=>{y(!0)};return(0,r.useLayoutEffect)(()=>{v&&g.current&&(g.current.scrollTop=g.current.scrollHeight)},[l,v]),(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1.5 border-b border-border flex-shrink-0 flex-wrap",children:[(0,n.jsxs)("select",{value:u||"",onChange:e=>{(0,eN.e)(),m(e.target.value||null),w()},className:"bg-surface-2 text-text text-xs rounded-brand px-1.5 py-1 focus:outline-none max-w-[40%]",title:b("mobile.filterByApp"),children:[(0,n.jsx)("option",{value:"",children:b("mobile.allApps")}),s.map(e=>(0,n.jsx)("option",{value:e.packageName,children:e.packageName},e.packageName))]}),(0,n.jsx)("select",{value:i,onChange:e=>{(0,eN.e)(),o(e.target.value),w()},className:"bg-surface-2 text-text text-xs rounded-brand px-1.5 py-1 focus:outline-none",title:b("mobile.minLevel"),children:el.map(e=>(0,n.jsx)("option",{value:e,children:e},e))}),(0,n.jsxs)("div",{className:"flex items-center gap-1 bg-surface-2 rounded-brand px-1.5 py-1 flex-1 min-w-[90px]",children:[(0,n.jsx)(ev.vj,{size:12,className:"text-text-muted flex-shrink-0"}),(0,n.jsx)("input",{value:c,onChange:e=>d(e.target.value),placeholder:b("common.search"),className:"bg-transparent text-xs text-text placeholder:text-text-muted focus:outline-none w-full min-w-0",autoCapitalize:"none",autoCorrect:"off",spellCheck:!1})]}),(0,n.jsx)("button",{onClick:()=>{(0,eN.e)(),p(!x)},className:`p-1.5 rounded-brand transition-colors ${x?"text-brand-500 bg-surface-2":"text-text-muted hover:text-text"}`,title:b(x?"mobile.resumeLog":"mobile.pauseLog"),"aria-label":b(x?"mobile.resumeLog":"mobile.pauseLog"),children:x?(0,n.jsx)(ev.jG,{size:13}):(0,n.jsx)(ev.vR,{size:13})}),(0,n.jsx)("button",{onClick:()=>{(0,eN.e)(),f(!h),w()},className:`p-1.5 rounded-brand transition-colors ${h?"text-amber-400 bg-surface-2":"text-text-muted hover:text-text"}`,title:b(h?"mobile.hideNoise":"mobile.showNoise"),"aria-label":b(h?"mobile.hideNoise":"mobile.showNoise"),children:(0,n.jsx)(ev.dJ,{size:13})}),(0,n.jsx)("button",{onClick:()=>{let e;(0,eN.e)(),e=l.map(e=>`${e.time} ${e.level} ${e.tag}: ${e.message}`).join("\n"),navigator.clipboard?.writeText(e)},className:"p-1.5 text-text-muted hover:text-text rounded-brand transition-colors",title:b("common.clipboardCopy"),"aria-label":b("common.clipboardCopy"),children:(0,n.jsx)(ev.QR,{size:13})}),(0,n.jsx)("button",{onClick:()=>{(0,eN.e)(),a()},className:"p-1.5 text-text-muted hover:text-red-400 rounded-brand transition-colors",title:b("mobile.clearLog"),"aria-label":b("mobile.clearLog"),children:(0,n.jsx)(ev.TB,{size:13})})]}),(0,n.jsxs)("div",{ref:g,onScroll:()=>{let e=g.current;e&&y(e.scrollHeight-e.scrollTop-e.clientHeight<40)},className:"flex-1 overflow-auto modal-scrollable font-mono text-[11px] leading-[1.45] p-2",children:[0===l.length&&(0,n.jsx)("p",{className:"text-text-muted text-xs text-center py-6 font-sans",children:b("mobile.noLogs")}),l.map(e=>(0,n.jsxs)("div",{className:"whitespace-pre-wrap break-all",children:[(0,n.jsx)("span",{className:"text-text-muted/60",children:e.time})," ",(0,n.jsx)("span",{className:ea[e.level]||"text-text",children:e.level})," ",(0,n.jsx)("span",{className:"text-brand-500/70",children:e.tag}),e.tag?": ":"",(0,n.jsx)("span",{className:ea[e.level]||"text-text",children:e.message})]},e.seq))]}),x&&(0,n.jsx)("div",{className:"px-2 py-1 text-[11px] text-amber-400 bg-amber-400/10 flex-shrink-0 text-center",children:b("mobile.logPaused")})]})}function iq(e){let{onClose:t,busRef:s,protocolRef:l,connected:a,variant:i="fullscreen"}=e,{t:o}=(0,eC.s)(),c=(0,r.useRef)(null),[d,u]=(0,r.useState)(null),[m,x]=(0,r.useState)(!1),[p,h]=(0,r.useState)(!1),b=function(e){let{busRef:t,connected:s}=e,[n,l]=(0,r.useState)([]),[a,i]=(0,r.useState)(!1),[o,c]=(0,r.useState)(null),[d,u]=(0,r.useState)(()=>new Set),[m,x]=(0,r.useState)(null),[p,h]=(0,r.useState)(!1),[b,g]=(0,r.useState)(null),v=(0,f.B)(e=>e.mobileLowPower),y=(0,f.B)(e=>e.setMobileLowPower),w=(0,r.useCallback)(async()=>{let e=t?.current;if(!e||!s)return[];let n=await ei(e,"mobile:list",{});if(!n?.success)return[];h(!0),i(!!n.canManageEmulators),n.env&&g(n.env.job||null);let r=Array.isArray(n.devices)?n.devices:[];return l(r),u(e=>{let t=new Set(r.map(e=>e.serial).filter(Boolean));for(let s of e)if(t.has(s))return e;let s=new Set([...e].filter(e=>t.has(e)));return s.size===e.size?e:s}),r},[t,s]);(0,r.useEffect)(()=>{let e=t?.current;if(!e||!s)return;let n=e=>{let{avdName:t,phase:s}=e;return c({avdName:t,phase:s})};e.on("mobile:avdProgress",n);let r=e=>{g(e),("done"===e.phase||"error"===e.phase)&&w()};return e.on("mobile:sdkProgress",r),()=>{e.off("mobile:avdProgress",n),e.off("mobile:sdkProgress",r)}},[t,s,w]),(0,r.useEffect)(()=>{if(!s)return;w();let e=setInterval(w,5e3);return()=>clearInterval(e)},[s,w]);let j=(0,r.useCallback)(async e=>{x(null),c({avdName:e,phase:"launching"});let s=await ei(t?.current,"mobile:avdStart",{avdName:e,lowPower:v});return(c(null),await w(),s?.success)?s.serial:(x(s?.error||"Could not start"),null)},[t,w,v]),k=(0,r.useCallback)(async e=>{if(!e)return!1;x(null),u(t=>new Set(t).add(e));let s=await ei(t?.current,"mobile:avdStop",{serial:e});return await w(),u(t=>{let s=new Set(t);return s.delete(e),s}),s?.success||x(s?.error||"Could not stop"),s?.success},[t,w]),[N,C]=(0,r.useState)([]),S=(0,r.useCallback)(async()=>{let e=await ei(t?.current,"mobile:provisionPresets",{});e?.success&&C(Array.isArray(e.presets)?e.presets:[])},[t]),T=(0,r.useCallback)(async e=>{x(null);let s=await ei(t?.current,"mobile:provision",{presetId:e});return await Promise.all([w(),S()]),!!s?.success||(x(s?.error||"Could not create device"),!1)},[t,w,S]),E=(0,r.useCallback)(async()=>{await ei(t?.current,"mobile:sdkCancel",{}),await w()},[t,w]),R=(0,r.useCallback)(async e=>{let s=await ei(t?.current,"mobile:avdDelete",{avdName:e});return s?.success||x(s?.error||"Could not delete"),await w(),s?.success},[t,w]),M=(0,r.useCallback)(async e=>{let s=await ei(t?.current,"mobile:avdWipe",{avdName:e});return s?.success||x(s?.error||"Could not wipe"),await w(),s?.success},[t,w]);return{devices:n,canManage:a,booting:o,error:m,setError:x,refresh:w,startAvd:j,stopAvd:k,stopping:d,lowPower:v,setLowPower:y,sdkJob:b,presets:N,refreshPresets:S,provision:T,cancelSetup:E,deleteAvd:R,wipeAvd:M,loaded:p}}({busRef:s,connected:a}),{devices:g,canManage:v,booting:y,refresh:w,startAvd:j,stopAvd:k,stopping:N,lowPower:C,setLowPower:S,sdkJob:T,presets:E,refreshPresets:R,provision:M,cancelSetup:$,deleteAvd:z,wipeAvd:P}=b,{serial:A,meta:I,starting:D,error:L,open:B,stop:F,cancel:O}=function(e){let{busRef:t,connected:s,devices:n,startAvd:l,stopAvd:a,stopping:i}=e,o=(0,f.B)(e=>e.mobileSession),c=(0,f.B)(e=>e.setMobileSession),d=o?.serial??null,u=o?.meta??null,[m,x]=(0,r.useState)(!1),[p,h]=(0,r.useState)(null),b=(0,r.useRef)(!1),g=(0,r.useRef)(!1),v=(0,r.useRef)(new Set);(0,r.useEffect)(()=>{u&&(b.current=!0)},[u]);let y=(0,r.useCallback)(()=>{t?.current?.emit("mobile:stop"),b.current=!1,c(null)},[t,c]),w=(0,r.useCallback)(()=>{g.current=!0,y()},[y]),j=(0,r.useCallback)(async e=>{let s=Math.max(window.innerWidth,window.innerHeight),n=window.devicePixelRatio,r=await ei(t?.current,"mobile:start",{serial:e,options:function(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,n=en[e]||en[er],r=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,n=Math.min(1600,Math.max(640,Math.round(e*Math.min(t||1,3)*s)));return n-n%8}(t,s,n.edgeScale),l=r*Math.round(.45*r);return{maxSize:r,bitRate:Math.min(n.maxBitRate,Math.round(l*n.maxFps*n.bitsPerPixel)),maxFps:n.maxFps}}(er,s,n)});if(!r?.success)throw Error(r?.error||"Failed to start");return b.current=!0,c({serial:e,meta:r.meta}),r.meta},[t,c]),k=(0,r.useCallback)(async e=>{if(e){g.current=!1,x(!0),h(null),v.current.add(e.id);try{let t=e.serial||(e.avdName?await l(e.avdName):null);if(g.current){t&&a?.(t);return}if(!t)throw Error("Device did not start");await j(t),g.current&&(y(),t&&a?.(t))}catch(e){g.current||h(e.message)}finally{x(!1)}}},[l,j,a,y]);return(0,r.useEffect)(()=>{if(u||m||d)return;let e=n.filter(e=>"running"===e.state);if(1!==e.length||1!==n.length)return;let t=e[0];if(v.current.has(t.id)||i?.has(t.serial))return;let s=setTimeout(()=>k(t),0);return()=>clearTimeout(s)},[n,u,m,d,k,i]),(0,r.useEffect)(()=>{let e=t?.current;if(!e||!s)return;let n=e=>{let{meta:t}=e;t&&c(e=>e?{...e,meta:t}:e)};return e.on("mobile:resized",n),()=>e.off("mobile:resized",n)},[t,s,c]),(0,r.useEffect)(()=>{!s&&b.current&&(b.current=!1,c(null))},[s,c]),{serial:d,meta:u,starting:m,error:p,setError:h,open:k,stop:y,cancel:w}}({busRef:s,connected:a,devices:g,startAvd:j,stopAvd:k,stopping:N}),{status:_,fps:K}=function(e){let{busRef:t,connected:s,canvasRef:n,meta:l}=e,[a,i]=(0,r.useState)("idle"),[o,c]=(0,r.useState)(0),d=(0,r.useRef)(null),u=(0,r.useCallback)(()=>{let e=d.current,s=performance.now();e&&s-e.lastKeyframeReq<1e3||(e&&(e.lastKeyframeReq=s),t?.current?.emit("mobile:keyframe"))},[t]);return(0,r.useEffect)(()=>{let e=t?.current;if(!e||!s||!l||!iL)return;let r={decoder:null,pending:new Map,queue:[],raf:0,sawKey:!1,dropping:!1,lastKeyframeReq:0,ackedSeq:-1,config:null,frameCount:0,fpsAt:performance.now()};d.current=r,i("connecting");let a=()=>{if(r.decoder&&"closed"!==r.decoder.state)try{r.decoder.close()}catch{}for(let e of(r.decoder=null,r.sawKey=!1,r.queue))e.close();r.queue=[]},o=()=>{r.raf=0;let e=n.current;for(;r.queue.length>1;)r.queue.shift()?.close();let t=r.queue.shift();if(!t)return;let s=e?.getContext("2d",{alpha:!1,desynchronized:!0});s&&s.drawImage(t,0,0,e.width,e.height),t.close(),r.frameCount++;let l=performance.now();l-r.fpsAt>=1e3&&(c(Math.round(1e3*r.frameCount/(l-r.fpsAt))),r.frameCount=0,r.fpsAt=l),r.queue.length&&(r.raf=requestAnimationFrame(o))},m=()=>{a(),r.dropping=!0,u()},x=e=>{if(r.decoder?.state==="configured")return!0;a();let t=new VideoDecoder({output:e=>{r.decoder!==t?e.close():(r.queue.length>=3&&r.queue.shift()?.close(),r.queue.push(e),r.raf||(r.raf=requestAnimationFrame(o)))},error:()=>{r.decoder===t&&m()}});try{let s;return t.configure({codec:(s=e=>e.toString(16).padStart(2,"0"),`avc1.${s(e[1])}${s(e[2])}${s(e[3])}`),optimizeForLatency:!0}),r.decoder=t,!0}catch{try{t.close()}catch{}return i("decoder failed"),u(),!1}},p=e=>{let{data:t,isKey:s,isConfig:n,ptsMs:l}=e,a=t;if(n){r.config=a;let e=iD(a).spsBytes;e&&x(e);return}if(s&&r.decoder?.state!=="configured"){if(!r.config)return void u();let e=iD(r.config).spsBytes;if(!e||!x(e))return}if(s&&r.config){let e=new Uint8Array(r.config.byteLength+a.byteLength);e.set(r.config,0),e.set(a,r.config.byteLength),a=e}if(r.dropping){if(!s||r.decoder?.state!=="configured")return void u();r.dropping=!1}if(r.decoder?.state!=="configured"){s||u();return}if(r.decoder.decodeQueueSize>30)return void(r.dropping=!0,u());if(!r.sawKey){if(!s)return void u();r.sawKey=!0,i("streaming")}try{r.decoder.decode(new EncodedVideoChunk({type:s?"key":"delta",timestamp:1e3*l,data:a}))}catch{m()}},h=t=>{t<=r.ackedSeq||(r.ackedSeq=t,e.emit("mobile:ack",{seq:t}))},f=e=>{let t=function(e){let t=e instanceof ArrayBuffer?new Uint8Array(e):e;if(t.byteLength<18)return null;let s=new DataView(t.buffer,t.byteOffset,t.byteLength);if(0xffffffff!==s.getUint32(0))return null;let n=s.getUint8(12);return{frameSeq:s.getUint32(4),chunkIdx:s.getUint16(8),chunkCount:s.getUint16(10),isKey:(1&n)!=0,isConfig:(2&n)!=0,ptsMs:s.getUint32(14),payload:t.slice(18)}}(e);if(!t)return;if(1===t.chunkCount){h(t.frameSeq),p({data:t.payload,isKey:t.isKey,isConfig:t.isConfig,ptsMs:t.ptsMs});return}let s=r.pending.get(t.frameSeq);if(!s)for(let e of(s={chunks:Array(t.chunkCount),received:0,count:t.chunkCount,isKey:t.isKey,isConfig:t.isConfig,ptsMs:t.ptsMs},r.pending.set(t.frameSeq,s),r.pending.keys()))t.frameSeq-e>96&&r.pending.delete(e);if(s.chunks[t.chunkIdx]||(s.chunks[t.chunkIdx]=t.payload,s.received++,s.received!==s.count))return;r.pending.delete(t.frameSeq),h(t.frameSeq);let n=new Uint8Array(s.chunks.reduce((e,t)=>e+t.byteLength,0)),l=0;for(let e of s.chunks)n.set(e,l),l+=e.byteLength;p({data:n,isKey:s.isKey,isConfig:s.isConfig,ptsMs:s.ptsMs})},b=()=>i("ended");return e.on("mobile-bin",f),e.on("file-bin",f),e.on("mobile:ended",b),u(),()=>{e.off("mobile-bin",f),e.off("file-bin",f),e.off("mobile:ended",b),r.raf&&cancelAnimationFrame(r.raf),a(),r.pending.clear(),d.current=null}},[t,s,n,l,u]),(0,r.useEffect)(()=>{let e=t?.current;if(!e||!s||!l)return;let n=()=>{let t=!document.hidden;e.emit("mobile:visible",{visible:t}),t&&u()};return document.addEventListener("visibilitychange",n),e.emit("mobile:visible",{visible:!document.hidden}),()=>document.removeEventListener("visibilitychange",n)},[t,s,l,u]),{status:iL?a:"unsupported",fps:o,requestKeyframe:u}}({busRef:s,connected:a,canvasRef:c,meta:I}),W=function(e){let{busRef:t,canvasRef:s}=e,n=(0,r.useRef)(null),l=(0,r.useRef)(null),a=(0,r.useRef)(0),i=(0,r.useCallback)(e=>{t?.current?.emit("mobile:input",e)},[t]),o=(0,r.useCallback)(()=>{a.current=0;let e=l.current;e&&(l.current=null,i({type:"touch",action:"move",...e}))},[i]),c=(0,r.useCallback)(e=>{let t=s.current;if(!t)return null;let n=t.getBoundingClientRect(),r=Math.min(n.width/t.width,n.height/t.height),l=t.width*r,a=t.height*r,i=n.left+(n.width-l)/2,o=n.top+(n.height-a)/2,c=(e.clientX-i)/l,d=(e.clientY-o)/a;return c<0||c>1||d<0||d>1?null:{x:c,y:d}},[s]),d=(0,r.useCallback)(e=>{let t=c(e);t&&(e.currentTarget.setPointerCapture?.(e.pointerId),n.current=t,i({type:"touch",action:"down",...t}))},[i,c]),u=(0,r.useCallback)(e=>{if(!n.current)return;let t=c(e);t&&(l.current=t,a.current||(a.current=requestAnimationFrame(o)))},[o,c]),m=(0,r.useCallback)(e=>{let t=c(e);if(!t)return;e.preventDefault();let s=1===e.deltaMode?16:2===e.deltaMode?400:1,n=e=>Math.max(-16,Math.min(16,-(e*s)/100));i({type:"scroll",...t,hscroll:n(e.deltaX),vscroll:n(e.deltaY)})},[i,c]),x=(0,r.useCallback)(e=>{let t=n.current;t&&(n.current=null,l.current=null,a.current&&(cancelAnimationFrame(a.current),a.current=0),i({type:"touch",action:"up",...c(e)||{x:t.x,y:t.y}}))},[i,c]);return{onPointerDown:d,onPointerMove:u,onPointerUp:x,onPointerCancel:x,onWheel:m,sendKey:(0,r.useCallback)(e=>i({type:"key",name:e}),[i])}}({busRef:s,canvasRef:c}),H=function(e){let{busRef:t,protocolRef:s,serial:n,enabled:l}=e,[a,i]=(0,r.useState)([]),[o,c]=(0,r.useState)(null),[d,u]=(0,r.useState)(null),[m,x]=(0,r.useState)(0),[p,h]=(0,r.useState)(null),f=(0,r.useCallback)(async()=>{if(!n||!l)return;let e=await ei(t?.current,"mobile:apps",{serial:n});e?.success&&(i(e.apps||[]),c(e.foreground||null))},[t,n,l]);(0,r.useEffect)(()=>{f()},[f]);let b=(0,r.useCallback)(async(e,s,r)=>{u(s),h(null);let l=await ei(t?.current,e,{serial:n,packageName:s});return(u(null),l?.success)?(r&&await f(),!0):(h(l?.error||"Failed"),!1)},[t,n,f]),g=(0,r.useCallback)(e=>b("mobile:launch",e),[b]),v=(0,r.useCallback)(e=>b("mobile:stopApp",e),[b]),y=(0,r.useCallback)(e=>b("mobile:clearApp",e),[b]),w=(0,r.useCallback)(e=>b("mobile:uninstall",e,!0),[b]),j=(0,r.useCallback)(async e=>{if(e&&n){u("install"),h(null),x(0);try{let r=await ei(t?.current,"mobile:apkStage",{name:e.name,size:e.size});if(!r?.success)throw Error(r?.error||"Cannot stage APK");let l=null;if(await ed({bus:t?.current,protocolRef:s,targetDir:r.targetDir,items:[{file:e,relativePath:r.fileName}],callbacks:{onProgress:(e,t,s)=>x(s?t/s:0),onError:(e,t)=>{l=t}}}),l)throw l;let a=await ei(t?.current,"mobile:install",{serial:n,fileName:r.fileName,launch:!0});if(!a?.success)throw Error(a?.error||"Install failed");return await f(),a.packageName}catch(e){return h(e.message),null}finally{u(null),x(0)}}},[t,s,n,f]),k=(0,r.useCallback)(async e=>{h(null);let s=await ei(t?.current,"mobile:openLink",{serial:n,url:e});return s?.success||h(s?.error||"Could not open link"),s?.success},[t,n]);return{apps:a,foreground:o,busy:d,progress:m,error:p,setError:h,refresh:f,install:j,launch:g,stopApp:v,clearData:y,uninstall:w,openLink:k}}({busRef:s,protocolRef:l,serial:A,enabled:!!I}),q=function(e){let{busRef:t,serial:s,active:n,foregroundPackage:l}=e,[a,i]=(0,r.useState)([]),[o,c]=(0,r.useState)("I"),[d,u]=(0,r.useState)(""),[m,x]=(0,r.useState)(null),p=(0,r.useRef)(!1);(0,r.useEffect)(()=>{!p.current&&l&&x(l)},[l]);let h=(0,r.useCallback)(e=>{p.current=!0,x(e)},[]),[f,b]=(0,r.useState)(!1),[g,v]=(0,r.useState)(!1),y=(0,r.useRef)(0),w=(0,r.useRef)(!1);(0,r.useEffect)(()=>{w.current=f},[f]);let j=(0,r.useCallback)(()=>i([]),[]);return(0,r.useEffect)(()=>{let e=t?.current;if(!e||!s||!n)return;i([]);let r=e=>{let{lines:t}=e;!w.current&&Array.isArray(t)&&i(e=>{let s=e.concat(t.map(e=>{var t;let s;return t=y.current++,(s=iB.exec(e))?{seq:t,time:s[1].slice(6),level:s[2],tag:s[3].trim(),message:s[4]}:{seq:t,time:"",level:"V",tag:"",message:e}}));return s.length>5e3?s.slice(s.length-5e3):s})};return e.on("mobile:logcat",r),ei(e,"mobile:logcatStart",{serial:s,minLevel:o,search:d,includeNoise:g,...p.current||m?{packageName:m}:{}}),()=>{e.off("mobile:logcat",r),e.emit("mobile:logcatStop")}},[t,s,n]),(0,r.useEffect)(()=>{if(!n||!s)return;let e=setTimeout(()=>{t?.current?.emit("mobile:logcatFilter",{minLevel:o,search:d,packageName:m,includeNoise:g})},200);return()=>clearTimeout(e)},[o,d,m,g,n,s,t]),{lines:a,clear:j,minLevel:o,setMinLevel:c,search:d,setSearch:u,packageName:m,setPackageName:h,paused:f,setPaused:b,includeNoise:g,setIncludeNoise:v}}({busRef:s,serial:A,active:!!I&&"logs"===d,foregroundPackage:H.foreground?.packageName});(0,r.useEffect)(()=>{let e=c.current;e&&I&&(e.width=I.width,e.height=I.height)},[I]);let U="panel"===i,X=g.find(e=>e.serial===A)||null,V=(0,r.useCallback)(async()=>{x(!1),F(),A&&await k(A)},[A,F,k]),G=(0,r.useCallback)(async e=>{e.serial===A&&F(),await k(e.serial)},[A,F,k]),J=(0,r.useCallback)(()=>{U||F(),t?.()},[U,F,t]),Y=(0,r.useCallback)(()=>{let e=g.find(e=>e.serial===A);e&&B(e)},[g,A,B]);if(!I){let e;return(0,n.jsxs)("div",{className:"absolute inset-0 flex flex-col bg-bg",children:[!U&&(0,n.jsxs)("header",{className:"flex items-center gap-2 px-2 py-1.5 border-b border-border flex-shrink-0",children:[(0,n.jsx)("button",{onClick:()=>{(0,eN.e)(),J()},className:"p-1.5 text-text hover:bg-surface-2 rounded-brand transition-all duration-150 ease-out active:scale-[0.94]","aria-label":o("common.back"),children:(0,n.jsx)(ev.JG,{size:18})}),(0,n.jsx)(ev.wO,{size:16,className:"text-brand-500 flex-shrink-0"}),(0,n.jsx)("span",{className:"text-sm text-text truncate",children:o("mobile.title")})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto modal-scrollable flex items-center justify-center",children:D||y?(0,n.jsxs)("div",{className:"flex flex-col items-center gap-3 p-6 text-center",children:[(0,n.jsx)(ev.kr,{size:22,className:"text-brand-500 animate-spin"}),(0,n.jsx)("p",{className:"text-text text-sm",children:y?(e=y.phase,o(`mobile.phase${e.charAt(0).toUpperCase()}${e.slice(1)}`)):o("mobile.starting")}),y&&(0,n.jsx)("p",{className:"text-text-muted text-xs",children:y.avdName}),(0,n.jsx)("button",{onClick:()=>{(0,eN.e)(),O()},className:"px-3 py-1.5 text-xs text-text-muted bg-surface hover:bg-surface-2 rounded-brand transition-colors",children:o("common.cancel")})]}):iL?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(iO,{devices:g,canManage:v,booting:y,stopping:N,loading:!b.loaded,error:L||b.error,onOpen:B,onStop:G,onRefresh:w,lowPower:C,onLowPowerChange:S,onAddDevice:()=>{R(),h(!0)},onDeleteAvd:z,onWipeAvd:P,sdkJob:T,onShowSetup:()=>h(!0)}),(0,n.jsx)(iK,{isOpen:p,onClose:()=>h(!1),presets:E,sdkJob:T,onProvision:M,onCancel:$})]}):(0,n.jsx)("p",{className:"text-text-muted text-sm max-w-xs text-center p-6",children:o("mobile.unsupportedBrowser")})})]})}return(0,n.jsxs)("div",{className:"absolute inset-0 flex bg-bg",children:[(0,n.jsx)(ek.A,{isOpen:m,onClose:()=>x(!1),onConfirm:V,title:o("mobile.shutdownTitle"),message:o("mobile.shutdownMessage",{name:I.deviceName}),confirmText:o("mobile.shutdownConfirm")}),(0,n.jsxs)("div",{className:"flex-1 min-w-0 relative flex items-center justify-center bg-black",children:[(0,n.jsx)("canvas",{ref:c,onPointerDown:W.onPointerDown,onPointerMove:W.onPointerMove,onPointerUp:W.onPointerUp,onPointerCancel:W.onPointerCancel,onWheel:W.onWheel,className:"max-w-full max-h-full object-contain touch-none"}),("connecting"===_||"idle"===_)&&(0,n.jsx)("div",{className:"absolute inset-0 flex items-center justify-center pointer-events-none",children:(0,n.jsx)(ev.kr,{size:22,className:"text-brand-500 animate-spin"})}),("ended"===_||"decoder failed"===_)&&(0,n.jsxs)("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-3 px-6 text-center bg-black/40",children:[(0,n.jsx)("p",{className:"text-text text-sm",children:o("ended"===_?"mobile.streamEnded":"mobile.streamFailed")}),X?(0,n.jsx)("button",{onClick:()=>{(0,eN.e)(),Y()},className:"px-3 py-1.5 text-xs text-brand-500 bg-surface hover:bg-surface-2 rounded-brand transition-colors",children:o("mobile.retry")}):(0,n.jsx)("p",{className:"text-text-muted text-xs",children:o("mobile.streamGone")})]}),"streaming"===_&&K>0&&(0,n.jsxs)("span",{className:"absolute top-2 right-2 px-1.5 py-0.5 rounded bg-black/50 text-[10px] text-white/80 pointer-events-none",children:[K," fps"]}),d&&(0,n.jsx)("button",{onClick:()=>{(0,eN.e)(),u(null)},className:"absolute inset-x-0 top-0 h-16 z-10 cursor-pointer","aria-label":o("mobile.backToScreen")}),d&&(0,n.jsxs)("div",{className:"absolute inset-x-0 bottom-0 top-16 bg-bg border-t border-border flex flex-col shadow-[0_-8px_24px_rgba(0,0,0,0.35)] sheet-rise",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-2.5 py-1.5 border-b border-border flex-shrink-0",children:["apps"===d?(0,n.jsx)(ev.lP,{size:14,className:"text-brand-500 flex-shrink-0"}):(0,n.jsx)(ev.iU,{size:14,className:"text-brand-500 flex-shrink-0"}),(0,n.jsx)("span",{className:"text-xs text-text flex-1 truncate",children:o("apps"===d?"mobile.tabApps":"mobile.tabLogs")}),(0,n.jsx)("button",{onClick:()=>{(0,eN.e)(),u(null)},className:"p-1 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors",title:o("mobile.backToScreen"),"aria-label":o("mobile.backToScreen"),children:(0,n.jsx)(ev.X,{size:14})})]}),"apps"===d?(0,n.jsx)(iW,{apps:H.apps,foreground:H.foreground,busy:H.busy,progress:H.progress,error:H.error,onInstall:H.install,onLaunch:H.launch,onStopApp:H.stopApp,onClearData:H.clearData,onUninstall:H.uninstall,onOpenLink:H.openLink,onRefresh:H.refresh}):(0,n.jsx)(iH,{logcat:q,apps:H.apps})]},d)]}),(0,n.jsxs)("div",{className:"flex flex-col items-center gap-0.5 px-1 py-1.5 pb-safe border-l border-border flex-shrink-0 overflow-y-auto modal-scrollable",children:[(0,n.jsx)(iU,{icon:(0,n.jsx)(ev.lM,{size:15,className:"-rotate-90"}),label:o("mobile.back"),onClick:()=>W.sendKey("back")}),(0,n.jsx)(iU,{icon:(0,n.jsx)(ev.jl,{size:15}),label:o("mobile.home"),onClick:()=>W.sendKey("home")}),(0,n.jsx)(iU,{icon:(0,n.jsx)(ev.M6,{size:14}),label:o("mobile.recents"),onClick:()=>W.sendKey("recents")}),(0,n.jsx)("div",{className:"w-5 h-px bg-border my-1"}),(0,n.jsx)(iU,{icon:(0,n.jsx)(ev.LM,{size:15}),label:o("mobile.power"),onClick:()=>W.sendKey("power")}),(0,n.jsx)("div",{className:"w-5 h-px bg-border my-1"}),(0,n.jsx)(iU,{icon:(0,n.jsx)(ev.lP,{size:15}),label:o("mobile.tabApps"),onClick:()=>u("apps"===d?null:"apps"),active:"apps"===d}),(0,n.jsx)(iU,{icon:(0,n.jsx)(ev.iU,{size:15}),label:o("mobile.tabLogs"),onClick:()=>u("logs"===d?null:"logs"),active:"logs"===d}),(0,n.jsx)("div",{className:"flex-1 min-h-2"}),(0,n.jsx)(iU,{icon:(0,n.jsx)(ev.wO,{size:15}),label:o("mobile.switchDevice"),onClick:F}),X?.canStop&&(0,n.jsx)("button",{onClick:()=>{(0,eN.e)(),x(!0)},className:"p-2 rounded-brand transition-all duration-150 ease-out active:scale-[0.94] flex-shrink-0 text-red-400 hover:bg-red-500/15",title:o("mobile.shutdownDevice"),"aria-label":o("mobile.shutdownDevice"),children:(0,n.jsx)(ev.$o,{size:15})}),!U&&(0,n.jsx)(iU,{icon:(0,n.jsx)(ev.X,{size:15}),label:o("common.close"),onClick:J})]})]})}function iU(e){let{icon:t,label:s,onClick:r,active:l=!1}=e;return(0,n.jsx)("button",{onClick:()=>{(0,eN.e)(),r?.()},className:`p-2 rounded-brand transition-all duration-150 ease-out active:scale-[0.94] flex-shrink-0 ${l?"text-brand-500 bg-surface-2":"text-text hover:bg-surface-2"}`,title:s,"aria-label":s,"aria-pressed":l,children:t})}let iX=[{edge:"n",className:"top-0 left-3 right-3 h-1",cursor:"cursor-ns-resize"},{edge:"s",className:"bottom-0 left-3 right-3 h-1",cursor:"cursor-ns-resize"},{edge:"w",className:"top-3 bottom-3 left-0 w-1",cursor:"cursor-ew-resize"},{edge:"e",className:"top-3 bottom-3 right-0 w-1",cursor:"cursor-ew-resize"},{edge:"nw",className:"top-0 left-0 w-3 h-3",cursor:"cursor-nwse-resize"},{edge:"ne",className:"top-0 right-0 w-3 h-3",cursor:"cursor-nesw-resize"},{edge:"sw",className:"bottom-0 left-0 w-3 h-3",cursor:"cursor-nesw-resize"},{edge:"se",className:"bottom-0 right-0 w-3 h-3",cursor:"cursor-nwse-resize"}];function iV(e){let{busRef:t,protocolRef:s,connected:l,pinSlot:a=null}=e,{t:i}=(0,eC.s)(),o=(0,f.B)(e=>e.mobileMode),c=(0,f.B)(e=>e.mobileFloatRect),d=(0,f.B)(e=>e.setMobileOpen),u=(0,f.B)(e=>e.setMobileSession),m=(0,f.B)(e=>e.setMobileMode),x=function(e){let{rect:t,onChange:s,enabled:n}=e,[l,a]=(0,r.useState)(()=>{let e,s;return t?iI(t):(e=ez.qj.width.default,s=Math.min(ez.qj.height.default,window.innerHeight-2*ez.qj.defaultOffset),{x:Math.max(ez.qj.margin,window.innerWidth-e-ez.qj.defaultOffset),y:Math.max(ez.qj.margin,window.innerHeight-s-ez.qj.defaultOffset),w:e,h:s})}),[i,o]=(0,r.useState)(!1),c=(0,r.useRef)(null),d=(0,r.useRef)(l),u=(0,r.useCallback)(e=>{d.current=e,a(e)},[]);(0,r.useEffect)(()=>{if(!n)return;let e=()=>{let e=d.current;if(!e)return;let t=Math.min(e.h,window.innerHeight-2*ez.qj.margin);u(iI({...e,h:t}))};return window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[n,u]);let m=(0,r.useCallback)((e,t)=>{(null==e.button||0===e.button)&&(e.preventDefault(),e.currentTarget.setPointerCapture?.(e.pointerId),c.current={mode:t,pointerId:e.pointerId,startX:e.clientX,startY:e.clientY,origin:l},o(!0))},[l]),x=(0,r.useCallback)(e=>{let t=c.current;if(!t||t.pointerId!==e.pointerId)return;if("mouse"===e.pointerType&&0===e.buttons)return void p(e);let s=e.clientX-t.startX,n=e.clientY-t.startY;if("move"===t.mode)return void u(iI({...t.origin,x:t.origin.x+s,y:t.origin.y+n}));let{origin:r,mode:l}=t,a=l.includes("w"),i=l.includes("n"),o=a||l.includes("e"),d=i||l.includes("s"),m=window.innerHeight-2*ez.qj.margin,x=i?r.y+r.h-ez.qj.margin:m,h=a?r.x+r.w-ez.qj.margin:ez.qj.width.max,f=o?iA(a?r.w-s:r.w+s,ez.qj.width.min,Math.min(ez.qj.width.max,h)):r.w,b=d?iA(i?r.h-n:r.h+n,ez.qj.height.min,Math.min(m,x)):r.h;u({x:a?r.x+(r.w-f):r.x,y:i?r.y+(r.h-b):r.y,w:f,h:b})},[u]),p=(0,r.useCallback)(e=>{let t=c.current;t&&t.pointerId===e.pointerId&&(c.current=null,o(!1),d.current&&s?.(d.current))},[s]);return(0,r.useEffect)(()=>{if(!i)return;let e=()=>{c.current=null,o(!1),d.current&&s?.(d.current)};return window.addEventListener("blur",e),()=>window.removeEventListener("blur",e)},[i,s]),{rect:l,dragging:i,onDragHandlePointerDown:e=>m(e,"move"),onResizeHandlePointerDown:e=>t=>m(t,e),onPointerMove:x,onPointerUp:p,onPointerCancel:p}}({rect:c,onChange:(0,f.B)(e=>e.setMobileFloatRect),enabled:"float"===o}),p=(0,r.useCallback)(()=>{t?.current?.emit("mobile:stop"),u(null),d(!1)},[t,u,d]),h="pin"===o,b=e=>(0,n.jsxs)("div",{className:"flex flex-col h-full w-full bg-bg overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex items-center gap-0.5 px-1.5 py-1 bg-surface flex-shrink-0",children:[(0,n.jsxs)("div",{className:`flex items-center gap-1 flex-1 min-w-0 ${e?"cursor-grab active:cursor-grabbing":""}`,onPointerDown:e?x.onDragHandlePointerDown:void 0,children:[e&&(0,n.jsx)(ev.f2,{size:13,className:"text-text-muted flex-shrink-0"}),(0,n.jsx)("span",{className:"text-xs text-text-muted select-none truncate",children:i("mobile.title")})]}),(0,n.jsx)("button",{onClick:()=>{(0,eN.e)(),m(h?"float":"pin")},className:`p-1.5 rounded-brand transition-colors ${h?"text-brand-500 bg-surface-2":"text-text-muted hover:text-text hover:bg-surface-2"}`,title:h?i("mobile.modeFloat"):i("mobile.modePin"),"aria-label":h?i("mobile.modeFloat"):i("mobile.modePin"),"aria-pressed":h,children:(0,n.jsx)(ev.jz,{size:13})}),(0,n.jsx)("button",{onClick:()=>{(0,eN.e)(),p()},className:"p-1.5 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors",title:i("common.close"),"aria-label":i("common.close"),children:(0,n.jsx)(ev.X,{size:13})})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0 relative",children:(0,n.jsx)(iq,{busRef:t,protocolRef:s,connected:l,variant:"panel",onClose:p})})]});if(h)return a?(0,sp.createPortal)(b(!1),a):null;let g=x.rect;return g?(0,sp.createPortal)((0,n.jsxs)("div",{className:"fixed z-40 flex flex-col rounded-brand-lg overflow-hidden border border-border shadow-2xl bg-bg",style:{left:g.x,top:g.y,width:g.w,height:g.h},onPointerMove:x.onPointerMove,onPointerUp:x.onPointerUp,onPointerCancel:x.onPointerCancel,children:[b(!0),iX.map(e=>{let{edge:t,className:s,cursor:r}=e;return(0,n.jsx)("div",{onPointerDown:x.onResizeHandlePointerDown(t),className:`absolute ${s} ${r}`,"aria-label":i("mobile.resize")},t)})]}),document.body):null}let iG=e=>e?.error==="Not connected";async function iJ(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:()=>!0,s=await e(),n=ez.Tk.retryBaseMs;for(;iG(s)&&t()&&n<=ez.Tk.retryMaxMs&&(await new Promise(e=>setTimeout(e,n)),t());)n*=2,s=await e();return s}let iY=e=>(e||"").split("/").filter(Boolean).pop()||e;function iZ(e,t){return e?e.endsWith("/")?`${e}${t}`:`${e}/${t}`:t}function iQ(e){let t=e.lastIndexOf("/");return t<=0?"/":e.slice(0,t)}function i0(e){if(!e)return"";let t=e.split("/").filter(Boolean);return t[t.length-1]||e}function i1(e){let{dirs:t,fileBus:s,onDirsChanged:n,enabled:l=!0,debounceMs:a=et.Jl.DEBOUNCE_MS}=e,i=(0,r.useRef)(new Set),o=(0,r.useRef)(n);(0,r.useEffect)(()=>{o.current=n},[n]);let{watchDir:c,unwatchDir:d,onFileChange:u}=s||{},m=t.join("\n");(0,r.useEffect)(()=>{if(!l||!c||!d)return;let e=!0,t=i.current,s=new Set,n=null,r=new Set([...m?m.split("\n"):[]].sort((e,t)=>t.split("/").length-e.split("/").length).slice(0,et.Jl.MAX_DIRS)),x=()=>{if(n=null,!e||!s.size)return;let t=[...s];s.clear(),o.current?.(t)},p=async()=>{for(let e of t)r.has(e)||(t.delete(e),d(e));for(let s of r){if(t.has(s))continue;t.add(s);let n=await c(s);e&&n?.watching!==!1||t.delete(s)}},h=u?.(e=>{let{type:t,path:l}=e;if(!l)return;let i="flooded"===t?l:l.slice(0,l.lastIndexOf("/"))||"/";r.has(i)&&(s.add(i),n||(n=setTimeout(x,a)))})||(()=>{});return p(),()=>{for(let s of(e=!1,clearTimeout(n),h(),t))d(s);t.clear()}},[m,l,a,c,d,u])}function i2(){let[e,t]=(0,r.useState)(()=>"u"<typeof document||!document.hidden);return(0,r.useEffect)(()=>{let e=()=>t(!document.hidden);return document.addEventListener("visibilitychange",e),()=>document.removeEventListener("visibilitychange",e)},[]),e}function i5(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";if(!e?.success)return{};let s=e.files||e.status||[],n={};for(let e of s){let s=e?.path||e?.file,r=e?.status||e?.code;if(!s||!r)continue;n[t+s]=r;let l=s.split("/");for(let e=1;e<l.length;e++){let s=t+l.slice(0,e).join("/");n[s]||(n[s]="folder-changed")}}return n}async function i3(e,t){let s=await e.gitStatus(t);if(s?.success)return{hasGit:!0,map:i5(s)};let n=await e.gitScanRepos?.(t),r=(n?.success?n.repos:[])||[],l=await Promise.all(r.map(async t=>{let s=String(t.relPath||"").split("\\").join("/");if(!s)return null;let n=await e.gitStatus(t.path);if(!n?.success)return null;let r=i5(n,`${s}/`);return Object.keys(r).length&&(r[s]||="folder-changed"),r})),a=Object.assign({},...l.filter(Boolean));return{hasGit:l.some(Boolean),map:a}}function i4(){try{let e=window.localStorage.getItem(et.d5.expandedFolders),t=e?JSON.parse(e):{};return Array.isArray(t)?{legacy:t}:t}catch{return{}}}function i6(){try{let e=window.localStorage.getItem(et.d5.showHidden);if(null===e)return!0;return!1!==JSON.parse(e)}catch{return!0}}let i8={created:"fileExplorer:fileCreated",deleted:"fileExplorer:fileDeleted",renamed:"fileExplorer:fileRenamed"};function i9(e){window.dispatchEvent(new CustomEvent(i8[e]))}let{xT:i7,Qm:oe,Pv:ot}=JSON.parse('{"xT":{"js":"js","mjs":"js","cjs":"js","jsx":"reactjs","ts":"typescript","tsx":"reactts","json":"json","json5":"json5","yml":"yaml","yaml":"yaml","toml":"toml","xml":"xml","ini":"ini","env":"dotenv","md":"markdown","markdown":"markdown","mdx":"mdx","pdf":"pdf","csv":"text","html":"html","css":"css","scss":"scss","sass":"sass","less":"less","styl":"stylus","vue":"vue","svelte":"svelte","astro":"astro","py":"python","pyw":"python","rb":"ruby","php":"php","go":"go","rs":"rust","java":"java","kt":"kotlin","swift":"swift","scala":"scala","cljs":"clojure","ex":"elixir","erl":"erlang","hs":"haskell","ml":"ocaml","dart":"dartlang","lua":"lua","r":"r","c":"c","h":"c","cpp":"cpp","hpp":"cpp","cs":"csharp","m":"objectivec","sh":"shell","bash":"shell","zsh":"shell","fish":"shell","ps1":"powershell","bat":"bat","sql":"sql","gql":"graphql","proto":"protobuf","png":"image","jpg":"image","jpeg":"image","gif":"image","webp":"image","ico":"image","bmp":"image","svg":"svg","avif":"image","tiff":"image","mp4":"video","m4v":"video","webm":"video","mov":"video","mkv":"video","avi":"video","mp3":"audio","wav":"audio","ogg":"audio","flac":"audio","m4a":"audio","aac":"audio","zip":"zip","tar":"zip","gz":"zip","tgz":"zip","rar":"zip","7z":"zip","bz2":"zip","xz":"zip","jar":"jar","log":"log","diff":"diff","patch":"diff","woff":"font","woff2":"font","ttf":"font","eot":"font","otf":"font","db":"datadog","sqlite":"sqlite","sqlite3":"sqlite","jsonc":"json","cfg":"ini","conf":"ini","txt":"text","htm":"html","kts":"kotlin","clj":"clojure","exs":"elixir","cc":"cpp","cxx":"cpp","graphql":"graphql","tif":"image"},"Qm":{".editorconfig":"editorconfig",".env":"dotenv",".gitattributes":"git",".gitignore":"git",".npmrc":"npm","docker-compose.yaml":"docker","docker-compose.yml":"docker","dockerfile":"docker","license":"license","makefile":"gnu","package-lock.json":"npm","package.json":"npm","tsconfig.json":"typescript"},"Pv":{"src":"src","source":"src","sources":"src","lib":"library","libs":"library","library":"library","app":"app","apps":"app","application":"app","component":"component","components":"component","page":"view","pages":"view","view":"view","views":"view","html":"view","model":"model","models":"model","controller":"controller","controllers":"controller","handler":"controller","handlers":"controller","route":"route","routes":"route","router":"route","routers":"route","public":"public","assets":"images","images":"images","image":"images","img":"images","icon":"images","icons":"images","font":"fonts","fonts":"fonts","style":"style","styles":"style","css":"style","docs":"docs","doc":"docs","test":"test","tests":"test","__tests__":"test","spec":"test","specs":"test","coverage":"test","util":"tools","utils":"tools","tool":"tools","tools":"tools","helpers":"tools","helper":"tools","script":"script","scripts":"script","config":"config","configs":"config","configuration":"config",".github":"github",".git":"git",".vscode":"vscode",".idea":"idea","node_modules":"node","bower_components":"bower","dist":"dist","out":"dist","export":"dist","exports":"dist","build":"dist","target":"dist","api":"api","apis":"api","server":"server","services":"server","service":"server","locale":"locale","locales":"locale","i18n":"locale","lang":"locale","languages":"locale","bin":"azurepipelines",".bin":"azurepipelines","middleware":"middleware","middlewares":"middleware","store":"redux","stores":"redux","hook":"hook","hooks":"hook","types":"typescript","typings":"typescript","@types":"typescript","interface":"interfaces","interfaces":"interfaces","theme":"theme","themes":"theme","layout":"view","layouts":"view","ios":"ios","static":"public","asset":"images","documentation":"docs","__specs__":"test","state":"redux","type":"typescript","constant":"tools","constants":"tools","core":"src","main":"src","android":"android"}}'),os="/icons/file-types",on="/icons/folder-types",or=`${os}/default.svg`,ol=`${on}/default.svg`,oa=`${on}/default-open.svg`;function oi(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],s=ot[(e||"").toLowerCase()];return s?{src:t?`${on}/${s}-open.svg`:`${on}/${s}.svg`,alt:s}:{src:t?oa:ol,alt:"folder"}}function oo(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:16,{src:s,alt:r}=function(e){if(!e)return{src:or,alt:"file"};if("folder"===e.type)return oi(e.name,!1);let t=(e.name||"").toLowerCase(),s=function(e){if(!e)return"";let t=e.toLowerCase(),s=t.lastIndexOf(".");return s<=0?t:t.slice(s+1)}(e.name);if(oe[t]){let e=oe[t];return{src:`${os}/${e}.svg`,alt:e}}if(i7[s]){let e=i7[s];return{src:`${os}/${e}.svg`,alt:e}}return{src:or,alt:"file"}}(e);return(0,n.jsx)("img",{src:s,alt:r,width:t,height:t,className:"pointer-events-none select-none",draggable:"false"})}let oc=e=>e?et.xW.compact:et.xW.normal,od=function(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],s=oc(t);return s.indentBase+e*s.indentStep};function ou(e){let{status:t}=e;return t?"folder-changed"===t?(0,n.jsx)("span",{className:"ml-auto mr-2 w-1.5 h-1.5 rounded-full bg-blue-400/70"}):(0,n.jsx)("span",{className:`ml-auto mr-2 text-[10px] font-semibold ${et.vs[t]||"text-text-muted"}`,children:t}):null}function om(e){let{depth:t,compact:s=!1}=e;return(0,n.jsx)("div",{className:"text-[11px] text-text-muted italic py-0.5 pr-2",style:{paddingLeft:od(t,s)},children:"Showing first 300 entries — use search for the rest."})}let ox=(0,r.memo)(function(e){let{file:t,depth:s,isFolder:r,isExpanded:l,isLoading:a,isActive:i,isSelected:o,isRenaming:c,isDragOver:d,isCut:u,gitStatus:m,renameValue:x,renameInputRef:p,onRenameChange:h,onRenameSubmit:f,onRenameCancel:b,onToggleFolder:g,onClick:v,onContextMenu:y,onTouchStart:w,onTouchEnd:j,onDragStart:k,onDragOver:N,onDragLeave:C,onDrop:S,compact:T=!1,children:E}=e,R=oc(T);return(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{"data-path":t.path,draggable:!c,onDragStart:e=>k(e,t),onDragOver:e=>N(e,t),onDragLeave:()=>C(t),onDrop:e=>S(e,t),className:`group relative flex items-center gap-1 rounded-[3px] mx-0.5 pr-2 cursor-pointer select-none ${R.text} ${R.padY} ${u?"opacity-50":""} ${d?"bg-brand-500/30 ring-1 ring-brand-500":o?"bg-brand-500/25":i?"bg-brand-500/15":"hover:bg-surface-2"}`,style:{paddingLeft:od(s,T)},onContextMenu:e=>y(e,t),onTouchStart:e=>w(e,t),onTouchEnd:j,onTouchMove:j,onClick:e=>!c&&v(t,e),children:[r?(0,n.jsx)("span",{onClick:e=>{e.stopPropagation(),g(t)},className:"flex items-center justify-center w-4 h-4 text-text-muted",children:a?(0,n.jsx)(ev.Ay,{name:"Loader2",size:R.chevron-2,className:"animate-spin"}):(0,n.jsx)(ev.Ay,{name:"ChevronRight",size:R.chevron,className:`transition-transform duration-150 ${l?"rotate-90":""}`})}):(0,n.jsx)("span",{className:"w-4 h-4"}),(0,n.jsx)("span",{className:"shrink-0",children:r?function(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:16,{src:r,alt:l}=oi(e,t);return(0,n.jsx)("img",{src:r,alt:l,width:s,height:s,className:"pointer-events-none select-none",draggable:"false"})}(t.name,l,R.icon):oo(t,R.icon)}),c?(0,n.jsx)("input",{ref:p,value:x,onChange:e=>h(e.target.value),onClick:e=>e.stopPropagation(),onBlur:f,onKeyDown:e=>{"Enter"===e.key?f():"Escape"===e.key&&b()},className:`flex-1 bg-surface-3 text-text ${R.text} px-1 py-0.5 rounded outline-none border border-brand-500`}):(0,n.jsx)("span",{className:`flex-1 truncate text-text ${et.vs[m]||""}`,title:t.name,children:t.name}),!c&&(0,n.jsx)(ou,{status:m}),!c&&(0,n.jsx)("div",{className:"absolute top-1/2 -translate-y-1/2 flex items-center pl-2 pr-1 rounded-[3px] bg-surface-2 opacity-0 group-hover:opacity-100 transition-opacity",style:{right:(0,et.mv)(m)},children:(0,n.jsx)("button",{onClick:e=>y(e,t),className:"p-0.5 text-text-muted hover:text-text",children:(0,n.jsx)(ev.Ay,{name:"MoreHorizontal",size:R.chevron})})})]}),E]})});async function op(e,t,s){let n=t?`${t}/${e.name}`:e.name;if(e.isFile){let t=await new Promise((t,s)=>e.file(t,s));s.push({file:t,relativePath:n})}else if(e.isDirectory){var r;for(let t of(await (r=e.createReader(),new Promise(e=>{let t=[],s=()=>r.readEntries(n=>{n.length?(t.push(...n),s()):e(t)},()=>e(t));s()}))))await op(t,n,s)}}async function oh(e){let t=[],s=[...e.items||[]].map(e=>e.webkitGetAsEntry?.()).filter(Boolean);if(s.length)for(let e of s)await op(e,"",t);else for(let s of e.files||[])t.push({file:s,relativePath:s.name});return t}let of="modal-overlay z-50",ob="w-full px-3 py-2 bg-surface-2 rounded-brand text-text focus:outline-none focus:ring-2 focus:ring-brand-500/40 transition-all duration-150 ease-out",og="flex-1 py-2 bg-surface-2 text-text rounded-brand hover:bg-surface-3 transition-all duration-150 ease-out active:scale-[0.98]",ov="flex-1 py-2 bg-brand-500 text-white rounded-brand hover:bg-brand-600 transition-all duration-150 ease-out active:scale-[0.98]";function oy(e){let{label:t,ratio:s}=e;return(0,n.jsxs)("div",{className:"bg-brand-500/10 border-b border-brand-500/30 px-4 py-2 text-text text-xs flex items-center gap-2",children:[(0,n.jsx)(ev.kr,{className:"animate-spin flex-shrink-0",size:14}),(0,n.jsx)("span",{className:"truncate flex-1",children:t}),(0,n.jsx)("div",{className:"w-16 h-1.5 bg-surface-2 rounded-full overflow-hidden flex-shrink-0",children:(0,n.jsx)("div",{className:"h-full bg-brand-500 transition-all",style:{width:`${Math.round(100*(s||0))}%`}})})]})}function ow(e){let{query:t,loading:s,onChange:r,onClose:l,compact:a=!1}=e,{t:i}=(0,eC.s)();return a?(0,n.jsx)("div",{className:"px-2 py-1.5 border-b border-border-subtle flex-shrink-0",children:(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)(ev.vj,{size:14,className:"absolute left-2 top-1/2 -translate-y-1/2 text-text-subtle pointer-events-none"}),(0,n.jsx)("input",{type:"text",value:t,onChange:e=>r(e.target.value),placeholder:i("files.searchPlaceholder"),className:"w-full min-w-0 bg-surface-2 border border-border rounded-brand pl-7 pr-7 h-8 text-xs text-text placeholder-text-subtle focus:outline-none focus:border-brand-500",autoFocus:!0}),s?(0,n.jsx)(ev.kr,{size:14,className:"absolute right-2 top-1/2 -translate-y-1/2 animate-spin text-brand-500"}):(0,n.jsx)("button",{onClick:()=>{(0,eN.e)(),l()},className:"absolute right-1 top-1/2 -translate-y-1/2 p-1 text-text-subtle hover:text-text",children:(0,n.jsx)(ev.X,{size:14})})]})}):(0,n.jsxs)("div",{className:"bg-surface-2 px-4 py-2 flex items-center gap-2 flex-shrink-0",children:[(0,n.jsx)(ev.vj,{className:"text-text-muted flex-shrink-0",size:20}),(0,n.jsx)("input",{type:"text",value:t,onChange:e=>r(e.target.value),placeholder:i("files.searchPlaceholder"),className:"flex-1 min-w-0 w-0 bg-transparent text-text placeholder-text-subtle focus:outline-none",autoFocus:!0}),s&&(0,n.jsx)(ev.kr,{className:"animate-spin text-brand-500",size:16}),(0,n.jsx)("button",{onClick:()=>{(0,eN.e)(),l()},className:"p-1 text-text-muted hover:text-text transition-colors",children:(0,n.jsx)(ev.X,{size:20})})]})}function oj(e){let{type:t,name:s,onTypeChange:l,onNameChange:a,onSubmit:i,onPickFile:o,onPickFolder:c,onClose:d}=e,{t:u}=(0,eC.s)(),[m]=(0,r.useState)(()=>"u">typeof document&&"webkitdirectory"in document.createElement("input")),x="upload"===t;return(0,r.useEffect)(()=>{let e=e=>{"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),d())};return window.addEventListener("keydown",e,!0),()=>window.removeEventListener("keydown",e,!0)},[d]),(0,sp.createPortal)((0,n.jsxs)("div",{className:of,children:[(0,n.jsx)("div",{className:"absolute inset-0 scrim fade-in",onClick:d}),(0,n.jsxs)("div",{className:"relative card-elev w-full max-w-sm my-auto overflow-y-auto pop-in",children:[(0,n.jsx)("div",{className:"px-4 py-3",children:(0,n.jsx)("h3",{className:"text-text font-semibold",children:u("files.createNew")})}),(0,n.jsxs)("div",{className:"p-4 space-y-4",children:[(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsxs)("button",{onClick:()=>{(0,eN.e)(),l("file")},className:`flex-1 py-2 rounded-brand transition flex items-center justify-center gap-2 ${"file"===t?"bg-brand-500 text-white dark:bg-white dark:text-black":"bg-surface-2 text-text"}`,children:[(0,n.jsx)(ev.ZH,{size:16,className:"text-text-subtle"})," ",u("files.file")]}),(0,n.jsxs)("button",{onClick:()=>{(0,eN.e)(),l("folder")},className:`flex-1 py-2 rounded-brand transition flex items-center justify-center gap-2 ${"folder"===t?"bg-brand-500 text-white dark:bg-white dark:text-black":"bg-surface-2 text-text"}`,children:[(0,n.jsx)(ev.vd,{size:16,className:"text-orange-500/70"})," ",u("files.folder")]}),(0,n.jsxs)("button",{onClick:()=>{(0,eN.e)(),l("upload")},className:`flex-1 py-2 rounded-brand transition flex items-center justify-center gap-2 ${x?"bg-brand-500 text-white dark:bg-white dark:text-black":"bg-surface-2 text-text"}`,children:[(0,n.jsx)(ev._O,{size:16,className:"text-brand-500"})," ",u("common.upload")]})]}),x?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("button",{onClick:()=>{(0,eN.e)(),o()},className:`${ov} flex items-center justify-center gap-2`,children:[(0,n.jsx)(ev.ZH,{size:16})," ",u("files.pickFile")]}),m&&(0,n.jsxs)("button",{onClick:()=>{(0,eN.e)(),c()},className:`${og} flex items-center justify-center gap-2`,children:[(0,n.jsx)(ev.vd,{size:16})," ",u("files.pickFolder")]}),(0,n.jsxs)("button",{onClick:()=>{(0,eN.e)(),d()},className:`${og} flex items-center justify-center gap-1.5`,children:[(0,n.jsx)("span",{children:u("common.cancel")}),(0,n.jsx)("kbd",{className:"hidden sm:inline-flex items-center text-[10px] font-mono px-1 py-0.5 rounded bg-surface-3 text-text-muted leading-none",children:"Esc"})]})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("input",{type:"text",value:s,onChange:e=>a(e.target.value),onKeyDown:e=>"Enter"===e.key&&i(),placeholder:u("file"===t?"files.placeholderFile":"files.placeholderFolder"),className:ob,autoFocus:!0}),(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsxs)("button",{onClick:()=>{(0,eN.e)(),d()},className:`${og} flex items-center justify-center gap-1.5`,children:[(0,n.jsx)("span",{children:u("common.cancel")}),(0,n.jsx)("kbd",{className:"hidden sm:inline-flex items-center text-[10px] font-mono px-1 py-0.5 rounded bg-surface-3 text-text-muted leading-none",children:"Esc"})]}),(0,n.jsxs)("button",{onClick:()=>{(0,eN.e)(),i()},className:`${ov} flex items-center justify-center gap-1.5`,children:[(0,n.jsx)("span",{children:u("common.create")}),(0,n.jsx)("kbd",{className:"hidden sm:inline-flex items-center justify-center w-4 h-4 rounded bg-white/20 text-white",children:(0,n.jsx)(ev.Lt,{size:10,strokeWidth:2.5})})]})]})]})]})]})]}),document.body)}function ok(e){let{value:t,onChange:s,onSubmit:l,onClose:a}=e,{t:i}=(0,eC.s)();return(0,r.useEffect)(()=>{let e=e=>{"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),a())};return window.addEventListener("keydown",e,!0),()=>window.removeEventListener("keydown",e,!0)},[a]),(0,sp.createPortal)((0,n.jsxs)("div",{className:of,children:[(0,n.jsx)("div",{className:"absolute inset-0 scrim fade-in",onClick:a}),(0,n.jsxs)("div",{className:"relative card-elev w-full max-w-sm my-auto max-h-[min(85%,calc(var(--app-height,85vh)-2rem))] overflow-y-auto pop-in",children:[(0,n.jsx)("div",{className:"px-4 py-3",children:(0,n.jsx)("h3",{className:"text-text font-semibold",children:i("files.rename")})}),(0,n.jsxs)("div",{className:"p-4 space-y-4",children:[(0,n.jsx)("input",{type:"text",value:t,onChange:e=>s(e.target.value),onKeyDown:e=>"Enter"===e.key&&l(),className:ob,autoFocus:!0}),(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsxs)("button",{onClick:()=>{(0,eN.e)(),a()},className:`${og} flex items-center justify-center gap-1.5`,children:[(0,n.jsx)("span",{children:i("common.cancel")}),(0,n.jsx)("kbd",{className:"hidden sm:inline-flex items-center text-[10px] font-mono px-1 py-0.5 rounded bg-surface-3 text-text-muted leading-none",children:"Esc"})]}),(0,n.jsxs)("button",{onClick:()=>{(0,eN.e)(),l()},className:`${ov} flex items-center justify-center gap-1.5`,children:[(0,n.jsx)("span",{children:i("files.rename")}),(0,n.jsx)("kbd",{className:"hidden sm:inline-flex items-center justify-center w-4 h-4 rounded bg-white/20 text-white",children:(0,n.jsx)(ev.Lt,{size:10,strokeWidth:2.5})})]})]})]})]})]}),document.body)}function oN(e){let{name:t,onResolve:s}=e,{t:l}=(0,eC.s)();(0,r.useEffect)(()=>{let e=e=>{"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),s?.("skip"))};return window.addEventListener("keydown",e,!0),()=>window.removeEventListener("keydown",e,!0)},[s]);let a=function(e,t){let r=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return(0,n.jsxs)("button",{onClick:()=>{(0,eN.e)(),s(e)},className:`py-2 rounded-brand text-sm flex items-center justify-center gap-1.5 ${t}`,children:[(0,n.jsx)("span",{children:l(`menu.${e}`)}),r&&(0,n.jsx)("kbd",{className:"hidden sm:inline-flex items-center text-[10px] font-mono px-1 py-0.5 rounded bg-surface-3 text-text-muted leading-none",children:"Esc"})]})};return(0,sp.createPortal)((0,n.jsxs)("div",{className:of,children:[(0,n.jsx)("div",{className:"absolute inset-0 scrim fade-in",onClick:()=>s?.("skip")}),(0,n.jsxs)("div",{className:"relative card-elev w-full max-w-sm pop-in",children:[(0,n.jsx)("div",{className:"px-4 py-3",children:(0,n.jsx)("h3",{className:"text-text font-semibold",children:l("menu.conflictTitle")})}),(0,n.jsx)("div",{className:"px-4 pb-3 text-text-muted text-sm break-all",children:l("menu.conflictMessage",{name:t})}),(0,n.jsxs)("div",{className:"p-4 grid grid-cols-2 gap-2",children:[a("skip","bg-surface-2 text-text hover:bg-surface-3",!0),a("skipAll","bg-surface-2 text-text hover:bg-surface-3"),a("replace","bg-brand-500 text-white hover:bg-brand-600"),a("replaceAll","bg-brand-500 text-white hover:bg-brand-600")]})]})]}),document.body)}async function oC(e,t,s){let n=arguments.length>3&&void 0!==arguments[3]&&arguments[3];if(!e||!t||!s)return{success:!1};let r=iZ(t,".gitignore"),l=s.replace(/^\/+/,"");n&&!l.endsWith("/")&&(l=`${l}/`);let a=await e.readFile(r),i=a?.success&&a.content||"",o=i.split(/\r?\n/),c=l.replace(/\/$/,"");if(o.includes(l)||o.includes(c)||o.includes(`/${l}`)||o.includes(`/${c}`))return{success:!0,alreadyIgnored:!0};let d=i?i.endsWith("\n")?`${i}${l}
14
14
  `:`${i}
15
15
  ${l}
16
16
  `:`${l}